]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.16.1-201409021826.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.16.1-201409021826.patch
CommitLineData
b6f713f0
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index 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
237diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
238index 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]
289diff --git a/Documentation/networking/filter.txt b/Documentation/networking/filter.txt
290index 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>
787diff --git a/Makefile b/Makefile
788index 87663a2..906dc62 100644
789--- a/Makefile
790+++ b/Makefile
791@@ -303,8 +303,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
792
793 HOSTCC = gcc
794 HOSTCXX = g++
795-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
796-HOSTCXXFLAGS = -O2
797+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
798+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
799+HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
800
801 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
802 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
803@@ -449,8 +450,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
804 # Rules shared between *config targets and build targets
805
806 # Basic helpers built in scripts/
807-PHONY += scripts_basic
808-scripts_basic:
809+PHONY += scripts_basic gcc-plugins
810+scripts_basic: gcc-plugins
811 $(Q)$(MAKE) $(build)=scripts/basic
812 $(Q)rm -f .tmp_quiet_recordmcount
813
814@@ -621,6 +622,75 @@ else
815 KBUILD_CFLAGS += -O2
816 endif
817
818+# Tell gcc to never replace conditional load with a non-conditional one
819+KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
820+
821+ifndef DISABLE_PAX_PLUGINS
822+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
823+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
824+else
825+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
826+endif
827+ifneq ($(PLUGINCC),)
828+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
829+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
830+endif
831+ifdef CONFIG_PAX_MEMORY_STACKLEAK
832+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
833+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
834+endif
835+ifdef CONFIG_KALLOCSTAT_PLUGIN
836+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
837+endif
838+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
839+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
840+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
841+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
842+endif
843+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
844+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
845+ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
846+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
847+endif
848+endif
849+ifdef CONFIG_CHECKER_PLUGIN
850+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
851+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
852+endif
853+endif
854+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
855+ifdef CONFIG_PAX_SIZE_OVERFLOW
856+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
857+endif
858+ifdef CONFIG_PAX_LATENT_ENTROPY
859+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
860+endif
861+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
862+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
863+endif
864+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
865+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
866+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
867+GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
868+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
869+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
870+ifeq ($(KBUILD_EXTMOD),)
871+gcc-plugins:
872+ $(Q)$(MAKE) $(build)=tools/gcc
873+else
874+gcc-plugins: ;
875+endif
876+else
877+gcc-plugins:
878+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
879+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
880+else
881+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
882+endif
883+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
884+endif
885+endif
886+
887 ifdef CONFIG_READABLE_ASM
888 # Disable optimizations that make assembler listings hard to read.
889 # reorder blocks reorders the control in the function
890@@ -839,7 +909,7 @@ export mod_sign_cmd
891
892
893 ifeq ($(KBUILD_EXTMOD),)
894-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
895+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
896
897 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
898 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
899@@ -888,6 +958,8 @@ endif
900
901 # The actual objects are generated when descending,
902 # make sure no implicit rule kicks in
903+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
904+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
905 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
906
907 # Handle descending into subdirectories listed in $(vmlinux-dirs)
908@@ -897,7 +969,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
909 # Error messages still appears in the original language
910
911 PHONY += $(vmlinux-dirs)
912-$(vmlinux-dirs): prepare scripts
913+$(vmlinux-dirs): gcc-plugins prepare scripts
914 $(Q)$(MAKE) $(build)=$@
915
916 define filechk_kernel.release
917@@ -940,10 +1012,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
918
919 archprepare: archheaders archscripts prepare1 scripts_basic
920
921+prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
922+prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
923 prepare0: archprepare FORCE
924 $(Q)$(MAKE) $(build)=.
925
926 # All the preparing..
927+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
928 prepare: prepare0
929
930 # Generate some files
931@@ -1051,6 +1126,8 @@ all: modules
932 # using awk while concatenating to the final file.
933
934 PHONY += modules
935+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
936+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
937 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
938 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
939 @$(kecho) ' Building modules, stage 2.';
940@@ -1066,7 +1143,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
941
942 # Target to prepare building external modules
943 PHONY += modules_prepare
944-modules_prepare: prepare scripts
945+modules_prepare: gcc-plugins prepare scripts
946
947 # Target to install modules
948 PHONY += modules_install
949@@ -1132,7 +1209,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
950 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
951 signing_key.priv signing_key.x509 x509.genkey \
952 extra_certificates signing_key.x509.keyid \
953- signing_key.x509.signer include/linux/version.h
954+ signing_key.x509.signer include/linux/version.h \
955+ tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
956+ tools/gcc/size_overflow_plugin/size_overflow_hash.h \
957+ tools/gcc/randomize_layout_seed.h
958
959 # clean - Delete most, but leave enough to build external modules
960 #
961@@ -1171,7 +1251,7 @@ distclean: mrproper
962 @find $(srctree) $(RCS_FIND_IGNORE) \
963 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
964 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
965- -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
966+ -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
967 -type f -print | xargs rm -f
968
969
970@@ -1332,6 +1412,8 @@ PHONY += $(module-dirs) modules
971 $(module-dirs): crmodverdir $(objtree)/Module.symvers
972 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
973
974+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
975+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
976 modules: $(module-dirs)
977 @$(kecho) ' Building modules, stage 2.';
978 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
979@@ -1471,17 +1553,21 @@ else
980 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
981 endif
982
983-%.s: %.c prepare scripts FORCE
984+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
985+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
986+%.s: %.c gcc-plugins prepare scripts FORCE
987 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
988 %.i: %.c prepare scripts FORCE
989 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
990-%.o: %.c prepare scripts FORCE
991+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
992+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
993+%.o: %.c gcc-plugins prepare scripts FORCE
994 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
995 %.lst: %.c prepare scripts FORCE
996 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
997-%.s: %.S prepare scripts FORCE
998+%.s: %.S gcc-plugins prepare scripts FORCE
999 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1000-%.o: %.S prepare scripts FORCE
1001+%.o: %.S gcc-plugins prepare scripts FORCE
1002 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1003 %.symtypes: %.c prepare scripts FORCE
1004 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1005@@ -1491,11 +1577,15 @@ endif
1006 $(cmd_crmodverdir)
1007 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1008 $(build)=$(build-dir)
1009-%/: prepare scripts FORCE
1010+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
1011+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
1012+%/: gcc-plugins prepare scripts FORCE
1013 $(cmd_crmodverdir)
1014 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1015 $(build)=$(build-dir)
1016-%.ko: prepare scripts FORCE
1017+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
1018+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
1019+%.ko: gcc-plugins prepare scripts FORCE
1020 $(cmd_crmodverdir)
1021 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1022 $(build)=$(build-dir) $(@:.ko=.o)
1023diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
1024index ed60a1e..47f1a55 100644
1025--- a/arch/alpha/include/asm/atomic.h
1026+++ b/arch/alpha/include/asm/atomic.h
1027@@ -292,4 +292,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
1028 #define atomic_dec(v) atomic_sub(1,(v))
1029 #define atomic64_dec(v) atomic64_sub(1,(v))
1030
1031+#define atomic64_read_unchecked(v) atomic64_read(v)
1032+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
1033+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
1034+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
1035+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
1036+#define atomic64_inc_unchecked(v) atomic64_inc(v)
1037+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
1038+#define atomic64_dec_unchecked(v) atomic64_dec(v)
1039+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
1040+
1041 #endif /* _ALPHA_ATOMIC_H */
1042diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
1043index ad368a9..fbe0f25 100644
1044--- a/arch/alpha/include/asm/cache.h
1045+++ b/arch/alpha/include/asm/cache.h
1046@@ -4,19 +4,19 @@
1047 #ifndef __ARCH_ALPHA_CACHE_H
1048 #define __ARCH_ALPHA_CACHE_H
1049
1050+#include <linux/const.h>
1051
1052 /* Bytes per L1 (data) cache line. */
1053 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
1054-# define L1_CACHE_BYTES 64
1055 # define L1_CACHE_SHIFT 6
1056 #else
1057 /* Both EV4 and EV5 are write-through, read-allocate,
1058 direct-mapped, physical.
1059 */
1060-# define L1_CACHE_BYTES 32
1061 # define L1_CACHE_SHIFT 5
1062 #endif
1063
1064+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1065 #define SMP_CACHE_BYTES L1_CACHE_BYTES
1066
1067 #endif
1068diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
1069index 968d999..d36b2df 100644
1070--- a/arch/alpha/include/asm/elf.h
1071+++ b/arch/alpha/include/asm/elf.h
1072@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
1073
1074 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
1075
1076+#ifdef CONFIG_PAX_ASLR
1077+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
1078+
1079+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
1080+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
1081+#endif
1082+
1083 /* $0 is set by ld.so to a pointer to a function which might be
1084 registered using atexit. This provides a mean for the dynamic
1085 linker to call DT_FINI functions for shared libraries that have
1086diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
1087index aab14a0..b4fa3e7 100644
1088--- a/arch/alpha/include/asm/pgalloc.h
1089+++ b/arch/alpha/include/asm/pgalloc.h
1090@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
1091 pgd_set(pgd, pmd);
1092 }
1093
1094+static inline void
1095+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
1096+{
1097+ pgd_populate(mm, pgd, pmd);
1098+}
1099+
1100 extern pgd_t *pgd_alloc(struct mm_struct *mm);
1101
1102 static inline void
1103diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
1104index d8f9b7e..f6222fa 100644
1105--- a/arch/alpha/include/asm/pgtable.h
1106+++ b/arch/alpha/include/asm/pgtable.h
1107@@ -102,6 +102,17 @@ struct vm_area_struct;
1108 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
1109 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
1110 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
1111+
1112+#ifdef CONFIG_PAX_PAGEEXEC
1113+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
1114+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
1115+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
1116+#else
1117+# define PAGE_SHARED_NOEXEC PAGE_SHARED
1118+# define PAGE_COPY_NOEXEC PAGE_COPY
1119+# define PAGE_READONLY_NOEXEC PAGE_READONLY
1120+#endif
1121+
1122 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
1123
1124 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
1125diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
1126index 2fd00b7..cfd5069 100644
1127--- a/arch/alpha/kernel/module.c
1128+++ b/arch/alpha/kernel/module.c
1129@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
1130
1131 /* The small sections were sorted to the end of the segment.
1132 The following should definitely cover them. */
1133- gp = (u64)me->module_core + me->core_size - 0x8000;
1134+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
1135 got = sechdrs[me->arch.gotsecindex].sh_addr;
1136
1137 for (i = 0; i < n; i++) {
1138diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
1139index 1402fcc..0b1abd2 100644
1140--- a/arch/alpha/kernel/osf_sys.c
1141+++ b/arch/alpha/kernel/osf_sys.c
1142@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
1143 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
1144
1145 static unsigned long
1146-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
1147- unsigned long limit)
1148+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
1149+ unsigned long limit, unsigned long flags)
1150 {
1151 struct vm_unmapped_area_info info;
1152+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
1153
1154 info.flags = 0;
1155 info.length = len;
1156@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
1157 info.high_limit = limit;
1158 info.align_mask = 0;
1159 info.align_offset = 0;
1160+ info.threadstack_offset = offset;
1161 return vm_unmapped_area(&info);
1162 }
1163
1164@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1165 merely specific addresses, but regions of memory -- perhaps
1166 this feature should be incorporated into all ports? */
1167
1168+#ifdef CONFIG_PAX_RANDMMAP
1169+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
1170+#endif
1171+
1172 if (addr) {
1173- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
1174+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
1175 if (addr != (unsigned long) -ENOMEM)
1176 return addr;
1177 }
1178
1179 /* Next, try allocating at TASK_UNMAPPED_BASE. */
1180- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
1181- len, limit);
1182+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
1183+
1184 if (addr != (unsigned long) -ENOMEM)
1185 return addr;
1186
1187 /* Finally, try allocating in low memory. */
1188- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
1189+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
1190
1191 return addr;
1192 }
1193diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
1194index 98838a0..b304fb4 100644
1195--- a/arch/alpha/mm/fault.c
1196+++ b/arch/alpha/mm/fault.c
1197@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
1198 __reload_thread(pcb);
1199 }
1200
1201+#ifdef CONFIG_PAX_PAGEEXEC
1202+/*
1203+ * PaX: decide what to do with offenders (regs->pc = fault address)
1204+ *
1205+ * returns 1 when task should be killed
1206+ * 2 when patched PLT trampoline was detected
1207+ * 3 when unpatched PLT trampoline was detected
1208+ */
1209+static int pax_handle_fetch_fault(struct pt_regs *regs)
1210+{
1211+
1212+#ifdef CONFIG_PAX_EMUPLT
1213+ int err;
1214+
1215+ do { /* PaX: patched PLT emulation #1 */
1216+ unsigned int ldah, ldq, jmp;
1217+
1218+ err = get_user(ldah, (unsigned int *)regs->pc);
1219+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
1220+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
1221+
1222+ if (err)
1223+ break;
1224+
1225+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
1226+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
1227+ jmp == 0x6BFB0000U)
1228+ {
1229+ unsigned long r27, addr;
1230+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
1231+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
1232+
1233+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
1234+ err = get_user(r27, (unsigned long *)addr);
1235+ if (err)
1236+ break;
1237+
1238+ regs->r27 = r27;
1239+ regs->pc = r27;
1240+ return 2;
1241+ }
1242+ } while (0);
1243+
1244+ do { /* PaX: patched PLT emulation #2 */
1245+ unsigned int ldah, lda, br;
1246+
1247+ err = get_user(ldah, (unsigned int *)regs->pc);
1248+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
1249+ err |= get_user(br, (unsigned int *)(regs->pc+8));
1250+
1251+ if (err)
1252+ break;
1253+
1254+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
1255+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
1256+ (br & 0xFFE00000U) == 0xC3E00000U)
1257+ {
1258+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
1259+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
1260+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
1261+
1262+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
1263+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
1264+ return 2;
1265+ }
1266+ } while (0);
1267+
1268+ do { /* PaX: unpatched PLT emulation */
1269+ unsigned int br;
1270+
1271+ err = get_user(br, (unsigned int *)regs->pc);
1272+
1273+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
1274+ unsigned int br2, ldq, nop, jmp;
1275+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
1276+
1277+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
1278+ err = get_user(br2, (unsigned int *)addr);
1279+ err |= get_user(ldq, (unsigned int *)(addr+4));
1280+ err |= get_user(nop, (unsigned int *)(addr+8));
1281+ err |= get_user(jmp, (unsigned int *)(addr+12));
1282+ err |= get_user(resolver, (unsigned long *)(addr+16));
1283+
1284+ if (err)
1285+ break;
1286+
1287+ if (br2 == 0xC3600000U &&
1288+ ldq == 0xA77B000CU &&
1289+ nop == 0x47FF041FU &&
1290+ jmp == 0x6B7B0000U)
1291+ {
1292+ regs->r28 = regs->pc+4;
1293+ regs->r27 = addr+16;
1294+ regs->pc = resolver;
1295+ return 3;
1296+ }
1297+ }
1298+ } while (0);
1299+#endif
1300+
1301+ return 1;
1302+}
1303+
1304+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1305+{
1306+ unsigned long i;
1307+
1308+ printk(KERN_ERR "PAX: bytes at PC: ");
1309+ for (i = 0; i < 5; i++) {
1310+ unsigned int c;
1311+ if (get_user(c, (unsigned int *)pc+i))
1312+ printk(KERN_CONT "???????? ");
1313+ else
1314+ printk(KERN_CONT "%08x ", c);
1315+ }
1316+ printk("\n");
1317+}
1318+#endif
1319
1320 /*
1321 * This routine handles page faults. It determines the address,
1322@@ -133,8 +251,29 @@ retry:
1323 good_area:
1324 si_code = SEGV_ACCERR;
1325 if (cause < 0) {
1326- if (!(vma->vm_flags & VM_EXEC))
1327+ if (!(vma->vm_flags & VM_EXEC)) {
1328+
1329+#ifdef CONFIG_PAX_PAGEEXEC
1330+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
1331+ goto bad_area;
1332+
1333+ up_read(&mm->mmap_sem);
1334+ switch (pax_handle_fetch_fault(regs)) {
1335+
1336+#ifdef CONFIG_PAX_EMUPLT
1337+ case 2:
1338+ case 3:
1339+ return;
1340+#endif
1341+
1342+ }
1343+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
1344+ do_group_exit(SIGKILL);
1345+#else
1346 goto bad_area;
1347+#endif
1348+
1349+ }
1350 } else if (!cause) {
1351 /* Allow reads even for write-only mappings */
1352 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
1353diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
1354index 290f02ee..a639059 100644
1355--- a/arch/arm/Kconfig
1356+++ b/arch/arm/Kconfig
1357@@ -1787,7 +1787,7 @@ config ALIGNMENT_TRAP
1358
1359 config UACCESS_WITH_MEMCPY
1360 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
1361- depends on MMU
1362+ depends on MMU && !PAX_MEMORY_UDEREF
1363 default y if CPU_FEROCEON
1364 help
1365 Implement faster copy_to_user and clear_user methods for CPU
1366@@ -2051,6 +2051,7 @@ config XIP_PHYS_ADDR
1367 config KEXEC
1368 bool "Kexec system call (EXPERIMENTAL)"
1369 depends on (!SMP || PM_SLEEP_SMP)
1370+ depends on !GRKERNSEC_KMEM
1371 help
1372 kexec is a system call that implements the ability to shutdown your
1373 current kernel, and to start another kernel. It is like a reboot
1374diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
1375index 3040359..89b3dfc 100644
1376--- a/arch/arm/include/asm/atomic.h
1377+++ b/arch/arm/include/asm/atomic.h
1378@@ -18,17 +18,35 @@
1379 #include <asm/barrier.h>
1380 #include <asm/cmpxchg.h>
1381
1382+#ifdef CONFIG_GENERIC_ATOMIC64
1383+#include <asm-generic/atomic64.h>
1384+#endif
1385+
1386 #define ATOMIC_INIT(i) { (i) }
1387
1388 #ifdef __KERNEL__
1389
1390+#define _ASM_EXTABLE(from, to) \
1391+" .pushsection __ex_table,\"a\"\n"\
1392+" .align 3\n" \
1393+" .long " #from ", " #to"\n" \
1394+" .popsection"
1395+
1396 /*
1397 * On ARM, ordinary assignment (str instruction) doesn't clear the local
1398 * strex/ldrex monitor on some implementations. The reason we can use it for
1399 * atomic_set() is the clrex or dummy strex done on every exception return.
1400 */
1401 #define atomic_read(v) (*(volatile int *)&(v)->counter)
1402+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
1403+{
1404+ return v->counter;
1405+}
1406 #define atomic_set(v,i) (((v)->counter) = (i))
1407+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1408+{
1409+ v->counter = i;
1410+}
1411
1412 #if __LINUX_ARM_ARCH__ >= 6
1413
1414@@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
1415
1416 prefetchw(&v->counter);
1417 __asm__ __volatile__("@ atomic_add\n"
1418+"1: ldrex %1, [%3]\n"
1419+" adds %0, %1, %4\n"
1420+
1421+#ifdef CONFIG_PAX_REFCOUNT
1422+" bvc 3f\n"
1423+"2: bkpt 0xf103\n"
1424+"3:\n"
1425+#endif
1426+
1427+" strex %1, %0, [%3]\n"
1428+" teq %1, #0\n"
1429+" bne 1b"
1430+
1431+#ifdef CONFIG_PAX_REFCOUNT
1432+"\n4:\n"
1433+ _ASM_EXTABLE(2b, 4b)
1434+#endif
1435+
1436+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1437+ : "r" (&v->counter), "Ir" (i)
1438+ : "cc");
1439+}
1440+
1441+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1442+{
1443+ unsigned long tmp;
1444+ int result;
1445+
1446+ prefetchw(&v->counter);
1447+ __asm__ __volatile__("@ atomic_add_unchecked\n"
1448 "1: ldrex %0, [%3]\n"
1449 " add %0, %0, %4\n"
1450 " strex %1, %0, [%3]\n"
1451@@ -63,6 +111,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
1452 prefetchw(&v->counter);
1453
1454 __asm__ __volatile__("@ atomic_add_return\n"
1455+"1: ldrex %1, [%3]\n"
1456+" adds %0, %1, %4\n"
1457+
1458+#ifdef CONFIG_PAX_REFCOUNT
1459+" bvc 3f\n"
1460+" mov %0, %1\n"
1461+"2: bkpt 0xf103\n"
1462+"3:\n"
1463+#endif
1464+
1465+" strex %1, %0, [%3]\n"
1466+" teq %1, #0\n"
1467+" bne 1b"
1468+
1469+#ifdef CONFIG_PAX_REFCOUNT
1470+"\n4:\n"
1471+ _ASM_EXTABLE(2b, 4b)
1472+#endif
1473+
1474+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1475+ : "r" (&v->counter), "Ir" (i)
1476+ : "cc");
1477+
1478+ smp_mb();
1479+
1480+ return result;
1481+}
1482+
1483+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1484+{
1485+ unsigned long tmp;
1486+ int result;
1487+
1488+ smp_mb();
1489+ prefetchw(&v->counter);
1490+
1491+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1492 "1: ldrex %0, [%3]\n"
1493 " add %0, %0, %4\n"
1494 " strex %1, %0, [%3]\n"
1495@@ -84,6 +169,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1496
1497 prefetchw(&v->counter);
1498 __asm__ __volatile__("@ atomic_sub\n"
1499+"1: ldrex %1, [%3]\n"
1500+" subs %0, %1, %4\n"
1501+
1502+#ifdef CONFIG_PAX_REFCOUNT
1503+" bvc 3f\n"
1504+"2: bkpt 0xf103\n"
1505+"3:\n"
1506+#endif
1507+
1508+" strex %1, %0, [%3]\n"
1509+" teq %1, #0\n"
1510+" bne 1b"
1511+
1512+#ifdef CONFIG_PAX_REFCOUNT
1513+"\n4:\n"
1514+ _ASM_EXTABLE(2b, 4b)
1515+#endif
1516+
1517+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1518+ : "r" (&v->counter), "Ir" (i)
1519+ : "cc");
1520+}
1521+
1522+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1523+{
1524+ unsigned long tmp;
1525+ int result;
1526+
1527+ prefetchw(&v->counter);
1528+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1529 "1: ldrex %0, [%3]\n"
1530 " sub %0, %0, %4\n"
1531 " strex %1, %0, [%3]\n"
1532@@ -103,11 +218,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1533 prefetchw(&v->counter);
1534
1535 __asm__ __volatile__("@ atomic_sub_return\n"
1536-"1: ldrex %0, [%3]\n"
1537-" sub %0, %0, %4\n"
1538+"1: ldrex %1, [%3]\n"
1539+" subs %0, %1, %4\n"
1540+
1541+#ifdef CONFIG_PAX_REFCOUNT
1542+" bvc 3f\n"
1543+" mov %0, %1\n"
1544+"2: bkpt 0xf103\n"
1545+"3:\n"
1546+#endif
1547+
1548 " strex %1, %0, [%3]\n"
1549 " teq %1, #0\n"
1550 " bne 1b"
1551+
1552+#ifdef CONFIG_PAX_REFCOUNT
1553+"\n4:\n"
1554+ _ASM_EXTABLE(2b, 4b)
1555+#endif
1556+
1557 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1558 : "r" (&v->counter), "Ir" (i)
1559 : "cc");
1560@@ -152,12 +281,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1561 __asm__ __volatile__ ("@ atomic_add_unless\n"
1562 "1: ldrex %0, [%4]\n"
1563 " teq %0, %5\n"
1564-" beq 2f\n"
1565-" add %1, %0, %6\n"
1566+" beq 4f\n"
1567+" adds %1, %0, %6\n"
1568+
1569+#ifdef CONFIG_PAX_REFCOUNT
1570+" bvc 3f\n"
1571+"2: bkpt 0xf103\n"
1572+"3:\n"
1573+#endif
1574+
1575 " strex %2, %1, [%4]\n"
1576 " teq %2, #0\n"
1577 " bne 1b\n"
1578-"2:"
1579+"4:"
1580+
1581+#ifdef CONFIG_PAX_REFCOUNT
1582+ _ASM_EXTABLE(2b, 4b)
1583+#endif
1584+
1585 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1586 : "r" (&v->counter), "r" (u), "r" (a)
1587 : "cc");
1588@@ -168,6 +309,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1589 return oldval;
1590 }
1591
1592+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1593+{
1594+ unsigned long oldval, res;
1595+
1596+ smp_mb();
1597+
1598+ do {
1599+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1600+ "ldrex %1, [%3]\n"
1601+ "mov %0, #0\n"
1602+ "teq %1, %4\n"
1603+ "strexeq %0, %5, [%3]\n"
1604+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1605+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1606+ : "cc");
1607+ } while (res);
1608+
1609+ smp_mb();
1610+
1611+ return oldval;
1612+}
1613+
1614 #else /* ARM_ARCH_6 */
1615
1616 #ifdef CONFIG_SMP
1617@@ -186,7 +349,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1618
1619 return val;
1620 }
1621+
1622+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1623+{
1624+ return atomic_add_return(i, v);
1625+}
1626+
1627 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1628+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1629+{
1630+ (void) atomic_add_return(i, v);
1631+}
1632
1633 static inline int atomic_sub_return(int i, atomic_t *v)
1634 {
1635@@ -201,6 +374,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1636 return val;
1637 }
1638 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1639+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1640+{
1641+ (void) atomic_sub_return(i, v);
1642+}
1643
1644 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1645 {
1646@@ -216,6 +393,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1647 return ret;
1648 }
1649
1650+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1651+{
1652+ return atomic_cmpxchg(v, old, new);
1653+}
1654+
1655 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1656 {
1657 int c, old;
1658@@ -229,13 +411,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1659 #endif /* __LINUX_ARM_ARCH__ */
1660
1661 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1662+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1663+{
1664+ return xchg(&v->counter, new);
1665+}
1666
1667 #define atomic_inc(v) atomic_add(1, v)
1668+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1669+{
1670+ atomic_add_unchecked(1, v);
1671+}
1672 #define atomic_dec(v) atomic_sub(1, v)
1673+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1674+{
1675+ atomic_sub_unchecked(1, v);
1676+}
1677
1678 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1679+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1680+{
1681+ return atomic_add_return_unchecked(1, v) == 0;
1682+}
1683 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1684 #define atomic_inc_return(v) (atomic_add_return(1, v))
1685+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1686+{
1687+ return atomic_add_return_unchecked(1, v);
1688+}
1689 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1690 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1691
1692@@ -246,6 +448,14 @@ typedef struct {
1693 long long counter;
1694 } atomic64_t;
1695
1696+#ifdef CONFIG_PAX_REFCOUNT
1697+typedef struct {
1698+ long long counter;
1699+} atomic64_unchecked_t;
1700+#else
1701+typedef atomic64_t atomic64_unchecked_t;
1702+#endif
1703+
1704 #define ATOMIC64_INIT(i) { (i) }
1705
1706 #ifdef CONFIG_ARM_LPAE
1707@@ -262,6 +472,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1708 return result;
1709 }
1710
1711+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1712+{
1713+ long long result;
1714+
1715+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1716+" ldrd %0, %H0, [%1]"
1717+ : "=&r" (result)
1718+ : "r" (&v->counter), "Qo" (v->counter)
1719+ );
1720+
1721+ return result;
1722+}
1723+
1724 static inline void atomic64_set(atomic64_t *v, long long i)
1725 {
1726 __asm__ __volatile__("@ atomic64_set\n"
1727@@ -270,6 +493,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1728 : "r" (&v->counter), "r" (i)
1729 );
1730 }
1731+
1732+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1733+{
1734+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1735+" strd %2, %H2, [%1]"
1736+ : "=Qo" (v->counter)
1737+ : "r" (&v->counter), "r" (i)
1738+ );
1739+}
1740 #else
1741 static inline long long atomic64_read(const atomic64_t *v)
1742 {
1743@@ -284,6 +516,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1744 return result;
1745 }
1746
1747+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1748+{
1749+ long long result;
1750+
1751+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1752+" ldrexd %0, %H0, [%1]"
1753+ : "=&r" (result)
1754+ : "r" (&v->counter), "Qo" (v->counter)
1755+ );
1756+
1757+ return result;
1758+}
1759+
1760 static inline void atomic64_set(atomic64_t *v, long long i)
1761 {
1762 long long tmp;
1763@@ -298,6 +543,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1764 : "r" (&v->counter), "r" (i)
1765 : "cc");
1766 }
1767+
1768+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1769+{
1770+ long long tmp;
1771+
1772+ prefetchw(&v->counter);
1773+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1774+"1: ldrexd %0, %H0, [%2]\n"
1775+" strexd %0, %3, %H3, [%2]\n"
1776+" teq %0, #0\n"
1777+" bne 1b"
1778+ : "=&r" (tmp), "=Qo" (v->counter)
1779+ : "r" (&v->counter), "r" (i)
1780+ : "cc");
1781+}
1782 #endif
1783
1784 static inline void atomic64_add(long long i, atomic64_t *v)
1785@@ -309,6 +569,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1786 __asm__ __volatile__("@ atomic64_add\n"
1787 "1: ldrexd %0, %H0, [%3]\n"
1788 " adds %Q0, %Q0, %Q4\n"
1789+" adcs %R0, %R0, %R4\n"
1790+
1791+#ifdef CONFIG_PAX_REFCOUNT
1792+" bvc 3f\n"
1793+"2: bkpt 0xf103\n"
1794+"3:\n"
1795+#endif
1796+
1797+" strexd %1, %0, %H0, [%3]\n"
1798+" teq %1, #0\n"
1799+" bne 1b"
1800+
1801+#ifdef CONFIG_PAX_REFCOUNT
1802+"\n4:\n"
1803+ _ASM_EXTABLE(2b, 4b)
1804+#endif
1805+
1806+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1807+ : "r" (&v->counter), "r" (i)
1808+ : "cc");
1809+}
1810+
1811+static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1812+{
1813+ long long result;
1814+ unsigned long tmp;
1815+
1816+ prefetchw(&v->counter);
1817+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1818+"1: ldrexd %0, %H0, [%3]\n"
1819+" adds %Q0, %Q0, %Q4\n"
1820 " adc %R0, %R0, %R4\n"
1821 " strexd %1, %0, %H0, [%3]\n"
1822 " teq %1, #0\n"
1823@@ -329,6 +620,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1824 __asm__ __volatile__("@ atomic64_add_return\n"
1825 "1: ldrexd %0, %H0, [%3]\n"
1826 " adds %Q0, %Q0, %Q4\n"
1827+" adcs %R0, %R0, %R4\n"
1828+
1829+#ifdef CONFIG_PAX_REFCOUNT
1830+" bvc 3f\n"
1831+" mov %0, %1\n"
1832+" mov %H0, %H1\n"
1833+"2: bkpt 0xf103\n"
1834+"3:\n"
1835+#endif
1836+
1837+" strexd %1, %0, %H0, [%3]\n"
1838+" teq %1, #0\n"
1839+" bne 1b"
1840+
1841+#ifdef CONFIG_PAX_REFCOUNT
1842+"\n4:\n"
1843+ _ASM_EXTABLE(2b, 4b)
1844+#endif
1845+
1846+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1847+ : "r" (&v->counter), "r" (i)
1848+ : "cc");
1849+
1850+ smp_mb();
1851+
1852+ return result;
1853+}
1854+
1855+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1856+{
1857+ long long result;
1858+ unsigned long tmp;
1859+
1860+ smp_mb();
1861+
1862+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1863+"1: ldrexd %0, %H0, [%3]\n"
1864+" adds %Q0, %Q0, %Q4\n"
1865 " adc %R0, %R0, %R4\n"
1866 " strexd %1, %0, %H0, [%3]\n"
1867 " teq %1, #0\n"
1868@@ -351,6 +680,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1869 __asm__ __volatile__("@ atomic64_sub\n"
1870 "1: ldrexd %0, %H0, [%3]\n"
1871 " subs %Q0, %Q0, %Q4\n"
1872+" sbcs %R0, %R0, %R4\n"
1873+
1874+#ifdef CONFIG_PAX_REFCOUNT
1875+" bvc 3f\n"
1876+"2: bkpt 0xf103\n"
1877+"3:\n"
1878+#endif
1879+
1880+" strexd %1, %0, %H0, [%3]\n"
1881+" teq %1, #0\n"
1882+" bne 1b"
1883+
1884+#ifdef CONFIG_PAX_REFCOUNT
1885+"\n4:\n"
1886+ _ASM_EXTABLE(2b, 4b)
1887+#endif
1888+
1889+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1890+ : "r" (&v->counter), "r" (i)
1891+ : "cc");
1892+}
1893+
1894+static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1895+{
1896+ long long result;
1897+ unsigned long tmp;
1898+
1899+ prefetchw(&v->counter);
1900+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1901+"1: ldrexd %0, %H0, [%3]\n"
1902+" subs %Q0, %Q0, %Q4\n"
1903 " sbc %R0, %R0, %R4\n"
1904 " strexd %1, %0, %H0, [%3]\n"
1905 " teq %1, #0\n"
1906@@ -371,16 +731,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1907 __asm__ __volatile__("@ atomic64_sub_return\n"
1908 "1: ldrexd %0, %H0, [%3]\n"
1909 " subs %Q0, %Q0, %Q4\n"
1910-" sbc %R0, %R0, %R4\n"
1911+" sbcs %R0, %R0, %R4\n"
1912+
1913+#ifdef CONFIG_PAX_REFCOUNT
1914+" bvc 3f\n"
1915+" mov %0, %1\n"
1916+" mov %H0, %H1\n"
1917+"2: bkpt 0xf103\n"
1918+"3:\n"
1919+#endif
1920+
1921 " strexd %1, %0, %H0, [%3]\n"
1922 " teq %1, #0\n"
1923 " bne 1b"
1924+
1925+#ifdef CONFIG_PAX_REFCOUNT
1926+"\n4:\n"
1927+ _ASM_EXTABLE(2b, 4b)
1928+#endif
1929+
1930 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1931 : "r" (&v->counter), "r" (i)
1932 : "cc");
1933
1934- smp_mb();
1935-
1936 return result;
1937 }
1938
1939@@ -410,6 +783,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1940 return oldval;
1941 }
1942
1943+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1944+ long long new)
1945+{
1946+ long long oldval;
1947+ unsigned long res;
1948+
1949+ smp_mb();
1950+
1951+ do {
1952+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1953+ "ldrexd %1, %H1, [%3]\n"
1954+ "mov %0, #0\n"
1955+ "teq %1, %4\n"
1956+ "teqeq %H1, %H4\n"
1957+ "strexdeq %0, %5, %H5, [%3]"
1958+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1959+ : "r" (&ptr->counter), "r" (old), "r" (new)
1960+ : "cc");
1961+ } while (res);
1962+
1963+ smp_mb();
1964+
1965+ return oldval;
1966+}
1967+
1968 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1969 {
1970 long long result;
1971@@ -435,21 +833,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1972 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1973 {
1974 long long result;
1975- unsigned long tmp;
1976+ u64 tmp;
1977
1978 smp_mb();
1979 prefetchw(&v->counter);
1980
1981 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1982-"1: ldrexd %0, %H0, [%3]\n"
1983-" subs %Q0, %Q0, #1\n"
1984-" sbc %R0, %R0, #0\n"
1985+"1: ldrexd %1, %H1, [%3]\n"
1986+" subs %Q0, %Q1, #1\n"
1987+" sbcs %R0, %R1, #0\n"
1988+
1989+#ifdef CONFIG_PAX_REFCOUNT
1990+" bvc 3f\n"
1991+" mov %Q0, %Q1\n"
1992+" mov %R0, %R1\n"
1993+"2: bkpt 0xf103\n"
1994+"3:\n"
1995+#endif
1996+
1997 " teq %R0, #0\n"
1998-" bmi 2f\n"
1999+" bmi 4f\n"
2000 " strexd %1, %0, %H0, [%3]\n"
2001 " teq %1, #0\n"
2002 " bne 1b\n"
2003-"2:"
2004+"4:\n"
2005+
2006+#ifdef CONFIG_PAX_REFCOUNT
2007+ _ASM_EXTABLE(2b, 4b)
2008+#endif
2009+
2010 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
2011 : "r" (&v->counter)
2012 : "cc");
2013@@ -473,13 +885,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
2014 " teq %0, %5\n"
2015 " teqeq %H0, %H5\n"
2016 " moveq %1, #0\n"
2017-" beq 2f\n"
2018+" beq 4f\n"
2019 " adds %Q0, %Q0, %Q6\n"
2020-" adc %R0, %R0, %R6\n"
2021+" adcs %R0, %R0, %R6\n"
2022+
2023+#ifdef CONFIG_PAX_REFCOUNT
2024+" bvc 3f\n"
2025+"2: bkpt 0xf103\n"
2026+"3:\n"
2027+#endif
2028+
2029 " strexd %2, %0, %H0, [%4]\n"
2030 " teq %2, #0\n"
2031 " bne 1b\n"
2032-"2:"
2033+"4:\n"
2034+
2035+#ifdef CONFIG_PAX_REFCOUNT
2036+ _ASM_EXTABLE(2b, 4b)
2037+#endif
2038+
2039 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
2040 : "r" (&v->counter), "r" (u), "r" (a)
2041 : "cc");
2042@@ -492,10 +916,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
2043
2044 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
2045 #define atomic64_inc(v) atomic64_add(1LL, (v))
2046+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
2047 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
2048+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
2049 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
2050 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
2051 #define atomic64_dec(v) atomic64_sub(1LL, (v))
2052+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
2053 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
2054 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
2055 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
2056diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
2057index c6a3e73..35cca85 100644
2058--- a/arch/arm/include/asm/barrier.h
2059+++ b/arch/arm/include/asm/barrier.h
2060@@ -63,7 +63,7 @@
2061 do { \
2062 compiletime_assert_atomic_type(*p); \
2063 smp_mb(); \
2064- ACCESS_ONCE(*p) = (v); \
2065+ ACCESS_ONCE_RW(*p) = (v); \
2066 } while (0)
2067
2068 #define smp_load_acquire(p) \
2069diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
2070index 75fe66b..ba3dee4 100644
2071--- a/arch/arm/include/asm/cache.h
2072+++ b/arch/arm/include/asm/cache.h
2073@@ -4,8 +4,10 @@
2074 #ifndef __ASMARM_CACHE_H
2075 #define __ASMARM_CACHE_H
2076
2077+#include <linux/const.h>
2078+
2079 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
2080-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2081+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2082
2083 /*
2084 * Memory returned by kmalloc() may be used for DMA, so we must make
2085@@ -24,5 +26,6 @@
2086 #endif
2087
2088 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2089+#define __read_only __attribute__ ((__section__(".data..read_only")))
2090
2091 #endif
2092diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
2093index fd43f7f..a817f5a 100644
2094--- a/arch/arm/include/asm/cacheflush.h
2095+++ b/arch/arm/include/asm/cacheflush.h
2096@@ -116,7 +116,7 @@ struct cpu_cache_fns {
2097 void (*dma_unmap_area)(const void *, size_t, int);
2098
2099 void (*dma_flush_range)(const void *, const void *);
2100-};
2101+} __no_const;
2102
2103 /*
2104 * Select the calling method
2105diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
2106index 5233151..87a71fa 100644
2107--- a/arch/arm/include/asm/checksum.h
2108+++ b/arch/arm/include/asm/checksum.h
2109@@ -37,7 +37,19 @@ __wsum
2110 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
2111
2112 __wsum
2113-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
2114+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
2115+
2116+static inline __wsum
2117+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
2118+{
2119+ __wsum ret;
2120+ pax_open_userland();
2121+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
2122+ pax_close_userland();
2123+ return ret;
2124+}
2125+
2126+
2127
2128 /*
2129 * Fold a partial checksum without adding pseudo headers
2130diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
2131index abb2c37..96db950 100644
2132--- a/arch/arm/include/asm/cmpxchg.h
2133+++ b/arch/arm/include/asm/cmpxchg.h
2134@@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
2135
2136 #define xchg(ptr,x) \
2137 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
2138+#define xchg_unchecked(ptr,x) \
2139+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
2140
2141 #include <asm-generic/cmpxchg-local.h>
2142
2143diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
2144index 6ddbe44..b5e38b1 100644
2145--- a/arch/arm/include/asm/domain.h
2146+++ b/arch/arm/include/asm/domain.h
2147@@ -48,18 +48,37 @@
2148 * Domain types
2149 */
2150 #define DOMAIN_NOACCESS 0
2151-#define DOMAIN_CLIENT 1
2152 #ifdef CONFIG_CPU_USE_DOMAINS
2153+#define DOMAIN_USERCLIENT 1
2154+#define DOMAIN_KERNELCLIENT 1
2155 #define DOMAIN_MANAGER 3
2156+#define DOMAIN_VECTORS DOMAIN_USER
2157 #else
2158+
2159+#ifdef CONFIG_PAX_KERNEXEC
2160 #define DOMAIN_MANAGER 1
2161+#define DOMAIN_KERNEXEC 3
2162+#else
2163+#define DOMAIN_MANAGER 1
2164+#endif
2165+
2166+#ifdef CONFIG_PAX_MEMORY_UDEREF
2167+#define DOMAIN_USERCLIENT 0
2168+#define DOMAIN_UDEREF 1
2169+#define DOMAIN_VECTORS DOMAIN_KERNEL
2170+#else
2171+#define DOMAIN_USERCLIENT 1
2172+#define DOMAIN_VECTORS DOMAIN_USER
2173+#endif
2174+#define DOMAIN_KERNELCLIENT 1
2175+
2176 #endif
2177
2178 #define domain_val(dom,type) ((type) << (2*(dom)))
2179
2180 #ifndef __ASSEMBLY__
2181
2182-#ifdef CONFIG_CPU_USE_DOMAINS
2183+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2184 static inline void set_domain(unsigned val)
2185 {
2186 asm volatile(
2187@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
2188 isb();
2189 }
2190
2191-#define modify_domain(dom,type) \
2192- do { \
2193- struct thread_info *thread = current_thread_info(); \
2194- unsigned int domain = thread->cpu_domain; \
2195- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
2196- thread->cpu_domain = domain | domain_val(dom, type); \
2197- set_domain(thread->cpu_domain); \
2198- } while (0)
2199-
2200+extern void modify_domain(unsigned int dom, unsigned int type);
2201 #else
2202 static inline void set_domain(unsigned val) { }
2203 static inline void modify_domain(unsigned dom, unsigned type) { }
2204diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
2205index f4b46d3..abc9b2b 100644
2206--- a/arch/arm/include/asm/elf.h
2207+++ b/arch/arm/include/asm/elf.h
2208@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
2209 the loader. We need to make sure that it is out of the way of the program
2210 that it will "exec", and that there is sufficient room for the brk. */
2211
2212-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2213+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2214+
2215+#ifdef CONFIG_PAX_ASLR
2216+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
2217+
2218+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
2219+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
2220+#endif
2221
2222 /* When the program starts, a1 contains a pointer to a function to be
2223 registered with atexit, as per the SVR4 ABI. A value of 0 means we
2224@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
2225 extern void elf_set_personality(const struct elf32_hdr *);
2226 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
2227
2228-struct mm_struct;
2229-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2230-#define arch_randomize_brk arch_randomize_brk
2231-
2232 #ifdef CONFIG_MMU
2233 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2234 struct linux_binprm;
2235diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
2236index de53547..52b9a28 100644
2237--- a/arch/arm/include/asm/fncpy.h
2238+++ b/arch/arm/include/asm/fncpy.h
2239@@ -81,7 +81,9 @@
2240 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
2241 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
2242 \
2243+ pax_open_kernel(); \
2244 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
2245+ pax_close_kernel(); \
2246 flush_icache_range((unsigned long)(dest_buf), \
2247 (unsigned long)(dest_buf) + (size)); \
2248 \
2249diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
2250index 53e69da..3fdc896 100644
2251--- a/arch/arm/include/asm/futex.h
2252+++ b/arch/arm/include/asm/futex.h
2253@@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
2254 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
2255 return -EFAULT;
2256
2257+ pax_open_userland();
2258+
2259 smp_mb();
2260 /* Prefetching cannot fault */
2261 prefetchw(uaddr);
2262@@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
2263 : "cc", "memory");
2264 smp_mb();
2265
2266+ pax_close_userland();
2267+
2268 *uval = val;
2269 return ret;
2270 }
2271@@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
2272 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
2273 return -EFAULT;
2274
2275+ pax_open_userland();
2276+
2277 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
2278 "1: " TUSER(ldr) " %1, [%4]\n"
2279 " teq %1, %2\n"
2280@@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
2281 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
2282 : "cc", "memory");
2283
2284+ pax_close_userland();
2285+
2286 *uval = val;
2287 return ret;
2288 }
2289@@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
2290 return -EFAULT;
2291
2292 pagefault_disable(); /* implies preempt_disable() */
2293+ pax_open_userland();
2294
2295 switch (op) {
2296 case FUTEX_OP_SET:
2297@@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
2298 ret = -ENOSYS;
2299 }
2300
2301+ pax_close_userland();
2302 pagefault_enable(); /* subsumes preempt_enable() */
2303
2304 if (!ret) {
2305diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
2306index 83eb2f7..ed77159 100644
2307--- a/arch/arm/include/asm/kmap_types.h
2308+++ b/arch/arm/include/asm/kmap_types.h
2309@@ -4,6 +4,6 @@
2310 /*
2311 * This is the "bare minimum". AIO seems to require this.
2312 */
2313-#define KM_TYPE_NR 16
2314+#define KM_TYPE_NR 17
2315
2316 #endif
2317diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
2318index 9e614a1..3302cca 100644
2319--- a/arch/arm/include/asm/mach/dma.h
2320+++ b/arch/arm/include/asm/mach/dma.h
2321@@ -22,7 +22,7 @@ struct dma_ops {
2322 int (*residue)(unsigned int, dma_t *); /* optional */
2323 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
2324 const char *type;
2325-};
2326+} __do_const;
2327
2328 struct dma_struct {
2329 void *addr; /* single DMA address */
2330diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
2331index f98c7f3..e5c626d 100644
2332--- a/arch/arm/include/asm/mach/map.h
2333+++ b/arch/arm/include/asm/mach/map.h
2334@@ -23,17 +23,19 @@ struct map_desc {
2335
2336 /* types 0-3 are defined in asm/io.h */
2337 enum {
2338- MT_UNCACHED = 4,
2339- MT_CACHECLEAN,
2340- MT_MINICLEAN,
2341+ MT_UNCACHED_RW = 4,
2342+ MT_CACHECLEAN_RO,
2343+ MT_MINICLEAN_RO,
2344 MT_LOW_VECTORS,
2345 MT_HIGH_VECTORS,
2346- MT_MEMORY_RWX,
2347+ __MT_MEMORY_RWX,
2348 MT_MEMORY_RW,
2349- MT_ROM,
2350- MT_MEMORY_RWX_NONCACHED,
2351+ MT_MEMORY_RX,
2352+ MT_ROM_RX,
2353+ MT_MEMORY_RW_NONCACHED,
2354+ MT_MEMORY_RX_NONCACHED,
2355 MT_MEMORY_RW_DTCM,
2356- MT_MEMORY_RWX_ITCM,
2357+ MT_MEMORY_RX_ITCM,
2358 MT_MEMORY_RW_SO,
2359 MT_MEMORY_DMA_READY,
2360 };
2361diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
2362index 891a56b..48f337e 100644
2363--- a/arch/arm/include/asm/outercache.h
2364+++ b/arch/arm/include/asm/outercache.h
2365@@ -36,7 +36,7 @@ struct outer_cache_fns {
2366
2367 /* This is an ARM L2C thing */
2368 void (*write_sec)(unsigned long, unsigned);
2369-};
2370+} __no_const;
2371
2372 extern struct outer_cache_fns outer_cache;
2373
2374diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
2375index 4355f0e..cd9168e 100644
2376--- a/arch/arm/include/asm/page.h
2377+++ b/arch/arm/include/asm/page.h
2378@@ -23,6 +23,7 @@
2379
2380 #else
2381
2382+#include <linux/compiler.h>
2383 #include <asm/glue.h>
2384
2385 /*
2386@@ -114,7 +115,7 @@ struct cpu_user_fns {
2387 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
2388 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
2389 unsigned long vaddr, struct vm_area_struct *vma);
2390-};
2391+} __no_const;
2392
2393 #ifdef MULTI_USER
2394 extern struct cpu_user_fns cpu_user;
2395diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
2396index 78a7793..e3dc06c 100644
2397--- a/arch/arm/include/asm/pgalloc.h
2398+++ b/arch/arm/include/asm/pgalloc.h
2399@@ -17,6 +17,7 @@
2400 #include <asm/processor.h>
2401 #include <asm/cacheflush.h>
2402 #include <asm/tlbflush.h>
2403+#include <asm/system_info.h>
2404
2405 #define check_pgt_cache() do { } while (0)
2406
2407@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2408 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
2409 }
2410
2411+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2412+{
2413+ pud_populate(mm, pud, pmd);
2414+}
2415+
2416 #else /* !CONFIG_ARM_LPAE */
2417
2418 /*
2419@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2420 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
2421 #define pmd_free(mm, pmd) do { } while (0)
2422 #define pud_populate(mm,pmd,pte) BUG()
2423+#define pud_populate_kernel(mm,pmd,pte) BUG()
2424
2425 #endif /* CONFIG_ARM_LPAE */
2426
2427@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
2428 __free_page(pte);
2429 }
2430
2431+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
2432+{
2433+#ifdef CONFIG_ARM_LPAE
2434+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2435+#else
2436+ if (addr & SECTION_SIZE)
2437+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
2438+ else
2439+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2440+#endif
2441+ flush_pmd_entry(pmdp);
2442+}
2443+
2444 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
2445 pmdval_t prot)
2446 {
2447@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
2448 static inline void
2449 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
2450 {
2451- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
2452+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
2453 }
2454 #define pmd_pgtable(pmd) pmd_page(pmd)
2455
2456diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
2457index 5cfba15..f415e1a 100644
2458--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
2459+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
2460@@ -20,12 +20,15 @@
2461 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
2462 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
2463 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
2464+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
2465 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
2466 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
2467 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
2468+
2469 /*
2470 * - section
2471 */
2472+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
2473 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
2474 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
2475 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
2476@@ -37,6 +40,7 @@
2477 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
2478 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
2479 #define PMD_SECT_AF (_AT(pmdval_t, 0))
2480+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
2481
2482 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
2483 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
2484@@ -66,6 +70,7 @@
2485 * - extended small page/tiny page
2486 */
2487 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
2488+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
2489 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
2490 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
2491 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
2492diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
2493index 219ac88..73ec32a 100644
2494--- a/arch/arm/include/asm/pgtable-2level.h
2495+++ b/arch/arm/include/asm/pgtable-2level.h
2496@@ -126,6 +126,9 @@
2497 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
2498 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
2499
2500+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2501+#define L_PTE_PXN (_AT(pteval_t, 0))
2502+
2503 /*
2504 * These are the memory types, defined to be compatible with
2505 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2506diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2507index 626989f..9d67a33 100644
2508--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2509+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2510@@ -75,6 +75,7 @@
2511 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2512 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2513 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2514+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2515 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2516
2517 /*
2518diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2519index 85c60ad..b0bbd7e 100644
2520--- a/arch/arm/include/asm/pgtable-3level.h
2521+++ b/arch/arm/include/asm/pgtable-3level.h
2522@@ -82,6 +82,7 @@
2523 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
2524 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2525 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2526+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2527 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2528 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2529 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2530@@ -95,6 +96,7 @@
2531 /*
2532 * To be used in assembly code with the upper page attributes.
2533 */
2534+#define L_PTE_PXN_HIGH (1 << (53 - 32))
2535 #define L_PTE_XN_HIGH (1 << (54 - 32))
2536 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2537
2538diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2539index 5478e5d..f5b5cb3 100644
2540--- a/arch/arm/include/asm/pgtable.h
2541+++ b/arch/arm/include/asm/pgtable.h
2542@@ -33,6 +33,9 @@
2543 #include <asm/pgtable-2level.h>
2544 #endif
2545
2546+#define ktla_ktva(addr) (addr)
2547+#define ktva_ktla(addr) (addr)
2548+
2549 /*
2550 * Just any arbitrary offset to the start of the vmalloc VM area: the
2551 * current 8MB value just means that there will be a 8MB "hole" after the
2552@@ -48,6 +51,9 @@
2553 #define LIBRARY_TEXT_START 0x0c000000
2554
2555 #ifndef __ASSEMBLY__
2556+extern pteval_t __supported_pte_mask;
2557+extern pmdval_t __supported_pmd_mask;
2558+
2559 extern void __pte_error(const char *file, int line, pte_t);
2560 extern void __pmd_error(const char *file, int line, pmd_t);
2561 extern void __pgd_error(const char *file, int line, pgd_t);
2562@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2563 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2564 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2565
2566+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2567+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2568+
2569+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2570+#include <asm/domain.h>
2571+#include <linux/thread_info.h>
2572+#include <linux/preempt.h>
2573+
2574+static inline int test_domain(int domain, int domaintype)
2575+{
2576+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2577+}
2578+#endif
2579+
2580+#ifdef CONFIG_PAX_KERNEXEC
2581+static inline unsigned long pax_open_kernel(void) {
2582+#ifdef CONFIG_ARM_LPAE
2583+ /* TODO */
2584+#else
2585+ preempt_disable();
2586+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2587+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2588+#endif
2589+ return 0;
2590+}
2591+
2592+static inline unsigned long pax_close_kernel(void) {
2593+#ifdef CONFIG_ARM_LPAE
2594+ /* TODO */
2595+#else
2596+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2597+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2598+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2599+ preempt_enable_no_resched();
2600+#endif
2601+ return 0;
2602+}
2603+#else
2604+static inline unsigned long pax_open_kernel(void) { return 0; }
2605+static inline unsigned long pax_close_kernel(void) { return 0; }
2606+#endif
2607+
2608 /*
2609 * This is the lowest virtual address we can permit any user space
2610 * mapping to be mapped at. This is particularly important for
2611@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2612 /*
2613 * The pgprot_* and protection_map entries will be fixed up in runtime
2614 * to include the cachable and bufferable bits based on memory policy,
2615- * as well as any architecture dependent bits like global/ASID and SMP
2616- * shared mapping bits.
2617+ * as well as any architecture dependent bits like global/ASID, PXN,
2618+ * and SMP shared mapping bits.
2619 */
2620 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2621
2622@@ -265,7 +313,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2623 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2624 {
2625 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2626- L_PTE_NONE | L_PTE_VALID;
2627+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2628 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2629 return pte;
2630 }
2631diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2632index c25ef3e..735f14b 100644
2633--- a/arch/arm/include/asm/psci.h
2634+++ b/arch/arm/include/asm/psci.h
2635@@ -32,7 +32,7 @@ struct psci_operations {
2636 int (*affinity_info)(unsigned long target_affinity,
2637 unsigned long lowest_affinity_level);
2638 int (*migrate_info_type)(void);
2639-};
2640+} __no_const;
2641
2642 extern struct psci_operations psci_ops;
2643 extern struct smp_operations psci_smp_ops;
2644diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2645index 2ec765c..beb1fe16 100644
2646--- a/arch/arm/include/asm/smp.h
2647+++ b/arch/arm/include/asm/smp.h
2648@@ -113,7 +113,7 @@ struct smp_operations {
2649 int (*cpu_disable)(unsigned int cpu);
2650 #endif
2651 #endif
2652-};
2653+} __no_const;
2654
2655 struct of_cpu_method {
2656 const char *method;
2657diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2658index e4e4208..086684a 100644
2659--- a/arch/arm/include/asm/thread_info.h
2660+++ b/arch/arm/include/asm/thread_info.h
2661@@ -88,9 +88,9 @@ struct thread_info {
2662 .flags = 0, \
2663 .preempt_count = INIT_PREEMPT_COUNT, \
2664 .addr_limit = KERNEL_DS, \
2665- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2666- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2667- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2668+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2669+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2670+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2671 .restart_block = { \
2672 .fn = do_no_restart_syscall, \
2673 }, \
2674@@ -164,7 +164,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2675 #define TIF_SYSCALL_AUDIT 9
2676 #define TIF_SYSCALL_TRACEPOINT 10
2677 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2678-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2679+/* within 8 bits of TIF_SYSCALL_TRACE
2680+ * to meet flexible second operand requirements
2681+ */
2682+#define TIF_GRSEC_SETXID 12
2683+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2684 #define TIF_USING_IWMMXT 17
2685 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2686 #define TIF_RESTORE_SIGMASK 20
2687@@ -178,10 +182,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2688 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2689 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2690 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2691+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2692
2693 /* Checks for any syscall work in entry-common.S */
2694 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2695- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2696+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2697
2698 /*
2699 * Change these and you break ASM code in entry-common.S
2700diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2701index 75d9579..b5b40e4 100644
2702--- a/arch/arm/include/asm/uaccess.h
2703+++ b/arch/arm/include/asm/uaccess.h
2704@@ -18,6 +18,7 @@
2705 #include <asm/domain.h>
2706 #include <asm/unified.h>
2707 #include <asm/compiler.h>
2708+#include <asm/pgtable.h>
2709
2710 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2711 #include <asm-generic/uaccess-unaligned.h>
2712@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2713 static inline void set_fs(mm_segment_t fs)
2714 {
2715 current_thread_info()->addr_limit = fs;
2716- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2717+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2718 }
2719
2720 #define segment_eq(a,b) ((a) == (b))
2721
2722+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2723+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2724+
2725+static inline void pax_open_userland(void)
2726+{
2727+
2728+#ifdef CONFIG_PAX_MEMORY_UDEREF
2729+ if (segment_eq(get_fs(), USER_DS)) {
2730+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2731+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2732+ }
2733+#endif
2734+
2735+}
2736+
2737+static inline void pax_close_userland(void)
2738+{
2739+
2740+#ifdef CONFIG_PAX_MEMORY_UDEREF
2741+ if (segment_eq(get_fs(), USER_DS)) {
2742+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2743+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2744+ }
2745+#endif
2746+
2747+}
2748+
2749 #define __addr_ok(addr) ({ \
2750 unsigned long flag; \
2751 __asm__("cmp %2, %0; movlo %0, #0" \
2752@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2753
2754 #define get_user(x,p) \
2755 ({ \
2756+ int __e; \
2757 might_fault(); \
2758- __get_user_check(x,p); \
2759+ pax_open_userland(); \
2760+ __e = __get_user_check(x,p); \
2761+ pax_close_userland(); \
2762+ __e; \
2763 })
2764
2765 extern int __put_user_1(void *, unsigned int);
2766@@ -196,8 +228,12 @@ extern int __put_user_8(void *, unsigned long long);
2767
2768 #define put_user(x,p) \
2769 ({ \
2770+ int __e; \
2771 might_fault(); \
2772- __put_user_check(x,p); \
2773+ pax_open_userland(); \
2774+ __e = __put_user_check(x,p); \
2775+ pax_close_userland(); \
2776+ __e; \
2777 })
2778
2779 #else /* CONFIG_MMU */
2780@@ -221,6 +257,7 @@ static inline void set_fs(mm_segment_t fs)
2781
2782 #endif /* CONFIG_MMU */
2783
2784+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2785 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2786
2787 #define user_addr_max() \
2788@@ -238,13 +275,17 @@ static inline void set_fs(mm_segment_t fs)
2789 #define __get_user(x,ptr) \
2790 ({ \
2791 long __gu_err = 0; \
2792+ pax_open_userland(); \
2793 __get_user_err((x),(ptr),__gu_err); \
2794+ pax_close_userland(); \
2795 __gu_err; \
2796 })
2797
2798 #define __get_user_error(x,ptr,err) \
2799 ({ \
2800+ pax_open_userland(); \
2801 __get_user_err((x),(ptr),err); \
2802+ pax_close_userland(); \
2803 (void) 0; \
2804 })
2805
2806@@ -320,13 +361,17 @@ do { \
2807 #define __put_user(x,ptr) \
2808 ({ \
2809 long __pu_err = 0; \
2810+ pax_open_userland(); \
2811 __put_user_err((x),(ptr),__pu_err); \
2812+ pax_close_userland(); \
2813 __pu_err; \
2814 })
2815
2816 #define __put_user_error(x,ptr,err) \
2817 ({ \
2818+ pax_open_userland(); \
2819 __put_user_err((x),(ptr),err); \
2820+ pax_close_userland(); \
2821 (void) 0; \
2822 })
2823
2824@@ -426,11 +471,44 @@ do { \
2825
2826
2827 #ifdef CONFIG_MMU
2828-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2829-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2830+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2831+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2832+
2833+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2834+{
2835+ unsigned long ret;
2836+
2837+ check_object_size(to, n, false);
2838+ pax_open_userland();
2839+ ret = ___copy_from_user(to, from, n);
2840+ pax_close_userland();
2841+ return ret;
2842+}
2843+
2844+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2845+{
2846+ unsigned long ret;
2847+
2848+ check_object_size(from, n, true);
2849+ pax_open_userland();
2850+ ret = ___copy_to_user(to, from, n);
2851+ pax_close_userland();
2852+ return ret;
2853+}
2854+
2855 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2856-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2857+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2858 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2859+
2860+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2861+{
2862+ unsigned long ret;
2863+ pax_open_userland();
2864+ ret = ___clear_user(addr, n);
2865+ pax_close_userland();
2866+ return ret;
2867+}
2868+
2869 #else
2870 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2871 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2872@@ -439,6 +517,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2873
2874 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2875 {
2876+ if ((long)n < 0)
2877+ return n;
2878+
2879 if (access_ok(VERIFY_READ, from, n))
2880 n = __copy_from_user(to, from, n);
2881 else /* security hole - plug it */
2882@@ -448,6 +529,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2883
2884 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2885 {
2886+ if ((long)n < 0)
2887+ return n;
2888+
2889 if (access_ok(VERIFY_WRITE, to, n))
2890 n = __copy_to_user(to, from, n);
2891 return n;
2892diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2893index 5af0ed1..cea83883 100644
2894--- a/arch/arm/include/uapi/asm/ptrace.h
2895+++ b/arch/arm/include/uapi/asm/ptrace.h
2896@@ -92,7 +92,7 @@
2897 * ARMv7 groups of PSR bits
2898 */
2899 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2900-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2901+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2902 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2903 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2904
2905diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2906index f7b450f..f5364c5 100644
2907--- a/arch/arm/kernel/armksyms.c
2908+++ b/arch/arm/kernel/armksyms.c
2909@@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2910
2911 /* networking */
2912 EXPORT_SYMBOL(csum_partial);
2913-EXPORT_SYMBOL(csum_partial_copy_from_user);
2914+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2915 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2916 EXPORT_SYMBOL(__csum_ipv6_magic);
2917
2918@@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2919 #ifdef CONFIG_MMU
2920 EXPORT_SYMBOL(copy_page);
2921
2922-EXPORT_SYMBOL(__copy_from_user);
2923-EXPORT_SYMBOL(__copy_to_user);
2924-EXPORT_SYMBOL(__clear_user);
2925+EXPORT_SYMBOL(___copy_from_user);
2926+EXPORT_SYMBOL(___copy_to_user);
2927+EXPORT_SYMBOL(___clear_user);
2928
2929 EXPORT_SYMBOL(__get_user_1);
2930 EXPORT_SYMBOL(__get_user_2);
2931diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2932index 52a949a..d8bbcab 100644
2933--- a/arch/arm/kernel/entry-armv.S
2934+++ b/arch/arm/kernel/entry-armv.S
2935@@ -47,6 +47,87 @@
2936 9997:
2937 .endm
2938
2939+ .macro pax_enter_kernel
2940+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2941+ @ make aligned space for saved DACR
2942+ sub sp, sp, #8
2943+ @ save regs
2944+ stmdb sp!, {r1, r2}
2945+ @ read DACR from cpu_domain into r1
2946+ mov r2, sp
2947+ @ assume 8K pages, since we have to split the immediate in two
2948+ bic r2, r2, #(0x1fc0)
2949+ bic r2, r2, #(0x3f)
2950+ ldr r1, [r2, #TI_CPU_DOMAIN]
2951+ @ store old DACR on stack
2952+ str r1, [sp, #8]
2953+#ifdef CONFIG_PAX_KERNEXEC
2954+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2955+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2956+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2957+#endif
2958+#ifdef CONFIG_PAX_MEMORY_UDEREF
2959+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2960+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2961+#endif
2962+ @ write r1 to current_thread_info()->cpu_domain
2963+ str r1, [r2, #TI_CPU_DOMAIN]
2964+ @ write r1 to DACR
2965+ mcr p15, 0, r1, c3, c0, 0
2966+ @ instruction sync
2967+ instr_sync
2968+ @ restore regs
2969+ ldmia sp!, {r1, r2}
2970+#endif
2971+ .endm
2972+
2973+ .macro pax_open_userland
2974+#ifdef CONFIG_PAX_MEMORY_UDEREF
2975+ @ save regs
2976+ stmdb sp!, {r0, r1}
2977+ @ read DACR from cpu_domain into r1
2978+ mov r0, sp
2979+ @ assume 8K pages, since we have to split the immediate in two
2980+ bic r0, r0, #(0x1fc0)
2981+ bic r0, r0, #(0x3f)
2982+ ldr r1, [r0, #TI_CPU_DOMAIN]
2983+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2984+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2985+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2986+ @ write r1 to current_thread_info()->cpu_domain
2987+ str r1, [r0, #TI_CPU_DOMAIN]
2988+ @ write r1 to DACR
2989+ mcr p15, 0, r1, c3, c0, 0
2990+ @ instruction sync
2991+ instr_sync
2992+ @ restore regs
2993+ ldmia sp!, {r0, r1}
2994+#endif
2995+ .endm
2996+
2997+ .macro pax_close_userland
2998+#ifdef CONFIG_PAX_MEMORY_UDEREF
2999+ @ save regs
3000+ stmdb sp!, {r0, r1}
3001+ @ read DACR from cpu_domain into r1
3002+ mov r0, sp
3003+ @ assume 8K pages, since we have to split the immediate in two
3004+ bic r0, r0, #(0x1fc0)
3005+ bic r0, r0, #(0x3f)
3006+ ldr r1, [r0, #TI_CPU_DOMAIN]
3007+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
3008+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
3009+ @ write r1 to current_thread_info()->cpu_domain
3010+ str r1, [r0, #TI_CPU_DOMAIN]
3011+ @ write r1 to DACR
3012+ mcr p15, 0, r1, c3, c0, 0
3013+ @ instruction sync
3014+ instr_sync
3015+ @ restore regs
3016+ ldmia sp!, {r0, r1}
3017+#endif
3018+ .endm
3019+
3020 .macro pabt_helper
3021 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
3022 #ifdef MULTI_PABORT
3023@@ -89,11 +170,15 @@
3024 * Invalid mode handlers
3025 */
3026 .macro inv_entry, reason
3027+
3028+ pax_enter_kernel
3029+
3030 sub sp, sp, #S_FRAME_SIZE
3031 ARM( stmib sp, {r1 - lr} )
3032 THUMB( stmia sp, {r0 - r12} )
3033 THUMB( str sp, [sp, #S_SP] )
3034 THUMB( str lr, [sp, #S_LR] )
3035+
3036 mov r1, #\reason
3037 .endm
3038
3039@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
3040 .macro svc_entry, stack_hole=0
3041 UNWIND(.fnstart )
3042 UNWIND(.save {r0 - pc} )
3043+
3044+ pax_enter_kernel
3045+
3046 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
3047+
3048 #ifdef CONFIG_THUMB2_KERNEL
3049 SPFIX( str r0, [sp] ) @ temporarily saved
3050 SPFIX( mov r0, sp )
3051@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
3052 ldmia r0, {r3 - r5}
3053 add r7, sp, #S_SP - 4 @ here for interlock avoidance
3054 mov r6, #-1 @ "" "" "" ""
3055+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3056+ @ offset sp by 8 as done in pax_enter_kernel
3057+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
3058+#else
3059 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
3060+#endif
3061 SPFIX( addeq r2, r2, #4 )
3062 str r3, [sp, #-4]! @ save the "real" r0 copied
3063 @ from the exception stack
3064@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
3065 .macro usr_entry
3066 UNWIND(.fnstart )
3067 UNWIND(.cantunwind ) @ don't unwind the user space
3068+
3069+ pax_enter_kernel_user
3070+
3071 sub sp, sp, #S_FRAME_SIZE
3072 ARM( stmib sp, {r1 - r12} )
3073 THUMB( stmia sp, {r0 - r12} )
3074@@ -421,7 +518,9 @@ __und_usr:
3075 tst r3, #PSR_T_BIT @ Thumb mode?
3076 bne __und_usr_thumb
3077 sub r4, r2, #4 @ ARM instr at LR - 4
3078+ pax_open_userland
3079 1: ldrt r0, [r4]
3080+ pax_close_userland
3081 ARM_BE8(rev r0, r0) @ little endian instruction
3082
3083 @ r0 = 32-bit ARM instruction which caused the exception
3084@@ -455,11 +554,15 @@ __und_usr_thumb:
3085 */
3086 .arch armv6t2
3087 #endif
3088+ pax_open_userland
3089 2: ldrht r5, [r4]
3090+ pax_close_userland
3091 ARM_BE8(rev16 r5, r5) @ little endian instruction
3092 cmp r5, #0xe800 @ 32bit instruction if xx != 0
3093 blo __und_usr_fault_16 @ 16bit undefined instruction
3094+ pax_open_userland
3095 3: ldrht r0, [r2]
3096+ pax_close_userland
3097 ARM_BE8(rev16 r0, r0) @ little endian instruction
3098 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
3099 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
3100@@ -489,7 +592,8 @@ ENDPROC(__und_usr)
3101 */
3102 .pushsection .fixup, "ax"
3103 .align 2
3104-4: str r4, [sp, #S_PC] @ retry current instruction
3105+4: pax_close_userland
3106+ str r4, [sp, #S_PC] @ retry current instruction
3107 mov pc, r9
3108 .popsection
3109 .pushsection __ex_table,"a"
3110@@ -698,7 +802,7 @@ ENTRY(__switch_to)
3111 THUMB( str lr, [ip], #4 )
3112 ldr r4, [r2, #TI_TP_VALUE]
3113 ldr r5, [r2, #TI_TP_VALUE + 4]
3114-#ifdef CONFIG_CPU_USE_DOMAINS
3115+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3116 ldr r6, [r2, #TI_CPU_DOMAIN]
3117 #endif
3118 switch_tls r1, r4, r5, r3, r7
3119@@ -707,7 +811,7 @@ ENTRY(__switch_to)
3120 ldr r8, =__stack_chk_guard
3121 ldr r7, [r7, #TSK_STACK_CANARY]
3122 #endif
3123-#ifdef CONFIG_CPU_USE_DOMAINS
3124+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3125 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
3126 #endif
3127 mov r5, r0
3128diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
3129index 7139d4a..feaf37f 100644
3130--- a/arch/arm/kernel/entry-common.S
3131+++ b/arch/arm/kernel/entry-common.S
3132@@ -10,18 +10,46 @@
3133
3134 #include <asm/unistd.h>
3135 #include <asm/ftrace.h>
3136+#include <asm/domain.h>
3137 #include <asm/unwind.h>
3138
3139+#include "entry-header.S"
3140+
3141 #ifdef CONFIG_NEED_RET_TO_USER
3142 #include <mach/entry-macro.S>
3143 #else
3144 .macro arch_ret_to_user, tmp1, tmp2
3145+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3146+ @ save regs
3147+ stmdb sp!, {r1, r2}
3148+ @ read DACR from cpu_domain into r1
3149+ mov r2, sp
3150+ @ assume 8K pages, since we have to split the immediate in two
3151+ bic r2, r2, #(0x1fc0)
3152+ bic r2, r2, #(0x3f)
3153+ ldr r1, [r2, #TI_CPU_DOMAIN]
3154+#ifdef CONFIG_PAX_KERNEXEC
3155+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
3156+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
3157+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
3158+#endif
3159+#ifdef CONFIG_PAX_MEMORY_UDEREF
3160+ @ set current DOMAIN_USER to DOMAIN_UDEREF
3161+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
3162+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
3163+#endif
3164+ @ write r1 to current_thread_info()->cpu_domain
3165+ str r1, [r2, #TI_CPU_DOMAIN]
3166+ @ write r1 to DACR
3167+ mcr p15, 0, r1, c3, c0, 0
3168+ @ instruction sync
3169+ instr_sync
3170+ @ restore regs
3171+ ldmia sp!, {r1, r2}
3172+#endif
3173 .endm
3174 #endif
3175
3176-#include "entry-header.S"
3177-
3178-
3179 .align 5
3180 /*
3181 * This is the fast syscall return path. We do as little as
3182@@ -405,6 +433,12 @@ ENTRY(vector_swi)
3183 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
3184 #endif
3185
3186+ /*
3187+ * do this here to avoid a performance hit of wrapping the code above
3188+ * that directly dereferences userland to parse the SWI instruction
3189+ */
3190+ pax_enter_kernel_user
3191+
3192 adr tbl, sys_call_table @ load syscall table pointer
3193
3194 #if defined(CONFIG_OABI_COMPAT)
3195diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
3196index 5d702f8..f5fc51a 100644
3197--- a/arch/arm/kernel/entry-header.S
3198+++ b/arch/arm/kernel/entry-header.S
3199@@ -188,6 +188,60 @@
3200 msr cpsr_c, \rtemp @ switch back to the SVC mode
3201 .endm
3202
3203+ .macro pax_enter_kernel_user
3204+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3205+ @ save regs
3206+ stmdb sp!, {r0, r1}
3207+ @ read DACR from cpu_domain into r1
3208+ mov r0, sp
3209+ @ assume 8K pages, since we have to split the immediate in two
3210+ bic r0, r0, #(0x1fc0)
3211+ bic r0, r0, #(0x3f)
3212+ ldr r1, [r0, #TI_CPU_DOMAIN]
3213+#ifdef CONFIG_PAX_MEMORY_UDEREF
3214+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
3215+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
3216+#endif
3217+#ifdef CONFIG_PAX_KERNEXEC
3218+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
3219+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
3220+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
3221+#endif
3222+ @ write r1 to current_thread_info()->cpu_domain
3223+ str r1, [r0, #TI_CPU_DOMAIN]
3224+ @ write r1 to DACR
3225+ mcr p15, 0, r1, c3, c0, 0
3226+ @ instruction sync
3227+ instr_sync
3228+ @ restore regs
3229+ ldmia sp!, {r0, r1}
3230+#endif
3231+ .endm
3232+
3233+ .macro pax_exit_kernel
3234+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3235+ @ save regs
3236+ stmdb sp!, {r0, r1}
3237+ @ read old DACR from stack into r1
3238+ ldr r1, [sp, #(8 + S_SP)]
3239+ sub r1, r1, #8
3240+ ldr r1, [r1]
3241+
3242+ @ write r1 to current_thread_info()->cpu_domain
3243+ mov r0, sp
3244+ @ assume 8K pages, since we have to split the immediate in two
3245+ bic r0, r0, #(0x1fc0)
3246+ bic r0, r0, #(0x3f)
3247+ str r1, [r0, #TI_CPU_DOMAIN]
3248+ @ write r1 to DACR
3249+ mcr p15, 0, r1, c3, c0, 0
3250+ @ instruction sync
3251+ instr_sync
3252+ @ restore regs
3253+ ldmia sp!, {r0, r1}
3254+#endif
3255+ .endm
3256+
3257 #ifndef CONFIG_THUMB2_KERNEL
3258 .macro svc_exit, rpsr, irq = 0
3259 .if \irq != 0
3260@@ -207,6 +261,9 @@
3261 blne trace_hardirqs_off
3262 #endif
3263 .endif
3264+
3265+ pax_exit_kernel
3266+
3267 msr spsr_cxsf, \rpsr
3268 #if defined(CONFIG_CPU_V6)
3269 ldr r0, [sp]
3270@@ -265,6 +322,9 @@
3271 blne trace_hardirqs_off
3272 #endif
3273 .endif
3274+
3275+ pax_exit_kernel
3276+
3277 ldr lr, [sp, #S_SP] @ top of the stack
3278 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
3279 clrex @ clear the exclusive monitor
3280diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
3281index 918875d..cd5fa27 100644
3282--- a/arch/arm/kernel/fiq.c
3283+++ b/arch/arm/kernel/fiq.c
3284@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
3285 void *base = vectors_page;
3286 unsigned offset = FIQ_OFFSET;
3287
3288+ pax_open_kernel();
3289 memcpy(base + offset, start, length);
3290+ pax_close_kernel();
3291+
3292 if (!cache_is_vipt_nonaliasing())
3293 flush_icache_range((unsigned long)base + offset, offset +
3294 length);
3295diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
3296index 2c35f0f..7747ee6 100644
3297--- a/arch/arm/kernel/head.S
3298+++ b/arch/arm/kernel/head.S
3299@@ -437,7 +437,7 @@ __enable_mmu:
3300 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
3301 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
3302 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
3303- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
3304+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
3305 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
3306 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
3307 #endif
3308diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
3309index 45e4781..8eac93d 100644
3310--- a/arch/arm/kernel/module.c
3311+++ b/arch/arm/kernel/module.c
3312@@ -38,12 +38,39 @@
3313 #endif
3314
3315 #ifdef CONFIG_MMU
3316-void *module_alloc(unsigned long size)
3317+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
3318 {
3319+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
3320+ return NULL;
3321 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
3322- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
3323+ GFP_KERNEL, prot, NUMA_NO_NODE,
3324 __builtin_return_address(0));
3325 }
3326+
3327+void *module_alloc(unsigned long size)
3328+{
3329+
3330+#ifdef CONFIG_PAX_KERNEXEC
3331+ return __module_alloc(size, PAGE_KERNEL);
3332+#else
3333+ return __module_alloc(size, PAGE_KERNEL_EXEC);
3334+#endif
3335+
3336+}
3337+
3338+#ifdef CONFIG_PAX_KERNEXEC
3339+void module_free_exec(struct module *mod, void *module_region)
3340+{
3341+ module_free(mod, module_region);
3342+}
3343+EXPORT_SYMBOL(module_free_exec);
3344+
3345+void *module_alloc_exec(unsigned long size)
3346+{
3347+ return __module_alloc(size, PAGE_KERNEL_EXEC);
3348+}
3349+EXPORT_SYMBOL(module_alloc_exec);
3350+#endif
3351 #endif
3352
3353 int
3354diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
3355index 07314af..c46655c 100644
3356--- a/arch/arm/kernel/patch.c
3357+++ b/arch/arm/kernel/patch.c
3358@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
3359 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
3360 int size;
3361
3362+ pax_open_kernel();
3363 if (thumb2 && __opcode_is_thumb16(insn)) {
3364 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
3365 size = sizeof(u16);
3366@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
3367 *(u32 *)addr = insn;
3368 size = sizeof(u32);
3369 }
3370+ pax_close_kernel();
3371
3372 flush_icache_range((uintptr_t)(addr),
3373 (uintptr_t)(addr) + size);
3374diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
3375index 81ef686..f4130b8 100644
3376--- a/arch/arm/kernel/process.c
3377+++ b/arch/arm/kernel/process.c
3378@@ -212,6 +212,7 @@ void machine_power_off(void)
3379
3380 if (pm_power_off)
3381 pm_power_off();
3382+ BUG();
3383 }
3384
3385 /*
3386@@ -225,7 +226,7 @@ void machine_power_off(void)
3387 * executing pre-reset code, and using RAM that the primary CPU's code wishes
3388 * to use. Implementing such co-ordination would be essentially impossible.
3389 */
3390-void machine_restart(char *cmd)
3391+__noreturn void machine_restart(char *cmd)
3392 {
3393 local_irq_disable();
3394 smp_send_stop();
3395@@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
3396
3397 show_regs_print_info(KERN_DEFAULT);
3398
3399- print_symbol("PC is at %s\n", instruction_pointer(regs));
3400- print_symbol("LR is at %s\n", regs->ARM_lr);
3401+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
3402+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
3403 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
3404 "sp : %08lx ip : %08lx fp : %08lx\n",
3405 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
3406@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
3407 return 0;
3408 }
3409
3410-unsigned long arch_randomize_brk(struct mm_struct *mm)
3411-{
3412- unsigned long range_end = mm->brk + 0x02000000;
3413- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
3414-}
3415-
3416 #ifdef CONFIG_MMU
3417 #ifdef CONFIG_KUSER_HELPERS
3418 /*
3419@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
3420
3421 static int __init gate_vma_init(void)
3422 {
3423- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
3424+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
3425 return 0;
3426 }
3427 arch_initcall(gate_vma_init);
3428@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
3429
3430 const char *arch_vma_name(struct vm_area_struct *vma)
3431 {
3432- return is_gate_vma(vma) ? "[vectors]" :
3433- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
3434- "[sigpage]" : NULL;
3435+ return is_gate_vma(vma) ? "[vectors]" : NULL;
3436 }
3437
3438-static struct page *signal_page;
3439-extern struct page *get_signal_page(void);
3440-
3441 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3442 {
3443 struct mm_struct *mm = current->mm;
3444- unsigned long addr;
3445- int ret;
3446-
3447- if (!signal_page)
3448- signal_page = get_signal_page();
3449- if (!signal_page)
3450- return -ENOMEM;
3451
3452 down_write(&mm->mmap_sem);
3453- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
3454- if (IS_ERR_VALUE(addr)) {
3455- ret = addr;
3456- goto up_fail;
3457- }
3458-
3459- ret = install_special_mapping(mm, addr, PAGE_SIZE,
3460- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
3461- &signal_page);
3462-
3463- if (ret == 0)
3464- mm->context.sigpage = addr;
3465-
3466- up_fail:
3467+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3468 up_write(&mm->mmap_sem);
3469- return ret;
3470+ return 0;
3471 }
3472 #endif
3473diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3474index f73891b..cf3004e 100644
3475--- a/arch/arm/kernel/psci.c
3476+++ b/arch/arm/kernel/psci.c
3477@@ -28,7 +28,7 @@
3478 #include <asm/psci.h>
3479 #include <asm/system_misc.h>
3480
3481-struct psci_operations psci_ops;
3482+struct psci_operations psci_ops __read_only;
3483
3484 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3485 typedef int (*psci_initcall_t)(const struct device_node *);
3486diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3487index 0c27ed6..b67388e 100644
3488--- a/arch/arm/kernel/ptrace.c
3489+++ b/arch/arm/kernel/ptrace.c
3490@@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3491 regs->ARM_ip = ip;
3492 }
3493
3494+#ifdef CONFIG_GRKERNSEC_SETXID
3495+extern void gr_delayed_cred_worker(void);
3496+#endif
3497+
3498 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3499 {
3500 current_thread_info()->syscall = scno;
3501
3502+#ifdef CONFIG_GRKERNSEC_SETXID
3503+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3504+ gr_delayed_cred_worker();
3505+#endif
3506+
3507 /* Do the secure computing check first; failures should be fast. */
3508 if (secure_computing(scno) == -1)
3509 return -1;
3510diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3511index 8a16ee5..4f560e5 100644
3512--- a/arch/arm/kernel/setup.c
3513+++ b/arch/arm/kernel/setup.c
3514@@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3515 unsigned int elf_hwcap2 __read_mostly;
3516 EXPORT_SYMBOL(elf_hwcap2);
3517
3518+pteval_t __supported_pte_mask __read_only;
3519+pmdval_t __supported_pmd_mask __read_only;
3520
3521 #ifdef MULTI_CPU
3522-struct processor processor __read_mostly;
3523+struct processor processor __read_only;
3524 #endif
3525 #ifdef MULTI_TLB
3526-struct cpu_tlb_fns cpu_tlb __read_mostly;
3527+struct cpu_tlb_fns cpu_tlb __read_only;
3528 #endif
3529 #ifdef MULTI_USER
3530-struct cpu_user_fns cpu_user __read_mostly;
3531+struct cpu_user_fns cpu_user __read_only;
3532 #endif
3533 #ifdef MULTI_CACHE
3534-struct cpu_cache_fns cpu_cache __read_mostly;
3535+struct cpu_cache_fns cpu_cache __read_only;
3536 #endif
3537 #ifdef CONFIG_OUTER_CACHE
3538-struct outer_cache_fns outer_cache __read_mostly;
3539+struct outer_cache_fns outer_cache __read_only;
3540 EXPORT_SYMBOL(outer_cache);
3541 #endif
3542
3543@@ -251,9 +253,13 @@ static int __get_cpu_architecture(void)
3544 asm("mrc p15, 0, %0, c0, c1, 4"
3545 : "=r" (mmfr0));
3546 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3547- (mmfr0 & 0x000000f0) >= 0x00000030)
3548+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3549 cpu_arch = CPU_ARCH_ARMv7;
3550- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3551+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3552+ __supported_pte_mask |= L_PTE_PXN;
3553+ __supported_pmd_mask |= PMD_PXNTABLE;
3554+ }
3555+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3556 (mmfr0 & 0x000000f0) == 0x00000020)
3557 cpu_arch = CPU_ARCH_ARMv6;
3558 else
3559diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3560index bd19834..e4d8c66 100644
3561--- a/arch/arm/kernel/signal.c
3562+++ b/arch/arm/kernel/signal.c
3563@@ -24,8 +24,6 @@
3564
3565 extern const unsigned long sigreturn_codes[7];
3566
3567-static unsigned long signal_return_offset;
3568-
3569 #ifdef CONFIG_CRUNCH
3570 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3571 {
3572@@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3573 * except when the MPU has protected the vectors
3574 * page from PL0
3575 */
3576- retcode = mm->context.sigpage + signal_return_offset +
3577- (idx << 2) + thumb;
3578+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3579 } else
3580 #endif
3581 {
3582@@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3583 } while (thread_flags & _TIF_WORK_MASK);
3584 return 0;
3585 }
3586-
3587-struct page *get_signal_page(void)
3588-{
3589- unsigned long ptr;
3590- unsigned offset;
3591- struct page *page;
3592- void *addr;
3593-
3594- page = alloc_pages(GFP_KERNEL, 0);
3595-
3596- if (!page)
3597- return NULL;
3598-
3599- addr = page_address(page);
3600-
3601- /* Give the signal return code some randomness */
3602- offset = 0x200 + (get_random_int() & 0x7fc);
3603- signal_return_offset = offset;
3604-
3605- /*
3606- * Copy signal return handlers into the vector page, and
3607- * set sigreturn to be a pointer to these.
3608- */
3609- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3610-
3611- ptr = (unsigned long)addr + offset;
3612- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3613-
3614- return page;
3615-}
3616diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3617index 7c4fada..8581286 100644
3618--- a/arch/arm/kernel/smp.c
3619+++ b/arch/arm/kernel/smp.c
3620@@ -73,7 +73,7 @@ enum ipi_msg_type {
3621
3622 static DECLARE_COMPLETION(cpu_running);
3623
3624-static struct smp_operations smp_ops;
3625+static struct smp_operations smp_ops __read_only;
3626
3627 void __init smp_set_ops(struct smp_operations *ops)
3628 {
3629diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3630index 7a3be1d..b00c7de 100644
3631--- a/arch/arm/kernel/tcm.c
3632+++ b/arch/arm/kernel/tcm.c
3633@@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3634 .virtual = ITCM_OFFSET,
3635 .pfn = __phys_to_pfn(ITCM_OFFSET),
3636 .length = 0,
3637- .type = MT_MEMORY_RWX_ITCM,
3638+ .type = MT_MEMORY_RX_ITCM,
3639 }
3640 };
3641
3642@@ -267,7 +267,9 @@ no_dtcm:
3643 start = &__sitcm_text;
3644 end = &__eitcm_text;
3645 ram = &__itcm_start;
3646+ pax_open_kernel();
3647 memcpy(start, ram, itcm_code_sz);
3648+ pax_close_kernel();
3649 pr_debug("CPU ITCM: copied code from %p - %p\n",
3650 start, end);
3651 itcm_present = true;
3652diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3653index abd2fc0..895dbb6 100644
3654--- a/arch/arm/kernel/traps.c
3655+++ b/arch/arm/kernel/traps.c
3656@@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3657 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3658 {
3659 #ifdef CONFIG_KALLSYMS
3660- printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3661+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3662 #else
3663 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3664 #endif
3665@@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3666 static int die_owner = -1;
3667 static unsigned int die_nest_count;
3668
3669+extern void gr_handle_kernel_exploit(void);
3670+
3671 static unsigned long oops_begin(void)
3672 {
3673 int cpu;
3674@@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3675 panic("Fatal exception in interrupt");
3676 if (panic_on_oops)
3677 panic("Fatal exception");
3678+
3679+ gr_handle_kernel_exploit();
3680+
3681 if (signr)
3682 do_exit(signr);
3683 }
3684@@ -643,7 +648,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3685 * The user helper at 0xffff0fe0 must be used instead.
3686 * (see entry-armv.S for details)
3687 */
3688+ pax_open_kernel();
3689 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3690+ pax_close_kernel();
3691 }
3692 return 0;
3693
3694@@ -900,7 +907,11 @@ void __init early_trap_init(void *vectors_base)
3695 kuser_init(vectors_base);
3696
3697 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3698- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3699+
3700+#ifndef CONFIG_PAX_MEMORY_UDEREF
3701+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3702+#endif
3703+
3704 #else /* ifndef CONFIG_CPU_V7M */
3705 /*
3706 * on V7-M there is no need to copy the vector table to a dedicated
3707diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3708index 7bcee5c..e2f3249 100644
3709--- a/arch/arm/kernel/vmlinux.lds.S
3710+++ b/arch/arm/kernel/vmlinux.lds.S
3711@@ -8,7 +8,11 @@
3712 #include <asm/thread_info.h>
3713 #include <asm/memory.h>
3714 #include <asm/page.h>
3715-
3716+
3717+#ifdef CONFIG_PAX_KERNEXEC
3718+#include <asm/pgtable.h>
3719+#endif
3720+
3721 #define PROC_INFO \
3722 . = ALIGN(4); \
3723 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3724@@ -34,7 +38,7 @@
3725 #endif
3726
3727 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3728- defined(CONFIG_GENERIC_BUG)
3729+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3730 #define ARM_EXIT_KEEP(x) x
3731 #define ARM_EXIT_DISCARD(x)
3732 #else
3733@@ -90,6 +94,11 @@ SECTIONS
3734 _text = .;
3735 HEAD_TEXT
3736 }
3737+
3738+#ifdef CONFIG_PAX_KERNEXEC
3739+ . = ALIGN(1<<SECTION_SHIFT);
3740+#endif
3741+
3742 .text : { /* Real text segment */
3743 _stext = .; /* Text and read-only data */
3744 __exception_text_start = .;
3745@@ -112,6 +121,8 @@ SECTIONS
3746 ARM_CPU_KEEP(PROC_INFO)
3747 }
3748
3749+ _etext = .; /* End of text section */
3750+
3751 RO_DATA(PAGE_SIZE)
3752
3753 . = ALIGN(4);
3754@@ -142,7 +153,9 @@ SECTIONS
3755
3756 NOTES
3757
3758- _etext = .; /* End of text and rodata section */
3759+#ifdef CONFIG_PAX_KERNEXEC
3760+ . = ALIGN(1<<SECTION_SHIFT);
3761+#endif
3762
3763 #ifndef CONFIG_XIP_KERNEL
3764 . = ALIGN(PAGE_SIZE);
3765@@ -220,6 +233,11 @@ SECTIONS
3766 . = PAGE_OFFSET + TEXT_OFFSET;
3767 #else
3768 __init_end = .;
3769+
3770+#ifdef CONFIG_PAX_KERNEXEC
3771+ . = ALIGN(1<<SECTION_SHIFT);
3772+#endif
3773+
3774 . = ALIGN(THREAD_SIZE);
3775 __data_loc = .;
3776 #endif
3777diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3778index 3c82b37..69fa3d2 100644
3779--- a/arch/arm/kvm/arm.c
3780+++ b/arch/arm/kvm/arm.c
3781@@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3782 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3783
3784 /* The VMID used in the VTTBR */
3785-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3786+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3787 static u8 kvm_next_vmid;
3788 static DEFINE_SPINLOCK(kvm_vmid_lock);
3789
3790@@ -409,7 +409,7 @@ void force_vm_exit(const cpumask_t *mask)
3791 */
3792 static bool need_new_vmid_gen(struct kvm *kvm)
3793 {
3794- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3795+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3796 }
3797
3798 /**
3799@@ -442,7 +442,7 @@ static void update_vttbr(struct kvm *kvm)
3800
3801 /* First user of a new VMID generation? */
3802 if (unlikely(kvm_next_vmid == 0)) {
3803- atomic64_inc(&kvm_vmid_gen);
3804+ atomic64_inc_unchecked(&kvm_vmid_gen);
3805 kvm_next_vmid = 1;
3806
3807 /*
3808@@ -459,7 +459,7 @@ static void update_vttbr(struct kvm *kvm)
3809 kvm_call_hyp(__kvm_flush_vm_context);
3810 }
3811
3812- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3813+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3814 kvm->arch.vmid = kvm_next_vmid;
3815 kvm_next_vmid++;
3816
3817@@ -1034,7 +1034,7 @@ static void check_kvm_target_cpu(void *ret)
3818 /**
3819 * Initialize Hyp-mode and memory mappings on all CPUs.
3820 */
3821-int kvm_arch_init(void *opaque)
3822+int kvm_arch_init(const void *opaque)
3823 {
3824 int err;
3825 int ret, cpu;
3826diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3827index 14a0d98..7771a7d 100644
3828--- a/arch/arm/lib/clear_user.S
3829+++ b/arch/arm/lib/clear_user.S
3830@@ -12,14 +12,14 @@
3831
3832 .text
3833
3834-/* Prototype: int __clear_user(void *addr, size_t sz)
3835+/* Prototype: int ___clear_user(void *addr, size_t sz)
3836 * Purpose : clear some user memory
3837 * Params : addr - user memory address to clear
3838 * : sz - number of bytes to clear
3839 * Returns : number of bytes NOT cleared
3840 */
3841 ENTRY(__clear_user_std)
3842-WEAK(__clear_user)
3843+WEAK(___clear_user)
3844 stmfd sp!, {r1, lr}
3845 mov r2, #0
3846 cmp r1, #4
3847@@ -44,7 +44,7 @@ WEAK(__clear_user)
3848 USER( strnebt r2, [r0])
3849 mov r0, #0
3850 ldmfd sp!, {r1, pc}
3851-ENDPROC(__clear_user)
3852+ENDPROC(___clear_user)
3853 ENDPROC(__clear_user_std)
3854
3855 .pushsection .fixup,"ax"
3856diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3857index 66a477a..bee61d3 100644
3858--- a/arch/arm/lib/copy_from_user.S
3859+++ b/arch/arm/lib/copy_from_user.S
3860@@ -16,7 +16,7 @@
3861 /*
3862 * Prototype:
3863 *
3864- * size_t __copy_from_user(void *to, const void *from, size_t n)
3865+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3866 *
3867 * Purpose:
3868 *
3869@@ -84,11 +84,11 @@
3870
3871 .text
3872
3873-ENTRY(__copy_from_user)
3874+ENTRY(___copy_from_user)
3875
3876 #include "copy_template.S"
3877
3878-ENDPROC(__copy_from_user)
3879+ENDPROC(___copy_from_user)
3880
3881 .pushsection .fixup,"ax"
3882 .align 0
3883diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3884index 6ee2f67..d1cce76 100644
3885--- a/arch/arm/lib/copy_page.S
3886+++ b/arch/arm/lib/copy_page.S
3887@@ -10,6 +10,7 @@
3888 * ASM optimised string functions
3889 */
3890 #include <linux/linkage.h>
3891+#include <linux/const.h>
3892 #include <asm/assembler.h>
3893 #include <asm/asm-offsets.h>
3894 #include <asm/cache.h>
3895diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3896index d066df6..df28194 100644
3897--- a/arch/arm/lib/copy_to_user.S
3898+++ b/arch/arm/lib/copy_to_user.S
3899@@ -16,7 +16,7 @@
3900 /*
3901 * Prototype:
3902 *
3903- * size_t __copy_to_user(void *to, const void *from, size_t n)
3904+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3905 *
3906 * Purpose:
3907 *
3908@@ -88,11 +88,11 @@
3909 .text
3910
3911 ENTRY(__copy_to_user_std)
3912-WEAK(__copy_to_user)
3913+WEAK(___copy_to_user)
3914
3915 #include "copy_template.S"
3916
3917-ENDPROC(__copy_to_user)
3918+ENDPROC(___copy_to_user)
3919 ENDPROC(__copy_to_user_std)
3920
3921 .pushsection .fixup,"ax"
3922diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3923index 7d08b43..f7ca7ea 100644
3924--- a/arch/arm/lib/csumpartialcopyuser.S
3925+++ b/arch/arm/lib/csumpartialcopyuser.S
3926@@ -57,8 +57,8 @@
3927 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3928 */
3929
3930-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3931-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3932+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3933+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3934
3935 #include "csumpartialcopygeneric.S"
3936
3937diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3938index 5306de3..aed6d03 100644
3939--- a/arch/arm/lib/delay.c
3940+++ b/arch/arm/lib/delay.c
3941@@ -28,7 +28,7 @@
3942 /*
3943 * Default to the loop-based delay implementation.
3944 */
3945-struct arm_delay_ops arm_delay_ops = {
3946+struct arm_delay_ops arm_delay_ops __read_only = {
3947 .delay = __loop_delay,
3948 .const_udelay = __loop_const_udelay,
3949 .udelay = __loop_udelay,
3950diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3951index 3e58d71..029817c 100644
3952--- a/arch/arm/lib/uaccess_with_memcpy.c
3953+++ b/arch/arm/lib/uaccess_with_memcpy.c
3954@@ -136,7 +136,7 @@ out:
3955 }
3956
3957 unsigned long
3958-__copy_to_user(void __user *to, const void *from, unsigned long n)
3959+___copy_to_user(void __user *to, const void *from, unsigned long n)
3960 {
3961 /*
3962 * This test is stubbed out of the main function above to keep
3963@@ -190,7 +190,7 @@ out:
3964 return n;
3965 }
3966
3967-unsigned long __clear_user(void __user *addr, unsigned long n)
3968+unsigned long ___clear_user(void __user *addr, unsigned long n)
3969 {
3970 /* See rational for this in __copy_to_user() above. */
3971 if (n < 64)
3972diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3973index f7a07a5..258e1f7 100644
3974--- a/arch/arm/mach-at91/setup.c
3975+++ b/arch/arm/mach-at91/setup.c
3976@@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3977
3978 desc->pfn = __phys_to_pfn(base);
3979 desc->length = length;
3980- desc->type = MT_MEMORY_RWX_NONCACHED;
3981+ desc->type = MT_MEMORY_RW_NONCACHED;
3982
3983 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3984 base, length, desc->virtual);
3985diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3986index 255f33a..507b157 100644
3987--- a/arch/arm/mach-kirkwood/common.c
3988+++ b/arch/arm/mach-kirkwood/common.c
3989@@ -157,7 +157,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3990 clk_gate_ops.disable(hw);
3991 }
3992
3993-static struct clk_ops clk_gate_fn_ops;
3994+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3995+{
3996+ return clk_gate_ops.is_enabled(hw);
3997+}
3998+
3999+static struct clk_ops clk_gate_fn_ops = {
4000+ .enable = clk_gate_fn_enable,
4001+ .disable = clk_gate_fn_disable,
4002+ .is_enabled = clk_gate_fn_is_enabled,
4003+};
4004
4005 static struct clk __init *clk_register_gate_fn(struct device *dev,
4006 const char *name,
4007@@ -191,14 +200,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
4008 gate_fn->fn_en = fn_en;
4009 gate_fn->fn_dis = fn_dis;
4010
4011- /* ops is the gate ops, but with our enable/disable functions */
4012- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
4013- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
4014- clk_gate_fn_ops = clk_gate_ops;
4015- clk_gate_fn_ops.enable = clk_gate_fn_enable;
4016- clk_gate_fn_ops.disable = clk_gate_fn_disable;
4017- }
4018-
4019 clk = clk_register(dev, &gate_fn->gate.hw);
4020
4021 if (IS_ERR(clk))
4022diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
4023index aead77a..a2253fa 100644
4024--- a/arch/arm/mach-omap2/board-n8x0.c
4025+++ b/arch/arm/mach-omap2/board-n8x0.c
4026@@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
4027 }
4028 #endif
4029
4030-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
4031+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
4032 .late_init = n8x0_menelaus_late_init,
4033 };
4034
4035diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
4036index 8bc1338..8b28b69 100644
4037--- a/arch/arm/mach-omap2/gpmc.c
4038+++ b/arch/arm/mach-omap2/gpmc.c
4039@@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
4040 };
4041
4042 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
4043-static struct irq_chip gpmc_irq_chip;
4044 static int gpmc_irq_start;
4045
4046 static struct resource gpmc_mem_root;
4047@@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
4048
4049 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
4050
4051+static struct irq_chip gpmc_irq_chip = {
4052+ .name = "gpmc",
4053+ .irq_startup = gpmc_irq_noop_ret,
4054+ .irq_enable = gpmc_irq_enable,
4055+ .irq_disable = gpmc_irq_disable,
4056+ .irq_shutdown = gpmc_irq_noop,
4057+ .irq_ack = gpmc_irq_noop,
4058+ .irq_mask = gpmc_irq_noop,
4059+ .irq_unmask = gpmc_irq_noop,
4060+
4061+};
4062+
4063 static int gpmc_setup_irq(void)
4064 {
4065 int i;
4066@@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
4067 return gpmc_irq_start;
4068 }
4069
4070- gpmc_irq_chip.name = "gpmc";
4071- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
4072- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
4073- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
4074- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
4075- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
4076- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
4077- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
4078-
4079 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
4080 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
4081
4082diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
4083index 4001325..b14e2a0 100644
4084--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
4085+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
4086@@ -84,7 +84,7 @@ struct cpu_pm_ops {
4087 int (*finish_suspend)(unsigned long cpu_state);
4088 void (*resume)(void);
4089 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
4090-};
4091+} __no_const;
4092
4093 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
4094 static struct powerdomain *mpuss_pd;
4095@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
4096 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
4097 {}
4098
4099-struct cpu_pm_ops omap_pm_ops = {
4100+static struct cpu_pm_ops omap_pm_ops __read_only = {
4101 .finish_suspend = default_finish_suspend,
4102 .resume = dummy_cpu_resume,
4103 .scu_prepare = dummy_scu_prepare,
4104diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
4105index 37843a7..a98df13 100644
4106--- a/arch/arm/mach-omap2/omap-wakeupgen.c
4107+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
4108@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
4109 return NOTIFY_OK;
4110 }
4111
4112-static struct notifier_block __refdata irq_hotplug_notifier = {
4113+static struct notifier_block irq_hotplug_notifier = {
4114 .notifier_call = irq_cpu_hotplug_notify,
4115 };
4116
4117diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
4118index 01ef59d..32ae28a8 100644
4119--- a/arch/arm/mach-omap2/omap_device.c
4120+++ b/arch/arm/mach-omap2/omap_device.c
4121@@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
4122 struct platform_device __init *omap_device_build(const char *pdev_name,
4123 int pdev_id,
4124 struct omap_hwmod *oh,
4125- void *pdata, int pdata_len)
4126+ const void *pdata, int pdata_len)
4127 {
4128 struct omap_hwmod *ohs[] = { oh };
4129
4130@@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
4131 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
4132 int pdev_id,
4133 struct omap_hwmod **ohs,
4134- int oh_cnt, void *pdata,
4135+ int oh_cnt, const void *pdata,
4136 int pdata_len)
4137 {
4138 int ret = -ENOMEM;
4139diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
4140index 78c02b3..c94109a 100644
4141--- a/arch/arm/mach-omap2/omap_device.h
4142+++ b/arch/arm/mach-omap2/omap_device.h
4143@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
4144 /* Core code interface */
4145
4146 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
4147- struct omap_hwmod *oh, void *pdata,
4148+ struct omap_hwmod *oh, const void *pdata,
4149 int pdata_len);
4150
4151 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
4152 struct omap_hwmod **oh, int oh_cnt,
4153- void *pdata, int pdata_len);
4154+ const void *pdata, int pdata_len);
4155
4156 struct omap_device *omap_device_alloc(struct platform_device *pdev,
4157 struct omap_hwmod **ohs, int oh_cnt);
4158diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
4159index 6c074f3..cd58cb7 100644
4160--- a/arch/arm/mach-omap2/omap_hwmod.c
4161+++ b/arch/arm/mach-omap2/omap_hwmod.c
4162@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
4163 int (*init_clkdm)(struct omap_hwmod *oh);
4164 void (*update_context_lost)(struct omap_hwmod *oh);
4165 int (*get_context_lost)(struct omap_hwmod *oh);
4166-};
4167+} __no_const;
4168
4169 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
4170-static struct omap_hwmod_soc_ops soc_ops;
4171+static struct omap_hwmod_soc_ops soc_ops __read_only;
4172
4173 /* omap_hwmod_list contains all registered struct omap_hwmods */
4174 static LIST_HEAD(omap_hwmod_list);
4175diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
4176index 95fee54..cfa9cf1 100644
4177--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
4178+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
4179@@ -10,6 +10,7 @@
4180
4181 #include <linux/kernel.h>
4182 #include <linux/init.h>
4183+#include <asm/pgtable.h>
4184
4185 #include "powerdomain.h"
4186
4187@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
4188
4189 void __init am43xx_powerdomains_init(void)
4190 {
4191- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
4192+ pax_open_kernel();
4193+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
4194+ pax_close_kernel();
4195 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
4196 pwrdm_register_pwrdms(powerdomains_am43xx);
4197 pwrdm_complete_init();
4198diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
4199index 97d6607..8429d14 100644
4200--- a/arch/arm/mach-omap2/wd_timer.c
4201+++ b/arch/arm/mach-omap2/wd_timer.c
4202@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
4203 struct omap_hwmod *oh;
4204 char *oh_name = "wd_timer2";
4205 char *dev_name = "omap_wdt";
4206- struct omap_wd_timer_platform_data pdata;
4207+ static struct omap_wd_timer_platform_data pdata = {
4208+ .read_reset_sources = prm_read_reset_sources
4209+ };
4210
4211 if (!cpu_class_is_omap2() || of_have_populated_dt())
4212 return 0;
4213@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
4214 return -EINVAL;
4215 }
4216
4217- pdata.read_reset_sources = prm_read_reset_sources;
4218-
4219 pdev = omap_device_build(dev_name, id, oh, &pdata,
4220 sizeof(struct omap_wd_timer_platform_data));
4221 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
4222diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
4223index b82dcae..44ee5b6 100644
4224--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
4225+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
4226@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
4227 bool entered_lp2 = false;
4228
4229 if (tegra_pending_sgi())
4230- ACCESS_ONCE(abort_flag) = true;
4231+ ACCESS_ONCE_RW(abort_flag) = true;
4232
4233 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
4234
4235diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
4236index 2dea8b5..6499da2 100644
4237--- a/arch/arm/mach-ux500/setup.h
4238+++ b/arch/arm/mach-ux500/setup.h
4239@@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
4240 .type = MT_DEVICE, \
4241 }
4242
4243-#define __MEM_DEV_DESC(x, sz) { \
4244- .virtual = IO_ADDRESS(x), \
4245- .pfn = __phys_to_pfn(x), \
4246- .length = sz, \
4247- .type = MT_MEMORY_RWX, \
4248-}
4249-
4250 extern struct smp_operations ux500_smp_ops;
4251 extern void ux500_cpu_die(unsigned int cpu);
4252
4253diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
4254index c348eae..456a1a4 100644
4255--- a/arch/arm/mm/Kconfig
4256+++ b/arch/arm/mm/Kconfig
4257@@ -446,6 +446,7 @@ config CPU_32v5
4258
4259 config CPU_32v6
4260 bool
4261+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
4262 select TLS_REG_EMUL if !CPU_32v6K && !MMU
4263
4264 config CPU_32v6K
4265@@ -600,6 +601,7 @@ config CPU_CP15_MPU
4266
4267 config CPU_USE_DOMAINS
4268 bool
4269+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
4270 help
4271 This option enables or disables the use of domain switching
4272 via the set_fs() function.
4273@@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
4274 config KUSER_HELPERS
4275 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
4276 default y
4277+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
4278 help
4279 Warning: disabling this option may break user programs.
4280
4281@@ -811,7 +814,7 @@ config KUSER_HELPERS
4282 See Documentation/arm/kernel_user_helpers.txt for details.
4283
4284 However, the fixed address nature of these helpers can be used
4285- by ROP (return orientated programming) authors when creating
4286+ by ROP (Return Oriented Programming) authors when creating
4287 exploits.
4288
4289 If all of the binaries and libraries which run on your platform
4290diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
4291index b8cb1a2..6a5624a 100644
4292--- a/arch/arm/mm/alignment.c
4293+++ b/arch/arm/mm/alignment.c
4294@@ -214,10 +214,12 @@ union offset_union {
4295 #define __get16_unaligned_check(ins,val,addr) \
4296 do { \
4297 unsigned int err = 0, v, a = addr; \
4298+ pax_open_userland(); \
4299 __get8_unaligned_check(ins,v,a,err); \
4300 val = v << ((BE) ? 8 : 0); \
4301 __get8_unaligned_check(ins,v,a,err); \
4302 val |= v << ((BE) ? 0 : 8); \
4303+ pax_close_userland(); \
4304 if (err) \
4305 goto fault; \
4306 } while (0)
4307@@ -231,6 +233,7 @@ union offset_union {
4308 #define __get32_unaligned_check(ins,val,addr) \
4309 do { \
4310 unsigned int err = 0, v, a = addr; \
4311+ pax_open_userland(); \
4312 __get8_unaligned_check(ins,v,a,err); \
4313 val = v << ((BE) ? 24 : 0); \
4314 __get8_unaligned_check(ins,v,a,err); \
4315@@ -239,6 +242,7 @@ union offset_union {
4316 val |= v << ((BE) ? 8 : 16); \
4317 __get8_unaligned_check(ins,v,a,err); \
4318 val |= v << ((BE) ? 0 : 24); \
4319+ pax_close_userland(); \
4320 if (err) \
4321 goto fault; \
4322 } while (0)
4323@@ -252,6 +256,7 @@ union offset_union {
4324 #define __put16_unaligned_check(ins,val,addr) \
4325 do { \
4326 unsigned int err = 0, v = val, a = addr; \
4327+ pax_open_userland(); \
4328 __asm__( FIRST_BYTE_16 \
4329 ARM( "1: "ins" %1, [%2], #1\n" ) \
4330 THUMB( "1: "ins" %1, [%2]\n" ) \
4331@@ -271,6 +276,7 @@ union offset_union {
4332 " .popsection\n" \
4333 : "=r" (err), "=&r" (v), "=&r" (a) \
4334 : "0" (err), "1" (v), "2" (a)); \
4335+ pax_close_userland(); \
4336 if (err) \
4337 goto fault; \
4338 } while (0)
4339@@ -284,6 +290,7 @@ union offset_union {
4340 #define __put32_unaligned_check(ins,val,addr) \
4341 do { \
4342 unsigned int err = 0, v = val, a = addr; \
4343+ pax_open_userland(); \
4344 __asm__( FIRST_BYTE_32 \
4345 ARM( "1: "ins" %1, [%2], #1\n" ) \
4346 THUMB( "1: "ins" %1, [%2]\n" ) \
4347@@ -313,6 +320,7 @@ union offset_union {
4348 " .popsection\n" \
4349 : "=r" (err), "=&r" (v), "=&r" (a) \
4350 : "0" (err), "1" (v), "2" (a)); \
4351+ pax_close_userland(); \
4352 if (err) \
4353 goto fault; \
4354 } while (0)
4355diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
4356index 7c3fb41..bfb87d8 100644
4357--- a/arch/arm/mm/cache-l2x0.c
4358+++ b/arch/arm/mm/cache-l2x0.c
4359@@ -41,7 +41,7 @@ struct l2c_init_data {
4360 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
4361 void (*save)(void __iomem *);
4362 struct outer_cache_fns outer_cache;
4363-};
4364+} __do_const;
4365
4366 #define CACHE_LINE_SIZE 32
4367
4368diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
4369index 6eb97b3..ac509f6 100644
4370--- a/arch/arm/mm/context.c
4371+++ b/arch/arm/mm/context.c
4372@@ -43,7 +43,7 @@
4373 #define NUM_USER_ASIDS ASID_FIRST_VERSION
4374
4375 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
4376-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4377+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4378 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
4379
4380 static DEFINE_PER_CPU(atomic64_t, active_asids);
4381@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4382 {
4383 static u32 cur_idx = 1;
4384 u64 asid = atomic64_read(&mm->context.id);
4385- u64 generation = atomic64_read(&asid_generation);
4386+ u64 generation = atomic64_read_unchecked(&asid_generation);
4387
4388 if (asid != 0 && is_reserved_asid(asid)) {
4389 /*
4390@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4391 */
4392 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
4393 if (asid == NUM_USER_ASIDS) {
4394- generation = atomic64_add_return(ASID_FIRST_VERSION,
4395+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
4396 &asid_generation);
4397 flush_context(cpu);
4398 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
4399@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
4400 cpu_set_reserved_ttbr0();
4401
4402 asid = atomic64_read(&mm->context.id);
4403- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
4404+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
4405 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
4406 goto switch_mm_fastpath;
4407
4408 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
4409 /* Check that our ASID belongs to the current generation. */
4410 asid = atomic64_read(&mm->context.id);
4411- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
4412+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
4413 asid = new_context(mm, cpu);
4414 atomic64_set(&mm->context.id, asid);
4415 }
4416diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
4417index eb8830a..5360ce7 100644
4418--- a/arch/arm/mm/fault.c
4419+++ b/arch/arm/mm/fault.c
4420@@ -25,6 +25,7 @@
4421 #include <asm/system_misc.h>
4422 #include <asm/system_info.h>
4423 #include <asm/tlbflush.h>
4424+#include <asm/sections.h>
4425
4426 #include "fault.h"
4427
4428@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
4429 if (fixup_exception(regs))
4430 return;
4431
4432+#ifdef CONFIG_PAX_MEMORY_UDEREF
4433+ if (addr < TASK_SIZE) {
4434+ if (current->signal->curr_ip)
4435+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4436+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4437+ else
4438+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4439+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4440+ }
4441+#endif
4442+
4443+#ifdef CONFIG_PAX_KERNEXEC
4444+ if ((fsr & FSR_WRITE) &&
4445+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
4446+ (MODULES_VADDR <= addr && addr < MODULES_END)))
4447+ {
4448+ if (current->signal->curr_ip)
4449+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4450+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4451+ else
4452+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
4453+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4454+ }
4455+#endif
4456+
4457 /*
4458 * No handler, we'll have to terminate things with extreme prejudice.
4459 */
4460@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
4461 }
4462 #endif
4463
4464+#ifdef CONFIG_PAX_PAGEEXEC
4465+ if (fsr & FSR_LNX_PF) {
4466+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
4467+ do_group_exit(SIGKILL);
4468+ }
4469+#endif
4470+
4471 tsk->thread.address = addr;
4472 tsk->thread.error_code = fsr;
4473 tsk->thread.trap_no = 14;
4474@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4475 }
4476 #endif /* CONFIG_MMU */
4477
4478+#ifdef CONFIG_PAX_PAGEEXEC
4479+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4480+{
4481+ long i;
4482+
4483+ printk(KERN_ERR "PAX: bytes at PC: ");
4484+ for (i = 0; i < 20; i++) {
4485+ unsigned char c;
4486+ if (get_user(c, (__force unsigned char __user *)pc+i))
4487+ printk(KERN_CONT "?? ");
4488+ else
4489+ printk(KERN_CONT "%02x ", c);
4490+ }
4491+ printk("\n");
4492+
4493+ printk(KERN_ERR "PAX: bytes at SP-4: ");
4494+ for (i = -1; i < 20; i++) {
4495+ unsigned long c;
4496+ if (get_user(c, (__force unsigned long __user *)sp+i))
4497+ printk(KERN_CONT "???????? ");
4498+ else
4499+ printk(KERN_CONT "%08lx ", c);
4500+ }
4501+ printk("\n");
4502+}
4503+#endif
4504+
4505 /*
4506 * First Level Translation Fault Handler
4507 *
4508@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4509 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4510 struct siginfo info;
4511
4512+#ifdef CONFIG_PAX_MEMORY_UDEREF
4513+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4514+ if (current->signal->curr_ip)
4515+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4516+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4517+ else
4518+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4519+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4520+ goto die;
4521+ }
4522+#endif
4523+
4524 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4525 return;
4526
4527+die:
4528 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4529 inf->name, fsr, addr);
4530
4531@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4532 ifsr_info[nr].name = name;
4533 }
4534
4535+asmlinkage int sys_sigreturn(struct pt_regs *regs);
4536+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4537+
4538 asmlinkage void __exception
4539 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4540 {
4541 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4542 struct siginfo info;
4543+ unsigned long pc = instruction_pointer(regs);
4544+
4545+ if (user_mode(regs)) {
4546+ unsigned long sigpage = current->mm->context.sigpage;
4547+
4548+ if (sigpage <= pc && pc < sigpage + 7*4) {
4549+ if (pc < sigpage + 3*4)
4550+ sys_sigreturn(regs);
4551+ else
4552+ sys_rt_sigreturn(regs);
4553+ return;
4554+ }
4555+ if (pc == 0xffff0f60UL) {
4556+ /*
4557+ * PaX: __kuser_cmpxchg64 emulation
4558+ */
4559+ // TODO
4560+ //regs->ARM_pc = regs->ARM_lr;
4561+ //return;
4562+ }
4563+ if (pc == 0xffff0fa0UL) {
4564+ /*
4565+ * PaX: __kuser_memory_barrier emulation
4566+ */
4567+ // dmb(); implied by the exception
4568+ regs->ARM_pc = regs->ARM_lr;
4569+ return;
4570+ }
4571+ if (pc == 0xffff0fc0UL) {
4572+ /*
4573+ * PaX: __kuser_cmpxchg emulation
4574+ */
4575+ // TODO
4576+ //long new;
4577+ //int op;
4578+
4579+ //op = FUTEX_OP_SET << 28;
4580+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4581+ //regs->ARM_r0 = old != new;
4582+ //regs->ARM_pc = regs->ARM_lr;
4583+ //return;
4584+ }
4585+ if (pc == 0xffff0fe0UL) {
4586+ /*
4587+ * PaX: __kuser_get_tls emulation
4588+ */
4589+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4590+ regs->ARM_pc = regs->ARM_lr;
4591+ return;
4592+ }
4593+ }
4594+
4595+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4596+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4597+ if (current->signal->curr_ip)
4598+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4599+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4600+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4601+ else
4602+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4603+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4604+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4605+ goto die;
4606+ }
4607+#endif
4608+
4609+#ifdef CONFIG_PAX_REFCOUNT
4610+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4611+ unsigned int bkpt;
4612+
4613+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4614+ current->thread.error_code = ifsr;
4615+ current->thread.trap_no = 0;
4616+ pax_report_refcount_overflow(regs);
4617+ fixup_exception(regs);
4618+ return;
4619+ }
4620+ }
4621+#endif
4622
4623 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4624 return;
4625
4626+die:
4627 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4628 inf->name, ifsr, addr);
4629
4630diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4631index cf08bdf..772656c 100644
4632--- a/arch/arm/mm/fault.h
4633+++ b/arch/arm/mm/fault.h
4634@@ -3,6 +3,7 @@
4635
4636 /*
4637 * Fault status register encodings. We steal bit 31 for our own purposes.
4638+ * Set when the FSR value is from an instruction fault.
4639 */
4640 #define FSR_LNX_PF (1 << 31)
4641 #define FSR_WRITE (1 << 11)
4642@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4643 }
4644 #endif
4645
4646+/* valid for LPAE and !LPAE */
4647+static inline int is_xn_fault(unsigned int fsr)
4648+{
4649+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4650+}
4651+
4652+static inline int is_domain_fault(unsigned int fsr)
4653+{
4654+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4655+}
4656+
4657 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4658 unsigned long search_exception_table(unsigned long addr);
4659
4660diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4661index 659c75d..6f8c029 100644
4662--- a/arch/arm/mm/init.c
4663+++ b/arch/arm/mm/init.c
4664@@ -31,6 +31,8 @@
4665 #include <asm/setup.h>
4666 #include <asm/tlb.h>
4667 #include <asm/fixmap.h>
4668+#include <asm/system_info.h>
4669+#include <asm/cp15.h>
4670
4671 #include <asm/mach/arch.h>
4672 #include <asm/mach/map.h>
4673@@ -619,7 +621,46 @@ void free_initmem(void)
4674 {
4675 #ifdef CONFIG_HAVE_TCM
4676 extern char __tcm_start, __tcm_end;
4677+#endif
4678
4679+#ifdef CONFIG_PAX_KERNEXEC
4680+ unsigned long addr;
4681+ pgd_t *pgd;
4682+ pud_t *pud;
4683+ pmd_t *pmd;
4684+ int cpu_arch = cpu_architecture();
4685+ unsigned int cr = get_cr();
4686+
4687+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4688+ /* make pages tables, etc before .text NX */
4689+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4690+ pgd = pgd_offset_k(addr);
4691+ pud = pud_offset(pgd, addr);
4692+ pmd = pmd_offset(pud, addr);
4693+ __section_update(pmd, addr, PMD_SECT_XN);
4694+ }
4695+ /* make init NX */
4696+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4697+ pgd = pgd_offset_k(addr);
4698+ pud = pud_offset(pgd, addr);
4699+ pmd = pmd_offset(pud, addr);
4700+ __section_update(pmd, addr, PMD_SECT_XN);
4701+ }
4702+ /* make kernel code/rodata RX */
4703+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4704+ pgd = pgd_offset_k(addr);
4705+ pud = pud_offset(pgd, addr);
4706+ pmd = pmd_offset(pud, addr);
4707+#ifdef CONFIG_ARM_LPAE
4708+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4709+#else
4710+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4711+#endif
4712+ }
4713+ }
4714+#endif
4715+
4716+#ifdef CONFIG_HAVE_TCM
4717 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4718 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4719 #endif
4720diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4721index d1e5ad7..84dcbf2 100644
4722--- a/arch/arm/mm/ioremap.c
4723+++ b/arch/arm/mm/ioremap.c
4724@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4725 unsigned int mtype;
4726
4727 if (cached)
4728- mtype = MT_MEMORY_RWX;
4729+ mtype = MT_MEMORY_RX;
4730 else
4731- mtype = MT_MEMORY_RWX_NONCACHED;
4732+ mtype = MT_MEMORY_RX_NONCACHED;
4733
4734 return __arm_ioremap_caller(phys_addr, size, mtype,
4735 __builtin_return_address(0));
4736diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4737index 5e85ed3..b10a7ed 100644
4738--- a/arch/arm/mm/mmap.c
4739+++ b/arch/arm/mm/mmap.c
4740@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4741 struct vm_area_struct *vma;
4742 int do_align = 0;
4743 int aliasing = cache_is_vipt_aliasing();
4744+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4745 struct vm_unmapped_area_info info;
4746
4747 /*
4748@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4749 if (len > TASK_SIZE)
4750 return -ENOMEM;
4751
4752+#ifdef CONFIG_PAX_RANDMMAP
4753+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4754+#endif
4755+
4756 if (addr) {
4757 if (do_align)
4758 addr = COLOUR_ALIGN(addr, pgoff);
4759@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4760 addr = PAGE_ALIGN(addr);
4761
4762 vma = find_vma(mm, addr);
4763- if (TASK_SIZE - len >= addr &&
4764- (!vma || addr + len <= vma->vm_start))
4765+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4766 return addr;
4767 }
4768
4769@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4770 info.high_limit = TASK_SIZE;
4771 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4772 info.align_offset = pgoff << PAGE_SHIFT;
4773+ info.threadstack_offset = offset;
4774 return vm_unmapped_area(&info);
4775 }
4776
4777@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4778 unsigned long addr = addr0;
4779 int do_align = 0;
4780 int aliasing = cache_is_vipt_aliasing();
4781+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4782 struct vm_unmapped_area_info info;
4783
4784 /*
4785@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4786 return addr;
4787 }
4788
4789+#ifdef CONFIG_PAX_RANDMMAP
4790+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4791+#endif
4792+
4793 /* requesting a specific address */
4794 if (addr) {
4795 if (do_align)
4796@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4797 else
4798 addr = PAGE_ALIGN(addr);
4799 vma = find_vma(mm, addr);
4800- if (TASK_SIZE - len >= addr &&
4801- (!vma || addr + len <= vma->vm_start))
4802+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4803 return addr;
4804 }
4805
4806@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4807 info.high_limit = mm->mmap_base;
4808 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4809 info.align_offset = pgoff << PAGE_SHIFT;
4810+ info.threadstack_offset = offset;
4811 addr = vm_unmapped_area(&info);
4812
4813 /*
4814@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4815 {
4816 unsigned long random_factor = 0UL;
4817
4818+#ifdef CONFIG_PAX_RANDMMAP
4819+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4820+#endif
4821+
4822 /* 8 bits of randomness in 20 address space bits */
4823 if ((current->flags & PF_RANDOMIZE) &&
4824 !(current->personality & ADDR_NO_RANDOMIZE))
4825@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4826
4827 if (mmap_is_legacy()) {
4828 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4829+
4830+#ifdef CONFIG_PAX_RANDMMAP
4831+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4832+ mm->mmap_base += mm->delta_mmap;
4833+#endif
4834+
4835 mm->get_unmapped_area = arch_get_unmapped_area;
4836 } else {
4837 mm->mmap_base = mmap_base(random_factor);
4838+
4839+#ifdef CONFIG_PAX_RANDMMAP
4840+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4841+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4842+#endif
4843+
4844 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4845 }
4846 }
4847diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4848index 6e3ba8d..9cbb4d7 100644
4849--- a/arch/arm/mm/mmu.c
4850+++ b/arch/arm/mm/mmu.c
4851@@ -40,6 +40,22 @@
4852 #include "mm.h"
4853 #include "tcm.h"
4854
4855+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4856+void modify_domain(unsigned int dom, unsigned int type)
4857+{
4858+ struct thread_info *thread = current_thread_info();
4859+ unsigned int domain = thread->cpu_domain;
4860+ /*
4861+ * DOMAIN_MANAGER might be defined to some other value,
4862+ * use the arch-defined constant
4863+ */
4864+ domain &= ~domain_val(dom, 3);
4865+ thread->cpu_domain = domain | domain_val(dom, type);
4866+ set_domain(thread->cpu_domain);
4867+}
4868+EXPORT_SYMBOL(modify_domain);
4869+#endif
4870+
4871 /*
4872 * empty_zero_page is a special page that is used for
4873 * zero-initialized data and COW.
4874@@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4875 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4876 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4877
4878-static struct mem_type mem_types[] = {
4879+#ifdef CONFIG_PAX_KERNEXEC
4880+#define L_PTE_KERNEXEC L_PTE_RDONLY
4881+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4882+#else
4883+#define L_PTE_KERNEXEC L_PTE_DIRTY
4884+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4885+#endif
4886+
4887+static struct mem_type mem_types[] __read_only = {
4888 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4889 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4890 L_PTE_SHARED,
4891@@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4892 .prot_sect = PROT_SECT_DEVICE,
4893 .domain = DOMAIN_IO,
4894 },
4895- [MT_UNCACHED] = {
4896+ [MT_UNCACHED_RW] = {
4897 .prot_pte = PROT_PTE_DEVICE,
4898 .prot_l1 = PMD_TYPE_TABLE,
4899 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4900 .domain = DOMAIN_IO,
4901 },
4902- [MT_CACHECLEAN] = {
4903- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4904+ [MT_CACHECLEAN_RO] = {
4905+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4906 .domain = DOMAIN_KERNEL,
4907 },
4908 #ifndef CONFIG_ARM_LPAE
4909- [MT_MINICLEAN] = {
4910- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4911+ [MT_MINICLEAN_RO] = {
4912+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4913 .domain = DOMAIN_KERNEL,
4914 },
4915 #endif
4916@@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4917 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4918 L_PTE_RDONLY,
4919 .prot_l1 = PMD_TYPE_TABLE,
4920- .domain = DOMAIN_USER,
4921+ .domain = DOMAIN_VECTORS,
4922 },
4923 [MT_HIGH_VECTORS] = {
4924 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4925 L_PTE_USER | L_PTE_RDONLY,
4926 .prot_l1 = PMD_TYPE_TABLE,
4927- .domain = DOMAIN_USER,
4928+ .domain = DOMAIN_VECTORS,
4929 },
4930- [MT_MEMORY_RWX] = {
4931+ [__MT_MEMORY_RWX] = {
4932 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4933 .prot_l1 = PMD_TYPE_TABLE,
4934 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4935@@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4936 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4937 .domain = DOMAIN_KERNEL,
4938 },
4939- [MT_ROM] = {
4940- .prot_sect = PMD_TYPE_SECT,
4941+ [MT_MEMORY_RX] = {
4942+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4943+ .prot_l1 = PMD_TYPE_TABLE,
4944+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4945+ .domain = DOMAIN_KERNEL,
4946+ },
4947+ [MT_ROM_RX] = {
4948+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4949 .domain = DOMAIN_KERNEL,
4950 },
4951- [MT_MEMORY_RWX_NONCACHED] = {
4952+ [MT_MEMORY_RW_NONCACHED] = {
4953 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4954 L_PTE_MT_BUFFERABLE,
4955 .prot_l1 = PMD_TYPE_TABLE,
4956 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4957 .domain = DOMAIN_KERNEL,
4958 },
4959+ [MT_MEMORY_RX_NONCACHED] = {
4960+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4961+ L_PTE_MT_BUFFERABLE,
4962+ .prot_l1 = PMD_TYPE_TABLE,
4963+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4964+ .domain = DOMAIN_KERNEL,
4965+ },
4966 [MT_MEMORY_RW_DTCM] = {
4967 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4968 L_PTE_XN,
4969@@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4970 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4971 .domain = DOMAIN_KERNEL,
4972 },
4973- [MT_MEMORY_RWX_ITCM] = {
4974- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4975+ [MT_MEMORY_RX_ITCM] = {
4976+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4977 .prot_l1 = PMD_TYPE_TABLE,
4978+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4979 .domain = DOMAIN_KERNEL,
4980 },
4981 [MT_MEMORY_RW_SO] = {
4982@@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4983 * Mark cache clean areas and XIP ROM read only
4984 * from SVC mode and no access from userspace.
4985 */
4986- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4987- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4988- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4989+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4990+#ifdef CONFIG_PAX_KERNEXEC
4991+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4992+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4993+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4994+#endif
4995+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4996+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4997 #endif
4998
4999 /*
5000@@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
5001 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
5002 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
5003 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
5004- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
5005- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
5006+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
5007+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
5008 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
5009 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
5010+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
5011+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
5012 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
5013- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
5014- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
5015+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
5016+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
5017+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
5018+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
5019 }
5020 }
5021
5022@@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
5023 if (cpu_arch >= CPU_ARCH_ARMv6) {
5024 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
5025 /* Non-cacheable Normal is XCB = 001 */
5026- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
5027+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
5028+ PMD_SECT_BUFFERED;
5029+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
5030 PMD_SECT_BUFFERED;
5031 } else {
5032 /* For both ARMv6 and non-TEX-remapping ARMv7 */
5033- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
5034+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
5035+ PMD_SECT_TEX(1);
5036+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
5037 PMD_SECT_TEX(1);
5038 }
5039 } else {
5040- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
5041+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
5042+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
5043 }
5044
5045 #ifdef CONFIG_ARM_LPAE
5046@@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
5047 vecs_pgprot |= PTE_EXT_AF;
5048 #endif
5049
5050+ user_pgprot |= __supported_pte_mask;
5051+
5052 for (i = 0; i < 16; i++) {
5053 pteval_t v = pgprot_val(protection_map[i]);
5054 protection_map[i] = __pgprot(v | user_pgprot);
5055@@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
5056
5057 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
5058 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
5059- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
5060- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
5061+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
5062+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
5063 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
5064 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
5065+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
5066+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
5067 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
5068- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
5069- mem_types[MT_ROM].prot_sect |= cp->pmd;
5070+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
5071+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
5072+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
5073
5074 switch (cp->pmd) {
5075 case PMD_SECT_WT:
5076- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
5077+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
5078 break;
5079 case PMD_SECT_WB:
5080 case PMD_SECT_WBWA:
5081- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
5082+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
5083 break;
5084 }
5085 pr_info("Memory policy: %sData cache %s\n",
5086@@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
5087 return;
5088 }
5089
5090- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
5091+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
5092 md->virtual >= PAGE_OFFSET &&
5093 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
5094 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
5095@@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
5096 * called function. This means you can't use any function or debugging
5097 * method which may touch any device, otherwise the kernel _will_ crash.
5098 */
5099+
5100+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
5101+
5102 static void __init devicemaps_init(const struct machine_desc *mdesc)
5103 {
5104 struct map_desc map;
5105 unsigned long addr;
5106- void *vectors;
5107
5108- /*
5109- * Allocate the vector page early.
5110- */
5111- vectors = early_alloc(PAGE_SIZE * 2);
5112-
5113- early_trap_init(vectors);
5114+ early_trap_init(&vectors);
5115
5116 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
5117 pmd_clear(pmd_off_k(addr));
5118@@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
5119 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
5120 map.virtual = MODULES_VADDR;
5121 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
5122- map.type = MT_ROM;
5123+ map.type = MT_ROM_RX;
5124 create_mapping(&map);
5125 #endif
5126
5127@@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
5128 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
5129 map.virtual = FLUSH_BASE;
5130 map.length = SZ_1M;
5131- map.type = MT_CACHECLEAN;
5132+ map.type = MT_CACHECLEAN_RO;
5133 create_mapping(&map);
5134 #endif
5135 #ifdef FLUSH_BASE_MINICACHE
5136 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
5137 map.virtual = FLUSH_BASE_MINICACHE;
5138 map.length = SZ_1M;
5139- map.type = MT_MINICLEAN;
5140+ map.type = MT_MINICLEAN_RO;
5141 create_mapping(&map);
5142 #endif
5143
5144@@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
5145 * location (0xffff0000). If we aren't using high-vectors, also
5146 * create a mapping at the low-vectors virtual address.
5147 */
5148- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
5149+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
5150 map.virtual = 0xffff0000;
5151 map.length = PAGE_SIZE;
5152 #ifdef CONFIG_KUSER_HELPERS
5153@@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
5154 static void __init map_lowmem(void)
5155 {
5156 struct memblock_region *reg;
5157+#ifndef CONFIG_PAX_KERNEXEC
5158 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
5159 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
5160+#endif
5161
5162 /* Map all the lowmem memory banks. */
5163 for_each_memblock(memory, reg) {
5164@@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
5165 if (start >= end)
5166 break;
5167
5168+#ifdef CONFIG_PAX_KERNEXEC
5169+ map.pfn = __phys_to_pfn(start);
5170+ map.virtual = __phys_to_virt(start);
5171+ map.length = end - start;
5172+
5173+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
5174+ struct map_desc kernel;
5175+ struct map_desc initmap;
5176+
5177+ /* when freeing initmem we will make this RW */
5178+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
5179+ initmap.virtual = (unsigned long)__init_begin;
5180+ initmap.length = _sdata - __init_begin;
5181+ initmap.type = __MT_MEMORY_RWX;
5182+ create_mapping(&initmap);
5183+
5184+ /* when freeing initmem we will make this RX */
5185+ kernel.pfn = __phys_to_pfn(__pa(_stext));
5186+ kernel.virtual = (unsigned long)_stext;
5187+ kernel.length = __init_begin - _stext;
5188+ kernel.type = __MT_MEMORY_RWX;
5189+ create_mapping(&kernel);
5190+
5191+ if (map.virtual < (unsigned long)_stext) {
5192+ map.length = (unsigned long)_stext - map.virtual;
5193+ map.type = __MT_MEMORY_RWX;
5194+ create_mapping(&map);
5195+ }
5196+
5197+ map.pfn = __phys_to_pfn(__pa(_sdata));
5198+ map.virtual = (unsigned long)_sdata;
5199+ map.length = end - __pa(_sdata);
5200+ }
5201+
5202+ map.type = MT_MEMORY_RW;
5203+ create_mapping(&map);
5204+#else
5205 if (end < kernel_x_start || start >= kernel_x_end) {
5206 map.pfn = __phys_to_pfn(start);
5207 map.virtual = __phys_to_virt(start);
5208 map.length = end - start;
5209- map.type = MT_MEMORY_RWX;
5210+ map.type = __MT_MEMORY_RWX;
5211
5212 create_mapping(&map);
5213 } else {
5214@@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
5215 map.pfn = __phys_to_pfn(kernel_x_start);
5216 map.virtual = __phys_to_virt(kernel_x_start);
5217 map.length = kernel_x_end - kernel_x_start;
5218- map.type = MT_MEMORY_RWX;
5219+ map.type = __MT_MEMORY_RWX;
5220
5221 create_mapping(&map);
5222
5223@@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
5224 create_mapping(&map);
5225 }
5226 }
5227+#endif
5228 }
5229 }
5230
5231diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
5232index 5b217f4..c23f40e 100644
5233--- a/arch/arm/plat-iop/setup.c
5234+++ b/arch/arm/plat-iop/setup.c
5235@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
5236 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
5237 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
5238 .length = IOP3XX_PERIPHERAL_SIZE,
5239- .type = MT_UNCACHED,
5240+ .type = MT_UNCACHED_RW,
5241 },
5242 };
5243
5244diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
5245index a5bc92d..0bb4730 100644
5246--- a/arch/arm/plat-omap/sram.c
5247+++ b/arch/arm/plat-omap/sram.c
5248@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
5249 * Looks like we need to preserve some bootloader code at the
5250 * beginning of SRAM for jumping to flash for reboot to work...
5251 */
5252+ pax_open_kernel();
5253 memset_io(omap_sram_base + omap_sram_skip, 0,
5254 omap_sram_size - omap_sram_skip);
5255+ pax_close_kernel();
5256 }
5257diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
5258index ce6d763..cfea917 100644
5259--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
5260+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
5261@@ -47,7 +47,7 @@ struct samsung_dma_ops {
5262 int (*started)(unsigned ch);
5263 int (*flush)(unsigned ch);
5264 int (*stop)(unsigned ch);
5265-};
5266+} __no_const;
5267
5268 extern void *samsung_dmadev_get_ops(void);
5269 extern void *s3c_dma_get_ops(void);
5270diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
5271index 6389d60..b5d3bdd 100644
5272--- a/arch/arm64/include/asm/barrier.h
5273+++ b/arch/arm64/include/asm/barrier.h
5274@@ -41,7 +41,7 @@
5275 do { \
5276 compiletime_assert_atomic_type(*p); \
5277 barrier(); \
5278- ACCESS_ONCE(*p) = (v); \
5279+ ACCESS_ONCE_RW(*p) = (v); \
5280 } while (0)
5281
5282 #define smp_load_acquire(p) \
5283diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
5284index 3bf8f4e..5dd5491 100644
5285--- a/arch/arm64/include/asm/uaccess.h
5286+++ b/arch/arm64/include/asm/uaccess.h
5287@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
5288 flag; \
5289 })
5290
5291+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5292 #define access_ok(type, addr, size) __range_ok(addr, size)
5293 #define user_addr_max get_fs
5294
5295diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
5296index c3a58a1..78fbf54 100644
5297--- a/arch/avr32/include/asm/cache.h
5298+++ b/arch/avr32/include/asm/cache.h
5299@@ -1,8 +1,10 @@
5300 #ifndef __ASM_AVR32_CACHE_H
5301 #define __ASM_AVR32_CACHE_H
5302
5303+#include <linux/const.h>
5304+
5305 #define L1_CACHE_SHIFT 5
5306-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5307+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5308
5309 /*
5310 * Memory returned by kmalloc() may be used for DMA, so we must make
5311diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
5312index d232888..87c8df1 100644
5313--- a/arch/avr32/include/asm/elf.h
5314+++ b/arch/avr32/include/asm/elf.h
5315@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
5316 the loader. We need to make sure that it is out of the way of the program
5317 that it will "exec", and that there is sufficient room for the brk. */
5318
5319-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
5320+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5321
5322+#ifdef CONFIG_PAX_ASLR
5323+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
5324+
5325+#define PAX_DELTA_MMAP_LEN 15
5326+#define PAX_DELTA_STACK_LEN 15
5327+#endif
5328
5329 /* This yields a mask that user programs can use to figure out what
5330 instruction set this CPU supports. This could be done in user space,
5331diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
5332index 479330b..53717a8 100644
5333--- a/arch/avr32/include/asm/kmap_types.h
5334+++ b/arch/avr32/include/asm/kmap_types.h
5335@@ -2,9 +2,9 @@
5336 #define __ASM_AVR32_KMAP_TYPES_H
5337
5338 #ifdef CONFIG_DEBUG_HIGHMEM
5339-# define KM_TYPE_NR 29
5340+# define KM_TYPE_NR 30
5341 #else
5342-# define KM_TYPE_NR 14
5343+# define KM_TYPE_NR 15
5344 #endif
5345
5346 #endif /* __ASM_AVR32_KMAP_TYPES_H */
5347diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
5348index 0eca933..eb78c7b 100644
5349--- a/arch/avr32/mm/fault.c
5350+++ b/arch/avr32/mm/fault.c
5351@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
5352
5353 int exception_trace = 1;
5354
5355+#ifdef CONFIG_PAX_PAGEEXEC
5356+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5357+{
5358+ unsigned long i;
5359+
5360+ printk(KERN_ERR "PAX: bytes at PC: ");
5361+ for (i = 0; i < 20; i++) {
5362+ unsigned char c;
5363+ if (get_user(c, (unsigned char *)pc+i))
5364+ printk(KERN_CONT "???????? ");
5365+ else
5366+ printk(KERN_CONT "%02x ", c);
5367+ }
5368+ printk("\n");
5369+}
5370+#endif
5371+
5372 /*
5373 * This routine handles page faults. It determines the address and the
5374 * problem, and then passes it off to one of the appropriate routines.
5375@@ -176,6 +193,16 @@ bad_area:
5376 up_read(&mm->mmap_sem);
5377
5378 if (user_mode(regs)) {
5379+
5380+#ifdef CONFIG_PAX_PAGEEXEC
5381+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5382+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
5383+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
5384+ do_group_exit(SIGKILL);
5385+ }
5386+ }
5387+#endif
5388+
5389 if (exception_trace && printk_ratelimit())
5390 printk("%s%s[%d]: segfault at %08lx pc %08lx "
5391 "sp %08lx ecr %lu\n",
5392diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
5393index 568885a..f8008df 100644
5394--- a/arch/blackfin/include/asm/cache.h
5395+++ b/arch/blackfin/include/asm/cache.h
5396@@ -7,6 +7,7 @@
5397 #ifndef __ARCH_BLACKFIN_CACHE_H
5398 #define __ARCH_BLACKFIN_CACHE_H
5399
5400+#include <linux/const.h>
5401 #include <linux/linkage.h> /* for asmlinkage */
5402
5403 /*
5404@@ -14,7 +15,7 @@
5405 * Blackfin loads 32 bytes for cache
5406 */
5407 #define L1_CACHE_SHIFT 5
5408-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5409+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5410 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5411
5412 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5413diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
5414index aea2718..3639a60 100644
5415--- a/arch/cris/include/arch-v10/arch/cache.h
5416+++ b/arch/cris/include/arch-v10/arch/cache.h
5417@@ -1,8 +1,9 @@
5418 #ifndef _ASM_ARCH_CACHE_H
5419 #define _ASM_ARCH_CACHE_H
5420
5421+#include <linux/const.h>
5422 /* Etrax 100LX have 32-byte cache-lines. */
5423-#define L1_CACHE_BYTES 32
5424 #define L1_CACHE_SHIFT 5
5425+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5426
5427 #endif /* _ASM_ARCH_CACHE_H */
5428diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
5429index 7caf25d..ee65ac5 100644
5430--- a/arch/cris/include/arch-v32/arch/cache.h
5431+++ b/arch/cris/include/arch-v32/arch/cache.h
5432@@ -1,11 +1,12 @@
5433 #ifndef _ASM_CRIS_ARCH_CACHE_H
5434 #define _ASM_CRIS_ARCH_CACHE_H
5435
5436+#include <linux/const.h>
5437 #include <arch/hwregs/dma.h>
5438
5439 /* A cache-line is 32 bytes. */
5440-#define L1_CACHE_BYTES 32
5441 #define L1_CACHE_SHIFT 5
5442+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5443
5444 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5445
5446diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5447index f6c3a16..cd422a4 100644
5448--- a/arch/frv/include/asm/atomic.h
5449+++ b/arch/frv/include/asm/atomic.h
5450@@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5451 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5452 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5453
5454+#define atomic64_read_unchecked(v) atomic64_read(v)
5455+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5456+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5457+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5458+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5459+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5460+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5461+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5462+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5463+
5464 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5465 {
5466 int c, old;
5467diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5468index 2797163..c2a401d 100644
5469--- a/arch/frv/include/asm/cache.h
5470+++ b/arch/frv/include/asm/cache.h
5471@@ -12,10 +12,11 @@
5472 #ifndef __ASM_CACHE_H
5473 #define __ASM_CACHE_H
5474
5475+#include <linux/const.h>
5476
5477 /* bytes per L1 cache line */
5478 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5479-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5480+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5481
5482 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5483 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5484diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5485index 43901f2..0d8b865 100644
5486--- a/arch/frv/include/asm/kmap_types.h
5487+++ b/arch/frv/include/asm/kmap_types.h
5488@@ -2,6 +2,6 @@
5489 #ifndef _ASM_KMAP_TYPES_H
5490 #define _ASM_KMAP_TYPES_H
5491
5492-#define KM_TYPE_NR 17
5493+#define KM_TYPE_NR 18
5494
5495 #endif
5496diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5497index 836f147..4cf23f5 100644
5498--- a/arch/frv/mm/elf-fdpic.c
5499+++ b/arch/frv/mm/elf-fdpic.c
5500@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5501 {
5502 struct vm_area_struct *vma;
5503 struct vm_unmapped_area_info info;
5504+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5505
5506 if (len > TASK_SIZE)
5507 return -ENOMEM;
5508@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5509 if (addr) {
5510 addr = PAGE_ALIGN(addr);
5511 vma = find_vma(current->mm, addr);
5512- if (TASK_SIZE - len >= addr &&
5513- (!vma || addr + len <= vma->vm_start))
5514+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5515 goto success;
5516 }
5517
5518@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5519 info.high_limit = (current->mm->start_stack - 0x00200000);
5520 info.align_mask = 0;
5521 info.align_offset = 0;
5522+ info.threadstack_offset = offset;
5523 addr = vm_unmapped_area(&info);
5524 if (!(addr & ~PAGE_MASK))
5525 goto success;
5526diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5527index f4ca594..adc72fd6 100644
5528--- a/arch/hexagon/include/asm/cache.h
5529+++ b/arch/hexagon/include/asm/cache.h
5530@@ -21,9 +21,11 @@
5531 #ifndef __ASM_CACHE_H
5532 #define __ASM_CACHE_H
5533
5534+#include <linux/const.h>
5535+
5536 /* Bytes per L1 cache line */
5537-#define L1_CACHE_SHIFT (5)
5538-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5539+#define L1_CACHE_SHIFT 5
5540+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5541
5542 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5543 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5544diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5545index 2f3abcf..e63c7fa 100644
5546--- a/arch/ia64/Kconfig
5547+++ b/arch/ia64/Kconfig
5548@@ -547,6 +547,7 @@ source "drivers/sn/Kconfig"
5549 config KEXEC
5550 bool "kexec system call"
5551 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5552+ depends on !GRKERNSEC_KMEM
5553 help
5554 kexec is a system call that implements the ability to shutdown your
5555 current kernel, and to start another kernel. It is like a reboot
5556diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5557index 0f8bf48..40ea950 100644
5558--- a/arch/ia64/include/asm/atomic.h
5559+++ b/arch/ia64/include/asm/atomic.h
5560@@ -209,4 +209,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5561 #define atomic64_inc(v) atomic64_add(1, (v))
5562 #define atomic64_dec(v) atomic64_sub(1, (v))
5563
5564+#define atomic64_read_unchecked(v) atomic64_read(v)
5565+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5566+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5567+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5568+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5569+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5570+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5571+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5572+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5573+
5574 #endif /* _ASM_IA64_ATOMIC_H */
5575diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5576index a48957c..e097b56 100644
5577--- a/arch/ia64/include/asm/barrier.h
5578+++ b/arch/ia64/include/asm/barrier.h
5579@@ -67,7 +67,7 @@
5580 do { \
5581 compiletime_assert_atomic_type(*p); \
5582 barrier(); \
5583- ACCESS_ONCE(*p) = (v); \
5584+ ACCESS_ONCE_RW(*p) = (v); \
5585 } while (0)
5586
5587 #define smp_load_acquire(p) \
5588diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5589index 988254a..e1ee885 100644
5590--- a/arch/ia64/include/asm/cache.h
5591+++ b/arch/ia64/include/asm/cache.h
5592@@ -1,6 +1,7 @@
5593 #ifndef _ASM_IA64_CACHE_H
5594 #define _ASM_IA64_CACHE_H
5595
5596+#include <linux/const.h>
5597
5598 /*
5599 * Copyright (C) 1998-2000 Hewlett-Packard Co
5600@@ -9,7 +10,7 @@
5601
5602 /* Bytes per L1 (data) cache line. */
5603 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5604-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5605+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5606
5607 #ifdef CONFIG_SMP
5608 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5609diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5610index 5a83c5c..4d7f553 100644
5611--- a/arch/ia64/include/asm/elf.h
5612+++ b/arch/ia64/include/asm/elf.h
5613@@ -42,6 +42,13 @@
5614 */
5615 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5616
5617+#ifdef CONFIG_PAX_ASLR
5618+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5619+
5620+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5621+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5622+#endif
5623+
5624 #define PT_IA_64_UNWIND 0x70000001
5625
5626 /* IA-64 relocations: */
5627diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5628index 5767cdf..7462574 100644
5629--- a/arch/ia64/include/asm/pgalloc.h
5630+++ b/arch/ia64/include/asm/pgalloc.h
5631@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5632 pgd_val(*pgd_entry) = __pa(pud);
5633 }
5634
5635+static inline void
5636+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5637+{
5638+ pgd_populate(mm, pgd_entry, pud);
5639+}
5640+
5641 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5642 {
5643 return quicklist_alloc(0, GFP_KERNEL, NULL);
5644@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5645 pud_val(*pud_entry) = __pa(pmd);
5646 }
5647
5648+static inline void
5649+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5650+{
5651+ pud_populate(mm, pud_entry, pmd);
5652+}
5653+
5654 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5655 {
5656 return quicklist_alloc(0, GFP_KERNEL, NULL);
5657diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5658index 7935115..c0eca6a 100644
5659--- a/arch/ia64/include/asm/pgtable.h
5660+++ b/arch/ia64/include/asm/pgtable.h
5661@@ -12,7 +12,7 @@
5662 * David Mosberger-Tang <davidm@hpl.hp.com>
5663 */
5664
5665-
5666+#include <linux/const.h>
5667 #include <asm/mman.h>
5668 #include <asm/page.h>
5669 #include <asm/processor.h>
5670@@ -142,6 +142,17 @@
5671 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5672 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5673 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5674+
5675+#ifdef CONFIG_PAX_PAGEEXEC
5676+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5677+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5678+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5679+#else
5680+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5681+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5682+# define PAGE_COPY_NOEXEC PAGE_COPY
5683+#endif
5684+
5685 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5686 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5687 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5688diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5689index 45698cd..e8e2dbc 100644
5690--- a/arch/ia64/include/asm/spinlock.h
5691+++ b/arch/ia64/include/asm/spinlock.h
5692@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5693 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5694
5695 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5696- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5697+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5698 }
5699
5700 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5701diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5702index 449c8c0..3d4b1e9 100644
5703--- a/arch/ia64/include/asm/uaccess.h
5704+++ b/arch/ia64/include/asm/uaccess.h
5705@@ -70,6 +70,7 @@
5706 && ((segment).seg == KERNEL_DS.seg \
5707 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5708 })
5709+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5710 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5711
5712 /*
5713@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5714 static inline unsigned long
5715 __copy_to_user (void __user *to, const void *from, unsigned long count)
5716 {
5717+ if (count > INT_MAX)
5718+ return count;
5719+
5720+ if (!__builtin_constant_p(count))
5721+ check_object_size(from, count, true);
5722+
5723 return __copy_user(to, (__force void __user *) from, count);
5724 }
5725
5726 static inline unsigned long
5727 __copy_from_user (void *to, const void __user *from, unsigned long count)
5728 {
5729+ if (count > INT_MAX)
5730+ return count;
5731+
5732+ if (!__builtin_constant_p(count))
5733+ check_object_size(to, count, false);
5734+
5735 return __copy_user((__force void __user *) to, from, count);
5736 }
5737
5738@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5739 ({ \
5740 void __user *__cu_to = (to); \
5741 const void *__cu_from = (from); \
5742- long __cu_len = (n); \
5743+ unsigned long __cu_len = (n); \
5744 \
5745- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5746+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5747+ if (!__builtin_constant_p(n)) \
5748+ check_object_size(__cu_from, __cu_len, true); \
5749 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5750+ } \
5751 __cu_len; \
5752 })
5753
5754@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5755 ({ \
5756 void *__cu_to = (to); \
5757 const void __user *__cu_from = (from); \
5758- long __cu_len = (n); \
5759+ unsigned long __cu_len = (n); \
5760 \
5761 __chk_user_ptr(__cu_from); \
5762- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5763+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5764+ if (!__builtin_constant_p(n)) \
5765+ check_object_size(__cu_to, __cu_len, false); \
5766 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5767+ } \
5768 __cu_len; \
5769 })
5770
5771diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5772index 24603be..948052d 100644
5773--- a/arch/ia64/kernel/module.c
5774+++ b/arch/ia64/kernel/module.c
5775@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5776 void
5777 module_free (struct module *mod, void *module_region)
5778 {
5779- if (mod && mod->arch.init_unw_table &&
5780- module_region == mod->module_init) {
5781+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5782 unw_remove_unwind_table(mod->arch.init_unw_table);
5783 mod->arch.init_unw_table = NULL;
5784 }
5785@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5786 }
5787
5788 static inline int
5789+in_init_rx (const struct module *mod, uint64_t addr)
5790+{
5791+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5792+}
5793+
5794+static inline int
5795+in_init_rw (const struct module *mod, uint64_t addr)
5796+{
5797+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5798+}
5799+
5800+static inline int
5801 in_init (const struct module *mod, uint64_t addr)
5802 {
5803- return addr - (uint64_t) mod->module_init < mod->init_size;
5804+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5805+}
5806+
5807+static inline int
5808+in_core_rx (const struct module *mod, uint64_t addr)
5809+{
5810+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5811+}
5812+
5813+static inline int
5814+in_core_rw (const struct module *mod, uint64_t addr)
5815+{
5816+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5817 }
5818
5819 static inline int
5820 in_core (const struct module *mod, uint64_t addr)
5821 {
5822- return addr - (uint64_t) mod->module_core < mod->core_size;
5823+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5824 }
5825
5826 static inline int
5827@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5828 break;
5829
5830 case RV_BDREL:
5831- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5832+ if (in_init_rx(mod, val))
5833+ val -= (uint64_t) mod->module_init_rx;
5834+ else if (in_init_rw(mod, val))
5835+ val -= (uint64_t) mod->module_init_rw;
5836+ else if (in_core_rx(mod, val))
5837+ val -= (uint64_t) mod->module_core_rx;
5838+ else if (in_core_rw(mod, val))
5839+ val -= (uint64_t) mod->module_core_rw;
5840 break;
5841
5842 case RV_LTV:
5843@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5844 * addresses have been selected...
5845 */
5846 uint64_t gp;
5847- if (mod->core_size > MAX_LTOFF)
5848+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5849 /*
5850 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5851 * at the end of the module.
5852 */
5853- gp = mod->core_size - MAX_LTOFF / 2;
5854+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5855 else
5856- gp = mod->core_size / 2;
5857- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5858+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5859+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5860 mod->arch.gp = gp;
5861 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5862 }
5863diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5864index c39c3cd..3c77738 100644
5865--- a/arch/ia64/kernel/palinfo.c
5866+++ b/arch/ia64/kernel/palinfo.c
5867@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5868 return NOTIFY_OK;
5869 }
5870
5871-static struct notifier_block __refdata palinfo_cpu_notifier =
5872+static struct notifier_block palinfo_cpu_notifier =
5873 {
5874 .notifier_call = palinfo_cpu_callback,
5875 .priority = 0,
5876diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5877index 41e33f8..65180b2a 100644
5878--- a/arch/ia64/kernel/sys_ia64.c
5879+++ b/arch/ia64/kernel/sys_ia64.c
5880@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5881 unsigned long align_mask = 0;
5882 struct mm_struct *mm = current->mm;
5883 struct vm_unmapped_area_info info;
5884+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5885
5886 if (len > RGN_MAP_LIMIT)
5887 return -ENOMEM;
5888@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5889 if (REGION_NUMBER(addr) == RGN_HPAGE)
5890 addr = 0;
5891 #endif
5892+
5893+#ifdef CONFIG_PAX_RANDMMAP
5894+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5895+ addr = mm->free_area_cache;
5896+ else
5897+#endif
5898+
5899 if (!addr)
5900 addr = TASK_UNMAPPED_BASE;
5901
5902@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5903 info.high_limit = TASK_SIZE;
5904 info.align_mask = align_mask;
5905 info.align_offset = 0;
5906+ info.threadstack_offset = offset;
5907 return vm_unmapped_area(&info);
5908 }
5909
5910diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5911index 84f8a52..7c76178 100644
5912--- a/arch/ia64/kernel/vmlinux.lds.S
5913+++ b/arch/ia64/kernel/vmlinux.lds.S
5914@@ -192,7 +192,7 @@ SECTIONS {
5915 /* Per-cpu data: */
5916 . = ALIGN(PERCPU_PAGE_SIZE);
5917 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5918- __phys_per_cpu_start = __per_cpu_load;
5919+ __phys_per_cpu_start = per_cpu_load;
5920 /*
5921 * ensure percpu data fits
5922 * into percpu page size
5923diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5924index 7225dad..2a7c8256 100644
5925--- a/arch/ia64/mm/fault.c
5926+++ b/arch/ia64/mm/fault.c
5927@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5928 return pte_present(pte);
5929 }
5930
5931+#ifdef CONFIG_PAX_PAGEEXEC
5932+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5933+{
5934+ unsigned long i;
5935+
5936+ printk(KERN_ERR "PAX: bytes at PC: ");
5937+ for (i = 0; i < 8; i++) {
5938+ unsigned int c;
5939+ if (get_user(c, (unsigned int *)pc+i))
5940+ printk(KERN_CONT "???????? ");
5941+ else
5942+ printk(KERN_CONT "%08x ", c);
5943+ }
5944+ printk("\n");
5945+}
5946+#endif
5947+
5948 # define VM_READ_BIT 0
5949 # define VM_WRITE_BIT 1
5950 # define VM_EXEC_BIT 2
5951@@ -151,8 +168,21 @@ retry:
5952 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5953 goto bad_area;
5954
5955- if ((vma->vm_flags & mask) != mask)
5956+ if ((vma->vm_flags & mask) != mask) {
5957+
5958+#ifdef CONFIG_PAX_PAGEEXEC
5959+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5960+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5961+ goto bad_area;
5962+
5963+ up_read(&mm->mmap_sem);
5964+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5965+ do_group_exit(SIGKILL);
5966+ }
5967+#endif
5968+
5969 goto bad_area;
5970+ }
5971
5972 /*
5973 * If for any reason at all we couldn't handle the fault, make
5974diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5975index 76069c1..c2aa816 100644
5976--- a/arch/ia64/mm/hugetlbpage.c
5977+++ b/arch/ia64/mm/hugetlbpage.c
5978@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5979 unsigned long pgoff, unsigned long flags)
5980 {
5981 struct vm_unmapped_area_info info;
5982+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5983
5984 if (len > RGN_MAP_LIMIT)
5985 return -ENOMEM;
5986@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5987 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5988 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5989 info.align_offset = 0;
5990+ info.threadstack_offset = offset;
5991 return vm_unmapped_area(&info);
5992 }
5993
5994diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5995index 25c3502..560dae7 100644
5996--- a/arch/ia64/mm/init.c
5997+++ b/arch/ia64/mm/init.c
5998@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5999 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
6000 vma->vm_end = vma->vm_start + PAGE_SIZE;
6001 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
6002+
6003+#ifdef CONFIG_PAX_PAGEEXEC
6004+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
6005+ vma->vm_flags &= ~VM_EXEC;
6006+
6007+#ifdef CONFIG_PAX_MPROTECT
6008+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
6009+ vma->vm_flags &= ~VM_MAYEXEC;
6010+#endif
6011+
6012+ }
6013+#endif
6014+
6015 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6016 down_write(&current->mm->mmap_sem);
6017 if (insert_vm_struct(current->mm, vma)) {
6018diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
6019index 40b3ee9..8c2c112 100644
6020--- a/arch/m32r/include/asm/cache.h
6021+++ b/arch/m32r/include/asm/cache.h
6022@@ -1,8 +1,10 @@
6023 #ifndef _ASM_M32R_CACHE_H
6024 #define _ASM_M32R_CACHE_H
6025
6026+#include <linux/const.h>
6027+
6028 /* L1 cache line size */
6029 #define L1_CACHE_SHIFT 4
6030-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6031+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6032
6033 #endif /* _ASM_M32R_CACHE_H */
6034diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
6035index 82abd15..d95ae5d 100644
6036--- a/arch/m32r/lib/usercopy.c
6037+++ b/arch/m32r/lib/usercopy.c
6038@@ -14,6 +14,9 @@
6039 unsigned long
6040 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
6041 {
6042+ if ((long)n < 0)
6043+ return n;
6044+
6045 prefetch(from);
6046 if (access_ok(VERIFY_WRITE, to, n))
6047 __copy_user(to,from,n);
6048@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
6049 unsigned long
6050 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
6051 {
6052+ if ((long)n < 0)
6053+ return n;
6054+
6055 prefetchw(to);
6056 if (access_ok(VERIFY_READ, from, n))
6057 __copy_user_zeroing(to,from,n);
6058diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
6059index 0395c51..5f26031 100644
6060--- a/arch/m68k/include/asm/cache.h
6061+++ b/arch/m68k/include/asm/cache.h
6062@@ -4,9 +4,11 @@
6063 #ifndef __ARCH_M68K_CACHE_H
6064 #define __ARCH_M68K_CACHE_H
6065
6066+#include <linux/const.h>
6067+
6068 /* bytes per L1 cache line */
6069 #define L1_CACHE_SHIFT 4
6070-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
6071+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6072
6073 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
6074
6075diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
6076index c7591e8..ecef036 100644
6077--- a/arch/metag/include/asm/barrier.h
6078+++ b/arch/metag/include/asm/barrier.h
6079@@ -89,7 +89,7 @@ static inline void fence(void)
6080 do { \
6081 compiletime_assert_atomic_type(*p); \
6082 smp_mb(); \
6083- ACCESS_ONCE(*p) = (v); \
6084+ ACCESS_ONCE_RW(*p) = (v); \
6085 } while (0)
6086
6087 #define smp_load_acquire(p) \
6088diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
6089index 3c52fa6..11b2ad8 100644
6090--- a/arch/metag/mm/hugetlbpage.c
6091+++ b/arch/metag/mm/hugetlbpage.c
6092@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
6093 info.high_limit = TASK_SIZE;
6094 info.align_mask = PAGE_MASK & HUGEPT_MASK;
6095 info.align_offset = 0;
6096+ info.threadstack_offset = 0;
6097 return vm_unmapped_area(&info);
6098 }
6099
6100diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
6101index 4efe96a..60e8699 100644
6102--- a/arch/microblaze/include/asm/cache.h
6103+++ b/arch/microblaze/include/asm/cache.h
6104@@ -13,11 +13,12 @@
6105 #ifndef _ASM_MICROBLAZE_CACHE_H
6106 #define _ASM_MICROBLAZE_CACHE_H
6107
6108+#include <linux/const.h>
6109 #include <asm/registers.h>
6110
6111 #define L1_CACHE_SHIFT 5
6112 /* word-granular cache in microblaze */
6113-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6114+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6115
6116 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6117
6118diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
6119index 4e238e6..7c9ed92 100644
6120--- a/arch/mips/Kconfig
6121+++ b/arch/mips/Kconfig
6122@@ -2392,6 +2392,7 @@ source "kernel/Kconfig.preempt"
6123
6124 config KEXEC
6125 bool "Kexec system call"
6126+ depends on !GRKERNSEC_KMEM
6127 help
6128 kexec is a system call that implements the ability to shutdown your
6129 current kernel, and to start another kernel. It is like a reboot
6130diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
6131index 02f2444..506969c 100644
6132--- a/arch/mips/cavium-octeon/dma-octeon.c
6133+++ b/arch/mips/cavium-octeon/dma-octeon.c
6134@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
6135 if (dma_release_from_coherent(dev, order, vaddr))
6136 return;
6137
6138- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
6139+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
6140 }
6141
6142 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
6143diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
6144index 37b2bef..02122b8 100644
6145--- a/arch/mips/include/asm/atomic.h
6146+++ b/arch/mips/include/asm/atomic.h
6147@@ -21,15 +21,39 @@
6148 #include <asm/cmpxchg.h>
6149 #include <asm/war.h>
6150
6151+#ifdef CONFIG_GENERIC_ATOMIC64
6152+#include <asm-generic/atomic64.h>
6153+#endif
6154+
6155 #define ATOMIC_INIT(i) { (i) }
6156
6157+#ifdef CONFIG_64BIT
6158+#define _ASM_EXTABLE(from, to) \
6159+" .section __ex_table,\"a\"\n" \
6160+" .dword " #from ", " #to"\n" \
6161+" .previous\n"
6162+#else
6163+#define _ASM_EXTABLE(from, to) \
6164+" .section __ex_table,\"a\"\n" \
6165+" .word " #from ", " #to"\n" \
6166+" .previous\n"
6167+#endif
6168+
6169 /*
6170 * atomic_read - read atomic variable
6171 * @v: pointer of type atomic_t
6172 *
6173 * Atomically reads the value of @v.
6174 */
6175-#define atomic_read(v) (*(volatile int *)&(v)->counter)
6176+static inline int atomic_read(const atomic_t *v)
6177+{
6178+ return (*(volatile const int *) &v->counter);
6179+}
6180+
6181+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6182+{
6183+ return (*(volatile const int *) &v->counter);
6184+}
6185
6186 /*
6187 * atomic_set - set atomic variable
6188@@ -38,7 +62,15 @@
6189 *
6190 * Atomically sets the value of @v to @i.
6191 */
6192-#define atomic_set(v, i) ((v)->counter = (i))
6193+static inline void atomic_set(atomic_t *v, int i)
6194+{
6195+ v->counter = i;
6196+}
6197+
6198+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6199+{
6200+ v->counter = i;
6201+}
6202
6203 /*
6204 * atomic_add - add integer to atomic variable
6205@@ -47,7 +79,67 @@
6206 *
6207 * Atomically adds @i to @v.
6208 */
6209-static __inline__ void atomic_add(int i, atomic_t * v)
6210+static __inline__ void atomic_add(int i, atomic_t *v)
6211+{
6212+ int temp;
6213+
6214+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6215+ __asm__ __volatile__(
6216+ " .set mips3 \n"
6217+ "1: ll %0, %1 # atomic_add \n"
6218+#ifdef CONFIG_PAX_REFCOUNT
6219+ /* Exception on overflow. */
6220+ "2: add %0, %2 \n"
6221+#else
6222+ " addu %0, %2 \n"
6223+#endif
6224+ " sc %0, %1 \n"
6225+ " beqzl %0, 1b \n"
6226+#ifdef CONFIG_PAX_REFCOUNT
6227+ "3: \n"
6228+ _ASM_EXTABLE(2b, 3b)
6229+#endif
6230+ " .set mips0 \n"
6231+ : "=&r" (temp), "+m" (v->counter)
6232+ : "Ir" (i));
6233+ } else if (kernel_uses_llsc) {
6234+ __asm__ __volatile__(
6235+ " .set mips3 \n"
6236+ "1: ll %0, %1 # atomic_add \n"
6237+#ifdef CONFIG_PAX_REFCOUNT
6238+ /* Exception on overflow. */
6239+ "2: add %0, %2 \n"
6240+#else
6241+ " addu %0, %2 \n"
6242+#endif
6243+ " sc %0, %1 \n"
6244+ " beqz %0, 1b \n"
6245+#ifdef CONFIG_PAX_REFCOUNT
6246+ "3: \n"
6247+ _ASM_EXTABLE(2b, 3b)
6248+#endif
6249+ " .set mips0 \n"
6250+ : "=&r" (temp), "+m" (v->counter)
6251+ : "Ir" (i));
6252+ } else {
6253+ unsigned long flags;
6254+
6255+ raw_local_irq_save(flags);
6256+ __asm__ __volatile__(
6257+#ifdef CONFIG_PAX_REFCOUNT
6258+ /* Exception on overflow. */
6259+ "1: add %0, %1 \n"
6260+ "2: \n"
6261+ _ASM_EXTABLE(1b, 2b)
6262+#else
6263+ " addu %0, %1 \n"
6264+#endif
6265+ : "+r" (v->counter) : "Ir" (i));
6266+ raw_local_irq_restore(flags);
6267+ }
6268+}
6269+
6270+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
6271 {
6272 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6273 int temp;
6274@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
6275 *
6276 * Atomically subtracts @i from @v.
6277 */
6278-static __inline__ void atomic_sub(int i, atomic_t * v)
6279+static __inline__ void atomic_sub(int i, atomic_t *v)
6280+{
6281+ int temp;
6282+
6283+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6284+ __asm__ __volatile__(
6285+ " .set mips3 \n"
6286+ "1: ll %0, %1 # atomic64_sub \n"
6287+#ifdef CONFIG_PAX_REFCOUNT
6288+ /* Exception on overflow. */
6289+ "2: sub %0, %2 \n"
6290+#else
6291+ " subu %0, %2 \n"
6292+#endif
6293+ " sc %0, %1 \n"
6294+ " beqzl %0, 1b \n"
6295+#ifdef CONFIG_PAX_REFCOUNT
6296+ "3: \n"
6297+ _ASM_EXTABLE(2b, 3b)
6298+#endif
6299+ " .set mips0 \n"
6300+ : "=&r" (temp), "+m" (v->counter)
6301+ : "Ir" (i));
6302+ } else if (kernel_uses_llsc) {
6303+ __asm__ __volatile__(
6304+ " .set mips3 \n"
6305+ "1: ll %0, %1 # atomic64_sub \n"
6306+#ifdef CONFIG_PAX_REFCOUNT
6307+ /* Exception on overflow. */
6308+ "2: sub %0, %2 \n"
6309+#else
6310+ " subu %0, %2 \n"
6311+#endif
6312+ " sc %0, %1 \n"
6313+ " beqz %0, 1b \n"
6314+#ifdef CONFIG_PAX_REFCOUNT
6315+ "3: \n"
6316+ _ASM_EXTABLE(2b, 3b)
6317+#endif
6318+ " .set mips0 \n"
6319+ : "=&r" (temp), "+m" (v->counter)
6320+ : "Ir" (i));
6321+ } else {
6322+ unsigned long flags;
6323+
6324+ raw_local_irq_save(flags);
6325+ __asm__ __volatile__(
6326+#ifdef CONFIG_PAX_REFCOUNT
6327+ /* Exception on overflow. */
6328+ "1: sub %0, %1 \n"
6329+ "2: \n"
6330+ _ASM_EXTABLE(1b, 2b)
6331+#else
6332+ " subu %0, %1 \n"
6333+#endif
6334+ : "+r" (v->counter) : "Ir" (i));
6335+ raw_local_irq_restore(flags);
6336+ }
6337+}
6338+
6339+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
6340 {
6341 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6342 int temp;
6343@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
6344 /*
6345 * Same as above, but return the result value
6346 */
6347-static __inline__ int atomic_add_return(int i, atomic_t * v)
6348+static __inline__ int atomic_add_return(int i, atomic_t *v)
6349+{
6350+ int result;
6351+ int temp;
6352+
6353+ smp_mb__before_llsc();
6354+
6355+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6356+ __asm__ __volatile__(
6357+ " .set mips3 \n"
6358+ "1: ll %1, %2 # atomic_add_return \n"
6359+#ifdef CONFIG_PAX_REFCOUNT
6360+ "2: add %0, %1, %3 \n"
6361+#else
6362+ " addu %0, %1, %3 \n"
6363+#endif
6364+ " sc %0, %2 \n"
6365+ " beqzl %0, 1b \n"
6366+#ifdef CONFIG_PAX_REFCOUNT
6367+ " b 4f \n"
6368+ " .set noreorder \n"
6369+ "3: b 5f \n"
6370+ " move %0, %1 \n"
6371+ " .set reorder \n"
6372+ _ASM_EXTABLE(2b, 3b)
6373+#endif
6374+ "4: addu %0, %1, %3 \n"
6375+#ifdef CONFIG_PAX_REFCOUNT
6376+ "5: \n"
6377+#endif
6378+ " .set mips0 \n"
6379+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6380+ : "Ir" (i));
6381+ } else if (kernel_uses_llsc) {
6382+ __asm__ __volatile__(
6383+ " .set mips3 \n"
6384+ "1: ll %1, %2 # atomic_add_return \n"
6385+#ifdef CONFIG_PAX_REFCOUNT
6386+ "2: add %0, %1, %3 \n"
6387+#else
6388+ " addu %0, %1, %3 \n"
6389+#endif
6390+ " sc %0, %2 \n"
6391+ " bnez %0, 4f \n"
6392+ " b 1b \n"
6393+#ifdef CONFIG_PAX_REFCOUNT
6394+ " .set noreorder \n"
6395+ "3: b 5f \n"
6396+ " move %0, %1 \n"
6397+ " .set reorder \n"
6398+ _ASM_EXTABLE(2b, 3b)
6399+#endif
6400+ "4: addu %0, %1, %3 \n"
6401+#ifdef CONFIG_PAX_REFCOUNT
6402+ "5: \n"
6403+#endif
6404+ " .set mips0 \n"
6405+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6406+ : "Ir" (i));
6407+ } else {
6408+ unsigned long flags;
6409+
6410+ raw_local_irq_save(flags);
6411+ __asm__ __volatile__(
6412+ " lw %0, %1 \n"
6413+#ifdef CONFIG_PAX_REFCOUNT
6414+ /* Exception on overflow. */
6415+ "1: add %0, %2 \n"
6416+#else
6417+ " addu %0, %2 \n"
6418+#endif
6419+ " sw %0, %1 \n"
6420+#ifdef CONFIG_PAX_REFCOUNT
6421+ /* Note: Dest reg is not modified on overflow */
6422+ "2: \n"
6423+ _ASM_EXTABLE(1b, 2b)
6424+#endif
6425+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6426+ raw_local_irq_restore(flags);
6427+ }
6428+
6429+ smp_llsc_mb();
6430+
6431+ return result;
6432+}
6433+
6434+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6435 {
6436 int result;
6437
6438@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
6439 return result;
6440 }
6441
6442-static __inline__ int atomic_sub_return(int i, atomic_t * v)
6443+static __inline__ int atomic_sub_return(int i, atomic_t *v)
6444+{
6445+ int result;
6446+ int temp;
6447+
6448+ smp_mb__before_llsc();
6449+
6450+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6451+ __asm__ __volatile__(
6452+ " .set mips3 \n"
6453+ "1: ll %1, %2 # atomic_sub_return \n"
6454+#ifdef CONFIG_PAX_REFCOUNT
6455+ "2: sub %0, %1, %3 \n"
6456+#else
6457+ " subu %0, %1, %3 \n"
6458+#endif
6459+ " sc %0, %2 \n"
6460+ " beqzl %0, 1b \n"
6461+#ifdef CONFIG_PAX_REFCOUNT
6462+ " b 4f \n"
6463+ " .set noreorder \n"
6464+ "3: b 5f \n"
6465+ " move %0, %1 \n"
6466+ " .set reorder \n"
6467+ _ASM_EXTABLE(2b, 3b)
6468+#endif
6469+ "4: subu %0, %1, %3 \n"
6470+#ifdef CONFIG_PAX_REFCOUNT
6471+ "5: \n"
6472+#endif
6473+ " .set mips0 \n"
6474+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6475+ : "Ir" (i), "m" (v->counter)
6476+ : "memory");
6477+ } else if (kernel_uses_llsc) {
6478+ __asm__ __volatile__(
6479+ " .set mips3 \n"
6480+ "1: ll %1, %2 # atomic_sub_return \n"
6481+#ifdef CONFIG_PAX_REFCOUNT
6482+ "2: sub %0, %1, %3 \n"
6483+#else
6484+ " subu %0, %1, %3 \n"
6485+#endif
6486+ " sc %0, %2 \n"
6487+ " bnez %0, 4f \n"
6488+ " b 1b \n"
6489+#ifdef CONFIG_PAX_REFCOUNT
6490+ " .set noreorder \n"
6491+ "3: b 5f \n"
6492+ " move %0, %1 \n"
6493+ " .set reorder \n"
6494+ _ASM_EXTABLE(2b, 3b)
6495+#endif
6496+ "4: subu %0, %1, %3 \n"
6497+#ifdef CONFIG_PAX_REFCOUNT
6498+ "5: \n"
6499+#endif
6500+ " .set mips0 \n"
6501+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6502+ : "Ir" (i));
6503+ } else {
6504+ unsigned long flags;
6505+
6506+ raw_local_irq_save(flags);
6507+ __asm__ __volatile__(
6508+ " lw %0, %1 \n"
6509+#ifdef CONFIG_PAX_REFCOUNT
6510+ /* Exception on overflow. */
6511+ "1: sub %0, %2 \n"
6512+#else
6513+ " subu %0, %2 \n"
6514+#endif
6515+ " sw %0, %1 \n"
6516+#ifdef CONFIG_PAX_REFCOUNT
6517+ /* Note: Dest reg is not modified on overflow */
6518+ "2: \n"
6519+ _ASM_EXTABLE(1b, 2b)
6520+#endif
6521+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6522+ raw_local_irq_restore(flags);
6523+ }
6524+
6525+ smp_llsc_mb();
6526+
6527+ return result;
6528+}
6529+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6530 {
6531 int result;
6532
6533@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6534 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6535 * The function returns the old value of @v minus @i.
6536 */
6537-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6538+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6539 {
6540 int result;
6541
6542@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6543 return result;
6544 }
6545
6546-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6547-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6548+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6549+{
6550+ return cmpxchg(&v->counter, old, new);
6551+}
6552+
6553+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6554+ int new)
6555+{
6556+ return cmpxchg(&(v->counter), old, new);
6557+}
6558+
6559+static inline int atomic_xchg(atomic_t *v, int new)
6560+{
6561+ return xchg(&v->counter, new);
6562+}
6563+
6564+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6565+{
6566+ return xchg(&(v->counter), new);
6567+}
6568
6569 /**
6570 * __atomic_add_unless - add unless the number is a given value
6571@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6572
6573 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6574 #define atomic_inc_return(v) atomic_add_return(1, (v))
6575+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6576+{
6577+ return atomic_add_return_unchecked(1, v);
6578+}
6579
6580 /*
6581 * atomic_sub_and_test - subtract value from variable and test result
6582@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6583 * other cases.
6584 */
6585 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6586+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6587+{
6588+ return atomic_add_return_unchecked(1, v) == 0;
6589+}
6590
6591 /*
6592 * atomic_dec_and_test - decrement by 1 and test
6593@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6594 * Atomically increments @v by 1.
6595 */
6596 #define atomic_inc(v) atomic_add(1, (v))
6597+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6598+{
6599+ atomic_add_unchecked(1, v);
6600+}
6601
6602 /*
6603 * atomic_dec - decrement and test
6604@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6605 * Atomically decrements @v by 1.
6606 */
6607 #define atomic_dec(v) atomic_sub(1, (v))
6608+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6609+{
6610+ atomic_sub_unchecked(1, v);
6611+}
6612
6613 /*
6614 * atomic_add_negative - add and test if negative
6615@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6616 * @v: pointer of type atomic64_t
6617 *
6618 */
6619-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6620+static inline long atomic64_read(const atomic64_t *v)
6621+{
6622+ return (*(volatile const long *) &v->counter);
6623+}
6624+
6625+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6626+{
6627+ return (*(volatile const long *) &v->counter);
6628+}
6629
6630 /*
6631 * atomic64_set - set atomic variable
6632 * @v: pointer of type atomic64_t
6633 * @i: required value
6634 */
6635-#define atomic64_set(v, i) ((v)->counter = (i))
6636+static inline void atomic64_set(atomic64_t *v, long i)
6637+{
6638+ v->counter = i;
6639+}
6640+
6641+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6642+{
6643+ v->counter = i;
6644+}
6645
6646 /*
6647 * atomic64_add - add integer to atomic variable
6648@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6649 *
6650 * Atomically adds @i to @v.
6651 */
6652-static __inline__ void atomic64_add(long i, atomic64_t * v)
6653+static __inline__ void atomic64_add(long i, atomic64_t *v)
6654+{
6655+ long temp;
6656+
6657+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6658+ __asm__ __volatile__(
6659+ " .set mips3 \n"
6660+ "1: lld %0, %1 # atomic64_add \n"
6661+#ifdef CONFIG_PAX_REFCOUNT
6662+ /* Exception on overflow. */
6663+ "2: dadd %0, %2 \n"
6664+#else
6665+ " daddu %0, %2 \n"
6666+#endif
6667+ " scd %0, %1 \n"
6668+ " beqzl %0, 1b \n"
6669+#ifdef CONFIG_PAX_REFCOUNT
6670+ "3: \n"
6671+ _ASM_EXTABLE(2b, 3b)
6672+#endif
6673+ " .set mips0 \n"
6674+ : "=&r" (temp), "+m" (v->counter)
6675+ : "Ir" (i));
6676+ } else if (kernel_uses_llsc) {
6677+ __asm__ __volatile__(
6678+ " .set mips3 \n"
6679+ "1: lld %0, %1 # atomic64_add \n"
6680+#ifdef CONFIG_PAX_REFCOUNT
6681+ /* Exception on overflow. */
6682+ "2: dadd %0, %2 \n"
6683+#else
6684+ " daddu %0, %2 \n"
6685+#endif
6686+ " scd %0, %1 \n"
6687+ " beqz %0, 1b \n"
6688+#ifdef CONFIG_PAX_REFCOUNT
6689+ "3: \n"
6690+ _ASM_EXTABLE(2b, 3b)
6691+#endif
6692+ " .set mips0 \n"
6693+ : "=&r" (temp), "+m" (v->counter)
6694+ : "Ir" (i));
6695+ } else {
6696+ unsigned long flags;
6697+
6698+ raw_local_irq_save(flags);
6699+ __asm__ __volatile__(
6700+#ifdef CONFIG_PAX_REFCOUNT
6701+ /* Exception on overflow. */
6702+ "1: dadd %0, %1 \n"
6703+ "2: \n"
6704+ _ASM_EXTABLE(1b, 2b)
6705+#else
6706+ " daddu %0, %1 \n"
6707+#endif
6708+ : "+r" (v->counter) : "Ir" (i));
6709+ raw_local_irq_restore(flags);
6710+ }
6711+}
6712+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6713 {
6714 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6715 long temp;
6716@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6717 *
6718 * Atomically subtracts @i from @v.
6719 */
6720-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6721+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6722+{
6723+ long temp;
6724+
6725+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6726+ __asm__ __volatile__(
6727+ " .set mips3 \n"
6728+ "1: lld %0, %1 # atomic64_sub \n"
6729+#ifdef CONFIG_PAX_REFCOUNT
6730+ /* Exception on overflow. */
6731+ "2: dsub %0, %2 \n"
6732+#else
6733+ " dsubu %0, %2 \n"
6734+#endif
6735+ " scd %0, %1 \n"
6736+ " beqzl %0, 1b \n"
6737+#ifdef CONFIG_PAX_REFCOUNT
6738+ "3: \n"
6739+ _ASM_EXTABLE(2b, 3b)
6740+#endif
6741+ " .set mips0 \n"
6742+ : "=&r" (temp), "+m" (v->counter)
6743+ : "Ir" (i));
6744+ } else if (kernel_uses_llsc) {
6745+ __asm__ __volatile__(
6746+ " .set mips3 \n"
6747+ "1: lld %0, %1 # atomic64_sub \n"
6748+#ifdef CONFIG_PAX_REFCOUNT
6749+ /* Exception on overflow. */
6750+ "2: dsub %0, %2 \n"
6751+#else
6752+ " dsubu %0, %2 \n"
6753+#endif
6754+ " scd %0, %1 \n"
6755+ " beqz %0, 1b \n"
6756+#ifdef CONFIG_PAX_REFCOUNT
6757+ "3: \n"
6758+ _ASM_EXTABLE(2b, 3b)
6759+#endif
6760+ " .set mips0 \n"
6761+ : "=&r" (temp), "+m" (v->counter)
6762+ : "Ir" (i));
6763+ } else {
6764+ unsigned long flags;
6765+
6766+ raw_local_irq_save(flags);
6767+ __asm__ __volatile__(
6768+#ifdef CONFIG_PAX_REFCOUNT
6769+ /* Exception on overflow. */
6770+ "1: dsub %0, %1 \n"
6771+ "2: \n"
6772+ _ASM_EXTABLE(1b, 2b)
6773+#else
6774+ " dsubu %0, %1 \n"
6775+#endif
6776+ : "+r" (v->counter) : "Ir" (i));
6777+ raw_local_irq_restore(flags);
6778+ }
6779+}
6780+
6781+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6782 {
6783 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6784 long temp;
6785@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6786 /*
6787 * Same as above, but return the result value
6788 */
6789-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6790+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6791+{
6792+ long result;
6793+ long temp;
6794+
6795+ smp_mb__before_llsc();
6796+
6797+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6798+ __asm__ __volatile__(
6799+ " .set mips3 \n"
6800+ "1: lld %1, %2 # atomic64_add_return \n"
6801+#ifdef CONFIG_PAX_REFCOUNT
6802+ "2: dadd %0, %1, %3 \n"
6803+#else
6804+ " daddu %0, %1, %3 \n"
6805+#endif
6806+ " scd %0, %2 \n"
6807+ " beqzl %0, 1b \n"
6808+#ifdef CONFIG_PAX_REFCOUNT
6809+ " b 4f \n"
6810+ " .set noreorder \n"
6811+ "3: b 5f \n"
6812+ " move %0, %1 \n"
6813+ " .set reorder \n"
6814+ _ASM_EXTABLE(2b, 3b)
6815+#endif
6816+ "4: daddu %0, %1, %3 \n"
6817+#ifdef CONFIG_PAX_REFCOUNT
6818+ "5: \n"
6819+#endif
6820+ " .set mips0 \n"
6821+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6822+ : "Ir" (i));
6823+ } else if (kernel_uses_llsc) {
6824+ __asm__ __volatile__(
6825+ " .set mips3 \n"
6826+ "1: lld %1, %2 # atomic64_add_return \n"
6827+#ifdef CONFIG_PAX_REFCOUNT
6828+ "2: dadd %0, %1, %3 \n"
6829+#else
6830+ " daddu %0, %1, %3 \n"
6831+#endif
6832+ " scd %0, %2 \n"
6833+ " bnez %0, 4f \n"
6834+ " b 1b \n"
6835+#ifdef CONFIG_PAX_REFCOUNT
6836+ " .set noreorder \n"
6837+ "3: b 5f \n"
6838+ " move %0, %1 \n"
6839+ " .set reorder \n"
6840+ _ASM_EXTABLE(2b, 3b)
6841+#endif
6842+ "4: daddu %0, %1, %3 \n"
6843+#ifdef CONFIG_PAX_REFCOUNT
6844+ "5: \n"
6845+#endif
6846+ " .set mips0 \n"
6847+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6848+ : "Ir" (i), "m" (v->counter)
6849+ : "memory");
6850+ } else {
6851+ unsigned long flags;
6852+
6853+ raw_local_irq_save(flags);
6854+ __asm__ __volatile__(
6855+ " ld %0, %1 \n"
6856+#ifdef CONFIG_PAX_REFCOUNT
6857+ /* Exception on overflow. */
6858+ "1: dadd %0, %2 \n"
6859+#else
6860+ " daddu %0, %2 \n"
6861+#endif
6862+ " sd %0, %1 \n"
6863+#ifdef CONFIG_PAX_REFCOUNT
6864+ /* Note: Dest reg is not modified on overflow */
6865+ "2: \n"
6866+ _ASM_EXTABLE(1b, 2b)
6867+#endif
6868+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6869+ raw_local_irq_restore(flags);
6870+ }
6871+
6872+ smp_llsc_mb();
6873+
6874+ return result;
6875+}
6876+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6877 {
6878 long result;
6879
6880@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6881 return result;
6882 }
6883
6884-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6885+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6886+{
6887+ long result;
6888+ long temp;
6889+
6890+ smp_mb__before_llsc();
6891+
6892+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6893+ long temp;
6894+
6895+ __asm__ __volatile__(
6896+ " .set mips3 \n"
6897+ "1: lld %1, %2 # atomic64_sub_return \n"
6898+#ifdef CONFIG_PAX_REFCOUNT
6899+ "2: dsub %0, %1, %3 \n"
6900+#else
6901+ " dsubu %0, %1, %3 \n"
6902+#endif
6903+ " scd %0, %2 \n"
6904+ " beqzl %0, 1b \n"
6905+#ifdef CONFIG_PAX_REFCOUNT
6906+ " b 4f \n"
6907+ " .set noreorder \n"
6908+ "3: b 5f \n"
6909+ " move %0, %1 \n"
6910+ " .set reorder \n"
6911+ _ASM_EXTABLE(2b, 3b)
6912+#endif
6913+ "4: dsubu %0, %1, %3 \n"
6914+#ifdef CONFIG_PAX_REFCOUNT
6915+ "5: \n"
6916+#endif
6917+ " .set mips0 \n"
6918+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6919+ : "Ir" (i), "m" (v->counter)
6920+ : "memory");
6921+ } else if (kernel_uses_llsc) {
6922+ __asm__ __volatile__(
6923+ " .set mips3 \n"
6924+ "1: lld %1, %2 # atomic64_sub_return \n"
6925+#ifdef CONFIG_PAX_REFCOUNT
6926+ "2: dsub %0, %1, %3 \n"
6927+#else
6928+ " dsubu %0, %1, %3 \n"
6929+#endif
6930+ " scd %0, %2 \n"
6931+ " bnez %0, 4f \n"
6932+ " b 1b \n"
6933+#ifdef CONFIG_PAX_REFCOUNT
6934+ " .set noreorder \n"
6935+ "3: b 5f \n"
6936+ " move %0, %1 \n"
6937+ " .set reorder \n"
6938+ _ASM_EXTABLE(2b, 3b)
6939+#endif
6940+ "4: dsubu %0, %1, %3 \n"
6941+#ifdef CONFIG_PAX_REFCOUNT
6942+ "5: \n"
6943+#endif
6944+ " .set mips0 \n"
6945+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6946+ : "Ir" (i), "m" (v->counter)
6947+ : "memory");
6948+ } else {
6949+ unsigned long flags;
6950+
6951+ raw_local_irq_save(flags);
6952+ __asm__ __volatile__(
6953+ " ld %0, %1 \n"
6954+#ifdef CONFIG_PAX_REFCOUNT
6955+ /* Exception on overflow. */
6956+ "1: dsub %0, %2 \n"
6957+#else
6958+ " dsubu %0, %2 \n"
6959+#endif
6960+ " sd %0, %1 \n"
6961+#ifdef CONFIG_PAX_REFCOUNT
6962+ /* Note: Dest reg is not modified on overflow */
6963+ "2: \n"
6964+ _ASM_EXTABLE(1b, 2b)
6965+#endif
6966+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6967+ raw_local_irq_restore(flags);
6968+ }
6969+
6970+ smp_llsc_mb();
6971+
6972+ return result;
6973+}
6974+
6975+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6976 {
6977 long result;
6978
6979@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6980 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6981 * The function returns the old value of @v minus @i.
6982 */
6983-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6984+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6985 {
6986 long result;
6987
6988@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6989 return result;
6990 }
6991
6992-#define atomic64_cmpxchg(v, o, n) \
6993- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6994-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6995+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6996+{
6997+ return cmpxchg(&v->counter, old, new);
6998+}
6999+
7000+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
7001+ long new)
7002+{
7003+ return cmpxchg(&(v->counter), old, new);
7004+}
7005+
7006+static inline long atomic64_xchg(atomic64_t *v, long new)
7007+{
7008+ return xchg(&v->counter, new);
7009+}
7010+
7011+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7012+{
7013+ return xchg(&(v->counter), new);
7014+}
7015
7016 /**
7017 * atomic64_add_unless - add unless the number is a given value
7018@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7019
7020 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
7021 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
7022+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
7023
7024 /*
7025 * atomic64_sub_and_test - subtract value from variable and test result
7026@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7027 * other cases.
7028 */
7029 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7030+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
7031
7032 /*
7033 * atomic64_dec_and_test - decrement by 1 and test
7034@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7035 * Atomically increments @v by 1.
7036 */
7037 #define atomic64_inc(v) atomic64_add(1, (v))
7038+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
7039
7040 /*
7041 * atomic64_dec - decrement and test
7042@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7043 * Atomically decrements @v by 1.
7044 */
7045 #define atomic64_dec(v) atomic64_sub(1, (v))
7046+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
7047
7048 /*
7049 * atomic64_add_negative - add and test if negative
7050diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
7051index d0101dd..266982c 100644
7052--- a/arch/mips/include/asm/barrier.h
7053+++ b/arch/mips/include/asm/barrier.h
7054@@ -184,7 +184,7 @@
7055 do { \
7056 compiletime_assert_atomic_type(*p); \
7057 smp_mb(); \
7058- ACCESS_ONCE(*p) = (v); \
7059+ ACCESS_ONCE_RW(*p) = (v); \
7060 } while (0)
7061
7062 #define smp_load_acquire(p) \
7063diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
7064index b4db69f..8f3b093 100644
7065--- a/arch/mips/include/asm/cache.h
7066+++ b/arch/mips/include/asm/cache.h
7067@@ -9,10 +9,11 @@
7068 #ifndef _ASM_CACHE_H
7069 #define _ASM_CACHE_H
7070
7071+#include <linux/const.h>
7072 #include <kmalloc.h>
7073
7074 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
7075-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7076+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7077
7078 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
7079 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7080diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
7081index d414405..6bb4ba2 100644
7082--- a/arch/mips/include/asm/elf.h
7083+++ b/arch/mips/include/asm/elf.h
7084@@ -398,13 +398,16 @@ extern const char *__elf_platform;
7085 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
7086 #endif
7087
7088+#ifdef CONFIG_PAX_ASLR
7089+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7090+
7091+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7092+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7093+#endif
7094+
7095 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7096 struct linux_binprm;
7097 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7098 int uses_interp);
7099
7100-struct mm_struct;
7101-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7102-#define arch_randomize_brk arch_randomize_brk
7103-
7104 #endif /* _ASM_ELF_H */
7105diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
7106index c1f6afa..38cc6e9 100644
7107--- a/arch/mips/include/asm/exec.h
7108+++ b/arch/mips/include/asm/exec.h
7109@@ -12,6 +12,6 @@
7110 #ifndef _ASM_EXEC_H
7111 #define _ASM_EXEC_H
7112
7113-extern unsigned long arch_align_stack(unsigned long sp);
7114+#define arch_align_stack(x) ((x) & ~0xfUL)
7115
7116 #endif /* _ASM_EXEC_H */
7117diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
7118index 9e8ef59..1139d6b 100644
7119--- a/arch/mips/include/asm/hw_irq.h
7120+++ b/arch/mips/include/asm/hw_irq.h
7121@@ -10,7 +10,7 @@
7122
7123 #include <linux/atomic.h>
7124
7125-extern atomic_t irq_err_count;
7126+extern atomic_unchecked_t irq_err_count;
7127
7128 /*
7129 * interrupt-retrigger: NOP for now. This may not be appropriate for all
7130diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
7131index 46dfc3c..a16b13a 100644
7132--- a/arch/mips/include/asm/local.h
7133+++ b/arch/mips/include/asm/local.h
7134@@ -12,15 +12,25 @@ typedef struct
7135 atomic_long_t a;
7136 } local_t;
7137
7138+typedef struct {
7139+ atomic_long_unchecked_t a;
7140+} local_unchecked_t;
7141+
7142 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
7143
7144 #define local_read(l) atomic_long_read(&(l)->a)
7145+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
7146 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
7147+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
7148
7149 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
7150+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
7151 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
7152+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
7153 #define local_inc(l) atomic_long_inc(&(l)->a)
7154+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
7155 #define local_dec(l) atomic_long_dec(&(l)->a)
7156+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
7157
7158 /*
7159 * Same as above, but return the result value
7160@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
7161 return result;
7162 }
7163
7164+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
7165+{
7166+ unsigned long result;
7167+
7168+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
7169+ unsigned long temp;
7170+
7171+ __asm__ __volatile__(
7172+ " .set mips3 \n"
7173+ "1:" __LL "%1, %2 # local_add_return \n"
7174+ " addu %0, %1, %3 \n"
7175+ __SC "%0, %2 \n"
7176+ " beqzl %0, 1b \n"
7177+ " addu %0, %1, %3 \n"
7178+ " .set mips0 \n"
7179+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
7180+ : "Ir" (i), "m" (l->a.counter)
7181+ : "memory");
7182+ } else if (kernel_uses_llsc) {
7183+ unsigned long temp;
7184+
7185+ __asm__ __volatile__(
7186+ " .set mips3 \n"
7187+ "1:" __LL "%1, %2 # local_add_return \n"
7188+ " addu %0, %1, %3 \n"
7189+ __SC "%0, %2 \n"
7190+ " beqz %0, 1b \n"
7191+ " addu %0, %1, %3 \n"
7192+ " .set mips0 \n"
7193+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
7194+ : "Ir" (i), "m" (l->a.counter)
7195+ : "memory");
7196+ } else {
7197+ unsigned long flags;
7198+
7199+ local_irq_save(flags);
7200+ result = l->a.counter;
7201+ result += i;
7202+ l->a.counter = result;
7203+ local_irq_restore(flags);
7204+ }
7205+
7206+ return result;
7207+}
7208+
7209 static __inline__ long local_sub_return(long i, local_t * l)
7210 {
7211 unsigned long result;
7212@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
7213
7214 #define local_cmpxchg(l, o, n) \
7215 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
7216+#define local_cmpxchg_unchecked(l, o, n) \
7217+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
7218 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
7219
7220 /**
7221diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
7222index 5699ec3..95def83 100644
7223--- a/arch/mips/include/asm/page.h
7224+++ b/arch/mips/include/asm/page.h
7225@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
7226 #ifdef CONFIG_CPU_MIPS32
7227 typedef struct { unsigned long pte_low, pte_high; } pte_t;
7228 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
7229- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
7230+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
7231 #else
7232 typedef struct { unsigned long long pte; } pte_t;
7233 #define pte_val(x) ((x).pte)
7234diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
7235index b336037..5b874cc 100644
7236--- a/arch/mips/include/asm/pgalloc.h
7237+++ b/arch/mips/include/asm/pgalloc.h
7238@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7239 {
7240 set_pud(pud, __pud((unsigned long)pmd));
7241 }
7242+
7243+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7244+{
7245+ pud_populate(mm, pud, pmd);
7246+}
7247 #endif
7248
7249 /*
7250diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
7251index 539ddd1..8783f9a 100644
7252--- a/arch/mips/include/asm/pgtable.h
7253+++ b/arch/mips/include/asm/pgtable.h
7254@@ -20,6 +20,9 @@
7255 #include <asm/io.h>
7256 #include <asm/pgtable-bits.h>
7257
7258+#define ktla_ktva(addr) (addr)
7259+#define ktva_ktla(addr) (addr)
7260+
7261 struct mm_struct;
7262 struct vm_area_struct;
7263
7264diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
7265index 7de8658..c109224 100644
7266--- a/arch/mips/include/asm/thread_info.h
7267+++ b/arch/mips/include/asm/thread_info.h
7268@@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
7269 #define TIF_SECCOMP 4 /* secure computing */
7270 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
7271 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
7272+/* li takes a 32bit immediate */
7273+#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
7274+
7275 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
7276 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
7277 #define TIF_NOHZ 19 /* in adaptive nohz mode */
7278@@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
7279 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
7280 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
7281 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7282+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7283
7284 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
7285 _TIF_SYSCALL_AUDIT | \
7286- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
7287+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
7288+ _TIF_GRSEC_SETXID)
7289
7290 /* work to do in syscall_trace_leave() */
7291 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
7292- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
7293+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7294
7295 /* work to do on interrupt/exception return */
7296 #define _TIF_WORK_MASK \
7297@@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
7298 /* work to do on any return to u-space */
7299 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
7300 _TIF_WORK_SYSCALL_EXIT | \
7301- _TIF_SYSCALL_TRACEPOINT)
7302+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7303
7304 /*
7305 * We stash processor id into a COP0 register to retrieve it fast
7306diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
7307index a109510..94ee3f6 100644
7308--- a/arch/mips/include/asm/uaccess.h
7309+++ b/arch/mips/include/asm/uaccess.h
7310@@ -130,6 +130,7 @@ extern u64 __ua_limit;
7311 __ok == 0; \
7312 })
7313
7314+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
7315 #define access_ok(type, addr, size) \
7316 likely(__access_ok((addr), (size), __access_mask))
7317
7318diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
7319index 1188e00..41cf144 100644
7320--- a/arch/mips/kernel/binfmt_elfn32.c
7321+++ b/arch/mips/kernel/binfmt_elfn32.c
7322@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7323 #undef ELF_ET_DYN_BASE
7324 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7325
7326+#ifdef CONFIG_PAX_ASLR
7327+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7328+
7329+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7330+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7331+#endif
7332+
7333 #include <asm/processor.h>
7334 #include <linux/module.h>
7335 #include <linux/elfcore.h>
7336diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
7337index 7faf5f2..f3d3cf4 100644
7338--- a/arch/mips/kernel/binfmt_elfo32.c
7339+++ b/arch/mips/kernel/binfmt_elfo32.c
7340@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7341 #undef ELF_ET_DYN_BASE
7342 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7343
7344+#ifdef CONFIG_PAX_ASLR
7345+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7346+
7347+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7348+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7349+#endif
7350+
7351 #include <asm/processor.h>
7352
7353 /*
7354diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
7355index 50b3648..c2f3cec 100644
7356--- a/arch/mips/kernel/i8259.c
7357+++ b/arch/mips/kernel/i8259.c
7358@@ -201,7 +201,7 @@ spurious_8259A_irq:
7359 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
7360 spurious_irq_mask |= irqmask;
7361 }
7362- atomic_inc(&irq_err_count);
7363+ atomic_inc_unchecked(&irq_err_count);
7364 /*
7365 * Theoretically we do not have to handle this IRQ,
7366 * but in Linux this does not cause problems and is
7367diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
7368index 44a1f79..2bd6aa3 100644
7369--- a/arch/mips/kernel/irq-gt641xx.c
7370+++ b/arch/mips/kernel/irq-gt641xx.c
7371@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
7372 }
7373 }
7374
7375- atomic_inc(&irq_err_count);
7376+ atomic_inc_unchecked(&irq_err_count);
7377 }
7378
7379 void __init gt641xx_irq_init(void)
7380diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
7381index d2bfbc2..a8eacd2 100644
7382--- a/arch/mips/kernel/irq.c
7383+++ b/arch/mips/kernel/irq.c
7384@@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
7385 printk("unexpected IRQ # %d\n", irq);
7386 }
7387
7388-atomic_t irq_err_count;
7389+atomic_unchecked_t irq_err_count;
7390
7391 int arch_show_interrupts(struct seq_file *p, int prec)
7392 {
7393- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
7394+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
7395 return 0;
7396 }
7397
7398 asmlinkage void spurious_interrupt(void)
7399 {
7400- atomic_inc(&irq_err_count);
7401+ atomic_inc_unchecked(&irq_err_count);
7402 }
7403
7404 void __init init_IRQ(void)
7405@@ -109,7 +109,10 @@ void __init init_IRQ(void)
7406 #endif
7407 }
7408
7409+
7410 #ifdef DEBUG_STACKOVERFLOW
7411+extern void gr_handle_kernel_exploit(void);
7412+
7413 static inline void check_stack_overflow(void)
7414 {
7415 unsigned long sp;
7416@@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
7417 printk("do_IRQ: stack overflow: %ld\n",
7418 sp - sizeof(struct thread_info));
7419 dump_stack();
7420+ gr_handle_kernel_exploit();
7421 }
7422 }
7423 #else
7424diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
7425index c4c2069..bde8051 100644
7426--- a/arch/mips/kernel/pm-cps.c
7427+++ b/arch/mips/kernel/pm-cps.c
7428@@ -168,7 +168,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
7429 nc_core_ready_count = nc_addr;
7430
7431 /* Ensure ready_count is zero-initialised before the assembly runs */
7432- ACCESS_ONCE(*nc_core_ready_count) = 0;
7433+ ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
7434 coupled_barrier(&per_cpu(pm_barrier, core), online);
7435
7436 /* Run the generated entry code */
7437diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
7438index 0a1ec0f..d9e93b6 100644
7439--- a/arch/mips/kernel/process.c
7440+++ b/arch/mips/kernel/process.c
7441@@ -572,15 +572,3 @@ unsigned long get_wchan(struct task_struct *task)
7442 out:
7443 return pc;
7444 }
7445-
7446-/*
7447- * Don't forget that the stack pointer must be aligned on a 8 bytes
7448- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
7449- */
7450-unsigned long arch_align_stack(unsigned long sp)
7451-{
7452- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7453- sp -= get_random_int() & ~PAGE_MASK;
7454-
7455- return sp & ALMASK;
7456-}
7457diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
7458index f639ccd..e4b110d 100644
7459--- a/arch/mips/kernel/ptrace.c
7460+++ b/arch/mips/kernel/ptrace.c
7461@@ -630,6 +630,10 @@ long arch_ptrace(struct task_struct *child, long request,
7462 return ret;
7463 }
7464
7465+#ifdef CONFIG_GRKERNSEC_SETXID
7466+extern void gr_delayed_cred_worker(void);
7467+#endif
7468+
7469 /*
7470 * Notification of system call entry/exit
7471 * - triggered by current->work.syscall_trace
7472@@ -646,6 +650,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
7473 tracehook_report_syscall_entry(regs))
7474 ret = -1;
7475
7476+#ifdef CONFIG_GRKERNSEC_SETXID
7477+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7478+ gr_delayed_cred_worker();
7479+#endif
7480+
7481 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7482 trace_sys_enter(regs, regs->regs[2]);
7483
7484diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
7485index 07fc524..b9d7f28 100644
7486--- a/arch/mips/kernel/reset.c
7487+++ b/arch/mips/kernel/reset.c
7488@@ -13,6 +13,7 @@
7489 #include <linux/reboot.h>
7490
7491 #include <asm/reboot.h>
7492+#include <asm/bug.h>
7493
7494 /*
7495 * Urgs ... Too many MIPS machines to handle this in a generic way.
7496@@ -29,16 +30,19 @@ void machine_restart(char *command)
7497 {
7498 if (_machine_restart)
7499 _machine_restart(command);
7500+ BUG();
7501 }
7502
7503 void machine_halt(void)
7504 {
7505 if (_machine_halt)
7506 _machine_halt();
7507+ BUG();
7508 }
7509
7510 void machine_power_off(void)
7511 {
7512 if (pm_power_off)
7513 pm_power_off();
7514+ BUG();
7515 }
7516diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7517index 2242bdd..b284048 100644
7518--- a/arch/mips/kernel/sync-r4k.c
7519+++ b/arch/mips/kernel/sync-r4k.c
7520@@ -18,8 +18,8 @@
7521 #include <asm/mipsregs.h>
7522
7523 static atomic_t count_start_flag = ATOMIC_INIT(0);
7524-static atomic_t count_count_start = ATOMIC_INIT(0);
7525-static atomic_t count_count_stop = ATOMIC_INIT(0);
7526+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7527+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7528 static atomic_t count_reference = ATOMIC_INIT(0);
7529
7530 #define COUNTON 100
7531@@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
7532
7533 for (i = 0; i < NR_LOOPS; i++) {
7534 /* slaves loop on '!= 2' */
7535- while (atomic_read(&count_count_start) != 1)
7536+ while (atomic_read_unchecked(&count_count_start) != 1)
7537 mb();
7538- atomic_set(&count_count_stop, 0);
7539+ atomic_set_unchecked(&count_count_stop, 0);
7540 smp_wmb();
7541
7542 /* this lets the slaves write their count register */
7543- atomic_inc(&count_count_start);
7544+ atomic_inc_unchecked(&count_count_start);
7545
7546 /*
7547 * Everyone initialises count in the last loop:
7548@@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
7549 /*
7550 * Wait for all slaves to leave the synchronization point:
7551 */
7552- while (atomic_read(&count_count_stop) != 1)
7553+ while (atomic_read_unchecked(&count_count_stop) != 1)
7554 mb();
7555- atomic_set(&count_count_start, 0);
7556+ atomic_set_unchecked(&count_count_start, 0);
7557 smp_wmb();
7558- atomic_inc(&count_count_stop);
7559+ atomic_inc_unchecked(&count_count_stop);
7560 }
7561 /* Arrange for an interrupt in a short while */
7562 write_c0_compare(read_c0_count() + COUNTON);
7563@@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
7564 initcount = atomic_read(&count_reference);
7565
7566 for (i = 0; i < NR_LOOPS; i++) {
7567- atomic_inc(&count_count_start);
7568- while (atomic_read(&count_count_start) != 2)
7569+ atomic_inc_unchecked(&count_count_start);
7570+ while (atomic_read_unchecked(&count_count_start) != 2)
7571 mb();
7572
7573 /*
7574@@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
7575 if (i == NR_LOOPS-1)
7576 write_c0_count(initcount);
7577
7578- atomic_inc(&count_count_stop);
7579- while (atomic_read(&count_count_stop) != 2)
7580+ atomic_inc_unchecked(&count_count_stop);
7581+ while (atomic_read_unchecked(&count_count_stop) != 2)
7582 mb();
7583 }
7584 /* Arrange for an interrupt in a short while */
7585diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7586index 51706d6..ec1178c 100644
7587--- a/arch/mips/kernel/traps.c
7588+++ b/arch/mips/kernel/traps.c
7589@@ -687,7 +687,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7590 siginfo_t info;
7591
7592 prev_state = exception_enter();
7593- die_if_kernel("Integer overflow", regs);
7594+ if (unlikely(!user_mode(regs))) {
7595+
7596+#ifdef CONFIG_PAX_REFCOUNT
7597+ if (fixup_exception(regs)) {
7598+ pax_report_refcount_overflow(regs);
7599+ exception_exit(prev_state);
7600+ return;
7601+ }
7602+#endif
7603+
7604+ die("Integer overflow", regs);
7605+ }
7606
7607 info.si_code = FPE_INTOVF;
7608 info.si_signo = SIGFPE;
7609diff --git a/arch/mips/kvm/kvm_mips.c b/arch/mips/kvm/kvm_mips.c
7610index f3c56a1..6a2f01c 100644
7611--- a/arch/mips/kvm/kvm_mips.c
7612+++ b/arch/mips/kvm/kvm_mips.c
7613@@ -841,7 +841,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
7614 return r;
7615 }
7616
7617-int kvm_arch_init(void *opaque)
7618+int kvm_arch_init(const void *opaque)
7619 {
7620 int ret;
7621
7622diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7623index becc42b..9e43d4b 100644
7624--- a/arch/mips/mm/fault.c
7625+++ b/arch/mips/mm/fault.c
7626@@ -28,6 +28,23 @@
7627 #include <asm/highmem.h> /* For VMALLOC_END */
7628 #include <linux/kdebug.h>
7629
7630+#ifdef CONFIG_PAX_PAGEEXEC
7631+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7632+{
7633+ unsigned long i;
7634+
7635+ printk(KERN_ERR "PAX: bytes at PC: ");
7636+ for (i = 0; i < 5; i++) {
7637+ unsigned int c;
7638+ if (get_user(c, (unsigned int *)pc+i))
7639+ printk(KERN_CONT "???????? ");
7640+ else
7641+ printk(KERN_CONT "%08x ", c);
7642+ }
7643+ printk("\n");
7644+}
7645+#endif
7646+
7647 /*
7648 * This routine handles page faults. It determines the address,
7649 * and the problem, and then passes it off to one of the appropriate
7650@@ -199,6 +216,14 @@ bad_area:
7651 bad_area_nosemaphore:
7652 /* User mode accesses just cause a SIGSEGV */
7653 if (user_mode(regs)) {
7654+
7655+#ifdef CONFIG_PAX_PAGEEXEC
7656+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7657+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7658+ do_group_exit(SIGKILL);
7659+ }
7660+#endif
7661+
7662 tsk->thread.cp0_badvaddr = address;
7663 tsk->thread.error_code = write;
7664 #if 0
7665diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7666index f1baadd..5472dca 100644
7667--- a/arch/mips/mm/mmap.c
7668+++ b/arch/mips/mm/mmap.c
7669@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7670 struct vm_area_struct *vma;
7671 unsigned long addr = addr0;
7672 int do_color_align;
7673+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7674 struct vm_unmapped_area_info info;
7675
7676 if (unlikely(len > TASK_SIZE))
7677@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7678 do_color_align = 1;
7679
7680 /* requesting a specific address */
7681+
7682+#ifdef CONFIG_PAX_RANDMMAP
7683+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7684+#endif
7685+
7686 if (addr) {
7687 if (do_color_align)
7688 addr = COLOUR_ALIGN(addr, pgoff);
7689@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7690 addr = PAGE_ALIGN(addr);
7691
7692 vma = find_vma(mm, addr);
7693- if (TASK_SIZE - len >= addr &&
7694- (!vma || addr + len <= vma->vm_start))
7695+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7696 return addr;
7697 }
7698
7699 info.length = len;
7700 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7701 info.align_offset = pgoff << PAGE_SHIFT;
7702+ info.threadstack_offset = offset;
7703
7704 if (dir == DOWN) {
7705 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7706@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7707 {
7708 unsigned long random_factor = 0UL;
7709
7710+#ifdef CONFIG_PAX_RANDMMAP
7711+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7712+#endif
7713+
7714 if (current->flags & PF_RANDOMIZE) {
7715 random_factor = get_random_int();
7716 random_factor = random_factor << PAGE_SHIFT;
7717@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7718
7719 if (mmap_is_legacy()) {
7720 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7721+
7722+#ifdef CONFIG_PAX_RANDMMAP
7723+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7724+ mm->mmap_base += mm->delta_mmap;
7725+#endif
7726+
7727 mm->get_unmapped_area = arch_get_unmapped_area;
7728 } else {
7729 mm->mmap_base = mmap_base(random_factor);
7730+
7731+#ifdef CONFIG_PAX_RANDMMAP
7732+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7733+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7734+#endif
7735+
7736 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7737 }
7738 }
7739
7740-static inline unsigned long brk_rnd(void)
7741-{
7742- unsigned long rnd = get_random_int();
7743-
7744- rnd = rnd << PAGE_SHIFT;
7745- /* 8MB for 32bit, 256MB for 64bit */
7746- if (TASK_IS_32BIT_ADDR)
7747- rnd = rnd & 0x7ffffful;
7748- else
7749- rnd = rnd & 0xffffffful;
7750-
7751- return rnd;
7752-}
7753-
7754-unsigned long arch_randomize_brk(struct mm_struct *mm)
7755-{
7756- unsigned long base = mm->brk;
7757- unsigned long ret;
7758-
7759- ret = PAGE_ALIGN(base + brk_rnd());
7760-
7761- if (ret < mm->brk)
7762- return mm->brk;
7763-
7764- return ret;
7765-}
7766-
7767 int __virt_addr_valid(const volatile void *kaddr)
7768 {
7769 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7770diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7771index 59cccd9..f39ac2f 100644
7772--- a/arch/mips/pci/pci-octeon.c
7773+++ b/arch/mips/pci/pci-octeon.c
7774@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7775
7776
7777 static struct pci_ops octeon_pci_ops = {
7778- octeon_read_config,
7779- octeon_write_config,
7780+ .read = octeon_read_config,
7781+ .write = octeon_write_config,
7782 };
7783
7784 static struct resource octeon_pci_mem_resource = {
7785diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7786index 5e36c33..eb4a17b 100644
7787--- a/arch/mips/pci/pcie-octeon.c
7788+++ b/arch/mips/pci/pcie-octeon.c
7789@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7790 }
7791
7792 static struct pci_ops octeon_pcie0_ops = {
7793- octeon_pcie0_read_config,
7794- octeon_pcie0_write_config,
7795+ .read = octeon_pcie0_read_config,
7796+ .write = octeon_pcie0_write_config,
7797 };
7798
7799 static struct resource octeon_pcie0_mem_resource = {
7800@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7801 };
7802
7803 static struct pci_ops octeon_pcie1_ops = {
7804- octeon_pcie1_read_config,
7805- octeon_pcie1_write_config,
7806+ .read = octeon_pcie1_read_config,
7807+ .write = octeon_pcie1_write_config,
7808 };
7809
7810 static struct resource octeon_pcie1_mem_resource = {
7811@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7812 };
7813
7814 static struct pci_ops octeon_dummy_ops = {
7815- octeon_dummy_read_config,
7816- octeon_dummy_write_config,
7817+ .read = octeon_dummy_read_config,
7818+ .write = octeon_dummy_write_config,
7819 };
7820
7821 static struct resource octeon_dummy_mem_resource = {
7822diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7823index a2358b4..7cead4f 100644
7824--- a/arch/mips/sgi-ip27/ip27-nmi.c
7825+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7826@@ -187,9 +187,9 @@ void
7827 cont_nmi_dump(void)
7828 {
7829 #ifndef REAL_NMI_SIGNAL
7830- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7831+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7832
7833- atomic_inc(&nmied_cpus);
7834+ atomic_inc_unchecked(&nmied_cpus);
7835 #endif
7836 /*
7837 * Only allow 1 cpu to proceed
7838@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7839 udelay(10000);
7840 }
7841 #else
7842- while (atomic_read(&nmied_cpus) != num_online_cpus());
7843+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7844 #endif
7845
7846 /*
7847diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7848index a046b30..6799527 100644
7849--- a/arch/mips/sni/rm200.c
7850+++ b/arch/mips/sni/rm200.c
7851@@ -270,7 +270,7 @@ spurious_8259A_irq:
7852 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7853 spurious_irq_mask |= irqmask;
7854 }
7855- atomic_inc(&irq_err_count);
7856+ atomic_inc_unchecked(&irq_err_count);
7857 /*
7858 * Theoretically we do not have to handle this IRQ,
7859 * but in Linux this does not cause problems and is
7860diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7861index 41e873b..34d33a7 100644
7862--- a/arch/mips/vr41xx/common/icu.c
7863+++ b/arch/mips/vr41xx/common/icu.c
7864@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7865
7866 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7867
7868- atomic_inc(&irq_err_count);
7869+ atomic_inc_unchecked(&irq_err_count);
7870
7871 return -1;
7872 }
7873diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7874index ae0e4ee..e8f0692 100644
7875--- a/arch/mips/vr41xx/common/irq.c
7876+++ b/arch/mips/vr41xx/common/irq.c
7877@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7878 irq_cascade_t *cascade;
7879
7880 if (irq >= NR_IRQS) {
7881- atomic_inc(&irq_err_count);
7882+ atomic_inc_unchecked(&irq_err_count);
7883 return;
7884 }
7885
7886@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7887 ret = cascade->get_irq(irq);
7888 irq = ret;
7889 if (ret < 0)
7890- atomic_inc(&irq_err_count);
7891+ atomic_inc_unchecked(&irq_err_count);
7892 else
7893 irq_dispatch(irq);
7894 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7895diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7896index 967d144..db12197 100644
7897--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7898+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7899@@ -11,12 +11,14 @@
7900 #ifndef _ASM_PROC_CACHE_H
7901 #define _ASM_PROC_CACHE_H
7902
7903+#include <linux/const.h>
7904+
7905 /* L1 cache */
7906
7907 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7908 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7909-#define L1_CACHE_BYTES 16 /* bytes per entry */
7910 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7911+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7912 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7913
7914 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7915diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7916index bcb5df2..84fabd2 100644
7917--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7918+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7919@@ -16,13 +16,15 @@
7920 #ifndef _ASM_PROC_CACHE_H
7921 #define _ASM_PROC_CACHE_H
7922
7923+#include <linux/const.h>
7924+
7925 /*
7926 * L1 cache
7927 */
7928 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7929 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7930-#define L1_CACHE_BYTES 32 /* bytes per entry */
7931 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7932+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7933 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7934
7935 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7936diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7937index 4ce7a01..449202a 100644
7938--- a/arch/openrisc/include/asm/cache.h
7939+++ b/arch/openrisc/include/asm/cache.h
7940@@ -19,11 +19,13 @@
7941 #ifndef __ASM_OPENRISC_CACHE_H
7942 #define __ASM_OPENRISC_CACHE_H
7943
7944+#include <linux/const.h>
7945+
7946 /* FIXME: How can we replace these with values from the CPU...
7947 * they shouldn't be hard-coded!
7948 */
7949
7950-#define L1_CACHE_BYTES 16
7951 #define L1_CACHE_SHIFT 4
7952+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7953
7954 #endif /* __ASM_OPENRISC_CACHE_H */
7955diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7956index 0be2db2..1b0f26d 100644
7957--- a/arch/parisc/include/asm/atomic.h
7958+++ b/arch/parisc/include/asm/atomic.h
7959@@ -248,6 +248,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7960 return dec;
7961 }
7962
7963+#define atomic64_read_unchecked(v) atomic64_read(v)
7964+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7965+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7966+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7967+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7968+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7969+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7970+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7971+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7972+
7973 #endif /* !CONFIG_64BIT */
7974
7975
7976diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7977index 47f11c7..3420df2 100644
7978--- a/arch/parisc/include/asm/cache.h
7979+++ b/arch/parisc/include/asm/cache.h
7980@@ -5,6 +5,7 @@
7981 #ifndef __ARCH_PARISC_CACHE_H
7982 #define __ARCH_PARISC_CACHE_H
7983
7984+#include <linux/const.h>
7985
7986 /*
7987 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7988@@ -15,13 +16,13 @@
7989 * just ruin performance.
7990 */
7991 #ifdef CONFIG_PA20
7992-#define L1_CACHE_BYTES 64
7993 #define L1_CACHE_SHIFT 6
7994 #else
7995-#define L1_CACHE_BYTES 32
7996 #define L1_CACHE_SHIFT 5
7997 #endif
7998
7999+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8000+
8001 #ifndef __ASSEMBLY__
8002
8003 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8004diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
8005index 3391d06..c23a2cc 100644
8006--- a/arch/parisc/include/asm/elf.h
8007+++ b/arch/parisc/include/asm/elf.h
8008@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
8009
8010 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
8011
8012+#ifdef CONFIG_PAX_ASLR
8013+#define PAX_ELF_ET_DYN_BASE 0x10000UL
8014+
8015+#define PAX_DELTA_MMAP_LEN 16
8016+#define PAX_DELTA_STACK_LEN 16
8017+#endif
8018+
8019 /* This yields a mask that user programs can use to figure out what
8020 instruction set this CPU supports. This could be done in user space,
8021 but it's not easy, and we've already done it here. */
8022diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
8023index f213f5b..0af3e8e 100644
8024--- a/arch/parisc/include/asm/pgalloc.h
8025+++ b/arch/parisc/include/asm/pgalloc.h
8026@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
8027 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
8028 }
8029
8030+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
8031+{
8032+ pgd_populate(mm, pgd, pmd);
8033+}
8034+
8035 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
8036 {
8037 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
8038@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
8039 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
8040 #define pmd_free(mm, x) do { } while (0)
8041 #define pgd_populate(mm, pmd, pte) BUG()
8042+#define pgd_populate_kernel(mm, pmd, pte) BUG()
8043
8044 #endif
8045
8046diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
8047index 22b89d1..ce34230 100644
8048--- a/arch/parisc/include/asm/pgtable.h
8049+++ b/arch/parisc/include/asm/pgtable.h
8050@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
8051 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
8052 #define PAGE_COPY PAGE_EXECREAD
8053 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
8054+
8055+#ifdef CONFIG_PAX_PAGEEXEC
8056+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
8057+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
8058+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
8059+#else
8060+# define PAGE_SHARED_NOEXEC PAGE_SHARED
8061+# define PAGE_COPY_NOEXEC PAGE_COPY
8062+# define PAGE_READONLY_NOEXEC PAGE_READONLY
8063+#endif
8064+
8065 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
8066 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
8067 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
8068diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
8069index 4006964..fcb3cc2 100644
8070--- a/arch/parisc/include/asm/uaccess.h
8071+++ b/arch/parisc/include/asm/uaccess.h
8072@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
8073 const void __user *from,
8074 unsigned long n)
8075 {
8076- int sz = __compiletime_object_size(to);
8077+ size_t sz = __compiletime_object_size(to);
8078 int ret = -EFAULT;
8079
8080- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
8081+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
8082 ret = __copy_from_user(to, from, n);
8083 else
8084 copy_from_user_overflow();
8085diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
8086index 50dfafc..b9fc230 100644
8087--- a/arch/parisc/kernel/module.c
8088+++ b/arch/parisc/kernel/module.c
8089@@ -98,16 +98,38 @@
8090
8091 /* three functions to determine where in the module core
8092 * or init pieces the location is */
8093+static inline int in_init_rx(struct module *me, void *loc)
8094+{
8095+ return (loc >= me->module_init_rx &&
8096+ loc < (me->module_init_rx + me->init_size_rx));
8097+}
8098+
8099+static inline int in_init_rw(struct module *me, void *loc)
8100+{
8101+ return (loc >= me->module_init_rw &&
8102+ loc < (me->module_init_rw + me->init_size_rw));
8103+}
8104+
8105 static inline int in_init(struct module *me, void *loc)
8106 {
8107- return (loc >= me->module_init &&
8108- loc <= (me->module_init + me->init_size));
8109+ return in_init_rx(me, loc) || in_init_rw(me, loc);
8110+}
8111+
8112+static inline int in_core_rx(struct module *me, void *loc)
8113+{
8114+ return (loc >= me->module_core_rx &&
8115+ loc < (me->module_core_rx + me->core_size_rx));
8116+}
8117+
8118+static inline int in_core_rw(struct module *me, void *loc)
8119+{
8120+ return (loc >= me->module_core_rw &&
8121+ loc < (me->module_core_rw + me->core_size_rw));
8122 }
8123
8124 static inline int in_core(struct module *me, void *loc)
8125 {
8126- return (loc >= me->module_core &&
8127- loc <= (me->module_core + me->core_size));
8128+ return in_core_rx(me, loc) || in_core_rw(me, loc);
8129 }
8130
8131 static inline int in_local(struct module *me, void *loc)
8132@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
8133 }
8134
8135 /* align things a bit */
8136- me->core_size = ALIGN(me->core_size, 16);
8137- me->arch.got_offset = me->core_size;
8138- me->core_size += gots * sizeof(struct got_entry);
8139+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
8140+ me->arch.got_offset = me->core_size_rw;
8141+ me->core_size_rw += gots * sizeof(struct got_entry);
8142
8143- me->core_size = ALIGN(me->core_size, 16);
8144- me->arch.fdesc_offset = me->core_size;
8145- me->core_size += fdescs * sizeof(Elf_Fdesc);
8146+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
8147+ me->arch.fdesc_offset = me->core_size_rw;
8148+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
8149
8150 me->arch.got_max = gots;
8151 me->arch.fdesc_max = fdescs;
8152@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
8153
8154 BUG_ON(value == 0);
8155
8156- got = me->module_core + me->arch.got_offset;
8157+ got = me->module_core_rw + me->arch.got_offset;
8158 for (i = 0; got[i].addr; i++)
8159 if (got[i].addr == value)
8160 goto out;
8161@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
8162 #ifdef CONFIG_64BIT
8163 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
8164 {
8165- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
8166+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
8167
8168 if (!value) {
8169 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
8170@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
8171
8172 /* Create new one */
8173 fdesc->addr = value;
8174- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
8175+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
8176 return (Elf_Addr)fdesc;
8177 }
8178 #endif /* CONFIG_64BIT */
8179@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
8180
8181 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
8182 end = table + sechdrs[me->arch.unwind_section].sh_size;
8183- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
8184+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
8185
8186 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
8187 me->arch.unwind_section, table, end, gp);
8188diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
8189index e1ffea2..46ed66e 100644
8190--- a/arch/parisc/kernel/sys_parisc.c
8191+++ b/arch/parisc/kernel/sys_parisc.c
8192@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8193 unsigned long task_size = TASK_SIZE;
8194 int do_color_align, last_mmap;
8195 struct vm_unmapped_area_info info;
8196+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
8197
8198 if (len > task_size)
8199 return -ENOMEM;
8200@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8201 goto found_addr;
8202 }
8203
8204+#ifdef CONFIG_PAX_RANDMMAP
8205+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8206+#endif
8207+
8208 if (addr) {
8209 if (do_color_align && last_mmap)
8210 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
8211@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8212 info.high_limit = mmap_upper_limit();
8213 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
8214 info.align_offset = shared_align_offset(last_mmap, pgoff);
8215+ info.threadstack_offset = offset;
8216 addr = vm_unmapped_area(&info);
8217
8218 found_addr:
8219@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8220 unsigned long addr = addr0;
8221 int do_color_align, last_mmap;
8222 struct vm_unmapped_area_info info;
8223+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
8224
8225 #ifdef CONFIG_64BIT
8226 /* This should only ever run for 32-bit processes. */
8227@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8228 }
8229
8230 /* requesting a specific address */
8231+#ifdef CONFIG_PAX_RANDMMAP
8232+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8233+#endif
8234+
8235 if (addr) {
8236 if (do_color_align && last_mmap)
8237 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
8238@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8239 info.high_limit = mm->mmap_base;
8240 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
8241 info.align_offset = shared_align_offset(last_mmap, pgoff);
8242+ info.threadstack_offset = offset;
8243 addr = vm_unmapped_area(&info);
8244 if (!(addr & ~PAGE_MASK))
8245 goto found_addr;
8246@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8247 mm->mmap_legacy_base = mmap_legacy_base();
8248 mm->mmap_base = mmap_upper_limit();
8249
8250+#ifdef CONFIG_PAX_RANDMMAP
8251+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
8252+ mm->mmap_legacy_base += mm->delta_mmap;
8253+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8254+ }
8255+#endif
8256+
8257 if (mmap_is_legacy()) {
8258 mm->mmap_base = mm->mmap_legacy_base;
8259 mm->get_unmapped_area = arch_get_unmapped_area;
8260diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
8261index 47ee620..1107387 100644
8262--- a/arch/parisc/kernel/traps.c
8263+++ b/arch/parisc/kernel/traps.c
8264@@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
8265
8266 down_read(&current->mm->mmap_sem);
8267 vma = find_vma(current->mm,regs->iaoq[0]);
8268- if (vma && (regs->iaoq[0] >= vma->vm_start)
8269- && (vma->vm_flags & VM_EXEC)) {
8270-
8271+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
8272 fault_address = regs->iaoq[0];
8273 fault_space = regs->iasq[0];
8274
8275diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
8276index 3ca9c11..d163ef7 100644
8277--- a/arch/parisc/mm/fault.c
8278+++ b/arch/parisc/mm/fault.c
8279@@ -15,6 +15,7 @@
8280 #include <linux/sched.h>
8281 #include <linux/interrupt.h>
8282 #include <linux/module.h>
8283+#include <linux/unistd.h>
8284
8285 #include <asm/uaccess.h>
8286 #include <asm/traps.h>
8287@@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
8288 static unsigned long
8289 parisc_acctyp(unsigned long code, unsigned int inst)
8290 {
8291- if (code == 6 || code == 16)
8292+ if (code == 6 || code == 7 || code == 16)
8293 return VM_EXEC;
8294
8295 switch (inst & 0xf0000000) {
8296@@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
8297 }
8298 #endif
8299
8300+#ifdef CONFIG_PAX_PAGEEXEC
8301+/*
8302+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
8303+ *
8304+ * returns 1 when task should be killed
8305+ * 2 when rt_sigreturn trampoline was detected
8306+ * 3 when unpatched PLT trampoline was detected
8307+ */
8308+static int pax_handle_fetch_fault(struct pt_regs *regs)
8309+{
8310+
8311+#ifdef CONFIG_PAX_EMUPLT
8312+ int err;
8313+
8314+ do { /* PaX: unpatched PLT emulation */
8315+ unsigned int bl, depwi;
8316+
8317+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
8318+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
8319+
8320+ if (err)
8321+ break;
8322+
8323+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
8324+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
8325+
8326+ err = get_user(ldw, (unsigned int *)addr);
8327+ err |= get_user(bv, (unsigned int *)(addr+4));
8328+ err |= get_user(ldw2, (unsigned int *)(addr+8));
8329+
8330+ if (err)
8331+ break;
8332+
8333+ if (ldw == 0x0E801096U &&
8334+ bv == 0xEAC0C000U &&
8335+ ldw2 == 0x0E881095U)
8336+ {
8337+ unsigned int resolver, map;
8338+
8339+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
8340+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
8341+ if (err)
8342+ break;
8343+
8344+ regs->gr[20] = instruction_pointer(regs)+8;
8345+ regs->gr[21] = map;
8346+ regs->gr[22] = resolver;
8347+ regs->iaoq[0] = resolver | 3UL;
8348+ regs->iaoq[1] = regs->iaoq[0] + 4;
8349+ return 3;
8350+ }
8351+ }
8352+ } while (0);
8353+#endif
8354+
8355+#ifdef CONFIG_PAX_EMUTRAMP
8356+
8357+#ifndef CONFIG_PAX_EMUSIGRT
8358+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
8359+ return 1;
8360+#endif
8361+
8362+ do { /* PaX: rt_sigreturn emulation */
8363+ unsigned int ldi1, ldi2, bel, nop;
8364+
8365+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
8366+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
8367+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
8368+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
8369+
8370+ if (err)
8371+ break;
8372+
8373+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
8374+ ldi2 == 0x3414015AU &&
8375+ bel == 0xE4008200U &&
8376+ nop == 0x08000240U)
8377+ {
8378+ regs->gr[25] = (ldi1 & 2) >> 1;
8379+ regs->gr[20] = __NR_rt_sigreturn;
8380+ regs->gr[31] = regs->iaoq[1] + 16;
8381+ regs->sr[0] = regs->iasq[1];
8382+ regs->iaoq[0] = 0x100UL;
8383+ regs->iaoq[1] = regs->iaoq[0] + 4;
8384+ regs->iasq[0] = regs->sr[2];
8385+ regs->iasq[1] = regs->sr[2];
8386+ return 2;
8387+ }
8388+ } while (0);
8389+#endif
8390+
8391+ return 1;
8392+}
8393+
8394+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8395+{
8396+ unsigned long i;
8397+
8398+ printk(KERN_ERR "PAX: bytes at PC: ");
8399+ for (i = 0; i < 5; i++) {
8400+ unsigned int c;
8401+ if (get_user(c, (unsigned int *)pc+i))
8402+ printk(KERN_CONT "???????? ");
8403+ else
8404+ printk(KERN_CONT "%08x ", c);
8405+ }
8406+ printk("\n");
8407+}
8408+#endif
8409+
8410 int fixup_exception(struct pt_regs *regs)
8411 {
8412 const struct exception_table_entry *fix;
8413@@ -234,8 +345,33 @@ retry:
8414
8415 good_area:
8416
8417- if ((vma->vm_flags & acc_type) != acc_type)
8418+ if ((vma->vm_flags & acc_type) != acc_type) {
8419+
8420+#ifdef CONFIG_PAX_PAGEEXEC
8421+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
8422+ (address & ~3UL) == instruction_pointer(regs))
8423+ {
8424+ up_read(&mm->mmap_sem);
8425+ switch (pax_handle_fetch_fault(regs)) {
8426+
8427+#ifdef CONFIG_PAX_EMUPLT
8428+ case 3:
8429+ return;
8430+#endif
8431+
8432+#ifdef CONFIG_PAX_EMUTRAMP
8433+ case 2:
8434+ return;
8435+#endif
8436+
8437+ }
8438+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
8439+ do_group_exit(SIGKILL);
8440+ }
8441+#endif
8442+
8443 goto bad_area;
8444+ }
8445
8446 /*
8447 * If for any reason at all we couldn't handle the fault, make
8448diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
8449index 80b94b0..a3274fb 100644
8450--- a/arch/powerpc/Kconfig
8451+++ b/arch/powerpc/Kconfig
8452@@ -398,6 +398,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
8453 config KEXEC
8454 bool "kexec system call"
8455 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8456+ depends on !GRKERNSEC_KMEM
8457 help
8458 kexec is a system call that implements the ability to shutdown your
8459 current kernel, and to start another kernel. It is like a reboot
8460diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8461index 28992d0..c797b20 100644
8462--- a/arch/powerpc/include/asm/atomic.h
8463+++ b/arch/powerpc/include/asm/atomic.h
8464@@ -519,6 +519,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
8465 return t1;
8466 }
8467
8468+#define atomic64_read_unchecked(v) atomic64_read(v)
8469+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8470+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8471+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8472+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8473+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8474+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8475+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8476+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8477+
8478 #endif /* __powerpc64__ */
8479
8480 #endif /* __KERNEL__ */
8481diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8482index bab79a1..4a3eabc 100644
8483--- a/arch/powerpc/include/asm/barrier.h
8484+++ b/arch/powerpc/include/asm/barrier.h
8485@@ -73,7 +73,7 @@
8486 do { \
8487 compiletime_assert_atomic_type(*p); \
8488 __lwsync(); \
8489- ACCESS_ONCE(*p) = (v); \
8490+ ACCESS_ONCE_RW(*p) = (v); \
8491 } while (0)
8492
8493 #define smp_load_acquire(p) \
8494diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8495index ed0afc1..0332825 100644
8496--- a/arch/powerpc/include/asm/cache.h
8497+++ b/arch/powerpc/include/asm/cache.h
8498@@ -3,6 +3,7 @@
8499
8500 #ifdef __KERNEL__
8501
8502+#include <linux/const.h>
8503
8504 /* bytes per L1 cache line */
8505 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8506@@ -22,7 +23,7 @@
8507 #define L1_CACHE_SHIFT 7
8508 #endif
8509
8510-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8511+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8512
8513 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8514
8515diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8516index 888d8f3..66f581c 100644
8517--- a/arch/powerpc/include/asm/elf.h
8518+++ b/arch/powerpc/include/asm/elf.h
8519@@ -28,8 +28,19 @@
8520 the loader. We need to make sure that it is out of the way of the program
8521 that it will "exec", and that there is sufficient room for the brk. */
8522
8523-extern unsigned long randomize_et_dyn(unsigned long base);
8524-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8525+#define ELF_ET_DYN_BASE (0x20000000)
8526+
8527+#ifdef CONFIG_PAX_ASLR
8528+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8529+
8530+#ifdef __powerpc64__
8531+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8532+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8533+#else
8534+#define PAX_DELTA_MMAP_LEN 15
8535+#define PAX_DELTA_STACK_LEN 15
8536+#endif
8537+#endif
8538
8539 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8540
8541@@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8542 (0x7ff >> (PAGE_SHIFT - 12)) : \
8543 (0x3ffff >> (PAGE_SHIFT - 12)))
8544
8545-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8546-#define arch_randomize_brk arch_randomize_brk
8547-
8548-
8549 #ifdef CONFIG_SPU_BASE
8550 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8551 #define NT_SPU 1
8552diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8553index 8196e9c..d83a9f3 100644
8554--- a/arch/powerpc/include/asm/exec.h
8555+++ b/arch/powerpc/include/asm/exec.h
8556@@ -4,6 +4,6 @@
8557 #ifndef _ASM_POWERPC_EXEC_H
8558 #define _ASM_POWERPC_EXEC_H
8559
8560-extern unsigned long arch_align_stack(unsigned long sp);
8561+#define arch_align_stack(x) ((x) & ~0xfUL)
8562
8563 #endif /* _ASM_POWERPC_EXEC_H */
8564diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8565index 5acabbd..7ea14fa 100644
8566--- a/arch/powerpc/include/asm/kmap_types.h
8567+++ b/arch/powerpc/include/asm/kmap_types.h
8568@@ -10,7 +10,7 @@
8569 * 2 of the License, or (at your option) any later version.
8570 */
8571
8572-#define KM_TYPE_NR 16
8573+#define KM_TYPE_NR 17
8574
8575 #endif /* __KERNEL__ */
8576 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8577diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8578index b8da913..60b608a 100644
8579--- a/arch/powerpc/include/asm/local.h
8580+++ b/arch/powerpc/include/asm/local.h
8581@@ -9,15 +9,26 @@ typedef struct
8582 atomic_long_t a;
8583 } local_t;
8584
8585+typedef struct
8586+{
8587+ atomic_long_unchecked_t a;
8588+} local_unchecked_t;
8589+
8590 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8591
8592 #define local_read(l) atomic_long_read(&(l)->a)
8593+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8594 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8595+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8596
8597 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8598+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8599 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8600+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8601 #define local_inc(l) atomic_long_inc(&(l)->a)
8602+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8603 #define local_dec(l) atomic_long_dec(&(l)->a)
8604+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8605
8606 static __inline__ long local_add_return(long a, local_t *l)
8607 {
8608@@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8609
8610 return t;
8611 }
8612+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8613
8614 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8615
8616@@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8617
8618 return t;
8619 }
8620+#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8621
8622 static __inline__ long local_inc_return(local_t *l)
8623 {
8624@@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8625
8626 #define local_cmpxchg(l, o, n) \
8627 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8628+#define local_cmpxchg_unchecked(l, o, n) \
8629+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8630 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8631
8632 /**
8633diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8634index 8565c25..2865190 100644
8635--- a/arch/powerpc/include/asm/mman.h
8636+++ b/arch/powerpc/include/asm/mman.h
8637@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8638 }
8639 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8640
8641-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8642+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8643 {
8644 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8645 }
8646diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8647index 32e4e21..62afb12 100644
8648--- a/arch/powerpc/include/asm/page.h
8649+++ b/arch/powerpc/include/asm/page.h
8650@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8651 * and needs to be executable. This means the whole heap ends
8652 * up being executable.
8653 */
8654-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8655- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8656+#define VM_DATA_DEFAULT_FLAGS32 \
8657+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8658+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8659
8660 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8661 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8662@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8663 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8664 #endif
8665
8666+#define ktla_ktva(addr) (addr)
8667+#define ktva_ktla(addr) (addr)
8668+
8669 #ifndef CONFIG_PPC_BOOK3S_64
8670 /*
8671 * Use the top bit of the higher-level page table entries to indicate whether
8672diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8673index 88693ce..ac6f9ab 100644
8674--- a/arch/powerpc/include/asm/page_64.h
8675+++ b/arch/powerpc/include/asm/page_64.h
8676@@ -153,15 +153,18 @@ do { \
8677 * stack by default, so in the absence of a PT_GNU_STACK program header
8678 * we turn execute permission off.
8679 */
8680-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8681- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8682+#define VM_STACK_DEFAULT_FLAGS32 \
8683+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8684+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8685
8686 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8687 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8688
8689+#ifndef CONFIG_PAX_PAGEEXEC
8690 #define VM_STACK_DEFAULT_FLAGS \
8691 (is_32bit_task() ? \
8692 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8693+#endif
8694
8695 #include <asm-generic/getorder.h>
8696
8697diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8698index 4b0be20..c15a27d 100644
8699--- a/arch/powerpc/include/asm/pgalloc-64.h
8700+++ b/arch/powerpc/include/asm/pgalloc-64.h
8701@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8702 #ifndef CONFIG_PPC_64K_PAGES
8703
8704 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8705+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8706
8707 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8708 {
8709@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8710 pud_set(pud, (unsigned long)pmd);
8711 }
8712
8713+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8714+{
8715+ pud_populate(mm, pud, pmd);
8716+}
8717+
8718 #define pmd_populate(mm, pmd, pte_page) \
8719 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8720 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8721@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8722 #endif
8723
8724 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8725+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8726
8727 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8728 pte_t *pte)
8729diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8730index d98c1ec..9f61569 100644
8731--- a/arch/powerpc/include/asm/pgtable.h
8732+++ b/arch/powerpc/include/asm/pgtable.h
8733@@ -2,6 +2,7 @@
8734 #define _ASM_POWERPC_PGTABLE_H
8735 #ifdef __KERNEL__
8736
8737+#include <linux/const.h>
8738 #ifndef __ASSEMBLY__
8739 #include <linux/mmdebug.h>
8740 #include <asm/processor.h> /* For TASK_SIZE */
8741diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8742index 4aad413..85d86bf 100644
8743--- a/arch/powerpc/include/asm/pte-hash32.h
8744+++ b/arch/powerpc/include/asm/pte-hash32.h
8745@@ -21,6 +21,7 @@
8746 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8747 #define _PAGE_USER 0x004 /* usermode access allowed */
8748 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8749+#define _PAGE_EXEC _PAGE_GUARDED
8750 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8751 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8752 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8753diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8754index bffd89d..a6641ed 100644
8755--- a/arch/powerpc/include/asm/reg.h
8756+++ b/arch/powerpc/include/asm/reg.h
8757@@ -251,6 +251,7 @@
8758 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8759 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8760 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8761+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8762 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8763 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8764 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8765diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8766index 5a6614a..d89995d1 100644
8767--- a/arch/powerpc/include/asm/smp.h
8768+++ b/arch/powerpc/include/asm/smp.h
8769@@ -51,7 +51,7 @@ struct smp_ops_t {
8770 int (*cpu_disable)(void);
8771 void (*cpu_die)(unsigned int nr);
8772 int (*cpu_bootable)(unsigned int nr);
8773-};
8774+} __no_const;
8775
8776 extern void smp_send_debugger_break(void);
8777 extern void start_secondary_resume(void);
8778diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8779index b034ecd..af7e31f 100644
8780--- a/arch/powerpc/include/asm/thread_info.h
8781+++ b/arch/powerpc/include/asm/thread_info.h
8782@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8783 #if defined(CONFIG_PPC64)
8784 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8785 #endif
8786+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8787+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8788
8789 /* as above, but as bit values */
8790 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8791@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8792 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8793 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8794 #define _TIF_NOHZ (1<<TIF_NOHZ)
8795+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8796 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8797 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8798- _TIF_NOHZ)
8799+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8800
8801 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8802 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8803diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8804index 9485b43..3bd3c16 100644
8805--- a/arch/powerpc/include/asm/uaccess.h
8806+++ b/arch/powerpc/include/asm/uaccess.h
8807@@ -58,6 +58,7 @@
8808
8809 #endif
8810
8811+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8812 #define access_ok(type, addr, size) \
8813 (__chk_user_ptr(addr), \
8814 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8815@@ -318,52 +319,6 @@ do { \
8816 extern unsigned long __copy_tofrom_user(void __user *to,
8817 const void __user *from, unsigned long size);
8818
8819-#ifndef __powerpc64__
8820-
8821-static inline unsigned long copy_from_user(void *to,
8822- const void __user *from, unsigned long n)
8823-{
8824- unsigned long over;
8825-
8826- if (access_ok(VERIFY_READ, from, n))
8827- return __copy_tofrom_user((__force void __user *)to, from, n);
8828- if ((unsigned long)from < TASK_SIZE) {
8829- over = (unsigned long)from + n - TASK_SIZE;
8830- return __copy_tofrom_user((__force void __user *)to, from,
8831- n - over) + over;
8832- }
8833- return n;
8834-}
8835-
8836-static inline unsigned long copy_to_user(void __user *to,
8837- const void *from, unsigned long n)
8838-{
8839- unsigned long over;
8840-
8841- if (access_ok(VERIFY_WRITE, to, n))
8842- return __copy_tofrom_user(to, (__force void __user *)from, n);
8843- if ((unsigned long)to < TASK_SIZE) {
8844- over = (unsigned long)to + n - TASK_SIZE;
8845- return __copy_tofrom_user(to, (__force void __user *)from,
8846- n - over) + over;
8847- }
8848- return n;
8849-}
8850-
8851-#else /* __powerpc64__ */
8852-
8853-#define __copy_in_user(to, from, size) \
8854- __copy_tofrom_user((to), (from), (size))
8855-
8856-extern unsigned long copy_from_user(void *to, const void __user *from,
8857- unsigned long n);
8858-extern unsigned long copy_to_user(void __user *to, const void *from,
8859- unsigned long n);
8860-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8861- unsigned long n);
8862-
8863-#endif /* __powerpc64__ */
8864-
8865 static inline unsigned long __copy_from_user_inatomic(void *to,
8866 const void __user *from, unsigned long n)
8867 {
8868@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8869 if (ret == 0)
8870 return 0;
8871 }
8872+
8873+ if (!__builtin_constant_p(n))
8874+ check_object_size(to, n, false);
8875+
8876 return __copy_tofrom_user((__force void __user *)to, from, n);
8877 }
8878
8879@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8880 if (ret == 0)
8881 return 0;
8882 }
8883+
8884+ if (!__builtin_constant_p(n))
8885+ check_object_size(from, n, true);
8886+
8887 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8888 }
8889
8890@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8891 return __copy_to_user_inatomic(to, from, size);
8892 }
8893
8894+#ifndef __powerpc64__
8895+
8896+static inline unsigned long __must_check copy_from_user(void *to,
8897+ const void __user *from, unsigned long n)
8898+{
8899+ unsigned long over;
8900+
8901+ if ((long)n < 0)
8902+ return n;
8903+
8904+ if (access_ok(VERIFY_READ, from, n)) {
8905+ if (!__builtin_constant_p(n))
8906+ check_object_size(to, n, false);
8907+ return __copy_tofrom_user((__force void __user *)to, from, n);
8908+ }
8909+ if ((unsigned long)from < TASK_SIZE) {
8910+ over = (unsigned long)from + n - TASK_SIZE;
8911+ if (!__builtin_constant_p(n - over))
8912+ check_object_size(to, n - over, false);
8913+ return __copy_tofrom_user((__force void __user *)to, from,
8914+ n - over) + over;
8915+ }
8916+ return n;
8917+}
8918+
8919+static inline unsigned long __must_check copy_to_user(void __user *to,
8920+ const void *from, unsigned long n)
8921+{
8922+ unsigned long over;
8923+
8924+ if ((long)n < 0)
8925+ return n;
8926+
8927+ if (access_ok(VERIFY_WRITE, to, n)) {
8928+ if (!__builtin_constant_p(n))
8929+ check_object_size(from, n, true);
8930+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8931+ }
8932+ if ((unsigned long)to < TASK_SIZE) {
8933+ over = (unsigned long)to + n - TASK_SIZE;
8934+ if (!__builtin_constant_p(n))
8935+ check_object_size(from, n - over, true);
8936+ return __copy_tofrom_user(to, (__force void __user *)from,
8937+ n - over) + over;
8938+ }
8939+ return n;
8940+}
8941+
8942+#else /* __powerpc64__ */
8943+
8944+#define __copy_in_user(to, from, size) \
8945+ __copy_tofrom_user((to), (from), (size))
8946+
8947+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8948+{
8949+ if ((long)n < 0 || n > INT_MAX)
8950+ return n;
8951+
8952+ if (!__builtin_constant_p(n))
8953+ check_object_size(to, n, false);
8954+
8955+ if (likely(access_ok(VERIFY_READ, from, n)))
8956+ n = __copy_from_user(to, from, n);
8957+ else
8958+ memset(to, 0, n);
8959+ return n;
8960+}
8961+
8962+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8963+{
8964+ if ((long)n < 0 || n > INT_MAX)
8965+ return n;
8966+
8967+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8968+ if (!__builtin_constant_p(n))
8969+ check_object_size(from, n, true);
8970+ n = __copy_to_user(to, from, n);
8971+ }
8972+ return n;
8973+}
8974+
8975+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8976+ unsigned long n);
8977+
8978+#endif /* __powerpc64__ */
8979+
8980 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8981
8982 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8983diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8984index 670c312..60c2b52 100644
8985--- a/arch/powerpc/kernel/Makefile
8986+++ b/arch/powerpc/kernel/Makefile
8987@@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8988 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8989 endif
8990
8991+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8992+
8993 obj-y := cputable.o ptrace.o syscalls.o \
8994 irq.o align.o signal_32.o pmc.o vdso.o \
8995 process.o systbl.o idle.o \
8996diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8997index bb9cac6..5181202 100644
8998--- a/arch/powerpc/kernel/exceptions-64e.S
8999+++ b/arch/powerpc/kernel/exceptions-64e.S
9000@@ -1010,6 +1010,7 @@ storage_fault_common:
9001 std r14,_DAR(r1)
9002 std r15,_DSISR(r1)
9003 addi r3,r1,STACK_FRAME_OVERHEAD
9004+ bl save_nvgprs
9005 mr r4,r14
9006 mr r5,r15
9007 ld r14,PACA_EXGEN+EX_R14(r13)
9008@@ -1018,8 +1019,7 @@ storage_fault_common:
9009 cmpdi r3,0
9010 bne- 1f
9011 b ret_from_except_lite
9012-1: bl save_nvgprs
9013- mr r5,r3
9014+1: mr r5,r3
9015 addi r3,r1,STACK_FRAME_OVERHEAD
9016 ld r4,_DAR(r1)
9017 bl bad_page_fault
9018diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
9019index a7d36b1..53af150 100644
9020--- a/arch/powerpc/kernel/exceptions-64s.S
9021+++ b/arch/powerpc/kernel/exceptions-64s.S
9022@@ -1637,10 +1637,10 @@ handle_page_fault:
9023 11: ld r4,_DAR(r1)
9024 ld r5,_DSISR(r1)
9025 addi r3,r1,STACK_FRAME_OVERHEAD
9026+ bl save_nvgprs
9027 bl do_page_fault
9028 cmpdi r3,0
9029 beq+ 12f
9030- bl save_nvgprs
9031 mr r5,r3
9032 addi r3,r1,STACK_FRAME_OVERHEAD
9033 lwz r4,_DAR(r1)
9034diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
9035index 248ee7e..1eb60dd 100644
9036--- a/arch/powerpc/kernel/irq.c
9037+++ b/arch/powerpc/kernel/irq.c
9038@@ -447,6 +447,8 @@ void migrate_irqs(void)
9039 }
9040 #endif
9041
9042+extern void gr_handle_kernel_exploit(void);
9043+
9044 static inline void check_stack_overflow(void)
9045 {
9046 #ifdef CONFIG_DEBUG_STACKOVERFLOW
9047@@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
9048 printk("do_IRQ: stack overflow: %ld\n",
9049 sp - sizeof(struct thread_info));
9050 dump_stack();
9051+ gr_handle_kernel_exploit();
9052 }
9053 #endif
9054 }
9055diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
9056index 6cff040..74ac5d1b 100644
9057--- a/arch/powerpc/kernel/module_32.c
9058+++ b/arch/powerpc/kernel/module_32.c
9059@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
9060 me->arch.core_plt_section = i;
9061 }
9062 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
9063- printk("Module doesn't contain .plt or .init.plt sections.\n");
9064+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
9065 return -ENOEXEC;
9066 }
9067
9068@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
9069
9070 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
9071 /* Init, or core PLT? */
9072- if (location >= mod->module_core
9073- && location < mod->module_core + mod->core_size)
9074+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
9075+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
9076 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
9077- else
9078+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
9079+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
9080 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
9081+ else {
9082+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
9083+ return ~0UL;
9084+ }
9085
9086 /* Find this entry, or if that fails, the next avail. entry */
9087 while (entry->jump[0]) {
9088@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
9089 }
9090 #ifdef CONFIG_DYNAMIC_FTRACE
9091 module->arch.tramp =
9092- do_plt_call(module->module_core,
9093+ do_plt_call(module->module_core_rx,
9094 (unsigned long)ftrace_caller,
9095 sechdrs, module);
9096 #endif
9097diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
9098index be99774..9879c82 100644
9099--- a/arch/powerpc/kernel/process.c
9100+++ b/arch/powerpc/kernel/process.c
9101@@ -1039,8 +1039,8 @@ void show_regs(struct pt_regs * regs)
9102 * Lookup NIP late so we have the best change of getting the
9103 * above info out without failing
9104 */
9105- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
9106- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
9107+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
9108+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
9109 #endif
9110 show_stack(current, (unsigned long *) regs->gpr[1]);
9111 if (!user_mode(regs))
9112@@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9113 newsp = stack[0];
9114 ip = stack[STACK_FRAME_LR_SAVE];
9115 if (!firstframe || ip != lr) {
9116- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
9117+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
9118 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9119 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
9120- printk(" (%pS)",
9121+ printk(" (%pA)",
9122 (void *)current->ret_stack[curr_frame].ret);
9123 curr_frame--;
9124 }
9125@@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9126 struct pt_regs *regs = (struct pt_regs *)
9127 (sp + STACK_FRAME_OVERHEAD);
9128 lr = regs->link;
9129- printk("--- Exception: %lx at %pS\n LR = %pS\n",
9130+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
9131 regs->trap, (void *)regs->nip, (void *)lr);
9132 firstframe = 1;
9133 }
9134@@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
9135 mtspr(SPRN_CTRLT, ctrl);
9136 }
9137 #endif /* CONFIG_PPC64 */
9138-
9139-unsigned long arch_align_stack(unsigned long sp)
9140-{
9141- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9142- sp -= get_random_int() & ~PAGE_MASK;
9143- return sp & ~0xf;
9144-}
9145-
9146-static inline unsigned long brk_rnd(void)
9147-{
9148- unsigned long rnd = 0;
9149-
9150- /* 8MB for 32bit, 1GB for 64bit */
9151- if (is_32bit_task())
9152- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
9153- else
9154- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
9155-
9156- return rnd << PAGE_SHIFT;
9157-}
9158-
9159-unsigned long arch_randomize_brk(struct mm_struct *mm)
9160-{
9161- unsigned long base = mm->brk;
9162- unsigned long ret;
9163-
9164-#ifdef CONFIG_PPC_STD_MMU_64
9165- /*
9166- * If we are using 1TB segments and we are allowed to randomise
9167- * the heap, we can put it above 1TB so it is backed by a 1TB
9168- * segment. Otherwise the heap will be in the bottom 1TB
9169- * which always uses 256MB segments and this may result in a
9170- * performance penalty.
9171- */
9172- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9173- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9174-#endif
9175-
9176- ret = PAGE_ALIGN(base + brk_rnd());
9177-
9178- if (ret < mm->brk)
9179- return mm->brk;
9180-
9181- return ret;
9182-}
9183-
9184-unsigned long randomize_et_dyn(unsigned long base)
9185-{
9186- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9187-
9188- if (ret < base)
9189- return base;
9190-
9191- return ret;
9192-}
9193diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9194index 2e3d2bf..35df241 100644
9195--- a/arch/powerpc/kernel/ptrace.c
9196+++ b/arch/powerpc/kernel/ptrace.c
9197@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9198 return ret;
9199 }
9200
9201+#ifdef CONFIG_GRKERNSEC_SETXID
9202+extern void gr_delayed_cred_worker(void);
9203+#endif
9204+
9205 /*
9206 * We must return the syscall number to actually look up in the table.
9207 * This can be -1L to skip running any syscall at all.
9208@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9209
9210 secure_computing_strict(regs->gpr[0]);
9211
9212+#ifdef CONFIG_GRKERNSEC_SETXID
9213+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9214+ gr_delayed_cred_worker();
9215+#endif
9216+
9217 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9218 tracehook_report_syscall_entry(regs))
9219 /*
9220@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9221 {
9222 int step;
9223
9224+#ifdef CONFIG_GRKERNSEC_SETXID
9225+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9226+ gr_delayed_cred_worker();
9227+#endif
9228+
9229 audit_syscall_exit(regs);
9230
9231 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9232diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9233index 1bc5a17..910d3f3 100644
9234--- a/arch/powerpc/kernel/signal_32.c
9235+++ b/arch/powerpc/kernel/signal_32.c
9236@@ -1012,7 +1012,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
9237 /* Save user registers on the stack */
9238 frame = &rt_sf->uc.uc_mcontext;
9239 addr = frame;
9240- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9241+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9242 sigret = 0;
9243 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9244 } else {
9245diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9246index 97c1e4b..f427f81 100644
9247--- a/arch/powerpc/kernel/signal_64.c
9248+++ b/arch/powerpc/kernel/signal_64.c
9249@@ -755,7 +755,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
9250 current->thread.fp_state.fpscr = 0;
9251
9252 /* Set up to return from userspace. */
9253- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9254+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9255 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9256 } else {
9257 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9258diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9259index 239f1cd..5359f76 100644
9260--- a/arch/powerpc/kernel/traps.c
9261+++ b/arch/powerpc/kernel/traps.c
9262@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9263 return flags;
9264 }
9265
9266+extern void gr_handle_kernel_exploit(void);
9267+
9268 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9269 int signr)
9270 {
9271@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9272 panic("Fatal exception in interrupt");
9273 if (panic_on_oops)
9274 panic("Fatal exception");
9275+
9276+ gr_handle_kernel_exploit();
9277+
9278 do_exit(signr);
9279 }
9280
9281diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9282index ce74c33..0803371 100644
9283--- a/arch/powerpc/kernel/vdso.c
9284+++ b/arch/powerpc/kernel/vdso.c
9285@@ -35,6 +35,7 @@
9286 #include <asm/vdso.h>
9287 #include <asm/vdso_datapage.h>
9288 #include <asm/setup.h>
9289+#include <asm/mman.h>
9290
9291 #undef DEBUG
9292
9293@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9294 vdso_base = VDSO32_MBASE;
9295 #endif
9296
9297- current->mm->context.vdso_base = 0;
9298+ current->mm->context.vdso_base = ~0UL;
9299
9300 /* vDSO has a problem and was disabled, just don't "enable" it for the
9301 * process
9302@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9303 vdso_base = get_unmapped_area(NULL, vdso_base,
9304 (vdso_pages << PAGE_SHIFT) +
9305 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9306- 0, 0);
9307+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
9308 if (IS_ERR_VALUE(vdso_base)) {
9309 rc = vdso_base;
9310 goto fail_mmapsem;
9311diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9312index 61c738a..b1092d6 100644
9313--- a/arch/powerpc/kvm/powerpc.c
9314+++ b/arch/powerpc/kvm/powerpc.c
9315@@ -1195,7 +1195,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9316 }
9317 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9318
9319-int kvm_arch_init(void *opaque)
9320+int kvm_arch_init(const void *opaque)
9321 {
9322 return 0;
9323 }
9324diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9325index 5eea6f3..5d10396 100644
9326--- a/arch/powerpc/lib/usercopy_64.c
9327+++ b/arch/powerpc/lib/usercopy_64.c
9328@@ -9,22 +9,6 @@
9329 #include <linux/module.h>
9330 #include <asm/uaccess.h>
9331
9332-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9333-{
9334- if (likely(access_ok(VERIFY_READ, from, n)))
9335- n = __copy_from_user(to, from, n);
9336- else
9337- memset(to, 0, n);
9338- return n;
9339-}
9340-
9341-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9342-{
9343- if (likely(access_ok(VERIFY_WRITE, to, n)))
9344- n = __copy_to_user(to, from, n);
9345- return n;
9346-}
9347-
9348 unsigned long copy_in_user(void __user *to, const void __user *from,
9349 unsigned long n)
9350 {
9351@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9352 return n;
9353 }
9354
9355-EXPORT_SYMBOL(copy_from_user);
9356-EXPORT_SYMBOL(copy_to_user);
9357 EXPORT_SYMBOL(copy_in_user);
9358
9359diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9360index 51ab9e7..7d3c78b 100644
9361--- a/arch/powerpc/mm/fault.c
9362+++ b/arch/powerpc/mm/fault.c
9363@@ -33,6 +33,10 @@
9364 #include <linux/magic.h>
9365 #include <linux/ratelimit.h>
9366 #include <linux/context_tracking.h>
9367+#include <linux/slab.h>
9368+#include <linux/pagemap.h>
9369+#include <linux/compiler.h>
9370+#include <linux/unistd.h>
9371
9372 #include <asm/firmware.h>
9373 #include <asm/page.h>
9374@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9375 }
9376 #endif
9377
9378+#ifdef CONFIG_PAX_PAGEEXEC
9379+/*
9380+ * PaX: decide what to do with offenders (regs->nip = fault address)
9381+ *
9382+ * returns 1 when task should be killed
9383+ */
9384+static int pax_handle_fetch_fault(struct pt_regs *regs)
9385+{
9386+ return 1;
9387+}
9388+
9389+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9390+{
9391+ unsigned long i;
9392+
9393+ printk(KERN_ERR "PAX: bytes at PC: ");
9394+ for (i = 0; i < 5; i++) {
9395+ unsigned int c;
9396+ if (get_user(c, (unsigned int __user *)pc+i))
9397+ printk(KERN_CONT "???????? ");
9398+ else
9399+ printk(KERN_CONT "%08x ", c);
9400+ }
9401+ printk("\n");
9402+}
9403+#endif
9404+
9405 /*
9406 * Check whether the instruction at regs->nip is a store using
9407 * an update addressing form which will update r1.
9408@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9409 * indicate errors in DSISR but can validly be set in SRR1.
9410 */
9411 if (trap == 0x400)
9412- error_code &= 0x48200000;
9413+ error_code &= 0x58200000;
9414 else
9415 is_write = error_code & DSISR_ISSTORE;
9416 #else
9417@@ -378,7 +409,7 @@ good_area:
9418 * "undefined". Of those that can be set, this is the only
9419 * one which seems bad.
9420 */
9421- if (error_code & 0x10000000)
9422+ if (error_code & DSISR_GUARDED)
9423 /* Guarded storage error. */
9424 goto bad_area;
9425 #endif /* CONFIG_8xx */
9426@@ -393,7 +424,7 @@ good_area:
9427 * processors use the same I/D cache coherency mechanism
9428 * as embedded.
9429 */
9430- if (error_code & DSISR_PROTFAULT)
9431+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9432 goto bad_area;
9433 #endif /* CONFIG_PPC_STD_MMU */
9434
9435@@ -483,6 +514,23 @@ bad_area:
9436 bad_area_nosemaphore:
9437 /* User mode accesses cause a SIGSEGV */
9438 if (user_mode(regs)) {
9439+
9440+#ifdef CONFIG_PAX_PAGEEXEC
9441+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9442+#ifdef CONFIG_PPC_STD_MMU
9443+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9444+#else
9445+ if (is_exec && regs->nip == address) {
9446+#endif
9447+ switch (pax_handle_fetch_fault(regs)) {
9448+ }
9449+
9450+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9451+ do_group_exit(SIGKILL);
9452+ }
9453+ }
9454+#endif
9455+
9456 _exception(SIGSEGV, regs, code, address);
9457 goto bail;
9458 }
9459diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9460index cb8bdbe..cde4bc7 100644
9461--- a/arch/powerpc/mm/mmap.c
9462+++ b/arch/powerpc/mm/mmap.c
9463@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9464 return sysctl_legacy_va_layout;
9465 }
9466
9467-static unsigned long mmap_rnd(void)
9468+static unsigned long mmap_rnd(struct mm_struct *mm)
9469 {
9470 unsigned long rnd = 0;
9471
9472+#ifdef CONFIG_PAX_RANDMMAP
9473+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9474+#endif
9475+
9476 if (current->flags & PF_RANDOMIZE) {
9477 /* 8MB for 32bit, 1GB for 64bit */
9478 if (is_32bit_task())
9479@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9480 return rnd << PAGE_SHIFT;
9481 }
9482
9483-static inline unsigned long mmap_base(void)
9484+static inline unsigned long mmap_base(struct mm_struct *mm)
9485 {
9486 unsigned long gap = rlimit(RLIMIT_STACK);
9487
9488@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9489 else if (gap > MAX_GAP)
9490 gap = MAX_GAP;
9491
9492- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9493+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9494 }
9495
9496 /*
9497@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9498 */
9499 if (mmap_is_legacy()) {
9500 mm->mmap_base = TASK_UNMAPPED_BASE;
9501+
9502+#ifdef CONFIG_PAX_RANDMMAP
9503+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9504+ mm->mmap_base += mm->delta_mmap;
9505+#endif
9506+
9507 mm->get_unmapped_area = arch_get_unmapped_area;
9508 } else {
9509- mm->mmap_base = mmap_base();
9510+ mm->mmap_base = mmap_base(mm);
9511+
9512+#ifdef CONFIG_PAX_RANDMMAP
9513+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9514+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9515+#endif
9516+
9517 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9518 }
9519 }
9520diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9521index b0c75cc..ef7fb93 100644
9522--- a/arch/powerpc/mm/slice.c
9523+++ b/arch/powerpc/mm/slice.c
9524@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9525 if ((mm->task_size - len) < addr)
9526 return 0;
9527 vma = find_vma(mm, addr);
9528- return (!vma || (addr + len) <= vma->vm_start);
9529+ return check_heap_stack_gap(vma, addr, len, 0);
9530 }
9531
9532 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9533@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9534 info.align_offset = 0;
9535
9536 addr = TASK_UNMAPPED_BASE;
9537+
9538+#ifdef CONFIG_PAX_RANDMMAP
9539+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9540+ addr += mm->delta_mmap;
9541+#endif
9542+
9543 while (addr < TASK_SIZE) {
9544 info.low_limit = addr;
9545 if (!slice_scan_available(addr, available, 1, &addr))
9546@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9547 if (fixed && addr > (mm->task_size - len))
9548 return -ENOMEM;
9549
9550+#ifdef CONFIG_PAX_RANDMMAP
9551+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9552+ addr = 0;
9553+#endif
9554+
9555 /* If hint, make sure it matches our alignment restrictions */
9556 if (!fixed && addr) {
9557 addr = _ALIGN_UP(addr, 1ul << pshift);
9558diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9559index 4278acf..67fd0e6 100644
9560--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9561+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9562@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9563 }
9564
9565 static struct pci_ops scc_pciex_pci_ops = {
9566- scc_pciex_read_config,
9567- scc_pciex_write_config,
9568+ .read = scc_pciex_read_config,
9569+ .write = scc_pciex_write_config,
9570 };
9571
9572 static void pciex_clear_intr_all(unsigned int __iomem *base)
9573diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9574index 9098692..3d54cd1 100644
9575--- a/arch/powerpc/platforms/cell/spufs/file.c
9576+++ b/arch/powerpc/platforms/cell/spufs/file.c
9577@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9578 return VM_FAULT_NOPAGE;
9579 }
9580
9581-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9582+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9583 unsigned long address,
9584- void *buf, int len, int write)
9585+ void *buf, size_t len, int write)
9586 {
9587 struct spu_context *ctx = vma->vm_file->private_data;
9588 unsigned long offset = address - vma->vm_start;
9589diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9590index fa934fe..c296056 100644
9591--- a/arch/s390/include/asm/atomic.h
9592+++ b/arch/s390/include/asm/atomic.h
9593@@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9594 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9595 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9596
9597+#define atomic64_read_unchecked(v) atomic64_read(v)
9598+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9599+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9600+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9601+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9602+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9603+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9604+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9605+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9606+
9607 #endif /* __ARCH_S390_ATOMIC__ */
9608diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9609index 19ff956..8d39cb1 100644
9610--- a/arch/s390/include/asm/barrier.h
9611+++ b/arch/s390/include/asm/barrier.h
9612@@ -37,7 +37,7 @@
9613 do { \
9614 compiletime_assert_atomic_type(*p); \
9615 barrier(); \
9616- ACCESS_ONCE(*p) = (v); \
9617+ ACCESS_ONCE_RW(*p) = (v); \
9618 } while (0)
9619
9620 #define smp_load_acquire(p) \
9621diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9622index 4d7ccac..d03d0ad 100644
9623--- a/arch/s390/include/asm/cache.h
9624+++ b/arch/s390/include/asm/cache.h
9625@@ -9,8 +9,10 @@
9626 #ifndef __ARCH_S390_CACHE_H
9627 #define __ARCH_S390_CACHE_H
9628
9629-#define L1_CACHE_BYTES 256
9630+#include <linux/const.h>
9631+
9632 #define L1_CACHE_SHIFT 8
9633+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9634 #define NET_SKB_PAD 32
9635
9636 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9637diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9638index 78f4f87..598ce39 100644
9639--- a/arch/s390/include/asm/elf.h
9640+++ b/arch/s390/include/asm/elf.h
9641@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9642 the loader. We need to make sure that it is out of the way of the program
9643 that it will "exec", and that there is sufficient room for the brk. */
9644
9645-extern unsigned long randomize_et_dyn(unsigned long base);
9646-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9647+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9648+
9649+#ifdef CONFIG_PAX_ASLR
9650+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9651+
9652+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9653+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9654+#endif
9655
9656 /* This yields a mask that user programs can use to figure out what
9657 instruction set this CPU supports. */
9658@@ -222,9 +228,6 @@ struct linux_binprm;
9659 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9660 int arch_setup_additional_pages(struct linux_binprm *, int);
9661
9662-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9663-#define arch_randomize_brk arch_randomize_brk
9664-
9665 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9666
9667 #endif
9668diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9669index c4a93d6..4d2a9b4 100644
9670--- a/arch/s390/include/asm/exec.h
9671+++ b/arch/s390/include/asm/exec.h
9672@@ -7,6 +7,6 @@
9673 #ifndef __ASM_EXEC_H
9674 #define __ASM_EXEC_H
9675
9676-extern unsigned long arch_align_stack(unsigned long sp);
9677+#define arch_align_stack(x) ((x) & ~0xfUL)
9678
9679 #endif /* __ASM_EXEC_H */
9680diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9681index cd4c68e..6764641 100644
9682--- a/arch/s390/include/asm/uaccess.h
9683+++ b/arch/s390/include/asm/uaccess.h
9684@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9685 __range_ok((unsigned long)(addr), (size)); \
9686 })
9687
9688+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9689 #define access_ok(type, addr, size) __access_ok(addr, size)
9690
9691 /*
9692@@ -275,6 +276,10 @@ static inline unsigned long __must_check
9693 copy_to_user(void __user *to, const void *from, unsigned long n)
9694 {
9695 might_fault();
9696+
9697+ if ((long)n < 0)
9698+ return n;
9699+
9700 return __copy_to_user(to, from, n);
9701 }
9702
9703@@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9704 static inline unsigned long __must_check
9705 copy_from_user(void *to, const void __user *from, unsigned long n)
9706 {
9707- unsigned int sz = __compiletime_object_size(to);
9708+ size_t sz = __compiletime_object_size(to);
9709
9710 might_fault();
9711- if (unlikely(sz != -1 && sz < n)) {
9712+
9713+ if ((long)n < 0)
9714+ return n;
9715+
9716+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9717 copy_from_user_overflow();
9718 return n;
9719 }
9720diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9721index b89b591..fd9609d 100644
9722--- a/arch/s390/kernel/module.c
9723+++ b/arch/s390/kernel/module.c
9724@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9725
9726 /* Increase core size by size of got & plt and set start
9727 offsets for got and plt. */
9728- me->core_size = ALIGN(me->core_size, 4);
9729- me->arch.got_offset = me->core_size;
9730- me->core_size += me->arch.got_size;
9731- me->arch.plt_offset = me->core_size;
9732- me->core_size += me->arch.plt_size;
9733+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9734+ me->arch.got_offset = me->core_size_rw;
9735+ me->core_size_rw += me->arch.got_size;
9736+ me->arch.plt_offset = me->core_size_rx;
9737+ me->core_size_rx += me->arch.plt_size;
9738 return 0;
9739 }
9740
9741@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9742 if (info->got_initialized == 0) {
9743 Elf_Addr *gotent;
9744
9745- gotent = me->module_core + me->arch.got_offset +
9746+ gotent = me->module_core_rw + me->arch.got_offset +
9747 info->got_offset;
9748 *gotent = val;
9749 info->got_initialized = 1;
9750@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9751 rc = apply_rela_bits(loc, val, 0, 64, 0);
9752 else if (r_type == R_390_GOTENT ||
9753 r_type == R_390_GOTPLTENT) {
9754- val += (Elf_Addr) me->module_core - loc;
9755+ val += (Elf_Addr) me->module_core_rw - loc;
9756 rc = apply_rela_bits(loc, val, 1, 32, 1);
9757 }
9758 break;
9759@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9760 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9761 if (info->plt_initialized == 0) {
9762 unsigned int *ip;
9763- ip = me->module_core + me->arch.plt_offset +
9764+ ip = me->module_core_rx + me->arch.plt_offset +
9765 info->plt_offset;
9766 #ifndef CONFIG_64BIT
9767 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9768@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9769 val - loc + 0xffffUL < 0x1ffffeUL) ||
9770 (r_type == R_390_PLT32DBL &&
9771 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9772- val = (Elf_Addr) me->module_core +
9773+ val = (Elf_Addr) me->module_core_rx +
9774 me->arch.plt_offset +
9775 info->plt_offset;
9776 val += rela->r_addend - loc;
9777@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9778 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9779 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9780 val = val + rela->r_addend -
9781- ((Elf_Addr) me->module_core + me->arch.got_offset);
9782+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9783 if (r_type == R_390_GOTOFF16)
9784 rc = apply_rela_bits(loc, val, 0, 16, 0);
9785 else if (r_type == R_390_GOTOFF32)
9786@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9787 break;
9788 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9789 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9790- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9791+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9792 rela->r_addend - loc;
9793 if (r_type == R_390_GOTPC)
9794 rc = apply_rela_bits(loc, val, 1, 32, 0);
9795diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9796index 93b9ca4..4ea1454 100644
9797--- a/arch/s390/kernel/process.c
9798+++ b/arch/s390/kernel/process.c
9799@@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9800 }
9801 return 0;
9802 }
9803-
9804-unsigned long arch_align_stack(unsigned long sp)
9805-{
9806- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9807- sp -= get_random_int() & ~PAGE_MASK;
9808- return sp & ~0xf;
9809-}
9810-
9811-static inline unsigned long brk_rnd(void)
9812-{
9813- /* 8MB for 32bit, 1GB for 64bit */
9814- if (is_32bit_task())
9815- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9816- else
9817- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9818-}
9819-
9820-unsigned long arch_randomize_brk(struct mm_struct *mm)
9821-{
9822- unsigned long ret;
9823-
9824- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9825- return (ret > mm->brk) ? ret : mm->brk;
9826-}
9827-
9828-unsigned long randomize_et_dyn(unsigned long base)
9829-{
9830- unsigned long ret;
9831-
9832- if (!(current->flags & PF_RANDOMIZE))
9833- return base;
9834- ret = PAGE_ALIGN(base + brk_rnd());
9835- return (ret > base) ? ret : base;
9836-}
9837diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9838index 9b436c2..54fbf0a 100644
9839--- a/arch/s390/mm/mmap.c
9840+++ b/arch/s390/mm/mmap.c
9841@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9842 */
9843 if (mmap_is_legacy()) {
9844 mm->mmap_base = mmap_base_legacy();
9845+
9846+#ifdef CONFIG_PAX_RANDMMAP
9847+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9848+ mm->mmap_base += mm->delta_mmap;
9849+#endif
9850+
9851 mm->get_unmapped_area = arch_get_unmapped_area;
9852 } else {
9853 mm->mmap_base = mmap_base();
9854+
9855+#ifdef CONFIG_PAX_RANDMMAP
9856+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9857+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9858+#endif
9859+
9860 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9861 }
9862 }
9863@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9864 */
9865 if (mmap_is_legacy()) {
9866 mm->mmap_base = mmap_base_legacy();
9867+
9868+#ifdef CONFIG_PAX_RANDMMAP
9869+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9870+ mm->mmap_base += mm->delta_mmap;
9871+#endif
9872+
9873 mm->get_unmapped_area = s390_get_unmapped_area;
9874 } else {
9875 mm->mmap_base = mmap_base();
9876+
9877+#ifdef CONFIG_PAX_RANDMMAP
9878+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9879+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9880+#endif
9881+
9882 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9883 }
9884 }
9885diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9886index ae3d59f..f65f075 100644
9887--- a/arch/score/include/asm/cache.h
9888+++ b/arch/score/include/asm/cache.h
9889@@ -1,7 +1,9 @@
9890 #ifndef _ASM_SCORE_CACHE_H
9891 #define _ASM_SCORE_CACHE_H
9892
9893+#include <linux/const.h>
9894+
9895 #define L1_CACHE_SHIFT 4
9896-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9897+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9898
9899 #endif /* _ASM_SCORE_CACHE_H */
9900diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9901index f9f3cd5..58ff438 100644
9902--- a/arch/score/include/asm/exec.h
9903+++ b/arch/score/include/asm/exec.h
9904@@ -1,6 +1,6 @@
9905 #ifndef _ASM_SCORE_EXEC_H
9906 #define _ASM_SCORE_EXEC_H
9907
9908-extern unsigned long arch_align_stack(unsigned long sp);
9909+#define arch_align_stack(x) (x)
9910
9911 #endif /* _ASM_SCORE_EXEC_H */
9912diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9913index a1519ad3..e8ac1ff 100644
9914--- a/arch/score/kernel/process.c
9915+++ b/arch/score/kernel/process.c
9916@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9917
9918 return task_pt_regs(task)->cp0_epc;
9919 }
9920-
9921-unsigned long arch_align_stack(unsigned long sp)
9922-{
9923- return sp;
9924-}
9925diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9926index ef9e555..331bd29 100644
9927--- a/arch/sh/include/asm/cache.h
9928+++ b/arch/sh/include/asm/cache.h
9929@@ -9,10 +9,11 @@
9930 #define __ASM_SH_CACHE_H
9931 #ifdef __KERNEL__
9932
9933+#include <linux/const.h>
9934 #include <linux/init.h>
9935 #include <cpu/cache.h>
9936
9937-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9938+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9939
9940 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9941
9942diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9943index 6777177..cb5e44f 100644
9944--- a/arch/sh/mm/mmap.c
9945+++ b/arch/sh/mm/mmap.c
9946@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9947 struct mm_struct *mm = current->mm;
9948 struct vm_area_struct *vma;
9949 int do_colour_align;
9950+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9951 struct vm_unmapped_area_info info;
9952
9953 if (flags & MAP_FIXED) {
9954@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9955 if (filp || (flags & MAP_SHARED))
9956 do_colour_align = 1;
9957
9958+#ifdef CONFIG_PAX_RANDMMAP
9959+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9960+#endif
9961+
9962 if (addr) {
9963 if (do_colour_align)
9964 addr = COLOUR_ALIGN(addr, pgoff);
9965@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9966 addr = PAGE_ALIGN(addr);
9967
9968 vma = find_vma(mm, addr);
9969- if (TASK_SIZE - len >= addr &&
9970- (!vma || addr + len <= vma->vm_start))
9971+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9972 return addr;
9973 }
9974
9975 info.flags = 0;
9976 info.length = len;
9977- info.low_limit = TASK_UNMAPPED_BASE;
9978+ info.low_limit = mm->mmap_base;
9979 info.high_limit = TASK_SIZE;
9980 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9981 info.align_offset = pgoff << PAGE_SHIFT;
9982@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9983 struct mm_struct *mm = current->mm;
9984 unsigned long addr = addr0;
9985 int do_colour_align;
9986+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9987 struct vm_unmapped_area_info info;
9988
9989 if (flags & MAP_FIXED) {
9990@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9991 if (filp || (flags & MAP_SHARED))
9992 do_colour_align = 1;
9993
9994+#ifdef CONFIG_PAX_RANDMMAP
9995+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9996+#endif
9997+
9998 /* requesting a specific address */
9999 if (addr) {
10000 if (do_colour_align)
10001@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10002 addr = PAGE_ALIGN(addr);
10003
10004 vma = find_vma(mm, addr);
10005- if (TASK_SIZE - len >= addr &&
10006- (!vma || addr + len <= vma->vm_start))
10007+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10008 return addr;
10009 }
10010
10011@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10012 VM_BUG_ON(addr != -ENOMEM);
10013 info.flags = 0;
10014 info.low_limit = TASK_UNMAPPED_BASE;
10015+
10016+#ifdef CONFIG_PAX_RANDMMAP
10017+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10018+ info.low_limit += mm->delta_mmap;
10019+#endif
10020+
10021 info.high_limit = TASK_SIZE;
10022 addr = vm_unmapped_area(&info);
10023 }
10024diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
10025index bb894c8..8141d5c 100644
10026--- a/arch/sparc/include/asm/atomic_64.h
10027+++ b/arch/sparc/include/asm/atomic_64.h
10028@@ -15,18 +15,40 @@
10029 #define ATOMIC64_INIT(i) { (i) }
10030
10031 #define atomic_read(v) (*(volatile int *)&(v)->counter)
10032+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10033+{
10034+ return v->counter;
10035+}
10036 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
10037+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10038+{
10039+ return v->counter;
10040+}
10041
10042 #define atomic_set(v, i) (((v)->counter) = i)
10043+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10044+{
10045+ v->counter = i;
10046+}
10047 #define atomic64_set(v, i) (((v)->counter) = i)
10048+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10049+{
10050+ v->counter = i;
10051+}
10052
10053 void atomic_add(int, atomic_t *);
10054+void atomic_add_unchecked(int, atomic_unchecked_t *);
10055 void atomic64_add(long, atomic64_t *);
10056+void atomic64_add_unchecked(long, atomic64_unchecked_t *);
10057 void atomic_sub(int, atomic_t *);
10058+void atomic_sub_unchecked(int, atomic_unchecked_t *);
10059 void atomic64_sub(long, atomic64_t *);
10060+void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
10061
10062 int atomic_add_ret(int, atomic_t *);
10063+int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
10064 long atomic64_add_ret(long, atomic64_t *);
10065+long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
10066 int atomic_sub_ret(int, atomic_t *);
10067 long atomic64_sub_ret(long, atomic64_t *);
10068
10069@@ -34,13 +56,29 @@ long atomic64_sub_ret(long, atomic64_t *);
10070 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
10071
10072 #define atomic_inc_return(v) atomic_add_ret(1, v)
10073+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10074+{
10075+ return atomic_add_ret_unchecked(1, v);
10076+}
10077 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
10078+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10079+{
10080+ return atomic64_add_ret_unchecked(1, v);
10081+}
10082
10083 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
10084 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
10085
10086 #define atomic_add_return(i, v) atomic_add_ret(i, v)
10087+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10088+{
10089+ return atomic_add_ret_unchecked(i, v);
10090+}
10091 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
10092+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10093+{
10094+ return atomic64_add_ret_unchecked(i, v);
10095+}
10096
10097 /*
10098 * atomic_inc_and_test - increment and test
10099@@ -51,6 +89,10 @@ long atomic64_sub_ret(long, atomic64_t *);
10100 * other cases.
10101 */
10102 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
10103+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10104+{
10105+ return atomic_inc_return_unchecked(v) == 0;
10106+}
10107 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
10108
10109 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
10110@@ -60,25 +102,60 @@ long atomic64_sub_ret(long, atomic64_t *);
10111 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
10112
10113 #define atomic_inc(v) atomic_add(1, v)
10114+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10115+{
10116+ atomic_add_unchecked(1, v);
10117+}
10118 #define atomic64_inc(v) atomic64_add(1, v)
10119+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10120+{
10121+ atomic64_add_unchecked(1, v);
10122+}
10123
10124 #define atomic_dec(v) atomic_sub(1, v)
10125+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10126+{
10127+ atomic_sub_unchecked(1, v);
10128+}
10129 #define atomic64_dec(v) atomic64_sub(1, v)
10130+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10131+{
10132+ atomic64_sub_unchecked(1, v);
10133+}
10134
10135 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
10136 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
10137
10138 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10139+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10140+{
10141+ return cmpxchg(&v->counter, old, new);
10142+}
10143 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10144+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10145+{
10146+ return xchg(&v->counter, new);
10147+}
10148
10149 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10150 {
10151- int c, old;
10152+ int c, old, new;
10153 c = atomic_read(v);
10154 for (;;) {
10155- if (unlikely(c == (u)))
10156+ if (unlikely(c == u))
10157 break;
10158- old = atomic_cmpxchg((v), c, c + (a));
10159+
10160+ asm volatile("addcc %2, %0, %0\n"
10161+
10162+#ifdef CONFIG_PAX_REFCOUNT
10163+ "tvs %%icc, 6\n"
10164+#endif
10165+
10166+ : "=r" (new)
10167+ : "0" (c), "ir" (a)
10168+ : "cc");
10169+
10170+ old = atomic_cmpxchg(v, c, new);
10171 if (likely(old == c))
10172 break;
10173 c = old;
10174@@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10175 #define atomic64_cmpxchg(v, o, n) \
10176 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10177 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10178+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10179+{
10180+ return xchg(&v->counter, new);
10181+}
10182
10183 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10184 {
10185- long c, old;
10186+ long c, old, new;
10187 c = atomic64_read(v);
10188 for (;;) {
10189- if (unlikely(c == (u)))
10190+ if (unlikely(c == u))
10191 break;
10192- old = atomic64_cmpxchg((v), c, c + (a));
10193+
10194+ asm volatile("addcc %2, %0, %0\n"
10195+
10196+#ifdef CONFIG_PAX_REFCOUNT
10197+ "tvs %%xcc, 6\n"
10198+#endif
10199+
10200+ : "=r" (new)
10201+ : "0" (c), "ir" (a)
10202+ : "cc");
10203+
10204+ old = atomic64_cmpxchg(v, c, new);
10205 if (likely(old == c))
10206 break;
10207 c = old;
10208 }
10209- return c != (u);
10210+ return c != u;
10211 }
10212
10213 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10214diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10215index 305dcc3..7835030 100644
10216--- a/arch/sparc/include/asm/barrier_64.h
10217+++ b/arch/sparc/include/asm/barrier_64.h
10218@@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10219 do { \
10220 compiletime_assert_atomic_type(*p); \
10221 barrier(); \
10222- ACCESS_ONCE(*p) = (v); \
10223+ ACCESS_ONCE_RW(*p) = (v); \
10224 } while (0)
10225
10226 #define smp_load_acquire(p) \
10227diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10228index 5bb6991..5c2132e 100644
10229--- a/arch/sparc/include/asm/cache.h
10230+++ b/arch/sparc/include/asm/cache.h
10231@@ -7,10 +7,12 @@
10232 #ifndef _SPARC_CACHE_H
10233 #define _SPARC_CACHE_H
10234
10235+#include <linux/const.h>
10236+
10237 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10238
10239 #define L1_CACHE_SHIFT 5
10240-#define L1_CACHE_BYTES 32
10241+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10242
10243 #ifdef CONFIG_SPARC32
10244 #define SMP_CACHE_BYTES_SHIFT 5
10245diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10246index a24e41f..47677ff 100644
10247--- a/arch/sparc/include/asm/elf_32.h
10248+++ b/arch/sparc/include/asm/elf_32.h
10249@@ -114,6 +114,13 @@ typedef struct {
10250
10251 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10252
10253+#ifdef CONFIG_PAX_ASLR
10254+#define PAX_ELF_ET_DYN_BASE 0x10000UL
10255+
10256+#define PAX_DELTA_MMAP_LEN 16
10257+#define PAX_DELTA_STACK_LEN 16
10258+#endif
10259+
10260 /* This yields a mask that user programs can use to figure out what
10261 instruction set this cpu supports. This can NOT be done in userspace
10262 on Sparc. */
10263diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10264index 370ca1e..d4f4a98 100644
10265--- a/arch/sparc/include/asm/elf_64.h
10266+++ b/arch/sparc/include/asm/elf_64.h
10267@@ -189,6 +189,13 @@ typedef struct {
10268 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10269 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10270
10271+#ifdef CONFIG_PAX_ASLR
10272+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10273+
10274+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10275+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10276+#endif
10277+
10278 extern unsigned long sparc64_elf_hwcap;
10279 #define ELF_HWCAP sparc64_elf_hwcap
10280
10281diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10282index a3890da..f6a408e 100644
10283--- a/arch/sparc/include/asm/pgalloc_32.h
10284+++ b/arch/sparc/include/asm/pgalloc_32.h
10285@@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10286 }
10287
10288 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10289+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10290
10291 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10292 unsigned long address)
10293diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10294index 39a7ac4..2c9b586 100644
10295--- a/arch/sparc/include/asm/pgalloc_64.h
10296+++ b/arch/sparc/include/asm/pgalloc_64.h
10297@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
10298 }
10299
10300 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
10301+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10302
10303 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
10304 {
10305diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10306index 59ba6f6..4518128 100644
10307--- a/arch/sparc/include/asm/pgtable.h
10308+++ b/arch/sparc/include/asm/pgtable.h
10309@@ -5,4 +5,8 @@
10310 #else
10311 #include <asm/pgtable_32.h>
10312 #endif
10313+
10314+#define ktla_ktva(addr) (addr)
10315+#define ktva_ktla(addr) (addr)
10316+
10317 #endif
10318diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10319index b9b91ae..950b91e 100644
10320--- a/arch/sparc/include/asm/pgtable_32.h
10321+++ b/arch/sparc/include/asm/pgtable_32.h
10322@@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10323 #define PAGE_SHARED SRMMU_PAGE_SHARED
10324 #define PAGE_COPY SRMMU_PAGE_COPY
10325 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10326+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10327+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10328+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10329 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10330
10331 /* Top-level page directory - dummy used by init-mm.
10332@@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10333
10334 /* xwr */
10335 #define __P000 PAGE_NONE
10336-#define __P001 PAGE_READONLY
10337-#define __P010 PAGE_COPY
10338-#define __P011 PAGE_COPY
10339+#define __P001 PAGE_READONLY_NOEXEC
10340+#define __P010 PAGE_COPY_NOEXEC
10341+#define __P011 PAGE_COPY_NOEXEC
10342 #define __P100 PAGE_READONLY
10343 #define __P101 PAGE_READONLY
10344 #define __P110 PAGE_COPY
10345 #define __P111 PAGE_COPY
10346
10347 #define __S000 PAGE_NONE
10348-#define __S001 PAGE_READONLY
10349-#define __S010 PAGE_SHARED
10350-#define __S011 PAGE_SHARED
10351+#define __S001 PAGE_READONLY_NOEXEC
10352+#define __S010 PAGE_SHARED_NOEXEC
10353+#define __S011 PAGE_SHARED_NOEXEC
10354 #define __S100 PAGE_READONLY
10355 #define __S101 PAGE_READONLY
10356 #define __S110 PAGE_SHARED
10357diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10358index 79da178..c2eede8 100644
10359--- a/arch/sparc/include/asm/pgtsrmmu.h
10360+++ b/arch/sparc/include/asm/pgtsrmmu.h
10361@@ -115,6 +115,11 @@
10362 SRMMU_EXEC | SRMMU_REF)
10363 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10364 SRMMU_EXEC | SRMMU_REF)
10365+
10366+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10367+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10368+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10369+
10370 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10371 SRMMU_DIRTY | SRMMU_REF)
10372
10373diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10374index f5fffd8..a0669f0 100644
10375--- a/arch/sparc/include/asm/setup.h
10376+++ b/arch/sparc/include/asm/setup.h
10377@@ -53,8 +53,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10378 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10379
10380 /* init_64.c */
10381-extern atomic_t dcpage_flushes;
10382-extern atomic_t dcpage_flushes_xcall;
10383+extern atomic_unchecked_t dcpage_flushes;
10384+extern atomic_unchecked_t dcpage_flushes_xcall;
10385
10386 extern int sysctl_tsb_ratio;
10387 #endif
10388diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10389index 9689176..63c18ea 100644
10390--- a/arch/sparc/include/asm/spinlock_64.h
10391+++ b/arch/sparc/include/asm/spinlock_64.h
10392@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10393
10394 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10395
10396-static void inline arch_read_lock(arch_rwlock_t *lock)
10397+static inline void arch_read_lock(arch_rwlock_t *lock)
10398 {
10399 unsigned long tmp1, tmp2;
10400
10401 __asm__ __volatile__ (
10402 "1: ldsw [%2], %0\n"
10403 " brlz,pn %0, 2f\n"
10404-"4: add %0, 1, %1\n"
10405+"4: addcc %0, 1, %1\n"
10406+
10407+#ifdef CONFIG_PAX_REFCOUNT
10408+" tvs %%icc, 6\n"
10409+#endif
10410+
10411 " cas [%2], %0, %1\n"
10412 " cmp %0, %1\n"
10413 " bne,pn %%icc, 1b\n"
10414@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10415 " .previous"
10416 : "=&r" (tmp1), "=&r" (tmp2)
10417 : "r" (lock)
10418- : "memory");
10419+ : "memory", "cc");
10420 }
10421
10422-static int inline arch_read_trylock(arch_rwlock_t *lock)
10423+static inline int arch_read_trylock(arch_rwlock_t *lock)
10424 {
10425 int tmp1, tmp2;
10426
10427@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10428 "1: ldsw [%2], %0\n"
10429 " brlz,a,pn %0, 2f\n"
10430 " mov 0, %0\n"
10431-" add %0, 1, %1\n"
10432+" addcc %0, 1, %1\n"
10433+
10434+#ifdef CONFIG_PAX_REFCOUNT
10435+" tvs %%icc, 6\n"
10436+#endif
10437+
10438 " cas [%2], %0, %1\n"
10439 " cmp %0, %1\n"
10440 " bne,pn %%icc, 1b\n"
10441@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10442 return tmp1;
10443 }
10444
10445-static void inline arch_read_unlock(arch_rwlock_t *lock)
10446+static inline void arch_read_unlock(arch_rwlock_t *lock)
10447 {
10448 unsigned long tmp1, tmp2;
10449
10450 __asm__ __volatile__(
10451 "1: lduw [%2], %0\n"
10452-" sub %0, 1, %1\n"
10453+" subcc %0, 1, %1\n"
10454+
10455+#ifdef CONFIG_PAX_REFCOUNT
10456+" tvs %%icc, 6\n"
10457+#endif
10458+
10459 " cas [%2], %0, %1\n"
10460 " cmp %0, %1\n"
10461 " bne,pn %%xcc, 1b\n"
10462@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10463 : "memory");
10464 }
10465
10466-static void inline arch_write_lock(arch_rwlock_t *lock)
10467+static inline void arch_write_lock(arch_rwlock_t *lock)
10468 {
10469 unsigned long mask, tmp1, tmp2;
10470
10471@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10472 : "memory");
10473 }
10474
10475-static void inline arch_write_unlock(arch_rwlock_t *lock)
10476+static inline void arch_write_unlock(arch_rwlock_t *lock)
10477 {
10478 __asm__ __volatile__(
10479 " stw %%g0, [%0]"
10480@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10481 : "memory");
10482 }
10483
10484-static int inline arch_write_trylock(arch_rwlock_t *lock)
10485+static inline int arch_write_trylock(arch_rwlock_t *lock)
10486 {
10487 unsigned long mask, tmp1, tmp2, result;
10488
10489diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10490index 96efa7a..16858bf 100644
10491--- a/arch/sparc/include/asm/thread_info_32.h
10492+++ b/arch/sparc/include/asm/thread_info_32.h
10493@@ -49,6 +49,8 @@ struct thread_info {
10494 unsigned long w_saved;
10495
10496 struct restart_block restart_block;
10497+
10498+ unsigned long lowest_stack;
10499 };
10500
10501 /*
10502diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10503index a5f01ac..703b554 100644
10504--- a/arch/sparc/include/asm/thread_info_64.h
10505+++ b/arch/sparc/include/asm/thread_info_64.h
10506@@ -63,6 +63,8 @@ struct thread_info {
10507 struct pt_regs *kern_una_regs;
10508 unsigned int kern_una_insn;
10509
10510+ unsigned long lowest_stack;
10511+
10512 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10513 };
10514
10515@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10516 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10517 /* flag bit 4 is available */
10518 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10519-/* flag bit 6 is available */
10520+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10521 #define TIF_32BIT 7 /* 32-bit binary */
10522 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10523 #define TIF_SECCOMP 9 /* secure computing */
10524 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10525 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10526+
10527 /* NOTE: Thread flags >= 12 should be ones we have no interest
10528 * in using in assembly, else we can't use the mask as
10529 * an immediate value in instructions such as andcc.
10530@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10531 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10532 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10533 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10534+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10535
10536 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10537 _TIF_DO_NOTIFY_RESUME_MASK | \
10538 _TIF_NEED_RESCHED)
10539 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10540
10541+#define _TIF_WORK_SYSCALL \
10542+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10543+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10544+
10545+
10546 /*
10547 * Thread-synchronous status.
10548 *
10549diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10550index bd56c28..4b63d83 100644
10551--- a/arch/sparc/include/asm/uaccess.h
10552+++ b/arch/sparc/include/asm/uaccess.h
10553@@ -1,5 +1,6 @@
10554 #ifndef ___ASM_SPARC_UACCESS_H
10555 #define ___ASM_SPARC_UACCESS_H
10556+
10557 #if defined(__sparc__) && defined(__arch64__)
10558 #include <asm/uaccess_64.h>
10559 #else
10560diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10561index 9634d08..f55fe4f 100644
10562--- a/arch/sparc/include/asm/uaccess_32.h
10563+++ b/arch/sparc/include/asm/uaccess_32.h
10564@@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
10565
10566 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10567 {
10568- if (n && __access_ok((unsigned long) to, n))
10569+ if ((long)n < 0)
10570+ return n;
10571+
10572+ if (n && __access_ok((unsigned long) to, n)) {
10573+ if (!__builtin_constant_p(n))
10574+ check_object_size(from, n, true);
10575 return __copy_user(to, (__force void __user *) from, n);
10576- else
10577+ } else
10578 return n;
10579 }
10580
10581 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10582 {
10583+ if ((long)n < 0)
10584+ return n;
10585+
10586+ if (!__builtin_constant_p(n))
10587+ check_object_size(from, n, true);
10588+
10589 return __copy_user(to, (__force void __user *) from, n);
10590 }
10591
10592 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10593 {
10594- if (n && __access_ok((unsigned long) from, n))
10595+ if ((long)n < 0)
10596+ return n;
10597+
10598+ if (n && __access_ok((unsigned long) from, n)) {
10599+ if (!__builtin_constant_p(n))
10600+ check_object_size(to, n, false);
10601 return __copy_user((__force void __user *) to, from, n);
10602- else
10603+ } else
10604 return n;
10605 }
10606
10607 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10608 {
10609+ if ((long)n < 0)
10610+ return n;
10611+
10612 return __copy_user((__force void __user *) to, from, n);
10613 }
10614
10615diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10616index c990a5e..f17b9c1 100644
10617--- a/arch/sparc/include/asm/uaccess_64.h
10618+++ b/arch/sparc/include/asm/uaccess_64.h
10619@@ -10,6 +10,7 @@
10620 #include <linux/compiler.h>
10621 #include <linux/string.h>
10622 #include <linux/thread_info.h>
10623+#include <linux/kernel.h>
10624 #include <asm/asi.h>
10625 #include <asm/spitfire.h>
10626 #include <asm-generic/uaccess-unaligned.h>
10627@@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
10628 static inline unsigned long __must_check
10629 copy_from_user(void *to, const void __user *from, unsigned long size)
10630 {
10631- unsigned long ret = ___copy_from_user(to, from, size);
10632+ unsigned long ret;
10633
10634+ if ((long)size < 0 || size > INT_MAX)
10635+ return size;
10636+
10637+ if (!__builtin_constant_p(size))
10638+ check_object_size(to, size, false);
10639+
10640+ ret = ___copy_from_user(to, from, size);
10641 if (unlikely(ret))
10642 ret = copy_from_user_fixup(to, from, size);
10643
10644@@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
10645 static inline unsigned long __must_check
10646 copy_to_user(void __user *to, const void *from, unsigned long size)
10647 {
10648- unsigned long ret = ___copy_to_user(to, from, size);
10649+ unsigned long ret;
10650
10651+ if ((long)size < 0 || size > INT_MAX)
10652+ return size;
10653+
10654+ if (!__builtin_constant_p(size))
10655+ check_object_size(from, size, true);
10656+
10657+ ret = ___copy_to_user(to, from, size);
10658 if (unlikely(ret))
10659 ret = copy_to_user_fixup(to, from, size);
10660 return ret;
10661diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10662index 7cf9c6e..6206648 100644
10663--- a/arch/sparc/kernel/Makefile
10664+++ b/arch/sparc/kernel/Makefile
10665@@ -4,7 +4,7 @@
10666 #
10667
10668 asflags-y := -ansi
10669-ccflags-y := -Werror
10670+#ccflags-y := -Werror
10671
10672 extra-y := head_$(BITS).o
10673
10674diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10675index 50e7b62..79fae35 100644
10676--- a/arch/sparc/kernel/process_32.c
10677+++ b/arch/sparc/kernel/process_32.c
10678@@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
10679
10680 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10681 r->psr, r->pc, r->npc, r->y, print_tainted());
10682- printk("PC: <%pS>\n", (void *) r->pc);
10683+ printk("PC: <%pA>\n", (void *) r->pc);
10684 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10685 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10686 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10687 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10688 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10689 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10690- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10691+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10692
10693 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10694 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10695@@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10696 rw = (struct reg_window32 *) fp;
10697 pc = rw->ins[7];
10698 printk("[%08lx : ", pc);
10699- printk("%pS ] ", (void *) pc);
10700+ printk("%pA ] ", (void *) pc);
10701 fp = rw->ins[6];
10702 } while (++count < 16);
10703 printk("\n");
10704diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10705index 027e099..6d4178f 100644
10706--- a/arch/sparc/kernel/process_64.c
10707+++ b/arch/sparc/kernel/process_64.c
10708@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10709 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10710 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10711 if (regs->tstate & TSTATE_PRIV)
10712- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10713+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10714 }
10715
10716 void show_regs(struct pt_regs *regs)
10717@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10718
10719 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10720 regs->tpc, regs->tnpc, regs->y, print_tainted());
10721- printk("TPC: <%pS>\n", (void *) regs->tpc);
10722+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10723 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10724 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10725 regs->u_regs[3]);
10726@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10727 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10728 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10729 regs->u_regs[15]);
10730- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10731+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10732 show_regwindow(regs);
10733 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10734 }
10735@@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
10736 ((tp && tp->task) ? tp->task->pid : -1));
10737
10738 if (gp->tstate & TSTATE_PRIV) {
10739- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10740+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10741 (void *) gp->tpc,
10742 (void *) gp->o7,
10743 (void *) gp->i7,
10744diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10745index 79cc0d1..ec62734 100644
10746--- a/arch/sparc/kernel/prom_common.c
10747+++ b/arch/sparc/kernel/prom_common.c
10748@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10749
10750 unsigned int prom_early_allocated __initdata;
10751
10752-static struct of_pdt_ops prom_sparc_ops __initdata = {
10753+static struct of_pdt_ops prom_sparc_ops __initconst = {
10754 .nextprop = prom_common_nextprop,
10755 .getproplen = prom_getproplen,
10756 .getproperty = prom_getproperty,
10757diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10758index c13c9f2..d572c34 100644
10759--- a/arch/sparc/kernel/ptrace_64.c
10760+++ b/arch/sparc/kernel/ptrace_64.c
10761@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10762 return ret;
10763 }
10764
10765+#ifdef CONFIG_GRKERNSEC_SETXID
10766+extern void gr_delayed_cred_worker(void);
10767+#endif
10768+
10769 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10770 {
10771 int ret = 0;
10772@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10773 if (test_thread_flag(TIF_NOHZ))
10774 user_exit();
10775
10776+#ifdef CONFIG_GRKERNSEC_SETXID
10777+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10778+ gr_delayed_cred_worker();
10779+#endif
10780+
10781 if (test_thread_flag(TIF_SYSCALL_TRACE))
10782 ret = tracehook_report_syscall_entry(regs);
10783
10784@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10785 if (test_thread_flag(TIF_NOHZ))
10786 user_exit();
10787
10788+#ifdef CONFIG_GRKERNSEC_SETXID
10789+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10790+ gr_delayed_cred_worker();
10791+#endif
10792+
10793 audit_syscall_exit(regs);
10794
10795 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10796diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10797index 41aa247..eadfb74 100644
10798--- a/arch/sparc/kernel/smp_64.c
10799+++ b/arch/sparc/kernel/smp_64.c
10800@@ -883,7 +883,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10801 return;
10802
10803 #ifdef CONFIG_DEBUG_DCFLUSH
10804- atomic_inc(&dcpage_flushes);
10805+ atomic_inc_unchecked(&dcpage_flushes);
10806 #endif
10807
10808 this_cpu = get_cpu();
10809@@ -907,7 +907,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10810 xcall_deliver(data0, __pa(pg_addr),
10811 (u64) pg_addr, cpumask_of(cpu));
10812 #ifdef CONFIG_DEBUG_DCFLUSH
10813- atomic_inc(&dcpage_flushes_xcall);
10814+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10815 #endif
10816 }
10817 }
10818@@ -926,7 +926,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10819 preempt_disable();
10820
10821 #ifdef CONFIG_DEBUG_DCFLUSH
10822- atomic_inc(&dcpage_flushes);
10823+ atomic_inc_unchecked(&dcpage_flushes);
10824 #endif
10825 data0 = 0;
10826 pg_addr = page_address(page);
10827@@ -943,7 +943,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10828 xcall_deliver(data0, __pa(pg_addr),
10829 (u64) pg_addr, cpu_online_mask);
10830 #ifdef CONFIG_DEBUG_DCFLUSH
10831- atomic_inc(&dcpage_flushes_xcall);
10832+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10833 #endif
10834 }
10835 __local_flush_dcache_page(page);
10836diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10837index 646988d..b88905f 100644
10838--- a/arch/sparc/kernel/sys_sparc_32.c
10839+++ b/arch/sparc/kernel/sys_sparc_32.c
10840@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10841 if (len > TASK_SIZE - PAGE_SIZE)
10842 return -ENOMEM;
10843 if (!addr)
10844- addr = TASK_UNMAPPED_BASE;
10845+ addr = current->mm->mmap_base;
10846
10847 info.flags = 0;
10848 info.length = len;
10849diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10850index c85403d..6af95c9 100644
10851--- a/arch/sparc/kernel/sys_sparc_64.c
10852+++ b/arch/sparc/kernel/sys_sparc_64.c
10853@@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10854 struct vm_area_struct * vma;
10855 unsigned long task_size = TASK_SIZE;
10856 int do_color_align;
10857+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10858 struct vm_unmapped_area_info info;
10859
10860 if (flags & MAP_FIXED) {
10861 /* We do not accept a shared mapping if it would violate
10862 * cache aliasing constraints.
10863 */
10864- if ((flags & MAP_SHARED) &&
10865+ if ((filp || (flags & MAP_SHARED)) &&
10866 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10867 return -EINVAL;
10868 return addr;
10869@@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10870 if (filp || (flags & MAP_SHARED))
10871 do_color_align = 1;
10872
10873+#ifdef CONFIG_PAX_RANDMMAP
10874+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10875+#endif
10876+
10877 if (addr) {
10878 if (do_color_align)
10879 addr = COLOR_ALIGN(addr, pgoff);
10880@@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10881 addr = PAGE_ALIGN(addr);
10882
10883 vma = find_vma(mm, addr);
10884- if (task_size - len >= addr &&
10885- (!vma || addr + len <= vma->vm_start))
10886+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10887 return addr;
10888 }
10889
10890 info.flags = 0;
10891 info.length = len;
10892- info.low_limit = TASK_UNMAPPED_BASE;
10893+ info.low_limit = mm->mmap_base;
10894 info.high_limit = min(task_size, VA_EXCLUDE_START);
10895 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10896 info.align_offset = pgoff << PAGE_SHIFT;
10897+ info.threadstack_offset = offset;
10898 addr = vm_unmapped_area(&info);
10899
10900 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10901 VM_BUG_ON(addr != -ENOMEM);
10902 info.low_limit = VA_EXCLUDE_END;
10903+
10904+#ifdef CONFIG_PAX_RANDMMAP
10905+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10906+ info.low_limit += mm->delta_mmap;
10907+#endif
10908+
10909 info.high_limit = task_size;
10910 addr = vm_unmapped_area(&info);
10911 }
10912@@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10913 unsigned long task_size = STACK_TOP32;
10914 unsigned long addr = addr0;
10915 int do_color_align;
10916+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10917 struct vm_unmapped_area_info info;
10918
10919 /* This should only ever run for 32-bit processes. */
10920@@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10921 /* We do not accept a shared mapping if it would violate
10922 * cache aliasing constraints.
10923 */
10924- if ((flags & MAP_SHARED) &&
10925+ if ((filp || (flags & MAP_SHARED)) &&
10926 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10927 return -EINVAL;
10928 return addr;
10929@@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10930 if (filp || (flags & MAP_SHARED))
10931 do_color_align = 1;
10932
10933+#ifdef CONFIG_PAX_RANDMMAP
10934+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10935+#endif
10936+
10937 /* requesting a specific address */
10938 if (addr) {
10939 if (do_color_align)
10940@@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10941 addr = PAGE_ALIGN(addr);
10942
10943 vma = find_vma(mm, addr);
10944- if (task_size - len >= addr &&
10945- (!vma || addr + len <= vma->vm_start))
10946+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10947 return addr;
10948 }
10949
10950@@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10951 info.high_limit = mm->mmap_base;
10952 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10953 info.align_offset = pgoff << PAGE_SHIFT;
10954+ info.threadstack_offset = offset;
10955 addr = vm_unmapped_area(&info);
10956
10957 /*
10958@@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10959 VM_BUG_ON(addr != -ENOMEM);
10960 info.flags = 0;
10961 info.low_limit = TASK_UNMAPPED_BASE;
10962+
10963+#ifdef CONFIG_PAX_RANDMMAP
10964+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10965+ info.low_limit += mm->delta_mmap;
10966+#endif
10967+
10968 info.high_limit = STACK_TOP32;
10969 addr = vm_unmapped_area(&info);
10970 }
10971@@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10972 EXPORT_SYMBOL(get_fb_unmapped_area);
10973
10974 /* Essentially the same as PowerPC. */
10975-static unsigned long mmap_rnd(void)
10976+static unsigned long mmap_rnd(struct mm_struct *mm)
10977 {
10978 unsigned long rnd = 0UL;
10979
10980+#ifdef CONFIG_PAX_RANDMMAP
10981+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10982+#endif
10983+
10984 if (current->flags & PF_RANDOMIZE) {
10985 unsigned long val = get_random_int();
10986 if (test_thread_flag(TIF_32BIT))
10987@@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
10988
10989 void arch_pick_mmap_layout(struct mm_struct *mm)
10990 {
10991- unsigned long random_factor = mmap_rnd();
10992+ unsigned long random_factor = mmap_rnd(mm);
10993 unsigned long gap;
10994
10995 /*
10996@@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10997 gap == RLIM_INFINITY ||
10998 sysctl_legacy_va_layout) {
10999 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
11000+
11001+#ifdef CONFIG_PAX_RANDMMAP
11002+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11003+ mm->mmap_base += mm->delta_mmap;
11004+#endif
11005+
11006 mm->get_unmapped_area = arch_get_unmapped_area;
11007 } else {
11008 /* We know it's 32-bit */
11009@@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11010 gap = (task_size / 6 * 5);
11011
11012 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
11013+
11014+#ifdef CONFIG_PAX_RANDMMAP
11015+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11016+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
11017+#endif
11018+
11019 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
11020 }
11021 }
11022diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
11023index 33a17e7..d87fb1f 100644
11024--- a/arch/sparc/kernel/syscalls.S
11025+++ b/arch/sparc/kernel/syscalls.S
11026@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
11027 #endif
11028 .align 32
11029 1: ldx [%g6 + TI_FLAGS], %l5
11030- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11031+ andcc %l5, _TIF_WORK_SYSCALL, %g0
11032 be,pt %icc, rtrap
11033 nop
11034 call syscall_trace_leave
11035@@ -184,7 +184,7 @@ linux_sparc_syscall32:
11036
11037 srl %i3, 0, %o3 ! IEU0
11038 srl %i2, 0, %o2 ! IEU0 Group
11039- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11040+ andcc %l0, _TIF_WORK_SYSCALL, %g0
11041 bne,pn %icc, linux_syscall_trace32 ! CTI
11042 mov %i0, %l5 ! IEU1
11043 5: call %l7 ! CTI Group brk forced
11044@@ -208,7 +208,7 @@ linux_sparc_syscall:
11045
11046 mov %i3, %o3 ! IEU1
11047 mov %i4, %o4 ! IEU0 Group
11048- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11049+ andcc %l0, _TIF_WORK_SYSCALL, %g0
11050 bne,pn %icc, linux_syscall_trace ! CTI Group
11051 mov %i0, %l5 ! IEU0
11052 2: call %l7 ! CTI Group brk forced
11053@@ -223,7 +223,7 @@ ret_sys_call:
11054
11055 cmp %o0, -ERESTART_RESTARTBLOCK
11056 bgeu,pn %xcc, 1f
11057- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11058+ andcc %l0, _TIF_WORK_SYSCALL, %g0
11059 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
11060
11061 2:
11062diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
11063index 6fd386c5..6907d81 100644
11064--- a/arch/sparc/kernel/traps_32.c
11065+++ b/arch/sparc/kernel/traps_32.c
11066@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
11067 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
11068 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
11069
11070+extern void gr_handle_kernel_exploit(void);
11071+
11072 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11073 {
11074 static int die_counter;
11075@@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11076 count++ < 30 &&
11077 (((unsigned long) rw) >= PAGE_OFFSET) &&
11078 !(((unsigned long) rw) & 0x7)) {
11079- printk("Caller[%08lx]: %pS\n", rw->ins[7],
11080+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
11081 (void *) rw->ins[7]);
11082 rw = (struct reg_window32 *)rw->ins[6];
11083 }
11084 }
11085 printk("Instruction DUMP:");
11086 instruction_dump ((unsigned long *) regs->pc);
11087- if(regs->psr & PSR_PS)
11088+ if(regs->psr & PSR_PS) {
11089+ gr_handle_kernel_exploit();
11090 do_exit(SIGKILL);
11091+ }
11092 do_exit(SIGSEGV);
11093 }
11094
11095diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
11096index fb6640e..2daada8 100644
11097--- a/arch/sparc/kernel/traps_64.c
11098+++ b/arch/sparc/kernel/traps_64.c
11099@@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
11100 i + 1,
11101 p->trapstack[i].tstate, p->trapstack[i].tpc,
11102 p->trapstack[i].tnpc, p->trapstack[i].tt);
11103- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
11104+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
11105 }
11106 }
11107
11108@@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
11109
11110 lvl -= 0x100;
11111 if (regs->tstate & TSTATE_PRIV) {
11112+
11113+#ifdef CONFIG_PAX_REFCOUNT
11114+ if (lvl == 6)
11115+ pax_report_refcount_overflow(regs);
11116+#endif
11117+
11118 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11119 die_if_kernel(buffer, regs);
11120 }
11121@@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11122 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11123 {
11124 char buffer[32];
11125-
11126+
11127 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11128 0, lvl, SIGTRAP) == NOTIFY_STOP)
11129 return;
11130
11131+#ifdef CONFIG_PAX_REFCOUNT
11132+ if (lvl == 6)
11133+ pax_report_refcount_overflow(regs);
11134+#endif
11135+
11136 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11137
11138 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11139@@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11140 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11141 printk("%s" "ERROR(%d): ",
11142 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11143- printk("TPC<%pS>\n", (void *) regs->tpc);
11144+ printk("TPC<%pA>\n", (void *) regs->tpc);
11145 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11146 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11147 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11148@@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11149 smp_processor_id(),
11150 (type & 0x1) ? 'I' : 'D',
11151 regs->tpc);
11152- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11153+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11154 panic("Irrecoverable Cheetah+ parity error.");
11155 }
11156
11157@@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11158 smp_processor_id(),
11159 (type & 0x1) ? 'I' : 'D',
11160 regs->tpc);
11161- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11162+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11163 }
11164
11165 struct sun4v_error_entry {
11166@@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11167 /*0x38*/u64 reserved_5;
11168 };
11169
11170-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11171-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11172+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11173+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11174
11175 static const char *sun4v_err_type_to_str(u8 type)
11176 {
11177@@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11178 }
11179
11180 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11181- int cpu, const char *pfx, atomic_t *ocnt)
11182+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11183 {
11184 u64 *raw_ptr = (u64 *) ent;
11185 u32 attrs;
11186@@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11187
11188 show_regs(regs);
11189
11190- if ((cnt = atomic_read(ocnt)) != 0) {
11191- atomic_set(ocnt, 0);
11192+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11193+ atomic_set_unchecked(ocnt, 0);
11194 wmb();
11195 printk("%s: Queue overflowed %d times.\n",
11196 pfx, cnt);
11197@@ -2048,7 +2059,7 @@ out:
11198 */
11199 void sun4v_resum_overflow(struct pt_regs *regs)
11200 {
11201- atomic_inc(&sun4v_resum_oflow_cnt);
11202+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11203 }
11204
11205 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11206@@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11207 /* XXX Actually even this can make not that much sense. Perhaps
11208 * XXX we should just pull the plug and panic directly from here?
11209 */
11210- atomic_inc(&sun4v_nonresum_oflow_cnt);
11211+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11212 }
11213
11214 unsigned long sun4v_err_itlb_vaddr;
11215@@ -2116,9 +2127,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11216
11217 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11218 regs->tpc, tl);
11219- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11220+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11221 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11222- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11223+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11224 (void *) regs->u_regs[UREG_I7]);
11225 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11226 "pte[%lx] error[%lx]\n",
11227@@ -2140,9 +2151,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11228
11229 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11230 regs->tpc, tl);
11231- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11232+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11233 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11234- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11235+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11236 (void *) regs->u_regs[UREG_I7]);
11237 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11238 "pte[%lx] error[%lx]\n",
11239@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11240 fp = (unsigned long)sf->fp + STACK_BIAS;
11241 }
11242
11243- printk(" [%016lx] %pS\n", pc, (void *) pc);
11244+ printk(" [%016lx] %pA\n", pc, (void *) pc);
11245 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11246 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11247 int index = tsk->curr_ret_stack;
11248 if (tsk->ret_stack && index >= graph) {
11249 pc = tsk->ret_stack[index - graph].ret;
11250- printk(" [%016lx] %pS\n", pc, (void *) pc);
11251+ printk(" [%016lx] %pA\n", pc, (void *) pc);
11252 graph++;
11253 }
11254 }
11255@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11256 return (struct reg_window *) (fp + STACK_BIAS);
11257 }
11258
11259+extern void gr_handle_kernel_exploit(void);
11260+
11261 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11262 {
11263 static int die_counter;
11264@@ -2411,7 +2424,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11265 while (rw &&
11266 count++ < 30 &&
11267 kstack_valid(tp, (unsigned long) rw)) {
11268- printk("Caller[%016lx]: %pS\n", rw->ins[7],
11269+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
11270 (void *) rw->ins[7]);
11271
11272 rw = kernel_stack_up(rw);
11273@@ -2424,8 +2437,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11274 }
11275 user_instruction_dump ((unsigned int __user *) regs->tpc);
11276 }
11277- if (regs->tstate & TSTATE_PRIV)
11278+ if (regs->tstate & TSTATE_PRIV) {
11279+ gr_handle_kernel_exploit();
11280 do_exit(SIGKILL);
11281+ }
11282 do_exit(SIGSEGV);
11283 }
11284 EXPORT_SYMBOL(die_if_kernel);
11285diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11286index 62098a8..547ab2c 100644
11287--- a/arch/sparc/kernel/unaligned_64.c
11288+++ b/arch/sparc/kernel/unaligned_64.c
11289@@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11290 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11291
11292 if (__ratelimit(&ratelimit)) {
11293- printk("Kernel unaligned access at TPC[%lx] %pS\n",
11294+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
11295 regs->tpc, (void *) regs->tpc);
11296 }
11297 }
11298diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11299index 3269b02..64f5231 100644
11300--- a/arch/sparc/lib/Makefile
11301+++ b/arch/sparc/lib/Makefile
11302@@ -2,7 +2,7 @@
11303 #
11304
11305 asflags-y := -ansi -DST_DIV0=0x02
11306-ccflags-y := -Werror
11307+#ccflags-y := -Werror
11308
11309 lib-$(CONFIG_SPARC32) += ashrdi3.o
11310 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11311diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11312index 85c233d..68500e0 100644
11313--- a/arch/sparc/lib/atomic_64.S
11314+++ b/arch/sparc/lib/atomic_64.S
11315@@ -17,7 +17,12 @@
11316 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11317 BACKOFF_SETUP(%o2)
11318 1: lduw [%o1], %g1
11319- add %g1, %o0, %g7
11320+ addcc %g1, %o0, %g7
11321+
11322+#ifdef CONFIG_PAX_REFCOUNT
11323+ tvs %icc, 6
11324+#endif
11325+
11326 cas [%o1], %g1, %g7
11327 cmp %g1, %g7
11328 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11329@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11330 2: BACKOFF_SPIN(%o2, %o3, 1b)
11331 ENDPROC(atomic_add)
11332
11333+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11334+ BACKOFF_SETUP(%o2)
11335+1: lduw [%o1], %g1
11336+ add %g1, %o0, %g7
11337+ cas [%o1], %g1, %g7
11338+ cmp %g1, %g7
11339+ bne,pn %icc, 2f
11340+ nop
11341+ retl
11342+ nop
11343+2: BACKOFF_SPIN(%o2, %o3, 1b)
11344+ENDPROC(atomic_add_unchecked)
11345+
11346 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11347 BACKOFF_SETUP(%o2)
11348 1: lduw [%o1], %g1
11349- sub %g1, %o0, %g7
11350+ subcc %g1, %o0, %g7
11351+
11352+#ifdef CONFIG_PAX_REFCOUNT
11353+ tvs %icc, 6
11354+#endif
11355+
11356 cas [%o1], %g1, %g7
11357 cmp %g1, %g7
11358 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11359@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11360 2: BACKOFF_SPIN(%o2, %o3, 1b)
11361 ENDPROC(atomic_sub)
11362
11363+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11364+ BACKOFF_SETUP(%o2)
11365+1: lduw [%o1], %g1
11366+ sub %g1, %o0, %g7
11367+ cas [%o1], %g1, %g7
11368+ cmp %g1, %g7
11369+ bne,pn %icc, 2f
11370+ nop
11371+ retl
11372+ nop
11373+2: BACKOFF_SPIN(%o2, %o3, 1b)
11374+ENDPROC(atomic_sub_unchecked)
11375+
11376 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11377 BACKOFF_SETUP(%o2)
11378 1: lduw [%o1], %g1
11379- add %g1, %o0, %g7
11380+ addcc %g1, %o0, %g7
11381+
11382+#ifdef CONFIG_PAX_REFCOUNT
11383+ tvs %icc, 6
11384+#endif
11385+
11386 cas [%o1], %g1, %g7
11387 cmp %g1, %g7
11388 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11389@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11390 2: BACKOFF_SPIN(%o2, %o3, 1b)
11391 ENDPROC(atomic_add_ret)
11392
11393+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11394+ BACKOFF_SETUP(%o2)
11395+1: lduw [%o1], %g1
11396+ addcc %g1, %o0, %g7
11397+ cas [%o1], %g1, %g7
11398+ cmp %g1, %g7
11399+ bne,pn %icc, 2f
11400+ add %g7, %o0, %g7
11401+ sra %g7, 0, %o0
11402+ retl
11403+ nop
11404+2: BACKOFF_SPIN(%o2, %o3, 1b)
11405+ENDPROC(atomic_add_ret_unchecked)
11406+
11407 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11408 BACKOFF_SETUP(%o2)
11409 1: lduw [%o1], %g1
11410- sub %g1, %o0, %g7
11411+ subcc %g1, %o0, %g7
11412+
11413+#ifdef CONFIG_PAX_REFCOUNT
11414+ tvs %icc, 6
11415+#endif
11416+
11417 cas [%o1], %g1, %g7
11418 cmp %g1, %g7
11419 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11420@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11421 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11422 BACKOFF_SETUP(%o2)
11423 1: ldx [%o1], %g1
11424- add %g1, %o0, %g7
11425+ addcc %g1, %o0, %g7
11426+
11427+#ifdef CONFIG_PAX_REFCOUNT
11428+ tvs %xcc, 6
11429+#endif
11430+
11431 casx [%o1], %g1, %g7
11432 cmp %g1, %g7
11433 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11434@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11435 2: BACKOFF_SPIN(%o2, %o3, 1b)
11436 ENDPROC(atomic64_add)
11437
11438+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11439+ BACKOFF_SETUP(%o2)
11440+1: ldx [%o1], %g1
11441+ addcc %g1, %o0, %g7
11442+ casx [%o1], %g1, %g7
11443+ cmp %g1, %g7
11444+ bne,pn %xcc, 2f
11445+ nop
11446+ retl
11447+ nop
11448+2: BACKOFF_SPIN(%o2, %o3, 1b)
11449+ENDPROC(atomic64_add_unchecked)
11450+
11451 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11452 BACKOFF_SETUP(%o2)
11453 1: ldx [%o1], %g1
11454- sub %g1, %o0, %g7
11455+ subcc %g1, %o0, %g7
11456+
11457+#ifdef CONFIG_PAX_REFCOUNT
11458+ tvs %xcc, 6
11459+#endif
11460+
11461 casx [%o1], %g1, %g7
11462 cmp %g1, %g7
11463 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11464@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11465 2: BACKOFF_SPIN(%o2, %o3, 1b)
11466 ENDPROC(atomic64_sub)
11467
11468+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11469+ BACKOFF_SETUP(%o2)
11470+1: ldx [%o1], %g1
11471+ subcc %g1, %o0, %g7
11472+ casx [%o1], %g1, %g7
11473+ cmp %g1, %g7
11474+ bne,pn %xcc, 2f
11475+ nop
11476+ retl
11477+ nop
11478+2: BACKOFF_SPIN(%o2, %o3, 1b)
11479+ENDPROC(atomic64_sub_unchecked)
11480+
11481 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11482 BACKOFF_SETUP(%o2)
11483 1: ldx [%o1], %g1
11484- add %g1, %o0, %g7
11485+ addcc %g1, %o0, %g7
11486+
11487+#ifdef CONFIG_PAX_REFCOUNT
11488+ tvs %xcc, 6
11489+#endif
11490+
11491 casx [%o1], %g1, %g7
11492 cmp %g1, %g7
11493 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11494@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11495 2: BACKOFF_SPIN(%o2, %o3, 1b)
11496 ENDPROC(atomic64_add_ret)
11497
11498+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11499+ BACKOFF_SETUP(%o2)
11500+1: ldx [%o1], %g1
11501+ addcc %g1, %o0, %g7
11502+ casx [%o1], %g1, %g7
11503+ cmp %g1, %g7
11504+ bne,pn %xcc, 2f
11505+ add %g7, %o0, %g7
11506+ mov %g7, %o0
11507+ retl
11508+ nop
11509+2: BACKOFF_SPIN(%o2, %o3, 1b)
11510+ENDPROC(atomic64_add_ret_unchecked)
11511+
11512 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11513 BACKOFF_SETUP(%o2)
11514 1: ldx [%o1], %g1
11515- sub %g1, %o0, %g7
11516+ subcc %g1, %o0, %g7
11517+
11518+#ifdef CONFIG_PAX_REFCOUNT
11519+ tvs %xcc, 6
11520+#endif
11521+
11522 casx [%o1], %g1, %g7
11523 cmp %g1, %g7
11524 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11525diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11526index 323335b..ed85ea2 100644
11527--- a/arch/sparc/lib/ksyms.c
11528+++ b/arch/sparc/lib/ksyms.c
11529@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11530
11531 /* Atomic counter implementation. */
11532 EXPORT_SYMBOL(atomic_add);
11533+EXPORT_SYMBOL(atomic_add_unchecked);
11534 EXPORT_SYMBOL(atomic_add_ret);
11535+EXPORT_SYMBOL(atomic_add_ret_unchecked);
11536 EXPORT_SYMBOL(atomic_sub);
11537+EXPORT_SYMBOL(atomic_sub_unchecked);
11538 EXPORT_SYMBOL(atomic_sub_ret);
11539 EXPORT_SYMBOL(atomic64_add);
11540+EXPORT_SYMBOL(atomic64_add_unchecked);
11541 EXPORT_SYMBOL(atomic64_add_ret);
11542+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11543 EXPORT_SYMBOL(atomic64_sub);
11544+EXPORT_SYMBOL(atomic64_sub_unchecked);
11545 EXPORT_SYMBOL(atomic64_sub_ret);
11546 EXPORT_SYMBOL(atomic64_dec_if_positive);
11547
11548diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11549index 30c3ecc..736f015 100644
11550--- a/arch/sparc/mm/Makefile
11551+++ b/arch/sparc/mm/Makefile
11552@@ -2,7 +2,7 @@
11553 #
11554
11555 asflags-y := -ansi
11556-ccflags-y := -Werror
11557+#ccflags-y := -Werror
11558
11559 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11560 obj-y += fault_$(BITS).o
11561diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11562index 908e8c1..1524793 100644
11563--- a/arch/sparc/mm/fault_32.c
11564+++ b/arch/sparc/mm/fault_32.c
11565@@ -21,6 +21,9 @@
11566 #include <linux/perf_event.h>
11567 #include <linux/interrupt.h>
11568 #include <linux/kdebug.h>
11569+#include <linux/slab.h>
11570+#include <linux/pagemap.h>
11571+#include <linux/compiler.h>
11572
11573 #include <asm/page.h>
11574 #include <asm/pgtable.h>
11575@@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11576 return safe_compute_effective_address(regs, insn);
11577 }
11578
11579+#ifdef CONFIG_PAX_PAGEEXEC
11580+#ifdef CONFIG_PAX_DLRESOLVE
11581+static void pax_emuplt_close(struct vm_area_struct *vma)
11582+{
11583+ vma->vm_mm->call_dl_resolve = 0UL;
11584+}
11585+
11586+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11587+{
11588+ unsigned int *kaddr;
11589+
11590+ vmf->page = alloc_page(GFP_HIGHUSER);
11591+ if (!vmf->page)
11592+ return VM_FAULT_OOM;
11593+
11594+ kaddr = kmap(vmf->page);
11595+ memset(kaddr, 0, PAGE_SIZE);
11596+ kaddr[0] = 0x9DE3BFA8U; /* save */
11597+ flush_dcache_page(vmf->page);
11598+ kunmap(vmf->page);
11599+ return VM_FAULT_MAJOR;
11600+}
11601+
11602+static const struct vm_operations_struct pax_vm_ops = {
11603+ .close = pax_emuplt_close,
11604+ .fault = pax_emuplt_fault
11605+};
11606+
11607+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11608+{
11609+ int ret;
11610+
11611+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11612+ vma->vm_mm = current->mm;
11613+ vma->vm_start = addr;
11614+ vma->vm_end = addr + PAGE_SIZE;
11615+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11616+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11617+ vma->vm_ops = &pax_vm_ops;
11618+
11619+ ret = insert_vm_struct(current->mm, vma);
11620+ if (ret)
11621+ return ret;
11622+
11623+ ++current->mm->total_vm;
11624+ return 0;
11625+}
11626+#endif
11627+
11628+/*
11629+ * PaX: decide what to do with offenders (regs->pc = fault address)
11630+ *
11631+ * returns 1 when task should be killed
11632+ * 2 when patched PLT trampoline was detected
11633+ * 3 when unpatched PLT trampoline was detected
11634+ */
11635+static int pax_handle_fetch_fault(struct pt_regs *regs)
11636+{
11637+
11638+#ifdef CONFIG_PAX_EMUPLT
11639+ int err;
11640+
11641+ do { /* PaX: patched PLT emulation #1 */
11642+ unsigned int sethi1, sethi2, jmpl;
11643+
11644+ err = get_user(sethi1, (unsigned int *)regs->pc);
11645+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11646+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11647+
11648+ if (err)
11649+ break;
11650+
11651+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11652+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11653+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11654+ {
11655+ unsigned int addr;
11656+
11657+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11658+ addr = regs->u_regs[UREG_G1];
11659+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11660+ regs->pc = addr;
11661+ regs->npc = addr+4;
11662+ return 2;
11663+ }
11664+ } while (0);
11665+
11666+ do { /* PaX: patched PLT emulation #2 */
11667+ unsigned int ba;
11668+
11669+ err = get_user(ba, (unsigned int *)regs->pc);
11670+
11671+ if (err)
11672+ break;
11673+
11674+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11675+ unsigned int addr;
11676+
11677+ if ((ba & 0xFFC00000U) == 0x30800000U)
11678+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11679+ else
11680+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11681+ regs->pc = addr;
11682+ regs->npc = addr+4;
11683+ return 2;
11684+ }
11685+ } while (0);
11686+
11687+ do { /* PaX: patched PLT emulation #3 */
11688+ unsigned int sethi, bajmpl, nop;
11689+
11690+ err = get_user(sethi, (unsigned int *)regs->pc);
11691+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11692+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11693+
11694+ if (err)
11695+ break;
11696+
11697+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11698+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11699+ nop == 0x01000000U)
11700+ {
11701+ unsigned int addr;
11702+
11703+ addr = (sethi & 0x003FFFFFU) << 10;
11704+ regs->u_regs[UREG_G1] = addr;
11705+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11706+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11707+ else
11708+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11709+ regs->pc = addr;
11710+ regs->npc = addr+4;
11711+ return 2;
11712+ }
11713+ } while (0);
11714+
11715+ do { /* PaX: unpatched PLT emulation step 1 */
11716+ unsigned int sethi, ba, nop;
11717+
11718+ err = get_user(sethi, (unsigned int *)regs->pc);
11719+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11720+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11721+
11722+ if (err)
11723+ break;
11724+
11725+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11726+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11727+ nop == 0x01000000U)
11728+ {
11729+ unsigned int addr, save, call;
11730+
11731+ if ((ba & 0xFFC00000U) == 0x30800000U)
11732+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11733+ else
11734+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11735+
11736+ err = get_user(save, (unsigned int *)addr);
11737+ err |= get_user(call, (unsigned int *)(addr+4));
11738+ err |= get_user(nop, (unsigned int *)(addr+8));
11739+ if (err)
11740+ break;
11741+
11742+#ifdef CONFIG_PAX_DLRESOLVE
11743+ if (save == 0x9DE3BFA8U &&
11744+ (call & 0xC0000000U) == 0x40000000U &&
11745+ nop == 0x01000000U)
11746+ {
11747+ struct vm_area_struct *vma;
11748+ unsigned long call_dl_resolve;
11749+
11750+ down_read(&current->mm->mmap_sem);
11751+ call_dl_resolve = current->mm->call_dl_resolve;
11752+ up_read(&current->mm->mmap_sem);
11753+ if (likely(call_dl_resolve))
11754+ goto emulate;
11755+
11756+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11757+
11758+ down_write(&current->mm->mmap_sem);
11759+ if (current->mm->call_dl_resolve) {
11760+ call_dl_resolve = current->mm->call_dl_resolve;
11761+ up_write(&current->mm->mmap_sem);
11762+ if (vma)
11763+ kmem_cache_free(vm_area_cachep, vma);
11764+ goto emulate;
11765+ }
11766+
11767+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11768+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11769+ up_write(&current->mm->mmap_sem);
11770+ if (vma)
11771+ kmem_cache_free(vm_area_cachep, vma);
11772+ return 1;
11773+ }
11774+
11775+ if (pax_insert_vma(vma, call_dl_resolve)) {
11776+ up_write(&current->mm->mmap_sem);
11777+ kmem_cache_free(vm_area_cachep, vma);
11778+ return 1;
11779+ }
11780+
11781+ current->mm->call_dl_resolve = call_dl_resolve;
11782+ up_write(&current->mm->mmap_sem);
11783+
11784+emulate:
11785+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11786+ regs->pc = call_dl_resolve;
11787+ regs->npc = addr+4;
11788+ return 3;
11789+ }
11790+#endif
11791+
11792+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11793+ if ((save & 0xFFC00000U) == 0x05000000U &&
11794+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11795+ nop == 0x01000000U)
11796+ {
11797+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11798+ regs->u_regs[UREG_G2] = addr + 4;
11799+ addr = (save & 0x003FFFFFU) << 10;
11800+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11801+ regs->pc = addr;
11802+ regs->npc = addr+4;
11803+ return 3;
11804+ }
11805+ }
11806+ } while (0);
11807+
11808+ do { /* PaX: unpatched PLT emulation step 2 */
11809+ unsigned int save, call, nop;
11810+
11811+ err = get_user(save, (unsigned int *)(regs->pc-4));
11812+ err |= get_user(call, (unsigned int *)regs->pc);
11813+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11814+ if (err)
11815+ break;
11816+
11817+ if (save == 0x9DE3BFA8U &&
11818+ (call & 0xC0000000U) == 0x40000000U &&
11819+ nop == 0x01000000U)
11820+ {
11821+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11822+
11823+ regs->u_regs[UREG_RETPC] = regs->pc;
11824+ regs->pc = dl_resolve;
11825+ regs->npc = dl_resolve+4;
11826+ return 3;
11827+ }
11828+ } while (0);
11829+#endif
11830+
11831+ return 1;
11832+}
11833+
11834+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11835+{
11836+ unsigned long i;
11837+
11838+ printk(KERN_ERR "PAX: bytes at PC: ");
11839+ for (i = 0; i < 8; i++) {
11840+ unsigned int c;
11841+ if (get_user(c, (unsigned int *)pc+i))
11842+ printk(KERN_CONT "???????? ");
11843+ else
11844+ printk(KERN_CONT "%08x ", c);
11845+ }
11846+ printk("\n");
11847+}
11848+#endif
11849+
11850 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11851 int text_fault)
11852 {
11853@@ -226,6 +500,24 @@ good_area:
11854 if (!(vma->vm_flags & VM_WRITE))
11855 goto bad_area;
11856 } else {
11857+
11858+#ifdef CONFIG_PAX_PAGEEXEC
11859+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11860+ up_read(&mm->mmap_sem);
11861+ switch (pax_handle_fetch_fault(regs)) {
11862+
11863+#ifdef CONFIG_PAX_EMUPLT
11864+ case 2:
11865+ case 3:
11866+ return;
11867+#endif
11868+
11869+ }
11870+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11871+ do_group_exit(SIGKILL);
11872+ }
11873+#endif
11874+
11875 /* Allow reads even for write-only mappings */
11876 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11877 goto bad_area;
11878diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11879index 587cd05..fbdf17a 100644
11880--- a/arch/sparc/mm/fault_64.c
11881+++ b/arch/sparc/mm/fault_64.c
11882@@ -22,6 +22,9 @@
11883 #include <linux/kdebug.h>
11884 #include <linux/percpu.h>
11885 #include <linux/context_tracking.h>
11886+#include <linux/slab.h>
11887+#include <linux/pagemap.h>
11888+#include <linux/compiler.h>
11889
11890 #include <asm/page.h>
11891 #include <asm/pgtable.h>
11892@@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11893 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11894 regs->tpc);
11895 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11896- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11897+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11898 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11899 dump_stack();
11900 unhandled_fault(regs->tpc, current, regs);
11901@@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11902 show_regs(regs);
11903 }
11904
11905+#ifdef CONFIG_PAX_PAGEEXEC
11906+#ifdef CONFIG_PAX_DLRESOLVE
11907+static void pax_emuplt_close(struct vm_area_struct *vma)
11908+{
11909+ vma->vm_mm->call_dl_resolve = 0UL;
11910+}
11911+
11912+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11913+{
11914+ unsigned int *kaddr;
11915+
11916+ vmf->page = alloc_page(GFP_HIGHUSER);
11917+ if (!vmf->page)
11918+ return VM_FAULT_OOM;
11919+
11920+ kaddr = kmap(vmf->page);
11921+ memset(kaddr, 0, PAGE_SIZE);
11922+ kaddr[0] = 0x9DE3BFA8U; /* save */
11923+ flush_dcache_page(vmf->page);
11924+ kunmap(vmf->page);
11925+ return VM_FAULT_MAJOR;
11926+}
11927+
11928+static const struct vm_operations_struct pax_vm_ops = {
11929+ .close = pax_emuplt_close,
11930+ .fault = pax_emuplt_fault
11931+};
11932+
11933+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11934+{
11935+ int ret;
11936+
11937+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11938+ vma->vm_mm = current->mm;
11939+ vma->vm_start = addr;
11940+ vma->vm_end = addr + PAGE_SIZE;
11941+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11942+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11943+ vma->vm_ops = &pax_vm_ops;
11944+
11945+ ret = insert_vm_struct(current->mm, vma);
11946+ if (ret)
11947+ return ret;
11948+
11949+ ++current->mm->total_vm;
11950+ return 0;
11951+}
11952+#endif
11953+
11954+/*
11955+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11956+ *
11957+ * returns 1 when task should be killed
11958+ * 2 when patched PLT trampoline was detected
11959+ * 3 when unpatched PLT trampoline was detected
11960+ */
11961+static int pax_handle_fetch_fault(struct pt_regs *regs)
11962+{
11963+
11964+#ifdef CONFIG_PAX_EMUPLT
11965+ int err;
11966+
11967+ do { /* PaX: patched PLT emulation #1 */
11968+ unsigned int sethi1, sethi2, jmpl;
11969+
11970+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11971+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11972+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11973+
11974+ if (err)
11975+ break;
11976+
11977+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11978+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11979+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11980+ {
11981+ unsigned long addr;
11982+
11983+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11984+ addr = regs->u_regs[UREG_G1];
11985+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11986+
11987+ if (test_thread_flag(TIF_32BIT))
11988+ addr &= 0xFFFFFFFFUL;
11989+
11990+ regs->tpc = addr;
11991+ regs->tnpc = addr+4;
11992+ return 2;
11993+ }
11994+ } while (0);
11995+
11996+ do { /* PaX: patched PLT emulation #2 */
11997+ unsigned int ba;
11998+
11999+ err = get_user(ba, (unsigned int *)regs->tpc);
12000+
12001+ if (err)
12002+ break;
12003+
12004+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12005+ unsigned long addr;
12006+
12007+ if ((ba & 0xFFC00000U) == 0x30800000U)
12008+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12009+ else
12010+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12011+
12012+ if (test_thread_flag(TIF_32BIT))
12013+ addr &= 0xFFFFFFFFUL;
12014+
12015+ regs->tpc = addr;
12016+ regs->tnpc = addr+4;
12017+ return 2;
12018+ }
12019+ } while (0);
12020+
12021+ do { /* PaX: patched PLT emulation #3 */
12022+ unsigned int sethi, bajmpl, nop;
12023+
12024+ err = get_user(sethi, (unsigned int *)regs->tpc);
12025+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
12026+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12027+
12028+ if (err)
12029+ break;
12030+
12031+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12032+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12033+ nop == 0x01000000U)
12034+ {
12035+ unsigned long addr;
12036+
12037+ addr = (sethi & 0x003FFFFFU) << 10;
12038+ regs->u_regs[UREG_G1] = addr;
12039+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12040+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12041+ else
12042+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12043+
12044+ if (test_thread_flag(TIF_32BIT))
12045+ addr &= 0xFFFFFFFFUL;
12046+
12047+ regs->tpc = addr;
12048+ regs->tnpc = addr+4;
12049+ return 2;
12050+ }
12051+ } while (0);
12052+
12053+ do { /* PaX: patched PLT emulation #4 */
12054+ unsigned int sethi, mov1, call, mov2;
12055+
12056+ err = get_user(sethi, (unsigned int *)regs->tpc);
12057+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
12058+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
12059+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
12060+
12061+ if (err)
12062+ break;
12063+
12064+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12065+ mov1 == 0x8210000FU &&
12066+ (call & 0xC0000000U) == 0x40000000U &&
12067+ mov2 == 0x9E100001U)
12068+ {
12069+ unsigned long addr;
12070+
12071+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
12072+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12073+
12074+ if (test_thread_flag(TIF_32BIT))
12075+ addr &= 0xFFFFFFFFUL;
12076+
12077+ regs->tpc = addr;
12078+ regs->tnpc = addr+4;
12079+ return 2;
12080+ }
12081+ } while (0);
12082+
12083+ do { /* PaX: patched PLT emulation #5 */
12084+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
12085+
12086+ err = get_user(sethi, (unsigned int *)regs->tpc);
12087+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12088+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12089+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
12090+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
12091+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
12092+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
12093+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
12094+
12095+ if (err)
12096+ break;
12097+
12098+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12099+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
12100+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12101+ (or1 & 0xFFFFE000U) == 0x82106000U &&
12102+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
12103+ sllx == 0x83287020U &&
12104+ jmpl == 0x81C04005U &&
12105+ nop == 0x01000000U)
12106+ {
12107+ unsigned long addr;
12108+
12109+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12110+ regs->u_regs[UREG_G1] <<= 32;
12111+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12112+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12113+ regs->tpc = addr;
12114+ regs->tnpc = addr+4;
12115+ return 2;
12116+ }
12117+ } while (0);
12118+
12119+ do { /* PaX: patched PLT emulation #6 */
12120+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
12121+
12122+ err = get_user(sethi, (unsigned int *)regs->tpc);
12123+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12124+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12125+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
12126+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
12127+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
12128+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
12129+
12130+ if (err)
12131+ break;
12132+
12133+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12134+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
12135+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12136+ sllx == 0x83287020U &&
12137+ (or & 0xFFFFE000U) == 0x8A116000U &&
12138+ jmpl == 0x81C04005U &&
12139+ nop == 0x01000000U)
12140+ {
12141+ unsigned long addr;
12142+
12143+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
12144+ regs->u_regs[UREG_G1] <<= 32;
12145+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
12146+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12147+ regs->tpc = addr;
12148+ regs->tnpc = addr+4;
12149+ return 2;
12150+ }
12151+ } while (0);
12152+
12153+ do { /* PaX: unpatched PLT emulation step 1 */
12154+ unsigned int sethi, ba, nop;
12155+
12156+ err = get_user(sethi, (unsigned int *)regs->tpc);
12157+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12158+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12159+
12160+ if (err)
12161+ break;
12162+
12163+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12164+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12165+ nop == 0x01000000U)
12166+ {
12167+ unsigned long addr;
12168+ unsigned int save, call;
12169+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
12170+
12171+ if ((ba & 0xFFC00000U) == 0x30800000U)
12172+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12173+ else
12174+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12175+
12176+ if (test_thread_flag(TIF_32BIT))
12177+ addr &= 0xFFFFFFFFUL;
12178+
12179+ err = get_user(save, (unsigned int *)addr);
12180+ err |= get_user(call, (unsigned int *)(addr+4));
12181+ err |= get_user(nop, (unsigned int *)(addr+8));
12182+ if (err)
12183+ break;
12184+
12185+#ifdef CONFIG_PAX_DLRESOLVE
12186+ if (save == 0x9DE3BFA8U &&
12187+ (call & 0xC0000000U) == 0x40000000U &&
12188+ nop == 0x01000000U)
12189+ {
12190+ struct vm_area_struct *vma;
12191+ unsigned long call_dl_resolve;
12192+
12193+ down_read(&current->mm->mmap_sem);
12194+ call_dl_resolve = current->mm->call_dl_resolve;
12195+ up_read(&current->mm->mmap_sem);
12196+ if (likely(call_dl_resolve))
12197+ goto emulate;
12198+
12199+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12200+
12201+ down_write(&current->mm->mmap_sem);
12202+ if (current->mm->call_dl_resolve) {
12203+ call_dl_resolve = current->mm->call_dl_resolve;
12204+ up_write(&current->mm->mmap_sem);
12205+ if (vma)
12206+ kmem_cache_free(vm_area_cachep, vma);
12207+ goto emulate;
12208+ }
12209+
12210+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12211+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12212+ up_write(&current->mm->mmap_sem);
12213+ if (vma)
12214+ kmem_cache_free(vm_area_cachep, vma);
12215+ return 1;
12216+ }
12217+
12218+ if (pax_insert_vma(vma, call_dl_resolve)) {
12219+ up_write(&current->mm->mmap_sem);
12220+ kmem_cache_free(vm_area_cachep, vma);
12221+ return 1;
12222+ }
12223+
12224+ current->mm->call_dl_resolve = call_dl_resolve;
12225+ up_write(&current->mm->mmap_sem);
12226+
12227+emulate:
12228+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12229+ regs->tpc = call_dl_resolve;
12230+ regs->tnpc = addr+4;
12231+ return 3;
12232+ }
12233+#endif
12234+
12235+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12236+ if ((save & 0xFFC00000U) == 0x05000000U &&
12237+ (call & 0xFFFFE000U) == 0x85C0A000U &&
12238+ nop == 0x01000000U)
12239+ {
12240+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12241+ regs->u_regs[UREG_G2] = addr + 4;
12242+ addr = (save & 0x003FFFFFU) << 10;
12243+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12244+
12245+ if (test_thread_flag(TIF_32BIT))
12246+ addr &= 0xFFFFFFFFUL;
12247+
12248+ regs->tpc = addr;
12249+ regs->tnpc = addr+4;
12250+ return 3;
12251+ }
12252+
12253+ /* PaX: 64-bit PLT stub */
12254+ err = get_user(sethi1, (unsigned int *)addr);
12255+ err |= get_user(sethi2, (unsigned int *)(addr+4));
12256+ err |= get_user(or1, (unsigned int *)(addr+8));
12257+ err |= get_user(or2, (unsigned int *)(addr+12));
12258+ err |= get_user(sllx, (unsigned int *)(addr+16));
12259+ err |= get_user(add, (unsigned int *)(addr+20));
12260+ err |= get_user(jmpl, (unsigned int *)(addr+24));
12261+ err |= get_user(nop, (unsigned int *)(addr+28));
12262+ if (err)
12263+ break;
12264+
12265+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12266+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12267+ (or1 & 0xFFFFE000U) == 0x88112000U &&
12268+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
12269+ sllx == 0x89293020U &&
12270+ add == 0x8A010005U &&
12271+ jmpl == 0x89C14000U &&
12272+ nop == 0x01000000U)
12273+ {
12274+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12275+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12276+ regs->u_regs[UREG_G4] <<= 32;
12277+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12278+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12279+ regs->u_regs[UREG_G4] = addr + 24;
12280+ addr = regs->u_regs[UREG_G5];
12281+ regs->tpc = addr;
12282+ regs->tnpc = addr+4;
12283+ return 3;
12284+ }
12285+ }
12286+ } while (0);
12287+
12288+#ifdef CONFIG_PAX_DLRESOLVE
12289+ do { /* PaX: unpatched PLT emulation step 2 */
12290+ unsigned int save, call, nop;
12291+
12292+ err = get_user(save, (unsigned int *)(regs->tpc-4));
12293+ err |= get_user(call, (unsigned int *)regs->tpc);
12294+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12295+ if (err)
12296+ break;
12297+
12298+ if (save == 0x9DE3BFA8U &&
12299+ (call & 0xC0000000U) == 0x40000000U &&
12300+ nop == 0x01000000U)
12301+ {
12302+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12303+
12304+ if (test_thread_flag(TIF_32BIT))
12305+ dl_resolve &= 0xFFFFFFFFUL;
12306+
12307+ regs->u_regs[UREG_RETPC] = regs->tpc;
12308+ regs->tpc = dl_resolve;
12309+ regs->tnpc = dl_resolve+4;
12310+ return 3;
12311+ }
12312+ } while (0);
12313+#endif
12314+
12315+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12316+ unsigned int sethi, ba, nop;
12317+
12318+ err = get_user(sethi, (unsigned int *)regs->tpc);
12319+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12320+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12321+
12322+ if (err)
12323+ break;
12324+
12325+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12326+ (ba & 0xFFF00000U) == 0x30600000U &&
12327+ nop == 0x01000000U)
12328+ {
12329+ unsigned long addr;
12330+
12331+ addr = (sethi & 0x003FFFFFU) << 10;
12332+ regs->u_regs[UREG_G1] = addr;
12333+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12334+
12335+ if (test_thread_flag(TIF_32BIT))
12336+ addr &= 0xFFFFFFFFUL;
12337+
12338+ regs->tpc = addr;
12339+ regs->tnpc = addr+4;
12340+ return 2;
12341+ }
12342+ } while (0);
12343+
12344+#endif
12345+
12346+ return 1;
12347+}
12348+
12349+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12350+{
12351+ unsigned long i;
12352+
12353+ printk(KERN_ERR "PAX: bytes at PC: ");
12354+ for (i = 0; i < 8; i++) {
12355+ unsigned int c;
12356+ if (get_user(c, (unsigned int *)pc+i))
12357+ printk(KERN_CONT "???????? ");
12358+ else
12359+ printk(KERN_CONT "%08x ", c);
12360+ }
12361+ printk("\n");
12362+}
12363+#endif
12364+
12365 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12366 {
12367 enum ctx_state prev_state = exception_enter();
12368@@ -350,6 +813,29 @@ retry:
12369 if (!vma)
12370 goto bad_area;
12371
12372+#ifdef CONFIG_PAX_PAGEEXEC
12373+ /* PaX: detect ITLB misses on non-exec pages */
12374+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12375+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12376+ {
12377+ if (address != regs->tpc)
12378+ goto good_area;
12379+
12380+ up_read(&mm->mmap_sem);
12381+ switch (pax_handle_fetch_fault(regs)) {
12382+
12383+#ifdef CONFIG_PAX_EMUPLT
12384+ case 2:
12385+ case 3:
12386+ return;
12387+#endif
12388+
12389+ }
12390+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12391+ do_group_exit(SIGKILL);
12392+ }
12393+#endif
12394+
12395 /* Pure DTLB misses do not tell us whether the fault causing
12396 * load/store/atomic was a write or not, it only says that there
12397 * was no match. So in such a case we (carefully) read the
12398diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12399index d329537..2c3746a 100644
12400--- a/arch/sparc/mm/hugetlbpage.c
12401+++ b/arch/sparc/mm/hugetlbpage.c
12402@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12403 unsigned long addr,
12404 unsigned long len,
12405 unsigned long pgoff,
12406- unsigned long flags)
12407+ unsigned long flags,
12408+ unsigned long offset)
12409 {
12410+ struct mm_struct *mm = current->mm;
12411 unsigned long task_size = TASK_SIZE;
12412 struct vm_unmapped_area_info info;
12413
12414@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12415
12416 info.flags = 0;
12417 info.length = len;
12418- info.low_limit = TASK_UNMAPPED_BASE;
12419+ info.low_limit = mm->mmap_base;
12420 info.high_limit = min(task_size, VA_EXCLUDE_START);
12421 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12422 info.align_offset = 0;
12423+ info.threadstack_offset = offset;
12424 addr = vm_unmapped_area(&info);
12425
12426 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12427 VM_BUG_ON(addr != -ENOMEM);
12428 info.low_limit = VA_EXCLUDE_END;
12429+
12430+#ifdef CONFIG_PAX_RANDMMAP
12431+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12432+ info.low_limit += mm->delta_mmap;
12433+#endif
12434+
12435 info.high_limit = task_size;
12436 addr = vm_unmapped_area(&info);
12437 }
12438@@ -55,7 +64,8 @@ static unsigned long
12439 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12440 const unsigned long len,
12441 const unsigned long pgoff,
12442- const unsigned long flags)
12443+ const unsigned long flags,
12444+ const unsigned long offset)
12445 {
12446 struct mm_struct *mm = current->mm;
12447 unsigned long addr = addr0;
12448@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12449 info.high_limit = mm->mmap_base;
12450 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12451 info.align_offset = 0;
12452+ info.threadstack_offset = offset;
12453 addr = vm_unmapped_area(&info);
12454
12455 /*
12456@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12457 VM_BUG_ON(addr != -ENOMEM);
12458 info.flags = 0;
12459 info.low_limit = TASK_UNMAPPED_BASE;
12460+
12461+#ifdef CONFIG_PAX_RANDMMAP
12462+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12463+ info.low_limit += mm->delta_mmap;
12464+#endif
12465+
12466 info.high_limit = STACK_TOP32;
12467 addr = vm_unmapped_area(&info);
12468 }
12469@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12470 struct mm_struct *mm = current->mm;
12471 struct vm_area_struct *vma;
12472 unsigned long task_size = TASK_SIZE;
12473+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12474
12475 if (test_thread_flag(TIF_32BIT))
12476 task_size = STACK_TOP32;
12477@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12478 return addr;
12479 }
12480
12481+#ifdef CONFIG_PAX_RANDMMAP
12482+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12483+#endif
12484+
12485 if (addr) {
12486 addr = ALIGN(addr, HPAGE_SIZE);
12487 vma = find_vma(mm, addr);
12488- if (task_size - len >= addr &&
12489- (!vma || addr + len <= vma->vm_start))
12490+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12491 return addr;
12492 }
12493 if (mm->get_unmapped_area == arch_get_unmapped_area)
12494 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12495- pgoff, flags);
12496+ pgoff, flags, offset);
12497 else
12498 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12499- pgoff, flags);
12500+ pgoff, flags, offset);
12501 }
12502
12503 pte_t *huge_pte_alloc(struct mm_struct *mm,
12504diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12505index 2cfb0f2..e917d9f 100644
12506--- a/arch/sparc/mm/init_64.c
12507+++ b/arch/sparc/mm/init_64.c
12508@@ -189,9 +189,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12509 int num_kernel_image_mappings;
12510
12511 #ifdef CONFIG_DEBUG_DCFLUSH
12512-atomic_t dcpage_flushes = ATOMIC_INIT(0);
12513+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12514 #ifdef CONFIG_SMP
12515-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12516+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12517 #endif
12518 #endif
12519
12520@@ -199,7 +199,7 @@ inline void flush_dcache_page_impl(struct page *page)
12521 {
12522 BUG_ON(tlb_type == hypervisor);
12523 #ifdef CONFIG_DEBUG_DCFLUSH
12524- atomic_inc(&dcpage_flushes);
12525+ atomic_inc_unchecked(&dcpage_flushes);
12526 #endif
12527
12528 #ifdef DCACHE_ALIASING_POSSIBLE
12529@@ -471,10 +471,10 @@ void mmu_info(struct seq_file *m)
12530
12531 #ifdef CONFIG_DEBUG_DCFLUSH
12532 seq_printf(m, "DCPageFlushes\t: %d\n",
12533- atomic_read(&dcpage_flushes));
12534+ atomic_read_unchecked(&dcpage_flushes));
12535 #ifdef CONFIG_SMP
12536 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12537- atomic_read(&dcpage_flushes_xcall));
12538+ atomic_read_unchecked(&dcpage_flushes_xcall));
12539 #endif /* CONFIG_SMP */
12540 #endif /* CONFIG_DEBUG_DCFLUSH */
12541 }
12542diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12543index 4f3006b..453f625f 100644
12544--- a/arch/tile/Kconfig
12545+++ b/arch/tile/Kconfig
12546@@ -192,6 +192,7 @@ source "kernel/Kconfig.hz"
12547
12548 config KEXEC
12549 bool "kexec system call"
12550+ depends on !GRKERNSEC_KMEM
12551 ---help---
12552 kexec is a system call that implements the ability to shutdown your
12553 current kernel, and to start another kernel. It is like a reboot
12554diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12555index 7b11c5f..755a026 100644
12556--- a/arch/tile/include/asm/atomic_64.h
12557+++ b/arch/tile/include/asm/atomic_64.h
12558@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12559
12560 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12561
12562+#define atomic64_read_unchecked(v) atomic64_read(v)
12563+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12564+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12565+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12566+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12567+#define atomic64_inc_unchecked(v) atomic64_inc(v)
12568+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12569+#define atomic64_dec_unchecked(v) atomic64_dec(v)
12570+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12571+
12572 /* Define this to indicate that cmpxchg is an efficient operation. */
12573 #define __HAVE_ARCH_CMPXCHG
12574
12575diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12576index 6160761..00cac88 100644
12577--- a/arch/tile/include/asm/cache.h
12578+++ b/arch/tile/include/asm/cache.h
12579@@ -15,11 +15,12 @@
12580 #ifndef _ASM_TILE_CACHE_H
12581 #define _ASM_TILE_CACHE_H
12582
12583+#include <linux/const.h>
12584 #include <arch/chip.h>
12585
12586 /* bytes per L1 data cache line */
12587 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12588-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12589+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12590
12591 /* bytes per L2 cache line */
12592 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12593diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12594index b6cde32..c0cb736 100644
12595--- a/arch/tile/include/asm/uaccess.h
12596+++ b/arch/tile/include/asm/uaccess.h
12597@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12598 const void __user *from,
12599 unsigned long n)
12600 {
12601- int sz = __compiletime_object_size(to);
12602+ size_t sz = __compiletime_object_size(to);
12603
12604- if (likely(sz == -1 || sz >= n))
12605+ if (likely(sz == (size_t)-1 || sz >= n))
12606 n = _copy_from_user(to, from, n);
12607 else
12608 copy_from_user_overflow();
12609diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12610index e514899..f8743c4 100644
12611--- a/arch/tile/mm/hugetlbpage.c
12612+++ b/arch/tile/mm/hugetlbpage.c
12613@@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12614 info.high_limit = TASK_SIZE;
12615 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12616 info.align_offset = 0;
12617+ info.threadstack_offset = 0;
12618 return vm_unmapped_area(&info);
12619 }
12620
12621@@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12622 info.high_limit = current->mm->mmap_base;
12623 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12624 info.align_offset = 0;
12625+ info.threadstack_offset = 0;
12626 addr = vm_unmapped_area(&info);
12627
12628 /*
12629diff --git a/arch/um/Makefile b/arch/um/Makefile
12630index e4b1a96..16162f8 100644
12631--- a/arch/um/Makefile
12632+++ b/arch/um/Makefile
12633@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12634 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12635 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12636
12637+ifdef CONSTIFY_PLUGIN
12638+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12639+endif
12640+
12641 #This will adjust *FLAGS accordingly to the platform.
12642 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12643
12644diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12645index 19e1bdd..3665b77 100644
12646--- a/arch/um/include/asm/cache.h
12647+++ b/arch/um/include/asm/cache.h
12648@@ -1,6 +1,7 @@
12649 #ifndef __UM_CACHE_H
12650 #define __UM_CACHE_H
12651
12652+#include <linux/const.h>
12653
12654 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12655 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12656@@ -12,6 +13,6 @@
12657 # define L1_CACHE_SHIFT 5
12658 #endif
12659
12660-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12661+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12662
12663 #endif
12664diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12665index 2e0a6b1..a64d0f5 100644
12666--- a/arch/um/include/asm/kmap_types.h
12667+++ b/arch/um/include/asm/kmap_types.h
12668@@ -8,6 +8,6 @@
12669
12670 /* No more #include "asm/arch/kmap_types.h" ! */
12671
12672-#define KM_TYPE_NR 14
12673+#define KM_TYPE_NR 15
12674
12675 #endif
12676diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12677index 5ff53d9..5850cdf 100644
12678--- a/arch/um/include/asm/page.h
12679+++ b/arch/um/include/asm/page.h
12680@@ -14,6 +14,9 @@
12681 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12682 #define PAGE_MASK (~(PAGE_SIZE-1))
12683
12684+#define ktla_ktva(addr) (addr)
12685+#define ktva_ktla(addr) (addr)
12686+
12687 #ifndef __ASSEMBLY__
12688
12689 struct page;
12690diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12691index 0032f92..cd151e0 100644
12692--- a/arch/um/include/asm/pgtable-3level.h
12693+++ b/arch/um/include/asm/pgtable-3level.h
12694@@ -58,6 +58,7 @@
12695 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12696 #define pud_populate(mm, pud, pmd) \
12697 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12698+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12699
12700 #ifdef CONFIG_64BIT
12701 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12702diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12703index f17bca8..48adb87 100644
12704--- a/arch/um/kernel/process.c
12705+++ b/arch/um/kernel/process.c
12706@@ -356,22 +356,6 @@ int singlestepping(void * t)
12707 return 2;
12708 }
12709
12710-/*
12711- * Only x86 and x86_64 have an arch_align_stack().
12712- * All other arches have "#define arch_align_stack(x) (x)"
12713- * in their asm/exec.h
12714- * As this is included in UML from asm-um/system-generic.h,
12715- * we can use it to behave as the subarch does.
12716- */
12717-#ifndef arch_align_stack
12718-unsigned long arch_align_stack(unsigned long sp)
12719-{
12720- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12721- sp -= get_random_int() % 8192;
12722- return sp & ~0xf;
12723-}
12724-#endif
12725-
12726 unsigned long get_wchan(struct task_struct *p)
12727 {
12728 unsigned long stack_page, sp, ip;
12729diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12730index ad8f795..2c7eec6 100644
12731--- a/arch/unicore32/include/asm/cache.h
12732+++ b/arch/unicore32/include/asm/cache.h
12733@@ -12,8 +12,10 @@
12734 #ifndef __UNICORE_CACHE_H__
12735 #define __UNICORE_CACHE_H__
12736
12737-#define L1_CACHE_SHIFT (5)
12738-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12739+#include <linux/const.h>
12740+
12741+#define L1_CACHE_SHIFT 5
12742+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12743
12744 /*
12745 * Memory returned by kmalloc() may be used for DMA, so we must make
12746diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12747index d24887b..267d526 100644
12748--- a/arch/x86/Kconfig
12749+++ b/arch/x86/Kconfig
12750@@ -128,7 +128,7 @@ config X86
12751 select RTC_LIB
12752 select HAVE_DEBUG_STACKOVERFLOW
12753 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12754- select HAVE_CC_STACKPROTECTOR
12755+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12756 select GENERIC_CPU_AUTOPROBE
12757 select HAVE_ARCH_AUDITSYSCALL
12758 select ARCH_SUPPORTS_ATOMIC_RMW
12759@@ -253,7 +253,7 @@ config X86_HT
12760
12761 config X86_32_LAZY_GS
12762 def_bool y
12763- depends on X86_32 && !CC_STACKPROTECTOR
12764+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12765
12766 config ARCH_HWEIGHT_CFLAGS
12767 string
12768@@ -549,6 +549,7 @@ config SCHED_OMIT_FRAME_POINTER
12769
12770 menuconfig HYPERVISOR_GUEST
12771 bool "Linux guest support"
12772+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12773 ---help---
12774 Say Y here to enable options for running Linux under various hyper-
12775 visors. This option enables basic hypervisor detection and platform
12776@@ -1076,6 +1077,7 @@ choice
12777
12778 config NOHIGHMEM
12779 bool "off"
12780+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12781 ---help---
12782 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12783 However, the address space of 32-bit x86 processors is only 4
12784@@ -1112,6 +1114,7 @@ config NOHIGHMEM
12785
12786 config HIGHMEM4G
12787 bool "4GB"
12788+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12789 ---help---
12790 Select this if you have a 32-bit processor and between 1 and 4
12791 gigabytes of physical RAM.
12792@@ -1164,7 +1167,7 @@ config PAGE_OFFSET
12793 hex
12794 default 0xB0000000 if VMSPLIT_3G_OPT
12795 default 0x80000000 if VMSPLIT_2G
12796- default 0x78000000 if VMSPLIT_2G_OPT
12797+ default 0x70000000 if VMSPLIT_2G_OPT
12798 default 0x40000000 if VMSPLIT_1G
12799 default 0xC0000000
12800 depends on X86_32
12801@@ -1577,6 +1580,7 @@ source kernel/Kconfig.hz
12802
12803 config KEXEC
12804 bool "kexec system call"
12805+ depends on !GRKERNSEC_KMEM
12806 ---help---
12807 kexec is a system call that implements the ability to shutdown your
12808 current kernel, and to start another kernel. It is like a reboot
12809@@ -1727,7 +1731,9 @@ config X86_NEED_RELOCS
12810
12811 config PHYSICAL_ALIGN
12812 hex "Alignment value to which kernel should be aligned"
12813- default "0x200000"
12814+ default "0x1000000"
12815+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12816+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12817 range 0x2000 0x1000000 if X86_32
12818 range 0x200000 0x1000000 if X86_64
12819 ---help---
12820@@ -1810,6 +1816,7 @@ config COMPAT_VDSO
12821 def_bool n
12822 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12823 depends on X86_32 || IA32_EMULATION
12824+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12825 ---help---
12826 Certain buggy versions of glibc will crash if they are
12827 presented with a 32-bit vDSO that is not mapped at the address
12828diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12829index 6983314..54ad7e8 100644
12830--- a/arch/x86/Kconfig.cpu
12831+++ b/arch/x86/Kconfig.cpu
12832@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12833
12834 config X86_F00F_BUG
12835 def_bool y
12836- depends on M586MMX || M586TSC || M586 || M486
12837+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12838
12839 config X86_INVD_BUG
12840 def_bool y
12841@@ -327,7 +327,7 @@ config X86_INVD_BUG
12842
12843 config X86_ALIGNMENT_16
12844 def_bool y
12845- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12846+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12847
12848 config X86_INTEL_USERCOPY
12849 def_bool y
12850@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12851 # generates cmov.
12852 config X86_CMOV
12853 def_bool y
12854- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12855+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12856
12857 config X86_MINIMUM_CPU_FAMILY
12858 int
12859diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12860index 61bd2ad..50b625d 100644
12861--- a/arch/x86/Kconfig.debug
12862+++ b/arch/x86/Kconfig.debug
12863@@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12864 config DEBUG_RODATA
12865 bool "Write protect kernel read-only data structures"
12866 default y
12867- depends on DEBUG_KERNEL
12868+ depends on DEBUG_KERNEL && BROKEN
12869 ---help---
12870 Mark the kernel read-only data as write-protected in the pagetables,
12871 in order to catch accidental (and incorrect) writes to such const
12872@@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12873
12874 config DEBUG_SET_MODULE_RONX
12875 bool "Set loadable kernel module data as NX and text as RO"
12876- depends on MODULES
12877+ depends on MODULES && BROKEN
12878 ---help---
12879 This option helps catch unintended modifications to loadable
12880 kernel module's text and read-only data. It also prevents execution
12881diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12882index 33f71b0..c2cefa2 100644
12883--- a/arch/x86/Makefile
12884+++ b/arch/x86/Makefile
12885@@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12886 # CPU-specific tuning. Anything which can be shared with UML should go here.
12887 include $(srctree)/arch/x86/Makefile_32.cpu
12888 KBUILD_CFLAGS += $(cflags-y)
12889-
12890- # temporary until string.h is fixed
12891- KBUILD_CFLAGS += -ffreestanding
12892 else
12893 BITS := 64
12894 UTS_MACHINE := x86_64
12895@@ -114,6 +111,9 @@ else
12896 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12897 endif
12898
12899+# temporary until string.h is fixed
12900+KBUILD_CFLAGS += -ffreestanding
12901+
12902 # Make sure compiler does not have buggy stack-protector support.
12903 ifdef CONFIG_CC_STACKPROTECTOR
12904 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12905@@ -271,3 +271,12 @@ define archhelp
12906 echo ' FDINITRD=file initrd for the booted kernel'
12907 echo ' kvmconfig - Enable additional options for guest kernel support'
12908 endef
12909+
12910+define OLD_LD
12911+
12912+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12913+*** Please upgrade your binutils to 2.18 or newer
12914+endef
12915+
12916+archprepare:
12917+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12918diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12919index dbe8dd2..2f0a98f 100644
12920--- a/arch/x86/boot/Makefile
12921+++ b/arch/x86/boot/Makefile
12922@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12923 # ---------------------------------------------------------------------------
12924
12925 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12926+ifdef CONSTIFY_PLUGIN
12927+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12928+endif
12929 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12930 GCOV_PROFILE := n
12931
12932diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12933index 878e4b9..20537ab 100644
12934--- a/arch/x86/boot/bitops.h
12935+++ b/arch/x86/boot/bitops.h
12936@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12937 u8 v;
12938 const u32 *p = (const u32 *)addr;
12939
12940- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12941+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12942 return v;
12943 }
12944
12945@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12946
12947 static inline void set_bit(int nr, void *addr)
12948 {
12949- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12950+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12951 }
12952
12953 #endif /* BOOT_BITOPS_H */
12954diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12955index bd49ec6..94c7f58 100644
12956--- a/arch/x86/boot/boot.h
12957+++ b/arch/x86/boot/boot.h
12958@@ -84,7 +84,7 @@ static inline void io_delay(void)
12959 static inline u16 ds(void)
12960 {
12961 u16 seg;
12962- asm("movw %%ds,%0" : "=rm" (seg));
12963+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12964 return seg;
12965 }
12966
12967diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12968index 0fcd913..3bb5c42 100644
12969--- a/arch/x86/boot/compressed/Makefile
12970+++ b/arch/x86/boot/compressed/Makefile
12971@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12972 KBUILD_CFLAGS += -mno-mmx -mno-sse
12973 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12974 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12975+ifdef CONSTIFY_PLUGIN
12976+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12977+endif
12978
12979 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12980 GCOV_PROFILE := n
12981diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12982index a53440e..c3dbf1e 100644
12983--- a/arch/x86/boot/compressed/efi_stub_32.S
12984+++ b/arch/x86/boot/compressed/efi_stub_32.S
12985@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12986 * parameter 2, ..., param n. To make things easy, we save the return
12987 * address of efi_call_phys in a global variable.
12988 */
12989- popl %ecx
12990- movl %ecx, saved_return_addr(%edx)
12991- /* get the function pointer into ECX*/
12992- popl %ecx
12993- movl %ecx, efi_rt_function_ptr(%edx)
12994+ popl saved_return_addr(%edx)
12995+ popl efi_rt_function_ptr(%edx)
12996
12997 /*
12998 * 3. Call the physical function.
12999 */
13000- call *%ecx
13001+ call *efi_rt_function_ptr(%edx)
13002
13003 /*
13004 * 4. Balance the stack. And because EAX contain the return value,
13005@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
13006 1: popl %edx
13007 subl $1b, %edx
13008
13009- movl efi_rt_function_ptr(%edx), %ecx
13010- pushl %ecx
13011+ pushl efi_rt_function_ptr(%edx)
13012
13013 /*
13014 * 10. Push the saved return address onto the stack and return.
13015 */
13016- movl saved_return_addr(%edx), %ecx
13017- pushl %ecx
13018- ret
13019+ jmpl *saved_return_addr(%edx)
13020 ENDPROC(efi_call_phys)
13021 .previous
13022
13023diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
13024index cbed140..5f2ca57 100644
13025--- a/arch/x86/boot/compressed/head_32.S
13026+++ b/arch/x86/boot/compressed/head_32.S
13027@@ -140,10 +140,10 @@ preferred_addr:
13028 addl %eax, %ebx
13029 notl %eax
13030 andl %eax, %ebx
13031- cmpl $LOAD_PHYSICAL_ADDR, %ebx
13032+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13033 jge 1f
13034 #endif
13035- movl $LOAD_PHYSICAL_ADDR, %ebx
13036+ movl $____LOAD_PHYSICAL_ADDR, %ebx
13037 1:
13038
13039 /* Target address to relocate to for decompression */
13040diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
13041index 2884e0c..904a2f7 100644
13042--- a/arch/x86/boot/compressed/head_64.S
13043+++ b/arch/x86/boot/compressed/head_64.S
13044@@ -94,10 +94,10 @@ ENTRY(startup_32)
13045 addl %eax, %ebx
13046 notl %eax
13047 andl %eax, %ebx
13048- cmpl $LOAD_PHYSICAL_ADDR, %ebx
13049+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13050 jge 1f
13051 #endif
13052- movl $LOAD_PHYSICAL_ADDR, %ebx
13053+ movl $____LOAD_PHYSICAL_ADDR, %ebx
13054 1:
13055
13056 /* Target address to relocate to for decompression */
13057@@ -322,10 +322,10 @@ preferred_addr:
13058 addq %rax, %rbp
13059 notq %rax
13060 andq %rax, %rbp
13061- cmpq $LOAD_PHYSICAL_ADDR, %rbp
13062+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
13063 jge 1f
13064 #endif
13065- movq $LOAD_PHYSICAL_ADDR, %rbp
13066+ movq $____LOAD_PHYSICAL_ADDR, %rbp
13067 1:
13068
13069 /* Target address to relocate to for decompression */
13070@@ -431,8 +431,8 @@ gdt:
13071 .long gdt
13072 .word 0
13073 .quad 0x0000000000000000 /* NULL descriptor */
13074- .quad 0x00af9a000000ffff /* __KERNEL_CS */
13075- .quad 0x00cf92000000ffff /* __KERNEL_DS */
13076+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
13077+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
13078 .quad 0x0080890000000000 /* TS descriptor */
13079 .quad 0x0000000000000000 /* TS continued */
13080 gdt_end:
13081diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
13082index 57ab74d..7c52182 100644
13083--- a/arch/x86/boot/compressed/misc.c
13084+++ b/arch/x86/boot/compressed/misc.c
13085@@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
13086 * Calculate the delta between where vmlinux was linked to load
13087 * and where it was actually loaded.
13088 */
13089- delta = min_addr - LOAD_PHYSICAL_ADDR;
13090+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
13091 if (!delta) {
13092 debug_putstr("No relocation needed... ");
13093 return;
13094@@ -312,7 +312,7 @@ static void parse_elf(void *output)
13095 Elf32_Ehdr ehdr;
13096 Elf32_Phdr *phdrs, *phdr;
13097 #endif
13098- void *dest;
13099+ void *dest, *prev;
13100 int i;
13101
13102 memcpy(&ehdr, output, sizeof(ehdr));
13103@@ -339,13 +339,16 @@ static void parse_elf(void *output)
13104 case PT_LOAD:
13105 #ifdef CONFIG_RELOCATABLE
13106 dest = output;
13107- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
13108+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
13109 #else
13110 dest = (void *)(phdr->p_paddr);
13111 #endif
13112 memcpy(dest,
13113 output + phdr->p_offset,
13114 phdr->p_filesz);
13115+ if (i)
13116+ memset(prev, 0xff, dest - prev);
13117+ prev = dest + phdr->p_filesz;
13118 break;
13119 default: /* Ignore other PT_* */ break;
13120 }
13121@@ -395,7 +398,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
13122 error("Destination address too large");
13123 #endif
13124 #ifndef CONFIG_RELOCATABLE
13125- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
13126+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
13127 error("Wrong destination address");
13128 #endif
13129
13130diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
13131index 1fd7d57..0f7d096 100644
13132--- a/arch/x86/boot/cpucheck.c
13133+++ b/arch/x86/boot/cpucheck.c
13134@@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13135 u32 ecx = MSR_K7_HWCR;
13136 u32 eax, edx;
13137
13138- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13139+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13140 eax &= ~(1 << 15);
13141- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13142+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13143
13144 get_cpuflags(); /* Make sure it really did something */
13145 err = check_cpuflags();
13146@@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13147 u32 ecx = MSR_VIA_FCR;
13148 u32 eax, edx;
13149
13150- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13151+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13152 eax |= (1<<1)|(1<<7);
13153- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13154+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13155
13156 set_bit(X86_FEATURE_CX8, cpu.flags);
13157 err = check_cpuflags();
13158@@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13159 u32 eax, edx;
13160 u32 level = 1;
13161
13162- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13163- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13164- asm("cpuid"
13165+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13166+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13167+ asm volatile("cpuid"
13168 : "+a" (level), "=d" (cpu.flags[0])
13169 : : "ecx", "ebx");
13170- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13171+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13172
13173 err = check_cpuflags();
13174 } else if (err == 0x01 &&
13175diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13176index 7a6d43a..edf6e40 100644
13177--- a/arch/x86/boot/header.S
13178+++ b/arch/x86/boot/header.S
13179@@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13180 # single linked list of
13181 # struct setup_data
13182
13183-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13184+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13185
13186 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13187+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13188+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13189+#else
13190 #define VO_INIT_SIZE (VO__end - VO__text)
13191+#endif
13192 #if ZO_INIT_SIZE > VO_INIT_SIZE
13193 #define INIT_SIZE ZO_INIT_SIZE
13194 #else
13195diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13196index db75d07..8e6d0af 100644
13197--- a/arch/x86/boot/memory.c
13198+++ b/arch/x86/boot/memory.c
13199@@ -19,7 +19,7 @@
13200
13201 static int detect_memory_e820(void)
13202 {
13203- int count = 0;
13204+ unsigned int count = 0;
13205 struct biosregs ireg, oreg;
13206 struct e820entry *desc = boot_params.e820_map;
13207 static struct e820entry buf; /* static so it is zeroed */
13208diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13209index ba3e100..6501b8f 100644
13210--- a/arch/x86/boot/video-vesa.c
13211+++ b/arch/x86/boot/video-vesa.c
13212@@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13213
13214 boot_params.screen_info.vesapm_seg = oreg.es;
13215 boot_params.screen_info.vesapm_off = oreg.di;
13216+ boot_params.screen_info.vesapm_size = oreg.cx;
13217 }
13218
13219 /*
13220diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13221index 43eda28..5ab5fdb 100644
13222--- a/arch/x86/boot/video.c
13223+++ b/arch/x86/boot/video.c
13224@@ -96,7 +96,7 @@ static void store_mode_params(void)
13225 static unsigned int get_entry(void)
13226 {
13227 char entry_buf[4];
13228- int i, len = 0;
13229+ unsigned int i, len = 0;
13230 int key;
13231 unsigned int v;
13232
13233diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13234index 9105655..41779c1 100644
13235--- a/arch/x86/crypto/aes-x86_64-asm_64.S
13236+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13237@@ -8,6 +8,8 @@
13238 * including this sentence is retained in full.
13239 */
13240
13241+#include <asm/alternative-asm.h>
13242+
13243 .extern crypto_ft_tab
13244 .extern crypto_it_tab
13245 .extern crypto_fl_tab
13246@@ -70,6 +72,8 @@
13247 je B192; \
13248 leaq 32(r9),r9;
13249
13250+#define ret pax_force_retaddr; ret
13251+
13252 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13253 movq r1,r2; \
13254 movq r3,r4; \
13255diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13256index 477e9d7..c92c7d8 100644
13257--- a/arch/x86/crypto/aesni-intel_asm.S
13258+++ b/arch/x86/crypto/aesni-intel_asm.S
13259@@ -31,6 +31,7 @@
13260
13261 #include <linux/linkage.h>
13262 #include <asm/inst.h>
13263+#include <asm/alternative-asm.h>
13264
13265 #ifdef __x86_64__
13266 .data
13267@@ -205,7 +206,7 @@ enc: .octa 0x2
13268 * num_initial_blocks = b mod 4
13269 * encrypt the initial num_initial_blocks blocks and apply ghash on
13270 * the ciphertext
13271-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13272+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13273 * are clobbered
13274 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13275 */
13276@@ -214,8 +215,8 @@ enc: .octa 0x2
13277 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13278 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13279 mov arg7, %r10 # %r10 = AAD
13280- mov arg8, %r12 # %r12 = aadLen
13281- mov %r12, %r11
13282+ mov arg8, %r15 # %r15 = aadLen
13283+ mov %r15, %r11
13284 pxor %xmm\i, %xmm\i
13285 _get_AAD_loop\num_initial_blocks\operation:
13286 movd (%r10), \TMP1
13287@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13288 psrldq $4, %xmm\i
13289 pxor \TMP1, %xmm\i
13290 add $4, %r10
13291- sub $4, %r12
13292+ sub $4, %r15
13293 jne _get_AAD_loop\num_initial_blocks\operation
13294 cmp $16, %r11
13295 je _get_AAD_loop2_done\num_initial_blocks\operation
13296- mov $16, %r12
13297+ mov $16, %r15
13298 _get_AAD_loop2\num_initial_blocks\operation:
13299 psrldq $4, %xmm\i
13300- sub $4, %r12
13301- cmp %r11, %r12
13302+ sub $4, %r15
13303+ cmp %r11, %r15
13304 jne _get_AAD_loop2\num_initial_blocks\operation
13305 _get_AAD_loop2_done\num_initial_blocks\operation:
13306 movdqa SHUF_MASK(%rip), %xmm14
13307@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13308 * num_initial_blocks = b mod 4
13309 * encrypt the initial num_initial_blocks blocks and apply ghash on
13310 * the ciphertext
13311-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13312+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13313 * are clobbered
13314 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13315 */
13316@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13317 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13318 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13319 mov arg7, %r10 # %r10 = AAD
13320- mov arg8, %r12 # %r12 = aadLen
13321- mov %r12, %r11
13322+ mov arg8, %r15 # %r15 = aadLen
13323+ mov %r15, %r11
13324 pxor %xmm\i, %xmm\i
13325 _get_AAD_loop\num_initial_blocks\operation:
13326 movd (%r10), \TMP1
13327@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13328 psrldq $4, %xmm\i
13329 pxor \TMP1, %xmm\i
13330 add $4, %r10
13331- sub $4, %r12
13332+ sub $4, %r15
13333 jne _get_AAD_loop\num_initial_blocks\operation
13334 cmp $16, %r11
13335 je _get_AAD_loop2_done\num_initial_blocks\operation
13336- mov $16, %r12
13337+ mov $16, %r15
13338 _get_AAD_loop2\num_initial_blocks\operation:
13339 psrldq $4, %xmm\i
13340- sub $4, %r12
13341- cmp %r11, %r12
13342+ sub $4, %r15
13343+ cmp %r11, %r15
13344 jne _get_AAD_loop2\num_initial_blocks\operation
13345 _get_AAD_loop2_done\num_initial_blocks\operation:
13346 movdqa SHUF_MASK(%rip), %xmm14
13347@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13348 *
13349 *****************************************************************************/
13350 ENTRY(aesni_gcm_dec)
13351- push %r12
13352+ push %r15
13353 push %r13
13354 push %r14
13355 mov %rsp, %r14
13356@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13357 */
13358 sub $VARIABLE_OFFSET, %rsp
13359 and $~63, %rsp # align rsp to 64 bytes
13360- mov %arg6, %r12
13361- movdqu (%r12), %xmm13 # %xmm13 = HashKey
13362+ mov %arg6, %r15
13363+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
13364 movdqa SHUF_MASK(%rip), %xmm2
13365 PSHUFB_XMM %xmm2, %xmm13
13366
13367@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13368 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13369 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13370 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13371- mov %r13, %r12
13372- and $(3<<4), %r12
13373+ mov %r13, %r15
13374+ and $(3<<4), %r15
13375 jz _initial_num_blocks_is_0_decrypt
13376- cmp $(2<<4), %r12
13377+ cmp $(2<<4), %r15
13378 jb _initial_num_blocks_is_1_decrypt
13379 je _initial_num_blocks_is_2_decrypt
13380 _initial_num_blocks_is_3_decrypt:
13381@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13382 sub $16, %r11
13383 add %r13, %r11
13384 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13385- lea SHIFT_MASK+16(%rip), %r12
13386- sub %r13, %r12
13387+ lea SHIFT_MASK+16(%rip), %r15
13388+ sub %r13, %r15
13389 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13390 # (%r13 is the number of bytes in plaintext mod 16)
13391- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13392+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13393 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13394
13395 movdqa %xmm1, %xmm2
13396 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13397- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13398+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13399 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13400 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13401 pand %xmm1, %xmm2
13402@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13403 sub $1, %r13
13404 jne _less_than_8_bytes_left_decrypt
13405 _multiple_of_16_bytes_decrypt:
13406- mov arg8, %r12 # %r13 = aadLen (number of bytes)
13407- shl $3, %r12 # convert into number of bits
13408- movd %r12d, %xmm15 # len(A) in %xmm15
13409+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
13410+ shl $3, %r15 # convert into number of bits
13411+ movd %r15d, %xmm15 # len(A) in %xmm15
13412 shl $3, %arg4 # len(C) in bits (*128)
13413 MOVQ_R64_XMM %arg4, %xmm1
13414 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13415@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13416 mov %r14, %rsp
13417 pop %r14
13418 pop %r13
13419- pop %r12
13420+ pop %r15
13421+ pax_force_retaddr
13422 ret
13423 ENDPROC(aesni_gcm_dec)
13424
13425@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13426 * poly = x^128 + x^127 + x^126 + x^121 + 1
13427 ***************************************************************************/
13428 ENTRY(aesni_gcm_enc)
13429- push %r12
13430+ push %r15
13431 push %r13
13432 push %r14
13433 mov %rsp, %r14
13434@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13435 #
13436 sub $VARIABLE_OFFSET, %rsp
13437 and $~63, %rsp
13438- mov %arg6, %r12
13439- movdqu (%r12), %xmm13
13440+ mov %arg6, %r15
13441+ movdqu (%r15), %xmm13
13442 movdqa SHUF_MASK(%rip), %xmm2
13443 PSHUFB_XMM %xmm2, %xmm13
13444
13445@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13446 movdqa %xmm13, HashKey(%rsp)
13447 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13448 and $-16, %r13
13449- mov %r13, %r12
13450+ mov %r13, %r15
13451
13452 # Encrypt first few blocks
13453
13454- and $(3<<4), %r12
13455+ and $(3<<4), %r15
13456 jz _initial_num_blocks_is_0_encrypt
13457- cmp $(2<<4), %r12
13458+ cmp $(2<<4), %r15
13459 jb _initial_num_blocks_is_1_encrypt
13460 je _initial_num_blocks_is_2_encrypt
13461 _initial_num_blocks_is_3_encrypt:
13462@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13463 sub $16, %r11
13464 add %r13, %r11
13465 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13466- lea SHIFT_MASK+16(%rip), %r12
13467- sub %r13, %r12
13468+ lea SHIFT_MASK+16(%rip), %r15
13469+ sub %r13, %r15
13470 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13471 # (%r13 is the number of bytes in plaintext mod 16)
13472- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13473+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13474 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13475 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13476- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13477+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13478 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13479 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13480 movdqa SHUF_MASK(%rip), %xmm10
13481@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13482 sub $1, %r13
13483 jne _less_than_8_bytes_left_encrypt
13484 _multiple_of_16_bytes_encrypt:
13485- mov arg8, %r12 # %r12 = addLen (number of bytes)
13486- shl $3, %r12
13487- movd %r12d, %xmm15 # len(A) in %xmm15
13488+ mov arg8, %r15 # %r15 = addLen (number of bytes)
13489+ shl $3, %r15
13490+ movd %r15d, %xmm15 # len(A) in %xmm15
13491 shl $3, %arg4 # len(C) in bits (*128)
13492 MOVQ_R64_XMM %arg4, %xmm1
13493 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13494@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13495 mov %r14, %rsp
13496 pop %r14
13497 pop %r13
13498- pop %r12
13499+ pop %r15
13500+ pax_force_retaddr
13501 ret
13502 ENDPROC(aesni_gcm_enc)
13503
13504@@ -1722,6 +1725,7 @@ _key_expansion_256a:
13505 pxor %xmm1, %xmm0
13506 movaps %xmm0, (TKEYP)
13507 add $0x10, TKEYP
13508+ pax_force_retaddr
13509 ret
13510 ENDPROC(_key_expansion_128)
13511 ENDPROC(_key_expansion_256a)
13512@@ -1748,6 +1752,7 @@ _key_expansion_192a:
13513 shufps $0b01001110, %xmm2, %xmm1
13514 movaps %xmm1, 0x10(TKEYP)
13515 add $0x20, TKEYP
13516+ pax_force_retaddr
13517 ret
13518 ENDPROC(_key_expansion_192a)
13519
13520@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13521
13522 movaps %xmm0, (TKEYP)
13523 add $0x10, TKEYP
13524+ pax_force_retaddr
13525 ret
13526 ENDPROC(_key_expansion_192b)
13527
13528@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13529 pxor %xmm1, %xmm2
13530 movaps %xmm2, (TKEYP)
13531 add $0x10, TKEYP
13532+ pax_force_retaddr
13533 ret
13534 ENDPROC(_key_expansion_256b)
13535
13536@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13537 #ifndef __x86_64__
13538 popl KEYP
13539 #endif
13540+ pax_force_retaddr
13541 ret
13542 ENDPROC(aesni_set_key)
13543
13544@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13545 popl KLEN
13546 popl KEYP
13547 #endif
13548+ pax_force_retaddr
13549 ret
13550 ENDPROC(aesni_enc)
13551
13552@@ -1974,6 +1983,7 @@ _aesni_enc1:
13553 AESENC KEY STATE
13554 movaps 0x70(TKEYP), KEY
13555 AESENCLAST KEY STATE
13556+ pax_force_retaddr
13557 ret
13558 ENDPROC(_aesni_enc1)
13559
13560@@ -2083,6 +2093,7 @@ _aesni_enc4:
13561 AESENCLAST KEY STATE2
13562 AESENCLAST KEY STATE3
13563 AESENCLAST KEY STATE4
13564+ pax_force_retaddr
13565 ret
13566 ENDPROC(_aesni_enc4)
13567
13568@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13569 popl KLEN
13570 popl KEYP
13571 #endif
13572+ pax_force_retaddr
13573 ret
13574 ENDPROC(aesni_dec)
13575
13576@@ -2164,6 +2176,7 @@ _aesni_dec1:
13577 AESDEC KEY STATE
13578 movaps 0x70(TKEYP), KEY
13579 AESDECLAST KEY STATE
13580+ pax_force_retaddr
13581 ret
13582 ENDPROC(_aesni_dec1)
13583
13584@@ -2273,6 +2286,7 @@ _aesni_dec4:
13585 AESDECLAST KEY STATE2
13586 AESDECLAST KEY STATE3
13587 AESDECLAST KEY STATE4
13588+ pax_force_retaddr
13589 ret
13590 ENDPROC(_aesni_dec4)
13591
13592@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13593 popl KEYP
13594 popl LEN
13595 #endif
13596+ pax_force_retaddr
13597 ret
13598 ENDPROC(aesni_ecb_enc)
13599
13600@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13601 popl KEYP
13602 popl LEN
13603 #endif
13604+ pax_force_retaddr
13605 ret
13606 ENDPROC(aesni_ecb_dec)
13607
13608@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13609 popl LEN
13610 popl IVP
13611 #endif
13612+ pax_force_retaddr
13613 ret
13614 ENDPROC(aesni_cbc_enc)
13615
13616@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13617 popl LEN
13618 popl IVP
13619 #endif
13620+ pax_force_retaddr
13621 ret
13622 ENDPROC(aesni_cbc_dec)
13623
13624@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13625 mov $1, TCTR_LOW
13626 MOVQ_R64_XMM TCTR_LOW INC
13627 MOVQ_R64_XMM CTR TCTR_LOW
13628+ pax_force_retaddr
13629 ret
13630 ENDPROC(_aesni_inc_init)
13631
13632@@ -2579,6 +2598,7 @@ _aesni_inc:
13633 .Linc_low:
13634 movaps CTR, IV
13635 PSHUFB_XMM BSWAP_MASK IV
13636+ pax_force_retaddr
13637 ret
13638 ENDPROC(_aesni_inc)
13639
13640@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13641 .Lctr_enc_ret:
13642 movups IV, (IVP)
13643 .Lctr_enc_just_ret:
13644+ pax_force_retaddr
13645 ret
13646 ENDPROC(aesni_ctr_enc)
13647
13648@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13649 pxor INC, STATE4
13650 movdqu STATE4, 0x70(OUTP)
13651
13652+ pax_force_retaddr
13653 ret
13654 ENDPROC(aesni_xts_crypt8)
13655
13656diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13657index 246c670..466e2d6 100644
13658--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13659+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13660@@ -21,6 +21,7 @@
13661 */
13662
13663 #include <linux/linkage.h>
13664+#include <asm/alternative-asm.h>
13665
13666 .file "blowfish-x86_64-asm.S"
13667 .text
13668@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13669 jnz .L__enc_xor;
13670
13671 write_block();
13672+ pax_force_retaddr
13673 ret;
13674 .L__enc_xor:
13675 xor_block();
13676+ pax_force_retaddr
13677 ret;
13678 ENDPROC(__blowfish_enc_blk)
13679
13680@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13681
13682 movq %r11, %rbp;
13683
13684+ pax_force_retaddr
13685 ret;
13686 ENDPROC(blowfish_dec_blk)
13687
13688@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13689
13690 popq %rbx;
13691 popq %rbp;
13692+ pax_force_retaddr
13693 ret;
13694
13695 .L__enc_xor4:
13696@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13697
13698 popq %rbx;
13699 popq %rbp;
13700+ pax_force_retaddr
13701 ret;
13702 ENDPROC(__blowfish_enc_blk_4way)
13703
13704@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13705 popq %rbx;
13706 popq %rbp;
13707
13708+ pax_force_retaddr
13709 ret;
13710 ENDPROC(blowfish_dec_blk_4way)
13711diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13712index ce71f92..1dce7ec 100644
13713--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13714+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13715@@ -16,6 +16,7 @@
13716 */
13717
13718 #include <linux/linkage.h>
13719+#include <asm/alternative-asm.h>
13720
13721 #define CAMELLIA_TABLE_BYTE_LEN 272
13722
13723@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13724 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13725 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13726 %rcx, (%r9));
13727+ pax_force_retaddr
13728 ret;
13729 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13730
13731@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13732 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13733 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13734 %rax, (%r9));
13735+ pax_force_retaddr
13736 ret;
13737 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13738
13739@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13740 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13741 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13742
13743+ pax_force_retaddr
13744 ret;
13745
13746 .align 8
13747@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13748 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13749 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13750
13751+ pax_force_retaddr
13752 ret;
13753
13754 .align 8
13755@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13756 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13757 %xmm8, %rsi);
13758
13759+ pax_force_retaddr
13760 ret;
13761 ENDPROC(camellia_ecb_enc_16way)
13762
13763@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13764 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13765 %xmm8, %rsi);
13766
13767+ pax_force_retaddr
13768 ret;
13769 ENDPROC(camellia_ecb_dec_16way)
13770
13771@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13772 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13773 %xmm8, %rsi);
13774
13775+ pax_force_retaddr
13776 ret;
13777 ENDPROC(camellia_cbc_dec_16way)
13778
13779@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13780 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13781 %xmm8, %rsi);
13782
13783+ pax_force_retaddr
13784 ret;
13785 ENDPROC(camellia_ctr_16way)
13786
13787@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13788 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13789 %xmm8, %rsi);
13790
13791+ pax_force_retaddr
13792 ret;
13793 ENDPROC(camellia_xts_crypt_16way)
13794
13795diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13796index 0e0b886..5a3123c 100644
13797--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13798+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13799@@ -11,6 +11,7 @@
13800 */
13801
13802 #include <linux/linkage.h>
13803+#include <asm/alternative-asm.h>
13804
13805 #define CAMELLIA_TABLE_BYTE_LEN 272
13806
13807@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13808 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13809 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13810 %rcx, (%r9));
13811+ pax_force_retaddr
13812 ret;
13813 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13814
13815@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13816 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13817 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13818 %rax, (%r9));
13819+ pax_force_retaddr
13820 ret;
13821 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13822
13823@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13824 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13825 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13826
13827+ pax_force_retaddr
13828 ret;
13829
13830 .align 8
13831@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13832 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13833 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13834
13835+ pax_force_retaddr
13836 ret;
13837
13838 .align 8
13839@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13840
13841 vzeroupper;
13842
13843+ pax_force_retaddr
13844 ret;
13845 ENDPROC(camellia_ecb_enc_32way)
13846
13847@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13848
13849 vzeroupper;
13850
13851+ pax_force_retaddr
13852 ret;
13853 ENDPROC(camellia_ecb_dec_32way)
13854
13855@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13856
13857 vzeroupper;
13858
13859+ pax_force_retaddr
13860 ret;
13861 ENDPROC(camellia_cbc_dec_32way)
13862
13863@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13864
13865 vzeroupper;
13866
13867+ pax_force_retaddr
13868 ret;
13869 ENDPROC(camellia_ctr_32way)
13870
13871@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13872
13873 vzeroupper;
13874
13875+ pax_force_retaddr
13876 ret;
13877 ENDPROC(camellia_xts_crypt_32way)
13878
13879diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13880index 310319c..db3d7b5 100644
13881--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13882+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13883@@ -21,6 +21,7 @@
13884 */
13885
13886 #include <linux/linkage.h>
13887+#include <asm/alternative-asm.h>
13888
13889 .file "camellia-x86_64-asm_64.S"
13890 .text
13891@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13892 enc_outunpack(mov, RT1);
13893
13894 movq RRBP, %rbp;
13895+ pax_force_retaddr
13896 ret;
13897
13898 .L__enc_xor:
13899 enc_outunpack(xor, RT1);
13900
13901 movq RRBP, %rbp;
13902+ pax_force_retaddr
13903 ret;
13904 ENDPROC(__camellia_enc_blk)
13905
13906@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13907 dec_outunpack();
13908
13909 movq RRBP, %rbp;
13910+ pax_force_retaddr
13911 ret;
13912 ENDPROC(camellia_dec_blk)
13913
13914@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13915
13916 movq RRBP, %rbp;
13917 popq %rbx;
13918+ pax_force_retaddr
13919 ret;
13920
13921 .L__enc2_xor:
13922@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13923
13924 movq RRBP, %rbp;
13925 popq %rbx;
13926+ pax_force_retaddr
13927 ret;
13928 ENDPROC(__camellia_enc_blk_2way)
13929
13930@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13931
13932 movq RRBP, %rbp;
13933 movq RXOR, %rbx;
13934+ pax_force_retaddr
13935 ret;
13936 ENDPROC(camellia_dec_blk_2way)
13937diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13938index c35fd5d..2d8c7db 100644
13939--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13940+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13941@@ -24,6 +24,7 @@
13942 */
13943
13944 #include <linux/linkage.h>
13945+#include <asm/alternative-asm.h>
13946
13947 .file "cast5-avx-x86_64-asm_64.S"
13948
13949@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13950 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13951 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13952
13953+ pax_force_retaddr
13954 ret;
13955 ENDPROC(__cast5_enc_blk16)
13956
13957@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13958 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13959 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13960
13961+ pax_force_retaddr
13962 ret;
13963
13964 .L__skip_dec:
13965@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13966 vmovdqu RR4, (6*4*4)(%r11);
13967 vmovdqu RL4, (7*4*4)(%r11);
13968
13969+ pax_force_retaddr
13970 ret;
13971 ENDPROC(cast5_ecb_enc_16way)
13972
13973@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13974 vmovdqu RR4, (6*4*4)(%r11);
13975 vmovdqu RL4, (7*4*4)(%r11);
13976
13977+ pax_force_retaddr
13978 ret;
13979 ENDPROC(cast5_ecb_dec_16way)
13980
13981@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13982 * %rdx: src
13983 */
13984
13985- pushq %r12;
13986+ pushq %r14;
13987
13988 movq %rsi, %r11;
13989- movq %rdx, %r12;
13990+ movq %rdx, %r14;
13991
13992 vmovdqu (0*16)(%rdx), RL1;
13993 vmovdqu (1*16)(%rdx), RR1;
13994@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13995 call __cast5_dec_blk16;
13996
13997 /* xor with src */
13998- vmovq (%r12), RX;
13999+ vmovq (%r14), RX;
14000 vpshufd $0x4f, RX, RX;
14001 vpxor RX, RR1, RR1;
14002- vpxor 0*16+8(%r12), RL1, RL1;
14003- vpxor 1*16+8(%r12), RR2, RR2;
14004- vpxor 2*16+8(%r12), RL2, RL2;
14005- vpxor 3*16+8(%r12), RR3, RR3;
14006- vpxor 4*16+8(%r12), RL3, RL3;
14007- vpxor 5*16+8(%r12), RR4, RR4;
14008- vpxor 6*16+8(%r12), RL4, RL4;
14009+ vpxor 0*16+8(%r14), RL1, RL1;
14010+ vpxor 1*16+8(%r14), RR2, RR2;
14011+ vpxor 2*16+8(%r14), RL2, RL2;
14012+ vpxor 3*16+8(%r14), RR3, RR3;
14013+ vpxor 4*16+8(%r14), RL3, RL3;
14014+ vpxor 5*16+8(%r14), RR4, RR4;
14015+ vpxor 6*16+8(%r14), RL4, RL4;
14016
14017 vmovdqu RR1, (0*16)(%r11);
14018 vmovdqu RL1, (1*16)(%r11);
14019@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
14020 vmovdqu RR4, (6*16)(%r11);
14021 vmovdqu RL4, (7*16)(%r11);
14022
14023- popq %r12;
14024+ popq %r14;
14025
14026+ pax_force_retaddr
14027 ret;
14028 ENDPROC(cast5_cbc_dec_16way)
14029
14030@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
14031 * %rcx: iv (big endian, 64bit)
14032 */
14033
14034- pushq %r12;
14035+ pushq %r14;
14036
14037 movq %rsi, %r11;
14038- movq %rdx, %r12;
14039+ movq %rdx, %r14;
14040
14041 vpcmpeqd RTMP, RTMP, RTMP;
14042 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
14043@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
14044 call __cast5_enc_blk16;
14045
14046 /* dst = src ^ iv */
14047- vpxor (0*16)(%r12), RR1, RR1;
14048- vpxor (1*16)(%r12), RL1, RL1;
14049- vpxor (2*16)(%r12), RR2, RR2;
14050- vpxor (3*16)(%r12), RL2, RL2;
14051- vpxor (4*16)(%r12), RR3, RR3;
14052- vpxor (5*16)(%r12), RL3, RL3;
14053- vpxor (6*16)(%r12), RR4, RR4;
14054- vpxor (7*16)(%r12), RL4, RL4;
14055+ vpxor (0*16)(%r14), RR1, RR1;
14056+ vpxor (1*16)(%r14), RL1, RL1;
14057+ vpxor (2*16)(%r14), RR2, RR2;
14058+ vpxor (3*16)(%r14), RL2, RL2;
14059+ vpxor (4*16)(%r14), RR3, RR3;
14060+ vpxor (5*16)(%r14), RL3, RL3;
14061+ vpxor (6*16)(%r14), RR4, RR4;
14062+ vpxor (7*16)(%r14), RL4, RL4;
14063 vmovdqu RR1, (0*16)(%r11);
14064 vmovdqu RL1, (1*16)(%r11);
14065 vmovdqu RR2, (2*16)(%r11);
14066@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
14067 vmovdqu RR4, (6*16)(%r11);
14068 vmovdqu RL4, (7*16)(%r11);
14069
14070- popq %r12;
14071+ popq %r14;
14072
14073+ pax_force_retaddr
14074 ret;
14075 ENDPROC(cast5_ctr_16way)
14076diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14077index e3531f8..e123f35 100644
14078--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14079+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14080@@ -24,6 +24,7 @@
14081 */
14082
14083 #include <linux/linkage.h>
14084+#include <asm/alternative-asm.h>
14085 #include "glue_helper-asm-avx.S"
14086
14087 .file "cast6-avx-x86_64-asm_64.S"
14088@@ -295,6 +296,7 @@ __cast6_enc_blk8:
14089 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14090 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14091
14092+ pax_force_retaddr
14093 ret;
14094 ENDPROC(__cast6_enc_blk8)
14095
14096@@ -340,6 +342,7 @@ __cast6_dec_blk8:
14097 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14098 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14099
14100+ pax_force_retaddr
14101 ret;
14102 ENDPROC(__cast6_dec_blk8)
14103
14104@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
14105
14106 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14107
14108+ pax_force_retaddr
14109 ret;
14110 ENDPROC(cast6_ecb_enc_8way)
14111
14112@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
14113
14114 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14115
14116+ pax_force_retaddr
14117 ret;
14118 ENDPROC(cast6_ecb_dec_8way)
14119
14120@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
14121 * %rdx: src
14122 */
14123
14124- pushq %r12;
14125+ pushq %r14;
14126
14127 movq %rsi, %r11;
14128- movq %rdx, %r12;
14129+ movq %rdx, %r14;
14130
14131 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14132
14133 call __cast6_dec_blk8;
14134
14135- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14136+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14137
14138- popq %r12;
14139+ popq %r14;
14140
14141+ pax_force_retaddr
14142 ret;
14143 ENDPROC(cast6_cbc_dec_8way)
14144
14145@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
14146 * %rcx: iv (little endian, 128bit)
14147 */
14148
14149- pushq %r12;
14150+ pushq %r14;
14151
14152 movq %rsi, %r11;
14153- movq %rdx, %r12;
14154+ movq %rdx, %r14;
14155
14156 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14157 RD2, RX, RKR, RKM);
14158
14159 call __cast6_enc_blk8;
14160
14161- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14162+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14163
14164- popq %r12;
14165+ popq %r14;
14166
14167+ pax_force_retaddr
14168 ret;
14169 ENDPROC(cast6_ctr_8way)
14170
14171@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14172 /* dst <= regs xor IVs(in dst) */
14173 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14174
14175+ pax_force_retaddr
14176 ret;
14177 ENDPROC(cast6_xts_enc_8way)
14178
14179@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14180 /* dst <= regs xor IVs(in dst) */
14181 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14182
14183+ pax_force_retaddr
14184 ret;
14185 ENDPROC(cast6_xts_dec_8way)
14186diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14187index dbc4339..de6e120 100644
14188--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14189+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14190@@ -45,6 +45,7 @@
14191
14192 #include <asm/inst.h>
14193 #include <linux/linkage.h>
14194+#include <asm/alternative-asm.h>
14195
14196 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14197
14198@@ -312,6 +313,7 @@ do_return:
14199 popq %rsi
14200 popq %rdi
14201 popq %rbx
14202+ pax_force_retaddr
14203 ret
14204
14205 ################################################################
14206diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14207index 5d1e007..098cb4f 100644
14208--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14209+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14210@@ -18,6 +18,7 @@
14211
14212 #include <linux/linkage.h>
14213 #include <asm/inst.h>
14214+#include <asm/alternative-asm.h>
14215
14216 .data
14217
14218@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14219 psrlq $1, T2
14220 pxor T2, T1
14221 pxor T1, DATA
14222+ pax_force_retaddr
14223 ret
14224 ENDPROC(__clmul_gf128mul_ble)
14225
14226@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14227 call __clmul_gf128mul_ble
14228 PSHUFB_XMM BSWAP DATA
14229 movups DATA, (%rdi)
14230+ pax_force_retaddr
14231 ret
14232 ENDPROC(clmul_ghash_mul)
14233
14234@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14235 PSHUFB_XMM BSWAP DATA
14236 movups DATA, (%rdi)
14237 .Lupdate_just_ret:
14238+ pax_force_retaddr
14239 ret
14240 ENDPROC(clmul_ghash_update)
14241diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14242index 9279e0b..c4b3d2c 100644
14243--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14244+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14245@@ -1,4 +1,5 @@
14246 #include <linux/linkage.h>
14247+#include <asm/alternative-asm.h>
14248
14249 # enter salsa20_encrypt_bytes
14250 ENTRY(salsa20_encrypt_bytes)
14251@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14252 add %r11,%rsp
14253 mov %rdi,%rax
14254 mov %rsi,%rdx
14255+ pax_force_retaddr
14256 ret
14257 # bytesatleast65:
14258 ._bytesatleast65:
14259@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14260 add %r11,%rsp
14261 mov %rdi,%rax
14262 mov %rsi,%rdx
14263+ pax_force_retaddr
14264 ret
14265 ENDPROC(salsa20_keysetup)
14266
14267@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14268 add %r11,%rsp
14269 mov %rdi,%rax
14270 mov %rsi,%rdx
14271+ pax_force_retaddr
14272 ret
14273 ENDPROC(salsa20_ivsetup)
14274diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14275index 2f202f4..d9164d6 100644
14276--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14277+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14278@@ -24,6 +24,7 @@
14279 */
14280
14281 #include <linux/linkage.h>
14282+#include <asm/alternative-asm.h>
14283 #include "glue_helper-asm-avx.S"
14284
14285 .file "serpent-avx-x86_64-asm_64.S"
14286@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14287 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14288 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14289
14290+ pax_force_retaddr
14291 ret;
14292 ENDPROC(__serpent_enc_blk8_avx)
14293
14294@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14295 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14296 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14297
14298+ pax_force_retaddr
14299 ret;
14300 ENDPROC(__serpent_dec_blk8_avx)
14301
14302@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14303
14304 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14305
14306+ pax_force_retaddr
14307 ret;
14308 ENDPROC(serpent_ecb_enc_8way_avx)
14309
14310@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14311
14312 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14313
14314+ pax_force_retaddr
14315 ret;
14316 ENDPROC(serpent_ecb_dec_8way_avx)
14317
14318@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14319
14320 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14321
14322+ pax_force_retaddr
14323 ret;
14324 ENDPROC(serpent_cbc_dec_8way_avx)
14325
14326@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14327
14328 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14329
14330+ pax_force_retaddr
14331 ret;
14332 ENDPROC(serpent_ctr_8way_avx)
14333
14334@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14335 /* dst <= regs xor IVs(in dst) */
14336 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14337
14338+ pax_force_retaddr
14339 ret;
14340 ENDPROC(serpent_xts_enc_8way_avx)
14341
14342@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14343 /* dst <= regs xor IVs(in dst) */
14344 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14345
14346+ pax_force_retaddr
14347 ret;
14348 ENDPROC(serpent_xts_dec_8way_avx)
14349diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14350index b222085..abd483c 100644
14351--- a/arch/x86/crypto/serpent-avx2-asm_64.S
14352+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14353@@ -15,6 +15,7 @@
14354 */
14355
14356 #include <linux/linkage.h>
14357+#include <asm/alternative-asm.h>
14358 #include "glue_helper-asm-avx2.S"
14359
14360 .file "serpent-avx2-asm_64.S"
14361@@ -610,6 +611,7 @@ __serpent_enc_blk16:
14362 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14363 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14364
14365+ pax_force_retaddr
14366 ret;
14367 ENDPROC(__serpent_enc_blk16)
14368
14369@@ -664,6 +666,7 @@ __serpent_dec_blk16:
14370 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14371 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14372
14373+ pax_force_retaddr
14374 ret;
14375 ENDPROC(__serpent_dec_blk16)
14376
14377@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14378
14379 vzeroupper;
14380
14381+ pax_force_retaddr
14382 ret;
14383 ENDPROC(serpent_ecb_enc_16way)
14384
14385@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14386
14387 vzeroupper;
14388
14389+ pax_force_retaddr
14390 ret;
14391 ENDPROC(serpent_ecb_dec_16way)
14392
14393@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14394
14395 vzeroupper;
14396
14397+ pax_force_retaddr
14398 ret;
14399 ENDPROC(serpent_cbc_dec_16way)
14400
14401@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14402
14403 vzeroupper;
14404
14405+ pax_force_retaddr
14406 ret;
14407 ENDPROC(serpent_ctr_16way)
14408
14409@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14410
14411 vzeroupper;
14412
14413+ pax_force_retaddr
14414 ret;
14415 ENDPROC(serpent_xts_enc_16way)
14416
14417@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14418
14419 vzeroupper;
14420
14421+ pax_force_retaddr
14422 ret;
14423 ENDPROC(serpent_xts_dec_16way)
14424diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14425index acc066c..1559cc4 100644
14426--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14427+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14428@@ -25,6 +25,7 @@
14429 */
14430
14431 #include <linux/linkage.h>
14432+#include <asm/alternative-asm.h>
14433
14434 .file "serpent-sse2-x86_64-asm_64.S"
14435 .text
14436@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14437 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14438 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14439
14440+ pax_force_retaddr
14441 ret;
14442
14443 .L__enc_xor8:
14444 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14445 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14446
14447+ pax_force_retaddr
14448 ret;
14449 ENDPROC(__serpent_enc_blk_8way)
14450
14451@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14452 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14453 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14454
14455+ pax_force_retaddr
14456 ret;
14457 ENDPROC(serpent_dec_blk_8way)
14458diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14459index a410950..9dfe7ad 100644
14460--- a/arch/x86/crypto/sha1_ssse3_asm.S
14461+++ b/arch/x86/crypto/sha1_ssse3_asm.S
14462@@ -29,6 +29,7 @@
14463 */
14464
14465 #include <linux/linkage.h>
14466+#include <asm/alternative-asm.h>
14467
14468 #define CTX %rdi // arg1
14469 #define BUF %rsi // arg2
14470@@ -75,9 +76,9 @@
14471
14472 push %rbx
14473 push %rbp
14474- push %r12
14475+ push %r14
14476
14477- mov %rsp, %r12
14478+ mov %rsp, %r14
14479 sub $64, %rsp # allocate workspace
14480 and $~15, %rsp # align stack
14481
14482@@ -99,11 +100,12 @@
14483 xor %rax, %rax
14484 rep stosq
14485
14486- mov %r12, %rsp # deallocate workspace
14487+ mov %r14, %rsp # deallocate workspace
14488
14489- pop %r12
14490+ pop %r14
14491 pop %rbp
14492 pop %rbx
14493+ pax_force_retaddr
14494 ret
14495
14496 ENDPROC(\name)
14497diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14498index 642f156..51a513c 100644
14499--- a/arch/x86/crypto/sha256-avx-asm.S
14500+++ b/arch/x86/crypto/sha256-avx-asm.S
14501@@ -49,6 +49,7 @@
14502
14503 #ifdef CONFIG_AS_AVX
14504 #include <linux/linkage.h>
14505+#include <asm/alternative-asm.h>
14506
14507 ## assume buffers not aligned
14508 #define VMOVDQ vmovdqu
14509@@ -460,6 +461,7 @@ done_hash:
14510 popq %r13
14511 popq %rbp
14512 popq %rbx
14513+ pax_force_retaddr
14514 ret
14515 ENDPROC(sha256_transform_avx)
14516
14517diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14518index 9e86944..3795e6a 100644
14519--- a/arch/x86/crypto/sha256-avx2-asm.S
14520+++ b/arch/x86/crypto/sha256-avx2-asm.S
14521@@ -50,6 +50,7 @@
14522
14523 #ifdef CONFIG_AS_AVX2
14524 #include <linux/linkage.h>
14525+#include <asm/alternative-asm.h>
14526
14527 ## assume buffers not aligned
14528 #define VMOVDQ vmovdqu
14529@@ -720,6 +721,7 @@ done_hash:
14530 popq %r12
14531 popq %rbp
14532 popq %rbx
14533+ pax_force_retaddr
14534 ret
14535 ENDPROC(sha256_transform_rorx)
14536
14537diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14538index f833b74..8c62a9e 100644
14539--- a/arch/x86/crypto/sha256-ssse3-asm.S
14540+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14541@@ -47,6 +47,7 @@
14542 ########################################################################
14543
14544 #include <linux/linkage.h>
14545+#include <asm/alternative-asm.h>
14546
14547 ## assume buffers not aligned
14548 #define MOVDQ movdqu
14549@@ -471,6 +472,7 @@ done_hash:
14550 popq %rbp
14551 popq %rbx
14552
14553+ pax_force_retaddr
14554 ret
14555 ENDPROC(sha256_transform_ssse3)
14556
14557diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14558index 974dde9..a823ff9 100644
14559--- a/arch/x86/crypto/sha512-avx-asm.S
14560+++ b/arch/x86/crypto/sha512-avx-asm.S
14561@@ -49,6 +49,7 @@
14562
14563 #ifdef CONFIG_AS_AVX
14564 #include <linux/linkage.h>
14565+#include <asm/alternative-asm.h>
14566
14567 .text
14568
14569@@ -364,6 +365,7 @@ updateblock:
14570 mov frame_RSPSAVE(%rsp), %rsp
14571
14572 nowork:
14573+ pax_force_retaddr
14574 ret
14575 ENDPROC(sha512_transform_avx)
14576
14577diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14578index 568b961..ed20c37 100644
14579--- a/arch/x86/crypto/sha512-avx2-asm.S
14580+++ b/arch/x86/crypto/sha512-avx2-asm.S
14581@@ -51,6 +51,7 @@
14582
14583 #ifdef CONFIG_AS_AVX2
14584 #include <linux/linkage.h>
14585+#include <asm/alternative-asm.h>
14586
14587 .text
14588
14589@@ -678,6 +679,7 @@ done_hash:
14590
14591 # Restore Stack Pointer
14592 mov frame_RSPSAVE(%rsp), %rsp
14593+ pax_force_retaddr
14594 ret
14595 ENDPROC(sha512_transform_rorx)
14596
14597diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14598index fb56855..6edd768 100644
14599--- a/arch/x86/crypto/sha512-ssse3-asm.S
14600+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14601@@ -48,6 +48,7 @@
14602 ########################################################################
14603
14604 #include <linux/linkage.h>
14605+#include <asm/alternative-asm.h>
14606
14607 .text
14608
14609@@ -363,6 +364,7 @@ updateblock:
14610 mov frame_RSPSAVE(%rsp), %rsp
14611
14612 nowork:
14613+ pax_force_retaddr
14614 ret
14615 ENDPROC(sha512_transform_ssse3)
14616
14617diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14618index 0505813..b067311 100644
14619--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14620+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14621@@ -24,6 +24,7 @@
14622 */
14623
14624 #include <linux/linkage.h>
14625+#include <asm/alternative-asm.h>
14626 #include "glue_helper-asm-avx.S"
14627
14628 .file "twofish-avx-x86_64-asm_64.S"
14629@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14630 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14631 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14632
14633+ pax_force_retaddr
14634 ret;
14635 ENDPROC(__twofish_enc_blk8)
14636
14637@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14638 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14639 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14640
14641+ pax_force_retaddr
14642 ret;
14643 ENDPROC(__twofish_dec_blk8)
14644
14645@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14646
14647 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14648
14649+ pax_force_retaddr
14650 ret;
14651 ENDPROC(twofish_ecb_enc_8way)
14652
14653@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14654
14655 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14656
14657+ pax_force_retaddr
14658 ret;
14659 ENDPROC(twofish_ecb_dec_8way)
14660
14661@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14662 * %rdx: src
14663 */
14664
14665- pushq %r12;
14666+ pushq %r14;
14667
14668 movq %rsi, %r11;
14669- movq %rdx, %r12;
14670+ movq %rdx, %r14;
14671
14672 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14673
14674 call __twofish_dec_blk8;
14675
14676- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14677+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14678
14679- popq %r12;
14680+ popq %r14;
14681
14682+ pax_force_retaddr
14683 ret;
14684 ENDPROC(twofish_cbc_dec_8way)
14685
14686@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14687 * %rcx: iv (little endian, 128bit)
14688 */
14689
14690- pushq %r12;
14691+ pushq %r14;
14692
14693 movq %rsi, %r11;
14694- movq %rdx, %r12;
14695+ movq %rdx, %r14;
14696
14697 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14698 RD2, RX0, RX1, RY0);
14699
14700 call __twofish_enc_blk8;
14701
14702- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14703+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14704
14705- popq %r12;
14706+ popq %r14;
14707
14708+ pax_force_retaddr
14709 ret;
14710 ENDPROC(twofish_ctr_8way)
14711
14712@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14713 /* dst <= regs xor IVs(in dst) */
14714 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14715
14716+ pax_force_retaddr
14717 ret;
14718 ENDPROC(twofish_xts_enc_8way)
14719
14720@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14721 /* dst <= regs xor IVs(in dst) */
14722 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14723
14724+ pax_force_retaddr
14725 ret;
14726 ENDPROC(twofish_xts_dec_8way)
14727diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14728index 1c3b7ce..02f578d 100644
14729--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14730+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14731@@ -21,6 +21,7 @@
14732 */
14733
14734 #include <linux/linkage.h>
14735+#include <asm/alternative-asm.h>
14736
14737 .file "twofish-x86_64-asm-3way.S"
14738 .text
14739@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14740 popq %r13;
14741 popq %r14;
14742 popq %r15;
14743+ pax_force_retaddr
14744 ret;
14745
14746 .L__enc_xor3:
14747@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14748 popq %r13;
14749 popq %r14;
14750 popq %r15;
14751+ pax_force_retaddr
14752 ret;
14753 ENDPROC(__twofish_enc_blk_3way)
14754
14755@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14756 popq %r13;
14757 popq %r14;
14758 popq %r15;
14759+ pax_force_retaddr
14760 ret;
14761 ENDPROC(twofish_dec_blk_3way)
14762diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14763index a039d21..524b8b2 100644
14764--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14765+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14766@@ -22,6 +22,7 @@
14767
14768 #include <linux/linkage.h>
14769 #include <asm/asm-offsets.h>
14770+#include <asm/alternative-asm.h>
14771
14772 #define a_offset 0
14773 #define b_offset 4
14774@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14775
14776 popq R1
14777 movq $1,%rax
14778+ pax_force_retaddr
14779 ret
14780 ENDPROC(twofish_enc_blk)
14781
14782@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14783
14784 popq R1
14785 movq $1,%rax
14786+ pax_force_retaddr
14787 ret
14788 ENDPROC(twofish_dec_blk)
14789diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14790index d21ff89..6da8e6e 100644
14791--- a/arch/x86/ia32/ia32_aout.c
14792+++ b/arch/x86/ia32/ia32_aout.c
14793@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14794 unsigned long dump_start, dump_size;
14795 struct user32 dump;
14796
14797+ memset(&dump, 0, sizeof(dump));
14798+
14799 fs = get_fs();
14800 set_fs(KERNEL_DS);
14801 has_dumped = 1;
14802diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14803index f9e181a..b0df8b3 100644
14804--- a/arch/x86/ia32/ia32_signal.c
14805+++ b/arch/x86/ia32/ia32_signal.c
14806@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14807 if (__get_user(set.sig[0], &frame->sc.oldmask)
14808 || (_COMPAT_NSIG_WORDS > 1
14809 && __copy_from_user((((char *) &set.sig) + 4),
14810- &frame->extramask,
14811+ frame->extramask,
14812 sizeof(frame->extramask))))
14813 goto badframe;
14814
14815@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14816 sp -= frame_size;
14817 /* Align the stack pointer according to the i386 ABI,
14818 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14819- sp = ((sp + 4) & -16ul) - 4;
14820+ sp = ((sp - 12) & -16ul) - 4;
14821 return (void __user *) sp;
14822 }
14823
14824@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14825 restorer = current->mm->context.vdso +
14826 selected_vdso32->sym___kernel_sigreturn;
14827 else
14828- restorer = &frame->retcode;
14829+ restorer = frame->retcode;
14830 }
14831
14832 put_user_try {
14833@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14834 * These are actually not used anymore, but left because some
14835 * gdb versions depend on them as a marker.
14836 */
14837- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14838+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14839 } put_user_catch(err);
14840
14841 if (err)
14842@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14843 0xb8,
14844 __NR_ia32_rt_sigreturn,
14845 0x80cd,
14846- 0,
14847+ 0
14848 };
14849
14850 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14851@@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14852
14853 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14854 restorer = ksig->ka.sa.sa_restorer;
14855- else
14856+ else if (current->mm->context.vdso)
14857+ /* Return stub is in 32bit vsyscall page */
14858 restorer = current->mm->context.vdso +
14859 selected_vdso32->sym___kernel_rt_sigreturn;
14860+ else
14861+ restorer = frame->retcode;
14862 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14863
14864 /*
14865 * Not actually used anymore, but left because some gdb
14866 * versions need it.
14867 */
14868- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14869+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14870 } put_user_catch(err);
14871
14872 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14873diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14874index 4299eb0..fefe70e 100644
14875--- a/arch/x86/ia32/ia32entry.S
14876+++ b/arch/x86/ia32/ia32entry.S
14877@@ -15,8 +15,10 @@
14878 #include <asm/irqflags.h>
14879 #include <asm/asm.h>
14880 #include <asm/smap.h>
14881+#include <asm/pgtable.h>
14882 #include <linux/linkage.h>
14883 #include <linux/err.h>
14884+#include <asm/alternative-asm.h>
14885
14886 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14887 #include <linux/elf-em.h>
14888@@ -62,12 +64,12 @@
14889 */
14890 .macro LOAD_ARGS32 offset, _r9=0
14891 .if \_r9
14892- movl \offset+16(%rsp),%r9d
14893+ movl \offset+R9(%rsp),%r9d
14894 .endif
14895- movl \offset+40(%rsp),%ecx
14896- movl \offset+48(%rsp),%edx
14897- movl \offset+56(%rsp),%esi
14898- movl \offset+64(%rsp),%edi
14899+ movl \offset+RCX(%rsp),%ecx
14900+ movl \offset+RDX(%rsp),%edx
14901+ movl \offset+RSI(%rsp),%esi
14902+ movl \offset+RDI(%rsp),%edi
14903 movl %eax,%eax /* zero extension */
14904 .endm
14905
14906@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14907 ENDPROC(native_irq_enable_sysexit)
14908 #endif
14909
14910+ .macro pax_enter_kernel_user
14911+ pax_set_fptr_mask
14912+#ifdef CONFIG_PAX_MEMORY_UDEREF
14913+ call pax_enter_kernel_user
14914+#endif
14915+ .endm
14916+
14917+ .macro pax_exit_kernel_user
14918+#ifdef CONFIG_PAX_MEMORY_UDEREF
14919+ call pax_exit_kernel_user
14920+#endif
14921+#ifdef CONFIG_PAX_RANDKSTACK
14922+ pushq %rax
14923+ pushq %r11
14924+ call pax_randomize_kstack
14925+ popq %r11
14926+ popq %rax
14927+#endif
14928+ .endm
14929+
14930+ .macro pax_erase_kstack
14931+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14932+ call pax_erase_kstack
14933+#endif
14934+ .endm
14935+
14936 /*
14937 * 32bit SYSENTER instruction entry.
14938 *
14939@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14940 CFI_REGISTER rsp,rbp
14941 SWAPGS_UNSAFE_STACK
14942 movq PER_CPU_VAR(kernel_stack), %rsp
14943- addq $(KERNEL_STACK_OFFSET),%rsp
14944- /*
14945- * No need to follow this irqs on/off section: the syscall
14946- * disabled irqs, here we enable it straight after entry:
14947- */
14948- ENABLE_INTERRUPTS(CLBR_NONE)
14949 movl %ebp,%ebp /* zero extension */
14950 pushq_cfi $__USER32_DS
14951 /*CFI_REL_OFFSET ss,0*/
14952@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14953 CFI_REL_OFFSET rsp,0
14954 pushfq_cfi
14955 /*CFI_REL_OFFSET rflags,0*/
14956- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14957- CFI_REGISTER rip,r10
14958+ orl $X86_EFLAGS_IF,(%rsp)
14959+ GET_THREAD_INFO(%r11)
14960+ movl TI_sysenter_return(%r11), %r11d
14961+ CFI_REGISTER rip,r11
14962 pushq_cfi $__USER32_CS
14963 /*CFI_REL_OFFSET cs,0*/
14964 movl %eax, %eax
14965- pushq_cfi %r10
14966+ pushq_cfi %r11
14967 CFI_REL_OFFSET rip,0
14968 pushq_cfi %rax
14969 cld
14970 SAVE_ARGS 0,1,0
14971+ pax_enter_kernel_user
14972+
14973+#ifdef CONFIG_PAX_RANDKSTACK
14974+ pax_erase_kstack
14975+#endif
14976+
14977+ /*
14978+ * No need to follow this irqs on/off section: the syscall
14979+ * disabled irqs, here we enable it straight after entry:
14980+ */
14981+ ENABLE_INTERRUPTS(CLBR_NONE)
14982 /* no need to do an access_ok check here because rbp has been
14983 32bit zero extended */
14984+
14985+#ifdef CONFIG_PAX_MEMORY_UDEREF
14986+ addq pax_user_shadow_base,%rbp
14987+ ASM_PAX_OPEN_USERLAND
14988+#endif
14989+
14990 ASM_STAC
14991 1: movl (%rbp),%ebp
14992 _ASM_EXTABLE(1b,ia32_badarg)
14993 ASM_CLAC
14994- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14995- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14996+
14997+#ifdef CONFIG_PAX_MEMORY_UDEREF
14998+ ASM_PAX_CLOSE_USERLAND
14999+#endif
15000+
15001+ GET_THREAD_INFO(%r11)
15002+ orl $TS_COMPAT,TI_status(%r11)
15003+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15004 CFI_REMEMBER_STATE
15005 jnz sysenter_tracesys
15006 cmpq $(IA32_NR_syscalls-1),%rax
15007@@ -162,15 +209,18 @@ sysenter_do_call:
15008 sysenter_dispatch:
15009 call *ia32_sys_call_table(,%rax,8)
15010 movq %rax,RAX-ARGOFFSET(%rsp)
15011+ GET_THREAD_INFO(%r11)
15012 DISABLE_INTERRUPTS(CLBR_NONE)
15013 TRACE_IRQS_OFF
15014- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15015+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15016 jnz sysexit_audit
15017 sysexit_from_sys_call:
15018- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15019+ pax_exit_kernel_user
15020+ pax_erase_kstack
15021+ andl $~TS_COMPAT,TI_status(%r11)
15022 /* clear IF, that popfq doesn't enable interrupts early */
15023- andl $~0x200,EFLAGS-R11(%rsp)
15024- movl RIP-R11(%rsp),%edx /* User %eip */
15025+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
15026+ movl RIP(%rsp),%edx /* User %eip */
15027 CFI_REGISTER rip,rdx
15028 RESTORE_ARGS 0,24,0,0,0,0
15029 xorq %r8,%r8
15030@@ -193,6 +243,9 @@ sysexit_from_sys_call:
15031 movl %eax,%esi /* 2nd arg: syscall number */
15032 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
15033 call __audit_syscall_entry
15034+
15035+ pax_erase_kstack
15036+
15037 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
15038 cmpq $(IA32_NR_syscalls-1),%rax
15039 ja ia32_badsys
15040@@ -204,7 +257,7 @@ sysexit_from_sys_call:
15041 .endm
15042
15043 .macro auditsys_exit exit
15044- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15045+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15046 jnz ia32_ret_from_sys_call
15047 TRACE_IRQS_ON
15048 ENABLE_INTERRUPTS(CLBR_NONE)
15049@@ -215,11 +268,12 @@ sysexit_from_sys_call:
15050 1: setbe %al /* 1 if error, 0 if not */
15051 movzbl %al,%edi /* zero-extend that into %edi */
15052 call __audit_syscall_exit
15053+ GET_THREAD_INFO(%r11)
15054 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
15055 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
15056 DISABLE_INTERRUPTS(CLBR_NONE)
15057 TRACE_IRQS_OFF
15058- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15059+ testl %edi,TI_flags(%r11)
15060 jz \exit
15061 CLEAR_RREGS -ARGOFFSET
15062 jmp int_with_check
15063@@ -237,7 +291,7 @@ sysexit_audit:
15064
15065 sysenter_tracesys:
15066 #ifdef CONFIG_AUDITSYSCALL
15067- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15068+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15069 jz sysenter_auditsys
15070 #endif
15071 SAVE_REST
15072@@ -249,6 +303,9 @@ sysenter_tracesys:
15073 RESTORE_REST
15074 cmpq $(IA32_NR_syscalls-1),%rax
15075 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
15076+
15077+ pax_erase_kstack
15078+
15079 jmp sysenter_do_call
15080 CFI_ENDPROC
15081 ENDPROC(ia32_sysenter_target)
15082@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
15083 ENTRY(ia32_cstar_target)
15084 CFI_STARTPROC32 simple
15085 CFI_SIGNAL_FRAME
15086- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15087+ CFI_DEF_CFA rsp,0
15088 CFI_REGISTER rip,rcx
15089 /*CFI_REGISTER rflags,r11*/
15090 SWAPGS_UNSAFE_STACK
15091 movl %esp,%r8d
15092 CFI_REGISTER rsp,r8
15093 movq PER_CPU_VAR(kernel_stack),%rsp
15094+ SAVE_ARGS 8*6,0,0
15095+ pax_enter_kernel_user
15096+
15097+#ifdef CONFIG_PAX_RANDKSTACK
15098+ pax_erase_kstack
15099+#endif
15100+
15101 /*
15102 * No need to follow this irqs on/off section: the syscall
15103 * disabled irqs and here we enable it straight after entry:
15104 */
15105 ENABLE_INTERRUPTS(CLBR_NONE)
15106- SAVE_ARGS 8,0,0
15107 movl %eax,%eax /* zero extension */
15108 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15109 movq %rcx,RIP-ARGOFFSET(%rsp)
15110@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
15111 /* no need to do an access_ok check here because r8 has been
15112 32bit zero extended */
15113 /* hardware stack frame is complete now */
15114+
15115+#ifdef CONFIG_PAX_MEMORY_UDEREF
15116+ ASM_PAX_OPEN_USERLAND
15117+ movq pax_user_shadow_base,%r8
15118+ addq RSP-ARGOFFSET(%rsp),%r8
15119+#endif
15120+
15121 ASM_STAC
15122 1: movl (%r8),%r9d
15123 _ASM_EXTABLE(1b,ia32_badarg)
15124 ASM_CLAC
15125- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15126- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15127+
15128+#ifdef CONFIG_PAX_MEMORY_UDEREF
15129+ ASM_PAX_CLOSE_USERLAND
15130+#endif
15131+
15132+ GET_THREAD_INFO(%r11)
15133+ orl $TS_COMPAT,TI_status(%r11)
15134+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15135 CFI_REMEMBER_STATE
15136 jnz cstar_tracesys
15137 cmpq $IA32_NR_syscalls-1,%rax
15138@@ -319,13 +395,16 @@ cstar_do_call:
15139 cstar_dispatch:
15140 call *ia32_sys_call_table(,%rax,8)
15141 movq %rax,RAX-ARGOFFSET(%rsp)
15142+ GET_THREAD_INFO(%r11)
15143 DISABLE_INTERRUPTS(CLBR_NONE)
15144 TRACE_IRQS_OFF
15145- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15146+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15147 jnz sysretl_audit
15148 sysretl_from_sys_call:
15149- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15150- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
15151+ pax_exit_kernel_user
15152+ pax_erase_kstack
15153+ andl $~TS_COMPAT,TI_status(%r11)
15154+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15155 movl RIP-ARGOFFSET(%rsp),%ecx
15156 CFI_REGISTER rip,rcx
15157 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15158@@ -352,7 +431,7 @@ sysretl_audit:
15159
15160 cstar_tracesys:
15161 #ifdef CONFIG_AUDITSYSCALL
15162- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15163+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15164 jz cstar_auditsys
15165 #endif
15166 xchgl %r9d,%ebp
15167@@ -366,11 +445,19 @@ cstar_tracesys:
15168 xchgl %ebp,%r9d
15169 cmpq $(IA32_NR_syscalls-1),%rax
15170 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15171+
15172+ pax_erase_kstack
15173+
15174 jmp cstar_do_call
15175 END(ia32_cstar_target)
15176
15177 ia32_badarg:
15178 ASM_CLAC
15179+
15180+#ifdef CONFIG_PAX_MEMORY_UDEREF
15181+ ASM_PAX_CLOSE_USERLAND
15182+#endif
15183+
15184 movq $-EFAULT,%rax
15185 jmp ia32_sysret
15186 CFI_ENDPROC
15187@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
15188 CFI_REL_OFFSET rip,RIP-RIP
15189 PARAVIRT_ADJUST_EXCEPTION_FRAME
15190 SWAPGS
15191- /*
15192- * No need to follow this irqs on/off section: the syscall
15193- * disabled irqs and here we enable it straight after entry:
15194- */
15195- ENABLE_INTERRUPTS(CLBR_NONE)
15196 movl %eax,%eax
15197 pushq_cfi %rax
15198 cld
15199 /* note the registers are not zero extended to the sf.
15200 this could be a problem. */
15201 SAVE_ARGS 0,1,0
15202- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15203- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15204+ pax_enter_kernel_user
15205+
15206+#ifdef CONFIG_PAX_RANDKSTACK
15207+ pax_erase_kstack
15208+#endif
15209+
15210+ /*
15211+ * No need to follow this irqs on/off section: the syscall
15212+ * disabled irqs and here we enable it straight after entry:
15213+ */
15214+ ENABLE_INTERRUPTS(CLBR_NONE)
15215+ GET_THREAD_INFO(%r11)
15216+ orl $TS_COMPAT,TI_status(%r11)
15217+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15218 jnz ia32_tracesys
15219 cmpq $(IA32_NR_syscalls-1),%rax
15220 ja ia32_badsys
15221@@ -442,6 +536,9 @@ ia32_tracesys:
15222 RESTORE_REST
15223 cmpq $(IA32_NR_syscalls-1),%rax
15224 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15225+
15226+ pax_erase_kstack
15227+
15228 jmp ia32_do_call
15229 END(ia32_syscall)
15230
15231diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15232index 8e0ceec..af13504 100644
15233--- a/arch/x86/ia32/sys_ia32.c
15234+++ b/arch/x86/ia32/sys_ia32.c
15235@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15236 */
15237 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15238 {
15239- typeof(ubuf->st_uid) uid = 0;
15240- typeof(ubuf->st_gid) gid = 0;
15241+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
15242+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
15243 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15244 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15245 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15246diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15247index 372231c..51b537d 100644
15248--- a/arch/x86/include/asm/alternative-asm.h
15249+++ b/arch/x86/include/asm/alternative-asm.h
15250@@ -18,6 +18,45 @@
15251 .endm
15252 #endif
15253
15254+#ifdef KERNEXEC_PLUGIN
15255+ .macro pax_force_retaddr_bts rip=0
15256+ btsq $63,\rip(%rsp)
15257+ .endm
15258+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15259+ .macro pax_force_retaddr rip=0, reload=0
15260+ btsq $63,\rip(%rsp)
15261+ .endm
15262+ .macro pax_force_fptr ptr
15263+ btsq $63,\ptr
15264+ .endm
15265+ .macro pax_set_fptr_mask
15266+ .endm
15267+#endif
15268+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15269+ .macro pax_force_retaddr rip=0, reload=0
15270+ .if \reload
15271+ pax_set_fptr_mask
15272+ .endif
15273+ orq %r12,\rip(%rsp)
15274+ .endm
15275+ .macro pax_force_fptr ptr
15276+ orq %r12,\ptr
15277+ .endm
15278+ .macro pax_set_fptr_mask
15279+ movabs $0x8000000000000000,%r12
15280+ .endm
15281+#endif
15282+#else
15283+ .macro pax_force_retaddr rip=0, reload=0
15284+ .endm
15285+ .macro pax_force_fptr ptr
15286+ .endm
15287+ .macro pax_force_retaddr_bts rip=0
15288+ .endm
15289+ .macro pax_set_fptr_mask
15290+ .endm
15291+#endif
15292+
15293 .macro altinstruction_entry orig alt feature orig_len alt_len
15294 .long \orig - .
15295 .long \alt - .
15296diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15297index 0a3f9c9..c9d081d 100644
15298--- a/arch/x86/include/asm/alternative.h
15299+++ b/arch/x86/include/asm/alternative.h
15300@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15301 ".pushsection .discard,\"aw\",@progbits\n" \
15302 DISCARD_ENTRY(1) \
15303 ".popsection\n" \
15304- ".pushsection .altinstr_replacement, \"ax\"\n" \
15305+ ".pushsection .altinstr_replacement, \"a\"\n" \
15306 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15307 ".popsection"
15308
15309@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15310 DISCARD_ENTRY(1) \
15311 DISCARD_ENTRY(2) \
15312 ".popsection\n" \
15313- ".pushsection .altinstr_replacement, \"ax\"\n" \
15314+ ".pushsection .altinstr_replacement, \"a\"\n" \
15315 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15316 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15317 ".popsection"
15318diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15319index 19b0eba..12254cd 100644
15320--- a/arch/x86/include/asm/apic.h
15321+++ b/arch/x86/include/asm/apic.h
15322@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15323
15324 #ifdef CONFIG_X86_LOCAL_APIC
15325
15326-extern unsigned int apic_verbosity;
15327+extern int apic_verbosity;
15328 extern int local_apic_timer_c2_ok;
15329
15330 extern int disable_apic;
15331diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15332index 20370c6..a2eb9b0 100644
15333--- a/arch/x86/include/asm/apm.h
15334+++ b/arch/x86/include/asm/apm.h
15335@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15336 __asm__ __volatile__(APM_DO_ZERO_SEGS
15337 "pushl %%edi\n\t"
15338 "pushl %%ebp\n\t"
15339- "lcall *%%cs:apm_bios_entry\n\t"
15340+ "lcall *%%ss:apm_bios_entry\n\t"
15341 "setc %%al\n\t"
15342 "popl %%ebp\n\t"
15343 "popl %%edi\n\t"
15344@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15345 __asm__ __volatile__(APM_DO_ZERO_SEGS
15346 "pushl %%edi\n\t"
15347 "pushl %%ebp\n\t"
15348- "lcall *%%cs:apm_bios_entry\n\t"
15349+ "lcall *%%ss:apm_bios_entry\n\t"
15350 "setc %%bl\n\t"
15351 "popl %%ebp\n\t"
15352 "popl %%edi\n\t"
15353diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15354index 6dd1c7dd..2edd216 100644
15355--- a/arch/x86/include/asm/atomic.h
15356+++ b/arch/x86/include/asm/atomic.h
15357@@ -24,7 +24,18 @@
15358 */
15359 static inline int atomic_read(const atomic_t *v)
15360 {
15361- return (*(volatile int *)&(v)->counter);
15362+ return (*(volatile const int *)&(v)->counter);
15363+}
15364+
15365+/**
15366+ * atomic_read_unchecked - read atomic variable
15367+ * @v: pointer of type atomic_unchecked_t
15368+ *
15369+ * Atomically reads the value of @v.
15370+ */
15371+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15372+{
15373+ return (*(volatile const int *)&(v)->counter);
15374 }
15375
15376 /**
15377@@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15378 }
15379
15380 /**
15381+ * atomic_set_unchecked - set atomic variable
15382+ * @v: pointer of type atomic_unchecked_t
15383+ * @i: required value
15384+ *
15385+ * Atomically sets the value of @v to @i.
15386+ */
15387+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15388+{
15389+ v->counter = i;
15390+}
15391+
15392+/**
15393 * atomic_add - add integer to atomic variable
15394 * @i: integer value to add
15395 * @v: pointer of type atomic_t
15396@@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15397 */
15398 static inline void atomic_add(int i, atomic_t *v)
15399 {
15400- asm volatile(LOCK_PREFIX "addl %1,%0"
15401+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15402+
15403+#ifdef CONFIG_PAX_REFCOUNT
15404+ "jno 0f\n"
15405+ LOCK_PREFIX "subl %1,%0\n"
15406+ "int $4\n0:\n"
15407+ _ASM_EXTABLE(0b, 0b)
15408+#endif
15409+
15410+ : "+m" (v->counter)
15411+ : "ir" (i));
15412+}
15413+
15414+/**
15415+ * atomic_add_unchecked - add integer to atomic variable
15416+ * @i: integer value to add
15417+ * @v: pointer of type atomic_unchecked_t
15418+ *
15419+ * Atomically adds @i to @v.
15420+ */
15421+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15422+{
15423+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15424 : "+m" (v->counter)
15425 : "ir" (i));
15426 }
15427@@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15428 */
15429 static inline void atomic_sub(int i, atomic_t *v)
15430 {
15431- asm volatile(LOCK_PREFIX "subl %1,%0"
15432+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15433+
15434+#ifdef CONFIG_PAX_REFCOUNT
15435+ "jno 0f\n"
15436+ LOCK_PREFIX "addl %1,%0\n"
15437+ "int $4\n0:\n"
15438+ _ASM_EXTABLE(0b, 0b)
15439+#endif
15440+
15441+ : "+m" (v->counter)
15442+ : "ir" (i));
15443+}
15444+
15445+/**
15446+ * atomic_sub_unchecked - subtract integer from atomic variable
15447+ * @i: integer value to subtract
15448+ * @v: pointer of type atomic_unchecked_t
15449+ *
15450+ * Atomically subtracts @i from @v.
15451+ */
15452+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15453+{
15454+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15455 : "+m" (v->counter)
15456 : "ir" (i));
15457 }
15458@@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15459 */
15460 static inline int atomic_sub_and_test(int i, atomic_t *v)
15461 {
15462- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15463+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15464 }
15465
15466 /**
15467@@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15468 */
15469 static inline void atomic_inc(atomic_t *v)
15470 {
15471- asm volatile(LOCK_PREFIX "incl %0"
15472+ asm volatile(LOCK_PREFIX "incl %0\n"
15473+
15474+#ifdef CONFIG_PAX_REFCOUNT
15475+ "jno 0f\n"
15476+ LOCK_PREFIX "decl %0\n"
15477+ "int $4\n0:\n"
15478+ _ASM_EXTABLE(0b, 0b)
15479+#endif
15480+
15481+ : "+m" (v->counter));
15482+}
15483+
15484+/**
15485+ * atomic_inc_unchecked - increment atomic variable
15486+ * @v: pointer of type atomic_unchecked_t
15487+ *
15488+ * Atomically increments @v by 1.
15489+ */
15490+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15491+{
15492+ asm volatile(LOCK_PREFIX "incl %0\n"
15493 : "+m" (v->counter));
15494 }
15495
15496@@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15497 */
15498 static inline void atomic_dec(atomic_t *v)
15499 {
15500- asm volatile(LOCK_PREFIX "decl %0"
15501+ asm volatile(LOCK_PREFIX "decl %0\n"
15502+
15503+#ifdef CONFIG_PAX_REFCOUNT
15504+ "jno 0f\n"
15505+ LOCK_PREFIX "incl %0\n"
15506+ "int $4\n0:\n"
15507+ _ASM_EXTABLE(0b, 0b)
15508+#endif
15509+
15510+ : "+m" (v->counter));
15511+}
15512+
15513+/**
15514+ * atomic_dec_unchecked - decrement atomic variable
15515+ * @v: pointer of type atomic_unchecked_t
15516+ *
15517+ * Atomically decrements @v by 1.
15518+ */
15519+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15520+{
15521+ asm volatile(LOCK_PREFIX "decl %0\n"
15522 : "+m" (v->counter));
15523 }
15524
15525@@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
15526 */
15527 static inline int atomic_dec_and_test(atomic_t *v)
15528 {
15529- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15530+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15531 }
15532
15533 /**
15534@@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15535 */
15536 static inline int atomic_inc_and_test(atomic_t *v)
15537 {
15538- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15539+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15540+}
15541+
15542+/**
15543+ * atomic_inc_and_test_unchecked - increment and test
15544+ * @v: pointer of type atomic_unchecked_t
15545+ *
15546+ * Atomically increments @v by 1
15547+ * and returns true if the result is zero, or false for all
15548+ * other cases.
15549+ */
15550+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15551+{
15552+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15553 }
15554
15555 /**
15556@@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15557 */
15558 static inline int atomic_add_negative(int i, atomic_t *v)
15559 {
15560- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15561+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15562 }
15563
15564 /**
15565@@ -154,6 +274,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15566 */
15567 static inline int atomic_add_return(int i, atomic_t *v)
15568 {
15569+ return i + xadd_check_overflow(&v->counter, i);
15570+}
15571+
15572+/**
15573+ * atomic_add_return_unchecked - add integer and return
15574+ * @i: integer value to add
15575+ * @v: pointer of type atomic_unchecked_t
15576+ *
15577+ * Atomically adds @i to @v and returns @i + @v
15578+ */
15579+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15580+{
15581 return i + xadd(&v->counter, i);
15582 }
15583
15584@@ -170,9 +302,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15585 }
15586
15587 #define atomic_inc_return(v) (atomic_add_return(1, v))
15588+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15589+{
15590+ return atomic_add_return_unchecked(1, v);
15591+}
15592 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15593
15594-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15595+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15596+{
15597+ return cmpxchg(&v->counter, old, new);
15598+}
15599+
15600+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15601 {
15602 return cmpxchg(&v->counter, old, new);
15603 }
15604@@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15605 return xchg(&v->counter, new);
15606 }
15607
15608+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15609+{
15610+ return xchg(&v->counter, new);
15611+}
15612+
15613 /**
15614 * __atomic_add_unless - add unless the number is already a given value
15615 * @v: pointer of type atomic_t
15616@@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15617 * Atomically adds @a to @v, so long as @v was not already @u.
15618 * Returns the old value of @v.
15619 */
15620-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15621+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15622 {
15623- int c, old;
15624+ int c, old, new;
15625 c = atomic_read(v);
15626 for (;;) {
15627- if (unlikely(c == (u)))
15628+ if (unlikely(c == u))
15629 break;
15630- old = atomic_cmpxchg((v), c, c + (a));
15631+
15632+ asm volatile("addl %2,%0\n"
15633+
15634+#ifdef CONFIG_PAX_REFCOUNT
15635+ "jno 0f\n"
15636+ "subl %2,%0\n"
15637+ "int $4\n0:\n"
15638+ _ASM_EXTABLE(0b, 0b)
15639+#endif
15640+
15641+ : "=r" (new)
15642+ : "0" (c), "ir" (a));
15643+
15644+ old = atomic_cmpxchg(v, c, new);
15645 if (likely(old == c))
15646 break;
15647 c = old;
15648@@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15649 }
15650
15651 /**
15652+ * atomic_inc_not_zero_hint - increment if not null
15653+ * @v: pointer of type atomic_t
15654+ * @hint: probable value of the atomic before the increment
15655+ *
15656+ * This version of atomic_inc_not_zero() gives a hint of probable
15657+ * value of the atomic. This helps processor to not read the memory
15658+ * before doing the atomic read/modify/write cycle, lowering
15659+ * number of bus transactions on some arches.
15660+ *
15661+ * Returns: 0 if increment was not done, 1 otherwise.
15662+ */
15663+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15664+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15665+{
15666+ int val, c = hint, new;
15667+
15668+ /* sanity test, should be removed by compiler if hint is a constant */
15669+ if (!hint)
15670+ return __atomic_add_unless(v, 1, 0);
15671+
15672+ do {
15673+ asm volatile("incl %0\n"
15674+
15675+#ifdef CONFIG_PAX_REFCOUNT
15676+ "jno 0f\n"
15677+ "decl %0\n"
15678+ "int $4\n0:\n"
15679+ _ASM_EXTABLE(0b, 0b)
15680+#endif
15681+
15682+ : "=r" (new)
15683+ : "0" (c));
15684+
15685+ val = atomic_cmpxchg(v, c, new);
15686+ if (val == c)
15687+ return 1;
15688+ c = val;
15689+ } while (c);
15690+
15691+ return 0;
15692+}
15693+
15694+/**
15695 * atomic_inc_short - increment of a short integer
15696 * @v: pointer to type int
15697 *
15698@@ -235,14 +437,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15699 #endif
15700
15701 /* These are x86-specific, used by some header files */
15702-#define atomic_clear_mask(mask, addr) \
15703- asm volatile(LOCK_PREFIX "andl %0,%1" \
15704- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15705+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15706+{
15707+ asm volatile(LOCK_PREFIX "andl %1,%0"
15708+ : "+m" (v->counter)
15709+ : "r" (~(mask))
15710+ : "memory");
15711+}
15712
15713-#define atomic_set_mask(mask, addr) \
15714- asm volatile(LOCK_PREFIX "orl %0,%1" \
15715- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15716- : "memory")
15717+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15718+{
15719+ asm volatile(LOCK_PREFIX "andl %1,%0"
15720+ : "+m" (v->counter)
15721+ : "r" (~(mask))
15722+ : "memory");
15723+}
15724+
15725+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15726+{
15727+ asm volatile(LOCK_PREFIX "orl %1,%0"
15728+ : "+m" (v->counter)
15729+ : "r" (mask)
15730+ : "memory");
15731+}
15732+
15733+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15734+{
15735+ asm volatile(LOCK_PREFIX "orl %1,%0"
15736+ : "+m" (v->counter)
15737+ : "r" (mask)
15738+ : "memory");
15739+}
15740
15741 #ifdef CONFIG_X86_32
15742 # include <asm/atomic64_32.h>
15743diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15744index b154de7..bf18a5a 100644
15745--- a/arch/x86/include/asm/atomic64_32.h
15746+++ b/arch/x86/include/asm/atomic64_32.h
15747@@ -12,6 +12,14 @@ typedef struct {
15748 u64 __aligned(8) counter;
15749 } atomic64_t;
15750
15751+#ifdef CONFIG_PAX_REFCOUNT
15752+typedef struct {
15753+ u64 __aligned(8) counter;
15754+} atomic64_unchecked_t;
15755+#else
15756+typedef atomic64_t atomic64_unchecked_t;
15757+#endif
15758+
15759 #define ATOMIC64_INIT(val) { (val) }
15760
15761 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15762@@ -37,21 +45,31 @@ typedef struct {
15763 ATOMIC64_DECL_ONE(sym##_386)
15764
15765 ATOMIC64_DECL_ONE(add_386);
15766+ATOMIC64_DECL_ONE(add_unchecked_386);
15767 ATOMIC64_DECL_ONE(sub_386);
15768+ATOMIC64_DECL_ONE(sub_unchecked_386);
15769 ATOMIC64_DECL_ONE(inc_386);
15770+ATOMIC64_DECL_ONE(inc_unchecked_386);
15771 ATOMIC64_DECL_ONE(dec_386);
15772+ATOMIC64_DECL_ONE(dec_unchecked_386);
15773 #endif
15774
15775 #define alternative_atomic64(f, out, in...) \
15776 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15777
15778 ATOMIC64_DECL(read);
15779+ATOMIC64_DECL(read_unchecked);
15780 ATOMIC64_DECL(set);
15781+ATOMIC64_DECL(set_unchecked);
15782 ATOMIC64_DECL(xchg);
15783 ATOMIC64_DECL(add_return);
15784+ATOMIC64_DECL(add_return_unchecked);
15785 ATOMIC64_DECL(sub_return);
15786+ATOMIC64_DECL(sub_return_unchecked);
15787 ATOMIC64_DECL(inc_return);
15788+ATOMIC64_DECL(inc_return_unchecked);
15789 ATOMIC64_DECL(dec_return);
15790+ATOMIC64_DECL(dec_return_unchecked);
15791 ATOMIC64_DECL(dec_if_positive);
15792 ATOMIC64_DECL(inc_not_zero);
15793 ATOMIC64_DECL(add_unless);
15794@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15795 }
15796
15797 /**
15798+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15799+ * @p: pointer to type atomic64_unchecked_t
15800+ * @o: expected value
15801+ * @n: new value
15802+ *
15803+ * Atomically sets @v to @n if it was equal to @o and returns
15804+ * the old value.
15805+ */
15806+
15807+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15808+{
15809+ return cmpxchg64(&v->counter, o, n);
15810+}
15811+
15812+/**
15813 * atomic64_xchg - xchg atomic64 variable
15814 * @v: pointer to type atomic64_t
15815 * @n: value to assign
15816@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15817 }
15818
15819 /**
15820+ * atomic64_set_unchecked - set atomic64 variable
15821+ * @v: pointer to type atomic64_unchecked_t
15822+ * @n: value to assign
15823+ *
15824+ * Atomically sets the value of @v to @n.
15825+ */
15826+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15827+{
15828+ unsigned high = (unsigned)(i >> 32);
15829+ unsigned low = (unsigned)i;
15830+ alternative_atomic64(set, /* no output */,
15831+ "S" (v), "b" (low), "c" (high)
15832+ : "eax", "edx", "memory");
15833+}
15834+
15835+/**
15836 * atomic64_read - read atomic64 variable
15837 * @v: pointer to type atomic64_t
15838 *
15839@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15840 }
15841
15842 /**
15843+ * atomic64_read_unchecked - read atomic64 variable
15844+ * @v: pointer to type atomic64_unchecked_t
15845+ *
15846+ * Atomically reads the value of @v and returns it.
15847+ */
15848+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15849+{
15850+ long long r;
15851+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15852+ return r;
15853+ }
15854+
15855+/**
15856 * atomic64_add_return - add and return
15857 * @i: integer value to add
15858 * @v: pointer to type atomic64_t
15859@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15860 return i;
15861 }
15862
15863+/**
15864+ * atomic64_add_return_unchecked - add and return
15865+ * @i: integer value to add
15866+ * @v: pointer to type atomic64_unchecked_t
15867+ *
15868+ * Atomically adds @i to @v and returns @i + *@v
15869+ */
15870+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15871+{
15872+ alternative_atomic64(add_return_unchecked,
15873+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15874+ ASM_NO_INPUT_CLOBBER("memory"));
15875+ return i;
15876+}
15877+
15878 /*
15879 * Other variants with different arithmetic operators:
15880 */
15881@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15882 return a;
15883 }
15884
15885+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15886+{
15887+ long long a;
15888+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15889+ "S" (v) : "memory", "ecx");
15890+ return a;
15891+}
15892+
15893 static inline long long atomic64_dec_return(atomic64_t *v)
15894 {
15895 long long a;
15896@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15897 }
15898
15899 /**
15900+ * atomic64_add_unchecked - add integer to atomic64 variable
15901+ * @i: integer value to add
15902+ * @v: pointer to type atomic64_unchecked_t
15903+ *
15904+ * Atomically adds @i to @v.
15905+ */
15906+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15907+{
15908+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15909+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15910+ ASM_NO_INPUT_CLOBBER("memory"));
15911+ return i;
15912+}
15913+
15914+/**
15915 * atomic64_sub - subtract the atomic64 variable
15916 * @i: integer value to subtract
15917 * @v: pointer to type atomic64_t
15918diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15919index 46e9052..ae45136 100644
15920--- a/arch/x86/include/asm/atomic64_64.h
15921+++ b/arch/x86/include/asm/atomic64_64.h
15922@@ -18,7 +18,19 @@
15923 */
15924 static inline long atomic64_read(const atomic64_t *v)
15925 {
15926- return (*(volatile long *)&(v)->counter);
15927+ return (*(volatile const long *)&(v)->counter);
15928+}
15929+
15930+/**
15931+ * atomic64_read_unchecked - read atomic64 variable
15932+ * @v: pointer of type atomic64_unchecked_t
15933+ *
15934+ * Atomically reads the value of @v.
15935+ * Doesn't imply a read memory barrier.
15936+ */
15937+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15938+{
15939+ return (*(volatile const long *)&(v)->counter);
15940 }
15941
15942 /**
15943@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15944 }
15945
15946 /**
15947+ * atomic64_set_unchecked - set atomic64 variable
15948+ * @v: pointer to type atomic64_unchecked_t
15949+ * @i: required value
15950+ *
15951+ * Atomically sets the value of @v to @i.
15952+ */
15953+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15954+{
15955+ v->counter = i;
15956+}
15957+
15958+/**
15959 * atomic64_add - add integer to atomic64 variable
15960 * @i: integer value to add
15961 * @v: pointer to type atomic64_t
15962@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15963 */
15964 static inline void atomic64_add(long i, atomic64_t *v)
15965 {
15966+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15967+
15968+#ifdef CONFIG_PAX_REFCOUNT
15969+ "jno 0f\n"
15970+ LOCK_PREFIX "subq %1,%0\n"
15971+ "int $4\n0:\n"
15972+ _ASM_EXTABLE(0b, 0b)
15973+#endif
15974+
15975+ : "=m" (v->counter)
15976+ : "er" (i), "m" (v->counter));
15977+}
15978+
15979+/**
15980+ * atomic64_add_unchecked - add integer to atomic64 variable
15981+ * @i: integer value to add
15982+ * @v: pointer to type atomic64_unchecked_t
15983+ *
15984+ * Atomically adds @i to @v.
15985+ */
15986+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15987+{
15988 asm volatile(LOCK_PREFIX "addq %1,%0"
15989 : "=m" (v->counter)
15990 : "er" (i), "m" (v->counter));
15991@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15992 */
15993 static inline void atomic64_sub(long i, atomic64_t *v)
15994 {
15995- asm volatile(LOCK_PREFIX "subq %1,%0"
15996+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15997+
15998+#ifdef CONFIG_PAX_REFCOUNT
15999+ "jno 0f\n"
16000+ LOCK_PREFIX "addq %1,%0\n"
16001+ "int $4\n0:\n"
16002+ _ASM_EXTABLE(0b, 0b)
16003+#endif
16004+
16005+ : "=m" (v->counter)
16006+ : "er" (i), "m" (v->counter));
16007+}
16008+
16009+/**
16010+ * atomic64_sub_unchecked - subtract the atomic64 variable
16011+ * @i: integer value to subtract
16012+ * @v: pointer to type atomic64_unchecked_t
16013+ *
16014+ * Atomically subtracts @i from @v.
16015+ */
16016+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
16017+{
16018+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
16019 : "=m" (v->counter)
16020 : "er" (i), "m" (v->counter));
16021 }
16022@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
16023 */
16024 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16025 {
16026- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
16027+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
16028 }
16029
16030 /**
16031@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16032 */
16033 static inline void atomic64_inc(atomic64_t *v)
16034 {
16035+ asm volatile(LOCK_PREFIX "incq %0\n"
16036+
16037+#ifdef CONFIG_PAX_REFCOUNT
16038+ "jno 0f\n"
16039+ LOCK_PREFIX "decq %0\n"
16040+ "int $4\n0:\n"
16041+ _ASM_EXTABLE(0b, 0b)
16042+#endif
16043+
16044+ : "=m" (v->counter)
16045+ : "m" (v->counter));
16046+}
16047+
16048+/**
16049+ * atomic64_inc_unchecked - increment atomic64 variable
16050+ * @v: pointer to type atomic64_unchecked_t
16051+ *
16052+ * Atomically increments @v by 1.
16053+ */
16054+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
16055+{
16056 asm volatile(LOCK_PREFIX "incq %0"
16057 : "=m" (v->counter)
16058 : "m" (v->counter));
16059@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
16060 */
16061 static inline void atomic64_dec(atomic64_t *v)
16062 {
16063- asm volatile(LOCK_PREFIX "decq %0"
16064+ asm volatile(LOCK_PREFIX "decq %0\n"
16065+
16066+#ifdef CONFIG_PAX_REFCOUNT
16067+ "jno 0f\n"
16068+ LOCK_PREFIX "incq %0\n"
16069+ "int $4\n0:\n"
16070+ _ASM_EXTABLE(0b, 0b)
16071+#endif
16072+
16073+ : "=m" (v->counter)
16074+ : "m" (v->counter));
16075+}
16076+
16077+/**
16078+ * atomic64_dec_unchecked - decrement atomic64 variable
16079+ * @v: pointer to type atomic64_t
16080+ *
16081+ * Atomically decrements @v by 1.
16082+ */
16083+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
16084+{
16085+ asm volatile(LOCK_PREFIX "decq %0\n"
16086 : "=m" (v->counter)
16087 : "m" (v->counter));
16088 }
16089@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
16090 */
16091 static inline int atomic64_dec_and_test(atomic64_t *v)
16092 {
16093- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
16094+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
16095 }
16096
16097 /**
16098@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
16099 */
16100 static inline int atomic64_inc_and_test(atomic64_t *v)
16101 {
16102- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
16103+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
16104 }
16105
16106 /**
16107@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
16108 */
16109 static inline int atomic64_add_negative(long i, atomic64_t *v)
16110 {
16111- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
16112+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
16113 }
16114
16115 /**
16116@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
16117 */
16118 static inline long atomic64_add_return(long i, atomic64_t *v)
16119 {
16120+ return i + xadd_check_overflow(&v->counter, i);
16121+}
16122+
16123+/**
16124+ * atomic64_add_return_unchecked - add and return
16125+ * @i: integer value to add
16126+ * @v: pointer to type atomic64_unchecked_t
16127+ *
16128+ * Atomically adds @i to @v and returns @i + @v
16129+ */
16130+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
16131+{
16132 return i + xadd(&v->counter, i);
16133 }
16134
16135@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
16136 }
16137
16138 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
16139+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16140+{
16141+ return atomic64_add_return_unchecked(1, v);
16142+}
16143 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
16144
16145 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16146@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16147 return cmpxchg(&v->counter, old, new);
16148 }
16149
16150+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16151+{
16152+ return cmpxchg(&v->counter, old, new);
16153+}
16154+
16155 static inline long atomic64_xchg(atomic64_t *v, long new)
16156 {
16157 return xchg(&v->counter, new);
16158@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16159 */
16160 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16161 {
16162- long c, old;
16163+ long c, old, new;
16164 c = atomic64_read(v);
16165 for (;;) {
16166- if (unlikely(c == (u)))
16167+ if (unlikely(c == u))
16168 break;
16169- old = atomic64_cmpxchg((v), c, c + (a));
16170+
16171+ asm volatile("add %2,%0\n"
16172+
16173+#ifdef CONFIG_PAX_REFCOUNT
16174+ "jno 0f\n"
16175+ "sub %2,%0\n"
16176+ "int $4\n0:\n"
16177+ _ASM_EXTABLE(0b, 0b)
16178+#endif
16179+
16180+ : "=r" (new)
16181+ : "0" (c), "ir" (a));
16182+
16183+ old = atomic64_cmpxchg(v, c, new);
16184 if (likely(old == c))
16185 break;
16186 c = old;
16187 }
16188- return c != (u);
16189+ return c != u;
16190 }
16191
16192 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16193diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16194index 5c7198c..44180b5 100644
16195--- a/arch/x86/include/asm/barrier.h
16196+++ b/arch/x86/include/asm/barrier.h
16197@@ -107,7 +107,7 @@
16198 do { \
16199 compiletime_assert_atomic_type(*p); \
16200 smp_mb(); \
16201- ACCESS_ONCE(*p) = (v); \
16202+ ACCESS_ONCE_RW(*p) = (v); \
16203 } while (0)
16204
16205 #define smp_load_acquire(p) \
16206@@ -124,7 +124,7 @@ do { \
16207 do { \
16208 compiletime_assert_atomic_type(*p); \
16209 barrier(); \
16210- ACCESS_ONCE(*p) = (v); \
16211+ ACCESS_ONCE_RW(*p) = (v); \
16212 } while (0)
16213
16214 #define smp_load_acquire(p) \
16215diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16216index afcd35d..141b32d 100644
16217--- a/arch/x86/include/asm/bitops.h
16218+++ b/arch/x86/include/asm/bitops.h
16219@@ -50,7 +50,7 @@
16220 * a mask operation on a byte.
16221 */
16222 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16223-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16224+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16225 #define CONST_MASK(nr) (1 << ((nr) & 7))
16226
16227 /**
16228@@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16229 */
16230 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16231 {
16232- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16233+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16234 }
16235
16236 /**
16237@@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16238 */
16239 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16240 {
16241- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16242+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16243 }
16244
16245 /**
16246@@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16247 */
16248 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16249 {
16250- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16251+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16252 }
16253
16254 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16255@@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16256 *
16257 * Undefined if no bit exists, so code should check against 0 first.
16258 */
16259-static inline unsigned long __ffs(unsigned long word)
16260+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16261 {
16262 asm("rep; bsf %1,%0"
16263 : "=r" (word)
16264@@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16265 *
16266 * Undefined if no zero exists, so code should check against ~0UL first.
16267 */
16268-static inline unsigned long ffz(unsigned long word)
16269+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16270 {
16271 asm("rep; bsf %1,%0"
16272 : "=r" (word)
16273@@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16274 *
16275 * Undefined if no set bit exists, so code should check against 0 first.
16276 */
16277-static inline unsigned long __fls(unsigned long word)
16278+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16279 {
16280 asm("bsr %1,%0"
16281 : "=r" (word)
16282@@ -434,7 +434,7 @@ static inline int ffs(int x)
16283 * set bit if value is nonzero. The last (most significant) bit is
16284 * at position 32.
16285 */
16286-static inline int fls(int x)
16287+static inline int __intentional_overflow(-1) fls(int x)
16288 {
16289 int r;
16290
16291@@ -476,7 +476,7 @@ static inline int fls(int x)
16292 * at position 64.
16293 */
16294 #ifdef CONFIG_X86_64
16295-static __always_inline int fls64(__u64 x)
16296+static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16297 {
16298 int bitpos = -1;
16299 /*
16300diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16301index 4fa687a..60f2d39 100644
16302--- a/arch/x86/include/asm/boot.h
16303+++ b/arch/x86/include/asm/boot.h
16304@@ -6,10 +6,15 @@
16305 #include <uapi/asm/boot.h>
16306
16307 /* Physical address where kernel should be loaded. */
16308-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16309+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16310 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16311 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16312
16313+#ifndef __ASSEMBLY__
16314+extern unsigned char __LOAD_PHYSICAL_ADDR[];
16315+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16316+#endif
16317+
16318 /* Minimum kernel alignment, as a power of two */
16319 #ifdef CONFIG_X86_64
16320 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16321diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16322index 48f99f1..d78ebf9 100644
16323--- a/arch/x86/include/asm/cache.h
16324+++ b/arch/x86/include/asm/cache.h
16325@@ -5,12 +5,13 @@
16326
16327 /* L1 cache line size */
16328 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16329-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16330+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16331
16332 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16333+#define __read_only __attribute__((__section__(".data..read_only")))
16334
16335 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16336-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16337+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16338
16339 #ifdef CONFIG_X86_VSMP
16340 #ifdef CONFIG_SMP
16341diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16342index 9863ee3..4a1f8e1 100644
16343--- a/arch/x86/include/asm/cacheflush.h
16344+++ b/arch/x86/include/asm/cacheflush.h
16345@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16346 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16347
16348 if (pg_flags == _PGMT_DEFAULT)
16349- return -1;
16350+ return ~0UL;
16351 else if (pg_flags == _PGMT_WC)
16352 return _PAGE_CACHE_WC;
16353 else if (pg_flags == _PGMT_UC_MINUS)
16354diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16355index cb4c73b..c473c29 100644
16356--- a/arch/x86/include/asm/calling.h
16357+++ b/arch/x86/include/asm/calling.h
16358@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16359 #define RSP 152
16360 #define SS 160
16361
16362-#define ARGOFFSET R11
16363-#define SWFRAME ORIG_RAX
16364+#define ARGOFFSET R15
16365
16366 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16367- subq $9*8+\addskip, %rsp
16368- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16369- movq_cfi rdi, 8*8
16370- movq_cfi rsi, 7*8
16371- movq_cfi rdx, 6*8
16372+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16373+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16374+ movq_cfi rdi, RDI
16375+ movq_cfi rsi, RSI
16376+ movq_cfi rdx, RDX
16377
16378 .if \save_rcx
16379- movq_cfi rcx, 5*8
16380+ movq_cfi rcx, RCX
16381 .endif
16382
16383- movq_cfi rax, 4*8
16384+ movq_cfi rax, RAX
16385
16386 .if \save_r891011
16387- movq_cfi r8, 3*8
16388- movq_cfi r9, 2*8
16389- movq_cfi r10, 1*8
16390- movq_cfi r11, 0*8
16391+ movq_cfi r8, R8
16392+ movq_cfi r9, R9
16393+ movq_cfi r10, R10
16394+ movq_cfi r11, R11
16395 .endif
16396
16397+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16398+ movq_cfi r12, R12
16399+#endif
16400+
16401 .endm
16402
16403-#define ARG_SKIP (9*8)
16404+#define ARG_SKIP ORIG_RAX
16405
16406 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16407 rstor_r8910=1, rstor_rdx=1
16408+
16409+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16410+ movq_cfi_restore R12, r12
16411+#endif
16412+
16413 .if \rstor_r11
16414- movq_cfi_restore 0*8, r11
16415+ movq_cfi_restore R11, r11
16416 .endif
16417
16418 .if \rstor_r8910
16419- movq_cfi_restore 1*8, r10
16420- movq_cfi_restore 2*8, r9
16421- movq_cfi_restore 3*8, r8
16422+ movq_cfi_restore R10, r10
16423+ movq_cfi_restore R9, r9
16424+ movq_cfi_restore R8, r8
16425 .endif
16426
16427 .if \rstor_rax
16428- movq_cfi_restore 4*8, rax
16429+ movq_cfi_restore RAX, rax
16430 .endif
16431
16432 .if \rstor_rcx
16433- movq_cfi_restore 5*8, rcx
16434+ movq_cfi_restore RCX, rcx
16435 .endif
16436
16437 .if \rstor_rdx
16438- movq_cfi_restore 6*8, rdx
16439+ movq_cfi_restore RDX, rdx
16440 .endif
16441
16442- movq_cfi_restore 7*8, rsi
16443- movq_cfi_restore 8*8, rdi
16444+ movq_cfi_restore RSI, rsi
16445+ movq_cfi_restore RDI, rdi
16446
16447- .if ARG_SKIP+\addskip > 0
16448- addq $ARG_SKIP+\addskip, %rsp
16449- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16450+ .if ORIG_RAX+\addskip > 0
16451+ addq $ORIG_RAX+\addskip, %rsp
16452+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16453 .endif
16454 .endm
16455
16456- .macro LOAD_ARGS offset, skiprax=0
16457- movq \offset(%rsp), %r11
16458- movq \offset+8(%rsp), %r10
16459- movq \offset+16(%rsp), %r9
16460- movq \offset+24(%rsp), %r8
16461- movq \offset+40(%rsp), %rcx
16462- movq \offset+48(%rsp), %rdx
16463- movq \offset+56(%rsp), %rsi
16464- movq \offset+64(%rsp), %rdi
16465+ .macro LOAD_ARGS skiprax=0
16466+ movq R11(%rsp), %r11
16467+ movq R10(%rsp), %r10
16468+ movq R9(%rsp), %r9
16469+ movq R8(%rsp), %r8
16470+ movq RCX(%rsp), %rcx
16471+ movq RDX(%rsp), %rdx
16472+ movq RSI(%rsp), %rsi
16473+ movq RDI(%rsp), %rdi
16474 .if \skiprax
16475 .else
16476- movq \offset+72(%rsp), %rax
16477+ movq RAX(%rsp), %rax
16478 .endif
16479 .endm
16480
16481-#define REST_SKIP (6*8)
16482-
16483 .macro SAVE_REST
16484- subq $REST_SKIP, %rsp
16485- CFI_ADJUST_CFA_OFFSET REST_SKIP
16486- movq_cfi rbx, 5*8
16487- movq_cfi rbp, 4*8
16488- movq_cfi r12, 3*8
16489- movq_cfi r13, 2*8
16490- movq_cfi r14, 1*8
16491- movq_cfi r15, 0*8
16492+ movq_cfi rbx, RBX
16493+ movq_cfi rbp, RBP
16494+
16495+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16496+ movq_cfi r12, R12
16497+#endif
16498+
16499+ movq_cfi r13, R13
16500+ movq_cfi r14, R14
16501+ movq_cfi r15, R15
16502 .endm
16503
16504 .macro RESTORE_REST
16505- movq_cfi_restore 0*8, r15
16506- movq_cfi_restore 1*8, r14
16507- movq_cfi_restore 2*8, r13
16508- movq_cfi_restore 3*8, r12
16509- movq_cfi_restore 4*8, rbp
16510- movq_cfi_restore 5*8, rbx
16511- addq $REST_SKIP, %rsp
16512- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16513+ movq_cfi_restore R15, r15
16514+ movq_cfi_restore R14, r14
16515+ movq_cfi_restore R13, r13
16516+
16517+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16518+ movq_cfi_restore R12, r12
16519+#endif
16520+
16521+ movq_cfi_restore RBP, rbp
16522+ movq_cfi_restore RBX, rbx
16523 .endm
16524
16525 .macro SAVE_ALL
16526diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16527index f50de69..2b0a458 100644
16528--- a/arch/x86/include/asm/checksum_32.h
16529+++ b/arch/x86/include/asm/checksum_32.h
16530@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16531 int len, __wsum sum,
16532 int *src_err_ptr, int *dst_err_ptr);
16533
16534+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16535+ int len, __wsum sum,
16536+ int *src_err_ptr, int *dst_err_ptr);
16537+
16538+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16539+ int len, __wsum sum,
16540+ int *src_err_ptr, int *dst_err_ptr);
16541+
16542 /*
16543 * Note: when you get a NULL pointer exception here this means someone
16544 * passed in an incorrect kernel address to one of these functions.
16545@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16546
16547 might_sleep();
16548 stac();
16549- ret = csum_partial_copy_generic((__force void *)src, dst,
16550+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16551 len, sum, err_ptr, NULL);
16552 clac();
16553
16554@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16555 might_sleep();
16556 if (access_ok(VERIFY_WRITE, dst, len)) {
16557 stac();
16558- ret = csum_partial_copy_generic(src, (__force void *)dst,
16559+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16560 len, sum, NULL, err_ptr);
16561 clac();
16562 return ret;
16563diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16564index d47786a..2d8883e 100644
16565--- a/arch/x86/include/asm/cmpxchg.h
16566+++ b/arch/x86/include/asm/cmpxchg.h
16567@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16568 __compiletime_error("Bad argument size for cmpxchg");
16569 extern void __xadd_wrong_size(void)
16570 __compiletime_error("Bad argument size for xadd");
16571+extern void __xadd_check_overflow_wrong_size(void)
16572+ __compiletime_error("Bad argument size for xadd_check_overflow");
16573 extern void __add_wrong_size(void)
16574 __compiletime_error("Bad argument size for add");
16575+extern void __add_check_overflow_wrong_size(void)
16576+ __compiletime_error("Bad argument size for add_check_overflow");
16577
16578 /*
16579 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16580@@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16581 __ret; \
16582 })
16583
16584+#ifdef CONFIG_PAX_REFCOUNT
16585+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16586+ ({ \
16587+ __typeof__ (*(ptr)) __ret = (arg); \
16588+ switch (sizeof(*(ptr))) { \
16589+ case __X86_CASE_L: \
16590+ asm volatile (lock #op "l %0, %1\n" \
16591+ "jno 0f\n" \
16592+ "mov %0,%1\n" \
16593+ "int $4\n0:\n" \
16594+ _ASM_EXTABLE(0b, 0b) \
16595+ : "+r" (__ret), "+m" (*(ptr)) \
16596+ : : "memory", "cc"); \
16597+ break; \
16598+ case __X86_CASE_Q: \
16599+ asm volatile (lock #op "q %q0, %1\n" \
16600+ "jno 0f\n" \
16601+ "mov %0,%1\n" \
16602+ "int $4\n0:\n" \
16603+ _ASM_EXTABLE(0b, 0b) \
16604+ : "+r" (__ret), "+m" (*(ptr)) \
16605+ : : "memory", "cc"); \
16606+ break; \
16607+ default: \
16608+ __ ## op ## _check_overflow_wrong_size(); \
16609+ } \
16610+ __ret; \
16611+ })
16612+#else
16613+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16614+#endif
16615+
16616 /*
16617 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16618 * Since this is generally used to protect other memory information, we
16619@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16620 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16621 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16622
16623+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16624+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16625+
16626 #define __add(ptr, inc, lock) \
16627 ({ \
16628 __typeof__ (*(ptr)) __ret = (inc); \
16629diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16630index 59c6c40..5e0b22c 100644
16631--- a/arch/x86/include/asm/compat.h
16632+++ b/arch/x86/include/asm/compat.h
16633@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16634 typedef u32 compat_uint_t;
16635 typedef u32 compat_ulong_t;
16636 typedef u64 __attribute__((aligned(4))) compat_u64;
16637-typedef u32 compat_uptr_t;
16638+typedef u32 __user compat_uptr_t;
16639
16640 struct compat_timespec {
16641 compat_time_t tv_sec;
16642diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16643index e265ff9..72c253b 100644
16644--- a/arch/x86/include/asm/cpufeature.h
16645+++ b/arch/x86/include/asm/cpufeature.h
16646@@ -203,7 +203,7 @@
16647 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16648 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16649 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16650-
16651+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16652
16653 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16654 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16655@@ -211,7 +211,7 @@
16656 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16657 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16658 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16659-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16660+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16661 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16662 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16663 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16664@@ -359,6 +359,7 @@ extern const char * const x86_power_flags[32];
16665 #undef cpu_has_centaur_mcr
16666 #define cpu_has_centaur_mcr 0
16667
16668+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16669 #endif /* CONFIG_X86_64 */
16670
16671 #if __GNUC__ >= 4
16672@@ -411,7 +412,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16673
16674 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16675 t_warn:
16676- warn_pre_alternatives();
16677+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16678+ warn_pre_alternatives();
16679 return false;
16680 #endif
16681
16682@@ -431,7 +433,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16683 ".section .discard,\"aw\",@progbits\n"
16684 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16685 ".previous\n"
16686- ".section .altinstr_replacement,\"ax\"\n"
16687+ ".section .altinstr_replacement,\"a\"\n"
16688 "3: movb $1,%0\n"
16689 "4:\n"
16690 ".previous\n"
16691@@ -468,7 +470,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16692 " .byte 2b - 1b\n" /* src len */
16693 " .byte 4f - 3f\n" /* repl len */
16694 ".previous\n"
16695- ".section .altinstr_replacement,\"ax\"\n"
16696+ ".section .altinstr_replacement,\"a\"\n"
16697 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16698 "4:\n"
16699 ".previous\n"
16700@@ -501,7 +503,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16701 ".section .discard,\"aw\",@progbits\n"
16702 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16703 ".previous\n"
16704- ".section .altinstr_replacement,\"ax\"\n"
16705+ ".section .altinstr_replacement,\"a\"\n"
16706 "3: movb $0,%0\n"
16707 "4:\n"
16708 ".previous\n"
16709@@ -515,7 +517,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16710 ".section .discard,\"aw\",@progbits\n"
16711 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16712 ".previous\n"
16713- ".section .altinstr_replacement,\"ax\"\n"
16714+ ".section .altinstr_replacement,\"a\"\n"
16715 "5: movb $1,%0\n"
16716 "6:\n"
16717 ".previous\n"
16718diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16719index 50d033a..37deb26 100644
16720--- a/arch/x86/include/asm/desc.h
16721+++ b/arch/x86/include/asm/desc.h
16722@@ -4,6 +4,7 @@
16723 #include <asm/desc_defs.h>
16724 #include <asm/ldt.h>
16725 #include <asm/mmu.h>
16726+#include <asm/pgtable.h>
16727
16728 #include <linux/smp.h>
16729 #include <linux/percpu.h>
16730@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16731
16732 desc->type = (info->read_exec_only ^ 1) << 1;
16733 desc->type |= info->contents << 2;
16734+ desc->type |= info->seg_not_present ^ 1;
16735
16736 desc->s = 1;
16737 desc->dpl = 0x3;
16738@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16739 }
16740
16741 extern struct desc_ptr idt_descr;
16742-extern gate_desc idt_table[];
16743-extern struct desc_ptr debug_idt_descr;
16744-extern gate_desc debug_idt_table[];
16745-
16746-struct gdt_page {
16747- struct desc_struct gdt[GDT_ENTRIES];
16748-} __attribute__((aligned(PAGE_SIZE)));
16749-
16750-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16751+extern gate_desc idt_table[IDT_ENTRIES];
16752+extern const struct desc_ptr debug_idt_descr;
16753+extern gate_desc debug_idt_table[IDT_ENTRIES];
16754
16755+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16756 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16757 {
16758- return per_cpu(gdt_page, cpu).gdt;
16759+ return cpu_gdt_table[cpu];
16760 }
16761
16762 #ifdef CONFIG_X86_64
16763@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16764 unsigned long base, unsigned dpl, unsigned flags,
16765 unsigned short seg)
16766 {
16767- gate->a = (seg << 16) | (base & 0xffff);
16768- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16769+ gate->gate.offset_low = base;
16770+ gate->gate.seg = seg;
16771+ gate->gate.reserved = 0;
16772+ gate->gate.type = type;
16773+ gate->gate.s = 0;
16774+ gate->gate.dpl = dpl;
16775+ gate->gate.p = 1;
16776+ gate->gate.offset_high = base >> 16;
16777 }
16778
16779 #endif
16780@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16781
16782 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16783 {
16784+ pax_open_kernel();
16785 memcpy(&idt[entry], gate, sizeof(*gate));
16786+ pax_close_kernel();
16787 }
16788
16789 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16790 {
16791+ pax_open_kernel();
16792 memcpy(&ldt[entry], desc, 8);
16793+ pax_close_kernel();
16794 }
16795
16796 static inline void
16797@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16798 default: size = sizeof(*gdt); break;
16799 }
16800
16801+ pax_open_kernel();
16802 memcpy(&gdt[entry], desc, size);
16803+ pax_close_kernel();
16804 }
16805
16806 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16807@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16808
16809 static inline void native_load_tr_desc(void)
16810 {
16811+ pax_open_kernel();
16812 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16813+ pax_close_kernel();
16814 }
16815
16816 static inline void native_load_gdt(const struct desc_ptr *dtr)
16817@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16818 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16819 unsigned int i;
16820
16821+ pax_open_kernel();
16822 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16823 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16824+ pax_close_kernel();
16825 }
16826
16827 #define _LDT_empty(info) \
16828@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16829 preempt_enable();
16830 }
16831
16832-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16833+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16834 {
16835 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16836 }
16837@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16838 }
16839
16840 #ifdef CONFIG_X86_64
16841-static inline void set_nmi_gate(int gate, void *addr)
16842+static inline void set_nmi_gate(int gate, const void *addr)
16843 {
16844 gate_desc s;
16845
16846@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16847 #endif
16848
16849 #ifdef CONFIG_TRACING
16850-extern struct desc_ptr trace_idt_descr;
16851-extern gate_desc trace_idt_table[];
16852+extern const struct desc_ptr trace_idt_descr;
16853+extern gate_desc trace_idt_table[IDT_ENTRIES];
16854 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16855 {
16856 write_idt_entry(trace_idt_table, entry, gate);
16857 }
16858
16859-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16860+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16861 unsigned dpl, unsigned ist, unsigned seg)
16862 {
16863 gate_desc s;
16864@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16865 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16866 #endif
16867
16868-static inline void _set_gate(int gate, unsigned type, void *addr,
16869+static inline void _set_gate(int gate, unsigned type, const void *addr,
16870 unsigned dpl, unsigned ist, unsigned seg)
16871 {
16872 gate_desc s;
16873@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16874 #define set_intr_gate(n, addr) \
16875 do { \
16876 BUG_ON((unsigned)n > 0xFF); \
16877- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16878+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16879 __KERNEL_CS); \
16880- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16881+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16882 0, 0, __KERNEL_CS); \
16883 } while (0)
16884
16885@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16886 /*
16887 * This routine sets up an interrupt gate at directory privilege level 3.
16888 */
16889-static inline void set_system_intr_gate(unsigned int n, void *addr)
16890+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16891 {
16892 BUG_ON((unsigned)n > 0xFF);
16893 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16894 }
16895
16896-static inline void set_system_trap_gate(unsigned int n, void *addr)
16897+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16898 {
16899 BUG_ON((unsigned)n > 0xFF);
16900 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16901 }
16902
16903-static inline void set_trap_gate(unsigned int n, void *addr)
16904+static inline void set_trap_gate(unsigned int n, const void *addr)
16905 {
16906 BUG_ON((unsigned)n > 0xFF);
16907 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16908@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16909 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16910 {
16911 BUG_ON((unsigned)n > 0xFF);
16912- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16913+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16914 }
16915
16916-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16917+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16918 {
16919 BUG_ON((unsigned)n > 0xFF);
16920 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16921 }
16922
16923-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16924+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16925 {
16926 BUG_ON((unsigned)n > 0xFF);
16927 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16928@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16929 else
16930 load_idt((const struct desc_ptr *)&idt_descr);
16931 }
16932+
16933+#ifdef CONFIG_X86_32
16934+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16935+{
16936+ struct desc_struct d;
16937+
16938+ if (likely(limit))
16939+ limit = (limit - 1UL) >> PAGE_SHIFT;
16940+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16941+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16942+}
16943+#endif
16944+
16945 #endif /* _ASM_X86_DESC_H */
16946diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16947index 278441f..b95a174 100644
16948--- a/arch/x86/include/asm/desc_defs.h
16949+++ b/arch/x86/include/asm/desc_defs.h
16950@@ -31,6 +31,12 @@ struct desc_struct {
16951 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16952 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16953 };
16954+ struct {
16955+ u16 offset_low;
16956+ u16 seg;
16957+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16958+ unsigned offset_high: 16;
16959+ } gate;
16960 };
16961 } __attribute__((packed));
16962
16963diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16964index ced283a..ffe04cc 100644
16965--- a/arch/x86/include/asm/div64.h
16966+++ b/arch/x86/include/asm/div64.h
16967@@ -39,7 +39,7 @@
16968 __mod; \
16969 })
16970
16971-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16972+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16973 {
16974 union {
16975 u64 v64;
16976diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16977index 1a055c8..a1701de 100644
16978--- a/arch/x86/include/asm/elf.h
16979+++ b/arch/x86/include/asm/elf.h
16980@@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
16981
16982 #include <asm/vdso.h>
16983
16984-#ifdef CONFIG_X86_64
16985-extern unsigned int vdso64_enabled;
16986-#endif
16987 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
16988 extern unsigned int vdso32_enabled;
16989 #endif
16990@@ -248,7 +245,25 @@ extern int force_personality32;
16991 the loader. We need to make sure that it is out of the way of the program
16992 that it will "exec", and that there is sufficient room for the brk. */
16993
16994+#ifdef CONFIG_PAX_SEGMEXEC
16995+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16996+#else
16997 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16998+#endif
16999+
17000+#ifdef CONFIG_PAX_ASLR
17001+#ifdef CONFIG_X86_32
17002+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
17003+
17004+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17005+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17006+#else
17007+#define PAX_ELF_ET_DYN_BASE 0x400000UL
17008+
17009+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17010+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17011+#endif
17012+#endif
17013
17014 /* This yields a mask that user programs can use to figure out what
17015 instruction set this CPU supports. This could be done in user space,
17016@@ -297,17 +312,13 @@ do { \
17017
17018 #define ARCH_DLINFO \
17019 do { \
17020- if (vdso64_enabled) \
17021- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17022- (unsigned long __force)current->mm->context.vdso); \
17023+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17024 } while (0)
17025
17026 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
17027 #define ARCH_DLINFO_X32 \
17028 do { \
17029- if (vdso64_enabled) \
17030- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17031- (unsigned long __force)current->mm->context.vdso); \
17032+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17033 } while (0)
17034
17035 #define AT_SYSINFO 32
17036@@ -322,10 +333,10 @@ else \
17037
17038 #endif /* !CONFIG_X86_32 */
17039
17040-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
17041+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
17042
17043 #define VDSO_ENTRY \
17044- ((unsigned long)current->mm->context.vdso + \
17045+ (current->mm->context.vdso + \
17046 selected_vdso32->sym___kernel_vsyscall)
17047
17048 struct linux_binprm;
17049@@ -337,9 +348,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
17050 int uses_interp);
17051 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
17052
17053-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
17054-#define arch_randomize_brk arch_randomize_brk
17055-
17056 /*
17057 * True on X86_32 or when emulating IA32 on X86_64
17058 */
17059diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
17060index 77a99ac..39ff7f5 100644
17061--- a/arch/x86/include/asm/emergency-restart.h
17062+++ b/arch/x86/include/asm/emergency-restart.h
17063@@ -1,6 +1,6 @@
17064 #ifndef _ASM_X86_EMERGENCY_RESTART_H
17065 #define _ASM_X86_EMERGENCY_RESTART_H
17066
17067-extern void machine_emergency_restart(void);
17068+extern void machine_emergency_restart(void) __noreturn;
17069
17070 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
17071diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
17072index 1c7eefe..d0e4702 100644
17073--- a/arch/x86/include/asm/floppy.h
17074+++ b/arch/x86/include/asm/floppy.h
17075@@ -229,18 +229,18 @@ static struct fd_routine_l {
17076 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
17077 } fd_routine[] = {
17078 {
17079- request_dma,
17080- free_dma,
17081- get_dma_residue,
17082- dma_mem_alloc,
17083- hard_dma_setup
17084+ ._request_dma = request_dma,
17085+ ._free_dma = free_dma,
17086+ ._get_dma_residue = get_dma_residue,
17087+ ._dma_mem_alloc = dma_mem_alloc,
17088+ ._dma_setup = hard_dma_setup
17089 },
17090 {
17091- vdma_request_dma,
17092- vdma_nop,
17093- vdma_get_dma_residue,
17094- vdma_mem_alloc,
17095- vdma_dma_setup
17096+ ._request_dma = vdma_request_dma,
17097+ ._free_dma = vdma_nop,
17098+ ._get_dma_residue = vdma_get_dma_residue,
17099+ ._dma_mem_alloc = vdma_mem_alloc,
17100+ ._dma_setup = vdma_dma_setup
17101 }
17102 };
17103
17104diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
17105index 115e368..76ecf6c 100644
17106--- a/arch/x86/include/asm/fpu-internal.h
17107+++ b/arch/x86/include/asm/fpu-internal.h
17108@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17109 #define user_insn(insn, output, input...) \
17110 ({ \
17111 int err; \
17112+ pax_open_userland(); \
17113 asm volatile(ASM_STAC "\n" \
17114- "1:" #insn "\n\t" \
17115+ "1:" \
17116+ __copyuser_seg \
17117+ #insn "\n\t" \
17118 "2: " ASM_CLAC "\n" \
17119 ".section .fixup,\"ax\"\n" \
17120 "3: movl $-1,%[err]\n" \
17121@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17122 _ASM_EXTABLE(1b, 3b) \
17123 : [err] "=r" (err), output \
17124 : "0"(0), input); \
17125+ pax_close_userland(); \
17126 err; \
17127 })
17128
17129@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
17130 "fnclex\n\t"
17131 "emms\n\t"
17132 "fildl %P[addr]" /* set F?P to defined value */
17133- : : [addr] "m" (tsk->thread.fpu.has_fpu));
17134+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
17135 }
17136
17137 return fpu_restore_checking(&tsk->thread.fpu);
17138diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
17139index b4c1f54..e290c08 100644
17140--- a/arch/x86/include/asm/futex.h
17141+++ b/arch/x86/include/asm/futex.h
17142@@ -12,6 +12,7 @@
17143 #include <asm/smap.h>
17144
17145 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17146+ typecheck(u32 __user *, uaddr); \
17147 asm volatile("\t" ASM_STAC "\n" \
17148 "1:\t" insn "\n" \
17149 "2:\t" ASM_CLAC "\n" \
17150@@ -20,15 +21,16 @@
17151 "\tjmp\t2b\n" \
17152 "\t.previous\n" \
17153 _ASM_EXTABLE(1b, 3b) \
17154- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17155+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17156 : "i" (-EFAULT), "0" (oparg), "1" (0))
17157
17158 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17159+ typecheck(u32 __user *, uaddr); \
17160 asm volatile("\t" ASM_STAC "\n" \
17161 "1:\tmovl %2, %0\n" \
17162 "\tmovl\t%0, %3\n" \
17163 "\t" insn "\n" \
17164- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17165+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17166 "\tjnz\t1b\n" \
17167 "3:\t" ASM_CLAC "\n" \
17168 "\t.section .fixup,\"ax\"\n" \
17169@@ -38,7 +40,7 @@
17170 _ASM_EXTABLE(1b, 4b) \
17171 _ASM_EXTABLE(2b, 4b) \
17172 : "=&a" (oldval), "=&r" (ret), \
17173- "+m" (*uaddr), "=&r" (tem) \
17174+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17175 : "r" (oparg), "i" (-EFAULT), "1" (0))
17176
17177 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17178@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17179
17180 pagefault_disable();
17181
17182+ pax_open_userland();
17183 switch (op) {
17184 case FUTEX_OP_SET:
17185- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17186+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17187 break;
17188 case FUTEX_OP_ADD:
17189- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17190+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17191 uaddr, oparg);
17192 break;
17193 case FUTEX_OP_OR:
17194@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17195 default:
17196 ret = -ENOSYS;
17197 }
17198+ pax_close_userland();
17199
17200 pagefault_enable();
17201
17202diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17203index 4615906..788c817 100644
17204--- a/arch/x86/include/asm/hw_irq.h
17205+++ b/arch/x86/include/asm/hw_irq.h
17206@@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17207 extern void enable_IO_APIC(void);
17208
17209 /* Statistics */
17210-extern atomic_t irq_err_count;
17211-extern atomic_t irq_mis_count;
17212+extern atomic_unchecked_t irq_err_count;
17213+extern atomic_unchecked_t irq_mis_count;
17214
17215 /* EISA */
17216 extern void eisa_set_level_irq(unsigned int irq);
17217diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17218index a203659..9889f1c 100644
17219--- a/arch/x86/include/asm/i8259.h
17220+++ b/arch/x86/include/asm/i8259.h
17221@@ -62,7 +62,7 @@ struct legacy_pic {
17222 void (*init)(int auto_eoi);
17223 int (*irq_pending)(unsigned int irq);
17224 void (*make_irq)(unsigned int irq);
17225-};
17226+} __do_const;
17227
17228 extern struct legacy_pic *legacy_pic;
17229 extern struct legacy_pic null_legacy_pic;
17230diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17231index b8237d8..3e8864e 100644
17232--- a/arch/x86/include/asm/io.h
17233+++ b/arch/x86/include/asm/io.h
17234@@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17235 "m" (*(volatile type __force *)addr) barrier); }
17236
17237 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17238-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17239-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17240+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17241+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17242
17243 build_mmio_read(__readb, "b", unsigned char, "=q", )
17244-build_mmio_read(__readw, "w", unsigned short, "=r", )
17245-build_mmio_read(__readl, "l", unsigned int, "=r", )
17246+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17247+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17248
17249 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17250 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17251@@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17252 * this function
17253 */
17254
17255-static inline phys_addr_t virt_to_phys(volatile void *address)
17256+static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17257 {
17258 return __pa(address);
17259 }
17260@@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17261 return ioremap_nocache(offset, size);
17262 }
17263
17264-extern void iounmap(volatile void __iomem *addr);
17265+extern void iounmap(const volatile void __iomem *addr);
17266
17267 extern void set_iounmap_nonlazy(void);
17268
17269@@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17270
17271 #include <linux/vmalloc.h>
17272
17273+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17274+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17275+{
17276+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17277+}
17278+
17279+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17280+{
17281+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17282+}
17283+
17284 /*
17285 * Convert a virtual cached pointer to an uncached pointer
17286 */
17287diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17288index 0a8b519..80e7d5b 100644
17289--- a/arch/x86/include/asm/irqflags.h
17290+++ b/arch/x86/include/asm/irqflags.h
17291@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17292 sti; \
17293 sysexit
17294
17295+#define GET_CR0_INTO_RDI mov %cr0, %rdi
17296+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17297+#define GET_CR3_INTO_RDI mov %cr3, %rdi
17298+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17299+
17300 #else
17301 #define INTERRUPT_RETURN iret
17302 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17303diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17304index 53cdfb2..d1369e6 100644
17305--- a/arch/x86/include/asm/kprobes.h
17306+++ b/arch/x86/include/asm/kprobes.h
17307@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17308 #define RELATIVEJUMP_SIZE 5
17309 #define RELATIVECALL_OPCODE 0xe8
17310 #define RELATIVE_ADDR_SIZE 4
17311-#define MAX_STACK_SIZE 64
17312-#define MIN_STACK_SIZE(ADDR) \
17313- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17314- THREAD_SIZE - (unsigned long)(ADDR))) \
17315- ? (MAX_STACK_SIZE) \
17316- : (((unsigned long)current_thread_info()) + \
17317- THREAD_SIZE - (unsigned long)(ADDR)))
17318+#define MAX_STACK_SIZE 64UL
17319+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17320
17321 #define flush_insn_slot(p) do { } while (0)
17322
17323diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17324index 4ad6560..75c7bdd 100644
17325--- a/arch/x86/include/asm/local.h
17326+++ b/arch/x86/include/asm/local.h
17327@@ -10,33 +10,97 @@ typedef struct {
17328 atomic_long_t a;
17329 } local_t;
17330
17331+typedef struct {
17332+ atomic_long_unchecked_t a;
17333+} local_unchecked_t;
17334+
17335 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17336
17337 #define local_read(l) atomic_long_read(&(l)->a)
17338+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17339 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17340+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17341
17342 static inline void local_inc(local_t *l)
17343 {
17344- asm volatile(_ASM_INC "%0"
17345+ asm volatile(_ASM_INC "%0\n"
17346+
17347+#ifdef CONFIG_PAX_REFCOUNT
17348+ "jno 0f\n"
17349+ _ASM_DEC "%0\n"
17350+ "int $4\n0:\n"
17351+ _ASM_EXTABLE(0b, 0b)
17352+#endif
17353+
17354+ : "+m" (l->a.counter));
17355+}
17356+
17357+static inline void local_inc_unchecked(local_unchecked_t *l)
17358+{
17359+ asm volatile(_ASM_INC "%0\n"
17360 : "+m" (l->a.counter));
17361 }
17362
17363 static inline void local_dec(local_t *l)
17364 {
17365- asm volatile(_ASM_DEC "%0"
17366+ asm volatile(_ASM_DEC "%0\n"
17367+
17368+#ifdef CONFIG_PAX_REFCOUNT
17369+ "jno 0f\n"
17370+ _ASM_INC "%0\n"
17371+ "int $4\n0:\n"
17372+ _ASM_EXTABLE(0b, 0b)
17373+#endif
17374+
17375+ : "+m" (l->a.counter));
17376+}
17377+
17378+static inline void local_dec_unchecked(local_unchecked_t *l)
17379+{
17380+ asm volatile(_ASM_DEC "%0\n"
17381 : "+m" (l->a.counter));
17382 }
17383
17384 static inline void local_add(long i, local_t *l)
17385 {
17386- asm volatile(_ASM_ADD "%1,%0"
17387+ asm volatile(_ASM_ADD "%1,%0\n"
17388+
17389+#ifdef CONFIG_PAX_REFCOUNT
17390+ "jno 0f\n"
17391+ _ASM_SUB "%1,%0\n"
17392+ "int $4\n0:\n"
17393+ _ASM_EXTABLE(0b, 0b)
17394+#endif
17395+
17396+ : "+m" (l->a.counter)
17397+ : "ir" (i));
17398+}
17399+
17400+static inline void local_add_unchecked(long i, local_unchecked_t *l)
17401+{
17402+ asm volatile(_ASM_ADD "%1,%0\n"
17403 : "+m" (l->a.counter)
17404 : "ir" (i));
17405 }
17406
17407 static inline void local_sub(long i, local_t *l)
17408 {
17409- asm volatile(_ASM_SUB "%1,%0"
17410+ asm volatile(_ASM_SUB "%1,%0\n"
17411+
17412+#ifdef CONFIG_PAX_REFCOUNT
17413+ "jno 0f\n"
17414+ _ASM_ADD "%1,%0\n"
17415+ "int $4\n0:\n"
17416+ _ASM_EXTABLE(0b, 0b)
17417+#endif
17418+
17419+ : "+m" (l->a.counter)
17420+ : "ir" (i));
17421+}
17422+
17423+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17424+{
17425+ asm volatile(_ASM_SUB "%1,%0\n"
17426 : "+m" (l->a.counter)
17427 : "ir" (i));
17428 }
17429@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17430 */
17431 static inline int local_sub_and_test(long i, local_t *l)
17432 {
17433- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17434+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17435 }
17436
17437 /**
17438@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17439 */
17440 static inline int local_dec_and_test(local_t *l)
17441 {
17442- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17443+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17444 }
17445
17446 /**
17447@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17448 */
17449 static inline int local_inc_and_test(local_t *l)
17450 {
17451- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17452+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17453 }
17454
17455 /**
17456@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17457 */
17458 static inline int local_add_negative(long i, local_t *l)
17459 {
17460- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17461+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17462 }
17463
17464 /**
17465@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17466 static inline long local_add_return(long i, local_t *l)
17467 {
17468 long __i = i;
17469+ asm volatile(_ASM_XADD "%0, %1\n"
17470+
17471+#ifdef CONFIG_PAX_REFCOUNT
17472+ "jno 0f\n"
17473+ _ASM_MOV "%0,%1\n"
17474+ "int $4\n0:\n"
17475+ _ASM_EXTABLE(0b, 0b)
17476+#endif
17477+
17478+ : "+r" (i), "+m" (l->a.counter)
17479+ : : "memory");
17480+ return i + __i;
17481+}
17482+
17483+/**
17484+ * local_add_return_unchecked - add and return
17485+ * @i: integer value to add
17486+ * @l: pointer to type local_unchecked_t
17487+ *
17488+ * Atomically adds @i to @l and returns @i + @l
17489+ */
17490+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17491+{
17492+ long __i = i;
17493 asm volatile(_ASM_XADD "%0, %1;"
17494 : "+r" (i), "+m" (l->a.counter)
17495 : : "memory");
17496@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17497
17498 #define local_cmpxchg(l, o, n) \
17499 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17500+#define local_cmpxchg_unchecked(l, o, n) \
17501+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
17502 /* Always has a lock prefix */
17503 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17504
17505diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17506new file mode 100644
17507index 0000000..2bfd3ba
17508--- /dev/null
17509+++ b/arch/x86/include/asm/mman.h
17510@@ -0,0 +1,15 @@
17511+#ifndef _X86_MMAN_H
17512+#define _X86_MMAN_H
17513+
17514+#include <uapi/asm/mman.h>
17515+
17516+#ifdef __KERNEL__
17517+#ifndef __ASSEMBLY__
17518+#ifdef CONFIG_X86_32
17519+#define arch_mmap_check i386_mmap_check
17520+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17521+#endif
17522+#endif
17523+#endif
17524+
17525+#endif /* X86_MMAN_H */
17526diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17527index 876e74e..e20bfb1 100644
17528--- a/arch/x86/include/asm/mmu.h
17529+++ b/arch/x86/include/asm/mmu.h
17530@@ -9,7 +9,7 @@
17531 * we put the segment information here.
17532 */
17533 typedef struct {
17534- void *ldt;
17535+ struct desc_struct *ldt;
17536 int size;
17537
17538 #ifdef CONFIG_X86_64
17539@@ -18,7 +18,19 @@ typedef struct {
17540 #endif
17541
17542 struct mutex lock;
17543- void __user *vdso;
17544+ unsigned long vdso;
17545+
17546+#ifdef CONFIG_X86_32
17547+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17548+ unsigned long user_cs_base;
17549+ unsigned long user_cs_limit;
17550+
17551+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17552+ cpumask_t cpu_user_cs_mask;
17553+#endif
17554+
17555+#endif
17556+#endif
17557 } mm_context_t;
17558
17559 #ifdef CONFIG_SMP
17560diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17561index be12c53..07fd3ca 100644
17562--- a/arch/x86/include/asm/mmu_context.h
17563+++ b/arch/x86/include/asm/mmu_context.h
17564@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17565
17566 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17567 {
17568+
17569+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17570+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17571+ unsigned int i;
17572+ pgd_t *pgd;
17573+
17574+ pax_open_kernel();
17575+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17576+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17577+ set_pgd_batched(pgd+i, native_make_pgd(0));
17578+ pax_close_kernel();
17579+ }
17580+#endif
17581+
17582 #ifdef CONFIG_SMP
17583 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17584 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17585@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17586 struct task_struct *tsk)
17587 {
17588 unsigned cpu = smp_processor_id();
17589+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17590+ int tlbstate = TLBSTATE_OK;
17591+#endif
17592
17593 if (likely(prev != next)) {
17594 #ifdef CONFIG_SMP
17595+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17596+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17597+#endif
17598 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17599 this_cpu_write(cpu_tlbstate.active_mm, next);
17600 #endif
17601 cpumask_set_cpu(cpu, mm_cpumask(next));
17602
17603 /* Re-load page tables */
17604+#ifdef CONFIG_PAX_PER_CPU_PGD
17605+ pax_open_kernel();
17606+
17607+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17608+ if (static_cpu_has(X86_FEATURE_PCID))
17609+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17610+ else
17611+#endif
17612+
17613+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17614+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17615+ pax_close_kernel();
17616+ BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
17617+
17618+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17619+ if (static_cpu_has(X86_FEATURE_PCID)) {
17620+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17621+ u64 descriptor[2];
17622+ descriptor[0] = PCID_USER;
17623+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17624+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17625+ descriptor[0] = PCID_KERNEL;
17626+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17627+ }
17628+ } else {
17629+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17630+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17631+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17632+ else
17633+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17634+ }
17635+ } else
17636+#endif
17637+
17638+ load_cr3(get_cpu_pgd(cpu, kernel));
17639+#else
17640 load_cr3(next->pgd);
17641+#endif
17642
17643 /* Stop flush ipis for the previous mm */
17644 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17645@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17646 /* Load the LDT, if the LDT is different: */
17647 if (unlikely(prev->context.ldt != next->context.ldt))
17648 load_LDT_nolock(&next->context);
17649+
17650+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17651+ if (!(__supported_pte_mask & _PAGE_NX)) {
17652+ smp_mb__before_atomic();
17653+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17654+ smp_mb__after_atomic();
17655+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17656+ }
17657+#endif
17658+
17659+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17660+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17661+ prev->context.user_cs_limit != next->context.user_cs_limit))
17662+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17663+#ifdef CONFIG_SMP
17664+ else if (unlikely(tlbstate != TLBSTATE_OK))
17665+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17666+#endif
17667+#endif
17668+
17669 }
17670+ else {
17671+
17672+#ifdef CONFIG_PAX_PER_CPU_PGD
17673+ pax_open_kernel();
17674+
17675+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17676+ if (static_cpu_has(X86_FEATURE_PCID))
17677+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17678+ else
17679+#endif
17680+
17681+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17682+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17683+ pax_close_kernel();
17684+ BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
17685+
17686+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17687+ if (static_cpu_has(X86_FEATURE_PCID)) {
17688+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17689+ u64 descriptor[2];
17690+ descriptor[0] = PCID_USER;
17691+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17692+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17693+ descriptor[0] = PCID_KERNEL;
17694+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17695+ }
17696+ } else {
17697+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17698+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17699+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17700+ else
17701+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17702+ }
17703+ } else
17704+#endif
17705+
17706+ load_cr3(get_cpu_pgd(cpu, kernel));
17707+#endif
17708+
17709 #ifdef CONFIG_SMP
17710- else {
17711 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17712 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17713
17714@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17715 * tlb flush IPI delivery. We must reload CR3
17716 * to make sure to use no freed page tables.
17717 */
17718+
17719+#ifndef CONFIG_PAX_PER_CPU_PGD
17720 load_cr3(next->pgd);
17721+#endif
17722+
17723 load_LDT_nolock(&next->context);
17724+
17725+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17726+ if (!(__supported_pte_mask & _PAGE_NX))
17727+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17728+#endif
17729+
17730+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17731+#ifdef CONFIG_PAX_PAGEEXEC
17732+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17733+#endif
17734+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17735+#endif
17736+
17737 }
17738+#endif
17739 }
17740-#endif
17741 }
17742
17743 #define activate_mm(prev, next) \
17744diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17745index e3b7819..b257c64 100644
17746--- a/arch/x86/include/asm/module.h
17747+++ b/arch/x86/include/asm/module.h
17748@@ -5,6 +5,7 @@
17749
17750 #ifdef CONFIG_X86_64
17751 /* X86_64 does not define MODULE_PROC_FAMILY */
17752+#define MODULE_PROC_FAMILY ""
17753 #elif defined CONFIG_M486
17754 #define MODULE_PROC_FAMILY "486 "
17755 #elif defined CONFIG_M586
17756@@ -57,8 +58,20 @@
17757 #error unknown processor family
17758 #endif
17759
17760-#ifdef CONFIG_X86_32
17761-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17762+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17763+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17764+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17765+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17766+#else
17767+#define MODULE_PAX_KERNEXEC ""
17768 #endif
17769
17770+#ifdef CONFIG_PAX_MEMORY_UDEREF
17771+#define MODULE_PAX_UDEREF "UDEREF "
17772+#else
17773+#define MODULE_PAX_UDEREF ""
17774+#endif
17775+
17776+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17777+
17778 #endif /* _ASM_X86_MODULE_H */
17779diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17780index 5f2fc44..106caa6 100644
17781--- a/arch/x86/include/asm/nmi.h
17782+++ b/arch/x86/include/asm/nmi.h
17783@@ -36,26 +36,35 @@ enum {
17784
17785 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17786
17787+struct nmiaction;
17788+
17789+struct nmiwork {
17790+ const struct nmiaction *action;
17791+ u64 max_duration;
17792+ struct irq_work irq_work;
17793+};
17794+
17795 struct nmiaction {
17796 struct list_head list;
17797 nmi_handler_t handler;
17798- u64 max_duration;
17799- struct irq_work irq_work;
17800 unsigned long flags;
17801 const char *name;
17802-};
17803+ struct nmiwork *work;
17804+} __do_const;
17805
17806 #define register_nmi_handler(t, fn, fg, n, init...) \
17807 ({ \
17808- static struct nmiaction init fn##_na = { \
17809+ static struct nmiwork fn##_nw; \
17810+ static const struct nmiaction init fn##_na = { \
17811 .handler = (fn), \
17812 .name = (n), \
17813 .flags = (fg), \
17814+ .work = &fn##_nw, \
17815 }; \
17816 __register_nmi_handler((t), &fn##_na); \
17817 })
17818
17819-int __register_nmi_handler(unsigned int, struct nmiaction *);
17820+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17821
17822 void unregister_nmi_handler(unsigned int, const char *);
17823
17824diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17825index 775873d..04cd306 100644
17826--- a/arch/x86/include/asm/page.h
17827+++ b/arch/x86/include/asm/page.h
17828@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17829 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17830
17831 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17832+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17833
17834 #define __boot_va(x) __va(x)
17835 #define __boot_pa(x) __pa(x)
17836@@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17837 * virt_to_page(kaddr) returns a valid pointer if and only if
17838 * virt_addr_valid(kaddr) returns true.
17839 */
17840-#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17841 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17842 extern bool __virt_addr_valid(unsigned long kaddr);
17843 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17844
17845+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17846+#define virt_to_page(kaddr) \
17847+ ({ \
17848+ const void *__kaddr = (const void *)(kaddr); \
17849+ BUG_ON(!virt_addr_valid(__kaddr)); \
17850+ pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17851+ })
17852+#else
17853+#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17854+#endif
17855+
17856 #endif /* __ASSEMBLY__ */
17857
17858 #include <asm-generic/memory_model.h>
17859diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17860index 0f1ddee..e2fc3d1 100644
17861--- a/arch/x86/include/asm/page_64.h
17862+++ b/arch/x86/include/asm/page_64.h
17863@@ -7,9 +7,9 @@
17864
17865 /* duplicated to the one in bootmem.h */
17866 extern unsigned long max_pfn;
17867-extern unsigned long phys_base;
17868+extern const unsigned long phys_base;
17869
17870-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17871+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17872 {
17873 unsigned long y = x - __START_KERNEL_map;
17874
17875diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17876index cd6e1610..70f4418 100644
17877--- a/arch/x86/include/asm/paravirt.h
17878+++ b/arch/x86/include/asm/paravirt.h
17879@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17880 return (pmd_t) { ret };
17881 }
17882
17883-static inline pmdval_t pmd_val(pmd_t pmd)
17884+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17885 {
17886 pmdval_t ret;
17887
17888@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17889 val);
17890 }
17891
17892+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17893+{
17894+ pgdval_t val = native_pgd_val(pgd);
17895+
17896+ if (sizeof(pgdval_t) > sizeof(long))
17897+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17898+ val, (u64)val >> 32);
17899+ else
17900+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17901+ val);
17902+}
17903+
17904 static inline void pgd_clear(pgd_t *pgdp)
17905 {
17906 set_pgd(pgdp, __pgd(0));
17907@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17908 pv_mmu_ops.set_fixmap(idx, phys, flags);
17909 }
17910
17911+#ifdef CONFIG_PAX_KERNEXEC
17912+static inline unsigned long pax_open_kernel(void)
17913+{
17914+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17915+}
17916+
17917+static inline unsigned long pax_close_kernel(void)
17918+{
17919+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17920+}
17921+#else
17922+static inline unsigned long pax_open_kernel(void) { return 0; }
17923+static inline unsigned long pax_close_kernel(void) { return 0; }
17924+#endif
17925+
17926 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17927
17928 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17929@@ -906,7 +933,7 @@ extern void default_banner(void);
17930
17931 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17932 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17933-#define PARA_INDIRECT(addr) *%cs:addr
17934+#define PARA_INDIRECT(addr) *%ss:addr
17935 #endif
17936
17937 #define INTERRUPT_RETURN \
17938@@ -981,6 +1008,21 @@ extern void default_banner(void);
17939 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17940 CLBR_NONE, \
17941 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17942+
17943+#define GET_CR0_INTO_RDI \
17944+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17945+ mov %rax,%rdi
17946+
17947+#define SET_RDI_INTO_CR0 \
17948+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17949+
17950+#define GET_CR3_INTO_RDI \
17951+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17952+ mov %rax,%rdi
17953+
17954+#define SET_RDI_INTO_CR3 \
17955+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17956+
17957 #endif /* CONFIG_X86_32 */
17958
17959 #endif /* __ASSEMBLY__ */
17960diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17961index 7549b8b..f0edfda 100644
17962--- a/arch/x86/include/asm/paravirt_types.h
17963+++ b/arch/x86/include/asm/paravirt_types.h
17964@@ -84,7 +84,7 @@ struct pv_init_ops {
17965 */
17966 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17967 unsigned long addr, unsigned len);
17968-};
17969+} __no_const __no_randomize_layout;
17970
17971
17972 struct pv_lazy_ops {
17973@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17974 void (*enter)(void);
17975 void (*leave)(void);
17976 void (*flush)(void);
17977-};
17978+} __no_randomize_layout;
17979
17980 struct pv_time_ops {
17981 unsigned long long (*sched_clock)(void);
17982 unsigned long long (*steal_clock)(int cpu);
17983 unsigned long (*get_tsc_khz)(void);
17984-};
17985+} __no_const __no_randomize_layout;
17986
17987 struct pv_cpu_ops {
17988 /* hooks for various privileged instructions */
17989@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17990
17991 void (*start_context_switch)(struct task_struct *prev);
17992 void (*end_context_switch)(struct task_struct *next);
17993-};
17994+} __no_const __no_randomize_layout;
17995
17996 struct pv_irq_ops {
17997 /*
17998@@ -215,7 +215,7 @@ struct pv_irq_ops {
17999 #ifdef CONFIG_X86_64
18000 void (*adjust_exception_frame)(void);
18001 #endif
18002-};
18003+} __no_randomize_layout;
18004
18005 struct pv_apic_ops {
18006 #ifdef CONFIG_X86_LOCAL_APIC
18007@@ -223,7 +223,7 @@ struct pv_apic_ops {
18008 unsigned long start_eip,
18009 unsigned long start_esp);
18010 #endif
18011-};
18012+} __no_const __no_randomize_layout;
18013
18014 struct pv_mmu_ops {
18015 unsigned long (*read_cr2)(void);
18016@@ -313,6 +313,7 @@ struct pv_mmu_ops {
18017 struct paravirt_callee_save make_pud;
18018
18019 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
18020+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
18021 #endif /* PAGETABLE_LEVELS == 4 */
18022 #endif /* PAGETABLE_LEVELS >= 3 */
18023
18024@@ -324,7 +325,13 @@ struct pv_mmu_ops {
18025 an mfn. We can tell which is which from the index. */
18026 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
18027 phys_addr_t phys, pgprot_t flags);
18028-};
18029+
18030+#ifdef CONFIG_PAX_KERNEXEC
18031+ unsigned long (*pax_open_kernel)(void);
18032+ unsigned long (*pax_close_kernel)(void);
18033+#endif
18034+
18035+} __no_randomize_layout;
18036
18037 struct arch_spinlock;
18038 #ifdef CONFIG_SMP
18039@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
18040 struct pv_lock_ops {
18041 struct paravirt_callee_save lock_spinning;
18042 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
18043-};
18044+} __no_randomize_layout;
18045
18046 /* This contains all the paravirt structures: we get a convenient
18047 * number for each function using the offset which we use to indicate
18048- * what to patch. */
18049+ * what to patch.
18050+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
18051+ */
18052+
18053 struct paravirt_patch_template {
18054 struct pv_init_ops pv_init_ops;
18055 struct pv_time_ops pv_time_ops;
18056@@ -349,7 +359,7 @@ struct paravirt_patch_template {
18057 struct pv_apic_ops pv_apic_ops;
18058 struct pv_mmu_ops pv_mmu_ops;
18059 struct pv_lock_ops pv_lock_ops;
18060-};
18061+} __no_randomize_layout;
18062
18063 extern struct pv_info pv_info;
18064 extern struct pv_init_ops pv_init_ops;
18065diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
18066index c4412e9..90e88c5 100644
18067--- a/arch/x86/include/asm/pgalloc.h
18068+++ b/arch/x86/include/asm/pgalloc.h
18069@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
18070 pmd_t *pmd, pte_t *pte)
18071 {
18072 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18073+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
18074+}
18075+
18076+static inline void pmd_populate_user(struct mm_struct *mm,
18077+ pmd_t *pmd, pte_t *pte)
18078+{
18079+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18080 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
18081 }
18082
18083@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
18084
18085 #ifdef CONFIG_X86_PAE
18086 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
18087+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
18088+{
18089+ pud_populate(mm, pudp, pmd);
18090+}
18091 #else /* !CONFIG_X86_PAE */
18092 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18093 {
18094 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18095 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
18096 }
18097+
18098+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18099+{
18100+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18101+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
18102+}
18103 #endif /* CONFIG_X86_PAE */
18104
18105 #if PAGETABLE_LEVELS > 3
18106@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18107 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
18108 }
18109
18110+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18111+{
18112+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
18113+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
18114+}
18115+
18116 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
18117 {
18118 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
18119diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
18120index 206a87f..1623b06 100644
18121--- a/arch/x86/include/asm/pgtable-2level.h
18122+++ b/arch/x86/include/asm/pgtable-2level.h
18123@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
18124
18125 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18126 {
18127+ pax_open_kernel();
18128 *pmdp = pmd;
18129+ pax_close_kernel();
18130 }
18131
18132 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18133diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18134index 81bb91b..9392125 100644
18135--- a/arch/x86/include/asm/pgtable-3level.h
18136+++ b/arch/x86/include/asm/pgtable-3level.h
18137@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18138
18139 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18140 {
18141+ pax_open_kernel();
18142 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18143+ pax_close_kernel();
18144 }
18145
18146 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18147 {
18148+ pax_open_kernel();
18149 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18150+ pax_close_kernel();
18151 }
18152
18153 /*
18154diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18155index 0ec0560..f169e5b 100644
18156--- a/arch/x86/include/asm/pgtable.h
18157+++ b/arch/x86/include/asm/pgtable.h
18158@@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18159
18160 #ifndef __PAGETABLE_PUD_FOLDED
18161 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18162+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18163 #define pgd_clear(pgd) native_pgd_clear(pgd)
18164 #endif
18165
18166@@ -83,12 +84,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18167
18168 #define arch_end_context_switch(prev) do {} while(0)
18169
18170+#define pax_open_kernel() native_pax_open_kernel()
18171+#define pax_close_kernel() native_pax_close_kernel()
18172 #endif /* CONFIG_PARAVIRT */
18173
18174+#define __HAVE_ARCH_PAX_OPEN_KERNEL
18175+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18176+
18177+#ifdef CONFIG_PAX_KERNEXEC
18178+static inline unsigned long native_pax_open_kernel(void)
18179+{
18180+ unsigned long cr0;
18181+
18182+ preempt_disable();
18183+ barrier();
18184+ cr0 = read_cr0() ^ X86_CR0_WP;
18185+ BUG_ON(cr0 & X86_CR0_WP);
18186+ write_cr0(cr0);
18187+ return cr0 ^ X86_CR0_WP;
18188+}
18189+
18190+static inline unsigned long native_pax_close_kernel(void)
18191+{
18192+ unsigned long cr0;
18193+
18194+ cr0 = read_cr0() ^ X86_CR0_WP;
18195+ BUG_ON(!(cr0 & X86_CR0_WP));
18196+ write_cr0(cr0);
18197+ barrier();
18198+ preempt_enable_no_resched();
18199+ return cr0 ^ X86_CR0_WP;
18200+}
18201+#else
18202+static inline unsigned long native_pax_open_kernel(void) { return 0; }
18203+static inline unsigned long native_pax_close_kernel(void) { return 0; }
18204+#endif
18205+
18206 /*
18207 * The following only work if pte_present() is true.
18208 * Undefined behaviour if not..
18209 */
18210+static inline int pte_user(pte_t pte)
18211+{
18212+ return pte_val(pte) & _PAGE_USER;
18213+}
18214+
18215 static inline int pte_dirty(pte_t pte)
18216 {
18217 return pte_flags(pte) & _PAGE_DIRTY;
18218@@ -131,8 +171,13 @@ static inline int pte_exec(pte_t pte)
18219
18220 static inline int pte_special(pte_t pte)
18221 {
18222- return (pte_flags(pte) & (_PAGE_PRESENT|_PAGE_SPECIAL)) ==
18223- (_PAGE_PRESENT|_PAGE_SPECIAL);
18224+ /*
18225+ * See CONFIG_NUMA_BALANCING pte_numa in include/asm-generic/pgtable.h.
18226+ * On x86 we have _PAGE_BIT_NUMA == _PAGE_BIT_GLOBAL+1 ==
18227+ * __PAGE_BIT_SOFTW1 == _PAGE_BIT_SPECIAL.
18228+ */
18229+ return (pte_flags(pte) & _PAGE_SPECIAL) &&
18230+ (pte_flags(pte) & (_PAGE_PRESENT|_PAGE_PROTNONE));
18231 }
18232
18233 static inline unsigned long pte_pfn(pte_t pte)
18234@@ -150,6 +195,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18235 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18236 }
18237
18238+static inline unsigned long pgd_pfn(pgd_t pgd)
18239+{
18240+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18241+}
18242+
18243 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18244
18245 static inline int pmd_large(pmd_t pte)
18246@@ -203,9 +253,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18247 return pte_clear_flags(pte, _PAGE_RW);
18248 }
18249
18250+static inline pte_t pte_mkread(pte_t pte)
18251+{
18252+ return __pte(pte_val(pte) | _PAGE_USER);
18253+}
18254+
18255 static inline pte_t pte_mkexec(pte_t pte)
18256 {
18257- return pte_clear_flags(pte, _PAGE_NX);
18258+#ifdef CONFIG_X86_PAE
18259+ if (__supported_pte_mask & _PAGE_NX)
18260+ return pte_clear_flags(pte, _PAGE_NX);
18261+ else
18262+#endif
18263+ return pte_set_flags(pte, _PAGE_USER);
18264+}
18265+
18266+static inline pte_t pte_exprotect(pte_t pte)
18267+{
18268+#ifdef CONFIG_X86_PAE
18269+ if (__supported_pte_mask & _PAGE_NX)
18270+ return pte_set_flags(pte, _PAGE_NX);
18271+ else
18272+#endif
18273+ return pte_clear_flags(pte, _PAGE_USER);
18274 }
18275
18276 static inline pte_t pte_mkdirty(pte_t pte)
18277@@ -435,6 +505,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18278 #endif
18279
18280 #ifndef __ASSEMBLY__
18281+
18282+#ifdef CONFIG_PAX_PER_CPU_PGD
18283+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18284+enum cpu_pgd_type {kernel = 0, user = 1};
18285+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18286+{
18287+ return cpu_pgd[cpu][type];
18288+}
18289+#endif
18290+
18291 #include <linux/mm_types.h>
18292 #include <linux/mmdebug.h>
18293 #include <linux/log2.h>
18294@@ -581,7 +661,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18295 * Currently stuck as a macro due to indirect forward reference to
18296 * linux/mmzone.h's __section_mem_map_addr() definition:
18297 */
18298-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18299+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18300
18301 /* Find an entry in the second-level page table.. */
18302 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18303@@ -621,7 +701,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18304 * Currently stuck as a macro due to indirect forward reference to
18305 * linux/mmzone.h's __section_mem_map_addr() definition:
18306 */
18307-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18308+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18309
18310 /* to find an entry in a page-table-directory. */
18311 static inline unsigned long pud_index(unsigned long address)
18312@@ -636,7 +716,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18313
18314 static inline int pgd_bad(pgd_t pgd)
18315 {
18316- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18317+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18318 }
18319
18320 static inline int pgd_none(pgd_t pgd)
18321@@ -659,7 +739,12 @@ static inline int pgd_none(pgd_t pgd)
18322 * pgd_offset() returns a (pgd_t *)
18323 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18324 */
18325-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18326+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18327+
18328+#ifdef CONFIG_PAX_PER_CPU_PGD
18329+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18330+#endif
18331+
18332 /*
18333 * a shortcut which implies the use of the kernel's pgd, instead
18334 * of a process's
18335@@ -670,6 +755,23 @@ static inline int pgd_none(pgd_t pgd)
18336 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18337 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18338
18339+#ifdef CONFIG_X86_32
18340+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18341+#else
18342+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18343+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18344+
18345+#ifdef CONFIG_PAX_MEMORY_UDEREF
18346+#ifdef __ASSEMBLY__
18347+#define pax_user_shadow_base pax_user_shadow_base(%rip)
18348+#else
18349+extern unsigned long pax_user_shadow_base;
18350+extern pgdval_t clone_pgd_mask;
18351+#endif
18352+#endif
18353+
18354+#endif
18355+
18356 #ifndef __ASSEMBLY__
18357
18358 extern int direct_gbpages;
18359@@ -836,11 +938,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18360 * dst and src can be on the same page, but the range must not overlap,
18361 * and must not cross a page boundary.
18362 */
18363-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18364+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18365 {
18366- memcpy(dst, src, count * sizeof(pgd_t));
18367+ pax_open_kernel();
18368+ while (count--)
18369+ *dst++ = *src++;
18370+ pax_close_kernel();
18371 }
18372
18373+#ifdef CONFIG_PAX_PER_CPU_PGD
18374+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18375+#endif
18376+
18377+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18378+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18379+#else
18380+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18381+#endif
18382+
18383 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18384 static inline int page_level_shift(enum pg_level level)
18385 {
18386diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18387index 9ee3221..b979c6b 100644
18388--- a/arch/x86/include/asm/pgtable_32.h
18389+++ b/arch/x86/include/asm/pgtable_32.h
18390@@ -25,9 +25,6 @@
18391 struct mm_struct;
18392 struct vm_area_struct;
18393
18394-extern pgd_t swapper_pg_dir[1024];
18395-extern pgd_t initial_page_table[1024];
18396-
18397 static inline void pgtable_cache_init(void) { }
18398 static inline void check_pgt_cache(void) { }
18399 void paging_init(void);
18400@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18401 # include <asm/pgtable-2level.h>
18402 #endif
18403
18404+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18405+extern pgd_t initial_page_table[PTRS_PER_PGD];
18406+#ifdef CONFIG_X86_PAE
18407+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18408+#endif
18409+
18410 #if defined(CONFIG_HIGHPTE)
18411 #define pte_offset_map(dir, address) \
18412 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18413@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18414 /* Clear a kernel PTE and flush it from the TLB */
18415 #define kpte_clear_flush(ptep, vaddr) \
18416 do { \
18417+ pax_open_kernel(); \
18418 pte_clear(&init_mm, (vaddr), (ptep)); \
18419+ pax_close_kernel(); \
18420 __flush_tlb_one((vaddr)); \
18421 } while (0)
18422
18423 #endif /* !__ASSEMBLY__ */
18424
18425+#define HAVE_ARCH_UNMAPPED_AREA
18426+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18427+
18428 /*
18429 * kern_addr_valid() is (1) for FLATMEM and (0) for
18430 * SPARSEMEM and DISCONTIGMEM
18431diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18432index ed5903b..c7fe163 100644
18433--- a/arch/x86/include/asm/pgtable_32_types.h
18434+++ b/arch/x86/include/asm/pgtable_32_types.h
18435@@ -8,7 +8,7 @@
18436 */
18437 #ifdef CONFIG_X86_PAE
18438 # include <asm/pgtable-3level_types.h>
18439-# define PMD_SIZE (1UL << PMD_SHIFT)
18440+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18441 # define PMD_MASK (~(PMD_SIZE - 1))
18442 #else
18443 # include <asm/pgtable-2level_types.h>
18444@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18445 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18446 #endif
18447
18448+#ifdef CONFIG_PAX_KERNEXEC
18449+#ifndef __ASSEMBLY__
18450+extern unsigned char MODULES_EXEC_VADDR[];
18451+extern unsigned char MODULES_EXEC_END[];
18452+#endif
18453+#include <asm/boot.h>
18454+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18455+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18456+#else
18457+#define ktla_ktva(addr) (addr)
18458+#define ktva_ktla(addr) (addr)
18459+#endif
18460+
18461 #define MODULES_VADDR VMALLOC_START
18462 #define MODULES_END VMALLOC_END
18463 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18464diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18465index 5be9063..d62185b 100644
18466--- a/arch/x86/include/asm/pgtable_64.h
18467+++ b/arch/x86/include/asm/pgtable_64.h
18468@@ -16,10 +16,14 @@
18469
18470 extern pud_t level3_kernel_pgt[512];
18471 extern pud_t level3_ident_pgt[512];
18472+extern pud_t level3_vmalloc_start_pgt[512];
18473+extern pud_t level3_vmalloc_end_pgt[512];
18474+extern pud_t level3_vmemmap_pgt[512];
18475+extern pud_t level2_vmemmap_pgt[512];
18476 extern pmd_t level2_kernel_pgt[512];
18477 extern pmd_t level2_fixmap_pgt[512];
18478-extern pmd_t level2_ident_pgt[512];
18479-extern pgd_t init_level4_pgt[];
18480+extern pmd_t level2_ident_pgt[512*2];
18481+extern pgd_t init_level4_pgt[512];
18482
18483 #define swapper_pg_dir init_level4_pgt
18484
18485@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18486
18487 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18488 {
18489+ pax_open_kernel();
18490 *pmdp = pmd;
18491+ pax_close_kernel();
18492 }
18493
18494 static inline void native_pmd_clear(pmd_t *pmd)
18495@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18496
18497 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18498 {
18499+ pax_open_kernel();
18500 *pudp = pud;
18501+ pax_close_kernel();
18502 }
18503
18504 static inline void native_pud_clear(pud_t *pud)
18505@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18506
18507 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18508 {
18509+ pax_open_kernel();
18510+ *pgdp = pgd;
18511+ pax_close_kernel();
18512+}
18513+
18514+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18515+{
18516 *pgdp = pgd;
18517 }
18518
18519diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18520index 7166e25..baaa6fe 100644
18521--- a/arch/x86/include/asm/pgtable_64_types.h
18522+++ b/arch/x86/include/asm/pgtable_64_types.h
18523@@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18524 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18525 #define MODULES_END _AC(0xffffffffff000000, UL)
18526 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18527+#define MODULES_EXEC_VADDR MODULES_VADDR
18528+#define MODULES_EXEC_END MODULES_END
18529 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18530 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18531
18532+#define ktla_ktva(addr) (addr)
18533+#define ktva_ktla(addr) (addr)
18534+
18535 #define EARLY_DYNAMIC_PAGE_TABLES 64
18536
18537 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18538diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18539index f216963..6bd7c21 100644
18540--- a/arch/x86/include/asm/pgtable_types.h
18541+++ b/arch/x86/include/asm/pgtable_types.h
18542@@ -111,8 +111,10 @@
18543
18544 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18545 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18546-#else
18547+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18548 #define _PAGE_NX (_AT(pteval_t, 0))
18549+#else
18550+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18551 #endif
18552
18553 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18554@@ -151,6 +153,9 @@
18555 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18556 _PAGE_ACCESSED)
18557
18558+#define PAGE_READONLY_NOEXEC PAGE_READONLY
18559+#define PAGE_SHARED_NOEXEC PAGE_SHARED
18560+
18561 #define __PAGE_KERNEL_EXEC \
18562 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18563 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18564@@ -161,7 +166,7 @@
18565 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18566 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18567 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18568-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18569+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18570 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18571 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18572 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18573@@ -218,7 +223,7 @@
18574 #ifdef CONFIG_X86_64
18575 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18576 #else
18577-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18578+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18579 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18580 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18581 #endif
18582@@ -257,7 +262,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18583 {
18584 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18585 }
18586+#endif
18587
18588+#if PAGETABLE_LEVELS == 3
18589+#include <asm-generic/pgtable-nopud.h>
18590+#endif
18591+
18592+#if PAGETABLE_LEVELS == 2
18593+#include <asm-generic/pgtable-nopmd.h>
18594+#endif
18595+
18596+#ifndef __ASSEMBLY__
18597 #if PAGETABLE_LEVELS > 3
18598 typedef struct { pudval_t pud; } pud_t;
18599
18600@@ -271,8 +286,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18601 return pud.pud;
18602 }
18603 #else
18604-#include <asm-generic/pgtable-nopud.h>
18605-
18606 static inline pudval_t native_pud_val(pud_t pud)
18607 {
18608 return native_pgd_val(pud.pgd);
18609@@ -292,8 +305,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18610 return pmd.pmd;
18611 }
18612 #else
18613-#include <asm-generic/pgtable-nopmd.h>
18614-
18615 static inline pmdval_t native_pmd_val(pmd_t pmd)
18616 {
18617 return native_pgd_val(pmd.pud.pgd);
18618@@ -333,7 +344,6 @@ typedef struct page *pgtable_t;
18619
18620 extern pteval_t __supported_pte_mask;
18621 extern void set_nx(void);
18622-extern int nx_enabled;
18623
18624 #define pgprot_writecombine pgprot_writecombine
18625 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18626diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18627index 7024c12..71c46b9 100644
18628--- a/arch/x86/include/asm/preempt.h
18629+++ b/arch/x86/include/asm/preempt.h
18630@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18631 */
18632 static __always_inline bool __preempt_count_dec_and_test(void)
18633 {
18634- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18635+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18636 }
18637
18638 /*
18639diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18640index a4ea023..33aa874 100644
18641--- a/arch/x86/include/asm/processor.h
18642+++ b/arch/x86/include/asm/processor.h
18643@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18644 /* Index into per_cpu list: */
18645 u16 cpu_index;
18646 u32 microcode;
18647-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18648+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18649
18650 #define X86_VENDOR_INTEL 0
18651 #define X86_VENDOR_CYRIX 1
18652@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18653 : "memory");
18654 }
18655
18656+/* invpcid (%rdx),%rax */
18657+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18658+
18659+#define INVPCID_SINGLE_ADDRESS 0UL
18660+#define INVPCID_SINGLE_CONTEXT 1UL
18661+#define INVPCID_ALL_GLOBAL 2UL
18662+#define INVPCID_ALL_MONGLOBAL 3UL
18663+
18664+#define PCID_KERNEL 0UL
18665+#define PCID_USER 1UL
18666+#define PCID_NOFLUSH (1UL << 63)
18667+
18668 static inline void load_cr3(pgd_t *pgdir)
18669 {
18670- write_cr3(__pa(pgdir));
18671+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18672 }
18673
18674 #ifdef CONFIG_X86_32
18675@@ -283,7 +295,7 @@ struct tss_struct {
18676
18677 } ____cacheline_aligned;
18678
18679-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18680+extern struct tss_struct init_tss[NR_CPUS];
18681
18682 /*
18683 * Save the original ist values for checking stack pointers during debugging
18684@@ -479,6 +491,7 @@ struct thread_struct {
18685 unsigned short ds;
18686 unsigned short fsindex;
18687 unsigned short gsindex;
18688+ unsigned short ss;
18689 #endif
18690 #ifdef CONFIG_X86_32
18691 unsigned long ip;
18692@@ -588,29 +601,8 @@ static inline void load_sp0(struct tss_struct *tss,
18693 extern unsigned long mmu_cr4_features;
18694 extern u32 *trampoline_cr4_features;
18695
18696-static inline void set_in_cr4(unsigned long mask)
18697-{
18698- unsigned long cr4;
18699-
18700- mmu_cr4_features |= mask;
18701- if (trampoline_cr4_features)
18702- *trampoline_cr4_features = mmu_cr4_features;
18703- cr4 = read_cr4();
18704- cr4 |= mask;
18705- write_cr4(cr4);
18706-}
18707-
18708-static inline void clear_in_cr4(unsigned long mask)
18709-{
18710- unsigned long cr4;
18711-
18712- mmu_cr4_features &= ~mask;
18713- if (trampoline_cr4_features)
18714- *trampoline_cr4_features = mmu_cr4_features;
18715- cr4 = read_cr4();
18716- cr4 &= ~mask;
18717- write_cr4(cr4);
18718-}
18719+extern void set_in_cr4(unsigned long mask);
18720+extern void clear_in_cr4(unsigned long mask);
18721
18722 typedef struct {
18723 unsigned long seg;
18724@@ -836,11 +828,18 @@ static inline void spin_lock_prefetch(const void *x)
18725 */
18726 #define TASK_SIZE PAGE_OFFSET
18727 #define TASK_SIZE_MAX TASK_SIZE
18728+
18729+#ifdef CONFIG_PAX_SEGMEXEC
18730+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18731+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18732+#else
18733 #define STACK_TOP TASK_SIZE
18734-#define STACK_TOP_MAX STACK_TOP
18735+#endif
18736+
18737+#define STACK_TOP_MAX TASK_SIZE
18738
18739 #define INIT_THREAD { \
18740- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18741+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18742 .vm86_info = NULL, \
18743 .sysenter_cs = __KERNEL_CS, \
18744 .io_bitmap_ptr = NULL, \
18745@@ -854,7 +853,7 @@ static inline void spin_lock_prefetch(const void *x)
18746 */
18747 #define INIT_TSS { \
18748 .x86_tss = { \
18749- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18750+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18751 .ss0 = __KERNEL_DS, \
18752 .ss1 = __KERNEL_CS, \
18753 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18754@@ -865,11 +864,7 @@ static inline void spin_lock_prefetch(const void *x)
18755 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18756
18757 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18758-#define KSTK_TOP(info) \
18759-({ \
18760- unsigned long *__ptr = (unsigned long *)(info); \
18761- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18762-})
18763+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18764
18765 /*
18766 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18767@@ -884,7 +879,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18768 #define task_pt_regs(task) \
18769 ({ \
18770 struct pt_regs *__regs__; \
18771- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18772+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18773 __regs__ - 1; \
18774 })
18775
18776@@ -894,13 +889,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18777 /*
18778 * User space process size. 47bits minus one guard page.
18779 */
18780-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18781+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18782
18783 /* This decides where the kernel will search for a free chunk of vm
18784 * space during mmap's.
18785 */
18786 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18787- 0xc0000000 : 0xFFFFe000)
18788+ 0xc0000000 : 0xFFFFf000)
18789
18790 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18791 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18792@@ -911,11 +906,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18793 #define STACK_TOP_MAX TASK_SIZE_MAX
18794
18795 #define INIT_THREAD { \
18796- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18797+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18798 }
18799
18800 #define INIT_TSS { \
18801- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18802+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18803 }
18804
18805 /*
18806@@ -943,6 +938,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18807 */
18808 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18809
18810+#ifdef CONFIG_PAX_SEGMEXEC
18811+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18812+#endif
18813+
18814 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18815
18816 /* Get/set a process' ability to use the timestamp counter instruction */
18817@@ -969,7 +968,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18818 return 0;
18819 }
18820
18821-extern unsigned long arch_align_stack(unsigned long sp);
18822+#define arch_align_stack(x) ((x) & ~0xfUL)
18823 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18824
18825 void default_idle(void);
18826@@ -979,6 +978,6 @@ bool xen_set_default_idle(void);
18827 #define xen_set_default_idle 0
18828 #endif
18829
18830-void stop_this_cpu(void *dummy);
18831+void stop_this_cpu(void *dummy) __noreturn;
18832 void df_debug(struct pt_regs *regs, long error_code);
18833 #endif /* _ASM_X86_PROCESSOR_H */
18834diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18835index 6205f0c..688a3a9 100644
18836--- a/arch/x86/include/asm/ptrace.h
18837+++ b/arch/x86/include/asm/ptrace.h
18838@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18839 }
18840
18841 /*
18842- * user_mode_vm(regs) determines whether a register set came from user mode.
18843+ * user_mode(regs) determines whether a register set came from user mode.
18844 * This is true if V8086 mode was enabled OR if the register set was from
18845 * protected mode with RPL-3 CS value. This tricky test checks that with
18846 * one comparison. Many places in the kernel can bypass this full check
18847- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18848+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18849+ * be used.
18850 */
18851-static inline int user_mode(struct pt_regs *regs)
18852+static inline int user_mode_novm(struct pt_regs *regs)
18853 {
18854 #ifdef CONFIG_X86_32
18855 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18856 #else
18857- return !!(regs->cs & 3);
18858+ return !!(regs->cs & SEGMENT_RPL_MASK);
18859 #endif
18860 }
18861
18862-static inline int user_mode_vm(struct pt_regs *regs)
18863+static inline int user_mode(struct pt_regs *regs)
18864 {
18865 #ifdef CONFIG_X86_32
18866 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18867 USER_RPL;
18868 #else
18869- return user_mode(regs);
18870+ return user_mode_novm(regs);
18871 #endif
18872 }
18873
18874@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18875 #ifdef CONFIG_X86_64
18876 static inline bool user_64bit_mode(struct pt_regs *regs)
18877 {
18878+ unsigned long cs = regs->cs & 0xffff;
18879 #ifndef CONFIG_PARAVIRT
18880 /*
18881 * On non-paravirt systems, this is the only long mode CPL 3
18882 * selector. We do not allow long mode selectors in the LDT.
18883 */
18884- return regs->cs == __USER_CS;
18885+ return cs == __USER_CS;
18886 #else
18887 /* Headers are too twisted for this to go in paravirt.h. */
18888- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18889+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18890 #endif
18891 }
18892
18893@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18894 * Traps from the kernel do not save sp and ss.
18895 * Use the helper function to retrieve sp.
18896 */
18897- if (offset == offsetof(struct pt_regs, sp) &&
18898- regs->cs == __KERNEL_CS)
18899- return kernel_stack_pointer(regs);
18900+ if (offset == offsetof(struct pt_regs, sp)) {
18901+ unsigned long cs = regs->cs & 0xffff;
18902+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18903+ return kernel_stack_pointer(regs);
18904+ }
18905 #endif
18906 return *(unsigned long *)((unsigned long)regs + offset);
18907 }
18908diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18909index 70f46f0..adfbdb4 100644
18910--- a/arch/x86/include/asm/qrwlock.h
18911+++ b/arch/x86/include/asm/qrwlock.h
18912@@ -7,8 +7,8 @@
18913 #define queue_write_unlock queue_write_unlock
18914 static inline void queue_write_unlock(struct qrwlock *lock)
18915 {
18916- barrier();
18917- ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18918+ barrier();
18919+ ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18920 }
18921 #endif
18922
18923diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18924index 9c6b890..5305f53 100644
18925--- a/arch/x86/include/asm/realmode.h
18926+++ b/arch/x86/include/asm/realmode.h
18927@@ -22,16 +22,14 @@ struct real_mode_header {
18928 #endif
18929 /* APM/BIOS reboot */
18930 u32 machine_real_restart_asm;
18931-#ifdef CONFIG_X86_64
18932 u32 machine_real_restart_seg;
18933-#endif
18934 };
18935
18936 /* This must match data at trampoline_32/64.S */
18937 struct trampoline_header {
18938 #ifdef CONFIG_X86_32
18939 u32 start;
18940- u16 gdt_pad;
18941+ u16 boot_cs;
18942 u16 gdt_limit;
18943 u32 gdt_base;
18944 #else
18945diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18946index a82c4f1..ac45053 100644
18947--- a/arch/x86/include/asm/reboot.h
18948+++ b/arch/x86/include/asm/reboot.h
18949@@ -6,13 +6,13 @@
18950 struct pt_regs;
18951
18952 struct machine_ops {
18953- void (*restart)(char *cmd);
18954- void (*halt)(void);
18955- void (*power_off)(void);
18956+ void (* __noreturn restart)(char *cmd);
18957+ void (* __noreturn halt)(void);
18958+ void (* __noreturn power_off)(void);
18959 void (*shutdown)(void);
18960 void (*crash_shutdown)(struct pt_regs *);
18961- void (*emergency_restart)(void);
18962-};
18963+ void (* __noreturn emergency_restart)(void);
18964+} __no_const;
18965
18966 extern struct machine_ops machine_ops;
18967
18968diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18969index 8f7866a..e442f20 100644
18970--- a/arch/x86/include/asm/rmwcc.h
18971+++ b/arch/x86/include/asm/rmwcc.h
18972@@ -3,7 +3,34 @@
18973
18974 #ifdef CC_HAVE_ASM_GOTO
18975
18976-#define __GEN_RMWcc(fullop, var, cc, ...) \
18977+#ifdef CONFIG_PAX_REFCOUNT
18978+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18979+do { \
18980+ asm_volatile_goto (fullop \
18981+ ";jno 0f\n" \
18982+ fullantiop \
18983+ ";int $4\n0:\n" \
18984+ _ASM_EXTABLE(0b, 0b) \
18985+ ";j" cc " %l[cc_label]" \
18986+ : : "m" (var), ## __VA_ARGS__ \
18987+ : "memory" : cc_label); \
18988+ return 0; \
18989+cc_label: \
18990+ return 1; \
18991+} while (0)
18992+#else
18993+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18994+do { \
18995+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18996+ : : "m" (var), ## __VA_ARGS__ \
18997+ : "memory" : cc_label); \
18998+ return 0; \
18999+cc_label: \
19000+ return 1; \
19001+} while (0)
19002+#endif
19003+
19004+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19005 do { \
19006 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
19007 : : "m" (var), ## __VA_ARGS__ \
19008@@ -13,15 +40,46 @@ cc_label: \
19009 return 1; \
19010 } while (0)
19011
19012-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19013- __GEN_RMWcc(op " " arg0, var, cc)
19014+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19015+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19016
19017-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19018- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
19019+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19020+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19021+
19022+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19023+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
19024+
19025+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19026+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
19027
19028 #else /* !CC_HAVE_ASM_GOTO */
19029
19030-#define __GEN_RMWcc(fullop, var, cc, ...) \
19031+#ifdef CONFIG_PAX_REFCOUNT
19032+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19033+do { \
19034+ char c; \
19035+ asm volatile (fullop \
19036+ ";jno 0f\n" \
19037+ fullantiop \
19038+ ";int $4\n0:\n" \
19039+ _ASM_EXTABLE(0b, 0b) \
19040+ "; set" cc " %1" \
19041+ : "+m" (var), "=qm" (c) \
19042+ : __VA_ARGS__ : "memory"); \
19043+ return c != 0; \
19044+} while (0)
19045+#else
19046+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19047+do { \
19048+ char c; \
19049+ asm volatile (fullop "; set" cc " %1" \
19050+ : "+m" (var), "=qm" (c) \
19051+ : __VA_ARGS__ : "memory"); \
19052+ return c != 0; \
19053+} while (0)
19054+#endif
19055+
19056+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19057 do { \
19058 char c; \
19059 asm volatile (fullop "; set" cc " %1" \
19060@@ -30,11 +88,17 @@ do { \
19061 return c != 0; \
19062 } while (0)
19063
19064-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19065- __GEN_RMWcc(op " " arg0, var, cc)
19066+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19067+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19068+
19069+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19070+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19071+
19072+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19073+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
19074
19075-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19076- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
19077+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19078+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
19079
19080 #endif /* CC_HAVE_ASM_GOTO */
19081
19082diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
19083index cad82c9..2e5c5c1 100644
19084--- a/arch/x86/include/asm/rwsem.h
19085+++ b/arch/x86/include/asm/rwsem.h
19086@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
19087 {
19088 asm volatile("# beginning down_read\n\t"
19089 LOCK_PREFIX _ASM_INC "(%1)\n\t"
19090+
19091+#ifdef CONFIG_PAX_REFCOUNT
19092+ "jno 0f\n"
19093+ LOCK_PREFIX _ASM_DEC "(%1)\n"
19094+ "int $4\n0:\n"
19095+ _ASM_EXTABLE(0b, 0b)
19096+#endif
19097+
19098 /* adds 0x00000001 */
19099 " jns 1f\n"
19100 " call call_rwsem_down_read_failed\n"
19101@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
19102 "1:\n\t"
19103 " mov %1,%2\n\t"
19104 " add %3,%2\n\t"
19105+
19106+#ifdef CONFIG_PAX_REFCOUNT
19107+ "jno 0f\n"
19108+ "sub %3,%2\n"
19109+ "int $4\n0:\n"
19110+ _ASM_EXTABLE(0b, 0b)
19111+#endif
19112+
19113 " jle 2f\n\t"
19114 LOCK_PREFIX " cmpxchg %2,%0\n\t"
19115 " jnz 1b\n\t"
19116@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
19117 long tmp;
19118 asm volatile("# beginning down_write\n\t"
19119 LOCK_PREFIX " xadd %1,(%2)\n\t"
19120+
19121+#ifdef CONFIG_PAX_REFCOUNT
19122+ "jno 0f\n"
19123+ "mov %1,(%2)\n"
19124+ "int $4\n0:\n"
19125+ _ASM_EXTABLE(0b, 0b)
19126+#endif
19127+
19128 /* adds 0xffff0001, returns the old value */
19129 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
19130 /* was the active mask 0 before? */
19131@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
19132 long tmp;
19133 asm volatile("# beginning __up_read\n\t"
19134 LOCK_PREFIX " xadd %1,(%2)\n\t"
19135+
19136+#ifdef CONFIG_PAX_REFCOUNT
19137+ "jno 0f\n"
19138+ "mov %1,(%2)\n"
19139+ "int $4\n0:\n"
19140+ _ASM_EXTABLE(0b, 0b)
19141+#endif
19142+
19143 /* subtracts 1, returns the old value */
19144 " jns 1f\n\t"
19145 " call call_rwsem_wake\n" /* expects old value in %edx */
19146@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19147 long tmp;
19148 asm volatile("# beginning __up_write\n\t"
19149 LOCK_PREFIX " xadd %1,(%2)\n\t"
19150+
19151+#ifdef CONFIG_PAX_REFCOUNT
19152+ "jno 0f\n"
19153+ "mov %1,(%2)\n"
19154+ "int $4\n0:\n"
19155+ _ASM_EXTABLE(0b, 0b)
19156+#endif
19157+
19158 /* subtracts 0xffff0001, returns the old value */
19159 " jns 1f\n\t"
19160 " call call_rwsem_wake\n" /* expects old value in %edx */
19161@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19162 {
19163 asm volatile("# beginning __downgrade_write\n\t"
19164 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19165+
19166+#ifdef CONFIG_PAX_REFCOUNT
19167+ "jno 0f\n"
19168+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19169+ "int $4\n0:\n"
19170+ _ASM_EXTABLE(0b, 0b)
19171+#endif
19172+
19173 /*
19174 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19175 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19176@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19177 */
19178 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19179 {
19180- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19181+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19182+
19183+#ifdef CONFIG_PAX_REFCOUNT
19184+ "jno 0f\n"
19185+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
19186+ "int $4\n0:\n"
19187+ _ASM_EXTABLE(0b, 0b)
19188+#endif
19189+
19190 : "+m" (sem->count)
19191 : "er" (delta));
19192 }
19193@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19194 */
19195 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19196 {
19197- return delta + xadd(&sem->count, delta);
19198+ return delta + xadd_check_overflow(&sem->count, delta);
19199 }
19200
19201 #endif /* __KERNEL__ */
19202diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19203index 6f1c3a8..7744f19 100644
19204--- a/arch/x86/include/asm/segment.h
19205+++ b/arch/x86/include/asm/segment.h
19206@@ -64,10 +64,15 @@
19207 * 26 - ESPFIX small SS
19208 * 27 - per-cpu [ offset to per-cpu data area ]
19209 * 28 - stack_canary-20 [ for stack protector ]
19210- * 29 - unused
19211- * 30 - unused
19212+ * 29 - PCI BIOS CS
19213+ * 30 - PCI BIOS DS
19214 * 31 - TSS for double fault handler
19215 */
19216+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19217+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19218+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19219+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19220+
19221 #define GDT_ENTRY_TLS_MIN 6
19222 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19223
19224@@ -79,6 +84,8 @@
19225
19226 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19227
19228+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19229+
19230 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19231
19232 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19233@@ -104,6 +111,12 @@
19234 #define __KERNEL_STACK_CANARY 0
19235 #endif
19236
19237+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19238+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19239+
19240+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19241+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19242+
19243 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19244
19245 /*
19246@@ -141,7 +154,7 @@
19247 */
19248
19249 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19250-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19251+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19252
19253
19254 #else
19255@@ -165,6 +178,8 @@
19256 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19257 #define __USER32_DS __USER_DS
19258
19259+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19260+
19261 #define GDT_ENTRY_TSS 8 /* needs two entries */
19262 #define GDT_ENTRY_LDT 10 /* needs two entries */
19263 #define GDT_ENTRY_TLS_MIN 12
19264@@ -173,6 +188,8 @@
19265 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19266 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19267
19268+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19269+
19270 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19271 #define FS_TLS 0
19272 #define GS_TLS 1
19273@@ -180,12 +197,14 @@
19274 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19275 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19276
19277-#define GDT_ENTRIES 16
19278+#define GDT_ENTRIES 17
19279
19280 #endif
19281
19282 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19283+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19284 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19285+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19286 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19287 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19288 #ifndef CONFIG_PARAVIRT
19289@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19290 {
19291 unsigned long __limit;
19292 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19293- return __limit + 1;
19294+ return __limit;
19295 }
19296
19297 #endif /* !__ASSEMBLY__ */
19298diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19299index 8d3120f..352b440 100644
19300--- a/arch/x86/include/asm/smap.h
19301+++ b/arch/x86/include/asm/smap.h
19302@@ -25,11 +25,40 @@
19303
19304 #include <asm/alternative-asm.h>
19305
19306+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19307+#define ASM_PAX_OPEN_USERLAND \
19308+ 661: jmp 663f; \
19309+ .pushsection .altinstr_replacement, "a" ; \
19310+ 662: pushq %rax; nop; \
19311+ .popsection ; \
19312+ .pushsection .altinstructions, "a" ; \
19313+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19314+ .popsection ; \
19315+ call __pax_open_userland; \
19316+ popq %rax; \
19317+ 663:
19318+
19319+#define ASM_PAX_CLOSE_USERLAND \
19320+ 661: jmp 663f; \
19321+ .pushsection .altinstr_replacement, "a" ; \
19322+ 662: pushq %rax; nop; \
19323+ .popsection; \
19324+ .pushsection .altinstructions, "a" ; \
19325+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19326+ .popsection; \
19327+ call __pax_close_userland; \
19328+ popq %rax; \
19329+ 663:
19330+#else
19331+#define ASM_PAX_OPEN_USERLAND
19332+#define ASM_PAX_CLOSE_USERLAND
19333+#endif
19334+
19335 #ifdef CONFIG_X86_SMAP
19336
19337 #define ASM_CLAC \
19338 661: ASM_NOP3 ; \
19339- .pushsection .altinstr_replacement, "ax" ; \
19340+ .pushsection .altinstr_replacement, "a" ; \
19341 662: __ASM_CLAC ; \
19342 .popsection ; \
19343 .pushsection .altinstructions, "a" ; \
19344@@ -38,7 +67,7 @@
19345
19346 #define ASM_STAC \
19347 661: ASM_NOP3 ; \
19348- .pushsection .altinstr_replacement, "ax" ; \
19349+ .pushsection .altinstr_replacement, "a" ; \
19350 662: __ASM_STAC ; \
19351 .popsection ; \
19352 .pushsection .altinstructions, "a" ; \
19353@@ -56,6 +85,37 @@
19354
19355 #include <asm/alternative.h>
19356
19357+#define __HAVE_ARCH_PAX_OPEN_USERLAND
19358+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19359+
19360+extern void __pax_open_userland(void);
19361+static __always_inline unsigned long pax_open_userland(void)
19362+{
19363+
19364+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19365+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19366+ :
19367+ : [open] "i" (__pax_open_userland)
19368+ : "memory", "rax");
19369+#endif
19370+
19371+ return 0;
19372+}
19373+
19374+extern void __pax_close_userland(void);
19375+static __always_inline unsigned long pax_close_userland(void)
19376+{
19377+
19378+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19379+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19380+ :
19381+ : [close] "i" (__pax_close_userland)
19382+ : "memory", "rax");
19383+#endif
19384+
19385+ return 0;
19386+}
19387+
19388 #ifdef CONFIG_X86_SMAP
19389
19390 static __always_inline void clac(void)
19391diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19392index 8cd27e0..7f05ec8 100644
19393--- a/arch/x86/include/asm/smp.h
19394+++ b/arch/x86/include/asm/smp.h
19395@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19396 /* cpus sharing the last level cache: */
19397 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19398 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19399-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19400+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19401
19402 static inline struct cpumask *cpu_sibling_mask(int cpu)
19403 {
19404@@ -78,7 +78,7 @@ struct smp_ops {
19405
19406 void (*send_call_func_ipi)(const struct cpumask *mask);
19407 void (*send_call_func_single_ipi)(int cpu);
19408-};
19409+} __no_const;
19410
19411 /* Globals due to paravirt */
19412 extern void set_cpu_sibling_map(int cpu);
19413@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19414 extern int safe_smp_processor_id(void);
19415
19416 #elif defined(CONFIG_X86_64_SMP)
19417-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19418-
19419-#define stack_smp_processor_id() \
19420-({ \
19421- struct thread_info *ti; \
19422- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19423- ti->cpu; \
19424-})
19425+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19426+#define stack_smp_processor_id() raw_smp_processor_id()
19427 #define safe_smp_processor_id() smp_processor_id()
19428
19429 #endif
19430diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19431index 54f1c80..39362a5 100644
19432--- a/arch/x86/include/asm/spinlock.h
19433+++ b/arch/x86/include/asm/spinlock.h
19434@@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19435 static inline void arch_read_lock(arch_rwlock_t *rw)
19436 {
19437 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19438+
19439+#ifdef CONFIG_PAX_REFCOUNT
19440+ "jno 0f\n"
19441+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19442+ "int $4\n0:\n"
19443+ _ASM_EXTABLE(0b, 0b)
19444+#endif
19445+
19446 "jns 1f\n"
19447 "call __read_lock_failed\n\t"
19448 "1:\n"
19449@@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19450 static inline void arch_write_lock(arch_rwlock_t *rw)
19451 {
19452 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19453+
19454+#ifdef CONFIG_PAX_REFCOUNT
19455+ "jno 0f\n"
19456+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19457+ "int $4\n0:\n"
19458+ _ASM_EXTABLE(0b, 0b)
19459+#endif
19460+
19461 "jz 1f\n"
19462 "call __write_lock_failed\n\t"
19463 "1:\n"
19464@@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19465
19466 static inline void arch_read_unlock(arch_rwlock_t *rw)
19467 {
19468- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19469+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19470+
19471+#ifdef CONFIG_PAX_REFCOUNT
19472+ "jno 0f\n"
19473+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19474+ "int $4\n0:\n"
19475+ _ASM_EXTABLE(0b, 0b)
19476+#endif
19477+
19478 :"+m" (rw->lock) : : "memory");
19479 }
19480
19481 static inline void arch_write_unlock(arch_rwlock_t *rw)
19482 {
19483- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19484+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19485+
19486+#ifdef CONFIG_PAX_REFCOUNT
19487+ "jno 0f\n"
19488+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19489+ "int $4\n0:\n"
19490+ _ASM_EXTABLE(0b, 0b)
19491+#endif
19492+
19493 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19494 }
19495 #else
19496diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19497index 6a99859..03cb807 100644
19498--- a/arch/x86/include/asm/stackprotector.h
19499+++ b/arch/x86/include/asm/stackprotector.h
19500@@ -47,7 +47,7 @@
19501 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19502 */
19503 #define GDT_STACK_CANARY_INIT \
19504- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19505+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19506
19507 /*
19508 * Initialize the stackprotector canary value.
19509@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19510
19511 static inline void load_stack_canary_segment(void)
19512 {
19513-#ifdef CONFIG_X86_32
19514+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19515 asm volatile ("mov %0, %%gs" : : "r" (0));
19516 #endif
19517 }
19518diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19519index 70bbe39..4ae2bd4 100644
19520--- a/arch/x86/include/asm/stacktrace.h
19521+++ b/arch/x86/include/asm/stacktrace.h
19522@@ -11,28 +11,20 @@
19523
19524 extern int kstack_depth_to_print;
19525
19526-struct thread_info;
19527+struct task_struct;
19528 struct stacktrace_ops;
19529
19530-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19531- unsigned long *stack,
19532- unsigned long bp,
19533- const struct stacktrace_ops *ops,
19534- void *data,
19535- unsigned long *end,
19536- int *graph);
19537+typedef unsigned long walk_stack_t(struct task_struct *task,
19538+ void *stack_start,
19539+ unsigned long *stack,
19540+ unsigned long bp,
19541+ const struct stacktrace_ops *ops,
19542+ void *data,
19543+ unsigned long *end,
19544+ int *graph);
19545
19546-extern unsigned long
19547-print_context_stack(struct thread_info *tinfo,
19548- unsigned long *stack, unsigned long bp,
19549- const struct stacktrace_ops *ops, void *data,
19550- unsigned long *end, int *graph);
19551-
19552-extern unsigned long
19553-print_context_stack_bp(struct thread_info *tinfo,
19554- unsigned long *stack, unsigned long bp,
19555- const struct stacktrace_ops *ops, void *data,
19556- unsigned long *end, int *graph);
19557+extern walk_stack_t print_context_stack;
19558+extern walk_stack_t print_context_stack_bp;
19559
19560 /* Generic stack tracer with callbacks */
19561
19562@@ -40,7 +32,7 @@ struct stacktrace_ops {
19563 void (*address)(void *data, unsigned long address, int reliable);
19564 /* On negative return stop dumping */
19565 int (*stack)(void *data, char *name);
19566- walk_stack_t walk_stack;
19567+ walk_stack_t *walk_stack;
19568 };
19569
19570 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19571diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19572index d7f3b3b..3cc39f1 100644
19573--- a/arch/x86/include/asm/switch_to.h
19574+++ b/arch/x86/include/asm/switch_to.h
19575@@ -108,7 +108,7 @@ do { \
19576 "call __switch_to\n\t" \
19577 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19578 __switch_canary \
19579- "movq %P[thread_info](%%rsi),%%r8\n\t" \
19580+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19581 "movq %%rax,%%rdi\n\t" \
19582 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19583 "jnz ret_from_fork\n\t" \
19584@@ -119,7 +119,7 @@ do { \
19585 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19586 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19587 [_tif_fork] "i" (_TIF_FORK), \
19588- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19589+ [thread_info] "m" (current_tinfo), \
19590 [current_task] "m" (current_task) \
19591 __switch_canary_iparam \
19592 : "memory", "cc" __EXTRA_CLOBBER)
19593diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19594index 8540538..4b0b5e9 100644
19595--- a/arch/x86/include/asm/thread_info.h
19596+++ b/arch/x86/include/asm/thread_info.h
19597@@ -24,7 +24,6 @@ struct exec_domain;
19598 #include <linux/atomic.h>
19599
19600 struct thread_info {
19601- struct task_struct *task; /* main task structure */
19602 struct exec_domain *exec_domain; /* execution domain */
19603 __u32 flags; /* low level flags */
19604 __u32 status; /* thread synchronous flags */
19605@@ -33,13 +32,13 @@ struct thread_info {
19606 mm_segment_t addr_limit;
19607 struct restart_block restart_block;
19608 void __user *sysenter_return;
19609+ unsigned long lowest_stack;
19610 unsigned int sig_on_uaccess_error:1;
19611 unsigned int uaccess_err:1; /* uaccess failed */
19612 };
19613
19614-#define INIT_THREAD_INFO(tsk) \
19615+#define INIT_THREAD_INFO \
19616 { \
19617- .task = &tsk, \
19618 .exec_domain = &default_exec_domain, \
19619 .flags = 0, \
19620 .cpu = 0, \
19621@@ -50,7 +49,7 @@ struct thread_info {
19622 }, \
19623 }
19624
19625-#define init_thread_info (init_thread_union.thread_info)
19626+#define init_thread_info (init_thread_union.stack)
19627 #define init_stack (init_thread_union.stack)
19628
19629 #else /* !__ASSEMBLY__ */
19630@@ -91,6 +90,7 @@ struct thread_info {
19631 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19632 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19633 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19634+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19635
19636 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19637 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19638@@ -115,17 +115,18 @@ struct thread_info {
19639 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19640 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19641 #define _TIF_X32 (1 << TIF_X32)
19642+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19643
19644 /* work to do in syscall_trace_enter() */
19645 #define _TIF_WORK_SYSCALL_ENTRY \
19646 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19647 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19648- _TIF_NOHZ)
19649+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19650
19651 /* work to do in syscall_trace_leave() */
19652 #define _TIF_WORK_SYSCALL_EXIT \
19653 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19654- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19655+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19656
19657 /* work to do on interrupt/exception return */
19658 #define _TIF_WORK_MASK \
19659@@ -136,7 +137,7 @@ struct thread_info {
19660 /* work to do on any return to user space */
19661 #define _TIF_ALLWORK_MASK \
19662 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19663- _TIF_NOHZ)
19664+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19665
19666 /* Only used for 64 bit */
19667 #define _TIF_DO_NOTIFY_MASK \
19668@@ -151,7 +152,6 @@ struct thread_info {
19669 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19670
19671 #define STACK_WARN (THREAD_SIZE/8)
19672-#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19673
19674 /*
19675 * macros/functions for gaining access to the thread information structure
19676@@ -162,26 +162,18 @@ struct thread_info {
19677
19678 DECLARE_PER_CPU(unsigned long, kernel_stack);
19679
19680+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19681+
19682 static inline struct thread_info *current_thread_info(void)
19683 {
19684- struct thread_info *ti;
19685- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19686- KERNEL_STACK_OFFSET - THREAD_SIZE);
19687- return ti;
19688+ return this_cpu_read_stable(current_tinfo);
19689 }
19690
19691 #else /* !__ASSEMBLY__ */
19692
19693 /* how to get the thread information struct from ASM */
19694 #define GET_THREAD_INFO(reg) \
19695- _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19696- _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19697-
19698-/*
19699- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19700- * a certain register (to be used in assembler memory operands).
19701- */
19702-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19703+ _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19704
19705 #endif
19706
19707@@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19708 extern void arch_task_cache_init(void);
19709 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19710 extern void arch_release_task_struct(struct task_struct *tsk);
19711+
19712+#define __HAVE_THREAD_FUNCTIONS
19713+#define task_thread_info(task) (&(task)->tinfo)
19714+#define task_stack_page(task) ((task)->stack)
19715+#define setup_thread_stack(p, org) do {} while (0)
19716+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19717+
19718 #endif
19719 #endif /* _ASM_X86_THREAD_INFO_H */
19720diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19721index 04905bf..49203ca 100644
19722--- a/arch/x86/include/asm/tlbflush.h
19723+++ b/arch/x86/include/asm/tlbflush.h
19724@@ -17,18 +17,44 @@
19725
19726 static inline void __native_flush_tlb(void)
19727 {
19728+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19729+ u64 descriptor[2];
19730+
19731+ descriptor[0] = PCID_KERNEL;
19732+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19733+ return;
19734+ }
19735+
19736+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19737+ if (static_cpu_has(X86_FEATURE_PCID)) {
19738+ unsigned int cpu = raw_get_cpu();
19739+
19740+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19741+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19742+ raw_put_cpu_no_resched();
19743+ return;
19744+ }
19745+#endif
19746+
19747 native_write_cr3(native_read_cr3());
19748 }
19749
19750 static inline void __native_flush_tlb_global_irq_disabled(void)
19751 {
19752- unsigned long cr4;
19753+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19754+ u64 descriptor[2];
19755
19756- cr4 = native_read_cr4();
19757- /* clear PGE */
19758- native_write_cr4(cr4 & ~X86_CR4_PGE);
19759- /* write old PGE again and flush TLBs */
19760- native_write_cr4(cr4);
19761+ descriptor[0] = PCID_KERNEL;
19762+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19763+ } else {
19764+ unsigned long cr4;
19765+
19766+ cr4 = native_read_cr4();
19767+ /* clear PGE */
19768+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19769+ /* write old PGE again and flush TLBs */
19770+ native_write_cr4(cr4);
19771+ }
19772 }
19773
19774 static inline void __native_flush_tlb_global(void)
19775@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19776
19777 static inline void __native_flush_tlb_single(unsigned long addr)
19778 {
19779+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19780+ u64 descriptor[2];
19781+
19782+ descriptor[0] = PCID_KERNEL;
19783+ descriptor[1] = addr;
19784+
19785+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19786+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19787+ if (addr < TASK_SIZE_MAX)
19788+ descriptor[1] += pax_user_shadow_base;
19789+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19790+ }
19791+
19792+ descriptor[0] = PCID_USER;
19793+ descriptor[1] = addr;
19794+#endif
19795+
19796+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19797+ return;
19798+ }
19799+
19800+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19801+ if (static_cpu_has(X86_FEATURE_PCID)) {
19802+ unsigned int cpu = raw_get_cpu();
19803+
19804+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19805+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19806+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19807+ raw_put_cpu_no_resched();
19808+
19809+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19810+ addr += pax_user_shadow_base;
19811+ }
19812+#endif
19813+
19814 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19815 }
19816
19817diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19818index 0d592e0..526f797 100644
19819--- a/arch/x86/include/asm/uaccess.h
19820+++ b/arch/x86/include/asm/uaccess.h
19821@@ -7,6 +7,7 @@
19822 #include <linux/compiler.h>
19823 #include <linux/thread_info.h>
19824 #include <linux/string.h>
19825+#include <linux/spinlock.h>
19826 #include <asm/asm.h>
19827 #include <asm/page.h>
19828 #include <asm/smap.h>
19829@@ -29,7 +30,12 @@
19830
19831 #define get_ds() (KERNEL_DS)
19832 #define get_fs() (current_thread_info()->addr_limit)
19833+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19834+void __set_fs(mm_segment_t x);
19835+void set_fs(mm_segment_t x);
19836+#else
19837 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19838+#endif
19839
19840 #define segment_eq(a, b) ((a).seg == (b).seg)
19841
19842@@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19843 * checks that the pointer is in the user space range - after calling
19844 * this function, memory access functions may still return -EFAULT.
19845 */
19846-#define access_ok(type, addr, size) \
19847- likely(!__range_not_ok(addr, size, user_addr_max()))
19848+extern int _cond_resched(void);
19849+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19850+#define access_ok(type, addr, size) \
19851+({ \
19852+ unsigned long __size = size; \
19853+ unsigned long __addr = (unsigned long)addr; \
19854+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19855+ if (__ret_ao && __size) { \
19856+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19857+ unsigned long __end_ao = __addr + __size - 1; \
19858+ if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19859+ while (__addr_ao <= __end_ao) { \
19860+ char __c_ao; \
19861+ __addr_ao += PAGE_SIZE; \
19862+ if (__size > PAGE_SIZE) \
19863+ _cond_resched(); \
19864+ if (__get_user(__c_ao, (char __user *)__addr)) \
19865+ break; \
19866+ if (type != VERIFY_WRITE) { \
19867+ __addr = __addr_ao; \
19868+ continue; \
19869+ } \
19870+ if (__put_user(__c_ao, (char __user *)__addr)) \
19871+ break; \
19872+ __addr = __addr_ao; \
19873+ } \
19874+ } \
19875+ } \
19876+ __ret_ao; \
19877+})
19878
19879 /*
19880 * The exception table consists of pairs of addresses relative to the
19881@@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19882 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19883 __chk_user_ptr(ptr); \
19884 might_fault(); \
19885+ pax_open_userland(); \
19886 asm volatile("call __get_user_%P3" \
19887 : "=a" (__ret_gu), "=r" (__val_gu) \
19888 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19889 (x) = (__typeof__(*(ptr))) __val_gu; \
19890+ pax_close_userland(); \
19891 __ret_gu; \
19892 })
19893
19894@@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19895 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19896 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19897
19898-
19899+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19900+#define __copyuser_seg "gs;"
19901+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19902+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19903+#else
19904+#define __copyuser_seg
19905+#define __COPYUSER_SET_ES
19906+#define __COPYUSER_RESTORE_ES
19907+#endif
19908
19909 #ifdef CONFIG_X86_32
19910 #define __put_user_asm_u64(x, addr, err, errret) \
19911 asm volatile(ASM_STAC "\n" \
19912- "1: movl %%eax,0(%2)\n" \
19913- "2: movl %%edx,4(%2)\n" \
19914+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19915+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19916 "3: " ASM_CLAC "\n" \
19917 ".section .fixup,\"ax\"\n" \
19918 "4: movl %3,%0\n" \
19919@@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19920
19921 #define __put_user_asm_ex_u64(x, addr) \
19922 asm volatile(ASM_STAC "\n" \
19923- "1: movl %%eax,0(%1)\n" \
19924- "2: movl %%edx,4(%1)\n" \
19925+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19926+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19927 "3: " ASM_CLAC "\n" \
19928 _ASM_EXTABLE_EX(1b, 2b) \
19929 _ASM_EXTABLE_EX(2b, 3b) \
19930@@ -257,7 +301,8 @@ extern void __put_user_8(void);
19931 __typeof__(*(ptr)) __pu_val; \
19932 __chk_user_ptr(ptr); \
19933 might_fault(); \
19934- __pu_val = x; \
19935+ __pu_val = (x); \
19936+ pax_open_userland(); \
19937 switch (sizeof(*(ptr))) { \
19938 case 1: \
19939 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19940@@ -275,6 +320,7 @@ extern void __put_user_8(void);
19941 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19942 break; \
19943 } \
19944+ pax_close_userland(); \
19945 __ret_pu; \
19946 })
19947
19948@@ -355,8 +401,10 @@ do { \
19949 } while (0)
19950
19951 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19952+do { \
19953+ pax_open_userland(); \
19954 asm volatile(ASM_STAC "\n" \
19955- "1: mov"itype" %2,%"rtype"1\n" \
19956+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19957 "2: " ASM_CLAC "\n" \
19958 ".section .fixup,\"ax\"\n" \
19959 "3: mov %3,%0\n" \
19960@@ -364,8 +412,10 @@ do { \
19961 " jmp 2b\n" \
19962 ".previous\n" \
19963 _ASM_EXTABLE(1b, 3b) \
19964- : "=r" (err), ltype(x) \
19965- : "m" (__m(addr)), "i" (errret), "0" (err))
19966+ : "=r" (err), ltype (x) \
19967+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19968+ pax_close_userland(); \
19969+} while (0)
19970
19971 #define __get_user_size_ex(x, ptr, size) \
19972 do { \
19973@@ -389,7 +439,7 @@ do { \
19974 } while (0)
19975
19976 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19977- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19978+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19979 "2:\n" \
19980 _ASM_EXTABLE_EX(1b, 2b) \
19981 : ltype(x) : "m" (__m(addr)))
19982@@ -406,13 +456,24 @@ do { \
19983 int __gu_err; \
19984 unsigned long __gu_val; \
19985 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19986- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19987+ (x) = (__typeof__(*(ptr)))__gu_val; \
19988 __gu_err; \
19989 })
19990
19991 /* FIXME: this hack is definitely wrong -AK */
19992 struct __large_struct { unsigned long buf[100]; };
19993-#define __m(x) (*(struct __large_struct __user *)(x))
19994+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19995+#define ____m(x) \
19996+({ \
19997+ unsigned long ____x = (unsigned long)(x); \
19998+ if (____x < pax_user_shadow_base) \
19999+ ____x += pax_user_shadow_base; \
20000+ (typeof(x))____x; \
20001+})
20002+#else
20003+#define ____m(x) (x)
20004+#endif
20005+#define __m(x) (*(struct __large_struct __user *)____m(x))
20006
20007 /*
20008 * Tell gcc we read from memory instead of writing: this is because
20009@@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
20010 * aliasing issues.
20011 */
20012 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20013+do { \
20014+ pax_open_userland(); \
20015 asm volatile(ASM_STAC "\n" \
20016- "1: mov"itype" %"rtype"1,%2\n" \
20017+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
20018 "2: " ASM_CLAC "\n" \
20019 ".section .fixup,\"ax\"\n" \
20020 "3: mov %3,%0\n" \
20021@@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
20022 ".previous\n" \
20023 _ASM_EXTABLE(1b, 3b) \
20024 : "=r"(err) \
20025- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
20026+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
20027+ pax_close_userland(); \
20028+} while (0)
20029
20030 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
20031- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
20032+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
20033 "2:\n" \
20034 _ASM_EXTABLE_EX(1b, 2b) \
20035 : : ltype(x), "m" (__m(addr)))
20036@@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
20037 */
20038 #define uaccess_try do { \
20039 current_thread_info()->uaccess_err = 0; \
20040+ pax_open_userland(); \
20041 stac(); \
20042 barrier();
20043
20044 #define uaccess_catch(err) \
20045 clac(); \
20046+ pax_close_userland(); \
20047 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
20048 } while (0)
20049
20050@@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
20051 * On error, the variable @x is set to zero.
20052 */
20053
20054+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20055+#define __get_user(x, ptr) get_user((x), (ptr))
20056+#else
20057 #define __get_user(x, ptr) \
20058 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
20059+#endif
20060
20061 /**
20062 * __put_user: - Write a simple value into user space, with less checking.
20063@@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
20064 * Returns zero on success, or -EFAULT on error.
20065 */
20066
20067+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20068+#define __put_user(x, ptr) put_user((x), (ptr))
20069+#else
20070 #define __put_user(x, ptr) \
20071 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
20072+#endif
20073
20074 #define __get_user_unaligned __get_user
20075 #define __put_user_unaligned __put_user
20076@@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
20077 #define get_user_ex(x, ptr) do { \
20078 unsigned long __gue_val; \
20079 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
20080- (x) = (__force __typeof__(*(ptr)))__gue_val; \
20081+ (x) = (__typeof__(*(ptr)))__gue_val; \
20082 } while (0)
20083
20084 #define put_user_try uaccess_try
20085@@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
20086 __typeof__(ptr) __uval = (uval); \
20087 __typeof__(*(ptr)) __old = (old); \
20088 __typeof__(*(ptr)) __new = (new); \
20089+ pax_open_userland(); \
20090 switch (size) { \
20091 case 1: \
20092 { \
20093 asm volatile("\t" ASM_STAC "\n" \
20094- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
20095+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
20096 "2:\t" ASM_CLAC "\n" \
20097 "\t.section .fixup, \"ax\"\n" \
20098 "3:\tmov %3, %0\n" \
20099 "\tjmp 2b\n" \
20100 "\t.previous\n" \
20101 _ASM_EXTABLE(1b, 3b) \
20102- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20103+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20104 : "i" (-EFAULT), "q" (__new), "1" (__old) \
20105 : "memory" \
20106 ); \
20107@@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
20108 case 2: \
20109 { \
20110 asm volatile("\t" ASM_STAC "\n" \
20111- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
20112+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
20113 "2:\t" ASM_CLAC "\n" \
20114 "\t.section .fixup, \"ax\"\n" \
20115 "3:\tmov %3, %0\n" \
20116 "\tjmp 2b\n" \
20117 "\t.previous\n" \
20118 _ASM_EXTABLE(1b, 3b) \
20119- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20120+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20121 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20122 : "memory" \
20123 ); \
20124@@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
20125 case 4: \
20126 { \
20127 asm volatile("\t" ASM_STAC "\n" \
20128- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
20129+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
20130 "2:\t" ASM_CLAC "\n" \
20131 "\t.section .fixup, \"ax\"\n" \
20132 "3:\tmov %3, %0\n" \
20133 "\tjmp 2b\n" \
20134 "\t.previous\n" \
20135 _ASM_EXTABLE(1b, 3b) \
20136- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20137+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20138 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20139 : "memory" \
20140 ); \
20141@@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
20142 __cmpxchg_wrong_size(); \
20143 \
20144 asm volatile("\t" ASM_STAC "\n" \
20145- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
20146+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
20147 "2:\t" ASM_CLAC "\n" \
20148 "\t.section .fixup, \"ax\"\n" \
20149 "3:\tmov %3, %0\n" \
20150 "\tjmp 2b\n" \
20151 "\t.previous\n" \
20152 _ASM_EXTABLE(1b, 3b) \
20153- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20154+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20155 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20156 : "memory" \
20157 ); \
20158@@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
20159 default: \
20160 __cmpxchg_wrong_size(); \
20161 } \
20162+ pax_close_userland(); \
20163 *__uval = __old; \
20164 __ret; \
20165 })
20166@@ -636,17 +713,6 @@ extern struct movsl_mask {
20167
20168 #define ARCH_HAS_NOCACHE_UACCESS 1
20169
20170-#ifdef CONFIG_X86_32
20171-# include <asm/uaccess_32.h>
20172-#else
20173-# include <asm/uaccess_64.h>
20174-#endif
20175-
20176-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
20177- unsigned n);
20178-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20179- unsigned n);
20180-
20181 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
20182 # define copy_user_diag __compiletime_error
20183 #else
20184@@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20185 extern void copy_user_diag("copy_from_user() buffer size is too small")
20186 copy_from_user_overflow(void);
20187 extern void copy_user_diag("copy_to_user() buffer size is too small")
20188-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20189+copy_to_user_overflow(void);
20190
20191 #undef copy_user_diag
20192
20193@@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
20194
20195 extern void
20196 __compiletime_warning("copy_to_user() buffer size is not provably correct")
20197-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20198+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
20199 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
20200
20201 #else
20202@@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
20203
20204 #endif
20205
20206+#ifdef CONFIG_X86_32
20207+# include <asm/uaccess_32.h>
20208+#else
20209+# include <asm/uaccess_64.h>
20210+#endif
20211+
20212 static inline unsigned long __must_check
20213 copy_from_user(void *to, const void __user *from, unsigned long n)
20214 {
20215- int sz = __compiletime_object_size(to);
20216+ size_t sz = __compiletime_object_size(to);
20217
20218 might_fault();
20219
20220@@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20221 * case, and do only runtime checking for non-constant sizes.
20222 */
20223
20224- if (likely(sz < 0 || sz >= n))
20225- n = _copy_from_user(to, from, n);
20226- else if(__builtin_constant_p(n))
20227- copy_from_user_overflow();
20228- else
20229- __copy_from_user_overflow(sz, n);
20230+ if (likely(sz != (size_t)-1 && sz < n)) {
20231+ if(__builtin_constant_p(n))
20232+ copy_from_user_overflow();
20233+ else
20234+ __copy_from_user_overflow(sz, n);
20235+ } else if (access_ok(VERIFY_READ, from, n))
20236+ n = __copy_from_user(to, from, n);
20237+ else if ((long)n > 0)
20238+ memset(to, 0, n);
20239
20240 return n;
20241 }
20242@@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20243 static inline unsigned long __must_check
20244 copy_to_user(void __user *to, const void *from, unsigned long n)
20245 {
20246- int sz = __compiletime_object_size(from);
20247+ size_t sz = __compiletime_object_size(from);
20248
20249 might_fault();
20250
20251 /* See the comment in copy_from_user() above. */
20252- if (likely(sz < 0 || sz >= n))
20253- n = _copy_to_user(to, from, n);
20254- else if(__builtin_constant_p(n))
20255- copy_to_user_overflow();
20256- else
20257- __copy_to_user_overflow(sz, n);
20258+ if (likely(sz != (size_t)-1 && sz < n)) {
20259+ if(__builtin_constant_p(n))
20260+ copy_to_user_overflow();
20261+ else
20262+ __copy_to_user_overflow(sz, n);
20263+ } else if (access_ok(VERIFY_WRITE, to, n))
20264+ n = __copy_to_user(to, from, n);
20265
20266 return n;
20267 }
20268diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20269index 3c03a5d..1071638 100644
20270--- a/arch/x86/include/asm/uaccess_32.h
20271+++ b/arch/x86/include/asm/uaccess_32.h
20272@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20273 static __always_inline unsigned long __must_check
20274 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20275 {
20276+ if ((long)n < 0)
20277+ return n;
20278+
20279+ check_object_size(from, n, true);
20280+
20281 if (__builtin_constant_p(n)) {
20282 unsigned long ret;
20283
20284@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20285 __copy_to_user(void __user *to, const void *from, unsigned long n)
20286 {
20287 might_fault();
20288+
20289 return __copy_to_user_inatomic(to, from, n);
20290 }
20291
20292 static __always_inline unsigned long
20293 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20294 {
20295+ if ((long)n < 0)
20296+ return n;
20297+
20298 /* Avoid zeroing the tail if the copy fails..
20299 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20300 * but as the zeroing behaviour is only significant when n is not
20301@@ -137,6 +146,12 @@ static __always_inline unsigned long
20302 __copy_from_user(void *to, const void __user *from, unsigned long n)
20303 {
20304 might_fault();
20305+
20306+ if ((long)n < 0)
20307+ return n;
20308+
20309+ check_object_size(to, n, false);
20310+
20311 if (__builtin_constant_p(n)) {
20312 unsigned long ret;
20313
20314@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20315 const void __user *from, unsigned long n)
20316 {
20317 might_fault();
20318+
20319+ if ((long)n < 0)
20320+ return n;
20321+
20322 if (__builtin_constant_p(n)) {
20323 unsigned long ret;
20324
20325@@ -181,7 +200,10 @@ static __always_inline unsigned long
20326 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20327 unsigned long n)
20328 {
20329- return __copy_from_user_ll_nocache_nozero(to, from, n);
20330+ if ((long)n < 0)
20331+ return n;
20332+
20333+ return __copy_from_user_ll_nocache_nozero(to, from, n);
20334 }
20335
20336 #endif /* _ASM_X86_UACCESS_32_H */
20337diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20338index 12a26b9..206c200 100644
20339--- a/arch/x86/include/asm/uaccess_64.h
20340+++ b/arch/x86/include/asm/uaccess_64.h
20341@@ -10,6 +10,9 @@
20342 #include <asm/alternative.h>
20343 #include <asm/cpufeature.h>
20344 #include <asm/page.h>
20345+#include <asm/pgtable.h>
20346+
20347+#define set_fs(x) (current_thread_info()->addr_limit = (x))
20348
20349 /*
20350 * Copy To/From Userspace
20351@@ -17,14 +20,14 @@
20352
20353 /* Handles exceptions in both to and from, but doesn't do access_ok */
20354 __must_check unsigned long
20355-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20356+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20357 __must_check unsigned long
20358-copy_user_generic_string(void *to, const void *from, unsigned len);
20359+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20360 __must_check unsigned long
20361-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20362+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20363
20364 static __always_inline __must_check unsigned long
20365-copy_user_generic(void *to, const void *from, unsigned len)
20366+copy_user_generic(void *to, const void *from, unsigned long len)
20367 {
20368 unsigned ret;
20369
20370@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20371 }
20372
20373 __must_check unsigned long
20374-copy_in_user(void __user *to, const void __user *from, unsigned len);
20375+copy_in_user(void __user *to, const void __user *from, unsigned long len);
20376
20377 static __always_inline __must_check
20378-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20379+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20380 {
20381- int ret = 0;
20382+ size_t sz = __compiletime_object_size(dst);
20383+ unsigned ret = 0;
20384+
20385+ if (size > INT_MAX)
20386+ return size;
20387+
20388+ check_object_size(dst, size, false);
20389+
20390+#ifdef CONFIG_PAX_MEMORY_UDEREF
20391+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20392+ return size;
20393+#endif
20394+
20395+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20396+ if(__builtin_constant_p(size))
20397+ copy_from_user_overflow();
20398+ else
20399+ __copy_from_user_overflow(sz, size);
20400+ return size;
20401+ }
20402
20403 if (!__builtin_constant_p(size))
20404- return copy_user_generic(dst, (__force void *)src, size);
20405+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20406 switch (size) {
20407- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20408+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20409 ret, "b", "b", "=q", 1);
20410 return ret;
20411- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20412+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20413 ret, "w", "w", "=r", 2);
20414 return ret;
20415- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20416+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20417 ret, "l", "k", "=r", 4);
20418 return ret;
20419- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20420+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20421 ret, "q", "", "=r", 8);
20422 return ret;
20423 case 10:
20424- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20425+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20426 ret, "q", "", "=r", 10);
20427 if (unlikely(ret))
20428 return ret;
20429 __get_user_asm(*(u16 *)(8 + (char *)dst),
20430- (u16 __user *)(8 + (char __user *)src),
20431+ (const u16 __user *)(8 + (const char __user *)src),
20432 ret, "w", "w", "=r", 2);
20433 return ret;
20434 case 16:
20435- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20436+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20437 ret, "q", "", "=r", 16);
20438 if (unlikely(ret))
20439 return ret;
20440 __get_user_asm(*(u64 *)(8 + (char *)dst),
20441- (u64 __user *)(8 + (char __user *)src),
20442+ (const u64 __user *)(8 + (const char __user *)src),
20443 ret, "q", "", "=r", 8);
20444 return ret;
20445 default:
20446- return copy_user_generic(dst, (__force void *)src, size);
20447+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20448 }
20449 }
20450
20451 static __always_inline __must_check
20452-int __copy_from_user(void *dst, const void __user *src, unsigned size)
20453+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20454 {
20455 might_fault();
20456 return __copy_from_user_nocheck(dst, src, size);
20457 }
20458
20459 static __always_inline __must_check
20460-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20461+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20462 {
20463- int ret = 0;
20464+ size_t sz = __compiletime_object_size(src);
20465+ unsigned ret = 0;
20466+
20467+ if (size > INT_MAX)
20468+ return size;
20469+
20470+ check_object_size(src, size, true);
20471+
20472+#ifdef CONFIG_PAX_MEMORY_UDEREF
20473+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20474+ return size;
20475+#endif
20476+
20477+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20478+ if(__builtin_constant_p(size))
20479+ copy_to_user_overflow();
20480+ else
20481+ __copy_to_user_overflow(sz, size);
20482+ return size;
20483+ }
20484
20485 if (!__builtin_constant_p(size))
20486- return copy_user_generic((__force void *)dst, src, size);
20487+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20488 switch (size) {
20489- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20490+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20491 ret, "b", "b", "iq", 1);
20492 return ret;
20493- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20494+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20495 ret, "w", "w", "ir", 2);
20496 return ret;
20497- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20498+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20499 ret, "l", "k", "ir", 4);
20500 return ret;
20501- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20502+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20503 ret, "q", "", "er", 8);
20504 return ret;
20505 case 10:
20506- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20507+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20508 ret, "q", "", "er", 10);
20509 if (unlikely(ret))
20510 return ret;
20511 asm("":::"memory");
20512- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20513+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20514 ret, "w", "w", "ir", 2);
20515 return ret;
20516 case 16:
20517- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20518+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20519 ret, "q", "", "er", 16);
20520 if (unlikely(ret))
20521 return ret;
20522 asm("":::"memory");
20523- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20524+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20525 ret, "q", "", "er", 8);
20526 return ret;
20527 default:
20528- return copy_user_generic((__force void *)dst, src, size);
20529+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20530 }
20531 }
20532
20533 static __always_inline __must_check
20534-int __copy_to_user(void __user *dst, const void *src, unsigned size)
20535+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20536 {
20537 might_fault();
20538 return __copy_to_user_nocheck(dst, src, size);
20539 }
20540
20541 static __always_inline __must_check
20542-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20543+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20544 {
20545- int ret = 0;
20546+ unsigned ret = 0;
20547
20548 might_fault();
20549+
20550+ if (size > INT_MAX)
20551+ return size;
20552+
20553+#ifdef CONFIG_PAX_MEMORY_UDEREF
20554+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20555+ return size;
20556+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20557+ return size;
20558+#endif
20559+
20560 if (!__builtin_constant_p(size))
20561- return copy_user_generic((__force void *)dst,
20562- (__force void *)src, size);
20563+ return copy_user_generic((__force_kernel void *)____m(dst),
20564+ (__force_kernel const void *)____m(src), size);
20565 switch (size) {
20566 case 1: {
20567 u8 tmp;
20568- __get_user_asm(tmp, (u8 __user *)src,
20569+ __get_user_asm(tmp, (const u8 __user *)src,
20570 ret, "b", "b", "=q", 1);
20571 if (likely(!ret))
20572 __put_user_asm(tmp, (u8 __user *)dst,
20573@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20574 }
20575 case 2: {
20576 u16 tmp;
20577- __get_user_asm(tmp, (u16 __user *)src,
20578+ __get_user_asm(tmp, (const u16 __user *)src,
20579 ret, "w", "w", "=r", 2);
20580 if (likely(!ret))
20581 __put_user_asm(tmp, (u16 __user *)dst,
20582@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20583
20584 case 4: {
20585 u32 tmp;
20586- __get_user_asm(tmp, (u32 __user *)src,
20587+ __get_user_asm(tmp, (const u32 __user *)src,
20588 ret, "l", "k", "=r", 4);
20589 if (likely(!ret))
20590 __put_user_asm(tmp, (u32 __user *)dst,
20591@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20592 }
20593 case 8: {
20594 u64 tmp;
20595- __get_user_asm(tmp, (u64 __user *)src,
20596+ __get_user_asm(tmp, (const u64 __user *)src,
20597 ret, "q", "", "=r", 8);
20598 if (likely(!ret))
20599 __put_user_asm(tmp, (u64 __user *)dst,
20600@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20601 return ret;
20602 }
20603 default:
20604- return copy_user_generic((__force void *)dst,
20605- (__force void *)src, size);
20606+ return copy_user_generic((__force_kernel void *)____m(dst),
20607+ (__force_kernel const void *)____m(src), size);
20608 }
20609 }
20610
20611-static __must_check __always_inline int
20612-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20613+static __must_check __always_inline unsigned long
20614+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20615 {
20616 return __copy_from_user_nocheck(dst, src, size);
20617 }
20618
20619-static __must_check __always_inline int
20620-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20621+static __must_check __always_inline unsigned long
20622+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20623 {
20624 return __copy_to_user_nocheck(dst, src, size);
20625 }
20626
20627-extern long __copy_user_nocache(void *dst, const void __user *src,
20628- unsigned size, int zerorest);
20629+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20630+ unsigned long size, int zerorest);
20631
20632-static inline int
20633-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20634+static inline unsigned long
20635+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20636 {
20637 might_fault();
20638+
20639+ if (size > INT_MAX)
20640+ return size;
20641+
20642+#ifdef CONFIG_PAX_MEMORY_UDEREF
20643+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20644+ return size;
20645+#endif
20646+
20647 return __copy_user_nocache(dst, src, size, 1);
20648 }
20649
20650-static inline int
20651+static inline unsigned long
20652 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20653- unsigned size)
20654+ unsigned long size)
20655 {
20656+ if (size > INT_MAX)
20657+ return size;
20658+
20659+#ifdef CONFIG_PAX_MEMORY_UDEREF
20660+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20661+ return size;
20662+#endif
20663+
20664 return __copy_user_nocache(dst, src, size, 0);
20665 }
20666
20667 unsigned long
20668-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20669+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20670
20671 #endif /* _ASM_X86_UACCESS_64_H */
20672diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20673index 5b238981..77fdd78 100644
20674--- a/arch/x86/include/asm/word-at-a-time.h
20675+++ b/arch/x86/include/asm/word-at-a-time.h
20676@@ -11,7 +11,7 @@
20677 * and shift, for example.
20678 */
20679 struct word_at_a_time {
20680- const unsigned long one_bits, high_bits;
20681+ unsigned long one_bits, high_bits;
20682 };
20683
20684 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20685diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20686index e45e4da..44e8572 100644
20687--- a/arch/x86/include/asm/x86_init.h
20688+++ b/arch/x86/include/asm/x86_init.h
20689@@ -129,7 +129,7 @@ struct x86_init_ops {
20690 struct x86_init_timers timers;
20691 struct x86_init_iommu iommu;
20692 struct x86_init_pci pci;
20693-};
20694+} __no_const;
20695
20696 /**
20697 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20698@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20699 void (*setup_percpu_clockev)(void);
20700 void (*early_percpu_clock_init)(void);
20701 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20702-};
20703+} __no_const;
20704
20705 struct timespec;
20706
20707@@ -168,7 +168,7 @@ struct x86_platform_ops {
20708 void (*save_sched_clock_state)(void);
20709 void (*restore_sched_clock_state)(void);
20710 void (*apic_post_init)(void);
20711-};
20712+} __no_const;
20713
20714 struct pci_dev;
20715 struct msi_msg;
20716@@ -185,7 +185,7 @@ struct x86_msi_ops {
20717 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20718 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20719 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20720-};
20721+} __no_const;
20722
20723 struct IO_APIC_route_entry;
20724 struct io_apic_irq_attr;
20725@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20726 unsigned int destination, int vector,
20727 struct io_apic_irq_attr *attr);
20728 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20729-};
20730+} __no_const;
20731
20732 extern struct x86_init_ops x86_init;
20733 extern struct x86_cpuinit_ops x86_cpuinit;
20734diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20735index c949923..c22bfa4 100644
20736--- a/arch/x86/include/asm/xen/page.h
20737+++ b/arch/x86/include/asm/xen/page.h
20738@@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20739 extern struct page *m2p_find_override(unsigned long mfn);
20740 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20741
20742-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20743+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20744 {
20745 unsigned long mfn;
20746
20747diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20748index d949ef2..479b9d1 100644
20749--- a/arch/x86/include/asm/xsave.h
20750+++ b/arch/x86/include/asm/xsave.h
20751@@ -82,8 +82,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20752 if (unlikely(err))
20753 return -EFAULT;
20754
20755+ pax_open_userland();
20756 __asm__ __volatile__(ASM_STAC "\n"
20757- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20758+ "1:"
20759+ __copyuser_seg
20760+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20761 "2: " ASM_CLAC "\n"
20762 ".section .fixup,\"ax\"\n"
20763 "3: movl $-1,%[err]\n"
20764@@ -93,18 +96,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20765 : [err] "=r" (err)
20766 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20767 : "memory");
20768+ pax_close_userland();
20769 return err;
20770 }
20771
20772 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20773 {
20774 int err;
20775- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20776+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20777 u32 lmask = mask;
20778 u32 hmask = mask >> 32;
20779
20780+ pax_open_userland();
20781 __asm__ __volatile__(ASM_STAC "\n"
20782- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20783+ "1:"
20784+ __copyuser_seg
20785+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20786 "2: " ASM_CLAC "\n"
20787 ".section .fixup,\"ax\"\n"
20788 "3: movl $-1,%[err]\n"
20789@@ -114,6 +121,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20790 : [err] "=r" (err)
20791 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20792 : "memory"); /* memory required? */
20793+ pax_close_userland();
20794 return err;
20795 }
20796
20797diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20798index bbae024..e1528f9 100644
20799--- a/arch/x86/include/uapi/asm/e820.h
20800+++ b/arch/x86/include/uapi/asm/e820.h
20801@@ -63,7 +63,7 @@ struct e820map {
20802 #define ISA_START_ADDRESS 0xa0000
20803 #define ISA_END_ADDRESS 0x100000
20804
20805-#define BIOS_BEGIN 0x000a0000
20806+#define BIOS_BEGIN 0x000c0000
20807 #define BIOS_END 0x00100000
20808
20809 #define BIOS_ROM_BASE 0xffe00000
20810diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20811index 7b0a55a..ad115bf 100644
20812--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20813+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20814@@ -49,7 +49,6 @@
20815 #define EFLAGS 144
20816 #define RSP 152
20817 #define SS 160
20818-#define ARGOFFSET R11
20819 #endif /* __ASSEMBLY__ */
20820
20821 /* top of stack page */
20822diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20823index 047f9ff..4ba5ea6 100644
20824--- a/arch/x86/kernel/Makefile
20825+++ b/arch/x86/kernel/Makefile
20826@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20827 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20828 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20829 obj-y += probe_roms.o
20830-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20831+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20832 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20833 obj-$(CONFIG_X86_64) += mcount_64.o
20834 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20835diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20836index 86281ff..e046fc2 100644
20837--- a/arch/x86/kernel/acpi/boot.c
20838+++ b/arch/x86/kernel/acpi/boot.c
20839@@ -1296,7 +1296,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20840 * If your system is blacklisted here, but you find that acpi=force
20841 * works for you, please contact linux-acpi@vger.kernel.org
20842 */
20843-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20844+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20845 /*
20846 * Boxes that need ACPI disabled
20847 */
20848@@ -1371,7 +1371,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20849 };
20850
20851 /* second table for DMI checks that should run after early-quirks */
20852-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20853+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20854 /*
20855 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20856 * which includes some code which overrides all temperature
20857diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20858index 3136820..e2c6577 100644
20859--- a/arch/x86/kernel/acpi/sleep.c
20860+++ b/arch/x86/kernel/acpi/sleep.c
20861@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20862 #else /* CONFIG_64BIT */
20863 #ifdef CONFIG_SMP
20864 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20865+
20866+ pax_open_kernel();
20867 early_gdt_descr.address =
20868 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20869+ pax_close_kernel();
20870+
20871 initial_gs = per_cpu_offset(smp_processor_id());
20872 #endif
20873 initial_code = (unsigned long)wakeup_long64;
20874diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20875index 665c6b7..eae4d56 100644
20876--- a/arch/x86/kernel/acpi/wakeup_32.S
20877+++ b/arch/x86/kernel/acpi/wakeup_32.S
20878@@ -29,13 +29,11 @@ wakeup_pmode_return:
20879 # and restore the stack ... but you need gdt for this to work
20880 movl saved_context_esp, %esp
20881
20882- movl %cs:saved_magic, %eax
20883- cmpl $0x12345678, %eax
20884+ cmpl $0x12345678, saved_magic
20885 jne bogus_magic
20886
20887 # jump to place where we left off
20888- movl saved_eip, %eax
20889- jmp *%eax
20890+ jmp *(saved_eip)
20891
20892 bogus_magic:
20893 jmp bogus_magic
20894diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20895index 703130f..27a155d 100644
20896--- a/arch/x86/kernel/alternative.c
20897+++ b/arch/x86/kernel/alternative.c
20898@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20899 */
20900 for (a = start; a < end; a++) {
20901 instr = (u8 *)&a->instr_offset + a->instr_offset;
20902+
20903+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20904+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20905+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20906+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20907+#endif
20908+
20909 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20910 BUG_ON(a->replacementlen > a->instrlen);
20911 BUG_ON(a->instrlen > sizeof(insnbuf));
20912@@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20913 add_nops(insnbuf + a->replacementlen,
20914 a->instrlen - a->replacementlen);
20915
20916+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20917+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20918+ instr = ktva_ktla(instr);
20919+#endif
20920+
20921 text_poke_early(instr, insnbuf, a->instrlen);
20922 }
20923 }
20924@@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20925 for (poff = start; poff < end; poff++) {
20926 u8 *ptr = (u8 *)poff + *poff;
20927
20928+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20929+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20930+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20931+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20932+#endif
20933+
20934 if (!*poff || ptr < text || ptr >= text_end)
20935 continue;
20936 /* turn DS segment override prefix into lock prefix */
20937- if (*ptr == 0x3e)
20938+ if (*ktla_ktva(ptr) == 0x3e)
20939 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20940 }
20941 mutex_unlock(&text_mutex);
20942@@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20943 for (poff = start; poff < end; poff++) {
20944 u8 *ptr = (u8 *)poff + *poff;
20945
20946+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20947+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20948+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20949+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20950+#endif
20951+
20952 if (!*poff || ptr < text || ptr >= text_end)
20953 continue;
20954 /* turn lock prefix into DS segment override prefix */
20955- if (*ptr == 0xf0)
20956+ if (*ktla_ktva(ptr) == 0xf0)
20957 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20958 }
20959 mutex_unlock(&text_mutex);
20960@@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20961
20962 BUG_ON(p->len > MAX_PATCH_LEN);
20963 /* prep the buffer with the original instructions */
20964- memcpy(insnbuf, p->instr, p->len);
20965+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20966 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20967 (unsigned long)p->instr, p->len);
20968
20969@@ -504,7 +528,7 @@ void __init alternative_instructions(void)
20970 if (!uniproc_patched || num_possible_cpus() == 1)
20971 free_init_pages("SMP alternatives",
20972 (unsigned long)__smp_locks,
20973- (unsigned long)__smp_locks_end);
20974+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20975 #endif
20976
20977 apply_paravirt(__parainstructions, __parainstructions_end);
20978@@ -524,13 +548,17 @@ void __init alternative_instructions(void)
20979 * instructions. And on the local CPU you need to be protected again NMI or MCE
20980 * handlers seeing an inconsistent instruction while you patch.
20981 */
20982-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20983+void *__kprobes text_poke_early(void *addr, const void *opcode,
20984 size_t len)
20985 {
20986 unsigned long flags;
20987 local_irq_save(flags);
20988- memcpy(addr, opcode, len);
20989+
20990+ pax_open_kernel();
20991+ memcpy(ktla_ktva(addr), opcode, len);
20992 sync_core();
20993+ pax_close_kernel();
20994+
20995 local_irq_restore(flags);
20996 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20997 that causes hangs on some VIA CPUs. */
20998@@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20999 */
21000 void *text_poke(void *addr, const void *opcode, size_t len)
21001 {
21002- unsigned long flags;
21003- char *vaddr;
21004+ unsigned char *vaddr = ktla_ktva(addr);
21005 struct page *pages[2];
21006- int i;
21007+ size_t i;
21008
21009 if (!core_kernel_text((unsigned long)addr)) {
21010- pages[0] = vmalloc_to_page(addr);
21011- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
21012+ pages[0] = vmalloc_to_page(vaddr);
21013+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
21014 } else {
21015- pages[0] = virt_to_page(addr);
21016+ pages[0] = virt_to_page(vaddr);
21017 WARN_ON(!PageReserved(pages[0]));
21018- pages[1] = virt_to_page(addr + PAGE_SIZE);
21019+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
21020 }
21021 BUG_ON(!pages[0]);
21022- local_irq_save(flags);
21023- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
21024- if (pages[1])
21025- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
21026- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
21027- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
21028- clear_fixmap(FIX_TEXT_POKE0);
21029- if (pages[1])
21030- clear_fixmap(FIX_TEXT_POKE1);
21031- local_flush_tlb();
21032- sync_core();
21033- /* Could also do a CLFLUSH here to speed up CPU recovery; but
21034- that causes hangs on some VIA CPUs. */
21035+ text_poke_early(addr, opcode, len);
21036 for (i = 0; i < len; i++)
21037- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
21038- local_irq_restore(flags);
21039+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
21040 return addr;
21041 }
21042
21043@@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
21044 if (likely(!bp_patching_in_progress))
21045 return 0;
21046
21047- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
21048+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
21049 return 0;
21050
21051 /* set up the specified breakpoint handler */
21052@@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
21053 */
21054 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
21055 {
21056- unsigned char int3 = 0xcc;
21057+ const unsigned char int3 = 0xcc;
21058
21059 bp_int3_handler = handler;
21060 bp_int3_addr = (u8 *)addr + sizeof(int3);
21061diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
21062index ad28db7..c538b2c 100644
21063--- a/arch/x86/kernel/apic/apic.c
21064+++ b/arch/x86/kernel/apic/apic.c
21065@@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
21066 /*
21067 * Debug level, exported for io_apic.c
21068 */
21069-unsigned int apic_verbosity;
21070+int apic_verbosity;
21071
21072 int pic_mode;
21073
21074@@ -2000,7 +2000,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
21075 apic_write(APIC_ESR, 0);
21076 v = apic_read(APIC_ESR);
21077 ack_APIC_irq();
21078- atomic_inc(&irq_err_count);
21079+ atomic_inc_unchecked(&irq_err_count);
21080
21081 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
21082 smp_processor_id(), v);
21083diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
21084index 7c1b294..e71d27f 100644
21085--- a/arch/x86/kernel/apic/apic_flat_64.c
21086+++ b/arch/x86/kernel/apic/apic_flat_64.c
21087@@ -154,7 +154,7 @@ static int flat_probe(void)
21088 return 1;
21089 }
21090
21091-static struct apic apic_flat = {
21092+static struct apic apic_flat __read_only = {
21093 .name = "flat",
21094 .probe = flat_probe,
21095 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
21096@@ -268,7 +268,7 @@ static int physflat_probe(void)
21097 return 0;
21098 }
21099
21100-static struct apic apic_physflat = {
21101+static struct apic apic_physflat __read_only = {
21102
21103 .name = "physical flat",
21104 .probe = physflat_probe,
21105diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
21106index 8c7c982..a225910 100644
21107--- a/arch/x86/kernel/apic/apic_noop.c
21108+++ b/arch/x86/kernel/apic/apic_noop.c
21109@@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
21110 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
21111 }
21112
21113-struct apic apic_noop = {
21114+struct apic apic_noop __read_only = {
21115 .name = "noop",
21116 .probe = noop_probe,
21117 .acpi_madt_oem_check = NULL,
21118diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
21119index e4840aa..e7d9dac 100644
21120--- a/arch/x86/kernel/apic/bigsmp_32.c
21121+++ b/arch/x86/kernel/apic/bigsmp_32.c
21122@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
21123 return dmi_bigsmp;
21124 }
21125
21126-static struct apic apic_bigsmp = {
21127+static struct apic apic_bigsmp __read_only = {
21128
21129 .name = "bigsmp",
21130 .probe = probe_bigsmp,
21131diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
21132index 81e08ef..abc77e5 100644
21133--- a/arch/x86/kernel/apic/io_apic.c
21134+++ b/arch/x86/kernel/apic/io_apic.c
21135@@ -1042,7 +1042,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
21136 }
21137 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
21138
21139-void lock_vector_lock(void)
21140+void lock_vector_lock(void) __acquires(vector_lock)
21141 {
21142 /* Used to the online set of cpus does not change
21143 * during assign_irq_vector.
21144@@ -1050,7 +1050,7 @@ void lock_vector_lock(void)
21145 raw_spin_lock(&vector_lock);
21146 }
21147
21148-void unlock_vector_lock(void)
21149+void unlock_vector_lock(void) __releases(vector_lock)
21150 {
21151 raw_spin_unlock(&vector_lock);
21152 }
21153@@ -2349,7 +2349,7 @@ static void ack_apic_edge(struct irq_data *data)
21154 ack_APIC_irq();
21155 }
21156
21157-atomic_t irq_mis_count;
21158+atomic_unchecked_t irq_mis_count;
21159
21160 #ifdef CONFIG_GENERIC_PENDING_IRQ
21161 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
21162@@ -2490,7 +2490,7 @@ static void ack_apic_level(struct irq_data *data)
21163 * at the cpu.
21164 */
21165 if (!(v & (1 << (i & 0x1f)))) {
21166- atomic_inc(&irq_mis_count);
21167+ atomic_inc_unchecked(&irq_mis_count);
21168
21169 eoi_ioapic_irq(irq, cfg);
21170 }
21171diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
21172index cceb352..a635fd8 100644
21173--- a/arch/x86/kernel/apic/probe_32.c
21174+++ b/arch/x86/kernel/apic/probe_32.c
21175@@ -72,7 +72,7 @@ static int probe_default(void)
21176 return 1;
21177 }
21178
21179-static struct apic apic_default = {
21180+static struct apic apic_default __read_only = {
21181
21182 .name = "default",
21183 .probe = probe_default,
21184diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21185index e66766b..1c008ba 100644
21186--- a/arch/x86/kernel/apic/x2apic_cluster.c
21187+++ b/arch/x86/kernel/apic/x2apic_cluster.c
21188@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21189 return notifier_from_errno(err);
21190 }
21191
21192-static struct notifier_block __refdata x2apic_cpu_notifier = {
21193+static struct notifier_block x2apic_cpu_notifier = {
21194 .notifier_call = update_clusterinfo,
21195 };
21196
21197@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21198 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21199 }
21200
21201-static struct apic apic_x2apic_cluster = {
21202+static struct apic apic_x2apic_cluster __read_only = {
21203
21204 .name = "cluster x2apic",
21205 .probe = x2apic_cluster_probe,
21206diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21207index 6d600eb..0300c00 100644
21208--- a/arch/x86/kernel/apic/x2apic_phys.c
21209+++ b/arch/x86/kernel/apic/x2apic_phys.c
21210@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21211 return apic == &apic_x2apic_phys;
21212 }
21213
21214-static struct apic apic_x2apic_phys = {
21215+static struct apic apic_x2apic_phys __read_only = {
21216
21217 .name = "physical x2apic",
21218 .probe = x2apic_phys_probe,
21219diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21220index 293b41d..4df25fd 100644
21221--- a/arch/x86/kernel/apic/x2apic_uv_x.c
21222+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21223@@ -350,7 +350,7 @@ static int uv_probe(void)
21224 return apic == &apic_x2apic_uv_x;
21225 }
21226
21227-static struct apic __refdata apic_x2apic_uv_x = {
21228+static struct apic apic_x2apic_uv_x __read_only = {
21229
21230 .name = "UV large system",
21231 .probe = uv_probe,
21232diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21233index 5848744..56cb598 100644
21234--- a/arch/x86/kernel/apm_32.c
21235+++ b/arch/x86/kernel/apm_32.c
21236@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21237 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21238 * even though they are called in protected mode.
21239 */
21240-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21241+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21242 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21243
21244 static const char driver_version[] = "1.16ac"; /* no spaces */
21245@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21246 BUG_ON(cpu != 0);
21247 gdt = get_cpu_gdt_table(cpu);
21248 save_desc_40 = gdt[0x40 / 8];
21249+
21250+ pax_open_kernel();
21251 gdt[0x40 / 8] = bad_bios_desc;
21252+ pax_close_kernel();
21253
21254 apm_irq_save(flags);
21255 APM_DO_SAVE_SEGS;
21256@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21257 &call->esi);
21258 APM_DO_RESTORE_SEGS;
21259 apm_irq_restore(flags);
21260+
21261+ pax_open_kernel();
21262 gdt[0x40 / 8] = save_desc_40;
21263+ pax_close_kernel();
21264+
21265 put_cpu();
21266
21267 return call->eax & 0xff;
21268@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21269 BUG_ON(cpu != 0);
21270 gdt = get_cpu_gdt_table(cpu);
21271 save_desc_40 = gdt[0x40 / 8];
21272+
21273+ pax_open_kernel();
21274 gdt[0x40 / 8] = bad_bios_desc;
21275+ pax_close_kernel();
21276
21277 apm_irq_save(flags);
21278 APM_DO_SAVE_SEGS;
21279@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21280 &call->eax);
21281 APM_DO_RESTORE_SEGS;
21282 apm_irq_restore(flags);
21283+
21284+ pax_open_kernel();
21285 gdt[0x40 / 8] = save_desc_40;
21286+ pax_close_kernel();
21287+
21288 put_cpu();
21289 return error;
21290 }
21291@@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21292 * code to that CPU.
21293 */
21294 gdt = get_cpu_gdt_table(0);
21295+
21296+ pax_open_kernel();
21297 set_desc_base(&gdt[APM_CS >> 3],
21298 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21299 set_desc_base(&gdt[APM_CS_16 >> 3],
21300 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21301 set_desc_base(&gdt[APM_DS >> 3],
21302 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21303+ pax_close_kernel();
21304
21305 proc_create("apm", 0, NULL, &apm_file_ops);
21306
21307diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21308index 9f6b934..cf5ffb3 100644
21309--- a/arch/x86/kernel/asm-offsets.c
21310+++ b/arch/x86/kernel/asm-offsets.c
21311@@ -32,6 +32,8 @@ void common(void) {
21312 OFFSET(TI_flags, thread_info, flags);
21313 OFFSET(TI_status, thread_info, status);
21314 OFFSET(TI_addr_limit, thread_info, addr_limit);
21315+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21316+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21317
21318 BLANK();
21319 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21320@@ -52,8 +54,26 @@ void common(void) {
21321 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21322 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21323 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21324+
21325+#ifdef CONFIG_PAX_KERNEXEC
21326+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21327 #endif
21328
21329+#ifdef CONFIG_PAX_MEMORY_UDEREF
21330+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21331+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21332+#ifdef CONFIG_X86_64
21333+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21334+#endif
21335+#endif
21336+
21337+#endif
21338+
21339+ BLANK();
21340+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21341+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21342+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21343+
21344 #ifdef CONFIG_XEN
21345 BLANK();
21346 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21347diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21348index e7c798b..2b2019b 100644
21349--- a/arch/x86/kernel/asm-offsets_64.c
21350+++ b/arch/x86/kernel/asm-offsets_64.c
21351@@ -77,6 +77,7 @@ int main(void)
21352 BLANK();
21353 #undef ENTRY
21354
21355+ DEFINE(TSS_size, sizeof(struct tss_struct));
21356 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21357 BLANK();
21358
21359diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21360index 7fd54f0..0691410 100644
21361--- a/arch/x86/kernel/cpu/Makefile
21362+++ b/arch/x86/kernel/cpu/Makefile
21363@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21364 CFLAGS_REMOVE_perf_event.o = -pg
21365 endif
21366
21367-# Make sure load_percpu_segment has no stackprotector
21368-nostackp := $(call cc-option, -fno-stack-protector)
21369-CFLAGS_common.o := $(nostackp)
21370-
21371 obj-y := intel_cacheinfo.o scattered.o topology.o
21372 obj-y += proc.o capflags.o powerflags.o common.o
21373 obj-y += rdrand.o
21374diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21375index ce8b8ff..d7d8851 100644
21376--- a/arch/x86/kernel/cpu/amd.c
21377+++ b/arch/x86/kernel/cpu/amd.c
21378@@ -728,7 +728,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21379 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21380 {
21381 /* AMD errata T13 (order #21922) */
21382- if ((c->x86 == 6)) {
21383+ if (c->x86 == 6) {
21384 /* Duron Rev A0 */
21385 if (c->x86_model == 3 && c->x86_mask == 0)
21386 size = 64;
21387diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21388index ef1b93f..150db65 100644
21389--- a/arch/x86/kernel/cpu/common.c
21390+++ b/arch/x86/kernel/cpu/common.c
21391@@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21392
21393 static const struct cpu_dev *this_cpu = &default_cpu;
21394
21395-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21396-#ifdef CONFIG_X86_64
21397- /*
21398- * We need valid kernel segments for data and code in long mode too
21399- * IRET will check the segment types kkeil 2000/10/28
21400- * Also sysret mandates a special GDT layout
21401- *
21402- * TLS descriptors are currently at a different place compared to i386.
21403- * Hopefully nobody expects them at a fixed place (Wine?)
21404- */
21405- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21406- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21407- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21408- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21409- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21410- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21411-#else
21412- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21413- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21414- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21415- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21416- /*
21417- * Segments used for calling PnP BIOS have byte granularity.
21418- * They code segments and data segments have fixed 64k limits,
21419- * the transfer segment sizes are set at run time.
21420- */
21421- /* 32-bit code */
21422- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21423- /* 16-bit code */
21424- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21425- /* 16-bit data */
21426- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21427- /* 16-bit data */
21428- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21429- /* 16-bit data */
21430- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21431- /*
21432- * The APM segments have byte granularity and their bases
21433- * are set at run time. All have 64k limits.
21434- */
21435- /* 32-bit code */
21436- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21437- /* 16-bit code */
21438- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21439- /* data */
21440- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21441-
21442- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21443- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21444- GDT_STACK_CANARY_INIT
21445-#endif
21446-} };
21447-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21448-
21449 static int __init x86_xsave_setup(char *s)
21450 {
21451 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21452@@ -295,6 +241,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21453 }
21454 }
21455
21456+#ifdef CONFIG_X86_64
21457+static __init int setup_disable_pcid(char *arg)
21458+{
21459+ setup_clear_cpu_cap(X86_FEATURE_PCID);
21460+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21461+
21462+#ifdef CONFIG_PAX_MEMORY_UDEREF
21463+ if (clone_pgd_mask != ~(pgdval_t)0UL)
21464+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21465+#endif
21466+
21467+ return 1;
21468+}
21469+__setup("nopcid", setup_disable_pcid);
21470+
21471+static void setup_pcid(struct cpuinfo_x86 *c)
21472+{
21473+ if (!cpu_has(c, X86_FEATURE_PCID)) {
21474+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
21475+
21476+#ifdef CONFIG_PAX_MEMORY_UDEREF
21477+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
21478+ pax_open_kernel();
21479+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21480+ pax_close_kernel();
21481+ printk("PAX: slow and weak UDEREF enabled\n");
21482+ } else
21483+ printk("PAX: UDEREF disabled\n");
21484+#endif
21485+
21486+ return;
21487+ }
21488+
21489+ printk("PAX: PCID detected\n");
21490+ set_in_cr4(X86_CR4_PCIDE);
21491+
21492+#ifdef CONFIG_PAX_MEMORY_UDEREF
21493+ pax_open_kernel();
21494+ clone_pgd_mask = ~(pgdval_t)0UL;
21495+ pax_close_kernel();
21496+ if (pax_user_shadow_base)
21497+ printk("PAX: weak UDEREF enabled\n");
21498+ else {
21499+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21500+ printk("PAX: strong UDEREF enabled\n");
21501+ }
21502+#endif
21503+
21504+ if (cpu_has(c, X86_FEATURE_INVPCID))
21505+ printk("PAX: INVPCID detected\n");
21506+}
21507+#endif
21508+
21509 /*
21510 * Some CPU features depend on higher CPUID levels, which may not always
21511 * be available due to CPUID level capping or broken virtualization
21512@@ -395,7 +394,7 @@ void switch_to_new_gdt(int cpu)
21513 {
21514 struct desc_ptr gdt_descr;
21515
21516- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21517+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21518 gdt_descr.size = GDT_SIZE - 1;
21519 load_gdt(&gdt_descr);
21520 /* Reload the per-cpu base */
21521@@ -885,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21522 setup_smep(c);
21523 setup_smap(c);
21524
21525+#ifdef CONFIG_X86_64
21526+ setup_pcid(c);
21527+#endif
21528+
21529 /*
21530 * The vendor-specific functions might have changed features.
21531 * Now we do "generic changes."
21532@@ -893,6 +896,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21533 /* Filter out anything that depends on CPUID levels we don't have */
21534 filter_cpuid_features(c, true);
21535
21536+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21537+ setup_clear_cpu_cap(X86_FEATURE_SEP);
21538+#endif
21539+
21540 /* If the model name is still unset, do table lookup. */
21541 if (!c->x86_model_id[0]) {
21542 const char *p;
21543@@ -973,7 +980,7 @@ static void syscall32_cpu_init(void)
21544 void enable_sep_cpu(void)
21545 {
21546 int cpu = get_cpu();
21547- struct tss_struct *tss = &per_cpu(init_tss, cpu);
21548+ struct tss_struct *tss = init_tss + cpu;
21549
21550 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21551 put_cpu();
21552@@ -1113,14 +1120,16 @@ static __init int setup_disablecpuid(char *arg)
21553 }
21554 __setup("clearcpuid=", setup_disablecpuid);
21555
21556+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21557+EXPORT_PER_CPU_SYMBOL(current_tinfo);
21558+
21559 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21560- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21561+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21562 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21563
21564 #ifdef CONFIG_X86_64
21565-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21566-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21567- (unsigned long) debug_idt_table };
21568+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21569+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21570
21571 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21572 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21573@@ -1283,7 +1292,7 @@ void cpu_init(void)
21574 load_ucode_ap();
21575
21576 cpu = stack_smp_processor_id();
21577- t = &per_cpu(init_tss, cpu);
21578+ t = init_tss + cpu;
21579 oist = &per_cpu(orig_ist, cpu);
21580
21581 #ifdef CONFIG_NUMA
21582@@ -1318,7 +1327,6 @@ void cpu_init(void)
21583 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21584 barrier();
21585
21586- x86_configure_nx();
21587 enable_x2apic();
21588
21589 /*
21590@@ -1370,7 +1378,7 @@ void cpu_init(void)
21591 {
21592 int cpu = smp_processor_id();
21593 struct task_struct *curr = current;
21594- struct tss_struct *t = &per_cpu(init_tss, cpu);
21595+ struct tss_struct *t = init_tss + cpu;
21596 struct thread_struct *thread = &curr->thread;
21597
21598 show_ucode_info_early();
21599diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21600index 9c8f739..902a9c5 100644
21601--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21602+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21603@@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21604 };
21605
21606 #ifdef CONFIG_AMD_NB
21607+static struct attribute *default_attrs_amd_nb[] = {
21608+ &type.attr,
21609+ &level.attr,
21610+ &coherency_line_size.attr,
21611+ &physical_line_partition.attr,
21612+ &ways_of_associativity.attr,
21613+ &number_of_sets.attr,
21614+ &size.attr,
21615+ &shared_cpu_map.attr,
21616+ &shared_cpu_list.attr,
21617+ NULL,
21618+ NULL,
21619+ NULL,
21620+ NULL
21621+};
21622+
21623 static struct attribute **amd_l3_attrs(void)
21624 {
21625 static struct attribute **attrs;
21626@@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21627
21628 n = ARRAY_SIZE(default_attrs);
21629
21630- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21631- n += 2;
21632-
21633- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21634- n += 1;
21635-
21636- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21637- if (attrs == NULL)
21638- return attrs = default_attrs;
21639-
21640- for (n = 0; default_attrs[n]; n++)
21641- attrs[n] = default_attrs[n];
21642+ attrs = default_attrs_amd_nb;
21643
21644 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21645 attrs[n++] = &cache_disable_0.attr;
21646@@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21647 .default_attrs = default_attrs,
21648 };
21649
21650+#ifdef CONFIG_AMD_NB
21651+static struct kobj_type ktype_cache_amd_nb = {
21652+ .sysfs_ops = &sysfs_ops,
21653+ .default_attrs = default_attrs_amd_nb,
21654+};
21655+#endif
21656+
21657 static struct kobj_type ktype_percpu_entry = {
21658 .sysfs_ops = &sysfs_ops,
21659 };
21660@@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21661 return retval;
21662 }
21663
21664+#ifdef CONFIG_AMD_NB
21665+ amd_l3_attrs();
21666+#endif
21667+
21668 for (i = 0; i < num_cache_leaves; i++) {
21669+ struct kobj_type *ktype;
21670+
21671 this_object = INDEX_KOBJECT_PTR(cpu, i);
21672 this_object->cpu = cpu;
21673 this_object->index = i;
21674
21675 this_leaf = CPUID4_INFO_IDX(cpu, i);
21676
21677- ktype_cache.default_attrs = default_attrs;
21678+ ktype = &ktype_cache;
21679 #ifdef CONFIG_AMD_NB
21680 if (this_leaf->base.nb)
21681- ktype_cache.default_attrs = amd_l3_attrs();
21682+ ktype = &ktype_cache_amd_nb;
21683 #endif
21684 retval = kobject_init_and_add(&(this_object->kobj),
21685- &ktype_cache,
21686+ ktype,
21687 per_cpu(ici_cache_kobject, cpu),
21688 "index%1lu", i);
21689 if (unlikely(retval)) {
21690diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21691index 9a79c8d..158c2f1 100644
21692--- a/arch/x86/kernel/cpu/mcheck/mce.c
21693+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21694@@ -45,6 +45,7 @@
21695 #include <asm/processor.h>
21696 #include <asm/mce.h>
21697 #include <asm/msr.h>
21698+#include <asm/local.h>
21699
21700 #include "mce-internal.h"
21701
21702@@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21703 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21704 m->cs, m->ip);
21705
21706- if (m->cs == __KERNEL_CS)
21707+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21708 print_symbol("{%s}", m->ip);
21709 pr_cont("\n");
21710 }
21711@@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21712
21713 #define PANIC_TIMEOUT 5 /* 5 seconds */
21714
21715-static atomic_t mce_paniced;
21716+static atomic_unchecked_t mce_paniced;
21717
21718 static int fake_panic;
21719-static atomic_t mce_fake_paniced;
21720+static atomic_unchecked_t mce_fake_paniced;
21721
21722 /* Panic in progress. Enable interrupts and wait for final IPI */
21723 static void wait_for_panic(void)
21724@@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21725 /*
21726 * Make sure only one CPU runs in machine check panic
21727 */
21728- if (atomic_inc_return(&mce_paniced) > 1)
21729+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21730 wait_for_panic();
21731 barrier();
21732
21733@@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21734 console_verbose();
21735 } else {
21736 /* Don't log too much for fake panic */
21737- if (atomic_inc_return(&mce_fake_paniced) > 1)
21738+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21739 return;
21740 }
21741 /* First print corrected ones that are still unlogged */
21742@@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21743 if (!fake_panic) {
21744 if (panic_timeout == 0)
21745 panic_timeout = mca_cfg.panic_timeout;
21746- panic(msg);
21747+ panic("%s", msg);
21748 } else
21749 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21750 }
21751@@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21752 * might have been modified by someone else.
21753 */
21754 rmb();
21755- if (atomic_read(&mce_paniced))
21756+ if (atomic_read_unchecked(&mce_paniced))
21757 wait_for_panic();
21758 if (!mca_cfg.monarch_timeout)
21759 goto out;
21760@@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21761 }
21762
21763 /* Call the installed machine check handler for this CPU setup. */
21764-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21765+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21766 unexpected_machine_check;
21767
21768 /*
21769@@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21770 return;
21771 }
21772
21773+ pax_open_kernel();
21774 machine_check_vector = do_machine_check;
21775+ pax_close_kernel();
21776
21777 __mcheck_cpu_init_generic();
21778 __mcheck_cpu_init_vendor(c);
21779@@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21780 */
21781
21782 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21783-static int mce_chrdev_open_count; /* #times opened */
21784+static local_t mce_chrdev_open_count; /* #times opened */
21785 static int mce_chrdev_open_exclu; /* already open exclusive? */
21786
21787 static int mce_chrdev_open(struct inode *inode, struct file *file)
21788@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21789 spin_lock(&mce_chrdev_state_lock);
21790
21791 if (mce_chrdev_open_exclu ||
21792- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21793+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21794 spin_unlock(&mce_chrdev_state_lock);
21795
21796 return -EBUSY;
21797@@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21798
21799 if (file->f_flags & O_EXCL)
21800 mce_chrdev_open_exclu = 1;
21801- mce_chrdev_open_count++;
21802+ local_inc(&mce_chrdev_open_count);
21803
21804 spin_unlock(&mce_chrdev_state_lock);
21805
21806@@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21807 {
21808 spin_lock(&mce_chrdev_state_lock);
21809
21810- mce_chrdev_open_count--;
21811+ local_dec(&mce_chrdev_open_count);
21812 mce_chrdev_open_exclu = 0;
21813
21814 spin_unlock(&mce_chrdev_state_lock);
21815@@ -2414,7 +2417,7 @@ static __init void mce_init_banks(void)
21816
21817 for (i = 0; i < mca_cfg.banks; i++) {
21818 struct mce_bank *b = &mce_banks[i];
21819- struct device_attribute *a = &b->attr;
21820+ device_attribute_no_const *a = &b->attr;
21821
21822 sysfs_attr_init(&a->attr);
21823 a->attr.name = b->attrname;
21824@@ -2521,7 +2524,7 @@ struct dentry *mce_get_debugfs_dir(void)
21825 static void mce_reset(void)
21826 {
21827 cpu_missing = 0;
21828- atomic_set(&mce_fake_paniced, 0);
21829+ atomic_set_unchecked(&mce_fake_paniced, 0);
21830 atomic_set(&mce_executing, 0);
21831 atomic_set(&mce_callin, 0);
21832 atomic_set(&global_nwo, 0);
21833diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21834index a304298..49b6d06 100644
21835--- a/arch/x86/kernel/cpu/mcheck/p5.c
21836+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21837@@ -10,6 +10,7 @@
21838 #include <asm/processor.h>
21839 #include <asm/mce.h>
21840 #include <asm/msr.h>
21841+#include <asm/pgtable.h>
21842
21843 /* By default disabled */
21844 int mce_p5_enabled __read_mostly;
21845@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21846 if (!cpu_has(c, X86_FEATURE_MCE))
21847 return;
21848
21849+ pax_open_kernel();
21850 machine_check_vector = pentium_machine_check;
21851+ pax_close_kernel();
21852 /* Make sure the vector pointer is visible before we enable MCEs: */
21853 wmb();
21854
21855diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21856index 7dc5564..1273569 100644
21857--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21858+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21859@@ -9,6 +9,7 @@
21860 #include <asm/processor.h>
21861 #include <asm/mce.h>
21862 #include <asm/msr.h>
21863+#include <asm/pgtable.h>
21864
21865 /* Machine check handler for WinChip C6: */
21866 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21867@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21868 {
21869 u32 lo, hi;
21870
21871+ pax_open_kernel();
21872 machine_check_vector = winchip_machine_check;
21873+ pax_close_kernel();
21874 /* Make sure the vector pointer is visible before we enable MCEs: */
21875 wmb();
21876
21877diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21878index dd9d619..86e1d81 100644
21879--- a/arch/x86/kernel/cpu/microcode/core.c
21880+++ b/arch/x86/kernel/cpu/microcode/core.c
21881@@ -516,7 +516,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21882 return NOTIFY_OK;
21883 }
21884
21885-static struct notifier_block __refdata mc_cpu_notifier = {
21886+static struct notifier_block mc_cpu_notifier = {
21887 .notifier_call = mc_cpu_callback,
21888 };
21889
21890diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21891index a276fa7..e66810f 100644
21892--- a/arch/x86/kernel/cpu/microcode/intel.c
21893+++ b/arch/x86/kernel/cpu/microcode/intel.c
21894@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21895
21896 static int get_ucode_user(void *to, const void *from, size_t n)
21897 {
21898- return copy_from_user(to, from, n);
21899+ return copy_from_user(to, (const void __force_user *)from, n);
21900 }
21901
21902 static enum ucode_state
21903 request_microcode_user(int cpu, const void __user *buf, size_t size)
21904 {
21905- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21906+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21907 }
21908
21909 static void microcode_fini_cpu(int cpu)
21910diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21911index f961de9..8a9d332 100644
21912--- a/arch/x86/kernel/cpu/mtrr/main.c
21913+++ b/arch/x86/kernel/cpu/mtrr/main.c
21914@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21915 u64 size_or_mask, size_and_mask;
21916 static bool mtrr_aps_delayed_init;
21917
21918-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21919+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21920
21921 const struct mtrr_ops *mtrr_if;
21922
21923diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21924index df5e41f..816c719 100644
21925--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21926+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21927@@ -25,7 +25,7 @@ struct mtrr_ops {
21928 int (*validate_add_page)(unsigned long base, unsigned long size,
21929 unsigned int type);
21930 int (*have_wrcomb)(void);
21931-};
21932+} __do_const;
21933
21934 extern int generic_get_free_region(unsigned long base, unsigned long size,
21935 int replace_reg);
21936diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21937index 2879ecd..bb8c80b 100644
21938--- a/arch/x86/kernel/cpu/perf_event.c
21939+++ b/arch/x86/kernel/cpu/perf_event.c
21940@@ -1372,7 +1372,7 @@ static void __init pmu_check_apic(void)
21941
21942 }
21943
21944-static struct attribute_group x86_pmu_format_group = {
21945+static attribute_group_no_const x86_pmu_format_group = {
21946 .name = "format",
21947 .attrs = NULL,
21948 };
21949@@ -1471,7 +1471,7 @@ static struct attribute *events_attr[] = {
21950 NULL,
21951 };
21952
21953-static struct attribute_group x86_pmu_events_group = {
21954+static attribute_group_no_const x86_pmu_events_group = {
21955 .name = "events",
21956 .attrs = events_attr,
21957 };
21958@@ -1995,7 +1995,7 @@ static unsigned long get_segment_base(unsigned int segment)
21959 if (idx > GDT_ENTRIES)
21960 return 0;
21961
21962- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21963+ desc = get_cpu_gdt_table(smp_processor_id());
21964 }
21965
21966 return get_desc_base(desc + idx);
21967@@ -2085,7 +2085,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21968 break;
21969
21970 perf_callchain_store(entry, frame.return_address);
21971- fp = frame.next_frame;
21972+ fp = (const void __force_user *)frame.next_frame;
21973 }
21974 }
21975
21976diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21977index 639d128..e92d7e5 100644
21978--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21979+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21980@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21981 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21982 {
21983 struct attribute **attrs;
21984- struct attribute_group *attr_group;
21985+ attribute_group_no_const *attr_group;
21986 int i = 0, j;
21987
21988 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21989diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21990index 2502d0d..e5cc05c 100644
21991--- a/arch/x86/kernel/cpu/perf_event_intel.c
21992+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21993@@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
21994 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21995
21996 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21997- u64 capabilities;
21998+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21999
22000- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
22001- x86_pmu.intel_cap.capabilities = capabilities;
22002+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
22003+ x86_pmu.intel_cap.capabilities = capabilities;
22004 }
22005
22006 intel_ds_init();
22007diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22008index 619f769..d510008 100644
22009--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22010+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22011@@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
22012 NULL,
22013 };
22014
22015-static struct attribute_group rapl_pmu_events_group = {
22016+static attribute_group_no_const rapl_pmu_events_group __read_only = {
22017 .name = "events",
22018 .attrs = NULL, /* patched at runtime */
22019 };
22020diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22021index ae6552a..b5be2d3 100644
22022--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22023+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22024@@ -3694,7 +3694,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
22025 static int __init uncore_type_init(struct intel_uncore_type *type)
22026 {
22027 struct intel_uncore_pmu *pmus;
22028- struct attribute_group *attr_group;
22029+ attribute_group_no_const *attr_group;
22030 struct attribute **attrs;
22031 int i, j;
22032
22033diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22034index 90236f0..54cb20d 100644
22035--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22036+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22037@@ -503,7 +503,7 @@ struct intel_uncore_box {
22038 struct uncore_event_desc {
22039 struct kobj_attribute attr;
22040 const char *config;
22041-};
22042+} __do_const;
22043
22044 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
22045 { \
22046diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
22047index 3225ae6c..ee3c6db 100644
22048--- a/arch/x86/kernel/cpuid.c
22049+++ b/arch/x86/kernel/cpuid.c
22050@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
22051 return notifier_from_errno(err);
22052 }
22053
22054-static struct notifier_block __refdata cpuid_class_cpu_notifier =
22055+static struct notifier_block cpuid_class_cpu_notifier =
22056 {
22057 .notifier_call = cpuid_class_cpu_callback,
22058 };
22059diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
22060index 507de80..ebaae2a 100644
22061--- a/arch/x86/kernel/crash.c
22062+++ b/arch/x86/kernel/crash.c
22063@@ -58,7 +58,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
22064 #ifdef CONFIG_X86_32
22065 struct pt_regs fixed_regs;
22066
22067- if (!user_mode_vm(regs)) {
22068+ if (!user_mode(regs)) {
22069 crash_fixup_ss_esp(&fixed_regs, regs);
22070 regs = &fixed_regs;
22071 }
22072diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
22073index afa64ad..dce67dd 100644
22074--- a/arch/x86/kernel/crash_dump_64.c
22075+++ b/arch/x86/kernel/crash_dump_64.c
22076@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
22077 return -ENOMEM;
22078
22079 if (userbuf) {
22080- if (copy_to_user(buf, vaddr + offset, csize)) {
22081+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
22082 iounmap(vaddr);
22083 return -EFAULT;
22084 }
22085diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
22086index f6dfd93..892ade4 100644
22087--- a/arch/x86/kernel/doublefault.c
22088+++ b/arch/x86/kernel/doublefault.c
22089@@ -12,7 +12,7 @@
22090
22091 #define DOUBLEFAULT_STACKSIZE (1024)
22092 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
22093-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
22094+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
22095
22096 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
22097
22098@@ -22,7 +22,7 @@ static void doublefault_fn(void)
22099 unsigned long gdt, tss;
22100
22101 native_store_gdt(&gdt_desc);
22102- gdt = gdt_desc.address;
22103+ gdt = (unsigned long)gdt_desc.address;
22104
22105 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
22106
22107@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
22108 /* 0x2 bit is always set */
22109 .flags = X86_EFLAGS_SF | 0x2,
22110 .sp = STACK_START,
22111- .es = __USER_DS,
22112+ .es = __KERNEL_DS,
22113 .cs = __KERNEL_CS,
22114 .ss = __KERNEL_DS,
22115- .ds = __USER_DS,
22116+ .ds = __KERNEL_DS,
22117 .fs = __KERNEL_PERCPU,
22118
22119 .__cr3 = __pa_nodebug(swapper_pg_dir),
22120diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
22121index b74ebc7..6dbb0c5 100644
22122--- a/arch/x86/kernel/dumpstack.c
22123+++ b/arch/x86/kernel/dumpstack.c
22124@@ -2,6 +2,9 @@
22125 * Copyright (C) 1991, 1992 Linus Torvalds
22126 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
22127 */
22128+#ifdef CONFIG_GRKERNSEC_HIDESYM
22129+#define __INCLUDED_BY_HIDESYM 1
22130+#endif
22131 #include <linux/kallsyms.h>
22132 #include <linux/kprobes.h>
22133 #include <linux/uaccess.h>
22134@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
22135 static void
22136 print_ftrace_graph_addr(unsigned long addr, void *data,
22137 const struct stacktrace_ops *ops,
22138- struct thread_info *tinfo, int *graph)
22139+ struct task_struct *task, int *graph)
22140 {
22141- struct task_struct *task;
22142 unsigned long ret_addr;
22143 int index;
22144
22145 if (addr != (unsigned long)return_to_handler)
22146 return;
22147
22148- task = tinfo->task;
22149 index = task->curr_ret_stack;
22150
22151 if (!task->ret_stack || index < *graph)
22152@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22153 static inline void
22154 print_ftrace_graph_addr(unsigned long addr, void *data,
22155 const struct stacktrace_ops *ops,
22156- struct thread_info *tinfo, int *graph)
22157+ struct task_struct *task, int *graph)
22158 { }
22159 #endif
22160
22161@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22162 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
22163 */
22164
22165-static inline int valid_stack_ptr(struct thread_info *tinfo,
22166- void *p, unsigned int size, void *end)
22167+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
22168 {
22169- void *t = tinfo;
22170 if (end) {
22171 if (p < end && p >= (end-THREAD_SIZE))
22172 return 1;
22173@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
22174 }
22175
22176 unsigned long
22177-print_context_stack(struct thread_info *tinfo,
22178+print_context_stack(struct task_struct *task, void *stack_start,
22179 unsigned long *stack, unsigned long bp,
22180 const struct stacktrace_ops *ops, void *data,
22181 unsigned long *end, int *graph)
22182 {
22183 struct stack_frame *frame = (struct stack_frame *)bp;
22184
22185- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22186+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22187 unsigned long addr;
22188
22189 addr = *stack;
22190@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22191 } else {
22192 ops->address(data, addr, 0);
22193 }
22194- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22195+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22196 }
22197 stack++;
22198 }
22199@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22200 EXPORT_SYMBOL_GPL(print_context_stack);
22201
22202 unsigned long
22203-print_context_stack_bp(struct thread_info *tinfo,
22204+print_context_stack_bp(struct task_struct *task, void *stack_start,
22205 unsigned long *stack, unsigned long bp,
22206 const struct stacktrace_ops *ops, void *data,
22207 unsigned long *end, int *graph)
22208@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22209 struct stack_frame *frame = (struct stack_frame *)bp;
22210 unsigned long *ret_addr = &frame->return_address;
22211
22212- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22213+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22214 unsigned long addr = *ret_addr;
22215
22216 if (!__kernel_text_address(addr))
22217@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22218 ops->address(data, addr, 1);
22219 frame = frame->next_frame;
22220 ret_addr = &frame->return_address;
22221- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22222+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22223 }
22224
22225 return (unsigned long)frame;
22226@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22227 static void print_trace_address(void *data, unsigned long addr, int reliable)
22228 {
22229 touch_nmi_watchdog();
22230- printk(data);
22231+ printk("%s", (char *)data);
22232 printk_stack_address(addr, reliable);
22233 }
22234
22235@@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22236 EXPORT_SYMBOL_GPL(oops_begin);
22237 NOKPROBE_SYMBOL(oops_begin);
22238
22239+extern void gr_handle_kernel_exploit(void);
22240+
22241 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22242 {
22243 if (regs && kexec_should_crash(current))
22244@@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22245 panic("Fatal exception in interrupt");
22246 if (panic_on_oops)
22247 panic("Fatal exception");
22248- do_exit(signr);
22249+
22250+ gr_handle_kernel_exploit();
22251+
22252+ do_group_exit(signr);
22253 }
22254 NOKPROBE_SYMBOL(oops_end);
22255
22256@@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22257 print_modules();
22258 show_regs(regs);
22259 #ifdef CONFIG_X86_32
22260- if (user_mode_vm(regs)) {
22261+ if (user_mode(regs)) {
22262 sp = regs->sp;
22263 ss = regs->ss & 0xffff;
22264 } else {
22265@@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22266 unsigned long flags = oops_begin();
22267 int sig = SIGSEGV;
22268
22269- if (!user_mode_vm(regs))
22270+ if (!user_mode(regs))
22271 report_bug(regs->ip, regs);
22272
22273 if (__die(str, regs, err))
22274diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22275index 5abd4cd..c65733b 100644
22276--- a/arch/x86/kernel/dumpstack_32.c
22277+++ b/arch/x86/kernel/dumpstack_32.c
22278@@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22279 bp = stack_frame(task, regs);
22280
22281 for (;;) {
22282- struct thread_info *context;
22283+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22284 void *end_stack;
22285
22286 end_stack = is_hardirq_stack(stack, cpu);
22287 if (!end_stack)
22288 end_stack = is_softirq_stack(stack, cpu);
22289
22290- context = task_thread_info(task);
22291- bp = ops->walk_stack(context, stack, bp, ops, data,
22292+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22293 end_stack, &graph);
22294
22295 /* Stop if not on irq stack */
22296@@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22297 int i;
22298
22299 show_regs_print_info(KERN_EMERG);
22300- __show_regs(regs, !user_mode_vm(regs));
22301+ __show_regs(regs, !user_mode(regs));
22302
22303 /*
22304 * When in-kernel, we also print out the stack and code at the
22305 * time of the fault..
22306 */
22307- if (!user_mode_vm(regs)) {
22308+ if (!user_mode(regs)) {
22309 unsigned int code_prologue = code_bytes * 43 / 64;
22310 unsigned int code_len = code_bytes;
22311 unsigned char c;
22312 u8 *ip;
22313+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22314
22315 pr_emerg("Stack:\n");
22316 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22317
22318 pr_emerg("Code:");
22319
22320- ip = (u8 *)regs->ip - code_prologue;
22321+ ip = (u8 *)regs->ip - code_prologue + cs_base;
22322 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22323 /* try starting at IP */
22324- ip = (u8 *)regs->ip;
22325+ ip = (u8 *)regs->ip + cs_base;
22326 code_len = code_len - code_prologue + 1;
22327 }
22328 for (i = 0; i < code_len; i++, ip++) {
22329@@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22330 pr_cont(" Bad EIP value.");
22331 break;
22332 }
22333- if (ip == (u8 *)regs->ip)
22334+ if (ip == (u8 *)regs->ip + cs_base)
22335 pr_cont(" <%02x>", c);
22336 else
22337 pr_cont(" %02x", c);
22338@@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22339 {
22340 unsigned short ud2;
22341
22342+ ip = ktla_ktva(ip);
22343 if (ip < PAGE_OFFSET)
22344 return 0;
22345 if (probe_kernel_address((unsigned short *)ip, ud2))
22346@@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22347
22348 return ud2 == 0x0b0f;
22349 }
22350+
22351+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22352+void pax_check_alloca(unsigned long size)
22353+{
22354+ unsigned long sp = (unsigned long)&sp, stack_left;
22355+
22356+ /* all kernel stacks are of the same size */
22357+ stack_left = sp & (THREAD_SIZE - 1);
22358+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22359+}
22360+EXPORT_SYMBOL(pax_check_alloca);
22361+#endif
22362diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22363index 1abcb50..6c8d702 100644
22364--- a/arch/x86/kernel/dumpstack_64.c
22365+++ b/arch/x86/kernel/dumpstack_64.c
22366@@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22367 const struct stacktrace_ops *ops, void *data)
22368 {
22369 const unsigned cpu = get_cpu();
22370- struct thread_info *tinfo;
22371 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22372 unsigned long dummy;
22373 unsigned used = 0;
22374 int graph = 0;
22375 int done = 0;
22376+ void *stack_start;
22377
22378 if (!task)
22379 task = current;
22380@@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22381 * current stack address. If the stacks consist of nested
22382 * exceptions
22383 */
22384- tinfo = task_thread_info(task);
22385 while (!done) {
22386 unsigned long *stack_end;
22387 enum stack_type stype;
22388@@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22389 if (ops->stack(data, id) < 0)
22390 break;
22391
22392- bp = ops->walk_stack(tinfo, stack, bp, ops,
22393+ bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22394 data, stack_end, &graph);
22395 ops->stack(data, "<EOE>");
22396 /*
22397@@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22398 * second-to-last pointer (index -2 to end) in the
22399 * exception stack:
22400 */
22401+ if ((u16)stack_end[-1] != __KERNEL_DS)
22402+ goto out;
22403 stack = (unsigned long *) stack_end[-2];
22404 done = 0;
22405 break;
22406@@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22407
22408 if (ops->stack(data, "IRQ") < 0)
22409 break;
22410- bp = ops->walk_stack(tinfo, stack, bp,
22411+ bp = ops->walk_stack(task, irq_stack, stack, bp,
22412 ops, data, stack_end, &graph);
22413 /*
22414 * We link to the next stack (which would be
22415@@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22416 /*
22417 * This handles the process stack:
22418 */
22419- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22420+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22421+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22422+out:
22423 put_cpu();
22424 }
22425 EXPORT_SYMBOL(dump_trace);
22426@@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
22427
22428 return ud2 == 0x0b0f;
22429 }
22430+
22431+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22432+void pax_check_alloca(unsigned long size)
22433+{
22434+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22435+ unsigned cpu, used;
22436+ char *id;
22437+
22438+ /* check the process stack first */
22439+ stack_start = (unsigned long)task_stack_page(current);
22440+ stack_end = stack_start + THREAD_SIZE;
22441+ if (likely(stack_start <= sp && sp < stack_end)) {
22442+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
22443+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22444+ return;
22445+ }
22446+
22447+ cpu = get_cpu();
22448+
22449+ /* check the irq stacks */
22450+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22451+ stack_start = stack_end - IRQ_STACK_SIZE;
22452+ if (stack_start <= sp && sp < stack_end) {
22453+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22454+ put_cpu();
22455+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22456+ return;
22457+ }
22458+
22459+ /* check the exception stacks */
22460+ used = 0;
22461+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22462+ stack_start = stack_end - EXCEPTION_STKSZ;
22463+ if (stack_end && stack_start <= sp && sp < stack_end) {
22464+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22465+ put_cpu();
22466+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22467+ return;
22468+ }
22469+
22470+ put_cpu();
22471+
22472+ /* unknown stack */
22473+ BUG();
22474+}
22475+EXPORT_SYMBOL(pax_check_alloca);
22476+#endif
22477diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22478index 988c00a..4f673b6 100644
22479--- a/arch/x86/kernel/e820.c
22480+++ b/arch/x86/kernel/e820.c
22481@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22482
22483 static void early_panic(char *msg)
22484 {
22485- early_printk(msg);
22486- panic(msg);
22487+ early_printk("%s", msg);
22488+ panic("%s", msg);
22489 }
22490
22491 static int userdef __initdata;
22492diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22493index 01d1c18..8073693 100644
22494--- a/arch/x86/kernel/early_printk.c
22495+++ b/arch/x86/kernel/early_printk.c
22496@@ -7,6 +7,7 @@
22497 #include <linux/pci_regs.h>
22498 #include <linux/pci_ids.h>
22499 #include <linux/errno.h>
22500+#include <linux/sched.h>
22501 #include <asm/io.h>
22502 #include <asm/processor.h>
22503 #include <asm/fcntl.h>
22504diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22505index 0d0c9d4..f65b4f6 100644
22506--- a/arch/x86/kernel/entry_32.S
22507+++ b/arch/x86/kernel/entry_32.S
22508@@ -177,13 +177,153 @@
22509 /*CFI_REL_OFFSET gs, PT_GS*/
22510 .endm
22511 .macro SET_KERNEL_GS reg
22512+
22513+#ifdef CONFIG_CC_STACKPROTECTOR
22514 movl $(__KERNEL_STACK_CANARY), \reg
22515+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22516+ movl $(__USER_DS), \reg
22517+#else
22518+ xorl \reg, \reg
22519+#endif
22520+
22521 movl \reg, %gs
22522 .endm
22523
22524 #endif /* CONFIG_X86_32_LAZY_GS */
22525
22526-.macro SAVE_ALL
22527+.macro pax_enter_kernel
22528+#ifdef CONFIG_PAX_KERNEXEC
22529+ call pax_enter_kernel
22530+#endif
22531+.endm
22532+
22533+.macro pax_exit_kernel
22534+#ifdef CONFIG_PAX_KERNEXEC
22535+ call pax_exit_kernel
22536+#endif
22537+.endm
22538+
22539+#ifdef CONFIG_PAX_KERNEXEC
22540+ENTRY(pax_enter_kernel)
22541+#ifdef CONFIG_PARAVIRT
22542+ pushl %eax
22543+ pushl %ecx
22544+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22545+ mov %eax, %esi
22546+#else
22547+ mov %cr0, %esi
22548+#endif
22549+ bts $16, %esi
22550+ jnc 1f
22551+ mov %cs, %esi
22552+ cmp $__KERNEL_CS, %esi
22553+ jz 3f
22554+ ljmp $__KERNEL_CS, $3f
22555+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22556+2:
22557+#ifdef CONFIG_PARAVIRT
22558+ mov %esi, %eax
22559+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22560+#else
22561+ mov %esi, %cr0
22562+#endif
22563+3:
22564+#ifdef CONFIG_PARAVIRT
22565+ popl %ecx
22566+ popl %eax
22567+#endif
22568+ ret
22569+ENDPROC(pax_enter_kernel)
22570+
22571+ENTRY(pax_exit_kernel)
22572+#ifdef CONFIG_PARAVIRT
22573+ pushl %eax
22574+ pushl %ecx
22575+#endif
22576+ mov %cs, %esi
22577+ cmp $__KERNEXEC_KERNEL_CS, %esi
22578+ jnz 2f
22579+#ifdef CONFIG_PARAVIRT
22580+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22581+ mov %eax, %esi
22582+#else
22583+ mov %cr0, %esi
22584+#endif
22585+ btr $16, %esi
22586+ ljmp $__KERNEL_CS, $1f
22587+1:
22588+#ifdef CONFIG_PARAVIRT
22589+ mov %esi, %eax
22590+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22591+#else
22592+ mov %esi, %cr0
22593+#endif
22594+2:
22595+#ifdef CONFIG_PARAVIRT
22596+ popl %ecx
22597+ popl %eax
22598+#endif
22599+ ret
22600+ENDPROC(pax_exit_kernel)
22601+#endif
22602+
22603+ .macro pax_erase_kstack
22604+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22605+ call pax_erase_kstack
22606+#endif
22607+ .endm
22608+
22609+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22610+/*
22611+ * ebp: thread_info
22612+ */
22613+ENTRY(pax_erase_kstack)
22614+ pushl %edi
22615+ pushl %ecx
22616+ pushl %eax
22617+
22618+ mov TI_lowest_stack(%ebp), %edi
22619+ mov $-0xBEEF, %eax
22620+ std
22621+
22622+1: mov %edi, %ecx
22623+ and $THREAD_SIZE_asm - 1, %ecx
22624+ shr $2, %ecx
22625+ repne scasl
22626+ jecxz 2f
22627+
22628+ cmp $2*16, %ecx
22629+ jc 2f
22630+
22631+ mov $2*16, %ecx
22632+ repe scasl
22633+ jecxz 2f
22634+ jne 1b
22635+
22636+2: cld
22637+ mov %esp, %ecx
22638+ sub %edi, %ecx
22639+
22640+ cmp $THREAD_SIZE_asm, %ecx
22641+ jb 3f
22642+ ud2
22643+3:
22644+
22645+ shr $2, %ecx
22646+ rep stosl
22647+
22648+ mov TI_task_thread_sp0(%ebp), %edi
22649+ sub $128, %edi
22650+ mov %edi, TI_lowest_stack(%ebp)
22651+
22652+ popl %eax
22653+ popl %ecx
22654+ popl %edi
22655+ ret
22656+ENDPROC(pax_erase_kstack)
22657+#endif
22658+
22659+.macro __SAVE_ALL _DS
22660 cld
22661 PUSH_GS
22662 pushl_cfi %fs
22663@@ -206,7 +346,7 @@
22664 CFI_REL_OFFSET ecx, 0
22665 pushl_cfi %ebx
22666 CFI_REL_OFFSET ebx, 0
22667- movl $(__USER_DS), %edx
22668+ movl $\_DS, %edx
22669 movl %edx, %ds
22670 movl %edx, %es
22671 movl $(__KERNEL_PERCPU), %edx
22672@@ -214,6 +354,15 @@
22673 SET_KERNEL_GS %edx
22674 .endm
22675
22676+.macro SAVE_ALL
22677+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22678+ __SAVE_ALL __KERNEL_DS
22679+ pax_enter_kernel
22680+#else
22681+ __SAVE_ALL __USER_DS
22682+#endif
22683+.endm
22684+
22685 .macro RESTORE_INT_REGS
22686 popl_cfi %ebx
22687 CFI_RESTORE ebx
22688@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22689 popfl_cfi
22690 jmp syscall_exit
22691 CFI_ENDPROC
22692-END(ret_from_fork)
22693+ENDPROC(ret_from_fork)
22694
22695 ENTRY(ret_from_kernel_thread)
22696 CFI_STARTPROC
22697@@ -340,7 +489,15 @@ ret_from_intr:
22698 andl $SEGMENT_RPL_MASK, %eax
22699 #endif
22700 cmpl $USER_RPL, %eax
22701+
22702+#ifdef CONFIG_PAX_KERNEXEC
22703+ jae resume_userspace
22704+
22705+ pax_exit_kernel
22706+ jmp resume_kernel
22707+#else
22708 jb resume_kernel # not returning to v8086 or userspace
22709+#endif
22710
22711 ENTRY(resume_userspace)
22712 LOCKDEP_SYS_EXIT
22713@@ -352,8 +509,8 @@ ENTRY(resume_userspace)
22714 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22715 # int/exception return?
22716 jne work_pending
22717- jmp restore_all
22718-END(ret_from_exception)
22719+ jmp restore_all_pax
22720+ENDPROC(ret_from_exception)
22721
22722 #ifdef CONFIG_PREEMPT
22723 ENTRY(resume_kernel)
22724@@ -365,7 +522,7 @@ need_resched:
22725 jz restore_all
22726 call preempt_schedule_irq
22727 jmp need_resched
22728-END(resume_kernel)
22729+ENDPROC(resume_kernel)
22730 #endif
22731 CFI_ENDPROC
22732
22733@@ -395,30 +552,45 @@ sysenter_past_esp:
22734 /*CFI_REL_OFFSET cs, 0*/
22735 /*
22736 * Push current_thread_info()->sysenter_return to the stack.
22737- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22738- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22739 */
22740- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22741+ pushl_cfi $0
22742 CFI_REL_OFFSET eip, 0
22743
22744 pushl_cfi %eax
22745 SAVE_ALL
22746+ GET_THREAD_INFO(%ebp)
22747+ movl TI_sysenter_return(%ebp),%ebp
22748+ movl %ebp,PT_EIP(%esp)
22749 ENABLE_INTERRUPTS(CLBR_NONE)
22750
22751 /*
22752 * Load the potential sixth argument from user stack.
22753 * Careful about security.
22754 */
22755+ movl PT_OLDESP(%esp),%ebp
22756+
22757+#ifdef CONFIG_PAX_MEMORY_UDEREF
22758+ mov PT_OLDSS(%esp),%ds
22759+1: movl %ds:(%ebp),%ebp
22760+ push %ss
22761+ pop %ds
22762+#else
22763 cmpl $__PAGE_OFFSET-3,%ebp
22764 jae syscall_fault
22765 ASM_STAC
22766 1: movl (%ebp),%ebp
22767 ASM_CLAC
22768+#endif
22769+
22770 movl %ebp,PT_EBP(%esp)
22771 _ASM_EXTABLE(1b,syscall_fault)
22772
22773 GET_THREAD_INFO(%ebp)
22774
22775+#ifdef CONFIG_PAX_RANDKSTACK
22776+ pax_erase_kstack
22777+#endif
22778+
22779 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22780 jnz sysenter_audit
22781 sysenter_do_call:
22782@@ -434,12 +606,24 @@ sysenter_after_call:
22783 testl $_TIF_ALLWORK_MASK, %ecx
22784 jne sysexit_audit
22785 sysenter_exit:
22786+
22787+#ifdef CONFIG_PAX_RANDKSTACK
22788+ pushl_cfi %eax
22789+ movl %esp, %eax
22790+ call pax_randomize_kstack
22791+ popl_cfi %eax
22792+#endif
22793+
22794+ pax_erase_kstack
22795+
22796 /* if something modifies registers it must also disable sysexit */
22797 movl PT_EIP(%esp), %edx
22798 movl PT_OLDESP(%esp), %ecx
22799 xorl %ebp,%ebp
22800 TRACE_IRQS_ON
22801 1: mov PT_FS(%esp), %fs
22802+2: mov PT_DS(%esp), %ds
22803+3: mov PT_ES(%esp), %es
22804 PTGS_TO_GS
22805 ENABLE_INTERRUPTS_SYSEXIT
22806
22807@@ -456,6 +640,9 @@ sysenter_audit:
22808 movl %eax,%edx /* 2nd arg: syscall number */
22809 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22810 call __audit_syscall_entry
22811+
22812+ pax_erase_kstack
22813+
22814 pushl_cfi %ebx
22815 movl PT_EAX(%esp),%eax /* reload syscall number */
22816 jmp sysenter_do_call
22817@@ -481,10 +668,16 @@ sysexit_audit:
22818
22819 CFI_ENDPROC
22820 .pushsection .fixup,"ax"
22821-2: movl $0,PT_FS(%esp)
22822+4: movl $0,PT_FS(%esp)
22823+ jmp 1b
22824+5: movl $0,PT_DS(%esp)
22825+ jmp 1b
22826+6: movl $0,PT_ES(%esp)
22827 jmp 1b
22828 .popsection
22829- _ASM_EXTABLE(1b,2b)
22830+ _ASM_EXTABLE(1b,4b)
22831+ _ASM_EXTABLE(2b,5b)
22832+ _ASM_EXTABLE(3b,6b)
22833 PTGS_TO_GS_EX
22834 ENDPROC(ia32_sysenter_target)
22835
22836@@ -495,6 +688,11 @@ ENTRY(system_call)
22837 pushl_cfi %eax # save orig_eax
22838 SAVE_ALL
22839 GET_THREAD_INFO(%ebp)
22840+
22841+#ifdef CONFIG_PAX_RANDKSTACK
22842+ pax_erase_kstack
22843+#endif
22844+
22845 # system call tracing in operation / emulation
22846 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22847 jnz syscall_trace_entry
22848@@ -514,6 +712,15 @@ syscall_exit:
22849 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22850 jne syscall_exit_work
22851
22852+restore_all_pax:
22853+
22854+#ifdef CONFIG_PAX_RANDKSTACK
22855+ movl %esp, %eax
22856+ call pax_randomize_kstack
22857+#endif
22858+
22859+ pax_erase_kstack
22860+
22861 restore_all:
22862 TRACE_IRQS_IRET
22863 restore_all_notrace:
22864@@ -568,14 +775,34 @@ ldt_ss:
22865 * compensating for the offset by changing to the ESPFIX segment with
22866 * a base address that matches for the difference.
22867 */
22868-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22869+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22870 mov %esp, %edx /* load kernel esp */
22871 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22872 mov %dx, %ax /* eax: new kernel esp */
22873 sub %eax, %edx /* offset (low word is 0) */
22874+#ifdef CONFIG_SMP
22875+ movl PER_CPU_VAR(cpu_number), %ebx
22876+ shll $PAGE_SHIFT_asm, %ebx
22877+ addl $cpu_gdt_table, %ebx
22878+#else
22879+ movl $cpu_gdt_table, %ebx
22880+#endif
22881 shr $16, %edx
22882- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22883- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22884+
22885+#ifdef CONFIG_PAX_KERNEXEC
22886+ mov %cr0, %esi
22887+ btr $16, %esi
22888+ mov %esi, %cr0
22889+#endif
22890+
22891+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22892+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22893+
22894+#ifdef CONFIG_PAX_KERNEXEC
22895+ bts $16, %esi
22896+ mov %esi, %cr0
22897+#endif
22898+
22899 pushl_cfi $__ESPFIX_SS
22900 pushl_cfi %eax /* new kernel esp */
22901 /* Disable interrupts, but do not irqtrace this section: we
22902@@ -605,20 +832,18 @@ work_resched:
22903 movl TI_flags(%ebp), %ecx
22904 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22905 # than syscall tracing?
22906- jz restore_all
22907+ jz restore_all_pax
22908 testb $_TIF_NEED_RESCHED, %cl
22909 jnz work_resched
22910
22911 work_notifysig: # deal with pending signals and
22912 # notify-resume requests
22913+ movl %esp, %eax
22914 #ifdef CONFIG_VM86
22915 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22916- movl %esp, %eax
22917 jne work_notifysig_v86 # returning to kernel-space or
22918 # vm86-space
22919 1:
22920-#else
22921- movl %esp, %eax
22922 #endif
22923 TRACE_IRQS_ON
22924 ENABLE_INTERRUPTS(CLBR_NONE)
22925@@ -639,7 +864,7 @@ work_notifysig_v86:
22926 movl %eax, %esp
22927 jmp 1b
22928 #endif
22929-END(work_pending)
22930+ENDPROC(work_pending)
22931
22932 # perform syscall exit tracing
22933 ALIGN
22934@@ -647,11 +872,14 @@ syscall_trace_entry:
22935 movl $-ENOSYS,PT_EAX(%esp)
22936 movl %esp, %eax
22937 call syscall_trace_enter
22938+
22939+ pax_erase_kstack
22940+
22941 /* What it returned is what we'll actually use. */
22942 cmpl $(NR_syscalls), %eax
22943 jnae syscall_call
22944 jmp syscall_exit
22945-END(syscall_trace_entry)
22946+ENDPROC(syscall_trace_entry)
22947
22948 # perform syscall exit tracing
22949 ALIGN
22950@@ -664,26 +892,30 @@ syscall_exit_work:
22951 movl %esp, %eax
22952 call syscall_trace_leave
22953 jmp resume_userspace
22954-END(syscall_exit_work)
22955+ENDPROC(syscall_exit_work)
22956 CFI_ENDPROC
22957
22958 RING0_INT_FRAME # can't unwind into user space anyway
22959 syscall_fault:
22960+#ifdef CONFIG_PAX_MEMORY_UDEREF
22961+ push %ss
22962+ pop %ds
22963+#endif
22964 ASM_CLAC
22965 GET_THREAD_INFO(%ebp)
22966 movl $-EFAULT,PT_EAX(%esp)
22967 jmp resume_userspace
22968-END(syscall_fault)
22969+ENDPROC(syscall_fault)
22970
22971 syscall_badsys:
22972 movl $-ENOSYS,%eax
22973 jmp syscall_after_call
22974-END(syscall_badsys)
22975+ENDPROC(syscall_badsys)
22976
22977 sysenter_badsys:
22978 movl $-ENOSYS,%eax
22979 jmp sysenter_after_call
22980-END(syscall_badsys)
22981+ENDPROC(sysenter_badsys)
22982 CFI_ENDPROC
22983
22984 .macro FIXUP_ESPFIX_STACK
22985@@ -696,8 +928,15 @@ END(syscall_badsys)
22986 */
22987 #ifdef CONFIG_X86_ESPFIX32
22988 /* fixup the stack */
22989- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22990- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22991+#ifdef CONFIG_SMP
22992+ movl PER_CPU_VAR(cpu_number), %ebx
22993+ shll $PAGE_SHIFT_asm, %ebx
22994+ addl $cpu_gdt_table, %ebx
22995+#else
22996+ movl $cpu_gdt_table, %ebx
22997+#endif
22998+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22999+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
23000 shl $16, %eax
23001 addl %esp, %eax /* the adjusted stack pointer */
23002 pushl_cfi $__KERNEL_DS
23003@@ -753,7 +992,7 @@ vector=vector+1
23004 .endr
23005 2: jmp common_interrupt
23006 .endr
23007-END(irq_entries_start)
23008+ENDPROC(irq_entries_start)
23009
23010 .previous
23011 END(interrupt)
23012@@ -810,7 +1049,7 @@ ENTRY(coprocessor_error)
23013 pushl_cfi $do_coprocessor_error
23014 jmp error_code
23015 CFI_ENDPROC
23016-END(coprocessor_error)
23017+ENDPROC(coprocessor_error)
23018
23019 ENTRY(simd_coprocessor_error)
23020 RING0_INT_FRAME
23021@@ -823,7 +1062,7 @@ ENTRY(simd_coprocessor_error)
23022 .section .altinstructions,"a"
23023 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
23024 .previous
23025-.section .altinstr_replacement,"ax"
23026+.section .altinstr_replacement,"a"
23027 663: pushl $do_simd_coprocessor_error
23028 664:
23029 .previous
23030@@ -832,7 +1071,7 @@ ENTRY(simd_coprocessor_error)
23031 #endif
23032 jmp error_code
23033 CFI_ENDPROC
23034-END(simd_coprocessor_error)
23035+ENDPROC(simd_coprocessor_error)
23036
23037 ENTRY(device_not_available)
23038 RING0_INT_FRAME
23039@@ -841,18 +1080,18 @@ ENTRY(device_not_available)
23040 pushl_cfi $do_device_not_available
23041 jmp error_code
23042 CFI_ENDPROC
23043-END(device_not_available)
23044+ENDPROC(device_not_available)
23045
23046 #ifdef CONFIG_PARAVIRT
23047 ENTRY(native_iret)
23048 iret
23049 _ASM_EXTABLE(native_iret, iret_exc)
23050-END(native_iret)
23051+ENDPROC(native_iret)
23052
23053 ENTRY(native_irq_enable_sysexit)
23054 sti
23055 sysexit
23056-END(native_irq_enable_sysexit)
23057+ENDPROC(native_irq_enable_sysexit)
23058 #endif
23059
23060 ENTRY(overflow)
23061@@ -862,7 +1101,7 @@ ENTRY(overflow)
23062 pushl_cfi $do_overflow
23063 jmp error_code
23064 CFI_ENDPROC
23065-END(overflow)
23066+ENDPROC(overflow)
23067
23068 ENTRY(bounds)
23069 RING0_INT_FRAME
23070@@ -871,7 +1110,7 @@ ENTRY(bounds)
23071 pushl_cfi $do_bounds
23072 jmp error_code
23073 CFI_ENDPROC
23074-END(bounds)
23075+ENDPROC(bounds)
23076
23077 ENTRY(invalid_op)
23078 RING0_INT_FRAME
23079@@ -880,7 +1119,7 @@ ENTRY(invalid_op)
23080 pushl_cfi $do_invalid_op
23081 jmp error_code
23082 CFI_ENDPROC
23083-END(invalid_op)
23084+ENDPROC(invalid_op)
23085
23086 ENTRY(coprocessor_segment_overrun)
23087 RING0_INT_FRAME
23088@@ -889,7 +1128,7 @@ ENTRY(coprocessor_segment_overrun)
23089 pushl_cfi $do_coprocessor_segment_overrun
23090 jmp error_code
23091 CFI_ENDPROC
23092-END(coprocessor_segment_overrun)
23093+ENDPROC(coprocessor_segment_overrun)
23094
23095 ENTRY(invalid_TSS)
23096 RING0_EC_FRAME
23097@@ -897,7 +1136,7 @@ ENTRY(invalid_TSS)
23098 pushl_cfi $do_invalid_TSS
23099 jmp error_code
23100 CFI_ENDPROC
23101-END(invalid_TSS)
23102+ENDPROC(invalid_TSS)
23103
23104 ENTRY(segment_not_present)
23105 RING0_EC_FRAME
23106@@ -905,7 +1144,7 @@ ENTRY(segment_not_present)
23107 pushl_cfi $do_segment_not_present
23108 jmp error_code
23109 CFI_ENDPROC
23110-END(segment_not_present)
23111+ENDPROC(segment_not_present)
23112
23113 ENTRY(stack_segment)
23114 RING0_EC_FRAME
23115@@ -913,7 +1152,7 @@ ENTRY(stack_segment)
23116 pushl_cfi $do_stack_segment
23117 jmp error_code
23118 CFI_ENDPROC
23119-END(stack_segment)
23120+ENDPROC(stack_segment)
23121
23122 ENTRY(alignment_check)
23123 RING0_EC_FRAME
23124@@ -921,7 +1160,7 @@ ENTRY(alignment_check)
23125 pushl_cfi $do_alignment_check
23126 jmp error_code
23127 CFI_ENDPROC
23128-END(alignment_check)
23129+ENDPROC(alignment_check)
23130
23131 ENTRY(divide_error)
23132 RING0_INT_FRAME
23133@@ -930,7 +1169,7 @@ ENTRY(divide_error)
23134 pushl_cfi $do_divide_error
23135 jmp error_code
23136 CFI_ENDPROC
23137-END(divide_error)
23138+ENDPROC(divide_error)
23139
23140 #ifdef CONFIG_X86_MCE
23141 ENTRY(machine_check)
23142@@ -940,7 +1179,7 @@ ENTRY(machine_check)
23143 pushl_cfi machine_check_vector
23144 jmp error_code
23145 CFI_ENDPROC
23146-END(machine_check)
23147+ENDPROC(machine_check)
23148 #endif
23149
23150 ENTRY(spurious_interrupt_bug)
23151@@ -950,7 +1189,7 @@ ENTRY(spurious_interrupt_bug)
23152 pushl_cfi $do_spurious_interrupt_bug
23153 jmp error_code
23154 CFI_ENDPROC
23155-END(spurious_interrupt_bug)
23156+ENDPROC(spurious_interrupt_bug)
23157
23158 #ifdef CONFIG_XEN
23159 /* Xen doesn't set %esp to be precisely what the normal sysenter
23160@@ -1056,7 +1295,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
23161
23162 ENTRY(mcount)
23163 ret
23164-END(mcount)
23165+ENDPROC(mcount)
23166
23167 ENTRY(ftrace_caller)
23168 cmpl $0, function_trace_stop
23169@@ -1089,7 +1328,7 @@ ftrace_graph_call:
23170 .globl ftrace_stub
23171 ftrace_stub:
23172 ret
23173-END(ftrace_caller)
23174+ENDPROC(ftrace_caller)
23175
23176 ENTRY(ftrace_regs_caller)
23177 pushf /* push flags before compare (in cs location) */
23178@@ -1193,7 +1432,7 @@ trace:
23179 popl %ecx
23180 popl %eax
23181 jmp ftrace_stub
23182-END(mcount)
23183+ENDPROC(mcount)
23184 #endif /* CONFIG_DYNAMIC_FTRACE */
23185 #endif /* CONFIG_FUNCTION_TRACER */
23186
23187@@ -1211,7 +1450,7 @@ ENTRY(ftrace_graph_caller)
23188 popl %ecx
23189 popl %eax
23190 ret
23191-END(ftrace_graph_caller)
23192+ENDPROC(ftrace_graph_caller)
23193
23194 .globl return_to_handler
23195 return_to_handler:
23196@@ -1272,15 +1511,18 @@ error_code:
23197 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23198 REG_TO_PTGS %ecx
23199 SET_KERNEL_GS %ecx
23200- movl $(__USER_DS), %ecx
23201+ movl $(__KERNEL_DS), %ecx
23202 movl %ecx, %ds
23203 movl %ecx, %es
23204+
23205+ pax_enter_kernel
23206+
23207 TRACE_IRQS_OFF
23208 movl %esp,%eax # pt_regs pointer
23209 call *%edi
23210 jmp ret_from_exception
23211 CFI_ENDPROC
23212-END(page_fault)
23213+ENDPROC(page_fault)
23214
23215 /*
23216 * Debug traps and NMI can happen at the one SYSENTER instruction
23217@@ -1323,7 +1565,7 @@ debug_stack_correct:
23218 call do_debug
23219 jmp ret_from_exception
23220 CFI_ENDPROC
23221-END(debug)
23222+ENDPROC(debug)
23223
23224 /*
23225 * NMI is doubly nasty. It can happen _while_ we're handling
23226@@ -1363,6 +1605,9 @@ nmi_stack_correct:
23227 xorl %edx,%edx # zero error code
23228 movl %esp,%eax # pt_regs pointer
23229 call do_nmi
23230+
23231+ pax_exit_kernel
23232+
23233 jmp restore_all_notrace
23234 CFI_ENDPROC
23235
23236@@ -1400,13 +1645,16 @@ nmi_espfix_stack:
23237 FIXUP_ESPFIX_STACK # %eax == %esp
23238 xorl %edx,%edx # zero error code
23239 call do_nmi
23240+
23241+ pax_exit_kernel
23242+
23243 RESTORE_REGS
23244 lss 12+4(%esp), %esp # back to espfix stack
23245 CFI_ADJUST_CFA_OFFSET -24
23246 jmp irq_return
23247 #endif
23248 CFI_ENDPROC
23249-END(nmi)
23250+ENDPROC(nmi)
23251
23252 ENTRY(int3)
23253 RING0_INT_FRAME
23254@@ -1419,14 +1667,14 @@ ENTRY(int3)
23255 call do_int3
23256 jmp ret_from_exception
23257 CFI_ENDPROC
23258-END(int3)
23259+ENDPROC(int3)
23260
23261 ENTRY(general_protection)
23262 RING0_EC_FRAME
23263 pushl_cfi $do_general_protection
23264 jmp error_code
23265 CFI_ENDPROC
23266-END(general_protection)
23267+ENDPROC(general_protection)
23268
23269 #ifdef CONFIG_KVM_GUEST
23270 ENTRY(async_page_fault)
23271@@ -1435,6 +1683,6 @@ ENTRY(async_page_fault)
23272 pushl_cfi $do_async_page_fault
23273 jmp error_code
23274 CFI_ENDPROC
23275-END(async_page_fault)
23276+ENDPROC(async_page_fault)
23277 #endif
23278
23279diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23280index c844f08..b07ea0e 100644
23281--- a/arch/x86/kernel/entry_64.S
23282+++ b/arch/x86/kernel/entry_64.S
23283@@ -59,6 +59,8 @@
23284 #include <asm/smap.h>
23285 #include <asm/pgtable_types.h>
23286 #include <linux/err.h>
23287+#include <asm/pgtable.h>
23288+#include <asm/alternative-asm.h>
23289
23290 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23291 #include <linux/elf-em.h>
23292@@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23293 ENDPROC(native_usergs_sysret64)
23294 #endif /* CONFIG_PARAVIRT */
23295
23296+ .macro ljmpq sel, off
23297+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23298+ .byte 0x48; ljmp *1234f(%rip)
23299+ .pushsection .rodata
23300+ .align 16
23301+ 1234: .quad \off; .word \sel
23302+ .popsection
23303+#else
23304+ pushq $\sel
23305+ pushq $\off
23306+ lretq
23307+#endif
23308+ .endm
23309+
23310+ .macro pax_enter_kernel
23311+ pax_set_fptr_mask
23312+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23313+ call pax_enter_kernel
23314+#endif
23315+ .endm
23316+
23317+ .macro pax_exit_kernel
23318+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23319+ call pax_exit_kernel
23320+#endif
23321+
23322+ .endm
23323+
23324+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23325+ENTRY(pax_enter_kernel)
23326+ pushq %rdi
23327+
23328+#ifdef CONFIG_PARAVIRT
23329+ PV_SAVE_REGS(CLBR_RDI)
23330+#endif
23331+
23332+#ifdef CONFIG_PAX_KERNEXEC
23333+ GET_CR0_INTO_RDI
23334+ bts $16,%rdi
23335+ jnc 3f
23336+ mov %cs,%edi
23337+ cmp $__KERNEL_CS,%edi
23338+ jnz 2f
23339+1:
23340+#endif
23341+
23342+#ifdef CONFIG_PAX_MEMORY_UDEREF
23343+ 661: jmp 111f
23344+ .pushsection .altinstr_replacement, "a"
23345+ 662: ASM_NOP2
23346+ .popsection
23347+ .pushsection .altinstructions, "a"
23348+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23349+ .popsection
23350+ GET_CR3_INTO_RDI
23351+ cmp $0,%dil
23352+ jnz 112f
23353+ mov $__KERNEL_DS,%edi
23354+ mov %edi,%ss
23355+ jmp 111f
23356+112: cmp $1,%dil
23357+ jz 113f
23358+ ud2
23359+113: sub $4097,%rdi
23360+ bts $63,%rdi
23361+ SET_RDI_INTO_CR3
23362+ mov $__UDEREF_KERNEL_DS,%edi
23363+ mov %edi,%ss
23364+111:
23365+#endif
23366+
23367+#ifdef CONFIG_PARAVIRT
23368+ PV_RESTORE_REGS(CLBR_RDI)
23369+#endif
23370+
23371+ popq %rdi
23372+ pax_force_retaddr
23373+ retq
23374+
23375+#ifdef CONFIG_PAX_KERNEXEC
23376+2: ljmpq __KERNEL_CS,1b
23377+3: ljmpq __KERNEXEC_KERNEL_CS,4f
23378+4: SET_RDI_INTO_CR0
23379+ jmp 1b
23380+#endif
23381+ENDPROC(pax_enter_kernel)
23382+
23383+ENTRY(pax_exit_kernel)
23384+ pushq %rdi
23385+
23386+#ifdef CONFIG_PARAVIRT
23387+ PV_SAVE_REGS(CLBR_RDI)
23388+#endif
23389+
23390+#ifdef CONFIG_PAX_KERNEXEC
23391+ mov %cs,%rdi
23392+ cmp $__KERNEXEC_KERNEL_CS,%edi
23393+ jz 2f
23394+ GET_CR0_INTO_RDI
23395+ bts $16,%rdi
23396+ jnc 4f
23397+1:
23398+#endif
23399+
23400+#ifdef CONFIG_PAX_MEMORY_UDEREF
23401+ 661: jmp 111f
23402+ .pushsection .altinstr_replacement, "a"
23403+ 662: ASM_NOP2
23404+ .popsection
23405+ .pushsection .altinstructions, "a"
23406+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23407+ .popsection
23408+ mov %ss,%edi
23409+ cmp $__UDEREF_KERNEL_DS,%edi
23410+ jnz 111f
23411+ GET_CR3_INTO_RDI
23412+ cmp $0,%dil
23413+ jz 112f
23414+ ud2
23415+112: add $4097,%rdi
23416+ bts $63,%rdi
23417+ SET_RDI_INTO_CR3
23418+ mov $__KERNEL_DS,%edi
23419+ mov %edi,%ss
23420+111:
23421+#endif
23422+
23423+#ifdef CONFIG_PARAVIRT
23424+ PV_RESTORE_REGS(CLBR_RDI);
23425+#endif
23426+
23427+ popq %rdi
23428+ pax_force_retaddr
23429+ retq
23430+
23431+#ifdef CONFIG_PAX_KERNEXEC
23432+2: GET_CR0_INTO_RDI
23433+ btr $16,%rdi
23434+ jnc 4f
23435+ ljmpq __KERNEL_CS,3f
23436+3: SET_RDI_INTO_CR0
23437+ jmp 1b
23438+4: ud2
23439+ jmp 4b
23440+#endif
23441+ENDPROC(pax_exit_kernel)
23442+#endif
23443+
23444+ .macro pax_enter_kernel_user
23445+ pax_set_fptr_mask
23446+#ifdef CONFIG_PAX_MEMORY_UDEREF
23447+ call pax_enter_kernel_user
23448+#endif
23449+ .endm
23450+
23451+ .macro pax_exit_kernel_user
23452+#ifdef CONFIG_PAX_MEMORY_UDEREF
23453+ call pax_exit_kernel_user
23454+#endif
23455+#ifdef CONFIG_PAX_RANDKSTACK
23456+ pushq %rax
23457+ pushq %r11
23458+ call pax_randomize_kstack
23459+ popq %r11
23460+ popq %rax
23461+#endif
23462+ .endm
23463+
23464+#ifdef CONFIG_PAX_MEMORY_UDEREF
23465+ENTRY(pax_enter_kernel_user)
23466+ pushq %rdi
23467+ pushq %rbx
23468+
23469+#ifdef CONFIG_PARAVIRT
23470+ PV_SAVE_REGS(CLBR_RDI)
23471+#endif
23472+
23473+ 661: jmp 111f
23474+ .pushsection .altinstr_replacement, "a"
23475+ 662: ASM_NOP2
23476+ .popsection
23477+ .pushsection .altinstructions, "a"
23478+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23479+ .popsection
23480+ GET_CR3_INTO_RDI
23481+ cmp $1,%dil
23482+ jnz 4f
23483+ sub $4097,%rdi
23484+ bts $63,%rdi
23485+ SET_RDI_INTO_CR3
23486+ jmp 3f
23487+111:
23488+
23489+ GET_CR3_INTO_RDI
23490+ mov %rdi,%rbx
23491+ add $__START_KERNEL_map,%rbx
23492+ sub phys_base(%rip),%rbx
23493+
23494+#ifdef CONFIG_PARAVIRT
23495+ cmpl $0, pv_info+PARAVIRT_enabled
23496+ jz 1f
23497+ pushq %rdi
23498+ i = 0
23499+ .rept USER_PGD_PTRS
23500+ mov i*8(%rbx),%rsi
23501+ mov $0,%sil
23502+ lea i*8(%rbx),%rdi
23503+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23504+ i = i + 1
23505+ .endr
23506+ popq %rdi
23507+ jmp 2f
23508+1:
23509+#endif
23510+
23511+ i = 0
23512+ .rept USER_PGD_PTRS
23513+ movb $0,i*8(%rbx)
23514+ i = i + 1
23515+ .endr
23516+
23517+2: SET_RDI_INTO_CR3
23518+
23519+#ifdef CONFIG_PAX_KERNEXEC
23520+ GET_CR0_INTO_RDI
23521+ bts $16,%rdi
23522+ SET_RDI_INTO_CR0
23523+#endif
23524+
23525+3:
23526+
23527+#ifdef CONFIG_PARAVIRT
23528+ PV_RESTORE_REGS(CLBR_RDI)
23529+#endif
23530+
23531+ popq %rbx
23532+ popq %rdi
23533+ pax_force_retaddr
23534+ retq
23535+4: ud2
23536+ENDPROC(pax_enter_kernel_user)
23537+
23538+ENTRY(pax_exit_kernel_user)
23539+ pushq %rdi
23540+ pushq %rbx
23541+
23542+#ifdef CONFIG_PARAVIRT
23543+ PV_SAVE_REGS(CLBR_RDI)
23544+#endif
23545+
23546+ GET_CR3_INTO_RDI
23547+ 661: jmp 1f
23548+ .pushsection .altinstr_replacement, "a"
23549+ 662: ASM_NOP2
23550+ .popsection
23551+ .pushsection .altinstructions, "a"
23552+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23553+ .popsection
23554+ cmp $0,%dil
23555+ jnz 3f
23556+ add $4097,%rdi
23557+ bts $63,%rdi
23558+ SET_RDI_INTO_CR3
23559+ jmp 2f
23560+1:
23561+
23562+ mov %rdi,%rbx
23563+
23564+#ifdef CONFIG_PAX_KERNEXEC
23565+ GET_CR0_INTO_RDI
23566+ btr $16,%rdi
23567+ jnc 3f
23568+ SET_RDI_INTO_CR0
23569+#endif
23570+
23571+ add $__START_KERNEL_map,%rbx
23572+ sub phys_base(%rip),%rbx
23573+
23574+#ifdef CONFIG_PARAVIRT
23575+ cmpl $0, pv_info+PARAVIRT_enabled
23576+ jz 1f
23577+ i = 0
23578+ .rept USER_PGD_PTRS
23579+ mov i*8(%rbx),%rsi
23580+ mov $0x67,%sil
23581+ lea i*8(%rbx),%rdi
23582+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23583+ i = i + 1
23584+ .endr
23585+ jmp 2f
23586+1:
23587+#endif
23588+
23589+ i = 0
23590+ .rept USER_PGD_PTRS
23591+ movb $0x67,i*8(%rbx)
23592+ i = i + 1
23593+ .endr
23594+2:
23595+
23596+#ifdef CONFIG_PARAVIRT
23597+ PV_RESTORE_REGS(CLBR_RDI)
23598+#endif
23599+
23600+ popq %rbx
23601+ popq %rdi
23602+ pax_force_retaddr
23603+ retq
23604+3: ud2
23605+ENDPROC(pax_exit_kernel_user)
23606+#endif
23607+
23608+ .macro pax_enter_kernel_nmi
23609+ pax_set_fptr_mask
23610+
23611+#ifdef CONFIG_PAX_KERNEXEC
23612+ GET_CR0_INTO_RDI
23613+ bts $16,%rdi
23614+ jc 110f
23615+ SET_RDI_INTO_CR0
23616+ or $2,%ebx
23617+110:
23618+#endif
23619+
23620+#ifdef CONFIG_PAX_MEMORY_UDEREF
23621+ 661: jmp 111f
23622+ .pushsection .altinstr_replacement, "a"
23623+ 662: ASM_NOP2
23624+ .popsection
23625+ .pushsection .altinstructions, "a"
23626+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23627+ .popsection
23628+ GET_CR3_INTO_RDI
23629+ cmp $0,%dil
23630+ jz 111f
23631+ sub $4097,%rdi
23632+ or $4,%ebx
23633+ bts $63,%rdi
23634+ SET_RDI_INTO_CR3
23635+ mov $__UDEREF_KERNEL_DS,%edi
23636+ mov %edi,%ss
23637+111:
23638+#endif
23639+ .endm
23640+
23641+ .macro pax_exit_kernel_nmi
23642+#ifdef CONFIG_PAX_KERNEXEC
23643+ btr $1,%ebx
23644+ jnc 110f
23645+ GET_CR0_INTO_RDI
23646+ btr $16,%rdi
23647+ SET_RDI_INTO_CR0
23648+110:
23649+#endif
23650+
23651+#ifdef CONFIG_PAX_MEMORY_UDEREF
23652+ btr $2,%ebx
23653+ jnc 111f
23654+ GET_CR3_INTO_RDI
23655+ add $4097,%rdi
23656+ bts $63,%rdi
23657+ SET_RDI_INTO_CR3
23658+ mov $__KERNEL_DS,%edi
23659+ mov %edi,%ss
23660+111:
23661+#endif
23662+ .endm
23663+
23664+ .macro pax_erase_kstack
23665+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23666+ call pax_erase_kstack
23667+#endif
23668+ .endm
23669+
23670+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23671+ENTRY(pax_erase_kstack)
23672+ pushq %rdi
23673+ pushq %rcx
23674+ pushq %rax
23675+ pushq %r11
23676+
23677+ GET_THREAD_INFO(%r11)
23678+ mov TI_lowest_stack(%r11), %rdi
23679+ mov $-0xBEEF, %rax
23680+ std
23681+
23682+1: mov %edi, %ecx
23683+ and $THREAD_SIZE_asm - 1, %ecx
23684+ shr $3, %ecx
23685+ repne scasq
23686+ jecxz 2f
23687+
23688+ cmp $2*8, %ecx
23689+ jc 2f
23690+
23691+ mov $2*8, %ecx
23692+ repe scasq
23693+ jecxz 2f
23694+ jne 1b
23695+
23696+2: cld
23697+ mov %esp, %ecx
23698+ sub %edi, %ecx
23699+
23700+ cmp $THREAD_SIZE_asm, %rcx
23701+ jb 3f
23702+ ud2
23703+3:
23704+
23705+ shr $3, %ecx
23706+ rep stosq
23707+
23708+ mov TI_task_thread_sp0(%r11), %rdi
23709+ sub $256, %rdi
23710+ mov %rdi, TI_lowest_stack(%r11)
23711+
23712+ popq %r11
23713+ popq %rax
23714+ popq %rcx
23715+ popq %rdi
23716+ pax_force_retaddr
23717+ ret
23718+ENDPROC(pax_erase_kstack)
23719+#endif
23720
23721 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23722 #ifdef CONFIG_TRACE_IRQFLAGS
23723@@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
23724 .endm
23725
23726 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23727- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23728+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23729 jnc 1f
23730 TRACE_IRQS_ON_DEBUG
23731 1:
23732@@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
23733 movq \tmp,R11+\offset(%rsp)
23734 .endm
23735
23736- .macro FAKE_STACK_FRAME child_rip
23737- /* push in order ss, rsp, eflags, cs, rip */
23738- xorl %eax, %eax
23739- pushq_cfi $__KERNEL_DS /* ss */
23740- /*CFI_REL_OFFSET ss,0*/
23741- pushq_cfi %rax /* rsp */
23742- CFI_REL_OFFSET rsp,0
23743- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23744- /*CFI_REL_OFFSET rflags,0*/
23745- pushq_cfi $__KERNEL_CS /* cs */
23746- /*CFI_REL_OFFSET cs,0*/
23747- pushq_cfi \child_rip /* rip */
23748- CFI_REL_OFFSET rip,0
23749- pushq_cfi %rax /* orig rax */
23750- .endm
23751-
23752- .macro UNFAKE_STACK_FRAME
23753- addq $8*6, %rsp
23754- CFI_ADJUST_CFA_OFFSET -(6*8)
23755- .endm
23756-
23757 /*
23758 * initial frame state for interrupts (and exceptions without error code)
23759 */
23760@@ -242,25 +647,26 @@ ENDPROC(native_usergs_sysret64)
23761 /* save partial stack frame */
23762 .macro SAVE_ARGS_IRQ
23763 cld
23764- /* start from rbp in pt_regs and jump over */
23765- movq_cfi rdi, (RDI-RBP)
23766- movq_cfi rsi, (RSI-RBP)
23767- movq_cfi rdx, (RDX-RBP)
23768- movq_cfi rcx, (RCX-RBP)
23769- movq_cfi rax, (RAX-RBP)
23770- movq_cfi r8, (R8-RBP)
23771- movq_cfi r9, (R9-RBP)
23772- movq_cfi r10, (R10-RBP)
23773- movq_cfi r11, (R11-RBP)
23774+ /* start from r15 in pt_regs and jump over */
23775+ movq_cfi rdi, RDI
23776+ movq_cfi rsi, RSI
23777+ movq_cfi rdx, RDX
23778+ movq_cfi rcx, RCX
23779+ movq_cfi rax, RAX
23780+ movq_cfi r8, R8
23781+ movq_cfi r9, R9
23782+ movq_cfi r10, R10
23783+ movq_cfi r11, R11
23784+ movq_cfi r12, R12
23785
23786 /* Save rbp so that we can unwind from get_irq_regs() */
23787- movq_cfi rbp, 0
23788+ movq_cfi rbp, RBP
23789
23790 /* Save previous stack value */
23791 movq %rsp, %rsi
23792
23793- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23794- testl $3, CS-RBP(%rsi)
23795+ movq %rsp,%rdi /* arg1 for handler */
23796+ testb $3, CS(%rsi)
23797 je 1f
23798 SWAPGS
23799 /*
23800@@ -280,6 +686,18 @@ ENDPROC(native_usergs_sysret64)
23801 0x06 /* DW_OP_deref */, \
23802 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23803 0x22 /* DW_OP_plus */
23804+
23805+#ifdef CONFIG_PAX_MEMORY_UDEREF
23806+ testb $3, CS(%rdi)
23807+ jnz 1f
23808+ pax_enter_kernel
23809+ jmp 2f
23810+1: pax_enter_kernel_user
23811+2:
23812+#else
23813+ pax_enter_kernel
23814+#endif
23815+
23816 /* We entered an interrupt context - irqs are off: */
23817 TRACE_IRQS_OFF
23818 .endm
23819@@ -309,9 +727,52 @@ ENTRY(save_paranoid)
23820 js 1f /* negative -> in kernel */
23821 SWAPGS
23822 xorl %ebx,%ebx
23823-1: ret
23824+1:
23825+#ifdef CONFIG_PAX_MEMORY_UDEREF
23826+ testb $3, CS+8(%rsp)
23827+ jnz 1f
23828+ pax_enter_kernel
23829+ jmp 2f
23830+1: pax_enter_kernel_user
23831+2:
23832+#else
23833+ pax_enter_kernel
23834+#endif
23835+ pax_force_retaddr
23836+ ret
23837 CFI_ENDPROC
23838-END(save_paranoid)
23839+ENDPROC(save_paranoid)
23840+
23841+ENTRY(save_paranoid_nmi)
23842+ XCPT_FRAME 1 RDI+8
23843+ cld
23844+ movq_cfi rdi, RDI+8
23845+ movq_cfi rsi, RSI+8
23846+ movq_cfi rdx, RDX+8
23847+ movq_cfi rcx, RCX+8
23848+ movq_cfi rax, RAX+8
23849+ movq_cfi r8, R8+8
23850+ movq_cfi r9, R9+8
23851+ movq_cfi r10, R10+8
23852+ movq_cfi r11, R11+8
23853+ movq_cfi rbx, RBX+8
23854+ movq_cfi rbp, RBP+8
23855+ movq_cfi r12, R12+8
23856+ movq_cfi r13, R13+8
23857+ movq_cfi r14, R14+8
23858+ movq_cfi r15, R15+8
23859+ movl $1,%ebx
23860+ movl $MSR_GS_BASE,%ecx
23861+ rdmsr
23862+ testl %edx,%edx
23863+ js 1f /* negative -> in kernel */
23864+ SWAPGS
23865+ xorl %ebx,%ebx
23866+1: pax_enter_kernel_nmi
23867+ pax_force_retaddr
23868+ ret
23869+ CFI_ENDPROC
23870+ENDPROC(save_paranoid_nmi)
23871
23872 /*
23873 * A newly forked process directly context switches into this address.
23874@@ -332,7 +793,7 @@ ENTRY(ret_from_fork)
23875
23876 RESTORE_REST
23877
23878- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23879+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23880 jz 1f
23881
23882 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23883@@ -342,15 +803,13 @@ ENTRY(ret_from_fork)
23884 jmp ret_from_sys_call # go to the SYSRET fastpath
23885
23886 1:
23887- subq $REST_SKIP, %rsp # leave space for volatiles
23888- CFI_ADJUST_CFA_OFFSET REST_SKIP
23889 movq %rbp, %rdi
23890 call *%rbx
23891 movl $0, RAX(%rsp)
23892 RESTORE_REST
23893 jmp int_ret_from_sys_call
23894 CFI_ENDPROC
23895-END(ret_from_fork)
23896+ENDPROC(ret_from_fork)
23897
23898 /*
23899 * System call entry. Up to 6 arguments in registers are supported.
23900@@ -387,7 +846,7 @@ END(ret_from_fork)
23901 ENTRY(system_call)
23902 CFI_STARTPROC simple
23903 CFI_SIGNAL_FRAME
23904- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23905+ CFI_DEF_CFA rsp,0
23906 CFI_REGISTER rip,rcx
23907 /*CFI_REGISTER rflags,r11*/
23908 SWAPGS_UNSAFE_STACK
23909@@ -400,16 +859,23 @@ GLOBAL(system_call_after_swapgs)
23910
23911 movq %rsp,PER_CPU_VAR(old_rsp)
23912 movq PER_CPU_VAR(kernel_stack),%rsp
23913+ SAVE_ARGS 8*6,0
23914+ pax_enter_kernel_user
23915+
23916+#ifdef CONFIG_PAX_RANDKSTACK
23917+ pax_erase_kstack
23918+#endif
23919+
23920 /*
23921 * No need to follow this irqs off/on section - it's straight
23922 * and short:
23923 */
23924 ENABLE_INTERRUPTS(CLBR_NONE)
23925- SAVE_ARGS 8,0
23926 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23927 movq %rcx,RIP-ARGOFFSET(%rsp)
23928 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23929- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23930+ GET_THREAD_INFO(%rcx)
23931+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23932 jnz tracesys
23933 system_call_fastpath:
23934 #if __SYSCALL_MASK == ~0
23935@@ -433,10 +899,13 @@ sysret_check:
23936 LOCKDEP_SYS_EXIT
23937 DISABLE_INTERRUPTS(CLBR_NONE)
23938 TRACE_IRQS_OFF
23939- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23940+ GET_THREAD_INFO(%rcx)
23941+ movl TI_flags(%rcx),%edx
23942 andl %edi,%edx
23943 jnz sysret_careful
23944 CFI_REMEMBER_STATE
23945+ pax_exit_kernel_user
23946+ pax_erase_kstack
23947 /*
23948 * sysretq will re-enable interrupts:
23949 */
23950@@ -495,6 +964,9 @@ auditsys:
23951 movq %rax,%rsi /* 2nd arg: syscall number */
23952 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23953 call __audit_syscall_entry
23954+
23955+ pax_erase_kstack
23956+
23957 LOAD_ARGS 0 /* reload call-clobbered registers */
23958 jmp system_call_fastpath
23959
23960@@ -516,7 +988,7 @@ sysret_audit:
23961 /* Do syscall tracing */
23962 tracesys:
23963 #ifdef CONFIG_AUDITSYSCALL
23964- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23965+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23966 jz auditsys
23967 #endif
23968 SAVE_REST
23969@@ -524,12 +996,15 @@ tracesys:
23970 FIXUP_TOP_OF_STACK %rdi
23971 movq %rsp,%rdi
23972 call syscall_trace_enter
23973+
23974+ pax_erase_kstack
23975+
23976 /*
23977 * Reload arg registers from stack in case ptrace changed them.
23978 * We don't reload %rax because syscall_trace_enter() returned
23979 * the value it wants us to use in the table lookup.
23980 */
23981- LOAD_ARGS ARGOFFSET, 1
23982+ LOAD_ARGS 1
23983 RESTORE_REST
23984 #if __SYSCALL_MASK == ~0
23985 cmpq $__NR_syscall_max,%rax
23986@@ -559,7 +1034,9 @@ GLOBAL(int_with_check)
23987 andl %edi,%edx
23988 jnz int_careful
23989 andl $~TS_COMPAT,TI_status(%rcx)
23990- jmp retint_swapgs
23991+ pax_exit_kernel_user
23992+ pax_erase_kstack
23993+ jmp retint_swapgs_pax
23994
23995 /* Either reschedule or signal or syscall exit tracking needed. */
23996 /* First do a reschedule test. */
23997@@ -605,7 +1082,7 @@ int_restore_rest:
23998 TRACE_IRQS_OFF
23999 jmp int_with_check
24000 CFI_ENDPROC
24001-END(system_call)
24002+ENDPROC(system_call)
24003
24004 .macro FORK_LIKE func
24005 ENTRY(stub_\func)
24006@@ -618,9 +1095,10 @@ ENTRY(stub_\func)
24007 DEFAULT_FRAME 0 8 /* offset 8: return address */
24008 call sys_\func
24009 RESTORE_TOP_OF_STACK %r11, 8
24010- ret $REST_SKIP /* pop extended registers */
24011+ pax_force_retaddr
24012+ ret
24013 CFI_ENDPROC
24014-END(stub_\func)
24015+ENDPROC(stub_\func)
24016 .endm
24017
24018 .macro FIXED_FRAME label,func
24019@@ -630,9 +1108,10 @@ ENTRY(\label)
24020 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
24021 call \func
24022 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
24023+ pax_force_retaddr
24024 ret
24025 CFI_ENDPROC
24026-END(\label)
24027+ENDPROC(\label)
24028 .endm
24029
24030 FORK_LIKE clone
24031@@ -640,19 +1119,6 @@ END(\label)
24032 FORK_LIKE vfork
24033 FIXED_FRAME stub_iopl, sys_iopl
24034
24035-ENTRY(ptregscall_common)
24036- DEFAULT_FRAME 1 8 /* offset 8: return address */
24037- RESTORE_TOP_OF_STACK %r11, 8
24038- movq_cfi_restore R15+8, r15
24039- movq_cfi_restore R14+8, r14
24040- movq_cfi_restore R13+8, r13
24041- movq_cfi_restore R12+8, r12
24042- movq_cfi_restore RBP+8, rbp
24043- movq_cfi_restore RBX+8, rbx
24044- ret $REST_SKIP /* pop extended registers */
24045- CFI_ENDPROC
24046-END(ptregscall_common)
24047-
24048 ENTRY(stub_execve)
24049 CFI_STARTPROC
24050 addq $8, %rsp
24051@@ -664,7 +1130,7 @@ ENTRY(stub_execve)
24052 RESTORE_REST
24053 jmp int_ret_from_sys_call
24054 CFI_ENDPROC
24055-END(stub_execve)
24056+ENDPROC(stub_execve)
24057
24058 /*
24059 * sigreturn is special because it needs to restore all registers on return.
24060@@ -681,7 +1147,7 @@ ENTRY(stub_rt_sigreturn)
24061 RESTORE_REST
24062 jmp int_ret_from_sys_call
24063 CFI_ENDPROC
24064-END(stub_rt_sigreturn)
24065+ENDPROC(stub_rt_sigreturn)
24066
24067 #ifdef CONFIG_X86_X32_ABI
24068 ENTRY(stub_x32_rt_sigreturn)
24069@@ -695,7 +1161,7 @@ ENTRY(stub_x32_rt_sigreturn)
24070 RESTORE_REST
24071 jmp int_ret_from_sys_call
24072 CFI_ENDPROC
24073-END(stub_x32_rt_sigreturn)
24074+ENDPROC(stub_x32_rt_sigreturn)
24075
24076 ENTRY(stub_x32_execve)
24077 CFI_STARTPROC
24078@@ -709,7 +1175,7 @@ ENTRY(stub_x32_execve)
24079 RESTORE_REST
24080 jmp int_ret_from_sys_call
24081 CFI_ENDPROC
24082-END(stub_x32_execve)
24083+ENDPROC(stub_x32_execve)
24084
24085 #endif
24086
24087@@ -746,7 +1212,7 @@ vector=vector+1
24088 2: jmp common_interrupt
24089 .endr
24090 CFI_ENDPROC
24091-END(irq_entries_start)
24092+ENDPROC(irq_entries_start)
24093
24094 .previous
24095 END(interrupt)
24096@@ -763,8 +1229,8 @@ END(interrupt)
24097 /* 0(%rsp): ~(interrupt number) */
24098 .macro interrupt func
24099 /* reserve pt_regs for scratch regs and rbp */
24100- subq $ORIG_RAX-RBP, %rsp
24101- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
24102+ subq $ORIG_RAX, %rsp
24103+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
24104 SAVE_ARGS_IRQ
24105 call \func
24106 .endm
24107@@ -787,14 +1253,14 @@ ret_from_intr:
24108
24109 /* Restore saved previous stack */
24110 popq %rsi
24111- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24112- leaq ARGOFFSET-RBP(%rsi), %rsp
24113+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24114+ movq %rsi, %rsp
24115 CFI_DEF_CFA_REGISTER rsp
24116- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24117+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24118
24119 exit_intr:
24120 GET_THREAD_INFO(%rcx)
24121- testl $3,CS-ARGOFFSET(%rsp)
24122+ testb $3,CS-ARGOFFSET(%rsp)
24123 je retint_kernel
24124
24125 /* Interrupt came from user space */
24126@@ -816,12 +1282,16 @@ retint_swapgs: /* return to user-space */
24127 * The iretq could re-enable interrupts:
24128 */
24129 DISABLE_INTERRUPTS(CLBR_ANY)
24130+ pax_exit_kernel_user
24131+retint_swapgs_pax:
24132 TRACE_IRQS_IRETQ
24133 SWAPGS
24134 jmp restore_args
24135
24136 retint_restore_args: /* return to kernel space */
24137 DISABLE_INTERRUPTS(CLBR_ANY)
24138+ pax_exit_kernel
24139+ pax_force_retaddr (RIP-ARGOFFSET)
24140 /*
24141 * The iretq could re-enable interrupts:
24142 */
24143@@ -934,7 +1404,7 @@ ENTRY(retint_kernel)
24144 jmp exit_intr
24145 #endif
24146 CFI_ENDPROC
24147-END(common_interrupt)
24148+ENDPROC(common_interrupt)
24149
24150 /*
24151 * If IRET takes a fault on the espfix stack, then we
24152@@ -956,13 +1426,13 @@ __do_double_fault:
24153 cmpq $native_irq_return_iret,%rax
24154 jne do_double_fault /* This shouldn't happen... */
24155 movq PER_CPU_VAR(kernel_stack),%rax
24156- subq $(6*8-KERNEL_STACK_OFFSET),%rax /* Reset to original stack */
24157+ subq $(6*8),%rax /* Reset to original stack */
24158 movq %rax,RSP(%rdi)
24159 movq $0,(%rax) /* Missing (lost) #GP error code */
24160 movq $general_protection,RIP(%rdi)
24161 retq
24162 CFI_ENDPROC
24163-END(__do_double_fault)
24164+ENDPROC(__do_double_fault)
24165 #else
24166 # define __do_double_fault do_double_fault
24167 #endif
24168@@ -979,7 +1449,7 @@ ENTRY(\sym)
24169 interrupt \do_sym
24170 jmp ret_from_intr
24171 CFI_ENDPROC
24172-END(\sym)
24173+ENDPROC(\sym)
24174 .endm
24175
24176 #ifdef CONFIG_TRACING
24177@@ -1052,7 +1522,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24178 /*
24179 * Exception entry points.
24180 */
24181-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24182+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24183
24184 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24185 ENTRY(\sym)
24186@@ -1103,6 +1573,12 @@ ENTRY(\sym)
24187 .endif
24188
24189 .if \shift_ist != -1
24190+#ifdef CONFIG_SMP
24191+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24192+ lea init_tss(%r13), %r13
24193+#else
24194+ lea init_tss(%rip), %r13
24195+#endif
24196 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24197 .endif
24198
24199@@ -1119,7 +1595,7 @@ ENTRY(\sym)
24200 .endif
24201
24202 CFI_ENDPROC
24203-END(\sym)
24204+ENDPROC(\sym)
24205 .endm
24206
24207 #ifdef CONFIG_TRACING
24208@@ -1160,9 +1636,10 @@ gs_change:
24209 2: mfence /* workaround */
24210 SWAPGS
24211 popfq_cfi
24212+ pax_force_retaddr
24213 ret
24214 CFI_ENDPROC
24215-END(native_load_gs_index)
24216+ENDPROC(native_load_gs_index)
24217
24218 _ASM_EXTABLE(gs_change,bad_gs)
24219 .section .fixup,"ax"
24220@@ -1190,9 +1667,10 @@ ENTRY(do_softirq_own_stack)
24221 CFI_DEF_CFA_REGISTER rsp
24222 CFI_ADJUST_CFA_OFFSET -8
24223 decl PER_CPU_VAR(irq_count)
24224+ pax_force_retaddr
24225 ret
24226 CFI_ENDPROC
24227-END(do_softirq_own_stack)
24228+ENDPROC(do_softirq_own_stack)
24229
24230 #ifdef CONFIG_XEN
24231 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24232@@ -1230,7 +1708,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24233 decl PER_CPU_VAR(irq_count)
24234 jmp error_exit
24235 CFI_ENDPROC
24236-END(xen_do_hypervisor_callback)
24237+ENDPROC(xen_do_hypervisor_callback)
24238
24239 /*
24240 * Hypervisor uses this for application faults while it executes.
24241@@ -1289,7 +1767,7 @@ ENTRY(xen_failsafe_callback)
24242 SAVE_ALL
24243 jmp error_exit
24244 CFI_ENDPROC
24245-END(xen_failsafe_callback)
24246+ENDPROC(xen_failsafe_callback)
24247
24248 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24249 xen_hvm_callback_vector xen_evtchn_do_upcall
24250@@ -1336,18 +1814,33 @@ ENTRY(paranoid_exit)
24251 DEFAULT_FRAME
24252 DISABLE_INTERRUPTS(CLBR_NONE)
24253 TRACE_IRQS_OFF_DEBUG
24254- testl %ebx,%ebx /* swapgs needed? */
24255+ testl $1,%ebx /* swapgs needed? */
24256 jnz paranoid_restore
24257- testl $3,CS(%rsp)
24258+ testb $3,CS(%rsp)
24259 jnz paranoid_userspace
24260+#ifdef CONFIG_PAX_MEMORY_UDEREF
24261+ pax_exit_kernel
24262+ TRACE_IRQS_IRETQ 0
24263+ SWAPGS_UNSAFE_STACK
24264+ RESTORE_ALL 8
24265+ pax_force_retaddr_bts
24266+ jmp irq_return
24267+#endif
24268 paranoid_swapgs:
24269+#ifdef CONFIG_PAX_MEMORY_UDEREF
24270+ pax_exit_kernel_user
24271+#else
24272+ pax_exit_kernel
24273+#endif
24274 TRACE_IRQS_IRETQ 0
24275 SWAPGS_UNSAFE_STACK
24276 RESTORE_ALL 8
24277 jmp irq_return
24278 paranoid_restore:
24279+ pax_exit_kernel
24280 TRACE_IRQS_IRETQ_DEBUG 0
24281 RESTORE_ALL 8
24282+ pax_force_retaddr_bts
24283 jmp irq_return
24284 paranoid_userspace:
24285 GET_THREAD_INFO(%rcx)
24286@@ -1376,7 +1869,7 @@ paranoid_schedule:
24287 TRACE_IRQS_OFF
24288 jmp paranoid_userspace
24289 CFI_ENDPROC
24290-END(paranoid_exit)
24291+ENDPROC(paranoid_exit)
24292
24293 /*
24294 * Exception entry point. This expects an error code/orig_rax on the stack.
24295@@ -1403,12 +1896,23 @@ ENTRY(error_entry)
24296 movq_cfi r14, R14+8
24297 movq_cfi r15, R15+8
24298 xorl %ebx,%ebx
24299- testl $3,CS+8(%rsp)
24300+ testb $3,CS+8(%rsp)
24301 je error_kernelspace
24302 error_swapgs:
24303 SWAPGS
24304 error_sti:
24305+#ifdef CONFIG_PAX_MEMORY_UDEREF
24306+ testb $3, CS+8(%rsp)
24307+ jnz 1f
24308+ pax_enter_kernel
24309+ jmp 2f
24310+1: pax_enter_kernel_user
24311+2:
24312+#else
24313+ pax_enter_kernel
24314+#endif
24315 TRACE_IRQS_OFF
24316+ pax_force_retaddr
24317 ret
24318
24319 /*
24320@@ -1435,7 +1939,7 @@ bstep_iret:
24321 movq %rcx,RIP+8(%rsp)
24322 jmp error_swapgs
24323 CFI_ENDPROC
24324-END(error_entry)
24325+ENDPROC(error_entry)
24326
24327
24328 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24329@@ -1446,7 +1950,7 @@ ENTRY(error_exit)
24330 DISABLE_INTERRUPTS(CLBR_NONE)
24331 TRACE_IRQS_OFF
24332 GET_THREAD_INFO(%rcx)
24333- testl %eax,%eax
24334+ testl $1,%eax
24335 jne retint_kernel
24336 LOCKDEP_SYS_EXIT_IRQ
24337 movl TI_flags(%rcx),%edx
24338@@ -1455,7 +1959,7 @@ ENTRY(error_exit)
24339 jnz retint_careful
24340 jmp retint_swapgs
24341 CFI_ENDPROC
24342-END(error_exit)
24343+ENDPROC(error_exit)
24344
24345 /*
24346 * Test if a given stack is an NMI stack or not.
24347@@ -1513,9 +2017,11 @@ ENTRY(nmi)
24348 * If %cs was not the kernel segment, then the NMI triggered in user
24349 * space, which means it is definitely not nested.
24350 */
24351+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24352+ je 1f
24353 cmpl $__KERNEL_CS, 16(%rsp)
24354 jne first_nmi
24355-
24356+1:
24357 /*
24358 * Check the special variable on the stack to see if NMIs are
24359 * executing.
24360@@ -1549,8 +2055,7 @@ nested_nmi:
24361
24362 1:
24363 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24364- leaq -1*8(%rsp), %rdx
24365- movq %rdx, %rsp
24366+ subq $8, %rsp
24367 CFI_ADJUST_CFA_OFFSET 1*8
24368 leaq -10*8(%rsp), %rdx
24369 pushq_cfi $__KERNEL_DS
24370@@ -1568,6 +2073,7 @@ nested_nmi_out:
24371 CFI_RESTORE rdx
24372
24373 /* No need to check faults here */
24374+# pax_force_retaddr_bts
24375 INTERRUPT_RETURN
24376
24377 CFI_RESTORE_STATE
24378@@ -1664,13 +2170,13 @@ end_repeat_nmi:
24379 subq $ORIG_RAX-R15, %rsp
24380 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24381 /*
24382- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24383+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24384 * as we should not be calling schedule in NMI context.
24385 * Even with normal interrupts enabled. An NMI should not be
24386 * setting NEED_RESCHED or anything that normal interrupts and
24387 * exceptions might do.
24388 */
24389- call save_paranoid
24390+ call save_paranoid_nmi
24391 DEFAULT_FRAME 0
24392
24393 /*
24394@@ -1680,9 +2186,9 @@ end_repeat_nmi:
24395 * NMI itself takes a page fault, the page fault that was preempted
24396 * will read the information from the NMI page fault and not the
24397 * origin fault. Save it off and restore it if it changes.
24398- * Use the r12 callee-saved register.
24399+ * Use the r13 callee-saved register.
24400 */
24401- movq %cr2, %r12
24402+ movq %cr2, %r13
24403
24404 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24405 movq %rsp,%rdi
24406@@ -1691,29 +2197,34 @@ end_repeat_nmi:
24407
24408 /* Did the NMI take a page fault? Restore cr2 if it did */
24409 movq %cr2, %rcx
24410- cmpq %rcx, %r12
24411+ cmpq %rcx, %r13
24412 je 1f
24413- movq %r12, %cr2
24414+ movq %r13, %cr2
24415 1:
24416
24417- testl %ebx,%ebx /* swapgs needed? */
24418+ testl $1,%ebx /* swapgs needed? */
24419 jnz nmi_restore
24420 nmi_swapgs:
24421 SWAPGS_UNSAFE_STACK
24422 nmi_restore:
24423+ pax_exit_kernel_nmi
24424 /* Pop the extra iret frame at once */
24425 RESTORE_ALL 6*8
24426+ testb $3, 8(%rsp)
24427+ jnz 1f
24428+ pax_force_retaddr_bts
24429+1:
24430
24431 /* Clear the NMI executing stack variable */
24432 movq $0, 5*8(%rsp)
24433 jmp irq_return
24434 CFI_ENDPROC
24435-END(nmi)
24436+ENDPROC(nmi)
24437
24438 ENTRY(ignore_sysret)
24439 CFI_STARTPROC
24440 mov $-ENOSYS,%eax
24441 sysret
24442 CFI_ENDPROC
24443-END(ignore_sysret)
24444+ENDPROC(ignore_sysret)
24445
24446diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24447index 94d857f..bf1f0bf 100644
24448--- a/arch/x86/kernel/espfix_64.c
24449+++ b/arch/x86/kernel/espfix_64.c
24450@@ -197,7 +197,7 @@ void init_espfix_ap(void)
24451 set_pte(&pte_p[n*PTE_STRIDE], pte);
24452
24453 /* Job is done for this CPU and any CPU which shares this page */
24454- ACCESS_ONCE(espfix_pages[page]) = stack_page;
24455+ ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24456
24457 unlock_done:
24458 mutex_unlock(&espfix_init_mutex);
24459diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24460index cbc4a91..b38ee45 100644
24461--- a/arch/x86/kernel/ftrace.c
24462+++ b/arch/x86/kernel/ftrace.c
24463@@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24464 * kernel identity mapping to modify code.
24465 */
24466 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24467- ip = (unsigned long)__va(__pa_symbol(ip));
24468+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24469
24470 return ip;
24471 }
24472@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24473 {
24474 unsigned char replaced[MCOUNT_INSN_SIZE];
24475
24476+ ip = ktla_ktva(ip);
24477+
24478 /*
24479 * Note: Due to modules and __init, code can
24480 * disappear and change, we need to protect against faulting
24481@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24482 unsigned char old[MCOUNT_INSN_SIZE];
24483 int ret;
24484
24485- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24486+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24487
24488 ftrace_update_func = ip;
24489 /* Make sure the breakpoints see the ftrace_update_func update */
24490@@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24491 unsigned char replaced[MCOUNT_INSN_SIZE];
24492 unsigned char brk = BREAKPOINT_INSTRUCTION;
24493
24494- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24495+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24496 return -EFAULT;
24497
24498 /* Make sure it is what we expect it to be */
24499diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24500index eda1a86..8f6df48 100644
24501--- a/arch/x86/kernel/head64.c
24502+++ b/arch/x86/kernel/head64.c
24503@@ -67,12 +67,12 @@ again:
24504 pgd = *pgd_p;
24505
24506 /*
24507- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24508- * critical -- __PAGE_OFFSET would point us back into the dynamic
24509+ * The use of __early_va rather than __va here is critical:
24510+ * __va would point us back into the dynamic
24511 * range and we might end up looping forever...
24512 */
24513 if (pgd)
24514- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24515+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24516 else {
24517 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24518 reset_early_page_tables();
24519@@ -82,13 +82,13 @@ again:
24520 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24521 for (i = 0; i < PTRS_PER_PUD; i++)
24522 pud_p[i] = 0;
24523- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24524+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24525 }
24526 pud_p += pud_index(address);
24527 pud = *pud_p;
24528
24529 if (pud)
24530- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24531+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24532 else {
24533 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24534 reset_early_page_tables();
24535@@ -98,7 +98,7 @@ again:
24536 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24537 for (i = 0; i < PTRS_PER_PMD; i++)
24538 pmd_p[i] = 0;
24539- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24540+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24541 }
24542 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24543 pmd_p[pmd_index(address)] = pmd;
24544@@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24545 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24546 early_printk("Kernel alive\n");
24547
24548- clear_page(init_level4_pgt);
24549 /* set init_level4_pgt kernel high mapping*/
24550 init_level4_pgt[511] = early_level4_pgt[511];
24551
24552diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24553index f36bd42..0ab4474 100644
24554--- a/arch/x86/kernel/head_32.S
24555+++ b/arch/x86/kernel/head_32.S
24556@@ -26,6 +26,12 @@
24557 /* Physical address */
24558 #define pa(X) ((X) - __PAGE_OFFSET)
24559
24560+#ifdef CONFIG_PAX_KERNEXEC
24561+#define ta(X) (X)
24562+#else
24563+#define ta(X) ((X) - __PAGE_OFFSET)
24564+#endif
24565+
24566 /*
24567 * References to members of the new_cpu_data structure.
24568 */
24569@@ -55,11 +61,7 @@
24570 * and small than max_low_pfn, otherwise will waste some page table entries
24571 */
24572
24573-#if PTRS_PER_PMD > 1
24574-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24575-#else
24576-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24577-#endif
24578+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24579
24580 /* Number of possible pages in the lowmem region */
24581 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24582@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24583 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24584
24585 /*
24586+ * Real beginning of normal "text" segment
24587+ */
24588+ENTRY(stext)
24589+ENTRY(_stext)
24590+
24591+/*
24592 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24593 * %esi points to the real-mode code as a 32-bit pointer.
24594 * CS and DS must be 4 GB flat segments, but we don't depend on
24595@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24596 * can.
24597 */
24598 __HEAD
24599+
24600+#ifdef CONFIG_PAX_KERNEXEC
24601+ jmp startup_32
24602+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24603+.fill PAGE_SIZE-5,1,0xcc
24604+#endif
24605+
24606 ENTRY(startup_32)
24607 movl pa(stack_start),%ecx
24608
24609@@ -106,6 +121,59 @@ ENTRY(startup_32)
24610 2:
24611 leal -__PAGE_OFFSET(%ecx),%esp
24612
24613+#ifdef CONFIG_SMP
24614+ movl $pa(cpu_gdt_table),%edi
24615+ movl $__per_cpu_load,%eax
24616+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24617+ rorl $16,%eax
24618+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24619+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24620+ movl $__per_cpu_end - 1,%eax
24621+ subl $__per_cpu_start,%eax
24622+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24623+#endif
24624+
24625+#ifdef CONFIG_PAX_MEMORY_UDEREF
24626+ movl $NR_CPUS,%ecx
24627+ movl $pa(cpu_gdt_table),%edi
24628+1:
24629+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24630+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24631+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24632+ addl $PAGE_SIZE_asm,%edi
24633+ loop 1b
24634+#endif
24635+
24636+#ifdef CONFIG_PAX_KERNEXEC
24637+ movl $pa(boot_gdt),%edi
24638+ movl $__LOAD_PHYSICAL_ADDR,%eax
24639+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24640+ rorl $16,%eax
24641+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24642+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24643+ rorl $16,%eax
24644+
24645+ ljmp $(__BOOT_CS),$1f
24646+1:
24647+
24648+ movl $NR_CPUS,%ecx
24649+ movl $pa(cpu_gdt_table),%edi
24650+ addl $__PAGE_OFFSET,%eax
24651+1:
24652+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24653+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24654+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24655+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24656+ rorl $16,%eax
24657+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24658+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24659+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24660+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24661+ rorl $16,%eax
24662+ addl $PAGE_SIZE_asm,%edi
24663+ loop 1b
24664+#endif
24665+
24666 /*
24667 * Clear BSS first so that there are no surprises...
24668 */
24669@@ -201,8 +269,11 @@ ENTRY(startup_32)
24670 movl %eax, pa(max_pfn_mapped)
24671
24672 /* Do early initialization of the fixmap area */
24673- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24674- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24675+#ifdef CONFIG_COMPAT_VDSO
24676+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24677+#else
24678+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24679+#endif
24680 #else /* Not PAE */
24681
24682 page_pde_offset = (__PAGE_OFFSET >> 20);
24683@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24684 movl %eax, pa(max_pfn_mapped)
24685
24686 /* Do early initialization of the fixmap area */
24687- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24688- movl %eax,pa(initial_page_table+0xffc)
24689+#ifdef CONFIG_COMPAT_VDSO
24690+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24691+#else
24692+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24693+#endif
24694 #endif
24695
24696 #ifdef CONFIG_PARAVIRT
24697@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24698 cmpl $num_subarch_entries, %eax
24699 jae bad_subarch
24700
24701- movl pa(subarch_entries)(,%eax,4), %eax
24702- subl $__PAGE_OFFSET, %eax
24703- jmp *%eax
24704+ jmp *pa(subarch_entries)(,%eax,4)
24705
24706 bad_subarch:
24707 WEAK(lguest_entry)
24708@@ -261,10 +333,10 @@ WEAK(xen_entry)
24709 __INITDATA
24710
24711 subarch_entries:
24712- .long default_entry /* normal x86/PC */
24713- .long lguest_entry /* lguest hypervisor */
24714- .long xen_entry /* Xen hypervisor */
24715- .long default_entry /* Moorestown MID */
24716+ .long ta(default_entry) /* normal x86/PC */
24717+ .long ta(lguest_entry) /* lguest hypervisor */
24718+ .long ta(xen_entry) /* Xen hypervisor */
24719+ .long ta(default_entry) /* Moorestown MID */
24720 num_subarch_entries = (. - subarch_entries) / 4
24721 .previous
24722 #else
24723@@ -354,6 +426,7 @@ default_entry:
24724 movl pa(mmu_cr4_features),%eax
24725 movl %eax,%cr4
24726
24727+#ifdef CONFIG_X86_PAE
24728 testb $X86_CR4_PAE, %al # check if PAE is enabled
24729 jz enable_paging
24730
24731@@ -382,6 +455,9 @@ default_entry:
24732 /* Make changes effective */
24733 wrmsr
24734
24735+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24736+#endif
24737+
24738 enable_paging:
24739
24740 /*
24741@@ -449,14 +525,20 @@ is486:
24742 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24743 movl %eax,%ss # after changing gdt.
24744
24745- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24746+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24747 movl %eax,%ds
24748 movl %eax,%es
24749
24750 movl $(__KERNEL_PERCPU), %eax
24751 movl %eax,%fs # set this cpu's percpu
24752
24753+#ifdef CONFIG_CC_STACKPROTECTOR
24754 movl $(__KERNEL_STACK_CANARY),%eax
24755+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24756+ movl $(__USER_DS),%eax
24757+#else
24758+ xorl %eax,%eax
24759+#endif
24760 movl %eax,%gs
24761
24762 xorl %eax,%eax # Clear LDT
24763@@ -512,8 +594,11 @@ setup_once:
24764 * relocation. Manually set base address in stack canary
24765 * segment descriptor.
24766 */
24767- movl $gdt_page,%eax
24768+ movl $cpu_gdt_table,%eax
24769 movl $stack_canary,%ecx
24770+#ifdef CONFIG_SMP
24771+ addl $__per_cpu_load,%ecx
24772+#endif
24773 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24774 shrl $16, %ecx
24775 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24776@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24777 cmpl $2,(%esp) # X86_TRAP_NMI
24778 je is_nmi # Ignore NMI
24779
24780- cmpl $2,%ss:early_recursion_flag
24781+ cmpl $1,%ss:early_recursion_flag
24782 je hlt_loop
24783 incl %ss:early_recursion_flag
24784
24785@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24786 pushl (20+6*4)(%esp) /* trapno */
24787 pushl $fault_msg
24788 call printk
24789-#endif
24790 call dump_stack
24791+#endif
24792 hlt_loop:
24793 hlt
24794 jmp hlt_loop
24795@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24796 /* This is the default interrupt "handler" :-) */
24797 ALIGN
24798 ignore_int:
24799- cld
24800 #ifdef CONFIG_PRINTK
24801+ cmpl $2,%ss:early_recursion_flag
24802+ je hlt_loop
24803+ incl %ss:early_recursion_flag
24804+ cld
24805 pushl %eax
24806 pushl %ecx
24807 pushl %edx
24808@@ -617,9 +705,6 @@ ignore_int:
24809 movl $(__KERNEL_DS),%eax
24810 movl %eax,%ds
24811 movl %eax,%es
24812- cmpl $2,early_recursion_flag
24813- je hlt_loop
24814- incl early_recursion_flag
24815 pushl 16(%esp)
24816 pushl 24(%esp)
24817 pushl 32(%esp)
24818@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24819 /*
24820 * BSS section
24821 */
24822-__PAGE_ALIGNED_BSS
24823- .align PAGE_SIZE
24824 #ifdef CONFIG_X86_PAE
24825+.section .initial_pg_pmd,"a",@progbits
24826 initial_pg_pmd:
24827 .fill 1024*KPMDS,4,0
24828 #else
24829+.section .initial_page_table,"a",@progbits
24830 ENTRY(initial_page_table)
24831 .fill 1024,4,0
24832 #endif
24833+.section .initial_pg_fixmap,"a",@progbits
24834 initial_pg_fixmap:
24835 .fill 1024,4,0
24836+.section .empty_zero_page,"a",@progbits
24837 ENTRY(empty_zero_page)
24838 .fill 4096,1,0
24839+.section .swapper_pg_dir,"a",@progbits
24840 ENTRY(swapper_pg_dir)
24841+#ifdef CONFIG_X86_PAE
24842+ .fill 4,8,0
24843+#else
24844 .fill 1024,4,0
24845+#endif
24846
24847 /*
24848 * This starts the data section.
24849 */
24850 #ifdef CONFIG_X86_PAE
24851-__PAGE_ALIGNED_DATA
24852- /* Page-aligned for the benefit of paravirt? */
24853- .align PAGE_SIZE
24854+.section .initial_page_table,"a",@progbits
24855 ENTRY(initial_page_table)
24856 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24857 # if KPMDS == 3
24858@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24859 # error "Kernel PMDs should be 1, 2 or 3"
24860 # endif
24861 .align PAGE_SIZE /* needs to be page-sized too */
24862+
24863+#ifdef CONFIG_PAX_PER_CPU_PGD
24864+ENTRY(cpu_pgd)
24865+ .rept 2*NR_CPUS
24866+ .fill 4,8,0
24867+ .endr
24868+#endif
24869+
24870 #endif
24871
24872 .data
24873 .balign 4
24874 ENTRY(stack_start)
24875- .long init_thread_union+THREAD_SIZE
24876+ .long init_thread_union+THREAD_SIZE-8
24877
24878 __INITRODATA
24879 int_msg:
24880@@ -727,7 +825,7 @@ fault_msg:
24881 * segment size, and 32-bit linear address value:
24882 */
24883
24884- .data
24885+.section .rodata,"a",@progbits
24886 .globl boot_gdt_descr
24887 .globl idt_descr
24888
24889@@ -736,7 +834,7 @@ fault_msg:
24890 .word 0 # 32 bit align gdt_desc.address
24891 boot_gdt_descr:
24892 .word __BOOT_DS+7
24893- .long boot_gdt - __PAGE_OFFSET
24894+ .long pa(boot_gdt)
24895
24896 .word 0 # 32-bit align idt_desc.address
24897 idt_descr:
24898@@ -747,7 +845,7 @@ idt_descr:
24899 .word 0 # 32 bit align gdt_desc.address
24900 ENTRY(early_gdt_descr)
24901 .word GDT_ENTRIES*8-1
24902- .long gdt_page /* Overwritten for secondary CPUs */
24903+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24904
24905 /*
24906 * The boot_gdt must mirror the equivalent in setup.S and is
24907@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24908 .align L1_CACHE_BYTES
24909 ENTRY(boot_gdt)
24910 .fill GDT_ENTRY_BOOT_CS,8,0
24911- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24912- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24913+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24914+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24915+
24916+ .align PAGE_SIZE_asm
24917+ENTRY(cpu_gdt_table)
24918+ .rept NR_CPUS
24919+ .quad 0x0000000000000000 /* NULL descriptor */
24920+ .quad 0x0000000000000000 /* 0x0b reserved */
24921+ .quad 0x0000000000000000 /* 0x13 reserved */
24922+ .quad 0x0000000000000000 /* 0x1b reserved */
24923+
24924+#ifdef CONFIG_PAX_KERNEXEC
24925+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24926+#else
24927+ .quad 0x0000000000000000 /* 0x20 unused */
24928+#endif
24929+
24930+ .quad 0x0000000000000000 /* 0x28 unused */
24931+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24932+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24933+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24934+ .quad 0x0000000000000000 /* 0x4b reserved */
24935+ .quad 0x0000000000000000 /* 0x53 reserved */
24936+ .quad 0x0000000000000000 /* 0x5b reserved */
24937+
24938+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24939+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24940+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24941+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24942+
24943+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24944+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24945+
24946+ /*
24947+ * Segments used for calling PnP BIOS have byte granularity.
24948+ * The code segments and data segments have fixed 64k limits,
24949+ * the transfer segment sizes are set at run time.
24950+ */
24951+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24952+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24953+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24954+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24955+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24956+
24957+ /*
24958+ * The APM segments have byte granularity and their bases
24959+ * are set at run time. All have 64k limits.
24960+ */
24961+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24962+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24963+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24964+
24965+ .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24966+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24967+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24968+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24969+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24970+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24971+
24972+ /* Be sure this is zeroed to avoid false validations in Xen */
24973+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24974+ .endr
24975diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24976index a468c0a..c7dec74 100644
24977--- a/arch/x86/kernel/head_64.S
24978+++ b/arch/x86/kernel/head_64.S
24979@@ -20,6 +20,8 @@
24980 #include <asm/processor-flags.h>
24981 #include <asm/percpu.h>
24982 #include <asm/nops.h>
24983+#include <asm/cpufeature.h>
24984+#include <asm/alternative-asm.h>
24985
24986 #ifdef CONFIG_PARAVIRT
24987 #include <asm/asm-offsets.h>
24988@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24989 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24990 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24991 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24992+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24993+L3_VMALLOC_START = pud_index(VMALLOC_START)
24994+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24995+L3_VMALLOC_END = pud_index(VMALLOC_END)
24996+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24997+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24998
24999 .text
25000 __HEAD
25001@@ -89,11 +97,24 @@ startup_64:
25002 * Fixup the physical addresses in the page table
25003 */
25004 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
25005+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
25006+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
25007+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
25008+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
25009+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
25010
25011- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
25012- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
25013+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
25014+#ifndef CONFIG_XEN
25015+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
25016+#endif
25017+
25018+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
25019+
25020+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
25021+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
25022
25023 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
25024+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
25025
25026 /*
25027 * Set up the identity mapping for the switchover. These
25028@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
25029 movq $(init_level4_pgt - __START_KERNEL_map), %rax
25030 1:
25031
25032- /* Enable PAE mode and PGE */
25033- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
25034+ /* Enable PAE mode and PSE/PGE */
25035+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
25036 movq %rcx, %cr4
25037
25038 /* Setup early boot stage 4 level pagetables. */
25039@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
25040 movl $MSR_EFER, %ecx
25041 rdmsr
25042 btsl $_EFER_SCE, %eax /* Enable System Call */
25043- btl $20,%edi /* No Execute supported? */
25044+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
25045 jnc 1f
25046 btsl $_EFER_NX, %eax
25047 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
25048+#ifndef CONFIG_EFI
25049+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
25050+#endif
25051+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
25052+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
25053+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
25054+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
25055+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
25056+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
25057 1: wrmsr /* Make changes effective */
25058
25059 /* Setup cr0 */
25060@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
25061 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
25062 * address given in m16:64.
25063 */
25064+ pax_set_fptr_mask
25065 movq initial_code(%rip),%rax
25066 pushq $0 # fake return address to stop unwinder
25067 pushq $__KERNEL_CS # set correct cs
25068@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
25069 .quad INIT_PER_CPU_VAR(irq_stack_union)
25070
25071 GLOBAL(stack_start)
25072- .quad init_thread_union+THREAD_SIZE-8
25073+ .quad init_thread_union+THREAD_SIZE-16
25074 .word 0
25075 __FINITDATA
25076
25077@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
25078 call dump_stack
25079 #ifdef CONFIG_KALLSYMS
25080 leaq early_idt_ripmsg(%rip),%rdi
25081- movq 40(%rsp),%rsi # %rip again
25082+ movq 88(%rsp),%rsi # %rip again
25083 call __print_symbol
25084 #endif
25085 #endif /* EARLY_PRINTK */
25086@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
25087 early_recursion_flag:
25088 .long 0
25089
25090+ .section .rodata,"a",@progbits
25091 #ifdef CONFIG_EARLY_PRINTK
25092 early_idt_msg:
25093 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
25094@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
25095 NEXT_PAGE(early_dynamic_pgts)
25096 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25097
25098- .data
25099+ .section .rodata,"a",@progbits
25100
25101-#ifndef CONFIG_XEN
25102 NEXT_PAGE(init_level4_pgt)
25103- .fill 512,8,0
25104-#else
25105-NEXT_PAGE(init_level4_pgt)
25106- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25107 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25108 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25109+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
25110+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25111+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
25112+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25113+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25114+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25115 .org init_level4_pgt + L4_START_KERNEL*8, 0
25116 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25117 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25118
25119+#ifdef CONFIG_PAX_PER_CPU_PGD
25120+NEXT_PAGE(cpu_pgd)
25121+ .rept 2*NR_CPUS
25122+ .fill 512,8,0
25123+ .endr
25124+#endif
25125+
25126 NEXT_PAGE(level3_ident_pgt)
25127 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25128+#ifdef CONFIG_XEN
25129 .fill 511, 8, 0
25130+#else
25131+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25132+ .fill 510,8,0
25133+#endif
25134+
25135+NEXT_PAGE(level3_vmalloc_start_pgt)
25136+ .fill 512,8,0
25137+
25138+NEXT_PAGE(level3_vmalloc_end_pgt)
25139+ .fill 512,8,0
25140+
25141+NEXT_PAGE(level3_vmemmap_pgt)
25142+ .fill L3_VMEMMAP_START,8,0
25143+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25144+
25145 NEXT_PAGE(level2_ident_pgt)
25146- /* Since I easily can, map the first 1G.
25147+ /* Since I easily can, map the first 2G.
25148 * Don't set NX because code runs from these pages.
25149 */
25150- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25151-#endif
25152+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25153
25154 NEXT_PAGE(level3_kernel_pgt)
25155 .fill L3_START_KERNEL,8,0
25156@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
25157 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25158 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25159
25160+NEXT_PAGE(level2_vmemmap_pgt)
25161+ .fill 512,8,0
25162+
25163 NEXT_PAGE(level2_kernel_pgt)
25164 /*
25165 * 512 MB kernel mapping. We spend a full page on this pagetable
25166@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
25167 NEXT_PAGE(level2_fixmap_pgt)
25168 .fill 506,8,0
25169 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25170- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25171- .fill 5,8,0
25172+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25173+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25174+ .fill 4,8,0
25175
25176 NEXT_PAGE(level1_fixmap_pgt)
25177 .fill 512,8,0
25178
25179+NEXT_PAGE(level1_vsyscall_pgt)
25180+ .fill 512,8,0
25181+
25182 #undef PMDS
25183
25184- .data
25185+ .align PAGE_SIZE
25186+ENTRY(cpu_gdt_table)
25187+ .rept NR_CPUS
25188+ .quad 0x0000000000000000 /* NULL descriptor */
25189+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25190+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
25191+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
25192+ .quad 0x00cffb000000ffff /* __USER32_CS */
25193+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25194+ .quad 0x00affb000000ffff /* __USER_CS */
25195+
25196+#ifdef CONFIG_PAX_KERNEXEC
25197+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25198+#else
25199+ .quad 0x0 /* unused */
25200+#endif
25201+
25202+ .quad 0,0 /* TSS */
25203+ .quad 0,0 /* LDT */
25204+ .quad 0,0,0 /* three TLS descriptors */
25205+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
25206+ /* asm/segment.h:GDT_ENTRIES must match this */
25207+
25208+#ifdef CONFIG_PAX_MEMORY_UDEREF
25209+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25210+#else
25211+ .quad 0x0 /* unused */
25212+#endif
25213+
25214+ /* zero the remaining page */
25215+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25216+ .endr
25217+
25218 .align 16
25219 .globl early_gdt_descr
25220 early_gdt_descr:
25221 .word GDT_ENTRIES*8-1
25222 early_gdt_descr_base:
25223- .quad INIT_PER_CPU_VAR(gdt_page)
25224+ .quad cpu_gdt_table
25225
25226 ENTRY(phys_base)
25227 /* This must match the first entry in level2_kernel_pgt */
25228 .quad 0x0000000000000000
25229
25230 #include "../../x86/xen/xen-head.S"
25231-
25232- __PAGE_ALIGNED_BSS
25233+
25234+ .section .rodata,"a",@progbits
25235 NEXT_PAGE(empty_zero_page)
25236 .skip PAGE_SIZE
25237diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25238index 05fd74f..c3548b1 100644
25239--- a/arch/x86/kernel/i386_ksyms_32.c
25240+++ b/arch/x86/kernel/i386_ksyms_32.c
25241@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25242 EXPORT_SYMBOL(cmpxchg8b_emu);
25243 #endif
25244
25245+EXPORT_SYMBOL_GPL(cpu_gdt_table);
25246+
25247 /* Networking helper routines. */
25248 EXPORT_SYMBOL(csum_partial_copy_generic);
25249+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25250+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25251
25252 EXPORT_SYMBOL(__get_user_1);
25253 EXPORT_SYMBOL(__get_user_2);
25254@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25255 EXPORT_SYMBOL(___preempt_schedule_context);
25256 #endif
25257 #endif
25258+
25259+#ifdef CONFIG_PAX_KERNEXEC
25260+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25261+#endif
25262+
25263+#ifdef CONFIG_PAX_PER_CPU_PGD
25264+EXPORT_SYMBOL(cpu_pgd);
25265+#endif
25266diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25267index d5dd808..b6432cf 100644
25268--- a/arch/x86/kernel/i387.c
25269+++ b/arch/x86/kernel/i387.c
25270@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25271 static inline bool interrupted_user_mode(void)
25272 {
25273 struct pt_regs *regs = get_irq_regs();
25274- return regs && user_mode_vm(regs);
25275+ return regs && user_mode(regs);
25276 }
25277
25278 /*
25279diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25280index 8af8171..f8c1169 100644
25281--- a/arch/x86/kernel/i8259.c
25282+++ b/arch/x86/kernel/i8259.c
25283@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25284 static void make_8259A_irq(unsigned int irq)
25285 {
25286 disable_irq_nosync(irq);
25287- io_apic_irqs &= ~(1<<irq);
25288+ io_apic_irqs &= ~(1UL<<irq);
25289 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25290 i8259A_chip.name);
25291 enable_irq(irq);
25292@@ -209,7 +209,7 @@ spurious_8259A_irq:
25293 "spurious 8259A interrupt: IRQ%d.\n", irq);
25294 spurious_irq_mask |= irqmask;
25295 }
25296- atomic_inc(&irq_err_count);
25297+ atomic_inc_unchecked(&irq_err_count);
25298 /*
25299 * Theoretically we do not have to handle this IRQ,
25300 * but in Linux this does not cause problems and is
25301@@ -350,14 +350,16 @@ static void init_8259A(int auto_eoi)
25302 /* (slave's support for AEOI in flat mode is to be investigated) */
25303 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25304
25305+ pax_open_kernel();
25306 if (auto_eoi)
25307 /*
25308 * In AEOI mode we just have to mask the interrupt
25309 * when acking.
25310 */
25311- i8259A_chip.irq_mask_ack = disable_8259A_irq;
25312+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25313 else
25314- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25315+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25316+ pax_close_kernel();
25317
25318 udelay(100); /* wait for 8259A to initialize */
25319
25320diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25321index a979b5b..1d6db75 100644
25322--- a/arch/x86/kernel/io_delay.c
25323+++ b/arch/x86/kernel/io_delay.c
25324@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25325 * Quirk table for systems that misbehave (lock up, etc.) if port
25326 * 0x80 is used:
25327 */
25328-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25329+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25330 {
25331 .callback = dmi_io_delay_0xed_port,
25332 .ident = "Compaq Presario V6000",
25333diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25334index 4ddaf66..49d5c18 100644
25335--- a/arch/x86/kernel/ioport.c
25336+++ b/arch/x86/kernel/ioport.c
25337@@ -6,6 +6,7 @@
25338 #include <linux/sched.h>
25339 #include <linux/kernel.h>
25340 #include <linux/capability.h>
25341+#include <linux/security.h>
25342 #include <linux/errno.h>
25343 #include <linux/types.h>
25344 #include <linux/ioport.h>
25345@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25346 return -EINVAL;
25347 if (turn_on && !capable(CAP_SYS_RAWIO))
25348 return -EPERM;
25349+#ifdef CONFIG_GRKERNSEC_IO
25350+ if (turn_on && grsec_disable_privio) {
25351+ gr_handle_ioperm();
25352+ return -ENODEV;
25353+ }
25354+#endif
25355
25356 /*
25357 * If it's the first ioperm() call in this thread's lifetime, set the
25358@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25359 * because the ->io_bitmap_max value must match the bitmap
25360 * contents:
25361 */
25362- tss = &per_cpu(init_tss, get_cpu());
25363+ tss = init_tss + get_cpu();
25364
25365 if (turn_on)
25366 bitmap_clear(t->io_bitmap_ptr, from, num);
25367@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25368 if (level > old) {
25369 if (!capable(CAP_SYS_RAWIO))
25370 return -EPERM;
25371+#ifdef CONFIG_GRKERNSEC_IO
25372+ if (grsec_disable_privio) {
25373+ gr_handle_iopl();
25374+ return -ENODEV;
25375+ }
25376+#endif
25377 }
25378 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25379 t->iopl = level << 12;
25380diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25381index 922d285..6d20692 100644
25382--- a/arch/x86/kernel/irq.c
25383+++ b/arch/x86/kernel/irq.c
25384@@ -22,7 +22,7 @@
25385 #define CREATE_TRACE_POINTS
25386 #include <asm/trace/irq_vectors.h>
25387
25388-atomic_t irq_err_count;
25389+atomic_unchecked_t irq_err_count;
25390
25391 /* Function pointer for generic interrupt vector handling */
25392 void (*x86_platform_ipi_callback)(void) = NULL;
25393@@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25394 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25395 seq_printf(p, " Hypervisor callback interrupts\n");
25396 #endif
25397- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25398+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25399 #if defined(CONFIG_X86_IO_APIC)
25400- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25401+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25402 #endif
25403 return 0;
25404 }
25405@@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25406
25407 u64 arch_irq_stat(void)
25408 {
25409- u64 sum = atomic_read(&irq_err_count);
25410+ u64 sum = atomic_read_unchecked(&irq_err_count);
25411 return sum;
25412 }
25413
25414diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25415index 63ce838..2ea3e06 100644
25416--- a/arch/x86/kernel/irq_32.c
25417+++ b/arch/x86/kernel/irq_32.c
25418@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25419
25420 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25421
25422+extern void gr_handle_kernel_exploit(void);
25423+
25424 int sysctl_panic_on_stackoverflow __read_mostly;
25425
25426 /* Debugging check for stack overflow: is there less than 1KB free? */
25427@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25428 __asm__ __volatile__("andl %%esp,%0" :
25429 "=r" (sp) : "0" (THREAD_SIZE - 1));
25430
25431- return sp < (sizeof(struct thread_info) + STACK_WARN);
25432+ return sp < STACK_WARN;
25433 }
25434
25435 static void print_stack_overflow(void)
25436 {
25437 printk(KERN_WARNING "low stack detected by irq handler\n");
25438 dump_stack();
25439+ gr_handle_kernel_exploit();
25440 if (sysctl_panic_on_stackoverflow)
25441 panic("low stack detected by irq handler - check messages\n");
25442 }
25443@@ -84,10 +87,9 @@ static inline void *current_stack(void)
25444 static inline int
25445 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25446 {
25447- struct irq_stack *curstk, *irqstk;
25448+ struct irq_stack *irqstk;
25449 u32 *isp, *prev_esp, arg1, arg2;
25450
25451- curstk = (struct irq_stack *) current_stack();
25452 irqstk = __this_cpu_read(hardirq_stack);
25453
25454 /*
25455@@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25456 * handler) we can't do that and just have to keep using the
25457 * current stack (which is the irq stack already after all)
25458 */
25459- if (unlikely(curstk == irqstk))
25460+ if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25461 return 0;
25462
25463- isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25464+ isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25465
25466 /* Save the next esp at the bottom of the stack */
25467 prev_esp = (u32 *)irqstk;
25468 *prev_esp = current_stack_pointer;
25469
25470+#ifdef CONFIG_PAX_MEMORY_UDEREF
25471+ __set_fs(MAKE_MM_SEG(0));
25472+#endif
25473+
25474 if (unlikely(overflow))
25475 call_on_stack(print_stack_overflow, isp);
25476
25477@@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25478 : "0" (irq), "1" (desc), "2" (isp),
25479 "D" (desc->handle_irq)
25480 : "memory", "cc", "ecx");
25481+
25482+#ifdef CONFIG_PAX_MEMORY_UDEREF
25483+ __set_fs(current_thread_info()->addr_limit);
25484+#endif
25485+
25486 return 1;
25487 }
25488
25489@@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25490 */
25491 void irq_ctx_init(int cpu)
25492 {
25493- struct irq_stack *irqstk;
25494-
25495 if (per_cpu(hardirq_stack, cpu))
25496 return;
25497
25498- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25499- THREADINFO_GFP,
25500- THREAD_SIZE_ORDER));
25501- per_cpu(hardirq_stack, cpu) = irqstk;
25502-
25503- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25504- THREADINFO_GFP,
25505- THREAD_SIZE_ORDER));
25506- per_cpu(softirq_stack, cpu) = irqstk;
25507-
25508- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25509- cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25510+ per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25511+ per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25512 }
25513
25514 void do_softirq_own_stack(void)
25515 {
25516- struct thread_info *curstk;
25517 struct irq_stack *irqstk;
25518 u32 *isp, *prev_esp;
25519
25520- curstk = current_stack();
25521 irqstk = __this_cpu_read(softirq_stack);
25522
25523 /* build the stack frame on the softirq stack */
25524@@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25525 prev_esp = (u32 *)irqstk;
25526 *prev_esp = current_stack_pointer;
25527
25528+#ifdef CONFIG_PAX_MEMORY_UDEREF
25529+ __set_fs(MAKE_MM_SEG(0));
25530+#endif
25531+
25532 call_on_stack(__do_softirq, isp);
25533+
25534+#ifdef CONFIG_PAX_MEMORY_UDEREF
25535+ __set_fs(current_thread_info()->addr_limit);
25536+#endif
25537+
25538 }
25539
25540 bool handle_irq(unsigned irq, struct pt_regs *regs)
25541@@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25542 if (unlikely(!desc))
25543 return false;
25544
25545- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25546+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25547 if (unlikely(overflow))
25548 print_stack_overflow();
25549 desc->handle_irq(irq, desc);
25550diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25551index 4d1c746..55a22d6 100644
25552--- a/arch/x86/kernel/irq_64.c
25553+++ b/arch/x86/kernel/irq_64.c
25554@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25555 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25556 EXPORT_PER_CPU_SYMBOL(irq_regs);
25557
25558+extern void gr_handle_kernel_exploit(void);
25559+
25560 int sysctl_panic_on_stackoverflow;
25561
25562 /*
25563@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25564 u64 estack_top, estack_bottom;
25565 u64 curbase = (u64)task_stack_page(current);
25566
25567- if (user_mode_vm(regs))
25568+ if (user_mode(regs))
25569 return;
25570
25571 if (regs->sp >= curbase + sizeof(struct thread_info) +
25572@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25573 irq_stack_top, irq_stack_bottom,
25574 estack_top, estack_bottom);
25575
25576+ gr_handle_kernel_exploit();
25577+
25578 if (sysctl_panic_on_stackoverflow)
25579 panic("low stack detected by irq handler - check messages\n");
25580 #endif
25581diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25582index 26d5a55..a01160a 100644
25583--- a/arch/x86/kernel/jump_label.c
25584+++ b/arch/x86/kernel/jump_label.c
25585@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25586 * Jump label is enabled for the first time.
25587 * So we expect a default_nop...
25588 */
25589- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25590+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25591 != 0))
25592 bug_at((void *)entry->code, __LINE__);
25593 } else {
25594@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25595 * ...otherwise expect an ideal_nop. Otherwise
25596 * something went horribly wrong.
25597 */
25598- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25599+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25600 != 0))
25601 bug_at((void *)entry->code, __LINE__);
25602 }
25603@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25604 * are converting the default nop to the ideal nop.
25605 */
25606 if (init) {
25607- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25608+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25609 bug_at((void *)entry->code, __LINE__);
25610 } else {
25611 code.jump = 0xe9;
25612 code.offset = entry->target -
25613 (entry->code + JUMP_LABEL_NOP_SIZE);
25614- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25615+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25616 bug_at((void *)entry->code, __LINE__);
25617 }
25618 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25619diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25620index 7ec1d5f..5a7d130 100644
25621--- a/arch/x86/kernel/kgdb.c
25622+++ b/arch/x86/kernel/kgdb.c
25623@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25624 #ifdef CONFIG_X86_32
25625 switch (regno) {
25626 case GDB_SS:
25627- if (!user_mode_vm(regs))
25628+ if (!user_mode(regs))
25629 *(unsigned long *)mem = __KERNEL_DS;
25630 break;
25631 case GDB_SP:
25632- if (!user_mode_vm(regs))
25633+ if (!user_mode(regs))
25634 *(unsigned long *)mem = kernel_stack_pointer(regs);
25635 break;
25636 case GDB_GS:
25637@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25638 bp->attr.bp_addr = breakinfo[breakno].addr;
25639 bp->attr.bp_len = breakinfo[breakno].len;
25640 bp->attr.bp_type = breakinfo[breakno].type;
25641- info->address = breakinfo[breakno].addr;
25642+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25643+ info->address = ktla_ktva(breakinfo[breakno].addr);
25644+ else
25645+ info->address = breakinfo[breakno].addr;
25646 info->len = breakinfo[breakno].len;
25647 info->type = breakinfo[breakno].type;
25648 val = arch_install_hw_breakpoint(bp);
25649@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25650 case 'k':
25651 /* clear the trace bit */
25652 linux_regs->flags &= ~X86_EFLAGS_TF;
25653- atomic_set(&kgdb_cpu_doing_single_step, -1);
25654+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25655
25656 /* set the trace bit if we're stepping */
25657 if (remcomInBuffer[0] == 's') {
25658 linux_regs->flags |= X86_EFLAGS_TF;
25659- atomic_set(&kgdb_cpu_doing_single_step,
25660+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25661 raw_smp_processor_id());
25662 }
25663
25664@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25665
25666 switch (cmd) {
25667 case DIE_DEBUG:
25668- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25669+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25670 if (user_mode(regs))
25671 return single_step_cont(regs, args);
25672 break;
25673@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25674 #endif /* CONFIG_DEBUG_RODATA */
25675
25676 bpt->type = BP_BREAKPOINT;
25677- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25678+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25679 BREAK_INSTR_SIZE);
25680 if (err)
25681 return err;
25682- err = probe_kernel_write((char *)bpt->bpt_addr,
25683+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25684 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25685 #ifdef CONFIG_DEBUG_RODATA
25686 if (!err)
25687@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25688 return -EBUSY;
25689 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25690 BREAK_INSTR_SIZE);
25691- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25692+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25693 if (err)
25694 return err;
25695 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25696@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25697 if (mutex_is_locked(&text_mutex))
25698 goto knl_write;
25699 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25700- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25701+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25702 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25703 goto knl_write;
25704 return err;
25705 knl_write:
25706 #endif /* CONFIG_DEBUG_RODATA */
25707- return probe_kernel_write((char *)bpt->bpt_addr,
25708+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25709 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25710 }
25711
25712diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25713index 67e6d19..731ed28 100644
25714--- a/arch/x86/kernel/kprobes/core.c
25715+++ b/arch/x86/kernel/kprobes/core.c
25716@@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25717 s32 raddr;
25718 } __packed *insn;
25719
25720- insn = (struct __arch_relative_insn *)from;
25721+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25722+
25723+ pax_open_kernel();
25724 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25725 insn->op = op;
25726+ pax_close_kernel();
25727 }
25728
25729 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25730@@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25731 kprobe_opcode_t opcode;
25732 kprobe_opcode_t *orig_opcodes = opcodes;
25733
25734- if (search_exception_tables((unsigned long)opcodes))
25735+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25736 return 0; /* Page fault may occur on this address. */
25737
25738 retry:
25739@@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25740 * for the first byte, we can recover the original instruction
25741 * from it and kp->opcode.
25742 */
25743- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25744+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25745 buf[0] = kp->opcode;
25746- return (unsigned long)buf;
25747+ return ktva_ktla((unsigned long)buf);
25748 }
25749
25750 /*
25751@@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25752 /* Another subsystem puts a breakpoint, failed to recover */
25753 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25754 return 0;
25755+ pax_open_kernel();
25756 memcpy(dest, insn.kaddr, insn.length);
25757+ pax_close_kernel();
25758
25759 #ifdef CONFIG_X86_64
25760 if (insn_rip_relative(&insn)) {
25761@@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25762 return 0;
25763 }
25764 disp = (u8 *) dest + insn_offset_displacement(&insn);
25765+ pax_open_kernel();
25766 *(s32 *) disp = (s32) newdisp;
25767+ pax_close_kernel();
25768 }
25769 #endif
25770 return insn.length;
25771@@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25772 * nor set current_kprobe, because it doesn't use single
25773 * stepping.
25774 */
25775- regs->ip = (unsigned long)p->ainsn.insn;
25776+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25777 preempt_enable_no_resched();
25778 return;
25779 }
25780@@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25781 regs->flags &= ~X86_EFLAGS_IF;
25782 /* single step inline if the instruction is an int3 */
25783 if (p->opcode == BREAKPOINT_INSTRUCTION)
25784- regs->ip = (unsigned long)p->addr;
25785+ regs->ip = ktla_ktva((unsigned long)p->addr);
25786 else
25787- regs->ip = (unsigned long)p->ainsn.insn;
25788+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25789 }
25790 NOKPROBE_SYMBOL(setup_singlestep);
25791
25792@@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25793 struct kprobe *p;
25794 struct kprobe_ctlblk *kcb;
25795
25796- if (user_mode_vm(regs))
25797+ if (user_mode(regs))
25798 return 0;
25799
25800 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25801@@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25802 setup_singlestep(p, regs, kcb, 0);
25803 return 1;
25804 }
25805- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25806+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25807 /*
25808 * The breakpoint instruction was removed right
25809 * after we hit it. Another cpu has removed
25810@@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25811 " movq %rax, 152(%rsp)\n"
25812 RESTORE_REGS_STRING
25813 " popfq\n"
25814+#ifdef KERNEXEC_PLUGIN
25815+ " btsq $63,(%rsp)\n"
25816+#endif
25817 #else
25818 " pushf\n"
25819 SAVE_REGS_STRING
25820@@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25821 struct kprobe_ctlblk *kcb)
25822 {
25823 unsigned long *tos = stack_addr(regs);
25824- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25825+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25826 unsigned long orig_ip = (unsigned long)p->addr;
25827 kprobe_opcode_t *insn = p->ainsn.insn;
25828
25829@@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25830 struct die_args *args = data;
25831 int ret = NOTIFY_DONE;
25832
25833- if (args->regs && user_mode_vm(args->regs))
25834+ if (args->regs && user_mode(args->regs))
25835 return ret;
25836
25837 if (val == DIE_GPF) {
25838diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25839index f304773..551e63c 100644
25840--- a/arch/x86/kernel/kprobes/opt.c
25841+++ b/arch/x86/kernel/kprobes/opt.c
25842@@ -79,6 +79,7 @@ found:
25843 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25844 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25845 {
25846+ pax_open_kernel();
25847 #ifdef CONFIG_X86_64
25848 *addr++ = 0x48;
25849 *addr++ = 0xbf;
25850@@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25851 *addr++ = 0xb8;
25852 #endif
25853 *(unsigned long *)addr = val;
25854+ pax_close_kernel();
25855 }
25856
25857 asm (
25858@@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25859 * Verify if the address gap is in 2GB range, because this uses
25860 * a relative jump.
25861 */
25862- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25863+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25864 if (abs(rel) > 0x7fffffff)
25865 return -ERANGE;
25866
25867@@ -352,16 +354,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25868 op->optinsn.size = ret;
25869
25870 /* Copy arch-dep-instance from template */
25871- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25872+ pax_open_kernel();
25873+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25874+ pax_close_kernel();
25875
25876 /* Set probe information */
25877 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25878
25879 /* Set probe function call */
25880- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25881+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25882
25883 /* Set returning jmp instruction at the tail of out-of-line buffer */
25884- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25885+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25886 (u8 *)op->kp.addr + op->optinsn.size);
25887
25888 flush_icache_range((unsigned long) buf,
25889@@ -386,7 +390,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25890 WARN_ON(kprobe_disabled(&op->kp));
25891
25892 /* Backup instructions which will be replaced by jump address */
25893- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25894+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25895 RELATIVE_ADDR_SIZE);
25896
25897 insn_buf[0] = RELATIVEJUMP_OPCODE;
25898@@ -434,7 +438,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25899 /* This kprobe is really able to run optimized path. */
25900 op = container_of(p, struct optimized_kprobe, kp);
25901 /* Detour through copied instructions */
25902- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25903+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25904 if (!reenter)
25905 reset_current_kprobe();
25906 preempt_enable_no_resched();
25907diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25908index c2bedae..25e7ab60 100644
25909--- a/arch/x86/kernel/ksysfs.c
25910+++ b/arch/x86/kernel/ksysfs.c
25911@@ -184,7 +184,7 @@ out:
25912
25913 static struct kobj_attribute type_attr = __ATTR_RO(type);
25914
25915-static struct bin_attribute data_attr = {
25916+static bin_attribute_no_const data_attr __read_only = {
25917 .attr = {
25918 .name = "data",
25919 .mode = S_IRUGO,
25920diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25921index c37886d..d851d32 100644
25922--- a/arch/x86/kernel/ldt.c
25923+++ b/arch/x86/kernel/ldt.c
25924@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25925 if (reload) {
25926 #ifdef CONFIG_SMP
25927 preempt_disable();
25928- load_LDT(pc);
25929+ load_LDT_nolock(pc);
25930 if (!cpumask_equal(mm_cpumask(current->mm),
25931 cpumask_of(smp_processor_id())))
25932 smp_call_function(flush_ldt, current->mm, 1);
25933 preempt_enable();
25934 #else
25935- load_LDT(pc);
25936+ load_LDT_nolock(pc);
25937 #endif
25938 }
25939 if (oldsize) {
25940@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25941 return err;
25942
25943 for (i = 0; i < old->size; i++)
25944- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25945+ write_ldt_entry(new->ldt, i, old->ldt + i);
25946 return 0;
25947 }
25948
25949@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25950 retval = copy_ldt(&mm->context, &old_mm->context);
25951 mutex_unlock(&old_mm->context.lock);
25952 }
25953+
25954+ if (tsk == current) {
25955+ mm->context.vdso = 0;
25956+
25957+#ifdef CONFIG_X86_32
25958+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25959+ mm->context.user_cs_base = 0UL;
25960+ mm->context.user_cs_limit = ~0UL;
25961+
25962+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25963+ cpus_clear(mm->context.cpu_user_cs_mask);
25964+#endif
25965+
25966+#endif
25967+#endif
25968+
25969+ }
25970+
25971 return retval;
25972 }
25973
25974@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25975 }
25976 }
25977
25978+#ifdef CONFIG_PAX_SEGMEXEC
25979+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25980+ error = -EINVAL;
25981+ goto out_unlock;
25982+ }
25983+#endif
25984+
25985 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25986 error = -EINVAL;
25987 goto out_unlock;
25988diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25989index 1667b1d..16492c5 100644
25990--- a/arch/x86/kernel/machine_kexec_32.c
25991+++ b/arch/x86/kernel/machine_kexec_32.c
25992@@ -25,7 +25,7 @@
25993 #include <asm/cacheflush.h>
25994 #include <asm/debugreg.h>
25995
25996-static void set_idt(void *newidt, __u16 limit)
25997+static void set_idt(struct desc_struct *newidt, __u16 limit)
25998 {
25999 struct desc_ptr curidt;
26000
26001@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
26002 }
26003
26004
26005-static void set_gdt(void *newgdt, __u16 limit)
26006+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
26007 {
26008 struct desc_ptr curgdt;
26009
26010@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
26011 }
26012
26013 control_page = page_address(image->control_code_page);
26014- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
26015+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
26016
26017 relocate_kernel_ptr = control_page;
26018 page_list[PA_CONTROL_PAGE] = __pa(control_page);
26019diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
26020index c050a01..5774072 100644
26021--- a/arch/x86/kernel/mcount_64.S
26022+++ b/arch/x86/kernel/mcount_64.S
26023@@ -7,7 +7,7 @@
26024 #include <linux/linkage.h>
26025 #include <asm/ptrace.h>
26026 #include <asm/ftrace.h>
26027-
26028+#include <asm/alternative-asm.h>
26029
26030 .code64
26031 .section .entry.text, "ax"
26032@@ -24,8 +24,9 @@
26033 #ifdef CONFIG_DYNAMIC_FTRACE
26034
26035 ENTRY(function_hook)
26036+ pax_force_retaddr
26037 retq
26038-END(function_hook)
26039+ENDPROC(function_hook)
26040
26041 /* skip is set if stack has been adjusted */
26042 .macro ftrace_caller_setup skip=0
26043@@ -66,8 +67,9 @@ GLOBAL(ftrace_graph_call)
26044 #endif
26045
26046 GLOBAL(ftrace_stub)
26047+ pax_force_retaddr
26048 retq
26049-END(ftrace_caller)
26050+ENDPROC(ftrace_caller)
26051
26052 ENTRY(ftrace_regs_caller)
26053 /* Save the current flags before compare (in SS location)*/
26054@@ -135,7 +137,7 @@ ftrace_restore_flags:
26055 popfq
26056 jmp ftrace_stub
26057
26058-END(ftrace_regs_caller)
26059+ENDPROC(ftrace_regs_caller)
26060
26061
26062 #else /* ! CONFIG_DYNAMIC_FTRACE */
26063@@ -156,6 +158,7 @@ ENTRY(function_hook)
26064 #endif
26065
26066 GLOBAL(ftrace_stub)
26067+ pax_force_retaddr
26068 retq
26069
26070 trace:
26071@@ -169,12 +172,13 @@ trace:
26072 #endif
26073 subq $MCOUNT_INSN_SIZE, %rdi
26074
26075+ pax_force_fptr ftrace_trace_function
26076 call *ftrace_trace_function
26077
26078 MCOUNT_RESTORE_FRAME
26079
26080 jmp ftrace_stub
26081-END(function_hook)
26082+ENDPROC(function_hook)
26083 #endif /* CONFIG_DYNAMIC_FTRACE */
26084 #endif /* CONFIG_FUNCTION_TRACER */
26085
26086@@ -196,8 +200,9 @@ ENTRY(ftrace_graph_caller)
26087
26088 MCOUNT_RESTORE_FRAME
26089
26090+ pax_force_retaddr
26091 retq
26092-END(ftrace_graph_caller)
26093+ENDPROC(ftrace_graph_caller)
26094
26095 GLOBAL(return_to_handler)
26096 subq $24, %rsp
26097@@ -213,5 +218,7 @@ GLOBAL(return_to_handler)
26098 movq 8(%rsp), %rdx
26099 movq (%rsp), %rax
26100 addq $24, %rsp
26101+ pax_force_fptr %rdi
26102 jmp *%rdi
26103+ENDPROC(return_to_handler)
26104 #endif
26105diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
26106index e69f988..da078ea 100644
26107--- a/arch/x86/kernel/module.c
26108+++ b/arch/x86/kernel/module.c
26109@@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
26110 }
26111 #endif
26112
26113-void *module_alloc(unsigned long size)
26114+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
26115 {
26116- if (PAGE_ALIGN(size) > MODULES_LEN)
26117+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
26118 return NULL;
26119 return __vmalloc_node_range(size, 1,
26120 MODULES_VADDR + get_module_load_offset(),
26121- MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
26122- PAGE_KERNEL_EXEC, NUMA_NO_NODE,
26123+ MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
26124+ prot, NUMA_NO_NODE,
26125 __builtin_return_address(0));
26126 }
26127
26128+void *module_alloc(unsigned long size)
26129+{
26130+
26131+#ifdef CONFIG_PAX_KERNEXEC
26132+ return __module_alloc(size, PAGE_KERNEL);
26133+#else
26134+ return __module_alloc(size, PAGE_KERNEL_EXEC);
26135+#endif
26136+
26137+}
26138+
26139+#ifdef CONFIG_PAX_KERNEXEC
26140+#ifdef CONFIG_X86_32
26141+void *module_alloc_exec(unsigned long size)
26142+{
26143+ struct vm_struct *area;
26144+
26145+ if (size == 0)
26146+ return NULL;
26147+
26148+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26149+return area ? area->addr : NULL;
26150+}
26151+EXPORT_SYMBOL(module_alloc_exec);
26152+
26153+void module_free_exec(struct module *mod, void *module_region)
26154+{
26155+ vunmap(module_region);
26156+}
26157+EXPORT_SYMBOL(module_free_exec);
26158+#else
26159+void module_free_exec(struct module *mod, void *module_region)
26160+{
26161+ module_free(mod, module_region);
26162+}
26163+EXPORT_SYMBOL(module_free_exec);
26164+
26165+void *module_alloc_exec(unsigned long size)
26166+{
26167+ return __module_alloc(size, PAGE_KERNEL_RX);
26168+}
26169+EXPORT_SYMBOL(module_alloc_exec);
26170+#endif
26171+#endif
26172+
26173 #ifdef CONFIG_X86_32
26174 int apply_relocate(Elf32_Shdr *sechdrs,
26175 const char *strtab,
26176@@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26177 unsigned int i;
26178 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26179 Elf32_Sym *sym;
26180- uint32_t *location;
26181+ uint32_t *plocation, location;
26182
26183 DEBUGP("Applying relocate section %u to %u\n",
26184 relsec, sechdrs[relsec].sh_info);
26185 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26186 /* This is where to make the change */
26187- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26188- + rel[i].r_offset;
26189+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26190+ location = (uint32_t)plocation;
26191+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26192+ plocation = ktla_ktva((void *)plocation);
26193 /* This is the symbol it is referring to. Note that all
26194 undefined symbols have been resolved. */
26195 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26196@@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26197 switch (ELF32_R_TYPE(rel[i].r_info)) {
26198 case R_386_32:
26199 /* We add the value into the location given */
26200- *location += sym->st_value;
26201+ pax_open_kernel();
26202+ *plocation += sym->st_value;
26203+ pax_close_kernel();
26204 break;
26205 case R_386_PC32:
26206 /* Add the value, subtract its position */
26207- *location += sym->st_value - (uint32_t)location;
26208+ pax_open_kernel();
26209+ *plocation += sym->st_value - location;
26210+ pax_close_kernel();
26211 break;
26212 default:
26213 pr_err("%s: Unknown relocation: %u\n",
26214@@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26215 case R_X86_64_NONE:
26216 break;
26217 case R_X86_64_64:
26218+ pax_open_kernel();
26219 *(u64 *)loc = val;
26220+ pax_close_kernel();
26221 break;
26222 case R_X86_64_32:
26223+ pax_open_kernel();
26224 *(u32 *)loc = val;
26225+ pax_close_kernel();
26226 if (val != *(u32 *)loc)
26227 goto overflow;
26228 break;
26229 case R_X86_64_32S:
26230+ pax_open_kernel();
26231 *(s32 *)loc = val;
26232+ pax_close_kernel();
26233 if ((s64)val != *(s32 *)loc)
26234 goto overflow;
26235 break;
26236 case R_X86_64_PC32:
26237 val -= (u64)loc;
26238+ pax_open_kernel();
26239 *(u32 *)loc = val;
26240+ pax_close_kernel();
26241+
26242 #if 0
26243 if ((s64)val != *(s32 *)loc)
26244 goto overflow;
26245diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26246index c9603ac..9f88728 100644
26247--- a/arch/x86/kernel/msr.c
26248+++ b/arch/x86/kernel/msr.c
26249@@ -37,6 +37,7 @@
26250 #include <linux/notifier.h>
26251 #include <linux/uaccess.h>
26252 #include <linux/gfp.h>
26253+#include <linux/grsecurity.h>
26254
26255 #include <asm/processor.h>
26256 #include <asm/msr.h>
26257@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26258 int err = 0;
26259 ssize_t bytes = 0;
26260
26261+#ifdef CONFIG_GRKERNSEC_KMEM
26262+ gr_handle_msr_write();
26263+ return -EPERM;
26264+#endif
26265+
26266 if (count % 8)
26267 return -EINVAL; /* Invalid chunk size */
26268
26269@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26270 err = -EBADF;
26271 break;
26272 }
26273+#ifdef CONFIG_GRKERNSEC_KMEM
26274+ gr_handle_msr_write();
26275+ return -EPERM;
26276+#endif
26277 if (copy_from_user(&regs, uregs, sizeof regs)) {
26278 err = -EFAULT;
26279 break;
26280@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26281 return notifier_from_errno(err);
26282 }
26283
26284-static struct notifier_block __refdata msr_class_cpu_notifier = {
26285+static struct notifier_block msr_class_cpu_notifier = {
26286 .notifier_call = msr_class_cpu_callback,
26287 };
26288
26289diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26290index c3e985d..110a36a 100644
26291--- a/arch/x86/kernel/nmi.c
26292+++ b/arch/x86/kernel/nmi.c
26293@@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26294
26295 static void nmi_max_handler(struct irq_work *w)
26296 {
26297- struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26298+ struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26299 int remainder_ns, decimal_msecs;
26300- u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26301+ u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26302
26303 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26304 decimal_msecs = remainder_ns / 1000;
26305
26306 printk_ratelimited(KERN_INFO
26307 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26308- a->handler, whole_msecs, decimal_msecs);
26309+ n->action->handler, whole_msecs, decimal_msecs);
26310 }
26311
26312 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26313@@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26314 delta = sched_clock() - delta;
26315 trace_nmi_handler(a->handler, (int)delta, thishandled);
26316
26317- if (delta < nmi_longest_ns || delta < a->max_duration)
26318+ if (delta < nmi_longest_ns || delta < a->work->max_duration)
26319 continue;
26320
26321- a->max_duration = delta;
26322- irq_work_queue(&a->irq_work);
26323+ a->work->max_duration = delta;
26324+ irq_work_queue(&a->work->irq_work);
26325 }
26326
26327 rcu_read_unlock();
26328@@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26329 }
26330 NOKPROBE_SYMBOL(nmi_handle);
26331
26332-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26333+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26334 {
26335 struct nmi_desc *desc = nmi_to_desc(type);
26336 unsigned long flags;
26337@@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26338 if (!action->handler)
26339 return -EINVAL;
26340
26341- init_irq_work(&action->irq_work, nmi_max_handler);
26342+ action->work->action = action;
26343+ init_irq_work(&action->work->irq_work, nmi_max_handler);
26344
26345 spin_lock_irqsave(&desc->lock, flags);
26346
26347@@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26348 * event confuses some handlers (kdump uses this flag)
26349 */
26350 if (action->flags & NMI_FLAG_FIRST)
26351- list_add_rcu(&action->list, &desc->head);
26352+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26353 else
26354- list_add_tail_rcu(&action->list, &desc->head);
26355+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26356
26357 spin_unlock_irqrestore(&desc->lock, flags);
26358 return 0;
26359@@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26360 if (!strcmp(n->name, name)) {
26361 WARN(in_nmi(),
26362 "Trying to free NMI (%s) from NMI context!\n", n->name);
26363- list_del_rcu(&n->list);
26364+ pax_list_del_rcu((struct list_head *)&n->list);
26365 break;
26366 }
26367 }
26368@@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26369 dotraplinkage notrace void
26370 do_nmi(struct pt_regs *regs, long error_code)
26371 {
26372+
26373+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26374+ if (!user_mode(regs)) {
26375+ unsigned long cs = regs->cs & 0xFFFF;
26376+ unsigned long ip = ktva_ktla(regs->ip);
26377+
26378+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26379+ regs->ip = ip;
26380+ }
26381+#endif
26382+
26383 nmi_nesting_preprocess(regs);
26384
26385 nmi_enter();
26386diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26387index 6d9582e..f746287 100644
26388--- a/arch/x86/kernel/nmi_selftest.c
26389+++ b/arch/x86/kernel/nmi_selftest.c
26390@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26391 {
26392 /* trap all the unknown NMIs we may generate */
26393 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26394- __initdata);
26395+ __initconst);
26396 }
26397
26398 static void __init cleanup_nmi_testsuite(void)
26399@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26400 unsigned long timeout;
26401
26402 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26403- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26404+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26405 nmi_fail = FAILURE;
26406 return;
26407 }
26408diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26409index bbb6c73..24a58ef 100644
26410--- a/arch/x86/kernel/paravirt-spinlocks.c
26411+++ b/arch/x86/kernel/paravirt-spinlocks.c
26412@@ -8,7 +8,7 @@
26413
26414 #include <asm/paravirt.h>
26415
26416-struct pv_lock_ops pv_lock_ops = {
26417+struct pv_lock_ops pv_lock_ops __read_only = {
26418 #ifdef CONFIG_SMP
26419 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26420 .unlock_kick = paravirt_nop,
26421diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26422index 548d25f..f8fb99c 100644
26423--- a/arch/x86/kernel/paravirt.c
26424+++ b/arch/x86/kernel/paravirt.c
26425@@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26426 {
26427 return x;
26428 }
26429+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26430+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26431+#endif
26432
26433 void __init default_banner(void)
26434 {
26435@@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26436
26437 if (opfunc == NULL)
26438 /* If there's no function, patch it with a ud2a (BUG) */
26439- ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26440- else if (opfunc == _paravirt_nop)
26441+ ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26442+ else if (opfunc == (void *)_paravirt_nop)
26443 /* If the operation is a nop, then nop the callsite */
26444 ret = paravirt_patch_nop();
26445
26446 /* identity functions just return their single argument */
26447- else if (opfunc == _paravirt_ident_32)
26448+ else if (opfunc == (void *)_paravirt_ident_32)
26449 ret = paravirt_patch_ident_32(insnbuf, len);
26450- else if (opfunc == _paravirt_ident_64)
26451+ else if (opfunc == (void *)_paravirt_ident_64)
26452 ret = paravirt_patch_ident_64(insnbuf, len);
26453+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26454+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26455+ ret = paravirt_patch_ident_64(insnbuf, len);
26456+#endif
26457
26458 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26459 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26460@@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26461 if (insn_len > len || start == NULL)
26462 insn_len = len;
26463 else
26464- memcpy(insnbuf, start, insn_len);
26465+ memcpy(insnbuf, ktla_ktva(start), insn_len);
26466
26467 return insn_len;
26468 }
26469@@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26470 return this_cpu_read(paravirt_lazy_mode);
26471 }
26472
26473-struct pv_info pv_info = {
26474+struct pv_info pv_info __read_only = {
26475 .name = "bare hardware",
26476 .paravirt_enabled = 0,
26477 .kernel_rpl = 0,
26478@@ -311,16 +318,16 @@ struct pv_info pv_info = {
26479 #endif
26480 };
26481
26482-struct pv_init_ops pv_init_ops = {
26483+struct pv_init_ops pv_init_ops __read_only = {
26484 .patch = native_patch,
26485 };
26486
26487-struct pv_time_ops pv_time_ops = {
26488+struct pv_time_ops pv_time_ops __read_only = {
26489 .sched_clock = native_sched_clock,
26490 .steal_clock = native_steal_clock,
26491 };
26492
26493-__visible struct pv_irq_ops pv_irq_ops = {
26494+__visible struct pv_irq_ops pv_irq_ops __read_only = {
26495 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26496 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26497 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26498@@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26499 #endif
26500 };
26501
26502-__visible struct pv_cpu_ops pv_cpu_ops = {
26503+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26504 .cpuid = native_cpuid,
26505 .get_debugreg = native_get_debugreg,
26506 .set_debugreg = native_set_debugreg,
26507@@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26508 NOKPROBE_SYMBOL(native_set_debugreg);
26509 NOKPROBE_SYMBOL(native_load_idt);
26510
26511-struct pv_apic_ops pv_apic_ops = {
26512+struct pv_apic_ops pv_apic_ops __read_only= {
26513 #ifdef CONFIG_X86_LOCAL_APIC
26514 .startup_ipi_hook = paravirt_nop,
26515 #endif
26516 };
26517
26518-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26519+#ifdef CONFIG_X86_32
26520+#ifdef CONFIG_X86_PAE
26521+/* 64-bit pagetable entries */
26522+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26523+#else
26524 /* 32-bit pagetable entries */
26525 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26526+#endif
26527 #else
26528 /* 64-bit pagetable entries */
26529 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26530 #endif
26531
26532-struct pv_mmu_ops pv_mmu_ops = {
26533+struct pv_mmu_ops pv_mmu_ops __read_only = {
26534
26535 .read_cr2 = native_read_cr2,
26536 .write_cr2 = native_write_cr2,
26537@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26538 .make_pud = PTE_IDENT,
26539
26540 .set_pgd = native_set_pgd,
26541+ .set_pgd_batched = native_set_pgd_batched,
26542 #endif
26543 #endif /* PAGETABLE_LEVELS >= 3 */
26544
26545@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26546 },
26547
26548 .set_fixmap = native_set_fixmap,
26549+
26550+#ifdef CONFIG_PAX_KERNEXEC
26551+ .pax_open_kernel = native_pax_open_kernel,
26552+ .pax_close_kernel = native_pax_close_kernel,
26553+#endif
26554+
26555 };
26556
26557 EXPORT_SYMBOL_GPL(pv_time_ops);
26558diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26559index 0497f71..7186c0d 100644
26560--- a/arch/x86/kernel/pci-calgary_64.c
26561+++ b/arch/x86/kernel/pci-calgary_64.c
26562@@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26563 tce_space = be64_to_cpu(readq(target));
26564 tce_space = tce_space & TAR_SW_BITS;
26565
26566- tce_space = tce_space & (~specified_table_size);
26567+ tce_space = tce_space & (~(unsigned long)specified_table_size);
26568 info->tce_space = (u64 *)__va(tce_space);
26569 }
26570 }
26571diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26572index 35ccf75..7a15747 100644
26573--- a/arch/x86/kernel/pci-iommu_table.c
26574+++ b/arch/x86/kernel/pci-iommu_table.c
26575@@ -2,7 +2,7 @@
26576 #include <asm/iommu_table.h>
26577 #include <linux/string.h>
26578 #include <linux/kallsyms.h>
26579-
26580+#include <linux/sched.h>
26581
26582 #define DEBUG 1
26583
26584diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26585index 77dd0ad..9ec4723 100644
26586--- a/arch/x86/kernel/pci-swiotlb.c
26587+++ b/arch/x86/kernel/pci-swiotlb.c
26588@@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26589 struct dma_attrs *attrs)
26590 {
26591 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26592- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26593+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26594 else
26595 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26596 }
26597diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26598index ca7f0d5..8996469 100644
26599--- a/arch/x86/kernel/preempt.S
26600+++ b/arch/x86/kernel/preempt.S
26601@@ -3,12 +3,14 @@
26602 #include <asm/dwarf2.h>
26603 #include <asm/asm.h>
26604 #include <asm/calling.h>
26605+#include <asm/alternative-asm.h>
26606
26607 ENTRY(___preempt_schedule)
26608 CFI_STARTPROC
26609 SAVE_ALL
26610 call preempt_schedule
26611 RESTORE_ALL
26612+ pax_force_retaddr
26613 ret
26614 CFI_ENDPROC
26615
26616@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26617 SAVE_ALL
26618 call preempt_schedule_context
26619 RESTORE_ALL
26620+ pax_force_retaddr
26621 ret
26622 CFI_ENDPROC
26623
26624diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26625index 4505e2a..ae28b0d 100644
26626--- a/arch/x86/kernel/process.c
26627+++ b/arch/x86/kernel/process.c
26628@@ -36,7 +36,8 @@
26629 * section. Since TSS's are completely CPU-local, we want them
26630 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26631 */
26632-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26633+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26634+EXPORT_SYMBOL(init_tss);
26635
26636 #ifdef CONFIG_X86_64
26637 static DEFINE_PER_CPU(unsigned char, is_idle);
26638@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26639 task_xstate_cachep =
26640 kmem_cache_create("task_xstate", xstate_size,
26641 __alignof__(union thread_xstate),
26642- SLAB_PANIC | SLAB_NOTRACK, NULL);
26643+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26644 }
26645
26646 /*
26647@@ -105,7 +106,7 @@ void exit_thread(void)
26648 unsigned long *bp = t->io_bitmap_ptr;
26649
26650 if (bp) {
26651- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26652+ struct tss_struct *tss = init_tss + get_cpu();
26653
26654 t->io_bitmap_ptr = NULL;
26655 clear_thread_flag(TIF_IO_BITMAP);
26656@@ -125,6 +126,9 @@ void flush_thread(void)
26657 {
26658 struct task_struct *tsk = current;
26659
26660+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26661+ loadsegment(gs, 0);
26662+#endif
26663 flush_ptrace_hw_breakpoint(tsk);
26664 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26665 drop_init_fpu(tsk);
26666@@ -271,7 +275,7 @@ static void __exit_idle(void)
26667 void exit_idle(void)
26668 {
26669 /* idle loop has pid 0 */
26670- if (current->pid)
26671+ if (task_pid_nr(current))
26672 return;
26673 __exit_idle();
26674 }
26675@@ -324,7 +328,7 @@ bool xen_set_default_idle(void)
26676 return ret;
26677 }
26678 #endif
26679-void stop_this_cpu(void *dummy)
26680+__noreturn void stop_this_cpu(void *dummy)
26681 {
26682 local_irq_disable();
26683 /*
26684@@ -453,16 +457,37 @@ static int __init idle_setup(char *str)
26685 }
26686 early_param("idle", idle_setup);
26687
26688-unsigned long arch_align_stack(unsigned long sp)
26689+#ifdef CONFIG_PAX_RANDKSTACK
26690+void pax_randomize_kstack(struct pt_regs *regs)
26691 {
26692- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26693- sp -= get_random_int() % 8192;
26694- return sp & ~0xf;
26695-}
26696+ struct thread_struct *thread = &current->thread;
26697+ unsigned long time;
26698
26699-unsigned long arch_randomize_brk(struct mm_struct *mm)
26700-{
26701- unsigned long range_end = mm->brk + 0x02000000;
26702- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26703-}
26704+ if (!randomize_va_space)
26705+ return;
26706+
26707+ if (v8086_mode(regs))
26708+ return;
26709
26710+ rdtscl(time);
26711+
26712+ /* P4 seems to return a 0 LSB, ignore it */
26713+#ifdef CONFIG_MPENTIUM4
26714+ time &= 0x3EUL;
26715+ time <<= 2;
26716+#elif defined(CONFIG_X86_64)
26717+ time &= 0xFUL;
26718+ time <<= 4;
26719+#else
26720+ time &= 0x1FUL;
26721+ time <<= 3;
26722+#endif
26723+
26724+ thread->sp0 ^= time;
26725+ load_sp0(init_tss + smp_processor_id(), thread);
26726+
26727+#ifdef CONFIG_X86_64
26728+ this_cpu_write(kernel_stack, thread->sp0);
26729+#endif
26730+}
26731+#endif
26732diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26733index 7bc86bb..0ea06e8 100644
26734--- a/arch/x86/kernel/process_32.c
26735+++ b/arch/x86/kernel/process_32.c
26736@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26737 unsigned long thread_saved_pc(struct task_struct *tsk)
26738 {
26739 return ((unsigned long *)tsk->thread.sp)[3];
26740+//XXX return tsk->thread.eip;
26741 }
26742
26743 void __show_regs(struct pt_regs *regs, int all)
26744@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26745 unsigned long sp;
26746 unsigned short ss, gs;
26747
26748- if (user_mode_vm(regs)) {
26749+ if (user_mode(regs)) {
26750 sp = regs->sp;
26751 ss = regs->ss & 0xffff;
26752- gs = get_user_gs(regs);
26753 } else {
26754 sp = kernel_stack_pointer(regs);
26755 savesegment(ss, ss);
26756- savesegment(gs, gs);
26757 }
26758+ gs = get_user_gs(regs);
26759
26760 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26761 (u16)regs->cs, regs->ip, regs->flags,
26762- smp_processor_id());
26763+ raw_smp_processor_id());
26764 print_symbol("EIP is at %s\n", regs->ip);
26765
26766 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26767@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26768 int copy_thread(unsigned long clone_flags, unsigned long sp,
26769 unsigned long arg, struct task_struct *p)
26770 {
26771- struct pt_regs *childregs = task_pt_regs(p);
26772+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26773 struct task_struct *tsk;
26774 int err;
26775
26776 p->thread.sp = (unsigned long) childregs;
26777 p->thread.sp0 = (unsigned long) (childregs+1);
26778+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26779
26780 if (unlikely(p->flags & PF_KTHREAD)) {
26781 /* kernel thread */
26782 memset(childregs, 0, sizeof(struct pt_regs));
26783 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26784- task_user_gs(p) = __KERNEL_STACK_CANARY;
26785- childregs->ds = __USER_DS;
26786- childregs->es = __USER_DS;
26787+ savesegment(gs, childregs->gs);
26788+ childregs->ds = __KERNEL_DS;
26789+ childregs->es = __KERNEL_DS;
26790 childregs->fs = __KERNEL_PERCPU;
26791 childregs->bx = sp; /* function */
26792 childregs->bp = arg;
26793@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26794 struct thread_struct *prev = &prev_p->thread,
26795 *next = &next_p->thread;
26796 int cpu = smp_processor_id();
26797- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26798+ struct tss_struct *tss = init_tss + cpu;
26799 fpu_switch_t fpu;
26800
26801 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26802@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26803 */
26804 lazy_save_gs(prev->gs);
26805
26806+#ifdef CONFIG_PAX_MEMORY_UDEREF
26807+ __set_fs(task_thread_info(next_p)->addr_limit);
26808+#endif
26809+
26810 /*
26811 * Load the per-thread Thread-Local Storage descriptor.
26812 */
26813@@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26814 */
26815 arch_end_context_switch(next_p);
26816
26817- this_cpu_write(kernel_stack,
26818- (unsigned long)task_stack_page(next_p) +
26819- THREAD_SIZE - KERNEL_STACK_OFFSET);
26820+ this_cpu_write(current_task, next_p);
26821+ this_cpu_write(current_tinfo, &next_p->tinfo);
26822+ this_cpu_write(kernel_stack, next->sp0);
26823
26824 /*
26825 * Restore %gs if needed (which is common)
26826@@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26827
26828 switch_fpu_finish(next_p, fpu);
26829
26830- this_cpu_write(current_task, next_p);
26831-
26832 return prev_p;
26833 }
26834
26835@@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26836 } while (count++ < 16);
26837 return 0;
26838 }
26839-
26840diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26841index ca5b02d..c0b2f6a 100644
26842--- a/arch/x86/kernel/process_64.c
26843+++ b/arch/x86/kernel/process_64.c
26844@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26845 struct pt_regs *childregs;
26846 struct task_struct *me = current;
26847
26848- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26849+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26850 childregs = task_pt_regs(p);
26851 p->thread.sp = (unsigned long) childregs;
26852 p->thread.usersp = me->thread.usersp;
26853+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26854 set_tsk_thread_flag(p, TIF_FORK);
26855 p->thread.fpu_counter = 0;
26856 p->thread.io_bitmap_ptr = NULL;
26857@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26858 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26859 savesegment(es, p->thread.es);
26860 savesegment(ds, p->thread.ds);
26861+ savesegment(ss, p->thread.ss);
26862+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26863 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26864
26865 if (unlikely(p->flags & PF_KTHREAD)) {
26866@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26867 struct thread_struct *prev = &prev_p->thread;
26868 struct thread_struct *next = &next_p->thread;
26869 int cpu = smp_processor_id();
26870- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26871+ struct tss_struct *tss = init_tss + cpu;
26872 unsigned fsindex, gsindex;
26873 fpu_switch_t fpu;
26874
26875@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26876 if (unlikely(next->ds | prev->ds))
26877 loadsegment(ds, next->ds);
26878
26879+ savesegment(ss, prev->ss);
26880+ if (unlikely(next->ss != prev->ss))
26881+ loadsegment(ss, next->ss);
26882
26883 /* We must save %fs and %gs before load_TLS() because
26884 * %fs and %gs may be cleared by load_TLS().
26885@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26886 prev->usersp = this_cpu_read(old_rsp);
26887 this_cpu_write(old_rsp, next->usersp);
26888 this_cpu_write(current_task, next_p);
26889+ this_cpu_write(current_tinfo, &next_p->tinfo);
26890
26891 /*
26892 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26893@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26894 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26895 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26896
26897- this_cpu_write(kernel_stack,
26898- (unsigned long)task_stack_page(next_p) +
26899- THREAD_SIZE - KERNEL_STACK_OFFSET);
26900+ this_cpu_write(kernel_stack, next->sp0);
26901
26902 /*
26903 * Now maybe reload the debug registers and handle I/O bitmaps
26904@@ -443,12 +448,11 @@ unsigned long get_wchan(struct task_struct *p)
26905 if (!p || p == current || p->state == TASK_RUNNING)
26906 return 0;
26907 stack = (unsigned long)task_stack_page(p);
26908- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26909+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26910 return 0;
26911 fp = *(u64 *)(p->thread.sp);
26912 do {
26913- if (fp < (unsigned long)stack ||
26914- fp >= (unsigned long)stack+THREAD_SIZE)
26915+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26916 return 0;
26917 ip = *(u64 *)(fp+8);
26918 if (!in_sched_functions(ip))
26919diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26920index 678c0ad..2fc2a7b 100644
26921--- a/arch/x86/kernel/ptrace.c
26922+++ b/arch/x86/kernel/ptrace.c
26923@@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26924 unsigned long sp = (unsigned long)&regs->sp;
26925 u32 *prev_esp;
26926
26927- if (context == (sp & ~(THREAD_SIZE - 1)))
26928+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26929 return sp;
26930
26931- prev_esp = (u32 *)(context);
26932+ prev_esp = *(u32 **)(context);
26933 if (prev_esp)
26934 return (unsigned long)prev_esp;
26935
26936@@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26937 if (child->thread.gs != value)
26938 return do_arch_prctl(child, ARCH_SET_GS, value);
26939 return 0;
26940+
26941+ case offsetof(struct user_regs_struct,ip):
26942+ /*
26943+ * Protect against any attempt to set ip to an
26944+ * impossible address. There are dragons lurking if the
26945+ * address is noncanonical. (This explicitly allows
26946+ * setting ip to TASK_SIZE_MAX, because user code can do
26947+ * that all by itself by running off the end of its
26948+ * address space.
26949+ */
26950+ if (value > TASK_SIZE_MAX)
26951+ return -EIO;
26952+ break;
26953+
26954 #endif
26955 }
26956
26957@@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26958 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26959 {
26960 int i;
26961- int dr7 = 0;
26962+ unsigned long dr7 = 0;
26963 struct arch_hw_breakpoint *info;
26964
26965 for (i = 0; i < HBP_NUM; i++) {
26966@@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26967 unsigned long addr, unsigned long data)
26968 {
26969 int ret;
26970- unsigned long __user *datap = (unsigned long __user *)data;
26971+ unsigned long __user *datap = (__force unsigned long __user *)data;
26972
26973 switch (request) {
26974 /* read the word at location addr in the USER area. */
26975@@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26976 if ((int) addr < 0)
26977 return -EIO;
26978 ret = do_get_thread_area(child, addr,
26979- (struct user_desc __user *)data);
26980+ (__force struct user_desc __user *) data);
26981 break;
26982
26983 case PTRACE_SET_THREAD_AREA:
26984 if ((int) addr < 0)
26985 return -EIO;
26986 ret = do_set_thread_area(child, addr,
26987- (struct user_desc __user *)data, 0);
26988+ (__force struct user_desc __user *) data, 0);
26989 break;
26990 #endif
26991
26992@@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26993
26994 #ifdef CONFIG_X86_64
26995
26996-static struct user_regset x86_64_regsets[] __read_mostly = {
26997+static user_regset_no_const x86_64_regsets[] __read_only = {
26998 [REGSET_GENERAL] = {
26999 .core_note_type = NT_PRSTATUS,
27000 .n = sizeof(struct user_regs_struct) / sizeof(long),
27001@@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
27002 #endif /* CONFIG_X86_64 */
27003
27004 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
27005-static struct user_regset x86_32_regsets[] __read_mostly = {
27006+static user_regset_no_const x86_32_regsets[] __read_only = {
27007 [REGSET_GENERAL] = {
27008 .core_note_type = NT_PRSTATUS,
27009 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
27010@@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
27011 */
27012 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
27013
27014-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27015+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27016 {
27017 #ifdef CONFIG_X86_64
27018 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
27019@@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
27020 memset(info, 0, sizeof(*info));
27021 info->si_signo = SIGTRAP;
27022 info->si_code = si_code;
27023- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
27024+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
27025 }
27026
27027 void user_single_step_siginfo(struct task_struct *tsk,
27028@@ -1450,6 +1464,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
27029 # define IS_IA32 0
27030 #endif
27031
27032+#ifdef CONFIG_GRKERNSEC_SETXID
27033+extern void gr_delayed_cred_worker(void);
27034+#endif
27035+
27036 /*
27037 * We must return the syscall number to actually look up in the table.
27038 * This can be -1L to skip running any syscall at all.
27039@@ -1460,6 +1478,11 @@ long syscall_trace_enter(struct pt_regs *regs)
27040
27041 user_exit();
27042
27043+#ifdef CONFIG_GRKERNSEC_SETXID
27044+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27045+ gr_delayed_cred_worker();
27046+#endif
27047+
27048 /*
27049 * If we stepped into a sysenter/syscall insn, it trapped in
27050 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
27051@@ -1515,6 +1538,11 @@ void syscall_trace_leave(struct pt_regs *regs)
27052 */
27053 user_exit();
27054
27055+#ifdef CONFIG_GRKERNSEC_SETXID
27056+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27057+ gr_delayed_cred_worker();
27058+#endif
27059+
27060 audit_syscall_exit(regs);
27061
27062 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
27063diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
27064index 2f355d2..e75ed0a 100644
27065--- a/arch/x86/kernel/pvclock.c
27066+++ b/arch/x86/kernel/pvclock.c
27067@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
27068 reset_hung_task_detector();
27069 }
27070
27071-static atomic64_t last_value = ATOMIC64_INIT(0);
27072+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
27073
27074 void pvclock_resume(void)
27075 {
27076- atomic64_set(&last_value, 0);
27077+ atomic64_set_unchecked(&last_value, 0);
27078 }
27079
27080 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
27081@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
27082 * updating at the same time, and one of them could be slightly behind,
27083 * making the assumption that last_value always go forward fail to hold.
27084 */
27085- last = atomic64_read(&last_value);
27086+ last = atomic64_read_unchecked(&last_value);
27087 do {
27088 if (ret < last)
27089 return last;
27090- last = atomic64_cmpxchg(&last_value, last, ret);
27091+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
27092 } while (unlikely(last != ret));
27093
27094 return ret;
27095diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
27096index 52b1157..c6e67c4 100644
27097--- a/arch/x86/kernel/reboot.c
27098+++ b/arch/x86/kernel/reboot.c
27099@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
27100
27101 void __noreturn machine_real_restart(unsigned int type)
27102 {
27103+
27104+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
27105+ struct desc_struct *gdt;
27106+#endif
27107+
27108 local_irq_disable();
27109
27110 /*
27111@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
27112
27113 /* Jump to the identity-mapped low memory code */
27114 #ifdef CONFIG_X86_32
27115- asm volatile("jmpl *%0" : :
27116+
27117+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
27118+ gdt = get_cpu_gdt_table(smp_processor_id());
27119+ pax_open_kernel();
27120+#ifdef CONFIG_PAX_MEMORY_UDEREF
27121+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
27122+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
27123+ loadsegment(ds, __KERNEL_DS);
27124+ loadsegment(es, __KERNEL_DS);
27125+ loadsegment(ss, __KERNEL_DS);
27126+#endif
27127+#ifdef CONFIG_PAX_KERNEXEC
27128+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27129+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27130+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27131+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27132+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27133+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27134+#endif
27135+ pax_close_kernel();
27136+#endif
27137+
27138+ asm volatile("ljmpl *%0" : :
27139 "rm" (real_mode_header->machine_real_restart_asm),
27140 "a" (type));
27141 #else
27142@@ -486,7 +513,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27143 * This means that this function can never return, it can misbehave
27144 * by not rebooting properly and hanging.
27145 */
27146-static void native_machine_emergency_restart(void)
27147+static void __noreturn native_machine_emergency_restart(void)
27148 {
27149 int i;
27150 int attempt = 0;
27151@@ -610,13 +637,13 @@ void native_machine_shutdown(void)
27152 #endif
27153 }
27154
27155-static void __machine_emergency_restart(int emergency)
27156+static void __noreturn __machine_emergency_restart(int emergency)
27157 {
27158 reboot_emergency = emergency;
27159 machine_ops.emergency_restart();
27160 }
27161
27162-static void native_machine_restart(char *__unused)
27163+static void __noreturn native_machine_restart(char *__unused)
27164 {
27165 pr_notice("machine restart\n");
27166
27167@@ -625,7 +652,7 @@ static void native_machine_restart(char *__unused)
27168 __machine_emergency_restart(0);
27169 }
27170
27171-static void native_machine_halt(void)
27172+static void __noreturn native_machine_halt(void)
27173 {
27174 /* Stop other cpus and apics */
27175 machine_shutdown();
27176@@ -635,7 +662,7 @@ static void native_machine_halt(void)
27177 stop_this_cpu(NULL);
27178 }
27179
27180-static void native_machine_power_off(void)
27181+static void __noreturn native_machine_power_off(void)
27182 {
27183 if (pm_power_off) {
27184 if (!reboot_force)
27185@@ -644,9 +671,10 @@ static void native_machine_power_off(void)
27186 }
27187 /* A fallback in case there is no PM info available */
27188 tboot_shutdown(TB_SHUTDOWN_HALT);
27189+ unreachable();
27190 }
27191
27192-struct machine_ops machine_ops = {
27193+struct machine_ops machine_ops __read_only = {
27194 .power_off = native_machine_power_off,
27195 .shutdown = native_machine_shutdown,
27196 .emergency_restart = native_machine_emergency_restart,
27197diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27198index c8e41e9..64049ef 100644
27199--- a/arch/x86/kernel/reboot_fixups_32.c
27200+++ b/arch/x86/kernel/reboot_fixups_32.c
27201@@ -57,7 +57,7 @@ struct device_fixup {
27202 unsigned int vendor;
27203 unsigned int device;
27204 void (*reboot_fixup)(struct pci_dev *);
27205-};
27206+} __do_const;
27207
27208 /*
27209 * PCI ids solely used for fixups_table go here
27210diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27211index 3fd2c69..a444264 100644
27212--- a/arch/x86/kernel/relocate_kernel_64.S
27213+++ b/arch/x86/kernel/relocate_kernel_64.S
27214@@ -96,8 +96,7 @@ relocate_kernel:
27215
27216 /* jump to identity mapped page */
27217 addq $(identity_mapped - relocate_kernel), %r8
27218- pushq %r8
27219- ret
27220+ jmp *%r8
27221
27222 identity_mapped:
27223 /* set return address to 0 if not preserving context */
27224diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27225index 78a0e62..5c2e510 100644
27226--- a/arch/x86/kernel/setup.c
27227+++ b/arch/x86/kernel/setup.c
27228@@ -110,6 +110,7 @@
27229 #include <asm/mce.h>
27230 #include <asm/alternative.h>
27231 #include <asm/prom.h>
27232+#include <asm/boot.h>
27233
27234 /*
27235 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27236@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27237 #endif
27238
27239
27240-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27241-__visible unsigned long mmu_cr4_features;
27242+#ifdef CONFIG_X86_64
27243+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27244+#elif defined(CONFIG_X86_PAE)
27245+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27246 #else
27247-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27248+__visible unsigned long mmu_cr4_features __read_only;
27249 #endif
27250
27251+void set_in_cr4(unsigned long mask)
27252+{
27253+ unsigned long cr4 = read_cr4();
27254+
27255+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27256+ return;
27257+
27258+ pax_open_kernel();
27259+ mmu_cr4_features |= mask;
27260+ pax_close_kernel();
27261+
27262+ if (trampoline_cr4_features)
27263+ *trampoline_cr4_features = mmu_cr4_features;
27264+ cr4 |= mask;
27265+ write_cr4(cr4);
27266+}
27267+EXPORT_SYMBOL(set_in_cr4);
27268+
27269+void clear_in_cr4(unsigned long mask)
27270+{
27271+ unsigned long cr4 = read_cr4();
27272+
27273+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27274+ return;
27275+
27276+ pax_open_kernel();
27277+ mmu_cr4_features &= ~mask;
27278+ pax_close_kernel();
27279+
27280+ if (trampoline_cr4_features)
27281+ *trampoline_cr4_features = mmu_cr4_features;
27282+ cr4 &= ~mask;
27283+ write_cr4(cr4);
27284+}
27285+EXPORT_SYMBOL(clear_in_cr4);
27286+
27287 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27288 int bootloader_type, bootloader_version;
27289
27290@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27291 * area (640->1Mb) as ram even though it is not.
27292 * take them out.
27293 */
27294- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27295+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27296
27297 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27298 }
27299@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27300 /* called before trim_bios_range() to spare extra sanitize */
27301 static void __init e820_add_kernel_range(void)
27302 {
27303- u64 start = __pa_symbol(_text);
27304+ u64 start = __pa_symbol(ktla_ktva(_text));
27305 u64 size = __pa_symbol(_end) - start;
27306
27307 /*
27308@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27309
27310 void __init setup_arch(char **cmdline_p)
27311 {
27312+#ifdef CONFIG_X86_32
27313+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27314+#else
27315 memblock_reserve(__pa_symbol(_text),
27316 (unsigned long)__bss_stop - (unsigned long)_text);
27317+#endif
27318
27319 early_reserve_initrd();
27320
27321@@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
27322
27323 if (!boot_params.hdr.root_flags)
27324 root_mountflags &= ~MS_RDONLY;
27325- init_mm.start_code = (unsigned long) _text;
27326- init_mm.end_code = (unsigned long) _etext;
27327+ init_mm.start_code = ktla_ktva((unsigned long) _text);
27328+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
27329 init_mm.end_data = (unsigned long) _edata;
27330 init_mm.brk = _brk_end;
27331
27332- code_resource.start = __pa_symbol(_text);
27333- code_resource.end = __pa_symbol(_etext)-1;
27334- data_resource.start = __pa_symbol(_etext);
27335+ code_resource.start = __pa_symbol(ktla_ktva(_text));
27336+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27337+ data_resource.start = __pa_symbol(_sdata);
27338 data_resource.end = __pa_symbol(_edata)-1;
27339 bss_resource.start = __pa_symbol(__bss_start);
27340 bss_resource.end = __pa_symbol(__bss_stop)-1;
27341diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27342index 5cdff03..80fa283 100644
27343--- a/arch/x86/kernel/setup_percpu.c
27344+++ b/arch/x86/kernel/setup_percpu.c
27345@@ -21,19 +21,17 @@
27346 #include <asm/cpu.h>
27347 #include <asm/stackprotector.h>
27348
27349-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27350+#ifdef CONFIG_SMP
27351+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27352 EXPORT_PER_CPU_SYMBOL(cpu_number);
27353+#endif
27354
27355-#ifdef CONFIG_X86_64
27356 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27357-#else
27358-#define BOOT_PERCPU_OFFSET 0
27359-#endif
27360
27361 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27362 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27363
27364-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27365+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27366 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27367 };
27368 EXPORT_SYMBOL(__per_cpu_offset);
27369@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27370 {
27371 #ifdef CONFIG_NEED_MULTIPLE_NODES
27372 pg_data_t *last = NULL;
27373- unsigned int cpu;
27374+ int cpu;
27375
27376 for_each_possible_cpu(cpu) {
27377 int node = early_cpu_to_node(cpu);
27378@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27379 {
27380 #ifdef CONFIG_X86_32
27381 struct desc_struct gdt;
27382+ unsigned long base = per_cpu_offset(cpu);
27383
27384- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27385- 0x2 | DESCTYPE_S, 0x8);
27386- gdt.s = 1;
27387+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27388+ 0x83 | DESCTYPE_S, 0xC);
27389 write_gdt_entry(get_cpu_gdt_table(cpu),
27390 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27391 #endif
27392@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27393 /* alrighty, percpu areas up and running */
27394 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27395 for_each_possible_cpu(cpu) {
27396+#ifdef CONFIG_CC_STACKPROTECTOR
27397+#ifdef CONFIG_X86_32
27398+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
27399+#endif
27400+#endif
27401 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27402 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27403 per_cpu(cpu_number, cpu) = cpu;
27404@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27405 */
27406 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27407 #endif
27408+#ifdef CONFIG_CC_STACKPROTECTOR
27409+#ifdef CONFIG_X86_32
27410+ if (!cpu)
27411+ per_cpu(stack_canary.canary, cpu) = canary;
27412+#endif
27413+#endif
27414 /*
27415 * Up to this point, the boot CPU has been using .init.data
27416 * area. Reload any changed state for the boot CPU.
27417diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27418index 2851d63..83bf567 100644
27419--- a/arch/x86/kernel/signal.c
27420+++ b/arch/x86/kernel/signal.c
27421@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27422 * Align the stack pointer according to the i386 ABI,
27423 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27424 */
27425- sp = ((sp + 4) & -16ul) - 4;
27426+ sp = ((sp - 12) & -16ul) - 4;
27427 #else /* !CONFIG_X86_32 */
27428 sp = round_down(sp, 16) - 8;
27429 #endif
27430@@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27431 }
27432
27433 if (current->mm->context.vdso)
27434- restorer = current->mm->context.vdso +
27435- selected_vdso32->sym___kernel_sigreturn;
27436+ restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27437 else
27438- restorer = &frame->retcode;
27439+ restorer = (void __user *)&frame->retcode;
27440 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27441 restorer = ksig->ka.sa.sa_restorer;
27442
27443@@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27444 * reasons and because gdb uses it as a signature to notice
27445 * signal handler stack frames.
27446 */
27447- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27448+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27449
27450 if (err)
27451 return -EFAULT;
27452@@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27453 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27454
27455 /* Set up to return from userspace. */
27456- restorer = current->mm->context.vdso +
27457- selected_vdso32->sym___kernel_rt_sigreturn;
27458+ if (current->mm->context.vdso)
27459+ restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27460+ else
27461+ restorer = (void __user *)&frame->retcode;
27462 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27463 restorer = ksig->ka.sa.sa_restorer;
27464 put_user_ex(restorer, &frame->pretcode);
27465@@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27466 * reasons and because gdb uses it as a signature to notice
27467 * signal handler stack frames.
27468 */
27469- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27470+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27471 } put_user_catch(err);
27472
27473 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27474@@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27475 {
27476 int usig = signr_convert(ksig->sig);
27477 sigset_t *set = sigmask_to_save();
27478- compat_sigset_t *cset = (compat_sigset_t *) set;
27479+ sigset_t sigcopy;
27480+ compat_sigset_t *cset;
27481+
27482+ sigcopy = *set;
27483+
27484+ cset = (compat_sigset_t *) &sigcopy;
27485
27486 /* Set up the stack frame */
27487 if (is_ia32_frame()) {
27488@@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27489 } else if (is_x32_frame()) {
27490 return x32_setup_rt_frame(ksig, cset, regs);
27491 } else {
27492- return __setup_rt_frame(ksig->sig, ksig, set, regs);
27493+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27494 }
27495 }
27496
27497diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27498index be8e1bd..a3d93fa 100644
27499--- a/arch/x86/kernel/smp.c
27500+++ b/arch/x86/kernel/smp.c
27501@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27502
27503 __setup("nonmi_ipi", nonmi_ipi_setup);
27504
27505-struct smp_ops smp_ops = {
27506+struct smp_ops smp_ops __read_only = {
27507 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27508 .smp_prepare_cpus = native_smp_prepare_cpus,
27509 .smp_cpus_done = native_smp_cpus_done,
27510diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27511index 5492798..a3bd4f2 100644
27512--- a/arch/x86/kernel/smpboot.c
27513+++ b/arch/x86/kernel/smpboot.c
27514@@ -230,14 +230,17 @@ static void notrace start_secondary(void *unused)
27515
27516 enable_start_cpu0 = 0;
27517
27518-#ifdef CONFIG_X86_32
27519+ /* otherwise gcc will move up smp_processor_id before the cpu_init */
27520+ barrier();
27521+
27522 /* switch away from the initial page table */
27523+#ifdef CONFIG_PAX_PER_CPU_PGD
27524+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27525+#else
27526 load_cr3(swapper_pg_dir);
27527+#endif
27528 __flush_tlb_all();
27529-#endif
27530
27531- /* otherwise gcc will move up smp_processor_id before the cpu_init */
27532- barrier();
27533 /*
27534 * Check TSC synchronization with the BP:
27535 */
27536@@ -764,8 +767,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27537 alternatives_enable_smp();
27538
27539 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27540- (THREAD_SIZE + task_stack_page(idle))) - 1);
27541+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27542 per_cpu(current_task, cpu) = idle;
27543+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27544
27545 #ifdef CONFIG_X86_32
27546 /* Stack for startup_32 can be just as for start_secondary onwards */
27547@@ -774,10 +778,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27548 clear_tsk_thread_flag(idle, TIF_FORK);
27549 initial_gs = per_cpu_offset(cpu);
27550 #endif
27551- per_cpu(kernel_stack, cpu) =
27552- (unsigned long)task_stack_page(idle) -
27553- KERNEL_STACK_OFFSET + THREAD_SIZE;
27554+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27555+ pax_open_kernel();
27556 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27557+ pax_close_kernel();
27558 initial_code = (unsigned long)start_secondary;
27559 stack_start = idle->thread.sp;
27560
27561@@ -923,6 +927,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27562 /* the FPU context is blank, nobody can own it */
27563 __cpu_disable_lazy_restore(cpu);
27564
27565+#ifdef CONFIG_PAX_PER_CPU_PGD
27566+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27567+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27568+ KERNEL_PGD_PTRS);
27569+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27570+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27571+ KERNEL_PGD_PTRS);
27572+#endif
27573+
27574 err = do_boot_cpu(apicid, cpu, tidle);
27575 if (err) {
27576 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27577diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27578index 9b4d51d..5d28b58 100644
27579--- a/arch/x86/kernel/step.c
27580+++ b/arch/x86/kernel/step.c
27581@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27582 struct desc_struct *desc;
27583 unsigned long base;
27584
27585- seg &= ~7UL;
27586+ seg >>= 3;
27587
27588 mutex_lock(&child->mm->context.lock);
27589- if (unlikely((seg >> 3) >= child->mm->context.size))
27590+ if (unlikely(seg >= child->mm->context.size))
27591 addr = -1L; /* bogus selector, access would fault */
27592 else {
27593 desc = child->mm->context.ldt + seg;
27594@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27595 addr += base;
27596 }
27597 mutex_unlock(&child->mm->context.lock);
27598- }
27599+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27600+ addr = ktla_ktva(addr);
27601
27602 return addr;
27603 }
27604@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27605 unsigned char opcode[15];
27606 unsigned long addr = convert_ip_to_linear(child, regs);
27607
27608+ if (addr == -EINVAL)
27609+ return 0;
27610+
27611 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27612 for (i = 0; i < copied; i++) {
27613 switch (opcode[i]) {
27614diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27615new file mode 100644
27616index 0000000..5877189
27617--- /dev/null
27618+++ b/arch/x86/kernel/sys_i386_32.c
27619@@ -0,0 +1,189 @@
27620+/*
27621+ * This file contains various random system calls that
27622+ * have a non-standard calling sequence on the Linux/i386
27623+ * platform.
27624+ */
27625+
27626+#include <linux/errno.h>
27627+#include <linux/sched.h>
27628+#include <linux/mm.h>
27629+#include <linux/fs.h>
27630+#include <linux/smp.h>
27631+#include <linux/sem.h>
27632+#include <linux/msg.h>
27633+#include <linux/shm.h>
27634+#include <linux/stat.h>
27635+#include <linux/syscalls.h>
27636+#include <linux/mman.h>
27637+#include <linux/file.h>
27638+#include <linux/utsname.h>
27639+#include <linux/ipc.h>
27640+#include <linux/elf.h>
27641+
27642+#include <linux/uaccess.h>
27643+#include <linux/unistd.h>
27644+
27645+#include <asm/syscalls.h>
27646+
27647+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27648+{
27649+ unsigned long pax_task_size = TASK_SIZE;
27650+
27651+#ifdef CONFIG_PAX_SEGMEXEC
27652+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27653+ pax_task_size = SEGMEXEC_TASK_SIZE;
27654+#endif
27655+
27656+ if (flags & MAP_FIXED)
27657+ if (len > pax_task_size || addr > pax_task_size - len)
27658+ return -EINVAL;
27659+
27660+ return 0;
27661+}
27662+
27663+/*
27664+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27665+ */
27666+static unsigned long get_align_mask(void)
27667+{
27668+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27669+ return 0;
27670+
27671+ if (!(current->flags & PF_RANDOMIZE))
27672+ return 0;
27673+
27674+ return va_align.mask;
27675+}
27676+
27677+unsigned long
27678+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27679+ unsigned long len, unsigned long pgoff, unsigned long flags)
27680+{
27681+ struct mm_struct *mm = current->mm;
27682+ struct vm_area_struct *vma;
27683+ unsigned long pax_task_size = TASK_SIZE;
27684+ struct vm_unmapped_area_info info;
27685+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27686+
27687+#ifdef CONFIG_PAX_SEGMEXEC
27688+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27689+ pax_task_size = SEGMEXEC_TASK_SIZE;
27690+#endif
27691+
27692+ pax_task_size -= PAGE_SIZE;
27693+
27694+ if (len > pax_task_size)
27695+ return -ENOMEM;
27696+
27697+ if (flags & MAP_FIXED)
27698+ return addr;
27699+
27700+#ifdef CONFIG_PAX_RANDMMAP
27701+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27702+#endif
27703+
27704+ if (addr) {
27705+ addr = PAGE_ALIGN(addr);
27706+ if (pax_task_size - len >= addr) {
27707+ vma = find_vma(mm, addr);
27708+ if (check_heap_stack_gap(vma, addr, len, offset))
27709+ return addr;
27710+ }
27711+ }
27712+
27713+ info.flags = 0;
27714+ info.length = len;
27715+ info.align_mask = filp ? get_align_mask() : 0;
27716+ info.align_offset = pgoff << PAGE_SHIFT;
27717+ info.threadstack_offset = offset;
27718+
27719+#ifdef CONFIG_PAX_PAGEEXEC
27720+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27721+ info.low_limit = 0x00110000UL;
27722+ info.high_limit = mm->start_code;
27723+
27724+#ifdef CONFIG_PAX_RANDMMAP
27725+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27726+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27727+#endif
27728+
27729+ if (info.low_limit < info.high_limit) {
27730+ addr = vm_unmapped_area(&info);
27731+ if (!IS_ERR_VALUE(addr))
27732+ return addr;
27733+ }
27734+ } else
27735+#endif
27736+
27737+ info.low_limit = mm->mmap_base;
27738+ info.high_limit = pax_task_size;
27739+
27740+ return vm_unmapped_area(&info);
27741+}
27742+
27743+unsigned long
27744+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27745+ const unsigned long len, const unsigned long pgoff,
27746+ const unsigned long flags)
27747+{
27748+ struct vm_area_struct *vma;
27749+ struct mm_struct *mm = current->mm;
27750+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27751+ struct vm_unmapped_area_info info;
27752+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27753+
27754+#ifdef CONFIG_PAX_SEGMEXEC
27755+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27756+ pax_task_size = SEGMEXEC_TASK_SIZE;
27757+#endif
27758+
27759+ pax_task_size -= PAGE_SIZE;
27760+
27761+ /* requested length too big for entire address space */
27762+ if (len > pax_task_size)
27763+ return -ENOMEM;
27764+
27765+ if (flags & MAP_FIXED)
27766+ return addr;
27767+
27768+#ifdef CONFIG_PAX_PAGEEXEC
27769+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27770+ goto bottomup;
27771+#endif
27772+
27773+#ifdef CONFIG_PAX_RANDMMAP
27774+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27775+#endif
27776+
27777+ /* requesting a specific address */
27778+ if (addr) {
27779+ addr = PAGE_ALIGN(addr);
27780+ if (pax_task_size - len >= addr) {
27781+ vma = find_vma(mm, addr);
27782+ if (check_heap_stack_gap(vma, addr, len, offset))
27783+ return addr;
27784+ }
27785+ }
27786+
27787+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27788+ info.length = len;
27789+ info.low_limit = PAGE_SIZE;
27790+ info.high_limit = mm->mmap_base;
27791+ info.align_mask = filp ? get_align_mask() : 0;
27792+ info.align_offset = pgoff << PAGE_SHIFT;
27793+ info.threadstack_offset = offset;
27794+
27795+ addr = vm_unmapped_area(&info);
27796+ if (!(addr & ~PAGE_MASK))
27797+ return addr;
27798+ VM_BUG_ON(addr != -ENOMEM);
27799+
27800+bottomup:
27801+ /*
27802+ * A failed mmap() very likely causes application failure,
27803+ * so fall back to the bottom-up function here. This scenario
27804+ * can happen with large stack limits and large mmap()
27805+ * allocations.
27806+ */
27807+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27808+}
27809diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27810index 30277e2..5664a29 100644
27811--- a/arch/x86/kernel/sys_x86_64.c
27812+++ b/arch/x86/kernel/sys_x86_64.c
27813@@ -81,8 +81,8 @@ out:
27814 return error;
27815 }
27816
27817-static void find_start_end(unsigned long flags, unsigned long *begin,
27818- unsigned long *end)
27819+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27820+ unsigned long *begin, unsigned long *end)
27821 {
27822 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27823 unsigned long new_begin;
27824@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27825 *begin = new_begin;
27826 }
27827 } else {
27828- *begin = current->mm->mmap_legacy_base;
27829+ *begin = mm->mmap_legacy_base;
27830 *end = TASK_SIZE;
27831 }
27832 }
27833@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27834 struct vm_area_struct *vma;
27835 struct vm_unmapped_area_info info;
27836 unsigned long begin, end;
27837+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27838
27839 if (flags & MAP_FIXED)
27840 return addr;
27841
27842- find_start_end(flags, &begin, &end);
27843+ find_start_end(mm, flags, &begin, &end);
27844
27845 if (len > end)
27846 return -ENOMEM;
27847
27848+#ifdef CONFIG_PAX_RANDMMAP
27849+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27850+#endif
27851+
27852 if (addr) {
27853 addr = PAGE_ALIGN(addr);
27854 vma = find_vma(mm, addr);
27855- if (end - len >= addr &&
27856- (!vma || addr + len <= vma->vm_start))
27857+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27858 return addr;
27859 }
27860
27861@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27862 info.high_limit = end;
27863 info.align_mask = filp ? get_align_mask() : 0;
27864 info.align_offset = pgoff << PAGE_SHIFT;
27865+ info.threadstack_offset = offset;
27866 return vm_unmapped_area(&info);
27867 }
27868
27869@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27870 struct mm_struct *mm = current->mm;
27871 unsigned long addr = addr0;
27872 struct vm_unmapped_area_info info;
27873+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27874
27875 /* requested length too big for entire address space */
27876 if (len > TASK_SIZE)
27877@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27878 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27879 goto bottomup;
27880
27881+#ifdef CONFIG_PAX_RANDMMAP
27882+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27883+#endif
27884+
27885 /* requesting a specific address */
27886 if (addr) {
27887 addr = PAGE_ALIGN(addr);
27888 vma = find_vma(mm, addr);
27889- if (TASK_SIZE - len >= addr &&
27890- (!vma || addr + len <= vma->vm_start))
27891+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27892 return addr;
27893 }
27894
27895@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27896 info.high_limit = mm->mmap_base;
27897 info.align_mask = filp ? get_align_mask() : 0;
27898 info.align_offset = pgoff << PAGE_SHIFT;
27899+ info.threadstack_offset = offset;
27900 addr = vm_unmapped_area(&info);
27901 if (!(addr & ~PAGE_MASK))
27902 return addr;
27903diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27904index 91a4496..bb87552 100644
27905--- a/arch/x86/kernel/tboot.c
27906+++ b/arch/x86/kernel/tboot.c
27907@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27908
27909 void tboot_shutdown(u32 shutdown_type)
27910 {
27911- void (*shutdown)(void);
27912+ void (* __noreturn shutdown)(void);
27913
27914 if (!tboot_enabled())
27915 return;
27916@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27917
27918 switch_to_tboot_pt();
27919
27920- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27921+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27922 shutdown();
27923
27924 /* should not reach here */
27925@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27926 return -ENODEV;
27927 }
27928
27929-static atomic_t ap_wfs_count;
27930+static atomic_unchecked_t ap_wfs_count;
27931
27932 static int tboot_wait_for_aps(int num_aps)
27933 {
27934@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27935 {
27936 switch (action) {
27937 case CPU_DYING:
27938- atomic_inc(&ap_wfs_count);
27939+ atomic_inc_unchecked(&ap_wfs_count);
27940 if (num_online_cpus() == 1)
27941- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27942+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27943 return NOTIFY_BAD;
27944 break;
27945 }
27946@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27947
27948 tboot_create_trampoline();
27949
27950- atomic_set(&ap_wfs_count, 0);
27951+ atomic_set_unchecked(&ap_wfs_count, 0);
27952 register_hotcpu_notifier(&tboot_cpu_notifier);
27953
27954 #ifdef CONFIG_DEBUG_FS
27955diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27956index bf7ef5c..59d0ac9 100644
27957--- a/arch/x86/kernel/time.c
27958+++ b/arch/x86/kernel/time.c
27959@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27960 {
27961 unsigned long pc = instruction_pointer(regs);
27962
27963- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27964+ if (!user_mode(regs) && in_lock_functions(pc)) {
27965 #ifdef CONFIG_FRAME_POINTER
27966- return *(unsigned long *)(regs->bp + sizeof(long));
27967+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27968 #else
27969 unsigned long *sp =
27970 (unsigned long *)kernel_stack_pointer(regs);
27971@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27972 * or above a saved flags. Eflags has bits 22-31 zero,
27973 * kernel addresses don't.
27974 */
27975+
27976+#ifdef CONFIG_PAX_KERNEXEC
27977+ return ktla_ktva(sp[0]);
27978+#else
27979 if (sp[0] >> 22)
27980 return sp[0];
27981 if (sp[1] >> 22)
27982 return sp[1];
27983 #endif
27984+
27985+#endif
27986 }
27987 return pc;
27988 }
27989diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27990index f7fec09..9991981 100644
27991--- a/arch/x86/kernel/tls.c
27992+++ b/arch/x86/kernel/tls.c
27993@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27994 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27995 return -EINVAL;
27996
27997+#ifdef CONFIG_PAX_SEGMEXEC
27998+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27999+ return -EINVAL;
28000+#endif
28001+
28002 set_tls_desc(p, idx, &info, 1);
28003
28004 return 0;
28005@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
28006
28007 if (kbuf)
28008 info = kbuf;
28009- else if (__copy_from_user(infobuf, ubuf, count))
28010+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
28011 return -EFAULT;
28012 else
28013 info = infobuf;
28014diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
28015index 1c113db..287b42e 100644
28016--- a/arch/x86/kernel/tracepoint.c
28017+++ b/arch/x86/kernel/tracepoint.c
28018@@ -9,11 +9,11 @@
28019 #include <linux/atomic.h>
28020
28021 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
28022-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28023+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28024 (unsigned long) trace_idt_table };
28025
28026 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28027-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
28028+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
28029
28030 static int trace_irq_vector_refcount;
28031 static DEFINE_MUTEX(irq_vector_mutex);
28032diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
28033index 0d0e922..0886373 100644
28034--- a/arch/x86/kernel/traps.c
28035+++ b/arch/x86/kernel/traps.c
28036@@ -67,7 +67,7 @@
28037 #include <asm/proto.h>
28038
28039 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28040-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
28041+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
28042 #else
28043 #include <asm/processor-flags.h>
28044 #include <asm/setup.h>
28045@@ -76,7 +76,7 @@ asmlinkage int system_call(void);
28046 #endif
28047
28048 /* Must be page-aligned because the real IDT is used in a fixmap. */
28049-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
28050+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
28051
28052 DECLARE_BITMAP(used_vectors, NR_VECTORS);
28053 EXPORT_SYMBOL_GPL(used_vectors);
28054@@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
28055 }
28056
28057 static nokprobe_inline int
28058-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28059+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
28060 struct pt_regs *regs, long error_code)
28061 {
28062 #ifdef CONFIG_X86_32
28063- if (regs->flags & X86_VM_MASK) {
28064+ if (v8086_mode(regs)) {
28065 /*
28066 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
28067 * On nmi (interrupt 2), do_trap should not be called.
28068@@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28069 return -1;
28070 }
28071 #endif
28072- if (!user_mode(regs)) {
28073+ if (!user_mode_novm(regs)) {
28074 if (!fixup_exception(regs)) {
28075 tsk->thread.error_code = error_code;
28076 tsk->thread.trap_nr = trapnr;
28077+
28078+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28079+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
28080+ str = "PAX: suspicious stack segment fault";
28081+#endif
28082+
28083 die(str, regs, error_code);
28084 }
28085+
28086+#ifdef CONFIG_PAX_REFCOUNT
28087+ if (trapnr == X86_TRAP_OF)
28088+ pax_report_refcount_overflow(regs);
28089+#endif
28090+
28091 return 0;
28092 }
28093
28094@@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
28095 }
28096
28097 static void
28098-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28099+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28100 long error_code, siginfo_t *info)
28101 {
28102 struct task_struct *tsk = current;
28103@@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28104 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28105 printk_ratelimit()) {
28106 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28107- tsk->comm, tsk->pid, str,
28108+ tsk->comm, task_pid_nr(tsk), str,
28109 regs->ip, regs->sp, error_code);
28110 print_vma_addr(" in ", regs->ip);
28111 pr_cont("\n");
28112@@ -266,6 +278,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28113 tsk->thread.error_code = error_code;
28114 tsk->thread.trap_nr = X86_TRAP_DF;
28115
28116+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28117+ if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28118+ die("grsec: kernel stack overflow detected", regs, error_code);
28119+#endif
28120+
28121 #ifdef CONFIG_DOUBLEFAULT
28122 df_debug(regs, error_code);
28123 #endif
28124@@ -288,7 +305,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28125 conditional_sti(regs);
28126
28127 #ifdef CONFIG_X86_32
28128- if (regs->flags & X86_VM_MASK) {
28129+ if (v8086_mode(regs)) {
28130 local_irq_enable();
28131 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28132 goto exit;
28133@@ -296,18 +313,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28134 #endif
28135
28136 tsk = current;
28137- if (!user_mode(regs)) {
28138+ if (!user_mode_novm(regs)) {
28139 if (fixup_exception(regs))
28140 goto exit;
28141
28142 tsk->thread.error_code = error_code;
28143 tsk->thread.trap_nr = X86_TRAP_GP;
28144 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28145- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28146+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28147+
28148+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28149+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28150+ die("PAX: suspicious general protection fault", regs, error_code);
28151+ else
28152+#endif
28153+
28154 die("general protection fault", regs, error_code);
28155+ }
28156 goto exit;
28157 }
28158
28159+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28160+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28161+ struct mm_struct *mm = tsk->mm;
28162+ unsigned long limit;
28163+
28164+ down_write(&mm->mmap_sem);
28165+ limit = mm->context.user_cs_limit;
28166+ if (limit < TASK_SIZE) {
28167+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28168+ up_write(&mm->mmap_sem);
28169+ return;
28170+ }
28171+ up_write(&mm->mmap_sem);
28172+ }
28173+#endif
28174+
28175 tsk->thread.error_code = error_code;
28176 tsk->thread.trap_nr = X86_TRAP_GP;
28177
28178@@ -481,7 +522,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28179 /* It's safe to allow irq's after DR6 has been saved */
28180 preempt_conditional_sti(regs);
28181
28182- if (regs->flags & X86_VM_MASK) {
28183+ if (v8086_mode(regs)) {
28184 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28185 X86_TRAP_DB);
28186 preempt_conditional_cli(regs);
28187@@ -496,7 +537,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28188 * We already checked v86 mode above, so we can check for kernel mode
28189 * by just checking the CPL of CS.
28190 */
28191- if ((dr6 & DR_STEP) && !user_mode(regs)) {
28192+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28193 tsk->thread.debugreg6 &= ~DR_STEP;
28194 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28195 regs->flags &= ~X86_EFLAGS_TF;
28196@@ -529,7 +570,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28197 return;
28198 conditional_sti(regs);
28199
28200- if (!user_mode_vm(regs))
28201+ if (!user_mode(regs))
28202 {
28203 if (!fixup_exception(regs)) {
28204 task->thread.error_code = error_code;
28205diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28206index ea03031..34a5cdda 100644
28207--- a/arch/x86/kernel/tsc.c
28208+++ b/arch/x86/kernel/tsc.c
28209@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28210 */
28211 smp_wmb();
28212
28213- ACCESS_ONCE(c2n->head) = data;
28214+ ACCESS_ONCE_RW(c2n->head) = data;
28215 }
28216
28217 /*
28218diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28219index 5d1cbfe..2a21feb 100644
28220--- a/arch/x86/kernel/uprobes.c
28221+++ b/arch/x86/kernel/uprobes.c
28222@@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28223 int ret = NOTIFY_DONE;
28224
28225 /* We are only interested in userspace traps */
28226- if (regs && !user_mode_vm(regs))
28227+ if (regs && !user_mode(regs))
28228 return NOTIFY_DONE;
28229
28230 switch (val) {
28231@@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28232
28233 if (nleft != rasize) {
28234 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28235- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28236+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28237
28238 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28239 }
28240diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28241index b9242ba..50c5edd 100644
28242--- a/arch/x86/kernel/verify_cpu.S
28243+++ b/arch/x86/kernel/verify_cpu.S
28244@@ -20,6 +20,7 @@
28245 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28246 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28247 * arch/x86/kernel/head_32.S: processor startup
28248+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28249 *
28250 * verify_cpu, returns the status of longmode and SSE in register %eax.
28251 * 0: Success 1: Failure
28252diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28253index e8edcf5..27f9344 100644
28254--- a/arch/x86/kernel/vm86_32.c
28255+++ b/arch/x86/kernel/vm86_32.c
28256@@ -44,6 +44,7 @@
28257 #include <linux/ptrace.h>
28258 #include <linux/audit.h>
28259 #include <linux/stddef.h>
28260+#include <linux/grsecurity.h>
28261
28262 #include <asm/uaccess.h>
28263 #include <asm/io.h>
28264@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28265 do_exit(SIGSEGV);
28266 }
28267
28268- tss = &per_cpu(init_tss, get_cpu());
28269+ tss = init_tss + get_cpu();
28270 current->thread.sp0 = current->thread.saved_sp0;
28271 current->thread.sysenter_cs = __KERNEL_CS;
28272 load_sp0(tss, &current->thread);
28273@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28274
28275 if (tsk->thread.saved_sp0)
28276 return -EPERM;
28277+
28278+#ifdef CONFIG_GRKERNSEC_VM86
28279+ if (!capable(CAP_SYS_RAWIO)) {
28280+ gr_handle_vm86();
28281+ return -EPERM;
28282+ }
28283+#endif
28284+
28285 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28286 offsetof(struct kernel_vm86_struct, vm86plus) -
28287 sizeof(info.regs));
28288@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28289 int tmp;
28290 struct vm86plus_struct __user *v86;
28291
28292+#ifdef CONFIG_GRKERNSEC_VM86
28293+ if (!capable(CAP_SYS_RAWIO)) {
28294+ gr_handle_vm86();
28295+ return -EPERM;
28296+ }
28297+#endif
28298+
28299 tsk = current;
28300 switch (cmd) {
28301 case VM86_REQUEST_IRQ:
28302@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28303 tsk->thread.saved_fs = info->regs32->fs;
28304 tsk->thread.saved_gs = get_user_gs(info->regs32);
28305
28306- tss = &per_cpu(init_tss, get_cpu());
28307+ tss = init_tss + get_cpu();
28308 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28309 if (cpu_has_sep)
28310 tsk->thread.sysenter_cs = 0;
28311@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28312 goto cannot_handle;
28313 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28314 goto cannot_handle;
28315- intr_ptr = (unsigned long __user *) (i << 2);
28316+ intr_ptr = (__force unsigned long __user *) (i << 2);
28317 if (get_user(segoffs, intr_ptr))
28318 goto cannot_handle;
28319 if ((segoffs >> 16) == BIOSSEG)
28320diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28321index 49edf2d..c0d1362 100644
28322--- a/arch/x86/kernel/vmlinux.lds.S
28323+++ b/arch/x86/kernel/vmlinux.lds.S
28324@@ -26,6 +26,13 @@
28325 #include <asm/page_types.h>
28326 #include <asm/cache.h>
28327 #include <asm/boot.h>
28328+#include <asm/segment.h>
28329+
28330+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28331+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28332+#else
28333+#define __KERNEL_TEXT_OFFSET 0
28334+#endif
28335
28336 #undef i386 /* in case the preprocessor is a 32bit one */
28337
28338@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28339
28340 PHDRS {
28341 text PT_LOAD FLAGS(5); /* R_E */
28342+#ifdef CONFIG_X86_32
28343+ module PT_LOAD FLAGS(5); /* R_E */
28344+#endif
28345+#ifdef CONFIG_XEN
28346+ rodata PT_LOAD FLAGS(5); /* R_E */
28347+#else
28348+ rodata PT_LOAD FLAGS(4); /* R__ */
28349+#endif
28350 data PT_LOAD FLAGS(6); /* RW_ */
28351-#ifdef CONFIG_X86_64
28352+ init.begin PT_LOAD FLAGS(6); /* RW_ */
28353 #ifdef CONFIG_SMP
28354 percpu PT_LOAD FLAGS(6); /* RW_ */
28355 #endif
28356+ text.init PT_LOAD FLAGS(5); /* R_E */
28357+ text.exit PT_LOAD FLAGS(5); /* R_E */
28358 init PT_LOAD FLAGS(7); /* RWE */
28359-#endif
28360 note PT_NOTE FLAGS(0); /* ___ */
28361 }
28362
28363 SECTIONS
28364 {
28365 #ifdef CONFIG_X86_32
28366- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28367- phys_startup_32 = startup_32 - LOAD_OFFSET;
28368+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28369 #else
28370- . = __START_KERNEL;
28371- phys_startup_64 = startup_64 - LOAD_OFFSET;
28372+ . = __START_KERNEL;
28373 #endif
28374
28375 /* Text and read-only data */
28376- .text : AT(ADDR(.text) - LOAD_OFFSET) {
28377- _text = .;
28378+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28379 /* bootstrapping code */
28380+#ifdef CONFIG_X86_32
28381+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28382+#else
28383+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28384+#endif
28385+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28386+ _text = .;
28387 HEAD_TEXT
28388 . = ALIGN(8);
28389 _stext = .;
28390@@ -104,13 +124,47 @@ SECTIONS
28391 IRQENTRY_TEXT
28392 *(.fixup)
28393 *(.gnu.warning)
28394- /* End of text section */
28395- _etext = .;
28396 } :text = 0x9090
28397
28398- NOTES :text :note
28399+ . += __KERNEL_TEXT_OFFSET;
28400
28401- EXCEPTION_TABLE(16) :text = 0x9090
28402+#ifdef CONFIG_X86_32
28403+ . = ALIGN(PAGE_SIZE);
28404+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28405+
28406+#ifdef CONFIG_PAX_KERNEXEC
28407+ MODULES_EXEC_VADDR = .;
28408+ BYTE(0)
28409+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28410+ . = ALIGN(HPAGE_SIZE) - 1;
28411+ MODULES_EXEC_END = .;
28412+#endif
28413+
28414+ } :module
28415+#endif
28416+
28417+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28418+ /* End of text section */
28419+ BYTE(0)
28420+ _etext = . - __KERNEL_TEXT_OFFSET;
28421+ }
28422+
28423+#ifdef CONFIG_X86_32
28424+ . = ALIGN(PAGE_SIZE);
28425+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28426+ . = ALIGN(PAGE_SIZE);
28427+ *(.empty_zero_page)
28428+ *(.initial_pg_fixmap)
28429+ *(.initial_pg_pmd)
28430+ *(.initial_page_table)
28431+ *(.swapper_pg_dir)
28432+ } :rodata
28433+#endif
28434+
28435+ . = ALIGN(PAGE_SIZE);
28436+ NOTES :rodata :note
28437+
28438+ EXCEPTION_TABLE(16) :rodata
28439
28440 #if defined(CONFIG_DEBUG_RODATA)
28441 /* .text should occupy whole number of pages */
28442@@ -122,16 +176,20 @@ SECTIONS
28443
28444 /* Data */
28445 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28446+
28447+#ifdef CONFIG_PAX_KERNEXEC
28448+ . = ALIGN(HPAGE_SIZE);
28449+#else
28450+ . = ALIGN(PAGE_SIZE);
28451+#endif
28452+
28453 /* Start of data section */
28454 _sdata = .;
28455
28456 /* init_task */
28457 INIT_TASK_DATA(THREAD_SIZE)
28458
28459-#ifdef CONFIG_X86_32
28460- /* 32 bit has nosave before _edata */
28461 NOSAVE_DATA
28462-#endif
28463
28464 PAGE_ALIGNED_DATA(PAGE_SIZE)
28465
28466@@ -174,12 +232,19 @@ SECTIONS
28467 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28468
28469 /* Init code and data - will be freed after init */
28470- . = ALIGN(PAGE_SIZE);
28471 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28472+ BYTE(0)
28473+
28474+#ifdef CONFIG_PAX_KERNEXEC
28475+ . = ALIGN(HPAGE_SIZE);
28476+#else
28477+ . = ALIGN(PAGE_SIZE);
28478+#endif
28479+
28480 __init_begin = .; /* paired with __init_end */
28481- }
28482+ } :init.begin
28483
28484-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28485+#ifdef CONFIG_SMP
28486 /*
28487 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28488 * output PHDR, so the next output section - .init.text - should
28489@@ -188,12 +253,27 @@ SECTIONS
28490 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28491 #endif
28492
28493- INIT_TEXT_SECTION(PAGE_SIZE)
28494-#ifdef CONFIG_X86_64
28495- :init
28496-#endif
28497+ . = ALIGN(PAGE_SIZE);
28498+ init_begin = .;
28499+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28500+ VMLINUX_SYMBOL(_sinittext) = .;
28501+ INIT_TEXT
28502+ VMLINUX_SYMBOL(_einittext) = .;
28503+ . = ALIGN(PAGE_SIZE);
28504+ } :text.init
28505
28506- INIT_DATA_SECTION(16)
28507+ /*
28508+ * .exit.text is discard at runtime, not link time, to deal with
28509+ * references from .altinstructions and .eh_frame
28510+ */
28511+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28512+ EXIT_TEXT
28513+ . = ALIGN(16);
28514+ } :text.exit
28515+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28516+
28517+ . = ALIGN(PAGE_SIZE);
28518+ INIT_DATA_SECTION(16) :init
28519
28520 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28521 __x86_cpu_dev_start = .;
28522@@ -264,19 +344,12 @@ SECTIONS
28523 }
28524
28525 . = ALIGN(8);
28526- /*
28527- * .exit.text is discard at runtime, not link time, to deal with
28528- * references from .altinstructions and .eh_frame
28529- */
28530- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28531- EXIT_TEXT
28532- }
28533
28534 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28535 EXIT_DATA
28536 }
28537
28538-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28539+#ifndef CONFIG_SMP
28540 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28541 #endif
28542
28543@@ -295,16 +368,10 @@ SECTIONS
28544 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28545 __smp_locks = .;
28546 *(.smp_locks)
28547- . = ALIGN(PAGE_SIZE);
28548 __smp_locks_end = .;
28549+ . = ALIGN(PAGE_SIZE);
28550 }
28551
28552-#ifdef CONFIG_X86_64
28553- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28554- NOSAVE_DATA
28555- }
28556-#endif
28557-
28558 /* BSS */
28559 . = ALIGN(PAGE_SIZE);
28560 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28561@@ -320,6 +387,7 @@ SECTIONS
28562 __brk_base = .;
28563 . += 64 * 1024; /* 64k alignment slop space */
28564 *(.brk_reservation) /* areas brk users have reserved */
28565+ . = ALIGN(HPAGE_SIZE);
28566 __brk_limit = .;
28567 }
28568
28569@@ -346,13 +414,12 @@ SECTIONS
28570 * for the boot processor.
28571 */
28572 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28573-INIT_PER_CPU(gdt_page);
28574 INIT_PER_CPU(irq_stack_union);
28575
28576 /*
28577 * Build-time check on the image size:
28578 */
28579-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28580+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28581 "kernel image bigger than KERNEL_IMAGE_SIZE");
28582
28583 #ifdef CONFIG_SMP
28584diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28585index ea5b570..960e4da 100644
28586--- a/arch/x86/kernel/vsyscall_64.c
28587+++ b/arch/x86/kernel/vsyscall_64.c
28588@@ -54,15 +54,13 @@
28589
28590 DEFINE_VVAR(int, vgetcpu_mode);
28591
28592-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28593+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28594
28595 static int __init vsyscall_setup(char *str)
28596 {
28597 if (str) {
28598 if (!strcmp("emulate", str))
28599 vsyscall_mode = EMULATE;
28600- else if (!strcmp("native", str))
28601- vsyscall_mode = NATIVE;
28602 else if (!strcmp("none", str))
28603 vsyscall_mode = NONE;
28604 else
28605@@ -279,8 +277,7 @@ do_ret:
28606 return true;
28607
28608 sigsegv:
28609- force_sig(SIGSEGV, current);
28610- return true;
28611+ do_group_exit(SIGKILL);
28612 }
28613
28614 /*
28615@@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28616 extern char __vsyscall_page;
28617 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28618
28619- __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28620- vsyscall_mode == NATIVE
28621- ? PAGE_KERNEL_VSYSCALL
28622- : PAGE_KERNEL_VVAR);
28623+ __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28624 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28625 (unsigned long)VSYSCALL_ADDR);
28626 }
28627diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28628index 04068192..4d75aa6 100644
28629--- a/arch/x86/kernel/x8664_ksyms_64.c
28630+++ b/arch/x86/kernel/x8664_ksyms_64.c
28631@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28632 EXPORT_SYMBOL(copy_user_generic_unrolled);
28633 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28634 EXPORT_SYMBOL(__copy_user_nocache);
28635-EXPORT_SYMBOL(_copy_from_user);
28636-EXPORT_SYMBOL(_copy_to_user);
28637
28638 EXPORT_SYMBOL(copy_page);
28639 EXPORT_SYMBOL(clear_page);
28640@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28641 EXPORT_SYMBOL(___preempt_schedule_context);
28642 #endif
28643 #endif
28644+
28645+#ifdef CONFIG_PAX_PER_CPU_PGD
28646+EXPORT_SYMBOL(cpu_pgd);
28647+#endif
28648diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28649index e48b674..a451dd9 100644
28650--- a/arch/x86/kernel/x86_init.c
28651+++ b/arch/x86/kernel/x86_init.c
28652@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28653 static void default_nmi_init(void) { };
28654 static int default_i8042_detect(void) { return 1; };
28655
28656-struct x86_platform_ops x86_platform = {
28657+struct x86_platform_ops x86_platform __read_only = {
28658 .calibrate_tsc = native_calibrate_tsc,
28659 .get_wallclock = mach_get_cmos_time,
28660 .set_wallclock = mach_set_rtc_mmss,
28661@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28662 EXPORT_SYMBOL_GPL(x86_platform);
28663
28664 #if defined(CONFIG_PCI_MSI)
28665-struct x86_msi_ops x86_msi = {
28666+struct x86_msi_ops x86_msi __read_only = {
28667 .setup_msi_irqs = native_setup_msi_irqs,
28668 .compose_msi_msg = native_compose_msi_msg,
28669 .teardown_msi_irq = native_teardown_msi_irq,
28670@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28671 }
28672 #endif
28673
28674-struct x86_io_apic_ops x86_io_apic_ops = {
28675+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28676 .init = native_io_apic_init_mappings,
28677 .read = native_io_apic_read,
28678 .write = native_io_apic_write,
28679diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28680index a4b451c..8dfe1ad 100644
28681--- a/arch/x86/kernel/xsave.c
28682+++ b/arch/x86/kernel/xsave.c
28683@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28684
28685 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28686 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28687- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28688+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28689
28690 if (!use_xsave())
28691 return err;
28692
28693- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28694+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28695
28696 /*
28697 * Read the xstate_bv which we copied (directly from the cpu or
28698 * from the state in task struct) to the user buffers.
28699 */
28700- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28701+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28702
28703 /*
28704 * For legacy compatible, we always set FP/SSE bits in the bit
28705@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28706 */
28707 xstate_bv |= XSTATE_FPSSE;
28708
28709- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28710+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28711
28712 return err;
28713 }
28714@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28715 {
28716 int err;
28717
28718+ buf = (struct xsave_struct __user *)____m(buf);
28719 if (use_xsave())
28720 err = xsave_user(buf);
28721 else if (use_fxsr())
28722@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28723 */
28724 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28725 {
28726+ buf = (void __user *)____m(buf);
28727 if (use_xsave()) {
28728 if ((unsigned long)buf % 64 || fx_only) {
28729 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28730diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28731index 38a0afe..94421a9 100644
28732--- a/arch/x86/kvm/cpuid.c
28733+++ b/arch/x86/kvm/cpuid.c
28734@@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28735 struct kvm_cpuid2 *cpuid,
28736 struct kvm_cpuid_entry2 __user *entries)
28737 {
28738- int r;
28739+ int r, i;
28740
28741 r = -E2BIG;
28742 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28743 goto out;
28744 r = -EFAULT;
28745- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28746- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28747+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28748 goto out;
28749+ for (i = 0; i < cpuid->nent; ++i) {
28750+ struct kvm_cpuid_entry2 cpuid_entry;
28751+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28752+ goto out;
28753+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28754+ }
28755 vcpu->arch.cpuid_nent = cpuid->nent;
28756 kvm_apic_set_version(vcpu);
28757 kvm_x86_ops->cpuid_update(vcpu);
28758@@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28759 struct kvm_cpuid2 *cpuid,
28760 struct kvm_cpuid_entry2 __user *entries)
28761 {
28762- int r;
28763+ int r, i;
28764
28765 r = -E2BIG;
28766 if (cpuid->nent < vcpu->arch.cpuid_nent)
28767 goto out;
28768 r = -EFAULT;
28769- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28770- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28771+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28772 goto out;
28773+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28774+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28775+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28776+ goto out;
28777+ }
28778 return 0;
28779
28780 out:
28781diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28782index 0069118..c28ec0a 100644
28783--- a/arch/x86/kvm/lapic.c
28784+++ b/arch/x86/kvm/lapic.c
28785@@ -55,7 +55,7 @@
28786 #define APIC_BUS_CYCLE_NS 1
28787
28788 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28789-#define apic_debug(fmt, arg...)
28790+#define apic_debug(fmt, arg...) do {} while (0)
28791
28792 #define APIC_LVT_NUM 6
28793 /* 14 is the version for Xeon and Pentium 8.4.8*/
28794diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28795index 4107765..d9eb358 100644
28796--- a/arch/x86/kvm/paging_tmpl.h
28797+++ b/arch/x86/kvm/paging_tmpl.h
28798@@ -331,7 +331,7 @@ retry_walk:
28799 if (unlikely(kvm_is_error_hva(host_addr)))
28800 goto error;
28801
28802- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28803+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28804 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28805 goto error;
28806 walker->ptep_user[walker->level - 1] = ptep_user;
28807diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28808index b5e994a..35b5866 100644
28809--- a/arch/x86/kvm/svm.c
28810+++ b/arch/x86/kvm/svm.c
28811@@ -3541,7 +3541,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28812 int cpu = raw_smp_processor_id();
28813
28814 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28815+
28816+ pax_open_kernel();
28817 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28818+ pax_close_kernel();
28819+
28820 load_TR_desc();
28821 }
28822
28823@@ -3942,6 +3946,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28824 #endif
28825 #endif
28826
28827+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28828+ __set_fs(current_thread_info()->addr_limit);
28829+#endif
28830+
28831 reload_tss(vcpu);
28832
28833 local_irq_disable();
28834diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28835index 801332e..eeff1cc 100644
28836--- a/arch/x86/kvm/vmx.c
28837+++ b/arch/x86/kvm/vmx.c
28838@@ -1339,12 +1339,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28839 #endif
28840 }
28841
28842-static void vmcs_clear_bits(unsigned long field, u32 mask)
28843+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28844 {
28845 vmcs_writel(field, vmcs_readl(field) & ~mask);
28846 }
28847
28848-static void vmcs_set_bits(unsigned long field, u32 mask)
28849+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28850 {
28851 vmcs_writel(field, vmcs_readl(field) | mask);
28852 }
28853@@ -1604,7 +1604,11 @@ static void reload_tss(void)
28854 struct desc_struct *descs;
28855
28856 descs = (void *)gdt->address;
28857+
28858+ pax_open_kernel();
28859 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28860+ pax_close_kernel();
28861+
28862 load_TR_desc();
28863 }
28864
28865@@ -1832,6 +1836,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28866 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28867 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28868
28869+#ifdef CONFIG_PAX_PER_CPU_PGD
28870+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28871+#endif
28872+
28873 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28874 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28875 vmx->loaded_vmcs->cpu = cpu;
28876@@ -2121,7 +2129,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28877 * reads and returns guest's timestamp counter "register"
28878 * guest_tsc = host_tsc + tsc_offset -- 21.3
28879 */
28880-static u64 guest_read_tsc(void)
28881+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28882 {
28883 u64 host_tsc, tsc_offset;
28884
28885@@ -3093,8 +3101,11 @@ static __init int hardware_setup(void)
28886 if (!cpu_has_vmx_flexpriority())
28887 flexpriority_enabled = 0;
28888
28889- if (!cpu_has_vmx_tpr_shadow())
28890- kvm_x86_ops->update_cr8_intercept = NULL;
28891+ if (!cpu_has_vmx_tpr_shadow()) {
28892+ pax_open_kernel();
28893+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28894+ pax_close_kernel();
28895+ }
28896
28897 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28898 kvm_disable_largepages();
28899@@ -3105,13 +3116,15 @@ static __init int hardware_setup(void)
28900 if (!cpu_has_vmx_apicv())
28901 enable_apicv = 0;
28902
28903+ pax_open_kernel();
28904 if (enable_apicv)
28905- kvm_x86_ops->update_cr8_intercept = NULL;
28906+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28907 else {
28908- kvm_x86_ops->hwapic_irr_update = NULL;
28909- kvm_x86_ops->deliver_posted_interrupt = NULL;
28910- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28911+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28912+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28913+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28914 }
28915+ pax_close_kernel();
28916
28917 if (nested)
28918 nested_vmx_setup_ctls_msrs();
28919@@ -4221,7 +4234,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28920
28921 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28922 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28923+
28924+#ifndef CONFIG_PAX_PER_CPU_PGD
28925 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28926+#endif
28927
28928 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28929 #ifdef CONFIG_X86_64
28930@@ -4243,7 +4259,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28931 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28932 vmx->host_idt_base = dt.address;
28933
28934- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28935+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28936
28937 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28938 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28939@@ -7413,6 +7429,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28940 "jmp 2f \n\t"
28941 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28942 "2: "
28943+
28944+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28945+ "ljmp %[cs],$3f\n\t"
28946+ "3: "
28947+#endif
28948+
28949 /* Save guest registers, load host registers, keep flags */
28950 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28951 "pop %0 \n\t"
28952@@ -7465,6 +7487,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28953 #endif
28954 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28955 [wordsize]"i"(sizeof(ulong))
28956+
28957+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28958+ ,[cs]"i"(__KERNEL_CS)
28959+#endif
28960+
28961 : "cc", "memory"
28962 #ifdef CONFIG_X86_64
28963 , "rax", "rbx", "rdi", "rsi"
28964@@ -7478,7 +7505,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28965 if (debugctlmsr)
28966 update_debugctlmsr(debugctlmsr);
28967
28968-#ifndef CONFIG_X86_64
28969+#ifdef CONFIG_X86_32
28970 /*
28971 * The sysexit path does not restore ds/es, so we must set them to
28972 * a reasonable value ourselves.
28973@@ -7487,8 +7514,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28974 * may be executed in interrupt context, which saves and restore segments
28975 * around it, nullifying its effect.
28976 */
28977- loadsegment(ds, __USER_DS);
28978- loadsegment(es, __USER_DS);
28979+ loadsegment(ds, __KERNEL_DS);
28980+ loadsegment(es, __KERNEL_DS);
28981+ loadsegment(ss, __KERNEL_DS);
28982+
28983+#ifdef CONFIG_PAX_KERNEXEC
28984+ loadsegment(fs, __KERNEL_PERCPU);
28985+#endif
28986+
28987+#ifdef CONFIG_PAX_MEMORY_UDEREF
28988+ __set_fs(current_thread_info()->addr_limit);
28989+#endif
28990+
28991 #endif
28992
28993 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28994diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28995index ef432f8..a630659 100644
28996--- a/arch/x86/kvm/x86.c
28997+++ b/arch/x86/kvm/x86.c
28998@@ -1808,8 +1808,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28999 {
29000 struct kvm *kvm = vcpu->kvm;
29001 int lm = is_long_mode(vcpu);
29002- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29003- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29004+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29005+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29006 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
29007 : kvm->arch.xen_hvm_config.blob_size_32;
29008 u32 page_num = data & ~PAGE_MASK;
29009@@ -2729,6 +2729,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
29010 if (n < msr_list.nmsrs)
29011 goto out;
29012 r = -EFAULT;
29013+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
29014+ goto out;
29015 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
29016 num_msrs_to_save * sizeof(u32)))
29017 goto out;
29018@@ -5567,7 +5569,7 @@ static struct notifier_block pvclock_gtod_notifier = {
29019 };
29020 #endif
29021
29022-int kvm_arch_init(void *opaque)
29023+int kvm_arch_init(const void *opaque)
29024 {
29025 int r;
29026 struct kvm_x86_ops *ops = opaque;
29027diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
29028index aae9413..d11e829 100644
29029--- a/arch/x86/lguest/boot.c
29030+++ b/arch/x86/lguest/boot.c
29031@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
29032 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
29033 * Launcher to reboot us.
29034 */
29035-static void lguest_restart(char *reason)
29036+static __noreturn void lguest_restart(char *reason)
29037 {
29038 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
29039+ BUG();
29040 }
29041
29042 /*G:050
29043diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29044index 00933d5..3a64af9 100644
29045--- a/arch/x86/lib/atomic64_386_32.S
29046+++ b/arch/x86/lib/atomic64_386_32.S
29047@@ -48,6 +48,10 @@ BEGIN(read)
29048 movl (v), %eax
29049 movl 4(v), %edx
29050 RET_ENDP
29051+BEGIN(read_unchecked)
29052+ movl (v), %eax
29053+ movl 4(v), %edx
29054+RET_ENDP
29055 #undef v
29056
29057 #define v %esi
29058@@ -55,6 +59,10 @@ BEGIN(set)
29059 movl %ebx, (v)
29060 movl %ecx, 4(v)
29061 RET_ENDP
29062+BEGIN(set_unchecked)
29063+ movl %ebx, (v)
29064+ movl %ecx, 4(v)
29065+RET_ENDP
29066 #undef v
29067
29068 #define v %esi
29069@@ -70,6 +78,20 @@ RET_ENDP
29070 BEGIN(add)
29071 addl %eax, (v)
29072 adcl %edx, 4(v)
29073+
29074+#ifdef CONFIG_PAX_REFCOUNT
29075+ jno 0f
29076+ subl %eax, (v)
29077+ sbbl %edx, 4(v)
29078+ int $4
29079+0:
29080+ _ASM_EXTABLE(0b, 0b)
29081+#endif
29082+
29083+RET_ENDP
29084+BEGIN(add_unchecked)
29085+ addl %eax, (v)
29086+ adcl %edx, 4(v)
29087 RET_ENDP
29088 #undef v
29089
29090@@ -77,6 +99,24 @@ RET_ENDP
29091 BEGIN(add_return)
29092 addl (v), %eax
29093 adcl 4(v), %edx
29094+
29095+#ifdef CONFIG_PAX_REFCOUNT
29096+ into
29097+1234:
29098+ _ASM_EXTABLE(1234b, 2f)
29099+#endif
29100+
29101+ movl %eax, (v)
29102+ movl %edx, 4(v)
29103+
29104+#ifdef CONFIG_PAX_REFCOUNT
29105+2:
29106+#endif
29107+
29108+RET_ENDP
29109+BEGIN(add_return_unchecked)
29110+ addl (v), %eax
29111+ adcl 4(v), %edx
29112 movl %eax, (v)
29113 movl %edx, 4(v)
29114 RET_ENDP
29115@@ -86,6 +126,20 @@ RET_ENDP
29116 BEGIN(sub)
29117 subl %eax, (v)
29118 sbbl %edx, 4(v)
29119+
29120+#ifdef CONFIG_PAX_REFCOUNT
29121+ jno 0f
29122+ addl %eax, (v)
29123+ adcl %edx, 4(v)
29124+ int $4
29125+0:
29126+ _ASM_EXTABLE(0b, 0b)
29127+#endif
29128+
29129+RET_ENDP
29130+BEGIN(sub_unchecked)
29131+ subl %eax, (v)
29132+ sbbl %edx, 4(v)
29133 RET_ENDP
29134 #undef v
29135
29136@@ -96,6 +150,27 @@ BEGIN(sub_return)
29137 sbbl $0, %edx
29138 addl (v), %eax
29139 adcl 4(v), %edx
29140+
29141+#ifdef CONFIG_PAX_REFCOUNT
29142+ into
29143+1234:
29144+ _ASM_EXTABLE(1234b, 2f)
29145+#endif
29146+
29147+ movl %eax, (v)
29148+ movl %edx, 4(v)
29149+
29150+#ifdef CONFIG_PAX_REFCOUNT
29151+2:
29152+#endif
29153+
29154+RET_ENDP
29155+BEGIN(sub_return_unchecked)
29156+ negl %edx
29157+ negl %eax
29158+ sbbl $0, %edx
29159+ addl (v), %eax
29160+ adcl 4(v), %edx
29161 movl %eax, (v)
29162 movl %edx, 4(v)
29163 RET_ENDP
29164@@ -105,6 +180,20 @@ RET_ENDP
29165 BEGIN(inc)
29166 addl $1, (v)
29167 adcl $0, 4(v)
29168+
29169+#ifdef CONFIG_PAX_REFCOUNT
29170+ jno 0f
29171+ subl $1, (v)
29172+ sbbl $0, 4(v)
29173+ int $4
29174+0:
29175+ _ASM_EXTABLE(0b, 0b)
29176+#endif
29177+
29178+RET_ENDP
29179+BEGIN(inc_unchecked)
29180+ addl $1, (v)
29181+ adcl $0, 4(v)
29182 RET_ENDP
29183 #undef v
29184
29185@@ -114,6 +203,26 @@ BEGIN(inc_return)
29186 movl 4(v), %edx
29187 addl $1, %eax
29188 adcl $0, %edx
29189+
29190+#ifdef CONFIG_PAX_REFCOUNT
29191+ into
29192+1234:
29193+ _ASM_EXTABLE(1234b, 2f)
29194+#endif
29195+
29196+ movl %eax, (v)
29197+ movl %edx, 4(v)
29198+
29199+#ifdef CONFIG_PAX_REFCOUNT
29200+2:
29201+#endif
29202+
29203+RET_ENDP
29204+BEGIN(inc_return_unchecked)
29205+ movl (v), %eax
29206+ movl 4(v), %edx
29207+ addl $1, %eax
29208+ adcl $0, %edx
29209 movl %eax, (v)
29210 movl %edx, 4(v)
29211 RET_ENDP
29212@@ -123,6 +232,20 @@ RET_ENDP
29213 BEGIN(dec)
29214 subl $1, (v)
29215 sbbl $0, 4(v)
29216+
29217+#ifdef CONFIG_PAX_REFCOUNT
29218+ jno 0f
29219+ addl $1, (v)
29220+ adcl $0, 4(v)
29221+ int $4
29222+0:
29223+ _ASM_EXTABLE(0b, 0b)
29224+#endif
29225+
29226+RET_ENDP
29227+BEGIN(dec_unchecked)
29228+ subl $1, (v)
29229+ sbbl $0, 4(v)
29230 RET_ENDP
29231 #undef v
29232
29233@@ -132,6 +255,26 @@ BEGIN(dec_return)
29234 movl 4(v), %edx
29235 subl $1, %eax
29236 sbbl $0, %edx
29237+
29238+#ifdef CONFIG_PAX_REFCOUNT
29239+ into
29240+1234:
29241+ _ASM_EXTABLE(1234b, 2f)
29242+#endif
29243+
29244+ movl %eax, (v)
29245+ movl %edx, 4(v)
29246+
29247+#ifdef CONFIG_PAX_REFCOUNT
29248+2:
29249+#endif
29250+
29251+RET_ENDP
29252+BEGIN(dec_return_unchecked)
29253+ movl (v), %eax
29254+ movl 4(v), %edx
29255+ subl $1, %eax
29256+ sbbl $0, %edx
29257 movl %eax, (v)
29258 movl %edx, 4(v)
29259 RET_ENDP
29260@@ -143,6 +286,13 @@ BEGIN(add_unless)
29261 adcl %edx, %edi
29262 addl (v), %eax
29263 adcl 4(v), %edx
29264+
29265+#ifdef CONFIG_PAX_REFCOUNT
29266+ into
29267+1234:
29268+ _ASM_EXTABLE(1234b, 2f)
29269+#endif
29270+
29271 cmpl %eax, %ecx
29272 je 3f
29273 1:
29274@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29275 1:
29276 addl $1, %eax
29277 adcl $0, %edx
29278+
29279+#ifdef CONFIG_PAX_REFCOUNT
29280+ into
29281+1234:
29282+ _ASM_EXTABLE(1234b, 2f)
29283+#endif
29284+
29285 movl %eax, (v)
29286 movl %edx, 4(v)
29287 movl $1, %eax
29288@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29289 movl 4(v), %edx
29290 subl $1, %eax
29291 sbbl $0, %edx
29292+
29293+#ifdef CONFIG_PAX_REFCOUNT
29294+ into
29295+1234:
29296+ _ASM_EXTABLE(1234b, 1f)
29297+#endif
29298+
29299 js 1f
29300 movl %eax, (v)
29301 movl %edx, 4(v)
29302diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29303index f5cc9eb..51fa319 100644
29304--- a/arch/x86/lib/atomic64_cx8_32.S
29305+++ b/arch/x86/lib/atomic64_cx8_32.S
29306@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29307 CFI_STARTPROC
29308
29309 read64 %ecx
29310+ pax_force_retaddr
29311 ret
29312 CFI_ENDPROC
29313 ENDPROC(atomic64_read_cx8)
29314
29315+ENTRY(atomic64_read_unchecked_cx8)
29316+ CFI_STARTPROC
29317+
29318+ read64 %ecx
29319+ pax_force_retaddr
29320+ ret
29321+ CFI_ENDPROC
29322+ENDPROC(atomic64_read_unchecked_cx8)
29323+
29324 ENTRY(atomic64_set_cx8)
29325 CFI_STARTPROC
29326
29327@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29328 cmpxchg8b (%esi)
29329 jne 1b
29330
29331+ pax_force_retaddr
29332 ret
29333 CFI_ENDPROC
29334 ENDPROC(atomic64_set_cx8)
29335
29336+ENTRY(atomic64_set_unchecked_cx8)
29337+ CFI_STARTPROC
29338+
29339+1:
29340+/* we don't need LOCK_PREFIX since aligned 64-bit writes
29341+ * are atomic on 586 and newer */
29342+ cmpxchg8b (%esi)
29343+ jne 1b
29344+
29345+ pax_force_retaddr
29346+ ret
29347+ CFI_ENDPROC
29348+ENDPROC(atomic64_set_unchecked_cx8)
29349+
29350 ENTRY(atomic64_xchg_cx8)
29351 CFI_STARTPROC
29352
29353@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29354 cmpxchg8b (%esi)
29355 jne 1b
29356
29357+ pax_force_retaddr
29358 ret
29359 CFI_ENDPROC
29360 ENDPROC(atomic64_xchg_cx8)
29361
29362-.macro addsub_return func ins insc
29363-ENTRY(atomic64_\func\()_return_cx8)
29364+.macro addsub_return func ins insc unchecked=""
29365+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29366 CFI_STARTPROC
29367 SAVE ebp
29368 SAVE ebx
29369@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29370 movl %edx, %ecx
29371 \ins\()l %esi, %ebx
29372 \insc\()l %edi, %ecx
29373+
29374+.ifb \unchecked
29375+#ifdef CONFIG_PAX_REFCOUNT
29376+ into
29377+2:
29378+ _ASM_EXTABLE(2b, 3f)
29379+#endif
29380+.endif
29381+
29382 LOCK_PREFIX
29383 cmpxchg8b (%ebp)
29384 jne 1b
29385-
29386-10:
29387 movl %ebx, %eax
29388 movl %ecx, %edx
29389+
29390+.ifb \unchecked
29391+#ifdef CONFIG_PAX_REFCOUNT
29392+3:
29393+#endif
29394+.endif
29395+
29396 RESTORE edi
29397 RESTORE esi
29398 RESTORE ebx
29399 RESTORE ebp
29400+ pax_force_retaddr
29401 ret
29402 CFI_ENDPROC
29403-ENDPROC(atomic64_\func\()_return_cx8)
29404+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29405 .endm
29406
29407 addsub_return add add adc
29408 addsub_return sub sub sbb
29409+addsub_return add add adc _unchecked
29410+addsub_return sub sub sbb _unchecked
29411
29412-.macro incdec_return func ins insc
29413-ENTRY(atomic64_\func\()_return_cx8)
29414+.macro incdec_return func ins insc unchecked=""
29415+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29416 CFI_STARTPROC
29417 SAVE ebx
29418
29419@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29420 movl %edx, %ecx
29421 \ins\()l $1, %ebx
29422 \insc\()l $0, %ecx
29423+
29424+.ifb \unchecked
29425+#ifdef CONFIG_PAX_REFCOUNT
29426+ into
29427+2:
29428+ _ASM_EXTABLE(2b, 3f)
29429+#endif
29430+.endif
29431+
29432 LOCK_PREFIX
29433 cmpxchg8b (%esi)
29434 jne 1b
29435
29436-10:
29437 movl %ebx, %eax
29438 movl %ecx, %edx
29439+
29440+.ifb \unchecked
29441+#ifdef CONFIG_PAX_REFCOUNT
29442+3:
29443+#endif
29444+.endif
29445+
29446 RESTORE ebx
29447+ pax_force_retaddr
29448 ret
29449 CFI_ENDPROC
29450-ENDPROC(atomic64_\func\()_return_cx8)
29451+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29452 .endm
29453
29454 incdec_return inc add adc
29455 incdec_return dec sub sbb
29456+incdec_return inc add adc _unchecked
29457+incdec_return dec sub sbb _unchecked
29458
29459 ENTRY(atomic64_dec_if_positive_cx8)
29460 CFI_STARTPROC
29461@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29462 movl %edx, %ecx
29463 subl $1, %ebx
29464 sbb $0, %ecx
29465+
29466+#ifdef CONFIG_PAX_REFCOUNT
29467+ into
29468+1234:
29469+ _ASM_EXTABLE(1234b, 2f)
29470+#endif
29471+
29472 js 2f
29473 LOCK_PREFIX
29474 cmpxchg8b (%esi)
29475@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29476 movl %ebx, %eax
29477 movl %ecx, %edx
29478 RESTORE ebx
29479+ pax_force_retaddr
29480 ret
29481 CFI_ENDPROC
29482 ENDPROC(atomic64_dec_if_positive_cx8)
29483@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29484 movl %edx, %ecx
29485 addl %ebp, %ebx
29486 adcl %edi, %ecx
29487+
29488+#ifdef CONFIG_PAX_REFCOUNT
29489+ into
29490+1234:
29491+ _ASM_EXTABLE(1234b, 3f)
29492+#endif
29493+
29494 LOCK_PREFIX
29495 cmpxchg8b (%esi)
29496 jne 1b
29497@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29498 CFI_ADJUST_CFA_OFFSET -8
29499 RESTORE ebx
29500 RESTORE ebp
29501+ pax_force_retaddr
29502 ret
29503 4:
29504 cmpl %edx, 4(%esp)
29505@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29506 xorl %ecx, %ecx
29507 addl $1, %ebx
29508 adcl %edx, %ecx
29509+
29510+#ifdef CONFIG_PAX_REFCOUNT
29511+ into
29512+1234:
29513+ _ASM_EXTABLE(1234b, 3f)
29514+#endif
29515+
29516 LOCK_PREFIX
29517 cmpxchg8b (%esi)
29518 jne 1b
29519@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29520 movl $1, %eax
29521 3:
29522 RESTORE ebx
29523+ pax_force_retaddr
29524 ret
29525 CFI_ENDPROC
29526 ENDPROC(atomic64_inc_not_zero_cx8)
29527diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29528index e78b8ee..7e173a8 100644
29529--- a/arch/x86/lib/checksum_32.S
29530+++ b/arch/x86/lib/checksum_32.S
29531@@ -29,7 +29,8 @@
29532 #include <asm/dwarf2.h>
29533 #include <asm/errno.h>
29534 #include <asm/asm.h>
29535-
29536+#include <asm/segment.h>
29537+
29538 /*
29539 * computes a partial checksum, e.g. for TCP/UDP fragments
29540 */
29541@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29542
29543 #define ARGBASE 16
29544 #define FP 12
29545-
29546-ENTRY(csum_partial_copy_generic)
29547+
29548+ENTRY(csum_partial_copy_generic_to_user)
29549 CFI_STARTPROC
29550+
29551+#ifdef CONFIG_PAX_MEMORY_UDEREF
29552+ pushl_cfi %gs
29553+ popl_cfi %es
29554+ jmp csum_partial_copy_generic
29555+#endif
29556+
29557+ENTRY(csum_partial_copy_generic_from_user)
29558+
29559+#ifdef CONFIG_PAX_MEMORY_UDEREF
29560+ pushl_cfi %gs
29561+ popl_cfi %ds
29562+#endif
29563+
29564+ENTRY(csum_partial_copy_generic)
29565 subl $4,%esp
29566 CFI_ADJUST_CFA_OFFSET 4
29567 pushl_cfi %edi
29568@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29569 jmp 4f
29570 SRC(1: movw (%esi), %bx )
29571 addl $2, %esi
29572-DST( movw %bx, (%edi) )
29573+DST( movw %bx, %es:(%edi) )
29574 addl $2, %edi
29575 addw %bx, %ax
29576 adcl $0, %eax
29577@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29578 SRC(1: movl (%esi), %ebx )
29579 SRC( movl 4(%esi), %edx )
29580 adcl %ebx, %eax
29581-DST( movl %ebx, (%edi) )
29582+DST( movl %ebx, %es:(%edi) )
29583 adcl %edx, %eax
29584-DST( movl %edx, 4(%edi) )
29585+DST( movl %edx, %es:4(%edi) )
29586
29587 SRC( movl 8(%esi), %ebx )
29588 SRC( movl 12(%esi), %edx )
29589 adcl %ebx, %eax
29590-DST( movl %ebx, 8(%edi) )
29591+DST( movl %ebx, %es:8(%edi) )
29592 adcl %edx, %eax
29593-DST( movl %edx, 12(%edi) )
29594+DST( movl %edx, %es:12(%edi) )
29595
29596 SRC( movl 16(%esi), %ebx )
29597 SRC( movl 20(%esi), %edx )
29598 adcl %ebx, %eax
29599-DST( movl %ebx, 16(%edi) )
29600+DST( movl %ebx, %es:16(%edi) )
29601 adcl %edx, %eax
29602-DST( movl %edx, 20(%edi) )
29603+DST( movl %edx, %es:20(%edi) )
29604
29605 SRC( movl 24(%esi), %ebx )
29606 SRC( movl 28(%esi), %edx )
29607 adcl %ebx, %eax
29608-DST( movl %ebx, 24(%edi) )
29609+DST( movl %ebx, %es:24(%edi) )
29610 adcl %edx, %eax
29611-DST( movl %edx, 28(%edi) )
29612+DST( movl %edx, %es:28(%edi) )
29613
29614 lea 32(%esi), %esi
29615 lea 32(%edi), %edi
29616@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29617 shrl $2, %edx # This clears CF
29618 SRC(3: movl (%esi), %ebx )
29619 adcl %ebx, %eax
29620-DST( movl %ebx, (%edi) )
29621+DST( movl %ebx, %es:(%edi) )
29622 lea 4(%esi), %esi
29623 lea 4(%edi), %edi
29624 dec %edx
29625@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29626 jb 5f
29627 SRC( movw (%esi), %cx )
29628 leal 2(%esi), %esi
29629-DST( movw %cx, (%edi) )
29630+DST( movw %cx, %es:(%edi) )
29631 leal 2(%edi), %edi
29632 je 6f
29633 shll $16,%ecx
29634 SRC(5: movb (%esi), %cl )
29635-DST( movb %cl, (%edi) )
29636+DST( movb %cl, %es:(%edi) )
29637 6: addl %ecx, %eax
29638 adcl $0, %eax
29639 7:
29640@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29641
29642 6001:
29643 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29644- movl $-EFAULT, (%ebx)
29645+ movl $-EFAULT, %ss:(%ebx)
29646
29647 # zero the complete destination - computing the rest
29648 # is too much work
29649@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29650
29651 6002:
29652 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29653- movl $-EFAULT,(%ebx)
29654+ movl $-EFAULT,%ss:(%ebx)
29655 jmp 5000b
29656
29657 .previous
29658
29659+ pushl_cfi %ss
29660+ popl_cfi %ds
29661+ pushl_cfi %ss
29662+ popl_cfi %es
29663 popl_cfi %ebx
29664 CFI_RESTORE ebx
29665 popl_cfi %esi
29666@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29667 popl_cfi %ecx # equivalent to addl $4,%esp
29668 ret
29669 CFI_ENDPROC
29670-ENDPROC(csum_partial_copy_generic)
29671+ENDPROC(csum_partial_copy_generic_to_user)
29672
29673 #else
29674
29675 /* Version for PentiumII/PPro */
29676
29677 #define ROUND1(x) \
29678+ nop; nop; nop; \
29679 SRC(movl x(%esi), %ebx ) ; \
29680 addl %ebx, %eax ; \
29681- DST(movl %ebx, x(%edi) ) ;
29682+ DST(movl %ebx, %es:x(%edi)) ;
29683
29684 #define ROUND(x) \
29685+ nop; nop; nop; \
29686 SRC(movl x(%esi), %ebx ) ; \
29687 adcl %ebx, %eax ; \
29688- DST(movl %ebx, x(%edi) ) ;
29689+ DST(movl %ebx, %es:x(%edi)) ;
29690
29691 #define ARGBASE 12
29692-
29693-ENTRY(csum_partial_copy_generic)
29694+
29695+ENTRY(csum_partial_copy_generic_to_user)
29696 CFI_STARTPROC
29697+
29698+#ifdef CONFIG_PAX_MEMORY_UDEREF
29699+ pushl_cfi %gs
29700+ popl_cfi %es
29701+ jmp csum_partial_copy_generic
29702+#endif
29703+
29704+ENTRY(csum_partial_copy_generic_from_user)
29705+
29706+#ifdef CONFIG_PAX_MEMORY_UDEREF
29707+ pushl_cfi %gs
29708+ popl_cfi %ds
29709+#endif
29710+
29711+ENTRY(csum_partial_copy_generic)
29712 pushl_cfi %ebx
29713 CFI_REL_OFFSET ebx, 0
29714 pushl_cfi %edi
29715@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29716 subl %ebx, %edi
29717 lea -1(%esi),%edx
29718 andl $-32,%edx
29719- lea 3f(%ebx,%ebx), %ebx
29720+ lea 3f(%ebx,%ebx,2), %ebx
29721 testl %esi, %esi
29722 jmp *%ebx
29723 1: addl $64,%esi
29724@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29725 jb 5f
29726 SRC( movw (%esi), %dx )
29727 leal 2(%esi), %esi
29728-DST( movw %dx, (%edi) )
29729+DST( movw %dx, %es:(%edi) )
29730 leal 2(%edi), %edi
29731 je 6f
29732 shll $16,%edx
29733 5:
29734 SRC( movb (%esi), %dl )
29735-DST( movb %dl, (%edi) )
29736+DST( movb %dl, %es:(%edi) )
29737 6: addl %edx, %eax
29738 adcl $0, %eax
29739 7:
29740 .section .fixup, "ax"
29741 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29742- movl $-EFAULT, (%ebx)
29743+ movl $-EFAULT, %ss:(%ebx)
29744 # zero the complete destination (computing the rest is too much work)
29745 movl ARGBASE+8(%esp),%edi # dst
29746 movl ARGBASE+12(%esp),%ecx # len
29747@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29748 rep; stosb
29749 jmp 7b
29750 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29751- movl $-EFAULT, (%ebx)
29752+ movl $-EFAULT, %ss:(%ebx)
29753 jmp 7b
29754 .previous
29755
29756+#ifdef CONFIG_PAX_MEMORY_UDEREF
29757+ pushl_cfi %ss
29758+ popl_cfi %ds
29759+ pushl_cfi %ss
29760+ popl_cfi %es
29761+#endif
29762+
29763 popl_cfi %esi
29764 CFI_RESTORE esi
29765 popl_cfi %edi
29766@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29767 CFI_RESTORE ebx
29768 ret
29769 CFI_ENDPROC
29770-ENDPROC(csum_partial_copy_generic)
29771+ENDPROC(csum_partial_copy_generic_to_user)
29772
29773 #undef ROUND
29774 #undef ROUND1
29775diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29776index f2145cf..cea889d 100644
29777--- a/arch/x86/lib/clear_page_64.S
29778+++ b/arch/x86/lib/clear_page_64.S
29779@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29780 movl $4096/8,%ecx
29781 xorl %eax,%eax
29782 rep stosq
29783+ pax_force_retaddr
29784 ret
29785 CFI_ENDPROC
29786 ENDPROC(clear_page_c)
29787@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29788 movl $4096,%ecx
29789 xorl %eax,%eax
29790 rep stosb
29791+ pax_force_retaddr
29792 ret
29793 CFI_ENDPROC
29794 ENDPROC(clear_page_c_e)
29795@@ -43,6 +45,7 @@ ENTRY(clear_page)
29796 leaq 64(%rdi),%rdi
29797 jnz .Lloop
29798 nop
29799+ pax_force_retaddr
29800 ret
29801 CFI_ENDPROC
29802 .Lclear_page_end:
29803@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29804
29805 #include <asm/cpufeature.h>
29806
29807- .section .altinstr_replacement,"ax"
29808+ .section .altinstr_replacement,"a"
29809 1: .byte 0xeb /* jmp <disp8> */
29810 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29811 2: .byte 0xeb /* jmp <disp8> */
29812diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29813index 1e572c5..2a162cd 100644
29814--- a/arch/x86/lib/cmpxchg16b_emu.S
29815+++ b/arch/x86/lib/cmpxchg16b_emu.S
29816@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29817
29818 popf
29819 mov $1, %al
29820+ pax_force_retaddr
29821 ret
29822
29823 not_same:
29824 popf
29825 xor %al,%al
29826+ pax_force_retaddr
29827 ret
29828
29829 CFI_ENDPROC
29830diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29831index 176cca6..e0d658e 100644
29832--- a/arch/x86/lib/copy_page_64.S
29833+++ b/arch/x86/lib/copy_page_64.S
29834@@ -9,6 +9,7 @@ copy_page_rep:
29835 CFI_STARTPROC
29836 movl $4096/8, %ecx
29837 rep movsq
29838+ pax_force_retaddr
29839 ret
29840 CFI_ENDPROC
29841 ENDPROC(copy_page_rep)
29842@@ -24,8 +25,8 @@ ENTRY(copy_page)
29843 CFI_ADJUST_CFA_OFFSET 2*8
29844 movq %rbx, (%rsp)
29845 CFI_REL_OFFSET rbx, 0
29846- movq %r12, 1*8(%rsp)
29847- CFI_REL_OFFSET r12, 1*8
29848+ movq %r13, 1*8(%rsp)
29849+ CFI_REL_OFFSET r13, 1*8
29850
29851 movl $(4096/64)-5, %ecx
29852 .p2align 4
29853@@ -38,7 +39,7 @@ ENTRY(copy_page)
29854 movq 0x8*4(%rsi), %r9
29855 movq 0x8*5(%rsi), %r10
29856 movq 0x8*6(%rsi), %r11
29857- movq 0x8*7(%rsi), %r12
29858+ movq 0x8*7(%rsi), %r13
29859
29860 prefetcht0 5*64(%rsi)
29861
29862@@ -49,7 +50,7 @@ ENTRY(copy_page)
29863 movq %r9, 0x8*4(%rdi)
29864 movq %r10, 0x8*5(%rdi)
29865 movq %r11, 0x8*6(%rdi)
29866- movq %r12, 0x8*7(%rdi)
29867+ movq %r13, 0x8*7(%rdi)
29868
29869 leaq 64 (%rsi), %rsi
29870 leaq 64 (%rdi), %rdi
29871@@ -68,7 +69,7 @@ ENTRY(copy_page)
29872 movq 0x8*4(%rsi), %r9
29873 movq 0x8*5(%rsi), %r10
29874 movq 0x8*6(%rsi), %r11
29875- movq 0x8*7(%rsi), %r12
29876+ movq 0x8*7(%rsi), %r13
29877
29878 movq %rax, 0x8*0(%rdi)
29879 movq %rbx, 0x8*1(%rdi)
29880@@ -77,7 +78,7 @@ ENTRY(copy_page)
29881 movq %r9, 0x8*4(%rdi)
29882 movq %r10, 0x8*5(%rdi)
29883 movq %r11, 0x8*6(%rdi)
29884- movq %r12, 0x8*7(%rdi)
29885+ movq %r13, 0x8*7(%rdi)
29886
29887 leaq 64(%rdi), %rdi
29888 leaq 64(%rsi), %rsi
29889@@ -85,10 +86,11 @@ ENTRY(copy_page)
29890
29891 movq (%rsp), %rbx
29892 CFI_RESTORE rbx
29893- movq 1*8(%rsp), %r12
29894- CFI_RESTORE r12
29895+ movq 1*8(%rsp), %r13
29896+ CFI_RESTORE r13
29897 addq $2*8, %rsp
29898 CFI_ADJUST_CFA_OFFSET -2*8
29899+ pax_force_retaddr
29900 ret
29901 .Lcopy_page_end:
29902 CFI_ENDPROC
29903@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29904
29905 #include <asm/cpufeature.h>
29906
29907- .section .altinstr_replacement,"ax"
29908+ .section .altinstr_replacement,"a"
29909 1: .byte 0xeb /* jmp <disp8> */
29910 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29911 2:
29912diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29913index dee945d..a84067b 100644
29914--- a/arch/x86/lib/copy_user_64.S
29915+++ b/arch/x86/lib/copy_user_64.S
29916@@ -18,31 +18,7 @@
29917 #include <asm/alternative-asm.h>
29918 #include <asm/asm.h>
29919 #include <asm/smap.h>
29920-
29921-/*
29922- * By placing feature2 after feature1 in altinstructions section, we logically
29923- * implement:
29924- * If CPU has feature2, jmp to alt2 is used
29925- * else if CPU has feature1, jmp to alt1 is used
29926- * else jmp to orig is used.
29927- */
29928- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29929-0:
29930- .byte 0xe9 /* 32bit jump */
29931- .long \orig-1f /* by default jump to orig */
29932-1:
29933- .section .altinstr_replacement,"ax"
29934-2: .byte 0xe9 /* near jump with 32bit immediate */
29935- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29936-3: .byte 0xe9 /* near jump with 32bit immediate */
29937- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29938- .previous
29939-
29940- .section .altinstructions,"a"
29941- altinstruction_entry 0b,2b,\feature1,5,5
29942- altinstruction_entry 0b,3b,\feature2,5,5
29943- .previous
29944- .endm
29945+#include <asm/pgtable.h>
29946
29947 .macro ALIGN_DESTINATION
29948 #ifdef FIX_ALIGNMENT
29949@@ -70,52 +46,6 @@
29950 #endif
29951 .endm
29952
29953-/* Standard copy_to_user with segment limit checking */
29954-ENTRY(_copy_to_user)
29955- CFI_STARTPROC
29956- GET_THREAD_INFO(%rax)
29957- movq %rdi,%rcx
29958- addq %rdx,%rcx
29959- jc bad_to_user
29960- cmpq TI_addr_limit(%rax),%rcx
29961- ja bad_to_user
29962- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29963- copy_user_generic_unrolled,copy_user_generic_string, \
29964- copy_user_enhanced_fast_string
29965- CFI_ENDPROC
29966-ENDPROC(_copy_to_user)
29967-
29968-/* Standard copy_from_user with segment limit checking */
29969-ENTRY(_copy_from_user)
29970- CFI_STARTPROC
29971- GET_THREAD_INFO(%rax)
29972- movq %rsi,%rcx
29973- addq %rdx,%rcx
29974- jc bad_from_user
29975- cmpq TI_addr_limit(%rax),%rcx
29976- ja bad_from_user
29977- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29978- copy_user_generic_unrolled,copy_user_generic_string, \
29979- copy_user_enhanced_fast_string
29980- CFI_ENDPROC
29981-ENDPROC(_copy_from_user)
29982-
29983- .section .fixup,"ax"
29984- /* must zero dest */
29985-ENTRY(bad_from_user)
29986-bad_from_user:
29987- CFI_STARTPROC
29988- movl %edx,%ecx
29989- xorl %eax,%eax
29990- rep
29991- stosb
29992-bad_to_user:
29993- movl %edx,%eax
29994- ret
29995- CFI_ENDPROC
29996-ENDPROC(bad_from_user)
29997- .previous
29998-
29999 /*
30000 * copy_user_generic_unrolled - memory copy with exception handling.
30001 * This version is for CPUs like P4 that don't have efficient micro
30002@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
30003 */
30004 ENTRY(copy_user_generic_unrolled)
30005 CFI_STARTPROC
30006+ ASM_PAX_OPEN_USERLAND
30007 ASM_STAC
30008 cmpl $8,%edx
30009 jb 20f /* less then 8 bytes, go to byte copy loop */
30010@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
30011 jnz 21b
30012 23: xor %eax,%eax
30013 ASM_CLAC
30014+ ASM_PAX_CLOSE_USERLAND
30015+ pax_force_retaddr
30016 ret
30017
30018 .section .fixup,"ax"
30019@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
30020 */
30021 ENTRY(copy_user_generic_string)
30022 CFI_STARTPROC
30023+ ASM_PAX_OPEN_USERLAND
30024 ASM_STAC
30025 cmpl $8,%edx
30026 jb 2f /* less than 8 bytes, go to byte copy loop */
30027@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
30028 movsb
30029 xorl %eax,%eax
30030 ASM_CLAC
30031+ ASM_PAX_CLOSE_USERLAND
30032+ pax_force_retaddr
30033 ret
30034
30035 .section .fixup,"ax"
30036@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30037 */
30038 ENTRY(copy_user_enhanced_fast_string)
30039 CFI_STARTPROC
30040+ ASM_PAX_OPEN_USERLAND
30041 ASM_STAC
30042 movl %edx,%ecx
30043 1: rep
30044 movsb
30045 xorl %eax,%eax
30046 ASM_CLAC
30047+ ASM_PAX_CLOSE_USERLAND
30048+ pax_force_retaddr
30049 ret
30050
30051 .section .fixup,"ax"
30052diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30053index 6a4f43c..c70fb52 100644
30054--- a/arch/x86/lib/copy_user_nocache_64.S
30055+++ b/arch/x86/lib/copy_user_nocache_64.S
30056@@ -8,6 +8,7 @@
30057
30058 #include <linux/linkage.h>
30059 #include <asm/dwarf2.h>
30060+#include <asm/alternative-asm.h>
30061
30062 #define FIX_ALIGNMENT 1
30063
30064@@ -16,6 +17,7 @@
30065 #include <asm/thread_info.h>
30066 #include <asm/asm.h>
30067 #include <asm/smap.h>
30068+#include <asm/pgtable.h>
30069
30070 .macro ALIGN_DESTINATION
30071 #ifdef FIX_ALIGNMENT
30072@@ -49,6 +51,16 @@
30073 */
30074 ENTRY(__copy_user_nocache)
30075 CFI_STARTPROC
30076+
30077+#ifdef CONFIG_PAX_MEMORY_UDEREF
30078+ mov pax_user_shadow_base,%rcx
30079+ cmp %rcx,%rsi
30080+ jae 1f
30081+ add %rcx,%rsi
30082+1:
30083+#endif
30084+
30085+ ASM_PAX_OPEN_USERLAND
30086 ASM_STAC
30087 cmpl $8,%edx
30088 jb 20f /* less then 8 bytes, go to byte copy loop */
30089@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30090 jnz 21b
30091 23: xorl %eax,%eax
30092 ASM_CLAC
30093+ ASM_PAX_CLOSE_USERLAND
30094 sfence
30095+ pax_force_retaddr
30096 ret
30097
30098 .section .fixup,"ax"
30099diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30100index 2419d5f..fe52d0e 100644
30101--- a/arch/x86/lib/csum-copy_64.S
30102+++ b/arch/x86/lib/csum-copy_64.S
30103@@ -9,6 +9,7 @@
30104 #include <asm/dwarf2.h>
30105 #include <asm/errno.h>
30106 #include <asm/asm.h>
30107+#include <asm/alternative-asm.h>
30108
30109 /*
30110 * Checksum copy with exception handling.
30111@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30112 CFI_ADJUST_CFA_OFFSET 7*8
30113 movq %rbx, 2*8(%rsp)
30114 CFI_REL_OFFSET rbx, 2*8
30115- movq %r12, 3*8(%rsp)
30116- CFI_REL_OFFSET r12, 3*8
30117+ movq %r15, 3*8(%rsp)
30118+ CFI_REL_OFFSET r15, 3*8
30119 movq %r14, 4*8(%rsp)
30120 CFI_REL_OFFSET r14, 4*8
30121 movq %r13, 5*8(%rsp)
30122@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30123 movl %edx, %ecx
30124
30125 xorl %r9d, %r9d
30126- movq %rcx, %r12
30127+ movq %rcx, %r15
30128
30129- shrq $6, %r12
30130+ shrq $6, %r15
30131 jz .Lhandle_tail /* < 64 */
30132
30133 clc
30134
30135 /* main loop. clear in 64 byte blocks */
30136 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30137- /* r11: temp3, rdx: temp4, r12 loopcnt */
30138+ /* r11: temp3, rdx: temp4, r15 loopcnt */
30139 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30140 .p2align 4
30141 .Lloop:
30142@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30143 adcq %r14, %rax
30144 adcq %r13, %rax
30145
30146- decl %r12d
30147+ decl %r15d
30148
30149 dest
30150 movq %rbx, (%rsi)
30151@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30152 .Lende:
30153 movq 2*8(%rsp), %rbx
30154 CFI_RESTORE rbx
30155- movq 3*8(%rsp), %r12
30156- CFI_RESTORE r12
30157+ movq 3*8(%rsp), %r15
30158+ CFI_RESTORE r15
30159 movq 4*8(%rsp), %r14
30160 CFI_RESTORE r14
30161 movq 5*8(%rsp), %r13
30162@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30163 CFI_RESTORE rbp
30164 addq $7*8, %rsp
30165 CFI_ADJUST_CFA_OFFSET -7*8
30166+ pax_force_retaddr
30167 ret
30168 CFI_RESTORE_STATE
30169
30170diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30171index 7609e0e..b449b98 100644
30172--- a/arch/x86/lib/csum-wrappers_64.c
30173+++ b/arch/x86/lib/csum-wrappers_64.c
30174@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30175 len -= 2;
30176 }
30177 }
30178+ pax_open_userland();
30179 stac();
30180- isum = csum_partial_copy_generic((__force const void *)src,
30181+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30182 dst, len, isum, errp, NULL);
30183 clac();
30184+ pax_close_userland();
30185 if (unlikely(*errp))
30186 goto out_err;
30187
30188@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30189 }
30190
30191 *errp = 0;
30192+ pax_open_userland();
30193 stac();
30194- ret = csum_partial_copy_generic(src, (void __force *)dst,
30195+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30196 len, isum, NULL, errp);
30197 clac();
30198+ pax_close_userland();
30199 return ret;
30200 }
30201 EXPORT_SYMBOL(csum_partial_copy_to_user);
30202diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30203index a451235..1daa956 100644
30204--- a/arch/x86/lib/getuser.S
30205+++ b/arch/x86/lib/getuser.S
30206@@ -33,17 +33,40 @@
30207 #include <asm/thread_info.h>
30208 #include <asm/asm.h>
30209 #include <asm/smap.h>
30210+#include <asm/segment.h>
30211+#include <asm/pgtable.h>
30212+#include <asm/alternative-asm.h>
30213+
30214+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30215+#define __copyuser_seg gs;
30216+#else
30217+#define __copyuser_seg
30218+#endif
30219
30220 .text
30221 ENTRY(__get_user_1)
30222 CFI_STARTPROC
30223+
30224+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30225 GET_THREAD_INFO(%_ASM_DX)
30226 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30227 jae bad_get_user
30228 ASM_STAC
30229-1: movzbl (%_ASM_AX),%edx
30230+
30231+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30232+ mov pax_user_shadow_base,%_ASM_DX
30233+ cmp %_ASM_DX,%_ASM_AX
30234+ jae 1234f
30235+ add %_ASM_DX,%_ASM_AX
30236+1234:
30237+#endif
30238+
30239+#endif
30240+
30241+1: __copyuser_seg movzbl (%_ASM_AX),%edx
30242 xor %eax,%eax
30243 ASM_CLAC
30244+ pax_force_retaddr
30245 ret
30246 CFI_ENDPROC
30247 ENDPROC(__get_user_1)
30248@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30249 ENTRY(__get_user_2)
30250 CFI_STARTPROC
30251 add $1,%_ASM_AX
30252+
30253+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30254 jc bad_get_user
30255 GET_THREAD_INFO(%_ASM_DX)
30256 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30257 jae bad_get_user
30258 ASM_STAC
30259-2: movzwl -1(%_ASM_AX),%edx
30260+
30261+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30262+ mov pax_user_shadow_base,%_ASM_DX
30263+ cmp %_ASM_DX,%_ASM_AX
30264+ jae 1234f
30265+ add %_ASM_DX,%_ASM_AX
30266+1234:
30267+#endif
30268+
30269+#endif
30270+
30271+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30272 xor %eax,%eax
30273 ASM_CLAC
30274+ pax_force_retaddr
30275 ret
30276 CFI_ENDPROC
30277 ENDPROC(__get_user_2)
30278@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30279 ENTRY(__get_user_4)
30280 CFI_STARTPROC
30281 add $3,%_ASM_AX
30282+
30283+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30284 jc bad_get_user
30285 GET_THREAD_INFO(%_ASM_DX)
30286 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30287 jae bad_get_user
30288 ASM_STAC
30289-3: movl -3(%_ASM_AX),%edx
30290+
30291+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30292+ mov pax_user_shadow_base,%_ASM_DX
30293+ cmp %_ASM_DX,%_ASM_AX
30294+ jae 1234f
30295+ add %_ASM_DX,%_ASM_AX
30296+1234:
30297+#endif
30298+
30299+#endif
30300+
30301+3: __copyuser_seg movl -3(%_ASM_AX),%edx
30302 xor %eax,%eax
30303 ASM_CLAC
30304+ pax_force_retaddr
30305 ret
30306 CFI_ENDPROC
30307 ENDPROC(__get_user_4)
30308@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30309 GET_THREAD_INFO(%_ASM_DX)
30310 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30311 jae bad_get_user
30312+
30313+#ifdef CONFIG_PAX_MEMORY_UDEREF
30314+ mov pax_user_shadow_base,%_ASM_DX
30315+ cmp %_ASM_DX,%_ASM_AX
30316+ jae 1234f
30317+ add %_ASM_DX,%_ASM_AX
30318+1234:
30319+#endif
30320+
30321 ASM_STAC
30322 4: movq -7(%_ASM_AX),%rdx
30323 xor %eax,%eax
30324 ASM_CLAC
30325+ pax_force_retaddr
30326 ret
30327 #else
30328 add $7,%_ASM_AX
30329@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30330 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30331 jae bad_get_user_8
30332 ASM_STAC
30333-4: movl -7(%_ASM_AX),%edx
30334-5: movl -3(%_ASM_AX),%ecx
30335+4: __copyuser_seg movl -7(%_ASM_AX),%edx
30336+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30337 xor %eax,%eax
30338 ASM_CLAC
30339+ pax_force_retaddr
30340 ret
30341 #endif
30342 CFI_ENDPROC
30343@@ -113,6 +175,7 @@ bad_get_user:
30344 xor %edx,%edx
30345 mov $(-EFAULT),%_ASM_AX
30346 ASM_CLAC
30347+ pax_force_retaddr
30348 ret
30349 CFI_ENDPROC
30350 END(bad_get_user)
30351@@ -124,6 +187,7 @@ bad_get_user_8:
30352 xor %ecx,%ecx
30353 mov $(-EFAULT),%_ASM_AX
30354 ASM_CLAC
30355+ pax_force_retaddr
30356 ret
30357 CFI_ENDPROC
30358 END(bad_get_user_8)
30359diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30360index 54fcffe..7be149e 100644
30361--- a/arch/x86/lib/insn.c
30362+++ b/arch/x86/lib/insn.c
30363@@ -20,8 +20,10 @@
30364
30365 #ifdef __KERNEL__
30366 #include <linux/string.h>
30367+#include <asm/pgtable_types.h>
30368 #else
30369 #include <string.h>
30370+#define ktla_ktva(addr) addr
30371 #endif
30372 #include <asm/inat.h>
30373 #include <asm/insn.h>
30374@@ -53,8 +55,8 @@
30375 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30376 {
30377 memset(insn, 0, sizeof(*insn));
30378- insn->kaddr = kaddr;
30379- insn->next_byte = kaddr;
30380+ insn->kaddr = ktla_ktva(kaddr);
30381+ insn->next_byte = ktla_ktva(kaddr);
30382 insn->x86_64 = x86_64 ? 1 : 0;
30383 insn->opnd_bytes = 4;
30384 if (x86_64)
30385diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30386index 05a95e7..326f2fa 100644
30387--- a/arch/x86/lib/iomap_copy_64.S
30388+++ b/arch/x86/lib/iomap_copy_64.S
30389@@ -17,6 +17,7 @@
30390
30391 #include <linux/linkage.h>
30392 #include <asm/dwarf2.h>
30393+#include <asm/alternative-asm.h>
30394
30395 /*
30396 * override generic version in lib/iomap_copy.c
30397@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30398 CFI_STARTPROC
30399 movl %edx,%ecx
30400 rep movsd
30401+ pax_force_retaddr
30402 ret
30403 CFI_ENDPROC
30404 ENDPROC(__iowrite32_copy)
30405diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30406index 56313a3..0db417e 100644
30407--- a/arch/x86/lib/memcpy_64.S
30408+++ b/arch/x86/lib/memcpy_64.S
30409@@ -24,7 +24,7 @@
30410 * This gets patched over the unrolled variant (below) via the
30411 * alternative instructions framework:
30412 */
30413- .section .altinstr_replacement, "ax", @progbits
30414+ .section .altinstr_replacement, "a", @progbits
30415 .Lmemcpy_c:
30416 movq %rdi, %rax
30417 movq %rdx, %rcx
30418@@ -33,6 +33,7 @@
30419 rep movsq
30420 movl %edx, %ecx
30421 rep movsb
30422+ pax_force_retaddr
30423 ret
30424 .Lmemcpy_e:
30425 .previous
30426@@ -44,11 +45,12 @@
30427 * This gets patched over the unrolled variant (below) via the
30428 * alternative instructions framework:
30429 */
30430- .section .altinstr_replacement, "ax", @progbits
30431+ .section .altinstr_replacement, "a", @progbits
30432 .Lmemcpy_c_e:
30433 movq %rdi, %rax
30434 movq %rdx, %rcx
30435 rep movsb
30436+ pax_force_retaddr
30437 ret
30438 .Lmemcpy_e_e:
30439 .previous
30440@@ -136,6 +138,7 @@ ENTRY(memcpy)
30441 movq %r9, 1*8(%rdi)
30442 movq %r10, -2*8(%rdi, %rdx)
30443 movq %r11, -1*8(%rdi, %rdx)
30444+ pax_force_retaddr
30445 retq
30446 .p2align 4
30447 .Lless_16bytes:
30448@@ -148,6 +151,7 @@ ENTRY(memcpy)
30449 movq -1*8(%rsi, %rdx), %r9
30450 movq %r8, 0*8(%rdi)
30451 movq %r9, -1*8(%rdi, %rdx)
30452+ pax_force_retaddr
30453 retq
30454 .p2align 4
30455 .Lless_8bytes:
30456@@ -161,6 +165,7 @@ ENTRY(memcpy)
30457 movl -4(%rsi, %rdx), %r8d
30458 movl %ecx, (%rdi)
30459 movl %r8d, -4(%rdi, %rdx)
30460+ pax_force_retaddr
30461 retq
30462 .p2align 4
30463 .Lless_3bytes:
30464@@ -179,6 +184,7 @@ ENTRY(memcpy)
30465 movb %cl, (%rdi)
30466
30467 .Lend:
30468+ pax_force_retaddr
30469 retq
30470 CFI_ENDPROC
30471 ENDPROC(memcpy)
30472diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30473index 65268a6..dd1de11 100644
30474--- a/arch/x86/lib/memmove_64.S
30475+++ b/arch/x86/lib/memmove_64.S
30476@@ -202,14 +202,16 @@ ENTRY(memmove)
30477 movb (%rsi), %r11b
30478 movb %r11b, (%rdi)
30479 13:
30480+ pax_force_retaddr
30481 retq
30482 CFI_ENDPROC
30483
30484- .section .altinstr_replacement,"ax"
30485+ .section .altinstr_replacement,"a"
30486 .Lmemmove_begin_forward_efs:
30487 /* Forward moving data. */
30488 movq %rdx, %rcx
30489 rep movsb
30490+ pax_force_retaddr
30491 retq
30492 .Lmemmove_end_forward_efs:
30493 .previous
30494diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30495index 2dcb380..2eb79fe 100644
30496--- a/arch/x86/lib/memset_64.S
30497+++ b/arch/x86/lib/memset_64.S
30498@@ -16,7 +16,7 @@
30499 *
30500 * rax original destination
30501 */
30502- .section .altinstr_replacement, "ax", @progbits
30503+ .section .altinstr_replacement, "a", @progbits
30504 .Lmemset_c:
30505 movq %rdi,%r9
30506 movq %rdx,%rcx
30507@@ -30,6 +30,7 @@
30508 movl %edx,%ecx
30509 rep stosb
30510 movq %r9,%rax
30511+ pax_force_retaddr
30512 ret
30513 .Lmemset_e:
30514 .previous
30515@@ -45,13 +46,14 @@
30516 *
30517 * rax original destination
30518 */
30519- .section .altinstr_replacement, "ax", @progbits
30520+ .section .altinstr_replacement, "a", @progbits
30521 .Lmemset_c_e:
30522 movq %rdi,%r9
30523 movb %sil,%al
30524 movq %rdx,%rcx
30525 rep stosb
30526 movq %r9,%rax
30527+ pax_force_retaddr
30528 ret
30529 .Lmemset_e_e:
30530 .previous
30531@@ -118,6 +120,7 @@ ENTRY(__memset)
30532
30533 .Lende:
30534 movq %r10,%rax
30535+ pax_force_retaddr
30536 ret
30537
30538 CFI_RESTORE_STATE
30539diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30540index c9f2d9b..e7fd2c0 100644
30541--- a/arch/x86/lib/mmx_32.c
30542+++ b/arch/x86/lib/mmx_32.c
30543@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30544 {
30545 void *p;
30546 int i;
30547+ unsigned long cr0;
30548
30549 if (unlikely(in_interrupt()))
30550 return __memcpy(to, from, len);
30551@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30552 kernel_fpu_begin();
30553
30554 __asm__ __volatile__ (
30555- "1: prefetch (%0)\n" /* This set is 28 bytes */
30556- " prefetch 64(%0)\n"
30557- " prefetch 128(%0)\n"
30558- " prefetch 192(%0)\n"
30559- " prefetch 256(%0)\n"
30560+ "1: prefetch (%1)\n" /* This set is 28 bytes */
30561+ " prefetch 64(%1)\n"
30562+ " prefetch 128(%1)\n"
30563+ " prefetch 192(%1)\n"
30564+ " prefetch 256(%1)\n"
30565 "2: \n"
30566 ".section .fixup, \"ax\"\n"
30567- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30568+ "3: \n"
30569+
30570+#ifdef CONFIG_PAX_KERNEXEC
30571+ " movl %%cr0, %0\n"
30572+ " movl %0, %%eax\n"
30573+ " andl $0xFFFEFFFF, %%eax\n"
30574+ " movl %%eax, %%cr0\n"
30575+#endif
30576+
30577+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30578+
30579+#ifdef CONFIG_PAX_KERNEXEC
30580+ " movl %0, %%cr0\n"
30581+#endif
30582+
30583 " jmp 2b\n"
30584 ".previous\n"
30585 _ASM_EXTABLE(1b, 3b)
30586- : : "r" (from));
30587+ : "=&r" (cr0) : "r" (from) : "ax");
30588
30589 for ( ; i > 5; i--) {
30590 __asm__ __volatile__ (
30591- "1: prefetch 320(%0)\n"
30592- "2: movq (%0), %%mm0\n"
30593- " movq 8(%0), %%mm1\n"
30594- " movq 16(%0), %%mm2\n"
30595- " movq 24(%0), %%mm3\n"
30596- " movq %%mm0, (%1)\n"
30597- " movq %%mm1, 8(%1)\n"
30598- " movq %%mm2, 16(%1)\n"
30599- " movq %%mm3, 24(%1)\n"
30600- " movq 32(%0), %%mm0\n"
30601- " movq 40(%0), %%mm1\n"
30602- " movq 48(%0), %%mm2\n"
30603- " movq 56(%0), %%mm3\n"
30604- " movq %%mm0, 32(%1)\n"
30605- " movq %%mm1, 40(%1)\n"
30606- " movq %%mm2, 48(%1)\n"
30607- " movq %%mm3, 56(%1)\n"
30608+ "1: prefetch 320(%1)\n"
30609+ "2: movq (%1), %%mm0\n"
30610+ " movq 8(%1), %%mm1\n"
30611+ " movq 16(%1), %%mm2\n"
30612+ " movq 24(%1), %%mm3\n"
30613+ " movq %%mm0, (%2)\n"
30614+ " movq %%mm1, 8(%2)\n"
30615+ " movq %%mm2, 16(%2)\n"
30616+ " movq %%mm3, 24(%2)\n"
30617+ " movq 32(%1), %%mm0\n"
30618+ " movq 40(%1), %%mm1\n"
30619+ " movq 48(%1), %%mm2\n"
30620+ " movq 56(%1), %%mm3\n"
30621+ " movq %%mm0, 32(%2)\n"
30622+ " movq %%mm1, 40(%2)\n"
30623+ " movq %%mm2, 48(%2)\n"
30624+ " movq %%mm3, 56(%2)\n"
30625 ".section .fixup, \"ax\"\n"
30626- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30627+ "3:\n"
30628+
30629+#ifdef CONFIG_PAX_KERNEXEC
30630+ " movl %%cr0, %0\n"
30631+ " movl %0, %%eax\n"
30632+ " andl $0xFFFEFFFF, %%eax\n"
30633+ " movl %%eax, %%cr0\n"
30634+#endif
30635+
30636+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30637+
30638+#ifdef CONFIG_PAX_KERNEXEC
30639+ " movl %0, %%cr0\n"
30640+#endif
30641+
30642 " jmp 2b\n"
30643 ".previous\n"
30644 _ASM_EXTABLE(1b, 3b)
30645- : : "r" (from), "r" (to) : "memory");
30646+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30647
30648 from += 64;
30649 to += 64;
30650@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30651 static void fast_copy_page(void *to, void *from)
30652 {
30653 int i;
30654+ unsigned long cr0;
30655
30656 kernel_fpu_begin();
30657
30658@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30659 * but that is for later. -AV
30660 */
30661 __asm__ __volatile__(
30662- "1: prefetch (%0)\n"
30663- " prefetch 64(%0)\n"
30664- " prefetch 128(%0)\n"
30665- " prefetch 192(%0)\n"
30666- " prefetch 256(%0)\n"
30667+ "1: prefetch (%1)\n"
30668+ " prefetch 64(%1)\n"
30669+ " prefetch 128(%1)\n"
30670+ " prefetch 192(%1)\n"
30671+ " prefetch 256(%1)\n"
30672 "2: \n"
30673 ".section .fixup, \"ax\"\n"
30674- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30675+ "3: \n"
30676+
30677+#ifdef CONFIG_PAX_KERNEXEC
30678+ " movl %%cr0, %0\n"
30679+ " movl %0, %%eax\n"
30680+ " andl $0xFFFEFFFF, %%eax\n"
30681+ " movl %%eax, %%cr0\n"
30682+#endif
30683+
30684+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30685+
30686+#ifdef CONFIG_PAX_KERNEXEC
30687+ " movl %0, %%cr0\n"
30688+#endif
30689+
30690 " jmp 2b\n"
30691 ".previous\n"
30692- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30693+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30694
30695 for (i = 0; i < (4096-320)/64; i++) {
30696 __asm__ __volatile__ (
30697- "1: prefetch 320(%0)\n"
30698- "2: movq (%0), %%mm0\n"
30699- " movntq %%mm0, (%1)\n"
30700- " movq 8(%0), %%mm1\n"
30701- " movntq %%mm1, 8(%1)\n"
30702- " movq 16(%0), %%mm2\n"
30703- " movntq %%mm2, 16(%1)\n"
30704- " movq 24(%0), %%mm3\n"
30705- " movntq %%mm3, 24(%1)\n"
30706- " movq 32(%0), %%mm4\n"
30707- " movntq %%mm4, 32(%1)\n"
30708- " movq 40(%0), %%mm5\n"
30709- " movntq %%mm5, 40(%1)\n"
30710- " movq 48(%0), %%mm6\n"
30711- " movntq %%mm6, 48(%1)\n"
30712- " movq 56(%0), %%mm7\n"
30713- " movntq %%mm7, 56(%1)\n"
30714+ "1: prefetch 320(%1)\n"
30715+ "2: movq (%1), %%mm0\n"
30716+ " movntq %%mm0, (%2)\n"
30717+ " movq 8(%1), %%mm1\n"
30718+ " movntq %%mm1, 8(%2)\n"
30719+ " movq 16(%1), %%mm2\n"
30720+ " movntq %%mm2, 16(%2)\n"
30721+ " movq 24(%1), %%mm3\n"
30722+ " movntq %%mm3, 24(%2)\n"
30723+ " movq 32(%1), %%mm4\n"
30724+ " movntq %%mm4, 32(%2)\n"
30725+ " movq 40(%1), %%mm5\n"
30726+ " movntq %%mm5, 40(%2)\n"
30727+ " movq 48(%1), %%mm6\n"
30728+ " movntq %%mm6, 48(%2)\n"
30729+ " movq 56(%1), %%mm7\n"
30730+ " movntq %%mm7, 56(%2)\n"
30731 ".section .fixup, \"ax\"\n"
30732- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30733+ "3:\n"
30734+
30735+#ifdef CONFIG_PAX_KERNEXEC
30736+ " movl %%cr0, %0\n"
30737+ " movl %0, %%eax\n"
30738+ " andl $0xFFFEFFFF, %%eax\n"
30739+ " movl %%eax, %%cr0\n"
30740+#endif
30741+
30742+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30743+
30744+#ifdef CONFIG_PAX_KERNEXEC
30745+ " movl %0, %%cr0\n"
30746+#endif
30747+
30748 " jmp 2b\n"
30749 ".previous\n"
30750- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30751+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30752
30753 from += 64;
30754 to += 64;
30755@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30756 static void fast_copy_page(void *to, void *from)
30757 {
30758 int i;
30759+ unsigned long cr0;
30760
30761 kernel_fpu_begin();
30762
30763 __asm__ __volatile__ (
30764- "1: prefetch (%0)\n"
30765- " prefetch 64(%0)\n"
30766- " prefetch 128(%0)\n"
30767- " prefetch 192(%0)\n"
30768- " prefetch 256(%0)\n"
30769+ "1: prefetch (%1)\n"
30770+ " prefetch 64(%1)\n"
30771+ " prefetch 128(%1)\n"
30772+ " prefetch 192(%1)\n"
30773+ " prefetch 256(%1)\n"
30774 "2: \n"
30775 ".section .fixup, \"ax\"\n"
30776- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30777+ "3: \n"
30778+
30779+#ifdef CONFIG_PAX_KERNEXEC
30780+ " movl %%cr0, %0\n"
30781+ " movl %0, %%eax\n"
30782+ " andl $0xFFFEFFFF, %%eax\n"
30783+ " movl %%eax, %%cr0\n"
30784+#endif
30785+
30786+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30787+
30788+#ifdef CONFIG_PAX_KERNEXEC
30789+ " movl %0, %%cr0\n"
30790+#endif
30791+
30792 " jmp 2b\n"
30793 ".previous\n"
30794- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30795+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30796
30797 for (i = 0; i < 4096/64; i++) {
30798 __asm__ __volatile__ (
30799- "1: prefetch 320(%0)\n"
30800- "2: movq (%0), %%mm0\n"
30801- " movq 8(%0), %%mm1\n"
30802- " movq 16(%0), %%mm2\n"
30803- " movq 24(%0), %%mm3\n"
30804- " movq %%mm0, (%1)\n"
30805- " movq %%mm1, 8(%1)\n"
30806- " movq %%mm2, 16(%1)\n"
30807- " movq %%mm3, 24(%1)\n"
30808- " movq 32(%0), %%mm0\n"
30809- " movq 40(%0), %%mm1\n"
30810- " movq 48(%0), %%mm2\n"
30811- " movq 56(%0), %%mm3\n"
30812- " movq %%mm0, 32(%1)\n"
30813- " movq %%mm1, 40(%1)\n"
30814- " movq %%mm2, 48(%1)\n"
30815- " movq %%mm3, 56(%1)\n"
30816+ "1: prefetch 320(%1)\n"
30817+ "2: movq (%1), %%mm0\n"
30818+ " movq 8(%1), %%mm1\n"
30819+ " movq 16(%1), %%mm2\n"
30820+ " movq 24(%1), %%mm3\n"
30821+ " movq %%mm0, (%2)\n"
30822+ " movq %%mm1, 8(%2)\n"
30823+ " movq %%mm2, 16(%2)\n"
30824+ " movq %%mm3, 24(%2)\n"
30825+ " movq 32(%1), %%mm0\n"
30826+ " movq 40(%1), %%mm1\n"
30827+ " movq 48(%1), %%mm2\n"
30828+ " movq 56(%1), %%mm3\n"
30829+ " movq %%mm0, 32(%2)\n"
30830+ " movq %%mm1, 40(%2)\n"
30831+ " movq %%mm2, 48(%2)\n"
30832+ " movq %%mm3, 56(%2)\n"
30833 ".section .fixup, \"ax\"\n"
30834- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30835+ "3:\n"
30836+
30837+#ifdef CONFIG_PAX_KERNEXEC
30838+ " movl %%cr0, %0\n"
30839+ " movl %0, %%eax\n"
30840+ " andl $0xFFFEFFFF, %%eax\n"
30841+ " movl %%eax, %%cr0\n"
30842+#endif
30843+
30844+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30845+
30846+#ifdef CONFIG_PAX_KERNEXEC
30847+ " movl %0, %%cr0\n"
30848+#endif
30849+
30850 " jmp 2b\n"
30851 ".previous\n"
30852 _ASM_EXTABLE(1b, 3b)
30853- : : "r" (from), "r" (to) : "memory");
30854+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30855
30856 from += 64;
30857 to += 64;
30858diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30859index f6d13ee..d789440 100644
30860--- a/arch/x86/lib/msr-reg.S
30861+++ b/arch/x86/lib/msr-reg.S
30862@@ -3,6 +3,7 @@
30863 #include <asm/dwarf2.h>
30864 #include <asm/asm.h>
30865 #include <asm/msr.h>
30866+#include <asm/alternative-asm.h>
30867
30868 #ifdef CONFIG_X86_64
30869 /*
30870@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30871 movl %edi, 28(%r10)
30872 popq_cfi %rbp
30873 popq_cfi %rbx
30874+ pax_force_retaddr
30875 ret
30876 3:
30877 CFI_RESTORE_STATE
30878diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30879index fc6ba17..d4d989d 100644
30880--- a/arch/x86/lib/putuser.S
30881+++ b/arch/x86/lib/putuser.S
30882@@ -16,7 +16,9 @@
30883 #include <asm/errno.h>
30884 #include <asm/asm.h>
30885 #include <asm/smap.h>
30886-
30887+#include <asm/segment.h>
30888+#include <asm/pgtable.h>
30889+#include <asm/alternative-asm.h>
30890
30891 /*
30892 * __put_user_X
30893@@ -30,57 +32,125 @@
30894 * as they get called from within inline assembly.
30895 */
30896
30897-#define ENTER CFI_STARTPROC ; \
30898- GET_THREAD_INFO(%_ASM_BX)
30899-#define EXIT ASM_CLAC ; \
30900- ret ; \
30901+#define ENTER CFI_STARTPROC
30902+#define EXIT ASM_CLAC ; \
30903+ pax_force_retaddr ; \
30904+ ret ; \
30905 CFI_ENDPROC
30906
30907+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30908+#define _DEST %_ASM_CX,%_ASM_BX
30909+#else
30910+#define _DEST %_ASM_CX
30911+#endif
30912+
30913+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30914+#define __copyuser_seg gs;
30915+#else
30916+#define __copyuser_seg
30917+#endif
30918+
30919 .text
30920 ENTRY(__put_user_1)
30921 ENTER
30922+
30923+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30924+ GET_THREAD_INFO(%_ASM_BX)
30925 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30926 jae bad_put_user
30927 ASM_STAC
30928-1: movb %al,(%_ASM_CX)
30929+
30930+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30931+ mov pax_user_shadow_base,%_ASM_BX
30932+ cmp %_ASM_BX,%_ASM_CX
30933+ jb 1234f
30934+ xor %ebx,%ebx
30935+1234:
30936+#endif
30937+
30938+#endif
30939+
30940+1: __copyuser_seg movb %al,(_DEST)
30941 xor %eax,%eax
30942 EXIT
30943 ENDPROC(__put_user_1)
30944
30945 ENTRY(__put_user_2)
30946 ENTER
30947+
30948+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30949+ GET_THREAD_INFO(%_ASM_BX)
30950 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30951 sub $1,%_ASM_BX
30952 cmp %_ASM_BX,%_ASM_CX
30953 jae bad_put_user
30954 ASM_STAC
30955-2: movw %ax,(%_ASM_CX)
30956+
30957+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30958+ mov pax_user_shadow_base,%_ASM_BX
30959+ cmp %_ASM_BX,%_ASM_CX
30960+ jb 1234f
30961+ xor %ebx,%ebx
30962+1234:
30963+#endif
30964+
30965+#endif
30966+
30967+2: __copyuser_seg movw %ax,(_DEST)
30968 xor %eax,%eax
30969 EXIT
30970 ENDPROC(__put_user_2)
30971
30972 ENTRY(__put_user_4)
30973 ENTER
30974+
30975+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30976+ GET_THREAD_INFO(%_ASM_BX)
30977 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30978 sub $3,%_ASM_BX
30979 cmp %_ASM_BX,%_ASM_CX
30980 jae bad_put_user
30981 ASM_STAC
30982-3: movl %eax,(%_ASM_CX)
30983+
30984+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30985+ mov pax_user_shadow_base,%_ASM_BX
30986+ cmp %_ASM_BX,%_ASM_CX
30987+ jb 1234f
30988+ xor %ebx,%ebx
30989+1234:
30990+#endif
30991+
30992+#endif
30993+
30994+3: __copyuser_seg movl %eax,(_DEST)
30995 xor %eax,%eax
30996 EXIT
30997 ENDPROC(__put_user_4)
30998
30999 ENTRY(__put_user_8)
31000 ENTER
31001+
31002+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31003+ GET_THREAD_INFO(%_ASM_BX)
31004 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31005 sub $7,%_ASM_BX
31006 cmp %_ASM_BX,%_ASM_CX
31007 jae bad_put_user
31008 ASM_STAC
31009-4: mov %_ASM_AX,(%_ASM_CX)
31010+
31011+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31012+ mov pax_user_shadow_base,%_ASM_BX
31013+ cmp %_ASM_BX,%_ASM_CX
31014+ jb 1234f
31015+ xor %ebx,%ebx
31016+1234:
31017+#endif
31018+
31019+#endif
31020+
31021+4: __copyuser_seg mov %_ASM_AX,(_DEST)
31022 #ifdef CONFIG_X86_32
31023-5: movl %edx,4(%_ASM_CX)
31024+5: __copyuser_seg movl %edx,4(_DEST)
31025 #endif
31026 xor %eax,%eax
31027 EXIT
31028diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
31029index 1cad221..de671ee 100644
31030--- a/arch/x86/lib/rwlock.S
31031+++ b/arch/x86/lib/rwlock.S
31032@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
31033 FRAME
31034 0: LOCK_PREFIX
31035 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31036+
31037+#ifdef CONFIG_PAX_REFCOUNT
31038+ jno 1234f
31039+ LOCK_PREFIX
31040+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31041+ int $4
31042+1234:
31043+ _ASM_EXTABLE(1234b, 1234b)
31044+#endif
31045+
31046 1: rep; nop
31047 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
31048 jne 1b
31049 LOCK_PREFIX
31050 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31051+
31052+#ifdef CONFIG_PAX_REFCOUNT
31053+ jno 1234f
31054+ LOCK_PREFIX
31055+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31056+ int $4
31057+1234:
31058+ _ASM_EXTABLE(1234b, 1234b)
31059+#endif
31060+
31061 jnz 0b
31062 ENDFRAME
31063+ pax_force_retaddr
31064 ret
31065 CFI_ENDPROC
31066 END(__write_lock_failed)
31067@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
31068 FRAME
31069 0: LOCK_PREFIX
31070 READ_LOCK_SIZE(inc) (%__lock_ptr)
31071+
31072+#ifdef CONFIG_PAX_REFCOUNT
31073+ jno 1234f
31074+ LOCK_PREFIX
31075+ READ_LOCK_SIZE(dec) (%__lock_ptr)
31076+ int $4
31077+1234:
31078+ _ASM_EXTABLE(1234b, 1234b)
31079+#endif
31080+
31081 1: rep; nop
31082 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
31083 js 1b
31084 LOCK_PREFIX
31085 READ_LOCK_SIZE(dec) (%__lock_ptr)
31086+
31087+#ifdef CONFIG_PAX_REFCOUNT
31088+ jno 1234f
31089+ LOCK_PREFIX
31090+ READ_LOCK_SIZE(inc) (%__lock_ptr)
31091+ int $4
31092+1234:
31093+ _ASM_EXTABLE(1234b, 1234b)
31094+#endif
31095+
31096 js 0b
31097 ENDFRAME
31098+ pax_force_retaddr
31099 ret
31100 CFI_ENDPROC
31101 END(__read_lock_failed)
31102diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
31103index 5dff5f0..cadebf4 100644
31104--- a/arch/x86/lib/rwsem.S
31105+++ b/arch/x86/lib/rwsem.S
31106@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
31107 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31108 CFI_RESTORE __ASM_REG(dx)
31109 restore_common_regs
31110+ pax_force_retaddr
31111 ret
31112 CFI_ENDPROC
31113 ENDPROC(call_rwsem_down_read_failed)
31114@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31115 movq %rax,%rdi
31116 call rwsem_down_write_failed
31117 restore_common_regs
31118+ pax_force_retaddr
31119 ret
31120 CFI_ENDPROC
31121 ENDPROC(call_rwsem_down_write_failed)
31122@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31123 movq %rax,%rdi
31124 call rwsem_wake
31125 restore_common_regs
31126-1: ret
31127+1: pax_force_retaddr
31128+ ret
31129 CFI_ENDPROC
31130 ENDPROC(call_rwsem_wake)
31131
31132@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31133 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31134 CFI_RESTORE __ASM_REG(dx)
31135 restore_common_regs
31136+ pax_force_retaddr
31137 ret
31138 CFI_ENDPROC
31139 ENDPROC(call_rwsem_downgrade_wake)
31140diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31141index 92d9fea..b2762c8 100644
31142--- a/arch/x86/lib/thunk_64.S
31143+++ b/arch/x86/lib/thunk_64.S
31144@@ -9,6 +9,7 @@
31145 #include <asm/dwarf2.h>
31146 #include <asm/calling.h>
31147 #include <asm/asm.h>
31148+#include <asm/alternative-asm.h>
31149
31150 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31151 .macro THUNK name, func, put_ret_addr_in_rdi=0
31152@@ -16,11 +17,11 @@
31153 \name:
31154 CFI_STARTPROC
31155
31156- /* this one pushes 9 elems, the next one would be %rIP */
31157- SAVE_ARGS
31158+ /* this one pushes 15+1 elems, the next one would be %rIP */
31159+ SAVE_ARGS 8
31160
31161 .if \put_ret_addr_in_rdi
31162- movq_cfi_restore 9*8, rdi
31163+ movq_cfi_restore RIP, rdi
31164 .endif
31165
31166 call \func
31167@@ -40,9 +41,10 @@
31168
31169 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31170 CFI_STARTPROC
31171- SAVE_ARGS
31172+ SAVE_ARGS 8
31173 restore:
31174- RESTORE_ARGS
31175+ RESTORE_ARGS 1,8
31176+ pax_force_retaddr
31177 ret
31178 CFI_ENDPROC
31179 _ASM_NOKPROBE(restore)
31180diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31181index e2f5e21..4b22130 100644
31182--- a/arch/x86/lib/usercopy_32.c
31183+++ b/arch/x86/lib/usercopy_32.c
31184@@ -42,11 +42,13 @@ do { \
31185 int __d0; \
31186 might_fault(); \
31187 __asm__ __volatile__( \
31188+ __COPYUSER_SET_ES \
31189 ASM_STAC "\n" \
31190 "0: rep; stosl\n" \
31191 " movl %2,%0\n" \
31192 "1: rep; stosb\n" \
31193 "2: " ASM_CLAC "\n" \
31194+ __COPYUSER_RESTORE_ES \
31195 ".section .fixup,\"ax\"\n" \
31196 "3: lea 0(%2,%0,4),%0\n" \
31197 " jmp 2b\n" \
31198@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31199
31200 #ifdef CONFIG_X86_INTEL_USERCOPY
31201 static unsigned long
31202-__copy_user_intel(void __user *to, const void *from, unsigned long size)
31203+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31204 {
31205 int d0, d1;
31206 __asm__ __volatile__(
31207@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31208 " .align 2,0x90\n"
31209 "3: movl 0(%4), %%eax\n"
31210 "4: movl 4(%4), %%edx\n"
31211- "5: movl %%eax, 0(%3)\n"
31212- "6: movl %%edx, 4(%3)\n"
31213+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31214+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31215 "7: movl 8(%4), %%eax\n"
31216 "8: movl 12(%4),%%edx\n"
31217- "9: movl %%eax, 8(%3)\n"
31218- "10: movl %%edx, 12(%3)\n"
31219+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31220+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31221 "11: movl 16(%4), %%eax\n"
31222 "12: movl 20(%4), %%edx\n"
31223- "13: movl %%eax, 16(%3)\n"
31224- "14: movl %%edx, 20(%3)\n"
31225+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31226+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31227 "15: movl 24(%4), %%eax\n"
31228 "16: movl 28(%4), %%edx\n"
31229- "17: movl %%eax, 24(%3)\n"
31230- "18: movl %%edx, 28(%3)\n"
31231+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31232+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31233 "19: movl 32(%4), %%eax\n"
31234 "20: movl 36(%4), %%edx\n"
31235- "21: movl %%eax, 32(%3)\n"
31236- "22: movl %%edx, 36(%3)\n"
31237+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31238+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31239 "23: movl 40(%4), %%eax\n"
31240 "24: movl 44(%4), %%edx\n"
31241- "25: movl %%eax, 40(%3)\n"
31242- "26: movl %%edx, 44(%3)\n"
31243+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31244+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31245 "27: movl 48(%4), %%eax\n"
31246 "28: movl 52(%4), %%edx\n"
31247- "29: movl %%eax, 48(%3)\n"
31248- "30: movl %%edx, 52(%3)\n"
31249+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31250+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31251 "31: movl 56(%4), %%eax\n"
31252 "32: movl 60(%4), %%edx\n"
31253- "33: movl %%eax, 56(%3)\n"
31254- "34: movl %%edx, 60(%3)\n"
31255+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31256+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31257 " addl $-64, %0\n"
31258 " addl $64, %4\n"
31259 " addl $64, %3\n"
31260@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31261 " shrl $2, %0\n"
31262 " andl $3, %%eax\n"
31263 " cld\n"
31264+ __COPYUSER_SET_ES
31265 "99: rep; movsl\n"
31266 "36: movl %%eax, %0\n"
31267 "37: rep; movsb\n"
31268 "100:\n"
31269+ __COPYUSER_RESTORE_ES
31270+ ".section .fixup,\"ax\"\n"
31271+ "101: lea 0(%%eax,%0,4),%0\n"
31272+ " jmp 100b\n"
31273+ ".previous\n"
31274+ _ASM_EXTABLE(1b,100b)
31275+ _ASM_EXTABLE(2b,100b)
31276+ _ASM_EXTABLE(3b,100b)
31277+ _ASM_EXTABLE(4b,100b)
31278+ _ASM_EXTABLE(5b,100b)
31279+ _ASM_EXTABLE(6b,100b)
31280+ _ASM_EXTABLE(7b,100b)
31281+ _ASM_EXTABLE(8b,100b)
31282+ _ASM_EXTABLE(9b,100b)
31283+ _ASM_EXTABLE(10b,100b)
31284+ _ASM_EXTABLE(11b,100b)
31285+ _ASM_EXTABLE(12b,100b)
31286+ _ASM_EXTABLE(13b,100b)
31287+ _ASM_EXTABLE(14b,100b)
31288+ _ASM_EXTABLE(15b,100b)
31289+ _ASM_EXTABLE(16b,100b)
31290+ _ASM_EXTABLE(17b,100b)
31291+ _ASM_EXTABLE(18b,100b)
31292+ _ASM_EXTABLE(19b,100b)
31293+ _ASM_EXTABLE(20b,100b)
31294+ _ASM_EXTABLE(21b,100b)
31295+ _ASM_EXTABLE(22b,100b)
31296+ _ASM_EXTABLE(23b,100b)
31297+ _ASM_EXTABLE(24b,100b)
31298+ _ASM_EXTABLE(25b,100b)
31299+ _ASM_EXTABLE(26b,100b)
31300+ _ASM_EXTABLE(27b,100b)
31301+ _ASM_EXTABLE(28b,100b)
31302+ _ASM_EXTABLE(29b,100b)
31303+ _ASM_EXTABLE(30b,100b)
31304+ _ASM_EXTABLE(31b,100b)
31305+ _ASM_EXTABLE(32b,100b)
31306+ _ASM_EXTABLE(33b,100b)
31307+ _ASM_EXTABLE(34b,100b)
31308+ _ASM_EXTABLE(35b,100b)
31309+ _ASM_EXTABLE(36b,100b)
31310+ _ASM_EXTABLE(37b,100b)
31311+ _ASM_EXTABLE(99b,101b)
31312+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
31313+ : "1"(to), "2"(from), "0"(size)
31314+ : "eax", "edx", "memory");
31315+ return size;
31316+}
31317+
31318+static unsigned long
31319+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31320+{
31321+ int d0, d1;
31322+ __asm__ __volatile__(
31323+ " .align 2,0x90\n"
31324+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31325+ " cmpl $67, %0\n"
31326+ " jbe 3f\n"
31327+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31328+ " .align 2,0x90\n"
31329+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31330+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31331+ "5: movl %%eax, 0(%3)\n"
31332+ "6: movl %%edx, 4(%3)\n"
31333+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31334+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31335+ "9: movl %%eax, 8(%3)\n"
31336+ "10: movl %%edx, 12(%3)\n"
31337+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31338+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31339+ "13: movl %%eax, 16(%3)\n"
31340+ "14: movl %%edx, 20(%3)\n"
31341+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31342+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31343+ "17: movl %%eax, 24(%3)\n"
31344+ "18: movl %%edx, 28(%3)\n"
31345+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31346+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31347+ "21: movl %%eax, 32(%3)\n"
31348+ "22: movl %%edx, 36(%3)\n"
31349+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31350+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31351+ "25: movl %%eax, 40(%3)\n"
31352+ "26: movl %%edx, 44(%3)\n"
31353+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31354+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31355+ "29: movl %%eax, 48(%3)\n"
31356+ "30: movl %%edx, 52(%3)\n"
31357+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31358+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31359+ "33: movl %%eax, 56(%3)\n"
31360+ "34: movl %%edx, 60(%3)\n"
31361+ " addl $-64, %0\n"
31362+ " addl $64, %4\n"
31363+ " addl $64, %3\n"
31364+ " cmpl $63, %0\n"
31365+ " ja 1b\n"
31366+ "35: movl %0, %%eax\n"
31367+ " shrl $2, %0\n"
31368+ " andl $3, %%eax\n"
31369+ " cld\n"
31370+ "99: rep; "__copyuser_seg" movsl\n"
31371+ "36: movl %%eax, %0\n"
31372+ "37: rep; "__copyuser_seg" movsb\n"
31373+ "100:\n"
31374 ".section .fixup,\"ax\"\n"
31375 "101: lea 0(%%eax,%0,4),%0\n"
31376 " jmp 100b\n"
31377@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31378 int d0, d1;
31379 __asm__ __volatile__(
31380 " .align 2,0x90\n"
31381- "0: movl 32(%4), %%eax\n"
31382+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31383 " cmpl $67, %0\n"
31384 " jbe 2f\n"
31385- "1: movl 64(%4), %%eax\n"
31386+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31387 " .align 2,0x90\n"
31388- "2: movl 0(%4), %%eax\n"
31389- "21: movl 4(%4), %%edx\n"
31390+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31391+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31392 " movl %%eax, 0(%3)\n"
31393 " movl %%edx, 4(%3)\n"
31394- "3: movl 8(%4), %%eax\n"
31395- "31: movl 12(%4),%%edx\n"
31396+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31397+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31398 " movl %%eax, 8(%3)\n"
31399 " movl %%edx, 12(%3)\n"
31400- "4: movl 16(%4), %%eax\n"
31401- "41: movl 20(%4), %%edx\n"
31402+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31403+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31404 " movl %%eax, 16(%3)\n"
31405 " movl %%edx, 20(%3)\n"
31406- "10: movl 24(%4), %%eax\n"
31407- "51: movl 28(%4), %%edx\n"
31408+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31409+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31410 " movl %%eax, 24(%3)\n"
31411 " movl %%edx, 28(%3)\n"
31412- "11: movl 32(%4), %%eax\n"
31413- "61: movl 36(%4), %%edx\n"
31414+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31415+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31416 " movl %%eax, 32(%3)\n"
31417 " movl %%edx, 36(%3)\n"
31418- "12: movl 40(%4), %%eax\n"
31419- "71: movl 44(%4), %%edx\n"
31420+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31421+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31422 " movl %%eax, 40(%3)\n"
31423 " movl %%edx, 44(%3)\n"
31424- "13: movl 48(%4), %%eax\n"
31425- "81: movl 52(%4), %%edx\n"
31426+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31427+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31428 " movl %%eax, 48(%3)\n"
31429 " movl %%edx, 52(%3)\n"
31430- "14: movl 56(%4), %%eax\n"
31431- "91: movl 60(%4), %%edx\n"
31432+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31433+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31434 " movl %%eax, 56(%3)\n"
31435 " movl %%edx, 60(%3)\n"
31436 " addl $-64, %0\n"
31437@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31438 " shrl $2, %0\n"
31439 " andl $3, %%eax\n"
31440 " cld\n"
31441- "6: rep; movsl\n"
31442+ "6: rep; "__copyuser_seg" movsl\n"
31443 " movl %%eax,%0\n"
31444- "7: rep; movsb\n"
31445+ "7: rep; "__copyuser_seg" movsb\n"
31446 "8:\n"
31447 ".section .fixup,\"ax\"\n"
31448 "9: lea 0(%%eax,%0,4),%0\n"
31449@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31450
31451 __asm__ __volatile__(
31452 " .align 2,0x90\n"
31453- "0: movl 32(%4), %%eax\n"
31454+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31455 " cmpl $67, %0\n"
31456 " jbe 2f\n"
31457- "1: movl 64(%4), %%eax\n"
31458+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31459 " .align 2,0x90\n"
31460- "2: movl 0(%4), %%eax\n"
31461- "21: movl 4(%4), %%edx\n"
31462+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31463+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31464 " movnti %%eax, 0(%3)\n"
31465 " movnti %%edx, 4(%3)\n"
31466- "3: movl 8(%4), %%eax\n"
31467- "31: movl 12(%4),%%edx\n"
31468+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31469+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31470 " movnti %%eax, 8(%3)\n"
31471 " movnti %%edx, 12(%3)\n"
31472- "4: movl 16(%4), %%eax\n"
31473- "41: movl 20(%4), %%edx\n"
31474+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31475+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31476 " movnti %%eax, 16(%3)\n"
31477 " movnti %%edx, 20(%3)\n"
31478- "10: movl 24(%4), %%eax\n"
31479- "51: movl 28(%4), %%edx\n"
31480+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31481+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31482 " movnti %%eax, 24(%3)\n"
31483 " movnti %%edx, 28(%3)\n"
31484- "11: movl 32(%4), %%eax\n"
31485- "61: movl 36(%4), %%edx\n"
31486+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31487+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31488 " movnti %%eax, 32(%3)\n"
31489 " movnti %%edx, 36(%3)\n"
31490- "12: movl 40(%4), %%eax\n"
31491- "71: movl 44(%4), %%edx\n"
31492+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31493+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31494 " movnti %%eax, 40(%3)\n"
31495 " movnti %%edx, 44(%3)\n"
31496- "13: movl 48(%4), %%eax\n"
31497- "81: movl 52(%4), %%edx\n"
31498+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31499+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31500 " movnti %%eax, 48(%3)\n"
31501 " movnti %%edx, 52(%3)\n"
31502- "14: movl 56(%4), %%eax\n"
31503- "91: movl 60(%4), %%edx\n"
31504+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31505+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31506 " movnti %%eax, 56(%3)\n"
31507 " movnti %%edx, 60(%3)\n"
31508 " addl $-64, %0\n"
31509@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31510 " shrl $2, %0\n"
31511 " andl $3, %%eax\n"
31512 " cld\n"
31513- "6: rep; movsl\n"
31514+ "6: rep; "__copyuser_seg" movsl\n"
31515 " movl %%eax,%0\n"
31516- "7: rep; movsb\n"
31517+ "7: rep; "__copyuser_seg" movsb\n"
31518 "8:\n"
31519 ".section .fixup,\"ax\"\n"
31520 "9: lea 0(%%eax,%0,4),%0\n"
31521@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31522
31523 __asm__ __volatile__(
31524 " .align 2,0x90\n"
31525- "0: movl 32(%4), %%eax\n"
31526+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31527 " cmpl $67, %0\n"
31528 " jbe 2f\n"
31529- "1: movl 64(%4), %%eax\n"
31530+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31531 " .align 2,0x90\n"
31532- "2: movl 0(%4), %%eax\n"
31533- "21: movl 4(%4), %%edx\n"
31534+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31535+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31536 " movnti %%eax, 0(%3)\n"
31537 " movnti %%edx, 4(%3)\n"
31538- "3: movl 8(%4), %%eax\n"
31539- "31: movl 12(%4),%%edx\n"
31540+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31541+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31542 " movnti %%eax, 8(%3)\n"
31543 " movnti %%edx, 12(%3)\n"
31544- "4: movl 16(%4), %%eax\n"
31545- "41: movl 20(%4), %%edx\n"
31546+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31547+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31548 " movnti %%eax, 16(%3)\n"
31549 " movnti %%edx, 20(%3)\n"
31550- "10: movl 24(%4), %%eax\n"
31551- "51: movl 28(%4), %%edx\n"
31552+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31553+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31554 " movnti %%eax, 24(%3)\n"
31555 " movnti %%edx, 28(%3)\n"
31556- "11: movl 32(%4), %%eax\n"
31557- "61: movl 36(%4), %%edx\n"
31558+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31559+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31560 " movnti %%eax, 32(%3)\n"
31561 " movnti %%edx, 36(%3)\n"
31562- "12: movl 40(%4), %%eax\n"
31563- "71: movl 44(%4), %%edx\n"
31564+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31565+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31566 " movnti %%eax, 40(%3)\n"
31567 " movnti %%edx, 44(%3)\n"
31568- "13: movl 48(%4), %%eax\n"
31569- "81: movl 52(%4), %%edx\n"
31570+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31571+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31572 " movnti %%eax, 48(%3)\n"
31573 " movnti %%edx, 52(%3)\n"
31574- "14: movl 56(%4), %%eax\n"
31575- "91: movl 60(%4), %%edx\n"
31576+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31577+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31578 " movnti %%eax, 56(%3)\n"
31579 " movnti %%edx, 60(%3)\n"
31580 " addl $-64, %0\n"
31581@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31582 " shrl $2, %0\n"
31583 " andl $3, %%eax\n"
31584 " cld\n"
31585- "6: rep; movsl\n"
31586+ "6: rep; "__copyuser_seg" movsl\n"
31587 " movl %%eax,%0\n"
31588- "7: rep; movsb\n"
31589+ "7: rep; "__copyuser_seg" movsb\n"
31590 "8:\n"
31591 ".section .fixup,\"ax\"\n"
31592 "9: lea 0(%%eax,%0,4),%0\n"
31593@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31594 */
31595 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31596 unsigned long size);
31597-unsigned long __copy_user_intel(void __user *to, const void *from,
31598+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31599+ unsigned long size);
31600+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31601 unsigned long size);
31602 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31603 const void __user *from, unsigned long size);
31604 #endif /* CONFIG_X86_INTEL_USERCOPY */
31605
31606 /* Generic arbitrary sized copy. */
31607-#define __copy_user(to, from, size) \
31608+#define __copy_user(to, from, size, prefix, set, restore) \
31609 do { \
31610 int __d0, __d1, __d2; \
31611 __asm__ __volatile__( \
31612+ set \
31613 " cmp $7,%0\n" \
31614 " jbe 1f\n" \
31615 " movl %1,%0\n" \
31616 " negl %0\n" \
31617 " andl $7,%0\n" \
31618 " subl %0,%3\n" \
31619- "4: rep; movsb\n" \
31620+ "4: rep; "prefix"movsb\n" \
31621 " movl %3,%0\n" \
31622 " shrl $2,%0\n" \
31623 " andl $3,%3\n" \
31624 " .align 2,0x90\n" \
31625- "0: rep; movsl\n" \
31626+ "0: rep; "prefix"movsl\n" \
31627 " movl %3,%0\n" \
31628- "1: rep; movsb\n" \
31629+ "1: rep; "prefix"movsb\n" \
31630 "2:\n" \
31631+ restore \
31632 ".section .fixup,\"ax\"\n" \
31633 "5: addl %3,%0\n" \
31634 " jmp 2b\n" \
31635@@ -538,14 +650,14 @@ do { \
31636 " negl %0\n" \
31637 " andl $7,%0\n" \
31638 " subl %0,%3\n" \
31639- "4: rep; movsb\n" \
31640+ "4: rep; "__copyuser_seg"movsb\n" \
31641 " movl %3,%0\n" \
31642 " shrl $2,%0\n" \
31643 " andl $3,%3\n" \
31644 " .align 2,0x90\n" \
31645- "0: rep; movsl\n" \
31646+ "0: rep; "__copyuser_seg"movsl\n" \
31647 " movl %3,%0\n" \
31648- "1: rep; movsb\n" \
31649+ "1: rep; "__copyuser_seg"movsb\n" \
31650 "2:\n" \
31651 ".section .fixup,\"ax\"\n" \
31652 "5: addl %3,%0\n" \
31653@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31654 {
31655 stac();
31656 if (movsl_is_ok(to, from, n))
31657- __copy_user(to, from, n);
31658+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31659 else
31660- n = __copy_user_intel(to, from, n);
31661+ n = __generic_copy_to_user_intel(to, from, n);
31662 clac();
31663 return n;
31664 }
31665@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31666 {
31667 stac();
31668 if (movsl_is_ok(to, from, n))
31669- __copy_user(to, from, n);
31670+ __copy_user(to, from, n, __copyuser_seg, "", "");
31671 else
31672- n = __copy_user_intel((void __user *)to,
31673- (const void *)from, n);
31674+ n = __generic_copy_from_user_intel(to, from, n);
31675 clac();
31676 return n;
31677 }
31678@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31679 if (n > 64 && cpu_has_xmm2)
31680 n = __copy_user_intel_nocache(to, from, n);
31681 else
31682- __copy_user(to, from, n);
31683+ __copy_user(to, from, n, __copyuser_seg, "", "");
31684 #else
31685- __copy_user(to, from, n);
31686+ __copy_user(to, from, n, __copyuser_seg, "", "");
31687 #endif
31688 clac();
31689 return n;
31690 }
31691 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31692
31693-/**
31694- * copy_to_user: - Copy a block of data into user space.
31695- * @to: Destination address, in user space.
31696- * @from: Source address, in kernel space.
31697- * @n: Number of bytes to copy.
31698- *
31699- * Context: User context only. This function may sleep.
31700- *
31701- * Copy data from kernel space to user space.
31702- *
31703- * Returns number of bytes that could not be copied.
31704- * On success, this will be zero.
31705- */
31706-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31707+#ifdef CONFIG_PAX_MEMORY_UDEREF
31708+void __set_fs(mm_segment_t x)
31709 {
31710- if (access_ok(VERIFY_WRITE, to, n))
31711- n = __copy_to_user(to, from, n);
31712- return n;
31713+ switch (x.seg) {
31714+ case 0:
31715+ loadsegment(gs, 0);
31716+ break;
31717+ case TASK_SIZE_MAX:
31718+ loadsegment(gs, __USER_DS);
31719+ break;
31720+ case -1UL:
31721+ loadsegment(gs, __KERNEL_DS);
31722+ break;
31723+ default:
31724+ BUG();
31725+ }
31726 }
31727-EXPORT_SYMBOL(_copy_to_user);
31728+EXPORT_SYMBOL(__set_fs);
31729
31730-/**
31731- * copy_from_user: - Copy a block of data from user space.
31732- * @to: Destination address, in kernel space.
31733- * @from: Source address, in user space.
31734- * @n: Number of bytes to copy.
31735- *
31736- * Context: User context only. This function may sleep.
31737- *
31738- * Copy data from user space to kernel space.
31739- *
31740- * Returns number of bytes that could not be copied.
31741- * On success, this will be zero.
31742- *
31743- * If some data could not be copied, this function will pad the copied
31744- * data to the requested size using zero bytes.
31745- */
31746-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31747+void set_fs(mm_segment_t x)
31748 {
31749- if (access_ok(VERIFY_READ, from, n))
31750- n = __copy_from_user(to, from, n);
31751- else
31752- memset(to, 0, n);
31753- return n;
31754+ current_thread_info()->addr_limit = x;
31755+ __set_fs(x);
31756 }
31757-EXPORT_SYMBOL(_copy_from_user);
31758+EXPORT_SYMBOL(set_fs);
31759+#endif
31760diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31761index c905e89..01ab928 100644
31762--- a/arch/x86/lib/usercopy_64.c
31763+++ b/arch/x86/lib/usercopy_64.c
31764@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31765 might_fault();
31766 /* no memory constraint because it doesn't change any memory gcc knows
31767 about */
31768+ pax_open_userland();
31769 stac();
31770 asm volatile(
31771 " testq %[size8],%[size8]\n"
31772@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31773 _ASM_EXTABLE(0b,3b)
31774 _ASM_EXTABLE(1b,2b)
31775 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31776- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31777+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31778 [zero] "r" (0UL), [eight] "r" (8UL));
31779 clac();
31780+ pax_close_userland();
31781 return size;
31782 }
31783 EXPORT_SYMBOL(__clear_user);
31784@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31785 }
31786 EXPORT_SYMBOL(clear_user);
31787
31788-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31789+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31790 {
31791- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31792- return copy_user_generic((__force void *)to, (__force void *)from, len);
31793- }
31794- return len;
31795+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31796+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31797+ return len;
31798 }
31799 EXPORT_SYMBOL(copy_in_user);
31800
31801@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31802 * it is not necessary to optimize tail handling.
31803 */
31804 __visible unsigned long
31805-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31806+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31807 {
31808 char c;
31809 unsigned zero_len;
31810
31811+ clac();
31812+ pax_close_userland();
31813 for (; len; --len, to++) {
31814 if (__get_user_nocheck(c, from++, sizeof(char)))
31815 break;
31816@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31817 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31818 if (__put_user_nocheck(c, to++, sizeof(char)))
31819 break;
31820- clac();
31821 return len;
31822 }
31823diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31824index 6a19ad9..1c48f9a 100644
31825--- a/arch/x86/mm/Makefile
31826+++ b/arch/x86/mm/Makefile
31827@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31828 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31829
31830 obj-$(CONFIG_MEMTEST) += memtest.o
31831+
31832+quote:="
31833+obj-$(CONFIG_X86_64) += uderef_64.o
31834+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31835diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31836index 903ec1e..c4166b2 100644
31837--- a/arch/x86/mm/extable.c
31838+++ b/arch/x86/mm/extable.c
31839@@ -6,12 +6,24 @@
31840 static inline unsigned long
31841 ex_insn_addr(const struct exception_table_entry *x)
31842 {
31843- return (unsigned long)&x->insn + x->insn;
31844+ unsigned long reloc = 0;
31845+
31846+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31847+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31848+#endif
31849+
31850+ return (unsigned long)&x->insn + x->insn + reloc;
31851 }
31852 static inline unsigned long
31853 ex_fixup_addr(const struct exception_table_entry *x)
31854 {
31855- return (unsigned long)&x->fixup + x->fixup;
31856+ unsigned long reloc = 0;
31857+
31858+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31859+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31860+#endif
31861+
31862+ return (unsigned long)&x->fixup + x->fixup + reloc;
31863 }
31864
31865 int fixup_exception(struct pt_regs *regs)
31866@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31867 unsigned long new_ip;
31868
31869 #ifdef CONFIG_PNPBIOS
31870- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31871+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31872 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31873 extern u32 pnp_bios_is_utter_crap;
31874 pnp_bios_is_utter_crap = 1;
31875@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31876 i += 4;
31877 p->fixup -= i;
31878 i += 4;
31879+
31880+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31881+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31882+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31883+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31884+#endif
31885+
31886 }
31887 }
31888
31889diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31890index 3664279..c6a7830 100644
31891--- a/arch/x86/mm/fault.c
31892+++ b/arch/x86/mm/fault.c
31893@@ -14,12 +14,19 @@
31894 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31895 #include <linux/prefetch.h> /* prefetchw */
31896 #include <linux/context_tracking.h> /* exception_enter(), ... */
31897+#include <linux/unistd.h>
31898+#include <linux/compiler.h>
31899
31900 #include <asm/traps.h> /* dotraplinkage, ... */
31901 #include <asm/pgalloc.h> /* pgd_*(), ... */
31902 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31903 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
31904 #include <asm/vsyscall.h> /* emulate_vsyscall */
31905+#include <asm/tlbflush.h>
31906+
31907+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31908+#include <asm/stacktrace.h>
31909+#endif
31910
31911 #define CREATE_TRACE_POINTS
31912 #include <asm/trace/exceptions.h>
31913@@ -60,7 +67,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
31914 int ret = 0;
31915
31916 /* kprobe_running() needs smp_processor_id() */
31917- if (kprobes_built_in() && !user_mode_vm(regs)) {
31918+ if (kprobes_built_in() && !user_mode(regs)) {
31919 preempt_disable();
31920 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31921 ret = 1;
31922@@ -121,7 +128,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31923 return !instr_lo || (instr_lo>>1) == 1;
31924 case 0x00:
31925 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31926- if (probe_kernel_address(instr, opcode))
31927+ if (user_mode(regs)) {
31928+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31929+ return 0;
31930+ } else if (probe_kernel_address(instr, opcode))
31931 return 0;
31932
31933 *prefetch = (instr_lo == 0xF) &&
31934@@ -155,7 +165,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31935 while (instr < max_instr) {
31936 unsigned char opcode;
31937
31938- if (probe_kernel_address(instr, opcode))
31939+ if (user_mode(regs)) {
31940+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31941+ break;
31942+ } else if (probe_kernel_address(instr, opcode))
31943 break;
31944
31945 instr++;
31946@@ -186,6 +199,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31947 force_sig_info(si_signo, &info, tsk);
31948 }
31949
31950+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31951+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31952+#endif
31953+
31954+#ifdef CONFIG_PAX_EMUTRAMP
31955+static int pax_handle_fetch_fault(struct pt_regs *regs);
31956+#endif
31957+
31958+#ifdef CONFIG_PAX_PAGEEXEC
31959+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31960+{
31961+ pgd_t *pgd;
31962+ pud_t *pud;
31963+ pmd_t *pmd;
31964+
31965+ pgd = pgd_offset(mm, address);
31966+ if (!pgd_present(*pgd))
31967+ return NULL;
31968+ pud = pud_offset(pgd, address);
31969+ if (!pud_present(*pud))
31970+ return NULL;
31971+ pmd = pmd_offset(pud, address);
31972+ if (!pmd_present(*pmd))
31973+ return NULL;
31974+ return pmd;
31975+}
31976+#endif
31977+
31978 DEFINE_SPINLOCK(pgd_lock);
31979 LIST_HEAD(pgd_list);
31980
31981@@ -236,10 +277,27 @@ void vmalloc_sync_all(void)
31982 for (address = VMALLOC_START & PMD_MASK;
31983 address >= TASK_SIZE && address < FIXADDR_TOP;
31984 address += PMD_SIZE) {
31985+
31986+#ifdef CONFIG_PAX_PER_CPU_PGD
31987+ unsigned long cpu;
31988+#else
31989 struct page *page;
31990+#endif
31991
31992 spin_lock(&pgd_lock);
31993+
31994+#ifdef CONFIG_PAX_PER_CPU_PGD
31995+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31996+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31997+ pmd_t *ret;
31998+
31999+ ret = vmalloc_sync_one(pgd, address);
32000+ if (!ret)
32001+ break;
32002+ pgd = get_cpu_pgd(cpu, kernel);
32003+#else
32004 list_for_each_entry(page, &pgd_list, lru) {
32005+ pgd_t *pgd;
32006 spinlock_t *pgt_lock;
32007 pmd_t *ret;
32008
32009@@ -247,8 +305,14 @@ void vmalloc_sync_all(void)
32010 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32011
32012 spin_lock(pgt_lock);
32013- ret = vmalloc_sync_one(page_address(page), address);
32014+ pgd = page_address(page);
32015+#endif
32016+
32017+ ret = vmalloc_sync_one(pgd, address);
32018+
32019+#ifndef CONFIG_PAX_PER_CPU_PGD
32020 spin_unlock(pgt_lock);
32021+#endif
32022
32023 if (!ret)
32024 break;
32025@@ -282,6 +346,12 @@ static noinline int vmalloc_fault(unsigned long address)
32026 * an interrupt in the middle of a task switch..
32027 */
32028 pgd_paddr = read_cr3();
32029+
32030+#ifdef CONFIG_PAX_PER_CPU_PGD
32031+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
32032+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
32033+#endif
32034+
32035 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
32036 if (!pmd_k)
32037 return -1;
32038@@ -378,11 +448,25 @@ static noinline int vmalloc_fault(unsigned long address)
32039 * happen within a race in page table update. In the later
32040 * case just flush:
32041 */
32042- pgd = pgd_offset(current->active_mm, address);
32043+
32044 pgd_ref = pgd_offset_k(address);
32045 if (pgd_none(*pgd_ref))
32046 return -1;
32047
32048+#ifdef CONFIG_PAX_PER_CPU_PGD
32049+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
32050+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
32051+ if (pgd_none(*pgd)) {
32052+ set_pgd(pgd, *pgd_ref);
32053+ arch_flush_lazy_mmu_mode();
32054+ } else {
32055+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
32056+ }
32057+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
32058+#else
32059+ pgd = pgd_offset(current->active_mm, address);
32060+#endif
32061+
32062 if (pgd_none(*pgd)) {
32063 set_pgd(pgd, *pgd_ref);
32064 arch_flush_lazy_mmu_mode();
32065@@ -549,7 +633,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
32066 static int is_errata100(struct pt_regs *regs, unsigned long address)
32067 {
32068 #ifdef CONFIG_X86_64
32069- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
32070+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
32071 return 1;
32072 #endif
32073 return 0;
32074@@ -576,7 +660,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
32075 }
32076
32077 static const char nx_warning[] = KERN_CRIT
32078-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
32079+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
32080
32081 static void
32082 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32083@@ -585,7 +669,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32084 if (!oops_may_print())
32085 return;
32086
32087- if (error_code & PF_INSTR) {
32088+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
32089 unsigned int level;
32090 pgd_t *pgd;
32091 pte_t *pte;
32092@@ -596,9 +680,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32093 pte = lookup_address_in_pgd(pgd, address, &level);
32094
32095 if (pte && pte_present(*pte) && !pte_exec(*pte))
32096- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
32097+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32098 }
32099
32100+#ifdef CONFIG_PAX_KERNEXEC
32101+ if (init_mm.start_code <= address && address < init_mm.end_code) {
32102+ if (current->signal->curr_ip)
32103+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32104+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
32105+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32106+ else
32107+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32108+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32109+ }
32110+#endif
32111+
32112 printk(KERN_ALERT "BUG: unable to handle kernel ");
32113 if (address < PAGE_SIZE)
32114 printk(KERN_CONT "NULL pointer dereference");
32115@@ -779,6 +875,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32116 return;
32117 }
32118 #endif
32119+
32120+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32121+ if (pax_is_fetch_fault(regs, error_code, address)) {
32122+
32123+#ifdef CONFIG_PAX_EMUTRAMP
32124+ switch (pax_handle_fetch_fault(regs)) {
32125+ case 2:
32126+ return;
32127+ }
32128+#endif
32129+
32130+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32131+ do_group_exit(SIGKILL);
32132+ }
32133+#endif
32134+
32135 /* Kernel addresses are always protection faults: */
32136 if (address >= TASK_SIZE)
32137 error_code |= PF_PROT;
32138@@ -864,7 +976,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32139 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32140 printk(KERN_ERR
32141 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32142- tsk->comm, tsk->pid, address);
32143+ tsk->comm, task_pid_nr(tsk), address);
32144 code = BUS_MCEERR_AR;
32145 }
32146 #endif
32147@@ -918,6 +1030,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32148 return 1;
32149 }
32150
32151+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32152+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32153+{
32154+ pte_t *pte;
32155+ pmd_t *pmd;
32156+ spinlock_t *ptl;
32157+ unsigned char pte_mask;
32158+
32159+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32160+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
32161+ return 0;
32162+
32163+ /* PaX: it's our fault, let's handle it if we can */
32164+
32165+ /* PaX: take a look at read faults before acquiring any locks */
32166+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32167+ /* instruction fetch attempt from a protected page in user mode */
32168+ up_read(&mm->mmap_sem);
32169+
32170+#ifdef CONFIG_PAX_EMUTRAMP
32171+ switch (pax_handle_fetch_fault(regs)) {
32172+ case 2:
32173+ return 1;
32174+ }
32175+#endif
32176+
32177+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32178+ do_group_exit(SIGKILL);
32179+ }
32180+
32181+ pmd = pax_get_pmd(mm, address);
32182+ if (unlikely(!pmd))
32183+ return 0;
32184+
32185+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32186+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32187+ pte_unmap_unlock(pte, ptl);
32188+ return 0;
32189+ }
32190+
32191+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32192+ /* write attempt to a protected page in user mode */
32193+ pte_unmap_unlock(pte, ptl);
32194+ return 0;
32195+ }
32196+
32197+#ifdef CONFIG_SMP
32198+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32199+#else
32200+ if (likely(address > get_limit(regs->cs)))
32201+#endif
32202+ {
32203+ set_pte(pte, pte_mkread(*pte));
32204+ __flush_tlb_one(address);
32205+ pte_unmap_unlock(pte, ptl);
32206+ up_read(&mm->mmap_sem);
32207+ return 1;
32208+ }
32209+
32210+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32211+
32212+ /*
32213+ * PaX: fill DTLB with user rights and retry
32214+ */
32215+ __asm__ __volatile__ (
32216+ "orb %2,(%1)\n"
32217+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32218+/*
32219+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32220+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32221+ * page fault when examined during a TLB load attempt. this is true not only
32222+ * for PTEs holding a non-present entry but also present entries that will
32223+ * raise a page fault (such as those set up by PaX, or the copy-on-write
32224+ * mechanism). in effect it means that we do *not* need to flush the TLBs
32225+ * for our target pages since their PTEs are simply not in the TLBs at all.
32226+
32227+ * the best thing in omitting it is that we gain around 15-20% speed in the
32228+ * fast path of the page fault handler and can get rid of tracing since we
32229+ * can no longer flush unintended entries.
32230+ */
32231+ "invlpg (%0)\n"
32232+#endif
32233+ __copyuser_seg"testb $0,(%0)\n"
32234+ "xorb %3,(%1)\n"
32235+ :
32236+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32237+ : "memory", "cc");
32238+ pte_unmap_unlock(pte, ptl);
32239+ up_read(&mm->mmap_sem);
32240+ return 1;
32241+}
32242+#endif
32243+
32244 /*
32245 * Handle a spurious fault caused by a stale TLB entry.
32246 *
32247@@ -985,6 +1190,9 @@ int show_unhandled_signals = 1;
32248 static inline int
32249 access_error(unsigned long error_code, struct vm_area_struct *vma)
32250 {
32251+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32252+ return 1;
32253+
32254 if (error_code & PF_WRITE) {
32255 /* write, present and write, not present: */
32256 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32257@@ -1019,7 +1227,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32258 if (error_code & PF_USER)
32259 return false;
32260
32261- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32262+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32263 return false;
32264
32265 return true;
32266@@ -1047,6 +1255,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32267 tsk = current;
32268 mm = tsk->mm;
32269
32270+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32271+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32272+ if (!search_exception_tables(regs->ip)) {
32273+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32274+ bad_area_nosemaphore(regs, error_code, address);
32275+ return;
32276+ }
32277+ if (address < pax_user_shadow_base) {
32278+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32279+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32280+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32281+ } else
32282+ address -= pax_user_shadow_base;
32283+ }
32284+#endif
32285+
32286 /*
32287 * Detect and handle instructions that would cause a page fault for
32288 * both a tracked kernel page and a userspace page.
32289@@ -1124,7 +1348,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32290 * User-mode registers count as a user access even for any
32291 * potential system fault or CPU buglet:
32292 */
32293- if (user_mode_vm(regs)) {
32294+ if (user_mode(regs)) {
32295 local_irq_enable();
32296 error_code |= PF_USER;
32297 flags |= FAULT_FLAG_USER;
32298@@ -1171,6 +1395,11 @@ retry:
32299 might_sleep();
32300 }
32301
32302+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32303+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32304+ return;
32305+#endif
32306+
32307 vma = find_vma(mm, address);
32308 if (unlikely(!vma)) {
32309 bad_area(regs, error_code, address);
32310@@ -1182,18 +1411,24 @@ retry:
32311 bad_area(regs, error_code, address);
32312 return;
32313 }
32314- if (error_code & PF_USER) {
32315- /*
32316- * Accessing the stack below %sp is always a bug.
32317- * The large cushion allows instructions like enter
32318- * and pusha to work. ("enter $65535, $31" pushes
32319- * 32 pointers and then decrements %sp by 65535.)
32320- */
32321- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32322- bad_area(regs, error_code, address);
32323- return;
32324- }
32325+ /*
32326+ * Accessing the stack below %sp is always a bug.
32327+ * The large cushion allows instructions like enter
32328+ * and pusha to work. ("enter $65535, $31" pushes
32329+ * 32 pointers and then decrements %sp by 65535.)
32330+ */
32331+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32332+ bad_area(regs, error_code, address);
32333+ return;
32334 }
32335+
32336+#ifdef CONFIG_PAX_SEGMEXEC
32337+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32338+ bad_area(regs, error_code, address);
32339+ return;
32340+ }
32341+#endif
32342+
32343 if (unlikely(expand_stack(vma, address))) {
32344 bad_area(regs, error_code, address);
32345 return;
32346@@ -1309,3 +1544,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32347 }
32348 NOKPROBE_SYMBOL(trace_do_page_fault);
32349 #endif /* CONFIG_TRACING */
32350+
32351+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32352+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32353+{
32354+ struct mm_struct *mm = current->mm;
32355+ unsigned long ip = regs->ip;
32356+
32357+ if (v8086_mode(regs))
32358+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32359+
32360+#ifdef CONFIG_PAX_PAGEEXEC
32361+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32362+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32363+ return true;
32364+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32365+ return true;
32366+ return false;
32367+ }
32368+#endif
32369+
32370+#ifdef CONFIG_PAX_SEGMEXEC
32371+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32372+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32373+ return true;
32374+ return false;
32375+ }
32376+#endif
32377+
32378+ return false;
32379+}
32380+#endif
32381+
32382+#ifdef CONFIG_PAX_EMUTRAMP
32383+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32384+{
32385+ int err;
32386+
32387+ do { /* PaX: libffi trampoline emulation */
32388+ unsigned char mov, jmp;
32389+ unsigned int addr1, addr2;
32390+
32391+#ifdef CONFIG_X86_64
32392+ if ((regs->ip + 9) >> 32)
32393+ break;
32394+#endif
32395+
32396+ err = get_user(mov, (unsigned char __user *)regs->ip);
32397+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32398+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32399+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32400+
32401+ if (err)
32402+ break;
32403+
32404+ if (mov == 0xB8 && jmp == 0xE9) {
32405+ regs->ax = addr1;
32406+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32407+ return 2;
32408+ }
32409+ } while (0);
32410+
32411+ do { /* PaX: gcc trampoline emulation #1 */
32412+ unsigned char mov1, mov2;
32413+ unsigned short jmp;
32414+ unsigned int addr1, addr2;
32415+
32416+#ifdef CONFIG_X86_64
32417+ if ((regs->ip + 11) >> 32)
32418+ break;
32419+#endif
32420+
32421+ err = get_user(mov1, (unsigned char __user *)regs->ip);
32422+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32423+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32424+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32425+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32426+
32427+ if (err)
32428+ break;
32429+
32430+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32431+ regs->cx = addr1;
32432+ regs->ax = addr2;
32433+ regs->ip = addr2;
32434+ return 2;
32435+ }
32436+ } while (0);
32437+
32438+ do { /* PaX: gcc trampoline emulation #2 */
32439+ unsigned char mov, jmp;
32440+ unsigned int addr1, addr2;
32441+
32442+#ifdef CONFIG_X86_64
32443+ if ((regs->ip + 9) >> 32)
32444+ break;
32445+#endif
32446+
32447+ err = get_user(mov, (unsigned char __user *)regs->ip);
32448+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32449+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32450+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32451+
32452+ if (err)
32453+ break;
32454+
32455+ if (mov == 0xB9 && jmp == 0xE9) {
32456+ regs->cx = addr1;
32457+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32458+ return 2;
32459+ }
32460+ } while (0);
32461+
32462+ return 1; /* PaX in action */
32463+}
32464+
32465+#ifdef CONFIG_X86_64
32466+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32467+{
32468+ int err;
32469+
32470+ do { /* PaX: libffi trampoline emulation */
32471+ unsigned short mov1, mov2, jmp1;
32472+ unsigned char stcclc, jmp2;
32473+ unsigned long addr1, addr2;
32474+
32475+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32476+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32477+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32478+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32479+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32480+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32481+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32482+
32483+ if (err)
32484+ break;
32485+
32486+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32487+ regs->r11 = addr1;
32488+ regs->r10 = addr2;
32489+ if (stcclc == 0xF8)
32490+ regs->flags &= ~X86_EFLAGS_CF;
32491+ else
32492+ regs->flags |= X86_EFLAGS_CF;
32493+ regs->ip = addr1;
32494+ return 2;
32495+ }
32496+ } while (0);
32497+
32498+ do { /* PaX: gcc trampoline emulation #1 */
32499+ unsigned short mov1, mov2, jmp1;
32500+ unsigned char jmp2;
32501+ unsigned int addr1;
32502+ unsigned long addr2;
32503+
32504+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32505+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32506+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32507+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32508+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32509+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32510+
32511+ if (err)
32512+ break;
32513+
32514+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32515+ regs->r11 = addr1;
32516+ regs->r10 = addr2;
32517+ regs->ip = addr1;
32518+ return 2;
32519+ }
32520+ } while (0);
32521+
32522+ do { /* PaX: gcc trampoline emulation #2 */
32523+ unsigned short mov1, mov2, jmp1;
32524+ unsigned char jmp2;
32525+ unsigned long addr1, addr2;
32526+
32527+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32528+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32529+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32530+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32531+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32532+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32533+
32534+ if (err)
32535+ break;
32536+
32537+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32538+ regs->r11 = addr1;
32539+ regs->r10 = addr2;
32540+ regs->ip = addr1;
32541+ return 2;
32542+ }
32543+ } while (0);
32544+
32545+ return 1; /* PaX in action */
32546+}
32547+#endif
32548+
32549+/*
32550+ * PaX: decide what to do with offenders (regs->ip = fault address)
32551+ *
32552+ * returns 1 when task should be killed
32553+ * 2 when gcc trampoline was detected
32554+ */
32555+static int pax_handle_fetch_fault(struct pt_regs *regs)
32556+{
32557+ if (v8086_mode(regs))
32558+ return 1;
32559+
32560+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32561+ return 1;
32562+
32563+#ifdef CONFIG_X86_32
32564+ return pax_handle_fetch_fault_32(regs);
32565+#else
32566+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32567+ return pax_handle_fetch_fault_32(regs);
32568+ else
32569+ return pax_handle_fetch_fault_64(regs);
32570+#endif
32571+}
32572+#endif
32573+
32574+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32575+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32576+{
32577+ long i;
32578+
32579+ printk(KERN_ERR "PAX: bytes at PC: ");
32580+ for (i = 0; i < 20; i++) {
32581+ unsigned char c;
32582+ if (get_user(c, (unsigned char __force_user *)pc+i))
32583+ printk(KERN_CONT "?? ");
32584+ else
32585+ printk(KERN_CONT "%02x ", c);
32586+ }
32587+ printk("\n");
32588+
32589+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32590+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
32591+ unsigned long c;
32592+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
32593+#ifdef CONFIG_X86_32
32594+ printk(KERN_CONT "???????? ");
32595+#else
32596+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32597+ printk(KERN_CONT "???????? ???????? ");
32598+ else
32599+ printk(KERN_CONT "???????????????? ");
32600+#endif
32601+ } else {
32602+#ifdef CONFIG_X86_64
32603+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32604+ printk(KERN_CONT "%08x ", (unsigned int)c);
32605+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32606+ } else
32607+#endif
32608+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32609+ }
32610+ }
32611+ printk("\n");
32612+}
32613+#endif
32614+
32615+/**
32616+ * probe_kernel_write(): safely attempt to write to a location
32617+ * @dst: address to write to
32618+ * @src: pointer to the data that shall be written
32619+ * @size: size of the data chunk
32620+ *
32621+ * Safely write to address @dst from the buffer at @src. If a kernel fault
32622+ * happens, handle that and return -EFAULT.
32623+ */
32624+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32625+{
32626+ long ret;
32627+ mm_segment_t old_fs = get_fs();
32628+
32629+ set_fs(KERNEL_DS);
32630+ pagefault_disable();
32631+ pax_open_kernel();
32632+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32633+ pax_close_kernel();
32634+ pagefault_enable();
32635+ set_fs(old_fs);
32636+
32637+ return ret ? -EFAULT : 0;
32638+}
32639diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32640index 207d9aef..69030980 100644
32641--- a/arch/x86/mm/gup.c
32642+++ b/arch/x86/mm/gup.c
32643@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32644 addr = start;
32645 len = (unsigned long) nr_pages << PAGE_SHIFT;
32646 end = start + len;
32647- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32648+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32649 (void __user *)start, len)))
32650 return 0;
32651
32652@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32653 goto slow_irqon;
32654 #endif
32655
32656+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32657+ (void __user *)start, len)))
32658+ return 0;
32659+
32660 /*
32661 * XXX: batch / limit 'nr', to avoid large irq off latency
32662 * needs some instrumenting to determine the common sizes used by
32663diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32664index 4500142..53a363c 100644
32665--- a/arch/x86/mm/highmem_32.c
32666+++ b/arch/x86/mm/highmem_32.c
32667@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32668 idx = type + KM_TYPE_NR*smp_processor_id();
32669 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32670 BUG_ON(!pte_none(*(kmap_pte-idx)));
32671+
32672+ pax_open_kernel();
32673 set_pte(kmap_pte-idx, mk_pte(page, prot));
32674+ pax_close_kernel();
32675+
32676 arch_flush_lazy_mmu_mode();
32677
32678 return (void *)vaddr;
32679diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32680index 8b977eb..4732c33 100644
32681--- a/arch/x86/mm/hugetlbpage.c
32682+++ b/arch/x86/mm/hugetlbpage.c
32683@@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32684 #ifdef CONFIG_HUGETLB_PAGE
32685 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32686 unsigned long addr, unsigned long len,
32687- unsigned long pgoff, unsigned long flags)
32688+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32689 {
32690 struct hstate *h = hstate_file(file);
32691 struct vm_unmapped_area_info info;
32692-
32693+
32694 info.flags = 0;
32695 info.length = len;
32696 info.low_limit = current->mm->mmap_legacy_base;
32697 info.high_limit = TASK_SIZE;
32698 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32699 info.align_offset = 0;
32700+ info.threadstack_offset = offset;
32701 return vm_unmapped_area(&info);
32702 }
32703
32704 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32705 unsigned long addr0, unsigned long len,
32706- unsigned long pgoff, unsigned long flags)
32707+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32708 {
32709 struct hstate *h = hstate_file(file);
32710 struct vm_unmapped_area_info info;
32711@@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32712 info.high_limit = current->mm->mmap_base;
32713 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32714 info.align_offset = 0;
32715+ info.threadstack_offset = offset;
32716 addr = vm_unmapped_area(&info);
32717
32718 /*
32719@@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32720 VM_BUG_ON(addr != -ENOMEM);
32721 info.flags = 0;
32722 info.low_limit = TASK_UNMAPPED_BASE;
32723+
32724+#ifdef CONFIG_PAX_RANDMMAP
32725+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32726+ info.low_limit += current->mm->delta_mmap;
32727+#endif
32728+
32729 info.high_limit = TASK_SIZE;
32730 addr = vm_unmapped_area(&info);
32731 }
32732@@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32733 struct hstate *h = hstate_file(file);
32734 struct mm_struct *mm = current->mm;
32735 struct vm_area_struct *vma;
32736+ unsigned long pax_task_size = TASK_SIZE;
32737+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32738
32739 if (len & ~huge_page_mask(h))
32740 return -EINVAL;
32741- if (len > TASK_SIZE)
32742+
32743+#ifdef CONFIG_PAX_SEGMEXEC
32744+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32745+ pax_task_size = SEGMEXEC_TASK_SIZE;
32746+#endif
32747+
32748+ pax_task_size -= PAGE_SIZE;
32749+
32750+ if (len > pax_task_size)
32751 return -ENOMEM;
32752
32753 if (flags & MAP_FIXED) {
32754@@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32755 return addr;
32756 }
32757
32758+#ifdef CONFIG_PAX_RANDMMAP
32759+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32760+#endif
32761+
32762 if (addr) {
32763 addr = ALIGN(addr, huge_page_size(h));
32764 vma = find_vma(mm, addr);
32765- if (TASK_SIZE - len >= addr &&
32766- (!vma || addr + len <= vma->vm_start))
32767+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32768 return addr;
32769 }
32770 if (mm->get_unmapped_area == arch_get_unmapped_area)
32771 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32772- pgoff, flags);
32773+ pgoff, flags, offset);
32774 else
32775 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32776- pgoff, flags);
32777+ pgoff, flags, offset);
32778 }
32779 #endif /* CONFIG_HUGETLB_PAGE */
32780
32781diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32782index f971306..e83e0f6 100644
32783--- a/arch/x86/mm/init.c
32784+++ b/arch/x86/mm/init.c
32785@@ -4,6 +4,7 @@
32786 #include <linux/swap.h>
32787 #include <linux/memblock.h>
32788 #include <linux/bootmem.h> /* for max_low_pfn */
32789+#include <linux/tboot.h>
32790
32791 #include <asm/cacheflush.h>
32792 #include <asm/e820.h>
32793@@ -17,6 +18,8 @@
32794 #include <asm/proto.h>
32795 #include <asm/dma.h> /* for MAX_DMA_PFN */
32796 #include <asm/microcode.h>
32797+#include <asm/desc.h>
32798+#include <asm/bios_ebda.h>
32799
32800 #include "mm_internal.h"
32801
32802@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32803 early_ioremap_page_table_range_init();
32804 #endif
32805
32806+#ifdef CONFIG_PAX_PER_CPU_PGD
32807+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32808+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32809+ KERNEL_PGD_PTRS);
32810+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32811+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32812+ KERNEL_PGD_PTRS);
32813+ load_cr3(get_cpu_pgd(0, kernel));
32814+#else
32815 load_cr3(swapper_pg_dir);
32816+#endif
32817+
32818 __flush_tlb_all();
32819
32820 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32821@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32822 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32823 * mmio resources as well as potential bios/acpi data regions.
32824 */
32825+
32826+#ifdef CONFIG_GRKERNSEC_KMEM
32827+static unsigned int ebda_start __read_only;
32828+static unsigned int ebda_end __read_only;
32829+#endif
32830+
32831 int devmem_is_allowed(unsigned long pagenr)
32832 {
32833- if (pagenr < 256)
32834+#ifdef CONFIG_GRKERNSEC_KMEM
32835+ /* allow BDA */
32836+ if (!pagenr)
32837 return 1;
32838+ /* allow EBDA */
32839+ if (pagenr >= ebda_start && pagenr < ebda_end)
32840+ return 1;
32841+ /* if tboot is in use, allow access to its hardcoded serial log range */
32842+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32843+ return 1;
32844+#else
32845+ if (!pagenr)
32846+ return 1;
32847+#ifdef CONFIG_VM86
32848+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32849+ return 1;
32850+#endif
32851+#endif
32852+
32853+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32854+ return 1;
32855+#ifdef CONFIG_GRKERNSEC_KMEM
32856+ /* throw out everything else below 1MB */
32857+ if (pagenr <= 256)
32858+ return 0;
32859+#endif
32860 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32861 return 0;
32862 if (!page_is_ram(pagenr))
32863@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32864 #endif
32865 }
32866
32867+#ifdef CONFIG_GRKERNSEC_KMEM
32868+static inline void gr_init_ebda(void)
32869+{
32870+ unsigned int ebda_addr;
32871+ unsigned int ebda_size = 0;
32872+
32873+ ebda_addr = get_bios_ebda();
32874+ if (ebda_addr) {
32875+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32876+ ebda_size <<= 10;
32877+ }
32878+ if (ebda_addr && ebda_size) {
32879+ ebda_start = ebda_addr >> PAGE_SHIFT;
32880+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32881+ } else {
32882+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32883+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32884+ }
32885+}
32886+#else
32887+static inline void gr_init_ebda(void) { }
32888+#endif
32889+
32890 void free_initmem(void)
32891 {
32892+#ifdef CONFIG_PAX_KERNEXEC
32893+#ifdef CONFIG_X86_32
32894+ /* PaX: limit KERNEL_CS to actual size */
32895+ unsigned long addr, limit;
32896+ struct desc_struct d;
32897+ int cpu;
32898+#else
32899+ pgd_t *pgd;
32900+ pud_t *pud;
32901+ pmd_t *pmd;
32902+ unsigned long addr, end;
32903+#endif
32904+#endif
32905+
32906+ gr_init_ebda();
32907+
32908+#ifdef CONFIG_PAX_KERNEXEC
32909+#ifdef CONFIG_X86_32
32910+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32911+ limit = (limit - 1UL) >> PAGE_SHIFT;
32912+
32913+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32914+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32915+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32916+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32917+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32918+ }
32919+
32920+ /* PaX: make KERNEL_CS read-only */
32921+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32922+ if (!paravirt_enabled())
32923+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32924+/*
32925+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32926+ pgd = pgd_offset_k(addr);
32927+ pud = pud_offset(pgd, addr);
32928+ pmd = pmd_offset(pud, addr);
32929+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32930+ }
32931+*/
32932+#ifdef CONFIG_X86_PAE
32933+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32934+/*
32935+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32936+ pgd = pgd_offset_k(addr);
32937+ pud = pud_offset(pgd, addr);
32938+ pmd = pmd_offset(pud, addr);
32939+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32940+ }
32941+*/
32942+#endif
32943+
32944+#ifdef CONFIG_MODULES
32945+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32946+#endif
32947+
32948+#else
32949+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32950+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32951+ pgd = pgd_offset_k(addr);
32952+ pud = pud_offset(pgd, addr);
32953+ pmd = pmd_offset(pud, addr);
32954+ if (!pmd_present(*pmd))
32955+ continue;
32956+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32957+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32958+ else
32959+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32960+ }
32961+
32962+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32963+ end = addr + KERNEL_IMAGE_SIZE;
32964+ for (; addr < end; addr += PMD_SIZE) {
32965+ pgd = pgd_offset_k(addr);
32966+ pud = pud_offset(pgd, addr);
32967+ pmd = pmd_offset(pud, addr);
32968+ if (!pmd_present(*pmd))
32969+ continue;
32970+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32971+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32972+ }
32973+#endif
32974+
32975+ flush_tlb_all();
32976+#endif
32977+
32978 free_init_pages("unused kernel",
32979 (unsigned long)(&__init_begin),
32980 (unsigned long)(&__init_end));
32981diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32982index e395048..cd38278 100644
32983--- a/arch/x86/mm/init_32.c
32984+++ b/arch/x86/mm/init_32.c
32985@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32986 bool __read_mostly __vmalloc_start_set = false;
32987
32988 /*
32989- * Creates a middle page table and puts a pointer to it in the
32990- * given global directory entry. This only returns the gd entry
32991- * in non-PAE compilation mode, since the middle layer is folded.
32992- */
32993-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32994-{
32995- pud_t *pud;
32996- pmd_t *pmd_table;
32997-
32998-#ifdef CONFIG_X86_PAE
32999- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
33000- pmd_table = (pmd_t *)alloc_low_page();
33001- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
33002- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
33003- pud = pud_offset(pgd, 0);
33004- BUG_ON(pmd_table != pmd_offset(pud, 0));
33005-
33006- return pmd_table;
33007- }
33008-#endif
33009- pud = pud_offset(pgd, 0);
33010- pmd_table = pmd_offset(pud, 0);
33011-
33012- return pmd_table;
33013-}
33014-
33015-/*
33016 * Create a page table and place a pointer to it in a middle page
33017 * directory entry:
33018 */
33019@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
33020 pte_t *page_table = (pte_t *)alloc_low_page();
33021
33022 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
33023+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33024+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
33025+#else
33026 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
33027+#endif
33028 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
33029 }
33030
33031 return pte_offset_kernel(pmd, 0);
33032 }
33033
33034+static pmd_t * __init one_md_table_init(pgd_t *pgd)
33035+{
33036+ pud_t *pud;
33037+ pmd_t *pmd_table;
33038+
33039+ pud = pud_offset(pgd, 0);
33040+ pmd_table = pmd_offset(pud, 0);
33041+
33042+ return pmd_table;
33043+}
33044+
33045 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
33046 {
33047 int pgd_idx = pgd_index(vaddr);
33048@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33049 int pgd_idx, pmd_idx;
33050 unsigned long vaddr;
33051 pgd_t *pgd;
33052+ pud_t *pud;
33053 pmd_t *pmd;
33054 pte_t *pte = NULL;
33055 unsigned long count = page_table_range_init_count(start, end);
33056@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33057 pgd = pgd_base + pgd_idx;
33058
33059 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
33060- pmd = one_md_table_init(pgd);
33061- pmd = pmd + pmd_index(vaddr);
33062+ pud = pud_offset(pgd, vaddr);
33063+ pmd = pmd_offset(pud, vaddr);
33064+
33065+#ifdef CONFIG_X86_PAE
33066+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33067+#endif
33068+
33069 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
33070 pmd++, pmd_idx++) {
33071 pte = page_table_kmap_check(one_page_table_init(pmd),
33072@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33073 }
33074 }
33075
33076-static inline int is_kernel_text(unsigned long addr)
33077+static inline int is_kernel_text(unsigned long start, unsigned long end)
33078 {
33079- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
33080- return 1;
33081- return 0;
33082+ if ((start >= ktla_ktva((unsigned long)_etext) ||
33083+ end <= ktla_ktva((unsigned long)_stext)) &&
33084+ (start >= ktla_ktva((unsigned long)_einittext) ||
33085+ end <= ktla_ktva((unsigned long)_sinittext)) &&
33086+
33087+#ifdef CONFIG_ACPI_SLEEP
33088+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
33089+#endif
33090+
33091+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
33092+ return 0;
33093+ return 1;
33094 }
33095
33096 /*
33097@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
33098 unsigned long last_map_addr = end;
33099 unsigned long start_pfn, end_pfn;
33100 pgd_t *pgd_base = swapper_pg_dir;
33101- int pgd_idx, pmd_idx, pte_ofs;
33102+ unsigned int pgd_idx, pmd_idx, pte_ofs;
33103 unsigned long pfn;
33104 pgd_t *pgd;
33105+ pud_t *pud;
33106 pmd_t *pmd;
33107 pte_t *pte;
33108 unsigned pages_2m, pages_4k;
33109@@ -291,8 +295,13 @@ repeat:
33110 pfn = start_pfn;
33111 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33112 pgd = pgd_base + pgd_idx;
33113- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33114- pmd = one_md_table_init(pgd);
33115+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33116+ pud = pud_offset(pgd, 0);
33117+ pmd = pmd_offset(pud, 0);
33118+
33119+#ifdef CONFIG_X86_PAE
33120+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33121+#endif
33122
33123 if (pfn >= end_pfn)
33124 continue;
33125@@ -304,14 +313,13 @@ repeat:
33126 #endif
33127 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33128 pmd++, pmd_idx++) {
33129- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33130+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33131
33132 /*
33133 * Map with big pages if possible, otherwise
33134 * create normal page tables:
33135 */
33136 if (use_pse) {
33137- unsigned int addr2;
33138 pgprot_t prot = PAGE_KERNEL_LARGE;
33139 /*
33140 * first pass will use the same initial
33141@@ -322,11 +330,7 @@ repeat:
33142 _PAGE_PSE);
33143
33144 pfn &= PMD_MASK >> PAGE_SHIFT;
33145- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33146- PAGE_OFFSET + PAGE_SIZE-1;
33147-
33148- if (is_kernel_text(addr) ||
33149- is_kernel_text(addr2))
33150+ if (is_kernel_text(address, address + PMD_SIZE))
33151 prot = PAGE_KERNEL_LARGE_EXEC;
33152
33153 pages_2m++;
33154@@ -343,7 +347,7 @@ repeat:
33155 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33156 pte += pte_ofs;
33157 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33158- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33159+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33160 pgprot_t prot = PAGE_KERNEL;
33161 /*
33162 * first pass will use the same initial
33163@@ -351,7 +355,7 @@ repeat:
33164 */
33165 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33166
33167- if (is_kernel_text(addr))
33168+ if (is_kernel_text(address, address + PAGE_SIZE))
33169 prot = PAGE_KERNEL_EXEC;
33170
33171 pages_4k++;
33172@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33173
33174 pud = pud_offset(pgd, va);
33175 pmd = pmd_offset(pud, va);
33176- if (!pmd_present(*pmd))
33177+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33178 break;
33179
33180 /* should not be large page here */
33181@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33182
33183 static void __init pagetable_init(void)
33184 {
33185- pgd_t *pgd_base = swapper_pg_dir;
33186-
33187- permanent_kmaps_init(pgd_base);
33188+ permanent_kmaps_init(swapper_pg_dir);
33189 }
33190
33191-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33192+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33193 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33194
33195 /* user-defined highmem size */
33196@@ -787,10 +789,10 @@ void __init mem_init(void)
33197 ((unsigned long)&__init_end -
33198 (unsigned long)&__init_begin) >> 10,
33199
33200- (unsigned long)&_etext, (unsigned long)&_edata,
33201- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33202+ (unsigned long)&_sdata, (unsigned long)&_edata,
33203+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33204
33205- (unsigned long)&_text, (unsigned long)&_etext,
33206+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33207 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33208
33209 /*
33210@@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
33211 if (!kernel_set_to_readonly)
33212 return;
33213
33214+ start = ktla_ktva(start);
33215 pr_debug("Set kernel text: %lx - %lx for read write\n",
33216 start, start+size);
33217
33218@@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
33219 if (!kernel_set_to_readonly)
33220 return;
33221
33222+ start = ktla_ktva(start);
33223 pr_debug("Set kernel text: %lx - %lx for read only\n",
33224 start, start+size);
33225
33226@@ -925,6 +929,7 @@ void mark_rodata_ro(void)
33227 unsigned long start = PFN_ALIGN(_text);
33228 unsigned long size = PFN_ALIGN(_etext) - start;
33229
33230+ start = ktla_ktva(start);
33231 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33232 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33233 size >> 10);
33234diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33235index df1a992..94c272c 100644
33236--- a/arch/x86/mm/init_64.c
33237+++ b/arch/x86/mm/init_64.c
33238@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33239 * around without checking the pgd every time.
33240 */
33241
33242-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
33243+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
33244 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33245
33246 int force_personality32;
33247@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33248
33249 for (address = start; address <= end; address += PGDIR_SIZE) {
33250 const pgd_t *pgd_ref = pgd_offset_k(address);
33251+
33252+#ifdef CONFIG_PAX_PER_CPU_PGD
33253+ unsigned long cpu;
33254+#else
33255 struct page *page;
33256+#endif
33257
33258 if (pgd_none(*pgd_ref))
33259 continue;
33260
33261 spin_lock(&pgd_lock);
33262+
33263+#ifdef CONFIG_PAX_PER_CPU_PGD
33264+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33265+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33266+
33267+ if (pgd_none(*pgd))
33268+ set_pgd(pgd, *pgd_ref);
33269+ else
33270+ BUG_ON(pgd_page_vaddr(*pgd)
33271+ != pgd_page_vaddr(*pgd_ref));
33272+ pgd = pgd_offset_cpu(cpu, kernel, address);
33273+#else
33274 list_for_each_entry(page, &pgd_list, lru) {
33275 pgd_t *pgd;
33276 spinlock_t *pgt_lock;
33277@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33278 /* the pgt_lock only for Xen */
33279 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33280 spin_lock(pgt_lock);
33281+#endif
33282
33283 if (pgd_none(*pgd))
33284 set_pgd(pgd, *pgd_ref);
33285@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33286 BUG_ON(pgd_page_vaddr(*pgd)
33287 != pgd_page_vaddr(*pgd_ref));
33288
33289+#ifndef CONFIG_PAX_PER_CPU_PGD
33290 spin_unlock(pgt_lock);
33291+#endif
33292+
33293 }
33294 spin_unlock(&pgd_lock);
33295 }
33296@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33297 {
33298 if (pgd_none(*pgd)) {
33299 pud_t *pud = (pud_t *)spp_getpage();
33300- pgd_populate(&init_mm, pgd, pud);
33301+ pgd_populate_kernel(&init_mm, pgd, pud);
33302 if (pud != pud_offset(pgd, 0))
33303 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33304 pud, pud_offset(pgd, 0));
33305@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33306 {
33307 if (pud_none(*pud)) {
33308 pmd_t *pmd = (pmd_t *) spp_getpage();
33309- pud_populate(&init_mm, pud, pmd);
33310+ pud_populate_kernel(&init_mm, pud, pmd);
33311 if (pmd != pmd_offset(pud, 0))
33312 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33313 pmd, pmd_offset(pud, 0));
33314@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33315 pmd = fill_pmd(pud, vaddr);
33316 pte = fill_pte(pmd, vaddr);
33317
33318+ pax_open_kernel();
33319 set_pte(pte, new_pte);
33320+ pax_close_kernel();
33321
33322 /*
33323 * It's enough to flush this one mapping.
33324@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33325 pgd = pgd_offset_k((unsigned long)__va(phys));
33326 if (pgd_none(*pgd)) {
33327 pud = (pud_t *) spp_getpage();
33328- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33329- _PAGE_USER));
33330+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33331 }
33332 pud = pud_offset(pgd, (unsigned long)__va(phys));
33333 if (pud_none(*pud)) {
33334 pmd = (pmd_t *) spp_getpage();
33335- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33336- _PAGE_USER));
33337+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33338 }
33339 pmd = pmd_offset(pud, phys);
33340 BUG_ON(!pmd_none(*pmd));
33341@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33342 prot);
33343
33344 spin_lock(&init_mm.page_table_lock);
33345- pud_populate(&init_mm, pud, pmd);
33346+ pud_populate_kernel(&init_mm, pud, pmd);
33347 spin_unlock(&init_mm.page_table_lock);
33348 }
33349 __flush_tlb_all();
33350@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33351 page_size_mask);
33352
33353 spin_lock(&init_mm.page_table_lock);
33354- pgd_populate(&init_mm, pgd, pud);
33355+ pgd_populate_kernel(&init_mm, pgd, pud);
33356 spin_unlock(&init_mm.page_table_lock);
33357 pgd_changed = true;
33358 }
33359@@ -1195,8 +1216,8 @@ static struct vm_operations_struct gate_vma_ops = {
33360 static struct vm_area_struct gate_vma = {
33361 .vm_start = VSYSCALL_ADDR,
33362 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33363- .vm_page_prot = PAGE_READONLY_EXEC,
33364- .vm_flags = VM_READ | VM_EXEC,
33365+ .vm_page_prot = PAGE_READONLY,
33366+ .vm_flags = VM_READ,
33367 .vm_ops = &gate_vma_ops,
33368 };
33369
33370diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33371index 7b179b4..6bd17777 100644
33372--- a/arch/x86/mm/iomap_32.c
33373+++ b/arch/x86/mm/iomap_32.c
33374@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33375 type = kmap_atomic_idx_push();
33376 idx = type + KM_TYPE_NR * smp_processor_id();
33377 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33378+
33379+ pax_open_kernel();
33380 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33381+ pax_close_kernel();
33382+
33383 arch_flush_lazy_mmu_mode();
33384
33385 return (void *)vaddr;
33386diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33387index baff1da..2816ef4 100644
33388--- a/arch/x86/mm/ioremap.c
33389+++ b/arch/x86/mm/ioremap.c
33390@@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33391 unsigned long i;
33392
33393 for (i = 0; i < nr_pages; ++i)
33394- if (pfn_valid(start_pfn + i) &&
33395- !PageReserved(pfn_to_page(start_pfn + i)))
33396+ if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33397+ !PageReserved(pfn_to_page(start_pfn + i))))
33398 return 1;
33399
33400 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33401@@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
33402 *
33403 * Caller must ensure there is only one unmapping for the same pointer.
33404 */
33405-void iounmap(volatile void __iomem *addr)
33406+void iounmap(const volatile void __iomem *addr)
33407 {
33408 struct vm_struct *p, *o;
33409
33410@@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33411
33412 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33413 if (page_is_ram(start >> PAGE_SHIFT))
33414+#ifdef CONFIG_HIGHMEM
33415+ if ((start >> PAGE_SHIFT) < max_low_pfn)
33416+#endif
33417 return __va(phys);
33418
33419 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33420@@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33421 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33422 {
33423 if (page_is_ram(phys >> PAGE_SHIFT))
33424+#ifdef CONFIG_HIGHMEM
33425+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
33426+#endif
33427 return;
33428
33429 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33430 return;
33431 }
33432
33433-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33434+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33435
33436 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33437 {
33438@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
33439 early_ioremap_setup();
33440
33441 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33442- memset(bm_pte, 0, sizeof(bm_pte));
33443- pmd_populate_kernel(&init_mm, pmd, bm_pte);
33444+ pmd_populate_user(&init_mm, pmd, bm_pte);
33445
33446 /*
33447 * The boot-ioremap range spans multiple pmds, for which
33448diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33449index dd89a13..d77bdcc 100644
33450--- a/arch/x86/mm/kmemcheck/kmemcheck.c
33451+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33452@@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33453 * memory (e.g. tracked pages)? For now, we need this to avoid
33454 * invoking kmemcheck for PnP BIOS calls.
33455 */
33456- if (regs->flags & X86_VM_MASK)
33457+ if (v8086_mode(regs))
33458 return false;
33459- if (regs->cs != __KERNEL_CS)
33460+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33461 return false;
33462
33463 pte = kmemcheck_pte_lookup(address);
33464diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33465index 25e7e13..1964579 100644
33466--- a/arch/x86/mm/mmap.c
33467+++ b/arch/x86/mm/mmap.c
33468@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33469 * Leave an at least ~128 MB hole with possible stack randomization.
33470 */
33471 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33472-#define MAX_GAP (TASK_SIZE/6*5)
33473+#define MAX_GAP (pax_task_size/6*5)
33474
33475 static int mmap_is_legacy(void)
33476 {
33477@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33478 return rnd << PAGE_SHIFT;
33479 }
33480
33481-static unsigned long mmap_base(void)
33482+static unsigned long mmap_base(struct mm_struct *mm)
33483 {
33484 unsigned long gap = rlimit(RLIMIT_STACK);
33485+ unsigned long pax_task_size = TASK_SIZE;
33486+
33487+#ifdef CONFIG_PAX_SEGMEXEC
33488+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33489+ pax_task_size = SEGMEXEC_TASK_SIZE;
33490+#endif
33491
33492 if (gap < MIN_GAP)
33493 gap = MIN_GAP;
33494 else if (gap > MAX_GAP)
33495 gap = MAX_GAP;
33496
33497- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33498+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33499 }
33500
33501 /*
33502 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33503 * does, but not when emulating X86_32
33504 */
33505-static unsigned long mmap_legacy_base(void)
33506+static unsigned long mmap_legacy_base(struct mm_struct *mm)
33507 {
33508- if (mmap_is_ia32())
33509+ if (mmap_is_ia32()) {
33510+
33511+#ifdef CONFIG_PAX_SEGMEXEC
33512+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33513+ return SEGMEXEC_TASK_UNMAPPED_BASE;
33514+ else
33515+#endif
33516+
33517 return TASK_UNMAPPED_BASE;
33518- else
33519+ } else
33520 return TASK_UNMAPPED_BASE + mmap_rnd();
33521 }
33522
33523@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33524 */
33525 void arch_pick_mmap_layout(struct mm_struct *mm)
33526 {
33527- mm->mmap_legacy_base = mmap_legacy_base();
33528- mm->mmap_base = mmap_base();
33529+ mm->mmap_legacy_base = mmap_legacy_base(mm);
33530+ mm->mmap_base = mmap_base(mm);
33531+
33532+#ifdef CONFIG_PAX_RANDMMAP
33533+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
33534+ mm->mmap_legacy_base += mm->delta_mmap;
33535+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33536+ }
33537+#endif
33538
33539 if (mmap_is_legacy()) {
33540 mm->mmap_base = mm->mmap_legacy_base;
33541diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33542index 0057a7a..95c7edd 100644
33543--- a/arch/x86/mm/mmio-mod.c
33544+++ b/arch/x86/mm/mmio-mod.c
33545@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33546 break;
33547 default:
33548 {
33549- unsigned char *ip = (unsigned char *)instptr;
33550+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33551 my_trace->opcode = MMIO_UNKNOWN_OP;
33552 my_trace->width = 0;
33553 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33554@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33555 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33556 void __iomem *addr)
33557 {
33558- static atomic_t next_id;
33559+ static atomic_unchecked_t next_id;
33560 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33561 /* These are page-unaligned. */
33562 struct mmiotrace_map map = {
33563@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33564 .private = trace
33565 },
33566 .phys = offset,
33567- .id = atomic_inc_return(&next_id)
33568+ .id = atomic_inc_return_unchecked(&next_id)
33569 };
33570 map.map_id = trace->id;
33571
33572@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33573 ioremap_trace_core(offset, size, addr);
33574 }
33575
33576-static void iounmap_trace_core(volatile void __iomem *addr)
33577+static void iounmap_trace_core(const volatile void __iomem *addr)
33578 {
33579 struct mmiotrace_map map = {
33580 .phys = 0,
33581@@ -328,7 +328,7 @@ not_enabled:
33582 }
33583 }
33584
33585-void mmiotrace_iounmap(volatile void __iomem *addr)
33586+void mmiotrace_iounmap(const volatile void __iomem *addr)
33587 {
33588 might_sleep();
33589 if (is_enabled()) /* recheck and proper locking in *_core() */
33590diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33591index a32b706..efb308b 100644
33592--- a/arch/x86/mm/numa.c
33593+++ b/arch/x86/mm/numa.c
33594@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33595 return true;
33596 }
33597
33598-static int __init numa_register_memblks(struct numa_meminfo *mi)
33599+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33600 {
33601 unsigned long uninitialized_var(pfn_align);
33602 int i, nid;
33603diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33604index ae242a7..1c7998f 100644
33605--- a/arch/x86/mm/pageattr.c
33606+++ b/arch/x86/mm/pageattr.c
33607@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33608 */
33609 #ifdef CONFIG_PCI_BIOS
33610 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33611- pgprot_val(forbidden) |= _PAGE_NX;
33612+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33613 #endif
33614
33615 /*
33616@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33617 * Does not cover __inittext since that is gone later on. On
33618 * 64bit we do not enforce !NX on the low mapping
33619 */
33620- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33621- pgprot_val(forbidden) |= _PAGE_NX;
33622+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33623+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33624
33625+#ifdef CONFIG_DEBUG_RODATA
33626 /*
33627 * The .rodata section needs to be read-only. Using the pfn
33628 * catches all aliases.
33629@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33630 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33631 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33632 pgprot_val(forbidden) |= _PAGE_RW;
33633+#endif
33634
33635 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33636 /*
33637@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33638 }
33639 #endif
33640
33641+#ifdef CONFIG_PAX_KERNEXEC
33642+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33643+ pgprot_val(forbidden) |= _PAGE_RW;
33644+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33645+ }
33646+#endif
33647+
33648 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33649
33650 return prot;
33651@@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33652 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33653 {
33654 /* change init_mm */
33655+ pax_open_kernel();
33656 set_pte_atomic(kpte, pte);
33657+
33658 #ifdef CONFIG_X86_32
33659 if (!SHARED_KERNEL_PMD) {
33660+
33661+#ifdef CONFIG_PAX_PER_CPU_PGD
33662+ unsigned long cpu;
33663+#else
33664 struct page *page;
33665+#endif
33666
33667+#ifdef CONFIG_PAX_PER_CPU_PGD
33668+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33669+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33670+#else
33671 list_for_each_entry(page, &pgd_list, lru) {
33672- pgd_t *pgd;
33673+ pgd_t *pgd = (pgd_t *)page_address(page);
33674+#endif
33675+
33676 pud_t *pud;
33677 pmd_t *pmd;
33678
33679- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33680+ pgd += pgd_index(address);
33681 pud = pud_offset(pgd, address);
33682 pmd = pmd_offset(pud, address);
33683 set_pte_atomic((pte_t *)pmd, pte);
33684 }
33685 }
33686 #endif
33687+ pax_close_kernel();
33688 }
33689
33690 static int
33691diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33692index 6574388..87e9bef 100644
33693--- a/arch/x86/mm/pat.c
33694+++ b/arch/x86/mm/pat.c
33695@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33696
33697 if (!entry) {
33698 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33699- current->comm, current->pid, start, end - 1);
33700+ current->comm, task_pid_nr(current), start, end - 1);
33701 return -EINVAL;
33702 }
33703
33704@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33705
33706 while (cursor < to) {
33707 if (!devmem_is_allowed(pfn)) {
33708- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33709- current->comm, from, to - 1);
33710+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33711+ current->comm, from, to - 1, cursor);
33712 return 0;
33713 }
33714 cursor += PAGE_SIZE;
33715@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33716 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33717 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33718 "for [mem %#010Lx-%#010Lx]\n",
33719- current->comm, current->pid,
33720+ current->comm, task_pid_nr(current),
33721 cattr_name(flags),
33722 base, (unsigned long long)(base + size-1));
33723 return -EINVAL;
33724@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33725 flags = lookup_memtype(paddr);
33726 if (want_flags != flags) {
33727 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33728- current->comm, current->pid,
33729+ current->comm, task_pid_nr(current),
33730 cattr_name(want_flags),
33731 (unsigned long long)paddr,
33732 (unsigned long long)(paddr + size - 1),
33733@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33734 free_memtype(paddr, paddr + size);
33735 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33736 " for [mem %#010Lx-%#010Lx], got %s\n",
33737- current->comm, current->pid,
33738+ current->comm, task_pid_nr(current),
33739 cattr_name(want_flags),
33740 (unsigned long long)paddr,
33741 (unsigned long long)(paddr + size - 1),
33742diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33743index 415f6c4..d319983 100644
33744--- a/arch/x86/mm/pat_rbtree.c
33745+++ b/arch/x86/mm/pat_rbtree.c
33746@@ -160,7 +160,7 @@ success:
33747
33748 failure:
33749 printk(KERN_INFO "%s:%d conflicting memory types "
33750- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33751+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33752 end, cattr_name(found_type), cattr_name(match->type));
33753 return -EBUSY;
33754 }
33755diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33756index 9f0614d..92ae64a 100644
33757--- a/arch/x86/mm/pf_in.c
33758+++ b/arch/x86/mm/pf_in.c
33759@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33760 int i;
33761 enum reason_type rv = OTHERS;
33762
33763- p = (unsigned char *)ins_addr;
33764+ p = (unsigned char *)ktla_ktva(ins_addr);
33765 p += skip_prefix(p, &prf);
33766 p += get_opcode(p, &opcode);
33767
33768@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33769 struct prefix_bits prf;
33770 int i;
33771
33772- p = (unsigned char *)ins_addr;
33773+ p = (unsigned char *)ktla_ktva(ins_addr);
33774 p += skip_prefix(p, &prf);
33775 p += get_opcode(p, &opcode);
33776
33777@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33778 struct prefix_bits prf;
33779 int i;
33780
33781- p = (unsigned char *)ins_addr;
33782+ p = (unsigned char *)ktla_ktva(ins_addr);
33783 p += skip_prefix(p, &prf);
33784 p += get_opcode(p, &opcode);
33785
33786@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33787 struct prefix_bits prf;
33788 int i;
33789
33790- p = (unsigned char *)ins_addr;
33791+ p = (unsigned char *)ktla_ktva(ins_addr);
33792 p += skip_prefix(p, &prf);
33793 p += get_opcode(p, &opcode);
33794 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33795@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33796 struct prefix_bits prf;
33797 int i;
33798
33799- p = (unsigned char *)ins_addr;
33800+ p = (unsigned char *)ktla_ktva(ins_addr);
33801 p += skip_prefix(p, &prf);
33802 p += get_opcode(p, &opcode);
33803 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33804diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33805index 6fb6927..4fc13c0 100644
33806--- a/arch/x86/mm/pgtable.c
33807+++ b/arch/x86/mm/pgtable.c
33808@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33809 list_del(&page->lru);
33810 }
33811
33812-#define UNSHARED_PTRS_PER_PGD \
33813- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33814+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33815+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33816
33817+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33818+{
33819+ unsigned int count = USER_PGD_PTRS;
33820
33821+ if (!pax_user_shadow_base)
33822+ return;
33823+
33824+ while (count--)
33825+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33826+}
33827+#endif
33828+
33829+#ifdef CONFIG_PAX_PER_CPU_PGD
33830+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33831+{
33832+ unsigned int count = USER_PGD_PTRS;
33833+
33834+ while (count--) {
33835+ pgd_t pgd;
33836+
33837+#ifdef CONFIG_X86_64
33838+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33839+#else
33840+ pgd = *src++;
33841+#endif
33842+
33843+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33844+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33845+#endif
33846+
33847+ *dst++ = pgd;
33848+ }
33849+
33850+}
33851+#endif
33852+
33853+#ifdef CONFIG_X86_64
33854+#define pxd_t pud_t
33855+#define pyd_t pgd_t
33856+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33857+#define pgtable_pxd_page_ctor(page) true
33858+#define pgtable_pxd_page_dtor(page)
33859+#define pxd_free(mm, pud) pud_free((mm), (pud))
33860+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33861+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33862+#define PYD_SIZE PGDIR_SIZE
33863+#else
33864+#define pxd_t pmd_t
33865+#define pyd_t pud_t
33866+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33867+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33868+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33869+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33870+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33871+#define pyd_offset(mm, address) pud_offset((mm), (address))
33872+#define PYD_SIZE PUD_SIZE
33873+#endif
33874+
33875+#ifdef CONFIG_PAX_PER_CPU_PGD
33876+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33877+static inline void pgd_dtor(pgd_t *pgd) {}
33878+#else
33879 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33880 {
33881 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33882@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33883 pgd_list_del(pgd);
33884 spin_unlock(&pgd_lock);
33885 }
33886+#endif
33887
33888 /*
33889 * List of all pgd's needed for non-PAE so it can invalidate entries
33890@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33891 * -- nyc
33892 */
33893
33894-#ifdef CONFIG_X86_PAE
33895+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33896 /*
33897 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33898 * updating the top-level pagetable entries to guarantee the
33899@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33900 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33901 * and initialize the kernel pmds here.
33902 */
33903-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33904+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33905
33906 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33907 {
33908@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33909 */
33910 flush_tlb_mm(mm);
33911 }
33912+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33913+#define PREALLOCATED_PXDS USER_PGD_PTRS
33914 #else /* !CONFIG_X86_PAE */
33915
33916 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33917-#define PREALLOCATED_PMDS 0
33918+#define PREALLOCATED_PXDS 0
33919
33920 #endif /* CONFIG_X86_PAE */
33921
33922-static void free_pmds(pmd_t *pmds[])
33923+static void free_pxds(pxd_t *pxds[])
33924 {
33925 int i;
33926
33927- for(i = 0; i < PREALLOCATED_PMDS; i++)
33928- if (pmds[i]) {
33929- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33930- free_page((unsigned long)pmds[i]);
33931+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33932+ if (pxds[i]) {
33933+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33934+ free_page((unsigned long)pxds[i]);
33935 }
33936 }
33937
33938-static int preallocate_pmds(pmd_t *pmds[])
33939+static int preallocate_pxds(pxd_t *pxds[])
33940 {
33941 int i;
33942 bool failed = false;
33943
33944- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33945- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33946- if (!pmd)
33947+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33948+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33949+ if (!pxd)
33950 failed = true;
33951- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33952- free_page((unsigned long)pmd);
33953- pmd = NULL;
33954+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33955+ free_page((unsigned long)pxd);
33956+ pxd = NULL;
33957 failed = true;
33958 }
33959- pmds[i] = pmd;
33960+ pxds[i] = pxd;
33961 }
33962
33963 if (failed) {
33964- free_pmds(pmds);
33965+ free_pxds(pxds);
33966 return -ENOMEM;
33967 }
33968
33969@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33970 * preallocate which never got a corresponding vma will need to be
33971 * freed manually.
33972 */
33973-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33974+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33975 {
33976 int i;
33977
33978- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33979+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33980 pgd_t pgd = pgdp[i];
33981
33982 if (pgd_val(pgd) != 0) {
33983- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33984+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33985
33986- pgdp[i] = native_make_pgd(0);
33987+ set_pgd(pgdp + i, native_make_pgd(0));
33988
33989- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33990- pmd_free(mm, pmd);
33991+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33992+ pxd_free(mm, pxd);
33993 }
33994 }
33995 }
33996
33997-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33998+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33999 {
34000- pud_t *pud;
34001+ pyd_t *pyd;
34002 int i;
34003
34004- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
34005+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
34006 return;
34007
34008- pud = pud_offset(pgd, 0);
34009-
34010- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
34011- pmd_t *pmd = pmds[i];
34012+#ifdef CONFIG_X86_64
34013+ pyd = pyd_offset(mm, 0L);
34014+#else
34015+ pyd = pyd_offset(pgd, 0L);
34016+#endif
34017
34018+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
34019+ pxd_t *pxd = pxds[i];
34020 if (i >= KERNEL_PGD_BOUNDARY)
34021- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34022- sizeof(pmd_t) * PTRS_PER_PMD);
34023+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34024+ sizeof(pxd_t) * PTRS_PER_PMD);
34025
34026- pud_populate(mm, pud, pmd);
34027+ pyd_populate(mm, pyd, pxd);
34028 }
34029 }
34030
34031 pgd_t *pgd_alloc(struct mm_struct *mm)
34032 {
34033 pgd_t *pgd;
34034- pmd_t *pmds[PREALLOCATED_PMDS];
34035+ pxd_t *pxds[PREALLOCATED_PXDS];
34036
34037 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
34038
34039@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34040
34041 mm->pgd = pgd;
34042
34043- if (preallocate_pmds(pmds) != 0)
34044+ if (preallocate_pxds(pxds) != 0)
34045 goto out_free_pgd;
34046
34047 if (paravirt_pgd_alloc(mm) != 0)
34048- goto out_free_pmds;
34049+ goto out_free_pxds;
34050
34051 /*
34052 * Make sure that pre-populating the pmds is atomic with
34053@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34054 spin_lock(&pgd_lock);
34055
34056 pgd_ctor(mm, pgd);
34057- pgd_prepopulate_pmd(mm, pgd, pmds);
34058+ pgd_prepopulate_pxd(mm, pgd, pxds);
34059
34060 spin_unlock(&pgd_lock);
34061
34062 return pgd;
34063
34064-out_free_pmds:
34065- free_pmds(pmds);
34066+out_free_pxds:
34067+ free_pxds(pxds);
34068 out_free_pgd:
34069 free_page((unsigned long)pgd);
34070 out:
34071@@ -313,7 +380,7 @@ out:
34072
34073 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34074 {
34075- pgd_mop_up_pmds(mm, pgd);
34076+ pgd_mop_up_pxds(mm, pgd);
34077 pgd_dtor(pgd);
34078 paravirt_pgd_free(mm, pgd);
34079 free_page((unsigned long)pgd);
34080diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34081index 4dd8cf6..f9d143e 100644
34082--- a/arch/x86/mm/pgtable_32.c
34083+++ b/arch/x86/mm/pgtable_32.c
34084@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34085 return;
34086 }
34087 pte = pte_offset_kernel(pmd, vaddr);
34088+
34089+ pax_open_kernel();
34090 if (pte_val(pteval))
34091 set_pte_at(&init_mm, vaddr, pte, pteval);
34092 else
34093 pte_clear(&init_mm, vaddr, pte);
34094+ pax_close_kernel();
34095
34096 /*
34097 * It's enough to flush this one mapping.
34098diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34099index e666cbb..61788c45 100644
34100--- a/arch/x86/mm/physaddr.c
34101+++ b/arch/x86/mm/physaddr.c
34102@@ -10,7 +10,7 @@
34103 #ifdef CONFIG_X86_64
34104
34105 #ifdef CONFIG_DEBUG_VIRTUAL
34106-unsigned long __phys_addr(unsigned long x)
34107+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34108 {
34109 unsigned long y = x - __START_KERNEL_map;
34110
34111@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34112 #else
34113
34114 #ifdef CONFIG_DEBUG_VIRTUAL
34115-unsigned long __phys_addr(unsigned long x)
34116+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34117 {
34118 unsigned long phys_addr = x - PAGE_OFFSET;
34119 /* VMALLOC_* aren't constants */
34120diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34121index 90555bf..f5f1828 100644
34122--- a/arch/x86/mm/setup_nx.c
34123+++ b/arch/x86/mm/setup_nx.c
34124@@ -5,8 +5,10 @@
34125 #include <asm/pgtable.h>
34126 #include <asm/proto.h>
34127
34128+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34129 static int disable_nx;
34130
34131+#ifndef CONFIG_PAX_PAGEEXEC
34132 /*
34133 * noexec = on|off
34134 *
34135@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34136 return 0;
34137 }
34138 early_param("noexec", noexec_setup);
34139+#endif
34140+
34141+#endif
34142
34143 void x86_configure_nx(void)
34144 {
34145+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34146 if (cpu_has_nx && !disable_nx)
34147 __supported_pte_mask |= _PAGE_NX;
34148 else
34149+#endif
34150 __supported_pte_mask &= ~_PAGE_NX;
34151 }
34152
34153diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34154index dd8dda1..9e9b0f6 100644
34155--- a/arch/x86/mm/tlb.c
34156+++ b/arch/x86/mm/tlb.c
34157@@ -48,7 +48,11 @@ void leave_mm(int cpu)
34158 BUG();
34159 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34160 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34161+
34162+#ifndef CONFIG_PAX_PER_CPU_PGD
34163 load_cr3(swapper_pg_dir);
34164+#endif
34165+
34166 }
34167 }
34168 EXPORT_SYMBOL_GPL(leave_mm);
34169diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34170new file mode 100644
34171index 0000000..dace51c
34172--- /dev/null
34173+++ b/arch/x86/mm/uderef_64.c
34174@@ -0,0 +1,37 @@
34175+#include <linux/mm.h>
34176+#include <asm/pgtable.h>
34177+#include <asm/uaccess.h>
34178+
34179+#ifdef CONFIG_PAX_MEMORY_UDEREF
34180+/* PaX: due to the special call convention these functions must
34181+ * - remain leaf functions under all configurations,
34182+ * - never be called directly, only dereferenced from the wrappers.
34183+ */
34184+void __pax_open_userland(void)
34185+{
34186+ unsigned int cpu;
34187+
34188+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34189+ return;
34190+
34191+ cpu = raw_get_cpu();
34192+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34193+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34194+ raw_put_cpu_no_resched();
34195+}
34196+EXPORT_SYMBOL(__pax_open_userland);
34197+
34198+void __pax_close_userland(void)
34199+{
34200+ unsigned int cpu;
34201+
34202+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34203+ return;
34204+
34205+ cpu = raw_get_cpu();
34206+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34207+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34208+ raw_put_cpu_no_resched();
34209+}
34210+EXPORT_SYMBOL(__pax_close_userland);
34211+#endif
34212diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34213index 6440221..f746de8 100644
34214--- a/arch/x86/net/bpf_jit.S
34215+++ b/arch/x86/net/bpf_jit.S
34216@@ -9,19 +9,17 @@
34217 */
34218 #include <linux/linkage.h>
34219 #include <asm/dwarf2.h>
34220+#include <asm/alternative-asm.h>
34221
34222 /*
34223 * Calling convention :
34224- * rbx : skb pointer (callee saved)
34225+ * rdi : skb pointer
34226 * esi : offset of byte(s) to fetch in skb (can be scratched)
34227- * r10 : copy of skb->data
34228+ * r8 : copy of skb->data
34229 * r9d : hlen = skb->len - skb->data_len
34230 */
34231-#define SKBDATA %r10
34232+#define SKBDATA %r8
34233 #define SKF_MAX_NEG_OFF $(-0x200000) /* SKF_LL_OFF from filter.h */
34234-#define MAX_BPF_STACK (512 /* from filter.h */ + \
34235- 32 /* space for rbx,r13,r14,r15 */ + \
34236- 8 /* space for skb_copy_bits */)
34237
34238 sk_load_word:
34239 .globl sk_load_word
34240@@ -38,6 +36,7 @@ sk_load_word_positive_offset:
34241 jle bpf_slow_path_word
34242 mov (SKBDATA,%rsi),%eax
34243 bswap %eax /* ntohl() */
34244+ pax_force_retaddr
34245 ret
34246
34247 sk_load_half:
34248@@ -55,6 +54,7 @@ sk_load_half_positive_offset:
34249 jle bpf_slow_path_half
34250 movzwl (SKBDATA,%rsi),%eax
34251 rol $8,%ax # ntohs()
34252+ pax_force_retaddr
34253 ret
34254
34255 sk_load_byte:
34256@@ -69,45 +69,83 @@ sk_load_byte_positive_offset:
34257 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34258 jle bpf_slow_path_byte
34259 movzbl (SKBDATA,%rsi),%eax
34260+ pax_force_retaddr
34261+ ret
34262+
34263+/**
34264+ * sk_load_byte_msh - BPF_S_LDX_B_MSH helper
34265+ *
34266+ * Implements BPF_S_LDX_B_MSH : ldxb 4*([offset]&0xf)
34267+ * Must preserve A accumulator (%eax)
34268+ * Inputs : %esi is the offset value
34269+ */
34270+sk_load_byte_msh:
34271+ .globl sk_load_byte_msh
34272+ test %esi,%esi
34273+ js bpf_slow_path_byte_msh_neg
34274+
34275+sk_load_byte_msh_positive_offset:
34276+ .globl sk_load_byte_msh_positive_offset
34277+ cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte_msh */
34278+ jle bpf_slow_path_byte_msh
34279+ movzbl (SKBDATA,%rsi),%ebx
34280+ and $15,%bl
34281+ shl $2,%bl
34282+ pax_force_retaddr
34283 ret
34284
34285 /* rsi contains offset and can be scratched */
34286 #define bpf_slow_path_common(LEN) \
34287- mov %rbx, %rdi; /* arg1 == skb */ \
34288+ push %rdi; /* save skb */ \
34289 push %r9; \
34290 push SKBDATA; \
34291 /* rsi already has offset */ \
34292 mov $LEN,%ecx; /* len */ \
34293- lea - MAX_BPF_STACK + 32(%rbp),%rdx; \
34294+ lea -12(%rbp),%rdx; \
34295 call skb_copy_bits; \
34296 test %eax,%eax; \
34297 pop SKBDATA; \
34298- pop %r9;
34299+ pop %r9; \
34300+ pop %rdi
34301
34302
34303 bpf_slow_path_word:
34304 bpf_slow_path_common(4)
34305 js bpf_error
34306- mov - MAX_BPF_STACK + 32(%rbp),%eax
34307+ mov -12(%rbp),%eax
34308 bswap %eax
34309+ pax_force_retaddr
34310 ret
34311
34312 bpf_slow_path_half:
34313 bpf_slow_path_common(2)
34314 js bpf_error
34315- mov - MAX_BPF_STACK + 32(%rbp),%ax
34316+ mov -12(%rbp),%ax
34317 rol $8,%ax
34318 movzwl %ax,%eax
34319+ pax_force_retaddr
34320 ret
34321
34322 bpf_slow_path_byte:
34323 bpf_slow_path_common(1)
34324 js bpf_error
34325- movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34326+ movzbl -12(%rbp),%eax
34327+ pax_force_retaddr
34328+ ret
34329+
34330+bpf_slow_path_byte_msh:
34331+ xchg %eax,%ebx /* dont lose A , X is about to be scratched */
34332+ bpf_slow_path_common(1)
34333+ js bpf_error
34334+ movzbl -12(%rbp),%eax
34335+ and $15,%al
34336+ shl $2,%al
34337+ xchg %eax,%ebx
34338+ pax_force_retaddr
34339 ret
34340
34341 #define sk_negative_common(SIZE) \
34342- mov %rbx, %rdi; /* arg1 == skb */ \
34343+ push %rdi; /* save skb */ \
34344 push %r9; \
34345 push SKBDATA; \
34346 /* rsi already has offset */ \
34347@@ -116,8 +154,10 @@ bpf_slow_path_byte:
34348 test %rax,%rax; \
34349 pop SKBDATA; \
34350 pop %r9; \
34351+ pop %rdi; \
34352 jz bpf_error
34353
34354+
34355 bpf_slow_path_word_neg:
34356 cmp SKF_MAX_NEG_OFF, %esi /* test range */
34357 jl bpf_error /* offset lower -> error */
34358@@ -126,6 +166,7 @@ sk_load_word_negative_offset:
34359 sk_negative_common(4)
34360 mov (%rax), %eax
34361 bswap %eax
34362+ pax_force_retaddr
34363 ret
34364
34365 bpf_slow_path_half_neg:
34366@@ -137,6 +178,7 @@ sk_load_half_negative_offset:
34367 mov (%rax),%ax
34368 rol $8,%ax
34369 movzwl %ax,%eax
34370+ pax_force_retaddr
34371 ret
34372
34373 bpf_slow_path_byte_neg:
34374@@ -146,14 +188,27 @@ sk_load_byte_negative_offset:
34375 .globl sk_load_byte_negative_offset
34376 sk_negative_common(1)
34377 movzbl (%rax), %eax
34378+ pax_force_retaddr
34379+ ret
34380+
34381+bpf_slow_path_byte_msh_neg:
34382+ cmp SKF_MAX_NEG_OFF, %esi
34383+ jl bpf_error
34384+sk_load_byte_msh_negative_offset:
34385+ .globl sk_load_byte_msh_negative_offset
34386+ xchg %eax,%ebx /* dont lose A , X is about to be scratched */
34387+ sk_negative_common(1)
34388+ movzbl (%rax),%eax
34389+ and $15,%al
34390+ shl $2,%al
34391+ xchg %eax,%ebx
34392+ pax_force_retaddr
34393 ret
34394
34395 bpf_error:
34396 # force a return 0 from jit handler
34397- xor %eax,%eax
34398- mov - MAX_BPF_STACK(%rbp),%rbx
34399- mov - MAX_BPF_STACK + 8(%rbp),%r13
34400- mov - MAX_BPF_STACK + 16(%rbp),%r14
34401- mov - MAX_BPF_STACK + 24(%rbp),%r15
34402+ xor %eax,%eax
34403+ mov -8(%rbp),%rbx
34404 leaveq
34405+ pax_force_retaddr
34406 ret
34407diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34408index 99bef86..bdfb5c6 100644
34409--- a/arch/x86/net/bpf_jit_comp.c
34410+++ b/arch/x86/net/bpf_jit_comp.c
34411@@ -1,7 +1,6 @@
34412 /* bpf_jit_comp.c : BPF JIT compiler
34413 *
34414 * Copyright (C) 2011-2013 Eric Dumazet (eric.dumazet@gmail.com)
34415- * Internal BPF Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
34416 *
34417 * This program is free software; you can redistribute it and/or
34418 * modify it under the terms of the GNU General Public License
34419@@ -15,16 +14,28 @@
34420 #include <linux/if_vlan.h>
34421 #include <linux/random.h>
34422
34423+/*
34424+ * Conventions :
34425+ * EAX : BPF A accumulator
34426+ * EBX : BPF X accumulator
34427+ * RDI : pointer to skb (first argument given to JIT function)
34428+ * RBP : frame pointer (even if CONFIG_FRAME_POINTER=n)
34429+ * ECX,EDX,ESI : scratch registers
34430+ * r9d : skb->len - skb->data_len (headlen)
34431+ * r8 : skb->data
34432+ * -8(RBP) : saved RBX value
34433+ * -16(RBP)..-80(RBP) : BPF_MEMWORDS values
34434+ */
34435 int bpf_jit_enable __read_mostly;
34436
34437 /*
34438 * assembly code in arch/x86/net/bpf_jit.S
34439 */
34440-extern u8 sk_load_word[], sk_load_half[], sk_load_byte[];
34441+extern u8 sk_load_word[], sk_load_half[], sk_load_byte[], sk_load_byte_msh[];
34442 extern u8 sk_load_word_positive_offset[], sk_load_half_positive_offset[];
34443-extern u8 sk_load_byte_positive_offset[];
34444+extern u8 sk_load_byte_positive_offset[], sk_load_byte_msh_positive_offset[];
34445 extern u8 sk_load_word_negative_offset[], sk_load_half_negative_offset[];
34446-extern u8 sk_load_byte_negative_offset[];
34447+extern u8 sk_load_byte_negative_offset[], sk_load_byte_msh_negative_offset[];
34448
34449 static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34450 {
34451@@ -39,50 +50,113 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34452 return ptr + len;
34453 }
34454
34455+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34456+#define MAX_INSTR_CODE_SIZE 96
34457+#else
34458+#define MAX_INSTR_CODE_SIZE 64
34459+#endif
34460+
34461 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
34462
34463 #define EMIT1(b1) EMIT(b1, 1)
34464 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
34465 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
34466 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
34467-#define EMIT1_off32(b1, off) \
34468- do {EMIT1(b1); EMIT(off, 4); } while (0)
34469-#define EMIT2_off32(b1, b2, off) \
34470- do {EMIT2(b1, b2); EMIT(off, 4); } while (0)
34471-#define EMIT3_off32(b1, b2, b3, off) \
34472- do {EMIT3(b1, b2, b3); EMIT(off, 4); } while (0)
34473-#define EMIT4_off32(b1, b2, b3, b4, off) \
34474- do {EMIT4(b1, b2, b3, b4); EMIT(off, 4); } while (0)
34475+
34476+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34477+/* original constant will appear in ecx */
34478+#define DILUTE_CONST_SEQUENCE(_off, _key) \
34479+do { \
34480+ /* mov ecx, randkey */ \
34481+ EMIT1(0xb9); \
34482+ EMIT(_key, 4); \
34483+ /* xor ecx, randkey ^ off */ \
34484+ EMIT2(0x81, 0xf1); \
34485+ EMIT((_key) ^ (_off), 4); \
34486+} while (0)
34487+
34488+#define EMIT1_off32(b1, _off) \
34489+do { \
34490+ switch (b1) { \
34491+ case 0x05: /* add eax, imm32 */ \
34492+ case 0x2d: /* sub eax, imm32 */ \
34493+ case 0x25: /* and eax, imm32 */ \
34494+ case 0x0d: /* or eax, imm32 */ \
34495+ case 0xb8: /* mov eax, imm32 */ \
34496+ case 0x35: /* xor eax, imm32 */ \
34497+ case 0x3d: /* cmp eax, imm32 */ \
34498+ case 0xa9: /* test eax, imm32 */ \
34499+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34500+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
34501+ break; \
34502+ case 0xbb: /* mov ebx, imm32 */ \
34503+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34504+ /* mov ebx, ecx */ \
34505+ EMIT2(0x89, 0xcb); \
34506+ break; \
34507+ case 0xbe: /* mov esi, imm32 */ \
34508+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34509+ /* mov esi, ecx */ \
34510+ EMIT2(0x89, 0xce); \
34511+ break; \
34512+ case 0xe8: /* call rel imm32, always to known funcs */ \
34513+ EMIT1(b1); \
34514+ EMIT(_off, 4); \
34515+ break; \
34516+ case 0xe9: /* jmp rel imm32 */ \
34517+ EMIT1(b1); \
34518+ EMIT(_off, 4); \
34519+ /* prevent fall-through, we're not called if off = 0 */ \
34520+ EMIT(0xcccccccc, 4); \
34521+ EMIT(0xcccccccc, 4); \
34522+ break; \
34523+ default: \
34524+ BUILD_BUG(); \
34525+ } \
34526+} while (0)
34527+
34528+#define EMIT2_off32(b1, b2, _off) \
34529+do { \
34530+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
34531+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
34532+ EMIT(randkey, 4); \
34533+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
34534+ EMIT((_off) - randkey, 4); \
34535+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
34536+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34537+ /* imul eax, ecx */ \
34538+ EMIT3(0x0f, 0xaf, 0xc1); \
34539+ } else { \
34540+ BUILD_BUG(); \
34541+ } \
34542+} while (0)
34543+#else
34544+#define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
34545+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
34546+#endif
34547+
34548+#define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
34549+#define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
34550
34551 static inline bool is_imm8(int value)
34552 {
34553 return value <= 127 && value >= -128;
34554 }
34555
34556-static inline bool is_simm32(s64 value)
34557+static inline bool is_near(int offset)
34558 {
34559- return value == (s64) (s32) value;
34560+ return offset <= 127 && offset >= -128;
34561 }
34562
34563-/* mov dst, src */
34564-#define EMIT_mov(DST, SRC) \
34565- do {if (DST != SRC) \
34566- EMIT3(add_2mod(0x48, DST, SRC), 0x89, add_2reg(0xC0, DST, SRC)); \
34567- } while (0)
34568-
34569-static int bpf_size_to_x86_bytes(int bpf_size)
34570-{
34571- if (bpf_size == BPF_W)
34572- return 4;
34573- else if (bpf_size == BPF_H)
34574- return 2;
34575- else if (bpf_size == BPF_B)
34576- return 1;
34577- else if (bpf_size == BPF_DW)
34578- return 4; /* imm32 */
34579- else
34580- return 0;
34581-}
34582+#define EMIT_JMP(offset) \
34583+do { \
34584+ if (offset) { \
34585+ if (is_near(offset)) \
34586+ EMIT2(0xeb, offset); /* jmp .+off8 */ \
34587+ else \
34588+ EMIT1_off32(0xe9, offset); /* jmp .+off32 */ \
34589+ } \
34590+} while (0)
34591
34592 /* list of x86 cond jumps opcodes (. + s8)
34593 * Add 0x10 (and an extra 0x0f) to generate far jumps (. + s32)
34594@@ -93,8 +167,46 @@ static int bpf_size_to_x86_bytes(int bpf_size)
34595 #define X86_JNE 0x75
34596 #define X86_JBE 0x76
34597 #define X86_JA 0x77
34598-#define X86_JGE 0x7D
34599-#define X86_JG 0x7F
34600+
34601+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34602+#define APPEND_FLOW_VERIFY() \
34603+do { \
34604+ /* mov ecx, randkey */ \
34605+ EMIT1(0xb9); \
34606+ EMIT(randkey, 4); \
34607+ /* cmp ecx, randkey */ \
34608+ EMIT2(0x81, 0xf9); \
34609+ EMIT(randkey, 4); \
34610+ /* jz after 8 int 3s */ \
34611+ EMIT2(0x74, 0x08); \
34612+ EMIT(0xcccccccc, 4); \
34613+ EMIT(0xcccccccc, 4); \
34614+} while (0)
34615+#else
34616+#define APPEND_FLOW_VERIFY() do { } while (0)
34617+#endif
34618+
34619+#define EMIT_COND_JMP(op, offset) \
34620+do { \
34621+ if (is_near(offset)) \
34622+ EMIT2(op, offset); /* jxx .+off8 */ \
34623+ else { \
34624+ EMIT2(0x0f, op + 0x10); \
34625+ EMIT(offset, 4); /* jxx .+off32 */ \
34626+ APPEND_FLOW_VERIFY(); \
34627+ } \
34628+} while (0)
34629+
34630+#define COND_SEL(CODE, TOP, FOP) \
34631+ case CODE: \
34632+ t_op = TOP; \
34633+ f_op = FOP; \
34634+ goto cond_branch
34635+
34636+
34637+#define SEEN_DATAREF 1 /* might call external helpers */
34638+#define SEEN_XREG 2 /* ebx is used */
34639+#define SEEN_MEM 4 /* use mem[] for temporary storage */
34640
34641 static inline void bpf_flush_icache(void *start, void *end)
34642 {
34643@@ -109,804 +221,646 @@ static inline void bpf_flush_icache(void *start, void *end)
34644 #define CHOOSE_LOAD_FUNC(K, func) \
34645 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
34646
34647-struct bpf_binary_header {
34648- unsigned int pages;
34649- /* Note : for security reasons, bpf code will follow a randomly
34650- * sized amount of int3 instructions
34651- */
34652- u8 image[];
34653-};
34654+/* Helper to find the offset of pkt_type in sk_buff
34655+ * We want to make sure its still a 3bit field starting at a byte boundary.
34656+ */
34657+#define PKT_TYPE_MAX 7
34658+static int pkt_type_offset(void)
34659+{
34660+ struct sk_buff skb_probe = {
34661+ .pkt_type = ~0,
34662+ };
34663+ char *ct = (char *)&skb_probe;
34664+ unsigned int off;
34665
34666-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34667+ for (off = 0; off < sizeof(struct sk_buff); off++) {
34668+ if (ct[off] == PKT_TYPE_MAX)
34669+ return off;
34670+ }
34671+ pr_err_once("Please fix pkt_type_offset(), as pkt_type couldn't be found\n");
34672+ return -1;
34673+}
34674+
34675+/* Note : for security reasons, bpf code will follow a randomly
34676+ * sized amount of int3 instructions
34677+ */
34678+static u8 *bpf_alloc_binary(unsigned int proglen,
34679 u8 **image_ptr)
34680 {
34681 unsigned int sz, hole;
34682- struct bpf_binary_header *header;
34683+ u8 *header;
34684
34685 /* Most of BPF filters are really small,
34686 * but if some of them fill a page, allow at least
34687 * 128 extra bytes to insert a random section of int3
34688 */
34689- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34690- header = module_alloc(sz);
34691+ sz = round_up(proglen + 128, PAGE_SIZE);
34692+ header = module_alloc_exec(sz);
34693 if (!header)
34694 return NULL;
34695
34696+ pax_open_kernel();
34697 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34698+ pax_close_kernel();
34699
34700- header->pages = sz / PAGE_SIZE;
34701- hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34702+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34703
34704 /* insert a random number of int3 instructions before BPF code */
34705- *image_ptr = &header->image[prandom_u32() % hole];
34706+ *image_ptr = &header[prandom_u32() % hole];
34707 return header;
34708 }
34709
34710-/* pick a register outside of BPF range for JIT internal work */
34711-#define AUX_REG (MAX_BPF_REG + 1)
34712-
34713-/* the following table maps BPF registers to x64 registers.
34714- * x64 register r12 is unused, since if used as base address register
34715- * in load/store instructions, it always needs an extra byte of encoding
34716- */
34717-static const int reg2hex[] = {
34718- [BPF_REG_0] = 0, /* rax */
34719- [BPF_REG_1] = 7, /* rdi */
34720- [BPF_REG_2] = 6, /* rsi */
34721- [BPF_REG_3] = 2, /* rdx */
34722- [BPF_REG_4] = 1, /* rcx */
34723- [BPF_REG_5] = 0, /* r8 */
34724- [BPF_REG_6] = 3, /* rbx callee saved */
34725- [BPF_REG_7] = 5, /* r13 callee saved */
34726- [BPF_REG_8] = 6, /* r14 callee saved */
34727- [BPF_REG_9] = 7, /* r15 callee saved */
34728- [BPF_REG_FP] = 5, /* rbp readonly */
34729- [AUX_REG] = 3, /* r11 temp register */
34730-};
34731-
34732-/* is_ereg() == true if BPF register 'reg' maps to x64 r8..r15
34733- * which need extra byte of encoding.
34734- * rax,rcx,...,rbp have simpler encoding
34735- */
34736-static inline bool is_ereg(u32 reg)
34737-{
34738- if (reg == BPF_REG_5 || reg == AUX_REG ||
34739- (reg >= BPF_REG_7 && reg <= BPF_REG_9))
34740- return true;
34741- else
34742- return false;
34743-}
34744-
34745-/* add modifiers if 'reg' maps to x64 registers r8..r15 */
34746-static inline u8 add_1mod(u8 byte, u32 reg)
34747-{
34748- if (is_ereg(reg))
34749- byte |= 1;
34750- return byte;
34751-}
34752-
34753-static inline u8 add_2mod(u8 byte, u32 r1, u32 r2)
34754-{
34755- if (is_ereg(r1))
34756- byte |= 1;
34757- if (is_ereg(r2))
34758- byte |= 4;
34759- return byte;
34760-}
34761-
34762-/* encode 'dst_reg' register into x64 opcode 'byte' */
34763-static inline u8 add_1reg(u8 byte, u32 dst_reg)
34764-{
34765- return byte + reg2hex[dst_reg];
34766-}
34767-
34768-/* encode 'dst_reg' and 'src_reg' registers into x64 opcode 'byte' */
34769-static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
34770-{
34771- return byte + reg2hex[dst_reg] + (reg2hex[src_reg] << 3);
34772-}
34773-
34774-struct jit_context {
34775- unsigned int cleanup_addr; /* epilogue code offset */
34776- bool seen_ld_abs;
34777-};
34778-
34779-static int do_jit(struct sk_filter *bpf_prog, int *addrs, u8 *image,
34780- int oldproglen, struct jit_context *ctx)
34781-{
34782- struct sock_filter_int *insn = bpf_prog->insnsi;
34783- int insn_cnt = bpf_prog->len;
34784- u8 temp[64];
34785- int i;
34786- int proglen = 0;
34787- u8 *prog = temp;
34788- int stacksize = MAX_BPF_STACK +
34789- 32 /* space for rbx, r13, r14, r15 */ +
34790- 8 /* space for skb_copy_bits() buffer */;
34791-
34792- EMIT1(0x55); /* push rbp */
34793- EMIT3(0x48, 0x89, 0xE5); /* mov rbp,rsp */
34794-
34795- /* sub rsp, stacksize */
34796- EMIT3_off32(0x48, 0x81, 0xEC, stacksize);
34797-
34798- /* all classic BPF filters use R6(rbx) save it */
34799-
34800- /* mov qword ptr [rbp-X],rbx */
34801- EMIT3_off32(0x48, 0x89, 0x9D, -stacksize);
34802-
34803- /* sk_convert_filter() maps classic BPF register X to R7 and uses R8
34804- * as temporary, so all tcpdump filters need to spill/fill R7(r13) and
34805- * R8(r14). R9(r15) spill could be made conditional, but there is only
34806- * one 'bpf_error' return path out of helper functions inside bpf_jit.S
34807- * The overhead of extra spill is negligible for any filter other
34808- * than synthetic ones. Therefore not worth adding complexity.
34809- */
34810-
34811- /* mov qword ptr [rbp-X],r13 */
34812- EMIT3_off32(0x4C, 0x89, 0xAD, -stacksize + 8);
34813- /* mov qword ptr [rbp-X],r14 */
34814- EMIT3_off32(0x4C, 0x89, 0xB5, -stacksize + 16);
34815- /* mov qword ptr [rbp-X],r15 */
34816- EMIT3_off32(0x4C, 0x89, 0xBD, -stacksize + 24);
34817-
34818- /* clear A and X registers */
34819- EMIT2(0x31, 0xc0); /* xor eax, eax */
34820- EMIT3(0x4D, 0x31, 0xED); /* xor r13, r13 */
34821-
34822- if (ctx->seen_ld_abs) {
34823- /* r9d : skb->len - skb->data_len (headlen)
34824- * r10 : skb->data
34825- */
34826- if (is_imm8(offsetof(struct sk_buff, len)))
34827- /* mov %r9d, off8(%rdi) */
34828- EMIT4(0x44, 0x8b, 0x4f,
34829- offsetof(struct sk_buff, len));
34830- else
34831- /* mov %r9d, off32(%rdi) */
34832- EMIT3_off32(0x44, 0x8b, 0x8f,
34833- offsetof(struct sk_buff, len));
34834-
34835- if (is_imm8(offsetof(struct sk_buff, data_len)))
34836- /* sub %r9d, off8(%rdi) */
34837- EMIT4(0x44, 0x2b, 0x4f,
34838- offsetof(struct sk_buff, data_len));
34839- else
34840- EMIT3_off32(0x44, 0x2b, 0x8f,
34841- offsetof(struct sk_buff, data_len));
34842-
34843- if (is_imm8(offsetof(struct sk_buff, data)))
34844- /* mov %r10, off8(%rdi) */
34845- EMIT4(0x4c, 0x8b, 0x57,
34846- offsetof(struct sk_buff, data));
34847- else
34848- /* mov %r10, off32(%rdi) */
34849- EMIT3_off32(0x4c, 0x8b, 0x97,
34850- offsetof(struct sk_buff, data));
34851- }
34852-
34853- for (i = 0; i < insn_cnt; i++, insn++) {
34854- const s32 imm32 = insn->imm;
34855- u32 dst_reg = insn->dst_reg;
34856- u32 src_reg = insn->src_reg;
34857- u8 b1 = 0, b2 = 0, b3 = 0;
34858- s64 jmp_offset;
34859- u8 jmp_cond;
34860- int ilen;
34861- u8 *func;
34862-
34863- switch (insn->code) {
34864- /* ALU */
34865- case BPF_ALU | BPF_ADD | BPF_X:
34866- case BPF_ALU | BPF_SUB | BPF_X:
34867- case BPF_ALU | BPF_AND | BPF_X:
34868- case BPF_ALU | BPF_OR | BPF_X:
34869- case BPF_ALU | BPF_XOR | BPF_X:
34870- case BPF_ALU64 | BPF_ADD | BPF_X:
34871- case BPF_ALU64 | BPF_SUB | BPF_X:
34872- case BPF_ALU64 | BPF_AND | BPF_X:
34873- case BPF_ALU64 | BPF_OR | BPF_X:
34874- case BPF_ALU64 | BPF_XOR | BPF_X:
34875- switch (BPF_OP(insn->code)) {
34876- case BPF_ADD: b2 = 0x01; break;
34877- case BPF_SUB: b2 = 0x29; break;
34878- case BPF_AND: b2 = 0x21; break;
34879- case BPF_OR: b2 = 0x09; break;
34880- case BPF_XOR: b2 = 0x31; break;
34881- }
34882- if (BPF_CLASS(insn->code) == BPF_ALU64)
34883- EMIT1(add_2mod(0x48, dst_reg, src_reg));
34884- else if (is_ereg(dst_reg) || is_ereg(src_reg))
34885- EMIT1(add_2mod(0x40, dst_reg, src_reg));
34886- EMIT2(b2, add_2reg(0xC0, dst_reg, src_reg));
34887- break;
34888-
34889- /* mov dst, src */
34890- case BPF_ALU64 | BPF_MOV | BPF_X:
34891- EMIT_mov(dst_reg, src_reg);
34892- break;
34893-
34894- /* mov32 dst, src */
34895- case BPF_ALU | BPF_MOV | BPF_X:
34896- if (is_ereg(dst_reg) || is_ereg(src_reg))
34897- EMIT1(add_2mod(0x40, dst_reg, src_reg));
34898- EMIT2(0x89, add_2reg(0xC0, dst_reg, src_reg));
34899- break;
34900-
34901- /* neg dst */
34902- case BPF_ALU | BPF_NEG:
34903- case BPF_ALU64 | BPF_NEG:
34904- if (BPF_CLASS(insn->code) == BPF_ALU64)
34905- EMIT1(add_1mod(0x48, dst_reg));
34906- else if (is_ereg(dst_reg))
34907- EMIT1(add_1mod(0x40, dst_reg));
34908- EMIT2(0xF7, add_1reg(0xD8, dst_reg));
34909- break;
34910-
34911- case BPF_ALU | BPF_ADD | BPF_K:
34912- case BPF_ALU | BPF_SUB | BPF_K:
34913- case BPF_ALU | BPF_AND | BPF_K:
34914- case BPF_ALU | BPF_OR | BPF_K:
34915- case BPF_ALU | BPF_XOR | BPF_K:
34916- case BPF_ALU64 | BPF_ADD | BPF_K:
34917- case BPF_ALU64 | BPF_SUB | BPF_K:
34918- case BPF_ALU64 | BPF_AND | BPF_K:
34919- case BPF_ALU64 | BPF_OR | BPF_K:
34920- case BPF_ALU64 | BPF_XOR | BPF_K:
34921- if (BPF_CLASS(insn->code) == BPF_ALU64)
34922- EMIT1(add_1mod(0x48, dst_reg));
34923- else if (is_ereg(dst_reg))
34924- EMIT1(add_1mod(0x40, dst_reg));
34925-
34926- switch (BPF_OP(insn->code)) {
34927- case BPF_ADD: b3 = 0xC0; break;
34928- case BPF_SUB: b3 = 0xE8; break;
34929- case BPF_AND: b3 = 0xE0; break;
34930- case BPF_OR: b3 = 0xC8; break;
34931- case BPF_XOR: b3 = 0xF0; break;
34932- }
34933-
34934- if (is_imm8(imm32))
34935- EMIT3(0x83, add_1reg(b3, dst_reg), imm32);
34936- else
34937- EMIT2_off32(0x81, add_1reg(b3, dst_reg), imm32);
34938- break;
34939-
34940- case BPF_ALU64 | BPF_MOV | BPF_K:
34941- /* optimization: if imm32 is positive,
34942- * use 'mov eax, imm32' (which zero-extends imm32)
34943- * to save 2 bytes
34944- */
34945- if (imm32 < 0) {
34946- /* 'mov rax, imm32' sign extends imm32 */
34947- b1 = add_1mod(0x48, dst_reg);
34948- b2 = 0xC7;
34949- b3 = 0xC0;
34950- EMIT3_off32(b1, b2, add_1reg(b3, dst_reg), imm32);
34951- break;
34952- }
34953-
34954- case BPF_ALU | BPF_MOV | BPF_K:
34955- /* mov %eax, imm32 */
34956- if (is_ereg(dst_reg))
34957- EMIT1(add_1mod(0x40, dst_reg));
34958- EMIT1_off32(add_1reg(0xB8, dst_reg), imm32);
34959- break;
34960-
34961- /* dst %= src, dst /= src, dst %= imm32, dst /= imm32 */
34962- case BPF_ALU | BPF_MOD | BPF_X:
34963- case BPF_ALU | BPF_DIV | BPF_X:
34964- case BPF_ALU | BPF_MOD | BPF_K:
34965- case BPF_ALU | BPF_DIV | BPF_K:
34966- case BPF_ALU64 | BPF_MOD | BPF_X:
34967- case BPF_ALU64 | BPF_DIV | BPF_X:
34968- case BPF_ALU64 | BPF_MOD | BPF_K:
34969- case BPF_ALU64 | BPF_DIV | BPF_K:
34970- EMIT1(0x50); /* push rax */
34971- EMIT1(0x52); /* push rdx */
34972-
34973- if (BPF_SRC(insn->code) == BPF_X)
34974- /* mov r11, src_reg */
34975- EMIT_mov(AUX_REG, src_reg);
34976- else
34977- /* mov r11, imm32 */
34978- EMIT3_off32(0x49, 0xC7, 0xC3, imm32);
34979-
34980- /* mov rax, dst_reg */
34981- EMIT_mov(BPF_REG_0, dst_reg);
34982-
34983- /* xor edx, edx
34984- * equivalent to 'xor rdx, rdx', but one byte less
34985- */
34986- EMIT2(0x31, 0xd2);
34987-
34988- if (BPF_SRC(insn->code) == BPF_X) {
34989- /* if (src_reg == 0) return 0 */
34990-
34991- /* cmp r11, 0 */
34992- EMIT4(0x49, 0x83, 0xFB, 0x00);
34993-
34994- /* jne .+9 (skip over pop, pop, xor and jmp) */
34995- EMIT2(X86_JNE, 1 + 1 + 2 + 5);
34996- EMIT1(0x5A); /* pop rdx */
34997- EMIT1(0x58); /* pop rax */
34998- EMIT2(0x31, 0xc0); /* xor eax, eax */
34999-
35000- /* jmp cleanup_addr
35001- * addrs[i] - 11, because there are 11 bytes
35002- * after this insn: div, mov, pop, pop, mov
35003- */
35004- jmp_offset = ctx->cleanup_addr - (addrs[i] - 11);
35005- EMIT1_off32(0xE9, jmp_offset);
35006- }
35007-
35008- if (BPF_CLASS(insn->code) == BPF_ALU64)
35009- /* div r11 */
35010- EMIT3(0x49, 0xF7, 0xF3);
35011- else
35012- /* div r11d */
35013- EMIT3(0x41, 0xF7, 0xF3);
35014-
35015- if (BPF_OP(insn->code) == BPF_MOD)
35016- /* mov r11, rdx */
35017- EMIT3(0x49, 0x89, 0xD3);
35018- else
35019- /* mov r11, rax */
35020- EMIT3(0x49, 0x89, 0xC3);
35021-
35022- EMIT1(0x5A); /* pop rdx */
35023- EMIT1(0x58); /* pop rax */
35024-
35025- /* mov dst_reg, r11 */
35026- EMIT_mov(dst_reg, AUX_REG);
35027- break;
35028-
35029- case BPF_ALU | BPF_MUL | BPF_K:
35030- case BPF_ALU | BPF_MUL | BPF_X:
35031- case BPF_ALU64 | BPF_MUL | BPF_K:
35032- case BPF_ALU64 | BPF_MUL | BPF_X:
35033- EMIT1(0x50); /* push rax */
35034- EMIT1(0x52); /* push rdx */
35035-
35036- /* mov r11, dst_reg */
35037- EMIT_mov(AUX_REG, dst_reg);
35038-
35039- if (BPF_SRC(insn->code) == BPF_X)
35040- /* mov rax, src_reg */
35041- EMIT_mov(BPF_REG_0, src_reg);
35042- else
35043- /* mov rax, imm32 */
35044- EMIT3_off32(0x48, 0xC7, 0xC0, imm32);
35045-
35046- if (BPF_CLASS(insn->code) == BPF_ALU64)
35047- EMIT1(add_1mod(0x48, AUX_REG));
35048- else if (is_ereg(AUX_REG))
35049- EMIT1(add_1mod(0x40, AUX_REG));
35050- /* mul(q) r11 */
35051- EMIT2(0xF7, add_1reg(0xE0, AUX_REG));
35052-
35053- /* mov r11, rax */
35054- EMIT_mov(AUX_REG, BPF_REG_0);
35055-
35056- EMIT1(0x5A); /* pop rdx */
35057- EMIT1(0x58); /* pop rax */
35058-
35059- /* mov dst_reg, r11 */
35060- EMIT_mov(dst_reg, AUX_REG);
35061- break;
35062-
35063- /* shifts */
35064- case BPF_ALU | BPF_LSH | BPF_K:
35065- case BPF_ALU | BPF_RSH | BPF_K:
35066- case BPF_ALU | BPF_ARSH | BPF_K:
35067- case BPF_ALU64 | BPF_LSH | BPF_K:
35068- case BPF_ALU64 | BPF_RSH | BPF_K:
35069- case BPF_ALU64 | BPF_ARSH | BPF_K:
35070- if (BPF_CLASS(insn->code) == BPF_ALU64)
35071- EMIT1(add_1mod(0x48, dst_reg));
35072- else if (is_ereg(dst_reg))
35073- EMIT1(add_1mod(0x40, dst_reg));
35074-
35075- switch (BPF_OP(insn->code)) {
35076- case BPF_LSH: b3 = 0xE0; break;
35077- case BPF_RSH: b3 = 0xE8; break;
35078- case BPF_ARSH: b3 = 0xF8; break;
35079- }
35080- EMIT3(0xC1, add_1reg(b3, dst_reg), imm32);
35081- break;
35082-
35083- case BPF_ALU | BPF_END | BPF_FROM_BE:
35084- switch (imm32) {
35085- case 16:
35086- /* emit 'ror %ax, 8' to swap lower 2 bytes */
35087- EMIT1(0x66);
35088- if (is_ereg(dst_reg))
35089- EMIT1(0x41);
35090- EMIT3(0xC1, add_1reg(0xC8, dst_reg), 8);
35091- break;
35092- case 32:
35093- /* emit 'bswap eax' to swap lower 4 bytes */
35094- if (is_ereg(dst_reg))
35095- EMIT2(0x41, 0x0F);
35096- else
35097- EMIT1(0x0F);
35098- EMIT1(add_1reg(0xC8, dst_reg));
35099- break;
35100- case 64:
35101- /* emit 'bswap rax' to swap 8 bytes */
35102- EMIT3(add_1mod(0x48, dst_reg), 0x0F,
35103- add_1reg(0xC8, dst_reg));
35104- break;
35105- }
35106- break;
35107-
35108- case BPF_ALU | BPF_END | BPF_FROM_LE:
35109- break;
35110-
35111- /* ST: *(u8*)(dst_reg + off) = imm */
35112- case BPF_ST | BPF_MEM | BPF_B:
35113- if (is_ereg(dst_reg))
35114- EMIT2(0x41, 0xC6);
35115- else
35116- EMIT1(0xC6);
35117- goto st;
35118- case BPF_ST | BPF_MEM | BPF_H:
35119- if (is_ereg(dst_reg))
35120- EMIT3(0x66, 0x41, 0xC7);
35121- else
35122- EMIT2(0x66, 0xC7);
35123- goto st;
35124- case BPF_ST | BPF_MEM | BPF_W:
35125- if (is_ereg(dst_reg))
35126- EMIT2(0x41, 0xC7);
35127- else
35128- EMIT1(0xC7);
35129- goto st;
35130- case BPF_ST | BPF_MEM | BPF_DW:
35131- EMIT2(add_1mod(0x48, dst_reg), 0xC7);
35132-
35133-st: if (is_imm8(insn->off))
35134- EMIT2(add_1reg(0x40, dst_reg), insn->off);
35135- else
35136- EMIT1_off32(add_1reg(0x80, dst_reg), insn->off);
35137-
35138- EMIT(imm32, bpf_size_to_x86_bytes(BPF_SIZE(insn->code)));
35139- break;
35140-
35141- /* STX: *(u8*)(dst_reg + off) = src_reg */
35142- case BPF_STX | BPF_MEM | BPF_B:
35143- /* emit 'mov byte ptr [rax + off], al' */
35144- if (is_ereg(dst_reg) || is_ereg(src_reg) ||
35145- /* have to add extra byte for x86 SIL, DIL regs */
35146- src_reg == BPF_REG_1 || src_reg == BPF_REG_2)
35147- EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x88);
35148- else
35149- EMIT1(0x88);
35150- goto stx;
35151- case BPF_STX | BPF_MEM | BPF_H:
35152- if (is_ereg(dst_reg) || is_ereg(src_reg))
35153- EMIT3(0x66, add_2mod(0x40, dst_reg, src_reg), 0x89);
35154- else
35155- EMIT2(0x66, 0x89);
35156- goto stx;
35157- case BPF_STX | BPF_MEM | BPF_W:
35158- if (is_ereg(dst_reg) || is_ereg(src_reg))
35159- EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x89);
35160- else
35161- EMIT1(0x89);
35162- goto stx;
35163- case BPF_STX | BPF_MEM | BPF_DW:
35164- EMIT2(add_2mod(0x48, dst_reg, src_reg), 0x89);
35165-stx: if (is_imm8(insn->off))
35166- EMIT2(add_2reg(0x40, dst_reg, src_reg), insn->off);
35167- else
35168- EMIT1_off32(add_2reg(0x80, dst_reg, src_reg),
35169- insn->off);
35170- break;
35171-
35172- /* LDX: dst_reg = *(u8*)(src_reg + off) */
35173- case BPF_LDX | BPF_MEM | BPF_B:
35174- /* emit 'movzx rax, byte ptr [rax + off]' */
35175- EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB6);
35176- goto ldx;
35177- case BPF_LDX | BPF_MEM | BPF_H:
35178- /* emit 'movzx rax, word ptr [rax + off]' */
35179- EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB7);
35180- goto ldx;
35181- case BPF_LDX | BPF_MEM | BPF_W:
35182- /* emit 'mov eax, dword ptr [rax+0x14]' */
35183- if (is_ereg(dst_reg) || is_ereg(src_reg))
35184- EMIT2(add_2mod(0x40, src_reg, dst_reg), 0x8B);
35185- else
35186- EMIT1(0x8B);
35187- goto ldx;
35188- case BPF_LDX | BPF_MEM | BPF_DW:
35189- /* emit 'mov rax, qword ptr [rax+0x14]' */
35190- EMIT2(add_2mod(0x48, src_reg, dst_reg), 0x8B);
35191-ldx: /* if insn->off == 0 we can save one extra byte, but
35192- * special case of x86 r13 which always needs an offset
35193- * is not worth the hassle
35194- */
35195- if (is_imm8(insn->off))
35196- EMIT2(add_2reg(0x40, src_reg, dst_reg), insn->off);
35197- else
35198- EMIT1_off32(add_2reg(0x80, src_reg, dst_reg),
35199- insn->off);
35200- break;
35201-
35202- /* STX XADD: lock *(u32*)(dst_reg + off) += src_reg */
35203- case BPF_STX | BPF_XADD | BPF_W:
35204- /* emit 'lock add dword ptr [rax + off], eax' */
35205- if (is_ereg(dst_reg) || is_ereg(src_reg))
35206- EMIT3(0xF0, add_2mod(0x40, dst_reg, src_reg), 0x01);
35207- else
35208- EMIT2(0xF0, 0x01);
35209- goto xadd;
35210- case BPF_STX | BPF_XADD | BPF_DW:
35211- EMIT3(0xF0, add_2mod(0x48, dst_reg, src_reg), 0x01);
35212-xadd: if (is_imm8(insn->off))
35213- EMIT2(add_2reg(0x40, dst_reg, src_reg), insn->off);
35214- else
35215- EMIT1_off32(add_2reg(0x80, dst_reg, src_reg),
35216- insn->off);
35217- break;
35218-
35219- /* call */
35220- case BPF_JMP | BPF_CALL:
35221- func = (u8 *) __bpf_call_base + imm32;
35222- jmp_offset = func - (image + addrs[i]);
35223- if (ctx->seen_ld_abs) {
35224- EMIT2(0x41, 0x52); /* push %r10 */
35225- EMIT2(0x41, 0x51); /* push %r9 */
35226- /* need to adjust jmp offset, since
35227- * pop %r9, pop %r10 take 4 bytes after call insn
35228- */
35229- jmp_offset += 4;
35230- }
35231- if (!imm32 || !is_simm32(jmp_offset)) {
35232- pr_err("unsupported bpf func %d addr %p image %p\n",
35233- imm32, func, image);
35234- return -EINVAL;
35235- }
35236- EMIT1_off32(0xE8, jmp_offset);
35237- if (ctx->seen_ld_abs) {
35238- EMIT2(0x41, 0x59); /* pop %r9 */
35239- EMIT2(0x41, 0x5A); /* pop %r10 */
35240- }
35241- break;
35242-
35243- /* cond jump */
35244- case BPF_JMP | BPF_JEQ | BPF_X:
35245- case BPF_JMP | BPF_JNE | BPF_X:
35246- case BPF_JMP | BPF_JGT | BPF_X:
35247- case BPF_JMP | BPF_JGE | BPF_X:
35248- case BPF_JMP | BPF_JSGT | BPF_X:
35249- case BPF_JMP | BPF_JSGE | BPF_X:
35250- /* cmp dst_reg, src_reg */
35251- EMIT3(add_2mod(0x48, dst_reg, src_reg), 0x39,
35252- add_2reg(0xC0, dst_reg, src_reg));
35253- goto emit_cond_jmp;
35254-
35255- case BPF_JMP | BPF_JSET | BPF_X:
35256- /* test dst_reg, src_reg */
35257- EMIT3(add_2mod(0x48, dst_reg, src_reg), 0x85,
35258- add_2reg(0xC0, dst_reg, src_reg));
35259- goto emit_cond_jmp;
35260-
35261- case BPF_JMP | BPF_JSET | BPF_K:
35262- /* test dst_reg, imm32 */
35263- EMIT1(add_1mod(0x48, dst_reg));
35264- EMIT2_off32(0xF7, add_1reg(0xC0, dst_reg), imm32);
35265- goto emit_cond_jmp;
35266-
35267- case BPF_JMP | BPF_JEQ | BPF_K:
35268- case BPF_JMP | BPF_JNE | BPF_K:
35269- case BPF_JMP | BPF_JGT | BPF_K:
35270- case BPF_JMP | BPF_JGE | BPF_K:
35271- case BPF_JMP | BPF_JSGT | BPF_K:
35272- case BPF_JMP | BPF_JSGE | BPF_K:
35273- /* cmp dst_reg, imm8/32 */
35274- EMIT1(add_1mod(0x48, dst_reg));
35275-
35276- if (is_imm8(imm32))
35277- EMIT3(0x83, add_1reg(0xF8, dst_reg), imm32);
35278- else
35279- EMIT2_off32(0x81, add_1reg(0xF8, dst_reg), imm32);
35280-
35281-emit_cond_jmp: /* convert BPF opcode to x86 */
35282- switch (BPF_OP(insn->code)) {
35283- case BPF_JEQ:
35284- jmp_cond = X86_JE;
35285- break;
35286- case BPF_JSET:
35287- case BPF_JNE:
35288- jmp_cond = X86_JNE;
35289- break;
35290- case BPF_JGT:
35291- /* GT is unsigned '>', JA in x86 */
35292- jmp_cond = X86_JA;
35293- break;
35294- case BPF_JGE:
35295- /* GE is unsigned '>=', JAE in x86 */
35296- jmp_cond = X86_JAE;
35297- break;
35298- case BPF_JSGT:
35299- /* signed '>', GT in x86 */
35300- jmp_cond = X86_JG;
35301- break;
35302- case BPF_JSGE:
35303- /* signed '>=', GE in x86 */
35304- jmp_cond = X86_JGE;
35305- break;
35306- default: /* to silence gcc warning */
35307- return -EFAULT;
35308- }
35309- jmp_offset = addrs[i + insn->off] - addrs[i];
35310- if (is_imm8(jmp_offset)) {
35311- EMIT2(jmp_cond, jmp_offset);
35312- } else if (is_simm32(jmp_offset)) {
35313- EMIT2_off32(0x0F, jmp_cond + 0x10, jmp_offset);
35314- } else {
35315- pr_err("cond_jmp gen bug %llx\n", jmp_offset);
35316- return -EFAULT;
35317- }
35318-
35319- break;
35320-
35321- case BPF_JMP | BPF_JA:
35322- jmp_offset = addrs[i + insn->off] - addrs[i];
35323- if (!jmp_offset)
35324- /* optimize out nop jumps */
35325- break;
35326-emit_jmp:
35327- if (is_imm8(jmp_offset)) {
35328- EMIT2(0xEB, jmp_offset);
35329- } else if (is_simm32(jmp_offset)) {
35330- EMIT1_off32(0xE9, jmp_offset);
35331- } else {
35332- pr_err("jmp gen bug %llx\n", jmp_offset);
35333- return -EFAULT;
35334- }
35335- break;
35336-
35337- case BPF_LD | BPF_IND | BPF_W:
35338- func = sk_load_word;
35339- goto common_load;
35340- case BPF_LD | BPF_ABS | BPF_W:
35341- func = CHOOSE_LOAD_FUNC(imm32, sk_load_word);
35342-common_load: ctx->seen_ld_abs = true;
35343- jmp_offset = func - (image + addrs[i]);
35344- if (!func || !is_simm32(jmp_offset)) {
35345- pr_err("unsupported bpf func %d addr %p image %p\n",
35346- imm32, func, image);
35347- return -EINVAL;
35348- }
35349- if (BPF_MODE(insn->code) == BPF_ABS) {
35350- /* mov %esi, imm32 */
35351- EMIT1_off32(0xBE, imm32);
35352- } else {
35353- /* mov %rsi, src_reg */
35354- EMIT_mov(BPF_REG_2, src_reg);
35355- if (imm32) {
35356- if (is_imm8(imm32))
35357- /* add %esi, imm8 */
35358- EMIT3(0x83, 0xC6, imm32);
35359- else
35360- /* add %esi, imm32 */
35361- EMIT2_off32(0x81, 0xC6, imm32);
35362- }
35363- }
35364- /* skb pointer is in R6 (%rbx), it will be copied into
35365- * %rdi if skb_copy_bits() call is necessary.
35366- * sk_load_* helpers also use %r10 and %r9d.
35367- * See bpf_jit.S
35368- */
35369- EMIT1_off32(0xE8, jmp_offset); /* call */
35370- break;
35371-
35372- case BPF_LD | BPF_IND | BPF_H:
35373- func = sk_load_half;
35374- goto common_load;
35375- case BPF_LD | BPF_ABS | BPF_H:
35376- func = CHOOSE_LOAD_FUNC(imm32, sk_load_half);
35377- goto common_load;
35378- case BPF_LD | BPF_IND | BPF_B:
35379- func = sk_load_byte;
35380- goto common_load;
35381- case BPF_LD | BPF_ABS | BPF_B:
35382- func = CHOOSE_LOAD_FUNC(imm32, sk_load_byte);
35383- goto common_load;
35384-
35385- case BPF_JMP | BPF_EXIT:
35386- if (i != insn_cnt - 1) {
35387- jmp_offset = ctx->cleanup_addr - addrs[i];
35388- goto emit_jmp;
35389- }
35390- /* update cleanup_addr */
35391- ctx->cleanup_addr = proglen;
35392- /* mov rbx, qword ptr [rbp-X] */
35393- EMIT3_off32(0x48, 0x8B, 0x9D, -stacksize);
35394- /* mov r13, qword ptr [rbp-X] */
35395- EMIT3_off32(0x4C, 0x8B, 0xAD, -stacksize + 8);
35396- /* mov r14, qword ptr [rbp-X] */
35397- EMIT3_off32(0x4C, 0x8B, 0xB5, -stacksize + 16);
35398- /* mov r15, qword ptr [rbp-X] */
35399- EMIT3_off32(0x4C, 0x8B, 0xBD, -stacksize + 24);
35400-
35401- EMIT1(0xC9); /* leave */
35402- EMIT1(0xC3); /* ret */
35403- break;
35404-
35405- default:
35406- /* By design x64 JIT should support all BPF instructions
35407- * This error will be seen if new instruction was added
35408- * to interpreter, but not to JIT
35409- * or if there is junk in sk_filter
35410- */
35411- pr_err("bpf_jit: unknown opcode %02x\n", insn->code);
35412- return -EINVAL;
35413- }
35414-
35415- ilen = prog - temp;
35416- if (image) {
35417- if (unlikely(proglen + ilen > oldproglen)) {
35418- pr_err("bpf_jit_compile fatal error\n");
35419- return -EFAULT;
35420- }
35421- memcpy(image + proglen, temp, ilen);
35422- }
35423- proglen += ilen;
35424- addrs[i] = proglen;
35425- prog = temp;
35426- }
35427- return proglen;
35428-}
35429-
35430-void bpf_jit_compile(struct sk_filter *prog)
35431-{
35432-}
35433-
35434-void bpf_int_jit_compile(struct sk_filter *prog)
35435-{
35436- struct bpf_binary_header *header = NULL;
35437- int proglen, oldproglen = 0;
35438- struct jit_context ctx = {};
35439+void bpf_jit_compile(struct sk_filter *fp)
35440+{
35441+ u8 temp[MAX_INSTR_CODE_SIZE];
35442+ u8 *prog;
35443+ unsigned int proglen, oldproglen = 0;
35444+ int ilen, i;
35445+ int t_offset, f_offset;
35446+ u8 t_op, f_op, seen = 0, pass;
35447 u8 *image = NULL;
35448- int *addrs;
35449- int pass;
35450- int i;
35451+ u8 *header = NULL;
35452+ u8 *func;
35453+ int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
35454+ unsigned int cleanup_addr; /* epilogue code offset */
35455+ unsigned int *addrs;
35456+ const struct sock_filter *filter = fp->insns;
35457+ int flen = fp->len;
35458+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35459+ unsigned int randkey;
35460+#endif
35461
35462 if (!bpf_jit_enable)
35463 return;
35464
35465- if (!prog || !prog->len)
35466- return;
35467-
35468- addrs = kmalloc(prog->len * sizeof(*addrs), GFP_KERNEL);
35469- if (!addrs)
35470+ addrs = kmalloc(flen * sizeof(*addrs), GFP_KERNEL);
35471+ if (addrs == NULL)
35472 return;
35473
35474 /* Before first pass, make a rough estimation of addrs[]
35475- * each bpf instruction is translated to less than 64 bytes
35476+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
35477 */
35478- for (proglen = 0, i = 0; i < prog->len; i++) {
35479- proglen += 64;
35480+ for (proglen = 0, i = 0; i < flen; i++) {
35481+ proglen += MAX_INSTR_CODE_SIZE;
35482 addrs[i] = proglen;
35483 }
35484- ctx.cleanup_addr = proglen;
35485+ cleanup_addr = proglen; /* epilogue address */
35486
35487 for (pass = 0; pass < 10; pass++) {
35488- proglen = do_jit(prog, addrs, image, oldproglen, &ctx);
35489- if (proglen <= 0) {
35490- image = NULL;
35491- if (header)
35492- module_free(NULL, header);
35493- goto out;
35494+ u8 seen_or_pass0 = (pass == 0) ? (SEEN_XREG | SEEN_DATAREF | SEEN_MEM) : seen;
35495+ /* no prologue/epilogue for trivial filters (RET something) */
35496+ proglen = 0;
35497+ prog = temp;
35498+
35499+ if (seen_or_pass0) {
35500+ EMIT4(0x55, 0x48, 0x89, 0xe5); /* push %rbp; mov %rsp,%rbp */
35501+ EMIT4(0x48, 0x83, 0xec, 96); /* subq $96,%rsp */
35502+ /* note : must save %rbx in case bpf_error is hit */
35503+ if (seen_or_pass0 & (SEEN_XREG | SEEN_DATAREF))
35504+ EMIT4(0x48, 0x89, 0x5d, 0xf8); /* mov %rbx, -8(%rbp) */
35505+ if (seen_or_pass0 & SEEN_XREG)
35506+ CLEAR_X(); /* make sure we dont leek kernel memory */
35507+
35508+ /*
35509+ * If this filter needs to access skb data,
35510+ * loads r9 and r8 with :
35511+ * r9 = skb->len - skb->data_len
35512+ * r8 = skb->data
35513+ */
35514+ if (seen_or_pass0 & SEEN_DATAREF) {
35515+ if (offsetof(struct sk_buff, len) <= 127)
35516+ /* mov off8(%rdi),%r9d */
35517+ EMIT4(0x44, 0x8b, 0x4f, offsetof(struct sk_buff, len));
35518+ else {
35519+ /* mov off32(%rdi),%r9d */
35520+ EMIT3(0x44, 0x8b, 0x8f);
35521+ EMIT(offsetof(struct sk_buff, len), 4);
35522+ }
35523+ if (is_imm8(offsetof(struct sk_buff, data_len)))
35524+ /* sub off8(%rdi),%r9d */
35525+ EMIT4(0x44, 0x2b, 0x4f, offsetof(struct sk_buff, data_len));
35526+ else {
35527+ EMIT3(0x44, 0x2b, 0x8f);
35528+ EMIT(offsetof(struct sk_buff, data_len), 4);
35529+ }
35530+
35531+ if (is_imm8(offsetof(struct sk_buff, data)))
35532+ /* mov off8(%rdi),%r8 */
35533+ EMIT4(0x4c, 0x8b, 0x47, offsetof(struct sk_buff, data));
35534+ else {
35535+ /* mov off32(%rdi),%r8 */
35536+ EMIT3(0x4c, 0x8b, 0x87);
35537+ EMIT(offsetof(struct sk_buff, data), 4);
35538+ }
35539+ }
35540 }
35541+
35542+ switch (filter[0].code) {
35543+ case BPF_S_RET_K:
35544+ case BPF_S_LD_W_LEN:
35545+ case BPF_S_ANC_PROTOCOL:
35546+ case BPF_S_ANC_IFINDEX:
35547+ case BPF_S_ANC_MARK:
35548+ case BPF_S_ANC_RXHASH:
35549+ case BPF_S_ANC_CPU:
35550+ case BPF_S_ANC_VLAN_TAG:
35551+ case BPF_S_ANC_VLAN_TAG_PRESENT:
35552+ case BPF_S_ANC_QUEUE:
35553+ case BPF_S_ANC_PKTTYPE:
35554+ case BPF_S_LD_W_ABS:
35555+ case BPF_S_LD_H_ABS:
35556+ case BPF_S_LD_B_ABS:
35557+ /* first instruction sets A register (or is RET 'constant') */
35558+ break;
35559+ default:
35560+ /* make sure we dont leak kernel information to user */
35561+ CLEAR_A(); /* A = 0 */
35562+ }
35563+
35564+ for (i = 0; i < flen; i++) {
35565+ unsigned int K = filter[i].k;
35566+
35567+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35568+ randkey = prandom_u32();
35569+#endif
35570+
35571+ switch (filter[i].code) {
35572+ case BPF_S_ALU_ADD_X: /* A += X; */
35573+ seen |= SEEN_XREG;
35574+ EMIT2(0x01, 0xd8); /* add %ebx,%eax */
35575+ break;
35576+ case BPF_S_ALU_ADD_K: /* A += K; */
35577+ if (!K)
35578+ break;
35579+ if (is_imm8(K))
35580+ EMIT3(0x83, 0xc0, K); /* add imm8,%eax */
35581+ else
35582+ EMIT1_off32(0x05, K); /* add imm32,%eax */
35583+ break;
35584+ case BPF_S_ALU_SUB_X: /* A -= X; */
35585+ seen |= SEEN_XREG;
35586+ EMIT2(0x29, 0xd8); /* sub %ebx,%eax */
35587+ break;
35588+ case BPF_S_ALU_SUB_K: /* A -= K */
35589+ if (!K)
35590+ break;
35591+ if (is_imm8(K))
35592+ EMIT3(0x83, 0xe8, K); /* sub imm8,%eax */
35593+ else
35594+ EMIT1_off32(0x2d, K); /* sub imm32,%eax */
35595+ break;
35596+ case BPF_S_ALU_MUL_X: /* A *= X; */
35597+ seen |= SEEN_XREG;
35598+ EMIT3(0x0f, 0xaf, 0xc3); /* imul %ebx,%eax */
35599+ break;
35600+ case BPF_S_ALU_MUL_K: /* A *= K */
35601+ if (is_imm8(K))
35602+ EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
35603+ else
35604+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
35605+ break;
35606+ case BPF_S_ALU_DIV_X: /* A /= X; */
35607+ seen |= SEEN_XREG;
35608+ EMIT2(0x85, 0xdb); /* test %ebx,%ebx */
35609+ if (pc_ret0 > 0) {
35610+ /* addrs[pc_ret0 - 1] is start address of target
35611+ * (addrs[i] - 4) is the address following this jmp
35612+ * ("xor %edx,%edx; div %ebx" being 4 bytes long)
35613+ */
35614+ EMIT_COND_JMP(X86_JE, addrs[pc_ret0 - 1] -
35615+ (addrs[i] - 4));
35616+ } else {
35617+ EMIT_COND_JMP(X86_JNE, 2 + 5);
35618+ CLEAR_A();
35619+ EMIT1_off32(0xe9, cleanup_addr - (addrs[i] - 4)); /* jmp .+off32 */
35620+ }
35621+ EMIT4(0x31, 0xd2, 0xf7, 0xf3); /* xor %edx,%edx; div %ebx */
35622+ break;
35623+ case BPF_S_ALU_MOD_X: /* A %= X; */
35624+ seen |= SEEN_XREG;
35625+ EMIT2(0x85, 0xdb); /* test %ebx,%ebx */
35626+ if (pc_ret0 > 0) {
35627+ /* addrs[pc_ret0 - 1] is start address of target
35628+ * (addrs[i] - 6) is the address following this jmp
35629+ * ("xor %edx,%edx; div %ebx;mov %edx,%eax" being 6 bytes long)
35630+ */
35631+ EMIT_COND_JMP(X86_JE, addrs[pc_ret0 - 1] -
35632+ (addrs[i] - 6));
35633+ } else {
35634+ EMIT_COND_JMP(X86_JNE, 2 + 5);
35635+ CLEAR_A();
35636+ EMIT1_off32(0xe9, cleanup_addr - (addrs[i] - 6)); /* jmp .+off32 */
35637+ }
35638+ EMIT2(0x31, 0xd2); /* xor %edx,%edx */
35639+ EMIT2(0xf7, 0xf3); /* div %ebx */
35640+ EMIT2(0x89, 0xd0); /* mov %edx,%eax */
35641+ break;
35642+ case BPF_S_ALU_MOD_K: /* A %= K; */
35643+ if (K == 1) {
35644+ CLEAR_A();
35645+ break;
35646+ }
35647+ EMIT2(0x31, 0xd2); /* xor %edx,%edx */
35648+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35649+ DILUTE_CONST_SEQUENCE(K, randkey);
35650+#else
35651+ EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
35652+#endif
35653+ EMIT2(0xf7, 0xf1); /* div %ecx */
35654+ EMIT2(0x89, 0xd0); /* mov %edx,%eax */
35655+ break;
35656+ case BPF_S_ALU_DIV_K: /* A /= K */
35657+ if (K == 1)
35658+ break;
35659+ EMIT2(0x31, 0xd2); /* xor %edx,%edx */
35660+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35661+ DILUTE_CONST_SEQUENCE(K, randkey);
35662+#else
35663+ EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
35664+#endif
35665+ EMIT2(0xf7, 0xf1); /* div %ecx */
35666+ break;
35667+ case BPF_S_ALU_AND_X:
35668+ seen |= SEEN_XREG;
35669+ EMIT2(0x21, 0xd8); /* and %ebx,%eax */
35670+ break;
35671+ case BPF_S_ALU_AND_K:
35672+ if (K >= 0xFFFFFF00) {
35673+ EMIT2(0x24, K & 0xFF); /* and imm8,%al */
35674+ } else if (K >= 0xFFFF0000) {
35675+ EMIT2(0x66, 0x25); /* and imm16,%ax */
35676+ EMIT(K, 2);
35677+ } else {
35678+ EMIT1_off32(0x25, K); /* and imm32,%eax */
35679+ }
35680+ break;
35681+ case BPF_S_ALU_OR_X:
35682+ seen |= SEEN_XREG;
35683+ EMIT2(0x09, 0xd8); /* or %ebx,%eax */
35684+ break;
35685+ case BPF_S_ALU_OR_K:
35686+ if (is_imm8(K))
35687+ EMIT3(0x83, 0xc8, K); /* or imm8,%eax */
35688+ else
35689+ EMIT1_off32(0x0d, K); /* or imm32,%eax */
35690+ break;
35691+ case BPF_S_ANC_ALU_XOR_X: /* A ^= X; */
35692+ case BPF_S_ALU_XOR_X:
35693+ seen |= SEEN_XREG;
35694+ EMIT2(0x31, 0xd8); /* xor %ebx,%eax */
35695+ break;
35696+ case BPF_S_ALU_XOR_K: /* A ^= K; */
35697+ if (K == 0)
35698+ break;
35699+ if (is_imm8(K))
35700+ EMIT3(0x83, 0xf0, K); /* xor imm8,%eax */
35701+ else
35702+ EMIT1_off32(0x35, K); /* xor imm32,%eax */
35703+ break;
35704+ case BPF_S_ALU_LSH_X: /* A <<= X; */
35705+ seen |= SEEN_XREG;
35706+ EMIT4(0x89, 0xd9, 0xd3, 0xe0); /* mov %ebx,%ecx; shl %cl,%eax */
35707+ break;
35708+ case BPF_S_ALU_LSH_K:
35709+ if (K == 0)
35710+ break;
35711+ else if (K == 1)
35712+ EMIT2(0xd1, 0xe0); /* shl %eax */
35713+ else
35714+ EMIT3(0xc1, 0xe0, K);
35715+ break;
35716+ case BPF_S_ALU_RSH_X: /* A >>= X; */
35717+ seen |= SEEN_XREG;
35718+ EMIT4(0x89, 0xd9, 0xd3, 0xe8); /* mov %ebx,%ecx; shr %cl,%eax */
35719+ break;
35720+ case BPF_S_ALU_RSH_K: /* A >>= K; */
35721+ if (K == 0)
35722+ break;
35723+ else if (K == 1)
35724+ EMIT2(0xd1, 0xe8); /* shr %eax */
35725+ else
35726+ EMIT3(0xc1, 0xe8, K);
35727+ break;
35728+ case BPF_S_ALU_NEG:
35729+ EMIT2(0xf7, 0xd8); /* neg %eax */
35730+ break;
35731+ case BPF_S_RET_K:
35732+ if (!K) {
35733+ if (pc_ret0 == -1)
35734+ pc_ret0 = i;
35735+ CLEAR_A();
35736+ } else {
35737+ EMIT1_off32(0xb8, K); /* mov $imm32,%eax */
35738+ }
35739+ /* fallinto */
35740+ case BPF_S_RET_A:
35741+ if (seen_or_pass0) {
35742+ if (i != flen - 1) {
35743+ EMIT_JMP(cleanup_addr - addrs[i]);
35744+ break;
35745+ }
35746+ if (seen_or_pass0 & SEEN_XREG)
35747+ EMIT4(0x48, 0x8b, 0x5d, 0xf8); /* mov -8(%rbp),%rbx */
35748+ EMIT1(0xc9); /* leaveq */
35749+ }
35750+ EMIT1(0xc3); /* ret */
35751+ break;
35752+ case BPF_S_MISC_TAX: /* X = A */
35753+ seen |= SEEN_XREG;
35754+ EMIT2(0x89, 0xc3); /* mov %eax,%ebx */
35755+ break;
35756+ case BPF_S_MISC_TXA: /* A = X */
35757+ seen |= SEEN_XREG;
35758+ EMIT2(0x89, 0xd8); /* mov %ebx,%eax */
35759+ break;
35760+ case BPF_S_LD_IMM: /* A = K */
35761+ if (!K)
35762+ CLEAR_A();
35763+ else
35764+ EMIT1_off32(0xb8, K); /* mov $imm32,%eax */
35765+ break;
35766+ case BPF_S_LDX_IMM: /* X = K */
35767+ seen |= SEEN_XREG;
35768+ if (!K)
35769+ CLEAR_X();
35770+ else
35771+ EMIT1_off32(0xbb, K); /* mov $imm32,%ebx */
35772+ break;
35773+ case BPF_S_LD_MEM: /* A = mem[K] : mov off8(%rbp),%eax */
35774+ seen |= SEEN_MEM;
35775+ EMIT3(0x8b, 0x45, 0xf0 - K*4);
35776+ break;
35777+ case BPF_S_LDX_MEM: /* X = mem[K] : mov off8(%rbp),%ebx */
35778+ seen |= SEEN_XREG | SEEN_MEM;
35779+ EMIT3(0x8b, 0x5d, 0xf0 - K*4);
35780+ break;
35781+ case BPF_S_ST: /* mem[K] = A : mov %eax,off8(%rbp) */
35782+ seen |= SEEN_MEM;
35783+ EMIT3(0x89, 0x45, 0xf0 - K*4);
35784+ break;
35785+ case BPF_S_STX: /* mem[K] = X : mov %ebx,off8(%rbp) */
35786+ seen |= SEEN_XREG | SEEN_MEM;
35787+ EMIT3(0x89, 0x5d, 0xf0 - K*4);
35788+ break;
35789+ case BPF_S_LD_W_LEN: /* A = skb->len; */
35790+ BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, len) != 4);
35791+ if (is_imm8(offsetof(struct sk_buff, len)))
35792+ /* mov off8(%rdi),%eax */
35793+ EMIT3(0x8b, 0x47, offsetof(struct sk_buff, len));
35794+ else {
35795+ EMIT2(0x8b, 0x87);
35796+ EMIT(offsetof(struct sk_buff, len), 4);
35797+ }
35798+ break;
35799+ case BPF_S_LDX_W_LEN: /* X = skb->len; */
35800+ seen |= SEEN_XREG;
35801+ if (is_imm8(offsetof(struct sk_buff, len)))
35802+ /* mov off8(%rdi),%ebx */
35803+ EMIT3(0x8b, 0x5f, offsetof(struct sk_buff, len));
35804+ else {
35805+ EMIT2(0x8b, 0x9f);
35806+ EMIT(offsetof(struct sk_buff, len), 4);
35807+ }
35808+ break;
35809+ case BPF_S_ANC_PROTOCOL: /* A = ntohs(skb->protocol); */
35810+ BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, protocol) != 2);
35811+ if (is_imm8(offsetof(struct sk_buff, protocol))) {
35812+ /* movzwl off8(%rdi),%eax */
35813+ EMIT4(0x0f, 0xb7, 0x47, offsetof(struct sk_buff, protocol));
35814+ } else {
35815+ EMIT3(0x0f, 0xb7, 0x87); /* movzwl off32(%rdi),%eax */
35816+ EMIT(offsetof(struct sk_buff, protocol), 4);
35817+ }
35818+ EMIT2(0x86, 0xc4); /* ntohs() : xchg %al,%ah */
35819+ break;
35820+ case BPF_S_ANC_IFINDEX:
35821+ if (is_imm8(offsetof(struct sk_buff, dev))) {
35822+ /* movq off8(%rdi),%rax */
35823+ EMIT4(0x48, 0x8b, 0x47, offsetof(struct sk_buff, dev));
35824+ } else {
35825+ EMIT3(0x48, 0x8b, 0x87); /* movq off32(%rdi),%rax */
35826+ EMIT(offsetof(struct sk_buff, dev), 4);
35827+ }
35828+ EMIT3(0x48, 0x85, 0xc0); /* test %rax,%rax */
35829+ EMIT_COND_JMP(X86_JE, cleanup_addr - (addrs[i] - 6));
35830+ BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4);
35831+ EMIT2(0x8b, 0x80); /* mov off32(%rax),%eax */
35832+ EMIT(offsetof(struct net_device, ifindex), 4);
35833+ break;
35834+ case BPF_S_ANC_MARK:
35835+ BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, mark) != 4);
35836+ if (is_imm8(offsetof(struct sk_buff, mark))) {
35837+ /* mov off8(%rdi),%eax */
35838+ EMIT3(0x8b, 0x47, offsetof(struct sk_buff, mark));
35839+ } else {
35840+ EMIT2(0x8b, 0x87);
35841+ EMIT(offsetof(struct sk_buff, mark), 4);
35842+ }
35843+ break;
35844+ case BPF_S_ANC_RXHASH:
35845+ BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, hash) != 4);
35846+ if (is_imm8(offsetof(struct sk_buff, hash))) {
35847+ /* mov off8(%rdi),%eax */
35848+ EMIT3(0x8b, 0x47, offsetof(struct sk_buff, hash));
35849+ } else {
35850+ EMIT2(0x8b, 0x87);
35851+ EMIT(offsetof(struct sk_buff, hash), 4);
35852+ }
35853+ break;
35854+ case BPF_S_ANC_QUEUE:
35855+ BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, queue_mapping) != 2);
35856+ if (is_imm8(offsetof(struct sk_buff, queue_mapping))) {
35857+ /* movzwl off8(%rdi),%eax */
35858+ EMIT4(0x0f, 0xb7, 0x47, offsetof(struct sk_buff, queue_mapping));
35859+ } else {
35860+ EMIT3(0x0f, 0xb7, 0x87); /* movzwl off32(%rdi),%eax */
35861+ EMIT(offsetof(struct sk_buff, queue_mapping), 4);
35862+ }
35863+ break;
35864+ case BPF_S_ANC_CPU:
35865+#ifdef CONFIG_SMP
35866+ EMIT4(0x65, 0x8b, 0x04, 0x25); /* mov %gs:off32,%eax */
35867+ EMIT((u32)(unsigned long)&cpu_number, 4); /* A = smp_processor_id(); */
35868+#else
35869+ CLEAR_A();
35870+#endif
35871+ break;
35872+ case BPF_S_ANC_VLAN_TAG:
35873+ case BPF_S_ANC_VLAN_TAG_PRESENT:
35874+ BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
35875+ if (is_imm8(offsetof(struct sk_buff, vlan_tci))) {
35876+ /* movzwl off8(%rdi),%eax */
35877+ EMIT4(0x0f, 0xb7, 0x47, offsetof(struct sk_buff, vlan_tci));
35878+ } else {
35879+ EMIT3(0x0f, 0xb7, 0x87); /* movzwl off32(%rdi),%eax */
35880+ EMIT(offsetof(struct sk_buff, vlan_tci), 4);
35881+ }
35882+ BUILD_BUG_ON(VLAN_TAG_PRESENT != 0x1000);
35883+ if (filter[i].code == BPF_S_ANC_VLAN_TAG) {
35884+ EMIT3(0x80, 0xe4, 0xef); /* and $0xef,%ah */
35885+ } else {
35886+ EMIT3(0xc1, 0xe8, 0x0c); /* shr $0xc,%eax */
35887+ EMIT3(0x83, 0xe0, 0x01); /* and $0x1,%eax */
35888+ }
35889+ break;
35890+ case BPF_S_ANC_PKTTYPE:
35891+ {
35892+ int off = pkt_type_offset();
35893+
35894+ if (off < 0)
35895+ goto out;
35896+ if (is_imm8(off)) {
35897+ /* movzbl off8(%rdi),%eax */
35898+ EMIT4(0x0f, 0xb6, 0x47, off);
35899+ } else {
35900+ /* movbl off32(%rdi),%eax */
35901+ EMIT3(0x0f, 0xb6, 0x87);
35902+ EMIT(off, 4);
35903+ }
35904+ EMIT3(0x83, 0xe0, PKT_TYPE_MAX); /* and $0x7,%eax */
35905+ break;
35906+ }
35907+ case BPF_S_LD_W_ABS:
35908+ func = CHOOSE_LOAD_FUNC(K, sk_load_word);
35909+common_load: seen |= SEEN_DATAREF;
35910+ t_offset = func - (image + addrs[i]);
35911+ EMIT1_off32(0xbe, K); /* mov imm32,%esi */
35912+ EMIT1_off32(0xe8, t_offset); /* call */
35913+ break;
35914+ case BPF_S_LD_H_ABS:
35915+ func = CHOOSE_LOAD_FUNC(K, sk_load_half);
35916+ goto common_load;
35917+ case BPF_S_LD_B_ABS:
35918+ func = CHOOSE_LOAD_FUNC(K, sk_load_byte);
35919+ goto common_load;
35920+ case BPF_S_LDX_B_MSH:
35921+ func = CHOOSE_LOAD_FUNC(K, sk_load_byte_msh);
35922+ seen |= SEEN_DATAREF | SEEN_XREG;
35923+ t_offset = func - (image + addrs[i]);
35924+ EMIT1_off32(0xbe, K); /* mov imm32,%esi */
35925+ EMIT1_off32(0xe8, t_offset); /* call sk_load_byte_msh */
35926+ break;
35927+ case BPF_S_LD_W_IND:
35928+ func = sk_load_word;
35929+common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
35930+ t_offset = func - (image + addrs[i]);
35931+ if (K) {
35932+ if (is_imm8(K)) {
35933+ EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
35934+ } else {
35935+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
35936+ }
35937+ } else {
35938+ EMIT2(0x89,0xde); /* mov %ebx,%esi */
35939+ }
35940+ EMIT1_off32(0xe8, t_offset); /* call sk_load_xxx_ind */
35941+ break;
35942+ case BPF_S_LD_H_IND:
35943+ func = sk_load_half;
35944+ goto common_load_ind;
35945+ case BPF_S_LD_B_IND:
35946+ func = sk_load_byte;
35947+ goto common_load_ind;
35948+ case BPF_S_JMP_JA:
35949+ t_offset = addrs[i + K] - addrs[i];
35950+ EMIT_JMP(t_offset);
35951+ break;
35952+ COND_SEL(BPF_S_JMP_JGT_K, X86_JA, X86_JBE);
35953+ COND_SEL(BPF_S_JMP_JGE_K, X86_JAE, X86_JB);
35954+ COND_SEL(BPF_S_JMP_JEQ_K, X86_JE, X86_JNE);
35955+ COND_SEL(BPF_S_JMP_JSET_K,X86_JNE, X86_JE);
35956+ COND_SEL(BPF_S_JMP_JGT_X, X86_JA, X86_JBE);
35957+ COND_SEL(BPF_S_JMP_JGE_X, X86_JAE, X86_JB);
35958+ COND_SEL(BPF_S_JMP_JEQ_X, X86_JE, X86_JNE);
35959+ COND_SEL(BPF_S_JMP_JSET_X,X86_JNE, X86_JE);
35960+
35961+cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
35962+ t_offset = addrs[i + filter[i].jt] - addrs[i];
35963+
35964+ /* same targets, can avoid doing the test :) */
35965+ if (filter[i].jt == filter[i].jf) {
35966+ EMIT_JMP(t_offset);
35967+ break;
35968+ }
35969+
35970+ switch (filter[i].code) {
35971+ case BPF_S_JMP_JGT_X:
35972+ case BPF_S_JMP_JGE_X:
35973+ case BPF_S_JMP_JEQ_X:
35974+ seen |= SEEN_XREG;
35975+ EMIT2(0x39, 0xd8); /* cmp %ebx,%eax */
35976+ break;
35977+ case BPF_S_JMP_JSET_X:
35978+ seen |= SEEN_XREG;
35979+ EMIT2(0x85, 0xd8); /* test %ebx,%eax */
35980+ break;
35981+ case BPF_S_JMP_JEQ_K:
35982+ if (K == 0) {
35983+ EMIT2(0x85, 0xc0); /* test %eax,%eax */
35984+ break;
35985+ }
35986+ case BPF_S_JMP_JGT_K:
35987+ case BPF_S_JMP_JGE_K:
35988+ if (K <= 127)
35989+ EMIT3(0x83, 0xf8, K); /* cmp imm8,%eax */
35990+ else
35991+ EMIT1_off32(0x3d, K); /* cmp imm32,%eax */
35992+ break;
35993+ case BPF_S_JMP_JSET_K:
35994+ if (K <= 0xFF)
35995+ EMIT2(0xa8, K); /* test imm8,%al */
35996+ else if (!(K & 0xFFFF00FF))
35997+ EMIT3(0xf6, 0xc4, K >> 8); /* test imm8,%ah */
35998+ else if (K <= 0xFFFF) {
35999+ EMIT2(0x66, 0xa9); /* test imm16,%ax */
36000+ EMIT(K, 2);
36001+ } else {
36002+ EMIT1_off32(0xa9, K); /* test imm32,%eax */
36003+ }
36004+ break;
36005+ }
36006+ if (filter[i].jt != 0) {
36007+ if (filter[i].jf && f_offset)
36008+ t_offset += is_near(f_offset) ? 2 : 5;
36009+ EMIT_COND_JMP(t_op, t_offset);
36010+ if (filter[i].jf)
36011+ EMIT_JMP(f_offset);
36012+ break;
36013+ }
36014+ EMIT_COND_JMP(f_op, f_offset);
36015+ break;
36016+ default:
36017+ /* hmm, too complex filter, give up with jit compiler */
36018+ goto out;
36019+ }
36020+ ilen = prog - temp;
36021+ if (image) {
36022+ if (unlikely(proglen + ilen > oldproglen)) {
36023+ pr_err("bpb_jit_compile fatal error\n");
36024+ kfree(addrs);
36025+ module_free_exec(NULL, image);
36026+ return;
36027+ }
36028+ pax_open_kernel();
36029+ memcpy(image + proglen, temp, ilen);
36030+ pax_close_kernel();
36031+ }
36032+ proglen += ilen;
36033+ addrs[i] = proglen;
36034+ prog = temp;
36035+ }
36036+ /* last bpf instruction is always a RET :
36037+ * use it to give the cleanup instruction(s) addr
36038+ */
36039+ cleanup_addr = proglen - 1; /* ret */
36040+ if (seen_or_pass0)
36041+ cleanup_addr -= 1; /* leaveq */
36042+ if (seen_or_pass0 & SEEN_XREG)
36043+ cleanup_addr -= 4; /* mov -8(%rbp),%rbx */
36044+
36045 if (image) {
36046 if (proglen != oldproglen)
36047- pr_err("bpf_jit: proglen=%d != oldproglen=%d\n",
36048- proglen, oldproglen);
36049+ pr_err("bpb_jit_compile proglen=%u != oldproglen=%u\n", proglen, oldproglen);
36050 break;
36051 }
36052 if (proglen == oldproglen) {
36053@@ -918,32 +872,30 @@ void bpf_int_jit_compile(struct sk_filter *prog)
36054 }
36055
36056 if (bpf_jit_enable > 1)
36057- bpf_jit_dump(prog->len, proglen, 0, image);
36058+ bpf_jit_dump(flen, proglen, pass, image);
36059
36060 if (image) {
36061 bpf_flush_icache(header, image + proglen);
36062- set_memory_ro((unsigned long)header, header->pages);
36063- prog->bpf_func = (void *)image;
36064- prog->jited = 1;
36065+ fp->bpf_func = (void *)image;
36066 }
36067 out:
36068 kfree(addrs);
36069+ return;
36070 }
36071
36072 static void bpf_jit_free_deferred(struct work_struct *work)
36073 {
36074 struct sk_filter *fp = container_of(work, struct sk_filter, work);
36075 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
36076- struct bpf_binary_header *header = (void *)addr;
36077
36078- set_memory_rw(addr, header->pages);
36079- module_free(NULL, header);
36080+ set_memory_rw(addr, 1);
36081+ module_free_exec(NULL, (void *)addr);
36082 kfree(fp);
36083 }
36084
36085 void bpf_jit_free(struct sk_filter *fp)
36086 {
36087- if (fp->jited) {
36088+ if (fp->bpf_func != sk_run_filter) {
36089 INIT_WORK(&fp->work, bpf_jit_free_deferred);
36090 schedule_work(&fp->work);
36091 } else {
36092diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
36093index 5d04be5..2beeaa2 100644
36094--- a/arch/x86/oprofile/backtrace.c
36095+++ b/arch/x86/oprofile/backtrace.c
36096@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
36097 struct stack_frame_ia32 *fp;
36098 unsigned long bytes;
36099
36100- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
36101+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
36102 if (bytes != 0)
36103 return NULL;
36104
36105- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
36106+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
36107
36108 oprofile_add_trace(bufhead[0].return_address);
36109
36110@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
36111 struct stack_frame bufhead[2];
36112 unsigned long bytes;
36113
36114- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
36115+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
36116 if (bytes != 0)
36117 return NULL;
36118
36119@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
36120 {
36121 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
36122
36123- if (!user_mode_vm(regs)) {
36124+ if (!user_mode(regs)) {
36125 unsigned long stack = kernel_stack_pointer(regs);
36126 if (depth)
36127 dump_trace(NULL, regs, (unsigned long *)stack, 0,
36128diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
36129index 379e8bd..6386e09 100644
36130--- a/arch/x86/oprofile/nmi_int.c
36131+++ b/arch/x86/oprofile/nmi_int.c
36132@@ -23,6 +23,7 @@
36133 #include <asm/nmi.h>
36134 #include <asm/msr.h>
36135 #include <asm/apic.h>
36136+#include <asm/pgtable.h>
36137
36138 #include "op_counter.h"
36139 #include "op_x86_model.h"
36140@@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
36141 if (ret)
36142 return ret;
36143
36144- if (!model->num_virt_counters)
36145- model->num_virt_counters = model->num_counters;
36146+ if (!model->num_virt_counters) {
36147+ pax_open_kernel();
36148+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
36149+ pax_close_kernel();
36150+ }
36151
36152 mux_init(ops);
36153
36154diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
36155index 50d86c0..7985318 100644
36156--- a/arch/x86/oprofile/op_model_amd.c
36157+++ b/arch/x86/oprofile/op_model_amd.c
36158@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
36159 num_counters = AMD64_NUM_COUNTERS;
36160 }
36161
36162- op_amd_spec.num_counters = num_counters;
36163- op_amd_spec.num_controls = num_counters;
36164- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
36165+ pax_open_kernel();
36166+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
36167+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
36168+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
36169+ pax_close_kernel();
36170
36171 return 0;
36172 }
36173diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
36174index d90528e..0127e2b 100644
36175--- a/arch/x86/oprofile/op_model_ppro.c
36176+++ b/arch/x86/oprofile/op_model_ppro.c
36177@@ -19,6 +19,7 @@
36178 #include <asm/msr.h>
36179 #include <asm/apic.h>
36180 #include <asm/nmi.h>
36181+#include <asm/pgtable.h>
36182
36183 #include "op_x86_model.h"
36184 #include "op_counter.h"
36185@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
36186
36187 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
36188
36189- op_arch_perfmon_spec.num_counters = num_counters;
36190- op_arch_perfmon_spec.num_controls = num_counters;
36191+ pax_open_kernel();
36192+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
36193+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
36194+ pax_close_kernel();
36195 }
36196
36197 static int arch_perfmon_init(struct oprofile_operations *ignore)
36198diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
36199index 71e8a67..6a313bb 100644
36200--- a/arch/x86/oprofile/op_x86_model.h
36201+++ b/arch/x86/oprofile/op_x86_model.h
36202@@ -52,7 +52,7 @@ struct op_x86_model_spec {
36203 void (*switch_ctrl)(struct op_x86_model_spec const *model,
36204 struct op_msrs const * const msrs);
36205 #endif
36206-};
36207+} __do_const;
36208
36209 struct op_counter_config;
36210
36211diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
36212index 84b9d67..260e5ff 100644
36213--- a/arch/x86/pci/intel_mid_pci.c
36214+++ b/arch/x86/pci/intel_mid_pci.c
36215@@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
36216 pr_info("Intel MID platform detected, using MID PCI ops\n");
36217 pci_mmcfg_late_init();
36218 pcibios_enable_irq = intel_mid_pci_irq_enable;
36219- pci_root_ops = intel_mid_pci_ops;
36220+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
36221 pci_soc_mode = 1;
36222 /* Continue with standard init */
36223 return 1;
36224diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
36225index 84112f5..6334d60 100644
36226--- a/arch/x86/pci/irq.c
36227+++ b/arch/x86/pci/irq.c
36228@@ -50,7 +50,7 @@ struct irq_router {
36229 struct irq_router_handler {
36230 u16 vendor;
36231 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
36232-};
36233+} __do_const;
36234
36235 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
36236 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
36237@@ -790,7 +790,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
36238 return 0;
36239 }
36240
36241-static __initdata struct irq_router_handler pirq_routers[] = {
36242+static __initconst const struct irq_router_handler pirq_routers[] = {
36243 { PCI_VENDOR_ID_INTEL, intel_router_probe },
36244 { PCI_VENDOR_ID_AL, ali_router_probe },
36245 { PCI_VENDOR_ID_ITE, ite_router_probe },
36246@@ -817,7 +817,7 @@ static struct pci_dev *pirq_router_dev;
36247 static void __init pirq_find_router(struct irq_router *r)
36248 {
36249 struct irq_routing_table *rt = pirq_table;
36250- struct irq_router_handler *h;
36251+ const struct irq_router_handler *h;
36252
36253 #ifdef CONFIG_PCI_BIOS
36254 if (!rt->signature) {
36255@@ -1090,7 +1090,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
36256 return 0;
36257 }
36258
36259-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
36260+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
36261 {
36262 .callback = fix_broken_hp_bios_irq9,
36263 .ident = "HP Pavilion N5400 Series Laptop",
36264diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
36265index c77b24a..c979855 100644
36266--- a/arch/x86/pci/pcbios.c
36267+++ b/arch/x86/pci/pcbios.c
36268@@ -79,7 +79,7 @@ union bios32 {
36269 static struct {
36270 unsigned long address;
36271 unsigned short segment;
36272-} bios32_indirect = { 0, __KERNEL_CS };
36273+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
36274
36275 /*
36276 * Returns the entry point for the given service, NULL on error
36277@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
36278 unsigned long length; /* %ecx */
36279 unsigned long entry; /* %edx */
36280 unsigned long flags;
36281+ struct desc_struct d, *gdt;
36282
36283 local_irq_save(flags);
36284- __asm__("lcall *(%%edi); cld"
36285+
36286+ gdt = get_cpu_gdt_table(smp_processor_id());
36287+
36288+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
36289+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
36290+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
36291+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
36292+
36293+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
36294 : "=a" (return_code),
36295 "=b" (address),
36296 "=c" (length),
36297 "=d" (entry)
36298 : "0" (service),
36299 "1" (0),
36300- "D" (&bios32_indirect));
36301+ "D" (&bios32_indirect),
36302+ "r"(__PCIBIOS_DS)
36303+ : "memory");
36304+
36305+ pax_open_kernel();
36306+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
36307+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
36308+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
36309+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
36310+ pax_close_kernel();
36311+
36312 local_irq_restore(flags);
36313
36314 switch (return_code) {
36315- case 0:
36316- return address + entry;
36317- case 0x80: /* Not present */
36318- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
36319- return 0;
36320- default: /* Shouldn't happen */
36321- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
36322- service, return_code);
36323+ case 0: {
36324+ int cpu;
36325+ unsigned char flags;
36326+
36327+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
36328+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
36329+ printk(KERN_WARNING "bios32_service: not valid\n");
36330 return 0;
36331+ }
36332+ address = address + PAGE_OFFSET;
36333+ length += 16UL; /* some BIOSs underreport this... */
36334+ flags = 4;
36335+ if (length >= 64*1024*1024) {
36336+ length >>= PAGE_SHIFT;
36337+ flags |= 8;
36338+ }
36339+
36340+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
36341+ gdt = get_cpu_gdt_table(cpu);
36342+ pack_descriptor(&d, address, length, 0x9b, flags);
36343+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
36344+ pack_descriptor(&d, address, length, 0x93, flags);
36345+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
36346+ }
36347+ return entry;
36348+ }
36349+ case 0x80: /* Not present */
36350+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
36351+ return 0;
36352+ default: /* Shouldn't happen */
36353+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
36354+ service, return_code);
36355+ return 0;
36356 }
36357 }
36358
36359 static struct {
36360 unsigned long address;
36361 unsigned short segment;
36362-} pci_indirect = { 0, __KERNEL_CS };
36363+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
36364
36365-static int pci_bios_present;
36366+static int pci_bios_present __read_only;
36367
36368 static int check_pcibios(void)
36369 {
36370@@ -131,11 +174,13 @@ static int check_pcibios(void)
36371 unsigned long flags, pcibios_entry;
36372
36373 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
36374- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
36375+ pci_indirect.address = pcibios_entry;
36376
36377 local_irq_save(flags);
36378- __asm__(
36379- "lcall *(%%edi); cld\n\t"
36380+ __asm__("movw %w6, %%ds\n\t"
36381+ "lcall *%%ss:(%%edi); cld\n\t"
36382+ "push %%ss\n\t"
36383+ "pop %%ds\n\t"
36384 "jc 1f\n\t"
36385 "xor %%ah, %%ah\n"
36386 "1:"
36387@@ -144,7 +189,8 @@ static int check_pcibios(void)
36388 "=b" (ebx),
36389 "=c" (ecx)
36390 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
36391- "D" (&pci_indirect)
36392+ "D" (&pci_indirect),
36393+ "r" (__PCIBIOS_DS)
36394 : "memory");
36395 local_irq_restore(flags);
36396
36397@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36398
36399 switch (len) {
36400 case 1:
36401- __asm__("lcall *(%%esi); cld\n\t"
36402+ __asm__("movw %w6, %%ds\n\t"
36403+ "lcall *%%ss:(%%esi); cld\n\t"
36404+ "push %%ss\n\t"
36405+ "pop %%ds\n\t"
36406 "jc 1f\n\t"
36407 "xor %%ah, %%ah\n"
36408 "1:"
36409@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36410 : "1" (PCIBIOS_READ_CONFIG_BYTE),
36411 "b" (bx),
36412 "D" ((long)reg),
36413- "S" (&pci_indirect));
36414+ "S" (&pci_indirect),
36415+ "r" (__PCIBIOS_DS));
36416 /*
36417 * Zero-extend the result beyond 8 bits, do not trust the
36418 * BIOS having done it:
36419@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36420 *value &= 0xff;
36421 break;
36422 case 2:
36423- __asm__("lcall *(%%esi); cld\n\t"
36424+ __asm__("movw %w6, %%ds\n\t"
36425+ "lcall *%%ss:(%%esi); cld\n\t"
36426+ "push %%ss\n\t"
36427+ "pop %%ds\n\t"
36428 "jc 1f\n\t"
36429 "xor %%ah, %%ah\n"
36430 "1:"
36431@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36432 : "1" (PCIBIOS_READ_CONFIG_WORD),
36433 "b" (bx),
36434 "D" ((long)reg),
36435- "S" (&pci_indirect));
36436+ "S" (&pci_indirect),
36437+ "r" (__PCIBIOS_DS));
36438 /*
36439 * Zero-extend the result beyond 16 bits, do not trust the
36440 * BIOS having done it:
36441@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36442 *value &= 0xffff;
36443 break;
36444 case 4:
36445- __asm__("lcall *(%%esi); cld\n\t"
36446+ __asm__("movw %w6, %%ds\n\t"
36447+ "lcall *%%ss:(%%esi); cld\n\t"
36448+ "push %%ss\n\t"
36449+ "pop %%ds\n\t"
36450 "jc 1f\n\t"
36451 "xor %%ah, %%ah\n"
36452 "1:"
36453@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36454 : "1" (PCIBIOS_READ_CONFIG_DWORD),
36455 "b" (bx),
36456 "D" ((long)reg),
36457- "S" (&pci_indirect));
36458+ "S" (&pci_indirect),
36459+ "r" (__PCIBIOS_DS));
36460 break;
36461 }
36462
36463@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36464
36465 switch (len) {
36466 case 1:
36467- __asm__("lcall *(%%esi); cld\n\t"
36468+ __asm__("movw %w6, %%ds\n\t"
36469+ "lcall *%%ss:(%%esi); cld\n\t"
36470+ "push %%ss\n\t"
36471+ "pop %%ds\n\t"
36472 "jc 1f\n\t"
36473 "xor %%ah, %%ah\n"
36474 "1:"
36475@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36476 "c" (value),
36477 "b" (bx),
36478 "D" ((long)reg),
36479- "S" (&pci_indirect));
36480+ "S" (&pci_indirect),
36481+ "r" (__PCIBIOS_DS));
36482 break;
36483 case 2:
36484- __asm__("lcall *(%%esi); cld\n\t"
36485+ __asm__("movw %w6, %%ds\n\t"
36486+ "lcall *%%ss:(%%esi); cld\n\t"
36487+ "push %%ss\n\t"
36488+ "pop %%ds\n\t"
36489 "jc 1f\n\t"
36490 "xor %%ah, %%ah\n"
36491 "1:"
36492@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36493 "c" (value),
36494 "b" (bx),
36495 "D" ((long)reg),
36496- "S" (&pci_indirect));
36497+ "S" (&pci_indirect),
36498+ "r" (__PCIBIOS_DS));
36499 break;
36500 case 4:
36501- __asm__("lcall *(%%esi); cld\n\t"
36502+ __asm__("movw %w6, %%ds\n\t"
36503+ "lcall *%%ss:(%%esi); cld\n\t"
36504+ "push %%ss\n\t"
36505+ "pop %%ds\n\t"
36506 "jc 1f\n\t"
36507 "xor %%ah, %%ah\n"
36508 "1:"
36509@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36510 "c" (value),
36511 "b" (bx),
36512 "D" ((long)reg),
36513- "S" (&pci_indirect));
36514+ "S" (&pci_indirect),
36515+ "r" (__PCIBIOS_DS));
36516 break;
36517 }
36518
36519@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
36520
36521 DBG("PCI: Fetching IRQ routing table... ");
36522 __asm__("push %%es\n\t"
36523+ "movw %w8, %%ds\n\t"
36524 "push %%ds\n\t"
36525 "pop %%es\n\t"
36526- "lcall *(%%esi); cld\n\t"
36527+ "lcall *%%ss:(%%esi); cld\n\t"
36528 "pop %%es\n\t"
36529+ "push %%ss\n\t"
36530+ "pop %%ds\n"
36531 "jc 1f\n\t"
36532 "xor %%ah, %%ah\n"
36533 "1:"
36534@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
36535 "1" (0),
36536 "D" ((long) &opt),
36537 "S" (&pci_indirect),
36538- "m" (opt)
36539+ "m" (opt),
36540+ "r" (__PCIBIOS_DS)
36541 : "memory");
36542 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
36543 if (ret & 0xff00)
36544@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
36545 {
36546 int ret;
36547
36548- __asm__("lcall *(%%esi); cld\n\t"
36549+ __asm__("movw %w5, %%ds\n\t"
36550+ "lcall *%%ss:(%%esi); cld\n\t"
36551+ "push %%ss\n\t"
36552+ "pop %%ds\n"
36553 "jc 1f\n\t"
36554 "xor %%ah, %%ah\n"
36555 "1:"
36556@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
36557 : "0" (PCIBIOS_SET_PCI_HW_INT),
36558 "b" ((dev->bus->number << 8) | dev->devfn),
36559 "c" ((irq << 8) | (pin + 10)),
36560- "S" (&pci_indirect));
36561+ "S" (&pci_indirect),
36562+ "r" (__PCIBIOS_DS));
36563 return !(ret & 0xff00);
36564 }
36565 EXPORT_SYMBOL(pcibios_set_irq_routing);
36566diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
36567index 9ee3491..872192f 100644
36568--- a/arch/x86/platform/efi/efi_32.c
36569+++ b/arch/x86/platform/efi/efi_32.c
36570@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
36571 {
36572 struct desc_ptr gdt_descr;
36573
36574+#ifdef CONFIG_PAX_KERNEXEC
36575+ struct desc_struct d;
36576+#endif
36577+
36578 local_irq_save(efi_rt_eflags);
36579
36580 load_cr3(initial_page_table);
36581 __flush_tlb_all();
36582
36583+#ifdef CONFIG_PAX_KERNEXEC
36584+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
36585+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
36586+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
36587+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
36588+#endif
36589+
36590 gdt_descr.address = __pa(get_cpu_gdt_table(0));
36591 gdt_descr.size = GDT_SIZE - 1;
36592 load_gdt(&gdt_descr);
36593@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
36594 {
36595 struct desc_ptr gdt_descr;
36596
36597+#ifdef CONFIG_PAX_KERNEXEC
36598+ struct desc_struct d;
36599+
36600+ memset(&d, 0, sizeof d);
36601+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
36602+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
36603+#endif
36604+
36605 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
36606 gdt_descr.size = GDT_SIZE - 1;
36607 load_gdt(&gdt_descr);
36608
36609+#ifdef CONFIG_PAX_PER_CPU_PGD
36610+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
36611+#else
36612 load_cr3(swapper_pg_dir);
36613+#endif
36614+
36615 __flush_tlb_all();
36616
36617 local_irq_restore(efi_rt_eflags);
36618diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
36619index 290d397..3906bcd 100644
36620--- a/arch/x86/platform/efi/efi_64.c
36621+++ b/arch/x86/platform/efi/efi_64.c
36622@@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
36623 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
36624 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
36625 }
36626+
36627+#ifdef CONFIG_PAX_PER_CPU_PGD
36628+ load_cr3(swapper_pg_dir);
36629+#endif
36630+
36631 __flush_tlb_all();
36632 }
36633
36634@@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
36635 for (pgd = 0; pgd < n_pgds; pgd++)
36636 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
36637 kfree(save_pgd);
36638+
36639+#ifdef CONFIG_PAX_PER_CPU_PGD
36640+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
36641+#endif
36642+
36643 __flush_tlb_all();
36644 local_irq_restore(efi_flags);
36645 early_code_mapping_set_exec(0);
36646diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
36647index fbe66e6..eae5e38 100644
36648--- a/arch/x86/platform/efi/efi_stub_32.S
36649+++ b/arch/x86/platform/efi/efi_stub_32.S
36650@@ -6,7 +6,9 @@
36651 */
36652
36653 #include <linux/linkage.h>
36654+#include <linux/init.h>
36655 #include <asm/page_types.h>
36656+#include <asm/segment.h>
36657
36658 /*
36659 * efi_call_phys(void *, ...) is a function with variable parameters.
36660@@ -20,7 +22,7 @@
36661 * service functions will comply with gcc calling convention, too.
36662 */
36663
36664-.text
36665+__INIT
36666 ENTRY(efi_call_phys)
36667 /*
36668 * 0. The function can only be called in Linux kernel. So CS has been
36669@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
36670 * The mapping of lower virtual memory has been created in prelog and
36671 * epilog.
36672 */
36673- movl $1f, %edx
36674- subl $__PAGE_OFFSET, %edx
36675- jmp *%edx
36676+#ifdef CONFIG_PAX_KERNEXEC
36677+ movl $(__KERNEXEC_EFI_DS), %edx
36678+ mov %edx, %ds
36679+ mov %edx, %es
36680+ mov %edx, %ss
36681+ addl $2f,(1f)
36682+ ljmp *(1f)
36683+
36684+__INITDATA
36685+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
36686+.previous
36687+
36688+2:
36689+ subl $2b,(1b)
36690+#else
36691+ jmp 1f-__PAGE_OFFSET
36692 1:
36693+#endif
36694
36695 /*
36696 * 2. Now on the top of stack is the return
36697@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
36698 * parameter 2, ..., param n. To make things easy, we save the return
36699 * address of efi_call_phys in a global variable.
36700 */
36701- popl %edx
36702- movl %edx, saved_return_addr
36703- /* get the function pointer into ECX*/
36704- popl %ecx
36705- movl %ecx, efi_rt_function_ptr
36706- movl $2f, %edx
36707- subl $__PAGE_OFFSET, %edx
36708- pushl %edx
36709+ popl (saved_return_addr)
36710+ popl (efi_rt_function_ptr)
36711
36712 /*
36713 * 3. Clear PG bit in %CR0.
36714@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
36715 /*
36716 * 5. Call the physical function.
36717 */
36718- jmp *%ecx
36719+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
36720
36721-2:
36722 /*
36723 * 6. After EFI runtime service returns, control will return to
36724 * following instruction. We'd better readjust stack pointer first.
36725@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
36726 movl %cr0, %edx
36727 orl $0x80000000, %edx
36728 movl %edx, %cr0
36729- jmp 1f
36730-1:
36731+
36732 /*
36733 * 8. Now restore the virtual mode from flat mode by
36734 * adding EIP with PAGE_OFFSET.
36735 */
36736- movl $1f, %edx
36737- jmp *%edx
36738+#ifdef CONFIG_PAX_KERNEXEC
36739+ movl $(__KERNEL_DS), %edx
36740+ mov %edx, %ds
36741+ mov %edx, %es
36742+ mov %edx, %ss
36743+ ljmp $(__KERNEL_CS),$1f
36744+#else
36745+ jmp 1f+__PAGE_OFFSET
36746+#endif
36747 1:
36748
36749 /*
36750 * 9. Balance the stack. And because EAX contain the return value,
36751 * we'd better not clobber it.
36752 */
36753- leal efi_rt_function_ptr, %edx
36754- movl (%edx), %ecx
36755- pushl %ecx
36756+ pushl (efi_rt_function_ptr)
36757
36758 /*
36759- * 10. Push the saved return address onto the stack and return.
36760+ * 10. Return to the saved return address.
36761 */
36762- leal saved_return_addr, %edx
36763- movl (%edx), %ecx
36764- pushl %ecx
36765- ret
36766+ jmpl *(saved_return_addr)
36767 ENDPROC(efi_call_phys)
36768 .previous
36769
36770-.data
36771+__INITDATA
36772 saved_return_addr:
36773 .long 0
36774 efi_rt_function_ptr:
36775diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
36776index 5fcda72..b9d1d65 100644
36777--- a/arch/x86/platform/efi/efi_stub_64.S
36778+++ b/arch/x86/platform/efi/efi_stub_64.S
36779@@ -11,6 +11,7 @@
36780 #include <asm/msr.h>
36781 #include <asm/processor-flags.h>
36782 #include <asm/page_types.h>
36783+#include <asm/alternative-asm.h>
36784
36785 #define SAVE_XMM \
36786 mov %rsp, %rax; \
36787@@ -88,6 +89,7 @@ ENTRY(efi_call)
36788 RESTORE_PGT
36789 addq $48, %rsp
36790 RESTORE_XMM
36791+ pax_force_retaddr 0, 1
36792 ret
36793 ENDPROC(efi_call)
36794
36795diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
36796index 1bbedc4..eb795b5 100644
36797--- a/arch/x86/platform/intel-mid/intel-mid.c
36798+++ b/arch/x86/platform/intel-mid/intel-mid.c
36799@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
36800 {
36801 };
36802
36803-static void intel_mid_reboot(void)
36804+static void __noreturn intel_mid_reboot(void)
36805 {
36806 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
36807+ BUG();
36808 }
36809
36810 static unsigned long __init intel_mid_calibrate_tsc(void)
36811diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
36812index d6ee929..3637cb5 100644
36813--- a/arch/x86/platform/olpc/olpc_dt.c
36814+++ b/arch/x86/platform/olpc/olpc_dt.c
36815@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
36816 return res;
36817 }
36818
36819-static struct of_pdt_ops prom_olpc_ops __initdata = {
36820+static struct of_pdt_ops prom_olpc_ops __initconst = {
36821 .nextprop = olpc_dt_nextprop,
36822 .getproplen = olpc_dt_getproplen,
36823 .getproperty = olpc_dt_getproperty,
36824diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
36825index 424f4c9..f2a2988 100644
36826--- a/arch/x86/power/cpu.c
36827+++ b/arch/x86/power/cpu.c
36828@@ -137,11 +137,8 @@ static void do_fpu_end(void)
36829 static void fix_processor_context(void)
36830 {
36831 int cpu = smp_processor_id();
36832- struct tss_struct *t = &per_cpu(init_tss, cpu);
36833-#ifdef CONFIG_X86_64
36834- struct desc_struct *desc = get_cpu_gdt_table(cpu);
36835- tss_desc tss;
36836-#endif
36837+ struct tss_struct *t = init_tss + cpu;
36838+
36839 set_tss_desc(cpu, t); /*
36840 * This just modifies memory; should not be
36841 * necessary. But... This is necessary, because
36842@@ -150,10 +147,6 @@ static void fix_processor_context(void)
36843 */
36844
36845 #ifdef CONFIG_X86_64
36846- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
36847- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
36848- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
36849-
36850 syscall_init(); /* This sets MSR_*STAR and related */
36851 #endif
36852 load_TR_desc(); /* This does ltr */
36853diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
36854index bad628a..a102610 100644
36855--- a/arch/x86/realmode/init.c
36856+++ b/arch/x86/realmode/init.c
36857@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
36858 __va(real_mode_header->trampoline_header);
36859
36860 #ifdef CONFIG_X86_32
36861- trampoline_header->start = __pa_symbol(startup_32_smp);
36862+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
36863+
36864+#ifdef CONFIG_PAX_KERNEXEC
36865+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
36866+#endif
36867+
36868+ trampoline_header->boot_cs = __BOOT_CS;
36869 trampoline_header->gdt_limit = __BOOT_DS + 7;
36870 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
36871 #else
36872@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
36873 *trampoline_cr4_features = read_cr4();
36874
36875 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
36876- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
36877+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
36878 trampoline_pgd[511] = init_level4_pgt[511].pgd;
36879 #endif
36880 }
36881diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
36882index 7c0d7be..d24dc88 100644
36883--- a/arch/x86/realmode/rm/Makefile
36884+++ b/arch/x86/realmode/rm/Makefile
36885@@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
36886
36887 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
36888 -I$(srctree)/arch/x86/boot
36889+ifdef CONSTIFY_PLUGIN
36890+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
36891+endif
36892 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
36893 GCOV_PROFILE := n
36894diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
36895index a28221d..93c40f1 100644
36896--- a/arch/x86/realmode/rm/header.S
36897+++ b/arch/x86/realmode/rm/header.S
36898@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
36899 #endif
36900 /* APM/BIOS reboot */
36901 .long pa_machine_real_restart_asm
36902-#ifdef CONFIG_X86_64
36903+#ifdef CONFIG_X86_32
36904+ .long __KERNEL_CS
36905+#else
36906 .long __KERNEL32_CS
36907 #endif
36908 END(real_mode_header)
36909diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
36910index 48ddd76..c26749f 100644
36911--- a/arch/x86/realmode/rm/trampoline_32.S
36912+++ b/arch/x86/realmode/rm/trampoline_32.S
36913@@ -24,6 +24,12 @@
36914 #include <asm/page_types.h>
36915 #include "realmode.h"
36916
36917+#ifdef CONFIG_PAX_KERNEXEC
36918+#define ta(X) (X)
36919+#else
36920+#define ta(X) (pa_ ## X)
36921+#endif
36922+
36923 .text
36924 .code16
36925
36926@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
36927
36928 cli # We should be safe anyway
36929
36930- movl tr_start, %eax # where we need to go
36931-
36932 movl $0xA5A5A5A5, trampoline_status
36933 # write marker for master knows we're running
36934
36935@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
36936 movw $1, %dx # protected mode (PE) bit
36937 lmsw %dx # into protected mode
36938
36939- ljmpl $__BOOT_CS, $pa_startup_32
36940+ ljmpl *(trampoline_header)
36941
36942 .section ".text32","ax"
36943 .code32
36944@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
36945 .balign 8
36946 GLOBAL(trampoline_header)
36947 tr_start: .space 4
36948- tr_gdt_pad: .space 2
36949+ tr_boot_cs: .space 2
36950 tr_gdt: .space 6
36951 END(trampoline_header)
36952
36953diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
36954index dac7b20..72dbaca 100644
36955--- a/arch/x86/realmode/rm/trampoline_64.S
36956+++ b/arch/x86/realmode/rm/trampoline_64.S
36957@@ -93,6 +93,7 @@ ENTRY(startup_32)
36958 movl %edx, %gs
36959
36960 movl pa_tr_cr4, %eax
36961+ andl $~X86_CR4_PCIDE, %eax
36962 movl %eax, %cr4 # Enable PAE mode
36963
36964 # Setup trampoline 4 level pagetables
36965@@ -106,7 +107,7 @@ ENTRY(startup_32)
36966 wrmsr
36967
36968 # Enable paging and in turn activate Long Mode
36969- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
36970+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
36971 movl %eax, %cr0
36972
36973 /*
36974diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
36975index 9e7e147..25a4158 100644
36976--- a/arch/x86/realmode/rm/wakeup_asm.S
36977+++ b/arch/x86/realmode/rm/wakeup_asm.S
36978@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
36979 lgdtl pmode_gdt
36980
36981 /* This really couldn't... */
36982- movl pmode_entry, %eax
36983 movl pmode_cr0, %ecx
36984 movl %ecx, %cr0
36985- ljmpl $__KERNEL_CS, $pa_startup_32
36986- /* -> jmp *%eax in trampoline_32.S */
36987+
36988+ ljmpl *pmode_entry
36989 #else
36990 jmp trampoline_start
36991 #endif
36992diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
36993index 604a37e..e49702a 100644
36994--- a/arch/x86/tools/Makefile
36995+++ b/arch/x86/tools/Makefile
36996@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
36997
36998 $(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c
36999
37000-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
37001+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
37002 hostprogs-y += relocs
37003 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
37004 PHONY += relocs
37005diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
37006index bbb1d22..e505211 100644
37007--- a/arch/x86/tools/relocs.c
37008+++ b/arch/x86/tools/relocs.c
37009@@ -1,5 +1,7 @@
37010 /* This is included from relocs_32/64.c */
37011
37012+#include "../../../include/generated/autoconf.h"
37013+
37014 #define ElfW(type) _ElfW(ELF_BITS, type)
37015 #define _ElfW(bits, type) __ElfW(bits, type)
37016 #define __ElfW(bits, type) Elf##bits##_##type
37017@@ -11,6 +13,7 @@
37018 #define Elf_Sym ElfW(Sym)
37019
37020 static Elf_Ehdr ehdr;
37021+static Elf_Phdr *phdr;
37022
37023 struct relocs {
37024 uint32_t *offset;
37025@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
37026 }
37027 }
37028
37029+static void read_phdrs(FILE *fp)
37030+{
37031+ unsigned int i;
37032+
37033+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
37034+ if (!phdr) {
37035+ die("Unable to allocate %d program headers\n",
37036+ ehdr.e_phnum);
37037+ }
37038+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
37039+ die("Seek to %d failed: %s\n",
37040+ ehdr.e_phoff, strerror(errno));
37041+ }
37042+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
37043+ die("Cannot read ELF program headers: %s\n",
37044+ strerror(errno));
37045+ }
37046+ for(i = 0; i < ehdr.e_phnum; i++) {
37047+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
37048+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
37049+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
37050+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
37051+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
37052+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
37053+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
37054+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
37055+ }
37056+
37057+}
37058+
37059 static void read_shdrs(FILE *fp)
37060 {
37061- int i;
37062+ unsigned int i;
37063 Elf_Shdr shdr;
37064
37065 secs = calloc(ehdr.e_shnum, sizeof(struct section));
37066@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
37067
37068 static void read_strtabs(FILE *fp)
37069 {
37070- int i;
37071+ unsigned int i;
37072 for (i = 0; i < ehdr.e_shnum; i++) {
37073 struct section *sec = &secs[i];
37074 if (sec->shdr.sh_type != SHT_STRTAB) {
37075@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
37076
37077 static void read_symtabs(FILE *fp)
37078 {
37079- int i,j;
37080+ unsigned int i,j;
37081 for (i = 0; i < ehdr.e_shnum; i++) {
37082 struct section *sec = &secs[i];
37083 if (sec->shdr.sh_type != SHT_SYMTAB) {
37084@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
37085 }
37086
37087
37088-static void read_relocs(FILE *fp)
37089+static void read_relocs(FILE *fp, int use_real_mode)
37090 {
37091- int i,j;
37092+ unsigned int i,j;
37093+ uint32_t base;
37094+
37095 for (i = 0; i < ehdr.e_shnum; i++) {
37096 struct section *sec = &secs[i];
37097 if (sec->shdr.sh_type != SHT_REL_TYPE) {
37098@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
37099 die("Cannot read symbol table: %s\n",
37100 strerror(errno));
37101 }
37102+ base = 0;
37103+
37104+#ifdef CONFIG_X86_32
37105+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
37106+ if (phdr[j].p_type != PT_LOAD )
37107+ continue;
37108+ if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
37109+ continue;
37110+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
37111+ break;
37112+ }
37113+#endif
37114+
37115 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
37116 Elf_Rel *rel = &sec->reltab[j];
37117- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
37118+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
37119 rel->r_info = elf_xword_to_cpu(rel->r_info);
37120 #if (SHT_REL_TYPE == SHT_RELA)
37121 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
37122@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
37123
37124 static void print_absolute_symbols(void)
37125 {
37126- int i;
37127+ unsigned int i;
37128 const char *format;
37129
37130 if (ELF_BITS == 64)
37131@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
37132 for (i = 0; i < ehdr.e_shnum; i++) {
37133 struct section *sec = &secs[i];
37134 char *sym_strtab;
37135- int j;
37136+ unsigned int j;
37137
37138 if (sec->shdr.sh_type != SHT_SYMTAB) {
37139 continue;
37140@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
37141
37142 static void print_absolute_relocs(void)
37143 {
37144- int i, printed = 0;
37145+ unsigned int i, printed = 0;
37146 const char *format;
37147
37148 if (ELF_BITS == 64)
37149@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
37150 struct section *sec_applies, *sec_symtab;
37151 char *sym_strtab;
37152 Elf_Sym *sh_symtab;
37153- int j;
37154+ unsigned int j;
37155 if (sec->shdr.sh_type != SHT_REL_TYPE) {
37156 continue;
37157 }
37158@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
37159 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
37160 Elf_Sym *sym, const char *symname))
37161 {
37162- int i;
37163+ unsigned int i;
37164 /* Walk through the relocations */
37165 for (i = 0; i < ehdr.e_shnum; i++) {
37166 char *sym_strtab;
37167 Elf_Sym *sh_symtab;
37168 struct section *sec_applies, *sec_symtab;
37169- int j;
37170+ unsigned int j;
37171 struct section *sec = &secs[i];
37172
37173 if (sec->shdr.sh_type != SHT_REL_TYPE) {
37174@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
37175 {
37176 unsigned r_type = ELF32_R_TYPE(rel->r_info);
37177 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
37178+ char *sym_strtab = sec->link->link->strtab;
37179+
37180+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
37181+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
37182+ return 0;
37183+
37184+#ifdef CONFIG_PAX_KERNEXEC
37185+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
37186+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
37187+ return 0;
37188+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
37189+ return 0;
37190+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
37191+ return 0;
37192+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
37193+ return 0;
37194+#endif
37195
37196 switch (r_type) {
37197 case R_386_NONE:
37198@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
37199
37200 static void emit_relocs(int as_text, int use_real_mode)
37201 {
37202- int i;
37203+ unsigned int i;
37204 int (*write_reloc)(uint32_t, FILE *) = write32;
37205 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
37206 const char *symname);
37207@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
37208 {
37209 regex_init(use_real_mode);
37210 read_ehdr(fp);
37211+ read_phdrs(fp);
37212 read_shdrs(fp);
37213 read_strtabs(fp);
37214 read_symtabs(fp);
37215- read_relocs(fp);
37216+ read_relocs(fp, use_real_mode);
37217 if (ELF_BITS == 64)
37218 percpu_init();
37219 if (show_absolute_syms) {
37220diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
37221index f40281e..92728c9 100644
37222--- a/arch/x86/um/mem_32.c
37223+++ b/arch/x86/um/mem_32.c
37224@@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
37225 gate_vma.vm_start = FIXADDR_USER_START;
37226 gate_vma.vm_end = FIXADDR_USER_END;
37227 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
37228- gate_vma.vm_page_prot = __P101;
37229+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
37230
37231 return 0;
37232 }
37233diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
37234index 80ffa5b..a33bd15 100644
37235--- a/arch/x86/um/tls_32.c
37236+++ b/arch/x86/um/tls_32.c
37237@@ -260,7 +260,7 @@ out:
37238 if (unlikely(task == current &&
37239 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
37240 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
37241- "without flushed TLS.", current->pid);
37242+ "without flushed TLS.", task_pid_nr(current));
37243 }
37244
37245 return 0;
37246diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
37247index 61b04fe..3134230 100644
37248--- a/arch/x86/vdso/Makefile
37249+++ b/arch/x86/vdso/Makefile
37250@@ -170,7 +170,7 @@ quiet_cmd_vdso = VDSO $@
37251 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
37252 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
37253
37254-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
37255+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
37256 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
37257 GCOV_PROFILE := n
37258
37259diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
37260index e4f7781..ab5ab26 100644
37261--- a/arch/x86/vdso/vdso32-setup.c
37262+++ b/arch/x86/vdso/vdso32-setup.c
37263@@ -14,6 +14,7 @@
37264 #include <asm/cpufeature.h>
37265 #include <asm/processor.h>
37266 #include <asm/vdso.h>
37267+#include <asm/mman.h>
37268
37269 #ifdef CONFIG_COMPAT_VDSO
37270 #define VDSO_DEFAULT 0
37271diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
37272index 5a5176d..e570acd 100644
37273--- a/arch/x86/vdso/vma.c
37274+++ b/arch/x86/vdso/vma.c
37275@@ -16,10 +16,9 @@
37276 #include <asm/vdso.h>
37277 #include <asm/page.h>
37278 #include <asm/hpet.h>
37279+#include <asm/mman.h>
37280
37281 #if defined(CONFIG_X86_64)
37282-unsigned int __read_mostly vdso64_enabled = 1;
37283-
37284 extern unsigned short vdso_sync_cpuid;
37285 #endif
37286
37287@@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
37288 .pages = no_pages,
37289 };
37290
37291+#ifdef CONFIG_PAX_RANDMMAP
37292+ if (mm->pax_flags & MF_PAX_RANDMMAP)
37293+ calculate_addr = false;
37294+#endif
37295+
37296 if (calculate_addr) {
37297 addr = vdso_addr(current->mm->start_stack,
37298 image->sym_end_mapping);
37299@@ -110,13 +114,13 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
37300
37301 down_write(&mm->mmap_sem);
37302
37303- addr = get_unmapped_area(NULL, addr, image->sym_end_mapping, 0, 0);
37304+ addr = get_unmapped_area(NULL, addr, image->sym_end_mapping, 0, MAP_EXECUTABLE);
37305 if (IS_ERR_VALUE(addr)) {
37306 ret = addr;
37307 goto up_fail;
37308 }
37309
37310- current->mm->context.vdso = (void __user *)addr;
37311+ mm->context.vdso = addr;
37312
37313 /*
37314 * MAYWRITE to allow gdb to COW and set breakpoints
37315@@ -161,15 +165,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
37316 hpet_address >> PAGE_SHIFT,
37317 PAGE_SIZE,
37318 pgprot_noncached(PAGE_READONLY));
37319-
37320- if (ret)
37321- goto up_fail;
37322 }
37323 #endif
37324
37325 up_fail:
37326 if (ret)
37327- current->mm->context.vdso = NULL;
37328+ current->mm->context.vdso = 0;
37329
37330 up_write(&mm->mmap_sem);
37331 return ret;
37332@@ -189,8 +190,8 @@ static int load_vdso32(void)
37333
37334 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
37335 current_thread_info()->sysenter_return =
37336- current->mm->context.vdso +
37337- selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
37338+ (void __force_user *)(current->mm->context.vdso +
37339+ selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
37340
37341 return 0;
37342 }
37343@@ -199,9 +200,6 @@ static int load_vdso32(void)
37344 #ifdef CONFIG_X86_64
37345 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
37346 {
37347- if (!vdso64_enabled)
37348- return 0;
37349-
37350 return map_vdso(&vdso_image_64, true);
37351 }
37352
37353@@ -210,12 +208,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
37354 int uses_interp)
37355 {
37356 #ifdef CONFIG_X86_X32_ABI
37357- if (test_thread_flag(TIF_X32)) {
37358- if (!vdso64_enabled)
37359- return 0;
37360-
37361+ if (test_thread_flag(TIF_X32))
37362 return map_vdso(&vdso_image_x32, true);
37363- }
37364 #endif
37365
37366 return load_vdso32();
37367@@ -227,12 +221,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
37368 return load_vdso32();
37369 }
37370 #endif
37371-
37372-#ifdef CONFIG_X86_64
37373-static __init int vdso_setup(char *s)
37374-{
37375- vdso64_enabled = simple_strtoul(s, NULL, 0);
37376- return 0;
37377-}
37378-__setup("vdso=", vdso_setup);
37379-#endif
37380diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
37381index e88fda8..76ce7ce 100644
37382--- a/arch/x86/xen/Kconfig
37383+++ b/arch/x86/xen/Kconfig
37384@@ -9,6 +9,7 @@ config XEN
37385 select XEN_HAVE_PVMMU
37386 depends on X86_64 || (X86_32 && X86_PAE)
37387 depends on X86_TSC
37388+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
37389 help
37390 This is the Linux Xen port. Enabling this will allow the
37391 kernel to boot in a paravirtualized environment under the
37392diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
37393index ffb101e..98c0ecf 100644
37394--- a/arch/x86/xen/enlighten.c
37395+++ b/arch/x86/xen/enlighten.c
37396@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
37397
37398 struct shared_info xen_dummy_shared_info;
37399
37400-void *xen_initial_gdt;
37401-
37402 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
37403 __read_mostly int xen_have_vector_callback;
37404 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
37405@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
37406 {
37407 unsigned long va = dtr->address;
37408 unsigned int size = dtr->size + 1;
37409- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
37410- unsigned long frames[pages];
37411+ unsigned long frames[65536 / PAGE_SIZE];
37412 int f;
37413
37414 /*
37415@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
37416 {
37417 unsigned long va = dtr->address;
37418 unsigned int size = dtr->size + 1;
37419- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
37420- unsigned long frames[pages];
37421+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
37422 int f;
37423
37424 /*
37425@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
37426 * 8-byte entries, or 16 4k pages..
37427 */
37428
37429- BUG_ON(size > 65536);
37430+ BUG_ON(size > GDT_SIZE);
37431 BUG_ON(va & ~PAGE_MASK);
37432
37433 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
37434@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
37435 return 0;
37436 }
37437
37438-static void set_xen_basic_apic_ops(void)
37439+static void __init set_xen_basic_apic_ops(void)
37440 {
37441 apic->read = xen_apic_read;
37442 apic->write = xen_apic_write;
37443@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
37444 #endif
37445 };
37446
37447-static void xen_reboot(int reason)
37448+static __noreturn void xen_reboot(int reason)
37449 {
37450 struct sched_shutdown r = { .reason = reason };
37451
37452- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
37453- BUG();
37454+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
37455+ BUG();
37456 }
37457
37458-static void xen_restart(char *msg)
37459+static __noreturn void xen_restart(char *msg)
37460 {
37461 xen_reboot(SHUTDOWN_reboot);
37462 }
37463
37464-static void xen_emergency_restart(void)
37465+static __noreturn void xen_emergency_restart(void)
37466 {
37467 xen_reboot(SHUTDOWN_reboot);
37468 }
37469
37470-static void xen_machine_halt(void)
37471+static __noreturn void xen_machine_halt(void)
37472 {
37473 xen_reboot(SHUTDOWN_poweroff);
37474 }
37475
37476-static void xen_machine_power_off(void)
37477+static __noreturn void xen_machine_power_off(void)
37478 {
37479 if (pm_power_off)
37480 pm_power_off();
37481@@ -1568,7 +1564,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
37482 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
37483
37484 /* Work out if we support NX */
37485- x86_configure_nx();
37486+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
37487+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
37488+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
37489+ unsigned l, h;
37490+
37491+ __supported_pte_mask |= _PAGE_NX;
37492+ rdmsr(MSR_EFER, l, h);
37493+ l |= EFER_NX;
37494+ wrmsr(MSR_EFER, l, h);
37495+ }
37496+#endif
37497
37498 /* Get mfn list */
37499 xen_build_dynamic_phys_to_machine();
37500@@ -1596,13 +1602,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
37501
37502 machine_ops = xen_machine_ops;
37503
37504- /*
37505- * The only reliable way to retain the initial address of the
37506- * percpu gdt_page is to remember it here, so we can go and
37507- * mark it RW later, when the initial percpu area is freed.
37508- */
37509- xen_initial_gdt = &per_cpu(gdt_page, 0);
37510-
37511 xen_smp_init();
37512
37513 #ifdef CONFIG_ACPI_NUMA
37514diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
37515index e8a1201..046c66c 100644
37516--- a/arch/x86/xen/mmu.c
37517+++ b/arch/x86/xen/mmu.c
37518@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
37519 return val;
37520 }
37521
37522-static pteval_t pte_pfn_to_mfn(pteval_t val)
37523+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
37524 {
37525 if (val & _PAGE_PRESENT) {
37526 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
37527@@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
37528 /* L3_k[510] -> level2_kernel_pgt
37529 * L3_i[511] -> level2_fixmap_pgt */
37530 convert_pfn_mfn(level3_kernel_pgt);
37531+ convert_pfn_mfn(level3_vmalloc_start_pgt);
37532+ convert_pfn_mfn(level3_vmalloc_end_pgt);
37533+ convert_pfn_mfn(level3_vmemmap_pgt);
37534 }
37535 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
37536 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
37537@@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
37538 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
37539 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
37540 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
37541+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
37542+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
37543+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
37544 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
37545 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
37546+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
37547 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
37548 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
37549
37550@@ -2120,6 +2127,7 @@ static void __init xen_post_allocator_init(void)
37551 pv_mmu_ops.set_pud = xen_set_pud;
37552 #if PAGETABLE_LEVELS == 4
37553 pv_mmu_ops.set_pgd = xen_set_pgd;
37554+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
37555 #endif
37556
37557 /* This will work as long as patching hasn't happened yet
37558@@ -2198,6 +2206,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
37559 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
37560 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
37561 .set_pgd = xen_set_pgd_hyper,
37562+ .set_pgd_batched = xen_set_pgd_hyper,
37563
37564 .alloc_pud = xen_alloc_pmd_init,
37565 .release_pud = xen_release_pmd_init,
37566diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
37567index 7005974..54fb05f 100644
37568--- a/arch/x86/xen/smp.c
37569+++ b/arch/x86/xen/smp.c
37570@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
37571
37572 if (xen_pv_domain()) {
37573 if (!xen_feature(XENFEAT_writable_page_tables))
37574- /* We've switched to the "real" per-cpu gdt, so make
37575- * sure the old memory can be recycled. */
37576- make_lowmem_page_readwrite(xen_initial_gdt);
37577-
37578 #ifdef CONFIG_X86_32
37579 /*
37580 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
37581 * expects __USER_DS
37582 */
37583- loadsegment(ds, __USER_DS);
37584- loadsegment(es, __USER_DS);
37585+ loadsegment(ds, __KERNEL_DS);
37586+ loadsegment(es, __KERNEL_DS);
37587 #endif
37588
37589 xen_filter_cpu_maps();
37590@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
37591 #ifdef CONFIG_X86_32
37592 /* Note: PVH is not yet supported on x86_32. */
37593 ctxt->user_regs.fs = __KERNEL_PERCPU;
37594- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
37595+ savesegment(gs, ctxt->user_regs.gs);
37596 #endif
37597 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
37598
37599@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
37600 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
37601 ctxt->flags = VGCF_IN_KERNEL;
37602 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
37603- ctxt->user_regs.ds = __USER_DS;
37604- ctxt->user_regs.es = __USER_DS;
37605+ ctxt->user_regs.ds = __KERNEL_DS;
37606+ ctxt->user_regs.es = __KERNEL_DS;
37607 ctxt->user_regs.ss = __KERNEL_DS;
37608
37609 xen_copy_trap_info(ctxt->trap_ctxt);
37610@@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
37611 int rc;
37612
37613 per_cpu(current_task, cpu) = idle;
37614+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
37615 #ifdef CONFIG_X86_32
37616 irq_ctx_init(cpu);
37617 #else
37618 clear_tsk_thread_flag(idle, TIF_FORK);
37619 #endif
37620- per_cpu(kernel_stack, cpu) =
37621- (unsigned long)task_stack_page(idle) -
37622- KERNEL_STACK_OFFSET + THREAD_SIZE;
37623+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
37624
37625 xen_setup_runstate_info(cpu);
37626 xen_setup_timer(cpu);
37627@@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
37628
37629 void __init xen_smp_init(void)
37630 {
37631- smp_ops = xen_smp_ops;
37632+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
37633 xen_fill_possible_map();
37634 }
37635
37636diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
37637index fd92a64..1f72641 100644
37638--- a/arch/x86/xen/xen-asm_32.S
37639+++ b/arch/x86/xen/xen-asm_32.S
37640@@ -99,7 +99,7 @@ ENTRY(xen_iret)
37641 pushw %fs
37642 movl $(__KERNEL_PERCPU), %eax
37643 movl %eax, %fs
37644- movl %fs:xen_vcpu, %eax
37645+ mov PER_CPU_VAR(xen_vcpu), %eax
37646 POP_FS
37647 #else
37648 movl %ss:xen_vcpu, %eax
37649diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
37650index 485b695..fda3e7c 100644
37651--- a/arch/x86/xen/xen-head.S
37652+++ b/arch/x86/xen/xen-head.S
37653@@ -39,6 +39,17 @@ ENTRY(startup_xen)
37654 #ifdef CONFIG_X86_32
37655 mov %esi,xen_start_info
37656 mov $init_thread_union+THREAD_SIZE,%esp
37657+#ifdef CONFIG_SMP
37658+ movl $cpu_gdt_table,%edi
37659+ movl $__per_cpu_load,%eax
37660+ movw %ax,__KERNEL_PERCPU + 2(%edi)
37661+ rorl $16,%eax
37662+ movb %al,__KERNEL_PERCPU + 4(%edi)
37663+ movb %ah,__KERNEL_PERCPU + 7(%edi)
37664+ movl $__per_cpu_end - 1,%eax
37665+ subl $__per_cpu_start,%eax
37666+ movw %ax,__KERNEL_PERCPU + 0(%edi)
37667+#endif
37668 #else
37669 mov %rsi,xen_start_info
37670 mov $init_thread_union+THREAD_SIZE,%rsp
37671diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
37672index 97d8765..c4526ec 100644
37673--- a/arch/x86/xen/xen-ops.h
37674+++ b/arch/x86/xen/xen-ops.h
37675@@ -10,8 +10,6 @@
37676 extern const char xen_hypervisor_callback[];
37677 extern const char xen_failsafe_callback[];
37678
37679-extern void *xen_initial_gdt;
37680-
37681 struct trap_info;
37682 void xen_copy_trap_info(struct trap_info *traps);
37683
37684diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
37685index 525bd3d..ef888b1 100644
37686--- a/arch/xtensa/variants/dc232b/include/variant/core.h
37687+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
37688@@ -119,9 +119,9 @@
37689 ----------------------------------------------------------------------*/
37690
37691 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
37692-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
37693 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
37694 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
37695+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
37696
37697 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
37698 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
37699diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
37700index 2f33760..835e50a 100644
37701--- a/arch/xtensa/variants/fsf/include/variant/core.h
37702+++ b/arch/xtensa/variants/fsf/include/variant/core.h
37703@@ -11,6 +11,7 @@
37704 #ifndef _XTENSA_CORE_H
37705 #define _XTENSA_CORE_H
37706
37707+#include <linux/const.h>
37708
37709 /****************************************************************************
37710 Parameters Useful for Any Code, USER or PRIVILEGED
37711@@ -112,9 +113,9 @@
37712 ----------------------------------------------------------------------*/
37713
37714 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
37715-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
37716 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
37717 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
37718+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
37719
37720 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
37721 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
37722diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
37723index af00795..2bb8105 100644
37724--- a/arch/xtensa/variants/s6000/include/variant/core.h
37725+++ b/arch/xtensa/variants/s6000/include/variant/core.h
37726@@ -11,6 +11,7 @@
37727 #ifndef _XTENSA_CORE_CONFIGURATION_H
37728 #define _XTENSA_CORE_CONFIGURATION_H
37729
37730+#include <linux/const.h>
37731
37732 /****************************************************************************
37733 Parameters Useful for Any Code, USER or PRIVILEGED
37734@@ -118,9 +119,9 @@
37735 ----------------------------------------------------------------------*/
37736
37737 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
37738-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
37739 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
37740 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
37741+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
37742
37743 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
37744 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
37745diff --git a/block/bio.c b/block/bio.c
37746index 0ec61c9..93b94060 100644
37747--- a/block/bio.c
37748+++ b/block/bio.c
37749@@ -1159,7 +1159,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
37750 /*
37751 * Overflow, abort
37752 */
37753- if (end < start)
37754+ if (end < start || end - start > INT_MAX - nr_pages)
37755 return ERR_PTR(-EINVAL);
37756
37757 nr_pages += end - start;
37758@@ -1293,7 +1293,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
37759 /*
37760 * Overflow, abort
37761 */
37762- if (end < start)
37763+ if (end < start || end - start > INT_MAX - nr_pages)
37764 return ERR_PTR(-EINVAL);
37765
37766 nr_pages += end - start;
37767@@ -1555,7 +1555,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
37768 const int read = bio_data_dir(bio) == READ;
37769 struct bio_map_data *bmd = bio->bi_private;
37770 int i;
37771- char *p = bmd->sgvecs[0].iov_base;
37772+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
37773
37774 bio_for_each_segment_all(bvec, bio, i) {
37775 char *addr = page_address(bvec->bv_page);
37776diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
37777index 28d227c..d4c0bad 100644
37778--- a/block/blk-cgroup.c
37779+++ b/block/blk-cgroup.c
37780@@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
37781 static struct cgroup_subsys_state *
37782 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
37783 {
37784- static atomic64_t id_seq = ATOMIC64_INIT(0);
37785+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
37786 struct blkcg *blkcg;
37787
37788 if (!parent_css) {
37789@@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
37790
37791 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
37792 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
37793- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
37794+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
37795 done:
37796 spin_lock_init(&blkcg->lock);
37797 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
37798diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
37799index 0736729..2ec3b48 100644
37800--- a/block/blk-iopoll.c
37801+++ b/block/blk-iopoll.c
37802@@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
37803 }
37804 EXPORT_SYMBOL(blk_iopoll_complete);
37805
37806-static void blk_iopoll_softirq(struct softirq_action *h)
37807+static __latent_entropy void blk_iopoll_softirq(void)
37808 {
37809 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
37810 int rearm = 0, budget = blk_iopoll_budget;
37811diff --git a/block/blk-map.c b/block/blk-map.c
37812index f890d43..97b0482 100644
37813--- a/block/blk-map.c
37814+++ b/block/blk-map.c
37815@@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
37816 if (!len || !kbuf)
37817 return -EINVAL;
37818
37819- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
37820+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
37821 if (do_copy)
37822 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
37823 else
37824diff --git a/block/blk-softirq.c b/block/blk-softirq.c
37825index 53b1737..08177d2e 100644
37826--- a/block/blk-softirq.c
37827+++ b/block/blk-softirq.c
37828@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
37829 * Softirq action handler - move entries to local list and loop over them
37830 * while passing them to the queue registered handler.
37831 */
37832-static void blk_done_softirq(struct softirq_action *h)
37833+static __latent_entropy void blk_done_softirq(void)
37834 {
37835 struct list_head *cpu_list, local_list;
37836
37837diff --git a/block/bsg.c b/block/bsg.c
37838index ff46add..c4ba8ee 100644
37839--- a/block/bsg.c
37840+++ b/block/bsg.c
37841@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
37842 struct sg_io_v4 *hdr, struct bsg_device *bd,
37843 fmode_t has_write_perm)
37844 {
37845+ unsigned char tmpcmd[sizeof(rq->__cmd)];
37846+ unsigned char *cmdptr;
37847+
37848 if (hdr->request_len > BLK_MAX_CDB) {
37849 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
37850 if (!rq->cmd)
37851 return -ENOMEM;
37852- }
37853+ cmdptr = rq->cmd;
37854+ } else
37855+ cmdptr = tmpcmd;
37856
37857- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
37858+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
37859 hdr->request_len))
37860 return -EFAULT;
37861
37862+ if (cmdptr != rq->cmd)
37863+ memcpy(rq->cmd, cmdptr, hdr->request_len);
37864+
37865 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
37866 if (blk_verify_command(rq->cmd, has_write_perm))
37867 return -EPERM;
37868diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
37869index a0926a6..b2b14b2 100644
37870--- a/block/compat_ioctl.c
37871+++ b/block/compat_ioctl.c
37872@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
37873 cgc = compat_alloc_user_space(sizeof(*cgc));
37874 cgc32 = compat_ptr(arg);
37875
37876- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
37877+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
37878 get_user(data, &cgc32->buffer) ||
37879 put_user(compat_ptr(data), &cgc->buffer) ||
37880 copy_in_user(&cgc->buflen, &cgc32->buflen,
37881@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
37882 err |= __get_user(f->spec1, &uf->spec1);
37883 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
37884 err |= __get_user(name, &uf->name);
37885- f->name = compat_ptr(name);
37886+ f->name = (void __force_kernel *)compat_ptr(name);
37887 if (err) {
37888 err = -EFAULT;
37889 goto out;
37890diff --git a/block/genhd.c b/block/genhd.c
37891index 791f419..89f21c4 100644
37892--- a/block/genhd.c
37893+++ b/block/genhd.c
37894@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
37895
37896 /*
37897 * Register device numbers dev..(dev+range-1)
37898- * range must be nonzero
37899+ * Noop if @range is zero.
37900 * The hash chain is sorted on range, so that subranges can override.
37901 */
37902 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
37903 struct kobject *(*probe)(dev_t, int *, void *),
37904 int (*lock)(dev_t, void *), void *data)
37905 {
37906- kobj_map(bdev_map, devt, range, module, probe, lock, data);
37907+ if (range)
37908+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
37909 }
37910
37911 EXPORT_SYMBOL(blk_register_region);
37912
37913+/* undo blk_register_region(), noop if @range is zero */
37914 void blk_unregister_region(dev_t devt, unsigned long range)
37915 {
37916- kobj_unmap(bdev_map, devt, range);
37917+ if (range)
37918+ kobj_unmap(bdev_map, devt, range);
37919 }
37920
37921 EXPORT_SYMBOL(blk_unregister_region);
37922diff --git a/block/partitions/efi.c b/block/partitions/efi.c
37923index dc51f46..d5446a8 100644
37924--- a/block/partitions/efi.c
37925+++ b/block/partitions/efi.c
37926@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
37927 if (!gpt)
37928 return NULL;
37929
37930+ if (!le32_to_cpu(gpt->num_partition_entries))
37931+ return NULL;
37932+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
37933+ if (!pte)
37934+ return NULL;
37935+
37936 count = le32_to_cpu(gpt->num_partition_entries) *
37937 le32_to_cpu(gpt->sizeof_partition_entry);
37938- if (!count)
37939- return NULL;
37940- pte = kmalloc(count, GFP_KERNEL);
37941- if (!pte)
37942- return NULL;
37943-
37944 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
37945 (u8 *) pte, count) < count) {
37946 kfree(pte);
37947diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
37948index 14695c6..27a4636 100644
37949--- a/block/scsi_ioctl.c
37950+++ b/block/scsi_ioctl.c
37951@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
37952 return put_user(0, p);
37953 }
37954
37955-static int sg_get_timeout(struct request_queue *q)
37956+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
37957 {
37958 return jiffies_to_clock_t(q->sg_timeout);
37959 }
37960@@ -220,8 +220,20 @@ EXPORT_SYMBOL(blk_verify_command);
37961 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
37962 struct sg_io_hdr *hdr, fmode_t mode)
37963 {
37964- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
37965+ unsigned char tmpcmd[sizeof(rq->__cmd)];
37966+ unsigned char *cmdptr;
37967+
37968+ if (rq->cmd != rq->__cmd)
37969+ cmdptr = rq->cmd;
37970+ else
37971+ cmdptr = tmpcmd;
37972+
37973+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
37974 return -EFAULT;
37975+
37976+ if (cmdptr != rq->cmd)
37977+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
37978+
37979 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
37980 return -EPERM;
37981
37982@@ -413,6 +425,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37983 int err;
37984 unsigned int in_len, out_len, bytes, opcode, cmdlen;
37985 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
37986+ unsigned char tmpcmd[sizeof(rq->__cmd)];
37987+ unsigned char *cmdptr;
37988
37989 if (!sic)
37990 return -EINVAL;
37991@@ -446,9 +460,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37992 */
37993 err = -EFAULT;
37994 rq->cmd_len = cmdlen;
37995- if (copy_from_user(rq->cmd, sic->data, cmdlen))
37996+
37997+ if (rq->cmd != rq->__cmd)
37998+ cmdptr = rq->cmd;
37999+ else
38000+ cmdptr = tmpcmd;
38001+
38002+ if (copy_from_user(cmdptr, sic->data, cmdlen))
38003 goto error;
38004
38005+ if (rq->cmd != cmdptr)
38006+ memcpy(rq->cmd, cmdptr, cmdlen);
38007+
38008 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
38009 goto error;
38010
38011diff --git a/crypto/cryptd.c b/crypto/cryptd.c
38012index 7bdd61b..afec999 100644
38013--- a/crypto/cryptd.c
38014+++ b/crypto/cryptd.c
38015@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
38016
38017 struct cryptd_blkcipher_request_ctx {
38018 crypto_completion_t complete;
38019-};
38020+} __no_const;
38021
38022 struct cryptd_hash_ctx {
38023 struct crypto_shash *child;
38024@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
38025
38026 struct cryptd_aead_request_ctx {
38027 crypto_completion_t complete;
38028-};
38029+} __no_const;
38030
38031 static void cryptd_queue_worker(struct work_struct *work);
38032
38033diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
38034index 309d345..1632720 100644
38035--- a/crypto/pcrypt.c
38036+++ b/crypto/pcrypt.c
38037@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
38038 int ret;
38039
38040 pinst->kobj.kset = pcrypt_kset;
38041- ret = kobject_add(&pinst->kobj, NULL, name);
38042+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
38043 if (!ret)
38044 kobject_uevent(&pinst->kobj, KOBJ_ADD);
38045
38046diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
38047index 6921c7f..78e1af7 100644
38048--- a/drivers/acpi/acpica/hwxfsleep.c
38049+++ b/drivers/acpi/acpica/hwxfsleep.c
38050@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
38051 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
38052
38053 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
38054- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
38055- acpi_hw_extended_sleep},
38056- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
38057- acpi_hw_extended_wake_prep},
38058- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
38059+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
38060+ .extended_function = acpi_hw_extended_sleep},
38061+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
38062+ .extended_function = acpi_hw_extended_wake_prep},
38063+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
38064+ .extended_function = acpi_hw_extended_wake}
38065 };
38066
38067 /*
38068diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
38069index e5bcd91..74f050d 100644
38070--- a/drivers/acpi/apei/apei-internal.h
38071+++ b/drivers/acpi/apei/apei-internal.h
38072@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
38073 struct apei_exec_ins_type {
38074 u32 flags;
38075 apei_exec_ins_func_t run;
38076-};
38077+} __do_const;
38078
38079 struct apei_exec_context {
38080 u32 ip;
38081diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
38082index dab7cb7..f0d2994 100644
38083--- a/drivers/acpi/apei/ghes.c
38084+++ b/drivers/acpi/apei/ghes.c
38085@@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
38086 const struct acpi_hest_generic *generic,
38087 const struct acpi_generic_status *estatus)
38088 {
38089- static atomic_t seqno;
38090+ static atomic_unchecked_t seqno;
38091 unsigned int curr_seqno;
38092 char pfx_seq[64];
38093
38094@@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
38095 else
38096 pfx = KERN_ERR;
38097 }
38098- curr_seqno = atomic_inc_return(&seqno);
38099+ curr_seqno = atomic_inc_return_unchecked(&seqno);
38100 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
38101 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
38102 pfx_seq, generic->header.source_id);
38103diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
38104index a83e3c6..c3d617f 100644
38105--- a/drivers/acpi/bgrt.c
38106+++ b/drivers/acpi/bgrt.c
38107@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
38108 if (!bgrt_image)
38109 return -ENODEV;
38110
38111- bin_attr_image.private = bgrt_image;
38112- bin_attr_image.size = bgrt_image_size;
38113+ pax_open_kernel();
38114+ *(void **)&bin_attr_image.private = bgrt_image;
38115+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
38116+ pax_close_kernel();
38117
38118 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
38119 if (!bgrt_kobj)
38120diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
38121index 3d8413d..95f638c 100644
38122--- a/drivers/acpi/blacklist.c
38123+++ b/drivers/acpi/blacklist.c
38124@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
38125 u32 is_critical_error;
38126 };
38127
38128-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
38129+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
38130
38131 /*
38132 * POLICY: If *anything* doesn't work, put it on the blacklist.
38133@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
38134 return 0;
38135 }
38136
38137-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
38138+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
38139 {
38140 .callback = dmi_disable_osi_vista,
38141 .ident = "Fujitsu Siemens",
38142diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
38143index c68e724..e863008 100644
38144--- a/drivers/acpi/custom_method.c
38145+++ b/drivers/acpi/custom_method.c
38146@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
38147 struct acpi_table_header table;
38148 acpi_status status;
38149
38150+#ifdef CONFIG_GRKERNSEC_KMEM
38151+ return -EPERM;
38152+#endif
38153+
38154 if (!(*ppos)) {
38155 /* parse the table header to get the table length */
38156 if (count <= sizeof(struct acpi_table_header))
38157diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
38158index 3dca36d..abaf070 100644
38159--- a/drivers/acpi/processor_idle.c
38160+++ b/drivers/acpi/processor_idle.c
38161@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
38162 {
38163 int i, count = CPUIDLE_DRIVER_STATE_START;
38164 struct acpi_processor_cx *cx;
38165- struct cpuidle_state *state;
38166+ cpuidle_state_no_const *state;
38167 struct cpuidle_driver *drv = &acpi_idle_driver;
38168
38169 if (!pr->flags.power_setup_done)
38170diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
38171index 38cb978..352c761 100644
38172--- a/drivers/acpi/sysfs.c
38173+++ b/drivers/acpi/sysfs.c
38174@@ -423,11 +423,11 @@ static u32 num_counters;
38175 static struct attribute **all_attrs;
38176 static u32 acpi_gpe_count;
38177
38178-static struct attribute_group interrupt_stats_attr_group = {
38179+static attribute_group_no_const interrupt_stats_attr_group = {
38180 .name = "interrupts",
38181 };
38182
38183-static struct kobj_attribute *counter_attrs;
38184+static kobj_attribute_no_const *counter_attrs;
38185
38186 static void delete_gpe_attr_array(void)
38187 {
38188diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
38189index d72ce04..d6ab3c2 100644
38190--- a/drivers/ata/libahci.c
38191+++ b/drivers/ata/libahci.c
38192@@ -1257,7 +1257,7 @@ int ahci_kick_engine(struct ata_port *ap)
38193 }
38194 EXPORT_SYMBOL_GPL(ahci_kick_engine);
38195
38196-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
38197+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
38198 struct ata_taskfile *tf, int is_cmd, u16 flags,
38199 unsigned long timeout_msec)
38200 {
38201diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
38202index 677c0c1..354b89b 100644
38203--- a/drivers/ata/libata-core.c
38204+++ b/drivers/ata/libata-core.c
38205@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
38206 static void ata_dev_xfermask(struct ata_device *dev);
38207 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
38208
38209-atomic_t ata_print_id = ATOMIC_INIT(0);
38210+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
38211
38212 struct ata_force_param {
38213 const char *name;
38214@@ -4863,7 +4863,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
38215 struct ata_port *ap;
38216 unsigned int tag;
38217
38218- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38219+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38220 ap = qc->ap;
38221
38222 qc->flags = 0;
38223@@ -4879,7 +4879,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
38224 struct ata_port *ap;
38225 struct ata_link *link;
38226
38227- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38228+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38229 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
38230 ap = qc->ap;
38231 link = qc->dev->link;
38232@@ -5983,6 +5983,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
38233 return;
38234
38235 spin_lock(&lock);
38236+ pax_open_kernel();
38237
38238 for (cur = ops->inherits; cur; cur = cur->inherits) {
38239 void **inherit = (void **)cur;
38240@@ -5996,8 +5997,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
38241 if (IS_ERR(*pp))
38242 *pp = NULL;
38243
38244- ops->inherits = NULL;
38245+ *(struct ata_port_operations **)&ops->inherits = NULL;
38246
38247+ pax_close_kernel();
38248 spin_unlock(&lock);
38249 }
38250
38251@@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
38252
38253 /* give ports names and add SCSI hosts */
38254 for (i = 0; i < host->n_ports; i++) {
38255- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
38256+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
38257 host->ports[i]->local_port_no = i + 1;
38258 }
38259
38260diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
38261index 72691fd..ad104c0 100644
38262--- a/drivers/ata/libata-scsi.c
38263+++ b/drivers/ata/libata-scsi.c
38264@@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
38265
38266 if (rc)
38267 return rc;
38268- ap->print_id = atomic_inc_return(&ata_print_id);
38269+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
38270 return 0;
38271 }
38272 EXPORT_SYMBOL_GPL(ata_sas_port_init);
38273diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
38274index 45b5ab3..98446b8 100644
38275--- a/drivers/ata/libata.h
38276+++ b/drivers/ata/libata.h
38277@@ -53,7 +53,7 @@ enum {
38278 ATA_DNXFER_QUIET = (1 << 31),
38279 };
38280
38281-extern atomic_t ata_print_id;
38282+extern atomic_unchecked_t ata_print_id;
38283 extern int atapi_passthru16;
38284 extern int libata_fua;
38285 extern int libata_noacpi;
38286diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
38287index 4edb1a8..84e1658 100644
38288--- a/drivers/ata/pata_arasan_cf.c
38289+++ b/drivers/ata/pata_arasan_cf.c
38290@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
38291 /* Handle platform specific quirks */
38292 if (quirk) {
38293 if (quirk & CF_BROKEN_PIO) {
38294- ap->ops->set_piomode = NULL;
38295+ pax_open_kernel();
38296+ *(void **)&ap->ops->set_piomode = NULL;
38297+ pax_close_kernel();
38298 ap->pio_mask = 0;
38299 }
38300 if (quirk & CF_BROKEN_MWDMA)
38301diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
38302index f9b983a..887b9d8 100644
38303--- a/drivers/atm/adummy.c
38304+++ b/drivers/atm/adummy.c
38305@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
38306 vcc->pop(vcc, skb);
38307 else
38308 dev_kfree_skb_any(skb);
38309- atomic_inc(&vcc->stats->tx);
38310+ atomic_inc_unchecked(&vcc->stats->tx);
38311
38312 return 0;
38313 }
38314diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
38315index f1a9198..f466a4a 100644
38316--- a/drivers/atm/ambassador.c
38317+++ b/drivers/atm/ambassador.c
38318@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
38319 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
38320
38321 // VC layer stats
38322- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38323+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38324
38325 // free the descriptor
38326 kfree (tx_descr);
38327@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
38328 dump_skb ("<<<", vc, skb);
38329
38330 // VC layer stats
38331- atomic_inc(&atm_vcc->stats->rx);
38332+ atomic_inc_unchecked(&atm_vcc->stats->rx);
38333 __net_timestamp(skb);
38334 // end of our responsibility
38335 atm_vcc->push (atm_vcc, skb);
38336@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
38337 } else {
38338 PRINTK (KERN_INFO, "dropped over-size frame");
38339 // should we count this?
38340- atomic_inc(&atm_vcc->stats->rx_drop);
38341+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
38342 }
38343
38344 } else {
38345@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
38346 }
38347
38348 if (check_area (skb->data, skb->len)) {
38349- atomic_inc(&atm_vcc->stats->tx_err);
38350+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
38351 return -ENOMEM; // ?
38352 }
38353
38354diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
38355index 0e3f8f9..765a7a5 100644
38356--- a/drivers/atm/atmtcp.c
38357+++ b/drivers/atm/atmtcp.c
38358@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
38359 if (vcc->pop) vcc->pop(vcc,skb);
38360 else dev_kfree_skb(skb);
38361 if (dev_data) return 0;
38362- atomic_inc(&vcc->stats->tx_err);
38363+ atomic_inc_unchecked(&vcc->stats->tx_err);
38364 return -ENOLINK;
38365 }
38366 size = skb->len+sizeof(struct atmtcp_hdr);
38367@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
38368 if (!new_skb) {
38369 if (vcc->pop) vcc->pop(vcc,skb);
38370 else dev_kfree_skb(skb);
38371- atomic_inc(&vcc->stats->tx_err);
38372+ atomic_inc_unchecked(&vcc->stats->tx_err);
38373 return -ENOBUFS;
38374 }
38375 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
38376@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
38377 if (vcc->pop) vcc->pop(vcc,skb);
38378 else dev_kfree_skb(skb);
38379 out_vcc->push(out_vcc,new_skb);
38380- atomic_inc(&vcc->stats->tx);
38381- atomic_inc(&out_vcc->stats->rx);
38382+ atomic_inc_unchecked(&vcc->stats->tx);
38383+ atomic_inc_unchecked(&out_vcc->stats->rx);
38384 return 0;
38385 }
38386
38387@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
38388 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
38389 read_unlock(&vcc_sklist_lock);
38390 if (!out_vcc) {
38391- atomic_inc(&vcc->stats->tx_err);
38392+ atomic_inc_unchecked(&vcc->stats->tx_err);
38393 goto done;
38394 }
38395 skb_pull(skb,sizeof(struct atmtcp_hdr));
38396@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
38397 __net_timestamp(new_skb);
38398 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
38399 out_vcc->push(out_vcc,new_skb);
38400- atomic_inc(&vcc->stats->tx);
38401- atomic_inc(&out_vcc->stats->rx);
38402+ atomic_inc_unchecked(&vcc->stats->tx);
38403+ atomic_inc_unchecked(&out_vcc->stats->rx);
38404 done:
38405 if (vcc->pop) vcc->pop(vcc,skb);
38406 else dev_kfree_skb(skb);
38407diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
38408index b1955ba..b179940 100644
38409--- a/drivers/atm/eni.c
38410+++ b/drivers/atm/eni.c
38411@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
38412 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
38413 vcc->dev->number);
38414 length = 0;
38415- atomic_inc(&vcc->stats->rx_err);
38416+ atomic_inc_unchecked(&vcc->stats->rx_err);
38417 }
38418 else {
38419 length = ATM_CELL_SIZE-1; /* no HEC */
38420@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
38421 size);
38422 }
38423 eff = length = 0;
38424- atomic_inc(&vcc->stats->rx_err);
38425+ atomic_inc_unchecked(&vcc->stats->rx_err);
38426 }
38427 else {
38428 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
38429@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
38430 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
38431 vcc->dev->number,vcc->vci,length,size << 2,descr);
38432 length = eff = 0;
38433- atomic_inc(&vcc->stats->rx_err);
38434+ atomic_inc_unchecked(&vcc->stats->rx_err);
38435 }
38436 }
38437 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
38438@@ -767,7 +767,7 @@ rx_dequeued++;
38439 vcc->push(vcc,skb);
38440 pushed++;
38441 }
38442- atomic_inc(&vcc->stats->rx);
38443+ atomic_inc_unchecked(&vcc->stats->rx);
38444 }
38445 wake_up(&eni_dev->rx_wait);
38446 }
38447@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
38448 PCI_DMA_TODEVICE);
38449 if (vcc->pop) vcc->pop(vcc,skb);
38450 else dev_kfree_skb_irq(skb);
38451- atomic_inc(&vcc->stats->tx);
38452+ atomic_inc_unchecked(&vcc->stats->tx);
38453 wake_up(&eni_dev->tx_wait);
38454 dma_complete++;
38455 }
38456diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
38457index 82f2ae0..f205c02 100644
38458--- a/drivers/atm/firestream.c
38459+++ b/drivers/atm/firestream.c
38460@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
38461 }
38462 }
38463
38464- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38465+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38466
38467 fs_dprintk (FS_DEBUG_TXMEM, "i");
38468 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
38469@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
38470 #endif
38471 skb_put (skb, qe->p1 & 0xffff);
38472 ATM_SKB(skb)->vcc = atm_vcc;
38473- atomic_inc(&atm_vcc->stats->rx);
38474+ atomic_inc_unchecked(&atm_vcc->stats->rx);
38475 __net_timestamp(skb);
38476 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
38477 atm_vcc->push (atm_vcc, skb);
38478@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
38479 kfree (pe);
38480 }
38481 if (atm_vcc)
38482- atomic_inc(&atm_vcc->stats->rx_drop);
38483+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
38484 break;
38485 case 0x1f: /* Reassembly abort: no buffers. */
38486 /* Silently increment error counter. */
38487 if (atm_vcc)
38488- atomic_inc(&atm_vcc->stats->rx_drop);
38489+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
38490 break;
38491 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
38492 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
38493diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
38494index d4725fc..2d4ea65 100644
38495--- a/drivers/atm/fore200e.c
38496+++ b/drivers/atm/fore200e.c
38497@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
38498 #endif
38499 /* check error condition */
38500 if (*entry->status & STATUS_ERROR)
38501- atomic_inc(&vcc->stats->tx_err);
38502+ atomic_inc_unchecked(&vcc->stats->tx_err);
38503 else
38504- atomic_inc(&vcc->stats->tx);
38505+ atomic_inc_unchecked(&vcc->stats->tx);
38506 }
38507 }
38508
38509@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
38510 if (skb == NULL) {
38511 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
38512
38513- atomic_inc(&vcc->stats->rx_drop);
38514+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38515 return -ENOMEM;
38516 }
38517
38518@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
38519
38520 dev_kfree_skb_any(skb);
38521
38522- atomic_inc(&vcc->stats->rx_drop);
38523+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38524 return -ENOMEM;
38525 }
38526
38527 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
38528
38529 vcc->push(vcc, skb);
38530- atomic_inc(&vcc->stats->rx);
38531+ atomic_inc_unchecked(&vcc->stats->rx);
38532
38533 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
38534
38535@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
38536 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
38537 fore200e->atm_dev->number,
38538 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
38539- atomic_inc(&vcc->stats->rx_err);
38540+ atomic_inc_unchecked(&vcc->stats->rx_err);
38541 }
38542 }
38543
38544@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
38545 goto retry_here;
38546 }
38547
38548- atomic_inc(&vcc->stats->tx_err);
38549+ atomic_inc_unchecked(&vcc->stats->tx_err);
38550
38551 fore200e->tx_sat++;
38552 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
38553diff --git a/drivers/atm/he.c b/drivers/atm/he.c
38554index aa6be26..f70a785 100644
38555--- a/drivers/atm/he.c
38556+++ b/drivers/atm/he.c
38557@@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
38558
38559 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
38560 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
38561- atomic_inc(&vcc->stats->rx_drop);
38562+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38563 goto return_host_buffers;
38564 }
38565
38566@@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
38567 RBRQ_LEN_ERR(he_dev->rbrq_head)
38568 ? "LEN_ERR" : "",
38569 vcc->vpi, vcc->vci);
38570- atomic_inc(&vcc->stats->rx_err);
38571+ atomic_inc_unchecked(&vcc->stats->rx_err);
38572 goto return_host_buffers;
38573 }
38574
38575@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
38576 vcc->push(vcc, skb);
38577 spin_lock(&he_dev->global_lock);
38578
38579- atomic_inc(&vcc->stats->rx);
38580+ atomic_inc_unchecked(&vcc->stats->rx);
38581
38582 return_host_buffers:
38583 ++pdus_assembled;
38584@@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
38585 tpd->vcc->pop(tpd->vcc, tpd->skb);
38586 else
38587 dev_kfree_skb_any(tpd->skb);
38588- atomic_inc(&tpd->vcc->stats->tx_err);
38589+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
38590 }
38591 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
38592 return;
38593@@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38594 vcc->pop(vcc, skb);
38595 else
38596 dev_kfree_skb_any(skb);
38597- atomic_inc(&vcc->stats->tx_err);
38598+ atomic_inc_unchecked(&vcc->stats->tx_err);
38599 return -EINVAL;
38600 }
38601
38602@@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38603 vcc->pop(vcc, skb);
38604 else
38605 dev_kfree_skb_any(skb);
38606- atomic_inc(&vcc->stats->tx_err);
38607+ atomic_inc_unchecked(&vcc->stats->tx_err);
38608 return -EINVAL;
38609 }
38610 #endif
38611@@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38612 vcc->pop(vcc, skb);
38613 else
38614 dev_kfree_skb_any(skb);
38615- atomic_inc(&vcc->stats->tx_err);
38616+ atomic_inc_unchecked(&vcc->stats->tx_err);
38617 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38618 return -ENOMEM;
38619 }
38620@@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38621 vcc->pop(vcc, skb);
38622 else
38623 dev_kfree_skb_any(skb);
38624- atomic_inc(&vcc->stats->tx_err);
38625+ atomic_inc_unchecked(&vcc->stats->tx_err);
38626 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38627 return -ENOMEM;
38628 }
38629@@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38630 __enqueue_tpd(he_dev, tpd, cid);
38631 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38632
38633- atomic_inc(&vcc->stats->tx);
38634+ atomic_inc_unchecked(&vcc->stats->tx);
38635
38636 return 0;
38637 }
38638diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
38639index 1dc0519..1aadaf7 100644
38640--- a/drivers/atm/horizon.c
38641+++ b/drivers/atm/horizon.c
38642@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
38643 {
38644 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
38645 // VC layer stats
38646- atomic_inc(&vcc->stats->rx);
38647+ atomic_inc_unchecked(&vcc->stats->rx);
38648 __net_timestamp(skb);
38649 // end of our responsibility
38650 vcc->push (vcc, skb);
38651@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
38652 dev->tx_iovec = NULL;
38653
38654 // VC layer stats
38655- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38656+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38657
38658 // free the skb
38659 hrz_kfree_skb (skb);
38660diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
38661index b621f56..1e3a799 100644
38662--- a/drivers/atm/idt77252.c
38663+++ b/drivers/atm/idt77252.c
38664@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
38665 else
38666 dev_kfree_skb(skb);
38667
38668- atomic_inc(&vcc->stats->tx);
38669+ atomic_inc_unchecked(&vcc->stats->tx);
38670 }
38671
38672 atomic_dec(&scq->used);
38673@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38674 if ((sb = dev_alloc_skb(64)) == NULL) {
38675 printk("%s: Can't allocate buffers for aal0.\n",
38676 card->name);
38677- atomic_add(i, &vcc->stats->rx_drop);
38678+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
38679 break;
38680 }
38681 if (!atm_charge(vcc, sb->truesize)) {
38682 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
38683 card->name);
38684- atomic_add(i - 1, &vcc->stats->rx_drop);
38685+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
38686 dev_kfree_skb(sb);
38687 break;
38688 }
38689@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38690 ATM_SKB(sb)->vcc = vcc;
38691 __net_timestamp(sb);
38692 vcc->push(vcc, sb);
38693- atomic_inc(&vcc->stats->rx);
38694+ atomic_inc_unchecked(&vcc->stats->rx);
38695
38696 cell += ATM_CELL_PAYLOAD;
38697 }
38698@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38699 "(CDC: %08x)\n",
38700 card->name, len, rpp->len, readl(SAR_REG_CDC));
38701 recycle_rx_pool_skb(card, rpp);
38702- atomic_inc(&vcc->stats->rx_err);
38703+ atomic_inc_unchecked(&vcc->stats->rx_err);
38704 return;
38705 }
38706 if (stat & SAR_RSQE_CRC) {
38707 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
38708 recycle_rx_pool_skb(card, rpp);
38709- atomic_inc(&vcc->stats->rx_err);
38710+ atomic_inc_unchecked(&vcc->stats->rx_err);
38711 return;
38712 }
38713 if (skb_queue_len(&rpp->queue) > 1) {
38714@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38715 RXPRINTK("%s: Can't alloc RX skb.\n",
38716 card->name);
38717 recycle_rx_pool_skb(card, rpp);
38718- atomic_inc(&vcc->stats->rx_err);
38719+ atomic_inc_unchecked(&vcc->stats->rx_err);
38720 return;
38721 }
38722 if (!atm_charge(vcc, skb->truesize)) {
38723@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38724 __net_timestamp(skb);
38725
38726 vcc->push(vcc, skb);
38727- atomic_inc(&vcc->stats->rx);
38728+ atomic_inc_unchecked(&vcc->stats->rx);
38729
38730 return;
38731 }
38732@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38733 __net_timestamp(skb);
38734
38735 vcc->push(vcc, skb);
38736- atomic_inc(&vcc->stats->rx);
38737+ atomic_inc_unchecked(&vcc->stats->rx);
38738
38739 if (skb->truesize > SAR_FB_SIZE_3)
38740 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
38741@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
38742 if (vcc->qos.aal != ATM_AAL0) {
38743 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
38744 card->name, vpi, vci);
38745- atomic_inc(&vcc->stats->rx_drop);
38746+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38747 goto drop;
38748 }
38749
38750 if ((sb = dev_alloc_skb(64)) == NULL) {
38751 printk("%s: Can't allocate buffers for AAL0.\n",
38752 card->name);
38753- atomic_inc(&vcc->stats->rx_err);
38754+ atomic_inc_unchecked(&vcc->stats->rx_err);
38755 goto drop;
38756 }
38757
38758@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
38759 ATM_SKB(sb)->vcc = vcc;
38760 __net_timestamp(sb);
38761 vcc->push(vcc, sb);
38762- atomic_inc(&vcc->stats->rx);
38763+ atomic_inc_unchecked(&vcc->stats->rx);
38764
38765 drop:
38766 skb_pull(queue, 64);
38767@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38768
38769 if (vc == NULL) {
38770 printk("%s: NULL connection in send().\n", card->name);
38771- atomic_inc(&vcc->stats->tx_err);
38772+ atomic_inc_unchecked(&vcc->stats->tx_err);
38773 dev_kfree_skb(skb);
38774 return -EINVAL;
38775 }
38776 if (!test_bit(VCF_TX, &vc->flags)) {
38777 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
38778- atomic_inc(&vcc->stats->tx_err);
38779+ atomic_inc_unchecked(&vcc->stats->tx_err);
38780 dev_kfree_skb(skb);
38781 return -EINVAL;
38782 }
38783@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38784 break;
38785 default:
38786 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
38787- atomic_inc(&vcc->stats->tx_err);
38788+ atomic_inc_unchecked(&vcc->stats->tx_err);
38789 dev_kfree_skb(skb);
38790 return -EINVAL;
38791 }
38792
38793 if (skb_shinfo(skb)->nr_frags != 0) {
38794 printk("%s: No scatter-gather yet.\n", card->name);
38795- atomic_inc(&vcc->stats->tx_err);
38796+ atomic_inc_unchecked(&vcc->stats->tx_err);
38797 dev_kfree_skb(skb);
38798 return -EINVAL;
38799 }
38800@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38801
38802 err = queue_skb(card, vc, skb, oam);
38803 if (err) {
38804- atomic_inc(&vcc->stats->tx_err);
38805+ atomic_inc_unchecked(&vcc->stats->tx_err);
38806 dev_kfree_skb(skb);
38807 return err;
38808 }
38809@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
38810 skb = dev_alloc_skb(64);
38811 if (!skb) {
38812 printk("%s: Out of memory in send_oam().\n", card->name);
38813- atomic_inc(&vcc->stats->tx_err);
38814+ atomic_inc_unchecked(&vcc->stats->tx_err);
38815 return -ENOMEM;
38816 }
38817 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
38818diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
38819index 4217f29..88f547a 100644
38820--- a/drivers/atm/iphase.c
38821+++ b/drivers/atm/iphase.c
38822@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
38823 status = (u_short) (buf_desc_ptr->desc_mode);
38824 if (status & (RX_CER | RX_PTE | RX_OFL))
38825 {
38826- atomic_inc(&vcc->stats->rx_err);
38827+ atomic_inc_unchecked(&vcc->stats->rx_err);
38828 IF_ERR(printk("IA: bad packet, dropping it");)
38829 if (status & RX_CER) {
38830 IF_ERR(printk(" cause: packet CRC error\n");)
38831@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
38832 len = dma_addr - buf_addr;
38833 if (len > iadev->rx_buf_sz) {
38834 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
38835- atomic_inc(&vcc->stats->rx_err);
38836+ atomic_inc_unchecked(&vcc->stats->rx_err);
38837 goto out_free_desc;
38838 }
38839
38840@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38841 ia_vcc = INPH_IA_VCC(vcc);
38842 if (ia_vcc == NULL)
38843 {
38844- atomic_inc(&vcc->stats->rx_err);
38845+ atomic_inc_unchecked(&vcc->stats->rx_err);
38846 atm_return(vcc, skb->truesize);
38847 dev_kfree_skb_any(skb);
38848 goto INCR_DLE;
38849@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38850 if ((length > iadev->rx_buf_sz) || (length >
38851 (skb->len - sizeof(struct cpcs_trailer))))
38852 {
38853- atomic_inc(&vcc->stats->rx_err);
38854+ atomic_inc_unchecked(&vcc->stats->rx_err);
38855 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
38856 length, skb->len);)
38857 atm_return(vcc, skb->truesize);
38858@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38859
38860 IF_RX(printk("rx_dle_intr: skb push");)
38861 vcc->push(vcc,skb);
38862- atomic_inc(&vcc->stats->rx);
38863+ atomic_inc_unchecked(&vcc->stats->rx);
38864 iadev->rx_pkt_cnt++;
38865 }
38866 INCR_DLE:
38867@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
38868 {
38869 struct k_sonet_stats *stats;
38870 stats = &PRIV(_ia_dev[board])->sonet_stats;
38871- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
38872- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
38873- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
38874- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
38875- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
38876- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
38877- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
38878- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
38879- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
38880+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
38881+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
38882+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
38883+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
38884+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
38885+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
38886+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
38887+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
38888+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
38889 }
38890 ia_cmds.status = 0;
38891 break;
38892@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38893 if ((desc == 0) || (desc > iadev->num_tx_desc))
38894 {
38895 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
38896- atomic_inc(&vcc->stats->tx);
38897+ atomic_inc_unchecked(&vcc->stats->tx);
38898 if (vcc->pop)
38899 vcc->pop(vcc, skb);
38900 else
38901@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38902 ATM_DESC(skb) = vcc->vci;
38903 skb_queue_tail(&iadev->tx_dma_q, skb);
38904
38905- atomic_inc(&vcc->stats->tx);
38906+ atomic_inc_unchecked(&vcc->stats->tx);
38907 iadev->tx_pkt_cnt++;
38908 /* Increment transaction counter */
38909 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
38910
38911 #if 0
38912 /* add flow control logic */
38913- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
38914+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
38915 if (iavcc->vc_desc_cnt > 10) {
38916 vcc->tx_quota = vcc->tx_quota * 3 / 4;
38917 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
38918diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
38919index fa7d7019..1e404c7 100644
38920--- a/drivers/atm/lanai.c
38921+++ b/drivers/atm/lanai.c
38922@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
38923 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
38924 lanai_endtx(lanai, lvcc);
38925 lanai_free_skb(lvcc->tx.atmvcc, skb);
38926- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
38927+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
38928 }
38929
38930 /* Try to fill the buffer - don't call unless there is backlog */
38931@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
38932 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
38933 __net_timestamp(skb);
38934 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
38935- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
38936+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
38937 out:
38938 lvcc->rx.buf.ptr = end;
38939 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
38940@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38941 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
38942 "vcc %d\n", lanai->number, (unsigned int) s, vci);
38943 lanai->stats.service_rxnotaal5++;
38944- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38945+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38946 return 0;
38947 }
38948 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
38949@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38950 int bytes;
38951 read_unlock(&vcc_sklist_lock);
38952 DPRINTK("got trashed rx pdu on vci %d\n", vci);
38953- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38954+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38955 lvcc->stats.x.aal5.service_trash++;
38956 bytes = (SERVICE_GET_END(s) * 16) -
38957 (((unsigned long) lvcc->rx.buf.ptr) -
38958@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38959 }
38960 if (s & SERVICE_STREAM) {
38961 read_unlock(&vcc_sklist_lock);
38962- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38963+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38964 lvcc->stats.x.aal5.service_stream++;
38965 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
38966 "PDU on VCI %d!\n", lanai->number, vci);
38967@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38968 return 0;
38969 }
38970 DPRINTK("got rx crc error on vci %d\n", vci);
38971- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38972+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38973 lvcc->stats.x.aal5.service_rxcrc++;
38974 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
38975 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
38976diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
38977index 9988ac9..7c52585 100644
38978--- a/drivers/atm/nicstar.c
38979+++ b/drivers/atm/nicstar.c
38980@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38981 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
38982 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
38983 card->index);
38984- atomic_inc(&vcc->stats->tx_err);
38985+ atomic_inc_unchecked(&vcc->stats->tx_err);
38986 dev_kfree_skb_any(skb);
38987 return -EINVAL;
38988 }
38989@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38990 if (!vc->tx) {
38991 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
38992 card->index);
38993- atomic_inc(&vcc->stats->tx_err);
38994+ atomic_inc_unchecked(&vcc->stats->tx_err);
38995 dev_kfree_skb_any(skb);
38996 return -EINVAL;
38997 }
38998@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38999 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
39000 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
39001 card->index);
39002- atomic_inc(&vcc->stats->tx_err);
39003+ atomic_inc_unchecked(&vcc->stats->tx_err);
39004 dev_kfree_skb_any(skb);
39005 return -EINVAL;
39006 }
39007
39008 if (skb_shinfo(skb)->nr_frags != 0) {
39009 printk("nicstar%d: No scatter-gather yet.\n", card->index);
39010- atomic_inc(&vcc->stats->tx_err);
39011+ atomic_inc_unchecked(&vcc->stats->tx_err);
39012 dev_kfree_skb_any(skb);
39013 return -EINVAL;
39014 }
39015@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
39016 }
39017
39018 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
39019- atomic_inc(&vcc->stats->tx_err);
39020+ atomic_inc_unchecked(&vcc->stats->tx_err);
39021 dev_kfree_skb_any(skb);
39022 return -EIO;
39023 }
39024- atomic_inc(&vcc->stats->tx);
39025+ atomic_inc_unchecked(&vcc->stats->tx);
39026
39027 return 0;
39028 }
39029@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39030 printk
39031 ("nicstar%d: Can't allocate buffers for aal0.\n",
39032 card->index);
39033- atomic_add(i, &vcc->stats->rx_drop);
39034+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
39035 break;
39036 }
39037 if (!atm_charge(vcc, sb->truesize)) {
39038 RXPRINTK
39039 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
39040 card->index);
39041- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
39042+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
39043 dev_kfree_skb_any(sb);
39044 break;
39045 }
39046@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39047 ATM_SKB(sb)->vcc = vcc;
39048 __net_timestamp(sb);
39049 vcc->push(vcc, sb);
39050- atomic_inc(&vcc->stats->rx);
39051+ atomic_inc_unchecked(&vcc->stats->rx);
39052 cell += ATM_CELL_PAYLOAD;
39053 }
39054
39055@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39056 if (iovb == NULL) {
39057 printk("nicstar%d: Out of iovec buffers.\n",
39058 card->index);
39059- atomic_inc(&vcc->stats->rx_drop);
39060+ atomic_inc_unchecked(&vcc->stats->rx_drop);
39061 recycle_rx_buf(card, skb);
39062 return;
39063 }
39064@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39065 small or large buffer itself. */
39066 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
39067 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
39068- atomic_inc(&vcc->stats->rx_err);
39069+ atomic_inc_unchecked(&vcc->stats->rx_err);
39070 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
39071 NS_MAX_IOVECS);
39072 NS_PRV_IOVCNT(iovb) = 0;
39073@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39074 ("nicstar%d: Expected a small buffer, and this is not one.\n",
39075 card->index);
39076 which_list(card, skb);
39077- atomic_inc(&vcc->stats->rx_err);
39078+ atomic_inc_unchecked(&vcc->stats->rx_err);
39079 recycle_rx_buf(card, skb);
39080 vc->rx_iov = NULL;
39081 recycle_iov_buf(card, iovb);
39082@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39083 ("nicstar%d: Expected a large buffer, and this is not one.\n",
39084 card->index);
39085 which_list(card, skb);
39086- atomic_inc(&vcc->stats->rx_err);
39087+ atomic_inc_unchecked(&vcc->stats->rx_err);
39088 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
39089 NS_PRV_IOVCNT(iovb));
39090 vc->rx_iov = NULL;
39091@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39092 printk(" - PDU size mismatch.\n");
39093 else
39094 printk(".\n");
39095- atomic_inc(&vcc->stats->rx_err);
39096+ atomic_inc_unchecked(&vcc->stats->rx_err);
39097 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
39098 NS_PRV_IOVCNT(iovb));
39099 vc->rx_iov = NULL;
39100@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39101 /* skb points to a small buffer */
39102 if (!atm_charge(vcc, skb->truesize)) {
39103 push_rxbufs(card, skb);
39104- atomic_inc(&vcc->stats->rx_drop);
39105+ atomic_inc_unchecked(&vcc->stats->rx_drop);
39106 } else {
39107 skb_put(skb, len);
39108 dequeue_sm_buf(card, skb);
39109@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39110 ATM_SKB(skb)->vcc = vcc;
39111 __net_timestamp(skb);
39112 vcc->push(vcc, skb);
39113- atomic_inc(&vcc->stats->rx);
39114+ atomic_inc_unchecked(&vcc->stats->rx);
39115 }
39116 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
39117 struct sk_buff *sb;
39118@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39119 if (len <= NS_SMBUFSIZE) {
39120 if (!atm_charge(vcc, sb->truesize)) {
39121 push_rxbufs(card, sb);
39122- atomic_inc(&vcc->stats->rx_drop);
39123+ atomic_inc_unchecked(&vcc->stats->rx_drop);
39124 } else {
39125 skb_put(sb, len);
39126 dequeue_sm_buf(card, sb);
39127@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39128 ATM_SKB(sb)->vcc = vcc;
39129 __net_timestamp(sb);
39130 vcc->push(vcc, sb);
39131- atomic_inc(&vcc->stats->rx);
39132+ atomic_inc_unchecked(&vcc->stats->rx);
39133 }
39134
39135 push_rxbufs(card, skb);
39136@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39137
39138 if (!atm_charge(vcc, skb->truesize)) {
39139 push_rxbufs(card, skb);
39140- atomic_inc(&vcc->stats->rx_drop);
39141+ atomic_inc_unchecked(&vcc->stats->rx_drop);
39142 } else {
39143 dequeue_lg_buf(card, skb);
39144 #ifdef NS_USE_DESTRUCTORS
39145@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39146 ATM_SKB(skb)->vcc = vcc;
39147 __net_timestamp(skb);
39148 vcc->push(vcc, skb);
39149- atomic_inc(&vcc->stats->rx);
39150+ atomic_inc_unchecked(&vcc->stats->rx);
39151 }
39152
39153 push_rxbufs(card, sb);
39154@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39155 printk
39156 ("nicstar%d: Out of huge buffers.\n",
39157 card->index);
39158- atomic_inc(&vcc->stats->rx_drop);
39159+ atomic_inc_unchecked(&vcc->stats->rx_drop);
39160 recycle_iovec_rx_bufs(card,
39161 (struct iovec *)
39162 iovb->data,
39163@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39164 card->hbpool.count++;
39165 } else
39166 dev_kfree_skb_any(hb);
39167- atomic_inc(&vcc->stats->rx_drop);
39168+ atomic_inc_unchecked(&vcc->stats->rx_drop);
39169 } else {
39170 /* Copy the small buffer to the huge buffer */
39171 sb = (struct sk_buff *)iov->iov_base;
39172@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39173 #endif /* NS_USE_DESTRUCTORS */
39174 __net_timestamp(hb);
39175 vcc->push(vcc, hb);
39176- atomic_inc(&vcc->stats->rx);
39177+ atomic_inc_unchecked(&vcc->stats->rx);
39178 }
39179 }
39180
39181diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
39182index 943cf0d..37d15d5 100644
39183--- a/drivers/atm/solos-pci.c
39184+++ b/drivers/atm/solos-pci.c
39185@@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
39186 }
39187 atm_charge(vcc, skb->truesize);
39188 vcc->push(vcc, skb);
39189- atomic_inc(&vcc->stats->rx);
39190+ atomic_inc_unchecked(&vcc->stats->rx);
39191 break;
39192
39193 case PKT_STATUS:
39194@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
39195 vcc = SKB_CB(oldskb)->vcc;
39196
39197 if (vcc) {
39198- atomic_inc(&vcc->stats->tx);
39199+ atomic_inc_unchecked(&vcc->stats->tx);
39200 solos_pop(vcc, oldskb);
39201 } else {
39202 dev_kfree_skb_irq(oldskb);
39203diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
39204index 0215934..ce9f5b1 100644
39205--- a/drivers/atm/suni.c
39206+++ b/drivers/atm/suni.c
39207@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
39208
39209
39210 #define ADD_LIMITED(s,v) \
39211- atomic_add((v),&stats->s); \
39212- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
39213+ atomic_add_unchecked((v),&stats->s); \
39214+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
39215
39216
39217 static void suni_hz(unsigned long from_timer)
39218diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
39219index 5120a96..e2572bd 100644
39220--- a/drivers/atm/uPD98402.c
39221+++ b/drivers/atm/uPD98402.c
39222@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
39223 struct sonet_stats tmp;
39224 int error = 0;
39225
39226- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
39227+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
39228 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
39229 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
39230 if (zero && !error) {
39231@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
39232
39233
39234 #define ADD_LIMITED(s,v) \
39235- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
39236- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
39237- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
39238+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
39239+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
39240+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
39241
39242
39243 static void stat_event(struct atm_dev *dev)
39244@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
39245 if (reason & uPD98402_INT_PFM) stat_event(dev);
39246 if (reason & uPD98402_INT_PCO) {
39247 (void) GET(PCOCR); /* clear interrupt cause */
39248- atomic_add(GET(HECCT),
39249+ atomic_add_unchecked(GET(HECCT),
39250 &PRIV(dev)->sonet_stats.uncorr_hcs);
39251 }
39252 if ((reason & uPD98402_INT_RFO) &&
39253@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
39254 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
39255 uPD98402_INT_LOS),PIMR); /* enable them */
39256 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
39257- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
39258- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
39259- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
39260+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
39261+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
39262+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
39263 return 0;
39264 }
39265
39266diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
39267index 969c3c2..9b72956 100644
39268--- a/drivers/atm/zatm.c
39269+++ b/drivers/atm/zatm.c
39270@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
39271 }
39272 if (!size) {
39273 dev_kfree_skb_irq(skb);
39274- if (vcc) atomic_inc(&vcc->stats->rx_err);
39275+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
39276 continue;
39277 }
39278 if (!atm_charge(vcc,skb->truesize)) {
39279@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
39280 skb->len = size;
39281 ATM_SKB(skb)->vcc = vcc;
39282 vcc->push(vcc,skb);
39283- atomic_inc(&vcc->stats->rx);
39284+ atomic_inc_unchecked(&vcc->stats->rx);
39285 }
39286 zout(pos & 0xffff,MTA(mbx));
39287 #if 0 /* probably a stupid idea */
39288@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
39289 skb_queue_head(&zatm_vcc->backlog,skb);
39290 break;
39291 }
39292- atomic_inc(&vcc->stats->tx);
39293+ atomic_inc_unchecked(&vcc->stats->tx);
39294 wake_up(&zatm_vcc->tx_wait);
39295 }
39296
39297diff --git a/drivers/base/bus.c b/drivers/base/bus.c
39298index 83e910a..b224a73 100644
39299--- a/drivers/base/bus.c
39300+++ b/drivers/base/bus.c
39301@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
39302 return -EINVAL;
39303
39304 mutex_lock(&subsys->p->mutex);
39305- list_add_tail(&sif->node, &subsys->p->interfaces);
39306+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
39307 if (sif->add_dev) {
39308 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
39309 while ((dev = subsys_dev_iter_next(&iter)))
39310@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
39311 subsys = sif->subsys;
39312
39313 mutex_lock(&subsys->p->mutex);
39314- list_del_init(&sif->node);
39315+ pax_list_del_init((struct list_head *)&sif->node);
39316 if (sif->remove_dev) {
39317 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
39318 while ((dev = subsys_dev_iter_next(&iter)))
39319diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
39320index 25798db..15f130e 100644
39321--- a/drivers/base/devtmpfs.c
39322+++ b/drivers/base/devtmpfs.c
39323@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
39324 if (!thread)
39325 return 0;
39326
39327- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
39328+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
39329 if (err)
39330 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
39331 else
39332@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
39333 *err = sys_unshare(CLONE_NEWNS);
39334 if (*err)
39335 goto out;
39336- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
39337+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
39338 if (*err)
39339 goto out;
39340- sys_chdir("/.."); /* will traverse into overmounted root */
39341- sys_chroot(".");
39342+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
39343+ sys_chroot((char __force_user *)".");
39344 complete(&setup_done);
39345 while (1) {
39346 spin_lock(&req_lock);
39347diff --git a/drivers/base/node.c b/drivers/base/node.c
39348index 8f7ed99..700dd0c 100644
39349--- a/drivers/base/node.c
39350+++ b/drivers/base/node.c
39351@@ -624,7 +624,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
39352 struct node_attr {
39353 struct device_attribute attr;
39354 enum node_states state;
39355-};
39356+} __do_const;
39357
39358 static ssize_t show_node_state(struct device *dev,
39359 struct device_attribute *attr, char *buf)
39360diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
39361index eee55c1..b8c9393 100644
39362--- a/drivers/base/power/domain.c
39363+++ b/drivers/base/power/domain.c
39364@@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
39365
39366 if (dev->power.subsys_data->domain_data) {
39367 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
39368- gpd_data->ops = (struct gpd_dev_ops){ NULL };
39369+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
39370 if (clear_td)
39371- gpd_data->td = (struct gpd_timing_data){ 0 };
39372+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
39373
39374 if (--gpd_data->refcount == 0) {
39375 dev->power.subsys_data->domain_data = NULL;
39376@@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
39377 {
39378 struct cpuidle_driver *cpuidle_drv;
39379 struct gpd_cpu_data *cpu_data;
39380- struct cpuidle_state *idle_state;
39381+ cpuidle_state_no_const *idle_state;
39382 int ret = 0;
39383
39384 if (IS_ERR_OR_NULL(genpd) || state < 0)
39385@@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
39386 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
39387 {
39388 struct gpd_cpu_data *cpu_data;
39389- struct cpuidle_state *idle_state;
39390+ cpuidle_state_no_const *idle_state;
39391 int ret = 0;
39392
39393 if (IS_ERR_OR_NULL(genpd))
39394diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
39395index 95b181d1..c4f0e19 100644
39396--- a/drivers/base/power/sysfs.c
39397+++ b/drivers/base/power/sysfs.c
39398@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
39399 return -EIO;
39400 }
39401 }
39402- return sprintf(buf, p);
39403+ return sprintf(buf, "%s", p);
39404 }
39405
39406 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
39407diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
39408index eb1bd2e..2667d3a 100644
39409--- a/drivers/base/power/wakeup.c
39410+++ b/drivers/base/power/wakeup.c
39411@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
39412 * They need to be modified together atomically, so it's better to use one
39413 * atomic variable to hold them both.
39414 */
39415-static atomic_t combined_event_count = ATOMIC_INIT(0);
39416+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
39417
39418 #define IN_PROGRESS_BITS (sizeof(int) * 4)
39419 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
39420
39421 static void split_counters(unsigned int *cnt, unsigned int *inpr)
39422 {
39423- unsigned int comb = atomic_read(&combined_event_count);
39424+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
39425
39426 *cnt = (comb >> IN_PROGRESS_BITS);
39427 *inpr = comb & MAX_IN_PROGRESS;
39428@@ -401,7 +401,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
39429 ws->start_prevent_time = ws->last_time;
39430
39431 /* Increment the counter of events in progress. */
39432- cec = atomic_inc_return(&combined_event_count);
39433+ cec = atomic_inc_return_unchecked(&combined_event_count);
39434
39435 trace_wakeup_source_activate(ws->name, cec);
39436 }
39437@@ -527,7 +527,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
39438 * Increment the counter of registered wakeup events and decrement the
39439 * couter of wakeup events in progress simultaneously.
39440 */
39441- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
39442+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
39443 trace_wakeup_source_deactivate(ws->name, cec);
39444
39445 split_counters(&cnt, &inpr);
39446diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
39447index dbb8350..4762f4c 100644
39448--- a/drivers/base/syscore.c
39449+++ b/drivers/base/syscore.c
39450@@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
39451 void register_syscore_ops(struct syscore_ops *ops)
39452 {
39453 mutex_lock(&syscore_ops_lock);
39454- list_add_tail(&ops->node, &syscore_ops_list);
39455+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
39456 mutex_unlock(&syscore_ops_lock);
39457 }
39458 EXPORT_SYMBOL_GPL(register_syscore_ops);
39459@@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
39460 void unregister_syscore_ops(struct syscore_ops *ops)
39461 {
39462 mutex_lock(&syscore_ops_lock);
39463- list_del(&ops->node);
39464+ pax_list_del((struct list_head *)&ops->node);
39465 mutex_unlock(&syscore_ops_lock);
39466 }
39467 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
39468diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
39469index 4595c22..d4f6c54 100644
39470--- a/drivers/block/cciss.c
39471+++ b/drivers/block/cciss.c
39472@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
39473 while (!list_empty(&h->reqQ)) {
39474 c = list_entry(h->reqQ.next, CommandList_struct, list);
39475 /* can't do anything if fifo is full */
39476- if ((h->access.fifo_full(h))) {
39477+ if ((h->access->fifo_full(h))) {
39478 dev_warn(&h->pdev->dev, "fifo full\n");
39479 break;
39480 }
39481@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
39482 h->Qdepth--;
39483
39484 /* Tell the controller execute command */
39485- h->access.submit_command(h, c);
39486+ h->access->submit_command(h, c);
39487
39488 /* Put job onto the completed Q */
39489 addQ(&h->cmpQ, c);
39490@@ -3447,17 +3447,17 @@ startio:
39491
39492 static inline unsigned long get_next_completion(ctlr_info_t *h)
39493 {
39494- return h->access.command_completed(h);
39495+ return h->access->command_completed(h);
39496 }
39497
39498 static inline int interrupt_pending(ctlr_info_t *h)
39499 {
39500- return h->access.intr_pending(h);
39501+ return h->access->intr_pending(h);
39502 }
39503
39504 static inline long interrupt_not_for_us(ctlr_info_t *h)
39505 {
39506- return ((h->access.intr_pending(h) == 0) ||
39507+ return ((h->access->intr_pending(h) == 0) ||
39508 (h->interrupts_enabled == 0));
39509 }
39510
39511@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
39512 u32 a;
39513
39514 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
39515- return h->access.command_completed(h);
39516+ return h->access->command_completed(h);
39517
39518 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
39519 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
39520@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
39521 trans_support & CFGTBL_Trans_use_short_tags);
39522
39523 /* Change the access methods to the performant access methods */
39524- h->access = SA5_performant_access;
39525+ h->access = &SA5_performant_access;
39526 h->transMethod = CFGTBL_Trans_Performant;
39527
39528 return;
39529@@ -4321,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
39530 if (prod_index < 0)
39531 return -ENODEV;
39532 h->product_name = products[prod_index].product_name;
39533- h->access = *(products[prod_index].access);
39534+ h->access = products[prod_index].access;
39535
39536 if (cciss_board_disabled(h)) {
39537 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
39538@@ -5053,7 +5053,7 @@ reinit_after_soft_reset:
39539 }
39540
39541 /* make sure the board interrupts are off */
39542- h->access.set_intr_mask(h, CCISS_INTR_OFF);
39543+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
39544 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
39545 if (rc)
39546 goto clean2;
39547@@ -5103,7 +5103,7 @@ reinit_after_soft_reset:
39548 * fake ones to scoop up any residual completions.
39549 */
39550 spin_lock_irqsave(&h->lock, flags);
39551- h->access.set_intr_mask(h, CCISS_INTR_OFF);
39552+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
39553 spin_unlock_irqrestore(&h->lock, flags);
39554 free_irq(h->intr[h->intr_mode], h);
39555 rc = cciss_request_irq(h, cciss_msix_discard_completions,
39556@@ -5123,9 +5123,9 @@ reinit_after_soft_reset:
39557 dev_info(&h->pdev->dev, "Board READY.\n");
39558 dev_info(&h->pdev->dev,
39559 "Waiting for stale completions to drain.\n");
39560- h->access.set_intr_mask(h, CCISS_INTR_ON);
39561+ h->access->set_intr_mask(h, CCISS_INTR_ON);
39562 msleep(10000);
39563- h->access.set_intr_mask(h, CCISS_INTR_OFF);
39564+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
39565
39566 rc = controller_reset_failed(h->cfgtable);
39567 if (rc)
39568@@ -5148,7 +5148,7 @@ reinit_after_soft_reset:
39569 cciss_scsi_setup(h);
39570
39571 /* Turn the interrupts on so we can service requests */
39572- h->access.set_intr_mask(h, CCISS_INTR_ON);
39573+ h->access->set_intr_mask(h, CCISS_INTR_ON);
39574
39575 /* Get the firmware version */
39576 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
39577@@ -5220,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
39578 kfree(flush_buf);
39579 if (return_code != IO_OK)
39580 dev_warn(&h->pdev->dev, "Error flushing cache\n");
39581- h->access.set_intr_mask(h, CCISS_INTR_OFF);
39582+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
39583 free_irq(h->intr[h->intr_mode], h);
39584 }
39585
39586diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
39587index 7fda30e..2f27946 100644
39588--- a/drivers/block/cciss.h
39589+++ b/drivers/block/cciss.h
39590@@ -101,7 +101,7 @@ struct ctlr_info
39591 /* information about each logical volume */
39592 drive_info_struct *drv[CISS_MAX_LUN];
39593
39594- struct access_method access;
39595+ struct access_method *access;
39596
39597 /* queue and queue Info */
39598 struct list_head reqQ;
39599@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
39600 }
39601
39602 static struct access_method SA5_access = {
39603- SA5_submit_command,
39604- SA5_intr_mask,
39605- SA5_fifo_full,
39606- SA5_intr_pending,
39607- SA5_completed,
39608+ .submit_command = SA5_submit_command,
39609+ .set_intr_mask = SA5_intr_mask,
39610+ .fifo_full = SA5_fifo_full,
39611+ .intr_pending = SA5_intr_pending,
39612+ .command_completed = SA5_completed,
39613 };
39614
39615 static struct access_method SA5B_access = {
39616- SA5_submit_command,
39617- SA5B_intr_mask,
39618- SA5_fifo_full,
39619- SA5B_intr_pending,
39620- SA5_completed,
39621+ .submit_command = SA5_submit_command,
39622+ .set_intr_mask = SA5B_intr_mask,
39623+ .fifo_full = SA5_fifo_full,
39624+ .intr_pending = SA5B_intr_pending,
39625+ .command_completed = SA5_completed,
39626 };
39627
39628 static struct access_method SA5_performant_access = {
39629- SA5_submit_command,
39630- SA5_performant_intr_mask,
39631- SA5_fifo_full,
39632- SA5_performant_intr_pending,
39633- SA5_performant_completed,
39634+ .submit_command = SA5_submit_command,
39635+ .set_intr_mask = SA5_performant_intr_mask,
39636+ .fifo_full = SA5_fifo_full,
39637+ .intr_pending = SA5_performant_intr_pending,
39638+ .command_completed = SA5_performant_completed,
39639 };
39640
39641 struct board_type {
39642diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
39643index 2b94403..fd6ad1f 100644
39644--- a/drivers/block/cpqarray.c
39645+++ b/drivers/block/cpqarray.c
39646@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
39647 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
39648 goto Enomem4;
39649 }
39650- hba[i]->access.set_intr_mask(hba[i], 0);
39651+ hba[i]->access->set_intr_mask(hba[i], 0);
39652 if (request_irq(hba[i]->intr, do_ida_intr,
39653 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
39654 {
39655@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
39656 add_timer(&hba[i]->timer);
39657
39658 /* Enable IRQ now that spinlock and rate limit timer are set up */
39659- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
39660+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
39661
39662 for(j=0; j<NWD; j++) {
39663 struct gendisk *disk = ida_gendisk[i][j];
39664@@ -694,7 +694,7 @@ DBGINFO(
39665 for(i=0; i<NR_PRODUCTS; i++) {
39666 if (board_id == products[i].board_id) {
39667 c->product_name = products[i].product_name;
39668- c->access = *(products[i].access);
39669+ c->access = products[i].access;
39670 break;
39671 }
39672 }
39673@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
39674 hba[ctlr]->intr = intr;
39675 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
39676 hba[ctlr]->product_name = products[j].product_name;
39677- hba[ctlr]->access = *(products[j].access);
39678+ hba[ctlr]->access = products[j].access;
39679 hba[ctlr]->ctlr = ctlr;
39680 hba[ctlr]->board_id = board_id;
39681 hba[ctlr]->pci_dev = NULL; /* not PCI */
39682@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
39683
39684 while((c = h->reqQ) != NULL) {
39685 /* Can't do anything if we're busy */
39686- if (h->access.fifo_full(h) == 0)
39687+ if (h->access->fifo_full(h) == 0)
39688 return;
39689
39690 /* Get the first entry from the request Q */
39691@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
39692 h->Qdepth--;
39693
39694 /* Tell the controller to do our bidding */
39695- h->access.submit_command(h, c);
39696+ h->access->submit_command(h, c);
39697
39698 /* Get onto the completion Q */
39699 addQ(&h->cmpQ, c);
39700@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
39701 unsigned long flags;
39702 __u32 a,a1;
39703
39704- istat = h->access.intr_pending(h);
39705+ istat = h->access->intr_pending(h);
39706 /* Is this interrupt for us? */
39707 if (istat == 0)
39708 return IRQ_NONE;
39709@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
39710 */
39711 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
39712 if (istat & FIFO_NOT_EMPTY) {
39713- while((a = h->access.command_completed(h))) {
39714+ while((a = h->access->command_completed(h))) {
39715 a1 = a; a &= ~3;
39716 if ((c = h->cmpQ) == NULL)
39717 {
39718@@ -1448,11 +1448,11 @@ static int sendcmd(
39719 /*
39720 * Disable interrupt
39721 */
39722- info_p->access.set_intr_mask(info_p, 0);
39723+ info_p->access->set_intr_mask(info_p, 0);
39724 /* Make sure there is room in the command FIFO */
39725 /* Actually it should be completely empty at this time. */
39726 for (i = 200000; i > 0; i--) {
39727- temp = info_p->access.fifo_full(info_p);
39728+ temp = info_p->access->fifo_full(info_p);
39729 if (temp != 0) {
39730 break;
39731 }
39732@@ -1465,7 +1465,7 @@ DBG(
39733 /*
39734 * Send the cmd
39735 */
39736- info_p->access.submit_command(info_p, c);
39737+ info_p->access->submit_command(info_p, c);
39738 complete = pollcomplete(ctlr);
39739
39740 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
39741@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
39742 * we check the new geometry. Then turn interrupts back on when
39743 * we're done.
39744 */
39745- host->access.set_intr_mask(host, 0);
39746+ host->access->set_intr_mask(host, 0);
39747 getgeometry(ctlr);
39748- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
39749+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
39750
39751 for(i=0; i<NWD; i++) {
39752 struct gendisk *disk = ida_gendisk[ctlr][i];
39753@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
39754 /* Wait (up to 2 seconds) for a command to complete */
39755
39756 for (i = 200000; i > 0; i--) {
39757- done = hba[ctlr]->access.command_completed(hba[ctlr]);
39758+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
39759 if (done == 0) {
39760 udelay(10); /* a short fixed delay */
39761 } else
39762diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
39763index be73e9d..7fbf140 100644
39764--- a/drivers/block/cpqarray.h
39765+++ b/drivers/block/cpqarray.h
39766@@ -99,7 +99,7 @@ struct ctlr_info {
39767 drv_info_t drv[NWD];
39768 struct proc_dir_entry *proc;
39769
39770- struct access_method access;
39771+ struct access_method *access;
39772
39773 cmdlist_t *reqQ;
39774 cmdlist_t *cmpQ;
39775diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
39776index a76ceb3..3c1a9fd 100644
39777--- a/drivers/block/drbd/drbd_int.h
39778+++ b/drivers/block/drbd/drbd_int.h
39779@@ -331,7 +331,7 @@ struct drbd_epoch {
39780 struct drbd_connection *connection;
39781 struct list_head list;
39782 unsigned int barrier_nr;
39783- atomic_t epoch_size; /* increased on every request added. */
39784+ atomic_unchecked_t epoch_size; /* increased on every request added. */
39785 atomic_t active; /* increased on every req. added, and dec on every finished. */
39786 unsigned long flags;
39787 };
39788@@ -797,7 +797,7 @@ struct drbd_device {
39789 unsigned int al_tr_number;
39790 int al_tr_cycle;
39791 wait_queue_head_t seq_wait;
39792- atomic_t packet_seq;
39793+ atomic_unchecked_t packet_seq;
39794 unsigned int peer_seq;
39795 spinlock_t peer_seq_lock;
39796 unsigned int minor;
39797@@ -1407,7 +1407,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
39798 char __user *uoptval;
39799 int err;
39800
39801- uoptval = (char __user __force *)optval;
39802+ uoptval = (char __force_user *)optval;
39803
39804 set_fs(KERNEL_DS);
39805 if (level == SOL_SOCKET)
39806diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
39807index 89c497c..9c736ae 100644
39808--- a/drivers/block/drbd/drbd_interval.c
39809+++ b/drivers/block/drbd/drbd_interval.c
39810@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
39811 }
39812
39813 static const struct rb_augment_callbacks augment_callbacks = {
39814- augment_propagate,
39815- augment_copy,
39816- augment_rotate,
39817+ .propagate = augment_propagate,
39818+ .copy = augment_copy,
39819+ .rotate = augment_rotate,
39820 };
39821
39822 /**
39823diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
39824index 960645c..6c2724a 100644
39825--- a/drivers/block/drbd/drbd_main.c
39826+++ b/drivers/block/drbd/drbd_main.c
39827@@ -1322,7 +1322,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
39828 p->sector = sector;
39829 p->block_id = block_id;
39830 p->blksize = blksize;
39831- p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
39832+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
39833 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
39834 }
39835
39836@@ -1628,7 +1628,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
39837 return -EIO;
39838 p->sector = cpu_to_be64(req->i.sector);
39839 p->block_id = (unsigned long)req;
39840- p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
39841+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
39842 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
39843 if (device->state.conn >= C_SYNC_SOURCE &&
39844 device->state.conn <= C_PAUSED_SYNC_T)
39845@@ -2670,8 +2670,8 @@ void drbd_destroy_connection(struct kref *kref)
39846 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
39847 struct drbd_resource *resource = connection->resource;
39848
39849- if (atomic_read(&connection->current_epoch->epoch_size) != 0)
39850- drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
39851+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
39852+ drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
39853 kfree(connection->current_epoch);
39854
39855 idr_destroy(&connection->peer_devices);
39856diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
39857index 3f2e167..d3170e4 100644
39858--- a/drivers/block/drbd/drbd_nl.c
39859+++ b/drivers/block/drbd/drbd_nl.c
39860@@ -3616,7 +3616,7 @@ finish:
39861
39862 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
39863 {
39864- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39865+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39866 struct sk_buff *msg;
39867 struct drbd_genlmsghdr *d_out;
39868 unsigned seq;
39869@@ -3629,7 +3629,7 @@ void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
39870 return;
39871 }
39872
39873- seq = atomic_inc_return(&drbd_genl_seq);
39874+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
39875 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
39876 if (!msg)
39877 goto failed;
39878diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
39879index 5b17ec8..6c21e6b 100644
39880--- a/drivers/block/drbd/drbd_receiver.c
39881+++ b/drivers/block/drbd/drbd_receiver.c
39882@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
39883 struct drbd_device *device = peer_device->device;
39884 int err;
39885
39886- atomic_set(&device->packet_seq, 0);
39887+ atomic_set_unchecked(&device->packet_seq, 0);
39888 device->peer_seq = 0;
39889
39890 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
39891@@ -1199,7 +1199,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39892 do {
39893 next_epoch = NULL;
39894
39895- epoch_size = atomic_read(&epoch->epoch_size);
39896+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
39897
39898 switch (ev & ~EV_CLEANUP) {
39899 case EV_PUT:
39900@@ -1239,7 +1239,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39901 rv = FE_DESTROYED;
39902 } else {
39903 epoch->flags = 0;
39904- atomic_set(&epoch->epoch_size, 0);
39905+ atomic_set_unchecked(&epoch->epoch_size, 0);
39906 /* atomic_set(&epoch->active, 0); is already zero */
39907 if (rv == FE_STILL_LIVE)
39908 rv = FE_RECYCLED;
39909@@ -1490,7 +1490,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39910 conn_wait_active_ee_empty(connection);
39911 drbd_flush(connection);
39912
39913- if (atomic_read(&connection->current_epoch->epoch_size)) {
39914+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39915 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
39916 if (epoch)
39917 break;
39918@@ -1503,11 +1503,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39919 }
39920
39921 epoch->flags = 0;
39922- atomic_set(&epoch->epoch_size, 0);
39923+ atomic_set_unchecked(&epoch->epoch_size, 0);
39924 atomic_set(&epoch->active, 0);
39925
39926 spin_lock(&connection->epoch_lock);
39927- if (atomic_read(&connection->current_epoch->epoch_size)) {
39928+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39929 list_add(&epoch->list, &connection->current_epoch->list);
39930 connection->current_epoch = epoch;
39931 connection->epochs++;
39932@@ -2224,7 +2224,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39933
39934 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
39935 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39936- atomic_inc(&connection->current_epoch->epoch_size);
39937+ atomic_inc_unchecked(&connection->current_epoch->epoch_size);
39938 err2 = drbd_drain_block(peer_device, pi->size);
39939 if (!err)
39940 err = err2;
39941@@ -2266,7 +2266,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39942
39943 spin_lock(&connection->epoch_lock);
39944 peer_req->epoch = connection->current_epoch;
39945- atomic_inc(&peer_req->epoch->epoch_size);
39946+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
39947 atomic_inc(&peer_req->epoch->active);
39948 spin_unlock(&connection->epoch_lock);
39949
39950@@ -4461,7 +4461,7 @@ struct data_cmd {
39951 int expect_payload;
39952 size_t pkt_size;
39953 int (*fn)(struct drbd_connection *, struct packet_info *);
39954-};
39955+} __do_const;
39956
39957 static struct data_cmd drbd_cmd_handler[] = {
39958 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
39959@@ -4572,7 +4572,7 @@ static void conn_disconnect(struct drbd_connection *connection)
39960 if (!list_empty(&connection->current_epoch->list))
39961 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
39962 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
39963- atomic_set(&connection->current_epoch->epoch_size, 0);
39964+ atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
39965 connection->send.seen_any_write_yet = false;
39966
39967 drbd_info(connection, "Connection closed\n");
39968@@ -5364,7 +5364,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
39969 struct asender_cmd {
39970 size_t pkt_size;
39971 int (*fn)(struct drbd_connection *connection, struct packet_info *);
39972-};
39973+} __do_const;
39974
39975 static struct asender_cmd asender_tbl[] = {
39976 [P_PING] = { 0, got_Ping },
39977diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39978index 6cb1beb..bf490f7 100644
39979--- a/drivers/block/loop.c
39980+++ b/drivers/block/loop.c
39981@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
39982
39983 file_start_write(file);
39984 set_fs(get_ds());
39985- bw = file->f_op->write(file, buf, len, &pos);
39986+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
39987 set_fs(old_fs);
39988 file_end_write(file);
39989 if (likely(bw == len))
39990diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
39991index 02351e2..a9ea617 100644
39992--- a/drivers/block/nvme-core.c
39993+++ b/drivers/block/nvme-core.c
39994@@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
39995 static struct task_struct *nvme_thread;
39996 static struct workqueue_struct *nvme_workq;
39997 static wait_queue_head_t nvme_kthread_wait;
39998-static struct notifier_block nvme_nb;
39999
40000 static void nvme_reset_failed_dev(struct work_struct *ws);
40001
40002@@ -2925,6 +2924,10 @@ static struct pci_driver nvme_driver = {
40003 .err_handler = &nvme_err_handler,
40004 };
40005
40006+static struct notifier_block nvme_nb = {
40007+ .notifier_call = &nvme_cpu_notify,
40008+};
40009+
40010 static int __init nvme_init(void)
40011 {
40012 int result;
40013@@ -2941,7 +2944,6 @@ static int __init nvme_init(void)
40014 else if (result > 0)
40015 nvme_major = result;
40016
40017- nvme_nb.notifier_call = &nvme_cpu_notify;
40018 result = register_hotcpu_notifier(&nvme_nb);
40019 if (result)
40020 goto unregister_blkdev;
40021diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
40022index 758ac44..58087fd 100644
40023--- a/drivers/block/pktcdvd.c
40024+++ b/drivers/block/pktcdvd.c
40025@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
40026
40027 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
40028 {
40029- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
40030+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
40031 }
40032
40033 /*
40034@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
40035 return -EROFS;
40036 }
40037 pd->settings.fp = ti.fp;
40038- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
40039+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
40040
40041 if (ti.nwa_v) {
40042 pd->nwa = be32_to_cpu(ti.next_writable);
40043diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
40044index e5565fb..71be10b4 100644
40045--- a/drivers/block/smart1,2.h
40046+++ b/drivers/block/smart1,2.h
40047@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
40048 }
40049
40050 static struct access_method smart4_access = {
40051- smart4_submit_command,
40052- smart4_intr_mask,
40053- smart4_fifo_full,
40054- smart4_intr_pending,
40055- smart4_completed,
40056+ .submit_command = smart4_submit_command,
40057+ .set_intr_mask = smart4_intr_mask,
40058+ .fifo_full = smart4_fifo_full,
40059+ .intr_pending = smart4_intr_pending,
40060+ .command_completed = smart4_completed,
40061 };
40062
40063 /*
40064@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
40065 }
40066
40067 static struct access_method smart2_access = {
40068- smart2_submit_command,
40069- smart2_intr_mask,
40070- smart2_fifo_full,
40071- smart2_intr_pending,
40072- smart2_completed,
40073+ .submit_command = smart2_submit_command,
40074+ .set_intr_mask = smart2_intr_mask,
40075+ .fifo_full = smart2_fifo_full,
40076+ .intr_pending = smart2_intr_pending,
40077+ .command_completed = smart2_completed,
40078 };
40079
40080 /*
40081@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
40082 }
40083
40084 static struct access_method smart2e_access = {
40085- smart2e_submit_command,
40086- smart2e_intr_mask,
40087- smart2e_fifo_full,
40088- smart2e_intr_pending,
40089- smart2e_completed,
40090+ .submit_command = smart2e_submit_command,
40091+ .set_intr_mask = smart2e_intr_mask,
40092+ .fifo_full = smart2e_fifo_full,
40093+ .intr_pending = smart2e_intr_pending,
40094+ .command_completed = smart2e_completed,
40095 };
40096
40097 /*
40098@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
40099 }
40100
40101 static struct access_method smart1_access = {
40102- smart1_submit_command,
40103- smart1_intr_mask,
40104- smart1_fifo_full,
40105- smart1_intr_pending,
40106- smart1_completed,
40107+ .submit_command = smart1_submit_command,
40108+ .set_intr_mask = smart1_intr_mask,
40109+ .fifo_full = smart1_fifo_full,
40110+ .intr_pending = smart1_intr_pending,
40111+ .command_completed = smart1_completed,
40112 };
40113diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
40114index f038dba..bb74c08 100644
40115--- a/drivers/bluetooth/btwilink.c
40116+++ b/drivers/bluetooth/btwilink.c
40117@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
40118
40119 static int bt_ti_probe(struct platform_device *pdev)
40120 {
40121- static struct ti_st *hst;
40122+ struct ti_st *hst;
40123 struct hci_dev *hdev;
40124 int err;
40125
40126diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
40127index 898b84b..86f74b9 100644
40128--- a/drivers/cdrom/cdrom.c
40129+++ b/drivers/cdrom/cdrom.c
40130@@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
40131 ENSURE(reset, CDC_RESET);
40132 ENSURE(generic_packet, CDC_GENERIC_PACKET);
40133 cdi->mc_flags = 0;
40134- cdo->n_minors = 0;
40135 cdi->options = CDO_USE_FFLAGS;
40136
40137 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
40138@@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
40139 else
40140 cdi->cdda_method = CDDA_OLD;
40141
40142- if (!cdo->generic_packet)
40143- cdo->generic_packet = cdrom_dummy_generic_packet;
40144+ if (!cdo->generic_packet) {
40145+ pax_open_kernel();
40146+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
40147+ pax_close_kernel();
40148+ }
40149
40150 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
40151 mutex_lock(&cdrom_mutex);
40152@@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
40153 if (cdi->exit)
40154 cdi->exit(cdi);
40155
40156- cdi->ops->n_minors--;
40157 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
40158 }
40159
40160@@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
40161 */
40162 nr = nframes;
40163 do {
40164- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
40165+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
40166 if (cgc.buffer)
40167 break;
40168
40169@@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
40170 struct cdrom_device_info *cdi;
40171 int ret;
40172
40173- ret = scnprintf(info + *pos, max_size - *pos, header);
40174+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
40175 if (!ret)
40176 return 1;
40177
40178diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
40179index 584bc31..e64a12c 100644
40180--- a/drivers/cdrom/gdrom.c
40181+++ b/drivers/cdrom/gdrom.c
40182@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
40183 .audio_ioctl = gdrom_audio_ioctl,
40184 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
40185 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
40186- .n_minors = 1,
40187 };
40188
40189 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
40190diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
40191index 6e9f74a..50c7cea 100644
40192--- a/drivers/char/Kconfig
40193+++ b/drivers/char/Kconfig
40194@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
40195
40196 config DEVKMEM
40197 bool "/dev/kmem virtual device support"
40198- default y
40199+ default n
40200+ depends on !GRKERNSEC_KMEM
40201 help
40202 Say Y here if you want to support the /dev/kmem device. The
40203 /dev/kmem device is rarely used, but can be used for certain
40204@@ -577,6 +578,7 @@ config DEVPORT
40205 bool
40206 depends on !M68K
40207 depends on ISA || PCI
40208+ depends on !GRKERNSEC_KMEM
40209 default y
40210
40211 source "drivers/s390/char/Kconfig"
40212diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
40213index a48e05b..6bac831 100644
40214--- a/drivers/char/agp/compat_ioctl.c
40215+++ b/drivers/char/agp/compat_ioctl.c
40216@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
40217 return -ENOMEM;
40218 }
40219
40220- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
40221+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
40222 sizeof(*usegment) * ureserve.seg_count)) {
40223 kfree(usegment);
40224 kfree(ksegment);
40225diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
40226index b297033..fa217ca 100644
40227--- a/drivers/char/agp/frontend.c
40228+++ b/drivers/char/agp/frontend.c
40229@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
40230 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
40231 return -EFAULT;
40232
40233- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
40234+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
40235 return -EFAULT;
40236
40237 client = agp_find_client_by_pid(reserve.pid);
40238@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
40239 if (segment == NULL)
40240 return -ENOMEM;
40241
40242- if (copy_from_user(segment, (void __user *) reserve.seg_list,
40243+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
40244 sizeof(struct agp_segment) * reserve.seg_count)) {
40245 kfree(segment);
40246 return -EFAULT;
40247diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
40248index 4f94375..413694e 100644
40249--- a/drivers/char/genrtc.c
40250+++ b/drivers/char/genrtc.c
40251@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
40252 switch (cmd) {
40253
40254 case RTC_PLL_GET:
40255+ memset(&pll, 0, sizeof(pll));
40256 if (get_rtc_pll(&pll))
40257 return -EINVAL;
40258 else
40259diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
40260index d5d4cd8..22d561d 100644
40261--- a/drivers/char/hpet.c
40262+++ b/drivers/char/hpet.c
40263@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
40264 }
40265
40266 static int
40267-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
40268+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
40269 struct hpet_info *info)
40270 {
40271 struct hpet_timer __iomem *timer;
40272diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
40273index 86fe45c..c0ea948 100644
40274--- a/drivers/char/hw_random/intel-rng.c
40275+++ b/drivers/char/hw_random/intel-rng.c
40276@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
40277
40278 if (no_fwh_detect)
40279 return -ENODEV;
40280- printk(warning);
40281+ printk("%s", warning);
40282 return -EBUSY;
40283 }
40284
40285diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
40286index e6db938..835e3a2 100644
40287--- a/drivers/char/ipmi/ipmi_msghandler.c
40288+++ b/drivers/char/ipmi/ipmi_msghandler.c
40289@@ -438,7 +438,7 @@ struct ipmi_smi {
40290 struct proc_dir_entry *proc_dir;
40291 char proc_dir_name[10];
40292
40293- atomic_t stats[IPMI_NUM_STATS];
40294+ atomic_unchecked_t stats[IPMI_NUM_STATS];
40295
40296 /*
40297 * run_to_completion duplicate of smb_info, smi_info
40298@@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
40299 static DEFINE_MUTEX(smi_watchers_mutex);
40300
40301 #define ipmi_inc_stat(intf, stat) \
40302- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
40303+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
40304 #define ipmi_get_stat(intf, stat) \
40305- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
40306+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
40307
40308 static int is_lan_addr(struct ipmi_addr *addr)
40309 {
40310@@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
40311 INIT_LIST_HEAD(&intf->cmd_rcvrs);
40312 init_waitqueue_head(&intf->waitq);
40313 for (i = 0; i < IPMI_NUM_STATS; i++)
40314- atomic_set(&intf->stats[i], 0);
40315+ atomic_set_unchecked(&intf->stats[i], 0);
40316
40317 intf->proc_dir = NULL;
40318
40319diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
40320index 5d66568..c9d93c3 100644
40321--- a/drivers/char/ipmi/ipmi_si_intf.c
40322+++ b/drivers/char/ipmi/ipmi_si_intf.c
40323@@ -285,7 +285,7 @@ struct smi_info {
40324 unsigned char slave_addr;
40325
40326 /* Counters and things for the proc filesystem. */
40327- atomic_t stats[SI_NUM_STATS];
40328+ atomic_unchecked_t stats[SI_NUM_STATS];
40329
40330 struct task_struct *thread;
40331
40332@@ -294,9 +294,9 @@ struct smi_info {
40333 };
40334
40335 #define smi_inc_stat(smi, stat) \
40336- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
40337+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
40338 #define smi_get_stat(smi, stat) \
40339- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
40340+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
40341
40342 #define SI_MAX_PARMS 4
40343
40344@@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
40345 atomic_set(&new_smi->req_events, 0);
40346 new_smi->run_to_completion = false;
40347 for (i = 0; i < SI_NUM_STATS; i++)
40348- atomic_set(&new_smi->stats[i], 0);
40349+ atomic_set_unchecked(&new_smi->stats[i], 0);
40350
40351 new_smi->interrupt_disabled = true;
40352 atomic_set(&new_smi->stop_operation, 0);
40353diff --git a/drivers/char/mem.c b/drivers/char/mem.c
40354index 917403f..dddd899 100644
40355--- a/drivers/char/mem.c
40356+++ b/drivers/char/mem.c
40357@@ -18,6 +18,7 @@
40358 #include <linux/raw.h>
40359 #include <linux/tty.h>
40360 #include <linux/capability.h>
40361+#include <linux/security.h>
40362 #include <linux/ptrace.h>
40363 #include <linux/device.h>
40364 #include <linux/highmem.h>
40365@@ -36,6 +37,10 @@
40366
40367 #define DEVPORT_MINOR 4
40368
40369+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
40370+extern const struct file_operations grsec_fops;
40371+#endif
40372+
40373 static inline unsigned long size_inside_page(unsigned long start,
40374 unsigned long size)
40375 {
40376@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40377
40378 while (cursor < to) {
40379 if (!devmem_is_allowed(pfn)) {
40380+#ifdef CONFIG_GRKERNSEC_KMEM
40381+ gr_handle_mem_readwrite(from, to);
40382+#else
40383 printk(KERN_INFO
40384 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
40385 current->comm, from, to);
40386+#endif
40387 return 0;
40388 }
40389 cursor += PAGE_SIZE;
40390@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40391 }
40392 return 1;
40393 }
40394+#elif defined(CONFIG_GRKERNSEC_KMEM)
40395+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40396+{
40397+ return 0;
40398+}
40399 #else
40400 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40401 {
40402@@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
40403
40404 while (count > 0) {
40405 unsigned long remaining;
40406+ char *temp;
40407
40408 sz = size_inside_page(p, count);
40409
40410@@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
40411 if (!ptr)
40412 return -EFAULT;
40413
40414- remaining = copy_to_user(buf, ptr, sz);
40415+#ifdef CONFIG_PAX_USERCOPY
40416+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
40417+ if (!temp) {
40418+ unxlate_dev_mem_ptr(p, ptr);
40419+ return -ENOMEM;
40420+ }
40421+ memcpy(temp, ptr, sz);
40422+#else
40423+ temp = ptr;
40424+#endif
40425+
40426+ remaining = copy_to_user(buf, temp, sz);
40427+
40428+#ifdef CONFIG_PAX_USERCOPY
40429+ kfree(temp);
40430+#endif
40431+
40432 unxlate_dev_mem_ptr(p, ptr);
40433 if (remaining)
40434 return -EFAULT;
40435@@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
40436 size_t count, loff_t *ppos)
40437 {
40438 unsigned long p = *ppos;
40439- ssize_t low_count, read, sz;
40440+ ssize_t low_count, read, sz, err = 0;
40441 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
40442- int err = 0;
40443
40444 read = 0;
40445 if (p < (unsigned long) high_memory) {
40446@@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
40447 }
40448 #endif
40449 while (low_count > 0) {
40450+ char *temp;
40451+
40452 sz = size_inside_page(p, low_count);
40453
40454 /*
40455@@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
40456 */
40457 kbuf = xlate_dev_kmem_ptr((char *)p);
40458
40459- if (copy_to_user(buf, kbuf, sz))
40460+#ifdef CONFIG_PAX_USERCOPY
40461+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
40462+ if (!temp)
40463+ return -ENOMEM;
40464+ memcpy(temp, kbuf, sz);
40465+#else
40466+ temp = kbuf;
40467+#endif
40468+
40469+ err = copy_to_user(buf, temp, sz);
40470+
40471+#ifdef CONFIG_PAX_USERCOPY
40472+ kfree(temp);
40473+#endif
40474+
40475+ if (err)
40476 return -EFAULT;
40477 buf += sz;
40478 p += sz;
40479@@ -827,6 +874,9 @@ static const struct memdev {
40480 #ifdef CONFIG_PRINTK
40481 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
40482 #endif
40483+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
40484+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
40485+#endif
40486 };
40487
40488 static int memory_open(struct inode *inode, struct file *filp)
40489@@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
40490 continue;
40491
40492 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
40493- NULL, devlist[minor].name);
40494+ NULL, "%s", devlist[minor].name);
40495 }
40496
40497 return tty_init();
40498diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
40499index 9df78e2..01ba9ae 100644
40500--- a/drivers/char/nvram.c
40501+++ b/drivers/char/nvram.c
40502@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
40503
40504 spin_unlock_irq(&rtc_lock);
40505
40506- if (copy_to_user(buf, contents, tmp - contents))
40507+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
40508 return -EFAULT;
40509
40510 *ppos = i;
40511diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
40512index 8320abd..ec48108 100644
40513--- a/drivers/char/pcmcia/synclink_cs.c
40514+++ b/drivers/char/pcmcia/synclink_cs.c
40515@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
40516
40517 if (debug_level >= DEBUG_LEVEL_INFO)
40518 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
40519- __FILE__, __LINE__, info->device_name, port->count);
40520+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
40521
40522- WARN_ON(!port->count);
40523+ WARN_ON(!atomic_read(&port->count));
40524
40525 if (tty_port_close_start(port, tty, filp) == 0)
40526 goto cleanup;
40527@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
40528 cleanup:
40529 if (debug_level >= DEBUG_LEVEL_INFO)
40530 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
40531- tty->driver->name, port->count);
40532+ tty->driver->name, atomic_read(&port->count));
40533 }
40534
40535 /* Wait until the transmitter is empty.
40536@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
40537
40538 if (debug_level >= DEBUG_LEVEL_INFO)
40539 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
40540- __FILE__, __LINE__, tty->driver->name, port->count);
40541+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
40542
40543 /* If port is closing, signal caller to try again */
40544 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
40545@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
40546 goto cleanup;
40547 }
40548 spin_lock(&port->lock);
40549- port->count++;
40550+ atomic_inc(&port->count);
40551 spin_unlock(&port->lock);
40552 spin_unlock_irqrestore(&info->netlock, flags);
40553
40554- if (port->count == 1) {
40555+ if (atomic_read(&port->count) == 1) {
40556 /* 1st open on this device, init hardware */
40557 retval = startup(info, tty);
40558 if (retval < 0)
40559@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40560 unsigned short new_crctype;
40561
40562 /* return error if TTY interface open */
40563- if (info->port.count)
40564+ if (atomic_read(&info->port.count))
40565 return -EBUSY;
40566
40567 switch (encoding)
40568@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
40569
40570 /* arbitrate between network and tty opens */
40571 spin_lock_irqsave(&info->netlock, flags);
40572- if (info->port.count != 0 || info->netcount != 0) {
40573+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40574 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40575 spin_unlock_irqrestore(&info->netlock, flags);
40576 return -EBUSY;
40577@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40578 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
40579
40580 /* return error if TTY interface open */
40581- if (info->port.count)
40582+ if (atomic_read(&info->port.count))
40583 return -EBUSY;
40584
40585 if (cmd != SIOCWANDEV)
40586diff --git a/drivers/char/random.c b/drivers/char/random.c
40587index 71529e1..822b036 100644
40588--- a/drivers/char/random.c
40589+++ b/drivers/char/random.c
40590@@ -284,9 +284,6 @@
40591 /*
40592 * To allow fractional bits to be tracked, the entropy_count field is
40593 * denominated in units of 1/8th bits.
40594- *
40595- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
40596- * credit_entropy_bits() needs to be 64 bits wide.
40597 */
40598 #define ENTROPY_SHIFT 3
40599 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
40600@@ -433,9 +430,9 @@ struct entropy_store {
40601 };
40602
40603 static void push_to_pool(struct work_struct *work);
40604-static __u32 input_pool_data[INPUT_POOL_WORDS];
40605-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
40606-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
40607+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
40608+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
40609+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
40610
40611 static struct entropy_store input_pool = {
40612 .poolinfo = &poolinfo_table[0],
40613@@ -524,8 +521,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
40614 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
40615 }
40616
40617- ACCESS_ONCE(r->input_rotate) = input_rotate;
40618- ACCESS_ONCE(r->add_ptr) = i;
40619+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
40620+ ACCESS_ONCE_RW(r->add_ptr) = i;
40621 smp_wmb();
40622
40623 if (out)
40624@@ -632,7 +629,7 @@ retry:
40625 /* The +2 corresponds to the /4 in the denominator */
40626
40627 do {
40628- unsigned int anfrac = min(pnfrac, pool_size/2);
40629+ u64 anfrac = min(pnfrac, pool_size/2);
40630 unsigned int add =
40631 ((pool_size - entropy_count)*anfrac*3) >> s;
40632
40633@@ -1177,7 +1174,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
40634
40635 extract_buf(r, tmp);
40636 i = min_t(int, nbytes, EXTRACT_SIZE);
40637- if (copy_to_user(buf, tmp, i)) {
40638+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
40639 ret = -EFAULT;
40640 break;
40641 }
40642@@ -1567,7 +1564,7 @@ static char sysctl_bootid[16];
40643 static int proc_do_uuid(struct ctl_table *table, int write,
40644 void __user *buffer, size_t *lenp, loff_t *ppos)
40645 {
40646- struct ctl_table fake_table;
40647+ ctl_table_no_const fake_table;
40648 unsigned char buf[64], tmp_uuid[16], *uuid;
40649
40650 uuid = table->data;
40651@@ -1597,7 +1594,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
40652 static int proc_do_entropy(struct ctl_table *table, int write,
40653 void __user *buffer, size_t *lenp, loff_t *ppos)
40654 {
40655- struct ctl_table fake_table;
40656+ ctl_table_no_const fake_table;
40657 int entropy_count;
40658
40659 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
40660diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
40661index 7cc1fe22..b602d6b 100644
40662--- a/drivers/char/sonypi.c
40663+++ b/drivers/char/sonypi.c
40664@@ -54,6 +54,7 @@
40665
40666 #include <asm/uaccess.h>
40667 #include <asm/io.h>
40668+#include <asm/local.h>
40669
40670 #include <linux/sonypi.h>
40671
40672@@ -490,7 +491,7 @@ static struct sonypi_device {
40673 spinlock_t fifo_lock;
40674 wait_queue_head_t fifo_proc_list;
40675 struct fasync_struct *fifo_async;
40676- int open_count;
40677+ local_t open_count;
40678 int model;
40679 struct input_dev *input_jog_dev;
40680 struct input_dev *input_key_dev;
40681@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
40682 static int sonypi_misc_release(struct inode *inode, struct file *file)
40683 {
40684 mutex_lock(&sonypi_device.lock);
40685- sonypi_device.open_count--;
40686+ local_dec(&sonypi_device.open_count);
40687 mutex_unlock(&sonypi_device.lock);
40688 return 0;
40689 }
40690@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
40691 {
40692 mutex_lock(&sonypi_device.lock);
40693 /* Flush input queue on first open */
40694- if (!sonypi_device.open_count)
40695+ if (!local_read(&sonypi_device.open_count))
40696 kfifo_reset(&sonypi_device.fifo);
40697- sonypi_device.open_count++;
40698+ local_inc(&sonypi_device.open_count);
40699 mutex_unlock(&sonypi_device.lock);
40700
40701 return 0;
40702diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
40703index 565a947..dcdc06e 100644
40704--- a/drivers/char/tpm/tpm_acpi.c
40705+++ b/drivers/char/tpm/tpm_acpi.c
40706@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
40707 virt = acpi_os_map_iomem(start, len);
40708 if (!virt) {
40709 kfree(log->bios_event_log);
40710+ log->bios_event_log = NULL;
40711 printk("%s: ERROR - Unable to map memory\n", __func__);
40712 return -EIO;
40713 }
40714
40715- memcpy_fromio(log->bios_event_log, virt, len);
40716+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
40717
40718 acpi_os_unmap_iomem(virt, len);
40719 return 0;
40720diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
40721index 59f7cb2..bac8b6d 100644
40722--- a/drivers/char/tpm/tpm_eventlog.c
40723+++ b/drivers/char/tpm/tpm_eventlog.c
40724@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
40725 event = addr;
40726
40727 if ((event->event_type == 0 && event->event_size == 0) ||
40728- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
40729+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
40730 return NULL;
40731
40732 return addr;
40733@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
40734 return NULL;
40735
40736 if ((event->event_type == 0 && event->event_size == 0) ||
40737- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
40738+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
40739 return NULL;
40740
40741 (*pos)++;
40742@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
40743 int i;
40744
40745 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
40746- seq_putc(m, data[i]);
40747+ if (!seq_putc(m, data[i]))
40748+ return -EFAULT;
40749
40750 return 0;
40751 }
40752diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
40753index 60aafb8..10c08e0 100644
40754--- a/drivers/char/virtio_console.c
40755+++ b/drivers/char/virtio_console.c
40756@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
40757 if (to_user) {
40758 ssize_t ret;
40759
40760- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
40761+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
40762 if (ret)
40763 return -EFAULT;
40764 } else {
40765@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
40766 if (!port_has_data(port) && !port->host_connected)
40767 return 0;
40768
40769- return fill_readbuf(port, ubuf, count, true);
40770+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
40771 }
40772
40773 static int wait_port_writable(struct port *port, bool nonblock)
40774diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
40775index 57a078e..c17cde8 100644
40776--- a/drivers/clk/clk-composite.c
40777+++ b/drivers/clk/clk-composite.c
40778@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
40779 struct clk *clk;
40780 struct clk_init_data init;
40781 struct clk_composite *composite;
40782- struct clk_ops *clk_composite_ops;
40783+ clk_ops_no_const *clk_composite_ops;
40784
40785 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
40786 if (!composite) {
40787diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
40788index dd3a78c..386d49c 100644
40789--- a/drivers/clk/socfpga/clk-gate.c
40790+++ b/drivers/clk/socfpga/clk-gate.c
40791@@ -22,6 +22,7 @@
40792 #include <linux/mfd/syscon.h>
40793 #include <linux/of.h>
40794 #include <linux/regmap.h>
40795+#include <asm/pgtable.h>
40796
40797 #include "clk.h"
40798
40799@@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
40800 return 0;
40801 }
40802
40803-static struct clk_ops gateclk_ops = {
40804+static clk_ops_no_const gateclk_ops __read_only = {
40805 .prepare = socfpga_clk_prepare,
40806 .recalc_rate = socfpga_clk_recalc_rate,
40807 .get_parent = socfpga_clk_get_parent,
40808@@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
40809 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
40810 socfpga_clk->hw.bit_idx = clk_gate[1];
40811
40812- gateclk_ops.enable = clk_gate_ops.enable;
40813- gateclk_ops.disable = clk_gate_ops.disable;
40814+ pax_open_kernel();
40815+ *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
40816+ *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
40817+ pax_close_kernel();
40818 }
40819
40820 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
40821diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
40822index de6da95..c98278b 100644
40823--- a/drivers/clk/socfpga/clk-pll.c
40824+++ b/drivers/clk/socfpga/clk-pll.c
40825@@ -21,6 +21,7 @@
40826 #include <linux/io.h>
40827 #include <linux/of.h>
40828 #include <linux/of_address.h>
40829+#include <asm/pgtable.h>
40830
40831 #include "clk.h"
40832
40833@@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
40834 CLK_MGR_PLL_CLK_SRC_MASK;
40835 }
40836
40837-static struct clk_ops clk_pll_ops = {
40838+static clk_ops_no_const clk_pll_ops __read_only = {
40839 .recalc_rate = clk_pll_recalc_rate,
40840 .get_parent = clk_pll_get_parent,
40841 };
40842@@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
40843 pll_clk->hw.hw.init = &init;
40844
40845 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
40846- clk_pll_ops.enable = clk_gate_ops.enable;
40847- clk_pll_ops.disable = clk_gate_ops.disable;
40848+ pax_open_kernel();
40849+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
40850+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
40851+ pax_close_kernel();
40852
40853 clk = clk_register(NULL, &pll_clk->hw.hw);
40854 if (WARN_ON(IS_ERR(clk))) {
40855diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
40856index b0c18ed..1713a80 100644
40857--- a/drivers/cpufreq/acpi-cpufreq.c
40858+++ b/drivers/cpufreq/acpi-cpufreq.c
40859@@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40860 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
40861 per_cpu(acfreq_data, cpu) = data;
40862
40863- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
40864- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40865+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
40866+ pax_open_kernel();
40867+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40868+ pax_close_kernel();
40869+ }
40870
40871 result = acpi_processor_register_performance(data->acpi_data, cpu);
40872 if (result)
40873@@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40874 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
40875 break;
40876 case ACPI_ADR_SPACE_FIXED_HARDWARE:
40877- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40878+ pax_open_kernel();
40879+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40880+ pax_close_kernel();
40881 break;
40882 default:
40883 break;
40884@@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
40885 if (!msrs)
40886 return;
40887
40888- acpi_cpufreq_driver.boost_supported = true;
40889- acpi_cpufreq_driver.boost_enabled = boost_state(0);
40890+ pax_open_kernel();
40891+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
40892+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
40893+ pax_close_kernel();
40894
40895 cpu_notifier_register_begin();
40896
40897diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
40898index 6f02485..13684ae 100644
40899--- a/drivers/cpufreq/cpufreq.c
40900+++ b/drivers/cpufreq/cpufreq.c
40901@@ -2100,7 +2100,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
40902 }
40903
40904 mutex_lock(&cpufreq_governor_mutex);
40905- list_del(&governor->governor_list);
40906+ pax_list_del(&governor->governor_list);
40907 mutex_unlock(&cpufreq_governor_mutex);
40908 return;
40909 }
40910@@ -2316,7 +2316,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
40911 return NOTIFY_OK;
40912 }
40913
40914-static struct notifier_block __refdata cpufreq_cpu_notifier = {
40915+static struct notifier_block cpufreq_cpu_notifier = {
40916 .notifier_call = cpufreq_cpu_callback,
40917 };
40918
40919@@ -2356,13 +2356,17 @@ int cpufreq_boost_trigger_state(int state)
40920 return 0;
40921
40922 write_lock_irqsave(&cpufreq_driver_lock, flags);
40923- cpufreq_driver->boost_enabled = state;
40924+ pax_open_kernel();
40925+ *(bool *)&cpufreq_driver->boost_enabled = state;
40926+ pax_close_kernel();
40927 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40928
40929 ret = cpufreq_driver->set_boost(state);
40930 if (ret) {
40931 write_lock_irqsave(&cpufreq_driver_lock, flags);
40932- cpufreq_driver->boost_enabled = !state;
40933+ pax_open_kernel();
40934+ *(bool *)&cpufreq_driver->boost_enabled = !state;
40935+ pax_close_kernel();
40936 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40937
40938 pr_err("%s: Cannot %s BOOST\n",
40939@@ -2419,8 +2423,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40940
40941 pr_debug("trying to register driver %s\n", driver_data->name);
40942
40943- if (driver_data->setpolicy)
40944- driver_data->flags |= CPUFREQ_CONST_LOOPS;
40945+ if (driver_data->setpolicy) {
40946+ pax_open_kernel();
40947+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
40948+ pax_close_kernel();
40949+ }
40950
40951 write_lock_irqsave(&cpufreq_driver_lock, flags);
40952 if (cpufreq_driver) {
40953@@ -2435,8 +2442,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40954 * Check if driver provides function to enable boost -
40955 * if not, use cpufreq_boost_set_sw as default
40956 */
40957- if (!cpufreq_driver->set_boost)
40958- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40959+ if (!cpufreq_driver->set_boost) {
40960+ pax_open_kernel();
40961+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40962+ pax_close_kernel();
40963+ }
40964
40965 ret = cpufreq_sysfs_create_file(&boost.attr);
40966 if (ret) {
40967diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
40968index 1b44496..b80ff5e 100644
40969--- a/drivers/cpufreq/cpufreq_governor.c
40970+++ b/drivers/cpufreq/cpufreq_governor.c
40971@@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40972 struct dbs_data *dbs_data;
40973 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
40974 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
40975- struct od_ops *od_ops = NULL;
40976+ const struct od_ops *od_ops = NULL;
40977 struct od_dbs_tuners *od_tuners = NULL;
40978 struct cs_dbs_tuners *cs_tuners = NULL;
40979 struct cpu_dbs_common_info *cpu_cdbs;
40980@@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40981
40982 if ((cdata->governor == GOV_CONSERVATIVE) &&
40983 (!policy->governor->initialized)) {
40984- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40985+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40986
40987 cpufreq_register_notifier(cs_ops->notifier_block,
40988 CPUFREQ_TRANSITION_NOTIFIER);
40989@@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40990
40991 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
40992 (policy->governor->initialized == 1)) {
40993- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40994+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40995
40996 cpufreq_unregister_notifier(cs_ops->notifier_block,
40997 CPUFREQ_TRANSITION_NOTIFIER);
40998diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
40999index cc401d1..8197340 100644
41000--- a/drivers/cpufreq/cpufreq_governor.h
41001+++ b/drivers/cpufreq/cpufreq_governor.h
41002@@ -212,7 +212,7 @@ struct common_dbs_data {
41003 void (*exit)(struct dbs_data *dbs_data);
41004
41005 /* Governor specific ops, see below */
41006- void *gov_ops;
41007+ const void *gov_ops;
41008 };
41009
41010 /* Governor Per policy data */
41011@@ -232,7 +232,7 @@ struct od_ops {
41012 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
41013 unsigned int freq_next, unsigned int relation);
41014 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
41015-};
41016+} __no_const;
41017
41018 struct cs_ops {
41019 struct notifier_block *notifier_block;
41020diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
41021index 18d4091..434be15 100644
41022--- a/drivers/cpufreq/cpufreq_ondemand.c
41023+++ b/drivers/cpufreq/cpufreq_ondemand.c
41024@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
41025
41026 define_get_cpu_dbs_routines(od_cpu_dbs_info);
41027
41028-static struct od_ops od_ops = {
41029+static struct od_ops od_ops __read_only = {
41030 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
41031 .powersave_bias_target = generic_powersave_bias_target,
41032 .freq_increase = dbs_freq_increase,
41033@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
41034 (struct cpufreq_policy *, unsigned int, unsigned int),
41035 unsigned int powersave_bias)
41036 {
41037- od_ops.powersave_bias_target = f;
41038+ pax_open_kernel();
41039+ *(void **)&od_ops.powersave_bias_target = f;
41040+ pax_close_kernel();
41041 od_set_powersave_bias(powersave_bias);
41042 }
41043 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
41044
41045 void od_unregister_powersave_bias_handler(void)
41046 {
41047- od_ops.powersave_bias_target = generic_powersave_bias_target;
41048+ pax_open_kernel();
41049+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
41050+ pax_close_kernel();
41051 od_set_powersave_bias(0);
41052 }
41053 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
41054diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
41055index 86631cb..c34ec78 100644
41056--- a/drivers/cpufreq/intel_pstate.c
41057+++ b/drivers/cpufreq/intel_pstate.c
41058@@ -121,10 +121,10 @@ struct pstate_funcs {
41059 struct cpu_defaults {
41060 struct pstate_adjust_policy pid_policy;
41061 struct pstate_funcs funcs;
41062-};
41063+} __do_const;
41064
41065 static struct pstate_adjust_policy pid_params;
41066-static struct pstate_funcs pstate_funcs;
41067+static struct pstate_funcs *pstate_funcs;
41068
41069 struct perf_limits {
41070 int no_turbo;
41071@@ -526,7 +526,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
41072
41073 cpu->pstate.current_pstate = pstate;
41074
41075- pstate_funcs.set(cpu, pstate);
41076+ pstate_funcs->set(cpu, pstate);
41077 }
41078
41079 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
41080@@ -546,12 +546,12 @@ static inline void intel_pstate_pstate_decrease(struct cpudata *cpu, int steps)
41081
41082 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
41083 {
41084- cpu->pstate.min_pstate = pstate_funcs.get_min();
41085- cpu->pstate.max_pstate = pstate_funcs.get_max();
41086- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
41087+ cpu->pstate.min_pstate = pstate_funcs->get_min();
41088+ cpu->pstate.max_pstate = pstate_funcs->get_max();
41089+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
41090
41091- if (pstate_funcs.get_vid)
41092- pstate_funcs.get_vid(cpu);
41093+ if (pstate_funcs->get_vid)
41094+ pstate_funcs->get_vid(cpu);
41095 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
41096 }
41097
41098@@ -838,9 +838,9 @@ static int intel_pstate_msrs_not_valid(void)
41099 rdmsrl(MSR_IA32_APERF, aperf);
41100 rdmsrl(MSR_IA32_MPERF, mperf);
41101
41102- if (!pstate_funcs.get_max() ||
41103- !pstate_funcs.get_min() ||
41104- !pstate_funcs.get_turbo())
41105+ if (!pstate_funcs->get_max() ||
41106+ !pstate_funcs->get_min() ||
41107+ !pstate_funcs->get_turbo())
41108 return -ENODEV;
41109
41110 rdmsrl(MSR_IA32_APERF, tmp);
41111@@ -854,7 +854,7 @@ static int intel_pstate_msrs_not_valid(void)
41112 return 0;
41113 }
41114
41115-static void copy_pid_params(struct pstate_adjust_policy *policy)
41116+static void copy_pid_params(const struct pstate_adjust_policy *policy)
41117 {
41118 pid_params.sample_rate_ms = policy->sample_rate_ms;
41119 pid_params.p_gain_pct = policy->p_gain_pct;
41120@@ -866,11 +866,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
41121
41122 static void copy_cpu_funcs(struct pstate_funcs *funcs)
41123 {
41124- pstate_funcs.get_max = funcs->get_max;
41125- pstate_funcs.get_min = funcs->get_min;
41126- pstate_funcs.get_turbo = funcs->get_turbo;
41127- pstate_funcs.set = funcs->set;
41128- pstate_funcs.get_vid = funcs->get_vid;
41129+ pstate_funcs = funcs;
41130 }
41131
41132 #if IS_ENABLED(CONFIG_ACPI)
41133diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
41134index 529cfd9..0e28fff 100644
41135--- a/drivers/cpufreq/p4-clockmod.c
41136+++ b/drivers/cpufreq/p4-clockmod.c
41137@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
41138 case 0x0F: /* Core Duo */
41139 case 0x16: /* Celeron Core */
41140 case 0x1C: /* Atom */
41141- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41142+ pax_open_kernel();
41143+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41144+ pax_close_kernel();
41145 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
41146 case 0x0D: /* Pentium M (Dothan) */
41147- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41148+ pax_open_kernel();
41149+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41150+ pax_close_kernel();
41151 /* fall through */
41152 case 0x09: /* Pentium M (Banias) */
41153 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
41154@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
41155
41156 /* on P-4s, the TSC runs with constant frequency independent whether
41157 * throttling is active or not. */
41158- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41159+ pax_open_kernel();
41160+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41161+ pax_close_kernel();
41162
41163 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
41164 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
41165diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
41166index 9bb42ba..b01b4a2 100644
41167--- a/drivers/cpufreq/sparc-us3-cpufreq.c
41168+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
41169@@ -18,14 +18,12 @@
41170 #include <asm/head.h>
41171 #include <asm/timer.h>
41172
41173-static struct cpufreq_driver *cpufreq_us3_driver;
41174-
41175 struct us3_freq_percpu_info {
41176 struct cpufreq_frequency_table table[4];
41177 };
41178
41179 /* Indexed by cpu number. */
41180-static struct us3_freq_percpu_info *us3_freq_table;
41181+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
41182
41183 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
41184 * in the Safari config register.
41185@@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
41186
41187 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
41188 {
41189- if (cpufreq_us3_driver)
41190- us3_freq_target(policy, 0);
41191+ us3_freq_target(policy, 0);
41192
41193 return 0;
41194 }
41195
41196+static int __init us3_freq_init(void);
41197+static void __exit us3_freq_exit(void);
41198+
41199+static struct cpufreq_driver cpufreq_us3_driver = {
41200+ .init = us3_freq_cpu_init,
41201+ .verify = cpufreq_generic_frequency_table_verify,
41202+ .target_index = us3_freq_target,
41203+ .get = us3_freq_get,
41204+ .exit = us3_freq_cpu_exit,
41205+ .name = "UltraSPARC-III",
41206+
41207+};
41208+
41209 static int __init us3_freq_init(void)
41210 {
41211 unsigned long manuf, impl, ver;
41212- int ret;
41213
41214 if (tlb_type != cheetah && tlb_type != cheetah_plus)
41215 return -ENODEV;
41216@@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
41217 (impl == CHEETAH_IMPL ||
41218 impl == CHEETAH_PLUS_IMPL ||
41219 impl == JAGUAR_IMPL ||
41220- impl == PANTHER_IMPL)) {
41221- struct cpufreq_driver *driver;
41222-
41223- ret = -ENOMEM;
41224- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
41225- if (!driver)
41226- goto err_out;
41227-
41228- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
41229- GFP_KERNEL);
41230- if (!us3_freq_table)
41231- goto err_out;
41232-
41233- driver->init = us3_freq_cpu_init;
41234- driver->verify = cpufreq_generic_frequency_table_verify;
41235- driver->target_index = us3_freq_target;
41236- driver->get = us3_freq_get;
41237- driver->exit = us3_freq_cpu_exit;
41238- strcpy(driver->name, "UltraSPARC-III");
41239-
41240- cpufreq_us3_driver = driver;
41241- ret = cpufreq_register_driver(driver);
41242- if (ret)
41243- goto err_out;
41244-
41245- return 0;
41246-
41247-err_out:
41248- if (driver) {
41249- kfree(driver);
41250- cpufreq_us3_driver = NULL;
41251- }
41252- kfree(us3_freq_table);
41253- us3_freq_table = NULL;
41254- return ret;
41255- }
41256+ impl == PANTHER_IMPL))
41257+ return cpufreq_register_driver(&cpufreq_us3_driver);
41258
41259 return -ENODEV;
41260 }
41261
41262 static void __exit us3_freq_exit(void)
41263 {
41264- if (cpufreq_us3_driver) {
41265- cpufreq_unregister_driver(cpufreq_us3_driver);
41266- kfree(cpufreq_us3_driver);
41267- cpufreq_us3_driver = NULL;
41268- kfree(us3_freq_table);
41269- us3_freq_table = NULL;
41270- }
41271+ cpufreq_unregister_driver(&cpufreq_us3_driver);
41272 }
41273
41274 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
41275diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
41276index 7d4a315..21bb886 100644
41277--- a/drivers/cpufreq/speedstep-centrino.c
41278+++ b/drivers/cpufreq/speedstep-centrino.c
41279@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
41280 !cpu_has(cpu, X86_FEATURE_EST))
41281 return -ENODEV;
41282
41283- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
41284- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
41285+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
41286+ pax_open_kernel();
41287+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
41288+ pax_close_kernel();
41289+ }
41290
41291 if (policy->cpu != 0)
41292 return -ENODEV;
41293diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
41294index 9634f20..e1499c7 100644
41295--- a/drivers/cpuidle/driver.c
41296+++ b/drivers/cpuidle/driver.c
41297@@ -205,7 +205,7 @@ static int poll_idle(struct cpuidle_device *dev,
41298
41299 static void poll_idle_init(struct cpuidle_driver *drv)
41300 {
41301- struct cpuidle_state *state = &drv->states[0];
41302+ cpuidle_state_no_const *state = &drv->states[0];
41303
41304 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
41305 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
41306diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
41307index ca89412..a7b9c49 100644
41308--- a/drivers/cpuidle/governor.c
41309+++ b/drivers/cpuidle/governor.c
41310@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
41311 mutex_lock(&cpuidle_lock);
41312 if (__cpuidle_find_governor(gov->name) == NULL) {
41313 ret = 0;
41314- list_add_tail(&gov->governor_list, &cpuidle_governors);
41315+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
41316 if (!cpuidle_curr_governor ||
41317 cpuidle_curr_governor->rating < gov->rating)
41318 cpuidle_switch_governor(gov);
41319diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
41320index efe2f17..b8124f9 100644
41321--- a/drivers/cpuidle/sysfs.c
41322+++ b/drivers/cpuidle/sysfs.c
41323@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
41324 NULL
41325 };
41326
41327-static struct attribute_group cpuidle_attr_group = {
41328+static attribute_group_no_const cpuidle_attr_group = {
41329 .attrs = cpuidle_default_attrs,
41330 .name = "cpuidle",
41331 };
41332diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
41333index 12fea3e..1e28f47 100644
41334--- a/drivers/crypto/hifn_795x.c
41335+++ b/drivers/crypto/hifn_795x.c
41336@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
41337 MODULE_PARM_DESC(hifn_pll_ref,
41338 "PLL reference clock (pci[freq] or ext[freq], default ext)");
41339
41340-static atomic_t hifn_dev_number;
41341+static atomic_unchecked_t hifn_dev_number;
41342
41343 #define ACRYPTO_OP_DECRYPT 0
41344 #define ACRYPTO_OP_ENCRYPT 1
41345@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
41346 goto err_out_disable_pci_device;
41347
41348 snprintf(name, sizeof(name), "hifn%d",
41349- atomic_inc_return(&hifn_dev_number)-1);
41350+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
41351
41352 err = pci_request_regions(pdev, name);
41353 if (err)
41354diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
41355index 9f90369..bfcacdb 100644
41356--- a/drivers/devfreq/devfreq.c
41357+++ b/drivers/devfreq/devfreq.c
41358@@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
41359 goto err_out;
41360 }
41361
41362- list_add(&governor->node, &devfreq_governor_list);
41363+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
41364
41365 list_for_each_entry(devfreq, &devfreq_list, node) {
41366 int ret = 0;
41367@@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
41368 }
41369 }
41370
41371- list_del(&governor->node);
41372+ pax_list_del((struct list_head *)&governor->node);
41373 err_out:
41374 mutex_unlock(&devfreq_list_lock);
41375
41376diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
41377index b35007e..55ad549 100644
41378--- a/drivers/dma/sh/shdma-base.c
41379+++ b/drivers/dma/sh/shdma-base.c
41380@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
41381 schan->slave_id = -EINVAL;
41382 }
41383
41384- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
41385- sdev->desc_size, GFP_KERNEL);
41386+ schan->desc = kcalloc(sdev->desc_size,
41387+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
41388 if (!schan->desc) {
41389 ret = -ENOMEM;
41390 goto edescalloc;
41391diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
41392index 146d5df..3c14970 100644
41393--- a/drivers/dma/sh/shdmac.c
41394+++ b/drivers/dma/sh/shdmac.c
41395@@ -514,7 +514,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
41396 return ret;
41397 }
41398
41399-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
41400+static struct notifier_block sh_dmae_nmi_notifier = {
41401 .notifier_call = sh_dmae_nmi_handler,
41402
41403 /* Run before NMI debug handler and KGDB */
41404diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
41405index 592af5f..bb1d583 100644
41406--- a/drivers/edac/edac_device.c
41407+++ b/drivers/edac/edac_device.c
41408@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
41409 */
41410 int edac_device_alloc_index(void)
41411 {
41412- static atomic_t device_indexes = ATOMIC_INIT(0);
41413+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
41414
41415- return atomic_inc_return(&device_indexes) - 1;
41416+ return atomic_inc_return_unchecked(&device_indexes) - 1;
41417 }
41418 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
41419
41420diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
41421index 01fae82..1dd8289 100644
41422--- a/drivers/edac/edac_mc_sysfs.c
41423+++ b/drivers/edac/edac_mc_sysfs.c
41424@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
41425 struct dev_ch_attribute {
41426 struct device_attribute attr;
41427 int channel;
41428-};
41429+} __do_const;
41430
41431 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
41432 struct dev_ch_attribute dev_attr_legacy_##_name = \
41433@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
41434 }
41435
41436 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
41437+ pax_open_kernel();
41438 if (mci->get_sdram_scrub_rate) {
41439- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
41440- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
41441+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
41442+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
41443 }
41444 if (mci->set_sdram_scrub_rate) {
41445- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
41446- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
41447+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
41448+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
41449 }
41450+ pax_close_kernel();
41451 err = device_create_file(&mci->dev,
41452 &dev_attr_sdram_scrub_rate);
41453 if (err) {
41454diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
41455index 2cf44b4d..6dd2dc7 100644
41456--- a/drivers/edac/edac_pci.c
41457+++ b/drivers/edac/edac_pci.c
41458@@ -29,7 +29,7 @@
41459
41460 static DEFINE_MUTEX(edac_pci_ctls_mutex);
41461 static LIST_HEAD(edac_pci_list);
41462-static atomic_t pci_indexes = ATOMIC_INIT(0);
41463+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
41464
41465 /*
41466 * edac_pci_alloc_ctl_info
41467@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
41468 */
41469 int edac_pci_alloc_index(void)
41470 {
41471- return atomic_inc_return(&pci_indexes) - 1;
41472+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
41473 }
41474 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
41475
41476diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
41477index e8658e4..22746d6 100644
41478--- a/drivers/edac/edac_pci_sysfs.c
41479+++ b/drivers/edac/edac_pci_sysfs.c
41480@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
41481 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
41482 static int edac_pci_poll_msec = 1000; /* one second workq period */
41483
41484-static atomic_t pci_parity_count = ATOMIC_INIT(0);
41485-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
41486+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
41487+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
41488
41489 static struct kobject *edac_pci_top_main_kobj;
41490 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
41491@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
41492 void *value;
41493 ssize_t(*show) (void *, char *);
41494 ssize_t(*store) (void *, const char *, size_t);
41495-};
41496+} __do_const;
41497
41498 /* Set of show/store abstract level functions for PCI Parity object */
41499 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
41500@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41501 edac_printk(KERN_CRIT, EDAC_PCI,
41502 "Signaled System Error on %s\n",
41503 pci_name(dev));
41504- atomic_inc(&pci_nonparity_count);
41505+ atomic_inc_unchecked(&pci_nonparity_count);
41506 }
41507
41508 if (status & (PCI_STATUS_PARITY)) {
41509@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41510 "Master Data Parity Error on %s\n",
41511 pci_name(dev));
41512
41513- atomic_inc(&pci_parity_count);
41514+ atomic_inc_unchecked(&pci_parity_count);
41515 }
41516
41517 if (status & (PCI_STATUS_DETECTED_PARITY)) {
41518@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41519 "Detected Parity Error on %s\n",
41520 pci_name(dev));
41521
41522- atomic_inc(&pci_parity_count);
41523+ atomic_inc_unchecked(&pci_parity_count);
41524 }
41525 }
41526
41527@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41528 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
41529 "Signaled System Error on %s\n",
41530 pci_name(dev));
41531- atomic_inc(&pci_nonparity_count);
41532+ atomic_inc_unchecked(&pci_nonparity_count);
41533 }
41534
41535 if (status & (PCI_STATUS_PARITY)) {
41536@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41537 "Master Data Parity Error on "
41538 "%s\n", pci_name(dev));
41539
41540- atomic_inc(&pci_parity_count);
41541+ atomic_inc_unchecked(&pci_parity_count);
41542 }
41543
41544 if (status & (PCI_STATUS_DETECTED_PARITY)) {
41545@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41546 "Detected Parity Error on %s\n",
41547 pci_name(dev));
41548
41549- atomic_inc(&pci_parity_count);
41550+ atomic_inc_unchecked(&pci_parity_count);
41551 }
41552 }
41553 }
41554@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
41555 if (!check_pci_errors)
41556 return;
41557
41558- before_count = atomic_read(&pci_parity_count);
41559+ before_count = atomic_read_unchecked(&pci_parity_count);
41560
41561 /* scan all PCI devices looking for a Parity Error on devices and
41562 * bridges.
41563@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
41564 /* Only if operator has selected panic on PCI Error */
41565 if (edac_pci_get_panic_on_pe()) {
41566 /* If the count is different 'after' from 'before' */
41567- if (before_count != atomic_read(&pci_parity_count))
41568+ if (before_count != atomic_read_unchecked(&pci_parity_count))
41569 panic("EDAC: PCI Parity Error");
41570 }
41571 }
41572diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
41573index 51b7e3a..aa8a3e8 100644
41574--- a/drivers/edac/mce_amd.h
41575+++ b/drivers/edac/mce_amd.h
41576@@ -77,7 +77,7 @@ struct amd_decoder_ops {
41577 bool (*mc0_mce)(u16, u8);
41578 bool (*mc1_mce)(u16, u8);
41579 bool (*mc2_mce)(u16, u8);
41580-};
41581+} __no_const;
41582
41583 void amd_report_gart_errors(bool);
41584 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
41585diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
41586index 57ea7f4..af06b76 100644
41587--- a/drivers/firewire/core-card.c
41588+++ b/drivers/firewire/core-card.c
41589@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
41590 const struct fw_card_driver *driver,
41591 struct device *device)
41592 {
41593- static atomic_t index = ATOMIC_INIT(-1);
41594+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
41595
41596- card->index = atomic_inc_return(&index);
41597+ card->index = atomic_inc_return_unchecked(&index);
41598 card->driver = driver;
41599 card->device = device;
41600 card->current_tlabel = 0;
41601@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
41602
41603 void fw_core_remove_card(struct fw_card *card)
41604 {
41605- struct fw_card_driver dummy_driver = dummy_driver_template;
41606+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
41607
41608 card->driver->update_phy_reg(card, 4,
41609 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
41610diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
41611index 2c6d5e1..a2cca6b 100644
41612--- a/drivers/firewire/core-device.c
41613+++ b/drivers/firewire/core-device.c
41614@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
41615 struct config_rom_attribute {
41616 struct device_attribute attr;
41617 u32 key;
41618-};
41619+} __do_const;
41620
41621 static ssize_t show_immediate(struct device *dev,
41622 struct device_attribute *dattr, char *buf)
41623diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
41624index eb6935c..3cc2bfa 100644
41625--- a/drivers/firewire/core-transaction.c
41626+++ b/drivers/firewire/core-transaction.c
41627@@ -38,6 +38,7 @@
41628 #include <linux/timer.h>
41629 #include <linux/types.h>
41630 #include <linux/workqueue.h>
41631+#include <linux/sched.h>
41632
41633 #include <asm/byteorder.h>
41634
41635diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
41636index e1480ff6..1a429bd 100644
41637--- a/drivers/firewire/core.h
41638+++ b/drivers/firewire/core.h
41639@@ -111,6 +111,7 @@ struct fw_card_driver {
41640
41641 int (*stop_iso)(struct fw_iso_context *ctx);
41642 };
41643+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
41644
41645 void fw_card_initialize(struct fw_card *card,
41646 const struct fw_card_driver *driver, struct device *device);
41647diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
41648index a66a321..f6caf20 100644
41649--- a/drivers/firewire/ohci.c
41650+++ b/drivers/firewire/ohci.c
41651@@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
41652 be32_to_cpu(ohci->next_header));
41653 }
41654
41655+#ifndef CONFIG_GRKERNSEC
41656 if (param_remote_dma) {
41657 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
41658 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
41659 }
41660+#endif
41661
41662 spin_unlock_irq(&ohci->lock);
41663
41664@@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
41665 unsigned long flags;
41666 int n, ret = 0;
41667
41668+#ifndef CONFIG_GRKERNSEC
41669 if (param_remote_dma)
41670 return 0;
41671+#endif
41672
41673 /*
41674 * FIXME: Make sure this bitmask is cleared when we clear the busReset
41675diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
41676index 94a58a0..f5eba42 100644
41677--- a/drivers/firmware/dmi-id.c
41678+++ b/drivers/firmware/dmi-id.c
41679@@ -16,7 +16,7 @@
41680 struct dmi_device_attribute{
41681 struct device_attribute dev_attr;
41682 int field;
41683-};
41684+} __do_const;
41685 #define to_dmi_dev_attr(_dev_attr) \
41686 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
41687
41688diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
41689index 17afc51..0ef90cd 100644
41690--- a/drivers/firmware/dmi_scan.c
41691+++ b/drivers/firmware/dmi_scan.c
41692@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
41693 if (buf == NULL)
41694 return -1;
41695
41696- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
41697+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
41698
41699 dmi_unmap(buf);
41700 return 0;
41701diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
41702index 1491dd4..aa910db 100644
41703--- a/drivers/firmware/efi/cper.c
41704+++ b/drivers/firmware/efi/cper.c
41705@@ -41,12 +41,12 @@
41706 */
41707 u64 cper_next_record_id(void)
41708 {
41709- static atomic64_t seq;
41710+ static atomic64_unchecked_t seq;
41711
41712- if (!atomic64_read(&seq))
41713- atomic64_set(&seq, ((u64)get_seconds()) << 32);
41714+ if (!atomic64_read_unchecked(&seq))
41715+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
41716
41717- return atomic64_inc_return(&seq);
41718+ return atomic64_inc_return_unchecked(&seq);
41719 }
41720 EXPORT_SYMBOL_GPL(cper_next_record_id);
41721
41722diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
41723index dc79346..b39bd69 100644
41724--- a/drivers/firmware/efi/efi.c
41725+++ b/drivers/firmware/efi/efi.c
41726@@ -122,14 +122,16 @@ static struct attribute_group efi_subsys_attr_group = {
41727 };
41728
41729 static struct efivars generic_efivars;
41730-static struct efivar_operations generic_ops;
41731+static efivar_operations_no_const generic_ops __read_only;
41732
41733 static int generic_ops_register(void)
41734 {
41735- generic_ops.get_variable = efi.get_variable;
41736- generic_ops.set_variable = efi.set_variable;
41737- generic_ops.get_next_variable = efi.get_next_variable;
41738- generic_ops.query_variable_store = efi_query_variable_store;
41739+ pax_open_kernel();
41740+ *(void **)&generic_ops.get_variable = efi.get_variable;
41741+ *(void **)&generic_ops.set_variable = efi.set_variable;
41742+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
41743+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
41744+ pax_close_kernel();
41745
41746 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
41747 }
41748diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
41749index 463c565..02a5640 100644
41750--- a/drivers/firmware/efi/efivars.c
41751+++ b/drivers/firmware/efi/efivars.c
41752@@ -588,7 +588,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
41753 static int
41754 create_efivars_bin_attributes(void)
41755 {
41756- struct bin_attribute *attr;
41757+ bin_attribute_no_const *attr;
41758 int error;
41759
41760 /* new_var */
41761diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
41762index 2f569aa..c95f4fb 100644
41763--- a/drivers/firmware/google/memconsole.c
41764+++ b/drivers/firmware/google/memconsole.c
41765@@ -155,7 +155,10 @@ static int __init memconsole_init(void)
41766 if (!found_memconsole())
41767 return -ENODEV;
41768
41769- memconsole_bin_attr.size = memconsole_length;
41770+ pax_open_kernel();
41771+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
41772+ pax_close_kernel();
41773+
41774 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
41775 }
41776
41777diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
41778index cde3605..8b69df7 100644
41779--- a/drivers/gpio/gpio-em.c
41780+++ b/drivers/gpio/gpio-em.c
41781@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
41782 struct em_gio_priv *p;
41783 struct resource *io[2], *irq[2];
41784 struct gpio_chip *gpio_chip;
41785- struct irq_chip *irq_chip;
41786+ irq_chip_no_const *irq_chip;
41787 const char *name = dev_name(&pdev->dev);
41788 int ret;
41789
41790diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
41791index 7030422..42a3fe9 100644
41792--- a/drivers/gpio/gpio-ich.c
41793+++ b/drivers/gpio/gpio-ich.c
41794@@ -94,7 +94,7 @@ struct ichx_desc {
41795 * this option allows driver caching written output values
41796 */
41797 bool use_outlvl_cache;
41798-};
41799+} __do_const;
41800
41801 static struct {
41802 spinlock_t lock;
41803diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
41804index b6ae89e..ac7349c 100644
41805--- a/drivers/gpio/gpio-rcar.c
41806+++ b/drivers/gpio/gpio-rcar.c
41807@@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
41808 struct gpio_rcar_priv *p;
41809 struct resource *io, *irq;
41810 struct gpio_chip *gpio_chip;
41811- struct irq_chip *irq_chip;
41812+ irq_chip_no_const *irq_chip;
41813 struct device *dev = &pdev->dev;
41814 const char *name = dev_name(dev);
41815 int ret;
41816diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
41817index 66cbcc1..0c5e622 100644
41818--- a/drivers/gpio/gpio-vr41xx.c
41819+++ b/drivers/gpio/gpio-vr41xx.c
41820@@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
41821 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
41822 maskl, pendl, maskh, pendh);
41823
41824- atomic_inc(&irq_err_count);
41825+ atomic_inc_unchecked(&irq_err_count);
41826
41827 return -EINVAL;
41828 }
41829diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
41830index 2ebc907..01bdd6e 100644
41831--- a/drivers/gpio/gpiolib.c
41832+++ b/drivers/gpio/gpiolib.c
41833@@ -1482,8 +1482,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
41834 }
41835
41836 if (gpiochip->irqchip) {
41837- gpiochip->irqchip->irq_request_resources = NULL;
41838- gpiochip->irqchip->irq_release_resources = NULL;
41839+ pax_open_kernel();
41840+ *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
41841+ *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
41842+ pax_close_kernel();
41843 gpiochip->irqchip = NULL;
41844 }
41845 }
41846@@ -1549,8 +1551,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
41847 gpiochip->irqchip = NULL;
41848 return -EINVAL;
41849 }
41850- irqchip->irq_request_resources = gpiochip_irq_reqres;
41851- irqchip->irq_release_resources = gpiochip_irq_relres;
41852+
41853+ pax_open_kernel();
41854+ *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
41855+ *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
41856+ pax_close_kernel();
41857
41858 /*
41859 * Prepare the mapping since the irqchip shall be orthogonal to
41860diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
41861index fe94cc1..5e697b3 100644
41862--- a/drivers/gpu/drm/drm_crtc.c
41863+++ b/drivers/gpu/drm/drm_crtc.c
41864@@ -3584,7 +3584,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
41865 goto done;
41866 }
41867
41868- if (copy_to_user(&enum_ptr[copied].name,
41869+ if (copy_to_user(enum_ptr[copied].name,
41870 &prop_enum->name, DRM_PROP_NAME_LEN)) {
41871 ret = -EFAULT;
41872 goto done;
41873diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
41874index 8218078..9960928a 100644
41875--- a/drivers/gpu/drm/drm_drv.c
41876+++ b/drivers/gpu/drm/drm_drv.c
41877@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
41878 /**
41879 * Copy and IOCTL return string to user space
41880 */
41881-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
41882+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
41883 {
41884 int len;
41885
41886@@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
41887 struct drm_file *file_priv = filp->private_data;
41888 struct drm_device *dev;
41889 const struct drm_ioctl_desc *ioctl = NULL;
41890- drm_ioctl_t *func;
41891+ drm_ioctl_no_const_t func;
41892 unsigned int nr = DRM_IOCTL_NR(cmd);
41893 int retcode = -EINVAL;
41894 char stack_kdata[128];
41895diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
41896index 021fe5d..abc9ce6 100644
41897--- a/drivers/gpu/drm/drm_fops.c
41898+++ b/drivers/gpu/drm/drm_fops.c
41899@@ -88,7 +88,7 @@ int drm_open(struct inode *inode, struct file *filp)
41900 return PTR_ERR(minor);
41901
41902 dev = minor->dev;
41903- if (!dev->open_count++)
41904+ if (local_inc_return(&dev->open_count) == 1)
41905 need_setup = 1;
41906
41907 /* share address_space across all char-devs of a single device */
41908@@ -105,7 +105,7 @@ int drm_open(struct inode *inode, struct file *filp)
41909 return 0;
41910
41911 err_undo:
41912- dev->open_count--;
41913+ local_dec(&dev->open_count);
41914 drm_minor_release(minor);
41915 return retcode;
41916 }
41917@@ -427,7 +427,7 @@ int drm_release(struct inode *inode, struct file *filp)
41918
41919 mutex_lock(&drm_global_mutex);
41920
41921- DRM_DEBUG("open_count = %d\n", dev->open_count);
41922+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
41923
41924 if (dev->driver->preclose)
41925 dev->driver->preclose(dev, file_priv);
41926@@ -436,10 +436,10 @@ int drm_release(struct inode *inode, struct file *filp)
41927 * Begin inline drm_release
41928 */
41929
41930- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
41931+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
41932 task_pid_nr(current),
41933 (long)old_encode_dev(file_priv->minor->kdev->devt),
41934- dev->open_count);
41935+ local_read(&dev->open_count));
41936
41937 /* Release any auth tokens that might point to this file_priv,
41938 (do that under the drm_global_mutex) */
41939@@ -540,7 +540,7 @@ int drm_release(struct inode *inode, struct file *filp)
41940 * End inline drm_release
41941 */
41942
41943- if (!--dev->open_count) {
41944+ if (local_dec_and_test(&dev->open_count)) {
41945 retcode = drm_lastclose(dev);
41946 if (drm_device_is_unplugged(dev))
41947 drm_put_dev(dev);
41948diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
41949index 3d2e91c..d31c4c9 100644
41950--- a/drivers/gpu/drm/drm_global.c
41951+++ b/drivers/gpu/drm/drm_global.c
41952@@ -36,7 +36,7 @@
41953 struct drm_global_item {
41954 struct mutex mutex;
41955 void *object;
41956- int refcount;
41957+ atomic_t refcount;
41958 };
41959
41960 static struct drm_global_item glob[DRM_GLOBAL_NUM];
41961@@ -49,7 +49,7 @@ void drm_global_init(void)
41962 struct drm_global_item *item = &glob[i];
41963 mutex_init(&item->mutex);
41964 item->object = NULL;
41965- item->refcount = 0;
41966+ atomic_set(&item->refcount, 0);
41967 }
41968 }
41969
41970@@ -59,7 +59,7 @@ void drm_global_release(void)
41971 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
41972 struct drm_global_item *item = &glob[i];
41973 BUG_ON(item->object != NULL);
41974- BUG_ON(item->refcount != 0);
41975+ BUG_ON(atomic_read(&item->refcount) != 0);
41976 }
41977 }
41978
41979@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41980 struct drm_global_item *item = &glob[ref->global_type];
41981
41982 mutex_lock(&item->mutex);
41983- if (item->refcount == 0) {
41984+ if (atomic_read(&item->refcount) == 0) {
41985 item->object = kzalloc(ref->size, GFP_KERNEL);
41986 if (unlikely(item->object == NULL)) {
41987 ret = -ENOMEM;
41988@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41989 goto out_err;
41990
41991 }
41992- ++item->refcount;
41993+ atomic_inc(&item->refcount);
41994 ref->object = item->object;
41995 mutex_unlock(&item->mutex);
41996 return 0;
41997@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
41998 struct drm_global_item *item = &glob[ref->global_type];
41999
42000 mutex_lock(&item->mutex);
42001- BUG_ON(item->refcount == 0);
42002+ BUG_ON(atomic_read(&item->refcount) == 0);
42003 BUG_ON(ref->object != item->object);
42004- if (--item->refcount == 0) {
42005+ if (atomic_dec_and_test(&item->refcount)) {
42006 ref->release(ref);
42007 item->object = NULL;
42008 }
42009diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
42010index 86feedd..cba70f5 100644
42011--- a/drivers/gpu/drm/drm_info.c
42012+++ b/drivers/gpu/drm/drm_info.c
42013@@ -73,10 +73,13 @@ int drm_vm_info(struct seq_file *m, void *data)
42014 struct drm_local_map *map;
42015 struct drm_map_list *r_list;
42016
42017- /* Hardcoded from _DRM_FRAME_BUFFER,
42018- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
42019- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
42020- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
42021+ static const char * const types[] = {
42022+ [_DRM_FRAME_BUFFER] = "FB",
42023+ [_DRM_REGISTERS] = "REG",
42024+ [_DRM_SHM] = "SHM",
42025+ [_DRM_AGP] = "AGP",
42026+ [_DRM_SCATTER_GATHER] = "SG",
42027+ [_DRM_CONSISTENT] = "PCI"};
42028 const char *type;
42029 int i;
42030
42031@@ -87,7 +90,7 @@ int drm_vm_info(struct seq_file *m, void *data)
42032 map = r_list->map;
42033 if (!map)
42034 continue;
42035- if (map->type < 0 || map->type > 5)
42036+ if (map->type >= ARRAY_SIZE(types))
42037 type = "??";
42038 else
42039 type = types[map->type];
42040@@ -259,7 +262,11 @@ int drm_vma_info(struct seq_file *m, void *data)
42041 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
42042 vma->vm_flags & VM_LOCKED ? 'l' : '-',
42043 vma->vm_flags & VM_IO ? 'i' : '-',
42044+#ifdef CONFIG_GRKERNSEC_HIDESYM
42045+ 0);
42046+#else
42047 vma->vm_pgoff);
42048+#endif
42049
42050 #if defined(__i386__)
42051 pgprot = pgprot_val(vma->vm_page_prot);
42052diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
42053index 2f4c4343..dd12cd2 100644
42054--- a/drivers/gpu/drm/drm_ioc32.c
42055+++ b/drivers/gpu/drm/drm_ioc32.c
42056@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
42057 request = compat_alloc_user_space(nbytes);
42058 if (!access_ok(VERIFY_WRITE, request, nbytes))
42059 return -EFAULT;
42060- list = (struct drm_buf_desc *) (request + 1);
42061+ list = (struct drm_buf_desc __user *) (request + 1);
42062
42063 if (__put_user(count, &request->count)
42064 || __put_user(list, &request->list))
42065@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
42066 request = compat_alloc_user_space(nbytes);
42067 if (!access_ok(VERIFY_WRITE, request, nbytes))
42068 return -EFAULT;
42069- list = (struct drm_buf_pub *) (request + 1);
42070+ list = (struct drm_buf_pub __user *) (request + 1);
42071
42072 if (__put_user(count, &request->count)
42073 || __put_user(list, &request->list))
42074@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
42075 return 0;
42076 }
42077
42078-drm_ioctl_compat_t *drm_compat_ioctls[] = {
42079+drm_ioctl_compat_t drm_compat_ioctls[] = {
42080 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
42081 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
42082 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
42083@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
42084 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42085 {
42086 unsigned int nr = DRM_IOCTL_NR(cmd);
42087- drm_ioctl_compat_t *fn;
42088 int ret;
42089
42090 /* Assume that ioctls without an explicit compat routine will just
42091@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42092 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
42093 return drm_ioctl(filp, cmd, arg);
42094
42095- fn = drm_compat_ioctls[nr];
42096-
42097- if (fn != NULL)
42098- ret = (*fn) (filp, cmd, arg);
42099+ if (drm_compat_ioctls[nr] != NULL)
42100+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
42101 else
42102 ret = drm_ioctl(filp, cmd, arg);
42103
42104diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
42105index 14d1646..99f9d49 100644
42106--- a/drivers/gpu/drm/drm_stub.c
42107+++ b/drivers/gpu/drm/drm_stub.c
42108@@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
42109
42110 drm_device_set_unplugged(dev);
42111
42112- if (dev->open_count == 0) {
42113+ if (local_read(&dev->open_count) == 0) {
42114 drm_put_dev(dev);
42115 }
42116 mutex_unlock(&drm_global_mutex);
42117diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
42118index 369b262..09ea3ab 100644
42119--- a/drivers/gpu/drm/drm_sysfs.c
42120+++ b/drivers/gpu/drm/drm_sysfs.c
42121@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
42122 */
42123 int drm_sysfs_device_add(struct drm_minor *minor)
42124 {
42125- char *minor_str;
42126+ const char *minor_str;
42127 int r;
42128
42129 if (minor->type == DRM_MINOR_CONTROL)
42130diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
42131index d4d16ed..8fb0b51 100644
42132--- a/drivers/gpu/drm/i810/i810_drv.h
42133+++ b/drivers/gpu/drm/i810/i810_drv.h
42134@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
42135 int page_flipping;
42136
42137 wait_queue_head_t irq_queue;
42138- atomic_t irq_received;
42139- atomic_t irq_emitted;
42140+ atomic_unchecked_t irq_received;
42141+ atomic_unchecked_t irq_emitted;
42142
42143 int front_offset;
42144 } drm_i810_private_t;
42145diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
42146index d443441..ab091dd 100644
42147--- a/drivers/gpu/drm/i915/i915_dma.c
42148+++ b/drivers/gpu/drm/i915/i915_dma.c
42149@@ -1290,7 +1290,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
42150 * locking inversion with the driver load path. And the access here is
42151 * completely racy anyway. So don't bother with locking for now.
42152 */
42153- return dev->open_count == 0;
42154+ return local_read(&dev->open_count) == 0;
42155 }
42156
42157 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
42158diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
42159index 3a30133..ef4a743 100644
42160--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
42161+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
42162@@ -891,9 +891,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
42163
42164 static int
42165 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
42166- int count)
42167+ unsigned int count)
42168 {
42169- int i;
42170+ unsigned int i;
42171 unsigned relocs_total = 0;
42172 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
42173
42174diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
42175index 2e0613e..a8b94d9 100644
42176--- a/drivers/gpu/drm/i915/i915_ioc32.c
42177+++ b/drivers/gpu/drm/i915/i915_ioc32.c
42178@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
42179 (unsigned long)request);
42180 }
42181
42182-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
42183+static drm_ioctl_compat_t i915_compat_ioctls[] = {
42184 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
42185 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
42186 [DRM_I915_GETPARAM] = compat_i915_getparam,
42187@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
42188 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42189 {
42190 unsigned int nr = DRM_IOCTL_NR(cmd);
42191- drm_ioctl_compat_t *fn = NULL;
42192 int ret;
42193
42194 if (nr < DRM_COMMAND_BASE)
42195 return drm_compat_ioctl(filp, cmd, arg);
42196
42197- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
42198- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
42199-
42200- if (fn != NULL)
42201+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
42202+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
42203 ret = (*fn) (filp, cmd, arg);
42204- else
42205+ } else
42206 ret = drm_ioctl(filp, cmd, arg);
42207
42208 return ret;
42209diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
42210index f0be855..94e82d9 100644
42211--- a/drivers/gpu/drm/i915/intel_display.c
42212+++ b/drivers/gpu/drm/i915/intel_display.c
42213@@ -11604,13 +11604,13 @@ struct intel_quirk {
42214 int subsystem_vendor;
42215 int subsystem_device;
42216 void (*hook)(struct drm_device *dev);
42217-};
42218+} __do_const;
42219
42220 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
42221 struct intel_dmi_quirk {
42222 void (*hook)(struct drm_device *dev);
42223 const struct dmi_system_id (*dmi_id_list)[];
42224-};
42225+} __do_const;
42226
42227 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
42228 {
42229@@ -11618,18 +11618,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
42230 return 1;
42231 }
42232
42233-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
42234+static const struct dmi_system_id intel_dmi_quirks_table[] = {
42235 {
42236- .dmi_id_list = &(const struct dmi_system_id[]) {
42237- {
42238- .callback = intel_dmi_reverse_brightness,
42239- .ident = "NCR Corporation",
42240- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
42241- DMI_MATCH(DMI_PRODUCT_NAME, ""),
42242- },
42243- },
42244- { } /* terminating entry */
42245+ .callback = intel_dmi_reverse_brightness,
42246+ .ident = "NCR Corporation",
42247+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
42248+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
42249 },
42250+ },
42251+ { } /* terminating entry */
42252+};
42253+
42254+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
42255+ {
42256+ .dmi_id_list = &intel_dmi_quirks_table,
42257 .hook = quirk_invert_brightness,
42258 },
42259 };
42260diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
42261index fe45321..836fdca 100644
42262--- a/drivers/gpu/drm/mga/mga_drv.h
42263+++ b/drivers/gpu/drm/mga/mga_drv.h
42264@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
42265 u32 clear_cmd;
42266 u32 maccess;
42267
42268- atomic_t vbl_received; /**< Number of vblanks received. */
42269+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
42270 wait_queue_head_t fence_queue;
42271- atomic_t last_fence_retired;
42272+ atomic_unchecked_t last_fence_retired;
42273 u32 next_fence_to_post;
42274
42275 unsigned int fb_cpp;
42276diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
42277index 729bfd5..ead8823 100644
42278--- a/drivers/gpu/drm/mga/mga_ioc32.c
42279+++ b/drivers/gpu/drm/mga/mga_ioc32.c
42280@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
42281 return 0;
42282 }
42283
42284-drm_ioctl_compat_t *mga_compat_ioctls[] = {
42285+drm_ioctl_compat_t mga_compat_ioctls[] = {
42286 [DRM_MGA_INIT] = compat_mga_init,
42287 [DRM_MGA_GETPARAM] = compat_mga_getparam,
42288 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
42289@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
42290 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42291 {
42292 unsigned int nr = DRM_IOCTL_NR(cmd);
42293- drm_ioctl_compat_t *fn = NULL;
42294 int ret;
42295
42296 if (nr < DRM_COMMAND_BASE)
42297 return drm_compat_ioctl(filp, cmd, arg);
42298
42299- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
42300- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
42301-
42302- if (fn != NULL)
42303+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
42304+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
42305 ret = (*fn) (filp, cmd, arg);
42306- else
42307+ } else
42308 ret = drm_ioctl(filp, cmd, arg);
42309
42310 return ret;
42311diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
42312index 1b071b8..de8601a 100644
42313--- a/drivers/gpu/drm/mga/mga_irq.c
42314+++ b/drivers/gpu/drm/mga/mga_irq.c
42315@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
42316 if (crtc != 0)
42317 return 0;
42318
42319- return atomic_read(&dev_priv->vbl_received);
42320+ return atomic_read_unchecked(&dev_priv->vbl_received);
42321 }
42322
42323
42324@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
42325 /* VBLANK interrupt */
42326 if (status & MGA_VLINEPEN) {
42327 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
42328- atomic_inc(&dev_priv->vbl_received);
42329+ atomic_inc_unchecked(&dev_priv->vbl_received);
42330 drm_handle_vblank(dev, 0);
42331 handled = 1;
42332 }
42333@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
42334 if ((prim_start & ~0x03) != (prim_end & ~0x03))
42335 MGA_WRITE(MGA_PRIMEND, prim_end);
42336
42337- atomic_inc(&dev_priv->last_fence_retired);
42338+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
42339 wake_up(&dev_priv->fence_queue);
42340 handled = 1;
42341 }
42342@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
42343 * using fences.
42344 */
42345 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
42346- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
42347+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
42348 - *sequence) <= (1 << 23)));
42349
42350 *sequence = cur_fence;
42351diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
42352index 8268a4c..5105708 100644
42353--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
42354+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
42355@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
42356 struct bit_table {
42357 const char id;
42358 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
42359-};
42360+} __no_const;
42361
42362 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
42363
42364diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
42365index 7efbafa..19f8087 100644
42366--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
42367+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
42368@@ -97,7 +97,6 @@ struct nouveau_drm {
42369 struct drm_global_reference mem_global_ref;
42370 struct ttm_bo_global_ref bo_global_ref;
42371 struct ttm_bo_device bdev;
42372- atomic_t validate_sequence;
42373 int (*move)(struct nouveau_channel *,
42374 struct ttm_buffer_object *,
42375 struct ttm_mem_reg *, struct ttm_mem_reg *);
42376diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
42377index 462679a..88e32a7 100644
42378--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
42379+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
42380@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
42381 unsigned long arg)
42382 {
42383 unsigned int nr = DRM_IOCTL_NR(cmd);
42384- drm_ioctl_compat_t *fn = NULL;
42385+ drm_ioctl_compat_t fn = NULL;
42386 int ret;
42387
42388 if (nr < DRM_COMMAND_BASE)
42389diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
42390index ab0228f..20b756b 100644
42391--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
42392+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
42393@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
42394 }
42395
42396 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
42397- nouveau_vram_manager_init,
42398- nouveau_vram_manager_fini,
42399- nouveau_vram_manager_new,
42400- nouveau_vram_manager_del,
42401- nouveau_vram_manager_debug
42402+ .init = nouveau_vram_manager_init,
42403+ .takedown = nouveau_vram_manager_fini,
42404+ .get_node = nouveau_vram_manager_new,
42405+ .put_node = nouveau_vram_manager_del,
42406+ .debug = nouveau_vram_manager_debug
42407 };
42408
42409 static int
42410@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
42411 }
42412
42413 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
42414- nouveau_gart_manager_init,
42415- nouveau_gart_manager_fini,
42416- nouveau_gart_manager_new,
42417- nouveau_gart_manager_del,
42418- nouveau_gart_manager_debug
42419+ .init = nouveau_gart_manager_init,
42420+ .takedown = nouveau_gart_manager_fini,
42421+ .get_node = nouveau_gart_manager_new,
42422+ .put_node = nouveau_gart_manager_del,
42423+ .debug = nouveau_gart_manager_debug
42424 };
42425
42426 #include <core/subdev/vm/nv04.h>
42427@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
42428 }
42429
42430 const struct ttm_mem_type_manager_func nv04_gart_manager = {
42431- nv04_gart_manager_init,
42432- nv04_gart_manager_fini,
42433- nv04_gart_manager_new,
42434- nv04_gart_manager_del,
42435- nv04_gart_manager_debug
42436+ .init = nv04_gart_manager_init,
42437+ .takedown = nv04_gart_manager_fini,
42438+ .get_node = nv04_gart_manager_new,
42439+ .put_node = nv04_gart_manager_del,
42440+ .debug = nv04_gart_manager_debug
42441 };
42442
42443 int
42444diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
42445index 4f4c3fe..2cce716 100644
42446--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
42447+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
42448@@ -70,7 +70,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
42449 * locking inversion with the driver load path. And the access here is
42450 * completely racy anyway. So don't bother with locking for now.
42451 */
42452- return dev->open_count == 0;
42453+ return local_read(&dev->open_count) == 0;
42454 }
42455
42456 static const struct vga_switcheroo_client_ops
42457diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
42458index eb89653..613cf71 100644
42459--- a/drivers/gpu/drm/qxl/qxl_cmd.c
42460+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
42461@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
42462 int ret;
42463
42464 mutex_lock(&qdev->async_io_mutex);
42465- irq_num = atomic_read(&qdev->irq_received_io_cmd);
42466+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
42467 if (qdev->last_sent_io_cmd > irq_num) {
42468 if (intr)
42469 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
42470- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42471+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42472 else
42473 ret = wait_event_timeout(qdev->io_cmd_event,
42474- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42475+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42476 /* 0 is timeout, just bail the "hw" has gone away */
42477 if (ret <= 0)
42478 goto out;
42479- irq_num = atomic_read(&qdev->irq_received_io_cmd);
42480+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
42481 }
42482 outb(val, addr);
42483 qdev->last_sent_io_cmd = irq_num + 1;
42484 if (intr)
42485 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
42486- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42487+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42488 else
42489 ret = wait_event_timeout(qdev->io_cmd_event,
42490- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42491+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42492 out:
42493 if (ret > 0)
42494 ret = 0;
42495diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
42496index c3c2bbd..bc3c0fb 100644
42497--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
42498+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
42499@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
42500 struct drm_info_node *node = (struct drm_info_node *) m->private;
42501 struct qxl_device *qdev = node->minor->dev->dev_private;
42502
42503- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
42504- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
42505- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
42506- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
42507+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
42508+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
42509+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
42510+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
42511 seq_printf(m, "%d\n", qdev->irq_received_error);
42512 return 0;
42513 }
42514diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
42515index 36ed40b..0397633 100644
42516--- a/drivers/gpu/drm/qxl/qxl_drv.h
42517+++ b/drivers/gpu/drm/qxl/qxl_drv.h
42518@@ -290,10 +290,10 @@ struct qxl_device {
42519 unsigned int last_sent_io_cmd;
42520
42521 /* interrupt handling */
42522- atomic_t irq_received;
42523- atomic_t irq_received_display;
42524- atomic_t irq_received_cursor;
42525- atomic_t irq_received_io_cmd;
42526+ atomic_unchecked_t irq_received;
42527+ atomic_unchecked_t irq_received_display;
42528+ atomic_unchecked_t irq_received_cursor;
42529+ atomic_unchecked_t irq_received_io_cmd;
42530 unsigned irq_received_error;
42531 wait_queue_head_t display_event;
42532 wait_queue_head_t cursor_event;
42533diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
42534index b110883..dd06418 100644
42535--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
42536+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
42537@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
42538
42539 /* TODO copy slow path code from i915 */
42540 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
42541- unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void *)(unsigned long)cmd->command, cmd->command_size);
42542+ unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void __force_user *)(unsigned long)cmd->command, cmd->command_size);
42543
42544 {
42545 struct qxl_drawable *draw = fb_cmd;
42546@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
42547 struct drm_qxl_reloc reloc;
42548
42549 if (copy_from_user(&reloc,
42550- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
42551+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
42552 sizeof(reloc))) {
42553 ret = -EFAULT;
42554 goto out_free_bos;
42555@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
42556
42557 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
42558
42559- struct drm_qxl_command *commands =
42560- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
42561+ struct drm_qxl_command __user *commands =
42562+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
42563
42564- if (copy_from_user(&user_cmd, &commands[cmd_num],
42565+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
42566 sizeof(user_cmd)))
42567 return -EFAULT;
42568
42569diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
42570index 0bf1e20..42a7310 100644
42571--- a/drivers/gpu/drm/qxl/qxl_irq.c
42572+++ b/drivers/gpu/drm/qxl/qxl_irq.c
42573@@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
42574 if (!pending)
42575 return IRQ_NONE;
42576
42577- atomic_inc(&qdev->irq_received);
42578+ atomic_inc_unchecked(&qdev->irq_received);
42579
42580 if (pending & QXL_INTERRUPT_DISPLAY) {
42581- atomic_inc(&qdev->irq_received_display);
42582+ atomic_inc_unchecked(&qdev->irq_received_display);
42583 wake_up_all(&qdev->display_event);
42584 qxl_queue_garbage_collect(qdev, false);
42585 }
42586 if (pending & QXL_INTERRUPT_CURSOR) {
42587- atomic_inc(&qdev->irq_received_cursor);
42588+ atomic_inc_unchecked(&qdev->irq_received_cursor);
42589 wake_up_all(&qdev->cursor_event);
42590 }
42591 if (pending & QXL_INTERRUPT_IO_CMD) {
42592- atomic_inc(&qdev->irq_received_io_cmd);
42593+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
42594 wake_up_all(&qdev->io_cmd_event);
42595 }
42596 if (pending & QXL_INTERRUPT_ERROR) {
42597@@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
42598 init_waitqueue_head(&qdev->io_cmd_event);
42599 INIT_WORK(&qdev->client_monitors_config_work,
42600 qxl_client_monitors_config_work_func);
42601- atomic_set(&qdev->irq_received, 0);
42602- atomic_set(&qdev->irq_received_display, 0);
42603- atomic_set(&qdev->irq_received_cursor, 0);
42604- atomic_set(&qdev->irq_received_io_cmd, 0);
42605+ atomic_set_unchecked(&qdev->irq_received, 0);
42606+ atomic_set_unchecked(&qdev->irq_received_display, 0);
42607+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
42608+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
42609 qdev->irq_received_error = 0;
42610 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
42611 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
42612diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
42613index 71a1bae..cb1f103 100644
42614--- a/drivers/gpu/drm/qxl/qxl_ttm.c
42615+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
42616@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
42617 }
42618 }
42619
42620-static struct vm_operations_struct qxl_ttm_vm_ops;
42621+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
42622 static const struct vm_operations_struct *ttm_vm_ops;
42623
42624 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42625@@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
42626 return r;
42627 if (unlikely(ttm_vm_ops == NULL)) {
42628 ttm_vm_ops = vma->vm_ops;
42629+ pax_open_kernel();
42630 qxl_ttm_vm_ops = *ttm_vm_ops;
42631 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
42632+ pax_close_kernel();
42633 }
42634 vma->vm_ops = &qxl_ttm_vm_ops;
42635 return 0;
42636@@ -555,25 +557,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
42637 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
42638 {
42639 #if defined(CONFIG_DEBUG_FS)
42640- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
42641- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
42642- unsigned i;
42643+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
42644+ {
42645+ .name = "qxl_mem_mm",
42646+ .show = &qxl_mm_dump_table,
42647+ },
42648+ {
42649+ .name = "qxl_surf_mm",
42650+ .show = &qxl_mm_dump_table,
42651+ }
42652+ };
42653
42654- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
42655- if (i == 0)
42656- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
42657- else
42658- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
42659- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
42660- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
42661- qxl_mem_types_list[i].driver_features = 0;
42662- if (i == 0)
42663- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
42664- else
42665- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
42666+ pax_open_kernel();
42667+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
42668+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
42669+ pax_close_kernel();
42670
42671- }
42672- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
42673+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
42674 #else
42675 return 0;
42676 #endif
42677diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
42678index 59459fe..be26b31 100644
42679--- a/drivers/gpu/drm/r128/r128_cce.c
42680+++ b/drivers/gpu/drm/r128/r128_cce.c
42681@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
42682
42683 /* GH: Simple idle check.
42684 */
42685- atomic_set(&dev_priv->idle_count, 0);
42686+ atomic_set_unchecked(&dev_priv->idle_count, 0);
42687
42688 /* We don't support anything other than bus-mastering ring mode,
42689 * but the ring can be in either AGP or PCI space for the ring
42690diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
42691index 5bf3f5f..7000661 100644
42692--- a/drivers/gpu/drm/r128/r128_drv.h
42693+++ b/drivers/gpu/drm/r128/r128_drv.h
42694@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
42695 int is_pci;
42696 unsigned long cce_buffers_offset;
42697
42698- atomic_t idle_count;
42699+ atomic_unchecked_t idle_count;
42700
42701 int page_flipping;
42702 int current_page;
42703 u32 crtc_offset;
42704 u32 crtc_offset_cntl;
42705
42706- atomic_t vbl_received;
42707+ atomic_unchecked_t vbl_received;
42708
42709 u32 color_fmt;
42710 unsigned int front_offset;
42711diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
42712index 663f38c..c689495 100644
42713--- a/drivers/gpu/drm/r128/r128_ioc32.c
42714+++ b/drivers/gpu/drm/r128/r128_ioc32.c
42715@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
42716 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
42717 }
42718
42719-drm_ioctl_compat_t *r128_compat_ioctls[] = {
42720+drm_ioctl_compat_t r128_compat_ioctls[] = {
42721 [DRM_R128_INIT] = compat_r128_init,
42722 [DRM_R128_DEPTH] = compat_r128_depth,
42723 [DRM_R128_STIPPLE] = compat_r128_stipple,
42724@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
42725 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42726 {
42727 unsigned int nr = DRM_IOCTL_NR(cmd);
42728- drm_ioctl_compat_t *fn = NULL;
42729 int ret;
42730
42731 if (nr < DRM_COMMAND_BASE)
42732 return drm_compat_ioctl(filp, cmd, arg);
42733
42734- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
42735- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
42736-
42737- if (fn != NULL)
42738+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
42739+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
42740 ret = (*fn) (filp, cmd, arg);
42741- else
42742+ } else
42743 ret = drm_ioctl(filp, cmd, arg);
42744
42745 return ret;
42746diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
42747index c2ae496..30b5993 100644
42748--- a/drivers/gpu/drm/r128/r128_irq.c
42749+++ b/drivers/gpu/drm/r128/r128_irq.c
42750@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
42751 if (crtc != 0)
42752 return 0;
42753
42754- return atomic_read(&dev_priv->vbl_received);
42755+ return atomic_read_unchecked(&dev_priv->vbl_received);
42756 }
42757
42758 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42759@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42760 /* VBLANK interrupt */
42761 if (status & R128_CRTC_VBLANK_INT) {
42762 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
42763- atomic_inc(&dev_priv->vbl_received);
42764+ atomic_inc_unchecked(&dev_priv->vbl_received);
42765 drm_handle_vblank(dev, 0);
42766 return IRQ_HANDLED;
42767 }
42768diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
42769index 575e986..66e62ca 100644
42770--- a/drivers/gpu/drm/r128/r128_state.c
42771+++ b/drivers/gpu/drm/r128/r128_state.c
42772@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
42773
42774 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
42775 {
42776- if (atomic_read(&dev_priv->idle_count) == 0)
42777+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
42778 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
42779 else
42780- atomic_set(&dev_priv->idle_count, 0);
42781+ atomic_set_unchecked(&dev_priv->idle_count, 0);
42782 }
42783
42784 #endif
42785diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
42786index 4a85bb6..aaea819 100644
42787--- a/drivers/gpu/drm/radeon/mkregtable.c
42788+++ b/drivers/gpu/drm/radeon/mkregtable.c
42789@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
42790 regex_t mask_rex;
42791 regmatch_t match[4];
42792 char buf[1024];
42793- size_t end;
42794+ long end;
42795 int len;
42796 int done = 0;
42797 int r;
42798 unsigned o;
42799 struct offset *offset;
42800 char last_reg_s[10];
42801- int last_reg;
42802+ unsigned long last_reg;
42803
42804 if (regcomp
42805 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
42806diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
42807index 697add2..9860f5b 100644
42808--- a/drivers/gpu/drm/radeon/radeon_device.c
42809+++ b/drivers/gpu/drm/radeon/radeon_device.c
42810@@ -1169,7 +1169,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
42811 * locking inversion with the driver load path. And the access here is
42812 * completely racy anyway. So don't bother with locking for now.
42813 */
42814- return dev->open_count == 0;
42815+ return local_read(&dev->open_count) == 0;
42816 }
42817
42818 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
42819diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
42820index dafd812..1bf20c7 100644
42821--- a/drivers/gpu/drm/radeon/radeon_drv.h
42822+++ b/drivers/gpu/drm/radeon/radeon_drv.h
42823@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
42824
42825 /* SW interrupt */
42826 wait_queue_head_t swi_queue;
42827- atomic_t swi_emitted;
42828+ atomic_unchecked_t swi_emitted;
42829 int vblank_crtc;
42830 uint32_t irq_enable_reg;
42831 uint32_t r500_disp_irq_reg;
42832diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
42833index 0b98ea1..0881827 100644
42834--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
42835+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
42836@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42837 request = compat_alloc_user_space(sizeof(*request));
42838 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
42839 || __put_user(req32.param, &request->param)
42840- || __put_user((void __user *)(unsigned long)req32.value,
42841+ || __put_user((unsigned long)req32.value,
42842 &request->value))
42843 return -EFAULT;
42844
42845@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42846 #define compat_radeon_cp_setparam NULL
42847 #endif /* X86_64 || IA64 */
42848
42849-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42850+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
42851 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
42852 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
42853 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
42854@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42855 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42856 {
42857 unsigned int nr = DRM_IOCTL_NR(cmd);
42858- drm_ioctl_compat_t *fn = NULL;
42859 int ret;
42860
42861 if (nr < DRM_COMMAND_BASE)
42862 return drm_compat_ioctl(filp, cmd, arg);
42863
42864- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
42865- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42866-
42867- if (fn != NULL)
42868+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
42869+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42870 ret = (*fn) (filp, cmd, arg);
42871- else
42872+ } else
42873 ret = drm_ioctl(filp, cmd, arg);
42874
42875 return ret;
42876diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
42877index 244b19b..c19226d 100644
42878--- a/drivers/gpu/drm/radeon/radeon_irq.c
42879+++ b/drivers/gpu/drm/radeon/radeon_irq.c
42880@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
42881 unsigned int ret;
42882 RING_LOCALS;
42883
42884- atomic_inc(&dev_priv->swi_emitted);
42885- ret = atomic_read(&dev_priv->swi_emitted);
42886+ atomic_inc_unchecked(&dev_priv->swi_emitted);
42887+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
42888
42889 BEGIN_RING(4);
42890 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
42891@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
42892 drm_radeon_private_t *dev_priv =
42893 (drm_radeon_private_t *) dev->dev_private;
42894
42895- atomic_set(&dev_priv->swi_emitted, 0);
42896+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
42897 init_waitqueue_head(&dev_priv->swi_queue);
42898
42899 dev->max_vblank_count = 0x001fffff;
42900diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
42901index 23bb64f..69d7234 100644
42902--- a/drivers/gpu/drm/radeon/radeon_state.c
42903+++ b/drivers/gpu/drm/radeon/radeon_state.c
42904@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
42905 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
42906 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
42907
42908- if (copy_from_user(&depth_boxes, clear->depth_boxes,
42909+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
42910 sarea_priv->nbox * sizeof(depth_boxes[0])))
42911 return -EFAULT;
42912
42913@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
42914 {
42915 drm_radeon_private_t *dev_priv = dev->dev_private;
42916 drm_radeon_getparam_t *param = data;
42917- int value;
42918+ int value = 0;
42919
42920 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
42921
42922diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
42923index c8a8a51..219dacc 100644
42924--- a/drivers/gpu/drm/radeon/radeon_ttm.c
42925+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
42926@@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
42927 man->size = size >> PAGE_SHIFT;
42928 }
42929
42930-static struct vm_operations_struct radeon_ttm_vm_ops;
42931+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
42932 static const struct vm_operations_struct *ttm_vm_ops = NULL;
42933
42934 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42935@@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
42936 }
42937 if (unlikely(ttm_vm_ops == NULL)) {
42938 ttm_vm_ops = vma->vm_ops;
42939+ pax_open_kernel();
42940 radeon_ttm_vm_ops = *ttm_vm_ops;
42941 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
42942+ pax_close_kernel();
42943 }
42944 vma->vm_ops = &radeon_ttm_vm_ops;
42945 return 0;
42946diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
42947index ef40381..347463e 100644
42948--- a/drivers/gpu/drm/tegra/dc.c
42949+++ b/drivers/gpu/drm/tegra/dc.c
42950@@ -1173,7 +1173,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
42951 }
42952
42953 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
42954- dc->debugfs_files[i].data = dc;
42955+ *(void **)&dc->debugfs_files[i].data = dc;
42956
42957 err = drm_debugfs_create_files(dc->debugfs_files,
42958 ARRAY_SIZE(debugfs_files),
42959diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
42960index bd56f2a..255af4b 100644
42961--- a/drivers/gpu/drm/tegra/dsi.c
42962+++ b/drivers/gpu/drm/tegra/dsi.c
42963@@ -41,7 +41,7 @@ struct tegra_dsi {
42964 struct clk *clk_lp;
42965 struct clk *clk;
42966
42967- struct drm_info_list *debugfs_files;
42968+ drm_info_list_no_const *debugfs_files;
42969 struct drm_minor *minor;
42970 struct dentry *debugfs;
42971
42972diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
42973index ba067bb..23afbbd 100644
42974--- a/drivers/gpu/drm/tegra/hdmi.c
42975+++ b/drivers/gpu/drm/tegra/hdmi.c
42976@@ -60,7 +60,7 @@ struct tegra_hdmi {
42977 bool stereo;
42978 bool dvi;
42979
42980- struct drm_info_list *debugfs_files;
42981+ drm_info_list_no_const *debugfs_files;
42982 struct drm_minor *minor;
42983 struct dentry *debugfs;
42984 };
42985diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42986index bd850c9..d9f3573 100644
42987--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
42988+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42989@@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
42990 }
42991
42992 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
42993- ttm_bo_man_init,
42994- ttm_bo_man_takedown,
42995- ttm_bo_man_get_node,
42996- ttm_bo_man_put_node,
42997- ttm_bo_man_debug
42998+ .init = ttm_bo_man_init,
42999+ .takedown = ttm_bo_man_takedown,
43000+ .get_node = ttm_bo_man_get_node,
43001+ .put_node = ttm_bo_man_put_node,
43002+ .debug = ttm_bo_man_debug
43003 };
43004 EXPORT_SYMBOL(ttm_bo_manager_func);
43005diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
43006index dbc2def..0a9f710 100644
43007--- a/drivers/gpu/drm/ttm/ttm_memory.c
43008+++ b/drivers/gpu/drm/ttm/ttm_memory.c
43009@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
43010 zone->glob = glob;
43011 glob->zone_kernel = zone;
43012 ret = kobject_init_and_add(
43013- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
43014+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
43015 if (unlikely(ret != 0)) {
43016 kobject_put(&zone->kobj);
43017 return ret;
43018@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
43019 zone->glob = glob;
43020 glob->zone_dma32 = zone;
43021 ret = kobject_init_and_add(
43022- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
43023+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
43024 if (unlikely(ret != 0)) {
43025 kobject_put(&zone->kobj);
43026 return ret;
43027diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
43028index 863bef9..cba15cf 100644
43029--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
43030+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
43031@@ -391,9 +391,9 @@ out:
43032 static unsigned long
43033 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
43034 {
43035- static atomic_t start_pool = ATOMIC_INIT(0);
43036+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
43037 unsigned i;
43038- unsigned pool_offset = atomic_add_return(1, &start_pool);
43039+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
43040 struct ttm_page_pool *pool;
43041 int shrink_pages = sc->nr_to_scan;
43042 unsigned long freed = 0;
43043diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
43044index 3771763..883f206 100644
43045--- a/drivers/gpu/drm/udl/udl_fb.c
43046+++ b/drivers/gpu/drm/udl/udl_fb.c
43047@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
43048 fb_deferred_io_cleanup(info);
43049 kfree(info->fbdefio);
43050 info->fbdefio = NULL;
43051- info->fbops->fb_mmap = udl_fb_mmap;
43052 }
43053
43054 pr_warn("released /dev/fb%d user=%d count=%d\n",
43055diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
43056index ad02732..144f5ed 100644
43057--- a/drivers/gpu/drm/via/via_drv.h
43058+++ b/drivers/gpu/drm/via/via_drv.h
43059@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
43060 typedef uint32_t maskarray_t[5];
43061
43062 typedef struct drm_via_irq {
43063- atomic_t irq_received;
43064+ atomic_unchecked_t irq_received;
43065 uint32_t pending_mask;
43066 uint32_t enable_mask;
43067 wait_queue_head_t irq_queue;
43068@@ -75,7 +75,7 @@ typedef struct drm_via_private {
43069 struct timeval last_vblank;
43070 int last_vblank_valid;
43071 unsigned usec_per_vblank;
43072- atomic_t vbl_received;
43073+ atomic_unchecked_t vbl_received;
43074 drm_via_state_t hc_state;
43075 char pci_buf[VIA_PCI_BUF_SIZE];
43076 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
43077diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
43078index 1319433..a993b0c 100644
43079--- a/drivers/gpu/drm/via/via_irq.c
43080+++ b/drivers/gpu/drm/via/via_irq.c
43081@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
43082 if (crtc != 0)
43083 return 0;
43084
43085- return atomic_read(&dev_priv->vbl_received);
43086+ return atomic_read_unchecked(&dev_priv->vbl_received);
43087 }
43088
43089 irqreturn_t via_driver_irq_handler(int irq, void *arg)
43090@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
43091
43092 status = VIA_READ(VIA_REG_INTERRUPT);
43093 if (status & VIA_IRQ_VBLANK_PENDING) {
43094- atomic_inc(&dev_priv->vbl_received);
43095- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
43096+ atomic_inc_unchecked(&dev_priv->vbl_received);
43097+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
43098 do_gettimeofday(&cur_vblank);
43099 if (dev_priv->last_vblank_valid) {
43100 dev_priv->usec_per_vblank =
43101@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
43102 dev_priv->last_vblank = cur_vblank;
43103 dev_priv->last_vblank_valid = 1;
43104 }
43105- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
43106+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
43107 DRM_DEBUG("US per vblank is: %u\n",
43108 dev_priv->usec_per_vblank);
43109 }
43110@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
43111
43112 for (i = 0; i < dev_priv->num_irqs; ++i) {
43113 if (status & cur_irq->pending_mask) {
43114- atomic_inc(&cur_irq->irq_received);
43115+ atomic_inc_unchecked(&cur_irq->irq_received);
43116 wake_up(&cur_irq->irq_queue);
43117 handled = 1;
43118 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
43119@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
43120 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
43121 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
43122 masks[irq][4]));
43123- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
43124+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
43125 } else {
43126 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
43127 (((cur_irq_sequence =
43128- atomic_read(&cur_irq->irq_received)) -
43129+ atomic_read_unchecked(&cur_irq->irq_received)) -
43130 *sequence) <= (1 << 23)));
43131 }
43132 *sequence = cur_irq_sequence;
43133@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
43134 }
43135
43136 for (i = 0; i < dev_priv->num_irqs; ++i) {
43137- atomic_set(&cur_irq->irq_received, 0);
43138+ atomic_set_unchecked(&cur_irq->irq_received, 0);
43139 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
43140 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
43141 init_waitqueue_head(&cur_irq->irq_queue);
43142@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
43143 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
43144 case VIA_IRQ_RELATIVE:
43145 irqwait->request.sequence +=
43146- atomic_read(&cur_irq->irq_received);
43147+ atomic_read_unchecked(&cur_irq->irq_received);
43148 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
43149 case VIA_IRQ_ABSOLUTE:
43150 break;
43151diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
43152index 6b252a8..5975dfe 100644
43153--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
43154+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
43155@@ -437,7 +437,7 @@ struct vmw_private {
43156 * Fencing and IRQs.
43157 */
43158
43159- atomic_t marker_seq;
43160+ atomic_unchecked_t marker_seq;
43161 wait_queue_head_t fence_queue;
43162 wait_queue_head_t fifo_queue;
43163 int fence_queue_waiters; /* Protected by hw_mutex */
43164diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
43165index 6ccd993..618d592 100644
43166--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
43167+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
43168@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
43169 (unsigned int) min,
43170 (unsigned int) fifo->capabilities);
43171
43172- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
43173+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
43174 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
43175 vmw_marker_queue_init(&fifo->marker_queue);
43176 return vmw_fifo_send_fence(dev_priv, &dummy);
43177@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
43178 if (reserveable)
43179 iowrite32(bytes, fifo_mem +
43180 SVGA_FIFO_RESERVED);
43181- return fifo_mem + (next_cmd >> 2);
43182+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
43183 } else {
43184 need_bounce = true;
43185 }
43186@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
43187
43188 fm = vmw_fifo_reserve(dev_priv, bytes);
43189 if (unlikely(fm == NULL)) {
43190- *seqno = atomic_read(&dev_priv->marker_seq);
43191+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
43192 ret = -ENOMEM;
43193 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
43194 false, 3*HZ);
43195@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
43196 }
43197
43198 do {
43199- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
43200+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
43201 } while (*seqno == 0);
43202
43203 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
43204diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
43205index b1273e8..9c274fd 100644
43206--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
43207+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
43208@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
43209 }
43210
43211 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
43212- vmw_gmrid_man_init,
43213- vmw_gmrid_man_takedown,
43214- vmw_gmrid_man_get_node,
43215- vmw_gmrid_man_put_node,
43216- vmw_gmrid_man_debug
43217+ .init = vmw_gmrid_man_init,
43218+ .takedown = vmw_gmrid_man_takedown,
43219+ .get_node = vmw_gmrid_man_get_node,
43220+ .put_node = vmw_gmrid_man_put_node,
43221+ .debug = vmw_gmrid_man_debug
43222 };
43223diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
43224index 37881ec..319065d 100644
43225--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
43226+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
43227@@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
43228 int ret;
43229
43230 num_clips = arg->num_clips;
43231- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
43232+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
43233
43234 if (unlikely(num_clips == 0))
43235 return 0;
43236@@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
43237 int ret;
43238
43239 num_clips = arg->num_clips;
43240- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
43241+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
43242
43243 if (unlikely(num_clips == 0))
43244 return 0;
43245diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
43246index 0c42376..6febe77 100644
43247--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
43248+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
43249@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
43250 * emitted. Then the fence is stale and signaled.
43251 */
43252
43253- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
43254+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
43255 > VMW_FENCE_WRAP);
43256
43257 return ret;
43258@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
43259
43260 if (fifo_idle)
43261 down_read(&fifo_state->rwsem);
43262- signal_seq = atomic_read(&dev_priv->marker_seq);
43263+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
43264 ret = 0;
43265
43266 for (;;) {
43267diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
43268index 8a8725c2..afed796 100644
43269--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
43270+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
43271@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
43272 while (!vmw_lag_lt(queue, us)) {
43273 spin_lock(&queue->lock);
43274 if (list_empty(&queue->head))
43275- seqno = atomic_read(&dev_priv->marker_seq);
43276+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
43277 else {
43278 marker = list_first_entry(&queue->head,
43279 struct vmw_marker, head);
43280diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
43281index 6866448..2ad2b34 100644
43282--- a/drivers/gpu/vga/vga_switcheroo.c
43283+++ b/drivers/gpu/vga/vga_switcheroo.c
43284@@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
43285
43286 /* this version is for the case where the power switch is separate
43287 to the device being powered down. */
43288-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
43289+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
43290 {
43291 /* copy over all the bus versions */
43292 if (dev->bus && dev->bus->pm) {
43293@@ -689,7 +689,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
43294 return ret;
43295 }
43296
43297-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
43298+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
43299 {
43300 /* copy over all the bus versions */
43301 if (dev->bus && dev->bus->pm) {
43302diff --git a/drivers/hid/hid-cherry.c b/drivers/hid/hid-cherry.c
43303index 1bdcccc..f745d2c 100644
43304--- a/drivers/hid/hid-cherry.c
43305+++ b/drivers/hid/hid-cherry.c
43306@@ -28,7 +28,7 @@
43307 static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
43308 unsigned int *rsize)
43309 {
43310- if (*rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
43311+ if (*rsize >= 18 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
43312 hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n");
43313 rdesc[11] = rdesc[16] = 0xff;
43314 rdesc[12] = rdesc[17] = 0x03;
43315diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
43316index 8ed66fd..38ff772 100644
43317--- a/drivers/hid/hid-core.c
43318+++ b/drivers/hid/hid-core.c
43319@@ -2488,7 +2488,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
43320
43321 int hid_add_device(struct hid_device *hdev)
43322 {
43323- static atomic_t id = ATOMIC_INIT(0);
43324+ static atomic_unchecked_t id = ATOMIC_INIT(0);
43325 int ret;
43326
43327 if (WARN_ON(hdev->status & HID_STAT_ADDED))
43328@@ -2530,7 +2530,7 @@ int hid_add_device(struct hid_device *hdev)
43329 /* XXX hack, any other cleaner solution after the driver core
43330 * is converted to allow more than 20 bytes as the device name? */
43331 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
43332- hdev->vendor, hdev->product, atomic_inc_return(&id));
43333+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
43334
43335 hid_debug_register(hdev, dev_name(&hdev->dev));
43336 ret = device_add(&hdev->dev);
43337diff --git a/drivers/hid/hid-kye.c b/drivers/hid/hid-kye.c
43338index e776963..b92bf01 100644
43339--- a/drivers/hid/hid-kye.c
43340+++ b/drivers/hid/hid-kye.c
43341@@ -300,7 +300,7 @@ static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
43342 * - change the button usage range to 4-7 for the extra
43343 * buttons
43344 */
43345- if (*rsize >= 74 &&
43346+ if (*rsize >= 75 &&
43347 rdesc[61] == 0x05 && rdesc[62] == 0x08 &&
43348 rdesc[63] == 0x19 && rdesc[64] == 0x08 &&
43349 rdesc[65] == 0x29 && rdesc[66] == 0x0f &&
43350diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c
43351index a976f48..f91ff14 100644
43352--- a/drivers/hid/hid-lg.c
43353+++ b/drivers/hid/hid-lg.c
43354@@ -345,14 +345,14 @@ static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
43355 struct usb_device_descriptor *udesc;
43356 __u16 bcdDevice, rev_maj, rev_min;
43357
43358- if ((drv_data->quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 &&
43359+ if ((drv_data->quirks & LG_RDESC) && *rsize >= 91 && rdesc[83] == 0x26 &&
43360 rdesc[84] == 0x8c && rdesc[85] == 0x02) {
43361 hid_info(hdev,
43362 "fixing up Logitech keyboard report descriptor\n");
43363 rdesc[84] = rdesc[89] = 0x4d;
43364 rdesc[85] = rdesc[90] = 0x10;
43365 }
43366- if ((drv_data->quirks & LG_RDESC_REL_ABS) && *rsize >= 50 &&
43367+ if ((drv_data->quirks & LG_RDESC_REL_ABS) && *rsize >= 51 &&
43368 rdesc[32] == 0x81 && rdesc[33] == 0x06 &&
43369 rdesc[49] == 0x81 && rdesc[50] == 0x06) {
43370 hid_info(hdev,
43371diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
43372index 486dbde..b7ba829 100644
43373--- a/drivers/hid/hid-logitech-dj.c
43374+++ b/drivers/hid/hid-logitech-dj.c
43375@@ -238,13 +238,6 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,
43376 return;
43377 }
43378
43379- if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
43380- (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
43381- dev_err(&djrcv_hdev->dev, "%s: invalid device index:%d\n",
43382- __func__, dj_report->device_index);
43383- return;
43384- }
43385-
43386 if (djrcv_dev->paired_dj_devices[dj_report->device_index]) {
43387 /* The device is already known. No need to reallocate it. */
43388 dbg_hid("%s: device is already known\n", __func__);
43389@@ -557,7 +550,7 @@ static int logi_dj_ll_raw_request(struct hid_device *hid,
43390 if (!out_buf)
43391 return -ENOMEM;
43392
43393- if (count < DJREPORT_SHORT_LENGTH - 2)
43394+ if (count > DJREPORT_SHORT_LENGTH - 2)
43395 count = DJREPORT_SHORT_LENGTH - 2;
43396
43397 out_buf[0] = REPORT_ID_DJ_SHORT;
43398@@ -690,6 +683,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
43399 * device (via hid_input_report() ) and return 1 so hid-core does not do
43400 * anything else with it.
43401 */
43402+ if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
43403+ (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
43404+ dev_err(&hdev->dev, "%s: invalid device index:%d\n",
43405+ __func__, dj_report->device_index);
43406+ return false;
43407+ }
43408
43409 spin_lock_irqsave(&djrcv_dev->lock, flags);
43410 if (dj_report->report_id == REPORT_ID_DJ_SHORT) {
43411diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
43412index ecc2cbf..29a74c1 100644
43413--- a/drivers/hid/hid-magicmouse.c
43414+++ b/drivers/hid/hid-magicmouse.c
43415@@ -290,6 +290,11 @@ static int magicmouse_raw_event(struct hid_device *hdev,
43416 if (size < 4 || ((size - 4) % 9) != 0)
43417 return 0;
43418 npoints = (size - 4) / 9;
43419+ if (npoints > 15) {
43420+ hid_warn(hdev, "invalid size value (%d) for TRACKPAD_REPORT_ID\n",
43421+ size);
43422+ return 0;
43423+ }
43424 msc->ntouches = 0;
43425 for (ii = 0; ii < npoints; ii++)
43426 magicmouse_emit_touch(msc, ii, data + ii * 9 + 4);
43427@@ -307,6 +312,11 @@ static int magicmouse_raw_event(struct hid_device *hdev,
43428 if (size < 6 || ((size - 6) % 8) != 0)
43429 return 0;
43430 npoints = (size - 6) / 8;
43431+ if (npoints > 15) {
43432+ hid_warn(hdev, "invalid size value (%d) for MOUSE_REPORT_ID\n",
43433+ size);
43434+ return 0;
43435+ }
43436 msc->ntouches = 0;
43437 for (ii = 0; ii < npoints; ii++)
43438 magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);
43439diff --git a/drivers/hid/hid-monterey.c b/drivers/hid/hid-monterey.c
43440index 9e14c00..25daf28 100644
43441--- a/drivers/hid/hid-monterey.c
43442+++ b/drivers/hid/hid-monterey.c
43443@@ -24,7 +24,7 @@
43444 static __u8 *mr_report_fixup(struct hid_device *hdev, __u8 *rdesc,
43445 unsigned int *rsize)
43446 {
43447- if (*rsize >= 30 && rdesc[29] == 0x05 && rdesc[30] == 0x09) {
43448+ if (*rsize >= 31 && rdesc[29] == 0x05 && rdesc[30] == 0x09) {
43449 hid_info(hdev, "fixing up button/consumer in HID report descriptor\n");
43450 rdesc[30] = 0x0c;
43451 }
43452diff --git a/drivers/hid/hid-petalynx.c b/drivers/hid/hid-petalynx.c
43453index 736b250..6aca4f2 100644
43454--- a/drivers/hid/hid-petalynx.c
43455+++ b/drivers/hid/hid-petalynx.c
43456@@ -25,7 +25,7 @@
43457 static __u8 *pl_report_fixup(struct hid_device *hdev, __u8 *rdesc,
43458 unsigned int *rsize)
43459 {
43460- if (*rsize >= 60 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
43461+ if (*rsize >= 62 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
43462 rdesc[41] == 0x00 && rdesc[59] == 0x26 &&
43463 rdesc[60] == 0xf9 && rdesc[61] == 0x00) {
43464 hid_info(hdev, "fixing up Petalynx Maxter Remote report descriptor\n");
43465diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
43466index acbb0210..020df3c 100644
43467--- a/drivers/hid/hid-picolcd_core.c
43468+++ b/drivers/hid/hid-picolcd_core.c
43469@@ -350,6 +350,12 @@ static int picolcd_raw_event(struct hid_device *hdev,
43470 if (!data)
43471 return 1;
43472
43473+ if (size > 64) {
43474+ hid_warn(hdev, "invalid size value (%d) for picolcd raw event\n",
43475+ size);
43476+ return 0;
43477+ }
43478+
43479 if (report->id == REPORT_KEY_STATE) {
43480 if (data->input_keys)
43481 ret = picolcd_raw_keypad(data, report, raw_data+1, size-1);
43482diff --git a/drivers/hid/hid-sunplus.c b/drivers/hid/hid-sunplus.c
43483index 87fc91e..91072fa 100644
43484--- a/drivers/hid/hid-sunplus.c
43485+++ b/drivers/hid/hid-sunplus.c
43486@@ -24,7 +24,7 @@
43487 static __u8 *sp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
43488 unsigned int *rsize)
43489 {
43490- if (*rsize >= 107 && rdesc[104] == 0x26 && rdesc[105] == 0x80 &&
43491+ if (*rsize >= 112 && rdesc[104] == 0x26 && rdesc[105] == 0x80 &&
43492 rdesc[106] == 0x03) {
43493 hid_info(hdev, "fixing up Sunplus Wireless Desktop report descriptor\n");
43494 rdesc[105] = rdesc[110] = 0x03;
43495diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
43496index c13fb5b..55a3802 100644
43497--- a/drivers/hid/hid-wiimote-debug.c
43498+++ b/drivers/hid/hid-wiimote-debug.c
43499@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
43500 else if (size == 0)
43501 return -EIO;
43502
43503- if (copy_to_user(u, buf, size))
43504+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
43505 return -EFAULT;
43506
43507 *off += size;
43508diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
43509index 0cb92e3..c7d453d 100644
43510--- a/drivers/hid/uhid.c
43511+++ b/drivers/hid/uhid.c
43512@@ -47,7 +47,7 @@ struct uhid_device {
43513 struct mutex report_lock;
43514 wait_queue_head_t report_wait;
43515 atomic_t report_done;
43516- atomic_t report_id;
43517+ atomic_unchecked_t report_id;
43518 struct uhid_event report_buf;
43519 };
43520
43521@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
43522
43523 spin_lock_irqsave(&uhid->qlock, flags);
43524 ev->type = UHID_FEATURE;
43525- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
43526+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
43527 ev->u.feature.rnum = rnum;
43528 ev->u.feature.rtype = report_type;
43529
43530@@ -538,7 +538,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
43531 spin_lock_irqsave(&uhid->qlock, flags);
43532
43533 /* id for old report; drop it silently */
43534- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
43535+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
43536 goto unlock;
43537 if (atomic_read(&uhid->report_done))
43538 goto unlock;
43539diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
43540index 284cf66..084c627 100644
43541--- a/drivers/hv/channel.c
43542+++ b/drivers/hv/channel.c
43543@@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
43544 int ret = 0;
43545 int t;
43546
43547- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
43548- atomic_inc(&vmbus_connection.next_gpadl_handle);
43549+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
43550+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
43551
43552 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
43553 if (ret)
43554diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
43555index edfc848..d83e195 100644
43556--- a/drivers/hv/hv.c
43557+++ b/drivers/hv/hv.c
43558@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
43559 u64 output_address = (output) ? virt_to_phys(output) : 0;
43560 u32 output_address_hi = output_address >> 32;
43561 u32 output_address_lo = output_address & 0xFFFFFFFF;
43562- void *hypercall_page = hv_context.hypercall_page;
43563+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
43564
43565 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
43566 "=a"(hv_status_lo) : "d" (control_hi),
43567@@ -154,7 +154,7 @@ int hv_init(void)
43568 /* See if the hypercall page is already set */
43569 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
43570
43571- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
43572+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
43573
43574 if (!virtaddr)
43575 goto cleanup;
43576diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
43577index 5e90c5d..d8fcefb 100644
43578--- a/drivers/hv/hv_balloon.c
43579+++ b/drivers/hv/hv_balloon.c
43580@@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
43581
43582 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
43583 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
43584-static atomic_t trans_id = ATOMIC_INIT(0);
43585+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
43586
43587 static int dm_ring_size = (5 * PAGE_SIZE);
43588
43589@@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
43590 pr_info("Memory hot add failed\n");
43591
43592 dm->state = DM_INITIALIZED;
43593- resp.hdr.trans_id = atomic_inc_return(&trans_id);
43594+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43595 vmbus_sendpacket(dm->dev->channel, &resp,
43596 sizeof(struct dm_hot_add_response),
43597 (unsigned long)NULL,
43598@@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
43599 memset(&status, 0, sizeof(struct dm_status));
43600 status.hdr.type = DM_STATUS_REPORT;
43601 status.hdr.size = sizeof(struct dm_status);
43602- status.hdr.trans_id = atomic_inc_return(&trans_id);
43603+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43604
43605 /*
43606 * The host expects the guest to report free memory.
43607@@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
43608 * send the status. This can happen if we were interrupted
43609 * after we picked our transaction ID.
43610 */
43611- if (status.hdr.trans_id != atomic_read(&trans_id))
43612+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
43613 return;
43614
43615 /*
43616@@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
43617 */
43618
43619 do {
43620- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
43621+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43622 ret = vmbus_sendpacket(dm_device.dev->channel,
43623 bl_resp,
43624 bl_resp->hdr.size,
43625@@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
43626
43627 memset(&resp, 0, sizeof(struct dm_unballoon_response));
43628 resp.hdr.type = DM_UNBALLOON_RESPONSE;
43629- resp.hdr.trans_id = atomic_inc_return(&trans_id);
43630+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43631 resp.hdr.size = sizeof(struct dm_unballoon_response);
43632
43633 vmbus_sendpacket(dm_device.dev->channel, &resp,
43634@@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
43635 memset(&version_req, 0, sizeof(struct dm_version_request));
43636 version_req.hdr.type = DM_VERSION_REQUEST;
43637 version_req.hdr.size = sizeof(struct dm_version_request);
43638- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
43639+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43640 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
43641 version_req.is_last_attempt = 1;
43642
43643@@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
43644 memset(&version_req, 0, sizeof(struct dm_version_request));
43645 version_req.hdr.type = DM_VERSION_REQUEST;
43646 version_req.hdr.size = sizeof(struct dm_version_request);
43647- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
43648+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43649 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
43650 version_req.is_last_attempt = 0;
43651
43652@@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
43653 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
43654 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
43655 cap_msg.hdr.size = sizeof(struct dm_capabilities);
43656- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
43657+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43658
43659 cap_msg.caps.cap_bits.balloon = 1;
43660 cap_msg.caps.cap_bits.hot_add = 1;
43661diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
43662index 22b7507..fc2fc47 100644
43663--- a/drivers/hv/hyperv_vmbus.h
43664+++ b/drivers/hv/hyperv_vmbus.h
43665@@ -607,7 +607,7 @@ enum vmbus_connect_state {
43666 struct vmbus_connection {
43667 enum vmbus_connect_state conn_state;
43668
43669- atomic_t next_gpadl_handle;
43670+ atomic_unchecked_t next_gpadl_handle;
43671
43672 /*
43673 * Represents channel interrupts. Each bit position represents a
43674diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
43675index 4d6b269..2e23b86 100644
43676--- a/drivers/hv/vmbus_drv.c
43677+++ b/drivers/hv/vmbus_drv.c
43678@@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
43679 {
43680 int ret = 0;
43681
43682- static atomic_t device_num = ATOMIC_INIT(0);
43683+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
43684
43685 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
43686- atomic_inc_return(&device_num));
43687+ atomic_inc_return_unchecked(&device_num));
43688
43689 child_device_obj->device.bus = &hv_bus;
43690 child_device_obj->device.parent = &hv_acpi_dev->dev;
43691diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
43692index 579bdf9..75118b5 100644
43693--- a/drivers/hwmon/acpi_power_meter.c
43694+++ b/drivers/hwmon/acpi_power_meter.c
43695@@ -116,7 +116,7 @@ struct sensor_template {
43696 struct device_attribute *devattr,
43697 const char *buf, size_t count);
43698 int index;
43699-};
43700+} __do_const;
43701
43702 /* Averaging interval */
43703 static int update_avg_interval(struct acpi_power_meter_resource *resource)
43704@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
43705 struct sensor_template *attrs)
43706 {
43707 struct device *dev = &resource->acpi_dev->dev;
43708- struct sensor_device_attribute *sensors =
43709+ sensor_device_attribute_no_const *sensors =
43710 &resource->sensors[resource->num_sensors];
43711 int res = 0;
43712
43713diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
43714index 3288f13..71cfb4e 100644
43715--- a/drivers/hwmon/applesmc.c
43716+++ b/drivers/hwmon/applesmc.c
43717@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
43718 {
43719 struct applesmc_node_group *grp;
43720 struct applesmc_dev_attr *node;
43721- struct attribute *attr;
43722+ attribute_no_const *attr;
43723 int ret, i;
43724
43725 for (grp = groups; grp->format; grp++) {
43726diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
43727index ae208f6..48b6c5b 100644
43728--- a/drivers/hwmon/asus_atk0110.c
43729+++ b/drivers/hwmon/asus_atk0110.c
43730@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
43731 struct atk_sensor_data {
43732 struct list_head list;
43733 struct atk_data *data;
43734- struct device_attribute label_attr;
43735- struct device_attribute input_attr;
43736- struct device_attribute limit1_attr;
43737- struct device_attribute limit2_attr;
43738+ device_attribute_no_const label_attr;
43739+ device_attribute_no_const input_attr;
43740+ device_attribute_no_const limit1_attr;
43741+ device_attribute_no_const limit2_attr;
43742 char label_attr_name[ATTR_NAME_SIZE];
43743 char input_attr_name[ATTR_NAME_SIZE];
43744 char limit1_attr_name[ATTR_NAME_SIZE];
43745@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
43746 static struct device_attribute atk_name_attr =
43747 __ATTR(name, 0444, atk_name_show, NULL);
43748
43749-static void atk_init_attribute(struct device_attribute *attr, char *name,
43750+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
43751 sysfs_show_func show)
43752 {
43753 sysfs_attr_init(&attr->attr);
43754diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
43755index d76f0b7..55ae976 100644
43756--- a/drivers/hwmon/coretemp.c
43757+++ b/drivers/hwmon/coretemp.c
43758@@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
43759 return NOTIFY_OK;
43760 }
43761
43762-static struct notifier_block coretemp_cpu_notifier __refdata = {
43763+static struct notifier_block coretemp_cpu_notifier = {
43764 .notifier_call = coretemp_cpu_callback,
43765 };
43766
43767diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
43768index 632f1dc..57e6a58 100644
43769--- a/drivers/hwmon/ibmaem.c
43770+++ b/drivers/hwmon/ibmaem.c
43771@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
43772 struct aem_rw_sensor_template *rw)
43773 {
43774 struct device *dev = &data->pdev->dev;
43775- struct sensor_device_attribute *sensors = data->sensors;
43776+ sensor_device_attribute_no_const *sensors = data->sensors;
43777 int err;
43778
43779 /* Set up read-only sensors */
43780diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
43781index 14c82da..09b25d7 100644
43782--- a/drivers/hwmon/iio_hwmon.c
43783+++ b/drivers/hwmon/iio_hwmon.c
43784@@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
43785 {
43786 struct device *dev = &pdev->dev;
43787 struct iio_hwmon_state *st;
43788- struct sensor_device_attribute *a;
43789+ sensor_device_attribute_no_const *a;
43790 int ret, i;
43791 int in_i = 1, temp_i = 1, curr_i = 1;
43792 enum iio_chan_type type;
43793diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
43794index 7710f46..427a28d 100644
43795--- a/drivers/hwmon/nct6683.c
43796+++ b/drivers/hwmon/nct6683.c
43797@@ -397,11 +397,11 @@ static struct attribute_group *
43798 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43799 int repeat)
43800 {
43801- struct sensor_device_attribute_2 *a2;
43802- struct sensor_device_attribute *a;
43803+ sensor_device_attribute_2_no_const *a2;
43804+ sensor_device_attribute_no_const *a;
43805 struct sensor_device_template **t;
43806 struct sensor_device_attr_u *su;
43807- struct attribute_group *group;
43808+ attribute_group_no_const *group;
43809 struct attribute **attrs;
43810 int i, j, count;
43811
43812diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
43813index 59d9a3f..2298fa4 100644
43814--- a/drivers/hwmon/nct6775.c
43815+++ b/drivers/hwmon/nct6775.c
43816@@ -944,10 +944,10 @@ static struct attribute_group *
43817 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43818 int repeat)
43819 {
43820- struct attribute_group *group;
43821+ attribute_group_no_const *group;
43822 struct sensor_device_attr_u *su;
43823- struct sensor_device_attribute *a;
43824- struct sensor_device_attribute_2 *a2;
43825+ sensor_device_attribute_no_const *a;
43826+ sensor_device_attribute_2_no_const *a2;
43827 struct attribute **attrs;
43828 struct sensor_device_template **t;
43829 int i, count;
43830diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
43831index 291d11f..3f0dbbd 100644
43832--- a/drivers/hwmon/pmbus/pmbus_core.c
43833+++ b/drivers/hwmon/pmbus/pmbus_core.c
43834@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
43835 return 0;
43836 }
43837
43838-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43839+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
43840 const char *name,
43841 umode_t mode,
43842 ssize_t (*show)(struct device *dev,
43843@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43844 dev_attr->store = store;
43845 }
43846
43847-static void pmbus_attr_init(struct sensor_device_attribute *a,
43848+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
43849 const char *name,
43850 umode_t mode,
43851 ssize_t (*show)(struct device *dev,
43852@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
43853 u16 reg, u8 mask)
43854 {
43855 struct pmbus_boolean *boolean;
43856- struct sensor_device_attribute *a;
43857+ sensor_device_attribute_no_const *a;
43858
43859 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
43860 if (!boolean)
43861@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
43862 bool update, bool readonly)
43863 {
43864 struct pmbus_sensor *sensor;
43865- struct device_attribute *a;
43866+ device_attribute_no_const *a;
43867
43868 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
43869 if (!sensor)
43870@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
43871 const char *lstring, int index)
43872 {
43873 struct pmbus_label *label;
43874- struct device_attribute *a;
43875+ device_attribute_no_const *a;
43876
43877 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
43878 if (!label)
43879diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
43880index 97cd45a..ac54d8b 100644
43881--- a/drivers/hwmon/sht15.c
43882+++ b/drivers/hwmon/sht15.c
43883@@ -169,7 +169,7 @@ struct sht15_data {
43884 int supply_uv;
43885 bool supply_uv_valid;
43886 struct work_struct update_supply_work;
43887- atomic_t interrupt_handled;
43888+ atomic_unchecked_t interrupt_handled;
43889 };
43890
43891 /**
43892@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
43893 ret = gpio_direction_input(data->pdata->gpio_data);
43894 if (ret)
43895 return ret;
43896- atomic_set(&data->interrupt_handled, 0);
43897+ atomic_set_unchecked(&data->interrupt_handled, 0);
43898
43899 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43900 if (gpio_get_value(data->pdata->gpio_data) == 0) {
43901 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
43902 /* Only relevant if the interrupt hasn't occurred. */
43903- if (!atomic_read(&data->interrupt_handled))
43904+ if (!atomic_read_unchecked(&data->interrupt_handled))
43905 schedule_work(&data->read_work);
43906 }
43907 ret = wait_event_timeout(data->wait_queue,
43908@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
43909
43910 /* First disable the interrupt */
43911 disable_irq_nosync(irq);
43912- atomic_inc(&data->interrupt_handled);
43913+ atomic_inc_unchecked(&data->interrupt_handled);
43914 /* Then schedule a reading work struct */
43915 if (data->state != SHT15_READING_NOTHING)
43916 schedule_work(&data->read_work);
43917@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
43918 * If not, then start the interrupt again - care here as could
43919 * have gone low in meantime so verify it hasn't!
43920 */
43921- atomic_set(&data->interrupt_handled, 0);
43922+ atomic_set_unchecked(&data->interrupt_handled, 0);
43923 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43924 /* If still not occurred or another handler was scheduled */
43925 if (gpio_get_value(data->pdata->gpio_data)
43926- || atomic_read(&data->interrupt_handled))
43927+ || atomic_read_unchecked(&data->interrupt_handled))
43928 return;
43929 }
43930
43931diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
43932index 8df43c5..b07b91d 100644
43933--- a/drivers/hwmon/via-cputemp.c
43934+++ b/drivers/hwmon/via-cputemp.c
43935@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
43936 return NOTIFY_OK;
43937 }
43938
43939-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
43940+static struct notifier_block via_cputemp_cpu_notifier = {
43941 .notifier_call = via_cputemp_cpu_callback,
43942 };
43943
43944diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
43945index 41fc683..a39cfea 100644
43946--- a/drivers/i2c/busses/i2c-amd756-s4882.c
43947+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
43948@@ -43,7 +43,7 @@
43949 extern struct i2c_adapter amd756_smbus;
43950
43951 static struct i2c_adapter *s4882_adapter;
43952-static struct i2c_algorithm *s4882_algo;
43953+static i2c_algorithm_no_const *s4882_algo;
43954
43955 /* Wrapper access functions for multiplexed SMBus */
43956 static DEFINE_MUTEX(amd756_lock);
43957diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
43958index b19a310..d6eece0 100644
43959--- a/drivers/i2c/busses/i2c-diolan-u2c.c
43960+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
43961@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
43962 /* usb layer */
43963
43964 /* Send command to device, and get response. */
43965-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43966+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43967 {
43968 int ret = 0;
43969 int actual;
43970diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
43971index b170bdf..3c76427 100644
43972--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
43973+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
43974@@ -41,7 +41,7 @@
43975 extern struct i2c_adapter *nforce2_smbus;
43976
43977 static struct i2c_adapter *s4985_adapter;
43978-static struct i2c_algorithm *s4985_algo;
43979+static i2c_algorithm_no_const *s4985_algo;
43980
43981 /* Wrapper access functions for multiplexed SMBus */
43982 static DEFINE_MUTEX(nforce2_lock);
43983diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
43984index 80b47e8..1a6040d9 100644
43985--- a/drivers/i2c/i2c-dev.c
43986+++ b/drivers/i2c/i2c-dev.c
43987@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
43988 break;
43989 }
43990
43991- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
43992+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
43993 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
43994 if (IS_ERR(rdwr_pa[i].buf)) {
43995 res = PTR_ERR(rdwr_pa[i].buf);
43996diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
43997index 0b510ba..4fbb5085 100644
43998--- a/drivers/ide/ide-cd.c
43999+++ b/drivers/ide/ide-cd.c
44000@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
44001 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
44002 if ((unsigned long)buf & alignment
44003 || blk_rq_bytes(rq) & q->dma_pad_mask
44004- || object_is_on_stack(buf))
44005+ || object_starts_on_stack(buf))
44006 drive->dma = 0;
44007 }
44008 }
44009diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
44010index 4b1f375..770b95f 100644
44011--- a/drivers/iio/industrialio-core.c
44012+++ b/drivers/iio/industrialio-core.c
44013@@ -551,7 +551,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
44014 }
44015
44016 static
44017-int __iio_device_attr_init(struct device_attribute *dev_attr,
44018+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
44019 const char *postfix,
44020 struct iio_chan_spec const *chan,
44021 ssize_t (*readfunc)(struct device *dev,
44022diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
44023index c323917..6ddea8b 100644
44024--- a/drivers/infiniband/core/cm.c
44025+++ b/drivers/infiniband/core/cm.c
44026@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
44027
44028 struct cm_counter_group {
44029 struct kobject obj;
44030- atomic_long_t counter[CM_ATTR_COUNT];
44031+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
44032 };
44033
44034 struct cm_counter_attribute {
44035@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
44036 struct ib_mad_send_buf *msg = NULL;
44037 int ret;
44038
44039- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44040+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44041 counter[CM_REQ_COUNTER]);
44042
44043 /* Quick state check to discard duplicate REQs. */
44044@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
44045 if (!cm_id_priv)
44046 return;
44047
44048- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44049+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44050 counter[CM_REP_COUNTER]);
44051 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
44052 if (ret)
44053@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
44054 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
44055 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
44056 spin_unlock_irq(&cm_id_priv->lock);
44057- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44058+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44059 counter[CM_RTU_COUNTER]);
44060 goto out;
44061 }
44062@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
44063 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
44064 dreq_msg->local_comm_id);
44065 if (!cm_id_priv) {
44066- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44067+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44068 counter[CM_DREQ_COUNTER]);
44069 cm_issue_drep(work->port, work->mad_recv_wc);
44070 return -EINVAL;
44071@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
44072 case IB_CM_MRA_REP_RCVD:
44073 break;
44074 case IB_CM_TIMEWAIT:
44075- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44076+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44077 counter[CM_DREQ_COUNTER]);
44078 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
44079 goto unlock;
44080@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
44081 cm_free_msg(msg);
44082 goto deref;
44083 case IB_CM_DREQ_RCVD:
44084- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44085+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44086 counter[CM_DREQ_COUNTER]);
44087 goto unlock;
44088 default:
44089@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
44090 ib_modify_mad(cm_id_priv->av.port->mad_agent,
44091 cm_id_priv->msg, timeout)) {
44092 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
44093- atomic_long_inc(&work->port->
44094+ atomic_long_inc_unchecked(&work->port->
44095 counter_group[CM_RECV_DUPLICATES].
44096 counter[CM_MRA_COUNTER]);
44097 goto out;
44098@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
44099 break;
44100 case IB_CM_MRA_REQ_RCVD:
44101 case IB_CM_MRA_REP_RCVD:
44102- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44103+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44104 counter[CM_MRA_COUNTER]);
44105 /* fall through */
44106 default:
44107@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
44108 case IB_CM_LAP_IDLE:
44109 break;
44110 case IB_CM_MRA_LAP_SENT:
44111- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44112+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44113 counter[CM_LAP_COUNTER]);
44114 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
44115 goto unlock;
44116@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
44117 cm_free_msg(msg);
44118 goto deref;
44119 case IB_CM_LAP_RCVD:
44120- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44121+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44122 counter[CM_LAP_COUNTER]);
44123 goto unlock;
44124 default:
44125@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
44126 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
44127 if (cur_cm_id_priv) {
44128 spin_unlock_irq(&cm.lock);
44129- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44130+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44131 counter[CM_SIDR_REQ_COUNTER]);
44132 goto out; /* Duplicate message. */
44133 }
44134@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
44135 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
44136 msg->retries = 1;
44137
44138- atomic_long_add(1 + msg->retries,
44139+ atomic_long_add_unchecked(1 + msg->retries,
44140 &port->counter_group[CM_XMIT].counter[attr_index]);
44141 if (msg->retries)
44142- atomic_long_add(msg->retries,
44143+ atomic_long_add_unchecked(msg->retries,
44144 &port->counter_group[CM_XMIT_RETRIES].
44145 counter[attr_index]);
44146
44147@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
44148 }
44149
44150 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
44151- atomic_long_inc(&port->counter_group[CM_RECV].
44152+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
44153 counter[attr_id - CM_ATTR_ID_OFFSET]);
44154
44155 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
44156@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
44157 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
44158
44159 return sprintf(buf, "%ld\n",
44160- atomic_long_read(&group->counter[cm_attr->index]));
44161+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
44162 }
44163
44164 static const struct sysfs_ops cm_counter_ops = {
44165diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
44166index 9f5ad7c..588cd84 100644
44167--- a/drivers/infiniband/core/fmr_pool.c
44168+++ b/drivers/infiniband/core/fmr_pool.c
44169@@ -98,8 +98,8 @@ struct ib_fmr_pool {
44170
44171 struct task_struct *thread;
44172
44173- atomic_t req_ser;
44174- atomic_t flush_ser;
44175+ atomic_unchecked_t req_ser;
44176+ atomic_unchecked_t flush_ser;
44177
44178 wait_queue_head_t force_wait;
44179 };
44180@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
44181 struct ib_fmr_pool *pool = pool_ptr;
44182
44183 do {
44184- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
44185+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
44186 ib_fmr_batch_release(pool);
44187
44188- atomic_inc(&pool->flush_ser);
44189+ atomic_inc_unchecked(&pool->flush_ser);
44190 wake_up_interruptible(&pool->force_wait);
44191
44192 if (pool->flush_function)
44193@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
44194 }
44195
44196 set_current_state(TASK_INTERRUPTIBLE);
44197- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
44198+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
44199 !kthread_should_stop())
44200 schedule();
44201 __set_current_state(TASK_RUNNING);
44202@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
44203 pool->dirty_watermark = params->dirty_watermark;
44204 pool->dirty_len = 0;
44205 spin_lock_init(&pool->pool_lock);
44206- atomic_set(&pool->req_ser, 0);
44207- atomic_set(&pool->flush_ser, 0);
44208+ atomic_set_unchecked(&pool->req_ser, 0);
44209+ atomic_set_unchecked(&pool->flush_ser, 0);
44210 init_waitqueue_head(&pool->force_wait);
44211
44212 pool->thread = kthread_run(ib_fmr_cleanup_thread,
44213@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
44214 }
44215 spin_unlock_irq(&pool->pool_lock);
44216
44217- serial = atomic_inc_return(&pool->req_ser);
44218+ serial = atomic_inc_return_unchecked(&pool->req_ser);
44219 wake_up_process(pool->thread);
44220
44221 if (wait_event_interruptible(pool->force_wait,
44222- atomic_read(&pool->flush_ser) - serial >= 0))
44223+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
44224 return -EINTR;
44225
44226 return 0;
44227@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
44228 } else {
44229 list_add_tail(&fmr->list, &pool->dirty_list);
44230 if (++pool->dirty_len >= pool->dirty_watermark) {
44231- atomic_inc(&pool->req_ser);
44232+ atomic_inc_unchecked(&pool->req_ser);
44233 wake_up_process(pool->thread);
44234 }
44235 }
44236diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
44237index ec7a298..8742e59 100644
44238--- a/drivers/infiniband/hw/cxgb4/mem.c
44239+++ b/drivers/infiniband/hw/cxgb4/mem.c
44240@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
44241 int err;
44242 struct fw_ri_tpte tpt;
44243 u32 stag_idx;
44244- static atomic_t key;
44245+ static atomic_unchecked_t key;
44246
44247 if (c4iw_fatal_error(rdev))
44248 return -EIO;
44249@@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
44250 if (rdev->stats.stag.cur > rdev->stats.stag.max)
44251 rdev->stats.stag.max = rdev->stats.stag.cur;
44252 mutex_unlock(&rdev->stats.lock);
44253- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
44254+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
44255 }
44256 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
44257 __func__, stag_state, type, pdid, stag_idx);
44258diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
44259index 79b3dbc..96e5fcc 100644
44260--- a/drivers/infiniband/hw/ipath/ipath_rc.c
44261+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
44262@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
44263 struct ib_atomic_eth *ateth;
44264 struct ipath_ack_entry *e;
44265 u64 vaddr;
44266- atomic64_t *maddr;
44267+ atomic64_unchecked_t *maddr;
44268 u64 sdata;
44269 u32 rkey;
44270 u8 next;
44271@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
44272 IB_ACCESS_REMOTE_ATOMIC)))
44273 goto nack_acc_unlck;
44274 /* Perform atomic OP and save result. */
44275- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
44276+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
44277 sdata = be64_to_cpu(ateth->swap_data);
44278 e = &qp->s_ack_queue[qp->r_head_ack_queue];
44279 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
44280- (u64) atomic64_add_return(sdata, maddr) - sdata :
44281+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
44282 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
44283 be64_to_cpu(ateth->compare_data),
44284 sdata);
44285diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
44286index 1f95bba..9530f87 100644
44287--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
44288+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
44289@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
44290 unsigned long flags;
44291 struct ib_wc wc;
44292 u64 sdata;
44293- atomic64_t *maddr;
44294+ atomic64_unchecked_t *maddr;
44295 enum ib_wc_status send_status;
44296
44297 /*
44298@@ -382,11 +382,11 @@ again:
44299 IB_ACCESS_REMOTE_ATOMIC)))
44300 goto acc_err;
44301 /* Perform atomic OP and save result. */
44302- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
44303+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
44304 sdata = wqe->wr.wr.atomic.compare_add;
44305 *(u64 *) sqp->s_sge.sge.vaddr =
44306 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
44307- (u64) atomic64_add_return(sdata, maddr) - sdata :
44308+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
44309 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
44310 sdata, wqe->wr.wr.atomic.swap);
44311 goto send_comp;
44312diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
44313index 287ad05..5ae7b44d 100644
44314--- a/drivers/infiniband/hw/mlx4/mad.c
44315+++ b/drivers/infiniband/hw/mlx4/mad.c
44316@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
44317
44318 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
44319 {
44320- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
44321+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
44322 cpu_to_be64(0xff00000000000000LL);
44323 }
44324
44325diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
44326index ed327e6..ca1739e0 100644
44327--- a/drivers/infiniband/hw/mlx4/mcg.c
44328+++ b/drivers/infiniband/hw/mlx4/mcg.c
44329@@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
44330 {
44331 char name[20];
44332
44333- atomic_set(&ctx->tid, 0);
44334+ atomic_set_unchecked(&ctx->tid, 0);
44335 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
44336 ctx->mcg_wq = create_singlethread_workqueue(name);
44337 if (!ctx->mcg_wq)
44338diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
44339index 369da3c..223e6e9 100644
44340--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
44341+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
44342@@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
44343 struct list_head mcg_mgid0_list;
44344 struct workqueue_struct *mcg_wq;
44345 struct mlx4_ib_demux_pv_ctx **tun;
44346- atomic_t tid;
44347+ atomic_unchecked_t tid;
44348 int flushing; /* flushing the work queue */
44349 };
44350
44351diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
44352index 9d3e5c1..6f166df 100644
44353--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
44354+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
44355@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
44356 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
44357 }
44358
44359-int mthca_QUERY_FW(struct mthca_dev *dev)
44360+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
44361 {
44362 struct mthca_mailbox *mailbox;
44363 u32 *outbox;
44364@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44365 CMD_TIME_CLASS_B);
44366 }
44367
44368-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44369+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44370 int num_mtt)
44371 {
44372 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
44373@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
44374 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
44375 }
44376
44377-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44378+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44379 int eq_num)
44380 {
44381 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
44382@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
44383 CMD_TIME_CLASS_B);
44384 }
44385
44386-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
44387+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
44388 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
44389 void *in_mad, void *response_mad)
44390 {
44391diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
44392index ded76c1..0cf0a08 100644
44393--- a/drivers/infiniband/hw/mthca/mthca_main.c
44394+++ b/drivers/infiniband/hw/mthca/mthca_main.c
44395@@ -692,7 +692,7 @@ err_close:
44396 return err;
44397 }
44398
44399-static int mthca_setup_hca(struct mthca_dev *dev)
44400+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
44401 {
44402 int err;
44403
44404diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
44405index ed9a989..6aa5dc2 100644
44406--- a/drivers/infiniband/hw/mthca/mthca_mr.c
44407+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
44408@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
44409 * through the bitmaps)
44410 */
44411
44412-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
44413+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
44414 {
44415 int o;
44416 int m;
44417@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
44418 return key;
44419 }
44420
44421-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
44422+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
44423 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
44424 {
44425 struct mthca_mailbox *mailbox;
44426@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
44427 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
44428 }
44429
44430-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
44431+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
44432 u64 *buffer_list, int buffer_size_shift,
44433 int list_len, u64 iova, u64 total_size,
44434 u32 access, struct mthca_mr *mr)
44435diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
44436index 415f8e1..e34214e 100644
44437--- a/drivers/infiniband/hw/mthca/mthca_provider.c
44438+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
44439@@ -764,7 +764,7 @@ unlock:
44440 return 0;
44441 }
44442
44443-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
44444+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
44445 {
44446 struct mthca_dev *dev = to_mdev(ibcq->device);
44447 struct mthca_cq *cq = to_mcq(ibcq);
44448diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
44449index 3b2a6dc..bce26ff 100644
44450--- a/drivers/infiniband/hw/nes/nes.c
44451+++ b/drivers/infiniband/hw/nes/nes.c
44452@@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
44453 LIST_HEAD(nes_adapter_list);
44454 static LIST_HEAD(nes_dev_list);
44455
44456-atomic_t qps_destroyed;
44457+atomic_unchecked_t qps_destroyed;
44458
44459 static unsigned int ee_flsh_adapter;
44460 static unsigned int sysfs_nonidx_addr;
44461@@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
44462 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
44463 struct nes_adapter *nesadapter = nesdev->nesadapter;
44464
44465- atomic_inc(&qps_destroyed);
44466+ atomic_inc_unchecked(&qps_destroyed);
44467
44468 /* Free the control structures */
44469
44470diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
44471index bd9d132..70d84f4 100644
44472--- a/drivers/infiniband/hw/nes/nes.h
44473+++ b/drivers/infiniband/hw/nes/nes.h
44474@@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
44475 extern unsigned int wqm_quanta;
44476 extern struct list_head nes_adapter_list;
44477
44478-extern atomic_t cm_connects;
44479-extern atomic_t cm_accepts;
44480-extern atomic_t cm_disconnects;
44481-extern atomic_t cm_closes;
44482-extern atomic_t cm_connecteds;
44483-extern atomic_t cm_connect_reqs;
44484-extern atomic_t cm_rejects;
44485-extern atomic_t mod_qp_timouts;
44486-extern atomic_t qps_created;
44487-extern atomic_t qps_destroyed;
44488-extern atomic_t sw_qps_destroyed;
44489+extern atomic_unchecked_t cm_connects;
44490+extern atomic_unchecked_t cm_accepts;
44491+extern atomic_unchecked_t cm_disconnects;
44492+extern atomic_unchecked_t cm_closes;
44493+extern atomic_unchecked_t cm_connecteds;
44494+extern atomic_unchecked_t cm_connect_reqs;
44495+extern atomic_unchecked_t cm_rejects;
44496+extern atomic_unchecked_t mod_qp_timouts;
44497+extern atomic_unchecked_t qps_created;
44498+extern atomic_unchecked_t qps_destroyed;
44499+extern atomic_unchecked_t sw_qps_destroyed;
44500 extern u32 mh_detected;
44501 extern u32 mh_pauses_sent;
44502 extern u32 cm_packets_sent;
44503@@ -199,16 +199,16 @@ extern u32 cm_packets_created;
44504 extern u32 cm_packets_received;
44505 extern u32 cm_packets_dropped;
44506 extern u32 cm_packets_retrans;
44507-extern atomic_t cm_listens_created;
44508-extern atomic_t cm_listens_destroyed;
44509+extern atomic_unchecked_t cm_listens_created;
44510+extern atomic_unchecked_t cm_listens_destroyed;
44511 extern u32 cm_backlog_drops;
44512-extern atomic_t cm_loopbacks;
44513-extern atomic_t cm_nodes_created;
44514-extern atomic_t cm_nodes_destroyed;
44515-extern atomic_t cm_accel_dropped_pkts;
44516-extern atomic_t cm_resets_recvd;
44517-extern atomic_t pau_qps_created;
44518-extern atomic_t pau_qps_destroyed;
44519+extern atomic_unchecked_t cm_loopbacks;
44520+extern atomic_unchecked_t cm_nodes_created;
44521+extern atomic_unchecked_t cm_nodes_destroyed;
44522+extern atomic_unchecked_t cm_accel_dropped_pkts;
44523+extern atomic_unchecked_t cm_resets_recvd;
44524+extern atomic_unchecked_t pau_qps_created;
44525+extern atomic_unchecked_t pau_qps_destroyed;
44526
44527 extern u32 int_mod_timer_init;
44528 extern u32 int_mod_cq_depth_256;
44529diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
44530index 6f09a72..cf4399d 100644
44531--- a/drivers/infiniband/hw/nes/nes_cm.c
44532+++ b/drivers/infiniband/hw/nes/nes_cm.c
44533@@ -69,14 +69,14 @@ u32 cm_packets_dropped;
44534 u32 cm_packets_retrans;
44535 u32 cm_packets_created;
44536 u32 cm_packets_received;
44537-atomic_t cm_listens_created;
44538-atomic_t cm_listens_destroyed;
44539+atomic_unchecked_t cm_listens_created;
44540+atomic_unchecked_t cm_listens_destroyed;
44541 u32 cm_backlog_drops;
44542-atomic_t cm_loopbacks;
44543-atomic_t cm_nodes_created;
44544-atomic_t cm_nodes_destroyed;
44545-atomic_t cm_accel_dropped_pkts;
44546-atomic_t cm_resets_recvd;
44547+atomic_unchecked_t cm_loopbacks;
44548+atomic_unchecked_t cm_nodes_created;
44549+atomic_unchecked_t cm_nodes_destroyed;
44550+atomic_unchecked_t cm_accel_dropped_pkts;
44551+atomic_unchecked_t cm_resets_recvd;
44552
44553 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
44554 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
44555@@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
44556 /* instance of function pointers for client API */
44557 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
44558 static struct nes_cm_ops nes_cm_api = {
44559- mini_cm_accelerated,
44560- mini_cm_listen,
44561- mini_cm_del_listen,
44562- mini_cm_connect,
44563- mini_cm_close,
44564- mini_cm_accept,
44565- mini_cm_reject,
44566- mini_cm_recv_pkt,
44567- mini_cm_dealloc_core,
44568- mini_cm_get,
44569- mini_cm_set
44570+ .accelerated = mini_cm_accelerated,
44571+ .listen = mini_cm_listen,
44572+ .stop_listener = mini_cm_del_listen,
44573+ .connect = mini_cm_connect,
44574+ .close = mini_cm_close,
44575+ .accept = mini_cm_accept,
44576+ .reject = mini_cm_reject,
44577+ .recv_pkt = mini_cm_recv_pkt,
44578+ .destroy_cm_core = mini_cm_dealloc_core,
44579+ .get = mini_cm_get,
44580+ .set = mini_cm_set
44581 };
44582
44583 static struct nes_cm_core *g_cm_core;
44584
44585-atomic_t cm_connects;
44586-atomic_t cm_accepts;
44587-atomic_t cm_disconnects;
44588-atomic_t cm_closes;
44589-atomic_t cm_connecteds;
44590-atomic_t cm_connect_reqs;
44591-atomic_t cm_rejects;
44592+atomic_unchecked_t cm_connects;
44593+atomic_unchecked_t cm_accepts;
44594+atomic_unchecked_t cm_disconnects;
44595+atomic_unchecked_t cm_closes;
44596+atomic_unchecked_t cm_connecteds;
44597+atomic_unchecked_t cm_connect_reqs;
44598+atomic_unchecked_t cm_rejects;
44599
44600 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
44601 {
44602@@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
44603 kfree(listener);
44604 listener = NULL;
44605 ret = 0;
44606- atomic_inc(&cm_listens_destroyed);
44607+ atomic_inc_unchecked(&cm_listens_destroyed);
44608 } else {
44609 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
44610 }
44611@@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
44612 cm_node->rem_mac);
44613
44614 add_hte_node(cm_core, cm_node);
44615- atomic_inc(&cm_nodes_created);
44616+ atomic_inc_unchecked(&cm_nodes_created);
44617
44618 return cm_node;
44619 }
44620@@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
44621 }
44622
44623 atomic_dec(&cm_core->node_cnt);
44624- atomic_inc(&cm_nodes_destroyed);
44625+ atomic_inc_unchecked(&cm_nodes_destroyed);
44626 nesqp = cm_node->nesqp;
44627 if (nesqp) {
44628 nesqp->cm_node = NULL;
44629@@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
44630
44631 static void drop_packet(struct sk_buff *skb)
44632 {
44633- atomic_inc(&cm_accel_dropped_pkts);
44634+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
44635 dev_kfree_skb_any(skb);
44636 }
44637
44638@@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
44639 {
44640
44641 int reset = 0; /* whether to send reset in case of err.. */
44642- atomic_inc(&cm_resets_recvd);
44643+ atomic_inc_unchecked(&cm_resets_recvd);
44644 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
44645 " refcnt=%d\n", cm_node, cm_node->state,
44646 atomic_read(&cm_node->ref_count));
44647@@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
44648 rem_ref_cm_node(cm_node->cm_core, cm_node);
44649 return NULL;
44650 }
44651- atomic_inc(&cm_loopbacks);
44652+ atomic_inc_unchecked(&cm_loopbacks);
44653 loopbackremotenode->loopbackpartner = cm_node;
44654 loopbackremotenode->tcp_cntxt.rcv_wscale =
44655 NES_CM_DEFAULT_RCV_WND_SCALE;
44656@@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
44657 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
44658 else {
44659 rem_ref_cm_node(cm_core, cm_node);
44660- atomic_inc(&cm_accel_dropped_pkts);
44661+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
44662 dev_kfree_skb_any(skb);
44663 }
44664 break;
44665@@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
44666
44667 if ((cm_id) && (cm_id->event_handler)) {
44668 if (issue_disconn) {
44669- atomic_inc(&cm_disconnects);
44670+ atomic_inc_unchecked(&cm_disconnects);
44671 cm_event.event = IW_CM_EVENT_DISCONNECT;
44672 cm_event.status = disconn_status;
44673 cm_event.local_addr = cm_id->local_addr;
44674@@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
44675 }
44676
44677 if (issue_close) {
44678- atomic_inc(&cm_closes);
44679+ atomic_inc_unchecked(&cm_closes);
44680 nes_disconnect(nesqp, 1);
44681
44682 cm_id->provider_data = nesqp;
44683@@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
44684
44685 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
44686 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
44687- atomic_inc(&cm_accepts);
44688+ atomic_inc_unchecked(&cm_accepts);
44689
44690 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
44691 netdev_refcnt_read(nesvnic->netdev));
44692@@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
44693 struct nes_cm_core *cm_core;
44694 u8 *start_buff;
44695
44696- atomic_inc(&cm_rejects);
44697+ atomic_inc_unchecked(&cm_rejects);
44698 cm_node = (struct nes_cm_node *)cm_id->provider_data;
44699 loopback = cm_node->loopbackpartner;
44700 cm_core = cm_node->cm_core;
44701@@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
44702 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
44703 ntohs(laddr->sin_port));
44704
44705- atomic_inc(&cm_connects);
44706+ atomic_inc_unchecked(&cm_connects);
44707 nesqp->active_conn = 1;
44708
44709 /* cache the cm_id in the qp */
44710@@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
44711 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
44712 return err;
44713 }
44714- atomic_inc(&cm_listens_created);
44715+ atomic_inc_unchecked(&cm_listens_created);
44716 }
44717
44718 cm_id->add_ref(cm_id);
44719@@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
44720
44721 if (nesqp->destroyed)
44722 return;
44723- atomic_inc(&cm_connecteds);
44724+ atomic_inc_unchecked(&cm_connecteds);
44725 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
44726 " local port 0x%04X. jiffies = %lu.\n",
44727 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
44728@@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
44729
44730 cm_id->add_ref(cm_id);
44731 ret = cm_id->event_handler(cm_id, &cm_event);
44732- atomic_inc(&cm_closes);
44733+ atomic_inc_unchecked(&cm_closes);
44734 cm_event.event = IW_CM_EVENT_CLOSE;
44735 cm_event.status = 0;
44736 cm_event.provider_data = cm_id->provider_data;
44737@@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
44738 return;
44739 cm_id = cm_node->cm_id;
44740
44741- atomic_inc(&cm_connect_reqs);
44742+ atomic_inc_unchecked(&cm_connect_reqs);
44743 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
44744 cm_node, cm_id, jiffies);
44745
44746@@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
44747 return;
44748 cm_id = cm_node->cm_id;
44749
44750- atomic_inc(&cm_connect_reqs);
44751+ atomic_inc_unchecked(&cm_connect_reqs);
44752 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
44753 cm_node, cm_id, jiffies);
44754
44755diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
44756index 4166452..fc952c3 100644
44757--- a/drivers/infiniband/hw/nes/nes_mgt.c
44758+++ b/drivers/infiniband/hw/nes/nes_mgt.c
44759@@ -40,8 +40,8 @@
44760 #include "nes.h"
44761 #include "nes_mgt.h"
44762
44763-atomic_t pau_qps_created;
44764-atomic_t pau_qps_destroyed;
44765+atomic_unchecked_t pau_qps_created;
44766+atomic_unchecked_t pau_qps_destroyed;
44767
44768 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
44769 {
44770@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
44771 {
44772 struct sk_buff *skb;
44773 unsigned long flags;
44774- atomic_inc(&pau_qps_destroyed);
44775+ atomic_inc_unchecked(&pau_qps_destroyed);
44776
44777 /* Free packets that have not yet been forwarded */
44778 /* Lock is acquired by skb_dequeue when removing the skb */
44779@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
44780 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
44781 skb_queue_head_init(&nesqp->pau_list);
44782 spin_lock_init(&nesqp->pau_lock);
44783- atomic_inc(&pau_qps_created);
44784+ atomic_inc_unchecked(&pau_qps_created);
44785 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
44786 }
44787
44788diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
44789index 49eb511..a774366 100644
44790--- a/drivers/infiniband/hw/nes/nes_nic.c
44791+++ b/drivers/infiniband/hw/nes/nes_nic.c
44792@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
44793 target_stat_values[++index] = mh_detected;
44794 target_stat_values[++index] = mh_pauses_sent;
44795 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
44796- target_stat_values[++index] = atomic_read(&cm_connects);
44797- target_stat_values[++index] = atomic_read(&cm_accepts);
44798- target_stat_values[++index] = atomic_read(&cm_disconnects);
44799- target_stat_values[++index] = atomic_read(&cm_connecteds);
44800- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
44801- target_stat_values[++index] = atomic_read(&cm_rejects);
44802- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
44803- target_stat_values[++index] = atomic_read(&qps_created);
44804- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
44805- target_stat_values[++index] = atomic_read(&qps_destroyed);
44806- target_stat_values[++index] = atomic_read(&cm_closes);
44807+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
44808+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
44809+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
44810+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
44811+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
44812+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
44813+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
44814+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
44815+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
44816+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
44817+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
44818 target_stat_values[++index] = cm_packets_sent;
44819 target_stat_values[++index] = cm_packets_bounced;
44820 target_stat_values[++index] = cm_packets_created;
44821 target_stat_values[++index] = cm_packets_received;
44822 target_stat_values[++index] = cm_packets_dropped;
44823 target_stat_values[++index] = cm_packets_retrans;
44824- target_stat_values[++index] = atomic_read(&cm_listens_created);
44825- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
44826+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
44827+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
44828 target_stat_values[++index] = cm_backlog_drops;
44829- target_stat_values[++index] = atomic_read(&cm_loopbacks);
44830- target_stat_values[++index] = atomic_read(&cm_nodes_created);
44831- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
44832- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
44833- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
44834+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
44835+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
44836+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
44837+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
44838+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
44839 target_stat_values[++index] = nesadapter->free_4kpbl;
44840 target_stat_values[++index] = nesadapter->free_256pbl;
44841 target_stat_values[++index] = int_mod_timer_init;
44842 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
44843 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
44844 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
44845- target_stat_values[++index] = atomic_read(&pau_qps_created);
44846- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
44847+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
44848+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
44849 }
44850
44851 /**
44852diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
44853index 218dd35..97ce31d 100644
44854--- a/drivers/infiniband/hw/nes/nes_verbs.c
44855+++ b/drivers/infiniband/hw/nes/nes_verbs.c
44856@@ -46,9 +46,9 @@
44857
44858 #include <rdma/ib_umem.h>
44859
44860-atomic_t mod_qp_timouts;
44861-atomic_t qps_created;
44862-atomic_t sw_qps_destroyed;
44863+atomic_unchecked_t mod_qp_timouts;
44864+atomic_unchecked_t qps_created;
44865+atomic_unchecked_t sw_qps_destroyed;
44866
44867 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
44868
44869@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
44870 if (init_attr->create_flags)
44871 return ERR_PTR(-EINVAL);
44872
44873- atomic_inc(&qps_created);
44874+ atomic_inc_unchecked(&qps_created);
44875 switch (init_attr->qp_type) {
44876 case IB_QPT_RC:
44877 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
44878@@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
44879 struct iw_cm_event cm_event;
44880 int ret = 0;
44881
44882- atomic_inc(&sw_qps_destroyed);
44883+ atomic_inc_unchecked(&sw_qps_destroyed);
44884 nesqp->destroyed = 1;
44885
44886 /* Blow away the connection if it exists. */
44887diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
44888index c00ae09..04e91be 100644
44889--- a/drivers/infiniband/hw/qib/qib.h
44890+++ b/drivers/infiniband/hw/qib/qib.h
44891@@ -52,6 +52,7 @@
44892 #include <linux/kref.h>
44893 #include <linux/sched.h>
44894 #include <linux/kthread.h>
44895+#include <linux/slab.h>
44896
44897 #include "qib_common.h"
44898 #include "qib_verbs.h"
44899diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
44900index 24c41ba..102d71f 100644
44901--- a/drivers/input/gameport/gameport.c
44902+++ b/drivers/input/gameport/gameport.c
44903@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
44904 */
44905 static void gameport_init_port(struct gameport *gameport)
44906 {
44907- static atomic_t gameport_no = ATOMIC_INIT(0);
44908+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
44909
44910 __module_get(THIS_MODULE);
44911
44912 mutex_init(&gameport->drv_mutex);
44913 device_initialize(&gameport->dev);
44914 dev_set_name(&gameport->dev, "gameport%lu",
44915- (unsigned long)atomic_inc_return(&gameport_no) - 1);
44916+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
44917 gameport->dev.bus = &gameport_bus;
44918 gameport->dev.release = gameport_release_port;
44919 if (gameport->parent)
44920diff --git a/drivers/input/input.c b/drivers/input/input.c
44921index 29ca0bb..f4bc2e3 100644
44922--- a/drivers/input/input.c
44923+++ b/drivers/input/input.c
44924@@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
44925 */
44926 struct input_dev *input_allocate_device(void)
44927 {
44928- static atomic_t input_no = ATOMIC_INIT(0);
44929+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
44930 struct input_dev *dev;
44931
44932 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
44933@@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
44934 INIT_LIST_HEAD(&dev->node);
44935
44936 dev_set_name(&dev->dev, "input%ld",
44937- (unsigned long) atomic_inc_return(&input_no) - 1);
44938+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
44939
44940 __module_get(THIS_MODULE);
44941 }
44942diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
44943index 4a95b22..874c182 100644
44944--- a/drivers/input/joystick/sidewinder.c
44945+++ b/drivers/input/joystick/sidewinder.c
44946@@ -30,6 +30,7 @@
44947 #include <linux/kernel.h>
44948 #include <linux/module.h>
44949 #include <linux/slab.h>
44950+#include <linux/sched.h>
44951 #include <linux/input.h>
44952 #include <linux/gameport.h>
44953 #include <linux/jiffies.h>
44954diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
44955index 603fe0d..f63decc 100644
44956--- a/drivers/input/joystick/xpad.c
44957+++ b/drivers/input/joystick/xpad.c
44958@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
44959
44960 static int xpad_led_probe(struct usb_xpad *xpad)
44961 {
44962- static atomic_t led_seq = ATOMIC_INIT(0);
44963+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
44964 long led_no;
44965 struct xpad_led *led;
44966 struct led_classdev *led_cdev;
44967@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
44968 if (!led)
44969 return -ENOMEM;
44970
44971- led_no = (long)atomic_inc_return(&led_seq) - 1;
44972+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
44973
44974 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
44975 led->xpad = xpad;
44976diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
44977index 719410f..1896169 100644
44978--- a/drivers/input/misc/ims-pcu.c
44979+++ b/drivers/input/misc/ims-pcu.c
44980@@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
44981
44982 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44983 {
44984- static atomic_t device_no = ATOMIC_INIT(0);
44985+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
44986
44987 const struct ims_pcu_device_info *info;
44988 int error;
44989@@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44990 }
44991
44992 /* Device appears to be operable, complete initialization */
44993- pcu->device_no = atomic_inc_return(&device_no) - 1;
44994+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
44995
44996 /*
44997 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
44998diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
44999index 2f0b39d..7370f13 100644
45000--- a/drivers/input/mouse/psmouse.h
45001+++ b/drivers/input/mouse/psmouse.h
45002@@ -116,7 +116,7 @@ struct psmouse_attribute {
45003 ssize_t (*set)(struct psmouse *psmouse, void *data,
45004 const char *buf, size_t count);
45005 bool protect;
45006-};
45007+} __do_const;
45008 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
45009
45010 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
45011diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
45012index b604564..3f14ae4 100644
45013--- a/drivers/input/mousedev.c
45014+++ b/drivers/input/mousedev.c
45015@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
45016
45017 spin_unlock_irq(&client->packet_lock);
45018
45019- if (copy_to_user(buffer, data, count))
45020+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
45021 return -EFAULT;
45022
45023 return count;
45024diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
45025index b29134d..394deb0 100644
45026--- a/drivers/input/serio/serio.c
45027+++ b/drivers/input/serio/serio.c
45028@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
45029 */
45030 static void serio_init_port(struct serio *serio)
45031 {
45032- static atomic_t serio_no = ATOMIC_INIT(0);
45033+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
45034
45035 __module_get(THIS_MODULE);
45036
45037@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
45038 mutex_init(&serio->drv_mutex);
45039 device_initialize(&serio->dev);
45040 dev_set_name(&serio->dev, "serio%ld",
45041- (long)atomic_inc_return(&serio_no) - 1);
45042+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
45043 serio->dev.bus = &serio_bus;
45044 serio->dev.release = serio_release_port;
45045 serio->dev.groups = serio_device_attr_groups;
45046diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
45047index c9a02fe..0debc75 100644
45048--- a/drivers/input/serio/serio_raw.c
45049+++ b/drivers/input/serio/serio_raw.c
45050@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
45051
45052 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
45053 {
45054- static atomic_t serio_raw_no = ATOMIC_INIT(0);
45055+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
45056 struct serio_raw *serio_raw;
45057 int err;
45058
45059@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
45060 }
45061
45062 snprintf(serio_raw->name, sizeof(serio_raw->name),
45063- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
45064+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
45065 kref_init(&serio_raw->kref);
45066 INIT_LIST_HEAD(&serio_raw->client_list);
45067 init_waitqueue_head(&serio_raw->wait);
45068diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
45069index e5555fc..937986d 100644
45070--- a/drivers/iommu/iommu.c
45071+++ b/drivers/iommu/iommu.c
45072@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
45073 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
45074 {
45075 bus_register_notifier(bus, &iommu_bus_nb);
45076- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
45077+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
45078 }
45079
45080 /**
45081diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
45082index 33c4395..e06447e 100644
45083--- a/drivers/iommu/irq_remapping.c
45084+++ b/drivers/iommu/irq_remapping.c
45085@@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
45086 void panic_if_irq_remap(const char *msg)
45087 {
45088 if (irq_remapping_enabled)
45089- panic(msg);
45090+ panic("%s", msg);
45091 }
45092
45093 static void ir_ack_apic_edge(struct irq_data *data)
45094@@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
45095
45096 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
45097 {
45098- chip->irq_print_chip = ir_print_prefix;
45099- chip->irq_ack = ir_ack_apic_edge;
45100- chip->irq_eoi = ir_ack_apic_level;
45101- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
45102+ pax_open_kernel();
45103+ *(void **)&chip->irq_print_chip = ir_print_prefix;
45104+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
45105+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
45106+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
45107+ pax_close_kernel();
45108 }
45109
45110 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
45111diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
45112index 7c131cf..035129b 100644
45113--- a/drivers/irqchip/irq-gic.c
45114+++ b/drivers/irqchip/irq-gic.c
45115@@ -85,7 +85,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
45116 * Supported arch specific GIC irq extension.
45117 * Default make them NULL.
45118 */
45119-struct irq_chip gic_arch_extn = {
45120+irq_chip_no_const gic_arch_extn = {
45121 .irq_eoi = NULL,
45122 .irq_mask = NULL,
45123 .irq_unmask = NULL,
45124@@ -337,7 +337,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
45125 chained_irq_exit(chip, desc);
45126 }
45127
45128-static struct irq_chip gic_chip = {
45129+static irq_chip_no_const gic_chip __read_only = {
45130 .name = "GIC",
45131 .irq_mask = gic_mask_irq,
45132 .irq_unmask = gic_unmask_irq,
45133diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
45134index 8777065..a4a9967 100644
45135--- a/drivers/irqchip/irq-renesas-irqc.c
45136+++ b/drivers/irqchip/irq-renesas-irqc.c
45137@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
45138 struct irqc_priv *p;
45139 struct resource *io;
45140 struct resource *irq;
45141- struct irq_chip *irq_chip;
45142+ irq_chip_no_const *irq_chip;
45143 const char *name = dev_name(&pdev->dev);
45144 int ret;
45145 int k;
45146diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
45147index f9a87ed..3fdd854 100644
45148--- a/drivers/isdn/capi/capi.c
45149+++ b/drivers/isdn/capi/capi.c
45150@@ -81,8 +81,8 @@ struct capiminor {
45151
45152 struct capi20_appl *ap;
45153 u32 ncci;
45154- atomic_t datahandle;
45155- atomic_t msgid;
45156+ atomic_unchecked_t datahandle;
45157+ atomic_unchecked_t msgid;
45158
45159 struct tty_port port;
45160 int ttyinstop;
45161@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
45162 capimsg_setu16(s, 2, mp->ap->applid);
45163 capimsg_setu8 (s, 4, CAPI_DATA_B3);
45164 capimsg_setu8 (s, 5, CAPI_RESP);
45165- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
45166+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
45167 capimsg_setu32(s, 8, mp->ncci);
45168 capimsg_setu16(s, 12, datahandle);
45169 }
45170@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
45171 mp->outbytes -= len;
45172 spin_unlock_bh(&mp->outlock);
45173
45174- datahandle = atomic_inc_return(&mp->datahandle);
45175+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
45176 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
45177 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
45178 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
45179 capimsg_setu16(skb->data, 2, mp->ap->applid);
45180 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
45181 capimsg_setu8 (skb->data, 5, CAPI_REQ);
45182- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
45183+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
45184 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
45185 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
45186 capimsg_setu16(skb->data, 16, len); /* Data length */
45187diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
45188index b7ae0a0..04590fa 100644
45189--- a/drivers/isdn/gigaset/bas-gigaset.c
45190+++ b/drivers/isdn/gigaset/bas-gigaset.c
45191@@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
45192
45193
45194 static const struct gigaset_ops gigops = {
45195- gigaset_write_cmd,
45196- gigaset_write_room,
45197- gigaset_chars_in_buffer,
45198- gigaset_brkchars,
45199- gigaset_init_bchannel,
45200- gigaset_close_bchannel,
45201- gigaset_initbcshw,
45202- gigaset_freebcshw,
45203- gigaset_reinitbcshw,
45204- gigaset_initcshw,
45205- gigaset_freecshw,
45206- gigaset_set_modem_ctrl,
45207- gigaset_baud_rate,
45208- gigaset_set_line_ctrl,
45209- gigaset_isoc_send_skb,
45210- gigaset_isoc_input,
45211+ .write_cmd = gigaset_write_cmd,
45212+ .write_room = gigaset_write_room,
45213+ .chars_in_buffer = gigaset_chars_in_buffer,
45214+ .brkchars = gigaset_brkchars,
45215+ .init_bchannel = gigaset_init_bchannel,
45216+ .close_bchannel = gigaset_close_bchannel,
45217+ .initbcshw = gigaset_initbcshw,
45218+ .freebcshw = gigaset_freebcshw,
45219+ .reinitbcshw = gigaset_reinitbcshw,
45220+ .initcshw = gigaset_initcshw,
45221+ .freecshw = gigaset_freecshw,
45222+ .set_modem_ctrl = gigaset_set_modem_ctrl,
45223+ .baud_rate = gigaset_baud_rate,
45224+ .set_line_ctrl = gigaset_set_line_ctrl,
45225+ .send_skb = gigaset_isoc_send_skb,
45226+ .handle_input = gigaset_isoc_input,
45227 };
45228
45229 /* bas_gigaset_init
45230diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
45231index 600c79b..3752bab 100644
45232--- a/drivers/isdn/gigaset/interface.c
45233+++ b/drivers/isdn/gigaset/interface.c
45234@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
45235 }
45236 tty->driver_data = cs;
45237
45238- ++cs->port.count;
45239+ atomic_inc(&cs->port.count);
45240
45241- if (cs->port.count == 1) {
45242+ if (atomic_read(&cs->port.count) == 1) {
45243 tty_port_tty_set(&cs->port, tty);
45244 cs->port.low_latency = 1;
45245 }
45246@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
45247
45248 if (!cs->connected)
45249 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
45250- else if (!cs->port.count)
45251+ else if (!atomic_read(&cs->port.count))
45252 dev_warn(cs->dev, "%s: device not opened\n", __func__);
45253- else if (!--cs->port.count)
45254+ else if (!atomic_dec_return(&cs->port.count))
45255 tty_port_tty_set(&cs->port, NULL);
45256
45257 mutex_unlock(&cs->mutex);
45258diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
45259index 8c91fd5..14f13ce 100644
45260--- a/drivers/isdn/gigaset/ser-gigaset.c
45261+++ b/drivers/isdn/gigaset/ser-gigaset.c
45262@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
45263 }
45264
45265 static const struct gigaset_ops ops = {
45266- gigaset_write_cmd,
45267- gigaset_write_room,
45268- gigaset_chars_in_buffer,
45269- gigaset_brkchars,
45270- gigaset_init_bchannel,
45271- gigaset_close_bchannel,
45272- gigaset_initbcshw,
45273- gigaset_freebcshw,
45274- gigaset_reinitbcshw,
45275- gigaset_initcshw,
45276- gigaset_freecshw,
45277- gigaset_set_modem_ctrl,
45278- gigaset_baud_rate,
45279- gigaset_set_line_ctrl,
45280- gigaset_m10x_send_skb, /* asyncdata.c */
45281- gigaset_m10x_input, /* asyncdata.c */
45282+ .write_cmd = gigaset_write_cmd,
45283+ .write_room = gigaset_write_room,
45284+ .chars_in_buffer = gigaset_chars_in_buffer,
45285+ .brkchars = gigaset_brkchars,
45286+ .init_bchannel = gigaset_init_bchannel,
45287+ .close_bchannel = gigaset_close_bchannel,
45288+ .initbcshw = gigaset_initbcshw,
45289+ .freebcshw = gigaset_freebcshw,
45290+ .reinitbcshw = gigaset_reinitbcshw,
45291+ .initcshw = gigaset_initcshw,
45292+ .freecshw = gigaset_freecshw,
45293+ .set_modem_ctrl = gigaset_set_modem_ctrl,
45294+ .baud_rate = gigaset_baud_rate,
45295+ .set_line_ctrl = gigaset_set_line_ctrl,
45296+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
45297+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
45298 };
45299
45300
45301diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
45302index d0a41cb..b953e50 100644
45303--- a/drivers/isdn/gigaset/usb-gigaset.c
45304+++ b/drivers/isdn/gigaset/usb-gigaset.c
45305@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
45306 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
45307 memcpy(cs->hw.usb->bchars, buf, 6);
45308 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
45309- 0, 0, &buf, 6, 2000);
45310+ 0, 0, buf, 6, 2000);
45311 }
45312
45313 static void gigaset_freebcshw(struct bc_state *bcs)
45314@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
45315 }
45316
45317 static const struct gigaset_ops ops = {
45318- gigaset_write_cmd,
45319- gigaset_write_room,
45320- gigaset_chars_in_buffer,
45321- gigaset_brkchars,
45322- gigaset_init_bchannel,
45323- gigaset_close_bchannel,
45324- gigaset_initbcshw,
45325- gigaset_freebcshw,
45326- gigaset_reinitbcshw,
45327- gigaset_initcshw,
45328- gigaset_freecshw,
45329- gigaset_set_modem_ctrl,
45330- gigaset_baud_rate,
45331- gigaset_set_line_ctrl,
45332- gigaset_m10x_send_skb,
45333- gigaset_m10x_input,
45334+ .write_cmd = gigaset_write_cmd,
45335+ .write_room = gigaset_write_room,
45336+ .chars_in_buffer = gigaset_chars_in_buffer,
45337+ .brkchars = gigaset_brkchars,
45338+ .init_bchannel = gigaset_init_bchannel,
45339+ .close_bchannel = gigaset_close_bchannel,
45340+ .initbcshw = gigaset_initbcshw,
45341+ .freebcshw = gigaset_freebcshw,
45342+ .reinitbcshw = gigaset_reinitbcshw,
45343+ .initcshw = gigaset_initcshw,
45344+ .freecshw = gigaset_freecshw,
45345+ .set_modem_ctrl = gigaset_set_modem_ctrl,
45346+ .baud_rate = gigaset_baud_rate,
45347+ .set_line_ctrl = gigaset_set_line_ctrl,
45348+ .send_skb = gigaset_m10x_send_skb,
45349+ .handle_input = gigaset_m10x_input,
45350 };
45351
45352 /*
45353diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
45354index 4d9b195..455075c 100644
45355--- a/drivers/isdn/hardware/avm/b1.c
45356+++ b/drivers/isdn/hardware/avm/b1.c
45357@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
45358 }
45359 if (left) {
45360 if (t4file->user) {
45361- if (copy_from_user(buf, dp, left))
45362+ if (left > sizeof buf || copy_from_user(buf, dp, left))
45363 return -EFAULT;
45364 } else {
45365 memcpy(buf, dp, left);
45366@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
45367 }
45368 if (left) {
45369 if (config->user) {
45370- if (copy_from_user(buf, dp, left))
45371+ if (left > sizeof buf || copy_from_user(buf, dp, left))
45372 return -EFAULT;
45373 } else {
45374 memcpy(buf, dp, left);
45375diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
45376index 9b856e1..fa03c92 100644
45377--- a/drivers/isdn/i4l/isdn_common.c
45378+++ b/drivers/isdn/i4l/isdn_common.c
45379@@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
45380 } else
45381 return -EINVAL;
45382 case IIOCDBGVAR:
45383+ if (!capable(CAP_SYS_RAWIO))
45384+ return -EPERM;
45385 if (arg) {
45386 if (copy_to_user(argp, &dev, sizeof(ulong)))
45387 return -EFAULT;
45388diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
45389index 91d5730..336523e 100644
45390--- a/drivers/isdn/i4l/isdn_concap.c
45391+++ b/drivers/isdn/i4l/isdn_concap.c
45392@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
45393 }
45394
45395 struct concap_device_ops isdn_concap_reliable_dl_dops = {
45396- &isdn_concap_dl_data_req,
45397- &isdn_concap_dl_connect_req,
45398- &isdn_concap_dl_disconn_req
45399+ .data_req = &isdn_concap_dl_data_req,
45400+ .connect_req = &isdn_concap_dl_connect_req,
45401+ .disconn_req = &isdn_concap_dl_disconn_req
45402 };
45403
45404 /* The following should better go into a dedicated source file such that
45405diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
45406index 62f0688..38ceac5 100644
45407--- a/drivers/isdn/i4l/isdn_ppp.c
45408+++ b/drivers/isdn/i4l/isdn_ppp.c
45409@@ -378,15 +378,10 @@ isdn_ppp_release(int min, struct file *file)
45410 is->slcomp = NULL;
45411 #endif
45412 #ifdef CONFIG_IPPP_FILTER
45413- if (is->pass_filter) {
45414- sk_unattached_filter_destroy(is->pass_filter);
45415- is->pass_filter = NULL;
45416- }
45417-
45418- if (is->active_filter) {
45419- sk_unattached_filter_destroy(is->active_filter);
45420- is->active_filter = NULL;
45421- }
45422+ kfree(is->pass_filter);
45423+ is->pass_filter = NULL;
45424+ kfree(is->active_filter);
45425+ is->active_filter = NULL;
45426 #endif
45427
45428 /* TODO: if this was the previous master: link the stuff to the new master */
45429@@ -442,7 +437,7 @@ static int get_filter(void __user *arg, struct sock_filter **p)
45430 {
45431 struct sock_fprog uprog;
45432 struct sock_filter *code = NULL;
45433- int len;
45434+ int len, err;
45435
45436 if (copy_from_user(&uprog, arg, sizeof(uprog)))
45437 return -EFAULT;
45438@@ -458,6 +453,12 @@ static int get_filter(void __user *arg, struct sock_filter **p)
45439 if (IS_ERR(code))
45440 return PTR_ERR(code);
45441
45442+ err = sk_chk_filter(code, uprog.len);
45443+ if (err) {
45444+ kfree(code);
45445+ return err;
45446+ }
45447+
45448 *p = code;
45449 return uprog.len;
45450 }
45451@@ -628,53 +629,25 @@ isdn_ppp_ioctl(int min, struct file *file, unsigned int cmd, unsigned long arg)
45452 #ifdef CONFIG_IPPP_FILTER
45453 case PPPIOCSPASS:
45454 {
45455- struct sock_fprog_kern fprog;
45456 struct sock_filter *code;
45457- int err, len = get_filter(argp, &code);
45458-
45459+ int len = get_filter(argp, &code);
45460 if (len < 0)
45461 return len;
45462-
45463- fprog.len = len;
45464- fprog.filter = code;
45465-
45466- if (is->pass_filter) {
45467- sk_unattached_filter_destroy(is->pass_filter);
45468- is->pass_filter = NULL;
45469- }
45470- if (fprog.filter != NULL)
45471- err = sk_unattached_filter_create(&is->pass_filter,
45472- &fprog);
45473- else
45474- err = 0;
45475- kfree(code);
45476-
45477- return err;
45478+ kfree(is->pass_filter);
45479+ is->pass_filter = code;
45480+ is->pass_len = len;
45481+ break;
45482 }
45483 case PPPIOCSACTIVE:
45484 {
45485- struct sock_fprog_kern fprog;
45486 struct sock_filter *code;
45487- int err, len = get_filter(argp, &code);
45488-
45489+ int len = get_filter(argp, &code);
45490 if (len < 0)
45491 return len;
45492-
45493- fprog.len = len;
45494- fprog.filter = code;
45495-
45496- if (is->active_filter) {
45497- sk_unattached_filter_destroy(is->active_filter);
45498- is->active_filter = NULL;
45499- }
45500- if (fprog.filter != NULL)
45501- err = sk_unattached_filter_create(&is->active_filter,
45502- &fprog);
45503- else
45504- err = 0;
45505- kfree(code);
45506-
45507- return err;
45508+ kfree(is->active_filter);
45509+ is->active_filter = code;
45510+ is->active_len = len;
45511+ break;
45512 }
45513 #endif /* CONFIG_IPPP_FILTER */
45514 default:
45515@@ -1174,14 +1147,14 @@ isdn_ppp_push_higher(isdn_net_dev *net_dev, isdn_net_local *lp, struct sk_buff *
45516 }
45517
45518 if (is->pass_filter
45519- && SK_RUN_FILTER(is->pass_filter, skb) == 0) {
45520+ && sk_run_filter(skb, is->pass_filter) == 0) {
45521 if (is->debug & 0x2)
45522 printk(KERN_DEBUG "IPPP: inbound frame filtered.\n");
45523 kfree_skb(skb);
45524 return;
45525 }
45526 if (!(is->active_filter
45527- && SK_RUN_FILTER(is->active_filter, skb) == 0)) {
45528+ && sk_run_filter(skb, is->active_filter) == 0)) {
45529 if (is->debug & 0x2)
45530 printk(KERN_DEBUG "IPPP: link-active filter: resetting huptimer.\n");
45531 lp->huptimer = 0;
45532@@ -1320,14 +1293,14 @@ isdn_ppp_xmit(struct sk_buff *skb, struct net_device *netdev)
45533 }
45534
45535 if (ipt->pass_filter
45536- && SK_RUN_FILTER(ipt->pass_filter, skb) == 0) {
45537+ && sk_run_filter(skb, ipt->pass_filter) == 0) {
45538 if (ipt->debug & 0x4)
45539 printk(KERN_DEBUG "IPPP: outbound frame filtered.\n");
45540 kfree_skb(skb);
45541 goto unlock;
45542 }
45543 if (!(ipt->active_filter
45544- && SK_RUN_FILTER(ipt->active_filter, skb) == 0)) {
45545+ && sk_run_filter(skb, ipt->active_filter) == 0)) {
45546 if (ipt->debug & 0x4)
45547 printk(KERN_DEBUG "IPPP: link-active filter: resetting huptimer.\n");
45548 lp->huptimer = 0;
45549@@ -1517,9 +1490,9 @@ int isdn_ppp_autodial_filter(struct sk_buff *skb, isdn_net_local *lp)
45550 }
45551
45552 drop |= is->pass_filter
45553- && SK_RUN_FILTER(is->pass_filter, skb) == 0;
45554+ && sk_run_filter(skb, is->pass_filter) == 0;
45555 drop |= is->active_filter
45556- && SK_RUN_FILTER(is->active_filter, skb) == 0;
45557+ && sk_run_filter(skb, is->active_filter) == 0;
45558
45559 skb_push(skb, IPPP_MAX_HEADER - 4);
45560 return drop;
45561diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
45562index 3c5f249..5fac4d0 100644
45563--- a/drivers/isdn/i4l/isdn_tty.c
45564+++ b/drivers/isdn/i4l/isdn_tty.c
45565@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
45566
45567 #ifdef ISDN_DEBUG_MODEM_OPEN
45568 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
45569- port->count);
45570+ atomic_read(&port->count));
45571 #endif
45572- port->count++;
45573+ atomic_inc(&port->count);
45574 port->tty = tty;
45575 /*
45576 * Start up serial port
45577@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
45578 #endif
45579 return;
45580 }
45581- if ((tty->count == 1) && (port->count != 1)) {
45582+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
45583 /*
45584 * Uh, oh. tty->count is 1, which means that the tty
45585 * structure will be freed. Info->count should always
45586@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
45587 * serial port won't be shutdown.
45588 */
45589 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
45590- "info->count is %d\n", port->count);
45591- port->count = 1;
45592+ "info->count is %d\n", atomic_read(&port->count));
45593+ atomic_set(&port->count, 1);
45594 }
45595- if (--port->count < 0) {
45596+ if (atomic_dec_return(&port->count) < 0) {
45597 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
45598- info->line, port->count);
45599- port->count = 0;
45600+ info->line, atomic_read(&port->count));
45601+ atomic_set(&port->count, 0);
45602 }
45603- if (port->count) {
45604+ if (atomic_read(&port->count)) {
45605 #ifdef ISDN_DEBUG_MODEM_OPEN
45606 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
45607 #endif
45608@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
45609 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
45610 return;
45611 isdn_tty_shutdown(info);
45612- port->count = 0;
45613+ atomic_set(&port->count, 0);
45614 port->flags &= ~ASYNC_NORMAL_ACTIVE;
45615 port->tty = NULL;
45616 wake_up_interruptible(&port->open_wait);
45617@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
45618 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
45619 modem_info *info = &dev->mdm.info[i];
45620
45621- if (info->port.count == 0)
45622+ if (atomic_read(&info->port.count) == 0)
45623 continue;
45624 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
45625 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
45626diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
45627index e2d4e58..40cd045 100644
45628--- a/drivers/isdn/i4l/isdn_x25iface.c
45629+++ b/drivers/isdn/i4l/isdn_x25iface.c
45630@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
45631
45632
45633 static struct concap_proto_ops ix25_pops = {
45634- &isdn_x25iface_proto_new,
45635- &isdn_x25iface_proto_del,
45636- &isdn_x25iface_proto_restart,
45637- &isdn_x25iface_proto_close,
45638- &isdn_x25iface_xmit,
45639- &isdn_x25iface_receive,
45640- &isdn_x25iface_connect_ind,
45641- &isdn_x25iface_disconn_ind
45642+ .proto_new = &isdn_x25iface_proto_new,
45643+ .proto_del = &isdn_x25iface_proto_del,
45644+ .restart = &isdn_x25iface_proto_restart,
45645+ .close = &isdn_x25iface_proto_close,
45646+ .encap_and_xmit = &isdn_x25iface_xmit,
45647+ .data_ind = &isdn_x25iface_receive,
45648+ .connect_ind = &isdn_x25iface_connect_ind,
45649+ .disconn_ind = &isdn_x25iface_disconn_ind
45650 };
45651
45652 /* error message helper function */
45653diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
45654index 6a7447c..cae33fe 100644
45655--- a/drivers/isdn/icn/icn.c
45656+++ b/drivers/isdn/icn/icn.c
45657@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
45658 if (count > len)
45659 count = len;
45660 if (user) {
45661- if (copy_from_user(msg, buf, count))
45662+ if (count > sizeof msg || copy_from_user(msg, buf, count))
45663 return -EFAULT;
45664 } else
45665 memcpy(msg, buf, count);
45666diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
45667index a4f05c5..1433bc5 100644
45668--- a/drivers/isdn/mISDN/dsp_cmx.c
45669+++ b/drivers/isdn/mISDN/dsp_cmx.c
45670@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
45671 static u16 dsp_count; /* last sample count */
45672 static int dsp_count_valid; /* if we have last sample count */
45673
45674-void
45675+void __intentional_overflow(-1)
45676 dsp_cmx_send(void *arg)
45677 {
45678 struct dsp_conf *conf;
45679diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
45680index f58a354..fbae176 100644
45681--- a/drivers/leds/leds-clevo-mail.c
45682+++ b/drivers/leds/leds-clevo-mail.c
45683@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
45684 * detected as working, but in reality it is not) as low as
45685 * possible.
45686 */
45687-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
45688+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
45689 {
45690 .callback = clevo_mail_led_dmi_callback,
45691 .ident = "Clevo D410J",
45692diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
45693index 2eb3ef6..295891f 100644
45694--- a/drivers/leds/leds-ss4200.c
45695+++ b/drivers/leds/leds-ss4200.c
45696@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
45697 * detected as working, but in reality it is not) as low as
45698 * possible.
45699 */
45700-static struct dmi_system_id nas_led_whitelist[] __initdata = {
45701+static struct dmi_system_id nas_led_whitelist[] __initconst = {
45702 {
45703 .callback = ss4200_led_dmi_callback,
45704 .ident = "Intel SS4200-E",
45705diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
45706index 0bf1e4e..b4bf44e 100644
45707--- a/drivers/lguest/core.c
45708+++ b/drivers/lguest/core.c
45709@@ -97,9 +97,17 @@ static __init int map_switcher(void)
45710 * The end address needs +1 because __get_vm_area allocates an
45711 * extra guard page, so we need space for that.
45712 */
45713+
45714+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
45715+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
45716+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
45717+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
45718+#else
45719 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
45720 VM_ALLOC, switcher_addr, switcher_addr
45721 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
45722+#endif
45723+
45724 if (!switcher_vma) {
45725 err = -ENOMEM;
45726 printk("lguest: could not map switcher pages high\n");
45727@@ -124,7 +132,7 @@ static __init int map_switcher(void)
45728 * Now the Switcher is mapped at the right address, we can't fail!
45729 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
45730 */
45731- memcpy(switcher_vma->addr, start_switcher_text,
45732+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
45733 end_switcher_text - start_switcher_text);
45734
45735 printk(KERN_INFO "lguest: mapped switcher at %p\n",
45736diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
45737index e8b55c3..3514c37 100644
45738--- a/drivers/lguest/page_tables.c
45739+++ b/drivers/lguest/page_tables.c
45740@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
45741 /*:*/
45742
45743 #ifdef CONFIG_X86_PAE
45744-static void release_pmd(pmd_t *spmd)
45745+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
45746 {
45747 /* If the entry's not present, there's nothing to release. */
45748 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
45749diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
45750index 922a1ac..9dd0c2a 100644
45751--- a/drivers/lguest/x86/core.c
45752+++ b/drivers/lguest/x86/core.c
45753@@ -59,7 +59,7 @@ static struct {
45754 /* Offset from where switcher.S was compiled to where we've copied it */
45755 static unsigned long switcher_offset(void)
45756 {
45757- return switcher_addr - (unsigned long)start_switcher_text;
45758+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
45759 }
45760
45761 /* This cpu's struct lguest_pages (after the Switcher text page) */
45762@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
45763 * These copies are pretty cheap, so we do them unconditionally: */
45764 /* Save the current Host top-level page directory.
45765 */
45766+
45767+#ifdef CONFIG_PAX_PER_CPU_PGD
45768+ pages->state.host_cr3 = read_cr3();
45769+#else
45770 pages->state.host_cr3 = __pa(current->mm->pgd);
45771+#endif
45772+
45773 /*
45774 * Set up the Guest's page tables to see this CPU's pages (and no
45775 * other CPU's pages).
45776@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
45777 * compiled-in switcher code and the high-mapped copy we just made.
45778 */
45779 for (i = 0; i < IDT_ENTRIES; i++)
45780- default_idt_entries[i] += switcher_offset();
45781+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
45782
45783 /*
45784 * Set up the Switcher's per-cpu areas.
45785@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
45786 * it will be undisturbed when we switch. To change %cs and jump we
45787 * need this structure to feed to Intel's "lcall" instruction.
45788 */
45789- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
45790+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
45791 lguest_entry.segment = LGUEST_CS;
45792
45793 /*
45794diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
45795index 40634b0..4f5855e 100644
45796--- a/drivers/lguest/x86/switcher_32.S
45797+++ b/drivers/lguest/x86/switcher_32.S
45798@@ -87,6 +87,7 @@
45799 #include <asm/page.h>
45800 #include <asm/segment.h>
45801 #include <asm/lguest.h>
45802+#include <asm/processor-flags.h>
45803
45804 // We mark the start of the code to copy
45805 // It's placed in .text tho it's never run here
45806@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
45807 // Changes type when we load it: damn Intel!
45808 // For after we switch over our page tables
45809 // That entry will be read-only: we'd crash.
45810+
45811+#ifdef CONFIG_PAX_KERNEXEC
45812+ mov %cr0, %edx
45813+ xor $X86_CR0_WP, %edx
45814+ mov %edx, %cr0
45815+#endif
45816+
45817 movl $(GDT_ENTRY_TSS*8), %edx
45818 ltr %dx
45819
45820@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
45821 // Let's clear it again for our return.
45822 // The GDT descriptor of the Host
45823 // Points to the table after two "size" bytes
45824- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
45825+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
45826 // Clear "used" from type field (byte 5, bit 2)
45827- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
45828+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
45829+
45830+#ifdef CONFIG_PAX_KERNEXEC
45831+ mov %cr0, %eax
45832+ xor $X86_CR0_WP, %eax
45833+ mov %eax, %cr0
45834+#endif
45835
45836 // Once our page table's switched, the Guest is live!
45837 // The Host fades as we run this final step.
45838@@ -295,13 +309,12 @@ deliver_to_host:
45839 // I consulted gcc, and it gave
45840 // These instructions, which I gladly credit:
45841 leal (%edx,%ebx,8), %eax
45842- movzwl (%eax),%edx
45843- movl 4(%eax), %eax
45844- xorw %ax, %ax
45845- orl %eax, %edx
45846+ movl 4(%eax), %edx
45847+ movw (%eax), %dx
45848 // Now the address of the handler's in %edx
45849 // We call it now: its "iret" drops us home.
45850- jmp *%edx
45851+ ljmp $__KERNEL_CS, $1f
45852+1: jmp *%edx
45853
45854 // Every interrupt can come to us here
45855 // But we must truly tell each apart.
45856diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
45857index a08e3ee..df8ade2 100644
45858--- a/drivers/md/bcache/closure.h
45859+++ b/drivers/md/bcache/closure.h
45860@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
45861 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
45862 struct workqueue_struct *wq)
45863 {
45864- BUG_ON(object_is_on_stack(cl));
45865+ BUG_ON(object_starts_on_stack(cl));
45866 closure_set_ip(cl);
45867 cl->fn = fn;
45868 cl->wq = wq;
45869diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
45870index 67f8b31..9418f2b 100644
45871--- a/drivers/md/bitmap.c
45872+++ b/drivers/md/bitmap.c
45873@@ -1775,7 +1775,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
45874 chunk_kb ? "KB" : "B");
45875 if (bitmap->storage.file) {
45876 seq_printf(seq, ", file: ");
45877- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
45878+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
45879 }
45880
45881 seq_printf(seq, "\n");
45882diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
45883index 5152142..623d141 100644
45884--- a/drivers/md/dm-ioctl.c
45885+++ b/drivers/md/dm-ioctl.c
45886@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
45887 cmd == DM_LIST_VERSIONS_CMD)
45888 return 0;
45889
45890- if ((cmd == DM_DEV_CREATE_CMD)) {
45891+ if (cmd == DM_DEV_CREATE_CMD) {
45892 if (!*param->name) {
45893 DMWARN("name not supplied when creating device");
45894 return -EINVAL;
45895diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
45896index 7dfdb5c..4caada6 100644
45897--- a/drivers/md/dm-raid1.c
45898+++ b/drivers/md/dm-raid1.c
45899@@ -40,7 +40,7 @@ enum dm_raid1_error {
45900
45901 struct mirror {
45902 struct mirror_set *ms;
45903- atomic_t error_count;
45904+ atomic_unchecked_t error_count;
45905 unsigned long error_type;
45906 struct dm_dev *dev;
45907 sector_t offset;
45908@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
45909 struct mirror *m;
45910
45911 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
45912- if (!atomic_read(&m->error_count))
45913+ if (!atomic_read_unchecked(&m->error_count))
45914 return m;
45915
45916 return NULL;
45917@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
45918 * simple way to tell if a device has encountered
45919 * errors.
45920 */
45921- atomic_inc(&m->error_count);
45922+ atomic_inc_unchecked(&m->error_count);
45923
45924 if (test_and_set_bit(error_type, &m->error_type))
45925 return;
45926@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
45927 struct mirror *m = get_default_mirror(ms);
45928
45929 do {
45930- if (likely(!atomic_read(&m->error_count)))
45931+ if (likely(!atomic_read_unchecked(&m->error_count)))
45932 return m;
45933
45934 if (m-- == ms->mirror)
45935@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
45936 {
45937 struct mirror *default_mirror = get_default_mirror(m->ms);
45938
45939- return !atomic_read(&default_mirror->error_count);
45940+ return !atomic_read_unchecked(&default_mirror->error_count);
45941 }
45942
45943 static int mirror_available(struct mirror_set *ms, struct bio *bio)
45944@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
45945 */
45946 if (likely(region_in_sync(ms, region, 1)))
45947 m = choose_mirror(ms, bio->bi_iter.bi_sector);
45948- else if (m && atomic_read(&m->error_count))
45949+ else if (m && atomic_read_unchecked(&m->error_count))
45950 m = NULL;
45951
45952 if (likely(m))
45953@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
45954 }
45955
45956 ms->mirror[mirror].ms = ms;
45957- atomic_set(&(ms->mirror[mirror].error_count), 0);
45958+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
45959 ms->mirror[mirror].error_type = 0;
45960 ms->mirror[mirror].offset = offset;
45961
45962@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
45963 */
45964 static char device_status_char(struct mirror *m)
45965 {
45966- if (!atomic_read(&(m->error_count)))
45967+ if (!atomic_read_unchecked(&(m->error_count)))
45968 return 'A';
45969
45970 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
45971diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
45972index 28a9012..9c0f6a5 100644
45973--- a/drivers/md/dm-stats.c
45974+++ b/drivers/md/dm-stats.c
45975@@ -382,7 +382,7 @@ do_sync_free:
45976 synchronize_rcu_expedited();
45977 dm_stat_free(&s->rcu_head);
45978 } else {
45979- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
45980+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
45981 call_rcu(&s->rcu_head, dm_stat_free);
45982 }
45983 return 0;
45984@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
45985 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
45986 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
45987 ));
45988- ACCESS_ONCE(last->last_sector) = end_sector;
45989- ACCESS_ONCE(last->last_rw) = bi_rw;
45990+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
45991+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
45992 }
45993
45994 rcu_read_lock();
45995diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
45996index d1600d2..4c3af3a 100644
45997--- a/drivers/md/dm-stripe.c
45998+++ b/drivers/md/dm-stripe.c
45999@@ -21,7 +21,7 @@ struct stripe {
46000 struct dm_dev *dev;
46001 sector_t physical_start;
46002
46003- atomic_t error_count;
46004+ atomic_unchecked_t error_count;
46005 };
46006
46007 struct stripe_c {
46008@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
46009 kfree(sc);
46010 return r;
46011 }
46012- atomic_set(&(sc->stripe[i].error_count), 0);
46013+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
46014 }
46015
46016 ti->private = sc;
46017@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
46018 DMEMIT("%d ", sc->stripes);
46019 for (i = 0; i < sc->stripes; i++) {
46020 DMEMIT("%s ", sc->stripe[i].dev->name);
46021- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
46022+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
46023 'D' : 'A';
46024 }
46025 buffer[i] = '\0';
46026@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
46027 */
46028 for (i = 0; i < sc->stripes; i++)
46029 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
46030- atomic_inc(&(sc->stripe[i].error_count));
46031- if (atomic_read(&(sc->stripe[i].error_count)) <
46032+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
46033+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
46034 DM_IO_ERROR_THRESHOLD)
46035 schedule_work(&sc->trigger_event);
46036 }
46037diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
46038index 5f59f1e..01bd02e 100644
46039--- a/drivers/md/dm-table.c
46040+++ b/drivers/md/dm-table.c
46041@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
46042 static int open_dev(struct dm_dev_internal *d, dev_t dev,
46043 struct mapped_device *md)
46044 {
46045- static char *_claim_ptr = "I belong to device-mapper";
46046+ static char _claim_ptr[] = "I belong to device-mapper";
46047 struct block_device *bdev;
46048
46049 int r;
46050@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
46051 if (!dev_size)
46052 return 0;
46053
46054- if ((start >= dev_size) || (start + len > dev_size)) {
46055+ if ((start >= dev_size) || (len > dev_size - start)) {
46056 DMWARN("%s: %s too small for target: "
46057 "start=%llu, len=%llu, dev_size=%llu",
46058 dm_device_name(ti->table->md), bdevname(bdev, b),
46059diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
46060index e9d33ad..dae9880d 100644
46061--- a/drivers/md/dm-thin-metadata.c
46062+++ b/drivers/md/dm-thin-metadata.c
46063@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
46064 {
46065 pmd->info.tm = pmd->tm;
46066 pmd->info.levels = 2;
46067- pmd->info.value_type.context = pmd->data_sm;
46068+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
46069 pmd->info.value_type.size = sizeof(__le64);
46070 pmd->info.value_type.inc = data_block_inc;
46071 pmd->info.value_type.dec = data_block_dec;
46072@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
46073
46074 pmd->bl_info.tm = pmd->tm;
46075 pmd->bl_info.levels = 1;
46076- pmd->bl_info.value_type.context = pmd->data_sm;
46077+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
46078 pmd->bl_info.value_type.size = sizeof(__le64);
46079 pmd->bl_info.value_type.inc = data_block_inc;
46080 pmd->bl_info.value_type.dec = data_block_dec;
46081diff --git a/drivers/md/dm.c b/drivers/md/dm.c
46082index 32b958d..34011e8 100644
46083--- a/drivers/md/dm.c
46084+++ b/drivers/md/dm.c
46085@@ -180,9 +180,9 @@ struct mapped_device {
46086 /*
46087 * Event handling.
46088 */
46089- atomic_t event_nr;
46090+ atomic_unchecked_t event_nr;
46091 wait_queue_head_t eventq;
46092- atomic_t uevent_seq;
46093+ atomic_unchecked_t uevent_seq;
46094 struct list_head uevent_list;
46095 spinlock_t uevent_lock; /* Protect access to uevent_list */
46096
46097@@ -1952,8 +1952,8 @@ static struct mapped_device *alloc_dev(int minor)
46098 spin_lock_init(&md->deferred_lock);
46099 atomic_set(&md->holders, 1);
46100 atomic_set(&md->open_count, 0);
46101- atomic_set(&md->event_nr, 0);
46102- atomic_set(&md->uevent_seq, 0);
46103+ atomic_set_unchecked(&md->event_nr, 0);
46104+ atomic_set_unchecked(&md->uevent_seq, 0);
46105 INIT_LIST_HEAD(&md->uevent_list);
46106 spin_lock_init(&md->uevent_lock);
46107
46108@@ -2107,7 +2107,7 @@ static void event_callback(void *context)
46109
46110 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
46111
46112- atomic_inc(&md->event_nr);
46113+ atomic_inc_unchecked(&md->event_nr);
46114 wake_up(&md->eventq);
46115 }
46116
46117@@ -2800,18 +2800,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
46118
46119 uint32_t dm_next_uevent_seq(struct mapped_device *md)
46120 {
46121- return atomic_add_return(1, &md->uevent_seq);
46122+ return atomic_add_return_unchecked(1, &md->uevent_seq);
46123 }
46124
46125 uint32_t dm_get_event_nr(struct mapped_device *md)
46126 {
46127- return atomic_read(&md->event_nr);
46128+ return atomic_read_unchecked(&md->event_nr);
46129 }
46130
46131 int dm_wait_event(struct mapped_device *md, int event_nr)
46132 {
46133 return wait_event_interruptible(md->eventq,
46134- (event_nr != atomic_read(&md->event_nr)));
46135+ (event_nr != atomic_read_unchecked(&md->event_nr)));
46136 }
46137
46138 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
46139diff --git a/drivers/md/md.c b/drivers/md/md.c
46140index 32fc19c..cb6eba3 100644
46141--- a/drivers/md/md.c
46142+++ b/drivers/md/md.c
46143@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
46144 * start build, activate spare
46145 */
46146 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
46147-static atomic_t md_event_count;
46148+static atomic_unchecked_t md_event_count;
46149 void md_new_event(struct mddev *mddev)
46150 {
46151- atomic_inc(&md_event_count);
46152+ atomic_inc_unchecked(&md_event_count);
46153 wake_up(&md_event_waiters);
46154 }
46155 EXPORT_SYMBOL_GPL(md_new_event);
46156@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
46157 */
46158 static void md_new_event_inintr(struct mddev *mddev)
46159 {
46160- atomic_inc(&md_event_count);
46161+ atomic_inc_unchecked(&md_event_count);
46162 wake_up(&md_event_waiters);
46163 }
46164
46165@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
46166 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
46167 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
46168 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
46169- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
46170+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
46171
46172 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
46173 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
46174@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
46175 else
46176 sb->resync_offset = cpu_to_le64(0);
46177
46178- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
46179+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
46180
46181 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
46182 sb->size = cpu_to_le64(mddev->dev_sectors);
46183@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
46184 static ssize_t
46185 errors_show(struct md_rdev *rdev, char *page)
46186 {
46187- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
46188+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
46189 }
46190
46191 static ssize_t
46192@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
46193 char *e;
46194 unsigned long n = simple_strtoul(buf, &e, 10);
46195 if (*buf && (*e == 0 || *e == '\n')) {
46196- atomic_set(&rdev->corrected_errors, n);
46197+ atomic_set_unchecked(&rdev->corrected_errors, n);
46198 return len;
46199 }
46200 return -EINVAL;
46201@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
46202 rdev->sb_loaded = 0;
46203 rdev->bb_page = NULL;
46204 atomic_set(&rdev->nr_pending, 0);
46205- atomic_set(&rdev->read_errors, 0);
46206- atomic_set(&rdev->corrected_errors, 0);
46207+ atomic_set_unchecked(&rdev->read_errors, 0);
46208+ atomic_set_unchecked(&rdev->corrected_errors, 0);
46209
46210 INIT_LIST_HEAD(&rdev->same_set);
46211 init_waitqueue_head(&rdev->blocked_wait);
46212@@ -7068,7 +7068,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
46213
46214 spin_unlock(&pers_lock);
46215 seq_printf(seq, "\n");
46216- seq->poll_event = atomic_read(&md_event_count);
46217+ seq->poll_event = atomic_read_unchecked(&md_event_count);
46218 return 0;
46219 }
46220 if (v == (void*)2) {
46221@@ -7171,7 +7171,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
46222 return error;
46223
46224 seq = file->private_data;
46225- seq->poll_event = atomic_read(&md_event_count);
46226+ seq->poll_event = atomic_read_unchecked(&md_event_count);
46227 return error;
46228 }
46229
46230@@ -7188,7 +7188,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
46231 /* always allow read */
46232 mask = POLLIN | POLLRDNORM;
46233
46234- if (seq->poll_event != atomic_read(&md_event_count))
46235+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
46236 mask |= POLLERR | POLLPRI;
46237 return mask;
46238 }
46239@@ -7232,7 +7232,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
46240 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
46241 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
46242 (int)part_stat_read(&disk->part0, sectors[1]) -
46243- atomic_read(&disk->sync_io);
46244+ atomic_read_unchecked(&disk->sync_io);
46245 /* sync IO will cause sync_io to increase before the disk_stats
46246 * as sync_io is counted when a request starts, and
46247 * disk_stats is counted when it completes.
46248diff --git a/drivers/md/md.h b/drivers/md/md.h
46249index a49d991..3582bb7 100644
46250--- a/drivers/md/md.h
46251+++ b/drivers/md/md.h
46252@@ -94,13 +94,13 @@ struct md_rdev {
46253 * only maintained for arrays that
46254 * support hot removal
46255 */
46256- atomic_t read_errors; /* number of consecutive read errors that
46257+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
46258 * we have tried to ignore.
46259 */
46260 struct timespec last_read_error; /* monotonic time since our
46261 * last read error
46262 */
46263- atomic_t corrected_errors; /* number of corrected read errors,
46264+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
46265 * for reporting to userspace and storing
46266 * in superblock.
46267 */
46268@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
46269
46270 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
46271 {
46272- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
46273+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
46274 }
46275
46276 struct md_personality
46277diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
46278index 786b689..ea8c956 100644
46279--- a/drivers/md/persistent-data/dm-space-map-metadata.c
46280+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
46281@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
46282 * Flick into a mode where all blocks get allocated in the new area.
46283 */
46284 smm->begin = old_len;
46285- memcpy(sm, &bootstrap_ops, sizeof(*sm));
46286+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
46287
46288 /*
46289 * Extend.
46290@@ -710,7 +710,7 @@ out:
46291 /*
46292 * Switch back to normal behaviour.
46293 */
46294- memcpy(sm, &ops, sizeof(*sm));
46295+ memcpy((void *)sm, &ops, sizeof(*sm));
46296 return r;
46297 }
46298
46299diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
46300index 3e6d115..ffecdeb 100644
46301--- a/drivers/md/persistent-data/dm-space-map.h
46302+++ b/drivers/md/persistent-data/dm-space-map.h
46303@@ -71,6 +71,7 @@ struct dm_space_map {
46304 dm_sm_threshold_fn fn,
46305 void *context);
46306 };
46307+typedef struct dm_space_map __no_const dm_space_map_no_const;
46308
46309 /*----------------------------------------------------------------*/
46310
46311diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
46312index 56e24c0..e1c8e1f 100644
46313--- a/drivers/md/raid1.c
46314+++ b/drivers/md/raid1.c
46315@@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
46316 if (r1_sync_page_io(rdev, sect, s,
46317 bio->bi_io_vec[idx].bv_page,
46318 READ) != 0)
46319- atomic_add(s, &rdev->corrected_errors);
46320+ atomic_add_unchecked(s, &rdev->corrected_errors);
46321 }
46322 sectors -= s;
46323 sect += s;
46324@@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
46325 test_bit(In_sync, &rdev->flags)) {
46326 if (r1_sync_page_io(rdev, sect, s,
46327 conf->tmppage, READ)) {
46328- atomic_add(s, &rdev->corrected_errors);
46329+ atomic_add_unchecked(s, &rdev->corrected_errors);
46330 printk(KERN_INFO
46331 "md/raid1:%s: read error corrected "
46332 "(%d sectors at %llu on %s)\n",
46333diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
46334index cb882aa..cb8aeca 100644
46335--- a/drivers/md/raid10.c
46336+++ b/drivers/md/raid10.c
46337@@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
46338 /* The write handler will notice the lack of
46339 * R10BIO_Uptodate and record any errors etc
46340 */
46341- atomic_add(r10_bio->sectors,
46342+ atomic_add_unchecked(r10_bio->sectors,
46343 &conf->mirrors[d].rdev->corrected_errors);
46344
46345 /* for reconstruct, we always reschedule after a read.
46346@@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
46347 {
46348 struct timespec cur_time_mon;
46349 unsigned long hours_since_last;
46350- unsigned int read_errors = atomic_read(&rdev->read_errors);
46351+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
46352
46353 ktime_get_ts(&cur_time_mon);
46354
46355@@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
46356 * overflowing the shift of read_errors by hours_since_last.
46357 */
46358 if (hours_since_last >= 8 * sizeof(read_errors))
46359- atomic_set(&rdev->read_errors, 0);
46360+ atomic_set_unchecked(&rdev->read_errors, 0);
46361 else
46362- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
46363+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
46364 }
46365
46366 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
46367@@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46368 return;
46369
46370 check_decay_read_errors(mddev, rdev);
46371- atomic_inc(&rdev->read_errors);
46372- if (atomic_read(&rdev->read_errors) > max_read_errors) {
46373+ atomic_inc_unchecked(&rdev->read_errors);
46374+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
46375 char b[BDEVNAME_SIZE];
46376 bdevname(rdev->bdev, b);
46377
46378@@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46379 "md/raid10:%s: %s: Raid device exceeded "
46380 "read_error threshold [cur %d:max %d]\n",
46381 mdname(mddev), b,
46382- atomic_read(&rdev->read_errors), max_read_errors);
46383+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
46384 printk(KERN_NOTICE
46385 "md/raid10:%s: %s: Failing raid device\n",
46386 mdname(mddev), b);
46387@@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46388 sect +
46389 choose_data_offset(r10_bio, rdev)),
46390 bdevname(rdev->bdev, b));
46391- atomic_add(s, &rdev->corrected_errors);
46392+ atomic_add_unchecked(s, &rdev->corrected_errors);
46393 }
46394
46395 rdev_dec_pending(rdev, mddev);
46396@@ -2954,6 +2954,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr,
46397 */
46398 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) {
46399 end_reshape(conf);
46400+ close_sync(conf);
46401 return 0;
46402 }
46403
46404@@ -4411,7 +4412,7 @@ read_more:
46405 read_bio->bi_private = r10_bio;
46406 read_bio->bi_end_io = end_sync_read;
46407 read_bio->bi_rw = READ;
46408- read_bio->bi_flags &= ~(BIO_POOL_MASK - 1);
46409+ read_bio->bi_flags &= (~0UL << BIO_RESET_BITS);
46410 read_bio->bi_flags |= 1 << BIO_UPTODATE;
46411 read_bio->bi_vcnt = 0;
46412 read_bio->bi_iter.bi_size = 0;
46413diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
46414index 6234b2e..4990801 100644
46415--- a/drivers/md/raid5.c
46416+++ b/drivers/md/raid5.c
46417@@ -1731,6 +1731,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
46418 return 1;
46419 }
46420
46421+#ifdef CONFIG_GRKERNSEC_HIDESYM
46422+static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
46423+#endif
46424+
46425 static int grow_stripes(struct r5conf *conf, int num)
46426 {
46427 struct kmem_cache *sc;
46428@@ -1742,7 +1746,11 @@ static int grow_stripes(struct r5conf *conf, int num)
46429 "raid%d-%s", conf->level, mdname(conf->mddev));
46430 else
46431 sprintf(conf->cache_name[0],
46432+#ifdef CONFIG_GRKERNSEC_HIDESYM
46433+ "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
46434+#else
46435 "raid%d-%p", conf->level, conf->mddev);
46436+#endif
46437 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
46438
46439 conf->active_name = 0;
46440@@ -2018,21 +2026,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
46441 mdname(conf->mddev), STRIPE_SECTORS,
46442 (unsigned long long)s,
46443 bdevname(rdev->bdev, b));
46444- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
46445+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
46446 clear_bit(R5_ReadError, &sh->dev[i].flags);
46447 clear_bit(R5_ReWrite, &sh->dev[i].flags);
46448 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
46449 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
46450
46451- if (atomic_read(&rdev->read_errors))
46452- atomic_set(&rdev->read_errors, 0);
46453+ if (atomic_read_unchecked(&rdev->read_errors))
46454+ atomic_set_unchecked(&rdev->read_errors, 0);
46455 } else {
46456 const char *bdn = bdevname(rdev->bdev, b);
46457 int retry = 0;
46458 int set_bad = 0;
46459
46460 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
46461- atomic_inc(&rdev->read_errors);
46462+ atomic_inc_unchecked(&rdev->read_errors);
46463 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
46464 printk_ratelimited(
46465 KERN_WARNING
46466@@ -2060,7 +2068,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
46467 mdname(conf->mddev),
46468 (unsigned long long)s,
46469 bdn);
46470- } else if (atomic_read(&rdev->read_errors)
46471+ } else if (atomic_read_unchecked(&rdev->read_errors)
46472 > conf->max_nr_stripes)
46473 printk(KERN_WARNING
46474 "md/raid:%s: Too many read errors, failing device %s.\n",
46475@@ -3817,6 +3825,8 @@ static void handle_stripe(struct stripe_head *sh)
46476 set_bit(R5_Wantwrite, &dev->flags);
46477 if (prexor)
46478 continue;
46479+ if (s.failed > 1)
46480+ continue;
46481 if (!test_bit(R5_Insync, &dev->flags) ||
46482 ((i == sh->pd_idx || i == sh->qd_idx) &&
46483 s.failed == 0))
46484diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
46485index 983db75..ef9248c 100644
46486--- a/drivers/media/dvb-core/dvbdev.c
46487+++ b/drivers/media/dvb-core/dvbdev.c
46488@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
46489 const struct dvb_device *template, void *priv, int type)
46490 {
46491 struct dvb_device *dvbdev;
46492- struct file_operations *dvbdevfops;
46493+ file_operations_no_const *dvbdevfops;
46494 struct device *clsdev;
46495 int minor;
46496 int id;
46497diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
46498index 539f4db..cdd403b 100644
46499--- a/drivers/media/dvb-frontends/af9033.h
46500+++ b/drivers/media/dvb-frontends/af9033.h
46501@@ -82,7 +82,7 @@ struct af9033_ops {
46502 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
46503 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
46504 int onoff);
46505-};
46506+} __no_const;
46507
46508
46509 #if IS_ENABLED(CONFIG_DVB_AF9033)
46510diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
46511index 9b6c3bb..baeb5c7 100644
46512--- a/drivers/media/dvb-frontends/dib3000.h
46513+++ b/drivers/media/dvb-frontends/dib3000.h
46514@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
46515 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
46516 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
46517 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
46518-};
46519+} __no_const;
46520
46521 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
46522 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
46523diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
46524index ed8cb90..5ef7f79 100644
46525--- a/drivers/media/pci/cx88/cx88-video.c
46526+++ b/drivers/media/pci/cx88/cx88-video.c
46527@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
46528
46529 /* ------------------------------------------------------------------ */
46530
46531-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46532-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46533-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46534+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46535+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46536+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46537
46538 module_param_array(video_nr, int, NULL, 0444);
46539 module_param_array(vbi_nr, int, NULL, 0444);
46540diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
46541index 802642d..5534900 100644
46542--- a/drivers/media/pci/ivtv/ivtv-driver.c
46543+++ b/drivers/media/pci/ivtv/ivtv-driver.c
46544@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
46545 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
46546
46547 /* ivtv instance counter */
46548-static atomic_t ivtv_instance = ATOMIC_INIT(0);
46549+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
46550
46551 /* Parameter declarations */
46552 static int cardtype[IVTV_MAX_CARDS];
46553diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
46554index 9a726ea..f5e9b52 100644
46555--- a/drivers/media/platform/omap/omap_vout.c
46556+++ b/drivers/media/platform/omap/omap_vout.c
46557@@ -63,7 +63,6 @@ enum omap_vout_channels {
46558 OMAP_VIDEO2,
46559 };
46560
46561-static struct videobuf_queue_ops video_vbq_ops;
46562 /* Variables configurable through module params*/
46563 static u32 video1_numbuffers = 3;
46564 static u32 video2_numbuffers = 3;
46565@@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
46566 {
46567 struct videobuf_queue *q;
46568 struct omap_vout_device *vout = NULL;
46569+ static struct videobuf_queue_ops video_vbq_ops = {
46570+ .buf_setup = omap_vout_buffer_setup,
46571+ .buf_prepare = omap_vout_buffer_prepare,
46572+ .buf_release = omap_vout_buffer_release,
46573+ .buf_queue = omap_vout_buffer_queue,
46574+ };
46575
46576 vout = video_drvdata(file);
46577 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
46578@@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
46579 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
46580
46581 q = &vout->vbq;
46582- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
46583- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
46584- video_vbq_ops.buf_release = omap_vout_buffer_release;
46585- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
46586 spin_lock_init(&vout->vbq_lock);
46587
46588 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
46589diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
46590index fb2acc5..a2fcbdc4 100644
46591--- a/drivers/media/platform/s5p-tv/mixer.h
46592+++ b/drivers/media/platform/s5p-tv/mixer.h
46593@@ -156,7 +156,7 @@ struct mxr_layer {
46594 /** layer index (unique identifier) */
46595 int idx;
46596 /** callbacks for layer methods */
46597- struct mxr_layer_ops ops;
46598+ struct mxr_layer_ops *ops;
46599 /** format array */
46600 const struct mxr_format **fmt_array;
46601 /** size of format array */
46602diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46603index 74344c7..a39e70e 100644
46604--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46605+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46606@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
46607 {
46608 struct mxr_layer *layer;
46609 int ret;
46610- struct mxr_layer_ops ops = {
46611+ static struct mxr_layer_ops ops = {
46612 .release = mxr_graph_layer_release,
46613 .buffer_set = mxr_graph_buffer_set,
46614 .stream_set = mxr_graph_stream_set,
46615diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
46616index b713403..53cb5ad 100644
46617--- a/drivers/media/platform/s5p-tv/mixer_reg.c
46618+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
46619@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
46620 layer->update_buf = next;
46621 }
46622
46623- layer->ops.buffer_set(layer, layer->update_buf);
46624+ layer->ops->buffer_set(layer, layer->update_buf);
46625
46626 if (done && done != layer->shadow_buf)
46627 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
46628diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
46629index 8a8dbc8..b74c62d 100644
46630--- a/drivers/media/platform/s5p-tv/mixer_video.c
46631+++ b/drivers/media/platform/s5p-tv/mixer_video.c
46632@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
46633 layer->geo.src.height = layer->geo.src.full_height;
46634
46635 mxr_geometry_dump(mdev, &layer->geo);
46636- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46637+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46638 mxr_geometry_dump(mdev, &layer->geo);
46639 }
46640
46641@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
46642 layer->geo.dst.full_width = mbus_fmt.width;
46643 layer->geo.dst.full_height = mbus_fmt.height;
46644 layer->geo.dst.field = mbus_fmt.field;
46645- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46646+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46647
46648 mxr_geometry_dump(mdev, &layer->geo);
46649 }
46650@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
46651 /* set source size to highest accepted value */
46652 geo->src.full_width = max(geo->dst.full_width, pix->width);
46653 geo->src.full_height = max(geo->dst.full_height, pix->height);
46654- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46655+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46656 mxr_geometry_dump(mdev, &layer->geo);
46657 /* set cropping to total visible screen */
46658 geo->src.width = pix->width;
46659@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
46660 geo->src.x_offset = 0;
46661 geo->src.y_offset = 0;
46662 /* assure consistency of geometry */
46663- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
46664+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
46665 mxr_geometry_dump(mdev, &layer->geo);
46666 /* set full size to lowest possible value */
46667 geo->src.full_width = 0;
46668 geo->src.full_height = 0;
46669- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46670+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46671 mxr_geometry_dump(mdev, &layer->geo);
46672
46673 /* returning results */
46674@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
46675 target->width = s->r.width;
46676 target->height = s->r.height;
46677
46678- layer->ops.fix_geometry(layer, stage, s->flags);
46679+ layer->ops->fix_geometry(layer, stage, s->flags);
46680
46681 /* retrieve update selection rectangle */
46682 res.left = target->x_offset;
46683@@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
46684 mxr_output_get(mdev);
46685
46686 mxr_layer_update_output(layer);
46687- layer->ops.format_set(layer);
46688+ layer->ops->format_set(layer);
46689 /* enabling layer in hardware */
46690 spin_lock_irqsave(&layer->enq_slock, flags);
46691 layer->state = MXR_LAYER_STREAMING;
46692 spin_unlock_irqrestore(&layer->enq_slock, flags);
46693
46694- layer->ops.stream_set(layer, MXR_ENABLE);
46695+ layer->ops->stream_set(layer, MXR_ENABLE);
46696 mxr_streamer_get(mdev);
46697
46698 return 0;
46699@@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
46700 spin_unlock_irqrestore(&layer->enq_slock, flags);
46701
46702 /* disabling layer in hardware */
46703- layer->ops.stream_set(layer, MXR_DISABLE);
46704+ layer->ops->stream_set(layer, MXR_DISABLE);
46705 /* remove one streamer */
46706 mxr_streamer_put(mdev);
46707 /* allow changes in output configuration */
46708@@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
46709
46710 void mxr_layer_release(struct mxr_layer *layer)
46711 {
46712- if (layer->ops.release)
46713- layer->ops.release(layer);
46714+ if (layer->ops->release)
46715+ layer->ops->release(layer);
46716 }
46717
46718 void mxr_base_layer_release(struct mxr_layer *layer)
46719@@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
46720
46721 layer->mdev = mdev;
46722 layer->idx = idx;
46723- layer->ops = *ops;
46724+ layer->ops = ops;
46725
46726 spin_lock_init(&layer->enq_slock);
46727 INIT_LIST_HEAD(&layer->enq_list);
46728diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46729index c9388c4..ce71ece 100644
46730--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46731+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46732@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
46733 {
46734 struct mxr_layer *layer;
46735 int ret;
46736- struct mxr_layer_ops ops = {
46737+ static struct mxr_layer_ops ops = {
46738 .release = mxr_vp_layer_release,
46739 .buffer_set = mxr_vp_buffer_set,
46740 .stream_set = mxr_vp_stream_set,
46741diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
46742index d00bf3d..1301a0c 100644
46743--- a/drivers/media/platform/vivi.c
46744+++ b/drivers/media/platform/vivi.c
46745@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
46746 MODULE_LICENSE("Dual BSD/GPL");
46747 MODULE_VERSION(VIVI_VERSION);
46748
46749-static unsigned video_nr = -1;
46750-module_param(video_nr, uint, 0644);
46751+static int video_nr = -1;
46752+module_param(video_nr, int, 0644);
46753 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
46754
46755 static unsigned n_devs = 1;
46756diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
46757index d719e59..63f3470 100644
46758--- a/drivers/media/radio/radio-cadet.c
46759+++ b/drivers/media/radio/radio-cadet.c
46760@@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
46761 unsigned char readbuf[RDS_BUFFER];
46762 int i = 0;
46763
46764+ if (count > RDS_BUFFER)
46765+ return -EFAULT;
46766 mutex_lock(&dev->lock);
46767 if (dev->rdsstat == 0)
46768 cadet_start_rds(dev);
46769@@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
46770 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
46771 mutex_unlock(&dev->lock);
46772
46773- if (i && copy_to_user(data, readbuf, i))
46774- return -EFAULT;
46775+ if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
46776+ i = -EFAULT;
46777+
46778 return i;
46779 }
46780
46781diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
46782index 5236035..c622c74 100644
46783--- a/drivers/media/radio/radio-maxiradio.c
46784+++ b/drivers/media/radio/radio-maxiradio.c
46785@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
46786 /* TEA5757 pin mappings */
46787 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
46788
46789-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
46790+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
46791
46792 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
46793 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
46794diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
46795index 050b3bb..79f62b9 100644
46796--- a/drivers/media/radio/radio-shark.c
46797+++ b/drivers/media/radio/radio-shark.c
46798@@ -79,7 +79,7 @@ struct shark_device {
46799 u32 last_val;
46800 };
46801
46802-static atomic_t shark_instance = ATOMIC_INIT(0);
46803+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
46804
46805 static void shark_write_val(struct snd_tea575x *tea, u32 val)
46806 {
46807diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
46808index 8654e0d..0608a64 100644
46809--- a/drivers/media/radio/radio-shark2.c
46810+++ b/drivers/media/radio/radio-shark2.c
46811@@ -74,7 +74,7 @@ struct shark_device {
46812 u8 *transfer_buffer;
46813 };
46814
46815-static atomic_t shark_instance = ATOMIC_INIT(0);
46816+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
46817
46818 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
46819 {
46820diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
46821index 2fd9009..278cc1e 100644
46822--- a/drivers/media/radio/radio-si476x.c
46823+++ b/drivers/media/radio/radio-si476x.c
46824@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
46825 struct si476x_radio *radio;
46826 struct v4l2_ctrl *ctrl;
46827
46828- static atomic_t instance = ATOMIC_INIT(0);
46829+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
46830
46831 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
46832 if (!radio)
46833diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
46834index a1c641e..3007da9 100644
46835--- a/drivers/media/usb/dvb-usb/cxusb.c
46836+++ b/drivers/media/usb/dvb-usb/cxusb.c
46837@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
46838
46839 struct dib0700_adapter_state {
46840 int (*set_param_save) (struct dvb_frontend *);
46841-};
46842+} __no_const;
46843
46844 static int dib7070_set_param_override(struct dvb_frontend *fe)
46845 {
46846diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46847index 733a7ff..f8b52e3 100644
46848--- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46849+++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46850@@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
46851
46852 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
46853 {
46854- struct hexline hx;
46855- u8 reset;
46856+ struct hexline *hx;
46857+ u8 *reset;
46858 int ret,pos=0;
46859
46860+ reset = kmalloc(1, GFP_KERNEL);
46861+ if (reset == NULL)
46862+ return -ENOMEM;
46863+
46864+ hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
46865+ if (hx == NULL) {
46866+ kfree(reset);
46867+ return -ENOMEM;
46868+ }
46869+
46870 /* stop the CPU */
46871- reset = 1;
46872- if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
46873+ reset[0] = 1;
46874+ if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
46875 err("could not stop the USB controller CPU.");
46876
46877- while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
46878- deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
46879- ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
46880+ while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
46881+ deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
46882+ ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
46883
46884- if (ret != hx.len) {
46885+ if (ret != hx->len) {
46886 err("error while transferring firmware "
46887 "(transferred size: %d, block size: %d)",
46888- ret,hx.len);
46889+ ret,hx->len);
46890 ret = -EINVAL;
46891 break;
46892 }
46893 }
46894 if (ret < 0) {
46895 err("firmware download failed at %d with %d",pos,ret);
46896+ kfree(reset);
46897+ kfree(hx);
46898 return ret;
46899 }
46900
46901 if (ret == 0) {
46902 /* restart the CPU */
46903- reset = 0;
46904- if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
46905+ reset[0] = 0;
46906+ if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
46907 err("could not restart the USB controller CPU.");
46908 ret = -EINVAL;
46909 }
46910 } else
46911 ret = -EIO;
46912
46913+ kfree(reset);
46914+ kfree(hx);
46915+
46916 return ret;
46917 }
46918 EXPORT_SYMBOL(usb_cypress_load_firmware);
46919diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
46920index ae0f56a..ec71784 100644
46921--- a/drivers/media/usb/dvb-usb/dw2102.c
46922+++ b/drivers/media/usb/dvb-usb/dw2102.c
46923@@ -118,7 +118,7 @@ struct su3000_state {
46924
46925 struct s6x0_state {
46926 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
46927-};
46928+} __no_const;
46929
46930 /* debug */
46931 static int dvb_usb_dw2102_debug;
46932diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
46933index d947e03..87fef42 100644
46934--- a/drivers/media/usb/dvb-usb/technisat-usb2.c
46935+++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
46936@@ -87,8 +87,11 @@ struct technisat_usb2_state {
46937 static int technisat_usb2_i2c_access(struct usb_device *udev,
46938 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
46939 {
46940- u8 b[64];
46941- int ret, actual_length;
46942+ u8 *b = kmalloc(64, GFP_KERNEL);
46943+ int ret, actual_length, error = 0;
46944+
46945+ if (b == NULL)
46946+ return -ENOMEM;
46947
46948 deb_i2c("i2c-access: %02x, tx: ", device_addr);
46949 debug_dump(tx, txlen, deb_i2c);
46950@@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46951
46952 if (ret < 0) {
46953 err("i2c-error: out failed %02x = %d", device_addr, ret);
46954- return -ENODEV;
46955+ error = -ENODEV;
46956+ goto out;
46957 }
46958
46959 ret = usb_bulk_msg(udev,
46960@@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46961 b, 64, &actual_length, 1000);
46962 if (ret < 0) {
46963 err("i2c-error: in failed %02x = %d", device_addr, ret);
46964- return -ENODEV;
46965+ error = -ENODEV;
46966+ goto out;
46967 }
46968
46969 if (b[0] != I2C_STATUS_OK) {
46970@@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46971 /* handle tuner-i2c-nak */
46972 if (!(b[0] == I2C_STATUS_NAK &&
46973 device_addr == 0x60
46974- /* && device_is_technisat_usb2 */))
46975- return -ENODEV;
46976+ /* && device_is_technisat_usb2 */)) {
46977+ error = -ENODEV;
46978+ goto out;
46979+ }
46980 }
46981
46982 deb_i2c("status: %d, ", b[0]);
46983@@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46984
46985 deb_i2c("\n");
46986
46987- return 0;
46988+out:
46989+ kfree(b);
46990+ return error;
46991 }
46992
46993 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
46994@@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46995 {
46996 int ret;
46997
46998- u8 led[8] = {
46999- red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
47000- 0
47001- };
47002+ u8 *led = kzalloc(8, GFP_KERNEL);
47003+
47004+ if (led == NULL)
47005+ return -ENOMEM;
47006
47007 if (disable_led_control && state != TECH_LED_OFF)
47008 return 0;
47009
47010+ led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
47011+
47012 switch (state) {
47013 case TECH_LED_ON:
47014 led[1] = 0x82;
47015@@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
47016 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
47017 USB_TYPE_VENDOR | USB_DIR_OUT,
47018 0, 0,
47019- led, sizeof(led), 500);
47020+ led, 8, 500);
47021
47022 mutex_unlock(&d->i2c_mutex);
47023+
47024+ kfree(led);
47025+
47026 return ret;
47027 }
47028
47029 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
47030 {
47031 int ret;
47032- u8 b = 0;
47033+ u8 *b = kzalloc(1, GFP_KERNEL);
47034+
47035+ if (b == NULL)
47036+ return -ENOMEM;
47037
47038 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
47039 return -EAGAIN;
47040@@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
47041 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
47042 USB_TYPE_VENDOR | USB_DIR_OUT,
47043 (red << 8) | green, 0,
47044- &b, 1, 500);
47045+ b, 1, 500);
47046
47047 mutex_unlock(&d->i2c_mutex);
47048
47049+ kfree(b);
47050+
47051 return ret;
47052 }
47053
47054@@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
47055 struct dvb_usb_device_description **desc, int *cold)
47056 {
47057 int ret;
47058- u8 version[3];
47059+ u8 *version = kmalloc(3, GFP_KERNEL);
47060
47061 /* first select the interface */
47062 if (usb_set_interface(udev, 0, 1) != 0)
47063@@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
47064
47065 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
47066
47067+ if (version == NULL)
47068+ return 0;
47069+
47070 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
47071 GET_VERSION_INFO_VENDOR_REQUEST,
47072 USB_TYPE_VENDOR | USB_DIR_IN,
47073 0, 0,
47074- version, sizeof(version), 500);
47075+ version, 3, 500);
47076
47077 if (ret < 0)
47078 *cold = 1;
47079@@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
47080 *cold = 0;
47081 }
47082
47083+ kfree(version);
47084+
47085 return 0;
47086 }
47087
47088@@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
47089
47090 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
47091 {
47092- u8 buf[62], *b;
47093+ u8 *buf, *b;
47094 int ret;
47095 struct ir_raw_event ev;
47096
47097+ buf = kmalloc(62, GFP_KERNEL);
47098+
47099+ if (buf == NULL)
47100+ return -ENOMEM;
47101+
47102 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
47103 buf[1] = 0x08;
47104 buf[2] = 0x8f;
47105@@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
47106 GET_IR_DATA_VENDOR_REQUEST,
47107 USB_TYPE_VENDOR | USB_DIR_IN,
47108 0x8080, 0,
47109- buf, sizeof(buf), 500);
47110+ buf, 62, 500);
47111
47112 unlock:
47113 mutex_unlock(&d->i2c_mutex);
47114
47115- if (ret < 0)
47116+ if (ret < 0) {
47117+ kfree(buf);
47118 return ret;
47119+ }
47120
47121- if (ret == 1)
47122+ if (ret == 1) {
47123+ kfree(buf);
47124 return 0; /* no key pressed */
47125+ }
47126
47127 /* decoding */
47128 b = buf+1;
47129@@ -653,6 +686,8 @@ unlock:
47130
47131 ir_raw_event_handle(d->rc_dev);
47132
47133+ kfree(buf);
47134+
47135 return 1;
47136 }
47137
47138diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47139index 7e2411c..cef73ca 100644
47140--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47141+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47142@@ -328,7 +328,7 @@ struct v4l2_buffer32 {
47143 __u32 reserved;
47144 };
47145
47146-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47147+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
47148 enum v4l2_memory memory)
47149 {
47150 void __user *up_pln;
47151@@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47152 return 0;
47153 }
47154
47155-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47156+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
47157 enum v4l2_memory memory)
47158 {
47159 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
47160@@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
47161 * by passing a very big num_planes value */
47162 uplane = compat_alloc_user_space(num_planes *
47163 sizeof(struct v4l2_plane));
47164- kp->m.planes = uplane;
47165+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
47166
47167 while (--num_planes >= 0) {
47168 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
47169@@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
47170 if (num_planes == 0)
47171 return 0;
47172
47173- uplane = kp->m.planes;
47174+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
47175 if (get_user(p, &up->m.planes))
47176 return -EFAULT;
47177 uplane32 = compat_ptr(p);
47178@@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
47179 get_user(kp->capability, &up->capability) ||
47180 get_user(kp->flags, &up->flags))
47181 return -EFAULT;
47182- kp->base = compat_ptr(tmp);
47183+ kp->base = (void __force_kernel *)compat_ptr(tmp);
47184 get_v4l2_pix_format(&kp->fmt, &up->fmt);
47185 return 0;
47186 }
47187@@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
47188 n * sizeof(struct v4l2_ext_control32)))
47189 return -EFAULT;
47190 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
47191- kp->controls = kcontrols;
47192+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
47193 while (--n >= 0) {
47194 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
47195 return -EFAULT;
47196@@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
47197 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
47198 {
47199 struct v4l2_ext_control32 __user *ucontrols;
47200- struct v4l2_ext_control __user *kcontrols = kp->controls;
47201+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
47202 int n = kp->count;
47203 compat_caddr_t p;
47204
47205@@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
47206 put_user(kp->start_block, &up->start_block) ||
47207 put_user(kp->blocks, &up->blocks) ||
47208 put_user(tmp, &up->edid) ||
47209- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
47210+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
47211 return -EFAULT;
47212 return 0;
47213 }
47214diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
47215index 55c6832..a91c7a6 100644
47216--- a/drivers/media/v4l2-core/v4l2-ctrls.c
47217+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
47218@@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
47219 return 0;
47220
47221 case V4L2_CTRL_TYPE_STRING:
47222- len = strlen(c->string);
47223- if (len < ctrl->minimum)
47224+ len = strlen_user(c->string);
47225+ if (!len || len < ctrl->minimum)
47226 return -ERANGE;
47227 if ((len - ctrl->minimum) % ctrl->step)
47228 return -ERANGE;
47229diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
47230index 015f92a..59e311e 100644
47231--- a/drivers/media/v4l2-core/v4l2-device.c
47232+++ b/drivers/media/v4l2-core/v4l2-device.c
47233@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
47234 EXPORT_SYMBOL_GPL(v4l2_device_put);
47235
47236 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
47237- atomic_t *instance)
47238+ atomic_unchecked_t *instance)
47239 {
47240- int num = atomic_inc_return(instance) - 1;
47241+ int num = atomic_inc_return_unchecked(instance) - 1;
47242 int len = strlen(basename);
47243
47244 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
47245diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
47246index 16bffd8..3ab516a 100644
47247--- a/drivers/media/v4l2-core/v4l2-ioctl.c
47248+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
47249@@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
47250 struct file *file, void *fh, void *p);
47251 } u;
47252 void (*debug)(const void *arg, bool write_only);
47253-};
47254+} __do_const;
47255+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
47256
47257 /* This control needs a priority check */
47258 #define INFO_FL_PRIO (1 << 0)
47259@@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
47260 struct video_device *vfd = video_devdata(file);
47261 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
47262 bool write_only = false;
47263- struct v4l2_ioctl_info default_info;
47264+ v4l2_ioctl_info_no_const default_info;
47265 const struct v4l2_ioctl_info *info;
47266 void *fh = file->private_data;
47267 struct v4l2_fh *vfh = NULL;
47268@@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47269 ret = -EINVAL;
47270 break;
47271 }
47272- *user_ptr = (void __user *)buf->m.planes;
47273+ *user_ptr = (void __force_user *)buf->m.planes;
47274 *kernel_ptr = (void **)&buf->m.planes;
47275 *array_size = sizeof(struct v4l2_plane) * buf->length;
47276 ret = 1;
47277@@ -2293,7 +2294,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47278 ret = -EINVAL;
47279 break;
47280 }
47281- *user_ptr = (void __user *)edid->edid;
47282+ *user_ptr = (void __force_user *)edid->edid;
47283 *kernel_ptr = (void **)&edid->edid;
47284 *array_size = edid->blocks * 128;
47285 ret = 1;
47286@@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47287 ret = -EINVAL;
47288 break;
47289 }
47290- *user_ptr = (void __user *)ctrls->controls;
47291+ *user_ptr = (void __force_user *)ctrls->controls;
47292 *kernel_ptr = (void **)&ctrls->controls;
47293 *array_size = sizeof(struct v4l2_ext_control)
47294 * ctrls->count;
47295@@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
47296 }
47297
47298 if (has_array_args) {
47299- *kernel_ptr = (void __force *)user_ptr;
47300+ *kernel_ptr = (void __force_kernel *)user_ptr;
47301 if (copy_to_user(user_ptr, mbuf, array_size))
47302 err = -EFAULT;
47303 goto out_array_args;
47304diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
47305index ebc0af7..baed058 100644
47306--- a/drivers/message/fusion/mptbase.c
47307+++ b/drivers/message/fusion/mptbase.c
47308@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
47309 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
47310 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
47311
47312+#ifdef CONFIG_GRKERNSEC_HIDESYM
47313+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
47314+#else
47315 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
47316 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
47317+#endif
47318+
47319 /*
47320 * Rounding UP to nearest 4-kB boundary here...
47321 */
47322@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
47323 ioc->facts.GlobalCredits);
47324
47325 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
47326+#ifdef CONFIG_GRKERNSEC_HIDESYM
47327+ NULL, NULL);
47328+#else
47329 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
47330+#endif
47331 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
47332 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
47333 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
47334diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
47335index 711fcb5..5da1fb0 100644
47336--- a/drivers/message/fusion/mptsas.c
47337+++ b/drivers/message/fusion/mptsas.c
47338@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
47339 return 0;
47340 }
47341
47342+static inline void
47343+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
47344+{
47345+ if (phy_info->port_details) {
47346+ phy_info->port_details->rphy = rphy;
47347+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
47348+ ioc->name, rphy));
47349+ }
47350+
47351+ if (rphy) {
47352+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
47353+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
47354+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
47355+ ioc->name, rphy, rphy->dev.release));
47356+ }
47357+}
47358+
47359 /* no mutex */
47360 static void
47361 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
47362@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
47363 return NULL;
47364 }
47365
47366-static inline void
47367-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
47368-{
47369- if (phy_info->port_details) {
47370- phy_info->port_details->rphy = rphy;
47371- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
47372- ioc->name, rphy));
47373- }
47374-
47375- if (rphy) {
47376- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
47377- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
47378- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
47379- ioc->name, rphy, rphy->dev.release));
47380- }
47381-}
47382-
47383 static inline struct sas_port *
47384 mptsas_get_port(struct mptsas_phyinfo *phy_info)
47385 {
47386diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
47387index 2a1c6f2..a04c6a2 100644
47388--- a/drivers/message/fusion/mptscsih.c
47389+++ b/drivers/message/fusion/mptscsih.c
47390@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
47391
47392 h = shost_priv(SChost);
47393
47394- if (h) {
47395- if (h->info_kbuf == NULL)
47396- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
47397- return h->info_kbuf;
47398- h->info_kbuf[0] = '\0';
47399+ if (!h)
47400+ return NULL;
47401
47402- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
47403- h->info_kbuf[size-1] = '\0';
47404- }
47405+ if (h->info_kbuf == NULL)
47406+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
47407+ return h->info_kbuf;
47408+ h->info_kbuf[0] = '\0';
47409+
47410+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
47411+ h->info_kbuf[size-1] = '\0';
47412
47413 return h->info_kbuf;
47414 }
47415diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
47416index b7d87cd..3fb36da 100644
47417--- a/drivers/message/i2o/i2o_proc.c
47418+++ b/drivers/message/i2o/i2o_proc.c
47419@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
47420 "Array Controller Device"
47421 };
47422
47423-static char *chtostr(char *tmp, u8 *chars, int n)
47424-{
47425- tmp[0] = 0;
47426- return strncat(tmp, (char *)chars, n);
47427-}
47428-
47429 static int i2o_report_query_status(struct seq_file *seq, int block_status,
47430 char *group)
47431 {
47432@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
47433 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
47434 {
47435 struct i2o_controller *c = (struct i2o_controller *)seq->private;
47436- static u32 work32[5];
47437- static u8 *work8 = (u8 *) work32;
47438- static u16 *work16 = (u16 *) work32;
47439+ u32 work32[5];
47440+ u8 *work8 = (u8 *) work32;
47441+ u16 *work16 = (u16 *) work32;
47442 int token;
47443 u32 hwcap;
47444
47445@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47446 } *result;
47447
47448 i2o_exec_execute_ddm_table ddm_table;
47449- char tmp[28 + 1];
47450
47451 result = kmalloc(sizeof(*result), GFP_KERNEL);
47452 if (!result)
47453@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47454
47455 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
47456 seq_printf(seq, "%-#8x", ddm_table.module_id);
47457- seq_printf(seq, "%-29s",
47458- chtostr(tmp, ddm_table.module_name_version, 28));
47459+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
47460 seq_printf(seq, "%9d ", ddm_table.data_size);
47461 seq_printf(seq, "%8d", ddm_table.code_size);
47462
47463@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47464
47465 i2o_driver_result_table *result;
47466 i2o_driver_store_table *dst;
47467- char tmp[28 + 1];
47468
47469 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
47470 if (result == NULL)
47471@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47472
47473 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
47474 seq_printf(seq, "%-#8x", dst->module_id);
47475- seq_printf(seq, "%-29s",
47476- chtostr(tmp, dst->module_name_version, 28));
47477- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
47478+ seq_printf(seq, "%-.28s", dst->module_name_version);
47479+ seq_printf(seq, "%-.8s", dst->date);
47480 seq_printf(seq, "%8d ", dst->module_size);
47481 seq_printf(seq, "%8d ", dst->mpb_size);
47482 seq_printf(seq, "0x%04x", dst->module_flags);
47483@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
47484 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47485 {
47486 struct i2o_device *d = (struct i2o_device *)seq->private;
47487- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47488+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47489 // == (allow) 512d bytes (max)
47490- static u16 *work16 = (u16 *) work32;
47491+ u16 *work16 = (u16 *) work32;
47492 int token;
47493- char tmp[16 + 1];
47494
47495 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
47496
47497@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47498 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
47499 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
47500 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
47501- seq_printf(seq, "Vendor info : %s\n",
47502- chtostr(tmp, (u8 *) (work32 + 2), 16));
47503- seq_printf(seq, "Product info : %s\n",
47504- chtostr(tmp, (u8 *) (work32 + 6), 16));
47505- seq_printf(seq, "Description : %s\n",
47506- chtostr(tmp, (u8 *) (work32 + 10), 16));
47507- seq_printf(seq, "Product rev. : %s\n",
47508- chtostr(tmp, (u8 *) (work32 + 14), 8));
47509+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
47510+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
47511+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
47512+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
47513
47514 seq_printf(seq, "Serial number : ");
47515 print_serial_number(seq, (u8 *) (work32 + 16),
47516@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47517 u8 pad[256]; // allow up to 256 byte (max) serial number
47518 } result;
47519
47520- char tmp[24 + 1];
47521-
47522 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
47523
47524 if (token < 0) {
47525@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47526 }
47527
47528 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
47529- seq_printf(seq, "Module name : %s\n",
47530- chtostr(tmp, result.module_name, 24));
47531- seq_printf(seq, "Module revision : %s\n",
47532- chtostr(tmp, result.module_rev, 8));
47533+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
47534+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
47535
47536 seq_printf(seq, "Serial number : ");
47537 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
47538@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47539 u8 instance_number[4];
47540 } result;
47541
47542- char tmp[64 + 1];
47543-
47544 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
47545
47546 if (token < 0) {
47547@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47548 return 0;
47549 }
47550
47551- seq_printf(seq, "Device name : %s\n",
47552- chtostr(tmp, result.device_name, 64));
47553- seq_printf(seq, "Service name : %s\n",
47554- chtostr(tmp, result.service_name, 64));
47555- seq_printf(seq, "Physical name : %s\n",
47556- chtostr(tmp, result.physical_location, 64));
47557- seq_printf(seq, "Instance number : %s\n",
47558- chtostr(tmp, result.instance_number, 4));
47559+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
47560+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
47561+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
47562+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
47563
47564 return 0;
47565 }
47566@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47567 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
47568 {
47569 struct i2o_device *d = (struct i2o_device *)seq->private;
47570- static u32 work32[12];
47571- static u16 *work16 = (u16 *) work32;
47572- static u8 *work8 = (u8 *) work32;
47573+ u32 work32[12];
47574+ u16 *work16 = (u16 *) work32;
47575+ u8 *work8 = (u8 *) work32;
47576 int token;
47577
47578 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
47579diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
47580index 92752fb..a7494f6 100644
47581--- a/drivers/message/i2o/iop.c
47582+++ b/drivers/message/i2o/iop.c
47583@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
47584
47585 spin_lock_irqsave(&c->context_list_lock, flags);
47586
47587- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
47588- atomic_inc(&c->context_list_counter);
47589+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
47590+ atomic_inc_unchecked(&c->context_list_counter);
47591
47592- entry->context = atomic_read(&c->context_list_counter);
47593+ entry->context = atomic_read_unchecked(&c->context_list_counter);
47594
47595 list_add(&entry->list, &c->context_list);
47596
47597@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
47598
47599 #if BITS_PER_LONG == 64
47600 spin_lock_init(&c->context_list_lock);
47601- atomic_set(&c->context_list_counter, 0);
47602+ atomic_set_unchecked(&c->context_list_counter, 0);
47603 INIT_LIST_HEAD(&c->context_list);
47604 #endif
47605
47606diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
47607index d1a22aa..d0f7bf7 100644
47608--- a/drivers/mfd/ab8500-debugfs.c
47609+++ b/drivers/mfd/ab8500-debugfs.c
47610@@ -100,7 +100,7 @@ static int irq_last;
47611 static u32 *irq_count;
47612 static int num_irqs;
47613
47614-static struct device_attribute **dev_attr;
47615+static device_attribute_no_const **dev_attr;
47616 static char **event_name;
47617
47618 static u8 avg_sample = SAMPLE_16;
47619diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
47620index a83eed5..62a58a9 100644
47621--- a/drivers/mfd/max8925-i2c.c
47622+++ b/drivers/mfd/max8925-i2c.c
47623@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
47624 const struct i2c_device_id *id)
47625 {
47626 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
47627- static struct max8925_chip *chip;
47628+ struct max8925_chip *chip;
47629 struct device_node *node = client->dev.of_node;
47630
47631 if (node && !pdata) {
47632diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
47633index f9e42ea..614d240 100644
47634--- a/drivers/mfd/tps65910.c
47635+++ b/drivers/mfd/tps65910.c
47636@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
47637 struct tps65910_platform_data *pdata)
47638 {
47639 int ret = 0;
47640- static struct regmap_irq_chip *tps6591x_irqs_chip;
47641+ struct regmap_irq_chip *tps6591x_irqs_chip;
47642
47643 if (!irq) {
47644 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
47645diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
47646index 596b1f6..5b6ab74 100644
47647--- a/drivers/mfd/twl4030-irq.c
47648+++ b/drivers/mfd/twl4030-irq.c
47649@@ -34,6 +34,7 @@
47650 #include <linux/of.h>
47651 #include <linux/irqdomain.h>
47652 #include <linux/i2c/twl.h>
47653+#include <asm/pgtable.h>
47654
47655 #include "twl-core.h"
47656
47657@@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
47658 * Install an irq handler for each of the SIH modules;
47659 * clone dummy irq_chip since PIH can't *do* anything
47660 */
47661- twl4030_irq_chip = dummy_irq_chip;
47662- twl4030_irq_chip.name = "twl4030";
47663+ pax_open_kernel();
47664+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
47665+ *(const char **)&twl4030_irq_chip.name = "twl4030";
47666
47667- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47668+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47669+ pax_close_kernel();
47670
47671 for (i = irq_base; i < irq_end; i++) {
47672 irq_set_chip_and_handler(i, &twl4030_irq_chip,
47673diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
47674index 464419b..64bae8d 100644
47675--- a/drivers/misc/c2port/core.c
47676+++ b/drivers/misc/c2port/core.c
47677@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
47678 goto error_idr_alloc;
47679 c2dev->id = ret;
47680
47681- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47682+ pax_open_kernel();
47683+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47684+ pax_close_kernel();
47685
47686 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
47687 "c2port%d", c2dev->id);
47688diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
47689index 3f2b625..945e179 100644
47690--- a/drivers/misc/eeprom/sunxi_sid.c
47691+++ b/drivers/misc/eeprom/sunxi_sid.c
47692@@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
47693
47694 platform_set_drvdata(pdev, sid_data);
47695
47696- sid_bin_attr.size = sid_data->keysize;
47697+ pax_open_kernel();
47698+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
47699+ pax_close_kernel();
47700 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
47701 return -ENODEV;
47702
47703diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
47704index 36f5d52..32311c3 100644
47705--- a/drivers/misc/kgdbts.c
47706+++ b/drivers/misc/kgdbts.c
47707@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
47708 char before[BREAK_INSTR_SIZE];
47709 char after[BREAK_INSTR_SIZE];
47710
47711- probe_kernel_read(before, (char *)kgdbts_break_test,
47712+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
47713 BREAK_INSTR_SIZE);
47714 init_simple_test();
47715 ts.tst = plant_and_detach_test;
47716@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
47717 /* Activate test with initial breakpoint */
47718 if (!is_early)
47719 kgdb_breakpoint();
47720- probe_kernel_read(after, (char *)kgdbts_break_test,
47721+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
47722 BREAK_INSTR_SIZE);
47723 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
47724 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
47725diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
47726index 3ef4627..8d00486 100644
47727--- a/drivers/misc/lis3lv02d/lis3lv02d.c
47728+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
47729@@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
47730 * the lid is closed. This leads to interrupts as soon as a little move
47731 * is done.
47732 */
47733- atomic_inc(&lis3->count);
47734+ atomic_inc_unchecked(&lis3->count);
47735
47736 wake_up_interruptible(&lis3->misc_wait);
47737 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
47738@@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
47739 if (lis3->pm_dev)
47740 pm_runtime_get_sync(lis3->pm_dev);
47741
47742- atomic_set(&lis3->count, 0);
47743+ atomic_set_unchecked(&lis3->count, 0);
47744 return 0;
47745 }
47746
47747@@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
47748 add_wait_queue(&lis3->misc_wait, &wait);
47749 while (true) {
47750 set_current_state(TASK_INTERRUPTIBLE);
47751- data = atomic_xchg(&lis3->count, 0);
47752+ data = atomic_xchg_unchecked(&lis3->count, 0);
47753 if (data)
47754 break;
47755
47756@@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
47757 struct lis3lv02d, miscdev);
47758
47759 poll_wait(file, &lis3->misc_wait, wait);
47760- if (atomic_read(&lis3->count))
47761+ if (atomic_read_unchecked(&lis3->count))
47762 return POLLIN | POLLRDNORM;
47763 return 0;
47764 }
47765diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
47766index c439c82..1f20f57 100644
47767--- a/drivers/misc/lis3lv02d/lis3lv02d.h
47768+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
47769@@ -297,7 +297,7 @@ struct lis3lv02d {
47770 struct input_polled_dev *idev; /* input device */
47771 struct platform_device *pdev; /* platform device */
47772 struct regulator_bulk_data regulators[2];
47773- atomic_t count; /* interrupt count after last read */
47774+ atomic_unchecked_t count; /* interrupt count after last read */
47775 union axis_conversion ac; /* hw -> logical axis */
47776 int mapped_btns[3];
47777
47778diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
47779index 2f30bad..c4c13d0 100644
47780--- a/drivers/misc/sgi-gru/gruhandles.c
47781+++ b/drivers/misc/sgi-gru/gruhandles.c
47782@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
47783 unsigned long nsec;
47784
47785 nsec = CLKS2NSEC(clks);
47786- atomic_long_inc(&mcs_op_statistics[op].count);
47787- atomic_long_add(nsec, &mcs_op_statistics[op].total);
47788+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
47789+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
47790 if (mcs_op_statistics[op].max < nsec)
47791 mcs_op_statistics[op].max = nsec;
47792 }
47793diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
47794index 4f76359..cdfcb2e 100644
47795--- a/drivers/misc/sgi-gru/gruprocfs.c
47796+++ b/drivers/misc/sgi-gru/gruprocfs.c
47797@@ -32,9 +32,9 @@
47798
47799 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
47800
47801-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
47802+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
47803 {
47804- unsigned long val = atomic_long_read(v);
47805+ unsigned long val = atomic_long_read_unchecked(v);
47806
47807 seq_printf(s, "%16lu %s\n", val, id);
47808 }
47809@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
47810
47811 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
47812 for (op = 0; op < mcsop_last; op++) {
47813- count = atomic_long_read(&mcs_op_statistics[op].count);
47814- total = atomic_long_read(&mcs_op_statistics[op].total);
47815+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
47816+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
47817 max = mcs_op_statistics[op].max;
47818 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
47819 count ? total / count : 0, max);
47820diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
47821index 5c3ce24..4915ccb 100644
47822--- a/drivers/misc/sgi-gru/grutables.h
47823+++ b/drivers/misc/sgi-gru/grutables.h
47824@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
47825 * GRU statistics.
47826 */
47827 struct gru_stats_s {
47828- atomic_long_t vdata_alloc;
47829- atomic_long_t vdata_free;
47830- atomic_long_t gts_alloc;
47831- atomic_long_t gts_free;
47832- atomic_long_t gms_alloc;
47833- atomic_long_t gms_free;
47834- atomic_long_t gts_double_allocate;
47835- atomic_long_t assign_context;
47836- atomic_long_t assign_context_failed;
47837- atomic_long_t free_context;
47838- atomic_long_t load_user_context;
47839- atomic_long_t load_kernel_context;
47840- atomic_long_t lock_kernel_context;
47841- atomic_long_t unlock_kernel_context;
47842- atomic_long_t steal_user_context;
47843- atomic_long_t steal_kernel_context;
47844- atomic_long_t steal_context_failed;
47845- atomic_long_t nopfn;
47846- atomic_long_t asid_new;
47847- atomic_long_t asid_next;
47848- atomic_long_t asid_wrap;
47849- atomic_long_t asid_reuse;
47850- atomic_long_t intr;
47851- atomic_long_t intr_cbr;
47852- atomic_long_t intr_tfh;
47853- atomic_long_t intr_spurious;
47854- atomic_long_t intr_mm_lock_failed;
47855- atomic_long_t call_os;
47856- atomic_long_t call_os_wait_queue;
47857- atomic_long_t user_flush_tlb;
47858- atomic_long_t user_unload_context;
47859- atomic_long_t user_exception;
47860- atomic_long_t set_context_option;
47861- atomic_long_t check_context_retarget_intr;
47862- atomic_long_t check_context_unload;
47863- atomic_long_t tlb_dropin;
47864- atomic_long_t tlb_preload_page;
47865- atomic_long_t tlb_dropin_fail_no_asid;
47866- atomic_long_t tlb_dropin_fail_upm;
47867- atomic_long_t tlb_dropin_fail_invalid;
47868- atomic_long_t tlb_dropin_fail_range_active;
47869- atomic_long_t tlb_dropin_fail_idle;
47870- atomic_long_t tlb_dropin_fail_fmm;
47871- atomic_long_t tlb_dropin_fail_no_exception;
47872- atomic_long_t tfh_stale_on_fault;
47873- atomic_long_t mmu_invalidate_range;
47874- atomic_long_t mmu_invalidate_page;
47875- atomic_long_t flush_tlb;
47876- atomic_long_t flush_tlb_gru;
47877- atomic_long_t flush_tlb_gru_tgh;
47878- atomic_long_t flush_tlb_gru_zero_asid;
47879+ atomic_long_unchecked_t vdata_alloc;
47880+ atomic_long_unchecked_t vdata_free;
47881+ atomic_long_unchecked_t gts_alloc;
47882+ atomic_long_unchecked_t gts_free;
47883+ atomic_long_unchecked_t gms_alloc;
47884+ atomic_long_unchecked_t gms_free;
47885+ atomic_long_unchecked_t gts_double_allocate;
47886+ atomic_long_unchecked_t assign_context;
47887+ atomic_long_unchecked_t assign_context_failed;
47888+ atomic_long_unchecked_t free_context;
47889+ atomic_long_unchecked_t load_user_context;
47890+ atomic_long_unchecked_t load_kernel_context;
47891+ atomic_long_unchecked_t lock_kernel_context;
47892+ atomic_long_unchecked_t unlock_kernel_context;
47893+ atomic_long_unchecked_t steal_user_context;
47894+ atomic_long_unchecked_t steal_kernel_context;
47895+ atomic_long_unchecked_t steal_context_failed;
47896+ atomic_long_unchecked_t nopfn;
47897+ atomic_long_unchecked_t asid_new;
47898+ atomic_long_unchecked_t asid_next;
47899+ atomic_long_unchecked_t asid_wrap;
47900+ atomic_long_unchecked_t asid_reuse;
47901+ atomic_long_unchecked_t intr;
47902+ atomic_long_unchecked_t intr_cbr;
47903+ atomic_long_unchecked_t intr_tfh;
47904+ atomic_long_unchecked_t intr_spurious;
47905+ atomic_long_unchecked_t intr_mm_lock_failed;
47906+ atomic_long_unchecked_t call_os;
47907+ atomic_long_unchecked_t call_os_wait_queue;
47908+ atomic_long_unchecked_t user_flush_tlb;
47909+ atomic_long_unchecked_t user_unload_context;
47910+ atomic_long_unchecked_t user_exception;
47911+ atomic_long_unchecked_t set_context_option;
47912+ atomic_long_unchecked_t check_context_retarget_intr;
47913+ atomic_long_unchecked_t check_context_unload;
47914+ atomic_long_unchecked_t tlb_dropin;
47915+ atomic_long_unchecked_t tlb_preload_page;
47916+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
47917+ atomic_long_unchecked_t tlb_dropin_fail_upm;
47918+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
47919+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
47920+ atomic_long_unchecked_t tlb_dropin_fail_idle;
47921+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
47922+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
47923+ atomic_long_unchecked_t tfh_stale_on_fault;
47924+ atomic_long_unchecked_t mmu_invalidate_range;
47925+ atomic_long_unchecked_t mmu_invalidate_page;
47926+ atomic_long_unchecked_t flush_tlb;
47927+ atomic_long_unchecked_t flush_tlb_gru;
47928+ atomic_long_unchecked_t flush_tlb_gru_tgh;
47929+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
47930
47931- atomic_long_t copy_gpa;
47932- atomic_long_t read_gpa;
47933+ atomic_long_unchecked_t copy_gpa;
47934+ atomic_long_unchecked_t read_gpa;
47935
47936- atomic_long_t mesq_receive;
47937- atomic_long_t mesq_receive_none;
47938- atomic_long_t mesq_send;
47939- atomic_long_t mesq_send_failed;
47940- atomic_long_t mesq_noop;
47941- atomic_long_t mesq_send_unexpected_error;
47942- atomic_long_t mesq_send_lb_overflow;
47943- atomic_long_t mesq_send_qlimit_reached;
47944- atomic_long_t mesq_send_amo_nacked;
47945- atomic_long_t mesq_send_put_nacked;
47946- atomic_long_t mesq_page_overflow;
47947- atomic_long_t mesq_qf_locked;
47948- atomic_long_t mesq_qf_noop_not_full;
47949- atomic_long_t mesq_qf_switch_head_failed;
47950- atomic_long_t mesq_qf_unexpected_error;
47951- atomic_long_t mesq_noop_unexpected_error;
47952- atomic_long_t mesq_noop_lb_overflow;
47953- atomic_long_t mesq_noop_qlimit_reached;
47954- atomic_long_t mesq_noop_amo_nacked;
47955- atomic_long_t mesq_noop_put_nacked;
47956- atomic_long_t mesq_noop_page_overflow;
47957+ atomic_long_unchecked_t mesq_receive;
47958+ atomic_long_unchecked_t mesq_receive_none;
47959+ atomic_long_unchecked_t mesq_send;
47960+ atomic_long_unchecked_t mesq_send_failed;
47961+ atomic_long_unchecked_t mesq_noop;
47962+ atomic_long_unchecked_t mesq_send_unexpected_error;
47963+ atomic_long_unchecked_t mesq_send_lb_overflow;
47964+ atomic_long_unchecked_t mesq_send_qlimit_reached;
47965+ atomic_long_unchecked_t mesq_send_amo_nacked;
47966+ atomic_long_unchecked_t mesq_send_put_nacked;
47967+ atomic_long_unchecked_t mesq_page_overflow;
47968+ atomic_long_unchecked_t mesq_qf_locked;
47969+ atomic_long_unchecked_t mesq_qf_noop_not_full;
47970+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
47971+ atomic_long_unchecked_t mesq_qf_unexpected_error;
47972+ atomic_long_unchecked_t mesq_noop_unexpected_error;
47973+ atomic_long_unchecked_t mesq_noop_lb_overflow;
47974+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
47975+ atomic_long_unchecked_t mesq_noop_amo_nacked;
47976+ atomic_long_unchecked_t mesq_noop_put_nacked;
47977+ atomic_long_unchecked_t mesq_noop_page_overflow;
47978
47979 };
47980
47981@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
47982 tghop_invalidate, mcsop_last};
47983
47984 struct mcs_op_statistic {
47985- atomic_long_t count;
47986- atomic_long_t total;
47987+ atomic_long_unchecked_t count;
47988+ atomic_long_unchecked_t total;
47989 unsigned long max;
47990 };
47991
47992@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
47993
47994 #define STAT(id) do { \
47995 if (gru_options & OPT_STATS) \
47996- atomic_long_inc(&gru_stats.id); \
47997+ atomic_long_inc_unchecked(&gru_stats.id); \
47998 } while (0)
47999
48000 #ifdef CONFIG_SGI_GRU_DEBUG
48001diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
48002index c862cd4..0d176fe 100644
48003--- a/drivers/misc/sgi-xp/xp.h
48004+++ b/drivers/misc/sgi-xp/xp.h
48005@@ -288,7 +288,7 @@ struct xpc_interface {
48006 xpc_notify_func, void *);
48007 void (*received) (short, int, void *);
48008 enum xp_retval (*partid_to_nasids) (short, void *);
48009-};
48010+} __no_const;
48011
48012 extern struct xpc_interface xpc_interface;
48013
48014diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
48015index 01be66d..e3a0c7e 100644
48016--- a/drivers/misc/sgi-xp/xp_main.c
48017+++ b/drivers/misc/sgi-xp/xp_main.c
48018@@ -78,13 +78,13 @@ xpc_notloaded(void)
48019 }
48020
48021 struct xpc_interface xpc_interface = {
48022- (void (*)(int))xpc_notloaded,
48023- (void (*)(int))xpc_notloaded,
48024- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
48025- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
48026+ .connect = (void (*)(int))xpc_notloaded,
48027+ .disconnect = (void (*)(int))xpc_notloaded,
48028+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
48029+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
48030 void *))xpc_notloaded,
48031- (void (*)(short, int, void *))xpc_notloaded,
48032- (enum xp_retval(*)(short, void *))xpc_notloaded
48033+ .received = (void (*)(short, int, void *))xpc_notloaded,
48034+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
48035 };
48036 EXPORT_SYMBOL_GPL(xpc_interface);
48037
48038diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
48039index b94d5f7..7f494c5 100644
48040--- a/drivers/misc/sgi-xp/xpc.h
48041+++ b/drivers/misc/sgi-xp/xpc.h
48042@@ -835,6 +835,7 @@ struct xpc_arch_operations {
48043 void (*received_payload) (struct xpc_channel *, void *);
48044 void (*notify_senders_of_disconnect) (struct xpc_channel *);
48045 };
48046+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
48047
48048 /* struct xpc_partition act_state values (for XPC HB) */
48049
48050@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
48051 /* found in xpc_main.c */
48052 extern struct device *xpc_part;
48053 extern struct device *xpc_chan;
48054-extern struct xpc_arch_operations xpc_arch_ops;
48055+extern xpc_arch_operations_no_const xpc_arch_ops;
48056 extern int xpc_disengage_timelimit;
48057 extern int xpc_disengage_timedout;
48058 extern int xpc_activate_IRQ_rcvd;
48059diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
48060index 82dc574..8539ab2 100644
48061--- a/drivers/misc/sgi-xp/xpc_main.c
48062+++ b/drivers/misc/sgi-xp/xpc_main.c
48063@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
48064 .notifier_call = xpc_system_die,
48065 };
48066
48067-struct xpc_arch_operations xpc_arch_ops;
48068+xpc_arch_operations_no_const xpc_arch_ops;
48069
48070 /*
48071 * Timer function to enforce the timelimit on the partition disengage.
48072@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
48073
48074 if (((die_args->trapnr == X86_TRAP_MF) ||
48075 (die_args->trapnr == X86_TRAP_XF)) &&
48076- !user_mode_vm(die_args->regs))
48077+ !user_mode(die_args->regs))
48078 xpc_die_deactivate();
48079
48080 break;
48081diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
48082index 452782b..0c10e40 100644
48083--- a/drivers/mmc/card/block.c
48084+++ b/drivers/mmc/card/block.c
48085@@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
48086 if (idata->ic.postsleep_min_us)
48087 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
48088
48089- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
48090+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
48091 err = -EFAULT;
48092 goto cmd_rel_host;
48093 }
48094diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
48095index f51b5ba..86614a7 100644
48096--- a/drivers/mmc/core/mmc_ops.c
48097+++ b/drivers/mmc/core/mmc_ops.c
48098@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
48099 void *data_buf;
48100 int is_on_stack;
48101
48102- is_on_stack = object_is_on_stack(buf);
48103+ is_on_stack = object_starts_on_stack(buf);
48104 if (is_on_stack) {
48105 /*
48106 * dma onto stack is unsafe/nonportable, but callers to this
48107diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
48108index 738fa24..1568451 100644
48109--- a/drivers/mmc/host/dw_mmc.h
48110+++ b/drivers/mmc/host/dw_mmc.h
48111@@ -257,5 +257,5 @@ struct dw_mci_drv_data {
48112 int (*parse_dt)(struct dw_mci *host);
48113 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
48114 struct dw_mci_tuning_data *tuning_data);
48115-};
48116+} __do_const;
48117 #endif /* _DW_MMC_H_ */
48118diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
48119index 7ad463e..2aa0079 100644
48120--- a/drivers/mmc/host/mmci.c
48121+++ b/drivers/mmc/host/mmci.c
48122@@ -1506,7 +1506,9 @@ static int mmci_probe(struct amba_device *dev,
48123 mmc->caps |= MMC_CAP_CMD23;
48124
48125 if (variant->busy_detect) {
48126- mmci_ops.card_busy = mmci_card_busy;
48127+ pax_open_kernel();
48128+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
48129+ pax_close_kernel();
48130 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
48131 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
48132 mmc->max_busy_timeout = 0;
48133diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
48134index ccec0e3..199f9ce 100644
48135--- a/drivers/mmc/host/sdhci-esdhc-imx.c
48136+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
48137@@ -1034,9 +1034,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
48138 host->mmc->caps |= MMC_CAP_1_8V_DDR;
48139 }
48140
48141- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
48142- sdhci_esdhc_ops.platform_execute_tuning =
48143+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
48144+ pax_open_kernel();
48145+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
48146 esdhc_executing_tuning;
48147+ pax_close_kernel();
48148+ }
48149
48150 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
48151 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
48152diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
48153index fa5954a..56840e5 100644
48154--- a/drivers/mmc/host/sdhci-s3c.c
48155+++ b/drivers/mmc/host/sdhci-s3c.c
48156@@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
48157 * we can use overriding functions instead of default.
48158 */
48159 if (sc->no_divider) {
48160- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
48161- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
48162- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
48163+ pax_open_kernel();
48164+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
48165+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
48166+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
48167+ pax_close_kernel();
48168 }
48169
48170 /* It supports additional host capabilities if needed */
48171diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
48172index 423666b..81ff5eb 100644
48173--- a/drivers/mtd/chips/cfi_cmdset_0020.c
48174+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
48175@@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
48176 size_t totlen = 0, thislen;
48177 int ret = 0;
48178 size_t buflen = 0;
48179- static char *buffer;
48180+ char *buffer;
48181
48182 if (!ECCBUF_SIZE) {
48183 /* We should fall back to a general writev implementation.
48184diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
48185index 9f2012a..a81c720 100644
48186--- a/drivers/mtd/nand/denali.c
48187+++ b/drivers/mtd/nand/denali.c
48188@@ -24,6 +24,7 @@
48189 #include <linux/slab.h>
48190 #include <linux/mtd/mtd.h>
48191 #include <linux/module.h>
48192+#include <linux/slab.h>
48193
48194 #include "denali.h"
48195
48196diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48197index f638cd8..2cbf586 100644
48198--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48199+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48200@@ -387,7 +387,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
48201
48202 /* first try to map the upper buffer directly */
48203 if (virt_addr_valid(this->upper_buf) &&
48204- !object_is_on_stack(this->upper_buf)) {
48205+ !object_starts_on_stack(this->upper_buf)) {
48206 sg_init_one(sgl, this->upper_buf, this->upper_len);
48207 ret = dma_map_sg(this->dev, sgl, 1, dr);
48208 if (ret == 0)
48209diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
48210index 51b9d6a..52af9a7 100644
48211--- a/drivers/mtd/nftlmount.c
48212+++ b/drivers/mtd/nftlmount.c
48213@@ -24,6 +24,7 @@
48214 #include <asm/errno.h>
48215 #include <linux/delay.h>
48216 #include <linux/slab.h>
48217+#include <linux/sched.h>
48218 #include <linux/mtd/mtd.h>
48219 #include <linux/mtd/nand.h>
48220 #include <linux/mtd/nftl.h>
48221diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
48222index cf49c22..971b133 100644
48223--- a/drivers/mtd/sm_ftl.c
48224+++ b/drivers/mtd/sm_ftl.c
48225@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
48226 #define SM_CIS_VENDOR_OFFSET 0x59
48227 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
48228 {
48229- struct attribute_group *attr_group;
48230+ attribute_group_no_const *attr_group;
48231 struct attribute **attributes;
48232 struct sm_sysfs_attribute *vendor_attribute;
48233 char *vendor;
48234diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
48235index 5ab3c18..5c3a836 100644
48236--- a/drivers/net/bonding/bond_netlink.c
48237+++ b/drivers/net/bonding/bond_netlink.c
48238@@ -542,7 +542,7 @@ nla_put_failure:
48239 return -EMSGSIZE;
48240 }
48241
48242-struct rtnl_link_ops bond_link_ops __read_mostly = {
48243+struct rtnl_link_ops bond_link_ops = {
48244 .kind = "bond",
48245 .priv_size = sizeof(struct bonding),
48246 .setup = bond_setup,
48247diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
48248index 4168822..f38eeddf 100644
48249--- a/drivers/net/can/Kconfig
48250+++ b/drivers/net/can/Kconfig
48251@@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
48252
48253 config CAN_FLEXCAN
48254 tristate "Support for Freescale FLEXCAN based chips"
48255- depends on ARM || PPC
48256+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
48257 ---help---
48258 Say Y here if you want to support for Freescale FlexCAN.
48259
48260diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
48261index 1d162cc..b546a75 100644
48262--- a/drivers/net/ethernet/8390/ax88796.c
48263+++ b/drivers/net/ethernet/8390/ax88796.c
48264@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
48265 if (ax->plat->reg_offsets)
48266 ei_local->reg_offset = ax->plat->reg_offsets;
48267 else {
48268+ resource_size_t _mem_size = mem_size;
48269+ do_div(_mem_size, 0x18);
48270 ei_local->reg_offset = ax->reg_offsets;
48271 for (ret = 0; ret < 0x18; ret++)
48272- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
48273+ ax->reg_offsets[ret] = _mem_size * ret;
48274 }
48275
48276 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
48277diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
48278index 7330681..7e9e463 100644
48279--- a/drivers/net/ethernet/altera/altera_tse_main.c
48280+++ b/drivers/net/ethernet/altera/altera_tse_main.c
48281@@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
48282 return 0;
48283 }
48284
48285-static struct net_device_ops altera_tse_netdev_ops = {
48286+static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
48287 .ndo_open = tse_open,
48288 .ndo_stop = tse_shutdown,
48289 .ndo_start_xmit = tse_start_xmit,
48290@@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
48291 ndev->netdev_ops = &altera_tse_netdev_ops;
48292 altera_tse_set_ethtool_ops(ndev);
48293
48294+ pax_open_kernel();
48295 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
48296
48297 if (priv->hash_filter)
48298 altera_tse_netdev_ops.ndo_set_rx_mode =
48299 tse_set_rx_mode_hashfilter;
48300+ pax_close_kernel();
48301
48302 /* Scatter/gather IO is not supported,
48303 * so it is turned off
48304diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48305index bf462ee8..18b8375 100644
48306--- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48307+++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48308@@ -986,14 +986,14 @@ do { \
48309 * operations, everything works on mask values.
48310 */
48311 #define XMDIO_READ(_pdata, _mmd, _reg) \
48312- ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
48313+ ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
48314 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
48315
48316 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
48317 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
48318
48319 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
48320- ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
48321+ ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
48322 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
48323
48324 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
48325diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
48326index 6bb76d5..ded47a8 100644
48327--- a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
48328+++ b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
48329@@ -273,7 +273,7 @@ static ssize_t xpcs_reg_value_read(struct file *filp, char __user *buffer,
48330 struct xgbe_prv_data *pdata = filp->private_data;
48331 unsigned int value;
48332
48333- value = pdata->hw_if.read_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48334+ value = pdata->hw_if->read_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48335 pdata->debugfs_xpcs_reg);
48336
48337 return xgbe_common_read(buffer, count, ppos, value);
48338@@ -291,7 +291,7 @@ static ssize_t xpcs_reg_value_write(struct file *filp,
48339 if (len < 0)
48340 return len;
48341
48342- pdata->hw_if.write_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48343+ pdata->hw_if->write_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48344 pdata->debugfs_xpcs_reg, value);
48345
48346 return len;
48347diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48348index 6f1c859..e96ac1a 100644
48349--- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48350+++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48351@@ -236,7 +236,7 @@ err_ring:
48352
48353 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
48354 {
48355- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48356+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48357 struct xgbe_channel *channel;
48358 struct xgbe_ring *ring;
48359 struct xgbe_ring_data *rdata;
48360@@ -277,7 +277,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
48361
48362 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
48363 {
48364- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48365+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48366 struct xgbe_channel *channel;
48367 struct xgbe_ring *ring;
48368 struct xgbe_ring_desc *rdesc;
48369@@ -496,7 +496,7 @@ err_out:
48370 static void xgbe_realloc_skb(struct xgbe_channel *channel)
48371 {
48372 struct xgbe_prv_data *pdata = channel->pdata;
48373- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48374+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48375 struct xgbe_ring *ring = channel->rx_ring;
48376 struct xgbe_ring_data *rdata;
48377 struct sk_buff *skb = NULL;
48378@@ -540,17 +540,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
48379 DBGPR("<--xgbe_realloc_skb\n");
48380 }
48381
48382-void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
48383-{
48384- DBGPR("-->xgbe_init_function_ptrs_desc\n");
48385-
48386- desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
48387- desc_if->free_ring_resources = xgbe_free_ring_resources;
48388- desc_if->map_tx_skb = xgbe_map_tx_skb;
48389- desc_if->realloc_skb = xgbe_realloc_skb;
48390- desc_if->unmap_skb = xgbe_unmap_skb;
48391- desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
48392- desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
48393-
48394- DBGPR("<--xgbe_init_function_ptrs_desc\n");
48395-}
48396+const struct xgbe_desc_if default_xgbe_desc_if = {
48397+ .alloc_ring_resources = xgbe_alloc_ring_resources,
48398+ .free_ring_resources = xgbe_free_ring_resources,
48399+ .map_tx_skb = xgbe_map_tx_skb,
48400+ .realloc_skb = xgbe_realloc_skb,
48401+ .unmap_skb = xgbe_unmap_skb,
48402+ .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
48403+ .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
48404+};
48405diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48406index 002293b..5ced1dd 100644
48407--- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48408+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48409@@ -2030,7 +2030,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
48410
48411 static int xgbe_init(struct xgbe_prv_data *pdata)
48412 {
48413- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48414+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48415 int ret;
48416
48417 DBGPR("-->xgbe_init\n");
48418@@ -2096,87 +2096,82 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
48419 return 0;
48420 }
48421
48422-void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
48423-{
48424- DBGPR("-->xgbe_init_function_ptrs\n");
48425-
48426- hw_if->tx_complete = xgbe_tx_complete;
48427-
48428- hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
48429- hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
48430- hw_if->set_addn_mac_addrs = xgbe_set_addn_mac_addrs;
48431- hw_if->set_mac_address = xgbe_set_mac_address;
48432-
48433- hw_if->enable_rx_csum = xgbe_enable_rx_csum;
48434- hw_if->disable_rx_csum = xgbe_disable_rx_csum;
48435-
48436- hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
48437- hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
48438-
48439- hw_if->read_mmd_regs = xgbe_read_mmd_regs;
48440- hw_if->write_mmd_regs = xgbe_write_mmd_regs;
48441-
48442- hw_if->set_gmii_speed = xgbe_set_gmii_speed;
48443- hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
48444- hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
48445-
48446- hw_if->enable_tx = xgbe_enable_tx;
48447- hw_if->disable_tx = xgbe_disable_tx;
48448- hw_if->enable_rx = xgbe_enable_rx;
48449- hw_if->disable_rx = xgbe_disable_rx;
48450-
48451- hw_if->powerup_tx = xgbe_powerup_tx;
48452- hw_if->powerdown_tx = xgbe_powerdown_tx;
48453- hw_if->powerup_rx = xgbe_powerup_rx;
48454- hw_if->powerdown_rx = xgbe_powerdown_rx;
48455-
48456- hw_if->pre_xmit = xgbe_pre_xmit;
48457- hw_if->dev_read = xgbe_dev_read;
48458- hw_if->enable_int = xgbe_enable_int;
48459- hw_if->disable_int = xgbe_disable_int;
48460- hw_if->init = xgbe_init;
48461- hw_if->exit = xgbe_exit;
48462+const struct xgbe_hw_if default_xgbe_hw_if = {
48463+ .tx_complete = xgbe_tx_complete,
48464+
48465+ .set_promiscuous_mode = xgbe_set_promiscuous_mode,
48466+ .set_all_multicast_mode = xgbe_set_all_multicast_mode,
48467+ .set_addn_mac_addrs = xgbe_set_addn_mac_addrs,
48468+ .set_mac_address = xgbe_set_mac_address,
48469+
48470+ .enable_rx_csum = xgbe_enable_rx_csum,
48471+ .disable_rx_csum = xgbe_disable_rx_csum,
48472+
48473+ .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
48474+ .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
48475+
48476+ .read_mmd_regs = xgbe_read_mmd_regs,
48477+ .write_mmd_regs = xgbe_write_mmd_regs,
48478+
48479+ .set_gmii_speed = xgbe_set_gmii_speed,
48480+ .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
48481+ .set_xgmii_speed = xgbe_set_xgmii_speed,
48482+
48483+ .enable_tx = xgbe_enable_tx,
48484+ .disable_tx = xgbe_disable_tx,
48485+ .enable_rx = xgbe_enable_rx,
48486+ .disable_rx = xgbe_disable_rx,
48487+
48488+ .powerup_tx = xgbe_powerup_tx,
48489+ .powerdown_tx = xgbe_powerdown_tx,
48490+ .powerup_rx = xgbe_powerup_rx,
48491+ .powerdown_rx = xgbe_powerdown_rx,
48492+
48493+ .pre_xmit = xgbe_pre_xmit,
48494+ .dev_read = xgbe_dev_read,
48495+ .enable_int = xgbe_enable_int,
48496+ .disable_int = xgbe_disable_int,
48497+ .init = xgbe_init,
48498+ .exit = xgbe_exit,
48499
48500 /* Descriptor related Sequences have to be initialized here */
48501- hw_if->tx_desc_init = xgbe_tx_desc_init;
48502- hw_if->rx_desc_init = xgbe_rx_desc_init;
48503- hw_if->tx_desc_reset = xgbe_tx_desc_reset;
48504- hw_if->rx_desc_reset = xgbe_rx_desc_reset;
48505- hw_if->is_last_desc = xgbe_is_last_desc;
48506- hw_if->is_context_desc = xgbe_is_context_desc;
48507+ .tx_desc_init = xgbe_tx_desc_init,
48508+ .rx_desc_init = xgbe_rx_desc_init,
48509+ .tx_desc_reset = xgbe_tx_desc_reset,
48510+ .rx_desc_reset = xgbe_rx_desc_reset,
48511+ .is_last_desc = xgbe_is_last_desc,
48512+ .is_context_desc = xgbe_is_context_desc,
48513
48514 /* For FLOW ctrl */
48515- hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
48516- hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
48517+ .config_tx_flow_control = xgbe_config_tx_flow_control,
48518+ .config_rx_flow_control = xgbe_config_rx_flow_control,
48519
48520 /* For RX coalescing */
48521- hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
48522- hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
48523- hw_if->usec_to_riwt = xgbe_usec_to_riwt;
48524- hw_if->riwt_to_usec = xgbe_riwt_to_usec;
48525+ .config_rx_coalesce = xgbe_config_rx_coalesce,
48526+ .config_tx_coalesce = xgbe_config_tx_coalesce,
48527+ .usec_to_riwt = xgbe_usec_to_riwt,
48528+ .riwt_to_usec = xgbe_riwt_to_usec,
48529
48530 /* For RX and TX threshold config */
48531- hw_if->config_rx_threshold = xgbe_config_rx_threshold;
48532- hw_if->config_tx_threshold = xgbe_config_tx_threshold;
48533+ .config_rx_threshold = xgbe_config_rx_threshold,
48534+ .config_tx_threshold = xgbe_config_tx_threshold,
48535
48536 /* For RX and TX Store and Forward Mode config */
48537- hw_if->config_rsf_mode = xgbe_config_rsf_mode;
48538- hw_if->config_tsf_mode = xgbe_config_tsf_mode;
48539+ .config_rsf_mode = xgbe_config_rsf_mode,
48540+ .config_tsf_mode = xgbe_config_tsf_mode,
48541
48542 /* For TX DMA Operating on Second Frame config */
48543- hw_if->config_osp_mode = xgbe_config_osp_mode;
48544+ .config_osp_mode = xgbe_config_osp_mode,
48545
48546 /* For RX and TX PBL config */
48547- hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
48548- hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
48549- hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
48550- hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
48551- hw_if->config_pblx8 = xgbe_config_pblx8;
48552+ .config_rx_pbl_val = xgbe_config_rx_pbl_val,
48553+ .get_rx_pbl_val = xgbe_get_rx_pbl_val,
48554+ .config_tx_pbl_val = xgbe_config_tx_pbl_val,
48555+ .get_tx_pbl_val = xgbe_get_tx_pbl_val,
48556+ .config_pblx8 = xgbe_config_pblx8,
48557
48558 /* For MMC statistics support */
48559- hw_if->tx_mmc_int = xgbe_tx_mmc_int;
48560- hw_if->rx_mmc_int = xgbe_rx_mmc_int;
48561- hw_if->read_mmc_stats = xgbe_read_mmc_stats;
48562-
48563- DBGPR("<--xgbe_init_function_ptrs\n");
48564-}
48565+ .tx_mmc_int = xgbe_tx_mmc_int,
48566+ .rx_mmc_int = xgbe_rx_mmc_int,
48567+ .read_mmc_stats = xgbe_read_mmc_stats,
48568+};
48569diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48570index cfe3d93..07a78ae 100644
48571--- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48572+++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48573@@ -153,7 +153,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
48574
48575 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48576 {
48577- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48578+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48579 struct xgbe_channel *channel;
48580 unsigned int i;
48581
48582@@ -170,7 +170,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48583
48584 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48585 {
48586- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48587+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48588 struct xgbe_channel *channel;
48589 unsigned int i;
48590
48591@@ -188,7 +188,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48592 static irqreturn_t xgbe_isr(int irq, void *data)
48593 {
48594 struct xgbe_prv_data *pdata = data;
48595- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48596+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48597 struct xgbe_channel *channel;
48598 unsigned int dma_isr, dma_ch_isr;
48599 unsigned int mac_isr;
48600@@ -403,7 +403,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata)
48601
48602 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48603 {
48604- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48605+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48606
48607 DBGPR("-->xgbe_init_tx_coalesce\n");
48608
48609@@ -417,7 +417,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48610
48611 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48612 {
48613- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48614+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48615
48616 DBGPR("-->xgbe_init_rx_coalesce\n");
48617
48618@@ -431,7 +431,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48619
48620 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48621 {
48622- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48623+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48624 struct xgbe_channel *channel;
48625 struct xgbe_ring *ring;
48626 struct xgbe_ring_data *rdata;
48627@@ -456,7 +456,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48628
48629 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48630 {
48631- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48632+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48633 struct xgbe_channel *channel;
48634 struct xgbe_ring *ring;
48635 struct xgbe_ring_data *rdata;
48636@@ -482,7 +482,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48637 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48638 {
48639 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48640- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48641+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48642 unsigned long flags;
48643
48644 DBGPR("-->xgbe_powerdown\n");
48645@@ -520,7 +520,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48646 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48647 {
48648 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48649- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48650+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48651 unsigned long flags;
48652
48653 DBGPR("-->xgbe_powerup\n");
48654@@ -557,7 +557,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48655
48656 static int xgbe_start(struct xgbe_prv_data *pdata)
48657 {
48658- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48659+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48660 struct net_device *netdev = pdata->netdev;
48661
48662 DBGPR("-->xgbe_start\n");
48663@@ -583,7 +583,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
48664
48665 static void xgbe_stop(struct xgbe_prv_data *pdata)
48666 {
48667- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48668+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48669 struct net_device *netdev = pdata->netdev;
48670
48671 DBGPR("-->xgbe_stop\n");
48672@@ -603,7 +603,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
48673
48674 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
48675 {
48676- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48677+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48678
48679 DBGPR("-->xgbe_restart_dev\n");
48680
48681@@ -741,8 +741,8 @@ static void xgbe_packet_info(struct xgbe_ring *ring, struct sk_buff *skb,
48682 static int xgbe_open(struct net_device *netdev)
48683 {
48684 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48685- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48686- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48687+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48688+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48689 int ret;
48690
48691 DBGPR("-->xgbe_open\n");
48692@@ -804,8 +804,8 @@ err_clk:
48693 static int xgbe_close(struct net_device *netdev)
48694 {
48695 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48696- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48697- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48698+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48699+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48700
48701 DBGPR("-->xgbe_close\n");
48702
48703@@ -835,8 +835,8 @@ static int xgbe_close(struct net_device *netdev)
48704 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
48705 {
48706 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48707- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48708- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48709+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48710+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48711 struct xgbe_channel *channel;
48712 struct xgbe_ring *ring;
48713 struct xgbe_packet_data *packet;
48714@@ -903,7 +903,7 @@ tx_netdev_return:
48715 static void xgbe_set_rx_mode(struct net_device *netdev)
48716 {
48717 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48718- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48719+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48720 unsigned int pr_mode, am_mode;
48721
48722 DBGPR("-->xgbe_set_rx_mode\n");
48723@@ -930,7 +930,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
48724 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
48725 {
48726 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48727- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48728+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48729 struct sockaddr *saddr = addr;
48730
48731 DBGPR("-->xgbe_set_mac_address\n");
48732@@ -976,7 +976,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
48733
48734 DBGPR("-->%s\n", __func__);
48735
48736- pdata->hw_if.read_mmc_stats(pdata);
48737+ pdata->hw_if->read_mmc_stats(pdata);
48738
48739 s->rx_packets = pstats->rxframecount_gb;
48740 s->rx_bytes = pstats->rxoctetcount_gb;
48741@@ -1020,7 +1020,7 @@ static int xgbe_set_features(struct net_device *netdev,
48742 netdev_features_t features)
48743 {
48744 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48745- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48746+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48747 unsigned int rxcsum_enabled, rxvlan_enabled;
48748
48749 rxcsum_enabled = !!(pdata->netdev_features & NETIF_F_RXCSUM);
48750@@ -1072,8 +1072,8 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
48751 static int xgbe_tx_poll(struct xgbe_channel *channel)
48752 {
48753 struct xgbe_prv_data *pdata = channel->pdata;
48754- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48755- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48756+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48757+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48758 struct xgbe_ring *ring = channel->tx_ring;
48759 struct xgbe_ring_data *rdata;
48760 struct xgbe_ring_desc *rdesc;
48761@@ -1124,8 +1124,8 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
48762 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
48763 {
48764 struct xgbe_prv_data *pdata = channel->pdata;
48765- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48766- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48767+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48768+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48769 struct xgbe_ring *ring = channel->rx_ring;
48770 struct xgbe_ring_data *rdata;
48771 struct xgbe_packet_data *packet;
48772diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48773index 8909f2b..719e767 100644
48774--- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48775+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48776@@ -202,7 +202,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
48777
48778 DBGPR("-->%s\n", __func__);
48779
48780- pdata->hw_if.read_mmc_stats(pdata);
48781+ pdata->hw_if->read_mmc_stats(pdata);
48782 for (i = 0; i < XGBE_STATS_COUNT; i++) {
48783 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
48784 *data++ = *(u64 *)stat;
48785@@ -387,7 +387,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
48786 struct ethtool_coalesce *ec)
48787 {
48788 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48789- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48790+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48791 unsigned int riwt;
48792
48793 DBGPR("-->xgbe_get_coalesce\n");
48794@@ -410,7 +410,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
48795 struct ethtool_coalesce *ec)
48796 {
48797 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48798- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48799+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48800 unsigned int rx_frames, rx_riwt, rx_usecs;
48801 unsigned int tx_frames, tx_usecs;
48802
48803diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48804index 5a1891f..1b7888e 100644
48805--- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48806+++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48807@@ -210,12 +210,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
48808 DBGPR("<--xgbe_default_config\n");
48809 }
48810
48811-static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
48812-{
48813- xgbe_init_function_ptrs_dev(&pdata->hw_if);
48814- xgbe_init_function_ptrs_desc(&pdata->desc_if);
48815-}
48816-
48817 static int xgbe_probe(struct platform_device *pdev)
48818 {
48819 struct xgbe_prv_data *pdata;
48820@@ -306,9 +300,8 @@ static int xgbe_probe(struct platform_device *pdev)
48821 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
48822
48823 /* Set all the function pointers */
48824- xgbe_init_all_fptrs(pdata);
48825- hw_if = &pdata->hw_if;
48826- desc_if = &pdata->desc_if;
48827+ hw_if = pdata->hw_if = &default_xgbe_hw_if;
48828+ desc_if = pdata->desc_if = &default_xgbe_desc_if;
48829
48830 /* Issue software reset to device */
48831 hw_if->exit(pdata);
48832diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48833index ea7a5d6..d10a742 100644
48834--- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48835+++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48836@@ -128,7 +128,7 @@
48837 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
48838 {
48839 struct xgbe_prv_data *pdata = mii->priv;
48840- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48841+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48842 int mmd_data;
48843
48844 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
48845@@ -145,7 +145,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
48846 u16 mmd_val)
48847 {
48848 struct xgbe_prv_data *pdata = mii->priv;
48849- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48850+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48851 int mmd_data = mmd_val;
48852
48853 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
48854@@ -161,7 +161,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
48855 static void xgbe_adjust_link(struct net_device *netdev)
48856 {
48857 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48858- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48859+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48860 struct phy_device *phydev = pdata->phydev;
48861 unsigned long flags;
48862 int new_state = 0;
48863diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
48864index ab06271..a560fa7 100644
48865--- a/drivers/net/ethernet/amd/xgbe/xgbe.h
48866+++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
48867@@ -527,8 +527,8 @@ struct xgbe_prv_data {
48868
48869 int irq_number;
48870
48871- struct xgbe_hw_if hw_if;
48872- struct xgbe_desc_if desc_if;
48873+ const struct xgbe_hw_if *hw_if;
48874+ const struct xgbe_desc_if *desc_if;
48875
48876 /* Rings for Tx/Rx on a DMA channel */
48877 struct xgbe_channel *channel;
48878@@ -611,6 +611,9 @@ struct xgbe_prv_data {
48879 #endif
48880 };
48881
48882+extern const struct xgbe_hw_if default_xgbe_hw_if;
48883+extern const struct xgbe_desc_if default_xgbe_desc_if;
48884+
48885 /* Function prototypes*/
48886
48887 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
48888diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48889index 571427c..e9fe9e7 100644
48890--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48891+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48892@@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
48893 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
48894 {
48895 /* RX_MODE controlling object */
48896- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
48897+ bnx2x_init_rx_mode_obj(bp);
48898
48899 /* multicast configuration controlling object */
48900 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
48901diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48902index b193604..8873bfd 100644
48903--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48904+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48905@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
48906 return rc;
48907 }
48908
48909-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48910- struct bnx2x_rx_mode_obj *o)
48911+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48912 {
48913 if (CHIP_IS_E1x(bp)) {
48914- o->wait_comp = bnx2x_empty_rx_mode_wait;
48915- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48916+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48917+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48918 } else {
48919- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48920- o->config_rx_mode = bnx2x_set_rx_mode_e2;
48921+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48922+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48923 }
48924 }
48925
48926diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48927index 718ecd2..2183b2f 100644
48928--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48929+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48930@@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48931
48932 /********************* RX MODE ****************/
48933
48934-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48935- struct bnx2x_rx_mode_obj *o);
48936+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48937
48938 /**
48939 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48940diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48941index 461acca..2b546ba 100644
48942--- a/drivers/net/ethernet/broadcom/tg3.h
48943+++ b/drivers/net/ethernet/broadcom/tg3.h
48944@@ -150,6 +150,7 @@
48945 #define CHIPREV_ID_5750_A0 0x4000
48946 #define CHIPREV_ID_5750_A1 0x4001
48947 #define CHIPREV_ID_5750_A3 0x4003
48948+#define CHIPREV_ID_5750_C1 0x4201
48949 #define CHIPREV_ID_5750_C2 0x4202
48950 #define CHIPREV_ID_5752_A0_HW 0x5000
48951 #define CHIPREV_ID_5752_A0 0x6000
48952diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48953index 13f9636..228040f 100644
48954--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48955+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48956@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
48957 }
48958
48959 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48960- bna_cb_ioceth_enable,
48961- bna_cb_ioceth_disable,
48962- bna_cb_ioceth_hbfail,
48963- bna_cb_ioceth_reset
48964+ .enable_cbfn = bna_cb_ioceth_enable,
48965+ .disable_cbfn = bna_cb_ioceth_disable,
48966+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
48967+ .reset_cbfn = bna_cb_ioceth_reset
48968 };
48969
48970 static void bna_attr_init(struct bna_ioceth *ioceth)
48971diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48972index 8cffcdf..aadf043 100644
48973--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48974+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48975@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48976 */
48977 struct l2t_skb_cb {
48978 arp_failure_handler_func arp_failure_handler;
48979-};
48980+} __no_const;
48981
48982 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48983
48984diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48985index a83271c..cf00874 100644
48986--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48987+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48988@@ -2174,7 +2174,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48989
48990 int i;
48991 struct adapter *ap = netdev2adap(dev);
48992- static const unsigned int *reg_ranges;
48993+ const unsigned int *reg_ranges;
48994 int arr_size = 0, buf_size = 0;
48995
48996 if (is_t4(ap->params.chip)) {
48997diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48998index c05b66d..ed69872 100644
48999--- a/drivers/net/ethernet/dec/tulip/de4x5.c
49000+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
49001@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
49002 for (i=0; i<ETH_ALEN; i++) {
49003 tmp.addr[i] = dev->dev_addr[i];
49004 }
49005- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
49006+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
49007 break;
49008
49009 case DE4X5_SET_HWADDR: /* Set the hardware address */
49010@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
49011 spin_lock_irqsave(&lp->lock, flags);
49012 memcpy(&statbuf, &lp->pktStats, ioc->len);
49013 spin_unlock_irqrestore(&lp->lock, flags);
49014- if (copy_to_user(ioc->data, &statbuf, ioc->len))
49015+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
49016 return -EFAULT;
49017 break;
49018 }
49019diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
49020index 1e187fb..d024547 100644
49021--- a/drivers/net/ethernet/emulex/benet/be_main.c
49022+++ b/drivers/net/ethernet/emulex/benet/be_main.c
49023@@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
49024
49025 if (wrapped)
49026 newacc += 65536;
49027- ACCESS_ONCE(*acc) = newacc;
49028+ ACCESS_ONCE_RW(*acc) = newacc;
49029 }
49030
49031 static void populate_erx_stats(struct be_adapter *adapter,
49032diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
49033index c77fa4a..7fd42fc 100644
49034--- a/drivers/net/ethernet/faraday/ftgmac100.c
49035+++ b/drivers/net/ethernet/faraday/ftgmac100.c
49036@@ -30,6 +30,8 @@
49037 #include <linux/netdevice.h>
49038 #include <linux/phy.h>
49039 #include <linux/platform_device.h>
49040+#include <linux/interrupt.h>
49041+#include <linux/irqreturn.h>
49042 #include <net/ip.h>
49043
49044 #include "ftgmac100.h"
49045diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
49046index 4ff1adc..0ea6bf4 100644
49047--- a/drivers/net/ethernet/faraday/ftmac100.c
49048+++ b/drivers/net/ethernet/faraday/ftmac100.c
49049@@ -31,6 +31,8 @@
49050 #include <linux/module.h>
49051 #include <linux/netdevice.h>
49052 #include <linux/platform_device.h>
49053+#include <linux/interrupt.h>
49054+#include <linux/irqreturn.h>
49055
49056 #include "ftmac100.h"
49057
49058diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
49059index 101f439..59e7ec6 100644
49060--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
49061+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
49062@@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
49063 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
49064
49065 /* Update the base adjustement value. */
49066- ACCESS_ONCE(pf->ptp_base_adj) = incval;
49067+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
49068 smp_mb(); /* Force the above update. */
49069 }
49070
49071diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
49072index 68f87ec..241dbe3 100644
49073--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
49074+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
49075@@ -792,7 +792,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
49076 }
49077
49078 /* update the base incval used to calculate frequency adjustment */
49079- ACCESS_ONCE(adapter->base_incval) = incval;
49080+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
49081 smp_mb();
49082
49083 /* need lock to prevent incorrect read while modifying cyclecounter */
49084diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
49085index 2bbd01f..e8baa64 100644
49086--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
49087+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
49088@@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
49089 struct __vxge_hw_fifo *fifo;
49090 struct vxge_hw_fifo_config *config;
49091 u32 txdl_size, txdl_per_memblock;
49092- struct vxge_hw_mempool_cbs fifo_mp_callback;
49093+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
49094+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
49095+ };
49096+
49097 struct __vxge_hw_virtualpath *vpath;
49098
49099 if ((vp == NULL) || (attr == NULL)) {
49100@@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
49101 goto exit;
49102 }
49103
49104- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
49105-
49106 fifo->mempool =
49107 __vxge_hw_mempool_create(vpath->hldev,
49108 fifo->config->memblock_size,
49109diff --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
49110index 73e6683..464e910 100644
49111--- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
49112+++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
49113@@ -120,6 +120,10 @@ static void pch_gbe_mdio_write(struct net_device *netdev, int addr, int reg,
49114 int data);
49115 static void pch_gbe_set_multi(struct net_device *netdev);
49116
49117+static struct sock_filter ptp_filter[] = {
49118+ PTP_FILTER
49119+};
49120+
49121 static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49122 {
49123 u8 *data = skb->data;
49124@@ -127,7 +131,7 @@ static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49125 u16 *hi, *id;
49126 u32 lo;
49127
49128- if (ptp_classify_raw(skb) == PTP_CLASS_NONE)
49129+ if (sk_run_filter(skb, ptp_filter) == PTP_CLASS_NONE)
49130 return 0;
49131
49132 offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN;
49133@@ -2631,6 +2635,11 @@ static int pch_gbe_probe(struct pci_dev *pdev,
49134
49135 adapter->ptp_pdev = pci_get_bus_and_slot(adapter->pdev->bus->number,
49136 PCI_DEVFN(12, 4));
49137+ if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
49138+ dev_err(&pdev->dev, "Bad ptp filter\n");
49139+ ret = -EINVAL;
49140+ goto err_free_netdev;
49141+ }
49142
49143 netdev->netdev_ops = &pch_gbe_netdev_ops;
49144 netdev->watchdog_timeo = PCH_GBE_WATCHDOG_PERIOD;
49145diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49146index f33559b..c7f50ac 100644
49147--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49148+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49149@@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
49150 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
49151 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
49152 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
49153- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
49154+ pax_open_kernel();
49155+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
49156+ pax_close_kernel();
49157 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49158 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
49159 max_tx_rings = QLCNIC_MAX_TX_RINGS;
49160diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49161index be7d7a6..a8983f8 100644
49162--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49163+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49164@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
49165 case QLCNIC_NON_PRIV_FUNC:
49166 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
49167 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49168- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
49169+ pax_open_kernel();
49170+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
49171+ pax_close_kernel();
49172 break;
49173 case QLCNIC_PRIV_FUNC:
49174 ahw->op_mode = QLCNIC_PRIV_FUNC;
49175 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
49176- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
49177+ pax_open_kernel();
49178+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
49179+ pax_close_kernel();
49180 break;
49181 case QLCNIC_MGMT_FUNC:
49182 ahw->op_mode = QLCNIC_MGMT_FUNC;
49183 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49184- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
49185+ pax_open_kernel();
49186+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
49187+ pax_close_kernel();
49188 break;
49189 default:
49190 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
49191diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49192index e46fc39..abe135b 100644
49193--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49194+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49195@@ -1228,7 +1228,7 @@ flash_temp:
49196 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
49197 {
49198 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
49199- static const struct qlcnic_dump_operations *fw_dump_ops;
49200+ const struct qlcnic_dump_operations *fw_dump_ops;
49201 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
49202 u32 entry_offset, dump, no_entries, buf_offset = 0;
49203 int i, k, ops_cnt, ops_index, dump_size = 0;
49204diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
49205index 61623e9..ac97c27 100644
49206--- a/drivers/net/ethernet/realtek/r8169.c
49207+++ b/drivers/net/ethernet/realtek/r8169.c
49208@@ -759,22 +759,22 @@ struct rtl8169_private {
49209 struct mdio_ops {
49210 void (*write)(struct rtl8169_private *, int, int);
49211 int (*read)(struct rtl8169_private *, int);
49212- } mdio_ops;
49213+ } __no_const mdio_ops;
49214
49215 struct pll_power_ops {
49216 void (*down)(struct rtl8169_private *);
49217 void (*up)(struct rtl8169_private *);
49218- } pll_power_ops;
49219+ } __no_const pll_power_ops;
49220
49221 struct jumbo_ops {
49222 void (*enable)(struct rtl8169_private *);
49223 void (*disable)(struct rtl8169_private *);
49224- } jumbo_ops;
49225+ } __no_const jumbo_ops;
49226
49227 struct csi_ops {
49228 void (*write)(struct rtl8169_private *, int, int);
49229 u32 (*read)(struct rtl8169_private *, int);
49230- } csi_ops;
49231+ } __no_const csi_ops;
49232
49233 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
49234 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
49235diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
49236index 6b861e3..204ac86 100644
49237--- a/drivers/net/ethernet/sfc/ptp.c
49238+++ b/drivers/net/ethernet/sfc/ptp.c
49239@@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
49240 ptp->start.dma_addr);
49241
49242 /* Clear flag that signals MC ready */
49243- ACCESS_ONCE(*start) = 0;
49244+ ACCESS_ONCE_RW(*start) = 0;
49245 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
49246 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
49247 EFX_BUG_ON_PARANOID(rc);
49248diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49249index 50617c5..b13724c 100644
49250--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49251+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49252@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
49253
49254 writel(value, ioaddr + MMC_CNTRL);
49255
49256- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
49257- MMC_CNTRL, value);
49258+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
49259+// MMC_CNTRL, value);
49260 }
49261
49262 /* To mask all all interrupts.*/
49263diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
49264index 6b56f85..50e285f 100644
49265--- a/drivers/net/ethernet/ti/cpts.c
49266+++ b/drivers/net/ethernet/ti/cpts.c
49267@@ -33,6 +33,10 @@
49268
49269 #ifdef CONFIG_TI_CPTS
49270
49271+static struct sock_filter ptp_filter[] = {
49272+ PTP_FILTER
49273+};
49274+
49275 #define cpts_read32(c, r) __raw_readl(&c->reg->r)
49276 #define cpts_write32(c, v, r) __raw_writel(v, &c->reg->r)
49277
49278@@ -296,7 +300,7 @@ static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, int ev_type)
49279 u64 ns = 0;
49280 struct cpts_event *event;
49281 struct list_head *this, *next;
49282- unsigned int class = ptp_classify_raw(skb);
49283+ unsigned int class = sk_run_filter(skb, ptp_filter);
49284 unsigned long flags;
49285 u16 seqid;
49286 u8 mtype;
49287@@ -367,6 +371,10 @@ int cpts_register(struct device *dev, struct cpts *cpts,
49288 int err, i;
49289 unsigned long flags;
49290
49291+ if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
49292+ pr_err("cpts: bad ptp filter\n");
49293+ return -EINVAL;
49294+ }
49295 cpts->info = cpts_info;
49296 cpts->clock = ptp_clock_register(&cpts->info, dev);
49297 if (IS_ERR(cpts->clock)) {
49298diff --git a/drivers/net/ethernet/xscale/Kconfig b/drivers/net/ethernet/xscale/Kconfig
49299index b81bc9f..3f43101 100644
49300--- a/drivers/net/ethernet/xscale/Kconfig
49301+++ b/drivers/net/ethernet/xscale/Kconfig
49302@@ -23,7 +23,6 @@ config IXP4XX_ETH
49303 tristate "Intel IXP4xx Ethernet support"
49304 depends on ARM && ARCH_IXP4XX && IXP4XX_NPE && IXP4XX_QMGR
49305 select PHYLIB
49306- select NET_PTP_CLASSIFY
49307 ---help---
49308 Say Y here if you want to use built-in Ethernet ports
49309 on IXP4xx processor.
49310diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
49311index f7e0f0f..25283f1 100644
49312--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
49313+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
49314@@ -256,6 +256,10 @@ static int ports_open;
49315 static struct port *npe_port_tab[MAX_NPES];
49316 static struct dma_pool *dma_pool;
49317
49318+static struct sock_filter ptp_filter[] = {
49319+ PTP_FILTER
49320+};
49321+
49322 static int ixp_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49323 {
49324 u8 *data = skb->data;
49325@@ -263,7 +267,7 @@ static int ixp_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49326 u16 *hi, *id;
49327 u32 lo;
49328
49329- if (ptp_classify_raw(skb) != PTP_CLASS_V1_IPV4)
49330+ if (sk_run_filter(skb, ptp_filter) != PTP_CLASS_V1_IPV4)
49331 return 0;
49332
49333 offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN;
49334@@ -1409,6 +1413,11 @@ static int eth_init_one(struct platform_device *pdev)
49335 char phy_id[MII_BUS_ID_SIZE + 3];
49336 int err;
49337
49338+ if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
49339+ pr_err("ixp4xx_eth: bad ptp filter\n");
49340+ return -EINVAL;
49341+ }
49342+
49343 if (!(dev = alloc_etherdev(sizeof(struct port))))
49344 return -ENOMEM;
49345
49346diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
49347index 6cc37c1..fdd9d77 100644
49348--- a/drivers/net/hyperv/hyperv_net.h
49349+++ b/drivers/net/hyperv/hyperv_net.h
49350@@ -170,7 +170,7 @@ struct rndis_device {
49351
49352 enum rndis_device_state state;
49353 bool link_state;
49354- atomic_t new_req_id;
49355+ atomic_unchecked_t new_req_id;
49356
49357 spinlock_t request_lock;
49358 struct list_head req_list;
49359diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
49360index 99c527a..6a2ce38 100644
49361--- a/drivers/net/hyperv/rndis_filter.c
49362+++ b/drivers/net/hyperv/rndis_filter.c
49363@@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
49364 * template
49365 */
49366 set = &rndis_msg->msg.set_req;
49367- set->req_id = atomic_inc_return(&dev->new_req_id);
49368+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
49369
49370 /* Add to the request list */
49371 spin_lock_irqsave(&dev->request_lock, flags);
49372@@ -930,7 +930,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
49373
49374 /* Setup the rndis set */
49375 halt = &request->request_msg.msg.halt_req;
49376- halt->req_id = atomic_inc_return(&dev->new_req_id);
49377+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
49378
49379 /* Ignore return since this msg is optional. */
49380 rndis_filter_send_request(dev, request);
49381diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
49382index 78f18be..1d19c62 100644
49383--- a/drivers/net/ieee802154/fakehard.c
49384+++ b/drivers/net/ieee802154/fakehard.c
49385@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
49386 phy->transmit_power = 0xbf;
49387
49388 dev->netdev_ops = &fake_ops;
49389- dev->ml_priv = &fake_mlme;
49390+ dev->ml_priv = (void *)&fake_mlme;
49391
49392 priv = netdev_priv(dev);
49393 priv->phy = phy;
49394diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
49395index ef8a5c2..76877d6 100644
49396--- a/drivers/net/macvlan.c
49397+++ b/drivers/net/macvlan.c
49398@@ -264,7 +264,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
49399 free_nskb:
49400 kfree_skb(nskb);
49401 err:
49402- atomic_long_inc(&skb->dev->rx_dropped);
49403+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
49404 }
49405
49406 /* called under rcu_read_lock() from netif_receive_skb */
49407@@ -1134,13 +1134,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
49408 int macvlan_link_register(struct rtnl_link_ops *ops)
49409 {
49410 /* common fields */
49411- ops->priv_size = sizeof(struct macvlan_dev);
49412- ops->validate = macvlan_validate;
49413- ops->maxtype = IFLA_MACVLAN_MAX;
49414- ops->policy = macvlan_policy;
49415- ops->changelink = macvlan_changelink;
49416- ops->get_size = macvlan_get_size;
49417- ops->fill_info = macvlan_fill_info;
49418+ pax_open_kernel();
49419+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
49420+ *(void **)&ops->validate = macvlan_validate;
49421+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
49422+ *(const void **)&ops->policy = macvlan_policy;
49423+ *(void **)&ops->changelink = macvlan_changelink;
49424+ *(void **)&ops->get_size = macvlan_get_size;
49425+ *(void **)&ops->fill_info = macvlan_fill_info;
49426+ pax_close_kernel();
49427
49428 return rtnl_link_register(ops);
49429 };
49430@@ -1220,7 +1222,7 @@ static int macvlan_device_event(struct notifier_block *unused,
49431 return NOTIFY_DONE;
49432 }
49433
49434-static struct notifier_block macvlan_notifier_block __read_mostly = {
49435+static struct notifier_block macvlan_notifier_block = {
49436 .notifier_call = macvlan_device_event,
49437 };
49438
49439diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
49440index 3381c4f..dea5fd5 100644
49441--- a/drivers/net/macvtap.c
49442+++ b/drivers/net/macvtap.c
49443@@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
49444 }
49445
49446 ret = 0;
49447- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49448+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49449 put_user(q->flags, &ifr->ifr_flags))
49450 ret = -EFAULT;
49451 macvtap_put_vlan(vlan);
49452@@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
49453 return NOTIFY_DONE;
49454 }
49455
49456-static struct notifier_block macvtap_notifier_block __read_mostly = {
49457+static struct notifier_block macvtap_notifier_block = {
49458 .notifier_call = macvtap_device_event,
49459 };
49460
49461diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
49462index 9408157..d53b924 100644
49463--- a/drivers/net/phy/dp83640.c
49464+++ b/drivers/net/phy/dp83640.c
49465@@ -27,7 +27,6 @@
49466 #include <linux/module.h>
49467 #include <linux/net_tstamp.h>
49468 #include <linux/netdevice.h>
49469-#include <linux/if_vlan.h>
49470 #include <linux/phy.h>
49471 #include <linux/ptp_classify.h>
49472 #include <linux/ptp_clock_kernel.h>
49473diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
49474index d5b77ef..72ff14b 100644
49475--- a/drivers/net/ppp/ppp_generic.c
49476+++ b/drivers/net/ppp/ppp_generic.c
49477@@ -143,8 +143,9 @@ struct ppp {
49478 struct sk_buff_head mrq; /* MP: receive reconstruction queue */
49479 #endif /* CONFIG_PPP_MULTILINK */
49480 #ifdef CONFIG_PPP_FILTER
49481- struct sk_filter *pass_filter; /* filter for packets to pass */
49482- struct sk_filter *active_filter;/* filter for pkts to reset idle */
49483+ struct sock_filter *pass_filter; /* filter for packets to pass */
49484+ struct sock_filter *active_filter;/* filter for pkts to reset idle */
49485+ unsigned pass_len, active_len;
49486 #endif /* CONFIG_PPP_FILTER */
49487 struct net *ppp_net; /* the net we belong to */
49488 struct ppp_link_stats stats64; /* 64 bit network stats */
49489@@ -539,7 +540,7 @@ static int get_filter(void __user *arg, struct sock_filter **p)
49490 {
49491 struct sock_fprog uprog;
49492 struct sock_filter *code = NULL;
49493- int len;
49494+ int len, err;
49495
49496 if (copy_from_user(&uprog, arg, sizeof(uprog)))
49497 return -EFAULT;
49498@@ -554,6 +555,12 @@ static int get_filter(void __user *arg, struct sock_filter **p)
49499 if (IS_ERR(code))
49500 return PTR_ERR(code);
49501
49502+ err = sk_chk_filter(code, uprog.len);
49503+ if (err) {
49504+ kfree(code);
49505+ return err;
49506+ }
49507+
49508 *p = code;
49509 return uprog.len;
49510 }
49511@@ -748,52 +755,28 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
49512 case PPPIOCSPASS:
49513 {
49514 struct sock_filter *code;
49515-
49516 err = get_filter(argp, &code);
49517 if (err >= 0) {
49518- struct sock_fprog_kern fprog = {
49519- .len = err,
49520- .filter = code,
49521- };
49522-
49523 ppp_lock(ppp);
49524- if (ppp->pass_filter) {
49525- sk_unattached_filter_destroy(ppp->pass_filter);
49526- ppp->pass_filter = NULL;
49527- }
49528- if (fprog.filter != NULL)
49529- err = sk_unattached_filter_create(&ppp->pass_filter,
49530- &fprog);
49531- else
49532- err = 0;
49533- kfree(code);
49534+ kfree(ppp->pass_filter);
49535+ ppp->pass_filter = code;
49536+ ppp->pass_len = err;
49537 ppp_unlock(ppp);
49538+ err = 0;
49539 }
49540 break;
49541 }
49542 case PPPIOCSACTIVE:
49543 {
49544 struct sock_filter *code;
49545-
49546 err = get_filter(argp, &code);
49547 if (err >= 0) {
49548- struct sock_fprog_kern fprog = {
49549- .len = err,
49550- .filter = code,
49551- };
49552-
49553 ppp_lock(ppp);
49554- if (ppp->active_filter) {
49555- sk_unattached_filter_destroy(ppp->active_filter);
49556- ppp->active_filter = NULL;
49557- }
49558- if (fprog.filter != NULL)
49559- err = sk_unattached_filter_create(&ppp->active_filter,
49560- &fprog);
49561- else
49562- err = 0;
49563- kfree(code);
49564+ kfree(ppp->active_filter);
49565+ ppp->active_filter = code;
49566+ ppp->active_len = err;
49567 ppp_unlock(ppp);
49568+ err = 0;
49569 }
49570 break;
49571 }
49572@@ -1201,7 +1184,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
49573 a four-byte PPP header on each packet */
49574 *skb_push(skb, 2) = 1;
49575 if (ppp->pass_filter &&
49576- SK_RUN_FILTER(ppp->pass_filter, skb) == 0) {
49577+ sk_run_filter(skb, ppp->pass_filter) == 0) {
49578 if (ppp->debug & 1)
49579 netdev_printk(KERN_DEBUG, ppp->dev,
49580 "PPP: outbound frame "
49581@@ -1211,7 +1194,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
49582 }
49583 /* if this packet passes the active filter, record the time */
49584 if (!(ppp->active_filter &&
49585- SK_RUN_FILTER(ppp->active_filter, skb) == 0))
49586+ sk_run_filter(skb, ppp->active_filter) == 0))
49587 ppp->last_xmit = jiffies;
49588 skb_pull(skb, 2);
49589 #else
49590@@ -1835,7 +1818,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
49591
49592 *skb_push(skb, 2) = 0;
49593 if (ppp->pass_filter &&
49594- SK_RUN_FILTER(ppp->pass_filter, skb) == 0) {
49595+ sk_run_filter(skb, ppp->pass_filter) == 0) {
49596 if (ppp->debug & 1)
49597 netdev_printk(KERN_DEBUG, ppp->dev,
49598 "PPP: inbound frame "
49599@@ -1844,7 +1827,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
49600 return;
49601 }
49602 if (!(ppp->active_filter &&
49603- SK_RUN_FILTER(ppp->active_filter, skb) == 0))
49604+ sk_run_filter(skb, ppp->active_filter) == 0))
49605 ppp->last_recv = jiffies;
49606 __skb_pull(skb, 2);
49607 } else
49608@@ -2689,10 +2672,6 @@ ppp_create_interface(struct net *net, int unit, int *retp)
49609 ppp->minseq = -1;
49610 skb_queue_head_init(&ppp->mrq);
49611 #endif /* CONFIG_PPP_MULTILINK */
49612-#ifdef CONFIG_PPP_FILTER
49613- ppp->pass_filter = NULL;
49614- ppp->active_filter = NULL;
49615-#endif /* CONFIG_PPP_FILTER */
49616
49617 /*
49618 * drum roll: don't forget to set
49619@@ -2823,15 +2802,10 @@ static void ppp_destroy_interface(struct ppp *ppp)
49620 skb_queue_purge(&ppp->mrq);
49621 #endif /* CONFIG_PPP_MULTILINK */
49622 #ifdef CONFIG_PPP_FILTER
49623- if (ppp->pass_filter) {
49624- sk_unattached_filter_destroy(ppp->pass_filter);
49625- ppp->pass_filter = NULL;
49626- }
49627-
49628- if (ppp->active_filter) {
49629- sk_unattached_filter_destroy(ppp->active_filter);
49630- ppp->active_filter = NULL;
49631- }
49632+ kfree(ppp->pass_filter);
49633+ ppp->pass_filter = NULL;
49634+ kfree(ppp->active_filter);
49635+ ppp->active_filter = NULL;
49636 #endif /* CONFIG_PPP_FILTER */
49637
49638 kfree_skb(ppp->xmit_pending);
49639diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
49640index 1252d9c..80e660b 100644
49641--- a/drivers/net/slip/slhc.c
49642+++ b/drivers/net/slip/slhc.c
49643@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
49644 register struct tcphdr *thp;
49645 register struct iphdr *ip;
49646 register struct cstate *cs;
49647- int len, hdrlen;
49648+ long len, hdrlen;
49649 unsigned char *cp = icp;
49650
49651 /* We've got a compressed packet; read the change byte */
49652diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
49653index b4958c7..277cb96 100644
49654--- a/drivers/net/team/team.c
49655+++ b/drivers/net/team/team.c
49656@@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
49657 return NOTIFY_DONE;
49658 }
49659
49660-static struct notifier_block team_notifier_block __read_mostly = {
49661+static struct notifier_block team_notifier_block = {
49662 .notifier_call = team_device_event,
49663 };
49664
49665diff --git a/drivers/net/team/team_mode_loadbalance.c b/drivers/net/team/team_mode_loadbalance.c
49666index a58dfeb..dbde341 100644
49667--- a/drivers/net/team/team_mode_loadbalance.c
49668+++ b/drivers/net/team/team_mode_loadbalance.c
49669@@ -49,7 +49,7 @@ struct lb_port_mapping {
49670 struct lb_priv_ex {
49671 struct team *team;
49672 struct lb_port_mapping tx_hash_to_port_mapping[LB_TX_HASHTABLE_SIZE];
49673- struct sock_fprog_kern *orig_fprog;
49674+ struct sock_fprog *orig_fprog;
49675 struct {
49676 unsigned int refresh_interval; /* in tenths of second */
49677 struct delayed_work refresh_dw;
49678@@ -241,15 +241,15 @@ static int lb_bpf_func_get(struct team *team, struct team_gsetter_ctx *ctx)
49679 return 0;
49680 }
49681
49682-static int __fprog_create(struct sock_fprog_kern **pfprog, u32 data_len,
49683+static int __fprog_create(struct sock_fprog **pfprog, u32 data_len,
49684 const void *data)
49685 {
49686- struct sock_fprog_kern *fprog;
49687+ struct sock_fprog *fprog;
49688 struct sock_filter *filter = (struct sock_filter *) data;
49689
49690 if (data_len % sizeof(struct sock_filter))
49691 return -EINVAL;
49692- fprog = kmalloc(sizeof(*fprog), GFP_KERNEL);
49693+ fprog = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
49694 if (!fprog)
49695 return -ENOMEM;
49696 fprog->filter = kmemdup(filter, data_len, GFP_KERNEL);
49697@@ -262,7 +262,7 @@ static int __fprog_create(struct sock_fprog_kern **pfprog, u32 data_len,
49698 return 0;
49699 }
49700
49701-static void __fprog_destroy(struct sock_fprog_kern *fprog)
49702+static void __fprog_destroy(struct sock_fprog *fprog)
49703 {
49704 kfree(fprog->filter);
49705 kfree(fprog);
49706@@ -273,7 +273,7 @@ static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx)
49707 struct lb_priv *lb_priv = get_lb_priv(team);
49708 struct sk_filter *fp = NULL;
49709 struct sk_filter *orig_fp;
49710- struct sock_fprog_kern *fprog = NULL;
49711+ struct sock_fprog *fprog = NULL;
49712 int err;
49713
49714 if (ctx->data.bin_val.len) {
49715diff --git a/drivers/net/tun.c b/drivers/net/tun.c
49716index 98bad1f..f197d7a 100644
49717--- a/drivers/net/tun.c
49718+++ b/drivers/net/tun.c
49719@@ -1854,7 +1854,7 @@ unlock:
49720 }
49721
49722 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49723- unsigned long arg, int ifreq_len)
49724+ unsigned long arg, size_t ifreq_len)
49725 {
49726 struct tun_file *tfile = file->private_data;
49727 struct tun_struct *tun;
49728@@ -1867,6 +1867,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49729 unsigned int ifindex;
49730 int ret;
49731
49732+ if (ifreq_len > sizeof ifr)
49733+ return -EFAULT;
49734+
49735 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
49736 if (copy_from_user(&ifr, argp, ifreq_len))
49737 return -EFAULT;
49738diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
49739index a4272ed..cdd69ff 100644
49740--- a/drivers/net/usb/hso.c
49741+++ b/drivers/net/usb/hso.c
49742@@ -71,7 +71,7 @@
49743 #include <asm/byteorder.h>
49744 #include <linux/serial_core.h>
49745 #include <linux/serial.h>
49746-
49747+#include <asm/local.h>
49748
49749 #define MOD_AUTHOR "Option Wireless"
49750 #define MOD_DESCRIPTION "USB High Speed Option driver"
49751@@ -1177,7 +1177,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
49752 struct urb *urb;
49753
49754 urb = serial->rx_urb[0];
49755- if (serial->port.count > 0) {
49756+ if (atomic_read(&serial->port.count) > 0) {
49757 count = put_rxbuf_data(urb, serial);
49758 if (count == -1)
49759 return;
49760@@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
49761 DUMP1(urb->transfer_buffer, urb->actual_length);
49762
49763 /* Anyone listening? */
49764- if (serial->port.count == 0)
49765+ if (atomic_read(&serial->port.count) == 0)
49766 return;
49767
49768 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
49769@@ -1277,8 +1277,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49770 tty_port_tty_set(&serial->port, tty);
49771
49772 /* check for port already opened, if not set the termios */
49773- serial->port.count++;
49774- if (serial->port.count == 1) {
49775+ if (atomic_inc_return(&serial->port.count) == 1) {
49776 serial->rx_state = RX_IDLE;
49777 /* Force default termio settings */
49778 _hso_serial_set_termios(tty, NULL);
49779@@ -1288,7 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49780 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
49781 if (result) {
49782 hso_stop_serial_device(serial->parent);
49783- serial->port.count--;
49784+ atomic_dec(&serial->port.count);
49785 kref_put(&serial->parent->ref, hso_serial_ref_free);
49786 }
49787 } else {
49788@@ -1325,10 +1324,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
49789
49790 /* reset the rts and dtr */
49791 /* do the actual close */
49792- serial->port.count--;
49793+ atomic_dec(&serial->port.count);
49794
49795- if (serial->port.count <= 0) {
49796- serial->port.count = 0;
49797+ if (atomic_read(&serial->port.count) <= 0) {
49798+ atomic_set(&serial->port.count, 0);
49799 tty_port_tty_set(&serial->port, NULL);
49800 if (!usb_gone)
49801 hso_stop_serial_device(serial->parent);
49802@@ -1403,7 +1402,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
49803
49804 /* the actual setup */
49805 spin_lock_irqsave(&serial->serial_lock, flags);
49806- if (serial->port.count)
49807+ if (atomic_read(&serial->port.count))
49808 _hso_serial_set_termios(tty, old);
49809 else
49810 tty->termios = *old;
49811@@ -1872,7 +1871,7 @@ static void intr_callback(struct urb *urb)
49812 D1("Pending read interrupt on port %d\n", i);
49813 spin_lock(&serial->serial_lock);
49814 if (serial->rx_state == RX_IDLE &&
49815- serial->port.count > 0) {
49816+ atomic_read(&serial->port.count) > 0) {
49817 /* Setup and send a ctrl req read on
49818 * port i */
49819 if (!serial->rx_urb_filled[0]) {
49820@@ -3045,7 +3044,7 @@ static int hso_resume(struct usb_interface *iface)
49821 /* Start all serial ports */
49822 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
49823 if (serial_table[i] && (serial_table[i]->interface == iface)) {
49824- if (dev2ser(serial_table[i])->port.count) {
49825+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
49826 result =
49827 hso_start_serial_device(serial_table[i], GFP_NOIO);
49828 hso_kick_transmit(dev2ser(serial_table[i]));
49829diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
49830index 3eab74c..fb6097c 100644
49831--- a/drivers/net/usb/r8152.c
49832+++ b/drivers/net/usb/r8152.c
49833@@ -567,7 +567,7 @@ struct r8152 {
49834 void (*up)(struct r8152 *);
49835 void (*down)(struct r8152 *);
49836 void (*unload)(struct r8152 *);
49837- } rtl_ops;
49838+ } __no_const rtl_ops;
49839
49840 int intr_interval;
49841 u32 saved_wolopts;
49842diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
49843index a2515887..6d13233 100644
49844--- a/drivers/net/usb/sierra_net.c
49845+++ b/drivers/net/usb/sierra_net.c
49846@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
49847 /* atomic counter partially included in MAC address to make sure 2 devices
49848 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
49849 */
49850-static atomic_t iface_counter = ATOMIC_INIT(0);
49851+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
49852
49853 /*
49854 * SYNC Timer Delay definition used to set the expiry time
49855@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
49856 dev->net->netdev_ops = &sierra_net_device_ops;
49857
49858 /* change MAC addr to include, ifacenum, and to be unique */
49859- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
49860+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
49861 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
49862
49863 /* we will have to manufacture ethernet headers, prepare template */
49864diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
49865index 7d9f84a..7f690da 100644
49866--- a/drivers/net/virtio_net.c
49867+++ b/drivers/net/virtio_net.c
49868@@ -47,7 +47,7 @@ module_param(gso, bool, 0444);
49869 #define RECEIVE_AVG_WEIGHT 64
49870
49871 /* Minimum alignment for mergeable packet buffers. */
49872-#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
49873+#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
49874
49875 #define VIRTNET_DRIVER_VERSION "1.0.0"
49876
49877diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
49878index 9f79192..838cf95 100644
49879--- a/drivers/net/vxlan.c
49880+++ b/drivers/net/vxlan.c
49881@@ -2838,7 +2838,7 @@ nla_put_failure:
49882 return -EMSGSIZE;
49883 }
49884
49885-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
49886+static struct rtnl_link_ops vxlan_link_ops = {
49887 .kind = "vxlan",
49888 .maxtype = IFLA_VXLAN_MAX,
49889 .policy = vxlan_policy,
49890@@ -2885,7 +2885,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
49891 return NOTIFY_DONE;
49892 }
49893
49894-static struct notifier_block vxlan_notifier_block __read_mostly = {
49895+static struct notifier_block vxlan_notifier_block = {
49896 .notifier_call = vxlan_lowerdev_event,
49897 };
49898
49899diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
49900index 5920c99..ff2e4a5 100644
49901--- a/drivers/net/wan/lmc/lmc_media.c
49902+++ b/drivers/net/wan/lmc/lmc_media.c
49903@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
49904 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
49905
49906 lmc_media_t lmc_ds3_media = {
49907- lmc_ds3_init, /* special media init stuff */
49908- lmc_ds3_default, /* reset to default state */
49909- lmc_ds3_set_status, /* reset status to state provided */
49910- lmc_dummy_set_1, /* set clock source */
49911- lmc_dummy_set2_1, /* set line speed */
49912- lmc_ds3_set_100ft, /* set cable length */
49913- lmc_ds3_set_scram, /* set scrambler */
49914- lmc_ds3_get_link_status, /* get link status */
49915- lmc_dummy_set_1, /* set link status */
49916- lmc_ds3_set_crc_length, /* set CRC length */
49917- lmc_dummy_set_1, /* set T1 or E1 circuit type */
49918- lmc_ds3_watchdog
49919+ .init = lmc_ds3_init, /* special media init stuff */
49920+ .defaults = lmc_ds3_default, /* reset to default state */
49921+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
49922+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
49923+ .set_speed = lmc_dummy_set2_1, /* set line speed */
49924+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
49925+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
49926+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
49927+ .set_link_status = lmc_dummy_set_1, /* set link status */
49928+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
49929+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49930+ .watchdog = lmc_ds3_watchdog
49931 };
49932
49933 lmc_media_t lmc_hssi_media = {
49934- lmc_hssi_init, /* special media init stuff */
49935- lmc_hssi_default, /* reset to default state */
49936- lmc_hssi_set_status, /* reset status to state provided */
49937- lmc_hssi_set_clock, /* set clock source */
49938- lmc_dummy_set2_1, /* set line speed */
49939- lmc_dummy_set_1, /* set cable length */
49940- lmc_dummy_set_1, /* set scrambler */
49941- lmc_hssi_get_link_status, /* get link status */
49942- lmc_hssi_set_link_status, /* set link status */
49943- lmc_hssi_set_crc_length, /* set CRC length */
49944- lmc_dummy_set_1, /* set T1 or E1 circuit type */
49945- lmc_hssi_watchdog
49946+ .init = lmc_hssi_init, /* special media init stuff */
49947+ .defaults = lmc_hssi_default, /* reset to default state */
49948+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
49949+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
49950+ .set_speed = lmc_dummy_set2_1, /* set line speed */
49951+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
49952+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49953+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
49954+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
49955+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
49956+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49957+ .watchdog = lmc_hssi_watchdog
49958 };
49959
49960-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
49961- lmc_ssi_default, /* reset to default state */
49962- lmc_ssi_set_status, /* reset status to state provided */
49963- lmc_ssi_set_clock, /* set clock source */
49964- lmc_ssi_set_speed, /* set line speed */
49965- lmc_dummy_set_1, /* set cable length */
49966- lmc_dummy_set_1, /* set scrambler */
49967- lmc_ssi_get_link_status, /* get link status */
49968- lmc_ssi_set_link_status, /* set link status */
49969- lmc_ssi_set_crc_length, /* set CRC length */
49970- lmc_dummy_set_1, /* set T1 or E1 circuit type */
49971- lmc_ssi_watchdog
49972+lmc_media_t lmc_ssi_media = {
49973+ .init = lmc_ssi_init, /* special media init stuff */
49974+ .defaults = lmc_ssi_default, /* reset to default state */
49975+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
49976+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
49977+ .set_speed = lmc_ssi_set_speed, /* set line speed */
49978+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
49979+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49980+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
49981+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
49982+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
49983+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49984+ .watchdog = lmc_ssi_watchdog
49985 };
49986
49987 lmc_media_t lmc_t1_media = {
49988- lmc_t1_init, /* special media init stuff */
49989- lmc_t1_default, /* reset to default state */
49990- lmc_t1_set_status, /* reset status to state provided */
49991- lmc_t1_set_clock, /* set clock source */
49992- lmc_dummy_set2_1, /* set line speed */
49993- lmc_dummy_set_1, /* set cable length */
49994- lmc_dummy_set_1, /* set scrambler */
49995- lmc_t1_get_link_status, /* get link status */
49996- lmc_dummy_set_1, /* set link status */
49997- lmc_t1_set_crc_length, /* set CRC length */
49998- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49999- lmc_t1_watchdog
50000+ .init = lmc_t1_init, /* special media init stuff */
50001+ .defaults = lmc_t1_default, /* reset to default state */
50002+ .set_status = lmc_t1_set_status, /* reset status to state provided */
50003+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
50004+ .set_speed = lmc_dummy_set2_1, /* set line speed */
50005+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
50006+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
50007+ .get_link_status = lmc_t1_get_link_status, /* get link status */
50008+ .set_link_status = lmc_dummy_set_1, /* set link status */
50009+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
50010+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
50011+ .watchdog = lmc_t1_watchdog
50012 };
50013
50014 static void
50015diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
50016index feacc3b..5bac0de 100644
50017--- a/drivers/net/wan/z85230.c
50018+++ b/drivers/net/wan/z85230.c
50019@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
50020
50021 struct z8530_irqhandler z8530_sync =
50022 {
50023- z8530_rx,
50024- z8530_tx,
50025- z8530_status
50026+ .rx = z8530_rx,
50027+ .tx = z8530_tx,
50028+ .status = z8530_status
50029 };
50030
50031 EXPORT_SYMBOL(z8530_sync);
50032@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
50033 }
50034
50035 static struct z8530_irqhandler z8530_dma_sync = {
50036- z8530_dma_rx,
50037- z8530_dma_tx,
50038- z8530_dma_status
50039+ .rx = z8530_dma_rx,
50040+ .tx = z8530_dma_tx,
50041+ .status = z8530_dma_status
50042 };
50043
50044 static struct z8530_irqhandler z8530_txdma_sync = {
50045- z8530_rx,
50046- z8530_dma_tx,
50047- z8530_dma_status
50048+ .rx = z8530_rx,
50049+ .tx = z8530_dma_tx,
50050+ .status = z8530_dma_status
50051 };
50052
50053 /**
50054@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
50055
50056 struct z8530_irqhandler z8530_nop=
50057 {
50058- z8530_rx_clear,
50059- z8530_tx_clear,
50060- z8530_status_clear
50061+ .rx = z8530_rx_clear,
50062+ .tx = z8530_tx_clear,
50063+ .status = z8530_status_clear
50064 };
50065
50066
50067diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
50068index 0b60295..b8bfa5b 100644
50069--- a/drivers/net/wimax/i2400m/rx.c
50070+++ b/drivers/net/wimax/i2400m/rx.c
50071@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
50072 if (i2400m->rx_roq == NULL)
50073 goto error_roq_alloc;
50074
50075- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
50076+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
50077 GFP_KERNEL);
50078 if (rd == NULL) {
50079 result = -ENOMEM;
50080diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
50081index 64747d4..17c4cf3 100644
50082--- a/drivers/net/wireless/airo.c
50083+++ b/drivers/net/wireless/airo.c
50084@@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
50085 struct airo_info *ai = dev->ml_priv;
50086 int ridcode;
50087 int enabled;
50088- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
50089+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
50090 unsigned char *iobuf;
50091
50092 /* Only super-user can write RIDs */
50093diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
50094index d48776e..373d049 100644
50095--- a/drivers/net/wireless/at76c50x-usb.c
50096+++ b/drivers/net/wireless/at76c50x-usb.c
50097@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
50098 }
50099
50100 /* Convert timeout from the DFU status to jiffies */
50101-static inline unsigned long at76_get_timeout(struct dfu_status *s)
50102+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
50103 {
50104 return msecs_to_jiffies((s->poll_timeout[2] << 16)
50105 | (s->poll_timeout[1] << 8)
50106diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
50107index e493db4..2c1853a 100644
50108--- a/drivers/net/wireless/ath/ath10k/htc.c
50109+++ b/drivers/net/wireless/ath/ath10k/htc.c
50110@@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
50111 /* registered target arrival callback from the HIF layer */
50112 int ath10k_htc_init(struct ath10k *ar)
50113 {
50114- struct ath10k_hif_cb htc_callbacks;
50115+ static struct ath10k_hif_cb htc_callbacks = {
50116+ .rx_completion = ath10k_htc_rx_completion_handler,
50117+ .tx_completion = ath10k_htc_tx_completion_handler,
50118+ };
50119 struct ath10k_htc_ep *ep = NULL;
50120 struct ath10k_htc *htc = &ar->htc;
50121
50122@@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
50123 ath10k_htc_reset_endpoint_states(htc);
50124
50125 /* setup HIF layer callbacks */
50126- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
50127- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
50128 htc->ar = ar;
50129
50130 /* Get HIF default pipe for HTC message exchange */
50131diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
50132index 4716d33..a688310 100644
50133--- a/drivers/net/wireless/ath/ath10k/htc.h
50134+++ b/drivers/net/wireless/ath/ath10k/htc.h
50135@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
50136
50137 struct ath10k_htc_ops {
50138 void (*target_send_suspend_complete)(struct ath10k *ar);
50139-};
50140+} __no_const;
50141
50142 struct ath10k_htc_ep_ops {
50143 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
50144 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
50145 void (*ep_tx_credits)(struct ath10k *);
50146-};
50147+} __no_const;
50148
50149 /* service connection information */
50150 struct ath10k_htc_svc_conn_req {
50151diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50152index 741b38d..b7ae41b 100644
50153--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50154+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50155@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50156 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
50157 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
50158
50159- ACCESS_ONCE(ads->ds_link) = i->link;
50160- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
50161+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
50162+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
50163
50164 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
50165 ctl6 = SM(i->keytype, AR_EncrType);
50166@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50167
50168 if ((i->is_first || i->is_last) &&
50169 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
50170- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
50171+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
50172 | set11nTries(i->rates, 1)
50173 | set11nTries(i->rates, 2)
50174 | set11nTries(i->rates, 3)
50175 | (i->dur_update ? AR_DurUpdateEna : 0)
50176 | SM(0, AR_BurstDur);
50177
50178- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
50179+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
50180 | set11nRate(i->rates, 1)
50181 | set11nRate(i->rates, 2)
50182 | set11nRate(i->rates, 3);
50183 } else {
50184- ACCESS_ONCE(ads->ds_ctl2) = 0;
50185- ACCESS_ONCE(ads->ds_ctl3) = 0;
50186+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
50187+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
50188 }
50189
50190 if (!i->is_first) {
50191- ACCESS_ONCE(ads->ds_ctl0) = 0;
50192- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
50193- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
50194+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
50195+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
50196+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
50197 return;
50198 }
50199
50200@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50201 break;
50202 }
50203
50204- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
50205+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
50206 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
50207 | SM(i->txpower, AR_XmitPower)
50208 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
50209@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50210 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
50211 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
50212
50213- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
50214- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
50215+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
50216+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
50217
50218 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
50219 return;
50220
50221- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
50222+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
50223 | set11nPktDurRTSCTS(i->rates, 1);
50224
50225- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
50226+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
50227 | set11nPktDurRTSCTS(i->rates, 3);
50228
50229- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
50230+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
50231 | set11nRateFlags(i->rates, 1)
50232 | set11nRateFlags(i->rates, 2)
50233 | set11nRateFlags(i->rates, 3)
50234diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50235index 729ffbf..49f50e3 100644
50236--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50237+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50238@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50239 (i->qcu << AR_TxQcuNum_S) | desc_len;
50240
50241 checksum += val;
50242- ACCESS_ONCE(ads->info) = val;
50243+ ACCESS_ONCE_RW(ads->info) = val;
50244
50245 checksum += i->link;
50246- ACCESS_ONCE(ads->link) = i->link;
50247+ ACCESS_ONCE_RW(ads->link) = i->link;
50248
50249 checksum += i->buf_addr[0];
50250- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
50251+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
50252 checksum += i->buf_addr[1];
50253- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
50254+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
50255 checksum += i->buf_addr[2];
50256- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
50257+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
50258 checksum += i->buf_addr[3];
50259- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
50260+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
50261
50262 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
50263- ACCESS_ONCE(ads->ctl3) = val;
50264+ ACCESS_ONCE_RW(ads->ctl3) = val;
50265 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
50266- ACCESS_ONCE(ads->ctl5) = val;
50267+ ACCESS_ONCE_RW(ads->ctl5) = val;
50268 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
50269- ACCESS_ONCE(ads->ctl7) = val;
50270+ ACCESS_ONCE_RW(ads->ctl7) = val;
50271 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
50272- ACCESS_ONCE(ads->ctl9) = val;
50273+ ACCESS_ONCE_RW(ads->ctl9) = val;
50274
50275 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
50276- ACCESS_ONCE(ads->ctl10) = checksum;
50277+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
50278
50279 if (i->is_first || i->is_last) {
50280- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
50281+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
50282 | set11nTries(i->rates, 1)
50283 | set11nTries(i->rates, 2)
50284 | set11nTries(i->rates, 3)
50285 | (i->dur_update ? AR_DurUpdateEna : 0)
50286 | SM(0, AR_BurstDur);
50287
50288- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
50289+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
50290 | set11nRate(i->rates, 1)
50291 | set11nRate(i->rates, 2)
50292 | set11nRate(i->rates, 3);
50293 } else {
50294- ACCESS_ONCE(ads->ctl13) = 0;
50295- ACCESS_ONCE(ads->ctl14) = 0;
50296+ ACCESS_ONCE_RW(ads->ctl13) = 0;
50297+ ACCESS_ONCE_RW(ads->ctl14) = 0;
50298 }
50299
50300 ads->ctl20 = 0;
50301@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50302
50303 ctl17 = SM(i->keytype, AR_EncrType);
50304 if (!i->is_first) {
50305- ACCESS_ONCE(ads->ctl11) = 0;
50306- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
50307- ACCESS_ONCE(ads->ctl15) = 0;
50308- ACCESS_ONCE(ads->ctl16) = 0;
50309- ACCESS_ONCE(ads->ctl17) = ctl17;
50310- ACCESS_ONCE(ads->ctl18) = 0;
50311- ACCESS_ONCE(ads->ctl19) = 0;
50312+ ACCESS_ONCE_RW(ads->ctl11) = 0;
50313+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
50314+ ACCESS_ONCE_RW(ads->ctl15) = 0;
50315+ ACCESS_ONCE_RW(ads->ctl16) = 0;
50316+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
50317+ ACCESS_ONCE_RW(ads->ctl18) = 0;
50318+ ACCESS_ONCE_RW(ads->ctl19) = 0;
50319 return;
50320 }
50321
50322- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
50323+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
50324 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
50325 | SM(i->txpower, AR_XmitPower)
50326 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
50327@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50328 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
50329 ctl12 |= SM(val, AR_PAPRDChainMask);
50330
50331- ACCESS_ONCE(ads->ctl12) = ctl12;
50332- ACCESS_ONCE(ads->ctl17) = ctl17;
50333+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
50334+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
50335
50336- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
50337+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
50338 | set11nPktDurRTSCTS(i->rates, 1);
50339
50340- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
50341+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
50342 | set11nPktDurRTSCTS(i->rates, 3);
50343
50344- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
50345+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
50346 | set11nRateFlags(i->rates, 1)
50347 | set11nRateFlags(i->rates, 2)
50348 | set11nRateFlags(i->rates, 3)
50349 | SM(i->rtscts_rate, AR_RTSCTSRate);
50350
50351- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
50352+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
50353 }
50354
50355 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
50356diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
50357index 0acd4b5..0591c91 100644
50358--- a/drivers/net/wireless/ath/ath9k/hw.h
50359+++ b/drivers/net/wireless/ath/ath9k/hw.h
50360@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
50361
50362 /* ANI */
50363 void (*ani_cache_ini_regs)(struct ath_hw *ah);
50364-};
50365+} __no_const;
50366
50367 /**
50368 * struct ath_spec_scan - parameters for Atheros spectral scan
50369@@ -706,7 +706,7 @@ struct ath_hw_ops {
50370 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
50371 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
50372 #endif
50373-};
50374+} __no_const;
50375
50376 struct ath_nf_limits {
50377 s16 max;
50378diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
50379index 92190da..f3a4c4c 100644
50380--- a/drivers/net/wireless/b43/phy_lp.c
50381+++ b/drivers/net/wireless/b43/phy_lp.c
50382@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
50383 {
50384 struct ssb_bus *bus = dev->dev->sdev->bus;
50385
50386- static const struct b206x_channel *chandata = NULL;
50387+ const struct b206x_channel *chandata = NULL;
50388 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
50389 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
50390 u16 old_comm15, scale;
50391diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
50392index dc1d20c..f7a4f06 100644
50393--- a/drivers/net/wireless/iwlegacy/3945-mac.c
50394+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
50395@@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
50396 */
50397 if (il3945_mod_params.disable_hw_scan) {
50398 D_INFO("Disabling hw_scan\n");
50399- il3945_mac_ops.hw_scan = NULL;
50400+ pax_open_kernel();
50401+ *(void **)&il3945_mac_ops.hw_scan = NULL;
50402+ pax_close_kernel();
50403 }
50404
50405 D_INFO("*** LOAD DRIVER ***\n");
50406diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50407index 0ffb6ff..c0b7f0e 100644
50408--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50409+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50410@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
50411 {
50412 struct iwl_priv *priv = file->private_data;
50413 char buf[64];
50414- int buf_size;
50415+ size_t buf_size;
50416 u32 offset, len;
50417
50418 memset(buf, 0, sizeof(buf));
50419@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
50420 struct iwl_priv *priv = file->private_data;
50421
50422 char buf[8];
50423- int buf_size;
50424+ size_t buf_size;
50425 u32 reset_flag;
50426
50427 memset(buf, 0, sizeof(buf));
50428@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
50429 {
50430 struct iwl_priv *priv = file->private_data;
50431 char buf[8];
50432- int buf_size;
50433+ size_t buf_size;
50434 int ht40;
50435
50436 memset(buf, 0, sizeof(buf));
50437@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
50438 {
50439 struct iwl_priv *priv = file->private_data;
50440 char buf[8];
50441- int buf_size;
50442+ size_t buf_size;
50443 int value;
50444
50445 memset(buf, 0, sizeof(buf));
50446@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
50447 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
50448 DEBUGFS_READ_FILE_OPS(current_sleep_command);
50449
50450-static const char *fmt_value = " %-30s %10u\n";
50451-static const char *fmt_hex = " %-30s 0x%02X\n";
50452-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
50453-static const char *fmt_header =
50454+static const char fmt_value[] = " %-30s %10u\n";
50455+static const char fmt_hex[] = " %-30s 0x%02X\n";
50456+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
50457+static const char fmt_header[] =
50458 "%-32s current cumulative delta max\n";
50459
50460 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
50461@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
50462 {
50463 struct iwl_priv *priv = file->private_data;
50464 char buf[8];
50465- int buf_size;
50466+ size_t buf_size;
50467 int clear;
50468
50469 memset(buf, 0, sizeof(buf));
50470@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
50471 {
50472 struct iwl_priv *priv = file->private_data;
50473 char buf[8];
50474- int buf_size;
50475+ size_t buf_size;
50476 int trace;
50477
50478 memset(buf, 0, sizeof(buf));
50479@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
50480 {
50481 struct iwl_priv *priv = file->private_data;
50482 char buf[8];
50483- int buf_size;
50484+ size_t buf_size;
50485 int missed;
50486
50487 memset(buf, 0, sizeof(buf));
50488@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
50489
50490 struct iwl_priv *priv = file->private_data;
50491 char buf[8];
50492- int buf_size;
50493+ size_t buf_size;
50494 int plcp;
50495
50496 memset(buf, 0, sizeof(buf));
50497@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
50498
50499 struct iwl_priv *priv = file->private_data;
50500 char buf[8];
50501- int buf_size;
50502+ size_t buf_size;
50503 int flush;
50504
50505 memset(buf, 0, sizeof(buf));
50506@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
50507
50508 struct iwl_priv *priv = file->private_data;
50509 char buf[8];
50510- int buf_size;
50511+ size_t buf_size;
50512 int rts;
50513
50514 if (!priv->cfg->ht_params)
50515@@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
50516 {
50517 struct iwl_priv *priv = file->private_data;
50518 char buf[8];
50519- int buf_size;
50520+ size_t buf_size;
50521
50522 memset(buf, 0, sizeof(buf));
50523 buf_size = min(count, sizeof(buf) - 1);
50524@@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
50525 struct iwl_priv *priv = file->private_data;
50526 u32 event_log_flag;
50527 char buf[8];
50528- int buf_size;
50529+ size_t buf_size;
50530
50531 /* check that the interface is up */
50532 if (!iwl_is_ready(priv))
50533@@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
50534 struct iwl_priv *priv = file->private_data;
50535 char buf[8];
50536 u32 calib_disabled;
50537- int buf_size;
50538+ size_t buf_size;
50539
50540 memset(buf, 0, sizeof(buf));
50541 buf_size = min(count, sizeof(buf) - 1);
50542diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
50543index 788085b..0bc852a 100644
50544--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
50545+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
50546@@ -1598,7 +1598,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
50547 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
50548
50549 char buf[8];
50550- int buf_size;
50551+ size_t buf_size;
50552 u32 reset_flag;
50553
50554 memset(buf, 0, sizeof(buf));
50555@@ -1619,7 +1619,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
50556 {
50557 struct iwl_trans *trans = file->private_data;
50558 char buf[8];
50559- int buf_size;
50560+ size_t buf_size;
50561 int csr;
50562
50563 memset(buf, 0, sizeof(buf));
50564diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
50565index a312c65..162b13a 100644
50566--- a/drivers/net/wireless/mac80211_hwsim.c
50567+++ b/drivers/net/wireless/mac80211_hwsim.c
50568@@ -2573,20 +2573,20 @@ static int __init init_mac80211_hwsim(void)
50569 if (channels < 1)
50570 return -EINVAL;
50571
50572- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
50573- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50574- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50575- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50576- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50577- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50578- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50579- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50580- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50581- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50582- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
50583- mac80211_hwsim_assign_vif_chanctx;
50584- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
50585- mac80211_hwsim_unassign_vif_chanctx;
50586+ pax_open_kernel();
50587+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
50588+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50589+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50590+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50591+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50592+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50593+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50594+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50595+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50596+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50597+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
50598+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
50599+ pax_close_kernel();
50600
50601 spin_lock_init(&hwsim_radio_lock);
50602 INIT_LIST_HEAD(&hwsim_radios);
50603diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
50604index d2a9a08..0cb175d 100644
50605--- a/drivers/net/wireless/rndis_wlan.c
50606+++ b/drivers/net/wireless/rndis_wlan.c
50607@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
50608
50609 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
50610
50611- if (rts_threshold < 0 || rts_threshold > 2347)
50612+ if (rts_threshold > 2347)
50613 rts_threshold = 2347;
50614
50615 tmp = cpu_to_le32(rts_threshold);
50616diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
50617index d13f25c..2573994 100644
50618--- a/drivers/net/wireless/rt2x00/rt2x00.h
50619+++ b/drivers/net/wireless/rt2x00/rt2x00.h
50620@@ -375,7 +375,7 @@ struct rt2x00_intf {
50621 * for hardware which doesn't support hardware
50622 * sequence counting.
50623 */
50624- atomic_t seqno;
50625+ atomic_unchecked_t seqno;
50626 };
50627
50628 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
50629diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
50630index 5642ccc..01f03eb 100644
50631--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
50632+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
50633@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
50634 * sequence counter given by mac80211.
50635 */
50636 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
50637- seqno = atomic_add_return(0x10, &intf->seqno);
50638+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
50639 else
50640- seqno = atomic_read(&intf->seqno);
50641+ seqno = atomic_read_unchecked(&intf->seqno);
50642
50643 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
50644 hdr->seq_ctrl |= cpu_to_le16(seqno);
50645diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
50646index b661f896..ddf7d2b 100644
50647--- a/drivers/net/wireless/ti/wl1251/sdio.c
50648+++ b/drivers/net/wireless/ti/wl1251/sdio.c
50649@@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
50650
50651 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
50652
50653- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50654- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50655+ pax_open_kernel();
50656+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50657+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50658+ pax_close_kernel();
50659
50660 wl1251_info("using dedicated interrupt line");
50661 } else {
50662- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50663- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50664+ pax_open_kernel();
50665+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50666+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50667+ pax_close_kernel();
50668
50669 wl1251_info("using SDIO interrupt");
50670 }
50671diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
50672index d50dfac..0a6f5be3 100644
50673--- a/drivers/net/wireless/ti/wl12xx/main.c
50674+++ b/drivers/net/wireless/ti/wl12xx/main.c
50675@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50676 sizeof(wl->conf.mem));
50677
50678 /* read data preparation is only needed by wl127x */
50679- wl->ops->prepare_read = wl127x_prepare_read;
50680+ pax_open_kernel();
50681+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50682+ pax_close_kernel();
50683
50684 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50685 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50686@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50687 sizeof(wl->conf.mem));
50688
50689 /* read data preparation is only needed by wl127x */
50690- wl->ops->prepare_read = wl127x_prepare_read;
50691+ pax_open_kernel();
50692+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50693+ pax_close_kernel();
50694
50695 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50696 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50697diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
50698index de5b4fa..7996ec6 100644
50699--- a/drivers/net/wireless/ti/wl18xx/main.c
50700+++ b/drivers/net/wireless/ti/wl18xx/main.c
50701@@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
50702 }
50703
50704 if (!checksum_param) {
50705- wl18xx_ops.set_rx_csum = NULL;
50706- wl18xx_ops.init_vif = NULL;
50707+ pax_open_kernel();
50708+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
50709+ *(void **)&wl18xx_ops.init_vif = NULL;
50710+ pax_close_kernel();
50711 }
50712
50713 /* Enable 11a Band only if we have 5G antennas */
50714diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
50715index a912dc0..a8225ba 100644
50716--- a/drivers/net/wireless/zd1211rw/zd_usb.c
50717+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
50718@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
50719 {
50720 struct zd_usb *usb = urb->context;
50721 struct zd_usb_interrupt *intr = &usb->intr;
50722- int len;
50723+ unsigned int len;
50724 u16 int_num;
50725
50726 ZD_ASSERT(in_interrupt());
50727diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
50728index 683671a..4519fc2 100644
50729--- a/drivers/nfc/nfcwilink.c
50730+++ b/drivers/nfc/nfcwilink.c
50731@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
50732
50733 static int nfcwilink_probe(struct platform_device *pdev)
50734 {
50735- static struct nfcwilink *drv;
50736+ struct nfcwilink *drv;
50737 int rc;
50738 __u32 protocols;
50739
50740diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
50741index d93b2b6..ae50401 100644
50742--- a/drivers/oprofile/buffer_sync.c
50743+++ b/drivers/oprofile/buffer_sync.c
50744@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
50745 if (cookie == NO_COOKIE)
50746 offset = pc;
50747 if (cookie == INVALID_COOKIE) {
50748- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50749+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50750 offset = pc;
50751 }
50752 if (cookie != last_cookie) {
50753@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
50754 /* add userspace sample */
50755
50756 if (!mm) {
50757- atomic_inc(&oprofile_stats.sample_lost_no_mm);
50758+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
50759 return 0;
50760 }
50761
50762 cookie = lookup_dcookie(mm, s->eip, &offset);
50763
50764 if (cookie == INVALID_COOKIE) {
50765- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50766+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50767 return 0;
50768 }
50769
50770@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
50771 /* ignore backtraces if failed to add a sample */
50772 if (state == sb_bt_start) {
50773 state = sb_bt_ignore;
50774- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
50775+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
50776 }
50777 }
50778 release_mm(mm);
50779diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
50780index c0cc4e7..44d4e54 100644
50781--- a/drivers/oprofile/event_buffer.c
50782+++ b/drivers/oprofile/event_buffer.c
50783@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
50784 }
50785
50786 if (buffer_pos == buffer_size) {
50787- atomic_inc(&oprofile_stats.event_lost_overflow);
50788+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
50789 return;
50790 }
50791
50792diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
50793index ed2c3ec..deda85a 100644
50794--- a/drivers/oprofile/oprof.c
50795+++ b/drivers/oprofile/oprof.c
50796@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
50797 if (oprofile_ops.switch_events())
50798 return;
50799
50800- atomic_inc(&oprofile_stats.multiplex_counter);
50801+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
50802 start_switch_worker();
50803 }
50804
50805diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
50806index ee2cfce..7f8f699 100644
50807--- a/drivers/oprofile/oprofile_files.c
50808+++ b/drivers/oprofile/oprofile_files.c
50809@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
50810
50811 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
50812
50813-static ssize_t timeout_read(struct file *file, char __user *buf,
50814+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
50815 size_t count, loff_t *offset)
50816 {
50817 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
50818diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
50819index 59659ce..6c860a0 100644
50820--- a/drivers/oprofile/oprofile_stats.c
50821+++ b/drivers/oprofile/oprofile_stats.c
50822@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
50823 cpu_buf->sample_invalid_eip = 0;
50824 }
50825
50826- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
50827- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
50828- atomic_set(&oprofile_stats.event_lost_overflow, 0);
50829- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
50830- atomic_set(&oprofile_stats.multiplex_counter, 0);
50831+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
50832+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
50833+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
50834+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
50835+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
50836 }
50837
50838
50839diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
50840index 1fc622b..8c48fc3 100644
50841--- a/drivers/oprofile/oprofile_stats.h
50842+++ b/drivers/oprofile/oprofile_stats.h
50843@@ -13,11 +13,11 @@
50844 #include <linux/atomic.h>
50845
50846 struct oprofile_stat_struct {
50847- atomic_t sample_lost_no_mm;
50848- atomic_t sample_lost_no_mapping;
50849- atomic_t bt_lost_no_mapping;
50850- atomic_t event_lost_overflow;
50851- atomic_t multiplex_counter;
50852+ atomic_unchecked_t sample_lost_no_mm;
50853+ atomic_unchecked_t sample_lost_no_mapping;
50854+ atomic_unchecked_t bt_lost_no_mapping;
50855+ atomic_unchecked_t event_lost_overflow;
50856+ atomic_unchecked_t multiplex_counter;
50857 };
50858
50859 extern struct oprofile_stat_struct oprofile_stats;
50860diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
50861index 3f49345..c750d0b 100644
50862--- a/drivers/oprofile/oprofilefs.c
50863+++ b/drivers/oprofile/oprofilefs.c
50864@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
50865
50866 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
50867 {
50868- atomic_t *val = file->private_data;
50869- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
50870+ atomic_unchecked_t *val = file->private_data;
50871+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
50872 }
50873
50874
50875@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
50876
50877
50878 int oprofilefs_create_ro_atomic(struct dentry *root,
50879- char const *name, atomic_t *val)
50880+ char const *name, atomic_unchecked_t *val)
50881 {
50882 return __oprofilefs_create_file(root, name,
50883 &atomic_ro_fops, 0444, val);
50884diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
50885index 61be1d9..dec05d7 100644
50886--- a/drivers/oprofile/timer_int.c
50887+++ b/drivers/oprofile/timer_int.c
50888@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
50889 return NOTIFY_OK;
50890 }
50891
50892-static struct notifier_block __refdata oprofile_cpu_notifier = {
50893+static struct notifier_block oprofile_cpu_notifier = {
50894 .notifier_call = oprofile_cpu_notify,
50895 };
50896
50897diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
50898index 3b47080..6cd05dd 100644
50899--- a/drivers/parport/procfs.c
50900+++ b/drivers/parport/procfs.c
50901@@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
50902
50903 *ppos += len;
50904
50905- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
50906+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
50907 }
50908
50909 #ifdef CONFIG_PARPORT_1284
50910@@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
50911
50912 *ppos += len;
50913
50914- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
50915+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
50916 }
50917 #endif /* IEEE1284.3 support. */
50918
50919diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
50920index 8dcccff..35d701d 100644
50921--- a/drivers/pci/hotplug/acpiphp_ibm.c
50922+++ b/drivers/pci/hotplug/acpiphp_ibm.c
50923@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
50924 goto init_cleanup;
50925 }
50926
50927- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50928+ pax_open_kernel();
50929+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50930+ pax_close_kernel();
50931 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
50932
50933 return retval;
50934diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
50935index 04fcd78..39e83f1 100644
50936--- a/drivers/pci/hotplug/cpcihp_generic.c
50937+++ b/drivers/pci/hotplug/cpcihp_generic.c
50938@@ -73,7 +73,6 @@ static u16 port;
50939 static unsigned int enum_bit;
50940 static u8 enum_mask;
50941
50942-static struct cpci_hp_controller_ops generic_hpc_ops;
50943 static struct cpci_hp_controller generic_hpc;
50944
50945 static int __init validate_parameters(void)
50946@@ -139,6 +138,10 @@ static int query_enum(void)
50947 return ((value & enum_mask) == enum_mask);
50948 }
50949
50950+static struct cpci_hp_controller_ops generic_hpc_ops = {
50951+ .query_enum = query_enum,
50952+};
50953+
50954 static int __init cpcihp_generic_init(void)
50955 {
50956 int status;
50957@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
50958 pci_dev_put(dev);
50959
50960 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
50961- generic_hpc_ops.query_enum = query_enum;
50962 generic_hpc.ops = &generic_hpc_ops;
50963
50964 status = cpci_hp_register_controller(&generic_hpc);
50965diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
50966index 6757b3e..d3bad62 100644
50967--- a/drivers/pci/hotplug/cpcihp_zt5550.c
50968+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
50969@@ -59,7 +59,6 @@
50970 /* local variables */
50971 static bool debug;
50972 static bool poll;
50973-static struct cpci_hp_controller_ops zt5550_hpc_ops;
50974 static struct cpci_hp_controller zt5550_hpc;
50975
50976 /* Primary cPCI bus bridge device */
50977@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
50978 return 0;
50979 }
50980
50981+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
50982+ .query_enum = zt5550_hc_query_enum,
50983+};
50984+
50985 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
50986 {
50987 int status;
50988@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
50989 dbg("returned from zt5550_hc_config");
50990
50991 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
50992- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
50993 zt5550_hpc.ops = &zt5550_hpc_ops;
50994 if(!poll) {
50995 zt5550_hpc.irq = hc_dev->irq;
50996 zt5550_hpc.irq_flags = IRQF_SHARED;
50997 zt5550_hpc.dev_id = hc_dev;
50998
50999- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
51000- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
51001- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
51002+ pax_open_kernel();
51003+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
51004+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
51005+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
51006+ pax_open_kernel();
51007 } else {
51008 info("using ENUM# polling mode");
51009 }
51010diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
51011index 0968a9b..5a00edf 100644
51012--- a/drivers/pci/hotplug/cpqphp_nvram.c
51013+++ b/drivers/pci/hotplug/cpqphp_nvram.c
51014@@ -427,9 +427,13 @@ static u32 store_HRT (void __iomem *rom_start)
51015
51016 void compaq_nvram_init (void __iomem *rom_start)
51017 {
51018+
51019+#ifndef CONFIG_PAX_KERNEXEC
51020 if (rom_start) {
51021 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
51022 }
51023+#endif
51024+
51025 dbg("int15 entry = %p\n", compaq_int15_entry_point);
51026
51027 /* initialize our int15 lock */
51028diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
51029index 56d8486..f26113f 100644
51030--- a/drivers/pci/hotplug/pci_hotplug_core.c
51031+++ b/drivers/pci/hotplug/pci_hotplug_core.c
51032@@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
51033 return -EINVAL;
51034 }
51035
51036- slot->ops->owner = owner;
51037- slot->ops->mod_name = mod_name;
51038+ pax_open_kernel();
51039+ *(struct module **)&slot->ops->owner = owner;
51040+ *(const char **)&slot->ops->mod_name = mod_name;
51041+ pax_close_kernel();
51042
51043 mutex_lock(&pci_hp_mutex);
51044 /*
51045diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
51046index a2297db..7c7d161 100644
51047--- a/drivers/pci/hotplug/pciehp_core.c
51048+++ b/drivers/pci/hotplug/pciehp_core.c
51049@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
51050 struct slot *slot = ctrl->slot;
51051 struct hotplug_slot *hotplug = NULL;
51052 struct hotplug_slot_info *info = NULL;
51053- struct hotplug_slot_ops *ops = NULL;
51054+ hotplug_slot_ops_no_const *ops = NULL;
51055 char name[SLOT_NAME_SIZE];
51056 int retval = -ENOMEM;
51057
51058diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
51059index 13f3d30..363cb44 100644
51060--- a/drivers/pci/msi.c
51061+++ b/drivers/pci/msi.c
51062@@ -523,8 +523,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
51063 {
51064 struct attribute **msi_attrs;
51065 struct attribute *msi_attr;
51066- struct device_attribute *msi_dev_attr;
51067- struct attribute_group *msi_irq_group;
51068+ device_attribute_no_const *msi_dev_attr;
51069+ attribute_group_no_const *msi_irq_group;
51070 const struct attribute_group **msi_irq_groups;
51071 struct msi_desc *entry;
51072 int ret = -ENOMEM;
51073@@ -584,7 +584,7 @@ error_attrs:
51074 count = 0;
51075 msi_attr = msi_attrs[count];
51076 while (msi_attr) {
51077- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
51078+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
51079 kfree(msi_attr->name);
51080 kfree(msi_dev_attr);
51081 ++count;
51082diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
51083index 9ff0a90..e819dda 100644
51084--- a/drivers/pci/pci-sysfs.c
51085+++ b/drivers/pci/pci-sysfs.c
51086@@ -1134,7 +1134,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
51087 {
51088 /* allocate attribute structure, piggyback attribute name */
51089 int name_len = write_combine ? 13 : 10;
51090- struct bin_attribute *res_attr;
51091+ bin_attribute_no_const *res_attr;
51092 int retval;
51093
51094 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
51095@@ -1311,7 +1311,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
51096 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
51097 {
51098 int retval;
51099- struct bin_attribute *attr;
51100+ bin_attribute_no_const *attr;
51101
51102 /* If the device has VPD, try to expose it in sysfs. */
51103 if (dev->vpd) {
51104@@ -1358,7 +1358,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
51105 {
51106 int retval;
51107 int rom_size = 0;
51108- struct bin_attribute *attr;
51109+ bin_attribute_no_const *attr;
51110
51111 if (!sysfs_initialized)
51112 return -EACCES;
51113diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
51114index 0601890..dc15007 100644
51115--- a/drivers/pci/pci.h
51116+++ b/drivers/pci/pci.h
51117@@ -91,7 +91,7 @@ struct pci_vpd_ops {
51118 struct pci_vpd {
51119 unsigned int len;
51120 const struct pci_vpd_ops *ops;
51121- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
51122+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
51123 };
51124
51125 int pci_vpd_pci22_init(struct pci_dev *dev);
51126diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
51127index e1e7026..d28dd33 100644
51128--- a/drivers/pci/pcie/aspm.c
51129+++ b/drivers/pci/pcie/aspm.c
51130@@ -27,9 +27,9 @@
51131 #define MODULE_PARAM_PREFIX "pcie_aspm."
51132
51133 /* Note: those are not register definitions */
51134-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
51135-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
51136-#define ASPM_STATE_L1 (4) /* L1 state */
51137+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
51138+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
51139+#define ASPM_STATE_L1 (4U) /* L1 state */
51140 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
51141 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
51142
51143diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
51144index e3cf8a2..be1baf0 100644
51145--- a/drivers/pci/probe.c
51146+++ b/drivers/pci/probe.c
51147@@ -176,7 +176,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
51148 struct pci_bus_region region, inverted_region;
51149 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
51150
51151- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
51152+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
51153
51154 /* No printks while decoding is disabled! */
51155 if (!dev->mmio_always_on) {
51156diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
51157index 3f155e7..0f4b1f0 100644
51158--- a/drivers/pci/proc.c
51159+++ b/drivers/pci/proc.c
51160@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
51161 static int __init pci_proc_init(void)
51162 {
51163 struct pci_dev *dev = NULL;
51164+
51165+#ifdef CONFIG_GRKERNSEC_PROC_ADD
51166+#ifdef CONFIG_GRKERNSEC_PROC_USER
51167+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
51168+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51169+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51170+#endif
51171+#else
51172 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
51173+#endif
51174 proc_create("devices", 0, proc_bus_pci_dir,
51175 &proc_bus_pci_dev_operations);
51176 proc_initialized = 1;
51177diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
51178index 7f1a2e2..bc4b405 100644
51179--- a/drivers/platform/chrome/chromeos_laptop.c
51180+++ b/drivers/platform/chrome/chromeos_laptop.c
51181@@ -395,7 +395,7 @@ static struct chromeos_laptop cr48 = {
51182 .callback = chromeos_laptop_dmi_matched, \
51183 .driver_data = (void *)&board_
51184
51185-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
51186+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
51187 {
51188 .ident = "Samsung Series 5 550",
51189 .matches = {
51190diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
51191index 297b664..ab91e39 100644
51192--- a/drivers/platform/x86/alienware-wmi.c
51193+++ b/drivers/platform/x86/alienware-wmi.c
51194@@ -133,7 +133,7 @@ struct wmax_led_args {
51195 } __packed;
51196
51197 static struct platform_device *platform_device;
51198-static struct device_attribute *zone_dev_attrs;
51199+static device_attribute_no_const *zone_dev_attrs;
51200 static struct attribute **zone_attrs;
51201 static struct platform_zone *zone_data;
51202
51203@@ -144,7 +144,7 @@ static struct platform_driver platform_driver = {
51204 }
51205 };
51206
51207-static struct attribute_group zone_attribute_group = {
51208+static attribute_group_no_const zone_attribute_group = {
51209 .name = "rgb_zones",
51210 };
51211
51212diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
51213index 3c6cced..12e0771 100644
51214--- a/drivers/platform/x86/asus-wmi.c
51215+++ b/drivers/platform/x86/asus-wmi.c
51216@@ -1592,6 +1592,10 @@ static int show_dsts(struct seq_file *m, void *data)
51217 int err;
51218 u32 retval = -1;
51219
51220+#ifdef CONFIG_GRKERNSEC_KMEM
51221+ return -EPERM;
51222+#endif
51223+
51224 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
51225
51226 if (err < 0)
51227@@ -1608,6 +1612,10 @@ static int show_devs(struct seq_file *m, void *data)
51228 int err;
51229 u32 retval = -1;
51230
51231+#ifdef CONFIG_GRKERNSEC_KMEM
51232+ return -EPERM;
51233+#endif
51234+
51235 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
51236 &retval);
51237
51238@@ -1632,6 +1640,10 @@ static int show_call(struct seq_file *m, void *data)
51239 union acpi_object *obj;
51240 acpi_status status;
51241
51242+#ifdef CONFIG_GRKERNSEC_KMEM
51243+ return -EPERM;
51244+#endif
51245+
51246 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
51247 1, asus->debug.method_id,
51248 &input, &output);
51249diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
51250index 62f8030..c7f2a45 100644
51251--- a/drivers/platform/x86/msi-laptop.c
51252+++ b/drivers/platform/x86/msi-laptop.c
51253@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
51254
51255 if (!quirks->ec_read_only) {
51256 /* allow userland write sysfs file */
51257- dev_attr_bluetooth.store = store_bluetooth;
51258- dev_attr_wlan.store = store_wlan;
51259- dev_attr_threeg.store = store_threeg;
51260- dev_attr_bluetooth.attr.mode |= S_IWUSR;
51261- dev_attr_wlan.attr.mode |= S_IWUSR;
51262- dev_attr_threeg.attr.mode |= S_IWUSR;
51263+ pax_open_kernel();
51264+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
51265+ *(void **)&dev_attr_wlan.store = store_wlan;
51266+ *(void **)&dev_attr_threeg.store = store_threeg;
51267+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
51268+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
51269+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
51270+ pax_close_kernel();
51271 }
51272
51273 /* disable hardware control by fn key */
51274diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
51275index 70222f2..8c8ce66 100644
51276--- a/drivers/platform/x86/msi-wmi.c
51277+++ b/drivers/platform/x86/msi-wmi.c
51278@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
51279 static void msi_wmi_notify(u32 value, void *context)
51280 {
51281 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
51282- static struct key_entry *key;
51283+ struct key_entry *key;
51284 union acpi_object *obj;
51285 acpi_status status;
51286
51287diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
51288index 9c5a074..06c976a 100644
51289--- a/drivers/platform/x86/sony-laptop.c
51290+++ b/drivers/platform/x86/sony-laptop.c
51291@@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
51292 }
51293
51294 /* High speed charging function */
51295-static struct device_attribute *hsc_handle;
51296+static device_attribute_no_const *hsc_handle;
51297
51298 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
51299 struct device_attribute *attr,
51300@@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
51301 }
51302
51303 /* low battery function */
51304-static struct device_attribute *lowbatt_handle;
51305+static device_attribute_no_const *lowbatt_handle;
51306
51307 static ssize_t sony_nc_lowbatt_store(struct device *dev,
51308 struct device_attribute *attr,
51309@@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
51310 }
51311
51312 /* fan speed function */
51313-static struct device_attribute *fan_handle, *hsf_handle;
51314+static device_attribute_no_const *fan_handle, *hsf_handle;
51315
51316 static ssize_t sony_nc_hsfan_store(struct device *dev,
51317 struct device_attribute *attr,
51318@@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
51319 }
51320
51321 /* USB charge function */
51322-static struct device_attribute *uc_handle;
51323+static device_attribute_no_const *uc_handle;
51324
51325 static ssize_t sony_nc_usb_charge_store(struct device *dev,
51326 struct device_attribute *attr,
51327@@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
51328 }
51329
51330 /* Panel ID function */
51331-static struct device_attribute *panel_handle;
51332+static device_attribute_no_const *panel_handle;
51333
51334 static ssize_t sony_nc_panelid_show(struct device *dev,
51335 struct device_attribute *attr, char *buffer)
51336@@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
51337 }
51338
51339 /* smart connect function */
51340-static struct device_attribute *sc_handle;
51341+static device_attribute_no_const *sc_handle;
51342
51343 static ssize_t sony_nc_smart_conn_store(struct device *dev,
51344 struct device_attribute *attr,
51345diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
51346index d82f196..5458f34 100644
51347--- a/drivers/platform/x86/thinkpad_acpi.c
51348+++ b/drivers/platform/x86/thinkpad_acpi.c
51349@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
51350 return 0;
51351 }
51352
51353-void static hotkey_mask_warn_incomplete_mask(void)
51354+static void hotkey_mask_warn_incomplete_mask(void)
51355 {
51356 /* log only what the user can fix... */
51357 const u32 wantedmask = hotkey_driver_mask &
51358@@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
51359 && !tp_features.bright_unkfw)
51360 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
51361 }
51362+}
51363
51364 #undef TPACPI_COMPARE_KEY
51365 #undef TPACPI_MAY_SEND_KEY
51366-}
51367
51368 /*
51369 * Polling driver
51370diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
51371index 438d4c7..ca8a2fb 100644
51372--- a/drivers/pnp/pnpbios/bioscalls.c
51373+++ b/drivers/pnp/pnpbios/bioscalls.c
51374@@ -59,7 +59,7 @@ do { \
51375 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
51376 } while(0)
51377
51378-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
51379+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
51380 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
51381
51382 /*
51383@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
51384
51385 cpu = get_cpu();
51386 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
51387+
51388+ pax_open_kernel();
51389 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
51390+ pax_close_kernel();
51391
51392 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
51393 spin_lock_irqsave(&pnp_bios_lock, flags);
51394@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
51395 :"memory");
51396 spin_unlock_irqrestore(&pnp_bios_lock, flags);
51397
51398+ pax_open_kernel();
51399 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
51400+ pax_close_kernel();
51401+
51402 put_cpu();
51403
51404 /* If we get here and this is set then the PnP BIOS faulted on us. */
51405@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
51406 return status;
51407 }
51408
51409-void pnpbios_calls_init(union pnp_bios_install_struct *header)
51410+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
51411 {
51412 int i;
51413
51414@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
51415 pnp_bios_callpoint.offset = header->fields.pm16offset;
51416 pnp_bios_callpoint.segment = PNP_CS16;
51417
51418+ pax_open_kernel();
51419+
51420 for_each_possible_cpu(i) {
51421 struct desc_struct *gdt = get_cpu_gdt_table(i);
51422 if (!gdt)
51423@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
51424 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
51425 (unsigned long)__va(header->fields.pm16dseg));
51426 }
51427+
51428+ pax_close_kernel();
51429 }
51430diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
51431index 0c52e2a..3421ab7 100644
51432--- a/drivers/power/pda_power.c
51433+++ b/drivers/power/pda_power.c
51434@@ -37,7 +37,11 @@ static int polling;
51435
51436 #if IS_ENABLED(CONFIG_USB_PHY)
51437 static struct usb_phy *transceiver;
51438-static struct notifier_block otg_nb;
51439+static int otg_handle_notification(struct notifier_block *nb,
51440+ unsigned long event, void *unused);
51441+static struct notifier_block otg_nb = {
51442+ .notifier_call = otg_handle_notification
51443+};
51444 #endif
51445
51446 static struct regulator *ac_draw;
51447@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
51448
51449 #if IS_ENABLED(CONFIG_USB_PHY)
51450 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
51451- otg_nb.notifier_call = otg_handle_notification;
51452 ret = usb_register_notifier(transceiver, &otg_nb);
51453 if (ret) {
51454 dev_err(dev, "failure to register otg notifier\n");
51455diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
51456index cc439fd..8fa30df 100644
51457--- a/drivers/power/power_supply.h
51458+++ b/drivers/power/power_supply.h
51459@@ -16,12 +16,12 @@ struct power_supply;
51460
51461 #ifdef CONFIG_SYSFS
51462
51463-extern void power_supply_init_attrs(struct device_type *dev_type);
51464+extern void power_supply_init_attrs(void);
51465 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
51466
51467 #else
51468
51469-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
51470+static inline void power_supply_init_attrs(void) {}
51471 #define power_supply_uevent NULL
51472
51473 #endif /* CONFIG_SYSFS */
51474diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
51475index 5a5a24e..f7a3754 100644
51476--- a/drivers/power/power_supply_core.c
51477+++ b/drivers/power/power_supply_core.c
51478@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
51479 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
51480 EXPORT_SYMBOL_GPL(power_supply_notifier);
51481
51482-static struct device_type power_supply_dev_type;
51483+extern const struct attribute_group *power_supply_attr_groups[];
51484+static struct device_type power_supply_dev_type = {
51485+ .groups = power_supply_attr_groups,
51486+};
51487
51488 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
51489 struct power_supply *supply)
51490@@ -639,7 +642,7 @@ static int __init power_supply_class_init(void)
51491 return PTR_ERR(power_supply_class);
51492
51493 power_supply_class->dev_uevent = power_supply_uevent;
51494- power_supply_init_attrs(&power_supply_dev_type);
51495+ power_supply_init_attrs();
51496
51497 return 0;
51498 }
51499diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
51500index 44420d1..967126e 100644
51501--- a/drivers/power/power_supply_sysfs.c
51502+++ b/drivers/power/power_supply_sysfs.c
51503@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
51504 .is_visible = power_supply_attr_is_visible,
51505 };
51506
51507-static const struct attribute_group *power_supply_attr_groups[] = {
51508+const struct attribute_group *power_supply_attr_groups[] = {
51509 &power_supply_attr_group,
51510 NULL,
51511 };
51512
51513-void power_supply_init_attrs(struct device_type *dev_type)
51514+void power_supply_init_attrs(void)
51515 {
51516 int i;
51517
51518- dev_type->groups = power_supply_attr_groups;
51519-
51520 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
51521 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
51522 }
51523diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
51524index 84419af..268ede8 100644
51525--- a/drivers/powercap/powercap_sys.c
51526+++ b/drivers/powercap/powercap_sys.c
51527@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
51528 struct device_attribute name_attr;
51529 };
51530
51531+static ssize_t show_constraint_name(struct device *dev,
51532+ struct device_attribute *dev_attr,
51533+ char *buf);
51534+
51535 static struct powercap_constraint_attr
51536- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
51537+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
51538+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
51539+ .power_limit_attr = {
51540+ .attr = {
51541+ .name = NULL,
51542+ .mode = S_IWUSR | S_IRUGO
51543+ },
51544+ .show = show_constraint_power_limit_uw,
51545+ .store = store_constraint_power_limit_uw
51546+ },
51547+
51548+ .time_window_attr = {
51549+ .attr = {
51550+ .name = NULL,
51551+ .mode = S_IWUSR | S_IRUGO
51552+ },
51553+ .show = show_constraint_time_window_us,
51554+ .store = store_constraint_time_window_us
51555+ },
51556+
51557+ .max_power_attr = {
51558+ .attr = {
51559+ .name = NULL,
51560+ .mode = S_IRUGO
51561+ },
51562+ .show = show_constraint_max_power_uw,
51563+ .store = NULL
51564+ },
51565+
51566+ .min_power_attr = {
51567+ .attr = {
51568+ .name = NULL,
51569+ .mode = S_IRUGO
51570+ },
51571+ .show = show_constraint_min_power_uw,
51572+ .store = NULL
51573+ },
51574+
51575+ .max_time_window_attr = {
51576+ .attr = {
51577+ .name = NULL,
51578+ .mode = S_IRUGO
51579+ },
51580+ .show = show_constraint_max_time_window_us,
51581+ .store = NULL
51582+ },
51583+
51584+ .min_time_window_attr = {
51585+ .attr = {
51586+ .name = NULL,
51587+ .mode = S_IRUGO
51588+ },
51589+ .show = show_constraint_min_time_window_us,
51590+ .store = NULL
51591+ },
51592+
51593+ .name_attr = {
51594+ .attr = {
51595+ .name = NULL,
51596+ .mode = S_IRUGO
51597+ },
51598+ .show = show_constraint_name,
51599+ .store = NULL
51600+ }
51601+ }
51602+};
51603
51604 /* A list of powercap control_types */
51605 static LIST_HEAD(powercap_cntrl_list);
51606@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
51607 }
51608
51609 static int create_constraint_attribute(int id, const char *name,
51610- int mode,
51611- struct device_attribute *dev_attr,
51612- ssize_t (*show)(struct device *,
51613- struct device_attribute *, char *),
51614- ssize_t (*store)(struct device *,
51615- struct device_attribute *,
51616- const char *, size_t)
51617- )
51618+ struct device_attribute *dev_attr)
51619 {
51620+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
51621
51622- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
51623- id, name);
51624- if (!dev_attr->attr.name)
51625+ if (!name)
51626 return -ENOMEM;
51627- dev_attr->attr.mode = mode;
51628- dev_attr->show = show;
51629- dev_attr->store = store;
51630+
51631+ pax_open_kernel();
51632+ *(const char **)&dev_attr->attr.name = name;
51633+ pax_close_kernel();
51634
51635 return 0;
51636 }
51637@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
51638
51639 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
51640 ret = create_constraint_attribute(i, "power_limit_uw",
51641- S_IWUSR | S_IRUGO,
51642- &constraint_attrs[i].power_limit_attr,
51643- show_constraint_power_limit_uw,
51644- store_constraint_power_limit_uw);
51645+ &constraint_attrs[i].power_limit_attr);
51646 if (ret)
51647 goto err_alloc;
51648 ret = create_constraint_attribute(i, "time_window_us",
51649- S_IWUSR | S_IRUGO,
51650- &constraint_attrs[i].time_window_attr,
51651- show_constraint_time_window_us,
51652- store_constraint_time_window_us);
51653+ &constraint_attrs[i].time_window_attr);
51654 if (ret)
51655 goto err_alloc;
51656- ret = create_constraint_attribute(i, "name", S_IRUGO,
51657- &constraint_attrs[i].name_attr,
51658- show_constraint_name,
51659- NULL);
51660+ ret = create_constraint_attribute(i, "name",
51661+ &constraint_attrs[i].name_attr);
51662 if (ret)
51663 goto err_alloc;
51664- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
51665- &constraint_attrs[i].max_power_attr,
51666- show_constraint_max_power_uw,
51667- NULL);
51668+ ret = create_constraint_attribute(i, "max_power_uw",
51669+ &constraint_attrs[i].max_power_attr);
51670 if (ret)
51671 goto err_alloc;
51672- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
51673- &constraint_attrs[i].min_power_attr,
51674- show_constraint_min_power_uw,
51675- NULL);
51676+ ret = create_constraint_attribute(i, "min_power_uw",
51677+ &constraint_attrs[i].min_power_attr);
51678 if (ret)
51679 goto err_alloc;
51680 ret = create_constraint_attribute(i, "max_time_window_us",
51681- S_IRUGO,
51682- &constraint_attrs[i].max_time_window_attr,
51683- show_constraint_max_time_window_us,
51684- NULL);
51685+ &constraint_attrs[i].max_time_window_attr);
51686 if (ret)
51687 goto err_alloc;
51688 ret = create_constraint_attribute(i, "min_time_window_us",
51689- S_IRUGO,
51690- &constraint_attrs[i].min_time_window_attr,
51691- show_constraint_min_time_window_us,
51692- NULL);
51693+ &constraint_attrs[i].min_time_window_attr);
51694 if (ret)
51695 goto err_alloc;
51696
51697@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
51698 power_zone->zone_dev_attrs[count++] =
51699 &dev_attr_max_energy_range_uj.attr;
51700 if (power_zone->ops->get_energy_uj) {
51701+ pax_open_kernel();
51702 if (power_zone->ops->reset_energy_uj)
51703- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51704+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51705 else
51706- dev_attr_energy_uj.attr.mode = S_IRUGO;
51707+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
51708+ pax_close_kernel();
51709 power_zone->zone_dev_attrs[count++] =
51710 &dev_attr_energy_uj.attr;
51711 }
51712diff --git a/drivers/ptp/Kconfig b/drivers/ptp/Kconfig
51713index ee3de34..bec7285 100644
51714--- a/drivers/ptp/Kconfig
51715+++ b/drivers/ptp/Kconfig
51716@@ -8,7 +8,6 @@ config PTP_1588_CLOCK
51717 tristate "PTP clock support"
51718 depends on NET
51719 select PPS
51720- select NET_PTP_CLASSIFY
51721 help
51722 The IEEE 1588 standard defines a method to precisely
51723 synchronize distributed clocks over Ethernet networks. The
51724diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
51725index 9c5d414..c7900ce 100644
51726--- a/drivers/ptp/ptp_private.h
51727+++ b/drivers/ptp/ptp_private.h
51728@@ -51,7 +51,7 @@ struct ptp_clock {
51729 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
51730 wait_queue_head_t tsev_wq;
51731 int defunct; /* tells readers to go away when clock is being removed */
51732- struct device_attribute *pin_dev_attr;
51733+ device_attribute_no_const *pin_dev_attr;
51734 struct attribute **pin_attr;
51735 struct attribute_group pin_attr_group;
51736 };
51737diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
51738index 302e626..12579af 100644
51739--- a/drivers/ptp/ptp_sysfs.c
51740+++ b/drivers/ptp/ptp_sysfs.c
51741@@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
51742 goto no_pin_attr;
51743
51744 for (i = 0; i < n_pins; i++) {
51745- struct device_attribute *da = &ptp->pin_dev_attr[i];
51746+ device_attribute_no_const *da = &ptp->pin_dev_attr[i];
51747 sysfs_attr_init(&da->attr);
51748 da->attr.name = info->pin_config[i].name;
51749 da->attr.mode = 0644;
51750diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
51751index 4c1f999..11078c9 100644
51752--- a/drivers/regulator/core.c
51753+++ b/drivers/regulator/core.c
51754@@ -3391,7 +3391,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51755 {
51756 const struct regulation_constraints *constraints = NULL;
51757 const struct regulator_init_data *init_data;
51758- static atomic_t regulator_no = ATOMIC_INIT(0);
51759+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
51760 struct regulator_dev *rdev;
51761 struct device *dev;
51762 int ret, i;
51763@@ -3461,7 +3461,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51764 rdev->dev.of_node = of_node_get(config->of_node);
51765 rdev->dev.parent = dev;
51766 dev_set_name(&rdev->dev, "regulator.%d",
51767- atomic_inc_return(&regulator_no) - 1);
51768+ atomic_inc_return_unchecked(&regulator_no) - 1);
51769 ret = device_register(&rdev->dev);
51770 if (ret != 0) {
51771 put_device(&rdev->dev);
51772diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
51773index 2fc4111..6aa88ca 100644
51774--- a/drivers/regulator/max8660.c
51775+++ b/drivers/regulator/max8660.c
51776@@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
51777 max8660->shadow_regs[MAX8660_OVER1] = 5;
51778 } else {
51779 /* Otherwise devices can be toggled via software */
51780- max8660_dcdc_ops.enable = max8660_dcdc_enable;
51781- max8660_dcdc_ops.disable = max8660_dcdc_disable;
51782+ pax_open_kernel();
51783+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
51784+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
51785+ pax_close_kernel();
51786 }
51787
51788 /*
51789diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
51790index dbedf17..18ff6b7 100644
51791--- a/drivers/regulator/max8973-regulator.c
51792+++ b/drivers/regulator/max8973-regulator.c
51793@@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
51794 if (!pdata || !pdata->enable_ext_control) {
51795 max->desc.enable_reg = MAX8973_VOUT;
51796 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
51797- max->ops.enable = regulator_enable_regmap;
51798- max->ops.disable = regulator_disable_regmap;
51799- max->ops.is_enabled = regulator_is_enabled_regmap;
51800+ pax_open_kernel();
51801+ *(void **)&max->ops.enable = regulator_enable_regmap;
51802+ *(void **)&max->ops.disable = regulator_disable_regmap;
51803+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
51804+ pax_close_kernel();
51805 }
51806
51807 if (pdata) {
51808diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
51809index f374fa5..26f0683 100644
51810--- a/drivers/regulator/mc13892-regulator.c
51811+++ b/drivers/regulator/mc13892-regulator.c
51812@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
51813 }
51814 mc13xxx_unlock(mc13892);
51815
51816- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51817+ pax_open_kernel();
51818+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51819 = mc13892_vcam_set_mode;
51820- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51821+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51822 = mc13892_vcam_get_mode;
51823+ pax_close_kernel();
51824
51825 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
51826 ARRAY_SIZE(mc13892_regulators));
51827diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
51828index b0e4a3e..e5dc11e 100644
51829--- a/drivers/rtc/rtc-cmos.c
51830+++ b/drivers/rtc/rtc-cmos.c
51831@@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
51832 hpet_rtc_timer_init();
51833
51834 /* export at least the first block of NVRAM */
51835- nvram.size = address_space - NVRAM_OFFSET;
51836+ pax_open_kernel();
51837+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
51838+ pax_close_kernel();
51839 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
51840 if (retval < 0) {
51841 dev_dbg(dev, "can't create nvram file? %d\n", retval);
51842diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
51843index d049393..bb20be0 100644
51844--- a/drivers/rtc/rtc-dev.c
51845+++ b/drivers/rtc/rtc-dev.c
51846@@ -16,6 +16,7 @@
51847 #include <linux/module.h>
51848 #include <linux/rtc.h>
51849 #include <linux/sched.h>
51850+#include <linux/grsecurity.h>
51851 #include "rtc-core.h"
51852
51853 static dev_t rtc_devt;
51854@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
51855 if (copy_from_user(&tm, uarg, sizeof(tm)))
51856 return -EFAULT;
51857
51858+ gr_log_timechange();
51859+
51860 return rtc_set_time(rtc, &tm);
51861
51862 case RTC_PIE_ON:
51863diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
51864index f03d5ba..8325bf6 100644
51865--- a/drivers/rtc/rtc-ds1307.c
51866+++ b/drivers/rtc/rtc-ds1307.c
51867@@ -107,7 +107,7 @@ struct ds1307 {
51868 u8 offset; /* register's offset */
51869 u8 regs[11];
51870 u16 nvram_offset;
51871- struct bin_attribute *nvram;
51872+ bin_attribute_no_const *nvram;
51873 enum ds_type type;
51874 unsigned long flags;
51875 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
51876diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
51877index 11880c1..b823aa4 100644
51878--- a/drivers/rtc/rtc-m48t59.c
51879+++ b/drivers/rtc/rtc-m48t59.c
51880@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
51881 if (IS_ERR(m48t59->rtc))
51882 return PTR_ERR(m48t59->rtc);
51883
51884- m48t59_nvram_attr.size = pdata->offset;
51885+ pax_open_kernel();
51886+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
51887+ pax_close_kernel();
51888
51889 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
51890 if (ret)
51891diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
51892index e693af6..2e525b6 100644
51893--- a/drivers/scsi/bfa/bfa_fcpim.h
51894+++ b/drivers/scsi/bfa/bfa_fcpim.h
51895@@ -36,7 +36,7 @@ struct bfa_iotag_s {
51896
51897 struct bfa_itn_s {
51898 bfa_isr_func_t isr;
51899-};
51900+} __no_const;
51901
51902 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
51903 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
51904diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
51905index a3ab5cc..8143622 100644
51906--- a/drivers/scsi/bfa/bfa_fcs.c
51907+++ b/drivers/scsi/bfa/bfa_fcs.c
51908@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
51909 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
51910
51911 static struct bfa_fcs_mod_s fcs_modules[] = {
51912- { bfa_fcs_port_attach, NULL, NULL },
51913- { bfa_fcs_uf_attach, NULL, NULL },
51914- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
51915- bfa_fcs_fabric_modexit },
51916+ {
51917+ .attach = bfa_fcs_port_attach,
51918+ .modinit = NULL,
51919+ .modexit = NULL
51920+ },
51921+ {
51922+ .attach = bfa_fcs_uf_attach,
51923+ .modinit = NULL,
51924+ .modexit = NULL
51925+ },
51926+ {
51927+ .attach = bfa_fcs_fabric_attach,
51928+ .modinit = bfa_fcs_fabric_modinit,
51929+ .modexit = bfa_fcs_fabric_modexit
51930+ },
51931 };
51932
51933 /*
51934diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
51935index ff75ef8..2dfe00a 100644
51936--- a/drivers/scsi/bfa/bfa_fcs_lport.c
51937+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
51938@@ -89,15 +89,26 @@ static struct {
51939 void (*offline) (struct bfa_fcs_lport_s *port);
51940 } __port_action[] = {
51941 {
51942- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
51943- bfa_fcs_lport_unknown_offline}, {
51944- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
51945- bfa_fcs_lport_fab_offline}, {
51946- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
51947- bfa_fcs_lport_n2n_offline}, {
51948- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
51949- bfa_fcs_lport_loop_offline},
51950- };
51951+ .init = bfa_fcs_lport_unknown_init,
51952+ .online = bfa_fcs_lport_unknown_online,
51953+ .offline = bfa_fcs_lport_unknown_offline
51954+ },
51955+ {
51956+ .init = bfa_fcs_lport_fab_init,
51957+ .online = bfa_fcs_lport_fab_online,
51958+ .offline = bfa_fcs_lport_fab_offline
51959+ },
51960+ {
51961+ .init = bfa_fcs_lport_n2n_init,
51962+ .online = bfa_fcs_lport_n2n_online,
51963+ .offline = bfa_fcs_lport_n2n_offline
51964+ },
51965+ {
51966+ .init = bfa_fcs_lport_loop_init,
51967+ .online = bfa_fcs_lport_loop_online,
51968+ .offline = bfa_fcs_lport_loop_offline
51969+ },
51970+};
51971
51972 /*
51973 * fcs_port_sm FCS logical port state machine
51974diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
51975index 2e28392..9d865b6 100644
51976--- a/drivers/scsi/bfa/bfa_ioc.h
51977+++ b/drivers/scsi/bfa/bfa_ioc.h
51978@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
51979 bfa_ioc_disable_cbfn_t disable_cbfn;
51980 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
51981 bfa_ioc_reset_cbfn_t reset_cbfn;
51982-};
51983+} __no_const;
51984
51985 /*
51986 * IOC event notification mechanism.
51987@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
51988 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
51989 enum bfi_ioc_state fwstate);
51990 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
51991-};
51992+} __no_const;
51993
51994 /*
51995 * Queue element to wait for room in request queue. FIFO order is
51996diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
51997index a14c784..6de6790 100644
51998--- a/drivers/scsi/bfa/bfa_modules.h
51999+++ b/drivers/scsi/bfa/bfa_modules.h
52000@@ -78,12 +78,12 @@ enum {
52001 \
52002 extern struct bfa_module_s hal_mod_ ## __mod; \
52003 struct bfa_module_s hal_mod_ ## __mod = { \
52004- bfa_ ## __mod ## _meminfo, \
52005- bfa_ ## __mod ## _attach, \
52006- bfa_ ## __mod ## _detach, \
52007- bfa_ ## __mod ## _start, \
52008- bfa_ ## __mod ## _stop, \
52009- bfa_ ## __mod ## _iocdisable, \
52010+ .meminfo = bfa_ ## __mod ## _meminfo, \
52011+ .attach = bfa_ ## __mod ## _attach, \
52012+ .detach = bfa_ ## __mod ## _detach, \
52013+ .start = bfa_ ## __mod ## _start, \
52014+ .stop = bfa_ ## __mod ## _stop, \
52015+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
52016 }
52017
52018 #define BFA_CACHELINE_SZ (256)
52019diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
52020index 045c4e1..13de803 100644
52021--- a/drivers/scsi/fcoe/fcoe_sysfs.c
52022+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
52023@@ -33,8 +33,8 @@
52024 */
52025 #include "libfcoe.h"
52026
52027-static atomic_t ctlr_num;
52028-static atomic_t fcf_num;
52029+static atomic_unchecked_t ctlr_num;
52030+static atomic_unchecked_t fcf_num;
52031
52032 /*
52033 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
52034@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
52035 if (!ctlr)
52036 goto out;
52037
52038- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
52039+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
52040 ctlr->f = f;
52041 ctlr->mode = FIP_CONN_TYPE_FABRIC;
52042 INIT_LIST_HEAD(&ctlr->fcfs);
52043@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
52044 fcf->dev.parent = &ctlr->dev;
52045 fcf->dev.bus = &fcoe_bus_type;
52046 fcf->dev.type = &fcoe_fcf_device_type;
52047- fcf->id = atomic_inc_return(&fcf_num) - 1;
52048+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
52049 fcf->state = FCOE_FCF_STATE_UNKNOWN;
52050
52051 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
52052@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
52053 {
52054 int error;
52055
52056- atomic_set(&ctlr_num, 0);
52057- atomic_set(&fcf_num, 0);
52058+ atomic_set_unchecked(&ctlr_num, 0);
52059+ atomic_set_unchecked(&fcf_num, 0);
52060
52061 error = bus_register(&fcoe_bus_type);
52062 if (error)
52063diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
52064index 3cbb57a..95e47a3 100644
52065--- a/drivers/scsi/hosts.c
52066+++ b/drivers/scsi/hosts.c
52067@@ -42,7 +42,7 @@
52068 #include "scsi_logging.h"
52069
52070
52071-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
52072+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
52073
52074
52075 static void scsi_host_cls_release(struct device *dev)
52076@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
52077 * subtract one because we increment first then return, but we need to
52078 * know what the next host number was before increment
52079 */
52080- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
52081+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
52082 shost->dma_channel = 0xff;
52083
52084 /* These three are default values which can be overridden */
52085diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
52086index 31184b3..cc44bbf 100644
52087--- a/drivers/scsi/hpsa.c
52088+++ b/drivers/scsi/hpsa.c
52089@@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
52090 unsigned long flags;
52091
52092 if (h->transMethod & CFGTBL_Trans_io_accel1)
52093- return h->access.command_completed(h, q);
52094+ return h->access->command_completed(h, q);
52095
52096 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
52097- return h->access.command_completed(h, q);
52098+ return h->access->command_completed(h, q);
52099
52100 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
52101 a = rq->head[rq->current_entry];
52102@@ -5455,7 +5455,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
52103 while (!list_empty(&h->reqQ)) {
52104 c = list_entry(h->reqQ.next, struct CommandList, list);
52105 /* can't do anything if fifo is full */
52106- if ((h->access.fifo_full(h))) {
52107+ if ((h->access->fifo_full(h))) {
52108 h->fifo_recently_full = 1;
52109 dev_warn(&h->pdev->dev, "fifo full\n");
52110 break;
52111@@ -5477,7 +5477,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
52112
52113 /* Tell the controller execute command */
52114 spin_unlock_irqrestore(&h->lock, *flags);
52115- h->access.submit_command(h, c);
52116+ h->access->submit_command(h, c);
52117 spin_lock_irqsave(&h->lock, *flags);
52118 }
52119 }
52120@@ -5493,17 +5493,17 @@ static void lock_and_start_io(struct ctlr_info *h)
52121
52122 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
52123 {
52124- return h->access.command_completed(h, q);
52125+ return h->access->command_completed(h, q);
52126 }
52127
52128 static inline bool interrupt_pending(struct ctlr_info *h)
52129 {
52130- return h->access.intr_pending(h);
52131+ return h->access->intr_pending(h);
52132 }
52133
52134 static inline long interrupt_not_for_us(struct ctlr_info *h)
52135 {
52136- return (h->access.intr_pending(h) == 0) ||
52137+ return (h->access->intr_pending(h) == 0) ||
52138 (h->interrupts_enabled == 0);
52139 }
52140
52141@@ -6459,7 +6459,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
52142 if (prod_index < 0)
52143 return -ENODEV;
52144 h->product_name = products[prod_index].product_name;
52145- h->access = *(products[prod_index].access);
52146+ h->access = products[prod_index].access;
52147
52148 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
52149 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
52150@@ -6781,7 +6781,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
52151 unsigned long flags;
52152 u32 lockup_detected;
52153
52154- h->access.set_intr_mask(h, HPSA_INTR_OFF);
52155+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
52156 spin_lock_irqsave(&h->lock, flags);
52157 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
52158 if (!lockup_detected) {
52159@@ -7022,7 +7022,7 @@ reinit_after_soft_reset:
52160 }
52161
52162 /* make sure the board interrupts are off */
52163- h->access.set_intr_mask(h, HPSA_INTR_OFF);
52164+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
52165
52166 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
52167 goto clean2;
52168@@ -7057,7 +7057,7 @@ reinit_after_soft_reset:
52169 * fake ones to scoop up any residual completions.
52170 */
52171 spin_lock_irqsave(&h->lock, flags);
52172- h->access.set_intr_mask(h, HPSA_INTR_OFF);
52173+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
52174 spin_unlock_irqrestore(&h->lock, flags);
52175 free_irqs(h);
52176 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
52177@@ -7076,9 +7076,9 @@ reinit_after_soft_reset:
52178 dev_info(&h->pdev->dev, "Board READY.\n");
52179 dev_info(&h->pdev->dev,
52180 "Waiting for stale completions to drain.\n");
52181- h->access.set_intr_mask(h, HPSA_INTR_ON);
52182+ h->access->set_intr_mask(h, HPSA_INTR_ON);
52183 msleep(10000);
52184- h->access.set_intr_mask(h, HPSA_INTR_OFF);
52185+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
52186
52187 rc = controller_reset_failed(h->cfgtable);
52188 if (rc)
52189@@ -7104,7 +7104,7 @@ reinit_after_soft_reset:
52190 h->drv_req_rescan = 0;
52191
52192 /* Turn the interrupts on so we can service requests */
52193- h->access.set_intr_mask(h, HPSA_INTR_ON);
52194+ h->access->set_intr_mask(h, HPSA_INTR_ON);
52195
52196 hpsa_hba_inquiry(h);
52197 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
52198@@ -7169,7 +7169,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
52199 * To write all data in the battery backed cache to disks
52200 */
52201 hpsa_flush_cache(h);
52202- h->access.set_intr_mask(h, HPSA_INTR_OFF);
52203+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
52204 hpsa_free_irqs_and_disable_msix(h);
52205 }
52206
52207@@ -7287,7 +7287,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52208 CFGTBL_Trans_enable_directed_msix |
52209 (trans_support & (CFGTBL_Trans_io_accel1 |
52210 CFGTBL_Trans_io_accel2));
52211- struct access_method access = SA5_performant_access;
52212+ struct access_method *access = &SA5_performant_access;
52213
52214 /* This is a bit complicated. There are 8 registers on
52215 * the controller which we write to to tell it 8 different
52216@@ -7329,7 +7329,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52217 * perform the superfluous readl() after each command submission.
52218 */
52219 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
52220- access = SA5_performant_access_no_read;
52221+ access = &SA5_performant_access_no_read;
52222
52223 /* Controller spec: zero out this buffer. */
52224 for (i = 0; i < h->nreply_queues; i++)
52225@@ -7359,12 +7359,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52226 * enable outbound interrupt coalescing in accelerator mode;
52227 */
52228 if (trans_support & CFGTBL_Trans_io_accel1) {
52229- access = SA5_ioaccel_mode1_access;
52230+ access = &SA5_ioaccel_mode1_access;
52231 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
52232 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
52233 } else {
52234 if (trans_support & CFGTBL_Trans_io_accel2) {
52235- access = SA5_ioaccel_mode2_access;
52236+ access = &SA5_ioaccel_mode2_access;
52237 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
52238 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
52239 }
52240diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
52241index 24472ce..8782caf 100644
52242--- a/drivers/scsi/hpsa.h
52243+++ b/drivers/scsi/hpsa.h
52244@@ -127,7 +127,7 @@ struct ctlr_info {
52245 unsigned int msix_vector;
52246 unsigned int msi_vector;
52247 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
52248- struct access_method access;
52249+ struct access_method *access;
52250 char hba_mode_enabled;
52251
52252 /* queue and queue Info */
52253@@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
52254 }
52255
52256 static struct access_method SA5_access = {
52257- SA5_submit_command,
52258- SA5_intr_mask,
52259- SA5_fifo_full,
52260- SA5_intr_pending,
52261- SA5_completed,
52262+ .submit_command = SA5_submit_command,
52263+ .set_intr_mask = SA5_intr_mask,
52264+ .fifo_full = SA5_fifo_full,
52265+ .intr_pending = SA5_intr_pending,
52266+ .command_completed = SA5_completed,
52267 };
52268
52269 static struct access_method SA5_ioaccel_mode1_access = {
52270- SA5_submit_command,
52271- SA5_performant_intr_mask,
52272- SA5_fifo_full,
52273- SA5_ioaccel_mode1_intr_pending,
52274- SA5_ioaccel_mode1_completed,
52275+ .submit_command = SA5_submit_command,
52276+ .set_intr_mask = SA5_performant_intr_mask,
52277+ .fifo_full = SA5_fifo_full,
52278+ .intr_pending = SA5_ioaccel_mode1_intr_pending,
52279+ .command_completed = SA5_ioaccel_mode1_completed,
52280 };
52281
52282 static struct access_method SA5_ioaccel_mode2_access = {
52283- SA5_submit_command_ioaccel2,
52284- SA5_performant_intr_mask,
52285- SA5_fifo_full,
52286- SA5_performant_intr_pending,
52287- SA5_performant_completed,
52288+ .submit_command = SA5_submit_command_ioaccel2,
52289+ .set_intr_mask = SA5_performant_intr_mask,
52290+ .fifo_full = SA5_fifo_full,
52291+ .intr_pending = SA5_performant_intr_pending,
52292+ .command_completed = SA5_performant_completed,
52293 };
52294
52295 static struct access_method SA5_performant_access = {
52296- SA5_submit_command,
52297- SA5_performant_intr_mask,
52298- SA5_fifo_full,
52299- SA5_performant_intr_pending,
52300- SA5_performant_completed,
52301+ .submit_command = SA5_submit_command,
52302+ .set_intr_mask = SA5_performant_intr_mask,
52303+ .fifo_full = SA5_fifo_full,
52304+ .intr_pending = SA5_performant_intr_pending,
52305+ .command_completed = SA5_performant_completed,
52306 };
52307
52308 static struct access_method SA5_performant_access_no_read = {
52309- SA5_submit_command_no_read,
52310- SA5_performant_intr_mask,
52311- SA5_fifo_full,
52312- SA5_performant_intr_pending,
52313- SA5_performant_completed,
52314+ .submit_command = SA5_submit_command_no_read,
52315+ .set_intr_mask = SA5_performant_intr_mask,
52316+ .fifo_full = SA5_fifo_full,
52317+ .intr_pending = SA5_performant_intr_pending,
52318+ .command_completed = SA5_performant_completed,
52319 };
52320
52321 struct board_type {
52322diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
52323index 1b3a094..068e683 100644
52324--- a/drivers/scsi/libfc/fc_exch.c
52325+++ b/drivers/scsi/libfc/fc_exch.c
52326@@ -101,12 +101,12 @@ struct fc_exch_mgr {
52327 u16 pool_max_index;
52328
52329 struct {
52330- atomic_t no_free_exch;
52331- atomic_t no_free_exch_xid;
52332- atomic_t xid_not_found;
52333- atomic_t xid_busy;
52334- atomic_t seq_not_found;
52335- atomic_t non_bls_resp;
52336+ atomic_unchecked_t no_free_exch;
52337+ atomic_unchecked_t no_free_exch_xid;
52338+ atomic_unchecked_t xid_not_found;
52339+ atomic_unchecked_t xid_busy;
52340+ atomic_unchecked_t seq_not_found;
52341+ atomic_unchecked_t non_bls_resp;
52342 } stats;
52343 };
52344
52345@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
52346 /* allocate memory for exchange */
52347 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
52348 if (!ep) {
52349- atomic_inc(&mp->stats.no_free_exch);
52350+ atomic_inc_unchecked(&mp->stats.no_free_exch);
52351 goto out;
52352 }
52353 memset(ep, 0, sizeof(*ep));
52354@@ -874,7 +874,7 @@ out:
52355 return ep;
52356 err:
52357 spin_unlock_bh(&pool->lock);
52358- atomic_inc(&mp->stats.no_free_exch_xid);
52359+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
52360 mempool_free(ep, mp->ep_pool);
52361 return NULL;
52362 }
52363@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52364 xid = ntohs(fh->fh_ox_id); /* we originated exch */
52365 ep = fc_exch_find(mp, xid);
52366 if (!ep) {
52367- atomic_inc(&mp->stats.xid_not_found);
52368+ atomic_inc_unchecked(&mp->stats.xid_not_found);
52369 reject = FC_RJT_OX_ID;
52370 goto out;
52371 }
52372@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52373 ep = fc_exch_find(mp, xid);
52374 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
52375 if (ep) {
52376- atomic_inc(&mp->stats.xid_busy);
52377+ atomic_inc_unchecked(&mp->stats.xid_busy);
52378 reject = FC_RJT_RX_ID;
52379 goto rel;
52380 }
52381@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52382 }
52383 xid = ep->xid; /* get our XID */
52384 } else if (!ep) {
52385- atomic_inc(&mp->stats.xid_not_found);
52386+ atomic_inc_unchecked(&mp->stats.xid_not_found);
52387 reject = FC_RJT_RX_ID; /* XID not found */
52388 goto out;
52389 }
52390@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52391 } else {
52392 sp = &ep->seq;
52393 if (sp->id != fh->fh_seq_id) {
52394- atomic_inc(&mp->stats.seq_not_found);
52395+ atomic_inc_unchecked(&mp->stats.seq_not_found);
52396 if (f_ctl & FC_FC_END_SEQ) {
52397 /*
52398 * Update sequence_id based on incoming last
52399@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52400
52401 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
52402 if (!ep) {
52403- atomic_inc(&mp->stats.xid_not_found);
52404+ atomic_inc_unchecked(&mp->stats.xid_not_found);
52405 goto out;
52406 }
52407 if (ep->esb_stat & ESB_ST_COMPLETE) {
52408- atomic_inc(&mp->stats.xid_not_found);
52409+ atomic_inc_unchecked(&mp->stats.xid_not_found);
52410 goto rel;
52411 }
52412 if (ep->rxid == FC_XID_UNKNOWN)
52413 ep->rxid = ntohs(fh->fh_rx_id);
52414 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
52415- atomic_inc(&mp->stats.xid_not_found);
52416+ atomic_inc_unchecked(&mp->stats.xid_not_found);
52417 goto rel;
52418 }
52419 if (ep->did != ntoh24(fh->fh_s_id) &&
52420 ep->did != FC_FID_FLOGI) {
52421- atomic_inc(&mp->stats.xid_not_found);
52422+ atomic_inc_unchecked(&mp->stats.xid_not_found);
52423 goto rel;
52424 }
52425 sof = fr_sof(fp);
52426@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52427 sp->ssb_stat |= SSB_ST_RESP;
52428 sp->id = fh->fh_seq_id;
52429 } else if (sp->id != fh->fh_seq_id) {
52430- atomic_inc(&mp->stats.seq_not_found);
52431+ atomic_inc_unchecked(&mp->stats.seq_not_found);
52432 goto rel;
52433 }
52434
52435@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52436 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
52437
52438 if (!sp)
52439- atomic_inc(&mp->stats.xid_not_found);
52440+ atomic_inc_unchecked(&mp->stats.xid_not_found);
52441 else
52442- atomic_inc(&mp->stats.non_bls_resp);
52443+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
52444
52445 fc_frame_free(fp);
52446 }
52447@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
52448
52449 list_for_each_entry(ema, &lport->ema_list, ema_list) {
52450 mp = ema->mp;
52451- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
52452+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
52453 st->fc_no_free_exch_xid +=
52454- atomic_read(&mp->stats.no_free_exch_xid);
52455- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
52456- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
52457- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
52458- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
52459+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
52460+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
52461+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
52462+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
52463+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
52464 }
52465 }
52466 EXPORT_SYMBOL(fc_exch_update_stats);
52467diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
52468index 766098a..1c6c971 100644
52469--- a/drivers/scsi/libsas/sas_ata.c
52470+++ b/drivers/scsi/libsas/sas_ata.c
52471@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
52472 .postreset = ata_std_postreset,
52473 .error_handler = ata_std_error_handler,
52474 .post_internal_cmd = sas_ata_post_internal,
52475- .qc_defer = ata_std_qc_defer,
52476+ .qc_defer = ata_std_qc_defer,
52477 .qc_prep = ata_noop_qc_prep,
52478 .qc_issue = sas_ata_qc_issue,
52479 .qc_fill_rtf = sas_ata_qc_fill_rtf,
52480diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
52481index 434e903..5a4a79b 100644
52482--- a/drivers/scsi/lpfc/lpfc.h
52483+++ b/drivers/scsi/lpfc/lpfc.h
52484@@ -430,7 +430,7 @@ struct lpfc_vport {
52485 struct dentry *debug_nodelist;
52486 struct dentry *vport_debugfs_root;
52487 struct lpfc_debugfs_trc *disc_trc;
52488- atomic_t disc_trc_cnt;
52489+ atomic_unchecked_t disc_trc_cnt;
52490 #endif
52491 uint8_t stat_data_enabled;
52492 uint8_t stat_data_blocked;
52493@@ -880,8 +880,8 @@ struct lpfc_hba {
52494 struct timer_list fabric_block_timer;
52495 unsigned long bit_flags;
52496 #define FABRIC_COMANDS_BLOCKED 0
52497- atomic_t num_rsrc_err;
52498- atomic_t num_cmd_success;
52499+ atomic_unchecked_t num_rsrc_err;
52500+ atomic_unchecked_t num_cmd_success;
52501 unsigned long last_rsrc_error_time;
52502 unsigned long last_ramp_down_time;
52503 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
52504@@ -916,7 +916,7 @@ struct lpfc_hba {
52505
52506 struct dentry *debug_slow_ring_trc;
52507 struct lpfc_debugfs_trc *slow_ring_trc;
52508- atomic_t slow_ring_trc_cnt;
52509+ atomic_unchecked_t slow_ring_trc_cnt;
52510 /* iDiag debugfs sub-directory */
52511 struct dentry *idiag_root;
52512 struct dentry *idiag_pci_cfg;
52513diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
52514index b0aedce..89c6ca6 100644
52515--- a/drivers/scsi/lpfc/lpfc_debugfs.c
52516+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
52517@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
52518
52519 #include <linux/debugfs.h>
52520
52521-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52522+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52523 static unsigned long lpfc_debugfs_start_time = 0L;
52524
52525 /* iDiag */
52526@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
52527 lpfc_debugfs_enable = 0;
52528
52529 len = 0;
52530- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
52531+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
52532 (lpfc_debugfs_max_disc_trc - 1);
52533 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
52534 dtp = vport->disc_trc + i;
52535@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
52536 lpfc_debugfs_enable = 0;
52537
52538 len = 0;
52539- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
52540+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
52541 (lpfc_debugfs_max_slow_ring_trc - 1);
52542 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
52543 dtp = phba->slow_ring_trc + i;
52544@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
52545 !vport || !vport->disc_trc)
52546 return;
52547
52548- index = atomic_inc_return(&vport->disc_trc_cnt) &
52549+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
52550 (lpfc_debugfs_max_disc_trc - 1);
52551 dtp = vport->disc_trc + index;
52552 dtp->fmt = fmt;
52553 dtp->data1 = data1;
52554 dtp->data2 = data2;
52555 dtp->data3 = data3;
52556- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52557+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52558 dtp->jif = jiffies;
52559 #endif
52560 return;
52561@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
52562 !phba || !phba->slow_ring_trc)
52563 return;
52564
52565- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
52566+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
52567 (lpfc_debugfs_max_slow_ring_trc - 1);
52568 dtp = phba->slow_ring_trc + index;
52569 dtp->fmt = fmt;
52570 dtp->data1 = data1;
52571 dtp->data2 = data2;
52572 dtp->data3 = data3;
52573- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52574+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52575 dtp->jif = jiffies;
52576 #endif
52577 return;
52578@@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52579 "slow_ring buffer\n");
52580 goto debug_failed;
52581 }
52582- atomic_set(&phba->slow_ring_trc_cnt, 0);
52583+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
52584 memset(phba->slow_ring_trc, 0,
52585 (sizeof(struct lpfc_debugfs_trc) *
52586 lpfc_debugfs_max_slow_ring_trc));
52587@@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52588 "buffer\n");
52589 goto debug_failed;
52590 }
52591- atomic_set(&vport->disc_trc_cnt, 0);
52592+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
52593
52594 snprintf(name, sizeof(name), "discovery_trace");
52595 vport->debug_disc_trc =
52596diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
52597index 06f9a5b..82812092 100644
52598--- a/drivers/scsi/lpfc/lpfc_init.c
52599+++ b/drivers/scsi/lpfc/lpfc_init.c
52600@@ -11296,8 +11296,10 @@ lpfc_init(void)
52601 "misc_register returned with status %d", error);
52602
52603 if (lpfc_enable_npiv) {
52604- lpfc_transport_functions.vport_create = lpfc_vport_create;
52605- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52606+ pax_open_kernel();
52607+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
52608+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52609+ pax_close_kernel();
52610 }
52611 lpfc_transport_template =
52612 fc_attach_transport(&lpfc_transport_functions);
52613diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
52614index 2df11da..e660a2c 100644
52615--- a/drivers/scsi/lpfc/lpfc_scsi.c
52616+++ b/drivers/scsi/lpfc/lpfc_scsi.c
52617@@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
52618 uint32_t evt_posted;
52619
52620 spin_lock_irqsave(&phba->hbalock, flags);
52621- atomic_inc(&phba->num_rsrc_err);
52622+ atomic_inc_unchecked(&phba->num_rsrc_err);
52623 phba->last_rsrc_error_time = jiffies;
52624
52625 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
52626@@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52627 unsigned long num_rsrc_err, num_cmd_success;
52628 int i;
52629
52630- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
52631- num_cmd_success = atomic_read(&phba->num_cmd_success);
52632+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
52633+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
52634
52635 /*
52636 * The error and success command counters are global per
52637@@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52638 }
52639 }
52640 lpfc_destroy_vport_work_array(phba, vports);
52641- atomic_set(&phba->num_rsrc_err, 0);
52642- atomic_set(&phba->num_cmd_success, 0);
52643+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
52644+ atomic_set_unchecked(&phba->num_cmd_success, 0);
52645 }
52646
52647 /**
52648diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52649index 5055f92..376cd98 100644
52650--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52651+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52652@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
52653 {
52654 struct scsi_device *sdev = to_scsi_device(dev);
52655 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52656- static struct _raid_device *raid_device;
52657+ struct _raid_device *raid_device;
52658 unsigned long flags;
52659 Mpi2RaidVolPage0_t vol_pg0;
52660 Mpi2ConfigReply_t mpi_reply;
52661@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
52662 {
52663 struct scsi_device *sdev = to_scsi_device(dev);
52664 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52665- static struct _raid_device *raid_device;
52666+ struct _raid_device *raid_device;
52667 unsigned long flags;
52668 Mpi2RaidVolPage0_t vol_pg0;
52669 Mpi2ConfigReply_t mpi_reply;
52670@@ -6631,7 +6631,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
52671 struct fw_event_work *fw_event)
52672 {
52673 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
52674- static struct _raid_device *raid_device;
52675+ struct _raid_device *raid_device;
52676 unsigned long flags;
52677 u16 handle;
52678
52679@@ -7102,7 +7102,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
52680 u64 sas_address;
52681 struct _sas_device *sas_device;
52682 struct _sas_node *expander_device;
52683- static struct _raid_device *raid_device;
52684+ struct _raid_device *raid_device;
52685 u8 retry_count;
52686 unsigned long flags;
52687
52688diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
52689index be8ce54..94ed33a 100644
52690--- a/drivers/scsi/pmcraid.c
52691+++ b/drivers/scsi/pmcraid.c
52692@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
52693 res->scsi_dev = scsi_dev;
52694 scsi_dev->hostdata = res;
52695 res->change_detected = 0;
52696- atomic_set(&res->read_failures, 0);
52697- atomic_set(&res->write_failures, 0);
52698+ atomic_set_unchecked(&res->read_failures, 0);
52699+ atomic_set_unchecked(&res->write_failures, 0);
52700 rc = 0;
52701 }
52702 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
52703@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
52704
52705 /* If this was a SCSI read/write command keep count of errors */
52706 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
52707- atomic_inc(&res->read_failures);
52708+ atomic_inc_unchecked(&res->read_failures);
52709 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
52710- atomic_inc(&res->write_failures);
52711+ atomic_inc_unchecked(&res->write_failures);
52712
52713 if (!RES_IS_GSCSI(res->cfg_entry) &&
52714 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
52715@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
52716 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52717 * hrrq_id assigned here in queuecommand
52718 */
52719- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52720+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52721 pinstance->num_hrrq;
52722 cmd->cmd_done = pmcraid_io_done;
52723
52724@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
52725 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52726 * hrrq_id assigned here in queuecommand
52727 */
52728- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52729+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52730 pinstance->num_hrrq;
52731
52732 if (request_size) {
52733@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
52734
52735 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
52736 /* add resources only after host is added into system */
52737- if (!atomic_read(&pinstance->expose_resources))
52738+ if (!atomic_read_unchecked(&pinstance->expose_resources))
52739 return;
52740
52741 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
52742@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
52743 init_waitqueue_head(&pinstance->reset_wait_q);
52744
52745 atomic_set(&pinstance->outstanding_cmds, 0);
52746- atomic_set(&pinstance->last_message_id, 0);
52747- atomic_set(&pinstance->expose_resources, 0);
52748+ atomic_set_unchecked(&pinstance->last_message_id, 0);
52749+ atomic_set_unchecked(&pinstance->expose_resources, 0);
52750
52751 INIT_LIST_HEAD(&pinstance->free_res_q);
52752 INIT_LIST_HEAD(&pinstance->used_res_q);
52753@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
52754 /* Schedule worker thread to handle CCN and take care of adding and
52755 * removing devices to OS
52756 */
52757- atomic_set(&pinstance->expose_resources, 1);
52758+ atomic_set_unchecked(&pinstance->expose_resources, 1);
52759 schedule_work(&pinstance->worker_q);
52760 return rc;
52761
52762diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
52763index e1d150f..6c6df44 100644
52764--- a/drivers/scsi/pmcraid.h
52765+++ b/drivers/scsi/pmcraid.h
52766@@ -748,7 +748,7 @@ struct pmcraid_instance {
52767 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
52768
52769 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
52770- atomic_t last_message_id;
52771+ atomic_unchecked_t last_message_id;
52772
52773 /* configuration table */
52774 struct pmcraid_config_table *cfg_table;
52775@@ -777,7 +777,7 @@ struct pmcraid_instance {
52776 atomic_t outstanding_cmds;
52777
52778 /* should add/delete resources to mid-layer now ?*/
52779- atomic_t expose_resources;
52780+ atomic_unchecked_t expose_resources;
52781
52782
52783
52784@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
52785 struct pmcraid_config_table_entry_ext cfg_entry_ext;
52786 };
52787 struct scsi_device *scsi_dev; /* Link scsi_device structure */
52788- atomic_t read_failures; /* count of failed READ commands */
52789- atomic_t write_failures; /* count of failed WRITE commands */
52790+ atomic_unchecked_t read_failures; /* count of failed READ commands */
52791+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
52792
52793 /* To indicate add/delete/modify during CCN */
52794 u8 change_detected;
52795diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
52796index 16fe519..3b1ec82 100644
52797--- a/drivers/scsi/qla2xxx/qla_attr.c
52798+++ b/drivers/scsi/qla2xxx/qla_attr.c
52799@@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
52800 return 0;
52801 }
52802
52803-struct fc_function_template qla2xxx_transport_functions = {
52804+fc_function_template_no_const qla2xxx_transport_functions = {
52805
52806 .show_host_node_name = 1,
52807 .show_host_port_name = 1,
52808@@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
52809 .bsg_timeout = qla24xx_bsg_timeout,
52810 };
52811
52812-struct fc_function_template qla2xxx_transport_vport_functions = {
52813+fc_function_template_no_const qla2xxx_transport_vport_functions = {
52814
52815 .show_host_node_name = 1,
52816 .show_host_port_name = 1,
52817diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
52818index d48dea8..0845f78 100644
52819--- a/drivers/scsi/qla2xxx/qla_gbl.h
52820+++ b/drivers/scsi/qla2xxx/qla_gbl.h
52821@@ -569,8 +569,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
52822 struct device_attribute;
52823 extern struct device_attribute *qla2x00_host_attrs[];
52824 struct fc_function_template;
52825-extern struct fc_function_template qla2xxx_transport_functions;
52826-extern struct fc_function_template qla2xxx_transport_vport_functions;
52827+extern fc_function_template_no_const qla2xxx_transport_functions;
52828+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
52829 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
52830 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
52831 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
52832diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
52833index d96bfb5..d7afe90 100644
52834--- a/drivers/scsi/qla2xxx/qla_os.c
52835+++ b/drivers/scsi/qla2xxx/qla_os.c
52836@@ -1490,8 +1490,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
52837 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
52838 /* Ok, a 64bit DMA mask is applicable. */
52839 ha->flags.enable_64bit_addressing = 1;
52840- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52841- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52842+ pax_open_kernel();
52843+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52844+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52845+ pax_close_kernel();
52846 return;
52847 }
52848 }
52849diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
52850index 8f6d0fb..1b21097 100644
52851--- a/drivers/scsi/qla4xxx/ql4_def.h
52852+++ b/drivers/scsi/qla4xxx/ql4_def.h
52853@@ -305,7 +305,7 @@ struct ddb_entry {
52854 * (4000 only) */
52855 atomic_t relogin_timer; /* Max Time to wait for
52856 * relogin to complete */
52857- atomic_t relogin_retry_count; /* Num of times relogin has been
52858+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
52859 * retried */
52860 uint32_t default_time2wait; /* Default Min time between
52861 * relogins (+aens) */
52862diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
52863index 3202063..f9f0ff6 100644
52864--- a/drivers/scsi/qla4xxx/ql4_os.c
52865+++ b/drivers/scsi/qla4xxx/ql4_os.c
52866@@ -4494,12 +4494,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
52867 */
52868 if (!iscsi_is_session_online(cls_sess)) {
52869 /* Reset retry relogin timer */
52870- atomic_inc(&ddb_entry->relogin_retry_count);
52871+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
52872 DEBUG2(ql4_printk(KERN_INFO, ha,
52873 "%s: index[%d] relogin timed out-retrying"
52874 " relogin (%d), retry (%d)\n", __func__,
52875 ddb_entry->fw_ddb_index,
52876- atomic_read(&ddb_entry->relogin_retry_count),
52877+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
52878 ddb_entry->default_time2wait + 4));
52879 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
52880 atomic_set(&ddb_entry->retry_relogin_timer,
52881@@ -6607,7 +6607,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
52882
52883 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
52884 atomic_set(&ddb_entry->relogin_timer, 0);
52885- atomic_set(&ddb_entry->relogin_retry_count, 0);
52886+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
52887 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
52888 ddb_entry->default_relogin_timeout =
52889 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
52890diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
52891index 88d46fe..7351be5 100644
52892--- a/drivers/scsi/scsi.c
52893+++ b/drivers/scsi/scsi.c
52894@@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
52895 struct Scsi_Host *host = cmd->device->host;
52896 int rtn = 0;
52897
52898- atomic_inc(&cmd->device->iorequest_cnt);
52899+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52900
52901 /* check if the device is still usable */
52902 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
52903diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
52904index 3f50dfc..86af487 100644
52905--- a/drivers/scsi/scsi_lib.c
52906+++ b/drivers/scsi/scsi_lib.c
52907@@ -1423,7 +1423,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
52908 shost = sdev->host;
52909 scsi_init_cmd_errh(cmd);
52910 cmd->result = DID_NO_CONNECT << 16;
52911- atomic_inc(&cmd->device->iorequest_cnt);
52912+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52913
52914 /*
52915 * SCSI request completion path will do scsi_device_unbusy(),
52916@@ -1449,9 +1449,9 @@ static void scsi_softirq_done(struct request *rq)
52917
52918 INIT_LIST_HEAD(&cmd->eh_entry);
52919
52920- atomic_inc(&cmd->device->iodone_cnt);
52921+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
52922 if (cmd->result)
52923- atomic_inc(&cmd->device->ioerr_cnt);
52924+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
52925
52926 disposition = scsi_decide_disposition(cmd);
52927 if (disposition != SUCCESS &&
52928diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
52929index 074e8cc..f612e5c 100644
52930--- a/drivers/scsi/scsi_sysfs.c
52931+++ b/drivers/scsi/scsi_sysfs.c
52932@@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
52933 char *buf) \
52934 { \
52935 struct scsi_device *sdev = to_scsi_device(dev); \
52936- unsigned long long count = atomic_read(&sdev->field); \
52937+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
52938 return snprintf(buf, 20, "0x%llx\n", count); \
52939 } \
52940 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
52941diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
52942index e51add0..1e06a96 100644
52943--- a/drivers/scsi/scsi_tgt_lib.c
52944+++ b/drivers/scsi/scsi_tgt_lib.c
52945@@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
52946 int err;
52947
52948 dprintk("%lx %u\n", uaddr, len);
52949- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
52950+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
52951 if (err) {
52952 /*
52953 * TODO: need to fixup sg_tablesize, max_segment_size,
52954diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
52955index 521f583..6b15966 100644
52956--- a/drivers/scsi/scsi_transport_fc.c
52957+++ b/drivers/scsi/scsi_transport_fc.c
52958@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
52959 * Netlink Infrastructure
52960 */
52961
52962-static atomic_t fc_event_seq;
52963+static atomic_unchecked_t fc_event_seq;
52964
52965 /**
52966 * fc_get_event_number - Obtain the next sequential FC event number
52967@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
52968 u32
52969 fc_get_event_number(void)
52970 {
52971- return atomic_add_return(1, &fc_event_seq);
52972+ return atomic_add_return_unchecked(1, &fc_event_seq);
52973 }
52974 EXPORT_SYMBOL(fc_get_event_number);
52975
52976@@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
52977 {
52978 int error;
52979
52980- atomic_set(&fc_event_seq, 0);
52981+ atomic_set_unchecked(&fc_event_seq, 0);
52982
52983 error = transport_class_register(&fc_host_class);
52984 if (error)
52985@@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
52986 char *cp;
52987
52988 *val = simple_strtoul(buf, &cp, 0);
52989- if ((*cp && (*cp != '\n')) || (*val < 0))
52990+ if (*cp && (*cp != '\n'))
52991 return -EINVAL;
52992 /*
52993 * Check for overflow; dev_loss_tmo is u32
52994diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
52995index 0102a2d..cc3f8e9 100644
52996--- a/drivers/scsi/scsi_transport_iscsi.c
52997+++ b/drivers/scsi/scsi_transport_iscsi.c
52998@@ -79,7 +79,7 @@ struct iscsi_internal {
52999 struct transport_container session_cont;
53000 };
53001
53002-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
53003+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
53004 static struct workqueue_struct *iscsi_eh_timer_workq;
53005
53006 static DEFINE_IDA(iscsi_sess_ida);
53007@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
53008 int err;
53009
53010 ihost = shost->shost_data;
53011- session->sid = atomic_add_return(1, &iscsi_session_nr);
53012+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
53013
53014 if (target_id == ISCSI_MAX_TARGET) {
53015 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
53016@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
53017 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
53018 ISCSI_TRANSPORT_VERSION);
53019
53020- atomic_set(&iscsi_session_nr, 0);
53021+ atomic_set_unchecked(&iscsi_session_nr, 0);
53022
53023 err = class_register(&iscsi_transport_class);
53024 if (err)
53025diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
53026index 13e8983..d306a68 100644
53027--- a/drivers/scsi/scsi_transport_srp.c
53028+++ b/drivers/scsi/scsi_transport_srp.c
53029@@ -36,7 +36,7 @@
53030 #include "scsi_transport_srp_internal.h"
53031
53032 struct srp_host_attrs {
53033- atomic_t next_port_id;
53034+ atomic_unchecked_t next_port_id;
53035 };
53036 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
53037
53038@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
53039 struct Scsi_Host *shost = dev_to_shost(dev);
53040 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
53041
53042- atomic_set(&srp_host->next_port_id, 0);
53043+ atomic_set_unchecked(&srp_host->next_port_id, 0);
53044 return 0;
53045 }
53046
53047@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
53048 rport_fast_io_fail_timedout);
53049 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
53050
53051- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
53052+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
53053 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
53054
53055 transport_setup_device(&rport->dev);
53056diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
53057index 6825eda..be470c4 100644
53058--- a/drivers/scsi/sd.c
53059+++ b/drivers/scsi/sd.c
53060@@ -2954,7 +2954,7 @@ static int sd_probe(struct device *dev)
53061 sdkp->disk = gd;
53062 sdkp->index = index;
53063 atomic_set(&sdkp->openers, 0);
53064- atomic_set(&sdkp->device->ioerr_cnt, 0);
53065+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
53066
53067 if (!sdp->request_queue->rq_timeout) {
53068 if (sdp->type != TYPE_MOD)
53069diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
53070index 53268aab..17c2764 100644
53071--- a/drivers/scsi/sg.c
53072+++ b/drivers/scsi/sg.c
53073@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
53074 sdp->disk->disk_name,
53075 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
53076 NULL,
53077- (char *)arg);
53078+ (char __user *)arg);
53079 case BLKTRACESTART:
53080 return blk_trace_startstop(sdp->device->request_queue, 1);
53081 case BLKTRACESTOP:
53082diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
53083index d4f9670..d37b662 100644
53084--- a/drivers/spi/spi.c
53085+++ b/drivers/spi/spi.c
53086@@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
53087 EXPORT_SYMBOL_GPL(spi_bus_unlock);
53088
53089 /* portable code must never pass more than 32 bytes */
53090-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
53091+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
53092
53093 static u8 *buf;
53094
53095diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
53096index c341ac1..bf9799f 100644
53097--- a/drivers/staging/android/timed_output.c
53098+++ b/drivers/staging/android/timed_output.c
53099@@ -25,7 +25,7 @@
53100 #include "timed_output.h"
53101
53102 static struct class *timed_output_class;
53103-static atomic_t device_count;
53104+static atomic_unchecked_t device_count;
53105
53106 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
53107 char *buf)
53108@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
53109 timed_output_class = class_create(THIS_MODULE, "timed_output");
53110 if (IS_ERR(timed_output_class))
53111 return PTR_ERR(timed_output_class);
53112- atomic_set(&device_count, 0);
53113+ atomic_set_unchecked(&device_count, 0);
53114 timed_output_class->dev_groups = timed_output_groups;
53115 }
53116
53117@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
53118 if (ret < 0)
53119 return ret;
53120
53121- tdev->index = atomic_inc_return(&device_count);
53122+ tdev->index = atomic_inc_return_unchecked(&device_count);
53123 tdev->dev = device_create(timed_output_class, NULL,
53124 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
53125 if (IS_ERR(tdev->dev))
53126diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
53127index fe47cd3..19a1bd1 100644
53128--- a/drivers/staging/gdm724x/gdm_tty.c
53129+++ b/drivers/staging/gdm724x/gdm_tty.c
53130@@ -44,7 +44,7 @@
53131 #define gdm_tty_send_control(n, r, v, d, l) (\
53132 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
53133
53134-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
53135+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
53136
53137 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
53138 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
53139diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
53140index def8280..e3fd96a 100644
53141--- a/drivers/staging/imx-drm/imx-drm-core.c
53142+++ b/drivers/staging/imx-drm/imx-drm-core.c
53143@@ -355,7 +355,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
53144 if (imxdrm->pipes >= MAX_CRTC)
53145 return -EINVAL;
53146
53147- if (imxdrm->drm->open_count)
53148+ if (local_read(&imxdrm->drm->open_count))
53149 return -EBUSY;
53150
53151 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
53152diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
53153index 3f8020c..649fded 100644
53154--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
53155+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
53156@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
53157 return 0;
53158 }
53159
53160-sfw_test_client_ops_t brw_test_client;
53161-void brw_init_test_client(void)
53162-{
53163- brw_test_client.tso_init = brw_client_init;
53164- brw_test_client.tso_fini = brw_client_fini;
53165- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
53166- brw_test_client.tso_done_rpc = brw_client_done_rpc;
53167+sfw_test_client_ops_t brw_test_client = {
53168+ .tso_init = brw_client_init,
53169+ .tso_fini = brw_client_fini,
53170+ .tso_prep_rpc = brw_client_prep_rpc,
53171+ .tso_done_rpc = brw_client_done_rpc,
53172 };
53173
53174 srpc_service_t brw_test_service;
53175diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
53176index 050723a..fa6fdf1 100644
53177--- a/drivers/staging/lustre/lnet/selftest/framework.c
53178+++ b/drivers/staging/lustre/lnet/selftest/framework.c
53179@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
53180
53181 extern sfw_test_client_ops_t ping_test_client;
53182 extern srpc_service_t ping_test_service;
53183-extern void ping_init_test_client(void);
53184 extern void ping_init_test_service(void);
53185
53186 extern sfw_test_client_ops_t brw_test_client;
53187 extern srpc_service_t brw_test_service;
53188-extern void brw_init_test_client(void);
53189 extern void brw_init_test_service(void);
53190
53191
53192@@ -1684,12 +1682,10 @@ sfw_startup (void)
53193 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
53194 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
53195
53196- brw_init_test_client();
53197 brw_init_test_service();
53198 rc = sfw_register_test(&brw_test_service, &brw_test_client);
53199 LASSERT (rc == 0);
53200
53201- ping_init_test_client();
53202 ping_init_test_service();
53203 rc = sfw_register_test(&ping_test_service, &ping_test_client);
53204 LASSERT (rc == 0);
53205diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
53206index 750cac4..e4d751f 100644
53207--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
53208+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
53209@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
53210 return 0;
53211 }
53212
53213-sfw_test_client_ops_t ping_test_client;
53214-void ping_init_test_client(void)
53215-{
53216- ping_test_client.tso_init = ping_client_init;
53217- ping_test_client.tso_fini = ping_client_fini;
53218- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
53219- ping_test_client.tso_done_rpc = ping_client_done_rpc;
53220-}
53221+sfw_test_client_ops_t ping_test_client = {
53222+ .tso_init = ping_client_init,
53223+ .tso_fini = ping_client_fini,
53224+ .tso_prep_rpc = ping_client_prep_rpc,
53225+ .tso_done_rpc = ping_client_done_rpc,
53226+};
53227
53228 srpc_service_t ping_test_service;
53229 void ping_init_test_service(void)
53230diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
53231index 0c6b784..c64235c 100644
53232--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
53233+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
53234@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
53235 ldlm_completion_callback lcs_completion;
53236 ldlm_blocking_callback lcs_blocking;
53237 ldlm_glimpse_callback lcs_glimpse;
53238-};
53239+} __no_const;
53240
53241 /* ldlm_lockd.c */
53242 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
53243diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
53244index d5c4613..a341678 100644
53245--- a/drivers/staging/lustre/lustre/include/obd.h
53246+++ b/drivers/staging/lustre/lustre/include/obd.h
53247@@ -1439,7 +1439,7 @@ struct md_ops {
53248 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
53249 * wrapper function in include/linux/obd_class.h.
53250 */
53251-};
53252+} __no_const;
53253
53254 struct lsm_operations {
53255 void (*lsm_free)(struct lov_stripe_md *);
53256diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53257index 986bf38..eab2558f 100644
53258--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53259+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53260@@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
53261 int added = (mode == LCK_NL);
53262 int overlaps = 0;
53263 int splitted = 0;
53264- const struct ldlm_callback_suite null_cbs = { NULL };
53265+ const struct ldlm_callback_suite null_cbs = { };
53266
53267 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
53268 LPU64" end "LPU64"\n", *flags,
53269diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53270index e947b91..f408990 100644
53271--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53272+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53273@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
53274 int LL_PROC_PROTO(proc_console_max_delay_cs)
53275 {
53276 int rc, max_delay_cs;
53277- ctl_table_t dummy = *table;
53278+ ctl_table_no_const dummy = *table;
53279 cfs_duration_t d;
53280
53281 dummy.data = &max_delay_cs;
53282@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
53283 int LL_PROC_PROTO(proc_console_min_delay_cs)
53284 {
53285 int rc, min_delay_cs;
53286- ctl_table_t dummy = *table;
53287+ ctl_table_no_const dummy = *table;
53288 cfs_duration_t d;
53289
53290 dummy.data = &min_delay_cs;
53291@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
53292 int LL_PROC_PROTO(proc_console_backoff)
53293 {
53294 int rc, backoff;
53295- ctl_table_t dummy = *table;
53296+ ctl_table_no_const dummy = *table;
53297
53298 dummy.data = &backoff;
53299 dummy.proc_handler = &proc_dointvec;
53300diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
53301index b16ee08..a3db5c6 100644
53302--- a/drivers/staging/lustre/lustre/libcfs/module.c
53303+++ b/drivers/staging/lustre/lustre/libcfs/module.c
53304@@ -314,11 +314,11 @@ out:
53305
53306
53307 struct cfs_psdev_ops libcfs_psdev_ops = {
53308- libcfs_psdev_open,
53309- libcfs_psdev_release,
53310- NULL,
53311- NULL,
53312- libcfs_ioctl
53313+ .p_open = libcfs_psdev_open,
53314+ .p_close = libcfs_psdev_release,
53315+ .p_read = NULL,
53316+ .p_write = NULL,
53317+ .p_ioctl = libcfs_ioctl
53318 };
53319
53320 extern int insert_proc(void);
53321diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
53322index ae6f61a..03c3d5d 100644
53323--- a/drivers/staging/lustre/lustre/llite/dir.c
53324+++ b/drivers/staging/lustre/lustre/llite/dir.c
53325@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
53326 int mode;
53327 int err;
53328
53329- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
53330+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
53331 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
53332 strlen(filename), mode, LUSTRE_OPC_MKDIR,
53333 lump);
53334diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
53335index f670469..03b7438 100644
53336--- a/drivers/staging/media/solo6x10/solo6x10-core.c
53337+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
53338@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
53339
53340 static int solo_sysfs_init(struct solo_dev *solo_dev)
53341 {
53342- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
53343+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
53344 struct device *dev = &solo_dev->dev;
53345 const char *driver;
53346 int i;
53347diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
53348index 74f037b..5b5bb76 100644
53349--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
53350+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
53351@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
53352
53353 int solo_g723_init(struct solo_dev *solo_dev)
53354 {
53355- static struct snd_device_ops ops = { NULL };
53356+ static struct snd_device_ops ops = { };
53357 struct snd_card *card;
53358 struct snd_kcontrol_new kctl;
53359 char name[32];
53360diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
53361index 7f2f247..d999137 100644
53362--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
53363+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
53364@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
53365
53366 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
53367 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
53368- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
53369+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
53370 if (p2m_id < 0)
53371 p2m_id = -p2m_id;
53372 }
53373diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
53374index 8964f8b..36eb087 100644
53375--- a/drivers/staging/media/solo6x10/solo6x10.h
53376+++ b/drivers/staging/media/solo6x10/solo6x10.h
53377@@ -237,7 +237,7 @@ struct solo_dev {
53378
53379 /* P2M DMA Engine */
53380 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
53381- atomic_t p2m_count;
53382+ atomic_unchecked_t p2m_count;
53383 int p2m_jiffies;
53384 unsigned int p2m_timeouts;
53385
53386diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
53387index a0f4868..139f1fb 100644
53388--- a/drivers/staging/octeon/ethernet-rx.c
53389+++ b/drivers/staging/octeon/ethernet-rx.c
53390@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
53391 /* Increment RX stats for virtual ports */
53392 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
53393 #ifdef CONFIG_64BIT
53394- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
53395- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
53396+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
53397+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
53398 #else
53399- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
53400- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
53401+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
53402+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
53403 #endif
53404 }
53405 netif_receive_skb(skb);
53406@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
53407 dev->name);
53408 */
53409 #ifdef CONFIG_64BIT
53410- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
53411+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
53412 #else
53413- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
53414+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
53415 #endif
53416 dev_kfree_skb_irq(skb);
53417 }
53418diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
53419index da9dd6b..8e3e0f5 100644
53420--- a/drivers/staging/octeon/ethernet.c
53421+++ b/drivers/staging/octeon/ethernet.c
53422@@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
53423 * since the RX tasklet also increments it.
53424 */
53425 #ifdef CONFIG_64BIT
53426- atomic64_add(rx_status.dropped_packets,
53427- (atomic64_t *)&priv->stats.rx_dropped);
53428+ atomic64_add_unchecked(rx_status.dropped_packets,
53429+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
53430 #else
53431- atomic_add(rx_status.dropped_packets,
53432- (atomic_t *)&priv->stats.rx_dropped);
53433+ atomic_add_unchecked(rx_status.dropped_packets,
53434+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
53435 #endif
53436 }
53437
53438diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
53439index c59fccd..79f8fc2 100644
53440--- a/drivers/staging/rtl8188eu/include/hal_intf.h
53441+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
53442@@ -267,7 +267,7 @@ struct hal_ops {
53443 s32 (*c2h_handler)(struct adapter *padapter,
53444 struct c2h_evt_hdr *c2h_evt);
53445 c2h_id_filter c2h_id_filter_ccx;
53446-};
53447+} __no_const;
53448
53449 enum rt_eeprom_type {
53450 EEPROM_93C46,
53451diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
53452index e8790f8..b4a5980 100644
53453--- a/drivers/staging/rtl8188eu/include/rtw_io.h
53454+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
53455@@ -124,7 +124,7 @@ struct _io_ops {
53456 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
53457 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
53458 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
53459-};
53460+} __no_const;
53461
53462 struct io_req {
53463 struct list_head list;
53464diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
53465index dc23395..cf7e9b1 100644
53466--- a/drivers/staging/rtl8712/rtl871x_io.h
53467+++ b/drivers/staging/rtl8712/rtl871x_io.h
53468@@ -108,7 +108,7 @@ struct _io_ops {
53469 u8 *pmem);
53470 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
53471 u8 *pmem);
53472-};
53473+} __no_const;
53474
53475 struct io_req {
53476 struct list_head list;
53477diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
53478index a863a98..d272795 100644
53479--- a/drivers/staging/usbip/vhci.h
53480+++ b/drivers/staging/usbip/vhci.h
53481@@ -83,7 +83,7 @@ struct vhci_hcd {
53482 unsigned resuming:1;
53483 unsigned long re_timeout;
53484
53485- atomic_t seqnum;
53486+ atomic_unchecked_t seqnum;
53487
53488 /*
53489 * NOTE:
53490diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
53491index 0007d30..c06a693 100644
53492--- a/drivers/staging/usbip/vhci_hcd.c
53493+++ b/drivers/staging/usbip/vhci_hcd.c
53494@@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
53495
53496 spin_lock(&vdev->priv_lock);
53497
53498- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
53499+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
53500 if (priv->seqnum == 0xffff)
53501 dev_info(&urb->dev->dev, "seqnum max\n");
53502
53503@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
53504 return -ENOMEM;
53505 }
53506
53507- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
53508+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
53509 if (unlink->seqnum == 0xffff)
53510 pr_info("seqnum max\n");
53511
53512@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
53513 vdev->rhport = rhport;
53514 }
53515
53516- atomic_set(&vhci->seqnum, 0);
53517+ atomic_set_unchecked(&vhci->seqnum, 0);
53518 spin_lock_init(&vhci->lock);
53519
53520 hcd->power_budget = 0; /* no limit */
53521diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
53522index d07fcb5..358e1e1 100644
53523--- a/drivers/staging/usbip/vhci_rx.c
53524+++ b/drivers/staging/usbip/vhci_rx.c
53525@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
53526 if (!urb) {
53527 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
53528 pr_info("max seqnum %d\n",
53529- atomic_read(&the_controller->seqnum));
53530+ atomic_read_unchecked(&the_controller->seqnum));
53531 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
53532 return;
53533 }
53534diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
53535index 317c2a8..ffeb4ef 100644
53536--- a/drivers/staging/vt6655/hostap.c
53537+++ b/drivers/staging/vt6655/hostap.c
53538@@ -68,14 +68,13 @@ static int msglevel = MSG_LEVEL_INFO;
53539 *
53540 */
53541
53542+static net_device_ops_no_const apdev_netdev_ops;
53543+
53544 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
53545 {
53546 PSDevice apdev_priv;
53547 struct net_device *dev = pDevice->dev;
53548 int ret;
53549- const struct net_device_ops apdev_netdev_ops = {
53550- .ndo_start_xmit = pDevice->tx_80211,
53551- };
53552
53553 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
53554
53555@@ -87,6 +86,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
53556 *apdev_priv = *pDevice;
53557 eth_hw_addr_inherit(pDevice->apdev, dev);
53558
53559+ /* only half broken now */
53560+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
53561 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
53562
53563 pDevice->apdev->type = ARPHRD_IEEE80211;
53564diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
53565index e7e9372..161f530 100644
53566--- a/drivers/target/sbp/sbp_target.c
53567+++ b/drivers/target/sbp/sbp_target.c
53568@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
53569
53570 #define SESSION_MAINTENANCE_INTERVAL HZ
53571
53572-static atomic_t login_id = ATOMIC_INIT(0);
53573+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
53574
53575 static void session_maintenance_work(struct work_struct *);
53576 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
53577@@ -444,7 +444,7 @@ static void sbp_management_request_login(
53578 login->lun = se_lun;
53579 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
53580 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
53581- login->login_id = atomic_inc_return(&login_id);
53582+ login->login_id = atomic_inc_return_unchecked(&login_id);
53583
53584 login->tgt_agt = sbp_target_agent_register(login);
53585 if (IS_ERR(login->tgt_agt)) {
53586diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
53587index 98da901..bb443e8 100644
53588--- a/drivers/target/target_core_device.c
53589+++ b/drivers/target/target_core_device.c
53590@@ -1525,7 +1525,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
53591 spin_lock_init(&dev->se_tmr_lock);
53592 spin_lock_init(&dev->qf_cmd_lock);
53593 sema_init(&dev->caw_sem, 1);
53594- atomic_set(&dev->dev_ordered_id, 0);
53595+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
53596 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
53597 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
53598 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
53599diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
53600index 7fa62fc..abdd041 100644
53601--- a/drivers/target/target_core_transport.c
53602+++ b/drivers/target/target_core_transport.c
53603@@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
53604 * Used to determine when ORDERED commands should go from
53605 * Dormant to Active status.
53606 */
53607- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
53608+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
53609 smp_mb__after_atomic();
53610 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
53611 cmd->se_ordered_id, cmd->sam_task_attr,
53612diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
53613index 4b2b999..cad9fa5 100644
53614--- a/drivers/thermal/of-thermal.c
53615+++ b/drivers/thermal/of-thermal.c
53616@@ -30,6 +30,7 @@
53617 #include <linux/err.h>
53618 #include <linux/export.h>
53619 #include <linux/string.h>
53620+#include <linux/mm.h>
53621
53622 #include "thermal_core.h"
53623
53624@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
53625 tz->get_trend = get_trend;
53626 tz->sensor_data = data;
53627
53628- tzd->ops->get_temp = of_thermal_get_temp;
53629- tzd->ops->get_trend = of_thermal_get_trend;
53630+ pax_open_kernel();
53631+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
53632+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
53633+ pax_close_kernel();
53634 mutex_unlock(&tzd->lock);
53635
53636 return tzd;
53637@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
53638 return;
53639
53640 mutex_lock(&tzd->lock);
53641- tzd->ops->get_temp = NULL;
53642- tzd->ops->get_trend = NULL;
53643+ pax_open_kernel();
53644+ *(void **)&tzd->ops->get_temp = NULL;
53645+ *(void **)&tzd->ops->get_trend = NULL;
53646+ pax_close_kernel();
53647
53648 tz->get_temp = NULL;
53649 tz->get_trend = NULL;
53650diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
53651index a57bb5a..1f727d33 100644
53652--- a/drivers/tty/cyclades.c
53653+++ b/drivers/tty/cyclades.c
53654@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
53655 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
53656 info->port.count);
53657 #endif
53658- info->port.count++;
53659+ atomic_inc(&info->port.count);
53660 #ifdef CY_DEBUG_COUNT
53661 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
53662- current->pid, info->port.count);
53663+ current->pid, atomic_read(&info->port.count));
53664 #endif
53665
53666 /*
53667@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
53668 for (j = 0; j < cy_card[i].nports; j++) {
53669 info = &cy_card[i].ports[j];
53670
53671- if (info->port.count) {
53672+ if (atomic_read(&info->port.count)) {
53673 /* XXX is the ldisc num worth this? */
53674 struct tty_struct *tty;
53675 struct tty_ldisc *ld;
53676diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
53677index 4fcec1d..5a036f7 100644
53678--- a/drivers/tty/hvc/hvc_console.c
53679+++ b/drivers/tty/hvc/hvc_console.c
53680@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
53681
53682 spin_lock_irqsave(&hp->port.lock, flags);
53683 /* Check and then increment for fast path open. */
53684- if (hp->port.count++ > 0) {
53685+ if (atomic_inc_return(&hp->port.count) > 1) {
53686 spin_unlock_irqrestore(&hp->port.lock, flags);
53687 hvc_kick();
53688 return 0;
53689@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53690
53691 spin_lock_irqsave(&hp->port.lock, flags);
53692
53693- if (--hp->port.count == 0) {
53694+ if (atomic_dec_return(&hp->port.count) == 0) {
53695 spin_unlock_irqrestore(&hp->port.lock, flags);
53696 /* We are done with the tty pointer now. */
53697 tty_port_tty_set(&hp->port, NULL);
53698@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53699 */
53700 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
53701 } else {
53702- if (hp->port.count < 0)
53703+ if (atomic_read(&hp->port.count) < 0)
53704 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
53705- hp->vtermno, hp->port.count);
53706+ hp->vtermno, atomic_read(&hp->port.count));
53707 spin_unlock_irqrestore(&hp->port.lock, flags);
53708 }
53709 }
53710@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
53711 * open->hangup case this can be called after the final close so prevent
53712 * that from happening for now.
53713 */
53714- if (hp->port.count <= 0) {
53715+ if (atomic_read(&hp->port.count) <= 0) {
53716 spin_unlock_irqrestore(&hp->port.lock, flags);
53717 return;
53718 }
53719
53720- hp->port.count = 0;
53721+ atomic_set(&hp->port.count, 0);
53722 spin_unlock_irqrestore(&hp->port.lock, flags);
53723 tty_port_tty_set(&hp->port, NULL);
53724
53725@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
53726 return -EPIPE;
53727
53728 /* FIXME what's this (unprotected) check for? */
53729- if (hp->port.count <= 0)
53730+ if (atomic_read(&hp->port.count) <= 0)
53731 return -EIO;
53732
53733 spin_lock_irqsave(&hp->lock, flags);
53734diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
53735index 81e939e..95ead10 100644
53736--- a/drivers/tty/hvc/hvcs.c
53737+++ b/drivers/tty/hvc/hvcs.c
53738@@ -83,6 +83,7 @@
53739 #include <asm/hvcserver.h>
53740 #include <asm/uaccess.h>
53741 #include <asm/vio.h>
53742+#include <asm/local.h>
53743
53744 /*
53745 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
53746@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
53747
53748 spin_lock_irqsave(&hvcsd->lock, flags);
53749
53750- if (hvcsd->port.count > 0) {
53751+ if (atomic_read(&hvcsd->port.count) > 0) {
53752 spin_unlock_irqrestore(&hvcsd->lock, flags);
53753 printk(KERN_INFO "HVCS: vterm state unchanged. "
53754 "The hvcs device node is still in use.\n");
53755@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
53756 }
53757 }
53758
53759- hvcsd->port.count = 0;
53760+ atomic_set(&hvcsd->port.count, 0);
53761 hvcsd->port.tty = tty;
53762 tty->driver_data = hvcsd;
53763
53764@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
53765 unsigned long flags;
53766
53767 spin_lock_irqsave(&hvcsd->lock, flags);
53768- hvcsd->port.count++;
53769+ atomic_inc(&hvcsd->port.count);
53770 hvcsd->todo_mask |= HVCS_SCHED_READ;
53771 spin_unlock_irqrestore(&hvcsd->lock, flags);
53772
53773@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53774 hvcsd = tty->driver_data;
53775
53776 spin_lock_irqsave(&hvcsd->lock, flags);
53777- if (--hvcsd->port.count == 0) {
53778+ if (atomic_dec_and_test(&hvcsd->port.count)) {
53779
53780 vio_disable_interrupts(hvcsd->vdev);
53781
53782@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53783
53784 free_irq(irq, hvcsd);
53785 return;
53786- } else if (hvcsd->port.count < 0) {
53787+ } else if (atomic_read(&hvcsd->port.count) < 0) {
53788 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
53789 " is missmanaged.\n",
53790- hvcsd->vdev->unit_address, hvcsd->port.count);
53791+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
53792 }
53793
53794 spin_unlock_irqrestore(&hvcsd->lock, flags);
53795@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53796
53797 spin_lock_irqsave(&hvcsd->lock, flags);
53798 /* Preserve this so that we know how many kref refs to put */
53799- temp_open_count = hvcsd->port.count;
53800+ temp_open_count = atomic_read(&hvcsd->port.count);
53801
53802 /*
53803 * Don't kref put inside the spinlock because the destruction
53804@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53805 tty->driver_data = NULL;
53806 hvcsd->port.tty = NULL;
53807
53808- hvcsd->port.count = 0;
53809+ atomic_set(&hvcsd->port.count, 0);
53810
53811 /* This will drop any buffered data on the floor which is OK in a hangup
53812 * scenario. */
53813@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
53814 * the middle of a write operation? This is a crummy place to do this
53815 * but we want to keep it all in the spinlock.
53816 */
53817- if (hvcsd->port.count <= 0) {
53818+ if (atomic_read(&hvcsd->port.count) <= 0) {
53819 spin_unlock_irqrestore(&hvcsd->lock, flags);
53820 return -ENODEV;
53821 }
53822@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
53823 {
53824 struct hvcs_struct *hvcsd = tty->driver_data;
53825
53826- if (!hvcsd || hvcsd->port.count <= 0)
53827+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
53828 return 0;
53829
53830 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
53831diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
53832index 4190199..06d5bfa 100644
53833--- a/drivers/tty/hvc/hvsi.c
53834+++ b/drivers/tty/hvc/hvsi.c
53835@@ -85,7 +85,7 @@ struct hvsi_struct {
53836 int n_outbuf;
53837 uint32_t vtermno;
53838 uint32_t virq;
53839- atomic_t seqno; /* HVSI packet sequence number */
53840+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
53841 uint16_t mctrl;
53842 uint8_t state; /* HVSI protocol state */
53843 uint8_t flags;
53844@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
53845
53846 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
53847 packet.hdr.len = sizeof(struct hvsi_query_response);
53848- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53849+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53850 packet.verb = VSV_SEND_VERSION_NUMBER;
53851 packet.u.version = HVSI_VERSION;
53852 packet.query_seqno = query_seqno+1;
53853@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
53854
53855 packet.hdr.type = VS_QUERY_PACKET_HEADER;
53856 packet.hdr.len = sizeof(struct hvsi_query);
53857- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53858+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53859 packet.verb = verb;
53860
53861 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
53862@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
53863 int wrote;
53864
53865 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
53866- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53867+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53868 packet.hdr.len = sizeof(struct hvsi_control);
53869 packet.verb = VSV_SET_MODEM_CTL;
53870 packet.mask = HVSI_TSDTR;
53871@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
53872 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
53873
53874 packet.hdr.type = VS_DATA_PACKET_HEADER;
53875- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53876+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53877 packet.hdr.len = count + sizeof(struct hvsi_header);
53878 memcpy(&packet.data, buf, count);
53879
53880@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
53881 struct hvsi_control packet __ALIGNED__;
53882
53883 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
53884- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53885+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53886 packet.hdr.len = 6;
53887 packet.verb = VSV_CLOSE_PROTOCOL;
53888
53889@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
53890
53891 tty_port_tty_set(&hp->port, tty);
53892 spin_lock_irqsave(&hp->lock, flags);
53893- hp->port.count++;
53894+ atomic_inc(&hp->port.count);
53895 atomic_set(&hp->seqno, 0);
53896 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
53897 spin_unlock_irqrestore(&hp->lock, flags);
53898@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53899
53900 spin_lock_irqsave(&hp->lock, flags);
53901
53902- if (--hp->port.count == 0) {
53903+ if (atomic_dec_return(&hp->port.count) == 0) {
53904 tty_port_tty_set(&hp->port, NULL);
53905 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
53906
53907@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53908
53909 spin_lock_irqsave(&hp->lock, flags);
53910 }
53911- } else if (hp->port.count < 0)
53912+ } else if (atomic_read(&hp->port.count) < 0)
53913 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
53914- hp - hvsi_ports, hp->port.count);
53915+ hp - hvsi_ports, atomic_read(&hp->port.count));
53916
53917 spin_unlock_irqrestore(&hp->lock, flags);
53918 }
53919@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
53920 tty_port_tty_set(&hp->port, NULL);
53921
53922 spin_lock_irqsave(&hp->lock, flags);
53923- hp->port.count = 0;
53924+ atomic_set(&hp->port.count, 0);
53925 hp->n_outbuf = 0;
53926 spin_unlock_irqrestore(&hp->lock, flags);
53927 }
53928diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
53929index 7ae6c29..05c6dba 100644
53930--- a/drivers/tty/hvc/hvsi_lib.c
53931+++ b/drivers/tty/hvc/hvsi_lib.c
53932@@ -8,7 +8,7 @@
53933
53934 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
53935 {
53936- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
53937+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
53938
53939 /* Assumes that always succeeds, works in practice */
53940 return pv->put_chars(pv->termno, (char *)packet, packet->len);
53941@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
53942
53943 /* Reset state */
53944 pv->established = 0;
53945- atomic_set(&pv->seqno, 0);
53946+ atomic_set_unchecked(&pv->seqno, 0);
53947
53948 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53949
53950diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53951index 17ee3bf..8d2520d 100644
53952--- a/drivers/tty/ipwireless/tty.c
53953+++ b/drivers/tty/ipwireless/tty.c
53954@@ -28,6 +28,7 @@
53955 #include <linux/tty_driver.h>
53956 #include <linux/tty_flip.h>
53957 #include <linux/uaccess.h>
53958+#include <asm/local.h>
53959
53960 #include "tty.h"
53961 #include "network.h"
53962@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53963 mutex_unlock(&tty->ipw_tty_mutex);
53964 return -ENODEV;
53965 }
53966- if (tty->port.count == 0)
53967+ if (atomic_read(&tty->port.count) == 0)
53968 tty->tx_bytes_queued = 0;
53969
53970- tty->port.count++;
53971+ atomic_inc(&tty->port.count);
53972
53973 tty->port.tty = linux_tty;
53974 linux_tty->driver_data = tty;
53975@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53976
53977 static void do_ipw_close(struct ipw_tty *tty)
53978 {
53979- tty->port.count--;
53980-
53981- if (tty->port.count == 0) {
53982+ if (atomic_dec_return(&tty->port.count) == 0) {
53983 struct tty_struct *linux_tty = tty->port.tty;
53984
53985 if (linux_tty != NULL) {
53986@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53987 return;
53988
53989 mutex_lock(&tty->ipw_tty_mutex);
53990- if (tty->port.count == 0) {
53991+ if (atomic_read(&tty->port.count) == 0) {
53992 mutex_unlock(&tty->ipw_tty_mutex);
53993 return;
53994 }
53995@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53996
53997 mutex_lock(&tty->ipw_tty_mutex);
53998
53999- if (!tty->port.count) {
54000+ if (!atomic_read(&tty->port.count)) {
54001 mutex_unlock(&tty->ipw_tty_mutex);
54002 return;
54003 }
54004@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
54005 return -ENODEV;
54006
54007 mutex_lock(&tty->ipw_tty_mutex);
54008- if (!tty->port.count) {
54009+ if (!atomic_read(&tty->port.count)) {
54010 mutex_unlock(&tty->ipw_tty_mutex);
54011 return -EINVAL;
54012 }
54013@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
54014 if (!tty)
54015 return -ENODEV;
54016
54017- if (!tty->port.count)
54018+ if (!atomic_read(&tty->port.count))
54019 return -EINVAL;
54020
54021 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
54022@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
54023 if (!tty)
54024 return 0;
54025
54026- if (!tty->port.count)
54027+ if (!atomic_read(&tty->port.count))
54028 return 0;
54029
54030 return tty->tx_bytes_queued;
54031@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
54032 if (!tty)
54033 return -ENODEV;
54034
54035- if (!tty->port.count)
54036+ if (!atomic_read(&tty->port.count))
54037 return -EINVAL;
54038
54039 return get_control_lines(tty);
54040@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
54041 if (!tty)
54042 return -ENODEV;
54043
54044- if (!tty->port.count)
54045+ if (!atomic_read(&tty->port.count))
54046 return -EINVAL;
54047
54048 return set_control_lines(tty, set, clear);
54049@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
54050 if (!tty)
54051 return -ENODEV;
54052
54053- if (!tty->port.count)
54054+ if (!atomic_read(&tty->port.count))
54055 return -EINVAL;
54056
54057 /* FIXME: Exactly how is the tty object locked here .. */
54058@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
54059 * are gone */
54060 mutex_lock(&ttyj->ipw_tty_mutex);
54061 }
54062- while (ttyj->port.count)
54063+ while (atomic_read(&ttyj->port.count))
54064 do_ipw_close(ttyj);
54065 ipwireless_disassociate_network_ttys(network,
54066 ttyj->channel_idx);
54067diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
54068index 1deaca4..c8582d4 100644
54069--- a/drivers/tty/moxa.c
54070+++ b/drivers/tty/moxa.c
54071@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
54072 }
54073
54074 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
54075- ch->port.count++;
54076+ atomic_inc(&ch->port.count);
54077 tty->driver_data = ch;
54078 tty_port_tty_set(&ch->port, tty);
54079 mutex_lock(&ch->port.mutex);
54080diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
54081index 2ebe47b..3205833 100644
54082--- a/drivers/tty/n_gsm.c
54083+++ b/drivers/tty/n_gsm.c
54084@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
54085 spin_lock_init(&dlci->lock);
54086 mutex_init(&dlci->mutex);
54087 dlci->fifo = &dlci->_fifo;
54088- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
54089+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
54090 kfree(dlci);
54091 return NULL;
54092 }
54093@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
54094 struct gsm_dlci *dlci = tty->driver_data;
54095 struct tty_port *port = &dlci->port;
54096
54097- port->count++;
54098+ atomic_inc(&port->count);
54099 tty_port_tty_set(port, tty);
54100
54101 dlci->modem_rx = 0;
54102diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
54103index f44f1ba..a8d5915 100644
54104--- a/drivers/tty/n_tty.c
54105+++ b/drivers/tty/n_tty.c
54106@@ -115,7 +115,7 @@ struct n_tty_data {
54107 int minimum_to_wake;
54108
54109 /* consumer-published */
54110- size_t read_tail;
54111+ size_t read_tail __intentional_overflow(-1);
54112 size_t line_start;
54113
54114 /* protected by output lock */
54115@@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
54116 {
54117 *ops = tty_ldisc_N_TTY;
54118 ops->owner = NULL;
54119- ops->refcount = ops->flags = 0;
54120+ atomic_set(&ops->refcount, 0);
54121+ ops->flags = 0;
54122 }
54123 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
54124diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
54125index 25c9bc7..24077b7 100644
54126--- a/drivers/tty/pty.c
54127+++ b/drivers/tty/pty.c
54128@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
54129 panic("Couldn't register Unix98 pts driver");
54130
54131 /* Now create the /dev/ptmx special device */
54132+ pax_open_kernel();
54133 tty_default_fops(&ptmx_fops);
54134- ptmx_fops.open = ptmx_open;
54135+ *(void **)&ptmx_fops.open = ptmx_open;
54136+ pax_close_kernel();
54137
54138 cdev_init(&ptmx_cdev, &ptmx_fops);
54139 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
54140diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
54141index 383c4c7..d408e21 100644
54142--- a/drivers/tty/rocket.c
54143+++ b/drivers/tty/rocket.c
54144@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
54145 tty->driver_data = info;
54146 tty_port_tty_set(port, tty);
54147
54148- if (port->count++ == 0) {
54149+ if (atomic_inc_return(&port->count) == 1) {
54150 atomic_inc(&rp_num_ports_open);
54151
54152 #ifdef ROCKET_DEBUG_OPEN
54153@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
54154 #endif
54155 }
54156 #ifdef ROCKET_DEBUG_OPEN
54157- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
54158+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
54159 #endif
54160
54161 /*
54162@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
54163 spin_unlock_irqrestore(&info->port.lock, flags);
54164 return;
54165 }
54166- if (info->port.count)
54167+ if (atomic_read(&info->port.count))
54168 atomic_dec(&rp_num_ports_open);
54169 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
54170 spin_unlock_irqrestore(&info->port.lock, flags);
54171diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
54172index 1274499..f541382 100644
54173--- a/drivers/tty/serial/ioc4_serial.c
54174+++ b/drivers/tty/serial/ioc4_serial.c
54175@@ -437,7 +437,7 @@ struct ioc4_soft {
54176 } is_intr_info[MAX_IOC4_INTR_ENTS];
54177
54178 /* Number of entries active in the above array */
54179- atomic_t is_num_intrs;
54180+ atomic_unchecked_t is_num_intrs;
54181 } is_intr_type[IOC4_NUM_INTR_TYPES];
54182
54183 /* is_ir_lock must be held while
54184@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
54185 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
54186 || (type == IOC4_OTHER_INTR_TYPE)));
54187
54188- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
54189+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
54190 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
54191
54192 /* Save off the lower level interrupt handler */
54193@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
54194
54195 soft = arg;
54196 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
54197- num_intrs = (int)atomic_read(
54198+ num_intrs = (int)atomic_read_unchecked(
54199 &soft->is_intr_type[intr_type].is_num_intrs);
54200
54201 this_mir = this_ir = pending_intrs(soft, intr_type);
54202diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
54203index cfadf29..8cf4595 100644
54204--- a/drivers/tty/serial/kgdb_nmi.c
54205+++ b/drivers/tty/serial/kgdb_nmi.c
54206@@ -51,7 +51,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
54207 * I/O utilities that messages sent to the console will automatically
54208 * be displayed on the dbg_io.
54209 */
54210- dbg_io_ops->is_console = true;
54211+ pax_open_kernel();
54212+ *(int *)&dbg_io_ops->is_console = true;
54213+ pax_close_kernel();
54214
54215 return 0;
54216 }
54217diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
54218index a260cde..6b2b5ce 100644
54219--- a/drivers/tty/serial/kgdboc.c
54220+++ b/drivers/tty/serial/kgdboc.c
54221@@ -24,8 +24,9 @@
54222 #define MAX_CONFIG_LEN 40
54223
54224 static struct kgdb_io kgdboc_io_ops;
54225+static struct kgdb_io kgdboc_io_ops_console;
54226
54227-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
54228+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
54229 static int configured = -1;
54230
54231 static char config[MAX_CONFIG_LEN];
54232@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
54233 kgdboc_unregister_kbd();
54234 if (configured == 1)
54235 kgdb_unregister_io_module(&kgdboc_io_ops);
54236+ else if (configured == 2)
54237+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
54238 }
54239
54240 static int configure_kgdboc(void)
54241@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
54242 int err;
54243 char *cptr = config;
54244 struct console *cons;
54245+ int is_console = 0;
54246
54247 err = kgdboc_option_setup(config);
54248 if (err || !strlen(config) || isspace(config[0]))
54249 goto noconfig;
54250
54251 err = -ENODEV;
54252- kgdboc_io_ops.is_console = 0;
54253 kgdb_tty_driver = NULL;
54254
54255 kgdboc_use_kms = 0;
54256@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
54257 int idx;
54258 if (cons->device && cons->device(cons, &idx) == p &&
54259 idx == tty_line) {
54260- kgdboc_io_ops.is_console = 1;
54261+ is_console = 1;
54262 break;
54263 }
54264 cons = cons->next;
54265@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
54266 kgdb_tty_line = tty_line;
54267
54268 do_register:
54269- err = kgdb_register_io_module(&kgdboc_io_ops);
54270+ if (is_console) {
54271+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
54272+ configured = 2;
54273+ } else {
54274+ err = kgdb_register_io_module(&kgdboc_io_ops);
54275+ configured = 1;
54276+ }
54277 if (err)
54278 goto noconfig;
54279
54280@@ -205,8 +214,6 @@ do_register:
54281 if (err)
54282 goto nmi_con_failed;
54283
54284- configured = 1;
54285-
54286 return 0;
54287
54288 nmi_con_failed:
54289@@ -223,7 +230,7 @@ noconfig:
54290 static int __init init_kgdboc(void)
54291 {
54292 /* Already configured? */
54293- if (configured == 1)
54294+ if (configured >= 1)
54295 return 0;
54296
54297 return configure_kgdboc();
54298@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
54299 if (config[len - 1] == '\n')
54300 config[len - 1] = '\0';
54301
54302- if (configured == 1)
54303+ if (configured >= 1)
54304 cleanup_kgdboc();
54305
54306 /* Go and configure with the new params. */
54307@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
54308 .post_exception = kgdboc_post_exp_handler,
54309 };
54310
54311+static struct kgdb_io kgdboc_io_ops_console = {
54312+ .name = "kgdboc",
54313+ .read_char = kgdboc_get_char,
54314+ .write_char = kgdboc_put_char,
54315+ .pre_exception = kgdboc_pre_exp_handler,
54316+ .post_exception = kgdboc_post_exp_handler,
54317+ .is_console = 1
54318+};
54319+
54320 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
54321 /* This is only available if kgdboc is a built in for early debugging */
54322 static int __init kgdboc_early_init(char *opt)
54323diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
54324index 72000a6..a190bc4 100644
54325--- a/drivers/tty/serial/msm_serial.c
54326+++ b/drivers/tty/serial/msm_serial.c
54327@@ -981,7 +981,7 @@ static struct uart_driver msm_uart_driver = {
54328 .cons = MSM_CONSOLE,
54329 };
54330
54331-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
54332+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
54333
54334 static const struct of_device_id msm_uartdm_table[] = {
54335 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
54336@@ -1000,7 +1000,7 @@ static int msm_serial_probe(struct platform_device *pdev)
54337 int irq;
54338
54339 if (pdev->id == -1)
54340- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
54341+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
54342
54343 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
54344 return -ENXIO;
54345diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
54346index c1d3ebd..f618a93 100644
54347--- a/drivers/tty/serial/samsung.c
54348+++ b/drivers/tty/serial/samsung.c
54349@@ -486,11 +486,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
54350 }
54351 }
54352
54353+static int s3c64xx_serial_startup(struct uart_port *port);
54354 static int s3c24xx_serial_startup(struct uart_port *port)
54355 {
54356 struct s3c24xx_uart_port *ourport = to_ourport(port);
54357 int ret;
54358
54359+ /* Startup sequence is different for s3c64xx and higher SoC's */
54360+ if (s3c24xx_serial_has_interrupt_mask(port))
54361+ return s3c64xx_serial_startup(port);
54362+
54363 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
54364 port, (unsigned long long)port->mapbase, port->membase);
54365
54366@@ -1164,10 +1169,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
54367 /* setup info for port */
54368 port->dev = &platdev->dev;
54369
54370- /* Startup sequence is different for s3c64xx and higher SoC's */
54371- if (s3c24xx_serial_has_interrupt_mask(port))
54372- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
54373-
54374 port->uartclk = 1;
54375
54376 if (cfg->uart_flags & UPF_CONS_FLOW) {
54377diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
54378index fbf6c5a..3939d92 100644
54379--- a/drivers/tty/serial/serial_core.c
54380+++ b/drivers/tty/serial/serial_core.c
54381@@ -1333,7 +1333,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
54382
54383 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
54384
54385- if (!port->count || tty_port_close_start(port, tty, filp) == 0)
54386+ if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
54387 return;
54388
54389 /*
54390@@ -1460,7 +1460,7 @@ static void uart_hangup(struct tty_struct *tty)
54391 uart_flush_buffer(tty);
54392 uart_shutdown(tty, state);
54393 spin_lock_irqsave(&port->lock, flags);
54394- port->count = 0;
54395+ atomic_set(&port->count, 0);
54396 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
54397 spin_unlock_irqrestore(&port->lock, flags);
54398 tty_port_tty_set(port, NULL);
54399@@ -1558,7 +1558,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
54400 goto end;
54401 }
54402
54403- port->count++;
54404+ atomic_inc(&port->count);
54405 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
54406 retval = -ENXIO;
54407 goto err_dec_count;
54408@@ -1598,7 +1598,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
54409 end:
54410 return retval;
54411 err_dec_count:
54412- port->count--;
54413+ atomic_inc(&port->count);
54414 mutex_unlock(&port->mutex);
54415 goto end;
54416 }
54417diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
54418index d48e040..0f52764 100644
54419--- a/drivers/tty/synclink.c
54420+++ b/drivers/tty/synclink.c
54421@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
54422
54423 if (debug_level >= DEBUG_LEVEL_INFO)
54424 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
54425- __FILE__,__LINE__, info->device_name, info->port.count);
54426+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
54427
54428 if (tty_port_close_start(&info->port, tty, filp) == 0)
54429 goto cleanup;
54430@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
54431 cleanup:
54432 if (debug_level >= DEBUG_LEVEL_INFO)
54433 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
54434- tty->driver->name, info->port.count);
54435+ tty->driver->name, atomic_read(&info->port.count));
54436
54437 } /* end of mgsl_close() */
54438
54439@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
54440
54441 mgsl_flush_buffer(tty);
54442 shutdown(info);
54443-
54444- info->port.count = 0;
54445+
54446+ atomic_set(&info->port.count, 0);
54447 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54448 info->port.tty = NULL;
54449
54450@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54451
54452 if (debug_level >= DEBUG_LEVEL_INFO)
54453 printk("%s(%d):block_til_ready before block on %s count=%d\n",
54454- __FILE__,__LINE__, tty->driver->name, port->count );
54455+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54456
54457 spin_lock_irqsave(&info->irq_spinlock, flags);
54458 if (!tty_hung_up_p(filp)) {
54459 extra_count = true;
54460- port->count--;
54461+ atomic_dec(&port->count);
54462 }
54463 spin_unlock_irqrestore(&info->irq_spinlock, flags);
54464 port->blocked_open++;
54465@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54466
54467 if (debug_level >= DEBUG_LEVEL_INFO)
54468 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
54469- __FILE__,__LINE__, tty->driver->name, port->count );
54470+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54471
54472 tty_unlock(tty);
54473 schedule();
54474@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54475
54476 /* FIXME: Racy on hangup during close wait */
54477 if (extra_count)
54478- port->count++;
54479+ atomic_inc(&port->count);
54480 port->blocked_open--;
54481
54482 if (debug_level >= DEBUG_LEVEL_INFO)
54483 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
54484- __FILE__,__LINE__, tty->driver->name, port->count );
54485+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54486
54487 if (!retval)
54488 port->flags |= ASYNC_NORMAL_ACTIVE;
54489@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
54490
54491 if (debug_level >= DEBUG_LEVEL_INFO)
54492 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
54493- __FILE__,__LINE__,tty->driver->name, info->port.count);
54494+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
54495
54496 /* If port is closing, signal caller to try again */
54497 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
54498@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
54499 spin_unlock_irqrestore(&info->netlock, flags);
54500 goto cleanup;
54501 }
54502- info->port.count++;
54503+ atomic_inc(&info->port.count);
54504 spin_unlock_irqrestore(&info->netlock, flags);
54505
54506- if (info->port.count == 1) {
54507+ if (atomic_read(&info->port.count) == 1) {
54508 /* 1st open on this device, init hardware */
54509 retval = startup(info);
54510 if (retval < 0)
54511@@ -3446,8 +3446,8 @@ cleanup:
54512 if (retval) {
54513 if (tty->count == 1)
54514 info->port.tty = NULL; /* tty layer will release tty struct */
54515- if(info->port.count)
54516- info->port.count--;
54517+ if (atomic_read(&info->port.count))
54518+ atomic_dec(&info->port.count);
54519 }
54520
54521 return retval;
54522@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54523 unsigned short new_crctype;
54524
54525 /* return error if TTY interface open */
54526- if (info->port.count)
54527+ if (atomic_read(&info->port.count))
54528 return -EBUSY;
54529
54530 switch (encoding)
54531@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
54532
54533 /* arbitrate between network and tty opens */
54534 spin_lock_irqsave(&info->netlock, flags);
54535- if (info->port.count != 0 || info->netcount != 0) {
54536+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54537 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
54538 spin_unlock_irqrestore(&info->netlock, flags);
54539 return -EBUSY;
54540@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54541 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
54542
54543 /* return error if TTY interface open */
54544- if (info->port.count)
54545+ if (atomic_read(&info->port.count))
54546 return -EBUSY;
54547
54548 if (cmd != SIOCWANDEV)
54549diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
54550index c359a91..959fc26 100644
54551--- a/drivers/tty/synclink_gt.c
54552+++ b/drivers/tty/synclink_gt.c
54553@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54554 tty->driver_data = info;
54555 info->port.tty = tty;
54556
54557- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
54558+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
54559
54560 /* If port is closing, signal caller to try again */
54561 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
54562@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54563 mutex_unlock(&info->port.mutex);
54564 goto cleanup;
54565 }
54566- info->port.count++;
54567+ atomic_inc(&info->port.count);
54568 spin_unlock_irqrestore(&info->netlock, flags);
54569
54570- if (info->port.count == 1) {
54571+ if (atomic_read(&info->port.count) == 1) {
54572 /* 1st open on this device, init hardware */
54573 retval = startup(info);
54574 if (retval < 0) {
54575@@ -715,8 +715,8 @@ cleanup:
54576 if (retval) {
54577 if (tty->count == 1)
54578 info->port.tty = NULL; /* tty layer will release tty struct */
54579- if(info->port.count)
54580- info->port.count--;
54581+ if(atomic_read(&info->port.count))
54582+ atomic_dec(&info->port.count);
54583 }
54584
54585 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
54586@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54587
54588 if (sanity_check(info, tty->name, "close"))
54589 return;
54590- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
54591+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
54592
54593 if (tty_port_close_start(&info->port, tty, filp) == 0)
54594 goto cleanup;
54595@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54596 tty_port_close_end(&info->port, tty);
54597 info->port.tty = NULL;
54598 cleanup:
54599- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
54600+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
54601 }
54602
54603 static void hangup(struct tty_struct *tty)
54604@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
54605 shutdown(info);
54606
54607 spin_lock_irqsave(&info->port.lock, flags);
54608- info->port.count = 0;
54609+ atomic_set(&info->port.count, 0);
54610 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54611 info->port.tty = NULL;
54612 spin_unlock_irqrestore(&info->port.lock, flags);
54613@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54614 unsigned short new_crctype;
54615
54616 /* return error if TTY interface open */
54617- if (info->port.count)
54618+ if (atomic_read(&info->port.count))
54619 return -EBUSY;
54620
54621 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
54622@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
54623
54624 /* arbitrate between network and tty opens */
54625 spin_lock_irqsave(&info->netlock, flags);
54626- if (info->port.count != 0 || info->netcount != 0) {
54627+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54628 DBGINFO(("%s hdlc_open busy\n", dev->name));
54629 spin_unlock_irqrestore(&info->netlock, flags);
54630 return -EBUSY;
54631@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54632 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
54633
54634 /* return error if TTY interface open */
54635- if (info->port.count)
54636+ if (atomic_read(&info->port.count))
54637 return -EBUSY;
54638
54639 if (cmd != SIOCWANDEV)
54640@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
54641 if (port == NULL)
54642 continue;
54643 spin_lock(&port->lock);
54644- if ((port->port.count || port->netcount) &&
54645+ if ((atomic_read(&port->port.count) || port->netcount) &&
54646 port->pending_bh && !port->bh_running &&
54647 !port->bh_requested) {
54648 DBGISR(("%s bh queued\n", port->device_name));
54649@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54650 spin_lock_irqsave(&info->lock, flags);
54651 if (!tty_hung_up_p(filp)) {
54652 extra_count = true;
54653- port->count--;
54654+ atomic_dec(&port->count);
54655 }
54656 spin_unlock_irqrestore(&info->lock, flags);
54657 port->blocked_open++;
54658@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54659 remove_wait_queue(&port->open_wait, &wait);
54660
54661 if (extra_count)
54662- port->count++;
54663+ atomic_inc(&port->count);
54664 port->blocked_open--;
54665
54666 if (!retval)
54667diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
54668index 53ba853..3c30f6d 100644
54669--- a/drivers/tty/synclinkmp.c
54670+++ b/drivers/tty/synclinkmp.c
54671@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54672
54673 if (debug_level >= DEBUG_LEVEL_INFO)
54674 printk("%s(%d):%s open(), old ref count = %d\n",
54675- __FILE__,__LINE__,tty->driver->name, info->port.count);
54676+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
54677
54678 /* If port is closing, signal caller to try again */
54679 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
54680@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54681 spin_unlock_irqrestore(&info->netlock, flags);
54682 goto cleanup;
54683 }
54684- info->port.count++;
54685+ atomic_inc(&info->port.count);
54686 spin_unlock_irqrestore(&info->netlock, flags);
54687
54688- if (info->port.count == 1) {
54689+ if (atomic_read(&info->port.count) == 1) {
54690 /* 1st open on this device, init hardware */
54691 retval = startup(info);
54692 if (retval < 0)
54693@@ -796,8 +796,8 @@ cleanup:
54694 if (retval) {
54695 if (tty->count == 1)
54696 info->port.tty = NULL; /* tty layer will release tty struct */
54697- if(info->port.count)
54698- info->port.count--;
54699+ if(atomic_read(&info->port.count))
54700+ atomic_dec(&info->port.count);
54701 }
54702
54703 return retval;
54704@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54705
54706 if (debug_level >= DEBUG_LEVEL_INFO)
54707 printk("%s(%d):%s close() entry, count=%d\n",
54708- __FILE__,__LINE__, info->device_name, info->port.count);
54709+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
54710
54711 if (tty_port_close_start(&info->port, tty, filp) == 0)
54712 goto cleanup;
54713@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54714 cleanup:
54715 if (debug_level >= DEBUG_LEVEL_INFO)
54716 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
54717- tty->driver->name, info->port.count);
54718+ tty->driver->name, atomic_read(&info->port.count));
54719 }
54720
54721 /* Called by tty_hangup() when a hangup is signaled.
54722@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
54723 shutdown(info);
54724
54725 spin_lock_irqsave(&info->port.lock, flags);
54726- info->port.count = 0;
54727+ atomic_set(&info->port.count, 0);
54728 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54729 info->port.tty = NULL;
54730 spin_unlock_irqrestore(&info->port.lock, flags);
54731@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54732 unsigned short new_crctype;
54733
54734 /* return error if TTY interface open */
54735- if (info->port.count)
54736+ if (atomic_read(&info->port.count))
54737 return -EBUSY;
54738
54739 switch (encoding)
54740@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
54741
54742 /* arbitrate between network and tty opens */
54743 spin_lock_irqsave(&info->netlock, flags);
54744- if (info->port.count != 0 || info->netcount != 0) {
54745+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54746 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
54747 spin_unlock_irqrestore(&info->netlock, flags);
54748 return -EBUSY;
54749@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54750 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
54751
54752 /* return error if TTY interface open */
54753- if (info->port.count)
54754+ if (atomic_read(&info->port.count))
54755 return -EBUSY;
54756
54757 if (cmd != SIOCWANDEV)
54758@@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
54759 * do not request bottom half processing if the
54760 * device is not open in a normal mode.
54761 */
54762- if ( port && (port->port.count || port->netcount) &&
54763+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
54764 port->pending_bh && !port->bh_running &&
54765 !port->bh_requested ) {
54766 if ( debug_level >= DEBUG_LEVEL_ISR )
54767@@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54768
54769 if (debug_level >= DEBUG_LEVEL_INFO)
54770 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
54771- __FILE__,__LINE__, tty->driver->name, port->count );
54772+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54773
54774 spin_lock_irqsave(&info->lock, flags);
54775 if (!tty_hung_up_p(filp)) {
54776 extra_count = true;
54777- port->count--;
54778+ atomic_dec(&port->count);
54779 }
54780 spin_unlock_irqrestore(&info->lock, flags);
54781 port->blocked_open++;
54782@@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54783
54784 if (debug_level >= DEBUG_LEVEL_INFO)
54785 printk("%s(%d):%s block_til_ready() count=%d\n",
54786- __FILE__,__LINE__, tty->driver->name, port->count );
54787+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54788
54789 tty_unlock(tty);
54790 schedule();
54791@@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54792 remove_wait_queue(&port->open_wait, &wait);
54793
54794 if (extra_count)
54795- port->count++;
54796+ atomic_inc(&port->count);
54797 port->blocked_open--;
54798
54799 if (debug_level >= DEBUG_LEVEL_INFO)
54800 printk("%s(%d):%s block_til_ready() after, count=%d\n",
54801- __FILE__,__LINE__, tty->driver->name, port->count );
54802+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54803
54804 if (!retval)
54805 port->flags |= ASYNC_NORMAL_ACTIVE;
54806diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
54807index 454b658..57b1430 100644
54808--- a/drivers/tty/sysrq.c
54809+++ b/drivers/tty/sysrq.c
54810@@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
54811 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
54812 size_t count, loff_t *ppos)
54813 {
54814- if (count) {
54815+ if (count && capable(CAP_SYS_ADMIN)) {
54816 char c;
54817
54818 if (get_user(c, buf))
54819diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
54820index 3411071..86f2cf2 100644
54821--- a/drivers/tty/tty_io.c
54822+++ b/drivers/tty/tty_io.c
54823@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
54824
54825 void tty_default_fops(struct file_operations *fops)
54826 {
54827- *fops = tty_fops;
54828+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
54829 }
54830
54831 /*
54832diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
54833index 2d822aa..a566234 100644
54834--- a/drivers/tty/tty_ldisc.c
54835+++ b/drivers/tty/tty_ldisc.c
54836@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
54837 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54838 tty_ldiscs[disc] = new_ldisc;
54839 new_ldisc->num = disc;
54840- new_ldisc->refcount = 0;
54841+ atomic_set(&new_ldisc->refcount, 0);
54842 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54843
54844 return ret;
54845@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
54846 return -EINVAL;
54847
54848 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54849- if (tty_ldiscs[disc]->refcount)
54850+ if (atomic_read(&tty_ldiscs[disc]->refcount))
54851 ret = -EBUSY;
54852 else
54853 tty_ldiscs[disc] = NULL;
54854@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
54855 if (ldops) {
54856 ret = ERR_PTR(-EAGAIN);
54857 if (try_module_get(ldops->owner)) {
54858- ldops->refcount++;
54859+ atomic_inc(&ldops->refcount);
54860 ret = ldops;
54861 }
54862 }
54863@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
54864 unsigned long flags;
54865
54866 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54867- ldops->refcount--;
54868+ atomic_dec(&ldops->refcount);
54869 module_put(ldops->owner);
54870 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54871 }
54872diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
54873index 3f746c8..2f2fcaa 100644
54874--- a/drivers/tty/tty_port.c
54875+++ b/drivers/tty/tty_port.c
54876@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
54877 unsigned long flags;
54878
54879 spin_lock_irqsave(&port->lock, flags);
54880- port->count = 0;
54881+ atomic_set(&port->count, 0);
54882 port->flags &= ~ASYNC_NORMAL_ACTIVE;
54883 tty = port->tty;
54884 if (tty)
54885@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54886 /* The port lock protects the port counts */
54887 spin_lock_irqsave(&port->lock, flags);
54888 if (!tty_hung_up_p(filp))
54889- port->count--;
54890+ atomic_dec(&port->count);
54891 port->blocked_open++;
54892 spin_unlock_irqrestore(&port->lock, flags);
54893
54894@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54895 we must not mess that up further */
54896 spin_lock_irqsave(&port->lock, flags);
54897 if (!tty_hung_up_p(filp))
54898- port->count++;
54899+ atomic_inc(&port->count);
54900 port->blocked_open--;
54901 if (retval == 0)
54902 port->flags |= ASYNC_NORMAL_ACTIVE;
54903@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
54904 return 0;
54905 }
54906
54907- if (tty->count == 1 && port->count != 1) {
54908+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
54909 printk(KERN_WARNING
54910 "tty_port_close_start: tty->count = 1 port count = %d.\n",
54911- port->count);
54912- port->count = 1;
54913+ atomic_read(&port->count));
54914+ atomic_set(&port->count, 1);
54915 }
54916- if (--port->count < 0) {
54917+ if (atomic_dec_return(&port->count) < 0) {
54918 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
54919- port->count);
54920- port->count = 0;
54921+ atomic_read(&port->count));
54922+ atomic_set(&port->count, 0);
54923 }
54924
54925- if (port->count) {
54926+ if (atomic_read(&port->count)) {
54927 spin_unlock_irqrestore(&port->lock, flags);
54928 return 0;
54929 }
54930@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
54931 {
54932 spin_lock_irq(&port->lock);
54933 if (!tty_hung_up_p(filp))
54934- ++port->count;
54935+ atomic_inc(&port->count);
54936 spin_unlock_irq(&port->lock);
54937 tty_port_tty_set(port, tty);
54938
54939diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
54940index d0e3a44..5f8b754 100644
54941--- a/drivers/tty/vt/keyboard.c
54942+++ b/drivers/tty/vt/keyboard.c
54943@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
54944 kbd->kbdmode == VC_OFF) &&
54945 value != KVAL(K_SAK))
54946 return; /* SAK is allowed even in raw mode */
54947+
54948+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54949+ {
54950+ void *func = fn_handler[value];
54951+ if (func == fn_show_state || func == fn_show_ptregs ||
54952+ func == fn_show_mem)
54953+ return;
54954+ }
54955+#endif
54956+
54957 fn_handler[value](vc);
54958 }
54959
54960@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54961 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54962 return -EFAULT;
54963
54964- if (!capable(CAP_SYS_TTY_CONFIG))
54965- perm = 0;
54966-
54967 switch (cmd) {
54968 case KDGKBENT:
54969 /* Ensure another thread doesn't free it under us */
54970@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54971 spin_unlock_irqrestore(&kbd_event_lock, flags);
54972 return put_user(val, &user_kbe->kb_value);
54973 case KDSKBENT:
54974+ if (!capable(CAP_SYS_TTY_CONFIG))
54975+ perm = 0;
54976+
54977 if (!perm)
54978 return -EPERM;
54979 if (!i && v == K_NOSUCHMAP) {
54980@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54981 int i, j, k;
54982 int ret;
54983
54984- if (!capable(CAP_SYS_TTY_CONFIG))
54985- perm = 0;
54986-
54987 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54988 if (!kbs) {
54989 ret = -ENOMEM;
54990@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54991 kfree(kbs);
54992 return ((p && *p) ? -EOVERFLOW : 0);
54993 case KDSKBSENT:
54994+ if (!capable(CAP_SYS_TTY_CONFIG))
54995+ perm = 0;
54996+
54997 if (!perm) {
54998 ret = -EPERM;
54999 goto reterr;
55000diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
55001index a673e5b..36e5d32 100644
55002--- a/drivers/uio/uio.c
55003+++ b/drivers/uio/uio.c
55004@@ -25,6 +25,7 @@
55005 #include <linux/kobject.h>
55006 #include <linux/cdev.h>
55007 #include <linux/uio_driver.h>
55008+#include <asm/local.h>
55009
55010 #define UIO_MAX_DEVICES (1U << MINORBITS)
55011
55012@@ -32,7 +33,7 @@ struct uio_device {
55013 struct module *owner;
55014 struct device *dev;
55015 int minor;
55016- atomic_t event;
55017+ atomic_unchecked_t event;
55018 struct fasync_struct *async_queue;
55019 wait_queue_head_t wait;
55020 struct uio_info *info;
55021@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
55022 struct device_attribute *attr, char *buf)
55023 {
55024 struct uio_device *idev = dev_get_drvdata(dev);
55025- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
55026+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
55027 }
55028 static DEVICE_ATTR_RO(event);
55029
55030@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
55031 {
55032 struct uio_device *idev = info->uio_dev;
55033
55034- atomic_inc(&idev->event);
55035+ atomic_inc_unchecked(&idev->event);
55036 wake_up_interruptible(&idev->wait);
55037 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
55038 }
55039@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
55040 }
55041
55042 listener->dev = idev;
55043- listener->event_count = atomic_read(&idev->event);
55044+ listener->event_count = atomic_read_unchecked(&idev->event);
55045 filep->private_data = listener;
55046
55047 if (idev->info->open) {
55048@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
55049 return -EIO;
55050
55051 poll_wait(filep, &idev->wait, wait);
55052- if (listener->event_count != atomic_read(&idev->event))
55053+ if (listener->event_count != atomic_read_unchecked(&idev->event))
55054 return POLLIN | POLLRDNORM;
55055 return 0;
55056 }
55057@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
55058 do {
55059 set_current_state(TASK_INTERRUPTIBLE);
55060
55061- event_count = atomic_read(&idev->event);
55062+ event_count = atomic_read_unchecked(&idev->event);
55063 if (event_count != listener->event_count) {
55064 if (copy_to_user(buf, &event_count, count))
55065 retval = -EFAULT;
55066@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
55067 static int uio_find_mem_index(struct vm_area_struct *vma)
55068 {
55069 struct uio_device *idev = vma->vm_private_data;
55070+ unsigned long size;
55071
55072 if (vma->vm_pgoff < MAX_UIO_MAPS) {
55073- if (idev->info->mem[vma->vm_pgoff].size == 0)
55074+ size = idev->info->mem[vma->vm_pgoff].size;
55075+ if (size == 0)
55076+ return -1;
55077+ if (vma->vm_end - vma->vm_start > size)
55078 return -1;
55079 return (int)vma->vm_pgoff;
55080 }
55081@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
55082 idev->owner = owner;
55083 idev->info = info;
55084 init_waitqueue_head(&idev->wait);
55085- atomic_set(&idev->event, 0);
55086+ atomic_set_unchecked(&idev->event, 0);
55087
55088 ret = uio_get_minor(idev);
55089 if (ret)
55090diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
55091index 813d4d3..a71934f 100644
55092--- a/drivers/usb/atm/cxacru.c
55093+++ b/drivers/usb/atm/cxacru.c
55094@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
55095 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
55096 if (ret < 2)
55097 return -EINVAL;
55098- if (index < 0 || index > 0x7f)
55099+ if (index > 0x7f)
55100 return -EINVAL;
55101 pos += tmp;
55102
55103diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
55104index dada014..1d0d517 100644
55105--- a/drivers/usb/atm/usbatm.c
55106+++ b/drivers/usb/atm/usbatm.c
55107@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55108 if (printk_ratelimit())
55109 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
55110 __func__, vpi, vci);
55111- atomic_inc(&vcc->stats->rx_err);
55112+ atomic_inc_unchecked(&vcc->stats->rx_err);
55113 return;
55114 }
55115
55116@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55117 if (length > ATM_MAX_AAL5_PDU) {
55118 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
55119 __func__, length, vcc);
55120- atomic_inc(&vcc->stats->rx_err);
55121+ atomic_inc_unchecked(&vcc->stats->rx_err);
55122 goto out;
55123 }
55124
55125@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55126 if (sarb->len < pdu_length) {
55127 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
55128 __func__, pdu_length, sarb->len, vcc);
55129- atomic_inc(&vcc->stats->rx_err);
55130+ atomic_inc_unchecked(&vcc->stats->rx_err);
55131 goto out;
55132 }
55133
55134 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
55135 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
55136 __func__, vcc);
55137- atomic_inc(&vcc->stats->rx_err);
55138+ atomic_inc_unchecked(&vcc->stats->rx_err);
55139 goto out;
55140 }
55141
55142@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55143 if (printk_ratelimit())
55144 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
55145 __func__, length);
55146- atomic_inc(&vcc->stats->rx_drop);
55147+ atomic_inc_unchecked(&vcc->stats->rx_drop);
55148 goto out;
55149 }
55150
55151@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55152
55153 vcc->push(vcc, skb);
55154
55155- atomic_inc(&vcc->stats->rx);
55156+ atomic_inc_unchecked(&vcc->stats->rx);
55157 out:
55158 skb_trim(sarb, 0);
55159 }
55160@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
55161 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
55162
55163 usbatm_pop(vcc, skb);
55164- atomic_inc(&vcc->stats->tx);
55165+ atomic_inc_unchecked(&vcc->stats->tx);
55166
55167 skb = skb_dequeue(&instance->sndqueue);
55168 }
55169@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
55170 if (!left--)
55171 return sprintf(page,
55172 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
55173- atomic_read(&atm_dev->stats.aal5.tx),
55174- atomic_read(&atm_dev->stats.aal5.tx_err),
55175- atomic_read(&atm_dev->stats.aal5.rx),
55176- atomic_read(&atm_dev->stats.aal5.rx_err),
55177- atomic_read(&atm_dev->stats.aal5.rx_drop));
55178+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
55179+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
55180+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
55181+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
55182+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
55183
55184 if (!left--) {
55185 if (instance->disconnected)
55186diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
55187index 2a3bbdf..91d72cf 100644
55188--- a/drivers/usb/core/devices.c
55189+++ b/drivers/usb/core/devices.c
55190@@ -126,7 +126,7 @@ static const char format_endpt[] =
55191 * time it gets called.
55192 */
55193 static struct device_connect_event {
55194- atomic_t count;
55195+ atomic_unchecked_t count;
55196 wait_queue_head_t wait;
55197 } device_event = {
55198 .count = ATOMIC_INIT(1),
55199@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
55200
55201 void usbfs_conn_disc_event(void)
55202 {
55203- atomic_add(2, &device_event.count);
55204+ atomic_add_unchecked(2, &device_event.count);
55205 wake_up(&device_event.wait);
55206 }
55207
55208@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
55209
55210 poll_wait(file, &device_event.wait, wait);
55211
55212- event_count = atomic_read(&device_event.count);
55213+ event_count = atomic_read_unchecked(&device_event.count);
55214 if (file->f_version != event_count) {
55215 file->f_version = event_count;
55216 return POLLIN | POLLRDNORM;
55217diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
55218index 257876e..4304364 100644
55219--- a/drivers/usb/core/devio.c
55220+++ b/drivers/usb/core/devio.c
55221@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
55222 struct usb_dev_state *ps = file->private_data;
55223 struct usb_device *dev = ps->dev;
55224 ssize_t ret = 0;
55225- unsigned len;
55226+ size_t len;
55227 loff_t pos;
55228 int i;
55229
55230@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
55231 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
55232 struct usb_config_descriptor *config =
55233 (struct usb_config_descriptor *)dev->rawdescriptors[i];
55234- unsigned int length = le16_to_cpu(config->wTotalLength);
55235+ size_t length = le16_to_cpu(config->wTotalLength);
55236
55237 if (*ppos < pos + length) {
55238
55239 /* The descriptor may claim to be longer than it
55240 * really is. Here is the actual allocated length. */
55241- unsigned alloclen =
55242+ size_t alloclen =
55243 le16_to_cpu(dev->config[i].desc.wTotalLength);
55244
55245- len = length - (*ppos - pos);
55246+ len = length + pos - *ppos;
55247 if (len > nbytes)
55248 len = nbytes;
55249
55250 /* Simply don't write (skip over) unallocated parts */
55251 if (alloclen > (*ppos - pos)) {
55252- alloclen -= (*ppos - pos);
55253+ alloclen = alloclen + pos - *ppos;
55254 if (copy_to_user(buf,
55255 dev->rawdescriptors[i] + (*ppos - pos),
55256 min(len, alloclen))) {
55257diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
55258index bec31e2..b8091cd 100644
55259--- a/drivers/usb/core/hcd.c
55260+++ b/drivers/usb/core/hcd.c
55261@@ -1554,7 +1554,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
55262 */
55263 usb_get_urb(urb);
55264 atomic_inc(&urb->use_count);
55265- atomic_inc(&urb->dev->urbnum);
55266+ atomic_inc_unchecked(&urb->dev->urbnum);
55267 usbmon_urb_submit(&hcd->self, urb);
55268
55269 /* NOTE requirements on root-hub callers (usbfs and the hub
55270@@ -1581,7 +1581,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
55271 urb->hcpriv = NULL;
55272 INIT_LIST_HEAD(&urb->urb_list);
55273 atomic_dec(&urb->use_count);
55274- atomic_dec(&urb->dev->urbnum);
55275+ atomic_dec_unchecked(&urb->dev->urbnum);
55276 if (atomic_read(&urb->reject))
55277 wake_up(&usb_kill_urb_queue);
55278 usb_put_urb(urb);
55279diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
55280index 0e950ad..a2be5b0 100644
55281--- a/drivers/usb/core/hub.c
55282+++ b/drivers/usb/core/hub.c
55283@@ -27,6 +27,7 @@
55284 #include <linux/freezer.h>
55285 #include <linux/random.h>
55286 #include <linux/pm_qos.h>
55287+#include <linux/grsecurity.h>
55288
55289 #include <asm/uaccess.h>
55290 #include <asm/byteorder.h>
55291@@ -4594,6 +4595,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
55292 goto done;
55293 return;
55294 }
55295+
55296+ if (gr_handle_new_usb())
55297+ goto done;
55298+
55299 if (hub_is_superspeed(hub->hdev))
55300 unit_load = 150;
55301 else
55302diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
55303index 0c8a7fc..c45b40a 100644
55304--- a/drivers/usb/core/message.c
55305+++ b/drivers/usb/core/message.c
55306@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
55307 * Return: If successful, the number of bytes transferred. Otherwise, a negative
55308 * error number.
55309 */
55310-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
55311+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
55312 __u8 requesttype, __u16 value, __u16 index, void *data,
55313 __u16 size, int timeout)
55314 {
55315@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
55316 * If successful, 0. Otherwise a negative error number. The number of actual
55317 * bytes transferred will be stored in the @actual_length parameter.
55318 */
55319-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
55320+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
55321 void *data, int len, int *actual_length, int timeout)
55322 {
55323 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
55324@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
55325 * bytes transferred will be stored in the @actual_length parameter.
55326 *
55327 */
55328-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
55329+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
55330 void *data, int len, int *actual_length, int timeout)
55331 {
55332 struct urb *urb;
55333diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
55334index 1236c60..d47a51c 100644
55335--- a/drivers/usb/core/sysfs.c
55336+++ b/drivers/usb/core/sysfs.c
55337@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
55338 struct usb_device *udev;
55339
55340 udev = to_usb_device(dev);
55341- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
55342+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
55343 }
55344 static DEVICE_ATTR_RO(urbnum);
55345
55346diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
55347index 4d11449..f4ccabf 100644
55348--- a/drivers/usb/core/usb.c
55349+++ b/drivers/usb/core/usb.c
55350@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
55351 set_dev_node(&dev->dev, dev_to_node(bus->controller));
55352 dev->state = USB_STATE_ATTACHED;
55353 dev->lpm_disable_count = 1;
55354- atomic_set(&dev->urbnum, 0);
55355+ atomic_set_unchecked(&dev->urbnum, 0);
55356
55357 INIT_LIST_HEAD(&dev->ep0.urb_list);
55358 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
55359diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
55360index dab7927..6f53afc 100644
55361--- a/drivers/usb/dwc3/gadget.c
55362+++ b/drivers/usb/dwc3/gadget.c
55363@@ -615,8 +615,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
55364 if (!usb_endpoint_xfer_isoc(desc))
55365 return 0;
55366
55367- memset(&trb_link, 0, sizeof(trb_link));
55368-
55369 /* Link TRB for ISOC. The HWO bit is never reset */
55370 trb_st_hw = &dep->trb_pool[0];
55371
55372diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
55373index 8cfc319..4868255 100644
55374--- a/drivers/usb/early/ehci-dbgp.c
55375+++ b/drivers/usb/early/ehci-dbgp.c
55376@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
55377
55378 #ifdef CONFIG_KGDB
55379 static struct kgdb_io kgdbdbgp_io_ops;
55380-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
55381+static struct kgdb_io kgdbdbgp_io_ops_console;
55382+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
55383 #else
55384 #define dbgp_kgdb_mode (0)
55385 #endif
55386@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
55387 .write_char = kgdbdbgp_write_char,
55388 };
55389
55390+static struct kgdb_io kgdbdbgp_io_ops_console = {
55391+ .name = "kgdbdbgp",
55392+ .read_char = kgdbdbgp_read_char,
55393+ .write_char = kgdbdbgp_write_char,
55394+ .is_console = 1
55395+};
55396+
55397 static int kgdbdbgp_wait_time;
55398
55399 static int __init kgdbdbgp_parse_config(char *str)
55400@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
55401 ptr++;
55402 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
55403 }
55404- kgdb_register_io_module(&kgdbdbgp_io_ops);
55405- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
55406+ if (early_dbgp_console.index != -1)
55407+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
55408+ else
55409+ kgdb_register_io_module(&kgdbdbgp_io_ops);
55410
55411 return 0;
55412 }
55413diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
55414index 2b4c82d..06a8ee6 100644
55415--- a/drivers/usb/gadget/f_uac1.c
55416+++ b/drivers/usb/gadget/f_uac1.c
55417@@ -13,6 +13,7 @@
55418 #include <linux/kernel.h>
55419 #include <linux/device.h>
55420 #include <linux/atomic.h>
55421+#include <linux/module.h>
55422
55423 #include "u_uac1.h"
55424
55425diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
55426index ad0aca8..8ff84865 100644
55427--- a/drivers/usb/gadget/u_serial.c
55428+++ b/drivers/usb/gadget/u_serial.c
55429@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
55430 spin_lock_irq(&port->port_lock);
55431
55432 /* already open? Great. */
55433- if (port->port.count) {
55434+ if (atomic_read(&port->port.count)) {
55435 status = 0;
55436- port->port.count++;
55437+ atomic_inc(&port->port.count);
55438
55439 /* currently opening/closing? wait ... */
55440 } else if (port->openclose) {
55441@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
55442 tty->driver_data = port;
55443 port->port.tty = tty;
55444
55445- port->port.count = 1;
55446+ atomic_set(&port->port.count, 1);
55447 port->openclose = false;
55448
55449 /* if connected, start the I/O stream */
55450@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
55451
55452 spin_lock_irq(&port->port_lock);
55453
55454- if (port->port.count != 1) {
55455- if (port->port.count == 0)
55456+ if (atomic_read(&port->port.count) != 1) {
55457+ if (atomic_read(&port->port.count) == 0)
55458 WARN_ON(1);
55459 else
55460- --port->port.count;
55461+ atomic_dec(&port->port.count);
55462 goto exit;
55463 }
55464
55465@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
55466 * and sleep if necessary
55467 */
55468 port->openclose = true;
55469- port->port.count = 0;
55470+ atomic_set(&port->port.count, 0);
55471
55472 gser = port->port_usb;
55473 if (gser && gser->disconnect)
55474@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
55475 int cond;
55476
55477 spin_lock_irq(&port->port_lock);
55478- cond = (port->port.count == 0) && !port->openclose;
55479+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
55480 spin_unlock_irq(&port->port_lock);
55481 return cond;
55482 }
55483@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
55484 /* if it's already open, start I/O ... and notify the serial
55485 * protocol about open/close status (connect/disconnect).
55486 */
55487- if (port->port.count) {
55488+ if (atomic_read(&port->port.count)) {
55489 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
55490 gs_start_io(port);
55491 if (gser->connect)
55492@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
55493
55494 port->port_usb = NULL;
55495 gser->ioport = NULL;
55496- if (port->port.count > 0 || port->openclose) {
55497+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
55498 wake_up_interruptible(&port->drain_wait);
55499 if (port->port.tty)
55500 tty_hangup(port->port.tty);
55501@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
55502
55503 /* finally, free any unused/unusable I/O buffers */
55504 spin_lock_irqsave(&port->port_lock, flags);
55505- if (port->port.count == 0 && !port->openclose)
55506+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
55507 gs_buf_free(&port->port_write_buf);
55508 gs_free_requests(gser->out, &port->read_pool, NULL);
55509 gs_free_requests(gser->out, &port->read_queue, NULL);
55510diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
55511index 7a55fea..cc0ed4f 100644
55512--- a/drivers/usb/gadget/u_uac1.c
55513+++ b/drivers/usb/gadget/u_uac1.c
55514@@ -16,6 +16,7 @@
55515 #include <linux/ctype.h>
55516 #include <linux/random.h>
55517 #include <linux/syscalls.h>
55518+#include <linux/module.h>
55519
55520 #include "u_uac1.h"
55521
55522diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
55523index cc305c7..cf6da4a 100644
55524--- a/drivers/usb/host/ehci-hub.c
55525+++ b/drivers/usb/host/ehci-hub.c
55526@@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
55527 urb->transfer_flags = URB_DIR_IN;
55528 usb_get_urb(urb);
55529 atomic_inc(&urb->use_count);
55530- atomic_inc(&urb->dev->urbnum);
55531+ atomic_inc_unchecked(&urb->dev->urbnum);
55532 urb->setup_dma = dma_map_single(
55533 hcd->self.controller,
55534 urb->setup_packet,
55535@@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
55536 urb->status = -EINPROGRESS;
55537 usb_get_urb(urb);
55538 atomic_inc(&urb->use_count);
55539- atomic_inc(&urb->dev->urbnum);
55540+ atomic_inc_unchecked(&urb->dev->urbnum);
55541 retval = submit_single_step_set_feature(hcd, urb, 0);
55542 if (!retval && !wait_for_completion_timeout(&done,
55543 msecs_to_jiffies(2000))) {
55544diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
55545index d0d8fad..668ef7b 100644
55546--- a/drivers/usb/host/hwa-hc.c
55547+++ b/drivers/usb/host/hwa-hc.c
55548@@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
55549 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
55550 struct wahc *wa = &hwahc->wa;
55551 struct device *dev = &wa->usb_iface->dev;
55552- u8 mas_le[UWB_NUM_MAS/8];
55553+ u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
55554+
55555+ if (mas_le == NULL)
55556+ return -ENOMEM;
55557
55558 /* Set the stream index */
55559 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
55560@@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
55561 WUSB_REQ_SET_WUSB_MAS,
55562 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
55563 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
55564- mas_le, 32, USB_CTRL_SET_TIMEOUT);
55565+ mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
55566 if (result < 0)
55567 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
55568 out:
55569+ kfree(mas_le);
55570+
55571 return result;
55572 }
55573
55574diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
55575index b3d245e..99549ed 100644
55576--- a/drivers/usb/misc/appledisplay.c
55577+++ b/drivers/usb/misc/appledisplay.c
55578@@ -84,7 +84,7 @@ struct appledisplay {
55579 struct mutex sysfslock; /* concurrent read and write */
55580 };
55581
55582-static atomic_t count_displays = ATOMIC_INIT(0);
55583+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
55584 static struct workqueue_struct *wq;
55585
55586 static void appledisplay_complete(struct urb *urb)
55587@@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
55588
55589 /* Register backlight device */
55590 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
55591- atomic_inc_return(&count_displays) - 1);
55592+ atomic_inc_return_unchecked(&count_displays) - 1);
55593 memset(&props, 0, sizeof(struct backlight_properties));
55594 props.type = BACKLIGHT_RAW;
55595 props.max_brightness = 0xff;
55596diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
55597index 8d7fc48..01c4986 100644
55598--- a/drivers/usb/serial/console.c
55599+++ b/drivers/usb/serial/console.c
55600@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
55601
55602 info->port = port;
55603
55604- ++port->port.count;
55605+ atomic_inc(&port->port.count);
55606 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
55607 if (serial->type->set_termios) {
55608 /*
55609@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
55610 }
55611 /* Now that any required fake tty operations are completed restore
55612 * the tty port count */
55613- --port->port.count;
55614+ atomic_dec(&port->port.count);
55615 /* The console is special in terms of closing the device so
55616 * indicate this port is now acting as a system console. */
55617 port->port.console = 1;
55618@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
55619 free_tty:
55620 kfree(tty);
55621 reset_open_count:
55622- port->port.count = 0;
55623+ atomic_set(&port->port.count, 0);
55624 usb_autopm_put_interface(serial->interface);
55625 error_get_interface:
55626 usb_serial_put(serial);
55627@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
55628 static void usb_console_write(struct console *co,
55629 const char *buf, unsigned count)
55630 {
55631- static struct usbcons_info *info = &usbcons_info;
55632+ struct usbcons_info *info = &usbcons_info;
55633 struct usb_serial_port *port = info->port;
55634 struct usb_serial *serial;
55635 int retval = -ENODEV;
55636diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
55637index 307e339..6aa97cb 100644
55638--- a/drivers/usb/storage/usb.h
55639+++ b/drivers/usb/storage/usb.h
55640@@ -63,7 +63,7 @@ struct us_unusual_dev {
55641 __u8 useProtocol;
55642 __u8 useTransport;
55643 int (*initFunction)(struct us_data *);
55644-};
55645+} __do_const;
55646
55647
55648 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
55649diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
55650index f2a8d29..7bc3fe7 100644
55651--- a/drivers/usb/wusbcore/wa-hc.h
55652+++ b/drivers/usb/wusbcore/wa-hc.h
55653@@ -240,7 +240,7 @@ struct wahc {
55654 spinlock_t xfer_list_lock;
55655 struct work_struct xfer_enqueue_work;
55656 struct work_struct xfer_error_work;
55657- atomic_t xfer_id_count;
55658+ atomic_unchecked_t xfer_id_count;
55659
55660 kernel_ulong_t quirks;
55661 };
55662@@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
55663 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
55664 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
55665 wa->dto_in_use = 0;
55666- atomic_set(&wa->xfer_id_count, 1);
55667+ atomic_set_unchecked(&wa->xfer_id_count, 1);
55668 /* init the buf in URBs */
55669 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
55670 usb_init_urb(&(wa->buf_in_urbs[index]));
55671diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
55672index 3e2e4ed..060c9b8 100644
55673--- a/drivers/usb/wusbcore/wa-xfer.c
55674+++ b/drivers/usb/wusbcore/wa-xfer.c
55675@@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
55676 */
55677 static void wa_xfer_id_init(struct wa_xfer *xfer)
55678 {
55679- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
55680+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
55681 }
55682
55683 /* Return the xfer's ID. */
55684diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
55685index f018d8d..ccab63f 100644
55686--- a/drivers/vfio/vfio.c
55687+++ b/drivers/vfio/vfio.c
55688@@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
55689 return 0;
55690
55691 /* TODO Prevent device auto probing */
55692- WARN("Device %s added to live group %d!\n", dev_name(dev),
55693+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
55694 iommu_group_id(group->iommu_group));
55695
55696 return 0;
55697diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
55698index 5174eba..451e6bc 100644
55699--- a/drivers/vhost/vringh.c
55700+++ b/drivers/vhost/vringh.c
55701@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
55702 /* Userspace access helpers: in this case, addresses are really userspace. */
55703 static inline int getu16_user(u16 *val, const u16 *p)
55704 {
55705- return get_user(*val, (__force u16 __user *)p);
55706+ return get_user(*val, (u16 __force_user *)p);
55707 }
55708
55709 static inline int putu16_user(u16 *p, u16 val)
55710 {
55711- return put_user(val, (__force u16 __user *)p);
55712+ return put_user(val, (u16 __force_user *)p);
55713 }
55714
55715 static inline int copydesc_user(void *dst, const void *src, size_t len)
55716 {
55717- return copy_from_user(dst, (__force void __user *)src, len) ?
55718+ return copy_from_user(dst, (void __force_user *)src, len) ?
55719 -EFAULT : 0;
55720 }
55721
55722@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
55723 const struct vring_used_elem *src,
55724 unsigned int num)
55725 {
55726- return copy_to_user((__force void __user *)dst, src,
55727+ return copy_to_user((void __force_user *)dst, src,
55728 sizeof(*dst) * num) ? -EFAULT : 0;
55729 }
55730
55731 static inline int xfer_from_user(void *src, void *dst, size_t len)
55732 {
55733- return copy_from_user(dst, (__force void __user *)src, len) ?
55734+ return copy_from_user(dst, (void __force_user *)src, len) ?
55735 -EFAULT : 0;
55736 }
55737
55738 static inline int xfer_to_user(void *dst, void *src, size_t len)
55739 {
55740- return copy_to_user((__force void __user *)dst, src, len) ?
55741+ return copy_to_user((void __force_user *)dst, src, len) ?
55742 -EFAULT : 0;
55743 }
55744
55745@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
55746 vrh->last_used_idx = 0;
55747 vrh->vring.num = num;
55748 /* vring expects kernel addresses, but only used via accessors. */
55749- vrh->vring.desc = (__force struct vring_desc *)desc;
55750- vrh->vring.avail = (__force struct vring_avail *)avail;
55751- vrh->vring.used = (__force struct vring_used *)used;
55752+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
55753+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
55754+ vrh->vring.used = (__force_kernel struct vring_used *)used;
55755 return 0;
55756 }
55757 EXPORT_SYMBOL(vringh_init_user);
55758@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
55759
55760 static inline int putu16_kern(u16 *p, u16 val)
55761 {
55762- ACCESS_ONCE(*p) = val;
55763+ ACCESS_ONCE_RW(*p) = val;
55764 return 0;
55765 }
55766
55767diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
55768index 84a110a..96312c3 100644
55769--- a/drivers/video/backlight/kb3886_bl.c
55770+++ b/drivers/video/backlight/kb3886_bl.c
55771@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
55772 static unsigned long kb3886bl_flags;
55773 #define KB3886BL_SUSPENDED 0x01
55774
55775-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
55776+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
55777 {
55778 .ident = "Sahara Touch-iT",
55779 .matches = {
55780diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
55781index 1b0b233..6f34c2c 100644
55782--- a/drivers/video/fbdev/arcfb.c
55783+++ b/drivers/video/fbdev/arcfb.c
55784@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
55785 return -ENOSPC;
55786
55787 err = 0;
55788- if ((count + p) > fbmemlength) {
55789+ if (count > (fbmemlength - p)) {
55790 count = fbmemlength - p;
55791 err = -ENOSPC;
55792 }
55793diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
55794index 52108be..c7c110d 100644
55795--- a/drivers/video/fbdev/aty/aty128fb.c
55796+++ b/drivers/video/fbdev/aty/aty128fb.c
55797@@ -149,7 +149,7 @@ enum {
55798 };
55799
55800 /* Must match above enum */
55801-static char * const r128_family[] = {
55802+static const char * const r128_family[] = {
55803 "AGP",
55804 "PCI",
55805 "PRO AGP",
55806diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
55807index c3d0074..0b9077e 100644
55808--- a/drivers/video/fbdev/aty/atyfb_base.c
55809+++ b/drivers/video/fbdev/aty/atyfb_base.c
55810@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
55811 par->accel_flags = var->accel_flags; /* hack */
55812
55813 if (var->accel_flags) {
55814- info->fbops->fb_sync = atyfb_sync;
55815+ pax_open_kernel();
55816+ *(void **)&info->fbops->fb_sync = atyfb_sync;
55817+ pax_close_kernel();
55818 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55819 } else {
55820- info->fbops->fb_sync = NULL;
55821+ pax_open_kernel();
55822+ *(void **)&info->fbops->fb_sync = NULL;
55823+ pax_close_kernel();
55824 info->flags |= FBINFO_HWACCEL_DISABLED;
55825 }
55826
55827diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
55828index 2fa0317..4983f2a 100644
55829--- a/drivers/video/fbdev/aty/mach64_cursor.c
55830+++ b/drivers/video/fbdev/aty/mach64_cursor.c
55831@@ -8,6 +8,7 @@
55832 #include "../core/fb_draw.h"
55833
55834 #include <asm/io.h>
55835+#include <asm/pgtable.h>
55836
55837 #ifdef __sparc__
55838 #include <asm/fbio.h>
55839@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
55840 info->sprite.buf_align = 16; /* and 64 lines tall. */
55841 info->sprite.flags = FB_PIXMAP_IO;
55842
55843- info->fbops->fb_cursor = atyfb_cursor;
55844+ pax_open_kernel();
55845+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
55846+ pax_close_kernel();
55847
55848 return 0;
55849 }
55850diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
55851index 900aa4e..6d49418 100644
55852--- a/drivers/video/fbdev/core/fb_defio.c
55853+++ b/drivers/video/fbdev/core/fb_defio.c
55854@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
55855
55856 BUG_ON(!fbdefio);
55857 mutex_init(&fbdefio->lock);
55858- info->fbops->fb_mmap = fb_deferred_io_mmap;
55859+ pax_open_kernel();
55860+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
55861+ pax_close_kernel();
55862 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
55863 INIT_LIST_HEAD(&fbdefio->pagelist);
55864 if (fbdefio->delay == 0) /* set a default of 1 s */
55865@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
55866 page->mapping = NULL;
55867 }
55868
55869- info->fbops->fb_mmap = NULL;
55870+ *(void **)&info->fbops->fb_mmap = NULL;
55871 mutex_destroy(&fbdefio->lock);
55872 }
55873 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
55874diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
55875index b5e85f6..290f8c7 100644
55876--- a/drivers/video/fbdev/core/fbmem.c
55877+++ b/drivers/video/fbdev/core/fbmem.c
55878@@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
55879 __u32 data;
55880 int err;
55881
55882- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
55883+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
55884
55885 data = (__u32) (unsigned long) fix->smem_start;
55886 err |= put_user(data, &fix32->smem_start);
55887diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
55888index e23392e..8a77540 100644
55889--- a/drivers/video/fbdev/hyperv_fb.c
55890+++ b/drivers/video/fbdev/hyperv_fb.c
55891@@ -235,7 +235,7 @@ static uint screen_fb_size;
55892 static inline int synthvid_send(struct hv_device *hdev,
55893 struct synthvid_msg *msg)
55894 {
55895- static atomic64_t request_id = ATOMIC64_INIT(0);
55896+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
55897 int ret;
55898
55899 msg->pipe_hdr.type = PIPE_MSG_DATA;
55900@@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
55901
55902 ret = vmbus_sendpacket(hdev->channel, msg,
55903 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
55904- atomic64_inc_return(&request_id),
55905+ atomic64_inc_return_unchecked(&request_id),
55906 VM_PKT_DATA_INBAND, 0);
55907
55908 if (ret)
55909diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
55910index 7672d2e..b56437f 100644
55911--- a/drivers/video/fbdev/i810/i810_accel.c
55912+++ b/drivers/video/fbdev/i810/i810_accel.c
55913@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55914 }
55915 }
55916 printk("ringbuffer lockup!!!\n");
55917+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55918 i810_report_error(mmio);
55919 par->dev_flags |= LOCKUP;
55920 info->pixmap.scan_align = 1;
55921diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55922index a01147f..5d896f8 100644
55923--- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55924+++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55925@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55926
55927 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55928 struct matrox_switch matrox_mystique = {
55929- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55930+ .preinit = MGA1064_preinit,
55931+ .reset = MGA1064_reset,
55932+ .init = MGA1064_init,
55933+ .restore = MGA1064_restore,
55934 };
55935 EXPORT_SYMBOL(matrox_mystique);
55936 #endif
55937
55938 #ifdef CONFIG_FB_MATROX_G
55939 struct matrox_switch matrox_G100 = {
55940- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55941+ .preinit = MGAG100_preinit,
55942+ .reset = MGAG100_reset,
55943+ .init = MGAG100_init,
55944+ .restore = MGAG100_restore,
55945 };
55946 EXPORT_SYMBOL(matrox_G100);
55947 #endif
55948diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55949index 195ad7c..09743fc 100644
55950--- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55951+++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55952@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55953 }
55954
55955 struct matrox_switch matrox_millennium = {
55956- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55957+ .preinit = Ti3026_preinit,
55958+ .reset = Ti3026_reset,
55959+ .init = Ti3026_init,
55960+ .restore = Ti3026_restore
55961 };
55962 EXPORT_SYMBOL(matrox_millennium);
55963 #endif
55964diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55965index fe92eed..106e085 100644
55966--- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55967+++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55968@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55969 struct mb862xxfb_par *par = info->par;
55970
55971 if (info->var.bits_per_pixel == 32) {
55972- info->fbops->fb_fillrect = cfb_fillrect;
55973- info->fbops->fb_copyarea = cfb_copyarea;
55974- info->fbops->fb_imageblit = cfb_imageblit;
55975+ pax_open_kernel();
55976+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55977+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55978+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55979+ pax_close_kernel();
55980 } else {
55981 outreg(disp, GC_L0EM, 3);
55982- info->fbops->fb_fillrect = mb86290fb_fillrect;
55983- info->fbops->fb_copyarea = mb86290fb_copyarea;
55984- info->fbops->fb_imageblit = mb86290fb_imageblit;
55985+ pax_open_kernel();
55986+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55987+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55988+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55989+ pax_close_kernel();
55990 }
55991 outreg(draw, GDC_REG_DRAW_BASE, 0);
55992 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55993diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55994index def0412..fed6529 100644
55995--- a/drivers/video/fbdev/nvidia/nvidia.c
55996+++ b/drivers/video/fbdev/nvidia/nvidia.c
55997@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55998 info->fix.line_length = (info->var.xres_virtual *
55999 info->var.bits_per_pixel) >> 3;
56000 if (info->var.accel_flags) {
56001- info->fbops->fb_imageblit = nvidiafb_imageblit;
56002- info->fbops->fb_fillrect = nvidiafb_fillrect;
56003- info->fbops->fb_copyarea = nvidiafb_copyarea;
56004- info->fbops->fb_sync = nvidiafb_sync;
56005+ pax_open_kernel();
56006+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
56007+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
56008+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
56009+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
56010+ pax_close_kernel();
56011 info->pixmap.scan_align = 4;
56012 info->flags &= ~FBINFO_HWACCEL_DISABLED;
56013 info->flags |= FBINFO_READS_FAST;
56014 NVResetGraphics(info);
56015 } else {
56016- info->fbops->fb_imageblit = cfb_imageblit;
56017- info->fbops->fb_fillrect = cfb_fillrect;
56018- info->fbops->fb_copyarea = cfb_copyarea;
56019- info->fbops->fb_sync = NULL;
56020+ pax_open_kernel();
56021+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
56022+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
56023+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
56024+ *(void **)&info->fbops->fb_sync = NULL;
56025+ pax_close_kernel();
56026 info->pixmap.scan_align = 1;
56027 info->flags |= FBINFO_HWACCEL_DISABLED;
56028 info->flags &= ~FBINFO_READS_FAST;
56029@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
56030 info->pixmap.size = 8 * 1024;
56031 info->pixmap.flags = FB_PIXMAP_SYSTEM;
56032
56033- if (!hwcur)
56034- info->fbops->fb_cursor = NULL;
56035+ if (!hwcur) {
56036+ pax_open_kernel();
56037+ *(void **)&info->fbops->fb_cursor = NULL;
56038+ pax_close_kernel();
56039+ }
56040
56041 info->var.accel_flags = (!noaccel);
56042
56043diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
56044index 2412a0d..294215b 100644
56045--- a/drivers/video/fbdev/omap2/dss/display.c
56046+++ b/drivers/video/fbdev/omap2/dss/display.c
56047@@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
56048 if (dssdev->name == NULL)
56049 dssdev->name = dssdev->alias;
56050
56051+ pax_open_kernel();
56052 if (drv && drv->get_resolution == NULL)
56053- drv->get_resolution = omapdss_default_get_resolution;
56054+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
56055 if (drv && drv->get_recommended_bpp == NULL)
56056- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
56057+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
56058 if (drv && drv->get_timings == NULL)
56059- drv->get_timings = omapdss_default_get_timings;
56060+ *(void **)&drv->get_timings = omapdss_default_get_timings;
56061+ pax_close_kernel();
56062
56063 mutex_lock(&panel_list_mutex);
56064 list_add_tail(&dssdev->panel_list, &panel_list);
56065diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
56066index 83433cb..71e9b98 100644
56067--- a/drivers/video/fbdev/s1d13xxxfb.c
56068+++ b/drivers/video/fbdev/s1d13xxxfb.c
56069@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
56070
56071 switch(prod_id) {
56072 case S1D13506_PROD_ID: /* activate acceleration */
56073- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
56074- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
56075+ pax_open_kernel();
56076+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
56077+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
56078+ pax_close_kernel();
56079 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
56080 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
56081 break;
56082diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
56083index 2bcc84a..29dd1ea 100644
56084--- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
56085+++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
56086@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
56087 }
56088
56089 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
56090- lcdc_sys_write_index,
56091- lcdc_sys_write_data,
56092- lcdc_sys_read_data,
56093+ .write_index = lcdc_sys_write_index,
56094+ .write_data = lcdc_sys_write_data,
56095+ .read_data = lcdc_sys_read_data,
56096 };
56097
56098 static int sh_mobile_lcdc_sginit(struct fb_info *info,
56099diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
56100index d513ed6..90b0de9 100644
56101--- a/drivers/video/fbdev/smscufx.c
56102+++ b/drivers/video/fbdev/smscufx.c
56103@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
56104 fb_deferred_io_cleanup(info);
56105 kfree(info->fbdefio);
56106 info->fbdefio = NULL;
56107- info->fbops->fb_mmap = ufx_ops_mmap;
56108+ pax_open_kernel();
56109+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
56110+ pax_close_kernel();
56111 }
56112
56113 pr_debug("released /dev/fb%d user=%d count=%d",
56114diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
56115index 77b890e..458e666 100644
56116--- a/drivers/video/fbdev/udlfb.c
56117+++ b/drivers/video/fbdev/udlfb.c
56118@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
56119 dlfb_urb_completion(urb);
56120
56121 error:
56122- atomic_add(bytes_sent, &dev->bytes_sent);
56123- atomic_add(bytes_identical, &dev->bytes_identical);
56124- atomic_add(width*height*2, &dev->bytes_rendered);
56125+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56126+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56127+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
56128 end_cycles = get_cycles();
56129- atomic_add(((unsigned int) ((end_cycles - start_cycles)
56130+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56131 >> 10)), /* Kcycles */
56132 &dev->cpu_kcycles_used);
56133
56134@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
56135 dlfb_urb_completion(urb);
56136
56137 error:
56138- atomic_add(bytes_sent, &dev->bytes_sent);
56139- atomic_add(bytes_identical, &dev->bytes_identical);
56140- atomic_add(bytes_rendered, &dev->bytes_rendered);
56141+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56142+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56143+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
56144 end_cycles = get_cycles();
56145- atomic_add(((unsigned int) ((end_cycles - start_cycles)
56146+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56147 >> 10)), /* Kcycles */
56148 &dev->cpu_kcycles_used);
56149 }
56150@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
56151 fb_deferred_io_cleanup(info);
56152 kfree(info->fbdefio);
56153 info->fbdefio = NULL;
56154- info->fbops->fb_mmap = dlfb_ops_mmap;
56155+ pax_open_kernel();
56156+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
56157+ pax_close_kernel();
56158 }
56159
56160 pr_warn("released /dev/fb%d user=%d count=%d\n",
56161@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
56162 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56163 struct dlfb_data *dev = fb_info->par;
56164 return snprintf(buf, PAGE_SIZE, "%u\n",
56165- atomic_read(&dev->bytes_rendered));
56166+ atomic_read_unchecked(&dev->bytes_rendered));
56167 }
56168
56169 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56170@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56171 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56172 struct dlfb_data *dev = fb_info->par;
56173 return snprintf(buf, PAGE_SIZE, "%u\n",
56174- atomic_read(&dev->bytes_identical));
56175+ atomic_read_unchecked(&dev->bytes_identical));
56176 }
56177
56178 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56179@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56180 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56181 struct dlfb_data *dev = fb_info->par;
56182 return snprintf(buf, PAGE_SIZE, "%u\n",
56183- atomic_read(&dev->bytes_sent));
56184+ atomic_read_unchecked(&dev->bytes_sent));
56185 }
56186
56187 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56188@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56189 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56190 struct dlfb_data *dev = fb_info->par;
56191 return snprintf(buf, PAGE_SIZE, "%u\n",
56192- atomic_read(&dev->cpu_kcycles_used));
56193+ atomic_read_unchecked(&dev->cpu_kcycles_used));
56194 }
56195
56196 static ssize_t edid_show(
56197@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
56198 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56199 struct dlfb_data *dev = fb_info->par;
56200
56201- atomic_set(&dev->bytes_rendered, 0);
56202- atomic_set(&dev->bytes_identical, 0);
56203- atomic_set(&dev->bytes_sent, 0);
56204- atomic_set(&dev->cpu_kcycles_used, 0);
56205+ atomic_set_unchecked(&dev->bytes_rendered, 0);
56206+ atomic_set_unchecked(&dev->bytes_identical, 0);
56207+ atomic_set_unchecked(&dev->bytes_sent, 0);
56208+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
56209
56210 return count;
56211 }
56212diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
56213index 509d452..7c9d2de 100644
56214--- a/drivers/video/fbdev/uvesafb.c
56215+++ b/drivers/video/fbdev/uvesafb.c
56216@@ -19,6 +19,7 @@
56217 #include <linux/io.h>
56218 #include <linux/mutex.h>
56219 #include <linux/slab.h>
56220+#include <linux/moduleloader.h>
56221 #include <video/edid.h>
56222 #include <video/uvesafb.h>
56223 #ifdef CONFIG_X86
56224@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
56225 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
56226 par->pmi_setpal = par->ypan = 0;
56227 } else {
56228+
56229+#ifdef CONFIG_PAX_KERNEXEC
56230+#ifdef CONFIG_MODULES
56231+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
56232+#endif
56233+ if (!par->pmi_code) {
56234+ par->pmi_setpal = par->ypan = 0;
56235+ return 0;
56236+ }
56237+#endif
56238+
56239 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
56240 + task->t.regs.edi);
56241+
56242+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56243+ pax_open_kernel();
56244+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
56245+ pax_close_kernel();
56246+
56247+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
56248+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
56249+#else
56250 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
56251 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
56252+#endif
56253+
56254 printk(KERN_INFO "uvesafb: protected mode interface info at "
56255 "%04x:%04x\n",
56256 (u16)task->t.regs.es, (u16)task->t.regs.edi);
56257@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
56258 par->ypan = ypan;
56259
56260 if (par->pmi_setpal || par->ypan) {
56261+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
56262 if (__supported_pte_mask & _PAGE_NX) {
56263 par->pmi_setpal = par->ypan = 0;
56264 printk(KERN_WARNING "uvesafb: NX protection is active, "
56265 "better not use the PMI.\n");
56266- } else {
56267+ } else
56268+#endif
56269 uvesafb_vbe_getpmi(task, par);
56270- }
56271 }
56272 #else
56273 /* The protected mode interface is not available on non-x86. */
56274@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56275 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
56276
56277 /* Disable blanking if the user requested so. */
56278- if (!blank)
56279- info->fbops->fb_blank = NULL;
56280+ if (!blank) {
56281+ pax_open_kernel();
56282+ *(void **)&info->fbops->fb_blank = NULL;
56283+ pax_close_kernel();
56284+ }
56285
56286 /*
56287 * Find out how much IO memory is required for the mode with
56288@@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56289 info->flags = FBINFO_FLAG_DEFAULT |
56290 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
56291
56292- if (!par->ypan)
56293- info->fbops->fb_pan_display = NULL;
56294+ if (!par->ypan) {
56295+ pax_open_kernel();
56296+ *(void **)&info->fbops->fb_pan_display = NULL;
56297+ pax_close_kernel();
56298+ }
56299 }
56300
56301 static void uvesafb_init_mtrr(struct fb_info *info)
56302@@ -1787,6 +1817,11 @@ out_mode:
56303 out:
56304 kfree(par->vbe_modes);
56305
56306+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56307+ if (par->pmi_code)
56308+ module_free_exec(NULL, par->pmi_code);
56309+#endif
56310+
56311 framebuffer_release(info);
56312 return err;
56313 }
56314@@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
56315 kfree(par->vbe_state_orig);
56316 kfree(par->vbe_state_saved);
56317
56318+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56319+ if (par->pmi_code)
56320+ module_free_exec(NULL, par->pmi_code);
56321+#endif
56322+
56323 framebuffer_release(info);
56324 }
56325 return 0;
56326diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
56327index 6170e7f..dd63031 100644
56328--- a/drivers/video/fbdev/vesafb.c
56329+++ b/drivers/video/fbdev/vesafb.c
56330@@ -9,6 +9,7 @@
56331 */
56332
56333 #include <linux/module.h>
56334+#include <linux/moduleloader.h>
56335 #include <linux/kernel.h>
56336 #include <linux/errno.h>
56337 #include <linux/string.h>
56338@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
56339 static int vram_total; /* Set total amount of memory */
56340 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
56341 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
56342-static void (*pmi_start)(void) __read_mostly;
56343-static void (*pmi_pal) (void) __read_mostly;
56344+static void (*pmi_start)(void) __read_only;
56345+static void (*pmi_pal) (void) __read_only;
56346 static int depth __read_mostly;
56347 static int vga_compat __read_mostly;
56348 /* --------------------------------------------------------------------- */
56349@@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
56350 unsigned int size_remap;
56351 unsigned int size_total;
56352 char *option = NULL;
56353+ void *pmi_code = NULL;
56354
56355 /* ignore error return of fb_get_options */
56356 fb_get_options("vesafb", &option);
56357@@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
56358 size_remap = size_total;
56359 vesafb_fix.smem_len = size_remap;
56360
56361-#ifndef __i386__
56362- screen_info.vesapm_seg = 0;
56363-#endif
56364-
56365 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
56366 printk(KERN_WARNING
56367 "vesafb: cannot reserve video memory at 0x%lx\n",
56368@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
56369 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
56370 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
56371
56372+#ifdef __i386__
56373+
56374+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56375+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
56376+ if (!pmi_code)
56377+#elif !defined(CONFIG_PAX_KERNEXEC)
56378+ if (0)
56379+#endif
56380+
56381+#endif
56382+ screen_info.vesapm_seg = 0;
56383+
56384 if (screen_info.vesapm_seg) {
56385- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
56386- screen_info.vesapm_seg,screen_info.vesapm_off);
56387+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
56388+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
56389 }
56390
56391 if (screen_info.vesapm_seg < 0xc000)
56392@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
56393
56394 if (ypan || pmi_setpal) {
56395 unsigned short *pmi_base;
56396+
56397 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
56398- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
56399- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
56400+
56401+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56402+ pax_open_kernel();
56403+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
56404+#else
56405+ pmi_code = pmi_base;
56406+#endif
56407+
56408+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
56409+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
56410+
56411+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56412+ pmi_start = ktva_ktla(pmi_start);
56413+ pmi_pal = ktva_ktla(pmi_pal);
56414+ pax_close_kernel();
56415+#endif
56416+
56417 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
56418 if (pmi_base[3]) {
56419 printk(KERN_INFO "vesafb: pmi: ports = ");
56420@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
56421 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
56422 (ypan ? FBINFO_HWACCEL_YPAN : 0);
56423
56424- if (!ypan)
56425- info->fbops->fb_pan_display = NULL;
56426+ if (!ypan) {
56427+ pax_open_kernel();
56428+ *(void **)&info->fbops->fb_pan_display = NULL;
56429+ pax_close_kernel();
56430+ }
56431
56432 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
56433 err = -ENOMEM;
56434@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
56435 fb_info(info, "%s frame buffer device\n", info->fix.id);
56436 return 0;
56437 err:
56438+
56439+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56440+ module_free_exec(NULL, pmi_code);
56441+#endif
56442+
56443 if (info->screen_base)
56444 iounmap(info->screen_base);
56445 framebuffer_release(info);
56446diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
56447index 88714ae..16c2e11 100644
56448--- a/drivers/video/fbdev/via/via_clock.h
56449+++ b/drivers/video/fbdev/via/via_clock.h
56450@@ -56,7 +56,7 @@ struct via_clock {
56451
56452 void (*set_engine_pll_state)(u8 state);
56453 void (*set_engine_pll)(struct via_pll_config config);
56454-};
56455+} __no_const;
56456
56457
56458 static inline u32 get_pll_internal_frequency(u32 ref_freq,
56459diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
56460index 3c14e43..2630570 100644
56461--- a/drivers/video/logo/logo_linux_clut224.ppm
56462+++ b/drivers/video/logo/logo_linux_clut224.ppm
56463@@ -2,1603 +2,1123 @@ P3
56464 # Standard 224-color Linux logo
56465 80 80
56466 255
56467- 0 0 0 0 0 0 0 0 0 0 0 0
56468- 0 0 0 0 0 0 0 0 0 0 0 0
56469- 0 0 0 0 0 0 0 0 0 0 0 0
56470- 0 0 0 0 0 0 0 0 0 0 0 0
56471- 0 0 0 0 0 0 0 0 0 0 0 0
56472- 0 0 0 0 0 0 0 0 0 0 0 0
56473- 0 0 0 0 0 0 0 0 0 0 0 0
56474- 0 0 0 0 0 0 0 0 0 0 0 0
56475- 0 0 0 0 0 0 0 0 0 0 0 0
56476- 6 6 6 6 6 6 10 10 10 10 10 10
56477- 10 10 10 6 6 6 6 6 6 6 6 6
56478- 0 0 0 0 0 0 0 0 0 0 0 0
56479- 0 0 0 0 0 0 0 0 0 0 0 0
56480- 0 0 0 0 0 0 0 0 0 0 0 0
56481- 0 0 0 0 0 0 0 0 0 0 0 0
56482- 0 0 0 0 0 0 0 0 0 0 0 0
56483- 0 0 0 0 0 0 0 0 0 0 0 0
56484- 0 0 0 0 0 0 0 0 0 0 0 0
56485- 0 0 0 0 0 0 0 0 0 0 0 0
56486- 0 0 0 0 0 0 0 0 0 0 0 0
56487- 0 0 0 0 0 0 0 0 0 0 0 0
56488- 0 0 0 0 0 0 0 0 0 0 0 0
56489- 0 0 0 0 0 0 0 0 0 0 0 0
56490- 0 0 0 0 0 0 0 0 0 0 0 0
56491- 0 0 0 0 0 0 0 0 0 0 0 0
56492- 0 0 0 0 0 0 0 0 0 0 0 0
56493- 0 0 0 0 0 0 0 0 0 0 0 0
56494- 0 0 0 0 0 0 0 0 0 0 0 0
56495- 0 0 0 6 6 6 10 10 10 14 14 14
56496- 22 22 22 26 26 26 30 30 30 34 34 34
56497- 30 30 30 30 30 30 26 26 26 18 18 18
56498- 14 14 14 10 10 10 6 6 6 0 0 0
56499- 0 0 0 0 0 0 0 0 0 0 0 0
56500- 0 0 0 0 0 0 0 0 0 0 0 0
56501- 0 0 0 0 0 0 0 0 0 0 0 0
56502- 0 0 0 0 0 0 0 0 0 0 0 0
56503- 0 0 0 0 0 0 0 0 0 0 0 0
56504- 0 0 0 0 0 0 0 0 0 0 0 0
56505- 0 0 0 0 0 0 0 0 0 0 0 0
56506- 0 0 0 0 0 0 0 0 0 0 0 0
56507- 0 0 0 0 0 0 0 0 0 0 0 0
56508- 0 0 0 0 0 1 0 0 1 0 0 0
56509- 0 0 0 0 0 0 0 0 0 0 0 0
56510- 0 0 0 0 0 0 0 0 0 0 0 0
56511- 0 0 0 0 0 0 0 0 0 0 0 0
56512- 0 0 0 0 0 0 0 0 0 0 0 0
56513- 0 0 0 0 0 0 0 0 0 0 0 0
56514- 0 0 0 0 0 0 0 0 0 0 0 0
56515- 6 6 6 14 14 14 26 26 26 42 42 42
56516- 54 54 54 66 66 66 78 78 78 78 78 78
56517- 78 78 78 74 74 74 66 66 66 54 54 54
56518- 42 42 42 26 26 26 18 18 18 10 10 10
56519- 6 6 6 0 0 0 0 0 0 0 0 0
56520- 0 0 0 0 0 0 0 0 0 0 0 0
56521- 0 0 0 0 0 0 0 0 0 0 0 0
56522- 0 0 0 0 0 0 0 0 0 0 0 0
56523- 0 0 0 0 0 0 0 0 0 0 0 0
56524- 0 0 0 0 0 0 0 0 0 0 0 0
56525- 0 0 0 0 0 0 0 0 0 0 0 0
56526- 0 0 0 0 0 0 0 0 0 0 0 0
56527- 0 0 0 0 0 0 0 0 0 0 0 0
56528- 0 0 1 0 0 0 0 0 0 0 0 0
56529- 0 0 0 0 0 0 0 0 0 0 0 0
56530- 0 0 0 0 0 0 0 0 0 0 0 0
56531- 0 0 0 0 0 0 0 0 0 0 0 0
56532- 0 0 0 0 0 0 0 0 0 0 0 0
56533- 0 0 0 0 0 0 0 0 0 0 0 0
56534- 0 0 0 0 0 0 0 0 0 10 10 10
56535- 22 22 22 42 42 42 66 66 66 86 86 86
56536- 66 66 66 38 38 38 38 38 38 22 22 22
56537- 26 26 26 34 34 34 54 54 54 66 66 66
56538- 86 86 86 70 70 70 46 46 46 26 26 26
56539- 14 14 14 6 6 6 0 0 0 0 0 0
56540- 0 0 0 0 0 0 0 0 0 0 0 0
56541- 0 0 0 0 0 0 0 0 0 0 0 0
56542- 0 0 0 0 0 0 0 0 0 0 0 0
56543- 0 0 0 0 0 0 0 0 0 0 0 0
56544- 0 0 0 0 0 0 0 0 0 0 0 0
56545- 0 0 0 0 0 0 0 0 0 0 0 0
56546- 0 0 0 0 0 0 0 0 0 0 0 0
56547- 0 0 0 0 0 0 0 0 0 0 0 0
56548- 0 0 1 0 0 1 0 0 1 0 0 0
56549- 0 0 0 0 0 0 0 0 0 0 0 0
56550- 0 0 0 0 0 0 0 0 0 0 0 0
56551- 0 0 0 0 0 0 0 0 0 0 0 0
56552- 0 0 0 0 0 0 0 0 0 0 0 0
56553- 0 0 0 0 0 0 0 0 0 0 0 0
56554- 0 0 0 0 0 0 10 10 10 26 26 26
56555- 50 50 50 82 82 82 58 58 58 6 6 6
56556- 2 2 6 2 2 6 2 2 6 2 2 6
56557- 2 2 6 2 2 6 2 2 6 2 2 6
56558- 6 6 6 54 54 54 86 86 86 66 66 66
56559- 38 38 38 18 18 18 6 6 6 0 0 0
56560- 0 0 0 0 0 0 0 0 0 0 0 0
56561- 0 0 0 0 0 0 0 0 0 0 0 0
56562- 0 0 0 0 0 0 0 0 0 0 0 0
56563- 0 0 0 0 0 0 0 0 0 0 0 0
56564- 0 0 0 0 0 0 0 0 0 0 0 0
56565- 0 0 0 0 0 0 0 0 0 0 0 0
56566- 0 0 0 0 0 0 0 0 0 0 0 0
56567- 0 0 0 0 0 0 0 0 0 0 0 0
56568- 0 0 0 0 0 0 0 0 0 0 0 0
56569- 0 0 0 0 0 0 0 0 0 0 0 0
56570- 0 0 0 0 0 0 0 0 0 0 0 0
56571- 0 0 0 0 0 0 0 0 0 0 0 0
56572- 0 0 0 0 0 0 0 0 0 0 0 0
56573- 0 0 0 0 0 0 0 0 0 0 0 0
56574- 0 0 0 6 6 6 22 22 22 50 50 50
56575- 78 78 78 34 34 34 2 2 6 2 2 6
56576- 2 2 6 2 2 6 2 2 6 2 2 6
56577- 2 2 6 2 2 6 2 2 6 2 2 6
56578- 2 2 6 2 2 6 6 6 6 70 70 70
56579- 78 78 78 46 46 46 22 22 22 6 6 6
56580- 0 0 0 0 0 0 0 0 0 0 0 0
56581- 0 0 0 0 0 0 0 0 0 0 0 0
56582- 0 0 0 0 0 0 0 0 0 0 0 0
56583- 0 0 0 0 0 0 0 0 0 0 0 0
56584- 0 0 0 0 0 0 0 0 0 0 0 0
56585- 0 0 0 0 0 0 0 0 0 0 0 0
56586- 0 0 0 0 0 0 0 0 0 0 0 0
56587- 0 0 0 0 0 0 0 0 0 0 0 0
56588- 0 0 1 0 0 1 0 0 1 0 0 0
56589- 0 0 0 0 0 0 0 0 0 0 0 0
56590- 0 0 0 0 0 0 0 0 0 0 0 0
56591- 0 0 0 0 0 0 0 0 0 0 0 0
56592- 0 0 0 0 0 0 0 0 0 0 0 0
56593- 0 0 0 0 0 0 0 0 0 0 0 0
56594- 6 6 6 18 18 18 42 42 42 82 82 82
56595- 26 26 26 2 2 6 2 2 6 2 2 6
56596- 2 2 6 2 2 6 2 2 6 2 2 6
56597- 2 2 6 2 2 6 2 2 6 14 14 14
56598- 46 46 46 34 34 34 6 6 6 2 2 6
56599- 42 42 42 78 78 78 42 42 42 18 18 18
56600- 6 6 6 0 0 0 0 0 0 0 0 0
56601- 0 0 0 0 0 0 0 0 0 0 0 0
56602- 0 0 0 0 0 0 0 0 0 0 0 0
56603- 0 0 0 0 0 0 0 0 0 0 0 0
56604- 0 0 0 0 0 0 0 0 0 0 0 0
56605- 0 0 0 0 0 0 0 0 0 0 0 0
56606- 0 0 0 0 0 0 0 0 0 0 0 0
56607- 0 0 0 0 0 0 0 0 0 0 0 0
56608- 0 0 1 0 0 0 0 0 1 0 0 0
56609- 0 0 0 0 0 0 0 0 0 0 0 0
56610- 0 0 0 0 0 0 0 0 0 0 0 0
56611- 0 0 0 0 0 0 0 0 0 0 0 0
56612- 0 0 0 0 0 0 0 0 0 0 0 0
56613- 0 0 0 0 0 0 0 0 0 0 0 0
56614- 10 10 10 30 30 30 66 66 66 58 58 58
56615- 2 2 6 2 2 6 2 2 6 2 2 6
56616- 2 2 6 2 2 6 2 2 6 2 2 6
56617- 2 2 6 2 2 6 2 2 6 26 26 26
56618- 86 86 86 101 101 101 46 46 46 10 10 10
56619- 2 2 6 58 58 58 70 70 70 34 34 34
56620- 10 10 10 0 0 0 0 0 0 0 0 0
56621- 0 0 0 0 0 0 0 0 0 0 0 0
56622- 0 0 0 0 0 0 0 0 0 0 0 0
56623- 0 0 0 0 0 0 0 0 0 0 0 0
56624- 0 0 0 0 0 0 0 0 0 0 0 0
56625- 0 0 0 0 0 0 0 0 0 0 0 0
56626- 0 0 0 0 0 0 0 0 0 0 0 0
56627- 0 0 0 0 0 0 0 0 0 0 0 0
56628- 0 0 1 0 0 1 0 0 1 0 0 0
56629- 0 0 0 0 0 0 0 0 0 0 0 0
56630- 0 0 0 0 0 0 0 0 0 0 0 0
56631- 0 0 0 0 0 0 0 0 0 0 0 0
56632- 0 0 0 0 0 0 0 0 0 0 0 0
56633- 0 0 0 0 0 0 0 0 0 0 0 0
56634- 14 14 14 42 42 42 86 86 86 10 10 10
56635- 2 2 6 2 2 6 2 2 6 2 2 6
56636- 2 2 6 2 2 6 2 2 6 2 2 6
56637- 2 2 6 2 2 6 2 2 6 30 30 30
56638- 94 94 94 94 94 94 58 58 58 26 26 26
56639- 2 2 6 6 6 6 78 78 78 54 54 54
56640- 22 22 22 6 6 6 0 0 0 0 0 0
56641- 0 0 0 0 0 0 0 0 0 0 0 0
56642- 0 0 0 0 0 0 0 0 0 0 0 0
56643- 0 0 0 0 0 0 0 0 0 0 0 0
56644- 0 0 0 0 0 0 0 0 0 0 0 0
56645- 0 0 0 0 0 0 0 0 0 0 0 0
56646- 0 0 0 0 0 0 0 0 0 0 0 0
56647- 0 0 0 0 0 0 0 0 0 0 0 0
56648- 0 0 0 0 0 0 0 0 0 0 0 0
56649- 0 0 0 0 0 0 0 0 0 0 0 0
56650- 0 0 0 0 0 0 0 0 0 0 0 0
56651- 0 0 0 0 0 0 0 0 0 0 0 0
56652- 0 0 0 0 0 0 0 0 0 0 0 0
56653- 0 0 0 0 0 0 0 0 0 6 6 6
56654- 22 22 22 62 62 62 62 62 62 2 2 6
56655- 2 2 6 2 2 6 2 2 6 2 2 6
56656- 2 2 6 2 2 6 2 2 6 2 2 6
56657- 2 2 6 2 2 6 2 2 6 26 26 26
56658- 54 54 54 38 38 38 18 18 18 10 10 10
56659- 2 2 6 2 2 6 34 34 34 82 82 82
56660- 38 38 38 14 14 14 0 0 0 0 0 0
56661- 0 0 0 0 0 0 0 0 0 0 0 0
56662- 0 0 0 0 0 0 0 0 0 0 0 0
56663- 0 0 0 0 0 0 0 0 0 0 0 0
56664- 0 0 0 0 0 0 0 0 0 0 0 0
56665- 0 0 0 0 0 0 0 0 0 0 0 0
56666- 0 0 0 0 0 0 0 0 0 0 0 0
56667- 0 0 0 0 0 0 0 0 0 0 0 0
56668- 0 0 0 0 0 1 0 0 1 0 0 0
56669- 0 0 0 0 0 0 0 0 0 0 0 0
56670- 0 0 0 0 0 0 0 0 0 0 0 0
56671- 0 0 0 0 0 0 0 0 0 0 0 0
56672- 0 0 0 0 0 0 0 0 0 0 0 0
56673- 0 0 0 0 0 0 0 0 0 6 6 6
56674- 30 30 30 78 78 78 30 30 30 2 2 6
56675- 2 2 6 2 2 6 2 2 6 2 2 6
56676- 2 2 6 2 2 6 2 2 6 2 2 6
56677- 2 2 6 2 2 6 2 2 6 10 10 10
56678- 10 10 10 2 2 6 2 2 6 2 2 6
56679- 2 2 6 2 2 6 2 2 6 78 78 78
56680- 50 50 50 18 18 18 6 6 6 0 0 0
56681- 0 0 0 0 0 0 0 0 0 0 0 0
56682- 0 0 0 0 0 0 0 0 0 0 0 0
56683- 0 0 0 0 0 0 0 0 0 0 0 0
56684- 0 0 0 0 0 0 0 0 0 0 0 0
56685- 0 0 0 0 0 0 0 0 0 0 0 0
56686- 0 0 0 0 0 0 0 0 0 0 0 0
56687- 0 0 0 0 0 0 0 0 0 0 0 0
56688- 0 0 1 0 0 0 0 0 0 0 0 0
56689- 0 0 0 0 0 0 0 0 0 0 0 0
56690- 0 0 0 0 0 0 0 0 0 0 0 0
56691- 0 0 0 0 0 0 0 0 0 0 0 0
56692- 0 0 0 0 0 0 0 0 0 0 0 0
56693- 0 0 0 0 0 0 0 0 0 10 10 10
56694- 38 38 38 86 86 86 14 14 14 2 2 6
56695- 2 2 6 2 2 6 2 2 6 2 2 6
56696- 2 2 6 2 2 6 2 2 6 2 2 6
56697- 2 2 6 2 2 6 2 2 6 2 2 6
56698- 2 2 6 2 2 6 2 2 6 2 2 6
56699- 2 2 6 2 2 6 2 2 6 54 54 54
56700- 66 66 66 26 26 26 6 6 6 0 0 0
56701- 0 0 0 0 0 0 0 0 0 0 0 0
56702- 0 0 0 0 0 0 0 0 0 0 0 0
56703- 0 0 0 0 0 0 0 0 0 0 0 0
56704- 0 0 0 0 0 0 0 0 0 0 0 0
56705- 0 0 0 0 0 0 0 0 0 0 0 0
56706- 0 0 0 0 0 0 0 0 0 0 0 0
56707- 0 0 0 0 0 0 0 0 0 0 0 0
56708- 0 0 0 0 0 1 0 0 1 0 0 0
56709- 0 0 0 0 0 0 0 0 0 0 0 0
56710- 0 0 0 0 0 0 0 0 0 0 0 0
56711- 0 0 0 0 0 0 0 0 0 0 0 0
56712- 0 0 0 0 0 0 0 0 0 0 0 0
56713- 0 0 0 0 0 0 0 0 0 14 14 14
56714- 42 42 42 82 82 82 2 2 6 2 2 6
56715- 2 2 6 6 6 6 10 10 10 2 2 6
56716- 2 2 6 2 2 6 2 2 6 2 2 6
56717- 2 2 6 2 2 6 2 2 6 6 6 6
56718- 14 14 14 10 10 10 2 2 6 2 2 6
56719- 2 2 6 2 2 6 2 2 6 18 18 18
56720- 82 82 82 34 34 34 10 10 10 0 0 0
56721- 0 0 0 0 0 0 0 0 0 0 0 0
56722- 0 0 0 0 0 0 0 0 0 0 0 0
56723- 0 0 0 0 0 0 0 0 0 0 0 0
56724- 0 0 0 0 0 0 0 0 0 0 0 0
56725- 0 0 0 0 0 0 0 0 0 0 0 0
56726- 0 0 0 0 0 0 0 0 0 0 0 0
56727- 0 0 0 0 0 0 0 0 0 0 0 0
56728- 0 0 1 0 0 0 0 0 0 0 0 0
56729- 0 0 0 0 0 0 0 0 0 0 0 0
56730- 0 0 0 0 0 0 0 0 0 0 0 0
56731- 0 0 0 0 0 0 0 0 0 0 0 0
56732- 0 0 0 0 0 0 0 0 0 0 0 0
56733- 0 0 0 0 0 0 0 0 0 14 14 14
56734- 46 46 46 86 86 86 2 2 6 2 2 6
56735- 6 6 6 6 6 6 22 22 22 34 34 34
56736- 6 6 6 2 2 6 2 2 6 2 2 6
56737- 2 2 6 2 2 6 18 18 18 34 34 34
56738- 10 10 10 50 50 50 22 22 22 2 2 6
56739- 2 2 6 2 2 6 2 2 6 10 10 10
56740- 86 86 86 42 42 42 14 14 14 0 0 0
56741- 0 0 0 0 0 0 0 0 0 0 0 0
56742- 0 0 0 0 0 0 0 0 0 0 0 0
56743- 0 0 0 0 0 0 0 0 0 0 0 0
56744- 0 0 0 0 0 0 0 0 0 0 0 0
56745- 0 0 0 0 0 0 0 0 0 0 0 0
56746- 0 0 0 0 0 0 0 0 0 0 0 0
56747- 0 0 0 0 0 0 0 0 0 0 0 0
56748- 0 0 1 0 0 1 0 0 1 0 0 0
56749- 0 0 0 0 0 0 0 0 0 0 0 0
56750- 0 0 0 0 0 0 0 0 0 0 0 0
56751- 0 0 0 0 0 0 0 0 0 0 0 0
56752- 0 0 0 0 0 0 0 0 0 0 0 0
56753- 0 0 0 0 0 0 0 0 0 14 14 14
56754- 46 46 46 86 86 86 2 2 6 2 2 6
56755- 38 38 38 116 116 116 94 94 94 22 22 22
56756- 22 22 22 2 2 6 2 2 6 2 2 6
56757- 14 14 14 86 86 86 138 138 138 162 162 162
56758-154 154 154 38 38 38 26 26 26 6 6 6
56759- 2 2 6 2 2 6 2 2 6 2 2 6
56760- 86 86 86 46 46 46 14 14 14 0 0 0
56761- 0 0 0 0 0 0 0 0 0 0 0 0
56762- 0 0 0 0 0 0 0 0 0 0 0 0
56763- 0 0 0 0 0 0 0 0 0 0 0 0
56764- 0 0 0 0 0 0 0 0 0 0 0 0
56765- 0 0 0 0 0 0 0 0 0 0 0 0
56766- 0 0 0 0 0 0 0 0 0 0 0 0
56767- 0 0 0 0 0 0 0 0 0 0 0 0
56768- 0 0 0 0 0 0 0 0 0 0 0 0
56769- 0 0 0 0 0 0 0 0 0 0 0 0
56770- 0 0 0 0 0 0 0 0 0 0 0 0
56771- 0 0 0 0 0 0 0 0 0 0 0 0
56772- 0 0 0 0 0 0 0 0 0 0 0 0
56773- 0 0 0 0 0 0 0 0 0 14 14 14
56774- 46 46 46 86 86 86 2 2 6 14 14 14
56775-134 134 134 198 198 198 195 195 195 116 116 116
56776- 10 10 10 2 2 6 2 2 6 6 6 6
56777-101 98 89 187 187 187 210 210 210 218 218 218
56778-214 214 214 134 134 134 14 14 14 6 6 6
56779- 2 2 6 2 2 6 2 2 6 2 2 6
56780- 86 86 86 50 50 50 18 18 18 6 6 6
56781- 0 0 0 0 0 0 0 0 0 0 0 0
56782- 0 0 0 0 0 0 0 0 0 0 0 0
56783- 0 0 0 0 0 0 0 0 0 0 0 0
56784- 0 0 0 0 0 0 0 0 0 0 0 0
56785- 0 0 0 0 0 0 0 0 0 0 0 0
56786- 0 0 0 0 0 0 0 0 0 0 0 0
56787- 0 0 0 0 0 0 0 0 1 0 0 0
56788- 0 0 1 0 0 1 0 0 1 0 0 0
56789- 0 0 0 0 0 0 0 0 0 0 0 0
56790- 0 0 0 0 0 0 0 0 0 0 0 0
56791- 0 0 0 0 0 0 0 0 0 0 0 0
56792- 0 0 0 0 0 0 0 0 0 0 0 0
56793- 0 0 0 0 0 0 0 0 0 14 14 14
56794- 46 46 46 86 86 86 2 2 6 54 54 54
56795-218 218 218 195 195 195 226 226 226 246 246 246
56796- 58 58 58 2 2 6 2 2 6 30 30 30
56797-210 210 210 253 253 253 174 174 174 123 123 123
56798-221 221 221 234 234 234 74 74 74 2 2 6
56799- 2 2 6 2 2 6 2 2 6 2 2 6
56800- 70 70 70 58 58 58 22 22 22 6 6 6
56801- 0 0 0 0 0 0 0 0 0 0 0 0
56802- 0 0 0 0 0 0 0 0 0 0 0 0
56803- 0 0 0 0 0 0 0 0 0 0 0 0
56804- 0 0 0 0 0 0 0 0 0 0 0 0
56805- 0 0 0 0 0 0 0 0 0 0 0 0
56806- 0 0 0 0 0 0 0 0 0 0 0 0
56807- 0 0 0 0 0 0 0 0 0 0 0 0
56808- 0 0 0 0 0 0 0 0 0 0 0 0
56809- 0 0 0 0 0 0 0 0 0 0 0 0
56810- 0 0 0 0 0 0 0 0 0 0 0 0
56811- 0 0 0 0 0 0 0 0 0 0 0 0
56812- 0 0 0 0 0 0 0 0 0 0 0 0
56813- 0 0 0 0 0 0 0 0 0 14 14 14
56814- 46 46 46 82 82 82 2 2 6 106 106 106
56815-170 170 170 26 26 26 86 86 86 226 226 226
56816-123 123 123 10 10 10 14 14 14 46 46 46
56817-231 231 231 190 190 190 6 6 6 70 70 70
56818- 90 90 90 238 238 238 158 158 158 2 2 6
56819- 2 2 6 2 2 6 2 2 6 2 2 6
56820- 70 70 70 58 58 58 22 22 22 6 6 6
56821- 0 0 0 0 0 0 0 0 0 0 0 0
56822- 0 0 0 0 0 0 0 0 0 0 0 0
56823- 0 0 0 0 0 0 0 0 0 0 0 0
56824- 0 0 0 0 0 0 0 0 0 0 0 0
56825- 0 0 0 0 0 0 0 0 0 0 0 0
56826- 0 0 0 0 0 0 0 0 0 0 0 0
56827- 0 0 0 0 0 0 0 0 1 0 0 0
56828- 0 0 1 0 0 1 0 0 1 0 0 0
56829- 0 0 0 0 0 0 0 0 0 0 0 0
56830- 0 0 0 0 0 0 0 0 0 0 0 0
56831- 0 0 0 0 0 0 0 0 0 0 0 0
56832- 0 0 0 0 0 0 0 0 0 0 0 0
56833- 0 0 0 0 0 0 0 0 0 14 14 14
56834- 42 42 42 86 86 86 6 6 6 116 116 116
56835-106 106 106 6 6 6 70 70 70 149 149 149
56836-128 128 128 18 18 18 38 38 38 54 54 54
56837-221 221 221 106 106 106 2 2 6 14 14 14
56838- 46 46 46 190 190 190 198 198 198 2 2 6
56839- 2 2 6 2 2 6 2 2 6 2 2 6
56840- 74 74 74 62 62 62 22 22 22 6 6 6
56841- 0 0 0 0 0 0 0 0 0 0 0 0
56842- 0 0 0 0 0 0 0 0 0 0 0 0
56843- 0 0 0 0 0 0 0 0 0 0 0 0
56844- 0 0 0 0 0 0 0 0 0 0 0 0
56845- 0 0 0 0 0 0 0 0 0 0 0 0
56846- 0 0 0 0 0 0 0 0 0 0 0 0
56847- 0 0 0 0 0 0 0 0 1 0 0 0
56848- 0 0 1 0 0 0 0 0 1 0 0 0
56849- 0 0 0 0 0 0 0 0 0 0 0 0
56850- 0 0 0 0 0 0 0 0 0 0 0 0
56851- 0 0 0 0 0 0 0 0 0 0 0 0
56852- 0 0 0 0 0 0 0 0 0 0 0 0
56853- 0 0 0 0 0 0 0 0 0 14 14 14
56854- 42 42 42 94 94 94 14 14 14 101 101 101
56855-128 128 128 2 2 6 18 18 18 116 116 116
56856-118 98 46 121 92 8 121 92 8 98 78 10
56857-162 162 162 106 106 106 2 2 6 2 2 6
56858- 2 2 6 195 195 195 195 195 195 6 6 6
56859- 2 2 6 2 2 6 2 2 6 2 2 6
56860- 74 74 74 62 62 62 22 22 22 6 6 6
56861- 0 0 0 0 0 0 0 0 0 0 0 0
56862- 0 0 0 0 0 0 0 0 0 0 0 0
56863- 0 0 0 0 0 0 0 0 0 0 0 0
56864- 0 0 0 0 0 0 0 0 0 0 0 0
56865- 0 0 0 0 0 0 0 0 0 0 0 0
56866- 0 0 0 0 0 0 0 0 0 0 0 0
56867- 0 0 0 0 0 0 0 0 1 0 0 1
56868- 0 0 1 0 0 0 0 0 1 0 0 0
56869- 0 0 0 0 0 0 0 0 0 0 0 0
56870- 0 0 0 0 0 0 0 0 0 0 0 0
56871- 0 0 0 0 0 0 0 0 0 0 0 0
56872- 0 0 0 0 0 0 0 0 0 0 0 0
56873- 0 0 0 0 0 0 0 0 0 10 10 10
56874- 38 38 38 90 90 90 14 14 14 58 58 58
56875-210 210 210 26 26 26 54 38 6 154 114 10
56876-226 170 11 236 186 11 225 175 15 184 144 12
56877-215 174 15 175 146 61 37 26 9 2 2 6
56878- 70 70 70 246 246 246 138 138 138 2 2 6
56879- 2 2 6 2 2 6 2 2 6 2 2 6
56880- 70 70 70 66 66 66 26 26 26 6 6 6
56881- 0 0 0 0 0 0 0 0 0 0 0 0
56882- 0 0 0 0 0 0 0 0 0 0 0 0
56883- 0 0 0 0 0 0 0 0 0 0 0 0
56884- 0 0 0 0 0 0 0 0 0 0 0 0
56885- 0 0 0 0 0 0 0 0 0 0 0 0
56886- 0 0 0 0 0 0 0 0 0 0 0 0
56887- 0 0 0 0 0 0 0 0 0 0 0 0
56888- 0 0 0 0 0 0 0 0 0 0 0 0
56889- 0 0 0 0 0 0 0 0 0 0 0 0
56890- 0 0 0 0 0 0 0 0 0 0 0 0
56891- 0 0 0 0 0 0 0 0 0 0 0 0
56892- 0 0 0 0 0 0 0 0 0 0 0 0
56893- 0 0 0 0 0 0 0 0 0 10 10 10
56894- 38 38 38 86 86 86 14 14 14 10 10 10
56895-195 195 195 188 164 115 192 133 9 225 175 15
56896-239 182 13 234 190 10 232 195 16 232 200 30
56897-245 207 45 241 208 19 232 195 16 184 144 12
56898-218 194 134 211 206 186 42 42 42 2 2 6
56899- 2 2 6 2 2 6 2 2 6 2 2 6
56900- 50 50 50 74 74 74 30 30 30 6 6 6
56901- 0 0 0 0 0 0 0 0 0 0 0 0
56902- 0 0 0 0 0 0 0 0 0 0 0 0
56903- 0 0 0 0 0 0 0 0 0 0 0 0
56904- 0 0 0 0 0 0 0 0 0 0 0 0
56905- 0 0 0 0 0 0 0 0 0 0 0 0
56906- 0 0 0 0 0 0 0 0 0 0 0 0
56907- 0 0 0 0 0 0 0 0 0 0 0 0
56908- 0 0 0 0 0 0 0 0 0 0 0 0
56909- 0 0 0 0 0 0 0 0 0 0 0 0
56910- 0 0 0 0 0 0 0 0 0 0 0 0
56911- 0 0 0 0 0 0 0 0 0 0 0 0
56912- 0 0 0 0 0 0 0 0 0 0 0 0
56913- 0 0 0 0 0 0 0 0 0 10 10 10
56914- 34 34 34 86 86 86 14 14 14 2 2 6
56915-121 87 25 192 133 9 219 162 10 239 182 13
56916-236 186 11 232 195 16 241 208 19 244 214 54
56917-246 218 60 246 218 38 246 215 20 241 208 19
56918-241 208 19 226 184 13 121 87 25 2 2 6
56919- 2 2 6 2 2 6 2 2 6 2 2 6
56920- 50 50 50 82 82 82 34 34 34 10 10 10
56921- 0 0 0 0 0 0 0 0 0 0 0 0
56922- 0 0 0 0 0 0 0 0 0 0 0 0
56923- 0 0 0 0 0 0 0 0 0 0 0 0
56924- 0 0 0 0 0 0 0 0 0 0 0 0
56925- 0 0 0 0 0 0 0 0 0 0 0 0
56926- 0 0 0 0 0 0 0 0 0 0 0 0
56927- 0 0 0 0 0 0 0 0 0 0 0 0
56928- 0 0 0 0 0 0 0 0 0 0 0 0
56929- 0 0 0 0 0 0 0 0 0 0 0 0
56930- 0 0 0 0 0 0 0 0 0 0 0 0
56931- 0 0 0 0 0 0 0 0 0 0 0 0
56932- 0 0 0 0 0 0 0 0 0 0 0 0
56933- 0 0 0 0 0 0 0 0 0 10 10 10
56934- 34 34 34 82 82 82 30 30 30 61 42 6
56935-180 123 7 206 145 10 230 174 11 239 182 13
56936-234 190 10 238 202 15 241 208 19 246 218 74
56937-246 218 38 246 215 20 246 215 20 246 215 20
56938-226 184 13 215 174 15 184 144 12 6 6 6
56939- 2 2 6 2 2 6 2 2 6 2 2 6
56940- 26 26 26 94 94 94 42 42 42 14 14 14
56941- 0 0 0 0 0 0 0 0 0 0 0 0
56942- 0 0 0 0 0 0 0 0 0 0 0 0
56943- 0 0 0 0 0 0 0 0 0 0 0 0
56944- 0 0 0 0 0 0 0 0 0 0 0 0
56945- 0 0 0 0 0 0 0 0 0 0 0 0
56946- 0 0 0 0 0 0 0 0 0 0 0 0
56947- 0 0 0 0 0 0 0 0 0 0 0 0
56948- 0 0 0 0 0 0 0 0 0 0 0 0
56949- 0 0 0 0 0 0 0 0 0 0 0 0
56950- 0 0 0 0 0 0 0 0 0 0 0 0
56951- 0 0 0 0 0 0 0 0 0 0 0 0
56952- 0 0 0 0 0 0 0 0 0 0 0 0
56953- 0 0 0 0 0 0 0 0 0 10 10 10
56954- 30 30 30 78 78 78 50 50 50 104 69 6
56955-192 133 9 216 158 10 236 178 12 236 186 11
56956-232 195 16 241 208 19 244 214 54 245 215 43
56957-246 215 20 246 215 20 241 208 19 198 155 10
56958-200 144 11 216 158 10 156 118 10 2 2 6
56959- 2 2 6 2 2 6 2 2 6 2 2 6
56960- 6 6 6 90 90 90 54 54 54 18 18 18
56961- 6 6 6 0 0 0 0 0 0 0 0 0
56962- 0 0 0 0 0 0 0 0 0 0 0 0
56963- 0 0 0 0 0 0 0 0 0 0 0 0
56964- 0 0 0 0 0 0 0 0 0 0 0 0
56965- 0 0 0 0 0 0 0 0 0 0 0 0
56966- 0 0 0 0 0 0 0 0 0 0 0 0
56967- 0 0 0 0 0 0 0 0 0 0 0 0
56968- 0 0 0 0 0 0 0 0 0 0 0 0
56969- 0 0 0 0 0 0 0 0 0 0 0 0
56970- 0 0 0 0 0 0 0 0 0 0 0 0
56971- 0 0 0 0 0 0 0 0 0 0 0 0
56972- 0 0 0 0 0 0 0 0 0 0 0 0
56973- 0 0 0 0 0 0 0 0 0 10 10 10
56974- 30 30 30 78 78 78 46 46 46 22 22 22
56975-137 92 6 210 162 10 239 182 13 238 190 10
56976-238 202 15 241 208 19 246 215 20 246 215 20
56977-241 208 19 203 166 17 185 133 11 210 150 10
56978-216 158 10 210 150 10 102 78 10 2 2 6
56979- 6 6 6 54 54 54 14 14 14 2 2 6
56980- 2 2 6 62 62 62 74 74 74 30 30 30
56981- 10 10 10 0 0 0 0 0 0 0 0 0
56982- 0 0 0 0 0 0 0 0 0 0 0 0
56983- 0 0 0 0 0 0 0 0 0 0 0 0
56984- 0 0 0 0 0 0 0 0 0 0 0 0
56985- 0 0 0 0 0 0 0 0 0 0 0 0
56986- 0 0 0 0 0 0 0 0 0 0 0 0
56987- 0 0 0 0 0 0 0 0 0 0 0 0
56988- 0 0 0 0 0 0 0 0 0 0 0 0
56989- 0 0 0 0 0 0 0 0 0 0 0 0
56990- 0 0 0 0 0 0 0 0 0 0 0 0
56991- 0 0 0 0 0 0 0 0 0 0 0 0
56992- 0 0 0 0 0 0 0 0 0 0 0 0
56993- 0 0 0 0 0 0 0 0 0 10 10 10
56994- 34 34 34 78 78 78 50 50 50 6 6 6
56995- 94 70 30 139 102 15 190 146 13 226 184 13
56996-232 200 30 232 195 16 215 174 15 190 146 13
56997-168 122 10 192 133 9 210 150 10 213 154 11
56998-202 150 34 182 157 106 101 98 89 2 2 6
56999- 2 2 6 78 78 78 116 116 116 58 58 58
57000- 2 2 6 22 22 22 90 90 90 46 46 46
57001- 18 18 18 6 6 6 0 0 0 0 0 0
57002- 0 0 0 0 0 0 0 0 0 0 0 0
57003- 0 0 0 0 0 0 0 0 0 0 0 0
57004- 0 0 0 0 0 0 0 0 0 0 0 0
57005- 0 0 0 0 0 0 0 0 0 0 0 0
57006- 0 0 0 0 0 0 0 0 0 0 0 0
57007- 0 0 0 0 0 0 0 0 0 0 0 0
57008- 0 0 0 0 0 0 0 0 0 0 0 0
57009- 0 0 0 0 0 0 0 0 0 0 0 0
57010- 0 0 0 0 0 0 0 0 0 0 0 0
57011- 0 0 0 0 0 0 0 0 0 0 0 0
57012- 0 0 0 0 0 0 0 0 0 0 0 0
57013- 0 0 0 0 0 0 0 0 0 10 10 10
57014- 38 38 38 86 86 86 50 50 50 6 6 6
57015-128 128 128 174 154 114 156 107 11 168 122 10
57016-198 155 10 184 144 12 197 138 11 200 144 11
57017-206 145 10 206 145 10 197 138 11 188 164 115
57018-195 195 195 198 198 198 174 174 174 14 14 14
57019- 2 2 6 22 22 22 116 116 116 116 116 116
57020- 22 22 22 2 2 6 74 74 74 70 70 70
57021- 30 30 30 10 10 10 0 0 0 0 0 0
57022- 0 0 0 0 0 0 0 0 0 0 0 0
57023- 0 0 0 0 0 0 0 0 0 0 0 0
57024- 0 0 0 0 0 0 0 0 0 0 0 0
57025- 0 0 0 0 0 0 0 0 0 0 0 0
57026- 0 0 0 0 0 0 0 0 0 0 0 0
57027- 0 0 0 0 0 0 0 0 0 0 0 0
57028- 0 0 0 0 0 0 0 0 0 0 0 0
57029- 0 0 0 0 0 0 0 0 0 0 0 0
57030- 0 0 0 0 0 0 0 0 0 0 0 0
57031- 0 0 0 0 0 0 0 0 0 0 0 0
57032- 0 0 0 0 0 0 0 0 0 0 0 0
57033- 0 0 0 0 0 0 6 6 6 18 18 18
57034- 50 50 50 101 101 101 26 26 26 10 10 10
57035-138 138 138 190 190 190 174 154 114 156 107 11
57036-197 138 11 200 144 11 197 138 11 192 133 9
57037-180 123 7 190 142 34 190 178 144 187 187 187
57038-202 202 202 221 221 221 214 214 214 66 66 66
57039- 2 2 6 2 2 6 50 50 50 62 62 62
57040- 6 6 6 2 2 6 10 10 10 90 90 90
57041- 50 50 50 18 18 18 6 6 6 0 0 0
57042- 0 0 0 0 0 0 0 0 0 0 0 0
57043- 0 0 0 0 0 0 0 0 0 0 0 0
57044- 0 0 0 0 0 0 0 0 0 0 0 0
57045- 0 0 0 0 0 0 0 0 0 0 0 0
57046- 0 0 0 0 0 0 0 0 0 0 0 0
57047- 0 0 0 0 0 0 0 0 0 0 0 0
57048- 0 0 0 0 0 0 0 0 0 0 0 0
57049- 0 0 0 0 0 0 0 0 0 0 0 0
57050- 0 0 0 0 0 0 0 0 0 0 0 0
57051- 0 0 0 0 0 0 0 0 0 0 0 0
57052- 0 0 0 0 0 0 0 0 0 0 0 0
57053- 0 0 0 0 0 0 10 10 10 34 34 34
57054- 74 74 74 74 74 74 2 2 6 6 6 6
57055-144 144 144 198 198 198 190 190 190 178 166 146
57056-154 121 60 156 107 11 156 107 11 168 124 44
57057-174 154 114 187 187 187 190 190 190 210 210 210
57058-246 246 246 253 253 253 253 253 253 182 182 182
57059- 6 6 6 2 2 6 2 2 6 2 2 6
57060- 2 2 6 2 2 6 2 2 6 62 62 62
57061- 74 74 74 34 34 34 14 14 14 0 0 0
57062- 0 0 0 0 0 0 0 0 0 0 0 0
57063- 0 0 0 0 0 0 0 0 0 0 0 0
57064- 0 0 0 0 0 0 0 0 0 0 0 0
57065- 0 0 0 0 0 0 0 0 0 0 0 0
57066- 0 0 0 0 0 0 0 0 0 0 0 0
57067- 0 0 0 0 0 0 0 0 0 0 0 0
57068- 0 0 0 0 0 0 0 0 0 0 0 0
57069- 0 0 0 0 0 0 0 0 0 0 0 0
57070- 0 0 0 0 0 0 0 0 0 0 0 0
57071- 0 0 0 0 0 0 0 0 0 0 0 0
57072- 0 0 0 0 0 0 0 0 0 0 0 0
57073- 0 0 0 10 10 10 22 22 22 54 54 54
57074- 94 94 94 18 18 18 2 2 6 46 46 46
57075-234 234 234 221 221 221 190 190 190 190 190 190
57076-190 190 190 187 187 187 187 187 187 190 190 190
57077-190 190 190 195 195 195 214 214 214 242 242 242
57078-253 253 253 253 253 253 253 253 253 253 253 253
57079- 82 82 82 2 2 6 2 2 6 2 2 6
57080- 2 2 6 2 2 6 2 2 6 14 14 14
57081- 86 86 86 54 54 54 22 22 22 6 6 6
57082- 0 0 0 0 0 0 0 0 0 0 0 0
57083- 0 0 0 0 0 0 0 0 0 0 0 0
57084- 0 0 0 0 0 0 0 0 0 0 0 0
57085- 0 0 0 0 0 0 0 0 0 0 0 0
57086- 0 0 0 0 0 0 0 0 0 0 0 0
57087- 0 0 0 0 0 0 0 0 0 0 0 0
57088- 0 0 0 0 0 0 0 0 0 0 0 0
57089- 0 0 0 0 0 0 0 0 0 0 0 0
57090- 0 0 0 0 0 0 0 0 0 0 0 0
57091- 0 0 0 0 0 0 0 0 0 0 0 0
57092- 0 0 0 0 0 0 0 0 0 0 0 0
57093- 6 6 6 18 18 18 46 46 46 90 90 90
57094- 46 46 46 18 18 18 6 6 6 182 182 182
57095-253 253 253 246 246 246 206 206 206 190 190 190
57096-190 190 190 190 190 190 190 190 190 190 190 190
57097-206 206 206 231 231 231 250 250 250 253 253 253
57098-253 253 253 253 253 253 253 253 253 253 253 253
57099-202 202 202 14 14 14 2 2 6 2 2 6
57100- 2 2 6 2 2 6 2 2 6 2 2 6
57101- 42 42 42 86 86 86 42 42 42 18 18 18
57102- 6 6 6 0 0 0 0 0 0 0 0 0
57103- 0 0 0 0 0 0 0 0 0 0 0 0
57104- 0 0 0 0 0 0 0 0 0 0 0 0
57105- 0 0 0 0 0 0 0 0 0 0 0 0
57106- 0 0 0 0 0 0 0 0 0 0 0 0
57107- 0 0 0 0 0 0 0 0 0 0 0 0
57108- 0 0 0 0 0 0 0 0 0 0 0 0
57109- 0 0 0 0 0 0 0 0 0 0 0 0
57110- 0 0 0 0 0 0 0 0 0 0 0 0
57111- 0 0 0 0 0 0 0 0 0 0 0 0
57112- 0 0 0 0 0 0 0 0 0 6 6 6
57113- 14 14 14 38 38 38 74 74 74 66 66 66
57114- 2 2 6 6 6 6 90 90 90 250 250 250
57115-253 253 253 253 253 253 238 238 238 198 198 198
57116-190 190 190 190 190 190 195 195 195 221 221 221
57117-246 246 246 253 253 253 253 253 253 253 253 253
57118-253 253 253 253 253 253 253 253 253 253 253 253
57119-253 253 253 82 82 82 2 2 6 2 2 6
57120- 2 2 6 2 2 6 2 2 6 2 2 6
57121- 2 2 6 78 78 78 70 70 70 34 34 34
57122- 14 14 14 6 6 6 0 0 0 0 0 0
57123- 0 0 0 0 0 0 0 0 0 0 0 0
57124- 0 0 0 0 0 0 0 0 0 0 0 0
57125- 0 0 0 0 0 0 0 0 0 0 0 0
57126- 0 0 0 0 0 0 0 0 0 0 0 0
57127- 0 0 0 0 0 0 0 0 0 0 0 0
57128- 0 0 0 0 0 0 0 0 0 0 0 0
57129- 0 0 0 0 0 0 0 0 0 0 0 0
57130- 0 0 0 0 0 0 0 0 0 0 0 0
57131- 0 0 0 0 0 0 0 0 0 0 0 0
57132- 0 0 0 0 0 0 0 0 0 14 14 14
57133- 34 34 34 66 66 66 78 78 78 6 6 6
57134- 2 2 6 18 18 18 218 218 218 253 253 253
57135-253 253 253 253 253 253 253 253 253 246 246 246
57136-226 226 226 231 231 231 246 246 246 253 253 253
57137-253 253 253 253 253 253 253 253 253 253 253 253
57138-253 253 253 253 253 253 253 253 253 253 253 253
57139-253 253 253 178 178 178 2 2 6 2 2 6
57140- 2 2 6 2 2 6 2 2 6 2 2 6
57141- 2 2 6 18 18 18 90 90 90 62 62 62
57142- 30 30 30 10 10 10 0 0 0 0 0 0
57143- 0 0 0 0 0 0 0 0 0 0 0 0
57144- 0 0 0 0 0 0 0 0 0 0 0 0
57145- 0 0 0 0 0 0 0 0 0 0 0 0
57146- 0 0 0 0 0 0 0 0 0 0 0 0
57147- 0 0 0 0 0 0 0 0 0 0 0 0
57148- 0 0 0 0 0 0 0 0 0 0 0 0
57149- 0 0 0 0 0 0 0 0 0 0 0 0
57150- 0 0 0 0 0 0 0 0 0 0 0 0
57151- 0 0 0 0 0 0 0 0 0 0 0 0
57152- 0 0 0 0 0 0 10 10 10 26 26 26
57153- 58 58 58 90 90 90 18 18 18 2 2 6
57154- 2 2 6 110 110 110 253 253 253 253 253 253
57155-253 253 253 253 253 253 253 253 253 253 253 253
57156-250 250 250 253 253 253 253 253 253 253 253 253
57157-253 253 253 253 253 253 253 253 253 253 253 253
57158-253 253 253 253 253 253 253 253 253 253 253 253
57159-253 253 253 231 231 231 18 18 18 2 2 6
57160- 2 2 6 2 2 6 2 2 6 2 2 6
57161- 2 2 6 2 2 6 18 18 18 94 94 94
57162- 54 54 54 26 26 26 10 10 10 0 0 0
57163- 0 0 0 0 0 0 0 0 0 0 0 0
57164- 0 0 0 0 0 0 0 0 0 0 0 0
57165- 0 0 0 0 0 0 0 0 0 0 0 0
57166- 0 0 0 0 0 0 0 0 0 0 0 0
57167- 0 0 0 0 0 0 0 0 0 0 0 0
57168- 0 0 0 0 0 0 0 0 0 0 0 0
57169- 0 0 0 0 0 0 0 0 0 0 0 0
57170- 0 0 0 0 0 0 0 0 0 0 0 0
57171- 0 0 0 0 0 0 0 0 0 0 0 0
57172- 0 0 0 6 6 6 22 22 22 50 50 50
57173- 90 90 90 26 26 26 2 2 6 2 2 6
57174- 14 14 14 195 195 195 250 250 250 253 253 253
57175-253 253 253 253 253 253 253 253 253 253 253 253
57176-253 253 253 253 253 253 253 253 253 253 253 253
57177-253 253 253 253 253 253 253 253 253 253 253 253
57178-253 253 253 253 253 253 253 253 253 253 253 253
57179-250 250 250 242 242 242 54 54 54 2 2 6
57180- 2 2 6 2 2 6 2 2 6 2 2 6
57181- 2 2 6 2 2 6 2 2 6 38 38 38
57182- 86 86 86 50 50 50 22 22 22 6 6 6
57183- 0 0 0 0 0 0 0 0 0 0 0 0
57184- 0 0 0 0 0 0 0 0 0 0 0 0
57185- 0 0 0 0 0 0 0 0 0 0 0 0
57186- 0 0 0 0 0 0 0 0 0 0 0 0
57187- 0 0 0 0 0 0 0 0 0 0 0 0
57188- 0 0 0 0 0 0 0 0 0 0 0 0
57189- 0 0 0 0 0 0 0 0 0 0 0 0
57190- 0 0 0 0 0 0 0 0 0 0 0 0
57191- 0 0 0 0 0 0 0 0 0 0 0 0
57192- 6 6 6 14 14 14 38 38 38 82 82 82
57193- 34 34 34 2 2 6 2 2 6 2 2 6
57194- 42 42 42 195 195 195 246 246 246 253 253 253
57195-253 253 253 253 253 253 253 253 253 250 250 250
57196-242 242 242 242 242 242 250 250 250 253 253 253
57197-253 253 253 253 253 253 253 253 253 253 253 253
57198-253 253 253 250 250 250 246 246 246 238 238 238
57199-226 226 226 231 231 231 101 101 101 6 6 6
57200- 2 2 6 2 2 6 2 2 6 2 2 6
57201- 2 2 6 2 2 6 2 2 6 2 2 6
57202- 38 38 38 82 82 82 42 42 42 14 14 14
57203- 6 6 6 0 0 0 0 0 0 0 0 0
57204- 0 0 0 0 0 0 0 0 0 0 0 0
57205- 0 0 0 0 0 0 0 0 0 0 0 0
57206- 0 0 0 0 0 0 0 0 0 0 0 0
57207- 0 0 0 0 0 0 0 0 0 0 0 0
57208- 0 0 0 0 0 0 0 0 0 0 0 0
57209- 0 0 0 0 0 0 0 0 0 0 0 0
57210- 0 0 0 0 0 0 0 0 0 0 0 0
57211- 0 0 0 0 0 0 0 0 0 0 0 0
57212- 10 10 10 26 26 26 62 62 62 66 66 66
57213- 2 2 6 2 2 6 2 2 6 6 6 6
57214- 70 70 70 170 170 170 206 206 206 234 234 234
57215-246 246 246 250 250 250 250 250 250 238 238 238
57216-226 226 226 231 231 231 238 238 238 250 250 250
57217-250 250 250 250 250 250 246 246 246 231 231 231
57218-214 214 214 206 206 206 202 202 202 202 202 202
57219-198 198 198 202 202 202 182 182 182 18 18 18
57220- 2 2 6 2 2 6 2 2 6 2 2 6
57221- 2 2 6 2 2 6 2 2 6 2 2 6
57222- 2 2 6 62 62 62 66 66 66 30 30 30
57223- 10 10 10 0 0 0 0 0 0 0 0 0
57224- 0 0 0 0 0 0 0 0 0 0 0 0
57225- 0 0 0 0 0 0 0 0 0 0 0 0
57226- 0 0 0 0 0 0 0 0 0 0 0 0
57227- 0 0 0 0 0 0 0 0 0 0 0 0
57228- 0 0 0 0 0 0 0 0 0 0 0 0
57229- 0 0 0 0 0 0 0 0 0 0 0 0
57230- 0 0 0 0 0 0 0 0 0 0 0 0
57231- 0 0 0 0 0 0 0 0 0 0 0 0
57232- 14 14 14 42 42 42 82 82 82 18 18 18
57233- 2 2 6 2 2 6 2 2 6 10 10 10
57234- 94 94 94 182 182 182 218 218 218 242 242 242
57235-250 250 250 253 253 253 253 253 253 250 250 250
57236-234 234 234 253 253 253 253 253 253 253 253 253
57237-253 253 253 253 253 253 253 253 253 246 246 246
57238-238 238 238 226 226 226 210 210 210 202 202 202
57239-195 195 195 195 195 195 210 210 210 158 158 158
57240- 6 6 6 14 14 14 50 50 50 14 14 14
57241- 2 2 6 2 2 6 2 2 6 2 2 6
57242- 2 2 6 6 6 6 86 86 86 46 46 46
57243- 18 18 18 6 6 6 0 0 0 0 0 0
57244- 0 0 0 0 0 0 0 0 0 0 0 0
57245- 0 0 0 0 0 0 0 0 0 0 0 0
57246- 0 0 0 0 0 0 0 0 0 0 0 0
57247- 0 0 0 0 0 0 0 0 0 0 0 0
57248- 0 0 0 0 0 0 0 0 0 0 0 0
57249- 0 0 0 0 0 0 0 0 0 0 0 0
57250- 0 0 0 0 0 0 0 0 0 0 0 0
57251- 0 0 0 0 0 0 0 0 0 6 6 6
57252- 22 22 22 54 54 54 70 70 70 2 2 6
57253- 2 2 6 10 10 10 2 2 6 22 22 22
57254-166 166 166 231 231 231 250 250 250 253 253 253
57255-253 253 253 253 253 253 253 253 253 250 250 250
57256-242 242 242 253 253 253 253 253 253 253 253 253
57257-253 253 253 253 253 253 253 253 253 253 253 253
57258-253 253 253 253 253 253 253 253 253 246 246 246
57259-231 231 231 206 206 206 198 198 198 226 226 226
57260- 94 94 94 2 2 6 6 6 6 38 38 38
57261- 30 30 30 2 2 6 2 2 6 2 2 6
57262- 2 2 6 2 2 6 62 62 62 66 66 66
57263- 26 26 26 10 10 10 0 0 0 0 0 0
57264- 0 0 0 0 0 0 0 0 0 0 0 0
57265- 0 0 0 0 0 0 0 0 0 0 0 0
57266- 0 0 0 0 0 0 0 0 0 0 0 0
57267- 0 0 0 0 0 0 0 0 0 0 0 0
57268- 0 0 0 0 0 0 0 0 0 0 0 0
57269- 0 0 0 0 0 0 0 0 0 0 0 0
57270- 0 0 0 0 0 0 0 0 0 0 0 0
57271- 0 0 0 0 0 0 0 0 0 10 10 10
57272- 30 30 30 74 74 74 50 50 50 2 2 6
57273- 26 26 26 26 26 26 2 2 6 106 106 106
57274-238 238 238 253 253 253 253 253 253 253 253 253
57275-253 253 253 253 253 253 253 253 253 253 253 253
57276-253 253 253 253 253 253 253 253 253 253 253 253
57277-253 253 253 253 253 253 253 253 253 253 253 253
57278-253 253 253 253 253 253 253 253 253 253 253 253
57279-253 253 253 246 246 246 218 218 218 202 202 202
57280-210 210 210 14 14 14 2 2 6 2 2 6
57281- 30 30 30 22 22 22 2 2 6 2 2 6
57282- 2 2 6 2 2 6 18 18 18 86 86 86
57283- 42 42 42 14 14 14 0 0 0 0 0 0
57284- 0 0 0 0 0 0 0 0 0 0 0 0
57285- 0 0 0 0 0 0 0 0 0 0 0 0
57286- 0 0 0 0 0 0 0 0 0 0 0 0
57287- 0 0 0 0 0 0 0 0 0 0 0 0
57288- 0 0 0 0 0 0 0 0 0 0 0 0
57289- 0 0 0 0 0 0 0 0 0 0 0 0
57290- 0 0 0 0 0 0 0 0 0 0 0 0
57291- 0 0 0 0 0 0 0 0 0 14 14 14
57292- 42 42 42 90 90 90 22 22 22 2 2 6
57293- 42 42 42 2 2 6 18 18 18 218 218 218
57294-253 253 253 253 253 253 253 253 253 253 253 253
57295-253 253 253 253 253 253 253 253 253 253 253 253
57296-253 253 253 253 253 253 253 253 253 253 253 253
57297-253 253 253 253 253 253 253 253 253 253 253 253
57298-253 253 253 253 253 253 253 253 253 253 253 253
57299-253 253 253 253 253 253 250 250 250 221 221 221
57300-218 218 218 101 101 101 2 2 6 14 14 14
57301- 18 18 18 38 38 38 10 10 10 2 2 6
57302- 2 2 6 2 2 6 2 2 6 78 78 78
57303- 58 58 58 22 22 22 6 6 6 0 0 0
57304- 0 0 0 0 0 0 0 0 0 0 0 0
57305- 0 0 0 0 0 0 0 0 0 0 0 0
57306- 0 0 0 0 0 0 0 0 0 0 0 0
57307- 0 0 0 0 0 0 0 0 0 0 0 0
57308- 0 0 0 0 0 0 0 0 0 0 0 0
57309- 0 0 0 0 0 0 0 0 0 0 0 0
57310- 0 0 0 0 0 0 0 0 0 0 0 0
57311- 0 0 0 0 0 0 6 6 6 18 18 18
57312- 54 54 54 82 82 82 2 2 6 26 26 26
57313- 22 22 22 2 2 6 123 123 123 253 253 253
57314-253 253 253 253 253 253 253 253 253 253 253 253
57315-253 253 253 253 253 253 253 253 253 253 253 253
57316-253 253 253 253 253 253 253 253 253 253 253 253
57317-253 253 253 253 253 253 253 253 253 253 253 253
57318-253 253 253 253 253 253 253 253 253 253 253 253
57319-253 253 253 253 253 253 253 253 253 250 250 250
57320-238 238 238 198 198 198 6 6 6 38 38 38
57321- 58 58 58 26 26 26 38 38 38 2 2 6
57322- 2 2 6 2 2 6 2 2 6 46 46 46
57323- 78 78 78 30 30 30 10 10 10 0 0 0
57324- 0 0 0 0 0 0 0 0 0 0 0 0
57325- 0 0 0 0 0 0 0 0 0 0 0 0
57326- 0 0 0 0 0 0 0 0 0 0 0 0
57327- 0 0 0 0 0 0 0 0 0 0 0 0
57328- 0 0 0 0 0 0 0 0 0 0 0 0
57329- 0 0 0 0 0 0 0 0 0 0 0 0
57330- 0 0 0 0 0 0 0 0 0 0 0 0
57331- 0 0 0 0 0 0 10 10 10 30 30 30
57332- 74 74 74 58 58 58 2 2 6 42 42 42
57333- 2 2 6 22 22 22 231 231 231 253 253 253
57334-253 253 253 253 253 253 253 253 253 253 253 253
57335-253 253 253 253 253 253 253 253 253 250 250 250
57336-253 253 253 253 253 253 253 253 253 253 253 253
57337-253 253 253 253 253 253 253 253 253 253 253 253
57338-253 253 253 253 253 253 253 253 253 253 253 253
57339-253 253 253 253 253 253 253 253 253 253 253 253
57340-253 253 253 246 246 246 46 46 46 38 38 38
57341- 42 42 42 14 14 14 38 38 38 14 14 14
57342- 2 2 6 2 2 6 2 2 6 6 6 6
57343- 86 86 86 46 46 46 14 14 14 0 0 0
57344- 0 0 0 0 0 0 0 0 0 0 0 0
57345- 0 0 0 0 0 0 0 0 0 0 0 0
57346- 0 0 0 0 0 0 0 0 0 0 0 0
57347- 0 0 0 0 0 0 0 0 0 0 0 0
57348- 0 0 0 0 0 0 0 0 0 0 0 0
57349- 0 0 0 0 0 0 0 0 0 0 0 0
57350- 0 0 0 0 0 0 0 0 0 0 0 0
57351- 0 0 0 6 6 6 14 14 14 42 42 42
57352- 90 90 90 18 18 18 18 18 18 26 26 26
57353- 2 2 6 116 116 116 253 253 253 253 253 253
57354-253 253 253 253 253 253 253 253 253 253 253 253
57355-253 253 253 253 253 253 250 250 250 238 238 238
57356-253 253 253 253 253 253 253 253 253 253 253 253
57357-253 253 253 253 253 253 253 253 253 253 253 253
57358-253 253 253 253 253 253 253 253 253 253 253 253
57359-253 253 253 253 253 253 253 253 253 253 253 253
57360-253 253 253 253 253 253 94 94 94 6 6 6
57361- 2 2 6 2 2 6 10 10 10 34 34 34
57362- 2 2 6 2 2 6 2 2 6 2 2 6
57363- 74 74 74 58 58 58 22 22 22 6 6 6
57364- 0 0 0 0 0 0 0 0 0 0 0 0
57365- 0 0 0 0 0 0 0 0 0 0 0 0
57366- 0 0 0 0 0 0 0 0 0 0 0 0
57367- 0 0 0 0 0 0 0 0 0 0 0 0
57368- 0 0 0 0 0 0 0 0 0 0 0 0
57369- 0 0 0 0 0 0 0 0 0 0 0 0
57370- 0 0 0 0 0 0 0 0 0 0 0 0
57371- 0 0 0 10 10 10 26 26 26 66 66 66
57372- 82 82 82 2 2 6 38 38 38 6 6 6
57373- 14 14 14 210 210 210 253 253 253 253 253 253
57374-253 253 253 253 253 253 253 253 253 253 253 253
57375-253 253 253 253 253 253 246 246 246 242 242 242
57376-253 253 253 253 253 253 253 253 253 253 253 253
57377-253 253 253 253 253 253 253 253 253 253 253 253
57378-253 253 253 253 253 253 253 253 253 253 253 253
57379-253 253 253 253 253 253 253 253 253 253 253 253
57380-253 253 253 253 253 253 144 144 144 2 2 6
57381- 2 2 6 2 2 6 2 2 6 46 46 46
57382- 2 2 6 2 2 6 2 2 6 2 2 6
57383- 42 42 42 74 74 74 30 30 30 10 10 10
57384- 0 0 0 0 0 0 0 0 0 0 0 0
57385- 0 0 0 0 0 0 0 0 0 0 0 0
57386- 0 0 0 0 0 0 0 0 0 0 0 0
57387- 0 0 0 0 0 0 0 0 0 0 0 0
57388- 0 0 0 0 0 0 0 0 0 0 0 0
57389- 0 0 0 0 0 0 0 0 0 0 0 0
57390- 0 0 0 0 0 0 0 0 0 0 0 0
57391- 6 6 6 14 14 14 42 42 42 90 90 90
57392- 26 26 26 6 6 6 42 42 42 2 2 6
57393- 74 74 74 250 250 250 253 253 253 253 253 253
57394-253 253 253 253 253 253 253 253 253 253 253 253
57395-253 253 253 253 253 253 242 242 242 242 242 242
57396-253 253 253 253 253 253 253 253 253 253 253 253
57397-253 253 253 253 253 253 253 253 253 253 253 253
57398-253 253 253 253 253 253 253 253 253 253 253 253
57399-253 253 253 253 253 253 253 253 253 253 253 253
57400-253 253 253 253 253 253 182 182 182 2 2 6
57401- 2 2 6 2 2 6 2 2 6 46 46 46
57402- 2 2 6 2 2 6 2 2 6 2 2 6
57403- 10 10 10 86 86 86 38 38 38 10 10 10
57404- 0 0 0 0 0 0 0 0 0 0 0 0
57405- 0 0 0 0 0 0 0 0 0 0 0 0
57406- 0 0 0 0 0 0 0 0 0 0 0 0
57407- 0 0 0 0 0 0 0 0 0 0 0 0
57408- 0 0 0 0 0 0 0 0 0 0 0 0
57409- 0 0 0 0 0 0 0 0 0 0 0 0
57410- 0 0 0 0 0 0 0 0 0 0 0 0
57411- 10 10 10 26 26 26 66 66 66 82 82 82
57412- 2 2 6 22 22 22 18 18 18 2 2 6
57413-149 149 149 253 253 253 253 253 253 253 253 253
57414-253 253 253 253 253 253 253 253 253 253 253 253
57415-253 253 253 253 253 253 234 234 234 242 242 242
57416-253 253 253 253 253 253 253 253 253 253 253 253
57417-253 253 253 253 253 253 253 253 253 253 253 253
57418-253 253 253 253 253 253 253 253 253 253 253 253
57419-253 253 253 253 253 253 253 253 253 253 253 253
57420-253 253 253 253 253 253 206 206 206 2 2 6
57421- 2 2 6 2 2 6 2 2 6 38 38 38
57422- 2 2 6 2 2 6 2 2 6 2 2 6
57423- 6 6 6 86 86 86 46 46 46 14 14 14
57424- 0 0 0 0 0 0 0 0 0 0 0 0
57425- 0 0 0 0 0 0 0 0 0 0 0 0
57426- 0 0 0 0 0 0 0 0 0 0 0 0
57427- 0 0 0 0 0 0 0 0 0 0 0 0
57428- 0 0 0 0 0 0 0 0 0 0 0 0
57429- 0 0 0 0 0 0 0 0 0 0 0 0
57430- 0 0 0 0 0 0 0 0 0 6 6 6
57431- 18 18 18 46 46 46 86 86 86 18 18 18
57432- 2 2 6 34 34 34 10 10 10 6 6 6
57433-210 210 210 253 253 253 253 253 253 253 253 253
57434-253 253 253 253 253 253 253 253 253 253 253 253
57435-253 253 253 253 253 253 234 234 234 242 242 242
57436-253 253 253 253 253 253 253 253 253 253 253 253
57437-253 253 253 253 253 253 253 253 253 253 253 253
57438-253 253 253 253 253 253 253 253 253 253 253 253
57439-253 253 253 253 253 253 253 253 253 253 253 253
57440-253 253 253 253 253 253 221 221 221 6 6 6
57441- 2 2 6 2 2 6 6 6 6 30 30 30
57442- 2 2 6 2 2 6 2 2 6 2 2 6
57443- 2 2 6 82 82 82 54 54 54 18 18 18
57444- 6 6 6 0 0 0 0 0 0 0 0 0
57445- 0 0 0 0 0 0 0 0 0 0 0 0
57446- 0 0 0 0 0 0 0 0 0 0 0 0
57447- 0 0 0 0 0 0 0 0 0 0 0 0
57448- 0 0 0 0 0 0 0 0 0 0 0 0
57449- 0 0 0 0 0 0 0 0 0 0 0 0
57450- 0 0 0 0 0 0 0 0 0 10 10 10
57451- 26 26 26 66 66 66 62 62 62 2 2 6
57452- 2 2 6 38 38 38 10 10 10 26 26 26
57453-238 238 238 253 253 253 253 253 253 253 253 253
57454-253 253 253 253 253 253 253 253 253 253 253 253
57455-253 253 253 253 253 253 231 231 231 238 238 238
57456-253 253 253 253 253 253 253 253 253 253 253 253
57457-253 253 253 253 253 253 253 253 253 253 253 253
57458-253 253 253 253 253 253 253 253 253 253 253 253
57459-253 253 253 253 253 253 253 253 253 253 253 253
57460-253 253 253 253 253 253 231 231 231 6 6 6
57461- 2 2 6 2 2 6 10 10 10 30 30 30
57462- 2 2 6 2 2 6 2 2 6 2 2 6
57463- 2 2 6 66 66 66 58 58 58 22 22 22
57464- 6 6 6 0 0 0 0 0 0 0 0 0
57465- 0 0 0 0 0 0 0 0 0 0 0 0
57466- 0 0 0 0 0 0 0 0 0 0 0 0
57467- 0 0 0 0 0 0 0 0 0 0 0 0
57468- 0 0 0 0 0 0 0 0 0 0 0 0
57469- 0 0 0 0 0 0 0 0 0 0 0 0
57470- 0 0 0 0 0 0 0 0 0 10 10 10
57471- 38 38 38 78 78 78 6 6 6 2 2 6
57472- 2 2 6 46 46 46 14 14 14 42 42 42
57473-246 246 246 253 253 253 253 253 253 253 253 253
57474-253 253 253 253 253 253 253 253 253 253 253 253
57475-253 253 253 253 253 253 231 231 231 242 242 242
57476-253 253 253 253 253 253 253 253 253 253 253 253
57477-253 253 253 253 253 253 253 253 253 253 253 253
57478-253 253 253 253 253 253 253 253 253 253 253 253
57479-253 253 253 253 253 253 253 253 253 253 253 253
57480-253 253 253 253 253 253 234 234 234 10 10 10
57481- 2 2 6 2 2 6 22 22 22 14 14 14
57482- 2 2 6 2 2 6 2 2 6 2 2 6
57483- 2 2 6 66 66 66 62 62 62 22 22 22
57484- 6 6 6 0 0 0 0 0 0 0 0 0
57485- 0 0 0 0 0 0 0 0 0 0 0 0
57486- 0 0 0 0 0 0 0 0 0 0 0 0
57487- 0 0 0 0 0 0 0 0 0 0 0 0
57488- 0 0 0 0 0 0 0 0 0 0 0 0
57489- 0 0 0 0 0 0 0 0 0 0 0 0
57490- 0 0 0 0 0 0 6 6 6 18 18 18
57491- 50 50 50 74 74 74 2 2 6 2 2 6
57492- 14 14 14 70 70 70 34 34 34 62 62 62
57493-250 250 250 253 253 253 253 253 253 253 253 253
57494-253 253 253 253 253 253 253 253 253 253 253 253
57495-253 253 253 253 253 253 231 231 231 246 246 246
57496-253 253 253 253 253 253 253 253 253 253 253 253
57497-253 253 253 253 253 253 253 253 253 253 253 253
57498-253 253 253 253 253 253 253 253 253 253 253 253
57499-253 253 253 253 253 253 253 253 253 253 253 253
57500-253 253 253 253 253 253 234 234 234 14 14 14
57501- 2 2 6 2 2 6 30 30 30 2 2 6
57502- 2 2 6 2 2 6 2 2 6 2 2 6
57503- 2 2 6 66 66 66 62 62 62 22 22 22
57504- 6 6 6 0 0 0 0 0 0 0 0 0
57505- 0 0 0 0 0 0 0 0 0 0 0 0
57506- 0 0 0 0 0 0 0 0 0 0 0 0
57507- 0 0 0 0 0 0 0 0 0 0 0 0
57508- 0 0 0 0 0 0 0 0 0 0 0 0
57509- 0 0 0 0 0 0 0 0 0 0 0 0
57510- 0 0 0 0 0 0 6 6 6 18 18 18
57511- 54 54 54 62 62 62 2 2 6 2 2 6
57512- 2 2 6 30 30 30 46 46 46 70 70 70
57513-250 250 250 253 253 253 253 253 253 253 253 253
57514-253 253 253 253 253 253 253 253 253 253 253 253
57515-253 253 253 253 253 253 231 231 231 246 246 246
57516-253 253 253 253 253 253 253 253 253 253 253 253
57517-253 253 253 253 253 253 253 253 253 253 253 253
57518-253 253 253 253 253 253 253 253 253 253 253 253
57519-253 253 253 253 253 253 253 253 253 253 253 253
57520-253 253 253 253 253 253 226 226 226 10 10 10
57521- 2 2 6 6 6 6 30 30 30 2 2 6
57522- 2 2 6 2 2 6 2 2 6 2 2 6
57523- 2 2 6 66 66 66 58 58 58 22 22 22
57524- 6 6 6 0 0 0 0 0 0 0 0 0
57525- 0 0 0 0 0 0 0 0 0 0 0 0
57526- 0 0 0 0 0 0 0 0 0 0 0 0
57527- 0 0 0 0 0 0 0 0 0 0 0 0
57528- 0 0 0 0 0 0 0 0 0 0 0 0
57529- 0 0 0 0 0 0 0 0 0 0 0 0
57530- 0 0 0 0 0 0 6 6 6 22 22 22
57531- 58 58 58 62 62 62 2 2 6 2 2 6
57532- 2 2 6 2 2 6 30 30 30 78 78 78
57533-250 250 250 253 253 253 253 253 253 253 253 253
57534-253 253 253 253 253 253 253 253 253 253 253 253
57535-253 253 253 253 253 253 231 231 231 246 246 246
57536-253 253 253 253 253 253 253 253 253 253 253 253
57537-253 253 253 253 253 253 253 253 253 253 253 253
57538-253 253 253 253 253 253 253 253 253 253 253 253
57539-253 253 253 253 253 253 253 253 253 253 253 253
57540-253 253 253 253 253 253 206 206 206 2 2 6
57541- 22 22 22 34 34 34 18 14 6 22 22 22
57542- 26 26 26 18 18 18 6 6 6 2 2 6
57543- 2 2 6 82 82 82 54 54 54 18 18 18
57544- 6 6 6 0 0 0 0 0 0 0 0 0
57545- 0 0 0 0 0 0 0 0 0 0 0 0
57546- 0 0 0 0 0 0 0 0 0 0 0 0
57547- 0 0 0 0 0 0 0 0 0 0 0 0
57548- 0 0 0 0 0 0 0 0 0 0 0 0
57549- 0 0 0 0 0 0 0 0 0 0 0 0
57550- 0 0 0 0 0 0 6 6 6 26 26 26
57551- 62 62 62 106 106 106 74 54 14 185 133 11
57552-210 162 10 121 92 8 6 6 6 62 62 62
57553-238 238 238 253 253 253 253 253 253 253 253 253
57554-253 253 253 253 253 253 253 253 253 253 253 253
57555-253 253 253 253 253 253 231 231 231 246 246 246
57556-253 253 253 253 253 253 253 253 253 253 253 253
57557-253 253 253 253 253 253 253 253 253 253 253 253
57558-253 253 253 253 253 253 253 253 253 253 253 253
57559-253 253 253 253 253 253 253 253 253 253 253 253
57560-253 253 253 253 253 253 158 158 158 18 18 18
57561- 14 14 14 2 2 6 2 2 6 2 2 6
57562- 6 6 6 18 18 18 66 66 66 38 38 38
57563- 6 6 6 94 94 94 50 50 50 18 18 18
57564- 6 6 6 0 0 0 0 0 0 0 0 0
57565- 0 0 0 0 0 0 0 0 0 0 0 0
57566- 0 0 0 0 0 0 0 0 0 0 0 0
57567- 0 0 0 0 0 0 0 0 0 0 0 0
57568- 0 0 0 0 0 0 0 0 0 0 0 0
57569- 0 0 0 0 0 0 0 0 0 6 6 6
57570- 10 10 10 10 10 10 18 18 18 38 38 38
57571- 78 78 78 142 134 106 216 158 10 242 186 14
57572-246 190 14 246 190 14 156 118 10 10 10 10
57573- 90 90 90 238 238 238 253 253 253 253 253 253
57574-253 253 253 253 253 253 253 253 253 253 253 253
57575-253 253 253 253 253 253 231 231 231 250 250 250
57576-253 253 253 253 253 253 253 253 253 253 253 253
57577-253 253 253 253 253 253 253 253 253 253 253 253
57578-253 253 253 253 253 253 253 253 253 253 253 253
57579-253 253 253 253 253 253 253 253 253 246 230 190
57580-238 204 91 238 204 91 181 142 44 37 26 9
57581- 2 2 6 2 2 6 2 2 6 2 2 6
57582- 2 2 6 2 2 6 38 38 38 46 46 46
57583- 26 26 26 106 106 106 54 54 54 18 18 18
57584- 6 6 6 0 0 0 0 0 0 0 0 0
57585- 0 0 0 0 0 0 0 0 0 0 0 0
57586- 0 0 0 0 0 0 0 0 0 0 0 0
57587- 0 0 0 0 0 0 0 0 0 0 0 0
57588- 0 0 0 0 0 0 0 0 0 0 0 0
57589- 0 0 0 6 6 6 14 14 14 22 22 22
57590- 30 30 30 38 38 38 50 50 50 70 70 70
57591-106 106 106 190 142 34 226 170 11 242 186 14
57592-246 190 14 246 190 14 246 190 14 154 114 10
57593- 6 6 6 74 74 74 226 226 226 253 253 253
57594-253 253 253 253 253 253 253 253 253 253 253 253
57595-253 253 253 253 253 253 231 231 231 250 250 250
57596-253 253 253 253 253 253 253 253 253 253 253 253
57597-253 253 253 253 253 253 253 253 253 253 253 253
57598-253 253 253 253 253 253 253 253 253 253 253 253
57599-253 253 253 253 253 253 253 253 253 228 184 62
57600-241 196 14 241 208 19 232 195 16 38 30 10
57601- 2 2 6 2 2 6 2 2 6 2 2 6
57602- 2 2 6 6 6 6 30 30 30 26 26 26
57603-203 166 17 154 142 90 66 66 66 26 26 26
57604- 6 6 6 0 0 0 0 0 0 0 0 0
57605- 0 0 0 0 0 0 0 0 0 0 0 0
57606- 0 0 0 0 0 0 0 0 0 0 0 0
57607- 0 0 0 0 0 0 0 0 0 0 0 0
57608- 0 0 0 0 0 0 0 0 0 0 0 0
57609- 6 6 6 18 18 18 38 38 38 58 58 58
57610- 78 78 78 86 86 86 101 101 101 123 123 123
57611-175 146 61 210 150 10 234 174 13 246 186 14
57612-246 190 14 246 190 14 246 190 14 238 190 10
57613-102 78 10 2 2 6 46 46 46 198 198 198
57614-253 253 253 253 253 253 253 253 253 253 253 253
57615-253 253 253 253 253 253 234 234 234 242 242 242
57616-253 253 253 253 253 253 253 253 253 253 253 253
57617-253 253 253 253 253 253 253 253 253 253 253 253
57618-253 253 253 253 253 253 253 253 253 253 253 253
57619-253 253 253 253 253 253 253 253 253 224 178 62
57620-242 186 14 241 196 14 210 166 10 22 18 6
57621- 2 2 6 2 2 6 2 2 6 2 2 6
57622- 2 2 6 2 2 6 6 6 6 121 92 8
57623-238 202 15 232 195 16 82 82 82 34 34 34
57624- 10 10 10 0 0 0 0 0 0 0 0 0
57625- 0 0 0 0 0 0 0 0 0 0 0 0
57626- 0 0 0 0 0 0 0 0 0 0 0 0
57627- 0 0 0 0 0 0 0 0 0 0 0 0
57628- 0 0 0 0 0 0 0 0 0 0 0 0
57629- 14 14 14 38 38 38 70 70 70 154 122 46
57630-190 142 34 200 144 11 197 138 11 197 138 11
57631-213 154 11 226 170 11 242 186 14 246 190 14
57632-246 190 14 246 190 14 246 190 14 246 190 14
57633-225 175 15 46 32 6 2 2 6 22 22 22
57634-158 158 158 250 250 250 253 253 253 253 253 253
57635-253 253 253 253 253 253 253 253 253 253 253 253
57636-253 253 253 253 253 253 253 253 253 253 253 253
57637-253 253 253 253 253 253 253 253 253 253 253 253
57638-253 253 253 253 253 253 253 253 253 253 253 253
57639-253 253 253 250 250 250 242 242 242 224 178 62
57640-239 182 13 236 186 11 213 154 11 46 32 6
57641- 2 2 6 2 2 6 2 2 6 2 2 6
57642- 2 2 6 2 2 6 61 42 6 225 175 15
57643-238 190 10 236 186 11 112 100 78 42 42 42
57644- 14 14 14 0 0 0 0 0 0 0 0 0
57645- 0 0 0 0 0 0 0 0 0 0 0 0
57646- 0 0 0 0 0 0 0 0 0 0 0 0
57647- 0 0 0 0 0 0 0 0 0 0 0 0
57648- 0 0 0 0 0 0 0 0 0 6 6 6
57649- 22 22 22 54 54 54 154 122 46 213 154 11
57650-226 170 11 230 174 11 226 170 11 226 170 11
57651-236 178 12 242 186 14 246 190 14 246 190 14
57652-246 190 14 246 190 14 246 190 14 246 190 14
57653-241 196 14 184 144 12 10 10 10 2 2 6
57654- 6 6 6 116 116 116 242 242 242 253 253 253
57655-253 253 253 253 253 253 253 253 253 253 253 253
57656-253 253 253 253 253 253 253 253 253 253 253 253
57657-253 253 253 253 253 253 253 253 253 253 253 253
57658-253 253 253 253 253 253 253 253 253 253 253 253
57659-253 253 253 231 231 231 198 198 198 214 170 54
57660-236 178 12 236 178 12 210 150 10 137 92 6
57661- 18 14 6 2 2 6 2 2 6 2 2 6
57662- 6 6 6 70 47 6 200 144 11 236 178 12
57663-239 182 13 239 182 13 124 112 88 58 58 58
57664- 22 22 22 6 6 6 0 0 0 0 0 0
57665- 0 0 0 0 0 0 0 0 0 0 0 0
57666- 0 0 0 0 0 0 0 0 0 0 0 0
57667- 0 0 0 0 0 0 0 0 0 0 0 0
57668- 0 0 0 0 0 0 0 0 0 10 10 10
57669- 30 30 30 70 70 70 180 133 36 226 170 11
57670-239 182 13 242 186 14 242 186 14 246 186 14
57671-246 190 14 246 190 14 246 190 14 246 190 14
57672-246 190 14 246 190 14 246 190 14 246 190 14
57673-246 190 14 232 195 16 98 70 6 2 2 6
57674- 2 2 6 2 2 6 66 66 66 221 221 221
57675-253 253 253 253 253 253 253 253 253 253 253 253
57676-253 253 253 253 253 253 253 253 253 253 253 253
57677-253 253 253 253 253 253 253 253 253 253 253 253
57678-253 253 253 253 253 253 253 253 253 253 253 253
57679-253 253 253 206 206 206 198 198 198 214 166 58
57680-230 174 11 230 174 11 216 158 10 192 133 9
57681-163 110 8 116 81 8 102 78 10 116 81 8
57682-167 114 7 197 138 11 226 170 11 239 182 13
57683-242 186 14 242 186 14 162 146 94 78 78 78
57684- 34 34 34 14 14 14 6 6 6 0 0 0
57685- 0 0 0 0 0 0 0 0 0 0 0 0
57686- 0 0 0 0 0 0 0 0 0 0 0 0
57687- 0 0 0 0 0 0 0 0 0 0 0 0
57688- 0 0 0 0 0 0 0 0 0 6 6 6
57689- 30 30 30 78 78 78 190 142 34 226 170 11
57690-239 182 13 246 190 14 246 190 14 246 190 14
57691-246 190 14 246 190 14 246 190 14 246 190 14
57692-246 190 14 246 190 14 246 190 14 246 190 14
57693-246 190 14 241 196 14 203 166 17 22 18 6
57694- 2 2 6 2 2 6 2 2 6 38 38 38
57695-218 218 218 253 253 253 253 253 253 253 253 253
57696-253 253 253 253 253 253 253 253 253 253 253 253
57697-253 253 253 253 253 253 253 253 253 253 253 253
57698-253 253 253 253 253 253 253 253 253 253 253 253
57699-250 250 250 206 206 206 198 198 198 202 162 69
57700-226 170 11 236 178 12 224 166 10 210 150 10
57701-200 144 11 197 138 11 192 133 9 197 138 11
57702-210 150 10 226 170 11 242 186 14 246 190 14
57703-246 190 14 246 186 14 225 175 15 124 112 88
57704- 62 62 62 30 30 30 14 14 14 6 6 6
57705- 0 0 0 0 0 0 0 0 0 0 0 0
57706- 0 0 0 0 0 0 0 0 0 0 0 0
57707- 0 0 0 0 0 0 0 0 0 0 0 0
57708- 0 0 0 0 0 0 0 0 0 10 10 10
57709- 30 30 30 78 78 78 174 135 50 224 166 10
57710-239 182 13 246 190 14 246 190 14 246 190 14
57711-246 190 14 246 190 14 246 190 14 246 190 14
57712-246 190 14 246 190 14 246 190 14 246 190 14
57713-246 190 14 246 190 14 241 196 14 139 102 15
57714- 2 2 6 2 2 6 2 2 6 2 2 6
57715- 78 78 78 250 250 250 253 253 253 253 253 253
57716-253 253 253 253 253 253 253 253 253 253 253 253
57717-253 253 253 253 253 253 253 253 253 253 253 253
57718-253 253 253 253 253 253 253 253 253 253 253 253
57719-250 250 250 214 214 214 198 198 198 190 150 46
57720-219 162 10 236 178 12 234 174 13 224 166 10
57721-216 158 10 213 154 11 213 154 11 216 158 10
57722-226 170 11 239 182 13 246 190 14 246 190 14
57723-246 190 14 246 190 14 242 186 14 206 162 42
57724-101 101 101 58 58 58 30 30 30 14 14 14
57725- 6 6 6 0 0 0 0 0 0 0 0 0
57726- 0 0 0 0 0 0 0 0 0 0 0 0
57727- 0 0 0 0 0 0 0 0 0 0 0 0
57728- 0 0 0 0 0 0 0 0 0 10 10 10
57729- 30 30 30 74 74 74 174 135 50 216 158 10
57730-236 178 12 246 190 14 246 190 14 246 190 14
57731-246 190 14 246 190 14 246 190 14 246 190 14
57732-246 190 14 246 190 14 246 190 14 246 190 14
57733-246 190 14 246 190 14 241 196 14 226 184 13
57734- 61 42 6 2 2 6 2 2 6 2 2 6
57735- 22 22 22 238 238 238 253 253 253 253 253 253
57736-253 253 253 253 253 253 253 253 253 253 253 253
57737-253 253 253 253 253 253 253 253 253 253 253 253
57738-253 253 253 253 253 253 253 253 253 253 253 253
57739-253 253 253 226 226 226 187 187 187 180 133 36
57740-216 158 10 236 178 12 239 182 13 236 178 12
57741-230 174 11 226 170 11 226 170 11 230 174 11
57742-236 178 12 242 186 14 246 190 14 246 190 14
57743-246 190 14 246 190 14 246 186 14 239 182 13
57744-206 162 42 106 106 106 66 66 66 34 34 34
57745- 14 14 14 6 6 6 0 0 0 0 0 0
57746- 0 0 0 0 0 0 0 0 0 0 0 0
57747- 0 0 0 0 0 0 0 0 0 0 0 0
57748- 0 0 0 0 0 0 0 0 0 6 6 6
57749- 26 26 26 70 70 70 163 133 67 213 154 11
57750-236 178 12 246 190 14 246 190 14 246 190 14
57751-246 190 14 246 190 14 246 190 14 246 190 14
57752-246 190 14 246 190 14 246 190 14 246 190 14
57753-246 190 14 246 190 14 246 190 14 241 196 14
57754-190 146 13 18 14 6 2 2 6 2 2 6
57755- 46 46 46 246 246 246 253 253 253 253 253 253
57756-253 253 253 253 253 253 253 253 253 253 253 253
57757-253 253 253 253 253 253 253 253 253 253 253 253
57758-253 253 253 253 253 253 253 253 253 253 253 253
57759-253 253 253 221 221 221 86 86 86 156 107 11
57760-216 158 10 236 178 12 242 186 14 246 186 14
57761-242 186 14 239 182 13 239 182 13 242 186 14
57762-242 186 14 246 186 14 246 190 14 246 190 14
57763-246 190 14 246 190 14 246 190 14 246 190 14
57764-242 186 14 225 175 15 142 122 72 66 66 66
57765- 30 30 30 10 10 10 0 0 0 0 0 0
57766- 0 0 0 0 0 0 0 0 0 0 0 0
57767- 0 0 0 0 0 0 0 0 0 0 0 0
57768- 0 0 0 0 0 0 0 0 0 6 6 6
57769- 26 26 26 70 70 70 163 133 67 210 150 10
57770-236 178 12 246 190 14 246 190 14 246 190 14
57771-246 190 14 246 190 14 246 190 14 246 190 14
57772-246 190 14 246 190 14 246 190 14 246 190 14
57773-246 190 14 246 190 14 246 190 14 246 190 14
57774-232 195 16 121 92 8 34 34 34 106 106 106
57775-221 221 221 253 253 253 253 253 253 253 253 253
57776-253 253 253 253 253 253 253 253 253 253 253 253
57777-253 253 253 253 253 253 253 253 253 253 253 253
57778-253 253 253 253 253 253 253 253 253 253 253 253
57779-242 242 242 82 82 82 18 14 6 163 110 8
57780-216 158 10 236 178 12 242 186 14 246 190 14
57781-246 190 14 246 190 14 246 190 14 246 190 14
57782-246 190 14 246 190 14 246 190 14 246 190 14
57783-246 190 14 246 190 14 246 190 14 246 190 14
57784-246 190 14 246 190 14 242 186 14 163 133 67
57785- 46 46 46 18 18 18 6 6 6 0 0 0
57786- 0 0 0 0 0 0 0 0 0 0 0 0
57787- 0 0 0 0 0 0 0 0 0 0 0 0
57788- 0 0 0 0 0 0 0 0 0 10 10 10
57789- 30 30 30 78 78 78 163 133 67 210 150 10
57790-236 178 12 246 186 14 246 190 14 246 190 14
57791-246 190 14 246 190 14 246 190 14 246 190 14
57792-246 190 14 246 190 14 246 190 14 246 190 14
57793-246 190 14 246 190 14 246 190 14 246 190 14
57794-241 196 14 215 174 15 190 178 144 253 253 253
57795-253 253 253 253 253 253 253 253 253 253 253 253
57796-253 253 253 253 253 253 253 253 253 253 253 253
57797-253 253 253 253 253 253 253 253 253 253 253 253
57798-253 253 253 253 253 253 253 253 253 218 218 218
57799- 58 58 58 2 2 6 22 18 6 167 114 7
57800-216 158 10 236 178 12 246 186 14 246 190 14
57801-246 190 14 246 190 14 246 190 14 246 190 14
57802-246 190 14 246 190 14 246 190 14 246 190 14
57803-246 190 14 246 190 14 246 190 14 246 190 14
57804-246 190 14 246 186 14 242 186 14 190 150 46
57805- 54 54 54 22 22 22 6 6 6 0 0 0
57806- 0 0 0 0 0 0 0 0 0 0 0 0
57807- 0 0 0 0 0 0 0 0 0 0 0 0
57808- 0 0 0 0 0 0 0 0 0 14 14 14
57809- 38 38 38 86 86 86 180 133 36 213 154 11
57810-236 178 12 246 186 14 246 190 14 246 190 14
57811-246 190 14 246 190 14 246 190 14 246 190 14
57812-246 190 14 246 190 14 246 190 14 246 190 14
57813-246 190 14 246 190 14 246 190 14 246 190 14
57814-246 190 14 232 195 16 190 146 13 214 214 214
57815-253 253 253 253 253 253 253 253 253 253 253 253
57816-253 253 253 253 253 253 253 253 253 253 253 253
57817-253 253 253 253 253 253 253 253 253 253 253 253
57818-253 253 253 250 250 250 170 170 170 26 26 26
57819- 2 2 6 2 2 6 37 26 9 163 110 8
57820-219 162 10 239 182 13 246 186 14 246 190 14
57821-246 190 14 246 190 14 246 190 14 246 190 14
57822-246 190 14 246 190 14 246 190 14 246 190 14
57823-246 190 14 246 190 14 246 190 14 246 190 14
57824-246 186 14 236 178 12 224 166 10 142 122 72
57825- 46 46 46 18 18 18 6 6 6 0 0 0
57826- 0 0 0 0 0 0 0 0 0 0 0 0
57827- 0 0 0 0 0 0 0 0 0 0 0 0
57828- 0 0 0 0 0 0 6 6 6 18 18 18
57829- 50 50 50 109 106 95 192 133 9 224 166 10
57830-242 186 14 246 190 14 246 190 14 246 190 14
57831-246 190 14 246 190 14 246 190 14 246 190 14
57832-246 190 14 246 190 14 246 190 14 246 190 14
57833-246 190 14 246 190 14 246 190 14 246 190 14
57834-242 186 14 226 184 13 210 162 10 142 110 46
57835-226 226 226 253 253 253 253 253 253 253 253 253
57836-253 253 253 253 253 253 253 253 253 253 253 253
57837-253 253 253 253 253 253 253 253 253 253 253 253
57838-198 198 198 66 66 66 2 2 6 2 2 6
57839- 2 2 6 2 2 6 50 34 6 156 107 11
57840-219 162 10 239 182 13 246 186 14 246 190 14
57841-246 190 14 246 190 14 246 190 14 246 190 14
57842-246 190 14 246 190 14 246 190 14 246 190 14
57843-246 190 14 246 190 14 246 190 14 242 186 14
57844-234 174 13 213 154 11 154 122 46 66 66 66
57845- 30 30 30 10 10 10 0 0 0 0 0 0
57846- 0 0 0 0 0 0 0 0 0 0 0 0
57847- 0 0 0 0 0 0 0 0 0 0 0 0
57848- 0 0 0 0 0 0 6 6 6 22 22 22
57849- 58 58 58 154 121 60 206 145 10 234 174 13
57850-242 186 14 246 186 14 246 190 14 246 190 14
57851-246 190 14 246 190 14 246 190 14 246 190 14
57852-246 190 14 246 190 14 246 190 14 246 190 14
57853-246 190 14 246 190 14 246 190 14 246 190 14
57854-246 186 14 236 178 12 210 162 10 163 110 8
57855- 61 42 6 138 138 138 218 218 218 250 250 250
57856-253 253 253 253 253 253 253 253 253 250 250 250
57857-242 242 242 210 210 210 144 144 144 66 66 66
57858- 6 6 6 2 2 6 2 2 6 2 2 6
57859- 2 2 6 2 2 6 61 42 6 163 110 8
57860-216 158 10 236 178 12 246 190 14 246 190 14
57861-246 190 14 246 190 14 246 190 14 246 190 14
57862-246 190 14 246 190 14 246 190 14 246 190 14
57863-246 190 14 239 182 13 230 174 11 216 158 10
57864-190 142 34 124 112 88 70 70 70 38 38 38
57865- 18 18 18 6 6 6 0 0 0 0 0 0
57866- 0 0 0 0 0 0 0 0 0 0 0 0
57867- 0 0 0 0 0 0 0 0 0 0 0 0
57868- 0 0 0 0 0 0 6 6 6 22 22 22
57869- 62 62 62 168 124 44 206 145 10 224 166 10
57870-236 178 12 239 182 13 242 186 14 242 186 14
57871-246 186 14 246 190 14 246 190 14 246 190 14
57872-246 190 14 246 190 14 246 190 14 246 190 14
57873-246 190 14 246 190 14 246 190 14 246 190 14
57874-246 190 14 236 178 12 216 158 10 175 118 6
57875- 80 54 7 2 2 6 6 6 6 30 30 30
57876- 54 54 54 62 62 62 50 50 50 38 38 38
57877- 14 14 14 2 2 6 2 2 6 2 2 6
57878- 2 2 6 2 2 6 2 2 6 2 2 6
57879- 2 2 6 6 6 6 80 54 7 167 114 7
57880-213 154 11 236 178 12 246 190 14 246 190 14
57881-246 190 14 246 190 14 246 190 14 246 190 14
57882-246 190 14 242 186 14 239 182 13 239 182 13
57883-230 174 11 210 150 10 174 135 50 124 112 88
57884- 82 82 82 54 54 54 34 34 34 18 18 18
57885- 6 6 6 0 0 0 0 0 0 0 0 0
57886- 0 0 0 0 0 0 0 0 0 0 0 0
57887- 0 0 0 0 0 0 0 0 0 0 0 0
57888- 0 0 0 0 0 0 6 6 6 18 18 18
57889- 50 50 50 158 118 36 192 133 9 200 144 11
57890-216 158 10 219 162 10 224 166 10 226 170 11
57891-230 174 11 236 178 12 239 182 13 239 182 13
57892-242 186 14 246 186 14 246 190 14 246 190 14
57893-246 190 14 246 190 14 246 190 14 246 190 14
57894-246 186 14 230 174 11 210 150 10 163 110 8
57895-104 69 6 10 10 10 2 2 6 2 2 6
57896- 2 2 6 2 2 6 2 2 6 2 2 6
57897- 2 2 6 2 2 6 2 2 6 2 2 6
57898- 2 2 6 2 2 6 2 2 6 2 2 6
57899- 2 2 6 6 6 6 91 60 6 167 114 7
57900-206 145 10 230 174 11 242 186 14 246 190 14
57901-246 190 14 246 190 14 246 186 14 242 186 14
57902-239 182 13 230 174 11 224 166 10 213 154 11
57903-180 133 36 124 112 88 86 86 86 58 58 58
57904- 38 38 38 22 22 22 10 10 10 6 6 6
57905- 0 0 0 0 0 0 0 0 0 0 0 0
57906- 0 0 0 0 0 0 0 0 0 0 0 0
57907- 0 0 0 0 0 0 0 0 0 0 0 0
57908- 0 0 0 0 0 0 0 0 0 14 14 14
57909- 34 34 34 70 70 70 138 110 50 158 118 36
57910-167 114 7 180 123 7 192 133 9 197 138 11
57911-200 144 11 206 145 10 213 154 11 219 162 10
57912-224 166 10 230 174 11 239 182 13 242 186 14
57913-246 186 14 246 186 14 246 186 14 246 186 14
57914-239 182 13 216 158 10 185 133 11 152 99 6
57915-104 69 6 18 14 6 2 2 6 2 2 6
57916- 2 2 6 2 2 6 2 2 6 2 2 6
57917- 2 2 6 2 2 6 2 2 6 2 2 6
57918- 2 2 6 2 2 6 2 2 6 2 2 6
57919- 2 2 6 6 6 6 80 54 7 152 99 6
57920-192 133 9 219 162 10 236 178 12 239 182 13
57921-246 186 14 242 186 14 239 182 13 236 178 12
57922-224 166 10 206 145 10 192 133 9 154 121 60
57923- 94 94 94 62 62 62 42 42 42 22 22 22
57924- 14 14 14 6 6 6 0 0 0 0 0 0
57925- 0 0 0 0 0 0 0 0 0 0 0 0
57926- 0 0 0 0 0 0 0 0 0 0 0 0
57927- 0 0 0 0 0 0 0 0 0 0 0 0
57928- 0 0 0 0 0 0 0 0 0 6 6 6
57929- 18 18 18 34 34 34 58 58 58 78 78 78
57930-101 98 89 124 112 88 142 110 46 156 107 11
57931-163 110 8 167 114 7 175 118 6 180 123 7
57932-185 133 11 197 138 11 210 150 10 219 162 10
57933-226 170 11 236 178 12 236 178 12 234 174 13
57934-219 162 10 197 138 11 163 110 8 130 83 6
57935- 91 60 6 10 10 10 2 2 6 2 2 6
57936- 18 18 18 38 38 38 38 38 38 38 38 38
57937- 38 38 38 38 38 38 38 38 38 38 38 38
57938- 38 38 38 38 38 38 26 26 26 2 2 6
57939- 2 2 6 6 6 6 70 47 6 137 92 6
57940-175 118 6 200 144 11 219 162 10 230 174 11
57941-234 174 13 230 174 11 219 162 10 210 150 10
57942-192 133 9 163 110 8 124 112 88 82 82 82
57943- 50 50 50 30 30 30 14 14 14 6 6 6
57944- 0 0 0 0 0 0 0 0 0 0 0 0
57945- 0 0 0 0 0 0 0 0 0 0 0 0
57946- 0 0 0 0 0 0 0 0 0 0 0 0
57947- 0 0 0 0 0 0 0 0 0 0 0 0
57948- 0 0 0 0 0 0 0 0 0 0 0 0
57949- 6 6 6 14 14 14 22 22 22 34 34 34
57950- 42 42 42 58 58 58 74 74 74 86 86 86
57951-101 98 89 122 102 70 130 98 46 121 87 25
57952-137 92 6 152 99 6 163 110 8 180 123 7
57953-185 133 11 197 138 11 206 145 10 200 144 11
57954-180 123 7 156 107 11 130 83 6 104 69 6
57955- 50 34 6 54 54 54 110 110 110 101 98 89
57956- 86 86 86 82 82 82 78 78 78 78 78 78
57957- 78 78 78 78 78 78 78 78 78 78 78 78
57958- 78 78 78 82 82 82 86 86 86 94 94 94
57959-106 106 106 101 101 101 86 66 34 124 80 6
57960-156 107 11 180 123 7 192 133 9 200 144 11
57961-206 145 10 200 144 11 192 133 9 175 118 6
57962-139 102 15 109 106 95 70 70 70 42 42 42
57963- 22 22 22 10 10 10 0 0 0 0 0 0
57964- 0 0 0 0 0 0 0 0 0 0 0 0
57965- 0 0 0 0 0 0 0 0 0 0 0 0
57966- 0 0 0 0 0 0 0 0 0 0 0 0
57967- 0 0 0 0 0 0 0 0 0 0 0 0
57968- 0 0 0 0 0 0 0 0 0 0 0 0
57969- 0 0 0 0 0 0 6 6 6 10 10 10
57970- 14 14 14 22 22 22 30 30 30 38 38 38
57971- 50 50 50 62 62 62 74 74 74 90 90 90
57972-101 98 89 112 100 78 121 87 25 124 80 6
57973-137 92 6 152 99 6 152 99 6 152 99 6
57974-138 86 6 124 80 6 98 70 6 86 66 30
57975-101 98 89 82 82 82 58 58 58 46 46 46
57976- 38 38 38 34 34 34 34 34 34 34 34 34
57977- 34 34 34 34 34 34 34 34 34 34 34 34
57978- 34 34 34 34 34 34 38 38 38 42 42 42
57979- 54 54 54 82 82 82 94 86 76 91 60 6
57980-134 86 6 156 107 11 167 114 7 175 118 6
57981-175 118 6 167 114 7 152 99 6 121 87 25
57982-101 98 89 62 62 62 34 34 34 18 18 18
57983- 6 6 6 0 0 0 0 0 0 0 0 0
57984- 0 0 0 0 0 0 0 0 0 0 0 0
57985- 0 0 0 0 0 0 0 0 0 0 0 0
57986- 0 0 0 0 0 0 0 0 0 0 0 0
57987- 0 0 0 0 0 0 0 0 0 0 0 0
57988- 0 0 0 0 0 0 0 0 0 0 0 0
57989- 0 0 0 0 0 0 0 0 0 0 0 0
57990- 0 0 0 6 6 6 6 6 6 10 10 10
57991- 18 18 18 22 22 22 30 30 30 42 42 42
57992- 50 50 50 66 66 66 86 86 86 101 98 89
57993-106 86 58 98 70 6 104 69 6 104 69 6
57994-104 69 6 91 60 6 82 62 34 90 90 90
57995- 62 62 62 38 38 38 22 22 22 14 14 14
57996- 10 10 10 10 10 10 10 10 10 10 10 10
57997- 10 10 10 10 10 10 6 6 6 10 10 10
57998- 10 10 10 10 10 10 10 10 10 14 14 14
57999- 22 22 22 42 42 42 70 70 70 89 81 66
58000- 80 54 7 104 69 6 124 80 6 137 92 6
58001-134 86 6 116 81 8 100 82 52 86 86 86
58002- 58 58 58 30 30 30 14 14 14 6 6 6
58003- 0 0 0 0 0 0 0 0 0 0 0 0
58004- 0 0 0 0 0 0 0 0 0 0 0 0
58005- 0 0 0 0 0 0 0 0 0 0 0 0
58006- 0 0 0 0 0 0 0 0 0 0 0 0
58007- 0 0 0 0 0 0 0 0 0 0 0 0
58008- 0 0 0 0 0 0 0 0 0 0 0 0
58009- 0 0 0 0 0 0 0 0 0 0 0 0
58010- 0 0 0 0 0 0 0 0 0 0 0 0
58011- 0 0 0 6 6 6 10 10 10 14 14 14
58012- 18 18 18 26 26 26 38 38 38 54 54 54
58013- 70 70 70 86 86 86 94 86 76 89 81 66
58014- 89 81 66 86 86 86 74 74 74 50 50 50
58015- 30 30 30 14 14 14 6 6 6 0 0 0
58016- 0 0 0 0 0 0 0 0 0 0 0 0
58017- 0 0 0 0 0 0 0 0 0 0 0 0
58018- 0 0 0 0 0 0 0 0 0 0 0 0
58019- 6 6 6 18 18 18 34 34 34 58 58 58
58020- 82 82 82 89 81 66 89 81 66 89 81 66
58021- 94 86 66 94 86 76 74 74 74 50 50 50
58022- 26 26 26 14 14 14 6 6 6 0 0 0
58023- 0 0 0 0 0 0 0 0 0 0 0 0
58024- 0 0 0 0 0 0 0 0 0 0 0 0
58025- 0 0 0 0 0 0 0 0 0 0 0 0
58026- 0 0 0 0 0 0 0 0 0 0 0 0
58027- 0 0 0 0 0 0 0 0 0 0 0 0
58028- 0 0 0 0 0 0 0 0 0 0 0 0
58029- 0 0 0 0 0 0 0 0 0 0 0 0
58030- 0 0 0 0 0 0 0 0 0 0 0 0
58031- 0 0 0 0 0 0 0 0 0 0 0 0
58032- 6 6 6 6 6 6 14 14 14 18 18 18
58033- 30 30 30 38 38 38 46 46 46 54 54 54
58034- 50 50 50 42 42 42 30 30 30 18 18 18
58035- 10 10 10 0 0 0 0 0 0 0 0 0
58036- 0 0 0 0 0 0 0 0 0 0 0 0
58037- 0 0 0 0 0 0 0 0 0 0 0 0
58038- 0 0 0 0 0 0 0 0 0 0 0 0
58039- 0 0 0 6 6 6 14 14 14 26 26 26
58040- 38 38 38 50 50 50 58 58 58 58 58 58
58041- 54 54 54 42 42 42 30 30 30 18 18 18
58042- 10 10 10 0 0 0 0 0 0 0 0 0
58043- 0 0 0 0 0 0 0 0 0 0 0 0
58044- 0 0 0 0 0 0 0 0 0 0 0 0
58045- 0 0 0 0 0 0 0 0 0 0 0 0
58046- 0 0 0 0 0 0 0 0 0 0 0 0
58047- 0 0 0 0 0 0 0 0 0 0 0 0
58048- 0 0 0 0 0 0 0 0 0 0 0 0
58049- 0 0 0 0 0 0 0 0 0 0 0 0
58050- 0 0 0 0 0 0 0 0 0 0 0 0
58051- 0 0 0 0 0 0 0 0 0 0 0 0
58052- 0 0 0 0 0 0 0 0 0 6 6 6
58053- 6 6 6 10 10 10 14 14 14 18 18 18
58054- 18 18 18 14 14 14 10 10 10 6 6 6
58055- 0 0 0 0 0 0 0 0 0 0 0 0
58056- 0 0 0 0 0 0 0 0 0 0 0 0
58057- 0 0 0 0 0 0 0 0 0 0 0 0
58058- 0 0 0 0 0 0 0 0 0 0 0 0
58059- 0 0 0 0 0 0 0 0 0 6 6 6
58060- 14 14 14 18 18 18 22 22 22 22 22 22
58061- 18 18 18 14 14 14 10 10 10 6 6 6
58062- 0 0 0 0 0 0 0 0 0 0 0 0
58063- 0 0 0 0 0 0 0 0 0 0 0 0
58064- 0 0 0 0 0 0 0 0 0 0 0 0
58065- 0 0 0 0 0 0 0 0 0 0 0 0
58066- 0 0 0 0 0 0 0 0 0 0 0 0
58067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58080+4 4 4 4 4 4
58081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58094+4 4 4 4 4 4
58095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58106+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58108+4 4 4 4 4 4
58109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58122+4 4 4 4 4 4
58123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58136+4 4 4 4 4 4
58137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58150+4 4 4 4 4 4
58151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58155+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
58156+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
58157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58160+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
58161+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
58162+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
58163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58164+4 4 4 4 4 4
58165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58169+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
58170+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
58171+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58174+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
58175+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
58176+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
58177+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58178+4 4 4 4 4 4
58179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58183+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
58184+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
58185+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
58186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58188+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
58189+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
58190+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
58191+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
58192+4 4 4 4 4 4
58193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58196+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
58197+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
58198+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
58199+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
58200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58201+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
58202+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
58203+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
58204+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
58205+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
58206+4 4 4 4 4 4
58207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58210+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
58211+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
58212+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
58213+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
58214+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58215+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
58216+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
58217+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
58218+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
58219+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
58220+4 4 4 4 4 4
58221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58224+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
58225+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
58226+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
58227+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
58228+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58229+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
58230+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
58231+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
58232+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
58233+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
58234+4 4 4 4 4 4
58235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58237+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
58238+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
58239+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
58240+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
58241+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
58242+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
58243+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
58244+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
58245+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
58246+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
58247+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
58248+4 4 4 4 4 4
58249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58251+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
58252+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
58253+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
58254+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
58255+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
58256+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
58257+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
58258+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
58259+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
58260+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
58261+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
58262+4 4 4 4 4 4
58263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58265+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
58266+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
58267+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
58268+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
58269+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
58270+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
58271+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
58272+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
58273+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
58274+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
58275+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
58276+4 4 4 4 4 4
58277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58279+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
58280+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
58281+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
58282+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
58283+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
58284+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
58285+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
58286+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
58287+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
58288+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
58289+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
58290+4 4 4 4 4 4
58291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58292+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
58293+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
58294+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
58295+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
58296+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
58297+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
58298+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
58299+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
58300+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
58301+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
58302+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
58303+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
58304+4 4 4 4 4 4
58305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58306+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
58307+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
58308+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
58309+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58310+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
58311+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
58312+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
58313+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
58314+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
58315+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
58316+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
58317+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
58318+0 0 0 4 4 4
58319+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
58320+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
58321+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
58322+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
58323+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
58324+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
58325+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
58326+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
58327+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
58328+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
58329+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
58330+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
58331+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
58332+2 0 0 0 0 0
58333+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
58334+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
58335+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
58336+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
58337+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
58338+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
58339+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
58340+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
58341+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
58342+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
58343+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
58344+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
58345+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
58346+37 38 37 0 0 0
58347+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
58348+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
58349+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
58350+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
58351+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
58352+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
58353+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
58354+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
58355+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
58356+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
58357+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
58358+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
58359+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
58360+85 115 134 4 0 0
58361+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
58362+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
58363+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
58364+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
58365+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
58366+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
58367+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
58368+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
58369+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
58370+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
58371+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
58372+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
58373+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
58374+60 73 81 4 0 0
58375+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
58376+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
58377+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
58378+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
58379+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
58380+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
58381+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
58382+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
58383+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
58384+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
58385+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
58386+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
58387+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
58388+16 19 21 4 0 0
58389+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
58390+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
58391+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
58392+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
58393+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
58394+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
58395+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
58396+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
58397+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
58398+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
58399+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
58400+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
58401+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
58402+4 0 0 4 3 3
58403+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
58404+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
58405+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
58406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
58407+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
58408+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
58409+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
58410+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
58411+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
58412+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
58413+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
58414+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
58415+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
58416+3 2 2 4 4 4
58417+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
58418+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
58419+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
58420+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
58421+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
58422+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
58423+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
58424+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
58425+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
58426+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
58427+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
58428+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
58429+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
58430+4 4 4 4 4 4
58431+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
58432+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
58433+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
58434+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
58435+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
58436+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
58437+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
58438+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
58439+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
58440+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
58441+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
58442+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
58443+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
58444+4 4 4 4 4 4
58445+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
58446+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
58447+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
58448+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
58449+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
58450+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
58451+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
58452+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
58453+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
58454+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
58455+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
58456+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
58457+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
58458+5 5 5 5 5 5
58459+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
58460+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
58461+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
58462+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
58463+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
58464+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58465+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
58466+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
58467+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
58468+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
58469+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
58470+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
58471+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58472+5 5 5 4 4 4
58473+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
58474+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
58475+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
58476+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
58477+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58478+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
58479+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
58480+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
58481+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
58482+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
58483+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
58484+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58486+4 4 4 4 4 4
58487+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
58488+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
58489+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
58490+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
58491+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
58492+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58493+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58494+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
58495+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
58496+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
58497+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
58498+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
58499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58500+4 4 4 4 4 4
58501+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
58502+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
58503+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
58504+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
58505+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58506+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
58507+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
58508+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
58509+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
58510+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
58511+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
58512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58514+4 4 4 4 4 4
58515+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
58516+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
58517+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
58518+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
58519+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58520+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58521+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58522+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
58523+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
58524+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
58525+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
58526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58528+4 4 4 4 4 4
58529+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
58530+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
58531+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
58532+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
58533+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58534+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
58535+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
58536+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
58537+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
58538+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
58539+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58542+4 4 4 4 4 4
58543+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
58544+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
58545+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
58546+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
58547+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58548+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
58549+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
58550+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
58551+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
58552+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
58553+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
58554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58556+4 4 4 4 4 4
58557+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
58558+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
58559+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
58560+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
58561+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58562+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
58563+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
58564+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
58565+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
58566+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
58567+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
58568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58570+4 4 4 4 4 4
58571+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
58572+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
58573+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
58574+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58575+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
58576+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
58577+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
58578+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
58579+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
58580+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
58581+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58584+4 4 4 4 4 4
58585+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
58586+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
58587+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
58588+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58589+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58590+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
58591+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
58592+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
58593+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
58594+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
58595+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58598+4 4 4 4 4 4
58599+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
58600+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
58601+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58602+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58603+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58604+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
58605+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
58606+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
58607+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
58608+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
58609+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58612+4 4 4 4 4 4
58613+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
58614+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
58615+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58616+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58617+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58618+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
58619+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
58620+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
58621+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58622+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58623+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58626+4 4 4 4 4 4
58627+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58628+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
58629+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58630+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
58631+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
58632+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
58633+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
58634+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
58635+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58636+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58637+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58640+4 4 4 4 4 4
58641+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58642+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
58643+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58644+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
58645+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58646+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
58647+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
58648+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
58649+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58650+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58651+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58654+4 4 4 4 4 4
58655+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
58656+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
58657+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58658+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
58659+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
58660+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
58661+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
58662+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
58663+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58664+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58665+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58668+4 4 4 4 4 4
58669+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
58670+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
58671+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58672+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
58673+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
58674+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
58675+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
58676+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
58677+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58678+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58679+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58682+4 4 4 4 4 4
58683+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58684+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
58685+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58686+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
58687+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
58688+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
58689+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
58690+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
58691+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58692+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58693+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58696+4 4 4 4 4 4
58697+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
58698+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
58699+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58700+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
58701+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
58702+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
58703+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
58704+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
58705+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
58706+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58707+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58710+4 4 4 4 4 4
58711+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58712+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
58713+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
58714+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
58715+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
58716+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
58717+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
58718+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
58719+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58720+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58721+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58724+4 4 4 4 4 4
58725+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58726+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
58727+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58728+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
58729+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
58730+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
58731+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
58732+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
58733+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58734+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58735+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58738+4 4 4 4 4 4
58739+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58740+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
58741+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
58742+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
58743+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
58744+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
58745+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58746+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
58747+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58748+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58749+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58752+4 4 4 4 4 4
58753+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58754+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
58755+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
58756+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58757+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
58758+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
58759+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58760+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
58761+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58762+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58763+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58766+4 4 4 4 4 4
58767+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58768+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
58769+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
58770+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
58771+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
58772+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
58773+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
58774+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
58775+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
58776+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58777+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58780+4 4 4 4 4 4
58781+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58782+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
58783+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
58784+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
58785+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
58786+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
58787+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
58788+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
58789+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
58790+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58791+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58794+4 4 4 4 4 4
58795+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
58796+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
58797+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
58798+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
58799+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58800+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
58801+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
58802+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
58803+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
58804+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58805+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58808+4 4 4 4 4 4
58809+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58810+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
58811+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
58812+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
58813+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
58814+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
58815+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
58816+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
58817+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
58818+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58819+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58822+4 4 4 4 4 4
58823+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
58824+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
58825+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
58826+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
58827+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
58828+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
58829+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
58830+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
58831+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
58832+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
58833+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58836+4 4 4 4 4 4
58837+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
58838+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58839+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
58840+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
58841+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
58842+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
58843+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
58844+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
58845+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
58846+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
58847+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58850+4 4 4 4 4 4
58851+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
58852+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58853+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
58854+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
58855+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
58856+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
58857+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58858+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
58859+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
58860+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
58861+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58864+4 4 4 4 4 4
58865+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
58866+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
58867+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
58868+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
58869+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
58870+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
58871+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
58872+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
58873+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
58874+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
58875+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58878+4 4 4 4 4 4
58879+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
58880+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
58881+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58882+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
58883+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
58884+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
58885+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
58886+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
58887+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
58888+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
58889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58892+4 4 4 4 4 4
58893+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58894+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
58895+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
58896+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
58897+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
58898+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
58899+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
58900+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
58901+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
58902+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58906+4 4 4 4 4 4
58907+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
58908+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
58909+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
58910+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
58911+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58912+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58913+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58914+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58915+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58916+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58920+4 4 4 4 4 4
58921+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58922+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58923+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58924+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58925+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58926+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58927+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58928+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58929+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58930+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58934+4 4 4 4 4 4
58935+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58936+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58937+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58938+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58939+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58940+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58941+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58942+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58943+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58948+4 4 4 4 4 4
58949+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58950+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58951+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58952+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58953+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58954+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58955+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58956+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58957+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58962+4 4 4 4 4 4
58963+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58964+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58965+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58966+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58967+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58968+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58969+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58970+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58971+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58976+4 4 4 4 4 4
58977+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58978+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58979+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58980+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58981+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58982+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58983+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58984+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58990+4 4 4 4 4 4
58991+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58992+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58993+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58994+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58995+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58996+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58997+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58998+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59004+4 4 4 4 4 4
59005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
59006+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
59007+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
59008+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
59009+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
59010+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
59011+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
59012+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
59013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59018+4 4 4 4 4 4
59019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59020+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
59021+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
59022+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
59023+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
59024+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
59025+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
59026+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
59027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59032+4 4 4 4 4 4
59033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59034+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
59035+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
59036+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
59037+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
59038+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
59039+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
59040+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
59041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59046+4 4 4 4 4 4
59047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59049+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
59050+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
59051+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
59052+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
59053+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
59054+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
59055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59060+4 4 4 4 4 4
59061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
59064+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
59065+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
59066+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
59067+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
59068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59074+4 4 4 4 4 4
59075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59078+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
59079+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
59080+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
59081+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
59082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59088+4 4 4 4 4 4
59089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59092+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
59093+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
59094+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
59095+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
59096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59102+4 4 4 4 4 4
59103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59106+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
59107+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
59108+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
59109+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
59110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59116+4 4 4 4 4 4
59117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
59121+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
59122+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
59123+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
59124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59130+4 4 4 4 4 4
59131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59135+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
59136+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
59137+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
59138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59144+4 4 4 4 4 4
59145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59149+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
59150+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
59151+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59158+4 4 4 4 4 4
59159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59163+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
59164+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
59165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59172+4 4 4 4 4 4
59173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59177+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
59178+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
59179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59186+4 4 4 4 4 4
59187diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
59188index fef20db..d28b1ab 100644
59189--- a/drivers/xen/xenfs/xenstored.c
59190+++ b/drivers/xen/xenfs/xenstored.c
59191@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
59192 static int xsd_kva_open(struct inode *inode, struct file *file)
59193 {
59194 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
59195+#ifdef CONFIG_GRKERNSEC_HIDESYM
59196+ NULL);
59197+#else
59198 xen_store_interface);
59199+#endif
59200+
59201 if (!file->private_data)
59202 return -ENOMEM;
59203 return 0;
59204diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
59205index cc1cfae..41158ad 100644
59206--- a/fs/9p/vfs_addr.c
59207+++ b/fs/9p/vfs_addr.c
59208@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
59209
59210 retval = v9fs_file_write_internal(inode,
59211 v9inode->writeback_fid,
59212- (__force const char __user *)buffer,
59213+ (const char __force_user *)buffer,
59214 len, &offset, 0);
59215 if (retval > 0)
59216 retval = 0;
59217diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
59218index 7fa4f7a..a7ebf8c 100644
59219--- a/fs/9p/vfs_inode.c
59220+++ b/fs/9p/vfs_inode.c
59221@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
59222 void
59223 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
59224 {
59225- char *s = nd_get_link(nd);
59226+ const char *s = nd_get_link(nd);
59227
59228 p9_debug(P9_DEBUG_VFS, " %s %s\n",
59229 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
59230diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
59231index 370b24c..ff0be7b 100644
59232--- a/fs/Kconfig.binfmt
59233+++ b/fs/Kconfig.binfmt
59234@@ -103,7 +103,7 @@ config HAVE_AOUT
59235
59236 config BINFMT_AOUT
59237 tristate "Kernel support for a.out and ECOFF binaries"
59238- depends on HAVE_AOUT
59239+ depends on HAVE_AOUT && BROKEN
59240 ---help---
59241 A.out (Assembler.OUTput) is a set of formats for libraries and
59242 executables used in the earliest versions of UNIX. Linux used
59243diff --git a/fs/afs/inode.c b/fs/afs/inode.c
59244index 2946712..f737435 100644
59245--- a/fs/afs/inode.c
59246+++ b/fs/afs/inode.c
59247@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
59248 struct afs_vnode *vnode;
59249 struct super_block *sb;
59250 struct inode *inode;
59251- static atomic_t afs_autocell_ino;
59252+ static atomic_unchecked_t afs_autocell_ino;
59253
59254 _enter("{%x:%u},%*.*s,",
59255 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
59256@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
59257 data.fid.unique = 0;
59258 data.fid.vnode = 0;
59259
59260- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
59261+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
59262 afs_iget5_autocell_test, afs_iget5_set,
59263 &data);
59264 if (!inode) {
59265diff --git a/fs/aio.c b/fs/aio.c
59266index 1c9c5f0..94455bc 100644
59267--- a/fs/aio.c
59268+++ b/fs/aio.c
59269@@ -141,6 +141,7 @@ struct kioctx {
59270
59271 struct {
59272 unsigned tail;
59273+ unsigned completed_events;
59274 spinlock_t completion_lock;
59275 } ____cacheline_aligned_in_smp;
59276
59277@@ -380,7 +381,7 @@ static int aio_setup_ring(struct kioctx *ctx)
59278 size += sizeof(struct io_event) * nr_events;
59279
59280 nr_pages = PFN_UP(size);
59281- if (nr_pages < 0)
59282+ if (nr_pages <= 0)
59283 return -EINVAL;
59284
59285 file = aio_private_file(ctx, nr_pages);
59286@@ -880,6 +881,68 @@ out:
59287 return ret;
59288 }
59289
59290+/* refill_reqs_available
59291+ * Updates the reqs_available reference counts used for tracking the
59292+ * number of free slots in the completion ring. This can be called
59293+ * from aio_complete() (to optimistically update reqs_available) or
59294+ * from aio_get_req() (the we're out of events case). It must be
59295+ * called holding ctx->completion_lock.
59296+ */
59297+static void refill_reqs_available(struct kioctx *ctx, unsigned head,
59298+ unsigned tail)
59299+{
59300+ unsigned events_in_ring, completed;
59301+
59302+ /* Clamp head since userland can write to it. */
59303+ head %= ctx->nr_events;
59304+ if (head <= tail)
59305+ events_in_ring = tail - head;
59306+ else
59307+ events_in_ring = ctx->nr_events - (head - tail);
59308+
59309+ completed = ctx->completed_events;
59310+ if (events_in_ring < completed)
59311+ completed -= events_in_ring;
59312+ else
59313+ completed = 0;
59314+
59315+ if (!completed)
59316+ return;
59317+
59318+ ctx->completed_events -= completed;
59319+ put_reqs_available(ctx, completed);
59320+}
59321+
59322+/* user_refill_reqs_available
59323+ * Called to refill reqs_available when aio_get_req() encounters an
59324+ * out of space in the completion ring.
59325+ */
59326+static void user_refill_reqs_available(struct kioctx *ctx)
59327+{
59328+ spin_lock_irq(&ctx->completion_lock);
59329+ if (ctx->completed_events) {
59330+ struct aio_ring *ring;
59331+ unsigned head;
59332+
59333+ /* Access of ring->head may race with aio_read_events_ring()
59334+ * here, but that's okay since whether we read the old version
59335+ * or the new version, and either will be valid. The important
59336+ * part is that head cannot pass tail since we prevent
59337+ * aio_complete() from updating tail by holding
59338+ * ctx->completion_lock. Even if head is invalid, the check
59339+ * against ctx->completed_events below will make sure we do the
59340+ * safe/right thing.
59341+ */
59342+ ring = kmap_atomic(ctx->ring_pages[0]);
59343+ head = ring->head;
59344+ kunmap_atomic(ring);
59345+
59346+ refill_reqs_available(ctx, head, ctx->tail);
59347+ }
59348+
59349+ spin_unlock_irq(&ctx->completion_lock);
59350+}
59351+
59352 /* aio_get_req
59353 * Allocate a slot for an aio request.
59354 * Returns NULL if no requests are free.
59355@@ -888,8 +951,11 @@ static inline struct kiocb *aio_get_req(struct kioctx *ctx)
59356 {
59357 struct kiocb *req;
59358
59359- if (!get_reqs_available(ctx))
59360- return NULL;
59361+ if (!get_reqs_available(ctx)) {
59362+ user_refill_reqs_available(ctx);
59363+ if (!get_reqs_available(ctx))
59364+ return NULL;
59365+ }
59366
59367 req = kmem_cache_alloc(kiocb_cachep, GFP_KERNEL|__GFP_ZERO);
59368 if (unlikely(!req))
59369@@ -948,8 +1014,8 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
59370 struct kioctx *ctx = iocb->ki_ctx;
59371 struct aio_ring *ring;
59372 struct io_event *ev_page, *event;
59373+ unsigned tail, pos, head;
59374 unsigned long flags;
59375- unsigned tail, pos;
59376
59377 /*
59378 * Special case handling for sync iocbs:
59379@@ -1010,10 +1076,14 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
59380 ctx->tail = tail;
59381
59382 ring = kmap_atomic(ctx->ring_pages[0]);
59383+ head = ring->head;
59384 ring->tail = tail;
59385 kunmap_atomic(ring);
59386 flush_dcache_page(ctx->ring_pages[0]);
59387
59388+ ctx->completed_events++;
59389+ if (ctx->completed_events > 1)
59390+ refill_reqs_available(ctx, head, tail);
59391 spin_unlock_irqrestore(&ctx->completion_lock, flags);
59392
59393 pr_debug("added to ring %p at [%u]\n", iocb, tail);
59394@@ -1028,7 +1098,6 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
59395
59396 /* everything turned out well, dispose of the aiocb. */
59397 kiocb_free(iocb);
59398- put_reqs_available(ctx, 1);
59399
59400 /*
59401 * We have to order our ring_info tail store above and test
59402diff --git a/fs/attr.c b/fs/attr.c
59403index 6530ced..4a827e2 100644
59404--- a/fs/attr.c
59405+++ b/fs/attr.c
59406@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
59407 unsigned long limit;
59408
59409 limit = rlimit(RLIMIT_FSIZE);
59410+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
59411 if (limit != RLIM_INFINITY && offset > limit)
59412 goto out_sig;
59413 if (offset > inode->i_sb->s_maxbytes)
59414diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
59415index 116fd38..c04182da 100644
59416--- a/fs/autofs4/waitq.c
59417+++ b/fs/autofs4/waitq.c
59418@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
59419 {
59420 unsigned long sigpipe, flags;
59421 mm_segment_t fs;
59422- const char *data = (const char *)addr;
59423+ const char __user *data = (const char __force_user *)addr;
59424 ssize_t wr = 0;
59425
59426 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
59427@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
59428 return 1;
59429 }
59430
59431+#ifdef CONFIG_GRKERNSEC_HIDESYM
59432+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
59433+#endif
59434+
59435 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
59436 enum autofs_notify notify)
59437 {
59438@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
59439
59440 /* If this is a direct mount request create a dummy name */
59441 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
59442+#ifdef CONFIG_GRKERNSEC_HIDESYM
59443+ /* this name does get written to userland via autofs4_write() */
59444+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
59445+#else
59446 qstr.len = sprintf(name, "%p", dentry);
59447+#endif
59448 else {
59449 qstr.len = autofs4_getpath(sbi, dentry, &name);
59450 if (!qstr.len) {
59451diff --git a/fs/befs/endian.h b/fs/befs/endian.h
59452index 2722387..56059b5 100644
59453--- a/fs/befs/endian.h
59454+++ b/fs/befs/endian.h
59455@@ -11,7 +11,7 @@
59456
59457 #include <asm/byteorder.h>
59458
59459-static inline u64
59460+static inline u64 __intentional_overflow(-1)
59461 fs64_to_cpu(const struct super_block *sb, fs64 n)
59462 {
59463 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59464@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
59465 return (__force fs64)cpu_to_be64(n);
59466 }
59467
59468-static inline u32
59469+static inline u32 __intentional_overflow(-1)
59470 fs32_to_cpu(const struct super_block *sb, fs32 n)
59471 {
59472 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59473@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
59474 return (__force fs32)cpu_to_be32(n);
59475 }
59476
59477-static inline u16
59478+static inline u16 __intentional_overflow(-1)
59479 fs16_to_cpu(const struct super_block *sb, fs16 n)
59480 {
59481 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59482diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
59483index ca0ba15..0fa3257 100644
59484--- a/fs/binfmt_aout.c
59485+++ b/fs/binfmt_aout.c
59486@@ -16,6 +16,7 @@
59487 #include <linux/string.h>
59488 #include <linux/fs.h>
59489 #include <linux/file.h>
59490+#include <linux/security.h>
59491 #include <linux/stat.h>
59492 #include <linux/fcntl.h>
59493 #include <linux/ptrace.h>
59494@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
59495 #endif
59496 # define START_STACK(u) ((void __user *)u.start_stack)
59497
59498+ memset(&dump, 0, sizeof(dump));
59499+
59500 fs = get_fs();
59501 set_fs(KERNEL_DS);
59502 has_dumped = 1;
59503@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
59504
59505 /* If the size of the dump file exceeds the rlimit, then see what would happen
59506 if we wrote the stack, but not the data area. */
59507+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
59508 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
59509 dump.u_dsize = 0;
59510
59511 /* Make sure we have enough room to write the stack and data areas. */
59512+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
59513 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
59514 dump.u_ssize = 0;
59515
59516@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
59517 rlim = rlimit(RLIMIT_DATA);
59518 if (rlim >= RLIM_INFINITY)
59519 rlim = ~0;
59520+
59521+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
59522 if (ex.a_data + ex.a_bss > rlim)
59523 return -ENOMEM;
59524
59525@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
59526
59527 install_exec_creds(bprm);
59528
59529+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59530+ current->mm->pax_flags = 0UL;
59531+#endif
59532+
59533+#ifdef CONFIG_PAX_PAGEEXEC
59534+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
59535+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
59536+
59537+#ifdef CONFIG_PAX_EMUTRAMP
59538+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
59539+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
59540+#endif
59541+
59542+#ifdef CONFIG_PAX_MPROTECT
59543+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
59544+ current->mm->pax_flags |= MF_PAX_MPROTECT;
59545+#endif
59546+
59547+ }
59548+#endif
59549+
59550 if (N_MAGIC(ex) == OMAGIC) {
59551 unsigned long text_addr, map_size;
59552 loff_t pos;
59553@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
59554 }
59555
59556 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
59557- PROT_READ | PROT_WRITE | PROT_EXEC,
59558+ PROT_READ | PROT_WRITE,
59559 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
59560 fd_offset + ex.a_text);
59561 if (error != N_DATADDR(ex)) {
59562diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
59563index 3892c1a..4e27c04 100644
59564--- a/fs/binfmt_elf.c
59565+++ b/fs/binfmt_elf.c
59566@@ -34,6 +34,7 @@
59567 #include <linux/utsname.h>
59568 #include <linux/coredump.h>
59569 #include <linux/sched.h>
59570+#include <linux/xattr.h>
59571 #include <asm/uaccess.h>
59572 #include <asm/param.h>
59573 #include <asm/page.h>
59574@@ -47,7 +48,7 @@
59575
59576 static int load_elf_binary(struct linux_binprm *bprm);
59577 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
59578- int, int, unsigned long);
59579+ int, int, unsigned long) __intentional_overflow(-1);
59580
59581 #ifdef CONFIG_USELIB
59582 static int load_elf_library(struct file *);
59583@@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
59584 #define elf_core_dump NULL
59585 #endif
59586
59587+#ifdef CONFIG_PAX_MPROTECT
59588+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
59589+#endif
59590+
59591+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59592+static void elf_handle_mmap(struct file *file);
59593+#endif
59594+
59595 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
59596 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
59597 #else
59598@@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
59599 .load_binary = load_elf_binary,
59600 .load_shlib = load_elf_library,
59601 .core_dump = elf_core_dump,
59602+
59603+#ifdef CONFIG_PAX_MPROTECT
59604+ .handle_mprotect= elf_handle_mprotect,
59605+#endif
59606+
59607+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59608+ .handle_mmap = elf_handle_mmap,
59609+#endif
59610+
59611 .min_coredump = ELF_EXEC_PAGESIZE,
59612 };
59613
59614@@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
59615
59616 static int set_brk(unsigned long start, unsigned long end)
59617 {
59618+ unsigned long e = end;
59619+
59620 start = ELF_PAGEALIGN(start);
59621 end = ELF_PAGEALIGN(end);
59622 if (end > start) {
59623@@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
59624 if (BAD_ADDR(addr))
59625 return addr;
59626 }
59627- current->mm->start_brk = current->mm->brk = end;
59628+ current->mm->start_brk = current->mm->brk = e;
59629 return 0;
59630 }
59631
59632@@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59633 elf_addr_t __user *u_rand_bytes;
59634 const char *k_platform = ELF_PLATFORM;
59635 const char *k_base_platform = ELF_BASE_PLATFORM;
59636- unsigned char k_rand_bytes[16];
59637+ u32 k_rand_bytes[4];
59638 int items;
59639 elf_addr_t *elf_info;
59640 int ei_index = 0;
59641 const struct cred *cred = current_cred();
59642 struct vm_area_struct *vma;
59643+ unsigned long saved_auxv[AT_VECTOR_SIZE];
59644
59645 /*
59646 * In some cases (e.g. Hyper-Threading), we want to avoid L1
59647@@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59648 * Generate 16 random bytes for userspace PRNG seeding.
59649 */
59650 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
59651- u_rand_bytes = (elf_addr_t __user *)
59652- STACK_ALLOC(p, sizeof(k_rand_bytes));
59653+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
59654+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
59655+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
59656+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
59657+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
59658+ u_rand_bytes = (elf_addr_t __user *) p;
59659 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
59660 return -EFAULT;
59661
59662@@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59663 return -EFAULT;
59664 current->mm->env_end = p;
59665
59666+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
59667+
59668 /* Put the elf_info on the stack in the right place. */
59669 sp = (elf_addr_t __user *)envp + 1;
59670- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
59671+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
59672 return -EFAULT;
59673 return 0;
59674 }
59675@@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
59676 an ELF header */
59677
59678 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59679- struct file *interpreter, unsigned long *interp_map_addr,
59680- unsigned long no_base)
59681+ struct file *interpreter, unsigned long no_base)
59682 {
59683 struct elf_phdr *elf_phdata;
59684 struct elf_phdr *eppnt;
59685- unsigned long load_addr = 0;
59686+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
59687 int load_addr_set = 0;
59688 unsigned long last_bss = 0, elf_bss = 0;
59689- unsigned long error = ~0UL;
59690+ unsigned long error = -EINVAL;
59691 unsigned long total_size;
59692 int retval, i, size;
59693
59694@@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59695 goto out_close;
59696 }
59697
59698+#ifdef CONFIG_PAX_SEGMEXEC
59699+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
59700+ pax_task_size = SEGMEXEC_TASK_SIZE;
59701+#endif
59702+
59703 eppnt = elf_phdata;
59704 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
59705 if (eppnt->p_type == PT_LOAD) {
59706@@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59707 map_addr = elf_map(interpreter, load_addr + vaddr,
59708 eppnt, elf_prot, elf_type, total_size);
59709 total_size = 0;
59710- if (!*interp_map_addr)
59711- *interp_map_addr = map_addr;
59712 error = map_addr;
59713 if (BAD_ADDR(map_addr))
59714 goto out_close;
59715@@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59716 k = load_addr + eppnt->p_vaddr;
59717 if (BAD_ADDR(k) ||
59718 eppnt->p_filesz > eppnt->p_memsz ||
59719- eppnt->p_memsz > TASK_SIZE ||
59720- TASK_SIZE - eppnt->p_memsz < k) {
59721+ eppnt->p_memsz > pax_task_size ||
59722+ pax_task_size - eppnt->p_memsz < k) {
59723 error = -ENOMEM;
59724 goto out_close;
59725 }
59726@@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59727 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
59728
59729 /* Map the last of the bss segment */
59730- error = vm_brk(elf_bss, last_bss - elf_bss);
59731- if (BAD_ADDR(error))
59732- goto out_close;
59733+ if (last_bss > elf_bss) {
59734+ error = vm_brk(elf_bss, last_bss - elf_bss);
59735+ if (BAD_ADDR(error))
59736+ goto out_close;
59737+ }
59738 }
59739
59740 error = load_addr;
59741@@ -543,6 +574,336 @@ out:
59742 return error;
59743 }
59744
59745+#ifdef CONFIG_PAX_PT_PAX_FLAGS
59746+#ifdef CONFIG_PAX_SOFTMODE
59747+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
59748+{
59749+ unsigned long pax_flags = 0UL;
59750+
59751+#ifdef CONFIG_PAX_PAGEEXEC
59752+ if (elf_phdata->p_flags & PF_PAGEEXEC)
59753+ pax_flags |= MF_PAX_PAGEEXEC;
59754+#endif
59755+
59756+#ifdef CONFIG_PAX_SEGMEXEC
59757+ if (elf_phdata->p_flags & PF_SEGMEXEC)
59758+ pax_flags |= MF_PAX_SEGMEXEC;
59759+#endif
59760+
59761+#ifdef CONFIG_PAX_EMUTRAMP
59762+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59763+ pax_flags |= MF_PAX_EMUTRAMP;
59764+#endif
59765+
59766+#ifdef CONFIG_PAX_MPROTECT
59767+ if (elf_phdata->p_flags & PF_MPROTECT)
59768+ pax_flags |= MF_PAX_MPROTECT;
59769+#endif
59770+
59771+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59772+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
59773+ pax_flags |= MF_PAX_RANDMMAP;
59774+#endif
59775+
59776+ return pax_flags;
59777+}
59778+#endif
59779+
59780+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
59781+{
59782+ unsigned long pax_flags = 0UL;
59783+
59784+#ifdef CONFIG_PAX_PAGEEXEC
59785+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
59786+ pax_flags |= MF_PAX_PAGEEXEC;
59787+#endif
59788+
59789+#ifdef CONFIG_PAX_SEGMEXEC
59790+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
59791+ pax_flags |= MF_PAX_SEGMEXEC;
59792+#endif
59793+
59794+#ifdef CONFIG_PAX_EMUTRAMP
59795+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
59796+ pax_flags |= MF_PAX_EMUTRAMP;
59797+#endif
59798+
59799+#ifdef CONFIG_PAX_MPROTECT
59800+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
59801+ pax_flags |= MF_PAX_MPROTECT;
59802+#endif
59803+
59804+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59805+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
59806+ pax_flags |= MF_PAX_RANDMMAP;
59807+#endif
59808+
59809+ return pax_flags;
59810+}
59811+#endif
59812+
59813+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59814+#ifdef CONFIG_PAX_SOFTMODE
59815+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
59816+{
59817+ unsigned long pax_flags = 0UL;
59818+
59819+#ifdef CONFIG_PAX_PAGEEXEC
59820+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
59821+ pax_flags |= MF_PAX_PAGEEXEC;
59822+#endif
59823+
59824+#ifdef CONFIG_PAX_SEGMEXEC
59825+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
59826+ pax_flags |= MF_PAX_SEGMEXEC;
59827+#endif
59828+
59829+#ifdef CONFIG_PAX_EMUTRAMP
59830+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59831+ pax_flags |= MF_PAX_EMUTRAMP;
59832+#endif
59833+
59834+#ifdef CONFIG_PAX_MPROTECT
59835+ if (pax_flags_softmode & MF_PAX_MPROTECT)
59836+ pax_flags |= MF_PAX_MPROTECT;
59837+#endif
59838+
59839+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59840+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
59841+ pax_flags |= MF_PAX_RANDMMAP;
59842+#endif
59843+
59844+ return pax_flags;
59845+}
59846+#endif
59847+
59848+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
59849+{
59850+ unsigned long pax_flags = 0UL;
59851+
59852+#ifdef CONFIG_PAX_PAGEEXEC
59853+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
59854+ pax_flags |= MF_PAX_PAGEEXEC;
59855+#endif
59856+
59857+#ifdef CONFIG_PAX_SEGMEXEC
59858+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
59859+ pax_flags |= MF_PAX_SEGMEXEC;
59860+#endif
59861+
59862+#ifdef CONFIG_PAX_EMUTRAMP
59863+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
59864+ pax_flags |= MF_PAX_EMUTRAMP;
59865+#endif
59866+
59867+#ifdef CONFIG_PAX_MPROTECT
59868+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
59869+ pax_flags |= MF_PAX_MPROTECT;
59870+#endif
59871+
59872+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59873+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
59874+ pax_flags |= MF_PAX_RANDMMAP;
59875+#endif
59876+
59877+ return pax_flags;
59878+}
59879+#endif
59880+
59881+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59882+static unsigned long pax_parse_defaults(void)
59883+{
59884+ unsigned long pax_flags = 0UL;
59885+
59886+#ifdef CONFIG_PAX_SOFTMODE
59887+ if (pax_softmode)
59888+ return pax_flags;
59889+#endif
59890+
59891+#ifdef CONFIG_PAX_PAGEEXEC
59892+ pax_flags |= MF_PAX_PAGEEXEC;
59893+#endif
59894+
59895+#ifdef CONFIG_PAX_SEGMEXEC
59896+ pax_flags |= MF_PAX_SEGMEXEC;
59897+#endif
59898+
59899+#ifdef CONFIG_PAX_MPROTECT
59900+ pax_flags |= MF_PAX_MPROTECT;
59901+#endif
59902+
59903+#ifdef CONFIG_PAX_RANDMMAP
59904+ if (randomize_va_space)
59905+ pax_flags |= MF_PAX_RANDMMAP;
59906+#endif
59907+
59908+ return pax_flags;
59909+}
59910+
59911+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
59912+{
59913+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
59914+
59915+#ifdef CONFIG_PAX_EI_PAX
59916+
59917+#ifdef CONFIG_PAX_SOFTMODE
59918+ if (pax_softmode)
59919+ return pax_flags;
59920+#endif
59921+
59922+ pax_flags = 0UL;
59923+
59924+#ifdef CONFIG_PAX_PAGEEXEC
59925+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
59926+ pax_flags |= MF_PAX_PAGEEXEC;
59927+#endif
59928+
59929+#ifdef CONFIG_PAX_SEGMEXEC
59930+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
59931+ pax_flags |= MF_PAX_SEGMEXEC;
59932+#endif
59933+
59934+#ifdef CONFIG_PAX_EMUTRAMP
59935+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
59936+ pax_flags |= MF_PAX_EMUTRAMP;
59937+#endif
59938+
59939+#ifdef CONFIG_PAX_MPROTECT
59940+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
59941+ pax_flags |= MF_PAX_MPROTECT;
59942+#endif
59943+
59944+#ifdef CONFIG_PAX_ASLR
59945+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
59946+ pax_flags |= MF_PAX_RANDMMAP;
59947+#endif
59948+
59949+#endif
59950+
59951+ return pax_flags;
59952+
59953+}
59954+
59955+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
59956+{
59957+
59958+#ifdef CONFIG_PAX_PT_PAX_FLAGS
59959+ unsigned long i;
59960+
59961+ for (i = 0UL; i < elf_ex->e_phnum; i++)
59962+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
59963+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
59964+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
59965+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
59966+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
59967+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
59968+ return PAX_PARSE_FLAGS_FALLBACK;
59969+
59970+#ifdef CONFIG_PAX_SOFTMODE
59971+ if (pax_softmode)
59972+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
59973+ else
59974+#endif
59975+
59976+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
59977+ break;
59978+ }
59979+#endif
59980+
59981+ return PAX_PARSE_FLAGS_FALLBACK;
59982+}
59983+
59984+static unsigned long pax_parse_xattr_pax(struct file * const file)
59985+{
59986+
59987+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59988+ ssize_t xattr_size, i;
59989+ unsigned char xattr_value[sizeof("pemrs") - 1];
59990+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
59991+
59992+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
59993+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
59994+ return PAX_PARSE_FLAGS_FALLBACK;
59995+
59996+ for (i = 0; i < xattr_size; i++)
59997+ switch (xattr_value[i]) {
59998+ default:
59999+ return PAX_PARSE_FLAGS_FALLBACK;
60000+
60001+#define parse_flag(option1, option2, flag) \
60002+ case option1: \
60003+ if (pax_flags_hardmode & MF_PAX_##flag) \
60004+ return PAX_PARSE_FLAGS_FALLBACK;\
60005+ pax_flags_hardmode |= MF_PAX_##flag; \
60006+ break; \
60007+ case option2: \
60008+ if (pax_flags_softmode & MF_PAX_##flag) \
60009+ return PAX_PARSE_FLAGS_FALLBACK;\
60010+ pax_flags_softmode |= MF_PAX_##flag; \
60011+ break;
60012+
60013+ parse_flag('p', 'P', PAGEEXEC);
60014+ parse_flag('e', 'E', EMUTRAMP);
60015+ parse_flag('m', 'M', MPROTECT);
60016+ parse_flag('r', 'R', RANDMMAP);
60017+ parse_flag('s', 'S', SEGMEXEC);
60018+
60019+#undef parse_flag
60020+ }
60021+
60022+ if (pax_flags_hardmode & pax_flags_softmode)
60023+ return PAX_PARSE_FLAGS_FALLBACK;
60024+
60025+#ifdef CONFIG_PAX_SOFTMODE
60026+ if (pax_softmode)
60027+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
60028+ else
60029+#endif
60030+
60031+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
60032+#else
60033+ return PAX_PARSE_FLAGS_FALLBACK;
60034+#endif
60035+
60036+}
60037+
60038+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
60039+{
60040+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
60041+
60042+ pax_flags = pax_parse_defaults();
60043+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
60044+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
60045+ xattr_pax_flags = pax_parse_xattr_pax(file);
60046+
60047+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
60048+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
60049+ pt_pax_flags != xattr_pax_flags)
60050+ return -EINVAL;
60051+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
60052+ pax_flags = xattr_pax_flags;
60053+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
60054+ pax_flags = pt_pax_flags;
60055+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
60056+ pax_flags = ei_pax_flags;
60057+
60058+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
60059+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60060+ if ((__supported_pte_mask & _PAGE_NX))
60061+ pax_flags &= ~MF_PAX_SEGMEXEC;
60062+ else
60063+ pax_flags &= ~MF_PAX_PAGEEXEC;
60064+ }
60065+#endif
60066+
60067+ if (0 > pax_check_flags(&pax_flags))
60068+ return -EINVAL;
60069+
60070+ current->mm->pax_flags = pax_flags;
60071+ return 0;
60072+}
60073+#endif
60074+
60075 /*
60076 * These are the functions used to load ELF style executables and shared
60077 * libraries. There is no binary dependent code anywhere else.
60078@@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
60079 {
60080 unsigned int random_variable = 0;
60081
60082+#ifdef CONFIG_PAX_RANDUSTACK
60083+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
60084+ return stack_top - current->mm->delta_stack;
60085+#endif
60086+
60087 if ((current->flags & PF_RANDOMIZE) &&
60088 !(current->personality & ADDR_NO_RANDOMIZE)) {
60089 random_variable = get_random_int() & STACK_RND_MASK;
60090@@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
60091 unsigned long load_addr = 0, load_bias = 0;
60092 int load_addr_set = 0;
60093 char * elf_interpreter = NULL;
60094- unsigned long error;
60095+ unsigned long error = 0;
60096 struct elf_phdr *elf_ppnt, *elf_phdata;
60097 unsigned long elf_bss, elf_brk;
60098 int retval, i;
60099@@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
60100 struct elfhdr elf_ex;
60101 struct elfhdr interp_elf_ex;
60102 } *loc;
60103+ unsigned long pax_task_size;
60104
60105 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
60106 if (!loc) {
60107@@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
60108 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
60109 may depend on the personality. */
60110 SET_PERSONALITY(loc->elf_ex);
60111+
60112+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60113+ current->mm->pax_flags = 0UL;
60114+#endif
60115+
60116+#ifdef CONFIG_PAX_DLRESOLVE
60117+ current->mm->call_dl_resolve = 0UL;
60118+#endif
60119+
60120+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
60121+ current->mm->call_syscall = 0UL;
60122+#endif
60123+
60124+#ifdef CONFIG_PAX_ASLR
60125+ current->mm->delta_mmap = 0UL;
60126+ current->mm->delta_stack = 0UL;
60127+#endif
60128+
60129+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60130+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
60131+ send_sig(SIGKILL, current, 0);
60132+ goto out_free_dentry;
60133+ }
60134+#endif
60135+
60136+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60137+ pax_set_initial_flags(bprm);
60138+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
60139+ if (pax_set_initial_flags_func)
60140+ (pax_set_initial_flags_func)(bprm);
60141+#endif
60142+
60143+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60144+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
60145+ current->mm->context.user_cs_limit = PAGE_SIZE;
60146+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
60147+ }
60148+#endif
60149+
60150+#ifdef CONFIG_PAX_SEGMEXEC
60151+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
60152+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
60153+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
60154+ pax_task_size = SEGMEXEC_TASK_SIZE;
60155+ current->mm->def_flags |= VM_NOHUGEPAGE;
60156+ } else
60157+#endif
60158+
60159+ pax_task_size = TASK_SIZE;
60160+
60161+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
60162+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60163+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
60164+ put_cpu();
60165+ }
60166+#endif
60167+
60168+#ifdef CONFIG_PAX_ASLR
60169+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
60170+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
60171+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
60172+ }
60173+#endif
60174+
60175+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
60176+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60177+ executable_stack = EXSTACK_DISABLE_X;
60178+ current->personality &= ~READ_IMPLIES_EXEC;
60179+ } else
60180+#endif
60181+
60182 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
60183 current->personality |= READ_IMPLIES_EXEC;
60184
60185@@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
60186 #else
60187 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
60188 #endif
60189+
60190+#ifdef CONFIG_PAX_RANDMMAP
60191+ /* PaX: randomize base address at the default exe base if requested */
60192+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
60193+#ifdef CONFIG_SPARC64
60194+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
60195+#else
60196+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
60197+#endif
60198+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
60199+ elf_flags |= MAP_FIXED;
60200+ }
60201+#endif
60202+
60203 }
60204
60205 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
60206@@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
60207 * allowed task size. Note that p_filesz must always be
60208 * <= p_memsz so it is only necessary to check p_memsz.
60209 */
60210- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
60211- elf_ppnt->p_memsz > TASK_SIZE ||
60212- TASK_SIZE - elf_ppnt->p_memsz < k) {
60213+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
60214+ elf_ppnt->p_memsz > pax_task_size ||
60215+ pax_task_size - elf_ppnt->p_memsz < k) {
60216 /* set_brk can never work. Avoid overflows. */
60217 send_sig(SIGKILL, current, 0);
60218 retval = -EINVAL;
60219@@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
60220 goto out_free_dentry;
60221 }
60222 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
60223- send_sig(SIGSEGV, current, 0);
60224- retval = -EFAULT; /* Nobody gets to see this, but.. */
60225- goto out_free_dentry;
60226+ /*
60227+ * This bss-zeroing can fail if the ELF
60228+ * file specifies odd protections. So
60229+ * we don't check the return value
60230+ */
60231 }
60232
60233+#ifdef CONFIG_PAX_RANDMMAP
60234+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
60235+ unsigned long start, size, flags;
60236+ vm_flags_t vm_flags;
60237+
60238+ start = ELF_PAGEALIGN(elf_brk);
60239+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
60240+ flags = MAP_FIXED | MAP_PRIVATE;
60241+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
60242+
60243+ down_write(&current->mm->mmap_sem);
60244+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
60245+ retval = -ENOMEM;
60246+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
60247+// if (current->personality & ADDR_NO_RANDOMIZE)
60248+// vm_flags |= VM_READ | VM_MAYREAD;
60249+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
60250+ retval = IS_ERR_VALUE(start) ? start : 0;
60251+ }
60252+ up_write(&current->mm->mmap_sem);
60253+ if (retval == 0)
60254+ retval = set_brk(start + size, start + size + PAGE_SIZE);
60255+ if (retval < 0) {
60256+ send_sig(SIGKILL, current, 0);
60257+ goto out_free_dentry;
60258+ }
60259+ }
60260+#endif
60261+
60262 if (elf_interpreter) {
60263- unsigned long interp_map_addr = 0;
60264-
60265 elf_entry = load_elf_interp(&loc->interp_elf_ex,
60266 interpreter,
60267- &interp_map_addr,
60268 load_bias);
60269 if (!IS_ERR((void *)elf_entry)) {
60270 /*
60271@@ -1130,7 +1610,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
60272 * Decide what to dump of a segment, part, all or none.
60273 */
60274 static unsigned long vma_dump_size(struct vm_area_struct *vma,
60275- unsigned long mm_flags)
60276+ unsigned long mm_flags, long signr)
60277 {
60278 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
60279
60280@@ -1168,7 +1648,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
60281 if (vma->vm_file == NULL)
60282 return 0;
60283
60284- if (FILTER(MAPPED_PRIVATE))
60285+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
60286 goto whole;
60287
60288 /*
60289@@ -1375,9 +1855,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
60290 {
60291 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
60292 int i = 0;
60293- do
60294+ do {
60295 i += 2;
60296- while (auxv[i - 2] != AT_NULL);
60297+ } while (auxv[i - 2] != AT_NULL);
60298 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
60299 }
60300
60301@@ -1386,7 +1866,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
60302 {
60303 mm_segment_t old_fs = get_fs();
60304 set_fs(KERNEL_DS);
60305- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
60306+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
60307 set_fs(old_fs);
60308 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
60309 }
60310@@ -2010,14 +2490,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
60311 }
60312
60313 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
60314- unsigned long mm_flags)
60315+ struct coredump_params *cprm)
60316 {
60317 struct vm_area_struct *vma;
60318 size_t size = 0;
60319
60320 for (vma = first_vma(current, gate_vma); vma != NULL;
60321 vma = next_vma(vma, gate_vma))
60322- size += vma_dump_size(vma, mm_flags);
60323+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60324 return size;
60325 }
60326
60327@@ -2108,7 +2588,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60328
60329 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
60330
60331- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
60332+ offset += elf_core_vma_data_size(gate_vma, cprm);
60333 offset += elf_core_extra_data_size();
60334 e_shoff = offset;
60335
60336@@ -2136,7 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60337 phdr.p_offset = offset;
60338 phdr.p_vaddr = vma->vm_start;
60339 phdr.p_paddr = 0;
60340- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
60341+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60342 phdr.p_memsz = vma->vm_end - vma->vm_start;
60343 offset += phdr.p_filesz;
60344 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
60345@@ -2169,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60346 unsigned long addr;
60347 unsigned long end;
60348
60349- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
60350+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60351
60352 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
60353 struct page *page;
60354@@ -2210,6 +2690,167 @@ out:
60355
60356 #endif /* CONFIG_ELF_CORE */
60357
60358+#ifdef CONFIG_PAX_MPROTECT
60359+/* PaX: non-PIC ELF libraries need relocations on their executable segments
60360+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
60361+ * we'll remove VM_MAYWRITE for good on RELRO segments.
60362+ *
60363+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
60364+ * basis because we want to allow the common case and not the special ones.
60365+ */
60366+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
60367+{
60368+ struct elfhdr elf_h;
60369+ struct elf_phdr elf_p;
60370+ unsigned long i;
60371+ unsigned long oldflags;
60372+ bool is_textrel_rw, is_textrel_rx, is_relro;
60373+
60374+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
60375+ return;
60376+
60377+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
60378+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
60379+
60380+#ifdef CONFIG_PAX_ELFRELOCS
60381+ /* possible TEXTREL */
60382+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
60383+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
60384+#else
60385+ is_textrel_rw = false;
60386+ is_textrel_rx = false;
60387+#endif
60388+
60389+ /* possible RELRO */
60390+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
60391+
60392+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
60393+ return;
60394+
60395+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
60396+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
60397+
60398+#ifdef CONFIG_PAX_ETEXECRELOCS
60399+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
60400+#else
60401+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
60402+#endif
60403+
60404+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
60405+ !elf_check_arch(&elf_h) ||
60406+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
60407+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
60408+ return;
60409+
60410+ for (i = 0UL; i < elf_h.e_phnum; i++) {
60411+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
60412+ return;
60413+ switch (elf_p.p_type) {
60414+ case PT_DYNAMIC:
60415+ if (!is_textrel_rw && !is_textrel_rx)
60416+ continue;
60417+ i = 0UL;
60418+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
60419+ elf_dyn dyn;
60420+
60421+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
60422+ break;
60423+ if (dyn.d_tag == DT_NULL)
60424+ break;
60425+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
60426+ gr_log_textrel(vma);
60427+ if (is_textrel_rw)
60428+ vma->vm_flags |= VM_MAYWRITE;
60429+ else
60430+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
60431+ vma->vm_flags &= ~VM_MAYWRITE;
60432+ break;
60433+ }
60434+ i++;
60435+ }
60436+ is_textrel_rw = false;
60437+ is_textrel_rx = false;
60438+ continue;
60439+
60440+ case PT_GNU_RELRO:
60441+ if (!is_relro)
60442+ continue;
60443+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
60444+ vma->vm_flags &= ~VM_MAYWRITE;
60445+ is_relro = false;
60446+ continue;
60447+
60448+#ifdef CONFIG_PAX_PT_PAX_FLAGS
60449+ case PT_PAX_FLAGS: {
60450+ const char *msg_mprotect = "", *msg_emutramp = "";
60451+ char *buffer_lib, *buffer_exe;
60452+
60453+ if (elf_p.p_flags & PF_NOMPROTECT)
60454+ msg_mprotect = "MPROTECT disabled";
60455+
60456+#ifdef CONFIG_PAX_EMUTRAMP
60457+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
60458+ msg_emutramp = "EMUTRAMP enabled";
60459+#endif
60460+
60461+ if (!msg_mprotect[0] && !msg_emutramp[0])
60462+ continue;
60463+
60464+ if (!printk_ratelimit())
60465+ continue;
60466+
60467+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
60468+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
60469+ if (buffer_lib && buffer_exe) {
60470+ char *path_lib, *path_exe;
60471+
60472+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
60473+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
60474+
60475+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
60476+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
60477+
60478+ }
60479+ free_page((unsigned long)buffer_exe);
60480+ free_page((unsigned long)buffer_lib);
60481+ continue;
60482+ }
60483+#endif
60484+
60485+ }
60486+ }
60487+}
60488+#endif
60489+
60490+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60491+
60492+extern int grsec_enable_log_rwxmaps;
60493+
60494+static void elf_handle_mmap(struct file *file)
60495+{
60496+ struct elfhdr elf_h;
60497+ struct elf_phdr elf_p;
60498+ unsigned long i;
60499+
60500+ if (!grsec_enable_log_rwxmaps)
60501+ return;
60502+
60503+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
60504+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
60505+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
60506+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
60507+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
60508+ return;
60509+
60510+ for (i = 0UL; i < elf_h.e_phnum; i++) {
60511+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
60512+ return;
60513+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
60514+ gr_log_ptgnustack(file);
60515+ }
60516+}
60517+#endif
60518+
60519 static int __init init_elf_binfmt(void)
60520 {
60521 register_binfmt(&elf_format);
60522diff --git a/fs/block_dev.c b/fs/block_dev.c
60523index 6d72746..536d1db 100644
60524--- a/fs/block_dev.c
60525+++ b/fs/block_dev.c
60526@@ -701,7 +701,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
60527 else if (bdev->bd_contains == bdev)
60528 return true; /* is a whole device which isn't held */
60529
60530- else if (whole->bd_holder == bd_may_claim)
60531+ else if (whole->bd_holder == (void *)bd_may_claim)
60532 return true; /* is a partition of a device that is being partitioned */
60533 else if (whole->bd_holder != NULL)
60534 return false; /* is a partition of a held device */
60535diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
60536index aeab453..48dbafc 100644
60537--- a/fs/btrfs/ctree.c
60538+++ b/fs/btrfs/ctree.c
60539@@ -1184,9 +1184,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
60540 free_extent_buffer(buf);
60541 add_root_to_dirty_list(root);
60542 } else {
60543- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
60544- parent_start = parent->start;
60545- else
60546+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
60547+ if (parent)
60548+ parent_start = parent->start;
60549+ else
60550+ parent_start = 0;
60551+ } else
60552 parent_start = 0;
60553
60554 WARN_ON(trans->transid != btrfs_header_generation(parent));
60555diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
60556index da775bf..882da68 100644
60557--- a/fs/btrfs/delayed-inode.c
60558+++ b/fs/btrfs/delayed-inode.c
60559@@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
60560
60561 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
60562 {
60563- int seq = atomic_inc_return(&delayed_root->items_seq);
60564+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
60565 if ((atomic_dec_return(&delayed_root->items) <
60566 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
60567 waitqueue_active(&delayed_root->wait))
60568@@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
60569
60570 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
60571 {
60572- int val = atomic_read(&delayed_root->items_seq);
60573+ int val = atomic_read_unchecked(&delayed_root->items_seq);
60574
60575 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
60576 return 1;
60577@@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
60578 int seq;
60579 int ret;
60580
60581- seq = atomic_read(&delayed_root->items_seq);
60582+ seq = atomic_read_unchecked(&delayed_root->items_seq);
60583
60584 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
60585 if (ret)
60586diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
60587index f70119f..ab5894d 100644
60588--- a/fs/btrfs/delayed-inode.h
60589+++ b/fs/btrfs/delayed-inode.h
60590@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
60591 */
60592 struct list_head prepare_list;
60593 atomic_t items; /* for delayed items */
60594- atomic_t items_seq; /* for delayed items */
60595+ atomic_unchecked_t items_seq; /* for delayed items */
60596 int nodes; /* for delayed nodes */
60597 wait_queue_head_t wait;
60598 };
60599@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
60600 struct btrfs_delayed_root *delayed_root)
60601 {
60602 atomic_set(&delayed_root->items, 0);
60603- atomic_set(&delayed_root->items_seq, 0);
60604+ atomic_set_unchecked(&delayed_root->items_seq, 0);
60605 delayed_root->nodes = 0;
60606 spin_lock_init(&delayed_root->lock);
60607 init_waitqueue_head(&delayed_root->wait);
60608diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
60609index 47aceb4..7d28b1c 100644
60610--- a/fs/btrfs/ioctl.c
60611+++ b/fs/btrfs/ioctl.c
60612@@ -3965,9 +3965,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
60613 for (i = 0; i < num_types; i++) {
60614 struct btrfs_space_info *tmp;
60615
60616+ /* Don't copy in more than we allocated */
60617 if (!slot_count)
60618 break;
60619
60620+ slot_count--;
60621+
60622 info = NULL;
60623 rcu_read_lock();
60624 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
60625@@ -3989,10 +3992,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
60626 memcpy(dest, &space, sizeof(space));
60627 dest++;
60628 space_args.total_spaces++;
60629- slot_count--;
60630 }
60631- if (!slot_count)
60632- break;
60633 }
60634 up_read(&info->groups_sem);
60635 }
60636diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
60637index 8e16bca..6eabd9e 100644
60638--- a/fs/btrfs/super.c
60639+++ b/fs/btrfs/super.c
60640@@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
60641 function, line, errstr);
60642 return;
60643 }
60644- ACCESS_ONCE(trans->transaction->aborted) = errno;
60645+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
60646 /* Wake up anybody who may be waiting on this transaction */
60647 wake_up(&root->fs_info->transaction_wait);
60648 wake_up(&root->fs_info->transaction_blocked_wait);
60649diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
60650index 7869936..7e153dc 100644
60651--- a/fs/btrfs/sysfs.c
60652+++ b/fs/btrfs/sysfs.c
60653@@ -475,7 +475,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
60654 for (set = 0; set < FEAT_MAX; set++) {
60655 int i;
60656 struct attribute *attrs[2];
60657- struct attribute_group agroup = {
60658+ attribute_group_no_const agroup = {
60659 .name = "features",
60660 .attrs = attrs,
60661 };
60662diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
60663index 7f5b41b..e589c13 100644
60664--- a/fs/btrfs/tree-log.h
60665+++ b/fs/btrfs/tree-log.h
60666@@ -41,7 +41,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
60667 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
60668 struct btrfs_trans_handle *trans)
60669 {
60670- ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
60671+ ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
60672 }
60673
60674 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
60675diff --git a/fs/buffer.c b/fs/buffer.c
60676index eba6e4f..af1182c 100644
60677--- a/fs/buffer.c
60678+++ b/fs/buffer.c
60679@@ -3429,7 +3429,7 @@ void __init buffer_init(void)
60680 bh_cachep = kmem_cache_create("buffer_head",
60681 sizeof(struct buffer_head), 0,
60682 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
60683- SLAB_MEM_SPREAD),
60684+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
60685 NULL);
60686
60687 /*
60688diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
60689index d749731..dd333a6 100644
60690--- a/fs/cachefiles/bind.c
60691+++ b/fs/cachefiles/bind.c
60692@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
60693 args);
60694
60695 /* start by checking things over */
60696- ASSERT(cache->fstop_percent >= 0 &&
60697- cache->fstop_percent < cache->fcull_percent &&
60698+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
60699 cache->fcull_percent < cache->frun_percent &&
60700 cache->frun_percent < 100);
60701
60702- ASSERT(cache->bstop_percent >= 0 &&
60703- cache->bstop_percent < cache->bcull_percent &&
60704+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
60705 cache->bcull_percent < cache->brun_percent &&
60706 cache->brun_percent < 100);
60707
60708diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
60709index b078d30..db23012 100644
60710--- a/fs/cachefiles/daemon.c
60711+++ b/fs/cachefiles/daemon.c
60712@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
60713 if (n > buflen)
60714 return -EMSGSIZE;
60715
60716- if (copy_to_user(_buffer, buffer, n) != 0)
60717+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
60718 return -EFAULT;
60719
60720 return n;
60721@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
60722 if (test_bit(CACHEFILES_DEAD, &cache->flags))
60723 return -EIO;
60724
60725- if (datalen < 0 || datalen > PAGE_SIZE - 1)
60726+ if (datalen > PAGE_SIZE - 1)
60727 return -EOPNOTSUPP;
60728
60729 /* drag the command string into the kernel so we can parse it */
60730@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
60731 if (args[0] != '%' || args[1] != '\0')
60732 return -EINVAL;
60733
60734- if (fstop < 0 || fstop >= cache->fcull_percent)
60735+ if (fstop >= cache->fcull_percent)
60736 return cachefiles_daemon_range_error(cache, args);
60737
60738 cache->fstop_percent = fstop;
60739@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
60740 if (args[0] != '%' || args[1] != '\0')
60741 return -EINVAL;
60742
60743- if (bstop < 0 || bstop >= cache->bcull_percent)
60744+ if (bstop >= cache->bcull_percent)
60745 return cachefiles_daemon_range_error(cache, args);
60746
60747 cache->bstop_percent = bstop;
60748diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
60749index 3d50998..0550d67 100644
60750--- a/fs/cachefiles/internal.h
60751+++ b/fs/cachefiles/internal.h
60752@@ -66,7 +66,7 @@ struct cachefiles_cache {
60753 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
60754 struct rb_root active_nodes; /* active nodes (can't be culled) */
60755 rwlock_t active_lock; /* lock for active_nodes */
60756- atomic_t gravecounter; /* graveyard uniquifier */
60757+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
60758 unsigned frun_percent; /* when to stop culling (% files) */
60759 unsigned fcull_percent; /* when to start culling (% files) */
60760 unsigned fstop_percent; /* when to stop allocating (% files) */
60761@@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
60762 * proc.c
60763 */
60764 #ifdef CONFIG_CACHEFILES_HISTOGRAM
60765-extern atomic_t cachefiles_lookup_histogram[HZ];
60766-extern atomic_t cachefiles_mkdir_histogram[HZ];
60767-extern atomic_t cachefiles_create_histogram[HZ];
60768+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60769+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60770+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
60771
60772 extern int __init cachefiles_proc_init(void);
60773 extern void cachefiles_proc_cleanup(void);
60774 static inline
60775-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
60776+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
60777 {
60778 unsigned long jif = jiffies - start_jif;
60779 if (jif >= HZ)
60780 jif = HZ - 1;
60781- atomic_inc(&histogram[jif]);
60782+ atomic_inc_unchecked(&histogram[jif]);
60783 }
60784
60785 #else
60786diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
60787index 5bf2b41..85b93f9 100644
60788--- a/fs/cachefiles/namei.c
60789+++ b/fs/cachefiles/namei.c
60790@@ -312,7 +312,7 @@ try_again:
60791 /* first step is to make up a grave dentry in the graveyard */
60792 sprintf(nbuffer, "%08x%08x",
60793 (uint32_t) get_seconds(),
60794- (uint32_t) atomic_inc_return(&cache->gravecounter));
60795+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
60796
60797 /* do the multiway lock magic */
60798 trap = lock_rename(cache->graveyard, dir);
60799diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
60800index eccd339..4c1d995 100644
60801--- a/fs/cachefiles/proc.c
60802+++ b/fs/cachefiles/proc.c
60803@@ -14,9 +14,9 @@
60804 #include <linux/seq_file.h>
60805 #include "internal.h"
60806
60807-atomic_t cachefiles_lookup_histogram[HZ];
60808-atomic_t cachefiles_mkdir_histogram[HZ];
60809-atomic_t cachefiles_create_histogram[HZ];
60810+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60811+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60812+atomic_unchecked_t cachefiles_create_histogram[HZ];
60813
60814 /*
60815 * display the latency histogram
60816@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
60817 return 0;
60818 default:
60819 index = (unsigned long) v - 3;
60820- x = atomic_read(&cachefiles_lookup_histogram[index]);
60821- y = atomic_read(&cachefiles_mkdir_histogram[index]);
60822- z = atomic_read(&cachefiles_create_histogram[index]);
60823+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
60824+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
60825+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
60826 if (x == 0 && y == 0 && z == 0)
60827 return 0;
60828
60829diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
60830index 4b1fb5c..0d2a699 100644
60831--- a/fs/cachefiles/rdwr.c
60832+++ b/fs/cachefiles/rdwr.c
60833@@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
60834 old_fs = get_fs();
60835 set_fs(KERNEL_DS);
60836 ret = file->f_op->write(
60837- file, (const void __user *) data, len, &pos);
60838+ file, (const void __force_user *) data, len, &pos);
60839 set_fs(old_fs);
60840 kunmap(page);
60841 file_end_write(file);
60842diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
60843index c29d6ae..719b9bb 100644
60844--- a/fs/ceph/dir.c
60845+++ b/fs/ceph/dir.c
60846@@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
60847 struct dentry *dentry, *last;
60848 struct ceph_dentry_info *di;
60849 int err = 0;
60850+ char d_name[DNAME_INLINE_LEN];
60851+ const unsigned char *name;
60852
60853 /* claim ref on last dentry we returned */
60854 last = fi->dentry;
60855@@ -192,7 +194,12 @@ more:
60856
60857 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
60858 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
60859- if (!dir_emit(ctx, dentry->d_name.name,
60860+ name = dentry->d_name.name;
60861+ if (name == dentry->d_iname) {
60862+ memcpy(d_name, name, dentry->d_name.len);
60863+ name = d_name;
60864+ }
60865+ if (!dir_emit(ctx, name,
60866 dentry->d_name.len,
60867 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
60868 dentry->d_inode->i_mode >> 12)) {
60869@@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
60870 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
60871 struct ceph_mds_client *mdsc = fsc->mdsc;
60872 unsigned frag = fpos_frag(ctx->pos);
60873- int off = fpos_off(ctx->pos);
60874+ unsigned int off = fpos_off(ctx->pos);
60875 int err;
60876 u32 ftype;
60877 struct ceph_mds_reply_info_parsed *rinfo;
60878diff --git a/fs/ceph/super.c b/fs/ceph/super.c
60879index 06150fd..192061b 100644
60880--- a/fs/ceph/super.c
60881+++ b/fs/ceph/super.c
60882@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
60883 /*
60884 * construct our own bdi so we can control readahead, etc.
60885 */
60886-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
60887+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
60888
60889 static int ceph_register_bdi(struct super_block *sb,
60890 struct ceph_fs_client *fsc)
60891@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
60892 default_backing_dev_info.ra_pages;
60893
60894 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
60895- atomic_long_inc_return(&bdi_seq));
60896+ atomic_long_inc_return_unchecked(&bdi_seq));
60897 if (!err)
60898 sb->s_bdi = &fsc->backing_dev_info;
60899 return err;
60900diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
60901index f3ac415..3d2420c 100644
60902--- a/fs/cifs/cifs_debug.c
60903+++ b/fs/cifs/cifs_debug.c
60904@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60905
60906 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
60907 #ifdef CONFIG_CIFS_STATS2
60908- atomic_set(&totBufAllocCount, 0);
60909- atomic_set(&totSmBufAllocCount, 0);
60910+ atomic_set_unchecked(&totBufAllocCount, 0);
60911+ atomic_set_unchecked(&totSmBufAllocCount, 0);
60912 #endif /* CONFIG_CIFS_STATS2 */
60913 spin_lock(&cifs_tcp_ses_lock);
60914 list_for_each(tmp1, &cifs_tcp_ses_list) {
60915@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60916 tcon = list_entry(tmp3,
60917 struct cifs_tcon,
60918 tcon_list);
60919- atomic_set(&tcon->num_smbs_sent, 0);
60920+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
60921 if (server->ops->clear_stats)
60922 server->ops->clear_stats(tcon);
60923 }
60924@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60925 smBufAllocCount.counter, cifs_min_small);
60926 #ifdef CONFIG_CIFS_STATS2
60927 seq_printf(m, "Total Large %d Small %d Allocations\n",
60928- atomic_read(&totBufAllocCount),
60929- atomic_read(&totSmBufAllocCount));
60930+ atomic_read_unchecked(&totBufAllocCount),
60931+ atomic_read_unchecked(&totSmBufAllocCount));
60932 #endif /* CONFIG_CIFS_STATS2 */
60933
60934 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
60935@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60936 if (tcon->need_reconnect)
60937 seq_puts(m, "\tDISCONNECTED ");
60938 seq_printf(m, "\nSMBs: %d",
60939- atomic_read(&tcon->num_smbs_sent));
60940+ atomic_read_unchecked(&tcon->num_smbs_sent));
60941 if (server->ops->print_stats)
60942 server->ops->print_stats(m, tcon);
60943 }
60944diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
60945index 8883980..c8ade72 100644
60946--- a/fs/cifs/cifsfs.c
60947+++ b/fs/cifs/cifsfs.c
60948@@ -1072,7 +1072,7 @@ cifs_init_request_bufs(void)
60949 */
60950 cifs_req_cachep = kmem_cache_create("cifs_request",
60951 CIFSMaxBufSize + max_hdr_size, 0,
60952- SLAB_HWCACHE_ALIGN, NULL);
60953+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
60954 if (cifs_req_cachep == NULL)
60955 return -ENOMEM;
60956
60957@@ -1099,7 +1099,7 @@ cifs_init_request_bufs(void)
60958 efficient to alloc 1 per page off the slab compared to 17K (5page)
60959 alloc of large cifs buffers even when page debugging is on */
60960 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
60961- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
60962+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
60963 NULL);
60964 if (cifs_sm_req_cachep == NULL) {
60965 mempool_destroy(cifs_req_poolp);
60966@@ -1184,8 +1184,8 @@ init_cifs(void)
60967 atomic_set(&bufAllocCount, 0);
60968 atomic_set(&smBufAllocCount, 0);
60969 #ifdef CONFIG_CIFS_STATS2
60970- atomic_set(&totBufAllocCount, 0);
60971- atomic_set(&totSmBufAllocCount, 0);
60972+ atomic_set_unchecked(&totBufAllocCount, 0);
60973+ atomic_set_unchecked(&totSmBufAllocCount, 0);
60974 #endif /* CONFIG_CIFS_STATS2 */
60975
60976 atomic_set(&midCount, 0);
60977diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
60978index de6aed8..a0a76fd 100644
60979--- a/fs/cifs/cifsglob.h
60980+++ b/fs/cifs/cifsglob.h
60981@@ -807,35 +807,35 @@ struct cifs_tcon {
60982 __u16 Flags; /* optional support bits */
60983 enum statusEnum tidStatus;
60984 #ifdef CONFIG_CIFS_STATS
60985- atomic_t num_smbs_sent;
60986+ atomic_unchecked_t num_smbs_sent;
60987 union {
60988 struct {
60989- atomic_t num_writes;
60990- atomic_t num_reads;
60991- atomic_t num_flushes;
60992- atomic_t num_oplock_brks;
60993- atomic_t num_opens;
60994- atomic_t num_closes;
60995- atomic_t num_deletes;
60996- atomic_t num_mkdirs;
60997- atomic_t num_posixopens;
60998- atomic_t num_posixmkdirs;
60999- atomic_t num_rmdirs;
61000- atomic_t num_renames;
61001- atomic_t num_t2renames;
61002- atomic_t num_ffirst;
61003- atomic_t num_fnext;
61004- atomic_t num_fclose;
61005- atomic_t num_hardlinks;
61006- atomic_t num_symlinks;
61007- atomic_t num_locks;
61008- atomic_t num_acl_get;
61009- atomic_t num_acl_set;
61010+ atomic_unchecked_t num_writes;
61011+ atomic_unchecked_t num_reads;
61012+ atomic_unchecked_t num_flushes;
61013+ atomic_unchecked_t num_oplock_brks;
61014+ atomic_unchecked_t num_opens;
61015+ atomic_unchecked_t num_closes;
61016+ atomic_unchecked_t num_deletes;
61017+ atomic_unchecked_t num_mkdirs;
61018+ atomic_unchecked_t num_posixopens;
61019+ atomic_unchecked_t num_posixmkdirs;
61020+ atomic_unchecked_t num_rmdirs;
61021+ atomic_unchecked_t num_renames;
61022+ atomic_unchecked_t num_t2renames;
61023+ atomic_unchecked_t num_ffirst;
61024+ atomic_unchecked_t num_fnext;
61025+ atomic_unchecked_t num_fclose;
61026+ atomic_unchecked_t num_hardlinks;
61027+ atomic_unchecked_t num_symlinks;
61028+ atomic_unchecked_t num_locks;
61029+ atomic_unchecked_t num_acl_get;
61030+ atomic_unchecked_t num_acl_set;
61031 } cifs_stats;
61032 #ifdef CONFIG_CIFS_SMB2
61033 struct {
61034- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
61035- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
61036+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
61037+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
61038 } smb2_stats;
61039 #endif /* CONFIG_CIFS_SMB2 */
61040 } stats;
61041@@ -1172,7 +1172,7 @@ convert_delimiter(char *path, char delim)
61042 }
61043
61044 #ifdef CONFIG_CIFS_STATS
61045-#define cifs_stats_inc atomic_inc
61046+#define cifs_stats_inc atomic_inc_unchecked
61047
61048 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
61049 unsigned int bytes)
61050@@ -1538,8 +1538,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
61051 /* Various Debug counters */
61052 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
61053 #ifdef CONFIG_CIFS_STATS2
61054-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
61055-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
61056+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
61057+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
61058 #endif
61059 GLOBAL_EXTERN atomic_t smBufAllocCount;
61060 GLOBAL_EXTERN atomic_t midCount;
61061diff --git a/fs/cifs/file.c b/fs/cifs/file.c
61062index e90a1e9..908699d 100644
61063--- a/fs/cifs/file.c
61064+++ b/fs/cifs/file.c
61065@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
61066 index = mapping->writeback_index; /* Start from prev offset */
61067 end = -1;
61068 } else {
61069- index = wbc->range_start >> PAGE_CACHE_SHIFT;
61070- end = wbc->range_end >> PAGE_CACHE_SHIFT;
61071- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
61072+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
61073 range_whole = true;
61074+ index = 0;
61075+ end = ULONG_MAX;
61076+ } else {
61077+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
61078+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
61079+ }
61080 scanned = true;
61081 }
61082 retry:
61083diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
61084index 3b0c62e..f7d090c 100644
61085--- a/fs/cifs/misc.c
61086+++ b/fs/cifs/misc.c
61087@@ -170,7 +170,7 @@ cifs_buf_get(void)
61088 memset(ret_buf, 0, buf_size + 3);
61089 atomic_inc(&bufAllocCount);
61090 #ifdef CONFIG_CIFS_STATS2
61091- atomic_inc(&totBufAllocCount);
61092+ atomic_inc_unchecked(&totBufAllocCount);
61093 #endif /* CONFIG_CIFS_STATS2 */
61094 }
61095
61096@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
61097 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
61098 atomic_inc(&smBufAllocCount);
61099 #ifdef CONFIG_CIFS_STATS2
61100- atomic_inc(&totSmBufAllocCount);
61101+ atomic_inc_unchecked(&totSmBufAllocCount);
61102 #endif /* CONFIG_CIFS_STATS2 */
61103
61104 }
61105diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
61106index d1fdfa8..94558f8 100644
61107--- a/fs/cifs/smb1ops.c
61108+++ b/fs/cifs/smb1ops.c
61109@@ -626,27 +626,27 @@ static void
61110 cifs_clear_stats(struct cifs_tcon *tcon)
61111 {
61112 #ifdef CONFIG_CIFS_STATS
61113- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
61114- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
61115- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
61116- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
61117- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
61118- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
61119- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
61120- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
61121- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
61122- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
61123- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
61124- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
61125- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
61126- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
61127- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
61128- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
61129- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
61130- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
61131- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
61132- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
61133- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
61134+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
61135+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
61136+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
61137+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
61138+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
61139+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
61140+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
61141+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
61142+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
61143+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
61144+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
61145+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
61146+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
61147+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
61148+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
61149+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
61150+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
61151+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
61152+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
61153+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
61154+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
61155 #endif
61156 }
61157
61158@@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
61159 {
61160 #ifdef CONFIG_CIFS_STATS
61161 seq_printf(m, " Oplocks breaks: %d",
61162- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
61163+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
61164 seq_printf(m, "\nReads: %d Bytes: %llu",
61165- atomic_read(&tcon->stats.cifs_stats.num_reads),
61166+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
61167 (long long)(tcon->bytes_read));
61168 seq_printf(m, "\nWrites: %d Bytes: %llu",
61169- atomic_read(&tcon->stats.cifs_stats.num_writes),
61170+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
61171 (long long)(tcon->bytes_written));
61172 seq_printf(m, "\nFlushes: %d",
61173- atomic_read(&tcon->stats.cifs_stats.num_flushes));
61174+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
61175 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
61176- atomic_read(&tcon->stats.cifs_stats.num_locks),
61177- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
61178- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
61179+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
61180+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
61181+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
61182 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
61183- atomic_read(&tcon->stats.cifs_stats.num_opens),
61184- atomic_read(&tcon->stats.cifs_stats.num_closes),
61185- atomic_read(&tcon->stats.cifs_stats.num_deletes));
61186+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
61187+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
61188+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
61189 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
61190- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
61191- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
61192+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
61193+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
61194 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
61195- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
61196- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
61197+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
61198+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
61199 seq_printf(m, "\nRenames: %d T2 Renames %d",
61200- atomic_read(&tcon->stats.cifs_stats.num_renames),
61201- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
61202+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
61203+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
61204 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
61205- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
61206- atomic_read(&tcon->stats.cifs_stats.num_fnext),
61207- atomic_read(&tcon->stats.cifs_stats.num_fclose));
61208+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
61209+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
61210+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
61211 #endif
61212 }
61213
61214diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
61215index 787844b..8e7bc7d 100644
61216--- a/fs/cifs/smb2ops.c
61217+++ b/fs/cifs/smb2ops.c
61218@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
61219 #ifdef CONFIG_CIFS_STATS
61220 int i;
61221 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
61222- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
61223- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
61224+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
61225+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
61226 }
61227 #endif
61228 }
61229@@ -405,65 +405,65 @@ static void
61230 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
61231 {
61232 #ifdef CONFIG_CIFS_STATS
61233- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
61234- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
61235+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
61236+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
61237 seq_printf(m, "\nNegotiates: %d sent %d failed",
61238- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
61239- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
61240+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
61241+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
61242 seq_printf(m, "\nSessionSetups: %d sent %d failed",
61243- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
61244- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
61245+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
61246+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
61247 seq_printf(m, "\nLogoffs: %d sent %d failed",
61248- atomic_read(&sent[SMB2_LOGOFF_HE]),
61249- atomic_read(&failed[SMB2_LOGOFF_HE]));
61250+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
61251+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
61252 seq_printf(m, "\nTreeConnects: %d sent %d failed",
61253- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
61254- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
61255+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
61256+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
61257 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
61258- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
61259- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
61260+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
61261+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
61262 seq_printf(m, "\nCreates: %d sent %d failed",
61263- atomic_read(&sent[SMB2_CREATE_HE]),
61264- atomic_read(&failed[SMB2_CREATE_HE]));
61265+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
61266+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
61267 seq_printf(m, "\nCloses: %d sent %d failed",
61268- atomic_read(&sent[SMB2_CLOSE_HE]),
61269- atomic_read(&failed[SMB2_CLOSE_HE]));
61270+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
61271+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
61272 seq_printf(m, "\nFlushes: %d sent %d failed",
61273- atomic_read(&sent[SMB2_FLUSH_HE]),
61274- atomic_read(&failed[SMB2_FLUSH_HE]));
61275+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
61276+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
61277 seq_printf(m, "\nReads: %d sent %d failed",
61278- atomic_read(&sent[SMB2_READ_HE]),
61279- atomic_read(&failed[SMB2_READ_HE]));
61280+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
61281+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
61282 seq_printf(m, "\nWrites: %d sent %d failed",
61283- atomic_read(&sent[SMB2_WRITE_HE]),
61284- atomic_read(&failed[SMB2_WRITE_HE]));
61285+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
61286+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
61287 seq_printf(m, "\nLocks: %d sent %d failed",
61288- atomic_read(&sent[SMB2_LOCK_HE]),
61289- atomic_read(&failed[SMB2_LOCK_HE]));
61290+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
61291+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
61292 seq_printf(m, "\nIOCTLs: %d sent %d failed",
61293- atomic_read(&sent[SMB2_IOCTL_HE]),
61294- atomic_read(&failed[SMB2_IOCTL_HE]));
61295+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
61296+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
61297 seq_printf(m, "\nCancels: %d sent %d failed",
61298- atomic_read(&sent[SMB2_CANCEL_HE]),
61299- atomic_read(&failed[SMB2_CANCEL_HE]));
61300+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
61301+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
61302 seq_printf(m, "\nEchos: %d sent %d failed",
61303- atomic_read(&sent[SMB2_ECHO_HE]),
61304- atomic_read(&failed[SMB2_ECHO_HE]));
61305+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
61306+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
61307 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
61308- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
61309- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
61310+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
61311+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
61312 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
61313- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
61314- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
61315+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
61316+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
61317 seq_printf(m, "\nQueryInfos: %d sent %d failed",
61318- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
61319- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
61320+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
61321+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
61322 seq_printf(m, "\nSetInfos: %d sent %d failed",
61323- atomic_read(&sent[SMB2_SET_INFO_HE]),
61324- atomic_read(&failed[SMB2_SET_INFO_HE]));
61325+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
61326+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
61327 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
61328- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
61329- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
61330+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
61331+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
61332 #endif
61333 }
61334
61335diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
61336index b0b260d..c8927e1 100644
61337--- a/fs/cifs/smb2pdu.c
61338+++ b/fs/cifs/smb2pdu.c
61339@@ -2105,8 +2105,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
61340 default:
61341 cifs_dbg(VFS, "info level %u isn't supported\n",
61342 srch_inf->info_level);
61343- rc = -EINVAL;
61344- goto qdir_exit;
61345+ return -EINVAL;
61346 }
61347
61348 req->FileIndex = cpu_to_le32(index);
61349diff --git a/fs/coda/cache.c b/fs/coda/cache.c
61350index 1da168c..8bc7ff6 100644
61351--- a/fs/coda/cache.c
61352+++ b/fs/coda/cache.c
61353@@ -24,7 +24,7 @@
61354 #include "coda_linux.h"
61355 #include "coda_cache.h"
61356
61357-static atomic_t permission_epoch = ATOMIC_INIT(0);
61358+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
61359
61360 /* replace or extend an acl cache hit */
61361 void coda_cache_enter(struct inode *inode, int mask)
61362@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
61363 struct coda_inode_info *cii = ITOC(inode);
61364
61365 spin_lock(&cii->c_lock);
61366- cii->c_cached_epoch = atomic_read(&permission_epoch);
61367+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
61368 if (!uid_eq(cii->c_uid, current_fsuid())) {
61369 cii->c_uid = current_fsuid();
61370 cii->c_cached_perm = mask;
61371@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
61372 {
61373 struct coda_inode_info *cii = ITOC(inode);
61374 spin_lock(&cii->c_lock);
61375- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
61376+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
61377 spin_unlock(&cii->c_lock);
61378 }
61379
61380 /* remove all acl caches */
61381 void coda_cache_clear_all(struct super_block *sb)
61382 {
61383- atomic_inc(&permission_epoch);
61384+ atomic_inc_unchecked(&permission_epoch);
61385 }
61386
61387
61388@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
61389 spin_lock(&cii->c_lock);
61390 hit = (mask & cii->c_cached_perm) == mask &&
61391 uid_eq(cii->c_uid, current_fsuid()) &&
61392- cii->c_cached_epoch == atomic_read(&permission_epoch);
61393+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
61394 spin_unlock(&cii->c_lock);
61395
61396 return hit;
61397diff --git a/fs/compat.c b/fs/compat.c
61398index 66d3d3c..9c10175 100644
61399--- a/fs/compat.c
61400+++ b/fs/compat.c
61401@@ -54,7 +54,7 @@
61402 #include <asm/ioctls.h>
61403 #include "internal.h"
61404
61405-int compat_log = 1;
61406+int compat_log = 0;
61407
61408 int compat_printk(const char *fmt, ...)
61409 {
61410@@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
61411
61412 set_fs(KERNEL_DS);
61413 /* The __user pointer cast is valid because of the set_fs() */
61414- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
61415+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
61416 set_fs(oldfs);
61417 /* truncating is ok because it's a user address */
61418 if (!ret)
61419@@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
61420 goto out;
61421
61422 ret = -EINVAL;
61423- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
61424+ if (nr_segs > UIO_MAXIOV)
61425 goto out;
61426 if (nr_segs > fast_segs) {
61427 ret = -ENOMEM;
61428@@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
61429 struct compat_readdir_callback {
61430 struct dir_context ctx;
61431 struct compat_old_linux_dirent __user *dirent;
61432+ struct file * file;
61433 int result;
61434 };
61435
61436@@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
61437 buf->result = -EOVERFLOW;
61438 return -EOVERFLOW;
61439 }
61440+
61441+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61442+ return 0;
61443+
61444 buf->result++;
61445 dirent = buf->dirent;
61446 if (!access_ok(VERIFY_WRITE, dirent,
61447@@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
61448 if (!f.file)
61449 return -EBADF;
61450
61451+ buf.file = f.file;
61452 error = iterate_dir(f.file, &buf.ctx);
61453 if (buf.result)
61454 error = buf.result;
61455@@ -917,6 +923,7 @@ struct compat_getdents_callback {
61456 struct dir_context ctx;
61457 struct compat_linux_dirent __user *current_dir;
61458 struct compat_linux_dirent __user *previous;
61459+ struct file * file;
61460 int count;
61461 int error;
61462 };
61463@@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
61464 buf->error = -EOVERFLOW;
61465 return -EOVERFLOW;
61466 }
61467+
61468+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61469+ return 0;
61470+
61471 dirent = buf->previous;
61472 if (dirent) {
61473 if (__put_user(offset, &dirent->d_off))
61474@@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
61475 if (!f.file)
61476 return -EBADF;
61477
61478+ buf.file = f.file;
61479 error = iterate_dir(f.file, &buf.ctx);
61480 if (error >= 0)
61481 error = buf.error;
61482@@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
61483 struct dir_context ctx;
61484 struct linux_dirent64 __user *current_dir;
61485 struct linux_dirent64 __user *previous;
61486+ struct file * file;
61487 int count;
61488 int error;
61489 };
61490@@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
61491 buf->error = -EINVAL; /* only used if we fail.. */
61492 if (reclen > buf->count)
61493 return -EINVAL;
61494+
61495+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61496+ return 0;
61497+
61498 dirent = buf->previous;
61499
61500 if (dirent) {
61501@@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
61502 if (!f.file)
61503 return -EBADF;
61504
61505+ buf.file = f.file;
61506 error = iterate_dir(f.file, &buf.ctx);
61507 if (error >= 0)
61508 error = buf.error;
61509diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
61510index 4d24d17..4f8c09e 100644
61511--- a/fs/compat_binfmt_elf.c
61512+++ b/fs/compat_binfmt_elf.c
61513@@ -30,11 +30,13 @@
61514 #undef elf_phdr
61515 #undef elf_shdr
61516 #undef elf_note
61517+#undef elf_dyn
61518 #undef elf_addr_t
61519 #define elfhdr elf32_hdr
61520 #define elf_phdr elf32_phdr
61521 #define elf_shdr elf32_shdr
61522 #define elf_note elf32_note
61523+#define elf_dyn Elf32_Dyn
61524 #define elf_addr_t Elf32_Addr
61525
61526 /*
61527diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
61528index e822890..fed89d9 100644
61529--- a/fs/compat_ioctl.c
61530+++ b/fs/compat_ioctl.c
61531@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
61532 return -EFAULT;
61533 if (__get_user(udata, &ss32->iomem_base))
61534 return -EFAULT;
61535- ss.iomem_base = compat_ptr(udata);
61536+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
61537 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
61538 __get_user(ss.port_high, &ss32->port_high))
61539 return -EFAULT;
61540@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
61541 for (i = 0; i < nmsgs; i++) {
61542 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
61543 return -EFAULT;
61544- if (get_user(datap, &umsgs[i].buf) ||
61545- put_user(compat_ptr(datap), &tmsgs[i].buf))
61546+ if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
61547+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
61548 return -EFAULT;
61549 }
61550 return sys_ioctl(fd, cmd, (unsigned long)tdata);
61551@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
61552 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
61553 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
61554 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
61555- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
61556+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
61557 return -EFAULT;
61558
61559 return ioctl_preallocate(file, p);
61560@@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
61561 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
61562 {
61563 unsigned int a, b;
61564- a = *(unsigned int *)p;
61565- b = *(unsigned int *)q;
61566+ a = *(const unsigned int *)p;
61567+ b = *(const unsigned int *)q;
61568 if (a > b)
61569 return 1;
61570 if (a < b)
61571diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
61572index 668dcab..daebcd6 100644
61573--- a/fs/configfs/dir.c
61574+++ b/fs/configfs/dir.c
61575@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
61576 }
61577 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
61578 struct configfs_dirent *next;
61579- const char *name;
61580+ const unsigned char * name;
61581+ char d_name[sizeof(next->s_dentry->d_iname)];
61582 int len;
61583 struct inode *inode = NULL;
61584
61585@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
61586 continue;
61587
61588 name = configfs_get_name(next);
61589- len = strlen(name);
61590+ if (next->s_dentry && name == next->s_dentry->d_iname) {
61591+ len = next->s_dentry->d_name.len;
61592+ memcpy(d_name, name, len);
61593+ name = d_name;
61594+ } else
61595+ len = strlen(name);
61596
61597 /*
61598 * We'll have a dentry and an inode for
61599diff --git a/fs/coredump.c b/fs/coredump.c
61600index a93f7e6..d58bcbe 100644
61601--- a/fs/coredump.c
61602+++ b/fs/coredump.c
61603@@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
61604 struct pipe_inode_info *pipe = file->private_data;
61605
61606 pipe_lock(pipe);
61607- pipe->readers++;
61608- pipe->writers--;
61609+ atomic_inc(&pipe->readers);
61610+ atomic_dec(&pipe->writers);
61611 wake_up_interruptible_sync(&pipe->wait);
61612 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61613 pipe_unlock(pipe);
61614@@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
61615 * We actually want wait_event_freezable() but then we need
61616 * to clear TIF_SIGPENDING and improve dump_interrupted().
61617 */
61618- wait_event_interruptible(pipe->wait, pipe->readers == 1);
61619+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
61620
61621 pipe_lock(pipe);
61622- pipe->readers--;
61623- pipe->writers++;
61624+ atomic_dec(&pipe->readers);
61625+ atomic_inc(&pipe->writers);
61626 pipe_unlock(pipe);
61627 }
61628
61629@@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
61630 struct files_struct *displaced;
61631 bool need_nonrelative = false;
61632 bool core_dumped = false;
61633- static atomic_t core_dump_count = ATOMIC_INIT(0);
61634+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
61635+ long signr = siginfo->si_signo;
61636+ int dumpable;
61637 struct coredump_params cprm = {
61638 .siginfo = siginfo,
61639 .regs = signal_pt_regs(),
61640@@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
61641 .mm_flags = mm->flags,
61642 };
61643
61644- audit_core_dumps(siginfo->si_signo);
61645+ audit_core_dumps(signr);
61646+
61647+ dumpable = __get_dumpable(cprm.mm_flags);
61648+
61649+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
61650+ gr_handle_brute_attach(dumpable);
61651
61652 binfmt = mm->binfmt;
61653 if (!binfmt || !binfmt->core_dump)
61654 goto fail;
61655- if (!__get_dumpable(cprm.mm_flags))
61656+ if (!dumpable)
61657 goto fail;
61658
61659 cred = prepare_creds();
61660@@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
61661 need_nonrelative = true;
61662 }
61663
61664- retval = coredump_wait(siginfo->si_signo, &core_state);
61665+ retval = coredump_wait(signr, &core_state);
61666 if (retval < 0)
61667 goto fail_creds;
61668
61669@@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
61670 }
61671 cprm.limit = RLIM_INFINITY;
61672
61673- dump_count = atomic_inc_return(&core_dump_count);
61674+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
61675 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
61676 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
61677 task_tgid_vnr(current), current->comm);
61678@@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
61679 } else {
61680 struct inode *inode;
61681
61682+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
61683+
61684 if (cprm.limit < binfmt->min_coredump)
61685 goto fail_unlock;
61686
61687@@ -673,7 +682,7 @@ close_fail:
61688 filp_close(cprm.file, NULL);
61689 fail_dropcount:
61690 if (ispipe)
61691- atomic_dec(&core_dump_count);
61692+ atomic_dec_unchecked(&core_dump_count);
61693 fail_unlock:
61694 kfree(cn.corename);
61695 coredump_finish(mm, core_dumped);
61696@@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
61697 struct file *file = cprm->file;
61698 loff_t pos = file->f_pos;
61699 ssize_t n;
61700+
61701+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
61702 if (cprm->written + nr > cprm->limit)
61703 return 0;
61704 while (nr) {
61705diff --git a/fs/dcache.c b/fs/dcache.c
61706index 06f6585..f95a6d1 100644
61707--- a/fs/dcache.c
61708+++ b/fs/dcache.c
61709@@ -1445,7 +1445,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
61710 */
61711 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
61712 if (name->len > DNAME_INLINE_LEN-1) {
61713- dname = kmalloc(name->len + 1, GFP_KERNEL);
61714+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
61715 if (!dname) {
61716 kmem_cache_free(dentry_cache, dentry);
61717 return NULL;
61718@@ -3413,7 +3413,8 @@ void __init vfs_caches_init(unsigned long mempages)
61719 mempages -= reserve;
61720
61721 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
61722- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
61723+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
61724+ SLAB_NO_SANITIZE, NULL);
61725
61726 dcache_init();
61727 inode_init();
61728diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
61729index 8c41b52..145b1b9 100644
61730--- a/fs/debugfs/inode.c
61731+++ b/fs/debugfs/inode.c
61732@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
61733 */
61734 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
61735 {
61736+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
61737+ return __create_file(name, S_IFDIR | S_IRWXU,
61738+#else
61739 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
61740+#endif
61741 parent, NULL, NULL);
61742 }
61743 EXPORT_SYMBOL_GPL(debugfs_create_dir);
61744diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
61745index d4a9431..77f9b2e 100644
61746--- a/fs/ecryptfs/inode.c
61747+++ b/fs/ecryptfs/inode.c
61748@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
61749 old_fs = get_fs();
61750 set_fs(get_ds());
61751 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
61752- (char __user *)lower_buf,
61753+ (char __force_user *)lower_buf,
61754 PATH_MAX);
61755 set_fs(old_fs);
61756 if (rc < 0)
61757diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
61758index e4141f2..d8263e8 100644
61759--- a/fs/ecryptfs/miscdev.c
61760+++ b/fs/ecryptfs/miscdev.c
61761@@ -304,7 +304,7 @@ check_list:
61762 goto out_unlock_msg_ctx;
61763 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
61764 if (msg_ctx->msg) {
61765- if (copy_to_user(&buf[i], packet_length, packet_length_size))
61766+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
61767 goto out_unlock_msg_ctx;
61768 i += packet_length_size;
61769 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
61770diff --git a/fs/exec.c b/fs/exec.c
61771index a3d33fe..49e9bc9 100644
61772--- a/fs/exec.c
61773+++ b/fs/exec.c
61774@@ -56,8 +56,20 @@
61775 #include <linux/pipe_fs_i.h>
61776 #include <linux/oom.h>
61777 #include <linux/compat.h>
61778+#include <linux/random.h>
61779+#include <linux/seq_file.h>
61780+#include <linux/coredump.h>
61781+#include <linux/mman.h>
61782+
61783+#ifdef CONFIG_PAX_REFCOUNT
61784+#include <linux/kallsyms.h>
61785+#include <linux/kdebug.h>
61786+#endif
61787+
61788+#include <trace/events/fs.h>
61789
61790 #include <asm/uaccess.h>
61791+#include <asm/sections.h>
61792 #include <asm/mmu_context.h>
61793 #include <asm/tlb.h>
61794
61795@@ -66,19 +78,34 @@
61796
61797 #include <trace/events/sched.h>
61798
61799+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61800+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
61801+{
61802+ pr_warn_once("PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
61803+}
61804+#endif
61805+
61806+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
61807+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
61808+EXPORT_SYMBOL(pax_set_initial_flags_func);
61809+#endif
61810+
61811 int suid_dumpable = 0;
61812
61813 static LIST_HEAD(formats);
61814 static DEFINE_RWLOCK(binfmt_lock);
61815
61816+extern int gr_process_kernel_exec_ban(void);
61817+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
61818+
61819 void __register_binfmt(struct linux_binfmt * fmt, int insert)
61820 {
61821 BUG_ON(!fmt);
61822 if (WARN_ON(!fmt->load_binary))
61823 return;
61824 write_lock(&binfmt_lock);
61825- insert ? list_add(&fmt->lh, &formats) :
61826- list_add_tail(&fmt->lh, &formats);
61827+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
61828+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
61829 write_unlock(&binfmt_lock);
61830 }
61831
61832@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
61833 void unregister_binfmt(struct linux_binfmt * fmt)
61834 {
61835 write_lock(&binfmt_lock);
61836- list_del(&fmt->lh);
61837+ pax_list_del((struct list_head *)&fmt->lh);
61838 write_unlock(&binfmt_lock);
61839 }
61840
61841@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61842 int write)
61843 {
61844 struct page *page;
61845- int ret;
61846
61847-#ifdef CONFIG_STACK_GROWSUP
61848- if (write) {
61849- ret = expand_downwards(bprm->vma, pos);
61850- if (ret < 0)
61851- return NULL;
61852- }
61853-#endif
61854- ret = get_user_pages(current, bprm->mm, pos,
61855- 1, write, 1, &page, NULL);
61856- if (ret <= 0)
61857+ if (0 > expand_downwards(bprm->vma, pos))
61858+ return NULL;
61859+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61860 return NULL;
61861
61862 if (write) {
61863@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61864 if (size <= ARG_MAX)
61865 return page;
61866
61867+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61868+ // only allow 512KB for argv+env on suid/sgid binaries
61869+ // to prevent easy ASLR exhaustion
61870+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61871+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
61872+ (size > (512 * 1024))) {
61873+ put_page(page);
61874+ return NULL;
61875+ }
61876+#endif
61877+
61878 /*
61879 * Limit to 1/4-th the stack size for the argv+env strings.
61880 * This ensures that:
61881@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61882 vma->vm_end = STACK_TOP_MAX;
61883 vma->vm_start = vma->vm_end - PAGE_SIZE;
61884 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61885+
61886+#ifdef CONFIG_PAX_SEGMEXEC
61887+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61888+#endif
61889+
61890 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61891 INIT_LIST_HEAD(&vma->anon_vma_chain);
61892
61893@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61894 mm->stack_vm = mm->total_vm = 1;
61895 up_write(&mm->mmap_sem);
61896 bprm->p = vma->vm_end - sizeof(void *);
61897+
61898+#ifdef CONFIG_PAX_RANDUSTACK
61899+ if (randomize_va_space)
61900+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
61901+#endif
61902+
61903 return 0;
61904 err:
61905 up_write(&mm->mmap_sem);
61906@@ -399,7 +440,7 @@ struct user_arg_ptr {
61907 } ptr;
61908 };
61909
61910-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61911+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61912 {
61913 const char __user *native;
61914
61915@@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61916 compat_uptr_t compat;
61917
61918 if (get_user(compat, argv.ptr.compat + nr))
61919- return ERR_PTR(-EFAULT);
61920+ return (const char __force_user *)ERR_PTR(-EFAULT);
61921
61922 return compat_ptr(compat);
61923 }
61924 #endif
61925
61926 if (get_user(native, argv.ptr.native + nr))
61927- return ERR_PTR(-EFAULT);
61928+ return (const char __force_user *)ERR_PTR(-EFAULT);
61929
61930 return native;
61931 }
61932@@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
61933 if (!p)
61934 break;
61935
61936- if (IS_ERR(p))
61937+ if (IS_ERR((const char __force_kernel *)p))
61938 return -EFAULT;
61939
61940 if (i >= max)
61941@@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61942
61943 ret = -EFAULT;
61944 str = get_user_arg_ptr(argv, argc);
61945- if (IS_ERR(str))
61946+ if (IS_ERR((const char __force_kernel *)str))
61947 goto out;
61948
61949 len = strnlen_user(str, MAX_ARG_STRLEN);
61950@@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61951 int r;
61952 mm_segment_t oldfs = get_fs();
61953 struct user_arg_ptr argv = {
61954- .ptr.native = (const char __user *const __user *)__argv,
61955+ .ptr.native = (const char __user * const __force_user *)__argv,
61956 };
61957
61958 set_fs(KERNEL_DS);
61959@@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61960 unsigned long new_end = old_end - shift;
61961 struct mmu_gather tlb;
61962
61963- BUG_ON(new_start > new_end);
61964+ if (new_start >= new_end || new_start < mmap_min_addr)
61965+ return -ENOMEM;
61966
61967 /*
61968 * ensure there are no vmas between where we want to go
61969@@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61970 if (vma != find_vma(mm, new_start))
61971 return -EFAULT;
61972
61973+#ifdef CONFIG_PAX_SEGMEXEC
61974+ BUG_ON(pax_find_mirror_vma(vma));
61975+#endif
61976+
61977 /*
61978 * cover the whole range: [new_start, old_end)
61979 */
61980@@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61981 stack_top = arch_align_stack(stack_top);
61982 stack_top = PAGE_ALIGN(stack_top);
61983
61984- if (unlikely(stack_top < mmap_min_addr) ||
61985- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61986- return -ENOMEM;
61987-
61988 stack_shift = vma->vm_end - stack_top;
61989
61990 bprm->p -= stack_shift;
61991@@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61992 bprm->exec -= stack_shift;
61993
61994 down_write(&mm->mmap_sem);
61995+
61996+ /* Move stack pages down in memory. */
61997+ if (stack_shift) {
61998+ ret = shift_arg_pages(vma, stack_shift);
61999+ if (ret)
62000+ goto out_unlock;
62001+ }
62002+
62003 vm_flags = VM_STACK_FLAGS;
62004
62005+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
62006+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
62007+ vm_flags &= ~VM_EXEC;
62008+
62009+#ifdef CONFIG_PAX_MPROTECT
62010+ if (mm->pax_flags & MF_PAX_MPROTECT)
62011+ vm_flags &= ~VM_MAYEXEC;
62012+#endif
62013+
62014+ }
62015+#endif
62016+
62017 /*
62018 * Adjust stack execute permissions; explicitly enable for
62019 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
62020@@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
62021 goto out_unlock;
62022 BUG_ON(prev != vma);
62023
62024- /* Move stack pages down in memory. */
62025- if (stack_shift) {
62026- ret = shift_arg_pages(vma, stack_shift);
62027- if (ret)
62028- goto out_unlock;
62029- }
62030-
62031 /* mprotect_fixup is overkill to remove the temporary stack flags */
62032 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
62033
62034@@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
62035 #endif
62036 current->mm->start_stack = bprm->p;
62037 ret = expand_stack(vma, stack_base);
62038+
62039+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
62040+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
62041+ unsigned long size;
62042+ vm_flags_t vm_flags;
62043+
62044+ size = STACK_TOP - vma->vm_end;
62045+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
62046+
62047+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
62048+
62049+#ifdef CONFIG_X86
62050+ if (!ret) {
62051+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
62052+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
62053+ }
62054+#endif
62055+
62056+ }
62057+#endif
62058+
62059 if (ret)
62060 ret = -EFAULT;
62061
62062@@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
62063
62064 fsnotify_open(file);
62065
62066+ trace_open_exec(name->name);
62067+
62068 err = deny_write_access(file);
62069 if (err)
62070 goto exit;
62071@@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
62072 old_fs = get_fs();
62073 set_fs(get_ds());
62074 /* The cast to a user pointer is valid due to the set_fs() */
62075- result = vfs_read(file, (void __user *)addr, count, &pos);
62076+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
62077 set_fs(old_fs);
62078 return result;
62079 }
62080@@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
62081 tsk->mm = mm;
62082 tsk->active_mm = mm;
62083 activate_mm(active_mm, mm);
62084+ populate_stack();
62085 tsk->mm->vmacache_seqnum = 0;
62086 vmacache_flush(tsk);
62087 task_unlock(tsk);
62088@@ -1247,7 +1326,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
62089 }
62090 rcu_read_unlock();
62091
62092- if (p->fs->users > n_fs)
62093+ if (atomic_read(&p->fs->users) > n_fs)
62094 bprm->unsafe |= LSM_UNSAFE_SHARE;
62095 else
62096 p->fs->in_exec = 1;
62097@@ -1423,6 +1502,31 @@ static int exec_binprm(struct linux_binprm *bprm)
62098 return ret;
62099 }
62100
62101+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62102+static DEFINE_PER_CPU(u64, exec_counter);
62103+static int __init init_exec_counters(void)
62104+{
62105+ unsigned int cpu;
62106+
62107+ for_each_possible_cpu(cpu) {
62108+ per_cpu(exec_counter, cpu) = (u64)cpu;
62109+ }
62110+
62111+ return 0;
62112+}
62113+early_initcall(init_exec_counters);
62114+static inline void increment_exec_counter(void)
62115+{
62116+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
62117+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
62118+}
62119+#else
62120+static inline void increment_exec_counter(void) {}
62121+#endif
62122+
62123+extern void gr_handle_exec_args(struct linux_binprm *bprm,
62124+ struct user_arg_ptr argv);
62125+
62126 /*
62127 * sys_execve() executes a new program.
62128 */
62129@@ -1430,6 +1534,11 @@ static int do_execve_common(struct filename *filename,
62130 struct user_arg_ptr argv,
62131 struct user_arg_ptr envp)
62132 {
62133+#ifdef CONFIG_GRKERNSEC
62134+ struct file *old_exec_file;
62135+ struct acl_subject_label *old_acl;
62136+ struct rlimit old_rlim[RLIM_NLIMITS];
62137+#endif
62138 struct linux_binprm *bprm;
62139 struct file *file;
62140 struct files_struct *displaced;
62141@@ -1438,6 +1547,8 @@ static int do_execve_common(struct filename *filename,
62142 if (IS_ERR(filename))
62143 return PTR_ERR(filename);
62144
62145+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
62146+
62147 /*
62148 * We move the actual failure in case of RLIMIT_NPROC excess from
62149 * set*uid() to execve() because too many poorly written programs
62150@@ -1475,11 +1586,21 @@ static int do_execve_common(struct filename *filename,
62151 if (IS_ERR(file))
62152 goto out_unmark;
62153
62154+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
62155+ retval = -EPERM;
62156+ goto out_unmark;
62157+ }
62158+
62159 sched_exec();
62160
62161 bprm->file = file;
62162 bprm->filename = bprm->interp = filename->name;
62163
62164+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
62165+ retval = -EACCES;
62166+ goto out_unmark;
62167+ }
62168+
62169 retval = bprm_mm_init(bprm);
62170 if (retval)
62171 goto out_unmark;
62172@@ -1496,24 +1617,70 @@ static int do_execve_common(struct filename *filename,
62173 if (retval < 0)
62174 goto out;
62175
62176+#ifdef CONFIG_GRKERNSEC
62177+ old_acl = current->acl;
62178+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
62179+ old_exec_file = current->exec_file;
62180+ get_file(file);
62181+ current->exec_file = file;
62182+#endif
62183+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62184+ /* limit suid stack to 8MB
62185+ * we saved the old limits above and will restore them if this exec fails
62186+ */
62187+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
62188+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
62189+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
62190+#endif
62191+
62192+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
62193+ retval = -EPERM;
62194+ goto out_fail;
62195+ }
62196+
62197+ if (!gr_tpe_allow(file)) {
62198+ retval = -EACCES;
62199+ goto out_fail;
62200+ }
62201+
62202+ if (gr_check_crash_exec(file)) {
62203+ retval = -EACCES;
62204+ goto out_fail;
62205+ }
62206+
62207+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
62208+ bprm->unsafe);
62209+ if (retval < 0)
62210+ goto out_fail;
62211+
62212 retval = copy_strings_kernel(1, &bprm->filename, bprm);
62213 if (retval < 0)
62214- goto out;
62215+ goto out_fail;
62216
62217 bprm->exec = bprm->p;
62218 retval = copy_strings(bprm->envc, envp, bprm);
62219 if (retval < 0)
62220- goto out;
62221+ goto out_fail;
62222
62223 retval = copy_strings(bprm->argc, argv, bprm);
62224 if (retval < 0)
62225- goto out;
62226+ goto out_fail;
62227+
62228+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
62229+
62230+ gr_handle_exec_args(bprm, argv);
62231
62232 retval = exec_binprm(bprm);
62233 if (retval < 0)
62234- goto out;
62235+ goto out_fail;
62236+#ifdef CONFIG_GRKERNSEC
62237+ if (old_exec_file)
62238+ fput(old_exec_file);
62239+#endif
62240
62241 /* execve succeeded */
62242+
62243+ increment_exec_counter();
62244 current->fs->in_exec = 0;
62245 current->in_execve = 0;
62246 acct_update_integrals(current);
62247@@ -1524,6 +1691,14 @@ static int do_execve_common(struct filename *filename,
62248 put_files_struct(displaced);
62249 return retval;
62250
62251+out_fail:
62252+#ifdef CONFIG_GRKERNSEC
62253+ current->acl = old_acl;
62254+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
62255+ fput(current->exec_file);
62256+ current->exec_file = old_exec_file;
62257+#endif
62258+
62259 out:
62260 if (bprm->mm) {
62261 acct_arg_size(bprm, 0);
62262@@ -1615,3 +1790,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
62263 return compat_do_execve(getname(filename), argv, envp);
62264 }
62265 #endif
62266+
62267+int pax_check_flags(unsigned long *flags)
62268+{
62269+ int retval = 0;
62270+
62271+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
62272+ if (*flags & MF_PAX_SEGMEXEC)
62273+ {
62274+ *flags &= ~MF_PAX_SEGMEXEC;
62275+ retval = -EINVAL;
62276+ }
62277+#endif
62278+
62279+ if ((*flags & MF_PAX_PAGEEXEC)
62280+
62281+#ifdef CONFIG_PAX_PAGEEXEC
62282+ && (*flags & MF_PAX_SEGMEXEC)
62283+#endif
62284+
62285+ )
62286+ {
62287+ *flags &= ~MF_PAX_PAGEEXEC;
62288+ retval = -EINVAL;
62289+ }
62290+
62291+ if ((*flags & MF_PAX_MPROTECT)
62292+
62293+#ifdef CONFIG_PAX_MPROTECT
62294+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
62295+#endif
62296+
62297+ )
62298+ {
62299+ *flags &= ~MF_PAX_MPROTECT;
62300+ retval = -EINVAL;
62301+ }
62302+
62303+ if ((*flags & MF_PAX_EMUTRAMP)
62304+
62305+#ifdef CONFIG_PAX_EMUTRAMP
62306+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
62307+#endif
62308+
62309+ )
62310+ {
62311+ *flags &= ~MF_PAX_EMUTRAMP;
62312+ retval = -EINVAL;
62313+ }
62314+
62315+ return retval;
62316+}
62317+
62318+EXPORT_SYMBOL(pax_check_flags);
62319+
62320+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
62321+char *pax_get_path(const struct path *path, char *buf, int buflen)
62322+{
62323+ char *pathname = d_path(path, buf, buflen);
62324+
62325+ if (IS_ERR(pathname))
62326+ goto toolong;
62327+
62328+ pathname = mangle_path(buf, pathname, "\t\n\\");
62329+ if (!pathname)
62330+ goto toolong;
62331+
62332+ *pathname = 0;
62333+ return buf;
62334+
62335+toolong:
62336+ return "<path too long>";
62337+}
62338+EXPORT_SYMBOL(pax_get_path);
62339+
62340+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
62341+{
62342+ struct task_struct *tsk = current;
62343+ struct mm_struct *mm = current->mm;
62344+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
62345+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
62346+ char *path_exec = NULL;
62347+ char *path_fault = NULL;
62348+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
62349+ siginfo_t info = { };
62350+
62351+ if (buffer_exec && buffer_fault) {
62352+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
62353+
62354+ down_read(&mm->mmap_sem);
62355+ vma = mm->mmap;
62356+ while (vma && (!vma_exec || !vma_fault)) {
62357+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
62358+ vma_exec = vma;
62359+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
62360+ vma_fault = vma;
62361+ vma = vma->vm_next;
62362+ }
62363+ if (vma_exec)
62364+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
62365+ if (vma_fault) {
62366+ start = vma_fault->vm_start;
62367+ end = vma_fault->vm_end;
62368+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
62369+ if (vma_fault->vm_file)
62370+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
62371+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
62372+ path_fault = "<heap>";
62373+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
62374+ path_fault = "<stack>";
62375+ else
62376+ path_fault = "<anonymous mapping>";
62377+ }
62378+ up_read(&mm->mmap_sem);
62379+ }
62380+ if (tsk->signal->curr_ip)
62381+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
62382+ else
62383+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
62384+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
62385+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
62386+ free_page((unsigned long)buffer_exec);
62387+ free_page((unsigned long)buffer_fault);
62388+ pax_report_insns(regs, pc, sp);
62389+ info.si_signo = SIGKILL;
62390+ info.si_errno = 0;
62391+ info.si_code = SI_KERNEL;
62392+ info.si_pid = 0;
62393+ info.si_uid = 0;
62394+ do_coredump(&info);
62395+}
62396+#endif
62397+
62398+#ifdef CONFIG_PAX_REFCOUNT
62399+void pax_report_refcount_overflow(struct pt_regs *regs)
62400+{
62401+ if (current->signal->curr_ip)
62402+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
62403+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
62404+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
62405+ else
62406+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
62407+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
62408+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
62409+ preempt_disable();
62410+ show_regs(regs);
62411+ preempt_enable();
62412+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
62413+}
62414+#endif
62415+
62416+#ifdef CONFIG_PAX_USERCOPY
62417+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
62418+static noinline int check_stack_object(const void *obj, unsigned long len)
62419+{
62420+ const void * const stack = task_stack_page(current);
62421+ const void * const stackend = stack + THREAD_SIZE;
62422+
62423+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
62424+ const void *frame = NULL;
62425+ const void *oldframe;
62426+#endif
62427+
62428+ if (obj + len < obj)
62429+ return -1;
62430+
62431+ if (obj + len <= stack || stackend <= obj)
62432+ return 0;
62433+
62434+ if (obj < stack || stackend < obj + len)
62435+ return -1;
62436+
62437+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
62438+ oldframe = __builtin_frame_address(1);
62439+ if (oldframe)
62440+ frame = __builtin_frame_address(2);
62441+ /*
62442+ low ----------------------------------------------> high
62443+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
62444+ ^----------------^
62445+ allow copies only within here
62446+ */
62447+ while (stack <= frame && frame < stackend) {
62448+ /* if obj + len extends past the last frame, this
62449+ check won't pass and the next frame will be 0,
62450+ causing us to bail out and correctly report
62451+ the copy as invalid
62452+ */
62453+ if (obj + len <= frame)
62454+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
62455+ oldframe = frame;
62456+ frame = *(const void * const *)frame;
62457+ }
62458+ return -1;
62459+#else
62460+ return 1;
62461+#endif
62462+}
62463+
62464+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
62465+{
62466+ if (current->signal->curr_ip)
62467+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
62468+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
62469+ else
62470+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
62471+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
62472+ dump_stack();
62473+ gr_handle_kernel_exploit();
62474+ do_group_exit(SIGKILL);
62475+}
62476+#endif
62477+
62478+#ifdef CONFIG_PAX_USERCOPY
62479+
62480+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
62481+{
62482+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
62483+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
62484+#ifdef CONFIG_MODULES
62485+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
62486+#else
62487+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
62488+#endif
62489+
62490+#else
62491+ unsigned long textlow = (unsigned long)_stext;
62492+ unsigned long texthigh = (unsigned long)_etext;
62493+
62494+#ifdef CONFIG_X86_64
62495+ /* check against linear mapping as well */
62496+ if (high > (unsigned long)__va(__pa(textlow)) &&
62497+ low < (unsigned long)__va(__pa(texthigh)))
62498+ return true;
62499+#endif
62500+
62501+#endif
62502+
62503+ if (high <= textlow || low >= texthigh)
62504+ return false;
62505+ else
62506+ return true;
62507+}
62508+#endif
62509+
62510+void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
62511+{
62512+#ifdef CONFIG_PAX_USERCOPY
62513+ const char *type;
62514+#endif
62515+
62516+#ifndef CONFIG_STACK_GROWSUP
62517+ unsigned long stackstart = (unsigned long)task_stack_page(current);
62518+ unsigned long currentsp = (unsigned long)&stackstart;
62519+ if (unlikely((currentsp < stackstart + 512 ||
62520+ currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
62521+ BUG();
62522+#endif
62523+
62524+#ifndef CONFIG_PAX_USERCOPY_DEBUG
62525+ if (const_size)
62526+ return;
62527+#endif
62528+
62529+#ifdef CONFIG_PAX_USERCOPY
62530+ if (!n)
62531+ return;
62532+
62533+ type = check_heap_object(ptr, n);
62534+ if (!type) {
62535+ int ret = check_stack_object(ptr, n);
62536+ if (ret == 1 || ret == 2)
62537+ return;
62538+ if (ret == 0) {
62539+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
62540+ type = "<kernel text>";
62541+ else
62542+ return;
62543+ } else
62544+ type = "<process stack>";
62545+ }
62546+
62547+ pax_report_usercopy(ptr, n, to_user, type);
62548+#endif
62549+
62550+}
62551+EXPORT_SYMBOL(__check_object_size);
62552+
62553+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
62554+void pax_track_stack(void)
62555+{
62556+ unsigned long sp = (unsigned long)&sp;
62557+ if (sp < current_thread_info()->lowest_stack &&
62558+ sp > (unsigned long)task_stack_page(current))
62559+ current_thread_info()->lowest_stack = sp;
62560+ if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
62561+ BUG();
62562+}
62563+EXPORT_SYMBOL(pax_track_stack);
62564+#endif
62565+
62566+#ifdef CONFIG_PAX_SIZE_OVERFLOW
62567+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
62568+{
62569+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
62570+ dump_stack();
62571+ do_group_exit(SIGKILL);
62572+}
62573+EXPORT_SYMBOL(report_size_overflow);
62574+#endif
62575diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
62576index 9f9992b..8b59411 100644
62577--- a/fs/ext2/balloc.c
62578+++ b/fs/ext2/balloc.c
62579@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
62580
62581 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62582 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62583- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62584+ if (free_blocks < root_blocks + 1 &&
62585 !uid_eq(sbi->s_resuid, current_fsuid()) &&
62586 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62587- !in_group_p (sbi->s_resgid))) {
62588+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62589 return 0;
62590 }
62591 return 1;
62592diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
62593index 9142614..97484fa 100644
62594--- a/fs/ext2/xattr.c
62595+++ b/fs/ext2/xattr.c
62596@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
62597 struct buffer_head *bh = NULL;
62598 struct ext2_xattr_entry *entry;
62599 char *end;
62600- size_t rest = buffer_size;
62601+ size_t rest = buffer_size, total_size = 0;
62602 int error;
62603
62604 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
62605@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
62606 buffer += size;
62607 }
62608 rest -= size;
62609+ total_size += size;
62610 }
62611 }
62612- error = buffer_size - rest; /* total size */
62613+ error = total_size;
62614
62615 cleanup:
62616 brelse(bh);
62617diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
62618index 158b5d4..2432610 100644
62619--- a/fs/ext3/balloc.c
62620+++ b/fs/ext3/balloc.c
62621@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
62622
62623 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62624 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62625- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62626+ if (free_blocks < root_blocks + 1 &&
62627 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
62628 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62629- !in_group_p (sbi->s_resgid))) {
62630+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62631 return 0;
62632 }
62633 return 1;
62634diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
62635index c6874be..f8a6ae8 100644
62636--- a/fs/ext3/xattr.c
62637+++ b/fs/ext3/xattr.c
62638@@ -330,7 +330,7 @@ static int
62639 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62640 char *buffer, size_t buffer_size)
62641 {
62642- size_t rest = buffer_size;
62643+ size_t rest = buffer_size, total_size = 0;
62644
62645 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
62646 const struct xattr_handler *handler =
62647@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62648 buffer += size;
62649 }
62650 rest -= size;
62651+ total_size += size;
62652 }
62653 }
62654- return buffer_size - rest;
62655+ return total_size;
62656 }
62657
62658 static int
62659diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
62660index fca3820..e1ea241 100644
62661--- a/fs/ext4/balloc.c
62662+++ b/fs/ext4/balloc.c
62663@@ -553,8 +553,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
62664 /* Hm, nope. Are (enough) root reserved clusters available? */
62665 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
62666 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
62667- capable(CAP_SYS_RESOURCE) ||
62668- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
62669+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
62670+ capable_nolog(CAP_SYS_RESOURCE)) {
62671
62672 if (free_clusters >= (nclusters + dirty_clusters +
62673 resv_clusters))
62674diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
62675index 7cc5a0e..851f176 100644
62676--- a/fs/ext4/ext4.h
62677+++ b/fs/ext4/ext4.h
62678@@ -1276,19 +1276,19 @@ struct ext4_sb_info {
62679 unsigned long s_mb_last_start;
62680
62681 /* stats for buddy allocator */
62682- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
62683- atomic_t s_bal_success; /* we found long enough chunks */
62684- atomic_t s_bal_allocated; /* in blocks */
62685- atomic_t s_bal_ex_scanned; /* total extents scanned */
62686- atomic_t s_bal_goals; /* goal hits */
62687- atomic_t s_bal_breaks; /* too long searches */
62688- atomic_t s_bal_2orders; /* 2^order hits */
62689+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
62690+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
62691+ atomic_unchecked_t s_bal_allocated; /* in blocks */
62692+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
62693+ atomic_unchecked_t s_bal_goals; /* goal hits */
62694+ atomic_unchecked_t s_bal_breaks; /* too long searches */
62695+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
62696 spinlock_t s_bal_lock;
62697 unsigned long s_mb_buddies_generated;
62698 unsigned long long s_mb_generation_time;
62699- atomic_t s_mb_lost_chunks;
62700- atomic_t s_mb_preallocated;
62701- atomic_t s_mb_discarded;
62702+ atomic_unchecked_t s_mb_lost_chunks;
62703+ atomic_unchecked_t s_mb_preallocated;
62704+ atomic_unchecked_t s_mb_discarded;
62705 atomic_t s_lock_busy;
62706
62707 /* locality groups */
62708diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
62709index 2dcb936..f5625a0 100644
62710--- a/fs/ext4/mballoc.c
62711+++ b/fs/ext4/mballoc.c
62712@@ -1899,7 +1899,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
62713 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
62714
62715 if (EXT4_SB(sb)->s_mb_stats)
62716- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
62717+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
62718
62719 break;
62720 }
62721@@ -2209,7 +2209,7 @@ repeat:
62722 ac->ac_status = AC_STATUS_CONTINUE;
62723 ac->ac_flags |= EXT4_MB_HINT_FIRST;
62724 cr = 3;
62725- atomic_inc(&sbi->s_mb_lost_chunks);
62726+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
62727 goto repeat;
62728 }
62729 }
62730@@ -2715,25 +2715,25 @@ int ext4_mb_release(struct super_block *sb)
62731 if (sbi->s_mb_stats) {
62732 ext4_msg(sb, KERN_INFO,
62733 "mballoc: %u blocks %u reqs (%u success)",
62734- atomic_read(&sbi->s_bal_allocated),
62735- atomic_read(&sbi->s_bal_reqs),
62736- atomic_read(&sbi->s_bal_success));
62737+ atomic_read_unchecked(&sbi->s_bal_allocated),
62738+ atomic_read_unchecked(&sbi->s_bal_reqs),
62739+ atomic_read_unchecked(&sbi->s_bal_success));
62740 ext4_msg(sb, KERN_INFO,
62741 "mballoc: %u extents scanned, %u goal hits, "
62742 "%u 2^N hits, %u breaks, %u lost",
62743- atomic_read(&sbi->s_bal_ex_scanned),
62744- atomic_read(&sbi->s_bal_goals),
62745- atomic_read(&sbi->s_bal_2orders),
62746- atomic_read(&sbi->s_bal_breaks),
62747- atomic_read(&sbi->s_mb_lost_chunks));
62748+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
62749+ atomic_read_unchecked(&sbi->s_bal_goals),
62750+ atomic_read_unchecked(&sbi->s_bal_2orders),
62751+ atomic_read_unchecked(&sbi->s_bal_breaks),
62752+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
62753 ext4_msg(sb, KERN_INFO,
62754 "mballoc: %lu generated and it took %Lu",
62755 sbi->s_mb_buddies_generated,
62756 sbi->s_mb_generation_time);
62757 ext4_msg(sb, KERN_INFO,
62758 "mballoc: %u preallocated, %u discarded",
62759- atomic_read(&sbi->s_mb_preallocated),
62760- atomic_read(&sbi->s_mb_discarded));
62761+ atomic_read_unchecked(&sbi->s_mb_preallocated),
62762+ atomic_read_unchecked(&sbi->s_mb_discarded));
62763 }
62764
62765 free_percpu(sbi->s_locality_groups);
62766@@ -3189,16 +3189,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
62767 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
62768
62769 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
62770- atomic_inc(&sbi->s_bal_reqs);
62771- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62772+ atomic_inc_unchecked(&sbi->s_bal_reqs);
62773+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62774 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
62775- atomic_inc(&sbi->s_bal_success);
62776- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
62777+ atomic_inc_unchecked(&sbi->s_bal_success);
62778+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
62779 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
62780 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
62781- atomic_inc(&sbi->s_bal_goals);
62782+ atomic_inc_unchecked(&sbi->s_bal_goals);
62783 if (ac->ac_found > sbi->s_mb_max_to_scan)
62784- atomic_inc(&sbi->s_bal_breaks);
62785+ atomic_inc_unchecked(&sbi->s_bal_breaks);
62786 }
62787
62788 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
62789@@ -3603,7 +3603,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
62790 trace_ext4_mb_new_inode_pa(ac, pa);
62791
62792 ext4_mb_use_inode_pa(ac, pa);
62793- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
62794+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
62795
62796 ei = EXT4_I(ac->ac_inode);
62797 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62798@@ -3663,7 +3663,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
62799 trace_ext4_mb_new_group_pa(ac, pa);
62800
62801 ext4_mb_use_group_pa(ac, pa);
62802- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62803+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62804
62805 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62806 lg = ac->ac_lg;
62807@@ -3752,7 +3752,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
62808 * from the bitmap and continue.
62809 */
62810 }
62811- atomic_add(free, &sbi->s_mb_discarded);
62812+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
62813
62814 return err;
62815 }
62816@@ -3770,7 +3770,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
62817 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
62818 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
62819 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
62820- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62821+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62822 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
62823
62824 return 0;
62825diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
62826index 32bce84..112d969 100644
62827--- a/fs/ext4/mmp.c
62828+++ b/fs/ext4/mmp.c
62829@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
62830 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62831 const char *function, unsigned int line, const char *msg)
62832 {
62833- __ext4_warning(sb, function, line, msg);
62834+ __ext4_warning(sb, function, line, "%s", msg);
62835 __ext4_warning(sb, function, line,
62836 "MMP failure info: last update time: %llu, last update "
62837 "node: %s, last update device: %s\n",
62838diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62839index 6df7bc6..410a655 100644
62840--- a/fs/ext4/super.c
62841+++ b/fs/ext4/super.c
62842@@ -1276,7 +1276,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62843 }
62844
62845 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62846-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62847+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62848 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62849
62850 #ifdef CONFIG_QUOTA
62851@@ -2464,7 +2464,7 @@ struct ext4_attr {
62852 int offset;
62853 int deprecated_val;
62854 } u;
62855-};
62856+} __do_const;
62857
62858 static int parse_strtoull(const char *buf,
62859 unsigned long long max, unsigned long long *value)
62860diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62861index e738733..9843a6c 100644
62862--- a/fs/ext4/xattr.c
62863+++ b/fs/ext4/xattr.c
62864@@ -386,7 +386,7 @@ static int
62865 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62866 char *buffer, size_t buffer_size)
62867 {
62868- size_t rest = buffer_size;
62869+ size_t rest = buffer_size, total_size = 0;
62870
62871 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62872 const struct xattr_handler *handler =
62873@@ -403,9 +403,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62874 buffer += size;
62875 }
62876 rest -= size;
62877+ total_size += size;
62878 }
62879 }
62880- return buffer_size - rest;
62881+ return total_size;
62882 }
62883
62884 static int
62885diff --git a/fs/fcntl.c b/fs/fcntl.c
62886index 72c82f6..a18b263 100644
62887--- a/fs/fcntl.c
62888+++ b/fs/fcntl.c
62889@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62890 if (err)
62891 return err;
62892
62893+ if (gr_handle_chroot_fowner(pid, type))
62894+ return -ENOENT;
62895+ if (gr_check_protected_task_fowner(pid, type))
62896+ return -EACCES;
62897+
62898 f_modown(filp, pid, type, force);
62899 return 0;
62900 }
62901diff --git a/fs/fhandle.c b/fs/fhandle.c
62902index 999ff5c..ac037c9 100644
62903--- a/fs/fhandle.c
62904+++ b/fs/fhandle.c
62905@@ -8,6 +8,7 @@
62906 #include <linux/fs_struct.h>
62907 #include <linux/fsnotify.h>
62908 #include <linux/personality.h>
62909+#include <linux/grsecurity.h>
62910 #include <asm/uaccess.h>
62911 #include "internal.h"
62912 #include "mount.h"
62913@@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62914 } else
62915 retval = 0;
62916 /* copy the mount id */
62917- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62918- sizeof(*mnt_id)) ||
62919+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62920 copy_to_user(ufh, handle,
62921 sizeof(struct file_handle) + handle_bytes))
62922 retval = -EFAULT;
62923@@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62924 * the directory. Ideally we would like CAP_DAC_SEARCH.
62925 * But we don't have that
62926 */
62927- if (!capable(CAP_DAC_READ_SEARCH)) {
62928+ if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62929 retval = -EPERM;
62930 goto out_err;
62931 }
62932diff --git a/fs/file.c b/fs/file.c
62933index 66923fe..2849783 100644
62934--- a/fs/file.c
62935+++ b/fs/file.c
62936@@ -16,6 +16,7 @@
62937 #include <linux/slab.h>
62938 #include <linux/vmalloc.h>
62939 #include <linux/file.h>
62940+#include <linux/security.h>
62941 #include <linux/fdtable.h>
62942 #include <linux/bitops.h>
62943 #include <linux/interrupt.h>
62944@@ -139,7 +140,7 @@ out:
62945 * Return <0 error code on error; 1 on successful completion.
62946 * The files->file_lock should be held on entry, and will be held on exit.
62947 */
62948-static int expand_fdtable(struct files_struct *files, int nr)
62949+static int expand_fdtable(struct files_struct *files, unsigned int nr)
62950 __releases(files->file_lock)
62951 __acquires(files->file_lock)
62952 {
62953@@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62954 * expanded and execution may have blocked.
62955 * The files->file_lock should be held on entry, and will be held on exit.
62956 */
62957-static int expand_files(struct files_struct *files, int nr)
62958+static int expand_files(struct files_struct *files, unsigned int nr)
62959 {
62960 struct fdtable *fdt;
62961
62962@@ -799,6 +800,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62963 if (!file)
62964 return __close_fd(files, fd);
62965
62966+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62967 if (fd >= rlimit(RLIMIT_NOFILE))
62968 return -EBADF;
62969
62970@@ -825,6 +827,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62971 if (unlikely(oldfd == newfd))
62972 return -EINVAL;
62973
62974+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62975 if (newfd >= rlimit(RLIMIT_NOFILE))
62976 return -EBADF;
62977
62978@@ -880,6 +883,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62979 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62980 {
62981 int err;
62982+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62983 if (from >= rlimit(RLIMIT_NOFILE))
62984 return -EINVAL;
62985 err = alloc_fd(from, flags);
62986diff --git a/fs/filesystems.c b/fs/filesystems.c
62987index 5797d45..7d7d79a 100644
62988--- a/fs/filesystems.c
62989+++ b/fs/filesystems.c
62990@@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62991 int len = dot ? dot - name : strlen(name);
62992
62993 fs = __get_fs_type(name, len);
62994+#ifdef CONFIG_GRKERNSEC_MODHARDEN
62995+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62996+#else
62997 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62998+#endif
62999 fs = __get_fs_type(name, len);
63000
63001 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
63002diff --git a/fs/fs_struct.c b/fs/fs_struct.c
63003index 7dca743..543d620 100644
63004--- a/fs/fs_struct.c
63005+++ b/fs/fs_struct.c
63006@@ -4,6 +4,7 @@
63007 #include <linux/path.h>
63008 #include <linux/slab.h>
63009 #include <linux/fs_struct.h>
63010+#include <linux/grsecurity.h>
63011 #include "internal.h"
63012
63013 /*
63014@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
63015 write_seqcount_begin(&fs->seq);
63016 old_root = fs->root;
63017 fs->root = *path;
63018+ gr_set_chroot_entries(current, path);
63019 write_seqcount_end(&fs->seq);
63020 spin_unlock(&fs->lock);
63021 if (old_root.dentry)
63022@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
63023 int hits = 0;
63024 spin_lock(&fs->lock);
63025 write_seqcount_begin(&fs->seq);
63026+ /* this root replacement is only done by pivot_root,
63027+ leave grsec's chroot tagging alone for this task
63028+ so that a pivoted root isn't treated as a chroot
63029+ */
63030 hits += replace_path(&fs->root, old_root, new_root);
63031 hits += replace_path(&fs->pwd, old_root, new_root);
63032 write_seqcount_end(&fs->seq);
63033@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
63034 task_lock(tsk);
63035 spin_lock(&fs->lock);
63036 tsk->fs = NULL;
63037- kill = !--fs->users;
63038+ gr_clear_chroot_entries(tsk);
63039+ kill = !atomic_dec_return(&fs->users);
63040 spin_unlock(&fs->lock);
63041 task_unlock(tsk);
63042 if (kill)
63043@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
63044 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
63045 /* We don't need to lock fs - think why ;-) */
63046 if (fs) {
63047- fs->users = 1;
63048+ atomic_set(&fs->users, 1);
63049 fs->in_exec = 0;
63050 spin_lock_init(&fs->lock);
63051 seqcount_init(&fs->seq);
63052@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
63053 spin_lock(&old->lock);
63054 fs->root = old->root;
63055 path_get(&fs->root);
63056+ /* instead of calling gr_set_chroot_entries here,
63057+ we call it from every caller of this function
63058+ */
63059 fs->pwd = old->pwd;
63060 path_get(&fs->pwd);
63061 spin_unlock(&old->lock);
63062@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
63063
63064 task_lock(current);
63065 spin_lock(&fs->lock);
63066- kill = !--fs->users;
63067+ kill = !atomic_dec_return(&fs->users);
63068 current->fs = new_fs;
63069+ gr_set_chroot_entries(current, &new_fs->root);
63070 spin_unlock(&fs->lock);
63071 task_unlock(current);
63072
63073@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
63074
63075 int current_umask(void)
63076 {
63077- return current->fs->umask;
63078+ return current->fs->umask | gr_acl_umask();
63079 }
63080 EXPORT_SYMBOL(current_umask);
63081
63082 /* to be mentioned only in INIT_TASK */
63083 struct fs_struct init_fs = {
63084- .users = 1,
63085+ .users = ATOMIC_INIT(1),
63086 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
63087 .seq = SEQCNT_ZERO(init_fs.seq),
63088 .umask = 0022,
63089diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
63090index aec01be..cf81ff9 100644
63091--- a/fs/fscache/cookie.c
63092+++ b/fs/fscache/cookie.c
63093@@ -19,7 +19,7 @@
63094
63095 struct kmem_cache *fscache_cookie_jar;
63096
63097-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
63098+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
63099
63100 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
63101 static int fscache_alloc_object(struct fscache_cache *cache,
63102@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
63103 parent ? (char *) parent->def->name : "<no-parent>",
63104 def->name, netfs_data, enable);
63105
63106- fscache_stat(&fscache_n_acquires);
63107+ fscache_stat_unchecked(&fscache_n_acquires);
63108
63109 /* if there's no parent cookie, then we don't create one here either */
63110 if (!parent) {
63111- fscache_stat(&fscache_n_acquires_null);
63112+ fscache_stat_unchecked(&fscache_n_acquires_null);
63113 _leave(" [no parent]");
63114 return NULL;
63115 }
63116@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63117 /* allocate and initialise a cookie */
63118 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
63119 if (!cookie) {
63120- fscache_stat(&fscache_n_acquires_oom);
63121+ fscache_stat_unchecked(&fscache_n_acquires_oom);
63122 _leave(" [ENOMEM]");
63123 return NULL;
63124 }
63125@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
63126
63127 switch (cookie->def->type) {
63128 case FSCACHE_COOKIE_TYPE_INDEX:
63129- fscache_stat(&fscache_n_cookie_index);
63130+ fscache_stat_unchecked(&fscache_n_cookie_index);
63131 break;
63132 case FSCACHE_COOKIE_TYPE_DATAFILE:
63133- fscache_stat(&fscache_n_cookie_data);
63134+ fscache_stat_unchecked(&fscache_n_cookie_data);
63135 break;
63136 default:
63137- fscache_stat(&fscache_n_cookie_special);
63138+ fscache_stat_unchecked(&fscache_n_cookie_special);
63139 break;
63140 }
63141
63142@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63143 } else {
63144 atomic_dec(&parent->n_children);
63145 __fscache_cookie_put(cookie);
63146- fscache_stat(&fscache_n_acquires_nobufs);
63147+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
63148 _leave(" = NULL");
63149 return NULL;
63150 }
63151@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63152 }
63153 }
63154
63155- fscache_stat(&fscache_n_acquires_ok);
63156+ fscache_stat_unchecked(&fscache_n_acquires_ok);
63157 _leave(" = %p", cookie);
63158 return cookie;
63159 }
63160@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
63161 cache = fscache_select_cache_for_object(cookie->parent);
63162 if (!cache) {
63163 up_read(&fscache_addremove_sem);
63164- fscache_stat(&fscache_n_acquires_no_cache);
63165+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
63166 _leave(" = -ENOMEDIUM [no cache]");
63167 return -ENOMEDIUM;
63168 }
63169@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
63170 object = cache->ops->alloc_object(cache, cookie);
63171 fscache_stat_d(&fscache_n_cop_alloc_object);
63172 if (IS_ERR(object)) {
63173- fscache_stat(&fscache_n_object_no_alloc);
63174+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
63175 ret = PTR_ERR(object);
63176 goto error;
63177 }
63178
63179- fscache_stat(&fscache_n_object_alloc);
63180+ fscache_stat_unchecked(&fscache_n_object_alloc);
63181
63182- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
63183+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
63184
63185 _debug("ALLOC OBJ%x: %s {%lx}",
63186 object->debug_id, cookie->def->name, object->events);
63187@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
63188
63189 _enter("{%s}", cookie->def->name);
63190
63191- fscache_stat(&fscache_n_invalidates);
63192+ fscache_stat_unchecked(&fscache_n_invalidates);
63193
63194 /* Only permit invalidation of data files. Invalidating an index will
63195 * require the caller to release all its attachments to the tree rooted
63196@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
63197 {
63198 struct fscache_object *object;
63199
63200- fscache_stat(&fscache_n_updates);
63201+ fscache_stat_unchecked(&fscache_n_updates);
63202
63203 if (!cookie) {
63204- fscache_stat(&fscache_n_updates_null);
63205+ fscache_stat_unchecked(&fscache_n_updates_null);
63206 _leave(" [no cookie]");
63207 return;
63208 }
63209@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
63210 */
63211 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
63212 {
63213- fscache_stat(&fscache_n_relinquishes);
63214+ fscache_stat_unchecked(&fscache_n_relinquishes);
63215 if (retire)
63216- fscache_stat(&fscache_n_relinquishes_retire);
63217+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
63218
63219 if (!cookie) {
63220- fscache_stat(&fscache_n_relinquishes_null);
63221+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
63222 _leave(" [no cookie]");
63223 return;
63224 }
63225@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
63226 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
63227 goto inconsistent;
63228
63229- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63230+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63231
63232 __fscache_use_cookie(cookie);
63233 if (fscache_submit_op(object, op) < 0)
63234diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
63235index bc6c08f..09c0d96 100644
63236--- a/fs/fscache/internal.h
63237+++ b/fs/fscache/internal.h
63238@@ -139,8 +139,8 @@ extern void fscache_operation_gc(struct work_struct *);
63239 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
63240 extern int fscache_wait_for_operation_activation(struct fscache_object *,
63241 struct fscache_operation *,
63242- atomic_t *,
63243- atomic_t *,
63244+ atomic_unchecked_t *,
63245+ atomic_unchecked_t *,
63246 void (*)(struct fscache_operation *));
63247 extern void fscache_invalidate_writes(struct fscache_cookie *);
63248
63249@@ -159,101 +159,101 @@ extern void fscache_proc_cleanup(void);
63250 * stats.c
63251 */
63252 #ifdef CONFIG_FSCACHE_STATS
63253-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
63254-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
63255+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
63256+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
63257
63258-extern atomic_t fscache_n_op_pend;
63259-extern atomic_t fscache_n_op_run;
63260-extern atomic_t fscache_n_op_enqueue;
63261-extern atomic_t fscache_n_op_deferred_release;
63262-extern atomic_t fscache_n_op_release;
63263-extern atomic_t fscache_n_op_gc;
63264-extern atomic_t fscache_n_op_cancelled;
63265-extern atomic_t fscache_n_op_rejected;
63266+extern atomic_unchecked_t fscache_n_op_pend;
63267+extern atomic_unchecked_t fscache_n_op_run;
63268+extern atomic_unchecked_t fscache_n_op_enqueue;
63269+extern atomic_unchecked_t fscache_n_op_deferred_release;
63270+extern atomic_unchecked_t fscache_n_op_release;
63271+extern atomic_unchecked_t fscache_n_op_gc;
63272+extern atomic_unchecked_t fscache_n_op_cancelled;
63273+extern atomic_unchecked_t fscache_n_op_rejected;
63274
63275-extern atomic_t fscache_n_attr_changed;
63276-extern atomic_t fscache_n_attr_changed_ok;
63277-extern atomic_t fscache_n_attr_changed_nobufs;
63278-extern atomic_t fscache_n_attr_changed_nomem;
63279-extern atomic_t fscache_n_attr_changed_calls;
63280+extern atomic_unchecked_t fscache_n_attr_changed;
63281+extern atomic_unchecked_t fscache_n_attr_changed_ok;
63282+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
63283+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
63284+extern atomic_unchecked_t fscache_n_attr_changed_calls;
63285
63286-extern atomic_t fscache_n_allocs;
63287-extern atomic_t fscache_n_allocs_ok;
63288-extern atomic_t fscache_n_allocs_wait;
63289-extern atomic_t fscache_n_allocs_nobufs;
63290-extern atomic_t fscache_n_allocs_intr;
63291-extern atomic_t fscache_n_allocs_object_dead;
63292-extern atomic_t fscache_n_alloc_ops;
63293-extern atomic_t fscache_n_alloc_op_waits;
63294+extern atomic_unchecked_t fscache_n_allocs;
63295+extern atomic_unchecked_t fscache_n_allocs_ok;
63296+extern atomic_unchecked_t fscache_n_allocs_wait;
63297+extern atomic_unchecked_t fscache_n_allocs_nobufs;
63298+extern atomic_unchecked_t fscache_n_allocs_intr;
63299+extern atomic_unchecked_t fscache_n_allocs_object_dead;
63300+extern atomic_unchecked_t fscache_n_alloc_ops;
63301+extern atomic_unchecked_t fscache_n_alloc_op_waits;
63302
63303-extern atomic_t fscache_n_retrievals;
63304-extern atomic_t fscache_n_retrievals_ok;
63305-extern atomic_t fscache_n_retrievals_wait;
63306-extern atomic_t fscache_n_retrievals_nodata;
63307-extern atomic_t fscache_n_retrievals_nobufs;
63308-extern atomic_t fscache_n_retrievals_intr;
63309-extern atomic_t fscache_n_retrievals_nomem;
63310-extern atomic_t fscache_n_retrievals_object_dead;
63311-extern atomic_t fscache_n_retrieval_ops;
63312-extern atomic_t fscache_n_retrieval_op_waits;
63313+extern atomic_unchecked_t fscache_n_retrievals;
63314+extern atomic_unchecked_t fscache_n_retrievals_ok;
63315+extern atomic_unchecked_t fscache_n_retrievals_wait;
63316+extern atomic_unchecked_t fscache_n_retrievals_nodata;
63317+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
63318+extern atomic_unchecked_t fscache_n_retrievals_intr;
63319+extern atomic_unchecked_t fscache_n_retrievals_nomem;
63320+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
63321+extern atomic_unchecked_t fscache_n_retrieval_ops;
63322+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
63323
63324-extern atomic_t fscache_n_stores;
63325-extern atomic_t fscache_n_stores_ok;
63326-extern atomic_t fscache_n_stores_again;
63327-extern atomic_t fscache_n_stores_nobufs;
63328-extern atomic_t fscache_n_stores_oom;
63329-extern atomic_t fscache_n_store_ops;
63330-extern atomic_t fscache_n_store_calls;
63331-extern atomic_t fscache_n_store_pages;
63332-extern atomic_t fscache_n_store_radix_deletes;
63333-extern atomic_t fscache_n_store_pages_over_limit;
63334+extern atomic_unchecked_t fscache_n_stores;
63335+extern atomic_unchecked_t fscache_n_stores_ok;
63336+extern atomic_unchecked_t fscache_n_stores_again;
63337+extern atomic_unchecked_t fscache_n_stores_nobufs;
63338+extern atomic_unchecked_t fscache_n_stores_oom;
63339+extern atomic_unchecked_t fscache_n_store_ops;
63340+extern atomic_unchecked_t fscache_n_store_calls;
63341+extern atomic_unchecked_t fscache_n_store_pages;
63342+extern atomic_unchecked_t fscache_n_store_radix_deletes;
63343+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
63344
63345-extern atomic_t fscache_n_store_vmscan_not_storing;
63346-extern atomic_t fscache_n_store_vmscan_gone;
63347-extern atomic_t fscache_n_store_vmscan_busy;
63348-extern atomic_t fscache_n_store_vmscan_cancelled;
63349-extern atomic_t fscache_n_store_vmscan_wait;
63350+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63351+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
63352+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
63353+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63354+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
63355
63356-extern atomic_t fscache_n_marks;
63357-extern atomic_t fscache_n_uncaches;
63358+extern atomic_unchecked_t fscache_n_marks;
63359+extern atomic_unchecked_t fscache_n_uncaches;
63360
63361-extern atomic_t fscache_n_acquires;
63362-extern atomic_t fscache_n_acquires_null;
63363-extern atomic_t fscache_n_acquires_no_cache;
63364-extern atomic_t fscache_n_acquires_ok;
63365-extern atomic_t fscache_n_acquires_nobufs;
63366-extern atomic_t fscache_n_acquires_oom;
63367+extern atomic_unchecked_t fscache_n_acquires;
63368+extern atomic_unchecked_t fscache_n_acquires_null;
63369+extern atomic_unchecked_t fscache_n_acquires_no_cache;
63370+extern atomic_unchecked_t fscache_n_acquires_ok;
63371+extern atomic_unchecked_t fscache_n_acquires_nobufs;
63372+extern atomic_unchecked_t fscache_n_acquires_oom;
63373
63374-extern atomic_t fscache_n_invalidates;
63375-extern atomic_t fscache_n_invalidates_run;
63376+extern atomic_unchecked_t fscache_n_invalidates;
63377+extern atomic_unchecked_t fscache_n_invalidates_run;
63378
63379-extern atomic_t fscache_n_updates;
63380-extern atomic_t fscache_n_updates_null;
63381-extern atomic_t fscache_n_updates_run;
63382+extern atomic_unchecked_t fscache_n_updates;
63383+extern atomic_unchecked_t fscache_n_updates_null;
63384+extern atomic_unchecked_t fscache_n_updates_run;
63385
63386-extern atomic_t fscache_n_relinquishes;
63387-extern atomic_t fscache_n_relinquishes_null;
63388-extern atomic_t fscache_n_relinquishes_waitcrt;
63389-extern atomic_t fscache_n_relinquishes_retire;
63390+extern atomic_unchecked_t fscache_n_relinquishes;
63391+extern atomic_unchecked_t fscache_n_relinquishes_null;
63392+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63393+extern atomic_unchecked_t fscache_n_relinquishes_retire;
63394
63395-extern atomic_t fscache_n_cookie_index;
63396-extern atomic_t fscache_n_cookie_data;
63397-extern atomic_t fscache_n_cookie_special;
63398+extern atomic_unchecked_t fscache_n_cookie_index;
63399+extern atomic_unchecked_t fscache_n_cookie_data;
63400+extern atomic_unchecked_t fscache_n_cookie_special;
63401
63402-extern atomic_t fscache_n_object_alloc;
63403-extern atomic_t fscache_n_object_no_alloc;
63404-extern atomic_t fscache_n_object_lookups;
63405-extern atomic_t fscache_n_object_lookups_negative;
63406-extern atomic_t fscache_n_object_lookups_positive;
63407-extern atomic_t fscache_n_object_lookups_timed_out;
63408-extern atomic_t fscache_n_object_created;
63409-extern atomic_t fscache_n_object_avail;
63410-extern atomic_t fscache_n_object_dead;
63411+extern atomic_unchecked_t fscache_n_object_alloc;
63412+extern atomic_unchecked_t fscache_n_object_no_alloc;
63413+extern atomic_unchecked_t fscache_n_object_lookups;
63414+extern atomic_unchecked_t fscache_n_object_lookups_negative;
63415+extern atomic_unchecked_t fscache_n_object_lookups_positive;
63416+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
63417+extern atomic_unchecked_t fscache_n_object_created;
63418+extern atomic_unchecked_t fscache_n_object_avail;
63419+extern atomic_unchecked_t fscache_n_object_dead;
63420
63421-extern atomic_t fscache_n_checkaux_none;
63422-extern atomic_t fscache_n_checkaux_okay;
63423-extern atomic_t fscache_n_checkaux_update;
63424-extern atomic_t fscache_n_checkaux_obsolete;
63425+extern atomic_unchecked_t fscache_n_checkaux_none;
63426+extern atomic_unchecked_t fscache_n_checkaux_okay;
63427+extern atomic_unchecked_t fscache_n_checkaux_update;
63428+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
63429
63430 extern atomic_t fscache_n_cop_alloc_object;
63431 extern atomic_t fscache_n_cop_lookup_object;
63432@@ -278,6 +278,11 @@ static inline void fscache_stat(atomic_t *stat)
63433 atomic_inc(stat);
63434 }
63435
63436+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
63437+{
63438+ atomic_inc_unchecked(stat);
63439+}
63440+
63441 static inline void fscache_stat_d(atomic_t *stat)
63442 {
63443 atomic_dec(stat);
63444@@ -290,6 +295,7 @@ extern const struct file_operations fscache_stats_fops;
63445
63446 #define __fscache_stat(stat) (NULL)
63447 #define fscache_stat(stat) do {} while (0)
63448+#define fscache_stat_unchecked(stat) do {} while (0)
63449 #define fscache_stat_d(stat) do {} while (0)
63450 #endif
63451
63452diff --git a/fs/fscache/object.c b/fs/fscache/object.c
63453index d3b4539..ed0c659 100644
63454--- a/fs/fscache/object.c
63455+++ b/fs/fscache/object.c
63456@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
63457 _debug("LOOKUP \"%s\" in \"%s\"",
63458 cookie->def->name, object->cache->tag->name);
63459
63460- fscache_stat(&fscache_n_object_lookups);
63461+ fscache_stat_unchecked(&fscache_n_object_lookups);
63462 fscache_stat(&fscache_n_cop_lookup_object);
63463 ret = object->cache->ops->lookup_object(object);
63464 fscache_stat_d(&fscache_n_cop_lookup_object);
63465@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
63466 if (ret == -ETIMEDOUT) {
63467 /* probably stuck behind another object, so move this one to
63468 * the back of the queue */
63469- fscache_stat(&fscache_n_object_lookups_timed_out);
63470+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
63471 _leave(" [timeout]");
63472 return NO_TRANSIT;
63473 }
63474@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
63475 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
63476
63477 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
63478- fscache_stat(&fscache_n_object_lookups_negative);
63479+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
63480
63481 /* Allow write requests to begin stacking up and read requests to begin
63482 * returning ENODATA.
63483@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
63484 /* if we were still looking up, then we must have a positive lookup
63485 * result, in which case there may be data available */
63486 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
63487- fscache_stat(&fscache_n_object_lookups_positive);
63488+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
63489
63490 /* We do (presumably) have data */
63491 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
63492@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
63493 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
63494 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
63495 } else {
63496- fscache_stat(&fscache_n_object_created);
63497+ fscache_stat_unchecked(&fscache_n_object_created);
63498 }
63499
63500 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
63501@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
63502 fscache_stat_d(&fscache_n_cop_lookup_complete);
63503
63504 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
63505- fscache_stat(&fscache_n_object_avail);
63506+ fscache_stat_unchecked(&fscache_n_object_avail);
63507
63508 _leave("");
63509 return transit_to(JUMPSTART_DEPS);
63510@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
63511
63512 /* this just shifts the object release to the work processor */
63513 fscache_put_object(object);
63514- fscache_stat(&fscache_n_object_dead);
63515+ fscache_stat_unchecked(&fscache_n_object_dead);
63516
63517 _leave("");
63518 return transit_to(OBJECT_DEAD);
63519@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63520 enum fscache_checkaux result;
63521
63522 if (!object->cookie->def->check_aux) {
63523- fscache_stat(&fscache_n_checkaux_none);
63524+ fscache_stat_unchecked(&fscache_n_checkaux_none);
63525 return FSCACHE_CHECKAUX_OKAY;
63526 }
63527
63528@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63529 switch (result) {
63530 /* entry okay as is */
63531 case FSCACHE_CHECKAUX_OKAY:
63532- fscache_stat(&fscache_n_checkaux_okay);
63533+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
63534 break;
63535
63536 /* entry requires update */
63537 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
63538- fscache_stat(&fscache_n_checkaux_update);
63539+ fscache_stat_unchecked(&fscache_n_checkaux_update);
63540 break;
63541
63542 /* entry requires deletion */
63543 case FSCACHE_CHECKAUX_OBSOLETE:
63544- fscache_stat(&fscache_n_checkaux_obsolete);
63545+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
63546 break;
63547
63548 default:
63549@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
63550 {
63551 const struct fscache_state *s;
63552
63553- fscache_stat(&fscache_n_invalidates_run);
63554+ fscache_stat_unchecked(&fscache_n_invalidates_run);
63555 fscache_stat(&fscache_n_cop_invalidate_object);
63556 s = _fscache_invalidate_object(object, event);
63557 fscache_stat_d(&fscache_n_cop_invalidate_object);
63558@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
63559 {
63560 _enter("{OBJ%x},%d", object->debug_id, event);
63561
63562- fscache_stat(&fscache_n_updates_run);
63563+ fscache_stat_unchecked(&fscache_n_updates_run);
63564 fscache_stat(&fscache_n_cop_update_object);
63565 object->cache->ops->update_object(object);
63566 fscache_stat_d(&fscache_n_cop_update_object);
63567diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
63568index e7b87a0..a85d47a 100644
63569--- a/fs/fscache/operation.c
63570+++ b/fs/fscache/operation.c
63571@@ -17,7 +17,7 @@
63572 #include <linux/slab.h>
63573 #include "internal.h"
63574
63575-atomic_t fscache_op_debug_id;
63576+atomic_unchecked_t fscache_op_debug_id;
63577 EXPORT_SYMBOL(fscache_op_debug_id);
63578
63579 /**
63580@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
63581 ASSERTCMP(atomic_read(&op->usage), >, 0);
63582 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
63583
63584- fscache_stat(&fscache_n_op_enqueue);
63585+ fscache_stat_unchecked(&fscache_n_op_enqueue);
63586 switch (op->flags & FSCACHE_OP_TYPE) {
63587 case FSCACHE_OP_ASYNC:
63588 _debug("queue async");
63589@@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
63590 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
63591 if (op->processor)
63592 fscache_enqueue_operation(op);
63593- fscache_stat(&fscache_n_op_run);
63594+ fscache_stat_unchecked(&fscache_n_op_run);
63595 }
63596
63597 /*
63598@@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63599 if (object->n_in_progress > 0) {
63600 atomic_inc(&op->usage);
63601 list_add_tail(&op->pend_link, &object->pending_ops);
63602- fscache_stat(&fscache_n_op_pend);
63603+ fscache_stat_unchecked(&fscache_n_op_pend);
63604 } else if (!list_empty(&object->pending_ops)) {
63605 atomic_inc(&op->usage);
63606 list_add_tail(&op->pend_link, &object->pending_ops);
63607- fscache_stat(&fscache_n_op_pend);
63608+ fscache_stat_unchecked(&fscache_n_op_pend);
63609 fscache_start_operations(object);
63610 } else {
63611 ASSERTCMP(object->n_in_progress, ==, 0);
63612@@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63613 object->n_exclusive++; /* reads and writes must wait */
63614 atomic_inc(&op->usage);
63615 list_add_tail(&op->pend_link, &object->pending_ops);
63616- fscache_stat(&fscache_n_op_pend);
63617+ fscache_stat_unchecked(&fscache_n_op_pend);
63618 ret = 0;
63619 } else {
63620 /* If we're in any other state, there must have been an I/O
63621@@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
63622 if (object->n_exclusive > 0) {
63623 atomic_inc(&op->usage);
63624 list_add_tail(&op->pend_link, &object->pending_ops);
63625- fscache_stat(&fscache_n_op_pend);
63626+ fscache_stat_unchecked(&fscache_n_op_pend);
63627 } else if (!list_empty(&object->pending_ops)) {
63628 atomic_inc(&op->usage);
63629 list_add_tail(&op->pend_link, &object->pending_ops);
63630- fscache_stat(&fscache_n_op_pend);
63631+ fscache_stat_unchecked(&fscache_n_op_pend);
63632 fscache_start_operations(object);
63633 } else {
63634 ASSERTCMP(object->n_exclusive, ==, 0);
63635@@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
63636 object->n_ops++;
63637 atomic_inc(&op->usage);
63638 list_add_tail(&op->pend_link, &object->pending_ops);
63639- fscache_stat(&fscache_n_op_pend);
63640+ fscache_stat_unchecked(&fscache_n_op_pend);
63641 ret = 0;
63642 } else if (fscache_object_is_dying(object)) {
63643- fscache_stat(&fscache_n_op_rejected);
63644+ fscache_stat_unchecked(&fscache_n_op_rejected);
63645 op->state = FSCACHE_OP_ST_CANCELLED;
63646 ret = -ENOBUFS;
63647 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
63648@@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
63649 ret = -EBUSY;
63650 if (op->state == FSCACHE_OP_ST_PENDING) {
63651 ASSERT(!list_empty(&op->pend_link));
63652- fscache_stat(&fscache_n_op_cancelled);
63653+ fscache_stat_unchecked(&fscache_n_op_cancelled);
63654 list_del_init(&op->pend_link);
63655 if (do_cancel)
63656 do_cancel(op);
63657@@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
63658 while (!list_empty(&object->pending_ops)) {
63659 op = list_entry(object->pending_ops.next,
63660 struct fscache_operation, pend_link);
63661- fscache_stat(&fscache_n_op_cancelled);
63662+ fscache_stat_unchecked(&fscache_n_op_cancelled);
63663 list_del_init(&op->pend_link);
63664
63665 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
63666@@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
63667 op->state, ==, FSCACHE_OP_ST_CANCELLED);
63668 op->state = FSCACHE_OP_ST_DEAD;
63669
63670- fscache_stat(&fscache_n_op_release);
63671+ fscache_stat_unchecked(&fscache_n_op_release);
63672
63673 if (op->release) {
63674 op->release(op);
63675@@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
63676 * lock, and defer it otherwise */
63677 if (!spin_trylock(&object->lock)) {
63678 _debug("defer put");
63679- fscache_stat(&fscache_n_op_deferred_release);
63680+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
63681
63682 cache = object->cache;
63683 spin_lock(&cache->op_gc_list_lock);
63684@@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
63685
63686 _debug("GC DEFERRED REL OBJ%x OP%x",
63687 object->debug_id, op->debug_id);
63688- fscache_stat(&fscache_n_op_gc);
63689+ fscache_stat_unchecked(&fscache_n_op_gc);
63690
63691 ASSERTCMP(atomic_read(&op->usage), ==, 0);
63692 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
63693diff --git a/fs/fscache/page.c b/fs/fscache/page.c
63694index ed70714..67f4982 100644
63695--- a/fs/fscache/page.c
63696+++ b/fs/fscache/page.c
63697@@ -61,7 +61,7 @@ try_again:
63698 val = radix_tree_lookup(&cookie->stores, page->index);
63699 if (!val) {
63700 rcu_read_unlock();
63701- fscache_stat(&fscache_n_store_vmscan_not_storing);
63702+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
63703 __fscache_uncache_page(cookie, page);
63704 return true;
63705 }
63706@@ -91,11 +91,11 @@ try_again:
63707 spin_unlock(&cookie->stores_lock);
63708
63709 if (xpage) {
63710- fscache_stat(&fscache_n_store_vmscan_cancelled);
63711- fscache_stat(&fscache_n_store_radix_deletes);
63712+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
63713+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63714 ASSERTCMP(xpage, ==, page);
63715 } else {
63716- fscache_stat(&fscache_n_store_vmscan_gone);
63717+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
63718 }
63719
63720 wake_up_bit(&cookie->flags, 0);
63721@@ -110,11 +110,11 @@ page_busy:
63722 * sleeping on memory allocation, so we may need to impose a timeout
63723 * too. */
63724 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
63725- fscache_stat(&fscache_n_store_vmscan_busy);
63726+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
63727 return false;
63728 }
63729
63730- fscache_stat(&fscache_n_store_vmscan_wait);
63731+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
63732 __fscache_wait_on_page_write(cookie, page);
63733 gfp &= ~__GFP_WAIT;
63734 goto try_again;
63735@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
63736 FSCACHE_COOKIE_STORING_TAG);
63737 if (!radix_tree_tag_get(&cookie->stores, page->index,
63738 FSCACHE_COOKIE_PENDING_TAG)) {
63739- fscache_stat(&fscache_n_store_radix_deletes);
63740+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63741 xpage = radix_tree_delete(&cookie->stores, page->index);
63742 }
63743 spin_unlock(&cookie->stores_lock);
63744@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
63745
63746 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
63747
63748- fscache_stat(&fscache_n_attr_changed_calls);
63749+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
63750
63751 if (fscache_object_is_active(object)) {
63752 fscache_stat(&fscache_n_cop_attr_changed);
63753@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63754
63755 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63756
63757- fscache_stat(&fscache_n_attr_changed);
63758+ fscache_stat_unchecked(&fscache_n_attr_changed);
63759
63760 op = kzalloc(sizeof(*op), GFP_KERNEL);
63761 if (!op) {
63762- fscache_stat(&fscache_n_attr_changed_nomem);
63763+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
63764 _leave(" = -ENOMEM");
63765 return -ENOMEM;
63766 }
63767@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63768 if (fscache_submit_exclusive_op(object, op) < 0)
63769 goto nobufs;
63770 spin_unlock(&cookie->lock);
63771- fscache_stat(&fscache_n_attr_changed_ok);
63772+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
63773 fscache_put_operation(op);
63774 _leave(" = 0");
63775 return 0;
63776@@ -225,7 +225,7 @@ nobufs:
63777 kfree(op);
63778 if (wake_cookie)
63779 __fscache_wake_unused_cookie(cookie);
63780- fscache_stat(&fscache_n_attr_changed_nobufs);
63781+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
63782 _leave(" = %d", -ENOBUFS);
63783 return -ENOBUFS;
63784 }
63785@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
63786 /* allocate a retrieval operation and attempt to submit it */
63787 op = kzalloc(sizeof(*op), GFP_NOIO);
63788 if (!op) {
63789- fscache_stat(&fscache_n_retrievals_nomem);
63790+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63791 return NULL;
63792 }
63793
63794@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
63795 return 0;
63796 }
63797
63798- fscache_stat(&fscache_n_retrievals_wait);
63799+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
63800
63801 jif = jiffies;
63802 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
63803 fscache_wait_bit_interruptible,
63804 TASK_INTERRUPTIBLE) != 0) {
63805- fscache_stat(&fscache_n_retrievals_intr);
63806+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
63807 _leave(" = -ERESTARTSYS");
63808 return -ERESTARTSYS;
63809 }
63810@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
63811 */
63812 int fscache_wait_for_operation_activation(struct fscache_object *object,
63813 struct fscache_operation *op,
63814- atomic_t *stat_op_waits,
63815- atomic_t *stat_object_dead,
63816+ atomic_unchecked_t *stat_op_waits,
63817+ atomic_unchecked_t *stat_object_dead,
63818 void (*do_cancel)(struct fscache_operation *))
63819 {
63820 int ret;
63821@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63822
63823 _debug(">>> WT");
63824 if (stat_op_waits)
63825- fscache_stat(stat_op_waits);
63826+ fscache_stat_unchecked(stat_op_waits);
63827 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63828 fscache_wait_bit_interruptible,
63829 TASK_INTERRUPTIBLE) != 0) {
63830@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63831 check_if_dead:
63832 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63833 if (stat_object_dead)
63834- fscache_stat(stat_object_dead);
63835+ fscache_stat_unchecked(stat_object_dead);
63836 _leave(" = -ENOBUFS [cancelled]");
63837 return -ENOBUFS;
63838 }
63839@@ -366,7 +366,7 @@ check_if_dead:
63840 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63841 fscache_cancel_op(op, do_cancel);
63842 if (stat_object_dead)
63843- fscache_stat(stat_object_dead);
63844+ fscache_stat_unchecked(stat_object_dead);
63845 return -ENOBUFS;
63846 }
63847 return 0;
63848@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63849
63850 _enter("%p,%p,,,", cookie, page);
63851
63852- fscache_stat(&fscache_n_retrievals);
63853+ fscache_stat_unchecked(&fscache_n_retrievals);
63854
63855 if (hlist_empty(&cookie->backing_objects))
63856 goto nobufs;
63857@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63858 goto nobufs_unlock_dec;
63859 spin_unlock(&cookie->lock);
63860
63861- fscache_stat(&fscache_n_retrieval_ops);
63862+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
63863
63864 /* pin the netfs read context in case we need to do the actual netfs
63865 * read because we've encountered a cache read failure */
63866@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63867
63868 error:
63869 if (ret == -ENOMEM)
63870- fscache_stat(&fscache_n_retrievals_nomem);
63871+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63872 else if (ret == -ERESTARTSYS)
63873- fscache_stat(&fscache_n_retrievals_intr);
63874+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
63875 else if (ret == -ENODATA)
63876- fscache_stat(&fscache_n_retrievals_nodata);
63877+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63878 else if (ret < 0)
63879- fscache_stat(&fscache_n_retrievals_nobufs);
63880+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63881 else
63882- fscache_stat(&fscache_n_retrievals_ok);
63883+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
63884
63885 fscache_put_retrieval(op);
63886 _leave(" = %d", ret);
63887@@ -490,7 +490,7 @@ nobufs_unlock:
63888 __fscache_wake_unused_cookie(cookie);
63889 kfree(op);
63890 nobufs:
63891- fscache_stat(&fscache_n_retrievals_nobufs);
63892+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63893 _leave(" = -ENOBUFS");
63894 return -ENOBUFS;
63895 }
63896@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63897
63898 _enter("%p,,%d,,,", cookie, *nr_pages);
63899
63900- fscache_stat(&fscache_n_retrievals);
63901+ fscache_stat_unchecked(&fscache_n_retrievals);
63902
63903 if (hlist_empty(&cookie->backing_objects))
63904 goto nobufs;
63905@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63906 goto nobufs_unlock_dec;
63907 spin_unlock(&cookie->lock);
63908
63909- fscache_stat(&fscache_n_retrieval_ops);
63910+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
63911
63912 /* pin the netfs read context in case we need to do the actual netfs
63913 * read because we've encountered a cache read failure */
63914@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63915
63916 error:
63917 if (ret == -ENOMEM)
63918- fscache_stat(&fscache_n_retrievals_nomem);
63919+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63920 else if (ret == -ERESTARTSYS)
63921- fscache_stat(&fscache_n_retrievals_intr);
63922+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
63923 else if (ret == -ENODATA)
63924- fscache_stat(&fscache_n_retrievals_nodata);
63925+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63926 else if (ret < 0)
63927- fscache_stat(&fscache_n_retrievals_nobufs);
63928+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63929 else
63930- fscache_stat(&fscache_n_retrievals_ok);
63931+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
63932
63933 fscache_put_retrieval(op);
63934 _leave(" = %d", ret);
63935@@ -621,7 +621,7 @@ nobufs_unlock:
63936 if (wake_cookie)
63937 __fscache_wake_unused_cookie(cookie);
63938 nobufs:
63939- fscache_stat(&fscache_n_retrievals_nobufs);
63940+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63941 _leave(" = -ENOBUFS");
63942 return -ENOBUFS;
63943 }
63944@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63945
63946 _enter("%p,%p,,,", cookie, page);
63947
63948- fscache_stat(&fscache_n_allocs);
63949+ fscache_stat_unchecked(&fscache_n_allocs);
63950
63951 if (hlist_empty(&cookie->backing_objects))
63952 goto nobufs;
63953@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63954 goto nobufs_unlock_dec;
63955 spin_unlock(&cookie->lock);
63956
63957- fscache_stat(&fscache_n_alloc_ops);
63958+ fscache_stat_unchecked(&fscache_n_alloc_ops);
63959
63960 ret = fscache_wait_for_operation_activation(
63961 object, &op->op,
63962@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63963
63964 error:
63965 if (ret == -ERESTARTSYS)
63966- fscache_stat(&fscache_n_allocs_intr);
63967+ fscache_stat_unchecked(&fscache_n_allocs_intr);
63968 else if (ret < 0)
63969- fscache_stat(&fscache_n_allocs_nobufs);
63970+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63971 else
63972- fscache_stat(&fscache_n_allocs_ok);
63973+ fscache_stat_unchecked(&fscache_n_allocs_ok);
63974
63975 fscache_put_retrieval(op);
63976 _leave(" = %d", ret);
63977@@ -715,7 +715,7 @@ nobufs_unlock:
63978 if (wake_cookie)
63979 __fscache_wake_unused_cookie(cookie);
63980 nobufs:
63981- fscache_stat(&fscache_n_allocs_nobufs);
63982+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63983 _leave(" = -ENOBUFS");
63984 return -ENOBUFS;
63985 }
63986@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63987
63988 spin_lock(&cookie->stores_lock);
63989
63990- fscache_stat(&fscache_n_store_calls);
63991+ fscache_stat_unchecked(&fscache_n_store_calls);
63992
63993 /* find a page to store */
63994 page = NULL;
63995@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63996 page = results[0];
63997 _debug("gang %d [%lx]", n, page->index);
63998 if (page->index > op->store_limit) {
63999- fscache_stat(&fscache_n_store_pages_over_limit);
64000+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
64001 goto superseded;
64002 }
64003
64004@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
64005 spin_unlock(&cookie->stores_lock);
64006 spin_unlock(&object->lock);
64007
64008- fscache_stat(&fscache_n_store_pages);
64009+ fscache_stat_unchecked(&fscache_n_store_pages);
64010 fscache_stat(&fscache_n_cop_write_page);
64011 ret = object->cache->ops->write_page(op, page);
64012 fscache_stat_d(&fscache_n_cop_write_page);
64013@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64014 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
64015 ASSERT(PageFsCache(page));
64016
64017- fscache_stat(&fscache_n_stores);
64018+ fscache_stat_unchecked(&fscache_n_stores);
64019
64020 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
64021 _leave(" = -ENOBUFS [invalidating]");
64022@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64023 spin_unlock(&cookie->stores_lock);
64024 spin_unlock(&object->lock);
64025
64026- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
64027+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
64028 op->store_limit = object->store_limit;
64029
64030 __fscache_use_cookie(cookie);
64031@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64032
64033 spin_unlock(&cookie->lock);
64034 radix_tree_preload_end();
64035- fscache_stat(&fscache_n_store_ops);
64036- fscache_stat(&fscache_n_stores_ok);
64037+ fscache_stat_unchecked(&fscache_n_store_ops);
64038+ fscache_stat_unchecked(&fscache_n_stores_ok);
64039
64040 /* the work queue now carries its own ref on the object */
64041 fscache_put_operation(&op->op);
64042@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64043 return 0;
64044
64045 already_queued:
64046- fscache_stat(&fscache_n_stores_again);
64047+ fscache_stat_unchecked(&fscache_n_stores_again);
64048 already_pending:
64049 spin_unlock(&cookie->stores_lock);
64050 spin_unlock(&object->lock);
64051 spin_unlock(&cookie->lock);
64052 radix_tree_preload_end();
64053 kfree(op);
64054- fscache_stat(&fscache_n_stores_ok);
64055+ fscache_stat_unchecked(&fscache_n_stores_ok);
64056 _leave(" = 0");
64057 return 0;
64058
64059@@ -1024,14 +1024,14 @@ nobufs:
64060 kfree(op);
64061 if (wake_cookie)
64062 __fscache_wake_unused_cookie(cookie);
64063- fscache_stat(&fscache_n_stores_nobufs);
64064+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
64065 _leave(" = -ENOBUFS");
64066 return -ENOBUFS;
64067
64068 nomem_free:
64069 kfree(op);
64070 nomem:
64071- fscache_stat(&fscache_n_stores_oom);
64072+ fscache_stat_unchecked(&fscache_n_stores_oom);
64073 _leave(" = -ENOMEM");
64074 return -ENOMEM;
64075 }
64076@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
64077 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
64078 ASSERTCMP(page, !=, NULL);
64079
64080- fscache_stat(&fscache_n_uncaches);
64081+ fscache_stat_unchecked(&fscache_n_uncaches);
64082
64083 /* cache withdrawal may beat us to it */
64084 if (!PageFsCache(page))
64085@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
64086 struct fscache_cookie *cookie = op->op.object->cookie;
64087
64088 #ifdef CONFIG_FSCACHE_STATS
64089- atomic_inc(&fscache_n_marks);
64090+ atomic_inc_unchecked(&fscache_n_marks);
64091 #endif
64092
64093 _debug("- mark %p{%lx}", page, page->index);
64094diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
64095index 40d13c7..ddf52b9 100644
64096--- a/fs/fscache/stats.c
64097+++ b/fs/fscache/stats.c
64098@@ -18,99 +18,99 @@
64099 /*
64100 * operation counters
64101 */
64102-atomic_t fscache_n_op_pend;
64103-atomic_t fscache_n_op_run;
64104-atomic_t fscache_n_op_enqueue;
64105-atomic_t fscache_n_op_requeue;
64106-atomic_t fscache_n_op_deferred_release;
64107-atomic_t fscache_n_op_release;
64108-atomic_t fscache_n_op_gc;
64109-atomic_t fscache_n_op_cancelled;
64110-atomic_t fscache_n_op_rejected;
64111+atomic_unchecked_t fscache_n_op_pend;
64112+atomic_unchecked_t fscache_n_op_run;
64113+atomic_unchecked_t fscache_n_op_enqueue;
64114+atomic_unchecked_t fscache_n_op_requeue;
64115+atomic_unchecked_t fscache_n_op_deferred_release;
64116+atomic_unchecked_t fscache_n_op_release;
64117+atomic_unchecked_t fscache_n_op_gc;
64118+atomic_unchecked_t fscache_n_op_cancelled;
64119+atomic_unchecked_t fscache_n_op_rejected;
64120
64121-atomic_t fscache_n_attr_changed;
64122-atomic_t fscache_n_attr_changed_ok;
64123-atomic_t fscache_n_attr_changed_nobufs;
64124-atomic_t fscache_n_attr_changed_nomem;
64125-atomic_t fscache_n_attr_changed_calls;
64126+atomic_unchecked_t fscache_n_attr_changed;
64127+atomic_unchecked_t fscache_n_attr_changed_ok;
64128+atomic_unchecked_t fscache_n_attr_changed_nobufs;
64129+atomic_unchecked_t fscache_n_attr_changed_nomem;
64130+atomic_unchecked_t fscache_n_attr_changed_calls;
64131
64132-atomic_t fscache_n_allocs;
64133-atomic_t fscache_n_allocs_ok;
64134-atomic_t fscache_n_allocs_wait;
64135-atomic_t fscache_n_allocs_nobufs;
64136-atomic_t fscache_n_allocs_intr;
64137-atomic_t fscache_n_allocs_object_dead;
64138-atomic_t fscache_n_alloc_ops;
64139-atomic_t fscache_n_alloc_op_waits;
64140+atomic_unchecked_t fscache_n_allocs;
64141+atomic_unchecked_t fscache_n_allocs_ok;
64142+atomic_unchecked_t fscache_n_allocs_wait;
64143+atomic_unchecked_t fscache_n_allocs_nobufs;
64144+atomic_unchecked_t fscache_n_allocs_intr;
64145+atomic_unchecked_t fscache_n_allocs_object_dead;
64146+atomic_unchecked_t fscache_n_alloc_ops;
64147+atomic_unchecked_t fscache_n_alloc_op_waits;
64148
64149-atomic_t fscache_n_retrievals;
64150-atomic_t fscache_n_retrievals_ok;
64151-atomic_t fscache_n_retrievals_wait;
64152-atomic_t fscache_n_retrievals_nodata;
64153-atomic_t fscache_n_retrievals_nobufs;
64154-atomic_t fscache_n_retrievals_intr;
64155-atomic_t fscache_n_retrievals_nomem;
64156-atomic_t fscache_n_retrievals_object_dead;
64157-atomic_t fscache_n_retrieval_ops;
64158-atomic_t fscache_n_retrieval_op_waits;
64159+atomic_unchecked_t fscache_n_retrievals;
64160+atomic_unchecked_t fscache_n_retrievals_ok;
64161+atomic_unchecked_t fscache_n_retrievals_wait;
64162+atomic_unchecked_t fscache_n_retrievals_nodata;
64163+atomic_unchecked_t fscache_n_retrievals_nobufs;
64164+atomic_unchecked_t fscache_n_retrievals_intr;
64165+atomic_unchecked_t fscache_n_retrievals_nomem;
64166+atomic_unchecked_t fscache_n_retrievals_object_dead;
64167+atomic_unchecked_t fscache_n_retrieval_ops;
64168+atomic_unchecked_t fscache_n_retrieval_op_waits;
64169
64170-atomic_t fscache_n_stores;
64171-atomic_t fscache_n_stores_ok;
64172-atomic_t fscache_n_stores_again;
64173-atomic_t fscache_n_stores_nobufs;
64174-atomic_t fscache_n_stores_oom;
64175-atomic_t fscache_n_store_ops;
64176-atomic_t fscache_n_store_calls;
64177-atomic_t fscache_n_store_pages;
64178-atomic_t fscache_n_store_radix_deletes;
64179-atomic_t fscache_n_store_pages_over_limit;
64180+atomic_unchecked_t fscache_n_stores;
64181+atomic_unchecked_t fscache_n_stores_ok;
64182+atomic_unchecked_t fscache_n_stores_again;
64183+atomic_unchecked_t fscache_n_stores_nobufs;
64184+atomic_unchecked_t fscache_n_stores_oom;
64185+atomic_unchecked_t fscache_n_store_ops;
64186+atomic_unchecked_t fscache_n_store_calls;
64187+atomic_unchecked_t fscache_n_store_pages;
64188+atomic_unchecked_t fscache_n_store_radix_deletes;
64189+atomic_unchecked_t fscache_n_store_pages_over_limit;
64190
64191-atomic_t fscache_n_store_vmscan_not_storing;
64192-atomic_t fscache_n_store_vmscan_gone;
64193-atomic_t fscache_n_store_vmscan_busy;
64194-atomic_t fscache_n_store_vmscan_cancelled;
64195-atomic_t fscache_n_store_vmscan_wait;
64196+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
64197+atomic_unchecked_t fscache_n_store_vmscan_gone;
64198+atomic_unchecked_t fscache_n_store_vmscan_busy;
64199+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
64200+atomic_unchecked_t fscache_n_store_vmscan_wait;
64201
64202-atomic_t fscache_n_marks;
64203-atomic_t fscache_n_uncaches;
64204+atomic_unchecked_t fscache_n_marks;
64205+atomic_unchecked_t fscache_n_uncaches;
64206
64207-atomic_t fscache_n_acquires;
64208-atomic_t fscache_n_acquires_null;
64209-atomic_t fscache_n_acquires_no_cache;
64210-atomic_t fscache_n_acquires_ok;
64211-atomic_t fscache_n_acquires_nobufs;
64212-atomic_t fscache_n_acquires_oom;
64213+atomic_unchecked_t fscache_n_acquires;
64214+atomic_unchecked_t fscache_n_acquires_null;
64215+atomic_unchecked_t fscache_n_acquires_no_cache;
64216+atomic_unchecked_t fscache_n_acquires_ok;
64217+atomic_unchecked_t fscache_n_acquires_nobufs;
64218+atomic_unchecked_t fscache_n_acquires_oom;
64219
64220-atomic_t fscache_n_invalidates;
64221-atomic_t fscache_n_invalidates_run;
64222+atomic_unchecked_t fscache_n_invalidates;
64223+atomic_unchecked_t fscache_n_invalidates_run;
64224
64225-atomic_t fscache_n_updates;
64226-atomic_t fscache_n_updates_null;
64227-atomic_t fscache_n_updates_run;
64228+atomic_unchecked_t fscache_n_updates;
64229+atomic_unchecked_t fscache_n_updates_null;
64230+atomic_unchecked_t fscache_n_updates_run;
64231
64232-atomic_t fscache_n_relinquishes;
64233-atomic_t fscache_n_relinquishes_null;
64234-atomic_t fscache_n_relinquishes_waitcrt;
64235-atomic_t fscache_n_relinquishes_retire;
64236+atomic_unchecked_t fscache_n_relinquishes;
64237+atomic_unchecked_t fscache_n_relinquishes_null;
64238+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
64239+atomic_unchecked_t fscache_n_relinquishes_retire;
64240
64241-atomic_t fscache_n_cookie_index;
64242-atomic_t fscache_n_cookie_data;
64243-atomic_t fscache_n_cookie_special;
64244+atomic_unchecked_t fscache_n_cookie_index;
64245+atomic_unchecked_t fscache_n_cookie_data;
64246+atomic_unchecked_t fscache_n_cookie_special;
64247
64248-atomic_t fscache_n_object_alloc;
64249-atomic_t fscache_n_object_no_alloc;
64250-atomic_t fscache_n_object_lookups;
64251-atomic_t fscache_n_object_lookups_negative;
64252-atomic_t fscache_n_object_lookups_positive;
64253-atomic_t fscache_n_object_lookups_timed_out;
64254-atomic_t fscache_n_object_created;
64255-atomic_t fscache_n_object_avail;
64256-atomic_t fscache_n_object_dead;
64257+atomic_unchecked_t fscache_n_object_alloc;
64258+atomic_unchecked_t fscache_n_object_no_alloc;
64259+atomic_unchecked_t fscache_n_object_lookups;
64260+atomic_unchecked_t fscache_n_object_lookups_negative;
64261+atomic_unchecked_t fscache_n_object_lookups_positive;
64262+atomic_unchecked_t fscache_n_object_lookups_timed_out;
64263+atomic_unchecked_t fscache_n_object_created;
64264+atomic_unchecked_t fscache_n_object_avail;
64265+atomic_unchecked_t fscache_n_object_dead;
64266
64267-atomic_t fscache_n_checkaux_none;
64268-atomic_t fscache_n_checkaux_okay;
64269-atomic_t fscache_n_checkaux_update;
64270-atomic_t fscache_n_checkaux_obsolete;
64271+atomic_unchecked_t fscache_n_checkaux_none;
64272+atomic_unchecked_t fscache_n_checkaux_okay;
64273+atomic_unchecked_t fscache_n_checkaux_update;
64274+atomic_unchecked_t fscache_n_checkaux_obsolete;
64275
64276 atomic_t fscache_n_cop_alloc_object;
64277 atomic_t fscache_n_cop_lookup_object;
64278@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
64279 seq_puts(m, "FS-Cache statistics\n");
64280
64281 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
64282- atomic_read(&fscache_n_cookie_index),
64283- atomic_read(&fscache_n_cookie_data),
64284- atomic_read(&fscache_n_cookie_special));
64285+ atomic_read_unchecked(&fscache_n_cookie_index),
64286+ atomic_read_unchecked(&fscache_n_cookie_data),
64287+ atomic_read_unchecked(&fscache_n_cookie_special));
64288
64289 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
64290- atomic_read(&fscache_n_object_alloc),
64291- atomic_read(&fscache_n_object_no_alloc),
64292- atomic_read(&fscache_n_object_avail),
64293- atomic_read(&fscache_n_object_dead));
64294+ atomic_read_unchecked(&fscache_n_object_alloc),
64295+ atomic_read_unchecked(&fscache_n_object_no_alloc),
64296+ atomic_read_unchecked(&fscache_n_object_avail),
64297+ atomic_read_unchecked(&fscache_n_object_dead));
64298 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
64299- atomic_read(&fscache_n_checkaux_none),
64300- atomic_read(&fscache_n_checkaux_okay),
64301- atomic_read(&fscache_n_checkaux_update),
64302- atomic_read(&fscache_n_checkaux_obsolete));
64303+ atomic_read_unchecked(&fscache_n_checkaux_none),
64304+ atomic_read_unchecked(&fscache_n_checkaux_okay),
64305+ atomic_read_unchecked(&fscache_n_checkaux_update),
64306+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
64307
64308 seq_printf(m, "Pages : mrk=%u unc=%u\n",
64309- atomic_read(&fscache_n_marks),
64310- atomic_read(&fscache_n_uncaches));
64311+ atomic_read_unchecked(&fscache_n_marks),
64312+ atomic_read_unchecked(&fscache_n_uncaches));
64313
64314 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
64315 " oom=%u\n",
64316- atomic_read(&fscache_n_acquires),
64317- atomic_read(&fscache_n_acquires_null),
64318- atomic_read(&fscache_n_acquires_no_cache),
64319- atomic_read(&fscache_n_acquires_ok),
64320- atomic_read(&fscache_n_acquires_nobufs),
64321- atomic_read(&fscache_n_acquires_oom));
64322+ atomic_read_unchecked(&fscache_n_acquires),
64323+ atomic_read_unchecked(&fscache_n_acquires_null),
64324+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
64325+ atomic_read_unchecked(&fscache_n_acquires_ok),
64326+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
64327+ atomic_read_unchecked(&fscache_n_acquires_oom));
64328
64329 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
64330- atomic_read(&fscache_n_object_lookups),
64331- atomic_read(&fscache_n_object_lookups_negative),
64332- atomic_read(&fscache_n_object_lookups_positive),
64333- atomic_read(&fscache_n_object_created),
64334- atomic_read(&fscache_n_object_lookups_timed_out));
64335+ atomic_read_unchecked(&fscache_n_object_lookups),
64336+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
64337+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
64338+ atomic_read_unchecked(&fscache_n_object_created),
64339+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
64340
64341 seq_printf(m, "Invals : n=%u run=%u\n",
64342- atomic_read(&fscache_n_invalidates),
64343- atomic_read(&fscache_n_invalidates_run));
64344+ atomic_read_unchecked(&fscache_n_invalidates),
64345+ atomic_read_unchecked(&fscache_n_invalidates_run));
64346
64347 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
64348- atomic_read(&fscache_n_updates),
64349- atomic_read(&fscache_n_updates_null),
64350- atomic_read(&fscache_n_updates_run));
64351+ atomic_read_unchecked(&fscache_n_updates),
64352+ atomic_read_unchecked(&fscache_n_updates_null),
64353+ atomic_read_unchecked(&fscache_n_updates_run));
64354
64355 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
64356- atomic_read(&fscache_n_relinquishes),
64357- atomic_read(&fscache_n_relinquishes_null),
64358- atomic_read(&fscache_n_relinquishes_waitcrt),
64359- atomic_read(&fscache_n_relinquishes_retire));
64360+ atomic_read_unchecked(&fscache_n_relinquishes),
64361+ atomic_read_unchecked(&fscache_n_relinquishes_null),
64362+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
64363+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
64364
64365 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
64366- atomic_read(&fscache_n_attr_changed),
64367- atomic_read(&fscache_n_attr_changed_ok),
64368- atomic_read(&fscache_n_attr_changed_nobufs),
64369- atomic_read(&fscache_n_attr_changed_nomem),
64370- atomic_read(&fscache_n_attr_changed_calls));
64371+ atomic_read_unchecked(&fscache_n_attr_changed),
64372+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
64373+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
64374+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
64375+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
64376
64377 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
64378- atomic_read(&fscache_n_allocs),
64379- atomic_read(&fscache_n_allocs_ok),
64380- atomic_read(&fscache_n_allocs_wait),
64381- atomic_read(&fscache_n_allocs_nobufs),
64382- atomic_read(&fscache_n_allocs_intr));
64383+ atomic_read_unchecked(&fscache_n_allocs),
64384+ atomic_read_unchecked(&fscache_n_allocs_ok),
64385+ atomic_read_unchecked(&fscache_n_allocs_wait),
64386+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
64387+ atomic_read_unchecked(&fscache_n_allocs_intr));
64388 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
64389- atomic_read(&fscache_n_alloc_ops),
64390- atomic_read(&fscache_n_alloc_op_waits),
64391- atomic_read(&fscache_n_allocs_object_dead));
64392+ atomic_read_unchecked(&fscache_n_alloc_ops),
64393+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
64394+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
64395
64396 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
64397 " int=%u oom=%u\n",
64398- atomic_read(&fscache_n_retrievals),
64399- atomic_read(&fscache_n_retrievals_ok),
64400- atomic_read(&fscache_n_retrievals_wait),
64401- atomic_read(&fscache_n_retrievals_nodata),
64402- atomic_read(&fscache_n_retrievals_nobufs),
64403- atomic_read(&fscache_n_retrievals_intr),
64404- atomic_read(&fscache_n_retrievals_nomem));
64405+ atomic_read_unchecked(&fscache_n_retrievals),
64406+ atomic_read_unchecked(&fscache_n_retrievals_ok),
64407+ atomic_read_unchecked(&fscache_n_retrievals_wait),
64408+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
64409+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
64410+ atomic_read_unchecked(&fscache_n_retrievals_intr),
64411+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
64412 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
64413- atomic_read(&fscache_n_retrieval_ops),
64414- atomic_read(&fscache_n_retrieval_op_waits),
64415- atomic_read(&fscache_n_retrievals_object_dead));
64416+ atomic_read_unchecked(&fscache_n_retrieval_ops),
64417+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
64418+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
64419
64420 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
64421- atomic_read(&fscache_n_stores),
64422- atomic_read(&fscache_n_stores_ok),
64423- atomic_read(&fscache_n_stores_again),
64424- atomic_read(&fscache_n_stores_nobufs),
64425- atomic_read(&fscache_n_stores_oom));
64426+ atomic_read_unchecked(&fscache_n_stores),
64427+ atomic_read_unchecked(&fscache_n_stores_ok),
64428+ atomic_read_unchecked(&fscache_n_stores_again),
64429+ atomic_read_unchecked(&fscache_n_stores_nobufs),
64430+ atomic_read_unchecked(&fscache_n_stores_oom));
64431 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
64432- atomic_read(&fscache_n_store_ops),
64433- atomic_read(&fscache_n_store_calls),
64434- atomic_read(&fscache_n_store_pages),
64435- atomic_read(&fscache_n_store_radix_deletes),
64436- atomic_read(&fscache_n_store_pages_over_limit));
64437+ atomic_read_unchecked(&fscache_n_store_ops),
64438+ atomic_read_unchecked(&fscache_n_store_calls),
64439+ atomic_read_unchecked(&fscache_n_store_pages),
64440+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
64441+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
64442
64443 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
64444- atomic_read(&fscache_n_store_vmscan_not_storing),
64445- atomic_read(&fscache_n_store_vmscan_gone),
64446- atomic_read(&fscache_n_store_vmscan_busy),
64447- atomic_read(&fscache_n_store_vmscan_cancelled),
64448- atomic_read(&fscache_n_store_vmscan_wait));
64449+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
64450+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
64451+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
64452+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
64453+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
64454
64455 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
64456- atomic_read(&fscache_n_op_pend),
64457- atomic_read(&fscache_n_op_run),
64458- atomic_read(&fscache_n_op_enqueue),
64459- atomic_read(&fscache_n_op_cancelled),
64460- atomic_read(&fscache_n_op_rejected));
64461+ atomic_read_unchecked(&fscache_n_op_pend),
64462+ atomic_read_unchecked(&fscache_n_op_run),
64463+ atomic_read_unchecked(&fscache_n_op_enqueue),
64464+ atomic_read_unchecked(&fscache_n_op_cancelled),
64465+ atomic_read_unchecked(&fscache_n_op_rejected));
64466 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
64467- atomic_read(&fscache_n_op_deferred_release),
64468- atomic_read(&fscache_n_op_release),
64469- atomic_read(&fscache_n_op_gc));
64470+ atomic_read_unchecked(&fscache_n_op_deferred_release),
64471+ atomic_read_unchecked(&fscache_n_op_release),
64472+ atomic_read_unchecked(&fscache_n_op_gc));
64473
64474 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
64475 atomic_read(&fscache_n_cop_alloc_object),
64476diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
64477index 966ace8..030a03a 100644
64478--- a/fs/fuse/cuse.c
64479+++ b/fs/fuse/cuse.c
64480@@ -611,10 +611,12 @@ static int __init cuse_init(void)
64481 INIT_LIST_HEAD(&cuse_conntbl[i]);
64482
64483 /* inherit and extend fuse_dev_operations */
64484- cuse_channel_fops = fuse_dev_operations;
64485- cuse_channel_fops.owner = THIS_MODULE;
64486- cuse_channel_fops.open = cuse_channel_open;
64487- cuse_channel_fops.release = cuse_channel_release;
64488+ pax_open_kernel();
64489+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
64490+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
64491+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
64492+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
64493+ pax_close_kernel();
64494
64495 cuse_class = class_create(THIS_MODULE, "cuse");
64496 if (IS_ERR(cuse_class))
64497diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
64498index ca88731..8e9c55d 100644
64499--- a/fs/fuse/dev.c
64500+++ b/fs/fuse/dev.c
64501@@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
64502 ret = 0;
64503 pipe_lock(pipe);
64504
64505- if (!pipe->readers) {
64506+ if (!atomic_read(&pipe->readers)) {
64507 send_sig(SIGPIPE, current, 0);
64508 if (!ret)
64509 ret = -EPIPE;
64510@@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
64511 page_nr++;
64512 ret += buf->len;
64513
64514- if (pipe->files)
64515+ if (atomic_read(&pipe->files))
64516 do_wakeup = 1;
64517 }
64518
64519diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
64520index 0c60482..025724f 100644
64521--- a/fs/fuse/dir.c
64522+++ b/fs/fuse/dir.c
64523@@ -1485,7 +1485,7 @@ static char *read_link(struct dentry *dentry)
64524 return link;
64525 }
64526
64527-static void free_link(char *link)
64528+static void free_link(const char *link)
64529 {
64530 if (!IS_ERR(link))
64531 free_page((unsigned long) link);
64532diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
64533index bb529f3..454c253 100644
64534--- a/fs/hostfs/hostfs_kern.c
64535+++ b/fs/hostfs/hostfs_kern.c
64536@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
64537
64538 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
64539 {
64540- char *s = nd_get_link(nd);
64541+ const char *s = nd_get_link(nd);
64542 if (!IS_ERR(s))
64543 __putname(s);
64544 }
64545diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
64546index 1e2872b..7aea000 100644
64547--- a/fs/hugetlbfs/inode.c
64548+++ b/fs/hugetlbfs/inode.c
64549@@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64550 struct mm_struct *mm = current->mm;
64551 struct vm_area_struct *vma;
64552 struct hstate *h = hstate_file(file);
64553+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
64554 struct vm_unmapped_area_info info;
64555
64556 if (len & ~huge_page_mask(h))
64557@@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64558 return addr;
64559 }
64560
64561+#ifdef CONFIG_PAX_RANDMMAP
64562+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
64563+#endif
64564+
64565 if (addr) {
64566 addr = ALIGN(addr, huge_page_size(h));
64567 vma = find_vma(mm, addr);
64568- if (TASK_SIZE - len >= addr &&
64569- (!vma || addr + len <= vma->vm_start))
64570+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
64571 return addr;
64572 }
64573
64574 info.flags = 0;
64575 info.length = len;
64576 info.low_limit = TASK_UNMAPPED_BASE;
64577+
64578+#ifdef CONFIG_PAX_RANDMMAP
64579+ if (mm->pax_flags & MF_PAX_RANDMMAP)
64580+ info.low_limit += mm->delta_mmap;
64581+#endif
64582+
64583 info.high_limit = TASK_SIZE;
64584 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
64585 info.align_offset = 0;
64586@@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
64587 };
64588 MODULE_ALIAS_FS("hugetlbfs");
64589
64590-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64591+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64592
64593 static int can_do_hugetlb_shm(void)
64594 {
64595diff --git a/fs/inode.c b/fs/inode.c
64596index 6eecb7f..abec305 100644
64597--- a/fs/inode.c
64598+++ b/fs/inode.c
64599@@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
64600 unsigned int *p = &get_cpu_var(last_ino);
64601 unsigned int res = *p;
64602
64603+start:
64604+
64605 #ifdef CONFIG_SMP
64606 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
64607- static atomic_t shared_last_ino;
64608- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
64609+ static atomic_unchecked_t shared_last_ino;
64610+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
64611
64612 res = next - LAST_INO_BATCH;
64613 }
64614 #endif
64615
64616- *p = ++res;
64617+ if (unlikely(!++res))
64618+ goto start; /* never zero */
64619+ *p = res;
64620 put_cpu_var(last_ino);
64621 return res;
64622 }
64623diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
64624index 4556ce1..5ddaf86 100644
64625--- a/fs/isofs/inode.c
64626+++ b/fs/isofs/inode.c
64627@@ -61,7 +61,7 @@ static void isofs_put_super(struct super_block *sb)
64628 return;
64629 }
64630
64631-static int isofs_read_inode(struct inode *);
64632+static int isofs_read_inode(struct inode *, int relocated);
64633 static int isofs_statfs (struct dentry *, struct kstatfs *);
64634
64635 static struct kmem_cache *isofs_inode_cachep;
64636@@ -1259,7 +1259,7 @@ out_toomany:
64637 goto out;
64638 }
64639
64640-static int isofs_read_inode(struct inode *inode)
64641+static int isofs_read_inode(struct inode *inode, int relocated)
64642 {
64643 struct super_block *sb = inode->i_sb;
64644 struct isofs_sb_info *sbi = ISOFS_SB(sb);
64645@@ -1404,7 +1404,7 @@ static int isofs_read_inode(struct inode *inode)
64646 */
64647
64648 if (!high_sierra) {
64649- parse_rock_ridge_inode(de, inode);
64650+ parse_rock_ridge_inode(de, inode, relocated);
64651 /* if we want uid/gid set, override the rock ridge setting */
64652 if (sbi->s_uid_set)
64653 inode->i_uid = sbi->s_uid;
64654@@ -1483,9 +1483,10 @@ static int isofs_iget5_set(struct inode *ino, void *data)
64655 * offset that point to the underlying meta-data for the inode. The
64656 * code below is otherwise similar to the iget() code in
64657 * include/linux/fs.h */
64658-struct inode *isofs_iget(struct super_block *sb,
64659- unsigned long block,
64660- unsigned long offset)
64661+struct inode *__isofs_iget(struct super_block *sb,
64662+ unsigned long block,
64663+ unsigned long offset,
64664+ int relocated)
64665 {
64666 unsigned long hashval;
64667 struct inode *inode;
64668@@ -1507,7 +1508,7 @@ struct inode *isofs_iget(struct super_block *sb,
64669 return ERR_PTR(-ENOMEM);
64670
64671 if (inode->i_state & I_NEW) {
64672- ret = isofs_read_inode(inode);
64673+ ret = isofs_read_inode(inode, relocated);
64674 if (ret < 0) {
64675 iget_failed(inode);
64676 inode = ERR_PTR(ret);
64677diff --git a/fs/isofs/isofs.h b/fs/isofs/isofs.h
64678index 9916723..0ac4c1f 100644
64679--- a/fs/isofs/isofs.h
64680+++ b/fs/isofs/isofs.h
64681@@ -107,7 +107,7 @@ extern int iso_date(char *, int);
64682
64683 struct inode; /* To make gcc happy */
64684
64685-extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *);
64686+extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *, int relocated);
64687 extern int get_rock_ridge_filename(struct iso_directory_record *, char *, struct inode *);
64688 extern int isofs_name_translate(struct iso_directory_record *, char *, struct inode *);
64689
64690@@ -118,9 +118,24 @@ extern struct dentry *isofs_lookup(struct inode *, struct dentry *, unsigned int
64691 extern struct buffer_head *isofs_bread(struct inode *, sector_t);
64692 extern int isofs_get_blocks(struct inode *, sector_t, struct buffer_head **, unsigned long);
64693
64694-extern struct inode *isofs_iget(struct super_block *sb,
64695- unsigned long block,
64696- unsigned long offset);
64697+struct inode *__isofs_iget(struct super_block *sb,
64698+ unsigned long block,
64699+ unsigned long offset,
64700+ int relocated);
64701+
64702+static inline struct inode *isofs_iget(struct super_block *sb,
64703+ unsigned long block,
64704+ unsigned long offset)
64705+{
64706+ return __isofs_iget(sb, block, offset, 0);
64707+}
64708+
64709+static inline struct inode *isofs_iget_reloc(struct super_block *sb,
64710+ unsigned long block,
64711+ unsigned long offset)
64712+{
64713+ return __isofs_iget(sb, block, offset, 1);
64714+}
64715
64716 /* Because the inode number is no longer relevant to finding the
64717 * underlying meta-data for an inode, we are free to choose a more
64718diff --git a/fs/isofs/rock.c b/fs/isofs/rock.c
64719index c0bf424..f488bba 100644
64720--- a/fs/isofs/rock.c
64721+++ b/fs/isofs/rock.c
64722@@ -288,12 +288,16 @@ eio:
64723 goto out;
64724 }
64725
64726+#define RR_REGARD_XA 1
64727+#define RR_RELOC_DE 2
64728+
64729 static int
64730 parse_rock_ridge_inode_internal(struct iso_directory_record *de,
64731- struct inode *inode, int regard_xa)
64732+ struct inode *inode, int flags)
64733 {
64734 int symlink_len = 0;
64735 int cnt, sig;
64736+ unsigned int reloc_block;
64737 struct inode *reloc;
64738 struct rock_ridge *rr;
64739 int rootflag;
64740@@ -305,7 +309,7 @@ parse_rock_ridge_inode_internal(struct iso_directory_record *de,
64741
64742 init_rock_state(&rs, inode);
64743 setup_rock_ridge(de, inode, &rs);
64744- if (regard_xa) {
64745+ if (flags & RR_REGARD_XA) {
64746 rs.chr += 14;
64747 rs.len -= 14;
64748 if (rs.len < 0)
64749@@ -485,12 +489,22 @@ repeat:
64750 "relocated directory\n");
64751 goto out;
64752 case SIG('C', 'L'):
64753- ISOFS_I(inode)->i_first_extent =
64754- isonum_733(rr->u.CL.location);
64755- reloc =
64756- isofs_iget(inode->i_sb,
64757- ISOFS_I(inode)->i_first_extent,
64758- 0);
64759+ if (flags & RR_RELOC_DE) {
64760+ printk(KERN_ERR
64761+ "ISOFS: Recursive directory relocation "
64762+ "is not supported\n");
64763+ goto eio;
64764+ }
64765+ reloc_block = isonum_733(rr->u.CL.location);
64766+ if (reloc_block == ISOFS_I(inode)->i_iget5_block &&
64767+ ISOFS_I(inode)->i_iget5_offset == 0) {
64768+ printk(KERN_ERR
64769+ "ISOFS: Directory relocation points to "
64770+ "itself\n");
64771+ goto eio;
64772+ }
64773+ ISOFS_I(inode)->i_first_extent = reloc_block;
64774+ reloc = isofs_iget_reloc(inode->i_sb, reloc_block, 0);
64775 if (IS_ERR(reloc)) {
64776 ret = PTR_ERR(reloc);
64777 goto out;
64778@@ -637,9 +651,11 @@ static char *get_symlink_chunk(char *rpnt, struct rock_ridge *rr, char *plimit)
64779 return rpnt;
64780 }
64781
64782-int parse_rock_ridge_inode(struct iso_directory_record *de, struct inode *inode)
64783+int parse_rock_ridge_inode(struct iso_directory_record *de, struct inode *inode,
64784+ int relocated)
64785 {
64786- int result = parse_rock_ridge_inode_internal(de, inode, 0);
64787+ int flags = relocated ? RR_RELOC_DE : 0;
64788+ int result = parse_rock_ridge_inode_internal(de, inode, flags);
64789
64790 /*
64791 * if rockridge flag was reset and we didn't look for attributes
64792@@ -647,7 +663,8 @@ int parse_rock_ridge_inode(struct iso_directory_record *de, struct inode *inode)
64793 */
64794 if ((ISOFS_SB(inode->i_sb)->s_rock_offset == -1)
64795 && (ISOFS_SB(inode->i_sb)->s_rock == 2)) {
64796- result = parse_rock_ridge_inode_internal(de, inode, 14);
64797+ result = parse_rock_ridge_inode_internal(de, inode,
64798+ flags | RR_REGARD_XA);
64799 }
64800 return result;
64801 }
64802diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
64803index 4a6cf28..d3a29d3 100644
64804--- a/fs/jffs2/erase.c
64805+++ b/fs/jffs2/erase.c
64806@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
64807 struct jffs2_unknown_node marker = {
64808 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
64809 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64810- .totlen = cpu_to_je32(c->cleanmarker_size)
64811+ .totlen = cpu_to_je32(c->cleanmarker_size),
64812+ .hdr_crc = cpu_to_je32(0)
64813 };
64814
64815 jffs2_prealloc_raw_node_refs(c, jeb, 1);
64816diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
64817index a6597d6..41b30ec 100644
64818--- a/fs/jffs2/wbuf.c
64819+++ b/fs/jffs2/wbuf.c
64820@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
64821 {
64822 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
64823 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64824- .totlen = constant_cpu_to_je32(8)
64825+ .totlen = constant_cpu_to_je32(8),
64826+ .hdr_crc = constant_cpu_to_je32(0)
64827 };
64828
64829 /*
64830diff --git a/fs/jfs/super.c b/fs/jfs/super.c
64831index adf8cb0..bb935fa 100644
64832--- a/fs/jfs/super.c
64833+++ b/fs/jfs/super.c
64834@@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
64835
64836 jfs_inode_cachep =
64837 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
64838- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
64839+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
64840 init_once);
64841 if (jfs_inode_cachep == NULL)
64842 return -ENOMEM;
64843diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
64844index a693f5b..82276a1 100644
64845--- a/fs/kernfs/dir.c
64846+++ b/fs/kernfs/dir.c
64847@@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
64848 *
64849 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64850 */
64851-static unsigned int kernfs_name_hash(const char *name, const void *ns)
64852+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
64853 {
64854 unsigned long hash = init_name_hash();
64855 unsigned int len = strlen(name);
64856diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
64857index d895b4b..0b8af77 100644
64858--- a/fs/kernfs/file.c
64859+++ b/fs/kernfs/file.c
64860@@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
64861
64862 struct kernfs_open_node {
64863 atomic_t refcnt;
64864- atomic_t event;
64865+ atomic_unchecked_t event;
64866 wait_queue_head_t poll;
64867 struct list_head files; /* goes through kernfs_open_file.list */
64868 };
64869@@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
64870 {
64871 struct kernfs_open_file *of = sf->private;
64872
64873- of->event = atomic_read(&of->kn->attr.open->event);
64874+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
64875
64876 return of->kn->attr.ops->seq_show(sf, v);
64877 }
64878@@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
64879 return ret;
64880 }
64881
64882-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64883- void *buf, int len, int write)
64884+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64885+ void *buf, size_t len, int write)
64886 {
64887 struct file *file = vma->vm_file;
64888 struct kernfs_open_file *of = kernfs_of(file);
64889- int ret;
64890+ ssize_t ret;
64891
64892 if (!of->vm_ops)
64893 return -EINVAL;
64894@@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
64895 return -ENOMEM;
64896
64897 atomic_set(&new_on->refcnt, 0);
64898- atomic_set(&new_on->event, 1);
64899+ atomic_set_unchecked(&new_on->event, 1);
64900 init_waitqueue_head(&new_on->poll);
64901 INIT_LIST_HEAD(&new_on->files);
64902 goto retry;
64903@@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
64904
64905 kernfs_put_active(kn);
64906
64907- if (of->event != atomic_read(&on->event))
64908+ if (of->event != atomic_read_unchecked(&on->event))
64909 goto trigger;
64910
64911 return DEFAULT_POLLMASK;
64912@@ -818,7 +818,7 @@ repeat:
64913
64914 on = kn->attr.open;
64915 if (on) {
64916- atomic_inc(&on->event);
64917+ atomic_inc_unchecked(&on->event);
64918 wake_up_interruptible(&on->poll);
64919 }
64920
64921diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
64922index 8a19889..4c3069a 100644
64923--- a/fs/kernfs/symlink.c
64924+++ b/fs/kernfs/symlink.c
64925@@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
64926 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
64927 void *cookie)
64928 {
64929- char *page = nd_get_link(nd);
64930+ const char *page = nd_get_link(nd);
64931 if (!IS_ERR(page))
64932 free_page((unsigned long)page);
64933 }
64934diff --git a/fs/libfs.c b/fs/libfs.c
64935index 88e3e00..979c262 100644
64936--- a/fs/libfs.c
64937+++ b/fs/libfs.c
64938@@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64939
64940 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
64941 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
64942+ char d_name[sizeof(next->d_iname)];
64943+ const unsigned char *name;
64944+
64945 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
64946 if (!simple_positive(next)) {
64947 spin_unlock(&next->d_lock);
64948@@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64949
64950 spin_unlock(&next->d_lock);
64951 spin_unlock(&dentry->d_lock);
64952- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
64953+ name = next->d_name.name;
64954+ if (name == next->d_iname) {
64955+ memcpy(d_name, name, next->d_name.len);
64956+ name = d_name;
64957+ }
64958+ if (!dir_emit(ctx, name, next->d_name.len,
64959 next->d_inode->i_ino, dt_type(next->d_inode)))
64960 return 0;
64961 spin_lock(&dentry->d_lock);
64962@@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
64963 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
64964 void *cookie)
64965 {
64966- char *s = nd_get_link(nd);
64967+ const char *s = nd_get_link(nd);
64968 if (!IS_ERR(s))
64969 kfree(s);
64970 }
64971diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
64972index acd3947..1f896e2 100644
64973--- a/fs/lockd/clntproc.c
64974+++ b/fs/lockd/clntproc.c
64975@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
64976 /*
64977 * Cookie counter for NLM requests
64978 */
64979-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64980+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64981
64982 void nlmclnt_next_cookie(struct nlm_cookie *c)
64983 {
64984- u32 cookie = atomic_inc_return(&nlm_cookie);
64985+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64986
64987 memcpy(c->data, &cookie, 4);
64988 c->len=4;
64989diff --git a/fs/locks.c b/fs/locks.c
64990index 717fbc4..74628c3 100644
64991--- a/fs/locks.c
64992+++ b/fs/locks.c
64993@@ -2327,7 +2327,7 @@ void locks_remove_file(struct file *filp)
64994 locks_remove_posix(filp, (fl_owner_t)filp);
64995
64996 if (filp->f_op->flock) {
64997- struct file_lock fl = {
64998+ struct file_lock flock = {
64999 .fl_owner = (fl_owner_t)filp,
65000 .fl_pid = current->tgid,
65001 .fl_file = filp,
65002@@ -2335,9 +2335,9 @@ void locks_remove_file(struct file *filp)
65003 .fl_type = F_UNLCK,
65004 .fl_end = OFFSET_MAX,
65005 };
65006- filp->f_op->flock(filp, F_SETLKW, &fl);
65007- if (fl.fl_ops && fl.fl_ops->fl_release_private)
65008- fl.fl_ops->fl_release_private(&fl);
65009+ filp->f_op->flock(filp, F_SETLKW, &flock);
65010+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
65011+ flock.fl_ops->fl_release_private(&flock);
65012 }
65013
65014 spin_lock(&inode->i_lock);
65015diff --git a/fs/mount.h b/fs/mount.h
65016index d55297f..f5b28c5 100644
65017--- a/fs/mount.h
65018+++ b/fs/mount.h
65019@@ -11,7 +11,7 @@ struct mnt_namespace {
65020 u64 seq; /* Sequence number to prevent loops */
65021 wait_queue_head_t poll;
65022 u64 event;
65023-};
65024+} __randomize_layout;
65025
65026 struct mnt_pcp {
65027 int mnt_count;
65028@@ -57,7 +57,7 @@ struct mount {
65029 int mnt_expiry_mark; /* true if marked for expiry */
65030 int mnt_pinned;
65031 struct path mnt_ex_mountpoint;
65032-};
65033+} __randomize_layout;
65034
65035 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
65036
65037diff --git a/fs/namei.c b/fs/namei.c
65038index 9eb787e..5f520b67 100644
65039--- a/fs/namei.c
65040+++ b/fs/namei.c
65041@@ -330,17 +330,32 @@ int generic_permission(struct inode *inode, int mask)
65042 if (ret != -EACCES)
65043 return ret;
65044
65045+#ifdef CONFIG_GRKERNSEC
65046+ /* we'll block if we have to log due to a denied capability use */
65047+ if (mask & MAY_NOT_BLOCK)
65048+ return -ECHILD;
65049+#endif
65050+
65051 if (S_ISDIR(inode->i_mode)) {
65052 /* DACs are overridable for directories */
65053- if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
65054- return 0;
65055 if (!(mask & MAY_WRITE))
65056- if (capable_wrt_inode_uidgid(inode,
65057- CAP_DAC_READ_SEARCH))
65058+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
65059+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
65060 return 0;
65061+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
65062+ return 0;
65063 return -EACCES;
65064 }
65065 /*
65066+ * Searching includes executable on directories, else just read.
65067+ */
65068+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
65069+ if (mask == MAY_READ)
65070+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
65071+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
65072+ return 0;
65073+
65074+ /*
65075 * Read/write DACs are always overridable.
65076 * Executable DACs are overridable when there is
65077 * at least one exec bit set.
65078@@ -349,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
65079 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
65080 return 0;
65081
65082- /*
65083- * Searching includes executable on directories, else just read.
65084- */
65085- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
65086- if (mask == MAY_READ)
65087- if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
65088- return 0;
65089-
65090 return -EACCES;
65091 }
65092 EXPORT_SYMBOL(generic_permission);
65093@@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
65094 {
65095 struct dentry *dentry = link->dentry;
65096 int error;
65097- char *s;
65098+ const char *s;
65099
65100 BUG_ON(nd->flags & LOOKUP_RCU);
65101
65102@@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
65103 if (error)
65104 goto out_put_nd_path;
65105
65106+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
65107+ dentry->d_inode, dentry, nd->path.mnt)) {
65108+ error = -EACCES;
65109+ goto out_put_nd_path;
65110+ }
65111+
65112 nd->last_type = LAST_BIND;
65113 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
65114 error = PTR_ERR(*p);
65115@@ -1596,6 +1609,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
65116 if (res)
65117 break;
65118 res = walk_component(nd, path, LOOKUP_FOLLOW);
65119+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
65120+ res = -EACCES;
65121 put_link(nd, &link, cookie);
65122 } while (res > 0);
65123
65124@@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
65125 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
65126 {
65127 unsigned long a, b, adata, bdata, mask, hash, len;
65128- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
65129+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
65130
65131 hash = a = 0;
65132 len = -sizeof(unsigned long);
65133@@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
65134 if (err)
65135 break;
65136 err = lookup_last(nd, &path);
65137+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
65138+ err = -EACCES;
65139 put_link(nd, &link, cookie);
65140 }
65141 }
65142@@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
65143 if (!err)
65144 err = complete_walk(nd);
65145
65146+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
65147+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
65148+ path_put(&nd->path);
65149+ err = -ENOENT;
65150+ }
65151+ }
65152+
65153 if (!err && nd->flags & LOOKUP_DIRECTORY) {
65154 if (!d_can_lookup(nd->path.dentry)) {
65155 path_put(&nd->path);
65156@@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
65157 retval = path_lookupat(dfd, name->name,
65158 flags | LOOKUP_REVAL, nd);
65159
65160- if (likely(!retval))
65161+ if (likely(!retval)) {
65162 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
65163+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
65164+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
65165+ path_put(&nd->path);
65166+ return -ENOENT;
65167+ }
65168+ }
65169+ }
65170 return retval;
65171 }
65172
65173@@ -2570,6 +2601,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
65174 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
65175 return -EPERM;
65176
65177+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
65178+ return -EPERM;
65179+ if (gr_handle_rawio(inode))
65180+ return -EPERM;
65181+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
65182+ return -EACCES;
65183+
65184 return 0;
65185 }
65186
65187@@ -2801,7 +2839,7 @@ looked_up:
65188 * cleared otherwise prior to returning.
65189 */
65190 static int lookup_open(struct nameidata *nd, struct path *path,
65191- struct file *file,
65192+ struct path *link, struct file *file,
65193 const struct open_flags *op,
65194 bool got_write, int *opened)
65195 {
65196@@ -2836,6 +2874,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
65197 /* Negative dentry, just create the file */
65198 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
65199 umode_t mode = op->mode;
65200+
65201+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
65202+ error = -EACCES;
65203+ goto out_dput;
65204+ }
65205+
65206+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
65207+ error = -EACCES;
65208+ goto out_dput;
65209+ }
65210+
65211 if (!IS_POSIXACL(dir->d_inode))
65212 mode &= ~current_umask();
65213 /*
65214@@ -2857,6 +2906,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
65215 nd->flags & LOOKUP_EXCL);
65216 if (error)
65217 goto out_dput;
65218+ else
65219+ gr_handle_create(dentry, nd->path.mnt);
65220 }
65221 out_no_open:
65222 path->dentry = dentry;
65223@@ -2871,7 +2922,7 @@ out_dput:
65224 /*
65225 * Handle the last step of open()
65226 */
65227-static int do_last(struct nameidata *nd, struct path *path,
65228+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
65229 struct file *file, const struct open_flags *op,
65230 int *opened, struct filename *name)
65231 {
65232@@ -2921,6 +2972,15 @@ static int do_last(struct nameidata *nd, struct path *path,
65233 if (error)
65234 return error;
65235
65236+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
65237+ error = -ENOENT;
65238+ goto out;
65239+ }
65240+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
65241+ error = -EACCES;
65242+ goto out;
65243+ }
65244+
65245 audit_inode(name, dir, LOOKUP_PARENT);
65246 error = -EISDIR;
65247 /* trailing slashes? */
65248@@ -2940,7 +3000,7 @@ retry_lookup:
65249 */
65250 }
65251 mutex_lock(&dir->d_inode->i_mutex);
65252- error = lookup_open(nd, path, file, op, got_write, opened);
65253+ error = lookup_open(nd, path, link, file, op, got_write, opened);
65254 mutex_unlock(&dir->d_inode->i_mutex);
65255
65256 if (error <= 0) {
65257@@ -2964,11 +3024,28 @@ retry_lookup:
65258 goto finish_open_created;
65259 }
65260
65261+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
65262+ error = -ENOENT;
65263+ goto exit_dput;
65264+ }
65265+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
65266+ error = -EACCES;
65267+ goto exit_dput;
65268+ }
65269+
65270 /*
65271 * create/update audit record if it already exists.
65272 */
65273- if (d_is_positive(path->dentry))
65274+ if (d_is_positive(path->dentry)) {
65275+ /* only check if O_CREAT is specified, all other checks need to go
65276+ into may_open */
65277+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
65278+ error = -EACCES;
65279+ goto exit_dput;
65280+ }
65281+
65282 audit_inode(name, path->dentry, 0);
65283+ }
65284
65285 /*
65286 * If atomic_open() acquired write access it is dropped now due to
65287@@ -3009,6 +3086,11 @@ finish_lookup:
65288 }
65289 }
65290 BUG_ON(inode != path->dentry->d_inode);
65291+ /* if we're resolving a symlink to another symlink */
65292+ if (link && gr_handle_symlink_owner(link, inode)) {
65293+ error = -EACCES;
65294+ goto out;
65295+ }
65296 return 1;
65297 }
65298
65299@@ -3018,7 +3100,6 @@ finish_lookup:
65300 save_parent.dentry = nd->path.dentry;
65301 save_parent.mnt = mntget(path->mnt);
65302 nd->path.dentry = path->dentry;
65303-
65304 }
65305 nd->inode = inode;
65306 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
65307@@ -3028,7 +3109,18 @@ finish_open:
65308 path_put(&save_parent);
65309 return error;
65310 }
65311+
65312+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
65313+ error = -ENOENT;
65314+ goto out;
65315+ }
65316+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
65317+ error = -EACCES;
65318+ goto out;
65319+ }
65320+
65321 audit_inode(name, nd->path.dentry, 0);
65322+
65323 error = -EISDIR;
65324 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
65325 goto out;
65326@@ -3191,7 +3283,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
65327 if (unlikely(error))
65328 goto out;
65329
65330- error = do_last(nd, &path, file, op, &opened, pathname);
65331+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
65332 while (unlikely(error > 0)) { /* trailing symlink */
65333 struct path link = path;
65334 void *cookie;
65335@@ -3209,7 +3301,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
65336 error = follow_link(&link, nd, &cookie);
65337 if (unlikely(error))
65338 break;
65339- error = do_last(nd, &path, file, op, &opened, pathname);
65340+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
65341 put_link(nd, &link, cookie);
65342 }
65343 out:
65344@@ -3309,9 +3401,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
65345 goto unlock;
65346
65347 error = -EEXIST;
65348- if (d_is_positive(dentry))
65349+ if (d_is_positive(dentry)) {
65350+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
65351+ error = -ENOENT;
65352 goto fail;
65353-
65354+ }
65355 /*
65356 * Special case - lookup gave negative, but... we had foo/bar/
65357 * From the vfs_mknod() POV we just have a negative dentry -
65358@@ -3363,6 +3457,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
65359 }
65360 EXPORT_SYMBOL(user_path_create);
65361
65362+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
65363+{
65364+ struct filename *tmp = getname(pathname);
65365+ struct dentry *res;
65366+ if (IS_ERR(tmp))
65367+ return ERR_CAST(tmp);
65368+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
65369+ if (IS_ERR(res))
65370+ putname(tmp);
65371+ else
65372+ *to = tmp;
65373+ return res;
65374+}
65375+
65376 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
65377 {
65378 int error = may_create(dir, dentry);
65379@@ -3426,6 +3534,17 @@ retry:
65380
65381 if (!IS_POSIXACL(path.dentry->d_inode))
65382 mode &= ~current_umask();
65383+
65384+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
65385+ error = -EPERM;
65386+ goto out;
65387+ }
65388+
65389+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
65390+ error = -EACCES;
65391+ goto out;
65392+ }
65393+
65394 error = security_path_mknod(&path, dentry, mode, dev);
65395 if (error)
65396 goto out;
65397@@ -3442,6 +3561,8 @@ retry:
65398 break;
65399 }
65400 out:
65401+ if (!error)
65402+ gr_handle_create(dentry, path.mnt);
65403 done_path_create(&path, dentry);
65404 if (retry_estale(error, lookup_flags)) {
65405 lookup_flags |= LOOKUP_REVAL;
65406@@ -3495,9 +3616,16 @@ retry:
65407
65408 if (!IS_POSIXACL(path.dentry->d_inode))
65409 mode &= ~current_umask();
65410+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
65411+ error = -EACCES;
65412+ goto out;
65413+ }
65414 error = security_path_mkdir(&path, dentry, mode);
65415 if (!error)
65416 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
65417+ if (!error)
65418+ gr_handle_create(dentry, path.mnt);
65419+out:
65420 done_path_create(&path, dentry);
65421 if (retry_estale(error, lookup_flags)) {
65422 lookup_flags |= LOOKUP_REVAL;
65423@@ -3580,6 +3708,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
65424 struct filename *name;
65425 struct dentry *dentry;
65426 struct nameidata nd;
65427+ ino_t saved_ino = 0;
65428+ dev_t saved_dev = 0;
65429 unsigned int lookup_flags = 0;
65430 retry:
65431 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
65432@@ -3612,10 +3742,21 @@ retry:
65433 error = -ENOENT;
65434 goto exit3;
65435 }
65436+
65437+ saved_ino = dentry->d_inode->i_ino;
65438+ saved_dev = gr_get_dev_from_dentry(dentry);
65439+
65440+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
65441+ error = -EACCES;
65442+ goto exit3;
65443+ }
65444+
65445 error = security_path_rmdir(&nd.path, dentry);
65446 if (error)
65447 goto exit3;
65448 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
65449+ if (!error && (saved_dev || saved_ino))
65450+ gr_handle_delete(saved_ino, saved_dev);
65451 exit3:
65452 dput(dentry);
65453 exit2:
65454@@ -3706,6 +3847,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
65455 struct nameidata nd;
65456 struct inode *inode = NULL;
65457 struct inode *delegated_inode = NULL;
65458+ ino_t saved_ino = 0;
65459+ dev_t saved_dev = 0;
65460 unsigned int lookup_flags = 0;
65461 retry:
65462 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
65463@@ -3732,10 +3875,22 @@ retry_deleg:
65464 if (d_is_negative(dentry))
65465 goto slashes;
65466 ihold(inode);
65467+
65468+ if (inode->i_nlink <= 1) {
65469+ saved_ino = inode->i_ino;
65470+ saved_dev = gr_get_dev_from_dentry(dentry);
65471+ }
65472+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
65473+ error = -EACCES;
65474+ goto exit2;
65475+ }
65476+
65477 error = security_path_unlink(&nd.path, dentry);
65478 if (error)
65479 goto exit2;
65480 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
65481+ if (!error && (saved_ino || saved_dev))
65482+ gr_handle_delete(saved_ino, saved_dev);
65483 exit2:
65484 dput(dentry);
65485 }
65486@@ -3824,9 +3979,17 @@ retry:
65487 if (IS_ERR(dentry))
65488 goto out_putname;
65489
65490+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
65491+ error = -EACCES;
65492+ goto out;
65493+ }
65494+
65495 error = security_path_symlink(&path, dentry, from->name);
65496 if (!error)
65497 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
65498+ if (!error)
65499+ gr_handle_create(dentry, path.mnt);
65500+out:
65501 done_path_create(&path, dentry);
65502 if (retry_estale(error, lookup_flags)) {
65503 lookup_flags |= LOOKUP_REVAL;
65504@@ -3930,6 +4093,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
65505 struct dentry *new_dentry;
65506 struct path old_path, new_path;
65507 struct inode *delegated_inode = NULL;
65508+ struct filename *to = NULL;
65509 int how = 0;
65510 int error;
65511
65512@@ -3953,7 +4117,7 @@ retry:
65513 if (error)
65514 return error;
65515
65516- new_dentry = user_path_create(newdfd, newname, &new_path,
65517+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
65518 (how & LOOKUP_REVAL));
65519 error = PTR_ERR(new_dentry);
65520 if (IS_ERR(new_dentry))
65521@@ -3965,11 +4129,28 @@ retry:
65522 error = may_linkat(&old_path);
65523 if (unlikely(error))
65524 goto out_dput;
65525+
65526+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
65527+ old_path.dentry->d_inode,
65528+ old_path.dentry->d_inode->i_mode, to)) {
65529+ error = -EACCES;
65530+ goto out_dput;
65531+ }
65532+
65533+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
65534+ old_path.dentry, old_path.mnt, to)) {
65535+ error = -EACCES;
65536+ goto out_dput;
65537+ }
65538+
65539 error = security_path_link(old_path.dentry, &new_path, new_dentry);
65540 if (error)
65541 goto out_dput;
65542 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
65543+ if (!error)
65544+ gr_handle_create(new_dentry, new_path.mnt);
65545 out_dput:
65546+ putname(to);
65547 done_path_create(&new_path, new_dentry);
65548 if (delegated_inode) {
65549 error = break_deleg_wait(&delegated_inode);
65550@@ -4279,6 +4460,12 @@ retry_deleg:
65551 if (new_dentry == trap)
65552 goto exit5;
65553
65554+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
65555+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
65556+ to, flags);
65557+ if (error)
65558+ goto exit5;
65559+
65560 error = security_path_rename(&oldnd.path, old_dentry,
65561 &newnd.path, new_dentry, flags);
65562 if (error)
65563@@ -4286,6 +4473,9 @@ retry_deleg:
65564 error = vfs_rename(old_dir->d_inode, old_dentry,
65565 new_dir->d_inode, new_dentry,
65566 &delegated_inode, flags);
65567+ if (!error)
65568+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
65569+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
65570 exit5:
65571 dput(new_dentry);
65572 exit4:
65573@@ -4328,14 +4518,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
65574
65575 int readlink_copy(char __user *buffer, int buflen, const char *link)
65576 {
65577+ char tmpbuf[64];
65578+ const char *newlink;
65579 int len = PTR_ERR(link);
65580+
65581 if (IS_ERR(link))
65582 goto out;
65583
65584 len = strlen(link);
65585 if (len > (unsigned) buflen)
65586 len = buflen;
65587- if (copy_to_user(buffer, link, len))
65588+
65589+ if (len < sizeof(tmpbuf)) {
65590+ memcpy(tmpbuf, link, len);
65591+ newlink = tmpbuf;
65592+ } else
65593+ newlink = link;
65594+
65595+ if (copy_to_user(buffer, newlink, len))
65596 len = -EFAULT;
65597 out:
65598 return len;
65599diff --git a/fs/namespace.c b/fs/namespace.c
65600index 182bc41..72e3cf1 100644
65601--- a/fs/namespace.c
65602+++ b/fs/namespace.c
65603@@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
65604 if (!(sb->s_flags & MS_RDONLY))
65605 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
65606 up_write(&sb->s_umount);
65607+
65608+ gr_log_remount(mnt->mnt_devname, retval);
65609+
65610 return retval;
65611 }
65612
65613@@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
65614 }
65615 unlock_mount_hash();
65616 namespace_unlock();
65617+
65618+ gr_log_unmount(mnt->mnt_devname, retval);
65619+
65620 return retval;
65621 }
65622
65623@@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
65624 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
65625 */
65626
65627-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
65628+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
65629 {
65630 struct path path;
65631 struct mount *mnt;
65632@@ -1431,7 +1437,7 @@ out:
65633 /*
65634 * The 2.0 compatible umount. No flags.
65635 */
65636-SYSCALL_DEFINE1(oldumount, char __user *, name)
65637+SYSCALL_DEFINE1(oldumount, const char __user *, name)
65638 {
65639 return sys_umount(name, 0);
65640 }
65641@@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
65642 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
65643 MS_STRICTATIME);
65644
65645+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
65646+ retval = -EPERM;
65647+ goto dput_out;
65648+ }
65649+
65650+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
65651+ retval = -EPERM;
65652+ goto dput_out;
65653+ }
65654+
65655 if (flags & MS_REMOUNT)
65656 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
65657 data_page);
65658@@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
65659 dev_name, data_page);
65660 dput_out:
65661 path_put(&path);
65662+
65663+ gr_log_mount(dev_name, dir_name, retval);
65664+
65665 return retval;
65666 }
65667
65668@@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
65669 * number incrementing at 10Ghz will take 12,427 years to wrap which
65670 * is effectively never, so we can ignore the possibility.
65671 */
65672-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
65673+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
65674
65675 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65676 {
65677@@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65678 kfree(new_ns);
65679 return ERR_PTR(ret);
65680 }
65681- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
65682+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
65683 atomic_set(&new_ns->count, 1);
65684 new_ns->root = NULL;
65685 INIT_LIST_HEAD(&new_ns->list);
65686@@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65687 return new_ns;
65688 }
65689
65690-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65691+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65692 struct user_namespace *user_ns, struct fs_struct *new_fs)
65693 {
65694 struct mnt_namespace *new_ns;
65695@@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
65696 }
65697 EXPORT_SYMBOL(mount_subtree);
65698
65699-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
65700- char __user *, type, unsigned long, flags, void __user *, data)
65701+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
65702+ const char __user *, type, unsigned long, flags, void __user *, data)
65703 {
65704 int ret;
65705 char *kernel_type;
65706@@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
65707 if (error)
65708 goto out2;
65709
65710+ if (gr_handle_chroot_pivot()) {
65711+ error = -EPERM;
65712+ goto out2;
65713+ }
65714+
65715 get_fs_root(current->fs, &root);
65716 old_mp = lock_mount(&old);
65717 error = PTR_ERR(old_mp);
65718@@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
65719 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
65720 return -EPERM;
65721
65722- if (fs->users != 1)
65723+ if (atomic_read(&fs->users) != 1)
65724 return -EINVAL;
65725
65726 get_mnt_ns(mnt_ns);
65727diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
65728index f4ccfe6..a5cf064 100644
65729--- a/fs/nfs/callback_xdr.c
65730+++ b/fs/nfs/callback_xdr.c
65731@@ -51,7 +51,7 @@ struct callback_op {
65732 callback_decode_arg_t decode_args;
65733 callback_encode_res_t encode_res;
65734 long res_maxsize;
65735-};
65736+} __do_const;
65737
65738 static struct callback_op callback_ops[];
65739
65740diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
65741index 9927913..faffc5c 100644
65742--- a/fs/nfs/inode.c
65743+++ b/fs/nfs/inode.c
65744@@ -1219,16 +1219,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
65745 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
65746 }
65747
65748-static atomic_long_t nfs_attr_generation_counter;
65749+static atomic_long_unchecked_t nfs_attr_generation_counter;
65750
65751 static unsigned long nfs_read_attr_generation_counter(void)
65752 {
65753- return atomic_long_read(&nfs_attr_generation_counter);
65754+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
65755 }
65756
65757 unsigned long nfs_inc_attr_generation_counter(void)
65758 {
65759- return atomic_long_inc_return(&nfs_attr_generation_counter);
65760+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
65761 }
65762
65763 void nfs_fattr_init(struct nfs_fattr *fattr)
65764diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
65765index 8f854dd..d0fec26 100644
65766--- a/fs/nfs/nfs3acl.c
65767+++ b/fs/nfs/nfs3acl.c
65768@@ -256,7 +256,7 @@ nfs3_list_one_acl(struct inode *inode, int type, const char *name, void *data,
65769 char *p = data + *result;
65770
65771 acl = get_acl(inode, type);
65772- if (!acl)
65773+ if (IS_ERR_OR_NULL(acl))
65774 return 0;
65775
65776 posix_acl_release(acl);
65777diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
65778index 8f029db..3688b84 100644
65779--- a/fs/nfsd/nfs4proc.c
65780+++ b/fs/nfsd/nfs4proc.c
65781@@ -1157,7 +1157,7 @@ struct nfsd4_operation {
65782 nfsd4op_rsize op_rsize_bop;
65783 stateid_getter op_get_currentstateid;
65784 stateid_setter op_set_currentstateid;
65785-};
65786+} __do_const;
65787
65788 static struct nfsd4_operation nfsd4_ops[];
65789
65790diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
65791index 944275c..6fc40a7 100644
65792--- a/fs/nfsd/nfs4xdr.c
65793+++ b/fs/nfsd/nfs4xdr.c
65794@@ -1539,7 +1539,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
65795
65796 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
65797
65798-static nfsd4_dec nfsd4_dec_ops[] = {
65799+static const nfsd4_dec nfsd4_dec_ops[] = {
65800 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
65801 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
65802 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
65803diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
65804index 6040da8..4348565 100644
65805--- a/fs/nfsd/nfscache.c
65806+++ b/fs/nfsd/nfscache.c
65807@@ -518,17 +518,20 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65808 {
65809 struct svc_cacherep *rp = rqstp->rq_cacherep;
65810 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
65811- int len;
65812+ long len;
65813 size_t bufsize = 0;
65814
65815 if (!rp)
65816 return;
65817
65818- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
65819- len >>= 2;
65820+ if (statp) {
65821+ len = (char*)statp - (char*)resv->iov_base;
65822+ len = resv->iov_len - len;
65823+ len >>= 2;
65824+ }
65825
65826 /* Don't cache excessive amounts of data and XDR failures */
65827- if (!statp || len > (256 >> 2)) {
65828+ if (!statp || len > (256 >> 2) || len < 0) {
65829 nfsd_reply_cache_free(rp);
65830 return;
65831 }
65832@@ -536,7 +539,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65833 switch (cachetype) {
65834 case RC_REPLSTAT:
65835 if (len != 1)
65836- printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
65837+ printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
65838 rp->c_replstat = *statp;
65839 break;
65840 case RC_REPLBUFF:
65841diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
65842index 140c496..e9cbf14 100644
65843--- a/fs/nfsd/vfs.c
65844+++ b/fs/nfsd/vfs.c
65845@@ -855,7 +855,7 @@ int nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
65846
65847 oldfs = get_fs();
65848 set_fs(KERNEL_DS);
65849- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
65850+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
65851 set_fs(oldfs);
65852 return nfsd_finish_read(file, count, host_err);
65853 }
65854@@ -943,7 +943,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
65855
65856 /* Write the data. */
65857 oldfs = get_fs(); set_fs(KERNEL_DS);
65858- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
65859+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
65860 set_fs(oldfs);
65861 if (host_err < 0)
65862 goto out_nfserr;
65863@@ -1482,7 +1482,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
65864 */
65865
65866 oldfs = get_fs(); set_fs(KERNEL_DS);
65867- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
65868+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
65869 set_fs(oldfs);
65870
65871 if (host_err < 0)
65872diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
65873index 52ccd34..7a6b202 100644
65874--- a/fs/nls/nls_base.c
65875+++ b/fs/nls/nls_base.c
65876@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
65877
65878 int __register_nls(struct nls_table *nls, struct module *owner)
65879 {
65880- struct nls_table ** tmp = &tables;
65881+ struct nls_table *tmp = tables;
65882
65883 if (nls->next)
65884 return -EBUSY;
65885
65886- nls->owner = owner;
65887+ pax_open_kernel();
65888+ *(void **)&nls->owner = owner;
65889+ pax_close_kernel();
65890 spin_lock(&nls_lock);
65891- while (*tmp) {
65892- if (nls == *tmp) {
65893+ while (tmp) {
65894+ if (nls == tmp) {
65895 spin_unlock(&nls_lock);
65896 return -EBUSY;
65897 }
65898- tmp = &(*tmp)->next;
65899+ tmp = tmp->next;
65900 }
65901- nls->next = tables;
65902+ pax_open_kernel();
65903+ *(struct nls_table **)&nls->next = tables;
65904+ pax_close_kernel();
65905 tables = nls;
65906 spin_unlock(&nls_lock);
65907 return 0;
65908@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
65909
65910 int unregister_nls(struct nls_table * nls)
65911 {
65912- struct nls_table ** tmp = &tables;
65913+ struct nls_table * const * tmp = &tables;
65914
65915 spin_lock(&nls_lock);
65916 while (*tmp) {
65917 if (nls == *tmp) {
65918- *tmp = nls->next;
65919+ pax_open_kernel();
65920+ *(struct nls_table **)tmp = nls->next;
65921+ pax_close_kernel();
65922 spin_unlock(&nls_lock);
65923 return 0;
65924 }
65925@@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
65926 return -EINVAL;
65927 }
65928
65929-static struct nls_table *find_nls(char *charset)
65930+static struct nls_table *find_nls(const char *charset)
65931 {
65932 struct nls_table *nls;
65933 spin_lock(&nls_lock);
65934@@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
65935 return nls;
65936 }
65937
65938-struct nls_table *load_nls(char *charset)
65939+struct nls_table *load_nls(const char *charset)
65940 {
65941 return try_then_request_module(find_nls(charset), "nls_%s", charset);
65942 }
65943diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
65944index 162b3f1..6076a7c 100644
65945--- a/fs/nls/nls_euc-jp.c
65946+++ b/fs/nls/nls_euc-jp.c
65947@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
65948 p_nls = load_nls("cp932");
65949
65950 if (p_nls) {
65951- table.charset2upper = p_nls->charset2upper;
65952- table.charset2lower = p_nls->charset2lower;
65953+ pax_open_kernel();
65954+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65955+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65956+ pax_close_kernel();
65957 return register_nls(&table);
65958 }
65959
65960diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
65961index a80a741..7b96e1b 100644
65962--- a/fs/nls/nls_koi8-ru.c
65963+++ b/fs/nls/nls_koi8-ru.c
65964@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
65965 p_nls = load_nls("koi8-u");
65966
65967 if (p_nls) {
65968- table.charset2upper = p_nls->charset2upper;
65969- table.charset2lower = p_nls->charset2lower;
65970+ pax_open_kernel();
65971+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65972+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65973+ pax_close_kernel();
65974 return register_nls(&table);
65975 }
65976
65977diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
65978index 3fdc8a3..5888623 100644
65979--- a/fs/notify/fanotify/fanotify_user.c
65980+++ b/fs/notify/fanotify/fanotify_user.c
65981@@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
65982
65983 fd = fanotify_event_metadata.fd;
65984 ret = -EFAULT;
65985- if (copy_to_user(buf, &fanotify_event_metadata,
65986- fanotify_event_metadata.event_len))
65987+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
65988+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65989 goto out_close_fd;
65990
65991 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65992diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65993index 1e58402..bb2d6f4 100644
65994--- a/fs/notify/notification.c
65995+++ b/fs/notify/notification.c
65996@@ -48,7 +48,7 @@
65997 #include <linux/fsnotify_backend.h>
65998 #include "fsnotify.h"
65999
66000-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
66001+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
66002
66003 /**
66004 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
66005@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
66006 */
66007 u32 fsnotify_get_cookie(void)
66008 {
66009- return atomic_inc_return(&fsnotify_sync_cookie);
66010+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
66011 }
66012 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
66013
66014diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
66015index 9e38daf..5727cae 100644
66016--- a/fs/ntfs/dir.c
66017+++ b/fs/ntfs/dir.c
66018@@ -1310,7 +1310,7 @@ find_next_index_buffer:
66019 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
66020 ~(s64)(ndir->itype.index.block_size - 1)));
66021 /* Bounds checks. */
66022- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
66023+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
66024 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
66025 "inode 0x%lx or driver bug.", vdir->i_ino);
66026 goto err_out;
66027diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
66028index 5c9e2c8..96e4ba0 100644
66029--- a/fs/ntfs/file.c
66030+++ b/fs/ntfs/file.c
66031@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
66032 char *addr;
66033 size_t total = 0;
66034 unsigned len;
66035- int left;
66036+ unsigned left;
66037
66038 do {
66039 len = PAGE_CACHE_SIZE - ofs;
66040diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
66041index 6c3296e..c0b99f0 100644
66042--- a/fs/ntfs/super.c
66043+++ b/fs/ntfs/super.c
66044@@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
66045 if (!silent)
66046 ntfs_error(sb, "Primary boot sector is invalid.");
66047 } else if (!silent)
66048- ntfs_error(sb, read_err_str, "primary");
66049+ ntfs_error(sb, read_err_str, "%s", "primary");
66050 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
66051 if (bh_primary)
66052 brelse(bh_primary);
66053@@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
66054 goto hotfix_primary_boot_sector;
66055 brelse(bh_backup);
66056 } else if (!silent)
66057- ntfs_error(sb, read_err_str, "backup");
66058+ ntfs_error(sb, read_err_str, "%s", "backup");
66059 /* Try to read NT3.51- backup boot sector. */
66060 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
66061 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
66062@@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
66063 "sector.");
66064 brelse(bh_backup);
66065 } else if (!silent)
66066- ntfs_error(sb, read_err_str, "backup");
66067+ ntfs_error(sb, read_err_str, "%s", "backup");
66068 /* We failed. Cleanup and return. */
66069 if (bh_primary)
66070 brelse(bh_primary);
66071diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
66072index 0440134..d52c93a 100644
66073--- a/fs/ocfs2/localalloc.c
66074+++ b/fs/ocfs2/localalloc.c
66075@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
66076 goto bail;
66077 }
66078
66079- atomic_inc(&osb->alloc_stats.moves);
66080+ atomic_inc_unchecked(&osb->alloc_stats.moves);
66081
66082 bail:
66083 if (handle)
66084diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
66085index bbec539..7b266d5 100644
66086--- a/fs/ocfs2/ocfs2.h
66087+++ b/fs/ocfs2/ocfs2.h
66088@@ -236,11 +236,11 @@ enum ocfs2_vol_state
66089
66090 struct ocfs2_alloc_stats
66091 {
66092- atomic_t moves;
66093- atomic_t local_data;
66094- atomic_t bitmap_data;
66095- atomic_t bg_allocs;
66096- atomic_t bg_extends;
66097+ atomic_unchecked_t moves;
66098+ atomic_unchecked_t local_data;
66099+ atomic_unchecked_t bitmap_data;
66100+ atomic_unchecked_t bg_allocs;
66101+ atomic_unchecked_t bg_extends;
66102 };
66103
66104 enum ocfs2_local_alloc_state
66105diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
66106index 0cb889a..6a26b24 100644
66107--- a/fs/ocfs2/suballoc.c
66108+++ b/fs/ocfs2/suballoc.c
66109@@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
66110 mlog_errno(status);
66111 goto bail;
66112 }
66113- atomic_inc(&osb->alloc_stats.bg_extends);
66114+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
66115
66116 /* You should never ask for this much metadata */
66117 BUG_ON(bits_wanted >
66118@@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
66119 mlog_errno(status);
66120 goto bail;
66121 }
66122- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66123+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66124
66125 *suballoc_loc = res.sr_bg_blkno;
66126 *suballoc_bit_start = res.sr_bit_offset;
66127@@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
66128 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
66129 res->sr_bits);
66130
66131- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66132+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66133
66134 BUG_ON(res->sr_bits != 1);
66135
66136@@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
66137 mlog_errno(status);
66138 goto bail;
66139 }
66140- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66141+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66142
66143 BUG_ON(res.sr_bits != 1);
66144
66145@@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
66146 cluster_start,
66147 num_clusters);
66148 if (!status)
66149- atomic_inc(&osb->alloc_stats.local_data);
66150+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
66151 } else {
66152 if (min_clusters > (osb->bitmap_cpg - 1)) {
66153 /* The only paths asking for contiguousness
66154@@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
66155 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
66156 res.sr_bg_blkno,
66157 res.sr_bit_offset);
66158- atomic_inc(&osb->alloc_stats.bitmap_data);
66159+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
66160 *num_clusters = res.sr_bits;
66161 }
66162 }
66163diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
66164index ddb662b..f701c83 100644
66165--- a/fs/ocfs2/super.c
66166+++ b/fs/ocfs2/super.c
66167@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
66168 "%10s => GlobalAllocs: %d LocalAllocs: %d "
66169 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
66170 "Stats",
66171- atomic_read(&osb->alloc_stats.bitmap_data),
66172- atomic_read(&osb->alloc_stats.local_data),
66173- atomic_read(&osb->alloc_stats.bg_allocs),
66174- atomic_read(&osb->alloc_stats.moves),
66175- atomic_read(&osb->alloc_stats.bg_extends));
66176+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
66177+ atomic_read_unchecked(&osb->alloc_stats.local_data),
66178+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
66179+ atomic_read_unchecked(&osb->alloc_stats.moves),
66180+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
66181
66182 out += snprintf(buf + out, len - out,
66183 "%10s => State: %u Descriptor: %llu Size: %u bits "
66184@@ -2100,11 +2100,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
66185
66186 mutex_init(&osb->system_file_mutex);
66187
66188- atomic_set(&osb->alloc_stats.moves, 0);
66189- atomic_set(&osb->alloc_stats.local_data, 0);
66190- atomic_set(&osb->alloc_stats.bitmap_data, 0);
66191- atomic_set(&osb->alloc_stats.bg_allocs, 0);
66192- atomic_set(&osb->alloc_stats.bg_extends, 0);
66193+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
66194+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
66195+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
66196+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
66197+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
66198
66199 /* Copy the blockcheck stats from the superblock probe */
66200 osb->osb_ecc_stats = *stats;
66201diff --git a/fs/open.c b/fs/open.c
66202index d6fd3ac..6ccf474 100644
66203--- a/fs/open.c
66204+++ b/fs/open.c
66205@@ -32,6 +32,8 @@
66206 #include <linux/dnotify.h>
66207 #include <linux/compat.h>
66208
66209+#define CREATE_TRACE_POINTS
66210+#include <trace/events/fs.h>
66211 #include "internal.h"
66212
66213 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
66214@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
66215 error = locks_verify_truncate(inode, NULL, length);
66216 if (!error)
66217 error = security_path_truncate(path);
66218+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
66219+ error = -EACCES;
66220 if (!error)
66221 error = do_truncate(path->dentry, length, 0, NULL);
66222
66223@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
66224 error = locks_verify_truncate(inode, f.file, length);
66225 if (!error)
66226 error = security_path_truncate(&f.file->f_path);
66227+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
66228+ error = -EACCES;
66229 if (!error)
66230 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
66231 sb_end_write(inode->i_sb);
66232@@ -380,6 +386,9 @@ retry:
66233 if (__mnt_is_readonly(path.mnt))
66234 res = -EROFS;
66235
66236+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
66237+ res = -EACCES;
66238+
66239 out_path_release:
66240 path_put(&path);
66241 if (retry_estale(res, lookup_flags)) {
66242@@ -411,6 +420,8 @@ retry:
66243 if (error)
66244 goto dput_and_out;
66245
66246+ gr_log_chdir(path.dentry, path.mnt);
66247+
66248 set_fs_pwd(current->fs, &path);
66249
66250 dput_and_out:
66251@@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
66252 goto out_putf;
66253
66254 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
66255+
66256+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
66257+ error = -EPERM;
66258+
66259+ if (!error)
66260+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
66261+
66262 if (!error)
66263 set_fs_pwd(current->fs, &f.file->f_path);
66264 out_putf:
66265@@ -469,7 +487,13 @@ retry:
66266 if (error)
66267 goto dput_and_out;
66268
66269+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
66270+ goto dput_and_out;
66271+
66272 set_fs_root(current->fs, &path);
66273+
66274+ gr_handle_chroot_chdir(&path);
66275+
66276 error = 0;
66277 dput_and_out:
66278 path_put(&path);
66279@@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
66280 return error;
66281 retry_deleg:
66282 mutex_lock(&inode->i_mutex);
66283+
66284+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
66285+ error = -EACCES;
66286+ goto out_unlock;
66287+ }
66288+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
66289+ error = -EACCES;
66290+ goto out_unlock;
66291+ }
66292+
66293 error = security_path_chmod(path, mode);
66294 if (error)
66295 goto out_unlock;
66296@@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
66297 uid = make_kuid(current_user_ns(), user);
66298 gid = make_kgid(current_user_ns(), group);
66299
66300+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
66301+ return -EACCES;
66302+
66303 newattrs.ia_valid = ATTR_CTIME;
66304 if (user != (uid_t) -1) {
66305 if (!uid_valid(uid))
66306@@ -983,6 +1020,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
66307 } else {
66308 fsnotify_open(f);
66309 fd_install(fd, f);
66310+ trace_do_sys_open(tmp->name, flags, mode);
66311 }
66312 }
66313 putname(tmp);
66314diff --git a/fs/pipe.c b/fs/pipe.c
66315index 21981e5..3d5f55c 100644
66316--- a/fs/pipe.c
66317+++ b/fs/pipe.c
66318@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
66319
66320 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
66321 {
66322- if (pipe->files)
66323+ if (atomic_read(&pipe->files))
66324 mutex_lock_nested(&pipe->mutex, subclass);
66325 }
66326
66327@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
66328
66329 void pipe_unlock(struct pipe_inode_info *pipe)
66330 {
66331- if (pipe->files)
66332+ if (atomic_read(&pipe->files))
66333 mutex_unlock(&pipe->mutex);
66334 }
66335 EXPORT_SYMBOL(pipe_unlock);
66336@@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
66337 }
66338 if (bufs) /* More to do? */
66339 continue;
66340- if (!pipe->writers)
66341+ if (!atomic_read(&pipe->writers))
66342 break;
66343- if (!pipe->waiting_writers) {
66344+ if (!atomic_read(&pipe->waiting_writers)) {
66345 /* syscall merging: Usually we must not sleep
66346 * if O_NONBLOCK is set, or if we got some data.
66347 * But if a writer sleeps in kernel space, then
66348@@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66349
66350 __pipe_lock(pipe);
66351
66352- if (!pipe->readers) {
66353+ if (!atomic_read(&pipe->readers)) {
66354 send_sig(SIGPIPE, current, 0);
66355 ret = -EPIPE;
66356 goto out;
66357@@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66358 for (;;) {
66359 int bufs;
66360
66361- if (!pipe->readers) {
66362+ if (!atomic_read(&pipe->readers)) {
66363 send_sig(SIGPIPE, current, 0);
66364 if (!ret)
66365 ret = -EPIPE;
66366@@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66367 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
66368 do_wakeup = 0;
66369 }
66370- pipe->waiting_writers++;
66371+ atomic_inc(&pipe->waiting_writers);
66372 pipe_wait(pipe);
66373- pipe->waiting_writers--;
66374+ atomic_dec(&pipe->waiting_writers);
66375 }
66376 out:
66377 __pipe_unlock(pipe);
66378@@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
66379 mask = 0;
66380 if (filp->f_mode & FMODE_READ) {
66381 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
66382- if (!pipe->writers && filp->f_version != pipe->w_counter)
66383+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
66384 mask |= POLLHUP;
66385 }
66386
66387@@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
66388 * Most Unices do not set POLLERR for FIFOs but on Linux they
66389 * behave exactly like pipes for poll().
66390 */
66391- if (!pipe->readers)
66392+ if (!atomic_read(&pipe->readers))
66393 mask |= POLLERR;
66394 }
66395
66396@@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
66397 int kill = 0;
66398
66399 spin_lock(&inode->i_lock);
66400- if (!--pipe->files) {
66401+ if (atomic_dec_and_test(&pipe->files)) {
66402 inode->i_pipe = NULL;
66403 kill = 1;
66404 }
66405@@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
66406
66407 __pipe_lock(pipe);
66408 if (file->f_mode & FMODE_READ)
66409- pipe->readers--;
66410+ atomic_dec(&pipe->readers);
66411 if (file->f_mode & FMODE_WRITE)
66412- pipe->writers--;
66413+ atomic_dec(&pipe->writers);
66414
66415- if (pipe->readers || pipe->writers) {
66416+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
66417 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
66418 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
66419 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
66420@@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
66421 kfree(pipe);
66422 }
66423
66424-static struct vfsmount *pipe_mnt __read_mostly;
66425+struct vfsmount *pipe_mnt __read_mostly;
66426
66427 /*
66428 * pipefs_dname() is called from d_path().
66429@@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
66430 goto fail_iput;
66431
66432 inode->i_pipe = pipe;
66433- pipe->files = 2;
66434- pipe->readers = pipe->writers = 1;
66435+ atomic_set(&pipe->files, 2);
66436+ atomic_set(&pipe->readers, 1);
66437+ atomic_set(&pipe->writers, 1);
66438 inode->i_fop = &pipefifo_fops;
66439
66440 /*
66441@@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
66442 spin_lock(&inode->i_lock);
66443 if (inode->i_pipe) {
66444 pipe = inode->i_pipe;
66445- pipe->files++;
66446+ atomic_inc(&pipe->files);
66447 spin_unlock(&inode->i_lock);
66448 } else {
66449 spin_unlock(&inode->i_lock);
66450 pipe = alloc_pipe_info();
66451 if (!pipe)
66452 return -ENOMEM;
66453- pipe->files = 1;
66454+ atomic_set(&pipe->files, 1);
66455 spin_lock(&inode->i_lock);
66456 if (unlikely(inode->i_pipe)) {
66457- inode->i_pipe->files++;
66458+ atomic_inc(&inode->i_pipe->files);
66459 spin_unlock(&inode->i_lock);
66460 free_pipe_info(pipe);
66461 pipe = inode->i_pipe;
66462@@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
66463 * opened, even when there is no process writing the FIFO.
66464 */
66465 pipe->r_counter++;
66466- if (pipe->readers++ == 0)
66467+ if (atomic_inc_return(&pipe->readers) == 1)
66468 wake_up_partner(pipe);
66469
66470- if (!is_pipe && !pipe->writers) {
66471+ if (!is_pipe && !atomic_read(&pipe->writers)) {
66472 if ((filp->f_flags & O_NONBLOCK)) {
66473 /* suppress POLLHUP until we have
66474 * seen a writer */
66475@@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
66476 * errno=ENXIO when there is no process reading the FIFO.
66477 */
66478 ret = -ENXIO;
66479- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
66480+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
66481 goto err;
66482
66483 pipe->w_counter++;
66484- if (!pipe->writers++)
66485+ if (atomic_inc_return(&pipe->writers) == 1)
66486 wake_up_partner(pipe);
66487
66488- if (!is_pipe && !pipe->readers) {
66489+ if (!is_pipe && !atomic_read(&pipe->readers)) {
66490 if (wait_for_partner(pipe, &pipe->r_counter))
66491 goto err_wr;
66492 }
66493@@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
66494 * the process can at least talk to itself.
66495 */
66496
66497- pipe->readers++;
66498- pipe->writers++;
66499+ atomic_inc(&pipe->readers);
66500+ atomic_inc(&pipe->writers);
66501 pipe->r_counter++;
66502 pipe->w_counter++;
66503- if (pipe->readers == 1 || pipe->writers == 1)
66504+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
66505 wake_up_partner(pipe);
66506 break;
66507
66508@@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
66509 return 0;
66510
66511 err_rd:
66512- if (!--pipe->readers)
66513+ if (atomic_dec_and_test(&pipe->readers))
66514 wake_up_interruptible(&pipe->wait);
66515 ret = -ERESTARTSYS;
66516 goto err;
66517
66518 err_wr:
66519- if (!--pipe->writers)
66520+ if (atomic_dec_and_test(&pipe->writers))
66521 wake_up_interruptible(&pipe->wait);
66522 ret = -ERESTARTSYS;
66523 goto err;
66524diff --git a/fs/posix_acl.c b/fs/posix_acl.c
66525index 0855f77..6787d50 100644
66526--- a/fs/posix_acl.c
66527+++ b/fs/posix_acl.c
66528@@ -20,6 +20,7 @@
66529 #include <linux/xattr.h>
66530 #include <linux/export.h>
66531 #include <linux/user_namespace.h>
66532+#include <linux/grsecurity.h>
66533
66534 struct posix_acl **acl_by_type(struct inode *inode, int type)
66535 {
66536@@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
66537 }
66538 }
66539 if (mode_p)
66540- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
66541+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
66542 return not_equiv;
66543 }
66544 EXPORT_SYMBOL(posix_acl_equiv_mode);
66545@@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
66546 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
66547 }
66548
66549- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
66550+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
66551 return not_equiv;
66552 }
66553
66554@@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
66555 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
66556 int err = -ENOMEM;
66557 if (clone) {
66558+ *mode_p &= ~gr_acl_umask();
66559+
66560 err = posix_acl_create_masq(clone, mode_p);
66561 if (err < 0) {
66562 posix_acl_release(clone);
66563@@ -659,11 +662,12 @@ struct posix_acl *
66564 posix_acl_from_xattr(struct user_namespace *user_ns,
66565 const void *value, size_t size)
66566 {
66567- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
66568- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
66569+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
66570+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
66571 int count;
66572 struct posix_acl *acl;
66573 struct posix_acl_entry *acl_e;
66574+ umode_t umask = gr_acl_umask();
66575
66576 if (!value)
66577 return NULL;
66578@@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
66579
66580 switch(acl_e->e_tag) {
66581 case ACL_USER_OBJ:
66582+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
66583+ break;
66584 case ACL_GROUP_OBJ:
66585 case ACL_MASK:
66586+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
66587+ break;
66588 case ACL_OTHER:
66589+ acl_e->e_perm &= ~(umask & S_IRWXO);
66590 break;
66591
66592 case ACL_USER:
66593+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
66594 acl_e->e_uid =
66595 make_kuid(user_ns,
66596 le32_to_cpu(entry->e_id));
66597@@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
66598 goto fail;
66599 break;
66600 case ACL_GROUP:
66601+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
66602 acl_e->e_gid =
66603 make_kgid(user_ns,
66604 le32_to_cpu(entry->e_id));
66605diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
66606index 2183fcf..3c32a98 100644
66607--- a/fs/proc/Kconfig
66608+++ b/fs/proc/Kconfig
66609@@ -30,7 +30,7 @@ config PROC_FS
66610
66611 config PROC_KCORE
66612 bool "/proc/kcore support" if !ARM
66613- depends on PROC_FS && MMU
66614+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
66615 help
66616 Provides a virtual ELF core file of the live kernel. This can
66617 be read with gdb and other ELF tools. No modifications can be
66618@@ -38,8 +38,8 @@ config PROC_KCORE
66619
66620 config PROC_VMCORE
66621 bool "/proc/vmcore support"
66622- depends on PROC_FS && CRASH_DUMP
66623- default y
66624+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
66625+ default n
66626 help
66627 Exports the dump image of crashed kernel in ELF format.
66628
66629@@ -63,8 +63,8 @@ config PROC_SYSCTL
66630 limited in memory.
66631
66632 config PROC_PAGE_MONITOR
66633- default y
66634- depends on PROC_FS && MMU
66635+ default n
66636+ depends on PROC_FS && MMU && !GRKERNSEC
66637 bool "Enable /proc page monitoring" if EXPERT
66638 help
66639 Various /proc files exist to monitor process memory utilization:
66640diff --git a/fs/proc/array.c b/fs/proc/array.c
66641index 64db2bc..a8185d6 100644
66642--- a/fs/proc/array.c
66643+++ b/fs/proc/array.c
66644@@ -60,6 +60,7 @@
66645 #include <linux/tty.h>
66646 #include <linux/string.h>
66647 #include <linux/mman.h>
66648+#include <linux/grsecurity.h>
66649 #include <linux/proc_fs.h>
66650 #include <linux/ioport.h>
66651 #include <linux/uaccess.h>
66652@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
66653 seq_putc(m, '\n');
66654 }
66655
66656+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66657+static inline void task_pax(struct seq_file *m, struct task_struct *p)
66658+{
66659+ if (p->mm)
66660+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
66661+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
66662+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
66663+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
66664+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
66665+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
66666+ else
66667+ seq_printf(m, "PaX:\t-----\n");
66668+}
66669+#endif
66670+
66671 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66672 struct pid *pid, struct task_struct *task)
66673 {
66674@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66675 task_cpus_allowed(m, task);
66676 cpuset_task_status_allowed(m, task);
66677 task_context_switch_counts(m, task);
66678+
66679+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66680+ task_pax(m, task);
66681+#endif
66682+
66683+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
66684+ task_grsec_rbac(m, task);
66685+#endif
66686+
66687 return 0;
66688 }
66689
66690+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66691+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66692+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
66693+ _mm->pax_flags & MF_PAX_SEGMEXEC))
66694+#endif
66695+
66696 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66697 struct pid *pid, struct task_struct *task, int whole)
66698 {
66699@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66700 char tcomm[sizeof(task->comm)];
66701 unsigned long flags;
66702
66703+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66704+ if (current->exec_id != m->exec_id) {
66705+ gr_log_badprocpid("stat");
66706+ return 0;
66707+ }
66708+#endif
66709+
66710 state = *get_task_state(task);
66711 vsize = eip = esp = 0;
66712 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66713@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66714 gtime = task_gtime(task);
66715 }
66716
66717+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66718+ if (PAX_RAND_FLAGS(mm)) {
66719+ eip = 0;
66720+ esp = 0;
66721+ wchan = 0;
66722+ }
66723+#endif
66724+#ifdef CONFIG_GRKERNSEC_HIDESYM
66725+ wchan = 0;
66726+ eip =0;
66727+ esp =0;
66728+#endif
66729+
66730 /* scale priority and nice values from timeslices to -20..20 */
66731 /* to make it look like a "normal" Unix priority/nice value */
66732 priority = task_prio(task);
66733@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66734 seq_put_decimal_ull(m, ' ', vsize);
66735 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
66736 seq_put_decimal_ull(m, ' ', rsslim);
66737+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66738+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
66739+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
66740+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
66741+#else
66742 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
66743 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
66744 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
66745+#endif
66746 seq_put_decimal_ull(m, ' ', esp);
66747 seq_put_decimal_ull(m, ' ', eip);
66748 /* The signal information here is obsolete.
66749@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66750 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
66751 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
66752
66753- if (mm && permitted) {
66754+ if (mm && permitted
66755+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66756+ && !PAX_RAND_FLAGS(mm)
66757+#endif
66758+ ) {
66759 seq_put_decimal_ull(m, ' ', mm->start_data);
66760 seq_put_decimal_ull(m, ' ', mm->end_data);
66761 seq_put_decimal_ull(m, ' ', mm->start_brk);
66762@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66763 struct pid *pid, struct task_struct *task)
66764 {
66765 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
66766- struct mm_struct *mm = get_task_mm(task);
66767+ struct mm_struct *mm;
66768
66769+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66770+ if (current->exec_id != m->exec_id) {
66771+ gr_log_badprocpid("statm");
66772+ return 0;
66773+ }
66774+#endif
66775+ mm = get_task_mm(task);
66776 if (mm) {
66777 size = task_statm(mm, &shared, &text, &data, &resident);
66778 mmput(mm);
66779@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66780 return 0;
66781 }
66782
66783+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66784+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
66785+{
66786+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
66787+}
66788+#endif
66789+
66790 #ifdef CONFIG_CHECKPOINT_RESTORE
66791 static struct pid *
66792 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
66793diff --git a/fs/proc/base.c b/fs/proc/base.c
66794index 2d696b0..b9da447 100644
66795--- a/fs/proc/base.c
66796+++ b/fs/proc/base.c
66797@@ -113,6 +113,14 @@ struct pid_entry {
66798 union proc_op op;
66799 };
66800
66801+struct getdents_callback {
66802+ struct linux_dirent __user * current_dir;
66803+ struct linux_dirent __user * previous;
66804+ struct file * file;
66805+ int count;
66806+ int error;
66807+};
66808+
66809 #define NOD(NAME, MODE, IOP, FOP, OP) { \
66810 .name = (NAME), \
66811 .len = sizeof(NAME) - 1, \
66812@@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
66813 return get_cmdline(task, buffer, PAGE_SIZE);
66814 }
66815
66816+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66817+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66818+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
66819+ _mm->pax_flags & MF_PAX_SEGMEXEC))
66820+#endif
66821+
66822 static int proc_pid_auxv(struct task_struct *task, char *buffer)
66823 {
66824 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
66825 int res = PTR_ERR(mm);
66826 if (mm && !IS_ERR(mm)) {
66827 unsigned int nwords = 0;
66828+
66829+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66830+ /* allow if we're currently ptracing this task */
66831+ if (PAX_RAND_FLAGS(mm) &&
66832+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
66833+ mmput(mm);
66834+ return 0;
66835+ }
66836+#endif
66837+
66838 do {
66839 nwords += 2;
66840 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
66841@@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
66842 }
66843
66844
66845-#ifdef CONFIG_KALLSYMS
66846+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66847 /*
66848 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
66849 * Returns the resolved symbol. If that fails, simply return the address.
66850@@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
66851 mutex_unlock(&task->signal->cred_guard_mutex);
66852 }
66853
66854-#ifdef CONFIG_STACKTRACE
66855+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66856
66857 #define MAX_STACK_TRACE_DEPTH 64
66858
66859@@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
66860 return count;
66861 }
66862
66863-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66864+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66865 static int proc_pid_syscall(struct task_struct *task, char *buffer)
66866 {
66867 long nr;
66868@@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
66869 /************************************************************************/
66870
66871 /* permission checks */
66872-static int proc_fd_access_allowed(struct inode *inode)
66873+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
66874 {
66875 struct task_struct *task;
66876 int allowed = 0;
66877@@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
66878 */
66879 task = get_proc_task(inode);
66880 if (task) {
66881- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66882+ if (log)
66883+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66884+ else
66885+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66886 put_task_struct(task);
66887 }
66888 return allowed;
66889@@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
66890 struct task_struct *task,
66891 int hide_pid_min)
66892 {
66893+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66894+ return false;
66895+
66896+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66897+ rcu_read_lock();
66898+ {
66899+ const struct cred *tmpcred = current_cred();
66900+ const struct cred *cred = __task_cred(task);
66901+
66902+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
66903+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66904+ || in_group_p(grsec_proc_gid)
66905+#endif
66906+ ) {
66907+ rcu_read_unlock();
66908+ return true;
66909+ }
66910+ }
66911+ rcu_read_unlock();
66912+
66913+ if (!pid->hide_pid)
66914+ return false;
66915+#endif
66916+
66917 if (pid->hide_pid < hide_pid_min)
66918 return true;
66919 if (in_group_p(pid->pid_gid))
66920 return true;
66921+
66922 return ptrace_may_access(task, PTRACE_MODE_READ);
66923 }
66924
66925@@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
66926 put_task_struct(task);
66927
66928 if (!has_perms) {
66929+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66930+ {
66931+#else
66932 if (pid->hide_pid == 2) {
66933+#endif
66934 /*
66935 * Let's make getdents(), stat(), and open()
66936 * consistent with each other. If a process
66937@@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66938 if (!task)
66939 return -ESRCH;
66940
66941+ if (gr_acl_handle_procpidmem(task)) {
66942+ put_task_struct(task);
66943+ return -EPERM;
66944+ }
66945+
66946 mm = mm_access(task, mode);
66947 put_task_struct(task);
66948
66949@@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66950
66951 file->private_data = mm;
66952
66953+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66954+ file->f_version = current->exec_id;
66955+#endif
66956+
66957 return 0;
66958 }
66959
66960@@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66961 ssize_t copied;
66962 char *page;
66963
66964+#ifdef CONFIG_GRKERNSEC
66965+ if (write)
66966+ return -EPERM;
66967+#endif
66968+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66969+ if (file->f_version != current->exec_id) {
66970+ gr_log_badprocpid("mem");
66971+ return 0;
66972+ }
66973+#endif
66974+
66975 if (!mm)
66976 return 0;
66977
66978@@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66979 goto free;
66980
66981 while (count > 0) {
66982- int this_len = min_t(int, count, PAGE_SIZE);
66983+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66984
66985 if (write && copy_from_user(page, buf, this_len)) {
66986 copied = -EFAULT;
66987@@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66988 if (!mm)
66989 return 0;
66990
66991+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66992+ if (file->f_version != current->exec_id) {
66993+ gr_log_badprocpid("environ");
66994+ return 0;
66995+ }
66996+#endif
66997+
66998 page = (char *)__get_free_page(GFP_TEMPORARY);
66999 if (!page)
67000 return -ENOMEM;
67001@@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
67002 goto free;
67003 while (count > 0) {
67004 size_t this_len, max_len;
67005- int retval;
67006+ ssize_t retval;
67007
67008 if (src >= (mm->env_end - mm->env_start))
67009 break;
67010@@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
67011 int error = -EACCES;
67012
67013 /* Are we allowed to snoop on the tasks file descriptors? */
67014- if (!proc_fd_access_allowed(inode))
67015+ if (!proc_fd_access_allowed(inode, 0))
67016 goto out;
67017
67018 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
67019@@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
67020 struct path path;
67021
67022 /* Are we allowed to snoop on the tasks file descriptors? */
67023- if (!proc_fd_access_allowed(inode))
67024- goto out;
67025+ /* logging this is needed for learning on chromium to work properly,
67026+ but we don't want to flood the logs from 'ps' which does a readlink
67027+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
67028+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
67029+ */
67030+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
67031+ if (!proc_fd_access_allowed(inode,0))
67032+ goto out;
67033+ } else {
67034+ if (!proc_fd_access_allowed(inode,1))
67035+ goto out;
67036+ }
67037
67038 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
67039 if (error)
67040@@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
67041 rcu_read_lock();
67042 cred = __task_cred(task);
67043 inode->i_uid = cred->euid;
67044+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67045+ inode->i_gid = grsec_proc_gid;
67046+#else
67047 inode->i_gid = cred->egid;
67048+#endif
67049 rcu_read_unlock();
67050 }
67051 security_task_to_inode(task, inode);
67052@@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
67053 return -ENOENT;
67054 }
67055 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
67056+#ifdef CONFIG_GRKERNSEC_PROC_USER
67057+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
67058+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67059+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
67060+#endif
67061 task_dumpable(task)) {
67062 cred = __task_cred(task);
67063 stat->uid = cred->euid;
67064+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67065+ stat->gid = grsec_proc_gid;
67066+#else
67067 stat->gid = cred->egid;
67068+#endif
67069 }
67070 }
67071 rcu_read_unlock();
67072@@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
67073
67074 if (task) {
67075 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
67076+#ifdef CONFIG_GRKERNSEC_PROC_USER
67077+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
67078+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67079+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
67080+#endif
67081 task_dumpable(task)) {
67082 rcu_read_lock();
67083 cred = __task_cred(task);
67084 inode->i_uid = cred->euid;
67085+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67086+ inode->i_gid = grsec_proc_gid;
67087+#else
67088 inode->i_gid = cred->egid;
67089+#endif
67090 rcu_read_unlock();
67091 } else {
67092 inode->i_uid = GLOBAL_ROOT_UID;
67093@@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
67094 if (!task)
67095 goto out_no_task;
67096
67097+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
67098+ goto out;
67099+
67100 /*
67101 * Yes, it does not scale. And it should not. Don't add
67102 * new entries into /proc/<tgid>/ without very good reasons.
67103@@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
67104 if (!task)
67105 return -ENOENT;
67106
67107+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
67108+ goto out;
67109+
67110 if (!dir_emit_dots(file, ctx))
67111 goto out;
67112
67113@@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
67114 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
67115 #endif
67116 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
67117-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
67118+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
67119 INF("syscall", S_IRUSR, proc_pid_syscall),
67120 #endif
67121 INF("cmdline", S_IRUGO, proc_pid_cmdline),
67122@@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
67123 #ifdef CONFIG_SECURITY
67124 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
67125 #endif
67126-#ifdef CONFIG_KALLSYMS
67127+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67128 INF("wchan", S_IRUGO, proc_pid_wchan),
67129 #endif
67130-#ifdef CONFIG_STACKTRACE
67131+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67132 ONE("stack", S_IRUSR, proc_pid_stack),
67133 #endif
67134 #ifdef CONFIG_SCHEDSTATS
67135@@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
67136 #ifdef CONFIG_HARDWALL
67137 INF("hardwall", S_IRUGO, proc_pid_hardwall),
67138 #endif
67139+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
67140+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
67141+#endif
67142 #ifdef CONFIG_USER_NS
67143 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
67144 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
67145@@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
67146 if (!inode)
67147 goto out;
67148
67149+#ifdef CONFIG_GRKERNSEC_PROC_USER
67150+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
67151+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67152+ inode->i_gid = grsec_proc_gid;
67153+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
67154+#else
67155 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
67156+#endif
67157 inode->i_op = &proc_tgid_base_inode_operations;
67158 inode->i_fop = &proc_tgid_base_operations;
67159 inode->i_flags|=S_IMMUTABLE;
67160@@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
67161 if (!task)
67162 goto out;
67163
67164+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
67165+ goto out_put_task;
67166+
67167 result = proc_pid_instantiate(dir, dentry, task, NULL);
67168+out_put_task:
67169 put_task_struct(task);
67170 out:
67171 return ERR_PTR(result);
67172@@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
67173 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
67174 #endif
67175 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
67176-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
67177+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
67178 INF("syscall", S_IRUSR, proc_pid_syscall),
67179 #endif
67180 INF("cmdline", S_IRUGO, proc_pid_cmdline),
67181@@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
67182 #ifdef CONFIG_SECURITY
67183 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
67184 #endif
67185-#ifdef CONFIG_KALLSYMS
67186+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67187 INF("wchan", S_IRUGO, proc_pid_wchan),
67188 #endif
67189-#ifdef CONFIG_STACKTRACE
67190+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67191 ONE("stack", S_IRUSR, proc_pid_stack),
67192 #endif
67193 #ifdef CONFIG_SCHEDSTATS
67194diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
67195index cbd82df..c0407d2 100644
67196--- a/fs/proc/cmdline.c
67197+++ b/fs/proc/cmdline.c
67198@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
67199
67200 static int __init proc_cmdline_init(void)
67201 {
67202+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67203+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
67204+#else
67205 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
67206+#endif
67207 return 0;
67208 }
67209 fs_initcall(proc_cmdline_init);
67210diff --git a/fs/proc/devices.c b/fs/proc/devices.c
67211index 50493ed..248166b 100644
67212--- a/fs/proc/devices.c
67213+++ b/fs/proc/devices.c
67214@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
67215
67216 static int __init proc_devices_init(void)
67217 {
67218+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67219+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
67220+#else
67221 proc_create("devices", 0, NULL, &proc_devinfo_operations);
67222+#endif
67223 return 0;
67224 }
67225 fs_initcall(proc_devices_init);
67226diff --git a/fs/proc/fd.c b/fs/proc/fd.c
67227index 0788d09..9cc1385 100644
67228--- a/fs/proc/fd.c
67229+++ b/fs/proc/fd.c
67230@@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
67231 if (!task)
67232 return -ENOENT;
67233
67234- files = get_files_struct(task);
67235+ if (!gr_acl_handle_procpidmem(task))
67236+ files = get_files_struct(task);
67237 put_task_struct(task);
67238
67239 if (files) {
67240@@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
67241 */
67242 int proc_fd_permission(struct inode *inode, int mask)
67243 {
67244+ struct task_struct *task;
67245 int rv = generic_permission(inode, mask);
67246- if (rv == 0)
67247- return 0;
67248+
67249 if (task_tgid(current) == proc_pid(inode))
67250 rv = 0;
67251+
67252+ task = get_proc_task(inode);
67253+ if (task == NULL)
67254+ return rv;
67255+
67256+ if (gr_acl_handle_procpidmem(task))
67257+ rv = -EACCES;
67258+
67259+ put_task_struct(task);
67260+
67261 return rv;
67262 }
67263
67264diff --git a/fs/proc/generic.c b/fs/proc/generic.c
67265index b7f268e..3bea6b7 100644
67266--- a/fs/proc/generic.c
67267+++ b/fs/proc/generic.c
67268@@ -23,6 +23,7 @@
67269 #include <linux/bitops.h>
67270 #include <linux/spinlock.h>
67271 #include <linux/completion.h>
67272+#include <linux/grsecurity.h>
67273 #include <asm/uaccess.h>
67274
67275 #include "internal.h"
67276@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
67277 return proc_lookup_de(PDE(dir), dir, dentry);
67278 }
67279
67280+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
67281+ unsigned int flags)
67282+{
67283+ if (gr_proc_is_restricted())
67284+ return ERR_PTR(-EACCES);
67285+
67286+ return proc_lookup_de(PDE(dir), dir, dentry);
67287+}
67288+
67289 /*
67290 * This returns non-zero if at EOF, so that the /proc
67291 * root directory can use this and check if it should
67292@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
67293 return proc_readdir_de(PDE(inode), file, ctx);
67294 }
67295
67296+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
67297+{
67298+ struct inode *inode = file_inode(file);
67299+
67300+ if (gr_proc_is_restricted())
67301+ return -EACCES;
67302+
67303+ return proc_readdir_de(PDE(inode), file, ctx);
67304+}
67305+
67306 /*
67307 * These are the generic /proc directory operations. They
67308 * use the in-memory "struct proc_dir_entry" tree to parse
67309@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
67310 .iterate = proc_readdir,
67311 };
67312
67313+static const struct file_operations proc_dir_restricted_operations = {
67314+ .llseek = generic_file_llseek,
67315+ .read = generic_read_dir,
67316+ .iterate = proc_readdir_restrict,
67317+};
67318+
67319 /*
67320 * proc directories can do almost nothing..
67321 */
67322@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
67323 .setattr = proc_notify_change,
67324 };
67325
67326+static const struct inode_operations proc_dir_restricted_inode_operations = {
67327+ .lookup = proc_lookup_restrict,
67328+ .getattr = proc_getattr,
67329+ .setattr = proc_notify_change,
67330+};
67331+
67332 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
67333 {
67334 struct proc_dir_entry *tmp;
67335@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
67336 return ret;
67337
67338 if (S_ISDIR(dp->mode)) {
67339- dp->proc_fops = &proc_dir_operations;
67340- dp->proc_iops = &proc_dir_inode_operations;
67341+ if (dp->restricted) {
67342+ dp->proc_fops = &proc_dir_restricted_operations;
67343+ dp->proc_iops = &proc_dir_restricted_inode_operations;
67344+ } else {
67345+ dp->proc_fops = &proc_dir_operations;
67346+ dp->proc_iops = &proc_dir_inode_operations;
67347+ }
67348 dir->nlink++;
67349 } else if (S_ISLNK(dp->mode)) {
67350 dp->proc_iops = &proc_link_inode_operations;
67351@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
67352 }
67353 EXPORT_SYMBOL_GPL(proc_mkdir_data);
67354
67355+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
67356+ struct proc_dir_entry *parent, void *data)
67357+{
67358+ struct proc_dir_entry *ent;
67359+
67360+ if (mode == 0)
67361+ mode = S_IRUGO | S_IXUGO;
67362+
67363+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
67364+ if (ent) {
67365+ ent->data = data;
67366+ ent->restricted = 1;
67367+ if (proc_register(parent, ent) < 0) {
67368+ kfree(ent);
67369+ ent = NULL;
67370+ }
67371+ }
67372+ return ent;
67373+}
67374+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
67375+
67376 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
67377 struct proc_dir_entry *parent)
67378 {
67379@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
67380 }
67381 EXPORT_SYMBOL(proc_mkdir);
67382
67383+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
67384+ struct proc_dir_entry *parent)
67385+{
67386+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
67387+}
67388+EXPORT_SYMBOL(proc_mkdir_restrict);
67389+
67390 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
67391 struct proc_dir_entry *parent,
67392 const struct file_operations *proc_fops,
67393diff --git a/fs/proc/inode.c b/fs/proc/inode.c
67394index 0adbc02..bee4d0b 100644
67395--- a/fs/proc/inode.c
67396+++ b/fs/proc/inode.c
67397@@ -23,11 +23,17 @@
67398 #include <linux/slab.h>
67399 #include <linux/mount.h>
67400 #include <linux/magic.h>
67401+#include <linux/grsecurity.h>
67402
67403 #include <asm/uaccess.h>
67404
67405 #include "internal.h"
67406
67407+#ifdef CONFIG_PROC_SYSCTL
67408+extern const struct inode_operations proc_sys_inode_operations;
67409+extern const struct inode_operations proc_sys_dir_operations;
67410+#endif
67411+
67412 static void proc_evict_inode(struct inode *inode)
67413 {
67414 struct proc_dir_entry *de;
67415@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
67416 ns = PROC_I(inode)->ns.ns;
67417 if (ns_ops && ns)
67418 ns_ops->put(ns);
67419+
67420+#ifdef CONFIG_PROC_SYSCTL
67421+ if (inode->i_op == &proc_sys_inode_operations ||
67422+ inode->i_op == &proc_sys_dir_operations)
67423+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
67424+#endif
67425+
67426 }
67427
67428 static struct kmem_cache * proc_inode_cachep;
67429@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
67430 if (de->mode) {
67431 inode->i_mode = de->mode;
67432 inode->i_uid = de->uid;
67433+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67434+ inode->i_gid = grsec_proc_gid;
67435+#else
67436 inode->i_gid = de->gid;
67437+#endif
67438 }
67439 if (de->size)
67440 inode->i_size = de->size;
67441diff --git a/fs/proc/internal.h b/fs/proc/internal.h
67442index 3ab6d14..b26174e 100644
67443--- a/fs/proc/internal.h
67444+++ b/fs/proc/internal.h
67445@@ -46,9 +46,10 @@ struct proc_dir_entry {
67446 struct completion *pde_unload_completion;
67447 struct list_head pde_openers; /* who did ->open, but not ->release */
67448 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
67449+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
67450 u8 namelen;
67451 char name[];
67452-};
67453+} __randomize_layout;
67454
67455 union proc_op {
67456 int (*proc_get_link)(struct dentry *, struct path *);
67457@@ -67,7 +68,7 @@ struct proc_inode {
67458 struct ctl_table *sysctl_entry;
67459 struct proc_ns ns;
67460 struct inode vfs_inode;
67461-};
67462+} __randomize_layout;
67463
67464 /*
67465 * General functions
67466@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
67467 struct pid *, struct task_struct *);
67468 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
67469 struct pid *, struct task_struct *);
67470+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
67471+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
67472+#endif
67473
67474 /*
67475 * base.c
67476@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
67477 extern spinlock_t proc_subdir_lock;
67478
67479 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
67480+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
67481 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
67482 struct dentry *);
67483 extern int proc_readdir(struct file *, struct dir_context *);
67484+extern int proc_readdir_restrict(struct file *, struct dir_context *);
67485 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
67486
67487 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
67488diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
67489index a352d57..cb94a5c 100644
67490--- a/fs/proc/interrupts.c
67491+++ b/fs/proc/interrupts.c
67492@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
67493
67494 static int __init proc_interrupts_init(void)
67495 {
67496+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67497+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
67498+#else
67499 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
67500+#endif
67501 return 0;
67502 }
67503 fs_initcall(proc_interrupts_init);
67504diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
67505index 39e6ef3..2f9cb5e 100644
67506--- a/fs/proc/kcore.c
67507+++ b/fs/proc/kcore.c
67508@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67509 * the addresses in the elf_phdr on our list.
67510 */
67511 start = kc_offset_to_vaddr(*fpos - elf_buflen);
67512- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
67513+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
67514+ if (tsz > buflen)
67515 tsz = buflen;
67516-
67517+
67518 while (buflen) {
67519 struct kcore_list *m;
67520
67521@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67522 kfree(elf_buf);
67523 } else {
67524 if (kern_addr_valid(start)) {
67525- unsigned long n;
67526+ char *elf_buf;
67527+ mm_segment_t oldfs;
67528
67529- n = copy_to_user(buffer, (char *)start, tsz);
67530- /*
67531- * We cannot distinguish between fault on source
67532- * and fault on destination. When this happens
67533- * we clear too and hope it will trigger the
67534- * EFAULT again.
67535- */
67536- if (n) {
67537- if (clear_user(buffer + tsz - n,
67538- n))
67539+ elf_buf = kmalloc(tsz, GFP_KERNEL);
67540+ if (!elf_buf)
67541+ return -ENOMEM;
67542+ oldfs = get_fs();
67543+ set_fs(KERNEL_DS);
67544+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
67545+ set_fs(oldfs);
67546+ if (copy_to_user(buffer, elf_buf, tsz)) {
67547+ kfree(elf_buf);
67548 return -EFAULT;
67549+ }
67550 }
67551+ set_fs(oldfs);
67552+ kfree(elf_buf);
67553 } else {
67554 if (clear_user(buffer, tsz))
67555 return -EFAULT;
67556@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67557
67558 static int open_kcore(struct inode *inode, struct file *filp)
67559 {
67560+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67561+ return -EPERM;
67562+#endif
67563 if (!capable(CAP_SYS_RAWIO))
67564 return -EPERM;
67565 if (kcore_need_update)
67566diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
67567index 7445af0..7c5113c 100644
67568--- a/fs/proc/meminfo.c
67569+++ b/fs/proc/meminfo.c
67570@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
67571 vmi.used >> 10,
67572 vmi.largest_chunk >> 10
67573 #ifdef CONFIG_MEMORY_FAILURE
67574- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
67575+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
67576 #endif
67577 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
67578 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
67579diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
67580index d4a3574..b421ce9 100644
67581--- a/fs/proc/nommu.c
67582+++ b/fs/proc/nommu.c
67583@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
67584
67585 if (file) {
67586 seq_pad(m, ' ');
67587- seq_path(m, &file->f_path, "");
67588+ seq_path(m, &file->f_path, "\n\\");
67589 }
67590
67591 seq_putc(m, '\n');
67592diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
67593index 4677bb7..dad3045 100644
67594--- a/fs/proc/proc_net.c
67595+++ b/fs/proc/proc_net.c
67596@@ -23,9 +23,27 @@
67597 #include <linux/nsproxy.h>
67598 #include <net/net_namespace.h>
67599 #include <linux/seq_file.h>
67600+#include <linux/grsecurity.h>
67601
67602 #include "internal.h"
67603
67604+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
67605+static struct seq_operations *ipv6_seq_ops_addr;
67606+
67607+void register_ipv6_seq_ops_addr(struct seq_operations *addr)
67608+{
67609+ ipv6_seq_ops_addr = addr;
67610+}
67611+
67612+void unregister_ipv6_seq_ops_addr(void)
67613+{
67614+ ipv6_seq_ops_addr = NULL;
67615+}
67616+
67617+EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
67618+EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
67619+#endif
67620+
67621 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
67622 {
67623 return pde->parent->data;
67624@@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
67625 return maybe_get_net(PDE_NET(PDE(inode)));
67626 }
67627
67628+extern const struct seq_operations dev_seq_ops;
67629+
67630 int seq_open_net(struct inode *ino, struct file *f,
67631 const struct seq_operations *ops, int size)
67632 {
67633@@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
67634
67635 BUG_ON(size < sizeof(*p));
67636
67637+ /* only permit access to /proc/net/dev */
67638+ if (
67639+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
67640+ ops != ipv6_seq_ops_addr &&
67641+#endif
67642+ ops != &dev_seq_ops && gr_proc_is_restricted())
67643+ return -EACCES;
67644+
67645 net = get_proc_net(ino);
67646 if (net == NULL)
67647 return -ENXIO;
67648@@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
67649 int err;
67650 struct net *net;
67651
67652+ if (gr_proc_is_restricted())
67653+ return -EACCES;
67654+
67655 err = -ENXIO;
67656 net = get_proc_net(inode);
67657 if (net == NULL)
67658diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
67659index 7129046..6914844 100644
67660--- a/fs/proc/proc_sysctl.c
67661+++ b/fs/proc/proc_sysctl.c
67662@@ -11,13 +11,21 @@
67663 #include <linux/namei.h>
67664 #include <linux/mm.h>
67665 #include <linux/module.h>
67666+#include <linux/nsproxy.h>
67667+#ifdef CONFIG_GRKERNSEC
67668+#include <net/net_namespace.h>
67669+#endif
67670 #include "internal.h"
67671
67672+extern int gr_handle_chroot_sysctl(const int op);
67673+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
67674+ const int op);
67675+
67676 static const struct dentry_operations proc_sys_dentry_operations;
67677 static const struct file_operations proc_sys_file_operations;
67678-static const struct inode_operations proc_sys_inode_operations;
67679+const struct inode_operations proc_sys_inode_operations;
67680 static const struct file_operations proc_sys_dir_file_operations;
67681-static const struct inode_operations proc_sys_dir_operations;
67682+const struct inode_operations proc_sys_dir_operations;
67683
67684 void proc_sys_poll_notify(struct ctl_table_poll *poll)
67685 {
67686@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
67687
67688 err = NULL;
67689 d_set_d_op(dentry, &proc_sys_dentry_operations);
67690+
67691+ gr_handle_proc_create(dentry, inode);
67692+
67693 d_add(dentry, inode);
67694
67695 out:
67696@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67697 struct inode *inode = file_inode(filp);
67698 struct ctl_table_header *head = grab_header(inode);
67699 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
67700+ int op = write ? MAY_WRITE : MAY_READ;
67701 ssize_t error;
67702 size_t res;
67703
67704@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67705 * and won't be until we finish.
67706 */
67707 error = -EPERM;
67708- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
67709+ if (sysctl_perm(head, table, op))
67710 goto out;
67711
67712 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
67713@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67714 if (!table->proc_handler)
67715 goto out;
67716
67717+#ifdef CONFIG_GRKERNSEC
67718+ error = -EPERM;
67719+ if (gr_handle_chroot_sysctl(op))
67720+ goto out;
67721+ dget(filp->f_path.dentry);
67722+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
67723+ dput(filp->f_path.dentry);
67724+ goto out;
67725+ }
67726+ dput(filp->f_path.dentry);
67727+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
67728+ goto out;
67729+ if (write) {
67730+ if (current->nsproxy->net_ns != table->extra2) {
67731+ if (!capable(CAP_SYS_ADMIN))
67732+ goto out;
67733+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
67734+ goto out;
67735+ }
67736+#endif
67737+
67738 /* careful: calling conventions are nasty here */
67739 res = count;
67740 error = table->proc_handler(table, write, buf, &res, ppos);
67741@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
67742 return false;
67743 } else {
67744 d_set_d_op(child, &proc_sys_dentry_operations);
67745+
67746+ gr_handle_proc_create(child, inode);
67747+
67748 d_add(child, inode);
67749 }
67750 } else {
67751@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
67752 if ((*pos)++ < ctx->pos)
67753 return true;
67754
67755+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
67756+ return 0;
67757+
67758 if (unlikely(S_ISLNK(table->mode)))
67759 res = proc_sys_link_fill_cache(file, ctx, head, table);
67760 else
67761@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
67762 if (IS_ERR(head))
67763 return PTR_ERR(head);
67764
67765+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
67766+ return -ENOENT;
67767+
67768 generic_fillattr(inode, stat);
67769 if (table)
67770 stat->mode = (stat->mode & S_IFMT) | table->mode;
67771@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
67772 .llseek = generic_file_llseek,
67773 };
67774
67775-static const struct inode_operations proc_sys_inode_operations = {
67776+const struct inode_operations proc_sys_inode_operations = {
67777 .permission = proc_sys_permission,
67778 .setattr = proc_sys_setattr,
67779 .getattr = proc_sys_getattr,
67780 };
67781
67782-static const struct inode_operations proc_sys_dir_operations = {
67783+const struct inode_operations proc_sys_dir_operations = {
67784 .lookup = proc_sys_lookup,
67785 .permission = proc_sys_permission,
67786 .setattr = proc_sys_setattr,
67787@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
67788 static struct ctl_dir *new_dir(struct ctl_table_set *set,
67789 const char *name, int namelen)
67790 {
67791- struct ctl_table *table;
67792+ ctl_table_no_const *table;
67793 struct ctl_dir *new;
67794 struct ctl_node *node;
67795 char *new_name;
67796@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
67797 return NULL;
67798
67799 node = (struct ctl_node *)(new + 1);
67800- table = (struct ctl_table *)(node + 1);
67801+ table = (ctl_table_no_const *)(node + 1);
67802 new_name = (char *)(table + 2);
67803 memcpy(new_name, name, namelen);
67804 new_name[namelen] = '\0';
67805@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
67806 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
67807 struct ctl_table_root *link_root)
67808 {
67809- struct ctl_table *link_table, *entry, *link;
67810+ ctl_table_no_const *link_table, *link;
67811+ struct ctl_table *entry;
67812 struct ctl_table_header *links;
67813 struct ctl_node *node;
67814 char *link_name;
67815@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
67816 return NULL;
67817
67818 node = (struct ctl_node *)(links + 1);
67819- link_table = (struct ctl_table *)(node + nr_entries);
67820+ link_table = (ctl_table_no_const *)(node + nr_entries);
67821 link_name = (char *)&link_table[nr_entries + 1];
67822
67823 for (link = link_table, entry = table; entry->procname; link++, entry++) {
67824@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67825 struct ctl_table_header ***subheader, struct ctl_table_set *set,
67826 struct ctl_table *table)
67827 {
67828- struct ctl_table *ctl_table_arg = NULL;
67829- struct ctl_table *entry, *files;
67830+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
67831+ struct ctl_table *entry;
67832 int nr_files = 0;
67833 int nr_dirs = 0;
67834 int err = -ENOMEM;
67835@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67836 nr_files++;
67837 }
67838
67839- files = table;
67840 /* If there are mixed files and directories we need a new table */
67841 if (nr_dirs && nr_files) {
67842- struct ctl_table *new;
67843+ ctl_table_no_const *new;
67844 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
67845 GFP_KERNEL);
67846 if (!files)
67847@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67848 /* Register everything except a directory full of subdirectories */
67849 if (nr_files || !nr_dirs) {
67850 struct ctl_table_header *header;
67851- header = __register_sysctl_table(set, path, files);
67852+ header = __register_sysctl_table(set, path, files ? files : table);
67853 if (!header) {
67854 kfree(ctl_table_arg);
67855 goto out;
67856diff --git a/fs/proc/root.c b/fs/proc/root.c
67857index 5dbadec..473af2f 100644
67858--- a/fs/proc/root.c
67859+++ b/fs/proc/root.c
67860@@ -185,7 +185,15 @@ void __init proc_root_init(void)
67861 proc_mkdir("openprom", NULL);
67862 #endif
67863 proc_tty_init();
67864+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67865+#ifdef CONFIG_GRKERNSEC_PROC_USER
67866+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
67867+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67868+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
67869+#endif
67870+#else
67871 proc_mkdir("bus", NULL);
67872+#endif
67873 proc_sys_init();
67874 }
67875
67876diff --git a/fs/proc/stat.c b/fs/proc/stat.c
67877index bf2d03f..f058f9c 100644
67878--- a/fs/proc/stat.c
67879+++ b/fs/proc/stat.c
67880@@ -11,6 +11,7 @@
67881 #include <linux/irqnr.h>
67882 #include <linux/cputime.h>
67883 #include <linux/tick.h>
67884+#include <linux/grsecurity.h>
67885
67886 #ifndef arch_irq_stat_cpu
67887 #define arch_irq_stat_cpu(cpu) 0
67888@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
67889 u64 sum_softirq = 0;
67890 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
67891 struct timespec boottime;
67892+ int unrestricted = 1;
67893+
67894+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67895+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67896+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
67897+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67898+ && !in_group_p(grsec_proc_gid)
67899+#endif
67900+ )
67901+ unrestricted = 0;
67902+#endif
67903+#endif
67904
67905 user = nice = system = idle = iowait =
67906 irq = softirq = steal = 0;
67907@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
67908 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67909 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67910 idle += get_idle_time(i);
67911- iowait += get_iowait_time(i);
67912- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67913- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67914- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67915- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67916- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67917- sum += kstat_cpu_irqs_sum(i);
67918- sum += arch_irq_stat_cpu(i);
67919+ if (unrestricted) {
67920+ iowait += get_iowait_time(i);
67921+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67922+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67923+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67924+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67925+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67926+ sum += kstat_cpu_irqs_sum(i);
67927+ sum += arch_irq_stat_cpu(i);
67928+ for (j = 0; j < NR_SOFTIRQS; j++) {
67929+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67930
67931- for (j = 0; j < NR_SOFTIRQS; j++) {
67932- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67933-
67934- per_softirq_sums[j] += softirq_stat;
67935- sum_softirq += softirq_stat;
67936+ per_softirq_sums[j] += softirq_stat;
67937+ sum_softirq += softirq_stat;
67938+ }
67939 }
67940 }
67941- sum += arch_irq_stat();
67942+ if (unrestricted)
67943+ sum += arch_irq_stat();
67944
67945 seq_puts(p, "cpu ");
67946 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67947@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
67948 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67949 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67950 idle = get_idle_time(i);
67951- iowait = get_iowait_time(i);
67952- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67953- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67954- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67955- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67956- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67957+ if (unrestricted) {
67958+ iowait = get_iowait_time(i);
67959+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67960+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67961+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67962+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67963+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67964+ }
67965 seq_printf(p, "cpu%d", i);
67966 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67967 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
67968@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
67969
67970 /* sum again ? it could be updated? */
67971 for_each_irq_nr(j)
67972- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
67973+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
67974
67975 seq_printf(p,
67976 "\nctxt %llu\n"
67977@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
67978 "processes %lu\n"
67979 "procs_running %lu\n"
67980 "procs_blocked %lu\n",
67981- nr_context_switches(),
67982+ unrestricted ? nr_context_switches() : 0ULL,
67983 (unsigned long)jif,
67984- total_forks,
67985- nr_running(),
67986- nr_iowait());
67987+ unrestricted ? total_forks : 0UL,
67988+ unrestricted ? nr_running() : 0UL,
67989+ unrestricted ? nr_iowait() : 0UL);
67990
67991 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67992
67993diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67994index cfa63ee..fce112e 100644
67995--- a/fs/proc/task_mmu.c
67996+++ b/fs/proc/task_mmu.c
67997@@ -13,12 +13,19 @@
67998 #include <linux/swap.h>
67999 #include <linux/swapops.h>
68000 #include <linux/mmu_notifier.h>
68001+#include <linux/grsecurity.h>
68002
68003 #include <asm/elf.h>
68004 #include <asm/uaccess.h>
68005 #include <asm/tlbflush.h>
68006 #include "internal.h"
68007
68008+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68009+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
68010+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
68011+ _mm->pax_flags & MF_PAX_SEGMEXEC))
68012+#endif
68013+
68014 void task_mem(struct seq_file *m, struct mm_struct *mm)
68015 {
68016 unsigned long data, text, lib, swap;
68017@@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
68018 "VmExe:\t%8lu kB\n"
68019 "VmLib:\t%8lu kB\n"
68020 "VmPTE:\t%8lu kB\n"
68021- "VmSwap:\t%8lu kB\n",
68022- hiwater_vm << (PAGE_SHIFT-10),
68023+ "VmSwap:\t%8lu kB\n"
68024+
68025+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
68026+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
68027+#endif
68028+
68029+ ,hiwater_vm << (PAGE_SHIFT-10),
68030 total_vm << (PAGE_SHIFT-10),
68031 mm->locked_vm << (PAGE_SHIFT-10),
68032 mm->pinned_vm << (PAGE_SHIFT-10),
68033@@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
68034 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
68035 (PTRS_PER_PTE * sizeof(pte_t) *
68036 atomic_long_read(&mm->nr_ptes)) >> 10,
68037- swap << (PAGE_SHIFT-10));
68038+ swap << (PAGE_SHIFT-10)
68039+
68040+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
68041+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68042+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
68043+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
68044+#else
68045+ , mm->context.user_cs_base
68046+ , mm->context.user_cs_limit
68047+#endif
68048+#endif
68049+
68050+ );
68051 }
68052
68053 unsigned long task_vsize(struct mm_struct *mm)
68054@@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68055 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
68056 }
68057
68058- /* We don't show the stack guard page in /proc/maps */
68059+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68060+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
68061+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
68062+#else
68063 start = vma->vm_start;
68064- if (stack_guard_page_start(vma, start))
68065- start += PAGE_SIZE;
68066 end = vma->vm_end;
68067- if (stack_guard_page_end(vma, end))
68068- end -= PAGE_SIZE;
68069+#endif
68070
68071 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
68072 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
68073@@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68074 flags & VM_WRITE ? 'w' : '-',
68075 flags & VM_EXEC ? 'x' : '-',
68076 flags & VM_MAYSHARE ? 's' : 'p',
68077+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68078+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
68079+#else
68080 pgoff,
68081+#endif
68082 MAJOR(dev), MINOR(dev), ino);
68083
68084 /*
68085@@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68086 */
68087 if (file) {
68088 seq_pad(m, ' ');
68089- seq_path(m, &file->f_path, "\n");
68090+ seq_path(m, &file->f_path, "\n\\");
68091 goto done;
68092 }
68093
68094@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68095 * Thread stack in /proc/PID/task/TID/maps or
68096 * the main process stack.
68097 */
68098- if (!is_pid || (vma->vm_start <= mm->start_stack &&
68099- vma->vm_end >= mm->start_stack)) {
68100+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
68101+ (vma->vm_start <= mm->start_stack &&
68102+ vma->vm_end >= mm->start_stack)) {
68103 name = "[stack]";
68104 } else {
68105 /* Thread stack in /proc/PID/maps */
68106@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
68107 struct proc_maps_private *priv = m->private;
68108 struct task_struct *task = priv->task;
68109
68110+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68111+ if (current->exec_id != m->exec_id) {
68112+ gr_log_badprocpid("maps");
68113+ return 0;
68114+ }
68115+#endif
68116+
68117 show_map_vma(m, vma, is_pid);
68118
68119 if (m->count < m->size) /* vma is copied successfully */
68120@@ -593,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
68121 .private = &mss,
68122 };
68123
68124+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68125+ if (current->exec_id != m->exec_id) {
68126+ gr_log_badprocpid("smaps");
68127+ return 0;
68128+ }
68129+#endif
68130 memset(&mss, 0, sizeof mss);
68131- mss.vma = vma;
68132- /* mmap_sem is held in m_start */
68133- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
68134- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
68135-
68136+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68137+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
68138+#endif
68139+ mss.vma = vma;
68140+ /* mmap_sem is held in m_start */
68141+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
68142+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
68143+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68144+ }
68145+#endif
68146 show_map_vma(m, vma, is_pid);
68147
68148 seq_printf(m,
68149@@ -616,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
68150 "KernelPageSize: %8lu kB\n"
68151 "MMUPageSize: %8lu kB\n"
68152 "Locked: %8lu kB\n",
68153+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68154+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
68155+#else
68156 (vma->vm_end - vma->vm_start) >> 10,
68157+#endif
68158 mss.resident >> 10,
68159 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
68160 mss.shared_clean >> 10,
68161@@ -1398,6 +1449,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
68162 char buffer[64];
68163 int nid;
68164
68165+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68166+ if (current->exec_id != m->exec_id) {
68167+ gr_log_badprocpid("numa_maps");
68168+ return 0;
68169+ }
68170+#endif
68171+
68172 if (!mm)
68173 return 0;
68174
68175@@ -1415,11 +1473,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
68176 mpol_to_str(buffer, sizeof(buffer), pol);
68177 mpol_cond_put(pol);
68178
68179+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68180+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
68181+#else
68182 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
68183+#endif
68184
68185 if (file) {
68186 seq_puts(m, " file=");
68187- seq_path(m, &file->f_path, "\n\t= ");
68188+ seq_path(m, &file->f_path, "\n\t\\= ");
68189 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
68190 seq_puts(m, " heap");
68191 } else {
68192diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
68193index 678455d..ebd3245 100644
68194--- a/fs/proc/task_nommu.c
68195+++ b/fs/proc/task_nommu.c
68196@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
68197 else
68198 bytes += kobjsize(mm);
68199
68200- if (current->fs && current->fs->users > 1)
68201+ if (current->fs && atomic_read(&current->fs->users) > 1)
68202 sbytes += kobjsize(current->fs);
68203 else
68204 bytes += kobjsize(current->fs);
68205@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
68206
68207 if (file) {
68208 seq_pad(m, ' ');
68209- seq_path(m, &file->f_path, "");
68210+ seq_path(m, &file->f_path, "\n\\");
68211 } else if (mm) {
68212 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
68213
68214diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
68215index 382aa89..6b03974 100644
68216--- a/fs/proc/vmcore.c
68217+++ b/fs/proc/vmcore.c
68218@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
68219 nr_bytes = count;
68220
68221 /* If pfn is not ram, return zeros for sparse dump files */
68222- if (pfn_is_ram(pfn) == 0)
68223- memset(buf, 0, nr_bytes);
68224- else {
68225+ if (pfn_is_ram(pfn) == 0) {
68226+ if (userbuf) {
68227+ if (clear_user((char __force_user *)buf, nr_bytes))
68228+ return -EFAULT;
68229+ } else
68230+ memset(buf, 0, nr_bytes);
68231+ } else {
68232 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
68233 offset, userbuf);
68234 if (tmp < 0)
68235@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
68236 static int copy_to(void *target, void *src, size_t size, int userbuf)
68237 {
68238 if (userbuf) {
68239- if (copy_to_user((char __user *) target, src, size))
68240+ if (copy_to_user((char __force_user *) target, src, size))
68241 return -EFAULT;
68242 } else {
68243 memcpy(target, src, size);
68244@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
68245 if (*fpos < m->offset + m->size) {
68246 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
68247 start = m->paddr + *fpos - m->offset;
68248- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
68249+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
68250 if (tmp < 0)
68251 return tmp;
68252 buflen -= tsz;
68253@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
68254 static ssize_t read_vmcore(struct file *file, char __user *buffer,
68255 size_t buflen, loff_t *fpos)
68256 {
68257- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
68258+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
68259 }
68260
68261 /*
68262diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
68263index b00fcc9..e0c6381 100644
68264--- a/fs/qnx6/qnx6.h
68265+++ b/fs/qnx6/qnx6.h
68266@@ -74,7 +74,7 @@ enum {
68267 BYTESEX_BE,
68268 };
68269
68270-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
68271+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
68272 {
68273 if (sbi->s_bytesex == BYTESEX_LE)
68274 return le64_to_cpu((__force __le64)n);
68275@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
68276 return (__force __fs64)cpu_to_be64(n);
68277 }
68278
68279-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
68280+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
68281 {
68282 if (sbi->s_bytesex == BYTESEX_LE)
68283 return le32_to_cpu((__force __le32)n);
68284diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
68285index 72d2917..c917c12 100644
68286--- a/fs/quota/netlink.c
68287+++ b/fs/quota/netlink.c
68288@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
68289 void quota_send_warning(struct kqid qid, dev_t dev,
68290 const char warntype)
68291 {
68292- static atomic_t seq;
68293+ static atomic_unchecked_t seq;
68294 struct sk_buff *skb;
68295 void *msg_head;
68296 int ret;
68297@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
68298 "VFS: Not enough memory to send quota warning.\n");
68299 return;
68300 }
68301- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
68302+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
68303 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
68304 if (!msg_head) {
68305 printk(KERN_ERR
68306diff --git a/fs/read_write.c b/fs/read_write.c
68307index 009d854..16ce214 100644
68308--- a/fs/read_write.c
68309+++ b/fs/read_write.c
68310@@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
68311
68312 old_fs = get_fs();
68313 set_fs(get_ds());
68314- p = (__force const char __user *)buf;
68315+ p = (const char __force_user *)buf;
68316 if (count > MAX_RW_COUNT)
68317 count = MAX_RW_COUNT;
68318 if (file->f_op->write)
68319diff --git a/fs/readdir.c b/fs/readdir.c
68320index 33fd922..e0d6094 100644
68321--- a/fs/readdir.c
68322+++ b/fs/readdir.c
68323@@ -18,6 +18,7 @@
68324 #include <linux/security.h>
68325 #include <linux/syscalls.h>
68326 #include <linux/unistd.h>
68327+#include <linux/namei.h>
68328
68329 #include <asm/uaccess.h>
68330
68331@@ -71,6 +72,7 @@ struct old_linux_dirent {
68332 struct readdir_callback {
68333 struct dir_context ctx;
68334 struct old_linux_dirent __user * dirent;
68335+ struct file * file;
68336 int result;
68337 };
68338
68339@@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
68340 buf->result = -EOVERFLOW;
68341 return -EOVERFLOW;
68342 }
68343+
68344+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68345+ return 0;
68346+
68347 buf->result++;
68348 dirent = buf->dirent;
68349 if (!access_ok(VERIFY_WRITE, dirent,
68350@@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
68351 if (!f.file)
68352 return -EBADF;
68353
68354+ buf.file = f.file;
68355 error = iterate_dir(f.file, &buf.ctx);
68356 if (buf.result)
68357 error = buf.result;
68358@@ -144,6 +151,7 @@ struct getdents_callback {
68359 struct dir_context ctx;
68360 struct linux_dirent __user * current_dir;
68361 struct linux_dirent __user * previous;
68362+ struct file * file;
68363 int count;
68364 int error;
68365 };
68366@@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
68367 buf->error = -EOVERFLOW;
68368 return -EOVERFLOW;
68369 }
68370+
68371+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68372+ return 0;
68373+
68374 dirent = buf->previous;
68375 if (dirent) {
68376 if (__put_user(offset, &dirent->d_off))
68377@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
68378 if (!f.file)
68379 return -EBADF;
68380
68381+ buf.file = f.file;
68382 error = iterate_dir(f.file, &buf.ctx);
68383 if (error >= 0)
68384 error = buf.error;
68385@@ -228,6 +241,7 @@ struct getdents_callback64 {
68386 struct dir_context ctx;
68387 struct linux_dirent64 __user * current_dir;
68388 struct linux_dirent64 __user * previous;
68389+ struct file *file;
68390 int count;
68391 int error;
68392 };
68393@@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
68394 buf->error = -EINVAL; /* only used if we fail.. */
68395 if (reclen > buf->count)
68396 return -EINVAL;
68397+
68398+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68399+ return 0;
68400+
68401 dirent = buf->previous;
68402 if (dirent) {
68403 if (__put_user(offset, &dirent->d_off))
68404@@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
68405 if (!f.file)
68406 return -EBADF;
68407
68408+ buf.file = f.file;
68409 error = iterate_dir(f.file, &buf.ctx);
68410 if (error >= 0)
68411 error = buf.error;
68412diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
68413index 54fdf19..987862b 100644
68414--- a/fs/reiserfs/do_balan.c
68415+++ b/fs/reiserfs/do_balan.c
68416@@ -1872,7 +1872,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
68417 return;
68418 }
68419
68420- atomic_inc(&fs_generation(tb->tb_sb));
68421+ atomic_inc_unchecked(&fs_generation(tb->tb_sb));
68422 do_balance_starts(tb);
68423
68424 /*
68425diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
68426index cfaee91..b9d0d60 100644
68427--- a/fs/reiserfs/item_ops.c
68428+++ b/fs/reiserfs/item_ops.c
68429@@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
68430 }
68431
68432 static struct item_operations errcatch_ops = {
68433- errcatch_bytes_number,
68434- errcatch_decrement_key,
68435- errcatch_is_left_mergeable,
68436- errcatch_print_item,
68437- errcatch_check_item,
68438+ .bytes_number = errcatch_bytes_number,
68439+ .decrement_key = errcatch_decrement_key,
68440+ .is_left_mergeable = errcatch_is_left_mergeable,
68441+ .print_item = errcatch_print_item,
68442+ .check_item = errcatch_check_item,
68443
68444- errcatch_create_vi,
68445- errcatch_check_left,
68446- errcatch_check_right,
68447- errcatch_part_size,
68448- errcatch_unit_num,
68449- errcatch_print_vi
68450+ .create_vi = errcatch_create_vi,
68451+ .check_left = errcatch_check_left,
68452+ .check_right = errcatch_check_right,
68453+ .part_size = errcatch_part_size,
68454+ .unit_num = errcatch_unit_num,
68455+ .print_vi = errcatch_print_vi
68456 };
68457
68458 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
68459diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
68460index 02b0b7d..c85018b 100644
68461--- a/fs/reiserfs/procfs.c
68462+++ b/fs/reiserfs/procfs.c
68463@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
68464 "SMALL_TAILS " : "NO_TAILS ",
68465 replay_only(sb) ? "REPLAY_ONLY " : "",
68466 convert_reiserfs(sb) ? "CONV " : "",
68467- atomic_read(&r->s_generation_counter),
68468+ atomic_read_unchecked(&r->s_generation_counter),
68469 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
68470 SF(s_do_balance), SF(s_unneeded_left_neighbor),
68471 SF(s_good_search_by_key_reada), SF(s_bmaps),
68472diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
68473index bf53888..227f5ae 100644
68474--- a/fs/reiserfs/reiserfs.h
68475+++ b/fs/reiserfs/reiserfs.h
68476@@ -573,7 +573,7 @@ struct reiserfs_sb_info {
68477 /* Comment? -Hans */
68478 wait_queue_head_t s_wait;
68479 /* increased by one every time the tree gets re-balanced */
68480- atomic_t s_generation_counter;
68481+ atomic_unchecked_t s_generation_counter;
68482
68483 /* File system properties. Currently holds on-disk FS format */
68484 unsigned long s_properties;
68485@@ -2294,7 +2294,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
68486 #define REISERFS_USER_MEM 1 /* user memory mode */
68487
68488 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
68489-#define get_generation(s) atomic_read (&fs_generation(s))
68490+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
68491 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
68492 #define __fs_changed(gen,s) (gen != get_generation (s))
68493 #define fs_changed(gen,s) \
68494diff --git a/fs/select.c b/fs/select.c
68495index 467bb1c..cf9d65a 100644
68496--- a/fs/select.c
68497+++ b/fs/select.c
68498@@ -20,6 +20,7 @@
68499 #include <linux/export.h>
68500 #include <linux/slab.h>
68501 #include <linux/poll.h>
68502+#include <linux/security.h>
68503 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
68504 #include <linux/file.h>
68505 #include <linux/fdtable.h>
68506@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
68507 struct poll_list *walk = head;
68508 unsigned long todo = nfds;
68509
68510+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
68511 if (nfds > rlimit(RLIMIT_NOFILE))
68512 return -EINVAL;
68513
68514diff --git a/fs/seq_file.c b/fs/seq_file.c
68515index 3857b72..0b7281e 100644
68516--- a/fs/seq_file.c
68517+++ b/fs/seq_file.c
68518@@ -12,6 +12,8 @@
68519 #include <linux/slab.h>
68520 #include <linux/cred.h>
68521 #include <linux/mm.h>
68522+#include <linux/sched.h>
68523+#include <linux/grsecurity.h>
68524
68525 #include <asm/uaccess.h>
68526 #include <asm/page.h>
68527@@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
68528
68529 static void *seq_buf_alloc(unsigned long size)
68530 {
68531- void *buf;
68532-
68533- buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
68534- if (!buf && size > PAGE_SIZE)
68535- buf = vmalloc(size);
68536- return buf;
68537+ return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
68538 }
68539
68540 /**
68541@@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
68542 #ifdef CONFIG_USER_NS
68543 p->user_ns = file->f_cred->user_ns;
68544 #endif
68545+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68546+ p->exec_id = current->exec_id;
68547+#endif
68548
68549 /*
68550 * Wrappers around seq_open(e.g. swaps_open) need to be
68551@@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
68552 }
68553 EXPORT_SYMBOL(seq_open);
68554
68555+
68556+int seq_open_restrict(struct file *file, const struct seq_operations *op)
68557+{
68558+ if (gr_proc_is_restricted())
68559+ return -EACCES;
68560+
68561+ return seq_open(file, op);
68562+}
68563+EXPORT_SYMBOL(seq_open_restrict);
68564+
68565 static int traverse(struct seq_file *m, loff_t offset)
68566 {
68567 loff_t pos = 0, index;
68568@@ -165,7 +175,7 @@ Eoverflow:
68569 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
68570 {
68571 struct seq_file *m = file->private_data;
68572- size_t copied = 0;
68573+ ssize_t copied = 0;
68574 loff_t pos;
68575 size_t n;
68576 void *p;
68577@@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
68578 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
68579 void *data)
68580 {
68581- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
68582+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
68583 int res = -ENOMEM;
68584
68585 if (op) {
68586@@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
68587 }
68588 EXPORT_SYMBOL(single_open_size);
68589
68590+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
68591+ void *data)
68592+{
68593+ if (gr_proc_is_restricted())
68594+ return -EACCES;
68595+
68596+ return single_open(file, show, data);
68597+}
68598+EXPORT_SYMBOL(single_open_restrict);
68599+
68600+
68601 int single_release(struct inode *inode, struct file *file)
68602 {
68603 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
68604diff --git a/fs/splice.c b/fs/splice.c
68605index f5cb9ba..8ddb1e9 100644
68606--- a/fs/splice.c
68607+++ b/fs/splice.c
68608@@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68609 pipe_lock(pipe);
68610
68611 for (;;) {
68612- if (!pipe->readers) {
68613+ if (!atomic_read(&pipe->readers)) {
68614 send_sig(SIGPIPE, current, 0);
68615 if (!ret)
68616 ret = -EPIPE;
68617@@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68618 page_nr++;
68619 ret += buf->len;
68620
68621- if (pipe->files)
68622+ if (atomic_read(&pipe->files))
68623 do_wakeup = 1;
68624
68625 if (!--spd->nr_pages)
68626@@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68627 do_wakeup = 0;
68628 }
68629
68630- pipe->waiting_writers++;
68631+ atomic_inc(&pipe->waiting_writers);
68632 pipe_wait(pipe);
68633- pipe->waiting_writers--;
68634+ atomic_dec(&pipe->waiting_writers);
68635 }
68636
68637 pipe_unlock(pipe);
68638@@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
68639 old_fs = get_fs();
68640 set_fs(get_ds());
68641 /* The cast to a user pointer is valid due to the set_fs() */
68642- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
68643+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
68644 set_fs(old_fs);
68645
68646 return res;
68647@@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
68648 old_fs = get_fs();
68649 set_fs(get_ds());
68650 /* The cast to a user pointer is valid due to the set_fs() */
68651- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
68652+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
68653 set_fs(old_fs);
68654
68655 return res;
68656@@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
68657 goto err;
68658
68659 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
68660- vec[i].iov_base = (void __user *) page_address(page);
68661+ vec[i].iov_base = (void __force_user *) page_address(page);
68662 vec[i].iov_len = this_len;
68663 spd.pages[i] = page;
68664 spd.nr_pages++;
68665@@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68666 ops->release(pipe, buf);
68667 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68668 pipe->nrbufs--;
68669- if (pipe->files)
68670+ if (atomic_read(&pipe->files))
68671 sd->need_wakeup = true;
68672 }
68673
68674@@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68675 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
68676 {
68677 while (!pipe->nrbufs) {
68678- if (!pipe->writers)
68679+ if (!atomic_read(&pipe->writers))
68680 return 0;
68681
68682- if (!pipe->waiting_writers && sd->num_spliced)
68683+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
68684 return 0;
68685
68686 if (sd->flags & SPLICE_F_NONBLOCK)
68687@@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
68688 ops->release(pipe, buf);
68689 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68690 pipe->nrbufs--;
68691- if (pipe->files)
68692+ if (atomic_read(&pipe->files))
68693 sd.need_wakeup = true;
68694 } else {
68695 buf->offset += ret;
68696@@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
68697 * out of the pipe right after the splice_to_pipe(). So set
68698 * PIPE_READERS appropriately.
68699 */
68700- pipe->readers = 1;
68701+ atomic_set(&pipe->readers, 1);
68702
68703 current->splice_pipe = pipe;
68704 }
68705@@ -1496,6 +1496,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
68706
68707 partial[buffers].offset = off;
68708 partial[buffers].len = plen;
68709+ partial[buffers].private = 0;
68710
68711 off = 0;
68712 len -= plen;
68713@@ -1732,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68714 ret = -ERESTARTSYS;
68715 break;
68716 }
68717- if (!pipe->writers)
68718+ if (!atomic_read(&pipe->writers))
68719 break;
68720- if (!pipe->waiting_writers) {
68721+ if (!atomic_read(&pipe->waiting_writers)) {
68722 if (flags & SPLICE_F_NONBLOCK) {
68723 ret = -EAGAIN;
68724 break;
68725@@ -1766,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68726 pipe_lock(pipe);
68727
68728 while (pipe->nrbufs >= pipe->buffers) {
68729- if (!pipe->readers) {
68730+ if (!atomic_read(&pipe->readers)) {
68731 send_sig(SIGPIPE, current, 0);
68732 ret = -EPIPE;
68733 break;
68734@@ -1779,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68735 ret = -ERESTARTSYS;
68736 break;
68737 }
68738- pipe->waiting_writers++;
68739+ atomic_inc(&pipe->waiting_writers);
68740 pipe_wait(pipe);
68741- pipe->waiting_writers--;
68742+ atomic_dec(&pipe->waiting_writers);
68743 }
68744
68745 pipe_unlock(pipe);
68746@@ -1817,14 +1818,14 @@ retry:
68747 pipe_double_lock(ipipe, opipe);
68748
68749 do {
68750- if (!opipe->readers) {
68751+ if (!atomic_read(&opipe->readers)) {
68752 send_sig(SIGPIPE, current, 0);
68753 if (!ret)
68754 ret = -EPIPE;
68755 break;
68756 }
68757
68758- if (!ipipe->nrbufs && !ipipe->writers)
68759+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
68760 break;
68761
68762 /*
68763@@ -1921,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68764 pipe_double_lock(ipipe, opipe);
68765
68766 do {
68767- if (!opipe->readers) {
68768+ if (!atomic_read(&opipe->readers)) {
68769 send_sig(SIGPIPE, current, 0);
68770 if (!ret)
68771 ret = -EPIPE;
68772@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68773 * return EAGAIN if we have the potential of some data in the
68774 * future, otherwise just return 0
68775 */
68776- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
68777+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
68778 ret = -EAGAIN;
68779
68780 pipe_unlock(ipipe);
68781diff --git a/fs/stat.c b/fs/stat.c
68782index ae0c3ce..9ee641c 100644
68783--- a/fs/stat.c
68784+++ b/fs/stat.c
68785@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
68786 stat->gid = inode->i_gid;
68787 stat->rdev = inode->i_rdev;
68788 stat->size = i_size_read(inode);
68789- stat->atime = inode->i_atime;
68790- stat->mtime = inode->i_mtime;
68791+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68792+ stat->atime = inode->i_ctime;
68793+ stat->mtime = inode->i_ctime;
68794+ } else {
68795+ stat->atime = inode->i_atime;
68796+ stat->mtime = inode->i_mtime;
68797+ }
68798 stat->ctime = inode->i_ctime;
68799 stat->blksize = (1 << inode->i_blkbits);
68800 stat->blocks = inode->i_blocks;
68801@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
68802 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
68803 {
68804 struct inode *inode = path->dentry->d_inode;
68805+ int retval;
68806
68807- if (inode->i_op->getattr)
68808- return inode->i_op->getattr(path->mnt, path->dentry, stat);
68809+ if (inode->i_op->getattr) {
68810+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
68811+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68812+ stat->atime = stat->ctime;
68813+ stat->mtime = stat->ctime;
68814+ }
68815+ return retval;
68816+ }
68817
68818 generic_fillattr(inode, stat);
68819 return 0;
68820diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
68821index 0b45ff4..847de5b 100644
68822--- a/fs/sysfs/dir.c
68823+++ b/fs/sysfs/dir.c
68824@@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
68825 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68826 {
68827 struct kernfs_node *parent, *kn;
68828+ const char *name;
68829+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
68830+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68831+ const char *parent_name;
68832+#endif
68833
68834 BUG_ON(!kobj);
68835
68836+ name = kobject_name(kobj);
68837+
68838 if (kobj->parent)
68839 parent = kobj->parent->sd;
68840 else
68841@@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68842 if (!parent)
68843 return -ENOENT;
68844
68845- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
68846- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
68847+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68848+ parent_name = parent->name;
68849+ mode = S_IRWXU;
68850+
68851+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
68852+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
68853+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
68854+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
68855+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
68856+#endif
68857+
68858+ kn = kernfs_create_dir_ns(parent, name,
68859+ mode, kobj, ns);
68860 if (IS_ERR(kn)) {
68861 if (PTR_ERR(kn) == -EEXIST)
68862- sysfs_warn_dup(parent, kobject_name(kobj));
68863+ sysfs_warn_dup(parent, name);
68864 return PTR_ERR(kn);
68865 }
68866
68867diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
68868index 69d4889..a810bd4 100644
68869--- a/fs/sysv/sysv.h
68870+++ b/fs/sysv/sysv.h
68871@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
68872 #endif
68873 }
68874
68875-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68876+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68877 {
68878 if (sbi->s_bytesex == BYTESEX_PDP)
68879 return PDP_swab((__force __u32)n);
68880diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
68881index 2290d58..7791371 100644
68882--- a/fs/ubifs/io.c
68883+++ b/fs/ubifs/io.c
68884@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
68885 return err;
68886 }
68887
68888-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68889+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68890 {
68891 int err;
68892
68893diff --git a/fs/udf/misc.c b/fs/udf/misc.c
68894index c175b4d..8f36a16 100644
68895--- a/fs/udf/misc.c
68896+++ b/fs/udf/misc.c
68897@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
68898
68899 u8 udf_tag_checksum(const struct tag *t)
68900 {
68901- u8 *data = (u8 *)t;
68902+ const u8 *data = (const u8 *)t;
68903 u8 checksum = 0;
68904 int i;
68905 for (i = 0; i < sizeof(struct tag); ++i)
68906diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68907index 8d974c4..b82f6ec 100644
68908--- a/fs/ufs/swab.h
68909+++ b/fs/ufs/swab.h
68910@@ -22,7 +22,7 @@ enum {
68911 BYTESEX_BE
68912 };
68913
68914-static inline u64
68915+static inline u64 __intentional_overflow(-1)
68916 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68917 {
68918 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68919@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68920 return (__force __fs64)cpu_to_be64(n);
68921 }
68922
68923-static inline u32
68924+static inline u32 __intentional_overflow(-1)
68925 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68926 {
68927 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68928diff --git a/fs/utimes.c b/fs/utimes.c
68929index aa138d6..5f3a811 100644
68930--- a/fs/utimes.c
68931+++ b/fs/utimes.c
68932@@ -1,6 +1,7 @@
68933 #include <linux/compiler.h>
68934 #include <linux/file.h>
68935 #include <linux/fs.h>
68936+#include <linux/security.h>
68937 #include <linux/linkage.h>
68938 #include <linux/mount.h>
68939 #include <linux/namei.h>
68940@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68941 }
68942 }
68943 retry_deleg:
68944+
68945+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68946+ error = -EACCES;
68947+ goto mnt_drop_write_and_out;
68948+ }
68949+
68950 mutex_lock(&inode->i_mutex);
68951 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68952 mutex_unlock(&inode->i_mutex);
68953diff --git a/fs/xattr.c b/fs/xattr.c
68954index c69e6d4..cc56af5 100644
68955--- a/fs/xattr.c
68956+++ b/fs/xattr.c
68957@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68958 return rc;
68959 }
68960
68961+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68962+ssize_t
68963+pax_getxattr(struct dentry *dentry, void *value, size_t size)
68964+{
68965+ struct inode *inode = dentry->d_inode;
68966+ ssize_t error;
68967+
68968+ error = inode_permission(inode, MAY_EXEC);
68969+ if (error)
68970+ return error;
68971+
68972+ if (inode->i_op->getxattr)
68973+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68974+ else
68975+ error = -EOPNOTSUPP;
68976+
68977+ return error;
68978+}
68979+EXPORT_SYMBOL(pax_getxattr);
68980+#endif
68981+
68982 ssize_t
68983 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68984 {
68985@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68986 * Extended attribute SET operations
68987 */
68988 static long
68989-setxattr(struct dentry *d, const char __user *name, const void __user *value,
68990+setxattr(struct path *path, const char __user *name, const void __user *value,
68991 size_t size, int flags)
68992 {
68993 int error;
68994@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68995 posix_acl_fix_xattr_from_user(kvalue, size);
68996 }
68997
68998- error = vfs_setxattr(d, kname, kvalue, size, flags);
68999+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
69000+ error = -EACCES;
69001+ goto out;
69002+ }
69003+
69004+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
69005 out:
69006 if (vvalue)
69007 vfree(vvalue);
69008@@ -377,7 +403,7 @@ retry:
69009 return error;
69010 error = mnt_want_write(path.mnt);
69011 if (!error) {
69012- error = setxattr(path.dentry, name, value, size, flags);
69013+ error = setxattr(&path, name, value, size, flags);
69014 mnt_drop_write(path.mnt);
69015 }
69016 path_put(&path);
69017@@ -401,7 +427,7 @@ retry:
69018 return error;
69019 error = mnt_want_write(path.mnt);
69020 if (!error) {
69021- error = setxattr(path.dentry, name, value, size, flags);
69022+ error = setxattr(&path, name, value, size, flags);
69023 mnt_drop_write(path.mnt);
69024 }
69025 path_put(&path);
69026@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
69027 const void __user *,value, size_t, size, int, flags)
69028 {
69029 struct fd f = fdget(fd);
69030- struct dentry *dentry;
69031 int error = -EBADF;
69032
69033 if (!f.file)
69034 return error;
69035- dentry = f.file->f_path.dentry;
69036- audit_inode(NULL, dentry, 0);
69037+ audit_inode(NULL, f.file->f_path.dentry, 0);
69038 error = mnt_want_write_file(f.file);
69039 if (!error) {
69040- error = setxattr(dentry, name, value, size, flags);
69041+ error = setxattr(&f.file->f_path, name, value, size, flags);
69042 mnt_drop_write_file(f.file);
69043 }
69044 fdput(f);
69045@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
69046 * Extended attribute REMOVE operations
69047 */
69048 static long
69049-removexattr(struct dentry *d, const char __user *name)
69050+removexattr(struct path *path, const char __user *name)
69051 {
69052 int error;
69053 char kname[XATTR_NAME_MAX + 1];
69054@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
69055 if (error < 0)
69056 return error;
69057
69058- return vfs_removexattr(d, kname);
69059+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
69060+ return -EACCES;
69061+
69062+ return vfs_removexattr(path->dentry, kname);
69063 }
69064
69065 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
69066@@ -652,7 +679,7 @@ retry:
69067 return error;
69068 error = mnt_want_write(path.mnt);
69069 if (!error) {
69070- error = removexattr(path.dentry, name);
69071+ error = removexattr(&path, name);
69072 mnt_drop_write(path.mnt);
69073 }
69074 path_put(&path);
69075@@ -675,7 +702,7 @@ retry:
69076 return error;
69077 error = mnt_want_write(path.mnt);
69078 if (!error) {
69079- error = removexattr(path.dentry, name);
69080+ error = removexattr(&path, name);
69081 mnt_drop_write(path.mnt);
69082 }
69083 path_put(&path);
69084@@ -689,16 +716,16 @@ retry:
69085 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
69086 {
69087 struct fd f = fdget(fd);
69088- struct dentry *dentry;
69089+ struct path *path;
69090 int error = -EBADF;
69091
69092 if (!f.file)
69093 return error;
69094- dentry = f.file->f_path.dentry;
69095- audit_inode(NULL, dentry, 0);
69096+ path = &f.file->f_path;
69097+ audit_inode(NULL, path->dentry, 0);
69098 error = mnt_want_write_file(f.file);
69099 if (!error) {
69100- error = removexattr(dentry, name);
69101+ error = removexattr(path, name);
69102 mnt_drop_write_file(f.file);
69103 }
69104 fdput(f);
69105diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
69106index 75c3fe5..b0f6bbe 100644
69107--- a/fs/xfs/xfs_bmap.c
69108+++ b/fs/xfs/xfs_bmap.c
69109@@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
69110
69111 #else
69112 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
69113-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
69114+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
69115 #endif /* DEBUG */
69116
69117 /*
69118diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
69119index 48e99af..54ebae3 100644
69120--- a/fs/xfs/xfs_dir2_readdir.c
69121+++ b/fs/xfs/xfs_dir2_readdir.c
69122@@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
69123 ino = dp->d_ops->sf_get_ino(sfp, sfep);
69124 filetype = dp->d_ops->sf_get_ftype(sfep);
69125 ctx->pos = off & 0x7fffffff;
69126- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
69127+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
69128+ char name[sfep->namelen];
69129+ memcpy(name, sfep->name, sfep->namelen);
69130+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
69131+ return 0;
69132+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
69133 xfs_dir3_get_dtype(dp->i_mount, filetype)))
69134 return 0;
69135 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
69136diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
69137index 8bc1bbc..0d6911b 100644
69138--- a/fs/xfs/xfs_ioctl.c
69139+++ b/fs/xfs/xfs_ioctl.c
69140@@ -122,7 +122,7 @@ xfs_find_handle(
69141 }
69142
69143 error = -EFAULT;
69144- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
69145+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
69146 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
69147 goto out_put;
69148
69149diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
69150new file mode 100644
69151index 0000000..27cec32
69152--- /dev/null
69153+++ b/grsecurity/Kconfig
69154@@ -0,0 +1,1166 @@
69155+#
69156+# grecurity configuration
69157+#
69158+menu "Memory Protections"
69159+depends on GRKERNSEC
69160+
69161+config GRKERNSEC_KMEM
69162+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
69163+ default y if GRKERNSEC_CONFIG_AUTO
69164+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
69165+ help
69166+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
69167+ be written to or read from to modify or leak the contents of the running
69168+ kernel. /dev/port will also not be allowed to be opened, writing to
69169+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
69170+ If you have module support disabled, enabling this will close up several
69171+ ways that are currently used to insert malicious code into the running
69172+ kernel.
69173+
69174+ Even with this feature enabled, we still highly recommend that
69175+ you use the RBAC system, as it is still possible for an attacker to
69176+ modify the running kernel through other more obscure methods.
69177+
69178+ It is highly recommended that you say Y here if you meet all the
69179+ conditions above.
69180+
69181+config GRKERNSEC_VM86
69182+ bool "Restrict VM86 mode"
69183+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69184+ depends on X86_32
69185+
69186+ help
69187+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
69188+ make use of a special execution mode on 32bit x86 processors called
69189+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
69190+ video cards and will still work with this option enabled. The purpose
69191+ of the option is to prevent exploitation of emulation errors in
69192+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
69193+ Nearly all users should be able to enable this option.
69194+
69195+config GRKERNSEC_IO
69196+ bool "Disable privileged I/O"
69197+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69198+ depends on X86
69199+ select RTC_CLASS
69200+ select RTC_INTF_DEV
69201+ select RTC_DRV_CMOS
69202+
69203+ help
69204+ If you say Y here, all ioperm and iopl calls will return an error.
69205+ Ioperm and iopl can be used to modify the running kernel.
69206+ Unfortunately, some programs need this access to operate properly,
69207+ the most notable of which are XFree86 and hwclock. hwclock can be
69208+ remedied by having RTC support in the kernel, so real-time
69209+ clock support is enabled if this option is enabled, to ensure
69210+ that hwclock operates correctly. If hwclock still does not work,
69211+ either update udev or symlink /dev/rtc to /dev/rtc0.
69212+
69213+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
69214+ you may not be able to boot into a graphical environment with this
69215+ option enabled. In this case, you should use the RBAC system instead.
69216+
69217+config GRKERNSEC_JIT_HARDEN
69218+ bool "Harden BPF JIT against spray attacks"
69219+ default y if GRKERNSEC_CONFIG_AUTO
69220+ depends on BPF_JIT && X86
69221+ help
69222+ If you say Y here, the native code generated by the kernel's Berkeley
69223+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
69224+ attacks that attempt to fit attacker-beneficial instructions in
69225+ 32bit immediate fields of JIT-generated native instructions. The
69226+ attacker will generally aim to cause an unintended instruction sequence
69227+ of JIT-generated native code to execute by jumping into the middle of
69228+ a generated instruction. This feature effectively randomizes the 32bit
69229+ immediate constants present in the generated code to thwart such attacks.
69230+
69231+ If you're using KERNEXEC, it's recommended that you enable this option
69232+ to supplement the hardening of the kernel.
69233+
69234+config GRKERNSEC_PERF_HARDEN
69235+ bool "Disable unprivileged PERF_EVENTS usage by default"
69236+ default y if GRKERNSEC_CONFIG_AUTO
69237+ depends on PERF_EVENTS
69238+ help
69239+ If you say Y here, the range of acceptable values for the
69240+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
69241+ default to a new value: 3. When the sysctl is set to this value, no
69242+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
69243+
69244+ Though PERF_EVENTS can be used legitimately for performance monitoring
69245+ and low-level application profiling, it is forced on regardless of
69246+ configuration, has been at fault for several vulnerabilities, and
69247+ creates new opportunities for side channels and other information leaks.
69248+
69249+ This feature puts PERF_EVENTS into a secure default state and permits
69250+ the administrator to change out of it temporarily if unprivileged
69251+ application profiling is needed.
69252+
69253+config GRKERNSEC_RAND_THREADSTACK
69254+ bool "Insert random gaps between thread stacks"
69255+ default y if GRKERNSEC_CONFIG_AUTO
69256+ depends on PAX_RANDMMAP && !PPC
69257+ help
69258+ If you say Y here, a random-sized gap will be enforced between allocated
69259+ thread stacks. Glibc's NPTL and other threading libraries that
69260+ pass MAP_STACK to the kernel for thread stack allocation are supported.
69261+ The implementation currently provides 8 bits of entropy for the gap.
69262+
69263+ Many distributions do not compile threaded remote services with the
69264+ -fstack-check argument to GCC, causing the variable-sized stack-based
69265+ allocator, alloca(), to not probe the stack on allocation. This
69266+ permits an unbounded alloca() to skip over any guard page and potentially
69267+ modify another thread's stack reliably. An enforced random gap
69268+ reduces the reliability of such an attack and increases the chance
69269+ that such a read/write to another thread's stack instead lands in
69270+ an unmapped area, causing a crash and triggering grsecurity's
69271+ anti-bruteforcing logic.
69272+
69273+config GRKERNSEC_PROC_MEMMAP
69274+ bool "Harden ASLR against information leaks and entropy reduction"
69275+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
69276+ depends on PAX_NOEXEC || PAX_ASLR
69277+ help
69278+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
69279+ give no information about the addresses of its mappings if
69280+ PaX features that rely on random addresses are enabled on the task.
69281+ In addition to sanitizing this information and disabling other
69282+ dangerous sources of information, this option causes reads of sensitive
69283+ /proc/<pid> entries where the file descriptor was opened in a different
69284+ task than the one performing the read. Such attempts are logged.
69285+ This option also limits argv/env strings for suid/sgid binaries
69286+ to 512KB to prevent a complete exhaustion of the stack entropy provided
69287+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
69288+ binaries to prevent alternative mmap layouts from being abused.
69289+
69290+ If you use PaX it is essential that you say Y here as it closes up
69291+ several holes that make full ASLR useless locally.
69292+
69293+
69294+config GRKERNSEC_KSTACKOVERFLOW
69295+ bool "Prevent kernel stack overflows"
69296+ default y if GRKERNSEC_CONFIG_AUTO
69297+ depends on !IA64 && 64BIT
69298+ help
69299+ If you say Y here, the kernel's process stacks will be allocated
69300+ with vmalloc instead of the kernel's default allocator. This
69301+ introduces guard pages that in combination with the alloca checking
69302+ of the STACKLEAK feature prevents all forms of kernel process stack
69303+ overflow abuse. Note that this is different from kernel stack
69304+ buffer overflows.
69305+
69306+config GRKERNSEC_BRUTE
69307+ bool "Deter exploit bruteforcing"
69308+ default y if GRKERNSEC_CONFIG_AUTO
69309+ help
69310+ If you say Y here, attempts to bruteforce exploits against forking
69311+ daemons such as apache or sshd, as well as against suid/sgid binaries
69312+ will be deterred. When a child of a forking daemon is killed by PaX
69313+ or crashes due to an illegal instruction or other suspicious signal,
69314+ the parent process will be delayed 30 seconds upon every subsequent
69315+ fork until the administrator is able to assess the situation and
69316+ restart the daemon.
69317+ In the suid/sgid case, the attempt is logged, the user has all their
69318+ existing instances of the suid/sgid binary terminated and will
69319+ be unable to execute any suid/sgid binaries for 15 minutes.
69320+
69321+ It is recommended that you also enable signal logging in the auditing
69322+ section so that logs are generated when a process triggers a suspicious
69323+ signal.
69324+ If the sysctl option is enabled, a sysctl option with name
69325+ "deter_bruteforce" is created.
69326+
69327+config GRKERNSEC_MODHARDEN
69328+ bool "Harden module auto-loading"
69329+ default y if GRKERNSEC_CONFIG_AUTO
69330+ depends on MODULES
69331+ help
69332+ If you say Y here, module auto-loading in response to use of some
69333+ feature implemented by an unloaded module will be restricted to
69334+ root users. Enabling this option helps defend against attacks
69335+ by unprivileged users who abuse the auto-loading behavior to
69336+ cause a vulnerable module to load that is then exploited.
69337+
69338+ If this option prevents a legitimate use of auto-loading for a
69339+ non-root user, the administrator can execute modprobe manually
69340+ with the exact name of the module mentioned in the alert log.
69341+ Alternatively, the administrator can add the module to the list
69342+ of modules loaded at boot by modifying init scripts.
69343+
69344+ Modification of init scripts will most likely be needed on
69345+ Ubuntu servers with encrypted home directory support enabled,
69346+ as the first non-root user logging in will cause the ecb(aes),
69347+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
69348+
69349+config GRKERNSEC_HIDESYM
69350+ bool "Hide kernel symbols"
69351+ default y if GRKERNSEC_CONFIG_AUTO
69352+ select PAX_USERCOPY_SLABS
69353+ help
69354+ If you say Y here, getting information on loaded modules, and
69355+ displaying all kernel symbols through a syscall will be restricted
69356+ to users with CAP_SYS_MODULE. For software compatibility reasons,
69357+ /proc/kallsyms will be restricted to the root user. The RBAC
69358+ system can hide that entry even from root.
69359+
69360+ This option also prevents leaking of kernel addresses through
69361+ several /proc entries.
69362+
69363+ Note that this option is only effective provided the following
69364+ conditions are met:
69365+ 1) The kernel using grsecurity is not precompiled by some distribution
69366+ 2) You have also enabled GRKERNSEC_DMESG
69367+ 3) You are using the RBAC system and hiding other files such as your
69368+ kernel image and System.map. Alternatively, enabling this option
69369+ causes the permissions on /boot, /lib/modules, and the kernel
69370+ source directory to change at compile time to prevent
69371+ reading by non-root users.
69372+ If the above conditions are met, this option will aid in providing a
69373+ useful protection against local kernel exploitation of overflows
69374+ and arbitrary read/write vulnerabilities.
69375+
69376+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
69377+ in addition to this feature.
69378+
69379+config GRKERNSEC_RANDSTRUCT
69380+ bool "Randomize layout of sensitive kernel structures"
69381+ default y if GRKERNSEC_CONFIG_AUTO
69382+ select GRKERNSEC_HIDESYM
69383+ select MODVERSIONS if MODULES
69384+ help
69385+ If you say Y here, the layouts of a number of sensitive kernel
69386+ structures (task, fs, cred, etc) and all structures composed entirely
69387+ of function pointers (aka "ops" structs) will be randomized at compile-time.
69388+ This can introduce the requirement of an additional infoleak
69389+ vulnerability for exploits targeting these structure types.
69390+
69391+ Enabling this feature will introduce some performance impact, slightly
69392+ increase memory usage, and prevent the use of forensic tools like
69393+ Volatility against the system (unless the kernel source tree isn't
69394+ cleaned after kernel installation).
69395+
69396+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
69397+ It remains after a make clean to allow for external modules to be compiled
69398+ with the existing seed and will be removed by a make mrproper or
69399+ make distclean.
69400+
69401+ Note that the implementation requires gcc 4.6.4. or newer. You may need
69402+ to install the supporting headers explicitly in addition to the normal
69403+ gcc package.
69404+
69405+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
69406+ bool "Use cacheline-aware structure randomization"
69407+ depends on GRKERNSEC_RANDSTRUCT
69408+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
69409+ help
69410+ If you say Y here, the RANDSTRUCT randomization will make a best effort
69411+ at restricting randomization to cacheline-sized groups of elements. It
69412+ will further not randomize bitfields in structures. This reduces the
69413+ performance hit of RANDSTRUCT at the cost of weakened randomization.
69414+
69415+config GRKERNSEC_KERN_LOCKOUT
69416+ bool "Active kernel exploit response"
69417+ default y if GRKERNSEC_CONFIG_AUTO
69418+ depends on X86 || ARM || PPC || SPARC
69419+ help
69420+ If you say Y here, when a PaX alert is triggered due to suspicious
69421+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
69422+ or an OOPS occurs due to bad memory accesses, instead of just
69423+ terminating the offending process (and potentially allowing
69424+ a subsequent exploit from the same user), we will take one of two
69425+ actions:
69426+ If the user was root, we will panic the system
69427+ If the user was non-root, we will log the attempt, terminate
69428+ all processes owned by the user, then prevent them from creating
69429+ any new processes until the system is restarted
69430+ This deters repeated kernel exploitation/bruteforcing attempts
69431+ and is useful for later forensics.
69432+
69433+config GRKERNSEC_OLD_ARM_USERLAND
69434+ bool "Old ARM userland compatibility"
69435+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
69436+ help
69437+ If you say Y here, stubs of executable code to perform such operations
69438+ as "compare-exchange" will be placed at fixed locations in the ARM vector
69439+ table. This is unfortunately needed for old ARM userland meant to run
69440+ across a wide range of processors. Without this option enabled,
69441+ the get_tls and data memory barrier stubs will be emulated by the kernel,
69442+ which is enough for Linaro userlands or other userlands designed for v6
69443+ and newer ARM CPUs. It's recommended that you try without this option enabled
69444+ first, and only enable it if your userland does not boot (it will likely fail
69445+ at init time).
69446+
69447+endmenu
69448+menu "Role Based Access Control Options"
69449+depends on GRKERNSEC
69450+
69451+config GRKERNSEC_RBAC_DEBUG
69452+ bool
69453+
69454+config GRKERNSEC_NO_RBAC
69455+ bool "Disable RBAC system"
69456+ help
69457+ If you say Y here, the /dev/grsec device will be removed from the kernel,
69458+ preventing the RBAC system from being enabled. You should only say Y
69459+ here if you have no intention of using the RBAC system, so as to prevent
69460+ an attacker with root access from misusing the RBAC system to hide files
69461+ and processes when loadable module support and /dev/[k]mem have been
69462+ locked down.
69463+
69464+config GRKERNSEC_ACL_HIDEKERN
69465+ bool "Hide kernel processes"
69466+ help
69467+ If you say Y here, all kernel threads will be hidden to all
69468+ processes but those whose subject has the "view hidden processes"
69469+ flag.
69470+
69471+config GRKERNSEC_ACL_MAXTRIES
69472+ int "Maximum tries before password lockout"
69473+ default 3
69474+ help
69475+ This option enforces the maximum number of times a user can attempt
69476+ to authorize themselves with the grsecurity RBAC system before being
69477+ denied the ability to attempt authorization again for a specified time.
69478+ The lower the number, the harder it will be to brute-force a password.
69479+
69480+config GRKERNSEC_ACL_TIMEOUT
69481+ int "Time to wait after max password tries, in seconds"
69482+ default 30
69483+ help
69484+ This option specifies the time the user must wait after attempting to
69485+ authorize to the RBAC system with the maximum number of invalid
69486+ passwords. The higher the number, the harder it will be to brute-force
69487+ a password.
69488+
69489+endmenu
69490+menu "Filesystem Protections"
69491+depends on GRKERNSEC
69492+
69493+config GRKERNSEC_PROC
69494+ bool "Proc restrictions"
69495+ default y if GRKERNSEC_CONFIG_AUTO
69496+ help
69497+ If you say Y here, the permissions of the /proc filesystem
69498+ will be altered to enhance system security and privacy. You MUST
69499+ choose either a user only restriction or a user and group restriction.
69500+ Depending upon the option you choose, you can either restrict users to
69501+ see only the processes they themselves run, or choose a group that can
69502+ view all processes and files normally restricted to root if you choose
69503+ the "restrict to user only" option. NOTE: If you're running identd or
69504+ ntpd as a non-root user, you will have to run it as the group you
69505+ specify here.
69506+
69507+config GRKERNSEC_PROC_USER
69508+ bool "Restrict /proc to user only"
69509+ depends on GRKERNSEC_PROC
69510+ help
69511+ If you say Y here, non-root users will only be able to view their own
69512+ processes, and restricts them from viewing network-related information,
69513+ and viewing kernel symbol and module information.
69514+
69515+config GRKERNSEC_PROC_USERGROUP
69516+ bool "Allow special group"
69517+ default y if GRKERNSEC_CONFIG_AUTO
69518+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
69519+ help
69520+ If you say Y here, you will be able to select a group that will be
69521+ able to view all processes and network-related information. If you've
69522+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
69523+ remain hidden. This option is useful if you want to run identd as
69524+ a non-root user. The group you select may also be chosen at boot time
69525+ via "grsec_proc_gid=" on the kernel commandline.
69526+
69527+config GRKERNSEC_PROC_GID
69528+ int "GID for special group"
69529+ depends on GRKERNSEC_PROC_USERGROUP
69530+ default 1001
69531+
69532+config GRKERNSEC_PROC_ADD
69533+ bool "Additional restrictions"
69534+ default y if GRKERNSEC_CONFIG_AUTO
69535+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
69536+ help
69537+ If you say Y here, additional restrictions will be placed on
69538+ /proc that keep normal users from viewing device information and
69539+ slabinfo information that could be useful for exploits.
69540+
69541+config GRKERNSEC_LINK
69542+ bool "Linking restrictions"
69543+ default y if GRKERNSEC_CONFIG_AUTO
69544+ help
69545+ If you say Y here, /tmp race exploits will be prevented, since users
69546+ will no longer be able to follow symlinks owned by other users in
69547+ world-writable +t directories (e.g. /tmp), unless the owner of the
69548+ symlink is the owner of the directory. users will also not be
69549+ able to hardlink to files they do not own. If the sysctl option is
69550+ enabled, a sysctl option with name "linking_restrictions" is created.
69551+
69552+config GRKERNSEC_SYMLINKOWN
69553+ bool "Kernel-enforced SymlinksIfOwnerMatch"
69554+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69555+ help
69556+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
69557+ that prevents it from being used as a security feature. As Apache
69558+ verifies the symlink by performing a stat() against the target of
69559+ the symlink before it is followed, an attacker can setup a symlink
69560+ to point to a same-owned file, then replace the symlink with one
69561+ that targets another user's file just after Apache "validates" the
69562+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
69563+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
69564+ will be in place for the group you specify. If the sysctl option
69565+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
69566+ created.
69567+
69568+config GRKERNSEC_SYMLINKOWN_GID
69569+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
69570+ depends on GRKERNSEC_SYMLINKOWN
69571+ default 1006
69572+ help
69573+ Setting this GID determines what group kernel-enforced
69574+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
69575+ is enabled, a sysctl option with name "symlinkown_gid" is created.
69576+
69577+config GRKERNSEC_FIFO
69578+ bool "FIFO restrictions"
69579+ default y if GRKERNSEC_CONFIG_AUTO
69580+ help
69581+ If you say Y here, users will not be able to write to FIFOs they don't
69582+ own in world-writable +t directories (e.g. /tmp), unless the owner of
69583+ the FIFO is the same owner of the directory it's held in. If the sysctl
69584+ option is enabled, a sysctl option with name "fifo_restrictions" is
69585+ created.
69586+
69587+config GRKERNSEC_SYSFS_RESTRICT
69588+ bool "Sysfs/debugfs restriction"
69589+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69590+ depends on SYSFS
69591+ help
69592+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
69593+ any filesystem normally mounted under it (e.g. debugfs) will be
69594+ mostly accessible only by root. These filesystems generally provide access
69595+ to hardware and debug information that isn't appropriate for unprivileged
69596+ users of the system. Sysfs and debugfs have also become a large source
69597+ of new vulnerabilities, ranging from infoleaks to local compromise.
69598+ There has been very little oversight with an eye toward security involved
69599+ in adding new exporters of information to these filesystems, so their
69600+ use is discouraged.
69601+ For reasons of compatibility, a few directories have been whitelisted
69602+ for access by non-root users:
69603+ /sys/fs/selinux
69604+ /sys/fs/fuse
69605+ /sys/devices/system/cpu
69606+
69607+config GRKERNSEC_ROFS
69608+ bool "Runtime read-only mount protection"
69609+ depends on SYSCTL
69610+ help
69611+ If you say Y here, a sysctl option with name "romount_protect" will
69612+ be created. By setting this option to 1 at runtime, filesystems
69613+ will be protected in the following ways:
69614+ * No new writable mounts will be allowed
69615+ * Existing read-only mounts won't be able to be remounted read/write
69616+ * Write operations will be denied on all block devices
69617+ This option acts independently of grsec_lock: once it is set to 1,
69618+ it cannot be turned off. Therefore, please be mindful of the resulting
69619+ behavior if this option is enabled in an init script on a read-only
69620+ filesystem.
69621+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
69622+ and GRKERNSEC_IO should be enabled and module loading disabled via
69623+ config or at runtime.
69624+ This feature is mainly intended for secure embedded systems.
69625+
69626+
69627+config GRKERNSEC_DEVICE_SIDECHANNEL
69628+ bool "Eliminate stat/notify-based device sidechannels"
69629+ default y if GRKERNSEC_CONFIG_AUTO
69630+ help
69631+ If you say Y here, timing analyses on block or character
69632+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
69633+ will be thwarted for unprivileged users. If a process without
69634+ CAP_MKNOD stats such a device, the last access and last modify times
69635+ will match the device's create time. No access or modify events
69636+ will be triggered through inotify/dnotify/fanotify for such devices.
69637+ This feature will prevent attacks that may at a minimum
69638+ allow an attacker to determine the administrator's password length.
69639+
69640+config GRKERNSEC_CHROOT
69641+ bool "Chroot jail restrictions"
69642+ default y if GRKERNSEC_CONFIG_AUTO
69643+ help
69644+ If you say Y here, you will be able to choose several options that will
69645+ make breaking out of a chrooted jail much more difficult. If you
69646+ encounter no software incompatibilities with the following options, it
69647+ is recommended that you enable each one.
69648+
69649+ Note that the chroot restrictions are not intended to apply to "chroots"
69650+ to directories that are simple bind mounts of the global root filesystem.
69651+ For several other reasons, a user shouldn't expect any significant
69652+ security by performing such a chroot.
69653+
69654+config GRKERNSEC_CHROOT_MOUNT
69655+ bool "Deny mounts"
69656+ default y if GRKERNSEC_CONFIG_AUTO
69657+ depends on GRKERNSEC_CHROOT
69658+ help
69659+ If you say Y here, processes inside a chroot will not be able to
69660+ mount or remount filesystems. If the sysctl option is enabled, a
69661+ sysctl option with name "chroot_deny_mount" is created.
69662+
69663+config GRKERNSEC_CHROOT_DOUBLE
69664+ bool "Deny double-chroots"
69665+ default y if GRKERNSEC_CONFIG_AUTO
69666+ depends on GRKERNSEC_CHROOT
69667+ help
69668+ If you say Y here, processes inside a chroot will not be able to chroot
69669+ again outside the chroot. This is a widely used method of breaking
69670+ out of a chroot jail and should not be allowed. If the sysctl
69671+ option is enabled, a sysctl option with name
69672+ "chroot_deny_chroot" is created.
69673+
69674+config GRKERNSEC_CHROOT_PIVOT
69675+ bool "Deny pivot_root in chroot"
69676+ default y if GRKERNSEC_CONFIG_AUTO
69677+ depends on GRKERNSEC_CHROOT
69678+ help
69679+ If you say Y here, processes inside a chroot will not be able to use
69680+ a function called pivot_root() that was introduced in Linux 2.3.41. It
69681+ works similar to chroot in that it changes the root filesystem. This
69682+ function could be misused in a chrooted process to attempt to break out
69683+ of the chroot, and therefore should not be allowed. If the sysctl
69684+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
69685+ created.
69686+
69687+config GRKERNSEC_CHROOT_CHDIR
69688+ bool "Enforce chdir(\"/\") on all chroots"
69689+ default y if GRKERNSEC_CONFIG_AUTO
69690+ depends on GRKERNSEC_CHROOT
69691+ help
69692+ If you say Y here, the current working directory of all newly-chrooted
69693+ applications will be set to the the root directory of the chroot.
69694+ The man page on chroot(2) states:
69695+ Note that this call does not change the current working
69696+ directory, so that `.' can be outside the tree rooted at
69697+ `/'. In particular, the super-user can escape from a
69698+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
69699+
69700+ It is recommended that you say Y here, since it's not known to break
69701+ any software. If the sysctl option is enabled, a sysctl option with
69702+ name "chroot_enforce_chdir" is created.
69703+
69704+config GRKERNSEC_CHROOT_CHMOD
69705+ bool "Deny (f)chmod +s"
69706+ default y if GRKERNSEC_CONFIG_AUTO
69707+ depends on GRKERNSEC_CHROOT
69708+ help
69709+ If you say Y here, processes inside a chroot will not be able to chmod
69710+ or fchmod files to make them have suid or sgid bits. This protects
69711+ against another published method of breaking a chroot. If the sysctl
69712+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
69713+ created.
69714+
69715+config GRKERNSEC_CHROOT_FCHDIR
69716+ bool "Deny fchdir and fhandle out of chroot"
69717+ default y if GRKERNSEC_CONFIG_AUTO
69718+ depends on GRKERNSEC_CHROOT
69719+ help
69720+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
69721+ to a file descriptor of the chrooting process that points to a directory
69722+ outside the filesystem will be stopped. Additionally, this option prevents
69723+ use of the recently-created syscall for opening files by a guessable "file
69724+ handle" inside a chroot. If the sysctl option is enabled, a sysctl option
69725+ with name "chroot_deny_fchdir" is created.
69726+
69727+config GRKERNSEC_CHROOT_MKNOD
69728+ bool "Deny mknod"
69729+ default y if GRKERNSEC_CONFIG_AUTO
69730+ depends on GRKERNSEC_CHROOT
69731+ help
69732+ If you say Y here, processes inside a chroot will not be allowed to
69733+ mknod. The problem with using mknod inside a chroot is that it
69734+ would allow an attacker to create a device entry that is the same
69735+ as one on the physical root of your system, which could range from
69736+ anything from the console device to a device for your harddrive (which
69737+ they could then use to wipe the drive or steal data). It is recommended
69738+ that you say Y here, unless you run into software incompatibilities.
69739+ If the sysctl option is enabled, a sysctl option with name
69740+ "chroot_deny_mknod" is created.
69741+
69742+config GRKERNSEC_CHROOT_SHMAT
69743+ bool "Deny shmat() out of chroot"
69744+ default y if GRKERNSEC_CONFIG_AUTO
69745+ depends on GRKERNSEC_CHROOT
69746+ help
69747+ If you say Y here, processes inside a chroot will not be able to attach
69748+ to shared memory segments that were created outside of the chroot jail.
69749+ It is recommended that you say Y here. If the sysctl option is enabled,
69750+ a sysctl option with name "chroot_deny_shmat" is created.
69751+
69752+config GRKERNSEC_CHROOT_UNIX
69753+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
69754+ default y if GRKERNSEC_CONFIG_AUTO
69755+ depends on GRKERNSEC_CHROOT
69756+ help
69757+ If you say Y here, processes inside a chroot will not be able to
69758+ connect to abstract (meaning not belonging to a filesystem) Unix
69759+ domain sockets that were bound outside of a chroot. It is recommended
69760+ that you say Y here. If the sysctl option is enabled, a sysctl option
69761+ with name "chroot_deny_unix" is created.
69762+
69763+config GRKERNSEC_CHROOT_FINDTASK
69764+ bool "Protect outside processes"
69765+ default y if GRKERNSEC_CONFIG_AUTO
69766+ depends on GRKERNSEC_CHROOT
69767+ help
69768+ If you say Y here, processes inside a chroot will not be able to
69769+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
69770+ getsid, or view any process outside of the chroot. If the sysctl
69771+ option is enabled, a sysctl option with name "chroot_findtask" is
69772+ created.
69773+
69774+config GRKERNSEC_CHROOT_NICE
69775+ bool "Restrict priority changes"
69776+ default y if GRKERNSEC_CONFIG_AUTO
69777+ depends on GRKERNSEC_CHROOT
69778+ help
69779+ If you say Y here, processes inside a chroot will not be able to raise
69780+ the priority of processes in the chroot, or alter the priority of
69781+ processes outside the chroot. This provides more security than simply
69782+ removing CAP_SYS_NICE from the process' capability set. If the
69783+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
69784+ is created.
69785+
69786+config GRKERNSEC_CHROOT_SYSCTL
69787+ bool "Deny sysctl writes"
69788+ default y if GRKERNSEC_CONFIG_AUTO
69789+ depends on GRKERNSEC_CHROOT
69790+ help
69791+ If you say Y here, an attacker in a chroot will not be able to
69792+ write to sysctl entries, either by sysctl(2) or through a /proc
69793+ interface. It is strongly recommended that you say Y here. If the
69794+ sysctl option is enabled, a sysctl option with name
69795+ "chroot_deny_sysctl" is created.
69796+
69797+config GRKERNSEC_CHROOT_CAPS
69798+ bool "Capability restrictions"
69799+ default y if GRKERNSEC_CONFIG_AUTO
69800+ depends on GRKERNSEC_CHROOT
69801+ help
69802+ If you say Y here, the capabilities on all processes within a
69803+ chroot jail will be lowered to stop module insertion, raw i/o,
69804+ system and net admin tasks, rebooting the system, modifying immutable
69805+ files, modifying IPC owned by another, and changing the system time.
69806+ This is left an option because it can break some apps. Disable this
69807+ if your chrooted apps are having problems performing those kinds of
69808+ tasks. If the sysctl option is enabled, a sysctl option with
69809+ name "chroot_caps" is created.
69810+
69811+config GRKERNSEC_CHROOT_INITRD
69812+ bool "Exempt initrd tasks from restrictions"
69813+ default y if GRKERNSEC_CONFIG_AUTO
69814+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
69815+ help
69816+ If you say Y here, tasks started prior to init will be exempted from
69817+ grsecurity's chroot restrictions. This option is mainly meant to
69818+ resolve Plymouth's performing privileged operations unnecessarily
69819+ in a chroot.
69820+
69821+endmenu
69822+menu "Kernel Auditing"
69823+depends on GRKERNSEC
69824+
69825+config GRKERNSEC_AUDIT_GROUP
69826+ bool "Single group for auditing"
69827+ help
69828+ If you say Y here, the exec and chdir logging features will only operate
69829+ on a group you specify. This option is recommended if you only want to
69830+ watch certain users instead of having a large amount of logs from the
69831+ entire system. If the sysctl option is enabled, a sysctl option with
69832+ name "audit_group" is created.
69833+
69834+config GRKERNSEC_AUDIT_GID
69835+ int "GID for auditing"
69836+ depends on GRKERNSEC_AUDIT_GROUP
69837+ default 1007
69838+
69839+config GRKERNSEC_EXECLOG
69840+ bool "Exec logging"
69841+ help
69842+ If you say Y here, all execve() calls will be logged (since the
69843+ other exec*() calls are frontends to execve(), all execution
69844+ will be logged). Useful for shell-servers that like to keep track
69845+ of their users. If the sysctl option is enabled, a sysctl option with
69846+ name "exec_logging" is created.
69847+ WARNING: This option when enabled will produce a LOT of logs, especially
69848+ on an active system.
69849+
69850+config GRKERNSEC_RESLOG
69851+ bool "Resource logging"
69852+ default y if GRKERNSEC_CONFIG_AUTO
69853+ help
69854+ If you say Y here, all attempts to overstep resource limits will
69855+ be logged with the resource name, the requested size, and the current
69856+ limit. It is highly recommended that you say Y here. If the sysctl
69857+ option is enabled, a sysctl option with name "resource_logging" is
69858+ created. If the RBAC system is enabled, the sysctl value is ignored.
69859+
69860+config GRKERNSEC_CHROOT_EXECLOG
69861+ bool "Log execs within chroot"
69862+ help
69863+ If you say Y here, all executions inside a chroot jail will be logged
69864+ to syslog. This can cause a large amount of logs if certain
69865+ applications (eg. djb's daemontools) are installed on the system, and
69866+ is therefore left as an option. If the sysctl option is enabled, a
69867+ sysctl option with name "chroot_execlog" is created.
69868+
69869+config GRKERNSEC_AUDIT_PTRACE
69870+ bool "Ptrace logging"
69871+ help
69872+ If you say Y here, all attempts to attach to a process via ptrace
69873+ will be logged. If the sysctl option is enabled, a sysctl option
69874+ with name "audit_ptrace" is created.
69875+
69876+config GRKERNSEC_AUDIT_CHDIR
69877+ bool "Chdir logging"
69878+ help
69879+ If you say Y here, all chdir() calls will be logged. If the sysctl
69880+ option is enabled, a sysctl option with name "audit_chdir" is created.
69881+
69882+config GRKERNSEC_AUDIT_MOUNT
69883+ bool "(Un)Mount logging"
69884+ help
69885+ If you say Y here, all mounts and unmounts will be logged. If the
69886+ sysctl option is enabled, a sysctl option with name "audit_mount" is
69887+ created.
69888+
69889+config GRKERNSEC_SIGNAL
69890+ bool "Signal logging"
69891+ default y if GRKERNSEC_CONFIG_AUTO
69892+ help
69893+ If you say Y here, certain important signals will be logged, such as
69894+ SIGSEGV, which will as a result inform you of when a error in a program
69895+ occurred, which in some cases could mean a possible exploit attempt.
69896+ If the sysctl option is enabled, a sysctl option with name
69897+ "signal_logging" is created.
69898+
69899+config GRKERNSEC_FORKFAIL
69900+ bool "Fork failure logging"
69901+ help
69902+ If you say Y here, all failed fork() attempts will be logged.
69903+ This could suggest a fork bomb, or someone attempting to overstep
69904+ their process limit. If the sysctl option is enabled, a sysctl option
69905+ with name "forkfail_logging" is created.
69906+
69907+config GRKERNSEC_TIME
69908+ bool "Time change logging"
69909+ default y if GRKERNSEC_CONFIG_AUTO
69910+ help
69911+ If you say Y here, any changes of the system clock will be logged.
69912+ If the sysctl option is enabled, a sysctl option with name
69913+ "timechange_logging" is created.
69914+
69915+config GRKERNSEC_PROC_IPADDR
69916+ bool "/proc/<pid>/ipaddr support"
69917+ default y if GRKERNSEC_CONFIG_AUTO
69918+ help
69919+ If you say Y here, a new entry will be added to each /proc/<pid>
69920+ directory that contains the IP address of the person using the task.
69921+ The IP is carried across local TCP and AF_UNIX stream sockets.
69922+ This information can be useful for IDS/IPSes to perform remote response
69923+ to a local attack. The entry is readable by only the owner of the
69924+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69925+ the RBAC system), and thus does not create privacy concerns.
69926+
69927+config GRKERNSEC_RWXMAP_LOG
69928+ bool 'Denied RWX mmap/mprotect logging'
69929+ default y if GRKERNSEC_CONFIG_AUTO
69930+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69931+ help
69932+ If you say Y here, calls to mmap() and mprotect() with explicit
69933+ usage of PROT_WRITE and PROT_EXEC together will be logged when
69934+ denied by the PAX_MPROTECT feature. This feature will also
69935+ log other problematic scenarios that can occur when PAX_MPROTECT
69936+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
69937+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69938+ is created.
69939+
69940+endmenu
69941+
69942+menu "Executable Protections"
69943+depends on GRKERNSEC
69944+
69945+config GRKERNSEC_DMESG
69946+ bool "Dmesg(8) restriction"
69947+ default y if GRKERNSEC_CONFIG_AUTO
69948+ help
69949+ If you say Y here, non-root users will not be able to use dmesg(8)
69950+ to view the contents of the kernel's circular log buffer.
69951+ The kernel's log buffer often contains kernel addresses and other
69952+ identifying information useful to an attacker in fingerprinting a
69953+ system for a targeted exploit.
69954+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
69955+ created.
69956+
69957+config GRKERNSEC_HARDEN_PTRACE
69958+ bool "Deter ptrace-based process snooping"
69959+ default y if GRKERNSEC_CONFIG_AUTO
69960+ help
69961+ If you say Y here, TTY sniffers and other malicious monitoring
69962+ programs implemented through ptrace will be defeated. If you
69963+ have been using the RBAC system, this option has already been
69964+ enabled for several years for all users, with the ability to make
69965+ fine-grained exceptions.
69966+
69967+ This option only affects the ability of non-root users to ptrace
69968+ processes that are not a descendent of the ptracing process.
69969+ This means that strace ./binary and gdb ./binary will still work,
69970+ but attaching to arbitrary processes will not. If the sysctl
69971+ option is enabled, a sysctl option with name "harden_ptrace" is
69972+ created.
69973+
69974+config GRKERNSEC_PTRACE_READEXEC
69975+ bool "Require read access to ptrace sensitive binaries"
69976+ default y if GRKERNSEC_CONFIG_AUTO
69977+ help
69978+ If you say Y here, unprivileged users will not be able to ptrace unreadable
69979+ binaries. This option is useful in environments that
69980+ remove the read bits (e.g. file mode 4711) from suid binaries to
69981+ prevent infoleaking of their contents. This option adds
69982+ consistency to the use of that file mode, as the binary could normally
69983+ be read out when run without privileges while ptracing.
69984+
69985+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69986+ is created.
69987+
69988+config GRKERNSEC_SETXID
69989+ bool "Enforce consistent multithreaded privileges"
69990+ default y if GRKERNSEC_CONFIG_AUTO
69991+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69992+ help
69993+ If you say Y here, a change from a root uid to a non-root uid
69994+ in a multithreaded application will cause the resulting uids,
69995+ gids, supplementary groups, and capabilities in that thread
69996+ to be propagated to the other threads of the process. In most
69997+ cases this is unnecessary, as glibc will emulate this behavior
69998+ on behalf of the application. Other libcs do not act in the
69999+ same way, allowing the other threads of the process to continue
70000+ running with root privileges. If the sysctl option is enabled,
70001+ a sysctl option with name "consistent_setxid" is created.
70002+
70003+config GRKERNSEC_HARDEN_IPC
70004+ bool "Disallow access to overly-permissive IPC objects"
70005+ default y if GRKERNSEC_CONFIG_AUTO
70006+ depends on SYSVIPC
70007+ help
70008+ If you say Y here, access to overly-permissive IPC objects (shared
70009+ memory, message queues, and semaphores) will be denied for processes
70010+ given the following criteria beyond normal permission checks:
70011+ 1) If the IPC object is world-accessible and the euid doesn't match
70012+ that of the creator or current uid for the IPC object
70013+ 2) If the IPC object is group-accessible and the egid doesn't
70014+ match that of the creator or current gid for the IPC object
70015+ It's a common error to grant too much permission to these objects,
70016+ with impact ranging from denial of service and information leaking to
70017+ privilege escalation. This feature was developed in response to
70018+ research by Tim Brown:
70019+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
70020+ who found hundreds of such insecure usages. Processes with
70021+ CAP_IPC_OWNER are still permitted to access these IPC objects.
70022+ If the sysctl option is enabled, a sysctl option with name
70023+ "harden_ipc" is created.
70024+
70025+config GRKERNSEC_TPE
70026+ bool "Trusted Path Execution (TPE)"
70027+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
70028+ help
70029+ If you say Y here, you will be able to choose a gid to add to the
70030+ supplementary groups of users you want to mark as "untrusted."
70031+ These users will not be able to execute any files that are not in
70032+ root-owned directories writable only by root. If the sysctl option
70033+ is enabled, a sysctl option with name "tpe" is created.
70034+
70035+config GRKERNSEC_TPE_ALL
70036+ bool "Partially restrict all non-root users"
70037+ depends on GRKERNSEC_TPE
70038+ help
70039+ If you say Y here, all non-root users will be covered under
70040+ a weaker TPE restriction. This is separate from, and in addition to,
70041+ the main TPE options that you have selected elsewhere. Thus, if a
70042+ "trusted" GID is chosen, this restriction applies to even that GID.
70043+ Under this restriction, all non-root users will only be allowed to
70044+ execute files in directories they own that are not group or
70045+ world-writable, or in directories owned by root and writable only by
70046+ root. If the sysctl option is enabled, a sysctl option with name
70047+ "tpe_restrict_all" is created.
70048+
70049+config GRKERNSEC_TPE_INVERT
70050+ bool "Invert GID option"
70051+ depends on GRKERNSEC_TPE
70052+ help
70053+ If you say Y here, the group you specify in the TPE configuration will
70054+ decide what group TPE restrictions will be *disabled* for. This
70055+ option is useful if you want TPE restrictions to be applied to most
70056+ users on the system. If the sysctl option is enabled, a sysctl option
70057+ with name "tpe_invert" is created. Unlike other sysctl options, this
70058+ entry will default to on for backward-compatibility.
70059+
70060+config GRKERNSEC_TPE_GID
70061+ int
70062+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
70063+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
70064+
70065+config GRKERNSEC_TPE_UNTRUSTED_GID
70066+ int "GID for TPE-untrusted users"
70067+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
70068+ default 1005
70069+ help
70070+ Setting this GID determines what group TPE restrictions will be
70071+ *enabled* for. If the sysctl option is enabled, a sysctl option
70072+ with name "tpe_gid" is created.
70073+
70074+config GRKERNSEC_TPE_TRUSTED_GID
70075+ int "GID for TPE-trusted users"
70076+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
70077+ default 1005
70078+ help
70079+ Setting this GID determines what group TPE restrictions will be
70080+ *disabled* for. If the sysctl option is enabled, a sysctl option
70081+ with name "tpe_gid" is created.
70082+
70083+endmenu
70084+menu "Network Protections"
70085+depends on GRKERNSEC
70086+
70087+config GRKERNSEC_BLACKHOLE
70088+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
70089+ default y if GRKERNSEC_CONFIG_AUTO
70090+ depends on NET
70091+ help
70092+ If you say Y here, neither TCP resets nor ICMP
70093+ destination-unreachable packets will be sent in response to packets
70094+ sent to ports for which no associated listening process exists.
70095+ This feature supports both IPV4 and IPV6 and exempts the
70096+ loopback interface from blackholing. Enabling this feature
70097+ makes a host more resilient to DoS attacks and reduces network
70098+ visibility against scanners.
70099+
70100+ The blackhole feature as-implemented is equivalent to the FreeBSD
70101+ blackhole feature, as it prevents RST responses to all packets, not
70102+ just SYNs. Under most application behavior this causes no
70103+ problems, but applications (like haproxy) may not close certain
70104+ connections in a way that cleanly terminates them on the remote
70105+ end, leaving the remote host in LAST_ACK state. Because of this
70106+ side-effect and to prevent intentional LAST_ACK DoSes, this
70107+ feature also adds automatic mitigation against such attacks.
70108+ The mitigation drastically reduces the amount of time a socket
70109+ can spend in LAST_ACK state. If you're using haproxy and not
70110+ all servers it connects to have this option enabled, consider
70111+ disabling this feature on the haproxy host.
70112+
70113+ If the sysctl option is enabled, two sysctl options with names
70114+ "ip_blackhole" and "lastack_retries" will be created.
70115+ While "ip_blackhole" takes the standard zero/non-zero on/off
70116+ toggle, "lastack_retries" uses the same kinds of values as
70117+ "tcp_retries1" and "tcp_retries2". The default value of 4
70118+ prevents a socket from lasting more than 45 seconds in LAST_ACK
70119+ state.
70120+
70121+config GRKERNSEC_NO_SIMULT_CONNECT
70122+ bool "Disable TCP Simultaneous Connect"
70123+ default y if GRKERNSEC_CONFIG_AUTO
70124+ depends on NET
70125+ help
70126+ If you say Y here, a feature by Willy Tarreau will be enabled that
70127+ removes a weakness in Linux's strict implementation of TCP that
70128+ allows two clients to connect to each other without either entering
70129+ a listening state. The weakness allows an attacker to easily prevent
70130+ a client from connecting to a known server provided the source port
70131+ for the connection is guessed correctly.
70132+
70133+ As the weakness could be used to prevent an antivirus or IPS from
70134+ fetching updates, or prevent an SSL gateway from fetching a CRL,
70135+ it should be eliminated by enabling this option. Though Linux is
70136+ one of few operating systems supporting simultaneous connect, it
70137+ has no legitimate use in practice and is rarely supported by firewalls.
70138+
70139+config GRKERNSEC_SOCKET
70140+ bool "Socket restrictions"
70141+ depends on NET
70142+ help
70143+ If you say Y here, you will be able to choose from several options.
70144+ If you assign a GID on your system and add it to the supplementary
70145+ groups of users you want to restrict socket access to, this patch
70146+ will perform up to three things, based on the option(s) you choose.
70147+
70148+config GRKERNSEC_SOCKET_ALL
70149+ bool "Deny any sockets to group"
70150+ depends on GRKERNSEC_SOCKET
70151+ help
70152+ If you say Y here, you will be able to choose a GID of whose users will
70153+ be unable to connect to other hosts from your machine or run server
70154+ applications from your machine. If the sysctl option is enabled, a
70155+ sysctl option with name "socket_all" is created.
70156+
70157+config GRKERNSEC_SOCKET_ALL_GID
70158+ int "GID to deny all sockets for"
70159+ depends on GRKERNSEC_SOCKET_ALL
70160+ default 1004
70161+ help
70162+ Here you can choose the GID to disable socket access for. Remember to
70163+ add the users you want socket access disabled for to the GID
70164+ specified here. If the sysctl option is enabled, a sysctl option
70165+ with name "socket_all_gid" is created.
70166+
70167+config GRKERNSEC_SOCKET_CLIENT
70168+ bool "Deny client sockets to group"
70169+ depends on GRKERNSEC_SOCKET
70170+ help
70171+ If you say Y here, you will be able to choose a GID of whose users will
70172+ be unable to connect to other hosts from your machine, but will be
70173+ able to run servers. If this option is enabled, all users in the group
70174+ you specify will have to use passive mode when initiating ftp transfers
70175+ from the shell on your machine. If the sysctl option is enabled, a
70176+ sysctl option with name "socket_client" is created.
70177+
70178+config GRKERNSEC_SOCKET_CLIENT_GID
70179+ int "GID to deny client sockets for"
70180+ depends on GRKERNSEC_SOCKET_CLIENT
70181+ default 1003
70182+ help
70183+ Here you can choose the GID to disable client socket access for.
70184+ Remember to add the users you want client socket access disabled for to
70185+ the GID specified here. If the sysctl option is enabled, a sysctl
70186+ option with name "socket_client_gid" is created.
70187+
70188+config GRKERNSEC_SOCKET_SERVER
70189+ bool "Deny server sockets to group"
70190+ depends on GRKERNSEC_SOCKET
70191+ help
70192+ If you say Y here, you will be able to choose a GID of whose users will
70193+ be unable to run server applications from your machine. If the sysctl
70194+ option is enabled, a sysctl option with name "socket_server" is created.
70195+
70196+config GRKERNSEC_SOCKET_SERVER_GID
70197+ int "GID to deny server sockets for"
70198+ depends on GRKERNSEC_SOCKET_SERVER
70199+ default 1002
70200+ help
70201+ Here you can choose the GID to disable server socket access for.
70202+ Remember to add the users you want server socket access disabled for to
70203+ the GID specified here. If the sysctl option is enabled, a sysctl
70204+ option with name "socket_server_gid" is created.
70205+
70206+endmenu
70207+
70208+menu "Physical Protections"
70209+depends on GRKERNSEC
70210+
70211+config GRKERNSEC_DENYUSB
70212+ bool "Deny new USB connections after toggle"
70213+ default y if GRKERNSEC_CONFIG_AUTO
70214+ depends on SYSCTL && USB_SUPPORT
70215+ help
70216+ If you say Y here, a new sysctl option with name "deny_new_usb"
70217+ will be created. Setting its value to 1 will prevent any new
70218+ USB devices from being recognized by the OS. Any attempted USB
70219+ device insertion will be logged. This option is intended to be
70220+ used against custom USB devices designed to exploit vulnerabilities
70221+ in various USB device drivers.
70222+
70223+ For greatest effectiveness, this sysctl should be set after any
70224+ relevant init scripts. This option is safe to enable in distros
70225+ as each user can choose whether or not to toggle the sysctl.
70226+
70227+config GRKERNSEC_DENYUSB_FORCE
70228+ bool "Reject all USB devices not connected at boot"
70229+ select USB
70230+ depends on GRKERNSEC_DENYUSB
70231+ help
70232+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
70233+ that doesn't involve a sysctl entry. This option should only be
70234+ enabled if you're sure you want to deny all new USB connections
70235+ at runtime and don't want to modify init scripts. This should not
70236+ be enabled by distros. It forces the core USB code to be built
70237+ into the kernel image so that all devices connected at boot time
70238+ can be recognized and new USB device connections can be prevented
70239+ prior to init running.
70240+
70241+endmenu
70242+
70243+menu "Sysctl Support"
70244+depends on GRKERNSEC && SYSCTL
70245+
70246+config GRKERNSEC_SYSCTL
70247+ bool "Sysctl support"
70248+ default y if GRKERNSEC_CONFIG_AUTO
70249+ help
70250+ If you say Y here, you will be able to change the options that
70251+ grsecurity runs with at bootup, without having to recompile your
70252+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
70253+ to enable (1) or disable (0) various features. All the sysctl entries
70254+ are mutable until the "grsec_lock" entry is set to a non-zero value.
70255+ All features enabled in the kernel configuration are disabled at boot
70256+ if you do not say Y to the "Turn on features by default" option.
70257+ All options should be set at startup, and the grsec_lock entry should
70258+ be set to a non-zero value after all the options are set.
70259+ *THIS IS EXTREMELY IMPORTANT*
70260+
70261+config GRKERNSEC_SYSCTL_DISTRO
70262+ bool "Extra sysctl support for distro makers (READ HELP)"
70263+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
70264+ help
70265+ If you say Y here, additional sysctl options will be created
70266+ for features that affect processes running as root. Therefore,
70267+ it is critical when using this option that the grsec_lock entry be
70268+ enabled after boot. Only distros with prebuilt kernel packages
70269+ with this option enabled that can ensure grsec_lock is enabled
70270+ after boot should use this option.
70271+ *Failure to set grsec_lock after boot makes all grsec features
70272+ this option covers useless*
70273+
70274+ Currently this option creates the following sysctl entries:
70275+ "Disable Privileged I/O": "disable_priv_io"
70276+
70277+config GRKERNSEC_SYSCTL_ON
70278+ bool "Turn on features by default"
70279+ default y if GRKERNSEC_CONFIG_AUTO
70280+ depends on GRKERNSEC_SYSCTL
70281+ help
70282+ If you say Y here, instead of having all features enabled in the
70283+ kernel configuration disabled at boot time, the features will be
70284+ enabled at boot time. It is recommended you say Y here unless
70285+ there is some reason you would want all sysctl-tunable features to
70286+ be disabled by default. As mentioned elsewhere, it is important
70287+ to enable the grsec_lock entry once you have finished modifying
70288+ the sysctl entries.
70289+
70290+endmenu
70291+menu "Logging Options"
70292+depends on GRKERNSEC
70293+
70294+config GRKERNSEC_FLOODTIME
70295+ int "Seconds in between log messages (minimum)"
70296+ default 10
70297+ help
70298+ This option allows you to enforce the number of seconds between
70299+ grsecurity log messages. The default should be suitable for most
70300+ people, however, if you choose to change it, choose a value small enough
70301+ to allow informative logs to be produced, but large enough to
70302+ prevent flooding.
70303+
70304+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
70305+ any rate limiting on grsecurity log messages.
70306+
70307+config GRKERNSEC_FLOODBURST
70308+ int "Number of messages in a burst (maximum)"
70309+ default 6
70310+ help
70311+ This option allows you to choose the maximum number of messages allowed
70312+ within the flood time interval you chose in a separate option. The
70313+ default should be suitable for most people, however if you find that
70314+ many of your logs are being interpreted as flooding, you may want to
70315+ raise this value.
70316+
70317+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
70318+ any rate limiting on grsecurity log messages.
70319+
70320+endmenu
70321diff --git a/grsecurity/Makefile b/grsecurity/Makefile
70322new file mode 100644
70323index 0000000..30ababb
70324--- /dev/null
70325+++ b/grsecurity/Makefile
70326@@ -0,0 +1,54 @@
70327+# grsecurity – access control and security hardening for Linux
70328+# All code in this directory and various hooks located throughout the Linux kernel are
70329+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
70330+# http://www.grsecurity.net spender@grsecurity.net
70331+#
70332+# This program is free software; you can redistribute it and/or
70333+# modify it under the terms of the GNU General Public License version 2
70334+# as published by the Free Software Foundation.
70335+#
70336+# This program is distributed in the hope that it will be useful,
70337+# but WITHOUT ANY WARRANTY; without even the implied warranty of
70338+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70339+# GNU General Public License for more details.
70340+#
70341+# You should have received a copy of the GNU General Public License
70342+# along with this program; if not, write to the Free Software
70343+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
70344+
70345+KBUILD_CFLAGS += -Werror
70346+
70347+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
70348+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
70349+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
70350+ grsec_usb.o grsec_ipc.o grsec_proc.o
70351+
70352+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
70353+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
70354+ gracl_learn.o grsec_log.o gracl_policy.o
70355+ifdef CONFIG_COMPAT
70356+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
70357+endif
70358+
70359+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
70360+
70361+ifdef CONFIG_NET
70362+obj-y += grsec_sock.o
70363+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
70364+endif
70365+
70366+ifndef CONFIG_GRKERNSEC
70367+obj-y += grsec_disabled.o
70368+endif
70369+
70370+ifdef CONFIG_GRKERNSEC_HIDESYM
70371+extra-y := grsec_hidesym.o
70372+$(obj)/grsec_hidesym.o:
70373+ @-chmod -f 500 /boot
70374+ @-chmod -f 500 /lib/modules
70375+ @-chmod -f 500 /lib64/modules
70376+ @-chmod -f 500 /lib32/modules
70377+ @-chmod -f 700 .
70378+ @-chmod -f 700 $(objtree)
70379+ @echo ' grsec: protected kernel image paths'
70380+endif
70381diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
70382new file mode 100644
70383index 0000000..58223f6
70384--- /dev/null
70385+++ b/grsecurity/gracl.c
70386@@ -0,0 +1,2702 @@
70387+#include <linux/kernel.h>
70388+#include <linux/module.h>
70389+#include <linux/sched.h>
70390+#include <linux/mm.h>
70391+#include <linux/file.h>
70392+#include <linux/fs.h>
70393+#include <linux/namei.h>
70394+#include <linux/mount.h>
70395+#include <linux/tty.h>
70396+#include <linux/proc_fs.h>
70397+#include <linux/lglock.h>
70398+#include <linux/slab.h>
70399+#include <linux/vmalloc.h>
70400+#include <linux/types.h>
70401+#include <linux/sysctl.h>
70402+#include <linux/netdevice.h>
70403+#include <linux/ptrace.h>
70404+#include <linux/gracl.h>
70405+#include <linux/gralloc.h>
70406+#include <linux/security.h>
70407+#include <linux/grinternal.h>
70408+#include <linux/pid_namespace.h>
70409+#include <linux/stop_machine.h>
70410+#include <linux/fdtable.h>
70411+#include <linux/percpu.h>
70412+#include <linux/lglock.h>
70413+#include <linux/hugetlb.h>
70414+#include <linux/posix-timers.h>
70415+#include <linux/prefetch.h>
70416+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
70417+#include <linux/magic.h>
70418+#include <linux/pagemap.h>
70419+#include "../fs/btrfs/async-thread.h"
70420+#include "../fs/btrfs/ctree.h"
70421+#include "../fs/btrfs/btrfs_inode.h"
70422+#endif
70423+#include "../fs/mount.h"
70424+
70425+#include <asm/uaccess.h>
70426+#include <asm/errno.h>
70427+#include <asm/mman.h>
70428+
70429+#define FOR_EACH_ROLE_START(role) \
70430+ role = running_polstate.role_list; \
70431+ while (role) {
70432+
70433+#define FOR_EACH_ROLE_END(role) \
70434+ role = role->prev; \
70435+ }
70436+
70437+extern struct path gr_real_root;
70438+
70439+static struct gr_policy_state running_polstate;
70440+struct gr_policy_state *polstate = &running_polstate;
70441+extern struct gr_alloc_state *current_alloc_state;
70442+
70443+extern char *gr_shared_page[4];
70444+DEFINE_RWLOCK(gr_inode_lock);
70445+
70446+static unsigned int gr_status __read_only = GR_STATUS_INIT;
70447+
70448+#ifdef CONFIG_NET
70449+extern struct vfsmount *sock_mnt;
70450+#endif
70451+
70452+extern struct vfsmount *pipe_mnt;
70453+extern struct vfsmount *shm_mnt;
70454+
70455+#ifdef CONFIG_HUGETLBFS
70456+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
70457+#endif
70458+
70459+extern u16 acl_sp_role_value;
70460+extern struct acl_object_label *fakefs_obj_rw;
70461+extern struct acl_object_label *fakefs_obj_rwx;
70462+
70463+int gr_acl_is_enabled(void)
70464+{
70465+ return (gr_status & GR_READY);
70466+}
70467+
70468+void gr_enable_rbac_system(void)
70469+{
70470+ pax_open_kernel();
70471+ gr_status |= GR_READY;
70472+ pax_close_kernel();
70473+}
70474+
70475+int gr_rbac_disable(void *unused)
70476+{
70477+ pax_open_kernel();
70478+ gr_status &= ~GR_READY;
70479+ pax_close_kernel();
70480+
70481+ return 0;
70482+}
70483+
70484+static inline dev_t __get_dev(const struct dentry *dentry)
70485+{
70486+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
70487+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
70488+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
70489+ else
70490+#endif
70491+ return dentry->d_sb->s_dev;
70492+}
70493+
70494+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
70495+{
70496+ return __get_dev(dentry);
70497+}
70498+
70499+static char gr_task_roletype_to_char(struct task_struct *task)
70500+{
70501+ switch (task->role->roletype &
70502+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
70503+ GR_ROLE_SPECIAL)) {
70504+ case GR_ROLE_DEFAULT:
70505+ return 'D';
70506+ case GR_ROLE_USER:
70507+ return 'U';
70508+ case GR_ROLE_GROUP:
70509+ return 'G';
70510+ case GR_ROLE_SPECIAL:
70511+ return 'S';
70512+ }
70513+
70514+ return 'X';
70515+}
70516+
70517+char gr_roletype_to_char(void)
70518+{
70519+ return gr_task_roletype_to_char(current);
70520+}
70521+
70522+__inline__ int
70523+gr_acl_tpe_check(void)
70524+{
70525+ if (unlikely(!(gr_status & GR_READY)))
70526+ return 0;
70527+ if (current->role->roletype & GR_ROLE_TPE)
70528+ return 1;
70529+ else
70530+ return 0;
70531+}
70532+
70533+int
70534+gr_handle_rawio(const struct inode *inode)
70535+{
70536+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70537+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
70538+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
70539+ !capable(CAP_SYS_RAWIO))
70540+ return 1;
70541+#endif
70542+ return 0;
70543+}
70544+
70545+int
70546+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
70547+{
70548+ if (likely(lena != lenb))
70549+ return 0;
70550+
70551+ return !memcmp(a, b, lena);
70552+}
70553+
70554+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
70555+{
70556+ *buflen -= namelen;
70557+ if (*buflen < 0)
70558+ return -ENAMETOOLONG;
70559+ *buffer -= namelen;
70560+ memcpy(*buffer, str, namelen);
70561+ return 0;
70562+}
70563+
70564+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
70565+{
70566+ return prepend(buffer, buflen, name->name, name->len);
70567+}
70568+
70569+static int prepend_path(const struct path *path, struct path *root,
70570+ char **buffer, int *buflen)
70571+{
70572+ struct dentry *dentry = path->dentry;
70573+ struct vfsmount *vfsmnt = path->mnt;
70574+ struct mount *mnt = real_mount(vfsmnt);
70575+ bool slash = false;
70576+ int error = 0;
70577+
70578+ while (dentry != root->dentry || vfsmnt != root->mnt) {
70579+ struct dentry * parent;
70580+
70581+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
70582+ /* Global root? */
70583+ if (!mnt_has_parent(mnt)) {
70584+ goto out;
70585+ }
70586+ dentry = mnt->mnt_mountpoint;
70587+ mnt = mnt->mnt_parent;
70588+ vfsmnt = &mnt->mnt;
70589+ continue;
70590+ }
70591+ parent = dentry->d_parent;
70592+ prefetch(parent);
70593+ spin_lock(&dentry->d_lock);
70594+ error = prepend_name(buffer, buflen, &dentry->d_name);
70595+ spin_unlock(&dentry->d_lock);
70596+ if (!error)
70597+ error = prepend(buffer, buflen, "/", 1);
70598+ if (error)
70599+ break;
70600+
70601+ slash = true;
70602+ dentry = parent;
70603+ }
70604+
70605+out:
70606+ if (!error && !slash)
70607+ error = prepend(buffer, buflen, "/", 1);
70608+
70609+ return error;
70610+}
70611+
70612+/* this must be called with mount_lock and rename_lock held */
70613+
70614+static char *__our_d_path(const struct path *path, struct path *root,
70615+ char *buf, int buflen)
70616+{
70617+ char *res = buf + buflen;
70618+ int error;
70619+
70620+ prepend(&res, &buflen, "\0", 1);
70621+ error = prepend_path(path, root, &res, &buflen);
70622+ if (error)
70623+ return ERR_PTR(error);
70624+
70625+ return res;
70626+}
70627+
70628+static char *
70629+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
70630+{
70631+ char *retval;
70632+
70633+ retval = __our_d_path(path, root, buf, buflen);
70634+ if (unlikely(IS_ERR(retval)))
70635+ retval = strcpy(buf, "<path too long>");
70636+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
70637+ retval[1] = '\0';
70638+
70639+ return retval;
70640+}
70641+
70642+static char *
70643+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
70644+ char *buf, int buflen)
70645+{
70646+ struct path path;
70647+ char *res;
70648+
70649+ path.dentry = (struct dentry *)dentry;
70650+ path.mnt = (struct vfsmount *)vfsmnt;
70651+
70652+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
70653+ by the RBAC system */
70654+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
70655+
70656+ return res;
70657+}
70658+
70659+static char *
70660+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
70661+ char *buf, int buflen)
70662+{
70663+ char *res;
70664+ struct path path;
70665+ struct path root;
70666+ struct task_struct *reaper = init_pid_ns.child_reaper;
70667+
70668+ path.dentry = (struct dentry *)dentry;
70669+ path.mnt = (struct vfsmount *)vfsmnt;
70670+
70671+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
70672+ get_fs_root(reaper->fs, &root);
70673+
70674+ read_seqlock_excl(&mount_lock);
70675+ write_seqlock(&rename_lock);
70676+ res = gen_full_path(&path, &root, buf, buflen);
70677+ write_sequnlock(&rename_lock);
70678+ read_sequnlock_excl(&mount_lock);
70679+
70680+ path_put(&root);
70681+ return res;
70682+}
70683+
70684+char *
70685+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70686+{
70687+ char *ret;
70688+ read_seqlock_excl(&mount_lock);
70689+ write_seqlock(&rename_lock);
70690+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70691+ PAGE_SIZE);
70692+ write_sequnlock(&rename_lock);
70693+ read_sequnlock_excl(&mount_lock);
70694+ return ret;
70695+}
70696+
70697+static char *
70698+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70699+{
70700+ char *ret;
70701+ char *buf;
70702+ int buflen;
70703+
70704+ read_seqlock_excl(&mount_lock);
70705+ write_seqlock(&rename_lock);
70706+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
70707+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
70708+ buflen = (int)(ret - buf);
70709+ if (buflen >= 5)
70710+ prepend(&ret, &buflen, "/proc", 5);
70711+ else
70712+ ret = strcpy(buf, "<path too long>");
70713+ write_sequnlock(&rename_lock);
70714+ read_sequnlock_excl(&mount_lock);
70715+ return ret;
70716+}
70717+
70718+char *
70719+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
70720+{
70721+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70722+ PAGE_SIZE);
70723+}
70724+
70725+char *
70726+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
70727+{
70728+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
70729+ PAGE_SIZE);
70730+}
70731+
70732+char *
70733+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
70734+{
70735+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
70736+ PAGE_SIZE);
70737+}
70738+
70739+char *
70740+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
70741+{
70742+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
70743+ PAGE_SIZE);
70744+}
70745+
70746+char *
70747+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
70748+{
70749+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
70750+ PAGE_SIZE);
70751+}
70752+
70753+__inline__ __u32
70754+to_gr_audit(const __u32 reqmode)
70755+{
70756+ /* masks off auditable permission flags, then shifts them to create
70757+ auditing flags, and adds the special case of append auditing if
70758+ we're requesting write */
70759+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
70760+}
70761+
70762+struct acl_role_label *
70763+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
70764+ const gid_t gid)
70765+{
70766+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
70767+ struct acl_role_label *match;
70768+ struct role_allowed_ip *ipp;
70769+ unsigned int x;
70770+ u32 curr_ip = task->signal->saved_ip;
70771+
70772+ match = state->acl_role_set.r_hash[index];
70773+
70774+ while (match) {
70775+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
70776+ for (x = 0; x < match->domain_child_num; x++) {
70777+ if (match->domain_children[x] == uid)
70778+ goto found;
70779+ }
70780+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
70781+ break;
70782+ match = match->next;
70783+ }
70784+found:
70785+ if (match == NULL) {
70786+ try_group:
70787+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
70788+ match = state->acl_role_set.r_hash[index];
70789+
70790+ while (match) {
70791+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
70792+ for (x = 0; x < match->domain_child_num; x++) {
70793+ if (match->domain_children[x] == gid)
70794+ goto found2;
70795+ }
70796+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
70797+ break;
70798+ match = match->next;
70799+ }
70800+found2:
70801+ if (match == NULL)
70802+ match = state->default_role;
70803+ if (match->allowed_ips == NULL)
70804+ return match;
70805+ else {
70806+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70807+ if (likely
70808+ ((ntohl(curr_ip) & ipp->netmask) ==
70809+ (ntohl(ipp->addr) & ipp->netmask)))
70810+ return match;
70811+ }
70812+ match = state->default_role;
70813+ }
70814+ } else if (match->allowed_ips == NULL) {
70815+ return match;
70816+ } else {
70817+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70818+ if (likely
70819+ ((ntohl(curr_ip) & ipp->netmask) ==
70820+ (ntohl(ipp->addr) & ipp->netmask)))
70821+ return match;
70822+ }
70823+ goto try_group;
70824+ }
70825+
70826+ return match;
70827+}
70828+
70829+static struct acl_role_label *
70830+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
70831+ const gid_t gid)
70832+{
70833+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
70834+}
70835+
70836+struct acl_subject_label *
70837+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
70838+ const struct acl_role_label *role)
70839+{
70840+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70841+ struct acl_subject_label *match;
70842+
70843+ match = role->subj_hash[index];
70844+
70845+ while (match && (match->inode != ino || match->device != dev ||
70846+ (match->mode & GR_DELETED))) {
70847+ match = match->next;
70848+ }
70849+
70850+ if (match && !(match->mode & GR_DELETED))
70851+ return match;
70852+ else
70853+ return NULL;
70854+}
70855+
70856+struct acl_subject_label *
70857+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
70858+ const struct acl_role_label *role)
70859+{
70860+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70861+ struct acl_subject_label *match;
70862+
70863+ match = role->subj_hash[index];
70864+
70865+ while (match && (match->inode != ino || match->device != dev ||
70866+ !(match->mode & GR_DELETED))) {
70867+ match = match->next;
70868+ }
70869+
70870+ if (match && (match->mode & GR_DELETED))
70871+ return match;
70872+ else
70873+ return NULL;
70874+}
70875+
70876+static struct acl_object_label *
70877+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
70878+ const struct acl_subject_label *subj)
70879+{
70880+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70881+ struct acl_object_label *match;
70882+
70883+ match = subj->obj_hash[index];
70884+
70885+ while (match && (match->inode != ino || match->device != dev ||
70886+ (match->mode & GR_DELETED))) {
70887+ match = match->next;
70888+ }
70889+
70890+ if (match && !(match->mode & GR_DELETED))
70891+ return match;
70892+ else
70893+ return NULL;
70894+}
70895+
70896+static struct acl_object_label *
70897+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
70898+ const struct acl_subject_label *subj)
70899+{
70900+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70901+ struct acl_object_label *match;
70902+
70903+ match = subj->obj_hash[index];
70904+
70905+ while (match && (match->inode != ino || match->device != dev ||
70906+ !(match->mode & GR_DELETED))) {
70907+ match = match->next;
70908+ }
70909+
70910+ if (match && (match->mode & GR_DELETED))
70911+ return match;
70912+
70913+ match = subj->obj_hash[index];
70914+
70915+ while (match && (match->inode != ino || match->device != dev ||
70916+ (match->mode & GR_DELETED))) {
70917+ match = match->next;
70918+ }
70919+
70920+ if (match && !(match->mode & GR_DELETED))
70921+ return match;
70922+ else
70923+ return NULL;
70924+}
70925+
70926+struct name_entry *
70927+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70928+{
70929+ unsigned int len = strlen(name);
70930+ unsigned int key = full_name_hash(name, len);
70931+ unsigned int index = key % state->name_set.n_size;
70932+ struct name_entry *match;
70933+
70934+ match = state->name_set.n_hash[index];
70935+
70936+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70937+ match = match->next;
70938+
70939+ return match;
70940+}
70941+
70942+static struct name_entry *
70943+lookup_name_entry(const char *name)
70944+{
70945+ return __lookup_name_entry(&running_polstate, name);
70946+}
70947+
70948+static struct name_entry *
70949+lookup_name_entry_create(const char *name)
70950+{
70951+ unsigned int len = strlen(name);
70952+ unsigned int key = full_name_hash(name, len);
70953+ unsigned int index = key % running_polstate.name_set.n_size;
70954+ struct name_entry *match;
70955+
70956+ match = running_polstate.name_set.n_hash[index];
70957+
70958+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70959+ !match->deleted))
70960+ match = match->next;
70961+
70962+ if (match && match->deleted)
70963+ return match;
70964+
70965+ match = running_polstate.name_set.n_hash[index];
70966+
70967+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70968+ match->deleted))
70969+ match = match->next;
70970+
70971+ if (match && !match->deleted)
70972+ return match;
70973+ else
70974+ return NULL;
70975+}
70976+
70977+static struct inodev_entry *
70978+lookup_inodev_entry(const ino_t ino, const dev_t dev)
70979+{
70980+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70981+ struct inodev_entry *match;
70982+
70983+ match = running_polstate.inodev_set.i_hash[index];
70984+
70985+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70986+ match = match->next;
70987+
70988+ return match;
70989+}
70990+
70991+void
70992+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70993+{
70994+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70995+ state->inodev_set.i_size);
70996+ struct inodev_entry **curr;
70997+
70998+ entry->prev = NULL;
70999+
71000+ curr = &state->inodev_set.i_hash[index];
71001+ if (*curr != NULL)
71002+ (*curr)->prev = entry;
71003+
71004+ entry->next = *curr;
71005+ *curr = entry;
71006+
71007+ return;
71008+}
71009+
71010+static void
71011+insert_inodev_entry(struct inodev_entry *entry)
71012+{
71013+ __insert_inodev_entry(&running_polstate, entry);
71014+}
71015+
71016+void
71017+insert_acl_obj_label(struct acl_object_label *obj,
71018+ struct acl_subject_label *subj)
71019+{
71020+ unsigned int index =
71021+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
71022+ struct acl_object_label **curr;
71023+
71024+ obj->prev = NULL;
71025+
71026+ curr = &subj->obj_hash[index];
71027+ if (*curr != NULL)
71028+ (*curr)->prev = obj;
71029+
71030+ obj->next = *curr;
71031+ *curr = obj;
71032+
71033+ return;
71034+}
71035+
71036+void
71037+insert_acl_subj_label(struct acl_subject_label *obj,
71038+ struct acl_role_label *role)
71039+{
71040+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
71041+ struct acl_subject_label **curr;
71042+
71043+ obj->prev = NULL;
71044+
71045+ curr = &role->subj_hash[index];
71046+ if (*curr != NULL)
71047+ (*curr)->prev = obj;
71048+
71049+ obj->next = *curr;
71050+ *curr = obj;
71051+
71052+ return;
71053+}
71054+
71055+/* derived from glibc fnmatch() 0: match, 1: no match*/
71056+
71057+static int
71058+glob_match(const char *p, const char *n)
71059+{
71060+ char c;
71061+
71062+ while ((c = *p++) != '\0') {
71063+ switch (c) {
71064+ case '?':
71065+ if (*n == '\0')
71066+ return 1;
71067+ else if (*n == '/')
71068+ return 1;
71069+ break;
71070+ case '\\':
71071+ if (*n != c)
71072+ return 1;
71073+ break;
71074+ case '*':
71075+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
71076+ if (*n == '/')
71077+ return 1;
71078+ else if (c == '?') {
71079+ if (*n == '\0')
71080+ return 1;
71081+ else
71082+ ++n;
71083+ }
71084+ }
71085+ if (c == '\0') {
71086+ return 0;
71087+ } else {
71088+ const char *endp;
71089+
71090+ if ((endp = strchr(n, '/')) == NULL)
71091+ endp = n + strlen(n);
71092+
71093+ if (c == '[') {
71094+ for (--p; n < endp; ++n)
71095+ if (!glob_match(p, n))
71096+ return 0;
71097+ } else if (c == '/') {
71098+ while (*n != '\0' && *n != '/')
71099+ ++n;
71100+ if (*n == '/' && !glob_match(p, n + 1))
71101+ return 0;
71102+ } else {
71103+ for (--p; n < endp; ++n)
71104+ if (*n == c && !glob_match(p, n))
71105+ return 0;
71106+ }
71107+
71108+ return 1;
71109+ }
71110+ case '[':
71111+ {
71112+ int not;
71113+ char cold;
71114+
71115+ if (*n == '\0' || *n == '/')
71116+ return 1;
71117+
71118+ not = (*p == '!' || *p == '^');
71119+ if (not)
71120+ ++p;
71121+
71122+ c = *p++;
71123+ for (;;) {
71124+ unsigned char fn = (unsigned char)*n;
71125+
71126+ if (c == '\0')
71127+ return 1;
71128+ else {
71129+ if (c == fn)
71130+ goto matched;
71131+ cold = c;
71132+ c = *p++;
71133+
71134+ if (c == '-' && *p != ']') {
71135+ unsigned char cend = *p++;
71136+
71137+ if (cend == '\0')
71138+ return 1;
71139+
71140+ if (cold <= fn && fn <= cend)
71141+ goto matched;
71142+
71143+ c = *p++;
71144+ }
71145+ }
71146+
71147+ if (c == ']')
71148+ break;
71149+ }
71150+ if (!not)
71151+ return 1;
71152+ break;
71153+ matched:
71154+ while (c != ']') {
71155+ if (c == '\0')
71156+ return 1;
71157+
71158+ c = *p++;
71159+ }
71160+ if (not)
71161+ return 1;
71162+ }
71163+ break;
71164+ default:
71165+ if (c != *n)
71166+ return 1;
71167+ }
71168+
71169+ ++n;
71170+ }
71171+
71172+ if (*n == '\0')
71173+ return 0;
71174+
71175+ if (*n == '/')
71176+ return 0;
71177+
71178+ return 1;
71179+}
71180+
71181+static struct acl_object_label *
71182+chk_glob_label(struct acl_object_label *globbed,
71183+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
71184+{
71185+ struct acl_object_label *tmp;
71186+
71187+ if (*path == NULL)
71188+ *path = gr_to_filename_nolock(dentry, mnt);
71189+
71190+ tmp = globbed;
71191+
71192+ while (tmp) {
71193+ if (!glob_match(tmp->filename, *path))
71194+ return tmp;
71195+ tmp = tmp->next;
71196+ }
71197+
71198+ return NULL;
71199+}
71200+
71201+static struct acl_object_label *
71202+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
71203+ const ino_t curr_ino, const dev_t curr_dev,
71204+ const struct acl_subject_label *subj, char **path, const int checkglob)
71205+{
71206+ struct acl_subject_label *tmpsubj;
71207+ struct acl_object_label *retval;
71208+ struct acl_object_label *retval2;
71209+
71210+ tmpsubj = (struct acl_subject_label *) subj;
71211+ read_lock(&gr_inode_lock);
71212+ do {
71213+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
71214+ if (retval) {
71215+ if (checkglob && retval->globbed) {
71216+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
71217+ if (retval2)
71218+ retval = retval2;
71219+ }
71220+ break;
71221+ }
71222+ } while ((tmpsubj = tmpsubj->parent_subject));
71223+ read_unlock(&gr_inode_lock);
71224+
71225+ return retval;
71226+}
71227+
71228+static __inline__ struct acl_object_label *
71229+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
71230+ struct dentry *curr_dentry,
71231+ const struct acl_subject_label *subj, char **path, const int checkglob)
71232+{
71233+ int newglob = checkglob;
71234+ ino_t inode;
71235+ dev_t device;
71236+
71237+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
71238+ as we don't want a / * rule to match instead of the / object
71239+ don't do this for create lookups that call this function though, since they're looking up
71240+ on the parent and thus need globbing checks on all paths
71241+ */
71242+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
71243+ newglob = GR_NO_GLOB;
71244+
71245+ spin_lock(&curr_dentry->d_lock);
71246+ inode = curr_dentry->d_inode->i_ino;
71247+ device = __get_dev(curr_dentry);
71248+ spin_unlock(&curr_dentry->d_lock);
71249+
71250+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
71251+}
71252+
71253+#ifdef CONFIG_HUGETLBFS
71254+static inline bool
71255+is_hugetlbfs_mnt(const struct vfsmount *mnt)
71256+{
71257+ int i;
71258+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
71259+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
71260+ return true;
71261+ }
71262+
71263+ return false;
71264+}
71265+#endif
71266+
71267+static struct acl_object_label *
71268+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71269+ const struct acl_subject_label *subj, char *path, const int checkglob)
71270+{
71271+ struct dentry *dentry = (struct dentry *) l_dentry;
71272+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
71273+ struct mount *real_mnt = real_mount(mnt);
71274+ struct acl_object_label *retval;
71275+ struct dentry *parent;
71276+
71277+ read_seqlock_excl(&mount_lock);
71278+ write_seqlock(&rename_lock);
71279+
71280+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
71281+#ifdef CONFIG_NET
71282+ mnt == sock_mnt ||
71283+#endif
71284+#ifdef CONFIG_HUGETLBFS
71285+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
71286+#endif
71287+ /* ignore Eric Biederman */
71288+ IS_PRIVATE(l_dentry->d_inode))) {
71289+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
71290+ goto out;
71291+ }
71292+
71293+ for (;;) {
71294+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
71295+ break;
71296+
71297+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
71298+ if (!mnt_has_parent(real_mnt))
71299+ break;
71300+
71301+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
71302+ if (retval != NULL)
71303+ goto out;
71304+
71305+ dentry = real_mnt->mnt_mountpoint;
71306+ real_mnt = real_mnt->mnt_parent;
71307+ mnt = &real_mnt->mnt;
71308+ continue;
71309+ }
71310+
71311+ parent = dentry->d_parent;
71312+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
71313+ if (retval != NULL)
71314+ goto out;
71315+
71316+ dentry = parent;
71317+ }
71318+
71319+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
71320+
71321+ /* gr_real_root is pinned so we don't have to hold a reference */
71322+ if (retval == NULL)
71323+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
71324+out:
71325+ write_sequnlock(&rename_lock);
71326+ read_sequnlock_excl(&mount_lock);
71327+
71328+ BUG_ON(retval == NULL);
71329+
71330+ return retval;
71331+}
71332+
71333+static __inline__ struct acl_object_label *
71334+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71335+ const struct acl_subject_label *subj)
71336+{
71337+ char *path = NULL;
71338+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
71339+}
71340+
71341+static __inline__ struct acl_object_label *
71342+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71343+ const struct acl_subject_label *subj)
71344+{
71345+ char *path = NULL;
71346+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
71347+}
71348+
71349+static __inline__ struct acl_object_label *
71350+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71351+ const struct acl_subject_label *subj, char *path)
71352+{
71353+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
71354+}
71355+
71356+struct acl_subject_label *
71357+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71358+ const struct acl_role_label *role)
71359+{
71360+ struct dentry *dentry = (struct dentry *) l_dentry;
71361+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
71362+ struct mount *real_mnt = real_mount(mnt);
71363+ struct acl_subject_label *retval;
71364+ struct dentry *parent;
71365+
71366+ read_seqlock_excl(&mount_lock);
71367+ write_seqlock(&rename_lock);
71368+
71369+ for (;;) {
71370+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
71371+ break;
71372+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
71373+ if (!mnt_has_parent(real_mnt))
71374+ break;
71375+
71376+ spin_lock(&dentry->d_lock);
71377+ read_lock(&gr_inode_lock);
71378+ retval =
71379+ lookup_acl_subj_label(dentry->d_inode->i_ino,
71380+ __get_dev(dentry), role);
71381+ read_unlock(&gr_inode_lock);
71382+ spin_unlock(&dentry->d_lock);
71383+ if (retval != NULL)
71384+ goto out;
71385+
71386+ dentry = real_mnt->mnt_mountpoint;
71387+ real_mnt = real_mnt->mnt_parent;
71388+ mnt = &real_mnt->mnt;
71389+ continue;
71390+ }
71391+
71392+ spin_lock(&dentry->d_lock);
71393+ read_lock(&gr_inode_lock);
71394+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
71395+ __get_dev(dentry), role);
71396+ read_unlock(&gr_inode_lock);
71397+ parent = dentry->d_parent;
71398+ spin_unlock(&dentry->d_lock);
71399+
71400+ if (retval != NULL)
71401+ goto out;
71402+
71403+ dentry = parent;
71404+ }
71405+
71406+ spin_lock(&dentry->d_lock);
71407+ read_lock(&gr_inode_lock);
71408+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
71409+ __get_dev(dentry), role);
71410+ read_unlock(&gr_inode_lock);
71411+ spin_unlock(&dentry->d_lock);
71412+
71413+ if (unlikely(retval == NULL)) {
71414+ /* gr_real_root is pinned, we don't need to hold a reference */
71415+ read_lock(&gr_inode_lock);
71416+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
71417+ __get_dev(gr_real_root.dentry), role);
71418+ read_unlock(&gr_inode_lock);
71419+ }
71420+out:
71421+ write_sequnlock(&rename_lock);
71422+ read_sequnlock_excl(&mount_lock);
71423+
71424+ BUG_ON(retval == NULL);
71425+
71426+ return retval;
71427+}
71428+
71429+void
71430+assign_special_role(const char *rolename)
71431+{
71432+ struct acl_object_label *obj;
71433+ struct acl_role_label *r;
71434+ struct acl_role_label *assigned = NULL;
71435+ struct task_struct *tsk;
71436+ struct file *filp;
71437+
71438+ FOR_EACH_ROLE_START(r)
71439+ if (!strcmp(rolename, r->rolename) &&
71440+ (r->roletype & GR_ROLE_SPECIAL)) {
71441+ assigned = r;
71442+ break;
71443+ }
71444+ FOR_EACH_ROLE_END(r)
71445+
71446+ if (!assigned)
71447+ return;
71448+
71449+ read_lock(&tasklist_lock);
71450+ read_lock(&grsec_exec_file_lock);
71451+
71452+ tsk = current->real_parent;
71453+ if (tsk == NULL)
71454+ goto out_unlock;
71455+
71456+ filp = tsk->exec_file;
71457+ if (filp == NULL)
71458+ goto out_unlock;
71459+
71460+ tsk->is_writable = 0;
71461+ tsk->inherited = 0;
71462+
71463+ tsk->acl_sp_role = 1;
71464+ tsk->acl_role_id = ++acl_sp_role_value;
71465+ tsk->role = assigned;
71466+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
71467+
71468+ /* ignore additional mmap checks for processes that are writable
71469+ by the default ACL */
71470+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71471+ if (unlikely(obj->mode & GR_WRITE))
71472+ tsk->is_writable = 1;
71473+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
71474+ if (unlikely(obj->mode & GR_WRITE))
71475+ tsk->is_writable = 1;
71476+
71477+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71478+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
71479+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
71480+#endif
71481+
71482+out_unlock:
71483+ read_unlock(&grsec_exec_file_lock);
71484+ read_unlock(&tasklist_lock);
71485+ return;
71486+}
71487+
71488+
71489+static void
71490+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
71491+{
71492+ struct task_struct *task = current;
71493+ const struct cred *cred = current_cred();
71494+
71495+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
71496+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71497+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71498+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
71499+
71500+ return;
71501+}
71502+
71503+static void
71504+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
71505+{
71506+ struct task_struct *task = current;
71507+ const struct cred *cred = current_cred();
71508+
71509+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
71510+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71511+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71512+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
71513+
71514+ return;
71515+}
71516+
71517+static void
71518+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
71519+{
71520+ struct task_struct *task = current;
71521+ const struct cred *cred = current_cred();
71522+
71523+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
71524+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71525+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71526+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
71527+
71528+ return;
71529+}
71530+
71531+static void
71532+gr_set_proc_res(struct task_struct *task)
71533+{
71534+ struct acl_subject_label *proc;
71535+ unsigned short i;
71536+
71537+ proc = task->acl;
71538+
71539+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
71540+ return;
71541+
71542+ for (i = 0; i < RLIM_NLIMITS; i++) {
71543+ if (!(proc->resmask & (1U << i)))
71544+ continue;
71545+
71546+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
71547+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
71548+
71549+ if (i == RLIMIT_CPU)
71550+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
71551+ }
71552+
71553+ return;
71554+}
71555+
71556+/* both of the below must be called with
71557+ rcu_read_lock();
71558+ read_lock(&tasklist_lock);
71559+ read_lock(&grsec_exec_file_lock);
71560+*/
71561+
71562+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
71563+{
71564+ char *tmpname;
71565+ struct acl_subject_label *tmpsubj;
71566+ struct file *filp;
71567+ struct name_entry *nmatch;
71568+
71569+ filp = task->exec_file;
71570+ if (filp == NULL)
71571+ return NULL;
71572+
71573+ /* the following is to apply the correct subject
71574+ on binaries running when the RBAC system
71575+ is enabled, when the binaries have been
71576+ replaced or deleted since their execution
71577+ -----
71578+ when the RBAC system starts, the inode/dev
71579+ from exec_file will be one the RBAC system
71580+ is unaware of. It only knows the inode/dev
71581+ of the present file on disk, or the absence
71582+ of it.
71583+ */
71584+
71585+ if (filename)
71586+ nmatch = __lookup_name_entry(state, filename);
71587+ else {
71588+ preempt_disable();
71589+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
71590+
71591+ nmatch = __lookup_name_entry(state, tmpname);
71592+ preempt_enable();
71593+ }
71594+ tmpsubj = NULL;
71595+ if (nmatch) {
71596+ if (nmatch->deleted)
71597+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
71598+ else
71599+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
71600+ }
71601+ /* this also works for the reload case -- if we don't match a potentially inherited subject
71602+ then we fall back to a normal lookup based on the binary's ino/dev
71603+ */
71604+ if (tmpsubj == NULL)
71605+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
71606+
71607+ return tmpsubj;
71608+}
71609+
71610+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
71611+{
71612+ return __gr_get_subject_for_task(&running_polstate, task, filename);
71613+}
71614+
71615+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
71616+{
71617+ struct acl_object_label *obj;
71618+ struct file *filp;
71619+
71620+ filp = task->exec_file;
71621+
71622+ task->acl = subj;
71623+ task->is_writable = 0;
71624+ /* ignore additional mmap checks for processes that are writable
71625+ by the default ACL */
71626+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
71627+ if (unlikely(obj->mode & GR_WRITE))
71628+ task->is_writable = 1;
71629+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71630+ if (unlikely(obj->mode & GR_WRITE))
71631+ task->is_writable = 1;
71632+
71633+ gr_set_proc_res(task);
71634+
71635+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71636+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
71637+#endif
71638+}
71639+
71640+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
71641+{
71642+ __gr_apply_subject_to_task(&running_polstate, task, subj);
71643+}
71644+
71645+__u32
71646+gr_search_file(const struct dentry * dentry, const __u32 mode,
71647+ const struct vfsmount * mnt)
71648+{
71649+ __u32 retval = mode;
71650+ struct acl_subject_label *curracl;
71651+ struct acl_object_label *currobj;
71652+
71653+ if (unlikely(!(gr_status & GR_READY)))
71654+ return (mode & ~GR_AUDITS);
71655+
71656+ curracl = current->acl;
71657+
71658+ currobj = chk_obj_label(dentry, mnt, curracl);
71659+ retval = currobj->mode & mode;
71660+
71661+ /* if we're opening a specified transfer file for writing
71662+ (e.g. /dev/initctl), then transfer our role to init
71663+ */
71664+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
71665+ current->role->roletype & GR_ROLE_PERSIST)) {
71666+ struct task_struct *task = init_pid_ns.child_reaper;
71667+
71668+ if (task->role != current->role) {
71669+ struct acl_subject_label *subj;
71670+
71671+ task->acl_sp_role = 0;
71672+ task->acl_role_id = current->acl_role_id;
71673+ task->role = current->role;
71674+ rcu_read_lock();
71675+ read_lock(&grsec_exec_file_lock);
71676+ subj = gr_get_subject_for_task(task, NULL);
71677+ gr_apply_subject_to_task(task, subj);
71678+ read_unlock(&grsec_exec_file_lock);
71679+ rcu_read_unlock();
71680+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
71681+ }
71682+ }
71683+
71684+ if (unlikely
71685+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
71686+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
71687+ __u32 new_mode = mode;
71688+
71689+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71690+
71691+ retval = new_mode;
71692+
71693+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
71694+ new_mode |= GR_INHERIT;
71695+
71696+ if (!(mode & GR_NOLEARN))
71697+ gr_log_learn(dentry, mnt, new_mode);
71698+ }
71699+
71700+ return retval;
71701+}
71702+
71703+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
71704+ const struct dentry *parent,
71705+ const struct vfsmount *mnt)
71706+{
71707+ struct name_entry *match;
71708+ struct acl_object_label *matchpo;
71709+ struct acl_subject_label *curracl;
71710+ char *path;
71711+
71712+ if (unlikely(!(gr_status & GR_READY)))
71713+ return NULL;
71714+
71715+ preempt_disable();
71716+ path = gr_to_filename_rbac(new_dentry, mnt);
71717+ match = lookup_name_entry_create(path);
71718+
71719+ curracl = current->acl;
71720+
71721+ if (match) {
71722+ read_lock(&gr_inode_lock);
71723+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
71724+ read_unlock(&gr_inode_lock);
71725+
71726+ if (matchpo) {
71727+ preempt_enable();
71728+ return matchpo;
71729+ }
71730+ }
71731+
71732+ // lookup parent
71733+
71734+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
71735+
71736+ preempt_enable();
71737+ return matchpo;
71738+}
71739+
71740+__u32
71741+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
71742+ const struct vfsmount * mnt, const __u32 mode)
71743+{
71744+ struct acl_object_label *matchpo;
71745+ __u32 retval;
71746+
71747+ if (unlikely(!(gr_status & GR_READY)))
71748+ return (mode & ~GR_AUDITS);
71749+
71750+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
71751+
71752+ retval = matchpo->mode & mode;
71753+
71754+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
71755+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71756+ __u32 new_mode = mode;
71757+
71758+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71759+
71760+ gr_log_learn(new_dentry, mnt, new_mode);
71761+ return new_mode;
71762+ }
71763+
71764+ return retval;
71765+}
71766+
71767+__u32
71768+gr_check_link(const struct dentry * new_dentry,
71769+ const struct dentry * parent_dentry,
71770+ const struct vfsmount * parent_mnt,
71771+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
71772+{
71773+ struct acl_object_label *obj;
71774+ __u32 oldmode, newmode;
71775+ __u32 needmode;
71776+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
71777+ GR_DELETE | GR_INHERIT;
71778+
71779+ if (unlikely(!(gr_status & GR_READY)))
71780+ return (GR_CREATE | GR_LINK);
71781+
71782+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
71783+ oldmode = obj->mode;
71784+
71785+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
71786+ newmode = obj->mode;
71787+
71788+ needmode = newmode & checkmodes;
71789+
71790+ // old name for hardlink must have at least the permissions of the new name
71791+ if ((oldmode & needmode) != needmode)
71792+ goto bad;
71793+
71794+ // if old name had restrictions/auditing, make sure the new name does as well
71795+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
71796+
71797+ // don't allow hardlinking of suid/sgid/fcapped files without permission
71798+ if (is_privileged_binary(old_dentry))
71799+ needmode |= GR_SETID;
71800+
71801+ if ((newmode & needmode) != needmode)
71802+ goto bad;
71803+
71804+ // enforce minimum permissions
71805+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
71806+ return newmode;
71807+bad:
71808+ needmode = oldmode;
71809+ if (is_privileged_binary(old_dentry))
71810+ needmode |= GR_SETID;
71811+
71812+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
71813+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
71814+ return (GR_CREATE | GR_LINK);
71815+ } else if (newmode & GR_SUPPRESS)
71816+ return GR_SUPPRESS;
71817+ else
71818+ return 0;
71819+}
71820+
71821+int
71822+gr_check_hidden_task(const struct task_struct *task)
71823+{
71824+ if (unlikely(!(gr_status & GR_READY)))
71825+ return 0;
71826+
71827+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
71828+ return 1;
71829+
71830+ return 0;
71831+}
71832+
71833+int
71834+gr_check_protected_task(const struct task_struct *task)
71835+{
71836+ if (unlikely(!(gr_status & GR_READY) || !task))
71837+ return 0;
71838+
71839+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71840+ task->acl != current->acl)
71841+ return 1;
71842+
71843+ return 0;
71844+}
71845+
71846+int
71847+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
71848+{
71849+ struct task_struct *p;
71850+ int ret = 0;
71851+
71852+ if (unlikely(!(gr_status & GR_READY) || !pid))
71853+ return ret;
71854+
71855+ read_lock(&tasklist_lock);
71856+ do_each_pid_task(pid, type, p) {
71857+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71858+ p->acl != current->acl) {
71859+ ret = 1;
71860+ goto out;
71861+ }
71862+ } while_each_pid_task(pid, type, p);
71863+out:
71864+ read_unlock(&tasklist_lock);
71865+
71866+ return ret;
71867+}
71868+
71869+void
71870+gr_copy_label(struct task_struct *tsk)
71871+{
71872+ struct task_struct *p = current;
71873+
71874+ tsk->inherited = p->inherited;
71875+ tsk->acl_sp_role = 0;
71876+ tsk->acl_role_id = p->acl_role_id;
71877+ tsk->acl = p->acl;
71878+ tsk->role = p->role;
71879+ tsk->signal->used_accept = 0;
71880+ tsk->signal->curr_ip = p->signal->curr_ip;
71881+ tsk->signal->saved_ip = p->signal->saved_ip;
71882+ if (p->exec_file)
71883+ get_file(p->exec_file);
71884+ tsk->exec_file = p->exec_file;
71885+ tsk->is_writable = p->is_writable;
71886+ if (unlikely(p->signal->used_accept)) {
71887+ p->signal->curr_ip = 0;
71888+ p->signal->saved_ip = 0;
71889+ }
71890+
71891+ return;
71892+}
71893+
71894+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71895+
71896+int
71897+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71898+{
71899+ unsigned int i;
71900+ __u16 num;
71901+ uid_t *uidlist;
71902+ uid_t curuid;
71903+ int realok = 0;
71904+ int effectiveok = 0;
71905+ int fsok = 0;
71906+ uid_t globalreal, globaleffective, globalfs;
71907+
71908+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71909+ struct user_struct *user;
71910+
71911+ if (!uid_valid(real))
71912+ goto skipit;
71913+
71914+ /* find user based on global namespace */
71915+
71916+ globalreal = GR_GLOBAL_UID(real);
71917+
71918+ user = find_user(make_kuid(&init_user_ns, globalreal));
71919+ if (user == NULL)
71920+ goto skipit;
71921+
71922+ if (gr_process_kernel_setuid_ban(user)) {
71923+ /* for find_user */
71924+ free_uid(user);
71925+ return 1;
71926+ }
71927+
71928+ /* for find_user */
71929+ free_uid(user);
71930+
71931+skipit:
71932+#endif
71933+
71934+ if (unlikely(!(gr_status & GR_READY)))
71935+ return 0;
71936+
71937+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71938+ gr_log_learn_uid_change(real, effective, fs);
71939+
71940+ num = current->acl->user_trans_num;
71941+ uidlist = current->acl->user_transitions;
71942+
71943+ if (uidlist == NULL)
71944+ return 0;
71945+
71946+ if (!uid_valid(real)) {
71947+ realok = 1;
71948+ globalreal = (uid_t)-1;
71949+ } else {
71950+ globalreal = GR_GLOBAL_UID(real);
71951+ }
71952+ if (!uid_valid(effective)) {
71953+ effectiveok = 1;
71954+ globaleffective = (uid_t)-1;
71955+ } else {
71956+ globaleffective = GR_GLOBAL_UID(effective);
71957+ }
71958+ if (!uid_valid(fs)) {
71959+ fsok = 1;
71960+ globalfs = (uid_t)-1;
71961+ } else {
71962+ globalfs = GR_GLOBAL_UID(fs);
71963+ }
71964+
71965+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
71966+ for (i = 0; i < num; i++) {
71967+ curuid = uidlist[i];
71968+ if (globalreal == curuid)
71969+ realok = 1;
71970+ if (globaleffective == curuid)
71971+ effectiveok = 1;
71972+ if (globalfs == curuid)
71973+ fsok = 1;
71974+ }
71975+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
71976+ for (i = 0; i < num; i++) {
71977+ curuid = uidlist[i];
71978+ if (globalreal == curuid)
71979+ break;
71980+ if (globaleffective == curuid)
71981+ break;
71982+ if (globalfs == curuid)
71983+ break;
71984+ }
71985+ /* not in deny list */
71986+ if (i == num) {
71987+ realok = 1;
71988+ effectiveok = 1;
71989+ fsok = 1;
71990+ }
71991+ }
71992+
71993+ if (realok && effectiveok && fsok)
71994+ return 0;
71995+ else {
71996+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71997+ return 1;
71998+ }
71999+}
72000+
72001+int
72002+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
72003+{
72004+ unsigned int i;
72005+ __u16 num;
72006+ gid_t *gidlist;
72007+ gid_t curgid;
72008+ int realok = 0;
72009+ int effectiveok = 0;
72010+ int fsok = 0;
72011+ gid_t globalreal, globaleffective, globalfs;
72012+
72013+ if (unlikely(!(gr_status & GR_READY)))
72014+ return 0;
72015+
72016+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72017+ gr_log_learn_gid_change(real, effective, fs);
72018+
72019+ num = current->acl->group_trans_num;
72020+ gidlist = current->acl->group_transitions;
72021+
72022+ if (gidlist == NULL)
72023+ return 0;
72024+
72025+ if (!gid_valid(real)) {
72026+ realok = 1;
72027+ globalreal = (gid_t)-1;
72028+ } else {
72029+ globalreal = GR_GLOBAL_GID(real);
72030+ }
72031+ if (!gid_valid(effective)) {
72032+ effectiveok = 1;
72033+ globaleffective = (gid_t)-1;
72034+ } else {
72035+ globaleffective = GR_GLOBAL_GID(effective);
72036+ }
72037+ if (!gid_valid(fs)) {
72038+ fsok = 1;
72039+ globalfs = (gid_t)-1;
72040+ } else {
72041+ globalfs = GR_GLOBAL_GID(fs);
72042+ }
72043+
72044+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
72045+ for (i = 0; i < num; i++) {
72046+ curgid = gidlist[i];
72047+ if (globalreal == curgid)
72048+ realok = 1;
72049+ if (globaleffective == curgid)
72050+ effectiveok = 1;
72051+ if (globalfs == curgid)
72052+ fsok = 1;
72053+ }
72054+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
72055+ for (i = 0; i < num; i++) {
72056+ curgid = gidlist[i];
72057+ if (globalreal == curgid)
72058+ break;
72059+ if (globaleffective == curgid)
72060+ break;
72061+ if (globalfs == curgid)
72062+ break;
72063+ }
72064+ /* not in deny list */
72065+ if (i == num) {
72066+ realok = 1;
72067+ effectiveok = 1;
72068+ fsok = 1;
72069+ }
72070+ }
72071+
72072+ if (realok && effectiveok && fsok)
72073+ return 0;
72074+ else {
72075+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
72076+ return 1;
72077+ }
72078+}
72079+
72080+extern int gr_acl_is_capable(const int cap);
72081+
72082+void
72083+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
72084+{
72085+ struct acl_role_label *role = task->role;
72086+ struct acl_subject_label *subj = NULL;
72087+ struct acl_object_label *obj;
72088+ struct file *filp;
72089+ uid_t uid;
72090+ gid_t gid;
72091+
72092+ if (unlikely(!(gr_status & GR_READY)))
72093+ return;
72094+
72095+ uid = GR_GLOBAL_UID(kuid);
72096+ gid = GR_GLOBAL_GID(kgid);
72097+
72098+ filp = task->exec_file;
72099+
72100+ /* kernel process, we'll give them the kernel role */
72101+ if (unlikely(!filp)) {
72102+ task->role = running_polstate.kernel_role;
72103+ task->acl = running_polstate.kernel_role->root_label;
72104+ return;
72105+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
72106+ /* save the current ip at time of role lookup so that the proper
72107+ IP will be learned for role_allowed_ip */
72108+ task->signal->saved_ip = task->signal->curr_ip;
72109+ role = lookup_acl_role_label(task, uid, gid);
72110+ }
72111+
72112+ /* don't change the role if we're not a privileged process */
72113+ if (role && task->role != role &&
72114+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
72115+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
72116+ return;
72117+
72118+ /* perform subject lookup in possibly new role
72119+ we can use this result below in the case where role == task->role
72120+ */
72121+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
72122+
72123+ /* if we changed uid/gid, but result in the same role
72124+ and are using inheritance, don't lose the inherited subject
72125+ if current subject is other than what normal lookup
72126+ would result in, we arrived via inheritance, don't
72127+ lose subject
72128+ */
72129+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
72130+ (subj == task->acl)))
72131+ task->acl = subj;
72132+
72133+ /* leave task->inherited unaffected */
72134+
72135+ task->role = role;
72136+
72137+ task->is_writable = 0;
72138+
72139+ /* ignore additional mmap checks for processes that are writable
72140+ by the default ACL */
72141+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72142+ if (unlikely(obj->mode & GR_WRITE))
72143+ task->is_writable = 1;
72144+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
72145+ if (unlikely(obj->mode & GR_WRITE))
72146+ task->is_writable = 1;
72147+
72148+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72149+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
72150+#endif
72151+
72152+ gr_set_proc_res(task);
72153+
72154+ return;
72155+}
72156+
72157+int
72158+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
72159+ const int unsafe_flags)
72160+{
72161+ struct task_struct *task = current;
72162+ struct acl_subject_label *newacl;
72163+ struct acl_object_label *obj;
72164+ __u32 retmode;
72165+
72166+ if (unlikely(!(gr_status & GR_READY)))
72167+ return 0;
72168+
72169+ newacl = chk_subj_label(dentry, mnt, task->role);
72170+
72171+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
72172+ did an exec
72173+ */
72174+ rcu_read_lock();
72175+ read_lock(&tasklist_lock);
72176+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
72177+ (task->parent->acl->mode & GR_POVERRIDE))) {
72178+ read_unlock(&tasklist_lock);
72179+ rcu_read_unlock();
72180+ goto skip_check;
72181+ }
72182+ read_unlock(&tasklist_lock);
72183+ rcu_read_unlock();
72184+
72185+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
72186+ !(task->role->roletype & GR_ROLE_GOD) &&
72187+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
72188+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
72189+ if (unsafe_flags & LSM_UNSAFE_SHARE)
72190+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
72191+ else
72192+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
72193+ return -EACCES;
72194+ }
72195+
72196+skip_check:
72197+
72198+ obj = chk_obj_label(dentry, mnt, task->acl);
72199+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
72200+
72201+ if (!(task->acl->mode & GR_INHERITLEARN) &&
72202+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
72203+ if (obj->nested)
72204+ task->acl = obj->nested;
72205+ else
72206+ task->acl = newacl;
72207+ task->inherited = 0;
72208+ } else {
72209+ task->inherited = 1;
72210+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
72211+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
72212+ }
72213+
72214+ task->is_writable = 0;
72215+
72216+ /* ignore additional mmap checks for processes that are writable
72217+ by the default ACL */
72218+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
72219+ if (unlikely(obj->mode & GR_WRITE))
72220+ task->is_writable = 1;
72221+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
72222+ if (unlikely(obj->mode & GR_WRITE))
72223+ task->is_writable = 1;
72224+
72225+ gr_set_proc_res(task);
72226+
72227+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72228+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
72229+#endif
72230+ return 0;
72231+}
72232+
72233+/* always called with valid inodev ptr */
72234+static void
72235+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
72236+{
72237+ struct acl_object_label *matchpo;
72238+ struct acl_subject_label *matchps;
72239+ struct acl_subject_label *subj;
72240+ struct acl_role_label *role;
72241+ unsigned int x;
72242+
72243+ FOR_EACH_ROLE_START(role)
72244+ FOR_EACH_SUBJECT_START(role, subj, x)
72245+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
72246+ matchpo->mode |= GR_DELETED;
72247+ FOR_EACH_SUBJECT_END(subj,x)
72248+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
72249+ /* nested subjects aren't in the role's subj_hash table */
72250+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
72251+ matchpo->mode |= GR_DELETED;
72252+ FOR_EACH_NESTED_SUBJECT_END(subj)
72253+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
72254+ matchps->mode |= GR_DELETED;
72255+ FOR_EACH_ROLE_END(role)
72256+
72257+ inodev->nentry->deleted = 1;
72258+
72259+ return;
72260+}
72261+
72262+void
72263+gr_handle_delete(const ino_t ino, const dev_t dev)
72264+{
72265+ struct inodev_entry *inodev;
72266+
72267+ if (unlikely(!(gr_status & GR_READY)))
72268+ return;
72269+
72270+ write_lock(&gr_inode_lock);
72271+ inodev = lookup_inodev_entry(ino, dev);
72272+ if (inodev != NULL)
72273+ do_handle_delete(inodev, ino, dev);
72274+ write_unlock(&gr_inode_lock);
72275+
72276+ return;
72277+}
72278+
72279+static void
72280+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
72281+ const ino_t newinode, const dev_t newdevice,
72282+ struct acl_subject_label *subj)
72283+{
72284+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
72285+ struct acl_object_label *match;
72286+
72287+ match = subj->obj_hash[index];
72288+
72289+ while (match && (match->inode != oldinode ||
72290+ match->device != olddevice ||
72291+ !(match->mode & GR_DELETED)))
72292+ match = match->next;
72293+
72294+ if (match && (match->inode == oldinode)
72295+ && (match->device == olddevice)
72296+ && (match->mode & GR_DELETED)) {
72297+ if (match->prev == NULL) {
72298+ subj->obj_hash[index] = match->next;
72299+ if (match->next != NULL)
72300+ match->next->prev = NULL;
72301+ } else {
72302+ match->prev->next = match->next;
72303+ if (match->next != NULL)
72304+ match->next->prev = match->prev;
72305+ }
72306+ match->prev = NULL;
72307+ match->next = NULL;
72308+ match->inode = newinode;
72309+ match->device = newdevice;
72310+ match->mode &= ~GR_DELETED;
72311+
72312+ insert_acl_obj_label(match, subj);
72313+ }
72314+
72315+ return;
72316+}
72317+
72318+static void
72319+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
72320+ const ino_t newinode, const dev_t newdevice,
72321+ struct acl_role_label *role)
72322+{
72323+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
72324+ struct acl_subject_label *match;
72325+
72326+ match = role->subj_hash[index];
72327+
72328+ while (match && (match->inode != oldinode ||
72329+ match->device != olddevice ||
72330+ !(match->mode & GR_DELETED)))
72331+ match = match->next;
72332+
72333+ if (match && (match->inode == oldinode)
72334+ && (match->device == olddevice)
72335+ && (match->mode & GR_DELETED)) {
72336+ if (match->prev == NULL) {
72337+ role->subj_hash[index] = match->next;
72338+ if (match->next != NULL)
72339+ match->next->prev = NULL;
72340+ } else {
72341+ match->prev->next = match->next;
72342+ if (match->next != NULL)
72343+ match->next->prev = match->prev;
72344+ }
72345+ match->prev = NULL;
72346+ match->next = NULL;
72347+ match->inode = newinode;
72348+ match->device = newdevice;
72349+ match->mode &= ~GR_DELETED;
72350+
72351+ insert_acl_subj_label(match, role);
72352+ }
72353+
72354+ return;
72355+}
72356+
72357+static void
72358+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
72359+ const ino_t newinode, const dev_t newdevice)
72360+{
72361+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
72362+ struct inodev_entry *match;
72363+
72364+ match = running_polstate.inodev_set.i_hash[index];
72365+
72366+ while (match && (match->nentry->inode != oldinode ||
72367+ match->nentry->device != olddevice || !match->nentry->deleted))
72368+ match = match->next;
72369+
72370+ if (match && (match->nentry->inode == oldinode)
72371+ && (match->nentry->device == olddevice) &&
72372+ match->nentry->deleted) {
72373+ if (match->prev == NULL) {
72374+ running_polstate.inodev_set.i_hash[index] = match->next;
72375+ if (match->next != NULL)
72376+ match->next->prev = NULL;
72377+ } else {
72378+ match->prev->next = match->next;
72379+ if (match->next != NULL)
72380+ match->next->prev = match->prev;
72381+ }
72382+ match->prev = NULL;
72383+ match->next = NULL;
72384+ match->nentry->inode = newinode;
72385+ match->nentry->device = newdevice;
72386+ match->nentry->deleted = 0;
72387+
72388+ insert_inodev_entry(match);
72389+ }
72390+
72391+ return;
72392+}
72393+
72394+static void
72395+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
72396+{
72397+ struct acl_subject_label *subj;
72398+ struct acl_role_label *role;
72399+ unsigned int x;
72400+
72401+ FOR_EACH_ROLE_START(role)
72402+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
72403+
72404+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
72405+ if ((subj->inode == ino) && (subj->device == dev)) {
72406+ subj->inode = ino;
72407+ subj->device = dev;
72408+ }
72409+ /* nested subjects aren't in the role's subj_hash table */
72410+ update_acl_obj_label(matchn->inode, matchn->device,
72411+ ino, dev, subj);
72412+ FOR_EACH_NESTED_SUBJECT_END(subj)
72413+ FOR_EACH_SUBJECT_START(role, subj, x)
72414+ update_acl_obj_label(matchn->inode, matchn->device,
72415+ ino, dev, subj);
72416+ FOR_EACH_SUBJECT_END(subj,x)
72417+ FOR_EACH_ROLE_END(role)
72418+
72419+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
72420+
72421+ return;
72422+}
72423+
72424+static void
72425+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
72426+ const struct vfsmount *mnt)
72427+{
72428+ ino_t ino = dentry->d_inode->i_ino;
72429+ dev_t dev = __get_dev(dentry);
72430+
72431+ __do_handle_create(matchn, ino, dev);
72432+
72433+ return;
72434+}
72435+
72436+void
72437+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
72438+{
72439+ struct name_entry *matchn;
72440+
72441+ if (unlikely(!(gr_status & GR_READY)))
72442+ return;
72443+
72444+ preempt_disable();
72445+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
72446+
72447+ if (unlikely((unsigned long)matchn)) {
72448+ write_lock(&gr_inode_lock);
72449+ do_handle_create(matchn, dentry, mnt);
72450+ write_unlock(&gr_inode_lock);
72451+ }
72452+ preempt_enable();
72453+
72454+ return;
72455+}
72456+
72457+void
72458+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
72459+{
72460+ struct name_entry *matchn;
72461+
72462+ if (unlikely(!(gr_status & GR_READY)))
72463+ return;
72464+
72465+ preempt_disable();
72466+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
72467+
72468+ if (unlikely((unsigned long)matchn)) {
72469+ write_lock(&gr_inode_lock);
72470+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
72471+ write_unlock(&gr_inode_lock);
72472+ }
72473+ preempt_enable();
72474+
72475+ return;
72476+}
72477+
72478+void
72479+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
72480+ struct dentry *old_dentry,
72481+ struct dentry *new_dentry,
72482+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
72483+{
72484+ struct name_entry *matchn;
72485+ struct name_entry *matchn2 = NULL;
72486+ struct inodev_entry *inodev;
72487+ struct inode *inode = new_dentry->d_inode;
72488+ ino_t old_ino = old_dentry->d_inode->i_ino;
72489+ dev_t old_dev = __get_dev(old_dentry);
72490+ unsigned int exchange = flags & RENAME_EXCHANGE;
72491+
72492+ /* vfs_rename swaps the name and parent link for old_dentry and
72493+ new_dentry
72494+ at this point, old_dentry has the new name, parent link, and inode
72495+ for the renamed file
72496+ if a file is being replaced by a rename, new_dentry has the inode
72497+ and name for the replaced file
72498+ */
72499+
72500+ if (unlikely(!(gr_status & GR_READY)))
72501+ return;
72502+
72503+ preempt_disable();
72504+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
72505+
72506+ /* exchange cases:
72507+ a filename exists for the source, but not dest
72508+ do a recreate on source
72509+ a filename exists for the dest, but not source
72510+ do a recreate on dest
72511+ a filename exists for both source and dest
72512+ delete source and dest, then create source and dest
72513+ a filename exists for neither source nor dest
72514+ no updates needed
72515+
72516+ the name entry lookups get us the old inode/dev associated with
72517+ each name, so do the deletes first (if possible) so that when
72518+ we do the create, we pick up on the right entries
72519+ */
72520+
72521+ if (exchange)
72522+ matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
72523+
72524+ /* we wouldn't have to check d_inode if it weren't for
72525+ NFS silly-renaming
72526+ */
72527+
72528+ write_lock(&gr_inode_lock);
72529+ if (unlikely((replace || exchange) && inode)) {
72530+ ino_t new_ino = inode->i_ino;
72531+ dev_t new_dev = __get_dev(new_dentry);
72532+
72533+ inodev = lookup_inodev_entry(new_ino, new_dev);
72534+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
72535+ do_handle_delete(inodev, new_ino, new_dev);
72536+ }
72537+
72538+ inodev = lookup_inodev_entry(old_ino, old_dev);
72539+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
72540+ do_handle_delete(inodev, old_ino, old_dev);
72541+
72542+ if (unlikely(matchn != NULL))
72543+ do_handle_create(matchn, old_dentry, mnt);
72544+
72545+ if (unlikely(matchn2 != NULL))
72546+ do_handle_create(matchn2, new_dentry, mnt);
72547+
72548+ write_unlock(&gr_inode_lock);
72549+ preempt_enable();
72550+
72551+ return;
72552+}
72553+
72554+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
72555+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
72556+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
72557+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
72558+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
72559+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
72560+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
72561+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
72562+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
72563+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
72564+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
72565+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
72566+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
72567+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
72568+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
72569+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
72570+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
72571+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
72572+};
72573+
72574+void
72575+gr_learn_resource(const struct task_struct *task,
72576+ const int res, const unsigned long wanted, const int gt)
72577+{
72578+ struct acl_subject_label *acl;
72579+ const struct cred *cred;
72580+
72581+ if (unlikely((gr_status & GR_READY) &&
72582+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
72583+ goto skip_reslog;
72584+
72585+ gr_log_resource(task, res, wanted, gt);
72586+skip_reslog:
72587+
72588+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
72589+ return;
72590+
72591+ acl = task->acl;
72592+
72593+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
72594+ !(acl->resmask & (1U << (unsigned short) res))))
72595+ return;
72596+
72597+ if (wanted >= acl->res[res].rlim_cur) {
72598+ unsigned long res_add;
72599+
72600+ res_add = wanted + res_learn_bumps[res];
72601+
72602+ acl->res[res].rlim_cur = res_add;
72603+
72604+ if (wanted > acl->res[res].rlim_max)
72605+ acl->res[res].rlim_max = res_add;
72606+
72607+ /* only log the subject filename, since resource logging is supported for
72608+ single-subject learning only */
72609+ rcu_read_lock();
72610+ cred = __task_cred(task);
72611+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72612+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
72613+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
72614+ "", (unsigned long) res, &task->signal->saved_ip);
72615+ rcu_read_unlock();
72616+ }
72617+
72618+ return;
72619+}
72620+EXPORT_SYMBOL_GPL(gr_learn_resource);
72621+#endif
72622+
72623+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
72624+void
72625+pax_set_initial_flags(struct linux_binprm *bprm)
72626+{
72627+ struct task_struct *task = current;
72628+ struct acl_subject_label *proc;
72629+ unsigned long flags;
72630+
72631+ if (unlikely(!(gr_status & GR_READY)))
72632+ return;
72633+
72634+ flags = pax_get_flags(task);
72635+
72636+ proc = task->acl;
72637+
72638+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
72639+ flags &= ~MF_PAX_PAGEEXEC;
72640+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
72641+ flags &= ~MF_PAX_SEGMEXEC;
72642+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
72643+ flags &= ~MF_PAX_RANDMMAP;
72644+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
72645+ flags &= ~MF_PAX_EMUTRAMP;
72646+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
72647+ flags &= ~MF_PAX_MPROTECT;
72648+
72649+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
72650+ flags |= MF_PAX_PAGEEXEC;
72651+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
72652+ flags |= MF_PAX_SEGMEXEC;
72653+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
72654+ flags |= MF_PAX_RANDMMAP;
72655+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
72656+ flags |= MF_PAX_EMUTRAMP;
72657+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
72658+ flags |= MF_PAX_MPROTECT;
72659+
72660+ pax_set_flags(task, flags);
72661+
72662+ return;
72663+}
72664+#endif
72665+
72666+int
72667+gr_handle_proc_ptrace(struct task_struct *task)
72668+{
72669+ struct file *filp;
72670+ struct task_struct *tmp = task;
72671+ struct task_struct *curtemp = current;
72672+ __u32 retmode;
72673+
72674+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72675+ if (unlikely(!(gr_status & GR_READY)))
72676+ return 0;
72677+#endif
72678+
72679+ read_lock(&tasklist_lock);
72680+ read_lock(&grsec_exec_file_lock);
72681+ filp = task->exec_file;
72682+
72683+ while (task_pid_nr(tmp) > 0) {
72684+ if (tmp == curtemp)
72685+ break;
72686+ tmp = tmp->real_parent;
72687+ }
72688+
72689+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72690+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
72691+ read_unlock(&grsec_exec_file_lock);
72692+ read_unlock(&tasklist_lock);
72693+ return 1;
72694+ }
72695+
72696+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72697+ if (!(gr_status & GR_READY)) {
72698+ read_unlock(&grsec_exec_file_lock);
72699+ read_unlock(&tasklist_lock);
72700+ return 0;
72701+ }
72702+#endif
72703+
72704+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
72705+ read_unlock(&grsec_exec_file_lock);
72706+ read_unlock(&tasklist_lock);
72707+
72708+ if (retmode & GR_NOPTRACE)
72709+ return 1;
72710+
72711+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
72712+ && (current->acl != task->acl || (current->acl != current->role->root_label
72713+ && task_pid_nr(current) != task_pid_nr(task))))
72714+ return 1;
72715+
72716+ return 0;
72717+}
72718+
72719+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
72720+{
72721+ if (unlikely(!(gr_status & GR_READY)))
72722+ return;
72723+
72724+ if (!(current->role->roletype & GR_ROLE_GOD))
72725+ return;
72726+
72727+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
72728+ p->role->rolename, gr_task_roletype_to_char(p),
72729+ p->acl->filename);
72730+}
72731+
72732+int
72733+gr_handle_ptrace(struct task_struct *task, const long request)
72734+{
72735+ struct task_struct *tmp = task;
72736+ struct task_struct *curtemp = current;
72737+ __u32 retmode;
72738+
72739+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72740+ if (unlikely(!(gr_status & GR_READY)))
72741+ return 0;
72742+#endif
72743+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72744+ read_lock(&tasklist_lock);
72745+ while (task_pid_nr(tmp) > 0) {
72746+ if (tmp == curtemp)
72747+ break;
72748+ tmp = tmp->real_parent;
72749+ }
72750+
72751+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72752+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
72753+ read_unlock(&tasklist_lock);
72754+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72755+ return 1;
72756+ }
72757+ read_unlock(&tasklist_lock);
72758+ }
72759+
72760+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72761+ if (!(gr_status & GR_READY))
72762+ return 0;
72763+#endif
72764+
72765+ read_lock(&grsec_exec_file_lock);
72766+ if (unlikely(!task->exec_file)) {
72767+ read_unlock(&grsec_exec_file_lock);
72768+ return 0;
72769+ }
72770+
72771+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
72772+ read_unlock(&grsec_exec_file_lock);
72773+
72774+ if (retmode & GR_NOPTRACE) {
72775+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72776+ return 1;
72777+ }
72778+
72779+ if (retmode & GR_PTRACERD) {
72780+ switch (request) {
72781+ case PTRACE_SEIZE:
72782+ case PTRACE_POKETEXT:
72783+ case PTRACE_POKEDATA:
72784+ case PTRACE_POKEUSR:
72785+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
72786+ case PTRACE_SETREGS:
72787+ case PTRACE_SETFPREGS:
72788+#endif
72789+#ifdef CONFIG_X86
72790+ case PTRACE_SETFPXREGS:
72791+#endif
72792+#ifdef CONFIG_ALTIVEC
72793+ case PTRACE_SETVRREGS:
72794+#endif
72795+ return 1;
72796+ default:
72797+ return 0;
72798+ }
72799+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
72800+ !(current->role->roletype & GR_ROLE_GOD) &&
72801+ (current->acl != task->acl)) {
72802+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72803+ return 1;
72804+ }
72805+
72806+ return 0;
72807+}
72808+
72809+static int is_writable_mmap(const struct file *filp)
72810+{
72811+ struct task_struct *task = current;
72812+ struct acl_object_label *obj, *obj2;
72813+
72814+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
72815+ !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode) && (filp->f_path.mnt != shm_mnt || (filp->f_path.dentry->d_inode->i_nlink > 0))) {
72816+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72817+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
72818+ task->role->root_label);
72819+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
72820+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
72821+ return 1;
72822+ }
72823+ }
72824+ return 0;
72825+}
72826+
72827+int
72828+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
72829+{
72830+ __u32 mode;
72831+
72832+ if (unlikely(!file || !(prot & PROT_EXEC)))
72833+ return 1;
72834+
72835+ if (is_writable_mmap(file))
72836+ return 0;
72837+
72838+ mode =
72839+ gr_search_file(file->f_path.dentry,
72840+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72841+ file->f_path.mnt);
72842+
72843+ if (!gr_tpe_allow(file))
72844+ return 0;
72845+
72846+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72847+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72848+ return 0;
72849+ } else if (unlikely(!(mode & GR_EXEC))) {
72850+ return 0;
72851+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72852+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72853+ return 1;
72854+ }
72855+
72856+ return 1;
72857+}
72858+
72859+int
72860+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72861+{
72862+ __u32 mode;
72863+
72864+ if (unlikely(!file || !(prot & PROT_EXEC)))
72865+ return 1;
72866+
72867+ if (is_writable_mmap(file))
72868+ return 0;
72869+
72870+ mode =
72871+ gr_search_file(file->f_path.dentry,
72872+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72873+ file->f_path.mnt);
72874+
72875+ if (!gr_tpe_allow(file))
72876+ return 0;
72877+
72878+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72879+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72880+ return 0;
72881+ } else if (unlikely(!(mode & GR_EXEC))) {
72882+ return 0;
72883+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72884+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72885+ return 1;
72886+ }
72887+
72888+ return 1;
72889+}
72890+
72891+void
72892+gr_acl_handle_psacct(struct task_struct *task, const long code)
72893+{
72894+ unsigned long runtime, cputime;
72895+ cputime_t utime, stime;
72896+ unsigned int wday, cday;
72897+ __u8 whr, chr;
72898+ __u8 wmin, cmin;
72899+ __u8 wsec, csec;
72900+ struct timespec timeval;
72901+
72902+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72903+ !(task->acl->mode & GR_PROCACCT)))
72904+ return;
72905+
72906+ do_posix_clock_monotonic_gettime(&timeval);
72907+ runtime = timeval.tv_sec - task->start_time.tv_sec;
72908+ wday = runtime / (60 * 60 * 24);
72909+ runtime -= wday * (60 * 60 * 24);
72910+ whr = runtime / (60 * 60);
72911+ runtime -= whr * (60 * 60);
72912+ wmin = runtime / 60;
72913+ runtime -= wmin * 60;
72914+ wsec = runtime;
72915+
72916+ task_cputime(task, &utime, &stime);
72917+ cputime = cputime_to_secs(utime + stime);
72918+ cday = cputime / (60 * 60 * 24);
72919+ cputime -= cday * (60 * 60 * 24);
72920+ chr = cputime / (60 * 60);
72921+ cputime -= chr * (60 * 60);
72922+ cmin = cputime / 60;
72923+ cputime -= cmin * 60;
72924+ csec = cputime;
72925+
72926+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72927+
72928+ return;
72929+}
72930+
72931+#ifdef CONFIG_TASKSTATS
72932+int gr_is_taskstats_denied(int pid)
72933+{
72934+ struct task_struct *task;
72935+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72936+ const struct cred *cred;
72937+#endif
72938+ int ret = 0;
72939+
72940+ /* restrict taskstats viewing to un-chrooted root users
72941+ who have the 'view' subject flag if the RBAC system is enabled
72942+ */
72943+
72944+ rcu_read_lock();
72945+ read_lock(&tasklist_lock);
72946+ task = find_task_by_vpid(pid);
72947+ if (task) {
72948+#ifdef CONFIG_GRKERNSEC_CHROOT
72949+ if (proc_is_chrooted(task))
72950+ ret = -EACCES;
72951+#endif
72952+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72953+ cred = __task_cred(task);
72954+#ifdef CONFIG_GRKERNSEC_PROC_USER
72955+ if (gr_is_global_nonroot(cred->uid))
72956+ ret = -EACCES;
72957+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72958+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72959+ ret = -EACCES;
72960+#endif
72961+#endif
72962+ if (gr_status & GR_READY) {
72963+ if (!(task->acl->mode & GR_VIEW))
72964+ ret = -EACCES;
72965+ }
72966+ } else
72967+ ret = -ENOENT;
72968+
72969+ read_unlock(&tasklist_lock);
72970+ rcu_read_unlock();
72971+
72972+ return ret;
72973+}
72974+#endif
72975+
72976+/* AUXV entries are filled via a descendant of search_binary_handler
72977+ after we've already applied the subject for the target
72978+*/
72979+int gr_acl_enable_at_secure(void)
72980+{
72981+ if (unlikely(!(gr_status & GR_READY)))
72982+ return 0;
72983+
72984+ if (current->acl->mode & GR_ATSECURE)
72985+ return 1;
72986+
72987+ return 0;
72988+}
72989+
72990+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72991+{
72992+ struct task_struct *task = current;
72993+ struct dentry *dentry = file->f_path.dentry;
72994+ struct vfsmount *mnt = file->f_path.mnt;
72995+ struct acl_object_label *obj, *tmp;
72996+ struct acl_subject_label *subj;
72997+ unsigned int bufsize;
72998+ int is_not_root;
72999+ char *path;
73000+ dev_t dev = __get_dev(dentry);
73001+
73002+ if (unlikely(!(gr_status & GR_READY)))
73003+ return 1;
73004+
73005+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
73006+ return 1;
73007+
73008+ /* ignore Eric Biederman */
73009+ if (IS_PRIVATE(dentry->d_inode))
73010+ return 1;
73011+
73012+ subj = task->acl;
73013+ read_lock(&gr_inode_lock);
73014+ do {
73015+ obj = lookup_acl_obj_label(ino, dev, subj);
73016+ if (obj != NULL) {
73017+ read_unlock(&gr_inode_lock);
73018+ return (obj->mode & GR_FIND) ? 1 : 0;
73019+ }
73020+ } while ((subj = subj->parent_subject));
73021+ read_unlock(&gr_inode_lock);
73022+
73023+ /* this is purely an optimization since we're looking for an object
73024+ for the directory we're doing a readdir on
73025+ if it's possible for any globbed object to match the entry we're
73026+ filling into the directory, then the object we find here will be
73027+ an anchor point with attached globbed objects
73028+ */
73029+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
73030+ if (obj->globbed == NULL)
73031+ return (obj->mode & GR_FIND) ? 1 : 0;
73032+
73033+ is_not_root = ((obj->filename[0] == '/') &&
73034+ (obj->filename[1] == '\0')) ? 0 : 1;
73035+ bufsize = PAGE_SIZE - namelen - is_not_root;
73036+
73037+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
73038+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
73039+ return 1;
73040+
73041+ preempt_disable();
73042+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
73043+ bufsize);
73044+
73045+ bufsize = strlen(path);
73046+
73047+ /* if base is "/", don't append an additional slash */
73048+ if (is_not_root)
73049+ *(path + bufsize) = '/';
73050+ memcpy(path + bufsize + is_not_root, name, namelen);
73051+ *(path + bufsize + namelen + is_not_root) = '\0';
73052+
73053+ tmp = obj->globbed;
73054+ while (tmp) {
73055+ if (!glob_match(tmp->filename, path)) {
73056+ preempt_enable();
73057+ return (tmp->mode & GR_FIND) ? 1 : 0;
73058+ }
73059+ tmp = tmp->next;
73060+ }
73061+ preempt_enable();
73062+ return (obj->mode & GR_FIND) ? 1 : 0;
73063+}
73064+
73065+void gr_put_exec_file(struct task_struct *task)
73066+{
73067+ struct file *filp;
73068+
73069+ write_lock(&grsec_exec_file_lock);
73070+ filp = task->exec_file;
73071+ task->exec_file = NULL;
73072+ write_unlock(&grsec_exec_file_lock);
73073+
73074+ if (filp)
73075+ fput(filp);
73076+
73077+ return;
73078+}
73079+
73080+
73081+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
73082+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
73083+#endif
73084+#ifdef CONFIG_SECURITY
73085+EXPORT_SYMBOL_GPL(gr_check_user_change);
73086+EXPORT_SYMBOL_GPL(gr_check_group_change);
73087+#endif
73088+
73089diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
73090new file mode 100644
73091index 0000000..18ffbbd
73092--- /dev/null
73093+++ b/grsecurity/gracl_alloc.c
73094@@ -0,0 +1,105 @@
73095+#include <linux/kernel.h>
73096+#include <linux/mm.h>
73097+#include <linux/slab.h>
73098+#include <linux/vmalloc.h>
73099+#include <linux/gracl.h>
73100+#include <linux/grsecurity.h>
73101+
73102+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
73103+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
73104+
73105+static __inline__ int
73106+alloc_pop(void)
73107+{
73108+ if (current_alloc_state->alloc_stack_next == 1)
73109+ return 0;
73110+
73111+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
73112+
73113+ current_alloc_state->alloc_stack_next--;
73114+
73115+ return 1;
73116+}
73117+
73118+static __inline__ int
73119+alloc_push(void *buf)
73120+{
73121+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
73122+ return 1;
73123+
73124+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
73125+
73126+ current_alloc_state->alloc_stack_next++;
73127+
73128+ return 0;
73129+}
73130+
73131+void *
73132+acl_alloc(unsigned long len)
73133+{
73134+ void *ret = NULL;
73135+
73136+ if (!len || len > PAGE_SIZE)
73137+ goto out;
73138+
73139+ ret = kmalloc(len, GFP_KERNEL);
73140+
73141+ if (ret) {
73142+ if (alloc_push(ret)) {
73143+ kfree(ret);
73144+ ret = NULL;
73145+ }
73146+ }
73147+
73148+out:
73149+ return ret;
73150+}
73151+
73152+void *
73153+acl_alloc_num(unsigned long num, unsigned long len)
73154+{
73155+ if (!len || (num > (PAGE_SIZE / len)))
73156+ return NULL;
73157+
73158+ return acl_alloc(num * len);
73159+}
73160+
73161+void
73162+acl_free_all(void)
73163+{
73164+ if (!current_alloc_state->alloc_stack)
73165+ return;
73166+
73167+ while (alloc_pop()) ;
73168+
73169+ if (current_alloc_state->alloc_stack) {
73170+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
73171+ kfree(current_alloc_state->alloc_stack);
73172+ else
73173+ vfree(current_alloc_state->alloc_stack);
73174+ }
73175+
73176+ current_alloc_state->alloc_stack = NULL;
73177+ current_alloc_state->alloc_stack_size = 1;
73178+ current_alloc_state->alloc_stack_next = 1;
73179+
73180+ return;
73181+}
73182+
73183+int
73184+acl_alloc_stack_init(unsigned long size)
73185+{
73186+ if ((size * sizeof (void *)) <= PAGE_SIZE)
73187+ current_alloc_state->alloc_stack =
73188+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
73189+ else
73190+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
73191+
73192+ current_alloc_state->alloc_stack_size = size;
73193+ current_alloc_state->alloc_stack_next = 1;
73194+
73195+ if (!current_alloc_state->alloc_stack)
73196+ return 0;
73197+ else
73198+ return 1;
73199+}
73200diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
73201new file mode 100644
73202index 0000000..1a94c11
73203--- /dev/null
73204+++ b/grsecurity/gracl_cap.c
73205@@ -0,0 +1,127 @@
73206+#include <linux/kernel.h>
73207+#include <linux/module.h>
73208+#include <linux/sched.h>
73209+#include <linux/gracl.h>
73210+#include <linux/grsecurity.h>
73211+#include <linux/grinternal.h>
73212+
73213+extern const char *captab_log[];
73214+extern int captab_log_entries;
73215+
73216+int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
73217+{
73218+ struct acl_subject_label *curracl;
73219+
73220+ if (!gr_acl_is_enabled())
73221+ return 1;
73222+
73223+ curracl = task->acl;
73224+
73225+ if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
73226+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
73227+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
73228+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
73229+ gr_to_filename(task->exec_file->f_path.dentry,
73230+ task->exec_file->f_path.mnt) : curracl->filename,
73231+ curracl->filename, 0UL,
73232+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
73233+ return 1;
73234+ }
73235+
73236+ return 0;
73237+}
73238+
73239+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73240+{
73241+ struct acl_subject_label *curracl;
73242+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
73243+ kernel_cap_t cap_audit = __cap_empty_set;
73244+
73245+ if (!gr_acl_is_enabled())
73246+ return 1;
73247+
73248+ curracl = task->acl;
73249+
73250+ cap_drop = curracl->cap_lower;
73251+ cap_mask = curracl->cap_mask;
73252+ cap_audit = curracl->cap_invert_audit;
73253+
73254+ while ((curracl = curracl->parent_subject)) {
73255+ /* if the cap isn't specified in the current computed mask but is specified in the
73256+ current level subject, and is lowered in the current level subject, then add
73257+ it to the set of dropped capabilities
73258+ otherwise, add the current level subject's mask to the current computed mask
73259+ */
73260+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
73261+ cap_raise(cap_mask, cap);
73262+ if (cap_raised(curracl->cap_lower, cap))
73263+ cap_raise(cap_drop, cap);
73264+ if (cap_raised(curracl->cap_invert_audit, cap))
73265+ cap_raise(cap_audit, cap);
73266+ }
73267+ }
73268+
73269+ if (!cap_raised(cap_drop, cap)) {
73270+ if (cap_raised(cap_audit, cap))
73271+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
73272+ return 1;
73273+ }
73274+
73275+ /* only learn the capability use if the process has the capability in the
73276+ general case, the two uses in sys.c of gr_learn_cap are an exception
73277+ to this rule to ensure any role transition involves what the full-learned
73278+ policy believes in a privileged process
73279+ */
73280+ if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
73281+ return 1;
73282+
73283+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
73284+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
73285+
73286+ return 0;
73287+}
73288+
73289+int
73290+gr_acl_is_capable(const int cap)
73291+{
73292+ return gr_task_acl_is_capable(current, current_cred(), cap);
73293+}
73294+
73295+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
73296+{
73297+ struct acl_subject_label *curracl;
73298+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
73299+
73300+ if (!gr_acl_is_enabled())
73301+ return 1;
73302+
73303+ curracl = task->acl;
73304+
73305+ cap_drop = curracl->cap_lower;
73306+ cap_mask = curracl->cap_mask;
73307+
73308+ while ((curracl = curracl->parent_subject)) {
73309+ /* if the cap isn't specified in the current computed mask but is specified in the
73310+ current level subject, and is lowered in the current level subject, then add
73311+ it to the set of dropped capabilities
73312+ otherwise, add the current level subject's mask to the current computed mask
73313+ */
73314+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
73315+ cap_raise(cap_mask, cap);
73316+ if (cap_raised(curracl->cap_lower, cap))
73317+ cap_raise(cap_drop, cap);
73318+ }
73319+ }
73320+
73321+ if (!cap_raised(cap_drop, cap))
73322+ return 1;
73323+
73324+ return 0;
73325+}
73326+
73327+int
73328+gr_acl_is_capable_nolog(const int cap)
73329+{
73330+ return gr_task_acl_is_capable_nolog(current, cap);
73331+}
73332+
73333diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
73334new file mode 100644
73335index 0000000..ca25605
73336--- /dev/null
73337+++ b/grsecurity/gracl_compat.c
73338@@ -0,0 +1,270 @@
73339+#include <linux/kernel.h>
73340+#include <linux/gracl.h>
73341+#include <linux/compat.h>
73342+#include <linux/gracl_compat.h>
73343+
73344+#include <asm/uaccess.h>
73345+
73346+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
73347+{
73348+ struct gr_arg_wrapper_compat uwrapcompat;
73349+
73350+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
73351+ return -EFAULT;
73352+
73353+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
73354+ (uwrapcompat.version != 0x2901)) ||
73355+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
73356+ return -EINVAL;
73357+
73358+ uwrap->arg = compat_ptr(uwrapcompat.arg);
73359+ uwrap->version = uwrapcompat.version;
73360+ uwrap->size = sizeof(struct gr_arg);
73361+
73362+ return 0;
73363+}
73364+
73365+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
73366+{
73367+ struct gr_arg_compat argcompat;
73368+
73369+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
73370+ return -EFAULT;
73371+
73372+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
73373+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
73374+ arg->role_db.num_roles = argcompat.role_db.num_roles;
73375+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
73376+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
73377+ arg->role_db.num_objects = argcompat.role_db.num_objects;
73378+
73379+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
73380+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
73381+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
73382+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
73383+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
73384+ arg->segv_device = argcompat.segv_device;
73385+ arg->segv_inode = argcompat.segv_inode;
73386+ arg->segv_uid = argcompat.segv_uid;
73387+ arg->num_sprole_pws = argcompat.num_sprole_pws;
73388+ arg->mode = argcompat.mode;
73389+
73390+ return 0;
73391+}
73392+
73393+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
73394+{
73395+ struct acl_object_label_compat objcompat;
73396+
73397+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
73398+ return -EFAULT;
73399+
73400+ obj->filename = compat_ptr(objcompat.filename);
73401+ obj->inode = objcompat.inode;
73402+ obj->device = objcompat.device;
73403+ obj->mode = objcompat.mode;
73404+
73405+ obj->nested = compat_ptr(objcompat.nested);
73406+ obj->globbed = compat_ptr(objcompat.globbed);
73407+
73408+ obj->prev = compat_ptr(objcompat.prev);
73409+ obj->next = compat_ptr(objcompat.next);
73410+
73411+ return 0;
73412+}
73413+
73414+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73415+{
73416+ unsigned int i;
73417+ struct acl_subject_label_compat subjcompat;
73418+
73419+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
73420+ return -EFAULT;
73421+
73422+ subj->filename = compat_ptr(subjcompat.filename);
73423+ subj->inode = subjcompat.inode;
73424+ subj->device = subjcompat.device;
73425+ subj->mode = subjcompat.mode;
73426+ subj->cap_mask = subjcompat.cap_mask;
73427+ subj->cap_lower = subjcompat.cap_lower;
73428+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
73429+
73430+ for (i = 0; i < GR_NLIMITS; i++) {
73431+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
73432+ subj->res[i].rlim_cur = RLIM_INFINITY;
73433+ else
73434+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
73435+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
73436+ subj->res[i].rlim_max = RLIM_INFINITY;
73437+ else
73438+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
73439+ }
73440+ subj->resmask = subjcompat.resmask;
73441+
73442+ subj->user_trans_type = subjcompat.user_trans_type;
73443+ subj->group_trans_type = subjcompat.group_trans_type;
73444+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
73445+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
73446+ subj->user_trans_num = subjcompat.user_trans_num;
73447+ subj->group_trans_num = subjcompat.group_trans_num;
73448+
73449+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
73450+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
73451+ subj->ip_type = subjcompat.ip_type;
73452+ subj->ips = compat_ptr(subjcompat.ips);
73453+ subj->ip_num = subjcompat.ip_num;
73454+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
73455+
73456+ subj->crashes = subjcompat.crashes;
73457+ subj->expires = subjcompat.expires;
73458+
73459+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
73460+ subj->hash = compat_ptr(subjcompat.hash);
73461+ subj->prev = compat_ptr(subjcompat.prev);
73462+ subj->next = compat_ptr(subjcompat.next);
73463+
73464+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
73465+ subj->obj_hash_size = subjcompat.obj_hash_size;
73466+ subj->pax_flags = subjcompat.pax_flags;
73467+
73468+ return 0;
73469+}
73470+
73471+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
73472+{
73473+ struct acl_role_label_compat rolecompat;
73474+
73475+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
73476+ return -EFAULT;
73477+
73478+ role->rolename = compat_ptr(rolecompat.rolename);
73479+ role->uidgid = rolecompat.uidgid;
73480+ role->roletype = rolecompat.roletype;
73481+
73482+ role->auth_attempts = rolecompat.auth_attempts;
73483+ role->expires = rolecompat.expires;
73484+
73485+ role->root_label = compat_ptr(rolecompat.root_label);
73486+ role->hash = compat_ptr(rolecompat.hash);
73487+
73488+ role->prev = compat_ptr(rolecompat.prev);
73489+ role->next = compat_ptr(rolecompat.next);
73490+
73491+ role->transitions = compat_ptr(rolecompat.transitions);
73492+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
73493+ role->domain_children = compat_ptr(rolecompat.domain_children);
73494+ role->domain_child_num = rolecompat.domain_child_num;
73495+
73496+ role->umask = rolecompat.umask;
73497+
73498+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
73499+ role->subj_hash_size = rolecompat.subj_hash_size;
73500+
73501+ return 0;
73502+}
73503+
73504+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73505+{
73506+ struct role_allowed_ip_compat roleip_compat;
73507+
73508+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
73509+ return -EFAULT;
73510+
73511+ roleip->addr = roleip_compat.addr;
73512+ roleip->netmask = roleip_compat.netmask;
73513+
73514+ roleip->prev = compat_ptr(roleip_compat.prev);
73515+ roleip->next = compat_ptr(roleip_compat.next);
73516+
73517+ return 0;
73518+}
73519+
73520+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
73521+{
73522+ struct role_transition_compat trans_compat;
73523+
73524+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
73525+ return -EFAULT;
73526+
73527+ trans->rolename = compat_ptr(trans_compat.rolename);
73528+
73529+ trans->prev = compat_ptr(trans_compat.prev);
73530+ trans->next = compat_ptr(trans_compat.next);
73531+
73532+ return 0;
73533+
73534+}
73535+
73536+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73537+{
73538+ struct gr_hash_struct_compat hash_compat;
73539+
73540+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
73541+ return -EFAULT;
73542+
73543+ hash->table = compat_ptr(hash_compat.table);
73544+ hash->nametable = compat_ptr(hash_compat.nametable);
73545+ hash->first = compat_ptr(hash_compat.first);
73546+
73547+ hash->table_size = hash_compat.table_size;
73548+ hash->used_size = hash_compat.used_size;
73549+
73550+ hash->type = hash_compat.type;
73551+
73552+ return 0;
73553+}
73554+
73555+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
73556+{
73557+ compat_uptr_t ptrcompat;
73558+
73559+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
73560+ return -EFAULT;
73561+
73562+ *(void **)ptr = compat_ptr(ptrcompat);
73563+
73564+ return 0;
73565+}
73566+
73567+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73568+{
73569+ struct acl_ip_label_compat ip_compat;
73570+
73571+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
73572+ return -EFAULT;
73573+
73574+ ip->iface = compat_ptr(ip_compat.iface);
73575+ ip->addr = ip_compat.addr;
73576+ ip->netmask = ip_compat.netmask;
73577+ ip->low = ip_compat.low;
73578+ ip->high = ip_compat.high;
73579+ ip->mode = ip_compat.mode;
73580+ ip->type = ip_compat.type;
73581+
73582+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
73583+
73584+ ip->prev = compat_ptr(ip_compat.prev);
73585+ ip->next = compat_ptr(ip_compat.next);
73586+
73587+ return 0;
73588+}
73589+
73590+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73591+{
73592+ struct sprole_pw_compat pw_compat;
73593+
73594+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
73595+ return -EFAULT;
73596+
73597+ pw->rolename = compat_ptr(pw_compat.rolename);
73598+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
73599+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
73600+
73601+ return 0;
73602+}
73603+
73604+size_t get_gr_arg_wrapper_size_compat(void)
73605+{
73606+ return sizeof(struct gr_arg_wrapper_compat);
73607+}
73608+
73609diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
73610new file mode 100644
73611index 0000000..4008fdc
73612--- /dev/null
73613+++ b/grsecurity/gracl_fs.c
73614@@ -0,0 +1,445 @@
73615+#include <linux/kernel.h>
73616+#include <linux/sched.h>
73617+#include <linux/types.h>
73618+#include <linux/fs.h>
73619+#include <linux/file.h>
73620+#include <linux/stat.h>
73621+#include <linux/grsecurity.h>
73622+#include <linux/grinternal.h>
73623+#include <linux/gracl.h>
73624+
73625+umode_t
73626+gr_acl_umask(void)
73627+{
73628+ if (unlikely(!gr_acl_is_enabled()))
73629+ return 0;
73630+
73631+ return current->role->umask;
73632+}
73633+
73634+__u32
73635+gr_acl_handle_hidden_file(const struct dentry * dentry,
73636+ const struct vfsmount * mnt)
73637+{
73638+ __u32 mode;
73639+
73640+ if (unlikely(d_is_negative(dentry)))
73641+ return GR_FIND;
73642+
73643+ mode =
73644+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
73645+
73646+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
73647+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73648+ return mode;
73649+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
73650+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73651+ return 0;
73652+ } else if (unlikely(!(mode & GR_FIND)))
73653+ return 0;
73654+
73655+ return GR_FIND;
73656+}
73657+
73658+__u32
73659+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73660+ int acc_mode)
73661+{
73662+ __u32 reqmode = GR_FIND;
73663+ __u32 mode;
73664+
73665+ if (unlikely(d_is_negative(dentry)))
73666+ return reqmode;
73667+
73668+ if (acc_mode & MAY_APPEND)
73669+ reqmode |= GR_APPEND;
73670+ else if (acc_mode & MAY_WRITE)
73671+ reqmode |= GR_WRITE;
73672+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
73673+ reqmode |= GR_READ;
73674+
73675+ mode =
73676+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73677+ mnt);
73678+
73679+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73680+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73681+ reqmode & GR_READ ? " reading" : "",
73682+ reqmode & GR_WRITE ? " writing" : reqmode &
73683+ GR_APPEND ? " appending" : "");
73684+ return reqmode;
73685+ } else
73686+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73687+ {
73688+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73689+ reqmode & GR_READ ? " reading" : "",
73690+ reqmode & GR_WRITE ? " writing" : reqmode &
73691+ GR_APPEND ? " appending" : "");
73692+ return 0;
73693+ } else if (unlikely((mode & reqmode) != reqmode))
73694+ return 0;
73695+
73696+ return reqmode;
73697+}
73698+
73699+__u32
73700+gr_acl_handle_creat(const struct dentry * dentry,
73701+ const struct dentry * p_dentry,
73702+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73703+ const int imode)
73704+{
73705+ __u32 reqmode = GR_WRITE | GR_CREATE;
73706+ __u32 mode;
73707+
73708+ if (acc_mode & MAY_APPEND)
73709+ reqmode |= GR_APPEND;
73710+ // if a directory was required or the directory already exists, then
73711+ // don't count this open as a read
73712+ if ((acc_mode & MAY_READ) &&
73713+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
73714+ reqmode |= GR_READ;
73715+ if ((open_flags & O_CREAT) &&
73716+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73717+ reqmode |= GR_SETID;
73718+
73719+ mode =
73720+ gr_check_create(dentry, p_dentry, p_mnt,
73721+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73722+
73723+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73724+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73725+ reqmode & GR_READ ? " reading" : "",
73726+ reqmode & GR_WRITE ? " writing" : reqmode &
73727+ GR_APPEND ? " appending" : "");
73728+ return reqmode;
73729+ } else
73730+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73731+ {
73732+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73733+ reqmode & GR_READ ? " reading" : "",
73734+ reqmode & GR_WRITE ? " writing" : reqmode &
73735+ GR_APPEND ? " appending" : "");
73736+ return 0;
73737+ } else if (unlikely((mode & reqmode) != reqmode))
73738+ return 0;
73739+
73740+ return reqmode;
73741+}
73742+
73743+__u32
73744+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
73745+ const int fmode)
73746+{
73747+ __u32 mode, reqmode = GR_FIND;
73748+
73749+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
73750+ reqmode |= GR_EXEC;
73751+ if (fmode & S_IWOTH)
73752+ reqmode |= GR_WRITE;
73753+ if (fmode & S_IROTH)
73754+ reqmode |= GR_READ;
73755+
73756+ mode =
73757+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73758+ mnt);
73759+
73760+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73761+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73762+ reqmode & GR_READ ? " reading" : "",
73763+ reqmode & GR_WRITE ? " writing" : "",
73764+ reqmode & GR_EXEC ? " executing" : "");
73765+ return reqmode;
73766+ } else
73767+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73768+ {
73769+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73770+ reqmode & GR_READ ? " reading" : "",
73771+ reqmode & GR_WRITE ? " writing" : "",
73772+ reqmode & GR_EXEC ? " executing" : "");
73773+ return 0;
73774+ } else if (unlikely((mode & reqmode) != reqmode))
73775+ return 0;
73776+
73777+ return reqmode;
73778+}
73779+
73780+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
73781+{
73782+ __u32 mode;
73783+
73784+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
73785+
73786+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73787+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
73788+ return mode;
73789+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73790+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
73791+ return 0;
73792+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
73793+ return 0;
73794+
73795+ return (reqmode);
73796+}
73797+
73798+__u32
73799+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73800+{
73801+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
73802+}
73803+
73804+__u32
73805+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
73806+{
73807+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
73808+}
73809+
73810+__u32
73811+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
73812+{
73813+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
73814+}
73815+
73816+__u32
73817+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
73818+{
73819+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
73820+}
73821+
73822+__u32
73823+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
73824+ umode_t *modeptr)
73825+{
73826+ umode_t mode;
73827+
73828+ *modeptr &= ~gr_acl_umask();
73829+ mode = *modeptr;
73830+
73831+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
73832+ return 1;
73833+
73834+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
73835+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
73836+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
73837+ GR_CHMOD_ACL_MSG);
73838+ } else {
73839+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
73840+ }
73841+}
73842+
73843+__u32
73844+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
73845+{
73846+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
73847+}
73848+
73849+__u32
73850+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
73851+{
73852+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
73853+}
73854+
73855+__u32
73856+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
73857+{
73858+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
73859+}
73860+
73861+__u32
73862+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
73863+{
73864+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
73865+}
73866+
73867+__u32
73868+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
73869+{
73870+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
73871+ GR_UNIXCONNECT_ACL_MSG);
73872+}
73873+
73874+/* hardlinks require at minimum create and link permission,
73875+ any additional privilege required is based on the
73876+ privilege of the file being linked to
73877+*/
73878+__u32
73879+gr_acl_handle_link(const struct dentry * new_dentry,
73880+ const struct dentry * parent_dentry,
73881+ const struct vfsmount * parent_mnt,
73882+ const struct dentry * old_dentry,
73883+ const struct vfsmount * old_mnt, const struct filename *to)
73884+{
73885+ __u32 mode;
73886+ __u32 needmode = GR_CREATE | GR_LINK;
73887+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73888+
73889+ mode =
73890+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73891+ old_mnt);
73892+
73893+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73894+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73895+ return mode;
73896+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73897+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73898+ return 0;
73899+ } else if (unlikely((mode & needmode) != needmode))
73900+ return 0;
73901+
73902+ return 1;
73903+}
73904+
73905+__u32
73906+gr_acl_handle_symlink(const struct dentry * new_dentry,
73907+ const struct dentry * parent_dentry,
73908+ const struct vfsmount * parent_mnt, const struct filename *from)
73909+{
73910+ __u32 needmode = GR_WRITE | GR_CREATE;
73911+ __u32 mode;
73912+
73913+ mode =
73914+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
73915+ GR_CREATE | GR_AUDIT_CREATE |
73916+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73917+
73918+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73919+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73920+ return mode;
73921+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73922+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73923+ return 0;
73924+ } else if (unlikely((mode & needmode) != needmode))
73925+ return 0;
73926+
73927+ return (GR_WRITE | GR_CREATE);
73928+}
73929+
73930+static __u32 generic_fs_create_handler(const struct dentry *new_dentry, const struct dentry *parent_dentry, const struct vfsmount *parent_mnt, __u32 reqmode, const char *fmt)
73931+{
73932+ __u32 mode;
73933+
73934+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73935+
73936+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73937+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73938+ return mode;
73939+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73940+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73941+ return 0;
73942+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
73943+ return 0;
73944+
73945+ return (reqmode);
73946+}
73947+
73948+__u32
73949+gr_acl_handle_mknod(const struct dentry * new_dentry,
73950+ const struct dentry * parent_dentry,
73951+ const struct vfsmount * parent_mnt,
73952+ const int mode)
73953+{
73954+ __u32 reqmode = GR_WRITE | GR_CREATE;
73955+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73956+ reqmode |= GR_SETID;
73957+
73958+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73959+ reqmode, GR_MKNOD_ACL_MSG);
73960+}
73961+
73962+__u32
73963+gr_acl_handle_mkdir(const struct dentry *new_dentry,
73964+ const struct dentry *parent_dentry,
73965+ const struct vfsmount *parent_mnt)
73966+{
73967+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73968+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73969+}
73970+
73971+#define RENAME_CHECK_SUCCESS(old, new) \
73972+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73973+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73974+
73975+int
73976+gr_acl_handle_rename(struct dentry *new_dentry,
73977+ struct dentry *parent_dentry,
73978+ const struct vfsmount *parent_mnt,
73979+ struct dentry *old_dentry,
73980+ struct inode *old_parent_inode,
73981+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73982+{
73983+ __u32 comp1, comp2;
73984+ int error = 0;
73985+
73986+ if (unlikely(!gr_acl_is_enabled()))
73987+ return 0;
73988+
73989+ if (flags & RENAME_EXCHANGE) {
73990+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73991+ GR_AUDIT_READ | GR_AUDIT_WRITE |
73992+ GR_SUPPRESS, parent_mnt);
73993+ comp2 =
73994+ gr_search_file(old_dentry,
73995+ GR_READ | GR_WRITE | GR_AUDIT_READ |
73996+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73997+ } else if (d_is_negative(new_dentry)) {
73998+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73999+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
74000+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
74001+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
74002+ GR_DELETE | GR_AUDIT_DELETE |
74003+ GR_AUDIT_READ | GR_AUDIT_WRITE |
74004+ GR_SUPPRESS, old_mnt);
74005+ } else {
74006+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
74007+ GR_CREATE | GR_DELETE |
74008+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
74009+ GR_AUDIT_READ | GR_AUDIT_WRITE |
74010+ GR_SUPPRESS, parent_mnt);
74011+ comp2 =
74012+ gr_search_file(old_dentry,
74013+ GR_READ | GR_WRITE | GR_AUDIT_READ |
74014+ GR_DELETE | GR_AUDIT_DELETE |
74015+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
74016+ }
74017+
74018+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
74019+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
74020+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
74021+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
74022+ && !(comp2 & GR_SUPPRESS)) {
74023+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
74024+ error = -EACCES;
74025+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
74026+ error = -EACCES;
74027+
74028+ return error;
74029+}
74030+
74031+void
74032+gr_acl_handle_exit(void)
74033+{
74034+ u16 id;
74035+ char *rolename;
74036+
74037+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
74038+ !(current->role->roletype & GR_ROLE_PERSIST))) {
74039+ id = current->acl_role_id;
74040+ rolename = current->role->rolename;
74041+ gr_set_acls(1);
74042+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
74043+ }
74044+
74045+ gr_put_exec_file(current);
74046+ return;
74047+}
74048+
74049+int
74050+gr_acl_handle_procpidmem(const struct task_struct *task)
74051+{
74052+ if (unlikely(!gr_acl_is_enabled()))
74053+ return 0;
74054+
74055+ if (task != current && task->acl->mode & GR_PROTPROCFD)
74056+ return -EACCES;
74057+
74058+ return 0;
74059+}
74060diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
74061new file mode 100644
74062index 0000000..f056b81
74063--- /dev/null
74064+++ b/grsecurity/gracl_ip.c
74065@@ -0,0 +1,386 @@
74066+#include <linux/kernel.h>
74067+#include <asm/uaccess.h>
74068+#include <asm/errno.h>
74069+#include <net/sock.h>
74070+#include <linux/file.h>
74071+#include <linux/fs.h>
74072+#include <linux/net.h>
74073+#include <linux/in.h>
74074+#include <linux/skbuff.h>
74075+#include <linux/ip.h>
74076+#include <linux/udp.h>
74077+#include <linux/types.h>
74078+#include <linux/sched.h>
74079+#include <linux/netdevice.h>
74080+#include <linux/inetdevice.h>
74081+#include <linux/gracl.h>
74082+#include <linux/grsecurity.h>
74083+#include <linux/grinternal.h>
74084+
74085+#define GR_BIND 0x01
74086+#define GR_CONNECT 0x02
74087+#define GR_INVERT 0x04
74088+#define GR_BINDOVERRIDE 0x08
74089+#define GR_CONNECTOVERRIDE 0x10
74090+#define GR_SOCK_FAMILY 0x20
74091+
74092+static const char * gr_protocols[IPPROTO_MAX] = {
74093+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
74094+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
74095+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
74096+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
74097+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
74098+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
74099+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
74100+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
74101+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
74102+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
74103+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
74104+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
74105+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
74106+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
74107+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
74108+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
74109+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
74110+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
74111+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
74112+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
74113+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
74114+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
74115+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
74116+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
74117+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
74118+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
74119+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
74120+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
74121+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
74122+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
74123+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
74124+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
74125+ };
74126+
74127+static const char * gr_socktypes[SOCK_MAX] = {
74128+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
74129+ "unknown:7", "unknown:8", "unknown:9", "packet"
74130+ };
74131+
74132+static const char * gr_sockfamilies[AF_MAX+1] = {
74133+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
74134+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
74135+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
74136+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
74137+ };
74138+
74139+const char *
74140+gr_proto_to_name(unsigned char proto)
74141+{
74142+ return gr_protocols[proto];
74143+}
74144+
74145+const char *
74146+gr_socktype_to_name(unsigned char type)
74147+{
74148+ return gr_socktypes[type];
74149+}
74150+
74151+const char *
74152+gr_sockfamily_to_name(unsigned char family)
74153+{
74154+ return gr_sockfamilies[family];
74155+}
74156+
74157+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
74158+
74159+int
74160+gr_search_socket(const int domain, const int type, const int protocol)
74161+{
74162+ struct acl_subject_label *curr;
74163+ const struct cred *cred = current_cred();
74164+
74165+ if (unlikely(!gr_acl_is_enabled()))
74166+ goto exit;
74167+
74168+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
74169+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
74170+ goto exit; // let the kernel handle it
74171+
74172+ curr = current->acl;
74173+
74174+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
74175+ /* the family is allowed, if this is PF_INET allow it only if
74176+ the extra sock type/protocol checks pass */
74177+ if (domain == PF_INET)
74178+ goto inet_check;
74179+ goto exit;
74180+ } else {
74181+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
74182+ __u32 fakeip = 0;
74183+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74184+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
74185+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
74186+ gr_to_filename(current->exec_file->f_path.dentry,
74187+ current->exec_file->f_path.mnt) :
74188+ curr->filename, curr->filename,
74189+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
74190+ &current->signal->saved_ip);
74191+ goto exit;
74192+ }
74193+ goto exit_fail;
74194+ }
74195+
74196+inet_check:
74197+ /* the rest of this checking is for IPv4 only */
74198+ if (!curr->ips)
74199+ goto exit;
74200+
74201+ if ((curr->ip_type & (1U << type)) &&
74202+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
74203+ goto exit;
74204+
74205+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
74206+ /* we don't place acls on raw sockets , and sometimes
74207+ dgram/ip sockets are opened for ioctl and not
74208+ bind/connect, so we'll fake a bind learn log */
74209+ if (type == SOCK_RAW || type == SOCK_PACKET) {
74210+ __u32 fakeip = 0;
74211+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74212+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
74213+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
74214+ gr_to_filename(current->exec_file->f_path.dentry,
74215+ current->exec_file->f_path.mnt) :
74216+ curr->filename, curr->filename,
74217+ &fakeip, 0, type,
74218+ protocol, GR_CONNECT, &current->signal->saved_ip);
74219+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
74220+ __u32 fakeip = 0;
74221+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74222+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
74223+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
74224+ gr_to_filename(current->exec_file->f_path.dentry,
74225+ current->exec_file->f_path.mnt) :
74226+ curr->filename, curr->filename,
74227+ &fakeip, 0, type,
74228+ protocol, GR_BIND, &current->signal->saved_ip);
74229+ }
74230+ /* we'll log when they use connect or bind */
74231+ goto exit;
74232+ }
74233+
74234+exit_fail:
74235+ if (domain == PF_INET)
74236+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
74237+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
74238+ else if (rcu_access_pointer(net_families[domain]) != NULL)
74239+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
74240+ gr_socktype_to_name(type), protocol);
74241+
74242+ return 0;
74243+exit:
74244+ return 1;
74245+}
74246+
74247+int check_ip_policy(struct acl_ip_label *ip, __u32 ip_addr, __u16 ip_port, __u8 protocol, const int mode, const int type, __u32 our_addr, __u32 our_netmask)
74248+{
74249+ if ((ip->mode & mode) &&
74250+ (ip_port >= ip->low) &&
74251+ (ip_port <= ip->high) &&
74252+ ((ntohl(ip_addr) & our_netmask) ==
74253+ (ntohl(our_addr) & our_netmask))
74254+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
74255+ && (ip->type & (1U << type))) {
74256+ if (ip->mode & GR_INVERT)
74257+ return 2; // specifically denied
74258+ else
74259+ return 1; // allowed
74260+ }
74261+
74262+ return 0; // not specifically allowed, may continue parsing
74263+}
74264+
74265+static int
74266+gr_search_connectbind(const int full_mode, struct sock *sk,
74267+ struct sockaddr_in *addr, const int type)
74268+{
74269+ char iface[IFNAMSIZ] = {0};
74270+ struct acl_subject_label *curr;
74271+ struct acl_ip_label *ip;
74272+ struct inet_sock *isk;
74273+ struct net_device *dev;
74274+ struct in_device *idev;
74275+ unsigned long i;
74276+ int ret;
74277+ int mode = full_mode & (GR_BIND | GR_CONNECT);
74278+ __u32 ip_addr = 0;
74279+ __u32 our_addr;
74280+ __u32 our_netmask;
74281+ char *p;
74282+ __u16 ip_port = 0;
74283+ const struct cred *cred = current_cred();
74284+
74285+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
74286+ return 0;
74287+
74288+ curr = current->acl;
74289+ isk = inet_sk(sk);
74290+
74291+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
74292+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
74293+ addr->sin_addr.s_addr = curr->inaddr_any_override;
74294+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
74295+ struct sockaddr_in saddr;
74296+ int err;
74297+
74298+ saddr.sin_family = AF_INET;
74299+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
74300+ saddr.sin_port = isk->inet_sport;
74301+
74302+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
74303+ if (err)
74304+ return err;
74305+
74306+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
74307+ if (err)
74308+ return err;
74309+ }
74310+
74311+ if (!curr->ips)
74312+ return 0;
74313+
74314+ ip_addr = addr->sin_addr.s_addr;
74315+ ip_port = ntohs(addr->sin_port);
74316+
74317+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
74318+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74319+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
74320+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
74321+ gr_to_filename(current->exec_file->f_path.dentry,
74322+ current->exec_file->f_path.mnt) :
74323+ curr->filename, curr->filename,
74324+ &ip_addr, ip_port, type,
74325+ sk->sk_protocol, mode, &current->signal->saved_ip);
74326+ return 0;
74327+ }
74328+
74329+ for (i = 0; i < curr->ip_num; i++) {
74330+ ip = *(curr->ips + i);
74331+ if (ip->iface != NULL) {
74332+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
74333+ p = strchr(iface, ':');
74334+ if (p != NULL)
74335+ *p = '\0';
74336+ dev = dev_get_by_name(sock_net(sk), iface);
74337+ if (dev == NULL)
74338+ continue;
74339+ idev = in_dev_get(dev);
74340+ if (idev == NULL) {
74341+ dev_put(dev);
74342+ continue;
74343+ }
74344+ rcu_read_lock();
74345+ for_ifa(idev) {
74346+ if (!strcmp(ip->iface, ifa->ifa_label)) {
74347+ our_addr = ifa->ifa_address;
74348+ our_netmask = 0xffffffff;
74349+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
74350+ if (ret == 1) {
74351+ rcu_read_unlock();
74352+ in_dev_put(idev);
74353+ dev_put(dev);
74354+ return 0;
74355+ } else if (ret == 2) {
74356+ rcu_read_unlock();
74357+ in_dev_put(idev);
74358+ dev_put(dev);
74359+ goto denied;
74360+ }
74361+ }
74362+ } endfor_ifa(idev);
74363+ rcu_read_unlock();
74364+ in_dev_put(idev);
74365+ dev_put(dev);
74366+ } else {
74367+ our_addr = ip->addr;
74368+ our_netmask = ip->netmask;
74369+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
74370+ if (ret == 1)
74371+ return 0;
74372+ else if (ret == 2)
74373+ goto denied;
74374+ }
74375+ }
74376+
74377+denied:
74378+ if (mode == GR_BIND)
74379+ gr_log_int5_str2(GR_DONT_AUDIT, GR_BIND_ACL_MSG, &ip_addr, ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
74380+ else if (mode == GR_CONNECT)
74381+ gr_log_int5_str2(GR_DONT_AUDIT, GR_CONNECT_ACL_MSG, &ip_addr, ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
74382+
74383+ return -EACCES;
74384+}
74385+
74386+int
74387+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
74388+{
74389+ /* always allow disconnection of dgram sockets with connect */
74390+ if (addr->sin_family == AF_UNSPEC)
74391+ return 0;
74392+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
74393+}
74394+
74395+int
74396+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
74397+{
74398+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
74399+}
74400+
74401+int gr_search_listen(struct socket *sock)
74402+{
74403+ struct sock *sk = sock->sk;
74404+ struct sockaddr_in addr;
74405+
74406+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
74407+ addr.sin_port = inet_sk(sk)->inet_sport;
74408+
74409+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
74410+}
74411+
74412+int gr_search_accept(struct socket *sock)
74413+{
74414+ struct sock *sk = sock->sk;
74415+ struct sockaddr_in addr;
74416+
74417+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
74418+ addr.sin_port = inet_sk(sk)->inet_sport;
74419+
74420+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
74421+}
74422+
74423+int
74424+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
74425+{
74426+ if (addr)
74427+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
74428+ else {
74429+ struct sockaddr_in sin;
74430+ const struct inet_sock *inet = inet_sk(sk);
74431+
74432+ sin.sin_addr.s_addr = inet->inet_daddr;
74433+ sin.sin_port = inet->inet_dport;
74434+
74435+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
74436+ }
74437+}
74438+
74439+int
74440+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
74441+{
74442+ struct sockaddr_in sin;
74443+
74444+ if (unlikely(skb->len < sizeof (struct udphdr)))
74445+ return 0; // skip this packet
74446+
74447+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
74448+ sin.sin_port = udp_hdr(skb)->source;
74449+
74450+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
74451+}
74452diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
74453new file mode 100644
74454index 0000000..25f54ef
74455--- /dev/null
74456+++ b/grsecurity/gracl_learn.c
74457@@ -0,0 +1,207 @@
74458+#include <linux/kernel.h>
74459+#include <linux/mm.h>
74460+#include <linux/sched.h>
74461+#include <linux/poll.h>
74462+#include <linux/string.h>
74463+#include <linux/file.h>
74464+#include <linux/types.h>
74465+#include <linux/vmalloc.h>
74466+#include <linux/grinternal.h>
74467+
74468+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
74469+ size_t count, loff_t *ppos);
74470+extern int gr_acl_is_enabled(void);
74471+
74472+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
74473+static int gr_learn_attached;
74474+
74475+/* use a 512k buffer */
74476+#define LEARN_BUFFER_SIZE (512 * 1024)
74477+
74478+static DEFINE_SPINLOCK(gr_learn_lock);
74479+static DEFINE_MUTEX(gr_learn_user_mutex);
74480+
74481+/* we need to maintain two buffers, so that the kernel context of grlearn
74482+ uses a semaphore around the userspace copying, and the other kernel contexts
74483+ use a spinlock when copying into the buffer, since they cannot sleep
74484+*/
74485+static char *learn_buffer;
74486+static char *learn_buffer_user;
74487+static int learn_buffer_len;
74488+static int learn_buffer_user_len;
74489+
74490+static ssize_t
74491+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
74492+{
74493+ DECLARE_WAITQUEUE(wait, current);
74494+ ssize_t retval = 0;
74495+
74496+ add_wait_queue(&learn_wait, &wait);
74497+ set_current_state(TASK_INTERRUPTIBLE);
74498+ do {
74499+ mutex_lock(&gr_learn_user_mutex);
74500+ spin_lock(&gr_learn_lock);
74501+ if (learn_buffer_len)
74502+ break;
74503+ spin_unlock(&gr_learn_lock);
74504+ mutex_unlock(&gr_learn_user_mutex);
74505+ if (file->f_flags & O_NONBLOCK) {
74506+ retval = -EAGAIN;
74507+ goto out;
74508+ }
74509+ if (signal_pending(current)) {
74510+ retval = -ERESTARTSYS;
74511+ goto out;
74512+ }
74513+
74514+ schedule();
74515+ } while (1);
74516+
74517+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
74518+ learn_buffer_user_len = learn_buffer_len;
74519+ retval = learn_buffer_len;
74520+ learn_buffer_len = 0;
74521+
74522+ spin_unlock(&gr_learn_lock);
74523+
74524+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
74525+ retval = -EFAULT;
74526+
74527+ mutex_unlock(&gr_learn_user_mutex);
74528+out:
74529+ set_current_state(TASK_RUNNING);
74530+ remove_wait_queue(&learn_wait, &wait);
74531+ return retval;
74532+}
74533+
74534+static unsigned int
74535+poll_learn(struct file * file, poll_table * wait)
74536+{
74537+ poll_wait(file, &learn_wait, wait);
74538+
74539+ if (learn_buffer_len)
74540+ return (POLLIN | POLLRDNORM);
74541+
74542+ return 0;
74543+}
74544+
74545+void
74546+gr_clear_learn_entries(void)
74547+{
74548+ char *tmp;
74549+
74550+ mutex_lock(&gr_learn_user_mutex);
74551+ spin_lock(&gr_learn_lock);
74552+ tmp = learn_buffer;
74553+ learn_buffer = NULL;
74554+ spin_unlock(&gr_learn_lock);
74555+ if (tmp)
74556+ vfree(tmp);
74557+ if (learn_buffer_user != NULL) {
74558+ vfree(learn_buffer_user);
74559+ learn_buffer_user = NULL;
74560+ }
74561+ learn_buffer_len = 0;
74562+ mutex_unlock(&gr_learn_user_mutex);
74563+
74564+ return;
74565+}
74566+
74567+void
74568+gr_add_learn_entry(const char *fmt, ...)
74569+{
74570+ va_list args;
74571+ unsigned int len;
74572+
74573+ if (!gr_learn_attached)
74574+ return;
74575+
74576+ spin_lock(&gr_learn_lock);
74577+
74578+ /* leave a gap at the end so we know when it's "full" but don't have to
74579+ compute the exact length of the string we're trying to append
74580+ */
74581+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
74582+ spin_unlock(&gr_learn_lock);
74583+ wake_up_interruptible(&learn_wait);
74584+ return;
74585+ }
74586+ if (learn_buffer == NULL) {
74587+ spin_unlock(&gr_learn_lock);
74588+ return;
74589+ }
74590+
74591+ va_start(args, fmt);
74592+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
74593+ va_end(args);
74594+
74595+ learn_buffer_len += len + 1;
74596+
74597+ spin_unlock(&gr_learn_lock);
74598+ wake_up_interruptible(&learn_wait);
74599+
74600+ return;
74601+}
74602+
74603+static int
74604+open_learn(struct inode *inode, struct file *file)
74605+{
74606+ if (file->f_mode & FMODE_READ && gr_learn_attached)
74607+ return -EBUSY;
74608+ if (file->f_mode & FMODE_READ) {
74609+ int retval = 0;
74610+ mutex_lock(&gr_learn_user_mutex);
74611+ if (learn_buffer == NULL)
74612+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
74613+ if (learn_buffer_user == NULL)
74614+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
74615+ if (learn_buffer == NULL) {
74616+ retval = -ENOMEM;
74617+ goto out_error;
74618+ }
74619+ if (learn_buffer_user == NULL) {
74620+ retval = -ENOMEM;
74621+ goto out_error;
74622+ }
74623+ learn_buffer_len = 0;
74624+ learn_buffer_user_len = 0;
74625+ gr_learn_attached = 1;
74626+out_error:
74627+ mutex_unlock(&gr_learn_user_mutex);
74628+ return retval;
74629+ }
74630+ return 0;
74631+}
74632+
74633+static int
74634+close_learn(struct inode *inode, struct file *file)
74635+{
74636+ if (file->f_mode & FMODE_READ) {
74637+ char *tmp = NULL;
74638+ mutex_lock(&gr_learn_user_mutex);
74639+ spin_lock(&gr_learn_lock);
74640+ tmp = learn_buffer;
74641+ learn_buffer = NULL;
74642+ spin_unlock(&gr_learn_lock);
74643+ if (tmp)
74644+ vfree(tmp);
74645+ if (learn_buffer_user != NULL) {
74646+ vfree(learn_buffer_user);
74647+ learn_buffer_user = NULL;
74648+ }
74649+ learn_buffer_len = 0;
74650+ learn_buffer_user_len = 0;
74651+ gr_learn_attached = 0;
74652+ mutex_unlock(&gr_learn_user_mutex);
74653+ }
74654+
74655+ return 0;
74656+}
74657+
74658+const struct file_operations grsec_fops = {
74659+ .read = read_learn,
74660+ .write = write_grsec_handler,
74661+ .open = open_learn,
74662+ .release = close_learn,
74663+ .poll = poll_learn,
74664+};
74665diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
74666new file mode 100644
74667index 0000000..3f8ade0
74668--- /dev/null
74669+++ b/grsecurity/gracl_policy.c
74670@@ -0,0 +1,1782 @@
74671+#include <linux/kernel.h>
74672+#include <linux/module.h>
74673+#include <linux/sched.h>
74674+#include <linux/mm.h>
74675+#include <linux/file.h>
74676+#include <linux/fs.h>
74677+#include <linux/namei.h>
74678+#include <linux/mount.h>
74679+#include <linux/tty.h>
74680+#include <linux/proc_fs.h>
74681+#include <linux/lglock.h>
74682+#include <linux/slab.h>
74683+#include <linux/vmalloc.h>
74684+#include <linux/types.h>
74685+#include <linux/sysctl.h>
74686+#include <linux/netdevice.h>
74687+#include <linux/ptrace.h>
74688+#include <linux/gracl.h>
74689+#include <linux/gralloc.h>
74690+#include <linux/security.h>
74691+#include <linux/grinternal.h>
74692+#include <linux/pid_namespace.h>
74693+#include <linux/stop_machine.h>
74694+#include <linux/fdtable.h>
74695+#include <linux/percpu.h>
74696+#include <linux/lglock.h>
74697+#include <linux/hugetlb.h>
74698+#include <linux/posix-timers.h>
74699+#include "../fs/mount.h"
74700+
74701+#include <asm/uaccess.h>
74702+#include <asm/errno.h>
74703+#include <asm/mman.h>
74704+
74705+extern struct gr_policy_state *polstate;
74706+
74707+#define FOR_EACH_ROLE_START(role) \
74708+ role = polstate->role_list; \
74709+ while (role) {
74710+
74711+#define FOR_EACH_ROLE_END(role) \
74712+ role = role->prev; \
74713+ }
74714+
74715+struct path gr_real_root;
74716+
74717+extern struct gr_alloc_state *current_alloc_state;
74718+
74719+u16 acl_sp_role_value;
74720+
74721+static DEFINE_MUTEX(gr_dev_mutex);
74722+
74723+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
74724+extern void gr_clear_learn_entries(void);
74725+
74726+struct gr_arg *gr_usermode __read_only;
74727+unsigned char *gr_system_salt __read_only;
74728+unsigned char *gr_system_sum __read_only;
74729+
74730+static unsigned int gr_auth_attempts = 0;
74731+static unsigned long gr_auth_expires = 0UL;
74732+
74733+struct acl_object_label *fakefs_obj_rw;
74734+struct acl_object_label *fakefs_obj_rwx;
74735+
74736+extern int gr_init_uidset(void);
74737+extern void gr_free_uidset(void);
74738+extern void gr_remove_uid(uid_t uid);
74739+extern int gr_find_uid(uid_t uid);
74740+
74741+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
74742+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
74743+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
74744+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
74745+extern struct acl_role_label *__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid, const gid_t gid);
74746+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
74747+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
74748+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
74749+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
74750+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74751+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74752+extern void assign_special_role(const char *rolename);
74753+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
74754+extern int gr_rbac_disable(void *unused);
74755+extern void gr_enable_rbac_system(void);
74756+
74757+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
74758+{
74759+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
74760+ return -EFAULT;
74761+
74762+ return 0;
74763+}
74764+
74765+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
74766+{
74767+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
74768+ return -EFAULT;
74769+
74770+ return 0;
74771+}
74772+
74773+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
74774+{
74775+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
74776+ return -EFAULT;
74777+
74778+ return 0;
74779+}
74780+
74781+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
74782+{
74783+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
74784+ return -EFAULT;
74785+
74786+ return 0;
74787+}
74788+
74789+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
74790+{
74791+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
74792+ return -EFAULT;
74793+
74794+ return 0;
74795+}
74796+
74797+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
74798+{
74799+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
74800+ return -EFAULT;
74801+
74802+ return 0;
74803+}
74804+
74805+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
74806+{
74807+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
74808+ return -EFAULT;
74809+
74810+ return 0;
74811+}
74812+
74813+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
74814+{
74815+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
74816+ return -EFAULT;
74817+
74818+ return 0;
74819+}
74820+
74821+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
74822+{
74823+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
74824+ return -EFAULT;
74825+
74826+ return 0;
74827+}
74828+
74829+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
74830+{
74831+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
74832+ return -EFAULT;
74833+
74834+ if (((uwrap->version != GRSECURITY_VERSION) &&
74835+ (uwrap->version != 0x2901)) ||
74836+ (uwrap->size != sizeof(struct gr_arg)))
74837+ return -EINVAL;
74838+
74839+ return 0;
74840+}
74841+
74842+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
74843+{
74844+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
74845+ return -EFAULT;
74846+
74847+ return 0;
74848+}
74849+
74850+static size_t get_gr_arg_wrapper_size_normal(void)
74851+{
74852+ return sizeof(struct gr_arg_wrapper);
74853+}
74854+
74855+#ifdef CONFIG_COMPAT
74856+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
74857+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
74858+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
74859+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
74860+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
74861+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
74862+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
74863+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
74864+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
74865+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
74866+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
74867+extern size_t get_gr_arg_wrapper_size_compat(void);
74868+
74869+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
74870+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
74871+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
74872+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
74873+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
74874+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
74875+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
74876+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
74877+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
74878+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
74879+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
74880+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74881+
74882+#else
74883+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74884+#define copy_gr_arg copy_gr_arg_normal
74885+#define copy_gr_hash_struct copy_gr_hash_struct_normal
74886+#define copy_acl_object_label copy_acl_object_label_normal
74887+#define copy_acl_subject_label copy_acl_subject_label_normal
74888+#define copy_acl_role_label copy_acl_role_label_normal
74889+#define copy_acl_ip_label copy_acl_ip_label_normal
74890+#define copy_pointer_from_array copy_pointer_from_array_normal
74891+#define copy_sprole_pw copy_sprole_pw_normal
74892+#define copy_role_transition copy_role_transition_normal
74893+#define copy_role_allowed_ip copy_role_allowed_ip_normal
74894+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74895+#endif
74896+
74897+static struct acl_subject_label *
74898+lookup_subject_map(const struct acl_subject_label *userp)
74899+{
74900+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74901+ struct subject_map *match;
74902+
74903+ match = polstate->subj_map_set.s_hash[index];
74904+
74905+ while (match && match->user != userp)
74906+ match = match->next;
74907+
74908+ if (match != NULL)
74909+ return match->kernel;
74910+ else
74911+ return NULL;
74912+}
74913+
74914+static void
74915+insert_subj_map_entry(struct subject_map *subjmap)
74916+{
74917+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74918+ struct subject_map **curr;
74919+
74920+ subjmap->prev = NULL;
74921+
74922+ curr = &polstate->subj_map_set.s_hash[index];
74923+ if (*curr != NULL)
74924+ (*curr)->prev = subjmap;
74925+
74926+ subjmap->next = *curr;
74927+ *curr = subjmap;
74928+
74929+ return;
74930+}
74931+
74932+static void
74933+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74934+{
74935+ unsigned int index =
74936+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74937+ struct acl_role_label **curr;
74938+ struct acl_role_label *tmp, *tmp2;
74939+
74940+ curr = &polstate->acl_role_set.r_hash[index];
74941+
74942+ /* simple case, slot is empty, just set it to our role */
74943+ if (*curr == NULL) {
74944+ *curr = role;
74945+ } else {
74946+ /* example:
74947+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
74948+ 2 -> 3
74949+ */
74950+ /* first check to see if we can already be reached via this slot */
74951+ tmp = *curr;
74952+ while (tmp && tmp != role)
74953+ tmp = tmp->next;
74954+ if (tmp == role) {
74955+ /* we don't need to add ourselves to this slot's chain */
74956+ return;
74957+ }
74958+ /* we need to add ourselves to this chain, two cases */
74959+ if (role->next == NULL) {
74960+ /* simple case, append the current chain to our role */
74961+ role->next = *curr;
74962+ *curr = role;
74963+ } else {
74964+ /* 1 -> 2 -> 3 -> 4
74965+ 2 -> 3 -> 4
74966+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74967+ */
74968+ /* trickier case: walk our role's chain until we find
74969+ the role for the start of the current slot's chain */
74970+ tmp = role;
74971+ tmp2 = *curr;
74972+ while (tmp->next && tmp->next != tmp2)
74973+ tmp = tmp->next;
74974+ if (tmp->next == tmp2) {
74975+ /* from example above, we found 3, so just
74976+ replace this slot's chain with ours */
74977+ *curr = role;
74978+ } else {
74979+ /* we didn't find a subset of our role's chain
74980+ in the current slot's chain, so append their
74981+ chain to ours, and set us as the first role in
74982+ the slot's chain
74983+
74984+ we could fold this case with the case above,
74985+ but making it explicit for clarity
74986+ */
74987+ tmp->next = tmp2;
74988+ *curr = role;
74989+ }
74990+ }
74991+ }
74992+
74993+ return;
74994+}
74995+
74996+static void
74997+insert_acl_role_label(struct acl_role_label *role)
74998+{
74999+ int i;
75000+
75001+ if (polstate->role_list == NULL) {
75002+ polstate->role_list = role;
75003+ role->prev = NULL;
75004+ } else {
75005+ role->prev = polstate->role_list;
75006+ polstate->role_list = role;
75007+ }
75008+
75009+ /* used for hash chains */
75010+ role->next = NULL;
75011+
75012+ if (role->roletype & GR_ROLE_DOMAIN) {
75013+ for (i = 0; i < role->domain_child_num; i++)
75014+ __insert_acl_role_label(role, role->domain_children[i]);
75015+ } else
75016+ __insert_acl_role_label(role, role->uidgid);
75017+}
75018+
75019+static int
75020+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
75021+{
75022+ struct name_entry **curr, *nentry;
75023+ struct inodev_entry *ientry;
75024+ unsigned int len = strlen(name);
75025+ unsigned int key = full_name_hash(name, len);
75026+ unsigned int index = key % polstate->name_set.n_size;
75027+
75028+ curr = &polstate->name_set.n_hash[index];
75029+
75030+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
75031+ curr = &((*curr)->next);
75032+
75033+ if (*curr != NULL)
75034+ return 1;
75035+
75036+ nentry = acl_alloc(sizeof (struct name_entry));
75037+ if (nentry == NULL)
75038+ return 0;
75039+ ientry = acl_alloc(sizeof (struct inodev_entry));
75040+ if (ientry == NULL)
75041+ return 0;
75042+ ientry->nentry = nentry;
75043+
75044+ nentry->key = key;
75045+ nentry->name = name;
75046+ nentry->inode = inode;
75047+ nentry->device = device;
75048+ nentry->len = len;
75049+ nentry->deleted = deleted;
75050+
75051+ nentry->prev = NULL;
75052+ curr = &polstate->name_set.n_hash[index];
75053+ if (*curr != NULL)
75054+ (*curr)->prev = nentry;
75055+ nentry->next = *curr;
75056+ *curr = nentry;
75057+
75058+ /* insert us into the table searchable by inode/dev */
75059+ __insert_inodev_entry(polstate, ientry);
75060+
75061+ return 1;
75062+}
75063+
75064+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
75065+
75066+static void *
75067+create_table(__u32 * len, int elementsize)
75068+{
75069+ unsigned int table_sizes[] = {
75070+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
75071+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
75072+ 4194301, 8388593, 16777213, 33554393, 67108859
75073+ };
75074+ void *newtable = NULL;
75075+ unsigned int pwr = 0;
75076+
75077+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
75078+ table_sizes[pwr] <= *len)
75079+ pwr++;
75080+
75081+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
75082+ return newtable;
75083+
75084+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
75085+ newtable =
75086+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
75087+ else
75088+ newtable = vmalloc(table_sizes[pwr] * elementsize);
75089+
75090+ *len = table_sizes[pwr];
75091+
75092+ return newtable;
75093+}
75094+
75095+static int
75096+init_variables(const struct gr_arg *arg, bool reload)
75097+{
75098+ struct task_struct *reaper = init_pid_ns.child_reaper;
75099+ unsigned int stacksize;
75100+
75101+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
75102+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
75103+ polstate->name_set.n_size = arg->role_db.num_objects;
75104+ polstate->inodev_set.i_size = arg->role_db.num_objects;
75105+
75106+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
75107+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
75108+ return 1;
75109+
75110+ if (!reload) {
75111+ if (!gr_init_uidset())
75112+ return 1;
75113+ }
75114+
75115+ /* set up the stack that holds allocation info */
75116+
75117+ stacksize = arg->role_db.num_pointers + 5;
75118+
75119+ if (!acl_alloc_stack_init(stacksize))
75120+ return 1;
75121+
75122+ if (!reload) {
75123+ /* grab reference for the real root dentry and vfsmount */
75124+ get_fs_root(reaper->fs, &gr_real_root);
75125+
75126+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
75127+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(gr_real_root.dentry), gr_real_root.dentry->d_inode->i_ino);
75128+#endif
75129+
75130+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
75131+ if (fakefs_obj_rw == NULL)
75132+ return 1;
75133+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
75134+
75135+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
75136+ if (fakefs_obj_rwx == NULL)
75137+ return 1;
75138+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
75139+ }
75140+
75141+ polstate->subj_map_set.s_hash =
75142+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
75143+ polstate->acl_role_set.r_hash =
75144+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
75145+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
75146+ polstate->inodev_set.i_hash =
75147+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
75148+
75149+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
75150+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
75151+ return 1;
75152+
75153+ memset(polstate->subj_map_set.s_hash, 0,
75154+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
75155+ memset(polstate->acl_role_set.r_hash, 0,
75156+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
75157+ memset(polstate->name_set.n_hash, 0,
75158+ sizeof (struct name_entry *) * polstate->name_set.n_size);
75159+ memset(polstate->inodev_set.i_hash, 0,
75160+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
75161+
75162+ return 0;
75163+}
75164+
75165+/* free information not needed after startup
75166+ currently contains user->kernel pointer mappings for subjects
75167+*/
75168+
75169+static void
75170+free_init_variables(void)
75171+{
75172+ __u32 i;
75173+
75174+ if (polstate->subj_map_set.s_hash) {
75175+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
75176+ if (polstate->subj_map_set.s_hash[i]) {
75177+ kfree(polstate->subj_map_set.s_hash[i]);
75178+ polstate->subj_map_set.s_hash[i] = NULL;
75179+ }
75180+ }
75181+
75182+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
75183+ PAGE_SIZE)
75184+ kfree(polstate->subj_map_set.s_hash);
75185+ else
75186+ vfree(polstate->subj_map_set.s_hash);
75187+ }
75188+
75189+ return;
75190+}
75191+
75192+static void
75193+free_variables(bool reload)
75194+{
75195+ struct acl_subject_label *s;
75196+ struct acl_role_label *r;
75197+ struct task_struct *task, *task2;
75198+ unsigned int x;
75199+
75200+ if (!reload) {
75201+ gr_clear_learn_entries();
75202+
75203+ read_lock(&tasklist_lock);
75204+ do_each_thread(task2, task) {
75205+ task->acl_sp_role = 0;
75206+ task->acl_role_id = 0;
75207+ task->inherited = 0;
75208+ task->acl = NULL;
75209+ task->role = NULL;
75210+ } while_each_thread(task2, task);
75211+ read_unlock(&tasklist_lock);
75212+
75213+ kfree(fakefs_obj_rw);
75214+ fakefs_obj_rw = NULL;
75215+ kfree(fakefs_obj_rwx);
75216+ fakefs_obj_rwx = NULL;
75217+
75218+ /* release the reference to the real root dentry and vfsmount */
75219+ path_put(&gr_real_root);
75220+ memset(&gr_real_root, 0, sizeof(gr_real_root));
75221+ }
75222+
75223+ /* free all object hash tables */
75224+
75225+ FOR_EACH_ROLE_START(r)
75226+ if (r->subj_hash == NULL)
75227+ goto next_role;
75228+ FOR_EACH_SUBJECT_START(r, s, x)
75229+ if (s->obj_hash == NULL)
75230+ break;
75231+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
75232+ kfree(s->obj_hash);
75233+ else
75234+ vfree(s->obj_hash);
75235+ FOR_EACH_SUBJECT_END(s, x)
75236+ FOR_EACH_NESTED_SUBJECT_START(r, s)
75237+ if (s->obj_hash == NULL)
75238+ break;
75239+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
75240+ kfree(s->obj_hash);
75241+ else
75242+ vfree(s->obj_hash);
75243+ FOR_EACH_NESTED_SUBJECT_END(s)
75244+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
75245+ kfree(r->subj_hash);
75246+ else
75247+ vfree(r->subj_hash);
75248+ r->subj_hash = NULL;
75249+next_role:
75250+ FOR_EACH_ROLE_END(r)
75251+
75252+ acl_free_all();
75253+
75254+ if (polstate->acl_role_set.r_hash) {
75255+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
75256+ PAGE_SIZE)
75257+ kfree(polstate->acl_role_set.r_hash);
75258+ else
75259+ vfree(polstate->acl_role_set.r_hash);
75260+ }
75261+ if (polstate->name_set.n_hash) {
75262+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
75263+ PAGE_SIZE)
75264+ kfree(polstate->name_set.n_hash);
75265+ else
75266+ vfree(polstate->name_set.n_hash);
75267+ }
75268+
75269+ if (polstate->inodev_set.i_hash) {
75270+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
75271+ PAGE_SIZE)
75272+ kfree(polstate->inodev_set.i_hash);
75273+ else
75274+ vfree(polstate->inodev_set.i_hash);
75275+ }
75276+
75277+ if (!reload)
75278+ gr_free_uidset();
75279+
75280+ memset(&polstate->name_set, 0, sizeof (struct name_db));
75281+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
75282+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
75283+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
75284+
75285+ polstate->default_role = NULL;
75286+ polstate->kernel_role = NULL;
75287+ polstate->role_list = NULL;
75288+
75289+ return;
75290+}
75291+
75292+static struct acl_subject_label *
75293+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
75294+
75295+static int alloc_and_copy_string(char **name, unsigned int maxlen)
75296+{
75297+ unsigned int len = strnlen_user(*name, maxlen);
75298+ char *tmp;
75299+
75300+ if (!len || len >= maxlen)
75301+ return -EINVAL;
75302+
75303+ if ((tmp = (char *) acl_alloc(len)) == NULL)
75304+ return -ENOMEM;
75305+
75306+ if (copy_from_user(tmp, *name, len))
75307+ return -EFAULT;
75308+
75309+ tmp[len-1] = '\0';
75310+ *name = tmp;
75311+
75312+ return 0;
75313+}
75314+
75315+static int
75316+copy_user_glob(struct acl_object_label *obj)
75317+{
75318+ struct acl_object_label *g_tmp, **guser;
75319+ int error;
75320+
75321+ if (obj->globbed == NULL)
75322+ return 0;
75323+
75324+ guser = &obj->globbed;
75325+ while (*guser) {
75326+ g_tmp = (struct acl_object_label *)
75327+ acl_alloc(sizeof (struct acl_object_label));
75328+ if (g_tmp == NULL)
75329+ return -ENOMEM;
75330+
75331+ if (copy_acl_object_label(g_tmp, *guser))
75332+ return -EFAULT;
75333+
75334+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
75335+ if (error)
75336+ return error;
75337+
75338+ *guser = g_tmp;
75339+ guser = &(g_tmp->next);
75340+ }
75341+
75342+ return 0;
75343+}
75344+
75345+static int
75346+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
75347+ struct acl_role_label *role)
75348+{
75349+ struct acl_object_label *o_tmp;
75350+ int ret;
75351+
75352+ while (userp) {
75353+ if ((o_tmp = (struct acl_object_label *)
75354+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
75355+ return -ENOMEM;
75356+
75357+ if (copy_acl_object_label(o_tmp, userp))
75358+ return -EFAULT;
75359+
75360+ userp = o_tmp->prev;
75361+
75362+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
75363+ if (ret)
75364+ return ret;
75365+
75366+ insert_acl_obj_label(o_tmp, subj);
75367+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
75368+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
75369+ return -ENOMEM;
75370+
75371+ ret = copy_user_glob(o_tmp);
75372+ if (ret)
75373+ return ret;
75374+
75375+ if (o_tmp->nested) {
75376+ int already_copied;
75377+
75378+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
75379+ if (IS_ERR(o_tmp->nested))
75380+ return PTR_ERR(o_tmp->nested);
75381+
75382+ /* insert into nested subject list if we haven't copied this one yet
75383+ to prevent duplicate entries */
75384+ if (!already_copied) {
75385+ o_tmp->nested->next = role->hash->first;
75386+ role->hash->first = o_tmp->nested;
75387+ }
75388+ }
75389+ }
75390+
75391+ return 0;
75392+}
75393+
75394+static __u32
75395+count_user_subjs(struct acl_subject_label *userp)
75396+{
75397+ struct acl_subject_label s_tmp;
75398+ __u32 num = 0;
75399+
75400+ while (userp) {
75401+ if (copy_acl_subject_label(&s_tmp, userp))
75402+ break;
75403+
75404+ userp = s_tmp.prev;
75405+ }
75406+
75407+ return num;
75408+}
75409+
75410+static int
75411+copy_user_allowedips(struct acl_role_label *rolep)
75412+{
75413+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
75414+
75415+ ruserip = rolep->allowed_ips;
75416+
75417+ while (ruserip) {
75418+ rlast = rtmp;
75419+
75420+ if ((rtmp = (struct role_allowed_ip *)
75421+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
75422+ return -ENOMEM;
75423+
75424+ if (copy_role_allowed_ip(rtmp, ruserip))
75425+ return -EFAULT;
75426+
75427+ ruserip = rtmp->prev;
75428+
75429+ if (!rlast) {
75430+ rtmp->prev = NULL;
75431+ rolep->allowed_ips = rtmp;
75432+ } else {
75433+ rlast->next = rtmp;
75434+ rtmp->prev = rlast;
75435+ }
75436+
75437+ if (!ruserip)
75438+ rtmp->next = NULL;
75439+ }
75440+
75441+ return 0;
75442+}
75443+
75444+static int
75445+copy_user_transitions(struct acl_role_label *rolep)
75446+{
75447+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
75448+ int error;
75449+
75450+ rusertp = rolep->transitions;
75451+
75452+ while (rusertp) {
75453+ rlast = rtmp;
75454+
75455+ if ((rtmp = (struct role_transition *)
75456+ acl_alloc(sizeof (struct role_transition))) == NULL)
75457+ return -ENOMEM;
75458+
75459+ if (copy_role_transition(rtmp, rusertp))
75460+ return -EFAULT;
75461+
75462+ rusertp = rtmp->prev;
75463+
75464+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
75465+ if (error)
75466+ return error;
75467+
75468+ if (!rlast) {
75469+ rtmp->prev = NULL;
75470+ rolep->transitions = rtmp;
75471+ } else {
75472+ rlast->next = rtmp;
75473+ rtmp->prev = rlast;
75474+ }
75475+
75476+ if (!rusertp)
75477+ rtmp->next = NULL;
75478+ }
75479+
75480+ return 0;
75481+}
75482+
75483+static __u32 count_user_objs(const struct acl_object_label __user *userp)
75484+{
75485+ struct acl_object_label o_tmp;
75486+ __u32 num = 0;
75487+
75488+ while (userp) {
75489+ if (copy_acl_object_label(&o_tmp, userp))
75490+ break;
75491+
75492+ userp = o_tmp.prev;
75493+ num++;
75494+ }
75495+
75496+ return num;
75497+}
75498+
75499+static struct acl_subject_label *
75500+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
75501+{
75502+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
75503+ __u32 num_objs;
75504+ struct acl_ip_label **i_tmp, *i_utmp2;
75505+ struct gr_hash_struct ghash;
75506+ struct subject_map *subjmap;
75507+ unsigned int i_num;
75508+ int err;
75509+
75510+ if (already_copied != NULL)
75511+ *already_copied = 0;
75512+
75513+ s_tmp = lookup_subject_map(userp);
75514+
75515+ /* we've already copied this subject into the kernel, just return
75516+ the reference to it, and don't copy it over again
75517+ */
75518+ if (s_tmp) {
75519+ if (already_copied != NULL)
75520+ *already_copied = 1;
75521+ return(s_tmp);
75522+ }
75523+
75524+ if ((s_tmp = (struct acl_subject_label *)
75525+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
75526+ return ERR_PTR(-ENOMEM);
75527+
75528+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
75529+ if (subjmap == NULL)
75530+ return ERR_PTR(-ENOMEM);
75531+
75532+ subjmap->user = userp;
75533+ subjmap->kernel = s_tmp;
75534+ insert_subj_map_entry(subjmap);
75535+
75536+ if (copy_acl_subject_label(s_tmp, userp))
75537+ return ERR_PTR(-EFAULT);
75538+
75539+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
75540+ if (err)
75541+ return ERR_PTR(err);
75542+
75543+ if (!strcmp(s_tmp->filename, "/"))
75544+ role->root_label = s_tmp;
75545+
75546+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
75547+ return ERR_PTR(-EFAULT);
75548+
75549+ /* copy user and group transition tables */
75550+
75551+ if (s_tmp->user_trans_num) {
75552+ uid_t *uidlist;
75553+
75554+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
75555+ if (uidlist == NULL)
75556+ return ERR_PTR(-ENOMEM);
75557+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
75558+ return ERR_PTR(-EFAULT);
75559+
75560+ s_tmp->user_transitions = uidlist;
75561+ }
75562+
75563+ if (s_tmp->group_trans_num) {
75564+ gid_t *gidlist;
75565+
75566+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
75567+ if (gidlist == NULL)
75568+ return ERR_PTR(-ENOMEM);
75569+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
75570+ return ERR_PTR(-EFAULT);
75571+
75572+ s_tmp->group_transitions = gidlist;
75573+ }
75574+
75575+ /* set up object hash table */
75576+ num_objs = count_user_objs(ghash.first);
75577+
75578+ s_tmp->obj_hash_size = num_objs;
75579+ s_tmp->obj_hash =
75580+ (struct acl_object_label **)
75581+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
75582+
75583+ if (!s_tmp->obj_hash)
75584+ return ERR_PTR(-ENOMEM);
75585+
75586+ memset(s_tmp->obj_hash, 0,
75587+ s_tmp->obj_hash_size *
75588+ sizeof (struct acl_object_label *));
75589+
75590+ /* add in objects */
75591+ err = copy_user_objs(ghash.first, s_tmp, role);
75592+
75593+ if (err)
75594+ return ERR_PTR(err);
75595+
75596+ /* set pointer for parent subject */
75597+ if (s_tmp->parent_subject) {
75598+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
75599+
75600+ if (IS_ERR(s_tmp2))
75601+ return s_tmp2;
75602+
75603+ s_tmp->parent_subject = s_tmp2;
75604+ }
75605+
75606+ /* add in ip acls */
75607+
75608+ if (!s_tmp->ip_num) {
75609+ s_tmp->ips = NULL;
75610+ goto insert;
75611+ }
75612+
75613+ i_tmp =
75614+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
75615+ sizeof (struct acl_ip_label *));
75616+
75617+ if (!i_tmp)
75618+ return ERR_PTR(-ENOMEM);
75619+
75620+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
75621+ *(i_tmp + i_num) =
75622+ (struct acl_ip_label *)
75623+ acl_alloc(sizeof (struct acl_ip_label));
75624+ if (!*(i_tmp + i_num))
75625+ return ERR_PTR(-ENOMEM);
75626+
75627+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
75628+ return ERR_PTR(-EFAULT);
75629+
75630+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
75631+ return ERR_PTR(-EFAULT);
75632+
75633+ if ((*(i_tmp + i_num))->iface == NULL)
75634+ continue;
75635+
75636+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
75637+ if (err)
75638+ return ERR_PTR(err);
75639+ }
75640+
75641+ s_tmp->ips = i_tmp;
75642+
75643+insert:
75644+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
75645+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
75646+ return ERR_PTR(-ENOMEM);
75647+
75648+ return s_tmp;
75649+}
75650+
75651+static int
75652+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
75653+{
75654+ struct acl_subject_label s_pre;
75655+ struct acl_subject_label * ret;
75656+ int err;
75657+
75658+ while (userp) {
75659+ if (copy_acl_subject_label(&s_pre, userp))
75660+ return -EFAULT;
75661+
75662+ ret = do_copy_user_subj(userp, role, NULL);
75663+
75664+ err = PTR_ERR(ret);
75665+ if (IS_ERR(ret))
75666+ return err;
75667+
75668+ insert_acl_subj_label(ret, role);
75669+
75670+ userp = s_pre.prev;
75671+ }
75672+
75673+ return 0;
75674+}
75675+
75676+static int
75677+copy_user_acl(struct gr_arg *arg)
75678+{
75679+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
75680+ struct acl_subject_label *subj_list;
75681+ struct sprole_pw *sptmp;
75682+ struct gr_hash_struct *ghash;
75683+ uid_t *domainlist;
75684+ unsigned int r_num;
75685+ int err = 0;
75686+ __u16 i;
75687+ __u32 num_subjs;
75688+
75689+ /* we need a default and kernel role */
75690+ if (arg->role_db.num_roles < 2)
75691+ return -EINVAL;
75692+
75693+ /* copy special role authentication info from userspace */
75694+
75695+ polstate->num_sprole_pws = arg->num_sprole_pws;
75696+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
75697+
75698+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
75699+ return -ENOMEM;
75700+
75701+ for (i = 0; i < polstate->num_sprole_pws; i++) {
75702+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
75703+ if (!sptmp)
75704+ return -ENOMEM;
75705+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
75706+ return -EFAULT;
75707+
75708+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
75709+ if (err)
75710+ return err;
75711+
75712+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
75713+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
75714+#endif
75715+
75716+ polstate->acl_special_roles[i] = sptmp;
75717+ }
75718+
75719+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
75720+
75721+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
75722+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
75723+
75724+ if (!r_tmp)
75725+ return -ENOMEM;
75726+
75727+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
75728+ return -EFAULT;
75729+
75730+ if (copy_acl_role_label(r_tmp, r_utmp2))
75731+ return -EFAULT;
75732+
75733+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
75734+ if (err)
75735+ return err;
75736+
75737+ if (!strcmp(r_tmp->rolename, "default")
75738+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
75739+ polstate->default_role = r_tmp;
75740+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
75741+ polstate->kernel_role = r_tmp;
75742+ }
75743+
75744+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
75745+ return -ENOMEM;
75746+
75747+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
75748+ return -EFAULT;
75749+
75750+ r_tmp->hash = ghash;
75751+
75752+ num_subjs = count_user_subjs(r_tmp->hash->first);
75753+
75754+ r_tmp->subj_hash_size = num_subjs;
75755+ r_tmp->subj_hash =
75756+ (struct acl_subject_label **)
75757+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
75758+
75759+ if (!r_tmp->subj_hash)
75760+ return -ENOMEM;
75761+
75762+ err = copy_user_allowedips(r_tmp);
75763+ if (err)
75764+ return err;
75765+
75766+ /* copy domain info */
75767+ if (r_tmp->domain_children != NULL) {
75768+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
75769+ if (domainlist == NULL)
75770+ return -ENOMEM;
75771+
75772+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
75773+ return -EFAULT;
75774+
75775+ r_tmp->domain_children = domainlist;
75776+ }
75777+
75778+ err = copy_user_transitions(r_tmp);
75779+ if (err)
75780+ return err;
75781+
75782+ memset(r_tmp->subj_hash, 0,
75783+ r_tmp->subj_hash_size *
75784+ sizeof (struct acl_subject_label *));
75785+
75786+ /* acquire the list of subjects, then NULL out
75787+ the list prior to parsing the subjects for this role,
75788+ as during this parsing the list is replaced with a list
75789+ of *nested* subjects for the role
75790+ */
75791+ subj_list = r_tmp->hash->first;
75792+
75793+ /* set nested subject list to null */
75794+ r_tmp->hash->first = NULL;
75795+
75796+ err = copy_user_subjs(subj_list, r_tmp);
75797+
75798+ if (err)
75799+ return err;
75800+
75801+ insert_acl_role_label(r_tmp);
75802+ }
75803+
75804+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
75805+ return -EINVAL;
75806+
75807+ return err;
75808+}
75809+
75810+static int gracl_reload_apply_policies(void *reload)
75811+{
75812+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
75813+ struct task_struct *task, *task2;
75814+ struct acl_role_label *role, *rtmp;
75815+ struct acl_subject_label *subj;
75816+ const struct cred *cred;
75817+ int role_applied;
75818+ int ret = 0;
75819+
75820+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
75821+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
75822+
75823+ /* first make sure we'll be able to apply the new policy cleanly */
75824+ do_each_thread(task2, task) {
75825+ if (task->exec_file == NULL)
75826+ continue;
75827+ role_applied = 0;
75828+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75829+ /* preserve special roles */
75830+ FOR_EACH_ROLE_START(role)
75831+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75832+ rtmp = task->role;
75833+ task->role = role;
75834+ role_applied = 1;
75835+ break;
75836+ }
75837+ FOR_EACH_ROLE_END(role)
75838+ }
75839+ if (!role_applied) {
75840+ cred = __task_cred(task);
75841+ rtmp = task->role;
75842+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75843+ }
75844+ /* this handles non-nested inherited subjects, nested subjects will still
75845+ be dropped currently */
75846+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75847+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
75848+ /* change the role back so that we've made no modifications to the policy */
75849+ task->role = rtmp;
75850+
75851+ if (subj == NULL || task->tmpacl == NULL) {
75852+ ret = -EINVAL;
75853+ goto out;
75854+ }
75855+ } while_each_thread(task2, task);
75856+
75857+ /* now actually apply the policy */
75858+
75859+ do_each_thread(task2, task) {
75860+ if (task->exec_file) {
75861+ role_applied = 0;
75862+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75863+ /* preserve special roles */
75864+ FOR_EACH_ROLE_START(role)
75865+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75866+ task->role = role;
75867+ role_applied = 1;
75868+ break;
75869+ }
75870+ FOR_EACH_ROLE_END(role)
75871+ }
75872+ if (!role_applied) {
75873+ cred = __task_cred(task);
75874+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75875+ }
75876+ /* this handles non-nested inherited subjects, nested subjects will still
75877+ be dropped currently */
75878+ if (!reload_state->oldmode && task->inherited)
75879+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75880+ else {
75881+ /* looked up and tagged to the task previously */
75882+ subj = task->tmpacl;
75883+ }
75884+ /* subj will be non-null */
75885+ __gr_apply_subject_to_task(polstate, task, subj);
75886+ if (reload_state->oldmode) {
75887+ task->acl_role_id = 0;
75888+ task->acl_sp_role = 0;
75889+ task->inherited = 0;
75890+ }
75891+ } else {
75892+ // it's a kernel process
75893+ task->role = polstate->kernel_role;
75894+ task->acl = polstate->kernel_role->root_label;
75895+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75896+ task->acl->mode &= ~GR_PROCFIND;
75897+#endif
75898+ }
75899+ } while_each_thread(task2, task);
75900+
75901+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75902+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75903+
75904+out:
75905+
75906+ return ret;
75907+}
75908+
75909+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75910+{
75911+ struct gr_reload_state new_reload_state = { };
75912+ int err;
75913+
75914+ new_reload_state.oldpolicy_ptr = polstate;
75915+ new_reload_state.oldalloc_ptr = current_alloc_state;
75916+ new_reload_state.oldmode = oldmode;
75917+
75918+ current_alloc_state = &new_reload_state.newalloc;
75919+ polstate = &new_reload_state.newpolicy;
75920+
75921+ /* everything relevant is now saved off, copy in the new policy */
75922+ if (init_variables(args, true)) {
75923+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75924+ err = -ENOMEM;
75925+ goto error;
75926+ }
75927+
75928+ err = copy_user_acl(args);
75929+ free_init_variables();
75930+ if (err)
75931+ goto error;
75932+ /* the new policy is copied in, with the old policy available via saved_state
75933+ first go through applying roles, making sure to preserve special roles
75934+ then apply new subjects, making sure to preserve inherited and nested subjects,
75935+ though currently only inherited subjects will be preserved
75936+ */
75937+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75938+ if (err)
75939+ goto error;
75940+
75941+ /* we've now applied the new policy, so restore the old policy state to free it */
75942+ polstate = &new_reload_state.oldpolicy;
75943+ current_alloc_state = &new_reload_state.oldalloc;
75944+ free_variables(true);
75945+
75946+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75947+ to running_polstate/current_alloc_state inside stop_machine
75948+ */
75949+ err = 0;
75950+ goto out;
75951+error:
75952+ /* on error of loading the new policy, we'll just keep the previous
75953+ policy set around
75954+ */
75955+ free_variables(true);
75956+
75957+ /* doesn't affect runtime, but maintains consistent state */
75958+out:
75959+ polstate = new_reload_state.oldpolicy_ptr;
75960+ current_alloc_state = new_reload_state.oldalloc_ptr;
75961+
75962+ return err;
75963+}
75964+
75965+static int
75966+gracl_init(struct gr_arg *args)
75967+{
75968+ int error = 0;
75969+
75970+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75971+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75972+
75973+ if (init_variables(args, false)) {
75974+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75975+ error = -ENOMEM;
75976+ goto out;
75977+ }
75978+
75979+ error = copy_user_acl(args);
75980+ free_init_variables();
75981+ if (error)
75982+ goto out;
75983+
75984+ error = gr_set_acls(0);
75985+ if (error)
75986+ goto out;
75987+
75988+ gr_enable_rbac_system();
75989+
75990+ return 0;
75991+
75992+out:
75993+ free_variables(false);
75994+ return error;
75995+}
75996+
75997+static int
75998+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75999+ unsigned char **sum)
76000+{
76001+ struct acl_role_label *r;
76002+ struct role_allowed_ip *ipp;
76003+ struct role_transition *trans;
76004+ unsigned int i;
76005+ int found = 0;
76006+ u32 curr_ip = current->signal->curr_ip;
76007+
76008+ current->signal->saved_ip = curr_ip;
76009+
76010+ /* check transition table */
76011+
76012+ for (trans = current->role->transitions; trans; trans = trans->next) {
76013+ if (!strcmp(rolename, trans->rolename)) {
76014+ found = 1;
76015+ break;
76016+ }
76017+ }
76018+
76019+ if (!found)
76020+ return 0;
76021+
76022+ /* handle special roles that do not require authentication
76023+ and check ip */
76024+
76025+ FOR_EACH_ROLE_START(r)
76026+ if (!strcmp(rolename, r->rolename) &&
76027+ (r->roletype & GR_ROLE_SPECIAL)) {
76028+ found = 0;
76029+ if (r->allowed_ips != NULL) {
76030+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
76031+ if ((ntohl(curr_ip) & ipp->netmask) ==
76032+ (ntohl(ipp->addr) & ipp->netmask))
76033+ found = 1;
76034+ }
76035+ } else
76036+ found = 2;
76037+ if (!found)
76038+ return 0;
76039+
76040+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
76041+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
76042+ *salt = NULL;
76043+ *sum = NULL;
76044+ return 1;
76045+ }
76046+ }
76047+ FOR_EACH_ROLE_END(r)
76048+
76049+ for (i = 0; i < polstate->num_sprole_pws; i++) {
76050+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
76051+ *salt = polstate->acl_special_roles[i]->salt;
76052+ *sum = polstate->acl_special_roles[i]->sum;
76053+ return 1;
76054+ }
76055+ }
76056+
76057+ return 0;
76058+}
76059+
76060+int gr_check_secure_terminal(struct task_struct *task)
76061+{
76062+ struct task_struct *p, *p2, *p3;
76063+ struct files_struct *files;
76064+ struct fdtable *fdt;
76065+ struct file *our_file = NULL, *file;
76066+ int i;
76067+
76068+ if (task->signal->tty == NULL)
76069+ return 1;
76070+
76071+ files = get_files_struct(task);
76072+ if (files != NULL) {
76073+ rcu_read_lock();
76074+ fdt = files_fdtable(files);
76075+ for (i=0; i < fdt->max_fds; i++) {
76076+ file = fcheck_files(files, i);
76077+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
76078+ get_file(file);
76079+ our_file = file;
76080+ }
76081+ }
76082+ rcu_read_unlock();
76083+ put_files_struct(files);
76084+ }
76085+
76086+ if (our_file == NULL)
76087+ return 1;
76088+
76089+ read_lock(&tasklist_lock);
76090+ do_each_thread(p2, p) {
76091+ files = get_files_struct(p);
76092+ if (files == NULL ||
76093+ (p->signal && p->signal->tty == task->signal->tty)) {
76094+ if (files != NULL)
76095+ put_files_struct(files);
76096+ continue;
76097+ }
76098+ rcu_read_lock();
76099+ fdt = files_fdtable(files);
76100+ for (i=0; i < fdt->max_fds; i++) {
76101+ file = fcheck_files(files, i);
76102+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
76103+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
76104+ p3 = task;
76105+ while (task_pid_nr(p3) > 0) {
76106+ if (p3 == p)
76107+ break;
76108+ p3 = p3->real_parent;
76109+ }
76110+ if (p3 == p)
76111+ break;
76112+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
76113+ gr_handle_alertkill(p);
76114+ rcu_read_unlock();
76115+ put_files_struct(files);
76116+ read_unlock(&tasklist_lock);
76117+ fput(our_file);
76118+ return 0;
76119+ }
76120+ }
76121+ rcu_read_unlock();
76122+ put_files_struct(files);
76123+ } while_each_thread(p2, p);
76124+ read_unlock(&tasklist_lock);
76125+
76126+ fput(our_file);
76127+ return 1;
76128+}
76129+
76130+ssize_t
76131+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
76132+{
76133+ struct gr_arg_wrapper uwrap;
76134+ unsigned char *sprole_salt = NULL;
76135+ unsigned char *sprole_sum = NULL;
76136+ int error = 0;
76137+ int error2 = 0;
76138+ size_t req_count = 0;
76139+ unsigned char oldmode = 0;
76140+
76141+ mutex_lock(&gr_dev_mutex);
76142+
76143+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
76144+ error = -EPERM;
76145+ goto out;
76146+ }
76147+
76148+#ifdef CONFIG_COMPAT
76149+ pax_open_kernel();
76150+ if (is_compat_task()) {
76151+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
76152+ copy_gr_arg = &copy_gr_arg_compat;
76153+ copy_acl_object_label = &copy_acl_object_label_compat;
76154+ copy_acl_subject_label = &copy_acl_subject_label_compat;
76155+ copy_acl_role_label = &copy_acl_role_label_compat;
76156+ copy_acl_ip_label = &copy_acl_ip_label_compat;
76157+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
76158+ copy_role_transition = &copy_role_transition_compat;
76159+ copy_sprole_pw = &copy_sprole_pw_compat;
76160+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
76161+ copy_pointer_from_array = &copy_pointer_from_array_compat;
76162+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
76163+ } else {
76164+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
76165+ copy_gr_arg = &copy_gr_arg_normal;
76166+ copy_acl_object_label = &copy_acl_object_label_normal;
76167+ copy_acl_subject_label = &copy_acl_subject_label_normal;
76168+ copy_acl_role_label = &copy_acl_role_label_normal;
76169+ copy_acl_ip_label = &copy_acl_ip_label_normal;
76170+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
76171+ copy_role_transition = &copy_role_transition_normal;
76172+ copy_sprole_pw = &copy_sprole_pw_normal;
76173+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
76174+ copy_pointer_from_array = &copy_pointer_from_array_normal;
76175+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
76176+ }
76177+ pax_close_kernel();
76178+#endif
76179+
76180+ req_count = get_gr_arg_wrapper_size();
76181+
76182+ if (count != req_count) {
76183+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
76184+ error = -EINVAL;
76185+ goto out;
76186+ }
76187+
76188+
76189+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
76190+ gr_auth_expires = 0;
76191+ gr_auth_attempts = 0;
76192+ }
76193+
76194+ error = copy_gr_arg_wrapper(buf, &uwrap);
76195+ if (error)
76196+ goto out;
76197+
76198+ error = copy_gr_arg(uwrap.arg, gr_usermode);
76199+ if (error)
76200+ goto out;
76201+
76202+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
76203+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
76204+ time_after(gr_auth_expires, get_seconds())) {
76205+ error = -EBUSY;
76206+ goto out;
76207+ }
76208+
76209+ /* if non-root trying to do anything other than use a special role,
76210+ do not attempt authentication, do not count towards authentication
76211+ locking
76212+ */
76213+
76214+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
76215+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
76216+ gr_is_global_nonroot(current_uid())) {
76217+ error = -EPERM;
76218+ goto out;
76219+ }
76220+
76221+ /* ensure pw and special role name are null terminated */
76222+
76223+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
76224+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
76225+
76226+ /* Okay.
76227+ * We have our enough of the argument structure..(we have yet
76228+ * to copy_from_user the tables themselves) . Copy the tables
76229+ * only if we need them, i.e. for loading operations. */
76230+
76231+ switch (gr_usermode->mode) {
76232+ case GR_STATUS:
76233+ if (gr_acl_is_enabled()) {
76234+ error = 1;
76235+ if (!gr_check_secure_terminal(current))
76236+ error = 3;
76237+ } else
76238+ error = 2;
76239+ goto out;
76240+ case GR_SHUTDOWN:
76241+ if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
76242+ stop_machine(gr_rbac_disable, NULL, NULL);
76243+ free_variables(false);
76244+ memset(gr_usermode, 0, sizeof(struct gr_arg));
76245+ memset(gr_system_salt, 0, GR_SALT_LEN);
76246+ memset(gr_system_sum, 0, GR_SHA_LEN);
76247+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
76248+ } else if (gr_acl_is_enabled()) {
76249+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
76250+ error = -EPERM;
76251+ } else {
76252+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
76253+ error = -EAGAIN;
76254+ }
76255+ break;
76256+ case GR_ENABLE:
76257+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
76258+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
76259+ else {
76260+ if (gr_acl_is_enabled())
76261+ error = -EAGAIN;
76262+ else
76263+ error = error2;
76264+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
76265+ }
76266+ break;
76267+ case GR_OLDRELOAD:
76268+ oldmode = 1;
76269+ case GR_RELOAD:
76270+ if (!gr_acl_is_enabled()) {
76271+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
76272+ error = -EAGAIN;
76273+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
76274+ error2 = gracl_reload(gr_usermode, oldmode);
76275+ if (!error2)
76276+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
76277+ else {
76278+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
76279+ error = error2;
76280+ }
76281+ } else {
76282+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
76283+ error = -EPERM;
76284+ }
76285+ break;
76286+ case GR_SEGVMOD:
76287+ if (unlikely(!gr_acl_is_enabled())) {
76288+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
76289+ error = -EAGAIN;
76290+ break;
76291+ }
76292+
76293+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
76294+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
76295+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
76296+ struct acl_subject_label *segvacl;
76297+ segvacl =
76298+ lookup_acl_subj_label(gr_usermode->segv_inode,
76299+ gr_usermode->segv_device,
76300+ current->role);
76301+ if (segvacl) {
76302+ segvacl->crashes = 0;
76303+ segvacl->expires = 0;
76304+ }
76305+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
76306+ gr_remove_uid(gr_usermode->segv_uid);
76307+ }
76308+ } else {
76309+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
76310+ error = -EPERM;
76311+ }
76312+ break;
76313+ case GR_SPROLE:
76314+ case GR_SPROLEPAM:
76315+ if (unlikely(!gr_acl_is_enabled())) {
76316+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
76317+ error = -EAGAIN;
76318+ break;
76319+ }
76320+
76321+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
76322+ current->role->expires = 0;
76323+ current->role->auth_attempts = 0;
76324+ }
76325+
76326+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
76327+ time_after(current->role->expires, get_seconds())) {
76328+ error = -EBUSY;
76329+ goto out;
76330+ }
76331+
76332+ if (lookup_special_role_auth
76333+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
76334+ && ((!sprole_salt && !sprole_sum)
76335+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
76336+ char *p = "";
76337+ assign_special_role(gr_usermode->sp_role);
76338+ read_lock(&tasklist_lock);
76339+ if (current->real_parent)
76340+ p = current->real_parent->role->rolename;
76341+ read_unlock(&tasklist_lock);
76342+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
76343+ p, acl_sp_role_value);
76344+ } else {
76345+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
76346+ error = -EPERM;
76347+ if(!(current->role->auth_attempts++))
76348+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
76349+
76350+ goto out;
76351+ }
76352+ break;
76353+ case GR_UNSPROLE:
76354+ if (unlikely(!gr_acl_is_enabled())) {
76355+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
76356+ error = -EAGAIN;
76357+ break;
76358+ }
76359+
76360+ if (current->role->roletype & GR_ROLE_SPECIAL) {
76361+ char *p = "";
76362+ int i = 0;
76363+
76364+ read_lock(&tasklist_lock);
76365+ if (current->real_parent) {
76366+ p = current->real_parent->role->rolename;
76367+ i = current->real_parent->acl_role_id;
76368+ }
76369+ read_unlock(&tasklist_lock);
76370+
76371+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
76372+ gr_set_acls(1);
76373+ } else {
76374+ error = -EPERM;
76375+ goto out;
76376+ }
76377+ break;
76378+ default:
76379+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
76380+ error = -EINVAL;
76381+ break;
76382+ }
76383+
76384+ if (error != -EPERM)
76385+ goto out;
76386+
76387+ if(!(gr_auth_attempts++))
76388+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
76389+
76390+ out:
76391+ mutex_unlock(&gr_dev_mutex);
76392+
76393+ if (!error)
76394+ error = req_count;
76395+
76396+ return error;
76397+}
76398+
76399+int
76400+gr_set_acls(const int type)
76401+{
76402+ struct task_struct *task, *task2;
76403+ struct acl_role_label *role = current->role;
76404+ struct acl_subject_label *subj;
76405+ __u16 acl_role_id = current->acl_role_id;
76406+ const struct cred *cred;
76407+ int ret;
76408+
76409+ rcu_read_lock();
76410+ read_lock(&tasklist_lock);
76411+ read_lock(&grsec_exec_file_lock);
76412+ do_each_thread(task2, task) {
76413+ /* check to see if we're called from the exit handler,
76414+ if so, only replace ACLs that have inherited the admin
76415+ ACL */
76416+
76417+ if (type && (task->role != role ||
76418+ task->acl_role_id != acl_role_id))
76419+ continue;
76420+
76421+ task->acl_role_id = 0;
76422+ task->acl_sp_role = 0;
76423+ task->inherited = 0;
76424+
76425+ if (task->exec_file) {
76426+ cred = __task_cred(task);
76427+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
76428+ subj = __gr_get_subject_for_task(polstate, task, NULL);
76429+ if (subj == NULL) {
76430+ ret = -EINVAL;
76431+ read_unlock(&grsec_exec_file_lock);
76432+ read_unlock(&tasklist_lock);
76433+ rcu_read_unlock();
76434+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
76435+ return ret;
76436+ }
76437+ __gr_apply_subject_to_task(polstate, task, subj);
76438+ } else {
76439+ // it's a kernel process
76440+ task->role = polstate->kernel_role;
76441+ task->acl = polstate->kernel_role->root_label;
76442+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
76443+ task->acl->mode &= ~GR_PROCFIND;
76444+#endif
76445+ }
76446+ } while_each_thread(task2, task);
76447+ read_unlock(&grsec_exec_file_lock);
76448+ read_unlock(&tasklist_lock);
76449+ rcu_read_unlock();
76450+
76451+ return 0;
76452+}
76453diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
76454new file mode 100644
76455index 0000000..39645c9
76456--- /dev/null
76457+++ b/grsecurity/gracl_res.c
76458@@ -0,0 +1,68 @@
76459+#include <linux/kernel.h>
76460+#include <linux/sched.h>
76461+#include <linux/gracl.h>
76462+#include <linux/grinternal.h>
76463+
76464+static const char *restab_log[] = {
76465+ [RLIMIT_CPU] = "RLIMIT_CPU",
76466+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
76467+ [RLIMIT_DATA] = "RLIMIT_DATA",
76468+ [RLIMIT_STACK] = "RLIMIT_STACK",
76469+ [RLIMIT_CORE] = "RLIMIT_CORE",
76470+ [RLIMIT_RSS] = "RLIMIT_RSS",
76471+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
76472+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
76473+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
76474+ [RLIMIT_AS] = "RLIMIT_AS",
76475+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
76476+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
76477+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
76478+ [RLIMIT_NICE] = "RLIMIT_NICE",
76479+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
76480+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
76481+ [GR_CRASH_RES] = "RLIMIT_CRASH"
76482+};
76483+
76484+void
76485+gr_log_resource(const struct task_struct *task,
76486+ const int res, const unsigned long wanted, const int gt)
76487+{
76488+ const struct cred *cred;
76489+ unsigned long rlim;
76490+
76491+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
76492+ return;
76493+
76494+ // not yet supported resource
76495+ if (unlikely(!restab_log[res]))
76496+ return;
76497+
76498+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
76499+ rlim = task_rlimit_max(task, res);
76500+ else
76501+ rlim = task_rlimit(task, res);
76502+
76503+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
76504+ return;
76505+
76506+ rcu_read_lock();
76507+ cred = __task_cred(task);
76508+
76509+ if (res == RLIMIT_NPROC &&
76510+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
76511+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
76512+ goto out_rcu_unlock;
76513+ else if (res == RLIMIT_MEMLOCK &&
76514+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
76515+ goto out_rcu_unlock;
76516+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
76517+ goto out_rcu_unlock;
76518+ rcu_read_unlock();
76519+
76520+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
76521+
76522+ return;
76523+out_rcu_unlock:
76524+ rcu_read_unlock();
76525+ return;
76526+}
76527diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
76528new file mode 100644
76529index 0000000..2040e61
76530--- /dev/null
76531+++ b/grsecurity/gracl_segv.c
76532@@ -0,0 +1,313 @@
76533+#include <linux/kernel.h>
76534+#include <linux/mm.h>
76535+#include <asm/uaccess.h>
76536+#include <asm/errno.h>
76537+#include <asm/mman.h>
76538+#include <net/sock.h>
76539+#include <linux/file.h>
76540+#include <linux/fs.h>
76541+#include <linux/net.h>
76542+#include <linux/in.h>
76543+#include <linux/slab.h>
76544+#include <linux/types.h>
76545+#include <linux/sched.h>
76546+#include <linux/timer.h>
76547+#include <linux/gracl.h>
76548+#include <linux/grsecurity.h>
76549+#include <linux/grinternal.h>
76550+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
76551+#include <linux/magic.h>
76552+#include <linux/pagemap.h>
76553+#include "../fs/btrfs/async-thread.h"
76554+#include "../fs/btrfs/ctree.h"
76555+#include "../fs/btrfs/btrfs_inode.h"
76556+#endif
76557+
76558+static struct crash_uid *uid_set;
76559+static unsigned short uid_used;
76560+static DEFINE_SPINLOCK(gr_uid_lock);
76561+extern rwlock_t gr_inode_lock;
76562+extern struct acl_subject_label *
76563+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
76564+ struct acl_role_label *role);
76565+
76566+static inline dev_t __get_dev(const struct dentry *dentry)
76567+{
76568+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
76569+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
76570+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
76571+ else
76572+#endif
76573+ return dentry->d_sb->s_dev;
76574+}
76575+
76576+int
76577+gr_init_uidset(void)
76578+{
76579+ uid_set =
76580+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
76581+ uid_used = 0;
76582+
76583+ return uid_set ? 1 : 0;
76584+}
76585+
76586+void
76587+gr_free_uidset(void)
76588+{
76589+ if (uid_set) {
76590+ struct crash_uid *tmpset;
76591+ spin_lock(&gr_uid_lock);
76592+ tmpset = uid_set;
76593+ uid_set = NULL;
76594+ uid_used = 0;
76595+ spin_unlock(&gr_uid_lock);
76596+ if (tmpset)
76597+ kfree(tmpset);
76598+ }
76599+
76600+ return;
76601+}
76602+
76603+int
76604+gr_find_uid(const uid_t uid)
76605+{
76606+ struct crash_uid *tmp = uid_set;
76607+ uid_t buid;
76608+ int low = 0, high = uid_used - 1, mid;
76609+
76610+ while (high >= low) {
76611+ mid = (low + high) >> 1;
76612+ buid = tmp[mid].uid;
76613+ if (buid == uid)
76614+ return mid;
76615+ if (buid > uid)
76616+ high = mid - 1;
76617+ if (buid < uid)
76618+ low = mid + 1;
76619+ }
76620+
76621+ return -1;
76622+}
76623+
76624+static __inline__ void
76625+gr_insertsort(void)
76626+{
76627+ unsigned short i, j;
76628+ struct crash_uid index;
76629+
76630+ for (i = 1; i < uid_used; i++) {
76631+ index = uid_set[i];
76632+ j = i;
76633+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
76634+ uid_set[j] = uid_set[j - 1];
76635+ j--;
76636+ }
76637+ uid_set[j] = index;
76638+ }
76639+
76640+ return;
76641+}
76642+
76643+static __inline__ void
76644+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
76645+{
76646+ int loc;
76647+ uid_t uid = GR_GLOBAL_UID(kuid);
76648+
76649+ if (uid_used == GR_UIDTABLE_MAX)
76650+ return;
76651+
76652+ loc = gr_find_uid(uid);
76653+
76654+ if (loc >= 0) {
76655+ uid_set[loc].expires = expires;
76656+ return;
76657+ }
76658+
76659+ uid_set[uid_used].uid = uid;
76660+ uid_set[uid_used].expires = expires;
76661+ uid_used++;
76662+
76663+ gr_insertsort();
76664+
76665+ return;
76666+}
76667+
76668+void
76669+gr_remove_uid(const unsigned short loc)
76670+{
76671+ unsigned short i;
76672+
76673+ for (i = loc + 1; i < uid_used; i++)
76674+ uid_set[i - 1] = uid_set[i];
76675+
76676+ uid_used--;
76677+
76678+ return;
76679+}
76680+
76681+int
76682+gr_check_crash_uid(const kuid_t kuid)
76683+{
76684+ int loc;
76685+ int ret = 0;
76686+ uid_t uid;
76687+
76688+ if (unlikely(!gr_acl_is_enabled()))
76689+ return 0;
76690+
76691+ uid = GR_GLOBAL_UID(kuid);
76692+
76693+ spin_lock(&gr_uid_lock);
76694+ loc = gr_find_uid(uid);
76695+
76696+ if (loc < 0)
76697+ goto out_unlock;
76698+
76699+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
76700+ gr_remove_uid(loc);
76701+ else
76702+ ret = 1;
76703+
76704+out_unlock:
76705+ spin_unlock(&gr_uid_lock);
76706+ return ret;
76707+}
76708+
76709+static __inline__ int
76710+proc_is_setxid(const struct cred *cred)
76711+{
76712+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
76713+ !uid_eq(cred->uid, cred->fsuid))
76714+ return 1;
76715+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
76716+ !gid_eq(cred->gid, cred->fsgid))
76717+ return 1;
76718+
76719+ return 0;
76720+}
76721+
76722+extern int gr_fake_force_sig(int sig, struct task_struct *t);
76723+
76724+void
76725+gr_handle_crash(struct task_struct *task, const int sig)
76726+{
76727+ struct acl_subject_label *curr;
76728+ struct task_struct *tsk, *tsk2;
76729+ const struct cred *cred;
76730+ const struct cred *cred2;
76731+
76732+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
76733+ return;
76734+
76735+ if (unlikely(!gr_acl_is_enabled()))
76736+ return;
76737+
76738+ curr = task->acl;
76739+
76740+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
76741+ return;
76742+
76743+ if (time_before_eq(curr->expires, get_seconds())) {
76744+ curr->expires = 0;
76745+ curr->crashes = 0;
76746+ }
76747+
76748+ curr->crashes++;
76749+
76750+ if (!curr->expires)
76751+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
76752+
76753+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76754+ time_after(curr->expires, get_seconds())) {
76755+ rcu_read_lock();
76756+ cred = __task_cred(task);
76757+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
76758+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76759+ spin_lock(&gr_uid_lock);
76760+ gr_insert_uid(cred->uid, curr->expires);
76761+ spin_unlock(&gr_uid_lock);
76762+ curr->expires = 0;
76763+ curr->crashes = 0;
76764+ read_lock(&tasklist_lock);
76765+ do_each_thread(tsk2, tsk) {
76766+ cred2 = __task_cred(tsk);
76767+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
76768+ gr_fake_force_sig(SIGKILL, tsk);
76769+ } while_each_thread(tsk2, tsk);
76770+ read_unlock(&tasklist_lock);
76771+ } else {
76772+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76773+ read_lock(&tasklist_lock);
76774+ read_lock(&grsec_exec_file_lock);
76775+ do_each_thread(tsk2, tsk) {
76776+ if (likely(tsk != task)) {
76777+ // if this thread has the same subject as the one that triggered
76778+ // RES_CRASH and it's the same binary, kill it
76779+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
76780+ gr_fake_force_sig(SIGKILL, tsk);
76781+ }
76782+ } while_each_thread(tsk2, tsk);
76783+ read_unlock(&grsec_exec_file_lock);
76784+ read_unlock(&tasklist_lock);
76785+ }
76786+ rcu_read_unlock();
76787+ }
76788+
76789+ return;
76790+}
76791+
76792+int
76793+gr_check_crash_exec(const struct file *filp)
76794+{
76795+ struct acl_subject_label *curr;
76796+
76797+ if (unlikely(!gr_acl_is_enabled()))
76798+ return 0;
76799+
76800+ read_lock(&gr_inode_lock);
76801+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
76802+ __get_dev(filp->f_path.dentry),
76803+ current->role);
76804+ read_unlock(&gr_inode_lock);
76805+
76806+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
76807+ (!curr->crashes && !curr->expires))
76808+ return 0;
76809+
76810+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76811+ time_after(curr->expires, get_seconds()))
76812+ return 1;
76813+ else if (time_before_eq(curr->expires, get_seconds())) {
76814+ curr->crashes = 0;
76815+ curr->expires = 0;
76816+ }
76817+
76818+ return 0;
76819+}
76820+
76821+void
76822+gr_handle_alertkill(struct task_struct *task)
76823+{
76824+ struct acl_subject_label *curracl;
76825+ __u32 curr_ip;
76826+ struct task_struct *p, *p2;
76827+
76828+ if (unlikely(!gr_acl_is_enabled()))
76829+ return;
76830+
76831+ curracl = task->acl;
76832+ curr_ip = task->signal->curr_ip;
76833+
76834+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
76835+ read_lock(&tasklist_lock);
76836+ do_each_thread(p2, p) {
76837+ if (p->signal->curr_ip == curr_ip)
76838+ gr_fake_force_sig(SIGKILL, p);
76839+ } while_each_thread(p2, p);
76840+ read_unlock(&tasklist_lock);
76841+ } else if (curracl->mode & GR_KILLPROC)
76842+ gr_fake_force_sig(SIGKILL, task);
76843+
76844+ return;
76845+}
76846diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
76847new file mode 100644
76848index 0000000..98011b0
76849--- /dev/null
76850+++ b/grsecurity/gracl_shm.c
76851@@ -0,0 +1,40 @@
76852+#include <linux/kernel.h>
76853+#include <linux/mm.h>
76854+#include <linux/sched.h>
76855+#include <linux/file.h>
76856+#include <linux/ipc.h>
76857+#include <linux/gracl.h>
76858+#include <linux/grsecurity.h>
76859+#include <linux/grinternal.h>
76860+
76861+int
76862+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76863+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
76864+{
76865+ struct task_struct *task;
76866+
76867+ if (!gr_acl_is_enabled())
76868+ return 1;
76869+
76870+ rcu_read_lock();
76871+ read_lock(&tasklist_lock);
76872+
76873+ task = find_task_by_vpid(shm_cprid);
76874+
76875+ if (unlikely(!task))
76876+ task = find_task_by_vpid(shm_lapid);
76877+
76878+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
76879+ (task_pid_nr(task) == shm_lapid)) &&
76880+ (task->acl->mode & GR_PROTSHM) &&
76881+ (task->acl != current->acl))) {
76882+ read_unlock(&tasklist_lock);
76883+ rcu_read_unlock();
76884+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76885+ return 0;
76886+ }
76887+ read_unlock(&tasklist_lock);
76888+ rcu_read_unlock();
76889+
76890+ return 1;
76891+}
76892diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76893new file mode 100644
76894index 0000000..bc0be01
76895--- /dev/null
76896+++ b/grsecurity/grsec_chdir.c
76897@@ -0,0 +1,19 @@
76898+#include <linux/kernel.h>
76899+#include <linux/sched.h>
76900+#include <linux/fs.h>
76901+#include <linux/file.h>
76902+#include <linux/grsecurity.h>
76903+#include <linux/grinternal.h>
76904+
76905+void
76906+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76907+{
76908+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76909+ if ((grsec_enable_chdir && grsec_enable_group &&
76910+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76911+ !grsec_enable_group)) {
76912+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76913+ }
76914+#endif
76915+ return;
76916+}
76917diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76918new file mode 100644
76919index 0000000..baa635c
76920--- /dev/null
76921+++ b/grsecurity/grsec_chroot.c
76922@@ -0,0 +1,387 @@
76923+#include <linux/kernel.h>
76924+#include <linux/module.h>
76925+#include <linux/sched.h>
76926+#include <linux/file.h>
76927+#include <linux/fs.h>
76928+#include <linux/mount.h>
76929+#include <linux/types.h>
76930+#include "../fs/mount.h"
76931+#include <linux/grsecurity.h>
76932+#include <linux/grinternal.h>
76933+
76934+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76935+int gr_init_ran;
76936+#endif
76937+
76938+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76939+{
76940+#ifdef CONFIG_GRKERNSEC
76941+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76942+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76943+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76944+ && gr_init_ran
76945+#endif
76946+ )
76947+ task->gr_is_chrooted = 1;
76948+ else {
76949+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76950+ if (task_pid_nr(task) == 1 && !gr_init_ran)
76951+ gr_init_ran = 1;
76952+#endif
76953+ task->gr_is_chrooted = 0;
76954+ }
76955+
76956+ task->gr_chroot_dentry = path->dentry;
76957+#endif
76958+ return;
76959+}
76960+
76961+void gr_clear_chroot_entries(struct task_struct *task)
76962+{
76963+#ifdef CONFIG_GRKERNSEC
76964+ task->gr_is_chrooted = 0;
76965+ task->gr_chroot_dentry = NULL;
76966+#endif
76967+ return;
76968+}
76969+
76970+int
76971+gr_handle_chroot_unix(const pid_t pid)
76972+{
76973+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76974+ struct task_struct *p;
76975+
76976+ if (unlikely(!grsec_enable_chroot_unix))
76977+ return 1;
76978+
76979+ if (likely(!proc_is_chrooted(current)))
76980+ return 1;
76981+
76982+ rcu_read_lock();
76983+ read_lock(&tasklist_lock);
76984+ p = find_task_by_vpid_unrestricted(pid);
76985+ if (unlikely(p && !have_same_root(current, p))) {
76986+ read_unlock(&tasklist_lock);
76987+ rcu_read_unlock();
76988+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76989+ return 0;
76990+ }
76991+ read_unlock(&tasklist_lock);
76992+ rcu_read_unlock();
76993+#endif
76994+ return 1;
76995+}
76996+
76997+int
76998+gr_handle_chroot_nice(void)
76999+{
77000+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77001+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
77002+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
77003+ return -EPERM;
77004+ }
77005+#endif
77006+ return 0;
77007+}
77008+
77009+int
77010+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
77011+{
77012+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77013+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
77014+ && proc_is_chrooted(current)) {
77015+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
77016+ return -EACCES;
77017+ }
77018+#endif
77019+ return 0;
77020+}
77021+
77022+int
77023+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
77024+{
77025+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77026+ struct task_struct *p;
77027+ int ret = 0;
77028+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
77029+ return ret;
77030+
77031+ read_lock(&tasklist_lock);
77032+ do_each_pid_task(pid, type, p) {
77033+ if (!have_same_root(current, p)) {
77034+ ret = 1;
77035+ goto out;
77036+ }
77037+ } while_each_pid_task(pid, type, p);
77038+out:
77039+ read_unlock(&tasklist_lock);
77040+ return ret;
77041+#endif
77042+ return 0;
77043+}
77044+
77045+int
77046+gr_pid_is_chrooted(struct task_struct *p)
77047+{
77048+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77049+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
77050+ return 0;
77051+
77052+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
77053+ !have_same_root(current, p)) {
77054+ return 1;
77055+ }
77056+#endif
77057+ return 0;
77058+}
77059+
77060+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
77061+
77062+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
77063+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
77064+{
77065+ struct path path, currentroot;
77066+ int ret = 0;
77067+
77068+ path.dentry = (struct dentry *)u_dentry;
77069+ path.mnt = (struct vfsmount *)u_mnt;
77070+ get_fs_root(current->fs, &currentroot);
77071+ if (path_is_under(&path, &currentroot))
77072+ ret = 1;
77073+ path_put(&currentroot);
77074+
77075+ return ret;
77076+}
77077+#endif
77078+
77079+int
77080+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
77081+{
77082+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77083+ if (!grsec_enable_chroot_fchdir)
77084+ return 1;
77085+
77086+ if (!proc_is_chrooted(current))
77087+ return 1;
77088+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
77089+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
77090+ return 0;
77091+ }
77092+#endif
77093+ return 1;
77094+}
77095+
77096+int
77097+gr_chroot_fhandle(void)
77098+{
77099+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77100+ if (!grsec_enable_chroot_fchdir)
77101+ return 1;
77102+
77103+ if (!proc_is_chrooted(current))
77104+ return 1;
77105+ else {
77106+ gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
77107+ return 0;
77108+ }
77109+#endif
77110+ return 1;
77111+}
77112+
77113+int
77114+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77115+ const time_t shm_createtime)
77116+{
77117+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77118+ struct task_struct *p;
77119+ time_t starttime;
77120+
77121+ if (unlikely(!grsec_enable_chroot_shmat))
77122+ return 1;
77123+
77124+ if (likely(!proc_is_chrooted(current)))
77125+ return 1;
77126+
77127+ rcu_read_lock();
77128+ read_lock(&tasklist_lock);
77129+
77130+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
77131+ starttime = p->start_time.tv_sec;
77132+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
77133+ if (have_same_root(current, p)) {
77134+ goto allow;
77135+ } else {
77136+ read_unlock(&tasklist_lock);
77137+ rcu_read_unlock();
77138+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
77139+ return 0;
77140+ }
77141+ }
77142+ /* creator exited, pid reuse, fall through to next check */
77143+ }
77144+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
77145+ if (unlikely(!have_same_root(current, p))) {
77146+ read_unlock(&tasklist_lock);
77147+ rcu_read_unlock();
77148+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
77149+ return 0;
77150+ }
77151+ }
77152+
77153+allow:
77154+ read_unlock(&tasklist_lock);
77155+ rcu_read_unlock();
77156+#endif
77157+ return 1;
77158+}
77159+
77160+void
77161+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
77162+{
77163+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77164+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
77165+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
77166+#endif
77167+ return;
77168+}
77169+
77170+int
77171+gr_handle_chroot_mknod(const struct dentry *dentry,
77172+ const struct vfsmount *mnt, const int mode)
77173+{
77174+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77175+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
77176+ proc_is_chrooted(current)) {
77177+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
77178+ return -EPERM;
77179+ }
77180+#endif
77181+ return 0;
77182+}
77183+
77184+int
77185+gr_handle_chroot_mount(const struct dentry *dentry,
77186+ const struct vfsmount *mnt, const char *dev_name)
77187+{
77188+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77189+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
77190+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
77191+ return -EPERM;
77192+ }
77193+#endif
77194+ return 0;
77195+}
77196+
77197+int
77198+gr_handle_chroot_pivot(void)
77199+{
77200+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77201+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
77202+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
77203+ return -EPERM;
77204+ }
77205+#endif
77206+ return 0;
77207+}
77208+
77209+int
77210+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
77211+{
77212+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77213+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
77214+ !gr_is_outside_chroot(dentry, mnt)) {
77215+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
77216+ return -EPERM;
77217+ }
77218+#endif
77219+ return 0;
77220+}
77221+
77222+extern const char *captab_log[];
77223+extern int captab_log_entries;
77224+
77225+int
77226+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77227+{
77228+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77229+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
77230+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
77231+ if (cap_raised(chroot_caps, cap)) {
77232+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
77233+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
77234+ }
77235+ return 0;
77236+ }
77237+ }
77238+#endif
77239+ return 1;
77240+}
77241+
77242+int
77243+gr_chroot_is_capable(const int cap)
77244+{
77245+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77246+ return gr_task_chroot_is_capable(current, current_cred(), cap);
77247+#endif
77248+ return 1;
77249+}
77250+
77251+int
77252+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
77253+{
77254+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77255+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
77256+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
77257+ if (cap_raised(chroot_caps, cap)) {
77258+ return 0;
77259+ }
77260+ }
77261+#endif
77262+ return 1;
77263+}
77264+
77265+int
77266+gr_chroot_is_capable_nolog(const int cap)
77267+{
77268+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77269+ return gr_task_chroot_is_capable_nolog(current, cap);
77270+#endif
77271+ return 1;
77272+}
77273+
77274+int
77275+gr_handle_chroot_sysctl(const int op)
77276+{
77277+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77278+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
77279+ proc_is_chrooted(current))
77280+ return -EACCES;
77281+#endif
77282+ return 0;
77283+}
77284+
77285+void
77286+gr_handle_chroot_chdir(const struct path *path)
77287+{
77288+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77289+ if (grsec_enable_chroot_chdir)
77290+ set_fs_pwd(current->fs, path);
77291+#endif
77292+ return;
77293+}
77294+
77295+int
77296+gr_handle_chroot_chmod(const struct dentry *dentry,
77297+ const struct vfsmount *mnt, const int mode)
77298+{
77299+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77300+ /* allow chmod +s on directories, but not files */
77301+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
77302+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
77303+ proc_is_chrooted(current)) {
77304+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
77305+ return -EPERM;
77306+ }
77307+#endif
77308+ return 0;
77309+}
77310diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
77311new file mode 100644
77312index 0000000..2d3bcb7
77313--- /dev/null
77314+++ b/grsecurity/grsec_disabled.c
77315@@ -0,0 +1,440 @@
77316+#include <linux/kernel.h>
77317+#include <linux/module.h>
77318+#include <linux/sched.h>
77319+#include <linux/file.h>
77320+#include <linux/fs.h>
77321+#include <linux/kdev_t.h>
77322+#include <linux/net.h>
77323+#include <linux/in.h>
77324+#include <linux/ip.h>
77325+#include <linux/skbuff.h>
77326+#include <linux/sysctl.h>
77327+
77328+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
77329+void
77330+pax_set_initial_flags(struct linux_binprm *bprm)
77331+{
77332+ return;
77333+}
77334+#endif
77335+
77336+#ifdef CONFIG_SYSCTL
77337+__u32
77338+gr_handle_sysctl(const struct ctl_table * table, const int op)
77339+{
77340+ return 0;
77341+}
77342+#endif
77343+
77344+#ifdef CONFIG_TASKSTATS
77345+int gr_is_taskstats_denied(int pid)
77346+{
77347+ return 0;
77348+}
77349+#endif
77350+
77351+int
77352+gr_acl_is_enabled(void)
77353+{
77354+ return 0;
77355+}
77356+
77357+int
77358+gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
77359+{
77360+ return 0;
77361+}
77362+
77363+void
77364+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
77365+{
77366+ return;
77367+}
77368+
77369+int
77370+gr_handle_rawio(const struct inode *inode)
77371+{
77372+ return 0;
77373+}
77374+
77375+void
77376+gr_acl_handle_psacct(struct task_struct *task, const long code)
77377+{
77378+ return;
77379+}
77380+
77381+int
77382+gr_handle_ptrace(struct task_struct *task, const long request)
77383+{
77384+ return 0;
77385+}
77386+
77387+int
77388+gr_handle_proc_ptrace(struct task_struct *task)
77389+{
77390+ return 0;
77391+}
77392+
77393+int
77394+gr_set_acls(const int type)
77395+{
77396+ return 0;
77397+}
77398+
77399+int
77400+gr_check_hidden_task(const struct task_struct *tsk)
77401+{
77402+ return 0;
77403+}
77404+
77405+int
77406+gr_check_protected_task(const struct task_struct *task)
77407+{
77408+ return 0;
77409+}
77410+
77411+int
77412+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
77413+{
77414+ return 0;
77415+}
77416+
77417+void
77418+gr_copy_label(struct task_struct *tsk)
77419+{
77420+ return;
77421+}
77422+
77423+void
77424+gr_set_pax_flags(struct task_struct *task)
77425+{
77426+ return;
77427+}
77428+
77429+int
77430+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
77431+ const int unsafe_share)
77432+{
77433+ return 0;
77434+}
77435+
77436+void
77437+gr_handle_delete(const ino_t ino, const dev_t dev)
77438+{
77439+ return;
77440+}
77441+
77442+void
77443+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
77444+{
77445+ return;
77446+}
77447+
77448+void
77449+gr_handle_crash(struct task_struct *task, const int sig)
77450+{
77451+ return;
77452+}
77453+
77454+int
77455+gr_check_crash_exec(const struct file *filp)
77456+{
77457+ return 0;
77458+}
77459+
77460+int
77461+gr_check_crash_uid(const kuid_t uid)
77462+{
77463+ return 0;
77464+}
77465+
77466+void
77467+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
77468+ struct dentry *old_dentry,
77469+ struct dentry *new_dentry,
77470+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
77471+{
77472+ return;
77473+}
77474+
77475+int
77476+gr_search_socket(const int family, const int type, const int protocol)
77477+{
77478+ return 1;
77479+}
77480+
77481+int
77482+gr_search_connectbind(const int mode, const struct socket *sock,
77483+ const struct sockaddr_in *addr)
77484+{
77485+ return 0;
77486+}
77487+
77488+void
77489+gr_handle_alertkill(struct task_struct *task)
77490+{
77491+ return;
77492+}
77493+
77494+__u32
77495+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
77496+{
77497+ return 1;
77498+}
77499+
77500+__u32
77501+gr_acl_handle_hidden_file(const struct dentry * dentry,
77502+ const struct vfsmount * mnt)
77503+{
77504+ return 1;
77505+}
77506+
77507+__u32
77508+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
77509+ int acc_mode)
77510+{
77511+ return 1;
77512+}
77513+
77514+__u32
77515+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
77516+{
77517+ return 1;
77518+}
77519+
77520+__u32
77521+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
77522+{
77523+ return 1;
77524+}
77525+
77526+int
77527+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
77528+ unsigned int *vm_flags)
77529+{
77530+ return 1;
77531+}
77532+
77533+__u32
77534+gr_acl_handle_truncate(const struct dentry * dentry,
77535+ const struct vfsmount * mnt)
77536+{
77537+ return 1;
77538+}
77539+
77540+__u32
77541+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
77542+{
77543+ return 1;
77544+}
77545+
77546+__u32
77547+gr_acl_handle_access(const struct dentry * dentry,
77548+ const struct vfsmount * mnt, const int fmode)
77549+{
77550+ return 1;
77551+}
77552+
77553+__u32
77554+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
77555+ umode_t *mode)
77556+{
77557+ return 1;
77558+}
77559+
77560+__u32
77561+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
77562+{
77563+ return 1;
77564+}
77565+
77566+__u32
77567+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
77568+{
77569+ return 1;
77570+}
77571+
77572+__u32
77573+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
77574+{
77575+ return 1;
77576+}
77577+
77578+void
77579+grsecurity_init(void)
77580+{
77581+ return;
77582+}
77583+
77584+umode_t gr_acl_umask(void)
77585+{
77586+ return 0;
77587+}
77588+
77589+__u32
77590+gr_acl_handle_mknod(const struct dentry * new_dentry,
77591+ const struct dentry * parent_dentry,
77592+ const struct vfsmount * parent_mnt,
77593+ const int mode)
77594+{
77595+ return 1;
77596+}
77597+
77598+__u32
77599+gr_acl_handle_mkdir(const struct dentry * new_dentry,
77600+ const struct dentry * parent_dentry,
77601+ const struct vfsmount * parent_mnt)
77602+{
77603+ return 1;
77604+}
77605+
77606+__u32
77607+gr_acl_handle_symlink(const struct dentry * new_dentry,
77608+ const struct dentry * parent_dentry,
77609+ const struct vfsmount * parent_mnt, const struct filename *from)
77610+{
77611+ return 1;
77612+}
77613+
77614+__u32
77615+gr_acl_handle_link(const struct dentry * new_dentry,
77616+ const struct dentry * parent_dentry,
77617+ const struct vfsmount * parent_mnt,
77618+ const struct dentry * old_dentry,
77619+ const struct vfsmount * old_mnt, const struct filename *to)
77620+{
77621+ return 1;
77622+}
77623+
77624+int
77625+gr_acl_handle_rename(const struct dentry *new_dentry,
77626+ const struct dentry *parent_dentry,
77627+ const struct vfsmount *parent_mnt,
77628+ const struct dentry *old_dentry,
77629+ const struct inode *old_parent_inode,
77630+ const struct vfsmount *old_mnt, const struct filename *newname,
77631+ unsigned int flags)
77632+{
77633+ return 0;
77634+}
77635+
77636+int
77637+gr_acl_handle_filldir(const struct file *file, const char *name,
77638+ const int namelen, const ino_t ino)
77639+{
77640+ return 1;
77641+}
77642+
77643+int
77644+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77645+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
77646+{
77647+ return 1;
77648+}
77649+
77650+int
77651+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
77652+{
77653+ return 0;
77654+}
77655+
77656+int
77657+gr_search_accept(const struct socket *sock)
77658+{
77659+ return 0;
77660+}
77661+
77662+int
77663+gr_search_listen(const struct socket *sock)
77664+{
77665+ return 0;
77666+}
77667+
77668+int
77669+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
77670+{
77671+ return 0;
77672+}
77673+
77674+__u32
77675+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
77676+{
77677+ return 1;
77678+}
77679+
77680+__u32
77681+gr_acl_handle_creat(const struct dentry * dentry,
77682+ const struct dentry * p_dentry,
77683+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
77684+ const int imode)
77685+{
77686+ return 1;
77687+}
77688+
77689+void
77690+gr_acl_handle_exit(void)
77691+{
77692+ return;
77693+}
77694+
77695+int
77696+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
77697+{
77698+ return 1;
77699+}
77700+
77701+void
77702+gr_set_role_label(const kuid_t uid, const kgid_t gid)
77703+{
77704+ return;
77705+}
77706+
77707+int
77708+gr_acl_handle_procpidmem(const struct task_struct *task)
77709+{
77710+ return 0;
77711+}
77712+
77713+int
77714+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
77715+{
77716+ return 0;
77717+}
77718+
77719+int
77720+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
77721+{
77722+ return 0;
77723+}
77724+
77725+int
77726+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
77727+{
77728+ return 0;
77729+}
77730+
77731+int
77732+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
77733+{
77734+ return 0;
77735+}
77736+
77737+int gr_acl_enable_at_secure(void)
77738+{
77739+ return 0;
77740+}
77741+
77742+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
77743+{
77744+ return dentry->d_sb->s_dev;
77745+}
77746+
77747+void gr_put_exec_file(struct task_struct *task)
77748+{
77749+ return;
77750+}
77751+
77752+#ifdef CONFIG_SECURITY
77753+EXPORT_SYMBOL_GPL(gr_check_user_change);
77754+EXPORT_SYMBOL_GPL(gr_check_group_change);
77755+#endif
77756diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
77757new file mode 100644
77758index 0000000..14638ff
77759--- /dev/null
77760+++ b/grsecurity/grsec_exec.c
77761@@ -0,0 +1,188 @@
77762+#include <linux/kernel.h>
77763+#include <linux/sched.h>
77764+#include <linux/file.h>
77765+#include <linux/binfmts.h>
77766+#include <linux/fs.h>
77767+#include <linux/types.h>
77768+#include <linux/grdefs.h>
77769+#include <linux/grsecurity.h>
77770+#include <linux/grinternal.h>
77771+#include <linux/capability.h>
77772+#include <linux/module.h>
77773+#include <linux/compat.h>
77774+
77775+#include <asm/uaccess.h>
77776+
77777+#ifdef CONFIG_GRKERNSEC_EXECLOG
77778+static char gr_exec_arg_buf[132];
77779+static DEFINE_MUTEX(gr_exec_arg_mutex);
77780+#endif
77781+
77782+struct user_arg_ptr {
77783+#ifdef CONFIG_COMPAT
77784+ bool is_compat;
77785+#endif
77786+ union {
77787+ const char __user *const __user *native;
77788+#ifdef CONFIG_COMPAT
77789+ const compat_uptr_t __user *compat;
77790+#endif
77791+ } ptr;
77792+};
77793+
77794+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
77795+
77796+void
77797+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
77798+{
77799+#ifdef CONFIG_GRKERNSEC_EXECLOG
77800+ char *grarg = gr_exec_arg_buf;
77801+ unsigned int i, x, execlen = 0;
77802+ char c;
77803+
77804+ if (!((grsec_enable_execlog && grsec_enable_group &&
77805+ in_group_p(grsec_audit_gid))
77806+ || (grsec_enable_execlog && !grsec_enable_group)))
77807+ return;
77808+
77809+ mutex_lock(&gr_exec_arg_mutex);
77810+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
77811+
77812+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
77813+ const char __user *p;
77814+ unsigned int len;
77815+
77816+ p = get_user_arg_ptr(argv, i);
77817+ if (IS_ERR(p))
77818+ goto log;
77819+
77820+ len = strnlen_user(p, 128 - execlen);
77821+ if (len > 128 - execlen)
77822+ len = 128 - execlen;
77823+ else if (len > 0)
77824+ len--;
77825+ if (copy_from_user(grarg + execlen, p, len))
77826+ goto log;
77827+
77828+ /* rewrite unprintable characters */
77829+ for (x = 0; x < len; x++) {
77830+ c = *(grarg + execlen + x);
77831+ if (c < 32 || c > 126)
77832+ *(grarg + execlen + x) = ' ';
77833+ }
77834+
77835+ execlen += len;
77836+ *(grarg + execlen) = ' ';
77837+ *(grarg + execlen + 1) = '\0';
77838+ execlen++;
77839+ }
77840+
77841+ log:
77842+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
77843+ bprm->file->f_path.mnt, grarg);
77844+ mutex_unlock(&gr_exec_arg_mutex);
77845+#endif
77846+ return;
77847+}
77848+
77849+#ifdef CONFIG_GRKERNSEC
77850+extern int gr_acl_is_capable(const int cap);
77851+extern int gr_acl_is_capable_nolog(const int cap);
77852+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77853+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
77854+extern int gr_chroot_is_capable(const int cap);
77855+extern int gr_chroot_is_capable_nolog(const int cap);
77856+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77857+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
77858+#endif
77859+
77860+const char *captab_log[] = {
77861+ "CAP_CHOWN",
77862+ "CAP_DAC_OVERRIDE",
77863+ "CAP_DAC_READ_SEARCH",
77864+ "CAP_FOWNER",
77865+ "CAP_FSETID",
77866+ "CAP_KILL",
77867+ "CAP_SETGID",
77868+ "CAP_SETUID",
77869+ "CAP_SETPCAP",
77870+ "CAP_LINUX_IMMUTABLE",
77871+ "CAP_NET_BIND_SERVICE",
77872+ "CAP_NET_BROADCAST",
77873+ "CAP_NET_ADMIN",
77874+ "CAP_NET_RAW",
77875+ "CAP_IPC_LOCK",
77876+ "CAP_IPC_OWNER",
77877+ "CAP_SYS_MODULE",
77878+ "CAP_SYS_RAWIO",
77879+ "CAP_SYS_CHROOT",
77880+ "CAP_SYS_PTRACE",
77881+ "CAP_SYS_PACCT",
77882+ "CAP_SYS_ADMIN",
77883+ "CAP_SYS_BOOT",
77884+ "CAP_SYS_NICE",
77885+ "CAP_SYS_RESOURCE",
77886+ "CAP_SYS_TIME",
77887+ "CAP_SYS_TTY_CONFIG",
77888+ "CAP_MKNOD",
77889+ "CAP_LEASE",
77890+ "CAP_AUDIT_WRITE",
77891+ "CAP_AUDIT_CONTROL",
77892+ "CAP_SETFCAP",
77893+ "CAP_MAC_OVERRIDE",
77894+ "CAP_MAC_ADMIN",
77895+ "CAP_SYSLOG",
77896+ "CAP_WAKE_ALARM",
77897+ "CAP_BLOCK_SUSPEND"
77898+};
77899+
77900+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77901+
77902+int gr_is_capable(const int cap)
77903+{
77904+#ifdef CONFIG_GRKERNSEC
77905+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77906+ return 1;
77907+ return 0;
77908+#else
77909+ return 1;
77910+#endif
77911+}
77912+
77913+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77914+{
77915+#ifdef CONFIG_GRKERNSEC
77916+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77917+ return 1;
77918+ return 0;
77919+#else
77920+ return 1;
77921+#endif
77922+}
77923+
77924+int gr_is_capable_nolog(const int cap)
77925+{
77926+#ifdef CONFIG_GRKERNSEC
77927+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77928+ return 1;
77929+ return 0;
77930+#else
77931+ return 1;
77932+#endif
77933+}
77934+
77935+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77936+{
77937+#ifdef CONFIG_GRKERNSEC
77938+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77939+ return 1;
77940+ return 0;
77941+#else
77942+ return 1;
77943+#endif
77944+}
77945+
77946+EXPORT_SYMBOL_GPL(gr_is_capable);
77947+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77948+EXPORT_SYMBOL_GPL(gr_task_is_capable);
77949+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77950diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77951new file mode 100644
77952index 0000000..06cc6ea
77953--- /dev/null
77954+++ b/grsecurity/grsec_fifo.c
77955@@ -0,0 +1,24 @@
77956+#include <linux/kernel.h>
77957+#include <linux/sched.h>
77958+#include <linux/fs.h>
77959+#include <linux/file.h>
77960+#include <linux/grinternal.h>
77961+
77962+int
77963+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77964+ const struct dentry *dir, const int flag, const int acc_mode)
77965+{
77966+#ifdef CONFIG_GRKERNSEC_FIFO
77967+ const struct cred *cred = current_cred();
77968+
77969+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77970+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77971+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77972+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77973+ if (!inode_permission(dentry->d_inode, acc_mode))
77974+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, GR_GLOBAL_UID(dentry->d_inode->i_uid), GR_GLOBAL_GID(dentry->d_inode->i_gid));
77975+ return -EACCES;
77976+ }
77977+#endif
77978+ return 0;
77979+}
77980diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77981new file mode 100644
77982index 0000000..8ca18bf
77983--- /dev/null
77984+++ b/grsecurity/grsec_fork.c
77985@@ -0,0 +1,23 @@
77986+#include <linux/kernel.h>
77987+#include <linux/sched.h>
77988+#include <linux/grsecurity.h>
77989+#include <linux/grinternal.h>
77990+#include <linux/errno.h>
77991+
77992+void
77993+gr_log_forkfail(const int retval)
77994+{
77995+#ifdef CONFIG_GRKERNSEC_FORKFAIL
77996+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77997+ switch (retval) {
77998+ case -EAGAIN:
77999+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
78000+ break;
78001+ case -ENOMEM:
78002+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
78003+ break;
78004+ }
78005+ }
78006+#endif
78007+ return;
78008+}
78009diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
78010new file mode 100644
78011index 0000000..b7cb191
78012--- /dev/null
78013+++ b/grsecurity/grsec_init.c
78014@@ -0,0 +1,286 @@
78015+#include <linux/kernel.h>
78016+#include <linux/sched.h>
78017+#include <linux/mm.h>
78018+#include <linux/gracl.h>
78019+#include <linux/slab.h>
78020+#include <linux/vmalloc.h>
78021+#include <linux/percpu.h>
78022+#include <linux/module.h>
78023+
78024+int grsec_enable_ptrace_readexec;
78025+int grsec_enable_setxid;
78026+int grsec_enable_symlinkown;
78027+kgid_t grsec_symlinkown_gid;
78028+int grsec_enable_brute;
78029+int grsec_enable_link;
78030+int grsec_enable_dmesg;
78031+int grsec_enable_harden_ptrace;
78032+int grsec_enable_harden_ipc;
78033+int grsec_enable_fifo;
78034+int grsec_enable_execlog;
78035+int grsec_enable_signal;
78036+int grsec_enable_forkfail;
78037+int grsec_enable_audit_ptrace;
78038+int grsec_enable_time;
78039+int grsec_enable_group;
78040+kgid_t grsec_audit_gid;
78041+int grsec_enable_chdir;
78042+int grsec_enable_mount;
78043+int grsec_enable_rofs;
78044+int grsec_deny_new_usb;
78045+int grsec_enable_chroot_findtask;
78046+int grsec_enable_chroot_mount;
78047+int grsec_enable_chroot_shmat;
78048+int grsec_enable_chroot_fchdir;
78049+int grsec_enable_chroot_double;
78050+int grsec_enable_chroot_pivot;
78051+int grsec_enable_chroot_chdir;
78052+int grsec_enable_chroot_chmod;
78053+int grsec_enable_chroot_mknod;
78054+int grsec_enable_chroot_nice;
78055+int grsec_enable_chroot_execlog;
78056+int grsec_enable_chroot_caps;
78057+int grsec_enable_chroot_sysctl;
78058+int grsec_enable_chroot_unix;
78059+int grsec_enable_tpe;
78060+kgid_t grsec_tpe_gid;
78061+int grsec_enable_blackhole;
78062+#ifdef CONFIG_IPV6_MODULE
78063+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
78064+#endif
78065+int grsec_lastack_retries;
78066+int grsec_enable_tpe_all;
78067+int grsec_enable_tpe_invert;
78068+int grsec_enable_socket_all;
78069+kgid_t grsec_socket_all_gid;
78070+int grsec_enable_socket_client;
78071+kgid_t grsec_socket_client_gid;
78072+int grsec_enable_socket_server;
78073+kgid_t grsec_socket_server_gid;
78074+int grsec_resource_logging;
78075+int grsec_disable_privio;
78076+int grsec_enable_log_rwxmaps;
78077+int grsec_lock;
78078+
78079+DEFINE_SPINLOCK(grsec_alert_lock);
78080+unsigned long grsec_alert_wtime = 0;
78081+unsigned long grsec_alert_fyet = 0;
78082+
78083+DEFINE_SPINLOCK(grsec_audit_lock);
78084+
78085+DEFINE_RWLOCK(grsec_exec_file_lock);
78086+
78087+char *gr_shared_page[4];
78088+
78089+char *gr_alert_log_fmt;
78090+char *gr_audit_log_fmt;
78091+char *gr_alert_log_buf;
78092+char *gr_audit_log_buf;
78093+
78094+extern struct gr_arg *gr_usermode;
78095+extern unsigned char *gr_system_salt;
78096+extern unsigned char *gr_system_sum;
78097+
78098+void __init
78099+grsecurity_init(void)
78100+{
78101+ int j;
78102+ /* create the per-cpu shared pages */
78103+
78104+#ifdef CONFIG_X86
78105+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
78106+#endif
78107+
78108+ for (j = 0; j < 4; j++) {
78109+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
78110+ if (gr_shared_page[j] == NULL) {
78111+ panic("Unable to allocate grsecurity shared page");
78112+ return;
78113+ }
78114+ }
78115+
78116+ /* allocate log buffers */
78117+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
78118+ if (!gr_alert_log_fmt) {
78119+ panic("Unable to allocate grsecurity alert log format buffer");
78120+ return;
78121+ }
78122+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
78123+ if (!gr_audit_log_fmt) {
78124+ panic("Unable to allocate grsecurity audit log format buffer");
78125+ return;
78126+ }
78127+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
78128+ if (!gr_alert_log_buf) {
78129+ panic("Unable to allocate grsecurity alert log buffer");
78130+ return;
78131+ }
78132+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
78133+ if (!gr_audit_log_buf) {
78134+ panic("Unable to allocate grsecurity audit log buffer");
78135+ return;
78136+ }
78137+
78138+ /* allocate memory for authentication structure */
78139+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
78140+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
78141+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
78142+
78143+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
78144+ panic("Unable to allocate grsecurity authentication structure");
78145+ return;
78146+ }
78147+
78148+#ifdef CONFIG_GRKERNSEC_IO
78149+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
78150+ grsec_disable_privio = 1;
78151+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
78152+ grsec_disable_privio = 1;
78153+#else
78154+ grsec_disable_privio = 0;
78155+#endif
78156+#endif
78157+
78158+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78159+ /* for backward compatibility, tpe_invert always defaults to on if
78160+ enabled in the kernel
78161+ */
78162+ grsec_enable_tpe_invert = 1;
78163+#endif
78164+
78165+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
78166+#ifndef CONFIG_GRKERNSEC_SYSCTL
78167+ grsec_lock = 1;
78168+#endif
78169+
78170+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78171+ grsec_enable_log_rwxmaps = 1;
78172+#endif
78173+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
78174+ grsec_enable_group = 1;
78175+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
78176+#endif
78177+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78178+ grsec_enable_ptrace_readexec = 1;
78179+#endif
78180+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
78181+ grsec_enable_chdir = 1;
78182+#endif
78183+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
78184+ grsec_enable_harden_ptrace = 1;
78185+#endif
78186+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
78187+ grsec_enable_harden_ipc = 1;
78188+#endif
78189+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78190+ grsec_enable_mount = 1;
78191+#endif
78192+#ifdef CONFIG_GRKERNSEC_LINK
78193+ grsec_enable_link = 1;
78194+#endif
78195+#ifdef CONFIG_GRKERNSEC_BRUTE
78196+ grsec_enable_brute = 1;
78197+#endif
78198+#ifdef CONFIG_GRKERNSEC_DMESG
78199+ grsec_enable_dmesg = 1;
78200+#endif
78201+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78202+ grsec_enable_blackhole = 1;
78203+ grsec_lastack_retries = 4;
78204+#endif
78205+#ifdef CONFIG_GRKERNSEC_FIFO
78206+ grsec_enable_fifo = 1;
78207+#endif
78208+#ifdef CONFIG_GRKERNSEC_EXECLOG
78209+ grsec_enable_execlog = 1;
78210+#endif
78211+#ifdef CONFIG_GRKERNSEC_SETXID
78212+ grsec_enable_setxid = 1;
78213+#endif
78214+#ifdef CONFIG_GRKERNSEC_SIGNAL
78215+ grsec_enable_signal = 1;
78216+#endif
78217+#ifdef CONFIG_GRKERNSEC_FORKFAIL
78218+ grsec_enable_forkfail = 1;
78219+#endif
78220+#ifdef CONFIG_GRKERNSEC_TIME
78221+ grsec_enable_time = 1;
78222+#endif
78223+#ifdef CONFIG_GRKERNSEC_RESLOG
78224+ grsec_resource_logging = 1;
78225+#endif
78226+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78227+ grsec_enable_chroot_findtask = 1;
78228+#endif
78229+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78230+ grsec_enable_chroot_unix = 1;
78231+#endif
78232+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78233+ grsec_enable_chroot_mount = 1;
78234+#endif
78235+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78236+ grsec_enable_chroot_fchdir = 1;
78237+#endif
78238+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78239+ grsec_enable_chroot_shmat = 1;
78240+#endif
78241+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78242+ grsec_enable_audit_ptrace = 1;
78243+#endif
78244+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78245+ grsec_enable_chroot_double = 1;
78246+#endif
78247+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78248+ grsec_enable_chroot_pivot = 1;
78249+#endif
78250+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78251+ grsec_enable_chroot_chdir = 1;
78252+#endif
78253+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78254+ grsec_enable_chroot_chmod = 1;
78255+#endif
78256+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
78257+ grsec_enable_chroot_mknod = 1;
78258+#endif
78259+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
78260+ grsec_enable_chroot_nice = 1;
78261+#endif
78262+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
78263+ grsec_enable_chroot_execlog = 1;
78264+#endif
78265+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
78266+ grsec_enable_chroot_caps = 1;
78267+#endif
78268+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
78269+ grsec_enable_chroot_sysctl = 1;
78270+#endif
78271+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78272+ grsec_enable_symlinkown = 1;
78273+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
78274+#endif
78275+#ifdef CONFIG_GRKERNSEC_TPE
78276+ grsec_enable_tpe = 1;
78277+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
78278+#ifdef CONFIG_GRKERNSEC_TPE_ALL
78279+ grsec_enable_tpe_all = 1;
78280+#endif
78281+#endif
78282+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78283+ grsec_enable_socket_all = 1;
78284+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
78285+#endif
78286+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78287+ grsec_enable_socket_client = 1;
78288+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
78289+#endif
78290+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78291+ grsec_enable_socket_server = 1;
78292+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
78293+#endif
78294+#endif
78295+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
78296+ grsec_deny_new_usb = 1;
78297+#endif
78298+
78299+ return;
78300+}
78301diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
78302new file mode 100644
78303index 0000000..1773300
78304--- /dev/null
78305+++ b/grsecurity/grsec_ipc.c
78306@@ -0,0 +1,48 @@
78307+#include <linux/kernel.h>
78308+#include <linux/mm.h>
78309+#include <linux/sched.h>
78310+#include <linux/file.h>
78311+#include <linux/ipc.h>
78312+#include <linux/ipc_namespace.h>
78313+#include <linux/grsecurity.h>
78314+#include <linux/grinternal.h>
78315+
78316+int
78317+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
78318+{
78319+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
78320+ int write;
78321+ int orig_granted_mode;
78322+ kuid_t euid;
78323+ kgid_t egid;
78324+
78325+ if (!grsec_enable_harden_ipc)
78326+ return 1;
78327+
78328+ euid = current_euid();
78329+ egid = current_egid();
78330+
78331+ write = requested_mode & 00002;
78332+ orig_granted_mode = ipcp->mode;
78333+
78334+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
78335+ orig_granted_mode >>= 6;
78336+ else {
78337+ /* if likely wrong permissions, lock to user */
78338+ if (orig_granted_mode & 0007)
78339+ orig_granted_mode = 0;
78340+ /* otherwise do a egid-only check */
78341+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
78342+ orig_granted_mode >>= 3;
78343+ /* otherwise, no access */
78344+ else
78345+ orig_granted_mode = 0;
78346+ }
78347+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
78348+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
78349+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
78350+ return 0;
78351+ }
78352+#endif
78353+ return 1;
78354+}
78355diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
78356new file mode 100644
78357index 0000000..5e05e20
78358--- /dev/null
78359+++ b/grsecurity/grsec_link.c
78360@@ -0,0 +1,58 @@
78361+#include <linux/kernel.h>
78362+#include <linux/sched.h>
78363+#include <linux/fs.h>
78364+#include <linux/file.h>
78365+#include <linux/grinternal.h>
78366+
78367+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
78368+{
78369+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78370+ const struct inode *link_inode = link->dentry->d_inode;
78371+
78372+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
78373+ /* ignore root-owned links, e.g. /proc/self */
78374+ gr_is_global_nonroot(link_inode->i_uid) && target &&
78375+ !uid_eq(link_inode->i_uid, target->i_uid)) {
78376+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
78377+ return 1;
78378+ }
78379+#endif
78380+ return 0;
78381+}
78382+
78383+int
78384+gr_handle_follow_link(const struct inode *parent,
78385+ const struct inode *inode,
78386+ const struct dentry *dentry, const struct vfsmount *mnt)
78387+{
78388+#ifdef CONFIG_GRKERNSEC_LINK
78389+ const struct cred *cred = current_cred();
78390+
78391+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
78392+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
78393+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
78394+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
78395+ return -EACCES;
78396+ }
78397+#endif
78398+ return 0;
78399+}
78400+
78401+int
78402+gr_handle_hardlink(const struct dentry *dentry,
78403+ const struct vfsmount *mnt,
78404+ struct inode *inode, const int mode, const struct filename *to)
78405+{
78406+#ifdef CONFIG_GRKERNSEC_LINK
78407+ const struct cred *cred = current_cred();
78408+
78409+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
78410+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
78411+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
78412+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
78413+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
78414+ return -EPERM;
78415+ }
78416+#endif
78417+ return 0;
78418+}
78419diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
78420new file mode 100644
78421index 0000000..dbe0a6b
78422--- /dev/null
78423+++ b/grsecurity/grsec_log.c
78424@@ -0,0 +1,341 @@
78425+#include <linux/kernel.h>
78426+#include <linux/sched.h>
78427+#include <linux/file.h>
78428+#include <linux/tty.h>
78429+#include <linux/fs.h>
78430+#include <linux/mm.h>
78431+#include <linux/grinternal.h>
78432+
78433+#ifdef CONFIG_TREE_PREEMPT_RCU
78434+#define DISABLE_PREEMPT() preempt_disable()
78435+#define ENABLE_PREEMPT() preempt_enable()
78436+#else
78437+#define DISABLE_PREEMPT()
78438+#define ENABLE_PREEMPT()
78439+#endif
78440+
78441+#define BEGIN_LOCKS(x) \
78442+ DISABLE_PREEMPT(); \
78443+ rcu_read_lock(); \
78444+ read_lock(&tasklist_lock); \
78445+ read_lock(&grsec_exec_file_lock); \
78446+ if (x != GR_DO_AUDIT) \
78447+ spin_lock(&grsec_alert_lock); \
78448+ else \
78449+ spin_lock(&grsec_audit_lock)
78450+
78451+#define END_LOCKS(x) \
78452+ if (x != GR_DO_AUDIT) \
78453+ spin_unlock(&grsec_alert_lock); \
78454+ else \
78455+ spin_unlock(&grsec_audit_lock); \
78456+ read_unlock(&grsec_exec_file_lock); \
78457+ read_unlock(&tasklist_lock); \
78458+ rcu_read_unlock(); \
78459+ ENABLE_PREEMPT(); \
78460+ if (x == GR_DONT_AUDIT) \
78461+ gr_handle_alertkill(current)
78462+
78463+enum {
78464+ FLOODING,
78465+ NO_FLOODING
78466+};
78467+
78468+extern char *gr_alert_log_fmt;
78469+extern char *gr_audit_log_fmt;
78470+extern char *gr_alert_log_buf;
78471+extern char *gr_audit_log_buf;
78472+
78473+static int gr_log_start(int audit)
78474+{
78475+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
78476+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
78477+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78478+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
78479+ unsigned long curr_secs = get_seconds();
78480+
78481+ if (audit == GR_DO_AUDIT)
78482+ goto set_fmt;
78483+
78484+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
78485+ grsec_alert_wtime = curr_secs;
78486+ grsec_alert_fyet = 0;
78487+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
78488+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
78489+ grsec_alert_fyet++;
78490+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
78491+ grsec_alert_wtime = curr_secs;
78492+ grsec_alert_fyet++;
78493+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
78494+ return FLOODING;
78495+ }
78496+ else return FLOODING;
78497+
78498+set_fmt:
78499+#endif
78500+ memset(buf, 0, PAGE_SIZE);
78501+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
78502+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
78503+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
78504+ } else if (current->signal->curr_ip) {
78505+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
78506+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
78507+ } else if (gr_acl_is_enabled()) {
78508+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
78509+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
78510+ } else {
78511+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
78512+ strcpy(buf, fmt);
78513+ }
78514+
78515+ return NO_FLOODING;
78516+}
78517+
78518+static void gr_log_middle(int audit, const char *msg, va_list ap)
78519+ __attribute__ ((format (printf, 2, 0)));
78520+
78521+static void gr_log_middle(int audit, const char *msg, va_list ap)
78522+{
78523+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78524+ unsigned int len = strlen(buf);
78525+
78526+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
78527+
78528+ return;
78529+}
78530+
78531+static void gr_log_middle_varargs(int audit, const char *msg, ...)
78532+ __attribute__ ((format (printf, 2, 3)));
78533+
78534+static void gr_log_middle_varargs(int audit, const char *msg, ...)
78535+{
78536+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78537+ unsigned int len = strlen(buf);
78538+ va_list ap;
78539+
78540+ va_start(ap, msg);
78541+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
78542+ va_end(ap);
78543+
78544+ return;
78545+}
78546+
78547+static void gr_log_end(int audit, int append_default)
78548+{
78549+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78550+ if (append_default) {
78551+ struct task_struct *task = current;
78552+ struct task_struct *parent = task->real_parent;
78553+ const struct cred *cred = __task_cred(task);
78554+ const struct cred *pcred = __task_cred(parent);
78555+ unsigned int len = strlen(buf);
78556+
78557+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
78558+ }
78559+
78560+ printk("%s\n", buf);
78561+
78562+ return;
78563+}
78564+
78565+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
78566+{
78567+ int logtype;
78568+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
78569+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
78570+ void *voidptr = NULL;
78571+ int num1 = 0, num2 = 0;
78572+ unsigned long ulong1 = 0, ulong2 = 0;
78573+ struct dentry *dentry = NULL;
78574+ struct vfsmount *mnt = NULL;
78575+ struct file *file = NULL;
78576+ struct task_struct *task = NULL;
78577+ struct vm_area_struct *vma = NULL;
78578+ const struct cred *cred, *pcred;
78579+ va_list ap;
78580+
78581+ BEGIN_LOCKS(audit);
78582+ logtype = gr_log_start(audit);
78583+ if (logtype == FLOODING) {
78584+ END_LOCKS(audit);
78585+ return;
78586+ }
78587+ va_start(ap, argtypes);
78588+ switch (argtypes) {
78589+ case GR_TTYSNIFF:
78590+ task = va_arg(ap, struct task_struct *);
78591+ gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task_pid_nr(task), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent));
78592+ break;
78593+ case GR_SYSCTL_HIDDEN:
78594+ str1 = va_arg(ap, char *);
78595+ gr_log_middle_varargs(audit, msg, result, str1);
78596+ break;
78597+ case GR_RBAC:
78598+ dentry = va_arg(ap, struct dentry *);
78599+ mnt = va_arg(ap, struct vfsmount *);
78600+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
78601+ break;
78602+ case GR_RBAC_STR:
78603+ dentry = va_arg(ap, struct dentry *);
78604+ mnt = va_arg(ap, struct vfsmount *);
78605+ str1 = va_arg(ap, char *);
78606+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
78607+ break;
78608+ case GR_STR_RBAC:
78609+ str1 = va_arg(ap, char *);
78610+ dentry = va_arg(ap, struct dentry *);
78611+ mnt = va_arg(ap, struct vfsmount *);
78612+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
78613+ break;
78614+ case GR_RBAC_MODE2:
78615+ dentry = va_arg(ap, struct dentry *);
78616+ mnt = va_arg(ap, struct vfsmount *);
78617+ str1 = va_arg(ap, char *);
78618+ str2 = va_arg(ap, char *);
78619+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
78620+ break;
78621+ case GR_RBAC_MODE3:
78622+ dentry = va_arg(ap, struct dentry *);
78623+ mnt = va_arg(ap, struct vfsmount *);
78624+ str1 = va_arg(ap, char *);
78625+ str2 = va_arg(ap, char *);
78626+ str3 = va_arg(ap, char *);
78627+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
78628+ break;
78629+ case GR_FILENAME:
78630+ dentry = va_arg(ap, struct dentry *);
78631+ mnt = va_arg(ap, struct vfsmount *);
78632+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
78633+ break;
78634+ case GR_STR_FILENAME:
78635+ str1 = va_arg(ap, char *);
78636+ dentry = va_arg(ap, struct dentry *);
78637+ mnt = va_arg(ap, struct vfsmount *);
78638+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
78639+ break;
78640+ case GR_FILENAME_STR:
78641+ dentry = va_arg(ap, struct dentry *);
78642+ mnt = va_arg(ap, struct vfsmount *);
78643+ str1 = va_arg(ap, char *);
78644+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
78645+ break;
78646+ case GR_FILENAME_TWO_INT:
78647+ dentry = va_arg(ap, struct dentry *);
78648+ mnt = va_arg(ap, struct vfsmount *);
78649+ num1 = va_arg(ap, int);
78650+ num2 = va_arg(ap, int);
78651+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
78652+ break;
78653+ case GR_FILENAME_TWO_INT_STR:
78654+ dentry = va_arg(ap, struct dentry *);
78655+ mnt = va_arg(ap, struct vfsmount *);
78656+ num1 = va_arg(ap, int);
78657+ num2 = va_arg(ap, int);
78658+ str1 = va_arg(ap, char *);
78659+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
78660+ break;
78661+ case GR_TEXTREL:
78662+ file = va_arg(ap, struct file *);
78663+ ulong1 = va_arg(ap, unsigned long);
78664+ ulong2 = va_arg(ap, unsigned long);
78665+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
78666+ break;
78667+ case GR_PTRACE:
78668+ task = va_arg(ap, struct task_struct *);
78669+ gr_log_middle_varargs(audit, msg, task->exec_file ? gr_to_filename(task->exec_file->f_path.dentry, task->exec_file->f_path.mnt) : "(none)", task->comm, task_pid_nr(task));
78670+ break;
78671+ case GR_RESOURCE:
78672+ task = va_arg(ap, struct task_struct *);
78673+ cred = __task_cred(task);
78674+ pcred = __task_cred(task->real_parent);
78675+ ulong1 = va_arg(ap, unsigned long);
78676+ str1 = va_arg(ap, char *);
78677+ ulong2 = va_arg(ap, unsigned long);
78678+ gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
78679+ break;
78680+ case GR_CAP:
78681+ task = va_arg(ap, struct task_struct *);
78682+ cred = __task_cred(task);
78683+ pcred = __task_cred(task->real_parent);
78684+ str1 = va_arg(ap, char *);
78685+ gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
78686+ break;
78687+ case GR_SIG:
78688+ str1 = va_arg(ap, char *);
78689+ voidptr = va_arg(ap, void *);
78690+ gr_log_middle_varargs(audit, msg, str1, voidptr);
78691+ break;
78692+ case GR_SIG2:
78693+ task = va_arg(ap, struct task_struct *);
78694+ cred = __task_cred(task);
78695+ pcred = __task_cred(task->real_parent);
78696+ num1 = va_arg(ap, int);
78697+ gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
78698+ break;
78699+ case GR_CRASH1:
78700+ task = va_arg(ap, struct task_struct *);
78701+ cred = __task_cred(task);
78702+ pcred = __task_cred(task->real_parent);
78703+ ulong1 = va_arg(ap, unsigned long);
78704+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), GR_GLOBAL_UID(cred->uid), ulong1);
78705+ break;
78706+ case GR_CRASH2:
78707+ task = va_arg(ap, struct task_struct *);
78708+ cred = __task_cred(task);
78709+ pcred = __task_cred(task->real_parent);
78710+ ulong1 = va_arg(ap, unsigned long);
78711+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), ulong1);
78712+ break;
78713+ case GR_RWXMAP:
78714+ file = va_arg(ap, struct file *);
78715+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
78716+ break;
78717+ case GR_RWXMAPVMA:
78718+ vma = va_arg(ap, struct vm_area_struct *);
78719+ if (vma->vm_file)
78720+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
78721+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
78722+ str1 = "<stack>";
78723+ else if (vma->vm_start <= current->mm->brk &&
78724+ vma->vm_end >= current->mm->start_brk)
78725+ str1 = "<heap>";
78726+ else
78727+ str1 = "<anonymous mapping>";
78728+ gr_log_middle_varargs(audit, msg, str1);
78729+ break;
78730+ case GR_PSACCT:
78731+ {
78732+ unsigned int wday, cday;
78733+ __u8 whr, chr;
78734+ __u8 wmin, cmin;
78735+ __u8 wsec, csec;
78736+ char cur_tty[64] = { 0 };
78737+ char parent_tty[64] = { 0 };
78738+
78739+ task = va_arg(ap, struct task_struct *);
78740+ wday = va_arg(ap, unsigned int);
78741+ cday = va_arg(ap, unsigned int);
78742+ whr = va_arg(ap, int);
78743+ chr = va_arg(ap, int);
78744+ wmin = va_arg(ap, int);
78745+ cmin = va_arg(ap, int);
78746+ wsec = va_arg(ap, int);
78747+ csec = va_arg(ap, int);
78748+ ulong1 = va_arg(ap, unsigned long);
78749+ cred = __task_cred(task);
78750+ pcred = __task_cred(task->real_parent);
78751+
78752+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
78753+ }
78754+ break;
78755+ default:
78756+ gr_log_middle(audit, msg, ap);
78757+ }
78758+ va_end(ap);
78759+ // these don't need DEFAULTSECARGS printed on the end
78760+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
78761+ gr_log_end(audit, 0);
78762+ else
78763+ gr_log_end(audit, 1);
78764+ END_LOCKS(audit);
78765+}
78766diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
78767new file mode 100644
78768index 0000000..0e39d8c
78769--- /dev/null
78770+++ b/grsecurity/grsec_mem.c
78771@@ -0,0 +1,48 @@
78772+#include <linux/kernel.h>
78773+#include <linux/sched.h>
78774+#include <linux/mm.h>
78775+#include <linux/mman.h>
78776+#include <linux/module.h>
78777+#include <linux/grinternal.h>
78778+
78779+void gr_handle_msr_write(void)
78780+{
78781+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
78782+ return;
78783+}
78784+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
78785+
78786+void
78787+gr_handle_ioperm(void)
78788+{
78789+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
78790+ return;
78791+}
78792+
78793+void
78794+gr_handle_iopl(void)
78795+{
78796+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
78797+ return;
78798+}
78799+
78800+void
78801+gr_handle_mem_readwrite(u64 from, u64 to)
78802+{
78803+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
78804+ return;
78805+}
78806+
78807+void
78808+gr_handle_vm86(void)
78809+{
78810+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
78811+ return;
78812+}
78813+
78814+void
78815+gr_log_badprocpid(const char *entry)
78816+{
78817+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
78818+ return;
78819+}
78820diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
78821new file mode 100644
78822index 0000000..cd9e124
78823--- /dev/null
78824+++ b/grsecurity/grsec_mount.c
78825@@ -0,0 +1,65 @@
78826+#include <linux/kernel.h>
78827+#include <linux/sched.h>
78828+#include <linux/mount.h>
78829+#include <linux/major.h>
78830+#include <linux/grsecurity.h>
78831+#include <linux/grinternal.h>
78832+
78833+void
78834+gr_log_remount(const char *devname, const int retval)
78835+{
78836+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78837+ if (grsec_enable_mount && (retval >= 0))
78838+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
78839+#endif
78840+ return;
78841+}
78842+
78843+void
78844+gr_log_unmount(const char *devname, const int retval)
78845+{
78846+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78847+ if (grsec_enable_mount && (retval >= 0))
78848+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
78849+#endif
78850+ return;
78851+}
78852+
78853+void
78854+gr_log_mount(const char *from, const char *to, const int retval)
78855+{
78856+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78857+ if (grsec_enable_mount && (retval >= 0))
78858+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
78859+#endif
78860+ return;
78861+}
78862+
78863+int
78864+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
78865+{
78866+#ifdef CONFIG_GRKERNSEC_ROFS
78867+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78868+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78869+ return -EPERM;
78870+ } else
78871+ return 0;
78872+#endif
78873+ return 0;
78874+}
78875+
78876+int
78877+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78878+{
78879+#ifdef CONFIG_GRKERNSEC_ROFS
78880+ struct inode *inode = dentry->d_inode;
78881+
78882+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78883+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78884+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78885+ return -EPERM;
78886+ } else
78887+ return 0;
78888+#endif
78889+ return 0;
78890+}
78891diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78892new file mode 100644
78893index 0000000..6ee9d50
78894--- /dev/null
78895+++ b/grsecurity/grsec_pax.c
78896@@ -0,0 +1,45 @@
78897+#include <linux/kernel.h>
78898+#include <linux/sched.h>
78899+#include <linux/mm.h>
78900+#include <linux/file.h>
78901+#include <linux/grinternal.h>
78902+#include <linux/grsecurity.h>
78903+
78904+void
78905+gr_log_textrel(struct vm_area_struct * vma)
78906+{
78907+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78908+ if (grsec_enable_log_rwxmaps)
78909+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78910+#endif
78911+ return;
78912+}
78913+
78914+void gr_log_ptgnustack(struct file *file)
78915+{
78916+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78917+ if (grsec_enable_log_rwxmaps)
78918+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78919+#endif
78920+ return;
78921+}
78922+
78923+void
78924+gr_log_rwxmmap(struct file *file)
78925+{
78926+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78927+ if (grsec_enable_log_rwxmaps)
78928+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78929+#endif
78930+ return;
78931+}
78932+
78933+void
78934+gr_log_rwxmprotect(struct vm_area_struct *vma)
78935+{
78936+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78937+ if (grsec_enable_log_rwxmaps)
78938+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78939+#endif
78940+ return;
78941+}
78942diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78943new file mode 100644
78944index 0000000..2005a3a
78945--- /dev/null
78946+++ b/grsecurity/grsec_proc.c
78947@@ -0,0 +1,20 @@
78948+#include <linux/kernel.h>
78949+#include <linux/sched.h>
78950+#include <linux/grsecurity.h>
78951+#include <linux/grinternal.h>
78952+
78953+int gr_proc_is_restricted(void)
78954+{
78955+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78956+ const struct cred *cred = current_cred();
78957+#endif
78958+
78959+#ifdef CONFIG_GRKERNSEC_PROC_USER
78960+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78961+ return -EACCES;
78962+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78963+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78964+ return -EACCES;
78965+#endif
78966+ return 0;
78967+}
78968diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78969new file mode 100644
78970index 0000000..f7f29aa
78971--- /dev/null
78972+++ b/grsecurity/grsec_ptrace.c
78973@@ -0,0 +1,30 @@
78974+#include <linux/kernel.h>
78975+#include <linux/sched.h>
78976+#include <linux/grinternal.h>
78977+#include <linux/security.h>
78978+
78979+void
78980+gr_audit_ptrace(struct task_struct *task)
78981+{
78982+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78983+ if (grsec_enable_audit_ptrace)
78984+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78985+#endif
78986+ return;
78987+}
78988+
78989+int
78990+gr_ptrace_readexec(struct file *file, int unsafe_flags)
78991+{
78992+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78993+ const struct dentry *dentry = file->f_path.dentry;
78994+ const struct vfsmount *mnt = file->f_path.mnt;
78995+
78996+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78997+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78998+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78999+ return -EACCES;
79000+ }
79001+#endif
79002+ return 0;
79003+}
79004diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
79005new file mode 100644
79006index 0000000..3860c7e
79007--- /dev/null
79008+++ b/grsecurity/grsec_sig.c
79009@@ -0,0 +1,236 @@
79010+#include <linux/kernel.h>
79011+#include <linux/sched.h>
79012+#include <linux/fs.h>
79013+#include <linux/delay.h>
79014+#include <linux/grsecurity.h>
79015+#include <linux/grinternal.h>
79016+#include <linux/hardirq.h>
79017+
79018+char *signames[] = {
79019+ [SIGSEGV] = "Segmentation fault",
79020+ [SIGILL] = "Illegal instruction",
79021+ [SIGABRT] = "Abort",
79022+ [SIGBUS] = "Invalid alignment/Bus error"
79023+};
79024+
79025+void
79026+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
79027+{
79028+#ifdef CONFIG_GRKERNSEC_SIGNAL
79029+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
79030+ (sig == SIGABRT) || (sig == SIGBUS))) {
79031+ if (task_pid_nr(t) == task_pid_nr(current)) {
79032+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
79033+ } else {
79034+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
79035+ }
79036+ }
79037+#endif
79038+ return;
79039+}
79040+
79041+int
79042+gr_handle_signal(const struct task_struct *p, const int sig)
79043+{
79044+#ifdef CONFIG_GRKERNSEC
79045+ /* ignore the 0 signal for protected task checks */
79046+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
79047+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
79048+ return -EPERM;
79049+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
79050+ return -EPERM;
79051+ }
79052+#endif
79053+ return 0;
79054+}
79055+
79056+#ifdef CONFIG_GRKERNSEC
79057+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
79058+
79059+int gr_fake_force_sig(int sig, struct task_struct *t)
79060+{
79061+ unsigned long int flags;
79062+ int ret, blocked, ignored;
79063+ struct k_sigaction *action;
79064+
79065+ spin_lock_irqsave(&t->sighand->siglock, flags);
79066+ action = &t->sighand->action[sig-1];
79067+ ignored = action->sa.sa_handler == SIG_IGN;
79068+ blocked = sigismember(&t->blocked, sig);
79069+ if (blocked || ignored) {
79070+ action->sa.sa_handler = SIG_DFL;
79071+ if (blocked) {
79072+ sigdelset(&t->blocked, sig);
79073+ recalc_sigpending_and_wake(t);
79074+ }
79075+ }
79076+ if (action->sa.sa_handler == SIG_DFL)
79077+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
79078+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
79079+
79080+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
79081+
79082+ return ret;
79083+}
79084+#endif
79085+
79086+#define GR_USER_BAN_TIME (15 * 60)
79087+#define GR_DAEMON_BRUTE_TIME (30 * 60)
79088+
79089+void gr_handle_brute_attach(int dumpable)
79090+{
79091+#ifdef CONFIG_GRKERNSEC_BRUTE
79092+ struct task_struct *p = current;
79093+ kuid_t uid = GLOBAL_ROOT_UID;
79094+ int daemon = 0;
79095+
79096+ if (!grsec_enable_brute)
79097+ return;
79098+
79099+ rcu_read_lock();
79100+ read_lock(&tasklist_lock);
79101+ read_lock(&grsec_exec_file_lock);
79102+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
79103+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
79104+ p->real_parent->brute = 1;
79105+ daemon = 1;
79106+ } else {
79107+ const struct cred *cred = __task_cred(p), *cred2;
79108+ struct task_struct *tsk, *tsk2;
79109+
79110+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
79111+ struct user_struct *user;
79112+
79113+ uid = cred->uid;
79114+
79115+ /* this is put upon execution past expiration */
79116+ user = find_user(uid);
79117+ if (user == NULL)
79118+ goto unlock;
79119+ user->suid_banned = 1;
79120+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
79121+ if (user->suid_ban_expires == ~0UL)
79122+ user->suid_ban_expires--;
79123+
79124+ /* only kill other threads of the same binary, from the same user */
79125+ do_each_thread(tsk2, tsk) {
79126+ cred2 = __task_cred(tsk);
79127+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
79128+ gr_fake_force_sig(SIGKILL, tsk);
79129+ } while_each_thread(tsk2, tsk);
79130+ }
79131+ }
79132+unlock:
79133+ read_unlock(&grsec_exec_file_lock);
79134+ read_unlock(&tasklist_lock);
79135+ rcu_read_unlock();
79136+
79137+ if (gr_is_global_nonroot(uid))
79138+ gr_log_fs_int2(GR_DONT_AUDIT, GR_BRUTE_SUID_MSG, p->exec_file->f_path.dentry, p->exec_file->f_path.mnt, GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
79139+ else if (daemon)
79140+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
79141+
79142+#endif
79143+ return;
79144+}
79145+
79146+void gr_handle_brute_check(void)
79147+{
79148+#ifdef CONFIG_GRKERNSEC_BRUTE
79149+ struct task_struct *p = current;
79150+
79151+ if (unlikely(p->brute)) {
79152+ if (!grsec_enable_brute)
79153+ p->brute = 0;
79154+ else if (time_before(get_seconds(), p->brute_expires))
79155+ msleep(30 * 1000);
79156+ }
79157+#endif
79158+ return;
79159+}
79160+
79161+void gr_handle_kernel_exploit(void)
79162+{
79163+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
79164+ const struct cred *cred;
79165+ struct task_struct *tsk, *tsk2;
79166+ struct user_struct *user;
79167+ kuid_t uid;
79168+
79169+ if (in_irq() || in_serving_softirq() || in_nmi())
79170+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
79171+
79172+ uid = current_uid();
79173+
79174+ if (gr_is_global_root(uid))
79175+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
79176+ else {
79177+ /* kill all the processes of this user, hold a reference
79178+ to their creds struct, and prevent them from creating
79179+ another process until system reset
79180+ */
79181+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
79182+ GR_GLOBAL_UID(uid));
79183+ /* we intentionally leak this ref */
79184+ user = get_uid(current->cred->user);
79185+ if (user)
79186+ user->kernel_banned = 1;
79187+
79188+ /* kill all processes of this user */
79189+ read_lock(&tasklist_lock);
79190+ do_each_thread(tsk2, tsk) {
79191+ cred = __task_cred(tsk);
79192+ if (uid_eq(cred->uid, uid))
79193+ gr_fake_force_sig(SIGKILL, tsk);
79194+ } while_each_thread(tsk2, tsk);
79195+ read_unlock(&tasklist_lock);
79196+ }
79197+#endif
79198+}
79199+
79200+#ifdef CONFIG_GRKERNSEC_BRUTE
79201+static bool suid_ban_expired(struct user_struct *user)
79202+{
79203+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
79204+ user->suid_banned = 0;
79205+ user->suid_ban_expires = 0;
79206+ free_uid(user);
79207+ return true;
79208+ }
79209+
79210+ return false;
79211+}
79212+#endif
79213+
79214+int gr_process_kernel_exec_ban(void)
79215+{
79216+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
79217+ if (unlikely(current->cred->user->kernel_banned))
79218+ return -EPERM;
79219+#endif
79220+ return 0;
79221+}
79222+
79223+int gr_process_kernel_setuid_ban(struct user_struct *user)
79224+{
79225+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
79226+ if (unlikely(user->kernel_banned))
79227+ gr_fake_force_sig(SIGKILL, current);
79228+#endif
79229+ return 0;
79230+}
79231+
79232+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
79233+{
79234+#ifdef CONFIG_GRKERNSEC_BRUTE
79235+ struct user_struct *user = current->cred->user;
79236+ if (unlikely(user->suid_banned)) {
79237+ if (suid_ban_expired(user))
79238+ return 0;
79239+ /* disallow execution of suid binaries only */
79240+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
79241+ return -EPERM;
79242+ }
79243+#endif
79244+ return 0;
79245+}
79246diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
79247new file mode 100644
79248index 0000000..c0aef3a
79249--- /dev/null
79250+++ b/grsecurity/grsec_sock.c
79251@@ -0,0 +1,244 @@
79252+#include <linux/kernel.h>
79253+#include <linux/module.h>
79254+#include <linux/sched.h>
79255+#include <linux/file.h>
79256+#include <linux/net.h>
79257+#include <linux/in.h>
79258+#include <linux/ip.h>
79259+#include <net/sock.h>
79260+#include <net/inet_sock.h>
79261+#include <linux/grsecurity.h>
79262+#include <linux/grinternal.h>
79263+#include <linux/gracl.h>
79264+
79265+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
79266+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
79267+
79268+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
79269+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
79270+
79271+#ifdef CONFIG_UNIX_MODULE
79272+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
79273+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
79274+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
79275+EXPORT_SYMBOL_GPL(gr_handle_create);
79276+#endif
79277+
79278+#ifdef CONFIG_GRKERNSEC
79279+#define gr_conn_table_size 32749
79280+struct conn_table_entry {
79281+ struct conn_table_entry *next;
79282+ struct signal_struct *sig;
79283+};
79284+
79285+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
79286+DEFINE_SPINLOCK(gr_conn_table_lock);
79287+
79288+extern const char * gr_socktype_to_name(unsigned char type);
79289+extern const char * gr_proto_to_name(unsigned char proto);
79290+extern const char * gr_sockfamily_to_name(unsigned char family);
79291+
79292+static __inline__ int
79293+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
79294+{
79295+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
79296+}
79297+
79298+static __inline__ int
79299+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
79300+ __u16 sport, __u16 dport)
79301+{
79302+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
79303+ sig->gr_sport == sport && sig->gr_dport == dport))
79304+ return 1;
79305+ else
79306+ return 0;
79307+}
79308+
79309+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
79310+{
79311+ struct conn_table_entry **match;
79312+ unsigned int index;
79313+
79314+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
79315+ sig->gr_sport, sig->gr_dport,
79316+ gr_conn_table_size);
79317+
79318+ newent->sig = sig;
79319+
79320+ match = &gr_conn_table[index];
79321+ newent->next = *match;
79322+ *match = newent;
79323+
79324+ return;
79325+}
79326+
79327+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
79328+{
79329+ struct conn_table_entry *match, *last = NULL;
79330+ unsigned int index;
79331+
79332+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
79333+ sig->gr_sport, sig->gr_dport,
79334+ gr_conn_table_size);
79335+
79336+ match = gr_conn_table[index];
79337+ while (match && !conn_match(match->sig,
79338+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
79339+ sig->gr_dport)) {
79340+ last = match;
79341+ match = match->next;
79342+ }
79343+
79344+ if (match) {
79345+ if (last)
79346+ last->next = match->next;
79347+ else
79348+ gr_conn_table[index] = NULL;
79349+ kfree(match);
79350+ }
79351+
79352+ return;
79353+}
79354+
79355+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
79356+ __u16 sport, __u16 dport)
79357+{
79358+ struct conn_table_entry *match;
79359+ unsigned int index;
79360+
79361+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
79362+
79363+ match = gr_conn_table[index];
79364+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
79365+ match = match->next;
79366+
79367+ if (match)
79368+ return match->sig;
79369+ else
79370+ return NULL;
79371+}
79372+
79373+#endif
79374+
79375+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
79376+{
79377+#ifdef CONFIG_GRKERNSEC
79378+ struct signal_struct *sig = task->signal;
79379+ struct conn_table_entry *newent;
79380+
79381+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
79382+ if (newent == NULL)
79383+ return;
79384+ /* no bh lock needed since we are called with bh disabled */
79385+ spin_lock(&gr_conn_table_lock);
79386+ gr_del_task_from_ip_table_nolock(sig);
79387+ sig->gr_saddr = inet->inet_rcv_saddr;
79388+ sig->gr_daddr = inet->inet_daddr;
79389+ sig->gr_sport = inet->inet_sport;
79390+ sig->gr_dport = inet->inet_dport;
79391+ gr_add_to_task_ip_table_nolock(sig, newent);
79392+ spin_unlock(&gr_conn_table_lock);
79393+#endif
79394+ return;
79395+}
79396+
79397+void gr_del_task_from_ip_table(struct task_struct *task)
79398+{
79399+#ifdef CONFIG_GRKERNSEC
79400+ spin_lock_bh(&gr_conn_table_lock);
79401+ gr_del_task_from_ip_table_nolock(task->signal);
79402+ spin_unlock_bh(&gr_conn_table_lock);
79403+#endif
79404+ return;
79405+}
79406+
79407+void
79408+gr_attach_curr_ip(const struct sock *sk)
79409+{
79410+#ifdef CONFIG_GRKERNSEC
79411+ struct signal_struct *p, *set;
79412+ const struct inet_sock *inet = inet_sk(sk);
79413+
79414+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
79415+ return;
79416+
79417+ set = current->signal;
79418+
79419+ spin_lock_bh(&gr_conn_table_lock);
79420+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
79421+ inet->inet_dport, inet->inet_sport);
79422+ if (unlikely(p != NULL)) {
79423+ set->curr_ip = p->curr_ip;
79424+ set->used_accept = 1;
79425+ gr_del_task_from_ip_table_nolock(p);
79426+ spin_unlock_bh(&gr_conn_table_lock);
79427+ return;
79428+ }
79429+ spin_unlock_bh(&gr_conn_table_lock);
79430+
79431+ set->curr_ip = inet->inet_daddr;
79432+ set->used_accept = 1;
79433+#endif
79434+ return;
79435+}
79436+
79437+int
79438+gr_handle_sock_all(const int family, const int type, const int protocol)
79439+{
79440+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79441+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
79442+ (family != AF_UNIX)) {
79443+ if (family == AF_INET)
79444+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
79445+ else
79446+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
79447+ return -EACCES;
79448+ }
79449+#endif
79450+ return 0;
79451+}
79452+
79453+int
79454+gr_handle_sock_server(const struct sockaddr *sck)
79455+{
79456+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79457+ if (grsec_enable_socket_server &&
79458+ in_group_p(grsec_socket_server_gid) &&
79459+ sck && (sck->sa_family != AF_UNIX) &&
79460+ (sck->sa_family != AF_LOCAL)) {
79461+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
79462+ return -EACCES;
79463+ }
79464+#endif
79465+ return 0;
79466+}
79467+
79468+int
79469+gr_handle_sock_server_other(const struct sock *sck)
79470+{
79471+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79472+ if (grsec_enable_socket_server &&
79473+ in_group_p(grsec_socket_server_gid) &&
79474+ sck && (sck->sk_family != AF_UNIX) &&
79475+ (sck->sk_family != AF_LOCAL)) {
79476+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
79477+ return -EACCES;
79478+ }
79479+#endif
79480+ return 0;
79481+}
79482+
79483+int
79484+gr_handle_sock_client(const struct sockaddr *sck)
79485+{
79486+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79487+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
79488+ sck && (sck->sa_family != AF_UNIX) &&
79489+ (sck->sa_family != AF_LOCAL)) {
79490+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
79491+ return -EACCES;
79492+ }
79493+#endif
79494+ return 0;
79495+}
79496diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
79497new file mode 100644
79498index 0000000..8159888
79499--- /dev/null
79500+++ b/grsecurity/grsec_sysctl.c
79501@@ -0,0 +1,479 @@
79502+#include <linux/kernel.h>
79503+#include <linux/sched.h>
79504+#include <linux/sysctl.h>
79505+#include <linux/grsecurity.h>
79506+#include <linux/grinternal.h>
79507+
79508+int
79509+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
79510+{
79511+#ifdef CONFIG_GRKERNSEC_SYSCTL
79512+ if (dirname == NULL || name == NULL)
79513+ return 0;
79514+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
79515+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
79516+ return -EACCES;
79517+ }
79518+#endif
79519+ return 0;
79520+}
79521+
79522+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
79523+static int __maybe_unused __read_only one = 1;
79524+#endif
79525+
79526+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
79527+ defined(CONFIG_GRKERNSEC_DENYUSB)
79528+struct ctl_table grsecurity_table[] = {
79529+#ifdef CONFIG_GRKERNSEC_SYSCTL
79530+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
79531+#ifdef CONFIG_GRKERNSEC_IO
79532+ {
79533+ .procname = "disable_priv_io",
79534+ .data = &grsec_disable_privio,
79535+ .maxlen = sizeof(int),
79536+ .mode = 0600,
79537+ .proc_handler = &proc_dointvec,
79538+ },
79539+#endif
79540+#endif
79541+#ifdef CONFIG_GRKERNSEC_LINK
79542+ {
79543+ .procname = "linking_restrictions",
79544+ .data = &grsec_enable_link,
79545+ .maxlen = sizeof(int),
79546+ .mode = 0600,
79547+ .proc_handler = &proc_dointvec,
79548+ },
79549+#endif
79550+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
79551+ {
79552+ .procname = "enforce_symlinksifowner",
79553+ .data = &grsec_enable_symlinkown,
79554+ .maxlen = sizeof(int),
79555+ .mode = 0600,
79556+ .proc_handler = &proc_dointvec,
79557+ },
79558+ {
79559+ .procname = "symlinkown_gid",
79560+ .data = &grsec_symlinkown_gid,
79561+ .maxlen = sizeof(int),
79562+ .mode = 0600,
79563+ .proc_handler = &proc_dointvec,
79564+ },
79565+#endif
79566+#ifdef CONFIG_GRKERNSEC_BRUTE
79567+ {
79568+ .procname = "deter_bruteforce",
79569+ .data = &grsec_enable_brute,
79570+ .maxlen = sizeof(int),
79571+ .mode = 0600,
79572+ .proc_handler = &proc_dointvec,
79573+ },
79574+#endif
79575+#ifdef CONFIG_GRKERNSEC_FIFO
79576+ {
79577+ .procname = "fifo_restrictions",
79578+ .data = &grsec_enable_fifo,
79579+ .maxlen = sizeof(int),
79580+ .mode = 0600,
79581+ .proc_handler = &proc_dointvec,
79582+ },
79583+#endif
79584+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
79585+ {
79586+ .procname = "ptrace_readexec",
79587+ .data = &grsec_enable_ptrace_readexec,
79588+ .maxlen = sizeof(int),
79589+ .mode = 0600,
79590+ .proc_handler = &proc_dointvec,
79591+ },
79592+#endif
79593+#ifdef CONFIG_GRKERNSEC_SETXID
79594+ {
79595+ .procname = "consistent_setxid",
79596+ .data = &grsec_enable_setxid,
79597+ .maxlen = sizeof(int),
79598+ .mode = 0600,
79599+ .proc_handler = &proc_dointvec,
79600+ },
79601+#endif
79602+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79603+ {
79604+ .procname = "ip_blackhole",
79605+ .data = &grsec_enable_blackhole,
79606+ .maxlen = sizeof(int),
79607+ .mode = 0600,
79608+ .proc_handler = &proc_dointvec,
79609+ },
79610+ {
79611+ .procname = "lastack_retries",
79612+ .data = &grsec_lastack_retries,
79613+ .maxlen = sizeof(int),
79614+ .mode = 0600,
79615+ .proc_handler = &proc_dointvec,
79616+ },
79617+#endif
79618+#ifdef CONFIG_GRKERNSEC_EXECLOG
79619+ {
79620+ .procname = "exec_logging",
79621+ .data = &grsec_enable_execlog,
79622+ .maxlen = sizeof(int),
79623+ .mode = 0600,
79624+ .proc_handler = &proc_dointvec,
79625+ },
79626+#endif
79627+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
79628+ {
79629+ .procname = "rwxmap_logging",
79630+ .data = &grsec_enable_log_rwxmaps,
79631+ .maxlen = sizeof(int),
79632+ .mode = 0600,
79633+ .proc_handler = &proc_dointvec,
79634+ },
79635+#endif
79636+#ifdef CONFIG_GRKERNSEC_SIGNAL
79637+ {
79638+ .procname = "signal_logging",
79639+ .data = &grsec_enable_signal,
79640+ .maxlen = sizeof(int),
79641+ .mode = 0600,
79642+ .proc_handler = &proc_dointvec,
79643+ },
79644+#endif
79645+#ifdef CONFIG_GRKERNSEC_FORKFAIL
79646+ {
79647+ .procname = "forkfail_logging",
79648+ .data = &grsec_enable_forkfail,
79649+ .maxlen = sizeof(int),
79650+ .mode = 0600,
79651+ .proc_handler = &proc_dointvec,
79652+ },
79653+#endif
79654+#ifdef CONFIG_GRKERNSEC_TIME
79655+ {
79656+ .procname = "timechange_logging",
79657+ .data = &grsec_enable_time,
79658+ .maxlen = sizeof(int),
79659+ .mode = 0600,
79660+ .proc_handler = &proc_dointvec,
79661+ },
79662+#endif
79663+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
79664+ {
79665+ .procname = "chroot_deny_shmat",
79666+ .data = &grsec_enable_chroot_shmat,
79667+ .maxlen = sizeof(int),
79668+ .mode = 0600,
79669+ .proc_handler = &proc_dointvec,
79670+ },
79671+#endif
79672+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
79673+ {
79674+ .procname = "chroot_deny_unix",
79675+ .data = &grsec_enable_chroot_unix,
79676+ .maxlen = sizeof(int),
79677+ .mode = 0600,
79678+ .proc_handler = &proc_dointvec,
79679+ },
79680+#endif
79681+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
79682+ {
79683+ .procname = "chroot_deny_mount",
79684+ .data = &grsec_enable_chroot_mount,
79685+ .maxlen = sizeof(int),
79686+ .mode = 0600,
79687+ .proc_handler = &proc_dointvec,
79688+ },
79689+#endif
79690+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
79691+ {
79692+ .procname = "chroot_deny_fchdir",
79693+ .data = &grsec_enable_chroot_fchdir,
79694+ .maxlen = sizeof(int),
79695+ .mode = 0600,
79696+ .proc_handler = &proc_dointvec,
79697+ },
79698+#endif
79699+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
79700+ {
79701+ .procname = "chroot_deny_chroot",
79702+ .data = &grsec_enable_chroot_double,
79703+ .maxlen = sizeof(int),
79704+ .mode = 0600,
79705+ .proc_handler = &proc_dointvec,
79706+ },
79707+#endif
79708+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
79709+ {
79710+ .procname = "chroot_deny_pivot",
79711+ .data = &grsec_enable_chroot_pivot,
79712+ .maxlen = sizeof(int),
79713+ .mode = 0600,
79714+ .proc_handler = &proc_dointvec,
79715+ },
79716+#endif
79717+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
79718+ {
79719+ .procname = "chroot_enforce_chdir",
79720+ .data = &grsec_enable_chroot_chdir,
79721+ .maxlen = sizeof(int),
79722+ .mode = 0600,
79723+ .proc_handler = &proc_dointvec,
79724+ },
79725+#endif
79726+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
79727+ {
79728+ .procname = "chroot_deny_chmod",
79729+ .data = &grsec_enable_chroot_chmod,
79730+ .maxlen = sizeof(int),
79731+ .mode = 0600,
79732+ .proc_handler = &proc_dointvec,
79733+ },
79734+#endif
79735+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
79736+ {
79737+ .procname = "chroot_deny_mknod",
79738+ .data = &grsec_enable_chroot_mknod,
79739+ .maxlen = sizeof(int),
79740+ .mode = 0600,
79741+ .proc_handler = &proc_dointvec,
79742+ },
79743+#endif
79744+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
79745+ {
79746+ .procname = "chroot_restrict_nice",
79747+ .data = &grsec_enable_chroot_nice,
79748+ .maxlen = sizeof(int),
79749+ .mode = 0600,
79750+ .proc_handler = &proc_dointvec,
79751+ },
79752+#endif
79753+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
79754+ {
79755+ .procname = "chroot_execlog",
79756+ .data = &grsec_enable_chroot_execlog,
79757+ .maxlen = sizeof(int),
79758+ .mode = 0600,
79759+ .proc_handler = &proc_dointvec,
79760+ },
79761+#endif
79762+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
79763+ {
79764+ .procname = "chroot_caps",
79765+ .data = &grsec_enable_chroot_caps,
79766+ .maxlen = sizeof(int),
79767+ .mode = 0600,
79768+ .proc_handler = &proc_dointvec,
79769+ },
79770+#endif
79771+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
79772+ {
79773+ .procname = "chroot_deny_sysctl",
79774+ .data = &grsec_enable_chroot_sysctl,
79775+ .maxlen = sizeof(int),
79776+ .mode = 0600,
79777+ .proc_handler = &proc_dointvec,
79778+ },
79779+#endif
79780+#ifdef CONFIG_GRKERNSEC_TPE
79781+ {
79782+ .procname = "tpe",
79783+ .data = &grsec_enable_tpe,
79784+ .maxlen = sizeof(int),
79785+ .mode = 0600,
79786+ .proc_handler = &proc_dointvec,
79787+ },
79788+ {
79789+ .procname = "tpe_gid",
79790+ .data = &grsec_tpe_gid,
79791+ .maxlen = sizeof(int),
79792+ .mode = 0600,
79793+ .proc_handler = &proc_dointvec,
79794+ },
79795+#endif
79796+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79797+ {
79798+ .procname = "tpe_invert",
79799+ .data = &grsec_enable_tpe_invert,
79800+ .maxlen = sizeof(int),
79801+ .mode = 0600,
79802+ .proc_handler = &proc_dointvec,
79803+ },
79804+#endif
79805+#ifdef CONFIG_GRKERNSEC_TPE_ALL
79806+ {
79807+ .procname = "tpe_restrict_all",
79808+ .data = &grsec_enable_tpe_all,
79809+ .maxlen = sizeof(int),
79810+ .mode = 0600,
79811+ .proc_handler = &proc_dointvec,
79812+ },
79813+#endif
79814+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79815+ {
79816+ .procname = "socket_all",
79817+ .data = &grsec_enable_socket_all,
79818+ .maxlen = sizeof(int),
79819+ .mode = 0600,
79820+ .proc_handler = &proc_dointvec,
79821+ },
79822+ {
79823+ .procname = "socket_all_gid",
79824+ .data = &grsec_socket_all_gid,
79825+ .maxlen = sizeof(int),
79826+ .mode = 0600,
79827+ .proc_handler = &proc_dointvec,
79828+ },
79829+#endif
79830+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79831+ {
79832+ .procname = "socket_client",
79833+ .data = &grsec_enable_socket_client,
79834+ .maxlen = sizeof(int),
79835+ .mode = 0600,
79836+ .proc_handler = &proc_dointvec,
79837+ },
79838+ {
79839+ .procname = "socket_client_gid",
79840+ .data = &grsec_socket_client_gid,
79841+ .maxlen = sizeof(int),
79842+ .mode = 0600,
79843+ .proc_handler = &proc_dointvec,
79844+ },
79845+#endif
79846+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79847+ {
79848+ .procname = "socket_server",
79849+ .data = &grsec_enable_socket_server,
79850+ .maxlen = sizeof(int),
79851+ .mode = 0600,
79852+ .proc_handler = &proc_dointvec,
79853+ },
79854+ {
79855+ .procname = "socket_server_gid",
79856+ .data = &grsec_socket_server_gid,
79857+ .maxlen = sizeof(int),
79858+ .mode = 0600,
79859+ .proc_handler = &proc_dointvec,
79860+ },
79861+#endif
79862+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
79863+ {
79864+ .procname = "audit_group",
79865+ .data = &grsec_enable_group,
79866+ .maxlen = sizeof(int),
79867+ .mode = 0600,
79868+ .proc_handler = &proc_dointvec,
79869+ },
79870+ {
79871+ .procname = "audit_gid",
79872+ .data = &grsec_audit_gid,
79873+ .maxlen = sizeof(int),
79874+ .mode = 0600,
79875+ .proc_handler = &proc_dointvec,
79876+ },
79877+#endif
79878+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79879+ {
79880+ .procname = "audit_chdir",
79881+ .data = &grsec_enable_chdir,
79882+ .maxlen = sizeof(int),
79883+ .mode = 0600,
79884+ .proc_handler = &proc_dointvec,
79885+ },
79886+#endif
79887+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79888+ {
79889+ .procname = "audit_mount",
79890+ .data = &grsec_enable_mount,
79891+ .maxlen = sizeof(int),
79892+ .mode = 0600,
79893+ .proc_handler = &proc_dointvec,
79894+ },
79895+#endif
79896+#ifdef CONFIG_GRKERNSEC_DMESG
79897+ {
79898+ .procname = "dmesg",
79899+ .data = &grsec_enable_dmesg,
79900+ .maxlen = sizeof(int),
79901+ .mode = 0600,
79902+ .proc_handler = &proc_dointvec,
79903+ },
79904+#endif
79905+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79906+ {
79907+ .procname = "chroot_findtask",
79908+ .data = &grsec_enable_chroot_findtask,
79909+ .maxlen = sizeof(int),
79910+ .mode = 0600,
79911+ .proc_handler = &proc_dointvec,
79912+ },
79913+#endif
79914+#ifdef CONFIG_GRKERNSEC_RESLOG
79915+ {
79916+ .procname = "resource_logging",
79917+ .data = &grsec_resource_logging,
79918+ .maxlen = sizeof(int),
79919+ .mode = 0600,
79920+ .proc_handler = &proc_dointvec,
79921+ },
79922+#endif
79923+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79924+ {
79925+ .procname = "audit_ptrace",
79926+ .data = &grsec_enable_audit_ptrace,
79927+ .maxlen = sizeof(int),
79928+ .mode = 0600,
79929+ .proc_handler = &proc_dointvec,
79930+ },
79931+#endif
79932+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79933+ {
79934+ .procname = "harden_ptrace",
79935+ .data = &grsec_enable_harden_ptrace,
79936+ .maxlen = sizeof(int),
79937+ .mode = 0600,
79938+ .proc_handler = &proc_dointvec,
79939+ },
79940+#endif
79941+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79942+ {
79943+ .procname = "harden_ipc",
79944+ .data = &grsec_enable_harden_ipc,
79945+ .maxlen = sizeof(int),
79946+ .mode = 0600,
79947+ .proc_handler = &proc_dointvec,
79948+ },
79949+#endif
79950+ {
79951+ .procname = "grsec_lock",
79952+ .data = &grsec_lock,
79953+ .maxlen = sizeof(int),
79954+ .mode = 0600,
79955+ .proc_handler = &proc_dointvec,
79956+ },
79957+#endif
79958+#ifdef CONFIG_GRKERNSEC_ROFS
79959+ {
79960+ .procname = "romount_protect",
79961+ .data = &grsec_enable_rofs,
79962+ .maxlen = sizeof(int),
79963+ .mode = 0600,
79964+ .proc_handler = &proc_dointvec_minmax,
79965+ .extra1 = &one,
79966+ .extra2 = &one,
79967+ },
79968+#endif
79969+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79970+ {
79971+ .procname = "deny_new_usb",
79972+ .data = &grsec_deny_new_usb,
79973+ .maxlen = sizeof(int),
79974+ .mode = 0600,
79975+ .proc_handler = &proc_dointvec,
79976+ },
79977+#endif
79978+ { }
79979+};
79980+#endif
79981diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79982new file mode 100644
79983index 0000000..61b514e
79984--- /dev/null
79985+++ b/grsecurity/grsec_time.c
79986@@ -0,0 +1,16 @@
79987+#include <linux/kernel.h>
79988+#include <linux/sched.h>
79989+#include <linux/grinternal.h>
79990+#include <linux/module.h>
79991+
79992+void
79993+gr_log_timechange(void)
79994+{
79995+#ifdef CONFIG_GRKERNSEC_TIME
79996+ if (grsec_enable_time)
79997+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79998+#endif
79999+ return;
80000+}
80001+
80002+EXPORT_SYMBOL_GPL(gr_log_timechange);
80003diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
80004new file mode 100644
80005index 0000000..d1953de
80006--- /dev/null
80007+++ b/grsecurity/grsec_tpe.c
80008@@ -0,0 +1,78 @@
80009+#include <linux/kernel.h>
80010+#include <linux/sched.h>
80011+#include <linux/file.h>
80012+#include <linux/fs.h>
80013+#include <linux/grinternal.h>
80014+
80015+extern int gr_acl_tpe_check(void);
80016+
80017+int
80018+gr_tpe_allow(const struct file *file)
80019+{
80020+#ifdef CONFIG_GRKERNSEC
80021+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
80022+ struct inode *file_inode = file->f_path.dentry->d_inode;
80023+ const struct cred *cred = current_cred();
80024+ char *msg = NULL;
80025+ char *msg2 = NULL;
80026+
80027+ // never restrict root
80028+ if (gr_is_global_root(cred->uid))
80029+ return 1;
80030+
80031+ if (grsec_enable_tpe) {
80032+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
80033+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
80034+ msg = "not being in trusted group";
80035+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
80036+ msg = "being in untrusted group";
80037+#else
80038+ if (in_group_p(grsec_tpe_gid))
80039+ msg = "being in untrusted group";
80040+#endif
80041+ }
80042+ if (!msg && gr_acl_tpe_check())
80043+ msg = "being in untrusted role";
80044+
80045+ // not in any affected group/role
80046+ if (!msg)
80047+ goto next_check;
80048+
80049+ if (gr_is_global_nonroot(inode->i_uid))
80050+ msg2 = "file in non-root-owned directory";
80051+ else if (inode->i_mode & S_IWOTH)
80052+ msg2 = "file in world-writable directory";
80053+ else if (inode->i_mode & S_IWGRP)
80054+ msg2 = "file in group-writable directory";
80055+ else if (file_inode->i_mode & S_IWOTH)
80056+ msg2 = "file is world-writable";
80057+
80058+ if (msg && msg2) {
80059+ char fullmsg[70] = {0};
80060+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
80061+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
80062+ return 0;
80063+ }
80064+ msg = NULL;
80065+next_check:
80066+#ifdef CONFIG_GRKERNSEC_TPE_ALL
80067+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
80068+ return 1;
80069+
80070+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
80071+ msg = "directory not owned by user";
80072+ else if (inode->i_mode & S_IWOTH)
80073+ msg = "file in world-writable directory";
80074+ else if (inode->i_mode & S_IWGRP)
80075+ msg = "file in group-writable directory";
80076+ else if (file_inode->i_mode & S_IWOTH)
80077+ msg = "file is world-writable";
80078+
80079+ if (msg) {
80080+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
80081+ return 0;
80082+ }
80083+#endif
80084+#endif
80085+ return 1;
80086+}
80087diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
80088new file mode 100644
80089index 0000000..ae02d8e
80090--- /dev/null
80091+++ b/grsecurity/grsec_usb.c
80092@@ -0,0 +1,15 @@
80093+#include <linux/kernel.h>
80094+#include <linux/grinternal.h>
80095+#include <linux/module.h>
80096+
80097+int gr_handle_new_usb(void)
80098+{
80099+#ifdef CONFIG_GRKERNSEC_DENYUSB
80100+ if (grsec_deny_new_usb) {
80101+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
80102+ return 1;
80103+ }
80104+#endif
80105+ return 0;
80106+}
80107+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
80108diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
80109new file mode 100644
80110index 0000000..158b330
80111--- /dev/null
80112+++ b/grsecurity/grsum.c
80113@@ -0,0 +1,64 @@
80114+#include <linux/err.h>
80115+#include <linux/kernel.h>
80116+#include <linux/sched.h>
80117+#include <linux/mm.h>
80118+#include <linux/scatterlist.h>
80119+#include <linux/crypto.h>
80120+#include <linux/gracl.h>
80121+
80122+
80123+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
80124+#error "crypto and sha256 must be built into the kernel"
80125+#endif
80126+
80127+int
80128+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
80129+{
80130+ struct crypto_hash *tfm;
80131+ struct hash_desc desc;
80132+ struct scatterlist sg[2];
80133+ unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
80134+ unsigned long *tmpsumptr = (unsigned long *)temp_sum;
80135+ unsigned long *sumptr = (unsigned long *)sum;
80136+ int cryptres;
80137+ int retval = 1;
80138+ volatile int mismatched = 0;
80139+ volatile int dummy = 0;
80140+ unsigned int i;
80141+
80142+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
80143+ if (IS_ERR(tfm)) {
80144+ /* should never happen, since sha256 should be built in */
80145+ memset(entry->pw, 0, GR_PW_LEN);
80146+ return 1;
80147+ }
80148+
80149+ sg_init_table(sg, 2);
80150+ sg_set_buf(&sg[0], salt, GR_SALT_LEN);
80151+ sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
80152+
80153+ desc.tfm = tfm;
80154+ desc.flags = 0;
80155+
80156+ cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
80157+ temp_sum);
80158+
80159+ memset(entry->pw, 0, GR_PW_LEN);
80160+
80161+ if (cryptres)
80162+ goto out;
80163+
80164+ for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
80165+ if (sumptr[i] != tmpsumptr[i])
80166+ mismatched = 1;
80167+ else
80168+ dummy = 1; // waste a cycle
80169+
80170+ if (!mismatched)
80171+ retval = dummy - 1;
80172+
80173+out:
80174+ crypto_free_hash(tfm);
80175+
80176+ return retval;
80177+}
80178diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
80179index 77ff547..181834f 100644
80180--- a/include/asm-generic/4level-fixup.h
80181+++ b/include/asm-generic/4level-fixup.h
80182@@ -13,8 +13,10 @@
80183 #define pmd_alloc(mm, pud, address) \
80184 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
80185 NULL: pmd_offset(pud, address))
80186+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
80187
80188 #define pud_alloc(mm, pgd, address) (pgd)
80189+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
80190 #define pud_offset(pgd, start) (pgd)
80191 #define pud_none(pud) 0
80192 #define pud_bad(pud) 0
80193diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
80194index b7babf0..97f4c4f 100644
80195--- a/include/asm-generic/atomic-long.h
80196+++ b/include/asm-generic/atomic-long.h
80197@@ -22,6 +22,12 @@
80198
80199 typedef atomic64_t atomic_long_t;
80200
80201+#ifdef CONFIG_PAX_REFCOUNT
80202+typedef atomic64_unchecked_t atomic_long_unchecked_t;
80203+#else
80204+typedef atomic64_t atomic_long_unchecked_t;
80205+#endif
80206+
80207 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
80208
80209 static inline long atomic_long_read(atomic_long_t *l)
80210@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
80211 return (long)atomic64_read(v);
80212 }
80213
80214+#ifdef CONFIG_PAX_REFCOUNT
80215+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
80216+{
80217+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80218+
80219+ return (long)atomic64_read_unchecked(v);
80220+}
80221+#endif
80222+
80223 static inline void atomic_long_set(atomic_long_t *l, long i)
80224 {
80225 atomic64_t *v = (atomic64_t *)l;
80226@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
80227 atomic64_set(v, i);
80228 }
80229
80230+#ifdef CONFIG_PAX_REFCOUNT
80231+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
80232+{
80233+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80234+
80235+ atomic64_set_unchecked(v, i);
80236+}
80237+#endif
80238+
80239 static inline void atomic_long_inc(atomic_long_t *l)
80240 {
80241 atomic64_t *v = (atomic64_t *)l;
80242@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
80243 atomic64_inc(v);
80244 }
80245
80246+#ifdef CONFIG_PAX_REFCOUNT
80247+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
80248+{
80249+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80250+
80251+ atomic64_inc_unchecked(v);
80252+}
80253+#endif
80254+
80255 static inline void atomic_long_dec(atomic_long_t *l)
80256 {
80257 atomic64_t *v = (atomic64_t *)l;
80258@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
80259 atomic64_dec(v);
80260 }
80261
80262+#ifdef CONFIG_PAX_REFCOUNT
80263+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
80264+{
80265+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80266+
80267+ atomic64_dec_unchecked(v);
80268+}
80269+#endif
80270+
80271 static inline void atomic_long_add(long i, atomic_long_t *l)
80272 {
80273 atomic64_t *v = (atomic64_t *)l;
80274@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
80275 atomic64_add(i, v);
80276 }
80277
80278+#ifdef CONFIG_PAX_REFCOUNT
80279+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
80280+{
80281+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80282+
80283+ atomic64_add_unchecked(i, v);
80284+}
80285+#endif
80286+
80287 static inline void atomic_long_sub(long i, atomic_long_t *l)
80288 {
80289 atomic64_t *v = (atomic64_t *)l;
80290@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
80291 atomic64_sub(i, v);
80292 }
80293
80294+#ifdef CONFIG_PAX_REFCOUNT
80295+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
80296+{
80297+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80298+
80299+ atomic64_sub_unchecked(i, v);
80300+}
80301+#endif
80302+
80303 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
80304 {
80305 atomic64_t *v = (atomic64_t *)l;
80306@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
80307 return atomic64_add_negative(i, v);
80308 }
80309
80310-static inline long atomic_long_add_return(long i, atomic_long_t *l)
80311+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
80312 {
80313 atomic64_t *v = (atomic64_t *)l;
80314
80315 return (long)atomic64_add_return(i, v);
80316 }
80317
80318+#ifdef CONFIG_PAX_REFCOUNT
80319+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
80320+{
80321+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80322+
80323+ return (long)atomic64_add_return_unchecked(i, v);
80324+}
80325+#endif
80326+
80327 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
80328 {
80329 atomic64_t *v = (atomic64_t *)l;
80330@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
80331 return (long)atomic64_inc_return(v);
80332 }
80333
80334+#ifdef CONFIG_PAX_REFCOUNT
80335+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
80336+{
80337+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80338+
80339+ return (long)atomic64_inc_return_unchecked(v);
80340+}
80341+#endif
80342+
80343 static inline long atomic_long_dec_return(atomic_long_t *l)
80344 {
80345 atomic64_t *v = (atomic64_t *)l;
80346@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
80347
80348 typedef atomic_t atomic_long_t;
80349
80350+#ifdef CONFIG_PAX_REFCOUNT
80351+typedef atomic_unchecked_t atomic_long_unchecked_t;
80352+#else
80353+typedef atomic_t atomic_long_unchecked_t;
80354+#endif
80355+
80356 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
80357 static inline long atomic_long_read(atomic_long_t *l)
80358 {
80359@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
80360 return (long)atomic_read(v);
80361 }
80362
80363+#ifdef CONFIG_PAX_REFCOUNT
80364+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
80365+{
80366+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80367+
80368+ return (long)atomic_read_unchecked(v);
80369+}
80370+#endif
80371+
80372 static inline void atomic_long_set(atomic_long_t *l, long i)
80373 {
80374 atomic_t *v = (atomic_t *)l;
80375@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
80376 atomic_set(v, i);
80377 }
80378
80379+#ifdef CONFIG_PAX_REFCOUNT
80380+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
80381+{
80382+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80383+
80384+ atomic_set_unchecked(v, i);
80385+}
80386+#endif
80387+
80388 static inline void atomic_long_inc(atomic_long_t *l)
80389 {
80390 atomic_t *v = (atomic_t *)l;
80391@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
80392 atomic_inc(v);
80393 }
80394
80395+#ifdef CONFIG_PAX_REFCOUNT
80396+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
80397+{
80398+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80399+
80400+ atomic_inc_unchecked(v);
80401+}
80402+#endif
80403+
80404 static inline void atomic_long_dec(atomic_long_t *l)
80405 {
80406 atomic_t *v = (atomic_t *)l;
80407@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
80408 atomic_dec(v);
80409 }
80410
80411+#ifdef CONFIG_PAX_REFCOUNT
80412+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
80413+{
80414+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80415+
80416+ atomic_dec_unchecked(v);
80417+}
80418+#endif
80419+
80420 static inline void atomic_long_add(long i, atomic_long_t *l)
80421 {
80422 atomic_t *v = (atomic_t *)l;
80423@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
80424 atomic_add(i, v);
80425 }
80426
80427+#ifdef CONFIG_PAX_REFCOUNT
80428+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
80429+{
80430+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80431+
80432+ atomic_add_unchecked(i, v);
80433+}
80434+#endif
80435+
80436 static inline void atomic_long_sub(long i, atomic_long_t *l)
80437 {
80438 atomic_t *v = (atomic_t *)l;
80439@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
80440 atomic_sub(i, v);
80441 }
80442
80443+#ifdef CONFIG_PAX_REFCOUNT
80444+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
80445+{
80446+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80447+
80448+ atomic_sub_unchecked(i, v);
80449+}
80450+#endif
80451+
80452 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
80453 {
80454 atomic_t *v = (atomic_t *)l;
80455@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
80456 return (long)atomic_add_return(i, v);
80457 }
80458
80459+#ifdef CONFIG_PAX_REFCOUNT
80460+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
80461+{
80462+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80463+
80464+ return (long)atomic_add_return_unchecked(i, v);
80465+}
80466+
80467+#endif
80468+
80469 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
80470 {
80471 atomic_t *v = (atomic_t *)l;
80472@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
80473 return (long)atomic_inc_return(v);
80474 }
80475
80476+#ifdef CONFIG_PAX_REFCOUNT
80477+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
80478+{
80479+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80480+
80481+ return (long)atomic_inc_return_unchecked(v);
80482+}
80483+#endif
80484+
80485 static inline long atomic_long_dec_return(atomic_long_t *l)
80486 {
80487 atomic_t *v = (atomic_t *)l;
80488@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
80489
80490 #endif /* BITS_PER_LONG == 64 */
80491
80492+#ifdef CONFIG_PAX_REFCOUNT
80493+static inline void pax_refcount_needs_these_functions(void)
80494+{
80495+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
80496+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
80497+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
80498+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
80499+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
80500+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
80501+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
80502+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
80503+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
80504+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
80505+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
80506+#ifdef CONFIG_X86
80507+ atomic_clear_mask_unchecked(0, NULL);
80508+ atomic_set_mask_unchecked(0, NULL);
80509+#endif
80510+
80511+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
80512+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
80513+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
80514+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
80515+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
80516+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
80517+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
80518+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
80519+}
80520+#else
80521+#define atomic_read_unchecked(v) atomic_read(v)
80522+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
80523+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
80524+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
80525+#define atomic_inc_unchecked(v) atomic_inc(v)
80526+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
80527+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
80528+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
80529+#define atomic_dec_unchecked(v) atomic_dec(v)
80530+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
80531+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
80532+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
80533+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
80534+
80535+#define atomic_long_read_unchecked(v) atomic_long_read(v)
80536+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
80537+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
80538+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
80539+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
80540+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
80541+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
80542+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
80543+#endif
80544+
80545 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
80546diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
80547index 9c79e76..9f7827d 100644
80548--- a/include/asm-generic/atomic.h
80549+++ b/include/asm-generic/atomic.h
80550@@ -154,7 +154,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
80551 * Atomically clears the bits set in @mask from @v
80552 */
80553 #ifndef atomic_clear_mask
80554-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
80555+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
80556 {
80557 unsigned long flags;
80558
80559diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
80560index b18ce4f..2ee2843 100644
80561--- a/include/asm-generic/atomic64.h
80562+++ b/include/asm-generic/atomic64.h
80563@@ -16,6 +16,8 @@ typedef struct {
80564 long long counter;
80565 } atomic64_t;
80566
80567+typedef atomic64_t atomic64_unchecked_t;
80568+
80569 #define ATOMIC64_INIT(i) { (i) }
80570
80571 extern long long atomic64_read(const atomic64_t *v);
80572@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
80573 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
80574 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
80575
80576+#define atomic64_read_unchecked(v) atomic64_read(v)
80577+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
80578+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
80579+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
80580+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
80581+#define atomic64_inc_unchecked(v) atomic64_inc(v)
80582+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
80583+#define atomic64_dec_unchecked(v) atomic64_dec(v)
80584+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
80585+
80586 #endif /* _ASM_GENERIC_ATOMIC64_H */
80587diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
80588index 1402fa8..025a736 100644
80589--- a/include/asm-generic/barrier.h
80590+++ b/include/asm-generic/barrier.h
80591@@ -74,7 +74,7 @@
80592 do { \
80593 compiletime_assert_atomic_type(*p); \
80594 smp_mb(); \
80595- ACCESS_ONCE(*p) = (v); \
80596+ ACCESS_ONCE_RW(*p) = (v); \
80597 } while (0)
80598
80599 #define smp_load_acquire(p) \
80600diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
80601index a60a7cc..0fe12f2 100644
80602--- a/include/asm-generic/bitops/__fls.h
80603+++ b/include/asm-generic/bitops/__fls.h
80604@@ -9,7 +9,7 @@
80605 *
80606 * Undefined if no set bit exists, so code should check against 0 first.
80607 */
80608-static __always_inline unsigned long __fls(unsigned long word)
80609+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
80610 {
80611 int num = BITS_PER_LONG - 1;
80612
80613diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
80614index 0576d1f..dad6c71 100644
80615--- a/include/asm-generic/bitops/fls.h
80616+++ b/include/asm-generic/bitops/fls.h
80617@@ -9,7 +9,7 @@
80618 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
80619 */
80620
80621-static __always_inline int fls(int x)
80622+static __always_inline int __intentional_overflow(-1) fls(int x)
80623 {
80624 int r = 32;
80625
80626diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
80627index b097cf8..3d40e14 100644
80628--- a/include/asm-generic/bitops/fls64.h
80629+++ b/include/asm-generic/bitops/fls64.h
80630@@ -15,7 +15,7 @@
80631 * at position 64.
80632 */
80633 #if BITS_PER_LONG == 32
80634-static __always_inline int fls64(__u64 x)
80635+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80636 {
80637 __u32 h = x >> 32;
80638 if (h)
80639@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
80640 return fls(x);
80641 }
80642 #elif BITS_PER_LONG == 64
80643-static __always_inline int fls64(__u64 x)
80644+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80645 {
80646 if (x == 0)
80647 return 0;
80648diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
80649index 1bfcfe5..e04c5c9 100644
80650--- a/include/asm-generic/cache.h
80651+++ b/include/asm-generic/cache.h
80652@@ -6,7 +6,7 @@
80653 * cache lines need to provide their own cache.h.
80654 */
80655
80656-#define L1_CACHE_SHIFT 5
80657-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
80658+#define L1_CACHE_SHIFT 5UL
80659+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
80660
80661 #endif /* __ASM_GENERIC_CACHE_H */
80662diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
80663index 0d68a1e..b74a761 100644
80664--- a/include/asm-generic/emergency-restart.h
80665+++ b/include/asm-generic/emergency-restart.h
80666@@ -1,7 +1,7 @@
80667 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
80668 #define _ASM_GENERIC_EMERGENCY_RESTART_H
80669
80670-static inline void machine_emergency_restart(void)
80671+static inline __noreturn void machine_emergency_restart(void)
80672 {
80673 machine_restart(NULL);
80674 }
80675diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
80676index 975e1cc..0b8a083 100644
80677--- a/include/asm-generic/io.h
80678+++ b/include/asm-generic/io.h
80679@@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
80680 * These are pretty trivial
80681 */
80682 #ifndef virt_to_phys
80683-static inline unsigned long virt_to_phys(volatile void *address)
80684+static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
80685 {
80686 return __pa((unsigned long)address);
80687 }
80688diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
80689index 90f99c7..00ce236 100644
80690--- a/include/asm-generic/kmap_types.h
80691+++ b/include/asm-generic/kmap_types.h
80692@@ -2,9 +2,9 @@
80693 #define _ASM_GENERIC_KMAP_TYPES_H
80694
80695 #ifdef __WITH_KM_FENCE
80696-# define KM_TYPE_NR 41
80697+# define KM_TYPE_NR 42
80698 #else
80699-# define KM_TYPE_NR 20
80700+# define KM_TYPE_NR 21
80701 #endif
80702
80703 #endif
80704diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
80705index 9ceb03b..62b0b8f 100644
80706--- a/include/asm-generic/local.h
80707+++ b/include/asm-generic/local.h
80708@@ -23,24 +23,37 @@ typedef struct
80709 atomic_long_t a;
80710 } local_t;
80711
80712+typedef struct {
80713+ atomic_long_unchecked_t a;
80714+} local_unchecked_t;
80715+
80716 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
80717
80718 #define local_read(l) atomic_long_read(&(l)->a)
80719+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
80720 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
80721+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
80722 #define local_inc(l) atomic_long_inc(&(l)->a)
80723+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
80724 #define local_dec(l) atomic_long_dec(&(l)->a)
80725+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
80726 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
80727+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
80728 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
80729+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
80730
80731 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
80732 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
80733 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
80734 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
80735 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
80736+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
80737 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
80738 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
80739+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
80740
80741 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80742+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80743 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
80744 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
80745 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
80746diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
80747index 725612b..9cc513a 100644
80748--- a/include/asm-generic/pgtable-nopmd.h
80749+++ b/include/asm-generic/pgtable-nopmd.h
80750@@ -1,14 +1,19 @@
80751 #ifndef _PGTABLE_NOPMD_H
80752 #define _PGTABLE_NOPMD_H
80753
80754-#ifndef __ASSEMBLY__
80755-
80756 #include <asm-generic/pgtable-nopud.h>
80757
80758-struct mm_struct;
80759-
80760 #define __PAGETABLE_PMD_FOLDED
80761
80762+#define PMD_SHIFT PUD_SHIFT
80763+#define PTRS_PER_PMD 1
80764+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
80765+#define PMD_MASK (~(PMD_SIZE-1))
80766+
80767+#ifndef __ASSEMBLY__
80768+
80769+struct mm_struct;
80770+
80771 /*
80772 * Having the pmd type consist of a pud gets the size right, and allows
80773 * us to conceptually access the pud entry that this pmd is folded into
80774@@ -16,11 +21,6 @@ struct mm_struct;
80775 */
80776 typedef struct { pud_t pud; } pmd_t;
80777
80778-#define PMD_SHIFT PUD_SHIFT
80779-#define PTRS_PER_PMD 1
80780-#define PMD_SIZE (1UL << PMD_SHIFT)
80781-#define PMD_MASK (~(PMD_SIZE-1))
80782-
80783 /*
80784 * The "pud_xxx()" functions here are trivial for a folded two-level
80785 * setup: the pmd is never bad, and a pmd always exists (as it's folded
80786diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
80787index 810431d..0ec4804f 100644
80788--- a/include/asm-generic/pgtable-nopud.h
80789+++ b/include/asm-generic/pgtable-nopud.h
80790@@ -1,10 +1,15 @@
80791 #ifndef _PGTABLE_NOPUD_H
80792 #define _PGTABLE_NOPUD_H
80793
80794-#ifndef __ASSEMBLY__
80795-
80796 #define __PAGETABLE_PUD_FOLDED
80797
80798+#define PUD_SHIFT PGDIR_SHIFT
80799+#define PTRS_PER_PUD 1
80800+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
80801+#define PUD_MASK (~(PUD_SIZE-1))
80802+
80803+#ifndef __ASSEMBLY__
80804+
80805 /*
80806 * Having the pud type consist of a pgd gets the size right, and allows
80807 * us to conceptually access the pgd entry that this pud is folded into
80808@@ -12,11 +17,6 @@
80809 */
80810 typedef struct { pgd_t pgd; } pud_t;
80811
80812-#define PUD_SHIFT PGDIR_SHIFT
80813-#define PTRS_PER_PUD 1
80814-#define PUD_SIZE (1UL << PUD_SHIFT)
80815-#define PUD_MASK (~(PUD_SIZE-1))
80816-
80817 /*
80818 * The "pgd_xxx()" functions here are trivial for a folded two-level
80819 * setup: the pud is never bad, and a pud always exists (as it's folded
80820@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
80821 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
80822
80823 #define pgd_populate(mm, pgd, pud) do { } while (0)
80824+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
80825 /*
80826 * (puds are folded into pgds so this doesn't get actually called,
80827 * but the define is needed for a generic inline function.)
80828diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
80829index 53b2acc..f4568e7 100644
80830--- a/include/asm-generic/pgtable.h
80831+++ b/include/asm-generic/pgtable.h
80832@@ -819,6 +819,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
80833 }
80834 #endif /* CONFIG_NUMA_BALANCING */
80835
80836+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
80837+#ifdef CONFIG_PAX_KERNEXEC
80838+#error KERNEXEC requires pax_open_kernel
80839+#else
80840+static inline unsigned long pax_open_kernel(void) { return 0; }
80841+#endif
80842+#endif
80843+
80844+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
80845+#ifdef CONFIG_PAX_KERNEXEC
80846+#error KERNEXEC requires pax_close_kernel
80847+#else
80848+static inline unsigned long pax_close_kernel(void) { return 0; }
80849+#endif
80850+#endif
80851+
80852 #endif /* CONFIG_MMU */
80853
80854 #endif /* !__ASSEMBLY__ */
80855diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
80856index 72d8803..cb9749c 100644
80857--- a/include/asm-generic/uaccess.h
80858+++ b/include/asm-generic/uaccess.h
80859@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
80860 return __clear_user(to, n);
80861 }
80862
80863+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
80864+#ifdef CONFIG_PAX_MEMORY_UDEREF
80865+#error UDEREF requires pax_open_userland
80866+#else
80867+static inline unsigned long pax_open_userland(void) { return 0; }
80868+#endif
80869+#endif
80870+
80871+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80872+#ifdef CONFIG_PAX_MEMORY_UDEREF
80873+#error UDEREF requires pax_close_userland
80874+#else
80875+static inline unsigned long pax_close_userland(void) { return 0; }
80876+#endif
80877+#endif
80878+
80879 #endif /* __ASM_GENERIC_UACCESS_H */
80880diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80881index c1c0b0c..05c9588 100644
80882--- a/include/asm-generic/vmlinux.lds.h
80883+++ b/include/asm-generic/vmlinux.lds.h
80884@@ -231,6 +231,7 @@
80885 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80886 VMLINUX_SYMBOL(__start_rodata) = .; \
80887 *(.rodata) *(.rodata.*) \
80888+ *(.data..read_only) \
80889 *(__vermagic) /* Kernel version magic */ \
80890 . = ALIGN(8); \
80891 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80892@@ -719,17 +720,18 @@
80893 * section in the linker script will go there too. @phdr should have
80894 * a leading colon.
80895 *
80896- * Note that this macros defines __per_cpu_load as an absolute symbol.
80897+ * Note that this macros defines per_cpu_load as an absolute symbol.
80898 * If there is no need to put the percpu section at a predetermined
80899 * address, use PERCPU_SECTION.
80900 */
80901 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80902- VMLINUX_SYMBOL(__per_cpu_load) = .; \
80903- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80904+ per_cpu_load = .; \
80905+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80906 - LOAD_OFFSET) { \
80907+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80908 PERCPU_INPUT(cacheline) \
80909 } phdr \
80910- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80911+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80912
80913 /**
80914 * PERCPU_SECTION - define output section for percpu area, simple version
80915diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80916index 016c2f1..c4baa98 100644
80917--- a/include/crypto/algapi.h
80918+++ b/include/crypto/algapi.h
80919@@ -34,7 +34,7 @@ struct crypto_type {
80920 unsigned int maskclear;
80921 unsigned int maskset;
80922 unsigned int tfmsize;
80923-};
80924+} __do_const;
80925
80926 struct crypto_instance {
80927 struct crypto_alg alg;
80928diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80929index 8af71a8..7fe6c19 100644
80930--- a/include/drm/drmP.h
80931+++ b/include/drm/drmP.h
80932@@ -68,6 +68,7 @@
80933 #include <linux/workqueue.h>
80934 #include <linux/poll.h>
80935 #include <asm/pgalloc.h>
80936+#include <asm/local.h>
80937 #include <drm/drm.h>
80938 #include <drm/drm_sarea.h>
80939 #include <drm/drm_vma_manager.h>
80940@@ -261,10 +262,12 @@ do { \
80941 * \param cmd command.
80942 * \param arg argument.
80943 */
80944-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80945+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80946+ struct drm_file *file_priv);
80947+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80948 struct drm_file *file_priv);
80949
80950-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80951+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80952 unsigned long arg);
80953
80954 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80955@@ -280,10 +283,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80956 struct drm_ioctl_desc {
80957 unsigned int cmd;
80958 int flags;
80959- drm_ioctl_t *func;
80960+ drm_ioctl_t func;
80961 unsigned int cmd_drv;
80962 const char *name;
80963-};
80964+} __do_const;
80965
80966 /**
80967 * Creates a driver or general drm_ioctl_desc array entry for the given
80968@@ -983,7 +986,8 @@ struct drm_info_list {
80969 int (*show)(struct seq_file*, void*); /** show callback */
80970 u32 driver_features; /**< Required driver features for this entry */
80971 void *data;
80972-};
80973+} __do_const;
80974+typedef struct drm_info_list __no_const drm_info_list_no_const;
80975
80976 /**
80977 * debugfs node structure. This structure represents a debugfs file.
80978@@ -1067,7 +1071,7 @@ struct drm_device {
80979
80980 /** \name Usage Counters */
80981 /*@{ */
80982- int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80983+ local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80984 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80985 int buf_use; /**< Buffers in use -- cannot alloc */
80986 atomic_t buf_alloc; /**< Buffer allocation in progress */
80987diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80988index a3d75fe..6802f9c 100644
80989--- a/include/drm/drm_crtc_helper.h
80990+++ b/include/drm/drm_crtc_helper.h
80991@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80992 struct drm_connector *connector);
80993 /* disable encoder when not in use - more explicit than dpms off */
80994 void (*disable)(struct drm_encoder *encoder);
80995-};
80996+} __no_const;
80997
80998 /**
80999 * drm_connector_helper_funcs - helper operations for connectors
81000diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
81001index a70d456..6ea07cd 100644
81002--- a/include/drm/i915_pciids.h
81003+++ b/include/drm/i915_pciids.h
81004@@ -37,7 +37,7 @@
81005 */
81006 #define INTEL_VGA_DEVICE(id, info) { \
81007 0x8086, id, \
81008- ~0, ~0, \
81009+ PCI_ANY_ID, PCI_ANY_ID, \
81010 0x030000, 0xff0000, \
81011 (unsigned long) info }
81012
81013diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
81014index 72dcbe8..8db58d7 100644
81015--- a/include/drm/ttm/ttm_memory.h
81016+++ b/include/drm/ttm/ttm_memory.h
81017@@ -48,7 +48,7 @@
81018
81019 struct ttm_mem_shrink {
81020 int (*do_shrink) (struct ttm_mem_shrink *);
81021-};
81022+} __no_const;
81023
81024 /**
81025 * struct ttm_mem_global - Global memory accounting structure.
81026diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
81027index 49a8284..9643967 100644
81028--- a/include/drm/ttm/ttm_page_alloc.h
81029+++ b/include/drm/ttm/ttm_page_alloc.h
81030@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
81031 */
81032 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
81033
81034+struct device;
81035 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
81036 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
81037
81038diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
81039index 4b840e8..155d235 100644
81040--- a/include/keys/asymmetric-subtype.h
81041+++ b/include/keys/asymmetric-subtype.h
81042@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
81043 /* Verify the signature on a key of this subtype (optional) */
81044 int (*verify_signature)(const struct key *key,
81045 const struct public_key_signature *sig);
81046-};
81047+} __do_const;
81048
81049 /**
81050 * asymmetric_key_subtype - Get the subtype from an asymmetric key
81051diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
81052index c1da539..1dcec55 100644
81053--- a/include/linux/atmdev.h
81054+++ b/include/linux/atmdev.h
81055@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
81056 #endif
81057
81058 struct k_atm_aal_stats {
81059-#define __HANDLE_ITEM(i) atomic_t i
81060+#define __HANDLE_ITEM(i) atomic_unchecked_t i
81061 __AAL_STAT_ITEMS
81062 #undef __HANDLE_ITEM
81063 };
81064@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
81065 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
81066 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
81067 struct module *owner;
81068-};
81069+} __do_const ;
81070
81071 struct atmphy_ops {
81072 int (*start)(struct atm_dev *dev);
81073diff --git a/include/linux/audit.h b/include/linux/audit.h
81074index 22cfddb..ab759e8 100644
81075--- a/include/linux/audit.h
81076+++ b/include/linux/audit.h
81077@@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
81078 extern unsigned int audit_serial(void);
81079 extern int auditsc_get_stamp(struct audit_context *ctx,
81080 struct timespec *t, unsigned int *serial);
81081-extern int audit_set_loginuid(kuid_t loginuid);
81082+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
81083
81084 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
81085 {
81086diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
81087index 61f29e5..e67c658 100644
81088--- a/include/linux/binfmts.h
81089+++ b/include/linux/binfmts.h
81090@@ -44,7 +44,7 @@ struct linux_binprm {
81091 unsigned interp_flags;
81092 unsigned interp_data;
81093 unsigned long loader, exec;
81094-};
81095+} __randomize_layout;
81096
81097 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
81098 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
81099@@ -73,8 +73,10 @@ struct linux_binfmt {
81100 int (*load_binary)(struct linux_binprm *);
81101 int (*load_shlib)(struct file *);
81102 int (*core_dump)(struct coredump_params *cprm);
81103+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
81104+ void (*handle_mmap)(struct file *);
81105 unsigned long min_coredump; /* minimal dump size */
81106-};
81107+} __do_const __randomize_layout;
81108
81109 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
81110
81111diff --git a/include/linux/bitops.h b/include/linux/bitops.h
81112index cbc5833..8123ebc 100644
81113--- a/include/linux/bitops.h
81114+++ b/include/linux/bitops.h
81115@@ -122,7 +122,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
81116 * @word: value to rotate
81117 * @shift: bits to roll
81118 */
81119-static inline __u32 rol32(__u32 word, unsigned int shift)
81120+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
81121 {
81122 return (word << shift) | (word >> (32 - shift));
81123 }
81124@@ -132,7 +132,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
81125 * @word: value to rotate
81126 * @shift: bits to roll
81127 */
81128-static inline __u32 ror32(__u32 word, unsigned int shift)
81129+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
81130 {
81131 return (word >> shift) | (word << (32 - shift));
81132 }
81133@@ -188,7 +188,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
81134 return (__s32)(value << shift) >> shift;
81135 }
81136
81137-static inline unsigned fls_long(unsigned long l)
81138+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
81139 {
81140 if (sizeof(l) == 4)
81141 return fls(l);
81142diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
81143index 8699bcf..279485d 100644
81144--- a/include/linux/blkdev.h
81145+++ b/include/linux/blkdev.h
81146@@ -1625,7 +1625,7 @@ struct block_device_operations {
81147 /* this callback is with swap_lock and sometimes page table lock held */
81148 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
81149 struct module *owner;
81150-};
81151+} __do_const;
81152
81153 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
81154 unsigned long);
81155diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
81156index afc1343..9735539 100644
81157--- a/include/linux/blktrace_api.h
81158+++ b/include/linux/blktrace_api.h
81159@@ -25,7 +25,7 @@ struct blk_trace {
81160 struct dentry *dropped_file;
81161 struct dentry *msg_file;
81162 struct list_head running_list;
81163- atomic_t dropped;
81164+ atomic_unchecked_t dropped;
81165 };
81166
81167 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
81168diff --git a/include/linux/cache.h b/include/linux/cache.h
81169index 17e7e82..1d7da26 100644
81170--- a/include/linux/cache.h
81171+++ b/include/linux/cache.h
81172@@ -16,6 +16,14 @@
81173 #define __read_mostly
81174 #endif
81175
81176+#ifndef __read_only
81177+#ifdef CONFIG_PAX_KERNEXEC
81178+#error KERNEXEC requires __read_only
81179+#else
81180+#define __read_only __read_mostly
81181+#endif
81182+#endif
81183+
81184 #ifndef ____cacheline_aligned
81185 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
81186 #endif
81187diff --git a/include/linux/capability.h b/include/linux/capability.h
81188index 84b13ad..172cdee 100644
81189--- a/include/linux/capability.h
81190+++ b/include/linux/capability.h
81191@@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
81192 extern bool capable(int cap);
81193 extern bool ns_capable(struct user_namespace *ns, int cap);
81194 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
81195+extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
81196 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
81197+extern bool capable_nolog(int cap);
81198+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
81199
81200 /* audit system wants to get cap info from files as well */
81201 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
81202
81203+extern int is_privileged_binary(const struct dentry *dentry);
81204+
81205 #endif /* !_LINUX_CAPABILITY_H */
81206diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
81207index 8609d57..86e4d79 100644
81208--- a/include/linux/cdrom.h
81209+++ b/include/linux/cdrom.h
81210@@ -87,7 +87,6 @@ struct cdrom_device_ops {
81211
81212 /* driver specifications */
81213 const int capability; /* capability flags */
81214- int n_minors; /* number of active minor devices */
81215 /* handle uniform packets for scsi type devices (scsi,atapi) */
81216 int (*generic_packet) (struct cdrom_device_info *,
81217 struct packet_command *);
81218diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
81219index 4ce9056..86caac6 100644
81220--- a/include/linux/cleancache.h
81221+++ b/include/linux/cleancache.h
81222@@ -31,7 +31,7 @@ struct cleancache_ops {
81223 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
81224 void (*invalidate_inode)(int, struct cleancache_filekey);
81225 void (*invalidate_fs)(int);
81226-};
81227+} __no_const;
81228
81229 extern struct cleancache_ops *
81230 cleancache_register_ops(struct cleancache_ops *ops);
81231diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
81232index 0c287db..5efa775 100644
81233--- a/include/linux/clk-provider.h
81234+++ b/include/linux/clk-provider.h
81235@@ -180,6 +180,7 @@ struct clk_ops {
81236 void (*init)(struct clk_hw *hw);
81237 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
81238 };
81239+typedef struct clk_ops __no_const clk_ops_no_const;
81240
81241 /**
81242 * struct clk_init_data - holds init data that's common to all clocks and is
81243diff --git a/include/linux/compat.h b/include/linux/compat.h
81244index e649426..a74047b 100644
81245--- a/include/linux/compat.h
81246+++ b/include/linux/compat.h
81247@@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
81248 compat_size_t __user *len_ptr);
81249
81250 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
81251-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
81252+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
81253 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
81254 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
81255 compat_ssize_t msgsz, int msgflg);
81256@@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
81257 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
81258 compat_ulong_t addr, compat_ulong_t data);
81259 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
81260- compat_long_t addr, compat_long_t data);
81261+ compat_ulong_t addr, compat_ulong_t data);
81262
81263 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
81264 /*
81265diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
81266index 2507fd2..55203f8 100644
81267--- a/include/linux/compiler-gcc4.h
81268+++ b/include/linux/compiler-gcc4.h
81269@@ -39,9 +39,34 @@
81270 # define __compiletime_warning(message) __attribute__((warning(message)))
81271 # define __compiletime_error(message) __attribute__((error(message)))
81272 #endif /* __CHECKER__ */
81273+
81274+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
81275+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
81276+#define __bos0(ptr) __bos((ptr), 0)
81277+#define __bos1(ptr) __bos((ptr), 1)
81278 #endif /* GCC_VERSION >= 40300 */
81279
81280 #if GCC_VERSION >= 40500
81281+
81282+#ifdef RANDSTRUCT_PLUGIN
81283+#define __randomize_layout __attribute__((randomize_layout))
81284+#define __no_randomize_layout __attribute__((no_randomize_layout))
81285+#endif
81286+
81287+#ifdef CONSTIFY_PLUGIN
81288+#define __no_const __attribute__((no_const))
81289+#define __do_const __attribute__((do_const))
81290+#endif
81291+
81292+#ifdef SIZE_OVERFLOW_PLUGIN
81293+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
81294+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
81295+#endif
81296+
81297+#ifdef LATENT_ENTROPY_PLUGIN
81298+#define __latent_entropy __attribute__((latent_entropy))
81299+#endif
81300+
81301 /*
81302 * Mark a position in code as unreachable. This can be used to
81303 * suppress control flow warnings after asm blocks that transfer
81304diff --git a/include/linux/compiler.h b/include/linux/compiler.h
81305index d5ad7b1..3b74638 100644
81306--- a/include/linux/compiler.h
81307+++ b/include/linux/compiler.h
81308@@ -5,11 +5,14 @@
81309
81310 #ifdef __CHECKER__
81311 # define __user __attribute__((noderef, address_space(1)))
81312+# define __force_user __force __user
81313 # define __kernel __attribute__((address_space(0)))
81314+# define __force_kernel __force __kernel
81315 # define __safe __attribute__((safe))
81316 # define __force __attribute__((force))
81317 # define __nocast __attribute__((nocast))
81318 # define __iomem __attribute__((noderef, address_space(2)))
81319+# define __force_iomem __force __iomem
81320 # define __must_hold(x) __attribute__((context(x,1,1)))
81321 # define __acquires(x) __attribute__((context(x,0,1)))
81322 # define __releases(x) __attribute__((context(x,1,0)))
81323@@ -17,20 +20,37 @@
81324 # define __release(x) __context__(x,-1)
81325 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
81326 # define __percpu __attribute__((noderef, address_space(3)))
81327+# define __force_percpu __force __percpu
81328 #ifdef CONFIG_SPARSE_RCU_POINTER
81329 # define __rcu __attribute__((noderef, address_space(4)))
81330+# define __force_rcu __force __rcu
81331 #else
81332 # define __rcu
81333+# define __force_rcu
81334 #endif
81335 extern void __chk_user_ptr(const volatile void __user *);
81336 extern void __chk_io_ptr(const volatile void __iomem *);
81337 #else
81338-# define __user
81339-# define __kernel
81340+# ifdef CHECKER_PLUGIN
81341+//# define __user
81342+//# define __force_user
81343+//# define __kernel
81344+//# define __force_kernel
81345+# else
81346+# ifdef STRUCTLEAK_PLUGIN
81347+# define __user __attribute__((user))
81348+# else
81349+# define __user
81350+# endif
81351+# define __force_user
81352+# define __kernel
81353+# define __force_kernel
81354+# endif
81355 # define __safe
81356 # define __force
81357 # define __nocast
81358 # define __iomem
81359+# define __force_iomem
81360 # define __chk_user_ptr(x) (void)0
81361 # define __chk_io_ptr(x) (void)0
81362 # define __builtin_warning(x, y...) (1)
81363@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
81364 # define __release(x) (void)0
81365 # define __cond_lock(x,c) (c)
81366 # define __percpu
81367+# define __force_percpu
81368 # define __rcu
81369+# define __force_rcu
81370 #endif
81371
81372 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
81373@@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
81374 # define __attribute_const__ /* unimplemented */
81375 #endif
81376
81377+#ifndef __randomize_layout
81378+# define __randomize_layout
81379+#endif
81380+
81381+#ifndef __no_randomize_layout
81382+# define __no_randomize_layout
81383+#endif
81384+
81385+#ifndef __no_const
81386+# define __no_const
81387+#endif
81388+
81389+#ifndef __do_const
81390+# define __do_const
81391+#endif
81392+
81393+#ifndef __size_overflow
81394+# define __size_overflow(...)
81395+#endif
81396+
81397+#ifndef __intentional_overflow
81398+# define __intentional_overflow(...)
81399+#endif
81400+
81401+#ifndef __latent_entropy
81402+# define __latent_entropy
81403+#endif
81404+
81405 /*
81406 * Tell gcc if a function is cold. The compiler will assume any path
81407 * directly leading to the call is unlikely.
81408@@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
81409 #define __cold
81410 #endif
81411
81412+#ifndef __alloc_size
81413+#define __alloc_size(...)
81414+#endif
81415+
81416+#ifndef __bos
81417+#define __bos(ptr, arg)
81418+#endif
81419+
81420+#ifndef __bos0
81421+#define __bos0(ptr)
81422+#endif
81423+
81424+#ifndef __bos1
81425+#define __bos1(ptr)
81426+#endif
81427+
81428 /* Simple shorthand for a section definition */
81429 #ifndef __section
81430 # define __section(S) __attribute__ ((__section__(#S)))
81431@@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
81432 * use is to mediate communication between process-level code and irq/NMI
81433 * handlers, all running on the same CPU.
81434 */
81435-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
81436+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
81437+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
81438
81439 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
81440 #ifdef CONFIG_KPROBES
81441diff --git a/include/linux/completion.h b/include/linux/completion.h
81442index 5d5aaae..0ea9b84 100644
81443--- a/include/linux/completion.h
81444+++ b/include/linux/completion.h
81445@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
81446
81447 extern void wait_for_completion(struct completion *);
81448 extern void wait_for_completion_io(struct completion *);
81449-extern int wait_for_completion_interruptible(struct completion *x);
81450-extern int wait_for_completion_killable(struct completion *x);
81451+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
81452+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
81453 extern unsigned long wait_for_completion_timeout(struct completion *x,
81454- unsigned long timeout);
81455+ unsigned long timeout) __intentional_overflow(-1);
81456 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
81457- unsigned long timeout);
81458+ unsigned long timeout) __intentional_overflow(-1);
81459 extern long wait_for_completion_interruptible_timeout(
81460- struct completion *x, unsigned long timeout);
81461+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
81462 extern long wait_for_completion_killable_timeout(
81463- struct completion *x, unsigned long timeout);
81464+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
81465 extern bool try_wait_for_completion(struct completion *x);
81466 extern bool completion_done(struct completion *x);
81467
81468diff --git a/include/linux/configfs.h b/include/linux/configfs.h
81469index 34025df..d94bbbc 100644
81470--- a/include/linux/configfs.h
81471+++ b/include/linux/configfs.h
81472@@ -125,7 +125,7 @@ struct configfs_attribute {
81473 const char *ca_name;
81474 struct module *ca_owner;
81475 umode_t ca_mode;
81476-};
81477+} __do_const;
81478
81479 /*
81480 * Users often need to create attribute structures for their configurable
81481diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
81482index 8f8ae95..b9b0e6d 100644
81483--- a/include/linux/cpufreq.h
81484+++ b/include/linux/cpufreq.h
81485@@ -202,6 +202,7 @@ struct global_attr {
81486 ssize_t (*store)(struct kobject *a, struct attribute *b,
81487 const char *c, size_t count);
81488 };
81489+typedef struct global_attr __no_const global_attr_no_const;
81490
81491 #define define_one_global_ro(_name) \
81492 static struct global_attr _name = \
81493@@ -268,7 +269,7 @@ struct cpufreq_driver {
81494 bool boost_supported;
81495 bool boost_enabled;
81496 int (*set_boost) (int state);
81497-};
81498+} __do_const;
81499
81500 /* flags */
81501 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
81502diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
81503index 25e0df6..952dffd 100644
81504--- a/include/linux/cpuidle.h
81505+++ b/include/linux/cpuidle.h
81506@@ -50,7 +50,8 @@ struct cpuidle_state {
81507 int index);
81508
81509 int (*enter_dead) (struct cpuidle_device *dev, int index);
81510-};
81511+} __do_const;
81512+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
81513
81514 /* Idle State Flags */
81515 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
81516@@ -209,7 +210,7 @@ struct cpuidle_governor {
81517 void (*reflect) (struct cpuidle_device *dev, int index);
81518
81519 struct module *owner;
81520-};
81521+} __do_const;
81522
81523 #ifdef CONFIG_CPU_IDLE
81524 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
81525diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
81526index 2997af6..424ddc1 100644
81527--- a/include/linux/cpumask.h
81528+++ b/include/linux/cpumask.h
81529@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
81530 }
81531
81532 /* Valid inputs for n are -1 and 0. */
81533-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81534+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
81535 {
81536 return n+1;
81537 }
81538
81539-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81540+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
81541 {
81542 return n+1;
81543 }
81544
81545-static inline unsigned int cpumask_next_and(int n,
81546+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
81547 const struct cpumask *srcp,
81548 const struct cpumask *andp)
81549 {
81550@@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
81551 *
81552 * Returns >= nr_cpu_ids if no further cpus set.
81553 */
81554-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81555+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
81556 {
81557 /* -1 is a legal arg here. */
81558 if (n != -1)
81559@@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81560 *
81561 * Returns >= nr_cpu_ids if no further cpus unset.
81562 */
81563-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81564+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
81565 {
81566 /* -1 is a legal arg here. */
81567 if (n != -1)
81568@@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81569 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
81570 }
81571
81572-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
81573+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
81574 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
81575 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
81576
81577diff --git a/include/linux/cred.h b/include/linux/cred.h
81578index f61d6c8..d372d95 100644
81579--- a/include/linux/cred.h
81580+++ b/include/linux/cred.h
81581@@ -35,7 +35,7 @@ struct group_info {
81582 int nblocks;
81583 kgid_t small_block[NGROUPS_SMALL];
81584 kgid_t *blocks[0];
81585-};
81586+} __randomize_layout;
81587
81588 /**
81589 * get_group_info - Get a reference to a group info structure
81590@@ -136,7 +136,7 @@ struct cred {
81591 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
81592 struct group_info *group_info; /* supplementary groups for euid/fsgid */
81593 struct rcu_head rcu; /* RCU deletion hook */
81594-};
81595+} __randomize_layout;
81596
81597 extern void __put_cred(struct cred *);
81598 extern void exit_creds(struct task_struct *);
81599@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
81600 static inline void validate_process_creds(void)
81601 {
81602 }
81603+static inline void validate_task_creds(struct task_struct *task)
81604+{
81605+}
81606 #endif
81607
81608 /**
81609@@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
81610
81611 #define task_uid(task) (task_cred_xxx((task), uid))
81612 #define task_euid(task) (task_cred_xxx((task), euid))
81613+#define task_securebits(task) (task_cred_xxx((task), securebits))
81614
81615 #define current_cred_xxx(xxx) \
81616 ({ \
81617diff --git a/include/linux/crypto.h b/include/linux/crypto.h
81618index b92eadf..b4ecdc1 100644
81619--- a/include/linux/crypto.h
81620+++ b/include/linux/crypto.h
81621@@ -373,7 +373,7 @@ struct cipher_tfm {
81622 const u8 *key, unsigned int keylen);
81623 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81624 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81625-};
81626+} __no_const;
81627
81628 struct hash_tfm {
81629 int (*init)(struct hash_desc *desc);
81630@@ -394,13 +394,13 @@ struct compress_tfm {
81631 int (*cot_decompress)(struct crypto_tfm *tfm,
81632 const u8 *src, unsigned int slen,
81633 u8 *dst, unsigned int *dlen);
81634-};
81635+} __no_const;
81636
81637 struct rng_tfm {
81638 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
81639 unsigned int dlen);
81640 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
81641-};
81642+} __no_const;
81643
81644 #define crt_ablkcipher crt_u.ablkcipher
81645 #define crt_aead crt_u.aead
81646diff --git a/include/linux/ctype.h b/include/linux/ctype.h
81647index 653589e..4ef254a 100644
81648--- a/include/linux/ctype.h
81649+++ b/include/linux/ctype.h
81650@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
81651 * Fast implementation of tolower() for internal usage. Do not use in your
81652 * code.
81653 */
81654-static inline char _tolower(const char c)
81655+static inline unsigned char _tolower(const unsigned char c)
81656 {
81657 return c | 0x20;
81658 }
81659diff --git a/include/linux/dcache.h b/include/linux/dcache.h
81660index 3c7ec32..4ca97cc 100644
81661--- a/include/linux/dcache.h
81662+++ b/include/linux/dcache.h
81663@@ -133,7 +133,7 @@ struct dentry {
81664 } d_u;
81665 struct list_head d_subdirs; /* our children */
81666 struct hlist_node d_alias; /* inode alias list */
81667-};
81668+} __randomize_layout;
81669
81670 /*
81671 * dentry->d_lock spinlock nesting subclasses:
81672diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
81673index 7925bf0..d5143d2 100644
81674--- a/include/linux/decompress/mm.h
81675+++ b/include/linux/decompress/mm.h
81676@@ -77,7 +77,7 @@ static void free(void *where)
81677 * warnings when not needed (indeed large_malloc / large_free are not
81678 * needed by inflate */
81679
81680-#define malloc(a) kmalloc(a, GFP_KERNEL)
81681+#define malloc(a) kmalloc((a), GFP_KERNEL)
81682 #define free(a) kfree(a)
81683
81684 #define large_malloc(a) vmalloc(a)
81685diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
81686index f1863dc..5c26074 100644
81687--- a/include/linux/devfreq.h
81688+++ b/include/linux/devfreq.h
81689@@ -114,7 +114,7 @@ struct devfreq_governor {
81690 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
81691 int (*event_handler)(struct devfreq *devfreq,
81692 unsigned int event, void *data);
81693-};
81694+} __do_const;
81695
81696 /**
81697 * struct devfreq - Device devfreq structure
81698diff --git a/include/linux/device.h b/include/linux/device.h
81699index af424ac..fd46ddf 100644
81700--- a/include/linux/device.h
81701+++ b/include/linux/device.h
81702@@ -310,7 +310,7 @@ struct subsys_interface {
81703 struct list_head node;
81704 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
81705 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
81706-};
81707+} __do_const;
81708
81709 int subsys_interface_register(struct subsys_interface *sif);
81710 void subsys_interface_unregister(struct subsys_interface *sif);
81711@@ -506,7 +506,7 @@ struct device_type {
81712 void (*release)(struct device *dev);
81713
81714 const struct dev_pm_ops *pm;
81715-};
81716+} __do_const;
81717
81718 /* interface for exporting device attributes */
81719 struct device_attribute {
81720@@ -516,11 +516,12 @@ struct device_attribute {
81721 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
81722 const char *buf, size_t count);
81723 };
81724+typedef struct device_attribute __no_const device_attribute_no_const;
81725
81726 struct dev_ext_attribute {
81727 struct device_attribute attr;
81728 void *var;
81729-};
81730+} __do_const;
81731
81732 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
81733 char *buf);
81734diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
81735index 931b709..89b2d89 100644
81736--- a/include/linux/dma-mapping.h
81737+++ b/include/linux/dma-mapping.h
81738@@ -60,7 +60,7 @@ struct dma_map_ops {
81739 u64 (*get_required_mask)(struct device *dev);
81740 #endif
81741 int is_phys;
81742-};
81743+} __do_const;
81744
81745 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
81746
81747diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
81748index d2c5cc7..d193394 100644
81749--- a/include/linux/dmaengine.h
81750+++ b/include/linux/dmaengine.h
81751@@ -1147,9 +1147,9 @@ struct dma_pinned_list {
81752 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
81753 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
81754
81755-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81756+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81757 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
81758-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81759+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81760 struct dma_pinned_list *pinned_list, struct page *page,
81761 unsigned int offset, size_t len);
81762
81763diff --git a/include/linux/efi.h b/include/linux/efi.h
81764index 41bbf8b..bd3a718 100644
81765--- a/include/linux/efi.h
81766+++ b/include/linux/efi.h
81767@@ -1027,6 +1027,7 @@ struct efivar_operations {
81768 efi_set_variable_t *set_variable;
81769 efi_query_variable_store_t *query_variable_store;
81770 };
81771+typedef struct efivar_operations __no_const efivar_operations_no_const;
81772
81773 struct efivars {
81774 /*
81775diff --git a/include/linux/elf.h b/include/linux/elf.h
81776index 67a5fa7..b817372 100644
81777--- a/include/linux/elf.h
81778+++ b/include/linux/elf.h
81779@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
81780 #define elf_note elf32_note
81781 #define elf_addr_t Elf32_Off
81782 #define Elf_Half Elf32_Half
81783+#define elf_dyn Elf32_Dyn
81784
81785 #else
81786
81787@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
81788 #define elf_note elf64_note
81789 #define elf_addr_t Elf64_Off
81790 #define Elf_Half Elf64_Half
81791+#define elf_dyn Elf64_Dyn
81792
81793 #endif
81794
81795diff --git a/include/linux/err.h b/include/linux/err.h
81796index a729120..6ede2c9 100644
81797--- a/include/linux/err.h
81798+++ b/include/linux/err.h
81799@@ -20,12 +20,12 @@
81800
81801 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
81802
81803-static inline void * __must_check ERR_PTR(long error)
81804+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
81805 {
81806 return (void *) error;
81807 }
81808
81809-static inline long __must_check PTR_ERR(__force const void *ptr)
81810+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
81811 {
81812 return (long) ptr;
81813 }
81814diff --git a/include/linux/extcon.h b/include/linux/extcon.h
81815index 36f49c4..a2a1f4c 100644
81816--- a/include/linux/extcon.h
81817+++ b/include/linux/extcon.h
81818@@ -135,7 +135,7 @@ struct extcon_dev {
81819 /* /sys/class/extcon/.../mutually_exclusive/... */
81820 struct attribute_group attr_g_muex;
81821 struct attribute **attrs_muex;
81822- struct device_attribute *d_attrs_muex;
81823+ device_attribute_no_const *d_attrs_muex;
81824 };
81825
81826 /**
81827diff --git a/include/linux/fb.h b/include/linux/fb.h
81828index b6bfda9..1f13487 100644
81829--- a/include/linux/fb.h
81830+++ b/include/linux/fb.h
81831@@ -305,7 +305,7 @@ struct fb_ops {
81832 /* called at KDB enter and leave time to prepare the console */
81833 int (*fb_debug_enter)(struct fb_info *info);
81834 int (*fb_debug_leave)(struct fb_info *info);
81835-};
81836+} __do_const;
81837
81838 #ifdef CONFIG_FB_TILEBLITTING
81839 #define FB_TILE_CURSOR_NONE 0
81840diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81841index 230f87b..1fd0485 100644
81842--- a/include/linux/fdtable.h
81843+++ b/include/linux/fdtable.h
81844@@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81845 void put_files_struct(struct files_struct *fs);
81846 void reset_files_struct(struct files_struct *);
81847 int unshare_files(struct files_struct **);
81848-struct files_struct *dup_fd(struct files_struct *, int *);
81849+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81850 void do_close_on_exec(struct files_struct *);
81851 int iterate_fd(struct files_struct *, unsigned,
81852 int (*)(const void *, struct file *, unsigned),
81853diff --git a/include/linux/filter.h b/include/linux/filter.h
81854index a7e3c48..e568c8e 100644
81855--- a/include/linux/filter.h
81856+++ b/include/linux/filter.h
81857@@ -9,330 +9,28 @@
81858 #include <linux/workqueue.h>
81859 #include <uapi/linux/filter.h>
81860
81861-/* Internally used and optimized filter representation with extended
81862- * instruction set based on top of classic BPF.
81863- */
81864-
81865-/* instruction classes */
81866-#define BPF_ALU64 0x07 /* alu mode in double word width */
81867-
81868-/* ld/ldx fields */
81869-#define BPF_DW 0x18 /* double word */
81870-#define BPF_XADD 0xc0 /* exclusive add */
81871-
81872-/* alu/jmp fields */
81873-#define BPF_MOV 0xb0 /* mov reg to reg */
81874-#define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */
81875-
81876-/* change endianness of a register */
81877-#define BPF_END 0xd0 /* flags for endianness conversion: */
81878-#define BPF_TO_LE 0x00 /* convert to little-endian */
81879-#define BPF_TO_BE 0x08 /* convert to big-endian */
81880-#define BPF_FROM_LE BPF_TO_LE
81881-#define BPF_FROM_BE BPF_TO_BE
81882-
81883-#define BPF_JNE 0x50 /* jump != */
81884-#define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */
81885-#define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */
81886-#define BPF_CALL 0x80 /* function call */
81887-#define BPF_EXIT 0x90 /* function return */
81888-
81889-/* Register numbers */
81890-enum {
81891- BPF_REG_0 = 0,
81892- BPF_REG_1,
81893- BPF_REG_2,
81894- BPF_REG_3,
81895- BPF_REG_4,
81896- BPF_REG_5,
81897- BPF_REG_6,
81898- BPF_REG_7,
81899- BPF_REG_8,
81900- BPF_REG_9,
81901- BPF_REG_10,
81902- __MAX_BPF_REG,
81903-};
81904-
81905-/* BPF has 10 general purpose 64-bit registers and stack frame. */
81906-#define MAX_BPF_REG __MAX_BPF_REG
81907-
81908-/* ArgX, context and stack frame pointer register positions. Note,
81909- * Arg1, Arg2, Arg3, etc are used as argument mappings of function
81910- * calls in BPF_CALL instruction.
81911- */
81912-#define BPF_REG_ARG1 BPF_REG_1
81913-#define BPF_REG_ARG2 BPF_REG_2
81914-#define BPF_REG_ARG3 BPF_REG_3
81915-#define BPF_REG_ARG4 BPF_REG_4
81916-#define BPF_REG_ARG5 BPF_REG_5
81917-#define BPF_REG_CTX BPF_REG_6
81918-#define BPF_REG_FP BPF_REG_10
81919-
81920-/* Additional register mappings for converted user programs. */
81921-#define BPF_REG_A BPF_REG_0
81922-#define BPF_REG_X BPF_REG_7
81923-#define BPF_REG_TMP BPF_REG_8
81924-
81925-/* BPF program can access up to 512 bytes of stack space. */
81926-#define MAX_BPF_STACK 512
81927-
81928-/* Helper macros for filter block array initializers. */
81929-
81930-/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */
81931-
81932-#define BPF_ALU64_REG(OP, DST, SRC) \
81933- ((struct sock_filter_int) { \
81934- .code = BPF_ALU64 | BPF_OP(OP) | BPF_X, \
81935- .dst_reg = DST, \
81936- .src_reg = SRC, \
81937- .off = 0, \
81938- .imm = 0 })
81939-
81940-#define BPF_ALU32_REG(OP, DST, SRC) \
81941- ((struct sock_filter_int) { \
81942- .code = BPF_ALU | BPF_OP(OP) | BPF_X, \
81943- .dst_reg = DST, \
81944- .src_reg = SRC, \
81945- .off = 0, \
81946- .imm = 0 })
81947-
81948-/* ALU ops on immediates, bpf_add|sub|...: dst_reg += imm32 */
81949-
81950-#define BPF_ALU64_IMM(OP, DST, IMM) \
81951- ((struct sock_filter_int) { \
81952- .code = BPF_ALU64 | BPF_OP(OP) | BPF_K, \
81953- .dst_reg = DST, \
81954- .src_reg = 0, \
81955- .off = 0, \
81956- .imm = IMM })
81957-
81958-#define BPF_ALU32_IMM(OP, DST, IMM) \
81959- ((struct sock_filter_int) { \
81960- .code = BPF_ALU | BPF_OP(OP) | BPF_K, \
81961- .dst_reg = DST, \
81962- .src_reg = 0, \
81963- .off = 0, \
81964- .imm = IMM })
81965-
81966-/* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */
81967-
81968-#define BPF_ENDIAN(TYPE, DST, LEN) \
81969- ((struct sock_filter_int) { \
81970- .code = BPF_ALU | BPF_END | BPF_SRC(TYPE), \
81971- .dst_reg = DST, \
81972- .src_reg = 0, \
81973- .off = 0, \
81974- .imm = LEN })
81975-
81976-/* Short form of mov, dst_reg = src_reg */
81977-
81978-#define BPF_MOV64_REG(DST, SRC) \
81979- ((struct sock_filter_int) { \
81980- .code = BPF_ALU64 | BPF_MOV | BPF_X, \
81981- .dst_reg = DST, \
81982- .src_reg = SRC, \
81983- .off = 0, \
81984- .imm = 0 })
81985-
81986-#define BPF_MOV32_REG(DST, SRC) \
81987- ((struct sock_filter_int) { \
81988- .code = BPF_ALU | BPF_MOV | BPF_X, \
81989- .dst_reg = DST, \
81990- .src_reg = SRC, \
81991- .off = 0, \
81992- .imm = 0 })
81993-
81994-/* Short form of mov, dst_reg = imm32 */
81995-
81996-#define BPF_MOV64_IMM(DST, IMM) \
81997- ((struct sock_filter_int) { \
81998- .code = BPF_ALU64 | BPF_MOV | BPF_K, \
81999- .dst_reg = DST, \
82000- .src_reg = 0, \
82001- .off = 0, \
82002- .imm = IMM })
82003-
82004-#define BPF_MOV32_IMM(DST, IMM) \
82005- ((struct sock_filter_int) { \
82006- .code = BPF_ALU | BPF_MOV | BPF_K, \
82007- .dst_reg = DST, \
82008- .src_reg = 0, \
82009- .off = 0, \
82010- .imm = IMM })
82011-
82012-/* Short form of mov based on type, BPF_X: dst_reg = src_reg, BPF_K: dst_reg = imm32 */
82013-
82014-#define BPF_MOV64_RAW(TYPE, DST, SRC, IMM) \
82015- ((struct sock_filter_int) { \
82016- .code = BPF_ALU64 | BPF_MOV | BPF_SRC(TYPE), \
82017- .dst_reg = DST, \
82018- .src_reg = SRC, \
82019- .off = 0, \
82020- .imm = IMM })
82021-
82022-#define BPF_MOV32_RAW(TYPE, DST, SRC, IMM) \
82023- ((struct sock_filter_int) { \
82024- .code = BPF_ALU | BPF_MOV | BPF_SRC(TYPE), \
82025- .dst_reg = DST, \
82026- .src_reg = SRC, \
82027- .off = 0, \
82028- .imm = IMM })
82029-
82030-/* Direct packet access, R0 = *(uint *) (skb->data + imm32) */
82031-
82032-#define BPF_LD_ABS(SIZE, IMM) \
82033- ((struct sock_filter_int) { \
82034- .code = BPF_LD | BPF_SIZE(SIZE) | BPF_ABS, \
82035- .dst_reg = 0, \
82036- .src_reg = 0, \
82037- .off = 0, \
82038- .imm = IMM })
82039-
82040-/* Indirect packet access, R0 = *(uint *) (skb->data + src_reg + imm32) */
82041-
82042-#define BPF_LD_IND(SIZE, SRC, IMM) \
82043- ((struct sock_filter_int) { \
82044- .code = BPF_LD | BPF_SIZE(SIZE) | BPF_IND, \
82045- .dst_reg = 0, \
82046- .src_reg = SRC, \
82047- .off = 0, \
82048- .imm = IMM })
82049-
82050-/* Memory load, dst_reg = *(uint *) (src_reg + off16) */
82051-
82052-#define BPF_LDX_MEM(SIZE, DST, SRC, OFF) \
82053- ((struct sock_filter_int) { \
82054- .code = BPF_LDX | BPF_SIZE(SIZE) | BPF_MEM, \
82055- .dst_reg = DST, \
82056- .src_reg = SRC, \
82057- .off = OFF, \
82058- .imm = 0 })
82059-
82060-/* Memory store, *(uint *) (dst_reg + off16) = src_reg */
82061-
82062-#define BPF_STX_MEM(SIZE, DST, SRC, OFF) \
82063- ((struct sock_filter_int) { \
82064- .code = BPF_STX | BPF_SIZE(SIZE) | BPF_MEM, \
82065- .dst_reg = DST, \
82066- .src_reg = SRC, \
82067- .off = OFF, \
82068- .imm = 0 })
82069-
82070-/* Memory store, *(uint *) (dst_reg + off16) = imm32 */
82071-
82072-#define BPF_ST_MEM(SIZE, DST, OFF, IMM) \
82073- ((struct sock_filter_int) { \
82074- .code = BPF_ST | BPF_SIZE(SIZE) | BPF_MEM, \
82075- .dst_reg = DST, \
82076- .src_reg = 0, \
82077- .off = OFF, \
82078- .imm = IMM })
82079-
82080-/* Conditional jumps against registers, if (dst_reg 'op' src_reg) goto pc + off16 */
82081-
82082-#define BPF_JMP_REG(OP, DST, SRC, OFF) \
82083- ((struct sock_filter_int) { \
82084- .code = BPF_JMP | BPF_OP(OP) | BPF_X, \
82085- .dst_reg = DST, \
82086- .src_reg = SRC, \
82087- .off = OFF, \
82088- .imm = 0 })
82089-
82090-/* Conditional jumps against immediates, if (dst_reg 'op' imm32) goto pc + off16 */
82091-
82092-#define BPF_JMP_IMM(OP, DST, IMM, OFF) \
82093- ((struct sock_filter_int) { \
82094- .code = BPF_JMP | BPF_OP(OP) | BPF_K, \
82095- .dst_reg = DST, \
82096- .src_reg = 0, \
82097- .off = OFF, \
82098- .imm = IMM })
82099-
82100-/* Function call */
82101-
82102-#define BPF_EMIT_CALL(FUNC) \
82103- ((struct sock_filter_int) { \
82104- .code = BPF_JMP | BPF_CALL, \
82105- .dst_reg = 0, \
82106- .src_reg = 0, \
82107- .off = 0, \
82108- .imm = ((FUNC) - __bpf_call_base) })
82109-
82110-/* Raw code statement block */
82111-
82112-#define BPF_RAW_INSN(CODE, DST, SRC, OFF, IMM) \
82113- ((struct sock_filter_int) { \
82114- .code = CODE, \
82115- .dst_reg = DST, \
82116- .src_reg = SRC, \
82117- .off = OFF, \
82118- .imm = IMM })
82119-
82120-/* Program exit */
82121-
82122-#define BPF_EXIT_INSN() \
82123- ((struct sock_filter_int) { \
82124- .code = BPF_JMP | BPF_EXIT, \
82125- .dst_reg = 0, \
82126- .src_reg = 0, \
82127- .off = 0, \
82128- .imm = 0 })
82129-
82130-#define bytes_to_bpf_size(bytes) \
82131-({ \
82132- int bpf_size = -EINVAL; \
82133- \
82134- if (bytes == sizeof(u8)) \
82135- bpf_size = BPF_B; \
82136- else if (bytes == sizeof(u16)) \
82137- bpf_size = BPF_H; \
82138- else if (bytes == sizeof(u32)) \
82139- bpf_size = BPF_W; \
82140- else if (bytes == sizeof(u64)) \
82141- bpf_size = BPF_DW; \
82142- \
82143- bpf_size; \
82144-})
82145-
82146-/* Macro to invoke filter function. */
82147-#define SK_RUN_FILTER(filter, ctx) (*filter->bpf_func)(ctx, filter->insnsi)
82148-
82149-struct sock_filter_int {
82150- __u8 code; /* opcode */
82151- __u8 dst_reg:4; /* dest register */
82152- __u8 src_reg:4; /* source register */
82153- __s16 off; /* signed offset */
82154- __s32 imm; /* signed immediate constant */
82155-};
82156-
82157 #ifdef CONFIG_COMPAT
82158-/* A struct sock_filter is architecture independent. */
82159+/*
82160+ * A struct sock_filter is architecture independent.
82161+ */
82162 struct compat_sock_fprog {
82163 u16 len;
82164- compat_uptr_t filter; /* struct sock_filter * */
82165+ compat_uptr_t filter; /* struct sock_filter * */
82166 };
82167 #endif
82168
82169-struct sock_fprog_kern {
82170- u16 len;
82171- struct sock_filter *filter;
82172-};
82173-
82174 struct sk_buff;
82175 struct sock;
82176-struct seccomp_data;
82177
82178-struct sk_filter {
82179+struct sk_filter
82180+{
82181 atomic_t refcnt;
82182- u32 jited:1, /* Is our filter JIT'ed? */
82183- len:31; /* Number of filter blocks */
82184- struct sock_fprog_kern *orig_prog; /* Original BPF program */
82185+ unsigned int len; /* Number of filter blocks */
82186 struct rcu_head rcu;
82187 unsigned int (*bpf_func)(const struct sk_buff *skb,
82188- const struct sock_filter_int *filter);
82189+ const struct sock_filter *filter);
82190 union {
82191- struct sock_filter insns[0];
82192- struct sock_filter_int insnsi[0];
82193+ struct sock_filter insns[0];
82194 struct work_struct work;
82195 };
82196 };
82197@@ -343,76 +41,25 @@ static inline unsigned int sk_filter_size(unsigned int proglen)
82198 offsetof(struct sk_filter, insns[proglen]));
82199 }
82200
82201-#define sk_filter_proglen(fprog) \
82202- (fprog->len * sizeof(fprog->filter[0]))
82203-
82204-int sk_filter(struct sock *sk, struct sk_buff *skb);
82205-
82206-void sk_filter_select_runtime(struct sk_filter *fp);
82207-void sk_filter_free(struct sk_filter *fp);
82208-
82209-int sk_convert_filter(struct sock_filter *prog, int len,
82210- struct sock_filter_int *new_prog, int *new_len);
82211-
82212-int sk_unattached_filter_create(struct sk_filter **pfp,
82213- struct sock_fprog_kern *fprog);
82214-void sk_unattached_filter_destroy(struct sk_filter *fp);
82215-
82216-int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
82217-int sk_detach_filter(struct sock *sk);
82218-
82219-int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
82220-int sk_get_filter(struct sock *sk, struct sock_filter __user *filter,
82221- unsigned int len);
82222-
82223-void sk_filter_charge(struct sock *sk, struct sk_filter *fp);
82224-void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp);
82225-
82226-u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
82227-void bpf_int_jit_compile(struct sk_filter *fp);
82228-
82229-#define BPF_ANC BIT(15)
82230-
82231-static inline u16 bpf_anc_helper(const struct sock_filter *ftest)
82232-{
82233- BUG_ON(ftest->code & BPF_ANC);
82234-
82235- switch (ftest->code) {
82236- case BPF_LD | BPF_W | BPF_ABS:
82237- case BPF_LD | BPF_H | BPF_ABS:
82238- case BPF_LD | BPF_B | BPF_ABS:
82239-#define BPF_ANCILLARY(CODE) case SKF_AD_OFF + SKF_AD_##CODE: \
82240- return BPF_ANC | SKF_AD_##CODE
82241- switch (ftest->k) {
82242- BPF_ANCILLARY(PROTOCOL);
82243- BPF_ANCILLARY(PKTTYPE);
82244- BPF_ANCILLARY(IFINDEX);
82245- BPF_ANCILLARY(NLATTR);
82246- BPF_ANCILLARY(NLATTR_NEST);
82247- BPF_ANCILLARY(MARK);
82248- BPF_ANCILLARY(QUEUE);
82249- BPF_ANCILLARY(HATYPE);
82250- BPF_ANCILLARY(RXHASH);
82251- BPF_ANCILLARY(CPU);
82252- BPF_ANCILLARY(ALU_XOR_X);
82253- BPF_ANCILLARY(VLAN_TAG);
82254- BPF_ANCILLARY(VLAN_TAG_PRESENT);
82255- BPF_ANCILLARY(PAY_OFFSET);
82256- BPF_ANCILLARY(RANDOM);
82257- }
82258- /* Fallthrough. */
82259- default:
82260- return ftest->code;
82261- }
82262-}
82263+extern int sk_filter(struct sock *sk, struct sk_buff *skb);
82264+extern unsigned int sk_run_filter(const struct sk_buff *skb,
82265+ const struct sock_filter *filter);
82266+extern int sk_unattached_filter_create(struct sk_filter **pfp,
82267+ struct sock_fprog *fprog);
82268+extern void sk_unattached_filter_destroy(struct sk_filter *fp);
82269+extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
82270+extern int sk_detach_filter(struct sock *sk);
82271+extern int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
82272+extern int sk_get_filter(struct sock *sk, struct sock_filter __user *filter, unsigned len);
82273+extern void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to);
82274
82275 #ifdef CONFIG_BPF_JIT
82276 #include <stdarg.h>
82277 #include <linux/linkage.h>
82278 #include <linux/printk.h>
82279
82280-void bpf_jit_compile(struct sk_filter *fp);
82281-void bpf_jit_free(struct sk_filter *fp);
82282+extern void bpf_jit_compile(struct sk_filter *fp);
82283+extern void bpf_jit_free(struct sk_filter *fp);
82284
82285 static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
82286 u32 pass, void *image)
82287@@ -423,22 +70,90 @@ static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
82288 print_hex_dump(KERN_ERR, "JIT code: ", DUMP_PREFIX_OFFSET,
82289 16, 1, image, proglen, false);
82290 }
82291+#define SK_RUN_FILTER(FILTER, SKB) (*FILTER->bpf_func)(SKB, FILTER->insns)
82292 #else
82293 #include <linux/slab.h>
82294-
82295 static inline void bpf_jit_compile(struct sk_filter *fp)
82296 {
82297 }
82298-
82299 static inline void bpf_jit_free(struct sk_filter *fp)
82300 {
82301 kfree(fp);
82302 }
82303-#endif /* CONFIG_BPF_JIT */
82304+#define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns)
82305+#endif
82306
82307 static inline int bpf_tell_extensions(void)
82308 {
82309 return SKF_AD_MAX;
82310 }
82311
82312+enum {
82313+ BPF_S_RET_K = 1,
82314+ BPF_S_RET_A,
82315+ BPF_S_ALU_ADD_K,
82316+ BPF_S_ALU_ADD_X,
82317+ BPF_S_ALU_SUB_K,
82318+ BPF_S_ALU_SUB_X,
82319+ BPF_S_ALU_MUL_K,
82320+ BPF_S_ALU_MUL_X,
82321+ BPF_S_ALU_DIV_X,
82322+ BPF_S_ALU_MOD_K,
82323+ BPF_S_ALU_MOD_X,
82324+ BPF_S_ALU_AND_K,
82325+ BPF_S_ALU_AND_X,
82326+ BPF_S_ALU_OR_K,
82327+ BPF_S_ALU_OR_X,
82328+ BPF_S_ALU_XOR_K,
82329+ BPF_S_ALU_XOR_X,
82330+ BPF_S_ALU_LSH_K,
82331+ BPF_S_ALU_LSH_X,
82332+ BPF_S_ALU_RSH_K,
82333+ BPF_S_ALU_RSH_X,
82334+ BPF_S_ALU_NEG,
82335+ BPF_S_LD_W_ABS,
82336+ BPF_S_LD_H_ABS,
82337+ BPF_S_LD_B_ABS,
82338+ BPF_S_LD_W_LEN,
82339+ BPF_S_LD_W_IND,
82340+ BPF_S_LD_H_IND,
82341+ BPF_S_LD_B_IND,
82342+ BPF_S_LD_IMM,
82343+ BPF_S_LDX_W_LEN,
82344+ BPF_S_LDX_B_MSH,
82345+ BPF_S_LDX_IMM,
82346+ BPF_S_MISC_TAX,
82347+ BPF_S_MISC_TXA,
82348+ BPF_S_ALU_DIV_K,
82349+ BPF_S_LD_MEM,
82350+ BPF_S_LDX_MEM,
82351+ BPF_S_ST,
82352+ BPF_S_STX,
82353+ BPF_S_JMP_JA,
82354+ BPF_S_JMP_JEQ_K,
82355+ BPF_S_JMP_JEQ_X,
82356+ BPF_S_JMP_JGE_K,
82357+ BPF_S_JMP_JGE_X,
82358+ BPF_S_JMP_JGT_K,
82359+ BPF_S_JMP_JGT_X,
82360+ BPF_S_JMP_JSET_K,
82361+ BPF_S_JMP_JSET_X,
82362+ /* Ancillary data */
82363+ BPF_S_ANC_PROTOCOL,
82364+ BPF_S_ANC_PKTTYPE,
82365+ BPF_S_ANC_IFINDEX,
82366+ BPF_S_ANC_NLATTR,
82367+ BPF_S_ANC_NLATTR_NEST,
82368+ BPF_S_ANC_MARK,
82369+ BPF_S_ANC_QUEUE,
82370+ BPF_S_ANC_HATYPE,
82371+ BPF_S_ANC_RXHASH,
82372+ BPF_S_ANC_CPU,
82373+ BPF_S_ANC_ALU_XOR_X,
82374+ BPF_S_ANC_SECCOMP_LD_W,
82375+ BPF_S_ANC_VLAN_TAG,
82376+ BPF_S_ANC_VLAN_TAG_PRESENT,
82377+ BPF_S_ANC_PAY_OFFSET,
82378+};
82379+
82380 #endif /* __LINUX_FILTER_H__ */
82381diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
82382index 8293262..2b3b8bd 100644
82383--- a/include/linux/frontswap.h
82384+++ b/include/linux/frontswap.h
82385@@ -11,7 +11,7 @@ struct frontswap_ops {
82386 int (*load)(unsigned, pgoff_t, struct page *);
82387 void (*invalidate_page)(unsigned, pgoff_t);
82388 void (*invalidate_area)(unsigned);
82389-};
82390+} __no_const;
82391
82392 extern bool frontswap_enabled;
82393 extern struct frontswap_ops *
82394diff --git a/include/linux/fs.h b/include/linux/fs.h
82395index e11d60c..901317a 100644
82396--- a/include/linux/fs.h
82397+++ b/include/linux/fs.h
82398@@ -401,7 +401,7 @@ struct address_space {
82399 spinlock_t private_lock; /* for use by the address_space */
82400 struct list_head private_list; /* ditto */
82401 void *private_data; /* ditto */
82402-} __attribute__((aligned(sizeof(long))));
82403+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
82404 /*
82405 * On most architectures that alignment is already the case; but
82406 * must be enforced here for CRIS, to let the least significant bit
82407@@ -444,7 +444,7 @@ struct block_device {
82408 int bd_fsfreeze_count;
82409 /* Mutex for freeze */
82410 struct mutex bd_fsfreeze_mutex;
82411-};
82412+} __randomize_layout;
82413
82414 /*
82415 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
82416@@ -588,7 +588,7 @@ struct inode {
82417 #endif
82418
82419 void *i_private; /* fs or device private pointer */
82420-};
82421+} __randomize_layout;
82422
82423 static inline int inode_unhashed(struct inode *inode)
82424 {
82425@@ -781,7 +781,7 @@ struct file {
82426 struct list_head f_tfile_llink;
82427 #endif /* #ifdef CONFIG_EPOLL */
82428 struct address_space *f_mapping;
82429-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
82430+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
82431
82432 struct file_handle {
82433 __u32 handle_bytes;
82434@@ -909,7 +909,7 @@ struct file_lock {
82435 int state; /* state of grant or error if -ve */
82436 } afs;
82437 } fl_u;
82438-};
82439+} __randomize_layout;
82440
82441 /* The following constant reflects the upper bound of the file/locking space */
82442 #ifndef OFFSET_MAX
82443@@ -1258,7 +1258,7 @@ struct super_block {
82444 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
82445 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
82446 struct rcu_head rcu;
82447-};
82448+} __randomize_layout;
82449
82450 extern struct timespec current_fs_time(struct super_block *sb);
82451
82452@@ -1484,7 +1484,8 @@ struct file_operations {
82453 long (*fallocate)(struct file *file, int mode, loff_t offset,
82454 loff_t len);
82455 int (*show_fdinfo)(struct seq_file *m, struct file *f);
82456-};
82457+} __do_const __randomize_layout;
82458+typedef struct file_operations __no_const file_operations_no_const;
82459
82460 struct inode_operations {
82461 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
82462@@ -2769,4 +2770,14 @@ static inline bool dir_relax(struct inode *inode)
82463 return !IS_DEADDIR(inode);
82464 }
82465
82466+static inline bool is_sidechannel_device(const struct inode *inode)
82467+{
82468+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
82469+ umode_t mode = inode->i_mode;
82470+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
82471+#else
82472+ return false;
82473+#endif
82474+}
82475+
82476 #endif /* _LINUX_FS_H */
82477diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
82478index 0efc3e6..fd23610 100644
82479--- a/include/linux/fs_struct.h
82480+++ b/include/linux/fs_struct.h
82481@@ -6,13 +6,13 @@
82482 #include <linux/seqlock.h>
82483
82484 struct fs_struct {
82485- int users;
82486+ atomic_t users;
82487 spinlock_t lock;
82488 seqcount_t seq;
82489 int umask;
82490 int in_exec;
82491 struct path root, pwd;
82492-};
82493+} __randomize_layout;
82494
82495 extern struct kmem_cache *fs_cachep;
82496
82497diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
82498index 7714849..a4a5c7a 100644
82499--- a/include/linux/fscache-cache.h
82500+++ b/include/linux/fscache-cache.h
82501@@ -113,7 +113,7 @@ struct fscache_operation {
82502 fscache_operation_release_t release;
82503 };
82504
82505-extern atomic_t fscache_op_debug_id;
82506+extern atomic_unchecked_t fscache_op_debug_id;
82507 extern void fscache_op_work_func(struct work_struct *work);
82508
82509 extern void fscache_enqueue_operation(struct fscache_operation *);
82510@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
82511 INIT_WORK(&op->work, fscache_op_work_func);
82512 atomic_set(&op->usage, 1);
82513 op->state = FSCACHE_OP_ST_INITIALISED;
82514- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
82515+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
82516 op->processor = processor;
82517 op->release = release;
82518 INIT_LIST_HEAD(&op->pend_link);
82519diff --git a/include/linux/fscache.h b/include/linux/fscache.h
82520index 115bb81..e7b812b 100644
82521--- a/include/linux/fscache.h
82522+++ b/include/linux/fscache.h
82523@@ -152,7 +152,7 @@ struct fscache_cookie_def {
82524 * - this is mandatory for any object that may have data
82525 */
82526 void (*now_uncached)(void *cookie_netfs_data);
82527-};
82528+} __do_const;
82529
82530 /*
82531 * fscache cached network filesystem type
82532diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
82533index 1c804b0..1432c2b 100644
82534--- a/include/linux/fsnotify.h
82535+++ b/include/linux/fsnotify.h
82536@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
82537 struct inode *inode = file_inode(file);
82538 __u32 mask = FS_ACCESS;
82539
82540+ if (is_sidechannel_device(inode))
82541+ return;
82542+
82543 if (S_ISDIR(inode->i_mode))
82544 mask |= FS_ISDIR;
82545
82546@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
82547 struct inode *inode = file_inode(file);
82548 __u32 mask = FS_MODIFY;
82549
82550+ if (is_sidechannel_device(inode))
82551+ return;
82552+
82553 if (S_ISDIR(inode->i_mode))
82554 mask |= FS_ISDIR;
82555
82556@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
82557 */
82558 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
82559 {
82560- return kstrdup(name, GFP_KERNEL);
82561+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
82562 }
82563
82564 /*
82565diff --git a/include/linux/genhd.h b/include/linux/genhd.h
82566index ec274e0..e678159 100644
82567--- a/include/linux/genhd.h
82568+++ b/include/linux/genhd.h
82569@@ -194,7 +194,7 @@ struct gendisk {
82570 struct kobject *slave_dir;
82571
82572 struct timer_rand_state *random;
82573- atomic_t sync_io; /* RAID */
82574+ atomic_unchecked_t sync_io; /* RAID */
82575 struct disk_events *ev;
82576 #ifdef CONFIG_BLK_DEV_INTEGRITY
82577 struct blk_integrity *integrity;
82578@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
82579 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
82580
82581 /* drivers/char/random.c */
82582-extern void add_disk_randomness(struct gendisk *disk);
82583+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
82584 extern void rand_initialize_disk(struct gendisk *disk);
82585
82586 static inline sector_t get_start_sect(struct block_device *bdev)
82587diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
82588index c0894dd..2fbf10c 100644
82589--- a/include/linux/genl_magic_func.h
82590+++ b/include/linux/genl_magic_func.h
82591@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
82592 },
82593
82594 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
82595-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
82596+static struct genl_ops ZZZ_genl_ops[] = {
82597 #include GENL_MAGIC_INCLUDE_FILE
82598 };
82599
82600diff --git a/include/linux/gfp.h b/include/linux/gfp.h
82601index 6eb1fb3..30fe7e4 100644
82602--- a/include/linux/gfp.h
82603+++ b/include/linux/gfp.h
82604@@ -34,6 +34,13 @@ struct vm_area_struct;
82605 #define ___GFP_NO_KSWAPD 0x400000u
82606 #define ___GFP_OTHER_NODE 0x800000u
82607 #define ___GFP_WRITE 0x1000000u
82608+
82609+#ifdef CONFIG_PAX_USERCOPY_SLABS
82610+#define ___GFP_USERCOPY 0x2000000u
82611+#else
82612+#define ___GFP_USERCOPY 0
82613+#endif
82614+
82615 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
82616
82617 /*
82618@@ -90,6 +97,7 @@ struct vm_area_struct;
82619 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
82620 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
82621 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
82622+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
82623
82624 /*
82625 * This may seem redundant, but it's a way of annotating false positives vs.
82626@@ -97,7 +105,7 @@ struct vm_area_struct;
82627 */
82628 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
82629
82630-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
82631+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
82632 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
82633
82634 /* This equals 0, but use constants in case they ever change */
82635@@ -155,6 +163,8 @@ struct vm_area_struct;
82636 /* 4GB DMA on some platforms */
82637 #define GFP_DMA32 __GFP_DMA32
82638
82639+#define GFP_USERCOPY __GFP_USERCOPY
82640+
82641 /* Convert GFP flags to their corresponding migrate type */
82642 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
82643 {
82644diff --git a/include/linux/gracl.h b/include/linux/gracl.h
82645new file mode 100644
82646index 0000000..edb2cb6
82647--- /dev/null
82648+++ b/include/linux/gracl.h
82649@@ -0,0 +1,340 @@
82650+#ifndef GR_ACL_H
82651+#define GR_ACL_H
82652+
82653+#include <linux/grdefs.h>
82654+#include <linux/resource.h>
82655+#include <linux/capability.h>
82656+#include <linux/dcache.h>
82657+#include <asm/resource.h>
82658+
82659+/* Major status information */
82660+
82661+#define GR_VERSION "grsecurity 3.0"
82662+#define GRSECURITY_VERSION 0x3000
82663+
82664+enum {
82665+ GR_SHUTDOWN = 0,
82666+ GR_ENABLE = 1,
82667+ GR_SPROLE = 2,
82668+ GR_OLDRELOAD = 3,
82669+ GR_SEGVMOD = 4,
82670+ GR_STATUS = 5,
82671+ GR_UNSPROLE = 6,
82672+ GR_PASSSET = 7,
82673+ GR_SPROLEPAM = 8,
82674+ GR_RELOAD = 9,
82675+};
82676+
82677+/* Password setup definitions
82678+ * kernel/grhash.c */
82679+enum {
82680+ GR_PW_LEN = 128,
82681+ GR_SALT_LEN = 16,
82682+ GR_SHA_LEN = 32,
82683+};
82684+
82685+enum {
82686+ GR_SPROLE_LEN = 64,
82687+};
82688+
82689+enum {
82690+ GR_NO_GLOB = 0,
82691+ GR_REG_GLOB,
82692+ GR_CREATE_GLOB
82693+};
82694+
82695+#define GR_NLIMITS 32
82696+
82697+/* Begin Data Structures */
82698+
82699+struct sprole_pw {
82700+ unsigned char *rolename;
82701+ unsigned char salt[GR_SALT_LEN];
82702+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
82703+};
82704+
82705+struct name_entry {
82706+ __u32 key;
82707+ ino_t inode;
82708+ dev_t device;
82709+ char *name;
82710+ __u16 len;
82711+ __u8 deleted;
82712+ struct name_entry *prev;
82713+ struct name_entry *next;
82714+};
82715+
82716+struct inodev_entry {
82717+ struct name_entry *nentry;
82718+ struct inodev_entry *prev;
82719+ struct inodev_entry *next;
82720+};
82721+
82722+struct acl_role_db {
82723+ struct acl_role_label **r_hash;
82724+ __u32 r_size;
82725+};
82726+
82727+struct inodev_db {
82728+ struct inodev_entry **i_hash;
82729+ __u32 i_size;
82730+};
82731+
82732+struct name_db {
82733+ struct name_entry **n_hash;
82734+ __u32 n_size;
82735+};
82736+
82737+struct crash_uid {
82738+ uid_t uid;
82739+ unsigned long expires;
82740+};
82741+
82742+struct gr_hash_struct {
82743+ void **table;
82744+ void **nametable;
82745+ void *first;
82746+ __u32 table_size;
82747+ __u32 used_size;
82748+ int type;
82749+};
82750+
82751+/* Userspace Grsecurity ACL data structures */
82752+
82753+struct acl_subject_label {
82754+ char *filename;
82755+ ino_t inode;
82756+ dev_t device;
82757+ __u32 mode;
82758+ kernel_cap_t cap_mask;
82759+ kernel_cap_t cap_lower;
82760+ kernel_cap_t cap_invert_audit;
82761+
82762+ struct rlimit res[GR_NLIMITS];
82763+ __u32 resmask;
82764+
82765+ __u8 user_trans_type;
82766+ __u8 group_trans_type;
82767+ uid_t *user_transitions;
82768+ gid_t *group_transitions;
82769+ __u16 user_trans_num;
82770+ __u16 group_trans_num;
82771+
82772+ __u32 sock_families[2];
82773+ __u32 ip_proto[8];
82774+ __u32 ip_type;
82775+ struct acl_ip_label **ips;
82776+ __u32 ip_num;
82777+ __u32 inaddr_any_override;
82778+
82779+ __u32 crashes;
82780+ unsigned long expires;
82781+
82782+ struct acl_subject_label *parent_subject;
82783+ struct gr_hash_struct *hash;
82784+ struct acl_subject_label *prev;
82785+ struct acl_subject_label *next;
82786+
82787+ struct acl_object_label **obj_hash;
82788+ __u32 obj_hash_size;
82789+ __u16 pax_flags;
82790+};
82791+
82792+struct role_allowed_ip {
82793+ __u32 addr;
82794+ __u32 netmask;
82795+
82796+ struct role_allowed_ip *prev;
82797+ struct role_allowed_ip *next;
82798+};
82799+
82800+struct role_transition {
82801+ char *rolename;
82802+
82803+ struct role_transition *prev;
82804+ struct role_transition *next;
82805+};
82806+
82807+struct acl_role_label {
82808+ char *rolename;
82809+ uid_t uidgid;
82810+ __u16 roletype;
82811+
82812+ __u16 auth_attempts;
82813+ unsigned long expires;
82814+
82815+ struct acl_subject_label *root_label;
82816+ struct gr_hash_struct *hash;
82817+
82818+ struct acl_role_label *prev;
82819+ struct acl_role_label *next;
82820+
82821+ struct role_transition *transitions;
82822+ struct role_allowed_ip *allowed_ips;
82823+ uid_t *domain_children;
82824+ __u16 domain_child_num;
82825+
82826+ umode_t umask;
82827+
82828+ struct acl_subject_label **subj_hash;
82829+ __u32 subj_hash_size;
82830+};
82831+
82832+struct user_acl_role_db {
82833+ struct acl_role_label **r_table;
82834+ __u32 num_pointers; /* Number of allocations to track */
82835+ __u32 num_roles; /* Number of roles */
82836+ __u32 num_domain_children; /* Number of domain children */
82837+ __u32 num_subjects; /* Number of subjects */
82838+ __u32 num_objects; /* Number of objects */
82839+};
82840+
82841+struct acl_object_label {
82842+ char *filename;
82843+ ino_t inode;
82844+ dev_t device;
82845+ __u32 mode;
82846+
82847+ struct acl_subject_label *nested;
82848+ struct acl_object_label *globbed;
82849+
82850+ /* next two structures not used */
82851+
82852+ struct acl_object_label *prev;
82853+ struct acl_object_label *next;
82854+};
82855+
82856+struct acl_ip_label {
82857+ char *iface;
82858+ __u32 addr;
82859+ __u32 netmask;
82860+ __u16 low, high;
82861+ __u8 mode;
82862+ __u32 type;
82863+ __u32 proto[8];
82864+
82865+ /* next two structures not used */
82866+
82867+ struct acl_ip_label *prev;
82868+ struct acl_ip_label *next;
82869+};
82870+
82871+struct gr_arg {
82872+ struct user_acl_role_db role_db;
82873+ unsigned char pw[GR_PW_LEN];
82874+ unsigned char salt[GR_SALT_LEN];
82875+ unsigned char sum[GR_SHA_LEN];
82876+ unsigned char sp_role[GR_SPROLE_LEN];
82877+ struct sprole_pw *sprole_pws;
82878+ dev_t segv_device;
82879+ ino_t segv_inode;
82880+ uid_t segv_uid;
82881+ __u16 num_sprole_pws;
82882+ __u16 mode;
82883+};
82884+
82885+struct gr_arg_wrapper {
82886+ struct gr_arg *arg;
82887+ __u32 version;
82888+ __u32 size;
82889+};
82890+
82891+struct subject_map {
82892+ struct acl_subject_label *user;
82893+ struct acl_subject_label *kernel;
82894+ struct subject_map *prev;
82895+ struct subject_map *next;
82896+};
82897+
82898+struct acl_subj_map_db {
82899+ struct subject_map **s_hash;
82900+ __u32 s_size;
82901+};
82902+
82903+struct gr_policy_state {
82904+ struct sprole_pw **acl_special_roles;
82905+ __u16 num_sprole_pws;
82906+ struct acl_role_label *kernel_role;
82907+ struct acl_role_label *role_list;
82908+ struct acl_role_label *default_role;
82909+ struct acl_role_db acl_role_set;
82910+ struct acl_subj_map_db subj_map_set;
82911+ struct name_db name_set;
82912+ struct inodev_db inodev_set;
82913+};
82914+
82915+struct gr_alloc_state {
82916+ unsigned long alloc_stack_next;
82917+ unsigned long alloc_stack_size;
82918+ void **alloc_stack;
82919+};
82920+
82921+struct gr_reload_state {
82922+ struct gr_policy_state oldpolicy;
82923+ struct gr_alloc_state oldalloc;
82924+ struct gr_policy_state newpolicy;
82925+ struct gr_alloc_state newalloc;
82926+ struct gr_policy_state *oldpolicy_ptr;
82927+ struct gr_alloc_state *oldalloc_ptr;
82928+ unsigned char oldmode;
82929+};
82930+
82931+/* End Data Structures Section */
82932+
82933+/* Hash functions generated by empirical testing by Brad Spengler
82934+ Makes good use of the low bits of the inode. Generally 0-1 times
82935+ in loop for successful match. 0-3 for unsuccessful match.
82936+ Shift/add algorithm with modulus of table size and an XOR*/
82937+
82938+static __inline__ unsigned int
82939+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
82940+{
82941+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
82942+}
82943+
82944+ static __inline__ unsigned int
82945+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
82946+{
82947+ return ((const unsigned long)userp % sz);
82948+}
82949+
82950+static __inline__ unsigned int
82951+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
82952+{
82953+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
82954+}
82955+
82956+static __inline__ unsigned int
82957+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
82958+{
82959+ return full_name_hash((const unsigned char *)name, len) % sz;
82960+}
82961+
82962+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
82963+ subj = NULL; \
82964+ iter = 0; \
82965+ while (iter < role->subj_hash_size) { \
82966+ if (subj == NULL) \
82967+ subj = role->subj_hash[iter]; \
82968+ if (subj == NULL) { \
82969+ iter++; \
82970+ continue; \
82971+ }
82972+
82973+#define FOR_EACH_SUBJECT_END(subj,iter) \
82974+ subj = subj->next; \
82975+ if (subj == NULL) \
82976+ iter++; \
82977+ }
82978+
82979+
82980+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
82981+ subj = role->hash->first; \
82982+ while (subj != NULL) {
82983+
82984+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
82985+ subj = subj->next; \
82986+ }
82987+
82988+#endif
82989+
82990diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
82991new file mode 100644
82992index 0000000..33ebd1f
82993--- /dev/null
82994+++ b/include/linux/gracl_compat.h
82995@@ -0,0 +1,156 @@
82996+#ifndef GR_ACL_COMPAT_H
82997+#define GR_ACL_COMPAT_H
82998+
82999+#include <linux/resource.h>
83000+#include <asm/resource.h>
83001+
83002+struct sprole_pw_compat {
83003+ compat_uptr_t rolename;
83004+ unsigned char salt[GR_SALT_LEN];
83005+ unsigned char sum[GR_SHA_LEN];
83006+};
83007+
83008+struct gr_hash_struct_compat {
83009+ compat_uptr_t table;
83010+ compat_uptr_t nametable;
83011+ compat_uptr_t first;
83012+ __u32 table_size;
83013+ __u32 used_size;
83014+ int type;
83015+};
83016+
83017+struct acl_subject_label_compat {
83018+ compat_uptr_t filename;
83019+ compat_ino_t inode;
83020+ __u32 device;
83021+ __u32 mode;
83022+ kernel_cap_t cap_mask;
83023+ kernel_cap_t cap_lower;
83024+ kernel_cap_t cap_invert_audit;
83025+
83026+ struct compat_rlimit res[GR_NLIMITS];
83027+ __u32 resmask;
83028+
83029+ __u8 user_trans_type;
83030+ __u8 group_trans_type;
83031+ compat_uptr_t user_transitions;
83032+ compat_uptr_t group_transitions;
83033+ __u16 user_trans_num;
83034+ __u16 group_trans_num;
83035+
83036+ __u32 sock_families[2];
83037+ __u32 ip_proto[8];
83038+ __u32 ip_type;
83039+ compat_uptr_t ips;
83040+ __u32 ip_num;
83041+ __u32 inaddr_any_override;
83042+
83043+ __u32 crashes;
83044+ compat_ulong_t expires;
83045+
83046+ compat_uptr_t parent_subject;
83047+ compat_uptr_t hash;
83048+ compat_uptr_t prev;
83049+ compat_uptr_t next;
83050+
83051+ compat_uptr_t obj_hash;
83052+ __u32 obj_hash_size;
83053+ __u16 pax_flags;
83054+};
83055+
83056+struct role_allowed_ip_compat {
83057+ __u32 addr;
83058+ __u32 netmask;
83059+
83060+ compat_uptr_t prev;
83061+ compat_uptr_t next;
83062+};
83063+
83064+struct role_transition_compat {
83065+ compat_uptr_t rolename;
83066+
83067+ compat_uptr_t prev;
83068+ compat_uptr_t next;
83069+};
83070+
83071+struct acl_role_label_compat {
83072+ compat_uptr_t rolename;
83073+ uid_t uidgid;
83074+ __u16 roletype;
83075+
83076+ __u16 auth_attempts;
83077+ compat_ulong_t expires;
83078+
83079+ compat_uptr_t root_label;
83080+ compat_uptr_t hash;
83081+
83082+ compat_uptr_t prev;
83083+ compat_uptr_t next;
83084+
83085+ compat_uptr_t transitions;
83086+ compat_uptr_t allowed_ips;
83087+ compat_uptr_t domain_children;
83088+ __u16 domain_child_num;
83089+
83090+ umode_t umask;
83091+
83092+ compat_uptr_t subj_hash;
83093+ __u32 subj_hash_size;
83094+};
83095+
83096+struct user_acl_role_db_compat {
83097+ compat_uptr_t r_table;
83098+ __u32 num_pointers;
83099+ __u32 num_roles;
83100+ __u32 num_domain_children;
83101+ __u32 num_subjects;
83102+ __u32 num_objects;
83103+};
83104+
83105+struct acl_object_label_compat {
83106+ compat_uptr_t filename;
83107+ compat_ino_t inode;
83108+ __u32 device;
83109+ __u32 mode;
83110+
83111+ compat_uptr_t nested;
83112+ compat_uptr_t globbed;
83113+
83114+ compat_uptr_t prev;
83115+ compat_uptr_t next;
83116+};
83117+
83118+struct acl_ip_label_compat {
83119+ compat_uptr_t iface;
83120+ __u32 addr;
83121+ __u32 netmask;
83122+ __u16 low, high;
83123+ __u8 mode;
83124+ __u32 type;
83125+ __u32 proto[8];
83126+
83127+ compat_uptr_t prev;
83128+ compat_uptr_t next;
83129+};
83130+
83131+struct gr_arg_compat {
83132+ struct user_acl_role_db_compat role_db;
83133+ unsigned char pw[GR_PW_LEN];
83134+ unsigned char salt[GR_SALT_LEN];
83135+ unsigned char sum[GR_SHA_LEN];
83136+ unsigned char sp_role[GR_SPROLE_LEN];
83137+ compat_uptr_t sprole_pws;
83138+ __u32 segv_device;
83139+ compat_ino_t segv_inode;
83140+ uid_t segv_uid;
83141+ __u16 num_sprole_pws;
83142+ __u16 mode;
83143+};
83144+
83145+struct gr_arg_wrapper_compat {
83146+ compat_uptr_t arg;
83147+ __u32 version;
83148+ __u32 size;
83149+};
83150+
83151+#endif
83152diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
83153new file mode 100644
83154index 0000000..323ecf2
83155--- /dev/null
83156+++ b/include/linux/gralloc.h
83157@@ -0,0 +1,9 @@
83158+#ifndef __GRALLOC_H
83159+#define __GRALLOC_H
83160+
83161+void acl_free_all(void);
83162+int acl_alloc_stack_init(unsigned long size);
83163+void *acl_alloc(unsigned long len);
83164+void *acl_alloc_num(unsigned long num, unsigned long len);
83165+
83166+#endif
83167diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
83168new file mode 100644
83169index 0000000..be66033
83170--- /dev/null
83171+++ b/include/linux/grdefs.h
83172@@ -0,0 +1,140 @@
83173+#ifndef GRDEFS_H
83174+#define GRDEFS_H
83175+
83176+/* Begin grsecurity status declarations */
83177+
83178+enum {
83179+ GR_READY = 0x01,
83180+ GR_STATUS_INIT = 0x00 // disabled state
83181+};
83182+
83183+/* Begin ACL declarations */
83184+
83185+/* Role flags */
83186+
83187+enum {
83188+ GR_ROLE_USER = 0x0001,
83189+ GR_ROLE_GROUP = 0x0002,
83190+ GR_ROLE_DEFAULT = 0x0004,
83191+ GR_ROLE_SPECIAL = 0x0008,
83192+ GR_ROLE_AUTH = 0x0010,
83193+ GR_ROLE_NOPW = 0x0020,
83194+ GR_ROLE_GOD = 0x0040,
83195+ GR_ROLE_LEARN = 0x0080,
83196+ GR_ROLE_TPE = 0x0100,
83197+ GR_ROLE_DOMAIN = 0x0200,
83198+ GR_ROLE_PAM = 0x0400,
83199+ GR_ROLE_PERSIST = 0x0800
83200+};
83201+
83202+/* ACL Subject and Object mode flags */
83203+enum {
83204+ GR_DELETED = 0x80000000
83205+};
83206+
83207+/* ACL Object-only mode flags */
83208+enum {
83209+ GR_READ = 0x00000001,
83210+ GR_APPEND = 0x00000002,
83211+ GR_WRITE = 0x00000004,
83212+ GR_EXEC = 0x00000008,
83213+ GR_FIND = 0x00000010,
83214+ GR_INHERIT = 0x00000020,
83215+ GR_SETID = 0x00000040,
83216+ GR_CREATE = 0x00000080,
83217+ GR_DELETE = 0x00000100,
83218+ GR_LINK = 0x00000200,
83219+ GR_AUDIT_READ = 0x00000400,
83220+ GR_AUDIT_APPEND = 0x00000800,
83221+ GR_AUDIT_WRITE = 0x00001000,
83222+ GR_AUDIT_EXEC = 0x00002000,
83223+ GR_AUDIT_FIND = 0x00004000,
83224+ GR_AUDIT_INHERIT= 0x00008000,
83225+ GR_AUDIT_SETID = 0x00010000,
83226+ GR_AUDIT_CREATE = 0x00020000,
83227+ GR_AUDIT_DELETE = 0x00040000,
83228+ GR_AUDIT_LINK = 0x00080000,
83229+ GR_PTRACERD = 0x00100000,
83230+ GR_NOPTRACE = 0x00200000,
83231+ GR_SUPPRESS = 0x00400000,
83232+ GR_NOLEARN = 0x00800000,
83233+ GR_INIT_TRANSFER= 0x01000000
83234+};
83235+
83236+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
83237+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
83238+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
83239+
83240+/* ACL subject-only mode flags */
83241+enum {
83242+ GR_KILL = 0x00000001,
83243+ GR_VIEW = 0x00000002,
83244+ GR_PROTECTED = 0x00000004,
83245+ GR_LEARN = 0x00000008,
83246+ GR_OVERRIDE = 0x00000010,
83247+ /* just a placeholder, this mode is only used in userspace */
83248+ GR_DUMMY = 0x00000020,
83249+ GR_PROTSHM = 0x00000040,
83250+ GR_KILLPROC = 0x00000080,
83251+ GR_KILLIPPROC = 0x00000100,
83252+ /* just a placeholder, this mode is only used in userspace */
83253+ GR_NOTROJAN = 0x00000200,
83254+ GR_PROTPROCFD = 0x00000400,
83255+ GR_PROCACCT = 0x00000800,
83256+ GR_RELAXPTRACE = 0x00001000,
83257+ //GR_NESTED = 0x00002000,
83258+ GR_INHERITLEARN = 0x00004000,
83259+ GR_PROCFIND = 0x00008000,
83260+ GR_POVERRIDE = 0x00010000,
83261+ GR_KERNELAUTH = 0x00020000,
83262+ GR_ATSECURE = 0x00040000,
83263+ GR_SHMEXEC = 0x00080000
83264+};
83265+
83266+enum {
83267+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
83268+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
83269+ GR_PAX_ENABLE_MPROTECT = 0x0004,
83270+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
83271+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
83272+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
83273+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
83274+ GR_PAX_DISABLE_MPROTECT = 0x0400,
83275+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
83276+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
83277+};
83278+
83279+enum {
83280+ GR_ID_USER = 0x01,
83281+ GR_ID_GROUP = 0x02,
83282+};
83283+
83284+enum {
83285+ GR_ID_ALLOW = 0x01,
83286+ GR_ID_DENY = 0x02,
83287+};
83288+
83289+#define GR_CRASH_RES 31
83290+#define GR_UIDTABLE_MAX 500
83291+
83292+/* begin resource learning section */
83293+enum {
83294+ GR_RLIM_CPU_BUMP = 60,
83295+ GR_RLIM_FSIZE_BUMP = 50000,
83296+ GR_RLIM_DATA_BUMP = 10000,
83297+ GR_RLIM_STACK_BUMP = 1000,
83298+ GR_RLIM_CORE_BUMP = 10000,
83299+ GR_RLIM_RSS_BUMP = 500000,
83300+ GR_RLIM_NPROC_BUMP = 1,
83301+ GR_RLIM_NOFILE_BUMP = 5,
83302+ GR_RLIM_MEMLOCK_BUMP = 50000,
83303+ GR_RLIM_AS_BUMP = 500000,
83304+ GR_RLIM_LOCKS_BUMP = 2,
83305+ GR_RLIM_SIGPENDING_BUMP = 5,
83306+ GR_RLIM_MSGQUEUE_BUMP = 10000,
83307+ GR_RLIM_NICE_BUMP = 1,
83308+ GR_RLIM_RTPRIO_BUMP = 1,
83309+ GR_RLIM_RTTIME_BUMP = 1000000
83310+};
83311+
83312+#endif
83313diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
83314new file mode 100644
83315index 0000000..d25522e
83316--- /dev/null
83317+++ b/include/linux/grinternal.h
83318@@ -0,0 +1,229 @@
83319+#ifndef __GRINTERNAL_H
83320+#define __GRINTERNAL_H
83321+
83322+#ifdef CONFIG_GRKERNSEC
83323+
83324+#include <linux/fs.h>
83325+#include <linux/mnt_namespace.h>
83326+#include <linux/nsproxy.h>
83327+#include <linux/gracl.h>
83328+#include <linux/grdefs.h>
83329+#include <linux/grmsg.h>
83330+
83331+void gr_add_learn_entry(const char *fmt, ...)
83332+ __attribute__ ((format (printf, 1, 2)));
83333+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
83334+ const struct vfsmount *mnt);
83335+__u32 gr_check_create(const struct dentry *new_dentry,
83336+ const struct dentry *parent,
83337+ const struct vfsmount *mnt, const __u32 mode);
83338+int gr_check_protected_task(const struct task_struct *task);
83339+__u32 to_gr_audit(const __u32 reqmode);
83340+int gr_set_acls(const int type);
83341+int gr_acl_is_enabled(void);
83342+char gr_roletype_to_char(void);
83343+
83344+void gr_handle_alertkill(struct task_struct *task);
83345+char *gr_to_filename(const struct dentry *dentry,
83346+ const struct vfsmount *mnt);
83347+char *gr_to_filename1(const struct dentry *dentry,
83348+ const struct vfsmount *mnt);
83349+char *gr_to_filename2(const struct dentry *dentry,
83350+ const struct vfsmount *mnt);
83351+char *gr_to_filename3(const struct dentry *dentry,
83352+ const struct vfsmount *mnt);
83353+
83354+extern int grsec_enable_ptrace_readexec;
83355+extern int grsec_enable_harden_ptrace;
83356+extern int grsec_enable_link;
83357+extern int grsec_enable_fifo;
83358+extern int grsec_enable_execve;
83359+extern int grsec_enable_shm;
83360+extern int grsec_enable_execlog;
83361+extern int grsec_enable_signal;
83362+extern int grsec_enable_audit_ptrace;
83363+extern int grsec_enable_forkfail;
83364+extern int grsec_enable_time;
83365+extern int grsec_enable_rofs;
83366+extern int grsec_deny_new_usb;
83367+extern int grsec_enable_chroot_shmat;
83368+extern int grsec_enable_chroot_mount;
83369+extern int grsec_enable_chroot_double;
83370+extern int grsec_enable_chroot_pivot;
83371+extern int grsec_enable_chroot_chdir;
83372+extern int grsec_enable_chroot_chmod;
83373+extern int grsec_enable_chroot_mknod;
83374+extern int grsec_enable_chroot_fchdir;
83375+extern int grsec_enable_chroot_nice;
83376+extern int grsec_enable_chroot_execlog;
83377+extern int grsec_enable_chroot_caps;
83378+extern int grsec_enable_chroot_sysctl;
83379+extern int grsec_enable_chroot_unix;
83380+extern int grsec_enable_symlinkown;
83381+extern kgid_t grsec_symlinkown_gid;
83382+extern int grsec_enable_tpe;
83383+extern kgid_t grsec_tpe_gid;
83384+extern int grsec_enable_tpe_all;
83385+extern int grsec_enable_tpe_invert;
83386+extern int grsec_enable_socket_all;
83387+extern kgid_t grsec_socket_all_gid;
83388+extern int grsec_enable_socket_client;
83389+extern kgid_t grsec_socket_client_gid;
83390+extern int grsec_enable_socket_server;
83391+extern kgid_t grsec_socket_server_gid;
83392+extern kgid_t grsec_audit_gid;
83393+extern int grsec_enable_group;
83394+extern int grsec_enable_log_rwxmaps;
83395+extern int grsec_enable_mount;
83396+extern int grsec_enable_chdir;
83397+extern int grsec_resource_logging;
83398+extern int grsec_enable_blackhole;
83399+extern int grsec_lastack_retries;
83400+extern int grsec_enable_brute;
83401+extern int grsec_enable_harden_ipc;
83402+extern int grsec_lock;
83403+
83404+extern spinlock_t grsec_alert_lock;
83405+extern unsigned long grsec_alert_wtime;
83406+extern unsigned long grsec_alert_fyet;
83407+
83408+extern spinlock_t grsec_audit_lock;
83409+
83410+extern rwlock_t grsec_exec_file_lock;
83411+
83412+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
83413+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
83414+ (tsk)->exec_file->f_path.mnt) : "/")
83415+
83416+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
83417+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
83418+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
83419+
83420+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
83421+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
83422+ (tsk)->exec_file->f_path.mnt) : "/")
83423+
83424+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
83425+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
83426+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
83427+
83428+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
83429+
83430+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
83431+
83432+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
83433+{
83434+ if (file1 && file2) {
83435+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
83436+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
83437+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
83438+ return true;
83439+ }
83440+
83441+ return false;
83442+}
83443+
83444+#define GR_CHROOT_CAPS {{ \
83445+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
83446+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
83447+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
83448+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
83449+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
83450+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
83451+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
83452+
83453+#define security_learn(normal_msg,args...) \
83454+({ \
83455+ read_lock(&grsec_exec_file_lock); \
83456+ gr_add_learn_entry(normal_msg "\n", ## args); \
83457+ read_unlock(&grsec_exec_file_lock); \
83458+})
83459+
83460+enum {
83461+ GR_DO_AUDIT,
83462+ GR_DONT_AUDIT,
83463+ /* used for non-audit messages that we shouldn't kill the task on */
83464+ GR_DONT_AUDIT_GOOD
83465+};
83466+
83467+enum {
83468+ GR_TTYSNIFF,
83469+ GR_RBAC,
83470+ GR_RBAC_STR,
83471+ GR_STR_RBAC,
83472+ GR_RBAC_MODE2,
83473+ GR_RBAC_MODE3,
83474+ GR_FILENAME,
83475+ GR_SYSCTL_HIDDEN,
83476+ GR_NOARGS,
83477+ GR_ONE_INT,
83478+ GR_ONE_INT_TWO_STR,
83479+ GR_ONE_STR,
83480+ GR_STR_INT,
83481+ GR_TWO_STR_INT,
83482+ GR_TWO_INT,
83483+ GR_TWO_U64,
83484+ GR_THREE_INT,
83485+ GR_FIVE_INT_TWO_STR,
83486+ GR_TWO_STR,
83487+ GR_THREE_STR,
83488+ GR_FOUR_STR,
83489+ GR_STR_FILENAME,
83490+ GR_FILENAME_STR,
83491+ GR_FILENAME_TWO_INT,
83492+ GR_FILENAME_TWO_INT_STR,
83493+ GR_TEXTREL,
83494+ GR_PTRACE,
83495+ GR_RESOURCE,
83496+ GR_CAP,
83497+ GR_SIG,
83498+ GR_SIG2,
83499+ GR_CRASH1,
83500+ GR_CRASH2,
83501+ GR_PSACCT,
83502+ GR_RWXMAP,
83503+ GR_RWXMAPVMA
83504+};
83505+
83506+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
83507+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
83508+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
83509+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
83510+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
83511+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
83512+#define gr_log_fs_rbac_mode3(audit, msg, dentry, mnt, str1, str2, str3) gr_log_varargs(audit, msg, GR_RBAC_MODE3, dentry, mnt, str1, str2, str3)
83513+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
83514+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
83515+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
83516+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
83517+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
83518+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
83519+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
83520+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
83521+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
83522+#define gr_log_int5_str2(audit, msg, num1, num2, str1, str2) gr_log_varargs(audit, msg, GR_FIVE_INT_TWO_STR, num1, num2, str1, str2)
83523+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
83524+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
83525+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
83526+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
83527+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
83528+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
83529+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
83530+#define gr_log_fs_int2_str(audit, msg, dentry, mnt, num1, num2, str) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT_STR, dentry, mnt, num1, num2, str)
83531+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
83532+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
83533+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
83534+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
83535+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
83536+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
83537+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
83538+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
83539+#define gr_log_procacct(audit, msg, task, num1, num2, num3, num4, num5, num6, num7, num8, num9) gr_log_varargs(audit, msg, GR_PSACCT, task, num1, num2, num3, num4, num5, num6, num7, num8, num9)
83540+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
83541+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
83542+
83543+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
83544+
83545+#endif
83546+
83547+#endif
83548diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
83549new file mode 100644
83550index 0000000..b02ba9d
83551--- /dev/null
83552+++ b/include/linux/grmsg.h
83553@@ -0,0 +1,117 @@
83554+#define DEFAULTSECMSG "%.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u, parent %.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u"
83555+#define GR_ACL_PROCACCT_MSG "%.256s[%.16s:%d] IP:%pI4 TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u run time:[%ud %uh %um %us] cpu time:[%ud %uh %um %us] %s with exit code %ld, parent %.256s[%.16s:%d] IP:%pI4 TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u"
83556+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
83557+#define GR_STOPMOD_MSG "denied modification of module state by "
83558+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
83559+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
83560+#define GR_IOPERM_MSG "denied use of ioperm() by "
83561+#define GR_IOPL_MSG "denied use of iopl() by "
83562+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
83563+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
83564+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
83565+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
83566+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
83567+#define GR_LEARN_AUDIT_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%lu\t%lu\t%.4095s\t%lu\t%pI4"
83568+#define GR_ID_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%c\t%d\t%d\t%d\t%pI4"
83569+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
83570+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
83571+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
83572+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
83573+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
83574+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
83575+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
83576+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
83577+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
83578+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
83579+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
83580+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
83581+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
83582+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
83583+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
83584+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
83585+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
83586+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
83587+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
83588+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
83589+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
83590+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
83591+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
83592+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
83593+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
83594+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
83595+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
83596+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
83597+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
83598+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
83599+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
83600+#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
83601+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
83602+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
83603+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
83604+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
83605+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
83606+#define GR_DISABLED_ACL_MSG "Error loading %s, trying to run kernel with acls disabled. To disable acls at startup use <kernel image name> gracl=off from your boot loader"
83607+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
83608+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
83609+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
83610+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
83611+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
83612+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
83613+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
83614+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
83615+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
83616+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
83617+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
83618+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
83619+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
83620+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
83621+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
83622+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
83623+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
83624+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
83625+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
83626+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
83627+#define GR_FAILFORK_MSG "failed fork with errno %s by "
83628+#define GR_NICE_CHROOT_MSG "denied priority change by "
83629+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
83630+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
83631+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
83632+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
83633+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
83634+#define GR_TIME_MSG "time set by "
83635+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
83636+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
83637+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
83638+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
83639+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
83640+#define GR_BIND_MSG "denied bind() by "
83641+#define GR_CONNECT_MSG "denied connect() by "
83642+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
83643+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
83644+#define GR_IP_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%pI4\t%u\t%u\t%u\t%u\t%pI4"
83645+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
83646+#define GR_CAP_ACL_MSG "use of %s denied for "
83647+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
83648+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
83649+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
83650+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
83651+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
83652+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
83653+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
83654+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
83655+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
83656+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
83657+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
83658+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
83659+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
83660+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
83661+#define GR_VM86_MSG "denied use of vm86 by "
83662+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
83663+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
83664+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
83665+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
83666+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
83667+#define GR_BRUTE_DAEMON_MSG "bruteforce prevention initiated for the next 30 minutes or until service restarted, stalling each fork 30 seconds. Please investigate the crash report for "
83668+#define GR_BRUTE_SUID_MSG "bruteforce prevention initiated due to crash of %.950s against uid %u, banning suid/sgid execs for %u minutes. Please investigate the crash report for "
83669+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
83670+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
83671diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
83672new file mode 100644
83673index 0000000..10b9635
83674--- /dev/null
83675+++ b/include/linux/grsecurity.h
83676@@ -0,0 +1,254 @@
83677+#ifndef GR_SECURITY_H
83678+#define GR_SECURITY_H
83679+#include <linux/fs.h>
83680+#include <linux/fs_struct.h>
83681+#include <linux/binfmts.h>
83682+#include <linux/gracl.h>
83683+
83684+/* notify of brain-dead configs */
83685+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83686+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
83687+#endif
83688+#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83689+#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
83690+#endif
83691+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
83692+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
83693+#endif
83694+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
83695+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
83696+#endif
83697+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
83698+#error "CONFIG_PAX enabled, but no PaX options are enabled."
83699+#endif
83700+
83701+int gr_handle_new_usb(void);
83702+
83703+void gr_handle_brute_attach(int dumpable);
83704+void gr_handle_brute_check(void);
83705+void gr_handle_kernel_exploit(void);
83706+
83707+char gr_roletype_to_char(void);
83708+
83709+int gr_proc_is_restricted(void);
83710+
83711+int gr_acl_enable_at_secure(void);
83712+
83713+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
83714+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
83715+
83716+int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
83717+
83718+void gr_del_task_from_ip_table(struct task_struct *p);
83719+
83720+int gr_pid_is_chrooted(struct task_struct *p);
83721+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
83722+int gr_handle_chroot_nice(void);
83723+int gr_handle_chroot_sysctl(const int op);
83724+int gr_handle_chroot_setpriority(struct task_struct *p,
83725+ const int niceval);
83726+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
83727+int gr_chroot_fhandle(void);
83728+int gr_handle_chroot_chroot(const struct dentry *dentry,
83729+ const struct vfsmount *mnt);
83730+void gr_handle_chroot_chdir(const struct path *path);
83731+int gr_handle_chroot_chmod(const struct dentry *dentry,
83732+ const struct vfsmount *mnt, const int mode);
83733+int gr_handle_chroot_mknod(const struct dentry *dentry,
83734+ const struct vfsmount *mnt, const int mode);
83735+int gr_handle_chroot_mount(const struct dentry *dentry,
83736+ const struct vfsmount *mnt,
83737+ const char *dev_name);
83738+int gr_handle_chroot_pivot(void);
83739+int gr_handle_chroot_unix(const pid_t pid);
83740+
83741+int gr_handle_rawio(const struct inode *inode);
83742+
83743+void gr_handle_ioperm(void);
83744+void gr_handle_iopl(void);
83745+void gr_handle_msr_write(void);
83746+
83747+umode_t gr_acl_umask(void);
83748+
83749+int gr_tpe_allow(const struct file *file);
83750+
83751+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
83752+void gr_clear_chroot_entries(struct task_struct *task);
83753+
83754+void gr_log_forkfail(const int retval);
83755+void gr_log_timechange(void);
83756+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
83757+void gr_log_chdir(const struct dentry *dentry,
83758+ const struct vfsmount *mnt);
83759+void gr_log_chroot_exec(const struct dentry *dentry,
83760+ const struct vfsmount *mnt);
83761+void gr_log_remount(const char *devname, const int retval);
83762+void gr_log_unmount(const char *devname, const int retval);
83763+void gr_log_mount(const char *from, const char *to, const int retval);
83764+void gr_log_textrel(struct vm_area_struct *vma);
83765+void gr_log_ptgnustack(struct file *file);
83766+void gr_log_rwxmmap(struct file *file);
83767+void gr_log_rwxmprotect(struct vm_area_struct *vma);
83768+
83769+int gr_handle_follow_link(const struct inode *parent,
83770+ const struct inode *inode,
83771+ const struct dentry *dentry,
83772+ const struct vfsmount *mnt);
83773+int gr_handle_fifo(const struct dentry *dentry,
83774+ const struct vfsmount *mnt,
83775+ const struct dentry *dir, const int flag,
83776+ const int acc_mode);
83777+int gr_handle_hardlink(const struct dentry *dentry,
83778+ const struct vfsmount *mnt,
83779+ struct inode *inode,
83780+ const int mode, const struct filename *to);
83781+
83782+int gr_is_capable(const int cap);
83783+int gr_is_capable_nolog(const int cap);
83784+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
83785+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
83786+
83787+void gr_copy_label(struct task_struct *tsk);
83788+void gr_handle_crash(struct task_struct *task, const int sig);
83789+int gr_handle_signal(const struct task_struct *p, const int sig);
83790+int gr_check_crash_uid(const kuid_t uid);
83791+int gr_check_protected_task(const struct task_struct *task);
83792+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
83793+int gr_acl_handle_mmap(const struct file *file,
83794+ const unsigned long prot);
83795+int gr_acl_handle_mprotect(const struct file *file,
83796+ const unsigned long prot);
83797+int gr_check_hidden_task(const struct task_struct *tsk);
83798+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
83799+ const struct vfsmount *mnt);
83800+__u32 gr_acl_handle_utime(const struct dentry *dentry,
83801+ const struct vfsmount *mnt);
83802+__u32 gr_acl_handle_access(const struct dentry *dentry,
83803+ const struct vfsmount *mnt, const int fmode);
83804+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
83805+ const struct vfsmount *mnt, umode_t *mode);
83806+__u32 gr_acl_handle_chown(const struct dentry *dentry,
83807+ const struct vfsmount *mnt);
83808+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
83809+ const struct vfsmount *mnt);
83810+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
83811+ const struct vfsmount *mnt);
83812+int gr_handle_ptrace(struct task_struct *task, const long request);
83813+int gr_handle_proc_ptrace(struct task_struct *task);
83814+__u32 gr_acl_handle_execve(const struct dentry *dentry,
83815+ const struct vfsmount *mnt);
83816+int gr_check_crash_exec(const struct file *filp);
83817+int gr_acl_is_enabled(void);
83818+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
83819+ const kgid_t gid);
83820+int gr_set_proc_label(const struct dentry *dentry,
83821+ const struct vfsmount *mnt,
83822+ const int unsafe_flags);
83823+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
83824+ const struct vfsmount *mnt);
83825+__u32 gr_acl_handle_open(const struct dentry *dentry,
83826+ const struct vfsmount *mnt, int acc_mode);
83827+__u32 gr_acl_handle_creat(const struct dentry *dentry,
83828+ const struct dentry *p_dentry,
83829+ const struct vfsmount *p_mnt,
83830+ int open_flags, int acc_mode, const int imode);
83831+void gr_handle_create(const struct dentry *dentry,
83832+ const struct vfsmount *mnt);
83833+void gr_handle_proc_create(const struct dentry *dentry,
83834+ const struct inode *inode);
83835+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
83836+ const struct dentry *parent_dentry,
83837+ const struct vfsmount *parent_mnt,
83838+ const int mode);
83839+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
83840+ const struct dentry *parent_dentry,
83841+ const struct vfsmount *parent_mnt);
83842+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
83843+ const struct vfsmount *mnt);
83844+void gr_handle_delete(const ino_t ino, const dev_t dev);
83845+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
83846+ const struct vfsmount *mnt);
83847+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
83848+ const struct dentry *parent_dentry,
83849+ const struct vfsmount *parent_mnt,
83850+ const struct filename *from);
83851+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
83852+ const struct dentry *parent_dentry,
83853+ const struct vfsmount *parent_mnt,
83854+ const struct dentry *old_dentry,
83855+ const struct vfsmount *old_mnt, const struct filename *to);
83856+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
83857+int gr_acl_handle_rename(struct dentry *new_dentry,
83858+ struct dentry *parent_dentry,
83859+ const struct vfsmount *parent_mnt,
83860+ struct dentry *old_dentry,
83861+ struct inode *old_parent_inode,
83862+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
83863+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
83864+ struct dentry *old_dentry,
83865+ struct dentry *new_dentry,
83866+ struct vfsmount *mnt, const __u8 replace, unsigned int flags);
83867+__u32 gr_check_link(const struct dentry *new_dentry,
83868+ const struct dentry *parent_dentry,
83869+ const struct vfsmount *parent_mnt,
83870+ const struct dentry *old_dentry,
83871+ const struct vfsmount *old_mnt);
83872+int gr_acl_handle_filldir(const struct file *file, const char *name,
83873+ const unsigned int namelen, const ino_t ino);
83874+
83875+__u32 gr_acl_handle_unix(const struct dentry *dentry,
83876+ const struct vfsmount *mnt);
83877+void gr_acl_handle_exit(void);
83878+void gr_acl_handle_psacct(struct task_struct *task, const long code);
83879+int gr_acl_handle_procpidmem(const struct task_struct *task);
83880+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
83881+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
83882+void gr_audit_ptrace(struct task_struct *task);
83883+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
83884+void gr_put_exec_file(struct task_struct *task);
83885+
83886+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
83887+
83888+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
83889+extern void gr_learn_resource(const struct task_struct *task, const int res,
83890+ const unsigned long wanted, const int gt);
83891+#else
83892+static inline void gr_learn_resource(const struct task_struct *task, const int res,
83893+ const unsigned long wanted, const int gt)
83894+{
83895+}
83896+#endif
83897+
83898+#ifdef CONFIG_GRKERNSEC_RESLOG
83899+extern void gr_log_resource(const struct task_struct *task, const int res,
83900+ const unsigned long wanted, const int gt);
83901+#else
83902+static inline void gr_log_resource(const struct task_struct *task, const int res,
83903+ const unsigned long wanted, const int gt)
83904+{
83905+}
83906+#endif
83907+
83908+#ifdef CONFIG_GRKERNSEC
83909+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
83910+void gr_handle_vm86(void);
83911+void gr_handle_mem_readwrite(u64 from, u64 to);
83912+
83913+void gr_log_badprocpid(const char *entry);
83914+
83915+extern int grsec_enable_dmesg;
83916+extern int grsec_disable_privio;
83917+
83918+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83919+extern kgid_t grsec_proc_gid;
83920+#endif
83921+
83922+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83923+extern int grsec_enable_chroot_findtask;
83924+#endif
83925+#ifdef CONFIG_GRKERNSEC_SETXID
83926+extern int grsec_enable_setxid;
83927+#endif
83928+#endif
83929+
83930+#endif
83931diff --git a/include/linux/grsock.h b/include/linux/grsock.h
83932new file mode 100644
83933index 0000000..e7ffaaf
83934--- /dev/null
83935+++ b/include/linux/grsock.h
83936@@ -0,0 +1,19 @@
83937+#ifndef __GRSOCK_H
83938+#define __GRSOCK_H
83939+
83940+extern void gr_attach_curr_ip(const struct sock *sk);
83941+extern int gr_handle_sock_all(const int family, const int type,
83942+ const int protocol);
83943+extern int gr_handle_sock_server(const struct sockaddr *sck);
83944+extern int gr_handle_sock_server_other(const struct sock *sck);
83945+extern int gr_handle_sock_client(const struct sockaddr *sck);
83946+extern int gr_search_connect(struct socket * sock,
83947+ struct sockaddr_in * addr);
83948+extern int gr_search_bind(struct socket * sock,
83949+ struct sockaddr_in * addr);
83950+extern int gr_search_listen(struct socket * sock);
83951+extern int gr_search_accept(struct socket * sock);
83952+extern int gr_search_socket(const int domain, const int type,
83953+ const int protocol);
83954+
83955+#endif
83956diff --git a/include/linux/hash.h b/include/linux/hash.h
83957index bd1754c..8240892 100644
83958--- a/include/linux/hash.h
83959+++ b/include/linux/hash.h
83960@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
83961 struct fast_hash_ops {
83962 u32 (*hash)(const void *data, u32 len, u32 seed);
83963 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
83964-};
83965+} __no_const;
83966
83967 /**
83968 * arch_fast_hash - Caclulates a hash over a given buffer that can have
83969diff --git a/include/linux/highmem.h b/include/linux/highmem.h
83970index 7fb31da..08b5114 100644
83971--- a/include/linux/highmem.h
83972+++ b/include/linux/highmem.h
83973@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
83974 kunmap_atomic(kaddr);
83975 }
83976
83977+static inline void sanitize_highpage(struct page *page)
83978+{
83979+ void *kaddr;
83980+ unsigned long flags;
83981+
83982+ local_irq_save(flags);
83983+ kaddr = kmap_atomic(page);
83984+ clear_page(kaddr);
83985+ kunmap_atomic(kaddr);
83986+ local_irq_restore(flags);
83987+}
83988+
83989 static inline void zero_user_segments(struct page *page,
83990 unsigned start1, unsigned end1,
83991 unsigned start2, unsigned end2)
83992diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
83993index 1c7b89a..7dda400 100644
83994--- a/include/linux/hwmon-sysfs.h
83995+++ b/include/linux/hwmon-sysfs.h
83996@@ -25,7 +25,8 @@
83997 struct sensor_device_attribute{
83998 struct device_attribute dev_attr;
83999 int index;
84000-};
84001+} __do_const;
84002+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
84003 #define to_sensor_dev_attr(_dev_attr) \
84004 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
84005
84006@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
84007 struct device_attribute dev_attr;
84008 u8 index;
84009 u8 nr;
84010-};
84011+} __do_const;
84012+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
84013 #define to_sensor_dev_attr_2(_dev_attr) \
84014 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
84015
84016diff --git a/include/linux/i2c.h b/include/linux/i2c.h
84017index b556e0a..c10a515 100644
84018--- a/include/linux/i2c.h
84019+++ b/include/linux/i2c.h
84020@@ -378,6 +378,7 @@ struct i2c_algorithm {
84021 /* To determine what the adapter supports */
84022 u32 (*functionality) (struct i2c_adapter *);
84023 };
84024+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
84025
84026 /**
84027 * struct i2c_bus_recovery_info - I2C bus recovery information
84028diff --git a/include/linux/i2o.h b/include/linux/i2o.h
84029index d23c3c2..eb63c81 100644
84030--- a/include/linux/i2o.h
84031+++ b/include/linux/i2o.h
84032@@ -565,7 +565,7 @@ struct i2o_controller {
84033 struct i2o_device *exec; /* Executive */
84034 #if BITS_PER_LONG == 64
84035 spinlock_t context_list_lock; /* lock for context_list */
84036- atomic_t context_list_counter; /* needed for unique contexts */
84037+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
84038 struct list_head context_list; /* list of context id's
84039 and pointers */
84040 #endif
84041diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
84042index aff7ad8..3942bbd 100644
84043--- a/include/linux/if_pppox.h
84044+++ b/include/linux/if_pppox.h
84045@@ -76,7 +76,7 @@ struct pppox_proto {
84046 int (*ioctl)(struct socket *sock, unsigned int cmd,
84047 unsigned long arg);
84048 struct module *owner;
84049-};
84050+} __do_const;
84051
84052 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
84053 extern void unregister_pppox_proto(int proto_num);
84054diff --git a/include/linux/init.h b/include/linux/init.h
84055index 2df8e8d..3e1280d 100644
84056--- a/include/linux/init.h
84057+++ b/include/linux/init.h
84058@@ -37,9 +37,17 @@
84059 * section.
84060 */
84061
84062+#define add_init_latent_entropy __latent_entropy
84063+
84064+#ifdef CONFIG_MEMORY_HOTPLUG
84065+#define add_meminit_latent_entropy
84066+#else
84067+#define add_meminit_latent_entropy __latent_entropy
84068+#endif
84069+
84070 /* These are for everybody (although not all archs will actually
84071 discard it in modules) */
84072-#define __init __section(.init.text) __cold notrace
84073+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
84074 #define __initdata __section(.init.data)
84075 #define __initconst __constsection(.init.rodata)
84076 #define __exitdata __section(.exit.data)
84077@@ -100,7 +108,7 @@
84078 #define __cpuexitconst
84079
84080 /* Used for MEMORY_HOTPLUG */
84081-#define __meminit __section(.meminit.text) __cold notrace
84082+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
84083 #define __meminitdata __section(.meminit.data)
84084 #define __meminitconst __constsection(.meminit.rodata)
84085 #define __memexit __section(.memexit.text) __exitused __cold notrace
84086diff --git a/include/linux/init_task.h b/include/linux/init_task.h
84087index 6df7f9f..d0bf699 100644
84088--- a/include/linux/init_task.h
84089+++ b/include/linux/init_task.h
84090@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
84091
84092 #define INIT_TASK_COMM "swapper"
84093
84094+#ifdef CONFIG_X86
84095+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
84096+#else
84097+#define INIT_TASK_THREAD_INFO
84098+#endif
84099+
84100 #ifdef CONFIG_RT_MUTEXES
84101 # define INIT_RT_MUTEXES(tsk) \
84102 .pi_waiters = RB_ROOT, \
84103@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
84104 RCU_POINTER_INITIALIZER(cred, &init_cred), \
84105 .comm = INIT_TASK_COMM, \
84106 .thread = INIT_THREAD, \
84107+ INIT_TASK_THREAD_INFO \
84108 .fs = &init_fs, \
84109 .files = &init_files, \
84110 .signal = &init_signals, \
84111diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
84112index 698ad05..8601bb7 100644
84113--- a/include/linux/interrupt.h
84114+++ b/include/linux/interrupt.h
84115@@ -418,8 +418,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
84116
84117 struct softirq_action
84118 {
84119- void (*action)(struct softirq_action *);
84120-};
84121+ void (*action)(void);
84122+} __no_const;
84123
84124 asmlinkage void do_softirq(void);
84125 asmlinkage void __do_softirq(void);
84126@@ -433,7 +433,7 @@ static inline void do_softirq_own_stack(void)
84127 }
84128 #endif
84129
84130-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
84131+extern void open_softirq(int nr, void (*action)(void));
84132 extern void softirq_init(void);
84133 extern void __raise_softirq_irqoff(unsigned int nr);
84134
84135diff --git a/include/linux/iommu.h b/include/linux/iommu.h
84136index b96a5b2..2732d1c 100644
84137--- a/include/linux/iommu.h
84138+++ b/include/linux/iommu.h
84139@@ -131,7 +131,7 @@ struct iommu_ops {
84140 u32 (*domain_get_windows)(struct iommu_domain *domain);
84141
84142 unsigned long pgsize_bitmap;
84143-};
84144+} __do_const;
84145
84146 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
84147 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
84148diff --git a/include/linux/ioport.h b/include/linux/ioport.h
84149index 5e3a906..3131d0f 100644
84150--- a/include/linux/ioport.h
84151+++ b/include/linux/ioport.h
84152@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
84153 int adjust_resource(struct resource *res, resource_size_t start,
84154 resource_size_t size);
84155 resource_size_t resource_alignment(struct resource *res);
84156-static inline resource_size_t resource_size(const struct resource *res)
84157+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
84158 {
84159 return res->end - res->start + 1;
84160 }
84161diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
84162index 35e7eca..6afb7ad 100644
84163--- a/include/linux/ipc_namespace.h
84164+++ b/include/linux/ipc_namespace.h
84165@@ -69,7 +69,7 @@ struct ipc_namespace {
84166 struct user_namespace *user_ns;
84167
84168 unsigned int proc_inum;
84169-};
84170+} __randomize_layout;
84171
84172 extern struct ipc_namespace init_ipc_ns;
84173 extern atomic_t nr_ipc_ns;
84174diff --git a/include/linux/irq.h b/include/linux/irq.h
84175index 0d998d8..3a1c782 100644
84176--- a/include/linux/irq.h
84177+++ b/include/linux/irq.h
84178@@ -344,7 +344,8 @@ struct irq_chip {
84179 void (*irq_release_resources)(struct irq_data *data);
84180
84181 unsigned long flags;
84182-};
84183+} __do_const;
84184+typedef struct irq_chip __no_const irq_chip_no_const;
84185
84186 /*
84187 * irq_chip specific flags
84188diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
84189index 45e2d8c..26d85da 100644
84190--- a/include/linux/irqchip/arm-gic.h
84191+++ b/include/linux/irqchip/arm-gic.h
84192@@ -75,9 +75,11 @@
84193
84194 #ifndef __ASSEMBLY__
84195
84196+#include <linux/irq.h>
84197+
84198 struct device_node;
84199
84200-extern struct irq_chip gic_arch_extn;
84201+extern irq_chip_no_const gic_arch_extn;
84202
84203 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
84204 u32 offset, struct device_node *);
84205diff --git a/include/linux/isdn_ppp.h b/include/linux/isdn_ppp.h
84206index 8e10f57..d5f62bc 100644
84207--- a/include/linux/isdn_ppp.h
84208+++ b/include/linux/isdn_ppp.h
84209@@ -180,8 +180,9 @@ struct ippp_struct {
84210 struct slcompress *slcomp;
84211 #endif
84212 #ifdef CONFIG_IPPP_FILTER
84213- struct sk_filter *pass_filter; /* filter for packets to pass */
84214- struct sk_filter *active_filter; /* filter for pkts to reset idle */
84215+ struct sock_filter *pass_filter; /* filter for packets to pass */
84216+ struct sock_filter *active_filter; /* filter for pkts to reset idle */
84217+ unsigned pass_len, active_len;
84218 #endif
84219 unsigned long debug;
84220 struct isdn_ppp_compressor *compressor,*decompressor;
84221diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
84222index 1f44466..b481806 100644
84223--- a/include/linux/jiffies.h
84224+++ b/include/linux/jiffies.h
84225@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
84226 /*
84227 * Convert various time units to each other:
84228 */
84229-extern unsigned int jiffies_to_msecs(const unsigned long j);
84230-extern unsigned int jiffies_to_usecs(const unsigned long j);
84231+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
84232+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
84233
84234-static inline u64 jiffies_to_nsecs(const unsigned long j)
84235+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
84236 {
84237 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
84238 }
84239
84240-extern unsigned long msecs_to_jiffies(const unsigned int m);
84241-extern unsigned long usecs_to_jiffies(const unsigned int u);
84242+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
84243+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
84244 extern unsigned long timespec_to_jiffies(const struct timespec *value);
84245 extern void jiffies_to_timespec(const unsigned long jiffies,
84246- struct timespec *value);
84247-extern unsigned long timeval_to_jiffies(const struct timeval *value);
84248+ struct timespec *value) __intentional_overflow(-1);
84249+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
84250 extern void jiffies_to_timeval(const unsigned long jiffies,
84251 struct timeval *value);
84252
84253diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
84254index 6883e19..e854fcb 100644
84255--- a/include/linux/kallsyms.h
84256+++ b/include/linux/kallsyms.h
84257@@ -15,7 +15,8 @@
84258
84259 struct module;
84260
84261-#ifdef CONFIG_KALLSYMS
84262+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
84263+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
84264 /* Lookup the address for a symbol. Returns 0 if not found. */
84265 unsigned long kallsyms_lookup_name(const char *name);
84266
84267@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
84268 /* Stupid that this does nothing, but I didn't create this mess. */
84269 #define __print_symbol(fmt, addr)
84270 #endif /*CONFIG_KALLSYMS*/
84271+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
84272+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
84273+extern unsigned long kallsyms_lookup_name(const char *name);
84274+extern void __print_symbol(const char *fmt, unsigned long address);
84275+extern int sprint_backtrace(char *buffer, unsigned long address);
84276+extern int sprint_symbol(char *buffer, unsigned long address);
84277+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
84278+const char *kallsyms_lookup(unsigned long addr,
84279+ unsigned long *symbolsize,
84280+ unsigned long *offset,
84281+ char **modname, char *namebuf);
84282+extern int kallsyms_lookup_size_offset(unsigned long addr,
84283+ unsigned long *symbolsize,
84284+ unsigned long *offset);
84285+#endif
84286
84287 /* This macro allows us to keep printk typechecking */
84288 static __printf(1, 2)
84289diff --git a/include/linux/key-type.h b/include/linux/key-type.h
84290index a74c3a8..28d3f21 100644
84291--- a/include/linux/key-type.h
84292+++ b/include/linux/key-type.h
84293@@ -131,7 +131,7 @@ struct key_type {
84294 /* internal fields */
84295 struct list_head link; /* link in types list */
84296 struct lock_class_key lock_class; /* key->sem lock class */
84297-};
84298+} __do_const;
84299
84300 extern struct key_type key_type_keyring;
84301
84302diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
84303index 6b06d37..c134867 100644
84304--- a/include/linux/kgdb.h
84305+++ b/include/linux/kgdb.h
84306@@ -52,7 +52,7 @@ extern int kgdb_connected;
84307 extern int kgdb_io_module_registered;
84308
84309 extern atomic_t kgdb_setting_breakpoint;
84310-extern atomic_t kgdb_cpu_doing_single_step;
84311+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
84312
84313 extern struct task_struct *kgdb_usethread;
84314 extern struct task_struct *kgdb_contthread;
84315@@ -254,7 +254,7 @@ struct kgdb_arch {
84316 void (*correct_hw_break)(void);
84317
84318 void (*enable_nmi)(bool on);
84319-};
84320+} __do_const;
84321
84322 /**
84323 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
84324@@ -279,7 +279,7 @@ struct kgdb_io {
84325 void (*pre_exception) (void);
84326 void (*post_exception) (void);
84327 int is_console;
84328-};
84329+} __do_const;
84330
84331 extern struct kgdb_arch arch_kgdb_ops;
84332
84333diff --git a/include/linux/kmod.h b/include/linux/kmod.h
84334index 0555cc6..40116ce 100644
84335--- a/include/linux/kmod.h
84336+++ b/include/linux/kmod.h
84337@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
84338 * usually useless though. */
84339 extern __printf(2, 3)
84340 int __request_module(bool wait, const char *name, ...);
84341+extern __printf(3, 4)
84342+int ___request_module(bool wait, char *param_name, const char *name, ...);
84343 #define request_module(mod...) __request_module(true, mod)
84344 #define request_module_nowait(mod...) __request_module(false, mod)
84345 #define try_then_request_module(x, mod...) \
84346@@ -57,6 +59,9 @@ struct subprocess_info {
84347 struct work_struct work;
84348 struct completion *complete;
84349 char *path;
84350+#ifdef CONFIG_GRKERNSEC
84351+ char *origpath;
84352+#endif
84353 char **argv;
84354 char **envp;
84355 int wait;
84356diff --git a/include/linux/kobject.h b/include/linux/kobject.h
84357index 2d61b90..a1d0a13 100644
84358--- a/include/linux/kobject.h
84359+++ b/include/linux/kobject.h
84360@@ -118,7 +118,7 @@ struct kobj_type {
84361 struct attribute **default_attrs;
84362 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
84363 const void *(*namespace)(struct kobject *kobj);
84364-};
84365+} __do_const;
84366
84367 struct kobj_uevent_env {
84368 char *argv[3];
84369@@ -142,6 +142,7 @@ struct kobj_attribute {
84370 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
84371 const char *buf, size_t count);
84372 };
84373+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
84374
84375 extern const struct sysfs_ops kobj_sysfs_ops;
84376
84377@@ -169,7 +170,7 @@ struct kset {
84378 spinlock_t list_lock;
84379 struct kobject kobj;
84380 const struct kset_uevent_ops *uevent_ops;
84381-};
84382+} __randomize_layout;
84383
84384 extern void kset_init(struct kset *kset);
84385 extern int __must_check kset_register(struct kset *kset);
84386diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
84387index df32d25..fb52e27 100644
84388--- a/include/linux/kobject_ns.h
84389+++ b/include/linux/kobject_ns.h
84390@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
84391 const void *(*netlink_ns)(struct sock *sk);
84392 const void *(*initial_ns)(void);
84393 void (*drop_ns)(void *);
84394-};
84395+} __do_const;
84396
84397 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
84398 int kobj_ns_type_registered(enum kobj_ns_type type);
84399diff --git a/include/linux/kref.h b/include/linux/kref.h
84400index 484604d..0f6c5b6 100644
84401--- a/include/linux/kref.h
84402+++ b/include/linux/kref.h
84403@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
84404 static inline int kref_sub(struct kref *kref, unsigned int count,
84405 void (*release)(struct kref *kref))
84406 {
84407- WARN_ON(release == NULL);
84408+ BUG_ON(release == NULL);
84409
84410 if (atomic_sub_and_test((int) count, &kref->refcount)) {
84411 release(kref);
84412diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
84413index ec4e3bd..14db03a 100644
84414--- a/include/linux/kvm_host.h
84415+++ b/include/linux/kvm_host.h
84416@@ -468,7 +468,7 @@ static inline void kvm_irqfd_exit(void)
84417 {
84418 }
84419 #endif
84420-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84421+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84422 struct module *module);
84423 void kvm_exit(void);
84424
84425@@ -634,7 +634,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
84426 struct kvm_guest_debug *dbg);
84427 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
84428
84429-int kvm_arch_init(void *opaque);
84430+int kvm_arch_init(const void *opaque);
84431 void kvm_arch_exit(void);
84432
84433 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
84434diff --git a/include/linux/libata.h b/include/linux/libata.h
84435index 92abb49..e7fff2a 100644
84436--- a/include/linux/libata.h
84437+++ b/include/linux/libata.h
84438@@ -976,7 +976,7 @@ struct ata_port_operations {
84439 * fields must be pointers.
84440 */
84441 const struct ata_port_operations *inherits;
84442-};
84443+} __do_const;
84444
84445 struct ata_port_info {
84446 unsigned long flags;
84447diff --git a/include/linux/linkage.h b/include/linux/linkage.h
84448index a6a42dd..6c5ebce 100644
84449--- a/include/linux/linkage.h
84450+++ b/include/linux/linkage.h
84451@@ -36,6 +36,7 @@
84452 #endif
84453
84454 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
84455+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
84456 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
84457
84458 /*
84459diff --git a/include/linux/list.h b/include/linux/list.h
84460index ef95941..82db65a 100644
84461--- a/include/linux/list.h
84462+++ b/include/linux/list.h
84463@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
84464 extern void list_del(struct list_head *entry);
84465 #endif
84466
84467+extern void __pax_list_add(struct list_head *new,
84468+ struct list_head *prev,
84469+ struct list_head *next);
84470+static inline void pax_list_add(struct list_head *new, struct list_head *head)
84471+{
84472+ __pax_list_add(new, head, head->next);
84473+}
84474+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
84475+{
84476+ __pax_list_add(new, head->prev, head);
84477+}
84478+extern void pax_list_del(struct list_head *entry);
84479+
84480 /**
84481 * list_replace - replace old entry by new one
84482 * @old : the element to be replaced
84483@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
84484 INIT_LIST_HEAD(entry);
84485 }
84486
84487+extern void pax_list_del_init(struct list_head *entry);
84488+
84489 /**
84490 * list_move - delete from one list and add as another's head
84491 * @list: the entry to move
84492diff --git a/include/linux/math64.h b/include/linux/math64.h
84493index c45c089..298841c 100644
84494--- a/include/linux/math64.h
84495+++ b/include/linux/math64.h
84496@@ -15,7 +15,7 @@
84497 * This is commonly provided by 32bit archs to provide an optimized 64bit
84498 * divide.
84499 */
84500-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84501+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84502 {
84503 *remainder = dividend % divisor;
84504 return dividend / divisor;
84505@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
84506 /**
84507 * div64_u64 - unsigned 64bit divide with 64bit divisor
84508 */
84509-static inline u64 div64_u64(u64 dividend, u64 divisor)
84510+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
84511 {
84512 return dividend / divisor;
84513 }
84514@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
84515 #define div64_ul(x, y) div_u64((x), (y))
84516
84517 #ifndef div_u64_rem
84518-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84519+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84520 {
84521 *remainder = do_div(dividend, divisor);
84522 return dividend;
84523@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
84524 #endif
84525
84526 #ifndef div64_u64
84527-extern u64 div64_u64(u64 dividend, u64 divisor);
84528+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
84529 #endif
84530
84531 #ifndef div64_s64
84532@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
84533 * divide.
84534 */
84535 #ifndef div_u64
84536-static inline u64 div_u64(u64 dividend, u32 divisor)
84537+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
84538 {
84539 u32 remainder;
84540 return div_u64_rem(dividend, divisor, &remainder);
84541diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
84542index f230a97..714c006 100644
84543--- a/include/linux/mempolicy.h
84544+++ b/include/linux/mempolicy.h
84545@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
84546 }
84547
84548 #define vma_policy(vma) ((vma)->vm_policy)
84549+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
84550+{
84551+ vma->vm_policy = pol;
84552+}
84553
84554 static inline void mpol_get(struct mempolicy *pol)
84555 {
84556@@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
84557 }
84558
84559 #define vma_policy(vma) NULL
84560+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
84561+{
84562+}
84563
84564 static inline int
84565 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
84566diff --git a/include/linux/mm.h b/include/linux/mm.h
84567index e03dd29..eaf923c 100644
84568--- a/include/linux/mm.h
84569+++ b/include/linux/mm.h
84570@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
84571 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
84572 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
84573 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
84574+
84575+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
84576+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
84577+#endif
84578+
84579 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
84580
84581 #ifdef CONFIG_MEM_SOFT_DIRTY
84582@@ -237,8 +242,8 @@ struct vm_operations_struct {
84583 /* called by access_process_vm when get_user_pages() fails, typically
84584 * for use by special VMAs that can switch between memory and hardware
84585 */
84586- int (*access)(struct vm_area_struct *vma, unsigned long addr,
84587- void *buf, int len, int write);
84588+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
84589+ void *buf, size_t len, int write);
84590
84591 /* Called by the /proc/PID/maps code to ask the vma whether it
84592 * has a special name. Returning non-NULL will also cause this
84593@@ -274,6 +279,7 @@ struct vm_operations_struct {
84594 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
84595 unsigned long size, pgoff_t pgoff);
84596 };
84597+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
84598
84599 struct mmu_gather;
84600 struct inode;
84601@@ -1144,8 +1150,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
84602 unsigned long *pfn);
84603 int follow_phys(struct vm_area_struct *vma, unsigned long address,
84604 unsigned int flags, unsigned long *prot, resource_size_t *phys);
84605-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
84606- void *buf, int len, int write);
84607+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
84608+ void *buf, size_t len, int write);
84609
84610 static inline void unmap_shared_mapping_range(struct address_space *mapping,
84611 loff_t const holebegin, loff_t const holelen)
84612@@ -1184,9 +1190,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
84613 }
84614 #endif
84615
84616-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
84617-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84618- void *buf, int len, int write);
84619+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
84620+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
84621+ void *buf, size_t len, int write);
84622
84623 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
84624 unsigned long start, unsigned long nr_pages,
84625@@ -1219,34 +1225,6 @@ int set_page_dirty_lock(struct page *page);
84626 int clear_page_dirty_for_io(struct page *page);
84627 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
84628
84629-/* Is the vma a continuation of the stack vma above it? */
84630-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
84631-{
84632- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
84633-}
84634-
84635-static inline int stack_guard_page_start(struct vm_area_struct *vma,
84636- unsigned long addr)
84637-{
84638- return (vma->vm_flags & VM_GROWSDOWN) &&
84639- (vma->vm_start == addr) &&
84640- !vma_growsdown(vma->vm_prev, addr);
84641-}
84642-
84643-/* Is the vma a continuation of the stack vma below it? */
84644-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
84645-{
84646- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
84647-}
84648-
84649-static inline int stack_guard_page_end(struct vm_area_struct *vma,
84650- unsigned long addr)
84651-{
84652- return (vma->vm_flags & VM_GROWSUP) &&
84653- (vma->vm_end == addr) &&
84654- !vma_growsup(vma->vm_next, addr);
84655-}
84656-
84657 extern pid_t
84658 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
84659
84660@@ -1346,6 +1324,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
84661 }
84662 #endif
84663
84664+#ifdef CONFIG_MMU
84665+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
84666+#else
84667+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
84668+{
84669+ return __pgprot(0);
84670+}
84671+#endif
84672+
84673 int vma_wants_writenotify(struct vm_area_struct *vma);
84674
84675 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
84676@@ -1364,8 +1351,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
84677 {
84678 return 0;
84679 }
84680+
84681+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
84682+ unsigned long address)
84683+{
84684+ return 0;
84685+}
84686 #else
84687 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
84688+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
84689 #endif
84690
84691 #ifdef __PAGETABLE_PMD_FOLDED
84692@@ -1374,8 +1368,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
84693 {
84694 return 0;
84695 }
84696+
84697+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
84698+ unsigned long address)
84699+{
84700+ return 0;
84701+}
84702 #else
84703 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
84704+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
84705 #endif
84706
84707 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
84708@@ -1393,11 +1394,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
84709 NULL: pud_offset(pgd, address);
84710 }
84711
84712+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
84713+{
84714+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
84715+ NULL: pud_offset(pgd, address);
84716+}
84717+
84718 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
84719 {
84720 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
84721 NULL: pmd_offset(pud, address);
84722 }
84723+
84724+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
84725+{
84726+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
84727+ NULL: pmd_offset(pud, address);
84728+}
84729 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
84730
84731 #if USE_SPLIT_PTE_PTLOCKS
84732@@ -1796,7 +1809,7 @@ extern int install_special_mapping(struct mm_struct *mm,
84733 unsigned long addr, unsigned long len,
84734 unsigned long flags, struct page **pages);
84735
84736-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
84737+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
84738
84739 extern unsigned long mmap_region(struct file *file, unsigned long addr,
84740 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
84741@@ -1804,6 +1817,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
84742 unsigned long len, unsigned long prot, unsigned long flags,
84743 unsigned long pgoff, unsigned long *populate);
84744 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
84745+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
84746
84747 #ifdef CONFIG_MMU
84748 extern int __mm_populate(unsigned long addr, unsigned long len,
84749@@ -1832,10 +1846,11 @@ struct vm_unmapped_area_info {
84750 unsigned long high_limit;
84751 unsigned long align_mask;
84752 unsigned long align_offset;
84753+ unsigned long threadstack_offset;
84754 };
84755
84756-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
84757-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
84758+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
84759+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
84760
84761 /*
84762 * Search for an unmapped address range.
84763@@ -1847,7 +1862,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
84764 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
84765 */
84766 static inline unsigned long
84767-vm_unmapped_area(struct vm_unmapped_area_info *info)
84768+vm_unmapped_area(const struct vm_unmapped_area_info *info)
84769 {
84770 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
84771 return unmapped_area(info);
84772@@ -1909,6 +1924,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
84773 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
84774 struct vm_area_struct **pprev);
84775
84776+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
84777+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
84778+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
84779+
84780 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
84781 NULL if none. Assume start_addr < end_addr. */
84782 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
84783@@ -1937,15 +1956,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
84784 return vma;
84785 }
84786
84787-#ifdef CONFIG_MMU
84788-pgprot_t vm_get_page_prot(unsigned long vm_flags);
84789-#else
84790-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
84791-{
84792- return __pgprot(0);
84793-}
84794-#endif
84795-
84796 #ifdef CONFIG_NUMA_BALANCING
84797 unsigned long change_prot_numa(struct vm_area_struct *vma,
84798 unsigned long start, unsigned long end);
84799@@ -1997,6 +2007,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
84800 static inline void vm_stat_account(struct mm_struct *mm,
84801 unsigned long flags, struct file *file, long pages)
84802 {
84803+
84804+#ifdef CONFIG_PAX_RANDMMAP
84805+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
84806+#endif
84807+
84808 mm->total_vm += pages;
84809 }
84810 #endif /* CONFIG_PROC_FS */
84811@@ -2078,7 +2093,7 @@ extern int unpoison_memory(unsigned long pfn);
84812 extern int sysctl_memory_failure_early_kill;
84813 extern int sysctl_memory_failure_recovery;
84814 extern void shake_page(struct page *p, int access);
84815-extern atomic_long_t num_poisoned_pages;
84816+extern atomic_long_unchecked_t num_poisoned_pages;
84817 extern int soft_offline_page(struct page *page, int flags);
84818
84819 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
84820@@ -2113,5 +2128,11 @@ void __init setup_nr_node_ids(void);
84821 static inline void setup_nr_node_ids(void) {}
84822 #endif
84823
84824+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
84825+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
84826+#else
84827+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
84828+#endif
84829+
84830 #endif /* __KERNEL__ */
84831 #endif /* _LINUX_MM_H */
84832diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
84833index 96c5750..15668ba 100644
84834--- a/include/linux/mm_types.h
84835+++ b/include/linux/mm_types.h
84836@@ -308,7 +308,9 @@ struct vm_area_struct {
84837 #ifdef CONFIG_NUMA
84838 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
84839 #endif
84840-};
84841+
84842+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
84843+} __randomize_layout;
84844
84845 struct core_thread {
84846 struct task_struct *task;
84847@@ -454,7 +456,25 @@ struct mm_struct {
84848 bool tlb_flush_pending;
84849 #endif
84850 struct uprobes_state uprobes_state;
84851-};
84852+
84853+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
84854+ unsigned long pax_flags;
84855+#endif
84856+
84857+#ifdef CONFIG_PAX_DLRESOLVE
84858+ unsigned long call_dl_resolve;
84859+#endif
84860+
84861+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
84862+ unsigned long call_syscall;
84863+#endif
84864+
84865+#ifdef CONFIG_PAX_ASLR
84866+ unsigned long delta_mmap; /* randomized offset */
84867+ unsigned long delta_stack; /* randomized offset */
84868+#endif
84869+
84870+} __randomize_layout;
84871
84872 static inline void mm_init_cpumask(struct mm_struct *mm)
84873 {
84874diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
84875index c5d5278..f0b68c8 100644
84876--- a/include/linux/mmiotrace.h
84877+++ b/include/linux/mmiotrace.h
84878@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
84879 /* Called from ioremap.c */
84880 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
84881 void __iomem *addr);
84882-extern void mmiotrace_iounmap(volatile void __iomem *addr);
84883+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
84884
84885 /* For anyone to insert markers. Remember trailing newline. */
84886 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
84887@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
84888 {
84889 }
84890
84891-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
84892+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
84893 {
84894 }
84895
84896diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
84897index 6cbd1b6..b1d2f99 100644
84898--- a/include/linux/mmzone.h
84899+++ b/include/linux/mmzone.h
84900@@ -412,7 +412,7 @@ struct zone {
84901 unsigned long flags; /* zone flags, see below */
84902
84903 /* Zone statistics */
84904- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
84905+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
84906
84907 /*
84908 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
84909diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
84910index 44eeef0..a92d3f9 100644
84911--- a/include/linux/mod_devicetable.h
84912+++ b/include/linux/mod_devicetable.h
84913@@ -139,7 +139,7 @@ struct usb_device_id {
84914 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
84915 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
84916
84917-#define HID_ANY_ID (~0)
84918+#define HID_ANY_ID (~0U)
84919 #define HID_BUS_ANY 0xffff
84920 #define HID_GROUP_ANY 0x0000
84921
84922@@ -475,7 +475,7 @@ struct dmi_system_id {
84923 const char *ident;
84924 struct dmi_strmatch matches[4];
84925 void *driver_data;
84926-};
84927+} __do_const;
84928 /*
84929 * struct dmi_device_id appears during expansion of
84930 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
84931diff --git a/include/linux/module.h b/include/linux/module.h
84932index f520a76..5f898ef 100644
84933--- a/include/linux/module.h
84934+++ b/include/linux/module.h
84935@@ -17,9 +17,11 @@
84936 #include <linux/moduleparam.h>
84937 #include <linux/jump_label.h>
84938 #include <linux/export.h>
84939+#include <linux/fs.h>
84940
84941 #include <linux/percpu.h>
84942 #include <asm/module.h>
84943+#include <asm/pgtable.h>
84944
84945 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
84946 #define MODULE_SIG_STRING "~Module signature appended~\n"
84947@@ -42,7 +44,7 @@ struct module_kobject {
84948 struct kobject *drivers_dir;
84949 struct module_param_attrs *mp;
84950 struct completion *kobj_completion;
84951-};
84952+} __randomize_layout;
84953
84954 struct module_attribute {
84955 struct attribute attr;
84956@@ -54,12 +56,13 @@ struct module_attribute {
84957 int (*test)(struct module *);
84958 void (*free)(struct module *);
84959 };
84960+typedef struct module_attribute __no_const module_attribute_no_const;
84961
84962 struct module_version_attribute {
84963 struct module_attribute mattr;
84964 const char *module_name;
84965 const char *version;
84966-} __attribute__ ((__aligned__(sizeof(void *))));
84967+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
84968
84969 extern ssize_t __modver_version_show(struct module_attribute *,
84970 struct module_kobject *, char *);
84971@@ -235,7 +238,7 @@ struct module {
84972
84973 /* Sysfs stuff. */
84974 struct module_kobject mkobj;
84975- struct module_attribute *modinfo_attrs;
84976+ module_attribute_no_const *modinfo_attrs;
84977 const char *version;
84978 const char *srcversion;
84979 struct kobject *holders_dir;
84980@@ -284,19 +287,16 @@ struct module {
84981 int (*init)(void);
84982
84983 /* If this is non-NULL, vfree after init() returns */
84984- void *module_init;
84985+ void *module_init_rx, *module_init_rw;
84986
84987 /* Here is the actual code + data, vfree'd on unload. */
84988- void *module_core;
84989+ void *module_core_rx, *module_core_rw;
84990
84991 /* Here are the sizes of the init and core sections */
84992- unsigned int init_size, core_size;
84993+ unsigned int init_size_rw, core_size_rw;
84994
84995 /* The size of the executable code in each section. */
84996- unsigned int init_text_size, core_text_size;
84997-
84998- /* Size of RO sections of the module (text+rodata) */
84999- unsigned int init_ro_size, core_ro_size;
85000+ unsigned int init_size_rx, core_size_rx;
85001
85002 /* Arch-specific module values */
85003 struct mod_arch_specific arch;
85004@@ -352,6 +352,10 @@ struct module {
85005 #ifdef CONFIG_EVENT_TRACING
85006 struct ftrace_event_call **trace_events;
85007 unsigned int num_trace_events;
85008+ struct file_operations trace_id;
85009+ struct file_operations trace_enable;
85010+ struct file_operations trace_format;
85011+ struct file_operations trace_filter;
85012 #endif
85013 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
85014 unsigned int num_ftrace_callsites;
85015@@ -375,7 +379,7 @@ struct module {
85016 ctor_fn_t *ctors;
85017 unsigned int num_ctors;
85018 #endif
85019-};
85020+} __randomize_layout;
85021 #ifndef MODULE_ARCH_INIT
85022 #define MODULE_ARCH_INIT {}
85023 #endif
85024@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
85025 bool is_module_percpu_address(unsigned long addr);
85026 bool is_module_text_address(unsigned long addr);
85027
85028+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
85029+{
85030+
85031+#ifdef CONFIG_PAX_KERNEXEC
85032+ if (ktla_ktva(addr) >= (unsigned long)start &&
85033+ ktla_ktva(addr) < (unsigned long)start + size)
85034+ return 1;
85035+#endif
85036+
85037+ return ((void *)addr >= start && (void *)addr < start + size);
85038+}
85039+
85040+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
85041+{
85042+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
85043+}
85044+
85045+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
85046+{
85047+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
85048+}
85049+
85050+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
85051+{
85052+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
85053+}
85054+
85055+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
85056+{
85057+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
85058+}
85059+
85060 static inline int within_module_core(unsigned long addr, const struct module *mod)
85061 {
85062- return (unsigned long)mod->module_core <= addr &&
85063- addr < (unsigned long)mod->module_core + mod->core_size;
85064+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
85065 }
85066
85067 static inline int within_module_init(unsigned long addr, const struct module *mod)
85068 {
85069- return (unsigned long)mod->module_init <= addr &&
85070- addr < (unsigned long)mod->module_init + mod->init_size;
85071+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
85072 }
85073
85074 /* Search for module by name: must hold module_mutex. */
85075diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
85076index 560ca53..ef621ef 100644
85077--- a/include/linux/moduleloader.h
85078+++ b/include/linux/moduleloader.h
85079@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
85080 sections. Returns NULL on failure. */
85081 void *module_alloc(unsigned long size);
85082
85083+#ifdef CONFIG_PAX_KERNEXEC
85084+void *module_alloc_exec(unsigned long size);
85085+#else
85086+#define module_alloc_exec(x) module_alloc(x)
85087+#endif
85088+
85089 /* Free memory returned from module_alloc. */
85090 void module_free(struct module *mod, void *module_region);
85091
85092+#ifdef CONFIG_PAX_KERNEXEC
85093+void module_free_exec(struct module *mod, void *module_region);
85094+#else
85095+#define module_free_exec(x, y) module_free((x), (y))
85096+#endif
85097+
85098 /*
85099 * Apply the given relocation to the (simplified) ELF. Return -error
85100 * or 0.
85101@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
85102 unsigned int relsec,
85103 struct module *me)
85104 {
85105+#ifdef CONFIG_MODULES
85106 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
85107+#endif
85108 return -ENOEXEC;
85109 }
85110 #endif
85111@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
85112 unsigned int relsec,
85113 struct module *me)
85114 {
85115+#ifdef CONFIG_MODULES
85116 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
85117+#endif
85118 return -ENOEXEC;
85119 }
85120 #endif
85121diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
85122index b1990c5..2a6e611 100644
85123--- a/include/linux/moduleparam.h
85124+++ b/include/linux/moduleparam.h
85125@@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
85126 * @len is usually just sizeof(string).
85127 */
85128 #define module_param_string(name, string, len, perm) \
85129- static const struct kparam_string __param_string_##name \
85130+ static const struct kparam_string __param_string_##name __used \
85131 = { len, string }; \
85132 __module_param_call(MODULE_PARAM_PREFIX, name, \
85133 &param_ops_string, \
85134@@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
85135 */
85136 #define module_param_array_named(name, array, type, nump, perm) \
85137 param_check_##type(name, &(array)[0]); \
85138- static const struct kparam_array __param_arr_##name \
85139+ static const struct kparam_array __param_arr_##name __used \
85140 = { .max = ARRAY_SIZE(array), .num = nump, \
85141 .ops = &param_ops_##type, \
85142 .elemsize = sizeof(array[0]), .elem = array }; \
85143diff --git a/include/linux/mount.h b/include/linux/mount.h
85144index 839bac2..a96b37c 100644
85145--- a/include/linux/mount.h
85146+++ b/include/linux/mount.h
85147@@ -59,7 +59,7 @@ struct vfsmount {
85148 struct dentry *mnt_root; /* root of the mounted tree */
85149 struct super_block *mnt_sb; /* pointer to superblock */
85150 int mnt_flags;
85151-};
85152+} __randomize_layout;
85153
85154 struct file; /* forward dec */
85155
85156diff --git a/include/linux/namei.h b/include/linux/namei.h
85157index 492de72..1bddcd4 100644
85158--- a/include/linux/namei.h
85159+++ b/include/linux/namei.h
85160@@ -19,7 +19,7 @@ struct nameidata {
85161 unsigned seq, m_seq;
85162 int last_type;
85163 unsigned depth;
85164- char *saved_names[MAX_NESTED_LINKS + 1];
85165+ const char *saved_names[MAX_NESTED_LINKS + 1];
85166 };
85167
85168 /*
85169@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
85170
85171 extern void nd_jump_link(struct nameidata *nd, struct path *path);
85172
85173-static inline void nd_set_link(struct nameidata *nd, char *path)
85174+static inline void nd_set_link(struct nameidata *nd, const char *path)
85175 {
85176 nd->saved_names[nd->depth] = path;
85177 }
85178
85179-static inline char *nd_get_link(struct nameidata *nd)
85180+static inline const char *nd_get_link(const struct nameidata *nd)
85181 {
85182 return nd->saved_names[nd->depth];
85183 }
85184diff --git a/include/linux/net.h b/include/linux/net.h
85185index 17d8339..81656c0 100644
85186--- a/include/linux/net.h
85187+++ b/include/linux/net.h
85188@@ -192,7 +192,7 @@ struct net_proto_family {
85189 int (*create)(struct net *net, struct socket *sock,
85190 int protocol, int kern);
85191 struct module *owner;
85192-};
85193+} __do_const;
85194
85195 struct iovec;
85196 struct kvec;
85197diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
85198index 66f9a04..056078d 100644
85199--- a/include/linux/netdevice.h
85200+++ b/include/linux/netdevice.h
85201@@ -1145,6 +1145,7 @@ struct net_device_ops {
85202 void *priv);
85203 int (*ndo_get_lock_subclass)(struct net_device *dev);
85204 };
85205+typedef struct net_device_ops __no_const net_device_ops_no_const;
85206
85207 /**
85208 * enum net_device_priv_flags - &struct net_device priv_flags
85209@@ -1312,11 +1313,11 @@ struct net_device {
85210 struct net_device_stats stats;
85211
85212 /* dropped packets by core network, Do not use this in drivers */
85213- atomic_long_t rx_dropped;
85214- atomic_long_t tx_dropped;
85215+ atomic_long_unchecked_t rx_dropped;
85216+ atomic_long_unchecked_t tx_dropped;
85217
85218 /* Stats to monitor carrier on<->off transitions */
85219- atomic_t carrier_changes;
85220+ atomic_unchecked_t carrier_changes;
85221
85222 #ifdef CONFIG_WIRELESS_EXT
85223 /* List of functions to handle Wireless Extensions (instead of ioctl).
85224diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
85225index 2077489..a15e561 100644
85226--- a/include/linux/netfilter.h
85227+++ b/include/linux/netfilter.h
85228@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
85229 #endif
85230 /* Use the module struct to lock set/get code in place */
85231 struct module *owner;
85232-};
85233+} __do_const;
85234
85235 /* Function to register/unregister hook points. */
85236 int nf_register_hook(struct nf_hook_ops *reg);
85237diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
85238index e955d47..04a5338 100644
85239--- a/include/linux/netfilter/nfnetlink.h
85240+++ b/include/linux/netfilter/nfnetlink.h
85241@@ -19,7 +19,7 @@ struct nfnl_callback {
85242 const struct nlattr * const cda[]);
85243 const struct nla_policy *policy; /* netlink attribute policy */
85244 const u_int16_t attr_count; /* number of nlattr's */
85245-};
85246+} __do_const;
85247
85248 struct nfnetlink_subsystem {
85249 const char *name;
85250diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
85251new file mode 100644
85252index 0000000..33f4af8
85253--- /dev/null
85254+++ b/include/linux/netfilter/xt_gradm.h
85255@@ -0,0 +1,9 @@
85256+#ifndef _LINUX_NETFILTER_XT_GRADM_H
85257+#define _LINUX_NETFILTER_XT_GRADM_H 1
85258+
85259+struct xt_gradm_mtinfo {
85260+ __u16 flags;
85261+ __u16 invflags;
85262+};
85263+
85264+#endif
85265diff --git a/include/linux/nls.h b/include/linux/nls.h
85266index 520681b..2b7fabb 100644
85267--- a/include/linux/nls.h
85268+++ b/include/linux/nls.h
85269@@ -31,7 +31,7 @@ struct nls_table {
85270 const unsigned char *charset2upper;
85271 struct module *owner;
85272 struct nls_table *next;
85273-};
85274+} __do_const;
85275
85276 /* this value hold the maximum octet of charset */
85277 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
85278@@ -46,7 +46,7 @@ enum utf16_endian {
85279 /* nls_base.c */
85280 extern int __register_nls(struct nls_table *, struct module *);
85281 extern int unregister_nls(struct nls_table *);
85282-extern struct nls_table *load_nls(char *);
85283+extern struct nls_table *load_nls(const char *);
85284 extern void unload_nls(struct nls_table *);
85285 extern struct nls_table *load_nls_default(void);
85286 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
85287diff --git a/include/linux/notifier.h b/include/linux/notifier.h
85288index d14a4c3..a078786 100644
85289--- a/include/linux/notifier.h
85290+++ b/include/linux/notifier.h
85291@@ -54,7 +54,8 @@ struct notifier_block {
85292 notifier_fn_t notifier_call;
85293 struct notifier_block __rcu *next;
85294 int priority;
85295-};
85296+} __do_const;
85297+typedef struct notifier_block __no_const notifier_block_no_const;
85298
85299 struct atomic_notifier_head {
85300 spinlock_t lock;
85301diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
85302index b2a0f15..4d7da32 100644
85303--- a/include/linux/oprofile.h
85304+++ b/include/linux/oprofile.h
85305@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
85306 int oprofilefs_create_ro_ulong(struct dentry * root,
85307 char const * name, ulong * val);
85308
85309-/** Create a file for read-only access to an atomic_t. */
85310+/** Create a file for read-only access to an atomic_unchecked_t. */
85311 int oprofilefs_create_ro_atomic(struct dentry * root,
85312- char const * name, atomic_t * val);
85313+ char const * name, atomic_unchecked_t * val);
85314
85315 /** create a directory */
85316 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
85317diff --git a/include/linux/padata.h b/include/linux/padata.h
85318index 4386946..f50c615 100644
85319--- a/include/linux/padata.h
85320+++ b/include/linux/padata.h
85321@@ -129,7 +129,7 @@ struct parallel_data {
85322 struct padata_serial_queue __percpu *squeue;
85323 atomic_t reorder_objects;
85324 atomic_t refcnt;
85325- atomic_t seq_nr;
85326+ atomic_unchecked_t seq_nr;
85327 struct padata_cpumask cpumask;
85328 spinlock_t lock ____cacheline_aligned;
85329 unsigned int processed;
85330diff --git a/include/linux/path.h b/include/linux/path.h
85331index d137218..be0c176 100644
85332--- a/include/linux/path.h
85333+++ b/include/linux/path.h
85334@@ -1,13 +1,15 @@
85335 #ifndef _LINUX_PATH_H
85336 #define _LINUX_PATH_H
85337
85338+#include <linux/compiler.h>
85339+
85340 struct dentry;
85341 struct vfsmount;
85342
85343 struct path {
85344 struct vfsmount *mnt;
85345 struct dentry *dentry;
85346-};
85347+} __randomize_layout;
85348
85349 extern void path_get(const struct path *);
85350 extern void path_put(const struct path *);
85351diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
85352index 5f2e559..7d59314 100644
85353--- a/include/linux/pci_hotplug.h
85354+++ b/include/linux/pci_hotplug.h
85355@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
85356 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
85357 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
85358 int (*reset_slot) (struct hotplug_slot *slot, int probe);
85359-};
85360+} __do_const;
85361+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
85362
85363 /**
85364 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
85365diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
85366index 707617a..28a2e7e 100644
85367--- a/include/linux/perf_event.h
85368+++ b/include/linux/perf_event.h
85369@@ -339,8 +339,8 @@ struct perf_event {
85370
85371 enum perf_event_active_state state;
85372 unsigned int attach_state;
85373- local64_t count;
85374- atomic64_t child_count;
85375+ local64_t count; /* PaX: fix it one day */
85376+ atomic64_unchecked_t child_count;
85377
85378 /*
85379 * These are the total time in nanoseconds that the event
85380@@ -391,8 +391,8 @@ struct perf_event {
85381 * These accumulate total time (in nanoseconds) that children
85382 * events have been enabled and running, respectively.
85383 */
85384- atomic64_t child_total_time_enabled;
85385- atomic64_t child_total_time_running;
85386+ atomic64_unchecked_t child_total_time_enabled;
85387+ atomic64_unchecked_t child_total_time_running;
85388
85389 /*
85390 * Protect attach/detach and child_list:
85391@@ -722,7 +722,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
85392 entry->ip[entry->nr++] = ip;
85393 }
85394
85395-extern int sysctl_perf_event_paranoid;
85396+extern int sysctl_perf_event_legitimately_concerned;
85397 extern int sysctl_perf_event_mlock;
85398 extern int sysctl_perf_event_sample_rate;
85399 extern int sysctl_perf_cpu_time_max_percent;
85400@@ -737,19 +737,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
85401 loff_t *ppos);
85402
85403
85404+static inline bool perf_paranoid_any(void)
85405+{
85406+ return sysctl_perf_event_legitimately_concerned > 2;
85407+}
85408+
85409 static inline bool perf_paranoid_tracepoint_raw(void)
85410 {
85411- return sysctl_perf_event_paranoid > -1;
85412+ return sysctl_perf_event_legitimately_concerned > -1;
85413 }
85414
85415 static inline bool perf_paranoid_cpu(void)
85416 {
85417- return sysctl_perf_event_paranoid > 0;
85418+ return sysctl_perf_event_legitimately_concerned > 0;
85419 }
85420
85421 static inline bool perf_paranoid_kernel(void)
85422 {
85423- return sysctl_perf_event_paranoid > 1;
85424+ return sysctl_perf_event_legitimately_concerned > 1;
85425 }
85426
85427 extern void perf_event_init(void);
85428@@ -880,7 +885,7 @@ struct perf_pmu_events_attr {
85429 struct device_attribute attr;
85430 u64 id;
85431 const char *event_str;
85432-};
85433+} __do_const;
85434
85435 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
85436 static struct perf_pmu_events_attr _var = { \
85437diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
85438index 7246ef3..1539ea4 100644
85439--- a/include/linux/pid_namespace.h
85440+++ b/include/linux/pid_namespace.h
85441@@ -43,7 +43,7 @@ struct pid_namespace {
85442 int hide_pid;
85443 int reboot; /* group exit code if this pidns was rebooted */
85444 unsigned int proc_inum;
85445-};
85446+} __randomize_layout;
85447
85448 extern struct pid_namespace init_pid_ns;
85449
85450diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
85451index eb8b8ac..62649e1 100644
85452--- a/include/linux/pipe_fs_i.h
85453+++ b/include/linux/pipe_fs_i.h
85454@@ -47,10 +47,10 @@ struct pipe_inode_info {
85455 struct mutex mutex;
85456 wait_queue_head_t wait;
85457 unsigned int nrbufs, curbuf, buffers;
85458- unsigned int readers;
85459- unsigned int writers;
85460- unsigned int files;
85461- unsigned int waiting_writers;
85462+ atomic_t readers;
85463+ atomic_t writers;
85464+ atomic_t files;
85465+ atomic_t waiting_writers;
85466 unsigned int r_counter;
85467 unsigned int w_counter;
85468 struct page *tmp_page;
85469diff --git a/include/linux/pm.h b/include/linux/pm.h
85470index 72c0fe0..26918ed 100644
85471--- a/include/linux/pm.h
85472+++ b/include/linux/pm.h
85473@@ -620,6 +620,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
85474 struct dev_pm_domain {
85475 struct dev_pm_ops ops;
85476 };
85477+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
85478
85479 /*
85480 * The PM_EVENT_ messages are also used by drivers implementing the legacy
85481diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
85482index 7c1d252..0e7061d 100644
85483--- a/include/linux/pm_domain.h
85484+++ b/include/linux/pm_domain.h
85485@@ -44,11 +44,11 @@ struct gpd_dev_ops {
85486 int (*thaw_early)(struct device *dev);
85487 int (*thaw)(struct device *dev);
85488 bool (*active_wakeup)(struct device *dev);
85489-};
85490+} __no_const;
85491
85492 struct gpd_cpu_data {
85493 unsigned int saved_exit_latency;
85494- struct cpuidle_state *idle_state;
85495+ cpuidle_state_no_const *idle_state;
85496 };
85497
85498 struct generic_pm_domain {
85499diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
85500index 43fd671..08c96ee 100644
85501--- a/include/linux/pm_runtime.h
85502+++ b/include/linux/pm_runtime.h
85503@@ -118,7 +118,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
85504
85505 static inline void pm_runtime_mark_last_busy(struct device *dev)
85506 {
85507- ACCESS_ONCE(dev->power.last_busy) = jiffies;
85508+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
85509 }
85510
85511 #else /* !CONFIG_PM_RUNTIME */
85512diff --git a/include/linux/pnp.h b/include/linux/pnp.h
85513index 195aafc..49a7bc2 100644
85514--- a/include/linux/pnp.h
85515+++ b/include/linux/pnp.h
85516@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
85517 struct pnp_fixup {
85518 char id[7];
85519 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
85520-};
85521+} __do_const;
85522
85523 /* config parameters */
85524 #define PNP_CONFIG_NORMAL 0x0001
85525diff --git a/include/linux/poison.h b/include/linux/poison.h
85526index 2110a81..13a11bb 100644
85527--- a/include/linux/poison.h
85528+++ b/include/linux/poison.h
85529@@ -19,8 +19,8 @@
85530 * under normal circumstances, used to verify that nobody uses
85531 * non-initialized list entries.
85532 */
85533-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
85534-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
85535+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
85536+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
85537
85538 /********** include/linux/timer.h **********/
85539 /*
85540diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
85541index d8b187c3..9a9257a 100644
85542--- a/include/linux/power/smartreflex.h
85543+++ b/include/linux/power/smartreflex.h
85544@@ -238,7 +238,7 @@ struct omap_sr_class_data {
85545 int (*notify)(struct omap_sr *sr, u32 status);
85546 u8 notify_flags;
85547 u8 class_type;
85548-};
85549+} __do_const;
85550
85551 /**
85552 * struct omap_sr_nvalue_table - Smartreflex n-target value info
85553diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
85554index 4ea1d37..80f4b33 100644
85555--- a/include/linux/ppp-comp.h
85556+++ b/include/linux/ppp-comp.h
85557@@ -84,7 +84,7 @@ struct compressor {
85558 struct module *owner;
85559 /* Extra skb space needed by the compressor algorithm */
85560 unsigned int comp_extra;
85561-};
85562+} __do_const;
85563
85564 /*
85565 * The return value from decompress routine is the length of the
85566diff --git a/include/linux/preempt.h b/include/linux/preempt.h
85567index de83b4e..c4b997d 100644
85568--- a/include/linux/preempt.h
85569+++ b/include/linux/preempt.h
85570@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
85571 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
85572 #endif
85573
85574+#define raw_preempt_count_add(val) __preempt_count_add(val)
85575+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
85576+
85577 #define __preempt_count_inc() __preempt_count_add(1)
85578 #define __preempt_count_dec() __preempt_count_sub(1)
85579
85580 #define preempt_count_inc() preempt_count_add(1)
85581+#define raw_preempt_count_inc() raw_preempt_count_add(1)
85582 #define preempt_count_dec() preempt_count_sub(1)
85583+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
85584
85585 #ifdef CONFIG_PREEMPT_COUNT
85586
85587@@ -41,6 +46,12 @@ do { \
85588 barrier(); \
85589 } while (0)
85590
85591+#define raw_preempt_disable() \
85592+do { \
85593+ raw_preempt_count_inc(); \
85594+ barrier(); \
85595+} while (0)
85596+
85597 #define sched_preempt_enable_no_resched() \
85598 do { \
85599 barrier(); \
85600@@ -49,6 +60,12 @@ do { \
85601
85602 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
85603
85604+#define raw_preempt_enable_no_resched() \
85605+do { \
85606+ barrier(); \
85607+ raw_preempt_count_dec(); \
85608+} while (0)
85609+
85610 #ifdef CONFIG_PREEMPT
85611 #define preempt_enable() \
85612 do { \
85613@@ -113,8 +130,10 @@ do { \
85614 * region.
85615 */
85616 #define preempt_disable() barrier()
85617+#define raw_preempt_disable() barrier()
85618 #define sched_preempt_enable_no_resched() barrier()
85619 #define preempt_enable_no_resched() barrier()
85620+#define raw_preempt_enable_no_resched() barrier()
85621 #define preempt_enable() barrier()
85622 #define preempt_check_resched() do { } while (0)
85623
85624@@ -128,11 +147,13 @@ do { \
85625 /*
85626 * Modules have no business playing preemption tricks.
85627 */
85628+#ifndef CONFIG_PAX_KERNEXEC
85629 #undef sched_preempt_enable_no_resched
85630 #undef preempt_enable_no_resched
85631 #undef preempt_enable_no_resched_notrace
85632 #undef preempt_check_resched
85633 #endif
85634+#endif
85635
85636 #define preempt_set_need_resched() \
85637 do { \
85638diff --git a/include/linux/printk.h b/include/linux/printk.h
85639index 319ff7e..608849a 100644
85640--- a/include/linux/printk.h
85641+++ b/include/linux/printk.h
85642@@ -121,6 +121,8 @@ static inline __printf(1, 2) __cold
85643 void early_printk(const char *s, ...) { }
85644 #endif
85645
85646+extern int kptr_restrict;
85647+
85648 #ifdef CONFIG_PRINTK
85649 asmlinkage __printf(5, 0)
85650 int vprintk_emit(int facility, int level,
85651@@ -155,7 +157,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
85652
85653 extern int printk_delay_msec;
85654 extern int dmesg_restrict;
85655-extern int kptr_restrict;
85656
85657 extern void wake_up_klogd(void);
85658
85659diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
85660index 9d117f6..d832b31 100644
85661--- a/include/linux/proc_fs.h
85662+++ b/include/linux/proc_fs.h
85663@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
85664 extern struct proc_dir_entry *proc_symlink(const char *,
85665 struct proc_dir_entry *, const char *);
85666 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
85667+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
85668 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
85669 struct proc_dir_entry *, void *);
85670+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
85671+ struct proc_dir_entry *, void *);
85672 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
85673 struct proc_dir_entry *);
85674
85675@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
85676 return proc_create_data(name, mode, parent, proc_fops, NULL);
85677 }
85678
85679+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
85680+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
85681+{
85682+#ifdef CONFIG_GRKERNSEC_PROC_USER
85683+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
85684+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85685+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
85686+#else
85687+ return proc_create_data(name, mode, parent, proc_fops, NULL);
85688+#endif
85689+}
85690+
85691+
85692 extern void proc_set_size(struct proc_dir_entry *, loff_t);
85693 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
85694 extern void *PDE_DATA(const struct inode *);
85695@@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
85696 struct proc_dir_entry *parent,const char *dest) { return NULL;}
85697 static inline struct proc_dir_entry *proc_mkdir(const char *name,
85698 struct proc_dir_entry *parent) {return NULL;}
85699+static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
85700+ struct proc_dir_entry *parent) { return NULL; }
85701 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
85702 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
85703+static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
85704+ umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
85705 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
85706 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
85707 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
85708@@ -77,7 +97,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
85709 static inline struct proc_dir_entry *proc_net_mkdir(
85710 struct net *net, const char *name, struct proc_dir_entry *parent)
85711 {
85712- return proc_mkdir_data(name, 0, parent, net);
85713+ return proc_mkdir_data_restrict(name, 0, parent, net);
85714 }
85715
85716 #endif /* _LINUX_PROC_FS_H */
85717diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
85718index 34a1e10..70f6bde 100644
85719--- a/include/linux/proc_ns.h
85720+++ b/include/linux/proc_ns.h
85721@@ -14,7 +14,7 @@ struct proc_ns_operations {
85722 void (*put)(void *ns);
85723 int (*install)(struct nsproxy *nsproxy, void *ns);
85724 unsigned int (*inum)(void *ns);
85725-};
85726+} __do_const __randomize_layout;
85727
85728 struct proc_ns {
85729 void *ns;
85730diff --git a/include/linux/ptp_classify.h b/include/linux/ptp_classify.h
85731index 7dfed71..1dc420b 100644
85732--- a/include/linux/ptp_classify.h
85733+++ b/include/linux/ptp_classify.h
85734@@ -23,8 +23,15 @@
85735 #ifndef _PTP_CLASSIFY_H_
85736 #define _PTP_CLASSIFY_H_
85737
85738+#include <linux/if_ether.h>
85739+#include <linux/if_vlan.h>
85740 #include <linux/ip.h>
85741-#include <linux/skbuff.h>
85742+#include <linux/filter.h>
85743+#ifdef __KERNEL__
85744+#include <linux/in.h>
85745+#else
85746+#include <netinet/in.h>
85747+#endif
85748
85749 #define PTP_CLASS_NONE 0x00 /* not a PTP event message */
85750 #define PTP_CLASS_V1 0x01 /* protocol version 1 */
85751@@ -37,7 +44,7 @@
85752 #define PTP_CLASS_PMASK 0xf0 /* mask for the packet type field */
85753
85754 #define PTP_CLASS_V1_IPV4 (PTP_CLASS_V1 | PTP_CLASS_IPV4)
85755-#define PTP_CLASS_V1_IPV6 (PTP_CLASS_V1 | PTP_CLASS_IPV6) /* probably DNE */
85756+#define PTP_CLASS_V1_IPV6 (PTP_CLASS_V1 | PTP_CLASS_IPV6) /*probably DNE*/
85757 #define PTP_CLASS_V2_IPV4 (PTP_CLASS_V2 | PTP_CLASS_IPV4)
85758 #define PTP_CLASS_V2_IPV6 (PTP_CLASS_V2 | PTP_CLASS_IPV6)
85759 #define PTP_CLASS_V2_L2 (PTP_CLASS_V2 | PTP_CLASS_L2)
85760@@ -46,34 +53,88 @@
85761 #define PTP_EV_PORT 319
85762 #define PTP_GEN_BIT 0x08 /* indicates general message, if set in message type */
85763
85764+#define OFF_ETYPE 12
85765+#define OFF_IHL 14
85766+#define OFF_FRAG 20
85767+#define OFF_PROTO4 23
85768+#define OFF_NEXT 6
85769+#define OFF_UDP_DST 2
85770+
85771 #define OFF_PTP_SOURCE_UUID 22 /* PTPv1 only */
85772 #define OFF_PTP_SEQUENCE_ID 30
85773 #define OFF_PTP_CONTROL 32 /* PTPv1 only */
85774
85775-/* Below defines should actually be removed at some point in time. */
85776+#define IPV4_HLEN(data) (((struct iphdr *)(data + OFF_IHL))->ihl << 2)
85777+
85778 #define IP6_HLEN 40
85779 #define UDP_HLEN 8
85780-#define OFF_IHL 14
85781+
85782+#define RELOFF_DST4 (ETH_HLEN + OFF_UDP_DST)
85783+#define OFF_DST6 (ETH_HLEN + IP6_HLEN + OFF_UDP_DST)
85784 #define OFF_PTP6 (ETH_HLEN + IP6_HLEN + UDP_HLEN)
85785-#define IPV4_HLEN(data) (((struct iphdr *)(data + OFF_IHL))->ihl << 2)
85786
85787-#if defined(CONFIG_NET_PTP_CLASSIFY)
85788-/**
85789- * ptp_classify_raw - classify a PTP packet
85790- * @skb: buffer
85791- *
85792- * Runs a minimal BPF dissector to classify a network packet to
85793- * determine the PTP class. In case the skb does not contain any
85794- * PTP protocol data, PTP_CLASS_NONE will be returned, otherwise
85795- * PTP_CLASS_V1_IPV{4,6}, PTP_CLASS_V2_IPV{4,6} or
85796- * PTP_CLASS_V2_{L2,VLAN}, depending on the packet content.
85797- */
85798-unsigned int ptp_classify_raw(const struct sk_buff *skb);
85799+#define OP_AND (BPF_ALU | BPF_AND | BPF_K)
85800+#define OP_JEQ (BPF_JMP | BPF_JEQ | BPF_K)
85801+#define OP_JSET (BPF_JMP | BPF_JSET | BPF_K)
85802+#define OP_LDB (BPF_LD | BPF_B | BPF_ABS)
85803+#define OP_LDH (BPF_LD | BPF_H | BPF_ABS)
85804+#define OP_LDHI (BPF_LD | BPF_H | BPF_IND)
85805+#define OP_LDX (BPF_LDX | BPF_B | BPF_MSH)
85806+#define OP_OR (BPF_ALU | BPF_OR | BPF_K)
85807+#define OP_RETA (BPF_RET | BPF_A)
85808+#define OP_RETK (BPF_RET | BPF_K)
85809
85810-void __init ptp_classifier_init(void);
85811-#else
85812-static inline void ptp_classifier_init(void)
85813+static inline int ptp_filter_init(struct sock_filter *f, int len)
85814 {
85815+ if (OP_LDH == f[0].code)
85816+ return sk_chk_filter(f, len);
85817+ else
85818+ return 0;
85819 }
85820+
85821+#define PTP_FILTER \
85822+ {OP_LDH, 0, 0, OFF_ETYPE }, /* */ \
85823+ {OP_JEQ, 0, 12, ETH_P_IP }, /* f goto L20 */ \
85824+ {OP_LDB, 0, 0, OFF_PROTO4 }, /* */ \
85825+ {OP_JEQ, 0, 9, IPPROTO_UDP }, /* f goto L10 */ \
85826+ {OP_LDH, 0, 0, OFF_FRAG }, /* */ \
85827+ {OP_JSET, 7, 0, 0x1fff }, /* t goto L11 */ \
85828+ {OP_LDX, 0, 0, OFF_IHL }, /* */ \
85829+ {OP_LDHI, 0, 0, RELOFF_DST4 }, /* */ \
85830+ {OP_JEQ, 0, 4, PTP_EV_PORT }, /* f goto L12 */ \
85831+ {OP_LDHI, 0, 0, ETH_HLEN + UDP_HLEN }, /* */ \
85832+ {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
85833+ {OP_OR, 0, 0, PTP_CLASS_IPV4 }, /* */ \
85834+ {OP_RETA, 0, 0, 0 }, /* */ \
85835+/*L1x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE }, /* */ \
85836+/*L20*/ {OP_JEQ, 0, 9, ETH_P_IPV6 }, /* f goto L40 */ \
85837+ {OP_LDB, 0, 0, ETH_HLEN + OFF_NEXT }, /* */ \
85838+ {OP_JEQ, 0, 6, IPPROTO_UDP }, /* f goto L30 */ \
85839+ {OP_LDH, 0, 0, OFF_DST6 }, /* */ \
85840+ {OP_JEQ, 0, 4, PTP_EV_PORT }, /* f goto L31 */ \
85841+ {OP_LDH, 0, 0, OFF_PTP6 }, /* */ \
85842+ {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
85843+ {OP_OR, 0, 0, PTP_CLASS_IPV6 }, /* */ \
85844+ {OP_RETA, 0, 0, 0 }, /* */ \
85845+/*L3x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE }, /* */ \
85846+/*L40*/ {OP_JEQ, 0, 9, ETH_P_8021Q }, /* f goto L50 */ \
85847+ {OP_LDH, 0, 0, OFF_ETYPE + 4 }, /* */ \
85848+ {OP_JEQ, 0, 15, ETH_P_1588 }, /* f goto L60 */ \
85849+ {OP_LDB, 0, 0, ETH_HLEN + VLAN_HLEN }, /* */ \
85850+ {OP_AND, 0, 0, PTP_GEN_BIT }, /* */ \
85851+ {OP_JEQ, 0, 12, 0 }, /* f goto L6x */ \
85852+ {OP_LDH, 0, 0, ETH_HLEN + VLAN_HLEN }, /* */ \
85853+ {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
85854+ {OP_OR, 0, 0, PTP_CLASS_VLAN }, /* */ \
85855+ {OP_RETA, 0, 0, 0 }, /* */ \
85856+/*L50*/ {OP_JEQ, 0, 7, ETH_P_1588 }, /* f goto L61 */ \
85857+ {OP_LDB, 0, 0, ETH_HLEN }, /* */ \
85858+ {OP_AND, 0, 0, PTP_GEN_BIT }, /* */ \
85859+ {OP_JEQ, 0, 4, 0 }, /* f goto L6x */ \
85860+ {OP_LDH, 0, 0, ETH_HLEN }, /* */ \
85861+ {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
85862+ {OP_OR, 0, 0, PTP_CLASS_L2 }, /* */ \
85863+ {OP_RETA, 0, 0, 0 }, /* */ \
85864+/*L6x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE },
85865+
85866 #endif
85867-#endif /* _PTP_CLASSIFY_H_ */
85868diff --git a/include/linux/quota.h b/include/linux/quota.h
85869index 0f3c5d3..bc559e3 100644
85870--- a/include/linux/quota.h
85871+++ b/include/linux/quota.h
85872@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
85873
85874 extern bool qid_eq(struct kqid left, struct kqid right);
85875 extern bool qid_lt(struct kqid left, struct kqid right);
85876-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
85877+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
85878 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
85879 extern bool qid_valid(struct kqid qid);
85880
85881diff --git a/include/linux/random.h b/include/linux/random.h
85882index 57fbbff..2170304 100644
85883--- a/include/linux/random.h
85884+++ b/include/linux/random.h
85885@@ -9,9 +9,19 @@
85886 #include <uapi/linux/random.h>
85887
85888 extern void add_device_randomness(const void *, unsigned int);
85889+
85890+static inline void add_latent_entropy(void)
85891+{
85892+
85893+#ifdef LATENT_ENTROPY_PLUGIN
85894+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
85895+#endif
85896+
85897+}
85898+
85899 extern void add_input_randomness(unsigned int type, unsigned int code,
85900- unsigned int value);
85901-extern void add_interrupt_randomness(int irq, int irq_flags);
85902+ unsigned int value) __latent_entropy;
85903+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
85904
85905 extern void get_random_bytes(void *buf, int nbytes);
85906 extern void get_random_bytes_arch(void *buf, int nbytes);
85907@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
85908 extern const struct file_operations random_fops, urandom_fops;
85909 #endif
85910
85911-unsigned int get_random_int(void);
85912+unsigned int __intentional_overflow(-1) get_random_int(void);
85913 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
85914
85915-u32 prandom_u32(void);
85916+u32 prandom_u32(void) __intentional_overflow(-1);
85917 void prandom_bytes(void *buf, int nbytes);
85918 void prandom_seed(u32 seed);
85919 void prandom_reseed_late(void);
85920@@ -37,6 +47,11 @@ struct rnd_state {
85921 u32 prandom_u32_state(struct rnd_state *state);
85922 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
85923
85924+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
85925+{
85926+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
85927+}
85928+
85929 /**
85930 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
85931 * @ep_ro: right open interval endpoint
85932@@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
85933 *
85934 * Returns: pseudo-random number in interval [0, ep_ro)
85935 */
85936-static inline u32 prandom_u32_max(u32 ep_ro)
85937+static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
85938 {
85939 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
85940 }
85941diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
85942index fea49b5..2ac22bb 100644
85943--- a/include/linux/rbtree_augmented.h
85944+++ b/include/linux/rbtree_augmented.h
85945@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
85946 old->rbaugmented = rbcompute(old); \
85947 } \
85948 rbstatic const struct rb_augment_callbacks rbname = { \
85949- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
85950+ .propagate = rbname ## _propagate, \
85951+ .copy = rbname ## _copy, \
85952+ .rotate = rbname ## _rotate \
85953 };
85954
85955
85956diff --git a/include/linux/rculist.h b/include/linux/rculist.h
85957index 8183b46..a388711 100644
85958--- a/include/linux/rculist.h
85959+++ b/include/linux/rculist.h
85960@@ -29,8 +29,8 @@
85961 */
85962 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
85963 {
85964- ACCESS_ONCE(list->next) = list;
85965- ACCESS_ONCE(list->prev) = list;
85966+ ACCESS_ONCE_RW(list->next) = list;
85967+ ACCESS_ONCE_RW(list->prev) = list;
85968 }
85969
85970 /*
85971@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
85972 struct list_head *prev, struct list_head *next);
85973 #endif
85974
85975+void __pax_list_add_rcu(struct list_head *new,
85976+ struct list_head *prev, struct list_head *next);
85977+
85978 /**
85979 * list_add_rcu - add a new entry to rcu-protected list
85980 * @new: new entry to be added
85981@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
85982 __list_add_rcu(new, head, head->next);
85983 }
85984
85985+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
85986+{
85987+ __pax_list_add_rcu(new, head, head->next);
85988+}
85989+
85990 /**
85991 * list_add_tail_rcu - add a new entry to rcu-protected list
85992 * @new: new entry to be added
85993@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
85994 __list_add_rcu(new, head->prev, head);
85995 }
85996
85997+static inline void pax_list_add_tail_rcu(struct list_head *new,
85998+ struct list_head *head)
85999+{
86000+ __pax_list_add_rcu(new, head->prev, head);
86001+}
86002+
86003 /**
86004 * list_del_rcu - deletes entry from list without re-initialization
86005 * @entry: the element to delete from the list.
86006@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
86007 entry->prev = LIST_POISON2;
86008 }
86009
86010+extern void pax_list_del_rcu(struct list_head *entry);
86011+
86012 /**
86013 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
86014 * @n: the element to delete from the hash list.
86015diff --git a/include/linux/reboot.h b/include/linux/reboot.h
86016index 48bf152..d38b785 100644
86017--- a/include/linux/reboot.h
86018+++ b/include/linux/reboot.h
86019@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
86020 */
86021
86022 extern void migrate_to_reboot_cpu(void);
86023-extern void machine_restart(char *cmd);
86024-extern void machine_halt(void);
86025-extern void machine_power_off(void);
86026+extern void machine_restart(char *cmd) __noreturn;
86027+extern void machine_halt(void) __noreturn;
86028+extern void machine_power_off(void) __noreturn;
86029
86030 extern void machine_shutdown(void);
86031 struct pt_regs;
86032@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
86033 */
86034
86035 extern void kernel_restart_prepare(char *cmd);
86036-extern void kernel_restart(char *cmd);
86037-extern void kernel_halt(void);
86038-extern void kernel_power_off(void);
86039+extern void kernel_restart(char *cmd) __noreturn;
86040+extern void kernel_halt(void) __noreturn;
86041+extern void kernel_power_off(void) __noreturn;
86042
86043 extern int C_A_D; /* for sysctl */
86044 void ctrl_alt_del(void);
86045@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
86046 * Emergency restart, callable from an interrupt handler.
86047 */
86048
86049-extern void emergency_restart(void);
86050+extern void emergency_restart(void) __noreturn;
86051 #include <asm/emergency-restart.h>
86052
86053 #endif /* _LINUX_REBOOT_H */
86054diff --git a/include/linux/regset.h b/include/linux/regset.h
86055index 8e0c9fe..ac4d221 100644
86056--- a/include/linux/regset.h
86057+++ b/include/linux/regset.h
86058@@ -161,7 +161,8 @@ struct user_regset {
86059 unsigned int align;
86060 unsigned int bias;
86061 unsigned int core_note_type;
86062-};
86063+} __do_const;
86064+typedef struct user_regset __no_const user_regset_no_const;
86065
86066 /**
86067 * struct user_regset_view - available regsets
86068diff --git a/include/linux/relay.h b/include/linux/relay.h
86069index d7c8359..818daf5 100644
86070--- a/include/linux/relay.h
86071+++ b/include/linux/relay.h
86072@@ -157,7 +157,7 @@ struct rchan_callbacks
86073 * The callback should return 0 if successful, negative if not.
86074 */
86075 int (*remove_buf_file)(struct dentry *dentry);
86076-};
86077+} __no_const;
86078
86079 /*
86080 * CONFIG_RELAY kernel API, kernel/relay.c
86081diff --git a/include/linux/rio.h b/include/linux/rio.h
86082index 6bda06f..bf39a9b 100644
86083--- a/include/linux/rio.h
86084+++ b/include/linux/rio.h
86085@@ -358,7 +358,7 @@ struct rio_ops {
86086 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
86087 u64 rstart, u32 size, u32 flags);
86088 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
86089-};
86090+} __no_const;
86091
86092 #define RIO_RESOURCE_MEM 0x00000100
86093 #define RIO_RESOURCE_DOORBELL 0x00000200
86094diff --git a/include/linux/rmap.h b/include/linux/rmap.h
86095index be57450..31cf65e 100644
86096--- a/include/linux/rmap.h
86097+++ b/include/linux/rmap.h
86098@@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
86099 void anon_vma_init(void); /* create anon_vma_cachep */
86100 int anon_vma_prepare(struct vm_area_struct *);
86101 void unlink_anon_vmas(struct vm_area_struct *);
86102-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
86103-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
86104+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
86105+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
86106
86107 static inline void anon_vma_merge(struct vm_area_struct *vma,
86108 struct vm_area_struct *next)
86109diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
86110index a964f72..b475afb 100644
86111--- a/include/linux/scatterlist.h
86112+++ b/include/linux/scatterlist.h
86113@@ -1,6 +1,7 @@
86114 #ifndef _LINUX_SCATTERLIST_H
86115 #define _LINUX_SCATTERLIST_H
86116
86117+#include <linux/sched.h>
86118 #include <linux/string.h>
86119 #include <linux/bug.h>
86120 #include <linux/mm.h>
86121@@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
86122 #ifdef CONFIG_DEBUG_SG
86123 BUG_ON(!virt_addr_valid(buf));
86124 #endif
86125+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86126+ if (object_starts_on_stack(buf)) {
86127+ void *adjbuf = buf - current->stack + current->lowmem_stack;
86128+ sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
86129+ } else
86130+#endif
86131 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
86132 }
86133
86134diff --git a/include/linux/sched.h b/include/linux/sched.h
86135index 0376b05..82054c2 100644
86136--- a/include/linux/sched.h
86137+++ b/include/linux/sched.h
86138@@ -131,6 +131,7 @@ struct fs_struct;
86139 struct perf_event_context;
86140 struct blk_plug;
86141 struct filename;
86142+struct linux_binprm;
86143
86144 #define VMACACHE_BITS 2
86145 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
86146@@ -374,7 +375,7 @@ extern char __sched_text_start[], __sched_text_end[];
86147 extern int in_sched_functions(unsigned long addr);
86148
86149 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
86150-extern signed long schedule_timeout(signed long timeout);
86151+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
86152 extern signed long schedule_timeout_interruptible(signed long timeout);
86153 extern signed long schedule_timeout_killable(signed long timeout);
86154 extern signed long schedule_timeout_uninterruptible(signed long timeout);
86155@@ -385,6 +386,19 @@ struct nsproxy;
86156 struct user_namespace;
86157
86158 #ifdef CONFIG_MMU
86159+
86160+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
86161+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
86162+#else
86163+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
86164+{
86165+ return 0;
86166+}
86167+#endif
86168+
86169+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
86170+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
86171+
86172 extern void arch_pick_mmap_layout(struct mm_struct *mm);
86173 extern unsigned long
86174 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
86175@@ -682,6 +696,17 @@ struct signal_struct {
86176 #ifdef CONFIG_TASKSTATS
86177 struct taskstats *stats;
86178 #endif
86179+
86180+#ifdef CONFIG_GRKERNSEC
86181+ u32 curr_ip;
86182+ u32 saved_ip;
86183+ u32 gr_saddr;
86184+ u32 gr_daddr;
86185+ u16 gr_sport;
86186+ u16 gr_dport;
86187+ u8 used_accept:1;
86188+#endif
86189+
86190 #ifdef CONFIG_AUDIT
86191 unsigned audit_tty;
86192 unsigned audit_tty_log_passwd;
86193@@ -708,7 +733,7 @@ struct signal_struct {
86194 struct mutex cred_guard_mutex; /* guard against foreign influences on
86195 * credential calculations
86196 * (notably. ptrace) */
86197-};
86198+} __randomize_layout;
86199
86200 /*
86201 * Bits in flags field of signal_struct.
86202@@ -761,6 +786,14 @@ struct user_struct {
86203 struct key *session_keyring; /* UID's default session keyring */
86204 #endif
86205
86206+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
86207+ unsigned char kernel_banned;
86208+#endif
86209+#ifdef CONFIG_GRKERNSEC_BRUTE
86210+ unsigned char suid_banned;
86211+ unsigned long suid_ban_expires;
86212+#endif
86213+
86214 /* Hash table maintenance information */
86215 struct hlist_node uidhash_node;
86216 kuid_t uid;
86217@@ -768,7 +801,7 @@ struct user_struct {
86218 #ifdef CONFIG_PERF_EVENTS
86219 atomic_long_t locked_vm;
86220 #endif
86221-};
86222+} __randomize_layout;
86223
86224 extern int uids_sysfs_init(void);
86225
86226@@ -1224,6 +1257,9 @@ enum perf_event_task_context {
86227 struct task_struct {
86228 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
86229 void *stack;
86230+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86231+ void *lowmem_stack;
86232+#endif
86233 atomic_t usage;
86234 unsigned int flags; /* per process flags, defined below */
86235 unsigned int ptrace;
86236@@ -1349,8 +1385,8 @@ struct task_struct {
86237 struct list_head thread_node;
86238
86239 struct completion *vfork_done; /* for vfork() */
86240- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
86241- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
86242+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
86243+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
86244
86245 cputime_t utime, stime, utimescaled, stimescaled;
86246 cputime_t gtime;
86247@@ -1375,11 +1411,6 @@ struct task_struct {
86248 struct task_cputime cputime_expires;
86249 struct list_head cpu_timers[3];
86250
86251-/* process credentials */
86252- const struct cred __rcu *real_cred; /* objective and real subjective task
86253- * credentials (COW) */
86254- const struct cred __rcu *cred; /* effective (overridable) subjective task
86255- * credentials (COW) */
86256 char comm[TASK_COMM_LEN]; /* executable name excluding path
86257 - access with [gs]et_task_comm (which lock
86258 it with task_lock())
86259@@ -1396,6 +1427,10 @@ struct task_struct {
86260 #endif
86261 /* CPU-specific state of this task */
86262 struct thread_struct thread;
86263+/* thread_info moved to task_struct */
86264+#ifdef CONFIG_X86
86265+ struct thread_info tinfo;
86266+#endif
86267 /* filesystem information */
86268 struct fs_struct *fs;
86269 /* open file information */
86270@@ -1472,6 +1507,10 @@ struct task_struct {
86271 gfp_t lockdep_reclaim_gfp;
86272 #endif
86273
86274+/* process credentials */
86275+ const struct cred __rcu *real_cred; /* objective and real subjective task
86276+ * credentials (COW) */
86277+
86278 /* journalling filesystem info */
86279 void *journal_info;
86280
86281@@ -1510,6 +1549,10 @@ struct task_struct {
86282 /* cg_list protected by css_set_lock and tsk->alloc_lock */
86283 struct list_head cg_list;
86284 #endif
86285+
86286+ const struct cred __rcu *cred; /* effective (overridable) subjective task
86287+ * credentials (COW) */
86288+
86289 #ifdef CONFIG_FUTEX
86290 struct robust_list_head __user *robust_list;
86291 #ifdef CONFIG_COMPAT
86292@@ -1655,7 +1698,78 @@ struct task_struct {
86293 unsigned int sequential_io;
86294 unsigned int sequential_io_avg;
86295 #endif
86296-};
86297+
86298+#ifdef CONFIG_GRKERNSEC
86299+ /* grsecurity */
86300+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
86301+ u64 exec_id;
86302+#endif
86303+#ifdef CONFIG_GRKERNSEC_SETXID
86304+ const struct cred *delayed_cred;
86305+#endif
86306+ struct dentry *gr_chroot_dentry;
86307+ struct acl_subject_label *acl;
86308+ struct acl_subject_label *tmpacl;
86309+ struct acl_role_label *role;
86310+ struct file *exec_file;
86311+ unsigned long brute_expires;
86312+ u16 acl_role_id;
86313+ u8 inherited;
86314+ /* is this the task that authenticated to the special role */
86315+ u8 acl_sp_role;
86316+ u8 is_writable;
86317+ u8 brute;
86318+ u8 gr_is_chrooted;
86319+#endif
86320+
86321+} __randomize_layout;
86322+
86323+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
86324+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
86325+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
86326+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
86327+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
86328+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
86329+
86330+#ifdef CONFIG_PAX_SOFTMODE
86331+extern int pax_softmode;
86332+#endif
86333+
86334+extern int pax_check_flags(unsigned long *);
86335+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
86336+
86337+/* if tsk != current then task_lock must be held on it */
86338+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
86339+static inline unsigned long pax_get_flags(struct task_struct *tsk)
86340+{
86341+ if (likely(tsk->mm))
86342+ return tsk->mm->pax_flags;
86343+ else
86344+ return 0UL;
86345+}
86346+
86347+/* if tsk != current then task_lock must be held on it */
86348+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
86349+{
86350+ if (likely(tsk->mm)) {
86351+ tsk->mm->pax_flags = flags;
86352+ return 0;
86353+ }
86354+ return -EINVAL;
86355+}
86356+#endif
86357+
86358+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
86359+extern void pax_set_initial_flags(struct linux_binprm *bprm);
86360+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
86361+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
86362+#endif
86363+
86364+struct path;
86365+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
86366+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
86367+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
86368+extern void pax_report_refcount_overflow(struct pt_regs *regs);
86369
86370 /* Future-safe accessor for struct task_struct's cpus_allowed. */
86371 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
86372@@ -1737,7 +1851,7 @@ struct pid_namespace;
86373 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
86374 struct pid_namespace *ns);
86375
86376-static inline pid_t task_pid_nr(struct task_struct *tsk)
86377+static inline pid_t task_pid_nr(const struct task_struct *tsk)
86378 {
86379 return tsk->pid;
86380 }
86381@@ -2084,6 +2198,25 @@ extern u64 sched_clock_cpu(int cpu);
86382
86383 extern void sched_clock_init(void);
86384
86385+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86386+static inline void populate_stack(void)
86387+{
86388+ struct task_struct *curtask = current;
86389+ int c;
86390+ int *ptr = curtask->stack;
86391+ int *end = curtask->stack + THREAD_SIZE;
86392+
86393+ while (ptr < end) {
86394+ c = *(volatile int *)ptr;
86395+ ptr += PAGE_SIZE/sizeof(int);
86396+ }
86397+}
86398+#else
86399+static inline void populate_stack(void)
86400+{
86401+}
86402+#endif
86403+
86404 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
86405 static inline void sched_clock_tick(void)
86406 {
86407@@ -2217,7 +2350,9 @@ void yield(void);
86408 extern struct exec_domain default_exec_domain;
86409
86410 union thread_union {
86411+#ifndef CONFIG_X86
86412 struct thread_info thread_info;
86413+#endif
86414 unsigned long stack[THREAD_SIZE/sizeof(long)];
86415 };
86416
86417@@ -2250,6 +2385,7 @@ extern struct pid_namespace init_pid_ns;
86418 */
86419
86420 extern struct task_struct *find_task_by_vpid(pid_t nr);
86421+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
86422 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
86423 struct pid_namespace *ns);
86424
86425@@ -2412,7 +2548,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
86426 extern void exit_itimers(struct signal_struct *);
86427 extern void flush_itimer_signals(void);
86428
86429-extern void do_group_exit(int);
86430+extern __noreturn void do_group_exit(int);
86431
86432 extern int do_execve(struct filename *,
86433 const char __user * const __user *,
86434@@ -2614,9 +2750,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
86435
86436 #endif
86437
86438-static inline int object_is_on_stack(void *obj)
86439+static inline int object_starts_on_stack(const void *obj)
86440 {
86441- void *stack = task_stack_page(current);
86442+ const void *stack = task_stack_page(current);
86443
86444 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
86445 }
86446diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
86447index 596a0e0..bea77ec 100644
86448--- a/include/linux/sched/sysctl.h
86449+++ b/include/linux/sched/sysctl.h
86450@@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
86451 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
86452
86453 extern int sysctl_max_map_count;
86454+extern unsigned long sysctl_heap_stack_gap;
86455
86456 extern unsigned int sysctl_sched_latency;
86457 extern unsigned int sysctl_sched_min_granularity;
86458diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h
86459index 4054b09..6f19cfd 100644
86460--- a/include/linux/seccomp.h
86461+++ b/include/linux/seccomp.h
86462@@ -76,6 +76,7 @@ static inline int seccomp_mode(struct seccomp *s)
86463 #ifdef CONFIG_SECCOMP_FILTER
86464 extern void put_seccomp_filter(struct task_struct *tsk);
86465 extern void get_seccomp_filter(struct task_struct *tsk);
86466+extern u32 seccomp_bpf_load(int off);
86467 #else /* CONFIG_SECCOMP_FILTER */
86468 static inline void put_seccomp_filter(struct task_struct *tsk)
86469 {
86470diff --git a/include/linux/security.h b/include/linux/security.h
86471index 9c6b972..7e7c704 100644
86472--- a/include/linux/security.h
86473+++ b/include/linux/security.h
86474@@ -27,6 +27,7 @@
86475 #include <linux/slab.h>
86476 #include <linux/err.h>
86477 #include <linux/string.h>
86478+#include <linux/grsecurity.h>
86479
86480 struct linux_binprm;
86481 struct cred;
86482@@ -116,8 +117,6 @@ struct seq_file;
86483
86484 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
86485
86486-void reset_security_ops(void);
86487-
86488 #ifdef CONFIG_MMU
86489 extern unsigned long mmap_min_addr;
86490 extern unsigned long dac_mmap_min_addr;
86491@@ -1719,7 +1718,7 @@ struct security_operations {
86492 struct audit_context *actx);
86493 void (*audit_rule_free) (void *lsmrule);
86494 #endif /* CONFIG_AUDIT */
86495-};
86496+} __randomize_layout;
86497
86498 /* prototypes */
86499 extern int security_init(void);
86500diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
86501index dc368b8..e895209 100644
86502--- a/include/linux/semaphore.h
86503+++ b/include/linux/semaphore.h
86504@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
86505 }
86506
86507 extern void down(struct semaphore *sem);
86508-extern int __must_check down_interruptible(struct semaphore *sem);
86509+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
86510 extern int __must_check down_killable(struct semaphore *sem);
86511 extern int __must_check down_trylock(struct semaphore *sem);
86512 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
86513diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
86514index 52e0097..383f21d 100644
86515--- a/include/linux/seq_file.h
86516+++ b/include/linux/seq_file.h
86517@@ -27,6 +27,9 @@ struct seq_file {
86518 struct mutex lock;
86519 const struct seq_operations *op;
86520 int poll_event;
86521+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
86522+ u64 exec_id;
86523+#endif
86524 #ifdef CONFIG_USER_NS
86525 struct user_namespace *user_ns;
86526 #endif
86527@@ -39,6 +42,7 @@ struct seq_operations {
86528 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
86529 int (*show) (struct seq_file *m, void *v);
86530 };
86531+typedef struct seq_operations __no_const seq_operations_no_const;
86532
86533 #define SEQ_SKIP 1
86534
86535@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
86536
86537 char *mangle_path(char *s, const char *p, const char *esc);
86538 int seq_open(struct file *, const struct seq_operations *);
86539+int seq_open_restrict(struct file *, const struct seq_operations *);
86540 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
86541 loff_t seq_lseek(struct file *, loff_t, int);
86542 int seq_release(struct inode *, struct file *);
86543@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
86544 }
86545
86546 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
86547+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
86548 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
86549 int single_release(struct inode *, struct file *);
86550 void *__seq_open_private(struct file *, const struct seq_operations *, int);
86551diff --git a/include/linux/shm.h b/include/linux/shm.h
86552index 57d7770..0936af6 100644
86553--- a/include/linux/shm.h
86554+++ b/include/linux/shm.h
86555@@ -20,6 +20,10 @@ struct shmid_kernel /* private to the kernel */
86556
86557 /* The task created the shm object. NULL if the task is dead. */
86558 struct task_struct *shm_creator;
86559+#ifdef CONFIG_GRKERNSEC
86560+ time_t shm_createtime;
86561+ pid_t shm_lapid;
86562+#endif
86563 };
86564
86565 /* shm_mode upper byte flags */
86566diff --git a/include/linux/signal.h b/include/linux/signal.h
86567index c9e6536..923b302 100644
86568--- a/include/linux/signal.h
86569+++ b/include/linux/signal.h
86570@@ -293,7 +293,7 @@ static inline void allow_signal(int sig)
86571 * know it'll be handled, so that they don't get converted to
86572 * SIGKILL or just silently dropped.
86573 */
86574- kernel_sigaction(sig, (__force __sighandler_t)2);
86575+ kernel_sigaction(sig, (__force_user __sighandler_t)2);
86576 }
86577
86578 static inline void disallow_signal(int sig)
86579diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
86580index ec89301..4fd29a6 100644
86581--- a/include/linux/skbuff.h
86582+++ b/include/linux/skbuff.h
86583@@ -725,7 +725,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
86584 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
86585 int node);
86586 struct sk_buff *build_skb(void *data, unsigned int frag_size);
86587-static inline struct sk_buff *alloc_skb(unsigned int size,
86588+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
86589 gfp_t priority)
86590 {
86591 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
86592@@ -1839,7 +1839,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
86593 return skb->inner_transport_header - skb->inner_network_header;
86594 }
86595
86596-static inline int skb_network_offset(const struct sk_buff *skb)
86597+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
86598 {
86599 return skb_network_header(skb) - skb->data;
86600 }
86601@@ -1911,7 +1911,7 @@ static inline void skb_pop_rcv_encapsulation(struct sk_buff *skb)
86602 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
86603 */
86604 #ifndef NET_SKB_PAD
86605-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
86606+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
86607 #endif
86608
86609 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
86610@@ -2518,7 +2518,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
86611 int *err);
86612 unsigned int datagram_poll(struct file *file, struct socket *sock,
86613 struct poll_table_struct *wait);
86614-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
86615+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
86616 struct iovec *to, int size);
86617 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
86618 struct iovec *iov);
86619@@ -2664,6 +2664,8 @@ static inline ktime_t net_invalid_timestamp(void)
86620 return ktime_set(0, 0);
86621 }
86622
86623+void skb_timestamping_init(void);
86624+
86625 #ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
86626
86627 void skb_clone_tx_timestamp(struct sk_buff *skb);
86628@@ -2907,6 +2909,9 @@ static inline void nf_reset(struct sk_buff *skb)
86629 nf_bridge_put(skb->nf_bridge);
86630 skb->nf_bridge = NULL;
86631 #endif
86632+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
86633+ skb->nf_trace = 0;
86634+#endif
86635 }
86636
86637 static inline void nf_reset_trace(struct sk_buff *skb)
86638diff --git a/include/linux/slab.h b/include/linux/slab.h
86639index 1d9abb7..b1e8b10 100644
86640--- a/include/linux/slab.h
86641+++ b/include/linux/slab.h
86642@@ -14,15 +14,29 @@
86643 #include <linux/gfp.h>
86644 #include <linux/types.h>
86645 #include <linux/workqueue.h>
86646-
86647+#include <linux/err.h>
86648
86649 /*
86650 * Flags to pass to kmem_cache_create().
86651 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
86652 */
86653 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
86654+
86655+#ifdef CONFIG_PAX_USERCOPY_SLABS
86656+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
86657+#else
86658+#define SLAB_USERCOPY 0x00000000UL
86659+#endif
86660+
86661 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
86662 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
86663+
86664+#ifdef CONFIG_PAX_MEMORY_SANITIZE
86665+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
86666+#else
86667+#define SLAB_NO_SANITIZE 0x00000000UL
86668+#endif
86669+
86670 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
86671 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
86672 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
86673@@ -98,10 +112,13 @@
86674 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
86675 * Both make kfree a no-op.
86676 */
86677-#define ZERO_SIZE_PTR ((void *)16)
86678+#define ZERO_SIZE_PTR \
86679+({ \
86680+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
86681+ (void *)(-MAX_ERRNO-1L); \
86682+})
86683
86684-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
86685- (unsigned long)ZERO_SIZE_PTR)
86686+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
86687
86688 #include <linux/kmemleak.h>
86689
86690@@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
86691 void kfree(const void *);
86692 void kzfree(const void *);
86693 size_t ksize(const void *);
86694+const char *check_heap_object(const void *ptr, unsigned long n);
86695+bool is_usercopy_object(const void *ptr);
86696
86697 /*
86698 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
86699@@ -176,7 +195,7 @@ struct kmem_cache {
86700 unsigned int align; /* Alignment as calculated */
86701 unsigned long flags; /* Active flags on the slab */
86702 const char *name; /* Slab name for sysfs */
86703- int refcount; /* Use counter */
86704+ atomic_t refcount; /* Use counter */
86705 void (*ctor)(void *); /* Called on object slot creation */
86706 struct list_head list; /* List of all slab caches on the system */
86707 };
86708@@ -261,6 +280,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
86709 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
86710 #endif
86711
86712+#ifdef CONFIG_PAX_USERCOPY_SLABS
86713+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
86714+#endif
86715+
86716 /*
86717 * Figure out which kmalloc slab an allocation of a certain size
86718 * belongs to.
86719@@ -269,7 +292,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
86720 * 2 = 120 .. 192 bytes
86721 * n = 2^(n-1) .. 2^n -1
86722 */
86723-static __always_inline int kmalloc_index(size_t size)
86724+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
86725 {
86726 if (!size)
86727 return 0;
86728@@ -312,11 +335,11 @@ static __always_inline int kmalloc_index(size_t size)
86729 }
86730 #endif /* !CONFIG_SLOB */
86731
86732-void *__kmalloc(size_t size, gfp_t flags);
86733+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
86734 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
86735
86736 #ifdef CONFIG_NUMA
86737-void *__kmalloc_node(size_t size, gfp_t flags, int node);
86738+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
86739 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
86740 #else
86741 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
86742diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
86743index 8235dfb..47ce586 100644
86744--- a/include/linux/slab_def.h
86745+++ b/include/linux/slab_def.h
86746@@ -38,7 +38,7 @@ struct kmem_cache {
86747 /* 4) cache creation/removal */
86748 const char *name;
86749 struct list_head list;
86750- int refcount;
86751+ atomic_t refcount;
86752 int object_size;
86753 int align;
86754
86755@@ -54,10 +54,14 @@ struct kmem_cache {
86756 unsigned long node_allocs;
86757 unsigned long node_frees;
86758 unsigned long node_overflow;
86759- atomic_t allochit;
86760- atomic_t allocmiss;
86761- atomic_t freehit;
86762- atomic_t freemiss;
86763+ atomic_unchecked_t allochit;
86764+ atomic_unchecked_t allocmiss;
86765+ atomic_unchecked_t freehit;
86766+ atomic_unchecked_t freemiss;
86767+#ifdef CONFIG_PAX_MEMORY_SANITIZE
86768+ atomic_unchecked_t sanitized;
86769+ atomic_unchecked_t not_sanitized;
86770+#endif
86771
86772 /*
86773 * If debugging is enabled, then the allocator can add additional
86774diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
86775index d82abd4..408c3a0 100644
86776--- a/include/linux/slub_def.h
86777+++ b/include/linux/slub_def.h
86778@@ -74,7 +74,7 @@ struct kmem_cache {
86779 struct kmem_cache_order_objects max;
86780 struct kmem_cache_order_objects min;
86781 gfp_t allocflags; /* gfp flags to use on each alloc */
86782- int refcount; /* Refcount for slab cache destroy */
86783+ atomic_t refcount; /* Refcount for slab cache destroy */
86784 void (*ctor)(void *);
86785 int inuse; /* Offset to metadata */
86786 int align; /* Alignment */
86787diff --git a/include/linux/smp.h b/include/linux/smp.h
86788index 34347f2..8739978 100644
86789--- a/include/linux/smp.h
86790+++ b/include/linux/smp.h
86791@@ -174,7 +174,9 @@ static inline void kick_all_cpus_sync(void) { }
86792 #endif
86793
86794 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
86795+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
86796 #define put_cpu() preempt_enable()
86797+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
86798
86799 /*
86800 * Callback to arch code if there's nosmp or maxcpus=0 on the
86801diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
86802index 46cca4c..3323536 100644
86803--- a/include/linux/sock_diag.h
86804+++ b/include/linux/sock_diag.h
86805@@ -11,7 +11,7 @@ struct sock;
86806 struct sock_diag_handler {
86807 __u8 family;
86808 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
86809-};
86810+} __do_const;
86811
86812 int sock_diag_register(const struct sock_diag_handler *h);
86813 void sock_diag_unregister(const struct sock_diag_handler *h);
86814diff --git a/include/linux/sonet.h b/include/linux/sonet.h
86815index 680f9a3..f13aeb0 100644
86816--- a/include/linux/sonet.h
86817+++ b/include/linux/sonet.h
86818@@ -7,7 +7,7 @@
86819 #include <uapi/linux/sonet.h>
86820
86821 struct k_sonet_stats {
86822-#define __HANDLE_ITEM(i) atomic_t i
86823+#define __HANDLE_ITEM(i) atomic_unchecked_t i
86824 __SONET_ITEMS
86825 #undef __HANDLE_ITEM
86826 };
86827diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
86828index 07d8e53..dc934c9 100644
86829--- a/include/linux/sunrpc/addr.h
86830+++ b/include/linux/sunrpc/addr.h
86831@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
86832 {
86833 switch (sap->sa_family) {
86834 case AF_INET:
86835- return ntohs(((struct sockaddr_in *)sap)->sin_port);
86836+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
86837 case AF_INET6:
86838- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
86839+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
86840 }
86841 return 0;
86842 }
86843@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
86844 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
86845 const struct sockaddr *src)
86846 {
86847- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
86848+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
86849 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
86850
86851 dsin->sin_family = ssin->sin_family;
86852@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
86853 if (sa->sa_family != AF_INET6)
86854 return 0;
86855
86856- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
86857+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
86858 }
86859
86860 #endif /* _LINUX_SUNRPC_ADDR_H */
86861diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
86862index 70736b9..37f33db 100644
86863--- a/include/linux/sunrpc/clnt.h
86864+++ b/include/linux/sunrpc/clnt.h
86865@@ -97,7 +97,7 @@ struct rpc_procinfo {
86866 unsigned int p_timer; /* Which RTT timer to use */
86867 u32 p_statidx; /* Which procedure to account */
86868 const char * p_name; /* name of procedure */
86869-};
86870+} __do_const;
86871
86872 #ifdef __KERNEL__
86873
86874diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
86875index 1bc7cd0..7912dc2 100644
86876--- a/include/linux/sunrpc/svc.h
86877+++ b/include/linux/sunrpc/svc.h
86878@@ -417,7 +417,7 @@ struct svc_procedure {
86879 unsigned int pc_count; /* call count */
86880 unsigned int pc_cachetype; /* cache info (NFS) */
86881 unsigned int pc_xdrressize; /* maximum size of XDR reply */
86882-};
86883+} __do_const;
86884
86885 /*
86886 * Function prototypes.
86887diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
86888index 5cf99a0..c0a1b98 100644
86889--- a/include/linux/sunrpc/svc_rdma.h
86890+++ b/include/linux/sunrpc/svc_rdma.h
86891@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
86892 extern unsigned int svcrdma_max_requests;
86893 extern unsigned int svcrdma_max_req_size;
86894
86895-extern atomic_t rdma_stat_recv;
86896-extern atomic_t rdma_stat_read;
86897-extern atomic_t rdma_stat_write;
86898-extern atomic_t rdma_stat_sq_starve;
86899-extern atomic_t rdma_stat_rq_starve;
86900-extern atomic_t rdma_stat_rq_poll;
86901-extern atomic_t rdma_stat_rq_prod;
86902-extern atomic_t rdma_stat_sq_poll;
86903-extern atomic_t rdma_stat_sq_prod;
86904+extern atomic_unchecked_t rdma_stat_recv;
86905+extern atomic_unchecked_t rdma_stat_read;
86906+extern atomic_unchecked_t rdma_stat_write;
86907+extern atomic_unchecked_t rdma_stat_sq_starve;
86908+extern atomic_unchecked_t rdma_stat_rq_starve;
86909+extern atomic_unchecked_t rdma_stat_rq_poll;
86910+extern atomic_unchecked_t rdma_stat_rq_prod;
86911+extern atomic_unchecked_t rdma_stat_sq_poll;
86912+extern atomic_unchecked_t rdma_stat_sq_prod;
86913
86914 #define RPCRDMA_VERSION 1
86915
86916diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
86917index 8d71d65..f79586e 100644
86918--- a/include/linux/sunrpc/svcauth.h
86919+++ b/include/linux/sunrpc/svcauth.h
86920@@ -120,7 +120,7 @@ struct auth_ops {
86921 int (*release)(struct svc_rqst *rq);
86922 void (*domain_release)(struct auth_domain *);
86923 int (*set_client)(struct svc_rqst *rq);
86924-};
86925+} __do_const;
86926
86927 #define SVC_GARBAGE 1
86928 #define SVC_SYSERR 2
86929diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
86930index e7a018e..49f8b17 100644
86931--- a/include/linux/swiotlb.h
86932+++ b/include/linux/swiotlb.h
86933@@ -60,7 +60,8 @@ extern void
86934
86935 extern void
86936 swiotlb_free_coherent(struct device *hwdev, size_t size,
86937- void *vaddr, dma_addr_t dma_handle);
86938+ void *vaddr, dma_addr_t dma_handle,
86939+ struct dma_attrs *attrs);
86940
86941 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
86942 unsigned long offset, size_t size,
86943diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
86944index b0881a0..559a440 100644
86945--- a/include/linux/syscalls.h
86946+++ b/include/linux/syscalls.h
86947@@ -98,10 +98,16 @@ struct sigaltstack;
86948 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
86949
86950 #define __SC_DECL(t, a) t a
86951+#define __TYPE_IS_U(t) (__same_type((t)0, 0UL) || __same_type((t)0, 0U) || __same_type((t)0, (unsigned short)0) || __same_type((t)0, (unsigned char)0))
86952 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
86953 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
86954 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
86955-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
86956+#define __SC_LONG(t, a) __typeof( \
86957+ __builtin_choose_expr( \
86958+ sizeof(t) > sizeof(int), \
86959+ (t) 0, \
86960+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
86961+ )) a
86962 #define __SC_CAST(t, a) (t) a
86963 #define __SC_ARGS(t, a) a
86964 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
86965@@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
86966 asmlinkage long sys_fsync(unsigned int fd);
86967 asmlinkage long sys_fdatasync(unsigned int fd);
86968 asmlinkage long sys_bdflush(int func, long data);
86969-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
86970- char __user *type, unsigned long flags,
86971+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
86972+ const char __user *type, unsigned long flags,
86973 void __user *data);
86974-asmlinkage long sys_umount(char __user *name, int flags);
86975-asmlinkage long sys_oldumount(char __user *name);
86976+asmlinkage long sys_umount(const char __user *name, int flags);
86977+asmlinkage long sys_oldumount(const char __user *name);
86978 asmlinkage long sys_truncate(const char __user *path, long length);
86979 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
86980 asmlinkage long sys_stat(const char __user *filename,
86981@@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
86982 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
86983 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
86984 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
86985- struct sockaddr __user *, int);
86986+ struct sockaddr __user *, int) __intentional_overflow(0);
86987 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
86988 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
86989 unsigned int vlen, unsigned flags);
86990diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
86991index 27b3b0b..e093dd9 100644
86992--- a/include/linux/syscore_ops.h
86993+++ b/include/linux/syscore_ops.h
86994@@ -16,7 +16,7 @@ struct syscore_ops {
86995 int (*suspend)(void);
86996 void (*resume)(void);
86997 void (*shutdown)(void);
86998-};
86999+} __do_const;
87000
87001 extern void register_syscore_ops(struct syscore_ops *ops);
87002 extern void unregister_syscore_ops(struct syscore_ops *ops);
87003diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
87004index 14a8ff2..fa95f3a 100644
87005--- a/include/linux/sysctl.h
87006+++ b/include/linux/sysctl.h
87007@@ -34,13 +34,13 @@ struct ctl_table_root;
87008 struct ctl_table_header;
87009 struct ctl_dir;
87010
87011-typedef struct ctl_table ctl_table;
87012-
87013 typedef int proc_handler (struct ctl_table *ctl, int write,
87014 void __user *buffer, size_t *lenp, loff_t *ppos);
87015
87016 extern int proc_dostring(struct ctl_table *, int,
87017 void __user *, size_t *, loff_t *);
87018+extern int proc_dostring_modpriv(struct ctl_table *, int,
87019+ void __user *, size_t *, loff_t *);
87020 extern int proc_dointvec(struct ctl_table *, int,
87021 void __user *, size_t *, loff_t *);
87022 extern int proc_dointvec_minmax(struct ctl_table *, int,
87023@@ -115,7 +115,9 @@ struct ctl_table
87024 struct ctl_table_poll *poll;
87025 void *extra1;
87026 void *extra2;
87027-};
87028+} __do_const __randomize_layout;
87029+typedef struct ctl_table __no_const ctl_table_no_const;
87030+typedef struct ctl_table ctl_table;
87031
87032 struct ctl_node {
87033 struct rb_node node;
87034diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
87035index f97d0db..c1187dc 100644
87036--- a/include/linux/sysfs.h
87037+++ b/include/linux/sysfs.h
87038@@ -34,7 +34,8 @@ struct attribute {
87039 struct lock_class_key *key;
87040 struct lock_class_key skey;
87041 #endif
87042-};
87043+} __do_const;
87044+typedef struct attribute __no_const attribute_no_const;
87045
87046 /**
87047 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
87048@@ -63,7 +64,8 @@ struct attribute_group {
87049 struct attribute *, int);
87050 struct attribute **attrs;
87051 struct bin_attribute **bin_attrs;
87052-};
87053+} __do_const;
87054+typedef struct attribute_group __no_const attribute_group_no_const;
87055
87056 /**
87057 * Use these macros to make defining attributes easier. See include/linux/device.h
87058@@ -128,7 +130,8 @@ struct bin_attribute {
87059 char *, loff_t, size_t);
87060 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
87061 struct vm_area_struct *vma);
87062-};
87063+} __do_const;
87064+typedef struct bin_attribute __no_const bin_attribute_no_const;
87065
87066 /**
87067 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
87068diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
87069index 387fa7d..3fcde6b 100644
87070--- a/include/linux/sysrq.h
87071+++ b/include/linux/sysrq.h
87072@@ -16,6 +16,7 @@
87073
87074 #include <linux/errno.h>
87075 #include <linux/types.h>
87076+#include <linux/compiler.h>
87077
87078 /* Possible values of bitmask for enabling sysrq functions */
87079 /* 0x0001 is reserved for enable everything */
87080@@ -33,7 +34,7 @@ struct sysrq_key_op {
87081 char *help_msg;
87082 char *action_msg;
87083 int enable_mask;
87084-};
87085+} __do_const;
87086
87087 #ifdef CONFIG_MAGIC_SYSRQ
87088
87089diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
87090index ff307b5..f1a4468 100644
87091--- a/include/linux/thread_info.h
87092+++ b/include/linux/thread_info.h
87093@@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
87094 #error "no set_restore_sigmask() provided and default one won't work"
87095 #endif
87096
87097+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
87098+
87099+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
87100+{
87101+ __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
87102+}
87103+
87104 #endif /* __KERNEL__ */
87105
87106 #endif /* _LINUX_THREAD_INFO_H */
87107diff --git a/include/linux/tty.h b/include/linux/tty.h
87108index 1c3316a..ae83b9f 100644
87109--- a/include/linux/tty.h
87110+++ b/include/linux/tty.h
87111@@ -202,7 +202,7 @@ struct tty_port {
87112 const struct tty_port_operations *ops; /* Port operations */
87113 spinlock_t lock; /* Lock protecting tty field */
87114 int blocked_open; /* Waiting to open */
87115- int count; /* Usage count */
87116+ atomic_t count; /* Usage count */
87117 wait_queue_head_t open_wait; /* Open waiters */
87118 wait_queue_head_t close_wait; /* Close waiters */
87119 wait_queue_head_t delta_msr_wait; /* Modem status change */
87120@@ -284,7 +284,7 @@ struct tty_struct {
87121 /* If the tty has a pending do_SAK, queue it here - akpm */
87122 struct work_struct SAK_work;
87123 struct tty_port *port;
87124-};
87125+} __randomize_layout;
87126
87127 /* Each of a tty's open files has private_data pointing to tty_file_private */
87128 struct tty_file_private {
87129@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
87130 struct tty_struct *tty, struct file *filp);
87131 static inline int tty_port_users(struct tty_port *port)
87132 {
87133- return port->count + port->blocked_open;
87134+ return atomic_read(&port->count) + port->blocked_open;
87135 }
87136
87137 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
87138diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
87139index 756a609..89db85e 100644
87140--- a/include/linux/tty_driver.h
87141+++ b/include/linux/tty_driver.h
87142@@ -285,7 +285,7 @@ struct tty_operations {
87143 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
87144 #endif
87145 const struct file_operations *proc_fops;
87146-};
87147+} __do_const __randomize_layout;
87148
87149 struct tty_driver {
87150 int magic; /* magic number for this structure */
87151@@ -319,7 +319,7 @@ struct tty_driver {
87152
87153 const struct tty_operations *ops;
87154 struct list_head tty_drivers;
87155-};
87156+} __randomize_layout;
87157
87158 extern struct list_head tty_drivers;
87159
87160diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
87161index 00c9d68..bc0188b 100644
87162--- a/include/linux/tty_ldisc.h
87163+++ b/include/linux/tty_ldisc.h
87164@@ -215,7 +215,7 @@ struct tty_ldisc_ops {
87165
87166 struct module *owner;
87167
87168- int refcount;
87169+ atomic_t refcount;
87170 };
87171
87172 struct tty_ldisc {
87173diff --git a/include/linux/types.h b/include/linux/types.h
87174index a0bb704..f511c77 100644
87175--- a/include/linux/types.h
87176+++ b/include/linux/types.h
87177@@ -177,10 +177,26 @@ typedef struct {
87178 int counter;
87179 } atomic_t;
87180
87181+#ifdef CONFIG_PAX_REFCOUNT
87182+typedef struct {
87183+ int counter;
87184+} atomic_unchecked_t;
87185+#else
87186+typedef atomic_t atomic_unchecked_t;
87187+#endif
87188+
87189 #ifdef CONFIG_64BIT
87190 typedef struct {
87191 long counter;
87192 } atomic64_t;
87193+
87194+#ifdef CONFIG_PAX_REFCOUNT
87195+typedef struct {
87196+ long counter;
87197+} atomic64_unchecked_t;
87198+#else
87199+typedef atomic64_t atomic64_unchecked_t;
87200+#endif
87201 #endif
87202
87203 struct list_head {
87204diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
87205index ecd3319..8a36ded 100644
87206--- a/include/linux/uaccess.h
87207+++ b/include/linux/uaccess.h
87208@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
87209 long ret; \
87210 mm_segment_t old_fs = get_fs(); \
87211 \
87212- set_fs(KERNEL_DS); \
87213 pagefault_disable(); \
87214- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
87215- pagefault_enable(); \
87216+ set_fs(KERNEL_DS); \
87217+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
87218 set_fs(old_fs); \
87219+ pagefault_enable(); \
87220 ret; \
87221 })
87222
87223diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
87224index 2d1f9b6..d7a9fce 100644
87225--- a/include/linux/uidgid.h
87226+++ b/include/linux/uidgid.h
87227@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
87228
87229 #endif /* CONFIG_USER_NS */
87230
87231+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
87232+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
87233+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
87234+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
87235+
87236 #endif /* _LINUX_UIDGID_H */
87237diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
87238index 99c1b4d..562e6f3 100644
87239--- a/include/linux/unaligned/access_ok.h
87240+++ b/include/linux/unaligned/access_ok.h
87241@@ -4,34 +4,34 @@
87242 #include <linux/kernel.h>
87243 #include <asm/byteorder.h>
87244
87245-static inline u16 get_unaligned_le16(const void *p)
87246+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
87247 {
87248- return le16_to_cpup((__le16 *)p);
87249+ return le16_to_cpup((const __le16 *)p);
87250 }
87251
87252-static inline u32 get_unaligned_le32(const void *p)
87253+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
87254 {
87255- return le32_to_cpup((__le32 *)p);
87256+ return le32_to_cpup((const __le32 *)p);
87257 }
87258
87259-static inline u64 get_unaligned_le64(const void *p)
87260+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
87261 {
87262- return le64_to_cpup((__le64 *)p);
87263+ return le64_to_cpup((const __le64 *)p);
87264 }
87265
87266-static inline u16 get_unaligned_be16(const void *p)
87267+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
87268 {
87269- return be16_to_cpup((__be16 *)p);
87270+ return be16_to_cpup((const __be16 *)p);
87271 }
87272
87273-static inline u32 get_unaligned_be32(const void *p)
87274+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
87275 {
87276- return be32_to_cpup((__be32 *)p);
87277+ return be32_to_cpup((const __be32 *)p);
87278 }
87279
87280-static inline u64 get_unaligned_be64(const void *p)
87281+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
87282 {
87283- return be64_to_cpup((__be64 *)p);
87284+ return be64_to_cpup((const __be64 *)p);
87285 }
87286
87287 static inline void put_unaligned_le16(u16 val, void *p)
87288diff --git a/include/linux/usb.h b/include/linux/usb.h
87289index d2465bc..5256de4 100644
87290--- a/include/linux/usb.h
87291+++ b/include/linux/usb.h
87292@@ -571,7 +571,7 @@ struct usb_device {
87293 int maxchild;
87294
87295 u32 quirks;
87296- atomic_t urbnum;
87297+ atomic_unchecked_t urbnum;
87298
87299 unsigned long active_duration;
87300
87301@@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
87302
87303 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
87304 __u8 request, __u8 requesttype, __u16 value, __u16 index,
87305- void *data, __u16 size, int timeout);
87306+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
87307 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
87308 void *data, int len, int *actual_length, int timeout);
87309 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
87310diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
87311index e452ba6..78f8e80 100644
87312--- a/include/linux/usb/renesas_usbhs.h
87313+++ b/include/linux/usb/renesas_usbhs.h
87314@@ -39,7 +39,7 @@ enum {
87315 */
87316 struct renesas_usbhs_driver_callback {
87317 int (*notify_hotplug)(struct platform_device *pdev);
87318-};
87319+} __no_const;
87320
87321 /*
87322 * callback functions for platform
87323diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
87324index 4836ba3..603f6ee 100644
87325--- a/include/linux/user_namespace.h
87326+++ b/include/linux/user_namespace.h
87327@@ -33,7 +33,7 @@ struct user_namespace {
87328 struct key *persistent_keyring_register;
87329 struct rw_semaphore persistent_keyring_register_sem;
87330 #endif
87331-};
87332+} __randomize_layout;
87333
87334 extern struct user_namespace init_user_ns;
87335
87336diff --git a/include/linux/utsname.h b/include/linux/utsname.h
87337index 239e277..22a5cf5 100644
87338--- a/include/linux/utsname.h
87339+++ b/include/linux/utsname.h
87340@@ -24,7 +24,7 @@ struct uts_namespace {
87341 struct new_utsname name;
87342 struct user_namespace *user_ns;
87343 unsigned int proc_inum;
87344-};
87345+} __randomize_layout;
87346 extern struct uts_namespace init_uts_ns;
87347
87348 #ifdef CONFIG_UTS_NS
87349diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
87350index 6f8fbcf..4efc177 100644
87351--- a/include/linux/vermagic.h
87352+++ b/include/linux/vermagic.h
87353@@ -25,9 +25,42 @@
87354 #define MODULE_ARCH_VERMAGIC ""
87355 #endif
87356
87357+#ifdef CONFIG_PAX_REFCOUNT
87358+#define MODULE_PAX_REFCOUNT "REFCOUNT "
87359+#else
87360+#define MODULE_PAX_REFCOUNT ""
87361+#endif
87362+
87363+#ifdef CONSTIFY_PLUGIN
87364+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
87365+#else
87366+#define MODULE_CONSTIFY_PLUGIN ""
87367+#endif
87368+
87369+#ifdef STACKLEAK_PLUGIN
87370+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
87371+#else
87372+#define MODULE_STACKLEAK_PLUGIN ""
87373+#endif
87374+
87375+#ifdef RANDSTRUCT_PLUGIN
87376+#include <generated/randomize_layout_hash.h>
87377+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
87378+#else
87379+#define MODULE_RANDSTRUCT_PLUGIN
87380+#endif
87381+
87382+#ifdef CONFIG_GRKERNSEC
87383+#define MODULE_GRSEC "GRSEC "
87384+#else
87385+#define MODULE_GRSEC ""
87386+#endif
87387+
87388 #define VERMAGIC_STRING \
87389 UTS_RELEASE " " \
87390 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
87391 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
87392- MODULE_ARCH_VERMAGIC
87393+ MODULE_ARCH_VERMAGIC \
87394+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
87395+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
87396
87397diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
87398index 502073a..a7de024 100644
87399--- a/include/linux/vga_switcheroo.h
87400+++ b/include/linux/vga_switcheroo.h
87401@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
87402
87403 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
87404
87405-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
87406-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
87407+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
87408+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
87409 #else
87410
87411 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
87412@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
87413
87414 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
87415
87416-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
87417-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
87418+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
87419+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
87420
87421 #endif
87422 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
87423diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
87424index 4b8a891..e9a2863 100644
87425--- a/include/linux/vmalloc.h
87426+++ b/include/linux/vmalloc.h
87427@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
87428 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
87429 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
87430 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
87431+
87432+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
87433+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
87434+#endif
87435+
87436 /* bits [20..32] reserved for arch specific ioremap internals */
87437
87438 /*
87439@@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
87440 unsigned long flags, pgprot_t prot);
87441 extern void vunmap(const void *addr);
87442
87443+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
87444+extern void unmap_process_stacks(struct task_struct *task);
87445+#endif
87446+
87447 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
87448 unsigned long uaddr, void *kaddr,
87449 unsigned long size);
87450@@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
87451
87452 /* for /dev/kmem */
87453 extern long vread(char *buf, char *addr, unsigned long count);
87454-extern long vwrite(char *buf, char *addr, unsigned long count);
87455+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
87456
87457 /*
87458 * Internals. Dont't use..
87459diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
87460index 82e7db7..f8ce3d0 100644
87461--- a/include/linux/vmstat.h
87462+++ b/include/linux/vmstat.h
87463@@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
87464 /*
87465 * Zone based page accounting with per cpu differentials.
87466 */
87467-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
87468+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
87469
87470 static inline void zone_page_state_add(long x, struct zone *zone,
87471 enum zone_stat_item item)
87472 {
87473- atomic_long_add(x, &zone->vm_stat[item]);
87474- atomic_long_add(x, &vm_stat[item]);
87475+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
87476+ atomic_long_add_unchecked(x, &vm_stat[item]);
87477 }
87478
87479-static inline unsigned long global_page_state(enum zone_stat_item item)
87480+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
87481 {
87482- long x = atomic_long_read(&vm_stat[item]);
87483+ long x = atomic_long_read_unchecked(&vm_stat[item]);
87484 #ifdef CONFIG_SMP
87485 if (x < 0)
87486 x = 0;
87487@@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
87488 return x;
87489 }
87490
87491-static inline unsigned long zone_page_state(struct zone *zone,
87492+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
87493 enum zone_stat_item item)
87494 {
87495- long x = atomic_long_read(&zone->vm_stat[item]);
87496+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
87497 #ifdef CONFIG_SMP
87498 if (x < 0)
87499 x = 0;
87500@@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
87501 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
87502 enum zone_stat_item item)
87503 {
87504- long x = atomic_long_read(&zone->vm_stat[item]);
87505+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
87506
87507 #ifdef CONFIG_SMP
87508 int cpu;
87509@@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
87510
87511 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
87512 {
87513- atomic_long_inc(&zone->vm_stat[item]);
87514- atomic_long_inc(&vm_stat[item]);
87515+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
87516+ atomic_long_inc_unchecked(&vm_stat[item]);
87517 }
87518
87519 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
87520 {
87521- atomic_long_dec(&zone->vm_stat[item]);
87522- atomic_long_dec(&vm_stat[item]);
87523+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
87524+ atomic_long_dec_unchecked(&vm_stat[item]);
87525 }
87526
87527 static inline void __inc_zone_page_state(struct page *page,
87528diff --git a/include/linux/xattr.h b/include/linux/xattr.h
87529index 91b0a68..0e9adf6 100644
87530--- a/include/linux/xattr.h
87531+++ b/include/linux/xattr.h
87532@@ -28,7 +28,7 @@ struct xattr_handler {
87533 size_t size, int handler_flags);
87534 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
87535 size_t size, int flags, int handler_flags);
87536-};
87537+} __do_const;
87538
87539 struct xattr {
87540 const char *name;
87541@@ -37,6 +37,9 @@ struct xattr {
87542 };
87543
87544 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
87545+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
87546+ssize_t pax_getxattr(struct dentry *, void *, size_t);
87547+#endif
87548 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
87549 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
87550 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
87551diff --git a/include/linux/zlib.h b/include/linux/zlib.h
87552index 9c5a6b4..09c9438 100644
87553--- a/include/linux/zlib.h
87554+++ b/include/linux/zlib.h
87555@@ -31,6 +31,7 @@
87556 #define _ZLIB_H
87557
87558 #include <linux/zconf.h>
87559+#include <linux/compiler.h>
87560
87561 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
87562 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
87563@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
87564
87565 /* basic functions */
87566
87567-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
87568+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
87569 /*
87570 Returns the number of bytes that needs to be allocated for a per-
87571 stream workspace with the specified parameters. A pointer to this
87572diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
87573index eec6e46..82d5641 100644
87574--- a/include/media/v4l2-dev.h
87575+++ b/include/media/v4l2-dev.h
87576@@ -77,7 +77,7 @@ struct v4l2_file_operations {
87577 int (*mmap) (struct file *, struct vm_area_struct *);
87578 int (*open) (struct file *);
87579 int (*release) (struct file *);
87580-};
87581+} __do_const;
87582
87583 /*
87584 * Newer version of video_device, handled by videodev2.c
87585diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
87586index ffb69da..040393e 100644
87587--- a/include/media/v4l2-device.h
87588+++ b/include/media/v4l2-device.h
87589@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
87590 this function returns 0. If the name ends with a digit (e.g. cx18),
87591 then the name will be set to cx18-0 since cx180 looks really odd. */
87592 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
87593- atomic_t *instance);
87594+ atomic_unchecked_t *instance);
87595
87596 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
87597 Since the parent disappears this ensures that v4l2_dev doesn't have an
87598diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
87599index d9fa68f..45c88d1 100644
87600--- a/include/net/9p/transport.h
87601+++ b/include/net/9p/transport.h
87602@@ -63,7 +63,7 @@ struct p9_trans_module {
87603 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
87604 int (*zc_request)(struct p9_client *, struct p9_req_t *,
87605 char *, char *, int , int, int, int);
87606-};
87607+} __do_const;
87608
87609 void v9fs_register_trans(struct p9_trans_module *m);
87610 void v9fs_unregister_trans(struct p9_trans_module *m);
87611diff --git a/include/net/af_unix.h b/include/net/af_unix.h
87612index a175ba4..196eb82 100644
87613--- a/include/net/af_unix.h
87614+++ b/include/net/af_unix.h
87615@@ -36,7 +36,7 @@ struct unix_skb_parms {
87616 u32 secid; /* Security ID */
87617 #endif
87618 u32 consumed;
87619-};
87620+} __randomize_layout;
87621
87622 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
87623 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
87624diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
87625index 4abdcb2..945c5cc 100644
87626--- a/include/net/bluetooth/l2cap.h
87627+++ b/include/net/bluetooth/l2cap.h
87628@@ -601,7 +601,7 @@ struct l2cap_ops {
87629 long (*get_sndtimeo) (struct l2cap_chan *chan);
87630 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
87631 unsigned long len, int nb);
87632-};
87633+} __do_const;
87634
87635 struct l2cap_conn {
87636 struct hci_conn *hcon;
87637diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
87638index f2ae33d..c457cf0 100644
87639--- a/include/net/caif/cfctrl.h
87640+++ b/include/net/caif/cfctrl.h
87641@@ -52,7 +52,7 @@ struct cfctrl_rsp {
87642 void (*radioset_rsp)(void);
87643 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
87644 struct cflayer *client_layer);
87645-};
87646+} __no_const;
87647
87648 /* Link Setup Parameters for CAIF-Links. */
87649 struct cfctrl_link_param {
87650@@ -101,8 +101,8 @@ struct cfctrl_request_info {
87651 struct cfctrl {
87652 struct cfsrvl serv;
87653 struct cfctrl_rsp res;
87654- atomic_t req_seq_no;
87655- atomic_t rsp_seq_no;
87656+ atomic_unchecked_t req_seq_no;
87657+ atomic_unchecked_t rsp_seq_no;
87658 struct list_head list;
87659 /* Protects from simultaneous access to first_req list */
87660 spinlock_t info_list_lock;
87661diff --git a/include/net/flow.h b/include/net/flow.h
87662index 8109a15..504466d 100644
87663--- a/include/net/flow.h
87664+++ b/include/net/flow.h
87665@@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
87666
87667 void flow_cache_flush(struct net *net);
87668 void flow_cache_flush_deferred(struct net *net);
87669-extern atomic_t flow_cache_genid;
87670+extern atomic_unchecked_t flow_cache_genid;
87671
87672 #endif
87673diff --git a/include/net/genetlink.h b/include/net/genetlink.h
87674index 93695f0..766d71c 100644
87675--- a/include/net/genetlink.h
87676+++ b/include/net/genetlink.h
87677@@ -120,7 +120,7 @@ struct genl_ops {
87678 u8 cmd;
87679 u8 internal_flags;
87680 u8 flags;
87681-};
87682+} __do_const;
87683
87684 int __genl_register_family(struct genl_family *family);
87685
87686diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
87687index 734d9b5..48a9a4b 100644
87688--- a/include/net/gro_cells.h
87689+++ b/include/net/gro_cells.h
87690@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
87691 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
87692
87693 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
87694- atomic_long_inc(&dev->rx_dropped);
87695+ atomic_long_inc_unchecked(&dev->rx_dropped);
87696 kfree_skb(skb);
87697 return;
87698 }
87699diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
87700index 7a43138..bc76865 100644
87701--- a/include/net/inet_connection_sock.h
87702+++ b/include/net/inet_connection_sock.h
87703@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
87704 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
87705 int (*bind_conflict)(const struct sock *sk,
87706 const struct inet_bind_bucket *tb, bool relax);
87707-};
87708+} __do_const;
87709
87710 /** inet_connection_sock - INET connection oriented sock
87711 *
87712diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
87713index 01d590e..f69c61d 100644
87714--- a/include/net/inetpeer.h
87715+++ b/include/net/inetpeer.h
87716@@ -47,7 +47,7 @@ struct inet_peer {
87717 */
87718 union {
87719 struct {
87720- atomic_t rid; /* Frag reception counter */
87721+ atomic_unchecked_t rid; /* Frag reception counter */
87722 };
87723 struct rcu_head rcu;
87724 struct inet_peer *gc_next;
87725diff --git a/include/net/ip.h b/include/net/ip.h
87726index 7596eb2..f7f5fad 100644
87727--- a/include/net/ip.h
87728+++ b/include/net/ip.h
87729@@ -309,7 +309,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
87730 }
87731 }
87732
87733-u32 ip_idents_reserve(u32 hash, int segs);
87734+u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
87735 void __ip_select_ident(struct iphdr *iph, int segs);
87736
87737 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
87738diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
87739index 9922093..a1755d6 100644
87740--- a/include/net/ip_fib.h
87741+++ b/include/net/ip_fib.h
87742@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
87743
87744 #define FIB_RES_SADDR(net, res) \
87745 ((FIB_RES_NH(res).nh_saddr_genid == \
87746- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
87747+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
87748 FIB_RES_NH(res).nh_saddr : \
87749 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
87750 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
87751diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
87752index 624a8a5..b1e2a24 100644
87753--- a/include/net/ip_vs.h
87754+++ b/include/net/ip_vs.h
87755@@ -558,7 +558,7 @@ struct ip_vs_conn {
87756 struct ip_vs_conn *control; /* Master control connection */
87757 atomic_t n_control; /* Number of controlled ones */
87758 struct ip_vs_dest *dest; /* real server */
87759- atomic_t in_pkts; /* incoming packet counter */
87760+ atomic_unchecked_t in_pkts; /* incoming packet counter */
87761
87762 /* packet transmitter for different forwarding methods. If it
87763 mangles the packet, it must return NF_DROP or better NF_STOLEN,
87764@@ -705,7 +705,7 @@ struct ip_vs_dest {
87765 __be16 port; /* port number of the server */
87766 union nf_inet_addr addr; /* IP address of the server */
87767 volatile unsigned int flags; /* dest status flags */
87768- atomic_t conn_flags; /* flags to copy to conn */
87769+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
87770 atomic_t weight; /* server weight */
87771
87772 atomic_t refcnt; /* reference counter */
87773@@ -960,11 +960,11 @@ struct netns_ipvs {
87774 /* ip_vs_lblc */
87775 int sysctl_lblc_expiration;
87776 struct ctl_table_header *lblc_ctl_header;
87777- struct ctl_table *lblc_ctl_table;
87778+ ctl_table_no_const *lblc_ctl_table;
87779 /* ip_vs_lblcr */
87780 int sysctl_lblcr_expiration;
87781 struct ctl_table_header *lblcr_ctl_header;
87782- struct ctl_table *lblcr_ctl_table;
87783+ ctl_table_no_const *lblcr_ctl_table;
87784 /* ip_vs_est */
87785 struct list_head est_list; /* estimator list */
87786 spinlock_t est_lock;
87787diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
87788index 8d4f588..2e37ad2 100644
87789--- a/include/net/irda/ircomm_tty.h
87790+++ b/include/net/irda/ircomm_tty.h
87791@@ -33,6 +33,7 @@
87792 #include <linux/termios.h>
87793 #include <linux/timer.h>
87794 #include <linux/tty.h> /* struct tty_struct */
87795+#include <asm/local.h>
87796
87797 #include <net/irda/irias_object.h>
87798 #include <net/irda/ircomm_core.h>
87799diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
87800index 714cc9a..ea05f3e 100644
87801--- a/include/net/iucv/af_iucv.h
87802+++ b/include/net/iucv/af_iucv.h
87803@@ -149,7 +149,7 @@ struct iucv_skb_cb {
87804 struct iucv_sock_list {
87805 struct hlist_head head;
87806 rwlock_t lock;
87807- atomic_t autobind_name;
87808+ atomic_unchecked_t autobind_name;
87809 };
87810
87811 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
87812diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
87813index f3be818..bf46196 100644
87814--- a/include/net/llc_c_ac.h
87815+++ b/include/net/llc_c_ac.h
87816@@ -87,7 +87,7 @@
87817 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
87818 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
87819
87820-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
87821+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
87822
87823 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
87824 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
87825diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
87826index 3948cf1..83b28c4 100644
87827--- a/include/net/llc_c_ev.h
87828+++ b/include/net/llc_c_ev.h
87829@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
87830 return (struct llc_conn_state_ev *)skb->cb;
87831 }
87832
87833-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
87834-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
87835+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
87836+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
87837
87838 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
87839 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
87840diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
87841index 0e79cfb..f46db31 100644
87842--- a/include/net/llc_c_st.h
87843+++ b/include/net/llc_c_st.h
87844@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
87845 u8 next_state;
87846 llc_conn_ev_qfyr_t *ev_qualifiers;
87847 llc_conn_action_t *ev_actions;
87848-};
87849+} __do_const;
87850
87851 struct llc_conn_state {
87852 u8 current_state;
87853diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
87854index a61b98c..aade1eb 100644
87855--- a/include/net/llc_s_ac.h
87856+++ b/include/net/llc_s_ac.h
87857@@ -23,7 +23,7 @@
87858 #define SAP_ACT_TEST_IND 9
87859
87860 /* All action functions must look like this */
87861-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
87862+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
87863
87864 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
87865 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
87866diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
87867index 567c681..cd73ac02 100644
87868--- a/include/net/llc_s_st.h
87869+++ b/include/net/llc_s_st.h
87870@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
87871 llc_sap_ev_t ev;
87872 u8 next_state;
87873 llc_sap_action_t *ev_actions;
87874-};
87875+} __do_const;
87876
87877 struct llc_sap_state {
87878 u8 curr_state;
87879diff --git a/include/net/mac80211.h b/include/net/mac80211.h
87880index 421b6ec..5a03729 100644
87881--- a/include/net/mac80211.h
87882+++ b/include/net/mac80211.h
87883@@ -4588,7 +4588,7 @@ struct rate_control_ops {
87884 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
87885
87886 u32 (*get_expected_throughput)(void *priv_sta);
87887-};
87888+} __do_const;
87889
87890 static inline int rate_supported(struct ieee80211_sta *sta,
87891 enum ieee80211_band band,
87892diff --git a/include/net/neighbour.h b/include/net/neighbour.h
87893index 47f4254..fd095bc 100644
87894--- a/include/net/neighbour.h
87895+++ b/include/net/neighbour.h
87896@@ -163,7 +163,7 @@ struct neigh_ops {
87897 void (*error_report)(struct neighbour *, struct sk_buff *);
87898 int (*output)(struct neighbour *, struct sk_buff *);
87899 int (*connected_output)(struct neighbour *, struct sk_buff *);
87900-};
87901+} __do_const;
87902
87903 struct pneigh_entry {
87904 struct pneigh_entry *next;
87905@@ -217,7 +217,7 @@ struct neigh_table {
87906 struct neigh_statistics __percpu *stats;
87907 struct neigh_hash_table __rcu *nht;
87908 struct pneigh_entry **phash_buckets;
87909-};
87910+} __randomize_layout;
87911
87912 static inline int neigh_parms_family(struct neigh_parms *p)
87913 {
87914diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
87915index 361d260..903d15f 100644
87916--- a/include/net/net_namespace.h
87917+++ b/include/net/net_namespace.h
87918@@ -129,8 +129,8 @@ struct net {
87919 struct netns_ipvs *ipvs;
87920 #endif
87921 struct sock *diag_nlsk;
87922- atomic_t fnhe_genid;
87923-};
87924+ atomic_unchecked_t fnhe_genid;
87925+} __randomize_layout;
87926
87927 #include <linux/seq_file_net.h>
87928
87929@@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
87930 #define __net_init __init
87931 #define __net_exit __exit_refok
87932 #define __net_initdata __initdata
87933+#ifdef CONSTIFY_PLUGIN
87934 #define __net_initconst __initconst
87935+#else
87936+#define __net_initconst __initdata
87937+#endif
87938 #endif
87939
87940 struct pernet_operations {
87941@@ -296,7 +300,7 @@ struct pernet_operations {
87942 void (*exit_batch)(struct list_head *net_exit_list);
87943 int *id;
87944 size_t size;
87945-};
87946+} __do_const;
87947
87948 /*
87949 * Use these carefully. If you implement a network device and it
87950@@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
87951
87952 static inline int rt_genid_ipv4(struct net *net)
87953 {
87954- return atomic_read(&net->ipv4.rt_genid);
87955+ return atomic_read_unchecked(&net->ipv4.rt_genid);
87956 }
87957
87958 static inline void rt_genid_bump_ipv4(struct net *net)
87959 {
87960- atomic_inc(&net->ipv4.rt_genid);
87961+ atomic_inc_unchecked(&net->ipv4.rt_genid);
87962 }
87963
87964 #if IS_ENABLED(CONFIG_IPV6)
87965 static inline int rt_genid_ipv6(struct net *net)
87966 {
87967- return atomic_read(&net->ipv6.rt_genid);
87968+ return atomic_read_unchecked(&net->ipv6.rt_genid);
87969 }
87970
87971 static inline void rt_genid_bump_ipv6(struct net *net)
87972 {
87973- atomic_inc(&net->ipv6.rt_genid);
87974+ atomic_inc_unchecked(&net->ipv6.rt_genid);
87975 }
87976 #else
87977 static inline int rt_genid_ipv6(struct net *net)
87978@@ -390,12 +394,12 @@ static inline void rt_genid_bump_all(struct net *net)
87979
87980 static inline int fnhe_genid(struct net *net)
87981 {
87982- return atomic_read(&net->fnhe_genid);
87983+ return atomic_read_unchecked(&net->fnhe_genid);
87984 }
87985
87986 static inline void fnhe_genid_bump(struct net *net)
87987 {
87988- atomic_inc(&net->fnhe_genid);
87989+ atomic_inc_unchecked(&net->fnhe_genid);
87990 }
87991
87992 #endif /* __NET_NET_NAMESPACE_H */
87993diff --git a/include/net/netdma.h b/include/net/netdma.h
87994index 8ba8ce2..99b7fff 100644
87995--- a/include/net/netdma.h
87996+++ b/include/net/netdma.h
87997@@ -24,7 +24,7 @@
87998 #include <linux/dmaengine.h>
87999 #include <linux/skbuff.h>
88000
88001-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
88002+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
88003 struct sk_buff *skb, int offset, struct iovec *to,
88004 size_t len, struct dma_pinned_list *pinned_list);
88005
88006diff --git a/include/net/netlink.h b/include/net/netlink.h
88007index 2b47eaa..6d5bcc2 100644
88008--- a/include/net/netlink.h
88009+++ b/include/net/netlink.h
88010@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
88011 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
88012 {
88013 if (mark)
88014- skb_trim(skb, (unsigned char *) mark - skb->data);
88015+ skb_trim(skb, (const unsigned char *) mark - skb->data);
88016 }
88017
88018 /**
88019diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
88020index 773cce3..6a11852 100644
88021--- a/include/net/netns/conntrack.h
88022+++ b/include/net/netns/conntrack.h
88023@@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
88024 struct nf_proto_net {
88025 #ifdef CONFIG_SYSCTL
88026 struct ctl_table_header *ctl_table_header;
88027- struct ctl_table *ctl_table;
88028+ ctl_table_no_const *ctl_table;
88029 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
88030 struct ctl_table_header *ctl_compat_header;
88031- struct ctl_table *ctl_compat_table;
88032+ ctl_table_no_const *ctl_compat_table;
88033 #endif
88034 #endif
88035 unsigned int users;
88036@@ -59,7 +59,7 @@ struct nf_ip_net {
88037 struct nf_icmp_net icmpv6;
88038 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
88039 struct ctl_table_header *ctl_table_header;
88040- struct ctl_table *ctl_table;
88041+ ctl_table_no_const *ctl_table;
88042 #endif
88043 };
88044
88045diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
88046index aec5e12..807233f 100644
88047--- a/include/net/netns/ipv4.h
88048+++ b/include/net/netns/ipv4.h
88049@@ -82,7 +82,7 @@ struct netns_ipv4 {
88050
88051 struct ping_group_range ping_group_range;
88052
88053- atomic_t dev_addr_genid;
88054+ atomic_unchecked_t dev_addr_genid;
88055
88056 #ifdef CONFIG_SYSCTL
88057 unsigned long *sysctl_local_reserved_ports;
88058@@ -96,6 +96,6 @@ struct netns_ipv4 {
88059 struct fib_rules_ops *mr_rules_ops;
88060 #endif
88061 #endif
88062- atomic_t rt_genid;
88063+ atomic_unchecked_t rt_genid;
88064 };
88065 #endif
88066diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
88067index 19d3446..3c87195 100644
88068--- a/include/net/netns/ipv6.h
88069+++ b/include/net/netns/ipv6.h
88070@@ -74,8 +74,8 @@ struct netns_ipv6 {
88071 struct fib_rules_ops *mr6_rules_ops;
88072 #endif
88073 #endif
88074- atomic_t dev_addr_genid;
88075- atomic_t rt_genid;
88076+ atomic_unchecked_t dev_addr_genid;
88077+ atomic_unchecked_t rt_genid;
88078 };
88079
88080 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
88081diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
88082index 3492434..209f58c 100644
88083--- a/include/net/netns/xfrm.h
88084+++ b/include/net/netns/xfrm.h
88085@@ -64,7 +64,7 @@ struct netns_xfrm {
88086
88087 /* flow cache part */
88088 struct flow_cache flow_cache_global;
88089- atomic_t flow_cache_genid;
88090+ atomic_unchecked_t flow_cache_genid;
88091 struct list_head flow_cache_gc_list;
88092 spinlock_t flow_cache_gc_lock;
88093 struct work_struct flow_cache_gc_work;
88094diff --git a/include/net/ping.h b/include/net/ping.h
88095index 026479b..d9b2829 100644
88096--- a/include/net/ping.h
88097+++ b/include/net/ping.h
88098@@ -54,7 +54,7 @@ struct ping_iter_state {
88099
88100 extern struct proto ping_prot;
88101 #if IS_ENABLED(CONFIG_IPV6)
88102-extern struct pingv6_ops pingv6_ops;
88103+extern struct pingv6_ops *pingv6_ops;
88104 #endif
88105
88106 struct pingfakehdr {
88107diff --git a/include/net/protocol.h b/include/net/protocol.h
88108index d6fcc1f..ca277058 100644
88109--- a/include/net/protocol.h
88110+++ b/include/net/protocol.h
88111@@ -49,7 +49,7 @@ struct net_protocol {
88112 * socket lookup?
88113 */
88114 icmp_strict_tag_validation:1;
88115-};
88116+} __do_const;
88117
88118 #if IS_ENABLED(CONFIG_IPV6)
88119 struct inet6_protocol {
88120@@ -62,7 +62,7 @@ struct inet6_protocol {
88121 u8 type, u8 code, int offset,
88122 __be32 info);
88123 unsigned int flags; /* INET6_PROTO_xxx */
88124-};
88125+} __do_const;
88126
88127 #define INET6_PROTO_NOPOLICY 0x1
88128 #define INET6_PROTO_FINAL 0x2
88129diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
88130index 72240e5..8c14bef 100644
88131--- a/include/net/rtnetlink.h
88132+++ b/include/net/rtnetlink.h
88133@@ -93,7 +93,7 @@ struct rtnl_link_ops {
88134 int (*fill_slave_info)(struct sk_buff *skb,
88135 const struct net_device *dev,
88136 const struct net_device *slave_dev);
88137-};
88138+} __do_const;
88139
88140 int __rtnl_link_register(struct rtnl_link_ops *ops);
88141 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
88142diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
88143index 4a5b9a3..ca27d73 100644
88144--- a/include/net/sctp/checksum.h
88145+++ b/include/net/sctp/checksum.h
88146@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
88147 unsigned int offset)
88148 {
88149 struct sctphdr *sh = sctp_hdr(skb);
88150- __le32 ret, old = sh->checksum;
88151- const struct skb_checksum_ops ops = {
88152+ __le32 ret, old = sh->checksum;
88153+ static const struct skb_checksum_ops ops = {
88154 .update = sctp_csum_update,
88155 .combine = sctp_csum_combine,
88156 };
88157diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
88158index 7f4eeb3..37e8fe1 100644
88159--- a/include/net/sctp/sm.h
88160+++ b/include/net/sctp/sm.h
88161@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
88162 typedef struct {
88163 sctp_state_fn_t *fn;
88164 const char *name;
88165-} sctp_sm_table_entry_t;
88166+} __do_const sctp_sm_table_entry_t;
88167
88168 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
88169 * currently in use.
88170@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
88171 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
88172
88173 /* Extern declarations for major data structures. */
88174-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
88175+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
88176
88177
88178 /* Get the size of a DATA chunk payload. */
88179diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
88180index f38588bf..94c1795 100644
88181--- a/include/net/sctp/structs.h
88182+++ b/include/net/sctp/structs.h
88183@@ -507,7 +507,7 @@ struct sctp_pf {
88184 struct sctp_association *asoc);
88185 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
88186 struct sctp_af *af;
88187-};
88188+} __do_const;
88189
88190
88191 /* Structure to track chunk fragments that have been acked, but peer
88192diff --git a/include/net/sock.h b/include/net/sock.h
88193index 1563507..20d5d0e 100644
88194--- a/include/net/sock.h
88195+++ b/include/net/sock.h
88196@@ -349,7 +349,7 @@ struct sock {
88197 unsigned int sk_napi_id;
88198 unsigned int sk_ll_usec;
88199 #endif
88200- atomic_t sk_drops;
88201+ atomic_unchecked_t sk_drops;
88202 int sk_rcvbuf;
88203
88204 struct sk_filter __rcu *sk_filter;
88205@@ -1038,7 +1038,7 @@ struct proto {
88206 void (*destroy_cgroup)(struct mem_cgroup *memcg);
88207 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
88208 #endif
88209-};
88210+} __randomize_layout;
88211
88212 /*
88213 * Bits in struct cg_proto.flags
88214@@ -1225,7 +1225,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
88215 return ret >> PAGE_SHIFT;
88216 }
88217
88218-static inline long
88219+static inline long __intentional_overflow(-1)
88220 sk_memory_allocated(const struct sock *sk)
88221 {
88222 struct proto *prot = sk->sk_prot;
88223@@ -1370,7 +1370,7 @@ struct sock_iocb {
88224 struct scm_cookie *scm;
88225 struct msghdr *msg, async_msg;
88226 struct kiocb *kiocb;
88227-};
88228+} __randomize_layout;
88229
88230 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
88231 {
88232@@ -1623,6 +1623,33 @@ void sk_common_release(struct sock *sk);
88233 /* Initialise core socket variables */
88234 void sock_init_data(struct socket *sock, struct sock *sk);
88235
88236+void sk_filter_release_rcu(struct rcu_head *rcu);
88237+
88238+/**
88239+ * sk_filter_release - release a socket filter
88240+ * @fp: filter to remove
88241+ *
88242+ * Remove a filter from a socket and release its resources.
88243+ */
88244+
88245+static inline void sk_filter_release(struct sk_filter *fp)
88246+{
88247+ if (atomic_dec_and_test(&fp->refcnt))
88248+ call_rcu(&fp->rcu, sk_filter_release_rcu);
88249+}
88250+
88251+static inline void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp)
88252+{
88253+ atomic_sub(sk_filter_size(fp->len), &sk->sk_omem_alloc);
88254+ sk_filter_release(fp);
88255+}
88256+
88257+static inline void sk_filter_charge(struct sock *sk, struct sk_filter *fp)
88258+{
88259+ atomic_inc(&fp->refcnt);
88260+ atomic_add(sk_filter_size(fp->len), &sk->sk_omem_alloc);
88261+}
88262+
88263 /*
88264 * Socket reference counting postulates.
88265 *
88266@@ -1805,7 +1832,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
88267 }
88268
88269 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
88270- char __user *from, char *to,
88271+ char __user *from, unsigned char *to,
88272 int copy, int offset)
88273 {
88274 if (skb->ip_summed == CHECKSUM_NONE) {
88275@@ -2067,7 +2094,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
88276 }
88277 }
88278
88279-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
88280+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
88281
88282 /**
88283 * sk_page_frag - return an appropriate page_frag
88284diff --git a/include/net/tcp.h b/include/net/tcp.h
88285index 7286db8..f1aa7dc 100644
88286--- a/include/net/tcp.h
88287+++ b/include/net/tcp.h
88288@@ -535,7 +535,7 @@ void tcp_retransmit_timer(struct sock *sk);
88289 void tcp_xmit_retransmit_queue(struct sock *);
88290 void tcp_simple_retransmit(struct sock *);
88291 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
88292-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
88293+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
88294
88295 void tcp_send_probe0(struct sock *);
88296 void tcp_send_partial(struct sock *);
88297@@ -708,8 +708,8 @@ struct tcp_skb_cb {
88298 struct inet6_skb_parm h6;
88299 #endif
88300 } header; /* For incoming frames */
88301- __u32 seq; /* Starting sequence number */
88302- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
88303+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
88304+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
88305 __u32 when; /* used to compute rtt's */
88306 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
88307
88308@@ -723,7 +723,7 @@ struct tcp_skb_cb {
88309
88310 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
88311 /* 1 byte hole */
88312- __u32 ack_seq; /* Sequence number ACK'd */
88313+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
88314 };
88315
88316 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
88317diff --git a/include/net/xfrm.h b/include/net/xfrm.h
88318index 721e9c3b..3c81bbf 100644
88319--- a/include/net/xfrm.h
88320+++ b/include/net/xfrm.h
88321@@ -285,7 +285,6 @@ struct xfrm_dst;
88322 struct xfrm_policy_afinfo {
88323 unsigned short family;
88324 struct dst_ops *dst_ops;
88325- void (*garbage_collect)(struct net *net);
88326 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
88327 const xfrm_address_t *saddr,
88328 const xfrm_address_t *daddr);
88329@@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
88330 struct net_device *dev,
88331 const struct flowi *fl);
88332 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
88333-};
88334+} __do_const;
88335
88336 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
88337 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
88338@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
88339 int (*transport_finish)(struct sk_buff *skb,
88340 int async);
88341 void (*local_error)(struct sk_buff *skb, u32 mtu);
88342-};
88343+} __do_const;
88344
88345 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
88346 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
88347@@ -437,7 +436,7 @@ struct xfrm_mode {
88348 struct module *owner;
88349 unsigned int encap;
88350 int flags;
88351-};
88352+} __do_const;
88353
88354 /* Flags for xfrm_mode. */
88355 enum {
88356@@ -534,7 +533,7 @@ struct xfrm_policy {
88357 struct timer_list timer;
88358
88359 struct flow_cache_object flo;
88360- atomic_t genid;
88361+ atomic_unchecked_t genid;
88362 u32 priority;
88363 u32 index;
88364 struct xfrm_mark mark;
88365@@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
88366 }
88367
88368 void xfrm_garbage_collect(struct net *net);
88369+void xfrm_garbage_collect_deferred(struct net *net);
88370
88371 #else
88372
88373@@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
88374 static inline void xfrm_garbage_collect(struct net *net)
88375 {
88376 }
88377+static inline void xfrm_garbage_collect_deferred(struct net *net)
88378+{
88379+}
88380 #endif
88381
88382 static __inline__
88383diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
88384index 1017e0b..227aa4d 100644
88385--- a/include/rdma/iw_cm.h
88386+++ b/include/rdma/iw_cm.h
88387@@ -122,7 +122,7 @@ struct iw_cm_verbs {
88388 int backlog);
88389
88390 int (*destroy_listen)(struct iw_cm_id *cm_id);
88391-};
88392+} __no_const;
88393
88394 /**
88395 * iw_create_cm_id - Create an IW CM identifier.
88396diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
88397index 52beadf..598734c 100644
88398--- a/include/scsi/libfc.h
88399+++ b/include/scsi/libfc.h
88400@@ -771,6 +771,7 @@ struct libfc_function_template {
88401 */
88402 void (*disc_stop_final) (struct fc_lport *);
88403 };
88404+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
88405
88406 /**
88407 * struct fc_disc - Discovery context
88408@@ -875,7 +876,7 @@ struct fc_lport {
88409 struct fc_vport *vport;
88410
88411 /* Operational Information */
88412- struct libfc_function_template tt;
88413+ libfc_function_template_no_const tt;
88414 u8 link_up;
88415 u8 qfull;
88416 enum fc_lport_state state;
88417diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
88418index 27ab310..60dc245 100644
88419--- a/include/scsi/scsi_device.h
88420+++ b/include/scsi/scsi_device.h
88421@@ -187,9 +187,9 @@ struct scsi_device {
88422 unsigned int max_device_blocked; /* what device_blocked counts down from */
88423 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
88424
88425- atomic_t iorequest_cnt;
88426- atomic_t iodone_cnt;
88427- atomic_t ioerr_cnt;
88428+ atomic_unchecked_t iorequest_cnt;
88429+ atomic_unchecked_t iodone_cnt;
88430+ atomic_unchecked_t ioerr_cnt;
88431
88432 struct device sdev_gendev,
88433 sdev_dev;
88434diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
88435index 8c79980..723f6f9 100644
88436--- a/include/scsi/scsi_transport_fc.h
88437+++ b/include/scsi/scsi_transport_fc.h
88438@@ -752,7 +752,8 @@ struct fc_function_template {
88439 unsigned long show_host_system_hostname:1;
88440
88441 unsigned long disable_target_scan:1;
88442-};
88443+} __do_const;
88444+typedef struct fc_function_template __no_const fc_function_template_no_const;
88445
88446
88447 /**
88448diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
88449index ae6c3b8..fd748ac 100644
88450--- a/include/sound/compress_driver.h
88451+++ b/include/sound/compress_driver.h
88452@@ -128,7 +128,7 @@ struct snd_compr_ops {
88453 struct snd_compr_caps *caps);
88454 int (*get_codec_caps) (struct snd_compr_stream *stream,
88455 struct snd_compr_codec_caps *codec);
88456-};
88457+} __no_const;
88458
88459 /**
88460 * struct snd_compr: Compressed device
88461diff --git a/include/sound/soc.h b/include/sound/soc.h
88462index ed9e2d7..aad0887 100644
88463--- a/include/sound/soc.h
88464+++ b/include/sound/soc.h
88465@@ -798,7 +798,7 @@ struct snd_soc_codec_driver {
88466 /* probe ordering - for components with runtime dependencies */
88467 int probe_order;
88468 int remove_order;
88469-};
88470+} __do_const;
88471
88472 /* SoC platform interface */
88473 struct snd_soc_platform_driver {
88474@@ -845,7 +845,7 @@ struct snd_soc_platform_driver {
88475 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
88476 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
88477 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
88478-};
88479+} __do_const;
88480
88481 struct snd_soc_platform {
88482 const char *name;
88483diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
88484index 9ec9864..e2ee1ee 100644
88485--- a/include/target/target_core_base.h
88486+++ b/include/target/target_core_base.h
88487@@ -761,7 +761,7 @@ struct se_device {
88488 atomic_long_t write_bytes;
88489 /* Active commands on this virtual SE device */
88490 atomic_t simple_cmds;
88491- atomic_t dev_ordered_id;
88492+ atomic_unchecked_t dev_ordered_id;
88493 atomic_t dev_ordered_sync;
88494 atomic_t dev_qf_count;
88495 int export_count;
88496diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
88497new file mode 100644
88498index 0000000..fb634b7
88499--- /dev/null
88500+++ b/include/trace/events/fs.h
88501@@ -0,0 +1,53 @@
88502+#undef TRACE_SYSTEM
88503+#define TRACE_SYSTEM fs
88504+
88505+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
88506+#define _TRACE_FS_H
88507+
88508+#include <linux/fs.h>
88509+#include <linux/tracepoint.h>
88510+
88511+TRACE_EVENT(do_sys_open,
88512+
88513+ TP_PROTO(const char *filename, int flags, int mode),
88514+
88515+ TP_ARGS(filename, flags, mode),
88516+
88517+ TP_STRUCT__entry(
88518+ __string( filename, filename )
88519+ __field( int, flags )
88520+ __field( int, mode )
88521+ ),
88522+
88523+ TP_fast_assign(
88524+ __assign_str(filename, filename);
88525+ __entry->flags = flags;
88526+ __entry->mode = mode;
88527+ ),
88528+
88529+ TP_printk("\"%s\" %x %o",
88530+ __get_str(filename), __entry->flags, __entry->mode)
88531+);
88532+
88533+TRACE_EVENT(open_exec,
88534+
88535+ TP_PROTO(const char *filename),
88536+
88537+ TP_ARGS(filename),
88538+
88539+ TP_STRUCT__entry(
88540+ __string( filename, filename )
88541+ ),
88542+
88543+ TP_fast_assign(
88544+ __assign_str(filename, filename);
88545+ ),
88546+
88547+ TP_printk("\"%s\"",
88548+ __get_str(filename))
88549+);
88550+
88551+#endif /* _TRACE_FS_H */
88552+
88553+/* This part must be outside protection */
88554+#include <trace/define_trace.h>
88555diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
88556index 1c09820..7f5ec79 100644
88557--- a/include/trace/events/irq.h
88558+++ b/include/trace/events/irq.h
88559@@ -36,7 +36,7 @@ struct softirq_action;
88560 */
88561 TRACE_EVENT(irq_handler_entry,
88562
88563- TP_PROTO(int irq, struct irqaction *action),
88564+ TP_PROTO(int irq, const struct irqaction *action),
88565
88566 TP_ARGS(irq, action),
88567
88568@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
88569 */
88570 TRACE_EVENT(irq_handler_exit,
88571
88572- TP_PROTO(int irq, struct irqaction *action, int ret),
88573+ TP_PROTO(int irq, const struct irqaction *action, int ret),
88574
88575 TP_ARGS(irq, action, ret),
88576
88577diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
88578index 7caf44c..23c6f27 100644
88579--- a/include/uapi/linux/a.out.h
88580+++ b/include/uapi/linux/a.out.h
88581@@ -39,6 +39,14 @@ enum machine_type {
88582 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
88583 };
88584
88585+/* Constants for the N_FLAGS field */
88586+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
88587+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
88588+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
88589+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
88590+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
88591+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
88592+
88593 #if !defined (N_MAGIC)
88594 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
88595 #endif
88596diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
88597index 22b6ad3..aeba37e 100644
88598--- a/include/uapi/linux/bcache.h
88599+++ b/include/uapi/linux/bcache.h
88600@@ -5,6 +5,7 @@
88601 * Bcache on disk data structures
88602 */
88603
88604+#include <linux/compiler.h>
88605 #include <asm/types.h>
88606
88607 #define BITMASK(name, type, field, offset, size) \
88608@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
88609 /* Btree keys - all units are in sectors */
88610
88611 struct bkey {
88612- __u64 high;
88613- __u64 low;
88614+ __u64 high __intentional_overflow(-1);
88615+ __u64 low __intentional_overflow(-1);
88616 __u64 ptr[];
88617 };
88618
88619diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
88620index d876736..ccce5c0 100644
88621--- a/include/uapi/linux/byteorder/little_endian.h
88622+++ b/include/uapi/linux/byteorder/little_endian.h
88623@@ -42,51 +42,51 @@
88624
88625 static inline __le64 __cpu_to_le64p(const __u64 *p)
88626 {
88627- return (__force __le64)*p;
88628+ return (__force const __le64)*p;
88629 }
88630-static inline __u64 __le64_to_cpup(const __le64 *p)
88631+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
88632 {
88633- return (__force __u64)*p;
88634+ return (__force const __u64)*p;
88635 }
88636 static inline __le32 __cpu_to_le32p(const __u32 *p)
88637 {
88638- return (__force __le32)*p;
88639+ return (__force const __le32)*p;
88640 }
88641 static inline __u32 __le32_to_cpup(const __le32 *p)
88642 {
88643- return (__force __u32)*p;
88644+ return (__force const __u32)*p;
88645 }
88646 static inline __le16 __cpu_to_le16p(const __u16 *p)
88647 {
88648- return (__force __le16)*p;
88649+ return (__force const __le16)*p;
88650 }
88651 static inline __u16 __le16_to_cpup(const __le16 *p)
88652 {
88653- return (__force __u16)*p;
88654+ return (__force const __u16)*p;
88655 }
88656 static inline __be64 __cpu_to_be64p(const __u64 *p)
88657 {
88658- return (__force __be64)__swab64p(p);
88659+ return (__force const __be64)__swab64p(p);
88660 }
88661 static inline __u64 __be64_to_cpup(const __be64 *p)
88662 {
88663- return __swab64p((__u64 *)p);
88664+ return __swab64p((const __u64 *)p);
88665 }
88666 static inline __be32 __cpu_to_be32p(const __u32 *p)
88667 {
88668- return (__force __be32)__swab32p(p);
88669+ return (__force const __be32)__swab32p(p);
88670 }
88671-static inline __u32 __be32_to_cpup(const __be32 *p)
88672+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
88673 {
88674- return __swab32p((__u32 *)p);
88675+ return __swab32p((const __u32 *)p);
88676 }
88677 static inline __be16 __cpu_to_be16p(const __u16 *p)
88678 {
88679- return (__force __be16)__swab16p(p);
88680+ return (__force const __be16)__swab16p(p);
88681 }
88682 static inline __u16 __be16_to_cpup(const __be16 *p)
88683 {
88684- return __swab16p((__u16 *)p);
88685+ return __swab16p((const __u16 *)p);
88686 }
88687 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
88688 #define __le64_to_cpus(x) do { (void)(x); } while (0)
88689diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
88690index ef6103b..d4e65dd 100644
88691--- a/include/uapi/linux/elf.h
88692+++ b/include/uapi/linux/elf.h
88693@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
88694 #define PT_GNU_EH_FRAME 0x6474e550
88695
88696 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
88697+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
88698+
88699+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
88700+
88701+/* Constants for the e_flags field */
88702+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
88703+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
88704+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
88705+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
88706+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
88707+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
88708
88709 /*
88710 * Extended Numbering
88711@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
88712 #define DT_DEBUG 21
88713 #define DT_TEXTREL 22
88714 #define DT_JMPREL 23
88715+#define DT_FLAGS 30
88716+ #define DF_TEXTREL 0x00000004
88717 #define DT_ENCODING 32
88718 #define OLD_DT_LOOS 0x60000000
88719 #define DT_LOOS 0x6000000d
88720@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
88721 #define PF_W 0x2
88722 #define PF_X 0x1
88723
88724+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
88725+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
88726+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
88727+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
88728+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
88729+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
88730+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
88731+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
88732+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
88733+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
88734+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
88735+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
88736+
88737 typedef struct elf32_phdr{
88738 Elf32_Word p_type;
88739 Elf32_Off p_offset;
88740@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
88741 #define EI_OSABI 7
88742 #define EI_PAD 8
88743
88744+#define EI_PAX 14
88745+
88746 #define ELFMAG0 0x7f /* EI_MAG */
88747 #define ELFMAG1 'E'
88748 #define ELFMAG2 'L'
88749diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
88750index aa169c4..6a2771d 100644
88751--- a/include/uapi/linux/personality.h
88752+++ b/include/uapi/linux/personality.h
88753@@ -30,6 +30,7 @@ enum {
88754 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
88755 ADDR_NO_RANDOMIZE | \
88756 ADDR_COMPAT_LAYOUT | \
88757+ ADDR_LIMIT_3GB | \
88758 MMAP_PAGE_ZERO)
88759
88760 /*
88761diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
88762index 7530e74..e714828 100644
88763--- a/include/uapi/linux/screen_info.h
88764+++ b/include/uapi/linux/screen_info.h
88765@@ -43,7 +43,8 @@ struct screen_info {
88766 __u16 pages; /* 0x32 */
88767 __u16 vesa_attributes; /* 0x34 */
88768 __u32 capabilities; /* 0x36 */
88769- __u8 _reserved[6]; /* 0x3a */
88770+ __u16 vesapm_size; /* 0x3a */
88771+ __u8 _reserved[4]; /* 0x3c */
88772 } __attribute__((packed));
88773
88774 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
88775diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
88776index 0e011eb..82681b1 100644
88777--- a/include/uapi/linux/swab.h
88778+++ b/include/uapi/linux/swab.h
88779@@ -43,7 +43,7 @@
88780 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
88781 */
88782
88783-static inline __attribute_const__ __u16 __fswab16(__u16 val)
88784+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
88785 {
88786 #ifdef __HAVE_BUILTIN_BSWAP16__
88787 return __builtin_bswap16(val);
88788@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
88789 #endif
88790 }
88791
88792-static inline __attribute_const__ __u32 __fswab32(__u32 val)
88793+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
88794 {
88795 #ifdef __HAVE_BUILTIN_BSWAP32__
88796 return __builtin_bswap32(val);
88797@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
88798 #endif
88799 }
88800
88801-static inline __attribute_const__ __u64 __fswab64(__u64 val)
88802+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
88803 {
88804 #ifdef __HAVE_BUILTIN_BSWAP64__
88805 return __builtin_bswap64(val);
88806diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
88807index 6d67213..552fdd9 100644
88808--- a/include/uapi/linux/sysctl.h
88809+++ b/include/uapi/linux/sysctl.h
88810@@ -155,8 +155,6 @@ enum
88811 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
88812 };
88813
88814-
88815-
88816 /* CTL_VM names: */
88817 enum
88818 {
88819diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
88820index 168ff50..a921df2 100644
88821--- a/include/uapi/linux/videodev2.h
88822+++ b/include/uapi/linux/videodev2.h
88823@@ -1253,7 +1253,7 @@ struct v4l2_ext_control {
88824 union {
88825 __s32 value;
88826 __s64 value64;
88827- char *string;
88828+ char __user *string;
88829 };
88830 } __attribute__ ((packed));
88831
88832diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
88833index c38355c..17a57bc 100644
88834--- a/include/uapi/linux/xattr.h
88835+++ b/include/uapi/linux/xattr.h
88836@@ -73,5 +73,9 @@
88837 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
88838 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
88839
88840+/* User namespace */
88841+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
88842+#define XATTR_PAX_FLAGS_SUFFIX "flags"
88843+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
88844
88845 #endif /* _UAPI_LINUX_XATTR_H */
88846diff --git a/include/video/udlfb.h b/include/video/udlfb.h
88847index f9466fa..f4e2b81 100644
88848--- a/include/video/udlfb.h
88849+++ b/include/video/udlfb.h
88850@@ -53,10 +53,10 @@ struct dlfb_data {
88851 u32 pseudo_palette[256];
88852 int blank_mode; /*one of FB_BLANK_ */
88853 /* blit-only rendering path metrics, exposed through sysfs */
88854- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
88855- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
88856- atomic_t bytes_sent; /* to usb, after compression including overhead */
88857- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
88858+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
88859+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
88860+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
88861+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
88862 };
88863
88864 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
88865diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
88866index 30f5362..8ed8ac9 100644
88867--- a/include/video/uvesafb.h
88868+++ b/include/video/uvesafb.h
88869@@ -122,6 +122,7 @@ struct uvesafb_par {
88870 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
88871 u8 pmi_setpal; /* PMI for palette changes */
88872 u16 *pmi_base; /* protected mode interface location */
88873+ u8 *pmi_code; /* protected mode code location */
88874 void *pmi_start;
88875 void *pmi_pal;
88876 u8 *vbe_state_orig; /*
88877diff --git a/init/Kconfig b/init/Kconfig
88878index 9d76b99..d378b1e 100644
88879--- a/init/Kconfig
88880+++ b/init/Kconfig
88881@@ -1105,6 +1105,7 @@ endif # CGROUPS
88882
88883 config CHECKPOINT_RESTORE
88884 bool "Checkpoint/restore support" if EXPERT
88885+ depends on !GRKERNSEC
88886 default n
88887 help
88888 Enables additional kernel features in a sake of checkpoint/restore.
88889@@ -1589,7 +1590,7 @@ config SLUB_DEBUG
88890
88891 config COMPAT_BRK
88892 bool "Disable heap randomization"
88893- default y
88894+ default n
88895 help
88896 Randomizing heap placement makes heap exploits harder, but it
88897 also breaks ancient binaries (including anything libc5 based).
88898@@ -1877,7 +1878,7 @@ config INIT_ALL_POSSIBLE
88899 config STOP_MACHINE
88900 bool
88901 default y
88902- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
88903+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
88904 help
88905 Need stop_machine() primitive.
88906
88907diff --git a/init/Makefile b/init/Makefile
88908index 7bc47ee..6da2dc7 100644
88909--- a/init/Makefile
88910+++ b/init/Makefile
88911@@ -2,6 +2,9 @@
88912 # Makefile for the linux kernel.
88913 #
88914
88915+ccflags-y := $(GCC_PLUGINS_CFLAGS)
88916+asflags-y := $(GCC_PLUGINS_AFLAGS)
88917+
88918 obj-y := main.o version.o mounts.o
88919 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
88920 obj-y += noinitramfs.o
88921diff --git a/init/do_mounts.c b/init/do_mounts.c
88922index 82f2288..ea1430a 100644
88923--- a/init/do_mounts.c
88924+++ b/init/do_mounts.c
88925@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
88926 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
88927 {
88928 struct super_block *s;
88929- int err = sys_mount(name, "/root", fs, flags, data);
88930+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
88931 if (err)
88932 return err;
88933
88934- sys_chdir("/root");
88935+ sys_chdir((const char __force_user *)"/root");
88936 s = current->fs->pwd.dentry->d_sb;
88937 ROOT_DEV = s->s_dev;
88938 printk(KERN_INFO
88939@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
88940 va_start(args, fmt);
88941 vsprintf(buf, fmt, args);
88942 va_end(args);
88943- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
88944+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
88945 if (fd >= 0) {
88946 sys_ioctl(fd, FDEJECT, 0);
88947 sys_close(fd);
88948 }
88949 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
88950- fd = sys_open("/dev/console", O_RDWR, 0);
88951+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
88952 if (fd >= 0) {
88953 sys_ioctl(fd, TCGETS, (long)&termios);
88954 termios.c_lflag &= ~ICANON;
88955 sys_ioctl(fd, TCSETSF, (long)&termios);
88956- sys_read(fd, &c, 1);
88957+ sys_read(fd, (char __user *)&c, 1);
88958 termios.c_lflag |= ICANON;
88959 sys_ioctl(fd, TCSETSF, (long)&termios);
88960 sys_close(fd);
88961@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
88962 mount_root();
88963 out:
88964 devtmpfs_mount("dev");
88965- sys_mount(".", "/", NULL, MS_MOVE, NULL);
88966- sys_chroot(".");
88967+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
88968+ sys_chroot((const char __force_user *)".");
88969 }
88970
88971 static bool is_tmpfs;
88972diff --git a/init/do_mounts.h b/init/do_mounts.h
88973index f5b978a..69dbfe8 100644
88974--- a/init/do_mounts.h
88975+++ b/init/do_mounts.h
88976@@ -15,15 +15,15 @@ extern int root_mountflags;
88977
88978 static inline int create_dev(char *name, dev_t dev)
88979 {
88980- sys_unlink(name);
88981- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
88982+ sys_unlink((char __force_user *)name);
88983+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
88984 }
88985
88986 #if BITS_PER_LONG == 32
88987 static inline u32 bstat(char *name)
88988 {
88989 struct stat64 stat;
88990- if (sys_stat64(name, &stat) != 0)
88991+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
88992 return 0;
88993 if (!S_ISBLK(stat.st_mode))
88994 return 0;
88995@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
88996 static inline u32 bstat(char *name)
88997 {
88998 struct stat stat;
88999- if (sys_newstat(name, &stat) != 0)
89000+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
89001 return 0;
89002 if (!S_ISBLK(stat.st_mode))
89003 return 0;
89004diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
89005index 3e0878e..8a9d7a0 100644
89006--- a/init/do_mounts_initrd.c
89007+++ b/init/do_mounts_initrd.c
89008@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
89009 {
89010 sys_unshare(CLONE_FS | CLONE_FILES);
89011 /* stdin/stdout/stderr for /linuxrc */
89012- sys_open("/dev/console", O_RDWR, 0);
89013+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
89014 sys_dup(0);
89015 sys_dup(0);
89016 /* move initrd over / and chdir/chroot in initrd root */
89017- sys_chdir("/root");
89018- sys_mount(".", "/", NULL, MS_MOVE, NULL);
89019- sys_chroot(".");
89020+ sys_chdir((const char __force_user *)"/root");
89021+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
89022+ sys_chroot((const char __force_user *)".");
89023 sys_setsid();
89024 return 0;
89025 }
89026@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
89027 create_dev("/dev/root.old", Root_RAM0);
89028 /* mount initrd on rootfs' /root */
89029 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
89030- sys_mkdir("/old", 0700);
89031- sys_chdir("/old");
89032+ sys_mkdir((const char __force_user *)"/old", 0700);
89033+ sys_chdir((const char __force_user *)"/old");
89034
89035 /* try loading default modules from initrd */
89036 load_default_modules();
89037@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
89038 current->flags &= ~PF_FREEZER_SKIP;
89039
89040 /* move initrd to rootfs' /old */
89041- sys_mount("..", ".", NULL, MS_MOVE, NULL);
89042+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
89043 /* switch root and cwd back to / of rootfs */
89044- sys_chroot("..");
89045+ sys_chroot((const char __force_user *)"..");
89046
89047 if (new_decode_dev(real_root_dev) == Root_RAM0) {
89048- sys_chdir("/old");
89049+ sys_chdir((const char __force_user *)"/old");
89050 return;
89051 }
89052
89053- sys_chdir("/");
89054+ sys_chdir((const char __force_user *)"/");
89055 ROOT_DEV = new_decode_dev(real_root_dev);
89056 mount_root();
89057
89058 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
89059- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
89060+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
89061 if (!error)
89062 printk("okay\n");
89063 else {
89064- int fd = sys_open("/dev/root.old", O_RDWR, 0);
89065+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
89066 if (error == -ENOENT)
89067 printk("/initrd does not exist. Ignored.\n");
89068 else
89069 printk("failed\n");
89070 printk(KERN_NOTICE "Unmounting old root\n");
89071- sys_umount("/old", MNT_DETACH);
89072+ sys_umount((char __force_user *)"/old", MNT_DETACH);
89073 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
89074 if (fd < 0) {
89075 error = fd;
89076@@ -127,11 +127,11 @@ int __init initrd_load(void)
89077 * mounted in the normal path.
89078 */
89079 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
89080- sys_unlink("/initrd.image");
89081+ sys_unlink((const char __force_user *)"/initrd.image");
89082 handle_initrd();
89083 return 1;
89084 }
89085 }
89086- sys_unlink("/initrd.image");
89087+ sys_unlink((const char __force_user *)"/initrd.image");
89088 return 0;
89089 }
89090diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
89091index 8cb6db5..d729f50 100644
89092--- a/init/do_mounts_md.c
89093+++ b/init/do_mounts_md.c
89094@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
89095 partitioned ? "_d" : "", minor,
89096 md_setup_args[ent].device_names);
89097
89098- fd = sys_open(name, 0, 0);
89099+ fd = sys_open((char __force_user *)name, 0, 0);
89100 if (fd < 0) {
89101 printk(KERN_ERR "md: open failed - cannot start "
89102 "array %s\n", name);
89103@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
89104 * array without it
89105 */
89106 sys_close(fd);
89107- fd = sys_open(name, 0, 0);
89108+ fd = sys_open((char __force_user *)name, 0, 0);
89109 sys_ioctl(fd, BLKRRPART, 0);
89110 }
89111 sys_close(fd);
89112@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
89113
89114 wait_for_device_probe();
89115
89116- fd = sys_open("/dev/md0", 0, 0);
89117+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
89118 if (fd >= 0) {
89119 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
89120 sys_close(fd);
89121diff --git a/init/init_task.c b/init/init_task.c
89122index ba0a7f36..2bcf1d5 100644
89123--- a/init/init_task.c
89124+++ b/init/init_task.c
89125@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
89126 * Initial thread structure. Alignment of this is handled by a special
89127 * linker map entry.
89128 */
89129+#ifdef CONFIG_X86
89130+union thread_union init_thread_union __init_task_data;
89131+#else
89132 union thread_union init_thread_union __init_task_data =
89133 { INIT_THREAD_INFO(init_task) };
89134+#endif
89135diff --git a/init/initramfs.c b/init/initramfs.c
89136index a8497fa..35b3c90 100644
89137--- a/init/initramfs.c
89138+++ b/init/initramfs.c
89139@@ -84,7 +84,7 @@ static void __init free_hash(void)
89140 }
89141 }
89142
89143-static long __init do_utime(char *filename, time_t mtime)
89144+static long __init do_utime(char __force_user *filename, time_t mtime)
89145 {
89146 struct timespec t[2];
89147
89148@@ -119,7 +119,7 @@ static void __init dir_utime(void)
89149 struct dir_entry *de, *tmp;
89150 list_for_each_entry_safe(de, tmp, &dir_list, list) {
89151 list_del(&de->list);
89152- do_utime(de->name, de->mtime);
89153+ do_utime((char __force_user *)de->name, de->mtime);
89154 kfree(de->name);
89155 kfree(de);
89156 }
89157@@ -281,7 +281,7 @@ static int __init maybe_link(void)
89158 if (nlink >= 2) {
89159 char *old = find_link(major, minor, ino, mode, collected);
89160 if (old)
89161- return (sys_link(old, collected) < 0) ? -1 : 1;
89162+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
89163 }
89164 return 0;
89165 }
89166@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
89167 {
89168 struct stat st;
89169
89170- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
89171+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
89172 if (S_ISDIR(st.st_mode))
89173- sys_rmdir(path);
89174+ sys_rmdir((char __force_user *)path);
89175 else
89176- sys_unlink(path);
89177+ sys_unlink((char __force_user *)path);
89178 }
89179 }
89180
89181@@ -315,7 +315,7 @@ static int __init do_name(void)
89182 int openflags = O_WRONLY|O_CREAT;
89183 if (ml != 1)
89184 openflags |= O_TRUNC;
89185- wfd = sys_open(collected, openflags, mode);
89186+ wfd = sys_open((char __force_user *)collected, openflags, mode);
89187
89188 if (wfd >= 0) {
89189 sys_fchown(wfd, uid, gid);
89190@@ -327,17 +327,17 @@ static int __init do_name(void)
89191 }
89192 }
89193 } else if (S_ISDIR(mode)) {
89194- sys_mkdir(collected, mode);
89195- sys_chown(collected, uid, gid);
89196- sys_chmod(collected, mode);
89197+ sys_mkdir((char __force_user *)collected, mode);
89198+ sys_chown((char __force_user *)collected, uid, gid);
89199+ sys_chmod((char __force_user *)collected, mode);
89200 dir_add(collected, mtime);
89201 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
89202 S_ISFIFO(mode) || S_ISSOCK(mode)) {
89203 if (maybe_link() == 0) {
89204- sys_mknod(collected, mode, rdev);
89205- sys_chown(collected, uid, gid);
89206- sys_chmod(collected, mode);
89207- do_utime(collected, mtime);
89208+ sys_mknod((char __force_user *)collected, mode, rdev);
89209+ sys_chown((char __force_user *)collected, uid, gid);
89210+ sys_chmod((char __force_user *)collected, mode);
89211+ do_utime((char __force_user *)collected, mtime);
89212 }
89213 }
89214 return 0;
89215@@ -346,15 +346,15 @@ static int __init do_name(void)
89216 static int __init do_copy(void)
89217 {
89218 if (count >= body_len) {
89219- sys_write(wfd, victim, body_len);
89220+ sys_write(wfd, (char __force_user *)victim, body_len);
89221 sys_close(wfd);
89222- do_utime(vcollected, mtime);
89223+ do_utime((char __force_user *)vcollected, mtime);
89224 kfree(vcollected);
89225 eat(body_len);
89226 state = SkipIt;
89227 return 0;
89228 } else {
89229- sys_write(wfd, victim, count);
89230+ sys_write(wfd, (char __force_user *)victim, count);
89231 body_len -= count;
89232 eat(count);
89233 return 1;
89234@@ -365,9 +365,9 @@ static int __init do_symlink(void)
89235 {
89236 collected[N_ALIGN(name_len) + body_len] = '\0';
89237 clean_path(collected, 0);
89238- sys_symlink(collected + N_ALIGN(name_len), collected);
89239- sys_lchown(collected, uid, gid);
89240- do_utime(collected, mtime);
89241+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
89242+ sys_lchown((char __force_user *)collected, uid, gid);
89243+ do_utime((char __force_user *)collected, mtime);
89244 state = SkipIt;
89245 next_state = Reset;
89246 return 0;
89247diff --git a/init/main.c b/init/main.c
89248index e8ae1fe..f60f98c 100644
89249--- a/init/main.c
89250+++ b/init/main.c
89251@@ -98,6 +98,8 @@ extern void radix_tree_init(void);
89252 static inline void mark_rodata_ro(void) { }
89253 #endif
89254
89255+extern void grsecurity_init(void);
89256+
89257 /*
89258 * Debug helper: via this flag we know that we are in 'early bootup code'
89259 * where only the boot processor is running with IRQ disabled. This means
89260@@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
89261
89262 __setup("reset_devices", set_reset_devices);
89263
89264+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
89265+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
89266+static int __init setup_grsec_proc_gid(char *str)
89267+{
89268+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
89269+ return 1;
89270+}
89271+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
89272+#endif
89273+
89274+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
89275+unsigned long pax_user_shadow_base __read_only;
89276+EXPORT_SYMBOL(pax_user_shadow_base);
89277+extern char pax_enter_kernel_user[];
89278+extern char pax_exit_kernel_user[];
89279+#endif
89280+
89281+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
89282+static int __init setup_pax_nouderef(char *str)
89283+{
89284+#ifdef CONFIG_X86_32
89285+ unsigned int cpu;
89286+ struct desc_struct *gdt;
89287+
89288+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
89289+ gdt = get_cpu_gdt_table(cpu);
89290+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
89291+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
89292+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
89293+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
89294+ }
89295+ loadsegment(ds, __KERNEL_DS);
89296+ loadsegment(es, __KERNEL_DS);
89297+ loadsegment(ss, __KERNEL_DS);
89298+#else
89299+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
89300+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
89301+ clone_pgd_mask = ~(pgdval_t)0UL;
89302+ pax_user_shadow_base = 0UL;
89303+ setup_clear_cpu_cap(X86_FEATURE_PCID);
89304+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
89305+#endif
89306+
89307+ return 0;
89308+}
89309+early_param("pax_nouderef", setup_pax_nouderef);
89310+
89311+#ifdef CONFIG_X86_64
89312+static int __init setup_pax_weakuderef(char *str)
89313+{
89314+ if (clone_pgd_mask != ~(pgdval_t)0UL)
89315+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
89316+ return 1;
89317+}
89318+__setup("pax_weakuderef", setup_pax_weakuderef);
89319+#endif
89320+#endif
89321+
89322+#ifdef CONFIG_PAX_SOFTMODE
89323+int pax_softmode;
89324+
89325+static int __init setup_pax_softmode(char *str)
89326+{
89327+ get_option(&str, &pax_softmode);
89328+ return 1;
89329+}
89330+__setup("pax_softmode=", setup_pax_softmode);
89331+#endif
89332+
89333 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
89334 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
89335 static const char *panic_later, *panic_param;
89336@@ -727,7 +798,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
89337 struct blacklist_entry *entry;
89338 char *fn_name;
89339
89340- fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
89341+ fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
89342 if (!fn_name)
89343 return false;
89344
89345@@ -779,7 +850,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
89346 {
89347 int count = preempt_count();
89348 int ret;
89349- char msgbuf[64];
89350+ const char *msg1 = "", *msg2 = "";
89351
89352 if (initcall_blacklisted(fn))
89353 return -EPERM;
89354@@ -789,18 +860,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
89355 else
89356 ret = fn();
89357
89358- msgbuf[0] = 0;
89359-
89360 if (preempt_count() != count) {
89361- sprintf(msgbuf, "preemption imbalance ");
89362+ msg1 = " preemption imbalance";
89363 preempt_count_set(count);
89364 }
89365 if (irqs_disabled()) {
89366- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
89367+ msg2 = " disabled interrupts";
89368 local_irq_enable();
89369 }
89370- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
89371+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
89372
89373+ add_latent_entropy();
89374 return ret;
89375 }
89376
89377@@ -907,8 +977,8 @@ static int run_init_process(const char *init_filename)
89378 {
89379 argv_init[0] = init_filename;
89380 return do_execve(getname_kernel(init_filename),
89381- (const char __user *const __user *)argv_init,
89382- (const char __user *const __user *)envp_init);
89383+ (const char __user *const __force_user *)argv_init,
89384+ (const char __user *const __force_user *)envp_init);
89385 }
89386
89387 static int try_to_run_init_process(const char *init_filename)
89388@@ -925,6 +995,10 @@ static int try_to_run_init_process(const char *init_filename)
89389 return ret;
89390 }
89391
89392+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
89393+extern int gr_init_ran;
89394+#endif
89395+
89396 static noinline void __init kernel_init_freeable(void);
89397
89398 static int __ref kernel_init(void *unused)
89399@@ -949,6 +1023,11 @@ static int __ref kernel_init(void *unused)
89400 ramdisk_execute_command, ret);
89401 }
89402
89403+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
89404+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
89405+ gr_init_ran = 1;
89406+#endif
89407+
89408 /*
89409 * We try each of these until one succeeds.
89410 *
89411@@ -1004,7 +1083,7 @@ static noinline void __init kernel_init_freeable(void)
89412 do_basic_setup();
89413
89414 /* Open the /dev/console on the rootfs, this should never fail */
89415- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
89416+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
89417 pr_err("Warning: unable to open an initial console.\n");
89418
89419 (void) sys_dup(0);
89420@@ -1017,11 +1096,13 @@ static noinline void __init kernel_init_freeable(void)
89421 if (!ramdisk_execute_command)
89422 ramdisk_execute_command = "/init";
89423
89424- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
89425+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
89426 ramdisk_execute_command = NULL;
89427 prepare_namespace();
89428 }
89429
89430+ grsecurity_init();
89431+
89432 /*
89433 * Ok, we have completed the initial bootup, and
89434 * we're essentially up and running. Get rid of the
89435diff --git a/ipc/compat.c b/ipc/compat.c
89436index b5ef4f7..ff31d87 100644
89437--- a/ipc/compat.c
89438+++ b/ipc/compat.c
89439@@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
89440 COMPAT_SHMLBA);
89441 if (err < 0)
89442 return err;
89443- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
89444+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
89445 }
89446 case SHMDT:
89447 return sys_shmdt(compat_ptr(ptr));
89448diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
89449index c3f0326..d4e0579 100644
89450--- a/ipc/ipc_sysctl.c
89451+++ b/ipc/ipc_sysctl.c
89452@@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
89453 static int proc_ipc_dointvec(struct ctl_table *table, int write,
89454 void __user *buffer, size_t *lenp, loff_t *ppos)
89455 {
89456- struct ctl_table ipc_table;
89457+ ctl_table_no_const ipc_table;
89458
89459 memcpy(&ipc_table, table, sizeof(ipc_table));
89460 ipc_table.data = get_ipc(table);
89461@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
89462 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
89463 void __user *buffer, size_t *lenp, loff_t *ppos)
89464 {
89465- struct ctl_table ipc_table;
89466+ ctl_table_no_const ipc_table;
89467
89468 memcpy(&ipc_table, table, sizeof(ipc_table));
89469 ipc_table.data = get_ipc(table);
89470@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
89471 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
89472 void __user *buffer, size_t *lenp, loff_t *ppos)
89473 {
89474- struct ctl_table ipc_table;
89475+ ctl_table_no_const ipc_table;
89476 size_t lenp_bef = *lenp;
89477 int rc;
89478
89479@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
89480 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
89481 void __user *buffer, size_t *lenp, loff_t *ppos)
89482 {
89483- struct ctl_table ipc_table;
89484+ ctl_table_no_const ipc_table;
89485 memcpy(&ipc_table, table, sizeof(ipc_table));
89486 ipc_table.data = get_ipc(table);
89487
89488@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
89489 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
89490 void __user *buffer, size_t *lenp, loff_t *ppos)
89491 {
89492- struct ctl_table ipc_table;
89493+ ctl_table_no_const ipc_table;
89494 size_t lenp_bef = *lenp;
89495 int oldval;
89496 int rc;
89497diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
89498index 68d4e95..1477ded 100644
89499--- a/ipc/mq_sysctl.c
89500+++ b/ipc/mq_sysctl.c
89501@@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
89502 static int proc_mq_dointvec(struct ctl_table *table, int write,
89503 void __user *buffer, size_t *lenp, loff_t *ppos)
89504 {
89505- struct ctl_table mq_table;
89506+ ctl_table_no_const mq_table;
89507 memcpy(&mq_table, table, sizeof(mq_table));
89508 mq_table.data = get_mq(table);
89509
89510@@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
89511 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
89512 void __user *buffer, size_t *lenp, loff_t *ppos)
89513 {
89514- struct ctl_table mq_table;
89515+ ctl_table_no_const mq_table;
89516 memcpy(&mq_table, table, sizeof(mq_table));
89517 mq_table.data = get_mq(table);
89518
89519diff --git a/ipc/mqueue.c b/ipc/mqueue.c
89520index 4fcf39a..d3cc2ec 100644
89521--- a/ipc/mqueue.c
89522+++ b/ipc/mqueue.c
89523@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
89524 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
89525 info->attr.mq_msgsize);
89526
89527+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
89528 spin_lock(&mq_lock);
89529 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
89530 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
89531diff --git a/ipc/shm.c b/ipc/shm.c
89532index 89fc354..cf56786 100644
89533--- a/ipc/shm.c
89534+++ b/ipc/shm.c
89535@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
89536 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
89537 #endif
89538
89539+#ifdef CONFIG_GRKERNSEC
89540+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
89541+ const time_t shm_createtime, const kuid_t cuid,
89542+ const int shmid);
89543+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
89544+ const time_t shm_createtime);
89545+#endif
89546+
89547 void shm_init_ns(struct ipc_namespace *ns)
89548 {
89549 ns->shm_ctlmax = SHMMAX;
89550@@ -557,6 +565,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
89551 shp->shm_lprid = 0;
89552 shp->shm_atim = shp->shm_dtim = 0;
89553 shp->shm_ctim = get_seconds();
89554+#ifdef CONFIG_GRKERNSEC
89555+ {
89556+ struct timespec timeval;
89557+ do_posix_clock_monotonic_gettime(&timeval);
89558+
89559+ shp->shm_createtime = timeval.tv_sec;
89560+ }
89561+#endif
89562 shp->shm_segsz = size;
89563 shp->shm_nattch = 0;
89564 shp->shm_file = file;
89565@@ -1092,6 +1108,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
89566 f_mode = FMODE_READ | FMODE_WRITE;
89567 }
89568 if (shmflg & SHM_EXEC) {
89569+
89570+#ifdef CONFIG_PAX_MPROTECT
89571+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
89572+ goto out;
89573+#endif
89574+
89575 prot |= PROT_EXEC;
89576 acc_mode |= S_IXUGO;
89577 }
89578@@ -1116,6 +1138,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
89579 if (err)
89580 goto out_unlock;
89581
89582+#ifdef CONFIG_GRKERNSEC
89583+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
89584+ shp->shm_perm.cuid, shmid) ||
89585+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
89586+ err = -EACCES;
89587+ goto out_unlock;
89588+ }
89589+#endif
89590+
89591 ipc_lock_object(&shp->shm_perm);
89592
89593 /* check if shm_destroy() is tearing down shp */
89594@@ -1128,6 +1159,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
89595 path = shp->shm_file->f_path;
89596 path_get(&path);
89597 shp->shm_nattch++;
89598+#ifdef CONFIG_GRKERNSEC
89599+ shp->shm_lapid = current->pid;
89600+#endif
89601 size = i_size_read(path.dentry->d_inode);
89602 ipc_unlock_object(&shp->shm_perm);
89603 rcu_read_unlock();
89604diff --git a/ipc/util.c b/ipc/util.c
89605index 27d74e6..8be0be2 100644
89606--- a/ipc/util.c
89607+++ b/ipc/util.c
89608@@ -71,6 +71,8 @@ struct ipc_proc_iface {
89609 int (*show)(struct seq_file *, void *);
89610 };
89611
89612+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
89613+
89614 static void ipc_memory_notifier(struct work_struct *work)
89615 {
89616 ipcns_notify(IPCNS_MEMCHANGED);
89617@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
89618 granted_mode >>= 6;
89619 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
89620 granted_mode >>= 3;
89621+
89622+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
89623+ return -1;
89624+
89625 /* is there some bit set in requested_mode but not in granted_mode? */
89626 if ((requested_mode & ~granted_mode & 0007) &&
89627 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
89628diff --git a/kernel/acct.c b/kernel/acct.c
89629index 808a86f..da69695 100644
89630--- a/kernel/acct.c
89631+++ b/kernel/acct.c
89632@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
89633 */
89634 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
89635 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
89636- file->f_op->write(file, (char *)&ac,
89637+ file->f_op->write(file, (char __force_user *)&ac,
89638 sizeof(acct_t), &file->f_pos);
89639 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
89640 set_fs(fs);
89641diff --git a/kernel/audit.c b/kernel/audit.c
89642index 3ef2e0e..8873765 100644
89643--- a/kernel/audit.c
89644+++ b/kernel/audit.c
89645@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
89646 3) suppressed due to audit_rate_limit
89647 4) suppressed due to audit_backlog_limit
89648 */
89649-static atomic_t audit_lost = ATOMIC_INIT(0);
89650+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
89651
89652 /* The netlink socket. */
89653 static struct sock *audit_sock;
89654@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
89655 unsigned long now;
89656 int print;
89657
89658- atomic_inc(&audit_lost);
89659+ atomic_inc_unchecked(&audit_lost);
89660
89661 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
89662
89663@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
89664 if (print) {
89665 if (printk_ratelimit())
89666 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
89667- atomic_read(&audit_lost),
89668+ atomic_read_unchecked(&audit_lost),
89669 audit_rate_limit,
89670 audit_backlog_limit);
89671 audit_panic(message);
89672@@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
89673 s.pid = audit_pid;
89674 s.rate_limit = audit_rate_limit;
89675 s.backlog_limit = audit_backlog_limit;
89676- s.lost = atomic_read(&audit_lost);
89677+ s.lost = atomic_read_unchecked(&audit_lost);
89678 s.backlog = skb_queue_len(&audit_skb_queue);
89679 s.version = AUDIT_VERSION_LATEST;
89680 s.backlog_wait_time = audit_backlog_wait_time;
89681diff --git a/kernel/auditsc.c b/kernel/auditsc.c
89682index 21eae3c..66db239 100644
89683--- a/kernel/auditsc.c
89684+++ b/kernel/auditsc.c
89685@@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
89686 }
89687
89688 /* global counter which is incremented every time something logs in */
89689-static atomic_t session_id = ATOMIC_INIT(0);
89690+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
89691
89692 static int audit_set_loginuid_perm(kuid_t loginuid)
89693 {
89694@@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
89695
89696 /* are we setting or clearing? */
89697 if (uid_valid(loginuid))
89698- sessionid = (unsigned int)atomic_inc_return(&session_id);
89699+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
89700
89701 task->sessionid = sessionid;
89702 task->loginuid = loginuid;
89703diff --git a/kernel/capability.c b/kernel/capability.c
89704index a5cf13c..07a2647 100644
89705--- a/kernel/capability.c
89706+++ b/kernel/capability.c
89707@@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
89708 * before modification is attempted and the application
89709 * fails.
89710 */
89711+ if (tocopy > ARRAY_SIZE(kdata))
89712+ return -EFAULT;
89713+
89714 if (copy_to_user(dataptr, kdata, tocopy
89715 * sizeof(struct __user_cap_data_struct))) {
89716 return -EFAULT;
89717@@ -293,10 +296,11 @@ bool has_ns_capability(struct task_struct *t,
89718 int ret;
89719
89720 rcu_read_lock();
89721- ret = security_capable(__task_cred(t), ns, cap);
89722+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
89723+ gr_task_is_capable(t, __task_cred(t), cap);
89724 rcu_read_unlock();
89725
89726- return (ret == 0);
89727+ return ret;
89728 }
89729
89730 /**
89731@@ -333,10 +337,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
89732 int ret;
89733
89734 rcu_read_lock();
89735- ret = security_capable_noaudit(__task_cred(t), ns, cap);
89736+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
89737 rcu_read_unlock();
89738
89739- return (ret == 0);
89740+ return ret;
89741 }
89742
89743 /**
89744@@ -374,7 +378,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
89745 BUG();
89746 }
89747
89748- if (security_capable(current_cred(), ns, cap) == 0) {
89749+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
89750 current->flags |= PF_SUPERPRIV;
89751 return true;
89752 }
89753@@ -382,6 +386,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
89754 }
89755 EXPORT_SYMBOL(ns_capable);
89756
89757+bool ns_capable_nolog(struct user_namespace *ns, int cap)
89758+{
89759+ if (unlikely(!cap_valid(cap))) {
89760+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
89761+ BUG();
89762+ }
89763+
89764+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
89765+ current->flags |= PF_SUPERPRIV;
89766+ return true;
89767+ }
89768+ return false;
89769+}
89770+EXPORT_SYMBOL(ns_capable_nolog);
89771+
89772 /**
89773 * file_ns_capable - Determine if the file's opener had a capability in effect
89774 * @file: The file we want to check
89775@@ -423,6 +442,12 @@ bool capable(int cap)
89776 }
89777 EXPORT_SYMBOL(capable);
89778
89779+bool capable_nolog(int cap)
89780+{
89781+ return ns_capable_nolog(&init_user_ns, cap);
89782+}
89783+EXPORT_SYMBOL(capable_nolog);
89784+
89785 /**
89786 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
89787 * @inode: The inode in question
89788@@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
89789 kgid_has_mapping(ns, inode->i_gid);
89790 }
89791 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
89792+
89793+bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
89794+{
89795+ struct user_namespace *ns = current_user_ns();
89796+
89797+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
89798+ kgid_has_mapping(ns, inode->i_gid);
89799+}
89800+EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
89801diff --git a/kernel/cgroup.c b/kernel/cgroup.c
89802index 70776ae..09c4988 100644
89803--- a/kernel/cgroup.c
89804+++ b/kernel/cgroup.c
89805@@ -5146,6 +5146,14 @@ static void cgroup_release_agent(struct work_struct *work)
89806 release_list);
89807 list_del_init(&cgrp->release_list);
89808 raw_spin_unlock(&release_list_lock);
89809+
89810+ /*
89811+ * don't bother calling call_usermodehelper if we haven't
89812+ * configured a binary to execute
89813+ */
89814+ if (cgrp->root->release_agent_path[0] == '\0')
89815+ goto continue_free;
89816+
89817 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
89818 if (!pathbuf)
89819 goto continue_free;
89820@@ -5336,7 +5344,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
89821 struct task_struct *task;
89822 int count = 0;
89823
89824- seq_printf(seq, "css_set %p\n", cset);
89825+ seq_printf(seq, "css_set %pK\n", cset);
89826
89827 list_for_each_entry(task, &cset->tasks, cg_list) {
89828 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
89829diff --git a/kernel/compat.c b/kernel/compat.c
89830index 633394f..bdfa969 100644
89831--- a/kernel/compat.c
89832+++ b/kernel/compat.c
89833@@ -13,6 +13,7 @@
89834
89835 #include <linux/linkage.h>
89836 #include <linux/compat.h>
89837+#include <linux/module.h>
89838 #include <linux/errno.h>
89839 #include <linux/time.h>
89840 #include <linux/signal.h>
89841@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
89842 mm_segment_t oldfs;
89843 long ret;
89844
89845- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
89846+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
89847 oldfs = get_fs();
89848 set_fs(KERNEL_DS);
89849 ret = hrtimer_nanosleep_restart(restart);
89850@@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
89851 oldfs = get_fs();
89852 set_fs(KERNEL_DS);
89853 ret = hrtimer_nanosleep(&tu,
89854- rmtp ? (struct timespec __user *)&rmt : NULL,
89855+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
89856 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
89857 set_fs(oldfs);
89858
89859@@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
89860 mm_segment_t old_fs = get_fs();
89861
89862 set_fs(KERNEL_DS);
89863- ret = sys_sigpending((old_sigset_t __user *) &s);
89864+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
89865 set_fs(old_fs);
89866 if (ret == 0)
89867 ret = put_user(s, set);
89868@@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
89869 mm_segment_t old_fs = get_fs();
89870
89871 set_fs(KERNEL_DS);
89872- ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
89873+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
89874 set_fs(old_fs);
89875
89876 if (!ret) {
89877@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
89878 set_fs (KERNEL_DS);
89879 ret = sys_wait4(pid,
89880 (stat_addr ?
89881- (unsigned int __user *) &status : NULL),
89882- options, (struct rusage __user *) &r);
89883+ (unsigned int __force_user *) &status : NULL),
89884+ options, (struct rusage __force_user *) &r);
89885 set_fs (old_fs);
89886
89887 if (ret > 0) {
89888@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
89889 memset(&info, 0, sizeof(info));
89890
89891 set_fs(KERNEL_DS);
89892- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
89893- uru ? (struct rusage __user *)&ru : NULL);
89894+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
89895+ uru ? (struct rusage __force_user *)&ru : NULL);
89896 set_fs(old_fs);
89897
89898 if ((ret < 0) || (info.si_signo == 0))
89899@@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
89900 oldfs = get_fs();
89901 set_fs(KERNEL_DS);
89902 err = sys_timer_settime(timer_id, flags,
89903- (struct itimerspec __user *) &newts,
89904- (struct itimerspec __user *) &oldts);
89905+ (struct itimerspec __force_user *) &newts,
89906+ (struct itimerspec __force_user *) &oldts);
89907 set_fs(oldfs);
89908 if (!err && old && put_compat_itimerspec(old, &oldts))
89909 return -EFAULT;
89910@@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
89911 oldfs = get_fs();
89912 set_fs(KERNEL_DS);
89913 err = sys_timer_gettime(timer_id,
89914- (struct itimerspec __user *) &ts);
89915+ (struct itimerspec __force_user *) &ts);
89916 set_fs(oldfs);
89917 if (!err && put_compat_itimerspec(setting, &ts))
89918 return -EFAULT;
89919@@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
89920 oldfs = get_fs();
89921 set_fs(KERNEL_DS);
89922 err = sys_clock_settime(which_clock,
89923- (struct timespec __user *) &ts);
89924+ (struct timespec __force_user *) &ts);
89925 set_fs(oldfs);
89926 return err;
89927 }
89928@@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
89929 oldfs = get_fs();
89930 set_fs(KERNEL_DS);
89931 err = sys_clock_gettime(which_clock,
89932- (struct timespec __user *) &ts);
89933+ (struct timespec __force_user *) &ts);
89934 set_fs(oldfs);
89935 if (!err && compat_put_timespec(&ts, tp))
89936 return -EFAULT;
89937@@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
89938
89939 oldfs = get_fs();
89940 set_fs(KERNEL_DS);
89941- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
89942+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
89943 set_fs(oldfs);
89944
89945 err = compat_put_timex(utp, &txc);
89946@@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
89947 oldfs = get_fs();
89948 set_fs(KERNEL_DS);
89949 err = sys_clock_getres(which_clock,
89950- (struct timespec __user *) &ts);
89951+ (struct timespec __force_user *) &ts);
89952 set_fs(oldfs);
89953 if (!err && tp && compat_put_timespec(&ts, tp))
89954 return -EFAULT;
89955@@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
89956 struct timespec tu;
89957 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
89958
89959- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
89960+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
89961 oldfs = get_fs();
89962 set_fs(KERNEL_DS);
89963 err = clock_nanosleep_restart(restart);
89964@@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
89965 oldfs = get_fs();
89966 set_fs(KERNEL_DS);
89967 err = sys_clock_nanosleep(which_clock, flags,
89968- (struct timespec __user *) &in,
89969- (struct timespec __user *) &out);
89970+ (struct timespec __force_user *) &in,
89971+ (struct timespec __force_user *) &out);
89972 set_fs(oldfs);
89973
89974 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
89975@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
89976 mm_segment_t old_fs = get_fs();
89977
89978 set_fs(KERNEL_DS);
89979- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
89980+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
89981 set_fs(old_fs);
89982 if (compat_put_timespec(&t, interval))
89983 return -EFAULT;
89984diff --git a/kernel/configs.c b/kernel/configs.c
89985index c18b1f1..b9a0132 100644
89986--- a/kernel/configs.c
89987+++ b/kernel/configs.c
89988@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
89989 struct proc_dir_entry *entry;
89990
89991 /* create the current config file */
89992+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
89993+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
89994+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
89995+ &ikconfig_file_ops);
89996+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89997+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
89998+ &ikconfig_file_ops);
89999+#endif
90000+#else
90001 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
90002 &ikconfig_file_ops);
90003+#endif
90004+
90005 if (!entry)
90006 return -ENOMEM;
90007
90008diff --git a/kernel/cred.c b/kernel/cred.c
90009index e0573a4..26c0fd3 100644
90010--- a/kernel/cred.c
90011+++ b/kernel/cred.c
90012@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
90013 validate_creds(cred);
90014 alter_cred_subscribers(cred, -1);
90015 put_cred(cred);
90016+
90017+#ifdef CONFIG_GRKERNSEC_SETXID
90018+ cred = (struct cred *) tsk->delayed_cred;
90019+ if (cred != NULL) {
90020+ tsk->delayed_cred = NULL;
90021+ validate_creds(cred);
90022+ alter_cred_subscribers(cred, -1);
90023+ put_cred(cred);
90024+ }
90025+#endif
90026 }
90027
90028 /**
90029@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
90030 * Always returns 0 thus allowing this function to be tail-called at the end
90031 * of, say, sys_setgid().
90032 */
90033-int commit_creds(struct cred *new)
90034+static int __commit_creds(struct cred *new)
90035 {
90036 struct task_struct *task = current;
90037 const struct cred *old = task->real_cred;
90038@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
90039
90040 get_cred(new); /* we will require a ref for the subj creds too */
90041
90042+ gr_set_role_label(task, new->uid, new->gid);
90043+
90044 /* dumpability changes */
90045 if (!uid_eq(old->euid, new->euid) ||
90046 !gid_eq(old->egid, new->egid) ||
90047@@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
90048 put_cred(old);
90049 return 0;
90050 }
90051+#ifdef CONFIG_GRKERNSEC_SETXID
90052+extern int set_user(struct cred *new);
90053+
90054+void gr_delayed_cred_worker(void)
90055+{
90056+ const struct cred *new = current->delayed_cred;
90057+ struct cred *ncred;
90058+
90059+ current->delayed_cred = NULL;
90060+
90061+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
90062+ // from doing get_cred on it when queueing this
90063+ put_cred(new);
90064+ return;
90065+ } else if (new == NULL)
90066+ return;
90067+
90068+ ncred = prepare_creds();
90069+ if (!ncred)
90070+ goto die;
90071+ // uids
90072+ ncred->uid = new->uid;
90073+ ncred->euid = new->euid;
90074+ ncred->suid = new->suid;
90075+ ncred->fsuid = new->fsuid;
90076+ // gids
90077+ ncred->gid = new->gid;
90078+ ncred->egid = new->egid;
90079+ ncred->sgid = new->sgid;
90080+ ncred->fsgid = new->fsgid;
90081+ // groups
90082+ set_groups(ncred, new->group_info);
90083+ // caps
90084+ ncred->securebits = new->securebits;
90085+ ncred->cap_inheritable = new->cap_inheritable;
90086+ ncred->cap_permitted = new->cap_permitted;
90087+ ncred->cap_effective = new->cap_effective;
90088+ ncred->cap_bset = new->cap_bset;
90089+
90090+ if (set_user(ncred)) {
90091+ abort_creds(ncred);
90092+ goto die;
90093+ }
90094+
90095+ // from doing get_cred on it when queueing this
90096+ put_cred(new);
90097+
90098+ __commit_creds(ncred);
90099+ return;
90100+die:
90101+ // from doing get_cred on it when queueing this
90102+ put_cred(new);
90103+ do_group_exit(SIGKILL);
90104+}
90105+#endif
90106+
90107+int commit_creds(struct cred *new)
90108+{
90109+#ifdef CONFIG_GRKERNSEC_SETXID
90110+ int ret;
90111+ int schedule_it = 0;
90112+ struct task_struct *t;
90113+ unsigned oldsecurebits = current_cred()->securebits;
90114+
90115+ /* we won't get called with tasklist_lock held for writing
90116+ and interrupts disabled as the cred struct in that case is
90117+ init_cred
90118+ */
90119+ if (grsec_enable_setxid && !current_is_single_threaded() &&
90120+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
90121+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
90122+ schedule_it = 1;
90123+ }
90124+ ret = __commit_creds(new);
90125+ if (schedule_it) {
90126+ rcu_read_lock();
90127+ read_lock(&tasklist_lock);
90128+ for (t = next_thread(current); t != current;
90129+ t = next_thread(t)) {
90130+ /* we'll check if the thread has uid 0 in
90131+ * the delayed worker routine
90132+ */
90133+ if (task_securebits(t) == oldsecurebits &&
90134+ t->delayed_cred == NULL) {
90135+ t->delayed_cred = get_cred(new);
90136+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
90137+ set_tsk_need_resched(t);
90138+ }
90139+ }
90140+ read_unlock(&tasklist_lock);
90141+ rcu_read_unlock();
90142+ }
90143+
90144+ return ret;
90145+#else
90146+ return __commit_creds(new);
90147+#endif
90148+}
90149+
90150 EXPORT_SYMBOL(commit_creds);
90151
90152 /**
90153diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
90154index 1adf62b..7736e06 100644
90155--- a/kernel/debug/debug_core.c
90156+++ b/kernel/debug/debug_core.c
90157@@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
90158 */
90159 static atomic_t masters_in_kgdb;
90160 static atomic_t slaves_in_kgdb;
90161-static atomic_t kgdb_break_tasklet_var;
90162+static atomic_unchecked_t kgdb_break_tasklet_var;
90163 atomic_t kgdb_setting_breakpoint;
90164
90165 struct task_struct *kgdb_usethread;
90166@@ -134,7 +134,7 @@ int kgdb_single_step;
90167 static pid_t kgdb_sstep_pid;
90168
90169 /* to keep track of the CPU which is doing the single stepping*/
90170-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
90171+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
90172
90173 /*
90174 * If you are debugging a problem where roundup (the collection of
90175@@ -549,7 +549,7 @@ return_normal:
90176 * kernel will only try for the value of sstep_tries before
90177 * giving up and continuing on.
90178 */
90179- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
90180+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
90181 (kgdb_info[cpu].task &&
90182 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
90183 atomic_set(&kgdb_active, -1);
90184@@ -647,8 +647,8 @@ cpu_master_loop:
90185 }
90186
90187 kgdb_restore:
90188- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
90189- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
90190+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
90191+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
90192 if (kgdb_info[sstep_cpu].task)
90193 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
90194 else
90195@@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
90196 static void kgdb_tasklet_bpt(unsigned long ing)
90197 {
90198 kgdb_breakpoint();
90199- atomic_set(&kgdb_break_tasklet_var, 0);
90200+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
90201 }
90202
90203 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
90204
90205 void kgdb_schedule_breakpoint(void)
90206 {
90207- if (atomic_read(&kgdb_break_tasklet_var) ||
90208+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
90209 atomic_read(&kgdb_active) != -1 ||
90210 atomic_read(&kgdb_setting_breakpoint))
90211 return;
90212- atomic_inc(&kgdb_break_tasklet_var);
90213+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
90214 tasklet_schedule(&kgdb_tasklet_breakpoint);
90215 }
90216 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
90217diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
90218index 2f7c760..95b6a66 100644
90219--- a/kernel/debug/kdb/kdb_main.c
90220+++ b/kernel/debug/kdb/kdb_main.c
90221@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
90222 continue;
90223
90224 kdb_printf("%-20s%8u 0x%p ", mod->name,
90225- mod->core_size, (void *)mod);
90226+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
90227 #ifdef CONFIG_MODULE_UNLOAD
90228 kdb_printf("%4ld ", module_refcount(mod));
90229 #endif
90230@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
90231 kdb_printf(" (Loading)");
90232 else
90233 kdb_printf(" (Live)");
90234- kdb_printf(" 0x%p", mod->module_core);
90235+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
90236
90237 #ifdef CONFIG_MODULE_UNLOAD
90238 {
90239diff --git a/kernel/events/core.c b/kernel/events/core.c
90240index 6b17ac1..00fd505 100644
90241--- a/kernel/events/core.c
90242+++ b/kernel/events/core.c
90243@@ -160,8 +160,15 @@ static struct srcu_struct pmus_srcu;
90244 * 0 - disallow raw tracepoint access for unpriv
90245 * 1 - disallow cpu events for unpriv
90246 * 2 - disallow kernel profiling for unpriv
90247+ * 3 - disallow all unpriv perf event use
90248 */
90249-int sysctl_perf_event_paranoid __read_mostly = 1;
90250+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90251+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
90252+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
90253+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
90254+#else
90255+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
90256+#endif
90257
90258 /* Minimum for 512 kiB + 1 user control page */
90259 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
90260@@ -187,7 +194,7 @@ void update_perf_cpu_limits(void)
90261
90262 tmp *= sysctl_perf_cpu_time_max_percent;
90263 do_div(tmp, 100);
90264- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
90265+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
90266 }
90267
90268 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
90269@@ -293,7 +300,7 @@ void perf_sample_event_took(u64 sample_len_ns)
90270 }
90271 }
90272
90273-static atomic64_t perf_event_id;
90274+static atomic64_unchecked_t perf_event_id;
90275
90276 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
90277 enum event_type_t event_type);
90278@@ -3023,7 +3030,7 @@ static void __perf_event_read(void *info)
90279
90280 static inline u64 perf_event_count(struct perf_event *event)
90281 {
90282- return local64_read(&event->count) + atomic64_read(&event->child_count);
90283+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
90284 }
90285
90286 static u64 perf_event_read(struct perf_event *event)
90287@@ -3399,9 +3406,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
90288 mutex_lock(&event->child_mutex);
90289 total += perf_event_read(event);
90290 *enabled += event->total_time_enabled +
90291- atomic64_read(&event->child_total_time_enabled);
90292+ atomic64_read_unchecked(&event->child_total_time_enabled);
90293 *running += event->total_time_running +
90294- atomic64_read(&event->child_total_time_running);
90295+ atomic64_read_unchecked(&event->child_total_time_running);
90296
90297 list_for_each_entry(child, &event->child_list, child_list) {
90298 total += perf_event_read(child);
90299@@ -3830,10 +3837,10 @@ void perf_event_update_userpage(struct perf_event *event)
90300 userpg->offset -= local64_read(&event->hw.prev_count);
90301
90302 userpg->time_enabled = enabled +
90303- atomic64_read(&event->child_total_time_enabled);
90304+ atomic64_read_unchecked(&event->child_total_time_enabled);
90305
90306 userpg->time_running = running +
90307- atomic64_read(&event->child_total_time_running);
90308+ atomic64_read_unchecked(&event->child_total_time_running);
90309
90310 arch_perf_update_userpage(userpg, now);
90311
90312@@ -4397,7 +4404,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
90313
90314 /* Data. */
90315 sp = perf_user_stack_pointer(regs);
90316- rem = __output_copy_user(handle, (void *) sp, dump_size);
90317+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
90318 dyn_size = dump_size - rem;
90319
90320 perf_output_skip(handle, rem);
90321@@ -4488,11 +4495,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
90322 values[n++] = perf_event_count(event);
90323 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
90324 values[n++] = enabled +
90325- atomic64_read(&event->child_total_time_enabled);
90326+ atomic64_read_unchecked(&event->child_total_time_enabled);
90327 }
90328 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
90329 values[n++] = running +
90330- atomic64_read(&event->child_total_time_running);
90331+ atomic64_read_unchecked(&event->child_total_time_running);
90332 }
90333 if (read_format & PERF_FORMAT_ID)
90334 values[n++] = primary_event_id(event);
90335@@ -6801,7 +6808,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
90336 event->parent = parent_event;
90337
90338 event->ns = get_pid_ns(task_active_pid_ns(current));
90339- event->id = atomic64_inc_return(&perf_event_id);
90340+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
90341
90342 event->state = PERF_EVENT_STATE_INACTIVE;
90343
90344@@ -7080,6 +7087,11 @@ SYSCALL_DEFINE5(perf_event_open,
90345 if (flags & ~PERF_FLAG_ALL)
90346 return -EINVAL;
90347
90348+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90349+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
90350+ return -EACCES;
90351+#endif
90352+
90353 err = perf_copy_attr(attr_uptr, &attr);
90354 if (err)
90355 return err;
90356@@ -7432,10 +7444,10 @@ static void sync_child_event(struct perf_event *child_event,
90357 /*
90358 * Add back the child's count to the parent's count:
90359 */
90360- atomic64_add(child_val, &parent_event->child_count);
90361- atomic64_add(child_event->total_time_enabled,
90362+ atomic64_add_unchecked(child_val, &parent_event->child_count);
90363+ atomic64_add_unchecked(child_event->total_time_enabled,
90364 &parent_event->child_total_time_enabled);
90365- atomic64_add(child_event->total_time_running,
90366+ atomic64_add_unchecked(child_event->total_time_running,
90367 &parent_event->child_total_time_running);
90368
90369 /*
90370diff --git a/kernel/events/internal.h b/kernel/events/internal.h
90371index 569b2187..19940d9 100644
90372--- a/kernel/events/internal.h
90373+++ b/kernel/events/internal.h
90374@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
90375 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
90376 }
90377
90378-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
90379+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
90380 static inline unsigned long \
90381 func_name(struct perf_output_handle *handle, \
90382- const void *buf, unsigned long len) \
90383+ const void user *buf, unsigned long len) \
90384 { \
90385 unsigned long size, written; \
90386 \
90387@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
90388 return 0;
90389 }
90390
90391-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
90392+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
90393
90394 static inline unsigned long
90395 memcpy_skip(void *dst, const void *src, unsigned long n)
90396@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
90397 return 0;
90398 }
90399
90400-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
90401+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
90402
90403 #ifndef arch_perf_out_copy_user
90404 #define arch_perf_out_copy_user arch_perf_out_copy_user
90405@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
90406 }
90407 #endif
90408
90409-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
90410+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
90411
90412 /* Callchain handling */
90413 extern struct perf_callchain_entry *
90414diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
90415index 6f3254e..e4c1fe4 100644
90416--- a/kernel/events/uprobes.c
90417+++ b/kernel/events/uprobes.c
90418@@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
90419 {
90420 struct page *page;
90421 uprobe_opcode_t opcode;
90422- int result;
90423+ long result;
90424
90425 pagefault_disable();
90426 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
90427diff --git a/kernel/exit.c b/kernel/exit.c
90428index e5c4668..592d2e5 100644
90429--- a/kernel/exit.c
90430+++ b/kernel/exit.c
90431@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
90432 struct task_struct *leader;
90433 int zap_leader;
90434 repeat:
90435+#ifdef CONFIG_NET
90436+ gr_del_task_from_ip_table(p);
90437+#endif
90438+
90439 /* don't need to get the RCU readlock here - the process is dead and
90440 * can't be modifying its own credentials. But shut RCU-lockdep up */
90441 rcu_read_lock();
90442@@ -664,6 +668,8 @@ void do_exit(long code)
90443 struct task_struct *tsk = current;
90444 int group_dead;
90445
90446+ set_fs(USER_DS);
90447+
90448 profile_task_exit(tsk);
90449
90450 WARN_ON(blk_needs_flush_plug(tsk));
90451@@ -680,7 +686,6 @@ void do_exit(long code)
90452 * mm_release()->clear_child_tid() from writing to a user-controlled
90453 * kernel address.
90454 */
90455- set_fs(USER_DS);
90456
90457 ptrace_event(PTRACE_EVENT_EXIT, code);
90458
90459@@ -739,6 +744,9 @@ void do_exit(long code)
90460 tsk->exit_code = code;
90461 taskstats_exit(tsk, group_dead);
90462
90463+ gr_acl_handle_psacct(tsk, code);
90464+ gr_acl_handle_exit();
90465+
90466 exit_mm(tsk);
90467
90468 if (group_dead)
90469@@ -858,7 +866,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
90470 * Take down every thread in the group. This is called by fatal signals
90471 * as well as by sys_exit_group (below).
90472 */
90473-void
90474+__noreturn void
90475 do_group_exit(int exit_code)
90476 {
90477 struct signal_struct *sig = current->signal;
90478diff --git a/kernel/fork.c b/kernel/fork.c
90479index 6a13c46..a623c8e 100644
90480--- a/kernel/fork.c
90481+++ b/kernel/fork.c
90482@@ -183,6 +183,48 @@ void thread_info_cache_init(void)
90483 # endif
90484 #endif
90485
90486+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
90487+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
90488+ int node, void **lowmem_stack)
90489+{
90490+ struct page *pages[THREAD_SIZE / PAGE_SIZE];
90491+ void *ret = NULL;
90492+ unsigned int i;
90493+
90494+ *lowmem_stack = alloc_thread_info_node(tsk, node);
90495+ if (*lowmem_stack == NULL)
90496+ goto out;
90497+
90498+ for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
90499+ pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
90500+
90501+ /* use VM_IOREMAP to gain THREAD_SIZE alignment */
90502+ ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
90503+ if (ret == NULL) {
90504+ free_thread_info(*lowmem_stack);
90505+ *lowmem_stack = NULL;
90506+ }
90507+
90508+out:
90509+ return ret;
90510+}
90511+
90512+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
90513+{
90514+ unmap_process_stacks(tsk);
90515+}
90516+#else
90517+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
90518+ int node, void **lowmem_stack)
90519+{
90520+ return alloc_thread_info_node(tsk, node);
90521+}
90522+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
90523+{
90524+ free_thread_info(ti);
90525+}
90526+#endif
90527+
90528 /* SLAB cache for signal_struct structures (tsk->signal) */
90529 static struct kmem_cache *signal_cachep;
90530
90531@@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
90532 /* SLAB cache for mm_struct structures (tsk->mm) */
90533 static struct kmem_cache *mm_cachep;
90534
90535-static void account_kernel_stack(struct thread_info *ti, int account)
90536+static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
90537 {
90538+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
90539+ struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
90540+#else
90541 struct zone *zone = page_zone(virt_to_page(ti));
90542+#endif
90543
90544 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
90545 }
90546
90547 void free_task(struct task_struct *tsk)
90548 {
90549- account_kernel_stack(tsk->stack, -1);
90550+ account_kernel_stack(tsk, tsk->stack, -1);
90551 arch_release_thread_info(tsk->stack);
90552- free_thread_info(tsk->stack);
90553+ gr_free_thread_info(tsk, tsk->stack);
90554 rt_mutex_debug_task_free(tsk);
90555 ftrace_graph_exit_task(tsk);
90556 put_seccomp_filter(tsk);
90557@@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90558 struct task_struct *tsk;
90559 struct thread_info *ti;
90560 unsigned long *stackend;
90561+ void *lowmem_stack;
90562 int node = tsk_fork_get_node(orig);
90563 int err;
90564
90565@@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90566 if (!tsk)
90567 return NULL;
90568
90569- ti = alloc_thread_info_node(tsk, node);
90570+ ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
90571 if (!ti)
90572 goto free_tsk;
90573
90574@@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90575 goto free_ti;
90576
90577 tsk->stack = ti;
90578+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
90579+ tsk->lowmem_stack = lowmem_stack;
90580+#endif
90581
90582 setup_thread_stack(tsk, orig);
90583 clear_user_return_notifier(tsk);
90584@@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90585 *stackend = STACK_END_MAGIC; /* for overflow detection */
90586
90587 #ifdef CONFIG_CC_STACKPROTECTOR
90588- tsk->stack_canary = get_random_int();
90589+ tsk->stack_canary = pax_get_random_long();
90590 #endif
90591
90592 /*
90593@@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90594 tsk->splice_pipe = NULL;
90595 tsk->task_frag.page = NULL;
90596
90597- account_kernel_stack(ti, 1);
90598+ account_kernel_stack(tsk, ti, 1);
90599
90600 return tsk;
90601
90602 free_ti:
90603- free_thread_info(ti);
90604+ gr_free_thread_info(tsk, ti);
90605 free_tsk:
90606 free_task_struct(tsk);
90607 return NULL;
90608 }
90609
90610 #ifdef CONFIG_MMU
90611-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90612+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
90613+{
90614+ struct vm_area_struct *tmp;
90615+ unsigned long charge;
90616+ struct file *file;
90617+ int retval;
90618+
90619+ charge = 0;
90620+ if (mpnt->vm_flags & VM_ACCOUNT) {
90621+ unsigned long len = vma_pages(mpnt);
90622+
90623+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
90624+ goto fail_nomem;
90625+ charge = len;
90626+ }
90627+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
90628+ if (!tmp)
90629+ goto fail_nomem;
90630+ *tmp = *mpnt;
90631+ tmp->vm_mm = mm;
90632+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
90633+ retval = vma_dup_policy(mpnt, tmp);
90634+ if (retval)
90635+ goto fail_nomem_policy;
90636+ if (anon_vma_fork(tmp, mpnt))
90637+ goto fail_nomem_anon_vma_fork;
90638+ tmp->vm_flags &= ~VM_LOCKED;
90639+ tmp->vm_next = tmp->vm_prev = NULL;
90640+ tmp->vm_mirror = NULL;
90641+ file = tmp->vm_file;
90642+ if (file) {
90643+ struct inode *inode = file_inode(file);
90644+ struct address_space *mapping = file->f_mapping;
90645+
90646+ get_file(file);
90647+ if (tmp->vm_flags & VM_DENYWRITE)
90648+ atomic_dec(&inode->i_writecount);
90649+ mutex_lock(&mapping->i_mmap_mutex);
90650+ if (tmp->vm_flags & VM_SHARED)
90651+ mapping->i_mmap_writable++;
90652+ flush_dcache_mmap_lock(mapping);
90653+ /* insert tmp into the share list, just after mpnt */
90654+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
90655+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
90656+ else
90657+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
90658+ flush_dcache_mmap_unlock(mapping);
90659+ mutex_unlock(&mapping->i_mmap_mutex);
90660+ }
90661+
90662+ /*
90663+ * Clear hugetlb-related page reserves for children. This only
90664+ * affects MAP_PRIVATE mappings. Faults generated by the child
90665+ * are not guaranteed to succeed, even if read-only
90666+ */
90667+ if (is_vm_hugetlb_page(tmp))
90668+ reset_vma_resv_huge_pages(tmp);
90669+
90670+ return tmp;
90671+
90672+fail_nomem_anon_vma_fork:
90673+ mpol_put(vma_policy(tmp));
90674+fail_nomem_policy:
90675+ kmem_cache_free(vm_area_cachep, tmp);
90676+fail_nomem:
90677+ vm_unacct_memory(charge);
90678+ return NULL;
90679+}
90680+
90681+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90682 {
90683 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
90684 struct rb_node **rb_link, *rb_parent;
90685 int retval;
90686- unsigned long charge;
90687
90688 uprobe_start_dup_mmap();
90689 down_write(&oldmm->mmap_sem);
90690@@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90691
90692 prev = NULL;
90693 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
90694- struct file *file;
90695-
90696 if (mpnt->vm_flags & VM_DONTCOPY) {
90697 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
90698 -vma_pages(mpnt));
90699 continue;
90700 }
90701- charge = 0;
90702- if (mpnt->vm_flags & VM_ACCOUNT) {
90703- unsigned long len = vma_pages(mpnt);
90704-
90705- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
90706- goto fail_nomem;
90707- charge = len;
90708- }
90709- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
90710- if (!tmp)
90711- goto fail_nomem;
90712- *tmp = *mpnt;
90713- INIT_LIST_HEAD(&tmp->anon_vma_chain);
90714- retval = vma_dup_policy(mpnt, tmp);
90715- if (retval)
90716- goto fail_nomem_policy;
90717- tmp->vm_mm = mm;
90718- if (anon_vma_fork(tmp, mpnt))
90719- goto fail_nomem_anon_vma_fork;
90720- tmp->vm_flags &= ~VM_LOCKED;
90721- tmp->vm_next = tmp->vm_prev = NULL;
90722- file = tmp->vm_file;
90723- if (file) {
90724- struct inode *inode = file_inode(file);
90725- struct address_space *mapping = file->f_mapping;
90726-
90727- get_file(file);
90728- if (tmp->vm_flags & VM_DENYWRITE)
90729- atomic_dec(&inode->i_writecount);
90730- mutex_lock(&mapping->i_mmap_mutex);
90731- if (tmp->vm_flags & VM_SHARED)
90732- mapping->i_mmap_writable++;
90733- flush_dcache_mmap_lock(mapping);
90734- /* insert tmp into the share list, just after mpnt */
90735- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
90736- vma_nonlinear_insert(tmp,
90737- &mapping->i_mmap_nonlinear);
90738- else
90739- vma_interval_tree_insert_after(tmp, mpnt,
90740- &mapping->i_mmap);
90741- flush_dcache_mmap_unlock(mapping);
90742- mutex_unlock(&mapping->i_mmap_mutex);
90743+ tmp = dup_vma(mm, oldmm, mpnt);
90744+ if (!tmp) {
90745+ retval = -ENOMEM;
90746+ goto out;
90747 }
90748
90749 /*
90750@@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90751 if (retval)
90752 goto out;
90753 }
90754+
90755+#ifdef CONFIG_PAX_SEGMEXEC
90756+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
90757+ struct vm_area_struct *mpnt_m;
90758+
90759+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
90760+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
90761+
90762+ if (!mpnt->vm_mirror)
90763+ continue;
90764+
90765+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
90766+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
90767+ mpnt->vm_mirror = mpnt_m;
90768+ } else {
90769+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
90770+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
90771+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
90772+ mpnt->vm_mirror->vm_mirror = mpnt;
90773+ }
90774+ }
90775+ BUG_ON(mpnt_m);
90776+ }
90777+#endif
90778+
90779 /* a new mm has just been created */
90780 arch_dup_mmap(oldmm, mm);
90781 retval = 0;
90782@@ -472,14 +575,6 @@ out:
90783 up_write(&oldmm->mmap_sem);
90784 uprobe_end_dup_mmap();
90785 return retval;
90786-fail_nomem_anon_vma_fork:
90787- mpol_put(vma_policy(tmp));
90788-fail_nomem_policy:
90789- kmem_cache_free(vm_area_cachep, tmp);
90790-fail_nomem:
90791- retval = -ENOMEM;
90792- vm_unacct_memory(charge);
90793- goto out;
90794 }
90795
90796 static inline int mm_alloc_pgd(struct mm_struct *mm)
90797@@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
90798 return ERR_PTR(err);
90799
90800 mm = get_task_mm(task);
90801- if (mm && mm != current->mm &&
90802- !ptrace_may_access(task, mode)) {
90803+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
90804+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
90805 mmput(mm);
90806 mm = ERR_PTR(-EACCES);
90807 }
90808@@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
90809 spin_unlock(&fs->lock);
90810 return -EAGAIN;
90811 }
90812- fs->users++;
90813+ atomic_inc(&fs->users);
90814 spin_unlock(&fs->lock);
90815 return 0;
90816 }
90817 tsk->fs = copy_fs_struct(fs);
90818 if (!tsk->fs)
90819 return -ENOMEM;
90820+ /* Carry through gr_chroot_dentry and is_chrooted instead
90821+ of recomputing it here. Already copied when the task struct
90822+ is duplicated. This allows pivot_root to not be treated as
90823+ a chroot
90824+ */
90825+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
90826+
90827 return 0;
90828 }
90829
90830@@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
90831 * parts of the process environment (as per the clone
90832 * flags). The actual kick-off is left to the caller.
90833 */
90834-static struct task_struct *copy_process(unsigned long clone_flags,
90835+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
90836 unsigned long stack_start,
90837 unsigned long stack_size,
90838 int __user *child_tidptr,
90839@@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
90840 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
90841 #endif
90842 retval = -EAGAIN;
90843+
90844+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
90845+
90846 if (atomic_read(&p->real_cred->user->processes) >=
90847 task_rlimit(p, RLIMIT_NPROC)) {
90848 if (p->real_cred->user != INIT_USER &&
90849@@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
90850 goto bad_fork_free_pid;
90851 }
90852
90853+ /* synchronizes with gr_set_acls()
90854+ we need to call this past the point of no return for fork()
90855+ */
90856+ gr_copy_label(p);
90857+
90858 if (likely(p->pid)) {
90859 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
90860
90861@@ -1541,6 +1651,8 @@ bad_fork_cleanup_count:
90862 bad_fork_free:
90863 free_task(p);
90864 fork_out:
90865+ gr_log_forkfail(retval);
90866+
90867 return ERR_PTR(retval);
90868 }
90869
90870@@ -1602,6 +1714,7 @@ long do_fork(unsigned long clone_flags,
90871
90872 p = copy_process(clone_flags, stack_start, stack_size,
90873 child_tidptr, NULL, trace);
90874+ add_latent_entropy();
90875 /*
90876 * Do this prior waking up the new thread - the thread pointer
90877 * might get invalid after that point, if the thread exits quickly.
90878@@ -1618,6 +1731,8 @@ long do_fork(unsigned long clone_flags,
90879 if (clone_flags & CLONE_PARENT_SETTID)
90880 put_user(nr, parent_tidptr);
90881
90882+ gr_handle_brute_check();
90883+
90884 if (clone_flags & CLONE_VFORK) {
90885 p->vfork_done = &vfork;
90886 init_completion(&vfork);
90887@@ -1736,7 +1851,7 @@ void __init proc_caches_init(void)
90888 mm_cachep = kmem_cache_create("mm_struct",
90889 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
90890 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
90891- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
90892+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
90893 mmap_init();
90894 nsproxy_cache_init();
90895 }
90896@@ -1776,7 +1891,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
90897 return 0;
90898
90899 /* don't need lock here; in the worst case we'll do useless copy */
90900- if (fs->users == 1)
90901+ if (atomic_read(&fs->users) == 1)
90902 return 0;
90903
90904 *new_fsp = copy_fs_struct(fs);
90905@@ -1883,7 +1998,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
90906 fs = current->fs;
90907 spin_lock(&fs->lock);
90908 current->fs = new_fs;
90909- if (--fs->users)
90910+ gr_set_chroot_entries(current, &current->fs->root);
90911+ if (atomic_dec_return(&fs->users))
90912 new_fs = NULL;
90913 else
90914 new_fs = fs;
90915diff --git a/kernel/futex.c b/kernel/futex.c
90916index b632b5f..ca00da9 100644
90917--- a/kernel/futex.c
90918+++ b/kernel/futex.c
90919@@ -202,7 +202,7 @@ struct futex_pi_state {
90920 atomic_t refcount;
90921
90922 union futex_key key;
90923-};
90924+} __randomize_layout;
90925
90926 /**
90927 * struct futex_q - The hashed futex queue entry, one per waiting task
90928@@ -236,7 +236,7 @@ struct futex_q {
90929 struct rt_mutex_waiter *rt_waiter;
90930 union futex_key *requeue_pi_key;
90931 u32 bitset;
90932-};
90933+} __randomize_layout;
90934
90935 static const struct futex_q futex_q_init = {
90936 /* list gets initialized in queue_me()*/
90937@@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
90938 struct page *page, *page_head;
90939 int err, ro = 0;
90940
90941+#ifdef CONFIG_PAX_SEGMEXEC
90942+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
90943+ return -EFAULT;
90944+#endif
90945+
90946 /*
90947 * The futex address must be "naturally" aligned.
90948 */
90949@@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
90950
90951 static int get_futex_value_locked(u32 *dest, u32 __user *from)
90952 {
90953- int ret;
90954+ unsigned long ret;
90955
90956 pagefault_disable();
90957 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
90958@@ -3033,6 +3038,7 @@ static void __init futex_detect_cmpxchg(void)
90959 {
90960 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
90961 u32 curval;
90962+ mm_segment_t oldfs;
90963
90964 /*
90965 * This will fail and we want it. Some arch implementations do
90966@@ -3044,8 +3050,11 @@ static void __init futex_detect_cmpxchg(void)
90967 * implementation, the non-functional ones will return
90968 * -ENOSYS.
90969 */
90970+ oldfs = get_fs();
90971+ set_fs(USER_DS);
90972 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
90973 futex_cmpxchg_enabled = 1;
90974+ set_fs(oldfs);
90975 #endif
90976 }
90977
90978diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
90979index 55c8c93..9ba7ad6 100644
90980--- a/kernel/futex_compat.c
90981+++ b/kernel/futex_compat.c
90982@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
90983 return 0;
90984 }
90985
90986-static void __user *futex_uaddr(struct robust_list __user *entry,
90987+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
90988 compat_long_t futex_offset)
90989 {
90990 compat_uptr_t base = ptr_to_compat(entry);
90991diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
90992index b358a80..fc25240 100644
90993--- a/kernel/gcov/base.c
90994+++ b/kernel/gcov/base.c
90995@@ -114,11 +114,6 @@ void gcov_enable_events(void)
90996 }
90997
90998 #ifdef CONFIG_MODULES
90999-static inline int within(void *addr, void *start, unsigned long size)
91000-{
91001- return ((addr >= start) && (addr < start + size));
91002-}
91003-
91004 /* Update list and generate events when modules are unloaded. */
91005 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
91006 void *data)
91007@@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
91008
91009 /* Remove entries located in module from linked list. */
91010 while ((info = gcov_info_next(info))) {
91011- if (within(info, mod->module_core, mod->core_size)) {
91012+ if (within_module_core_rw((unsigned long)info, mod)) {
91013 gcov_info_unlink(prev, info);
91014 if (gcov_events_enabled)
91015 gcov_event(GCOV_REMOVE, info);
91016diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
91017index 3ab2899..c6ad010 100644
91018--- a/kernel/hrtimer.c
91019+++ b/kernel/hrtimer.c
91020@@ -1449,7 +1449,7 @@ void hrtimer_peek_ahead_timers(void)
91021 local_irq_restore(flags);
91022 }
91023
91024-static void run_hrtimer_softirq(struct softirq_action *h)
91025+static __latent_entropy void run_hrtimer_softirq(void)
91026 {
91027 hrtimer_peek_ahead_timers();
91028 }
91029diff --git a/kernel/irq_work.c b/kernel/irq_work.c
91030index a82170e..5b01e7f 100644
91031--- a/kernel/irq_work.c
91032+++ b/kernel/irq_work.c
91033@@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
91034 return NOTIFY_OK;
91035 }
91036
91037-static struct notifier_block cpu_notify;
91038+static struct notifier_block cpu_notify = {
91039+ .notifier_call = irq_work_cpu_notify,
91040+ .priority = 0,
91041+};
91042
91043 static __init int irq_work_init_cpu_notifier(void)
91044 {
91045- cpu_notify.notifier_call = irq_work_cpu_notify;
91046- cpu_notify.priority = 0;
91047 register_cpu_notifier(&cpu_notify);
91048 return 0;
91049 }
91050diff --git a/kernel/jump_label.c b/kernel/jump_label.c
91051index 9019f15..9a3c42e 100644
91052--- a/kernel/jump_label.c
91053+++ b/kernel/jump_label.c
91054@@ -14,6 +14,7 @@
91055 #include <linux/err.h>
91056 #include <linux/static_key.h>
91057 #include <linux/jump_label_ratelimit.h>
91058+#include <linux/mm.h>
91059
91060 #ifdef HAVE_JUMP_LABEL
91061
91062@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
91063
91064 size = (((unsigned long)stop - (unsigned long)start)
91065 / sizeof(struct jump_entry));
91066+ pax_open_kernel();
91067 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
91068+ pax_close_kernel();
91069 }
91070
91071 static void jump_label_update(struct static_key *key, int enable);
91072@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
91073 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
91074 struct jump_entry *iter;
91075
91076+ pax_open_kernel();
91077 for (iter = iter_start; iter < iter_stop; iter++) {
91078 if (within_module_init(iter->code, mod))
91079 iter->code = 0;
91080 }
91081+ pax_close_kernel();
91082 }
91083
91084 static int
91085diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
91086index cb0cf37..b69e161 100644
91087--- a/kernel/kallsyms.c
91088+++ b/kernel/kallsyms.c
91089@@ -11,6 +11,9 @@
91090 * Changed the compression method from stem compression to "table lookup"
91091 * compression (see scripts/kallsyms.c for a more complete description)
91092 */
91093+#ifdef CONFIG_GRKERNSEC_HIDESYM
91094+#define __INCLUDED_BY_HIDESYM 1
91095+#endif
91096 #include <linux/kallsyms.h>
91097 #include <linux/module.h>
91098 #include <linux/init.h>
91099@@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
91100
91101 static inline int is_kernel_inittext(unsigned long addr)
91102 {
91103+ if (system_state != SYSTEM_BOOTING)
91104+ return 0;
91105+
91106 if (addr >= (unsigned long)_sinittext
91107 && addr <= (unsigned long)_einittext)
91108 return 1;
91109 return 0;
91110 }
91111
91112+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91113+#ifdef CONFIG_MODULES
91114+static inline int is_module_text(unsigned long addr)
91115+{
91116+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
91117+ return 1;
91118+
91119+ addr = ktla_ktva(addr);
91120+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
91121+}
91122+#else
91123+static inline int is_module_text(unsigned long addr)
91124+{
91125+ return 0;
91126+}
91127+#endif
91128+#endif
91129+
91130 static inline int is_kernel_text(unsigned long addr)
91131 {
91132 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
91133@@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
91134
91135 static inline int is_kernel(unsigned long addr)
91136 {
91137+
91138+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91139+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
91140+ return 1;
91141+
91142+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
91143+#else
91144 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
91145+#endif
91146+
91147 return 1;
91148 return in_gate_area_no_mm(addr);
91149 }
91150
91151 static int is_ksym_addr(unsigned long addr)
91152 {
91153+
91154+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91155+ if (is_module_text(addr))
91156+ return 0;
91157+#endif
91158+
91159 if (all_var)
91160 return is_kernel(addr);
91161
91162@@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
91163
91164 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
91165 {
91166- iter->name[0] = '\0';
91167 iter->nameoff = get_symbol_offset(new_pos);
91168 iter->pos = new_pos;
91169 }
91170@@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
91171 {
91172 struct kallsym_iter *iter = m->private;
91173
91174+#ifdef CONFIG_GRKERNSEC_HIDESYM
91175+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
91176+ return 0;
91177+#endif
91178+
91179 /* Some debugging symbols have no name. Ignore them. */
91180 if (!iter->name[0])
91181 return 0;
91182@@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
91183 */
91184 type = iter->exported ? toupper(iter->type) :
91185 tolower(iter->type);
91186+
91187 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
91188 type, iter->name, iter->module_name);
91189 } else
91190@@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
91191 struct kallsym_iter *iter;
91192 int ret;
91193
91194- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
91195+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
91196 if (!iter)
91197 return -ENOMEM;
91198 reset_iter(iter, 0);
91199diff --git a/kernel/kcmp.c b/kernel/kcmp.c
91200index e30ac0f..3528cac 100644
91201--- a/kernel/kcmp.c
91202+++ b/kernel/kcmp.c
91203@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
91204 struct task_struct *task1, *task2;
91205 int ret;
91206
91207+#ifdef CONFIG_GRKERNSEC
91208+ return -ENOSYS;
91209+#endif
91210+
91211 rcu_read_lock();
91212
91213 /*
91214diff --git a/kernel/kexec.c b/kernel/kexec.c
91215index 4b8f0c9..fffd0df 100644
91216--- a/kernel/kexec.c
91217+++ b/kernel/kexec.c
91218@@ -1045,7 +1045,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
91219 compat_ulong_t, flags)
91220 {
91221 struct compat_kexec_segment in;
91222- struct kexec_segment out, __user *ksegments;
91223+ struct kexec_segment out;
91224+ struct kexec_segment __user *ksegments;
91225 unsigned long i, result;
91226
91227 /* Don't allow clients that don't understand the native
91228diff --git a/kernel/kmod.c b/kernel/kmod.c
91229index 8637e04..8b1d0d8 100644
91230--- a/kernel/kmod.c
91231+++ b/kernel/kmod.c
91232@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
91233 kfree(info->argv);
91234 }
91235
91236-static int call_modprobe(char *module_name, int wait)
91237+static int call_modprobe(char *module_name, char *module_param, int wait)
91238 {
91239 struct subprocess_info *info;
91240 static char *envp[] = {
91241@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
91242 NULL
91243 };
91244
91245- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
91246+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
91247 if (!argv)
91248 goto out;
91249
91250@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
91251 argv[1] = "-q";
91252 argv[2] = "--";
91253 argv[3] = module_name; /* check free_modprobe_argv() */
91254- argv[4] = NULL;
91255+ argv[4] = module_param;
91256+ argv[5] = NULL;
91257
91258 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
91259 NULL, free_modprobe_argv, NULL);
91260@@ -129,9 +130,8 @@ out:
91261 * If module auto-loading support is disabled then this function
91262 * becomes a no-operation.
91263 */
91264-int __request_module(bool wait, const char *fmt, ...)
91265+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
91266 {
91267- va_list args;
91268 char module_name[MODULE_NAME_LEN];
91269 unsigned int max_modprobes;
91270 int ret;
91271@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
91272 if (!modprobe_path[0])
91273 return 0;
91274
91275- va_start(args, fmt);
91276- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
91277- va_end(args);
91278+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
91279 if (ret >= MODULE_NAME_LEN)
91280 return -ENAMETOOLONG;
91281
91282@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
91283 if (ret)
91284 return ret;
91285
91286+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91287+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
91288+ /* hack to workaround consolekit/udisks stupidity */
91289+ read_lock(&tasklist_lock);
91290+ if (!strcmp(current->comm, "mount") &&
91291+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
91292+ read_unlock(&tasklist_lock);
91293+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
91294+ return -EPERM;
91295+ }
91296+ read_unlock(&tasklist_lock);
91297+ }
91298+#endif
91299+
91300 /* If modprobe needs a service that is in a module, we get a recursive
91301 * loop. Limit the number of running kmod threads to max_threads/2 or
91302 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
91303@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
91304
91305 trace_module_request(module_name, wait, _RET_IP_);
91306
91307- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
91308+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
91309
91310 atomic_dec(&kmod_concurrent);
91311 return ret;
91312 }
91313+
91314+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
91315+{
91316+ va_list args;
91317+ int ret;
91318+
91319+ va_start(args, fmt);
91320+ ret = ____request_module(wait, module_param, fmt, args);
91321+ va_end(args);
91322+
91323+ return ret;
91324+}
91325+
91326+int __request_module(bool wait, const char *fmt, ...)
91327+{
91328+ va_list args;
91329+ int ret;
91330+
91331+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91332+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
91333+ char module_param[MODULE_NAME_LEN];
91334+
91335+ memset(module_param, 0, sizeof(module_param));
91336+
91337+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
91338+
91339+ va_start(args, fmt);
91340+ ret = ____request_module(wait, module_param, fmt, args);
91341+ va_end(args);
91342+
91343+ return ret;
91344+ }
91345+#endif
91346+
91347+ va_start(args, fmt);
91348+ ret = ____request_module(wait, NULL, fmt, args);
91349+ va_end(args);
91350+
91351+ return ret;
91352+}
91353+
91354 EXPORT_SYMBOL(__request_module);
91355 #endif /* CONFIG_MODULES */
91356
91357@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
91358 */
91359 set_user_nice(current, 0);
91360
91361+#ifdef CONFIG_GRKERNSEC
91362+ /* this is race-free as far as userland is concerned as we copied
91363+ out the path to be used prior to this point and are now operating
91364+ on that copy
91365+ */
91366+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
91367+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
91368+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
91369+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
91370+ retval = -EPERM;
91371+ goto fail;
91372+ }
91373+#endif
91374+
91375 retval = -ENOMEM;
91376 new = prepare_kernel_cred(current);
91377 if (!new)
91378@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
91379 commit_creds(new);
91380
91381 retval = do_execve(getname_kernel(sub_info->path),
91382- (const char __user *const __user *)sub_info->argv,
91383- (const char __user *const __user *)sub_info->envp);
91384+ (const char __user *const __force_user *)sub_info->argv,
91385+ (const char __user *const __force_user *)sub_info->envp);
91386 if (!retval)
91387 return 0;
91388
91389@@ -260,6 +327,10 @@ static int call_helper(void *data)
91390
91391 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
91392 {
91393+#ifdef CONFIG_GRKERNSEC
91394+ kfree(info->path);
91395+ info->path = info->origpath;
91396+#endif
91397 if (info->cleanup)
91398 (*info->cleanup)(info);
91399 kfree(info);
91400@@ -300,7 +371,7 @@ static int wait_for_helper(void *data)
91401 *
91402 * Thus the __user pointer cast is valid here.
91403 */
91404- sys_wait4(pid, (int __user *)&ret, 0, NULL);
91405+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
91406
91407 /*
91408 * If ret is 0, either ____call_usermodehelper failed and the
91409@@ -539,7 +610,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
91410 goto out;
91411
91412 INIT_WORK(&sub_info->work, __call_usermodehelper);
91413+#ifdef CONFIG_GRKERNSEC
91414+ sub_info->origpath = path;
91415+ sub_info->path = kstrdup(path, gfp_mask);
91416+#else
91417 sub_info->path = path;
91418+#endif
91419 sub_info->argv = argv;
91420 sub_info->envp = envp;
91421
91422@@ -647,7 +723,7 @@ EXPORT_SYMBOL(call_usermodehelper);
91423 static int proc_cap_handler(struct ctl_table *table, int write,
91424 void __user *buffer, size_t *lenp, loff_t *ppos)
91425 {
91426- struct ctl_table t;
91427+ ctl_table_no_const t;
91428 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
91429 kernel_cap_t new_cap;
91430 int err, i;
91431diff --git a/kernel/kprobes.c b/kernel/kprobes.c
91432index 734e9a7..0a313b8 100644
91433--- a/kernel/kprobes.c
91434+++ b/kernel/kprobes.c
91435@@ -31,6 +31,9 @@
91436 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
91437 * <prasanna@in.ibm.com> added function-return probes.
91438 */
91439+#ifdef CONFIG_GRKERNSEC_HIDESYM
91440+#define __INCLUDED_BY_HIDESYM 1
91441+#endif
91442 #include <linux/kprobes.h>
91443 #include <linux/hash.h>
91444 #include <linux/init.h>
91445@@ -122,12 +125,12 @@ enum kprobe_slot_state {
91446
91447 static void *alloc_insn_page(void)
91448 {
91449- return module_alloc(PAGE_SIZE);
91450+ return module_alloc_exec(PAGE_SIZE);
91451 }
91452
91453 static void free_insn_page(void *page)
91454 {
91455- module_free(NULL, page);
91456+ module_free_exec(NULL, page);
91457 }
91458
91459 struct kprobe_insn_cache kprobe_insn_slots = {
91460@@ -2176,11 +2179,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
91461 kprobe_type = "k";
91462
91463 if (sym)
91464- seq_printf(pi, "%p %s %s+0x%x %s ",
91465+ seq_printf(pi, "%pK %s %s+0x%x %s ",
91466 p->addr, kprobe_type, sym, offset,
91467 (modname ? modname : " "));
91468 else
91469- seq_printf(pi, "%p %s %p ",
91470+ seq_printf(pi, "%pK %s %pK ",
91471 p->addr, kprobe_type, p->addr);
91472
91473 if (!pp)
91474diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
91475index 6683cce..daf8999 100644
91476--- a/kernel/ksysfs.c
91477+++ b/kernel/ksysfs.c
91478@@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
91479 {
91480 if (count+1 > UEVENT_HELPER_PATH_LEN)
91481 return -ENOENT;
91482+ if (!capable(CAP_SYS_ADMIN))
91483+ return -EPERM;
91484 memcpy(uevent_helper, buf, count);
91485 uevent_helper[count] = '\0';
91486 if (count && uevent_helper[count-1] == '\n')
91487@@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
91488 return count;
91489 }
91490
91491-static struct bin_attribute notes_attr = {
91492+static bin_attribute_no_const notes_attr __read_only = {
91493 .attr = {
91494 .name = "notes",
91495 .mode = S_IRUGO,
91496diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
91497index d24e433..fa04fb8 100644
91498--- a/kernel/locking/lockdep.c
91499+++ b/kernel/locking/lockdep.c
91500@@ -597,6 +597,10 @@ static int static_obj(void *obj)
91501 end = (unsigned long) &_end,
91502 addr = (unsigned long) obj;
91503
91504+#ifdef CONFIG_PAX_KERNEXEC
91505+ start = ktla_ktva(start);
91506+#endif
91507+
91508 /*
91509 * static variable?
91510 */
91511@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
91512 if (!static_obj(lock->key)) {
91513 debug_locks_off();
91514 printk("INFO: trying to register non-static key.\n");
91515+ printk("lock:%pS key:%pS.\n", lock, lock->key);
91516 printk("the code is fine but needs lockdep annotation.\n");
91517 printk("turning off the locking correctness validator.\n");
91518 dump_stack();
91519@@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
91520 if (!class)
91521 return 0;
91522 }
91523- atomic_inc((atomic_t *)&class->ops);
91524+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
91525 if (very_verbose(class)) {
91526 printk("\nacquire class [%p] %s", class->key, class->name);
91527 if (class->name_version > 1)
91528diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
91529index ef43ac4..2720dfa 100644
91530--- a/kernel/locking/lockdep_proc.c
91531+++ b/kernel/locking/lockdep_proc.c
91532@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
91533 return 0;
91534 }
91535
91536- seq_printf(m, "%p", class->key);
91537+ seq_printf(m, "%pK", class->key);
91538 #ifdef CONFIG_DEBUG_LOCKDEP
91539 seq_printf(m, " OPS:%8ld", class->ops);
91540 #endif
91541@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
91542
91543 list_for_each_entry(entry, &class->locks_after, entry) {
91544 if (entry->distance == 1) {
91545- seq_printf(m, " -> [%p] ", entry->class->key);
91546+ seq_printf(m, " -> [%pK] ", entry->class->key);
91547 print_name(m, entry->class);
91548 seq_puts(m, "\n");
91549 }
91550@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
91551 if (!class->key)
91552 continue;
91553
91554- seq_printf(m, "[%p] ", class->key);
91555+ seq_printf(m, "[%pK] ", class->key);
91556 print_name(m, class);
91557 seq_puts(m, "\n");
91558 }
91559@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
91560 if (!i)
91561 seq_line(m, '-', 40-namelen, namelen);
91562
91563- snprintf(ip, sizeof(ip), "[<%p>]",
91564+ snprintf(ip, sizeof(ip), "[<%pK>]",
91565 (void *)class->contention_point[i]);
91566 seq_printf(m, "%40s %14lu %29s %pS\n",
91567 name, stats->contention_point[i],
91568@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
91569 if (!i)
91570 seq_line(m, '-', 40-namelen, namelen);
91571
91572- snprintf(ip, sizeof(ip), "[<%p>]",
91573+ snprintf(ip, sizeof(ip), "[<%pK>]",
91574 (void *)class->contending_point[i]);
91575 seq_printf(m, "%40s %14lu %29s %pS\n",
91576 name, stats->contending_point[i],
91577diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
91578index be9ee15..39d6233 100644
91579--- a/kernel/locking/mcs_spinlock.c
91580+++ b/kernel/locking/mcs_spinlock.c
91581@@ -102,7 +102,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
91582
91583 prev = decode_cpu(old);
91584 node->prev = prev;
91585- ACCESS_ONCE(prev->next) = node;
91586+ ACCESS_ONCE_RW(prev->next) = node;
91587
91588 /*
91589 * Normally @prev is untouchable after the above store; because at that
91590@@ -174,8 +174,8 @@ unqueue:
91591 * it will wait in Step-A.
91592 */
91593
91594- ACCESS_ONCE(next->prev) = prev;
91595- ACCESS_ONCE(prev->next) = next;
91596+ ACCESS_ONCE_RW(next->prev) = prev;
91597+ ACCESS_ONCE_RW(prev->next) = next;
91598
91599 return false;
91600 }
91601@@ -197,13 +197,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
91602 node = this_cpu_ptr(&osq_node);
91603 next = xchg(&node->next, NULL);
91604 if (next) {
91605- ACCESS_ONCE(next->locked) = 1;
91606+ ACCESS_ONCE_RW(next->locked) = 1;
91607 return;
91608 }
91609
91610 next = osq_wait_next(lock, node, NULL);
91611 if (next)
91612- ACCESS_ONCE(next->locked) = 1;
91613+ ACCESS_ONCE_RW(next->locked) = 1;
91614 }
91615
91616 #endif
91617diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
91618index 74356dc..48dd5e1 100644
91619--- a/kernel/locking/mcs_spinlock.h
91620+++ b/kernel/locking/mcs_spinlock.h
91621@@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
91622 */
91623 return;
91624 }
91625- ACCESS_ONCE(prev->next) = node;
91626+ ACCESS_ONCE_RW(prev->next) = node;
91627
91628 /* Wait until the lock holder passes the lock down. */
91629 arch_mcs_spin_lock_contended(&node->locked);
91630diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
91631index 5cf6731..ce3bc5a 100644
91632--- a/kernel/locking/mutex-debug.c
91633+++ b/kernel/locking/mutex-debug.c
91634@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
91635 }
91636
91637 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
91638- struct thread_info *ti)
91639+ struct task_struct *task)
91640 {
91641 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
91642
91643 /* Mark the current thread as blocked on the lock: */
91644- ti->task->blocked_on = waiter;
91645+ task->blocked_on = waiter;
91646 }
91647
91648 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
91649- struct thread_info *ti)
91650+ struct task_struct *task)
91651 {
91652 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
91653- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
91654- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
91655- ti->task->blocked_on = NULL;
91656+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
91657+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
91658+ task->blocked_on = NULL;
91659
91660 list_del_init(&waiter->list);
91661 waiter->task = NULL;
91662diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
91663index 0799fd3..d06ae3b 100644
91664--- a/kernel/locking/mutex-debug.h
91665+++ b/kernel/locking/mutex-debug.h
91666@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
91667 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
91668 extern void debug_mutex_add_waiter(struct mutex *lock,
91669 struct mutex_waiter *waiter,
91670- struct thread_info *ti);
91671+ struct task_struct *task);
91672 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
91673- struct thread_info *ti);
91674+ struct task_struct *task);
91675 extern void debug_mutex_unlock(struct mutex *lock);
91676 extern void debug_mutex_init(struct mutex *lock, const char *name,
91677 struct lock_class_key *key);
91678diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
91679index acca2c1..ddeaea8 100644
91680--- a/kernel/locking/mutex.c
91681+++ b/kernel/locking/mutex.c
91682@@ -490,7 +490,7 @@ slowpath:
91683 goto skip_wait;
91684
91685 debug_mutex_lock_common(lock, &waiter);
91686- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
91687+ debug_mutex_add_waiter(lock, &waiter, task);
91688
91689 /* add waiting tasks to the end of the waitqueue (FIFO): */
91690 list_add_tail(&waiter.list, &lock->wait_list);
91691@@ -534,7 +534,7 @@ slowpath:
91692 schedule_preempt_disabled();
91693 spin_lock_mutex(&lock->wait_lock, flags);
91694 }
91695- mutex_remove_waiter(lock, &waiter, current_thread_info());
91696+ mutex_remove_waiter(lock, &waiter, task);
91697 /* set it to 0 if there are no waiters left: */
91698 if (likely(list_empty(&lock->wait_list)))
91699 atomic_set(&lock->count, 0);
91700@@ -571,7 +571,7 @@ skip_wait:
91701 return 0;
91702
91703 err:
91704- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
91705+ mutex_remove_waiter(lock, &waiter, task);
91706 spin_unlock_mutex(&lock->wait_lock, flags);
91707 debug_mutex_free_waiter(&waiter);
91708 mutex_release(&lock->dep_map, 1, ip);
91709diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
91710index 1d96dd0..994ff19 100644
91711--- a/kernel/locking/rtmutex-tester.c
91712+++ b/kernel/locking/rtmutex-tester.c
91713@@ -22,7 +22,7 @@
91714 #define MAX_RT_TEST_MUTEXES 8
91715
91716 static spinlock_t rttest_lock;
91717-static atomic_t rttest_event;
91718+static atomic_unchecked_t rttest_event;
91719
91720 struct test_thread_data {
91721 int opcode;
91722@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91723
91724 case RTTEST_LOCKCONT:
91725 td->mutexes[td->opdata] = 1;
91726- td->event = atomic_add_return(1, &rttest_event);
91727+ td->event = atomic_add_return_unchecked(1, &rttest_event);
91728 return 0;
91729
91730 case RTTEST_RESET:
91731@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91732 return 0;
91733
91734 case RTTEST_RESETEVENT:
91735- atomic_set(&rttest_event, 0);
91736+ atomic_set_unchecked(&rttest_event, 0);
91737 return 0;
91738
91739 default:
91740@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91741 return ret;
91742
91743 td->mutexes[id] = 1;
91744- td->event = atomic_add_return(1, &rttest_event);
91745+ td->event = atomic_add_return_unchecked(1, &rttest_event);
91746 rt_mutex_lock(&mutexes[id]);
91747- td->event = atomic_add_return(1, &rttest_event);
91748+ td->event = atomic_add_return_unchecked(1, &rttest_event);
91749 td->mutexes[id] = 4;
91750 return 0;
91751
91752@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91753 return ret;
91754
91755 td->mutexes[id] = 1;
91756- td->event = atomic_add_return(1, &rttest_event);
91757+ td->event = atomic_add_return_unchecked(1, &rttest_event);
91758 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
91759- td->event = atomic_add_return(1, &rttest_event);
91760+ td->event = atomic_add_return_unchecked(1, &rttest_event);
91761 td->mutexes[id] = ret ? 0 : 4;
91762 return ret ? -EINTR : 0;
91763
91764@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91765 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
91766 return ret;
91767
91768- td->event = atomic_add_return(1, &rttest_event);
91769+ td->event = atomic_add_return_unchecked(1, &rttest_event);
91770 rt_mutex_unlock(&mutexes[id]);
91771- td->event = atomic_add_return(1, &rttest_event);
91772+ td->event = atomic_add_return_unchecked(1, &rttest_event);
91773 td->mutexes[id] = 0;
91774 return 0;
91775
91776@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
91777 break;
91778
91779 td->mutexes[dat] = 2;
91780- td->event = atomic_add_return(1, &rttest_event);
91781+ td->event = atomic_add_return_unchecked(1, &rttest_event);
91782 break;
91783
91784 default:
91785@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
91786 return;
91787
91788 td->mutexes[dat] = 3;
91789- td->event = atomic_add_return(1, &rttest_event);
91790+ td->event = atomic_add_return_unchecked(1, &rttest_event);
91791 break;
91792
91793 case RTTEST_LOCKNOWAIT:
91794@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
91795 return;
91796
91797 td->mutexes[dat] = 1;
91798- td->event = atomic_add_return(1, &rttest_event);
91799+ td->event = atomic_add_return_unchecked(1, &rttest_event);
91800 return;
91801
91802 default:
91803diff --git a/kernel/module.c b/kernel/module.c
91804index 81e727c..a8ea6f9 100644
91805--- a/kernel/module.c
91806+++ b/kernel/module.c
91807@@ -61,6 +61,7 @@
91808 #include <linux/pfn.h>
91809 #include <linux/bsearch.h>
91810 #include <linux/fips.h>
91811+#include <linux/grsecurity.h>
91812 #include <uapi/linux/module.h>
91813 #include "module-internal.h"
91814
91815@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
91816
91817 /* Bounds of module allocation, for speeding __module_address.
91818 * Protected by module_mutex. */
91819-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
91820+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
91821+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
91822
91823 int register_module_notifier(struct notifier_block * nb)
91824 {
91825@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
91826 return true;
91827
91828 list_for_each_entry_rcu(mod, &modules, list) {
91829- struct symsearch arr[] = {
91830+ struct symsearch modarr[] = {
91831 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
91832 NOT_GPL_ONLY, false },
91833 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
91834@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
91835 if (mod->state == MODULE_STATE_UNFORMED)
91836 continue;
91837
91838- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
91839+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
91840 return true;
91841 }
91842 return false;
91843@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
91844 if (!pcpusec->sh_size)
91845 return 0;
91846
91847- if (align > PAGE_SIZE) {
91848+ if (align-1 >= PAGE_SIZE) {
91849 pr_warn("%s: per-cpu alignment %li > %li\n",
91850 mod->name, align, PAGE_SIZE);
91851 align = PAGE_SIZE;
91852@@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
91853 static ssize_t show_coresize(struct module_attribute *mattr,
91854 struct module_kobject *mk, char *buffer)
91855 {
91856- return sprintf(buffer, "%u\n", mk->mod->core_size);
91857+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
91858 }
91859
91860 static struct module_attribute modinfo_coresize =
91861@@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
91862 static ssize_t show_initsize(struct module_attribute *mattr,
91863 struct module_kobject *mk, char *buffer)
91864 {
91865- return sprintf(buffer, "%u\n", mk->mod->init_size);
91866+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
91867 }
91868
91869 static struct module_attribute modinfo_initsize =
91870@@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
91871 goto bad_version;
91872 }
91873
91874+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91875+ /*
91876+ * avoid potentially printing jibberish on attempted load
91877+ * of a module randomized with a different seed
91878+ */
91879+ pr_warn("no symbol version for %s\n", symname);
91880+#else
91881 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
91882+#endif
91883 return 0;
91884
91885 bad_version:
91886+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91887+ /*
91888+ * avoid potentially printing jibberish on attempted load
91889+ * of a module randomized with a different seed
91890+ */
91891+ printk("attempted module disagrees about version of symbol %s\n",
91892+ symname);
91893+#else
91894 printk("%s: disagrees about version of symbol %s\n",
91895 mod->name, symname);
91896+#endif
91897 return 0;
91898 }
91899
91900@@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
91901 */
91902 #ifdef CONFIG_SYSFS
91903
91904-#ifdef CONFIG_KALLSYMS
91905+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
91906 static inline bool sect_empty(const Elf_Shdr *sect)
91907 {
91908 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
91909@@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
91910 {
91911 unsigned int notes, loaded, i;
91912 struct module_notes_attrs *notes_attrs;
91913- struct bin_attribute *nattr;
91914+ bin_attribute_no_const *nattr;
91915
91916 /* failed to create section attributes, so can't create notes */
91917 if (!mod->sect_attrs)
91918@@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
91919 static int module_add_modinfo_attrs(struct module *mod)
91920 {
91921 struct module_attribute *attr;
91922- struct module_attribute *temp_attr;
91923+ module_attribute_no_const *temp_attr;
91924 int error = 0;
91925 int i;
91926
91927@@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
91928
91929 static void unset_module_core_ro_nx(struct module *mod)
91930 {
91931- set_page_attributes(mod->module_core + mod->core_text_size,
91932- mod->module_core + mod->core_size,
91933+ set_page_attributes(mod->module_core_rw,
91934+ mod->module_core_rw + mod->core_size_rw,
91935 set_memory_x);
91936- set_page_attributes(mod->module_core,
91937- mod->module_core + mod->core_ro_size,
91938+ set_page_attributes(mod->module_core_rx,
91939+ mod->module_core_rx + mod->core_size_rx,
91940 set_memory_rw);
91941 }
91942
91943 static void unset_module_init_ro_nx(struct module *mod)
91944 {
91945- set_page_attributes(mod->module_init + mod->init_text_size,
91946- mod->module_init + mod->init_size,
91947+ set_page_attributes(mod->module_init_rw,
91948+ mod->module_init_rw + mod->init_size_rw,
91949 set_memory_x);
91950- set_page_attributes(mod->module_init,
91951- mod->module_init + mod->init_ro_size,
91952+ set_page_attributes(mod->module_init_rx,
91953+ mod->module_init_rx + mod->init_size_rx,
91954 set_memory_rw);
91955 }
91956
91957@@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
91958 list_for_each_entry_rcu(mod, &modules, list) {
91959 if (mod->state == MODULE_STATE_UNFORMED)
91960 continue;
91961- if ((mod->module_core) && (mod->core_text_size)) {
91962- set_page_attributes(mod->module_core,
91963- mod->module_core + mod->core_text_size,
91964+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
91965+ set_page_attributes(mod->module_core_rx,
91966+ mod->module_core_rx + mod->core_size_rx,
91967 set_memory_rw);
91968 }
91969- if ((mod->module_init) && (mod->init_text_size)) {
91970- set_page_attributes(mod->module_init,
91971- mod->module_init + mod->init_text_size,
91972+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
91973+ set_page_attributes(mod->module_init_rx,
91974+ mod->module_init_rx + mod->init_size_rx,
91975 set_memory_rw);
91976 }
91977 }
91978@@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
91979 list_for_each_entry_rcu(mod, &modules, list) {
91980 if (mod->state == MODULE_STATE_UNFORMED)
91981 continue;
91982- if ((mod->module_core) && (mod->core_text_size)) {
91983- set_page_attributes(mod->module_core,
91984- mod->module_core + mod->core_text_size,
91985+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
91986+ set_page_attributes(mod->module_core_rx,
91987+ mod->module_core_rx + mod->core_size_rx,
91988 set_memory_ro);
91989 }
91990- if ((mod->module_init) && (mod->init_text_size)) {
91991- set_page_attributes(mod->module_init,
91992- mod->module_init + mod->init_text_size,
91993+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
91994+ set_page_attributes(mod->module_init_rx,
91995+ mod->module_init_rx + mod->init_size_rx,
91996 set_memory_ro);
91997 }
91998 }
91999@@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
92000
92001 /* This may be NULL, but that's OK */
92002 unset_module_init_ro_nx(mod);
92003- module_free(mod, mod->module_init);
92004+ module_free(mod, mod->module_init_rw);
92005+ module_free_exec(mod, mod->module_init_rx);
92006 kfree(mod->args);
92007 percpu_modfree(mod);
92008
92009 /* Free lock-classes: */
92010- lockdep_free_key_range(mod->module_core, mod->core_size);
92011+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
92012+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
92013
92014 /* Finally, free the core (containing the module structure) */
92015 unset_module_core_ro_nx(mod);
92016- module_free(mod, mod->module_core);
92017+ module_free_exec(mod, mod->module_core_rx);
92018+ module_free(mod, mod->module_core_rw);
92019
92020 #ifdef CONFIG_MPU
92021 update_protections(current->mm);
92022@@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
92023 int ret = 0;
92024 const struct kernel_symbol *ksym;
92025
92026+#ifdef CONFIG_GRKERNSEC_MODHARDEN
92027+ int is_fs_load = 0;
92028+ int register_filesystem_found = 0;
92029+ char *p;
92030+
92031+ p = strstr(mod->args, "grsec_modharden_fs");
92032+ if (p) {
92033+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
92034+ /* copy \0 as well */
92035+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
92036+ is_fs_load = 1;
92037+ }
92038+#endif
92039+
92040 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
92041 const char *name = info->strtab + sym[i].st_name;
92042
92043+#ifdef CONFIG_GRKERNSEC_MODHARDEN
92044+ /* it's a real shame this will never get ripped and copied
92045+ upstream! ;(
92046+ */
92047+ if (is_fs_load && !strcmp(name, "register_filesystem"))
92048+ register_filesystem_found = 1;
92049+#endif
92050+
92051 switch (sym[i].st_shndx) {
92052 case SHN_COMMON:
92053 /* Ignore common symbols */
92054@@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
92055 ksym = resolve_symbol_wait(mod, info, name);
92056 /* Ok if resolved. */
92057 if (ksym && !IS_ERR(ksym)) {
92058+ pax_open_kernel();
92059 sym[i].st_value = ksym->value;
92060+ pax_close_kernel();
92061 break;
92062 }
92063
92064@@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
92065 secbase = (unsigned long)mod_percpu(mod);
92066 else
92067 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
92068+ pax_open_kernel();
92069 sym[i].st_value += secbase;
92070+ pax_close_kernel();
92071 break;
92072 }
92073 }
92074
92075+#ifdef CONFIG_GRKERNSEC_MODHARDEN
92076+ if (is_fs_load && !register_filesystem_found) {
92077+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
92078+ ret = -EPERM;
92079+ }
92080+#endif
92081+
92082 return ret;
92083 }
92084
92085@@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
92086 || s->sh_entsize != ~0UL
92087 || strstarts(sname, ".init"))
92088 continue;
92089- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
92090+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
92091+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
92092+ else
92093+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
92094 pr_debug("\t%s\n", sname);
92095 }
92096- switch (m) {
92097- case 0: /* executable */
92098- mod->core_size = debug_align(mod->core_size);
92099- mod->core_text_size = mod->core_size;
92100- break;
92101- case 1: /* RO: text and ro-data */
92102- mod->core_size = debug_align(mod->core_size);
92103- mod->core_ro_size = mod->core_size;
92104- break;
92105- case 3: /* whole core */
92106- mod->core_size = debug_align(mod->core_size);
92107- break;
92108- }
92109 }
92110
92111 pr_debug("Init section allocation order:\n");
92112@@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
92113 || s->sh_entsize != ~0UL
92114 || !strstarts(sname, ".init"))
92115 continue;
92116- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
92117- | INIT_OFFSET_MASK);
92118+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
92119+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
92120+ else
92121+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
92122+ s->sh_entsize |= INIT_OFFSET_MASK;
92123 pr_debug("\t%s\n", sname);
92124 }
92125- switch (m) {
92126- case 0: /* executable */
92127- mod->init_size = debug_align(mod->init_size);
92128- mod->init_text_size = mod->init_size;
92129- break;
92130- case 1: /* RO: text and ro-data */
92131- mod->init_size = debug_align(mod->init_size);
92132- mod->init_ro_size = mod->init_size;
92133- break;
92134- case 3: /* whole init */
92135- mod->init_size = debug_align(mod->init_size);
92136- break;
92137- }
92138 }
92139 }
92140
92141@@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
92142
92143 /* Put symbol section at end of init part of module. */
92144 symsect->sh_flags |= SHF_ALLOC;
92145- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
92146+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
92147 info->index.sym) | INIT_OFFSET_MASK;
92148 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
92149
92150@@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
92151 }
92152
92153 /* Append room for core symbols at end of core part. */
92154- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
92155- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
92156- mod->core_size += strtab_size;
92157+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
92158+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
92159+ mod->core_size_rx += strtab_size;
92160
92161 /* Put string table section at end of init part of module. */
92162 strsect->sh_flags |= SHF_ALLOC;
92163- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
92164+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
92165 info->index.str) | INIT_OFFSET_MASK;
92166 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
92167 }
92168@@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
92169 /* Make sure we get permanent strtab: don't use info->strtab. */
92170 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
92171
92172+ pax_open_kernel();
92173+
92174 /* Set types up while we still have access to sections. */
92175 for (i = 0; i < mod->num_symtab; i++)
92176 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
92177
92178- mod->core_symtab = dst = mod->module_core + info->symoffs;
92179- mod->core_strtab = s = mod->module_core + info->stroffs;
92180+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
92181+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
92182 src = mod->symtab;
92183 for (ndst = i = 0; i < mod->num_symtab; i++) {
92184 if (i == 0 ||
92185@@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
92186 }
92187 }
92188 mod->core_num_syms = ndst;
92189+
92190+ pax_close_kernel();
92191 }
92192 #else
92193 static inline void layout_symtab(struct module *mod, struct load_info *info)
92194@@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
92195 return vmalloc_exec(size);
92196 }
92197
92198-static void *module_alloc_update_bounds(unsigned long size)
92199+static void *module_alloc_update_bounds_rw(unsigned long size)
92200 {
92201 void *ret = module_alloc(size);
92202
92203 if (ret) {
92204 mutex_lock(&module_mutex);
92205 /* Update module bounds. */
92206- if ((unsigned long)ret < module_addr_min)
92207- module_addr_min = (unsigned long)ret;
92208- if ((unsigned long)ret + size > module_addr_max)
92209- module_addr_max = (unsigned long)ret + size;
92210+ if ((unsigned long)ret < module_addr_min_rw)
92211+ module_addr_min_rw = (unsigned long)ret;
92212+ if ((unsigned long)ret + size > module_addr_max_rw)
92213+ module_addr_max_rw = (unsigned long)ret + size;
92214+ mutex_unlock(&module_mutex);
92215+ }
92216+ return ret;
92217+}
92218+
92219+static void *module_alloc_update_bounds_rx(unsigned long size)
92220+{
92221+ void *ret = module_alloc_exec(size);
92222+
92223+ if (ret) {
92224+ mutex_lock(&module_mutex);
92225+ /* Update module bounds. */
92226+ if ((unsigned long)ret < module_addr_min_rx)
92227+ module_addr_min_rx = (unsigned long)ret;
92228+ if ((unsigned long)ret + size > module_addr_max_rx)
92229+ module_addr_max_rx = (unsigned long)ret + size;
92230 mutex_unlock(&module_mutex);
92231 }
92232 return ret;
92233@@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
92234 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
92235
92236 if (info->index.sym == 0) {
92237+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
92238+ /*
92239+ * avoid potentially printing jibberish on attempted load
92240+ * of a module randomized with a different seed
92241+ */
92242+ pr_warn("module has no symbols (stripped?)\n");
92243+#else
92244 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
92245+#endif
92246 return ERR_PTR(-ENOEXEC);
92247 }
92248
92249@@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
92250 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
92251 {
92252 const char *modmagic = get_modinfo(info, "vermagic");
92253+ const char *license = get_modinfo(info, "license");
92254 int err;
92255
92256+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
92257+ if (!license || !license_is_gpl_compatible(license))
92258+ return -ENOEXEC;
92259+#endif
92260+
92261 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
92262 modmagic = NULL;
92263
92264@@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
92265 }
92266
92267 /* Set up license info based on the info section */
92268- set_license(mod, get_modinfo(info, "license"));
92269+ set_license(mod, license);
92270
92271 return 0;
92272 }
92273@@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
92274 void *ptr;
92275
92276 /* Do the allocs. */
92277- ptr = module_alloc_update_bounds(mod->core_size);
92278+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
92279 /*
92280 * The pointer to this block is stored in the module structure
92281 * which is inside the block. Just mark it as not being a
92282@@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
92283 if (!ptr)
92284 return -ENOMEM;
92285
92286- memset(ptr, 0, mod->core_size);
92287- mod->module_core = ptr;
92288+ memset(ptr, 0, mod->core_size_rw);
92289+ mod->module_core_rw = ptr;
92290
92291- if (mod->init_size) {
92292- ptr = module_alloc_update_bounds(mod->init_size);
92293+ if (mod->init_size_rw) {
92294+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
92295 /*
92296 * The pointer to this block is stored in the module structure
92297 * which is inside the block. This block doesn't need to be
92298@@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
92299 */
92300 kmemleak_ignore(ptr);
92301 if (!ptr) {
92302- module_free(mod, mod->module_core);
92303+ module_free(mod, mod->module_core_rw);
92304 return -ENOMEM;
92305 }
92306- memset(ptr, 0, mod->init_size);
92307- mod->module_init = ptr;
92308+ memset(ptr, 0, mod->init_size_rw);
92309+ mod->module_init_rw = ptr;
92310 } else
92311- mod->module_init = NULL;
92312+ mod->module_init_rw = NULL;
92313+
92314+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
92315+ kmemleak_not_leak(ptr);
92316+ if (!ptr) {
92317+ if (mod->module_init_rw)
92318+ module_free(mod, mod->module_init_rw);
92319+ module_free(mod, mod->module_core_rw);
92320+ return -ENOMEM;
92321+ }
92322+
92323+ pax_open_kernel();
92324+ memset(ptr, 0, mod->core_size_rx);
92325+ pax_close_kernel();
92326+ mod->module_core_rx = ptr;
92327+
92328+ if (mod->init_size_rx) {
92329+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
92330+ kmemleak_ignore(ptr);
92331+ if (!ptr && mod->init_size_rx) {
92332+ module_free_exec(mod, mod->module_core_rx);
92333+ if (mod->module_init_rw)
92334+ module_free(mod, mod->module_init_rw);
92335+ module_free(mod, mod->module_core_rw);
92336+ return -ENOMEM;
92337+ }
92338+
92339+ pax_open_kernel();
92340+ memset(ptr, 0, mod->init_size_rx);
92341+ pax_close_kernel();
92342+ mod->module_init_rx = ptr;
92343+ } else
92344+ mod->module_init_rx = NULL;
92345
92346 /* Transfer each section which specifies SHF_ALLOC */
92347 pr_debug("final section addresses:\n");
92348@@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
92349 if (!(shdr->sh_flags & SHF_ALLOC))
92350 continue;
92351
92352- if (shdr->sh_entsize & INIT_OFFSET_MASK)
92353- dest = mod->module_init
92354- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
92355- else
92356- dest = mod->module_core + shdr->sh_entsize;
92357+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
92358+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
92359+ dest = mod->module_init_rw
92360+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
92361+ else
92362+ dest = mod->module_init_rx
92363+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
92364+ } else {
92365+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
92366+ dest = mod->module_core_rw + shdr->sh_entsize;
92367+ else
92368+ dest = mod->module_core_rx + shdr->sh_entsize;
92369+ }
92370+
92371+ if (shdr->sh_type != SHT_NOBITS) {
92372+
92373+#ifdef CONFIG_PAX_KERNEXEC
92374+#ifdef CONFIG_X86_64
92375+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
92376+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
92377+#endif
92378+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
92379+ pax_open_kernel();
92380+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
92381+ pax_close_kernel();
92382+ } else
92383+#endif
92384
92385- if (shdr->sh_type != SHT_NOBITS)
92386 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
92387+ }
92388 /* Update sh_addr to point to copy in image. */
92389- shdr->sh_addr = (unsigned long)dest;
92390+
92391+#ifdef CONFIG_PAX_KERNEXEC
92392+ if (shdr->sh_flags & SHF_EXECINSTR)
92393+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
92394+ else
92395+#endif
92396+
92397+ shdr->sh_addr = (unsigned long)dest;
92398 pr_debug("\t0x%lx %s\n",
92399 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
92400 }
92401@@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
92402 * Do it before processing of module parameters, so the module
92403 * can provide parameter accessor functions of its own.
92404 */
92405- if (mod->module_init)
92406- flush_icache_range((unsigned long)mod->module_init,
92407- (unsigned long)mod->module_init
92408- + mod->init_size);
92409- flush_icache_range((unsigned long)mod->module_core,
92410- (unsigned long)mod->module_core + mod->core_size);
92411+ if (mod->module_init_rx)
92412+ flush_icache_range((unsigned long)mod->module_init_rx,
92413+ (unsigned long)mod->module_init_rx
92414+ + mod->init_size_rx);
92415+ flush_icache_range((unsigned long)mod->module_core_rx,
92416+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
92417
92418 set_fs(old_fs);
92419 }
92420@@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
92421 static void module_deallocate(struct module *mod, struct load_info *info)
92422 {
92423 percpu_modfree(mod);
92424- module_free(mod, mod->module_init);
92425- module_free(mod, mod->module_core);
92426+ module_free_exec(mod, mod->module_init_rx);
92427+ module_free_exec(mod, mod->module_core_rx);
92428+ module_free(mod, mod->module_init_rw);
92429+ module_free(mod, mod->module_core_rw);
92430 }
92431
92432 int __weak module_finalize(const Elf_Ehdr *hdr,
92433@@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
92434 static int post_relocation(struct module *mod, const struct load_info *info)
92435 {
92436 /* Sort exception table now relocations are done. */
92437+ pax_open_kernel();
92438 sort_extable(mod->extable, mod->extable + mod->num_exentries);
92439+ pax_close_kernel();
92440
92441 /* Copy relocated percpu area over. */
92442 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
92443@@ -3079,11 +3213,12 @@ static int do_init_module(struct module *mod)
92444 mod->strtab = mod->core_strtab;
92445 #endif
92446 unset_module_init_ro_nx(mod);
92447- module_free(mod, mod->module_init);
92448- mod->module_init = NULL;
92449- mod->init_size = 0;
92450- mod->init_ro_size = 0;
92451- mod->init_text_size = 0;
92452+ module_free(mod, mod->module_init_rw);
92453+ module_free_exec(mod, mod->module_init_rx);
92454+ mod->module_init_rw = NULL;
92455+ mod->module_init_rx = NULL;
92456+ mod->init_size_rw = 0;
92457+ mod->init_size_rx = 0;
92458 mutex_unlock(&module_mutex);
92459 wake_up_all(&module_wq);
92460
92461@@ -3151,16 +3286,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
92462 module_bug_finalize(info->hdr, info->sechdrs, mod);
92463
92464 /* Set RO and NX regions for core */
92465- set_section_ro_nx(mod->module_core,
92466- mod->core_text_size,
92467- mod->core_ro_size,
92468- mod->core_size);
92469+ set_section_ro_nx(mod->module_core_rx,
92470+ mod->core_size_rx,
92471+ mod->core_size_rx,
92472+ mod->core_size_rx);
92473
92474 /* Set RO and NX regions for init */
92475- set_section_ro_nx(mod->module_init,
92476- mod->init_text_size,
92477- mod->init_ro_size,
92478- mod->init_size);
92479+ set_section_ro_nx(mod->module_init_rx,
92480+ mod->init_size_rx,
92481+ mod->init_size_rx,
92482+ mod->init_size_rx);
92483
92484 /* Mark state as coming so strong_try_module_get() ignores us,
92485 * but kallsyms etc. can see us. */
92486@@ -3244,9 +3379,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
92487 if (err)
92488 goto free_unload;
92489
92490+ /* Now copy in args */
92491+ mod->args = strndup_user(uargs, ~0UL >> 1);
92492+ if (IS_ERR(mod->args)) {
92493+ err = PTR_ERR(mod->args);
92494+ goto free_unload;
92495+ }
92496+
92497 /* Set up MODINFO_ATTR fields */
92498 setup_modinfo(mod, info);
92499
92500+#ifdef CONFIG_GRKERNSEC_MODHARDEN
92501+ {
92502+ char *p, *p2;
92503+
92504+ if (strstr(mod->args, "grsec_modharden_netdev")) {
92505+ printk(KERN_ALERT "grsec: denied auto-loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%.64s instead.", mod->name);
92506+ err = -EPERM;
92507+ goto free_modinfo;
92508+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
92509+ p += sizeof("grsec_modharden_normal") - 1;
92510+ p2 = strstr(p, "_");
92511+ if (p2) {
92512+ *p2 = '\0';
92513+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
92514+ *p2 = '_';
92515+ }
92516+ err = -EPERM;
92517+ goto free_modinfo;
92518+ }
92519+ }
92520+#endif
92521+
92522 /* Fix up syms, so that st_value is a pointer to location. */
92523 err = simplify_symbols(mod, info);
92524 if (err < 0)
92525@@ -3262,13 +3426,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
92526
92527 flush_module_icache(mod);
92528
92529- /* Now copy in args */
92530- mod->args = strndup_user(uargs, ~0UL >> 1);
92531- if (IS_ERR(mod->args)) {
92532- err = PTR_ERR(mod->args);
92533- goto free_arch_cleanup;
92534- }
92535-
92536 dynamic_debug_setup(info->debug, info->num_debug);
92537
92538 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
92539@@ -3311,11 +3468,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
92540 ddebug_cleanup:
92541 dynamic_debug_remove(info->debug);
92542 synchronize_sched();
92543- kfree(mod->args);
92544- free_arch_cleanup:
92545 module_arch_cleanup(mod);
92546 free_modinfo:
92547 free_modinfo(mod);
92548+ kfree(mod->args);
92549 free_unload:
92550 module_unload_free(mod);
92551 unlink_mod:
92552@@ -3398,10 +3554,16 @@ static const char *get_ksymbol(struct module *mod,
92553 unsigned long nextval;
92554
92555 /* At worse, next value is at end of module */
92556- if (within_module_init(addr, mod))
92557- nextval = (unsigned long)mod->module_init+mod->init_text_size;
92558+ if (within_module_init_rx(addr, mod))
92559+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
92560+ else if (within_module_init_rw(addr, mod))
92561+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
92562+ else if (within_module_core_rx(addr, mod))
92563+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
92564+ else if (within_module_core_rw(addr, mod))
92565+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
92566 else
92567- nextval = (unsigned long)mod->module_core+mod->core_text_size;
92568+ return NULL;
92569
92570 /* Scan for closest preceding symbol, and next symbol. (ELF
92571 starts real symbols at 1). */
92572@@ -3652,7 +3814,7 @@ static int m_show(struct seq_file *m, void *p)
92573 return 0;
92574
92575 seq_printf(m, "%s %u",
92576- mod->name, mod->init_size + mod->core_size);
92577+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
92578 print_unload_info(m, mod);
92579
92580 /* Informative for users. */
92581@@ -3661,7 +3823,7 @@ static int m_show(struct seq_file *m, void *p)
92582 mod->state == MODULE_STATE_COMING ? "Loading":
92583 "Live");
92584 /* Used by oprofile and other similar tools. */
92585- seq_printf(m, " 0x%pK", mod->module_core);
92586+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
92587
92588 /* Taints info */
92589 if (mod->taints)
92590@@ -3697,7 +3859,17 @@ static const struct file_operations proc_modules_operations = {
92591
92592 static int __init proc_modules_init(void)
92593 {
92594+#ifndef CONFIG_GRKERNSEC_HIDESYM
92595+#ifdef CONFIG_GRKERNSEC_PROC_USER
92596+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
92597+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92598+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
92599+#else
92600 proc_create("modules", 0, NULL, &proc_modules_operations);
92601+#endif
92602+#else
92603+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
92604+#endif
92605 return 0;
92606 }
92607 module_init(proc_modules_init);
92608@@ -3758,14 +3930,14 @@ struct module *__module_address(unsigned long addr)
92609 {
92610 struct module *mod;
92611
92612- if (addr < module_addr_min || addr > module_addr_max)
92613+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
92614+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
92615 return NULL;
92616
92617 list_for_each_entry_rcu(mod, &modules, list) {
92618 if (mod->state == MODULE_STATE_UNFORMED)
92619 continue;
92620- if (within_module_core(addr, mod)
92621- || within_module_init(addr, mod))
92622+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
92623 return mod;
92624 }
92625 return NULL;
92626@@ -3800,11 +3972,20 @@ bool is_module_text_address(unsigned long addr)
92627 */
92628 struct module *__module_text_address(unsigned long addr)
92629 {
92630- struct module *mod = __module_address(addr);
92631+ struct module *mod;
92632+
92633+#ifdef CONFIG_X86_32
92634+ addr = ktla_ktva(addr);
92635+#endif
92636+
92637+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
92638+ return NULL;
92639+
92640+ mod = __module_address(addr);
92641+
92642 if (mod) {
92643 /* Make sure it's within the text section. */
92644- if (!within(addr, mod->module_init, mod->init_text_size)
92645- && !within(addr, mod->module_core, mod->core_text_size))
92646+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
92647 mod = NULL;
92648 }
92649 return mod;
92650diff --git a/kernel/notifier.c b/kernel/notifier.c
92651index 4803da6..1c5eea6 100644
92652--- a/kernel/notifier.c
92653+++ b/kernel/notifier.c
92654@@ -5,6 +5,7 @@
92655 #include <linux/rcupdate.h>
92656 #include <linux/vmalloc.h>
92657 #include <linux/reboot.h>
92658+#include <linux/mm.h>
92659
92660 /*
92661 * Notifier list for kernel code which wants to be called
92662@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
92663 while ((*nl) != NULL) {
92664 if (n->priority > (*nl)->priority)
92665 break;
92666- nl = &((*nl)->next);
92667+ nl = (struct notifier_block **)&((*nl)->next);
92668 }
92669- n->next = *nl;
92670+ pax_open_kernel();
92671+ *(const void **)&n->next = *nl;
92672 rcu_assign_pointer(*nl, n);
92673+ pax_close_kernel();
92674 return 0;
92675 }
92676
92677@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
92678 return 0;
92679 if (n->priority > (*nl)->priority)
92680 break;
92681- nl = &((*nl)->next);
92682+ nl = (struct notifier_block **)&((*nl)->next);
92683 }
92684- n->next = *nl;
92685+ pax_open_kernel();
92686+ *(const void **)&n->next = *nl;
92687 rcu_assign_pointer(*nl, n);
92688+ pax_close_kernel();
92689 return 0;
92690 }
92691
92692@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
92693 {
92694 while ((*nl) != NULL) {
92695 if ((*nl) == n) {
92696+ pax_open_kernel();
92697 rcu_assign_pointer(*nl, n->next);
92698+ pax_close_kernel();
92699 return 0;
92700 }
92701- nl = &((*nl)->next);
92702+ nl = (struct notifier_block **)&((*nl)->next);
92703 }
92704 return -ENOENT;
92705 }
92706diff --git a/kernel/padata.c b/kernel/padata.c
92707index 161402f..598814c 100644
92708--- a/kernel/padata.c
92709+++ b/kernel/padata.c
92710@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
92711 * seq_nr mod. number of cpus in use.
92712 */
92713
92714- seq_nr = atomic_inc_return(&pd->seq_nr);
92715+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
92716 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
92717
92718 return padata_index_to_cpu(pd, cpu_index);
92719@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
92720 padata_init_pqueues(pd);
92721 padata_init_squeues(pd);
92722 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
92723- atomic_set(&pd->seq_nr, -1);
92724+ atomic_set_unchecked(&pd->seq_nr, -1);
92725 atomic_set(&pd->reorder_objects, 0);
92726 atomic_set(&pd->refcnt, 0);
92727 pd->pinst = pinst;
92728diff --git a/kernel/panic.c b/kernel/panic.c
92729index 62e16ce..9db5047b 100644
92730--- a/kernel/panic.c
92731+++ b/kernel/panic.c
92732@@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
92733 /*
92734 * Stop ourself in panic -- architecture code may override this
92735 */
92736-void __weak panic_smp_self_stop(void)
92737+void __weak __noreturn panic_smp_self_stop(void)
92738 {
92739 while (1)
92740 cpu_relax();
92741@@ -420,7 +420,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
92742 disable_trace_on_warning();
92743
92744 pr_warn("------------[ cut here ]------------\n");
92745- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
92746+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
92747 raw_smp_processor_id(), current->pid, file, line, caller);
92748
92749 if (args)
92750@@ -474,7 +474,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
92751 */
92752 __visible void __stack_chk_fail(void)
92753 {
92754- panic("stack-protector: Kernel stack is corrupted in: %p\n",
92755+ dump_stack();
92756+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
92757 __builtin_return_address(0));
92758 }
92759 EXPORT_SYMBOL(__stack_chk_fail);
92760diff --git a/kernel/pid.c b/kernel/pid.c
92761index 9b9a266..c20ef80 100644
92762--- a/kernel/pid.c
92763+++ b/kernel/pid.c
92764@@ -33,6 +33,7 @@
92765 #include <linux/rculist.h>
92766 #include <linux/bootmem.h>
92767 #include <linux/hash.h>
92768+#include <linux/security.h>
92769 #include <linux/pid_namespace.h>
92770 #include <linux/init_task.h>
92771 #include <linux/syscalls.h>
92772@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
92773
92774 int pid_max = PID_MAX_DEFAULT;
92775
92776-#define RESERVED_PIDS 300
92777+#define RESERVED_PIDS 500
92778
92779 int pid_max_min = RESERVED_PIDS + 1;
92780 int pid_max_max = PID_MAX_LIMIT;
92781@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
92782 */
92783 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
92784 {
92785+ struct task_struct *task;
92786+
92787 rcu_lockdep_assert(rcu_read_lock_held(),
92788 "find_task_by_pid_ns() needs rcu_read_lock()"
92789 " protection");
92790- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
92791+
92792+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
92793+
92794+ if (gr_pid_is_chrooted(task))
92795+ return NULL;
92796+
92797+ return task;
92798 }
92799
92800 struct task_struct *find_task_by_vpid(pid_t vnr)
92801@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
92802 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
92803 }
92804
92805+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
92806+{
92807+ rcu_lockdep_assert(rcu_read_lock_held(),
92808+ "find_task_by_pid_ns() needs rcu_read_lock()"
92809+ " protection");
92810+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
92811+}
92812+
92813 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
92814 {
92815 struct pid *pid;
92816diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
92817index db95d8e..a0ca23f 100644
92818--- a/kernel/pid_namespace.c
92819+++ b/kernel/pid_namespace.c
92820@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
92821 void __user *buffer, size_t *lenp, loff_t *ppos)
92822 {
92823 struct pid_namespace *pid_ns = task_active_pid_ns(current);
92824- struct ctl_table tmp = *table;
92825+ ctl_table_no_const tmp = *table;
92826
92827 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
92828 return -EPERM;
92829diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
92830index 3b89464..5e38379 100644
92831--- a/kernel/posix-cpu-timers.c
92832+++ b/kernel/posix-cpu-timers.c
92833@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
92834
92835 static __init int init_posix_cpu_timers(void)
92836 {
92837- struct k_clock process = {
92838+ static struct k_clock process = {
92839 .clock_getres = process_cpu_clock_getres,
92840 .clock_get = process_cpu_clock_get,
92841 .timer_create = process_cpu_timer_create,
92842 .nsleep = process_cpu_nsleep,
92843 .nsleep_restart = process_cpu_nsleep_restart,
92844 };
92845- struct k_clock thread = {
92846+ static struct k_clock thread = {
92847 .clock_getres = thread_cpu_clock_getres,
92848 .clock_get = thread_cpu_clock_get,
92849 .timer_create = thread_cpu_timer_create,
92850diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
92851index 424c2d4..679242f 100644
92852--- a/kernel/posix-timers.c
92853+++ b/kernel/posix-timers.c
92854@@ -43,6 +43,7 @@
92855 #include <linux/hash.h>
92856 #include <linux/posix-clock.h>
92857 #include <linux/posix-timers.h>
92858+#include <linux/grsecurity.h>
92859 #include <linux/syscalls.h>
92860 #include <linux/wait.h>
92861 #include <linux/workqueue.h>
92862@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
92863 * which we beg off on and pass to do_sys_settimeofday().
92864 */
92865
92866-static struct k_clock posix_clocks[MAX_CLOCKS];
92867+static struct k_clock *posix_clocks[MAX_CLOCKS];
92868
92869 /*
92870 * These ones are defined below.
92871@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
92872 */
92873 static __init int init_posix_timers(void)
92874 {
92875- struct k_clock clock_realtime = {
92876+ static struct k_clock clock_realtime = {
92877 .clock_getres = hrtimer_get_res,
92878 .clock_get = posix_clock_realtime_get,
92879 .clock_set = posix_clock_realtime_set,
92880@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
92881 .timer_get = common_timer_get,
92882 .timer_del = common_timer_del,
92883 };
92884- struct k_clock clock_monotonic = {
92885+ static struct k_clock clock_monotonic = {
92886 .clock_getres = hrtimer_get_res,
92887 .clock_get = posix_ktime_get_ts,
92888 .nsleep = common_nsleep,
92889@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
92890 .timer_get = common_timer_get,
92891 .timer_del = common_timer_del,
92892 };
92893- struct k_clock clock_monotonic_raw = {
92894+ static struct k_clock clock_monotonic_raw = {
92895 .clock_getres = hrtimer_get_res,
92896 .clock_get = posix_get_monotonic_raw,
92897 };
92898- struct k_clock clock_realtime_coarse = {
92899+ static struct k_clock clock_realtime_coarse = {
92900 .clock_getres = posix_get_coarse_res,
92901 .clock_get = posix_get_realtime_coarse,
92902 };
92903- struct k_clock clock_monotonic_coarse = {
92904+ static struct k_clock clock_monotonic_coarse = {
92905 .clock_getres = posix_get_coarse_res,
92906 .clock_get = posix_get_monotonic_coarse,
92907 };
92908- struct k_clock clock_tai = {
92909+ static struct k_clock clock_tai = {
92910 .clock_getres = hrtimer_get_res,
92911 .clock_get = posix_get_tai,
92912 .nsleep = common_nsleep,
92913@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
92914 .timer_get = common_timer_get,
92915 .timer_del = common_timer_del,
92916 };
92917- struct k_clock clock_boottime = {
92918+ static struct k_clock clock_boottime = {
92919 .clock_getres = hrtimer_get_res,
92920 .clock_get = posix_get_boottime,
92921 .nsleep = common_nsleep,
92922@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
92923 return;
92924 }
92925
92926- posix_clocks[clock_id] = *new_clock;
92927+ posix_clocks[clock_id] = new_clock;
92928 }
92929 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
92930
92931@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
92932 return (id & CLOCKFD_MASK) == CLOCKFD ?
92933 &clock_posix_dynamic : &clock_posix_cpu;
92934
92935- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
92936+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
92937 return NULL;
92938- return &posix_clocks[id];
92939+ return posix_clocks[id];
92940 }
92941
92942 static int common_timer_create(struct k_itimer *new_timer)
92943@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
92944 struct k_clock *kc = clockid_to_kclock(which_clock);
92945 struct k_itimer *new_timer;
92946 int error, new_timer_id;
92947- sigevent_t event;
92948+ sigevent_t event = { };
92949 int it_id_set = IT_ID_NOT_SET;
92950
92951 if (!kc)
92952@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
92953 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
92954 return -EFAULT;
92955
92956+ /* only the CLOCK_REALTIME clock can be set, all other clocks
92957+ have their clock_set fptr set to a nosettime dummy function
92958+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
92959+ call common_clock_set, which calls do_sys_settimeofday, which
92960+ we hook
92961+ */
92962+
92963 return kc->clock_set(which_clock, &new_tp);
92964 }
92965
92966diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
92967index 9a83d78..128bfc0 100644
92968--- a/kernel/power/Kconfig
92969+++ b/kernel/power/Kconfig
92970@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
92971 config HIBERNATION
92972 bool "Hibernation (aka 'suspend to disk')"
92973 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
92974+ depends on !GRKERNSEC_KMEM
92975+ depends on !PAX_MEMORY_SANITIZE
92976 select HIBERNATE_CALLBACKS
92977 select LZO_COMPRESS
92978 select LZO_DECOMPRESS
92979diff --git a/kernel/power/process.c b/kernel/power/process.c
92980index 4ee194e..925778f 100644
92981--- a/kernel/power/process.c
92982+++ b/kernel/power/process.c
92983@@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
92984 unsigned int elapsed_msecs;
92985 bool wakeup = false;
92986 int sleep_usecs = USEC_PER_MSEC;
92987+ bool timedout = false;
92988
92989 do_gettimeofday(&start);
92990
92991@@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
92992
92993 while (true) {
92994 todo = 0;
92995+ if (time_after(jiffies, end_time))
92996+ timedout = true;
92997 read_lock(&tasklist_lock);
92998 do_each_thread(g, p) {
92999 if (p == current || !freeze_task(p))
93000 continue;
93001
93002- if (!freezer_should_skip(p))
93003+ if (!freezer_should_skip(p)) {
93004 todo++;
93005+ if (timedout) {
93006+ printk(KERN_ERR "Task refusing to freeze:\n");
93007+ sched_show_task(p);
93008+ }
93009+ }
93010 } while_each_thread(g, p);
93011 read_unlock(&tasklist_lock);
93012
93013@@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
93014 todo += wq_busy;
93015 }
93016
93017- if (!todo || time_after(jiffies, end_time))
93018+ if (!todo || timedout)
93019 break;
93020
93021 if (pm_wakeup_pending()) {
93022diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
93023index 13e839d..8a71f12 100644
93024--- a/kernel/printk/printk.c
93025+++ b/kernel/printk/printk.c
93026@@ -480,6 +480,11 @@ static int check_syslog_permissions(int type, bool from_file)
93027 if (from_file && type != SYSLOG_ACTION_OPEN)
93028 return 0;
93029
93030+#ifdef CONFIG_GRKERNSEC_DMESG
93031+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
93032+ return -EPERM;
93033+#endif
93034+
93035 if (syslog_action_restricted(type)) {
93036 if (capable(CAP_SYSLOG))
93037 return 0;
93038diff --git a/kernel/profile.c b/kernel/profile.c
93039index 54bf5ba..df6e0a2 100644
93040--- a/kernel/profile.c
93041+++ b/kernel/profile.c
93042@@ -37,7 +37,7 @@ struct profile_hit {
93043 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
93044 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
93045
93046-static atomic_t *prof_buffer;
93047+static atomic_unchecked_t *prof_buffer;
93048 static unsigned long prof_len, prof_shift;
93049
93050 int prof_on __read_mostly;
93051@@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
93052 hits[i].pc = 0;
93053 continue;
93054 }
93055- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
93056+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
93057 hits[i].hits = hits[i].pc = 0;
93058 }
93059 }
93060@@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
93061 * Add the current hit(s) and flush the write-queue out
93062 * to the global buffer:
93063 */
93064- atomic_add(nr_hits, &prof_buffer[pc]);
93065+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
93066 for (i = 0; i < NR_PROFILE_HIT; ++i) {
93067- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
93068+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
93069 hits[i].pc = hits[i].hits = 0;
93070 }
93071 out:
93072@@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
93073 {
93074 unsigned long pc;
93075 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
93076- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
93077+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
93078 }
93079 #endif /* !CONFIG_SMP */
93080
93081@@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
93082 return -EFAULT;
93083 buf++; p++; count--; read++;
93084 }
93085- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
93086+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
93087 if (copy_to_user(buf, (void *)pnt, count))
93088 return -EFAULT;
93089 read += count;
93090@@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
93091 }
93092 #endif
93093 profile_discard_flip_buffers();
93094- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
93095+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
93096 return count;
93097 }
93098
93099diff --git a/kernel/ptrace.c b/kernel/ptrace.c
93100index adf9862..9d86345 100644
93101--- a/kernel/ptrace.c
93102+++ b/kernel/ptrace.c
93103@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
93104 if (seize)
93105 flags |= PT_SEIZED;
93106 rcu_read_lock();
93107- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
93108+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
93109 flags |= PT_PTRACE_CAP;
93110 rcu_read_unlock();
93111 task->ptrace = flags;
93112@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
93113 break;
93114 return -EIO;
93115 }
93116- if (copy_to_user(dst, buf, retval))
93117+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
93118 return -EFAULT;
93119 copied += retval;
93120 src += retval;
93121@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
93122 bool seized = child->ptrace & PT_SEIZED;
93123 int ret = -EIO;
93124 siginfo_t siginfo, *si;
93125- void __user *datavp = (void __user *) data;
93126+ void __user *datavp = (__force void __user *) data;
93127 unsigned long __user *datalp = datavp;
93128 unsigned long flags;
93129
93130@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
93131 goto out;
93132 }
93133
93134+ if (gr_handle_ptrace(child, request)) {
93135+ ret = -EPERM;
93136+ goto out_put_task_struct;
93137+ }
93138+
93139 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
93140 ret = ptrace_attach(child, request, addr, data);
93141 /*
93142 * Some architectures need to do book-keeping after
93143 * a ptrace attach.
93144 */
93145- if (!ret)
93146+ if (!ret) {
93147 arch_ptrace_attach(child);
93148+ gr_audit_ptrace(child);
93149+ }
93150 goto out_put_task_struct;
93151 }
93152
93153@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
93154 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
93155 if (copied != sizeof(tmp))
93156 return -EIO;
93157- return put_user(tmp, (unsigned long __user *)data);
93158+ return put_user(tmp, (__force unsigned long __user *)data);
93159 }
93160
93161 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
93162@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
93163 }
93164
93165 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
93166- compat_long_t, addr, compat_long_t, data)
93167+ compat_ulong_t, addr, compat_ulong_t, data)
93168 {
93169 struct task_struct *child;
93170 long ret;
93171@@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
93172 goto out;
93173 }
93174
93175+ if (gr_handle_ptrace(child, request)) {
93176+ ret = -EPERM;
93177+ goto out_put_task_struct;
93178+ }
93179+
93180 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
93181 ret = ptrace_attach(child, request, addr, data);
93182 /*
93183 * Some architectures need to do book-keeping after
93184 * a ptrace attach.
93185 */
93186- if (!ret)
93187+ if (!ret) {
93188 arch_ptrace_attach(child);
93189+ gr_audit_ptrace(child);
93190+ }
93191 goto out_put_task_struct;
93192 }
93193
93194diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
93195index 948a769..5ca842b 100644
93196--- a/kernel/rcu/rcutorture.c
93197+++ b/kernel/rcu/rcutorture.c
93198@@ -124,12 +124,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
93199 rcu_torture_count) = { 0 };
93200 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
93201 rcu_torture_batch) = { 0 };
93202-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
93203-static atomic_t n_rcu_torture_alloc;
93204-static atomic_t n_rcu_torture_alloc_fail;
93205-static atomic_t n_rcu_torture_free;
93206-static atomic_t n_rcu_torture_mberror;
93207-static atomic_t n_rcu_torture_error;
93208+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
93209+static atomic_unchecked_t n_rcu_torture_alloc;
93210+static atomic_unchecked_t n_rcu_torture_alloc_fail;
93211+static atomic_unchecked_t n_rcu_torture_free;
93212+static atomic_unchecked_t n_rcu_torture_mberror;
93213+static atomic_unchecked_t n_rcu_torture_error;
93214 static long n_rcu_torture_barrier_error;
93215 static long n_rcu_torture_boost_ktrerror;
93216 static long n_rcu_torture_boost_rterror;
93217@@ -200,11 +200,11 @@ rcu_torture_alloc(void)
93218
93219 spin_lock_bh(&rcu_torture_lock);
93220 if (list_empty(&rcu_torture_freelist)) {
93221- atomic_inc(&n_rcu_torture_alloc_fail);
93222+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
93223 spin_unlock_bh(&rcu_torture_lock);
93224 return NULL;
93225 }
93226- atomic_inc(&n_rcu_torture_alloc);
93227+ atomic_inc_unchecked(&n_rcu_torture_alloc);
93228 p = rcu_torture_freelist.next;
93229 list_del_init(p);
93230 spin_unlock_bh(&rcu_torture_lock);
93231@@ -217,7 +217,7 @@ rcu_torture_alloc(void)
93232 static void
93233 rcu_torture_free(struct rcu_torture *p)
93234 {
93235- atomic_inc(&n_rcu_torture_free);
93236+ atomic_inc_unchecked(&n_rcu_torture_free);
93237 spin_lock_bh(&rcu_torture_lock);
93238 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
93239 spin_unlock_bh(&rcu_torture_lock);
93240@@ -301,7 +301,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
93241 i = rp->rtort_pipe_count;
93242 if (i > RCU_TORTURE_PIPE_LEN)
93243 i = RCU_TORTURE_PIPE_LEN;
93244- atomic_inc(&rcu_torture_wcount[i]);
93245+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
93246 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
93247 rp->rtort_mbtest = 0;
93248 return true;
93249@@ -808,7 +808,7 @@ rcu_torture_writer(void *arg)
93250 i = old_rp->rtort_pipe_count;
93251 if (i > RCU_TORTURE_PIPE_LEN)
93252 i = RCU_TORTURE_PIPE_LEN;
93253- atomic_inc(&rcu_torture_wcount[i]);
93254+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
93255 old_rp->rtort_pipe_count++;
93256 switch (synctype[torture_random(&rand) % nsynctypes]) {
93257 case RTWS_DEF_FREE:
93258@@ -926,7 +926,7 @@ static void rcu_torture_timer(unsigned long unused)
93259 return;
93260 }
93261 if (p->rtort_mbtest == 0)
93262- atomic_inc(&n_rcu_torture_mberror);
93263+ atomic_inc_unchecked(&n_rcu_torture_mberror);
93264 spin_lock(&rand_lock);
93265 cur_ops->read_delay(&rand);
93266 n_rcu_torture_timers++;
93267@@ -996,7 +996,7 @@ rcu_torture_reader(void *arg)
93268 continue;
93269 }
93270 if (p->rtort_mbtest == 0)
93271- atomic_inc(&n_rcu_torture_mberror);
93272+ atomic_inc_unchecked(&n_rcu_torture_mberror);
93273 cur_ops->read_delay(&rand);
93274 preempt_disable();
93275 pipe_count = p->rtort_pipe_count;
93276@@ -1054,15 +1054,15 @@ rcu_torture_printk(char *page)
93277 }
93278 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
93279 page += sprintf(page,
93280- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
93281+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
93282 rcu_torture_current,
93283 rcu_torture_current_version,
93284 list_empty(&rcu_torture_freelist),
93285- atomic_read(&n_rcu_torture_alloc),
93286- atomic_read(&n_rcu_torture_alloc_fail),
93287- atomic_read(&n_rcu_torture_free));
93288+ atomic_read_unchecked(&n_rcu_torture_alloc),
93289+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
93290+ atomic_read_unchecked(&n_rcu_torture_free));
93291 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
93292- atomic_read(&n_rcu_torture_mberror),
93293+ atomic_read_unchecked(&n_rcu_torture_mberror),
93294 n_rcu_torture_boost_ktrerror,
93295 n_rcu_torture_boost_rterror);
93296 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
93297@@ -1075,14 +1075,14 @@ rcu_torture_printk(char *page)
93298 n_barrier_attempts,
93299 n_rcu_torture_barrier_error);
93300 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
93301- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
93302+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
93303 n_rcu_torture_barrier_error != 0 ||
93304 n_rcu_torture_boost_ktrerror != 0 ||
93305 n_rcu_torture_boost_rterror != 0 ||
93306 n_rcu_torture_boost_failure != 0 ||
93307 i > 1) {
93308 page += sprintf(page, "!!! ");
93309- atomic_inc(&n_rcu_torture_error);
93310+ atomic_inc_unchecked(&n_rcu_torture_error);
93311 WARN_ON_ONCE(1);
93312 }
93313 page += sprintf(page, "Reader Pipe: ");
93314@@ -1096,7 +1096,7 @@ rcu_torture_printk(char *page)
93315 page += sprintf(page, "Free-Block Circulation: ");
93316 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
93317 page += sprintf(page, " %d",
93318- atomic_read(&rcu_torture_wcount[i]));
93319+ atomic_read_unchecked(&rcu_torture_wcount[i]));
93320 }
93321 page += sprintf(page, "\n");
93322 if (cur_ops->stats)
93323@@ -1461,7 +1461,7 @@ rcu_torture_cleanup(void)
93324
93325 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
93326
93327- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
93328+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
93329 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
93330 else if (torture_onoff_failures())
93331 rcu_torture_print_module_parms(cur_ops,
93332@@ -1584,18 +1584,18 @@ rcu_torture_init(void)
93333
93334 rcu_torture_current = NULL;
93335 rcu_torture_current_version = 0;
93336- atomic_set(&n_rcu_torture_alloc, 0);
93337- atomic_set(&n_rcu_torture_alloc_fail, 0);
93338- atomic_set(&n_rcu_torture_free, 0);
93339- atomic_set(&n_rcu_torture_mberror, 0);
93340- atomic_set(&n_rcu_torture_error, 0);
93341+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
93342+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
93343+ atomic_set_unchecked(&n_rcu_torture_free, 0);
93344+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
93345+ atomic_set_unchecked(&n_rcu_torture_error, 0);
93346 n_rcu_torture_barrier_error = 0;
93347 n_rcu_torture_boost_ktrerror = 0;
93348 n_rcu_torture_boost_rterror = 0;
93349 n_rcu_torture_boost_failure = 0;
93350 n_rcu_torture_boosts = 0;
93351 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
93352- atomic_set(&rcu_torture_wcount[i], 0);
93353+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
93354 for_each_possible_cpu(cpu) {
93355 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
93356 per_cpu(rcu_torture_count, cpu)[i] = 0;
93357diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
93358index c639556..cf0a0d5 100644
93359--- a/kernel/rcu/srcu.c
93360+++ b/kernel/rcu/srcu.c
93361@@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
93362
93363 idx = ACCESS_ONCE(sp->completed) & 0x1;
93364 preempt_disable();
93365- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
93366+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
93367 smp_mb(); /* B */ /* Avoid leaking the critical section. */
93368- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
93369+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
93370 preempt_enable();
93371 return idx;
93372 }
93373diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
93374index d9efcc1..ea543e9 100644
93375--- a/kernel/rcu/tiny.c
93376+++ b/kernel/rcu/tiny.c
93377@@ -42,7 +42,7 @@
93378 /* Forward declarations for tiny_plugin.h. */
93379 struct rcu_ctrlblk;
93380 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
93381-static void rcu_process_callbacks(struct softirq_action *unused);
93382+static void rcu_process_callbacks(void);
93383 static void __call_rcu(struct rcu_head *head,
93384 void (*func)(struct rcu_head *rcu),
93385 struct rcu_ctrlblk *rcp);
93386@@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
93387 false));
93388 }
93389
93390-static void rcu_process_callbacks(struct softirq_action *unused)
93391+static __latent_entropy void rcu_process_callbacks(void)
93392 {
93393 __rcu_process_callbacks(&rcu_sched_ctrlblk);
93394 __rcu_process_callbacks(&rcu_bh_ctrlblk);
93395diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
93396index 858c565..7efd915 100644
93397--- a/kernel/rcu/tiny_plugin.h
93398+++ b/kernel/rcu/tiny_plugin.h
93399@@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
93400 dump_stack();
93401 }
93402 if (*rcp->curtail && ULONG_CMP_GE(j, js))
93403- ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
93404+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
93405 3 * rcu_jiffies_till_stall_check() + 3;
93406 else if (ULONG_CMP_GE(j, js))
93407- ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
93408+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
93409 }
93410
93411 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
93412 {
93413 rcp->ticks_this_gp = 0;
93414 rcp->gp_start = jiffies;
93415- ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
93416+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
93417 }
93418
93419 static void check_cpu_stalls(void)
93420diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
93421index 625d0b0..0bce4d6 100644
93422--- a/kernel/rcu/tree.c
93423+++ b/kernel/rcu/tree.c
93424@@ -263,7 +263,7 @@ static void rcu_momentary_dyntick_idle(void)
93425 */
93426 rdtp = this_cpu_ptr(&rcu_dynticks);
93427 smp_mb__before_atomic(); /* Earlier stuff before QS. */
93428- atomic_add(2, &rdtp->dynticks); /* QS. */
93429+ atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
93430 smp_mb__after_atomic(); /* Later stuff after QS. */
93431 break;
93432 }
93433@@ -523,9 +523,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
93434 rcu_prepare_for_idle(smp_processor_id());
93435 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
93436 smp_mb__before_atomic(); /* See above. */
93437- atomic_inc(&rdtp->dynticks);
93438+ atomic_inc_unchecked(&rdtp->dynticks);
93439 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
93440- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
93441+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
93442
93443 /*
93444 * It is illegal to enter an extended quiescent state while
93445@@ -643,10 +643,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
93446 int user)
93447 {
93448 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
93449- atomic_inc(&rdtp->dynticks);
93450+ atomic_inc_unchecked(&rdtp->dynticks);
93451 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
93452 smp_mb__after_atomic(); /* See above. */
93453- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
93454+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
93455 rcu_cleanup_after_idle(smp_processor_id());
93456 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
93457 if (!user && !is_idle_task(current)) {
93458@@ -767,14 +767,14 @@ void rcu_nmi_enter(void)
93459 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
93460
93461 if (rdtp->dynticks_nmi_nesting == 0 &&
93462- (atomic_read(&rdtp->dynticks) & 0x1))
93463+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
93464 return;
93465 rdtp->dynticks_nmi_nesting++;
93466 smp_mb__before_atomic(); /* Force delay from prior write. */
93467- atomic_inc(&rdtp->dynticks);
93468+ atomic_inc_unchecked(&rdtp->dynticks);
93469 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
93470 smp_mb__after_atomic(); /* See above. */
93471- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
93472+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
93473 }
93474
93475 /**
93476@@ -793,9 +793,9 @@ void rcu_nmi_exit(void)
93477 return;
93478 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
93479 smp_mb__before_atomic(); /* See above. */
93480- atomic_inc(&rdtp->dynticks);
93481+ atomic_inc_unchecked(&rdtp->dynticks);
93482 smp_mb__after_atomic(); /* Force delay to next write. */
93483- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
93484+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
93485 }
93486
93487 /**
93488@@ -808,7 +808,7 @@ void rcu_nmi_exit(void)
93489 */
93490 bool notrace __rcu_is_watching(void)
93491 {
93492- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
93493+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
93494 }
93495
93496 /**
93497@@ -891,7 +891,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
93498 static int dyntick_save_progress_counter(struct rcu_data *rdp,
93499 bool *isidle, unsigned long *maxj)
93500 {
93501- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
93502+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
93503 rcu_sysidle_check_cpu(rdp, isidle, maxj);
93504 if ((rdp->dynticks_snap & 0x1) == 0) {
93505 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
93506@@ -920,7 +920,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
93507 int *rcrmp;
93508 unsigned int snap;
93509
93510- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
93511+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
93512 snap = (unsigned int)rdp->dynticks_snap;
93513
93514 /*
93515@@ -983,10 +983,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
93516 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
93517 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
93518 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
93519- ACCESS_ONCE(rdp->cond_resched_completed) =
93520+ ACCESS_ONCE_RW(rdp->cond_resched_completed) =
93521 ACCESS_ONCE(rdp->mynode->completed);
93522 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
93523- ACCESS_ONCE(*rcrmp) =
93524+ ACCESS_ONCE_RW(*rcrmp) =
93525 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
93526 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
93527 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
93528@@ -1008,7 +1008,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
93529 rsp->gp_start = j;
93530 smp_wmb(); /* Record start time before stall time. */
93531 j1 = rcu_jiffies_till_stall_check();
93532- ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
93533+ ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
93534 rsp->jiffies_resched = j + j1 / 2;
93535 }
93536
93537@@ -1052,7 +1052,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
93538 raw_spin_unlock_irqrestore(&rnp->lock, flags);
93539 return;
93540 }
93541- ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
93542+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
93543 raw_spin_unlock_irqrestore(&rnp->lock, flags);
93544
93545 /*
93546@@ -1130,7 +1130,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
93547
93548 raw_spin_lock_irqsave(&rnp->lock, flags);
93549 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
93550- ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
93551+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
93552 3 * rcu_jiffies_till_stall_check() + 3;
93553 raw_spin_unlock_irqrestore(&rnp->lock, flags);
93554
93555@@ -1214,7 +1214,7 @@ void rcu_cpu_stall_reset(void)
93556 struct rcu_state *rsp;
93557
93558 for_each_rcu_flavor(rsp)
93559- ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
93560+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
93561 }
93562
93563 /*
93564@@ -1594,7 +1594,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
93565 raw_spin_unlock_irq(&rnp->lock);
93566 return 0;
93567 }
93568- ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
93569+ ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
93570
93571 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
93572 /*
93573@@ -1635,9 +1635,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
93574 rdp = this_cpu_ptr(rsp->rda);
93575 rcu_preempt_check_blocked_tasks(rnp);
93576 rnp->qsmask = rnp->qsmaskinit;
93577- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
93578+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
93579 WARN_ON_ONCE(rnp->completed != rsp->completed);
93580- ACCESS_ONCE(rnp->completed) = rsp->completed;
93581+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
93582 if (rnp == rdp->mynode)
93583 (void)__note_gp_changes(rsp, rnp, rdp);
93584 rcu_preempt_boost_start_gp(rnp);
93585@@ -1687,7 +1687,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
93586 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
93587 raw_spin_lock_irq(&rnp->lock);
93588 smp_mb__after_unlock_lock();
93589- ACCESS_ONCE(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
93590+ ACCESS_ONCE_RW(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
93591 raw_spin_unlock_irq(&rnp->lock);
93592 }
93593 return fqs_state;
93594@@ -1732,7 +1732,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
93595 rcu_for_each_node_breadth_first(rsp, rnp) {
93596 raw_spin_lock_irq(&rnp->lock);
93597 smp_mb__after_unlock_lock();
93598- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
93599+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
93600 rdp = this_cpu_ptr(rsp->rda);
93601 if (rnp == rdp->mynode)
93602 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
93603@@ -1747,14 +1747,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
93604 rcu_nocb_gp_set(rnp, nocb);
93605
93606 /* Declare grace period done. */
93607- ACCESS_ONCE(rsp->completed) = rsp->gpnum;
93608+ ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
93609 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
93610 rsp->fqs_state = RCU_GP_IDLE;
93611 rdp = this_cpu_ptr(rsp->rda);
93612 /* Advance CBs to reduce false positives below. */
93613 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
93614 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
93615- ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
93616+ ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
93617 trace_rcu_grace_period(rsp->name,
93618 ACCESS_ONCE(rsp->gpnum),
93619 TPS("newreq"));
93620@@ -1879,7 +1879,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
93621 */
93622 return false;
93623 }
93624- ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
93625+ ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
93626 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
93627 TPS("newreq"));
93628
93629@@ -2100,7 +2100,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
93630 rsp->qlen += rdp->qlen;
93631 rdp->n_cbs_orphaned += rdp->qlen;
93632 rdp->qlen_lazy = 0;
93633- ACCESS_ONCE(rdp->qlen) = 0;
93634+ ACCESS_ONCE_RW(rdp->qlen) = 0;
93635 }
93636
93637 /*
93638@@ -2347,7 +2347,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
93639 }
93640 smp_mb(); /* List handling before counting for rcu_barrier(). */
93641 rdp->qlen_lazy -= count_lazy;
93642- ACCESS_ONCE(rdp->qlen) -= count;
93643+ ACCESS_ONCE_RW(rdp->qlen) -= count;
93644 rdp->n_cbs_invoked += count;
93645
93646 /* Reinstate batch limit if we have worked down the excess. */
93647@@ -2492,7 +2492,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
93648 if (rnp_old != NULL)
93649 raw_spin_unlock(&rnp_old->fqslock);
93650 if (ret) {
93651- ACCESS_ONCE(rsp->n_force_qs_lh)++;
93652+ ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
93653 return;
93654 }
93655 rnp_old = rnp;
93656@@ -2504,11 +2504,11 @@ static void force_quiescent_state(struct rcu_state *rsp)
93657 smp_mb__after_unlock_lock();
93658 raw_spin_unlock(&rnp_old->fqslock);
93659 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
93660- ACCESS_ONCE(rsp->n_force_qs_lh)++;
93661+ ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
93662 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
93663 return; /* Someone beat us to it. */
93664 }
93665- ACCESS_ONCE(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
93666+ ACCESS_ONCE_RW(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
93667 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
93668 wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */
93669 }
93670@@ -2553,7 +2553,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
93671 /*
93672 * Do RCU core processing for the current CPU.
93673 */
93674-static void rcu_process_callbacks(struct softirq_action *unused)
93675+static void rcu_process_callbacks(void)
93676 {
93677 struct rcu_state *rsp;
93678
93679@@ -2665,7 +2665,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
93680 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
93681 if (debug_rcu_head_queue(head)) {
93682 /* Probable double call_rcu(), so leak the callback. */
93683- ACCESS_ONCE(head->func) = rcu_leak_callback;
93684+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
93685 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
93686 return;
93687 }
93688@@ -2693,7 +2693,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
93689 local_irq_restore(flags);
93690 return;
93691 }
93692- ACCESS_ONCE(rdp->qlen)++;
93693+ ACCESS_ONCE_RW(rdp->qlen)++;
93694 if (lazy)
93695 rdp->qlen_lazy++;
93696 else
93697@@ -2968,11 +2968,11 @@ void synchronize_sched_expedited(void)
93698 * counter wrap on a 32-bit system. Quite a few more CPUs would of
93699 * course be required on a 64-bit system.
93700 */
93701- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
93702+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
93703 (ulong)atomic_long_read(&rsp->expedited_done) +
93704 ULONG_MAX / 8)) {
93705 synchronize_sched();
93706- atomic_long_inc(&rsp->expedited_wrap);
93707+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
93708 return;
93709 }
93710
93711@@ -2980,7 +2980,7 @@ void synchronize_sched_expedited(void)
93712 * Take a ticket. Note that atomic_inc_return() implies a
93713 * full memory barrier.
93714 */
93715- snap = atomic_long_inc_return(&rsp->expedited_start);
93716+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
93717 firstsnap = snap;
93718 get_online_cpus();
93719 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
93720@@ -2993,14 +2993,14 @@ void synchronize_sched_expedited(void)
93721 synchronize_sched_expedited_cpu_stop,
93722 NULL) == -EAGAIN) {
93723 put_online_cpus();
93724- atomic_long_inc(&rsp->expedited_tryfail);
93725+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
93726
93727 /* Check to see if someone else did our work for us. */
93728 s = atomic_long_read(&rsp->expedited_done);
93729 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
93730 /* ensure test happens before caller kfree */
93731 smp_mb__before_atomic(); /* ^^^ */
93732- atomic_long_inc(&rsp->expedited_workdone1);
93733+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
93734 return;
93735 }
93736
93737@@ -3009,7 +3009,7 @@ void synchronize_sched_expedited(void)
93738 udelay(trycount * num_online_cpus());
93739 } else {
93740 wait_rcu_gp(call_rcu_sched);
93741- atomic_long_inc(&rsp->expedited_normal);
93742+ atomic_long_inc_unchecked(&rsp->expedited_normal);
93743 return;
93744 }
93745
93746@@ -3018,7 +3018,7 @@ void synchronize_sched_expedited(void)
93747 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
93748 /* ensure test happens before caller kfree */
93749 smp_mb__before_atomic(); /* ^^^ */
93750- atomic_long_inc(&rsp->expedited_workdone2);
93751+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
93752 return;
93753 }
93754
93755@@ -3030,10 +3030,10 @@ void synchronize_sched_expedited(void)
93756 * period works for us.
93757 */
93758 get_online_cpus();
93759- snap = atomic_long_read(&rsp->expedited_start);
93760+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
93761 smp_mb(); /* ensure read is before try_stop_cpus(). */
93762 }
93763- atomic_long_inc(&rsp->expedited_stoppedcpus);
93764+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
93765
93766 /*
93767 * Everyone up to our most recent fetch is covered by our grace
93768@@ -3042,16 +3042,16 @@ void synchronize_sched_expedited(void)
93769 * than we did already did their update.
93770 */
93771 do {
93772- atomic_long_inc(&rsp->expedited_done_tries);
93773+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
93774 s = atomic_long_read(&rsp->expedited_done);
93775 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
93776 /* ensure test happens before caller kfree */
93777 smp_mb__before_atomic(); /* ^^^ */
93778- atomic_long_inc(&rsp->expedited_done_lost);
93779+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
93780 break;
93781 }
93782 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
93783- atomic_long_inc(&rsp->expedited_done_exit);
93784+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
93785
93786 put_online_cpus();
93787 }
93788@@ -3257,7 +3257,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
93789 * ACCESS_ONCE() to prevent the compiler from speculating
93790 * the increment to precede the early-exit check.
93791 */
93792- ACCESS_ONCE(rsp->n_barrier_done)++;
93793+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
93794 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
93795 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
93796 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
93797@@ -3307,7 +3307,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
93798
93799 /* Increment ->n_barrier_done to prevent duplicate work. */
93800 smp_mb(); /* Keep increment after above mechanism. */
93801- ACCESS_ONCE(rsp->n_barrier_done)++;
93802+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
93803 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
93804 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
93805 smp_mb(); /* Keep increment before caller's subsequent code. */
93806@@ -3352,10 +3352,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
93807 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
93808 init_callback_list(rdp);
93809 rdp->qlen_lazy = 0;
93810- ACCESS_ONCE(rdp->qlen) = 0;
93811+ ACCESS_ONCE_RW(rdp->qlen) = 0;
93812 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
93813 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
93814- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
93815+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
93816 rdp->cpu = cpu;
93817 rdp->rsp = rsp;
93818 rcu_boot_init_nocb_percpu_data(rdp);
93819@@ -3388,8 +3388,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
93820 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
93821 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
93822 rcu_sysidle_init_percpu_data(rdp->dynticks);
93823- atomic_set(&rdp->dynticks->dynticks,
93824- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
93825+ atomic_set_unchecked(&rdp->dynticks->dynticks,
93826+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
93827 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
93828
93829 /* Add CPU to rcu_node bitmasks. */
93830diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
93831index 0f69a79..c85c2dc 100644
93832--- a/kernel/rcu/tree.h
93833+++ b/kernel/rcu/tree.h
93834@@ -87,11 +87,11 @@ struct rcu_dynticks {
93835 long long dynticks_nesting; /* Track irq/process nesting level. */
93836 /* Process level is worth LLONG_MAX/2. */
93837 int dynticks_nmi_nesting; /* Track NMI nesting level. */
93838- atomic_t dynticks; /* Even value for idle, else odd. */
93839+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
93840 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
93841 long long dynticks_idle_nesting;
93842 /* irq/process nesting level from idle. */
93843- atomic_t dynticks_idle; /* Even value for idle, else odd. */
93844+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
93845 /* "Idle" excludes userspace execution. */
93846 unsigned long dynticks_idle_jiffies;
93847 /* End of last non-NMI non-idle period. */
93848@@ -435,17 +435,17 @@ struct rcu_state {
93849 /* _rcu_barrier(). */
93850 /* End of fields guarded by barrier_mutex. */
93851
93852- atomic_long_t expedited_start; /* Starting ticket. */
93853- atomic_long_t expedited_done; /* Done ticket. */
93854- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
93855- atomic_long_t expedited_tryfail; /* # acquisition failures. */
93856- atomic_long_t expedited_workdone1; /* # done by others #1. */
93857- atomic_long_t expedited_workdone2; /* # done by others #2. */
93858- atomic_long_t expedited_normal; /* # fallbacks to normal. */
93859- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
93860- atomic_long_t expedited_done_tries; /* # tries to update _done. */
93861- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
93862- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
93863+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
93864+ atomic_long_t expedited_done; /* Done ticket. */
93865+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
93866+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
93867+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
93868+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
93869+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
93870+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
93871+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
93872+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
93873+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
93874
93875 unsigned long jiffies_force_qs; /* Time at which to invoke */
93876 /* force_quiescent_state(). */
93877diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
93878index 02ac0fb..4aa4a36 100644
93879--- a/kernel/rcu/tree_plugin.h
93880+++ b/kernel/rcu/tree_plugin.h
93881@@ -735,7 +735,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
93882 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
93883 {
93884 return !rcu_preempted_readers_exp(rnp) &&
93885- ACCESS_ONCE(rnp->expmask) == 0;
93886+ ACCESS_ONCE_RW(rnp->expmask) == 0;
93887 }
93888
93889 /*
93890@@ -897,7 +897,7 @@ void synchronize_rcu_expedited(void)
93891
93892 /* Clean up and exit. */
93893 smp_mb(); /* ensure expedited GP seen before counter increment. */
93894- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
93895+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
93896 unlock_mb_ret:
93897 mutex_unlock(&sync_rcu_preempt_exp_mutex);
93898 mb_ret:
93899@@ -1447,7 +1447,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
93900 free_cpumask_var(cm);
93901 }
93902
93903-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
93904+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
93905 .store = &rcu_cpu_kthread_task,
93906 .thread_should_run = rcu_cpu_kthread_should_run,
93907 .thread_fn = rcu_cpu_kthread,
93908@@ -1926,7 +1926,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
93909 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
93910 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
93911 cpu, ticks_value, ticks_title,
93912- atomic_read(&rdtp->dynticks) & 0xfff,
93913+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
93914 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
93915 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
93916 fast_no_hz);
93917@@ -2079,7 +2079,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
93918
93919 /* Enqueue the callback on the nocb list and update counts. */
93920 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
93921- ACCESS_ONCE(*old_rhpp) = rhp;
93922+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
93923 atomic_long_add(rhcount, &rdp->nocb_q_count);
93924 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
93925
93926@@ -2255,12 +2255,12 @@ static int rcu_nocb_kthread(void *arg)
93927 * Extract queued callbacks, update counts, and wait
93928 * for a grace period to elapse.
93929 */
93930- ACCESS_ONCE(rdp->nocb_head) = NULL;
93931+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
93932 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
93933 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
93934 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
93935- ACCESS_ONCE(rdp->nocb_p_count) += c;
93936- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
93937+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
93938+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
93939 rcu_nocb_wait_gp(rdp);
93940
93941 /* Each pass through the following loop invokes a callback. */
93942@@ -2286,8 +2286,8 @@ static int rcu_nocb_kthread(void *arg)
93943 list = next;
93944 }
93945 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
93946- ACCESS_ONCE(rdp->nocb_p_count) -= c;
93947- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
93948+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
93949+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
93950 rdp->n_nocbs_invoked += c;
93951 }
93952 return 0;
93953@@ -2304,7 +2304,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
93954 {
93955 if (!rcu_nocb_need_deferred_wakeup(rdp))
93956 return;
93957- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
93958+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
93959 wake_up(&rdp->nocb_wq);
93960 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
93961 }
93962@@ -2330,7 +2330,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
93963 t = kthread_run(rcu_nocb_kthread, rdp,
93964 "rcuo%c/%d", rsp->abbr, cpu);
93965 BUG_ON(IS_ERR(t));
93966- ACCESS_ONCE(rdp->nocb_kthread) = t;
93967+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
93968 }
93969 }
93970
93971@@ -2461,11 +2461,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
93972
93973 /* Record start of fully idle period. */
93974 j = jiffies;
93975- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
93976+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
93977 smp_mb__before_atomic();
93978- atomic_inc(&rdtp->dynticks_idle);
93979+ atomic_inc_unchecked(&rdtp->dynticks_idle);
93980 smp_mb__after_atomic();
93981- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
93982+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
93983 }
93984
93985 /*
93986@@ -2530,9 +2530,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
93987
93988 /* Record end of idle period. */
93989 smp_mb__before_atomic();
93990- atomic_inc(&rdtp->dynticks_idle);
93991+ atomic_inc_unchecked(&rdtp->dynticks_idle);
93992 smp_mb__after_atomic();
93993- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
93994+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
93995
93996 /*
93997 * If we are the timekeeping CPU, we are permitted to be non-idle
93998@@ -2573,7 +2573,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
93999 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
94000
94001 /* Pick up current idle and NMI-nesting counter and check. */
94002- cur = atomic_read(&rdtp->dynticks_idle);
94003+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
94004 if (cur & 0x1) {
94005 *isidle = false; /* We are not idle! */
94006 return;
94007@@ -2622,7 +2622,7 @@ static void rcu_sysidle(unsigned long j)
94008 case RCU_SYSIDLE_NOT:
94009
94010 /* First time all are idle, so note a short idle period. */
94011- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
94012+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
94013 break;
94014
94015 case RCU_SYSIDLE_SHORT:
94016@@ -2660,7 +2660,7 @@ static void rcu_sysidle_cancel(void)
94017 {
94018 smp_mb();
94019 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
94020- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
94021+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
94022 }
94023
94024 /*
94025@@ -2708,7 +2708,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
94026 smp_mb(); /* grace period precedes setting inuse. */
94027
94028 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
94029- ACCESS_ONCE(rshp->inuse) = 0;
94030+ ACCESS_ONCE_RW(rshp->inuse) = 0;
94031 }
94032
94033 /*
94034diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
94035index 5cdc62e..cc52e88 100644
94036--- a/kernel/rcu/tree_trace.c
94037+++ b/kernel/rcu/tree_trace.c
94038@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
94039 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
94040 rdp->passed_quiesce, rdp->qs_pending);
94041 seq_printf(m, " dt=%d/%llx/%d df=%lu",
94042- atomic_read(&rdp->dynticks->dynticks),
94043+ atomic_read_unchecked(&rdp->dynticks->dynticks),
94044 rdp->dynticks->dynticks_nesting,
94045 rdp->dynticks->dynticks_nmi_nesting,
94046 rdp->dynticks_fqs);
94047@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
94048 struct rcu_state *rsp = (struct rcu_state *)m->private;
94049
94050 seq_printf(m, "s=%lu d=%lu w=%lu tf=%lu wd1=%lu wd2=%lu n=%lu sc=%lu dt=%lu dl=%lu dx=%lu\n",
94051- atomic_long_read(&rsp->expedited_start),
94052+ atomic_long_read_unchecked(&rsp->expedited_start),
94053 atomic_long_read(&rsp->expedited_done),
94054- atomic_long_read(&rsp->expedited_wrap),
94055- atomic_long_read(&rsp->expedited_tryfail),
94056- atomic_long_read(&rsp->expedited_workdone1),
94057- atomic_long_read(&rsp->expedited_workdone2),
94058- atomic_long_read(&rsp->expedited_normal),
94059- atomic_long_read(&rsp->expedited_stoppedcpus),
94060- atomic_long_read(&rsp->expedited_done_tries),
94061- atomic_long_read(&rsp->expedited_done_lost),
94062- atomic_long_read(&rsp->expedited_done_exit));
94063+ atomic_long_read_unchecked(&rsp->expedited_wrap),
94064+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
94065+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
94066+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
94067+ atomic_long_read_unchecked(&rsp->expedited_normal),
94068+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
94069+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
94070+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
94071+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
94072 return 0;
94073 }
94074
94075diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
94076index bc78835..7691a45 100644
94077--- a/kernel/rcu/update.c
94078+++ b/kernel/rcu/update.c
94079@@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
94080 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
94081 */
94082 if (till_stall_check < 3) {
94083- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
94084+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
94085 till_stall_check = 3;
94086 } else if (till_stall_check > 300) {
94087- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
94088+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
94089 till_stall_check = 300;
94090 }
94091 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
94092diff --git a/kernel/resource.c b/kernel/resource.c
94093index 3c2237a..4568d96 100644
94094--- a/kernel/resource.c
94095+++ b/kernel/resource.c
94096@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
94097
94098 static int __init ioresources_init(void)
94099 {
94100+#ifdef CONFIG_GRKERNSEC_PROC_ADD
94101+#ifdef CONFIG_GRKERNSEC_PROC_USER
94102+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
94103+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
94104+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
94105+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
94106+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
94107+#endif
94108+#else
94109 proc_create("ioports", 0, NULL, &proc_ioports_operations);
94110 proc_create("iomem", 0, NULL, &proc_iomem_operations);
94111+#endif
94112 return 0;
94113 }
94114 __initcall(ioresources_init);
94115diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
94116index e73efba..c9bfbd4 100644
94117--- a/kernel/sched/auto_group.c
94118+++ b/kernel/sched/auto_group.c
94119@@ -11,7 +11,7 @@
94120
94121 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
94122 static struct autogroup autogroup_default;
94123-static atomic_t autogroup_seq_nr;
94124+static atomic_unchecked_t autogroup_seq_nr;
94125
94126 void __init autogroup_init(struct task_struct *init_task)
94127 {
94128@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
94129
94130 kref_init(&ag->kref);
94131 init_rwsem(&ag->lock);
94132- ag->id = atomic_inc_return(&autogroup_seq_nr);
94133+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
94134 ag->tg = tg;
94135 #ifdef CONFIG_RT_GROUP_SCHED
94136 /*
94137diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
94138index a63f4dc..349bbb0 100644
94139--- a/kernel/sched/completion.c
94140+++ b/kernel/sched/completion.c
94141@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
94142 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
94143 * or number of jiffies left till timeout) if completed.
94144 */
94145-long __sched
94146+long __sched __intentional_overflow(-1)
94147 wait_for_completion_interruptible_timeout(struct completion *x,
94148 unsigned long timeout)
94149 {
94150@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
94151 *
94152 * Return: -ERESTARTSYS if interrupted, 0 if completed.
94153 */
94154-int __sched wait_for_completion_killable(struct completion *x)
94155+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
94156 {
94157 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
94158 if (t == -ERESTARTSYS)
94159@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
94160 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
94161 * or number of jiffies left till timeout) if completed.
94162 */
94163-long __sched
94164+long __sched __intentional_overflow(-1)
94165 wait_for_completion_killable_timeout(struct completion *x,
94166 unsigned long timeout)
94167 {
94168diff --git a/kernel/sched/core.c b/kernel/sched/core.c
94169index bc1638b..a7638fc 100644
94170--- a/kernel/sched/core.c
94171+++ b/kernel/sched/core.c
94172@@ -1849,7 +1849,7 @@ void set_numabalancing_state(bool enabled)
94173 int sysctl_numa_balancing(struct ctl_table *table, int write,
94174 void __user *buffer, size_t *lenp, loff_t *ppos)
94175 {
94176- struct ctl_table t;
94177+ ctl_table_no_const t;
94178 int err;
94179 int state = numabalancing_enabled;
94180
94181@@ -2312,8 +2312,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
94182 next->active_mm = oldmm;
94183 atomic_inc(&oldmm->mm_count);
94184 enter_lazy_tlb(oldmm, next);
94185- } else
94186+ } else {
94187 switch_mm(oldmm, mm, next);
94188+ populate_stack();
94189+ }
94190
94191 if (!prev->mm) {
94192 prev->active_mm = NULL;
94193@@ -3081,6 +3083,8 @@ int can_nice(const struct task_struct *p, const int nice)
94194 /* convert nice value [19,-20] to rlimit style value [1,40] */
94195 int nice_rlim = nice_to_rlimit(nice);
94196
94197+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
94198+
94199 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
94200 capable(CAP_SYS_NICE));
94201 }
94202@@ -3107,7 +3111,8 @@ SYSCALL_DEFINE1(nice, int, increment)
94203 nice = task_nice(current) + increment;
94204
94205 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
94206- if (increment < 0 && !can_nice(current, nice))
94207+ if (increment < 0 && (!can_nice(current, nice) ||
94208+ gr_handle_chroot_nice()))
94209 return -EPERM;
94210
94211 retval = security_task_setnice(current, nice);
94212@@ -3380,6 +3385,7 @@ recheck:
94213 if (policy != p->policy && !rlim_rtprio)
94214 return -EPERM;
94215
94216+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
94217 /* can't increase priority */
94218 if (attr->sched_priority > p->rt_priority &&
94219 attr->sched_priority > rlim_rtprio)
94220@@ -4771,6 +4777,7 @@ void idle_task_exit(void)
94221
94222 if (mm != &init_mm) {
94223 switch_mm(mm, &init_mm, current);
94224+ populate_stack();
94225 finish_arch_post_lock_switch();
94226 }
94227 mmdrop(mm);
94228@@ -4866,7 +4873,7 @@ static void migrate_tasks(unsigned int dead_cpu)
94229
94230 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
94231
94232-static struct ctl_table sd_ctl_dir[] = {
94233+static ctl_table_no_const sd_ctl_dir[] __read_only = {
94234 {
94235 .procname = "sched_domain",
94236 .mode = 0555,
94237@@ -4883,17 +4890,17 @@ static struct ctl_table sd_ctl_root[] = {
94238 {}
94239 };
94240
94241-static struct ctl_table *sd_alloc_ctl_entry(int n)
94242+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
94243 {
94244- struct ctl_table *entry =
94245+ ctl_table_no_const *entry =
94246 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
94247
94248 return entry;
94249 }
94250
94251-static void sd_free_ctl_entry(struct ctl_table **tablep)
94252+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
94253 {
94254- struct ctl_table *entry;
94255+ ctl_table_no_const *entry;
94256
94257 /*
94258 * In the intermediate directories, both the child directory and
94259@@ -4901,22 +4908,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
94260 * will always be set. In the lowest directory the names are
94261 * static strings and all have proc handlers.
94262 */
94263- for (entry = *tablep; entry->mode; entry++) {
94264- if (entry->child)
94265- sd_free_ctl_entry(&entry->child);
94266+ for (entry = tablep; entry->mode; entry++) {
94267+ if (entry->child) {
94268+ sd_free_ctl_entry(entry->child);
94269+ pax_open_kernel();
94270+ entry->child = NULL;
94271+ pax_close_kernel();
94272+ }
94273 if (entry->proc_handler == NULL)
94274 kfree(entry->procname);
94275 }
94276
94277- kfree(*tablep);
94278- *tablep = NULL;
94279+ kfree(tablep);
94280 }
94281
94282 static int min_load_idx = 0;
94283 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
94284
94285 static void
94286-set_table_entry(struct ctl_table *entry,
94287+set_table_entry(ctl_table_no_const *entry,
94288 const char *procname, void *data, int maxlen,
94289 umode_t mode, proc_handler *proc_handler,
94290 bool load_idx)
94291@@ -4936,7 +4946,7 @@ set_table_entry(struct ctl_table *entry,
94292 static struct ctl_table *
94293 sd_alloc_ctl_domain_table(struct sched_domain *sd)
94294 {
94295- struct ctl_table *table = sd_alloc_ctl_entry(14);
94296+ ctl_table_no_const *table = sd_alloc_ctl_entry(14);
94297
94298 if (table == NULL)
94299 return NULL;
94300@@ -4974,9 +4984,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
94301 return table;
94302 }
94303
94304-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
94305+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
94306 {
94307- struct ctl_table *entry, *table;
94308+ ctl_table_no_const *entry, *table;
94309 struct sched_domain *sd;
94310 int domain_num = 0, i;
94311 char buf[32];
94312@@ -5003,11 +5013,13 @@ static struct ctl_table_header *sd_sysctl_header;
94313 static void register_sched_domain_sysctl(void)
94314 {
94315 int i, cpu_num = num_possible_cpus();
94316- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
94317+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
94318 char buf[32];
94319
94320 WARN_ON(sd_ctl_dir[0].child);
94321+ pax_open_kernel();
94322 sd_ctl_dir[0].child = entry;
94323+ pax_close_kernel();
94324
94325 if (entry == NULL)
94326 return;
94327@@ -5030,8 +5042,12 @@ static void unregister_sched_domain_sysctl(void)
94328 if (sd_sysctl_header)
94329 unregister_sysctl_table(sd_sysctl_header);
94330 sd_sysctl_header = NULL;
94331- if (sd_ctl_dir[0].child)
94332- sd_free_ctl_entry(&sd_ctl_dir[0].child);
94333+ if (sd_ctl_dir[0].child) {
94334+ sd_free_ctl_entry(sd_ctl_dir[0].child);
94335+ pax_open_kernel();
94336+ sd_ctl_dir[0].child = NULL;
94337+ pax_close_kernel();
94338+ }
94339 }
94340 #else
94341 static void register_sched_domain_sysctl(void)
94342diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
94343index fea7d33..84faa94 100644
94344--- a/kernel/sched/fair.c
94345+++ b/kernel/sched/fair.c
94346@@ -1857,7 +1857,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
94347
94348 static void reset_ptenuma_scan(struct task_struct *p)
94349 {
94350- ACCESS_ONCE(p->mm->numa_scan_seq)++;
94351+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
94352 p->mm->numa_scan_offset = 0;
94353 }
94354
94355@@ -7289,7 +7289,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
94356 * run_rebalance_domains is triggered when needed from the scheduler tick.
94357 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
94358 */
94359-static void run_rebalance_domains(struct softirq_action *h)
94360+static __latent_entropy void run_rebalance_domains(void)
94361 {
94362 struct rq *this_rq = this_rq();
94363 enum cpu_idle_type idle = this_rq->idle_balance ?
94364diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
94365index 31cc02e..734fb85 100644
94366--- a/kernel/sched/sched.h
94367+++ b/kernel/sched/sched.h
94368@@ -1153,7 +1153,7 @@ struct sched_class {
94369 #ifdef CONFIG_FAIR_GROUP_SCHED
94370 void (*task_move_group) (struct task_struct *p, int on_rq);
94371 #endif
94372-};
94373+} __do_const;
94374
94375 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
94376 {
94377diff --git a/kernel/seccomp.c b/kernel/seccomp.c
94378index 301bbc2..eda2da3 100644
94379--- a/kernel/seccomp.c
94380+++ b/kernel/seccomp.c
94381@@ -39,7 +39,7 @@
94382 * is only needed for handling filters shared across tasks.
94383 * @prev: points to a previously installed, or inherited, filter
94384 * @len: the number of instructions in the program
94385- * @insnsi: the BPF program instructions to evaluate
94386+ * @insns: the BPF program instructions to evaluate
94387 *
94388 * seccomp_filter objects are organized in a tree linked via the @prev
94389 * pointer. For any task, it appears to be a singly-linked list starting
94390@@ -54,32 +54,61 @@
94391 struct seccomp_filter {
94392 atomic_t usage;
94393 struct seccomp_filter *prev;
94394- struct sk_filter *prog;
94395+ unsigned short len; /* Instruction count */
94396+ struct sock_filter insns[];
94397 };
94398
94399 /* Limit any path through the tree to 256KB worth of instructions. */
94400 #define MAX_INSNS_PER_PATH ((1 << 18) / sizeof(struct sock_filter))
94401
94402-/*
94403+/**
94404+ * get_u32 - returns a u32 offset into data
94405+ * @data: a unsigned 64 bit value
94406+ * @index: 0 or 1 to return the first or second 32-bits
94407+ *
94408+ * This inline exists to hide the length of unsigned long. If a 32-bit
94409+ * unsigned long is passed in, it will be extended and the top 32-bits will be
94410+ * 0. If it is a 64-bit unsigned long, then whatever data is resident will be
94411+ * properly returned.
94412+ *
94413 * Endianness is explicitly ignored and left for BPF program authors to manage
94414 * as per the specific architecture.
94415 */
94416-static void populate_seccomp_data(struct seccomp_data *sd)
94417+static inline u32 get_u32(u64 data, int index)
94418 {
94419- struct task_struct *task = current;
94420- struct pt_regs *regs = task_pt_regs(task);
94421- unsigned long args[6];
94422+ return ((u32 *)&data)[index];
94423+}
94424
94425- sd->nr = syscall_get_nr(task, regs);
94426- sd->arch = syscall_get_arch();
94427- syscall_get_arguments(task, regs, 0, 6, args);
94428- sd->args[0] = args[0];
94429- sd->args[1] = args[1];
94430- sd->args[2] = args[2];
94431- sd->args[3] = args[3];
94432- sd->args[4] = args[4];
94433- sd->args[5] = args[5];
94434- sd->instruction_pointer = KSTK_EIP(task);
94435+/* Helper for bpf_load below. */
94436+#define BPF_DATA(_name) offsetof(struct seccomp_data, _name)
94437+/**
94438+ * bpf_load: checks and returns a pointer to the requested offset
94439+ * @off: offset into struct seccomp_data to load from
94440+ *
94441+ * Returns the requested 32-bits of data.
94442+ * seccomp_check_filter() should assure that @off is 32-bit aligned
94443+ * and not out of bounds. Failure to do so is a BUG.
94444+ */
94445+u32 seccomp_bpf_load(int off)
94446+{
94447+ struct pt_regs *regs = task_pt_regs(current);
94448+ if (off == BPF_DATA(nr))
94449+ return syscall_get_nr(current, regs);
94450+ if (off == BPF_DATA(arch))
94451+ return syscall_get_arch();
94452+ if (off >= BPF_DATA(args[0]) && off < BPF_DATA(args[6])) {
94453+ unsigned long value;
94454+ int arg = (off - BPF_DATA(args[0])) / sizeof(u64);
94455+ int index = !!(off % sizeof(u64));
94456+ syscall_get_arguments(current, regs, arg, 1, &value);
94457+ return get_u32(value, index);
94458+ }
94459+ if (off == BPF_DATA(instruction_pointer))
94460+ return get_u32(KSTK_EIP(current), 0);
94461+ if (off == BPF_DATA(instruction_pointer) + sizeof(u32))
94462+ return get_u32(KSTK_EIP(current), 1);
94463+ /* seccomp_check_filter should make this impossible. */
94464+ BUG();
94465 }
94466
94467 /**
94468@@ -103,59 +132,59 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)
94469 u32 k = ftest->k;
94470
94471 switch (code) {
94472- case BPF_LD | BPF_W | BPF_ABS:
94473- ftest->code = BPF_LDX | BPF_W | BPF_ABS;
94474+ case BPF_S_LD_W_ABS:
94475+ ftest->code = BPF_S_ANC_SECCOMP_LD_W;
94476 /* 32-bit aligned and not out of bounds. */
94477 if (k >= sizeof(struct seccomp_data) || k & 3)
94478 return -EINVAL;
94479 continue;
94480- case BPF_LD | BPF_W | BPF_LEN:
94481- ftest->code = BPF_LD | BPF_IMM;
94482+ case BPF_S_LD_W_LEN:
94483+ ftest->code = BPF_S_LD_IMM;
94484 ftest->k = sizeof(struct seccomp_data);
94485 continue;
94486- case BPF_LDX | BPF_W | BPF_LEN:
94487- ftest->code = BPF_LDX | BPF_IMM;
94488+ case BPF_S_LDX_W_LEN:
94489+ ftest->code = BPF_S_LDX_IMM;
94490 ftest->k = sizeof(struct seccomp_data);
94491 continue;
94492 /* Explicitly include allowed calls. */
94493- case BPF_RET | BPF_K:
94494- case BPF_RET | BPF_A:
94495- case BPF_ALU | BPF_ADD | BPF_K:
94496- case BPF_ALU | BPF_ADD | BPF_X:
94497- case BPF_ALU | BPF_SUB | BPF_K:
94498- case BPF_ALU | BPF_SUB | BPF_X:
94499- case BPF_ALU | BPF_MUL | BPF_K:
94500- case BPF_ALU | BPF_MUL | BPF_X:
94501- case BPF_ALU | BPF_DIV | BPF_K:
94502- case BPF_ALU | BPF_DIV | BPF_X:
94503- case BPF_ALU | BPF_AND | BPF_K:
94504- case BPF_ALU | BPF_AND | BPF_X:
94505- case BPF_ALU | BPF_OR | BPF_K:
94506- case BPF_ALU | BPF_OR | BPF_X:
94507- case BPF_ALU | BPF_XOR | BPF_K:
94508- case BPF_ALU | BPF_XOR | BPF_X:
94509- case BPF_ALU | BPF_LSH | BPF_K:
94510- case BPF_ALU | BPF_LSH | BPF_X:
94511- case BPF_ALU | BPF_RSH | BPF_K:
94512- case BPF_ALU | BPF_RSH | BPF_X:
94513- case BPF_ALU | BPF_NEG:
94514- case BPF_LD | BPF_IMM:
94515- case BPF_LDX | BPF_IMM:
94516- case BPF_MISC | BPF_TAX:
94517- case BPF_MISC | BPF_TXA:
94518- case BPF_LD | BPF_MEM:
94519- case BPF_LDX | BPF_MEM:
94520- case BPF_ST:
94521- case BPF_STX:
94522- case BPF_JMP | BPF_JA:
94523- case BPF_JMP | BPF_JEQ | BPF_K:
94524- case BPF_JMP | BPF_JEQ | BPF_X:
94525- case BPF_JMP | BPF_JGE | BPF_K:
94526- case BPF_JMP | BPF_JGE | BPF_X:
94527- case BPF_JMP | BPF_JGT | BPF_K:
94528- case BPF_JMP | BPF_JGT | BPF_X:
94529- case BPF_JMP | BPF_JSET | BPF_K:
94530- case BPF_JMP | BPF_JSET | BPF_X:
94531+ case BPF_S_RET_K:
94532+ case BPF_S_RET_A:
94533+ case BPF_S_ALU_ADD_K:
94534+ case BPF_S_ALU_ADD_X:
94535+ case BPF_S_ALU_SUB_K:
94536+ case BPF_S_ALU_SUB_X:
94537+ case BPF_S_ALU_MUL_K:
94538+ case BPF_S_ALU_MUL_X:
94539+ case BPF_S_ALU_DIV_X:
94540+ case BPF_S_ALU_AND_K:
94541+ case BPF_S_ALU_AND_X:
94542+ case BPF_S_ALU_OR_K:
94543+ case BPF_S_ALU_OR_X:
94544+ case BPF_S_ALU_XOR_K:
94545+ case BPF_S_ALU_XOR_X:
94546+ case BPF_S_ALU_LSH_K:
94547+ case BPF_S_ALU_LSH_X:
94548+ case BPF_S_ALU_RSH_K:
94549+ case BPF_S_ALU_RSH_X:
94550+ case BPF_S_ALU_NEG:
94551+ case BPF_S_LD_IMM:
94552+ case BPF_S_LDX_IMM:
94553+ case BPF_S_MISC_TAX:
94554+ case BPF_S_MISC_TXA:
94555+ case BPF_S_ALU_DIV_K:
94556+ case BPF_S_LD_MEM:
94557+ case BPF_S_LDX_MEM:
94558+ case BPF_S_ST:
94559+ case BPF_S_STX:
94560+ case BPF_S_JMP_JA:
94561+ case BPF_S_JMP_JEQ_K:
94562+ case BPF_S_JMP_JEQ_X:
94563+ case BPF_S_JMP_JGE_K:
94564+ case BPF_S_JMP_JGE_X:
94565+ case BPF_S_JMP_JGT_K:
94566+ case BPF_S_JMP_JGT_X:
94567+ case BPF_S_JMP_JSET_K:
94568+ case BPF_S_JMP_JSET_X:
94569 continue;
94570 default:
94571 return -EINVAL;
94572@@ -173,22 +202,18 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)
94573 static u32 seccomp_run_filters(int syscall)
94574 {
94575 struct seccomp_filter *f;
94576- struct seccomp_data sd;
94577 u32 ret = SECCOMP_RET_ALLOW;
94578
94579 /* Ensure unexpected behavior doesn't result in failing open. */
94580 if (WARN_ON(current->seccomp.filter == NULL))
94581 return SECCOMP_RET_KILL;
94582
94583- populate_seccomp_data(&sd);
94584-
94585 /*
94586 * All filters in the list are evaluated and the lowest BPF return
94587 * value always takes priority (ignoring the DATA).
94588 */
94589 for (f = current->seccomp.filter; f; f = f->prev) {
94590- u32 cur_ret = SK_RUN_FILTER(f->prog, (void *)&sd);
94591-
94592+ u32 cur_ret = sk_run_filter(NULL, f->insns);
94593 if ((cur_ret & SECCOMP_RET_ACTION) < (ret & SECCOMP_RET_ACTION))
94594 ret = cur_ret;
94595 }
94596@@ -206,20 +231,18 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
94597 struct seccomp_filter *filter;
94598 unsigned long fp_size = fprog->len * sizeof(struct sock_filter);
94599 unsigned long total_insns = fprog->len;
94600- struct sock_filter *fp;
94601- int new_len;
94602 long ret;
94603
94604 if (fprog->len == 0 || fprog->len > BPF_MAXINSNS)
94605 return -EINVAL;
94606
94607 for (filter = current->seccomp.filter; filter; filter = filter->prev)
94608- total_insns += filter->prog->len + 4; /* include a 4 instr penalty */
94609+ total_insns += filter->len + 4; /* include a 4 instr penalty */
94610 if (total_insns > MAX_INSNS_PER_PATH)
94611 return -ENOMEM;
94612
94613 /*
94614- * Installing a seccomp filter requires that the task has
94615+ * Installing a seccomp filter requires that the task have
94616 * CAP_SYS_ADMIN in its namespace or be running with no_new_privs.
94617 * This avoids scenarios where unprivileged tasks can affect the
94618 * behavior of privileged children.
94619@@ -229,51 +252,28 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
94620 CAP_SYS_ADMIN) != 0)
94621 return -EACCES;
94622
94623- fp = kzalloc(fp_size, GFP_KERNEL|__GFP_NOWARN);
94624- if (!fp)
94625- return -ENOMEM;
94626-
94627- /* Copy the instructions from fprog. */
94628- ret = -EFAULT;
94629- if (copy_from_user(fp, fprog->filter, fp_size))
94630- goto free_prog;
94631-
94632- /* Check and rewrite the fprog via the skb checker */
94633- ret = sk_chk_filter(fp, fprog->len);
94634- if (ret)
94635- goto free_prog;
94636-
94637- /* Check and rewrite the fprog for seccomp use */
94638- ret = seccomp_check_filter(fp, fprog->len);
94639- if (ret)
94640- goto free_prog;
94641-
94642- /* Convert 'sock_filter' insns to 'sock_filter_int' insns */
94643- ret = sk_convert_filter(fp, fprog->len, NULL, &new_len);
94644- if (ret)
94645- goto free_prog;
94646-
94647 /* Allocate a new seccomp_filter */
94648- ret = -ENOMEM;
94649- filter = kzalloc(sizeof(struct seccomp_filter),
94650+ filter = kzalloc(sizeof(struct seccomp_filter) + fp_size,
94651 GFP_KERNEL|__GFP_NOWARN);
94652 if (!filter)
94653- goto free_prog;
94654-
94655- filter->prog = kzalloc(sk_filter_size(new_len),
94656- GFP_KERNEL|__GFP_NOWARN);
94657- if (!filter->prog)
94658- goto free_filter;
94659-
94660- ret = sk_convert_filter(fp, fprog->len, filter->prog->insnsi, &new_len);
94661- if (ret)
94662- goto free_filter_prog;
94663- kfree(fp);
94664-
94665+ return -ENOMEM;
94666 atomic_set(&filter->usage, 1);
94667- filter->prog->len = new_len;
94668+ filter->len = fprog->len;
94669
94670- sk_filter_select_runtime(filter->prog);
94671+ /* Copy the instructions from fprog. */
94672+ ret = -EFAULT;
94673+ if (copy_from_user(filter->insns, fprog->filter, fp_size))
94674+ goto fail;
94675+
94676+ /* Check and rewrite the fprog via the skb checker */
94677+ ret = sk_chk_filter(filter->insns, filter->len);
94678+ if (ret)
94679+ goto fail;
94680+
94681+ /* Check and rewrite the fprog for seccomp use */
94682+ ret = seccomp_check_filter(filter->insns, filter->len);
94683+ if (ret)
94684+ goto fail;
94685
94686 /*
94687 * If there is an existing filter, make it the prev and don't drop its
94688@@ -282,13 +282,8 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
94689 filter->prev = current->seccomp.filter;
94690 current->seccomp.filter = filter;
94691 return 0;
94692-
94693-free_filter_prog:
94694- kfree(filter->prog);
94695-free_filter:
94696+fail:
94697 kfree(filter);
94698-free_prog:
94699- kfree(fp);
94700 return ret;
94701 }
94702
94703@@ -298,7 +293,7 @@ free_prog:
94704 *
94705 * Returns 0 on success and non-zero otherwise.
94706 */
94707-static long seccomp_attach_user_filter(char __user *user_filter)
94708+long seccomp_attach_user_filter(char __user *user_filter)
94709 {
94710 struct sock_fprog fprog;
94711 long ret = -EFAULT;
94712@@ -337,7 +332,6 @@ void put_seccomp_filter(struct task_struct *tsk)
94713 while (orig && atomic_dec_and_test(&orig->usage)) {
94714 struct seccomp_filter *freeme = orig;
94715 orig = orig->prev;
94716- sk_filter_free(freeme->prog);
94717 kfree(freeme);
94718 }
94719 }
94720diff --git a/kernel/signal.c b/kernel/signal.c
94721index a4077e9..f0d4e5c 100644
94722--- a/kernel/signal.c
94723+++ b/kernel/signal.c
94724@@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
94725
94726 int print_fatal_signals __read_mostly;
94727
94728-static void __user *sig_handler(struct task_struct *t, int sig)
94729+static __sighandler_t sig_handler(struct task_struct *t, int sig)
94730 {
94731 return t->sighand->action[sig - 1].sa.sa_handler;
94732 }
94733
94734-static int sig_handler_ignored(void __user *handler, int sig)
94735+static int sig_handler_ignored(__sighandler_t handler, int sig)
94736 {
94737 /* Is it explicitly or implicitly ignored? */
94738 return handler == SIG_IGN ||
94739@@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
94740
94741 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
94742 {
94743- void __user *handler;
94744+ __sighandler_t handler;
94745
94746 handler = sig_handler(t, sig);
94747
94748@@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
94749 atomic_inc(&user->sigpending);
94750 rcu_read_unlock();
94751
94752+ if (!override_rlimit)
94753+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
94754+
94755 if (override_rlimit ||
94756 atomic_read(&user->sigpending) <=
94757 task_rlimit(t, RLIMIT_SIGPENDING)) {
94758@@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
94759
94760 int unhandled_signal(struct task_struct *tsk, int sig)
94761 {
94762- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
94763+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
94764 if (is_global_init(tsk))
94765 return 1;
94766 if (handler != SIG_IGN && handler != SIG_DFL)
94767@@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
94768 }
94769 }
94770
94771+ /* allow glibc communication via tgkill to other threads in our
94772+ thread group */
94773+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
94774+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
94775+ && gr_handle_signal(t, sig))
94776+ return -EPERM;
94777+
94778 return security_task_kill(t, info, sig, 0);
94779 }
94780
94781@@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
94782 return send_signal(sig, info, p, 1);
94783 }
94784
94785-static int
94786+int
94787 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
94788 {
94789 return send_signal(sig, info, t, 0);
94790@@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
94791 unsigned long int flags;
94792 int ret, blocked, ignored;
94793 struct k_sigaction *action;
94794+ int is_unhandled = 0;
94795
94796 spin_lock_irqsave(&t->sighand->siglock, flags);
94797 action = &t->sighand->action[sig-1];
94798@@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
94799 }
94800 if (action->sa.sa_handler == SIG_DFL)
94801 t->signal->flags &= ~SIGNAL_UNKILLABLE;
94802+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
94803+ is_unhandled = 1;
94804 ret = specific_send_sig_info(sig, info, t);
94805 spin_unlock_irqrestore(&t->sighand->siglock, flags);
94806
94807+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
94808+ normal operation */
94809+ if (is_unhandled) {
94810+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
94811+ gr_handle_crash(t, sig);
94812+ }
94813+
94814 return ret;
94815 }
94816
94817@@ -1296,8 +1316,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
94818 ret = check_kill_permission(sig, info, p);
94819 rcu_read_unlock();
94820
94821- if (!ret && sig)
94822+ if (!ret && sig) {
94823 ret = do_send_sig_info(sig, info, p, true);
94824+ if (!ret)
94825+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
94826+ }
94827
94828 return ret;
94829 }
94830@@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
94831 int error = -ESRCH;
94832
94833 rcu_read_lock();
94834- p = find_task_by_vpid(pid);
94835+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
94836+ /* allow glibc communication via tgkill to other threads in our
94837+ thread group */
94838+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
94839+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
94840+ p = find_task_by_vpid_unrestricted(pid);
94841+ else
94842+#endif
94843+ p = find_task_by_vpid(pid);
94844 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
94845 error = check_kill_permission(sig, info, p);
94846 /*
94847@@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
94848 }
94849 seg = get_fs();
94850 set_fs(KERNEL_DS);
94851- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
94852- (stack_t __force __user *) &uoss,
94853+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
94854+ (stack_t __force_user *) &uoss,
94855 compat_user_stack_pointer());
94856 set_fs(seg);
94857 if (ret >= 0 && uoss_ptr) {
94858diff --git a/kernel/smpboot.c b/kernel/smpboot.c
94859index eb89e18..a4e6792 100644
94860--- a/kernel/smpboot.c
94861+++ b/kernel/smpboot.c
94862@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
94863 }
94864 smpboot_unpark_thread(plug_thread, cpu);
94865 }
94866- list_add(&plug_thread->list, &hotplug_threads);
94867+ pax_list_add(&plug_thread->list, &hotplug_threads);
94868 out:
94869 mutex_unlock(&smpboot_threads_lock);
94870 return ret;
94871@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
94872 {
94873 get_online_cpus();
94874 mutex_lock(&smpboot_threads_lock);
94875- list_del(&plug_thread->list);
94876+ pax_list_del(&plug_thread->list);
94877 smpboot_destroy_threads(plug_thread);
94878 mutex_unlock(&smpboot_threads_lock);
94879 put_online_cpus();
94880diff --git a/kernel/softirq.c b/kernel/softirq.c
94881index 5918d22..e95d1926 100644
94882--- a/kernel/softirq.c
94883+++ b/kernel/softirq.c
94884@@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
94885 EXPORT_SYMBOL(irq_stat);
94886 #endif
94887
94888-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
94889+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
94890
94891 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
94892
94893@@ -266,7 +266,7 @@ restart:
94894 kstat_incr_softirqs_this_cpu(vec_nr);
94895
94896 trace_softirq_entry(vec_nr);
94897- h->action(h);
94898+ h->action();
94899 trace_softirq_exit(vec_nr);
94900 if (unlikely(prev_count != preempt_count())) {
94901 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
94902@@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
94903 or_softirq_pending(1UL << nr);
94904 }
94905
94906-void open_softirq(int nr, void (*action)(struct softirq_action *))
94907+void __init open_softirq(int nr, void (*action)(void))
94908 {
94909 softirq_vec[nr].action = action;
94910 }
94911@@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
94912 }
94913 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
94914
94915-static void tasklet_action(struct softirq_action *a)
94916+static void tasklet_action(void)
94917 {
94918 struct tasklet_struct *list;
94919
94920@@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
94921 }
94922 }
94923
94924-static void tasklet_hi_action(struct softirq_action *a)
94925+static __latent_entropy void tasklet_hi_action(void)
94926 {
94927 struct tasklet_struct *list;
94928
94929@@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
94930 .notifier_call = cpu_callback
94931 };
94932
94933-static struct smp_hotplug_thread softirq_threads = {
94934+static struct smp_hotplug_thread softirq_threads __read_only = {
94935 .store = &ksoftirqd,
94936 .thread_should_run = ksoftirqd_should_run,
94937 .thread_fn = run_ksoftirqd,
94938diff --git a/kernel/sys.c b/kernel/sys.c
94939index 66a751e..a42497e 100644
94940--- a/kernel/sys.c
94941+++ b/kernel/sys.c
94942@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
94943 error = -EACCES;
94944 goto out;
94945 }
94946+
94947+ if (gr_handle_chroot_setpriority(p, niceval)) {
94948+ error = -EACCES;
94949+ goto out;
94950+ }
94951+
94952 no_nice = security_task_setnice(p, niceval);
94953 if (no_nice) {
94954 error = no_nice;
94955@@ -351,6 +357,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
94956 goto error;
94957 }
94958
94959+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
94960+ goto error;
94961+
94962+ if (!gid_eq(new->gid, old->gid)) {
94963+ /* make sure we generate a learn log for what will
94964+ end up being a role transition after a full-learning
94965+ policy is generated
94966+ CAP_SETGID is required to perform a transition
94967+ we may not log a CAP_SETGID check above, e.g.
94968+ in the case where new rgid = old egid
94969+ */
94970+ gr_learn_cap(current, new, CAP_SETGID);
94971+ }
94972+
94973 if (rgid != (gid_t) -1 ||
94974 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
94975 new->sgid = new->egid;
94976@@ -386,6 +406,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
94977 old = current_cred();
94978
94979 retval = -EPERM;
94980+
94981+ if (gr_check_group_change(kgid, kgid, kgid))
94982+ goto error;
94983+
94984 if (ns_capable(old->user_ns, CAP_SETGID))
94985 new->gid = new->egid = new->sgid = new->fsgid = kgid;
94986 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
94987@@ -403,7 +427,7 @@ error:
94988 /*
94989 * change the user struct in a credentials set to match the new UID
94990 */
94991-static int set_user(struct cred *new)
94992+int set_user(struct cred *new)
94993 {
94994 struct user_struct *new_user;
94995
94996@@ -483,7 +507,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
94997 goto error;
94998 }
94999
95000+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
95001+ goto error;
95002+
95003 if (!uid_eq(new->uid, old->uid)) {
95004+ /* make sure we generate a learn log for what will
95005+ end up being a role transition after a full-learning
95006+ policy is generated
95007+ CAP_SETUID is required to perform a transition
95008+ we may not log a CAP_SETUID check above, e.g.
95009+ in the case where new ruid = old euid
95010+ */
95011+ gr_learn_cap(current, new, CAP_SETUID);
95012 retval = set_user(new);
95013 if (retval < 0)
95014 goto error;
95015@@ -533,6 +568,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
95016 old = current_cred();
95017
95018 retval = -EPERM;
95019+
95020+ if (gr_check_crash_uid(kuid))
95021+ goto error;
95022+ if (gr_check_user_change(kuid, kuid, kuid))
95023+ goto error;
95024+
95025 if (ns_capable(old->user_ns, CAP_SETUID)) {
95026 new->suid = new->uid = kuid;
95027 if (!uid_eq(kuid, old->uid)) {
95028@@ -602,6 +643,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
95029 goto error;
95030 }
95031
95032+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
95033+ goto error;
95034+
95035 if (ruid != (uid_t) -1) {
95036 new->uid = kruid;
95037 if (!uid_eq(kruid, old->uid)) {
95038@@ -684,6 +728,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
95039 goto error;
95040 }
95041
95042+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
95043+ goto error;
95044+
95045 if (rgid != (gid_t) -1)
95046 new->gid = krgid;
95047 if (egid != (gid_t) -1)
95048@@ -745,12 +792,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
95049 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
95050 ns_capable(old->user_ns, CAP_SETUID)) {
95051 if (!uid_eq(kuid, old->fsuid)) {
95052+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
95053+ goto error;
95054+
95055 new->fsuid = kuid;
95056 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
95057 goto change_okay;
95058 }
95059 }
95060
95061+error:
95062 abort_creds(new);
95063 return old_fsuid;
95064
95065@@ -783,12 +834,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
95066 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
95067 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
95068 ns_capable(old->user_ns, CAP_SETGID)) {
95069+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
95070+ goto error;
95071+
95072 if (!gid_eq(kgid, old->fsgid)) {
95073 new->fsgid = kgid;
95074 goto change_okay;
95075 }
95076 }
95077
95078+error:
95079 abort_creds(new);
95080 return old_fsgid;
95081
95082@@ -1167,19 +1222,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
95083 return -EFAULT;
95084
95085 down_read(&uts_sem);
95086- error = __copy_to_user(&name->sysname, &utsname()->sysname,
95087+ error = __copy_to_user(name->sysname, &utsname()->sysname,
95088 __OLD_UTS_LEN);
95089 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
95090- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
95091+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
95092 __OLD_UTS_LEN);
95093 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
95094- error |= __copy_to_user(&name->release, &utsname()->release,
95095+ error |= __copy_to_user(name->release, &utsname()->release,
95096 __OLD_UTS_LEN);
95097 error |= __put_user(0, name->release + __OLD_UTS_LEN);
95098- error |= __copy_to_user(&name->version, &utsname()->version,
95099+ error |= __copy_to_user(name->version, &utsname()->version,
95100 __OLD_UTS_LEN);
95101 error |= __put_user(0, name->version + __OLD_UTS_LEN);
95102- error |= __copy_to_user(&name->machine, &utsname()->machine,
95103+ error |= __copy_to_user(name->machine, &utsname()->machine,
95104 __OLD_UTS_LEN);
95105 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
95106 up_read(&uts_sem);
95107@@ -1381,6 +1436,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
95108 */
95109 new_rlim->rlim_cur = 1;
95110 }
95111+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
95112+ is changed to a lower value. Since tasks can be created by the same
95113+ user in between this limit change and an execve by this task, force
95114+ a recheck only for this task by setting PF_NPROC_EXCEEDED
95115+ */
95116+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
95117+ tsk->flags |= PF_NPROC_EXCEEDED;
95118 }
95119 if (!retval) {
95120 if (old_rlim)
95121diff --git a/kernel/sysctl.c b/kernel/sysctl.c
95122index 75b22e2..65c0ac8 100644
95123--- a/kernel/sysctl.c
95124+++ b/kernel/sysctl.c
95125@@ -94,7 +94,6 @@
95126
95127
95128 #if defined(CONFIG_SYSCTL)
95129-
95130 /* External variables not in a header file. */
95131 extern int max_threads;
95132 extern int suid_dumpable;
95133@@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
95134
95135 /* Constants used for minimum and maximum */
95136 #ifdef CONFIG_LOCKUP_DETECTOR
95137-static int sixty = 60;
95138+static int sixty __read_only = 60;
95139 #endif
95140
95141-static int __maybe_unused neg_one = -1;
95142+static int __maybe_unused neg_one __read_only = -1;
95143
95144-static int zero;
95145-static int __maybe_unused one = 1;
95146-static int __maybe_unused two = 2;
95147-static int __maybe_unused four = 4;
95148-static unsigned long one_ul = 1;
95149-static int one_hundred = 100;
95150+static int zero __read_only = 0;
95151+static int __maybe_unused one __read_only = 1;
95152+static int __maybe_unused two __read_only = 2;
95153+static int __maybe_unused three __read_only = 3;
95154+static int __maybe_unused four __read_only = 4;
95155+static unsigned long one_ul __read_only = 1;
95156+static int one_hundred __read_only = 100;
95157 #ifdef CONFIG_PRINTK
95158-static int ten_thousand = 10000;
95159+static int ten_thousand __read_only = 10000;
95160 #endif
95161
95162 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
95163@@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
95164 void __user *buffer, size_t *lenp, loff_t *ppos);
95165 #endif
95166
95167-#ifdef CONFIG_PRINTK
95168 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
95169 void __user *buffer, size_t *lenp, loff_t *ppos);
95170-#endif
95171
95172 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
95173 void __user *buffer, size_t *lenp, loff_t *ppos);
95174@@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
95175
95176 #endif
95177
95178+extern struct ctl_table grsecurity_table[];
95179+
95180 static struct ctl_table kern_table[];
95181 static struct ctl_table vm_table[];
95182 static struct ctl_table fs_table[];
95183@@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
95184 int sysctl_legacy_va_layout;
95185 #endif
95186
95187+#ifdef CONFIG_PAX_SOFTMODE
95188+static ctl_table pax_table[] = {
95189+ {
95190+ .procname = "softmode",
95191+ .data = &pax_softmode,
95192+ .maxlen = sizeof(unsigned int),
95193+ .mode = 0600,
95194+ .proc_handler = &proc_dointvec,
95195+ },
95196+
95197+ { }
95198+};
95199+#endif
95200+
95201 /* The default sysctl tables: */
95202
95203 static struct ctl_table sysctl_base_table[] = {
95204@@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
95205 #endif
95206
95207 static struct ctl_table kern_table[] = {
95208+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
95209+ {
95210+ .procname = "grsecurity",
95211+ .mode = 0500,
95212+ .child = grsecurity_table,
95213+ },
95214+#endif
95215+
95216+#ifdef CONFIG_PAX_SOFTMODE
95217+ {
95218+ .procname = "pax",
95219+ .mode = 0500,
95220+ .child = pax_table,
95221+ },
95222+#endif
95223+
95224 {
95225 .procname = "sched_child_runs_first",
95226 .data = &sysctl_sched_child_runs_first,
95227@@ -641,7 +671,7 @@ static struct ctl_table kern_table[] = {
95228 .data = &modprobe_path,
95229 .maxlen = KMOD_PATH_LEN,
95230 .mode = 0644,
95231- .proc_handler = proc_dostring,
95232+ .proc_handler = proc_dostring_modpriv,
95233 },
95234 {
95235 .procname = "modules_disabled",
95236@@ -808,16 +838,20 @@ static struct ctl_table kern_table[] = {
95237 .extra1 = &zero,
95238 .extra2 = &one,
95239 },
95240+#endif
95241 {
95242 .procname = "kptr_restrict",
95243 .data = &kptr_restrict,
95244 .maxlen = sizeof(int),
95245 .mode = 0644,
95246 .proc_handler = proc_dointvec_minmax_sysadmin,
95247+#ifdef CONFIG_GRKERNSEC_HIDESYM
95248+ .extra1 = &two,
95249+#else
95250 .extra1 = &zero,
95251+#endif
95252 .extra2 = &two,
95253 },
95254-#endif
95255 {
95256 .procname = "ngroups_max",
95257 .data = &ngroups_max,
95258@@ -1073,10 +1107,17 @@ static struct ctl_table kern_table[] = {
95259 */
95260 {
95261 .procname = "perf_event_paranoid",
95262- .data = &sysctl_perf_event_paranoid,
95263- .maxlen = sizeof(sysctl_perf_event_paranoid),
95264+ .data = &sysctl_perf_event_legitimately_concerned,
95265+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
95266 .mode = 0644,
95267- .proc_handler = proc_dointvec,
95268+ /* go ahead, be a hero */
95269+ .proc_handler = proc_dointvec_minmax_sysadmin,
95270+ .extra1 = &neg_one,
95271+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
95272+ .extra2 = &three,
95273+#else
95274+ .extra2 = &two,
95275+#endif
95276 },
95277 {
95278 .procname = "perf_event_mlock_kb",
95279@@ -1338,6 +1379,13 @@ static struct ctl_table vm_table[] = {
95280 .proc_handler = proc_dointvec_minmax,
95281 .extra1 = &zero,
95282 },
95283+ {
95284+ .procname = "heap_stack_gap",
95285+ .data = &sysctl_heap_stack_gap,
95286+ .maxlen = sizeof(sysctl_heap_stack_gap),
95287+ .mode = 0644,
95288+ .proc_handler = proc_doulongvec_minmax,
95289+ },
95290 #else
95291 {
95292 .procname = "nr_trim_pages",
95293@@ -1827,6 +1875,16 @@ int proc_dostring(struct ctl_table *table, int write,
95294 (char __user *)buffer, lenp, ppos);
95295 }
95296
95297+int proc_dostring_modpriv(struct ctl_table *table, int write,
95298+ void __user *buffer, size_t *lenp, loff_t *ppos)
95299+{
95300+ if (write && !capable(CAP_SYS_MODULE))
95301+ return -EPERM;
95302+
95303+ return _proc_do_string(table->data, table->maxlen, write,
95304+ buffer, lenp, ppos);
95305+}
95306+
95307 static size_t proc_skip_spaces(char **buf)
95308 {
95309 size_t ret;
95310@@ -1932,6 +1990,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
95311 len = strlen(tmp);
95312 if (len > *size)
95313 len = *size;
95314+ if (len > sizeof(tmp))
95315+ len = sizeof(tmp);
95316 if (copy_to_user(*buf, tmp, len))
95317 return -EFAULT;
95318 *size -= len;
95319@@ -2109,7 +2169,7 @@ int proc_dointvec(struct ctl_table *table, int write,
95320 static int proc_taint(struct ctl_table *table, int write,
95321 void __user *buffer, size_t *lenp, loff_t *ppos)
95322 {
95323- struct ctl_table t;
95324+ ctl_table_no_const t;
95325 unsigned long tmptaint = get_taint();
95326 int err;
95327
95328@@ -2137,7 +2197,6 @@ static int proc_taint(struct ctl_table *table, int write,
95329 return err;
95330 }
95331
95332-#ifdef CONFIG_PRINTK
95333 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
95334 void __user *buffer, size_t *lenp, loff_t *ppos)
95335 {
95336@@ -2146,7 +2205,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
95337
95338 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
95339 }
95340-#endif
95341
95342 struct do_proc_dointvec_minmax_conv_param {
95343 int *min;
95344@@ -2706,6 +2764,12 @@ int proc_dostring(struct ctl_table *table, int write,
95345 return -ENOSYS;
95346 }
95347
95348+int proc_dostring_modpriv(struct ctl_table *table, int write,
95349+ void __user *buffer, size_t *lenp, loff_t *ppos)
95350+{
95351+ return -ENOSYS;
95352+}
95353+
95354 int proc_dointvec(struct ctl_table *table, int write,
95355 void __user *buffer, size_t *lenp, loff_t *ppos)
95356 {
95357@@ -2762,5 +2826,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
95358 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
95359 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
95360 EXPORT_SYMBOL(proc_dostring);
95361+EXPORT_SYMBOL(proc_dostring_modpriv);
95362 EXPORT_SYMBOL(proc_doulongvec_minmax);
95363 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
95364diff --git a/kernel/taskstats.c b/kernel/taskstats.c
95365index 13d2f7c..c93d0b0 100644
95366--- a/kernel/taskstats.c
95367+++ b/kernel/taskstats.c
95368@@ -28,9 +28,12 @@
95369 #include <linux/fs.h>
95370 #include <linux/file.h>
95371 #include <linux/pid_namespace.h>
95372+#include <linux/grsecurity.h>
95373 #include <net/genetlink.h>
95374 #include <linux/atomic.h>
95375
95376+extern int gr_is_taskstats_denied(int pid);
95377+
95378 /*
95379 * Maximum length of a cpumask that can be specified in
95380 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
95381@@ -576,6 +579,9 @@ err:
95382
95383 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
95384 {
95385+ if (gr_is_taskstats_denied(current->pid))
95386+ return -EACCES;
95387+
95388 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
95389 return cmd_attr_register_cpumask(info);
95390 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
95391diff --git a/kernel/time.c b/kernel/time.c
95392index 7c7964c..2a0d412 100644
95393--- a/kernel/time.c
95394+++ b/kernel/time.c
95395@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
95396 return error;
95397
95398 if (tz) {
95399+ /* we log in do_settimeofday called below, so don't log twice
95400+ */
95401+ if (!tv)
95402+ gr_log_timechange();
95403+
95404 sys_tz = *tz;
95405 update_vsyscall_tz();
95406 if (firsttime) {
95407diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
95408index fe75444..190c528 100644
95409--- a/kernel/time/alarmtimer.c
95410+++ b/kernel/time/alarmtimer.c
95411@@ -811,7 +811,7 @@ static int __init alarmtimer_init(void)
95412 struct platform_device *pdev;
95413 int error = 0;
95414 int i;
95415- struct k_clock alarm_clock = {
95416+ static struct k_clock alarm_clock = {
95417 .clock_getres = alarm_clock_getres,
95418 .clock_get = alarm_clock_get,
95419 .timer_create = alarm_timer_create,
95420diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
95421index 32d8d6a..11486af 100644
95422--- a/kernel/time/timekeeping.c
95423+++ b/kernel/time/timekeeping.c
95424@@ -15,6 +15,7 @@
95425 #include <linux/init.h>
95426 #include <linux/mm.h>
95427 #include <linux/sched.h>
95428+#include <linux/grsecurity.h>
95429 #include <linux/syscore_ops.h>
95430 #include <linux/clocksource.h>
95431 #include <linux/jiffies.h>
95432@@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
95433 if (!timespec_valid_strict(tv))
95434 return -EINVAL;
95435
95436+ gr_log_timechange();
95437+
95438 raw_spin_lock_irqsave(&timekeeper_lock, flags);
95439 write_seqcount_begin(&timekeeper_seq);
95440
95441diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
95442index 61ed862..3b52c65 100644
95443--- a/kernel/time/timer_list.c
95444+++ b/kernel/time/timer_list.c
95445@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
95446
95447 static void print_name_offset(struct seq_file *m, void *sym)
95448 {
95449+#ifdef CONFIG_GRKERNSEC_HIDESYM
95450+ SEQ_printf(m, "<%p>", NULL);
95451+#else
95452 char symname[KSYM_NAME_LEN];
95453
95454 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
95455 SEQ_printf(m, "<%pK>", sym);
95456 else
95457 SEQ_printf(m, "%s", symname);
95458+#endif
95459 }
95460
95461 static void
95462@@ -119,7 +123,11 @@ next_one:
95463 static void
95464 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
95465 {
95466+#ifdef CONFIG_GRKERNSEC_HIDESYM
95467+ SEQ_printf(m, " .base: %p\n", NULL);
95468+#else
95469 SEQ_printf(m, " .base: %pK\n", base);
95470+#endif
95471 SEQ_printf(m, " .index: %d\n",
95472 base->index);
95473 SEQ_printf(m, " .resolution: %Lu nsecs\n",
95474@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
95475 {
95476 struct proc_dir_entry *pe;
95477
95478+#ifdef CONFIG_GRKERNSEC_PROC_ADD
95479+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
95480+#else
95481 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
95482+#endif
95483 if (!pe)
95484 return -ENOMEM;
95485 return 0;
95486diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
95487index 1fb08f2..ca4bb1e 100644
95488--- a/kernel/time/timer_stats.c
95489+++ b/kernel/time/timer_stats.c
95490@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
95491 static unsigned long nr_entries;
95492 static struct entry entries[MAX_ENTRIES];
95493
95494-static atomic_t overflow_count;
95495+static atomic_unchecked_t overflow_count;
95496
95497 /*
95498 * The entries are in a hash-table, for fast lookup:
95499@@ -140,7 +140,7 @@ static void reset_entries(void)
95500 nr_entries = 0;
95501 memset(entries, 0, sizeof(entries));
95502 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
95503- atomic_set(&overflow_count, 0);
95504+ atomic_set_unchecked(&overflow_count, 0);
95505 }
95506
95507 static struct entry *alloc_entry(void)
95508@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
95509 if (likely(entry))
95510 entry->count++;
95511 else
95512- atomic_inc(&overflow_count);
95513+ atomic_inc_unchecked(&overflow_count);
95514
95515 out_unlock:
95516 raw_spin_unlock_irqrestore(lock, flags);
95517@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
95518
95519 static void print_name_offset(struct seq_file *m, unsigned long addr)
95520 {
95521+#ifdef CONFIG_GRKERNSEC_HIDESYM
95522+ seq_printf(m, "<%p>", NULL);
95523+#else
95524 char symname[KSYM_NAME_LEN];
95525
95526 if (lookup_symbol_name(addr, symname) < 0)
95527- seq_printf(m, "<%p>", (void *)addr);
95528+ seq_printf(m, "<%pK>", (void *)addr);
95529 else
95530 seq_printf(m, "%s", symname);
95531+#endif
95532 }
95533
95534 static int tstats_show(struct seq_file *m, void *v)
95535@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
95536
95537 seq_puts(m, "Timer Stats Version: v0.3\n");
95538 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
95539- if (atomic_read(&overflow_count))
95540- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
95541+ if (atomic_read_unchecked(&overflow_count))
95542+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
95543 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
95544
95545 for (i = 0; i < nr_entries; i++) {
95546@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
95547 {
95548 struct proc_dir_entry *pe;
95549
95550+#ifdef CONFIG_GRKERNSEC_PROC_ADD
95551+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
95552+#else
95553 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
95554+#endif
95555 if (!pe)
95556 return -ENOMEM;
95557 return 0;
95558diff --git a/kernel/timer.c b/kernel/timer.c
95559index 3bb01a3..0e7760e 100644
95560--- a/kernel/timer.c
95561+++ b/kernel/timer.c
95562@@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
95563 /*
95564 * This function runs timers and the timer-tq in bottom half context.
95565 */
95566-static void run_timer_softirq(struct softirq_action *h)
95567+static __latent_entropy void run_timer_softirq(void)
95568 {
95569 struct tvec_base *base = __this_cpu_read(tvec_bases);
95570
95571@@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
95572 *
95573 * In all cases the return value is guaranteed to be non-negative.
95574 */
95575-signed long __sched schedule_timeout(signed long timeout)
95576+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
95577 {
95578 struct timer_list timer;
95579 unsigned long expire;
95580diff --git a/kernel/torture.c b/kernel/torture.c
95581index 40bb511..91190b9 100644
95582--- a/kernel/torture.c
95583+++ b/kernel/torture.c
95584@@ -484,7 +484,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
95585 mutex_lock(&fullstop_mutex);
95586 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
95587 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
95588- ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
95589+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
95590 } else {
95591 pr_warn("Concurrent rmmod and shutdown illegal!\n");
95592 }
95593@@ -551,14 +551,14 @@ static int torture_stutter(void *arg)
95594 if (!torture_must_stop()) {
95595 if (stutter > 1) {
95596 schedule_timeout_interruptible(stutter - 1);
95597- ACCESS_ONCE(stutter_pause_test) = 2;
95598+ ACCESS_ONCE_RW(stutter_pause_test) = 2;
95599 }
95600 schedule_timeout_interruptible(1);
95601- ACCESS_ONCE(stutter_pause_test) = 1;
95602+ ACCESS_ONCE_RW(stutter_pause_test) = 1;
95603 }
95604 if (!torture_must_stop())
95605 schedule_timeout_interruptible(stutter);
95606- ACCESS_ONCE(stutter_pause_test) = 0;
95607+ ACCESS_ONCE_RW(stutter_pause_test) = 0;
95608 torture_shutdown_absorb("torture_stutter");
95609 } while (!torture_must_stop());
95610 torture_kthread_stopping("torture_stutter");
95611@@ -645,7 +645,7 @@ bool torture_cleanup(void)
95612 schedule_timeout_uninterruptible(10);
95613 return true;
95614 }
95615- ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
95616+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
95617 mutex_unlock(&fullstop_mutex);
95618 torture_shutdown_cleanup();
95619 torture_shuffle_cleanup();
95620diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
95621index c1bd4ad..4b861dc 100644
95622--- a/kernel/trace/blktrace.c
95623+++ b/kernel/trace/blktrace.c
95624@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
95625 struct blk_trace *bt = filp->private_data;
95626 char buf[16];
95627
95628- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
95629+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
95630
95631 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
95632 }
95633@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
95634 return 1;
95635
95636 bt = buf->chan->private_data;
95637- atomic_inc(&bt->dropped);
95638+ atomic_inc_unchecked(&bt->dropped);
95639 return 0;
95640 }
95641
95642@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
95643
95644 bt->dir = dir;
95645 bt->dev = dev;
95646- atomic_set(&bt->dropped, 0);
95647+ atomic_set_unchecked(&bt->dropped, 0);
95648 INIT_LIST_HEAD(&bt->running_list);
95649
95650 ret = -EIO;
95651diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
95652index ac9d1da..ce98b35 100644
95653--- a/kernel/trace/ftrace.c
95654+++ b/kernel/trace/ftrace.c
95655@@ -1920,12 +1920,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
95656 if (unlikely(ftrace_disabled))
95657 return 0;
95658
95659+ ret = ftrace_arch_code_modify_prepare();
95660+ FTRACE_WARN_ON(ret);
95661+ if (ret)
95662+ return 0;
95663+
95664 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
95665+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
95666 if (ret) {
95667 ftrace_bug(ret, ip);
95668- return 0;
95669 }
95670- return 1;
95671+ return ret ? 0 : 1;
95672 }
95673
95674 /*
95675@@ -4126,8 +4131,10 @@ static int ftrace_process_locs(struct module *mod,
95676 if (!count)
95677 return 0;
95678
95679+ pax_open_kernel();
95680 sort(start, count, sizeof(*start),
95681 ftrace_cmp_ips, ftrace_swap_ips);
95682+ pax_close_kernel();
95683
95684 start_pg = ftrace_allocate_pages(count);
95685 if (!start_pg)
95686diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
95687index ff70271..4242e69 100644
95688--- a/kernel/trace/ring_buffer.c
95689+++ b/kernel/trace/ring_buffer.c
95690@@ -352,9 +352,9 @@ struct buffer_data_page {
95691 */
95692 struct buffer_page {
95693 struct list_head list; /* list of buffer pages */
95694- local_t write; /* index for next write */
95695+ local_unchecked_t write; /* index for next write */
95696 unsigned read; /* index for next read */
95697- local_t entries; /* entries on this page */
95698+ local_unchecked_t entries; /* entries on this page */
95699 unsigned long real_end; /* real end of data */
95700 struct buffer_data_page *page; /* Actual data page */
95701 };
95702@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
95703 unsigned long last_overrun;
95704 local_t entries_bytes;
95705 local_t entries;
95706- local_t overrun;
95707- local_t commit_overrun;
95708+ local_unchecked_t overrun;
95709+ local_unchecked_t commit_overrun;
95710 local_t dropped_events;
95711 local_t committing;
95712 local_t commits;
95713@@ -626,8 +626,22 @@ int ring_buffer_poll_wait(struct ring_buffer *buffer, int cpu,
95714 work = &cpu_buffer->irq_work;
95715 }
95716
95717- work->waiters_pending = true;
95718 poll_wait(filp, &work->waiters, poll_table);
95719+ work->waiters_pending = true;
95720+ /*
95721+ * There's a tight race between setting the waiters_pending and
95722+ * checking if the ring buffer is empty. Once the waiters_pending bit
95723+ * is set, the next event will wake the task up, but we can get stuck
95724+ * if there's only a single event in.
95725+ *
95726+ * FIXME: Ideally, we need a memory barrier on the writer side as well,
95727+ * but adding a memory barrier to all events will cause too much of a
95728+ * performance hit in the fast path. We only need a memory barrier when
95729+ * the buffer goes from empty to having content. But as this race is
95730+ * extremely small, and it's not a problem if another event comes in, we
95731+ * will fix it later.
95732+ */
95733+ smp_mb();
95734
95735 if ((cpu == RING_BUFFER_ALL_CPUS && !ring_buffer_empty(buffer)) ||
95736 (cpu != RING_BUFFER_ALL_CPUS && !ring_buffer_empty_cpu(buffer, cpu)))
95737@@ -991,8 +1005,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
95738 *
95739 * We add a counter to the write field to denote this.
95740 */
95741- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
95742- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
95743+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
95744+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
95745
95746 /*
95747 * Just make sure we have seen our old_write and synchronize
95748@@ -1020,8 +1034,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
95749 * cmpxchg to only update if an interrupt did not already
95750 * do it for us. If the cmpxchg fails, we don't care.
95751 */
95752- (void)local_cmpxchg(&next_page->write, old_write, val);
95753- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
95754+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
95755+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
95756
95757 /*
95758 * No need to worry about races with clearing out the commit.
95759@@ -1388,12 +1402,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
95760
95761 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
95762 {
95763- return local_read(&bpage->entries) & RB_WRITE_MASK;
95764+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
95765 }
95766
95767 static inline unsigned long rb_page_write(struct buffer_page *bpage)
95768 {
95769- return local_read(&bpage->write) & RB_WRITE_MASK;
95770+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
95771 }
95772
95773 static int
95774@@ -1488,7 +1502,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
95775 * bytes consumed in ring buffer from here.
95776 * Increment overrun to account for the lost events.
95777 */
95778- local_add(page_entries, &cpu_buffer->overrun);
95779+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
95780 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
95781 }
95782
95783@@ -2066,7 +2080,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
95784 * it is our responsibility to update
95785 * the counters.
95786 */
95787- local_add(entries, &cpu_buffer->overrun);
95788+ local_add_unchecked(entries, &cpu_buffer->overrun);
95789 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
95790
95791 /*
95792@@ -2216,7 +2230,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
95793 if (tail == BUF_PAGE_SIZE)
95794 tail_page->real_end = 0;
95795
95796- local_sub(length, &tail_page->write);
95797+ local_sub_unchecked(length, &tail_page->write);
95798 return;
95799 }
95800
95801@@ -2251,7 +2265,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
95802 rb_event_set_padding(event);
95803
95804 /* Set the write back to the previous setting */
95805- local_sub(length, &tail_page->write);
95806+ local_sub_unchecked(length, &tail_page->write);
95807 return;
95808 }
95809
95810@@ -2263,7 +2277,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
95811
95812 /* Set write to end of buffer */
95813 length = (tail + length) - BUF_PAGE_SIZE;
95814- local_sub(length, &tail_page->write);
95815+ local_sub_unchecked(length, &tail_page->write);
95816 }
95817
95818 /*
95819@@ -2289,7 +2303,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
95820 * about it.
95821 */
95822 if (unlikely(next_page == commit_page)) {
95823- local_inc(&cpu_buffer->commit_overrun);
95824+ local_inc_unchecked(&cpu_buffer->commit_overrun);
95825 goto out_reset;
95826 }
95827
95828@@ -2345,7 +2359,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
95829 cpu_buffer->tail_page) &&
95830 (cpu_buffer->commit_page ==
95831 cpu_buffer->reader_page))) {
95832- local_inc(&cpu_buffer->commit_overrun);
95833+ local_inc_unchecked(&cpu_buffer->commit_overrun);
95834 goto out_reset;
95835 }
95836 }
95837@@ -2393,7 +2407,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
95838 length += RB_LEN_TIME_EXTEND;
95839
95840 tail_page = cpu_buffer->tail_page;
95841- write = local_add_return(length, &tail_page->write);
95842+ write = local_add_return_unchecked(length, &tail_page->write);
95843
95844 /* set write to only the index of the write */
95845 write &= RB_WRITE_MASK;
95846@@ -2417,7 +2431,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
95847 kmemcheck_annotate_bitfield(event, bitfield);
95848 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
95849
95850- local_inc(&tail_page->entries);
95851+ local_inc_unchecked(&tail_page->entries);
95852
95853 /*
95854 * If this is the first commit on the page, then update
95855@@ -2450,7 +2464,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
95856
95857 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
95858 unsigned long write_mask =
95859- local_read(&bpage->write) & ~RB_WRITE_MASK;
95860+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
95861 unsigned long event_length = rb_event_length(event);
95862 /*
95863 * This is on the tail page. It is possible that
95864@@ -2460,7 +2474,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
95865 */
95866 old_index += write_mask;
95867 new_index += write_mask;
95868- index = local_cmpxchg(&bpage->write, old_index, new_index);
95869+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
95870 if (index == old_index) {
95871 /* update counters */
95872 local_sub(event_length, &cpu_buffer->entries_bytes);
95873@@ -2852,7 +2866,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
95874
95875 /* Do the likely case first */
95876 if (likely(bpage->page == (void *)addr)) {
95877- local_dec(&bpage->entries);
95878+ local_dec_unchecked(&bpage->entries);
95879 return;
95880 }
95881
95882@@ -2864,7 +2878,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
95883 start = bpage;
95884 do {
95885 if (bpage->page == (void *)addr) {
95886- local_dec(&bpage->entries);
95887+ local_dec_unchecked(&bpage->entries);
95888 return;
95889 }
95890 rb_inc_page(cpu_buffer, &bpage);
95891@@ -3148,7 +3162,7 @@ static inline unsigned long
95892 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
95893 {
95894 return local_read(&cpu_buffer->entries) -
95895- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
95896+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
95897 }
95898
95899 /**
95900@@ -3237,7 +3251,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
95901 return 0;
95902
95903 cpu_buffer = buffer->buffers[cpu];
95904- ret = local_read(&cpu_buffer->overrun);
95905+ ret = local_read_unchecked(&cpu_buffer->overrun);
95906
95907 return ret;
95908 }
95909@@ -3260,7 +3274,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
95910 return 0;
95911
95912 cpu_buffer = buffer->buffers[cpu];
95913- ret = local_read(&cpu_buffer->commit_overrun);
95914+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
95915
95916 return ret;
95917 }
95918@@ -3345,7 +3359,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
95919 /* if you care about this being correct, lock the buffer */
95920 for_each_buffer_cpu(buffer, cpu) {
95921 cpu_buffer = buffer->buffers[cpu];
95922- overruns += local_read(&cpu_buffer->overrun);
95923+ overruns += local_read_unchecked(&cpu_buffer->overrun);
95924 }
95925
95926 return overruns;
95927@@ -3521,8 +3535,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
95928 /*
95929 * Reset the reader page to size zero.
95930 */
95931- local_set(&cpu_buffer->reader_page->write, 0);
95932- local_set(&cpu_buffer->reader_page->entries, 0);
95933+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
95934+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
95935 local_set(&cpu_buffer->reader_page->page->commit, 0);
95936 cpu_buffer->reader_page->real_end = 0;
95937
95938@@ -3556,7 +3570,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
95939 * want to compare with the last_overrun.
95940 */
95941 smp_mb();
95942- overwrite = local_read(&(cpu_buffer->overrun));
95943+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
95944
95945 /*
95946 * Here's the tricky part.
95947@@ -4126,8 +4140,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
95948
95949 cpu_buffer->head_page
95950 = list_entry(cpu_buffer->pages, struct buffer_page, list);
95951- local_set(&cpu_buffer->head_page->write, 0);
95952- local_set(&cpu_buffer->head_page->entries, 0);
95953+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
95954+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
95955 local_set(&cpu_buffer->head_page->page->commit, 0);
95956
95957 cpu_buffer->head_page->read = 0;
95958@@ -4137,14 +4151,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
95959
95960 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
95961 INIT_LIST_HEAD(&cpu_buffer->new_pages);
95962- local_set(&cpu_buffer->reader_page->write, 0);
95963- local_set(&cpu_buffer->reader_page->entries, 0);
95964+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
95965+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
95966 local_set(&cpu_buffer->reader_page->page->commit, 0);
95967 cpu_buffer->reader_page->read = 0;
95968
95969 local_set(&cpu_buffer->entries_bytes, 0);
95970- local_set(&cpu_buffer->overrun, 0);
95971- local_set(&cpu_buffer->commit_overrun, 0);
95972+ local_set_unchecked(&cpu_buffer->overrun, 0);
95973+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
95974 local_set(&cpu_buffer->dropped_events, 0);
95975 local_set(&cpu_buffer->entries, 0);
95976 local_set(&cpu_buffer->committing, 0);
95977@@ -4549,8 +4563,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
95978 rb_init_page(bpage);
95979 bpage = reader->page;
95980 reader->page = *data_page;
95981- local_set(&reader->write, 0);
95982- local_set(&reader->entries, 0);
95983+ local_set_unchecked(&reader->write, 0);
95984+ local_set_unchecked(&reader->entries, 0);
95985 reader->read = 0;
95986 *data_page = bpage;
95987
95988diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
95989index 291397e..db3836d 100644
95990--- a/kernel/trace/trace.c
95991+++ b/kernel/trace/trace.c
95992@@ -3510,7 +3510,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
95993 return 0;
95994 }
95995
95996-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
95997+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
95998 {
95999 /* do nothing if flag is already set */
96000 if (!!(trace_flags & mask) == !!enabled)
96001diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
96002index 9258f5a..9b1e41e 100644
96003--- a/kernel/trace/trace.h
96004+++ b/kernel/trace/trace.h
96005@@ -1278,7 +1278,7 @@ extern const char *__stop___tracepoint_str[];
96006 void trace_printk_init_buffers(void);
96007 void trace_printk_start_comm(void);
96008 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
96009-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
96010+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
96011
96012 /*
96013 * Normal trace_printk() and friends allocates special buffers
96014diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
96015index 57b67b1..66082a9 100644
96016--- a/kernel/trace/trace_clock.c
96017+++ b/kernel/trace/trace_clock.c
96018@@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
96019 return now;
96020 }
96021
96022-static atomic64_t trace_counter;
96023+static atomic64_unchecked_t trace_counter;
96024
96025 /*
96026 * trace_clock_counter(): simply an atomic counter.
96027@@ -133,5 +133,5 @@ static atomic64_t trace_counter;
96028 */
96029 u64 notrace trace_clock_counter(void)
96030 {
96031- return atomic64_add_return(1, &trace_counter);
96032+ return atomic64_inc_return_unchecked(&trace_counter);
96033 }
96034diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
96035index 2de5362..c4c7003 100644
96036--- a/kernel/trace/trace_events.c
96037+++ b/kernel/trace/trace_events.c
96038@@ -1722,7 +1722,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
96039 return 0;
96040 }
96041
96042-struct ftrace_module_file_ops;
96043 static void __add_event_to_tracers(struct ftrace_event_call *call);
96044
96045 /* Add an additional event_call dynamically */
96046diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
96047index 0abd9b8..6a663a2 100644
96048--- a/kernel/trace/trace_mmiotrace.c
96049+++ b/kernel/trace/trace_mmiotrace.c
96050@@ -24,7 +24,7 @@ struct header_iter {
96051 static struct trace_array *mmio_trace_array;
96052 static bool overrun_detected;
96053 static unsigned long prev_overruns;
96054-static atomic_t dropped_count;
96055+static atomic_unchecked_t dropped_count;
96056
96057 static void mmio_reset_data(struct trace_array *tr)
96058 {
96059@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
96060
96061 static unsigned long count_overruns(struct trace_iterator *iter)
96062 {
96063- unsigned long cnt = atomic_xchg(&dropped_count, 0);
96064+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
96065 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
96066
96067 if (over > prev_overruns)
96068@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
96069 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
96070 sizeof(*entry), 0, pc);
96071 if (!event) {
96072- atomic_inc(&dropped_count);
96073+ atomic_inc_unchecked(&dropped_count);
96074 return;
96075 }
96076 entry = ring_buffer_event_data(event);
96077@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
96078 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
96079 sizeof(*entry), 0, pc);
96080 if (!event) {
96081- atomic_inc(&dropped_count);
96082+ atomic_inc_unchecked(&dropped_count);
96083 return;
96084 }
96085 entry = ring_buffer_event_data(event);
96086diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
96087index f3dad80..d291d61 100644
96088--- a/kernel/trace/trace_output.c
96089+++ b/kernel/trace/trace_output.c
96090@@ -322,7 +322,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
96091
96092 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
96093 if (!IS_ERR(p)) {
96094- p = mangle_path(s->buffer + s->len, p, "\n");
96095+ p = mangle_path(s->buffer + s->len, p, "\n\\");
96096 if (p) {
96097 s->len = p - s->buffer;
96098 return 1;
96099@@ -980,14 +980,16 @@ int register_ftrace_event(struct trace_event *event)
96100 goto out;
96101 }
96102
96103+ pax_open_kernel();
96104 if (event->funcs->trace == NULL)
96105- event->funcs->trace = trace_nop_print;
96106+ *(void **)&event->funcs->trace = trace_nop_print;
96107 if (event->funcs->raw == NULL)
96108- event->funcs->raw = trace_nop_print;
96109+ *(void **)&event->funcs->raw = trace_nop_print;
96110 if (event->funcs->hex == NULL)
96111- event->funcs->hex = trace_nop_print;
96112+ *(void **)&event->funcs->hex = trace_nop_print;
96113 if (event->funcs->binary == NULL)
96114- event->funcs->binary = trace_nop_print;
96115+ *(void **)&event->funcs->binary = trace_nop_print;
96116+ pax_close_kernel();
96117
96118 key = event->type & (EVENT_HASHSIZE - 1);
96119
96120diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
96121index 8a4e5cb..64f270d 100644
96122--- a/kernel/trace/trace_stack.c
96123+++ b/kernel/trace/trace_stack.c
96124@@ -91,7 +91,7 @@ check_stack(unsigned long ip, unsigned long *stack)
96125 return;
96126
96127 /* we do not handle interrupt stacks yet */
96128- if (!object_is_on_stack(stack))
96129+ if (!object_starts_on_stack(stack))
96130 return;
96131
96132 local_irq_save(flags);
96133diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
96134index fcc0256..aee880f 100644
96135--- a/kernel/user_namespace.c
96136+++ b/kernel/user_namespace.c
96137@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
96138 !kgid_has_mapping(parent_ns, group))
96139 return -EPERM;
96140
96141+#ifdef CONFIG_GRKERNSEC
96142+ /*
96143+ * This doesn't really inspire confidence:
96144+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
96145+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
96146+ * Increases kernel attack surface in areas developers
96147+ * previously cared little about ("low importance due
96148+ * to requiring "root" capability")
96149+ * To be removed when this code receives *proper* review
96150+ */
96151+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
96152+ !capable(CAP_SETGID))
96153+ return -EPERM;
96154+#endif
96155+
96156 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
96157 if (!ns)
96158 return -ENOMEM;
96159@@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
96160 if (atomic_read(&current->mm->mm_users) > 1)
96161 return -EINVAL;
96162
96163- if (current->fs->users != 1)
96164+ if (atomic_read(&current->fs->users) != 1)
96165 return -EINVAL;
96166
96167 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
96168diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
96169index c8eac43..4b5f08f 100644
96170--- a/kernel/utsname_sysctl.c
96171+++ b/kernel/utsname_sysctl.c
96172@@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
96173 static int proc_do_uts_string(struct ctl_table *table, int write,
96174 void __user *buffer, size_t *lenp, loff_t *ppos)
96175 {
96176- struct ctl_table uts_table;
96177+ ctl_table_no_const uts_table;
96178 int r;
96179 memcpy(&uts_table, table, sizeof(uts_table));
96180 uts_table.data = get_uts(table, write);
96181diff --git a/kernel/watchdog.c b/kernel/watchdog.c
96182index c3319bd..67efc3c 100644
96183--- a/kernel/watchdog.c
96184+++ b/kernel/watchdog.c
96185@@ -518,7 +518,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
96186 static void watchdog_nmi_disable(unsigned int cpu) { return; }
96187 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
96188
96189-static struct smp_hotplug_thread watchdog_threads = {
96190+static struct smp_hotplug_thread watchdog_threads __read_only = {
96191 .store = &softlockup_watchdog,
96192 .thread_should_run = watchdog_should_run,
96193 .thread_fn = watchdog,
96194diff --git a/kernel/workqueue.c b/kernel/workqueue.c
96195index 35974ac..43c9e87 100644
96196--- a/kernel/workqueue.c
96197+++ b/kernel/workqueue.c
96198@@ -4576,7 +4576,7 @@ static void rebind_workers(struct worker_pool *pool)
96199 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
96200 worker_flags |= WORKER_REBOUND;
96201 worker_flags &= ~WORKER_UNBOUND;
96202- ACCESS_ONCE(worker->flags) = worker_flags;
96203+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
96204 }
96205
96206 spin_unlock_irq(&pool->lock);
96207diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
96208index 7a638aa..20db901 100644
96209--- a/lib/Kconfig.debug
96210+++ b/lib/Kconfig.debug
96211@@ -858,7 +858,7 @@ config DEBUG_MUTEXES
96212
96213 config DEBUG_WW_MUTEX_SLOWPATH
96214 bool "Wait/wound mutex debugging: Slowpath testing"
96215- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
96216+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
96217 select DEBUG_LOCK_ALLOC
96218 select DEBUG_SPINLOCK
96219 select DEBUG_MUTEXES
96220@@ -871,7 +871,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
96221
96222 config DEBUG_LOCK_ALLOC
96223 bool "Lock debugging: detect incorrect freeing of live locks"
96224- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
96225+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
96226 select DEBUG_SPINLOCK
96227 select DEBUG_MUTEXES
96228 select LOCKDEP
96229@@ -885,7 +885,7 @@ config DEBUG_LOCK_ALLOC
96230
96231 config PROVE_LOCKING
96232 bool "Lock debugging: prove locking correctness"
96233- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
96234+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
96235 select LOCKDEP
96236 select DEBUG_SPINLOCK
96237 select DEBUG_MUTEXES
96238@@ -936,7 +936,7 @@ config LOCKDEP
96239
96240 config LOCK_STAT
96241 bool "Lock usage statistics"
96242- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
96243+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
96244 select LOCKDEP
96245 select DEBUG_SPINLOCK
96246 select DEBUG_MUTEXES
96247@@ -1418,6 +1418,7 @@ config LATENCYTOP
96248 depends on DEBUG_KERNEL
96249 depends on STACKTRACE_SUPPORT
96250 depends on PROC_FS
96251+ depends on !GRKERNSEC_HIDESYM
96252 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
96253 select KALLSYMS
96254 select KALLSYMS_ALL
96255@@ -1434,7 +1435,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
96256 config DEBUG_STRICT_USER_COPY_CHECKS
96257 bool "Strict user copy size checks"
96258 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
96259- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
96260+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
96261 help
96262 Enabling this option turns a certain set of sanity checks for user
96263 copy operations into compile time failures.
96264@@ -1554,7 +1555,7 @@ endmenu # runtime tests
96265
96266 config PROVIDE_OHCI1394_DMA_INIT
96267 bool "Remote debugging over FireWire early on boot"
96268- depends on PCI && X86
96269+ depends on PCI && X86 && !GRKERNSEC
96270 help
96271 If you want to debug problems which hang or crash the kernel early
96272 on boot and the crashing machine has a FireWire port, you can use
96273diff --git a/lib/Makefile b/lib/Makefile
96274index ba967a1..2cc869a 100644
96275--- a/lib/Makefile
96276+++ b/lib/Makefile
96277@@ -33,7 +33,6 @@ obj-y += kstrtox.o
96278 obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
96279 obj-$(CONFIG_TEST_MODULE) += test_module.o
96280 obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o
96281-obj-$(CONFIG_TEST_BPF) += test_bpf.o
96282
96283 ifeq ($(CONFIG_DEBUG_KOBJECT),y)
96284 CFLAGS_kobject.o += -DDEBUG
96285@@ -54,7 +53,7 @@ obj-$(CONFIG_BTREE) += btree.o
96286 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
96287 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
96288 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
96289-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
96290+obj-y += list_debug.o
96291 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
96292
96293 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
96294diff --git a/lib/average.c b/lib/average.c
96295index 114d1be..ab0350c 100644
96296--- a/lib/average.c
96297+++ b/lib/average.c
96298@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
96299 {
96300 unsigned long internal = ACCESS_ONCE(avg->internal);
96301
96302- ACCESS_ONCE(avg->internal) = internal ?
96303+ ACCESS_ONCE_RW(avg->internal) = internal ?
96304 (((internal << avg->weight) - internal) +
96305 (val << avg->factor)) >> avg->weight :
96306 (val << avg->factor);
96307diff --git a/lib/bitmap.c b/lib/bitmap.c
96308index 06f7e4f..f3cf2b0 100644
96309--- a/lib/bitmap.c
96310+++ b/lib/bitmap.c
96311@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
96312 {
96313 int c, old_c, totaldigits, ndigits, nchunks, nbits;
96314 u32 chunk;
96315- const char __user __force *ubuf = (const char __user __force *)buf;
96316+ const char __user *ubuf = (const char __force_user *)buf;
96317
96318 bitmap_zero(maskp, nmaskbits);
96319
96320@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
96321 {
96322 if (!access_ok(VERIFY_READ, ubuf, ulen))
96323 return -EFAULT;
96324- return __bitmap_parse((const char __force *)ubuf,
96325+ return __bitmap_parse((const char __force_kernel *)ubuf,
96326 ulen, 1, maskp, nmaskbits);
96327
96328 }
96329@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
96330 {
96331 unsigned a, b;
96332 int c, old_c, totaldigits;
96333- const char __user __force *ubuf = (const char __user __force *)buf;
96334+ const char __user *ubuf = (const char __force_user *)buf;
96335 int exp_digit, in_range;
96336
96337 totaldigits = c = 0;
96338@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
96339 {
96340 if (!access_ok(VERIFY_READ, ubuf, ulen))
96341 return -EFAULT;
96342- return __bitmap_parselist((const char __force *)ubuf,
96343+ return __bitmap_parselist((const char __force_kernel *)ubuf,
96344 ulen, 1, maskp, nmaskbits);
96345 }
96346 EXPORT_SYMBOL(bitmap_parselist_user);
96347diff --git a/lib/bug.c b/lib/bug.c
96348index d1d7c78..b354235 100644
96349--- a/lib/bug.c
96350+++ b/lib/bug.c
96351@@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
96352 return BUG_TRAP_TYPE_NONE;
96353
96354 bug = find_bug(bugaddr);
96355+ if (!bug)
96356+ return BUG_TRAP_TYPE_NONE;
96357
96358 file = NULL;
96359 line = 0;
96360diff --git a/lib/debugobjects.c b/lib/debugobjects.c
96361index 547f7f9..a6d4ba0 100644
96362--- a/lib/debugobjects.c
96363+++ b/lib/debugobjects.c
96364@@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
96365 if (limit > 4)
96366 return;
96367
96368- is_on_stack = object_is_on_stack(addr);
96369+ is_on_stack = object_starts_on_stack(addr);
96370 if (is_on_stack == onstack)
96371 return;
96372
96373diff --git a/lib/div64.c b/lib/div64.c
96374index 4382ad7..08aa558 100644
96375--- a/lib/div64.c
96376+++ b/lib/div64.c
96377@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
96378 EXPORT_SYMBOL(__div64_32);
96379
96380 #ifndef div_s64_rem
96381-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
96382+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
96383 {
96384 u64 quotient;
96385
96386@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
96387 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
96388 */
96389 #ifndef div64_u64
96390-u64 div64_u64(u64 dividend, u64 divisor)
96391+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
96392 {
96393 u32 high = divisor >> 32;
96394 u64 quot;
96395diff --git a/lib/dma-debug.c b/lib/dma-debug.c
96396index 98f2d7e..899da5c 100644
96397--- a/lib/dma-debug.c
96398+++ b/lib/dma-debug.c
96399@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
96400
96401 void dma_debug_add_bus(struct bus_type *bus)
96402 {
96403- struct notifier_block *nb;
96404+ notifier_block_no_const *nb;
96405
96406 if (global_disable)
96407 return;
96408@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
96409
96410 static void check_for_stack(struct device *dev, void *addr)
96411 {
96412- if (object_is_on_stack(addr))
96413+ if (object_starts_on_stack(addr))
96414 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
96415 "stack [addr=%p]\n", addr);
96416 }
96417diff --git a/lib/hash.c b/lib/hash.c
96418index fea973f..386626f 100644
96419--- a/lib/hash.c
96420+++ b/lib/hash.c
96421@@ -14,7 +14,7 @@
96422 #include <linux/hash.h>
96423 #include <linux/cache.h>
96424
96425-static struct fast_hash_ops arch_hash_ops __read_mostly = {
96426+static struct fast_hash_ops arch_hash_ops __read_only = {
96427 .hash = jhash,
96428 .hash2 = jhash2,
96429 };
96430diff --git a/lib/inflate.c b/lib/inflate.c
96431index 013a761..c28f3fc 100644
96432--- a/lib/inflate.c
96433+++ b/lib/inflate.c
96434@@ -269,7 +269,7 @@ static void free(void *where)
96435 malloc_ptr = free_mem_ptr;
96436 }
96437 #else
96438-#define malloc(a) kmalloc(a, GFP_KERNEL)
96439+#define malloc(a) kmalloc((a), GFP_KERNEL)
96440 #define free(a) kfree(a)
96441 #endif
96442
96443diff --git a/lib/ioremap.c b/lib/ioremap.c
96444index 0c9216c..863bd89 100644
96445--- a/lib/ioremap.c
96446+++ b/lib/ioremap.c
96447@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
96448 unsigned long next;
96449
96450 phys_addr -= addr;
96451- pmd = pmd_alloc(&init_mm, pud, addr);
96452+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96453 if (!pmd)
96454 return -ENOMEM;
96455 do {
96456@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
96457 unsigned long next;
96458
96459 phys_addr -= addr;
96460- pud = pud_alloc(&init_mm, pgd, addr);
96461+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
96462 if (!pud)
96463 return -ENOMEM;
96464 do {
96465diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
96466index bd2bea9..6b3c95e 100644
96467--- a/lib/is_single_threaded.c
96468+++ b/lib/is_single_threaded.c
96469@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
96470 struct task_struct *p, *t;
96471 bool ret;
96472
96473+ if (!mm)
96474+ return true;
96475+
96476 if (atomic_read(&task->signal->live) != 1)
96477 return false;
96478
96479diff --git a/lib/kobject.c b/lib/kobject.c
96480index 58751bb..93a1853 100644
96481--- a/lib/kobject.c
96482+++ b/lib/kobject.c
96483@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
96484
96485
96486 static DEFINE_SPINLOCK(kobj_ns_type_lock);
96487-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
96488+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
96489
96490-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
96491+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
96492 {
96493 enum kobj_ns_type type = ops->type;
96494 int error;
96495diff --git a/lib/list_debug.c b/lib/list_debug.c
96496index c24c2f7..f0296f4 100644
96497--- a/lib/list_debug.c
96498+++ b/lib/list_debug.c
96499@@ -11,7 +11,9 @@
96500 #include <linux/bug.h>
96501 #include <linux/kernel.h>
96502 #include <linux/rculist.h>
96503+#include <linux/mm.h>
96504
96505+#ifdef CONFIG_DEBUG_LIST
96506 /*
96507 * Insert a new entry between two known consecutive entries.
96508 *
96509@@ -19,21 +21,40 @@
96510 * the prev/next entries already!
96511 */
96512
96513+static bool __list_add_debug(struct list_head *new,
96514+ struct list_head *prev,
96515+ struct list_head *next)
96516+{
96517+ if (unlikely(next->prev != prev)) {
96518+ printk(KERN_ERR "list_add corruption. next->prev should be "
96519+ "prev (%p), but was %p. (next=%p).\n",
96520+ prev, next->prev, next);
96521+ BUG();
96522+ return false;
96523+ }
96524+ if (unlikely(prev->next != next)) {
96525+ printk(KERN_ERR "list_add corruption. prev->next should be "
96526+ "next (%p), but was %p. (prev=%p).\n",
96527+ next, prev->next, prev);
96528+ BUG();
96529+ return false;
96530+ }
96531+ if (unlikely(new == prev || new == next)) {
96532+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
96533+ new, prev, next);
96534+ BUG();
96535+ return false;
96536+ }
96537+ return true;
96538+}
96539+
96540 void __list_add(struct list_head *new,
96541- struct list_head *prev,
96542- struct list_head *next)
96543+ struct list_head *prev,
96544+ struct list_head *next)
96545 {
96546- WARN(next->prev != prev,
96547- "list_add corruption. next->prev should be "
96548- "prev (%p), but was %p. (next=%p).\n",
96549- prev, next->prev, next);
96550- WARN(prev->next != next,
96551- "list_add corruption. prev->next should be "
96552- "next (%p), but was %p. (prev=%p).\n",
96553- next, prev->next, prev);
96554- WARN(new == prev || new == next,
96555- "list_add double add: new=%p, prev=%p, next=%p.\n",
96556- new, prev, next);
96557+ if (!__list_add_debug(new, prev, next))
96558+ return;
96559+
96560 next->prev = new;
96561 new->next = next;
96562 new->prev = prev;
96563@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
96564 }
96565 EXPORT_SYMBOL(__list_add);
96566
96567-void __list_del_entry(struct list_head *entry)
96568+static bool __list_del_entry_debug(struct list_head *entry)
96569 {
96570 struct list_head *prev, *next;
96571
96572 prev = entry->prev;
96573 next = entry->next;
96574
96575- if (WARN(next == LIST_POISON1,
96576- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
96577- entry, LIST_POISON1) ||
96578- WARN(prev == LIST_POISON2,
96579- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
96580- entry, LIST_POISON2) ||
96581- WARN(prev->next != entry,
96582- "list_del corruption. prev->next should be %p, "
96583- "but was %p\n", entry, prev->next) ||
96584- WARN(next->prev != entry,
96585- "list_del corruption. next->prev should be %p, "
96586- "but was %p\n", entry, next->prev))
96587+ if (unlikely(next == LIST_POISON1)) {
96588+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
96589+ entry, LIST_POISON1);
96590+ BUG();
96591+ return false;
96592+ }
96593+ if (unlikely(prev == LIST_POISON2)) {
96594+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
96595+ entry, LIST_POISON2);
96596+ BUG();
96597+ return false;
96598+ }
96599+ if (unlikely(entry->prev->next != entry)) {
96600+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
96601+ "but was %p\n", entry, prev->next);
96602+ BUG();
96603+ return false;
96604+ }
96605+ if (unlikely(entry->next->prev != entry)) {
96606+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
96607+ "but was %p\n", entry, next->prev);
96608+ BUG();
96609+ return false;
96610+ }
96611+ return true;
96612+}
96613+
96614+void __list_del_entry(struct list_head *entry)
96615+{
96616+ if (!__list_del_entry_debug(entry))
96617 return;
96618
96619- __list_del(prev, next);
96620+ __list_del(entry->prev, entry->next);
96621 }
96622 EXPORT_SYMBOL(__list_del_entry);
96623
96624@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
96625 void __list_add_rcu(struct list_head *new,
96626 struct list_head *prev, struct list_head *next)
96627 {
96628- WARN(next->prev != prev,
96629- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
96630- prev, next->prev, next);
96631- WARN(prev->next != next,
96632- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
96633- next, prev->next, prev);
96634+ if (!__list_add_debug(new, prev, next))
96635+ return;
96636+
96637 new->next = next;
96638 new->prev = prev;
96639 rcu_assign_pointer(list_next_rcu(prev), new);
96640 next->prev = new;
96641 }
96642 EXPORT_SYMBOL(__list_add_rcu);
96643+#endif
96644+
96645+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
96646+{
96647+#ifdef CONFIG_DEBUG_LIST
96648+ if (!__list_add_debug(new, prev, next))
96649+ return;
96650+#endif
96651+
96652+ pax_open_kernel();
96653+ next->prev = new;
96654+ new->next = next;
96655+ new->prev = prev;
96656+ prev->next = new;
96657+ pax_close_kernel();
96658+}
96659+EXPORT_SYMBOL(__pax_list_add);
96660+
96661+void pax_list_del(struct list_head *entry)
96662+{
96663+#ifdef CONFIG_DEBUG_LIST
96664+ if (!__list_del_entry_debug(entry))
96665+ return;
96666+#endif
96667+
96668+ pax_open_kernel();
96669+ __list_del(entry->prev, entry->next);
96670+ entry->next = LIST_POISON1;
96671+ entry->prev = LIST_POISON2;
96672+ pax_close_kernel();
96673+}
96674+EXPORT_SYMBOL(pax_list_del);
96675+
96676+void pax_list_del_init(struct list_head *entry)
96677+{
96678+ pax_open_kernel();
96679+ __list_del(entry->prev, entry->next);
96680+ INIT_LIST_HEAD(entry);
96681+ pax_close_kernel();
96682+}
96683+EXPORT_SYMBOL(pax_list_del_init);
96684+
96685+void __pax_list_add_rcu(struct list_head *new,
96686+ struct list_head *prev, struct list_head *next)
96687+{
96688+#ifdef CONFIG_DEBUG_LIST
96689+ if (!__list_add_debug(new, prev, next))
96690+ return;
96691+#endif
96692+
96693+ pax_open_kernel();
96694+ new->next = next;
96695+ new->prev = prev;
96696+ rcu_assign_pointer(list_next_rcu(prev), new);
96697+ next->prev = new;
96698+ pax_close_kernel();
96699+}
96700+EXPORT_SYMBOL(__pax_list_add_rcu);
96701+
96702+void pax_list_del_rcu(struct list_head *entry)
96703+{
96704+#ifdef CONFIG_DEBUG_LIST
96705+ if (!__list_del_entry_debug(entry))
96706+ return;
96707+#endif
96708+
96709+ pax_open_kernel();
96710+ __list_del(entry->prev, entry->next);
96711+ entry->next = LIST_POISON1;
96712+ entry->prev = LIST_POISON2;
96713+ pax_close_kernel();
96714+}
96715+EXPORT_SYMBOL(pax_list_del_rcu);
96716diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
96717index 963b703..438bc51 100644
96718--- a/lib/percpu-refcount.c
96719+++ b/lib/percpu-refcount.c
96720@@ -29,7 +29,7 @@
96721 * can't hit 0 before we've added up all the percpu refs.
96722 */
96723
96724-#define PCPU_COUNT_BIAS (1U << 31)
96725+#define PCPU_COUNT_BIAS (1U << 30)
96726
96727 /**
96728 * percpu_ref_init - initialize a percpu refcount
96729diff --git a/lib/radix-tree.c b/lib/radix-tree.c
96730index 3291a8e..346a91e 100644
96731--- a/lib/radix-tree.c
96732+++ b/lib/radix-tree.c
96733@@ -67,7 +67,7 @@ struct radix_tree_preload {
96734 int nr;
96735 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
96736 };
96737-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
96738+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
96739
96740 static inline void *ptr_to_indirect(void *ptr)
96741 {
96742diff --git a/lib/random32.c b/lib/random32.c
96743index fa5da61..35fe9af 100644
96744--- a/lib/random32.c
96745+++ b/lib/random32.c
96746@@ -42,7 +42,7 @@
96747 static void __init prandom_state_selftest(void);
96748 #endif
96749
96750-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
96751+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
96752
96753 /**
96754 * prandom_u32_state - seeded pseudo-random number generator.
96755diff --git a/lib/rbtree.c b/lib/rbtree.c
96756index 65f4eff..2cfa167 100644
96757--- a/lib/rbtree.c
96758+++ b/lib/rbtree.c
96759@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
96760 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
96761
96762 static const struct rb_augment_callbacks dummy_callbacks = {
96763- dummy_propagate, dummy_copy, dummy_rotate
96764+ .propagate = dummy_propagate,
96765+ .copy = dummy_copy,
96766+ .rotate = dummy_rotate
96767 };
96768
96769 void rb_insert_color(struct rb_node *node, struct rb_root *root)
96770diff --git a/lib/show_mem.c b/lib/show_mem.c
96771index 0922579..9d7adb9 100644
96772--- a/lib/show_mem.c
96773+++ b/lib/show_mem.c
96774@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
96775 quicklist_total_size());
96776 #endif
96777 #ifdef CONFIG_MEMORY_FAILURE
96778- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
96779+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
96780 #endif
96781 }
96782diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
96783index bb2b201..46abaf9 100644
96784--- a/lib/strncpy_from_user.c
96785+++ b/lib/strncpy_from_user.c
96786@@ -21,7 +21,7 @@
96787 */
96788 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
96789 {
96790- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96791+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96792 long res = 0;
96793
96794 /*
96795diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
96796index a28df52..3d55877 100644
96797--- a/lib/strnlen_user.c
96798+++ b/lib/strnlen_user.c
96799@@ -26,7 +26,7 @@
96800 */
96801 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
96802 {
96803- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96804+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96805 long align, res = 0;
96806 unsigned long c;
96807
96808diff --git a/lib/swiotlb.c b/lib/swiotlb.c
96809index 4abda07..b9d3765 100644
96810--- a/lib/swiotlb.c
96811+++ b/lib/swiotlb.c
96812@@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
96813
96814 void
96815 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
96816- dma_addr_t dev_addr)
96817+ dma_addr_t dev_addr, struct dma_attrs *attrs)
96818 {
96819 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
96820
96821diff --git a/lib/test_bpf.c b/lib/test_bpf.c
96822deleted file mode 100644
96823index c579e0f..0000000
96824--- a/lib/test_bpf.c
96825+++ /dev/null
96826@@ -1,1929 +0,0 @@
96827-/*
96828- * Testsuite for BPF interpreter and BPF JIT compiler
96829- *
96830- * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
96831- *
96832- * This program is free software; you can redistribute it and/or
96833- * modify it under the terms of version 2 of the GNU General Public
96834- * License as published by the Free Software Foundation.
96835- *
96836- * This program is distributed in the hope that it will be useful, but
96837- * WITHOUT ANY WARRANTY; without even the implied warranty of
96838- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
96839- * General Public License for more details.
96840- */
96841-
96842-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
96843-
96844-#include <linux/init.h>
96845-#include <linux/module.h>
96846-#include <linux/filter.h>
96847-#include <linux/skbuff.h>
96848-#include <linux/netdevice.h>
96849-#include <linux/if_vlan.h>
96850-
96851-/* General test specific settings */
96852-#define MAX_SUBTESTS 3
96853-#define MAX_TESTRUNS 10000
96854-#define MAX_DATA 128
96855-#define MAX_INSNS 512
96856-#define MAX_K 0xffffFFFF
96857-
96858-/* Few constants used to init test 'skb' */
96859-#define SKB_TYPE 3
96860-#define SKB_MARK 0x1234aaaa
96861-#define SKB_HASH 0x1234aaab
96862-#define SKB_QUEUE_MAP 123
96863-#define SKB_VLAN_TCI 0xffff
96864-#define SKB_DEV_IFINDEX 577
96865-#define SKB_DEV_TYPE 588
96866-
96867-/* Redefine REGs to make tests less verbose */
96868-#define R0 BPF_REG_0
96869-#define R1 BPF_REG_1
96870-#define R2 BPF_REG_2
96871-#define R3 BPF_REG_3
96872-#define R4 BPF_REG_4
96873-#define R5 BPF_REG_5
96874-#define R6 BPF_REG_6
96875-#define R7 BPF_REG_7
96876-#define R8 BPF_REG_8
96877-#define R9 BPF_REG_9
96878-#define R10 BPF_REG_10
96879-
96880-/* Flags that can be passed to test cases */
96881-#define FLAG_NO_DATA BIT(0)
96882-#define FLAG_EXPECTED_FAIL BIT(1)
96883-
96884-enum {
96885- CLASSIC = BIT(6), /* Old BPF instructions only. */
96886- INTERNAL = BIT(7), /* Extended instruction set. */
96887-};
96888-
96889-#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
96890-
96891-struct bpf_test {
96892- const char *descr;
96893- union {
96894- struct sock_filter insns[MAX_INSNS];
96895- struct sock_filter_int insns_int[MAX_INSNS];
96896- } u;
96897- __u8 aux;
96898- __u8 data[MAX_DATA];
96899- struct {
96900- int data_size;
96901- __u32 result;
96902- } test[MAX_SUBTESTS];
96903-};
96904-
96905-static struct bpf_test tests[] = {
96906- {
96907- "TAX",
96908- .u.insns = {
96909- BPF_STMT(BPF_LD | BPF_IMM, 1),
96910- BPF_STMT(BPF_MISC | BPF_TAX, 0),
96911- BPF_STMT(BPF_LD | BPF_IMM, 2),
96912- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96913- BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
96914- BPF_STMT(BPF_MISC | BPF_TAX, 0),
96915- BPF_STMT(BPF_LD | BPF_LEN, 0),
96916- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96917- BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
96918- BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
96919- BPF_STMT(BPF_RET | BPF_A, 0)
96920- },
96921- CLASSIC,
96922- { 10, 20, 30, 40, 50 },
96923- { { 2, 10 }, { 3, 20 }, { 4, 30 } },
96924- },
96925- {
96926- "TXA",
96927- .u.insns = {
96928- BPF_STMT(BPF_LDX | BPF_LEN, 0),
96929- BPF_STMT(BPF_MISC | BPF_TXA, 0),
96930- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96931- BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
96932- },
96933- CLASSIC,
96934- { 10, 20, 30, 40, 50 },
96935- { { 1, 2 }, { 3, 6 }, { 4, 8 } },
96936- },
96937- {
96938- "ADD_SUB_MUL_K",
96939- .u.insns = {
96940- BPF_STMT(BPF_LD | BPF_IMM, 1),
96941- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
96942- BPF_STMT(BPF_LDX | BPF_IMM, 3),
96943- BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
96944- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
96945- BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
96946- BPF_STMT(BPF_RET | BPF_A, 0)
96947- },
96948- CLASSIC | FLAG_NO_DATA,
96949- { },
96950- { { 0, 0xfffffffd } }
96951- },
96952- {
96953- "DIV_KX",
96954- .u.insns = {
96955- BPF_STMT(BPF_LD | BPF_IMM, 8),
96956- BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
96957- BPF_STMT(BPF_MISC | BPF_TAX, 0),
96958- BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
96959- BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
96960- BPF_STMT(BPF_MISC | BPF_TAX, 0),
96961- BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
96962- BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
96963- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96964- BPF_STMT(BPF_RET | BPF_A, 0)
96965- },
96966- CLASSIC | FLAG_NO_DATA,
96967- { },
96968- { { 0, 0x40000001 } }
96969- },
96970- {
96971- "AND_OR_LSH_K",
96972- .u.insns = {
96973- BPF_STMT(BPF_LD | BPF_IMM, 0xff),
96974- BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
96975- BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
96976- BPF_STMT(BPF_MISC | BPF_TAX, 0),
96977- BPF_STMT(BPF_LD | BPF_IMM, 0xf),
96978- BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
96979- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96980- BPF_STMT(BPF_RET | BPF_A, 0)
96981- },
96982- CLASSIC | FLAG_NO_DATA,
96983- { },
96984- { { 0, 0x800000ff }, { 1, 0x800000ff } },
96985- },
96986- {
96987- "LD_IMM_0",
96988- .u.insns = {
96989- BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
96990- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
96991- BPF_STMT(BPF_RET | BPF_K, 0),
96992- BPF_STMT(BPF_RET | BPF_K, 1),
96993- },
96994- CLASSIC,
96995- { },
96996- { { 1, 1 } },
96997- },
96998- {
96999- "LD_IND",
97000- .u.insns = {
97001- BPF_STMT(BPF_LDX | BPF_LEN, 0),
97002- BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
97003- BPF_STMT(BPF_RET | BPF_K, 1)
97004- },
97005- CLASSIC,
97006- { },
97007- { { 1, 0 }, { 10, 0 }, { 60, 0 } },
97008- },
97009- {
97010- "LD_ABS",
97011- .u.insns = {
97012- BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
97013- BPF_STMT(BPF_RET | BPF_K, 1)
97014- },
97015- CLASSIC,
97016- { },
97017- { { 1, 0 }, { 10, 0 }, { 60, 0 } },
97018- },
97019- {
97020- "LD_ABS_LL",
97021- .u.insns = {
97022- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
97023- BPF_STMT(BPF_MISC | BPF_TAX, 0),
97024- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
97025- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
97026- BPF_STMT(BPF_RET | BPF_A, 0)
97027- },
97028- CLASSIC,
97029- { 1, 2, 3 },
97030- { { 1, 0 }, { 2, 3 } },
97031- },
97032- {
97033- "LD_IND_LL",
97034- .u.insns = {
97035- BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
97036- BPF_STMT(BPF_LDX | BPF_LEN, 0),
97037- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
97038- BPF_STMT(BPF_MISC | BPF_TAX, 0),
97039- BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
97040- BPF_STMT(BPF_RET | BPF_A, 0)
97041- },
97042- CLASSIC,
97043- { 1, 2, 3, 0xff },
97044- { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
97045- },
97046- {
97047- "LD_ABS_NET",
97048- .u.insns = {
97049- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
97050- BPF_STMT(BPF_MISC | BPF_TAX, 0),
97051- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
97052- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
97053- BPF_STMT(BPF_RET | BPF_A, 0)
97054- },
97055- CLASSIC,
97056- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
97057- { { 15, 0 }, { 16, 3 } },
97058- },
97059- {
97060- "LD_IND_NET",
97061- .u.insns = {
97062- BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
97063- BPF_STMT(BPF_LDX | BPF_LEN, 0),
97064- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
97065- BPF_STMT(BPF_MISC | BPF_TAX, 0),
97066- BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
97067- BPF_STMT(BPF_RET | BPF_A, 0)
97068- },
97069- CLASSIC,
97070- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
97071- { { 14, 0 }, { 15, 1 }, { 17, 3 } },
97072- },
97073- {
97074- "LD_PKTTYPE",
97075- .u.insns = {
97076- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97077- SKF_AD_OFF + SKF_AD_PKTTYPE),
97078- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
97079- BPF_STMT(BPF_RET | BPF_K, 1),
97080- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97081- SKF_AD_OFF + SKF_AD_PKTTYPE),
97082- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
97083- BPF_STMT(BPF_RET | BPF_K, 1),
97084- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97085- SKF_AD_OFF + SKF_AD_PKTTYPE),
97086- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
97087- BPF_STMT(BPF_RET | BPF_K, 1),
97088- BPF_STMT(BPF_RET | BPF_A, 0)
97089- },
97090- CLASSIC,
97091- { },
97092- { { 1, 3 }, { 10, 3 } },
97093- },
97094- {
97095- "LD_MARK",
97096- .u.insns = {
97097- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97098- SKF_AD_OFF + SKF_AD_MARK),
97099- BPF_STMT(BPF_RET | BPF_A, 0)
97100- },
97101- CLASSIC,
97102- { },
97103- { { 1, SKB_MARK}, { 10, SKB_MARK} },
97104- },
97105- {
97106- "LD_RXHASH",
97107- .u.insns = {
97108- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97109- SKF_AD_OFF + SKF_AD_RXHASH),
97110- BPF_STMT(BPF_RET | BPF_A, 0)
97111- },
97112- CLASSIC,
97113- { },
97114- { { 1, SKB_HASH}, { 10, SKB_HASH} },
97115- },
97116- {
97117- "LD_QUEUE",
97118- .u.insns = {
97119- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97120- SKF_AD_OFF + SKF_AD_QUEUE),
97121- BPF_STMT(BPF_RET | BPF_A, 0)
97122- },
97123- CLASSIC,
97124- { },
97125- { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
97126- },
97127- {
97128- "LD_PROTOCOL",
97129- .u.insns = {
97130- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
97131- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
97132- BPF_STMT(BPF_RET | BPF_K, 0),
97133- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97134- SKF_AD_OFF + SKF_AD_PROTOCOL),
97135- BPF_STMT(BPF_MISC | BPF_TAX, 0),
97136- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
97137- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
97138- BPF_STMT(BPF_RET | BPF_K, 0),
97139- BPF_STMT(BPF_MISC | BPF_TXA, 0),
97140- BPF_STMT(BPF_RET | BPF_A, 0)
97141- },
97142- CLASSIC,
97143- { 10, 20, 30 },
97144- { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
97145- },
97146- {
97147- "LD_VLAN_TAG",
97148- .u.insns = {
97149- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97150- SKF_AD_OFF + SKF_AD_VLAN_TAG),
97151- BPF_STMT(BPF_RET | BPF_A, 0)
97152- },
97153- CLASSIC,
97154- { },
97155- {
97156- { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
97157- { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
97158- },
97159- },
97160- {
97161- "LD_VLAN_TAG_PRESENT",
97162- .u.insns = {
97163- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97164- SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
97165- BPF_STMT(BPF_RET | BPF_A, 0)
97166- },
97167- CLASSIC,
97168- { },
97169- {
97170- { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
97171- { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
97172- },
97173- },
97174- {
97175- "LD_IFINDEX",
97176- .u.insns = {
97177- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97178- SKF_AD_OFF + SKF_AD_IFINDEX),
97179- BPF_STMT(BPF_RET | BPF_A, 0)
97180- },
97181- CLASSIC,
97182- { },
97183- { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
97184- },
97185- {
97186- "LD_HATYPE",
97187- .u.insns = {
97188- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97189- SKF_AD_OFF + SKF_AD_HATYPE),
97190- BPF_STMT(BPF_RET | BPF_A, 0)
97191- },
97192- CLASSIC,
97193- { },
97194- { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
97195- },
97196- {
97197- "LD_CPU",
97198- .u.insns = {
97199- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97200- SKF_AD_OFF + SKF_AD_CPU),
97201- BPF_STMT(BPF_MISC | BPF_TAX, 0),
97202- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97203- SKF_AD_OFF + SKF_AD_CPU),
97204- BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
97205- BPF_STMT(BPF_RET | BPF_A, 0)
97206- },
97207- CLASSIC,
97208- { },
97209- { { 1, 0 }, { 10, 0 } },
97210- },
97211- {
97212- "LD_NLATTR",
97213- .u.insns = {
97214- BPF_STMT(BPF_LDX | BPF_IMM, 2),
97215- BPF_STMT(BPF_MISC | BPF_TXA, 0),
97216- BPF_STMT(BPF_LDX | BPF_IMM, 3),
97217- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97218- SKF_AD_OFF + SKF_AD_NLATTR),
97219- BPF_STMT(BPF_RET | BPF_A, 0)
97220- },
97221- CLASSIC,
97222-#ifdef __BIG_ENDIAN
97223- { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
97224-#else
97225- { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
97226-#endif
97227- { { 4, 0 }, { 20, 6 } },
97228- },
97229- {
97230- "LD_NLATTR_NEST",
97231- .u.insns = {
97232- BPF_STMT(BPF_LD | BPF_IMM, 2),
97233- BPF_STMT(BPF_LDX | BPF_IMM, 3),
97234- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97235- SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97236- BPF_STMT(BPF_LD | BPF_IMM, 2),
97237- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97238- SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97239- BPF_STMT(BPF_LD | BPF_IMM, 2),
97240- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97241- SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97242- BPF_STMT(BPF_LD | BPF_IMM, 2),
97243- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97244- SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97245- BPF_STMT(BPF_LD | BPF_IMM, 2),
97246- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97247- SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97248- BPF_STMT(BPF_LD | BPF_IMM, 2),
97249- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97250- SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97251- BPF_STMT(BPF_LD | BPF_IMM, 2),
97252- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97253- SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97254- BPF_STMT(BPF_LD | BPF_IMM, 2),
97255- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97256- SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97257- BPF_STMT(BPF_RET | BPF_A, 0)
97258- },
97259- CLASSIC,
97260-#ifdef __BIG_ENDIAN
97261- { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
97262-#else
97263- { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
97264-#endif
97265- { { 4, 0 }, { 20, 10 } },
97266- },
97267- {
97268- "LD_PAYLOAD_OFF",
97269- .u.insns = {
97270- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97271- SKF_AD_OFF + SKF_AD_PAY_OFFSET),
97272- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97273- SKF_AD_OFF + SKF_AD_PAY_OFFSET),
97274- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97275- SKF_AD_OFF + SKF_AD_PAY_OFFSET),
97276- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97277- SKF_AD_OFF + SKF_AD_PAY_OFFSET),
97278- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97279- SKF_AD_OFF + SKF_AD_PAY_OFFSET),
97280- BPF_STMT(BPF_RET | BPF_A, 0)
97281- },
97282- CLASSIC,
97283- /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
97284- * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
97285- * id 9737, seq 1, length 64
97286- */
97287- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97288- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97289- 0x08, 0x00,
97290- 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
97291- 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
97292- { { 30, 0 }, { 100, 42 } },
97293- },
97294- {
97295- "LD_ANC_XOR",
97296- .u.insns = {
97297- BPF_STMT(BPF_LD | BPF_IMM, 10),
97298- BPF_STMT(BPF_LDX | BPF_IMM, 300),
97299- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97300- SKF_AD_OFF + SKF_AD_ALU_XOR_X),
97301- BPF_STMT(BPF_RET | BPF_A, 0)
97302- },
97303- CLASSIC,
97304- { },
97305- { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
97306- },
97307- {
97308- "SPILL_FILL",
97309- .u.insns = {
97310- BPF_STMT(BPF_LDX | BPF_LEN, 0),
97311- BPF_STMT(BPF_LD | BPF_IMM, 2),
97312- BPF_STMT(BPF_ALU | BPF_RSH, 1),
97313- BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
97314- BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
97315- BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
97316- BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
97317- BPF_STMT(BPF_STX, 15), /* M3 = len */
97318- BPF_STMT(BPF_LDX | BPF_MEM, 1),
97319- BPF_STMT(BPF_LD | BPF_MEM, 2),
97320- BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
97321- BPF_STMT(BPF_LDX | BPF_MEM, 15),
97322- BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
97323- BPF_STMT(BPF_RET | BPF_A, 0)
97324- },
97325- CLASSIC,
97326- { },
97327- { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
97328- },
97329- {
97330- "JEQ",
97331- .u.insns = {
97332- BPF_STMT(BPF_LDX | BPF_LEN, 0),
97333- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
97334- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
97335- BPF_STMT(BPF_RET | BPF_K, 1),
97336- BPF_STMT(BPF_RET | BPF_K, MAX_K)
97337- },
97338- CLASSIC,
97339- { 3, 3, 3, 3, 3 },
97340- { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
97341- },
97342- {
97343- "JGT",
97344- .u.insns = {
97345- BPF_STMT(BPF_LDX | BPF_LEN, 0),
97346- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
97347- BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
97348- BPF_STMT(BPF_RET | BPF_K, 1),
97349- BPF_STMT(BPF_RET | BPF_K, MAX_K)
97350- },
97351- CLASSIC,
97352- { 4, 4, 4, 3, 3 },
97353- { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
97354- },
97355- {
97356- "JGE",
97357- .u.insns = {
97358- BPF_STMT(BPF_LDX | BPF_LEN, 0),
97359- BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
97360- BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
97361- BPF_STMT(BPF_RET | BPF_K, 10),
97362- BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
97363- BPF_STMT(BPF_RET | BPF_K, 20),
97364- BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
97365- BPF_STMT(BPF_RET | BPF_K, 30),
97366- BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
97367- BPF_STMT(BPF_RET | BPF_K, 40),
97368- BPF_STMT(BPF_RET | BPF_K, MAX_K)
97369- },
97370- CLASSIC,
97371- { 1, 2, 3, 4, 5 },
97372- { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
97373- },
97374- {
97375- "JSET",
97376- .u.insns = {
97377- BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
97378- BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
97379- BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
97380- BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
97381- BPF_STMT(BPF_LDX | BPF_LEN, 0),
97382- BPF_STMT(BPF_MISC | BPF_TXA, 0),
97383- BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
97384- BPF_STMT(BPF_MISC | BPF_TAX, 0),
97385- BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
97386- BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
97387- BPF_STMT(BPF_RET | BPF_K, 10),
97388- BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
97389- BPF_STMT(BPF_RET | BPF_K, 20),
97390- BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97391- BPF_STMT(BPF_RET | BPF_K, 30),
97392- BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97393- BPF_STMT(BPF_RET | BPF_K, 30),
97394- BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97395- BPF_STMT(BPF_RET | BPF_K, 30),
97396- BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97397- BPF_STMT(BPF_RET | BPF_K, 30),
97398- BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97399- BPF_STMT(BPF_RET | BPF_K, 30),
97400- BPF_STMT(BPF_RET | BPF_K, MAX_K)
97401- },
97402- CLASSIC,
97403- { 0, 0xAA, 0x55, 1 },
97404- { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
97405- },
97406- {
97407- "tcpdump port 22",
97408- .u.insns = {
97409- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
97410- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
97411- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
97412- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
97413- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
97414- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
97415- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
97416- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
97417- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
97418- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
97419- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
97420- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
97421- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
97422- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
97423- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
97424- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
97425- BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
97426- BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
97427- BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
97428- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
97429- BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
97430- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
97431- BPF_STMT(BPF_RET | BPF_K, 0xffff),
97432- BPF_STMT(BPF_RET | BPF_K, 0),
97433- },
97434- CLASSIC,
97435- /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
97436- * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
97437- * seq 1305692979:1305693027, ack 3650467037, win 65535,
97438- * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
97439- */
97440- { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
97441- 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
97442- 0x08, 0x00,
97443- 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
97444- 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
97445- 0x0a, 0x01, 0x01, 0x95, /* ip src */
97446- 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
97447- 0xc2, 0x24,
97448- 0x00, 0x16 /* dst port */ },
97449- { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
97450- },
97451- {
97452- "tcpdump complex",
97453- .u.insns = {
97454- /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
97455- * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
97456- * (len > 115 or len < 30000000000)' -d
97457- */
97458- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
97459- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
97460- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
97461- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
97462- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
97463- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
97464- BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
97465- BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
97466- BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
97467- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
97468- BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
97469- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
97470- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
97471- BPF_STMT(BPF_ST, 1),
97472- BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
97473- BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
97474- BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
97475- BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
97476- BPF_STMT(BPF_LD | BPF_MEM, 1),
97477- BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
97478- BPF_STMT(BPF_ST, 5),
97479- BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
97480- BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
97481- BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
97482- BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
97483- BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
97484- BPF_STMT(BPF_LD | BPF_MEM, 5),
97485- BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
97486- BPF_STMT(BPF_LD | BPF_LEN, 0),
97487- BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
97488- BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
97489- BPF_STMT(BPF_RET | BPF_K, 0xffff),
97490- BPF_STMT(BPF_RET | BPF_K, 0),
97491- },
97492- CLASSIC,
97493- { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
97494- 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
97495- 0x08, 0x00,
97496- 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
97497- 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
97498- 0x0a, 0x01, 0x01, 0x95, /* ip src */
97499- 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
97500- 0xc2, 0x24,
97501- 0x00, 0x16 /* dst port */ },
97502- { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
97503- },
97504- {
97505- "RET_A",
97506- .u.insns = {
97507- /* check that unitialized X and A contain zeros */
97508- BPF_STMT(BPF_MISC | BPF_TXA, 0),
97509- BPF_STMT(BPF_RET | BPF_A, 0)
97510- },
97511- CLASSIC,
97512- { },
97513- { {1, 0}, {2, 0} },
97514- },
97515- {
97516- "INT: ADD trivial",
97517- .u.insns_int = {
97518- BPF_ALU64_IMM(BPF_MOV, R1, 1),
97519- BPF_ALU64_IMM(BPF_ADD, R1, 2),
97520- BPF_ALU64_IMM(BPF_MOV, R2, 3),
97521- BPF_ALU64_REG(BPF_SUB, R1, R2),
97522- BPF_ALU64_IMM(BPF_ADD, R1, -1),
97523- BPF_ALU64_IMM(BPF_MUL, R1, 3),
97524- BPF_ALU64_REG(BPF_MOV, R0, R1),
97525- BPF_EXIT_INSN(),
97526- },
97527- INTERNAL,
97528- { },
97529- { { 0, 0xfffffffd } }
97530- },
97531- {
97532- "INT: MUL_X",
97533- .u.insns_int = {
97534- BPF_ALU64_IMM(BPF_MOV, R0, -1),
97535- BPF_ALU64_IMM(BPF_MOV, R1, -1),
97536- BPF_ALU64_IMM(BPF_MOV, R2, 3),
97537- BPF_ALU64_REG(BPF_MUL, R1, R2),
97538- BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
97539- BPF_EXIT_INSN(),
97540- BPF_ALU64_IMM(BPF_MOV, R0, 1),
97541- BPF_EXIT_INSN(),
97542- },
97543- INTERNAL,
97544- { },
97545- { { 0, 1 } }
97546- },
97547- {
97548- "INT: MUL_X2",
97549- .u.insns_int = {
97550- BPF_ALU32_IMM(BPF_MOV, R0, -1),
97551- BPF_ALU32_IMM(BPF_MOV, R1, -1),
97552- BPF_ALU32_IMM(BPF_MOV, R2, 3),
97553- BPF_ALU64_REG(BPF_MUL, R1, R2),
97554- BPF_ALU64_IMM(BPF_RSH, R1, 8),
97555- BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
97556- BPF_EXIT_INSN(),
97557- BPF_ALU32_IMM(BPF_MOV, R0, 1),
97558- BPF_EXIT_INSN(),
97559- },
97560- INTERNAL,
97561- { },
97562- { { 0, 1 } }
97563- },
97564- {
97565- "INT: MUL32_X",
97566- .u.insns_int = {
97567- BPF_ALU32_IMM(BPF_MOV, R0, -1),
97568- BPF_ALU64_IMM(BPF_MOV, R1, -1),
97569- BPF_ALU32_IMM(BPF_MOV, R2, 3),
97570- BPF_ALU32_REG(BPF_MUL, R1, R2),
97571- BPF_ALU64_IMM(BPF_RSH, R1, 8),
97572- BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
97573- BPF_EXIT_INSN(),
97574- BPF_ALU32_IMM(BPF_MOV, R0, 1),
97575- BPF_EXIT_INSN(),
97576- },
97577- INTERNAL,
97578- { },
97579- { { 0, 1 } }
97580- },
97581- {
97582- /* Have to test all register combinations, since
97583- * JITing of different registers will produce
97584- * different asm code.
97585- */
97586- "INT: ADD 64-bit",
97587- .u.insns_int = {
97588- BPF_ALU64_IMM(BPF_MOV, R0, 0),
97589- BPF_ALU64_IMM(BPF_MOV, R1, 1),
97590- BPF_ALU64_IMM(BPF_MOV, R2, 2),
97591- BPF_ALU64_IMM(BPF_MOV, R3, 3),
97592- BPF_ALU64_IMM(BPF_MOV, R4, 4),
97593- BPF_ALU64_IMM(BPF_MOV, R5, 5),
97594- BPF_ALU64_IMM(BPF_MOV, R6, 6),
97595- BPF_ALU64_IMM(BPF_MOV, R7, 7),
97596- BPF_ALU64_IMM(BPF_MOV, R8, 8),
97597- BPF_ALU64_IMM(BPF_MOV, R9, 9),
97598- BPF_ALU64_IMM(BPF_ADD, R0, 20),
97599- BPF_ALU64_IMM(BPF_ADD, R1, 20),
97600- BPF_ALU64_IMM(BPF_ADD, R2, 20),
97601- BPF_ALU64_IMM(BPF_ADD, R3, 20),
97602- BPF_ALU64_IMM(BPF_ADD, R4, 20),
97603- BPF_ALU64_IMM(BPF_ADD, R5, 20),
97604- BPF_ALU64_IMM(BPF_ADD, R6, 20),
97605- BPF_ALU64_IMM(BPF_ADD, R7, 20),
97606- BPF_ALU64_IMM(BPF_ADD, R8, 20),
97607- BPF_ALU64_IMM(BPF_ADD, R9, 20),
97608- BPF_ALU64_IMM(BPF_SUB, R0, 10),
97609- BPF_ALU64_IMM(BPF_SUB, R1, 10),
97610- BPF_ALU64_IMM(BPF_SUB, R2, 10),
97611- BPF_ALU64_IMM(BPF_SUB, R3, 10),
97612- BPF_ALU64_IMM(BPF_SUB, R4, 10),
97613- BPF_ALU64_IMM(BPF_SUB, R5, 10),
97614- BPF_ALU64_IMM(BPF_SUB, R6, 10),
97615- BPF_ALU64_IMM(BPF_SUB, R7, 10),
97616- BPF_ALU64_IMM(BPF_SUB, R8, 10),
97617- BPF_ALU64_IMM(BPF_SUB, R9, 10),
97618- BPF_ALU64_REG(BPF_ADD, R0, R0),
97619- BPF_ALU64_REG(BPF_ADD, R0, R1),
97620- BPF_ALU64_REG(BPF_ADD, R0, R2),
97621- BPF_ALU64_REG(BPF_ADD, R0, R3),
97622- BPF_ALU64_REG(BPF_ADD, R0, R4),
97623- BPF_ALU64_REG(BPF_ADD, R0, R5),
97624- BPF_ALU64_REG(BPF_ADD, R0, R6),
97625- BPF_ALU64_REG(BPF_ADD, R0, R7),
97626- BPF_ALU64_REG(BPF_ADD, R0, R8),
97627- BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
97628- BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
97629- BPF_EXIT_INSN(),
97630- BPF_ALU64_REG(BPF_ADD, R1, R0),
97631- BPF_ALU64_REG(BPF_ADD, R1, R1),
97632- BPF_ALU64_REG(BPF_ADD, R1, R2),
97633- BPF_ALU64_REG(BPF_ADD, R1, R3),
97634- BPF_ALU64_REG(BPF_ADD, R1, R4),
97635- BPF_ALU64_REG(BPF_ADD, R1, R5),
97636- BPF_ALU64_REG(BPF_ADD, R1, R6),
97637- BPF_ALU64_REG(BPF_ADD, R1, R7),
97638- BPF_ALU64_REG(BPF_ADD, R1, R8),
97639- BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
97640- BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
97641- BPF_EXIT_INSN(),
97642- BPF_ALU64_REG(BPF_ADD, R2, R0),
97643- BPF_ALU64_REG(BPF_ADD, R2, R1),
97644- BPF_ALU64_REG(BPF_ADD, R2, R2),
97645- BPF_ALU64_REG(BPF_ADD, R2, R3),
97646- BPF_ALU64_REG(BPF_ADD, R2, R4),
97647- BPF_ALU64_REG(BPF_ADD, R2, R5),
97648- BPF_ALU64_REG(BPF_ADD, R2, R6),
97649- BPF_ALU64_REG(BPF_ADD, R2, R7),
97650- BPF_ALU64_REG(BPF_ADD, R2, R8),
97651- BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
97652- BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
97653- BPF_EXIT_INSN(),
97654- BPF_ALU64_REG(BPF_ADD, R3, R0),
97655- BPF_ALU64_REG(BPF_ADD, R3, R1),
97656- BPF_ALU64_REG(BPF_ADD, R3, R2),
97657- BPF_ALU64_REG(BPF_ADD, R3, R3),
97658- BPF_ALU64_REG(BPF_ADD, R3, R4),
97659- BPF_ALU64_REG(BPF_ADD, R3, R5),
97660- BPF_ALU64_REG(BPF_ADD, R3, R6),
97661- BPF_ALU64_REG(BPF_ADD, R3, R7),
97662- BPF_ALU64_REG(BPF_ADD, R3, R8),
97663- BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
97664- BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
97665- BPF_EXIT_INSN(),
97666- BPF_ALU64_REG(BPF_ADD, R4, R0),
97667- BPF_ALU64_REG(BPF_ADD, R4, R1),
97668- BPF_ALU64_REG(BPF_ADD, R4, R2),
97669- BPF_ALU64_REG(BPF_ADD, R4, R3),
97670- BPF_ALU64_REG(BPF_ADD, R4, R4),
97671- BPF_ALU64_REG(BPF_ADD, R4, R5),
97672- BPF_ALU64_REG(BPF_ADD, R4, R6),
97673- BPF_ALU64_REG(BPF_ADD, R4, R7),
97674- BPF_ALU64_REG(BPF_ADD, R4, R8),
97675- BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
97676- BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
97677- BPF_EXIT_INSN(),
97678- BPF_ALU64_REG(BPF_ADD, R5, R0),
97679- BPF_ALU64_REG(BPF_ADD, R5, R1),
97680- BPF_ALU64_REG(BPF_ADD, R5, R2),
97681- BPF_ALU64_REG(BPF_ADD, R5, R3),
97682- BPF_ALU64_REG(BPF_ADD, R5, R4),
97683- BPF_ALU64_REG(BPF_ADD, R5, R5),
97684- BPF_ALU64_REG(BPF_ADD, R5, R6),
97685- BPF_ALU64_REG(BPF_ADD, R5, R7),
97686- BPF_ALU64_REG(BPF_ADD, R5, R8),
97687- BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
97688- BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
97689- BPF_EXIT_INSN(),
97690- BPF_ALU64_REG(BPF_ADD, R6, R0),
97691- BPF_ALU64_REG(BPF_ADD, R6, R1),
97692- BPF_ALU64_REG(BPF_ADD, R6, R2),
97693- BPF_ALU64_REG(BPF_ADD, R6, R3),
97694- BPF_ALU64_REG(BPF_ADD, R6, R4),
97695- BPF_ALU64_REG(BPF_ADD, R6, R5),
97696- BPF_ALU64_REG(BPF_ADD, R6, R6),
97697- BPF_ALU64_REG(BPF_ADD, R6, R7),
97698- BPF_ALU64_REG(BPF_ADD, R6, R8),
97699- BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
97700- BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
97701- BPF_EXIT_INSN(),
97702- BPF_ALU64_REG(BPF_ADD, R7, R0),
97703- BPF_ALU64_REG(BPF_ADD, R7, R1),
97704- BPF_ALU64_REG(BPF_ADD, R7, R2),
97705- BPF_ALU64_REG(BPF_ADD, R7, R3),
97706- BPF_ALU64_REG(BPF_ADD, R7, R4),
97707- BPF_ALU64_REG(BPF_ADD, R7, R5),
97708- BPF_ALU64_REG(BPF_ADD, R7, R6),
97709- BPF_ALU64_REG(BPF_ADD, R7, R7),
97710- BPF_ALU64_REG(BPF_ADD, R7, R8),
97711- BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
97712- BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
97713- BPF_EXIT_INSN(),
97714- BPF_ALU64_REG(BPF_ADD, R8, R0),
97715- BPF_ALU64_REG(BPF_ADD, R8, R1),
97716- BPF_ALU64_REG(BPF_ADD, R8, R2),
97717- BPF_ALU64_REG(BPF_ADD, R8, R3),
97718- BPF_ALU64_REG(BPF_ADD, R8, R4),
97719- BPF_ALU64_REG(BPF_ADD, R8, R5),
97720- BPF_ALU64_REG(BPF_ADD, R8, R6),
97721- BPF_ALU64_REG(BPF_ADD, R8, R7),
97722- BPF_ALU64_REG(BPF_ADD, R8, R8),
97723- BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
97724- BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
97725- BPF_EXIT_INSN(),
97726- BPF_ALU64_REG(BPF_ADD, R9, R0),
97727- BPF_ALU64_REG(BPF_ADD, R9, R1),
97728- BPF_ALU64_REG(BPF_ADD, R9, R2),
97729- BPF_ALU64_REG(BPF_ADD, R9, R3),
97730- BPF_ALU64_REG(BPF_ADD, R9, R4),
97731- BPF_ALU64_REG(BPF_ADD, R9, R5),
97732- BPF_ALU64_REG(BPF_ADD, R9, R6),
97733- BPF_ALU64_REG(BPF_ADD, R9, R7),
97734- BPF_ALU64_REG(BPF_ADD, R9, R8),
97735- BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
97736- BPF_ALU64_REG(BPF_MOV, R0, R9),
97737- BPF_EXIT_INSN(),
97738- },
97739- INTERNAL,
97740- { },
97741- { { 0, 2957380 } }
97742- },
97743- {
97744- "INT: ADD 32-bit",
97745- .u.insns_int = {
97746- BPF_ALU32_IMM(BPF_MOV, R0, 20),
97747- BPF_ALU32_IMM(BPF_MOV, R1, 1),
97748- BPF_ALU32_IMM(BPF_MOV, R2, 2),
97749- BPF_ALU32_IMM(BPF_MOV, R3, 3),
97750- BPF_ALU32_IMM(BPF_MOV, R4, 4),
97751- BPF_ALU32_IMM(BPF_MOV, R5, 5),
97752- BPF_ALU32_IMM(BPF_MOV, R6, 6),
97753- BPF_ALU32_IMM(BPF_MOV, R7, 7),
97754- BPF_ALU32_IMM(BPF_MOV, R8, 8),
97755- BPF_ALU32_IMM(BPF_MOV, R9, 9),
97756- BPF_ALU64_IMM(BPF_ADD, R1, 10),
97757- BPF_ALU64_IMM(BPF_ADD, R2, 10),
97758- BPF_ALU64_IMM(BPF_ADD, R3, 10),
97759- BPF_ALU64_IMM(BPF_ADD, R4, 10),
97760- BPF_ALU64_IMM(BPF_ADD, R5, 10),
97761- BPF_ALU64_IMM(BPF_ADD, R6, 10),
97762- BPF_ALU64_IMM(BPF_ADD, R7, 10),
97763- BPF_ALU64_IMM(BPF_ADD, R8, 10),
97764- BPF_ALU64_IMM(BPF_ADD, R9, 10),
97765- BPF_ALU32_REG(BPF_ADD, R0, R1),
97766- BPF_ALU32_REG(BPF_ADD, R0, R2),
97767- BPF_ALU32_REG(BPF_ADD, R0, R3),
97768- BPF_ALU32_REG(BPF_ADD, R0, R4),
97769- BPF_ALU32_REG(BPF_ADD, R0, R5),
97770- BPF_ALU32_REG(BPF_ADD, R0, R6),
97771- BPF_ALU32_REG(BPF_ADD, R0, R7),
97772- BPF_ALU32_REG(BPF_ADD, R0, R8),
97773- BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
97774- BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
97775- BPF_EXIT_INSN(),
97776- BPF_ALU32_REG(BPF_ADD, R1, R0),
97777- BPF_ALU32_REG(BPF_ADD, R1, R1),
97778- BPF_ALU32_REG(BPF_ADD, R1, R2),
97779- BPF_ALU32_REG(BPF_ADD, R1, R3),
97780- BPF_ALU32_REG(BPF_ADD, R1, R4),
97781- BPF_ALU32_REG(BPF_ADD, R1, R5),
97782- BPF_ALU32_REG(BPF_ADD, R1, R6),
97783- BPF_ALU32_REG(BPF_ADD, R1, R7),
97784- BPF_ALU32_REG(BPF_ADD, R1, R8),
97785- BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
97786- BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
97787- BPF_EXIT_INSN(),
97788- BPF_ALU32_REG(BPF_ADD, R2, R0),
97789- BPF_ALU32_REG(BPF_ADD, R2, R1),
97790- BPF_ALU32_REG(BPF_ADD, R2, R2),
97791- BPF_ALU32_REG(BPF_ADD, R2, R3),
97792- BPF_ALU32_REG(BPF_ADD, R2, R4),
97793- BPF_ALU32_REG(BPF_ADD, R2, R5),
97794- BPF_ALU32_REG(BPF_ADD, R2, R6),
97795- BPF_ALU32_REG(BPF_ADD, R2, R7),
97796- BPF_ALU32_REG(BPF_ADD, R2, R8),
97797- BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
97798- BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
97799- BPF_EXIT_INSN(),
97800- BPF_ALU32_REG(BPF_ADD, R3, R0),
97801- BPF_ALU32_REG(BPF_ADD, R3, R1),
97802- BPF_ALU32_REG(BPF_ADD, R3, R2),
97803- BPF_ALU32_REG(BPF_ADD, R3, R3),
97804- BPF_ALU32_REG(BPF_ADD, R3, R4),
97805- BPF_ALU32_REG(BPF_ADD, R3, R5),
97806- BPF_ALU32_REG(BPF_ADD, R3, R6),
97807- BPF_ALU32_REG(BPF_ADD, R3, R7),
97808- BPF_ALU32_REG(BPF_ADD, R3, R8),
97809- BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
97810- BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
97811- BPF_EXIT_INSN(),
97812- BPF_ALU32_REG(BPF_ADD, R4, R0),
97813- BPF_ALU32_REG(BPF_ADD, R4, R1),
97814- BPF_ALU32_REG(BPF_ADD, R4, R2),
97815- BPF_ALU32_REG(BPF_ADD, R4, R3),
97816- BPF_ALU32_REG(BPF_ADD, R4, R4),
97817- BPF_ALU32_REG(BPF_ADD, R4, R5),
97818- BPF_ALU32_REG(BPF_ADD, R4, R6),
97819- BPF_ALU32_REG(BPF_ADD, R4, R7),
97820- BPF_ALU32_REG(BPF_ADD, R4, R8),
97821- BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
97822- BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
97823- BPF_EXIT_INSN(),
97824- BPF_ALU32_REG(BPF_ADD, R5, R0),
97825- BPF_ALU32_REG(BPF_ADD, R5, R1),
97826- BPF_ALU32_REG(BPF_ADD, R5, R2),
97827- BPF_ALU32_REG(BPF_ADD, R5, R3),
97828- BPF_ALU32_REG(BPF_ADD, R5, R4),
97829- BPF_ALU32_REG(BPF_ADD, R5, R5),
97830- BPF_ALU32_REG(BPF_ADD, R5, R6),
97831- BPF_ALU32_REG(BPF_ADD, R5, R7),
97832- BPF_ALU32_REG(BPF_ADD, R5, R8),
97833- BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
97834- BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
97835- BPF_EXIT_INSN(),
97836- BPF_ALU32_REG(BPF_ADD, R6, R0),
97837- BPF_ALU32_REG(BPF_ADD, R6, R1),
97838- BPF_ALU32_REG(BPF_ADD, R6, R2),
97839- BPF_ALU32_REG(BPF_ADD, R6, R3),
97840- BPF_ALU32_REG(BPF_ADD, R6, R4),
97841- BPF_ALU32_REG(BPF_ADD, R6, R5),
97842- BPF_ALU32_REG(BPF_ADD, R6, R6),
97843- BPF_ALU32_REG(BPF_ADD, R6, R7),
97844- BPF_ALU32_REG(BPF_ADD, R6, R8),
97845- BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
97846- BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
97847- BPF_EXIT_INSN(),
97848- BPF_ALU32_REG(BPF_ADD, R7, R0),
97849- BPF_ALU32_REG(BPF_ADD, R7, R1),
97850- BPF_ALU32_REG(BPF_ADD, R7, R2),
97851- BPF_ALU32_REG(BPF_ADD, R7, R3),
97852- BPF_ALU32_REG(BPF_ADD, R7, R4),
97853- BPF_ALU32_REG(BPF_ADD, R7, R5),
97854- BPF_ALU32_REG(BPF_ADD, R7, R6),
97855- BPF_ALU32_REG(BPF_ADD, R7, R7),
97856- BPF_ALU32_REG(BPF_ADD, R7, R8),
97857- BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
97858- BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
97859- BPF_EXIT_INSN(),
97860- BPF_ALU32_REG(BPF_ADD, R8, R0),
97861- BPF_ALU32_REG(BPF_ADD, R8, R1),
97862- BPF_ALU32_REG(BPF_ADD, R8, R2),
97863- BPF_ALU32_REG(BPF_ADD, R8, R3),
97864- BPF_ALU32_REG(BPF_ADD, R8, R4),
97865- BPF_ALU32_REG(BPF_ADD, R8, R5),
97866- BPF_ALU32_REG(BPF_ADD, R8, R6),
97867- BPF_ALU32_REG(BPF_ADD, R8, R7),
97868- BPF_ALU32_REG(BPF_ADD, R8, R8),
97869- BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
97870- BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
97871- BPF_EXIT_INSN(),
97872- BPF_ALU32_REG(BPF_ADD, R9, R0),
97873- BPF_ALU32_REG(BPF_ADD, R9, R1),
97874- BPF_ALU32_REG(BPF_ADD, R9, R2),
97875- BPF_ALU32_REG(BPF_ADD, R9, R3),
97876- BPF_ALU32_REG(BPF_ADD, R9, R4),
97877- BPF_ALU32_REG(BPF_ADD, R9, R5),
97878- BPF_ALU32_REG(BPF_ADD, R9, R6),
97879- BPF_ALU32_REG(BPF_ADD, R9, R7),
97880- BPF_ALU32_REG(BPF_ADD, R9, R8),
97881- BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
97882- BPF_ALU32_REG(BPF_MOV, R0, R9),
97883- BPF_EXIT_INSN(),
97884- },
97885- INTERNAL,
97886- { },
97887- { { 0, 2957380 } }
97888- },
97889- { /* Mainly checking JIT here. */
97890- "INT: SUB",
97891- .u.insns_int = {
97892- BPF_ALU64_IMM(BPF_MOV, R0, 0),
97893- BPF_ALU64_IMM(BPF_MOV, R1, 1),
97894- BPF_ALU64_IMM(BPF_MOV, R2, 2),
97895- BPF_ALU64_IMM(BPF_MOV, R3, 3),
97896- BPF_ALU64_IMM(BPF_MOV, R4, 4),
97897- BPF_ALU64_IMM(BPF_MOV, R5, 5),
97898- BPF_ALU64_IMM(BPF_MOV, R6, 6),
97899- BPF_ALU64_IMM(BPF_MOV, R7, 7),
97900- BPF_ALU64_IMM(BPF_MOV, R8, 8),
97901- BPF_ALU64_IMM(BPF_MOV, R9, 9),
97902- BPF_ALU64_REG(BPF_SUB, R0, R0),
97903- BPF_ALU64_REG(BPF_SUB, R0, R1),
97904- BPF_ALU64_REG(BPF_SUB, R0, R2),
97905- BPF_ALU64_REG(BPF_SUB, R0, R3),
97906- BPF_ALU64_REG(BPF_SUB, R0, R4),
97907- BPF_ALU64_REG(BPF_SUB, R0, R5),
97908- BPF_ALU64_REG(BPF_SUB, R0, R6),
97909- BPF_ALU64_REG(BPF_SUB, R0, R7),
97910- BPF_ALU64_REG(BPF_SUB, R0, R8),
97911- BPF_ALU64_REG(BPF_SUB, R0, R9),
97912- BPF_ALU64_IMM(BPF_SUB, R0, 10),
97913- BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
97914- BPF_EXIT_INSN(),
97915- BPF_ALU64_REG(BPF_SUB, R1, R0),
97916- BPF_ALU64_REG(BPF_SUB, R1, R2),
97917- BPF_ALU64_REG(BPF_SUB, R1, R3),
97918- BPF_ALU64_REG(BPF_SUB, R1, R4),
97919- BPF_ALU64_REG(BPF_SUB, R1, R5),
97920- BPF_ALU64_REG(BPF_SUB, R1, R6),
97921- BPF_ALU64_REG(BPF_SUB, R1, R7),
97922- BPF_ALU64_REG(BPF_SUB, R1, R8),
97923- BPF_ALU64_REG(BPF_SUB, R1, R9),
97924- BPF_ALU64_IMM(BPF_SUB, R1, 10),
97925- BPF_ALU64_REG(BPF_SUB, R2, R0),
97926- BPF_ALU64_REG(BPF_SUB, R2, R1),
97927- BPF_ALU64_REG(BPF_SUB, R2, R3),
97928- BPF_ALU64_REG(BPF_SUB, R2, R4),
97929- BPF_ALU64_REG(BPF_SUB, R2, R5),
97930- BPF_ALU64_REG(BPF_SUB, R2, R6),
97931- BPF_ALU64_REG(BPF_SUB, R2, R7),
97932- BPF_ALU64_REG(BPF_SUB, R2, R8),
97933- BPF_ALU64_REG(BPF_SUB, R2, R9),
97934- BPF_ALU64_IMM(BPF_SUB, R2, 10),
97935- BPF_ALU64_REG(BPF_SUB, R3, R0),
97936- BPF_ALU64_REG(BPF_SUB, R3, R1),
97937- BPF_ALU64_REG(BPF_SUB, R3, R2),
97938- BPF_ALU64_REG(BPF_SUB, R3, R4),
97939- BPF_ALU64_REG(BPF_SUB, R3, R5),
97940- BPF_ALU64_REG(BPF_SUB, R3, R6),
97941- BPF_ALU64_REG(BPF_SUB, R3, R7),
97942- BPF_ALU64_REG(BPF_SUB, R3, R8),
97943- BPF_ALU64_REG(BPF_SUB, R3, R9),
97944- BPF_ALU64_IMM(BPF_SUB, R3, 10),
97945- BPF_ALU64_REG(BPF_SUB, R4, R0),
97946- BPF_ALU64_REG(BPF_SUB, R4, R1),
97947- BPF_ALU64_REG(BPF_SUB, R4, R2),
97948- BPF_ALU64_REG(BPF_SUB, R4, R3),
97949- BPF_ALU64_REG(BPF_SUB, R4, R5),
97950- BPF_ALU64_REG(BPF_SUB, R4, R6),
97951- BPF_ALU64_REG(BPF_SUB, R4, R7),
97952- BPF_ALU64_REG(BPF_SUB, R4, R8),
97953- BPF_ALU64_REG(BPF_SUB, R4, R9),
97954- BPF_ALU64_IMM(BPF_SUB, R4, 10),
97955- BPF_ALU64_REG(BPF_SUB, R5, R0),
97956- BPF_ALU64_REG(BPF_SUB, R5, R1),
97957- BPF_ALU64_REG(BPF_SUB, R5, R2),
97958- BPF_ALU64_REG(BPF_SUB, R5, R3),
97959- BPF_ALU64_REG(BPF_SUB, R5, R4),
97960- BPF_ALU64_REG(BPF_SUB, R5, R6),
97961- BPF_ALU64_REG(BPF_SUB, R5, R7),
97962- BPF_ALU64_REG(BPF_SUB, R5, R8),
97963- BPF_ALU64_REG(BPF_SUB, R5, R9),
97964- BPF_ALU64_IMM(BPF_SUB, R5, 10),
97965- BPF_ALU64_REG(BPF_SUB, R6, R0),
97966- BPF_ALU64_REG(BPF_SUB, R6, R1),
97967- BPF_ALU64_REG(BPF_SUB, R6, R2),
97968- BPF_ALU64_REG(BPF_SUB, R6, R3),
97969- BPF_ALU64_REG(BPF_SUB, R6, R4),
97970- BPF_ALU64_REG(BPF_SUB, R6, R5),
97971- BPF_ALU64_REG(BPF_SUB, R6, R7),
97972- BPF_ALU64_REG(BPF_SUB, R6, R8),
97973- BPF_ALU64_REG(BPF_SUB, R6, R9),
97974- BPF_ALU64_IMM(BPF_SUB, R6, 10),
97975- BPF_ALU64_REG(BPF_SUB, R7, R0),
97976- BPF_ALU64_REG(BPF_SUB, R7, R1),
97977- BPF_ALU64_REG(BPF_SUB, R7, R2),
97978- BPF_ALU64_REG(BPF_SUB, R7, R3),
97979- BPF_ALU64_REG(BPF_SUB, R7, R4),
97980- BPF_ALU64_REG(BPF_SUB, R7, R5),
97981- BPF_ALU64_REG(BPF_SUB, R7, R6),
97982- BPF_ALU64_REG(BPF_SUB, R7, R8),
97983- BPF_ALU64_REG(BPF_SUB, R7, R9),
97984- BPF_ALU64_IMM(BPF_SUB, R7, 10),
97985- BPF_ALU64_REG(BPF_SUB, R8, R0),
97986- BPF_ALU64_REG(BPF_SUB, R8, R1),
97987- BPF_ALU64_REG(BPF_SUB, R8, R2),
97988- BPF_ALU64_REG(BPF_SUB, R8, R3),
97989- BPF_ALU64_REG(BPF_SUB, R8, R4),
97990- BPF_ALU64_REG(BPF_SUB, R8, R5),
97991- BPF_ALU64_REG(BPF_SUB, R8, R6),
97992- BPF_ALU64_REG(BPF_SUB, R8, R7),
97993- BPF_ALU64_REG(BPF_SUB, R8, R9),
97994- BPF_ALU64_IMM(BPF_SUB, R8, 10),
97995- BPF_ALU64_REG(BPF_SUB, R9, R0),
97996- BPF_ALU64_REG(BPF_SUB, R9, R1),
97997- BPF_ALU64_REG(BPF_SUB, R9, R2),
97998- BPF_ALU64_REG(BPF_SUB, R9, R3),
97999- BPF_ALU64_REG(BPF_SUB, R9, R4),
98000- BPF_ALU64_REG(BPF_SUB, R9, R5),
98001- BPF_ALU64_REG(BPF_SUB, R9, R6),
98002- BPF_ALU64_REG(BPF_SUB, R9, R7),
98003- BPF_ALU64_REG(BPF_SUB, R9, R8),
98004- BPF_ALU64_IMM(BPF_SUB, R9, 10),
98005- BPF_ALU64_IMM(BPF_SUB, R0, 10),
98006- BPF_ALU64_IMM(BPF_NEG, R0, 0),
98007- BPF_ALU64_REG(BPF_SUB, R0, R1),
98008- BPF_ALU64_REG(BPF_SUB, R0, R2),
98009- BPF_ALU64_REG(BPF_SUB, R0, R3),
98010- BPF_ALU64_REG(BPF_SUB, R0, R4),
98011- BPF_ALU64_REG(BPF_SUB, R0, R5),
98012- BPF_ALU64_REG(BPF_SUB, R0, R6),
98013- BPF_ALU64_REG(BPF_SUB, R0, R7),
98014- BPF_ALU64_REG(BPF_SUB, R0, R8),
98015- BPF_ALU64_REG(BPF_SUB, R0, R9),
98016- BPF_EXIT_INSN(),
98017- },
98018- INTERNAL,
98019- { },
98020- { { 0, 11 } }
98021- },
98022- { /* Mainly checking JIT here. */
98023- "INT: XOR",
98024- .u.insns_int = {
98025- BPF_ALU64_REG(BPF_SUB, R0, R0),
98026- BPF_ALU64_REG(BPF_XOR, R1, R1),
98027- BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
98028- BPF_EXIT_INSN(),
98029- BPF_ALU64_IMM(BPF_MOV, R0, 10),
98030- BPF_ALU64_IMM(BPF_MOV, R1, -1),
98031- BPF_ALU64_REG(BPF_SUB, R1, R1),
98032- BPF_ALU64_REG(BPF_XOR, R2, R2),
98033- BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
98034- BPF_EXIT_INSN(),
98035- BPF_ALU64_REG(BPF_SUB, R2, R2),
98036- BPF_ALU64_REG(BPF_XOR, R3, R3),
98037- BPF_ALU64_IMM(BPF_MOV, R0, 10),
98038- BPF_ALU64_IMM(BPF_MOV, R1, -1),
98039- BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
98040- BPF_EXIT_INSN(),
98041- BPF_ALU64_REG(BPF_SUB, R3, R3),
98042- BPF_ALU64_REG(BPF_XOR, R4, R4),
98043- BPF_ALU64_IMM(BPF_MOV, R2, 1),
98044- BPF_ALU64_IMM(BPF_MOV, R5, -1),
98045- BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
98046- BPF_EXIT_INSN(),
98047- BPF_ALU64_REG(BPF_SUB, R4, R4),
98048- BPF_ALU64_REG(BPF_XOR, R5, R5),
98049- BPF_ALU64_IMM(BPF_MOV, R3, 1),
98050- BPF_ALU64_IMM(BPF_MOV, R7, -1),
98051- BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
98052- BPF_EXIT_INSN(),
98053- BPF_ALU64_IMM(BPF_MOV, R5, 1),
98054- BPF_ALU64_REG(BPF_SUB, R5, R5),
98055- BPF_ALU64_REG(BPF_XOR, R6, R6),
98056- BPF_ALU64_IMM(BPF_MOV, R1, 1),
98057- BPF_ALU64_IMM(BPF_MOV, R8, -1),
98058- BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
98059- BPF_EXIT_INSN(),
98060- BPF_ALU64_REG(BPF_SUB, R6, R6),
98061- BPF_ALU64_REG(BPF_XOR, R7, R7),
98062- BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
98063- BPF_EXIT_INSN(),
98064- BPF_ALU64_REG(BPF_SUB, R7, R7),
98065- BPF_ALU64_REG(BPF_XOR, R8, R8),
98066- BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
98067- BPF_EXIT_INSN(),
98068- BPF_ALU64_REG(BPF_SUB, R8, R8),
98069- BPF_ALU64_REG(BPF_XOR, R9, R9),
98070- BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
98071- BPF_EXIT_INSN(),
98072- BPF_ALU64_REG(BPF_SUB, R9, R9),
98073- BPF_ALU64_REG(BPF_XOR, R0, R0),
98074- BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
98075- BPF_EXIT_INSN(),
98076- BPF_ALU64_REG(BPF_SUB, R1, R1),
98077- BPF_ALU64_REG(BPF_XOR, R0, R0),
98078- BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
98079- BPF_ALU64_IMM(BPF_MOV, R0, 0),
98080- BPF_EXIT_INSN(),
98081- BPF_ALU64_IMM(BPF_MOV, R0, 1),
98082- BPF_EXIT_INSN(),
98083- },
98084- INTERNAL,
98085- { },
98086- { { 0, 1 } }
98087- },
98088- { /* Mainly checking JIT here. */
98089- "INT: MUL",
98090- .u.insns_int = {
98091- BPF_ALU64_IMM(BPF_MOV, R0, 11),
98092- BPF_ALU64_IMM(BPF_MOV, R1, 1),
98093- BPF_ALU64_IMM(BPF_MOV, R2, 2),
98094- BPF_ALU64_IMM(BPF_MOV, R3, 3),
98095- BPF_ALU64_IMM(BPF_MOV, R4, 4),
98096- BPF_ALU64_IMM(BPF_MOV, R5, 5),
98097- BPF_ALU64_IMM(BPF_MOV, R6, 6),
98098- BPF_ALU64_IMM(BPF_MOV, R7, 7),
98099- BPF_ALU64_IMM(BPF_MOV, R8, 8),
98100- BPF_ALU64_IMM(BPF_MOV, R9, 9),
98101- BPF_ALU64_REG(BPF_MUL, R0, R0),
98102- BPF_ALU64_REG(BPF_MUL, R0, R1),
98103- BPF_ALU64_REG(BPF_MUL, R0, R2),
98104- BPF_ALU64_REG(BPF_MUL, R0, R3),
98105- BPF_ALU64_REG(BPF_MUL, R0, R4),
98106- BPF_ALU64_REG(BPF_MUL, R0, R5),
98107- BPF_ALU64_REG(BPF_MUL, R0, R6),
98108- BPF_ALU64_REG(BPF_MUL, R0, R7),
98109- BPF_ALU64_REG(BPF_MUL, R0, R8),
98110- BPF_ALU64_REG(BPF_MUL, R0, R9),
98111- BPF_ALU64_IMM(BPF_MUL, R0, 10),
98112- BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
98113- BPF_EXIT_INSN(),
98114- BPF_ALU64_REG(BPF_MUL, R1, R0),
98115- BPF_ALU64_REG(BPF_MUL, R1, R2),
98116- BPF_ALU64_REG(BPF_MUL, R1, R3),
98117- BPF_ALU64_REG(BPF_MUL, R1, R4),
98118- BPF_ALU64_REG(BPF_MUL, R1, R5),
98119- BPF_ALU64_REG(BPF_MUL, R1, R6),
98120- BPF_ALU64_REG(BPF_MUL, R1, R7),
98121- BPF_ALU64_REG(BPF_MUL, R1, R8),
98122- BPF_ALU64_REG(BPF_MUL, R1, R9),
98123- BPF_ALU64_IMM(BPF_MUL, R1, 10),
98124- BPF_ALU64_REG(BPF_MOV, R2, R1),
98125- BPF_ALU64_IMM(BPF_RSH, R2, 32),
98126- BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
98127- BPF_EXIT_INSN(),
98128- BPF_ALU64_IMM(BPF_LSH, R1, 32),
98129- BPF_ALU64_IMM(BPF_ARSH, R1, 32),
98130- BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
98131- BPF_EXIT_INSN(),
98132- BPF_ALU64_REG(BPF_MUL, R2, R0),
98133- BPF_ALU64_REG(BPF_MUL, R2, R1),
98134- BPF_ALU64_REG(BPF_MUL, R2, R3),
98135- BPF_ALU64_REG(BPF_MUL, R2, R4),
98136- BPF_ALU64_REG(BPF_MUL, R2, R5),
98137- BPF_ALU64_REG(BPF_MUL, R2, R6),
98138- BPF_ALU64_REG(BPF_MUL, R2, R7),
98139- BPF_ALU64_REG(BPF_MUL, R2, R8),
98140- BPF_ALU64_REG(BPF_MUL, R2, R9),
98141- BPF_ALU64_IMM(BPF_MUL, R2, 10),
98142- BPF_ALU64_IMM(BPF_RSH, R2, 32),
98143- BPF_ALU64_REG(BPF_MOV, R0, R2),
98144- BPF_EXIT_INSN(),
98145- },
98146- INTERNAL,
98147- { },
98148- { { 0, 0x35d97ef2 } }
98149- },
98150- {
98151- "INT: ALU MIX",
98152- .u.insns_int = {
98153- BPF_ALU64_IMM(BPF_MOV, R0, 11),
98154- BPF_ALU64_IMM(BPF_ADD, R0, -1),
98155- BPF_ALU64_IMM(BPF_MOV, R2, 2),
98156- BPF_ALU64_IMM(BPF_XOR, R2, 3),
98157- BPF_ALU64_REG(BPF_DIV, R0, R2),
98158- BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
98159- BPF_EXIT_INSN(),
98160- BPF_ALU64_IMM(BPF_MOD, R0, 3),
98161- BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
98162- BPF_EXIT_INSN(),
98163- BPF_ALU64_IMM(BPF_MOV, R0, -1),
98164- BPF_EXIT_INSN(),
98165- },
98166- INTERNAL,
98167- { },
98168- { { 0, -1 } }
98169- },
98170- {
98171- "INT: DIV + ABS",
98172- .u.insns_int = {
98173- BPF_ALU64_REG(BPF_MOV, R6, R1),
98174- BPF_LD_ABS(BPF_B, 3),
98175- BPF_ALU64_IMM(BPF_MOV, R2, 2),
98176- BPF_ALU32_REG(BPF_DIV, R0, R2),
98177- BPF_ALU64_REG(BPF_MOV, R8, R0),
98178- BPF_LD_ABS(BPF_B, 4),
98179- BPF_ALU64_REG(BPF_ADD, R8, R0),
98180- BPF_LD_IND(BPF_B, R8, -70),
98181- BPF_EXIT_INSN(),
98182- },
98183- INTERNAL,
98184- { 10, 20, 30, 40, 50 },
98185- { { 4, 0 }, { 5, 10 } }
98186- },
98187- {
98188- "INT: DIV by zero",
98189- .u.insns_int = {
98190- BPF_ALU64_REG(BPF_MOV, R6, R1),
98191- BPF_ALU64_IMM(BPF_MOV, R7, 0),
98192- BPF_LD_ABS(BPF_B, 3),
98193- BPF_ALU32_REG(BPF_DIV, R0, R7),
98194- BPF_EXIT_INSN(),
98195- },
98196- INTERNAL,
98197- { 10, 20, 30, 40, 50 },
98198- { { 3, 0 }, { 4, 0 } }
98199- },
98200- {
98201- "check: missing ret",
98202- .u.insns = {
98203- BPF_STMT(BPF_LD | BPF_IMM, 1),
98204- },
98205- CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98206- { },
98207- { }
98208- },
98209- {
98210- "check: div_k_0",
98211- .u.insns = {
98212- BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
98213- BPF_STMT(BPF_RET | BPF_K, 0)
98214- },
98215- CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98216- { },
98217- { }
98218- },
98219- {
98220- "check: unknown insn",
98221- .u.insns = {
98222- /* seccomp insn, rejected in socket filter */
98223- BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
98224- BPF_STMT(BPF_RET | BPF_K, 0)
98225- },
98226- CLASSIC | FLAG_EXPECTED_FAIL,
98227- { },
98228- { }
98229- },
98230- {
98231- "check: out of range spill/fill",
98232- .u.insns = {
98233- BPF_STMT(BPF_STX, 16),
98234- BPF_STMT(BPF_RET | BPF_K, 0)
98235- },
98236- CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98237- { },
98238- { }
98239- },
98240- {
98241- "JUMPS + HOLES",
98242- .u.insns = {
98243- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98244- BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
98245- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98246- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98247- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98248- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98249- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98250- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98251- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98252- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98253- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98254- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98255- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98256- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98257- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98258- BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
98259- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98260- BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
98261- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98262- BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
98263- BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
98264- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98265- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98266- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98267- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98268- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98269- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98270- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98271- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98272- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98273- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98274- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98275- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98276- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98277- BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
98278- BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
98279- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98280- BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
98281- BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
98282- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98283- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98284- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98285- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98286- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98287- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98288- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98289- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98290- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98291- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98292- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98293- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98294- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98295- BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
98296- BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
98297- BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98298- BPF_STMT(BPF_RET | BPF_A, 0),
98299- BPF_STMT(BPF_RET | BPF_A, 0),
98300- },
98301- CLASSIC,
98302- { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
98303- 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
98304- 0x08, 0x00,
98305- 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
98306- 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
98307- 0xc0, 0xa8, 0x33, 0x01,
98308- 0xc0, 0xa8, 0x33, 0x02,
98309- 0xbb, 0xb6,
98310- 0xa9, 0xfa,
98311- 0x00, 0x14, 0x00, 0x00,
98312- 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98313- 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98314- 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98315- 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98316- 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98317- 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98318- 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98319- 0xcc, 0xcc, 0xcc, 0xcc },
98320- { { 88, 0x001b } }
98321- },
98322- {
98323- "check: RET X",
98324- .u.insns = {
98325- BPF_STMT(BPF_RET | BPF_X, 0),
98326- },
98327- CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98328- { },
98329- { },
98330- },
98331- {
98332- "check: LDX + RET X",
98333- .u.insns = {
98334- BPF_STMT(BPF_LDX | BPF_IMM, 42),
98335- BPF_STMT(BPF_RET | BPF_X, 0),
98336- },
98337- CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98338- { },
98339- { },
98340- },
98341- { /* Mainly checking JIT here. */
98342- "M[]: alt STX + LDX",
98343- .u.insns = {
98344- BPF_STMT(BPF_LDX | BPF_IMM, 100),
98345- BPF_STMT(BPF_STX, 0),
98346- BPF_STMT(BPF_LDX | BPF_MEM, 0),
98347- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98348- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98349- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98350- BPF_STMT(BPF_STX, 1),
98351- BPF_STMT(BPF_LDX | BPF_MEM, 1),
98352- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98353- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98354- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98355- BPF_STMT(BPF_STX, 2),
98356- BPF_STMT(BPF_LDX | BPF_MEM, 2),
98357- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98358- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98359- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98360- BPF_STMT(BPF_STX, 3),
98361- BPF_STMT(BPF_LDX | BPF_MEM, 3),
98362- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98363- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98364- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98365- BPF_STMT(BPF_STX, 4),
98366- BPF_STMT(BPF_LDX | BPF_MEM, 4),
98367- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98368- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98369- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98370- BPF_STMT(BPF_STX, 5),
98371- BPF_STMT(BPF_LDX | BPF_MEM, 5),
98372- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98373- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98374- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98375- BPF_STMT(BPF_STX, 6),
98376- BPF_STMT(BPF_LDX | BPF_MEM, 6),
98377- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98378- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98379- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98380- BPF_STMT(BPF_STX, 7),
98381- BPF_STMT(BPF_LDX | BPF_MEM, 7),
98382- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98383- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98384- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98385- BPF_STMT(BPF_STX, 8),
98386- BPF_STMT(BPF_LDX | BPF_MEM, 8),
98387- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98388- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98389- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98390- BPF_STMT(BPF_STX, 9),
98391- BPF_STMT(BPF_LDX | BPF_MEM, 9),
98392- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98393- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98394- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98395- BPF_STMT(BPF_STX, 10),
98396- BPF_STMT(BPF_LDX | BPF_MEM, 10),
98397- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98398- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98399- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98400- BPF_STMT(BPF_STX, 11),
98401- BPF_STMT(BPF_LDX | BPF_MEM, 11),
98402- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98403- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98404- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98405- BPF_STMT(BPF_STX, 12),
98406- BPF_STMT(BPF_LDX | BPF_MEM, 12),
98407- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98408- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98409- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98410- BPF_STMT(BPF_STX, 13),
98411- BPF_STMT(BPF_LDX | BPF_MEM, 13),
98412- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98413- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98414- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98415- BPF_STMT(BPF_STX, 14),
98416- BPF_STMT(BPF_LDX | BPF_MEM, 14),
98417- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98418- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98419- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98420- BPF_STMT(BPF_STX, 15),
98421- BPF_STMT(BPF_LDX | BPF_MEM, 15),
98422- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98423- BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98424- BPF_STMT(BPF_MISC | BPF_TAX, 0),
98425- BPF_STMT(BPF_RET | BPF_A, 0),
98426- },
98427- CLASSIC | FLAG_NO_DATA,
98428- { },
98429- { { 0, 116 } },
98430- },
98431- { /* Mainly checking JIT here. */
98432- "M[]: full STX + full LDX",
98433- .u.insns = {
98434- BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
98435- BPF_STMT(BPF_STX, 0),
98436- BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
98437- BPF_STMT(BPF_STX, 1),
98438- BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
98439- BPF_STMT(BPF_STX, 2),
98440- BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
98441- BPF_STMT(BPF_STX, 3),
98442- BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
98443- BPF_STMT(BPF_STX, 4),
98444- BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
98445- BPF_STMT(BPF_STX, 5),
98446- BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
98447- BPF_STMT(BPF_STX, 6),
98448- BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
98449- BPF_STMT(BPF_STX, 7),
98450- BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
98451- BPF_STMT(BPF_STX, 8),
98452- BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
98453- BPF_STMT(BPF_STX, 9),
98454- BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
98455- BPF_STMT(BPF_STX, 10),
98456- BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
98457- BPF_STMT(BPF_STX, 11),
98458- BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
98459- BPF_STMT(BPF_STX, 12),
98460- BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
98461- BPF_STMT(BPF_STX, 13),
98462- BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
98463- BPF_STMT(BPF_STX, 14),
98464- BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
98465- BPF_STMT(BPF_STX, 15),
98466- BPF_STMT(BPF_LDX | BPF_MEM, 0),
98467- BPF_STMT(BPF_MISC | BPF_TXA, 0),
98468- BPF_STMT(BPF_LDX | BPF_MEM, 1),
98469- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98470- BPF_STMT(BPF_LDX | BPF_MEM, 2),
98471- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98472- BPF_STMT(BPF_LDX | BPF_MEM, 3),
98473- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98474- BPF_STMT(BPF_LDX | BPF_MEM, 4),
98475- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98476- BPF_STMT(BPF_LDX | BPF_MEM, 5),
98477- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98478- BPF_STMT(BPF_LDX | BPF_MEM, 6),
98479- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98480- BPF_STMT(BPF_LDX | BPF_MEM, 7),
98481- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98482- BPF_STMT(BPF_LDX | BPF_MEM, 8),
98483- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98484- BPF_STMT(BPF_LDX | BPF_MEM, 9),
98485- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98486- BPF_STMT(BPF_LDX | BPF_MEM, 10),
98487- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98488- BPF_STMT(BPF_LDX | BPF_MEM, 11),
98489- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98490- BPF_STMT(BPF_LDX | BPF_MEM, 12),
98491- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98492- BPF_STMT(BPF_LDX | BPF_MEM, 13),
98493- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98494- BPF_STMT(BPF_LDX | BPF_MEM, 14),
98495- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98496- BPF_STMT(BPF_LDX | BPF_MEM, 15),
98497- BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98498- BPF_STMT(BPF_RET | BPF_A, 0),
98499- },
98500- CLASSIC | FLAG_NO_DATA,
98501- { },
98502- { { 0, 0x2a5a5e5 } },
98503- },
98504- {
98505- "check: SKF_AD_MAX",
98506- .u.insns = {
98507- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98508- SKF_AD_OFF + SKF_AD_MAX),
98509- BPF_STMT(BPF_RET | BPF_A, 0),
98510- },
98511- CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98512- { },
98513- { },
98514- },
98515- { /* Passes checker but fails during runtime. */
98516- "LD [SKF_AD_OFF-1]",
98517- .u.insns = {
98518- BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98519- SKF_AD_OFF - 1),
98520- BPF_STMT(BPF_RET | BPF_K, 1),
98521- },
98522- CLASSIC,
98523- { },
98524- { { 1, 0 } },
98525- },
98526-};
98527-
98528-static struct net_device dev;
98529-
98530-static struct sk_buff *populate_skb(char *buf, int size)
98531-{
98532- struct sk_buff *skb;
98533-
98534- if (size >= MAX_DATA)
98535- return NULL;
98536-
98537- skb = alloc_skb(MAX_DATA, GFP_KERNEL);
98538- if (!skb)
98539- return NULL;
98540-
98541- memcpy(__skb_put(skb, size), buf, size);
98542-
98543- /* Initialize a fake skb with test pattern. */
98544- skb_reset_mac_header(skb);
98545- skb->protocol = htons(ETH_P_IP);
98546- skb->pkt_type = SKB_TYPE;
98547- skb->mark = SKB_MARK;
98548- skb->hash = SKB_HASH;
98549- skb->queue_mapping = SKB_QUEUE_MAP;
98550- skb->vlan_tci = SKB_VLAN_TCI;
98551- skb->dev = &dev;
98552- skb->dev->ifindex = SKB_DEV_IFINDEX;
98553- skb->dev->type = SKB_DEV_TYPE;
98554- skb_set_network_header(skb, min(size, ETH_HLEN));
98555-
98556- return skb;
98557-}
98558-
98559-static void *generate_test_data(struct bpf_test *test, int sub)
98560-{
98561- if (test->aux & FLAG_NO_DATA)
98562- return NULL;
98563-
98564- /* Test case expects an skb, so populate one. Various
98565- * subtests generate skbs of different sizes based on
98566- * the same data.
98567- */
98568- return populate_skb(test->data, test->test[sub].data_size);
98569-}
98570-
98571-static void release_test_data(const struct bpf_test *test, void *data)
98572-{
98573- if (test->aux & FLAG_NO_DATA)
98574- return;
98575-
98576- kfree_skb(data);
98577-}
98578-
98579-static int probe_filter_length(struct sock_filter *fp)
98580-{
98581- int len = 0;
98582-
98583- for (len = MAX_INSNS - 1; len > 0; --len)
98584- if (fp[len].code != 0 || fp[len].k != 0)
98585- break;
98586-
98587- return len + 1;
98588-}
98589-
98590-static struct sk_filter *generate_filter(int which, int *err)
98591-{
98592- struct sk_filter *fp;
98593- struct sock_fprog_kern fprog;
98594- unsigned int flen = probe_filter_length(tests[which].u.insns);
98595- __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
98596-
98597- switch (test_type) {
98598- case CLASSIC:
98599- fprog.filter = tests[which].u.insns;
98600- fprog.len = flen;
98601-
98602- *err = sk_unattached_filter_create(&fp, &fprog);
98603- if (tests[which].aux & FLAG_EXPECTED_FAIL) {
98604- if (*err == -EINVAL) {
98605- pr_cont("PASS\n");
98606- /* Verifier rejected filter as expected. */
98607- *err = 0;
98608- return NULL;
98609- } else {
98610- pr_cont("UNEXPECTED_PASS\n");
98611- /* Verifier didn't reject the test that's
98612- * bad enough, just return!
98613- */
98614- *err = -EINVAL;
98615- return NULL;
98616- }
98617- }
98618- /* We don't expect to fail. */
98619- if (*err) {
98620- pr_cont("FAIL to attach err=%d len=%d\n",
98621- *err, fprog.len);
98622- return NULL;
98623- }
98624- break;
98625-
98626- case INTERNAL:
98627- fp = kzalloc(sk_filter_size(flen), GFP_KERNEL);
98628- if (fp == NULL) {
98629- pr_cont("UNEXPECTED_FAIL no memory left\n");
98630- *err = -ENOMEM;
98631- return NULL;
98632- }
98633-
98634- fp->len = flen;
98635- memcpy(fp->insnsi, tests[which].u.insns_int,
98636- fp->len * sizeof(struct sock_filter_int));
98637-
98638- sk_filter_select_runtime(fp);
98639- break;
98640- }
98641-
98642- *err = 0;
98643- return fp;
98644-}
98645-
98646-static void release_filter(struct sk_filter *fp, int which)
98647-{
98648- __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
98649-
98650- switch (test_type) {
98651- case CLASSIC:
98652- sk_unattached_filter_destroy(fp);
98653- break;
98654- case INTERNAL:
98655- sk_filter_free(fp);
98656- break;
98657- }
98658-}
98659-
98660-static int __run_one(const struct sk_filter *fp, const void *data,
98661- int runs, u64 *duration)
98662-{
98663- u64 start, finish;
98664- int ret, i;
98665-
98666- start = ktime_to_us(ktime_get());
98667-
98668- for (i = 0; i < runs; i++)
98669- ret = SK_RUN_FILTER(fp, data);
98670-
98671- finish = ktime_to_us(ktime_get());
98672-
98673- *duration = (finish - start) * 1000ULL;
98674- do_div(*duration, runs);
98675-
98676- return ret;
98677-}
98678-
98679-static int run_one(const struct sk_filter *fp, struct bpf_test *test)
98680-{
98681- int err_cnt = 0, i, runs = MAX_TESTRUNS;
98682-
98683- for (i = 0; i < MAX_SUBTESTS; i++) {
98684- void *data;
98685- u64 duration;
98686- u32 ret;
98687-
98688- if (test->test[i].data_size == 0 &&
98689- test->test[i].result == 0)
98690- break;
98691-
98692- data = generate_test_data(test, i);
98693- ret = __run_one(fp, data, runs, &duration);
98694- release_test_data(test, data);
98695-
98696- if (ret == test->test[i].result) {
98697- pr_cont("%lld ", duration);
98698- } else {
98699- pr_cont("ret %d != %d ", ret,
98700- test->test[i].result);
98701- err_cnt++;
98702- }
98703- }
98704-
98705- return err_cnt;
98706-}
98707-
98708-static __init int test_bpf(void)
98709-{
98710- int i, err_cnt = 0, pass_cnt = 0;
98711-
98712- for (i = 0; i < ARRAY_SIZE(tests); i++) {
98713- struct sk_filter *fp;
98714- int err;
98715-
98716- pr_info("#%d %s ", i, tests[i].descr);
98717-
98718- fp = generate_filter(i, &err);
98719- if (fp == NULL) {
98720- if (err == 0) {
98721- pass_cnt++;
98722- continue;
98723- }
98724-
98725- return err;
98726- }
98727- err = run_one(fp, &tests[i]);
98728- release_filter(fp, i);
98729-
98730- if (err) {
98731- pr_cont("FAIL (%d times)\n", err);
98732- err_cnt++;
98733- } else {
98734- pr_cont("PASS\n");
98735- pass_cnt++;
98736- }
98737- }
98738-
98739- pr_info("Summary: %d PASSED, %d FAILED\n", pass_cnt, err_cnt);
98740- return err_cnt ? -EINVAL : 0;
98741-}
98742-
98743-static int __init test_bpf_init(void)
98744-{
98745- return test_bpf();
98746-}
98747-
98748-static void __exit test_bpf_exit(void)
98749-{
98750-}
98751-
98752-module_init(test_bpf_init);
98753-module_exit(test_bpf_exit);
98754-
98755-MODULE_LICENSE("GPL");
98756diff --git a/lib/usercopy.c b/lib/usercopy.c
98757index 4f5b1dd..7cab418 100644
98758--- a/lib/usercopy.c
98759+++ b/lib/usercopy.c
98760@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
98761 WARN(1, "Buffer overflow detected!\n");
98762 }
98763 EXPORT_SYMBOL(copy_from_user_overflow);
98764+
98765+void copy_to_user_overflow(void)
98766+{
98767+ WARN(1, "Buffer overflow detected!\n");
98768+}
98769+EXPORT_SYMBOL(copy_to_user_overflow);
98770diff --git a/lib/vsprintf.c b/lib/vsprintf.c
98771index 6fe2c84..2fe5ec6 100644
98772--- a/lib/vsprintf.c
98773+++ b/lib/vsprintf.c
98774@@ -16,6 +16,9 @@
98775 * - scnprintf and vscnprintf
98776 */
98777
98778+#ifdef CONFIG_GRKERNSEC_HIDESYM
98779+#define __INCLUDED_BY_HIDESYM 1
98780+#endif
98781 #include <stdarg.h>
98782 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
98783 #include <linux/types.h>
98784@@ -624,7 +627,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
98785 #ifdef CONFIG_KALLSYMS
98786 if (*fmt == 'B')
98787 sprint_backtrace(sym, value);
98788- else if (*fmt != 'f' && *fmt != 's')
98789+ else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
98790 sprint_symbol(sym, value);
98791 else
98792 sprint_symbol_no_offset(sym, value);
98793@@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
98794 return number(buf, end, num, spec);
98795 }
98796
98797+#ifdef CONFIG_GRKERNSEC_HIDESYM
98798+int kptr_restrict __read_mostly = 2;
98799+#else
98800 int kptr_restrict __read_mostly;
98801+#endif
98802
98803 /*
98804 * Show a '%p' thing. A kernel extension is that the '%p' is followed
98805@@ -1194,8 +1201,10 @@ int kptr_restrict __read_mostly;
98806 *
98807 * - 'F' For symbolic function descriptor pointers with offset
98808 * - 'f' For simple symbolic function names without offset
98809+ * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
98810 * - 'S' For symbolic direct pointers with offset
98811 * - 's' For symbolic direct pointers without offset
98812+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
98813 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
98814 * - 'B' For backtraced symbolic direct pointers with offset
98815 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
98816@@ -1263,12 +1272,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
98817
98818 if (!ptr && *fmt != 'K') {
98819 /*
98820- * Print (null) with the same width as a pointer so it makes
98821+ * Print (nil) with the same width as a pointer so it makes
98822 * tabular output look nice.
98823 */
98824 if (spec.field_width == -1)
98825 spec.field_width = default_width;
98826- return string(buf, end, "(null)", spec);
98827+ return string(buf, end, "(nil)", spec);
98828 }
98829
98830 switch (*fmt) {
98831@@ -1278,6 +1287,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
98832 /* Fallthrough */
98833 case 'S':
98834 case 's':
98835+#ifdef CONFIG_GRKERNSEC_HIDESYM
98836+ break;
98837+#else
98838+ return symbol_string(buf, end, ptr, spec, fmt);
98839+#endif
98840+ case 'X':
98841+ ptr = dereference_function_descriptor(ptr);
98842+ case 'A':
98843 case 'B':
98844 return symbol_string(buf, end, ptr, spec, fmt);
98845 case 'R':
98846@@ -1333,6 +1350,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
98847 va_end(va);
98848 return buf;
98849 }
98850+ case 'P':
98851+ break;
98852 case 'K':
98853 /*
98854 * %pK cannot be used in IRQ context because its test
98855@@ -1390,6 +1409,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
98856 ((const struct file *)ptr)->f_path.dentry,
98857 spec, fmt);
98858 }
98859+
98860+#ifdef CONFIG_GRKERNSEC_HIDESYM
98861+ /* 'P' = approved pointers to copy to userland,
98862+ as in the /proc/kallsyms case, as we make it display nothing
98863+ for non-root users, and the real contents for root users
98864+ 'X' = approved simple symbols
98865+ Also ignore 'K' pointers, since we force their NULLing for non-root users
98866+ above
98867+ */
98868+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
98869+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
98870+ dump_stack();
98871+ ptr = NULL;
98872+ }
98873+#endif
98874+
98875 spec.flags |= SMALL;
98876 if (spec.field_width == -1) {
98877 spec.field_width = default_width;
98878@@ -2089,11 +2124,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
98879 typeof(type) value; \
98880 if (sizeof(type) == 8) { \
98881 args = PTR_ALIGN(args, sizeof(u32)); \
98882- *(u32 *)&value = *(u32 *)args; \
98883- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
98884+ *(u32 *)&value = *(const u32 *)args; \
98885+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
98886 } else { \
98887 args = PTR_ALIGN(args, sizeof(type)); \
98888- value = *(typeof(type) *)args; \
98889+ value = *(const typeof(type) *)args; \
98890 } \
98891 args += sizeof(type); \
98892 value; \
98893@@ -2156,7 +2191,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
98894 case FORMAT_TYPE_STR: {
98895 const char *str_arg = args;
98896 args += strlen(str_arg) + 1;
98897- str = string(str, end, (char *)str_arg, spec);
98898+ str = string(str, end, str_arg, spec);
98899 break;
98900 }
98901
98902diff --git a/localversion-grsec b/localversion-grsec
98903new file mode 100644
98904index 0000000..7cd6065
98905--- /dev/null
98906+++ b/localversion-grsec
98907@@ -0,0 +1 @@
98908+-grsec
98909diff --git a/mm/Kconfig b/mm/Kconfig
98910index 3e9977a..205074f 100644
98911--- a/mm/Kconfig
98912+++ b/mm/Kconfig
98913@@ -333,10 +333,11 @@ config KSM
98914 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
98915
98916 config DEFAULT_MMAP_MIN_ADDR
98917- int "Low address space to protect from user allocation"
98918+ int "Low address space to protect from user allocation"
98919 depends on MMU
98920- default 4096
98921- help
98922+ default 32768 if ALPHA || ARM || PARISC || SPARC32
98923+ default 65536
98924+ help
98925 This is the portion of low virtual memory which should be protected
98926 from userspace allocation. Keeping a user from writing to low pages
98927 can help reduce the impact of kernel NULL pointer bugs.
98928@@ -367,7 +368,7 @@ config MEMORY_FAILURE
98929
98930 config HWPOISON_INJECT
98931 tristate "HWPoison pages injector"
98932- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
98933+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
98934 select PROC_PAGE_MONITOR
98935
98936 config NOMMU_INITIAL_TRIM_EXCESS
98937diff --git a/mm/backing-dev.c b/mm/backing-dev.c
98938index 1706cbb..f89dbca 100644
98939--- a/mm/backing-dev.c
98940+++ b/mm/backing-dev.c
98941@@ -12,7 +12,7 @@
98942 #include <linux/device.h>
98943 #include <trace/events/writeback.h>
98944
98945-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
98946+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
98947
98948 struct backing_dev_info default_backing_dev_info = {
98949 .name = "default",
98950@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
98951 return err;
98952
98953 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
98954- atomic_long_inc_return(&bdi_seq));
98955+ atomic_long_inc_return_unchecked(&bdi_seq));
98956 if (err) {
98957 bdi_destroy(bdi);
98958 return err;
98959diff --git a/mm/filemap.c b/mm/filemap.c
98960index 900edfa..ff056b1 100644
98961--- a/mm/filemap.c
98962+++ b/mm/filemap.c
98963@@ -2074,7 +2074,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
98964 struct address_space *mapping = file->f_mapping;
98965
98966 if (!mapping->a_ops->readpage)
98967- return -ENOEXEC;
98968+ return -ENODEV;
98969 file_accessed(file);
98970 vma->vm_ops = &generic_file_vm_ops;
98971 return 0;
98972@@ -2252,6 +2252,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
98973 *pos = i_size_read(inode);
98974
98975 if (limit != RLIM_INFINITY) {
98976+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
98977 if (*pos >= limit) {
98978 send_sig(SIGXFSZ, current, 0);
98979 return -EFBIG;
98980diff --git a/mm/fremap.c b/mm/fremap.c
98981index 72b8fa3..c5b39f1 100644
98982--- a/mm/fremap.c
98983+++ b/mm/fremap.c
98984@@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
98985 retry:
98986 vma = find_vma(mm, start);
98987
98988+#ifdef CONFIG_PAX_SEGMEXEC
98989+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
98990+ goto out;
98991+#endif
98992+
98993 /*
98994 * Make sure the vma is shared, that it supports prefaulting,
98995 * and that the remapped range is valid and fully within
98996diff --git a/mm/gup.c b/mm/gup.c
98997index cc5a9e7..d496acf 100644
98998--- a/mm/gup.c
98999+++ b/mm/gup.c
99000@@ -265,11 +265,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
99001 unsigned int fault_flags = 0;
99002 int ret;
99003
99004- /* For mlock, just skip the stack guard page. */
99005- if ((*flags & FOLL_MLOCK) &&
99006- (stack_guard_page_start(vma, address) ||
99007- stack_guard_page_end(vma, address + PAGE_SIZE)))
99008- return -ENOENT;
99009 if (*flags & FOLL_WRITE)
99010 fault_flags |= FAULT_FLAG_WRITE;
99011 if (nonblocking)
99012@@ -424,14 +419,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
99013 if (!(gup_flags & FOLL_FORCE))
99014 gup_flags |= FOLL_NUMA;
99015
99016- do {
99017+ while (nr_pages) {
99018 struct page *page;
99019 unsigned int foll_flags = gup_flags;
99020 unsigned int page_increm;
99021
99022 /* first iteration or cross vma bound */
99023 if (!vma || start >= vma->vm_end) {
99024- vma = find_extend_vma(mm, start);
99025+ vma = find_vma(mm, start);
99026 if (!vma && in_gate_area(mm, start)) {
99027 int ret;
99028 ret = get_gate_page(mm, start & PAGE_MASK,
99029@@ -443,7 +438,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
99030 goto next_page;
99031 }
99032
99033- if (!vma || check_vma_flags(vma, gup_flags))
99034+ if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
99035 return i ? : -EFAULT;
99036 if (is_vm_hugetlb_page(vma)) {
99037 i = follow_hugetlb_page(mm, vma, pages, vmas,
99038@@ -498,7 +493,7 @@ next_page:
99039 i += page_increm;
99040 start += page_increm * PAGE_SIZE;
99041 nr_pages -= page_increm;
99042- } while (nr_pages);
99043+ }
99044 return i;
99045 }
99046 EXPORT_SYMBOL(__get_user_pages);
99047diff --git a/mm/highmem.c b/mm/highmem.c
99048index b32b70c..e512eb0 100644
99049--- a/mm/highmem.c
99050+++ b/mm/highmem.c
99051@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
99052 * So no dangers, even with speculative execution.
99053 */
99054 page = pte_page(pkmap_page_table[i]);
99055+ pax_open_kernel();
99056 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
99057-
99058+ pax_close_kernel();
99059 set_page_address(page, NULL);
99060 need_flush = 1;
99061 }
99062@@ -198,9 +199,11 @@ start:
99063 }
99064 }
99065 vaddr = PKMAP_ADDR(last_pkmap_nr);
99066+
99067+ pax_open_kernel();
99068 set_pte_at(&init_mm, vaddr,
99069 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
99070-
99071+ pax_close_kernel();
99072 pkmap_count[last_pkmap_nr] = 1;
99073 set_page_address(page, (void *)vaddr);
99074
99075diff --git a/mm/hugetlb.c b/mm/hugetlb.c
99076index 7a0a73d..d583cca 100644
99077--- a/mm/hugetlb.c
99078+++ b/mm/hugetlb.c
99079@@ -2250,6 +2250,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
99080 struct hstate *h = &default_hstate;
99081 unsigned long tmp;
99082 int ret;
99083+ ctl_table_no_const hugetlb_table;
99084
99085 if (!hugepages_supported())
99086 return -ENOTSUPP;
99087@@ -2259,9 +2260,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
99088 if (write && hstate_is_gigantic(h) && !gigantic_page_supported())
99089 return -EINVAL;
99090
99091- table->data = &tmp;
99092- table->maxlen = sizeof(unsigned long);
99093- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
99094+ hugetlb_table = *table;
99095+ hugetlb_table.data = &tmp;
99096+ hugetlb_table.maxlen = sizeof(unsigned long);
99097+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
99098 if (ret)
99099 goto out;
99100
99101@@ -2306,6 +2308,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
99102 struct hstate *h = &default_hstate;
99103 unsigned long tmp;
99104 int ret;
99105+ ctl_table_no_const hugetlb_table;
99106
99107 if (!hugepages_supported())
99108 return -ENOTSUPP;
99109@@ -2315,9 +2318,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
99110 if (write && hstate_is_gigantic(h))
99111 return -EINVAL;
99112
99113- table->data = &tmp;
99114- table->maxlen = sizeof(unsigned long);
99115- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
99116+ hugetlb_table = *table;
99117+ hugetlb_table.data = &tmp;
99118+ hugetlb_table.maxlen = sizeof(unsigned long);
99119+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
99120 if (ret)
99121 goto out;
99122
99123@@ -2798,6 +2802,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
99124 return 1;
99125 }
99126
99127+#ifdef CONFIG_PAX_SEGMEXEC
99128+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
99129+{
99130+ struct mm_struct *mm = vma->vm_mm;
99131+ struct vm_area_struct *vma_m;
99132+ unsigned long address_m;
99133+ pte_t *ptep_m;
99134+
99135+ vma_m = pax_find_mirror_vma(vma);
99136+ if (!vma_m)
99137+ return;
99138+
99139+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
99140+ address_m = address + SEGMEXEC_TASK_SIZE;
99141+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
99142+ get_page(page_m);
99143+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
99144+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
99145+}
99146+#endif
99147+
99148 /*
99149 * Hugetlb_cow() should be called with page lock of the original hugepage held.
99150 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
99151@@ -2915,6 +2940,11 @@ retry_avoidcopy:
99152 make_huge_pte(vma, new_page, 1));
99153 page_remove_rmap(old_page);
99154 hugepage_add_new_anon_rmap(new_page, vma, address);
99155+
99156+#ifdef CONFIG_PAX_SEGMEXEC
99157+ pax_mirror_huge_pte(vma, address, new_page);
99158+#endif
99159+
99160 /* Make the old page be freed below */
99161 new_page = old_page;
99162 }
99163@@ -3074,6 +3104,10 @@ retry:
99164 && (vma->vm_flags & VM_SHARED)));
99165 set_huge_pte_at(mm, address, ptep, new_pte);
99166
99167+#ifdef CONFIG_PAX_SEGMEXEC
99168+ pax_mirror_huge_pte(vma, address, page);
99169+#endif
99170+
99171 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
99172 /* Optimization, do the COW without a second fault */
99173 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
99174@@ -3140,6 +3174,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
99175 struct hstate *h = hstate_vma(vma);
99176 struct address_space *mapping;
99177
99178+#ifdef CONFIG_PAX_SEGMEXEC
99179+ struct vm_area_struct *vma_m;
99180+#endif
99181+
99182 address &= huge_page_mask(h);
99183
99184 ptep = huge_pte_offset(mm, address);
99185@@ -3153,6 +3191,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
99186 VM_FAULT_SET_HINDEX(hstate_index(h));
99187 }
99188
99189+#ifdef CONFIG_PAX_SEGMEXEC
99190+ vma_m = pax_find_mirror_vma(vma);
99191+ if (vma_m) {
99192+ unsigned long address_m;
99193+
99194+ if (vma->vm_start > vma_m->vm_start) {
99195+ address_m = address;
99196+ address -= SEGMEXEC_TASK_SIZE;
99197+ vma = vma_m;
99198+ h = hstate_vma(vma);
99199+ } else
99200+ address_m = address + SEGMEXEC_TASK_SIZE;
99201+
99202+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
99203+ return VM_FAULT_OOM;
99204+ address_m &= HPAGE_MASK;
99205+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
99206+ }
99207+#endif
99208+
99209 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
99210 if (!ptep)
99211 return VM_FAULT_OOM;
99212diff --git a/mm/internal.h b/mm/internal.h
99213index 7f22a11f..f3c207f 100644
99214--- a/mm/internal.h
99215+++ b/mm/internal.h
99216@@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
99217 * in mm/page_alloc.c
99218 */
99219 extern void __free_pages_bootmem(struct page *page, unsigned int order);
99220+extern void free_compound_page(struct page *page);
99221 extern void prep_compound_page(struct page *page, unsigned long order);
99222 #ifdef CONFIG_MEMORY_FAILURE
99223 extern bool is_free_buddy_page(struct page *page);
99224@@ -351,7 +352,7 @@ extern u32 hwpoison_filter_enable;
99225
99226 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
99227 unsigned long, unsigned long,
99228- unsigned long, unsigned long);
99229+ unsigned long, unsigned long) __intentional_overflow(-1);
99230
99231 extern void set_pageblock_order(void);
99232 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
99233diff --git a/mm/iov_iter.c b/mm/iov_iter.c
99234index 7b5dbd1..af0e329 100644
99235--- a/mm/iov_iter.c
99236+++ b/mm/iov_iter.c
99237@@ -173,7 +173,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
99238
99239 while (bytes) {
99240 char __user *buf = iov->iov_base + base;
99241- int copy = min(bytes, iov->iov_len - base);
99242+ size_t copy = min(bytes, iov->iov_len - base);
99243
99244 base = 0;
99245 left = __copy_from_user_inatomic(vaddr, buf, copy);
99246@@ -201,7 +201,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
99247
99248 kaddr = kmap_atomic(page);
99249 if (likely(i->nr_segs == 1)) {
99250- int left;
99251+ size_t left;
99252 char __user *buf = i->iov->iov_base + i->iov_offset;
99253 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
99254 copied = bytes - left;
99255@@ -231,7 +231,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
99256 * zero-length segments (without overruning the iovec).
99257 */
99258 while (bytes || unlikely(i->count && !iov->iov_len)) {
99259- int copy;
99260+ size_t copy;
99261
99262 copy = min(bytes, iov->iov_len - base);
99263 BUG_ON(!i->count || i->count < copy);
99264diff --git a/mm/kmemleak.c b/mm/kmemleak.c
99265index 3cda50c..032ba634 100644
99266--- a/mm/kmemleak.c
99267+++ b/mm/kmemleak.c
99268@@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
99269
99270 for (i = 0; i < object->trace_len; i++) {
99271 void *ptr = (void *)object->trace[i];
99272- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
99273+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
99274 }
99275 }
99276
99277@@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
99278 return -ENOMEM;
99279 }
99280
99281- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
99282+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
99283 &kmemleak_fops);
99284 if (!dentry)
99285 pr_warning("Failed to create the debugfs kmemleak file\n");
99286diff --git a/mm/maccess.c b/mm/maccess.c
99287index d53adf9..03a24bf 100644
99288--- a/mm/maccess.c
99289+++ b/mm/maccess.c
99290@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
99291 set_fs(KERNEL_DS);
99292 pagefault_disable();
99293 ret = __copy_from_user_inatomic(dst,
99294- (__force const void __user *)src, size);
99295+ (const void __force_user *)src, size);
99296 pagefault_enable();
99297 set_fs(old_fs);
99298
99299@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
99300
99301 set_fs(KERNEL_DS);
99302 pagefault_disable();
99303- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
99304+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
99305 pagefault_enable();
99306 set_fs(old_fs);
99307
99308diff --git a/mm/madvise.c b/mm/madvise.c
99309index a402f8f..f5e5daa 100644
99310--- a/mm/madvise.c
99311+++ b/mm/madvise.c
99312@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
99313 pgoff_t pgoff;
99314 unsigned long new_flags = vma->vm_flags;
99315
99316+#ifdef CONFIG_PAX_SEGMEXEC
99317+ struct vm_area_struct *vma_m;
99318+#endif
99319+
99320 switch (behavior) {
99321 case MADV_NORMAL:
99322 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
99323@@ -126,6 +130,13 @@ success:
99324 /*
99325 * vm_flags is protected by the mmap_sem held in write mode.
99326 */
99327+
99328+#ifdef CONFIG_PAX_SEGMEXEC
99329+ vma_m = pax_find_mirror_vma(vma);
99330+ if (vma_m)
99331+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
99332+#endif
99333+
99334 vma->vm_flags = new_flags;
99335
99336 out:
99337@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
99338 struct vm_area_struct **prev,
99339 unsigned long start, unsigned long end)
99340 {
99341+
99342+#ifdef CONFIG_PAX_SEGMEXEC
99343+ struct vm_area_struct *vma_m;
99344+#endif
99345+
99346 *prev = vma;
99347 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
99348 return -EINVAL;
99349@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
99350 zap_page_range(vma, start, end - start, &details);
99351 } else
99352 zap_page_range(vma, start, end - start, NULL);
99353+
99354+#ifdef CONFIG_PAX_SEGMEXEC
99355+ vma_m = pax_find_mirror_vma(vma);
99356+ if (vma_m) {
99357+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
99358+ struct zap_details details = {
99359+ .nonlinear_vma = vma_m,
99360+ .last_index = ULONG_MAX,
99361+ };
99362+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
99363+ } else
99364+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
99365+ }
99366+#endif
99367+
99368 return 0;
99369 }
99370
99371@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
99372 if (end < start)
99373 return error;
99374
99375+#ifdef CONFIG_PAX_SEGMEXEC
99376+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
99377+ if (end > SEGMEXEC_TASK_SIZE)
99378+ return error;
99379+ } else
99380+#endif
99381+
99382+ if (end > TASK_SIZE)
99383+ return error;
99384+
99385 error = 0;
99386 if (end == start)
99387 return error;
99388diff --git a/mm/memory-failure.c b/mm/memory-failure.c
99389index a013bc9..a897a14 100644
99390--- a/mm/memory-failure.c
99391+++ b/mm/memory-failure.c
99392@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
99393
99394 int sysctl_memory_failure_recovery __read_mostly = 1;
99395
99396-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
99397+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
99398
99399 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
99400
99401@@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
99402 pfn, t->comm, t->pid);
99403 si.si_signo = SIGBUS;
99404 si.si_errno = 0;
99405- si.si_addr = (void *)addr;
99406+ si.si_addr = (void __user *)addr;
99407 #ifdef __ARCH_SI_TRAPNO
99408 si.si_trapno = trapno;
99409 #endif
99410@@ -791,7 +791,7 @@ static struct page_state {
99411 unsigned long res;
99412 char *msg;
99413 int (*action)(struct page *p, unsigned long pfn);
99414-} error_states[] = {
99415+} __do_const error_states[] = {
99416 { reserved, reserved, "reserved kernel", me_kernel },
99417 /*
99418 * free pages are specially detected outside this table:
99419@@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
99420 nr_pages = 1 << compound_order(hpage);
99421 else /* normal page or thp */
99422 nr_pages = 1;
99423- atomic_long_add(nr_pages, &num_poisoned_pages);
99424+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
99425
99426 /*
99427 * We need/can do nothing about count=0 pages.
99428@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
99429 if (PageHWPoison(hpage)) {
99430 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
99431 || (p != hpage && TestSetPageHWPoison(hpage))) {
99432- atomic_long_sub(nr_pages, &num_poisoned_pages);
99433+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
99434 unlock_page(hpage);
99435 return 0;
99436 }
99437@@ -1186,14 +1186,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
99438 */
99439 if (!PageHWPoison(p)) {
99440 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
99441- atomic_long_sub(nr_pages, &num_poisoned_pages);
99442+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
99443 put_page(hpage);
99444 res = 0;
99445 goto out;
99446 }
99447 if (hwpoison_filter(p)) {
99448 if (TestClearPageHWPoison(p))
99449- atomic_long_sub(nr_pages, &num_poisoned_pages);
99450+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
99451 unlock_page(hpage);
99452 put_page(hpage);
99453 return 0;
99454@@ -1423,7 +1423,7 @@ int unpoison_memory(unsigned long pfn)
99455 return 0;
99456 }
99457 if (TestClearPageHWPoison(p))
99458- atomic_long_dec(&num_poisoned_pages);
99459+ atomic_long_dec_unchecked(&num_poisoned_pages);
99460 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
99461 return 0;
99462 }
99463@@ -1437,7 +1437,7 @@ int unpoison_memory(unsigned long pfn)
99464 */
99465 if (TestClearPageHWPoison(page)) {
99466 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
99467- atomic_long_sub(nr_pages, &num_poisoned_pages);
99468+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
99469 freeit = 1;
99470 if (PageHuge(page))
99471 clear_page_hwpoison_huge_page(page);
99472@@ -1562,11 +1562,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
99473 if (PageHuge(page)) {
99474 set_page_hwpoison_huge_page(hpage);
99475 dequeue_hwpoisoned_huge_page(hpage);
99476- atomic_long_add(1 << compound_order(hpage),
99477+ atomic_long_add_unchecked(1 << compound_order(hpage),
99478 &num_poisoned_pages);
99479 } else {
99480 SetPageHWPoison(page);
99481- atomic_long_inc(&num_poisoned_pages);
99482+ atomic_long_inc_unchecked(&num_poisoned_pages);
99483 }
99484 }
99485 return ret;
99486@@ -1605,7 +1605,7 @@ static int __soft_offline_page(struct page *page, int flags)
99487 put_page(page);
99488 pr_info("soft_offline: %#lx: invalidated\n", pfn);
99489 SetPageHWPoison(page);
99490- atomic_long_inc(&num_poisoned_pages);
99491+ atomic_long_inc_unchecked(&num_poisoned_pages);
99492 return 0;
99493 }
99494
99495@@ -1656,7 +1656,7 @@ static int __soft_offline_page(struct page *page, int flags)
99496 if (!is_free_buddy_page(page))
99497 pr_info("soft offline: %#lx: page leaked\n",
99498 pfn);
99499- atomic_long_inc(&num_poisoned_pages);
99500+ atomic_long_inc_unchecked(&num_poisoned_pages);
99501 }
99502 } else {
99503 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
99504@@ -1726,11 +1726,11 @@ int soft_offline_page(struct page *page, int flags)
99505 if (PageHuge(page)) {
99506 set_page_hwpoison_huge_page(hpage);
99507 dequeue_hwpoisoned_huge_page(hpage);
99508- atomic_long_add(1 << compound_order(hpage),
99509+ atomic_long_add_unchecked(1 << compound_order(hpage),
99510 &num_poisoned_pages);
99511 } else {
99512 SetPageHWPoison(page);
99513- atomic_long_inc(&num_poisoned_pages);
99514+ atomic_long_inc_unchecked(&num_poisoned_pages);
99515 }
99516 }
99517 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
99518diff --git a/mm/memory.c b/mm/memory.c
99519index 8b44f76..babeaec 100644
99520--- a/mm/memory.c
99521+++ b/mm/memory.c
99522@@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
99523 free_pte_range(tlb, pmd, addr);
99524 } while (pmd++, addr = next, addr != end);
99525
99526+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
99527 start &= PUD_MASK;
99528 if (start < floor)
99529 return;
99530@@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
99531 pmd = pmd_offset(pud, start);
99532 pud_clear(pud);
99533 pmd_free_tlb(tlb, pmd, start);
99534+#endif
99535+
99536 }
99537
99538 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
99539@@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
99540 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
99541 } while (pud++, addr = next, addr != end);
99542
99543+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
99544 start &= PGDIR_MASK;
99545 if (start < floor)
99546 return;
99547@@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
99548 pud = pud_offset(pgd, start);
99549 pgd_clear(pgd);
99550 pud_free_tlb(tlb, pud, start);
99551+#endif
99552+
99553 }
99554
99555 /*
99556@@ -751,7 +757,7 @@ struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr,
99557 unsigned long pfn = pte_pfn(pte);
99558
99559 if (HAVE_PTE_SPECIAL) {
99560- if (likely(!pte_special(pte) || pte_numa(pte)))
99561+ if (likely(!pte_special(pte)))
99562 goto check_pfn;
99563 if (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP))
99564 return NULL;
99565@@ -777,15 +783,14 @@ struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr,
99566 }
99567 }
99568
99569+ if (is_zero_pfn(pfn))
99570+ return NULL;
99571 check_pfn:
99572 if (unlikely(pfn > highest_memmap_pfn)) {
99573 print_bad_pte(vma, addr, pte, NULL);
99574 return NULL;
99575 }
99576
99577- if (is_zero_pfn(pfn))
99578- return NULL;
99579-
99580 /*
99581 * NOTE! We still have PageReserved() pages in the page tables.
99582 * eg. VDSO mappings can cause them to exist.
99583@@ -1501,6 +1506,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
99584 page_add_file_rmap(page);
99585 set_pte_at(mm, addr, pte, mk_pte(page, prot));
99586
99587+#ifdef CONFIG_PAX_SEGMEXEC
99588+ pax_mirror_file_pte(vma, addr, page, ptl);
99589+#endif
99590+
99591 retval = 0;
99592 pte_unmap_unlock(pte, ptl);
99593 return retval;
99594@@ -1545,9 +1554,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
99595 if (!page_count(page))
99596 return -EINVAL;
99597 if (!(vma->vm_flags & VM_MIXEDMAP)) {
99598+
99599+#ifdef CONFIG_PAX_SEGMEXEC
99600+ struct vm_area_struct *vma_m;
99601+#endif
99602+
99603 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
99604 BUG_ON(vma->vm_flags & VM_PFNMAP);
99605 vma->vm_flags |= VM_MIXEDMAP;
99606+
99607+#ifdef CONFIG_PAX_SEGMEXEC
99608+ vma_m = pax_find_mirror_vma(vma);
99609+ if (vma_m)
99610+ vma_m->vm_flags |= VM_MIXEDMAP;
99611+#endif
99612+
99613 }
99614 return insert_page(vma, addr, page, vma->vm_page_prot);
99615 }
99616@@ -1630,6 +1651,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
99617 unsigned long pfn)
99618 {
99619 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
99620+ BUG_ON(vma->vm_mirror);
99621
99622 if (addr < vma->vm_start || addr >= vma->vm_end)
99623 return -EFAULT;
99624@@ -1877,7 +1899,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
99625
99626 BUG_ON(pud_huge(*pud));
99627
99628- pmd = pmd_alloc(mm, pud, addr);
99629+ pmd = (mm == &init_mm) ?
99630+ pmd_alloc_kernel(mm, pud, addr) :
99631+ pmd_alloc(mm, pud, addr);
99632 if (!pmd)
99633 return -ENOMEM;
99634 do {
99635@@ -1897,7 +1921,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
99636 unsigned long next;
99637 int err;
99638
99639- pud = pud_alloc(mm, pgd, addr);
99640+ pud = (mm == &init_mm) ?
99641+ pud_alloc_kernel(mm, pgd, addr) :
99642+ pud_alloc(mm, pgd, addr);
99643 if (!pud)
99644 return -ENOMEM;
99645 do {
99646@@ -2019,6 +2045,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
99647 return ret;
99648 }
99649
99650+#ifdef CONFIG_PAX_SEGMEXEC
99651+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
99652+{
99653+ struct mm_struct *mm = vma->vm_mm;
99654+ spinlock_t *ptl;
99655+ pte_t *pte, entry;
99656+
99657+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
99658+ entry = *pte;
99659+ if (!pte_present(entry)) {
99660+ if (!pte_none(entry)) {
99661+ BUG_ON(pte_file(entry));
99662+ free_swap_and_cache(pte_to_swp_entry(entry));
99663+ pte_clear_not_present_full(mm, address, pte, 0);
99664+ }
99665+ } else {
99666+ struct page *page;
99667+
99668+ flush_cache_page(vma, address, pte_pfn(entry));
99669+ entry = ptep_clear_flush(vma, address, pte);
99670+ BUG_ON(pte_dirty(entry));
99671+ page = vm_normal_page(vma, address, entry);
99672+ if (page) {
99673+ update_hiwater_rss(mm);
99674+ if (PageAnon(page))
99675+ dec_mm_counter_fast(mm, MM_ANONPAGES);
99676+ else
99677+ dec_mm_counter_fast(mm, MM_FILEPAGES);
99678+ page_remove_rmap(page);
99679+ page_cache_release(page);
99680+ }
99681+ }
99682+ pte_unmap_unlock(pte, ptl);
99683+}
99684+
99685+/* PaX: if vma is mirrored, synchronize the mirror's PTE
99686+ *
99687+ * the ptl of the lower mapped page is held on entry and is not released on exit
99688+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
99689+ */
99690+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
99691+{
99692+ struct mm_struct *mm = vma->vm_mm;
99693+ unsigned long address_m;
99694+ spinlock_t *ptl_m;
99695+ struct vm_area_struct *vma_m;
99696+ pmd_t *pmd_m;
99697+ pte_t *pte_m, entry_m;
99698+
99699+ BUG_ON(!page_m || !PageAnon(page_m));
99700+
99701+ vma_m = pax_find_mirror_vma(vma);
99702+ if (!vma_m)
99703+ return;
99704+
99705+ BUG_ON(!PageLocked(page_m));
99706+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
99707+ address_m = address + SEGMEXEC_TASK_SIZE;
99708+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
99709+ pte_m = pte_offset_map(pmd_m, address_m);
99710+ ptl_m = pte_lockptr(mm, pmd_m);
99711+ if (ptl != ptl_m) {
99712+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
99713+ if (!pte_none(*pte_m))
99714+ goto out;
99715+ }
99716+
99717+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
99718+ page_cache_get(page_m);
99719+ page_add_anon_rmap(page_m, vma_m, address_m);
99720+ inc_mm_counter_fast(mm, MM_ANONPAGES);
99721+ set_pte_at(mm, address_m, pte_m, entry_m);
99722+ update_mmu_cache(vma_m, address_m, pte_m);
99723+out:
99724+ if (ptl != ptl_m)
99725+ spin_unlock(ptl_m);
99726+ pte_unmap(pte_m);
99727+ unlock_page(page_m);
99728+}
99729+
99730+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
99731+{
99732+ struct mm_struct *mm = vma->vm_mm;
99733+ unsigned long address_m;
99734+ spinlock_t *ptl_m;
99735+ struct vm_area_struct *vma_m;
99736+ pmd_t *pmd_m;
99737+ pte_t *pte_m, entry_m;
99738+
99739+ BUG_ON(!page_m || PageAnon(page_m));
99740+
99741+ vma_m = pax_find_mirror_vma(vma);
99742+ if (!vma_m)
99743+ return;
99744+
99745+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
99746+ address_m = address + SEGMEXEC_TASK_SIZE;
99747+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
99748+ pte_m = pte_offset_map(pmd_m, address_m);
99749+ ptl_m = pte_lockptr(mm, pmd_m);
99750+ if (ptl != ptl_m) {
99751+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
99752+ if (!pte_none(*pte_m))
99753+ goto out;
99754+ }
99755+
99756+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
99757+ page_cache_get(page_m);
99758+ page_add_file_rmap(page_m);
99759+ inc_mm_counter_fast(mm, MM_FILEPAGES);
99760+ set_pte_at(mm, address_m, pte_m, entry_m);
99761+ update_mmu_cache(vma_m, address_m, pte_m);
99762+out:
99763+ if (ptl != ptl_m)
99764+ spin_unlock(ptl_m);
99765+ pte_unmap(pte_m);
99766+}
99767+
99768+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
99769+{
99770+ struct mm_struct *mm = vma->vm_mm;
99771+ unsigned long address_m;
99772+ spinlock_t *ptl_m;
99773+ struct vm_area_struct *vma_m;
99774+ pmd_t *pmd_m;
99775+ pte_t *pte_m, entry_m;
99776+
99777+ vma_m = pax_find_mirror_vma(vma);
99778+ if (!vma_m)
99779+ return;
99780+
99781+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
99782+ address_m = address + SEGMEXEC_TASK_SIZE;
99783+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
99784+ pte_m = pte_offset_map(pmd_m, address_m);
99785+ ptl_m = pte_lockptr(mm, pmd_m);
99786+ if (ptl != ptl_m) {
99787+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
99788+ if (!pte_none(*pte_m))
99789+ goto out;
99790+ }
99791+
99792+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
99793+ set_pte_at(mm, address_m, pte_m, entry_m);
99794+out:
99795+ if (ptl != ptl_m)
99796+ spin_unlock(ptl_m);
99797+ pte_unmap(pte_m);
99798+}
99799+
99800+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
99801+{
99802+ struct page *page_m;
99803+ pte_t entry;
99804+
99805+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
99806+ goto out;
99807+
99808+ entry = *pte;
99809+ page_m = vm_normal_page(vma, address, entry);
99810+ if (!page_m)
99811+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
99812+ else if (PageAnon(page_m)) {
99813+ if (pax_find_mirror_vma(vma)) {
99814+ pte_unmap_unlock(pte, ptl);
99815+ lock_page(page_m);
99816+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
99817+ if (pte_same(entry, *pte))
99818+ pax_mirror_anon_pte(vma, address, page_m, ptl);
99819+ else
99820+ unlock_page(page_m);
99821+ }
99822+ } else
99823+ pax_mirror_file_pte(vma, address, page_m, ptl);
99824+
99825+out:
99826+ pte_unmap_unlock(pte, ptl);
99827+}
99828+#endif
99829+
99830 /*
99831 * This routine handles present pages, when users try to write
99832 * to a shared page. It is done by copying the page to a new address
99833@@ -2216,6 +2422,12 @@ gotten:
99834 */
99835 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
99836 if (likely(pte_same(*page_table, orig_pte))) {
99837+
99838+#ifdef CONFIG_PAX_SEGMEXEC
99839+ if (pax_find_mirror_vma(vma))
99840+ BUG_ON(!trylock_page(new_page));
99841+#endif
99842+
99843 if (old_page) {
99844 if (!PageAnon(old_page)) {
99845 dec_mm_counter_fast(mm, MM_FILEPAGES);
99846@@ -2267,6 +2479,10 @@ gotten:
99847 page_remove_rmap(old_page);
99848 }
99849
99850+#ifdef CONFIG_PAX_SEGMEXEC
99851+ pax_mirror_anon_pte(vma, address, new_page, ptl);
99852+#endif
99853+
99854 /* Free the old page.. */
99855 new_page = old_page;
99856 ret |= VM_FAULT_WRITE;
99857@@ -2540,6 +2756,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
99858 swap_free(entry);
99859 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
99860 try_to_free_swap(page);
99861+
99862+#ifdef CONFIG_PAX_SEGMEXEC
99863+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
99864+#endif
99865+
99866 unlock_page(page);
99867 if (page != swapcache) {
99868 /*
99869@@ -2563,6 +2784,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
99870
99871 /* No need to invalidate - it was non-present before */
99872 update_mmu_cache(vma, address, page_table);
99873+
99874+#ifdef CONFIG_PAX_SEGMEXEC
99875+ pax_mirror_anon_pte(vma, address, page, ptl);
99876+#endif
99877+
99878 unlock:
99879 pte_unmap_unlock(page_table, ptl);
99880 out:
99881@@ -2582,40 +2808,6 @@ out_release:
99882 }
99883
99884 /*
99885- * This is like a special single-page "expand_{down|up}wards()",
99886- * except we must first make sure that 'address{-|+}PAGE_SIZE'
99887- * doesn't hit another vma.
99888- */
99889-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
99890-{
99891- address &= PAGE_MASK;
99892- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
99893- struct vm_area_struct *prev = vma->vm_prev;
99894-
99895- /*
99896- * Is there a mapping abutting this one below?
99897- *
99898- * That's only ok if it's the same stack mapping
99899- * that has gotten split..
99900- */
99901- if (prev && prev->vm_end == address)
99902- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
99903-
99904- expand_downwards(vma, address - PAGE_SIZE);
99905- }
99906- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
99907- struct vm_area_struct *next = vma->vm_next;
99908-
99909- /* As VM_GROWSDOWN but s/below/above/ */
99910- if (next && next->vm_start == address + PAGE_SIZE)
99911- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
99912-
99913- expand_upwards(vma, address + PAGE_SIZE);
99914- }
99915- return 0;
99916-}
99917-
99918-/*
99919 * We enter with non-exclusive mmap_sem (to exclude vma changes,
99920 * but allow concurrent faults), and pte mapped but not yet locked.
99921 * We return with mmap_sem still held, but pte unmapped and unlocked.
99922@@ -2624,27 +2816,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
99923 unsigned long address, pte_t *page_table, pmd_t *pmd,
99924 unsigned int flags)
99925 {
99926- struct page *page;
99927+ struct page *page = NULL;
99928 spinlock_t *ptl;
99929 pte_t entry;
99930
99931- pte_unmap(page_table);
99932-
99933- /* Check if we need to add a guard page to the stack */
99934- if (check_stack_guard_page(vma, address) < 0)
99935- return VM_FAULT_SIGBUS;
99936-
99937- /* Use the zero-page for reads */
99938 if (!(flags & FAULT_FLAG_WRITE)) {
99939 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
99940 vma->vm_page_prot));
99941- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
99942+ ptl = pte_lockptr(mm, pmd);
99943+ spin_lock(ptl);
99944 if (!pte_none(*page_table))
99945 goto unlock;
99946 goto setpte;
99947 }
99948
99949 /* Allocate our own private page. */
99950+ pte_unmap(page_table);
99951+
99952 if (unlikely(anon_vma_prepare(vma)))
99953 goto oom;
99954 page = alloc_zeroed_user_highpage_movable(vma, address);
99955@@ -2668,6 +2856,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
99956 if (!pte_none(*page_table))
99957 goto release;
99958
99959+#ifdef CONFIG_PAX_SEGMEXEC
99960+ if (pax_find_mirror_vma(vma))
99961+ BUG_ON(!trylock_page(page));
99962+#endif
99963+
99964 inc_mm_counter_fast(mm, MM_ANONPAGES);
99965 page_add_new_anon_rmap(page, vma, address);
99966 setpte:
99967@@ -2675,6 +2868,12 @@ setpte:
99968
99969 /* No need to invalidate - it was non-present before */
99970 update_mmu_cache(vma, address, page_table);
99971+
99972+#ifdef CONFIG_PAX_SEGMEXEC
99973+ if (page)
99974+ pax_mirror_anon_pte(vma, address, page, ptl);
99975+#endif
99976+
99977 unlock:
99978 pte_unmap_unlock(page_table, ptl);
99979 return 0;
99980@@ -2906,6 +3105,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
99981 return ret;
99982 }
99983 do_set_pte(vma, address, fault_page, pte, false, false);
99984+
99985+#ifdef CONFIG_PAX_SEGMEXEC
99986+ pax_mirror_file_pte(vma, address, fault_page, ptl);
99987+#endif
99988+
99989 unlock_page(fault_page);
99990 unlock_out:
99991 pte_unmap_unlock(pte, ptl);
99992@@ -2947,7 +3151,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
99993 page_cache_release(fault_page);
99994 goto uncharge_out;
99995 }
99996+
99997+#ifdef CONFIG_PAX_SEGMEXEC
99998+ if (pax_find_mirror_vma(vma))
99999+ BUG_ON(!trylock_page(new_page));
100000+#endif
100001+
100002 do_set_pte(vma, address, new_page, pte, true, true);
100003+
100004+#ifdef CONFIG_PAX_SEGMEXEC
100005+ pax_mirror_anon_pte(vma, address, new_page, ptl);
100006+#endif
100007+
100008 pte_unmap_unlock(pte, ptl);
100009 unlock_page(fault_page);
100010 page_cache_release(fault_page);
100011@@ -2995,6 +3210,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
100012 return ret;
100013 }
100014 do_set_pte(vma, address, fault_page, pte, true, false);
100015+
100016+#ifdef CONFIG_PAX_SEGMEXEC
100017+ pax_mirror_file_pte(vma, address, fault_page, ptl);
100018+#endif
100019+
100020 pte_unmap_unlock(pte, ptl);
100021
100022 if (set_page_dirty(fault_page))
100023@@ -3225,6 +3445,12 @@ static int handle_pte_fault(struct mm_struct *mm,
100024 if (flags & FAULT_FLAG_WRITE)
100025 flush_tlb_fix_spurious_fault(vma, address);
100026 }
100027+
100028+#ifdef CONFIG_PAX_SEGMEXEC
100029+ pax_mirror_pte(vma, address, pte, pmd, ptl);
100030+ return 0;
100031+#endif
100032+
100033 unlock:
100034 pte_unmap_unlock(pte, ptl);
100035 return 0;
100036@@ -3241,9 +3467,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
100037 pmd_t *pmd;
100038 pte_t *pte;
100039
100040+#ifdef CONFIG_PAX_SEGMEXEC
100041+ struct vm_area_struct *vma_m;
100042+#endif
100043+
100044 if (unlikely(is_vm_hugetlb_page(vma)))
100045 return hugetlb_fault(mm, vma, address, flags);
100046
100047+#ifdef CONFIG_PAX_SEGMEXEC
100048+ vma_m = pax_find_mirror_vma(vma);
100049+ if (vma_m) {
100050+ unsigned long address_m;
100051+ pgd_t *pgd_m;
100052+ pud_t *pud_m;
100053+ pmd_t *pmd_m;
100054+
100055+ if (vma->vm_start > vma_m->vm_start) {
100056+ address_m = address;
100057+ address -= SEGMEXEC_TASK_SIZE;
100058+ vma = vma_m;
100059+ } else
100060+ address_m = address + SEGMEXEC_TASK_SIZE;
100061+
100062+ pgd_m = pgd_offset(mm, address_m);
100063+ pud_m = pud_alloc(mm, pgd_m, address_m);
100064+ if (!pud_m)
100065+ return VM_FAULT_OOM;
100066+ pmd_m = pmd_alloc(mm, pud_m, address_m);
100067+ if (!pmd_m)
100068+ return VM_FAULT_OOM;
100069+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
100070+ return VM_FAULT_OOM;
100071+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
100072+ }
100073+#endif
100074+
100075 pgd = pgd_offset(mm, address);
100076 pud = pud_alloc(mm, pgd, address);
100077 if (!pud)
100078@@ -3371,6 +3629,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
100079 spin_unlock(&mm->page_table_lock);
100080 return 0;
100081 }
100082+
100083+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
100084+{
100085+ pud_t *new = pud_alloc_one(mm, address);
100086+ if (!new)
100087+ return -ENOMEM;
100088+
100089+ smp_wmb(); /* See comment in __pte_alloc */
100090+
100091+ spin_lock(&mm->page_table_lock);
100092+ if (pgd_present(*pgd)) /* Another has populated it */
100093+ pud_free(mm, new);
100094+ else
100095+ pgd_populate_kernel(mm, pgd, new);
100096+ spin_unlock(&mm->page_table_lock);
100097+ return 0;
100098+}
100099 #endif /* __PAGETABLE_PUD_FOLDED */
100100
100101 #ifndef __PAGETABLE_PMD_FOLDED
100102@@ -3401,6 +3676,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
100103 spin_unlock(&mm->page_table_lock);
100104 return 0;
100105 }
100106+
100107+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
100108+{
100109+ pmd_t *new = pmd_alloc_one(mm, address);
100110+ if (!new)
100111+ return -ENOMEM;
100112+
100113+ smp_wmb(); /* See comment in __pte_alloc */
100114+
100115+ spin_lock(&mm->page_table_lock);
100116+#ifndef __ARCH_HAS_4LEVEL_HACK
100117+ if (pud_present(*pud)) /* Another has populated it */
100118+ pmd_free(mm, new);
100119+ else
100120+ pud_populate_kernel(mm, pud, new);
100121+#else
100122+ if (pgd_present(*pud)) /* Another has populated it */
100123+ pmd_free(mm, new);
100124+ else
100125+ pgd_populate_kernel(mm, pud, new);
100126+#endif /* __ARCH_HAS_4LEVEL_HACK */
100127+ spin_unlock(&mm->page_table_lock);
100128+ return 0;
100129+}
100130 #endif /* __PAGETABLE_PMD_FOLDED */
100131
100132 #if !defined(__HAVE_ARCH_GATE_AREA)
100133@@ -3414,7 +3713,7 @@ static int __init gate_vma_init(void)
100134 gate_vma.vm_start = FIXADDR_USER_START;
100135 gate_vma.vm_end = FIXADDR_USER_END;
100136 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
100137- gate_vma.vm_page_prot = __P101;
100138+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
100139
100140 return 0;
100141 }
100142@@ -3548,8 +3847,8 @@ out:
100143 return ret;
100144 }
100145
100146-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
100147- void *buf, int len, int write)
100148+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
100149+ void *buf, size_t len, int write)
100150 {
100151 resource_size_t phys_addr;
100152 unsigned long prot = 0;
100153@@ -3575,8 +3874,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
100154 * Access another process' address space as given in mm. If non-NULL, use the
100155 * given task for page fault accounting.
100156 */
100157-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
100158- unsigned long addr, void *buf, int len, int write)
100159+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
100160+ unsigned long addr, void *buf, size_t len, int write)
100161 {
100162 struct vm_area_struct *vma;
100163 void *old_buf = buf;
100164@@ -3584,7 +3883,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
100165 down_read(&mm->mmap_sem);
100166 /* ignore errors, just check how much was successfully transferred */
100167 while (len) {
100168- int bytes, ret, offset;
100169+ ssize_t bytes, ret, offset;
100170 void *maddr;
100171 struct page *page = NULL;
100172
100173@@ -3643,8 +3942,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
100174 *
100175 * The caller must hold a reference on @mm.
100176 */
100177-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
100178- void *buf, int len, int write)
100179+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
100180+ void *buf, size_t len, int write)
100181 {
100182 return __access_remote_vm(NULL, mm, addr, buf, len, write);
100183 }
100184@@ -3654,11 +3953,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
100185 * Source/target buffer must be kernel space,
100186 * Do not walk the page table directly, use get_user_pages
100187 */
100188-int access_process_vm(struct task_struct *tsk, unsigned long addr,
100189- void *buf, int len, int write)
100190+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
100191+ void *buf, size_t len, int write)
100192 {
100193 struct mm_struct *mm;
100194- int ret;
100195+ ssize_t ret;
100196
100197 mm = get_task_mm(tsk);
100198 if (!mm)
100199diff --git a/mm/mempolicy.c b/mm/mempolicy.c
100200index 8f5330d..b41914b 100644
100201--- a/mm/mempolicy.c
100202+++ b/mm/mempolicy.c
100203@@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
100204 unsigned long vmstart;
100205 unsigned long vmend;
100206
100207+#ifdef CONFIG_PAX_SEGMEXEC
100208+ struct vm_area_struct *vma_m;
100209+#endif
100210+
100211 vma = find_vma(mm, start);
100212 if (!vma || vma->vm_start > start)
100213 return -EFAULT;
100214@@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
100215 err = vma_replace_policy(vma, new_pol);
100216 if (err)
100217 goto out;
100218+
100219+#ifdef CONFIG_PAX_SEGMEXEC
100220+ vma_m = pax_find_mirror_vma(vma);
100221+ if (vma_m) {
100222+ err = vma_replace_policy(vma_m, new_pol);
100223+ if (err)
100224+ goto out;
100225+ }
100226+#endif
100227+
100228 }
100229
100230 out:
100231@@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
100232
100233 if (end < start)
100234 return -EINVAL;
100235+
100236+#ifdef CONFIG_PAX_SEGMEXEC
100237+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
100238+ if (end > SEGMEXEC_TASK_SIZE)
100239+ return -EINVAL;
100240+ } else
100241+#endif
100242+
100243+ if (end > TASK_SIZE)
100244+ return -EINVAL;
100245+
100246 if (end == start)
100247 return 0;
100248
100249@@ -1450,8 +1475,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
100250 */
100251 tcred = __task_cred(task);
100252 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
100253- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
100254- !capable(CAP_SYS_NICE)) {
100255+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
100256 rcu_read_unlock();
100257 err = -EPERM;
100258 goto out_put;
100259@@ -1482,6 +1506,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
100260 goto out;
100261 }
100262
100263+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
100264+ if (mm != current->mm &&
100265+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
100266+ mmput(mm);
100267+ err = -EPERM;
100268+ goto out;
100269+ }
100270+#endif
100271+
100272 err = do_migrate_pages(mm, old, new,
100273 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
100274
100275diff --git a/mm/migrate.c b/mm/migrate.c
100276index be6dbf9..febb8ec 100644
100277--- a/mm/migrate.c
100278+++ b/mm/migrate.c
100279@@ -1506,8 +1506,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
100280 */
100281 tcred = __task_cred(task);
100282 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
100283- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
100284- !capable(CAP_SYS_NICE)) {
100285+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
100286 rcu_read_unlock();
100287 err = -EPERM;
100288 goto out;
100289diff --git a/mm/mlock.c b/mm/mlock.c
100290index b1eb536..091d154 100644
100291--- a/mm/mlock.c
100292+++ b/mm/mlock.c
100293@@ -14,6 +14,7 @@
100294 #include <linux/pagevec.h>
100295 #include <linux/mempolicy.h>
100296 #include <linux/syscalls.h>
100297+#include <linux/security.h>
100298 #include <linux/sched.h>
100299 #include <linux/export.h>
100300 #include <linux/rmap.h>
100301@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
100302 {
100303 unsigned long nstart, end, tmp;
100304 struct vm_area_struct * vma, * prev;
100305- int error;
100306+ int error = 0;
100307
100308 VM_BUG_ON(start & ~PAGE_MASK);
100309 VM_BUG_ON(len != PAGE_ALIGN(len));
100310@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
100311 return -EINVAL;
100312 if (end == start)
100313 return 0;
100314+ if (end > TASK_SIZE)
100315+ return -EINVAL;
100316+
100317 vma = find_vma(current->mm, start);
100318 if (!vma || vma->vm_start > start)
100319 return -ENOMEM;
100320@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
100321 for (nstart = start ; ; ) {
100322 vm_flags_t newflags;
100323
100324+#ifdef CONFIG_PAX_SEGMEXEC
100325+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
100326+ break;
100327+#endif
100328+
100329 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
100330
100331 newflags = vma->vm_flags & ~VM_LOCKED;
100332@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
100333 locked += current->mm->locked_vm;
100334
100335 /* check against resource limits */
100336+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
100337 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
100338 error = do_mlock(start, len, 1);
100339
100340@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
100341 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
100342 vm_flags_t newflags;
100343
100344+#ifdef CONFIG_PAX_SEGMEXEC
100345+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
100346+ break;
100347+#endif
100348+
100349 newflags = vma->vm_flags & ~VM_LOCKED;
100350 if (flags & MCL_CURRENT)
100351 newflags |= VM_LOCKED;
100352@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
100353 lock_limit >>= PAGE_SHIFT;
100354
100355 ret = -ENOMEM;
100356+
100357+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
100358+
100359 down_write(&current->mm->mmap_sem);
100360-
100361 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
100362 capable(CAP_IPC_LOCK))
100363 ret = do_mlockall(flags);
100364diff --git a/mm/mmap.c b/mm/mmap.c
100365index 129b847..fbed804 100644
100366--- a/mm/mmap.c
100367+++ b/mm/mmap.c
100368@@ -40,6 +40,7 @@
100369 #include <linux/notifier.h>
100370 #include <linux/memory.h>
100371 #include <linux/printk.h>
100372+#include <linux/random.h>
100373
100374 #include <asm/uaccess.h>
100375 #include <asm/cacheflush.h>
100376@@ -56,6 +57,16 @@
100377 #define arch_rebalance_pgtables(addr, len) (addr)
100378 #endif
100379
100380+static inline void verify_mm_writelocked(struct mm_struct *mm)
100381+{
100382+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
100383+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
100384+ up_read(&mm->mmap_sem);
100385+ BUG();
100386+ }
100387+#endif
100388+}
100389+
100390 static void unmap_region(struct mm_struct *mm,
100391 struct vm_area_struct *vma, struct vm_area_struct *prev,
100392 unsigned long start, unsigned long end);
100393@@ -75,16 +86,25 @@ static void unmap_region(struct mm_struct *mm,
100394 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
100395 *
100396 */
100397-pgprot_t protection_map[16] = {
100398+pgprot_t protection_map[16] __read_only = {
100399 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
100400 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
100401 };
100402
100403-pgprot_t vm_get_page_prot(unsigned long vm_flags)
100404+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
100405 {
100406- return __pgprot(pgprot_val(protection_map[vm_flags &
100407+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
100408 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
100409 pgprot_val(arch_vm_get_page_prot(vm_flags)));
100410+
100411+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
100412+ if (!(__supported_pte_mask & _PAGE_NX) &&
100413+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
100414+ (vm_flags & (VM_READ | VM_WRITE)))
100415+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
100416+#endif
100417+
100418+ return prot;
100419 }
100420 EXPORT_SYMBOL(vm_get_page_prot);
100421
100422@@ -94,6 +114,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
100423 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
100424 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
100425 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
100426+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
100427 /*
100428 * Make sure vm_committed_as in one cacheline and not cacheline shared with
100429 * other variables. It can be updated by several CPUs frequently.
100430@@ -250,6 +271,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
100431 struct vm_area_struct *next = vma->vm_next;
100432
100433 might_sleep();
100434+ BUG_ON(vma->vm_mirror);
100435 if (vma->vm_ops && vma->vm_ops->close)
100436 vma->vm_ops->close(vma);
100437 if (vma->vm_file)
100438@@ -294,6 +316,12 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
100439 * not page aligned -Ram Gupta
100440 */
100441 rlim = rlimit(RLIMIT_DATA);
100442+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
100443+ /* force a minimum 16MB brk heap on setuid/setgid binaries */
100444+ if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
100445+ rlim = 4096 * PAGE_SIZE;
100446+#endif
100447+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
100448 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
100449 (mm->end_data - mm->start_data) > rlim)
100450 goto out;
100451@@ -944,6 +972,12 @@ static int
100452 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
100453 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
100454 {
100455+
100456+#ifdef CONFIG_PAX_SEGMEXEC
100457+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
100458+ return 0;
100459+#endif
100460+
100461 if (is_mergeable_vma(vma, file, vm_flags) &&
100462 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
100463 if (vma->vm_pgoff == vm_pgoff)
100464@@ -963,6 +997,12 @@ static int
100465 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
100466 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
100467 {
100468+
100469+#ifdef CONFIG_PAX_SEGMEXEC
100470+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
100471+ return 0;
100472+#endif
100473+
100474 if (is_mergeable_vma(vma, file, vm_flags) &&
100475 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
100476 pgoff_t vm_pglen;
100477@@ -1005,13 +1045,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
100478 struct vm_area_struct *vma_merge(struct mm_struct *mm,
100479 struct vm_area_struct *prev, unsigned long addr,
100480 unsigned long end, unsigned long vm_flags,
100481- struct anon_vma *anon_vma, struct file *file,
100482+ struct anon_vma *anon_vma, struct file *file,
100483 pgoff_t pgoff, struct mempolicy *policy)
100484 {
100485 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
100486 struct vm_area_struct *area, *next;
100487 int err;
100488
100489+#ifdef CONFIG_PAX_SEGMEXEC
100490+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
100491+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
100492+
100493+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
100494+#endif
100495+
100496 /*
100497 * We later require that vma->vm_flags == vm_flags,
100498 * so this tests vma->vm_flags & VM_SPECIAL, too.
100499@@ -1027,6 +1074,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
100500 if (next && next->vm_end == end) /* cases 6, 7, 8 */
100501 next = next->vm_next;
100502
100503+#ifdef CONFIG_PAX_SEGMEXEC
100504+ if (prev)
100505+ prev_m = pax_find_mirror_vma(prev);
100506+ if (area)
100507+ area_m = pax_find_mirror_vma(area);
100508+ if (next)
100509+ next_m = pax_find_mirror_vma(next);
100510+#endif
100511+
100512 /*
100513 * Can it merge with the predecessor?
100514 */
100515@@ -1046,9 +1102,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
100516 /* cases 1, 6 */
100517 err = vma_adjust(prev, prev->vm_start,
100518 next->vm_end, prev->vm_pgoff, NULL);
100519- } else /* cases 2, 5, 7 */
100520+
100521+#ifdef CONFIG_PAX_SEGMEXEC
100522+ if (!err && prev_m)
100523+ err = vma_adjust(prev_m, prev_m->vm_start,
100524+ next_m->vm_end, prev_m->vm_pgoff, NULL);
100525+#endif
100526+
100527+ } else { /* cases 2, 5, 7 */
100528 err = vma_adjust(prev, prev->vm_start,
100529 end, prev->vm_pgoff, NULL);
100530+
100531+#ifdef CONFIG_PAX_SEGMEXEC
100532+ if (!err && prev_m)
100533+ err = vma_adjust(prev_m, prev_m->vm_start,
100534+ end_m, prev_m->vm_pgoff, NULL);
100535+#endif
100536+
100537+ }
100538 if (err)
100539 return NULL;
100540 khugepaged_enter_vma_merge(prev);
100541@@ -1062,12 +1133,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
100542 mpol_equal(policy, vma_policy(next)) &&
100543 can_vma_merge_before(next, vm_flags,
100544 anon_vma, file, pgoff+pglen)) {
100545- if (prev && addr < prev->vm_end) /* case 4 */
100546+ if (prev && addr < prev->vm_end) { /* case 4 */
100547 err = vma_adjust(prev, prev->vm_start,
100548 addr, prev->vm_pgoff, NULL);
100549- else /* cases 3, 8 */
100550+
100551+#ifdef CONFIG_PAX_SEGMEXEC
100552+ if (!err && prev_m)
100553+ err = vma_adjust(prev_m, prev_m->vm_start,
100554+ addr_m, prev_m->vm_pgoff, NULL);
100555+#endif
100556+
100557+ } else { /* cases 3, 8 */
100558 err = vma_adjust(area, addr, next->vm_end,
100559 next->vm_pgoff - pglen, NULL);
100560+
100561+#ifdef CONFIG_PAX_SEGMEXEC
100562+ if (!err && area_m)
100563+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
100564+ next_m->vm_pgoff - pglen, NULL);
100565+#endif
100566+
100567+ }
100568 if (err)
100569 return NULL;
100570 khugepaged_enter_vma_merge(area);
100571@@ -1176,8 +1262,10 @@ none:
100572 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
100573 struct file *file, long pages)
100574 {
100575- const unsigned long stack_flags
100576- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
100577+
100578+#ifdef CONFIG_PAX_RANDMMAP
100579+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
100580+#endif
100581
100582 mm->total_vm += pages;
100583
100584@@ -1185,7 +1273,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
100585 mm->shared_vm += pages;
100586 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
100587 mm->exec_vm += pages;
100588- } else if (flags & stack_flags)
100589+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
100590 mm->stack_vm += pages;
100591 }
100592 #endif /* CONFIG_PROC_FS */
100593@@ -1215,6 +1303,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
100594 locked += mm->locked_vm;
100595 lock_limit = rlimit(RLIMIT_MEMLOCK);
100596 lock_limit >>= PAGE_SHIFT;
100597+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
100598 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
100599 return -EAGAIN;
100600 }
100601@@ -1241,7 +1330,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
100602 * (the exception is when the underlying filesystem is noexec
100603 * mounted, in which case we dont add PROT_EXEC.)
100604 */
100605- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
100606+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
100607 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
100608 prot |= PROT_EXEC;
100609
100610@@ -1267,7 +1356,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
100611 /* Obtain the address to map to. we verify (or select) it and ensure
100612 * that it represents a valid section of the address space.
100613 */
100614- addr = get_unmapped_area(file, addr, len, pgoff, flags);
100615+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
100616 if (addr & ~PAGE_MASK)
100617 return addr;
100618
100619@@ -1278,6 +1367,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
100620 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
100621 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
100622
100623+#ifdef CONFIG_PAX_MPROTECT
100624+ if (mm->pax_flags & MF_PAX_MPROTECT) {
100625+
100626+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
100627+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
100628+ mm->binfmt->handle_mmap)
100629+ mm->binfmt->handle_mmap(file);
100630+#endif
100631+
100632+#ifndef CONFIG_PAX_MPROTECT_COMPAT
100633+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
100634+ gr_log_rwxmmap(file);
100635+
100636+#ifdef CONFIG_PAX_EMUPLT
100637+ vm_flags &= ~VM_EXEC;
100638+#else
100639+ return -EPERM;
100640+#endif
100641+
100642+ }
100643+
100644+ if (!(vm_flags & VM_EXEC))
100645+ vm_flags &= ~VM_MAYEXEC;
100646+#else
100647+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
100648+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
100649+#endif
100650+ else
100651+ vm_flags &= ~VM_MAYWRITE;
100652+ }
100653+#endif
100654+
100655+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
100656+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
100657+ vm_flags &= ~VM_PAGEEXEC;
100658+#endif
100659+
100660 if (flags & MAP_LOCKED)
100661 if (!can_do_mlock())
100662 return -EPERM;
100663@@ -1365,6 +1491,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
100664 vm_flags |= VM_NORESERVE;
100665 }
100666
100667+ if (!gr_acl_handle_mmap(file, prot))
100668+ return -EACCES;
100669+
100670 addr = mmap_region(file, addr, len, vm_flags, pgoff);
100671 if (!IS_ERR_VALUE(addr) &&
100672 ((vm_flags & VM_LOCKED) ||
100673@@ -1458,7 +1587,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
100674 vm_flags_t vm_flags = vma->vm_flags;
100675
100676 /* If it was private or non-writable, the write bit is already clear */
100677- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
100678+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
100679 return 0;
100680
100681 /* The backer wishes to know when pages are first written to? */
100682@@ -1504,7 +1633,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
100683 struct rb_node **rb_link, *rb_parent;
100684 unsigned long charged = 0;
100685
100686+#ifdef CONFIG_PAX_SEGMEXEC
100687+ struct vm_area_struct *vma_m = NULL;
100688+#endif
100689+
100690+ /*
100691+ * mm->mmap_sem is required to protect against another thread
100692+ * changing the mappings in case we sleep.
100693+ */
100694+ verify_mm_writelocked(mm);
100695+
100696 /* Check against address space limit. */
100697+
100698+#ifdef CONFIG_PAX_RANDMMAP
100699+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
100700+#endif
100701+
100702 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
100703 unsigned long nr_pages;
100704
100705@@ -1523,11 +1667,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
100706
100707 /* Clear old maps */
100708 error = -ENOMEM;
100709-munmap_back:
100710 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
100711 if (do_munmap(mm, addr, len))
100712 return -ENOMEM;
100713- goto munmap_back;
100714+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
100715 }
100716
100717 /*
100718@@ -1558,6 +1701,16 @@ munmap_back:
100719 goto unacct_error;
100720 }
100721
100722+#ifdef CONFIG_PAX_SEGMEXEC
100723+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
100724+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
100725+ if (!vma_m) {
100726+ error = -ENOMEM;
100727+ goto free_vma;
100728+ }
100729+ }
100730+#endif
100731+
100732 vma->vm_mm = mm;
100733 vma->vm_start = addr;
100734 vma->vm_end = addr + len;
100735@@ -1577,6 +1730,13 @@ munmap_back:
100736 if (error)
100737 goto unmap_and_free_vma;
100738
100739+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
100740+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
100741+ vma->vm_flags |= VM_PAGEEXEC;
100742+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
100743+ }
100744+#endif
100745+
100746 /* Can addr have changed??
100747 *
100748 * Answer: Yes, several device drivers can do it in their
100749@@ -1610,6 +1770,12 @@ munmap_back:
100750 }
100751
100752 vma_link(mm, vma, prev, rb_link, rb_parent);
100753+
100754+#ifdef CONFIG_PAX_SEGMEXEC
100755+ if (vma_m)
100756+ BUG_ON(pax_mirror_vma(vma_m, vma));
100757+#endif
100758+
100759 /* Once vma denies write, undo our temporary denial count */
100760 if (vm_flags & VM_DENYWRITE)
100761 allow_write_access(file);
100762@@ -1618,6 +1784,7 @@ out:
100763 perf_event_mmap(vma);
100764
100765 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
100766+ track_exec_limit(mm, addr, addr + len, vm_flags);
100767 if (vm_flags & VM_LOCKED) {
100768 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
100769 vma == get_gate_vma(current->mm)))
100770@@ -1650,6 +1817,12 @@ unmap_and_free_vma:
100771 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
100772 charged = 0;
100773 free_vma:
100774+
100775+#ifdef CONFIG_PAX_SEGMEXEC
100776+ if (vma_m)
100777+ kmem_cache_free(vm_area_cachep, vma_m);
100778+#endif
100779+
100780 kmem_cache_free(vm_area_cachep, vma);
100781 unacct_error:
100782 if (charged)
100783@@ -1657,7 +1830,63 @@ unacct_error:
100784 return error;
100785 }
100786
100787-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
100788+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
100789+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
100790+{
100791+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
100792+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
100793+
100794+ return 0;
100795+}
100796+#endif
100797+
100798+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
100799+{
100800+ if (!vma) {
100801+#ifdef CONFIG_STACK_GROWSUP
100802+ if (addr > sysctl_heap_stack_gap)
100803+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
100804+ else
100805+ vma = find_vma(current->mm, 0);
100806+ if (vma && (vma->vm_flags & VM_GROWSUP))
100807+ return false;
100808+#endif
100809+ return true;
100810+ }
100811+
100812+ if (addr + len > vma->vm_start)
100813+ return false;
100814+
100815+ if (vma->vm_flags & VM_GROWSDOWN)
100816+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
100817+#ifdef CONFIG_STACK_GROWSUP
100818+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
100819+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
100820+#endif
100821+ else if (offset)
100822+ return offset <= vma->vm_start - addr - len;
100823+
100824+ return true;
100825+}
100826+
100827+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
100828+{
100829+ if (vma->vm_start < len)
100830+ return -ENOMEM;
100831+
100832+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
100833+ if (offset <= vma->vm_start - len)
100834+ return vma->vm_start - len - offset;
100835+ else
100836+ return -ENOMEM;
100837+ }
100838+
100839+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
100840+ return vma->vm_start - len - sysctl_heap_stack_gap;
100841+ return -ENOMEM;
100842+}
100843+
100844+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
100845 {
100846 /*
100847 * We implement the search by looking for an rbtree node that
100848@@ -1705,11 +1934,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
100849 }
100850 }
100851
100852- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
100853+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
100854 check_current:
100855 /* Check if current node has a suitable gap */
100856 if (gap_start > high_limit)
100857 return -ENOMEM;
100858+
100859+ if (gap_end - gap_start > info->threadstack_offset)
100860+ gap_start += info->threadstack_offset;
100861+ else
100862+ gap_start = gap_end;
100863+
100864+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
100865+ if (gap_end - gap_start > sysctl_heap_stack_gap)
100866+ gap_start += sysctl_heap_stack_gap;
100867+ else
100868+ gap_start = gap_end;
100869+ }
100870+ if (vma->vm_flags & VM_GROWSDOWN) {
100871+ if (gap_end - gap_start > sysctl_heap_stack_gap)
100872+ gap_end -= sysctl_heap_stack_gap;
100873+ else
100874+ gap_end = gap_start;
100875+ }
100876 if (gap_end >= low_limit && gap_end - gap_start >= length)
100877 goto found;
100878
100879@@ -1759,7 +2006,7 @@ found:
100880 return gap_start;
100881 }
100882
100883-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
100884+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
100885 {
100886 struct mm_struct *mm = current->mm;
100887 struct vm_area_struct *vma;
100888@@ -1813,6 +2060,24 @@ check_current:
100889 gap_end = vma->vm_start;
100890 if (gap_end < low_limit)
100891 return -ENOMEM;
100892+
100893+ if (gap_end - gap_start > info->threadstack_offset)
100894+ gap_end -= info->threadstack_offset;
100895+ else
100896+ gap_end = gap_start;
100897+
100898+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
100899+ if (gap_end - gap_start > sysctl_heap_stack_gap)
100900+ gap_start += sysctl_heap_stack_gap;
100901+ else
100902+ gap_start = gap_end;
100903+ }
100904+ if (vma->vm_flags & VM_GROWSDOWN) {
100905+ if (gap_end - gap_start > sysctl_heap_stack_gap)
100906+ gap_end -= sysctl_heap_stack_gap;
100907+ else
100908+ gap_end = gap_start;
100909+ }
100910 if (gap_start <= high_limit && gap_end - gap_start >= length)
100911 goto found;
100912
100913@@ -1876,6 +2141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
100914 struct mm_struct *mm = current->mm;
100915 struct vm_area_struct *vma;
100916 struct vm_unmapped_area_info info;
100917+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
100918
100919 if (len > TASK_SIZE - mmap_min_addr)
100920 return -ENOMEM;
100921@@ -1883,11 +2149,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
100922 if (flags & MAP_FIXED)
100923 return addr;
100924
100925+#ifdef CONFIG_PAX_RANDMMAP
100926+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
100927+#endif
100928+
100929 if (addr) {
100930 addr = PAGE_ALIGN(addr);
100931 vma = find_vma(mm, addr);
100932 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
100933- (!vma || addr + len <= vma->vm_start))
100934+ check_heap_stack_gap(vma, addr, len, offset))
100935 return addr;
100936 }
100937
100938@@ -1896,6 +2166,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
100939 info.low_limit = mm->mmap_base;
100940 info.high_limit = TASK_SIZE;
100941 info.align_mask = 0;
100942+ info.threadstack_offset = offset;
100943 return vm_unmapped_area(&info);
100944 }
100945 #endif
100946@@ -1914,6 +2185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
100947 struct mm_struct *mm = current->mm;
100948 unsigned long addr = addr0;
100949 struct vm_unmapped_area_info info;
100950+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
100951
100952 /* requested length too big for entire address space */
100953 if (len > TASK_SIZE - mmap_min_addr)
100954@@ -1922,12 +2194,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
100955 if (flags & MAP_FIXED)
100956 return addr;
100957
100958+#ifdef CONFIG_PAX_RANDMMAP
100959+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
100960+#endif
100961+
100962 /* requesting a specific address */
100963 if (addr) {
100964 addr = PAGE_ALIGN(addr);
100965 vma = find_vma(mm, addr);
100966 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
100967- (!vma || addr + len <= vma->vm_start))
100968+ check_heap_stack_gap(vma, addr, len, offset))
100969 return addr;
100970 }
100971
100972@@ -1936,6 +2212,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
100973 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
100974 info.high_limit = mm->mmap_base;
100975 info.align_mask = 0;
100976+ info.threadstack_offset = offset;
100977 addr = vm_unmapped_area(&info);
100978
100979 /*
100980@@ -1948,6 +2225,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
100981 VM_BUG_ON(addr != -ENOMEM);
100982 info.flags = 0;
100983 info.low_limit = TASK_UNMAPPED_BASE;
100984+
100985+#ifdef CONFIG_PAX_RANDMMAP
100986+ if (mm->pax_flags & MF_PAX_RANDMMAP)
100987+ info.low_limit += mm->delta_mmap;
100988+#endif
100989+
100990 info.high_limit = TASK_SIZE;
100991 addr = vm_unmapped_area(&info);
100992 }
100993@@ -2048,6 +2331,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
100994 return vma;
100995 }
100996
100997+#ifdef CONFIG_PAX_SEGMEXEC
100998+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
100999+{
101000+ struct vm_area_struct *vma_m;
101001+
101002+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
101003+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
101004+ BUG_ON(vma->vm_mirror);
101005+ return NULL;
101006+ }
101007+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
101008+ vma_m = vma->vm_mirror;
101009+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
101010+ BUG_ON(vma->vm_file != vma_m->vm_file);
101011+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
101012+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
101013+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
101014+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
101015+ return vma_m;
101016+}
101017+#endif
101018+
101019 /*
101020 * Verify that the stack growth is acceptable and
101021 * update accounting. This is shared with both the
101022@@ -2064,6 +2369,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
101023 return -ENOMEM;
101024
101025 /* Stack limit test */
101026+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
101027 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
101028 return -ENOMEM;
101029
101030@@ -2074,6 +2380,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
101031 locked = mm->locked_vm + grow;
101032 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
101033 limit >>= PAGE_SHIFT;
101034+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
101035 if (locked > limit && !capable(CAP_IPC_LOCK))
101036 return -ENOMEM;
101037 }
101038@@ -2103,37 +2410,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
101039 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
101040 * vma is the last one with address > vma->vm_end. Have to extend vma.
101041 */
101042+#ifndef CONFIG_IA64
101043+static
101044+#endif
101045 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
101046 {
101047 int error;
101048+ bool locknext;
101049
101050 if (!(vma->vm_flags & VM_GROWSUP))
101051 return -EFAULT;
101052
101053+ /* Also guard against wrapping around to address 0. */
101054+ if (address < PAGE_ALIGN(address+1))
101055+ address = PAGE_ALIGN(address+1);
101056+ else
101057+ return -ENOMEM;
101058+
101059 /*
101060 * We must make sure the anon_vma is allocated
101061 * so that the anon_vma locking is not a noop.
101062 */
101063 if (unlikely(anon_vma_prepare(vma)))
101064 return -ENOMEM;
101065+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
101066+ if (locknext && anon_vma_prepare(vma->vm_next))
101067+ return -ENOMEM;
101068 vma_lock_anon_vma(vma);
101069+ if (locknext)
101070+ vma_lock_anon_vma(vma->vm_next);
101071
101072 /*
101073 * vma->vm_start/vm_end cannot change under us because the caller
101074 * is required to hold the mmap_sem in read mode. We need the
101075- * anon_vma lock to serialize against concurrent expand_stacks.
101076- * Also guard against wrapping around to address 0.
101077+ * anon_vma locks to serialize against concurrent expand_stacks
101078+ * and expand_upwards.
101079 */
101080- if (address < PAGE_ALIGN(address+4))
101081- address = PAGE_ALIGN(address+4);
101082- else {
101083- vma_unlock_anon_vma(vma);
101084- return -ENOMEM;
101085- }
101086 error = 0;
101087
101088 /* Somebody else might have raced and expanded it already */
101089- if (address > vma->vm_end) {
101090+ if (vma->vm_next && (vma->vm_next->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && vma->vm_next->vm_start - address < sysctl_heap_stack_gap)
101091+ error = -ENOMEM;
101092+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
101093 unsigned long size, grow;
101094
101095 size = address - vma->vm_start;
101096@@ -2168,6 +2486,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
101097 }
101098 }
101099 }
101100+ if (locknext)
101101+ vma_unlock_anon_vma(vma->vm_next);
101102 vma_unlock_anon_vma(vma);
101103 khugepaged_enter_vma_merge(vma);
101104 validate_mm(vma->vm_mm);
101105@@ -2182,6 +2502,8 @@ int expand_downwards(struct vm_area_struct *vma,
101106 unsigned long address)
101107 {
101108 int error;
101109+ bool lockprev = false;
101110+ struct vm_area_struct *prev;
101111
101112 /*
101113 * We must make sure the anon_vma is allocated
101114@@ -2195,6 +2517,15 @@ int expand_downwards(struct vm_area_struct *vma,
101115 if (error)
101116 return error;
101117
101118+ prev = vma->vm_prev;
101119+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
101120+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
101121+#endif
101122+ if (lockprev && anon_vma_prepare(prev))
101123+ return -ENOMEM;
101124+ if (lockprev)
101125+ vma_lock_anon_vma(prev);
101126+
101127 vma_lock_anon_vma(vma);
101128
101129 /*
101130@@ -2204,9 +2535,17 @@ int expand_downwards(struct vm_area_struct *vma,
101131 */
101132
101133 /* Somebody else might have raced and expanded it already */
101134- if (address < vma->vm_start) {
101135+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
101136+ error = -ENOMEM;
101137+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
101138 unsigned long size, grow;
101139
101140+#ifdef CONFIG_PAX_SEGMEXEC
101141+ struct vm_area_struct *vma_m;
101142+
101143+ vma_m = pax_find_mirror_vma(vma);
101144+#endif
101145+
101146 size = vma->vm_end - address;
101147 grow = (vma->vm_start - address) >> PAGE_SHIFT;
101148
101149@@ -2231,13 +2570,27 @@ int expand_downwards(struct vm_area_struct *vma,
101150 vma->vm_pgoff -= grow;
101151 anon_vma_interval_tree_post_update_vma(vma);
101152 vma_gap_update(vma);
101153+
101154+#ifdef CONFIG_PAX_SEGMEXEC
101155+ if (vma_m) {
101156+ anon_vma_interval_tree_pre_update_vma(vma_m);
101157+ vma_m->vm_start -= grow << PAGE_SHIFT;
101158+ vma_m->vm_pgoff -= grow;
101159+ anon_vma_interval_tree_post_update_vma(vma_m);
101160+ vma_gap_update(vma_m);
101161+ }
101162+#endif
101163+
101164 spin_unlock(&vma->vm_mm->page_table_lock);
101165
101166+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
101167 perf_event_mmap(vma);
101168 }
101169 }
101170 }
101171 vma_unlock_anon_vma(vma);
101172+ if (lockprev)
101173+ vma_unlock_anon_vma(prev);
101174 khugepaged_enter_vma_merge(vma);
101175 validate_mm(vma->vm_mm);
101176 return error;
101177@@ -2335,6 +2688,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
101178 do {
101179 long nrpages = vma_pages(vma);
101180
101181+#ifdef CONFIG_PAX_SEGMEXEC
101182+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
101183+ vma = remove_vma(vma);
101184+ continue;
101185+ }
101186+#endif
101187+
101188 if (vma->vm_flags & VM_ACCOUNT)
101189 nr_accounted += nrpages;
101190 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
101191@@ -2379,6 +2739,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
101192 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
101193 vma->vm_prev = NULL;
101194 do {
101195+
101196+#ifdef CONFIG_PAX_SEGMEXEC
101197+ if (vma->vm_mirror) {
101198+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
101199+ vma->vm_mirror->vm_mirror = NULL;
101200+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
101201+ vma->vm_mirror = NULL;
101202+ }
101203+#endif
101204+
101205 vma_rb_erase(vma, &mm->mm_rb);
101206 mm->map_count--;
101207 tail_vma = vma;
101208@@ -2406,14 +2776,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
101209 struct vm_area_struct *new;
101210 int err = -ENOMEM;
101211
101212+#ifdef CONFIG_PAX_SEGMEXEC
101213+ struct vm_area_struct *vma_m, *new_m = NULL;
101214+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
101215+#endif
101216+
101217 if (is_vm_hugetlb_page(vma) && (addr &
101218 ~(huge_page_mask(hstate_vma(vma)))))
101219 return -EINVAL;
101220
101221+#ifdef CONFIG_PAX_SEGMEXEC
101222+ vma_m = pax_find_mirror_vma(vma);
101223+#endif
101224+
101225 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
101226 if (!new)
101227 goto out_err;
101228
101229+#ifdef CONFIG_PAX_SEGMEXEC
101230+ if (vma_m) {
101231+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
101232+ if (!new_m) {
101233+ kmem_cache_free(vm_area_cachep, new);
101234+ goto out_err;
101235+ }
101236+ }
101237+#endif
101238+
101239 /* most fields are the same, copy all, and then fixup */
101240 *new = *vma;
101241
101242@@ -2426,6 +2815,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
101243 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
101244 }
101245
101246+#ifdef CONFIG_PAX_SEGMEXEC
101247+ if (vma_m) {
101248+ *new_m = *vma_m;
101249+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
101250+ new_m->vm_mirror = new;
101251+ new->vm_mirror = new_m;
101252+
101253+ if (new_below)
101254+ new_m->vm_end = addr_m;
101255+ else {
101256+ new_m->vm_start = addr_m;
101257+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
101258+ }
101259+ }
101260+#endif
101261+
101262 err = vma_dup_policy(vma, new);
101263 if (err)
101264 goto out_free_vma;
101265@@ -2445,6 +2850,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
101266 else
101267 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
101268
101269+#ifdef CONFIG_PAX_SEGMEXEC
101270+ if (!err && vma_m) {
101271+ struct mempolicy *pol = vma_policy(new);
101272+
101273+ if (anon_vma_clone(new_m, vma_m))
101274+ goto out_free_mpol;
101275+
101276+ mpol_get(pol);
101277+ set_vma_policy(new_m, pol);
101278+
101279+ if (new_m->vm_file)
101280+ get_file(new_m->vm_file);
101281+
101282+ if (new_m->vm_ops && new_m->vm_ops->open)
101283+ new_m->vm_ops->open(new_m);
101284+
101285+ if (new_below)
101286+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
101287+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
101288+ else
101289+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
101290+
101291+ if (err) {
101292+ if (new_m->vm_ops && new_m->vm_ops->close)
101293+ new_m->vm_ops->close(new_m);
101294+ if (new_m->vm_file)
101295+ fput(new_m->vm_file);
101296+ mpol_put(pol);
101297+ }
101298+ }
101299+#endif
101300+
101301 /* Success. */
101302 if (!err)
101303 return 0;
101304@@ -2454,10 +2891,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
101305 new->vm_ops->close(new);
101306 if (new->vm_file)
101307 fput(new->vm_file);
101308- unlink_anon_vmas(new);
101309 out_free_mpol:
101310 mpol_put(vma_policy(new));
101311 out_free_vma:
101312+
101313+#ifdef CONFIG_PAX_SEGMEXEC
101314+ if (new_m) {
101315+ unlink_anon_vmas(new_m);
101316+ kmem_cache_free(vm_area_cachep, new_m);
101317+ }
101318+#endif
101319+
101320+ unlink_anon_vmas(new);
101321 kmem_cache_free(vm_area_cachep, new);
101322 out_err:
101323 return err;
101324@@ -2470,6 +2915,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
101325 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
101326 unsigned long addr, int new_below)
101327 {
101328+
101329+#ifdef CONFIG_PAX_SEGMEXEC
101330+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
101331+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
101332+ if (mm->map_count >= sysctl_max_map_count-1)
101333+ return -ENOMEM;
101334+ } else
101335+#endif
101336+
101337 if (mm->map_count >= sysctl_max_map_count)
101338 return -ENOMEM;
101339
101340@@ -2481,11 +2935,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
101341 * work. This now handles partial unmappings.
101342 * Jeremy Fitzhardinge <jeremy@goop.org>
101343 */
101344+#ifdef CONFIG_PAX_SEGMEXEC
101345 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
101346 {
101347+ int ret = __do_munmap(mm, start, len);
101348+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
101349+ return ret;
101350+
101351+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
101352+}
101353+
101354+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
101355+#else
101356+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
101357+#endif
101358+{
101359 unsigned long end;
101360 struct vm_area_struct *vma, *prev, *last;
101361
101362+ /*
101363+ * mm->mmap_sem is required to protect against another thread
101364+ * changing the mappings in case we sleep.
101365+ */
101366+ verify_mm_writelocked(mm);
101367+
101368 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
101369 return -EINVAL;
101370
101371@@ -2560,6 +3033,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
101372 /* Fix up all other VM information */
101373 remove_vma_list(mm, vma);
101374
101375+ track_exec_limit(mm, start, end, 0UL);
101376+
101377 return 0;
101378 }
101379
101380@@ -2568,6 +3043,13 @@ int vm_munmap(unsigned long start, size_t len)
101381 int ret;
101382 struct mm_struct *mm = current->mm;
101383
101384+
101385+#ifdef CONFIG_PAX_SEGMEXEC
101386+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
101387+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
101388+ return -EINVAL;
101389+#endif
101390+
101391 down_write(&mm->mmap_sem);
101392 ret = do_munmap(mm, start, len);
101393 up_write(&mm->mmap_sem);
101394@@ -2581,16 +3063,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
101395 return vm_munmap(addr, len);
101396 }
101397
101398-static inline void verify_mm_writelocked(struct mm_struct *mm)
101399-{
101400-#ifdef CONFIG_DEBUG_VM
101401- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
101402- WARN_ON(1);
101403- up_read(&mm->mmap_sem);
101404- }
101405-#endif
101406-}
101407-
101408 /*
101409 * this is really a simplified "do_mmap". it only handles
101410 * anonymous maps. eventually we may be able to do some
101411@@ -2604,6 +3076,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101412 struct rb_node ** rb_link, * rb_parent;
101413 pgoff_t pgoff = addr >> PAGE_SHIFT;
101414 int error;
101415+ unsigned long charged;
101416
101417 len = PAGE_ALIGN(len);
101418 if (!len)
101419@@ -2611,10 +3084,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101420
101421 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
101422
101423+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
101424+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
101425+ flags &= ~VM_EXEC;
101426+
101427+#ifdef CONFIG_PAX_MPROTECT
101428+ if (mm->pax_flags & MF_PAX_MPROTECT)
101429+ flags &= ~VM_MAYEXEC;
101430+#endif
101431+
101432+ }
101433+#endif
101434+
101435 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
101436 if (error & ~PAGE_MASK)
101437 return error;
101438
101439+ charged = len >> PAGE_SHIFT;
101440+
101441 error = mlock_future_check(mm, mm->def_flags, len);
101442 if (error)
101443 return error;
101444@@ -2628,21 +3115,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101445 /*
101446 * Clear old maps. this also does some error checking for us
101447 */
101448- munmap_back:
101449 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
101450 if (do_munmap(mm, addr, len))
101451 return -ENOMEM;
101452- goto munmap_back;
101453+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
101454 }
101455
101456 /* Check against address space limits *after* clearing old maps... */
101457- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
101458+ if (!may_expand_vm(mm, charged))
101459 return -ENOMEM;
101460
101461 if (mm->map_count > sysctl_max_map_count)
101462 return -ENOMEM;
101463
101464- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
101465+ if (security_vm_enough_memory_mm(mm, charged))
101466 return -ENOMEM;
101467
101468 /* Can we just expand an old private anonymous mapping? */
101469@@ -2656,7 +3142,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101470 */
101471 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
101472 if (!vma) {
101473- vm_unacct_memory(len >> PAGE_SHIFT);
101474+ vm_unacct_memory(charged);
101475 return -ENOMEM;
101476 }
101477
101478@@ -2670,10 +3156,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101479 vma_link(mm, vma, prev, rb_link, rb_parent);
101480 out:
101481 perf_event_mmap(vma);
101482- mm->total_vm += len >> PAGE_SHIFT;
101483+ mm->total_vm += charged;
101484 if (flags & VM_LOCKED)
101485- mm->locked_vm += (len >> PAGE_SHIFT);
101486+ mm->locked_vm += charged;
101487 vma->vm_flags |= VM_SOFTDIRTY;
101488+ track_exec_limit(mm, addr, addr + len, flags);
101489 return addr;
101490 }
101491
101492@@ -2735,6 +3222,7 @@ void exit_mmap(struct mm_struct *mm)
101493 while (vma) {
101494 if (vma->vm_flags & VM_ACCOUNT)
101495 nr_accounted += vma_pages(vma);
101496+ vma->vm_mirror = NULL;
101497 vma = remove_vma(vma);
101498 }
101499 vm_unacct_memory(nr_accounted);
101500@@ -2752,6 +3240,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
101501 struct vm_area_struct *prev;
101502 struct rb_node **rb_link, *rb_parent;
101503
101504+#ifdef CONFIG_PAX_SEGMEXEC
101505+ struct vm_area_struct *vma_m = NULL;
101506+#endif
101507+
101508+ if (security_mmap_addr(vma->vm_start))
101509+ return -EPERM;
101510+
101511 /*
101512 * The vm_pgoff of a purely anonymous vma should be irrelevant
101513 * until its first write fault, when page's anon_vma and index
101514@@ -2775,7 +3270,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
101515 security_vm_enough_memory_mm(mm, vma_pages(vma)))
101516 return -ENOMEM;
101517
101518+#ifdef CONFIG_PAX_SEGMEXEC
101519+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
101520+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
101521+ if (!vma_m)
101522+ return -ENOMEM;
101523+ }
101524+#endif
101525+
101526 vma_link(mm, vma, prev, rb_link, rb_parent);
101527+
101528+#ifdef CONFIG_PAX_SEGMEXEC
101529+ if (vma_m)
101530+ BUG_ON(pax_mirror_vma(vma_m, vma));
101531+#endif
101532+
101533 return 0;
101534 }
101535
101536@@ -2794,6 +3303,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
101537 struct rb_node **rb_link, *rb_parent;
101538 bool faulted_in_anon_vma = true;
101539
101540+ BUG_ON(vma->vm_mirror);
101541+
101542 /*
101543 * If anonymous vma has not yet been faulted, update new pgoff
101544 * to match new location, to increase its chance of merging.
101545@@ -2858,6 +3369,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
101546 return NULL;
101547 }
101548
101549+#ifdef CONFIG_PAX_SEGMEXEC
101550+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
101551+{
101552+ struct vm_area_struct *prev_m;
101553+ struct rb_node **rb_link_m, *rb_parent_m;
101554+ struct mempolicy *pol_m;
101555+
101556+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
101557+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
101558+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
101559+ *vma_m = *vma;
101560+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
101561+ if (anon_vma_clone(vma_m, vma))
101562+ return -ENOMEM;
101563+ pol_m = vma_policy(vma_m);
101564+ mpol_get(pol_m);
101565+ set_vma_policy(vma_m, pol_m);
101566+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
101567+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
101568+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
101569+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
101570+ if (vma_m->vm_file)
101571+ get_file(vma_m->vm_file);
101572+ if (vma_m->vm_ops && vma_m->vm_ops->open)
101573+ vma_m->vm_ops->open(vma_m);
101574+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
101575+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
101576+ vma_m->vm_mirror = vma;
101577+ vma->vm_mirror = vma_m;
101578+ return 0;
101579+}
101580+#endif
101581+
101582 /*
101583 * Return true if the calling process may expand its vm space by the passed
101584 * number of pages
101585@@ -2869,6 +3413,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
101586
101587 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
101588
101589+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
101590 if (cur + npages > lim)
101591 return 0;
101592 return 1;
101593@@ -2951,6 +3496,22 @@ static struct vm_area_struct *__install_special_mapping(
101594 vma->vm_start = addr;
101595 vma->vm_end = addr + len;
101596
101597+#ifdef CONFIG_PAX_MPROTECT
101598+ if (mm->pax_flags & MF_PAX_MPROTECT) {
101599+#ifndef CONFIG_PAX_MPROTECT_COMPAT
101600+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
101601+ return ERR_PTR(-EPERM);
101602+ if (!(vm_flags & VM_EXEC))
101603+ vm_flags &= ~VM_MAYEXEC;
101604+#else
101605+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
101606+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
101607+#endif
101608+ else
101609+ vm_flags &= ~VM_MAYWRITE;
101610+ }
101611+#endif
101612+
101613 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
101614 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
101615
101616diff --git a/mm/mprotect.c b/mm/mprotect.c
101617index c43d557..0b7ccd2 100644
101618--- a/mm/mprotect.c
101619+++ b/mm/mprotect.c
101620@@ -24,10 +24,18 @@
101621 #include <linux/migrate.h>
101622 #include <linux/perf_event.h>
101623 #include <linux/ksm.h>
101624+#include <linux/sched/sysctl.h>
101625+
101626+#ifdef CONFIG_PAX_MPROTECT
101627+#include <linux/elf.h>
101628+#include <linux/binfmts.h>
101629+#endif
101630+
101631 #include <asm/uaccess.h>
101632 #include <asm/pgtable.h>
101633 #include <asm/cacheflush.h>
101634 #include <asm/tlbflush.h>
101635+#include <asm/mmu_context.h>
101636
101637 #ifndef pgprot_modify
101638 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
101639@@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
101640 return pages;
101641 }
101642
101643+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
101644+/* called while holding the mmap semaphor for writing except stack expansion */
101645+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
101646+{
101647+ unsigned long oldlimit, newlimit = 0UL;
101648+
101649+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
101650+ return;
101651+
101652+ spin_lock(&mm->page_table_lock);
101653+ oldlimit = mm->context.user_cs_limit;
101654+ if ((prot & VM_EXEC) && oldlimit < end)
101655+ /* USER_CS limit moved up */
101656+ newlimit = end;
101657+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
101658+ /* USER_CS limit moved down */
101659+ newlimit = start;
101660+
101661+ if (newlimit) {
101662+ mm->context.user_cs_limit = newlimit;
101663+
101664+#ifdef CONFIG_SMP
101665+ wmb();
101666+ cpus_clear(mm->context.cpu_user_cs_mask);
101667+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
101668+#endif
101669+
101670+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
101671+ }
101672+ spin_unlock(&mm->page_table_lock);
101673+ if (newlimit == end) {
101674+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
101675+
101676+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
101677+ if (is_vm_hugetlb_page(vma))
101678+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
101679+ else
101680+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
101681+ }
101682+}
101683+#endif
101684+
101685 int
101686 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
101687 unsigned long start, unsigned long end, unsigned long newflags)
101688@@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
101689 int error;
101690 int dirty_accountable = 0;
101691
101692+#ifdef CONFIG_PAX_SEGMEXEC
101693+ struct vm_area_struct *vma_m = NULL;
101694+ unsigned long start_m, end_m;
101695+
101696+ start_m = start + SEGMEXEC_TASK_SIZE;
101697+ end_m = end + SEGMEXEC_TASK_SIZE;
101698+#endif
101699+
101700 if (newflags == oldflags) {
101701 *pprev = vma;
101702 return 0;
101703 }
101704
101705+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
101706+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
101707+
101708+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
101709+ return -ENOMEM;
101710+
101711+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
101712+ return -ENOMEM;
101713+ }
101714+
101715 /*
101716 * If we make a private mapping writable we increase our commit;
101717 * but (without finer accounting) cannot reduce our commit if we
101718@@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
101719 }
101720 }
101721
101722+#ifdef CONFIG_PAX_SEGMEXEC
101723+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
101724+ if (start != vma->vm_start) {
101725+ error = split_vma(mm, vma, start, 1);
101726+ if (error)
101727+ goto fail;
101728+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
101729+ *pprev = (*pprev)->vm_next;
101730+ }
101731+
101732+ if (end != vma->vm_end) {
101733+ error = split_vma(mm, vma, end, 0);
101734+ if (error)
101735+ goto fail;
101736+ }
101737+
101738+ if (pax_find_mirror_vma(vma)) {
101739+ error = __do_munmap(mm, start_m, end_m - start_m);
101740+ if (error)
101741+ goto fail;
101742+ } else {
101743+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
101744+ if (!vma_m) {
101745+ error = -ENOMEM;
101746+ goto fail;
101747+ }
101748+ vma->vm_flags = newflags;
101749+ error = pax_mirror_vma(vma_m, vma);
101750+ if (error) {
101751+ vma->vm_flags = oldflags;
101752+ goto fail;
101753+ }
101754+ }
101755+ }
101756+#endif
101757+
101758 /*
101759 * First try to merge with previous and/or next vma.
101760 */
101761@@ -319,9 +423,21 @@ success:
101762 * vm_flags and vm_page_prot are protected by the mmap_sem
101763 * held in write mode.
101764 */
101765+
101766+#ifdef CONFIG_PAX_SEGMEXEC
101767+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
101768+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
101769+#endif
101770+
101771 vma->vm_flags = newflags;
101772+
101773+#ifdef CONFIG_PAX_MPROTECT
101774+ if (mm->binfmt && mm->binfmt->handle_mprotect)
101775+ mm->binfmt->handle_mprotect(vma, newflags);
101776+#endif
101777+
101778 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
101779- vm_get_page_prot(newflags));
101780+ vm_get_page_prot(vma->vm_flags));
101781
101782 if (vma_wants_writenotify(vma)) {
101783 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
101784@@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101785 end = start + len;
101786 if (end <= start)
101787 return -ENOMEM;
101788+
101789+#ifdef CONFIG_PAX_SEGMEXEC
101790+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
101791+ if (end > SEGMEXEC_TASK_SIZE)
101792+ return -EINVAL;
101793+ } else
101794+#endif
101795+
101796+ if (end > TASK_SIZE)
101797+ return -EINVAL;
101798+
101799 if (!arch_validate_prot(prot))
101800 return -EINVAL;
101801
101802@@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101803 /*
101804 * Does the application expect PROT_READ to imply PROT_EXEC:
101805 */
101806- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
101807+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
101808 prot |= PROT_EXEC;
101809
101810 vm_flags = calc_vm_prot_bits(prot);
101811@@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101812 if (start > vma->vm_start)
101813 prev = vma;
101814
101815+#ifdef CONFIG_PAX_MPROTECT
101816+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
101817+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
101818+#endif
101819+
101820 for (nstart = start ; ; ) {
101821 unsigned long newflags;
101822
101823@@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101824
101825 /* newflags >> 4 shift VM_MAY% in place of VM_% */
101826 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
101827+ if (prot & (PROT_WRITE | PROT_EXEC))
101828+ gr_log_rwxmprotect(vma);
101829+
101830+ error = -EACCES;
101831+ goto out;
101832+ }
101833+
101834+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
101835 error = -EACCES;
101836 goto out;
101837 }
101838@@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101839 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
101840 if (error)
101841 goto out;
101842+
101843+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
101844+
101845 nstart = tmp;
101846
101847 if (nstart < prev->vm_end)
101848diff --git a/mm/mremap.c b/mm/mremap.c
101849index 05f1180..c3cde48 100644
101850--- a/mm/mremap.c
101851+++ b/mm/mremap.c
101852@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
101853 continue;
101854 pte = ptep_get_and_clear(mm, old_addr, old_pte);
101855 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
101856+
101857+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
101858+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
101859+ pte = pte_exprotect(pte);
101860+#endif
101861+
101862 pte = move_soft_dirty_pte(pte);
101863 set_pte_at(mm, new_addr, new_pte, pte);
101864 }
101865@@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
101866 if (is_vm_hugetlb_page(vma))
101867 goto Einval;
101868
101869+#ifdef CONFIG_PAX_SEGMEXEC
101870+ if (pax_find_mirror_vma(vma))
101871+ goto Einval;
101872+#endif
101873+
101874 /* We can't remap across vm area boundaries */
101875 if (old_len > vma->vm_end - addr)
101876 goto Efault;
101877@@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
101878 unsigned long ret = -EINVAL;
101879 unsigned long charged = 0;
101880 unsigned long map_flags;
101881+ unsigned long pax_task_size = TASK_SIZE;
101882
101883 if (new_addr & ~PAGE_MASK)
101884 goto out;
101885
101886- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
101887+#ifdef CONFIG_PAX_SEGMEXEC
101888+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
101889+ pax_task_size = SEGMEXEC_TASK_SIZE;
101890+#endif
101891+
101892+ pax_task_size -= PAGE_SIZE;
101893+
101894+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
101895 goto out;
101896
101897 /* Check if the location we're moving into overlaps the
101898 * old location at all, and fail if it does.
101899 */
101900- if ((new_addr <= addr) && (new_addr+new_len) > addr)
101901- goto out;
101902-
101903- if ((addr <= new_addr) && (addr+old_len) > new_addr)
101904+ if (addr + old_len > new_addr && new_addr + new_len > addr)
101905 goto out;
101906
101907 ret = do_munmap(mm, new_addr, new_len);
101908@@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
101909 unsigned long ret = -EINVAL;
101910 unsigned long charged = 0;
101911 bool locked = false;
101912+ unsigned long pax_task_size = TASK_SIZE;
101913
101914 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
101915 return ret;
101916@@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
101917 if (!new_len)
101918 return ret;
101919
101920+#ifdef CONFIG_PAX_SEGMEXEC
101921+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
101922+ pax_task_size = SEGMEXEC_TASK_SIZE;
101923+#endif
101924+
101925+ pax_task_size -= PAGE_SIZE;
101926+
101927+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
101928+ old_len > pax_task_size || addr > pax_task_size-old_len)
101929+ return ret;
101930+
101931 down_write(&current->mm->mmap_sem);
101932
101933 if (flags & MREMAP_FIXED) {
101934@@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
101935 new_addr = addr;
101936 }
101937 ret = addr;
101938+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
101939 goto out;
101940 }
101941 }
101942@@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
101943 goto out;
101944 }
101945
101946+ map_flags = vma->vm_flags;
101947 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
101948+ if (!(ret & ~PAGE_MASK)) {
101949+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
101950+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
101951+ }
101952 }
101953 out:
101954 if (ret & ~PAGE_MASK)
101955diff --git a/mm/nommu.c b/mm/nommu.c
101956index 4a852f6..4371a6b 100644
101957--- a/mm/nommu.c
101958+++ b/mm/nommu.c
101959@@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
101960 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
101961 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
101962 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
101963-int heap_stack_gap = 0;
101964
101965 atomic_long_t mmap_pages_allocated;
101966
101967@@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
101968 EXPORT_SYMBOL(find_vma);
101969
101970 /*
101971- * find a VMA
101972- * - we don't extend stack VMAs under NOMMU conditions
101973- */
101974-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
101975-{
101976- return find_vma(mm, addr);
101977-}
101978-
101979-/*
101980 * expand a stack to a given address
101981 * - not supported under NOMMU conditions
101982 */
101983@@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
101984
101985 /* most fields are the same, copy all, and then fixup */
101986 *new = *vma;
101987+ INIT_LIST_HEAD(&new->anon_vma_chain);
101988 *region = *vma->vm_region;
101989 new->vm_region = region;
101990
101991@@ -2007,8 +1998,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
101992 }
101993 EXPORT_SYMBOL(generic_file_remap_pages);
101994
101995-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
101996- unsigned long addr, void *buf, int len, int write)
101997+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
101998+ unsigned long addr, void *buf, size_t len, int write)
101999 {
102000 struct vm_area_struct *vma;
102001
102002@@ -2049,8 +2040,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
102003 *
102004 * The caller must hold a reference on @mm.
102005 */
102006-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
102007- void *buf, int len, int write)
102008+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
102009+ void *buf, size_t len, int write)
102010 {
102011 return __access_remote_vm(NULL, mm, addr, buf, len, write);
102012 }
102013@@ -2059,7 +2050,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
102014 * Access another process' address space.
102015 * - source/target buffer must be kernel space
102016 */
102017-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
102018+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
102019 {
102020 struct mm_struct *mm;
102021
102022diff --git a/mm/page-writeback.c b/mm/page-writeback.c
102023index e0c9430..3c6bf79 100644
102024--- a/mm/page-writeback.c
102025+++ b/mm/page-writeback.c
102026@@ -667,7 +667,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
102027 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
102028 * - the bdi dirty thresh drops quickly due to change of JBOD workload
102029 */
102030-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
102031+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
102032 unsigned long thresh,
102033 unsigned long bg_thresh,
102034 unsigned long dirty,
102035diff --git a/mm/page_alloc.c b/mm/page_alloc.c
102036index ef44ad7..1056bc7 100644
102037--- a/mm/page_alloc.c
102038+++ b/mm/page_alloc.c
102039@@ -61,6 +61,7 @@
102040 #include <linux/page-debug-flags.h>
102041 #include <linux/hugetlb.h>
102042 #include <linux/sched/rt.h>
102043+#include <linux/random.h>
102044
102045 #include <asm/sections.h>
102046 #include <asm/tlbflush.h>
102047@@ -357,7 +358,7 @@ out:
102048 * This usage means that zero-order pages may not be compound.
102049 */
102050
102051-static void free_compound_page(struct page *page)
102052+void free_compound_page(struct page *page)
102053 {
102054 __free_pages_ok(page, compound_order(page));
102055 }
102056@@ -745,6 +746,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
102057 int i;
102058 int bad = 0;
102059
102060+#ifdef CONFIG_PAX_MEMORY_SANITIZE
102061+ unsigned long index = 1UL << order;
102062+#endif
102063+
102064 trace_mm_page_free(page, order);
102065 kmemcheck_free_shadow(page, order);
102066
102067@@ -761,6 +766,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
102068 debug_check_no_obj_freed(page_address(page),
102069 PAGE_SIZE << order);
102070 }
102071+
102072+#ifdef CONFIG_PAX_MEMORY_SANITIZE
102073+ for (; index; --index)
102074+ sanitize_highpage(page + index - 1);
102075+#endif
102076+
102077 arch_free_page(page, order);
102078 kernel_map_pages(page, 1 << order, 0);
102079
102080@@ -784,6 +795,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
102081 local_irq_restore(flags);
102082 }
102083
102084+#ifdef CONFIG_PAX_LATENT_ENTROPY
102085+bool __meminitdata extra_latent_entropy;
102086+
102087+static int __init setup_pax_extra_latent_entropy(char *str)
102088+{
102089+ extra_latent_entropy = true;
102090+ return 0;
102091+}
102092+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
102093+
102094+volatile u64 latent_entropy __latent_entropy;
102095+EXPORT_SYMBOL(latent_entropy);
102096+#endif
102097+
102098 void __init __free_pages_bootmem(struct page *page, unsigned int order)
102099 {
102100 unsigned int nr_pages = 1 << order;
102101@@ -799,6 +824,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
102102 __ClearPageReserved(p);
102103 set_page_count(p, 0);
102104
102105+#ifdef CONFIG_PAX_LATENT_ENTROPY
102106+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
102107+ u64 hash = 0;
102108+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
102109+ const u64 *data = lowmem_page_address(page);
102110+
102111+ for (index = 0; index < end; index++)
102112+ hash ^= hash + data[index];
102113+ latent_entropy ^= hash;
102114+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
102115+ }
102116+#endif
102117+
102118 page_zone(page)->managed_pages += nr_pages;
102119 set_page_refcounted(page);
102120 __free_pages(page, order);
102121@@ -927,8 +965,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
102122 arch_alloc_page(page, order);
102123 kernel_map_pages(page, 1 << order, 1);
102124
102125+#ifndef CONFIG_PAX_MEMORY_SANITIZE
102126 if (gfp_flags & __GFP_ZERO)
102127 prep_zero_page(page, order, gfp_flags);
102128+#endif
102129
102130 if (order && (gfp_flags & __GFP_COMP))
102131 prep_compound_page(page, order);
102132@@ -2427,7 +2467,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
102133 continue;
102134 mod_zone_page_state(zone, NR_ALLOC_BATCH,
102135 high_wmark_pages(zone) - low_wmark_pages(zone) -
102136- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
102137+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
102138 }
102139 }
102140
102141diff --git a/mm/percpu.c b/mm/percpu.c
102142index 2ddf9a9..f8fc075 100644
102143--- a/mm/percpu.c
102144+++ b/mm/percpu.c
102145@@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
102146 static unsigned int pcpu_high_unit_cpu __read_mostly;
102147
102148 /* the address of the first chunk which starts with the kernel static area */
102149-void *pcpu_base_addr __read_mostly;
102150+void *pcpu_base_addr __read_only;
102151 EXPORT_SYMBOL_GPL(pcpu_base_addr);
102152
102153 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
102154diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c
102155index a8b9199..dfb79e0 100644
102156--- a/mm/pgtable-generic.c
102157+++ b/mm/pgtable-generic.c
102158@@ -195,7 +195,7 @@ void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
102159 pmd_t entry = *pmdp;
102160 if (pmd_numa(entry))
102161 entry = pmd_mknonnuma(entry);
102162- set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(*pmdp));
102163+ set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(entry));
102164 flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
102165 }
102166 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
102167diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
102168index 5077afc..846c9ef 100644
102169--- a/mm/process_vm_access.c
102170+++ b/mm/process_vm_access.c
102171@@ -13,6 +13,7 @@
102172 #include <linux/uio.h>
102173 #include <linux/sched.h>
102174 #include <linux/highmem.h>
102175+#include <linux/security.h>
102176 #include <linux/ptrace.h>
102177 #include <linux/slab.h>
102178 #include <linux/syscalls.h>
102179@@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
102180 ssize_t iov_len;
102181 size_t total_len = iov_iter_count(iter);
102182
102183+ return -ENOSYS; // PaX: until properly audited
102184+
102185 /*
102186 * Work out how many pages of struct pages we're going to need
102187 * when eventually calling get_user_pages
102188 */
102189 for (i = 0; i < riovcnt; i++) {
102190 iov_len = rvec[i].iov_len;
102191- if (iov_len > 0) {
102192- nr_pages_iov = ((unsigned long)rvec[i].iov_base
102193- + iov_len)
102194- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
102195- / PAGE_SIZE + 1;
102196- nr_pages = max(nr_pages, nr_pages_iov);
102197- }
102198+ if (iov_len <= 0)
102199+ continue;
102200+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
102201+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
102202+ nr_pages = max(nr_pages, nr_pages_iov);
102203 }
102204
102205 if (nr_pages == 0)
102206@@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
102207 goto free_proc_pages;
102208 }
102209
102210+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
102211+ rc = -EPERM;
102212+ goto put_task_struct;
102213+ }
102214+
102215 mm = mm_access(task, PTRACE_MODE_ATTACH);
102216 if (!mm || IS_ERR(mm)) {
102217 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
102218diff --git a/mm/rmap.c b/mm/rmap.c
102219index 22a4a76..9551288 100644
102220--- a/mm/rmap.c
102221+++ b/mm/rmap.c
102222@@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
102223 struct anon_vma *anon_vma = vma->anon_vma;
102224 struct anon_vma_chain *avc;
102225
102226+#ifdef CONFIG_PAX_SEGMEXEC
102227+ struct anon_vma_chain *avc_m = NULL;
102228+#endif
102229+
102230 might_sleep();
102231 if (unlikely(!anon_vma)) {
102232 struct mm_struct *mm = vma->vm_mm;
102233@@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
102234 if (!avc)
102235 goto out_enomem;
102236
102237+#ifdef CONFIG_PAX_SEGMEXEC
102238+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
102239+ if (!avc_m)
102240+ goto out_enomem_free_avc;
102241+#endif
102242+
102243 anon_vma = find_mergeable_anon_vma(vma);
102244 allocated = NULL;
102245 if (!anon_vma) {
102246@@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
102247 /* page_table_lock to protect against threads */
102248 spin_lock(&mm->page_table_lock);
102249 if (likely(!vma->anon_vma)) {
102250+
102251+#ifdef CONFIG_PAX_SEGMEXEC
102252+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
102253+
102254+ if (vma_m) {
102255+ BUG_ON(vma_m->anon_vma);
102256+ vma_m->anon_vma = anon_vma;
102257+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
102258+ avc_m = NULL;
102259+ }
102260+#endif
102261+
102262 vma->anon_vma = anon_vma;
102263 anon_vma_chain_link(vma, avc, anon_vma);
102264 allocated = NULL;
102265@@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
102266
102267 if (unlikely(allocated))
102268 put_anon_vma(allocated);
102269+
102270+#ifdef CONFIG_PAX_SEGMEXEC
102271+ if (unlikely(avc_m))
102272+ anon_vma_chain_free(avc_m);
102273+#endif
102274+
102275 if (unlikely(avc))
102276 anon_vma_chain_free(avc);
102277 }
102278 return 0;
102279
102280 out_enomem_free_avc:
102281+
102282+#ifdef CONFIG_PAX_SEGMEXEC
102283+ if (avc_m)
102284+ anon_vma_chain_free(avc_m);
102285+#endif
102286+
102287 anon_vma_chain_free(avc);
102288 out_enomem:
102289 return -ENOMEM;
102290@@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
102291 * Attach the anon_vmas from src to dst.
102292 * Returns 0 on success, -ENOMEM on failure.
102293 */
102294-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
102295+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
102296 {
102297 struct anon_vma_chain *avc, *pavc;
102298 struct anon_vma *root = NULL;
102299@@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
102300 * the corresponding VMA in the parent process is attached to.
102301 * Returns 0 on success, non-zero on failure.
102302 */
102303-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
102304+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
102305 {
102306 struct anon_vma_chain *avc;
102307 struct anon_vma *anon_vma;
102308@@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
102309 void __init anon_vma_init(void)
102310 {
102311 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
102312- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
102313- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
102314+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
102315+ anon_vma_ctor);
102316+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
102317+ SLAB_PANIC|SLAB_NO_SANITIZE);
102318 }
102319
102320 /*
102321diff --git a/mm/shmem.c b/mm/shmem.c
102322index af68b15..1227320 100644
102323--- a/mm/shmem.c
102324+++ b/mm/shmem.c
102325@@ -33,7 +33,7 @@
102326 #include <linux/swap.h>
102327 #include <linux/aio.h>
102328
102329-static struct vfsmount *shm_mnt;
102330+struct vfsmount *shm_mnt;
102331
102332 #ifdef CONFIG_SHMEM
102333 /*
102334@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
102335 #define BOGO_DIRENT_SIZE 20
102336
102337 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
102338-#define SHORT_SYMLINK_LEN 128
102339+#define SHORT_SYMLINK_LEN 64
102340
102341 /*
102342 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
102343@@ -2219,6 +2219,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
102344 static int shmem_xattr_validate(const char *name)
102345 {
102346 struct { const char *prefix; size_t len; } arr[] = {
102347+
102348+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
102349+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
102350+#endif
102351+
102352 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
102353 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
102354 };
102355@@ -2274,6 +2279,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
102356 if (err)
102357 return err;
102358
102359+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
102360+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
102361+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
102362+ return -EOPNOTSUPP;
102363+ if (size > 8)
102364+ return -EINVAL;
102365+ }
102366+#endif
102367+
102368 return simple_xattr_set(&info->xattrs, name, value, size, flags);
102369 }
102370
102371@@ -2586,8 +2600,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
102372 int err = -ENOMEM;
102373
102374 /* Round up to L1_CACHE_BYTES to resist false sharing */
102375- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
102376- L1_CACHE_BYTES), GFP_KERNEL);
102377+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
102378 if (!sbinfo)
102379 return -ENOMEM;
102380
102381diff --git a/mm/slab.c b/mm/slab.c
102382index 3070b92..bcfff83 100644
102383--- a/mm/slab.c
102384+++ b/mm/slab.c
102385@@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
102386 if ((x)->max_freeable < i) \
102387 (x)->max_freeable = i; \
102388 } while (0)
102389-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
102390-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
102391-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
102392-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
102393+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
102394+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
102395+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
102396+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
102397+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
102398+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
102399 #else
102400 #define STATS_INC_ACTIVE(x) do { } while (0)
102401 #define STATS_DEC_ACTIVE(x) do { } while (0)
102402@@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
102403 #define STATS_INC_ALLOCMISS(x) do { } while (0)
102404 #define STATS_INC_FREEHIT(x) do { } while (0)
102405 #define STATS_INC_FREEMISS(x) do { } while (0)
102406+#define STATS_INC_SANITIZED(x) do { } while (0)
102407+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
102408 #endif
102409
102410 #if DEBUG
102411@@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
102412 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
102413 */
102414 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
102415- const struct page *page, void *obj)
102416+ const struct page *page, const void *obj)
102417 {
102418 u32 offset = (obj - page->s_mem);
102419 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
102420@@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
102421 */
102422
102423 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
102424- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
102425+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
102426
102427 if (INDEX_AC != INDEX_NODE)
102428 kmalloc_caches[INDEX_NODE] =
102429 create_kmalloc_cache("kmalloc-node",
102430- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
102431+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
102432
102433 slab_early_init = 0;
102434
102435@@ -3512,6 +3516,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
102436 struct array_cache *ac = cpu_cache_get(cachep);
102437
102438 check_irq_off();
102439+
102440+#ifdef CONFIG_PAX_MEMORY_SANITIZE
102441+ if (pax_sanitize_slab) {
102442+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
102443+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
102444+
102445+ if (cachep->ctor)
102446+ cachep->ctor(objp);
102447+
102448+ STATS_INC_SANITIZED(cachep);
102449+ } else
102450+ STATS_INC_NOT_SANITIZED(cachep);
102451+ }
102452+#endif
102453+
102454 kmemleak_free_recursive(objp, cachep->flags);
102455 objp = cache_free_debugcheck(cachep, objp, caller);
102456
102457@@ -3735,6 +3754,7 @@ void kfree(const void *objp)
102458
102459 if (unlikely(ZERO_OR_NULL_PTR(objp)))
102460 return;
102461+ VM_BUG_ON(!virt_addr_valid(objp));
102462 local_irq_save(flags);
102463 kfree_debugcheck(objp);
102464 c = virt_to_cache(objp);
102465@@ -4176,14 +4196,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
102466 }
102467 /* cpu stats */
102468 {
102469- unsigned long allochit = atomic_read(&cachep->allochit);
102470- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
102471- unsigned long freehit = atomic_read(&cachep->freehit);
102472- unsigned long freemiss = atomic_read(&cachep->freemiss);
102473+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
102474+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
102475+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
102476+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
102477
102478 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
102479 allochit, allocmiss, freehit, freemiss);
102480 }
102481+#ifdef CONFIG_PAX_MEMORY_SANITIZE
102482+ {
102483+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
102484+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
102485+
102486+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
102487+ }
102488+#endif
102489 #endif
102490 }
102491
102492@@ -4404,13 +4432,69 @@ static const struct file_operations proc_slabstats_operations = {
102493 static int __init slab_proc_init(void)
102494 {
102495 #ifdef CONFIG_DEBUG_SLAB_LEAK
102496- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
102497+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
102498 #endif
102499 return 0;
102500 }
102501 module_init(slab_proc_init);
102502 #endif
102503
102504+bool is_usercopy_object(const void *ptr)
102505+{
102506+ struct page *page;
102507+ struct kmem_cache *cachep;
102508+
102509+ if (ZERO_OR_NULL_PTR(ptr))
102510+ return false;
102511+
102512+ if (!slab_is_available())
102513+ return false;
102514+
102515+ if (!virt_addr_valid(ptr))
102516+ return false;
102517+
102518+ page = virt_to_head_page(ptr);
102519+
102520+ if (!PageSlab(page))
102521+ return false;
102522+
102523+ cachep = page->slab_cache;
102524+ return cachep->flags & SLAB_USERCOPY;
102525+}
102526+
102527+#ifdef CONFIG_PAX_USERCOPY
102528+const char *check_heap_object(const void *ptr, unsigned long n)
102529+{
102530+ struct page *page;
102531+ struct kmem_cache *cachep;
102532+ unsigned int objnr;
102533+ unsigned long offset;
102534+
102535+ if (ZERO_OR_NULL_PTR(ptr))
102536+ return "<null>";
102537+
102538+ if (!virt_addr_valid(ptr))
102539+ return NULL;
102540+
102541+ page = virt_to_head_page(ptr);
102542+
102543+ if (!PageSlab(page))
102544+ return NULL;
102545+
102546+ cachep = page->slab_cache;
102547+ if (!(cachep->flags & SLAB_USERCOPY))
102548+ return cachep->name;
102549+
102550+ objnr = obj_to_index(cachep, page, ptr);
102551+ BUG_ON(objnr >= cachep->num);
102552+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
102553+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
102554+ return NULL;
102555+
102556+ return cachep->name;
102557+}
102558+#endif
102559+
102560 /**
102561 * ksize - get the actual amount of memory allocated for a given object
102562 * @objp: Pointer to the object
102563diff --git a/mm/slab.h b/mm/slab.h
102564index 961a3fb..6b12514 100644
102565--- a/mm/slab.h
102566+++ b/mm/slab.h
102567@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
102568 /* The slab cache that manages slab cache information */
102569 extern struct kmem_cache *kmem_cache;
102570
102571+#ifdef CONFIG_PAX_MEMORY_SANITIZE
102572+#ifdef CONFIG_X86_64
102573+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
102574+#else
102575+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
102576+#endif
102577+extern bool pax_sanitize_slab;
102578+#endif
102579+
102580 unsigned long calculate_alignment(unsigned long flags,
102581 unsigned long align, unsigned long size);
102582
102583@@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
102584
102585 /* Legal flag mask for kmem_cache_create(), for various configurations */
102586 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
102587- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
102588+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
102589+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
102590
102591 #if defined(CONFIG_DEBUG_SLAB)
102592 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
102593@@ -251,6 +261,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
102594 return s;
102595
102596 page = virt_to_head_page(x);
102597+
102598+ BUG_ON(!PageSlab(page));
102599+
102600 cachep = page->slab_cache;
102601 if (slab_equal_or_root(cachep, s))
102602 return cachep;
102603diff --git a/mm/slab_common.c b/mm/slab_common.c
102604index d31c4ba..1121296 100644
102605--- a/mm/slab_common.c
102606+++ b/mm/slab_common.c
102607@@ -23,11 +23,22 @@
102608
102609 #include "slab.h"
102610
102611-enum slab_state slab_state;
102612+enum slab_state slab_state __read_only;
102613 LIST_HEAD(slab_caches);
102614 DEFINE_MUTEX(slab_mutex);
102615 struct kmem_cache *kmem_cache;
102616
102617+#ifdef CONFIG_PAX_MEMORY_SANITIZE
102618+bool pax_sanitize_slab __read_only = true;
102619+static int __init pax_sanitize_slab_setup(char *str)
102620+{
102621+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
102622+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
102623+ return 1;
102624+}
102625+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
102626+#endif
102627+
102628 #ifdef CONFIG_DEBUG_VM
102629 static int kmem_cache_sanity_check(const char *name, size_t size)
102630 {
102631@@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
102632 if (err)
102633 goto out_free_cache;
102634
102635- s->refcount = 1;
102636+ atomic_set(&s->refcount, 1);
102637 list_add(&s->list, &slab_caches);
102638 out:
102639 if (err)
102640@@ -339,8 +350,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
102641
102642 mutex_lock(&slab_mutex);
102643
102644- s->refcount--;
102645- if (s->refcount)
102646+ if (!atomic_dec_and_test(&s->refcount))
102647 goto out_unlock;
102648
102649 if (memcg_cleanup_cache_params(s) != 0)
102650@@ -360,7 +370,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
102651 rcu_barrier();
102652
102653 memcg_free_cache_params(s);
102654-#ifdef SLAB_SUPPORTS_SYSFS
102655+#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
102656 sysfs_slab_remove(s);
102657 #else
102658 slab_kmem_cache_release(s);
102659@@ -416,7 +426,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
102660 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
102661 name, size, err);
102662
102663- s->refcount = -1; /* Exempt from merging for now */
102664+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
102665 }
102666
102667 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
102668@@ -429,7 +439,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
102669
102670 create_boot_cache(s, name, size, flags);
102671 list_add(&s->list, &slab_caches);
102672- s->refcount = 1;
102673+ atomic_set(&s->refcount, 1);
102674 return s;
102675 }
102676
102677@@ -441,6 +451,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
102678 EXPORT_SYMBOL(kmalloc_dma_caches);
102679 #endif
102680
102681+#ifdef CONFIG_PAX_USERCOPY_SLABS
102682+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
102683+EXPORT_SYMBOL(kmalloc_usercopy_caches);
102684+#endif
102685+
102686 /*
102687 * Conversion table for small slabs sizes / 8 to the index in the
102688 * kmalloc array. This is necessary for slabs < 192 since we have non power
102689@@ -505,6 +520,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
102690 return kmalloc_dma_caches[index];
102691
102692 #endif
102693+
102694+#ifdef CONFIG_PAX_USERCOPY_SLABS
102695+ if (unlikely((flags & GFP_USERCOPY)))
102696+ return kmalloc_usercopy_caches[index];
102697+
102698+#endif
102699+
102700 return kmalloc_caches[index];
102701 }
102702
102703@@ -561,7 +583,7 @@ void __init create_kmalloc_caches(unsigned long flags)
102704 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
102705 if (!kmalloc_caches[i]) {
102706 kmalloc_caches[i] = create_kmalloc_cache(NULL,
102707- 1 << i, flags);
102708+ 1 << i, SLAB_USERCOPY | flags);
102709 }
102710
102711 /*
102712@@ -570,10 +592,10 @@ void __init create_kmalloc_caches(unsigned long flags)
102713 * earlier power of two caches
102714 */
102715 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
102716- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
102717+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
102718
102719 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
102720- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
102721+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
102722 }
102723
102724 /* Kmalloc array is now usable */
102725@@ -606,6 +628,23 @@ void __init create_kmalloc_caches(unsigned long flags)
102726 }
102727 }
102728 #endif
102729+
102730+#ifdef CONFIG_PAX_USERCOPY_SLABS
102731+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
102732+ struct kmem_cache *s = kmalloc_caches[i];
102733+
102734+ if (s) {
102735+ int size = kmalloc_size(i);
102736+ char *n = kasprintf(GFP_NOWAIT,
102737+ "usercopy-kmalloc-%d", size);
102738+
102739+ BUG_ON(!n);
102740+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
102741+ size, SLAB_USERCOPY | flags);
102742+ }
102743+ }
102744+#endif
102745+
102746 }
102747 #endif /* !CONFIG_SLOB */
102748
102749@@ -664,6 +703,9 @@ void print_slabinfo_header(struct seq_file *m)
102750 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
102751 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
102752 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
102753+#ifdef CONFIG_PAX_MEMORY_SANITIZE
102754+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
102755+#endif
102756 #endif
102757 seq_putc(m, '\n');
102758 }
102759diff --git a/mm/slob.c b/mm/slob.c
102760index 21980e0..ed9a648 100644
102761--- a/mm/slob.c
102762+++ b/mm/slob.c
102763@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
102764 /*
102765 * Return the size of a slob block.
102766 */
102767-static slobidx_t slob_units(slob_t *s)
102768+static slobidx_t slob_units(const slob_t *s)
102769 {
102770 if (s->units > 0)
102771 return s->units;
102772@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
102773 /*
102774 * Return the next free slob block pointer after this one.
102775 */
102776-static slob_t *slob_next(slob_t *s)
102777+static slob_t *slob_next(const slob_t *s)
102778 {
102779 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
102780 slobidx_t next;
102781@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
102782 /*
102783 * Returns true if s is the last free block in its page.
102784 */
102785-static int slob_last(slob_t *s)
102786+static int slob_last(const slob_t *s)
102787 {
102788 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
102789 }
102790
102791-static void *slob_new_pages(gfp_t gfp, int order, int node)
102792+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
102793 {
102794- void *page;
102795+ struct page *page;
102796
102797 #ifdef CONFIG_NUMA
102798 if (node != NUMA_NO_NODE)
102799@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
102800 if (!page)
102801 return NULL;
102802
102803- return page_address(page);
102804+ __SetPageSlab(page);
102805+ return page;
102806 }
102807
102808-static void slob_free_pages(void *b, int order)
102809+static void slob_free_pages(struct page *sp, int order)
102810 {
102811 if (current->reclaim_state)
102812 current->reclaim_state->reclaimed_slab += 1 << order;
102813- free_pages((unsigned long)b, order);
102814+ __ClearPageSlab(sp);
102815+ page_mapcount_reset(sp);
102816+ sp->private = 0;
102817+ __free_pages(sp, order);
102818 }
102819
102820 /*
102821@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
102822
102823 /* Not enough space: must allocate a new page */
102824 if (!b) {
102825- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
102826- if (!b)
102827+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
102828+ if (!sp)
102829 return NULL;
102830- sp = virt_to_page(b);
102831- __SetPageSlab(sp);
102832+ b = page_address(sp);
102833
102834 spin_lock_irqsave(&slob_lock, flags);
102835 sp->units = SLOB_UNITS(PAGE_SIZE);
102836 sp->freelist = b;
102837+ sp->private = 0;
102838 INIT_LIST_HEAD(&sp->lru);
102839 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
102840 set_slob_page_free(sp, slob_list);
102841@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
102842 if (slob_page_free(sp))
102843 clear_slob_page_free(sp);
102844 spin_unlock_irqrestore(&slob_lock, flags);
102845- __ClearPageSlab(sp);
102846- page_mapcount_reset(sp);
102847- slob_free_pages(b, 0);
102848+ slob_free_pages(sp, 0);
102849 return;
102850 }
102851
102852+#ifdef CONFIG_PAX_MEMORY_SANITIZE
102853+ if (pax_sanitize_slab)
102854+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
102855+#endif
102856+
102857 if (!slob_page_free(sp)) {
102858 /* This slob page is about to become partially free. Easy! */
102859 sp->units = units;
102860@@ -424,11 +431,10 @@ out:
102861 */
102862
102863 static __always_inline void *
102864-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
102865+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
102866 {
102867- unsigned int *m;
102868- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
102869- void *ret;
102870+ slob_t *m;
102871+ void *ret = NULL;
102872
102873 gfp &= gfp_allowed_mask;
102874
102875@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
102876
102877 if (!m)
102878 return NULL;
102879- *m = size;
102880+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
102881+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
102882+ m[0].units = size;
102883+ m[1].units = align;
102884 ret = (void *)m + align;
102885
102886 trace_kmalloc_node(caller, ret,
102887 size, size + align, gfp, node);
102888 } else {
102889 unsigned int order = get_order(size);
102890+ struct page *page;
102891
102892 if (likely(order))
102893 gfp |= __GFP_COMP;
102894- ret = slob_new_pages(gfp, order, node);
102895+ page = slob_new_pages(gfp, order, node);
102896+ if (page) {
102897+ ret = page_address(page);
102898+ page->private = size;
102899+ }
102900
102901 trace_kmalloc_node(caller, ret,
102902 size, PAGE_SIZE << order, gfp, node);
102903 }
102904
102905- kmemleak_alloc(ret, size, 1, gfp);
102906+ return ret;
102907+}
102908+
102909+static __always_inline void *
102910+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
102911+{
102912+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
102913+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
102914+
102915+ if (!ZERO_OR_NULL_PTR(ret))
102916+ kmemleak_alloc(ret, size, 1, gfp);
102917 return ret;
102918 }
102919
102920@@ -493,34 +517,112 @@ void kfree(const void *block)
102921 return;
102922 kmemleak_free(block);
102923
102924+ VM_BUG_ON(!virt_addr_valid(block));
102925 sp = virt_to_page(block);
102926- if (PageSlab(sp)) {
102927+ VM_BUG_ON(!PageSlab(sp));
102928+ if (!sp->private) {
102929 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
102930- unsigned int *m = (unsigned int *)(block - align);
102931- slob_free(m, *m + align);
102932- } else
102933+ slob_t *m = (slob_t *)(block - align);
102934+ slob_free(m, m[0].units + align);
102935+ } else {
102936+ __ClearPageSlab(sp);
102937+ page_mapcount_reset(sp);
102938+ sp->private = 0;
102939 __free_pages(sp, compound_order(sp));
102940+ }
102941 }
102942 EXPORT_SYMBOL(kfree);
102943
102944+bool is_usercopy_object(const void *ptr)
102945+{
102946+ if (!slab_is_available())
102947+ return false;
102948+
102949+ // PAX: TODO
102950+
102951+ return false;
102952+}
102953+
102954+#ifdef CONFIG_PAX_USERCOPY
102955+const char *check_heap_object(const void *ptr, unsigned long n)
102956+{
102957+ struct page *page;
102958+ const slob_t *free;
102959+ const void *base;
102960+ unsigned long flags;
102961+
102962+ if (ZERO_OR_NULL_PTR(ptr))
102963+ return "<null>";
102964+
102965+ if (!virt_addr_valid(ptr))
102966+ return NULL;
102967+
102968+ page = virt_to_head_page(ptr);
102969+ if (!PageSlab(page))
102970+ return NULL;
102971+
102972+ if (page->private) {
102973+ base = page;
102974+ if (base <= ptr && n <= page->private - (ptr - base))
102975+ return NULL;
102976+ return "<slob>";
102977+ }
102978+
102979+ /* some tricky double walking to find the chunk */
102980+ spin_lock_irqsave(&slob_lock, flags);
102981+ base = (void *)((unsigned long)ptr & PAGE_MASK);
102982+ free = page->freelist;
102983+
102984+ while (!slob_last(free) && (void *)free <= ptr) {
102985+ base = free + slob_units(free);
102986+ free = slob_next(free);
102987+ }
102988+
102989+ while (base < (void *)free) {
102990+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
102991+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
102992+ int offset;
102993+
102994+ if (ptr < base + align)
102995+ break;
102996+
102997+ offset = ptr - base - align;
102998+ if (offset >= m) {
102999+ base += size;
103000+ continue;
103001+ }
103002+
103003+ if (n > m - offset)
103004+ break;
103005+
103006+ spin_unlock_irqrestore(&slob_lock, flags);
103007+ return NULL;
103008+ }
103009+
103010+ spin_unlock_irqrestore(&slob_lock, flags);
103011+ return "<slob>";
103012+}
103013+#endif
103014+
103015 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
103016 size_t ksize(const void *block)
103017 {
103018 struct page *sp;
103019 int align;
103020- unsigned int *m;
103021+ slob_t *m;
103022
103023 BUG_ON(!block);
103024 if (unlikely(block == ZERO_SIZE_PTR))
103025 return 0;
103026
103027 sp = virt_to_page(block);
103028- if (unlikely(!PageSlab(sp)))
103029- return PAGE_SIZE << compound_order(sp);
103030+ VM_BUG_ON(!PageSlab(sp));
103031+ if (sp->private)
103032+ return sp->private;
103033
103034 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
103035- m = (unsigned int *)(block - align);
103036- return SLOB_UNITS(*m) * SLOB_UNIT;
103037+ m = (slob_t *)(block - align);
103038+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
103039 }
103040 EXPORT_SYMBOL(ksize);
103041
103042@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
103043
103044 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
103045 {
103046- void *b;
103047+ void *b = NULL;
103048
103049 flags &= gfp_allowed_mask;
103050
103051 lockdep_trace_alloc(flags);
103052
103053+#ifdef CONFIG_PAX_USERCOPY_SLABS
103054+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
103055+#else
103056 if (c->size < PAGE_SIZE) {
103057 b = slob_alloc(c->size, flags, c->align, node);
103058 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
103059 SLOB_UNITS(c->size) * SLOB_UNIT,
103060 flags, node);
103061 } else {
103062- b = slob_new_pages(flags, get_order(c->size), node);
103063+ struct page *sp;
103064+
103065+ sp = slob_new_pages(flags, get_order(c->size), node);
103066+ if (sp) {
103067+ b = page_address(sp);
103068+ sp->private = c->size;
103069+ }
103070 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
103071 PAGE_SIZE << get_order(c->size),
103072 flags, node);
103073 }
103074+#endif
103075
103076 if (b && c->ctor)
103077 c->ctor(b);
103078@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
103079
103080 static void __kmem_cache_free(void *b, int size)
103081 {
103082- if (size < PAGE_SIZE)
103083+ struct page *sp;
103084+
103085+ sp = virt_to_page(b);
103086+ BUG_ON(!PageSlab(sp));
103087+ if (!sp->private)
103088 slob_free(b, size);
103089 else
103090- slob_free_pages(b, get_order(size));
103091+ slob_free_pages(sp, get_order(size));
103092 }
103093
103094 static void kmem_rcu_free(struct rcu_head *head)
103095@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
103096
103097 void kmem_cache_free(struct kmem_cache *c, void *b)
103098 {
103099+ int size = c->size;
103100+
103101+#ifdef CONFIG_PAX_USERCOPY_SLABS
103102+ if (size + c->align < PAGE_SIZE) {
103103+ size += c->align;
103104+ b -= c->align;
103105+ }
103106+#endif
103107+
103108 kmemleak_free_recursive(b, c->flags);
103109 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
103110 struct slob_rcu *slob_rcu;
103111- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
103112- slob_rcu->size = c->size;
103113+ slob_rcu = b + (size - sizeof(struct slob_rcu));
103114+ slob_rcu->size = size;
103115 call_rcu(&slob_rcu->head, kmem_rcu_free);
103116 } else {
103117- __kmem_cache_free(b, c->size);
103118+ __kmem_cache_free(b, size);
103119 }
103120
103121+#ifdef CONFIG_PAX_USERCOPY_SLABS
103122+ trace_kfree(_RET_IP_, b);
103123+#else
103124 trace_kmem_cache_free(_RET_IP_, b);
103125+#endif
103126+
103127 }
103128 EXPORT_SYMBOL(kmem_cache_free);
103129
103130diff --git a/mm/slub.c b/mm/slub.c
103131index 7300480..cb92846 100644
103132--- a/mm/slub.c
103133+++ b/mm/slub.c
103134@@ -207,7 +207,7 @@ struct track {
103135
103136 enum track_item { TRACK_ALLOC, TRACK_FREE };
103137
103138-#ifdef CONFIG_SYSFS
103139+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103140 static int sysfs_slab_add(struct kmem_cache *);
103141 static int sysfs_slab_alias(struct kmem_cache *, const char *);
103142 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
103143@@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
103144 if (!t->addr)
103145 return;
103146
103147- pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
103148+ pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
103149 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
103150 #ifdef CONFIG_STACKTRACE
103151 {
103152@@ -2673,6 +2673,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
103153
103154 slab_free_hook(s, x);
103155
103156+#ifdef CONFIG_PAX_MEMORY_SANITIZE
103157+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
103158+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
103159+ if (s->ctor)
103160+ s->ctor(x);
103161+ }
103162+#endif
103163+
103164 redo:
103165 /*
103166 * Determine the currently cpus per cpu slab.
103167@@ -2740,7 +2748,7 @@ static int slub_min_objects;
103168 * Merge control. If this is set then no merging of slab caches will occur.
103169 * (Could be removed. This was introduced to pacify the merge skeptics.)
103170 */
103171-static int slub_nomerge;
103172+static int slub_nomerge = 1;
103173
103174 /*
103175 * Calculate the order of allocation given an slab object size.
103176@@ -3019,6 +3027,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
103177 s->inuse = size;
103178
103179 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
103180+#ifdef CONFIG_PAX_MEMORY_SANITIZE
103181+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
103182+#endif
103183 s->ctor)) {
103184 /*
103185 * Relocate free pointer after the object if it is not
103186@@ -3347,6 +3358,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
103187 EXPORT_SYMBOL(__kmalloc_node);
103188 #endif
103189
103190+bool is_usercopy_object(const void *ptr)
103191+{
103192+ struct page *page;
103193+ struct kmem_cache *s;
103194+
103195+ if (ZERO_OR_NULL_PTR(ptr))
103196+ return false;
103197+
103198+ if (!slab_is_available())
103199+ return false;
103200+
103201+ if (!virt_addr_valid(ptr))
103202+ return false;
103203+
103204+ page = virt_to_head_page(ptr);
103205+
103206+ if (!PageSlab(page))
103207+ return false;
103208+
103209+ s = page->slab_cache;
103210+ return s->flags & SLAB_USERCOPY;
103211+}
103212+
103213+#ifdef CONFIG_PAX_USERCOPY
103214+const char *check_heap_object(const void *ptr, unsigned long n)
103215+{
103216+ struct page *page;
103217+ struct kmem_cache *s;
103218+ unsigned long offset;
103219+
103220+ if (ZERO_OR_NULL_PTR(ptr))
103221+ return "<null>";
103222+
103223+ if (!virt_addr_valid(ptr))
103224+ return NULL;
103225+
103226+ page = virt_to_head_page(ptr);
103227+
103228+ if (!PageSlab(page))
103229+ return NULL;
103230+
103231+ s = page->slab_cache;
103232+ if (!(s->flags & SLAB_USERCOPY))
103233+ return s->name;
103234+
103235+ offset = (ptr - page_address(page)) % s->size;
103236+ if (offset <= s->object_size && n <= s->object_size - offset)
103237+ return NULL;
103238+
103239+ return s->name;
103240+}
103241+#endif
103242+
103243 size_t ksize(const void *object)
103244 {
103245 struct page *page;
103246@@ -3375,6 +3439,7 @@ void kfree(const void *x)
103247 if (unlikely(ZERO_OR_NULL_PTR(x)))
103248 return;
103249
103250+ VM_BUG_ON(!virt_addr_valid(x));
103251 page = virt_to_head_page(x);
103252 if (unlikely(!PageSlab(page))) {
103253 BUG_ON(!PageCompound(page));
103254@@ -3680,7 +3745,7 @@ static int slab_unmergeable(struct kmem_cache *s)
103255 /*
103256 * We may have set a slab to be unmergeable during bootstrap.
103257 */
103258- if (s->refcount < 0)
103259+ if (atomic_read(&s->refcount) < 0)
103260 return 1;
103261
103262 return 0;
103263@@ -3737,7 +3802,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
103264 int i;
103265 struct kmem_cache *c;
103266
103267- s->refcount++;
103268+ atomic_inc(&s->refcount);
103269
103270 /*
103271 * Adjust the object sizes so that we clear
103272@@ -3756,7 +3821,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
103273 }
103274
103275 if (sysfs_slab_alias(s, name)) {
103276- s->refcount--;
103277+ atomic_dec(&s->refcount);
103278 s = NULL;
103279 }
103280 }
103281@@ -3873,7 +3938,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
103282 }
103283 #endif
103284
103285-#ifdef CONFIG_SYSFS
103286+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103287 static int count_inuse(struct page *page)
103288 {
103289 return page->inuse;
103290@@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
103291 len += sprintf(buf + len, "%7ld ", l->count);
103292
103293 if (l->addr)
103294+#ifdef CONFIG_GRKERNSEC_HIDESYM
103295+ len += sprintf(buf + len, "%pS", NULL);
103296+#else
103297 len += sprintf(buf + len, "%pS", (void *)l->addr);
103298+#endif
103299 else
103300 len += sprintf(buf + len, "<not-available>");
103301
103302@@ -4258,12 +4327,12 @@ static void resiliency_test(void)
103303 validate_slab_cache(kmalloc_caches[9]);
103304 }
103305 #else
103306-#ifdef CONFIG_SYSFS
103307+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103308 static void resiliency_test(void) {};
103309 #endif
103310 #endif
103311
103312-#ifdef CONFIG_SYSFS
103313+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103314 enum slab_stat_type {
103315 SL_ALL, /* All slabs */
103316 SL_PARTIAL, /* Only partially allocated slabs */
103317@@ -4503,13 +4572,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
103318 {
103319 if (!s->ctor)
103320 return 0;
103321+#ifdef CONFIG_GRKERNSEC_HIDESYM
103322+ return sprintf(buf, "%pS\n", NULL);
103323+#else
103324 return sprintf(buf, "%pS\n", s->ctor);
103325+#endif
103326 }
103327 SLAB_ATTR_RO(ctor);
103328
103329 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
103330 {
103331- return sprintf(buf, "%d\n", s->refcount - 1);
103332+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
103333 }
103334 SLAB_ATTR_RO(aliases);
103335
103336@@ -4597,6 +4670,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
103337 SLAB_ATTR_RO(cache_dma);
103338 #endif
103339
103340+#ifdef CONFIG_PAX_USERCOPY_SLABS
103341+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
103342+{
103343+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
103344+}
103345+SLAB_ATTR_RO(usercopy);
103346+#endif
103347+
103348 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
103349 {
103350 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
103351@@ -4931,6 +5012,9 @@ static struct attribute *slab_attrs[] = {
103352 #ifdef CONFIG_ZONE_DMA
103353 &cache_dma_attr.attr,
103354 #endif
103355+#ifdef CONFIG_PAX_USERCOPY_SLABS
103356+ &usercopy_attr.attr,
103357+#endif
103358 #ifdef CONFIG_NUMA
103359 &remote_node_defrag_ratio_attr.attr,
103360 #endif
103361@@ -5181,6 +5265,7 @@ static char *create_unique_id(struct kmem_cache *s)
103362 return name;
103363 }
103364
103365+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103366 static int sysfs_slab_add(struct kmem_cache *s)
103367 {
103368 int err;
103369@@ -5254,6 +5339,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
103370 kobject_del(&s->kobj);
103371 kobject_put(&s->kobj);
103372 }
103373+#endif
103374
103375 /*
103376 * Need to buffer aliases during bootup until sysfs becomes
103377@@ -5267,6 +5353,7 @@ struct saved_alias {
103378
103379 static struct saved_alias *alias_list;
103380
103381+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103382 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
103383 {
103384 struct saved_alias *al;
103385@@ -5289,6 +5376,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
103386 alias_list = al;
103387 return 0;
103388 }
103389+#endif
103390
103391 static int __init slab_sysfs_init(void)
103392 {
103393diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
103394index 4cba9c2..b4f9fcc 100644
103395--- a/mm/sparse-vmemmap.c
103396+++ b/mm/sparse-vmemmap.c
103397@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
103398 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
103399 if (!p)
103400 return NULL;
103401- pud_populate(&init_mm, pud, p);
103402+ pud_populate_kernel(&init_mm, pud, p);
103403 }
103404 return pud;
103405 }
103406@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
103407 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
103408 if (!p)
103409 return NULL;
103410- pgd_populate(&init_mm, pgd, p);
103411+ pgd_populate_kernel(&init_mm, pgd, p);
103412 }
103413 return pgd;
103414 }
103415diff --git a/mm/sparse.c b/mm/sparse.c
103416index d1b48b6..6e8590e 100644
103417--- a/mm/sparse.c
103418+++ b/mm/sparse.c
103419@@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
103420
103421 for (i = 0; i < PAGES_PER_SECTION; i++) {
103422 if (PageHWPoison(&memmap[i])) {
103423- atomic_long_sub(1, &num_poisoned_pages);
103424+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
103425 ClearPageHWPoison(&memmap[i]);
103426 }
103427 }
103428diff --git a/mm/swap.c b/mm/swap.c
103429index 9e8e347..3c22e0f 100644
103430--- a/mm/swap.c
103431+++ b/mm/swap.c
103432@@ -31,6 +31,7 @@
103433 #include <linux/memcontrol.h>
103434 #include <linux/gfp.h>
103435 #include <linux/uio.h>
103436+#include <linux/hugetlb.h>
103437
103438 #include "internal.h"
103439
103440@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
103441
103442 __page_cache_release(page);
103443 dtor = get_compound_page_dtor(page);
103444+ if (!PageHuge(page))
103445+ BUG_ON(dtor != free_compound_page);
103446 (*dtor)(page);
103447 }
103448
103449diff --git a/mm/swapfile.c b/mm/swapfile.c
103450index 4c524f7..f7601f17 100644
103451--- a/mm/swapfile.c
103452+++ b/mm/swapfile.c
103453@@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
103454
103455 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
103456 /* Activity counter to indicate that a swapon or swapoff has occurred */
103457-static atomic_t proc_poll_event = ATOMIC_INIT(0);
103458+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
103459
103460 static inline unsigned char swap_count(unsigned char ent)
103461 {
103462@@ -1945,7 +1945,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
103463 spin_unlock(&swap_lock);
103464
103465 err = 0;
103466- atomic_inc(&proc_poll_event);
103467+ atomic_inc_unchecked(&proc_poll_event);
103468 wake_up_interruptible(&proc_poll_wait);
103469
103470 out_dput:
103471@@ -1962,8 +1962,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
103472
103473 poll_wait(file, &proc_poll_wait, wait);
103474
103475- if (seq->poll_event != atomic_read(&proc_poll_event)) {
103476- seq->poll_event = atomic_read(&proc_poll_event);
103477+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
103478+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
103479 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
103480 }
103481
103482@@ -2061,7 +2061,7 @@ static int swaps_open(struct inode *inode, struct file *file)
103483 return ret;
103484
103485 seq = file->private_data;
103486- seq->poll_event = atomic_read(&proc_poll_event);
103487+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
103488 return 0;
103489 }
103490
103491@@ -2521,7 +2521,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
103492 (frontswap_map) ? "FS" : "");
103493
103494 mutex_unlock(&swapon_mutex);
103495- atomic_inc(&proc_poll_event);
103496+ atomic_inc_unchecked(&proc_poll_event);
103497 wake_up_interruptible(&proc_poll_wait);
103498
103499 if (S_ISREG(inode->i_mode))
103500diff --git a/mm/util.c b/mm/util.c
103501index d5ea733..e8953f9 100644
103502--- a/mm/util.c
103503+++ b/mm/util.c
103504@@ -299,6 +299,12 @@ done:
103505 void arch_pick_mmap_layout(struct mm_struct *mm)
103506 {
103507 mm->mmap_base = TASK_UNMAPPED_BASE;
103508+
103509+#ifdef CONFIG_PAX_RANDMMAP
103510+ if (mm->pax_flags & MF_PAX_RANDMMAP)
103511+ mm->mmap_base += mm->delta_mmap;
103512+#endif
103513+
103514 mm->get_unmapped_area = arch_get_unmapped_area;
103515 }
103516 #endif
103517@@ -475,6 +481,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
103518 if (!mm->arg_end)
103519 goto out_mm; /* Shh! No looking before we're done */
103520
103521+ if (gr_acl_handle_procpidmem(task))
103522+ goto out_mm;
103523+
103524 len = mm->arg_end - mm->arg_start;
103525
103526 if (len > buflen)
103527diff --git a/mm/vmalloc.c b/mm/vmalloc.c
103528index f64632b..e8c52e7 100644
103529--- a/mm/vmalloc.c
103530+++ b/mm/vmalloc.c
103531@@ -40,6 +40,21 @@ struct vfree_deferred {
103532 };
103533 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
103534
103535+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103536+struct stack_deferred_llist {
103537+ struct llist_head list;
103538+ void *stack;
103539+ void *lowmem_stack;
103540+};
103541+
103542+struct stack_deferred {
103543+ struct stack_deferred_llist list;
103544+ struct work_struct wq;
103545+};
103546+
103547+static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
103548+#endif
103549+
103550 static void __vunmap(const void *, int);
103551
103552 static void free_work(struct work_struct *w)
103553@@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
103554 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
103555 struct llist_node *llnode = llist_del_all(&p->list);
103556 while (llnode) {
103557- void *p = llnode;
103558+ void *x = llnode;
103559 llnode = llist_next(llnode);
103560- __vunmap(p, 1);
103561+ __vunmap(x, 1);
103562 }
103563 }
103564
103565+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103566+static void unmap_work(struct work_struct *w)
103567+{
103568+ struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
103569+ struct llist_node *llnode = llist_del_all(&p->list.list);
103570+ while (llnode) {
103571+ struct stack_deferred_llist *x =
103572+ llist_entry((struct llist_head *)llnode,
103573+ struct stack_deferred_llist, list);
103574+ void *stack = ACCESS_ONCE(x->stack);
103575+ void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
103576+ llnode = llist_next(llnode);
103577+ __vunmap(stack, 0);
103578+ free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
103579+ }
103580+}
103581+#endif
103582+
103583 /*** Page table manipulation functions ***/
103584
103585 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
103586@@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
103587
103588 pte = pte_offset_kernel(pmd, addr);
103589 do {
103590- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
103591- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
103592+
103593+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
103594+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
103595+ BUG_ON(!pte_exec(*pte));
103596+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
103597+ continue;
103598+ }
103599+#endif
103600+
103601+ {
103602+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
103603+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
103604+ }
103605 } while (pte++, addr += PAGE_SIZE, addr != end);
103606 }
103607
103608@@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
103609 pte = pte_alloc_kernel(pmd, addr);
103610 if (!pte)
103611 return -ENOMEM;
103612+
103613+ pax_open_kernel();
103614 do {
103615 struct page *page = pages[*nr];
103616
103617- if (WARN_ON(!pte_none(*pte)))
103618+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
103619+ if (pgprot_val(prot) & _PAGE_NX)
103620+#endif
103621+
103622+ if (!pte_none(*pte)) {
103623+ pax_close_kernel();
103624+ WARN_ON(1);
103625 return -EBUSY;
103626- if (WARN_ON(!page))
103627+ }
103628+ if (!page) {
103629+ pax_close_kernel();
103630+ WARN_ON(1);
103631 return -ENOMEM;
103632+ }
103633 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
103634 (*nr)++;
103635 } while (pte++, addr += PAGE_SIZE, addr != end);
103636+ pax_close_kernel();
103637 return 0;
103638 }
103639
103640@@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
103641 pmd_t *pmd;
103642 unsigned long next;
103643
103644- pmd = pmd_alloc(&init_mm, pud, addr);
103645+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
103646 if (!pmd)
103647 return -ENOMEM;
103648 do {
103649@@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
103650 pud_t *pud;
103651 unsigned long next;
103652
103653- pud = pud_alloc(&init_mm, pgd, addr);
103654+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
103655 if (!pud)
103656 return -ENOMEM;
103657 do {
103658@@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
103659 if (addr >= MODULES_VADDR && addr < MODULES_END)
103660 return 1;
103661 #endif
103662+
103663+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
103664+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
103665+ return 1;
103666+#endif
103667+
103668 return is_vmalloc_addr(x);
103669 }
103670
103671@@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
103672
103673 if (!pgd_none(*pgd)) {
103674 pud_t *pud = pud_offset(pgd, addr);
103675+#ifdef CONFIG_X86
103676+ if (!pud_large(*pud))
103677+#endif
103678 if (!pud_none(*pud)) {
103679 pmd_t *pmd = pmd_offset(pud, addr);
103680+#ifdef CONFIG_X86
103681+ if (!pmd_large(*pmd))
103682+#endif
103683 if (!pmd_none(*pmd)) {
103684 pte_t *ptep, pte;
103685
103686@@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
103687 for_each_possible_cpu(i) {
103688 struct vmap_block_queue *vbq;
103689 struct vfree_deferred *p;
103690+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103691+ struct stack_deferred *p2;
103692+#endif
103693
103694 vbq = &per_cpu(vmap_block_queue, i);
103695 spin_lock_init(&vbq->lock);
103696 INIT_LIST_HEAD(&vbq->free);
103697+
103698 p = &per_cpu(vfree_deferred, i);
103699 init_llist_head(&p->list);
103700 INIT_WORK(&p->wq, free_work);
103701+
103702+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103703+ p2 = &per_cpu(stack_deferred, i);
103704+ init_llist_head(&p2->list.list);
103705+ INIT_WORK(&p2->wq, unmap_work);
103706+#endif
103707 }
103708
103709 /* Import existing vmlist entries. */
103710@@ -1318,6 +1397,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
103711 struct vm_struct *area;
103712
103713 BUG_ON(in_interrupt());
103714+
103715+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
103716+ if (flags & VM_KERNEXEC) {
103717+ if (start != VMALLOC_START || end != VMALLOC_END)
103718+ return NULL;
103719+ start = (unsigned long)MODULES_EXEC_VADDR;
103720+ end = (unsigned long)MODULES_EXEC_END;
103721+ }
103722+#endif
103723+
103724 if (flags & VM_IOREMAP)
103725 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
103726
103727@@ -1523,6 +1612,23 @@ void vunmap(const void *addr)
103728 }
103729 EXPORT_SYMBOL(vunmap);
103730
103731+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103732+void unmap_process_stacks(struct task_struct *task)
103733+{
103734+ if (unlikely(in_interrupt())) {
103735+ struct stack_deferred *p = &__get_cpu_var(stack_deferred);
103736+ struct stack_deferred_llist *list = task->stack;
103737+ list->stack = task->stack;
103738+ list->lowmem_stack = task->lowmem_stack;
103739+ if (llist_add((struct llist_node *)&list->list, &p->list.list))
103740+ schedule_work(&p->wq);
103741+ } else {
103742+ __vunmap(task->stack, 0);
103743+ free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
103744+ }
103745+}
103746+#endif
103747+
103748 /**
103749 * vmap - map an array of pages into virtually contiguous space
103750 * @pages: array of page pointers
103751@@ -1543,6 +1649,11 @@ void *vmap(struct page **pages, unsigned int count,
103752 if (count > totalram_pages)
103753 return NULL;
103754
103755+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
103756+ if (!(pgprot_val(prot) & _PAGE_NX))
103757+ flags |= VM_KERNEXEC;
103758+#endif
103759+
103760 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
103761 __builtin_return_address(0));
103762 if (!area)
103763@@ -1643,6 +1754,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
103764 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
103765 goto fail;
103766
103767+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
103768+ if (!(pgprot_val(prot) & _PAGE_NX))
103769+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
103770+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
103771+ else
103772+#endif
103773+
103774 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
103775 start, end, node, gfp_mask, caller);
103776 if (!area)
103777@@ -1819,10 +1937,9 @@ EXPORT_SYMBOL(vzalloc_node);
103778 * For tight control over page level allocator and protection flags
103779 * use __vmalloc() instead.
103780 */
103781-
103782 void *vmalloc_exec(unsigned long size)
103783 {
103784- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
103785+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
103786 NUMA_NO_NODE, __builtin_return_address(0));
103787 }
103788
103789@@ -2129,6 +2246,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
103790 {
103791 struct vm_struct *area;
103792
103793+ BUG_ON(vma->vm_mirror);
103794+
103795 size = PAGE_ALIGN(size);
103796
103797 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
103798@@ -2611,7 +2730,11 @@ static int s_show(struct seq_file *m, void *p)
103799 v->addr, v->addr + v->size, v->size);
103800
103801 if (v->caller)
103802+#ifdef CONFIG_GRKERNSEC_HIDESYM
103803+ seq_printf(m, " %pK", v->caller);
103804+#else
103805 seq_printf(m, " %pS", v->caller);
103806+#endif
103807
103808 if (v->nr_pages)
103809 seq_printf(m, " pages=%d", v->nr_pages);
103810diff --git a/mm/vmstat.c b/mm/vmstat.c
103811index b37bd49..4d7b3da 100644
103812--- a/mm/vmstat.c
103813+++ b/mm/vmstat.c
103814@@ -20,6 +20,7 @@
103815 #include <linux/writeback.h>
103816 #include <linux/compaction.h>
103817 #include <linux/mm_inline.h>
103818+#include <linux/grsecurity.h>
103819
103820 #include "internal.h"
103821
103822@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
103823 *
103824 * vm_stat contains the global counters
103825 */
103826-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
103827+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
103828 EXPORT_SYMBOL(vm_stat);
103829
103830 #ifdef CONFIG_SMP
103831@@ -425,7 +426,7 @@ static inline void fold_diff(int *diff)
103832
103833 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
103834 if (diff[i])
103835- atomic_long_add(diff[i], &vm_stat[i]);
103836+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
103837 }
103838
103839 /*
103840@@ -457,7 +458,7 @@ static void refresh_cpu_vm_stats(void)
103841 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
103842 if (v) {
103843
103844- atomic_long_add(v, &zone->vm_stat[i]);
103845+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
103846 global_diff[i] += v;
103847 #ifdef CONFIG_NUMA
103848 /* 3 seconds idle till flush */
103849@@ -519,7 +520,7 @@ void cpu_vm_stats_fold(int cpu)
103850
103851 v = p->vm_stat_diff[i];
103852 p->vm_stat_diff[i] = 0;
103853- atomic_long_add(v, &zone->vm_stat[i]);
103854+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
103855 global_diff[i] += v;
103856 }
103857 }
103858@@ -539,8 +540,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
103859 if (pset->vm_stat_diff[i]) {
103860 int v = pset->vm_stat_diff[i];
103861 pset->vm_stat_diff[i] = 0;
103862- atomic_long_add(v, &zone->vm_stat[i]);
103863- atomic_long_add(v, &vm_stat[i]);
103864+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
103865+ atomic_long_add_unchecked(v, &vm_stat[i]);
103866 }
103867 }
103868 #endif
103869@@ -1162,10 +1163,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
103870 stat_items_size += sizeof(struct vm_event_state);
103871 #endif
103872
103873- v = kmalloc(stat_items_size, GFP_KERNEL);
103874+ v = kzalloc(stat_items_size, GFP_KERNEL);
103875 m->private = v;
103876 if (!v)
103877 return ERR_PTR(-ENOMEM);
103878+
103879+#ifdef CONFIG_GRKERNSEC_PROC_ADD
103880+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
103881+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
103882+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
103883+ && !in_group_p(grsec_proc_gid)
103884+#endif
103885+ )
103886+ return (unsigned long *)m->private + *pos;
103887+#endif
103888+#endif
103889+
103890 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
103891 v[i] = global_page_state(i);
103892 v += NR_VM_ZONE_STAT_ITEMS;
103893@@ -1314,10 +1327,16 @@ static int __init setup_vmstat(void)
103894 cpu_notifier_register_done();
103895 #endif
103896 #ifdef CONFIG_PROC_FS
103897- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
103898- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
103899- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
103900- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
103901+ {
103902+ mode_t gr_mode = S_IRUGO;
103903+#ifdef CONFIG_GRKERNSEC_PROC_ADD
103904+ gr_mode = S_IRUSR;
103905+#endif
103906+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
103907+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
103908+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
103909+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
103910+ }
103911 #endif
103912 return 0;
103913 }
103914diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
103915index 44ebd5c..1f732bae 100644
103916--- a/net/8021q/vlan.c
103917+++ b/net/8021q/vlan.c
103918@@ -475,7 +475,7 @@ out:
103919 return NOTIFY_DONE;
103920 }
103921
103922-static struct notifier_block vlan_notifier_block __read_mostly = {
103923+static struct notifier_block vlan_notifier_block = {
103924 .notifier_call = vlan_device_event,
103925 };
103926
103927@@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
103928 err = -EPERM;
103929 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
103930 break;
103931- if ((args.u.name_type >= 0) &&
103932- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
103933+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
103934 struct vlan_net *vn;
103935
103936 vn = net_generic(net, vlan_net_id);
103937diff --git a/net/9p/client.c b/net/9p/client.c
103938index 0004cba..feba240 100644
103939--- a/net/9p/client.c
103940+++ b/net/9p/client.c
103941@@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
103942 len - inline_len);
103943 } else {
103944 err = copy_from_user(ename + inline_len,
103945- uidata, len - inline_len);
103946+ (char __force_user *)uidata, len - inline_len);
103947 if (err) {
103948 err = -EFAULT;
103949 goto out_err;
103950@@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
103951 kernel_buf = 1;
103952 indata = data;
103953 } else
103954- indata = (__force char *)udata;
103955+ indata = (__force_kernel char *)udata;
103956 /*
103957 * response header len is 11
103958 * PDU Header(7) + IO Size (4)
103959@@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
103960 kernel_buf = 1;
103961 odata = data;
103962 } else
103963- odata = (char *)udata;
103964+ odata = (char __force_kernel *)udata;
103965 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
103966 P9_ZC_HDR_SZ, kernel_buf, "dqd",
103967 fid->fid, offset, rsize);
103968diff --git a/net/9p/mod.c b/net/9p/mod.c
103969index 6ab36ae..6f1841b 100644
103970--- a/net/9p/mod.c
103971+++ b/net/9p/mod.c
103972@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
103973 void v9fs_register_trans(struct p9_trans_module *m)
103974 {
103975 spin_lock(&v9fs_trans_lock);
103976- list_add_tail(&m->list, &v9fs_trans_list);
103977+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
103978 spin_unlock(&v9fs_trans_lock);
103979 }
103980 EXPORT_SYMBOL(v9fs_register_trans);
103981@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
103982 void v9fs_unregister_trans(struct p9_trans_module *m)
103983 {
103984 spin_lock(&v9fs_trans_lock);
103985- list_del_init(&m->list);
103986+ pax_list_del_init((struct list_head *)&m->list);
103987 spin_unlock(&v9fs_trans_lock);
103988 }
103989 EXPORT_SYMBOL(v9fs_unregister_trans);
103990diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
103991index 80d08f6..de63fd1 100644
103992--- a/net/9p/trans_fd.c
103993+++ b/net/9p/trans_fd.c
103994@@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
103995 oldfs = get_fs();
103996 set_fs(get_ds());
103997 /* The cast to a user pointer is valid due to the set_fs() */
103998- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
103999+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
104000 set_fs(oldfs);
104001
104002 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
104003diff --git a/net/Kconfig b/net/Kconfig
104004index d92afe4..ab63892 100644
104005--- a/net/Kconfig
104006+++ b/net/Kconfig
104007@@ -89,12 +89,8 @@ config NETWORK_SECMARK
104008 to nfmark, but designated for security purposes.
104009 If you are unsure how to answer this question, answer N.
104010
104011-config NET_PTP_CLASSIFY
104012- def_bool n
104013-
104014 config NETWORK_PHY_TIMESTAMPING
104015 bool "Timestamping in PHY devices"
104016- select NET_PTP_CLASSIFY
104017 help
104018 This allows timestamping of network packets by PHYs with
104019 hardware timestamping capabilities. This option adds some
104020@@ -269,7 +265,7 @@ config BQL
104021 config BPF_JIT
104022 bool "enable BPF Just In Time compiler"
104023 depends on HAVE_BPF_JIT
104024- depends on MODULES
104025+ depends on MODULES && X86
104026 ---help---
104027 Berkeley Packet Filter filtering capabilities are normally handled
104028 by an interpreter. This option allows kernel to generate a native
104029diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
104030index af46bc4..f9adfcd 100644
104031--- a/net/appletalk/atalk_proc.c
104032+++ b/net/appletalk/atalk_proc.c
104033@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
104034 struct proc_dir_entry *p;
104035 int rc = -ENOMEM;
104036
104037- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
104038+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
104039 if (!atalk_proc_dir)
104040 goto out;
104041
104042diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
104043index 876fbe8..8bbea9f 100644
104044--- a/net/atm/atm_misc.c
104045+++ b/net/atm/atm_misc.c
104046@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
104047 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
104048 return 1;
104049 atm_return(vcc, truesize);
104050- atomic_inc(&vcc->stats->rx_drop);
104051+ atomic_inc_unchecked(&vcc->stats->rx_drop);
104052 return 0;
104053 }
104054 EXPORT_SYMBOL(atm_charge);
104055@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
104056 }
104057 }
104058 atm_return(vcc, guess);
104059- atomic_inc(&vcc->stats->rx_drop);
104060+ atomic_inc_unchecked(&vcc->stats->rx_drop);
104061 return NULL;
104062 }
104063 EXPORT_SYMBOL(atm_alloc_charge);
104064@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
104065
104066 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
104067 {
104068-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
104069+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
104070 __SONET_ITEMS
104071 #undef __HANDLE_ITEM
104072 }
104073@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
104074
104075 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
104076 {
104077-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
104078+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
104079 __SONET_ITEMS
104080 #undef __HANDLE_ITEM
104081 }
104082diff --git a/net/atm/lec.c b/net/atm/lec.c
104083index 4c5b8ba..95f7005 100644
104084--- a/net/atm/lec.c
104085+++ b/net/atm/lec.c
104086@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
104087 }
104088
104089 static struct lane2_ops lane2_ops = {
104090- lane2_resolve, /* resolve, spec 3.1.3 */
104091- lane2_associate_req, /* associate_req, spec 3.1.4 */
104092- NULL /* associate indicator, spec 3.1.5 */
104093+ .resolve = lane2_resolve,
104094+ .associate_req = lane2_associate_req,
104095+ .associate_indicator = NULL
104096 };
104097
104098 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
104099diff --git a/net/atm/lec.h b/net/atm/lec.h
104100index 4149db1..f2ab682 100644
104101--- a/net/atm/lec.h
104102+++ b/net/atm/lec.h
104103@@ -48,7 +48,7 @@ struct lane2_ops {
104104 const u8 *tlvs, u32 sizeoftlvs);
104105 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
104106 const u8 *tlvs, u32 sizeoftlvs);
104107-};
104108+} __no_const;
104109
104110 /*
104111 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
104112diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
104113index d1b2d9a..d549f7f 100644
104114--- a/net/atm/mpoa_caches.c
104115+++ b/net/atm/mpoa_caches.c
104116@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
104117
104118
104119 static struct in_cache_ops ingress_ops = {
104120- in_cache_add_entry, /* add_entry */
104121- in_cache_get, /* get */
104122- in_cache_get_with_mask, /* get_with_mask */
104123- in_cache_get_by_vcc, /* get_by_vcc */
104124- in_cache_put, /* put */
104125- in_cache_remove_entry, /* remove_entry */
104126- cache_hit, /* cache_hit */
104127- clear_count_and_expired, /* clear_count */
104128- check_resolving_entries, /* check_resolving */
104129- refresh_entries, /* refresh */
104130- in_destroy_cache /* destroy_cache */
104131+ .add_entry = in_cache_add_entry,
104132+ .get = in_cache_get,
104133+ .get_with_mask = in_cache_get_with_mask,
104134+ .get_by_vcc = in_cache_get_by_vcc,
104135+ .put = in_cache_put,
104136+ .remove_entry = in_cache_remove_entry,
104137+ .cache_hit = cache_hit,
104138+ .clear_count = clear_count_and_expired,
104139+ .check_resolving = check_resolving_entries,
104140+ .refresh = refresh_entries,
104141+ .destroy_cache = in_destroy_cache
104142 };
104143
104144 static struct eg_cache_ops egress_ops = {
104145- eg_cache_add_entry, /* add_entry */
104146- eg_cache_get_by_cache_id, /* get_by_cache_id */
104147- eg_cache_get_by_tag, /* get_by_tag */
104148- eg_cache_get_by_vcc, /* get_by_vcc */
104149- eg_cache_get_by_src_ip, /* get_by_src_ip */
104150- eg_cache_put, /* put */
104151- eg_cache_remove_entry, /* remove_entry */
104152- update_eg_cache_entry, /* update */
104153- clear_expired, /* clear_expired */
104154- eg_destroy_cache /* destroy_cache */
104155+ .add_entry = eg_cache_add_entry,
104156+ .get_by_cache_id = eg_cache_get_by_cache_id,
104157+ .get_by_tag = eg_cache_get_by_tag,
104158+ .get_by_vcc = eg_cache_get_by_vcc,
104159+ .get_by_src_ip = eg_cache_get_by_src_ip,
104160+ .put = eg_cache_put,
104161+ .remove_entry = eg_cache_remove_entry,
104162+ .update = update_eg_cache_entry,
104163+ .clear_expired = clear_expired,
104164+ .destroy_cache = eg_destroy_cache
104165 };
104166
104167
104168diff --git a/net/atm/proc.c b/net/atm/proc.c
104169index bbb6461..cf04016 100644
104170--- a/net/atm/proc.c
104171+++ b/net/atm/proc.c
104172@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
104173 const struct k_atm_aal_stats *stats)
104174 {
104175 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
104176- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
104177- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
104178- atomic_read(&stats->rx_drop));
104179+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
104180+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
104181+ atomic_read_unchecked(&stats->rx_drop));
104182 }
104183
104184 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
104185diff --git a/net/atm/resources.c b/net/atm/resources.c
104186index 0447d5d..3cf4728 100644
104187--- a/net/atm/resources.c
104188+++ b/net/atm/resources.c
104189@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
104190 static void copy_aal_stats(struct k_atm_aal_stats *from,
104191 struct atm_aal_stats *to)
104192 {
104193-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
104194+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
104195 __AAL_STAT_ITEMS
104196 #undef __HANDLE_ITEM
104197 }
104198@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
104199 static void subtract_aal_stats(struct k_atm_aal_stats *from,
104200 struct atm_aal_stats *to)
104201 {
104202-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
104203+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
104204 __AAL_STAT_ITEMS
104205 #undef __HANDLE_ITEM
104206 }
104207diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
104208index 919a5ce..cc6b444 100644
104209--- a/net/ax25/sysctl_net_ax25.c
104210+++ b/net/ax25/sysctl_net_ax25.c
104211@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
104212 {
104213 char path[sizeof("net/ax25/") + IFNAMSIZ];
104214 int k;
104215- struct ctl_table *table;
104216+ ctl_table_no_const *table;
104217
104218 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
104219 if (!table)
104220diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
104221index f04224c..f326579 100644
104222--- a/net/batman-adv/bat_iv_ogm.c
104223+++ b/net/batman-adv/bat_iv_ogm.c
104224@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
104225
104226 /* randomize initial seqno to avoid collision */
104227 get_random_bytes(&random_seqno, sizeof(random_seqno));
104228- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
104229+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
104230
104231 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
104232 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
104233@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
104234 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
104235
104236 /* change sequence number to network order */
104237- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
104238+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
104239 batadv_ogm_packet->seqno = htonl(seqno);
104240- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
104241+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
104242
104243 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
104244
104245@@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
104246 return;
104247
104248 /* could be changed by schedule_own_packet() */
104249- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
104250+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
104251
104252 if (ogm_packet->flags & BATADV_DIRECTLINK)
104253 has_directlink_flag = true;
104254diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
104255index 022d18a..919daff 100644
104256--- a/net/batman-adv/fragmentation.c
104257+++ b/net/batman-adv/fragmentation.c
104258@@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
104259 frag_header.packet_type = BATADV_UNICAST_FRAG;
104260 frag_header.version = BATADV_COMPAT_VERSION;
104261 frag_header.ttl = BATADV_TTL;
104262- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
104263+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
104264 frag_header.reserved = 0;
104265 frag_header.no = 0;
104266 frag_header.total_size = htons(skb->len);
104267diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
104268index cbd677f..b783347 100644
104269--- a/net/batman-adv/soft-interface.c
104270+++ b/net/batman-adv/soft-interface.c
104271@@ -296,7 +296,7 @@ send:
104272 primary_if->net_dev->dev_addr);
104273
104274 /* set broadcast sequence number */
104275- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
104276+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
104277 bcast_packet->seqno = htonl(seqno);
104278
104279 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
104280@@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
104281 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
104282
104283 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
104284- atomic_set(&bat_priv->bcast_seqno, 1);
104285+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
104286 atomic_set(&bat_priv->tt.vn, 0);
104287 atomic_set(&bat_priv->tt.local_changes, 0);
104288 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
104289@@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
104290
104291 /* randomize initial seqno to avoid collision */
104292 get_random_bytes(&random_seqno, sizeof(random_seqno));
104293- atomic_set(&bat_priv->frag_seqno, random_seqno);
104294+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
104295
104296 bat_priv->primary_if = NULL;
104297 bat_priv->num_ifaces = 0;
104298diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
104299index 8854c05..ee5d5497 100644
104300--- a/net/batman-adv/types.h
104301+++ b/net/batman-adv/types.h
104302@@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
104303 struct batadv_hard_iface_bat_iv {
104304 unsigned char *ogm_buff;
104305 int ogm_buff_len;
104306- atomic_t ogm_seqno;
104307+ atomic_unchecked_t ogm_seqno;
104308 };
104309
104310 /**
104311@@ -768,7 +768,7 @@ struct batadv_priv {
104312 atomic_t bonding;
104313 atomic_t fragmentation;
104314 atomic_t packet_size_max;
104315- atomic_t frag_seqno;
104316+ atomic_unchecked_t frag_seqno;
104317 #ifdef CONFIG_BATMAN_ADV_BLA
104318 atomic_t bridge_loop_avoidance;
104319 #endif
104320@@ -787,7 +787,7 @@ struct batadv_priv {
104321 #endif
104322 uint32_t isolation_mark;
104323 uint32_t isolation_mark_mask;
104324- atomic_t bcast_seqno;
104325+ atomic_unchecked_t bcast_seqno;
104326 atomic_t bcast_queue_left;
104327 atomic_t batman_queue_left;
104328 char num_ifaces;
104329diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
104330index 80d25c1..aa99a98 100644
104331--- a/net/bluetooth/hci_sock.c
104332+++ b/net/bluetooth/hci_sock.c
104333@@ -1044,7 +1044,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
104334 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
104335 }
104336
104337- len = min_t(unsigned int, len, sizeof(uf));
104338+ len = min((size_t)len, sizeof(uf));
104339 if (copy_from_user(&uf, optval, len)) {
104340 err = -EFAULT;
104341 break;
104342diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
104343index 323f23c..5e27529 100644
104344--- a/net/bluetooth/l2cap_core.c
104345+++ b/net/bluetooth/l2cap_core.c
104346@@ -3548,8 +3548,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
104347 break;
104348
104349 case L2CAP_CONF_RFC:
104350- if (olen == sizeof(rfc))
104351- memcpy(&rfc, (void *)val, olen);
104352+ if (olen != sizeof(rfc))
104353+ break;
104354+
104355+ memcpy(&rfc, (void *)val, olen);
104356
104357 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
104358 rfc.mode != chan->mode)
104359diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
104360index e137869..33f3ebd 100644
104361--- a/net/bluetooth/l2cap_sock.c
104362+++ b/net/bluetooth/l2cap_sock.c
104363@@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
104364 struct sock *sk = sock->sk;
104365 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
104366 struct l2cap_options opts;
104367- int len, err = 0;
104368+ int err = 0;
104369+ size_t len = optlen;
104370 u32 opt;
104371
104372 BT_DBG("sk %p", sk);
104373@@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
104374 opts.max_tx = chan->max_tx;
104375 opts.txwin_size = chan->tx_win;
104376
104377- len = min_t(unsigned int, sizeof(opts), optlen);
104378+ len = min(sizeof(opts), len);
104379 if (copy_from_user((char *) &opts, optval, len)) {
104380 err = -EFAULT;
104381 break;
104382@@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
104383 struct bt_security sec;
104384 struct bt_power pwr;
104385 struct l2cap_conn *conn;
104386- int len, err = 0;
104387+ int err = 0;
104388+ size_t len = optlen;
104389 u32 opt;
104390
104391 BT_DBG("sk %p", sk);
104392@@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
104393
104394 sec.level = BT_SECURITY_LOW;
104395
104396- len = min_t(unsigned int, sizeof(sec), optlen);
104397+ len = min(sizeof(sec), len);
104398 if (copy_from_user((char *) &sec, optval, len)) {
104399 err = -EFAULT;
104400 break;
104401@@ -861,7 +863,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
104402
104403 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
104404
104405- len = min_t(unsigned int, sizeof(pwr), optlen);
104406+ len = min(sizeof(pwr), len);
104407 if (copy_from_user((char *) &pwr, optval, len)) {
104408 err = -EFAULT;
104409 break;
104410diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
104411index c603a5e..7f08991 100644
104412--- a/net/bluetooth/rfcomm/sock.c
104413+++ b/net/bluetooth/rfcomm/sock.c
104414@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
104415 struct sock *sk = sock->sk;
104416 struct bt_security sec;
104417 int err = 0;
104418- size_t len;
104419+ size_t len = optlen;
104420 u32 opt;
104421
104422 BT_DBG("sk %p", sk);
104423@@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
104424
104425 sec.level = BT_SECURITY_LOW;
104426
104427- len = min_t(unsigned int, sizeof(sec), optlen);
104428+ len = min(sizeof(sec), len);
104429 if (copy_from_user((char *) &sec, optval, len)) {
104430 err = -EFAULT;
104431 break;
104432diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
104433index 8e385a0..a5bdd8e 100644
104434--- a/net/bluetooth/rfcomm/tty.c
104435+++ b/net/bluetooth/rfcomm/tty.c
104436@@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
104437 BT_DBG("tty %p id %d", tty, tty->index);
104438
104439 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
104440- dev->channel, dev->port.count);
104441+ dev->channel, atomic_read(&dev->port.count));
104442
104443 err = tty_port_open(&dev->port, tty, filp);
104444 if (err)
104445@@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
104446 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
104447
104448 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
104449- dev->port.count);
104450+ atomic_read(&dev->port.count));
104451
104452 tty_port_close(&dev->port, tty, filp);
104453 }
104454diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
104455index 1059ed3..d70846a 100644
104456--- a/net/bridge/netfilter/ebtables.c
104457+++ b/net/bridge/netfilter/ebtables.c
104458@@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104459 tmp.valid_hooks = t->table->valid_hooks;
104460 }
104461 mutex_unlock(&ebt_mutex);
104462- if (copy_to_user(user, &tmp, *len) != 0) {
104463+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
104464 BUGPRINT("c2u Didn't work\n");
104465 ret = -EFAULT;
104466 break;
104467@@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
104468 goto out;
104469 tmp.valid_hooks = t->valid_hooks;
104470
104471- if (copy_to_user(user, &tmp, *len) != 0) {
104472+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
104473 ret = -EFAULT;
104474 break;
104475 }
104476@@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
104477 tmp.entries_size = t->table->entries_size;
104478 tmp.valid_hooks = t->table->valid_hooks;
104479
104480- if (copy_to_user(user, &tmp, *len) != 0) {
104481+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
104482 ret = -EFAULT;
104483 break;
104484 }
104485diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
104486index 0f45522..dab651f 100644
104487--- a/net/caif/cfctrl.c
104488+++ b/net/caif/cfctrl.c
104489@@ -10,6 +10,7 @@
104490 #include <linux/spinlock.h>
104491 #include <linux/slab.h>
104492 #include <linux/pkt_sched.h>
104493+#include <linux/sched.h>
104494 #include <net/caif/caif_layer.h>
104495 #include <net/caif/cfpkt.h>
104496 #include <net/caif/cfctrl.h>
104497@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
104498 memset(&dev_info, 0, sizeof(dev_info));
104499 dev_info.id = 0xff;
104500 cfsrvl_init(&this->serv, 0, &dev_info, false);
104501- atomic_set(&this->req_seq_no, 1);
104502- atomic_set(&this->rsp_seq_no, 1);
104503+ atomic_set_unchecked(&this->req_seq_no, 1);
104504+ atomic_set_unchecked(&this->rsp_seq_no, 1);
104505 this->serv.layer.receive = cfctrl_recv;
104506 sprintf(this->serv.layer.name, "ctrl");
104507 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
104508@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
104509 struct cfctrl_request_info *req)
104510 {
104511 spin_lock_bh(&ctrl->info_list_lock);
104512- atomic_inc(&ctrl->req_seq_no);
104513- req->sequence_no = atomic_read(&ctrl->req_seq_no);
104514+ atomic_inc_unchecked(&ctrl->req_seq_no);
104515+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
104516 list_add_tail(&req->list, &ctrl->list);
104517 spin_unlock_bh(&ctrl->info_list_lock);
104518 }
104519@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
104520 if (p != first)
104521 pr_warn("Requests are not received in order\n");
104522
104523- atomic_set(&ctrl->rsp_seq_no,
104524+ atomic_set_unchecked(&ctrl->rsp_seq_no,
104525 p->sequence_no);
104526 list_del(&p->list);
104527 goto out;
104528diff --git a/net/can/af_can.c b/net/can/af_can.c
104529index ce82337..5d17b4d 100644
104530--- a/net/can/af_can.c
104531+++ b/net/can/af_can.c
104532@@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
104533 };
104534
104535 /* notifier block for netdevice event */
104536-static struct notifier_block can_netdev_notifier __read_mostly = {
104537+static struct notifier_block can_netdev_notifier = {
104538 .notifier_call = can_notifier,
104539 };
104540
104541diff --git a/net/can/bcm.c b/net/can/bcm.c
104542index dcb75c0..24b1b43 100644
104543--- a/net/can/bcm.c
104544+++ b/net/can/bcm.c
104545@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
104546 }
104547
104548 /* create /proc/net/can-bcm directory */
104549- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
104550+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
104551 return 0;
104552 }
104553
104554diff --git a/net/can/gw.c b/net/can/gw.c
104555index 050a211..bb9fe33 100644
104556--- a/net/can/gw.c
104557+++ b/net/can/gw.c
104558@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
104559 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
104560
104561 static HLIST_HEAD(cgw_list);
104562-static struct notifier_block notifier;
104563
104564 static struct kmem_cache *cgw_cache __read_mostly;
104565
104566@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
104567 return err;
104568 }
104569
104570+static struct notifier_block notifier = {
104571+ .notifier_call = cgw_notifier
104572+};
104573+
104574 static __init int cgw_module_init(void)
104575 {
104576 /* sanitize given module parameter */
104577@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
104578 return -ENOMEM;
104579
104580 /* set notifier */
104581- notifier.notifier_call = cgw_notifier;
104582 register_netdevice_notifier(&notifier);
104583
104584 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
104585diff --git a/net/can/proc.c b/net/can/proc.c
104586index 1a19b98..df2b4ec 100644
104587--- a/net/can/proc.c
104588+++ b/net/can/proc.c
104589@@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
104590 void can_init_proc(void)
104591 {
104592 /* create /proc/net/can directory */
104593- can_dir = proc_mkdir("can", init_net.proc_net);
104594+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
104595
104596 if (!can_dir) {
104597 printk(KERN_INFO "can: failed to create /proc/net/can . "
104598diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
104599index 1948d59..9e854d5 100644
104600--- a/net/ceph/messenger.c
104601+++ b/net/ceph/messenger.c
104602@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
104603 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
104604
104605 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
104606-static atomic_t addr_str_seq = ATOMIC_INIT(0);
104607+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
104608
104609 static struct page *zero_page; /* used in certain error cases */
104610
104611@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
104612 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
104613 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
104614
104615- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
104616+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
104617 s = addr_str[i];
104618
104619 switch (ss->ss_family) {
104620diff --git a/net/compat.c b/net/compat.c
104621index bc8aeef..f9c070c 100644
104622--- a/net/compat.c
104623+++ b/net/compat.c
104624@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
104625 return -EFAULT;
104626 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
104627 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
104628- kmsg->msg_name = compat_ptr(tmp1);
104629- kmsg->msg_iov = compat_ptr(tmp2);
104630- kmsg->msg_control = compat_ptr(tmp3);
104631+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
104632+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
104633+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
104634 return 0;
104635 }
104636
104637@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
104638
104639 if (kern_msg->msg_name && kern_msg->msg_namelen) {
104640 if (mode == VERIFY_READ) {
104641- int err = move_addr_to_kernel(kern_msg->msg_name,
104642+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
104643 kern_msg->msg_namelen,
104644 kern_address);
104645 if (err < 0)
104646@@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
104647 }
104648
104649 tot_len = iov_from_user_compat_to_kern(kern_iov,
104650- (struct compat_iovec __user *)kern_msg->msg_iov,
104651+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
104652 kern_msg->msg_iovlen);
104653 if (tot_len >= 0)
104654 kern_msg->msg_iov = kern_iov;
104655@@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
104656
104657 #define CMSG_COMPAT_FIRSTHDR(msg) \
104658 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
104659- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
104660+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
104661 (struct compat_cmsghdr __user *)NULL)
104662
104663 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
104664 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
104665 (ucmlen) <= (unsigned long) \
104666 ((mhdr)->msg_controllen - \
104667- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
104668+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
104669
104670 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
104671 struct compat_cmsghdr __user *cmsg, int cmsg_len)
104672 {
104673 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
104674- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
104675+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
104676 msg->msg_controllen)
104677 return NULL;
104678 return (struct compat_cmsghdr __user *)ptr;
104679@@ -223,7 +223,7 @@ Efault:
104680
104681 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
104682 {
104683- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
104684+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
104685 struct compat_cmsghdr cmhdr;
104686 struct compat_timeval ctv;
104687 struct compat_timespec cts[3];
104688@@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
104689
104690 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
104691 {
104692- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
104693+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
104694 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
104695 int fdnum = scm->fp->count;
104696 struct file **fp = scm->fp->fp;
104697@@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
104698 return -EFAULT;
104699 old_fs = get_fs();
104700 set_fs(KERNEL_DS);
104701- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
104702+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
104703 set_fs(old_fs);
104704
104705 return err;
104706@@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
104707 len = sizeof(ktime);
104708 old_fs = get_fs();
104709 set_fs(KERNEL_DS);
104710- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
104711+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
104712 set_fs(old_fs);
104713
104714 if (!err) {
104715@@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
104716 case MCAST_JOIN_GROUP:
104717 case MCAST_LEAVE_GROUP:
104718 {
104719- struct compat_group_req __user *gr32 = (void *)optval;
104720+ struct compat_group_req __user *gr32 = (void __user *)optval;
104721 struct group_req __user *kgr =
104722 compat_alloc_user_space(sizeof(struct group_req));
104723 u32 interface;
104724@@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
104725 case MCAST_BLOCK_SOURCE:
104726 case MCAST_UNBLOCK_SOURCE:
104727 {
104728- struct compat_group_source_req __user *gsr32 = (void *)optval;
104729+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
104730 struct group_source_req __user *kgsr = compat_alloc_user_space(
104731 sizeof(struct group_source_req));
104732 u32 interface;
104733@@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
104734 }
104735 case MCAST_MSFILTER:
104736 {
104737- struct compat_group_filter __user *gf32 = (void *)optval;
104738+ struct compat_group_filter __user *gf32 = (void __user *)optval;
104739 struct group_filter __user *kgf;
104740 u32 interface, fmode, numsrc;
104741
104742@@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
104743 char __user *optval, int __user *optlen,
104744 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
104745 {
104746- struct compat_group_filter __user *gf32 = (void *)optval;
104747+ struct compat_group_filter __user *gf32 = (void __user *)optval;
104748 struct group_filter __user *kgf;
104749 int __user *koptlen;
104750 u32 interface, fmode, numsrc;
104751@@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
104752
104753 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
104754 return -EINVAL;
104755- if (copy_from_user(a, args, nas[call]))
104756+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
104757 return -EFAULT;
104758 a0 = a[0];
104759 a1 = a[1];
104760diff --git a/net/core/Makefile b/net/core/Makefile
104761index 71093d9..a8a035b 100644
104762--- a/net/core/Makefile
104763+++ b/net/core/Makefile
104764@@ -21,6 +21,5 @@ obj-$(CONFIG_FIB_RULES) += fib_rules.o
104765 obj-$(CONFIG_TRACEPOINTS) += net-traces.o
104766 obj-$(CONFIG_NET_DROP_MONITOR) += drop_monitor.o
104767 obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += timestamping.o
104768-obj-$(CONFIG_NET_PTP_CLASSIFY) += ptp_classifier.o
104769 obj-$(CONFIG_CGROUP_NET_PRIO) += netprio_cgroup.o
104770 obj-$(CONFIG_CGROUP_NET_CLASSID) += netclassid_cgroup.o
104771diff --git a/net/core/datagram.c b/net/core/datagram.c
104772index 488dd1a..7179f0f 100644
104773--- a/net/core/datagram.c
104774+++ b/net/core/datagram.c
104775@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
104776 }
104777
104778 kfree_skb(skb);
104779- atomic_inc(&sk->sk_drops);
104780+ atomic_inc_unchecked(&sk->sk_drops);
104781 sk_mem_reclaim_partial(sk);
104782
104783 return err;
104784diff --git a/net/core/dev.c b/net/core/dev.c
104785index 367a586..ef2fe17 100644
104786--- a/net/core/dev.c
104787+++ b/net/core/dev.c
104788@@ -1672,14 +1672,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
104789 {
104790 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
104791 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
104792- atomic_long_inc(&dev->rx_dropped);
104793+ atomic_long_inc_unchecked(&dev->rx_dropped);
104794 kfree_skb(skb);
104795 return NET_RX_DROP;
104796 }
104797 }
104798
104799 if (unlikely(!is_skb_forwardable(dev, skb))) {
104800- atomic_long_inc(&dev->rx_dropped);
104801+ atomic_long_inc_unchecked(&dev->rx_dropped);
104802 kfree_skb(skb);
104803 return NET_RX_DROP;
104804 }
104805@@ -2476,7 +2476,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
104806
104807 struct dev_gso_cb {
104808 void (*destructor)(struct sk_buff *skb);
104809-};
104810+} __no_const;
104811
104812 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
104813
104814@@ -2932,7 +2932,7 @@ recursion_alert:
104815 rc = -ENETDOWN;
104816 rcu_read_unlock_bh();
104817
104818- atomic_long_inc(&dev->tx_dropped);
104819+ atomic_long_inc_unchecked(&dev->tx_dropped);
104820 kfree_skb(skb);
104821 return rc;
104822 out:
104823@@ -3276,7 +3276,7 @@ enqueue:
104824
104825 local_irq_restore(flags);
104826
104827- atomic_long_inc(&skb->dev->rx_dropped);
104828+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
104829 kfree_skb(skb);
104830 return NET_RX_DROP;
104831 }
104832@@ -3353,7 +3353,7 @@ int netif_rx_ni(struct sk_buff *skb)
104833 }
104834 EXPORT_SYMBOL(netif_rx_ni);
104835
104836-static void net_tx_action(struct softirq_action *h)
104837+static __latent_entropy void net_tx_action(void)
104838 {
104839 struct softnet_data *sd = &__get_cpu_var(softnet_data);
104840
104841@@ -3686,7 +3686,7 @@ ncls:
104842 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
104843 } else {
104844 drop:
104845- atomic_long_inc(&skb->dev->rx_dropped);
104846+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
104847 kfree_skb(skb);
104848 /* Jamal, now you will not able to escape explaining
104849 * me how you were going to use this. :-)
104850@@ -4406,7 +4406,7 @@ void netif_napi_del(struct napi_struct *napi)
104851 }
104852 EXPORT_SYMBOL(netif_napi_del);
104853
104854-static void net_rx_action(struct softirq_action *h)
104855+static __latent_entropy void net_rx_action(void)
104856 {
104857 struct softnet_data *sd = &__get_cpu_var(softnet_data);
104858 unsigned long time_limit = jiffies + 2;
104859@@ -6403,8 +6403,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
104860 } else {
104861 netdev_stats_to_stats64(storage, &dev->stats);
104862 }
104863- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
104864- storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
104865+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
104866+ storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
104867 return storage;
104868 }
104869 EXPORT_SYMBOL(dev_get_stats);
104870diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
104871index cf999e0..c59a975 100644
104872--- a/net/core/dev_ioctl.c
104873+++ b/net/core/dev_ioctl.c
104874@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
104875 if (no_module && capable(CAP_NET_ADMIN))
104876 no_module = request_module("netdev-%s", name);
104877 if (no_module && capable(CAP_SYS_MODULE)) {
104878+#ifdef CONFIG_GRKERNSEC_MODHARDEN
104879+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
104880+#else
104881 if (!request_module("%s", name))
104882 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
104883 name);
104884+#endif
104885 }
104886 }
104887 EXPORT_SYMBOL(dev_load);
104888diff --git a/net/core/filter.c b/net/core/filter.c
104889index 1dbf646..0f95703 100644
104890--- a/net/core/filter.c
104891+++ b/net/core/filter.c
104892@@ -1,16 +1,11 @@
104893 /*
104894 * Linux Socket Filter - Kernel level socket filtering
104895 *
104896- * Based on the design of the Berkeley Packet Filter. The new
104897- * internal format has been designed by PLUMgrid:
104898+ * Author:
104899+ * Jay Schulist <jschlst@samba.org>
104900 *
104901- * Copyright (c) 2011 - 2014 PLUMgrid, http://plumgrid.com
104902- *
104903- * Authors:
104904- *
104905- * Jay Schulist <jschlst@samba.org>
104906- * Alexei Starovoitov <ast@plumgrid.com>
104907- * Daniel Borkmann <dborkman@redhat.com>
104908+ * Based on the design of:
104909+ * - The Berkeley Packet Filter
104910 *
104911 * This program is free software; you can redistribute it and/or
104912 * modify it under the terms of the GNU General Public License
104913@@ -45,27 +40,6 @@
104914 #include <linux/seccomp.h>
104915 #include <linux/if_vlan.h>
104916
104917-/* Registers */
104918-#define BPF_R0 regs[BPF_REG_0]
104919-#define BPF_R1 regs[BPF_REG_1]
104920-#define BPF_R2 regs[BPF_REG_2]
104921-#define BPF_R3 regs[BPF_REG_3]
104922-#define BPF_R4 regs[BPF_REG_4]
104923-#define BPF_R5 regs[BPF_REG_5]
104924-#define BPF_R6 regs[BPF_REG_6]
104925-#define BPF_R7 regs[BPF_REG_7]
104926-#define BPF_R8 regs[BPF_REG_8]
104927-#define BPF_R9 regs[BPF_REG_9]
104928-#define BPF_R10 regs[BPF_REG_10]
104929-
104930-/* Named registers */
104931-#define DST regs[insn->dst_reg]
104932-#define SRC regs[insn->src_reg]
104933-#define FP regs[BPF_REG_FP]
104934-#define ARG1 regs[BPF_REG_ARG1]
104935-#define CTX regs[BPF_REG_CTX]
104936-#define IMM insn->imm
104937-
104938 /* No hurry in this branch
104939 *
104940 * Exported for the bpf jit load helper.
104941@@ -78,9 +52,9 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
104942 ptr = skb_network_header(skb) + k - SKF_NET_OFF;
104943 else if (k >= SKF_LL_OFF)
104944 ptr = skb_mac_header(skb) + k - SKF_LL_OFF;
104945+
104946 if (ptr >= skb->head && ptr + size <= skb_tail_pointer(skb))
104947 return ptr;
104948-
104949 return NULL;
104950 }
104951
104952@@ -89,7 +63,6 @@ static inline void *load_pointer(const struct sk_buff *skb, int k,
104953 {
104954 if (k >= 0)
104955 return skb_header_pointer(skb, k, size, buffer);
104956-
104957 return bpf_internal_load_pointer_neg_helper(skb, k, size);
104958 }
104959
104960@@ -135,960 +108,309 @@ int sk_filter(struct sock *sk, struct sk_buff *skb)
104961 }
104962 EXPORT_SYMBOL(sk_filter);
104963
104964-/* Base function for offset calculation. Needs to go into .text section,
104965- * therefore keeping it non-static as well; will also be used by JITs
104966- * anyway later on, so do not let the compiler omit it.
104967- */
104968-noinline u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
104969-{
104970- return 0;
104971-}
104972-
104973 /**
104974- * __sk_run_filter - run a filter on a given context
104975- * @ctx: buffer to run the filter on
104976- * @insn: filter to apply
104977+ * sk_run_filter - run a filter on a socket
104978+ * @skb: buffer to run the filter on
104979+ * @fentry: filter to apply
104980 *
104981- * Decode and apply filter instructions to the skb->data. Return length to
104982- * keep, 0 for none. @ctx is the data we are operating on, @insn is the
104983- * array of filter instructions.
104984+ * Decode and apply filter instructions to the skb->data.
104985+ * Return length to keep, 0 for none. @skb is the data we are
104986+ * filtering, @filter is the array of filter instructions.
104987+ * Because all jumps are guaranteed to be before last instruction,
104988+ * and last instruction guaranteed to be a RET, we dont need to check
104989+ * flen. (We used to pass to this function the length of filter)
104990 */
104991-static unsigned int __sk_run_filter(void *ctx, const struct sock_filter_int *insn)
104992+unsigned int sk_run_filter(const struct sk_buff *skb,
104993+ const struct sock_filter *fentry)
104994 {
104995- u64 stack[MAX_BPF_STACK / sizeof(u64)];
104996- u64 regs[MAX_BPF_REG], tmp;
104997- static const void *jumptable[256] = {
104998- [0 ... 255] = &&default_label,
104999- /* Now overwrite non-defaults ... */
105000- /* 32 bit ALU operations */
105001- [BPF_ALU | BPF_ADD | BPF_X] = &&ALU_ADD_X,
105002- [BPF_ALU | BPF_ADD | BPF_K] = &&ALU_ADD_K,
105003- [BPF_ALU | BPF_SUB | BPF_X] = &&ALU_SUB_X,
105004- [BPF_ALU | BPF_SUB | BPF_K] = &&ALU_SUB_K,
105005- [BPF_ALU | BPF_AND | BPF_X] = &&ALU_AND_X,
105006- [BPF_ALU | BPF_AND | BPF_K] = &&ALU_AND_K,
105007- [BPF_ALU | BPF_OR | BPF_X] = &&ALU_OR_X,
105008- [BPF_ALU | BPF_OR | BPF_K] = &&ALU_OR_K,
105009- [BPF_ALU | BPF_LSH | BPF_X] = &&ALU_LSH_X,
105010- [BPF_ALU | BPF_LSH | BPF_K] = &&ALU_LSH_K,
105011- [BPF_ALU | BPF_RSH | BPF_X] = &&ALU_RSH_X,
105012- [BPF_ALU | BPF_RSH | BPF_K] = &&ALU_RSH_K,
105013- [BPF_ALU | BPF_XOR | BPF_X] = &&ALU_XOR_X,
105014- [BPF_ALU | BPF_XOR | BPF_K] = &&ALU_XOR_K,
105015- [BPF_ALU | BPF_MUL | BPF_X] = &&ALU_MUL_X,
105016- [BPF_ALU | BPF_MUL | BPF_K] = &&ALU_MUL_K,
105017- [BPF_ALU | BPF_MOV | BPF_X] = &&ALU_MOV_X,
105018- [BPF_ALU | BPF_MOV | BPF_K] = &&ALU_MOV_K,
105019- [BPF_ALU | BPF_DIV | BPF_X] = &&ALU_DIV_X,
105020- [BPF_ALU | BPF_DIV | BPF_K] = &&ALU_DIV_K,
105021- [BPF_ALU | BPF_MOD | BPF_X] = &&ALU_MOD_X,
105022- [BPF_ALU | BPF_MOD | BPF_K] = &&ALU_MOD_K,
105023- [BPF_ALU | BPF_NEG] = &&ALU_NEG,
105024- [BPF_ALU | BPF_END | BPF_TO_BE] = &&ALU_END_TO_BE,
105025- [BPF_ALU | BPF_END | BPF_TO_LE] = &&ALU_END_TO_LE,
105026- /* 64 bit ALU operations */
105027- [BPF_ALU64 | BPF_ADD | BPF_X] = &&ALU64_ADD_X,
105028- [BPF_ALU64 | BPF_ADD | BPF_K] = &&ALU64_ADD_K,
105029- [BPF_ALU64 | BPF_SUB | BPF_X] = &&ALU64_SUB_X,
105030- [BPF_ALU64 | BPF_SUB | BPF_K] = &&ALU64_SUB_K,
105031- [BPF_ALU64 | BPF_AND | BPF_X] = &&ALU64_AND_X,
105032- [BPF_ALU64 | BPF_AND | BPF_K] = &&ALU64_AND_K,
105033- [BPF_ALU64 | BPF_OR | BPF_X] = &&ALU64_OR_X,
105034- [BPF_ALU64 | BPF_OR | BPF_K] = &&ALU64_OR_K,
105035- [BPF_ALU64 | BPF_LSH | BPF_X] = &&ALU64_LSH_X,
105036- [BPF_ALU64 | BPF_LSH | BPF_K] = &&ALU64_LSH_K,
105037- [BPF_ALU64 | BPF_RSH | BPF_X] = &&ALU64_RSH_X,
105038- [BPF_ALU64 | BPF_RSH | BPF_K] = &&ALU64_RSH_K,
105039- [BPF_ALU64 | BPF_XOR | BPF_X] = &&ALU64_XOR_X,
105040- [BPF_ALU64 | BPF_XOR | BPF_K] = &&ALU64_XOR_K,
105041- [BPF_ALU64 | BPF_MUL | BPF_X] = &&ALU64_MUL_X,
105042- [BPF_ALU64 | BPF_MUL | BPF_K] = &&ALU64_MUL_K,
105043- [BPF_ALU64 | BPF_MOV | BPF_X] = &&ALU64_MOV_X,
105044- [BPF_ALU64 | BPF_MOV | BPF_K] = &&ALU64_MOV_K,
105045- [BPF_ALU64 | BPF_ARSH | BPF_X] = &&ALU64_ARSH_X,
105046- [BPF_ALU64 | BPF_ARSH | BPF_K] = &&ALU64_ARSH_K,
105047- [BPF_ALU64 | BPF_DIV | BPF_X] = &&ALU64_DIV_X,
105048- [BPF_ALU64 | BPF_DIV | BPF_K] = &&ALU64_DIV_K,
105049- [BPF_ALU64 | BPF_MOD | BPF_X] = &&ALU64_MOD_X,
105050- [BPF_ALU64 | BPF_MOD | BPF_K] = &&ALU64_MOD_K,
105051- [BPF_ALU64 | BPF_NEG] = &&ALU64_NEG,
105052- /* Call instruction */
105053- [BPF_JMP | BPF_CALL] = &&JMP_CALL,
105054- /* Jumps */
105055- [BPF_JMP | BPF_JA] = &&JMP_JA,
105056- [BPF_JMP | BPF_JEQ | BPF_X] = &&JMP_JEQ_X,
105057- [BPF_JMP | BPF_JEQ | BPF_K] = &&JMP_JEQ_K,
105058- [BPF_JMP | BPF_JNE | BPF_X] = &&JMP_JNE_X,
105059- [BPF_JMP | BPF_JNE | BPF_K] = &&JMP_JNE_K,
105060- [BPF_JMP | BPF_JGT | BPF_X] = &&JMP_JGT_X,
105061- [BPF_JMP | BPF_JGT | BPF_K] = &&JMP_JGT_K,
105062- [BPF_JMP | BPF_JGE | BPF_X] = &&JMP_JGE_X,
105063- [BPF_JMP | BPF_JGE | BPF_K] = &&JMP_JGE_K,
105064- [BPF_JMP | BPF_JSGT | BPF_X] = &&JMP_JSGT_X,
105065- [BPF_JMP | BPF_JSGT | BPF_K] = &&JMP_JSGT_K,
105066- [BPF_JMP | BPF_JSGE | BPF_X] = &&JMP_JSGE_X,
105067- [BPF_JMP | BPF_JSGE | BPF_K] = &&JMP_JSGE_K,
105068- [BPF_JMP | BPF_JSET | BPF_X] = &&JMP_JSET_X,
105069- [BPF_JMP | BPF_JSET | BPF_K] = &&JMP_JSET_K,
105070- /* Program return */
105071- [BPF_JMP | BPF_EXIT] = &&JMP_EXIT,
105072- /* Store instructions */
105073- [BPF_STX | BPF_MEM | BPF_B] = &&STX_MEM_B,
105074- [BPF_STX | BPF_MEM | BPF_H] = &&STX_MEM_H,
105075- [BPF_STX | BPF_MEM | BPF_W] = &&STX_MEM_W,
105076- [BPF_STX | BPF_MEM | BPF_DW] = &&STX_MEM_DW,
105077- [BPF_STX | BPF_XADD | BPF_W] = &&STX_XADD_W,
105078- [BPF_STX | BPF_XADD | BPF_DW] = &&STX_XADD_DW,
105079- [BPF_ST | BPF_MEM | BPF_B] = &&ST_MEM_B,
105080- [BPF_ST | BPF_MEM | BPF_H] = &&ST_MEM_H,
105081- [BPF_ST | BPF_MEM | BPF_W] = &&ST_MEM_W,
105082- [BPF_ST | BPF_MEM | BPF_DW] = &&ST_MEM_DW,
105083- /* Load instructions */
105084- [BPF_LDX | BPF_MEM | BPF_B] = &&LDX_MEM_B,
105085- [BPF_LDX | BPF_MEM | BPF_H] = &&LDX_MEM_H,
105086- [BPF_LDX | BPF_MEM | BPF_W] = &&LDX_MEM_W,
105087- [BPF_LDX | BPF_MEM | BPF_DW] = &&LDX_MEM_DW,
105088- [BPF_LD | BPF_ABS | BPF_W] = &&LD_ABS_W,
105089- [BPF_LD | BPF_ABS | BPF_H] = &&LD_ABS_H,
105090- [BPF_LD | BPF_ABS | BPF_B] = &&LD_ABS_B,
105091- [BPF_LD | BPF_IND | BPF_W] = &&LD_IND_W,
105092- [BPF_LD | BPF_IND | BPF_H] = &&LD_IND_H,
105093- [BPF_LD | BPF_IND | BPF_B] = &&LD_IND_B,
105094- };
105095 void *ptr;
105096- int off;
105097-
105098-#define CONT ({ insn++; goto select_insn; })
105099-#define CONT_JMP ({ insn++; goto select_insn; })
105100-
105101- FP = (u64) (unsigned long) &stack[ARRAY_SIZE(stack)];
105102- ARG1 = (u64) (unsigned long) ctx;
105103-
105104- /* Registers used in classic BPF programs need to be reset first. */
105105- regs[BPF_REG_A] = 0;
105106- regs[BPF_REG_X] = 0;
105107-
105108-select_insn:
105109- goto *jumptable[insn->code];
105110-
105111- /* ALU */
105112-#define ALU(OPCODE, OP) \
105113- ALU64_##OPCODE##_X: \
105114- DST = DST OP SRC; \
105115- CONT; \
105116- ALU_##OPCODE##_X: \
105117- DST = (u32) DST OP (u32) SRC; \
105118- CONT; \
105119- ALU64_##OPCODE##_K: \
105120- DST = DST OP IMM; \
105121- CONT; \
105122- ALU_##OPCODE##_K: \
105123- DST = (u32) DST OP (u32) IMM; \
105124- CONT;
105125-
105126- ALU(ADD, +)
105127- ALU(SUB, -)
105128- ALU(AND, &)
105129- ALU(OR, |)
105130- ALU(LSH, <<)
105131- ALU(RSH, >>)
105132- ALU(XOR, ^)
105133- ALU(MUL, *)
105134-#undef ALU
105135- ALU_NEG:
105136- DST = (u32) -DST;
105137- CONT;
105138- ALU64_NEG:
105139- DST = -DST;
105140- CONT;
105141- ALU_MOV_X:
105142- DST = (u32) SRC;
105143- CONT;
105144- ALU_MOV_K:
105145- DST = (u32) IMM;
105146- CONT;
105147- ALU64_MOV_X:
105148- DST = SRC;
105149- CONT;
105150- ALU64_MOV_K:
105151- DST = IMM;
105152- CONT;
105153- ALU64_ARSH_X:
105154- (*(s64 *) &DST) >>= SRC;
105155- CONT;
105156- ALU64_ARSH_K:
105157- (*(s64 *) &DST) >>= IMM;
105158- CONT;
105159- ALU64_MOD_X:
105160- if (unlikely(SRC == 0))
105161- return 0;
105162- tmp = DST;
105163- DST = do_div(tmp, SRC);
105164- CONT;
105165- ALU_MOD_X:
105166- if (unlikely(SRC == 0))
105167- return 0;
105168- tmp = (u32) DST;
105169- DST = do_div(tmp, (u32) SRC);
105170- CONT;
105171- ALU64_MOD_K:
105172- tmp = DST;
105173- DST = do_div(tmp, IMM);
105174- CONT;
105175- ALU_MOD_K:
105176- tmp = (u32) DST;
105177- DST = do_div(tmp, (u32) IMM);
105178- CONT;
105179- ALU64_DIV_X:
105180- if (unlikely(SRC == 0))
105181- return 0;
105182- do_div(DST, SRC);
105183- CONT;
105184- ALU_DIV_X:
105185- if (unlikely(SRC == 0))
105186- return 0;
105187- tmp = (u32) DST;
105188- do_div(tmp, (u32) SRC);
105189- DST = (u32) tmp;
105190- CONT;
105191- ALU64_DIV_K:
105192- do_div(DST, IMM);
105193- CONT;
105194- ALU_DIV_K:
105195- tmp = (u32) DST;
105196- do_div(tmp, (u32) IMM);
105197- DST = (u32) tmp;
105198- CONT;
105199- ALU_END_TO_BE:
105200- switch (IMM) {
105201- case 16:
105202- DST = (__force u16) cpu_to_be16(DST);
105203- break;
105204- case 32:
105205- DST = (__force u32) cpu_to_be32(DST);
105206- break;
105207- case 64:
105208- DST = (__force u64) cpu_to_be64(DST);
105209- break;
105210- }
105211- CONT;
105212- ALU_END_TO_LE:
105213- switch (IMM) {
105214- case 16:
105215- DST = (__force u16) cpu_to_le16(DST);
105216- break;
105217- case 32:
105218- DST = (__force u32) cpu_to_le32(DST);
105219- break;
105220- case 64:
105221- DST = (__force u64) cpu_to_le64(DST);
105222- break;
105223- }
105224- CONT;
105225-
105226- /* CALL */
105227- JMP_CALL:
105228- /* Function call scratches BPF_R1-BPF_R5 registers,
105229- * preserves BPF_R6-BPF_R9, and stores return value
105230- * into BPF_R0.
105231- */
105232- BPF_R0 = (__bpf_call_base + insn->imm)(BPF_R1, BPF_R2, BPF_R3,
105233- BPF_R4, BPF_R5);
105234- CONT;
105235-
105236- /* JMP */
105237- JMP_JA:
105238- insn += insn->off;
105239- CONT;
105240- JMP_JEQ_X:
105241- if (DST == SRC) {
105242- insn += insn->off;
105243- CONT_JMP;
105244- }
105245- CONT;
105246- JMP_JEQ_K:
105247- if (DST == IMM) {
105248- insn += insn->off;
105249- CONT_JMP;
105250- }
105251- CONT;
105252- JMP_JNE_X:
105253- if (DST != SRC) {
105254- insn += insn->off;
105255- CONT_JMP;
105256- }
105257- CONT;
105258- JMP_JNE_K:
105259- if (DST != IMM) {
105260- insn += insn->off;
105261- CONT_JMP;
105262- }
105263- CONT;
105264- JMP_JGT_X:
105265- if (DST > SRC) {
105266- insn += insn->off;
105267- CONT_JMP;
105268- }
105269- CONT;
105270- JMP_JGT_K:
105271- if (DST > IMM) {
105272- insn += insn->off;
105273- CONT_JMP;
105274- }
105275- CONT;
105276- JMP_JGE_X:
105277- if (DST >= SRC) {
105278- insn += insn->off;
105279- CONT_JMP;
105280- }
105281- CONT;
105282- JMP_JGE_K:
105283- if (DST >= IMM) {
105284- insn += insn->off;
105285- CONT_JMP;
105286- }
105287- CONT;
105288- JMP_JSGT_X:
105289- if (((s64) DST) > ((s64) SRC)) {
105290- insn += insn->off;
105291- CONT_JMP;
105292- }
105293- CONT;
105294- JMP_JSGT_K:
105295- if (((s64) DST) > ((s64) IMM)) {
105296- insn += insn->off;
105297- CONT_JMP;
105298- }
105299- CONT;
105300- JMP_JSGE_X:
105301- if (((s64) DST) >= ((s64) SRC)) {
105302- insn += insn->off;
105303- CONT_JMP;
105304- }
105305- CONT;
105306- JMP_JSGE_K:
105307- if (((s64) DST) >= ((s64) IMM)) {
105308- insn += insn->off;
105309- CONT_JMP;
105310- }
105311- CONT;
105312- JMP_JSET_X:
105313- if (DST & SRC) {
105314- insn += insn->off;
105315- CONT_JMP;
105316- }
105317- CONT;
105318- JMP_JSET_K:
105319- if (DST & IMM) {
105320- insn += insn->off;
105321- CONT_JMP;
105322- }
105323- CONT;
105324- JMP_EXIT:
105325- return BPF_R0;
105326-
105327- /* STX and ST and LDX*/
105328-#define LDST(SIZEOP, SIZE) \
105329- STX_MEM_##SIZEOP: \
105330- *(SIZE *)(unsigned long) (DST + insn->off) = SRC; \
105331- CONT; \
105332- ST_MEM_##SIZEOP: \
105333- *(SIZE *)(unsigned long) (DST + insn->off) = IMM; \
105334- CONT; \
105335- LDX_MEM_##SIZEOP: \
105336- DST = *(SIZE *)(unsigned long) (SRC + insn->off); \
105337- CONT;
105338-
105339- LDST(B, u8)
105340- LDST(H, u16)
105341- LDST(W, u32)
105342- LDST(DW, u64)
105343-#undef LDST
105344- STX_XADD_W: /* lock xadd *(u32 *)(dst_reg + off16) += src_reg */
105345- atomic_add((u32) SRC, (atomic_t *)(unsigned long)
105346- (DST + insn->off));
105347- CONT;
105348- STX_XADD_DW: /* lock xadd *(u64 *)(dst_reg + off16) += src_reg */
105349- atomic64_add((u64) SRC, (atomic64_t *)(unsigned long)
105350- (DST + insn->off));
105351- CONT;
105352- LD_ABS_W: /* BPF_R0 = ntohl(*(u32 *) (skb->data + imm32)) */
105353- off = IMM;
105354-load_word:
105355- /* BPF_LD + BPD_ABS and BPF_LD + BPF_IND insns are
105356- * only appearing in the programs where ctx ==
105357- * skb. All programs keep 'ctx' in regs[BPF_REG_CTX]
105358- * == BPF_R6, sk_convert_filter() saves it in BPF_R6,
105359- * internal BPF verifier will check that BPF_R6 ==
105360- * ctx.
105361- *
105362- * BPF_ABS and BPF_IND are wrappers of function calls,
105363- * so they scratch BPF_R1-BPF_R5 registers, preserve
105364- * BPF_R6-BPF_R9, and store return value into BPF_R0.
105365- *
105366- * Implicit input:
105367- * ctx == skb == BPF_R6 == CTX
105368- *
105369- * Explicit input:
105370- * SRC == any register
105371- * IMM == 32-bit immediate
105372- *
105373- * Output:
105374- * BPF_R0 - 8/16/32-bit skb data converted to cpu endianness
105375- */
105376-
105377- ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 4, &tmp);
105378- if (likely(ptr != NULL)) {
105379- BPF_R0 = get_unaligned_be32(ptr);
105380- CONT;
105381- }
105382-
105383- return 0;
105384- LD_ABS_H: /* BPF_R0 = ntohs(*(u16 *) (skb->data + imm32)) */
105385- off = IMM;
105386-load_half:
105387- ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 2, &tmp);
105388- if (likely(ptr != NULL)) {
105389- BPF_R0 = get_unaligned_be16(ptr);
105390- CONT;
105391- }
105392-
105393- return 0;
105394- LD_ABS_B: /* BPF_R0 = *(u8 *) (skb->data + imm32) */
105395- off = IMM;
105396-load_byte:
105397- ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 1, &tmp);
105398- if (likely(ptr != NULL)) {
105399- BPF_R0 = *(u8 *)ptr;
105400- CONT;
105401- }
105402-
105403- return 0;
105404- LD_IND_W: /* BPF_R0 = ntohl(*(u32 *) (skb->data + src_reg + imm32)) */
105405- off = IMM + SRC;
105406- goto load_word;
105407- LD_IND_H: /* BPF_R0 = ntohs(*(u16 *) (skb->data + src_reg + imm32)) */
105408- off = IMM + SRC;
105409- goto load_half;
105410- LD_IND_B: /* BPF_R0 = *(u8 *) (skb->data + src_reg + imm32) */
105411- off = IMM + SRC;
105412- goto load_byte;
105413-
105414- default_label:
105415- /* If we ever reach this, we have a bug somewhere. */
105416- WARN_RATELIMIT(1, "unknown opcode %02x\n", insn->code);
105417- return 0;
105418-}
105419-
105420-/* Helper to find the offset of pkt_type in sk_buff structure. We want
105421- * to make sure its still a 3bit field starting at a byte boundary;
105422- * taken from arch/x86/net/bpf_jit_comp.c.
105423- */
105424-#ifdef __BIG_ENDIAN_BITFIELD
105425-#define PKT_TYPE_MAX (7 << 5)
105426+ u32 A = 0; /* Accumulator */
105427+ u32 X = 0; /* Index Register */
105428+ u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
105429+ u32 tmp;
105430+ int k;
105431+
105432+ /*
105433+ * Process array of filter instructions.
105434+ */
105435+ for (;; fentry++) {
105436+#if defined(CONFIG_X86_32)
105437+#define K (fentry->k)
105438 #else
105439-#define PKT_TYPE_MAX 7
105440+ const u32 K = fentry->k;
105441 #endif
105442-static unsigned int pkt_type_offset(void)
105443-{
105444- struct sk_buff skb_probe = { .pkt_type = ~0, };
105445- u8 *ct = (u8 *) &skb_probe;
105446- unsigned int off;
105447
105448- for (off = 0; off < sizeof(struct sk_buff); off++) {
105449- if (ct[off] == PKT_TYPE_MAX)
105450- return off;
105451- }
105452-
105453- pr_err_once("Please fix %s, as pkt_type couldn't be found!\n", __func__);
105454- return -1;
105455-}
105456-
105457-static u64 __skb_get_pay_offset(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105458-{
105459- return __skb_get_poff((struct sk_buff *)(unsigned long) ctx);
105460-}
105461-
105462-static u64 __skb_get_nlattr(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105463-{
105464- struct sk_buff *skb = (struct sk_buff *)(unsigned long) ctx;
105465- struct nlattr *nla;
105466-
105467- if (skb_is_nonlinear(skb))
105468- return 0;
105469-
105470- if (skb->len < sizeof(struct nlattr))
105471- return 0;
105472-
105473- if (a > skb->len - sizeof(struct nlattr))
105474- return 0;
105475-
105476- nla = nla_find((struct nlattr *) &skb->data[a], skb->len - a, x);
105477- if (nla)
105478- return (void *) nla - (void *) skb->data;
105479-
105480- return 0;
105481-}
105482-
105483-static u64 __skb_get_nlattr_nest(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105484-{
105485- struct sk_buff *skb = (struct sk_buff *)(unsigned long) ctx;
105486- struct nlattr *nla;
105487-
105488- if (skb_is_nonlinear(skb))
105489- return 0;
105490-
105491- if (skb->len < sizeof(struct nlattr))
105492- return 0;
105493-
105494- if (a > skb->len - sizeof(struct nlattr))
105495- return 0;
105496-
105497- nla = (struct nlattr *) &skb->data[a];
105498- if (nla->nla_len > skb->len - a)
105499- return 0;
105500-
105501- nla = nla_find_nested(nla, x);
105502- if (nla)
105503- return (void *) nla - (void *) skb->data;
105504-
105505- return 0;
105506-}
105507-
105508-static u64 __get_raw_cpu_id(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105509-{
105510- return raw_smp_processor_id();
105511-}
105512-
105513-/* note that this only generates 32-bit random numbers */
105514-static u64 __get_random_u32(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105515-{
105516- return prandom_u32();
105517-}
105518-
105519-static bool convert_bpf_extensions(struct sock_filter *fp,
105520- struct sock_filter_int **insnp)
105521-{
105522- struct sock_filter_int *insn = *insnp;
105523-
105524- switch (fp->k) {
105525- case SKF_AD_OFF + SKF_AD_PROTOCOL:
105526- BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, protocol) != 2);
105527-
105528- /* A = *(u16 *) (CTX + offsetof(protocol)) */
105529- *insn++ = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_CTX,
105530- offsetof(struct sk_buff, protocol));
105531- /* A = ntohs(A) [emitting a nop or swap16] */
105532- *insn = BPF_ENDIAN(BPF_FROM_BE, BPF_REG_A, 16);
105533- break;
105534-
105535- case SKF_AD_OFF + SKF_AD_PKTTYPE:
105536- *insn = BPF_LDX_MEM(BPF_B, BPF_REG_A, BPF_REG_CTX,
105537- pkt_type_offset());
105538- if (insn->off < 0)
105539- return false;
105540- insn++;
105541- *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, PKT_TYPE_MAX);
105542-#ifdef __BIG_ENDIAN_BITFIELD
105543- insn++;
105544- *insn = BPF_ALU32_IMM(BPF_RSH, BPF_REG_A, 5);
105545-#endif
105546- break;
105547-
105548- case SKF_AD_OFF + SKF_AD_IFINDEX:
105549- case SKF_AD_OFF + SKF_AD_HATYPE:
105550- BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4);
105551- BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, type) != 2);
105552- BUILD_BUG_ON(bytes_to_bpf_size(FIELD_SIZEOF(struct sk_buff, dev)) < 0);
105553-
105554- *insn++ = BPF_LDX_MEM(bytes_to_bpf_size(FIELD_SIZEOF(struct sk_buff, dev)),
105555- BPF_REG_TMP, BPF_REG_CTX,
105556- offsetof(struct sk_buff, dev));
105557- /* if (tmp != 0) goto pc + 1 */
105558- *insn++ = BPF_JMP_IMM(BPF_JNE, BPF_REG_TMP, 0, 1);
105559- *insn++ = BPF_EXIT_INSN();
105560- if (fp->k == SKF_AD_OFF + SKF_AD_IFINDEX)
105561- *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_TMP,
105562- offsetof(struct net_device, ifindex));
105563- else
105564- *insn = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_TMP,
105565- offsetof(struct net_device, type));
105566- break;
105567-
105568- case SKF_AD_OFF + SKF_AD_MARK:
105569- BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, mark) != 4);
105570-
105571- *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_CTX,
105572- offsetof(struct sk_buff, mark));
105573- break;
105574-
105575- case SKF_AD_OFF + SKF_AD_RXHASH:
105576- BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, hash) != 4);
105577-
105578- *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_CTX,
105579- offsetof(struct sk_buff, hash));
105580- break;
105581-
105582- case SKF_AD_OFF + SKF_AD_QUEUE:
105583- BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, queue_mapping) != 2);
105584-
105585- *insn = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_CTX,
105586- offsetof(struct sk_buff, queue_mapping));
105587- break;
105588-
105589- case SKF_AD_OFF + SKF_AD_VLAN_TAG:
105590- case SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT:
105591- BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
105592- BUILD_BUG_ON(VLAN_TAG_PRESENT != 0x1000);
105593-
105594- /* A = *(u16 *) (CTX + offsetof(vlan_tci)) */
105595- *insn++ = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_CTX,
105596- offsetof(struct sk_buff, vlan_tci));
105597- if (fp->k == SKF_AD_OFF + SKF_AD_VLAN_TAG) {
105598- *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A,
105599- ~VLAN_TAG_PRESENT);
105600- } else {
105601- /* A >>= 12 */
105602- *insn++ = BPF_ALU32_IMM(BPF_RSH, BPF_REG_A, 12);
105603- /* A &= 1 */
105604- *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, 1);
105605- }
105606- break;
105607-
105608- case SKF_AD_OFF + SKF_AD_PAY_OFFSET:
105609- case SKF_AD_OFF + SKF_AD_NLATTR:
105610- case SKF_AD_OFF + SKF_AD_NLATTR_NEST:
105611- case SKF_AD_OFF + SKF_AD_CPU:
105612- case SKF_AD_OFF + SKF_AD_RANDOM:
105613- /* arg1 = CTX */
105614- *insn++ = BPF_MOV64_REG(BPF_REG_ARG1, BPF_REG_CTX);
105615- /* arg2 = A */
105616- *insn++ = BPF_MOV64_REG(BPF_REG_ARG2, BPF_REG_A);
105617- /* arg3 = X */
105618- *insn++ = BPF_MOV64_REG(BPF_REG_ARG3, BPF_REG_X);
105619- /* Emit call(arg1=CTX, arg2=A, arg3=X) */
105620- switch (fp->k) {
105621- case SKF_AD_OFF + SKF_AD_PAY_OFFSET:
105622- *insn = BPF_EMIT_CALL(__skb_get_pay_offset);
105623- break;
105624- case SKF_AD_OFF + SKF_AD_NLATTR:
105625- *insn = BPF_EMIT_CALL(__skb_get_nlattr);
105626- break;
105627- case SKF_AD_OFF + SKF_AD_NLATTR_NEST:
105628- *insn = BPF_EMIT_CALL(__skb_get_nlattr_nest);
105629- break;
105630- case SKF_AD_OFF + SKF_AD_CPU:
105631- *insn = BPF_EMIT_CALL(__get_raw_cpu_id);
105632- break;
105633- case SKF_AD_OFF + SKF_AD_RANDOM:
105634- *insn = BPF_EMIT_CALL(__get_random_u32);
105635- break;
105636- }
105637- break;
105638-
105639- case SKF_AD_OFF + SKF_AD_ALU_XOR_X:
105640- /* A ^= X */
105641- *insn = BPF_ALU32_REG(BPF_XOR, BPF_REG_A, BPF_REG_X);
105642- break;
105643-
105644- default:
105645- /* This is just a dummy call to avoid letting the compiler
105646- * evict __bpf_call_base() as an optimization. Placed here
105647- * where no-one bothers.
105648- */
105649- BUG_ON(__bpf_call_base(0, 0, 0, 0, 0) != 0);
105650- return false;
105651- }
105652-
105653- *insnp = insn;
105654- return true;
105655-}
105656-
105657-/**
105658- * sk_convert_filter - convert filter program
105659- * @prog: the user passed filter program
105660- * @len: the length of the user passed filter program
105661- * @new_prog: buffer where converted program will be stored
105662- * @new_len: pointer to store length of converted program
105663- *
105664- * Remap 'sock_filter' style BPF instruction set to 'sock_filter_ext' style.
105665- * Conversion workflow:
105666- *
105667- * 1) First pass for calculating the new program length:
105668- * sk_convert_filter(old_prog, old_len, NULL, &new_len)
105669- *
105670- * 2) 2nd pass to remap in two passes: 1st pass finds new
105671- * jump offsets, 2nd pass remapping:
105672- * new_prog = kmalloc(sizeof(struct sock_filter_int) * new_len);
105673- * sk_convert_filter(old_prog, old_len, new_prog, &new_len);
105674- *
105675- * User BPF's register A is mapped to our BPF register 6, user BPF
105676- * register X is mapped to BPF register 7; frame pointer is always
105677- * register 10; Context 'void *ctx' is stored in register 1, that is,
105678- * for socket filters: ctx == 'struct sk_buff *', for seccomp:
105679- * ctx == 'struct seccomp_data *'.
105680- */
105681-int sk_convert_filter(struct sock_filter *prog, int len,
105682- struct sock_filter_int *new_prog, int *new_len)
105683-{
105684- int new_flen = 0, pass = 0, target, i;
105685- struct sock_filter_int *new_insn;
105686- struct sock_filter *fp;
105687- int *addrs = NULL;
105688- u8 bpf_src;
105689-
105690- BUILD_BUG_ON(BPF_MEMWORDS * sizeof(u32) > MAX_BPF_STACK);
105691- BUILD_BUG_ON(BPF_REG_FP + 1 != MAX_BPF_REG);
105692-
105693- if (len <= 0 || len > BPF_MAXINSNS)
105694- return -EINVAL;
105695-
105696- if (new_prog) {
105697- addrs = kcalloc(len, sizeof(*addrs), GFP_KERNEL);
105698- if (!addrs)
105699- return -ENOMEM;
105700- }
105701-
105702-do_pass:
105703- new_insn = new_prog;
105704- fp = prog;
105705-
105706- if (new_insn)
105707- *new_insn = BPF_MOV64_REG(BPF_REG_CTX, BPF_REG_ARG1);
105708- new_insn++;
105709-
105710- for (i = 0; i < len; fp++, i++) {
105711- struct sock_filter_int tmp_insns[6] = { };
105712- struct sock_filter_int *insn = tmp_insns;
105713-
105714- if (addrs)
105715- addrs[i] = new_insn - new_prog;
105716-
105717- switch (fp->code) {
105718- /* All arithmetic insns and skb loads map as-is. */
105719- case BPF_ALU | BPF_ADD | BPF_X:
105720- case BPF_ALU | BPF_ADD | BPF_K:
105721- case BPF_ALU | BPF_SUB | BPF_X:
105722- case BPF_ALU | BPF_SUB | BPF_K:
105723- case BPF_ALU | BPF_AND | BPF_X:
105724- case BPF_ALU | BPF_AND | BPF_K:
105725- case BPF_ALU | BPF_OR | BPF_X:
105726- case BPF_ALU | BPF_OR | BPF_K:
105727- case BPF_ALU | BPF_LSH | BPF_X:
105728- case BPF_ALU | BPF_LSH | BPF_K:
105729- case BPF_ALU | BPF_RSH | BPF_X:
105730- case BPF_ALU | BPF_RSH | BPF_K:
105731- case BPF_ALU | BPF_XOR | BPF_X:
105732- case BPF_ALU | BPF_XOR | BPF_K:
105733- case BPF_ALU | BPF_MUL | BPF_X:
105734- case BPF_ALU | BPF_MUL | BPF_K:
105735- case BPF_ALU | BPF_DIV | BPF_X:
105736- case BPF_ALU | BPF_DIV | BPF_K:
105737- case BPF_ALU | BPF_MOD | BPF_X:
105738- case BPF_ALU | BPF_MOD | BPF_K:
105739- case BPF_ALU | BPF_NEG:
105740- case BPF_LD | BPF_ABS | BPF_W:
105741- case BPF_LD | BPF_ABS | BPF_H:
105742- case BPF_LD | BPF_ABS | BPF_B:
105743- case BPF_LD | BPF_IND | BPF_W:
105744- case BPF_LD | BPF_IND | BPF_H:
105745- case BPF_LD | BPF_IND | BPF_B:
105746- /* Check for overloaded BPF extension and
105747- * directly convert it if found, otherwise
105748- * just move on with mapping.
105749- */
105750- if (BPF_CLASS(fp->code) == BPF_LD &&
105751- BPF_MODE(fp->code) == BPF_ABS &&
105752- convert_bpf_extensions(fp, &insn))
105753- break;
105754-
105755- *insn = BPF_RAW_INSN(fp->code, BPF_REG_A, BPF_REG_X, 0, fp->k);
105756- break;
105757-
105758- /* Jump transformation cannot use BPF block macros
105759- * everywhere as offset calculation and target updates
105760- * require a bit more work than the rest, i.e. jump
105761- * opcodes map as-is, but offsets need adjustment.
105762- */
105763-
105764-#define BPF_EMIT_JMP \
105765- do { \
105766- if (target >= len || target < 0) \
105767- goto err; \
105768- insn->off = addrs ? addrs[target] - addrs[i] - 1 : 0; \
105769- /* Adjust pc relative offset for 2nd or 3rd insn. */ \
105770- insn->off -= insn - tmp_insns; \
105771- } while (0)
105772-
105773- case BPF_JMP | BPF_JA:
105774- target = i + fp->k + 1;
105775- insn->code = fp->code;
105776- BPF_EMIT_JMP;
105777- break;
105778-
105779- case BPF_JMP | BPF_JEQ | BPF_K:
105780- case BPF_JMP | BPF_JEQ | BPF_X:
105781- case BPF_JMP | BPF_JSET | BPF_K:
105782- case BPF_JMP | BPF_JSET | BPF_X:
105783- case BPF_JMP | BPF_JGT | BPF_K:
105784- case BPF_JMP | BPF_JGT | BPF_X:
105785- case BPF_JMP | BPF_JGE | BPF_K:
105786- case BPF_JMP | BPF_JGE | BPF_X:
105787- if (BPF_SRC(fp->code) == BPF_K && (int) fp->k < 0) {
105788- /* BPF immediates are signed, zero extend
105789- * immediate into tmp register and use it
105790- * in compare insn.
105791- */
105792- *insn++ = BPF_MOV32_IMM(BPF_REG_TMP, fp->k);
105793-
105794- insn->dst_reg = BPF_REG_A;
105795- insn->src_reg = BPF_REG_TMP;
105796- bpf_src = BPF_X;
105797- } else {
105798- insn->dst_reg = BPF_REG_A;
105799- insn->src_reg = BPF_REG_X;
105800- insn->imm = fp->k;
105801- bpf_src = BPF_SRC(fp->code);
105802+ switch (fentry->code) {
105803+ case BPF_S_ALU_ADD_X:
105804+ A += X;
105805+ continue;
105806+ case BPF_S_ALU_ADD_K:
105807+ A += K;
105808+ continue;
105809+ case BPF_S_ALU_SUB_X:
105810+ A -= X;
105811+ continue;
105812+ case BPF_S_ALU_SUB_K:
105813+ A -= K;
105814+ continue;
105815+ case BPF_S_ALU_MUL_X:
105816+ A *= X;
105817+ continue;
105818+ case BPF_S_ALU_MUL_K:
105819+ A *= K;
105820+ continue;
105821+ case BPF_S_ALU_DIV_X:
105822+ if (X == 0)
105823+ return 0;
105824+ A /= X;
105825+ continue;
105826+ case BPF_S_ALU_DIV_K:
105827+ A /= K;
105828+ continue;
105829+ case BPF_S_ALU_MOD_X:
105830+ if (X == 0)
105831+ return 0;
105832+ A %= X;
105833+ continue;
105834+ case BPF_S_ALU_MOD_K:
105835+ A %= K;
105836+ continue;
105837+ case BPF_S_ALU_AND_X:
105838+ A &= X;
105839+ continue;
105840+ case BPF_S_ALU_AND_K:
105841+ A &= K;
105842+ continue;
105843+ case BPF_S_ALU_OR_X:
105844+ A |= X;
105845+ continue;
105846+ case BPF_S_ALU_OR_K:
105847+ A |= K;
105848+ continue;
105849+ case BPF_S_ANC_ALU_XOR_X:
105850+ case BPF_S_ALU_XOR_X:
105851+ A ^= X;
105852+ continue;
105853+ case BPF_S_ALU_XOR_K:
105854+ A ^= K;
105855+ continue;
105856+ case BPF_S_ALU_LSH_X:
105857+ A <<= X;
105858+ continue;
105859+ case BPF_S_ALU_LSH_K:
105860+ A <<= K;
105861+ continue;
105862+ case BPF_S_ALU_RSH_X:
105863+ A >>= X;
105864+ continue;
105865+ case BPF_S_ALU_RSH_K:
105866+ A >>= K;
105867+ continue;
105868+ case BPF_S_ALU_NEG:
105869+ A = -A;
105870+ continue;
105871+ case BPF_S_JMP_JA:
105872+ fentry += K;
105873+ continue;
105874+ case BPF_S_JMP_JGT_K:
105875+ fentry += (A > K) ? fentry->jt : fentry->jf;
105876+ continue;
105877+ case BPF_S_JMP_JGE_K:
105878+ fentry += (A >= K) ? fentry->jt : fentry->jf;
105879+ continue;
105880+ case BPF_S_JMP_JEQ_K:
105881+ fentry += (A == K) ? fentry->jt : fentry->jf;
105882+ continue;
105883+ case BPF_S_JMP_JSET_K:
105884+ fentry += (A & K) ? fentry->jt : fentry->jf;
105885+ continue;
105886+ case BPF_S_JMP_JGT_X:
105887+ fentry += (A > X) ? fentry->jt : fentry->jf;
105888+ continue;
105889+ case BPF_S_JMP_JGE_X:
105890+ fentry += (A >= X) ? fentry->jt : fentry->jf;
105891+ continue;
105892+ case BPF_S_JMP_JEQ_X:
105893+ fentry += (A == X) ? fentry->jt : fentry->jf;
105894+ continue;
105895+ case BPF_S_JMP_JSET_X:
105896+ fentry += (A & X) ? fentry->jt : fentry->jf;
105897+ continue;
105898+ case BPF_S_LD_W_ABS:
105899+ k = K;
105900+load_w:
105901+ ptr = load_pointer(skb, k, 4, &tmp);
105902+ if (ptr != NULL) {
105903+ A = get_unaligned_be32(ptr);
105904+ continue;
105905 }
105906-
105907- /* Common case where 'jump_false' is next insn. */
105908- if (fp->jf == 0) {
105909- insn->code = BPF_JMP | BPF_OP(fp->code) | bpf_src;
105910- target = i + fp->jt + 1;
105911- BPF_EMIT_JMP;
105912- break;
105913+ return 0;
105914+ case BPF_S_LD_H_ABS:
105915+ k = K;
105916+load_h:
105917+ ptr = load_pointer(skb, k, 2, &tmp);
105918+ if (ptr != NULL) {
105919+ A = get_unaligned_be16(ptr);
105920+ continue;
105921 }
105922-
105923- /* Convert JEQ into JNE when 'jump_true' is next insn. */
105924- if (fp->jt == 0 && BPF_OP(fp->code) == BPF_JEQ) {
105925- insn->code = BPF_JMP | BPF_JNE | bpf_src;
105926- target = i + fp->jf + 1;
105927- BPF_EMIT_JMP;
105928- break;
105929+ return 0;
105930+ case BPF_S_LD_B_ABS:
105931+ k = K;
105932+load_b:
105933+ ptr = load_pointer(skb, k, 1, &tmp);
105934+ if (ptr != NULL) {
105935+ A = *(u8 *)ptr;
105936+ continue;
105937 }
105938-
105939- /* Other jumps are mapped into two insns: Jxx and JA. */
105940- target = i + fp->jt + 1;
105941- insn->code = BPF_JMP | BPF_OP(fp->code) | bpf_src;
105942- BPF_EMIT_JMP;
105943- insn++;
105944-
105945- insn->code = BPF_JMP | BPF_JA;
105946- target = i + fp->jf + 1;
105947- BPF_EMIT_JMP;
105948- break;
105949-
105950- /* ldxb 4 * ([14] & 0xf) is remaped into 6 insns. */
105951- case BPF_LDX | BPF_MSH | BPF_B:
105952- /* tmp = A */
105953- *insn++ = BPF_MOV64_REG(BPF_REG_TMP, BPF_REG_A);
105954- /* A = BPF_R0 = *(u8 *) (skb->data + K) */
105955- *insn++ = BPF_LD_ABS(BPF_B, fp->k);
105956- /* A &= 0xf */
105957- *insn++ = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, 0xf);
105958- /* A <<= 2 */
105959- *insn++ = BPF_ALU32_IMM(BPF_LSH, BPF_REG_A, 2);
105960- /* X = A */
105961- *insn++ = BPF_MOV64_REG(BPF_REG_X, BPF_REG_A);
105962- /* A = tmp */
105963- *insn = BPF_MOV64_REG(BPF_REG_A, BPF_REG_TMP);
105964- break;
105965-
105966- /* RET_K, RET_A are remaped into 2 insns. */
105967- case BPF_RET | BPF_A:
105968- case BPF_RET | BPF_K:
105969- *insn++ = BPF_MOV32_RAW(BPF_RVAL(fp->code) == BPF_K ?
105970- BPF_K : BPF_X, BPF_REG_0,
105971- BPF_REG_A, fp->k);
105972- *insn = BPF_EXIT_INSN();
105973- break;
105974-
105975- /* Store to stack. */
105976- case BPF_ST:
105977- case BPF_STX:
105978- *insn = BPF_STX_MEM(BPF_W, BPF_REG_FP, BPF_CLASS(fp->code) ==
105979- BPF_ST ? BPF_REG_A : BPF_REG_X,
105980- -(BPF_MEMWORDS - fp->k) * 4);
105981- break;
105982-
105983- /* Load from stack. */
105984- case BPF_LD | BPF_MEM:
105985- case BPF_LDX | BPF_MEM:
105986- *insn = BPF_LDX_MEM(BPF_W, BPF_CLASS(fp->code) == BPF_LD ?
105987- BPF_REG_A : BPF_REG_X, BPF_REG_FP,
105988- -(BPF_MEMWORDS - fp->k) * 4);
105989- break;
105990-
105991- /* A = K or X = K */
105992- case BPF_LD | BPF_IMM:
105993- case BPF_LDX | BPF_IMM:
105994- *insn = BPF_MOV32_IMM(BPF_CLASS(fp->code) == BPF_LD ?
105995- BPF_REG_A : BPF_REG_X, fp->k);
105996- break;
105997-
105998- /* X = A */
105999- case BPF_MISC | BPF_TAX:
106000- *insn = BPF_MOV64_REG(BPF_REG_X, BPF_REG_A);
106001- break;
106002-
106003- /* A = X */
106004- case BPF_MISC | BPF_TXA:
106005- *insn = BPF_MOV64_REG(BPF_REG_A, BPF_REG_X);
106006- break;
106007-
106008- /* A = skb->len or X = skb->len */
106009- case BPF_LD | BPF_W | BPF_LEN:
106010- case BPF_LDX | BPF_W | BPF_LEN:
106011- *insn = BPF_LDX_MEM(BPF_W, BPF_CLASS(fp->code) == BPF_LD ?
106012- BPF_REG_A : BPF_REG_X, BPF_REG_CTX,
106013- offsetof(struct sk_buff, len));
106014- break;
106015-
106016- /* Access seccomp_data fields. */
106017- case BPF_LDX | BPF_ABS | BPF_W:
106018- /* A = *(u32 *) (ctx + K) */
106019- *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_CTX, fp->k);
106020- break;
106021-
106022- /* Unkown instruction. */
106023+ return 0;
106024+ case BPF_S_LD_W_LEN:
106025+ A = skb->len;
106026+ continue;
106027+ case BPF_S_LDX_W_LEN:
106028+ X = skb->len;
106029+ continue;
106030+ case BPF_S_LD_W_IND:
106031+ k = X + K;
106032+ goto load_w;
106033+ case BPF_S_LD_H_IND:
106034+ k = X + K;
106035+ goto load_h;
106036+ case BPF_S_LD_B_IND:
106037+ k = X + K;
106038+ goto load_b;
106039+ case BPF_S_LDX_B_MSH:
106040+ ptr = load_pointer(skb, K, 1, &tmp);
106041+ if (ptr != NULL) {
106042+ X = (*(u8 *)ptr & 0xf) << 2;
106043+ continue;
106044+ }
106045+ return 0;
106046+ case BPF_S_LD_IMM:
106047+ A = K;
106048+ continue;
106049+ case BPF_S_LDX_IMM:
106050+ X = K;
106051+ continue;
106052+ case BPF_S_LD_MEM:
106053+ A = mem[K&15];
106054+ continue;
106055+ case BPF_S_LDX_MEM:
106056+ X = mem[K&15];
106057+ continue;
106058+ case BPF_S_MISC_TAX:
106059+ X = A;
106060+ continue;
106061+ case BPF_S_MISC_TXA:
106062+ A = X;
106063+ continue;
106064+ case BPF_S_RET_K:
106065+ return K;
106066+ case BPF_S_RET_A:
106067+ return A;
106068+ case BPF_S_ST:
106069+ mem[K&15] = A;
106070+ continue;
106071+ case BPF_S_STX:
106072+ mem[K&15] = X;
106073+ continue;
106074+ case BPF_S_ANC_PROTOCOL:
106075+ A = ntohs(skb->protocol);
106076+ continue;
106077+ case BPF_S_ANC_PKTTYPE:
106078+ A = skb->pkt_type;
106079+ continue;
106080+ case BPF_S_ANC_IFINDEX:
106081+ if (!skb->dev)
106082+ return 0;
106083+ A = skb->dev->ifindex;
106084+ continue;
106085+ case BPF_S_ANC_MARK:
106086+ A = skb->mark;
106087+ continue;
106088+ case BPF_S_ANC_QUEUE:
106089+ A = skb->queue_mapping;
106090+ continue;
106091+ case BPF_S_ANC_HATYPE:
106092+ if (!skb->dev)
106093+ return 0;
106094+ A = skb->dev->type;
106095+ continue;
106096+ case BPF_S_ANC_RXHASH:
106097+ A = skb->hash;
106098+ continue;
106099+ case BPF_S_ANC_CPU:
106100+ A = raw_smp_processor_id();
106101+ continue;
106102+ case BPF_S_ANC_VLAN_TAG:
106103+ A = vlan_tx_tag_get(skb);
106104+ continue;
106105+ case BPF_S_ANC_VLAN_TAG_PRESENT:
106106+ A = !!vlan_tx_tag_present(skb);
106107+ continue;
106108+ case BPF_S_ANC_PAY_OFFSET:
106109+ A = __skb_get_poff(skb);
106110+ continue;
106111+ case BPF_S_ANC_NLATTR: {
106112+ struct nlattr *nla;
106113+
106114+ if (skb_is_nonlinear(skb))
106115+ return 0;
106116+ if (skb->len < sizeof(struct nlattr))
106117+ return 0;
106118+ if (A > skb->len - sizeof(struct nlattr))
106119+ return 0;
106120+
106121+ nla = nla_find((struct nlattr *)&skb->data[A],
106122+ skb->len - A, X);
106123+ if (nla)
106124+ A = (void *)nla - (void *)skb->data;
106125+ else
106126+ A = 0;
106127+ continue;
106128+ }
106129+ case BPF_S_ANC_NLATTR_NEST: {
106130+ struct nlattr *nla;
106131+
106132+ if (skb_is_nonlinear(skb))
106133+ return 0;
106134+ if (skb->len < sizeof(struct nlattr))
106135+ return 0;
106136+ if (A > skb->len - sizeof(struct nlattr))
106137+ return 0;
106138+
106139+ nla = (struct nlattr *)&skb->data[A];
106140+ if (nla->nla_len > skb->len - A)
106141+ return 0;
106142+
106143+ nla = nla_find_nested(nla, X);
106144+ if (nla)
106145+ A = (void *)nla - (void *)skb->data;
106146+ else
106147+ A = 0;
106148+ continue;
106149+ }
106150+#ifdef CONFIG_SECCOMP_FILTER
106151+ case BPF_S_ANC_SECCOMP_LD_W:
106152+ A = seccomp_bpf_load(fentry->k);
106153+ continue;
106154+#endif
106155 default:
106156- goto err;
106157+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
106158+ fentry->code, fentry->jt,
106159+ fentry->jf, fentry->k);
106160+ BUG();
106161+ return 0;
106162 }
106163-
106164- insn++;
106165- if (new_prog)
106166- memcpy(new_insn, tmp_insns,
106167- sizeof(*insn) * (insn - tmp_insns));
106168- new_insn += insn - tmp_insns;
106169- }
106170-
106171- if (!new_prog) {
106172- /* Only calculating new length. */
106173- *new_len = new_insn - new_prog;
106174- return 0;
106175- }
106176-
106177- pass++;
106178- if (new_flen != new_insn - new_prog) {
106179- new_flen = new_insn - new_prog;
106180- if (pass > 2)
106181- goto err;
106182- goto do_pass;
106183 }
106184
106185- kfree(addrs);
106186- BUG_ON(*new_len != new_flen);
106187 return 0;
106188-err:
106189- kfree(addrs);
106190- return -EINVAL;
106191 }
106192+EXPORT_SYMBOL(sk_run_filter);
106193
106194-/* Security:
106195- *
106196+/*
106197+ * Security :
106198 * A BPF program is able to use 16 cells of memory to store intermediate
106199- * values (check u32 mem[BPF_MEMWORDS] in sk_run_filter()).
106200- *
106201+ * values (check u32 mem[BPF_MEMWORDS] in sk_run_filter())
106202 * As we dont want to clear mem[] array for each packet going through
106203 * sk_run_filter(), we check that filter loaded by user never try to read
106204 * a cell if not previously written, and we check all branches to be sure
106205@@ -1096,46 +418,44 @@ err:
106206 */
106207 static int check_load_and_stores(struct sock_filter *filter, int flen)
106208 {
106209- u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
106210+ u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
106211 int pc, ret = 0;
106212
106213- BUILD_BUG_ON(BPF_MEMWORDS > 16);
106214-
106215- masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
106216+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
106217+ masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
106218 if (!masks)
106219 return -ENOMEM;
106220-
106221 memset(masks, 0xff, flen * sizeof(*masks));
106222
106223 for (pc = 0; pc < flen; pc++) {
106224 memvalid &= masks[pc];
106225
106226 switch (filter[pc].code) {
106227- case BPF_ST:
106228- case BPF_STX:
106229+ case BPF_S_ST:
106230+ case BPF_S_STX:
106231 memvalid |= (1 << filter[pc].k);
106232 break;
106233- case BPF_LD | BPF_MEM:
106234- case BPF_LDX | BPF_MEM:
106235+ case BPF_S_LD_MEM:
106236+ case BPF_S_LDX_MEM:
106237 if (!(memvalid & (1 << filter[pc].k))) {
106238 ret = -EINVAL;
106239 goto error;
106240 }
106241 break;
106242- case BPF_JMP | BPF_JA:
106243- /* A jump must set masks on target */
106244+ case BPF_S_JMP_JA:
106245+ /* a jump must set masks on target */
106246 masks[pc + 1 + filter[pc].k] &= memvalid;
106247 memvalid = ~0;
106248 break;
106249- case BPF_JMP | BPF_JEQ | BPF_K:
106250- case BPF_JMP | BPF_JEQ | BPF_X:
106251- case BPF_JMP | BPF_JGE | BPF_K:
106252- case BPF_JMP | BPF_JGE | BPF_X:
106253- case BPF_JMP | BPF_JGT | BPF_K:
106254- case BPF_JMP | BPF_JGT | BPF_X:
106255- case BPF_JMP | BPF_JSET | BPF_K:
106256- case BPF_JMP | BPF_JSET | BPF_X:
106257- /* A jump must set masks on targets */
106258+ case BPF_S_JMP_JEQ_K:
106259+ case BPF_S_JMP_JEQ_X:
106260+ case BPF_S_JMP_JGE_K:
106261+ case BPF_S_JMP_JGE_X:
106262+ case BPF_S_JMP_JGT_K:
106263+ case BPF_S_JMP_JGT_X:
106264+ case BPF_S_JMP_JSET_X:
106265+ case BPF_S_JMP_JSET_K:
106266+ /* a jump must set masks on targets */
106267 masks[pc + 1 + filter[pc].jt] &= memvalid;
106268 masks[pc + 1 + filter[pc].jf] &= memvalid;
106269 memvalid = ~0;
106270@@ -1147,72 +467,6 @@ error:
106271 return ret;
106272 }
106273
106274-static bool chk_code_allowed(u16 code_to_probe)
106275-{
106276- static const bool codes[] = {
106277- /* 32 bit ALU operations */
106278- [BPF_ALU | BPF_ADD | BPF_K] = true,
106279- [BPF_ALU | BPF_ADD | BPF_X] = true,
106280- [BPF_ALU | BPF_SUB | BPF_K] = true,
106281- [BPF_ALU | BPF_SUB | BPF_X] = true,
106282- [BPF_ALU | BPF_MUL | BPF_K] = true,
106283- [BPF_ALU | BPF_MUL | BPF_X] = true,
106284- [BPF_ALU | BPF_DIV | BPF_K] = true,
106285- [BPF_ALU | BPF_DIV | BPF_X] = true,
106286- [BPF_ALU | BPF_MOD | BPF_K] = true,
106287- [BPF_ALU | BPF_MOD | BPF_X] = true,
106288- [BPF_ALU | BPF_AND | BPF_K] = true,
106289- [BPF_ALU | BPF_AND | BPF_X] = true,
106290- [BPF_ALU | BPF_OR | BPF_K] = true,
106291- [BPF_ALU | BPF_OR | BPF_X] = true,
106292- [BPF_ALU | BPF_XOR | BPF_K] = true,
106293- [BPF_ALU | BPF_XOR | BPF_X] = true,
106294- [BPF_ALU | BPF_LSH | BPF_K] = true,
106295- [BPF_ALU | BPF_LSH | BPF_X] = true,
106296- [BPF_ALU | BPF_RSH | BPF_K] = true,
106297- [BPF_ALU | BPF_RSH | BPF_X] = true,
106298- [BPF_ALU | BPF_NEG] = true,
106299- /* Load instructions */
106300- [BPF_LD | BPF_W | BPF_ABS] = true,
106301- [BPF_LD | BPF_H | BPF_ABS] = true,
106302- [BPF_LD | BPF_B | BPF_ABS] = true,
106303- [BPF_LD | BPF_W | BPF_LEN] = true,
106304- [BPF_LD | BPF_W | BPF_IND] = true,
106305- [BPF_LD | BPF_H | BPF_IND] = true,
106306- [BPF_LD | BPF_B | BPF_IND] = true,
106307- [BPF_LD | BPF_IMM] = true,
106308- [BPF_LD | BPF_MEM] = true,
106309- [BPF_LDX | BPF_W | BPF_LEN] = true,
106310- [BPF_LDX | BPF_B | BPF_MSH] = true,
106311- [BPF_LDX | BPF_IMM] = true,
106312- [BPF_LDX | BPF_MEM] = true,
106313- /* Store instructions */
106314- [BPF_ST] = true,
106315- [BPF_STX] = true,
106316- /* Misc instructions */
106317- [BPF_MISC | BPF_TAX] = true,
106318- [BPF_MISC | BPF_TXA] = true,
106319- /* Return instructions */
106320- [BPF_RET | BPF_K] = true,
106321- [BPF_RET | BPF_A] = true,
106322- /* Jump instructions */
106323- [BPF_JMP | BPF_JA] = true,
106324- [BPF_JMP | BPF_JEQ | BPF_K] = true,
106325- [BPF_JMP | BPF_JEQ | BPF_X] = true,
106326- [BPF_JMP | BPF_JGE | BPF_K] = true,
106327- [BPF_JMP | BPF_JGE | BPF_X] = true,
106328- [BPF_JMP | BPF_JGT | BPF_K] = true,
106329- [BPF_JMP | BPF_JGT | BPF_X] = true,
106330- [BPF_JMP | BPF_JSET | BPF_K] = true,
106331- [BPF_JMP | BPF_JSET | BPF_X] = true,
106332- };
106333-
106334- if (code_to_probe >= ARRAY_SIZE(codes))
106335- return false;
106336-
106337- return codes[code_to_probe];
106338-}
106339-
106340 /**
106341 * sk_chk_filter - verify socket filter code
106342 * @filter: filter to verify
106343@@ -1229,303 +483,187 @@ static bool chk_code_allowed(u16 code_to_probe)
106344 */
106345 int sk_chk_filter(struct sock_filter *filter, unsigned int flen)
106346 {
106347- bool anc_found;
106348+ /*
106349+ * Valid instructions are initialized to non-0.
106350+ * Invalid instructions are initialized to 0.
106351+ */
106352+ static const u8 codes[] = {
106353+ [BPF_ALU|BPF_ADD|BPF_K] = BPF_S_ALU_ADD_K,
106354+ [BPF_ALU|BPF_ADD|BPF_X] = BPF_S_ALU_ADD_X,
106355+ [BPF_ALU|BPF_SUB|BPF_K] = BPF_S_ALU_SUB_K,
106356+ [BPF_ALU|BPF_SUB|BPF_X] = BPF_S_ALU_SUB_X,
106357+ [BPF_ALU|BPF_MUL|BPF_K] = BPF_S_ALU_MUL_K,
106358+ [BPF_ALU|BPF_MUL|BPF_X] = BPF_S_ALU_MUL_X,
106359+ [BPF_ALU|BPF_DIV|BPF_X] = BPF_S_ALU_DIV_X,
106360+ [BPF_ALU|BPF_MOD|BPF_K] = BPF_S_ALU_MOD_K,
106361+ [BPF_ALU|BPF_MOD|BPF_X] = BPF_S_ALU_MOD_X,
106362+ [BPF_ALU|BPF_AND|BPF_K] = BPF_S_ALU_AND_K,
106363+ [BPF_ALU|BPF_AND|BPF_X] = BPF_S_ALU_AND_X,
106364+ [BPF_ALU|BPF_OR|BPF_K] = BPF_S_ALU_OR_K,
106365+ [BPF_ALU|BPF_OR|BPF_X] = BPF_S_ALU_OR_X,
106366+ [BPF_ALU|BPF_XOR|BPF_K] = BPF_S_ALU_XOR_K,
106367+ [BPF_ALU|BPF_XOR|BPF_X] = BPF_S_ALU_XOR_X,
106368+ [BPF_ALU|BPF_LSH|BPF_K] = BPF_S_ALU_LSH_K,
106369+ [BPF_ALU|BPF_LSH|BPF_X] = BPF_S_ALU_LSH_X,
106370+ [BPF_ALU|BPF_RSH|BPF_K] = BPF_S_ALU_RSH_K,
106371+ [BPF_ALU|BPF_RSH|BPF_X] = BPF_S_ALU_RSH_X,
106372+ [BPF_ALU|BPF_NEG] = BPF_S_ALU_NEG,
106373+ [BPF_LD|BPF_W|BPF_ABS] = BPF_S_LD_W_ABS,
106374+ [BPF_LD|BPF_H|BPF_ABS] = BPF_S_LD_H_ABS,
106375+ [BPF_LD|BPF_B|BPF_ABS] = BPF_S_LD_B_ABS,
106376+ [BPF_LD|BPF_W|BPF_LEN] = BPF_S_LD_W_LEN,
106377+ [BPF_LD|BPF_W|BPF_IND] = BPF_S_LD_W_IND,
106378+ [BPF_LD|BPF_H|BPF_IND] = BPF_S_LD_H_IND,
106379+ [BPF_LD|BPF_B|BPF_IND] = BPF_S_LD_B_IND,
106380+ [BPF_LD|BPF_IMM] = BPF_S_LD_IMM,
106381+ [BPF_LDX|BPF_W|BPF_LEN] = BPF_S_LDX_W_LEN,
106382+ [BPF_LDX|BPF_B|BPF_MSH] = BPF_S_LDX_B_MSH,
106383+ [BPF_LDX|BPF_IMM] = BPF_S_LDX_IMM,
106384+ [BPF_MISC|BPF_TAX] = BPF_S_MISC_TAX,
106385+ [BPF_MISC|BPF_TXA] = BPF_S_MISC_TXA,
106386+ [BPF_RET|BPF_K] = BPF_S_RET_K,
106387+ [BPF_RET|BPF_A] = BPF_S_RET_A,
106388+ [BPF_ALU|BPF_DIV|BPF_K] = BPF_S_ALU_DIV_K,
106389+ [BPF_LD|BPF_MEM] = BPF_S_LD_MEM,
106390+ [BPF_LDX|BPF_MEM] = BPF_S_LDX_MEM,
106391+ [BPF_ST] = BPF_S_ST,
106392+ [BPF_STX] = BPF_S_STX,
106393+ [BPF_JMP|BPF_JA] = BPF_S_JMP_JA,
106394+ [BPF_JMP|BPF_JEQ|BPF_K] = BPF_S_JMP_JEQ_K,
106395+ [BPF_JMP|BPF_JEQ|BPF_X] = BPF_S_JMP_JEQ_X,
106396+ [BPF_JMP|BPF_JGE|BPF_K] = BPF_S_JMP_JGE_K,
106397+ [BPF_JMP|BPF_JGE|BPF_X] = BPF_S_JMP_JGE_X,
106398+ [BPF_JMP|BPF_JGT|BPF_K] = BPF_S_JMP_JGT_K,
106399+ [BPF_JMP|BPF_JGT|BPF_X] = BPF_S_JMP_JGT_X,
106400+ [BPF_JMP|BPF_JSET|BPF_K] = BPF_S_JMP_JSET_K,
106401+ [BPF_JMP|BPF_JSET|BPF_X] = BPF_S_JMP_JSET_X,
106402+ };
106403 int pc;
106404+ bool anc_found;
106405
106406 if (flen == 0 || flen > BPF_MAXINSNS)
106407 return -EINVAL;
106408
106409- /* Check the filter code now */
106410+ /* check the filter code now */
106411 for (pc = 0; pc < flen; pc++) {
106412 struct sock_filter *ftest = &filter[pc];
106413+ u16 code = ftest->code;
106414
106415- /* May we actually operate on this code? */
106416- if (!chk_code_allowed(ftest->code))
106417+ if (code >= ARRAY_SIZE(codes))
106418+ return -EINVAL;
106419+ code = codes[code];
106420+ if (!code)
106421 return -EINVAL;
106422-
106423 /* Some instructions need special checks */
106424- switch (ftest->code) {
106425- case BPF_ALU | BPF_DIV | BPF_K:
106426- case BPF_ALU | BPF_MOD | BPF_K:
106427- /* Check for division by zero */
106428+ switch (code) {
106429+ case BPF_S_ALU_DIV_K:
106430+ case BPF_S_ALU_MOD_K:
106431+ /* check for division by zero */
106432 if (ftest->k == 0)
106433 return -EINVAL;
106434 break;
106435- case BPF_LD | BPF_MEM:
106436- case BPF_LDX | BPF_MEM:
106437- case BPF_ST:
106438- case BPF_STX:
106439- /* Check for invalid memory addresses */
106440+ case BPF_S_LD_MEM:
106441+ case BPF_S_LDX_MEM:
106442+ case BPF_S_ST:
106443+ case BPF_S_STX:
106444+ /* check for invalid memory addresses */
106445 if (ftest->k >= BPF_MEMWORDS)
106446 return -EINVAL;
106447 break;
106448- case BPF_JMP | BPF_JA:
106449- /* Note, the large ftest->k might cause loops.
106450+ case BPF_S_JMP_JA:
106451+ /*
106452+ * Note, the large ftest->k might cause loops.
106453 * Compare this with conditional jumps below,
106454 * where offsets are limited. --ANK (981016)
106455 */
106456- if (ftest->k >= (unsigned int)(flen - pc - 1))
106457+ if (ftest->k >= (unsigned int)(flen-pc-1))
106458 return -EINVAL;
106459 break;
106460- case BPF_JMP | BPF_JEQ | BPF_K:
106461- case BPF_JMP | BPF_JEQ | BPF_X:
106462- case BPF_JMP | BPF_JGE | BPF_K:
106463- case BPF_JMP | BPF_JGE | BPF_X:
106464- case BPF_JMP | BPF_JGT | BPF_K:
106465- case BPF_JMP | BPF_JGT | BPF_X:
106466- case BPF_JMP | BPF_JSET | BPF_K:
106467- case BPF_JMP | BPF_JSET | BPF_X:
106468- /* Both conditionals must be safe */
106469+ case BPF_S_JMP_JEQ_K:
106470+ case BPF_S_JMP_JEQ_X:
106471+ case BPF_S_JMP_JGE_K:
106472+ case BPF_S_JMP_JGE_X:
106473+ case BPF_S_JMP_JGT_K:
106474+ case BPF_S_JMP_JGT_X:
106475+ case BPF_S_JMP_JSET_X:
106476+ case BPF_S_JMP_JSET_K:
106477+ /* for conditionals both must be safe */
106478 if (pc + ftest->jt + 1 >= flen ||
106479 pc + ftest->jf + 1 >= flen)
106480 return -EINVAL;
106481 break;
106482- case BPF_LD | BPF_W | BPF_ABS:
106483- case BPF_LD | BPF_H | BPF_ABS:
106484- case BPF_LD | BPF_B | BPF_ABS:
106485+ case BPF_S_LD_W_ABS:
106486+ case BPF_S_LD_H_ABS:
106487+ case BPF_S_LD_B_ABS:
106488 anc_found = false;
106489- if (bpf_anc_helper(ftest) & BPF_ANC)
106490- anc_found = true;
106491- /* Ancillary operation unknown or unsupported */
106492+#define ANCILLARY(CODE) case SKF_AD_OFF + SKF_AD_##CODE: \
106493+ code = BPF_S_ANC_##CODE; \
106494+ anc_found = true; \
106495+ break
106496+ switch (ftest->k) {
106497+ ANCILLARY(PROTOCOL);
106498+ ANCILLARY(PKTTYPE);
106499+ ANCILLARY(IFINDEX);
106500+ ANCILLARY(NLATTR);
106501+ ANCILLARY(NLATTR_NEST);
106502+ ANCILLARY(MARK);
106503+ ANCILLARY(QUEUE);
106504+ ANCILLARY(HATYPE);
106505+ ANCILLARY(RXHASH);
106506+ ANCILLARY(CPU);
106507+ ANCILLARY(ALU_XOR_X);
106508+ ANCILLARY(VLAN_TAG);
106509+ ANCILLARY(VLAN_TAG_PRESENT);
106510+ ANCILLARY(PAY_OFFSET);
106511+ }
106512+
106513+ /* ancillary operation unknown or unsupported */
106514 if (anc_found == false && ftest->k >= SKF_AD_OFF)
106515 return -EINVAL;
106516 }
106517+ ftest->code = code;
106518 }
106519
106520- /* Last instruction must be a RET code */
106521+ /* last instruction must be a RET code */
106522 switch (filter[flen - 1].code) {
106523- case BPF_RET | BPF_K:
106524- case BPF_RET | BPF_A:
106525+ case BPF_S_RET_K:
106526+ case BPF_S_RET_A:
106527 return check_load_and_stores(filter, flen);
106528 }
106529-
106530 return -EINVAL;
106531 }
106532 EXPORT_SYMBOL(sk_chk_filter);
106533
106534-static int sk_store_orig_filter(struct sk_filter *fp,
106535- const struct sock_fprog *fprog)
106536-{
106537- unsigned int fsize = sk_filter_proglen(fprog);
106538- struct sock_fprog_kern *fkprog;
106539-
106540- fp->orig_prog = kmalloc(sizeof(*fkprog), GFP_KERNEL);
106541- if (!fp->orig_prog)
106542- return -ENOMEM;
106543-
106544- fkprog = fp->orig_prog;
106545- fkprog->len = fprog->len;
106546- fkprog->filter = kmemdup(fp->insns, fsize, GFP_KERNEL);
106547- if (!fkprog->filter) {
106548- kfree(fp->orig_prog);
106549- return -ENOMEM;
106550- }
106551-
106552- return 0;
106553-}
106554-
106555-static void sk_release_orig_filter(struct sk_filter *fp)
106556-{
106557- struct sock_fprog_kern *fprog = fp->orig_prog;
106558-
106559- if (fprog) {
106560- kfree(fprog->filter);
106561- kfree(fprog);
106562- }
106563-}
106564-
106565 /**
106566 * sk_filter_release_rcu - Release a socket filter by rcu_head
106567 * @rcu: rcu_head that contains the sk_filter to free
106568 */
106569-static void sk_filter_release_rcu(struct rcu_head *rcu)
106570+void sk_filter_release_rcu(struct rcu_head *rcu)
106571 {
106572 struct sk_filter *fp = container_of(rcu, struct sk_filter, rcu);
106573
106574- sk_release_orig_filter(fp);
106575- sk_filter_free(fp);
106576-}
106577-
106578-/**
106579- * sk_filter_release - release a socket filter
106580- * @fp: filter to remove
106581- *
106582- * Remove a filter from a socket and release its resources.
106583- */
106584-static void sk_filter_release(struct sk_filter *fp)
106585-{
106586- if (atomic_dec_and_test(&fp->refcnt))
106587- call_rcu(&fp->rcu, sk_filter_release_rcu);
106588-}
106589-
106590-void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp)
106591-{
106592- atomic_sub(sk_filter_size(fp->len), &sk->sk_omem_alloc);
106593- sk_filter_release(fp);
106594-}
106595-
106596-void sk_filter_charge(struct sock *sk, struct sk_filter *fp)
106597-{
106598- atomic_inc(&fp->refcnt);
106599- atomic_add(sk_filter_size(fp->len), &sk->sk_omem_alloc);
106600-}
106601-
106602-static struct sk_filter *__sk_migrate_realloc(struct sk_filter *fp,
106603- struct sock *sk,
106604- unsigned int len)
106605-{
106606- struct sk_filter *fp_new;
106607-
106608- if (sk == NULL)
106609- return krealloc(fp, len, GFP_KERNEL);
106610-
106611- fp_new = sock_kmalloc(sk, len, GFP_KERNEL);
106612- if (fp_new) {
106613- *fp_new = *fp;
106614- /* As we're keeping orig_prog in fp_new along,
106615- * we need to make sure we're not evicting it
106616- * from the old fp.
106617- */
106618- fp->orig_prog = NULL;
106619- sk_filter_uncharge(sk, fp);
106620- }
106621-
106622- return fp_new;
106623-}
106624-
106625-static struct sk_filter *__sk_migrate_filter(struct sk_filter *fp,
106626- struct sock *sk)
106627-{
106628- struct sock_filter *old_prog;
106629- struct sk_filter *old_fp;
106630- int err, new_len, old_len = fp->len;
106631-
106632- /* We are free to overwrite insns et al right here as it
106633- * won't be used at this point in time anymore internally
106634- * after the migration to the internal BPF instruction
106635- * representation.
106636- */
106637- BUILD_BUG_ON(sizeof(struct sock_filter) !=
106638- sizeof(struct sock_filter_int));
106639-
106640- /* Conversion cannot happen on overlapping memory areas,
106641- * so we need to keep the user BPF around until the 2nd
106642- * pass. At this time, the user BPF is stored in fp->insns.
106643- */
106644- old_prog = kmemdup(fp->insns, old_len * sizeof(struct sock_filter),
106645- GFP_KERNEL);
106646- if (!old_prog) {
106647- err = -ENOMEM;
106648- goto out_err;
106649- }
106650-
106651- /* 1st pass: calculate the new program length. */
106652- err = sk_convert_filter(old_prog, old_len, NULL, &new_len);
106653- if (err)
106654- goto out_err_free;
106655-
106656- /* Expand fp for appending the new filter representation. */
106657- old_fp = fp;
106658- fp = __sk_migrate_realloc(old_fp, sk, sk_filter_size(new_len));
106659- if (!fp) {
106660- /* The old_fp is still around in case we couldn't
106661- * allocate new memory, so uncharge on that one.
106662- */
106663- fp = old_fp;
106664- err = -ENOMEM;
106665- goto out_err_free;
106666- }
106667-
106668- fp->len = new_len;
106669-
106670- /* 2nd pass: remap sock_filter insns into sock_filter_int insns. */
106671- err = sk_convert_filter(old_prog, old_len, fp->insnsi, &new_len);
106672- if (err)
106673- /* 2nd sk_convert_filter() can fail only if it fails
106674- * to allocate memory, remapping must succeed. Note,
106675- * that at this time old_fp has already been released
106676- * by __sk_migrate_realloc().
106677- */
106678- goto out_err_free;
106679-
106680- sk_filter_select_runtime(fp);
106681-
106682- kfree(old_prog);
106683- return fp;
106684-
106685-out_err_free:
106686- kfree(old_prog);
106687-out_err:
106688- /* Rollback filter setup. */
106689- if (sk != NULL)
106690- sk_filter_uncharge(sk, fp);
106691- else
106692- kfree(fp);
106693- return ERR_PTR(err);
106694-}
106695-
106696-void __weak bpf_int_jit_compile(struct sk_filter *prog)
106697-{
106698-}
106699-
106700-/**
106701- * sk_filter_select_runtime - select execution runtime for BPF program
106702- * @fp: sk_filter populated with internal BPF program
106703- *
106704- * try to JIT internal BPF program, if JIT is not available select interpreter
106705- * BPF program will be executed via SK_RUN_FILTER() macro
106706- */
106707-void sk_filter_select_runtime(struct sk_filter *fp)
106708-{
106709- fp->bpf_func = (void *) __sk_run_filter;
106710-
106711- /* Probe if internal BPF can be JITed */
106712- bpf_int_jit_compile(fp);
106713-}
106714-EXPORT_SYMBOL_GPL(sk_filter_select_runtime);
106715-
106716-/* free internal BPF program */
106717-void sk_filter_free(struct sk_filter *fp)
106718-{
106719 bpf_jit_free(fp);
106720 }
106721-EXPORT_SYMBOL_GPL(sk_filter_free);
106722+EXPORT_SYMBOL(sk_filter_release_rcu);
106723
106724-static struct sk_filter *__sk_prepare_filter(struct sk_filter *fp,
106725- struct sock *sk)
106726+static int __sk_prepare_filter(struct sk_filter *fp)
106727 {
106728 int err;
106729
106730- fp->bpf_func = NULL;
106731- fp->jited = 0;
106732+ fp->bpf_func = sk_run_filter;
106733
106734 err = sk_chk_filter(fp->insns, fp->len);
106735- if (err) {
106736- if (sk != NULL)
106737- sk_filter_uncharge(sk, fp);
106738- else
106739- kfree(fp);
106740- return ERR_PTR(err);
106741- }
106742+ if (err)
106743+ return err;
106744
106745- /* Probe if we can JIT compile the filter and if so, do
106746- * the compilation of the filter.
106747- */
106748 bpf_jit_compile(fp);
106749-
106750- /* JIT compiler couldn't process this filter, so do the
106751- * internal BPF translation for the optimized interpreter.
106752- */
106753- if (!fp->jited)
106754- fp = __sk_migrate_filter(fp, sk);
106755-
106756- return fp;
106757+ return 0;
106758 }
106759
106760 /**
106761 * sk_unattached_filter_create - create an unattached filter
106762+ * @fprog: the filter program
106763 * @pfp: the unattached filter that is created
106764- * @fprog: the filter program
106765 *
106766 * Create a filter independent of any socket. We first run some
106767 * sanity checks on it to make sure it does not explode on us later.
106768@@ -1533,10 +671,11 @@ static struct sk_filter *__sk_prepare_filter(struct sk_filter *fp,
106769 * a negative errno code is returned. On success the return is zero.
106770 */
106771 int sk_unattached_filter_create(struct sk_filter **pfp,
106772- struct sock_fprog_kern *fprog)
106773+ struct sock_fprog *fprog)
106774 {
106775- unsigned int fsize = sk_filter_proglen(fprog);
106776 struct sk_filter *fp;
106777+ unsigned int fsize = sizeof(struct sock_filter) * fprog->len;
106778+ int err;
106779
106780 /* Make sure new filter is there and in the right amounts. */
106781 if (fprog->filter == NULL)
106782@@ -1545,26 +684,20 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
106783 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
106784 if (!fp)
106785 return -ENOMEM;
106786-
106787- memcpy(fp->insns, fprog->filter, fsize);
106788+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
106789
106790 atomic_set(&fp->refcnt, 1);
106791 fp->len = fprog->len;
106792- /* Since unattached filters are not copied back to user
106793- * space through sk_get_filter(), we do not need to hold
106794- * a copy here, and can spare us the work.
106795- */
106796- fp->orig_prog = NULL;
106797
106798- /* __sk_prepare_filter() already takes care of uncharging
106799- * memory in case something goes wrong.
106800- */
106801- fp = __sk_prepare_filter(fp, NULL);
106802- if (IS_ERR(fp))
106803- return PTR_ERR(fp);
106804+ err = __sk_prepare_filter(fp);
106805+ if (err)
106806+ goto free_mem;
106807
106808 *pfp = fp;
106809 return 0;
106810+free_mem:
106811+ kfree(fp);
106812+ return err;
106813 }
106814 EXPORT_SYMBOL_GPL(sk_unattached_filter_create);
106815
106816@@ -1587,7 +720,7 @@ EXPORT_SYMBOL_GPL(sk_unattached_filter_destroy);
106817 int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
106818 {
106819 struct sk_filter *fp, *old_fp;
106820- unsigned int fsize = sk_filter_proglen(fprog);
106821+ unsigned int fsize = sizeof(struct sock_filter) * fprog->len;
106822 unsigned int sk_fsize = sk_filter_size(fprog->len);
106823 int err;
106824
106825@@ -1601,7 +734,6 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
106826 fp = sock_kmalloc(sk, sk_fsize, GFP_KERNEL);
106827 if (!fp)
106828 return -ENOMEM;
106829-
106830 if (copy_from_user(fp->insns, fprog->filter, fsize)) {
106831 sock_kfree_s(sk, fp, sk_fsize);
106832 return -EFAULT;
106833@@ -1610,26 +742,18 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
106834 atomic_set(&fp->refcnt, 1);
106835 fp->len = fprog->len;
106836
106837- err = sk_store_orig_filter(fp, fprog);
106838+ err = __sk_prepare_filter(fp);
106839 if (err) {
106840 sk_filter_uncharge(sk, fp);
106841- return -ENOMEM;
106842+ return err;
106843 }
106844
106845- /* __sk_prepare_filter() already takes care of uncharging
106846- * memory in case something goes wrong.
106847- */
106848- fp = __sk_prepare_filter(fp, sk);
106849- if (IS_ERR(fp))
106850- return PTR_ERR(fp);
106851-
106852 old_fp = rcu_dereference_protected(sk->sk_filter,
106853 sock_owned_by_user(sk));
106854 rcu_assign_pointer(sk->sk_filter, fp);
106855
106856 if (old_fp)
106857 sk_filter_uncharge(sk, old_fp);
106858-
106859 return 0;
106860 }
106861 EXPORT_SYMBOL_GPL(sk_attach_filter);
106862@@ -1649,46 +773,116 @@ int sk_detach_filter(struct sock *sk)
106863 sk_filter_uncharge(sk, filter);
106864 ret = 0;
106865 }
106866-
106867 return ret;
106868 }
106869 EXPORT_SYMBOL_GPL(sk_detach_filter);
106870
106871-int sk_get_filter(struct sock *sk, struct sock_filter __user *ubuf,
106872- unsigned int len)
106873+void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to)
106874+{
106875+ static const u16 decodes[] = {
106876+ [BPF_S_ALU_ADD_K] = BPF_ALU|BPF_ADD|BPF_K,
106877+ [BPF_S_ALU_ADD_X] = BPF_ALU|BPF_ADD|BPF_X,
106878+ [BPF_S_ALU_SUB_K] = BPF_ALU|BPF_SUB|BPF_K,
106879+ [BPF_S_ALU_SUB_X] = BPF_ALU|BPF_SUB|BPF_X,
106880+ [BPF_S_ALU_MUL_K] = BPF_ALU|BPF_MUL|BPF_K,
106881+ [BPF_S_ALU_MUL_X] = BPF_ALU|BPF_MUL|BPF_X,
106882+ [BPF_S_ALU_DIV_X] = BPF_ALU|BPF_DIV|BPF_X,
106883+ [BPF_S_ALU_MOD_K] = BPF_ALU|BPF_MOD|BPF_K,
106884+ [BPF_S_ALU_MOD_X] = BPF_ALU|BPF_MOD|BPF_X,
106885+ [BPF_S_ALU_AND_K] = BPF_ALU|BPF_AND|BPF_K,
106886+ [BPF_S_ALU_AND_X] = BPF_ALU|BPF_AND|BPF_X,
106887+ [BPF_S_ALU_OR_K] = BPF_ALU|BPF_OR|BPF_K,
106888+ [BPF_S_ALU_OR_X] = BPF_ALU|BPF_OR|BPF_X,
106889+ [BPF_S_ALU_XOR_K] = BPF_ALU|BPF_XOR|BPF_K,
106890+ [BPF_S_ALU_XOR_X] = BPF_ALU|BPF_XOR|BPF_X,
106891+ [BPF_S_ALU_LSH_K] = BPF_ALU|BPF_LSH|BPF_K,
106892+ [BPF_S_ALU_LSH_X] = BPF_ALU|BPF_LSH|BPF_X,
106893+ [BPF_S_ALU_RSH_K] = BPF_ALU|BPF_RSH|BPF_K,
106894+ [BPF_S_ALU_RSH_X] = BPF_ALU|BPF_RSH|BPF_X,
106895+ [BPF_S_ALU_NEG] = BPF_ALU|BPF_NEG,
106896+ [BPF_S_LD_W_ABS] = BPF_LD|BPF_W|BPF_ABS,
106897+ [BPF_S_LD_H_ABS] = BPF_LD|BPF_H|BPF_ABS,
106898+ [BPF_S_LD_B_ABS] = BPF_LD|BPF_B|BPF_ABS,
106899+ [BPF_S_ANC_PROTOCOL] = BPF_LD|BPF_B|BPF_ABS,
106900+ [BPF_S_ANC_PKTTYPE] = BPF_LD|BPF_B|BPF_ABS,
106901+ [BPF_S_ANC_IFINDEX] = BPF_LD|BPF_B|BPF_ABS,
106902+ [BPF_S_ANC_NLATTR] = BPF_LD|BPF_B|BPF_ABS,
106903+ [BPF_S_ANC_NLATTR_NEST] = BPF_LD|BPF_B|BPF_ABS,
106904+ [BPF_S_ANC_MARK] = BPF_LD|BPF_B|BPF_ABS,
106905+ [BPF_S_ANC_QUEUE] = BPF_LD|BPF_B|BPF_ABS,
106906+ [BPF_S_ANC_HATYPE] = BPF_LD|BPF_B|BPF_ABS,
106907+ [BPF_S_ANC_RXHASH] = BPF_LD|BPF_B|BPF_ABS,
106908+ [BPF_S_ANC_CPU] = BPF_LD|BPF_B|BPF_ABS,
106909+ [BPF_S_ANC_ALU_XOR_X] = BPF_LD|BPF_B|BPF_ABS,
106910+ [BPF_S_ANC_SECCOMP_LD_W] = BPF_LD|BPF_B|BPF_ABS,
106911+ [BPF_S_ANC_VLAN_TAG] = BPF_LD|BPF_B|BPF_ABS,
106912+ [BPF_S_ANC_VLAN_TAG_PRESENT] = BPF_LD|BPF_B|BPF_ABS,
106913+ [BPF_S_ANC_PAY_OFFSET] = BPF_LD|BPF_B|BPF_ABS,
106914+ [BPF_S_LD_W_LEN] = BPF_LD|BPF_W|BPF_LEN,
106915+ [BPF_S_LD_W_IND] = BPF_LD|BPF_W|BPF_IND,
106916+ [BPF_S_LD_H_IND] = BPF_LD|BPF_H|BPF_IND,
106917+ [BPF_S_LD_B_IND] = BPF_LD|BPF_B|BPF_IND,
106918+ [BPF_S_LD_IMM] = BPF_LD|BPF_IMM,
106919+ [BPF_S_LDX_W_LEN] = BPF_LDX|BPF_W|BPF_LEN,
106920+ [BPF_S_LDX_B_MSH] = BPF_LDX|BPF_B|BPF_MSH,
106921+ [BPF_S_LDX_IMM] = BPF_LDX|BPF_IMM,
106922+ [BPF_S_MISC_TAX] = BPF_MISC|BPF_TAX,
106923+ [BPF_S_MISC_TXA] = BPF_MISC|BPF_TXA,
106924+ [BPF_S_RET_K] = BPF_RET|BPF_K,
106925+ [BPF_S_RET_A] = BPF_RET|BPF_A,
106926+ [BPF_S_ALU_DIV_K] = BPF_ALU|BPF_DIV|BPF_K,
106927+ [BPF_S_LD_MEM] = BPF_LD|BPF_MEM,
106928+ [BPF_S_LDX_MEM] = BPF_LDX|BPF_MEM,
106929+ [BPF_S_ST] = BPF_ST,
106930+ [BPF_S_STX] = BPF_STX,
106931+ [BPF_S_JMP_JA] = BPF_JMP|BPF_JA,
106932+ [BPF_S_JMP_JEQ_K] = BPF_JMP|BPF_JEQ|BPF_K,
106933+ [BPF_S_JMP_JEQ_X] = BPF_JMP|BPF_JEQ|BPF_X,
106934+ [BPF_S_JMP_JGE_K] = BPF_JMP|BPF_JGE|BPF_K,
106935+ [BPF_S_JMP_JGE_X] = BPF_JMP|BPF_JGE|BPF_X,
106936+ [BPF_S_JMP_JGT_K] = BPF_JMP|BPF_JGT|BPF_K,
106937+ [BPF_S_JMP_JGT_X] = BPF_JMP|BPF_JGT|BPF_X,
106938+ [BPF_S_JMP_JSET_K] = BPF_JMP|BPF_JSET|BPF_K,
106939+ [BPF_S_JMP_JSET_X] = BPF_JMP|BPF_JSET|BPF_X,
106940+ };
106941+ u16 code;
106942+
106943+ code = filt->code;
106944+
106945+ to->code = decodes[code];
106946+ to->jt = filt->jt;
106947+ to->jf = filt->jf;
106948+ to->k = filt->k;
106949+}
106950+
106951+int sk_get_filter(struct sock *sk, struct sock_filter __user *ubuf, unsigned int len)
106952 {
106953- struct sock_fprog_kern *fprog;
106954 struct sk_filter *filter;
106955- int ret = 0;
106956+ int i, ret;
106957
106958 lock_sock(sk);
106959 filter = rcu_dereference_protected(sk->sk_filter,
106960- sock_owned_by_user(sk));
106961+ sock_owned_by_user(sk));
106962+ ret = 0;
106963 if (!filter)
106964 goto out;
106965-
106966- /* We're copying the filter that has been originally attached,
106967- * so no conversion/decode needed anymore.
106968- */
106969- fprog = filter->orig_prog;
106970-
106971- ret = fprog->len;
106972+ ret = filter->len;
106973 if (!len)
106974- /* User space only enquires number of filter blocks. */
106975 goto out;
106976-
106977 ret = -EINVAL;
106978- if (len < fprog->len)
106979+ if (len < filter->len)
106980 goto out;
106981
106982 ret = -EFAULT;
106983- if (copy_to_user(ubuf, fprog->filter, sk_filter_proglen(fprog)))
106984- goto out;
106985+ for (i = 0; i < filter->len; i++) {
106986+ struct sock_filter fb;
106987
106988- /* Instead of bytes, the API requests to return the number
106989- * of filter blocks.
106990- */
106991- ret = fprog->len;
106992+ sk_decode_filter(&filter->insns[i], &fb);
106993+ if (copy_to_user(&ubuf[i], &fb, sizeof(fb)))
106994+ goto out;
106995+ }
106996+
106997+ ret = filter->len;
106998 out:
106999 release_sock(sk);
107000 return ret;
107001diff --git a/net/core/flow.c b/net/core/flow.c
107002index a0348fd..6951c76 100644
107003--- a/net/core/flow.c
107004+++ b/net/core/flow.c
107005@@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
107006 static int flow_entry_valid(struct flow_cache_entry *fle,
107007 struct netns_xfrm *xfrm)
107008 {
107009- if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
107010+ if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
107011 return 0;
107012 if (fle->object && !fle->object->ops->check(fle->object))
107013 return 0;
107014@@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
107015 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
107016 fcp->hash_count++;
107017 }
107018- } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
107019+ } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
107020 flo = fle->object;
107021 if (!flo)
107022 goto ret_object;
107023@@ -263,7 +263,7 @@ nocache:
107024 }
107025 flo = resolver(net, key, family, dir, flo, ctx);
107026 if (fle) {
107027- fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
107028+ fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
107029 if (!IS_ERR(flo))
107030 fle->object = flo;
107031 else
107032diff --git a/net/core/iovec.c b/net/core/iovec.c
107033index e1ec45a..e5c6f16 100644
107034--- a/net/core/iovec.c
107035+++ b/net/core/iovec.c
107036@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
107037 if (m->msg_name && m->msg_namelen) {
107038 if (mode == VERIFY_READ) {
107039 void __user *namep;
107040- namep = (void __user __force *) m->msg_name;
107041+ namep = (void __force_user *) m->msg_name;
107042 err = move_addr_to_kernel(namep, m->msg_namelen,
107043 address);
107044 if (err < 0)
107045@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
107046 }
107047
107048 size = m->msg_iovlen * sizeof(struct iovec);
107049- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
107050+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
107051 return -EFAULT;
107052
107053 m->msg_iov = iov;
107054diff --git a/net/core/neighbour.c b/net/core/neighbour.c
107055index ef31fef..8be66d9 100644
107056--- a/net/core/neighbour.c
107057+++ b/net/core/neighbour.c
107058@@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
107059 void __user *buffer, size_t *lenp, loff_t *ppos)
107060 {
107061 int size, ret;
107062- struct ctl_table tmp = *ctl;
107063+ ctl_table_no_const tmp = *ctl;
107064
107065 tmp.extra1 = &zero;
107066 tmp.extra2 = &unres_qlen_max;
107067@@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
107068 void __user *buffer,
107069 size_t *lenp, loff_t *ppos)
107070 {
107071- struct ctl_table tmp = *ctl;
107072+ ctl_table_no_const tmp = *ctl;
107073 int ret;
107074
107075 tmp.extra1 = &zero;
107076diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
107077index 2bf8329..2eb1423 100644
107078--- a/net/core/net-procfs.c
107079+++ b/net/core/net-procfs.c
107080@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
107081 struct rtnl_link_stats64 temp;
107082 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
107083
107084- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
107085+ if (gr_proc_is_restricted())
107086+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
107087+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
107088+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
107089+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
107090+ else
107091+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
107092 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
107093 dev->name, stats->rx_bytes, stats->rx_packets,
107094 stats->rx_errors,
107095@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
107096 return 0;
107097 }
107098
107099-static const struct seq_operations dev_seq_ops = {
107100+const struct seq_operations dev_seq_ops = {
107101 .start = dev_seq_start,
107102 .next = dev_seq_next,
107103 .stop = dev_seq_stop,
107104@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
107105
107106 static int softnet_seq_open(struct inode *inode, struct file *file)
107107 {
107108- return seq_open(file, &softnet_seq_ops);
107109+ return seq_open_restrict(file, &softnet_seq_ops);
107110 }
107111
107112 static const struct file_operations softnet_seq_fops = {
107113@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
107114 else
107115 seq_printf(seq, "%04x", ntohs(pt->type));
107116
107117+#ifdef CONFIG_GRKERNSEC_HIDESYM
107118+ seq_printf(seq, " %-8s %pf\n",
107119+ pt->dev ? pt->dev->name : "", NULL);
107120+#else
107121 seq_printf(seq, " %-8s %pf\n",
107122 pt->dev ? pt->dev->name : "", pt->func);
107123+#endif
107124 }
107125
107126 return 0;
107127diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
107128index 1cac29e..fb482f3 100644
107129--- a/net/core/net-sysfs.c
107130+++ b/net/core/net-sysfs.c
107131@@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
107132 {
107133 struct net_device *netdev = to_net_dev(dev);
107134 return sprintf(buf, fmt_dec,
107135- atomic_read(&netdev->carrier_changes));
107136+ atomic_read_unchecked(&netdev->carrier_changes));
107137 }
107138 static DEVICE_ATTR_RO(carrier_changes);
107139
107140diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
107141index 85b6269..fc77ea0 100644
107142--- a/net/core/net_namespace.c
107143+++ b/net/core/net_namespace.c
107144@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
107145 int error;
107146 LIST_HEAD(net_exit_list);
107147
107148- list_add_tail(&ops->list, list);
107149+ pax_list_add_tail((struct list_head *)&ops->list, list);
107150 if (ops->init || (ops->id && ops->size)) {
107151 for_each_net(net) {
107152 error = ops_init(ops, net);
107153@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
107154
107155 out_undo:
107156 /* If I have an error cleanup all namespaces I initialized */
107157- list_del(&ops->list);
107158+ pax_list_del((struct list_head *)&ops->list);
107159 ops_exit_list(ops, &net_exit_list);
107160 ops_free_list(ops, &net_exit_list);
107161 return error;
107162@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
107163 struct net *net;
107164 LIST_HEAD(net_exit_list);
107165
107166- list_del(&ops->list);
107167+ pax_list_del((struct list_head *)&ops->list);
107168 for_each_net(net)
107169 list_add_tail(&net->exit_list, &net_exit_list);
107170 ops_exit_list(ops, &net_exit_list);
107171@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
107172 mutex_lock(&net_mutex);
107173 error = register_pernet_operations(&pernet_list, ops);
107174 if (!error && (first_device == &pernet_list))
107175- first_device = &ops->list;
107176+ first_device = (struct list_head *)&ops->list;
107177 mutex_unlock(&net_mutex);
107178 return error;
107179 }
107180diff --git a/net/core/netpoll.c b/net/core/netpoll.c
107181index e33937f..b2b4981 100644
107182--- a/net/core/netpoll.c
107183+++ b/net/core/netpoll.c
107184@@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
107185 struct udphdr *udph;
107186 struct iphdr *iph;
107187 struct ethhdr *eth;
107188- static atomic_t ip_ident;
107189+ static atomic_unchecked_t ip_ident;
107190 struct ipv6hdr *ip6h;
107191
107192 udp_len = len + sizeof(*udph);
107193@@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
107194 put_unaligned(0x45, (unsigned char *)iph);
107195 iph->tos = 0;
107196 put_unaligned(htons(ip_len), &(iph->tot_len));
107197- iph->id = htons(atomic_inc_return(&ip_ident));
107198+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
107199 iph->frag_off = 0;
107200 iph->ttl = 64;
107201 iph->protocol = IPPROTO_UDP;
107202diff --git a/net/core/pktgen.c b/net/core/pktgen.c
107203index fc17a9d..d4a3d88 100644
107204--- a/net/core/pktgen.c
107205+++ b/net/core/pktgen.c
107206@@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
107207 pn->net = net;
107208 INIT_LIST_HEAD(&pn->pktgen_threads);
107209 pn->pktgen_exiting = false;
107210- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
107211+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
107212 if (!pn->proc_dir) {
107213 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
107214 return -ENODEV;
107215diff --git a/net/core/ptp_classifier.c b/net/core/ptp_classifier.c
107216deleted file mode 100644
107217index d3027a7..0000000
107218--- a/net/core/ptp_classifier.c
107219+++ /dev/null
107220@@ -1,141 +0,0 @@
107221-/* PTP classifier
107222- *
107223- * This program is free software; you can redistribute it and/or
107224- * modify it under the terms of version 2 of the GNU General Public
107225- * License as published by the Free Software Foundation.
107226- *
107227- * This program is distributed in the hope that it will be useful, but
107228- * WITHOUT ANY WARRANTY; without even the implied warranty of
107229- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
107230- * General Public License for more details.
107231- */
107232-
107233-/* The below program is the bpf_asm (tools/net/) representation of
107234- * the opcode array in the ptp_filter structure.
107235- *
107236- * For convenience, this can easily be altered and reviewed with
107237- * bpf_asm and bpf_dbg, e.g. `./bpf_asm -c prog` where prog is a
107238- * simple file containing the below program:
107239- *
107240- * ldh [12] ; load ethertype
107241- *
107242- * ; PTP over UDP over IPv4 over Ethernet
107243- * test_ipv4:
107244- * jneq #0x800, test_ipv6 ; ETH_P_IP ?
107245- * ldb [23] ; load proto
107246- * jneq #17, drop_ipv4 ; IPPROTO_UDP ?
107247- * ldh [20] ; load frag offset field
107248- * jset #0x1fff, drop_ipv4 ; don't allow fragments
107249- * ldxb 4*([14]&0xf) ; load IP header len
107250- * ldh [x + 16] ; load UDP dst port
107251- * jneq #319, drop_ipv4 ; is port PTP_EV_PORT ?
107252- * ldh [x + 22] ; load payload
107253- * and #0xf ; mask PTP_CLASS_VMASK
107254- * or #0x10 ; PTP_CLASS_IPV4
107255- * ret a ; return PTP class
107256- * drop_ipv4: ret #0x0 ; PTP_CLASS_NONE
107257- *
107258- * ; PTP over UDP over IPv6 over Ethernet
107259- * test_ipv6:
107260- * jneq #0x86dd, test_8021q ; ETH_P_IPV6 ?
107261- * ldb [20] ; load proto
107262- * jneq #17, drop_ipv6 ; IPPROTO_UDP ?
107263- * ldh [56] ; load UDP dst port
107264- * jneq #319, drop_ipv6 ; is port PTP_EV_PORT ?
107265- * ldh [62] ; load payload
107266- * and #0xf ; mask PTP_CLASS_VMASK
107267- * or #0x20 ; PTP_CLASS_IPV6
107268- * ret a ; return PTP class
107269- * drop_ipv6: ret #0x0 ; PTP_CLASS_NONE
107270- *
107271- * ; PTP over 802.1Q over Ethernet
107272- * test_8021q:
107273- * jneq #0x8100, test_ieee1588 ; ETH_P_8021Q ?
107274- * ldh [16] ; load inner type
107275- * jneq #0x88f7, drop_ieee1588 ; ETH_P_1588 ?
107276- * ldb [18] ; load payload
107277- * and #0x8 ; as we don't have ports here, test
107278- * jneq #0x0, drop_ieee1588 ; for PTP_GEN_BIT and drop these
107279- * ldh [18] ; reload payload
107280- * and #0xf ; mask PTP_CLASS_VMASK
107281- * or #0x40 ; PTP_CLASS_V2_VLAN
107282- * ret a ; return PTP class
107283- *
107284- * ; PTP over Ethernet
107285- * test_ieee1588:
107286- * jneq #0x88f7, drop_ieee1588 ; ETH_P_1588 ?
107287- * ldb [14] ; load payload
107288- * and #0x8 ; as we don't have ports here, test
107289- * jneq #0x0, drop_ieee1588 ; for PTP_GEN_BIT and drop these
107290- * ldh [14] ; reload payload
107291- * and #0xf ; mask PTP_CLASS_VMASK
107292- * or #0x30 ; PTP_CLASS_L2
107293- * ret a ; return PTP class
107294- * drop_ieee1588: ret #0x0 ; PTP_CLASS_NONE
107295- */
107296-
107297-#include <linux/skbuff.h>
107298-#include <linux/filter.h>
107299-#include <linux/ptp_classify.h>
107300-
107301-static struct sk_filter *ptp_insns __read_mostly;
107302-
107303-unsigned int ptp_classify_raw(const struct sk_buff *skb)
107304-{
107305- return SK_RUN_FILTER(ptp_insns, skb);
107306-}
107307-EXPORT_SYMBOL_GPL(ptp_classify_raw);
107308-
107309-void __init ptp_classifier_init(void)
107310-{
107311- static struct sock_filter ptp_filter[] __initdata = {
107312- { 0x28, 0, 0, 0x0000000c },
107313- { 0x15, 0, 12, 0x00000800 },
107314- { 0x30, 0, 0, 0x00000017 },
107315- { 0x15, 0, 9, 0x00000011 },
107316- { 0x28, 0, 0, 0x00000014 },
107317- { 0x45, 7, 0, 0x00001fff },
107318- { 0xb1, 0, 0, 0x0000000e },
107319- { 0x48, 0, 0, 0x00000010 },
107320- { 0x15, 0, 4, 0x0000013f },
107321- { 0x48, 0, 0, 0x00000016 },
107322- { 0x54, 0, 0, 0x0000000f },
107323- { 0x44, 0, 0, 0x00000010 },
107324- { 0x16, 0, 0, 0x00000000 },
107325- { 0x06, 0, 0, 0x00000000 },
107326- { 0x15, 0, 9, 0x000086dd },
107327- { 0x30, 0, 0, 0x00000014 },
107328- { 0x15, 0, 6, 0x00000011 },
107329- { 0x28, 0, 0, 0x00000038 },
107330- { 0x15, 0, 4, 0x0000013f },
107331- { 0x28, 0, 0, 0x0000003e },
107332- { 0x54, 0, 0, 0x0000000f },
107333- { 0x44, 0, 0, 0x00000020 },
107334- { 0x16, 0, 0, 0x00000000 },
107335- { 0x06, 0, 0, 0x00000000 },
107336- { 0x15, 0, 9, 0x00008100 },
107337- { 0x28, 0, 0, 0x00000010 },
107338- { 0x15, 0, 15, 0x000088f7 },
107339- { 0x30, 0, 0, 0x00000012 },
107340- { 0x54, 0, 0, 0x00000008 },
107341- { 0x15, 0, 12, 0x00000000 },
107342- { 0x28, 0, 0, 0x00000012 },
107343- { 0x54, 0, 0, 0x0000000f },
107344- { 0x44, 0, 0, 0x00000040 },
107345- { 0x16, 0, 0, 0x00000000 },
107346- { 0x15, 0, 7, 0x000088f7 },
107347- { 0x30, 0, 0, 0x0000000e },
107348- { 0x54, 0, 0, 0x00000008 },
107349- { 0x15, 0, 4, 0x00000000 },
107350- { 0x28, 0, 0, 0x0000000e },
107351- { 0x54, 0, 0, 0x0000000f },
107352- { 0x44, 0, 0, 0x00000030 },
107353- { 0x16, 0, 0, 0x00000000 },
107354- { 0x06, 0, 0, 0x00000000 },
107355- };
107356- struct sock_fprog_kern ptp_prog = {
107357- .len = ARRAY_SIZE(ptp_filter), .filter = ptp_filter,
107358- };
107359-
107360- BUG_ON(sk_unattached_filter_create(&ptp_insns, &ptp_prog));
107361-}
107362diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
107363index 1063996..0729c19 100644
107364--- a/net/core/rtnetlink.c
107365+++ b/net/core/rtnetlink.c
107366@@ -58,7 +58,7 @@ struct rtnl_link {
107367 rtnl_doit_func doit;
107368 rtnl_dumpit_func dumpit;
107369 rtnl_calcit_func calcit;
107370-};
107371+} __no_const;
107372
107373 static DEFINE_MUTEX(rtnl_mutex);
107374
107375@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
107376 if (rtnl_link_ops_get(ops->kind))
107377 return -EEXIST;
107378
107379- if (!ops->dellink)
107380- ops->dellink = unregister_netdevice_queue;
107381+ if (!ops->dellink) {
107382+ pax_open_kernel();
107383+ *(void **)&ops->dellink = unregister_netdevice_queue;
107384+ pax_close_kernel();
107385+ }
107386
107387- list_add_tail(&ops->list, &link_ops);
107388+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
107389 return 0;
107390 }
107391 EXPORT_SYMBOL_GPL(__rtnl_link_register);
107392@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
107393 for_each_net(net) {
107394 __rtnl_kill_links(net, ops);
107395 }
107396- list_del(&ops->list);
107397+ pax_list_del((struct list_head *)&ops->list);
107398 }
107399 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
107400
107401@@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
107402 (dev->ifalias &&
107403 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
107404 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
107405- atomic_read(&dev->carrier_changes)))
107406+ atomic_read_unchecked(&dev->carrier_changes)))
107407 goto nla_put_failure;
107408
107409 if (1) {
107410diff --git a/net/core/scm.c b/net/core/scm.c
107411index b442e7e..6f5b5a2 100644
107412--- a/net/core/scm.c
107413+++ b/net/core/scm.c
107414@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
107415 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
107416 {
107417 struct cmsghdr __user *cm
107418- = (__force struct cmsghdr __user *)msg->msg_control;
107419+ = (struct cmsghdr __force_user *)msg->msg_control;
107420 struct cmsghdr cmhdr;
107421 int cmlen = CMSG_LEN(len);
107422 int err;
107423@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
107424 err = -EFAULT;
107425 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
107426 goto out;
107427- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
107428+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
107429 goto out;
107430 cmlen = CMSG_SPACE(len);
107431 if (msg->msg_controllen < cmlen)
107432@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
107433 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
107434 {
107435 struct cmsghdr __user *cm
107436- = (__force struct cmsghdr __user*)msg->msg_control;
107437+ = (struct cmsghdr __force_user *)msg->msg_control;
107438
107439 int fdmax = 0;
107440 int fdnum = scm->fp->count;
107441@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
107442 if (fdnum < fdmax)
107443 fdmax = fdnum;
107444
107445- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
107446+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
107447 i++, cmfptr++)
107448 {
107449 struct socket *sock;
107450diff --git a/net/core/skbuff.c b/net/core/skbuff.c
107451index 58ff88e..af9b458 100644
107452--- a/net/core/skbuff.c
107453+++ b/net/core/skbuff.c
107454@@ -2010,7 +2010,7 @@ EXPORT_SYMBOL(__skb_checksum);
107455 __wsum skb_checksum(const struct sk_buff *skb, int offset,
107456 int len, __wsum csum)
107457 {
107458- const struct skb_checksum_ops ops = {
107459+ static const struct skb_checksum_ops ops = {
107460 .update = csum_partial_ext,
107461 .combine = csum_block_add_ext,
107462 };
107463@@ -3233,13 +3233,15 @@ void __init skb_init(void)
107464 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
107465 sizeof(struct sk_buff),
107466 0,
107467- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
107468+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
107469+ SLAB_NO_SANITIZE,
107470 NULL);
107471 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
107472 (2*sizeof(struct sk_buff)) +
107473 sizeof(atomic_t),
107474 0,
107475- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
107476+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
107477+ SLAB_NO_SANITIZE,
107478 NULL);
107479 }
107480
107481diff --git a/net/core/sock.c b/net/core/sock.c
107482index 026e01f..f54f908 100644
107483--- a/net/core/sock.c
107484+++ b/net/core/sock.c
107485@@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
107486 struct sk_buff_head *list = &sk->sk_receive_queue;
107487
107488 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
107489- atomic_inc(&sk->sk_drops);
107490+ atomic_inc_unchecked(&sk->sk_drops);
107491 trace_sock_rcvqueue_full(sk, skb);
107492 return -ENOMEM;
107493 }
107494@@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
107495 return err;
107496
107497 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
107498- atomic_inc(&sk->sk_drops);
107499+ atomic_inc_unchecked(&sk->sk_drops);
107500 return -ENOBUFS;
107501 }
107502
107503@@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
107504 skb_dst_force(skb);
107505
107506 spin_lock_irqsave(&list->lock, flags);
107507- skb->dropcount = atomic_read(&sk->sk_drops);
107508+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
107509 __skb_queue_tail(list, skb);
107510 spin_unlock_irqrestore(&list->lock, flags);
107511
107512@@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
107513 skb->dev = NULL;
107514
107515 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
107516- atomic_inc(&sk->sk_drops);
107517+ atomic_inc_unchecked(&sk->sk_drops);
107518 goto discard_and_relse;
107519 }
107520 if (nested)
107521@@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
107522 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
107523 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
107524 bh_unlock_sock(sk);
107525- atomic_inc(&sk->sk_drops);
107526+ atomic_inc_unchecked(&sk->sk_drops);
107527 goto discard_and_relse;
107528 }
107529
107530@@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
107531 struct timeval tm;
107532 } v;
107533
107534- int lv = sizeof(int);
107535- int len;
107536+ unsigned int lv = sizeof(int);
107537+ unsigned int len;
107538
107539 if (get_user(len, optlen))
107540 return -EFAULT;
107541- if (len < 0)
107542+ if (len > INT_MAX)
107543 return -EINVAL;
107544
107545 memset(&v, 0, sizeof(v));
107546@@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
107547
107548 case SO_PEERNAME:
107549 {
107550- char address[128];
107551+ char address[_K_SS_MAXSIZE];
107552
107553 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
107554 return -ENOTCONN;
107555- if (lv < len)
107556+ if (lv < len || sizeof address < len)
107557 return -EINVAL;
107558 if (copy_to_user(optval, address, len))
107559 return -EFAULT;
107560@@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
107561
107562 if (len > lv)
107563 len = lv;
107564- if (copy_to_user(optval, &v, len))
107565+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
107566 return -EFAULT;
107567 lenout:
107568 if (put_user(len, optlen))
107569@@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
107570 */
107571 smp_wmb();
107572 atomic_set(&sk->sk_refcnt, 1);
107573- atomic_set(&sk->sk_drops, 0);
107574+ atomic_set_unchecked(&sk->sk_drops, 0);
107575 }
107576 EXPORT_SYMBOL(sock_init_data);
107577
107578@@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
107579 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
107580 int level, int type)
107581 {
107582+ struct sock_extended_err ee;
107583 struct sock_exterr_skb *serr;
107584 struct sk_buff *skb, *skb2;
107585 int copied, err;
107586@@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
107587 sock_recv_timestamp(msg, sk, skb);
107588
107589 serr = SKB_EXT_ERR(skb);
107590- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
107591+ ee = serr->ee;
107592+ put_cmsg(msg, level, type, sizeof ee, &ee);
107593
107594 msg->msg_flags |= MSG_ERRQUEUE;
107595 err = copied;
107596diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
107597index a4216a4..773e3d7 100644
107598--- a/net/core/sock_diag.c
107599+++ b/net/core/sock_diag.c
107600@@ -9,26 +9,33 @@
107601 #include <linux/inet_diag.h>
107602 #include <linux/sock_diag.h>
107603
107604-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
107605+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
107606 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
107607 static DEFINE_MUTEX(sock_diag_table_mutex);
107608
107609 int sock_diag_check_cookie(void *sk, __u32 *cookie)
107610 {
107611+#ifndef CONFIG_GRKERNSEC_HIDESYM
107612 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
107613 cookie[1] != INET_DIAG_NOCOOKIE) &&
107614 ((u32)(unsigned long)sk != cookie[0] ||
107615 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
107616 return -ESTALE;
107617 else
107618+#endif
107619 return 0;
107620 }
107621 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
107622
107623 void sock_diag_save_cookie(void *sk, __u32 *cookie)
107624 {
107625+#ifdef CONFIG_GRKERNSEC_HIDESYM
107626+ cookie[0] = 0;
107627+ cookie[1] = 0;
107628+#else
107629 cookie[0] = (u32)(unsigned long)sk;
107630 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
107631+#endif
107632 }
107633 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
107634
107635@@ -52,10 +59,9 @@ EXPORT_SYMBOL_GPL(sock_diag_put_meminfo);
107636 int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
107637 struct sk_buff *skb, int attrtype)
107638 {
107639- struct sock_fprog_kern *fprog;
107640- struct sk_filter *filter;
107641 struct nlattr *attr;
107642- unsigned int flen;
107643+ struct sk_filter *filter;
107644+ unsigned int len;
107645 int err = 0;
107646
107647 if (!may_report_filterinfo) {
107648@@ -64,20 +70,24 @@ int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
107649 }
107650
107651 rcu_read_lock();
107652+
107653 filter = rcu_dereference(sk->sk_filter);
107654- if (!filter)
107655- goto out;
107656+ len = filter ? filter->len * sizeof(struct sock_filter) : 0;
107657
107658- fprog = filter->orig_prog;
107659- flen = sk_filter_proglen(fprog);
107660-
107661- attr = nla_reserve(skb, attrtype, flen);
107662+ attr = nla_reserve(skb, attrtype, len);
107663 if (attr == NULL) {
107664 err = -EMSGSIZE;
107665 goto out;
107666 }
107667
107668- memcpy(nla_data(attr), fprog->filter, flen);
107669+ if (filter) {
107670+ struct sock_filter *fb = (struct sock_filter *)nla_data(attr);
107671+ int i;
107672+
107673+ for (i = 0; i < filter->len; i++, fb++)
107674+ sk_decode_filter(&filter->insns[i], fb);
107675+ }
107676+
107677 out:
107678 rcu_read_unlock();
107679 return err;
107680@@ -110,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
107681 mutex_lock(&sock_diag_table_mutex);
107682 if (sock_diag_handlers[hndl->family])
107683 err = -EBUSY;
107684- else
107685+ else {
107686+ pax_open_kernel();
107687 sock_diag_handlers[hndl->family] = hndl;
107688+ pax_close_kernel();
107689+ }
107690 mutex_unlock(&sock_diag_table_mutex);
107691
107692 return err;
107693@@ -127,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
107694
107695 mutex_lock(&sock_diag_table_mutex);
107696 BUG_ON(sock_diag_handlers[family] != hnld);
107697+ pax_open_kernel();
107698 sock_diag_handlers[family] = NULL;
107699+ pax_close_kernel();
107700 mutex_unlock(&sock_diag_table_mutex);
107701 }
107702 EXPORT_SYMBOL_GPL(sock_diag_unregister);
107703diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
107704index cf9cd13..8b56af3 100644
107705--- a/net/core/sysctl_net_core.c
107706+++ b/net/core/sysctl_net_core.c
107707@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
107708 {
107709 unsigned int orig_size, size;
107710 int ret, i;
107711- struct ctl_table tmp = {
107712+ ctl_table_no_const tmp = {
107713 .data = &size,
107714 .maxlen = sizeof(size),
107715 .mode = table->mode
107716@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
107717 void __user *buffer, size_t *lenp, loff_t *ppos)
107718 {
107719 char id[IFNAMSIZ];
107720- struct ctl_table tbl = {
107721+ ctl_table_no_const tbl = {
107722 .data = id,
107723 .maxlen = IFNAMSIZ,
107724 };
107725@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
107726
107727 static __net_init int sysctl_core_net_init(struct net *net)
107728 {
107729- struct ctl_table *tbl;
107730+ ctl_table_no_const *tbl = NULL;
107731
107732 net->core.sysctl_somaxconn = SOMAXCONN;
107733
107734- tbl = netns_core_table;
107735 if (!net_eq(net, &init_net)) {
107736- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
107737+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
107738 if (tbl == NULL)
107739 goto err_dup;
107740
107741@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
107742 if (net->user_ns != &init_user_ns) {
107743 tbl[0].procname = NULL;
107744 }
107745- }
107746-
107747- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
107748+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
107749+ } else
107750+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
107751 if (net->core.sysctl_hdr == NULL)
107752 goto err_reg;
107753
107754 return 0;
107755
107756 err_reg:
107757- if (tbl != netns_core_table)
107758- kfree(tbl);
107759+ kfree(tbl);
107760 err_dup:
107761 return -ENOMEM;
107762 }
107763@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
107764 kfree(tbl);
107765 }
107766
107767-static __net_initdata struct pernet_operations sysctl_core_ops = {
107768+static __net_initconst struct pernet_operations sysctl_core_ops = {
107769 .init = sysctl_core_net_init,
107770 .exit = sysctl_core_net_exit,
107771 };
107772diff --git a/net/core/timestamping.c b/net/core/timestamping.c
107773index 6521dfd..661b5a4 100644
107774--- a/net/core/timestamping.c
107775+++ b/net/core/timestamping.c
107776@@ -23,11 +23,16 @@
107777 #include <linux/skbuff.h>
107778 #include <linux/export.h>
107779
107780+static struct sock_filter ptp_filter[] = {
107781+ PTP_FILTER
107782+};
107783+
107784 static unsigned int classify(const struct sk_buff *skb)
107785 {
107786- if (likely(skb->dev && skb->dev->phydev &&
107787+ if (likely(skb->dev &&
107788+ skb->dev->phydev &&
107789 skb->dev->phydev->drv))
107790- return ptp_classify_raw(skb);
107791+ return sk_run_filter(skb, ptp_filter);
107792 else
107793 return PTP_CLASS_NONE;
107794 }
107795@@ -55,13 +60,11 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
107796 if (likely(phydev->drv->txtstamp)) {
107797 if (!atomic_inc_not_zero(&sk->sk_refcnt))
107798 return;
107799-
107800 clone = skb_clone(skb, GFP_ATOMIC);
107801 if (!clone) {
107802 sock_put(sk);
107803 return;
107804 }
107805-
107806 clone->sk = sk;
107807 phydev->drv->txtstamp(phydev, clone, type);
107808 }
107809@@ -86,15 +89,12 @@ void skb_complete_tx_timestamp(struct sk_buff *skb,
107810 }
107811
107812 *skb_hwtstamps(skb) = *hwtstamps;
107813-
107814 serr = SKB_EXT_ERR(skb);
107815 memset(serr, 0, sizeof(*serr));
107816 serr->ee.ee_errno = ENOMSG;
107817 serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
107818 skb->sk = NULL;
107819-
107820 err = sock_queue_err_skb(sk, skb);
107821-
107822 sock_put(sk);
107823 if (err)
107824 kfree_skb(skb);
107825@@ -132,3 +132,8 @@ bool skb_defer_rx_timestamp(struct sk_buff *skb)
107826 return false;
107827 }
107828 EXPORT_SYMBOL_GPL(skb_defer_rx_timestamp);
107829+
107830+void __init skb_timestamping_init(void)
107831+{
107832+ BUG_ON(sk_chk_filter(ptp_filter, ARRAY_SIZE(ptp_filter)));
107833+}
107834diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
107835index ae011b4..d2d18bf 100644
107836--- a/net/decnet/af_decnet.c
107837+++ b/net/decnet/af_decnet.c
107838@@ -465,6 +465,7 @@ static struct proto dn_proto = {
107839 .sysctl_rmem = sysctl_decnet_rmem,
107840 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
107841 .obj_size = sizeof(struct dn_sock),
107842+ .slab_flags = SLAB_USERCOPY,
107843 };
107844
107845 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
107846diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
107847index 3b726f3..1af6368 100644
107848--- a/net/decnet/dn_dev.c
107849+++ b/net/decnet/dn_dev.c
107850@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
107851 .extra1 = &min_t3,
107852 .extra2 = &max_t3
107853 },
107854- {0}
107855+ { }
107856 },
107857 };
107858
107859diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
107860index 5325b54..a0d4d69 100644
107861--- a/net/decnet/sysctl_net_decnet.c
107862+++ b/net/decnet/sysctl_net_decnet.c
107863@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
107864
107865 if (len > *lenp) len = *lenp;
107866
107867- if (copy_to_user(buffer, addr, len))
107868+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
107869 return -EFAULT;
107870
107871 *lenp = len;
107872@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
107873
107874 if (len > *lenp) len = *lenp;
107875
107876- if (copy_to_user(buffer, devname, len))
107877+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
107878 return -EFAULT;
107879
107880 *lenp = len;
107881diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
107882index 6f1428c..9586b83 100644
107883--- a/net/ieee802154/reassembly.c
107884+++ b/net/ieee802154/reassembly.c
107885@@ -438,14 +438,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
107886
107887 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
107888 {
107889- struct ctl_table *table;
107890+ ctl_table_no_const *table = NULL;
107891 struct ctl_table_header *hdr;
107892 struct netns_ieee802154_lowpan *ieee802154_lowpan =
107893 net_ieee802154_lowpan(net);
107894
107895- table = lowpan_frags_ns_ctl_table;
107896 if (!net_eq(net, &init_net)) {
107897- table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
107898+ table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
107899 GFP_KERNEL);
107900 if (table == NULL)
107901 goto err_alloc;
107902@@ -458,9 +457,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
107903 /* Don't export sysctls to unprivileged users */
107904 if (net->user_ns != &init_user_ns)
107905 table[0].procname = NULL;
107906- }
107907-
107908- hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
107909+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
107910+ } else
107911+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
107912 if (hdr == NULL)
107913 goto err_reg;
107914
107915@@ -468,8 +467,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
107916 return 0;
107917
107918 err_reg:
107919- if (!net_eq(net, &init_net))
107920- kfree(table);
107921+ kfree(table);
107922 err_alloc:
107923 return -ENOMEM;
107924 }
107925diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
107926index e944937..368fe78 100644
107927--- a/net/ipv4/devinet.c
107928+++ b/net/ipv4/devinet.c
107929@@ -1540,7 +1540,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
107930 idx = 0;
107931 head = &net->dev_index_head[h];
107932 rcu_read_lock();
107933- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
107934+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
107935 net->dev_base_seq;
107936 hlist_for_each_entry_rcu(dev, head, index_hlist) {
107937 if (idx < s_idx)
107938@@ -1858,7 +1858,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
107939 idx = 0;
107940 head = &net->dev_index_head[h];
107941 rcu_read_lock();
107942- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
107943+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
107944 net->dev_base_seq;
107945 hlist_for_each_entry_rcu(dev, head, index_hlist) {
107946 if (idx < s_idx)
107947@@ -2093,7 +2093,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
107948 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
107949 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
107950
107951-static struct devinet_sysctl_table {
107952+static const struct devinet_sysctl_table {
107953 struct ctl_table_header *sysctl_header;
107954 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
107955 } devinet_sysctl = {
107956@@ -2215,7 +2215,7 @@ static __net_init int devinet_init_net(struct net *net)
107957 int err;
107958 struct ipv4_devconf *all, *dflt;
107959 #ifdef CONFIG_SYSCTL
107960- struct ctl_table *tbl = ctl_forward_entry;
107961+ ctl_table_no_const *tbl = NULL;
107962 struct ctl_table_header *forw_hdr;
107963 #endif
107964
107965@@ -2233,7 +2233,7 @@ static __net_init int devinet_init_net(struct net *net)
107966 goto err_alloc_dflt;
107967
107968 #ifdef CONFIG_SYSCTL
107969- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
107970+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
107971 if (tbl == NULL)
107972 goto err_alloc_ctl;
107973
107974@@ -2253,7 +2253,10 @@ static __net_init int devinet_init_net(struct net *net)
107975 goto err_reg_dflt;
107976
107977 err = -ENOMEM;
107978- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
107979+ if (!net_eq(net, &init_net))
107980+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
107981+ else
107982+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
107983 if (forw_hdr == NULL)
107984 goto err_reg_ctl;
107985 net->ipv4.forw_hdr = forw_hdr;
107986@@ -2269,8 +2272,7 @@ err_reg_ctl:
107987 err_reg_dflt:
107988 __devinet_sysctl_unregister(all);
107989 err_reg_all:
107990- if (tbl != ctl_forward_entry)
107991- kfree(tbl);
107992+ kfree(tbl);
107993 err_alloc_ctl:
107994 #endif
107995 if (dflt != &ipv4_devconf_dflt)
107996diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
107997index 255aa99..45c78f8 100644
107998--- a/net/ipv4/fib_frontend.c
107999+++ b/net/ipv4/fib_frontend.c
108000@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
108001 #ifdef CONFIG_IP_ROUTE_MULTIPATH
108002 fib_sync_up(dev);
108003 #endif
108004- atomic_inc(&net->ipv4.dev_addr_genid);
108005+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
108006 rt_cache_flush(dev_net(dev));
108007 break;
108008 case NETDEV_DOWN:
108009 fib_del_ifaddr(ifa, NULL);
108010- atomic_inc(&net->ipv4.dev_addr_genid);
108011+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
108012 if (ifa->ifa_dev->ifa_list == NULL) {
108013 /* Last address was deleted from this interface.
108014 * Disable IP.
108015@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
108016 #ifdef CONFIG_IP_ROUTE_MULTIPATH
108017 fib_sync_up(dev);
108018 #endif
108019- atomic_inc(&net->ipv4.dev_addr_genid);
108020+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
108021 rt_cache_flush(net);
108022 break;
108023 case NETDEV_DOWN:
108024diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
108025index b10cd43a..22327f9 100644
108026--- a/net/ipv4/fib_semantics.c
108027+++ b/net/ipv4/fib_semantics.c
108028@@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
108029 nh->nh_saddr = inet_select_addr(nh->nh_dev,
108030 nh->nh_gw,
108031 nh->nh_parent->fib_scope);
108032- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
108033+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
108034
108035 return nh->nh_saddr;
108036 }
108037diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
108038index 43116e8..e3e6159 100644
108039--- a/net/ipv4/inet_hashtables.c
108040+++ b/net/ipv4/inet_hashtables.c
108041@@ -18,6 +18,7 @@
108042 #include <linux/sched.h>
108043 #include <linux/slab.h>
108044 #include <linux/wait.h>
108045+#include <linux/security.h>
108046
108047 #include <net/inet_connection_sock.h>
108048 #include <net/inet_hashtables.h>
108049@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
108050 return inet_ehashfn(net, laddr, lport, faddr, fport);
108051 }
108052
108053+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
108054+
108055 /*
108056 * Allocate and initialize a new local port bind bucket.
108057 * The bindhash mutex for snum's hash chain must be held here.
108058@@ -554,6 +557,8 @@ ok:
108059 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
108060 spin_unlock(&head->lock);
108061
108062+ gr_update_task_in_ip_table(current, inet_sk(sk));
108063+
108064 if (tw) {
108065 inet_twsk_deschedule(tw, death_row);
108066 while (twrefcnt) {
108067diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
108068index bd5f592..e80e605 100644
108069--- a/net/ipv4/inetpeer.c
108070+++ b/net/ipv4/inetpeer.c
108071@@ -482,7 +482,7 @@ relookup:
108072 if (p) {
108073 p->daddr = *daddr;
108074 atomic_set(&p->refcnt, 1);
108075- atomic_set(&p->rid, 0);
108076+ atomic_set_unchecked(&p->rid, 0);
108077 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
108078 p->rate_tokens = 0;
108079 /* 60*HZ is arbitrary, but chosen enough high so that the first
108080diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
108081index ed32313..3762abe 100644
108082--- a/net/ipv4/ip_fragment.c
108083+++ b/net/ipv4/ip_fragment.c
108084@@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
108085 return 0;
108086
108087 start = qp->rid;
108088- end = atomic_inc_return(&peer->rid);
108089+ end = atomic_inc_return_unchecked(&peer->rid);
108090 qp->rid = end;
108091
108092 rc = qp->q.fragments && (end - start) > max;
108093@@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
108094
108095 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
108096 {
108097- struct ctl_table *table;
108098+ ctl_table_no_const *table = NULL;
108099 struct ctl_table_header *hdr;
108100
108101- table = ip4_frags_ns_ctl_table;
108102 if (!net_eq(net, &init_net)) {
108103- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
108104+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
108105 if (table == NULL)
108106 goto err_alloc;
108107
108108@@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
108109 /* Don't export sysctls to unprivileged users */
108110 if (net->user_ns != &init_user_ns)
108111 table[0].procname = NULL;
108112- }
108113+ hdr = register_net_sysctl(net, "net/ipv4", table);
108114+ } else
108115+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
108116
108117- hdr = register_net_sysctl(net, "net/ipv4", table);
108118 if (hdr == NULL)
108119 goto err_reg;
108120
108121@@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
108122 return 0;
108123
108124 err_reg:
108125- if (!net_eq(net, &init_net))
108126- kfree(table);
108127+ kfree(table);
108128 err_alloc:
108129 return -ENOMEM;
108130 }
108131diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
108132index 9b84254..c776611 100644
108133--- a/net/ipv4/ip_gre.c
108134+++ b/net/ipv4/ip_gre.c
108135@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
108136 module_param(log_ecn_error, bool, 0644);
108137 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
108138
108139-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
108140+static struct rtnl_link_ops ipgre_link_ops;
108141 static int ipgre_tunnel_init(struct net_device *dev);
108142
108143 static int ipgre_net_id __read_mostly;
108144@@ -733,7 +733,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
108145 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
108146 };
108147
108148-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
108149+static struct rtnl_link_ops ipgre_link_ops = {
108150 .kind = "gre",
108151 .maxtype = IFLA_GRE_MAX,
108152 .policy = ipgre_policy,
108153@@ -747,7 +747,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
108154 .fill_info = ipgre_fill_info,
108155 };
108156
108157-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
108158+static struct rtnl_link_ops ipgre_tap_ops = {
108159 .kind = "gretap",
108160 .maxtype = IFLA_GRE_MAX,
108161 .policy = ipgre_policy,
108162diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
108163index 64741b9..6f334a2 100644
108164--- a/net/ipv4/ip_sockglue.c
108165+++ b/net/ipv4/ip_sockglue.c
108166@@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
108167 len = min_t(unsigned int, len, opt->optlen);
108168 if (put_user(len, optlen))
108169 return -EFAULT;
108170- if (copy_to_user(optval, opt->__data, len))
108171+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
108172+ copy_to_user(optval, opt->__data, len))
108173 return -EFAULT;
108174 return 0;
108175 }
108176@@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
108177 if (sk->sk_type != SOCK_STREAM)
108178 return -ENOPROTOOPT;
108179
108180- msg.msg_control = optval;
108181+ msg.msg_control = (void __force_kernel *)optval;
108182 msg.msg_controllen = len;
108183 msg.msg_flags = flags;
108184
108185diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
108186index b8960f3..0f025db 100644
108187--- a/net/ipv4/ip_vti.c
108188+++ b/net/ipv4/ip_vti.c
108189@@ -45,7 +45,7 @@
108190 #include <net/net_namespace.h>
108191 #include <net/netns/generic.h>
108192
108193-static struct rtnl_link_ops vti_link_ops __read_mostly;
108194+static struct rtnl_link_ops vti_link_ops;
108195
108196 static int vti_net_id __read_mostly;
108197 static int vti_tunnel_init(struct net_device *dev);
108198@@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
108199 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
108200 };
108201
108202-static struct rtnl_link_ops vti_link_ops __read_mostly = {
108203+static struct rtnl_link_ops vti_link_ops = {
108204 .kind = "vti",
108205 .maxtype = IFLA_VTI_MAX,
108206 .policy = vti_policy,
108207diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
108208index b3e86ea..18ce98c 100644
108209--- a/net/ipv4/ipconfig.c
108210+++ b/net/ipv4/ipconfig.c
108211@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
108212
108213 mm_segment_t oldfs = get_fs();
108214 set_fs(get_ds());
108215- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
108216+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
108217 set_fs(oldfs);
108218 return res;
108219 }
108220@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
108221
108222 mm_segment_t oldfs = get_fs();
108223 set_fs(get_ds());
108224- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
108225+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
108226 set_fs(oldfs);
108227 return res;
108228 }
108229@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
108230
108231 mm_segment_t oldfs = get_fs();
108232 set_fs(get_ds());
108233- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
108234+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
108235 set_fs(oldfs);
108236 return res;
108237 }
108238diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
108239index 62eaa00..29b2dc2 100644
108240--- a/net/ipv4/ipip.c
108241+++ b/net/ipv4/ipip.c
108242@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
108243 static int ipip_net_id __read_mostly;
108244
108245 static int ipip_tunnel_init(struct net_device *dev);
108246-static struct rtnl_link_ops ipip_link_ops __read_mostly;
108247+static struct rtnl_link_ops ipip_link_ops;
108248
108249 static int ipip_err(struct sk_buff *skb, u32 info)
108250 {
108251@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
108252 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
108253 };
108254
108255-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
108256+static struct rtnl_link_ops ipip_link_ops = {
108257 .kind = "ipip",
108258 .maxtype = IFLA_IPTUN_MAX,
108259 .policy = ipip_policy,
108260diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
108261index f95b6f9..2ee2097 100644
108262--- a/net/ipv4/netfilter/arp_tables.c
108263+++ b/net/ipv4/netfilter/arp_tables.c
108264@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
108265 #endif
108266
108267 static int get_info(struct net *net, void __user *user,
108268- const int *len, int compat)
108269+ int len, int compat)
108270 {
108271 char name[XT_TABLE_MAXNAMELEN];
108272 struct xt_table *t;
108273 int ret;
108274
108275- if (*len != sizeof(struct arpt_getinfo)) {
108276- duprintf("length %u != %Zu\n", *len,
108277+ if (len != sizeof(struct arpt_getinfo)) {
108278+ duprintf("length %u != %Zu\n", len,
108279 sizeof(struct arpt_getinfo));
108280 return -EINVAL;
108281 }
108282@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
108283 info.size = private->size;
108284 strcpy(info.name, name);
108285
108286- if (copy_to_user(user, &info, *len) != 0)
108287+ if (copy_to_user(user, &info, len) != 0)
108288 ret = -EFAULT;
108289 else
108290 ret = 0;
108291@@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
108292
108293 switch (cmd) {
108294 case ARPT_SO_GET_INFO:
108295- ret = get_info(sock_net(sk), user, len, 1);
108296+ ret = get_info(sock_net(sk), user, *len, 1);
108297 break;
108298 case ARPT_SO_GET_ENTRIES:
108299 ret = compat_get_entries(sock_net(sk), user, len);
108300@@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
108301
108302 switch (cmd) {
108303 case ARPT_SO_GET_INFO:
108304- ret = get_info(sock_net(sk), user, len, 0);
108305+ ret = get_info(sock_net(sk), user, *len, 0);
108306 break;
108307
108308 case ARPT_SO_GET_ENTRIES:
108309diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
108310index 99e810f..3711b81 100644
108311--- a/net/ipv4/netfilter/ip_tables.c
108312+++ b/net/ipv4/netfilter/ip_tables.c
108313@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
108314 #endif
108315
108316 static int get_info(struct net *net, void __user *user,
108317- const int *len, int compat)
108318+ int len, int compat)
108319 {
108320 char name[XT_TABLE_MAXNAMELEN];
108321 struct xt_table *t;
108322 int ret;
108323
108324- if (*len != sizeof(struct ipt_getinfo)) {
108325- duprintf("length %u != %zu\n", *len,
108326+ if (len != sizeof(struct ipt_getinfo)) {
108327+ duprintf("length %u != %zu\n", len,
108328 sizeof(struct ipt_getinfo));
108329 return -EINVAL;
108330 }
108331@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
108332 info.size = private->size;
108333 strcpy(info.name, name);
108334
108335- if (copy_to_user(user, &info, *len) != 0)
108336+ if (copy_to_user(user, &info, len) != 0)
108337 ret = -EFAULT;
108338 else
108339 ret = 0;
108340@@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
108341
108342 switch (cmd) {
108343 case IPT_SO_GET_INFO:
108344- ret = get_info(sock_net(sk), user, len, 1);
108345+ ret = get_info(sock_net(sk), user, *len, 1);
108346 break;
108347 case IPT_SO_GET_ENTRIES:
108348 ret = compat_get_entries(sock_net(sk), user, len);
108349@@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
108350
108351 switch (cmd) {
108352 case IPT_SO_GET_INFO:
108353- ret = get_info(sock_net(sk), user, len, 0);
108354+ ret = get_info(sock_net(sk), user, *len, 0);
108355 break;
108356
108357 case IPT_SO_GET_ENTRIES:
108358diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
108359index 2510c02..cfb34fa 100644
108360--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
108361+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
108362@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
108363 spin_lock_init(&cn->lock);
108364
108365 #ifdef CONFIG_PROC_FS
108366- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
108367+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
108368 if (!cn->procdir) {
108369 pr_err("Unable to proc dir entry\n");
108370 return -ENOMEM;
108371diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
108372index 044a0dd..3399751 100644
108373--- a/net/ipv4/ping.c
108374+++ b/net/ipv4/ping.c
108375@@ -59,7 +59,7 @@ struct ping_table {
108376 };
108377
108378 static struct ping_table ping_table;
108379-struct pingv6_ops pingv6_ops;
108380+struct pingv6_ops *pingv6_ops;
108381 EXPORT_SYMBOL_GPL(pingv6_ops);
108382
108383 static u16 ping_port_rover;
108384@@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
108385 return -ENODEV;
108386 }
108387 }
108388- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
108389+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
108390 scoped);
108391 rcu_read_unlock();
108392
108393@@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
108394 }
108395 #if IS_ENABLED(CONFIG_IPV6)
108396 } else if (skb->protocol == htons(ETH_P_IPV6)) {
108397- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
108398+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
108399 #endif
108400 }
108401
108402@@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
108403 info, (u8 *)icmph);
108404 #if IS_ENABLED(CONFIG_IPV6)
108405 } else if (family == AF_INET6) {
108406- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
108407+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
108408 info, (u8 *)icmph);
108409 #endif
108410 }
108411@@ -858,7 +858,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
108412 return ip_recv_error(sk, msg, len, addr_len);
108413 #if IS_ENABLED(CONFIG_IPV6)
108414 } else if (family == AF_INET6) {
108415- return pingv6_ops.ipv6_recv_error(sk, msg, len,
108416+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
108417 addr_len);
108418 #endif
108419 }
108420@@ -916,10 +916,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
108421 }
108422
108423 if (inet6_sk(sk)->rxopt.all)
108424- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
108425+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
108426 if (skb->protocol == htons(ETH_P_IPV6) &&
108427 inet6_sk(sk)->rxopt.all)
108428- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
108429+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
108430 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
108431 ip_cmsg_recv(msg, skb);
108432 #endif
108433@@ -1111,7 +1111,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
108434 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
108435 0, sock_i_ino(sp),
108436 atomic_read(&sp->sk_refcnt), sp,
108437- atomic_read(&sp->sk_drops));
108438+ atomic_read_unchecked(&sp->sk_drops));
108439 }
108440
108441 static int ping_v4_seq_show(struct seq_file *seq, void *v)
108442diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
108443index 2c65160..213ecdf 100644
108444--- a/net/ipv4/raw.c
108445+++ b/net/ipv4/raw.c
108446@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
108447 int raw_rcv(struct sock *sk, struct sk_buff *skb)
108448 {
108449 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
108450- atomic_inc(&sk->sk_drops);
108451+ atomic_inc_unchecked(&sk->sk_drops);
108452 kfree_skb(skb);
108453 return NET_RX_DROP;
108454 }
108455@@ -748,16 +748,20 @@ static int raw_init(struct sock *sk)
108456
108457 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
108458 {
108459+ struct icmp_filter filter;
108460+
108461 if (optlen > sizeof(struct icmp_filter))
108462 optlen = sizeof(struct icmp_filter);
108463- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
108464+ if (copy_from_user(&filter, optval, optlen))
108465 return -EFAULT;
108466+ raw_sk(sk)->filter = filter;
108467 return 0;
108468 }
108469
108470 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
108471 {
108472 int len, ret = -EFAULT;
108473+ struct icmp_filter filter;
108474
108475 if (get_user(len, optlen))
108476 goto out;
108477@@ -767,8 +771,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
108478 if (len > sizeof(struct icmp_filter))
108479 len = sizeof(struct icmp_filter);
108480 ret = -EFAULT;
108481- if (put_user(len, optlen) ||
108482- copy_to_user(optval, &raw_sk(sk)->filter, len))
108483+ filter = raw_sk(sk)->filter;
108484+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
108485 goto out;
108486 ret = 0;
108487 out: return ret;
108488@@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
108489 0, 0L, 0,
108490 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
108491 0, sock_i_ino(sp),
108492- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
108493+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
108494 }
108495
108496 static int raw_seq_show(struct seq_file *seq, void *v)
108497diff --git a/net/ipv4/route.c b/net/ipv4/route.c
108498index 1901998..a9a850a 100644
108499--- a/net/ipv4/route.c
108500+++ b/net/ipv4/route.c
108501@@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
108502
108503 static int rt_cache_seq_open(struct inode *inode, struct file *file)
108504 {
108505- return seq_open(file, &rt_cache_seq_ops);
108506+ return seq_open_restrict(file, &rt_cache_seq_ops);
108507 }
108508
108509 static const struct file_operations rt_cache_seq_fops = {
108510@@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
108511
108512 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
108513 {
108514- return seq_open(file, &rt_cpu_seq_ops);
108515+ return seq_open_restrict(file, &rt_cpu_seq_ops);
108516 }
108517
108518 static const struct file_operations rt_cpu_seq_fops = {
108519@@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
108520
108521 static int rt_acct_proc_open(struct inode *inode, struct file *file)
108522 {
108523- return single_open(file, rt_acct_proc_show, NULL);
108524+ return single_open_restrict(file, rt_acct_proc_show, NULL);
108525 }
108526
108527 static const struct file_operations rt_acct_proc_fops = {
108528@@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
108529
108530 #define IP_IDENTS_SZ 2048u
108531 struct ip_ident_bucket {
108532- atomic_t id;
108533+ atomic_unchecked_t id;
108534 u32 stamp32;
108535 };
108536
108537-static struct ip_ident_bucket *ip_idents __read_mostly;
108538+static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
108539
108540 /* In order to protect privacy, we add a perturbation to identifiers
108541 * if one generator is seldom used. This makes hard for an attacker
108542@@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
108543 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
108544 delta = prandom_u32_max(now - old);
108545
108546- return atomic_add_return(segs + delta, &bucket->id) - segs;
108547+ return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
108548 }
108549 EXPORT_SYMBOL(ip_idents_reserve);
108550
108551@@ -2625,34 +2625,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
108552 .maxlen = sizeof(int),
108553 .mode = 0200,
108554 .proc_handler = ipv4_sysctl_rtcache_flush,
108555+ .extra1 = &init_net,
108556 },
108557 { },
108558 };
108559
108560 static __net_init int sysctl_route_net_init(struct net *net)
108561 {
108562- struct ctl_table *tbl;
108563+ ctl_table_no_const *tbl = NULL;
108564
108565- tbl = ipv4_route_flush_table;
108566 if (!net_eq(net, &init_net)) {
108567- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
108568+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
108569 if (tbl == NULL)
108570 goto err_dup;
108571
108572 /* Don't export sysctls to unprivileged users */
108573 if (net->user_ns != &init_user_ns)
108574 tbl[0].procname = NULL;
108575- }
108576- tbl[0].extra1 = net;
108577+ tbl[0].extra1 = net;
108578+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
108579+ } else
108580+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
108581
108582- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
108583 if (net->ipv4.route_hdr == NULL)
108584 goto err_reg;
108585 return 0;
108586
108587 err_reg:
108588- if (tbl != ipv4_route_flush_table)
108589- kfree(tbl);
108590+ kfree(tbl);
108591 err_dup:
108592 return -ENOMEM;
108593 }
108594@@ -2675,8 +2675,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
108595
108596 static __net_init int rt_genid_init(struct net *net)
108597 {
108598- atomic_set(&net->ipv4.rt_genid, 0);
108599- atomic_set(&net->fnhe_genid, 0);
108600+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
108601+ atomic_set_unchecked(&net->fnhe_genid, 0);
108602 get_random_bytes(&net->ipv4.dev_addr_genid,
108603 sizeof(net->ipv4.dev_addr_genid));
108604 return 0;
108605@@ -2719,11 +2719,7 @@ int __init ip_rt_init(void)
108606 {
108607 int rc = 0;
108608
108609- ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
108610- if (!ip_idents)
108611- panic("IP: failed to allocate ip_idents\n");
108612-
108613- prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
108614+ prandom_bytes(ip_idents, sizeof(ip_idents));
108615
108616 #ifdef CONFIG_IP_ROUTE_CLASSID
108617 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
108618diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
108619index 79a007c..5023029 100644
108620--- a/net/ipv4/sysctl_net_ipv4.c
108621+++ b/net/ipv4/sysctl_net_ipv4.c
108622@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
108623 container_of(table->data, struct net, ipv4.ip_local_ports.range);
108624 int ret;
108625 int range[2];
108626- struct ctl_table tmp = {
108627+ ctl_table_no_const tmp = {
108628 .data = &range,
108629 .maxlen = sizeof(range),
108630 .mode = table->mode,
108631@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
108632 int ret;
108633 gid_t urange[2];
108634 kgid_t low, high;
108635- struct ctl_table tmp = {
108636+ ctl_table_no_const tmp = {
108637 .data = &urange,
108638 .maxlen = sizeof(urange),
108639 .mode = table->mode,
108640@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
108641 void __user *buffer, size_t *lenp, loff_t *ppos)
108642 {
108643 char val[TCP_CA_NAME_MAX];
108644- struct ctl_table tbl = {
108645+ ctl_table_no_const tbl = {
108646 .data = val,
108647 .maxlen = TCP_CA_NAME_MAX,
108648 };
108649@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
108650 void __user *buffer, size_t *lenp,
108651 loff_t *ppos)
108652 {
108653- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
108654+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
108655 int ret;
108656
108657 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
108658@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
108659 void __user *buffer, size_t *lenp,
108660 loff_t *ppos)
108661 {
108662- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
108663+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
108664 int ret;
108665
108666 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
108667@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
108668 void __user *buffer, size_t *lenp,
108669 loff_t *ppos)
108670 {
108671- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
108672+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
108673 struct tcp_fastopen_context *ctxt;
108674 int ret;
108675 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
108676@@ -857,13 +857,12 @@ static struct ctl_table ipv4_net_table[] = {
108677
108678 static __net_init int ipv4_sysctl_init_net(struct net *net)
108679 {
108680- struct ctl_table *table;
108681+ ctl_table_no_const *table = NULL;
108682
108683- table = ipv4_net_table;
108684 if (!net_eq(net, &init_net)) {
108685 int i;
108686
108687- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
108688+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
108689 if (table == NULL)
108690 goto err_alloc;
108691
108692@@ -872,7 +871,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
108693 table[i].data += (void *)net - (void *)&init_net;
108694 }
108695
108696- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
108697+ if (!net_eq(net, &init_net))
108698+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
108699+ else
108700+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
108701 if (net->ipv4.ipv4_hdr == NULL)
108702 goto err_reg;
108703
108704diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
108705index 40639c2..dfc86b2 100644
108706--- a/net/ipv4/tcp_input.c
108707+++ b/net/ipv4/tcp_input.c
108708@@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
108709 * without any lock. We want to make sure compiler wont store
108710 * intermediate values in this location.
108711 */
108712- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
108713+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
108714 sk->sk_max_pacing_rate);
108715 }
108716
108717@@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
108718 * simplifies code)
108719 */
108720 static void
108721-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
108722+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
108723 struct sk_buff *head, struct sk_buff *tail,
108724 u32 start, u32 end)
108725 {
108726@@ -5536,6 +5536,7 @@ discard:
108727 tcp_paws_reject(&tp->rx_opt, 0))
108728 goto discard_and_undo;
108729
108730+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
108731 if (th->syn) {
108732 /* We see SYN without ACK. It is attempt of
108733 * simultaneous connect with crossed SYNs.
108734@@ -5586,6 +5587,7 @@ discard:
108735 goto discard;
108736 #endif
108737 }
108738+#endif
108739 /* "fifth, if neither of the SYN or RST bits is set then
108740 * drop the segment and return."
108741 */
108742@@ -5632,7 +5634,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
108743 goto discard;
108744
108745 if (th->syn) {
108746- if (th->fin)
108747+ if (th->fin || th->urg || th->psh)
108748 goto discard;
108749 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
108750 return 1;
108751diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
108752index 77cccda..10122c4 100644
108753--- a/net/ipv4/tcp_ipv4.c
108754+++ b/net/ipv4/tcp_ipv4.c
108755@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
108756 EXPORT_SYMBOL(sysctl_tcp_low_latency);
108757
108758
108759+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108760+extern int grsec_enable_blackhole;
108761+#endif
108762+
108763 #ifdef CONFIG_TCP_MD5SIG
108764 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
108765 __be32 daddr, __be32 saddr, const struct tcphdr *th);
108766@@ -1591,6 +1595,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
108767 return 0;
108768
108769 reset:
108770+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108771+ if (!grsec_enable_blackhole)
108772+#endif
108773 tcp_v4_send_reset(rsk, skb);
108774 discard:
108775 kfree_skb(skb);
108776@@ -1737,12 +1744,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
108777 TCP_SKB_CB(skb)->sacked = 0;
108778
108779 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
108780- if (!sk)
108781+ if (!sk) {
108782+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108783+ ret = 1;
108784+#endif
108785 goto no_tcp_socket;
108786-
108787+ }
108788 process:
108789- if (sk->sk_state == TCP_TIME_WAIT)
108790+ if (sk->sk_state == TCP_TIME_WAIT) {
108791+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108792+ ret = 2;
108793+#endif
108794 goto do_time_wait;
108795+ }
108796
108797 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
108798 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
108799@@ -1796,6 +1810,10 @@ csum_error:
108800 bad_packet:
108801 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
108802 } else {
108803+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108804+ if (!grsec_enable_blackhole || (ret == 1 &&
108805+ (skb->dev->flags & IFF_LOOPBACK)))
108806+#endif
108807 tcp_v4_send_reset(NULL, skb);
108808 }
108809
108810diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
108811index e68e0d4..0334263 100644
108812--- a/net/ipv4/tcp_minisocks.c
108813+++ b/net/ipv4/tcp_minisocks.c
108814@@ -27,6 +27,10 @@
108815 #include <net/inet_common.h>
108816 #include <net/xfrm.h>
108817
108818+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108819+extern int grsec_enable_blackhole;
108820+#endif
108821+
108822 int sysctl_tcp_syncookies __read_mostly = 1;
108823 EXPORT_SYMBOL(sysctl_tcp_syncookies);
108824
108825@@ -740,7 +744,10 @@ embryonic_reset:
108826 * avoid becoming vulnerable to outside attack aiming at
108827 * resetting legit local connections.
108828 */
108829- req->rsk_ops->send_reset(sk, skb);
108830+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108831+ if (!grsec_enable_blackhole)
108832+#endif
108833+ req->rsk_ops->send_reset(sk, skb);
108834 } else if (fastopen) { /* received a valid RST pkt */
108835 reqsk_fastopen_remove(sk, req, true);
108836 tcp_reset(sk);
108837diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
108838index 3b66610..bfbe23a 100644
108839--- a/net/ipv4/tcp_probe.c
108840+++ b/net/ipv4/tcp_probe.c
108841@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
108842 if (cnt + width >= len)
108843 break;
108844
108845- if (copy_to_user(buf + cnt, tbuf, width))
108846+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
108847 return -EFAULT;
108848 cnt += width;
108849 }
108850diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
108851index 286227a..c495a76 100644
108852--- a/net/ipv4/tcp_timer.c
108853+++ b/net/ipv4/tcp_timer.c
108854@@ -22,6 +22,10 @@
108855 #include <linux/gfp.h>
108856 #include <net/tcp.h>
108857
108858+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108859+extern int grsec_lastack_retries;
108860+#endif
108861+
108862 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
108863 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
108864 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
108865@@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
108866 }
108867 }
108868
108869+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108870+ if ((sk->sk_state == TCP_LAST_ACK) &&
108871+ (grsec_lastack_retries > 0) &&
108872+ (grsec_lastack_retries < retry_until))
108873+ retry_until = grsec_lastack_retries;
108874+#endif
108875+
108876 if (retransmits_timed_out(sk, retry_until,
108877 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
108878 /* Has it gone just too far? */
108879diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
108880index 7d5a866..4874211 100644
108881--- a/net/ipv4/udp.c
108882+++ b/net/ipv4/udp.c
108883@@ -87,6 +87,7 @@
108884 #include <linux/types.h>
108885 #include <linux/fcntl.h>
108886 #include <linux/module.h>
108887+#include <linux/security.h>
108888 #include <linux/socket.h>
108889 #include <linux/sockios.h>
108890 #include <linux/igmp.h>
108891@@ -113,6 +114,10 @@
108892 #include <net/busy_poll.h>
108893 #include "udp_impl.h"
108894
108895+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108896+extern int grsec_enable_blackhole;
108897+#endif
108898+
108899 struct udp_table udp_table __read_mostly;
108900 EXPORT_SYMBOL(udp_table);
108901
108902@@ -615,6 +620,9 @@ found:
108903 return s;
108904 }
108905
108906+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
108907+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
108908+
108909 /*
108910 * This routine is called by the ICMP module when it gets some
108911 * sort of error condition. If err < 0 then the socket should
108912@@ -952,9 +960,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
108913 dport = usin->sin_port;
108914 if (dport == 0)
108915 return -EINVAL;
108916+
108917+ err = gr_search_udp_sendmsg(sk, usin);
108918+ if (err)
108919+ return err;
108920 } else {
108921 if (sk->sk_state != TCP_ESTABLISHED)
108922 return -EDESTADDRREQ;
108923+
108924+ err = gr_search_udp_sendmsg(sk, NULL);
108925+ if (err)
108926+ return err;
108927+
108928 daddr = inet->inet_daddr;
108929 dport = inet->inet_dport;
108930 /* Open fast path for connected socket.
108931@@ -1202,7 +1219,7 @@ static unsigned int first_packet_length(struct sock *sk)
108932 IS_UDPLITE(sk));
108933 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
108934 IS_UDPLITE(sk));
108935- atomic_inc(&sk->sk_drops);
108936+ atomic_inc_unchecked(&sk->sk_drops);
108937 __skb_unlink(skb, rcvq);
108938 __skb_queue_tail(&list_kill, skb);
108939 }
108940@@ -1282,6 +1299,10 @@ try_again:
108941 if (!skb)
108942 goto out;
108943
108944+ err = gr_search_udp_recvmsg(sk, skb);
108945+ if (err)
108946+ goto out_free;
108947+
108948 ulen = skb->len - sizeof(struct udphdr);
108949 copied = len;
108950 if (copied > ulen)
108951@@ -1315,7 +1336,7 @@ try_again:
108952 if (unlikely(err)) {
108953 trace_kfree_skb(skb, udp_recvmsg);
108954 if (!peeked) {
108955- atomic_inc(&sk->sk_drops);
108956+ atomic_inc_unchecked(&sk->sk_drops);
108957 UDP_INC_STATS_USER(sock_net(sk),
108958 UDP_MIB_INERRORS, is_udplite);
108959 }
108960@@ -1612,7 +1633,7 @@ csum_error:
108961 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
108962 drop:
108963 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
108964- atomic_inc(&sk->sk_drops);
108965+ atomic_inc_unchecked(&sk->sk_drops);
108966 kfree_skb(skb);
108967 return -1;
108968 }
108969@@ -1631,7 +1652,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
108970 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
108971
108972 if (!skb1) {
108973- atomic_inc(&sk->sk_drops);
108974+ atomic_inc_unchecked(&sk->sk_drops);
108975 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
108976 IS_UDPLITE(sk));
108977 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
108978@@ -1817,6 +1838,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
108979 goto csum_error;
108980
108981 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
108982+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108983+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
108984+#endif
108985 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
108986
108987 /*
108988@@ -2403,7 +2427,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
108989 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
108990 0, sock_i_ino(sp),
108991 atomic_read(&sp->sk_refcnt), sp,
108992- atomic_read(&sp->sk_drops));
108993+ atomic_read_unchecked(&sp->sk_drops));
108994 }
108995
108996 int udp4_seq_show(struct seq_file *seq, void *v)
108997diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
108998index 6156f68..d6ab46d 100644
108999--- a/net/ipv4/xfrm4_policy.c
109000+++ b/net/ipv4/xfrm4_policy.c
109001@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
109002 fl4->flowi4_tos = iph->tos;
109003 }
109004
109005-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
109006+static int xfrm4_garbage_collect(struct dst_ops *ops)
109007 {
109008 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
109009
109010- xfrm4_policy_afinfo.garbage_collect(net);
109011+ xfrm_garbage_collect_deferred(net);
109012 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
109013 }
109014
109015@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
109016
109017 static int __net_init xfrm4_net_init(struct net *net)
109018 {
109019- struct ctl_table *table;
109020+ ctl_table_no_const *table = NULL;
109021 struct ctl_table_header *hdr;
109022
109023- table = xfrm4_policy_table;
109024 if (!net_eq(net, &init_net)) {
109025- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
109026+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
109027 if (!table)
109028 goto err_alloc;
109029
109030 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
109031- }
109032-
109033- hdr = register_net_sysctl(net, "net/ipv4", table);
109034+ hdr = register_net_sysctl(net, "net/ipv4", table);
109035+ } else
109036+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
109037 if (!hdr)
109038 goto err_reg;
109039
109040@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
109041 return 0;
109042
109043 err_reg:
109044- if (!net_eq(net, &init_net))
109045- kfree(table);
109046+ kfree(table);
109047 err_alloc:
109048 return -ENOMEM;
109049 }
109050diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
109051index 5667b30..9b1b876 100644
109052--- a/net/ipv6/addrconf.c
109053+++ b/net/ipv6/addrconf.c
109054@@ -593,7 +593,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
109055 idx = 0;
109056 head = &net->dev_index_head[h];
109057 rcu_read_lock();
109058- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
109059+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
109060 net->dev_base_seq;
109061 hlist_for_each_entry_rcu(dev, head, index_hlist) {
109062 if (idx < s_idx)
109063@@ -2390,7 +2390,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
109064 p.iph.ihl = 5;
109065 p.iph.protocol = IPPROTO_IPV6;
109066 p.iph.ttl = 64;
109067- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
109068+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
109069
109070 if (ops->ndo_do_ioctl) {
109071 mm_segment_t oldfs = get_fs();
109072@@ -3516,16 +3516,23 @@ static const struct file_operations if6_fops = {
109073 .release = seq_release_net,
109074 };
109075
109076+extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
109077+extern void unregister_ipv6_seq_ops_addr(void);
109078+
109079 static int __net_init if6_proc_net_init(struct net *net)
109080 {
109081- if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
109082+ register_ipv6_seq_ops_addr(&if6_seq_ops);
109083+ if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
109084+ unregister_ipv6_seq_ops_addr();
109085 return -ENOMEM;
109086+ }
109087 return 0;
109088 }
109089
109090 static void __net_exit if6_proc_net_exit(struct net *net)
109091 {
109092 remove_proc_entry("if_inet6", net->proc_net);
109093+ unregister_ipv6_seq_ops_addr();
109094 }
109095
109096 static struct pernet_operations if6_proc_net_ops = {
109097@@ -4141,7 +4148,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
109098 s_ip_idx = ip_idx = cb->args[2];
109099
109100 rcu_read_lock();
109101- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
109102+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
109103 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
109104 idx = 0;
109105 head = &net->dev_index_head[h];
109106@@ -4753,7 +4760,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
109107 dst_free(&ifp->rt->dst);
109108 break;
109109 }
109110- atomic_inc(&net->ipv6.dev_addr_genid);
109111+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
109112 rt_genid_bump_ipv6(net);
109113 }
109114
109115@@ -4774,7 +4781,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
109116 int *valp = ctl->data;
109117 int val = *valp;
109118 loff_t pos = *ppos;
109119- struct ctl_table lctl;
109120+ ctl_table_no_const lctl;
109121 int ret;
109122
109123 /*
109124@@ -4859,7 +4866,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
109125 int *valp = ctl->data;
109126 int val = *valp;
109127 loff_t pos = *ppos;
109128- struct ctl_table lctl;
109129+ ctl_table_no_const lctl;
109130 int ret;
109131
109132 /*
109133diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
109134index 7cb4392..dc96d28 100644
109135--- a/net/ipv6/af_inet6.c
109136+++ b/net/ipv6/af_inet6.c
109137@@ -765,7 +765,7 @@ static int __net_init inet6_net_init(struct net *net)
109138 net->ipv6.sysctl.bindv6only = 0;
109139 net->ipv6.sysctl.icmpv6_time = 1*HZ;
109140 net->ipv6.sysctl.flowlabel_consistency = 1;
109141- atomic_set(&net->ipv6.rt_genid, 0);
109142+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
109143
109144 err = ipv6_init_mibs(net);
109145 if (err)
109146diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
109147index c3bf2d2..1f00573 100644
109148--- a/net/ipv6/datagram.c
109149+++ b/net/ipv6/datagram.c
109150@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
109151 0,
109152 sock_i_ino(sp),
109153 atomic_read(&sp->sk_refcnt), sp,
109154- atomic_read(&sp->sk_drops));
109155+ atomic_read_unchecked(&sp->sk_drops));
109156 }
109157diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
109158index f6c84a6..9f2084e 100644
109159--- a/net/ipv6/icmp.c
109160+++ b/net/ipv6/icmp.c
109161@@ -990,7 +990,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
109162
109163 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
109164 {
109165- struct ctl_table *table;
109166+ ctl_table_no_const *table;
109167
109168 table = kmemdup(ipv6_icmp_table_template,
109169 sizeof(ipv6_icmp_table_template),
109170diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
109171index 3873181..220ad3f 100644
109172--- a/net/ipv6/ip6_gre.c
109173+++ b/net/ipv6/ip6_gre.c
109174@@ -71,8 +71,8 @@ struct ip6gre_net {
109175 struct net_device *fb_tunnel_dev;
109176 };
109177
109178-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
109179-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
109180+static struct rtnl_link_ops ip6gre_link_ops;
109181+static struct rtnl_link_ops ip6gre_tap_ops;
109182 static int ip6gre_tunnel_init(struct net_device *dev);
109183 static void ip6gre_tunnel_setup(struct net_device *dev);
109184 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
109185@@ -1280,7 +1280,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
109186 }
109187
109188
109189-static struct inet6_protocol ip6gre_protocol __read_mostly = {
109190+static struct inet6_protocol ip6gre_protocol = {
109191 .handler = ip6gre_rcv,
109192 .err_handler = ip6gre_err,
109193 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
109194@@ -1638,7 +1638,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
109195 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
109196 };
109197
109198-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
109199+static struct rtnl_link_ops ip6gre_link_ops = {
109200 .kind = "ip6gre",
109201 .maxtype = IFLA_GRE_MAX,
109202 .policy = ip6gre_policy,
109203@@ -1652,7 +1652,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
109204 .fill_info = ip6gre_fill_info,
109205 };
109206
109207-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
109208+static struct rtnl_link_ops ip6gre_tap_ops = {
109209 .kind = "ip6gretap",
109210 .maxtype = IFLA_GRE_MAX,
109211 .policy = ip6gre_policy,
109212diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
109213index afa0824..04ba530 100644
109214--- a/net/ipv6/ip6_tunnel.c
109215+++ b/net/ipv6/ip6_tunnel.c
109216@@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
109217
109218 static int ip6_tnl_dev_init(struct net_device *dev);
109219 static void ip6_tnl_dev_setup(struct net_device *dev);
109220-static struct rtnl_link_ops ip6_link_ops __read_mostly;
109221+static struct rtnl_link_ops ip6_link_ops;
109222
109223 static int ip6_tnl_net_id __read_mostly;
109224 struct ip6_tnl_net {
109225@@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
109226 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
109227 };
109228
109229-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
109230+static struct rtnl_link_ops ip6_link_ops = {
109231 .kind = "ip6tnl",
109232 .maxtype = IFLA_IPTUN_MAX,
109233 .policy = ip6_tnl_policy,
109234diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
109235index 9aaa6bb..5c13e57 100644
109236--- a/net/ipv6/ip6_vti.c
109237+++ b/net/ipv6/ip6_vti.c
109238@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
109239
109240 static int vti6_dev_init(struct net_device *dev);
109241 static void vti6_dev_setup(struct net_device *dev);
109242-static struct rtnl_link_ops vti6_link_ops __read_mostly;
109243+static struct rtnl_link_ops vti6_link_ops;
109244
109245 static int vti6_net_id __read_mostly;
109246 struct vti6_net {
109247@@ -977,7 +977,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
109248 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
109249 };
109250
109251-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
109252+static struct rtnl_link_ops vti6_link_ops = {
109253 .kind = "vti6",
109254 .maxtype = IFLA_VTI_MAX,
109255 .policy = vti6_policy,
109256diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
109257index edb58af..78de133 100644
109258--- a/net/ipv6/ipv6_sockglue.c
109259+++ b/net/ipv6/ipv6_sockglue.c
109260@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
109261 if (sk->sk_type != SOCK_STREAM)
109262 return -ENOPROTOOPT;
109263
109264- msg.msg_control = optval;
109265+ msg.msg_control = (void __force_kernel *)optval;
109266 msg.msg_controllen = len;
109267 msg.msg_flags = flags;
109268
109269diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
109270index e080fbb..412b3cf 100644
109271--- a/net/ipv6/netfilter/ip6_tables.c
109272+++ b/net/ipv6/netfilter/ip6_tables.c
109273@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
109274 #endif
109275
109276 static int get_info(struct net *net, void __user *user,
109277- const int *len, int compat)
109278+ int len, int compat)
109279 {
109280 char name[XT_TABLE_MAXNAMELEN];
109281 struct xt_table *t;
109282 int ret;
109283
109284- if (*len != sizeof(struct ip6t_getinfo)) {
109285- duprintf("length %u != %zu\n", *len,
109286+ if (len != sizeof(struct ip6t_getinfo)) {
109287+ duprintf("length %u != %zu\n", len,
109288 sizeof(struct ip6t_getinfo));
109289 return -EINVAL;
109290 }
109291@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
109292 info.size = private->size;
109293 strcpy(info.name, name);
109294
109295- if (copy_to_user(user, &info, *len) != 0)
109296+ if (copy_to_user(user, &info, len) != 0)
109297 ret = -EFAULT;
109298 else
109299 ret = 0;
109300@@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
109301
109302 switch (cmd) {
109303 case IP6T_SO_GET_INFO:
109304- ret = get_info(sock_net(sk), user, len, 1);
109305+ ret = get_info(sock_net(sk), user, *len, 1);
109306 break;
109307 case IP6T_SO_GET_ENTRIES:
109308 ret = compat_get_entries(sock_net(sk), user, len);
109309@@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
109310
109311 switch (cmd) {
109312 case IP6T_SO_GET_INFO:
109313- ret = get_info(sock_net(sk), user, len, 0);
109314+ ret = get_info(sock_net(sk), user, *len, 0);
109315 break;
109316
109317 case IP6T_SO_GET_ENTRIES:
109318diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
109319index 0d5279f..89d9f6f 100644
109320--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
109321+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
109322@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
109323
109324 static int nf_ct_frag6_sysctl_register(struct net *net)
109325 {
109326- struct ctl_table *table;
109327+ ctl_table_no_const *table = NULL;
109328 struct ctl_table_header *hdr;
109329
109330- table = nf_ct_frag6_sysctl_table;
109331 if (!net_eq(net, &init_net)) {
109332- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
109333+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
109334 GFP_KERNEL);
109335 if (table == NULL)
109336 goto err_alloc;
109337@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
109338 table[0].data = &net->nf_frag.frags.timeout;
109339 table[1].data = &net->nf_frag.frags.low_thresh;
109340 table[2].data = &net->nf_frag.frags.high_thresh;
109341- }
109342-
109343- hdr = register_net_sysctl(net, "net/netfilter", table);
109344+ hdr = register_net_sysctl(net, "net/netfilter", table);
109345+ } else
109346+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
109347 if (hdr == NULL)
109348 goto err_reg;
109349
109350@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
109351 return 0;
109352
109353 err_reg:
109354- if (!net_eq(net, &init_net))
109355- kfree(table);
109356+ kfree(table);
109357 err_alloc:
109358 return -ENOMEM;
109359 }
109360diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
109361index 5b7a1ed..d9da205 100644
109362--- a/net/ipv6/ping.c
109363+++ b/net/ipv6/ping.c
109364@@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
109365 };
109366 #endif
109367
109368+static struct pingv6_ops real_pingv6_ops = {
109369+ .ipv6_recv_error = ipv6_recv_error,
109370+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
109371+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
109372+ .icmpv6_err_convert = icmpv6_err_convert,
109373+ .ipv6_icmp_error = ipv6_icmp_error,
109374+ .ipv6_chk_addr = ipv6_chk_addr,
109375+};
109376+
109377+static struct pingv6_ops dummy_pingv6_ops = {
109378+ .ipv6_recv_error = dummy_ipv6_recv_error,
109379+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
109380+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
109381+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
109382+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
109383+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
109384+};
109385+
109386 int __init pingv6_init(void)
109387 {
109388 #ifdef CONFIG_PROC_FS
109389@@ -247,13 +265,7 @@ int __init pingv6_init(void)
109390 if (ret)
109391 return ret;
109392 #endif
109393- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
109394- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
109395- pingv6_ops.ip6_datagram_recv_specific_ctl =
109396- ip6_datagram_recv_specific_ctl;
109397- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
109398- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
109399- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
109400+ pingv6_ops = &real_pingv6_ops;
109401 return inet6_register_protosw(&pingv6_protosw);
109402 }
109403
109404@@ -262,14 +274,9 @@ int __init pingv6_init(void)
109405 */
109406 void pingv6_exit(void)
109407 {
109408- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
109409- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
109410- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
109411- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
109412- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
109413- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
109414 #ifdef CONFIG_PROC_FS
109415 unregister_pernet_subsys(&ping_v6_net_ops);
109416 #endif
109417+ pingv6_ops = &dummy_pingv6_ops;
109418 inet6_unregister_protosw(&pingv6_protosw);
109419 }
109420diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
109421index 3317440..201764e 100644
109422--- a/net/ipv6/proc.c
109423+++ b/net/ipv6/proc.c
109424@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
109425 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
109426 goto proc_snmp6_fail;
109427
109428- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
109429+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
109430 if (!net->mib.proc_net_devsnmp6)
109431 goto proc_dev_snmp6_fail;
109432 return 0;
109433diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
109434index b2dc60b..a6b6c10 100644
109435--- a/net/ipv6/raw.c
109436+++ b/net/ipv6/raw.c
109437@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
109438 {
109439 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
109440 skb_checksum_complete(skb)) {
109441- atomic_inc(&sk->sk_drops);
109442+ atomic_inc_unchecked(&sk->sk_drops);
109443 kfree_skb(skb);
109444 return NET_RX_DROP;
109445 }
109446@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
109447 struct raw6_sock *rp = raw6_sk(sk);
109448
109449 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
109450- atomic_inc(&sk->sk_drops);
109451+ atomic_inc_unchecked(&sk->sk_drops);
109452 kfree_skb(skb);
109453 return NET_RX_DROP;
109454 }
109455@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
109456
109457 if (inet->hdrincl) {
109458 if (skb_checksum_complete(skb)) {
109459- atomic_inc(&sk->sk_drops);
109460+ atomic_inc_unchecked(&sk->sk_drops);
109461 kfree_skb(skb);
109462 return NET_RX_DROP;
109463 }
109464@@ -610,7 +610,7 @@ out:
109465 return err;
109466 }
109467
109468-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
109469+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
109470 struct flowi6 *fl6, struct dst_entry **dstp,
109471 unsigned int flags)
109472 {
109473@@ -916,12 +916,15 @@ do_confirm:
109474 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
109475 char __user *optval, int optlen)
109476 {
109477+ struct icmp6_filter filter;
109478+
109479 switch (optname) {
109480 case ICMPV6_FILTER:
109481 if (optlen > sizeof(struct icmp6_filter))
109482 optlen = sizeof(struct icmp6_filter);
109483- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
109484+ if (copy_from_user(&filter, optval, optlen))
109485 return -EFAULT;
109486+ raw6_sk(sk)->filter = filter;
109487 return 0;
109488 default:
109489 return -ENOPROTOOPT;
109490@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
109491 char __user *optval, int __user *optlen)
109492 {
109493 int len;
109494+ struct icmp6_filter filter;
109495
109496 switch (optname) {
109497 case ICMPV6_FILTER:
109498@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
109499 len = sizeof(struct icmp6_filter);
109500 if (put_user(len, optlen))
109501 return -EFAULT;
109502- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
109503+ filter = raw6_sk(sk)->filter;
109504+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
109505 return -EFAULT;
109506 return 0;
109507 default:
109508diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
109509index cc85a9b..526a133 100644
109510--- a/net/ipv6/reassembly.c
109511+++ b/net/ipv6/reassembly.c
109512@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
109513
109514 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
109515 {
109516- struct ctl_table *table;
109517+ ctl_table_no_const *table = NULL;
109518 struct ctl_table_header *hdr;
109519
109520- table = ip6_frags_ns_ctl_table;
109521 if (!net_eq(net, &init_net)) {
109522- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
109523+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
109524 if (table == NULL)
109525 goto err_alloc;
109526
109527@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
109528 /* Don't export sysctls to unprivileged users */
109529 if (net->user_ns != &init_user_ns)
109530 table[0].procname = NULL;
109531- }
109532+ hdr = register_net_sysctl(net, "net/ipv6", table);
109533+ } else
109534+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
109535
109536- hdr = register_net_sysctl(net, "net/ipv6", table);
109537 if (hdr == NULL)
109538 goto err_reg;
109539
109540@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
109541 return 0;
109542
109543 err_reg:
109544- if (!net_eq(net, &init_net))
109545- kfree(table);
109546+ kfree(table);
109547 err_alloc:
109548 return -ENOMEM;
109549 }
109550diff --git a/net/ipv6/route.c b/net/ipv6/route.c
109551index f23fbd2..7868241 100644
109552--- a/net/ipv6/route.c
109553+++ b/net/ipv6/route.c
109554@@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
109555
109556 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
109557 {
109558- struct ctl_table *table;
109559+ ctl_table_no_const *table;
109560
109561 table = kmemdup(ipv6_route_table_template,
109562 sizeof(ipv6_route_table_template),
109563diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
109564index 4f40817..54dcbef 100644
109565--- a/net/ipv6/sit.c
109566+++ b/net/ipv6/sit.c
109567@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
109568 static void ipip6_dev_free(struct net_device *dev);
109569 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
109570 __be32 *v4dst);
109571-static struct rtnl_link_ops sit_link_ops __read_mostly;
109572+static struct rtnl_link_ops sit_link_ops;
109573
109574 static int sit_net_id __read_mostly;
109575 struct sit_net {
109576@@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
109577 unregister_netdevice_queue(dev, head);
109578 }
109579
109580-static struct rtnl_link_ops sit_link_ops __read_mostly = {
109581+static struct rtnl_link_ops sit_link_ops = {
109582 .kind = "sit",
109583 .maxtype = IFLA_IPTUN_MAX,
109584 .policy = ipip6_policy,
109585diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
109586index 058f3ec..dec973d 100644
109587--- a/net/ipv6/sysctl_net_ipv6.c
109588+++ b/net/ipv6/sysctl_net_ipv6.c
109589@@ -61,7 +61,7 @@ static struct ctl_table ipv6_rotable[] = {
109590
109591 static int __net_init ipv6_sysctl_net_init(struct net *net)
109592 {
109593- struct ctl_table *ipv6_table;
109594+ ctl_table_no_const *ipv6_table;
109595 struct ctl_table *ipv6_route_table;
109596 struct ctl_table *ipv6_icmp_table;
109597 int err;
109598diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
109599index 229239ad..ee2802f 100644
109600--- a/net/ipv6/tcp_ipv6.c
109601+++ b/net/ipv6/tcp_ipv6.c
109602@@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
109603 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
109604 }
109605
109606+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109607+extern int grsec_enable_blackhole;
109608+#endif
109609+
109610 static void tcp_v6_hash(struct sock *sk)
109611 {
109612 if (sk->sk_state != TCP_CLOSE) {
109613@@ -1424,6 +1428,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
109614 return 0;
109615
109616 reset:
109617+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109618+ if (!grsec_enable_blackhole)
109619+#endif
109620 tcp_v6_send_reset(sk, skb);
109621 discard:
109622 if (opt_skb)
109623@@ -1508,12 +1515,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
109624 TCP_SKB_CB(skb)->sacked = 0;
109625
109626 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
109627- if (!sk)
109628+ if (!sk) {
109629+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109630+ ret = 1;
109631+#endif
109632 goto no_tcp_socket;
109633+ }
109634
109635 process:
109636- if (sk->sk_state == TCP_TIME_WAIT)
109637+ if (sk->sk_state == TCP_TIME_WAIT) {
109638+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109639+ ret = 2;
109640+#endif
109641 goto do_time_wait;
109642+ }
109643
109644 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
109645 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
109646@@ -1565,6 +1580,10 @@ csum_error:
109647 bad_packet:
109648 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
109649 } else {
109650+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109651+ if (!grsec_enable_blackhole || (ret == 1 &&
109652+ (skb->dev->flags & IFF_LOOPBACK)))
109653+#endif
109654 tcp_v6_send_reset(NULL, skb);
109655 }
109656
109657diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
109658index 7092ff7..3fd0eb4 100644
109659--- a/net/ipv6/udp.c
109660+++ b/net/ipv6/udp.c
109661@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
109662 udp_ipv6_hash_secret + net_hash_mix(net));
109663 }
109664
109665+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109666+extern int grsec_enable_blackhole;
109667+#endif
109668+
109669 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
109670 {
109671 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
109672@@ -435,7 +439,7 @@ try_again:
109673 if (unlikely(err)) {
109674 trace_kfree_skb(skb, udpv6_recvmsg);
109675 if (!peeked) {
109676- atomic_inc(&sk->sk_drops);
109677+ atomic_inc_unchecked(&sk->sk_drops);
109678 if (is_udp4)
109679 UDP_INC_STATS_USER(sock_net(sk),
109680 UDP_MIB_INERRORS,
109681@@ -698,7 +702,7 @@ csum_error:
109682 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
109683 drop:
109684 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
109685- atomic_inc(&sk->sk_drops);
109686+ atomic_inc_unchecked(&sk->sk_drops);
109687 kfree_skb(skb);
109688 return -1;
109689 }
109690@@ -754,7 +758,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
109691 if (likely(skb1 == NULL))
109692 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
109693 if (!skb1) {
109694- atomic_inc(&sk->sk_drops);
109695+ atomic_inc_unchecked(&sk->sk_drops);
109696 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
109697 IS_UDPLITE(sk));
109698 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
109699@@ -920,6 +924,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
109700 goto csum_error;
109701
109702 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
109703+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109704+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
109705+#endif
109706 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
109707
109708 kfree_skb(skb);
109709diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
109710index 2a0bbda..d75ca57 100644
109711--- a/net/ipv6/xfrm6_policy.c
109712+++ b/net/ipv6/xfrm6_policy.c
109713@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
109714 }
109715 }
109716
109717-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
109718+static int xfrm6_garbage_collect(struct dst_ops *ops)
109719 {
109720 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
109721
109722- xfrm6_policy_afinfo.garbage_collect(net);
109723+ xfrm_garbage_collect_deferred(net);
109724 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
109725 }
109726
109727@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
109728
109729 static int __net_init xfrm6_net_init(struct net *net)
109730 {
109731- struct ctl_table *table;
109732+ ctl_table_no_const *table = NULL;
109733 struct ctl_table_header *hdr;
109734
109735- table = xfrm6_policy_table;
109736 if (!net_eq(net, &init_net)) {
109737- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
109738+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
109739 if (!table)
109740 goto err_alloc;
109741
109742 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
109743- }
109744+ hdr = register_net_sysctl(net, "net/ipv6", table);
109745+ } else
109746+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
109747
109748- hdr = register_net_sysctl(net, "net/ipv6", table);
109749 if (!hdr)
109750 goto err_reg;
109751
109752@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
109753 return 0;
109754
109755 err_reg:
109756- if (!net_eq(net, &init_net))
109757- kfree(table);
109758+ kfree(table);
109759 err_alloc:
109760 return -ENOMEM;
109761 }
109762diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
109763index e15c16a..7cf07aa 100644
109764--- a/net/ipx/ipx_proc.c
109765+++ b/net/ipx/ipx_proc.c
109766@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
109767 struct proc_dir_entry *p;
109768 int rc = -ENOMEM;
109769
109770- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
109771+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
109772
109773 if (!ipx_proc_dir)
109774 goto out;
109775diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
109776index 2ba8b97..6d33010 100644
109777--- a/net/irda/ircomm/ircomm_tty.c
109778+++ b/net/irda/ircomm/ircomm_tty.c
109779@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
109780 add_wait_queue(&port->open_wait, &wait);
109781
109782 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
109783- __FILE__, __LINE__, tty->driver->name, port->count);
109784+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
109785
109786 spin_lock_irqsave(&port->lock, flags);
109787 if (!tty_hung_up_p(filp))
109788- port->count--;
109789+ atomic_dec(&port->count);
109790 port->blocked_open++;
109791 spin_unlock_irqrestore(&port->lock, flags);
109792
109793@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
109794 }
109795
109796 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
109797- __FILE__, __LINE__, tty->driver->name, port->count);
109798+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
109799
109800 schedule();
109801 }
109802@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
109803
109804 spin_lock_irqsave(&port->lock, flags);
109805 if (!tty_hung_up_p(filp))
109806- port->count++;
109807+ atomic_inc(&port->count);
109808 port->blocked_open--;
109809 spin_unlock_irqrestore(&port->lock, flags);
109810
109811 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
109812- __FILE__, __LINE__, tty->driver->name, port->count);
109813+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
109814
109815 if (!retval)
109816 port->flags |= ASYNC_NORMAL_ACTIVE;
109817@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
109818
109819 /* ++ is not atomic, so this should be protected - Jean II */
109820 spin_lock_irqsave(&self->port.lock, flags);
109821- self->port.count++;
109822+ atomic_inc(&self->port.count);
109823 spin_unlock_irqrestore(&self->port.lock, flags);
109824 tty_port_tty_set(&self->port, tty);
109825
109826 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
109827- self->line, self->port.count);
109828+ self->line, atomic_read(&self->port.count));
109829
109830 /* Not really used by us, but lets do it anyway */
109831 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
109832@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
109833 tty_kref_put(port->tty);
109834 }
109835 port->tty = NULL;
109836- port->count = 0;
109837+ atomic_set(&port->count, 0);
109838 spin_unlock_irqrestore(&port->lock, flags);
109839
109840 wake_up_interruptible(&port->open_wait);
109841@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
109842 seq_putc(m, '\n');
109843
109844 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
109845- seq_printf(m, "Open count: %d\n", self->port.count);
109846+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
109847 seq_printf(m, "Max data size: %d\n", self->max_data_size);
109848 seq_printf(m, "Max header size: %d\n", self->max_header_size);
109849
109850diff --git a/net/irda/irproc.c b/net/irda/irproc.c
109851index b9ac598..f88cc56 100644
109852--- a/net/irda/irproc.c
109853+++ b/net/irda/irproc.c
109854@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
109855 {
109856 int i;
109857
109858- proc_irda = proc_mkdir("irda", init_net.proc_net);
109859+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
109860 if (proc_irda == NULL)
109861 return;
109862
109863diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
109864index 7a95fa4..57be196 100644
109865--- a/net/iucv/af_iucv.c
109866+++ b/net/iucv/af_iucv.c
109867@@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
109868 {
109869 char name[12];
109870
109871- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
109872+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
109873 while (__iucv_get_sock_by_name(name)) {
109874 sprintf(name, "%08x",
109875- atomic_inc_return(&iucv_sk_list.autobind_name));
109876+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
109877 }
109878 memcpy(iucv->src_name, name, 8);
109879 }
109880diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
109881index da78793..bdd78cf 100644
109882--- a/net/iucv/iucv.c
109883+++ b/net/iucv/iucv.c
109884@@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
109885 return NOTIFY_OK;
109886 }
109887
109888-static struct notifier_block __refdata iucv_cpu_notifier = {
109889+static struct notifier_block iucv_cpu_notifier = {
109890 .notifier_call = iucv_cpu_notify,
109891 };
109892
109893diff --git a/net/key/af_key.c b/net/key/af_key.c
109894index ba2a2f9..b658bc3 100644
109895--- a/net/key/af_key.c
109896+++ b/net/key/af_key.c
109897@@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
109898 static u32 get_acqseq(void)
109899 {
109900 u32 res;
109901- static atomic_t acqseq;
109902+ static atomic_unchecked_t acqseq;
109903
109904 do {
109905- res = atomic_inc_return(&acqseq);
109906+ res = atomic_inc_return_unchecked(&acqseq);
109907 } while (!res);
109908 return res;
109909 }
109910diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
109911index 76125c5..e474828 100644
109912--- a/net/l2tp/l2tp_eth.c
109913+++ b/net/l2tp/l2tp_eth.c
109914@@ -42,12 +42,12 @@ struct l2tp_eth {
109915 struct sock *tunnel_sock;
109916 struct l2tp_session *session;
109917 struct list_head list;
109918- atomic_long_t tx_bytes;
109919- atomic_long_t tx_packets;
109920- atomic_long_t tx_dropped;
109921- atomic_long_t rx_bytes;
109922- atomic_long_t rx_packets;
109923- atomic_long_t rx_errors;
109924+ atomic_long_unchecked_t tx_bytes;
109925+ atomic_long_unchecked_t tx_packets;
109926+ atomic_long_unchecked_t tx_dropped;
109927+ atomic_long_unchecked_t rx_bytes;
109928+ atomic_long_unchecked_t rx_packets;
109929+ atomic_long_unchecked_t rx_errors;
109930 };
109931
109932 /* via l2tp_session_priv() */
109933@@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
109934 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
109935
109936 if (likely(ret == NET_XMIT_SUCCESS)) {
109937- atomic_long_add(len, &priv->tx_bytes);
109938- atomic_long_inc(&priv->tx_packets);
109939+ atomic_long_add_unchecked(len, &priv->tx_bytes);
109940+ atomic_long_inc_unchecked(&priv->tx_packets);
109941 } else {
109942- atomic_long_inc(&priv->tx_dropped);
109943+ atomic_long_inc_unchecked(&priv->tx_dropped);
109944 }
109945 return NETDEV_TX_OK;
109946 }
109947@@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
109948 {
109949 struct l2tp_eth *priv = netdev_priv(dev);
109950
109951- stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
109952- stats->tx_packets = atomic_long_read(&priv->tx_packets);
109953- stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
109954- stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
109955- stats->rx_packets = atomic_long_read(&priv->rx_packets);
109956- stats->rx_errors = atomic_long_read(&priv->rx_errors);
109957+ stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
109958+ stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
109959+ stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
109960+ stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
109961+ stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
109962+ stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
109963 return stats;
109964 }
109965
109966@@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
109967 nf_reset(skb);
109968
109969 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
109970- atomic_long_inc(&priv->rx_packets);
109971- atomic_long_add(data_len, &priv->rx_bytes);
109972+ atomic_long_inc_unchecked(&priv->rx_packets);
109973+ atomic_long_add_unchecked(data_len, &priv->rx_bytes);
109974 } else {
109975- atomic_long_inc(&priv->rx_errors);
109976+ atomic_long_inc_unchecked(&priv->rx_errors);
109977 }
109978 return;
109979
109980 error:
109981- atomic_long_inc(&priv->rx_errors);
109982+ atomic_long_inc_unchecked(&priv->rx_errors);
109983 kfree_skb(skb);
109984 }
109985
109986diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
109987index 1a3c7e0..80f8b0c 100644
109988--- a/net/llc/llc_proc.c
109989+++ b/net/llc/llc_proc.c
109990@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
109991 int rc = -ENOMEM;
109992 struct proc_dir_entry *p;
109993
109994- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
109995+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
109996 if (!llc_proc_dir)
109997 goto out;
109998
109999diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
110000index 592f4b1..efa7aa9 100644
110001--- a/net/mac80211/cfg.c
110002+++ b/net/mac80211/cfg.c
110003@@ -864,7 +864,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
110004 ret = ieee80211_vif_use_channel(sdata, chandef,
110005 IEEE80211_CHANCTX_EXCLUSIVE);
110006 }
110007- } else if (local->open_count == local->monitors) {
110008+ } else if (local_read(&local->open_count) == local->monitors) {
110009 local->_oper_chandef = *chandef;
110010 ieee80211_hw_config(local, 0);
110011 }
110012@@ -3574,7 +3574,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
110013 else
110014 local->probe_req_reg--;
110015
110016- if (!local->open_count)
110017+ if (!local_read(&local->open_count))
110018 break;
110019
110020 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
110021@@ -3723,8 +3723,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
110022 if (chanctx_conf) {
110023 *chandef = chanctx_conf->def;
110024 ret = 0;
110025- } else if (local->open_count > 0 &&
110026- local->open_count == local->monitors &&
110027+ } else if (local_read(&local->open_count) > 0 &&
110028+ local_read(&local->open_count) == local->monitors &&
110029 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
110030 if (local->use_chanctx)
110031 *chandef = local->monitor_chandef;
110032diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
110033index ac9836e..32613c1 100644
110034--- a/net/mac80211/ieee80211_i.h
110035+++ b/net/mac80211/ieee80211_i.h
110036@@ -28,6 +28,7 @@
110037 #include <net/ieee80211_radiotap.h>
110038 #include <net/cfg80211.h>
110039 #include <net/mac80211.h>
110040+#include <asm/local.h>
110041 #include "key.h"
110042 #include "sta_info.h"
110043 #include "debug.h"
110044@@ -1011,7 +1012,7 @@ struct ieee80211_local {
110045 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
110046 spinlock_t queue_stop_reason_lock;
110047
110048- int open_count;
110049+ local_t open_count;
110050 int monitors, cooked_mntrs;
110051 /* number of interfaces with corresponding FIF_ flags */
110052 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
110053diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
110054index 388b863..6575b55 100644
110055--- a/net/mac80211/iface.c
110056+++ b/net/mac80211/iface.c
110057@@ -531,7 +531,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
110058 break;
110059 }
110060
110061- if (local->open_count == 0) {
110062+ if (local_read(&local->open_count) == 0) {
110063 res = drv_start(local);
110064 if (res)
110065 goto err_del_bss;
110066@@ -578,7 +578,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
110067 res = drv_add_interface(local, sdata);
110068 if (res)
110069 goto err_stop;
110070- } else if (local->monitors == 0 && local->open_count == 0) {
110071+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
110072 res = ieee80211_add_virtual_monitor(local);
110073 if (res)
110074 goto err_stop;
110075@@ -687,7 +687,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
110076 atomic_inc(&local->iff_promiscs);
110077
110078 if (coming_up)
110079- local->open_count++;
110080+ local_inc(&local->open_count);
110081
110082 if (hw_reconf_flags)
110083 ieee80211_hw_config(local, hw_reconf_flags);
110084@@ -725,7 +725,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
110085 err_del_interface:
110086 drv_remove_interface(local, sdata);
110087 err_stop:
110088- if (!local->open_count)
110089+ if (!local_read(&local->open_count))
110090 drv_stop(local);
110091 err_del_bss:
110092 sdata->bss = NULL;
110093@@ -888,7 +888,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
110094 }
110095
110096 if (going_down)
110097- local->open_count--;
110098+ local_dec(&local->open_count);
110099
110100 switch (sdata->vif.type) {
110101 case NL80211_IFTYPE_AP_VLAN:
110102@@ -949,7 +949,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
110103 }
110104 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
110105
110106- if (local->open_count == 0)
110107+ if (local_read(&local->open_count) == 0)
110108 ieee80211_clear_tx_pending(local);
110109
110110 /*
110111@@ -989,7 +989,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
110112
110113 ieee80211_recalc_ps(local, -1);
110114
110115- if (local->open_count == 0) {
110116+ if (local_read(&local->open_count) == 0) {
110117 ieee80211_stop_device(local);
110118
110119 /* no reconfiguring after stop! */
110120@@ -1000,7 +1000,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
110121 ieee80211_configure_filter(local);
110122 ieee80211_hw_config(local, hw_reconf_flags);
110123
110124- if (local->monitors == local->open_count)
110125+ if (local->monitors == local_read(&local->open_count))
110126 ieee80211_add_virtual_monitor(local);
110127 }
110128
110129diff --git a/net/mac80211/main.c b/net/mac80211/main.c
110130index d17c26d..43d6bfb 100644
110131--- a/net/mac80211/main.c
110132+++ b/net/mac80211/main.c
110133@@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
110134 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
110135 IEEE80211_CONF_CHANGE_POWER);
110136
110137- if (changed && local->open_count) {
110138+ if (changed && local_read(&local->open_count)) {
110139 ret = drv_config(local, changed);
110140 /*
110141 * Goal:
110142diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
110143index d478b88..8c8d157 100644
110144--- a/net/mac80211/pm.c
110145+++ b/net/mac80211/pm.c
110146@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
110147 struct ieee80211_sub_if_data *sdata;
110148 struct sta_info *sta;
110149
110150- if (!local->open_count)
110151+ if (!local_read(&local->open_count))
110152 goto suspend;
110153
110154 ieee80211_scan_cancel(local);
110155@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
110156 cancel_work_sync(&local->dynamic_ps_enable_work);
110157 del_timer_sync(&local->dynamic_ps_timer);
110158
110159- local->wowlan = wowlan && local->open_count;
110160+ local->wowlan = wowlan && local_read(&local->open_count);
110161 if (local->wowlan) {
110162 int err = drv_suspend(local, wowlan);
110163 if (err < 0) {
110164@@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
110165 WARN_ON(!list_empty(&local->chanctx_list));
110166
110167 /* stop hardware - this must stop RX */
110168- if (local->open_count)
110169+ if (local_read(&local->open_count))
110170 ieee80211_stop_device(local);
110171
110172 suspend:
110173diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
110174index 8fdadfd..a4f72b8 100644
110175--- a/net/mac80211/rate.c
110176+++ b/net/mac80211/rate.c
110177@@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
110178
110179 ASSERT_RTNL();
110180
110181- if (local->open_count)
110182+ if (local_read(&local->open_count))
110183 return -EBUSY;
110184
110185 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
110186diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
110187index 6ff1346..936ca9a 100644
110188--- a/net/mac80211/rc80211_pid_debugfs.c
110189+++ b/net/mac80211/rc80211_pid_debugfs.c
110190@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
110191
110192 spin_unlock_irqrestore(&events->lock, status);
110193
110194- if (copy_to_user(buf, pb, p))
110195+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
110196 return -EFAULT;
110197
110198 return p;
110199diff --git a/net/mac80211/util.c b/net/mac80211/util.c
110200index a6cda52..f3b6776 100644
110201--- a/net/mac80211/util.c
110202+++ b/net/mac80211/util.c
110203@@ -1548,7 +1548,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
110204 }
110205 #endif
110206 /* everything else happens only if HW was up & running */
110207- if (!local->open_count)
110208+ if (!local_read(&local->open_count))
110209 goto wake_up;
110210
110211 /*
110212@@ -1772,7 +1772,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
110213 local->in_reconfig = false;
110214 barrier();
110215
110216- if (local->monitors == local->open_count && local->monitors > 0)
110217+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
110218 ieee80211_add_virtual_monitor(local);
110219
110220 /*
110221diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
110222index e9410d1..77b6378 100644
110223--- a/net/netfilter/Kconfig
110224+++ b/net/netfilter/Kconfig
110225@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
110226
110227 To compile it as a module, choose M here. If unsure, say N.
110228
110229+config NETFILTER_XT_MATCH_GRADM
110230+ tristate '"gradm" match support'
110231+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
110232+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
110233+ ---help---
110234+ The gradm match allows to match on grsecurity RBAC being enabled.
110235+ It is useful when iptables rules are applied early on bootup to
110236+ prevent connections to the machine (except from a trusted host)
110237+ while the RBAC system is disabled.
110238+
110239 config NETFILTER_XT_MATCH_HASHLIMIT
110240 tristate '"hashlimit" match support'
110241 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
110242diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
110243index bffdad7..f9317d1 100644
110244--- a/net/netfilter/Makefile
110245+++ b/net/netfilter/Makefile
110246@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
110247 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
110248 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
110249 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
110250+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
110251 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
110252 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
110253 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
110254diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
110255index ec8114f..6b2bfba 100644
110256--- a/net/netfilter/ipset/ip_set_core.c
110257+++ b/net/netfilter/ipset/ip_set_core.c
110258@@ -1921,7 +1921,7 @@ done:
110259 return ret;
110260 }
110261
110262-static struct nf_sockopt_ops so_set __read_mostly = {
110263+static struct nf_sockopt_ops so_set = {
110264 .pf = PF_INET,
110265 .get_optmin = SO_IP_SET,
110266 .get_optmax = SO_IP_SET + 1,
110267diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
110268index 610e19c..08d0c3f 100644
110269--- a/net/netfilter/ipvs/ip_vs_conn.c
110270+++ b/net/netfilter/ipvs/ip_vs_conn.c
110271@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
110272 /* Increase the refcnt counter of the dest */
110273 ip_vs_dest_hold(dest);
110274
110275- conn_flags = atomic_read(&dest->conn_flags);
110276+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
110277 if (cp->protocol != IPPROTO_UDP)
110278 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
110279 flags = cp->flags;
110280@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
110281
110282 cp->control = NULL;
110283 atomic_set(&cp->n_control, 0);
110284- atomic_set(&cp->in_pkts, 0);
110285+ atomic_set_unchecked(&cp->in_pkts, 0);
110286
110287 cp->packet_xmit = NULL;
110288 cp->app = NULL;
110289@@ -1187,7 +1187,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
110290
110291 /* Don't drop the entry if its number of incoming packets is not
110292 located in [0, 8] */
110293- i = atomic_read(&cp->in_pkts);
110294+ i = atomic_read_unchecked(&cp->in_pkts);
110295 if (i > 8 || i < 0) return 0;
110296
110297 if (!todrop_rate[i]) return 0;
110298diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
110299index e683675..67cb16b 100644
110300--- a/net/netfilter/ipvs/ip_vs_core.c
110301+++ b/net/netfilter/ipvs/ip_vs_core.c
110302@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
110303 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
110304 /* do not touch skb anymore */
110305
110306- atomic_inc(&cp->in_pkts);
110307+ atomic_inc_unchecked(&cp->in_pkts);
110308 ip_vs_conn_put(cp);
110309 return ret;
110310 }
110311@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
110312 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
110313 pkts = sysctl_sync_threshold(ipvs);
110314 else
110315- pkts = atomic_add_return(1, &cp->in_pkts);
110316+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
110317
110318 if (ipvs->sync_state & IP_VS_STATE_MASTER)
110319 ip_vs_sync_conn(net, cp, pkts);
110320diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
110321index 581a658..910e112 100644
110322--- a/net/netfilter/ipvs/ip_vs_ctl.c
110323+++ b/net/netfilter/ipvs/ip_vs_ctl.c
110324@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
110325 */
110326 ip_vs_rs_hash(ipvs, dest);
110327 }
110328- atomic_set(&dest->conn_flags, conn_flags);
110329+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
110330
110331 /* bind the service */
110332 old_svc = rcu_dereference_protected(dest->svc, 1);
110333@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
110334 * align with netns init in ip_vs_control_net_init()
110335 */
110336
110337-static struct ctl_table vs_vars[] = {
110338+static ctl_table_no_const vs_vars[] __read_only = {
110339 {
110340 .procname = "amemthresh",
110341 .maxlen = sizeof(int),
110342@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
110343 " %-7s %-6d %-10d %-10d\n",
110344 &dest->addr.in6,
110345 ntohs(dest->port),
110346- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
110347+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
110348 atomic_read(&dest->weight),
110349 atomic_read(&dest->activeconns),
110350 atomic_read(&dest->inactconns));
110351@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
110352 "%-7s %-6d %-10d %-10d\n",
110353 ntohl(dest->addr.ip),
110354 ntohs(dest->port),
110355- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
110356+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
110357 atomic_read(&dest->weight),
110358 atomic_read(&dest->activeconns),
110359 atomic_read(&dest->inactconns));
110360@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
110361
110362 entry.addr = dest->addr.ip;
110363 entry.port = dest->port;
110364- entry.conn_flags = atomic_read(&dest->conn_flags);
110365+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
110366 entry.weight = atomic_read(&dest->weight);
110367 entry.u_threshold = dest->u_threshold;
110368 entry.l_threshold = dest->l_threshold;
110369@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
110370 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
110371 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
110372 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
110373- (atomic_read(&dest->conn_flags) &
110374+ (atomic_read_unchecked(&dest->conn_flags) &
110375 IP_VS_CONN_F_FWD_MASK)) ||
110376 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
110377 atomic_read(&dest->weight)) ||
110378@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
110379 {
110380 int idx;
110381 struct netns_ipvs *ipvs = net_ipvs(net);
110382- struct ctl_table *tbl;
110383+ ctl_table_no_const *tbl;
110384
110385 atomic_set(&ipvs->dropentry, 0);
110386 spin_lock_init(&ipvs->dropentry_lock);
110387diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
110388index 547ff33..c8c8117 100644
110389--- a/net/netfilter/ipvs/ip_vs_lblc.c
110390+++ b/net/netfilter/ipvs/ip_vs_lblc.c
110391@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
110392 * IPVS LBLC sysctl table
110393 */
110394 #ifdef CONFIG_SYSCTL
110395-static struct ctl_table vs_vars_table[] = {
110396+static ctl_table_no_const vs_vars_table[] __read_only = {
110397 {
110398 .procname = "lblc_expiration",
110399 .data = NULL,
110400diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
110401index 3f21a2f..a112e85 100644
110402--- a/net/netfilter/ipvs/ip_vs_lblcr.c
110403+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
110404@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
110405 * IPVS LBLCR sysctl table
110406 */
110407
110408-static struct ctl_table vs_vars_table[] = {
110409+static ctl_table_no_const vs_vars_table[] __read_only = {
110410 {
110411 .procname = "lblcr_expiration",
110412 .data = NULL,
110413diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
110414index db80126..ef7110e 100644
110415--- a/net/netfilter/ipvs/ip_vs_sync.c
110416+++ b/net/netfilter/ipvs/ip_vs_sync.c
110417@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
110418 cp = cp->control;
110419 if (cp) {
110420 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
110421- pkts = atomic_add_return(1, &cp->in_pkts);
110422+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
110423 else
110424 pkts = sysctl_sync_threshold(ipvs);
110425 ip_vs_sync_conn(net, cp->control, pkts);
110426@@ -771,7 +771,7 @@ control:
110427 if (!cp)
110428 return;
110429 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
110430- pkts = atomic_add_return(1, &cp->in_pkts);
110431+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
110432 else
110433 pkts = sysctl_sync_threshold(ipvs);
110434 goto sloop;
110435@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
110436
110437 if (opt)
110438 memcpy(&cp->in_seq, opt, sizeof(*opt));
110439- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
110440+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
110441 cp->state = state;
110442 cp->old_state = cp->state;
110443 /*
110444diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
110445index 73ba1cc..1adfc7a 100644
110446--- a/net/netfilter/ipvs/ip_vs_xmit.c
110447+++ b/net/netfilter/ipvs/ip_vs_xmit.c
110448@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
110449 else
110450 rc = NF_ACCEPT;
110451 /* do not touch skb anymore */
110452- atomic_inc(&cp->in_pkts);
110453+ atomic_inc_unchecked(&cp->in_pkts);
110454 goto out;
110455 }
110456
110457@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
110458 else
110459 rc = NF_ACCEPT;
110460 /* do not touch skb anymore */
110461- atomic_inc(&cp->in_pkts);
110462+ atomic_inc_unchecked(&cp->in_pkts);
110463 goto out;
110464 }
110465
110466diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
110467index a4b5e2a..13b1de3 100644
110468--- a/net/netfilter/nf_conntrack_acct.c
110469+++ b/net/netfilter/nf_conntrack_acct.c
110470@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
110471 #ifdef CONFIG_SYSCTL
110472 static int nf_conntrack_acct_init_sysctl(struct net *net)
110473 {
110474- struct ctl_table *table;
110475+ ctl_table_no_const *table;
110476
110477 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
110478 GFP_KERNEL);
110479diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
110480index 1f4f954..e364ad7 100644
110481--- a/net/netfilter/nf_conntrack_core.c
110482+++ b/net/netfilter/nf_conntrack_core.c
110483@@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
110484 #define DYING_NULLS_VAL ((1<<30)+1)
110485 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
110486
110487+#ifdef CONFIG_GRKERNSEC_HIDESYM
110488+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
110489+#endif
110490+
110491 int nf_conntrack_init_net(struct net *net)
110492 {
110493 int ret = -ENOMEM;
110494@@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
110495 if (!net->ct.stat)
110496 goto err_pcpu_lists;
110497
110498+#ifdef CONFIG_GRKERNSEC_HIDESYM
110499+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
110500+#else
110501 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
110502+#endif
110503 if (!net->ct.slabname)
110504 goto err_slabname;
110505
110506diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
110507index 1df1761..ce8b88a 100644
110508--- a/net/netfilter/nf_conntrack_ecache.c
110509+++ b/net/netfilter/nf_conntrack_ecache.c
110510@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
110511 #ifdef CONFIG_SYSCTL
110512 static int nf_conntrack_event_init_sysctl(struct net *net)
110513 {
110514- struct ctl_table *table;
110515+ ctl_table_no_const *table;
110516
110517 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
110518 GFP_KERNEL);
110519diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
110520index 5b3eae7..dd4b8fe 100644
110521--- a/net/netfilter/nf_conntrack_helper.c
110522+++ b/net/netfilter/nf_conntrack_helper.c
110523@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
110524
110525 static int nf_conntrack_helper_init_sysctl(struct net *net)
110526 {
110527- struct ctl_table *table;
110528+ ctl_table_no_const *table;
110529
110530 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
110531 GFP_KERNEL);
110532diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
110533index b65d586..beec902 100644
110534--- a/net/netfilter/nf_conntrack_proto.c
110535+++ b/net/netfilter/nf_conntrack_proto.c
110536@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
110537
110538 static void
110539 nf_ct_unregister_sysctl(struct ctl_table_header **header,
110540- struct ctl_table **table,
110541+ ctl_table_no_const **table,
110542 unsigned int users)
110543 {
110544 if (users > 0)
110545diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
110546index f641751..d3c5b51 100644
110547--- a/net/netfilter/nf_conntrack_standalone.c
110548+++ b/net/netfilter/nf_conntrack_standalone.c
110549@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
110550
110551 static int nf_conntrack_standalone_init_sysctl(struct net *net)
110552 {
110553- struct ctl_table *table;
110554+ ctl_table_no_const *table;
110555
110556 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
110557 GFP_KERNEL);
110558diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
110559index 7a394df..bd91a8a 100644
110560--- a/net/netfilter/nf_conntrack_timestamp.c
110561+++ b/net/netfilter/nf_conntrack_timestamp.c
110562@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
110563 #ifdef CONFIG_SYSCTL
110564 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
110565 {
110566- struct ctl_table *table;
110567+ ctl_table_no_const *table;
110568
110569 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
110570 GFP_KERNEL);
110571diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
110572index 85296d4..8becdec 100644
110573--- a/net/netfilter/nf_log.c
110574+++ b/net/netfilter/nf_log.c
110575@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
110576
110577 #ifdef CONFIG_SYSCTL
110578 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
110579-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
110580+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
110581
110582 static int nf_log_proc_dostring(struct ctl_table *table, int write,
110583 void __user *buffer, size_t *lenp, loff_t *ppos)
110584@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
110585 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
110586 mutex_unlock(&nf_log_mutex);
110587 } else {
110588+ ctl_table_no_const nf_log_table = *table;
110589+
110590 mutex_lock(&nf_log_mutex);
110591 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
110592 lockdep_is_held(&nf_log_mutex));
110593 if (!logger)
110594- table->data = "NONE";
110595+ nf_log_table.data = "NONE";
110596 else
110597- table->data = logger->name;
110598- r = proc_dostring(table, write, buffer, lenp, ppos);
110599+ nf_log_table.data = logger->name;
110600+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
110601 mutex_unlock(&nf_log_mutex);
110602 }
110603
110604diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
110605index f042ae5..30ea486 100644
110606--- a/net/netfilter/nf_sockopt.c
110607+++ b/net/netfilter/nf_sockopt.c
110608@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
110609 }
110610 }
110611
110612- list_add(&reg->list, &nf_sockopts);
110613+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
110614 out:
110615 mutex_unlock(&nf_sockopt_mutex);
110616 return ret;
110617@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
110618 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
110619 {
110620 mutex_lock(&nf_sockopt_mutex);
110621- list_del(&reg->list);
110622+ pax_list_del((struct list_head *)&reg->list);
110623 mutex_unlock(&nf_sockopt_mutex);
110624 }
110625 EXPORT_SYMBOL(nf_unregister_sockopt);
110626diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
110627index d292c8d..9f1e166 100644
110628--- a/net/netfilter/nfnetlink_log.c
110629+++ b/net/netfilter/nfnetlink_log.c
110630@@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
110631 struct nfnl_log_net {
110632 spinlock_t instances_lock;
110633 struct hlist_head instance_table[INSTANCE_BUCKETS];
110634- atomic_t global_seq;
110635+ atomic_unchecked_t global_seq;
110636 };
110637
110638 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
110639@@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
110640 /* global sequence number */
110641 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
110642 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
110643- htonl(atomic_inc_return(&log->global_seq))))
110644+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
110645 goto nla_put_failure;
110646
110647 if (data_len) {
110648diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
110649index 1840989..6895744 100644
110650--- a/net/netfilter/nft_compat.c
110651+++ b/net/netfilter/nft_compat.c
110652@@ -225,7 +225,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
110653 /* We want to reuse existing compat_to_user */
110654 old_fs = get_fs();
110655 set_fs(KERNEL_DS);
110656- t->compat_to_user(out, in);
110657+ t->compat_to_user((void __force_user *)out, in);
110658 set_fs(old_fs);
110659 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
110660 kfree(out);
110661@@ -421,7 +421,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
110662 /* We want to reuse existing compat_to_user */
110663 old_fs = get_fs();
110664 set_fs(KERNEL_DS);
110665- m->compat_to_user(out, in);
110666+ m->compat_to_user((void __force_user *)out, in);
110667 set_fs(old_fs);
110668 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
110669 kfree(out);
110670diff --git a/net/netfilter/xt_bpf.c b/net/netfilter/xt_bpf.c
110671index bbffdbda..12d4da8 100644
110672--- a/net/netfilter/xt_bpf.c
110673+++ b/net/netfilter/xt_bpf.c
110674@@ -23,11 +23,10 @@ MODULE_ALIAS("ip6t_bpf");
110675 static int bpf_mt_check(const struct xt_mtchk_param *par)
110676 {
110677 struct xt_bpf_info *info = par->matchinfo;
110678- struct sock_fprog_kern program;
110679+ struct sock_fprog program;
110680
110681 program.len = info->bpf_program_num_elem;
110682- program.filter = info->bpf_program;
110683-
110684+ program.filter = (struct sock_filter __user *) info->bpf_program;
110685 if (sk_unattached_filter_create(&info->filter, &program)) {
110686 pr_info("bpf: check failed: parse error\n");
110687 return -EINVAL;
110688diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
110689new file mode 100644
110690index 0000000..c566332
110691--- /dev/null
110692+++ b/net/netfilter/xt_gradm.c
110693@@ -0,0 +1,51 @@
110694+/*
110695+ * gradm match for netfilter
110696