Gentoo Archives: gentoo-commits

From: "Anthony G. Basile" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/hardened-patchset:master commit in: 4.3.4/
Date: Sat, 30 Jan 2016 12:30:01
Message-Id: 1454157478.92b230adb84942fe6bf8d05cc6012ce0f98050a7.blueness@gentoo
1 commit: 92b230adb84942fe6bf8d05cc6012ce0f98050a7
2 Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
3 AuthorDate: Sat Jan 30 12:37:58 2016 +0000
4 Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
5 CommitDate: Sat Jan 30 12:37:58 2016 +0000
6 URL: https://gitweb.gentoo.org/proj/hardened-patchset.git/commit/?id=92b230ad
7
8 grsecurity-3.1-4.3.4-201601292206
9
10 4.3.4/0000_README | 2 +-
11 ...> 4420_grsecurity-3.1-4.3.4-201601292206.patch} | 204 ++++++++++++++++++---
12 2 files changed, 179 insertions(+), 27 deletions(-)
13
14 diff --git a/4.3.4/0000_README b/4.3.4/0000_README
15 index 158f0b1..ce73e44 100644
16 --- a/4.3.4/0000_README
17 +++ b/4.3.4/0000_README
18 @@ -6,7 +6,7 @@ Patch: 1003_linux-4.3.4.patch
19 From: http://www.kernel.org
20 Desc: Linux 4.3.4
21
22 -Patch: 4420_grsecurity-3.1-4.3.4-201601261954.patch
23 +Patch: 4420_grsecurity-3.1-4.3.4-201601292206.patch
24 From: http://www.grsecurity.net
25 Desc: hardened-sources base patch from upstream grsecurity
26
27
28 diff --git a/4.3.4/4420_grsecurity-3.1-4.3.4-201601261954.patch b/4.3.4/4420_grsecurity-3.1-4.3.4-201601292206.patch
29 similarity index 99%
30 rename from 4.3.4/4420_grsecurity-3.1-4.3.4-201601261954.patch
31 rename to 4.3.4/4420_grsecurity-3.1-4.3.4-201601292206.patch
32 index f866bc7..92cf754 100644
33 --- a/4.3.4/4420_grsecurity-3.1-4.3.4-201601261954.patch
34 +++ b/4.3.4/4420_grsecurity-3.1-4.3.4-201601292206.patch
35 @@ -75860,14 +75860,17 @@ index 155f842..89922d8 100644
36
37 file = aio_private_file(ctx, nr_pages);
38 diff --git a/fs/attr.c b/fs/attr.c
39 -index 6530ced..4a827e2 100644
40 +index 6530ced..559e5e6 100644
41 --- a/fs/attr.c
42 +++ b/fs/attr.c
43 -@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
44 +@@ -102,6 +102,10 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
45 unsigned long limit;
46
47 limit = rlimit(RLIMIT_FSIZE);
48 -+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
49 ++ if (offset > ULONG_MAX)
50 ++ gr_learn_resource(current, RLIMIT_FSIZE, ULONG_MAX, 1);
51 ++ else if (offset > 0)
52 ++ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
53 if (limit != RLIM_INFINITY && offset > limit)
54 goto out_sig;
55 if (offset > inode->i_sb->s_maxbytes)
56 @@ -77631,7 +77634,7 @@ index b406a32..243eb1c 100644
57 GLOBAL_EXTERN atomic_t smBufAllocCount;
58 GLOBAL_EXTERN atomic_t midCount;
59 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60 -index 62203c3..93267bf 100644
61 +index 62203c3..fa2d9b3 100644
62 --- a/fs/cifs/file.c
63 +++ b/fs/cifs/file.c
64 @@ -2054,10 +2054,14 @@ static int cifs_writepages(struct address_space *mapping,
65 @@ -77652,6 +77655,15 @@ index 62203c3..93267bf 100644
66 scanned = true;
67 }
68 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
69 +@@ -2531,7 +2535,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from,
70 + wdata->pid = pid;
71 + wdata->bytes = cur_len;
72 + wdata->pagesz = PAGE_SIZE;
73 +- wdata->tailsz = cur_len - ((nr_pages - 1) * PAGE_SIZE);
74 ++ wdata->tailsz = cur_len - nr_pages * PAGE_SIZE + PAGE_SIZE;
75 + wdata->credits = credits;
76 +
77 + if (!wdata->cfile->invalidHandle ||
78 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
79 index 8442b8b..ea6986f 100644
80 --- a/fs/cifs/misc.c
81 @@ -82037,6 +82049,19 @@ index ebb5e37..beae05b 100644
82 do_wakeup = 1;
83 }
84
85 +diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c
86 +index cf4ab89..5a00960 100644
87 +--- a/fs/gfs2/file.c
88 ++++ b/fs/gfs2/file.c
89 +@@ -781,7 +781,7 @@ static void calc_max_reserv(struct gfs2_inode *ip, loff_t *len,
90 + {
91 + loff_t max = *len;
92 + const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
93 +- unsigned int tmp, max_data = max_blocks - 3 * (sdp->sd_max_height - 1);
94 ++ unsigned int tmp, max_data = max_blocks - 3 * sdp->sd_max_height + 3;
95 +
96 + for (tmp = max_data; tmp > sdp->sd_diptrs;) {
97 + tmp = DIV_ROUND_UP(tmp, sdp->sd_inptrs);
98 diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
99 index 9bd1244..b8c82d9 100644
100 --- a/fs/gfs2/glock.c
101 @@ -112918,6 +112943,46 @@ index 6d2a119..ac24f34 100644
102
103 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
104 {
105 +diff --git a/kernel/seccomp.c b/kernel/seccomp.c
106 +index 5bd4779..6bf906d 100644
107 +--- a/kernel/seccomp.c
108 ++++ b/kernel/seccomp.c
109 +@@ -316,24 +316,24 @@ static inline void seccomp_sync_threads(void)
110 + put_seccomp_filter(thread);
111 + smp_store_release(&thread->seccomp.filter,
112 + caller->seccomp.filter);
113 ++
114 ++ /*
115 ++ * Don't let an unprivileged task work around
116 ++ * the no_new_privs restriction by creating
117 ++ * a thread that sets it up, enters seccomp,
118 ++ * then dies.
119 ++ */
120 ++ if (task_no_new_privs(caller))
121 ++ task_set_no_new_privs(thread);
122 ++
123 + /*
124 + * Opt the other thread into seccomp if needed.
125 + * As threads are considered to be trust-realm
126 + * equivalent (see ptrace_may_access), it is safe to
127 + * allow one thread to transition the other.
128 + */
129 +- if (thread->seccomp.mode == SECCOMP_MODE_DISABLED) {
130 +- /*
131 +- * Don't let an unprivileged task work around
132 +- * the no_new_privs restriction by creating
133 +- * a thread that sets it up, enters seccomp,
134 +- * then dies.
135 +- */
136 +- if (task_no_new_privs(caller))
137 +- task_set_no_new_privs(thread);
138 +-
139 ++ if (thread->seccomp.mode == SECCOMP_MODE_DISABLED)
140 + seccomp_assign_mode(thread, SECCOMP_MODE_FILTER);
141 +- }
142 + }
143 + }
144 +
145 diff --git a/kernel/signal.c b/kernel/signal.c
146 index 0f6bbbe..4791c7d 100644
147 --- a/kernel/signal.c
148 @@ -150284,10 +150349,10 @@ index 0000000..cc20d48
149 +#endif
150 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
151 new file mode 100644
152 -index 0000000..7d9135d
153 +index 0000000..bd18a67
154 --- /dev/null
155 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
156 -@@ -0,0 +1,1032 @@
157 +@@ -0,0 +1,1116 @@
158 +/*
159 + * Copyright 2011-2015 by Emese Revfy <re.emese@×××××.com>
160 + * Licensed under the GPL v2, or (at your option) v3
161 @@ -150495,9 +150560,6 @@ index 0000000..7d9135d
162 + switch (TREE_CODE(node)) {
163 + case COMPONENT_REF:
164 + cur_decl = search_field_decl(node);
165 -+ // !!! temporarily ignore bitfield types
166 -+ if (DECL_BIT_FIELD_TYPE(cur_decl))
167 -+ return MARK_YES;
168 + if (is_turn_off_intentional_attr(cur_decl))
169 + return MARK_TURN_OFF;
170 + if (is_end_intentional_intentional_attr(cur_decl))
171 @@ -150526,9 +150588,6 @@ index 0000000..7d9135d
172 + break;
173 + }
174 + case FIELD_DECL:
175 -+ // !!! temporarily ignore bitfield types
176 -+ if (DECL_BIT_FIELD_TYPE(node))
177 -+ return MARK_YES;
178 + case VAR_DECL:
179 + if (is_end_intentional_intentional_attr(node))
180 + return MARK_END_INTENTIONAL;
181 @@ -151320,6 +151379,96 @@ index 0000000..7d9135d
182 + add_rhs2 = gimple_assign_rhs2(add_stmt);
183 + return check_add_stmt(add_rhs2);
184 +}
185 ++
186 ++/* True:
187 ++ * _25 = (<unnamed-unsigned:1>) _24;
188 ++ * r_5(D)->stereo = _25;
189 ++ */
190 ++bool is_bitfield_unnamed_cast(const_tree decl, gassign *assign)
191 ++{
192 ++ const_tree rhs, type;
193 ++ gimple def_stmt;
194 ++
195 ++ if (TREE_CODE(decl) != FIELD_DECL)
196 ++ return false;
197 ++ if (!DECL_BIT_FIELD_TYPE(decl))
198 ++ return false;
199 ++ if (gimple_num_ops(assign) != 2)
200 ++ return false;
201 ++
202 ++ rhs = gimple_assign_rhs1(assign);
203 ++ if (is_gimple_constant(rhs))
204 ++ return false;
205 ++ type = TREE_TYPE(rhs);
206 ++ if (TREE_CODE(type) == BOOLEAN_TYPE)
207 ++ return false;
208 ++
209 ++ def_stmt = get_def_stmt(rhs);
210 ++ if (!gimple_assign_cast_p(def_stmt))
211 ++ return false;
212 ++ return TYPE_PRECISION(type) < CHAR_TYPE_SIZE;
213 ++}
214 ++
215 ++static bool is_mult_const(const_tree lhs)
216 ++{
217 ++ const_gimple def_stmt;
218 ++ const_tree rhs1, rhs2;
219 ++
220 ++ def_stmt = get_def_stmt(lhs);
221 ++ if (!def_stmt || gimple_assign_rhs_code(def_stmt) != MULT_EXPR)
222 ++ return false;
223 ++
224 ++ rhs1 = gimple_assign_rhs1(def_stmt);
225 ++ rhs2 = gimple_assign_rhs2(def_stmt);
226 ++ if (is_gimple_constant(rhs1))
227 ++ return !is_lt_signed_type_max(rhs1);
228 ++ else if (is_gimple_constant(rhs2))
229 ++ return !is_lt_signed_type_max(rhs2);
230 ++ return false;
231 ++}
232 ++
233 ++/* True:
234 ++ * fs/cifs/file.c cifs_write_from_iter()
235 ++ * u32 = u64 - (u64 - constant) * constant
236 ++ * wdata->tailsz = cur_len - (nr_pages - 1) * PAGE_SIZE;
237 ++ *
238 ++ * _51 = _50 * 4294963200;
239 ++ * _52 = _49 + _51;
240 ++ * _53 = _52 + 4096;
241 ++ */
242 ++
243 ++bool uconst_neg_intentional_overflow(struct visited *visited, const gassign *stmt)
244 ++{
245 ++ const_gimple def_stmt;
246 ++ const_tree noconst_rhs;
247 ++ tree rhs1, rhs2;
248 ++
249 ++ // _53 = _52 + const;
250 ++ if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
251 ++ return false;
252 ++ rhs1 = gimple_assign_rhs1(stmt);
253 ++ rhs2 = gimple_assign_rhs2(stmt);
254 ++ if (is_gimple_constant(rhs1))
255 ++ noconst_rhs = rhs2;
256 ++ else if (is_gimple_constant(rhs2))
257 ++ noconst_rhs = rhs1;
258 ++ else
259 ++ return false;
260 ++ def_stmt = get_def_stmt(noconst_rhs);
261 ++
262 ++ // _52 = _49 + _51;
263 ++ if (!def_stmt)
264 ++ return false;
265 ++ if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
266 ++ return false;
267 ++ rhs1 = gimple_assign_rhs1(def_stmt);
268 ++ rhs2 = gimple_assign_rhs2(def_stmt);
269 ++ if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
270 ++ return false;
271 ++
272 ++ // _51 = _50 * gt signed type max;
273 ++ return is_mult_const(rhs1) || is_mult_const(rhs2);
274 ++}
275 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
276 new file mode 100644
277 index 0000000..5622b51
278 @@ -151465,10 +151614,10 @@ index 0000000..5622b51
279 +
280 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
281 new file mode 100644
282 -index 0000000..5fd6c28
283 +index 0000000..ee57a00
284 --- /dev/null
285 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
286 -@@ -0,0 +1,323 @@
287 +@@ -0,0 +1,325 @@
288 +#ifndef SIZE_OVERFLOW_H
289 +#define SIZE_OVERFLOW_H
290 +
291 @@ -151673,6 +151822,8 @@ index 0000000..5fd6c28
292 +extern enum intentional_overflow_type add_mul_intentional_overflow(const gassign *stmt);
293 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gassign *stmt);
294 +extern bool neg_short_add_intentional_overflow(gassign *stmt);
295 ++extern bool is_bitfield_unnamed_cast(const_tree decl, gassign *assign);
296 ++extern bool uconst_neg_intentional_overflow(struct visited *visited, const gassign *stmt);
297 +
298 +
299 +// insert_size_overflow_asm.c
300 @@ -175586,12 +175737,12 @@ index 0000000..6075e8f
301 +
302 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
303 new file mode 100644
304 -index 0000000..f1cc040
305 +index 0000000..f50c635
306 --- /dev/null
307 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
308 @@ -0,0 +1,318 @@
309 +/*
310 -+ * Copyright 2011-2015 by Emese Revfy <re.emese@×××××.com>
311 ++ * Copyright 2011-2016 by Emese Revfy <re.emese@×××××.com>
312 + * Licensed under the GPL v2, or (at your option) v3
313 + *
314 + * Homepage:
315 @@ -175621,7 +175772,7 @@ index 0000000..f1cc040
316 +tree size_overflow_type_TI;
317 +
318 +static struct plugin_info size_overflow_plugin_info = {
319 -+ .version = "20151201",
320 ++ .version = "20160128",
321 + .help = "no-size-overflow\tturn off size overflow checking\n",
322 +};
323 +
324 @@ -176268,10 +176419,10 @@ index 0000000..317cd6c
325 +
326 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_transform.c b/tools/gcc/size_overflow_plugin/size_overflow_transform.c
327 new file mode 100644
328 -index 0000000..8f42c7e
329 +index 0000000..f9de78e
330 --- /dev/null
331 +++ b/tools/gcc/size_overflow_plugin/size_overflow_transform.c
332 -@@ -0,0 +1,749 @@
333 +@@ -0,0 +1,745 @@
334 +/*
335 + * Copyright 2011-2015 by Emese Revfy <re.emese@×××××.com>
336 + * Licensed under the GPL v2, or (at your option) v3
337 @@ -176457,9 +176608,6 @@ index 0000000..8f42c7e
338 +
339 + if (skip_types(orig_node))
340 + return head;
341 -+ // !!! temporarily ignore bitfield types
342 -+ if (orig_code == FIELD_DECL && DECL_BIT_FIELD_TYPE(orig_node))
343 -+ return head;
344 +
345 + // find a defining marked caller argument or struct field for arg
346 + if (check_intentional_size_overflow_asm_and_attribute(orig_node) != MARK_NO)
347 @@ -176818,8 +176966,7 @@ index 0000000..8f42c7e
348 + if (DECL_NAME(decl) == NULL_TREE)
349 + return head;
350 +
351 -+ // !!! temporarily ignore bitfield types
352 -+ if (TREE_CODE(decl) == FIELD_DECL && DECL_BIT_FIELD_TYPE(decl))
353 ++ if (is_bitfield_unnamed_cast(decl, assign))
354 + return head;
355 +
356 + next_node = get_interesting_function_next_node(decl, 0);
357 @@ -177023,10 +177170,10 @@ index 0000000..8f42c7e
358 +}
359 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_transform_core.c b/tools/gcc/size_overflow_plugin/size_overflow_transform_core.c
360 new file mode 100644
361 -index 0000000..8a30b3b
362 +index 0000000..2ab3b9e
363 --- /dev/null
364 +++ b/tools/gcc/size_overflow_plugin/size_overflow_transform_core.c
365 -@@ -0,0 +1,1010 @@
366 +@@ -0,0 +1,1015 @@
367 +/*
368 + * Copyright 2011-2015 by Emese Revfy <re.emese@×××××.com>
369 + * Licensed under the GPL v2, or (at your option) v3
370 @@ -177945,6 +178092,11 @@ index 0000000..8a30b3b
371 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
372 + return handle_comparison_code_class(visited, expand_from, def_stmt, new_rhs1, new_rhs2);
373 +
374 ++ if (uconst_neg_intentional_overflow(visited, def_stmt)) {
375 ++ inform(gimple_location(def_stmt), "%s: gcc intentional overflow", __func__);
376 ++ gcc_unreachable();
377 ++ }
378 ++
379 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
380 +}
381 +