1 diff -NurpP --minimal linux-4.9.76/Documentation/vserver/debug.txt linux-4.9.76-vs2.3.9.5/Documentation/vserver/debug.txt
2 --- linux-4.9.76/Documentation/vserver/debug.txt 1970-01-01 00:00:00.000000000 +0000
3 +++ linux-4.9.76-vs2.3.9.5/Documentation/vserver/debug.txt 2018-01-10 02:50:49.000000000 +0000
8 + 2 4 "vx_map_tgid: %p/%llx: %d -> %d"
9 + "vx_rmap_tgid: %p/%llx: %d -> %d"
13 + 0 1 "ALLOC (%p,#%d)%c inode (%d)"
14 + "FREE (%p,#%d)%c inode"
15 + 1 2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
16 + "FREE (%p,#%d)%c %lld bytes"
17 + 2 4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
18 + 3 8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
19 + "ext3_has_free_blocks(%p): free=%lu, root=%lu"
20 + "rcu_free_dl_info(%p)"
21 + 4 10 "alloc_dl_info(%p,%d) = %p"
22 + "dealloc_dl_info(%p)"
23 + "get_dl_info(%p[#%d.%d])"
24 + "put_dl_info(%p[#%d.%d])"
25 + 5 20 "alloc_dl_info(%p,%d)*"
26 + 6 40 "__hash_dl_info: %p[#%d]"
27 + "__unhash_dl_info: %p[#%d]"
28 + 7 80 "locate_dl_info(%p,#%d) = %p"
32 + 0 1 "destroy_dqhash: %p [#0x%08x] c=%d"
33 + "new_dqhash: %p [#0x%08x]"
34 + "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
35 + "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
36 + "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
37 + "vroot_get_real_bdev not set"
38 + 1 2 "cow_break_link(?%s?)"
40 + 2 4 "dentry_open(new): %p"
41 + "dentry_open(old): %p"
42 + "lookup_create(new): %p"
44 + "path_lookup(old): %d"
45 + "vfs_create(new): %d"
48 + 3 8 "fput(new_file=%p[#%d])"
49 + "fput(old_file=%p[#%d])"
50 + 4 10 "vx_info_kill(%p[#%d],%d,%d) = %d"
51 + "vx_info_kill(%p[#%d],%d,%d)*"
52 + 5 20 "vs_reboot(%p[#%d],%d)"
53 + 6 40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
57 + 2 4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
58 + 3 8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
59 + "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
60 + 4 10 "ip_route_connect(%p) %p,%p;%lx"
61 + 5 20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
62 + 6 40 "sk,egf: %p [#%d] (from %d)"
63 + "sk,egn: %p [#%d] (from %d)"
64 + "sk,req: %p [#%d] (from %d)"
65 + "sk: %p [#%d] (from %d)"
66 + "tw: %p [#%d] (from %d)"
67 + 7 80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
68 + "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
72 + 0 1 "__lookup_nx_info(#%u): %p[#%u]"
73 + "alloc_nx_info(%d) = %p"
74 + "create_nx_info(%d) (dynamic rejected)"
75 + "create_nx_info(%d) = %p (already there)"
76 + "create_nx_info(%d) = %p (new)"
77 + "dealloc_nx_info(%p)"
78 + 1 2 "alloc_nx_info(%d)*"
79 + "create_nx_info(%d)*"
80 + 2 4 "get_nx_info(%p[#%d.%d])"
81 + "put_nx_info(%p[#%d.%d])"
82 + 3 8 "claim_nx_info(%p[#%d.%d.%d]) %p"
83 + "clr_nx_info(%p[#%d.%d])"
84 + "init_nx_info(%p[#%d.%d])"
85 + "release_nx_info(%p[#%d.%d.%d]) %p"
86 + "set_nx_info(%p[#%d.%d])"
87 + 4 10 "__hash_nx_info: %p[#%d]"
88 + "__nx_dynamic_id: [#%d]"
89 + "__unhash_nx_info: %p[#%d.%d.%d]"
90 + 5 20 "moved task %p into nxi:%p[#%d]"
91 + "nx_migrate_task(%p,%p[#%d.%d.%d])"
92 + "task_get_nx_info(%p)"
93 + 6 40 "nx_clear_persistent(%p[#%d])"
97 + 0 1 "quota_sync_dqh(%p,%d) discard inode %p"
98 + 1 2 "quota_sync_dqh(%p,%d)"
99 + "sync_dquots(%p,%d)"
100 + "sync_dquots_dqh(%p,%d)"
101 + 3 8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
105 + 0 1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
106 + 1 2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
107 + 4 10 "%s: (%s %s) returned %s with %d"
111 + 7 80 "dx_parse_tag(?%s?): %d:#%d"
112 + "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
116 + 0 1 "__lookup_vx_info(#%u): %p[#%u]"
117 + "alloc_vx_info(%d) = %p"
118 + "alloc_vx_info(%d)*"
119 + "create_vx_info(%d) (dynamic rejected)"
120 + "create_vx_info(%d) = %p (already there)"
121 + "create_vx_info(%d) = %p (new)"
122 + "dealloc_vx_info(%p)"
123 + "loc_vx_info(%d) = %p (found)"
124 + "loc_vx_info(%d) = %p (new)"
125 + "loc_vx_info(%d) = %p (not available)"
126 + 1 2 "create_vx_info(%d)*"
128 + 2 4 "get_vx_info(%p[#%d.%d])"
129 + "put_vx_info(%p[#%d.%d])"
130 + 3 8 "claim_vx_info(%p[#%d.%d.%d]) %p"
131 + "clr_vx_info(%p[#%d.%d])"
132 + "init_vx_info(%p[#%d.%d])"
133 + "release_vx_info(%p[#%d.%d.%d]) %p"
134 + "set_vx_info(%p[#%d.%d])"
135 + 4 10 "__hash_vx_info: %p[#%d]"
136 + "__unhash_vx_info: %p[#%d.%d.%d]"
137 + "__vx_dynamic_id: [#%d]"
138 + 5 20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
139 + "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
140 + "moved task %p into vxi:%p[#%d]"
141 + "task_get_vx_info(%p)"
142 + "vx_migrate_task(%p,%p[#%d.%d])"
143 + 6 40 "vx_clear_persistent(%p[#%d])"
144 + "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
145 + "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
146 + "vx_set_persistent(%p[#%d])"
147 + "vx_set_reaper(%p[#%d],%p[#%d,%d])"
148 + 7 80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
153 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154 + "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
156 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
157 + "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
158 + "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
159 diff -NurpP --minimal linux-4.9.76/arch/alpha/Kconfig linux-4.9.76-vs2.3.9.5/arch/alpha/Kconfig
160 --- linux-4.9.76/arch/alpha/Kconfig 2016-12-11 19:17:54.000000000 +0000
161 +++ linux-4.9.76-vs2.3.9.5/arch/alpha/Kconfig 2018-01-10 02:50:49.000000000 +0000
162 @@ -743,6 +743,8 @@ config DUMMY_CONSOLE
166 +source "kernel/vserver/Kconfig"
168 source "security/Kconfig"
170 source "crypto/Kconfig"
171 diff -NurpP --minimal linux-4.9.76/arch/alpha/kernel/systbls.S linux-4.9.76-vs2.3.9.5/arch/alpha/kernel/systbls.S
172 --- linux-4.9.76/arch/alpha/kernel/systbls.S 2016-12-11 19:17:54.000000000 +0000
173 +++ linux-4.9.76-vs2.3.9.5/arch/alpha/kernel/systbls.S 2018-01-10 02:50:49.000000000 +0000
174 @@ -446,7 +446,7 @@ sys_call_table:
175 .quad sys_stat64 /* 425 */
178 - .quad sys_ni_syscall /* sys_vserver */
179 + .quad sys_vserver /* sys_vserver */
180 .quad sys_ni_syscall /* sys_mbind */
181 .quad sys_ni_syscall /* sys_get_mempolicy */
182 .quad sys_ni_syscall /* sys_set_mempolicy */
183 diff -NurpP --minimal linux-4.9.76/arch/alpha/kernel/traps.c linux-4.9.76-vs2.3.9.5/arch/alpha/kernel/traps.c
184 --- linux-4.9.76/arch/alpha/kernel/traps.c 2016-12-11 19:17:54.000000000 +0000
185 +++ linux-4.9.76-vs2.3.9.5/arch/alpha/kernel/traps.c 2018-01-10 02:50:49.000000000 +0000
186 @@ -174,7 +174,8 @@ die_if_kernel(char * str, struct pt_regs
188 printk("CPU %d ", hard_smp_processor_id());
190 - printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
191 + printk("%s(%d:#%u): %s %ld\n", current->comm,
192 + task_pid_nr(current), current->xid, str, err);
193 dik_show_regs(regs, r9_15);
194 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
195 dik_show_trace((unsigned long *)(regs+1));
196 diff -NurpP --minimal linux-4.9.76/arch/arm/Kconfig linux-4.9.76-vs2.3.9.5/arch/arm/Kconfig
197 --- linux-4.9.76/arch/arm/Kconfig 2016-12-11 19:17:54.000000000 +0000
198 +++ linux-4.9.76-vs2.3.9.5/arch/arm/Kconfig 2018-01-10 02:50:49.000000000 +0000
199 @@ -2199,6 +2199,8 @@ source "fs/Kconfig"
201 source "arch/arm/Kconfig.debug"
203 +source "kernel/vserver/Kconfig"
205 source "security/Kconfig"
207 source "crypto/Kconfig"
208 diff -NurpP --minimal linux-4.9.76/arch/arm/kernel/calls.S linux-4.9.76-vs2.3.9.5/arch/arm/kernel/calls.S
209 --- linux-4.9.76/arch/arm/kernel/calls.S 2016-12-11 19:17:54.000000000 +0000
210 +++ linux-4.9.76-vs2.3.9.5/arch/arm/kernel/calls.S 2018-01-10 02:50:49.000000000 +0000
212 /* 310 */ CALL(sys_request_key)
214 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
215 -/* vserver */ CALL(sys_ni_syscall)
218 /* 315 */ CALL(sys_ioprio_get)
219 CALL(sys_inotify_init)
220 diff -NurpP --minimal linux-4.9.76/arch/arm/kernel/traps.c linux-4.9.76-vs2.3.9.5/arch/arm/kernel/traps.c
221 --- linux-4.9.76/arch/arm/kernel/traps.c 2018-01-13 21:28:37.000000000 +0000
222 +++ linux-4.9.76-vs2.3.9.5/arch/arm/kernel/traps.c 2018-01-10 02:50:49.000000000 +0000
223 @@ -278,8 +278,8 @@ static int __die(const char *str, int er
227 - pr_emerg("Process %.*s (pid: %d, stack limit = 0x%p)\n",
228 - TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), end_of_stack(tsk));
229 + pr_emerg("Process %.*s (pid: %d:%u, stack limit = 0x%p)\n",
230 + TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, end_of_stack(tsk));
232 if (!user_mode(regs) || in_interrupt()) {
233 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
234 diff -NurpP --minimal linux-4.9.76/arch/cris/Kconfig linux-4.9.76-vs2.3.9.5/arch/cris/Kconfig
235 --- linux-4.9.76/arch/cris/Kconfig 2016-12-11 19:17:54.000000000 +0000
236 +++ linux-4.9.76-vs2.3.9.5/arch/cris/Kconfig 2018-01-10 02:50:49.000000000 +0000
237 @@ -583,6 +583,8 @@ source "fs/Kconfig"
239 source "arch/cris/Kconfig.debug"
241 +source "kernel/vserver/Kconfig"
243 source "security/Kconfig"
245 source "crypto/Kconfig"
246 diff -NurpP --minimal linux-4.9.76/arch/ia64/Kconfig linux-4.9.76-vs2.3.9.5/arch/ia64/Kconfig
247 --- linux-4.9.76/arch/ia64/Kconfig 2016-12-11 19:17:54.000000000 +0000
248 +++ linux-4.9.76-vs2.3.9.5/arch/ia64/Kconfig 2018-01-10 02:50:49.000000000 +0000
249 @@ -602,6 +602,8 @@ source "fs/Kconfig"
251 source "arch/ia64/Kconfig.debug"
253 +source "kernel/vserver/Kconfig"
255 source "security/Kconfig"
257 source "crypto/Kconfig"
258 diff -NurpP --minimal linux-4.9.76/arch/ia64/kernel/entry.S linux-4.9.76-vs2.3.9.5/arch/ia64/kernel/entry.S
259 --- linux-4.9.76/arch/ia64/kernel/entry.S 2016-12-11 19:17:54.000000000 +0000
260 +++ linux-4.9.76-vs2.3.9.5/arch/ia64/kernel/entry.S 2018-01-10 02:50:49.000000000 +0000
261 @@ -1697,7 +1697,7 @@ sys_call_table:
263 data8 sys_mq_getsetattr
265 - data8 sys_ni_syscall // reserved for vserver
267 data8 sys_waitid // 1270
269 data8 sys_request_key
270 diff -NurpP --minimal linux-4.9.76/arch/ia64/kernel/ptrace.c linux-4.9.76-vs2.3.9.5/arch/ia64/kernel/ptrace.c
271 --- linux-4.9.76/arch/ia64/kernel/ptrace.c 2018-01-13 21:28:38.000000000 +0000
272 +++ linux-4.9.76-vs2.3.9.5/arch/ia64/kernel/ptrace.c 2018-01-10 02:50:49.000000000 +0000
274 #include <linux/regset.h>
275 #include <linux/elf.h>
276 #include <linux/tracehook.h>
277 +#include <linux/vs_base.h>
279 #include <asm/pgtable.h>
280 #include <asm/processor.h>
281 diff -NurpP --minimal linux-4.9.76/arch/ia64/kernel/traps.c linux-4.9.76-vs2.3.9.5/arch/ia64/kernel/traps.c
282 --- linux-4.9.76/arch/ia64/kernel/traps.c 2016-12-11 19:17:54.000000000 +0000
283 +++ linux-4.9.76-vs2.3.9.5/arch/ia64/kernel/traps.c 2018-01-10 02:50:49.000000000 +0000
284 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
287 if (++die.lock_owner_depth < 3) {
288 - printk("%s[%d]: %s %ld [%d]\n",
289 - current->comm, task_pid_nr(current), str, err, ++die_counter);
290 + printk("%s[%d:#%u]: %s %ld [%d]\n",
291 + current->comm, task_pid_nr(current), current->xid,
292 + str, err, ++die_counter);
293 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
296 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
297 if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
298 last.time = current_jiffies + 5 * HZ;
300 - "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
301 - current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
302 + "%s(%d:#%u): floating-point assist fault at ip %016lx, isr %016lx\n",
303 + current->comm, task_pid_nr(current), current->xid,
304 + regs->cr_iip + ia64_psr(regs)->ri, isr);
308 diff -NurpP --minimal linux-4.9.76/arch/m32r/kernel/traps.c linux-4.9.76-vs2.3.9.5/arch/m32r/kernel/traps.c
309 --- linux-4.9.76/arch/m32r/kernel/traps.c 2016-12-11 19:17:54.000000000 +0000
310 +++ linux-4.9.76-vs2.3.9.5/arch/m32r/kernel/traps.c 2018-01-10 02:50:49.000000000 +0000
311 @@ -184,8 +184,9 @@ static void show_registers(struct pt_reg
313 printk("SPI: %08lx\n", sp);
315 - printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
316 - current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
317 + printk("Process %s (pid: %d:#%u, process nr: %d, stackpage=%08lx)",
318 + current->comm, task_pid_nr(current), current->xid,
319 + 0xffff & i, 4096+(unsigned long)current);
322 * When in-kernel, we also print out the stack and code at the
323 diff -NurpP --minimal linux-4.9.76/arch/m68k/Kconfig linux-4.9.76-vs2.3.9.5/arch/m68k/Kconfig
324 --- linux-4.9.76/arch/m68k/Kconfig 2016-12-11 19:17:54.000000000 +0000
325 +++ linux-4.9.76-vs2.3.9.5/arch/m68k/Kconfig 2018-01-10 02:50:49.000000000 +0000
326 @@ -163,6 +163,8 @@ source "fs/Kconfig"
328 source "arch/m68k/Kconfig.debug"
330 +source "kernel/vserver/Kconfig"
332 source "security/Kconfig"
334 source "crypto/Kconfig"
335 diff -NurpP --minimal linux-4.9.76/arch/mips/Kconfig linux-4.9.76-vs2.3.9.5/arch/mips/Kconfig
336 --- linux-4.9.76/arch/mips/Kconfig 2018-01-13 21:28:38.000000000 +0000
337 +++ linux-4.9.76-vs2.3.9.5/arch/mips/Kconfig 2018-01-10 02:50:49.000000000 +0000
338 @@ -3189,6 +3189,8 @@ source "fs/Kconfig"
340 source "arch/mips/Kconfig.debug"
342 +source "kernel/vserver/Kconfig"
344 source "security/Kconfig"
346 source "crypto/Kconfig"
347 diff -NurpP --minimal linux-4.9.76/arch/mips/kernel/ptrace.c linux-4.9.76-vs2.3.9.5/arch/mips/kernel/ptrace.c
348 --- linux-4.9.76/arch/mips/kernel/ptrace.c 2018-01-13 21:28:38.000000000 +0000
349 +++ linux-4.9.76-vs2.3.9.5/arch/mips/kernel/ptrace.c 2018-01-10 02:50:49.000000000 +0000
351 #include <linux/audit.h>
352 #include <linux/seccomp.h>
353 #include <linux/ftrace.h>
354 +#include <linux/vs_base.h>
356 #include <asm/byteorder.h>
358 @@ -687,6 +688,9 @@ long arch_ptrace(struct task_struct *chi
359 void __user *datavp = (void __user *) data;
360 unsigned long __user *datalp = (void __user *) data;
362 + if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
366 /* when I and D space are separate, these will need to be fixed. */
367 case PTRACE_PEEKTEXT: /* read word at location addr. */
368 diff -NurpP --minimal linux-4.9.76/arch/mips/kernel/scall32-o32.S linux-4.9.76-vs2.3.9.5/arch/mips/kernel/scall32-o32.S
369 --- linux-4.9.76/arch/mips/kernel/scall32-o32.S 2018-01-13 21:28:38.000000000 +0000
370 +++ linux-4.9.76-vs2.3.9.5/arch/mips/kernel/scall32-o32.S 2018-01-10 02:50:49.000000000 +0000
371 @@ -511,7 +511,7 @@ EXPORT(sys_call_table)
372 PTR sys_mq_timedreceive
373 PTR sys_mq_notify /* 4275 */
374 PTR sys_mq_getsetattr
375 - PTR sys_ni_syscall /* sys_vserver */
378 PTR sys_ni_syscall /* available, was setaltroot */
379 PTR sys_add_key /* 4280 */
380 diff -NurpP --minimal linux-4.9.76/arch/mips/kernel/scall64-64.S linux-4.9.76-vs2.3.9.5/arch/mips/kernel/scall64-64.S
381 --- linux-4.9.76/arch/mips/kernel/scall64-64.S 2018-01-13 21:28:38.000000000 +0000
382 +++ linux-4.9.76-vs2.3.9.5/arch/mips/kernel/scall64-64.S 2018-01-10 02:50:49.000000000 +0000
383 @@ -348,7 +348,7 @@ EXPORT(sys_call_table)
384 PTR sys_mq_timedreceive
386 PTR sys_mq_getsetattr /* 5235 */
387 - PTR sys_ni_syscall /* sys_vserver */
390 PTR sys_ni_syscall /* available, was setaltroot */
392 diff -NurpP --minimal linux-4.9.76/arch/mips/kernel/scall64-n32.S linux-4.9.76-vs2.3.9.5/arch/mips/kernel/scall64-n32.S
393 --- linux-4.9.76/arch/mips/kernel/scall64-n32.S 2018-01-13 21:28:38.000000000 +0000
394 +++ linux-4.9.76-vs2.3.9.5/arch/mips/kernel/scall64-n32.S 2018-01-10 02:50:49.000000000 +0000
395 @@ -343,7 +343,7 @@ EXPORT(sysn32_call_table)
396 PTR compat_sys_mq_timedreceive
397 PTR compat_sys_mq_notify
398 PTR compat_sys_mq_getsetattr
399 - PTR sys_ni_syscall /* 6240, sys_vserver */
400 + PTR sys32_vserver /* 6240 */
401 PTR compat_sys_waitid
402 PTR sys_ni_syscall /* available, was setaltroot */
404 diff -NurpP --minimal linux-4.9.76/arch/mips/kernel/scall64-o32.S linux-4.9.76-vs2.3.9.5/arch/mips/kernel/scall64-o32.S
405 --- linux-4.9.76/arch/mips/kernel/scall64-o32.S 2018-01-13 21:28:38.000000000 +0000
406 +++ linux-4.9.76-vs2.3.9.5/arch/mips/kernel/scall64-o32.S 2018-01-10 02:50:49.000000000 +0000
407 @@ -499,7 +499,7 @@ EXPORT(sys32_call_table)
408 PTR compat_sys_mq_timedreceive
409 PTR compat_sys_mq_notify /* 4275 */
410 PTR compat_sys_mq_getsetattr
411 - PTR sys_ni_syscall /* sys_vserver */
413 PTR compat_sys_waitid
414 PTR sys_ni_syscall /* available, was setaltroot */
415 PTR sys_add_key /* 4280 */
416 diff -NurpP --minimal linux-4.9.76/arch/mips/kernel/traps.c linux-4.9.76-vs2.3.9.5/arch/mips/kernel/traps.c
417 --- linux-4.9.76/arch/mips/kernel/traps.c 2018-01-13 21:28:38.000000000 +0000
418 +++ linux-4.9.76-vs2.3.9.5/arch/mips/kernel/traps.c 2018-01-10 02:50:49.000000000 +0000
419 @@ -360,9 +360,10 @@ void show_registers(struct pt_regs *regs
423 - printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
424 - current->comm, current->pid, current_thread_info(), current,
425 - field, current_thread_info()->tp_value);
426 + printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
427 + current->comm, task_pid_nr(current), current->xid,
428 + current_thread_info(), current,
429 + field, current_thread_info()->tp_value);
430 if (cpu_has_userlocal) {
433 diff -NurpP --minimal linux-4.9.76/arch/parisc/Kconfig linux-4.9.76-vs2.3.9.5/arch/parisc/Kconfig
434 --- linux-4.9.76/arch/parisc/Kconfig 2016-12-11 19:17:54.000000000 +0000
435 +++ linux-4.9.76-vs2.3.9.5/arch/parisc/Kconfig 2018-01-10 02:50:49.000000000 +0000
436 @@ -348,6 +348,8 @@ config SECCOMP
438 If unsure, say Y. Only embedded should say N here.
440 +source "kernel/vserver/Kconfig"
442 source "security/Kconfig"
444 source "crypto/Kconfig"
445 diff -NurpP --minimal linux-4.9.76/arch/parisc/kernel/syscall_table.S linux-4.9.76-vs2.3.9.5/arch/parisc/kernel/syscall_table.S
446 --- linux-4.9.76/arch/parisc/kernel/syscall_table.S 2018-01-13 21:28:38.000000000 +0000
447 +++ linux-4.9.76-vs2.3.9.5/arch/parisc/kernel/syscall_table.S 2018-01-10 02:50:49.000000000 +0000
449 ENTRY_COMP(mbind) /* 260 */
450 ENTRY_COMP(get_mempolicy)
451 ENTRY_COMP(set_mempolicy)
452 - ENTRY_SAME(ni_syscall) /* 263: reserved for vserver */
453 + ENTRY_DIFF(vserver)
455 ENTRY_SAME(request_key) /* 265 */
457 diff -NurpP --minimal linux-4.9.76/arch/parisc/kernel/traps.c linux-4.9.76-vs2.3.9.5/arch/parisc/kernel/traps.c
458 --- linux-4.9.76/arch/parisc/kernel/traps.c 2016-12-11 19:17:54.000000000 +0000
459 +++ linux-4.9.76-vs2.3.9.5/arch/parisc/kernel/traps.c 2018-01-10 02:50:49.000000000 +0000
460 @@ -235,8 +235,9 @@ void die_if_kernel(char *str, struct pt_
463 parisc_printk_ratelimited(1, regs,
464 - KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
465 - current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
466 + KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
467 + current->comm, task_pid_nr(current), current->xid,
468 + str, err, regs->iaoq[0]);
472 @@ -266,8 +267,8 @@ void die_if_kernel(char *str, struct pt_
473 pdc_console_restart();
476 - printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
477 - current->comm, task_pid_nr(current), str, err);
478 + printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
479 + current->comm, task_pid_nr(current), current->xid, str, err);
481 /* Wot's wrong wif bein' racy? */
482 if (current->thread.flags & PARISC_KERNEL_DEATH) {
483 diff -NurpP --minimal linux-4.9.76/arch/powerpc/Kconfig linux-4.9.76-vs2.3.9.5/arch/powerpc/Kconfig
484 --- linux-4.9.76/arch/powerpc/Kconfig 2018-01-13 21:28:38.000000000 +0000
485 +++ linux-4.9.76-vs2.3.9.5/arch/powerpc/Kconfig 2018-01-10 02:50:49.000000000 +0000
486 @@ -1085,6 +1085,8 @@ source "lib/Kconfig"
488 source "arch/powerpc/Kconfig.debug"
490 +source "kernel/vserver/Kconfig"
492 source "security/Kconfig"
494 source "crypto/Kconfig"
495 diff -NurpP --minimal linux-4.9.76/arch/powerpc/include/uapi/asm/unistd.h linux-4.9.76-vs2.3.9.5/arch/powerpc/include/uapi/asm/unistd.h
496 --- linux-4.9.76/arch/powerpc/include/uapi/asm/unistd.h 2016-12-11 19:17:54.000000000 +0000
497 +++ linux-4.9.76-vs2.3.9.5/arch/powerpc/include/uapi/asm/unistd.h 2018-01-10 02:50:49.000000000 +0000
500 #define __NR_rtas 255
501 #define __NR_sys_debug_setcontext 256
502 -/* Number 257 is reserved for vserver */
503 +#define __NR_vserver 257
504 #define __NR_migrate_pages 258
505 #define __NR_mbind 259
506 #define __NR_get_mempolicy 260
507 diff -NurpP --minimal linux-4.9.76/arch/s390/Kconfig linux-4.9.76-vs2.3.9.5/arch/s390/Kconfig
508 --- linux-4.9.76/arch/s390/Kconfig 2018-01-13 21:28:39.000000000 +0000
509 +++ linux-4.9.76-vs2.3.9.5/arch/s390/Kconfig 2018-01-10 02:50:49.000000000 +0000
510 @@ -729,6 +729,8 @@ source "fs/Kconfig"
512 source "arch/s390/Kconfig.debug"
514 +source "kernel/vserver/Kconfig"
516 source "security/Kconfig"
518 source "crypto/Kconfig"
519 diff -NurpP --minimal linux-4.9.76/arch/s390/include/asm/tlb.h linux-4.9.76-vs2.3.9.5/arch/s390/include/asm/tlb.h
520 --- linux-4.9.76/arch/s390/include/asm/tlb.h 2016-12-11 19:17:54.000000000 +0000
521 +++ linux-4.9.76-vs2.3.9.5/arch/s390/include/asm/tlb.h 2018-01-10 02:50:49.000000000 +0000
523 #include <linux/mm.h>
524 #include <linux/pagemap.h>
525 #include <linux/swap.h>
527 #include <asm/processor.h>
528 #include <asm/pgalloc.h>
529 #include <asm/tlbflush.h>
530 diff -NurpP --minimal linux-4.9.76/arch/s390/include/uapi/asm/unistd.h linux-4.9.76-vs2.3.9.5/arch/s390/include/uapi/asm/unistd.h
531 --- linux-4.9.76/arch/s390/include/uapi/asm/unistd.h 2016-12-11 19:17:54.000000000 +0000
532 +++ linux-4.9.76-vs2.3.9.5/arch/s390/include/uapi/asm/unistd.h 2018-01-10 02:50:49.000000000 +0000
534 #define __NR_clock_gettime 260
535 #define __NR_clock_getres 261
536 #define __NR_clock_nanosleep 262
537 -/* Number 263 is reserved for vserver */
538 +#define __NR_vserver 263
539 #define __NR_statfs64 265
540 #define __NR_fstatfs64 266
541 #define __NR_remap_file_pages 267
542 diff -NurpP --minimal linux-4.9.76/arch/s390/kernel/ptrace.c linux-4.9.76-vs2.3.9.5/arch/s390/kernel/ptrace.c
543 --- linux-4.9.76/arch/s390/kernel/ptrace.c 2018-01-13 21:28:39.000000000 +0000
544 +++ linux-4.9.76-vs2.3.9.5/arch/s390/kernel/ptrace.c 2018-01-10 02:50:49.000000000 +0000
546 #include <linux/tracehook.h>
547 #include <linux/seccomp.h>
548 #include <linux/compat.h>
549 +#include <linux/vs_base.h>
550 #include <trace/syscall.h>
551 #include <asm/segment.h>
552 #include <asm/page.h>
553 diff -NurpP --minimal linux-4.9.76/arch/s390/kernel/syscalls.S linux-4.9.76-vs2.3.9.5/arch/s390/kernel/syscalls.S
554 --- linux-4.9.76/arch/s390/kernel/syscalls.S 2018-01-13 21:28:39.000000000 +0000
555 +++ linux-4.9.76-vs2.3.9.5/arch/s390/kernel/syscalls.S 2018-01-10 02:50:49.000000000 +0000
556 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,compat_sys_clo
557 SYSCALL(sys_clock_gettime,compat_sys_clock_gettime) /* 260 */
558 SYSCALL(sys_clock_getres,compat_sys_clock_getres)
559 SYSCALL(sys_clock_nanosleep,compat_sys_clock_nanosleep)
560 -NI_SYSCALL /* reserved for vserver */
561 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
562 SYSCALL(sys_ni_syscall,compat_sys_s390_fadvise64_64)
563 SYSCALL(sys_statfs64,compat_sys_statfs64)
564 SYSCALL(sys_fstatfs64,compat_sys_fstatfs64)
565 diff -NurpP --minimal linux-4.9.76/arch/sh/Kconfig linux-4.9.76-vs2.3.9.5/arch/sh/Kconfig
566 --- linux-4.9.76/arch/sh/Kconfig 2016-12-11 19:17:54.000000000 +0000
567 +++ linux-4.9.76-vs2.3.9.5/arch/sh/Kconfig 2018-01-10 02:50:49.000000000 +0000
568 @@ -904,6 +904,8 @@ source "fs/Kconfig"
570 source "arch/sh/Kconfig.debug"
572 +source "kernel/vserver/Kconfig"
574 source "security/Kconfig"
576 source "crypto/Kconfig"
577 diff -NurpP --minimal linux-4.9.76/arch/sh/kernel/irq.c linux-4.9.76-vs2.3.9.5/arch/sh/kernel/irq.c
578 --- linux-4.9.76/arch/sh/kernel/irq.c 2016-12-11 19:17:54.000000000 +0000
579 +++ linux-4.9.76-vs2.3.9.5/arch/sh/kernel/irq.c 2018-01-10 02:50:49.000000000 +0000
581 #include <linux/ftrace.h>
582 #include <linux/delay.h>
583 #include <linux/ratelimit.h>
584 +// #include <linux/vs_context.h>
585 #include <asm/processor.h>
586 #include <asm/machvec.h>
587 #include <asm/uaccess.h>
588 diff -NurpP --minimal linux-4.9.76/arch/sparc/Kconfig linux-4.9.76-vs2.3.9.5/arch/sparc/Kconfig
589 --- linux-4.9.76/arch/sparc/Kconfig 2018-01-13 21:28:39.000000000 +0000
590 +++ linux-4.9.76-vs2.3.9.5/arch/sparc/Kconfig 2018-01-10 02:50:49.000000000 +0000
591 @@ -580,6 +580,8 @@ source "fs/Kconfig"
593 source "arch/sparc/Kconfig.debug"
595 +source "kernel/vserver/Kconfig"
597 source "security/Kconfig"
599 source "crypto/Kconfig"
600 diff -NurpP --minimal linux-4.9.76/arch/sparc/include/uapi/asm/unistd.h linux-4.9.76-vs2.3.9.5/arch/sparc/include/uapi/asm/unistd.h
601 --- linux-4.9.76/arch/sparc/include/uapi/asm/unistd.h 2016-12-11 19:17:54.000000000 +0000
602 +++ linux-4.9.76-vs2.3.9.5/arch/sparc/include/uapi/asm/unistd.h 2018-01-10 02:50:49.000000000 +0000
604 #define __NR_timer_getoverrun 264
605 #define __NR_timer_delete 265
606 #define __NR_timer_create 266
607 -/* #define __NR_vserver 267 Reserved for VSERVER */
608 +#define __NR_vserver 267
609 #define __NR_io_setup 268
610 #define __NR_io_destroy 269
611 #define __NR_io_submit 270
612 diff -NurpP --minimal linux-4.9.76/arch/sparc/kernel/systbls_32.S linux-4.9.76-vs2.3.9.5/arch/sparc/kernel/systbls_32.S
613 --- linux-4.9.76/arch/sparc/kernel/systbls_32.S 2016-12-11 19:17:54.000000000 +0000
614 +++ linux-4.9.76-vs2.3.9.5/arch/sparc/kernel/systbls_32.S 2018-01-10 02:50:49.000000000 +0000
615 @@ -70,7 +70,7 @@ sys_call_table:
616 /*250*/ .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
617 /*255*/ .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
618 /*260*/ .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
619 -/*265*/ .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
620 +/*265*/ .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
621 /*270*/ .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
622 /*275*/ .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
623 /*280*/ .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
624 diff -NurpP --minimal linux-4.9.76/arch/sparc/kernel/systbls_64.S linux-4.9.76-vs2.3.9.5/arch/sparc/kernel/systbls_64.S
625 --- linux-4.9.76/arch/sparc/kernel/systbls_64.S 2016-12-11 19:17:54.000000000 +0000
626 +++ linux-4.9.76-vs2.3.9.5/arch/sparc/kernel/systbls_64.S 2018-01-10 02:50:49.000000000 +0000
627 @@ -71,7 +71,7 @@ sys_call_table32:
628 /*250*/ .word sys_mremap, compat_sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
629 .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
630 /*260*/ .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
631 - .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
632 + .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
633 /*270*/ .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
634 .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
635 /*280*/ .word sys_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
636 @@ -152,7 +152,7 @@ sys_call_table:
637 /*250*/ .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
638 .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
639 /*260*/ .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
640 - .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
641 + .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
642 /*270*/ .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
643 .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
644 /*280*/ .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
645 diff -NurpP --minimal linux-4.9.76/arch/um/Kconfig.rest linux-4.9.76-vs2.3.9.5/arch/um/Kconfig.rest
646 --- linux-4.9.76/arch/um/Kconfig.rest 2016-12-11 19:17:54.000000000 +0000
647 +++ linux-4.9.76-vs2.3.9.5/arch/um/Kconfig.rest 2018-01-10 02:50:49.000000000 +0000
648 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
652 +source "kernel/vserver/Kconfig"
654 source "security/Kconfig"
656 source "crypto/Kconfig"
657 diff -NurpP --minimal linux-4.9.76/arch/x86/Kconfig linux-4.9.76-vs2.3.9.5/arch/x86/Kconfig
658 --- linux-4.9.76/arch/x86/Kconfig 2018-01-13 21:28:39.000000000 +0000
659 +++ linux-4.9.76-vs2.3.9.5/arch/x86/Kconfig 2018-01-10 02:50:49.000000000 +0000
660 @@ -2763,6 +2763,8 @@ source "fs/Kconfig"
662 source "arch/x86/Kconfig.debug"
664 +source "kernel/vserver/Kconfig"
666 source "security/Kconfig"
668 source "crypto/Kconfig"
669 diff -NurpP --minimal linux-4.9.76/arch/x86/entry/syscalls/syscall_32.tbl linux-4.9.76-vs2.3.9.5/arch/x86/entry/syscalls/syscall_32.tbl
670 --- linux-4.9.76/arch/x86/entry/syscalls/syscall_32.tbl 2016-12-11 19:17:54.000000000 +0000
671 +++ linux-4.9.76-vs2.3.9.5/arch/x86/entry/syscalls/syscall_32.tbl 2018-01-10 02:50:49.000000000 +0000
673 270 i386 tgkill sys_tgkill
674 271 i386 utimes sys_utimes compat_sys_utimes
675 272 i386 fadvise64_64 sys_fadvise64_64 sys32_fadvise64_64
677 +273 i386 vserver sys_vserver sys32_vserver
678 274 i386 mbind sys_mbind
679 275 i386 get_mempolicy sys_get_mempolicy compat_sys_get_mempolicy
680 276 i386 set_mempolicy sys_set_mempolicy
681 diff -NurpP --minimal linux-4.9.76/arch/x86/entry/syscalls/syscall_64.tbl linux-4.9.76-vs2.3.9.5/arch/x86/entry/syscalls/syscall_64.tbl
682 --- linux-4.9.76/arch/x86/entry/syscalls/syscall_64.tbl 2016-12-11 19:17:54.000000000 +0000
683 +++ linux-4.9.76-vs2.3.9.5/arch/x86/entry/syscalls/syscall_64.tbl 2018-01-10 02:50:49.000000000 +0000
685 233 common epoll_ctl sys_epoll_ctl
686 234 common tgkill sys_tgkill
687 235 common utimes sys_utimes
689 +236 64 vserver sys_vserver
690 237 common mbind sys_mbind
691 238 common set_mempolicy sys_set_mempolicy
692 239 common get_mempolicy sys_get_mempolicy
693 diff -NurpP --minimal linux-4.9.76/block/ioprio.c linux-4.9.76-vs2.3.9.5/block/ioprio.c
694 --- linux-4.9.76/block/ioprio.c 2016-12-11 19:17:54.000000000 +0000
695 +++ linux-4.9.76-vs2.3.9.5/block/ioprio.c 2018-01-10 02:50:49.000000000 +0000
697 #include <linux/syscalls.h>
698 #include <linux/security.h>
699 #include <linux/pid_namespace.h>
700 +#include <linux/vs_base.h>
702 int set_task_ioprio(struct task_struct *task, int ioprio)
704 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
706 pgrp = find_vpid(who);
707 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
708 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
710 ret = set_task_ioprio(p, ioprio);
713 @@ -203,6 +206,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
715 pgrp = find_vpid(who);
716 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
717 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
719 tmpio = get_task_ioprio(p);
722 diff -NurpP --minimal linux-4.9.76/drivers/block/Kconfig linux-4.9.76-vs2.3.9.5/drivers/block/Kconfig
723 --- linux-4.9.76/drivers/block/Kconfig 2016-12-11 19:17:54.000000000 +0000
724 +++ linux-4.9.76-vs2.3.9.5/drivers/block/Kconfig 2018-01-10 02:50:49.000000000 +0000
725 @@ -273,6 +273,13 @@ config BLK_DEV_CRYPTOLOOP
727 source "drivers/block/drbd/Kconfig"
729 +config BLK_DEV_VROOT
730 + tristate "Virtual Root device support"
731 + depends on QUOTACTL
733 + Saying Y here will allow you to use quota/fs ioctls on a shared
734 + partition within a virtual server without compromising security.
737 tristate "Network block device support"
739 diff -NurpP --minimal linux-4.9.76/drivers/block/Makefile linux-4.9.76-vs2.3.9.5/drivers/block/Makefile
740 --- linux-4.9.76/drivers/block/Makefile 2016-12-11 19:17:54.000000000 +0000
741 +++ linux-4.9.76-vs2.3.9.5/drivers/block/Makefile 2018-01-10 02:50:49.000000000 +0000
742 @@ -31,6 +31,7 @@ obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
744 obj-$(CONFIG_BLK_DEV_SX8) += sx8.o
745 obj-$(CONFIG_BLK_DEV_HD) += hd.o
746 +obj-$(CONFIG_BLK_DEV_VROOT) += vroot.o
748 obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o
749 obj-$(CONFIG_XEN_BLKDEV_BACKEND) += xen-blkback/
750 diff -NurpP --minimal linux-4.9.76/drivers/block/loop.c linux-4.9.76-vs2.3.9.5/drivers/block/loop.c
751 --- linux-4.9.76/drivers/block/loop.c 2018-01-13 21:28:40.000000000 +0000
752 +++ linux-4.9.76-vs2.3.9.5/drivers/block/loop.c 2018-01-10 02:50:49.000000000 +0000
754 #include <linux/miscdevice.h>
755 #include <linux/falloc.h>
756 #include <linux/uio.h>
757 +#include <linux/vs_context.h>
760 #include <asm/uaccess.h>
761 @@ -924,6 +925,7 @@ static int loop_set_fd(struct loop_devic
762 lo->lo_blocksize = lo_blocksize;
763 lo->lo_device = bdev;
764 lo->lo_flags = lo_flags;
765 + lo->lo_xid = vx_current_xid();
766 lo->lo_backing_file = file;
769 @@ -1044,6 +1046,7 @@ static int loop_clr_fd(struct loop_devic
771 lo->lo_sizelimit = 0;
772 lo->lo_encrypt_key_size = 0;
774 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
775 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
776 memset(lo->lo_file_name, 0, LO_NAME_SIZE);
777 @@ -1090,7 +1093,7 @@ loop_set_status(struct loop_device *lo,
779 if (lo->lo_encrypt_key_size &&
780 !uid_eq(lo->lo_key_owner, uid) &&
781 - !capable(CAP_SYS_ADMIN))
782 + !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
784 if (lo->lo_state != Lo_bound)
786 @@ -1191,7 +1194,8 @@ loop_get_status(struct loop_device *lo,
787 memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
788 info->lo_encrypt_type =
789 lo->lo_encryption ? lo->lo_encryption->number : 0;
790 - if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
791 + if (lo->lo_encrypt_key_size &&
792 + vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
793 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
794 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
795 lo->lo_encrypt_key_size);
796 @@ -1552,6 +1556,11 @@ static int lo_open(struct block_device *
800 + if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
805 atomic_inc(&lo->lo_refcnt);
807 mutex_unlock(&loop_index_mutex);
808 diff -NurpP --minimal linux-4.9.76/drivers/block/loop.h linux-4.9.76-vs2.3.9.5/drivers/block/loop.h
809 --- linux-4.9.76/drivers/block/loop.h 2016-12-11 19:17:54.000000000 +0000
810 +++ linux-4.9.76-vs2.3.9.5/drivers/block/loop.h 2018-01-10 02:50:49.000000000 +0000
811 @@ -43,6 +43,7 @@ struct loop_device {
812 struct loop_func_table *lo_encryption;
814 kuid_t lo_key_owner; /* Who set the key */
816 int (*ioctl)(struct loop_device *, int cmd,
819 diff -NurpP --minimal linux-4.9.76/drivers/block/vroot.c linux-4.9.76-vs2.3.9.5/drivers/block/vroot.c
820 --- linux-4.9.76/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
821 +++ linux-4.9.76-vs2.3.9.5/drivers/block/vroot.c 2018-01-13 22:00:41.000000000 +0000
824 + * linux/drivers/block/vroot.c
826 + * written by Herbert P?tzl, 9/11/2002
827 + * ported to 2.6.10 by Herbert P?tzl, 30/12/2004
829 + * based on the loop.c code by Theodore Ts'o.
831 + * Copyright (C) 2002-2007 by Herbert P?tzl.
832 + * Redistribution of this file is permitted under the
833 + * GNU General Public License.
837 +#include <linux/module.h>
838 +#include <linux/moduleparam.h>
839 +#include <linux/file.h>
840 +#include <linux/major.h>
841 +#include <linux/blkdev.h>
842 +#include <linux/slab.h>
844 +#include <linux/vroot.h>
845 +#include <linux/vs_context.h>
848 +static int max_vroot = 8;
850 +static struct vroot_device *vroot_dev;
851 +static struct gendisk **disks;
854 +static int vroot_set_dev(
855 + struct vroot_device *vr,
856 + struct block_device *bdev,
859 + struct block_device *real_bdev;
861 + struct inode *inode;
865 + if (vr->vr_state != Vr_unbound)
874 + inode = file->f_path.dentry->d_inode;
877 + if (S_ISBLK(inode->i_mode)) {
878 + real_bdev = inode->i_bdev;
879 + vr->vr_device = real_bdev;
880 + __iget(real_bdev->bd_inode);
884 + vxdprintk(VXD_CBIT(misc, 0),
885 + "vroot[%d]_set_dev: dev=" VXF_DEV,
886 + vr->vr_number, VXD_DEV(real_bdev));
888 + vr->vr_state = Vr_bound;
897 +static int vroot_clr_dev(
898 + struct vroot_device *vr,
899 + struct block_device *bdev)
901 + struct block_device *real_bdev;
903 + if (vr->vr_state != Vr_bound)
905 + if (vr->vr_refcnt > 1) /* we needed one fd for the ioctl */
908 + real_bdev = vr->vr_device;
910 + vxdprintk(VXD_CBIT(misc, 0),
911 + "vroot[%d]_clr_dev: dev=" VXF_DEV,
912 + vr->vr_number, VXD_DEV(real_bdev));
915 + vr->vr_state = Vr_unbound;
916 + vr->vr_device = NULL;
921 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
922 + unsigned int cmd, unsigned long arg)
924 + struct vroot_device *vr = bdev->bd_disk->private_data;
927 + down(&vr->vr_ctl_mutex);
929 + case VROOT_SET_DEV:
930 + err = vroot_set_dev(vr, bdev, arg);
932 + case VROOT_CLR_DEV:
933 + err = vroot_clr_dev(vr, bdev);
939 + up(&vr->vr_ctl_mutex);
943 +static int vr_open(struct block_device *bdev, fmode_t mode)
945 + struct vroot_device *vr = bdev->bd_disk->private_data;
947 + down(&vr->vr_ctl_mutex);
949 + up(&vr->vr_ctl_mutex);
953 +static void vr_release(struct gendisk *disk, fmode_t mode)
955 + struct vroot_device *vr = disk->private_data;
957 + down(&vr->vr_ctl_mutex);
959 + up(&vr->vr_ctl_mutex);
962 +static struct block_device_operations vr_fops = {
963 + .owner = THIS_MODULE,
965 + .release = vr_release,
969 +static blk_qc_t vroot_make_request(struct request_queue *q, struct bio *bio)
971 + printk("vroot_make_request %p, %p\n", q, bio);
973 + return BLK_QC_T_NONE;
976 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
978 + struct inode *inode = bdev->bd_inode;
979 + struct vroot_device *vr;
980 + struct block_device *real_bdev;
981 + int minor = iminor(inode);
983 + vr = &vroot_dev[minor];
984 + real_bdev = vr->vr_device;
986 + vxdprintk(VXD_CBIT(misc, 0),
987 + "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
988 + vr->vr_number, VXD_DEV(real_bdev));
990 + if (vr->vr_state != Vr_bound)
991 + return ERR_PTR(-ENXIO);
993 + __iget(real_bdev->bd_inode);
1000 + * And now the modules code and kernel interface.
1003 +module_param(max_vroot, int, 0);
1005 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1006 +MODULE_LICENSE("GPL");
1007 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1009 +MODULE_AUTHOR ("Herbert P?tzl");
1010 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1013 +int __init vroot_init(void)
1017 + if (max_vroot < 1 || max_vroot > 256) {
1018 + max_vroot = MAX_VROOT_DEFAULT;
1019 + printk(KERN_WARNING "vroot: invalid max_vroot "
1020 + "(must be between 1 and 256), "
1021 + "using default (%d)\n", max_vroot);
1024 + if (register_blkdev(VROOT_MAJOR, "vroot"))
1028 + vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1031 + memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1033 + disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1037 + for (i = 0; i < max_vroot; i++) {
1038 + disks[i] = alloc_disk(1);
1041 + disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1042 + if (!disks[i]->queue)
1044 + blk_queue_make_request(disks[i]->queue, vroot_make_request);
1047 + for (i = 0; i < max_vroot; i++) {
1048 + struct vroot_device *vr = &vroot_dev[i];
1049 + struct gendisk *disk = disks[i];
1051 + memset(vr, 0, sizeof(*vr));
1052 + sema_init(&vr->vr_ctl_mutex, 1);
1053 + vr->vr_number = i;
1054 + disk->major = VROOT_MAJOR;
1055 + disk->first_minor = i;
1056 + disk->fops = &vr_fops;
1057 + sprintf(disk->disk_name, "vroot%d", i);
1058 + disk->private_data = vr;
1061 + err = register_vroot_grb(&__vroot_get_real_bdev);
1065 + for (i = 0; i < max_vroot; i++)
1066 + add_disk(disks[i]);
1067 + printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1072 + put_disk(disks[i]);
1077 + unregister_blkdev(VROOT_MAJOR, "vroot");
1078 + printk(KERN_ERR "vroot: ran out of memory\n");
1082 +void vroot_exit(void)
1086 + if (unregister_vroot_grb(&__vroot_get_real_bdev))
1087 + printk(KERN_WARNING "vroot: cannot unregister grb\n");
1089 + for (i = 0; i < max_vroot; i++) {
1090 + del_gendisk(disks[i]);
1091 + put_disk(disks[i]);
1093 + unregister_blkdev(VROOT_MAJOR, "vroot");
1099 +module_init(vroot_init);
1100 +module_exit(vroot_exit);
1104 +static int __init max_vroot_setup(char *str)
1106 + max_vroot = simple_strtol(str, NULL, 0);
1110 +__setup("max_vroot=", max_vroot_setup);
1114 diff -NurpP --minimal linux-4.9.76/drivers/md/dm-core.h linux-4.9.76-vs2.3.9.5/drivers/md/dm-core.h
1115 --- linux-4.9.76/drivers/md/dm-core.h 2018-01-13 21:28:44.000000000 +0000
1116 +++ linux-4.9.76-vs2.3.9.5/drivers/md/dm-core.h 2018-01-10 08:35:10.000000000 +0000
1117 @@ -52,6 +52,7 @@ struct mapped_device {
1120 atomic_t open_count;
1123 struct dm_target *immutable_target;
1124 struct target_type *immutable_target_type;
1125 diff -NurpP --minimal linux-4.9.76/drivers/md/dm-ioctl.c linux-4.9.76-vs2.3.9.5/drivers/md/dm-ioctl.c
1126 --- linux-4.9.76/drivers/md/dm-ioctl.c 2018-01-13 21:28:44.000000000 +0000
1127 +++ linux-4.9.76-vs2.3.9.5/drivers/md/dm-ioctl.c 2018-01-10 02:50:49.000000000 +0000
1129 #include <linux/dm-ioctl.h>
1130 #include <linux/hdreg.h>
1131 #include <linux/compat.h>
1132 +#include <linux/vs_context.h>
1134 #include <asm/uaccess.h>
1136 @@ -114,7 +115,8 @@ static struct hash_cell *__get_name_cell
1137 unsigned int h = hash_str(str);
1139 list_for_each_entry (hc, _name_buckets + h, name_list)
1140 - if (!strcmp(hc->name, str)) {
1141 + if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1142 + !strcmp(hc->name, str)) {
1146 @@ -128,7 +130,8 @@ static struct hash_cell *__get_uuid_cell
1147 unsigned int h = hash_str(str);
1149 list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1150 - if (!strcmp(hc->uuid, str)) {
1151 + if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1152 + !strcmp(hc->uuid, str)) {
1156 @@ -139,13 +142,15 @@ static struct hash_cell *__get_uuid_cell
1157 static struct hash_cell *__get_dev_cell(uint64_t dev)
1159 struct mapped_device *md;
1160 - struct hash_cell *hc;
1161 + struct hash_cell *hc = NULL;
1163 md = dm_get_md(huge_decode_dev(dev));
1167 - hc = dm_get_mdptr(md);
1168 + if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1169 + hc = dm_get_mdptr(md);
1174 @@ -467,6 +472,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1176 static int remove_all(struct dm_ioctl *param, size_t param_size)
1178 + if (!vx_check(0, VS_ADMIN))
1181 dm_hash_remove_all(true, !!(param->flags & DM_DEFERRED_REMOVE), false);
1182 param->data_size = 0;
1184 @@ -514,6 +522,8 @@ static int list_devices(struct dm_ioctl
1186 for (i = 0; i < NUM_BUCKETS; i++) {
1187 list_for_each_entry (hc, _name_buckets + i, name_list) {
1188 + if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1190 needed += sizeof(struct dm_name_list);
1191 needed += strlen(hc->name) + 1;
1192 needed += ALIGN_MASK;
1193 @@ -537,6 +547,8 @@ static int list_devices(struct dm_ioctl
1195 for (i = 0; i < NUM_BUCKETS; i++) {
1196 list_for_each_entry (hc, _name_buckets + i, name_list) {
1197 + if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1200 old_nl->next = (uint32_t) ((void *) nl -
1202 @@ -1805,8 +1817,8 @@ static int ctl_ioctl(uint command, struc
1203 size_t input_param_size;
1204 struct dm_ioctl param_kernel;
1206 - /* only root can play with this */
1207 - if (!capable(CAP_SYS_ADMIN))
1208 + /* only root and certain contexts can play with this */
1209 + if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1212 if (_IOC_TYPE(command) != DM_IOCTL)
1213 diff -NurpP --minimal linux-4.9.76/drivers/md/dm.c linux-4.9.76-vs2.3.9.5/drivers/md/dm.c
1214 --- linux-4.9.76/drivers/md/dm.c 2018-01-13 21:28:45.000000000 +0000
1215 +++ linux-4.9.76-vs2.3.9.5/drivers/md/dm.c 2018-01-10 08:32:35.000000000 +0000
1217 #include <linux/wait.h>
1218 #include <linux/pr.h>
1219 #include <linux/vmalloc.h>
1220 +#include <linux/vs_base.h>
1222 #define DM_MSG_PREFIX "core"
1224 @@ -300,6 +301,7 @@ int dm_deleting_md(struct mapped_device
1225 static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1227 struct mapped_device *md;
1230 spin_lock(&_minor_lock);
1232 @@ -308,17 +310,19 @@ static int dm_blk_open(struct block_devi
1235 if (test_bit(DMF_FREEING, &md->flags) ||
1236 - dm_deleting_md(md)) {
1238 + dm_deleting_md(md))
1242 + if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1247 atomic_inc(&md->open_count);
1250 spin_unlock(&_minor_lock);
1252 - return md ? 0 : -ENXIO;
1256 static void dm_blk_close(struct gendisk *disk, fmode_t mode)
1257 @@ -744,6 +748,14 @@ int dm_set_geometry(struct mapped_device
1262 + * Get the xid associated with a dm device
1264 +vxid_t dm_get_xid(struct mapped_device *md)
1269 /*-----------------------------------------------------------------
1271 * A more elegant soln is in the works that uses the queue
1272 @@ -1548,6 +1560,7 @@ static struct mapped_device *alloc_dev(i
1273 INIT_LIST_HEAD(&md->uevent_list);
1274 INIT_LIST_HEAD(&md->table_devices);
1275 spin_lock_init(&md->uevent_lock);
1276 + md->xid = vx_current_xid();
1278 md->queue = blk_alloc_queue_node(GFP_KERNEL, numa_node_id);
1280 diff -NurpP --minimal linux-4.9.76/drivers/md/dm.h linux-4.9.76-vs2.3.9.5/drivers/md/dm.h
1281 --- linux-4.9.76/drivers/md/dm.h 2016-12-11 19:17:54.000000000 +0000
1282 +++ linux-4.9.76-vs2.3.9.5/drivers/md/dm.h 2018-01-10 02:50:49.000000000 +0000
1283 @@ -45,6 +45,8 @@ struct dm_dev_internal {
1285 struct dm_md_mempools;
1287 +vxid_t dm_get_xid(struct mapped_device *md);
1289 /*-----------------------------------------------------------------
1290 * Internal table functions.
1291 *---------------------------------------------------------------*/
1292 diff -NurpP --minimal linux-4.9.76/drivers/net/tun.c linux-4.9.76-vs2.3.9.5/drivers/net/tun.c
1293 --- linux-4.9.76/drivers/net/tun.c 2018-01-13 21:28:50.000000000 +0000
1294 +++ linux-4.9.76-vs2.3.9.5/drivers/net/tun.c 2018-01-10 02:50:49.000000000 +0000
1296 #include <linux/nsproxy.h>
1297 #include <linux/virtio_net.h>
1298 #include <linux/rcupdate.h>
1299 +#include <linux/vs_network.h>
1300 #include <net/net_namespace.h>
1301 #include <net/netns/generic.h>
1302 #include <net/rtnetlink.h>
1303 @@ -194,6 +195,7 @@ struct tun_struct {
1309 struct net_device *dev;
1310 netdev_features_t set_features;
1311 @@ -490,6 +492,7 @@ static inline bool tun_not_capable(struc
1312 return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1313 (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1314 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1315 + /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1318 static void tun_set_real_num_queues(struct tun_struct *tun)
1319 @@ -1549,6 +1552,7 @@ static void tun_setup(struct net_device
1321 tun->owner = INVALID_UID;
1322 tun->group = INVALID_GID;
1323 + tun->nid = nx_current_nid();
1325 dev->ethtool_ops = &tun_ethtool_ops;
1326 dev->destructor = tun_free_netdev;
1327 @@ -1760,7 +1764,7 @@ static int tun_set_iff(struct net *net,
1328 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1331 - if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1332 + if (!nx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1334 err = security_tun_dev_create();
1336 @@ -2125,6 +2129,16 @@ static long __tun_chr_ioctl(struct file
1337 from_kgid(&init_user_ns, tun->group));
1341 + if (!capable(CAP_CONTEXT))
1344 + /* Set nid owner of the device */
1345 + tun->nid = (vnid_t) arg;
1347 + tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1351 /* Only allow setting the type when the interface is down */
1352 if (tun->dev->flags & IFF_UP) {
1353 diff -NurpP --minimal linux-4.9.76/drivers/scsi/cxgbi/libcxgbi.c linux-4.9.76-vs2.3.9.5/drivers/scsi/cxgbi/libcxgbi.c
1354 --- linux-4.9.76/drivers/scsi/cxgbi/libcxgbi.c 2016-12-11 19:17:54.000000000 +0000
1355 +++ linux-4.9.76-vs2.3.9.5/drivers/scsi/cxgbi/libcxgbi.c 2018-01-10 02:50:49.000000000 +0000
1356 @@ -772,7 +772,8 @@ static struct cxgbi_sock *cxgbi_check_ro
1357 struct inet6_dev *idev = ip6_dst_idev((struct dst_entry *)rt);
1359 err = ipv6_dev_get_saddr(&init_net, idev ? idev->dev : NULL,
1360 - &daddr6->sin6_addr, 0, &pref_saddr);
1361 + &daddr6->sin6_addr, 0, &pref_saddr,
1364 pr_info("failed to get source address to reach %pI6\n",
1365 &daddr6->sin6_addr);
1366 diff -NurpP --minimal linux-4.9.76/drivers/tty/sysrq.c linux-4.9.76-vs2.3.9.5/drivers/tty/sysrq.c
1367 --- linux-4.9.76/drivers/tty/sysrq.c 2018-01-13 21:28:54.000000000 +0000
1368 +++ linux-4.9.76-vs2.3.9.5/drivers/tty/sysrq.c 2018-01-10 02:50:49.000000000 +0000
1370 #include <linux/syscalls.h>
1371 #include <linux/of.h>
1372 #include <linux/rcupdate.h>
1373 +#include <linux/vserver/debug.h>
1375 #include <asm/ptrace.h>
1376 #include <asm/irq_regs.h>
1377 @@ -428,6 +429,21 @@ static struct sysrq_key_op sysrq_unrt_op
1378 .enable_mask = SYSRQ_ENABLE_RTNICE,
1382 +#ifdef CONFIG_VSERVER_DEBUG
1383 +static void sysrq_handle_vxinfo(int key)
1385 + dump_vx_info_inactive((key == 'x') ? 0 : 1);
1388 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1389 + .handler = sysrq_handle_vxinfo,
1390 + .help_msg = "conteXt",
1391 + .action_msg = "Show Context Info",
1392 + .enable_mask = SYSRQ_ENABLE_DUMP,
1396 /* Key Operations table and lock */
1397 static DEFINE_SPINLOCK(sysrq_key_table_lock);
1399 @@ -484,7 +500,11 @@ static struct sysrq_key_op *sysrq_key_ta
1400 /* x: May be registered on mips for TLB dump */
1401 /* x: May be registered on ppc/powerpc for xmon */
1402 /* x: May be registered on sparc64 for global PMU dump */
1403 +#ifdef CONFIG_VSERVER_DEBUG
1404 + &sysrq_showvxinfo_op, /* x */
1408 /* y: May be registered on sparc64 for global register dump */
1410 &sysrq_ftrace_dump_op, /* z */
1411 @@ -499,6 +519,8 @@ static int sysrq_key_table_key2index(int
1413 else if ((key >= 'a') && (key <= 'z'))
1414 retval = key + 10 - 'a';
1415 + else if ((key >= 'A') && (key <= 'Z'))
1416 + retval = key + 10 - 'A';
1420 diff -NurpP --minimal linux-4.9.76/drivers/tty/tty_io.c linux-4.9.76-vs2.3.9.5/drivers/tty/tty_io.c
1421 --- linux-4.9.76/drivers/tty/tty_io.c 2016-12-11 19:17:54.000000000 +0000
1422 +++ linux-4.9.76-vs2.3.9.5/drivers/tty/tty_io.c 2018-01-10 02:50:49.000000000 +0000
1425 #include <linux/kmod.h>
1426 #include <linux/nsproxy.h>
1427 +#include <linux/vs_pid.h>
1429 #undef TTY_DEBUG_HANGUP
1430 #ifdef TTY_DEBUG_HANGUP
1431 @@ -2286,7 +2287,8 @@ static int tiocsti(struct tty_struct *tt
1433 struct tty_ldisc *ld;
1435 - if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1436 + if (((current->signal->tty != tty) &&
1437 + !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1439 if (get_user(ch, p))
1441 @@ -2601,6 +2603,7 @@ static int tiocspgrp(struct tty_struct *
1443 if (get_user(pgrp_nr, p))
1445 + pgrp_nr = vx_rmap_pid(pgrp_nr);
1449 diff -NurpP --minimal linux-4.9.76/fs/attr.c linux-4.9.76-vs2.3.9.5/fs/attr.c
1450 --- linux-4.9.76/fs/attr.c 2016-12-11 19:17:54.000000000 +0000
1451 +++ linux-4.9.76-vs2.3.9.5/fs/attr.c 2018-01-10 02:50:49.000000000 +0000
1453 #include <linux/security.h>
1454 #include <linux/evm.h>
1455 #include <linux/ima.h>
1456 +#include <linux/proc_fs.h>
1457 +#include <linux/devpts_fs.h>
1458 +#include <linux/vs_tag.h>
1461 * setattr_prepare - check if attribute changes to a dentry are allowed
1462 @@ -90,6 +93,10 @@ kill_priv:
1466 + /* check for inode tag permission */
1467 + if (dx_permission(inode, MAY_WRITE))
1472 EXPORT_SYMBOL(setattr_prepare);
1473 @@ -160,6 +167,8 @@ void setattr_copy(struct inode *inode, c
1474 inode->i_uid = attr->ia_uid;
1475 if (ia_valid & ATTR_GID)
1476 inode->i_gid = attr->ia_gid;
1477 + if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1478 + inode->i_tag = attr->ia_tag;
1479 if (ia_valid & ATTR_ATIME)
1480 inode->i_atime = timespec_trunc(attr->ia_atime,
1481 inode->i_sb->s_time_gran);
1482 @@ -210,7 +219,8 @@ int notify_change(struct dentry * dentry
1484 WARN_ON_ONCE(!inode_is_locked(inode));
1486 - if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1487 + if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1488 + ATTR_TAG | ATTR_TIMES_SET)) {
1489 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1492 diff -NurpP --minimal linux-4.9.76/fs/block_dev.c linux-4.9.76-vs2.3.9.5/fs/block_dev.c
1493 --- linux-4.9.76/fs/block_dev.c 2018-01-13 21:28:56.000000000 +0000
1494 +++ linux-4.9.76-vs2.3.9.5/fs/block_dev.c 2018-01-13 00:48:31.000000000 +0000
1496 #include <linux/dax.h>
1497 #include <linux/badblocks.h>
1498 #include <linux/falloc.h>
1499 +#include <linux/vs_device.h>
1500 #include <asm/uaccess.h>
1501 #include "internal.h"
1503 @@ -720,6 +721,7 @@ struct block_device *bdget(dev_t dev)
1504 bdev->bd_invalidated = 0;
1505 inode->i_mode = S_IFBLK;
1506 inode->i_rdev = dev;
1507 + inode->i_mdev = dev;
1508 inode->i_bdev = bdev;
1509 inode->i_data.a_ops = &def_blk_aops;
1510 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1511 @@ -766,6 +768,11 @@ EXPORT_SYMBOL(bdput);
1512 static struct block_device *bd_acquire(struct inode *inode)
1514 struct block_device *bdev;
1517 + if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1519 + inode->i_mdev = mdev;
1521 spin_lock(&bdev_lock);
1522 bdev = inode->i_bdev;
1523 @@ -776,7 +783,7 @@ static struct block_device *bd_acquire(s
1525 spin_unlock(&bdev_lock);
1527 - bdev = bdget(inode->i_rdev);
1528 + bdev = bdget(mdev);
1530 spin_lock(&bdev_lock);
1531 if (!inode->i_bdev) {
1532 diff -NurpP --minimal linux-4.9.76/fs/btrfs/ctree.h linux-4.9.76-vs2.3.9.5/fs/btrfs/ctree.h
1533 --- linux-4.9.76/fs/btrfs/ctree.h 2018-01-13 21:28:56.000000000 +0000
1534 +++ linux-4.9.76-vs2.3.9.5/fs/btrfs/ctree.h 2018-01-10 02:50:49.000000000 +0000
1535 @@ -1321,6 +1321,8 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(c
1536 #define BTRFS_DEFAULT_COMMIT_INTERVAL (30)
1537 #define BTRFS_DEFAULT_MAX_INLINE (2048)
1539 +#define BTRFS_MOUNT_TAGGED (1 << 24)
1541 #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
1542 #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
1543 #define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt)
1544 @@ -1668,6 +1670,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1545 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1546 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1547 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1548 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1549 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1550 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1551 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1552 @@ -1715,6 +1718,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1554 BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1556 +#define BTRFS_INODE_IXUNLINK (1 << 24)
1557 +#define BTRFS_INODE_BARRIER (1 << 25)
1558 +#define BTRFS_INODE_COW (1 << 26)
1561 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1563 @@ -3197,6 +3204,7 @@ int btrfs_ioctl_get_supported_features(v
1564 void btrfs_update_iflags(struct inode *inode);
1565 void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1566 int btrfs_is_empty_uuid(u8 *uuid);
1567 +int btrfs_sync_flags(struct inode *inode, int, int);
1568 int btrfs_defrag_file(struct inode *inode, struct file *file,
1569 struct btrfs_ioctl_defrag_range_args *range,
1570 u64 newer_than, unsigned long max_pages);
1571 diff -NurpP --minimal linux-4.9.76/fs/btrfs/disk-io.c linux-4.9.76-vs2.3.9.5/fs/btrfs/disk-io.c
1572 --- linux-4.9.76/fs/btrfs/disk-io.c 2018-01-13 21:28:56.000000000 +0000
1573 +++ linux-4.9.76-vs2.3.9.5/fs/btrfs/disk-io.c 2018-01-13 05:55:56.000000000 +0000
1574 @@ -2850,6 +2850,9 @@ int open_ctree(struct super_block *sb,
1578 + if (btrfs_test_opt(fs_info, TAGGED))
1579 + sb->s_flags |= MS_TAGGED;
1581 features = btrfs_super_incompat_flags(disk_super) &
1582 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1584 diff -NurpP --minimal linux-4.9.76/fs/btrfs/inode.c linux-4.9.76-vs2.3.9.5/fs/btrfs/inode.c
1585 --- linux-4.9.76/fs/btrfs/inode.c 2018-01-13 21:28:56.000000000 +0000
1586 +++ linux-4.9.76-vs2.3.9.5/fs/btrfs/inode.c 2018-01-13 01:41:05.000000000 +0000
1588 #include <linux/blkdev.h>
1589 #include <linux/posix_acl_xattr.h>
1590 #include <linux/uio.h>
1591 +#include <linux/vs_tag.h>
1593 #include "disk-io.h"
1594 #include "transaction.h"
1595 @@ -3662,6 +3663,9 @@ static int btrfs_read_locked_inode(struc
1603 bool filled = false;
1604 int first_xattr_slot;
1605 @@ -3694,8 +3698,14 @@ static int btrfs_read_locked_inode(struc
1606 struct btrfs_inode_item);
1607 inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1608 set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1609 - i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1610 - i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1612 + kuid = make_kuid(&init_user_ns, btrfs_inode_uid(leaf, inode_item));
1613 + kgid = make_kgid(&init_user_ns, btrfs_inode_gid(leaf, inode_item));
1614 + ktag = make_ktag(&init_user_ns, btrfs_inode_tag(leaf, inode_item));
1616 + inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
1617 + inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
1618 + inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
1619 btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1621 inode->i_atime.tv_sec = btrfs_timespec_sec(leaf, &inode_item->atime);
1622 @@ -3850,11 +3860,18 @@ static void fill_inode_item(struct btrfs
1623 struct inode *inode)
1625 struct btrfs_map_token token;
1626 + uid_t uid = from_kuid(&init_user_ns,
1627 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
1628 + gid_t gid = from_kgid(&init_user_ns,
1629 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
1631 btrfs_init_map_token(&token);
1633 - btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1634 - btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1635 + btrfs_set_token_inode_uid(leaf, item, uid, &token);
1636 + btrfs_set_token_inode_gid(leaf, item, gid, &token);
1637 +#ifdef CONFIG_TAGGING_INTERN
1638 + btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1640 btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1642 btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1643 @@ -10613,6 +10630,7 @@ static const struct inode_operations btr
1644 .mknod = btrfs_mknod,
1645 .listxattr = btrfs_listxattr,
1646 .permission = btrfs_permission,
1647 + .sync_flags = btrfs_sync_flags,
1648 .get_acl = btrfs_get_acl,
1649 .set_acl = btrfs_set_acl,
1650 .update_time = btrfs_update_time,
1651 @@ -10621,6 +10639,7 @@ static const struct inode_operations btr
1652 static const struct inode_operations btrfs_dir_ro_inode_operations = {
1653 .lookup = btrfs_lookup,
1654 .permission = btrfs_permission,
1655 + .sync_flags = btrfs_sync_flags,
1656 .update_time = btrfs_update_time,
1659 @@ -10686,6 +10705,7 @@ static const struct inode_operations btr
1660 .listxattr = btrfs_listxattr,
1661 .permission = btrfs_permission,
1662 .fiemap = btrfs_fiemap,
1663 + .sync_flags = btrfs_sync_flags,
1664 .get_acl = btrfs_get_acl,
1665 .set_acl = btrfs_set_acl,
1666 .update_time = btrfs_update_time,
1667 diff -NurpP --minimal linux-4.9.76/fs/btrfs/ioctl.c linux-4.9.76-vs2.3.9.5/fs/btrfs/ioctl.c
1668 --- linux-4.9.76/fs/btrfs/ioctl.c 2018-01-13 21:28:56.000000000 +0000
1669 +++ linux-4.9.76-vs2.3.9.5/fs/btrfs/ioctl.c 2018-01-10 02:50:49.000000000 +0000
1670 @@ -110,10 +110,13 @@ static unsigned int btrfs_flags_to_ioctl
1672 unsigned int iflags = 0;
1674 - if (flags & BTRFS_INODE_SYNC)
1675 - iflags |= FS_SYNC_FL;
1676 if (flags & BTRFS_INODE_IMMUTABLE)
1677 iflags |= FS_IMMUTABLE_FL;
1678 + if (flags & BTRFS_INODE_IXUNLINK)
1679 + iflags |= FS_IXUNLINK_FL;
1681 + if (flags & BTRFS_INODE_SYNC)
1682 + iflags |= FS_SYNC_FL;
1683 if (flags & BTRFS_INODE_APPEND)
1684 iflags |= FS_APPEND_FL;
1685 if (flags & BTRFS_INODE_NODUMP)
1686 @@ -130,34 +133,84 @@ static unsigned int btrfs_flags_to_ioctl
1687 else if (flags & BTRFS_INODE_COMPRESS)
1688 iflags |= FS_COMPR_FL;
1690 + if (flags & BTRFS_INODE_BARRIER)
1691 + iflags |= FS_BARRIER_FL;
1692 + if (flags & BTRFS_INODE_COW)
1693 + iflags |= FS_COW_FL;
1698 - * Update inode->i_flags based on the btrfs internal flags.
1699 + * Update inode->i_(v)flags based on the btrfs internal flags.
1701 void btrfs_update_iflags(struct inode *inode)
1703 struct btrfs_inode *ip = BTRFS_I(inode);
1704 unsigned int new_fl = 0;
1706 - if (ip->flags & BTRFS_INODE_SYNC)
1708 if (ip->flags & BTRFS_INODE_IMMUTABLE)
1709 new_fl |= S_IMMUTABLE;
1710 + if (ip->flags & BTRFS_INODE_IXUNLINK)
1711 + new_fl |= S_IXUNLINK;
1713 + if (ip->flags & BTRFS_INODE_SYNC)
1715 if (ip->flags & BTRFS_INODE_APPEND)
1717 if (ip->flags & BTRFS_INODE_NOATIME)
1718 new_fl |= S_NOATIME;
1719 if (ip->flags & BTRFS_INODE_DIRSYNC)
1720 new_fl |= S_DIRSYNC;
1722 set_mask_bits(&inode->i_flags,
1723 - S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | S_DIRSYNC,
1724 + S_SYNC | S_APPEND | S_IMMUTABLE | S_IXUNLINK | S_NOATIME | S_DIRSYNC,
1728 + if (ip->flags & BTRFS_INODE_BARRIER)
1729 + new_fl |= V_BARRIER;
1730 + if (ip->flags & BTRFS_INODE_COW)
1733 + set_mask_bits(&inode->i_vflags,
1734 + V_BARRIER | V_COW, new_fl);
1738 + * Update btrfs internal flags from inode->i_(v)flags.
1740 +void btrfs_update_flags(struct inode *inode)
1742 + struct btrfs_inode *ip = BTRFS_I(inode);
1744 + unsigned int flags = inode->i_flags;
1745 + unsigned int vflags = inode->i_vflags;
1747 + ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1748 + BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1749 + BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1750 + BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1752 + if (flags & S_IMMUTABLE)
1753 + ip->flags |= BTRFS_INODE_IMMUTABLE;
1754 + if (flags & S_IXUNLINK)
1755 + ip->flags |= BTRFS_INODE_IXUNLINK;
1757 + if (flags & S_SYNC)
1758 + ip->flags |= BTRFS_INODE_SYNC;
1759 + if (flags & S_APPEND)
1760 + ip->flags |= BTRFS_INODE_APPEND;
1761 + if (flags & S_NOATIME)
1762 + ip->flags |= BTRFS_INODE_NOATIME;
1763 + if (flags & S_DIRSYNC)
1764 + ip->flags |= BTRFS_INODE_DIRSYNC;
1766 + if (vflags & V_BARRIER)
1767 + ip->flags |= BTRFS_INODE_BARRIER;
1768 + if (vflags & V_COW)
1769 + ip->flags |= BTRFS_INODE_COW;
1773 * Inherit flags from the parent inode.
1775 * Currently only the compression flags and the cow flags are inherited.
1776 @@ -170,6 +223,7 @@ void btrfs_inherit_iflags(struct inode *
1779 flags = BTRFS_I(dir)->flags;
1780 + flags &= ~BTRFS_INODE_BARRIER;
1782 if (flags & BTRFS_INODE_NOCOMPRESS) {
1783 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1784 @@ -188,6 +242,30 @@ void btrfs_inherit_iflags(struct inode *
1785 btrfs_update_iflags(inode);
1788 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1790 + struct btrfs_inode *ip = BTRFS_I(inode);
1791 + struct btrfs_root *root = ip->root;
1792 + struct btrfs_trans_handle *trans;
1795 + trans = btrfs_join_transaction(root);
1798 + inode->i_flags = flags;
1799 + inode->i_vflags = vflags;
1800 + btrfs_update_flags(inode);
1802 + ret = btrfs_update_inode(trans, root, inode);
1805 + btrfs_update_iflags(inode);
1806 + inode->i_ctime = CURRENT_TIME;
1807 + btrfs_end_transaction(trans, root);
1812 static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1814 struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1815 @@ -250,21 +328,27 @@ static int btrfs_ioctl_setflags(struct f
1817 flags = btrfs_mask_flags(inode->i_mode, flags);
1818 oldflags = btrfs_flags_to_ioctl(ip->flags);
1819 - if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1820 + if ((flags ^ oldflags) & (FS_APPEND_FL |
1821 + FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1822 if (!capable(CAP_LINUX_IMMUTABLE)) {
1828 - if (flags & FS_SYNC_FL)
1829 - ip->flags |= BTRFS_INODE_SYNC;
1831 - ip->flags &= ~BTRFS_INODE_SYNC;
1832 if (flags & FS_IMMUTABLE_FL)
1833 ip->flags |= BTRFS_INODE_IMMUTABLE;
1835 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1836 + if (flags & FS_IXUNLINK_FL)
1837 + ip->flags |= BTRFS_INODE_IXUNLINK;
1839 + ip->flags &= ~BTRFS_INODE_IXUNLINK;
1841 + if (flags & FS_SYNC_FL)
1842 + ip->flags |= BTRFS_INODE_SYNC;
1844 + ip->flags &= ~BTRFS_INODE_SYNC;
1845 if (flags & FS_APPEND_FL)
1846 ip->flags |= BTRFS_INODE_APPEND;
1848 diff -NurpP --minimal linux-4.9.76/fs/btrfs/super.c linux-4.9.76-vs2.3.9.5/fs/btrfs/super.c
1849 --- linux-4.9.76/fs/btrfs/super.c 2018-01-13 21:28:56.000000000 +0000
1850 +++ linux-4.9.76-vs2.3.9.5/fs/btrfs/super.c 2018-01-13 05:51:52.000000000 +0000
1851 @@ -327,7 +327,7 @@ enum {
1852 #ifdef CONFIG_BTRFS_DEBUG
1853 Opt_fragment_data, Opt_fragment_metadata, Opt_fragment_all,
1856 + Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1859 static const match_table_t tokens = {
1860 @@ -388,6 +388,9 @@ static const match_table_t tokens = {
1861 {Opt_fragment_metadata, "fragment=metadata"},
1862 {Opt_fragment_all, "fragment=all"},
1865 + {Opt_notag, "notag"},
1866 + {Opt_tagid, "tagid=%u"},
1870 @@ -833,6 +836,22 @@ int btrfs_parse_options(struct btrfs_roo
1871 btrfs_set_opt(info->mount_opt, FRAGMENT_DATA);
1874 +#ifndef CONFIG_TAGGING_NONE
1876 + printk(KERN_INFO "btrfs: use tagging\n");
1877 + btrfs_set_opt(info->mount_opt, TAGGED);
1880 + printk(KERN_INFO "btrfs: disabled tagging\n");
1881 + btrfs_clear_opt(info->mount_opt, TAGGED);
1884 +#ifdef CONFIG_PROPAGATE
1887 + btrfs_set_opt(info->mount_opt, TAGGED);
1891 btrfs_info(root->fs_info,
1892 "unrecognized mount option '%s'", p);
1893 @@ -1754,6 +1773,12 @@ static int btrfs_remount(struct super_bl
1894 btrfs_resize_thread_pool(fs_info,
1895 fs_info->thread_pool_size, old_thread_pool_size);
1897 + if (btrfs_test_opt(fs_info, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1898 + printk("btrfs: %s: tagging not permitted on remount.\n",
1903 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1906 diff -NurpP --minimal linux-4.9.76/fs/char_dev.c linux-4.9.76-vs2.3.9.5/fs/char_dev.c
1907 --- linux-4.9.76/fs/char_dev.c 2016-12-11 19:17:54.000000000 +0000
1908 +++ linux-4.9.76-vs2.3.9.5/fs/char_dev.c 2018-01-10 02:50:49.000000000 +0000
1910 #include <linux/mutex.h>
1911 #include <linux/backing-dev.h>
1912 #include <linux/tty.h>
1913 +#include <linux/vs_context.h>
1914 +#include <linux/vs_device.h>
1916 #include "internal.h"
1918 @@ -354,14 +356,21 @@ static int chrdev_open(struct inode *ino
1920 struct cdev *new = NULL;
1924 + if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1926 + inode->i_mdev = mdev;
1928 spin_lock(&cdev_lock);
1931 struct kobject *kobj;
1934 spin_unlock(&cdev_lock);
1935 - kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1937 + kobj = kobj_lookup(cdev_map, mdev, &idx);
1940 new = container_of(kobj, struct cdev, kobj);
1941 diff -NurpP --minimal linux-4.9.76/fs/dcache.c linux-4.9.76-vs2.3.9.5/fs/dcache.c
1942 --- linux-4.9.76/fs/dcache.c 2018-01-13 21:28:56.000000000 +0000
1943 +++ linux-4.9.76-vs2.3.9.5/fs/dcache.c 2018-01-10 02:50:49.000000000 +0000
1945 #include <linux/ratelimit.h>
1946 #include <linux/list_lru.h>
1947 #include <linux/kasan.h>
1948 +#include <linux/vs_limit.h>
1950 #include "internal.h"
1952 @@ -680,6 +681,7 @@ static inline bool fast_dput(struct dent
1953 spin_lock(&dentry->d_lock);
1954 if (dentry->d_lockref.count > 1) {
1955 dentry->d_lockref.count--;
1956 + vx_dentry_dec(dentry);
1957 spin_unlock(&dentry->d_lock);
1960 @@ -811,6 +813,7 @@ repeat:
1961 dentry_lru_add(dentry);
1963 dentry->d_lockref.count--;
1964 + vx_dentry_dec(dentry);
1965 spin_unlock(&dentry->d_lock);
1968 @@ -828,6 +831,7 @@ EXPORT_SYMBOL(dput);
1969 static inline void __dget_dlock(struct dentry *dentry)
1971 dentry->d_lockref.count++;
1972 + vx_dentry_inc(dentry);
1975 static inline void __dget(struct dentry *dentry)
1976 @@ -840,6 +844,8 @@ struct dentry *dget_parent(struct dentry
1980 + vx_dentry_dec(dentry);
1983 * Do optimistic parent lookup without any
1985 @@ -870,6 +876,7 @@ repeat:
1987 BUG_ON(!ret->d_lockref.count);
1988 ret->d_lockref.count++;
1989 + vx_dentry_inc(ret);
1990 spin_unlock(&ret->d_lock);
1993 @@ -1024,6 +1031,7 @@ static void shrink_dentry_list(struct li
1994 parent = lock_parent(dentry);
1995 if (dentry->d_lockref.count != 1) {
1996 dentry->d_lockref.count--;
1997 + vx_dentry_dec(dentry);
1998 spin_unlock(&dentry->d_lock);
2000 spin_unlock(&parent->d_lock);
2001 @@ -1590,6 +1598,9 @@ struct dentry *__d_alloc(struct super_bl
2005 + if (!vx_dentry_avail(1))
2008 dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2011 @@ -1633,6 +1644,7 @@ struct dentry *__d_alloc(struct super_bl
2013 dentry->d_lockref.count = 1;
2014 dentry->d_flags = 0;
2015 + vx_dentry_inc(dentry);
2016 spin_lock_init(&dentry->d_lock);
2017 seqcount_init(&dentry->d_seq);
2018 dentry->d_inode = NULL;
2019 @@ -2282,6 +2294,7 @@ struct dentry *__d_lookup(const struct d
2022 dentry->d_lockref.count++;
2023 + vx_dentry_inc(dentry);
2025 spin_unlock(&dentry->d_lock);
2027 @@ -3532,6 +3545,7 @@ static enum d_walk_ret d_genocide_kill(v
2028 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
2029 dentry->d_flags |= DCACHE_GENOCIDE;
2030 dentry->d_lockref.count--;
2031 + vx_dentry_dec(dentry);
2034 return D_WALK_CONTINUE;
2035 diff -NurpP --minimal linux-4.9.76/fs/devpts/inode.c linux-4.9.76-vs2.3.9.5/fs/devpts/inode.c
2036 --- linux-4.9.76/fs/devpts/inode.c 2016-12-11 19:17:54.000000000 +0000
2037 +++ linux-4.9.76-vs2.3.9.5/fs/devpts/inode.c 2018-01-13 01:06:29.000000000 +0000
2039 #include <linux/parser.h>
2040 #include <linux/fsnotify.h>
2041 #include <linux/seq_file.h>
2042 +#include <linux/vs_base.h>
2044 #define DEVPTS_DEFAULT_MODE 0600
2047 #define DEVPTS_DEFAULT_PTMX_MODE 0000
2048 #define PTMX_MINOR 2
2050 +static int devpts_permission(struct inode *inode, int mask)
2052 + int ret = -EACCES;
2054 + /* devpts is xid tagged */
2055 + if (vx_check((vxid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2056 + ret = generic_permission(inode, mask);
2060 +static struct inode_operations devpts_file_inode_operations = {
2061 + .permission = devpts_permission,
2066 * sysctl support for setting limits on the number of Unix98 ptys allocated.
2067 * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2068 @@ -363,6 +379,34 @@ static int devpts_show_options(struct se
2072 +static int devpts_filter(struct dentry *de)
2076 + /* devpts is xid tagged */
2077 + if (de && de->d_inode)
2078 + xid = (vxid_t)i_tag_read(de->d_inode);
2079 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2081 + vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2082 + de->d_name.len, de->d_name.name);
2084 + return vx_check(xid, VS_WATCH_P | VS_IDENT);
2087 +static int devpts_readdir(struct file * filp, struct dir_context *ctx)
2089 + return dcache_readdir_filter(filp, ctx, devpts_filter);
2092 +static struct file_operations devpts_dir_operations = {
2093 + .open = dcache_dir_open,
2094 + .release = dcache_dir_close,
2095 + .llseek = dcache_dir_lseek,
2096 + .read = generic_read_dir,
2097 + .iterate = devpts_readdir,
2100 static const struct super_operations devpts_sops = {
2101 .statfs = simple_statfs,
2102 .remount_fs = devpts_remount,
2103 @@ -415,8 +459,10 @@ devpts_fill_super(struct super_block *s,
2104 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
2105 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2106 inode->i_op = &simple_dir_inode_operations;
2107 - inode->i_fop = &simple_dir_operations;
2108 + inode->i_fop = &devpts_dir_operations;
2109 set_nlink(inode, 2);
2110 + /* devpts is xid tagged */
2111 + i_tag_write(inode, (vtag_t)vx_current_xid());
2113 s->s_root = d_make_root(inode);
2115 @@ -542,6 +588,9 @@ struct dentry *devpts_pty_new(struct pts
2116 inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2117 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
2118 init_special_inode(inode, S_IFCHR|opts->mode, MKDEV(UNIX98_PTY_SLAVE_MAJOR, index));
2119 + /* devpts is xid tagged */
2120 + i_tag_write(inode, (vtag_t)vx_current_xid());
2121 + inode->i_op = &devpts_file_inode_operations;
2123 sprintf(s, "%d", index);
2125 diff -NurpP --minimal linux-4.9.76/fs/ext2/balloc.c linux-4.9.76-vs2.3.9.5/fs/ext2/balloc.c
2126 --- linux-4.9.76/fs/ext2/balloc.c 2016-12-11 19:17:54.000000000 +0000
2127 +++ linux-4.9.76-vs2.3.9.5/fs/ext2/balloc.c 2018-01-10 02:50:49.000000000 +0000
2128 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2130 end = EXT2_BLOCKS_PER_GROUP(sb);
2133 BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2136 diff -NurpP --minimal linux-4.9.76/fs/ext2/ext2.h linux-4.9.76-vs2.3.9.5/fs/ext2/ext2.h
2137 --- linux-4.9.76/fs/ext2/ext2.h 2016-12-11 19:17:54.000000000 +0000
2138 +++ linux-4.9.76-vs2.3.9.5/fs/ext2/ext2.h 2018-01-10 02:50:49.000000000 +0000
2139 @@ -247,8 +247,12 @@ struct ext2_group_desc
2140 #define EXT2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
2141 #define EXT2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
2142 #define EXT2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
2143 +#define EXT2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
2144 #define EXT2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
2146 +#define EXT2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
2147 +#define EXT2_COW_FL FS_COW_FL /* Copy on Write marker */
2149 #define EXT2_FL_USER_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
2150 #define EXT2_FL_USER_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
2152 @@ -332,7 +336,8 @@ struct ext2_inode {
2154 __le16 l_i_uid_high; /* these 2 fields */
2155 __le16 l_i_gid_high; /* were reserved2[0] */
2156 - __u32 l_i_reserved2;
2157 + __le16 l_i_tag; /* Context Tag */
2158 + __u16 l_i_reserved2;
2161 __u8 h_i_frag; /* Fragment number */
2162 @@ -360,6 +365,7 @@ struct ext2_inode {
2163 #define i_gid_low i_gid
2164 #define i_uid_high osd2.linux2.l_i_uid_high
2165 #define i_gid_high osd2.linux2.l_i_gid_high
2166 +#define i_raw_tag osd2.linux2.l_i_tag
2167 #define i_reserved2 osd2.linux2.l_i_reserved2
2170 @@ -393,6 +399,7 @@ struct ext2_inode {
2172 #define EXT2_MOUNT_DAX 0
2174 +#define EXT2_MOUNT_TAGGED 0x200000 /* Enable Context Tags */
2177 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
2178 @@ -782,6 +789,7 @@ extern void ext2_set_inode_flags(struct
2179 extern void ext2_get_inode_flags(struct ext2_inode_info *);
2180 extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2181 u64 start, u64 len);
2182 +extern int ext2_sync_flags(struct inode *, int, int);
2185 extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2186 diff -NurpP --minimal linux-4.9.76/fs/ext2/file.c linux-4.9.76-vs2.3.9.5/fs/ext2/file.c
2187 --- linux-4.9.76/fs/ext2/file.c 2016-12-11 19:17:54.000000000 +0000
2188 +++ linux-4.9.76-vs2.3.9.5/fs/ext2/file.c 2018-01-10 02:50:49.000000000 +0000
2189 @@ -247,4 +247,5 @@ const struct inode_operations ext2_file_
2190 .get_acl = ext2_get_acl,
2191 .set_acl = ext2_set_acl,
2192 .fiemap = ext2_fiemap,
2193 + .sync_flags = ext2_sync_flags,
2195 diff -NurpP --minimal linux-4.9.76/fs/ext2/ialloc.c linux-4.9.76-vs2.3.9.5/fs/ext2/ialloc.c
2196 --- linux-4.9.76/fs/ext2/ialloc.c 2016-12-11 19:17:54.000000000 +0000
2197 +++ linux-4.9.76-vs2.3.9.5/fs/ext2/ialloc.c 2018-01-10 02:50:49.000000000 +0000
2199 #include <linux/backing-dev.h>
2200 #include <linux/buffer_head.h>
2201 #include <linux/random.h>
2202 +#include <linux/vs_tag.h>
2206 @@ -551,6 +552,7 @@ got:
2207 inode->i_mode = mode;
2208 inode->i_uid = current_fsuid();
2209 inode->i_gid = dir->i_gid;
2210 + i_tag_write(inode, dx_current_fstag(sb));
2212 inode_init_owner(inode, dir, mode);
2214 diff -NurpP --minimal linux-4.9.76/fs/ext2/inode.c linux-4.9.76-vs2.3.9.5/fs/ext2/inode.c
2215 --- linux-4.9.76/fs/ext2/inode.c 2016-12-11 19:17:54.000000000 +0000
2216 +++ linux-4.9.76-vs2.3.9.5/fs/ext2/inode.c 2018-01-13 01:19:54.000000000 +0000
2218 #include <linux/iomap.h>
2219 #include <linux/namei.h>
2220 #include <linux/uio.h>
2221 +#include <linux/vs_tag.h>
2225 @@ -1271,7 +1272,7 @@ static void ext2_truncate_blocks(struct
2227 if (ext2_inode_is_fast_symlink(inode))
2229 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2230 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2233 dax_sem_down_write(EXT2_I(inode));
2234 @@ -1367,39 +1368,61 @@ void ext2_set_inode_flags(struct inode *
2236 unsigned int flags = EXT2_I(inode)->i_flags;
2238 - inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME |
2239 - S_DIRSYNC | S_DAX);
2240 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK | S_DAX |
2241 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2243 + if (flags & EXT2_IMMUTABLE_FL)
2244 + inode->i_flags |= S_IMMUTABLE;
2245 + if (flags & EXT2_IXUNLINK_FL)
2246 + inode->i_flags |= S_IXUNLINK;
2247 if (flags & EXT2_SYNC_FL)
2248 inode->i_flags |= S_SYNC;
2249 if (flags & EXT2_APPEND_FL)
2250 inode->i_flags |= S_APPEND;
2251 - if (flags & EXT2_IMMUTABLE_FL)
2252 - inode->i_flags |= S_IMMUTABLE;
2253 if (flags & EXT2_NOATIME_FL)
2254 inode->i_flags |= S_NOATIME;
2255 if (flags & EXT2_DIRSYNC_FL)
2256 inode->i_flags |= S_DIRSYNC;
2257 if (test_opt(inode->i_sb, DAX) && S_ISREG(inode->i_mode))
2258 inode->i_flags |= S_DAX;
2260 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2262 + if (flags & EXT2_BARRIER_FL)
2263 + inode->i_vflags |= V_BARRIER;
2264 + if (flags & EXT2_COW_FL)
2265 + inode->i_vflags |= V_COW;
2268 /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2269 void ext2_get_inode_flags(struct ext2_inode_info *ei)
2271 unsigned int flags = ei->vfs_inode.i_flags;
2272 + unsigned int vflags = ei->vfs_inode.i_vflags;
2274 + ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2275 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2276 + EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2277 + EXT2_BARRIER_FL | EXT2_COW_FL);
2279 + if (flags & S_IMMUTABLE)
2280 + ei->i_flags |= EXT2_IMMUTABLE_FL;
2281 + if (flags & S_IXUNLINK)
2282 + ei->i_flags |= EXT2_IXUNLINK_FL;
2284 - ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2285 - EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2287 ei->i_flags |= EXT2_SYNC_FL;
2288 if (flags & S_APPEND)
2289 ei->i_flags |= EXT2_APPEND_FL;
2290 - if (flags & S_IMMUTABLE)
2291 - ei->i_flags |= EXT2_IMMUTABLE_FL;
2292 if (flags & S_NOATIME)
2293 ei->i_flags |= EXT2_NOATIME_FL;
2294 if (flags & S_DIRSYNC)
2295 ei->i_flags |= EXT2_DIRSYNC_FL;
2297 + if (vflags & V_BARRIER)
2298 + ei->i_flags |= EXT2_BARRIER_FL;
2299 + if (vflags & V_COW)
2300 + ei->i_flags |= EXT2_COW_FL;
2303 struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2304 @@ -1435,8 +1458,10 @@ struct inode *ext2_iget (struct super_bl
2305 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2306 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2308 - i_uid_write(inode, i_uid);
2309 - i_gid_write(inode, i_gid);
2310 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2311 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2312 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2313 + le16_to_cpu(raw_inode->i_raw_tag)));
2314 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2315 inode->i_size = le32_to_cpu(raw_inode->i_size);
2316 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2317 @@ -1543,8 +1568,10 @@ static int __ext2_write_inode(struct ino
2318 struct ext2_inode_info *ei = EXT2_I(inode);
2319 struct super_block *sb = inode->i_sb;
2320 ino_t ino = inode->i_ino;
2321 - uid_t uid = i_uid_read(inode);
2322 - gid_t gid = i_gid_read(inode);
2323 + uid_t uid = from_kuid(&init_user_ns,
2324 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2325 + gid_t gid = from_kgid(&init_user_ns,
2326 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2327 struct buffer_head * bh;
2328 struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2330 @@ -1580,6 +1607,9 @@ static int __ext2_write_inode(struct ino
2331 raw_inode->i_uid_high = 0;
2332 raw_inode->i_gid_high = 0;
2334 +#ifdef CONFIG_TAGGING_INTERN
2335 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2337 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2338 raw_inode->i_size = cpu_to_le32(inode->i_size);
2339 raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2340 @@ -1663,7 +1693,8 @@ int ext2_setattr(struct dentry *dentry,
2343 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2344 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2345 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2346 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2347 error = dquot_transfer(inode, iattr);
2350 diff -NurpP --minimal linux-4.9.76/fs/ext2/ioctl.c linux-4.9.76-vs2.3.9.5/fs/ext2/ioctl.c
2351 --- linux-4.9.76/fs/ext2/ioctl.c 2016-12-11 19:17:54.000000000 +0000
2352 +++ linux-4.9.76-vs2.3.9.5/fs/ext2/ioctl.c 2018-01-13 01:20:40.000000000 +0000
2354 #include <asm/uaccess.h>
2357 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2359 + inode->i_flags = flags;
2360 + inode->i_vflags = vflags;
2361 + ext2_get_inode_flags(EXT2_I(inode));
2362 + inode->i_ctime = CURRENT_TIME_SEC;
2363 + mark_inode_dirty(inode);
2367 long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2369 struct inode *inode = file_inode(filp);
2370 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2372 flags = ext2_mask_flags(inode->i_mode, flags);
2374 + if (IS_BARRIER(inode)) {
2375 + vxwprintk_task(1, "messing with the barrier.");
2380 /* Is it quota file? Do not allow user to mess with it */
2381 if (IS_NOQUOTA(inode)) {
2382 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2384 * This test looks nicer. Thanks to Pauline Middelink
2386 - if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2387 + if ((oldflags & EXT2_IMMUTABLE_FL) ||
2388 + ((flags ^ oldflags) & (EXT2_APPEND_FL |
2389 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2390 if (!capable(CAP_LINUX_IMMUTABLE)) {
2391 inode_unlock(inode);
2393 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2397 - flags = flags & EXT2_FL_USER_MODIFIABLE;
2398 + flags &= EXT2_FL_USER_MODIFIABLE;
2399 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2400 ei->i_flags = flags;
2402 diff -NurpP --minimal linux-4.9.76/fs/ext2/namei.c linux-4.9.76-vs2.3.9.5/fs/ext2/namei.c
2403 --- linux-4.9.76/fs/ext2/namei.c 2016-12-11 19:17:54.000000000 +0000
2404 +++ linux-4.9.76-vs2.3.9.5/fs/ext2/namei.c 2018-01-10 02:50:49.000000000 +0000
2407 #include <linux/pagemap.h>
2408 #include <linux/quotaops.h>
2409 +#include <linux/vs_tag.h>
2413 @@ -72,6 +73,7 @@ static struct dentry *ext2_lookup(struct
2414 (unsigned long) ino);
2415 return ERR_PTR(-EIO);
2417 + dx_propagate_tag(nd, inode);
2419 return d_splice_alias(inode, dentry);
2421 @@ -445,6 +447,7 @@ const struct inode_operations ext2_speci
2422 .listxattr = ext2_listxattr,
2424 .setattr = ext2_setattr,
2425 + .sync_flags = ext2_sync_flags,
2426 .get_acl = ext2_get_acl,
2427 .set_acl = ext2_set_acl,
2429 diff -NurpP --minimal linux-4.9.76/fs/ext2/super.c linux-4.9.76-vs2.3.9.5/fs/ext2/super.c
2430 --- linux-4.9.76/fs/ext2/super.c 2016-12-11 19:17:54.000000000 +0000
2431 +++ linux-4.9.76-vs2.3.9.5/fs/ext2/super.c 2018-01-10 02:50:49.000000000 +0000
2432 @@ -411,7 +411,8 @@ enum {
2433 Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2434 Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2435 Opt_acl, Opt_noacl, Opt_xip, Opt_dax, Opt_ignore, Opt_err, Opt_quota,
2436 - Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2437 + Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2438 + Opt_tag, Opt_notag, Opt_tagid
2441 static const match_table_t tokens = {
2442 @@ -439,6 +440,9 @@ static const match_table_t tokens = {
2444 {Opt_noacl, "noacl"},
2447 + {Opt_notag, "notag"},
2448 + {Opt_tagid, "tagid=%u"},
2450 {Opt_grpquota, "grpquota"},
2451 {Opt_ignore, "noquota"},
2452 @@ -523,6 +527,20 @@ static int parse_options(char *options,
2454 set_opt (sbi->s_mount_opt, NO_UID32);
2456 +#ifndef CONFIG_TAGGING_NONE
2458 + set_opt (sbi->s_mount_opt, TAGGED);
2461 + clear_opt (sbi->s_mount_opt, TAGGED);
2464 +#ifdef CONFIG_PROPAGATE
2467 + set_opt (sbi->s_mount_opt, TAGGED);
2471 clear_opt (sbi->s_mount_opt, CHECK);
2473 @@ -887,6 +905,8 @@ static int ext2_fill_super(struct super_
2474 if (!parse_options((char *) data, sb))
2477 + if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2478 + sb->s_flags |= MS_TAGGED;
2479 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2480 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2482 @@ -1300,6 +1320,14 @@ static int ext2_remount (struct super_bl
2487 + if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2488 + !(sb->s_flags & MS_TAGGED)) {
2489 + printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2492 + goto restore_opts;
2495 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2496 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2497 diff -NurpP --minimal linux-4.9.76/fs/ext4/ext4.h linux-4.9.76-vs2.3.9.5/fs/ext4/ext4.h
2498 --- linux-4.9.76/fs/ext4/ext4.h 2016-12-11 19:17:54.000000000 +0000
2499 +++ linux-4.9.76-vs2.3.9.5/fs/ext4/ext4.h 2018-01-13 02:00:49.000000000 +0000
2500 @@ -392,8 +392,11 @@ struct flex_groups {
2501 #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
2502 #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
2503 #define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
2504 +#define EXT4_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2505 +#define EXT4_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2506 #define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */
2507 #define EXT4_PROJINHERIT_FL 0x20000000 /* Create with parents projid */
2508 +#define EXT4_COW_FL 0x40000000 /* Copy on Write marker */
2509 #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
2511 #define EXT4_FL_USER_VISIBLE 0x304BDFFF /* User visible flags */
2512 @@ -735,7 +738,7 @@ struct ext4_inode {
2513 __le16 l_i_uid_high; /* these 2 fields */
2514 __le16 l_i_gid_high; /* were reserved2[0] */
2515 __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2516 - __le16 l_i_reserved;
2517 + __le16 l_i_tag; /* Context Tag */
2520 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
2521 @@ -892,6 +895,7 @@ do { \
2522 #define i_gid_low i_gid
2523 #define i_uid_high osd2.linux2.l_i_uid_high
2524 #define i_gid_high osd2.linux2.l_i_gid_high
2525 +#define i_raw_tag osd2.linux2.l_i_tag
2526 #define i_checksum_lo osd2.linux2.l_i_checksum_lo
2528 #elif defined(__GNU__)
2529 @@ -1133,6 +1137,7 @@ struct ext4_inode_info {
2530 #define EXT4_MOUNT_DIOREAD_NOLOCK 0x400000 /* Enable support for dio read nolocking */
2531 #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */
2532 #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */
2533 +#define EXT4_MOUNT_TAGGED 0x2000000 /* Enable Context Tags */
2534 #define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */
2535 #define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */
2536 #define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000 /* Block validity checking */
2537 @@ -2497,6 +2502,7 @@ extern int ext4_punch_hole(struct inode
2538 extern int ext4_truncate_restart_trans(handle_t *, struct inode *, int nblocks);
2539 extern void ext4_set_inode_flags(struct inode *);
2540 extern void ext4_get_inode_flags(struct ext4_inode_info *);
2541 +extern int ext4_sync_flags(struct inode *, int, int);
2542 extern int ext4_alloc_da_blocks(struct inode *inode);
2543 extern void ext4_set_aops(struct inode *inode);
2544 extern int ext4_writepage_trans_blocks(struct inode *);
2545 diff -NurpP --minimal linux-4.9.76/fs/ext4/file.c linux-4.9.76-vs2.3.9.5/fs/ext4/file.c
2546 --- linux-4.9.76/fs/ext4/file.c 2018-01-13 21:28:56.000000000 +0000
2547 +++ linux-4.9.76-vs2.3.9.5/fs/ext4/file.c 2018-01-10 02:50:49.000000000 +0000
2548 @@ -691,5 +691,6 @@ const struct inode_operations ext4_file_
2549 .get_acl = ext4_get_acl,
2550 .set_acl = ext4_set_acl,
2551 .fiemap = ext4_fiemap,
2552 + .sync_flags = ext4_sync_flags,
2555 diff -NurpP --minimal linux-4.9.76/fs/ext4/ialloc.c linux-4.9.76-vs2.3.9.5/fs/ext4/ialloc.c
2556 --- linux-4.9.76/fs/ext4/ialloc.c 2018-01-13 21:28:56.000000000 +0000
2557 +++ linux-4.9.76-vs2.3.9.5/fs/ext4/ialloc.c 2018-01-10 02:50:49.000000000 +0000
2559 #include <linux/random.h>
2560 #include <linux/bitops.h>
2561 #include <linux/blkdev.h>
2562 +#include <linux/vs_tag.h>
2563 #include <asm/byteorder.h>
2566 @@ -799,6 +800,7 @@ struct inode *__ext4_new_inode(handle_t
2567 inode->i_mode = mode;
2568 inode->i_uid = current_fsuid();
2569 inode->i_gid = dir->i_gid;
2570 + i_tag_write(inode, dx_current_fstag(sb));
2572 inode_init_owner(inode, dir, mode);
2574 diff -NurpP --minimal linux-4.9.76/fs/ext4/inode.c linux-4.9.76-vs2.3.9.5/fs/ext4/inode.c
2575 --- linux-4.9.76/fs/ext4/inode.c 2018-01-13 21:28:56.000000000 +0000
2576 +++ linux-4.9.76-vs2.3.9.5/fs/ext4/inode.c 2018-01-13 02:02:12.000000000 +0000
2578 #include <linux/printk.h>
2579 #include <linux/slab.h>
2580 #include <linux/bitops.h>
2581 +#include <linux/vs_tag.h>
2583 #include "ext4_jbd2.h"
2585 @@ -4374,12 +4375,15 @@ void ext4_set_inode_flags(struct inode *
2586 unsigned int flags = EXT4_I(inode)->i_flags;
2587 unsigned int new_fl = 0;
2589 + if (flags & EXT4_IMMUTABLE_FL)
2590 + new_fl |= S_IMMUTABLE;
2591 + if (flags & EXT4_IXUNLINK_FL)
2592 + new_fl |= S_IXUNLINK;
2594 if (flags & EXT4_SYNC_FL)
2596 if (flags & EXT4_APPEND_FL)
2598 - if (flags & EXT4_IMMUTABLE_FL)
2599 - new_fl |= S_IMMUTABLE;
2600 if (flags & EXT4_NOATIME_FL)
2601 new_fl |= S_NOATIME;
2602 if (flags & EXT4_DIRSYNC_FL)
2603 @@ -4387,31 +4391,52 @@ void ext4_set_inode_flags(struct inode *
2604 if (test_opt(inode->i_sb, DAX) && S_ISREG(inode->i_mode))
2606 inode_set_flags(inode, new_fl,
2607 - S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_DAX);
2608 + S_IXUNLINK | S_IMMUTABLE | S_DAX |
2609 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2612 + if (flags & EXT4_BARRIER_FL)
2613 + new_fl |= V_BARRIER;
2614 + if (flags & EXT4_COW_FL)
2617 + set_mask_bits(&inode->i_vflags,
2618 + V_BARRIER | V_COW, new_fl);
2621 /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2622 void ext4_get_inode_flags(struct ext4_inode_info *ei)
2624 - unsigned int vfs_fl;
2625 + unsigned int vfs_fl, vfs_vf;
2626 unsigned long old_fl, new_fl;
2629 vfs_fl = ei->vfs_inode.i_flags;
2630 + vfs_vf = ei->vfs_inode.i_vflags;
2631 old_fl = ei->i_flags;
2632 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2633 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2635 + EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2638 + if (vfs_fl & S_IMMUTABLE)
2639 + new_fl |= EXT4_IMMUTABLE_FL;
2640 + if (vfs_fl & S_IXUNLINK)
2641 + new_fl |= EXT4_IXUNLINK_FL;
2643 if (vfs_fl & S_SYNC)
2644 new_fl |= EXT4_SYNC_FL;
2645 if (vfs_fl & S_APPEND)
2646 new_fl |= EXT4_APPEND_FL;
2647 - if (vfs_fl & S_IMMUTABLE)
2648 - new_fl |= EXT4_IMMUTABLE_FL;
2649 if (vfs_fl & S_NOATIME)
2650 new_fl |= EXT4_NOATIME_FL;
2651 if (vfs_fl & S_DIRSYNC)
2652 new_fl |= EXT4_DIRSYNC_FL;
2654 + if (vfs_vf & V_BARRIER)
2655 + new_fl |= EXT4_BARRIER_FL;
2656 + if (vfs_vf & V_COW)
2657 + new_fl |= EXT4_COW_FL;
2658 } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
2661 @@ -4531,8 +4556,10 @@ struct inode *ext4_iget(struct super_blo
2662 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2663 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2665 - i_uid_write(inode, i_uid);
2666 - i_gid_write(inode, i_gid);
2667 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2668 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2669 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2670 + le16_to_cpu(raw_inode->i_raw_tag)));
2671 ei->i_projid = make_kprojid(&init_user_ns, i_projid);
2672 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2674 @@ -4848,8 +4875,10 @@ static int ext4_do_update_inode(handle_t
2676 ext4_get_inode_flags(ei);
2677 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2678 - i_uid = i_uid_read(inode);
2679 - i_gid = i_gid_read(inode);
2680 + i_uid = from_kuid(&init_user_ns,
2681 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2682 + i_gid = from_kgid(&init_user_ns,
2683 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2684 i_projid = from_kprojid(&init_user_ns, ei->i_projid);
2685 if (!(test_opt(inode->i_sb, NO_UID32))) {
2686 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2687 @@ -4873,6 +4902,9 @@ static int ext4_do_update_inode(handle_t
2688 raw_inode->i_uid_high = 0;
2689 raw_inode->i_gid_high = 0;
2691 +#ifdef CONFIG_TAGGING_INTERN
2692 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2694 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2696 EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
2697 @@ -5126,7 +5158,8 @@ int ext4_setattr(struct dentry *dentry,
2700 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2701 - (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2702 + (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2703 + (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2706 /* (user+group)*(old+new) structure, inode write (sb,
2707 @@ -5149,6 +5182,8 @@ int ext4_setattr(struct dentry *dentry,
2708 inode->i_uid = attr->ia_uid;
2709 if (attr->ia_valid & ATTR_GID)
2710 inode->i_gid = attr->ia_gid;
2711 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2712 + inode->i_tag = attr->ia_tag;
2713 error = ext4_mark_inode_dirty(handle, inode);
2714 ext4_journal_stop(handle);
2716 diff -NurpP --minimal linux-4.9.76/fs/ext4/ioctl.c linux-4.9.76-vs2.3.9.5/fs/ext4/ioctl.c
2717 --- linux-4.9.76/fs/ext4/ioctl.c 2016-12-11 19:17:54.000000000 +0000
2718 +++ linux-4.9.76-vs2.3.9.5/fs/ext4/ioctl.c 2018-01-13 02:03:59.000000000 +0000
2720 #include <linux/file.h>
2721 #include <linux/quotaops.h>
2722 #include <linux/uuid.h>
2723 +#include <linux/vs_tag.h>
2724 #include <asm/uaccess.h>
2725 #include "ext4_jbd2.h"
2727 @@ -226,7 +227,9 @@ static int ext4_ioctl_setflags(struct in
2729 * This test looks nicer. Thanks to Pauline Middelink
2731 - if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
2732 + if ((oldflags & EXT4_IMMUTABLE_FL) ||
2733 + ((flags ^ oldflags) & (EXT4_APPEND_FL |
2734 + EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
2735 if (!capable(CAP_LINUX_IMMUTABLE))
2738 @@ -430,6 +433,33 @@ static inline unsigned long ext4_xflags_
2742 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
2744 + handle_t *handle = NULL;
2745 + struct ext4_iloc iloc;
2748 + handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
2749 + if (IS_ERR(handle))
2750 + return PTR_ERR(handle);
2752 + if (IS_SYNC(inode))
2753 + ext4_handle_sync(handle);
2754 + err = ext4_reserve_inode_write(handle, inode, &iloc);
2758 + inode->i_flags = flags;
2759 + inode->i_vflags = vflags;
2760 + ext4_get_inode_flags(EXT4_I(inode));
2761 + inode->i_ctime = ext4_current_time(inode);
2763 + err = ext4_mark_iloc_dirty(handle, inode, &iloc);
2765 + ext4_journal_stop(handle);
2769 long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2771 struct inode *inode = file_inode(filp);
2772 @@ -459,6 +489,11 @@ long ext4_ioctl(struct file *filp, unsig
2774 flags = ext4_mask_flags(inode->i_mode, flags);
2776 + if (IS_BARRIER(inode)) {
2777 + vxwprintk_task(1, "messing with the barrier.");
2782 err = ext4_ioctl_setflags(inode, flags);
2783 inode_unlock(inode);
2784 diff -NurpP --minimal linux-4.9.76/fs/ext4/namei.c linux-4.9.76-vs2.3.9.5/fs/ext4/namei.c
2785 --- linux-4.9.76/fs/ext4/namei.c 2018-01-13 21:28:56.000000000 +0000
2786 +++ linux-4.9.76-vs2.3.9.5/fs/ext4/namei.c 2018-01-10 02:50:49.000000000 +0000
2788 #include <linux/quotaops.h>
2789 #include <linux/buffer_head.h>
2790 #include <linux/bio.h>
2791 +#include <linux/vs_tag.h>
2793 #include "ext4_jbd2.h"
2795 @@ -1459,6 +1460,7 @@ restart:
2796 REQ_META | REQ_PRIO,
2799 + dx_propagate_tag(nd, inode);
2801 if ((bh = bh_use[ra_ptr++]) == NULL)
2803 @@ -3906,6 +3908,7 @@ const struct inode_operations ext4_dir_i
2804 .get_acl = ext4_get_acl,
2805 .set_acl = ext4_set_acl,
2806 .fiemap = ext4_fiemap,
2807 + .sync_flags = ext4_sync_flags,
2810 const struct inode_operations ext4_special_inode_operations = {
2811 diff -NurpP --minimal linux-4.9.76/fs/ext4/super.c linux-4.9.76-vs2.3.9.5/fs/ext4/super.c
2812 --- linux-4.9.76/fs/ext4/super.c 2018-01-13 21:28:56.000000000 +0000
2813 +++ linux-4.9.76-vs2.3.9.5/fs/ext4/super.c 2018-01-10 02:50:49.000000000 +0000
2814 @@ -1280,6 +1280,7 @@ enum {
2815 Opt_dioread_nolock, Opt_dioread_lock,
2816 Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
2817 Opt_max_dir_size_kb, Opt_nojournal_checksum,
2818 + Opt_tag, Opt_notag, Opt_tagid
2821 static const match_table_t tokens = {
2822 @@ -1366,6 +1367,9 @@ static const match_table_t tokens = {
2823 {Opt_removed, "reservation"}, /* mount option from ext2/3 */
2824 {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
2825 {Opt_removed, "journal=%u"}, /* mount option from ext2/3 */
2827 + {Opt_notag, "notag"},
2828 + {Opt_tagid, "tagid=%u"},
2832 @@ -1611,6 +1615,20 @@ static int handle_mount_opt(struct super
2833 case Opt_nolazytime:
2834 sb->s_flags &= ~MS_LAZYTIME;
2836 +#ifndef CONFIG_TAGGING_NONE
2838 + set_opt(sb, TAGGED);
2841 + clear_opt(sb, TAGGED);
2844 +#ifdef CONFIG_PROPAGATE
2847 + set_opt(sb, TAGGED);
2852 for (m = ext4_mount_opts; m->token != Opt_err; m++)
2853 @@ -3550,6 +3568,9 @@ static int ext4_fill_super(struct super_
2854 sb->s_iflags |= SB_I_CGROUPWB;
2857 + if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
2858 + sb->s_flags |= MS_TAGGED;
2860 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2861 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2863 @@ -4917,6 +4938,14 @@ static int ext4_remount(struct super_blo
2864 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
2865 ext4_abort(sb, "Abort forced by user");
2867 + if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
2868 + !(sb->s_flags & MS_TAGGED)) {
2869 + printk("EXT4-fs: %s: tagging not permitted on remount.\n",
2872 + goto restore_opts;
2875 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2876 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2878 diff -NurpP --minimal linux-4.9.76/fs/fcntl.c linux-4.9.76-vs2.3.9.5/fs/fcntl.c
2879 --- linux-4.9.76/fs/fcntl.c 2018-01-13 21:28:57.000000000 +0000
2880 +++ linux-4.9.76-vs2.3.9.5/fs/fcntl.c 2018-01-10 02:50:49.000000000 +0000
2882 #include <linux/pid_namespace.h>
2883 #include <linux/user_namespace.h>
2884 #include <linux/shmem_fs.h>
2885 +#include <linux/vs_limit.h>
2887 #include <asm/poll.h>
2888 #include <asm/siginfo.h>
2889 @@ -386,6 +387,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
2893 + if (!vx_files_avail(1))
2896 if (unlikely(f.file->f_mode & FMODE_PATH)) {
2897 if (!check_fcntl_cmd(cmd))
2898 diff -NurpP --minimal linux-4.9.76/fs/file.c linux-4.9.76-vs2.3.9.5/fs/file.c
2899 --- linux-4.9.76/fs/file.c 2016-12-11 19:17:54.000000000 +0000
2900 +++ linux-4.9.76-vs2.3.9.5/fs/file.c 2018-01-10 02:50:49.000000000 +0000
2902 #include <linux/spinlock.h>
2903 #include <linux/rcupdate.h>
2904 #include <linux/workqueue.h>
2905 +#include <linux/vs_limit.h>
2907 unsigned int sysctl_nr_open __read_mostly = 1024*1024;
2908 unsigned int sysctl_nr_open_min = BITS_PER_LONG;
2909 @@ -357,6 +358,8 @@ struct files_struct *dup_fd(struct files
2910 struct file *f = *old_fds++;
2913 + /* TODO: sum it first for check and performance */
2914 + vx_openfd_inc(open_files - i);
2917 * The fd may be claimed in the fd bitmap but not yet
2918 @@ -406,9 +409,11 @@ static struct fdtable *close_files(struc
2919 filp_close(file, files);
2920 cond_resched_rcu_qs();
2930 @@ -539,6 +544,7 @@ repeat:
2932 __clear_close_on_exec(fd, fdt);
2934 + vx_openfd_inc(fd);
2937 if (rcu_access_pointer(fdt->fd[fd]) != NULL) {
2938 @@ -569,6 +575,7 @@ static void __put_unused_fd(struct files
2939 __clear_open_fd(fd, fdt);
2940 if (fd < files->next_fd)
2941 files->next_fd = fd;
2942 + vx_openfd_dec(fd);
2945 void put_unused_fd(unsigned int fd)
2946 @@ -856,6 +863,8 @@ __releases(&files->file_lock)
2949 filp_close(tofree, files);
2951 + vx_openfd_inc(fd); /* fd was unused */
2955 diff -NurpP --minimal linux-4.9.76/fs/file_table.c linux-4.9.76-vs2.3.9.5/fs/file_table.c
2956 --- linux-4.9.76/fs/file_table.c 2016-12-11 19:17:54.000000000 +0000
2957 +++ linux-4.9.76-vs2.3.9.5/fs/file_table.c 2018-01-10 02:50:49.000000000 +0000
2959 #include <linux/task_work.h>
2960 #include <linux/ima.h>
2961 #include <linux/swap.h>
2962 +#include <linux/vs_limit.h>
2963 +#include <linux/vs_context.h>
2965 #include <linux/atomic.h>
2967 @@ -137,6 +139,8 @@ struct file *get_empty_filp(void)
2968 mutex_init(&f->f_pos_lock);
2969 eventpoll_init_file(f);
2970 /* f->f_version: 0 */
2971 + f->f_xid = vx_current_xid();
2976 @@ -219,6 +223,8 @@ static void __fput(struct file *file)
2977 put_write_access(inode);
2978 __mnt_drop_write(mnt);
2980 + vx_files_dec(file);
2982 file->f_path.dentry = NULL;
2983 file->f_path.mnt = NULL;
2984 file->f_inode = NULL;
2985 @@ -305,6 +311,8 @@ void put_filp(struct file *file)
2987 if (atomic_long_dec_and_test(&file->f_count)) {
2988 security_file_free(file);
2989 + vx_files_dec(file);
2994 diff -NurpP --minimal linux-4.9.76/fs/fs_struct.c linux-4.9.76-vs2.3.9.5/fs/fs_struct.c
2995 --- linux-4.9.76/fs/fs_struct.c 2016-12-11 19:17:54.000000000 +0000
2996 +++ linux-4.9.76-vs2.3.9.5/fs/fs_struct.c 2018-01-10 02:50:49.000000000 +0000
2998 #include <linux/path.h>
2999 #include <linux/slab.h>
3000 #include <linux/fs_struct.h>
3001 +#include <linux/vserver/global.h>
3002 #include "internal.h"
3005 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3007 path_put(&fs->root);
3009 + atomic_dec(&vs_global_fs);
3010 kmem_cache_free(fs_cachep, fs);
3013 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3016 spin_unlock(&old->lock);
3017 + atomic_inc(&vs_global_fs);
3021 diff -NurpP --minimal linux-4.9.76/fs/gfs2/file.c linux-4.9.76-vs2.3.9.5/fs/gfs2/file.c
3022 --- linux-4.9.76/fs/gfs2/file.c 2018-01-13 21:28:57.000000000 +0000
3023 +++ linux-4.9.76-vs2.3.9.5/fs/gfs2/file.c 2018-01-10 02:50:49.000000000 +0000
3024 @@ -137,6 +137,9 @@ static const u32 fsflags_to_gfs2[32] = {
3025 [12] = GFS2_DIF_EXHASH,
3026 [14] = GFS2_DIF_INHERIT_JDATA,
3027 [17] = GFS2_DIF_TOPDIR,
3028 + [27] = GFS2_DIF_IXUNLINK,
3029 + [26] = GFS2_DIF_BARRIER,
3030 + [29] = GFS2_DIF_COW,
3033 static const u32 gfs2_to_fsflags[32] = {
3034 @@ -147,6 +150,9 @@ static const u32 gfs2_to_fsflags[32] = {
3035 [gfs2fl_ExHash] = FS_INDEX_FL,
3036 [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3037 [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3038 + [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3039 + [gfs2fl_Barrier] = FS_BARRIER_FL,
3040 + [gfs2fl_Cow] = FS_COW_FL,
3043 static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3044 @@ -178,12 +184,17 @@ void gfs2_set_inode_flags(struct inode *
3046 struct gfs2_inode *ip = GFS2_I(inode);
3047 unsigned int flags = inode->i_flags;
3048 + unsigned int vflags = inode->i_vflags;
3050 + flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3051 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3053 - flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3054 if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3056 if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3057 flags |= S_IMMUTABLE;
3058 + if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3059 + flags |= S_IXUNLINK;
3060 if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3062 if (ip->i_diskflags & GFS2_DIF_NOATIME)
3063 @@ -191,6 +202,43 @@ void gfs2_set_inode_flags(struct inode *
3064 if (ip->i_diskflags & GFS2_DIF_SYNC)
3066 inode->i_flags = flags;
3068 + vflags &= ~(V_BARRIER | V_COW);
3070 + if (ip->i_diskflags & GFS2_DIF_BARRIER)
3071 + vflags |= V_BARRIER;
3072 + if (ip->i_diskflags & GFS2_DIF_COW)
3074 + inode->i_vflags = vflags;
3077 +void gfs2_get_inode_flags(struct inode *inode)
3079 + struct gfs2_inode *ip = GFS2_I(inode);
3080 + unsigned int flags = inode->i_flags;
3081 + unsigned int vflags = inode->i_vflags;
3083 + ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3084 + GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3085 + GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3086 + GFS2_DIF_BARRIER | GFS2_DIF_COW);
3088 + if (flags & S_IMMUTABLE)
3089 + ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3090 + if (flags & S_IXUNLINK)
3091 + ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3093 + if (flags & S_APPEND)
3094 + ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3095 + if (flags & S_NOATIME)
3096 + ip->i_diskflags |= GFS2_DIF_NOATIME;
3097 + if (flags & S_SYNC)
3098 + ip->i_diskflags |= GFS2_DIF_SYNC;
3100 + if (vflags & V_BARRIER)
3101 + ip->i_diskflags |= GFS2_DIF_BARRIER;
3102 + if (vflags & V_COW)
3103 + ip->i_diskflags |= GFS2_DIF_COW;
3106 /* Flags that can be set by user space */
3107 @@ -306,6 +354,37 @@ static int gfs2_set_flags(struct file *f
3108 return do_gfs2_set_flags(filp, gfsflags, ~(GFS2_DIF_SYSTEM | GFS2_DIF_JDATA));
3111 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3113 + struct gfs2_inode *ip = GFS2_I(inode);
3114 + struct gfs2_sbd *sdp = GFS2_SB(inode);
3115 + struct buffer_head *bh;
3116 + struct gfs2_holder gh;
3119 + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3122 + error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3125 + error = gfs2_meta_inode_buffer(ip, &bh);
3127 + goto out_trans_end;
3128 + gfs2_trans_add_meta(ip->i_gl, bh);
3129 + inode->i_flags = flags;
3130 + inode->i_vflags = vflags;
3131 + gfs2_get_inode_flags(inode);
3132 + gfs2_dinode_out(ip, bh->b_data);
3134 + gfs2_set_aops(inode);
3136 + gfs2_trans_end(sdp);
3138 + gfs2_glock_dq_uninit(&gh);
3142 static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3145 diff -NurpP --minimal linux-4.9.76/fs/gfs2/inode.h linux-4.9.76-vs2.3.9.5/fs/gfs2/inode.h
3146 --- linux-4.9.76/fs/gfs2/inode.h 2016-12-11 19:17:54.000000000 +0000
3147 +++ linux-4.9.76-vs2.3.9.5/fs/gfs2/inode.h 2018-01-10 02:50:49.000000000 +0000
3148 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3149 extern const struct file_operations gfs2_dir_fops_nolock;
3151 extern void gfs2_set_inode_flags(struct inode *inode);
3152 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3154 #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3155 extern const struct file_operations gfs2_file_fops;
3156 diff -NurpP --minimal linux-4.9.76/fs/hostfs/hostfs.h linux-4.9.76-vs2.3.9.5/fs/hostfs/hostfs.h
3157 --- linux-4.9.76/fs/hostfs/hostfs.h 2016-12-11 19:17:54.000000000 +0000
3158 +++ linux-4.9.76-vs2.3.9.5/fs/hostfs/hostfs.h 2018-01-10 02:50:49.000000000 +0000
3159 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3160 unsigned short ia_mode;
3165 struct timespec ia_atime;
3166 struct timespec ia_mtime;
3167 diff -NurpP --minimal linux-4.9.76/fs/inode.c linux-4.9.76-vs2.3.9.5/fs/inode.c
3168 --- linux-4.9.76/fs/inode.c 2018-01-13 21:28:57.000000000 +0000
3169 +++ linux-4.9.76-vs2.3.9.5/fs/inode.c 2018-01-10 02:50:49.000000000 +0000
3171 #include <linux/buffer_head.h> /* for inode_has_buffers */
3172 #include <linux/ratelimit.h>
3173 #include <linux/list_lru.h>
3174 +#include <linux/vs_tag.h>
3175 #include <trace/events/writeback.h>
3176 #include "internal.h"
3178 @@ -133,6 +134,8 @@ int inode_init_always(struct super_block
3179 struct address_space *const mapping = &inode->i_data;
3183 + /* essential because of inode slab reuse */
3184 inode->i_blkbits = sb->s_blocksize_bits;
3186 atomic_set(&inode->i_count, 1);
3187 @@ -144,6 +147,7 @@ int inode_init_always(struct super_block
3188 inode->i_opflags |= IOP_XATTR;
3189 i_uid_write(inode, 0);
3190 i_gid_write(inode, 0);
3191 + i_tag_write(inode, 0);
3192 atomic_set(&inode->i_writecount, 0);
3194 inode->i_blocks = 0;
3195 @@ -155,6 +159,7 @@ int inode_init_always(struct super_block
3196 inode->i_link = NULL;
3197 inode->i_dir_seq = 0;
3199 + inode->i_mdev = 0;
3200 inode->dirtied_when = 0;
3202 #ifdef CONFIG_CGROUP_WRITEBACK
3203 @@ -479,6 +484,8 @@ void __insert_inode_hash(struct inode *i
3205 EXPORT_SYMBOL(__insert_inode_hash);
3207 +EXPORT_SYMBOL_GPL(__iget);
3210 * __remove_inode_hash - remove an inode from the hash
3211 * @inode: inode to unhash
3212 @@ -1977,9 +1984,11 @@ void init_special_inode(struct inode *in
3213 if (S_ISCHR(mode)) {
3214 inode->i_fop = &def_chr_fops;
3215 inode->i_rdev = rdev;
3216 + inode->i_mdev = rdev;
3217 } else if (S_ISBLK(mode)) {
3218 inode->i_fop = &def_blk_fops;
3219 inode->i_rdev = rdev;
3220 + inode->i_mdev = rdev;
3221 } else if (S_ISFIFO(mode))
3222 inode->i_fop = &pipefifo_fops;
3223 else if (S_ISSOCK(mode))
3224 @@ -2008,6 +2017,7 @@ void inode_init_owner(struct inode *inod
3226 inode->i_gid = current_fsgid();
3227 inode->i_mode = mode;
3228 + i_tag_write(inode, dx_current_fstag(inode->i_sb));
3230 EXPORT_SYMBOL(inode_init_owner);
3232 diff -NurpP --minimal linux-4.9.76/fs/ioctl.c linux-4.9.76-vs2.3.9.5/fs/ioctl.c
3233 --- linux-4.9.76/fs/ioctl.c 2016-12-11 19:17:54.000000000 +0000
3234 +++ linux-4.9.76-vs2.3.9.5/fs/ioctl.c 2018-01-13 01:03:36.000000000 +0000
3236 #include <linux/writeback.h>
3237 #include <linux/buffer_head.h>
3238 #include <linux/falloc.h>
3239 +#include <linux/proc_fs.h>
3240 +#include <linux/vserver/inode.h>
3241 +#include <linux/vs_tag.h>
3242 #include "internal.h"
3244 #include <asm/ioctls.h>
3245 diff -NurpP --minimal linux-4.9.76/fs/jfs/file.c linux-4.9.76-vs2.3.9.5/fs/jfs/file.c
3246 --- linux-4.9.76/fs/jfs/file.c 2016-12-11 19:17:54.000000000 +0000
3247 +++ linux-4.9.76-vs2.3.9.5/fs/jfs/file.c 2018-01-10 02:50:49.000000000 +0000
3248 @@ -113,7 +113,8 @@ int jfs_setattr(struct dentry *dentry, s
3251 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3252 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3253 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3254 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3255 rc = dquot_transfer(inode, iattr);
3258 @@ -146,6 +147,7 @@ const struct inode_operations jfs_file_i
3259 .get_acl = jfs_get_acl,
3260 .set_acl = jfs_set_acl,
3262 + .sync_flags = jfs_sync_flags,
3265 const struct file_operations jfs_file_operations = {
3266 diff -NurpP --minimal linux-4.9.76/fs/jfs/ioctl.c linux-4.9.76-vs2.3.9.5/fs/jfs/ioctl.c
3267 --- linux-4.9.76/fs/jfs/ioctl.c 2016-12-11 19:17:54.000000000 +0000
3268 +++ linux-4.9.76-vs2.3.9.5/fs/jfs/ioctl.c 2018-01-10 02:50:49.000000000 +0000
3270 #include <linux/time.h>
3271 #include <linux/sched.h>
3272 #include <linux/blkdev.h>
3273 +#include <linux/mount.h>
3274 #include <asm/current.h>
3275 #include <asm/uaccess.h>
3277 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3281 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3283 + inode->i_flags = flags;
3284 + inode->i_vflags = vflags;
3285 + jfs_get_inode_flags(JFS_IP(inode));
3286 + inode->i_ctime = CURRENT_TIME_SEC;
3287 + mark_inode_dirty(inode);
3291 long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3293 struct inode *inode = file_inode(filp);
3294 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3295 if (!S_ISDIR(inode->i_mode))
3296 flags &= ~JFS_DIRSYNC_FL;
3298 + if (IS_BARRIER(inode)) {
3299 + vxwprintk_task(1, "messing with the barrier.");
3303 /* Is it quota file? Do not allow user to mess with it */
3304 if (IS_NOQUOTA(inode)) {
3306 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3307 * the relevant capability.
3309 if ((oldflags & JFS_IMMUTABLE_FL) ||
3310 - ((flags ^ oldflags) &
3311 - (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3312 + ((flags ^ oldflags) & (JFS_APPEND_FL |
3313 + JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3314 if (!capable(CAP_LINUX_IMMUTABLE)) {
3315 inode_unlock(inode);
3317 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3321 - flags = flags & JFS_FL_USER_MODIFIABLE;
3322 + flags &= JFS_FL_USER_MODIFIABLE;
3323 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3324 jfs_inode->mode2 = flags;
3326 diff -NurpP --minimal linux-4.9.76/fs/jfs/jfs_dinode.h linux-4.9.76-vs2.3.9.5/fs/jfs/jfs_dinode.h
3327 --- linux-4.9.76/fs/jfs/jfs_dinode.h 2016-12-11 19:17:54.000000000 +0000
3328 +++ linux-4.9.76-vs2.3.9.5/fs/jfs/jfs_dinode.h 2018-01-10 02:50:49.000000000 +0000
3329 @@ -161,9 +161,13 @@ struct dinode {
3331 #define JFS_APPEND_FL 0x01000000 /* writes to file may only append */
3332 #define JFS_IMMUTABLE_FL 0x02000000 /* Immutable file */
3333 +#define JFS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
3335 -#define JFS_FL_USER_VISIBLE 0x03F80000
3336 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3337 +#define JFS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
3338 +#define JFS_COW_FL 0x20000000 /* Copy on Write marker */
3340 +#define JFS_FL_USER_VISIBLE 0x07F80000
3341 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3342 #define JFS_FL_INHERIT 0x03C80000
3344 /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3345 diff -NurpP --minimal linux-4.9.76/fs/jfs/jfs_filsys.h linux-4.9.76-vs2.3.9.5/fs/jfs/jfs_filsys.h
3346 --- linux-4.9.76/fs/jfs/jfs_filsys.h 2016-12-11 19:17:54.000000000 +0000
3347 +++ linux-4.9.76-vs2.3.9.5/fs/jfs/jfs_filsys.h 2018-01-10 02:50:49.000000000 +0000
3349 #define JFS_NAME_MAX 255
3350 #define JFS_PATH_MAX BPSIZE
3352 +#define JFS_TAGGED 0x00800000 /* Context Tagging */
3355 * file system state (superblock state)
3356 diff -NurpP --minimal linux-4.9.76/fs/jfs/jfs_imap.c linux-4.9.76-vs2.3.9.5/fs/jfs/jfs_imap.c
3357 --- linux-4.9.76/fs/jfs/jfs_imap.c 2016-12-11 19:17:54.000000000 +0000
3358 +++ linux-4.9.76-vs2.3.9.5/fs/jfs/jfs_imap.c 2018-01-10 02:50:49.000000000 +0000
3360 #include <linux/pagemap.h>
3361 #include <linux/quotaops.h>
3362 #include <linux/slab.h>
3363 +#include <linux/vs_tag.h>
3365 #include "jfs_incore.h"
3366 #include "jfs_inode.h"
3367 @@ -3046,6 +3047,8 @@ static int copy_from_dinode(struct dinod
3369 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3370 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3374 jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3375 jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3376 @@ -3066,14 +3069,18 @@ static int copy_from_dinode(struct dinod
3378 set_nlink(ip, le32_to_cpu(dip->di_nlink));
3380 - jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3381 + kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3382 + kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3383 + ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3385 + jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3386 if (!uid_valid(sbi->uid))
3387 ip->i_uid = jfs_ip->saved_uid;
3389 ip->i_uid = sbi->uid;
3392 - jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3393 + jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3394 if (!gid_valid(sbi->gid))
3395 ip->i_gid = jfs_ip->saved_gid;
3397 @@ -3138,16 +3145,14 @@ static void copy_to_dinode(struct dinode
3398 dip->di_size = cpu_to_le64(ip->i_size);
3399 dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3400 dip->di_nlink = cpu_to_le32(ip->i_nlink);
3401 - if (!uid_valid(sbi->uid))
3402 - dip->di_uid = cpu_to_le32(i_uid_read(ip));
3404 - dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3405 - jfs_ip->saved_uid));
3406 - if (!gid_valid(sbi->gid))
3407 - dip->di_gid = cpu_to_le32(i_gid_read(ip));
3409 - dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3410 - jfs_ip->saved_gid));
3411 + dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3412 + TAGINO_KUID(DX_TAG(ip),
3413 + !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3415 + dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3416 + TAGINO_KGID(DX_TAG(ip),
3417 + !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3419 jfs_get_inode_flags(jfs_ip);
3421 * mode2 is only needed for storing the higher order bits.
3422 diff -NurpP --minimal linux-4.9.76/fs/jfs/jfs_inode.c linux-4.9.76-vs2.3.9.5/fs/jfs/jfs_inode.c
3423 --- linux-4.9.76/fs/jfs/jfs_inode.c 2016-12-11 19:17:54.000000000 +0000
3424 +++ linux-4.9.76-vs2.3.9.5/fs/jfs/jfs_inode.c 2018-01-14 06:01:31.000000000 +0000
3427 #include <linux/fs.h>
3428 #include <linux/quotaops.h>
3429 +#include <linux/vs_tag.h>
3430 #include "jfs_incore.h"
3431 #include "jfs_inode.h"
3432 #include "jfs_filsys.h"
3433 @@ -33,6 +34,9 @@ void jfs_set_inode_flags(struct inode *i
3435 if (flags & JFS_IMMUTABLE_FL)
3436 new_fl |= S_IMMUTABLE;
3437 + if (flags & JFS_IXUNLINK_FL)
3438 + new_fl |= S_IXUNLINK;
3440 if (flags & JFS_APPEND_FL)
3442 if (flags & JFS_NOATIME_FL)
3443 @@ -41,18 +45,35 @@ void jfs_set_inode_flags(struct inode *i
3444 new_fl |= S_DIRSYNC;
3445 if (flags & JFS_SYNC_FL)
3447 - inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND | S_NOATIME |
3448 - S_DIRSYNC | S_SYNC);
3450 + inode_set_flags(inode, new_fl, S_IMMUTABLE | S_IXUNLINK |
3451 + S_APPEND | S_NOATIME | S_DIRSYNC | S_SYNC);
3454 + if (flags & JFS_BARRIER_FL)
3455 + new_fl |= V_BARRIER;
3456 + if (flags & JFS_COW_FL)
3459 + set_mask_bits(&inode->i_vflags,
3460 + V_BARRIER | V_COW, new_fl);
3463 void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3465 unsigned int flags = jfs_ip->vfs_inode.i_flags;
3466 + unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3468 + jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3469 + JFS_APPEND_FL | JFS_NOATIME_FL |
3470 + JFS_DIRSYNC_FL | JFS_SYNC_FL |
3471 + JFS_BARRIER_FL | JFS_COW_FL);
3473 - jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3474 - JFS_DIRSYNC_FL | JFS_SYNC_FL);
3475 if (flags & S_IMMUTABLE)
3476 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3477 + if (flags & S_IXUNLINK)
3478 + jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3480 if (flags & S_APPEND)
3481 jfs_ip->mode2 |= JFS_APPEND_FL;
3482 if (flags & S_NOATIME)
3483 @@ -61,6 +82,11 @@ void jfs_get_inode_flags(struct jfs_inod
3484 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3486 jfs_ip->mode2 |= JFS_SYNC_FL;
3488 + if (vflags & V_BARRIER)
3489 + jfs_ip->mode2 |= JFS_BARRIER_FL;
3490 + if (vflags & V_COW)
3491 + jfs_ip->mode2 |= JFS_COW_FL;
3495 diff -NurpP --minimal linux-4.9.76/fs/jfs/jfs_inode.h linux-4.9.76-vs2.3.9.5/fs/jfs/jfs_inode.h
3496 --- linux-4.9.76/fs/jfs/jfs_inode.h 2016-12-11 19:17:54.000000000 +0000
3497 +++ linux-4.9.76-vs2.3.9.5/fs/jfs/jfs_inode.h 2018-01-10 02:50:49.000000000 +0000
3498 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3499 extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3500 int fh_len, int fh_type);
3501 extern void jfs_set_inode_flags(struct inode *);
3502 +extern int jfs_sync_flags(struct inode *, int, int);
3503 extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3504 extern int jfs_setattr(struct dentry *, struct iattr *);
3506 diff -NurpP --minimal linux-4.9.76/fs/jfs/namei.c linux-4.9.76-vs2.3.9.5/fs/jfs/namei.c
3507 --- linux-4.9.76/fs/jfs/namei.c 2016-12-11 19:17:54.000000000 +0000
3508 +++ linux-4.9.76-vs2.3.9.5/fs/jfs/namei.c 2018-01-10 02:50:49.000000000 +0000
3510 #include <linux/ctype.h>
3511 #include <linux/quotaops.h>
3512 #include <linux/exportfs.h>
3513 +#include <linux/vs_tag.h>
3514 #include "jfs_incore.h"
3515 #include "jfs_superblock.h"
3516 #include "jfs_inode.h"
3517 @@ -1484,6 +1485,7 @@ static struct dentry *jfs_lookup(struct
3518 jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3521 + dx_propagate_tag(nd, ip);
3522 return d_splice_alias(ip, dentry);
3525 @@ -1546,6 +1548,7 @@ const struct inode_operations jfs_dir_in
3526 .get_acl = jfs_get_acl,
3527 .set_acl = jfs_set_acl,
3529 + .sync_flags = jfs_sync_flags,
3532 const struct file_operations jfs_dir_operations = {
3533 diff -NurpP --minimal linux-4.9.76/fs/jfs/super.c linux-4.9.76-vs2.3.9.5/fs/jfs/super.c
3534 --- linux-4.9.76/fs/jfs/super.c 2018-01-13 21:28:57.000000000 +0000
3535 +++ linux-4.9.76-vs2.3.9.5/fs/jfs/super.c 2018-01-10 02:50:49.000000000 +0000
3536 @@ -206,7 +206,8 @@ enum {
3537 Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3538 Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3539 Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3540 - Opt_discard, Opt_nodiscard, Opt_discard_minblk
3541 + Opt_discard, Opt_nodiscard, Opt_discard_minblk,
3542 + Opt_tag, Opt_notag, Opt_tagid
3545 static const match_table_t tokens = {
3546 @@ -216,6 +217,10 @@ static const match_table_t tokens = {
3547 {Opt_resize, "resize=%u"},
3548 {Opt_resize_nosize, "resize"},
3549 {Opt_errors, "errors=%s"},
3551 + {Opt_notag, "notag"},
3552 + {Opt_tagid, "tagid=%u"},
3553 + {Opt_tag, "tagxid"},
3554 {Opt_ignore, "noquota"},
3555 {Opt_ignore, "quota"},
3556 {Opt_usrquota, "usrquota"},
3557 @@ -405,7 +410,20 @@ static int parse_options(char *options,
3558 pr_err("JFS: discard option not supported on device\n");
3562 +#ifndef CONFIG_TAGGING_NONE
3564 + *flag |= JFS_TAGGED;
3567 + *flag &= JFS_TAGGED;
3570 +#ifdef CONFIG_PROPAGATE
3573 + *flag |= JFS_TAGGED;
3577 printk("jfs: Unrecognized mount option \"%s\" or missing value\n",
3579 @@ -437,6 +455,12 @@ static int jfs_remount(struct super_bloc
3580 if (!parse_options(data, sb, &newLVSize, &flag))
3583 + if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3584 + printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
3590 if (sb->s_flags & MS_RDONLY) {
3591 pr_err("JFS: resize requires volume to be mounted read-write\n");
3592 @@ -517,6 +541,9 @@ static int jfs_fill_super(struct super_b
3593 #ifdef CONFIG_JFS_POSIX_ACL
3594 sb->s_flags |= MS_POSIXACL;
3596 + /* map mount option tagxid */
3597 + if (sbi->flag & JFS_TAGGED)
3598 + sb->s_flags |= MS_TAGGED;
3601 pr_err("resize option for remount only\n");
3602 diff -NurpP --minimal linux-4.9.76/fs/libfs.c linux-4.9.76-vs2.3.9.5/fs/libfs.c
3603 --- linux-4.9.76/fs/libfs.c 2018-01-13 21:28:57.000000000 +0000
3604 +++ linux-4.9.76-vs2.3.9.5/fs/libfs.c 2018-01-13 01:03:09.000000000 +0000
3605 @@ -180,7 +180,8 @@ static inline unsigned char dt_type(stru
3606 * both impossible due to the lock on directory.
3609 -int dcache_readdir(struct file *file, struct dir_context *ctx)
3610 +static inline int do_dcache_readdir_filter(struct file *file,
3611 + struct dir_context *ctx, int (*filter)(struct dentry *dentry))
3613 struct dentry *dentry = file->f_path.dentry;
3614 struct dentry *cursor = file->private_data;
3615 @@ -194,9 +195,10 @@ int dcache_readdir(struct file *file, st
3617 p = &dentry->d_subdirs;
3618 while ((next = next_positive(dentry, p, 1)) != NULL) {
3619 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
3620 + if (!filter || filter(next))
3621 + if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
3622 d_inode(next)->i_ino, dt_type(d_inode(next))))
3628 @@ -205,8 +207,22 @@ int dcache_readdir(struct file *file, st
3629 move_cursor(cursor, p);
3633 EXPORT_SYMBOL(dcache_readdir);
3635 +int dcache_readdir(struct file *filp, struct dir_context *ctx)
3637 + return do_dcache_readdir_filter(filp, ctx, NULL);
3640 +EXPORT_SYMBOL(dcache_readdir_filter);
3642 +int dcache_readdir_filter(struct file *filp, struct dir_context *ctx,
3643 + int (*filter)(struct dentry *))
3645 + return do_dcache_readdir_filter(filp, ctx, filter);
3648 ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
3651 diff -NurpP --minimal linux-4.9.76/fs/locks.c linux-4.9.76-vs2.3.9.5/fs/locks.c
3652 --- linux-4.9.76/fs/locks.c 2016-12-11 19:17:54.000000000 +0000
3653 +++ linux-4.9.76-vs2.3.9.5/fs/locks.c 2018-01-13 01:28:30.000000000 +0000
3655 #include <linux/pid_namespace.h>
3656 #include <linux/hashtable.h>
3657 #include <linux/percpu.h>
3658 +#include <linux/vs_base.h>
3659 +#include <linux/vs_limit.h>
3661 #define CREATE_TRACE_POINTS
3662 #include <trace/events/filelock.h>
3663 @@ -292,11 +294,15 @@ static void locks_init_lock_heads(struct
3664 /* Allocate an empty lock structure. */
3665 struct file_lock *locks_alloc_lock(void)
3667 - struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
3668 + struct file_lock *fl;
3671 - locks_init_lock_heads(fl);
3672 + fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
3675 + locks_init_lock_heads(fl);
3681 EXPORT_SYMBOL_GPL(locks_alloc_lock);
3682 @@ -348,6 +354,7 @@ void locks_init_lock(struct file_lock *f
3684 memset(fl, 0, sizeof(struct file_lock));
3685 locks_init_lock_heads(fl);
3689 EXPORT_SYMBOL(locks_init_lock);
3690 @@ -365,6 +372,7 @@ void locks_copy_conflock(struct file_loc
3691 new->fl_start = fl->fl_start;
3692 new->fl_end = fl->fl_end;
3693 new->fl_lmops = fl->fl_lmops;
3694 + new->fl_xid = fl->fl_xid;
3698 @@ -426,7 +434,10 @@ flock_make_lock(struct file *filp, unsig
3699 fl->fl_flags = FL_FLOCK;
3701 fl->fl_end = OFFSET_MAX;
3704 + vxd_assert(filp->f_xid == vx_current_xid(),
3705 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
3706 + fl->fl_xid = filp->f_xid;
3710 @@ -548,6 +559,7 @@ static int lease_init(struct file *filp,
3712 fl->fl_owner = filp;
3713 fl->fl_pid = current->tgid;
3714 + fl->fl_xid = vx_current_xid();
3717 fl->fl_flags = FL_LEASE;
3718 @@ -567,6 +579,10 @@ static struct file_lock *lease_alloc(str
3720 return ERR_PTR(error);
3722 + fl->fl_xid = vx_current_xid();
3724 + vxd_assert(filp->f_xid == fl->fl_xid,
3725 + "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
3726 error = lease_init(filp, type, fl);
3728 locks_free_lock(fl);
3729 @@ -956,6 +972,7 @@ static int flock_lock_inode(struct inode
3733 + new_fl->fl_xid = -1;
3735 list_for_each_entry(fl, &ctx->flc_flock, fl_list) {
3736 if (!flock_locks_conflict(request, fl))
3737 @@ -984,7 +1001,7 @@ out:
3740 static int posix_lock_inode(struct inode *inode, struct file_lock *request,
3741 - struct file_lock *conflock)
3742 + struct file_lock *conflock, vxid_t xid)
3744 struct file_lock *fl, *tmp;
3745 struct file_lock *new_fl = NULL;
3746 @@ -1000,6 +1017,9 @@ static int posix_lock_inode(struct inode
3748 return (request->fl_type == F_UNLCK) ? 0 : -ENOMEM;
3751 + vxd_assert(xid == vx_current_xid(),
3752 + "xid(%d) == current(%d)", xid, vx_current_xid());
3754 * We may need two file_lock structures for this operation,
3755 * so we get them in advance to avoid races.
3756 @@ -1010,7 +1030,11 @@ static int posix_lock_inode(struct inode
3757 (request->fl_type != F_UNLCK ||
3758 request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
3759 new_fl = locks_alloc_lock();
3760 + new_fl->fl_xid = xid;
3761 + // vx_locks_inc(new_fl);
3762 new_fl2 = locks_alloc_lock();
3763 + new_fl2->fl_xid = xid;
3764 + // vx_locks_inc(new_fl2);
3767 percpu_down_read_preempt_disable(&file_rwsem);
3768 @@ -1216,7 +1240,7 @@ static int posix_lock_inode(struct inode
3769 int posix_lock_file(struct file *filp, struct file_lock *fl,
3770 struct file_lock *conflock)
3772 - return posix_lock_inode(locks_inode(filp), fl, conflock);
3773 + return posix_lock_inode(locks_inode(filp), fl, conflock, filp->f_xid);
3775 EXPORT_SYMBOL(posix_lock_file);
3777 @@ -1232,7 +1256,7 @@ static int posix_lock_inode_wait(struct
3781 - error = posix_lock_inode(inode, fl, NULL);
3782 + error = posix_lock_inode(inode, fl, NULL, 0);
3783 if (error != FILE_LOCK_DEFERRED)
3785 error = wait_event_interruptible(fl->fl_wait, !fl->fl_next);
3786 @@ -1308,10 +1332,13 @@ int locks_mandatory_area(struct inode *i
3794 fl.fl_flags &= ~FL_SLEEP;
3795 - error = posix_lock_inode(inode, &fl, NULL);
3796 + f_xid = filp->f_xid;
3797 + error = posix_lock_inode(inode, &fl, NULL, f_xid);
3801 @@ -1319,7 +1346,7 @@ int locks_mandatory_area(struct inode *i
3803 fl.fl_flags |= FL_SLEEP;
3804 fl.fl_owner = current->files;
3805 - error = posix_lock_inode(inode, &fl, NULL);
3806 + error = posix_lock_inode(inode, &fl, NULL, f_xid);
3807 if (error != FILE_LOCK_DEFERRED)
3809 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
3810 @@ -2374,6 +2401,16 @@ int fcntl_setlk64(unsigned int fd, struc
3811 if (file_lock == NULL)
3814 + vxd_assert(filp->f_xid == vx_current_xid(),
3815 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
3816 + file_lock->fl_xid = filp->f_xid;
3817 + // vx_locks_inc(file_lock);
3819 + vxd_assert(filp->f_xid == vx_current_xid(),
3820 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
3821 + file_lock->fl_xid = filp->f_xid;
3822 + // vx_locks_inc(file_lock);
3825 * This might block, so we do it before checking the inode.
3827 @@ -2710,8 +2747,11 @@ static int locks_show(struct seq_file *f
3829 lock_get_status(f, fl, iter->li_pos, "");
3831 - list_for_each_entry(bfl, &fl->fl_block, fl_block)
3832 + list_for_each_entry(bfl, &fl->fl_block, fl_block) {
3833 + if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
3835 lock_get_status(f, bfl, iter->li_pos, " ->");
3840 diff -NurpP --minimal linux-4.9.76/fs/mount.h linux-4.9.76-vs2.3.9.5/fs/mount.h
3841 --- linux-4.9.76/fs/mount.h 2018-01-13 21:28:57.000000000 +0000
3842 +++ linux-4.9.76-vs2.3.9.5/fs/mount.h 2018-01-10 02:50:49.000000000 +0000
3843 @@ -69,6 +69,7 @@ struct mount {
3844 struct hlist_head mnt_pins;
3845 struct fs_pin mnt_umount;
3846 struct dentry *mnt_ex_mountpoint;
3847 + vtag_t mnt_tag; /* tagging used for vfsmount */
3850 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
3851 diff -NurpP --minimal linux-4.9.76/fs/namei.c linux-4.9.76-vs2.3.9.5/fs/namei.c
3852 --- linux-4.9.76/fs/namei.c 2018-01-13 21:28:57.000000000 +0000
3853 +++ linux-4.9.76-vs2.3.9.5/fs/namei.c 2018-01-13 05:43:43.000000000 +0000
3855 #include <linux/hash.h>
3856 #include <linux/bitops.h>
3857 #include <linux/init_task.h>
3858 +#include <linux/proc_fs.h>
3859 +#include <linux/magic.h>
3860 +#include <linux/vserver/inode.h>
3861 +#include <linux/vs_base.h>
3862 +#include <linux/vs_tag.h>
3863 +#include <linux/vs_cowbl.h>
3864 +#include <linux/vs_device.h>
3865 +#include <linux/vs_context.h>
3866 +#include <linux/pid_namespace.h>
3867 #include <asm/uaccess.h>
3869 #include "internal.h"
3870 +#include "proc/internal.h"
3873 /* [Feb-1997 T. Schoebel-Theuer]
3874 @@ -285,6 +295,93 @@ static int check_acl(struct inode *inode
3878 +static inline int dx_barrier(const struct inode *inode)
3880 + if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
3881 + vxwprintk_task(1, "did hit the barrier.");
3887 +static int __dx_permission(const struct inode *inode, int mask)
3889 + if (dx_barrier(inode))
3892 + if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
3893 + /* devpts is xid tagged */
3894 + if (S_ISDIR(inode->i_mode) ||
3895 + vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
3898 + /* just pretend we didn't find anything */
3901 + else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
3902 + struct proc_dir_entry *de = PDE(inode);
3904 + if (de && !vx_hide_check(0, de->vx_flags)) {
3905 + vxdprintk(VXD_CBIT(misc, 9),
3906 + VS_Q("%*s") " hidden by _dx_permission",
3907 + de->namelen, de->name);
3911 + if ((mask & (MAY_WRITE | MAY_APPEND))) {
3913 + struct task_struct *tsk;
3915 + if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
3916 + vx_flags(VXF_STATE_SETUP, 0))
3919 + pid = PROC_I(inode)->pid;
3924 + tsk = pid_task(pid, PIDTYPE_PID);
3925 + vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
3926 + tsk, (tsk ? vx_task_xid(tsk) : 0));
3928 + vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
3929 + rcu_read_unlock();
3932 + rcu_read_unlock();
3935 + /* FIXME: Should we block some entries here? */
3940 + if (dx_notagcheck(inode->i_sb) ||
3941 + dx_check((vxid_t)i_tag_read(inode),
3942 + DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
3950 +int dx_permission(const struct inode *inode, int mask)
3952 + int ret = __dx_permission(inode, mask);
3953 + if (unlikely(ret)) {
3954 +#ifndef CONFIG_VSERVER_WARN_DEVPTS
3955 + if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
3958 + "denied [0x%x] access to inode %s:%p[#%d,%lu]",
3959 + mask, inode->i_sb->s_id, inode,
3960 + i_tag_read(inode), inode->i_ino);
3966 * This does the basic permission checking
3968 @@ -409,7 +506,7 @@ int __inode_permission(struct inode *ino
3970 * Nobody gets write access to an immutable file.
3972 - if (IS_IMMUTABLE(inode))
3973 + if (IS_IMMUTABLE(inode) && !IS_COW(inode))
3977 @@ -421,6 +518,10 @@ int __inode_permission(struct inode *ino
3981 + retval = dx_permission(inode, mask);
3985 retval = do_inode_permission(inode, mask);
3988 @@ -2781,7 +2882,7 @@ static int may_delete(struct inode *dir,
3991 if (check_sticky(dir, inode) || IS_APPEND(inode) ||
3992 - IS_IMMUTABLE(inode) || IS_SWAPFILE(inode) || HAS_UNMAPPED_ID(inode))
3993 + IS_IXORUNLINK(inode) || IS_SWAPFILE(inode) || HAS_UNMAPPED_ID(inode))
3996 if (!d_is_dir(victim))
3997 @@ -2869,19 +2970,25 @@ int vfs_create(struct inode *dir, struct
4000 int error = may_create(dir, dentry);
4003 + vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4007 if (!dir->i_op->create)
4008 return -EACCES; /* shouldn't it be ENOSYS? */
4011 error = security_inode_create(dir, dentry, mode);
4014 + vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4017 error = dir->i_op->create(dir, dentry, mode, want_excl);
4019 fsnotify_create(dir, dentry);
4021 + vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4024 EXPORT_SYMBOL(vfs_create);
4025 @@ -2919,6 +3026,15 @@ static int may_open(struct path *path, i
4029 +#ifdef CONFIG_VSERVER_COWBL
4030 + if (IS_COW(inode) &&
4031 + ((flag & O_ACCMODE) != O_RDONLY)) {
4032 + if (IS_COW_LINK(inode))
4034 + inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4035 + mark_inode_dirty(inode);
4038 error = inode_permission(inode, MAY_OPEN | acc_mode);
4041 @@ -3371,6 +3487,16 @@ finish_open:
4043 finish_open_created:
4044 error = may_open(&nd->path, acc_mode, open_flag);
4045 +#ifdef CONFIG_VSERVER_COWBL
4046 + if (error == -EMLINK) {
4047 + struct dentry *dentry;
4048 + dentry = cow_break_link(nd->name->name);
4049 + if (IS_ERR(dentry))
4050 + error = PTR_ERR(dentry);
4057 BUG_ON(*opened & FILE_OPENED); /* once it's opened, it's opened */
4058 @@ -3474,6 +3600,9 @@ static struct file *path_openat(struct n
4062 +#ifdef CONFIG_VSERVER_COWBL
4065 file = get_empty_filp();
4068 @@ -3507,6 +3636,12 @@ static struct file *path_openat(struct n
4072 +#ifdef CONFIG_VSERVER_COWBL
4073 + if (error == -EMLINK) {
4074 + // path_cleanup(nd);
4079 if (!(opened & FILE_OPENED)) {
4081 @@ -3627,6 +3762,11 @@ static struct dentry *filename_create(in
4085 + vxdprintk(VXD_CBIT(misc, 3), "filename_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4086 + path->dentry, path->dentry->d_name.len,
4087 + path->dentry->d_name.name, dentry,
4088 + dentry->d_name.len, dentry->d_name.name,
4089 + path->dentry->d_inode);
4093 @@ -3745,6 +3885,7 @@ retry:
4094 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
4099 done_path_create(&path, dentry);
4100 if (retry_estale(error, lookup_flags)) {
4101 @@ -4166,7 +4307,7 @@ int vfs_link(struct dentry *old_dentry,
4103 * A link to an append-only or immutable file cannot be created.
4105 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4106 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4109 * Updating the link count will likely cause i_uid and i_gid to
4110 @@ -4696,6 +4837,326 @@ const char *vfs_get_link(struct dentry *
4112 EXPORT_SYMBOL(vfs_get_link);
4115 +#ifdef CONFIG_VSERVER_COWBL
4118 +void dump_path(const char *name, struct path *path)
4120 + vxdprintk(VXD_CBIT(misc, 3),
4121 + "%s: path=%p mnt=%p dentry=%p", name, path,
4122 + path ? path->mnt : NULL,
4123 + path ? path->dentry : NULL);
4125 + if (path && path->mnt)
4126 + vxdprintk(VXD_CBIT(misc, 3),
4127 + "%s: path mnt_sb=%p[#%d,#%d] mnt_root=%p[#%d]", name,
4128 + path->mnt->mnt_sb,
4129 + path->mnt->mnt_sb ? path->mnt->mnt_sb->s_count : -1,
4130 + path->mnt->mnt_sb ? atomic_read(&path->mnt->mnt_sb->s_active) : -1,
4131 + path->mnt->mnt_root,
4132 + path->mnt->mnt_root ? path->mnt->mnt_root->d_lockref.count : -1);
4134 + if (path && path->dentry)
4135 + vxdprintk(VXD_CBIT(misc, 3),
4136 + "%s: path dentry=%p[#%d]", name,
4138 + path->dentry ? path->dentry->d_lockref.count : -1);
4142 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4147 + return do_splice_direct(in, &ppos, out, &opos, len, 0);
4150 +struct dentry *cow_break_link(const char *pathname)
4152 + int ret, mode, pathlen, redo = 0, drop = 1;
4153 + struct path old_path = {}, par_path = {}, dir_path = {}, *new_path = NULL;
4154 + struct dentry *dir, *old_dentry, *new_dentry = NULL;
4155 + struct file *old_file;
4156 + struct file *new_file;
4157 + struct qstr new_qstr;
4159 + char *to, *path, pad='\251';
4161 + struct filename *filename = getname_kernel(pathname);
4162 + struct filename *to_filename;
4164 + vxdprintk(VXD_CBIT(misc, 1),
4165 + "cow_break_link(" VS_Q("%s") ")", pathname);
4167 + path = kmalloc(PATH_MAX, GFP_KERNEL);
4169 + if (!path || IS_ERR(filename))
4172 + /* old_path will have refs to dentry and mnt */
4173 + ret = filename_lookup(AT_FDCWD, filename, LOOKUP_FOLLOW, &old_path, NULL);
4174 + vxdprintk(VXD_CBIT(misc, 2),
4175 + "do_path_lookup(old): %d", ret);
4177 + goto out_free_path;
4179 + dump_path("cow (old)", &old_path);
4181 + /* no explicit reference for old_dentry here */
4182 + old_dentry = old_path.dentry;
4184 + mode = old_dentry->d_inode->i_mode;
4185 + to = d_path(&old_path, path, PATH_MAX-2);
4186 + pathlen = strlen(to);
4187 + vxdprintk(VXD_CBIT(misc, 2),
4188 + "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4190 + old_dentry->d_name.len, old_dentry->d_name.name,
4191 + old_dentry->d_name.len);
4193 + to[pathlen + 1] = 0;
4195 + new_dentry = NULL;
4196 + to[pathlen] = pad--;
4198 + if (pad <= '\240')
4201 + vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4203 + /* dir_path will have refs to dentry and mnt */
4204 + to_filename = getname_kernel(to);
4205 + to_filename = filename_parentat(AT_FDCWD, to_filename,
4206 + LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &par_path, &new_qstr, &new_type);
4207 + vxdprintk(VXD_CBIT(misc, 2), "filename_parentat(new): %p", to_filename);
4208 + dump_path("cow (par)", &par_path);
4209 + if (IS_ERR(to_filename))
4212 + vxdprintk(VXD_CBIT(misc, 2), "to_filename refcnt=%d", to_filename->refcnt);
4214 + /* this puppy downs the dir inode mutex if successful.
4215 + dir_path will hold refs to dentry and mnt and
4216 + we'll have write access to the mnt */
4217 + new_dentry = filename_create(AT_FDCWD, to_filename, &dir_path, 0);
4218 + if (!new_dentry || IS_ERR(new_dentry)) {
4219 + path_put(&par_path);
4220 + vxdprintk(VXD_CBIT(misc, 2),
4221 + "filename_create(new) failed with %ld",
4222 + PTR_ERR(new_dentry));
4225 + vxdprintk(VXD_CBIT(misc, 2),
4226 + "filename_create(new): %p [" VS_Q("%.*s") ":%d]",
4228 + new_dentry->d_name.len, new_dentry->d_name.name,
4229 + new_dentry->d_name.len);
4231 + dump_path("cow (dir)", &dir_path);
4233 + /* take a reference on new_dentry */
4236 + /* dentry/mnt refs handed over to new_path */
4237 + new_path = &dir_path;
4239 + /* dentry for old/new dir */
4240 + dir = par_path.dentry;
4242 + /* give up reference on dir */
4243 + dput(new_path->dentry);
4245 + /* new_dentry already has a reference */
4246 + new_path->dentry = new_dentry;
4248 + ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4249 + vxdprintk(VXD_CBIT(misc, 2),
4250 + "vfs_create(new): %d", ret);
4251 + if (ret == -EEXIST) {
4252 + path_put(&par_path);
4253 + inode_unlock(dir->d_inode);
4254 + mnt_drop_write(new_path->mnt);
4255 + path_put(new_path);
4256 + new_dentry = NULL;
4260 + goto out_unlock_new;
4262 + /* the old file went away */
4264 + if ((redo = d_unhashed(old_dentry)))
4265 + goto out_unlock_new;
4267 + /* doesn't change refs for old_path */
4268 + old_file = dentry_open(&old_path, O_RDONLY, current_cred());
4269 + vxdprintk(VXD_CBIT(misc, 2),
4270 + "dentry_open(old): %p", old_file);
4271 + if (IS_ERR(old_file)) {
4272 + ret = PTR_ERR(old_file);
4273 + goto out_unlock_new;
4276 + /* doesn't change refs for new_path */
4277 + new_file = dentry_open(new_path, O_WRONLY, current_cred());
4278 + vxdprintk(VXD_CBIT(misc, 2),
4279 + "dentry_open(new): %p", new_file);
4280 + if (IS_ERR(new_file)) {
4281 + ret = PTR_ERR(new_file);
4282 + goto out_fput_old;
4285 + /* unlock the inode from filename_create() */
4286 + inode_unlock(dir->d_inode);
4288 + /* drop write access to mnt */
4289 + mnt_drop_write(new_path->mnt);
4293 + size = i_size_read(old_file->f_path.dentry->d_inode);
4294 + ret = do_cow_splice(old_file, new_file, size);
4295 + vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4297 + goto out_fput_both;
4298 + } else if (ret < size) {
4300 + goto out_fput_both;
4302 + struct inode *old_inode = old_dentry->d_inode;
4303 + struct inode *new_inode = new_dentry->d_inode;
4304 + struct iattr attr = {
4305 + .ia_uid = old_inode->i_uid,
4306 + .ia_gid = old_inode->i_gid,
4307 + .ia_valid = ATTR_UID | ATTR_GID
4310 + setattr_copy(new_inode, &attr);
4311 + mark_inode_dirty(new_inode);
4314 + /* lock rename mutex */
4315 + mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4317 + /* drop out late */
4319 + if ((redo = d_unhashed(old_dentry)))
4322 + vxdprintk(VXD_CBIT(misc, 2),
4323 + "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4324 + new_dentry->d_name.len, new_dentry->d_name.name,
4325 + new_dentry->d_name.len,
4326 + old_dentry->d_name.len, old_dentry->d_name.name,
4327 + old_dentry->d_name.len);
4328 + ret = vfs_rename(par_path.dentry->d_inode, new_dentry,
4329 + old_dentry->d_parent->d_inode, old_dentry, NULL, 0);
4330 + vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4333 + mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4336 + vxdprintk(VXD_CBIT(misc, 3),
4337 + "fput(new_file=%p[#%ld])", new_file,
4338 + atomic_long_read(&new_file->f_count));
4342 + vxdprintk(VXD_CBIT(misc, 3),
4343 + "fput(old_file=%p[#%ld])", old_file,
4344 + atomic_long_read(&old_file->f_count));
4348 + /* drop references from par_path */
4349 + path_put(&par_path);
4352 + /* unlock the inode from filename_create() */
4353 + inode_unlock(dir->d_inode);
4355 + /* drop write access to mnt */
4356 + mnt_drop_write(new_path->mnt);
4362 + /* error path cleanup */
4363 + vfs_unlink(dir->d_inode, new_dentry, NULL);
4367 + goto out_rel_both;
4369 + /* lookup dentry once again
4370 + old_path will be freed as old_path in out_rel_old */
4371 + ret = filename_lookup(AT_FDCWD, filename, LOOKUP_FOLLOW, &old_path, NULL);
4373 + goto out_rel_both;
4375 + /* drop reference on new_dentry */
4377 + new_dentry = old_path.dentry;
4379 + vxdprintk(VXD_CBIT(misc, 2),
4380 + "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4382 + new_dentry->d_name.len, new_dentry->d_name.name,
4383 + new_dentry->d_name.len);
4386 + dump_path("put (new)", new_path);
4388 + path_put(new_path);
4390 + dump_path("put (old)", &old_path);
4391 + path_put(&old_path);
4397 + new_dentry = ERR_PTR(ret);
4399 + // if (!IS_ERR(filename))
4400 + // putname(filename);
4401 + vxdprintk(VXD_CBIT(misc, 3),
4402 + "cow_break_link returning with %p", new_dentry);
4403 + return new_dentry;
4408 +int vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4411 + struct vfsmount *vmnt;
4412 + char *pstr, *root;
4415 + pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4419 + vmnt = &ns->root->mnt;
4421 + path.dentry = vmnt->mnt_root;
4422 + root = d_path(&path, pstr, PATH_MAX - 2);
4423 + length = sprintf(buffer + length,
4424 + "Namespace:\t%p [#%u]\n"
4425 + "RootPath:\t%s\n",
4426 + ns, atomic_read(&ns->count),
4432 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4434 /* get the link contents into pagecache */
4435 const char *page_get_link(struct dentry *dentry, struct inode *inode,
4436 struct delayed_call *callback)
4437 diff -NurpP --minimal linux-4.9.76/fs/namespace.c linux-4.9.76-vs2.3.9.5/fs/namespace.c
4438 --- linux-4.9.76/fs/namespace.c 2018-01-13 21:28:57.000000000 +0000
4439 +++ linux-4.9.76-vs2.3.9.5/fs/namespace.c 2018-01-13 01:17:24.000000000 +0000
4441 #include <linux/magic.h>
4442 #include <linux/bootmem.h>
4443 #include <linux/task_work.h>
4444 +#include <linux/vs_base.h>
4445 +#include <linux/vs_context.h>
4446 +#include <linux/vs_tag.h>
4447 +#include <linux/vserver/space.h>
4448 +#include <linux/vserver/global.h>
4450 #include "internal.h"
4452 @@ -971,6 +976,10 @@ vfs_kern_mount(struct file_system_type *
4454 return ERR_PTR(-ENODEV);
4456 + if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4457 + !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4458 + return ERR_PTR(-EPERM);
4460 mnt = alloc_vfsmnt(name);
4462 return ERR_PTR(-ENOMEM);
4463 @@ -1061,6 +1070,7 @@ static struct mount *clone_mnt(struct mo
4464 mnt->mnt.mnt_root = dget(root);
4465 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4466 mnt->mnt_parent = mnt;
4467 + mnt->mnt_tag = old->mnt_tag;
4469 list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4470 unlock_mount_hash();
4471 @@ -1635,7 +1645,8 @@ out_unlock:
4473 static inline bool may_mount(void)
4475 - return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4476 + return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4477 + CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4480 static inline bool may_mandlock(void)
4481 @@ -2144,6 +2155,7 @@ static int do_change_type(struct path *p
4485 + // mnt->mnt_flags = mnt_flags;
4488 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4489 @@ -2172,12 +2184,14 @@ static bool has_locked_children(struct m
4490 * do loopback mount.
4492 static int do_loopback(struct path *path, const char *old_name,
4494 + vtag_t tag, unsigned long flags, int mnt_flags)
4496 struct path old_path;
4497 struct mount *mnt = NULL, *old, *parent;
4498 struct mountpoint *mp;
4499 + int recurse = flags & MS_REC;
4502 if (!old_name || !*old_name)
4504 err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4505 @@ -2257,7 +2271,7 @@ static int change_mount_flags(struct vfs
4506 * on it - tough luck.
4508 static int do_remount(struct path *path, int flags, int mnt_flags,
4510 + void *data, vxid_t xid)
4513 struct super_block *sb = path->mnt->mnt_sb;
4514 @@ -2742,6 +2756,7 @@ long do_mount(const char *dev_name, cons
4521 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4522 @@ -2769,6 +2784,12 @@ long do_mount(const char *dev_name, cons
4523 if (!(flags & MS_NOATIME))
4524 mnt_flags |= MNT_RELATIME;
4526 + if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4527 + /* FIXME: bind and re-mounts get the tag flag? */
4528 + if (flags & (MS_BIND|MS_REMOUNT))
4529 + flags |= MS_TAGID;
4532 /* Separate the per-mountpoint flags */
4533 if (flags & MS_NOSUID)
4534 mnt_flags |= MNT_NOSUID;
4535 @@ -2793,15 +2814,18 @@ long do_mount(const char *dev_name, cons
4536 mnt_flags |= path.mnt->mnt_flags & MNT_ATIME_MASK;
4539 + if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4540 + mnt_flags |= MNT_NODEV;
4542 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4543 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4544 MS_STRICTATIME | MS_NOREMOTELOCK | MS_SUBMOUNT);
4546 if (flags & MS_REMOUNT)
4547 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4550 else if (flags & MS_BIND)
4551 - retval = do_loopback(&path, dev_name, flags & MS_REC);
4552 + retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4553 else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4554 retval = do_change_type(&path, flags);
4555 else if (flags & MS_MOVE)
4556 @@ -2942,6 +2966,7 @@ struct mnt_namespace *copy_mnt_ns(unsign
4557 p = next_mnt(p, old);
4560 + atomic_inc(&vs_global_mnt_ns);
4564 @@ -3117,9 +3142,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4565 new_mnt = real_mount(new.mnt);
4566 root_mnt = real_mount(root.mnt);
4567 old_mnt = real_mount(old.mnt);
4568 - if (IS_MNT_SHARED(old_mnt) ||
4569 + if ((IS_MNT_SHARED(old_mnt) ||
4570 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4571 - IS_MNT_SHARED(root_mnt->mnt_parent))
4572 + IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4573 + !vx_flags(VXF_STATE_SETUP, 0))
4575 if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4577 @@ -3257,6 +3283,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4578 if (!atomic_dec_and_test(&ns->count))
4580 drop_collected_mounts(&ns->root->mnt);
4581 + atomic_dec(&vs_global_mnt_ns);
4585 diff -NurpP --minimal linux-4.9.76/fs/nfs/client.c linux-4.9.76-vs2.3.9.5/fs/nfs/client.c
4586 --- linux-4.9.76/fs/nfs/client.c 2016-12-11 19:17:54.000000000 +0000
4587 +++ linux-4.9.76-vs2.3.9.5/fs/nfs/client.c 2018-01-10 02:50:49.000000000 +0000
4588 @@ -586,6 +586,9 @@ int nfs_init_server_rpcclient(struct nfs
4589 if (server->flags & NFS_MOUNT_SOFT)
4590 server->client->cl_softrtry = 1;
4592 + server->client->cl_tag = 0;
4593 + if (server->flags & NFS_MOUNT_TAGGED)
4594 + server->client->cl_tag = 1;
4597 EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4598 @@ -762,6 +765,10 @@ static void nfs_server_set_fsinfo(struct
4599 server->acdirmin = server->acdirmax = 0;
4602 + /* FIXME: needs fsinfo
4603 + if (server->flags & NFS_MOUNT_TAGGED)
4604 + sb->s_flags |= MS_TAGGED; */
4606 server->maxfilesize = fsinfo->maxfilesize;
4608 server->time_delta = fsinfo->time_delta;
4609 diff -NurpP --minimal linux-4.9.76/fs/nfs/dir.c linux-4.9.76-vs2.3.9.5/fs/nfs/dir.c
4610 --- linux-4.9.76/fs/nfs/dir.c 2018-01-13 21:28:57.000000000 +0000
4611 +++ linux-4.9.76-vs2.3.9.5/fs/nfs/dir.c 2018-01-10 02:50:49.000000000 +0000
4613 #include <linux/sched.h>
4614 #include <linux/kmemleak.h>
4615 #include <linux/xattr.h>
4616 +#include <linux/vs_tag.h>
4618 #include "delegation.h"
4620 @@ -1420,6 +1421,7 @@ struct dentry *nfs_lookup(struct inode *
4621 /* Success: notify readdir to use READDIRPLUS */
4622 nfs_advise_use_readdirplus(dir);
4624 + dx_propagate_tag(nd, inode);
4626 res = d_splice_alias(inode, dentry);
4628 diff -NurpP --minimal linux-4.9.76/fs/nfs/inode.c linux-4.9.76-vs2.3.9.5/fs/nfs/inode.c
4629 --- linux-4.9.76/fs/nfs/inode.c 2018-01-13 21:28:57.000000000 +0000
4630 +++ linux-4.9.76-vs2.3.9.5/fs/nfs/inode.c 2018-01-10 02:50:49.000000000 +0000
4632 #include <linux/slab.h>
4633 #include <linux/compat.h>
4634 #include <linux/freezer.h>
4635 +#include <linux/vs_tag.h>
4637 #include <asm/uaccess.h>
4639 @@ -383,6 +384,8 @@ nfs_fhget(struct super_block *sb, struct
4640 if (inode->i_state & I_NEW) {
4641 struct nfs_inode *nfsi = NFS_I(inode);
4642 unsigned long now = jiffies;
4646 /* We set i_ino for the few things that still rely on it,
4647 * such as stat(2) */
4648 @@ -427,8 +430,8 @@ nfs_fhget(struct super_block *sb, struct
4649 inode->i_version = 0;
4652 - inode->i_uid = make_kuid(&init_user_ns, -2);
4653 - inode->i_gid = make_kgid(&init_user_ns, -2);
4654 + kuid = make_kuid(&init_user_ns, -2);
4655 + kgid = make_kgid(&init_user_ns, -2);
4656 inode->i_blocks = 0;
4657 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
4659 @@ -463,11 +466,11 @@ nfs_fhget(struct super_block *sb, struct
4660 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
4661 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
4662 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
4663 - inode->i_uid = fattr->uid;
4664 + kuid = fattr->uid;
4665 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
4666 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
4667 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
4668 - inode->i_gid = fattr->gid;
4669 + kgid = fattr->gid;
4670 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
4671 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
4672 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
4673 @@ -478,6 +481,10 @@ nfs_fhget(struct super_block *sb, struct
4675 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
4677 + inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
4678 + inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
4679 + inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
4680 + /* maybe fattr->xid someday */
4682 nfs_setsecurity(inode, fattr, label);
4684 @@ -619,6 +626,8 @@ void nfs_setattr_update_inode(struct ino
4685 inode->i_uid = attr->ia_uid;
4686 if ((attr->ia_valid & ATTR_GID) != 0)
4687 inode->i_gid = attr->ia_gid;
4688 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4689 + inode->i_tag = attr->ia_tag;
4690 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ACCESS
4691 | NFS_INO_INVALID_ACL);
4693 @@ -1272,7 +1281,9 @@ static int nfs_check_inode_attributes(st
4694 struct nfs_inode *nfsi = NFS_I(inode);
4695 loff_t cur_size, new_isize;
4696 unsigned long invalid = 0;
4702 if (nfs_have_delegated_attributes(inode))
4704 @@ -1301,13 +1312,18 @@ static int nfs_check_inode_attributes(st
4708 + kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
4709 + kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
4710 + ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
4712 /* Have any file permissions changed? */
4713 if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
4714 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
4715 - if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
4716 + if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
4717 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
4718 - if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
4719 + if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
4720 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
4721 + /* maybe check for tag too? */
4723 /* Has the link count changed? */
4724 if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
4725 @@ -1666,6 +1682,9 @@ static int nfs_update_inode(struct inode
4726 unsigned long save_cache_validity;
4727 bool have_writers = nfs_file_has_buffered_writers(nfsi);
4728 bool cache_revalidated = true;
4733 dfprintk(VFS, "NFS: %s(%s/%lu fh_crc=0x%08x ct=%d info=0x%x)\n",
4734 __func__, inode->i_sb->s_id, inode->i_ino,
4735 @@ -1785,6 +1804,9 @@ static int nfs_update_inode(struct inode
4736 cache_revalidated = false;
4739 + kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4740 + kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4741 + ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
4743 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
4744 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
4745 @@ -1839,6 +1861,10 @@ static int nfs_update_inode(struct inode
4746 cache_revalidated = false;
4749 + inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
4750 + inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
4751 + inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
4753 if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
4754 if (inode->i_nlink != fattr->nlink) {
4755 invalid |= NFS_INO_INVALID_ATTR;
4756 diff -NurpP --minimal linux-4.9.76/fs/nfs/nfs3xdr.c linux-4.9.76-vs2.3.9.5/fs/nfs/nfs3xdr.c
4757 --- linux-4.9.76/fs/nfs/nfs3xdr.c 2016-12-11 19:17:54.000000000 +0000
4758 +++ linux-4.9.76-vs2.3.9.5/fs/nfs/nfs3xdr.c 2018-01-10 02:50:49.000000000 +0000
4760 #include <linux/nfs3.h>
4761 #include <linux/nfs_fs.h>
4762 #include <linux/nfsacl.h>
4763 +#include <linux/vs_tag.h>
4764 #include "internal.h"
4766 #define NFSDBG_FACILITY NFSDBG_XDR
4767 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
4771 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
4772 +static void encode_sattr3(struct xdr_stream *xdr,
4773 + const struct iattr *attr, int tag)
4777 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
4781 - if (attr->ia_valid & ATTR_UID) {
4782 + if (attr->ia_valid & ATTR_UID ||
4783 + (tag && (attr->ia_valid & ATTR_TAG))) {
4785 - *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
4786 + *p++ = cpu_to_be32(from_kuid(&init_user_ns,
4787 + TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
4791 - if (attr->ia_valid & ATTR_GID) {
4792 + if (attr->ia_valid & ATTR_GID ||
4793 + (tag && (attr->ia_valid & ATTR_TAG))) {
4795 - *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
4796 + *p++ = cpu_to_be32(from_kgid(&init_user_ns,
4797 + TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
4801 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
4802 const struct nfs3_sattrargs *args)
4804 encode_nfs_fh3(xdr, args->fh);
4805 - encode_sattr3(xdr, args->sattr);
4806 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
4807 encode_sattrguard3(xdr, args);
4810 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
4813 static void encode_createhow3(struct xdr_stream *xdr,
4814 - const struct nfs3_createargs *args)
4815 + const struct nfs3_createargs *args, int tag)
4817 encode_uint32(xdr, args->createmode);
4818 switch (args->createmode) {
4819 case NFS3_CREATE_UNCHECKED:
4820 case NFS3_CREATE_GUARDED:
4821 - encode_sattr3(xdr, args->sattr);
4822 + encode_sattr3(xdr, args->sattr, tag);
4824 case NFS3_CREATE_EXCLUSIVE:
4825 encode_createverf3(xdr, args->verifier);
4826 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
4827 const struct nfs3_createargs *args)
4829 encode_diropargs3(xdr, args->fh, args->name, args->len);
4830 - encode_createhow3(xdr, args);
4831 + encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
4835 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
4836 const struct nfs3_mkdirargs *args)
4838 encode_diropargs3(xdr, args->fh, args->name, args->len);
4839 - encode_sattr3(xdr, args->sattr);
4840 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
4844 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
4847 static void encode_symlinkdata3(struct xdr_stream *xdr,
4848 - const struct nfs3_symlinkargs *args)
4849 + const struct nfs3_symlinkargs *args, int tag)
4851 - encode_sattr3(xdr, args->sattr);
4852 + encode_sattr3(xdr, args->sattr, tag);
4853 encode_nfspath3(xdr, args->pages, args->pathlen);
4856 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
4857 const struct nfs3_symlinkargs *args)
4859 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
4860 - encode_symlinkdata3(xdr, args);
4861 + encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
4862 xdr->buf->flags |= XDRBUF_WRITE;
4865 @@ -1131,24 +1137,24 @@ static void nfs3_xdr_enc_symlink3args(st
4868 static void encode_devicedata3(struct xdr_stream *xdr,
4869 - const struct nfs3_mknodargs *args)
4870 + const struct nfs3_mknodargs *args, int tag)
4872 - encode_sattr3(xdr, args->sattr);
4873 + encode_sattr3(xdr, args->sattr, tag);
4874 encode_specdata3(xdr, args->rdev);
4877 static void encode_mknoddata3(struct xdr_stream *xdr,
4878 - const struct nfs3_mknodargs *args)
4879 + const struct nfs3_mknodargs *args, int tag)
4881 encode_ftype3(xdr, args->type);
4882 switch (args->type) {
4885 - encode_devicedata3(xdr, args);
4886 + encode_devicedata3(xdr, args, tag);
4890 - encode_sattr3(xdr, args->sattr);
4891 + encode_sattr3(xdr, args->sattr, tag);
4895 @@ -1163,7 +1169,7 @@ static void nfs3_xdr_enc_mknod3args(stru
4896 const struct nfs3_mknodargs *args)
4898 encode_diropargs3(xdr, args->fh, args->name, args->len);
4899 - encode_mknoddata3(xdr, args);
4900 + encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
4904 diff -NurpP --minimal linux-4.9.76/fs/nfs/super.c linux-4.9.76-vs2.3.9.5/fs/nfs/super.c
4905 --- linux-4.9.76/fs/nfs/super.c 2018-01-13 21:28:57.000000000 +0000
4906 +++ linux-4.9.76-vs2.3.9.5/fs/nfs/super.c 2018-01-10 02:50:49.000000000 +0000
4908 #include <linux/parser.h>
4909 #include <linux/nsproxy.h>
4910 #include <linux/rcupdate.h>
4911 +#include <linux/vs_tag.h>
4913 #include <asm/uaccess.h>
4915 @@ -102,6 +103,7 @@ enum {
4921 /* Mount options that take string arguments */
4923 @@ -114,6 +116,9 @@ enum {
4924 /* Special mount options */
4925 Opt_userspace, Opt_deprecated, Opt_sloppy,
4927 + /* Linux-VServer tagging options */
4928 + Opt_tag, Opt_notag,
4933 @@ -183,6 +188,10 @@ static const match_table_t nfs_mount_opt
4934 { Opt_fscache_uniq, "fsc=%s" },
4935 { Opt_local_lock, "local_lock=%s" },
4937 + { Opt_tag, "tag" },
4938 + { Opt_notag, "notag" },
4939 + { Opt_tagid, "tagid=%u" },
4941 /* The following needs to be listed after all other options */
4942 { Opt_nfsvers, "v%s" },
4944 @@ -644,6 +653,7 @@ static void nfs_show_mount_options(struc
4945 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
4946 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
4947 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
4948 + { NFS_MOUNT_TAGGED, ",tag", "" },
4951 const struct proc_nfs_info *nfs_infop;
4952 @@ -1341,6 +1351,14 @@ static int nfs_parse_mount_options(char
4953 case Opt_nomigration:
4954 mnt->options &= ~NFS_OPTION_MIGRATION;
4956 +#ifndef CONFIG_TAGGING_NONE
4958 + mnt->flags |= NFS_MOUNT_TAGGED;
4961 + mnt->flags &= ~NFS_MOUNT_TAGGED;
4966 * options that take numeric values
4967 @@ -1427,6 +1445,12 @@ static int nfs_parse_mount_options(char
4968 goto out_invalid_value;
4969 mnt->minorversion = option;
4971 +#ifdef CONFIG_PROPAGATE
4974 + nfs_data.flags |= NFS_MOUNT_TAGGED;
4979 * options that take text values
4980 diff -NurpP --minimal linux-4.9.76/fs/nfsd/auth.c linux-4.9.76-vs2.3.9.5/fs/nfsd/auth.c
4981 --- linux-4.9.76/fs/nfsd/auth.c 2018-01-13 21:28:57.000000000 +0000
4982 +++ linux-4.9.76-vs2.3.9.5/fs/nfsd/auth.c 2018-01-13 21:30:31.000000000 +0000
4984 /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
4986 #include <linux/sched.h>
4987 +#include <linux/vs_tag.h>
4991 @@ -35,6 +36,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
4993 new->fsuid = rqstp->rq_cred.cr_uid;
4994 new->fsgid = rqstp->rq_cred.cr_gid;
4995 + /* FIXME: this desperately needs a tag :)
4996 + new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
4999 rqgi = rqstp->rq_cred.cr_group_info;
5001 diff -NurpP --minimal linux-4.9.76/fs/nfsd/nfs3xdr.c linux-4.9.76-vs2.3.9.5/fs/nfsd/nfs3xdr.c
5002 --- linux-4.9.76/fs/nfsd/nfs3xdr.c 2018-01-13 21:28:57.000000000 +0000
5003 +++ linux-4.9.76-vs2.3.9.5/fs/nfsd/nfs3xdr.c 2018-01-10 02:50:49.000000000 +0000
5006 #include <linux/namei.h>
5007 #include <linux/sunrpc/svc_xprt.h>
5008 +#include <linux/vs_tag.h>
5012 @@ -98,6 +99,8 @@ static __be32 *
5013 decode_sattr3(__be32 *p, struct iattr *iap)
5016 + kuid_t kuid = GLOBAL_ROOT_UID;
5017 + kgid_t kgid = GLOBAL_ROOT_GID;
5021 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5022 iap->ia_mode = ntohl(*p++);
5025 - iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5026 + kuid = make_kuid(&init_user_ns, ntohl(*p++));
5027 if (uid_valid(iap->ia_uid))
5028 iap->ia_valid |= ATTR_UID;
5031 - iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5032 + kgid = make_kgid(&init_user_ns, ntohl(*p++));
5033 if (gid_valid(iap->ia_gid))
5034 iap->ia_valid |= ATTR_GID;
5036 + iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5037 + iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5038 + iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5042 @@ -167,8 +173,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5043 *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5044 *p++ = htonl((u32) (stat->mode & S_IALLUGO));
5045 *p++ = htonl((u32) stat->nlink);
5046 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5047 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5048 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5049 + TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5050 + stat->uid, stat->tag)));
5051 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5052 + TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5053 + stat->gid, stat->tag)));
5054 if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5055 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5057 diff -NurpP --minimal linux-4.9.76/fs/nfsd/nfs4xdr.c linux-4.9.76-vs2.3.9.5/fs/nfsd/nfs4xdr.c
5058 --- linux-4.9.76/fs/nfsd/nfs4xdr.c 2018-01-13 21:28:58.000000000 +0000
5059 +++ linux-4.9.76-vs2.3.9.5/fs/nfsd/nfs4xdr.c 2018-01-10 02:50:49.000000000 +0000
5061 #include <linux/utsname.h>
5062 #include <linux/pagemap.h>
5063 #include <linux/sunrpc/svcauth_gss.h>
5064 +#include <linux/vs_tag.h>
5068 @@ -2677,12 +2678,16 @@ out_acl:
5069 *p++ = cpu_to_be32(stat.nlink);
5071 if (bmval1 & FATTR4_WORD1_OWNER) {
5072 - status = nfsd4_encode_user(xdr, rqstp, stat.uid);
5073 + status = nfsd4_encode_user(xdr, rqstp,
5074 + TAGINO_KUID(DX_TAG(dentry->d_inode),
5075 + stat.uid, stat.tag));
5079 if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5080 - status = nfsd4_encode_group(xdr, rqstp, stat.gid);
5081 + status = nfsd4_encode_group(xdr, rqstp,
5082 + TAGINO_KGID(DX_TAG(dentry->d_inode),
5083 + stat.gid, stat.tag));
5087 diff -NurpP --minimal linux-4.9.76/fs/nfsd/nfsxdr.c linux-4.9.76-vs2.3.9.5/fs/nfsd/nfsxdr.c
5088 --- linux-4.9.76/fs/nfsd/nfsxdr.c 2018-01-13 21:28:58.000000000 +0000
5089 +++ linux-4.9.76-vs2.3.9.5/fs/nfsd/nfsxdr.c 2018-01-10 02:50:49.000000000 +0000
5094 +#include <linux/vs_tag.h>
5096 #define NFSDDBG_FACILITY NFSDDBG_XDR
5098 @@ -89,6 +90,8 @@ static __be32 *
5099 decode_sattr(__be32 *p, struct iattr *iap)
5102 + kuid_t kuid = GLOBAL_ROOT_UID;
5103 + kgid_t kgid = GLOBAL_ROOT_GID;
5107 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5110 if ((tmp = ntohl(*p++)) != (u32)-1) {
5111 - iap->ia_uid = make_kuid(&init_user_ns, tmp);
5112 + kuid = make_kuid(&init_user_ns, tmp);
5113 if (uid_valid(iap->ia_uid))
5114 iap->ia_valid |= ATTR_UID;
5116 if ((tmp = ntohl(*p++)) != (u32)-1) {
5117 - iap->ia_gid = make_kgid(&init_user_ns, tmp);
5118 + kgid = make_kgid(&init_user_ns, tmp);
5119 if (gid_valid(iap->ia_gid))
5120 iap->ia_valid |= ATTR_GID;
5122 + iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5123 + iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5124 + iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5125 if ((tmp = ntohl(*p++)) != (u32)-1) {
5126 iap->ia_valid |= ATTR_SIZE;
5128 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5129 *p++ = htonl(nfs_ftypes[type >> 12]);
5130 *p++ = htonl((u32) stat->mode);
5131 *p++ = htonl((u32) stat->nlink);
5132 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5133 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5134 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5135 + TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5136 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5137 + TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5139 if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5140 *p++ = htonl(NFS_MAXPATHLEN);
5141 diff -NurpP --minimal linux-4.9.76/fs/ocfs2/dlmglue.c linux-4.9.76-vs2.3.9.5/fs/ocfs2/dlmglue.c
5142 --- linux-4.9.76/fs/ocfs2/dlmglue.c 2018-01-13 21:28:58.000000000 +0000
5143 +++ linux-4.9.76-vs2.3.9.5/fs/ocfs2/dlmglue.c 2018-01-10 02:50:49.000000000 +0000
5144 @@ -2120,6 +2120,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5145 lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5146 lvb->lvb_iuid = cpu_to_be32(i_uid_read(inode));
5147 lvb->lvb_igid = cpu_to_be32(i_gid_read(inode));
5148 + lvb->lvb_itag = cpu_to_be16(i_tag_read(inode));
5149 lvb->lvb_imode = cpu_to_be16(inode->i_mode);
5150 lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
5151 lvb->lvb_iatime_packed =
5152 @@ -2170,6 +2171,7 @@ static void ocfs2_refresh_inode_from_lvb
5154 i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5155 i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5156 + i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5157 inode->i_mode = be16_to_cpu(lvb->lvb_imode);
5158 set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5159 ocfs2_unpack_timespec(&inode->i_atime,
5160 diff -NurpP --minimal linux-4.9.76/fs/ocfs2/dlmglue.h linux-4.9.76-vs2.3.9.5/fs/ocfs2/dlmglue.h
5161 --- linux-4.9.76/fs/ocfs2/dlmglue.h 2018-01-13 21:28:58.000000000 +0000
5162 +++ linux-4.9.76-vs2.3.9.5/fs/ocfs2/dlmglue.h 2018-01-10 02:50:49.000000000 +0000
5163 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5166 __be32 lvb_igeneration;
5167 - __be32 lvb_reserved2;
5169 + __be16 lvb_reserved2;
5172 #define OCFS2_QINFO_LVB_VERSION 1
5173 diff -NurpP --minimal linux-4.9.76/fs/ocfs2/file.c linux-4.9.76-vs2.3.9.5/fs/ocfs2/file.c
5174 --- linux-4.9.76/fs/ocfs2/file.c 2018-01-13 21:28:58.000000000 +0000
5175 +++ linux-4.9.76-vs2.3.9.5/fs/ocfs2/file.c 2018-01-10 02:50:49.000000000 +0000
5176 @@ -1151,7 +1151,7 @@ int ocfs2_setattr(struct dentry *dentry,
5177 attr->ia_valid &= ~ATTR_SIZE;
5179 #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5180 - | ATTR_GID | ATTR_UID | ATTR_MODE)
5181 + | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5182 if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5185 diff -NurpP --minimal linux-4.9.76/fs/ocfs2/inode.c linux-4.9.76-vs2.3.9.5/fs/ocfs2/inode.c
5186 --- linux-4.9.76/fs/ocfs2/inode.c 2016-12-11 19:17:54.000000000 +0000
5187 +++ linux-4.9.76-vs2.3.9.5/fs/ocfs2/inode.c 2018-01-10 02:50:49.000000000 +0000
5189 #include <linux/highmem.h>
5190 #include <linux/pagemap.h>
5191 #include <linux/quotaops.h>
5192 +#include <linux/vs_tag.h>
5194 #include <asm/byteorder.h>
5196 @@ -87,11 +88,13 @@ void ocfs2_set_inode_flags(struct inode
5198 unsigned int flags = OCFS2_I(inode)->ip_attr;
5200 - inode->i_flags &= ~(S_IMMUTABLE |
5201 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5202 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5204 if (flags & OCFS2_IMMUTABLE_FL)
5205 inode->i_flags |= S_IMMUTABLE;
5206 + if (flags & OCFS2_IXUNLINK_FL)
5207 + inode->i_flags |= S_IXUNLINK;
5209 if (flags & OCFS2_SYNC_FL)
5210 inode->i_flags |= S_SYNC;
5211 @@ -101,25 +104,44 @@ void ocfs2_set_inode_flags(struct inode
5212 inode->i_flags |= S_NOATIME;
5213 if (flags & OCFS2_DIRSYNC_FL)
5214 inode->i_flags |= S_DIRSYNC;
5216 + inode->i_vflags &= ~(V_BARRIER | V_COW);
5218 + if (flags & OCFS2_BARRIER_FL)
5219 + inode->i_vflags |= V_BARRIER;
5220 + if (flags & OCFS2_COW_FL)
5221 + inode->i_vflags |= V_COW;
5224 /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5225 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5227 unsigned int flags = oi->vfs_inode.i_flags;
5228 + unsigned int vflags = oi->vfs_inode.i_vflags;
5230 + oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5231 + OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5232 + OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5233 + OCFS2_BARRIER_FL | OCFS2_COW_FL);
5235 + if (flags & S_IMMUTABLE)
5236 + oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5237 + if (flags & S_IXUNLINK)
5238 + oi->ip_attr |= OCFS2_IXUNLINK_FL;
5240 - oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5241 - OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5243 oi->ip_attr |= OCFS2_SYNC_FL;
5244 if (flags & S_APPEND)
5245 oi->ip_attr |= OCFS2_APPEND_FL;
5246 - if (flags & S_IMMUTABLE)
5247 - oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5248 if (flags & S_NOATIME)
5249 oi->ip_attr |= OCFS2_NOATIME_FL;
5250 if (flags & S_DIRSYNC)
5251 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5253 + if (vflags & V_BARRIER)
5254 + oi->ip_attr |= OCFS2_BARRIER_FL;
5255 + if (vflags & V_COW)
5256 + oi->ip_attr |= OCFS2_COW_FL;
5259 struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5260 @@ -278,6 +300,8 @@ void ocfs2_populate_inode(struct inode *
5261 struct super_block *sb;
5262 struct ocfs2_super *osb;
5269 @@ -306,8 +330,12 @@ void ocfs2_populate_inode(struct inode *
5270 inode->i_generation = le32_to_cpu(fe->i_generation);
5271 inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5272 inode->i_mode = le16_to_cpu(fe->i_mode);
5273 - i_uid_write(inode, le32_to_cpu(fe->i_uid));
5274 - i_gid_write(inode, le32_to_cpu(fe->i_gid));
5275 + uid = le32_to_cpu(fe->i_uid);
5276 + gid = le32_to_cpu(fe->i_gid);
5277 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5278 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5279 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5280 + /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5282 /* Fast symlinks will have i_size but no allocated clusters. */
5283 if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5284 diff -NurpP --minimal linux-4.9.76/fs/ocfs2/inode.h linux-4.9.76-vs2.3.9.5/fs/ocfs2/inode.h
5285 --- linux-4.9.76/fs/ocfs2/inode.h 2016-12-11 19:17:54.000000000 +0000
5286 +++ linux-4.9.76-vs2.3.9.5/fs/ocfs2/inode.h 2018-01-10 02:50:49.000000000 +0000
5287 @@ -155,6 +155,7 @@ int ocfs2_mark_inode_dirty(handle_t *han
5289 void ocfs2_set_inode_flags(struct inode *inode);
5290 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5291 +int ocfs2_sync_flags(struct inode *inode, int, int);
5293 static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5295 diff -NurpP --minimal linux-4.9.76/fs/ocfs2/ioctl.c linux-4.9.76-vs2.3.9.5/fs/ocfs2/ioctl.c
5296 --- linux-4.9.76/fs/ocfs2/ioctl.c 2016-12-11 19:17:54.000000000 +0000
5297 +++ linux-4.9.76-vs2.3.9.5/fs/ocfs2/ioctl.c 2018-01-10 02:50:49.000000000 +0000
5298 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5302 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5303 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5305 + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5306 + struct buffer_head *bh = NULL;
5307 + handle_t *handle = NULL;
5310 + status = ocfs2_inode_lock(inode, &bh, 1);
5312 + mlog_errno(status);
5315 + handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5316 + if (IS_ERR(handle)) {
5317 + status = PTR_ERR(handle);
5318 + mlog_errno(status);
5322 + inode->i_flags = flags;
5323 + inode->i_vflags = vflags;
5324 + ocfs2_get_inode_flags(OCFS2_I(inode));
5326 + status = ocfs2_mark_inode_dirty(handle, inode, bh);
5328 + mlog_errno(status);
5330 + ocfs2_commit_trans(osb, handle);
5332 + ocfs2_inode_unlock(inode, 1);
5337 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5340 struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5341 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5345 + if (IS_BARRIER(inode)) {
5346 + vxwprintk_task(1, "messing with the barrier.");
5350 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5351 if (IS_ERR(handle)) {
5352 status = PTR_ERR(handle);
5353 @@ -839,6 +878,7 @@ bail:
5358 long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5360 struct inode *inode = file_inode(filp);
5361 diff -NurpP --minimal linux-4.9.76/fs/ocfs2/namei.c linux-4.9.76-vs2.3.9.5/fs/ocfs2/namei.c
5362 --- linux-4.9.76/fs/ocfs2/namei.c 2016-12-11 19:17:54.000000000 +0000
5363 +++ linux-4.9.76-vs2.3.9.5/fs/ocfs2/namei.c 2018-01-10 02:50:49.000000000 +0000
5365 #include <linux/slab.h>
5366 #include <linux/highmem.h>
5367 #include <linux/quotaops.h>
5368 +#include <linux/vs_tag.h>
5370 #include <cluster/masklog.h>
5372 @@ -516,6 +517,7 @@ static int __ocfs2_mknod_locked(struct i
5373 struct ocfs2_extent_list *fel;
5375 struct ocfs2_inode_info *oi = OCFS2_I(inode);
5380 @@ -553,8 +555,13 @@ static int __ocfs2_mknod_locked(struct i
5381 fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5382 fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5383 fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5384 - fe->i_uid = cpu_to_le32(i_uid_read(inode));
5385 - fe->i_gid = cpu_to_le32(i_gid_read(inode));
5387 + ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5388 + fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5389 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5390 + fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5391 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5392 + inode->i_tag = ktag; /* is this correct? */
5393 fe->i_mode = cpu_to_le16(inode->i_mode);
5394 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5395 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5396 diff -NurpP --minimal linux-4.9.76/fs/ocfs2/ocfs2.h linux-4.9.76-vs2.3.9.5/fs/ocfs2/ocfs2.h
5397 --- linux-4.9.76/fs/ocfs2/ocfs2.h 2018-01-13 21:28:58.000000000 +0000
5398 +++ linux-4.9.76-vs2.3.9.5/fs/ocfs2/ocfs2.h 2018-01-10 02:50:49.000000000 +0000
5399 @@ -289,6 +289,7 @@ enum ocfs2_mount_options
5400 OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT = 1 << 15, /* Journal Async Commit */
5401 OCFS2_MOUNT_ERRORS_CONT = 1 << 16, /* Return EIO to the calling process on error */
5402 OCFS2_MOUNT_ERRORS_ROFS = 1 << 17, /* Change filesystem to read-only on error */
5403 + OCFS2_MOUNT_TAGGED = 1 << 18, /* use tagging */
5406 #define OCFS2_OSB_SOFT_RO 0x0001
5407 diff -NurpP --minimal linux-4.9.76/fs/ocfs2/ocfs2_fs.h linux-4.9.76-vs2.3.9.5/fs/ocfs2/ocfs2_fs.h
5408 --- linux-4.9.76/fs/ocfs2/ocfs2_fs.h 2016-12-11 19:17:54.000000000 +0000
5409 +++ linux-4.9.76-vs2.3.9.5/fs/ocfs2/ocfs2_fs.h 2018-01-10 02:50:49.000000000 +0000
5410 @@ -275,6 +275,11 @@
5411 #define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
5412 #define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
5414 +#define OCFS2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
5416 +#define OCFS2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
5417 +#define OCFS2_COW_FL FS_COW_FL /* Copy on Write marker */
5419 #define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
5420 #define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
5422 diff -NurpP --minimal linux-4.9.76/fs/ocfs2/super.c linux-4.9.76-vs2.3.9.5/fs/ocfs2/super.c
5423 --- linux-4.9.76/fs/ocfs2/super.c 2016-12-11 19:17:54.000000000 +0000
5424 +++ linux-4.9.76-vs2.3.9.5/fs/ocfs2/super.c 2018-01-10 02:50:49.000000000 +0000
5425 @@ -188,6 +188,7 @@ enum {
5427 Opt_journal_async_commit,
5429 + Opt_tag, Opt_notag, Opt_tagid,
5433 @@ -221,6 +222,9 @@ static const match_table_t tokens = {
5434 {Opt_dir_resv_level, "dir_resv_level=%u"},
5435 {Opt_journal_async_commit, "journal_async_commit"},
5436 {Opt_err_cont, "errors=continue"},
5438 + {Opt_notag, "notag"},
5439 + {Opt_tagid, "tagid=%u"},
5443 @@ -673,6 +677,13 @@ static int ocfs2_remount(struct super_bl
5447 + if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5448 + (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5450 + mlog(ML_ERROR, "Cannot change tagging on remount\n");
5454 /* We're going to/from readonly mode. */
5455 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5456 /* Disable quota accounting before remounting RO */
5457 @@ -1162,6 +1173,9 @@ static int ocfs2_fill_super(struct super
5459 ocfs2_complete_mount_recovery(osb);
5461 + if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5462 + sb->s_flags |= MS_TAGGED;
5464 if (ocfs2_mount_local(osb))
5465 snprintf(nodestr, sizeof(nodestr), "local");
5467 @@ -1481,6 +1495,20 @@ static int ocfs2_parse_options(struct su
5468 case Opt_journal_async_commit:
5469 mopt->mount_opt |= OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT;
5471 +#ifndef CONFIG_TAGGING_NONE
5473 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5476 + mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5479 +#ifdef CONFIG_PROPAGATE
5482 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5487 "Unrecognized mount option \"%s\" "
5488 diff -NurpP --minimal linux-4.9.76/fs/open.c linux-4.9.76-vs2.3.9.5/fs/open.c
5489 --- linux-4.9.76/fs/open.c 2018-01-13 21:28:58.000000000 +0000
5490 +++ linux-4.9.76-vs2.3.9.5/fs/open.c 2018-01-13 22:17:33.000000000 +0000
5492 #include <linux/ima.h>
5493 #include <linux/dnotify.h>
5494 #include <linux/compat.h>
5495 +#include <linux/vs_base.h>
5496 +#include <linux/vs_limit.h>
5497 +#include <linux/vs_tag.h>
5498 +#include <linux/vs_cowbl.h>
5499 +#include <linux/vserver/dlimit.h>
5501 #include "internal.h"
5503 @@ -65,12 +70,17 @@ int do_truncate(struct dentry *dentry, l
5507 -long vfs_truncate(const struct path *path, loff_t length)
5508 +long vfs_truncate(struct path *path, loff_t length)
5510 struct inode *inode;
5511 struct dentry *upperdentry;
5514 +#ifdef CONFIG_VSERVER_COWBL
5515 + error = cow_check_and_break(path);
5519 inode = path->dentry->d_inode;
5521 /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5522 @@ -565,6 +575,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5523 unsigned int lookup_flags = LOOKUP_FOLLOW;
5525 error = user_path_at(dfd, filename, lookup_flags, &path);
5526 +#ifdef CONFIG_VSERVER_COWBL
5528 + error = cow_check_and_break(&path);
5534 error = chmod_common(&path, mode);
5536 @@ -599,13 +616,15 @@ retry_deleg:
5537 if (!uid_valid(uid))
5539 newattrs.ia_valid |= ATTR_UID;
5540 - newattrs.ia_uid = uid;
5541 + newattrs.ia_uid = make_kuid(&init_user_ns,
5542 + dx_map_uid(user));
5544 if (group != (gid_t) -1) {
5545 if (!gid_valid(gid))
5547 newattrs.ia_valid |= ATTR_GID;
5548 - newattrs.ia_gid = gid;
5549 + newattrs.ia_gid = make_kgid(&init_user_ns,
5550 + dx_map_gid(group));
5552 if (!S_ISDIR(inode->i_mode))
5553 newattrs.ia_valid |=
5554 @@ -643,6 +662,10 @@ retry:
5555 error = mnt_want_write(path.mnt);
5558 +#ifdef CONFIG_VSERVER_COWBL
5559 + error = cow_check_and_break(&path);
5562 error = chown_common(&path, user, group);
5563 mnt_drop_write(path.mnt);
5565 diff -NurpP --minimal linux-4.9.76/fs/proc/array.c linux-4.9.76-vs2.3.9.5/fs/proc/array.c
5566 --- linux-4.9.76/fs/proc/array.c 2018-01-13 21:28:58.000000000 +0000
5567 +++ linux-4.9.76-vs2.3.9.5/fs/proc/array.c 2018-01-13 01:59:39.000000000 +0000
5569 #include <linux/string_helpers.h>
5570 #include <linux/user_namespace.h>
5571 #include <linux/fs_struct.h>
5572 +#include <linux/vs_context.h>
5573 +#include <linux/vs_network.h>
5575 #include <asm/pgtable.h>
5576 #include <asm/processor.h>
5577 @@ -169,6 +171,9 @@ static inline void task_state(struct seq
5578 ppid = pid_alive(p) ?
5579 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5581 + if (unlikely(vx_current_initpid(p->pid)))
5584 tracer = ptrace_parent(p);
5586 tpid = task_pid_nr_ns(tracer, ns);
5587 @@ -306,8 +311,8 @@ static inline void task_sig(struct seq_f
5588 render_sigset_t(m, "SigCgt:\t", &caught);
5591 -static void render_cap_t(struct seq_file *m, const char *header,
5593 +void render_cap_t(struct seq_file *m, const char *header,
5594 + struct vx_info *vxi, kernel_cap_t *a)
5598 @@ -334,11 +339,12 @@ static inline void task_cap(struct seq_f
5599 cap_ambient = cred->cap_ambient;
5602 - render_cap_t(m, "CapInh:\t", &cap_inheritable);
5603 - render_cap_t(m, "CapPrm:\t", &cap_permitted);
5604 - render_cap_t(m, "CapEff:\t", &cap_effective);
5605 - render_cap_t(m, "CapBnd:\t", &cap_bset);
5606 - render_cap_t(m, "CapAmb:\t", &cap_ambient);
5607 + /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5608 + render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5609 + render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5610 + render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5611 + render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5612 + render_cap_t(m, "CapAmb:\t", p->vx_info, &cap_ambient);
5615 static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
5616 @@ -365,6 +371,43 @@ static void task_cpus_allowed(struct seq
5617 cpumask_pr_args(&task->cpus_allowed));
5620 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
5621 + struct pid *pid, struct task_struct *task)
5623 + seq_printf(m, "Proxy:\t%p(%c)\n"
5631 + (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
5632 + atomic_read(&task->nsproxy->count),
5633 + task->nsproxy->uts_ns,
5634 + (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
5635 + task->nsproxy->ipc_ns,
5636 + (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
5637 + task->nsproxy->mnt_ns,
5638 + (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
5639 + task->nsproxy->pid_ns_for_children,
5640 + (task->nsproxy->pid_ns_for_children ==
5641 + init_task.nsproxy->pid_ns_for_children ? 'I' : '-'),
5642 + task->nsproxy->net_ns,
5643 + (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
5647 +void task_vs_id(struct seq_file *m, struct task_struct *task)
5649 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
5652 + seq_printf(m, "VxID:\t%d\n", vx_task_xid(task));
5653 + seq_printf(m, "NxID:\t%d\n", nx_task_nid(task));
5657 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
5658 struct pid *pid, struct task_struct *task)
5660 @@ -382,6 +425,7 @@ int proc_pid_status(struct seq_file *m,
5661 task_seccomp(m, task);
5662 task_cpus_allowed(m, task);
5663 cpuset_task_status_allowed(m, task);
5664 + task_vs_id(m, task);
5665 task_context_switch_counts(m, task);
5668 @@ -494,6 +538,17 @@ static int do_task_stat(struct seq_file
5669 /* convert nsec -> ticks */
5670 start_time = nsec_to_clock_t(task->real_start_time);
5672 + /* fixup start time for virt uptime */
5673 + if (vx_flags(VXF_VIRT_UPTIME, 0)) {
5674 + unsigned long long bias =
5675 + current->vx_info->cvirt.bias_clock;
5677 + if (start_time > bias)
5678 + start_time -= bias;
5683 seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
5684 seq_put_decimal_ll(m, " ", ppid);
5685 seq_put_decimal_ll(m, " ", pgid);
5686 diff -NurpP --minimal linux-4.9.76/fs/proc/base.c linux-4.9.76-vs2.3.9.5/fs/proc/base.c
5687 --- linux-4.9.76/fs/proc/base.c 2018-01-13 21:28:58.000000000 +0000
5688 +++ linux-4.9.76-vs2.3.9.5/fs/proc/base.c 2018-01-13 01:59:11.000000000 +0000
5690 #include <linux/slab.h>
5691 #include <linux/flex_array.h>
5692 #include <linux/posix-timers.h>
5693 +#include <linux/vs_context.h>
5694 +#include <linux/vs_network.h>
5695 #ifdef CONFIG_HARDWALL
5696 #include <asm/hardwall.h>
5698 @@ -1063,10 +1065,15 @@ static int __set_oom_adj(struct file *fi
5699 mutex_lock(&oom_adj_mutex);
5701 if (oom_adj < task->signal->oom_score_adj &&
5702 - !capable(CAP_SYS_RESOURCE)) {
5703 + !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
5708 + /* prevent guest processes from circumventing the oom killer */
5709 + if (vx_current_xid() && (oom_adj == OOM_DISABLE))
5710 + oom_adj = OOM_ADJUST_MIN;
5713 * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
5714 * /proc/pid/oom_score_adj instead.
5715 @@ -1696,6 +1703,8 @@ struct inode *proc_pid_make_inode(struct
5716 inode->i_gid = cred->egid;
5719 + /* procfs is xid tagged */
5720 + i_tag_write(inode, (vtag_t)vx_task_xid(task));
5721 security_task_to_inode(task, inode);
5724 @@ -1741,6 +1750,8 @@ int pid_getattr(struct vfsmount *mnt, st
5728 +// static unsigned name_to_int(struct dentry *dentry);
5731 * Exceptional case: normally we are not allowed to unhash a busy
5732 * directory. In this case, however, we can do it - no aliasing problems
5733 @@ -1769,6 +1780,19 @@ int pid_revalidate(struct dentry *dentry
5734 task = get_proc_task(inode);
5737 + unsigned pid = name_to_int(&dentry->d_name);
5739 + if (pid != ~0U && pid != vx_map_pid(task->pid) &&
5740 + pid != __task_pid_nr_ns(task, PIDTYPE_PID,
5741 + task_active_pid_ns(task))) {
5742 + vxdprintk(VXD_CBIT(misc, 10),
5743 + VS_Q("%*s") " dropped by pid_revalidate(%d!=%d)",
5744 + dentry->d_name.len, dentry->d_name.name,
5745 + pid, vx_map_pid(task->pid));
5746 + put_task_struct(task);
5750 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
5751 task_dumpable(task)) {
5753 @@ -2408,6 +2432,13 @@ static struct dentry *proc_pident_lookup
5757 + /* TODO: maybe we can come up with a generic approach? */
5758 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
5759 + (dentry->d_name.len == 5) &&
5760 + (!memcmp(dentry->d_name.name, "vinfo", 5) ||
5761 + !memcmp(dentry->d_name.name, "ninfo", 5)))
5765 * Yes, it does not scale. And it should not. Don't add
5766 * new entries into /proc/<tgid>/ without very good reasons.
5767 @@ -2847,6 +2878,11 @@ static int proc_pid_personality(struct s
5768 static const struct file_operations proc_task_operations;
5769 static const struct inode_operations proc_task_inode_operations;
5771 +extern int proc_pid_vx_info(struct seq_file *,
5772 + struct pid_namespace *, struct pid *, struct task_struct *);
5773 +extern int proc_pid_nx_info(struct seq_file *,
5774 + struct pid_namespace *, struct pid *, struct task_struct *);
5776 static const struct pid_entry tgid_base_stuff[] = {
5777 DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
5778 DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
5779 @@ -2911,6 +2947,8 @@ static const struct pid_entry tgid_base_
5780 #ifdef CONFIG_CGROUPS
5781 ONE("cgroup", S_IRUGO, proc_cgroup_show),
5783 + ONE("vinfo", S_IRUGO, proc_pid_vx_info),
5784 + ONE("ninfo", S_IRUGO, proc_pid_nx_info),
5785 ONE("oom_score", S_IRUGO, proc_oom_score),
5786 REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations),
5787 REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
5788 @@ -3126,7 +3164,7 @@ retry:
5790 pid = find_ge_pid(iter.tgid, ns);
5792 - iter.tgid = pid_nr_ns(pid, ns);
5793 + iter.tgid = pid_unmapped_nr_ns(pid, ns);
5794 iter.task = pid_task(pid, PIDTYPE_PID);
5795 /* What we to know is if the pid we have find is the
5796 * pid of a thread_group_leader. Testing for task
5797 @@ -3186,8 +3224,10 @@ int proc_pid_readdir(struct file *file,
5798 if (!has_pid_permissions(ns, iter.task, 2))
5801 - len = snprintf(name, sizeof(name), "%d", iter.tgid);
5802 + len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
5803 ctx->pos = iter.tgid + TGID_OFFSET;
5804 + if (!vx_proc_task_visible(iter.task))
5806 if (!proc_fill_cache(file, ctx, name, len,
5807 proc_pid_instantiate, iter.task, NULL)) {
5808 put_task_struct(iter.task);
5809 @@ -3324,6 +3364,7 @@ static const struct pid_entry tid_base_s
5810 REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
5811 REG("setgroups", S_IRUGO|S_IWUSR, proc_setgroups_operations),
5813 + ONE("nsproxy", S_IRUGO, proc_pid_nsproxy),
5816 static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
5817 @@ -3390,6 +3431,8 @@ static struct dentry *proc_task_lookup(s
5818 tid = name_to_int(&dentry->d_name);
5821 + if (vx_current_initpid(tid))
5824 ns = dentry->d_sb->s_fs_info;
5826 diff -NurpP --minimal linux-4.9.76/fs/proc/generic.c linux-4.9.76-vs2.3.9.5/fs/proc/generic.c
5827 --- linux-4.9.76/fs/proc/generic.c 2018-01-13 21:28:58.000000000 +0000
5828 +++ linux-4.9.76-vs2.3.9.5/fs/proc/generic.c 2018-01-10 02:50:49.000000000 +0000
5830 #include <linux/bitops.h>
5831 #include <linux/spinlock.h>
5832 #include <linux/completion.h>
5833 +#include <linux/vserver/inode.h>
5834 #include <asm/uaccess.h>
5836 #include "internal.h"
5837 @@ -66,8 +67,16 @@ static struct proc_dir_entry *pde_subdir
5838 node = node->rb_left;
5839 else if (result > 0)
5840 node = node->rb_right;
5843 + if (!vx_hide_check(0, de->vx_flags)) {
5844 + vxdprintk(VXD_CBIT(misc, 9),
5846 + " hidden in pde_subdir_find()",
5847 + de->namelen, de->name);
5855 @@ -241,6 +250,8 @@ struct dentry *proc_lookup_de(struct pro
5856 return ERR_PTR(-ENOMEM);
5857 d_set_d_op(dentry, &simple_dentry_operations);
5858 d_add(dentry, inode);
5859 + /* generic proc entries belong to the host */
5860 + i_tag_write(inode, 0);
5863 read_unlock(&proc_subdir_lock);
5864 @@ -287,6 +298,12 @@ int proc_readdir_de(struct proc_dir_entr
5866 struct proc_dir_entry *next;
5868 + if (!vx_hide_check(0, de->vx_flags)) {
5869 + vxdprintk(VXD_CBIT(misc, 9),
5870 + VS_Q("%*s") " hidden in proc_readdir_de()",
5871 + de->namelen, de->name);
5874 read_unlock(&proc_subdir_lock);
5875 if (!dir_emit(ctx, de->name, de->namelen,
5876 de->low_ino, de->mode >> 12)) {
5877 @@ -294,6 +311,7 @@ int proc_readdir_de(struct proc_dir_entr
5880 read_lock(&proc_subdir_lock);
5883 next = pde_subdir_next(de);
5885 @@ -387,6 +405,7 @@ static struct proc_dir_entry *__proc_cre
5888 ent->subdir = RB_ROOT;
5889 + ent->vx_flags = IATTR_PROC_DEFAULT;
5890 atomic_set(&ent->count, 1);
5891 spin_lock_init(&ent->pde_unload_lock);
5892 INIT_LIST_HEAD(&ent->pde_openers);
5893 @@ -413,7 +432,8 @@ struct proc_dir_entry *proc_symlink(cons
5899 + ent->vx_flags = IATTR_PROC_SYMLINK;
5903 diff -NurpP --minimal linux-4.9.76/fs/proc/inode.c linux-4.9.76-vs2.3.9.5/fs/proc/inode.c
5904 --- linux-4.9.76/fs/proc/inode.c 2016-12-11 19:17:54.000000000 +0000
5905 +++ linux-4.9.76-vs2.3.9.5/fs/proc/inode.c 2018-01-10 02:50:49.000000000 +0000
5906 @@ -432,6 +432,8 @@ struct inode *proc_get_inode(struct supe
5907 inode->i_uid = de->uid;
5908 inode->i_gid = de->gid;
5911 + PROC_I(inode)->vx_flags = de->vx_flags;
5913 inode->i_size = de->size;
5915 diff -NurpP --minimal linux-4.9.76/fs/proc/internal.h linux-4.9.76-vs2.3.9.5/fs/proc/internal.h
5916 --- linux-4.9.76/fs/proc/internal.h 2016-12-11 19:17:54.000000000 +0000
5917 +++ linux-4.9.76-vs2.3.9.5/fs/proc/internal.h 2018-01-13 01:48:13.000000000 +0000
5919 #include <linux/spinlock.h>
5920 #include <linux/atomic.h>
5921 #include <linux/binfmts.h>
5922 +#include <linux/vs_pid.h>
5924 struct ctl_table_header;
5926 @@ -34,6 +35,7 @@ struct proc_dir_entry {
5932 const struct inode_operations *proc_iops;
5933 const struct file_operations *proc_fops;
5934 @@ -51,15 +53,22 @@ struct proc_dir_entry {
5942 int (*proc_get_link)(struct dentry *, struct path *);
5943 int (*proc_show)(struct seq_file *m,
5944 struct pid_namespace *ns, struct pid *pid,
5945 struct task_struct *task);
5946 + int (*proc_vs_read)(char *page);
5947 + int (*proc_vxi_read)(struct vx_info *vxi, char *page);
5948 + int (*proc_nxi_read)(struct nx_info *nxi, char *page);
5956 struct proc_dir_entry *pde;
5957 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
5958 return PROC_I(inode)->pid;
5961 -static inline struct task_struct *get_proc_task(struct inode *inode)
5962 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
5964 return get_pid_task(proc_pid(inode), PIDTYPE_PID);
5967 +static inline struct task_struct *get_proc_task(struct inode *inode)
5969 + return vx_get_proc_task(inode, proc_pid(inode));
5972 static inline int task_dumpable(struct task_struct *task)
5975 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
5976 struct pid *, struct task_struct *);
5977 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
5978 struct pid *, struct task_struct *);
5979 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
5980 + struct pid *pid, struct task_struct *task);
5984 diff -NurpP --minimal linux-4.9.76/fs/proc/loadavg.c linux-4.9.76-vs2.3.9.5/fs/proc/loadavg.c
5985 --- linux-4.9.76/fs/proc/loadavg.c 2016-12-11 19:17:54.000000000 +0000
5986 +++ linux-4.9.76-vs2.3.9.5/fs/proc/loadavg.c 2018-01-10 02:50:49.000000000 +0000
5989 static int loadavg_proc_show(struct seq_file *m, void *v)
5991 + unsigned long running;
5992 + unsigned int threads;
5993 unsigned long avnrun[3];
5995 get_avenrun(avnrun, FIXED_1/200, 0);
5997 + if (vx_flags(VXF_VIRT_LOAD, 0)) {
5998 + struct vx_info *vxi = current_vx_info();
6000 + running = atomic_read(&vxi->cvirt.nr_running);
6001 + threads = atomic_read(&vxi->cvirt.nr_threads);
6003 + running = nr_running();
6004 + threads = nr_threads;
6007 seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6008 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6009 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6010 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6011 - nr_running(), nr_threads,
6013 task_active_pid_ns(current)->last_pid);
6016 diff -NurpP --minimal linux-4.9.76/fs/proc/meminfo.c linux-4.9.76-vs2.3.9.5/fs/proc/meminfo.c
6017 --- linux-4.9.76/fs/proc/meminfo.c 2016-12-11 19:17:54.000000000 +0000
6018 +++ linux-4.9.76-vs2.3.9.5/fs/proc/meminfo.c 2018-01-13 01:55:40.000000000 +0000
6019 @@ -55,7 +55,8 @@ static int meminfo_proc_show(struct seq_
6021 committed = percpu_counter_read_positive(&vm_committed_as);
6023 - cached = global_node_page_state(NR_FILE_PAGES) -
6024 + cached = vx_flags(VXF_VIRT_MEM, 0) ?
6025 + vx_vsi_cached(&i) : global_node_page_state(NR_FILE_PAGES) -
6026 total_swapcache_pages() - i.bufferram;
6029 diff -NurpP --minimal linux-4.9.76/fs/proc/root.c linux-4.9.76-vs2.3.9.5/fs/proc/root.c
6030 --- linux-4.9.76/fs/proc/root.c 2016-12-11 19:17:54.000000000 +0000
6031 +++ linux-4.9.76-vs2.3.9.5/fs/proc/root.c 2018-01-13 01:48:57.000000000 +0000
6033 #include <linux/mount.h>
6034 #include <linux/pid_namespace.h>
6035 #include <linux/parser.h>
6036 +#include <linux/vserver/inode.h>
6038 #include "internal.h"
6040 +struct proc_dir_entry *proc_virtual;
6042 +extern void proc_vx_init(void);
6045 Opt_gid, Opt_hidepid, Opt_err,
6047 @@ -145,6 +150,7 @@ void __init proc_root_init(void)
6049 proc_mkdir("bus", NULL);
6054 static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6055 @@ -206,6 +212,7 @@ struct proc_dir_entry proc_root = {
6056 .proc_iops = &proc_root_inode_operations,
6057 .proc_fops = &proc_root_operations,
6058 .parent = &proc_root,
6059 + .vx_flags = IATTR_ADMIN | IATTR_WATCH,
6063 diff -NurpP --minimal linux-4.9.76/fs/proc/self.c linux-4.9.76-vs2.3.9.5/fs/proc/self.c
6064 --- linux-4.9.76/fs/proc/self.c 2016-12-11 19:17:54.000000000 +0000
6065 +++ linux-4.9.76-vs2.3.9.5/fs/proc/self.c 2018-01-10 02:50:49.000000000 +0000
6067 #include <linux/sched.h>
6068 #include <linux/slab.h>
6069 #include <linux/pid_namespace.h>
6070 +#include <linux/vserver/inode.h>
6071 #include "internal.h"
6074 @@ -54,6 +55,8 @@ int proc_setup_self(struct super_block *
6075 self = d_alloc_name(s->s_root, "self");
6077 struct inode *inode = new_inode_pseudo(s);
6079 + // self->vx_flags = IATTR_PROC_SYMLINK;
6081 inode->i_ino = self_inum;
6082 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
6083 diff -NurpP --minimal linux-4.9.76/fs/proc/stat.c linux-4.9.76-vs2.3.9.5/fs/proc/stat.c
6084 --- linux-4.9.76/fs/proc/stat.c 2016-12-11 19:17:54.000000000 +0000
6085 +++ linux-4.9.76-vs2.3.9.5/fs/proc/stat.c 2018-01-13 01:47:09.000000000 +0000
6087 #include <linux/slab.h>
6088 #include <linux/time.h>
6089 #include <linux/irqnr.h>
6090 +#include <linux/vserver/cvirt.h>
6091 #include <linux/cputime.h>
6092 #include <linux/tick.h>
6093 +#include <linux/cpuset.h>
6095 #ifndef arch_irq_stat_cpu
6096 #define arch_irq_stat_cpu(cpu) 0
6097 @@ -86,13 +88,24 @@ static int show_stat(struct seq_file *p,
6098 u64 sum_softirq = 0;
6099 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6100 struct timespec64 boottime;
6101 + cpumask_var_t cpus_allowed;
6102 + bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6104 user = nice = system = idle = iowait =
6105 irq = softirq = steal = 0;
6106 guest = guest_nice = 0;
6107 getboottime64(&boottime);
6109 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6110 + vx_vsi_boottime(&boottime);
6113 + cpuset_cpus_allowed(current, cpus_allowed);
6115 for_each_possible_cpu(i) {
6116 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6119 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6120 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6121 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6122 @@ -128,6 +141,9 @@ static int show_stat(struct seq_file *p,
6125 for_each_online_cpu(i) {
6126 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6129 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6130 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6131 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6132 diff -NurpP --minimal linux-4.9.76/fs/proc/uptime.c linux-4.9.76-vs2.3.9.5/fs/proc/uptime.c
6133 --- linux-4.9.76/fs/proc/uptime.c 2016-12-11 19:17:54.000000000 +0000
6134 +++ linux-4.9.76-vs2.3.9.5/fs/proc/uptime.c 2018-01-10 02:50:49.000000000 +0000
6136 #include <linux/seq_file.h>
6137 #include <linux/time.h>
6138 #include <linux/kernel_stat.h>
6139 +#include <linux/vserver/cvirt.h>
6140 #include <linux/cputime.h>
6142 static int uptime_proc_show(struct seq_file *m, void *v)
6143 @@ -24,6 +25,10 @@ static int uptime_proc_show(struct seq_f
6144 nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6145 idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6148 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6149 + vx_vsi_uptime(&uptime, &idle);
6151 seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6152 (unsigned long) uptime.tv_sec,
6153 (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6154 diff -NurpP --minimal linux-4.9.76/fs/proc_namespace.c linux-4.9.76-vs2.3.9.5/fs/proc_namespace.c
6155 --- linux-4.9.76/fs/proc_namespace.c 2016-12-11 19:17:54.000000000 +0000
6156 +++ linux-4.9.76-vs2.3.9.5/fs/proc_namespace.c 2018-01-10 02:50:49.000000000 +0000
6157 @@ -46,6 +46,8 @@ static int show_sb_opts(struct seq_file
6158 { MS_DIRSYNC, ",dirsync" },
6159 { MS_MANDLOCK, ",mand" },
6160 { MS_LAZYTIME, ",lazytime" },
6161 + { MS_TAGGED, ",tag" },
6162 + { MS_NOTAGCHECK, ",notagcheck" },
6165 const struct proc_fs_info *fs_infop;
6166 @@ -82,6 +84,38 @@ static inline void mangle(struct seq_fil
6167 seq_escape(m, s, " \t\n\\");
6170 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6172 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6175 + struct dentry *point;
6176 + struct mount *mnt = real_mount(vfsmnt);
6177 + struct mount *root_mnt;
6180 + if (mnt == mnt->mnt_ns->root)
6184 + root = current->fs->root;
6185 + root_mnt = real_mount(root.mnt);
6186 + point = root.dentry;
6188 + while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6189 + point = mnt->mnt_mountpoint;
6190 + mnt = mnt->mnt_parent;
6192 + rcu_read_unlock();
6194 + ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6199 +#define mnt_is_reachable(v) (1)
6202 static void show_type(struct seq_file *m, struct super_block *sb)
6204 mangle(m, sb->s_type->name);
6205 @@ -99,6 +133,17 @@ static int show_vfsmnt(struct seq_file *
6206 struct super_block *sb = mnt_path.dentry->d_sb;
6209 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6211 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6214 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6215 + mnt == current->fs->root.mnt) {
6216 + seq_puts(m, "/dev/root / ");
6220 if (sb->s_op->show_devname) {
6221 err = sb->s_op->show_devname(m, mnt_path.dentry);
6223 @@ -112,6 +157,7 @@ static int show_vfsmnt(struct seq_file *
6229 seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6230 err = show_sb_opts(m, sb);
6231 @@ -133,6 +179,11 @@ static int show_mountinfo(struct seq_fil
6232 struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6235 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6237 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6240 seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6241 MAJOR(sb->s_dev), MINOR(sb->s_dev));
6242 if (sb->s_op->show_path) {
6243 @@ -195,6 +246,17 @@ static int show_vfsstat(struct seq_file
6244 struct super_block *sb = mnt_path.dentry->d_sb;
6247 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6249 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6252 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6253 + mnt == current->fs->root.mnt) {
6254 + seq_puts(m, "device /dev/root mounted on / ");
6259 if (sb->s_op->show_devname) {
6260 seq_puts(m, "device ");
6261 @@ -216,7 +278,7 @@ static int show_vfsstat(struct seq_file
6267 /* file system type */
6268 seq_puts(m, "with fstype ");
6270 diff -NurpP --minimal linux-4.9.76/fs/quota/dquot.c linux-4.9.76-vs2.3.9.5/fs/quota/dquot.c
6271 --- linux-4.9.76/fs/quota/dquot.c 2016-12-11 19:17:54.000000000 +0000
6272 +++ linux-4.9.76-vs2.3.9.5/fs/quota/dquot.c 2018-01-10 02:50:49.000000000 +0000
6273 @@ -1658,6 +1658,9 @@ int __dquot_alloc_space(struct inode *in
6274 int reserve = flags & DQUOT_SPACE_RESERVE;
6275 struct dquot **dquots;
6277 + if ((ret = dl_alloc_space(inode, number)))
6280 if (!dquot_active(inode)) {
6281 inode_incr_space(inode, number, reserve);
6283 @@ -1710,6 +1713,9 @@ int dquot_alloc_inode(struct inode *inod
6284 struct dquot_warn warn[MAXQUOTAS];
6285 struct dquot * const *dquots;
6287 + if ((ret = dl_alloc_inode(inode)))
6290 if (!dquot_active(inode))
6292 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
6293 @@ -1812,6 +1818,8 @@ void __dquot_free_space(struct inode *in
6294 struct dquot **dquots;
6295 int reserve = flags & DQUOT_SPACE_RESERVE, index;
6297 + dl_free_space(inode, number);
6299 if (!dquot_active(inode)) {
6300 inode_decr_space(inode, number, reserve);
6302 @@ -1856,6 +1864,8 @@ void dquot_free_inode(struct inode *inod
6303 struct dquot * const *dquots;
6306 + dl_free_inode(inode);
6308 if (!dquot_active(inode))
6311 diff -NurpP --minimal linux-4.9.76/fs/quota/quota.c linux-4.9.76-vs2.3.9.5/fs/quota/quota.c
6312 --- linux-4.9.76/fs/quota/quota.c 2016-12-11 19:17:54.000000000 +0000
6313 +++ linux-4.9.76-vs2.3.9.5/fs/quota/quota.c 2018-01-10 02:50:49.000000000 +0000
6315 #include <linux/fs.h>
6316 #include <linux/namei.h>
6317 #include <linux/slab.h>
6318 +#include <linux/vs_context.h>
6319 #include <asm/current.h>
6320 #include <linux/uaccess.h>
6321 #include <linux/kernel.h>
6322 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6326 - if (!capable(CAP_SYS_ADMIN))
6327 + if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6331 @@ -768,6 +769,46 @@ static int do_quotactl(struct super_bloc
6335 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6337 +#include <linux/vroot.h>
6338 +#include <linux/major.h>
6339 +#include <linux/module.h>
6340 +#include <linux/kallsyms.h>
6341 +#include <linux/vserver/debug.h>
6343 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6345 +static DEFINE_SPINLOCK(vroot_grb_lock);
6347 +int register_vroot_grb(vroot_grb_func *func) {
6350 + spin_lock(&vroot_grb_lock);
6351 + if (!vroot_get_real_bdev) {
6352 + vroot_get_real_bdev = func;
6355 + spin_unlock(&vroot_grb_lock);
6358 +EXPORT_SYMBOL(register_vroot_grb);
6360 +int unregister_vroot_grb(vroot_grb_func *func) {
6361 + int ret = -EINVAL;
6363 + spin_lock(&vroot_grb_lock);
6364 + if (vroot_get_real_bdev) {
6365 + vroot_get_real_bdev = NULL;
6368 + spin_unlock(&vroot_grb_lock);
6371 +EXPORT_SYMBOL(unregister_vroot_grb);
6375 /* Return 1 if 'cmd' will block on frozen filesystem */
6376 static int quotactl_cmd_write(int cmd)
6378 @@ -809,6 +850,22 @@ static struct super_block *quotactl_bloc
6381 return ERR_CAST(bdev);
6382 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6383 + if (bdev && bdev->bd_inode &&
6384 + imajor(bdev->bd_inode) == VROOT_MAJOR) {
6385 + struct block_device *bdnew = (void *)-EINVAL;
6387 + if (vroot_get_real_bdev)
6388 + bdnew = vroot_get_real_bdev(bdev);
6390 + vxdprintk(VXD_CBIT(misc, 0),
6391 + "vroot_get_real_bdev not set");
6393 + if (IS_ERR(bdnew))
6394 + return ERR_PTR(PTR_ERR(bdnew));
6398 if (quotactl_cmd_write(cmd))
6399 sb = get_super_thawed(bdev);
6401 diff -NurpP --minimal linux-4.9.76/fs/stat.c linux-4.9.76-vs2.3.9.5/fs/stat.c
6402 --- linux-4.9.76/fs/stat.c 2018-01-13 21:28:58.000000000 +0000
6403 +++ linux-4.9.76-vs2.3.9.5/fs/stat.c 2018-01-10 02:50:49.000000000 +0000
6404 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6405 stat->nlink = inode->i_nlink;
6406 stat->uid = inode->i_uid;
6407 stat->gid = inode->i_gid;
6408 + stat->tag = inode->i_tag;
6409 stat->rdev = inode->i_rdev;
6410 stat->size = i_size_read(inode);
6411 stat->atime = inode->i_atime;
6412 diff -NurpP --minimal linux-4.9.76/fs/statfs.c linux-4.9.76-vs2.3.9.5/fs/statfs.c
6413 --- linux-4.9.76/fs/statfs.c 2016-12-11 19:17:54.000000000 +0000
6414 +++ linux-4.9.76-vs2.3.9.5/fs/statfs.c 2018-01-10 02:50:49.000000000 +0000
6416 #include <linux/statfs.h>
6417 #include <linux/security.h>
6418 #include <linux/uaccess.h>
6419 +#include <linux/vs_base.h>
6420 +#include <linux/vs_dlimit.h>
6421 #include "internal.h"
6423 static int flags_by_mnt(int mnt_flags)
6424 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6425 retval = dentry->d_sb->s_op->statfs(dentry, buf);
6426 if (retval == 0 && buf->f_frsize == 0)
6427 buf->f_frsize = buf->f_bsize;
6428 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
6429 + vx_vsi_statfs(dentry->d_sb, buf);
6433 diff -NurpP --minimal linux-4.9.76/fs/super.c linux-4.9.76-vs2.3.9.5/fs/super.c
6434 --- linux-4.9.76/fs/super.c 2018-01-13 21:28:58.000000000 +0000
6435 +++ linux-4.9.76-vs2.3.9.5/fs/super.c 2018-01-13 01:53:26.000000000 +0000
6437 #include <linux/fsnotify.h>
6438 #include <linux/lockdep.h>
6439 #include <linux/user_namespace.h>
6440 +#include <linux/magic.h>
6441 +#include <linux/vs_context.h>
6442 #include "internal.h"
6445 @@ -981,7 +983,8 @@ struct dentry *mount_ns(struct file_syst
6446 /* Don't allow mounting unless the caller has CAP_SYS_ADMIN
6447 * over the namespace.
6449 - if (!(flags & MS_KERNMOUNT) && !ns_capable(user_ns, CAP_SYS_ADMIN))
6450 + if (!(flags & MS_KERNMOUNT) &&
6451 + !vx_ns_capable(user_ns, CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6452 return ERR_PTR(-EPERM);
6454 sb = sget_userns(fs_type, ns_test_super, ns_set_super, flags,
6455 @@ -1191,6 +1194,13 @@ mount_fs(struct file_system_type *type,
6456 WARN_ON(!sb->s_bdi);
6457 sb->s_flags |= MS_BORN;
6460 + if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6462 + (sb->s_magic != PROC_SUPER_MAGIC) &&
6463 + (sb->s_magic != DEVPTS_SUPER_MAGIC))
6466 error = security_sb_kern_mount(sb, flags, secdata);
6469 diff -NurpP --minimal linux-4.9.76/fs/utimes.c linux-4.9.76-vs2.3.9.5/fs/utimes.c
6470 --- linux-4.9.76/fs/utimes.c 2016-12-11 19:17:54.000000000 +0000
6471 +++ linux-4.9.76-vs2.3.9.5/fs/utimes.c 2018-01-10 02:50:49.000000000 +0000
6473 #include <linux/stat.h>
6474 #include <linux/utime.h>
6475 #include <linux/syscalls.h>
6476 +#include <linux/mount.h>
6477 +#include <linux/vs_cowbl.h>
6478 #include <asm/uaccess.h>
6479 #include <asm/unistd.h>
6481 @@ -52,13 +54,19 @@ static int utimes_common(struct path *pa
6484 struct iattr newattrs;
6485 - struct inode *inode = path->dentry->d_inode;
6486 struct inode *delegated_inode = NULL;
6487 + struct inode *inode;
6489 + error = cow_check_and_break(path);
6493 error = mnt_want_write(path->mnt);
6497 + inode = path->dentry->d_inode;
6499 if (times && times[0].tv_nsec == UTIME_NOW &&
6500 times[1].tv_nsec == UTIME_NOW)
6502 diff -NurpP --minimal linux-4.9.76/fs/xattr.c linux-4.9.76-vs2.3.9.5/fs/xattr.c
6503 --- linux-4.9.76/fs/xattr.c 2018-01-13 21:28:58.000000000 +0000
6504 +++ linux-4.9.76-vs2.3.9.5/fs/xattr.c 2018-01-10 02:50:49.000000000 +0000
6506 #include <linux/audit.h>
6507 #include <linux/vmalloc.h>
6508 #include <linux/posix_acl_xattr.h>
6509 +#include <linux/mount.h>
6511 #include <asm/uaccess.h>
6513 @@ -112,7 +113,7 @@ xattr_permission(struct inode *inode, co
6514 * The trusted.* namespace can only be accessed by privileged users.
6516 if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6517 - if (!capable(CAP_SYS_ADMIN))
6518 + if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6519 return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6522 diff -NurpP --minimal linux-4.9.76/include/linux/capability.h linux-4.9.76-vs2.3.9.5/include/linux/capability.h
6523 --- linux-4.9.76/include/linux/capability.h 2018-01-13 21:28:59.000000000 +0000
6524 +++ linux-4.9.76-vs2.3.9.5/include/linux/capability.h 2018-01-10 02:50:49.000000000 +0000
6525 @@ -78,7 +78,8 @@ extern const kernel_cap_t __cap_init_eff
6526 #else /* HAND-CODED capability initializers */
6528 #define CAP_LAST_U32 ((_KERNEL_CAPABILITY_U32S) - 1)
6529 -#define CAP_LAST_U32_VALID_MASK (CAP_TO_MASK(CAP_LAST_CAP + 1) -1)
6530 +#define CAP_LAST_U32_VALID_MASK ((CAP_TO_MASK(CAP_LAST_CAP + 1) -1) \
6531 + | CAP_TO_MASK(CAP_CONTEXT))
6533 # define CAP_EMPTY_SET ((kernel_cap_t){{ 0, 0 }})
6534 # define CAP_FULL_SET ((kernel_cap_t){{ ~0, CAP_LAST_U32_VALID_MASK }})
6535 diff -NurpP --minimal linux-4.9.76/include/linux/cred.h linux-4.9.76-vs2.3.9.5/include/linux/cred.h
6536 --- linux-4.9.76/include/linux/cred.h 2018-01-13 21:28:59.000000000 +0000
6537 +++ linux-4.9.76-vs2.3.9.5/include/linux/cred.h 2018-01-13 21:30:31.000000000 +0000
6538 @@ -152,6 +152,7 @@ extern void exit_creds(struct task_struc
6539 extern int copy_creds(struct task_struct *, unsigned long);
6540 extern const struct cred *get_task_cred(struct task_struct *);
6541 extern struct cred *cred_alloc_blank(void);
6542 +extern struct cred *__prepare_creds(const struct cred *);
6543 extern struct cred *prepare_creds(void);
6544 extern struct cred *prepare_exec_creds(void);
6545 extern int commit_creds(struct cred *);
6546 @@ -212,6 +213,31 @@ static inline bool cap_ambient_invariant
6547 cred->cap_inheritable));
6550 +static inline void set_cred_subscribers(struct cred *cred, int n)
6552 +#ifdef CONFIG_DEBUG_CREDENTIALS
6553 + atomic_set(&cred->subscribers, n);
6557 +static inline int read_cred_subscribers(const struct cred *cred)
6559 +#ifdef CONFIG_DEBUG_CREDENTIALS
6560 + return atomic_read(&cred->subscribers);
6566 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
6568 +#ifdef CONFIG_DEBUG_CREDENTIALS
6569 + struct cred *cred = (struct cred *) _cred;
6571 + atomic_add(n, &cred->subscribers);
6576 * get_new_cred - Get a reference on a new set of credentials
6577 * @cred: The new credentials to reference
6578 diff -NurpP --minimal linux-4.9.76/include/linux/dcache.h linux-4.9.76-vs2.3.9.5/include/linux/dcache.h
6579 --- linux-4.9.76/include/linux/dcache.h 2018-01-13 21:28:59.000000000 +0000
6580 +++ linux-4.9.76-vs2.3.9.5/include/linux/dcache.h 2018-01-10 02:50:49.000000000 +0000
6581 @@ -307,8 +307,10 @@ extern char *dentry_path(struct dentry *
6583 static inline struct dentry *dget_dlock(struct dentry *dentry)
6587 dentry->d_lockref.count++;
6588 + // vx_dentry_inc(dentry);
6593 diff -NurpP --minimal linux-4.9.76/include/linux/devpts_fs.h linux-4.9.76-vs2.3.9.5/include/linux/devpts_fs.h
6594 --- linux-4.9.76/include/linux/devpts_fs.h 2016-12-11 19:17:54.000000000 +0000
6595 +++ linux-4.9.76-vs2.3.9.5/include/linux/devpts_fs.h 2018-01-10 02:50:49.000000000 +0000
6596 @@ -34,5 +34,4 @@ void devpts_pty_kill(struct dentry *);
6601 #endif /* _LINUX_DEVPTS_FS_H */
6602 diff -NurpP --minimal linux-4.9.76/include/linux/fs.h linux-4.9.76-vs2.3.9.5/include/linux/fs.h
6603 --- linux-4.9.76/include/linux/fs.h 2018-01-13 21:28:59.000000000 +0000
6604 +++ linux-4.9.76-vs2.3.9.5/include/linux/fs.h 2018-01-13 22:18:13.000000000 +0000
6605 @@ -225,6 +225,7 @@ typedef int (dio_iodone_t)(struct kiocb
6606 #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */
6607 #define ATTR_TIMES_SET (1 << 16)
6608 #define ATTR_TOUCH (1 << 17)
6609 +#define ATTR_TAG (1 << 18)
6612 * Whiteout is represented by a char device. The following constants define the
6613 @@ -247,6 +248,7 @@ struct iattr {
6619 struct timespec ia_atime;
6620 struct timespec ia_mtime;
6621 @@ -606,7 +608,9 @@ struct inode {
6622 unsigned short i_opflags;
6625 - unsigned int i_flags;
6627 + unsigned short i_flags;
6628 + unsigned short i_vflags;
6630 #ifdef CONFIG_FS_POSIX_ACL
6631 struct posix_acl *i_acl;
6632 @@ -635,6 +639,7 @@ struct inode {
6633 unsigned int __i_nlink;
6638 struct timespec i_atime;
6639 struct timespec i_mtime;
6640 @@ -839,14 +844,19 @@ static inline void i_size_write(struct i
6644 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
6646 + inode->i_tag = make_ktag(&init_user_ns, tag);
6649 static inline unsigned iminor(const struct inode *inode)
6651 - return MINOR(inode->i_rdev);
6652 + return MINOR(inode->i_mdev);
6655 static inline unsigned imajor(const struct inode *inode)
6657 - return MAJOR(inode->i_rdev);
6658 + return MAJOR(inode->i_mdev);
6661 extern struct block_device *I_BDEV(struct inode *inode);
6662 @@ -903,6 +913,7 @@ struct file {
6664 struct fown_struct f_owner;
6665 const struct cred *f_cred;
6667 struct file_ra_state f_ra;
6670 @@ -1037,6 +1048,7 @@ struct file_lock {
6671 struct file *fl_file;
6676 struct fasync_struct * fl_fasync; /* for lease break notifications */
6677 /* for lease breaks: */
6678 @@ -1469,6 +1481,11 @@ static inline gid_t i_gid_read(const str
6679 return from_kgid(inode->i_sb->s_user_ns, inode->i_gid);
6682 +static inline vtag_t i_tag_read(const struct inode *inode)
6684 + return from_ktag(&init_user_ns, inode->i_tag);
6687 static inline void i_uid_write(struct inode *inode, uid_t uid)
6689 inode->i_uid = make_kuid(inode->i_sb->s_user_ns, uid);
6690 @@ -1758,6 +1775,7 @@ struct inode_operations {
6691 int (*setattr) (struct dentry *, struct iattr *);
6692 int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
6693 ssize_t (*listxattr) (struct dentry *, char *, size_t);
6694 + int (*sync_flags) (struct inode *, int, int);
6695 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
6697 int (*update_time)(struct inode *, struct timespec *, int);
6698 @@ -1772,6 +1790,7 @@ ssize_t rw_copy_check_uvector(int type,
6699 unsigned long nr_segs, unsigned long fast_segs,
6700 struct iovec *fast_pointer,
6701 struct iovec **ret_pointer);
6702 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
6704 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
6705 extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *);
6706 @@ -1843,6 +1862,14 @@ struct super_operations {
6708 #define S_DAX 0 /* Make all the DAX code disappear */
6710 +#define S_IXUNLINK 16384 /* Immutable Invert on unlink */
6712 +/* Linux-VServer related Inode flags */
6716 +#define V_BARRIER 4 /* Barrier for chroot() */
6717 +#define V_COW 8 /* Copy on Write */
6720 * Note that nosuid etc flags are inode-specific: setting some file-system
6721 @@ -1867,10 +1894,13 @@ struct super_operations {
6722 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
6723 #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
6724 #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION)
6725 +#define IS_TAGGED(inode) __IS_FLG(inode, MS_TAGGED)
6727 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
6728 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
6729 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
6730 +#define IS_IXUNLINK(inode) ((inode)->i_flags & S_IXUNLINK)
6731 +#define IS_IXORUNLINK(inode) ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
6732 #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL)
6734 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
6735 @@ -1890,6 +1920,16 @@ static inline bool HAS_UNMAPPED_ID(struc
6736 return !uid_valid(inode->i_uid) || !gid_valid(inode->i_gid);
6739 +#define IS_BARRIER(inode) (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
6741 +#ifdef CONFIG_VSERVER_COWBL
6742 +# define IS_COW(inode) (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
6743 +# define IS_COW_LINK(inode) (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
6745 +# define IS_COW(inode) (0)
6746 +# define IS_COW_LINK(inode) (0)
6750 * Inode state bits. Protected by inode->i_lock
6752 @@ -2155,6 +2195,9 @@ extern struct kobject *fs_kobj;
6753 extern int locks_mandatory_locked(struct file *);
6754 extern int locks_mandatory_area(struct inode *, struct file *, loff_t, loff_t, unsigned char);
6756 +#define ATTR_FLAG_BARRIER 512 /* Barrier for chroot() */
6757 +#define ATTR_FLAG_IXUNLINK 1024 /* Immutable invert on unlink */
6760 * Candidates for mandatory locking have the setgid bit set
6761 * but no group execute bit - an otherwise meaningless combination.
6762 @@ -2335,7 +2378,7 @@ struct filename {
6766 -extern long vfs_truncate(const struct path *, loff_t);
6767 +extern long vfs_truncate(struct path *, loff_t);
6768 extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs,
6770 extern int vfs_fallocate(struct file *file, int mode, loff_t offset,
6771 @@ -2965,6 +3008,7 @@ extern int dcache_dir_open(struct inode
6772 extern int dcache_dir_close(struct inode *, struct file *);
6773 extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
6774 extern int dcache_readdir(struct file *, struct dir_context *);
6775 +extern int dcache_readdir_filter(struct file *, struct dir_context *, int (*)(struct dentry *));
6776 extern int simple_setattr(struct dentry *, struct iattr *);
6777 extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
6778 extern int simple_statfs(struct dentry *, struct kstatfs *);
6779 diff -NurpP --minimal linux-4.9.76/include/linux/init_task.h linux-4.9.76-vs2.3.9.5/include/linux/init_task.h
6780 --- linux-4.9.76/include/linux/init_task.h 2016-12-11 19:17:54.000000000 +0000
6781 +++ linux-4.9.76-vs2.3.9.5/include/linux/init_task.h 2018-01-10 02:50:49.000000000 +0000
6782 @@ -271,6 +271,10 @@ extern struct task_group root_task_group
6784 INIT_NUMA_BALANCING(tsk) \
6787 + .vx_info = NULL, \
6789 + .nx_info = NULL, \
6793 diff -NurpP --minimal linux-4.9.76/include/linux/ipc.h linux-4.9.76-vs2.3.9.5/include/linux/ipc.h
6794 --- linux-4.9.76/include/linux/ipc.h 2016-12-11 19:17:54.000000000 +0000
6795 +++ linux-4.9.76-vs2.3.9.5/include/linux/ipc.h 2018-01-10 02:50:49.000000000 +0000
6796 @@ -16,6 +16,7 @@ struct kern_ipc_perm
6804 diff -NurpP --minimal linux-4.9.76/include/linux/memcontrol.h linux-4.9.76-vs2.3.9.5/include/linux/memcontrol.h
6805 --- linux-4.9.76/include/linux/memcontrol.h 2018-01-13 21:29:00.000000000 +0000
6806 +++ linux-4.9.76-vs2.3.9.5/include/linux/memcontrol.h 2018-01-10 02:50:49.000000000 +0000
6807 @@ -92,6 +92,7 @@ enum mem_cgroup_events_target {
6808 MEM_CGROUP_NTARGETS,
6814 #define MEM_CGROUP_ID_SHIFT 16
6815 @@ -402,6 +403,11 @@ static inline bool mem_cgroup_is_descend
6816 return cgroup_is_descendant(memcg->css.cgroup, root->css.cgroup);
6819 +extern u64 mem_cgroup_mem_usage_pages(struct mem_cgroup *memcg);
6820 +extern u64 mem_cgroup_mem_limit_pages(struct mem_cgroup *memcg);
6821 +extern u64 mem_cgroup_memsw_usage_pages(struct mem_cgroup *memcg);
6822 +extern u64 mem_cgroup_memsw_limit_pages(struct mem_cgroup *memcg);
6824 static inline bool mm_match_cgroup(struct mm_struct *mm,
6825 struct mem_cgroup *memcg)
6827 diff -NurpP --minimal linux-4.9.76/include/linux/mount.h linux-4.9.76-vs2.3.9.5/include/linux/mount.h
6828 --- linux-4.9.76/include/linux/mount.h 2018-01-13 21:29:00.000000000 +0000
6829 +++ linux-4.9.76-vs2.3.9.5/include/linux/mount.h 2018-01-10 02:50:49.000000000 +0000
6830 @@ -63,6 +63,9 @@ struct mnt_namespace;
6831 #define MNT_MARKED 0x4000000
6832 #define MNT_UMOUNT 0x8000000
6834 +#define MNT_TAGID 0x10000
6835 +#define MNT_NOTAG 0x20000
6838 struct dentry *mnt_root; /* root of the mounted tree */
6839 struct super_block *mnt_sb; /* pointer to superblock */
6840 diff -NurpP --minimal linux-4.9.76/include/linux/net.h linux-4.9.76-vs2.3.9.5/include/linux/net.h
6841 --- linux-4.9.76/include/linux/net.h 2016-12-11 19:17:54.000000000 +0000
6842 +++ linux-4.9.76-vs2.3.9.5/include/linux/net.h 2018-01-10 02:50:49.000000000 +0000
6843 @@ -44,6 +44,7 @@ struct net;
6844 #define SOCK_NOSPACE 2
6845 #define SOCK_PASSCRED 3
6846 #define SOCK_PASSSEC 4
6847 +#define SOCK_USER_SOCKET 5
6849 #ifndef ARCH_HAS_SOCKET_TYPES
6851 diff -NurpP --minimal linux-4.9.76/include/linux/netdevice.h linux-4.9.76-vs2.3.9.5/include/linux/netdevice.h
6852 --- linux-4.9.76/include/linux/netdevice.h 2018-01-13 21:29:00.000000000 +0000
6853 +++ linux-4.9.76-vs2.3.9.5/include/linux/netdevice.h 2018-01-10 02:50:49.000000000 +0000
6854 @@ -2474,6 +2474,7 @@ static inline int dev_recursion_level(vo
6856 struct net_device *dev_get_by_index(struct net *net, int ifindex);
6857 struct net_device *__dev_get_by_index(struct net *net, int ifindex);
6858 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
6859 struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
6860 int netdev_get_name(struct net *net, char *name, int ifindex);
6861 int dev_restart(struct net_device *dev);
6862 diff -NurpP --minimal linux-4.9.76/include/linux/nsproxy.h linux-4.9.76-vs2.3.9.5/include/linux/nsproxy.h
6863 --- linux-4.9.76/include/linux/nsproxy.h 2016-12-11 19:17:54.000000000 +0000
6864 +++ linux-4.9.76-vs2.3.9.5/include/linux/nsproxy.h 2018-01-10 02:50:49.000000000 +0000
6867 #include <linux/spinlock.h>
6868 #include <linux/sched.h>
6869 +#include <linux/vserver/debug.h>
6871 struct mnt_namespace;
6872 struct uts_namespace;
6873 @@ -65,6 +66,7 @@ extern struct nsproxy init_nsproxy;
6876 int copy_namespaces(unsigned long flags, struct task_struct *tsk);
6877 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
6878 void exit_task_namespaces(struct task_struct *tsk);
6879 void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
6880 void free_nsproxy(struct nsproxy *ns);
6881 @@ -72,16 +74,26 @@ int unshare_nsproxy_namespaces(unsigned
6882 struct cred *, struct fs_struct *);
6883 int __init nsproxy_cache_init(void);
6885 -static inline void put_nsproxy(struct nsproxy *ns)
6886 +#define get_nsproxy(n) __get_nsproxy(n, __FILE__, __LINE__)
6888 +static inline void __get_nsproxy(struct nsproxy *ns,
6889 + const char *_file, int _line)
6891 - if (atomic_dec_and_test(&ns->count)) {
6894 + vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
6895 + ns, atomic_read(&ns->count), _file, _line);
6896 + atomic_inc(&ns->count);
6899 -static inline void get_nsproxy(struct nsproxy *ns)
6900 +#define put_nsproxy(n) __put_nsproxy(n, __FILE__, __LINE__)
6902 +static inline void __put_nsproxy(struct nsproxy *ns,
6903 + const char *_file, int _line)
6905 - atomic_inc(&ns->count);
6906 + vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
6907 + ns, atomic_read(&ns->count), _file, _line);
6908 + if (atomic_dec_and_test(&ns->count)) {
6914 diff -NurpP --minimal linux-4.9.76/include/linux/pid.h linux-4.9.76-vs2.3.9.5/include/linux/pid.h
6915 --- linux-4.9.76/include/linux/pid.h 2018-01-13 21:29:00.000000000 +0000
6916 +++ linux-4.9.76-vs2.3.9.5/include/linux/pid.h 2018-01-10 02:50:49.000000000 +0000
6917 @@ -10,7 +10,8 @@ enum pid_type
6920 /* only valid to __task_pid_nr_ns() */
6927 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
6930 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
6931 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
6932 pid_t pid_vnr(struct pid *pid);
6934 #define do_each_pid_task(pid, type, task) \
6935 diff -NurpP --minimal linux-4.9.76/include/linux/quotaops.h linux-4.9.76-vs2.3.9.5/include/linux/quotaops.h
6936 --- linux-4.9.76/include/linux/quotaops.h 2016-12-11 19:17:54.000000000 +0000
6937 +++ linux-4.9.76-vs2.3.9.5/include/linux/quotaops.h 2018-01-10 02:50:49.000000000 +0000
6939 #define _LINUX_QUOTAOPS_
6941 #include <linux/fs.h>
6942 +#include <linux/vs_dlimit.h>
6944 #define DQUOT_SPACE_WARN 0x1
6945 #define DQUOT_SPACE_RESERVE 0x2
6946 @@ -214,11 +215,12 @@ static inline void dquot_drop(struct ino
6948 static inline int dquot_alloc_inode(struct inode *inode)
6951 + return dl_alloc_inode(inode);
6954 static inline void dquot_free_inode(struct inode *inode)
6956 + dl_free_inode(inode);
6959 static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
6960 @@ -229,6 +231,10 @@ static inline int dquot_transfer(struct
6961 static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
6966 + if ((ret = dl_alloc_space(inode, number)))
6968 if (!(flags & DQUOT_SPACE_RESERVE))
6969 inode_add_bytes(inode, number);
6971 @@ -239,6 +245,7 @@ static inline void __dquot_free_space(st
6973 if (!(flags & DQUOT_SPACE_RESERVE))
6974 inode_sub_bytes(inode, number);
6975 + dl_free_space(inode, number);
6978 static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
6979 diff -NurpP --minimal linux-4.9.76/include/linux/sched.h linux-4.9.76-vs2.3.9.5/include/linux/sched.h
6980 --- linux-4.9.76/include/linux/sched.h 2018-01-13 21:29:00.000000000 +0000
6981 +++ linux-4.9.76-vs2.3.9.5/include/linux/sched.h 2018-01-10 02:50:49.000000000 +0000
6982 @@ -1717,6 +1717,14 @@ struct task_struct {
6984 struct seccomp seccomp;
6986 +/* vserver context data */
6987 + struct vx_info *vx_info;
6988 + struct nx_info *nx_info;
6994 /* Thread group tracking */
6997 @@ -2110,6 +2118,11 @@ struct pid_namespace;
6998 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
6999 struct pid_namespace *ns);
7001 +#include <linux/vserver/base.h>
7002 +#include <linux/vserver/context.h>
7003 +#include <linux/vserver/debug.h>
7004 +#include <linux/vserver/pid.h>
7006 static inline pid_t task_pid_nr(struct task_struct *tsk)
7009 @@ -2123,7 +2136,8 @@ static inline pid_t task_pid_nr_ns(struc
7011 static inline pid_t task_pid_vnr(struct task_struct *tsk)
7013 - return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7014 + // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7015 + return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
7019 diff -NurpP --minimal linux-4.9.76/include/linux/shmem_fs.h linux-4.9.76-vs2.3.9.5/include/linux/shmem_fs.h
7020 --- linux-4.9.76/include/linux/shmem_fs.h 2016-12-11 19:17:54.000000000 +0000
7021 +++ linux-4.9.76-vs2.3.9.5/include/linux/shmem_fs.h 2018-01-10 02:50:49.000000000 +0000
7024 /* inode in-kernel data */
7026 +#define TMPFS_SUPER_MAGIC 0x01021994
7029 struct shmem_inode_info {
7031 unsigned int seals; /* shmem seals */
7032 diff -NurpP --minimal linux-4.9.76/include/linux/stat.h linux-4.9.76-vs2.3.9.5/include/linux/stat.h
7033 --- linux-4.9.76/include/linux/stat.h 2016-12-11 19:17:54.000000000 +0000
7034 +++ linux-4.9.76-vs2.3.9.5/include/linux/stat.h 2018-01-10 02:50:49.000000000 +0000
7035 @@ -25,6 +25,7 @@ struct kstat {
7042 struct timespec atime;
7043 diff -NurpP --minimal linux-4.9.76/include/linux/sunrpc/auth.h linux-4.9.76-vs2.3.9.5/include/linux/sunrpc/auth.h
7044 --- linux-4.9.76/include/linux/sunrpc/auth.h 2016-12-11 19:17:54.000000000 +0000
7045 +++ linux-4.9.76-vs2.3.9.5/include/linux/sunrpc/auth.h 2018-01-10 02:50:49.000000000 +0000
7046 @@ -46,6 +46,7 @@ enum {
7051 struct group_info *group_info;
7052 const char *principal;
7053 unsigned long ac_flags;
7054 diff -NurpP --minimal linux-4.9.76/include/linux/sunrpc/clnt.h linux-4.9.76-vs2.3.9.5/include/linux/sunrpc/clnt.h
7055 --- linux-4.9.76/include/linux/sunrpc/clnt.h 2018-01-13 21:29:00.000000000 +0000
7056 +++ linux-4.9.76-vs2.3.9.5/include/linux/sunrpc/clnt.h 2018-01-10 02:50:49.000000000 +0000
7057 @@ -52,7 +52,8 @@ struct rpc_clnt {
7058 cl_discrtry : 1,/* disconnect before retry */
7059 cl_noretranstimeo: 1,/* No retransmit timeouts */
7060 cl_autobind : 1,/* use getport() */
7061 - cl_chatty : 1;/* be verbose */
7062 + cl_chatty : 1,/* be verbose */
7063 + cl_tag : 1;/* context tagging */
7065 struct rpc_rtt * cl_rtt; /* RTO estimator data */
7066 const struct rpc_timeout *cl_timeout; /* Timeout strategy */
7067 diff -NurpP --minimal linux-4.9.76/include/linux/types.h linux-4.9.76-vs2.3.9.5/include/linux/types.h
7068 --- linux-4.9.76/include/linux/types.h 2016-12-11 19:17:54.000000000 +0000
7069 +++ linux-4.9.76-vs2.3.9.5/include/linux/types.h 2018-01-10 02:50:49.000000000 +0000
7070 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t uid_t;
7071 typedef __kernel_gid32_t gid_t;
7072 typedef __kernel_uid16_t uid16_t;
7073 typedef __kernel_gid16_t gid16_t;
7074 +typedef unsigned int vxid_t;
7075 +typedef unsigned int vnid_t;
7076 +typedef unsigned int vtag_t;
7078 typedef unsigned long uintptr_t;
7080 diff -NurpP --minimal linux-4.9.76/include/linux/uidgid.h linux-4.9.76-vs2.3.9.5/include/linux/uidgid.h
7081 --- linux-4.9.76/include/linux/uidgid.h 2016-12-11 19:17:54.000000000 +0000
7082 +++ linux-4.9.76-vs2.3.9.5/include/linux/uidgid.h 2018-01-10 02:50:49.000000000 +0000
7083 @@ -21,13 +21,17 @@ typedef struct {
7096 #define KUIDT_INIT(value) (kuid_t){ value }
7097 #define KGIDT_INIT(value) (kgid_t){ value }
7098 +#define KTAGT_INIT(value) (ktag_t){ value }
7100 #ifdef CONFIG_MULTIUSER
7101 static inline uid_t __kuid_val(kuid_t uid)
7102 @@ -51,11 +55,18 @@ static inline gid_t __kgid_val(kgid_t gi
7106 +static inline vtag_t __ktag_val(ktag_t tag)
7111 #define GLOBAL_ROOT_UID KUIDT_INIT(0)
7112 #define GLOBAL_ROOT_GID KGIDT_INIT(0)
7113 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
7115 #define INVALID_UID KUIDT_INIT(-1)
7116 #define INVALID_GID KGIDT_INIT(-1)
7117 +#define INVALID_TAG KTAGT_INIT(-1)
7119 static inline bool uid_eq(kuid_t left, kuid_t right)
7121 @@ -67,6 +78,11 @@ static inline bool gid_eq(kgid_t left, k
7122 return __kgid_val(left) == __kgid_val(right);
7125 +static inline bool tag_eq(ktag_t left, ktag_t right)
7127 + return __ktag_val(left) == __ktag_val(right);
7130 static inline bool uid_gt(kuid_t left, kuid_t right)
7132 return __kuid_val(left) > __kuid_val(right);
7133 @@ -117,13 +133,21 @@ static inline bool gid_valid(kgid_t gid)
7134 return __kgid_val(gid) != (gid_t) -1;
7137 +static inline bool tag_valid(ktag_t tag)
7139 + return !tag_eq(tag, INVALID_TAG);
7142 #ifdef CONFIG_USER_NS
7144 extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
7145 extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
7146 +extern ktag_t make_ktag(struct user_namespace *from, gid_t gid);
7148 extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
7149 extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
7150 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
7152 extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
7153 extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
7155 @@ -149,6 +173,11 @@ static inline kgid_t make_kgid(struct us
7156 return KGIDT_INIT(gid);
7159 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
7161 + return KTAGT_INIT(tag);
7164 static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
7166 return __kuid_val(kuid);
7167 @@ -159,6 +188,11 @@ static inline gid_t from_kgid(struct use
7168 return __kgid_val(kgid);
7171 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
7173 + return __ktag_val(ktag);
7176 static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
7178 uid_t uid = from_kuid(to, kuid);
7179 diff -NurpP --minimal linux-4.9.76/include/linux/vroot.h linux-4.9.76-vs2.3.9.5/include/linux/vroot.h
7180 --- linux-4.9.76/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
7181 +++ linux-4.9.76-vs2.3.9.5/include/linux/vroot.h 2018-01-10 02:50:49.000000000 +0000
7185 + * include/linux/vroot.h
7187 + * written by Herbert P?tzl, 9/11/2002
7188 + * ported to 2.6 by Herbert P?tzl, 30/12/2004
7190 + * Copyright (C) 2002-2007 by Herbert P?tzl.
7191 + * Redistribution of this file is permitted under the
7192 + * GNU General Public License.
7195 +#ifndef _LINUX_VROOT_H
7196 +#define _LINUX_VROOT_H
7201 +/* Possible states of device */
7207 +struct vroot_device {
7211 + struct semaphore vr_ctl_mutex;
7212 + struct block_device *vr_device;
7217 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
7219 +extern int register_vroot_grb(vroot_grb_func *);
7220 +extern int unregister_vroot_grb(vroot_grb_func *);
7222 +#endif /* __KERNEL__ */
7224 +#define MAX_VROOT_DEFAULT 8
7227 + * IOCTL commands --- we will commandeer 0x56 ('V')
7230 +#define VROOT_SET_DEV 0x5600
7231 +#define VROOT_CLR_DEV 0x5601
7233 +#endif /* _LINUX_VROOT_H */
7234 diff -NurpP --minimal linux-4.9.76/include/linux/vs_base.h linux-4.9.76-vs2.3.9.5/include/linux/vs_base.h
7235 --- linux-4.9.76/include/linux/vs_base.h 1970-01-01 00:00:00.000000000 +0000
7236 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_base.h 2018-01-10 02:50:49.000000000 +0000
7241 +#include "vserver/base.h"
7242 +#include "vserver/check.h"
7243 +#include "vserver/debug.h"
7246 +#warning duplicate inclusion
7248 diff -NurpP --minimal linux-4.9.76/include/linux/vs_context.h linux-4.9.76-vs2.3.9.5/include/linux/vs_context.h
7249 --- linux-4.9.76/include/linux/vs_context.h 1970-01-01 00:00:00.000000000 +0000
7250 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_context.h 2018-01-10 02:50:49.000000000 +0000
7252 +#ifndef _VS_CONTEXT_H
7253 +#define _VS_CONTEXT_H
7255 +#include "vserver/base.h"
7256 +#include "vserver/check.h"
7257 +#include "vserver/context.h"
7258 +#include "vserver/history.h"
7259 +#include "vserver/debug.h"
7261 +#include <linux/sched.h>
7264 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
7266 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
7267 + const char *_file, int _line, void *_here)
7272 + vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
7273 + vxi, vxi ? vxi->vx_id : 0,
7274 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7276 + __vxh_get_vx_info(vxi, _here);
7278 + atomic_inc(&vxi->vx_usecnt);
7283 +extern void free_vx_info(struct vx_info *);
7285 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
7287 +static inline void __put_vx_info(struct vx_info *vxi,
7288 + const char *_file, int _line, void *_here)
7293 + vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
7294 + vxi, vxi ? vxi->vx_id : 0,
7295 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7297 + __vxh_put_vx_info(vxi, _here);
7299 + if (atomic_dec_and_test(&vxi->vx_usecnt))
7300 + free_vx_info(vxi);
7304 +#define init_vx_info(p, i) \
7305 + __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7307 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7308 + const char *_file, int _line, void *_here)
7311 + vxlprintk(VXD_CBIT(xid, 3),
7312 + "init_vx_info(%p[#%d.%d])",
7313 + vxi, vxi ? vxi->vx_id : 0,
7314 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7316 + __vxh_init_vx_info(vxi, vxp, _here);
7318 + atomic_inc(&vxi->vx_usecnt);
7324 +#define set_vx_info(p, i) \
7325 + __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7327 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7328 + const char *_file, int _line, void *_here)
7330 + struct vx_info *vxo;
7335 + vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
7336 + vxi, vxi ? vxi->vx_id : 0,
7337 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7339 + __vxh_set_vx_info(vxi, vxp, _here);
7341 + atomic_inc(&vxi->vx_usecnt);
7342 + vxo = xchg(vxp, vxi);
7347 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
7349 +static inline void __clr_vx_info(struct vx_info **vxp,
7350 + const char *_file, int _line, void *_here)
7352 + struct vx_info *vxo;
7354 + vxo = xchg(vxp, NULL);
7358 + vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
7359 + vxo, vxo ? vxo->vx_id : 0,
7360 + vxo ? atomic_read(&vxo->vx_usecnt) : 0,
7362 + __vxh_clr_vx_info(vxo, vxp, _here);
7364 + if (atomic_dec_and_test(&vxo->vx_usecnt))
7365 + free_vx_info(vxo);
7369 +#define claim_vx_info(v, p) \
7370 + __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7372 +static inline void __claim_vx_info(struct vx_info *vxi,
7373 + struct task_struct *task,
7374 + const char *_file, int _line, void *_here)
7376 + vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
7377 + vxi, vxi ? vxi->vx_id : 0,
7378 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7379 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
7380 + task, _file, _line);
7381 + __vxh_claim_vx_info(vxi, task, _here);
7383 + atomic_inc(&vxi->vx_tasks);
7387 +extern void unhash_vx_info(struct vx_info *);
7389 +#define release_vx_info(v, p) \
7390 + __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7392 +static inline void __release_vx_info(struct vx_info *vxi,
7393 + struct task_struct *task,
7394 + const char *_file, int _line, void *_here)
7396 + vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
7397 + vxi, vxi ? vxi->vx_id : 0,
7398 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7399 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
7400 + task, _file, _line);
7401 + __vxh_release_vx_info(vxi, task, _here);
7405 + if (atomic_dec_and_test(&vxi->vx_tasks))
7406 + unhash_vx_info(vxi);
7410 +#define task_get_vx_info(p) \
7411 + __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
7413 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
7414 + const char *_file, int _line, void *_here)
7416 + struct vx_info *vxi;
7419 + vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
7421 + vxi = __get_vx_info(p->vx_info, _file, _line, _here);
7427 +static inline void __wakeup_vx_info(struct vx_info *vxi)
7429 + if (waitqueue_active(&vxi->vx_wait))
7430 + wake_up_interruptible(&vxi->vx_wait);
7434 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
7436 +static inline void __enter_vx_info(struct vx_info *vxi,
7437 + struct vx_info_save *vxis, const char *_file, int _line)
7439 + vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
7440 + vxi, vxi ? vxi->vx_id : 0, vxis, current,
7441 + current->xid, current->vx_info, _file, _line);
7442 + vxis->vxi = xchg(¤t->vx_info, vxi);
7443 + vxis->xid = current->xid;
7444 + current->xid = vxi ? vxi->vx_id : 0;
7447 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
7449 +static inline void __leave_vx_info(struct vx_info_save *vxis,
7450 + const char *_file, int _line)
7452 + vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
7453 + vxis, vxis->xid, vxis->vxi, current,
7454 + current->xid, current->vx_info, _file, _line);
7455 + (void)xchg(¤t->vx_info, vxis->vxi);
7456 + current->xid = vxis->xid;
7460 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
7462 + vxis->vxi = xchg(¤t->vx_info, NULL);
7463 + vxis->xid = xchg(¤t->xid, (vxid_t)0);
7466 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
7468 + (void)xchg(¤t->xid, vxis->xid);
7469 + (void)xchg(¤t->vx_info, vxis->vxi);
7472 +#define task_is_init(p) \
7473 + __task_is_init(p, __FILE__, __LINE__, __HERE__)
7475 +static inline int __task_is_init(struct task_struct *p,
7476 + const char *_file, int _line, void *_here)
7478 + int is_init = is_global_init(p);
7482 + is_init = p->vx_info->vx_initpid == p->pid;
7487 +extern void exit_vx_info(struct task_struct *, int);
7488 +extern void exit_vx_info_early(struct task_struct *, int);
7492 +#warning duplicate inclusion
7494 diff -NurpP --minimal linux-4.9.76/include/linux/vs_cowbl.h linux-4.9.76-vs2.3.9.5/include/linux/vs_cowbl.h
7495 --- linux-4.9.76/include/linux/vs_cowbl.h 1970-01-01 00:00:00.000000000 +0000
7496 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_cowbl.h 2018-01-13 22:17:14.000000000 +0000
7498 +#ifndef _VS_COWBL_H
7499 +#define _VS_COWBL_H
7501 +#include <linux/fs.h>
7502 +#include <linux/dcache.h>
7503 +#include <linux/namei.h>
7504 +#include <linux/slab.h>
7506 +extern struct dentry *cow_break_link(const char *pathname);
7508 +static inline int cow_check_and_break(struct path *path)
7510 + struct inode *inode = path->dentry->d_inode;
7513 + /* do we need this check? */
7514 + if (IS_RDONLY(inode))
7517 + if (IS_COW(inode)) {
7518 + if (IS_COW_LINK(inode)) {
7519 + struct dentry *new_dentry, *old_dentry = path->dentry;
7522 + buf = kmalloc(PATH_MAX, GFP_KERNEL);
7526 + pp = d_path(path, buf, PATH_MAX);
7527 + new_dentry = cow_break_link(pp);
7529 + if (!IS_ERR(new_dentry)) {
7530 + path->dentry = new_dentry;
7533 + error = PTR_ERR(new_dentry);
7535 + inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
7536 + inode->i_ctime = CURRENT_TIME;
7537 + mark_inode_dirty(inode);
7544 +#warning duplicate inclusion
7546 diff -NurpP --minimal linux-4.9.76/include/linux/vs_cvirt.h linux-4.9.76-vs2.3.9.5/include/linux/vs_cvirt.h
7547 --- linux-4.9.76/include/linux/vs_cvirt.h 1970-01-01 00:00:00.000000000 +0000
7548 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_cvirt.h 2018-01-10 02:50:49.000000000 +0000
7550 +#ifndef _VS_CVIRT_H
7551 +#define _VS_CVIRT_H
7553 +#include "vserver/cvirt.h"
7554 +#include "vserver/context.h"
7555 +#include "vserver/base.h"
7556 +#include "vserver/check.h"
7557 +#include "vserver/debug.h"
7560 +static inline void vx_activate_task(struct task_struct *p)
7562 + struct vx_info *vxi;
7564 + if ((vxi = p->vx_info)) {
7565 + vx_update_load(vxi);
7566 + atomic_inc(&vxi->cvirt.nr_running);
7570 +static inline void vx_deactivate_task(struct task_struct *p)
7572 + struct vx_info *vxi;
7574 + if ((vxi = p->vx_info)) {
7575 + vx_update_load(vxi);
7576 + atomic_dec(&vxi->cvirt.nr_running);
7580 +static inline void vx_uninterruptible_inc(struct task_struct *p)
7582 + struct vx_info *vxi;
7584 + if ((vxi = p->vx_info))
7585 + atomic_inc(&vxi->cvirt.nr_uninterruptible);
7588 +static inline void vx_uninterruptible_dec(struct task_struct *p)
7590 + struct vx_info *vxi;
7592 + if ((vxi = p->vx_info))
7593 + atomic_dec(&vxi->cvirt.nr_uninterruptible);
7598 +#warning duplicate inclusion
7600 diff -NurpP --minimal linux-4.9.76/include/linux/vs_device.h linux-4.9.76-vs2.3.9.5/include/linux/vs_device.h
7601 --- linux-4.9.76/include/linux/vs_device.h 1970-01-01 00:00:00.000000000 +0000
7602 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_device.h 2018-01-10 02:50:49.000000000 +0000
7604 +#ifndef _VS_DEVICE_H
7605 +#define _VS_DEVICE_H
7607 +#include "vserver/base.h"
7608 +#include "vserver/device.h"
7609 +#include "vserver/debug.h"
7612 +#ifdef CONFIG_VSERVER_DEVICE
7614 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
7616 +#define vs_device_perm(v, d, m, p) \
7617 + ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
7622 +int vs_map_device(struct vx_info *vxi,
7623 + dev_t device, dev_t *target, umode_t mode)
7630 +#define vs_device_perm(v, d, m, p) ((p) == (p))
7635 +#define vs_map_chrdev(d, t, p) \
7636 + ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
7637 +#define vs_map_blkdev(d, t, p) \
7638 + ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
7640 +#define vs_chrdev_perm(d, p) \
7641 + vs_device_perm(current_vx_info(), d, S_IFCHR, p)
7642 +#define vs_blkdev_perm(d, p) \
7643 + vs_device_perm(current_vx_info(), d, S_IFBLK, p)
7647 +#warning duplicate inclusion
7649 diff -NurpP --minimal linux-4.9.76/include/linux/vs_dlimit.h linux-4.9.76-vs2.3.9.5/include/linux/vs_dlimit.h
7650 --- linux-4.9.76/include/linux/vs_dlimit.h 1970-01-01 00:00:00.000000000 +0000
7651 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_dlimit.h 2018-01-10 02:50:49.000000000 +0000
7653 +#ifndef _VS_DLIMIT_H
7654 +#define _VS_DLIMIT_H
7656 +#include <linux/fs.h>
7658 +#include "vserver/dlimit.h"
7659 +#include "vserver/base.h"
7660 +#include "vserver/debug.h"
7663 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
7665 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
7666 + const char *_file, int _line)
7670 + vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
7671 + dli, dli ? dli->dl_tag : 0,
7672 + dli ? atomic_read(&dli->dl_usecnt) : 0,
7674 + atomic_inc(&dli->dl_usecnt);
7679 +#define free_dl_info(i) \
7680 + call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
7682 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
7684 +static inline void __put_dl_info(struct dl_info *dli,
7685 + const char *_file, int _line)
7689 + vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
7690 + dli, dli ? dli->dl_tag : 0,
7691 + dli ? atomic_read(&dli->dl_usecnt) : 0,
7693 + if (atomic_dec_and_test(&dli->dl_usecnt))
7694 + free_dl_info(dli);
7698 +#define __dlimit_char(d) ((d) ? '*' : ' ')
7700 +static inline int __dl_alloc_space(struct super_block *sb,
7701 + vtag_t tag, dlsize_t nr, const char *file, int line)
7703 + struct dl_info *dli = NULL;
7708 + dli = locate_dl_info(sb, tag);
7712 + spin_lock(&dli->dl_lock);
7713 + ret = (dli->dl_space_used + nr > dli->dl_space_total);
7715 + dli->dl_space_used += nr;
7716 + spin_unlock(&dli->dl_lock);
7719 + vxlprintk(VXD_CBIT(dlim, 1),
7720 + "ALLOC (%p,#%d)%c %lld bytes (%d)",
7721 + sb, tag, __dlimit_char(dli), (long long)nr,
7723 + return ret ? -ENOSPC : 0;
7726 +static inline void __dl_free_space(struct super_block *sb,
7727 + vtag_t tag, dlsize_t nr, const char *_file, int _line)
7729 + struct dl_info *dli = NULL;
7733 + dli = locate_dl_info(sb, tag);
7737 + spin_lock(&dli->dl_lock);
7738 + if (dli->dl_space_used > nr)
7739 + dli->dl_space_used -= nr;
7741 + dli->dl_space_used = 0;
7742 + spin_unlock(&dli->dl_lock);
7745 + vxlprintk(VXD_CBIT(dlim, 1),
7746 + "FREE (%p,#%d)%c %lld bytes",
7747 + sb, tag, __dlimit_char(dli), (long long)nr,
7751 +static inline int __dl_alloc_inode(struct super_block *sb,
7752 + vtag_t tag, const char *_file, int _line)
7754 + struct dl_info *dli;
7757 + dli = locate_dl_info(sb, tag);
7761 + spin_lock(&dli->dl_lock);
7762 + dli->dl_inodes_used++;
7763 + ret = (dli->dl_inodes_used > dli->dl_inodes_total);
7764 + spin_unlock(&dli->dl_lock);
7767 + vxlprintk(VXD_CBIT(dlim, 0),
7768 + "ALLOC (%p,#%d)%c inode (%d)",
7769 + sb, tag, __dlimit_char(dli), ret, _file, _line);
7770 + return ret ? -ENOSPC : 0;
7773 +static inline void __dl_free_inode(struct super_block *sb,
7774 + vtag_t tag, const char *_file, int _line)
7776 + struct dl_info *dli;
7778 + dli = locate_dl_info(sb, tag);
7782 + spin_lock(&dli->dl_lock);
7783 + if (dli->dl_inodes_used > 1)
7784 + dli->dl_inodes_used--;
7786 + dli->dl_inodes_used = 0;
7787 + spin_unlock(&dli->dl_lock);
7790 + vxlprintk(VXD_CBIT(dlim, 0),
7791 + "FREE (%p,#%d)%c inode",
7792 + sb, tag, __dlimit_char(dli), _file, _line);
7795 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
7796 + unsigned long long *free_blocks, unsigned long long *root_blocks,
7797 + const char *_file, int _line)
7799 + struct dl_info *dli;
7800 + uint64_t broot, bfree;
7802 + dli = locate_dl_info(sb, tag);
7806 + spin_lock(&dli->dl_lock);
7807 + broot = (dli->dl_space_total -
7808 + (dli->dl_space_total >> 10) * dli->dl_nrlmult)
7809 + >> sb->s_blocksize_bits;
7810 + bfree = (dli->dl_space_total - dli->dl_space_used)
7811 + >> sb->s_blocksize_bits;
7812 + spin_unlock(&dli->dl_lock);
7814 + vxlprintk(VXD_CBIT(dlim, 2),
7815 + "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
7816 + (long long)bfree, (long long)broot,
7817 + *free_blocks, *root_blocks, dli->dl_nrlmult,
7819 + if (free_blocks) {
7820 + if (*free_blocks > bfree)
7821 + *free_blocks = bfree;
7823 + if (root_blocks) {
7824 + if (*root_blocks > broot)
7825 + *root_blocks = broot;
7830 +#define dl_prealloc_space(in, bytes) \
7831 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7832 + __FILE__, __LINE__ )
7834 +#define dl_alloc_space(in, bytes) \
7835 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7836 + __FILE__, __LINE__ )
7838 +#define dl_reserve_space(in, bytes) \
7839 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7840 + __FILE__, __LINE__ )
7842 +#define dl_claim_space(in, bytes) (0)
7844 +#define dl_release_space(in, bytes) \
7845 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7846 + __FILE__, __LINE__ )
7848 +#define dl_free_space(in, bytes) \
7849 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7850 + __FILE__, __LINE__ )
7854 +#define dl_alloc_inode(in) \
7855 + __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
7857 +#define dl_free_inode(in) \
7858 + __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
7861 +#define dl_adjust_block(sb, tag, fb, rb) \
7862 + __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
7866 +#warning duplicate inclusion
7868 diff -NurpP --minimal linux-4.9.76/include/linux/vs_inet.h linux-4.9.76-vs2.3.9.5/include/linux/vs_inet.h
7869 --- linux-4.9.76/include/linux/vs_inet.h 1970-01-01 00:00:00.000000000 +0000
7870 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_inet.h 2018-01-10 02:50:49.000000000 +0000
7875 +#include "vserver/base.h"
7876 +#include "vserver/network.h"
7877 +#include "vserver/debug.h"
7879 +#define IPI_LOOPBACK htonl(INADDR_LOOPBACK)
7881 +#define NXAV4(a) NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
7882 + NIPQUAD((a)->mask), (a)->type
7883 +#define NXAV4_FMT "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
7885 +#define NIPQUAD(addr) \
7886 + ((unsigned char *)&addr)[0], \
7887 + ((unsigned char *)&addr)[1], \
7888 + ((unsigned char *)&addr)[2], \
7889 + ((unsigned char *)&addr)[3]
7891 +#define NIPQUAD_FMT "%u.%u.%u.%u"
7895 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
7897 + __be32 ip = nxa->ip[0].s_addr;
7898 + __be32 mask = nxa->mask.s_addr;
7899 + __be32 bcast = ip | ~mask;
7902 + switch (nxa->type & tmask) {
7903 + case NXA_TYPE_MASK:
7904 + ret = (ip == (addr & mask));
7906 + case NXA_TYPE_ADDR:
7910 + /* fall through to broadcast */
7911 + case NXA_MOD_BCAST:
7912 + ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
7914 + case NXA_TYPE_RANGE:
7915 + ret = ((nxa->ip[0].s_addr <= addr) &&
7916 + (nxa->ip[1].s_addr > addr));
7918 + case NXA_TYPE_ANY:
7923 + vxdprintk(VXD_CBIT(net, 0),
7924 + "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
7925 + nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
7930 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
7932 + struct nx_addr_v4 *nxa;
7933 + unsigned long irqflags;
7940 + /* allow 127.0.0.1 when remapping lback */
7941 + if ((tmask & NXA_LOOPBACK) &&
7942 + (addr == IPI_LOOPBACK) &&
7943 + nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
7946 + /* check for lback address */
7947 + if ((tmask & NXA_MOD_LBACK) &&
7948 + (nxi->v4_lback.s_addr == addr))
7951 + /* check for broadcast address */
7952 + if ((tmask & NXA_MOD_BCAST) &&
7953 + (nxi->v4_bcast.s_addr == addr))
7957 + /* check for v4 addresses */
7958 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
7959 + for (nxa = &nxi->v4; nxa; nxa = nxa->next)
7960 + if (v4_addr_match(nxa, addr, tmask))
7964 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
7966 + vxdprintk(VXD_CBIT(net, 0),
7967 + "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
7968 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
7973 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
7975 + /* FIXME: needs full range checks */
7976 + return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
7980 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
7982 + struct nx_addr_v4 *ptr;
7983 + unsigned long irqflags;
7986 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
7987 + for (ptr = &nxi->v4; ptr; ptr = ptr->next)
7988 + if (v4_nx_addr_match(ptr, nxa, mask))
7992 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
7996 +#include <net/inet_sock.h>
7999 + * Check if a given address matches for a socket
8001 + * nxi: the socket's nx_info if any
8002 + * addr: to be verified address
8005 +int v4_sock_addr_match (
8006 + struct nx_info *nxi,
8007 + struct inet_sock *inet,
8010 + __be32 saddr = inet->inet_rcv_saddr;
8011 + __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
8013 + if (addr && (saddr == addr || bcast == addr))
8016 + return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
8021 +/* inet related checks and helpers */
8030 +#include <linux/netdevice.h>
8031 +#include <linux/inetdevice.h>
8032 +#include <net/inet_sock.h>
8033 +#include <net/inet_timewait_sock.h>
8036 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8037 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
8038 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
8042 + * check if address is covered by socket
8044 + * sk: the socket to check against
8045 + * addr: the address in question (must be != 0)
8049 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
8051 + struct nx_info *nxi = sk->sk_nx_info;
8052 + __be32 saddr = sk->sk_rcv_saddr;
8054 + vxdprintk(VXD_CBIT(net, 5),
8055 + "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
8056 + sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
8057 + (sk->sk_socket?sk->sk_socket->flags:0));
8059 + if (saddr) { /* direct address match */
8060 + return v4_addr_match(nxa, saddr, -1);
8061 + } else if (nxi) { /* match against nx_info */
8062 + return v4_nx_addr_in_nx_info(nxi, nxa, -1);
8063 + } else { /* unrestricted any socket */
8071 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
8073 + vxdprintk(VXD_CBIT(net, 1),
8074 + "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
8075 + nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
8076 + nxi ? dev_in_nx_info(dev, nxi) : 0);
8078 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8080 + if (dev_in_nx_info(dev, nxi))
8087 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
8093 + return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
8097 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
8099 + vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
8100 + nxi, nxi ? nxi->nx_id : 0, ifa,
8101 + nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
8103 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8105 + if (v4_ifa_in_nx_info(ifa, nxi))
8111 +struct nx_v4_sock_addr {
8112 + __be32 saddr; /* Address used for validation */
8113 + __be32 baddr; /* Address used for socket bind */
8117 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
8118 + struct nx_v4_sock_addr *nsa)
8120 + struct sock *sk = &inet->sk;
8121 + struct nx_info *nxi = sk->sk_nx_info;
8122 + __be32 saddr = addr->sin_addr.s_addr;
8123 + __be32 baddr = saddr;
8125 + vxdprintk(VXD_CBIT(net, 3),
8126 + "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
8127 + sk, sk->sk_nx_info, sk->sk_socket,
8128 + (sk->sk_socket ? sk->sk_socket->flags : 0),
8132 + if (saddr == INADDR_ANY) {
8133 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
8134 + baddr = nxi->v4.ip[0].s_addr;
8135 + } else if (saddr == IPI_LOOPBACK) {
8136 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8137 + baddr = nxi->v4_lback.s_addr;
8138 + } else if (!ipv4_is_multicast(saddr) ||
8139 + !nx_info_ncaps(nxi, NXC_MULTICAST)) {
8140 + /* normal address bind */
8141 + if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
8142 + return -EADDRNOTAVAIL;
8146 + vxdprintk(VXD_CBIT(net, 3),
8147 + "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
8148 + sk, NIPQUAD(saddr), NIPQUAD(baddr));
8150 + nsa->saddr = saddr;
8151 + nsa->baddr = baddr;
8156 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
8158 + inet->inet_saddr = nsa->baddr;
8159 + inet->inet_rcv_saddr = nsa->baddr;
8164 + * helper to simplify inet_lookup_listener
8166 + * nxi: the socket's nx_info if any
8167 + * addr: to be verified address
8168 + * saddr: socket address
8170 +static inline int v4_inet_addr_match (
8171 + struct nx_info *nxi,
8175 + if (addr && (saddr == addr))
8178 + return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
8182 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
8184 + if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
8185 + (addr == nxi->v4_lback.s_addr))
8186 + return IPI_LOOPBACK;
8191 +int nx_info_has_v4(struct nx_info *nxi)
8197 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8202 +#else /* CONFIG_INET */
8205 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
8211 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8217 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8223 +int nx_info_has_v4(struct nx_info *nxi)
8228 +#endif /* CONFIG_INET */
8230 +#define current_nx_info_has_v4() \
8231 + nx_info_has_v4(current_nx_info())
8234 +// #warning duplicate inclusion
8236 diff -NurpP --minimal linux-4.9.76/include/linux/vs_inet6.h linux-4.9.76-vs2.3.9.5/include/linux/vs_inet6.h
8237 --- linux-4.9.76/include/linux/vs_inet6.h 1970-01-01 00:00:00.000000000 +0000
8238 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_inet6.h 2018-01-10 02:50:49.000000000 +0000
8240 +#ifndef _VS_INET6_H
8241 +#define _VS_INET6_H
8243 +#include "vserver/base.h"
8244 +#include "vserver/network.h"
8245 +#include "vserver/debug.h"
8247 +#include <net/ipv6.h>
8249 +#define NXAV6(a) &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
8250 +#define NXAV6_FMT "[%pI6/%pI6/%d:%04x]"
8256 +int v6_addr_match(struct nx_addr_v6 *nxa,
8257 + const struct in6_addr *addr, uint16_t mask)
8261 + switch (nxa->type & mask) {
8262 + case NXA_TYPE_MASK:
8263 + ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
8265 + case NXA_TYPE_ADDR:
8266 + ret = ipv6_addr_equal(&nxa->ip, addr);
8268 + case NXA_TYPE_ANY:
8272 + vxdprintk(VXD_CBIT(net, 0),
8273 + "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
8274 + nxa, NXAV6(nxa), addr, mask, ret);
8279 +int v6_addr_in_nx_info(struct nx_info *nxi,
8280 + const struct in6_addr *addr, uint16_t mask)
8282 + struct nx_addr_v6 *nxa;
8283 + unsigned long irqflags;
8289 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8290 + for (nxa = &nxi->v6; nxa; nxa = nxa->next)
8291 + if (v6_addr_match(nxa, addr, mask))
8295 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8297 + vxdprintk(VXD_CBIT(net, 0),
8298 + "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
8299 + nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
8304 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
8306 + /* FIXME: needs full range checks */
8307 + return v6_addr_match(nxa, &addr->ip, mask);
8311 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
8313 + struct nx_addr_v6 *ptr;
8314 + unsigned long irqflags;
8317 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8318 + for (ptr = &nxi->v6; ptr; ptr = ptr->next)
8319 + if (v6_nx_addr_match(ptr, nxa, mask))
8323 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8329 + * Check if a given address matches for a socket
8331 + * nxi: the socket's nx_info if any
8332 + * addr: to be verified address
8335 +int v6_sock_addr_match (
8336 + struct nx_info *nxi,
8337 + struct inet_sock *inet,
8338 + struct in6_addr *addr)
8340 + struct sock *sk = &inet->sk;
8341 + const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8343 + if (!ipv6_addr_any(addr) &&
8344 + ipv6_addr_equal(saddr, addr))
8346 + if (ipv6_addr_any(saddr))
8347 + return v6_addr_in_nx_info(nxi, addr, -1);
8352 + * check if address is covered by socket
8354 + * sk: the socket to check against
8355 + * addr: the address in question (must be != 0)
8359 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
8361 + struct nx_info *nxi = sk->sk_nx_info;
8362 + const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8364 + vxdprintk(VXD_CBIT(net, 5),
8365 + "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
8366 + sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
8367 + (sk->sk_socket?sk->sk_socket->flags:0));
8369 + if (!ipv6_addr_any(saddr)) { /* direct address match */
8370 + return v6_addr_match(nxa, saddr, -1);
8371 + } else if (nxi) { /* match against nx_info */
8372 + return v6_nx_addr_in_nx_info(nxi, nxa, -1);
8373 + } else { /* unrestricted any socket */
8379 +/* inet related checks and helpers */
8387 +#include <linux/netdevice.h>
8388 +#include <linux/inetdevice.h>
8389 +#include <net/inet_timewait_sock.h>
8392 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8393 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
8394 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
8399 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
8405 + return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
8409 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
8411 + vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
8412 + nxi, nxi ? nxi->nx_id : 0, ifa,
8413 + nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
8415 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8417 + if (v6_ifa_in_nx_info(ifa, nxi))
8423 +struct nx_v6_sock_addr {
8424 + struct in6_addr saddr; /* Address used for validation */
8425 + struct in6_addr baddr; /* Address used for socket bind */
8429 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
8430 + struct nx_v6_sock_addr *nsa)
8432 + // struct sock *sk = &inet->sk;
8433 + // struct nx_info *nxi = sk->sk_nx_info;
8434 + struct in6_addr saddr = addr->sin6_addr;
8435 + struct in6_addr baddr = saddr;
8437 + nsa->saddr = saddr;
8438 + nsa->baddr = baddr;
8443 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
8445 + // struct sock *sk = &inet->sk;
8446 + // struct in6_addr *saddr = inet6_rcv_saddr(sk);
8448 + // *saddr = nsa->baddr;
8449 + // inet->inet_saddr = nsa->baddr;
8453 +int nx_info_has_v6(struct nx_info *nxi)
8462 +#else /* CONFIG_IPV6 */
8465 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
8472 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8478 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8484 +int nx_info_has_v6(struct nx_info *nxi)
8489 +#endif /* CONFIG_IPV6 */
8491 +#define current_nx_info_has_v6() \
8492 + nx_info_has_v6(current_nx_info())
8495 +#warning duplicate inclusion
8497 diff -NurpP --minimal linux-4.9.76/include/linux/vs_limit.h linux-4.9.76-vs2.3.9.5/include/linux/vs_limit.h
8498 --- linux-4.9.76/include/linux/vs_limit.h 1970-01-01 00:00:00.000000000 +0000
8499 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_limit.h 2018-01-10 02:50:49.000000000 +0000
8501 +#ifndef _VS_LIMIT_H
8502 +#define _VS_LIMIT_H
8504 +#include "vserver/limit.h"
8505 +#include "vserver/base.h"
8506 +#include "vserver/context.h"
8507 +#include "vserver/debug.h"
8508 +#include "vserver/context.h"
8509 +#include "vserver/limit_int.h"
8512 +#define vx_acc_cres(v, d, p, r) \
8513 + __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
8515 +#define vx_acc_cres_cond(x, d, p, r) \
8516 + __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8517 + r, d, p, __FILE__, __LINE__)
8520 +#define vx_add_cres(v, a, p, r) \
8521 + __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
8522 +#define vx_sub_cres(v, a, p, r) vx_add_cres(v, -(a), p, r)
8524 +#define vx_add_cres_cond(x, a, p, r) \
8525 + __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8526 + r, a, p, __FILE__, __LINE__)
8527 +#define vx_sub_cres_cond(x, a, p, r) vx_add_cres_cond(x, -(a), p, r)
8530 +/* process and file limits */
8532 +#define vx_nproc_inc(p) \
8533 + vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
8535 +#define vx_nproc_dec(p) \
8536 + vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
8538 +#define vx_files_inc(f) \
8539 + vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
8541 +#define vx_files_dec(f) \
8542 + vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
8544 +#define vx_locks_inc(l) \
8545 + vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
8547 +#define vx_locks_dec(l) \
8548 + vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
8550 +#define vx_openfd_inc(f) \
8551 + vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
8553 +#define vx_openfd_dec(f) \
8554 + vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
8557 +#define vx_cres_avail(v, n, r) \
8558 + __vx_cres_avail(v, r, n, __FILE__, __LINE__)
8561 +#define vx_nproc_avail(n) \
8562 + vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
8564 +#define vx_files_avail(n) \
8565 + vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
8567 +#define vx_locks_avail(n) \
8568 + vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
8570 +#define vx_openfd_avail(n) \
8571 + vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
8574 +/* dentry limits */
8576 +#define vx_dentry_inc(d) do { \
8577 + if (d_count(d) == 1) \
8578 + vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY); \
8581 +#define vx_dentry_dec(d) do { \
8582 + if (d_count(d) == 0) \
8583 + vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY); \
8586 +#define vx_dentry_avail(n) \
8587 + vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
8590 +/* socket limits */
8592 +#define vx_sock_inc(s) \
8593 + vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
8595 +#define vx_sock_dec(s) \
8596 + vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
8598 +#define vx_sock_avail(n) \
8599 + vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
8602 +/* ipc resource limits */
8604 +#define vx_ipcmsg_add(v, u, a) \
8605 + vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
8607 +#define vx_ipcmsg_sub(v, u, a) \
8608 + vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
8610 +#define vx_ipcmsg_avail(v, a) \
8611 + vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
8614 +#define vx_ipcshm_add(v, k, a) \
8615 + vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8617 +#define vx_ipcshm_sub(v, k, a) \
8618 + vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8620 +#define vx_ipcshm_avail(v, a) \
8621 + vx_cres_avail(v, a, VLIMIT_SHMEM)
8624 +#define vx_semary_inc(a) \
8625 + vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
8627 +#define vx_semary_dec(a) \
8628 + vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
8631 +#define vx_nsems_add(a,n) \
8632 + vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8634 +#define vx_nsems_sub(a,n) \
8635 + vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8639 +#warning duplicate inclusion
8641 diff -NurpP --minimal linux-4.9.76/include/linux/vs_network.h linux-4.9.76-vs2.3.9.5/include/linux/vs_network.h
8642 --- linux-4.9.76/include/linux/vs_network.h 1970-01-01 00:00:00.000000000 +0000
8643 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_network.h 2018-01-10 02:50:49.000000000 +0000
8645 +#ifndef _NX_VS_NETWORK_H
8646 +#define _NX_VS_NETWORK_H
8648 +#include "vserver/context.h"
8649 +#include "vserver/network.h"
8650 +#include "vserver/base.h"
8651 +#include "vserver/check.h"
8652 +#include "vserver/debug.h"
8654 +#include <linux/sched.h>
8657 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
8659 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
8660 + const char *_file, int _line)
8665 + vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
8666 + nxi, nxi ? nxi->nx_id : 0,
8667 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8670 + atomic_inc(&nxi->nx_usecnt);
8675 +extern void free_nx_info(struct nx_info *);
8677 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
8679 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
8684 + vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
8685 + nxi, nxi ? nxi->nx_id : 0,
8686 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8689 + if (atomic_dec_and_test(&nxi->nx_usecnt))
8690 + free_nx_info(nxi);
8694 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
8696 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
8697 + const char *_file, int _line)
8700 + vxlprintk(VXD_CBIT(nid, 3),
8701 + "init_nx_info(%p[#%d.%d])",
8702 + nxi, nxi ? nxi->nx_id : 0,
8703 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8706 + atomic_inc(&nxi->nx_usecnt);
8712 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
8714 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
8715 + const char *_file, int _line)
8717 + struct nx_info *nxo;
8722 + vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
8723 + nxi, nxi ? nxi->nx_id : 0,
8724 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8727 + atomic_inc(&nxi->nx_usecnt);
8728 + nxo = xchg(nxp, nxi);
8732 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
8734 +static inline void __clr_nx_info(struct nx_info **nxp,
8735 + const char *_file, int _line)
8737 + struct nx_info *nxo;
8739 + nxo = xchg(nxp, NULL);
8743 + vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
8744 + nxo, nxo ? nxo->nx_id : 0,
8745 + nxo ? atomic_read(&nxo->nx_usecnt) : 0,
8748 + if (atomic_dec_and_test(&nxo->nx_usecnt))
8749 + free_nx_info(nxo);
8753 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
8755 +static inline void __claim_nx_info(struct nx_info *nxi,
8756 + struct task_struct *task, const char *_file, int _line)
8758 + vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
8759 + nxi, nxi ? nxi->nx_id : 0,
8760 + nxi?atomic_read(&nxi->nx_usecnt):0,
8761 + nxi?atomic_read(&nxi->nx_tasks):0,
8762 + task, _file, _line);
8764 + atomic_inc(&nxi->nx_tasks);
8768 +extern void unhash_nx_info(struct nx_info *);
8770 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
8772 +static inline void __release_nx_info(struct nx_info *nxi,
8773 + struct task_struct *task, const char *_file, int _line)
8775 + vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
8776 + nxi, nxi ? nxi->nx_id : 0,
8777 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8778 + nxi ? atomic_read(&nxi->nx_tasks) : 0,
8779 + task, _file, _line);
8783 + if (atomic_dec_and_test(&nxi->nx_tasks))
8784 + unhash_nx_info(nxi);
8788 +#define task_get_nx_info(i) __task_get_nx_info(i, __FILE__, __LINE__)
8790 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
8791 + const char *_file, int _line)
8793 + struct nx_info *nxi;
8796 + vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
8798 + nxi = __get_nx_info(p->nx_info, _file, _line);
8804 +static inline void exit_nx_info(struct task_struct *p)
8807 + release_nx_info(p->nx_info, p);
8812 +#warning duplicate inclusion
8814 diff -NurpP --minimal linux-4.9.76/include/linux/vs_pid.h linux-4.9.76-vs2.3.9.5/include/linux/vs_pid.h
8815 --- linux-4.9.76/include/linux/vs_pid.h 1970-01-01 00:00:00.000000000 +0000
8816 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_pid.h 2018-01-10 02:50:49.000000000 +0000
8821 +#include "vserver/base.h"
8822 +#include "vserver/check.h"
8823 +#include "vserver/context.h"
8824 +#include "vserver/debug.h"
8825 +#include "vserver/pid.h"
8826 +#include <linux/pid_namespace.h>
8829 +#define VXF_FAKE_INIT (VXF_INFO_INIT | VXF_STATE_INIT)
8832 +int vx_proc_task_visible(struct task_struct *task)
8834 + if ((task->pid == 1) &&
8835 + !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
8836 + /* show a blend through init */
8838 + if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
8845 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
8849 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
8851 + struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
8853 + if (task && !vx_proc_task_visible(task)) {
8854 + vxdprintk(VXD_CBIT(misc, 6),
8855 + "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
8856 + task, task->xid, task->pid,
8857 + current, current->xid, current->pid);
8858 + put_task_struct(task);
8866 +#warning duplicate inclusion
8868 diff -NurpP --minimal linux-4.9.76/include/linux/vs_sched.h linux-4.9.76-vs2.3.9.5/include/linux/vs_sched.h
8869 --- linux-4.9.76/include/linux/vs_sched.h 1970-01-01 00:00:00.000000000 +0000
8870 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_sched.h 2018-01-10 02:50:49.000000000 +0000
8872 +#ifndef _VS_SCHED_H
8873 +#define _VS_SCHED_H
8875 +#include "vserver/base.h"
8876 +#include "vserver/context.h"
8877 +#include "vserver/sched.h"
8880 +#define MAX_PRIO_BIAS 20
8881 +#define MIN_PRIO_BIAS -20
8884 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
8886 + struct vx_info *vxi = p->vx_info;
8889 + prio += vx_cpu(vxi, sched_pc).prio_bias;
8893 +static inline void vx_account_user(struct vx_info *vxi,
8894 + cputime_t cputime, int nice)
8898 + vx_cpu(vxi, sched_pc).user_ticks += cputime;
8901 +static inline void vx_account_system(struct vx_info *vxi,
8902 + cputime_t cputime, int idle)
8906 + vx_cpu(vxi, sched_pc).sys_ticks += cputime;
8910 +#warning duplicate inclusion
8912 diff -NurpP --minimal linux-4.9.76/include/linux/vs_socket.h linux-4.9.76-vs2.3.9.5/include/linux/vs_socket.h
8913 --- linux-4.9.76/include/linux/vs_socket.h 1970-01-01 00:00:00.000000000 +0000
8914 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_socket.h 2018-01-10 02:50:49.000000000 +0000
8916 +#ifndef _VS_SOCKET_H
8917 +#define _VS_SOCKET_H
8919 +#include "vserver/debug.h"
8920 +#include "vserver/base.h"
8921 +#include "vserver/cacct.h"
8922 +#include "vserver/context.h"
8923 +#include "vserver/tag.h"
8926 +/* socket accounting */
8928 +#include <linux/socket.h>
8930 +static inline int vx_sock_type(int family)
8934 + return VXA_SOCK_UNSPEC;
8936 + return VXA_SOCK_UNIX;
8938 + return VXA_SOCK_INET;
8940 + return VXA_SOCK_INET6;
8942 + return VXA_SOCK_PACKET;
8944 + return VXA_SOCK_OTHER;
8948 +#define vx_acc_sock(v, f, p, s) \
8949 + __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
8951 +static inline void __vx_acc_sock(struct vx_info *vxi,
8952 + int family, int pos, int size, char *file, int line)
8955 + int type = vx_sock_type(family);
8957 + atomic_long_inc(&vxi->cacct.sock[type][pos].count);
8958 + atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
8962 +#define vx_sock_recv(sk, s) \
8963 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
8964 +#define vx_sock_send(sk, s) \
8965 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
8966 +#define vx_sock_fail(sk, s) \
8967 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
8970 +#define sock_vx_init(s) do { \
8971 + (s)->sk_xid = 0; \
8972 + (s)->sk_vx_info = NULL; \
8975 +#define sock_nx_init(s) do { \
8976 + (s)->sk_nid = 0; \
8977 + (s)->sk_nx_info = NULL; \
8981 +#warning duplicate inclusion
8983 diff -NurpP --minimal linux-4.9.76/include/linux/vs_tag.h linux-4.9.76-vs2.3.9.5/include/linux/vs_tag.h
8984 --- linux-4.9.76/include/linux/vs_tag.h 1970-01-01 00:00:00.000000000 +0000
8985 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_tag.h 2018-01-10 02:50:49.000000000 +0000
8990 +#include <linux/vserver/tag.h>
8992 +/* check conditions */
8994 +#define DX_ADMIN 0x0001
8995 +#define DX_WATCH 0x0002
8996 +#define DX_HOSTID 0x0008
8998 +#define DX_IDENT 0x0010
9000 +#define DX_ARG_MASK 0x0010
9003 +#define dx_task_tag(t) ((t)->tag)
9005 +#define dx_current_tag() dx_task_tag(current)
9007 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
9009 +#define dx_weak_check(c, m) ((m) ? dx_check(c, m) : 1)
9013 + * check current context for ADMIN/WATCH and
9014 + * optionally against supplied argument
9016 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
9018 + if (mode & DX_ARG_MASK) {
9019 + if ((mode & DX_IDENT) && (id == cid))
9022 + return (((mode & DX_ADMIN) && (cid == 0)) ||
9023 + ((mode & DX_WATCH) && (cid == 1)) ||
9024 + ((mode & DX_HOSTID) && (id == 0)));
9028 +int dx_permission(const struct inode *inode, int mask);
9032 +#warning duplicate inclusion
9034 diff -NurpP --minimal linux-4.9.76/include/linux/vs_time.h linux-4.9.76-vs2.3.9.5/include/linux/vs_time.h
9035 --- linux-4.9.76/include/linux/vs_time.h 1970-01-01 00:00:00.000000000 +0000
9036 +++ linux-4.9.76-vs2.3.9.5/include/linux/vs_time.h 2018-01-10 09:27:12.000000000 +0000
9042 +/* time faking stuff */
9044 +#ifdef CONFIG_VSERVER_VTIME
9046 +extern void vx_adjust_timespec(struct timespec *ts);
9047 +extern int vx_settimeofday(const struct timespec *ts);
9048 +extern int vx_settimeofday64(const struct timespec *ts);
9051 +#define vx_adjust_timespec(t) do { } while (0)
9052 +#define vx_settimeofday(t) do_settimeofday(t)
9053 +#define vx_settimeofday64(t) do_settimeofday64(t)
9057 +#warning duplicate inclusion
9059 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/base.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/base.h
9060 --- linux-4.9.76/include/linux/vserver/base.h 1970-01-01 00:00:00.000000000 +0000
9061 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/base.h 2018-01-10 02:50:49.000000000 +0000
9063 +#ifndef _VSERVER_BASE_H
9064 +#define _VSERVER_BASE_H
9067 +/* context state changes */
9079 +#define vx_task_xid(t) ((t)->xid)
9081 +#define vx_current_xid() vx_task_xid(current)
9083 +#define current_vx_info() (current->vx_info)
9086 +#define nx_task_nid(t) ((t)->nid)
9088 +#define nx_current_nid() nx_task_nid(current)
9090 +#define current_nx_info() (current->nx_info)
9093 +/* generic flag merging */
9095 +#define vs_check_flags(v, m, f) (((v) & (m)) ^ (f))
9097 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
9099 +#define vs_mask_mask(v, f, m) (((v) & ~(m)) | ((v) & (f) & (m)))
9101 +#define vs_check_bit(v, n) ((v) & (1LL << (n)))
9104 +/* context flags */
9106 +#define __vx_flags(v) ((v) ? (v)->vx_flags : 0)
9108 +#define vx_current_flags() __vx_flags(current_vx_info())
9110 +#define vx_info_flags(v, m, f) \
9111 + vs_check_flags(__vx_flags(v), m, f)
9113 +#define task_vx_flags(t, m, f) \
9114 + ((t) && vx_info_flags((t)->vx_info, m, f))
9116 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
9121 +#define __vx_ccaps(v) ((v) ? (v)->vx_ccaps : 0)
9123 +#define vx_current_ccaps() __vx_ccaps(current_vx_info())
9125 +#define vx_info_ccaps(v, c) (__vx_ccaps(v) & (c))
9127 +#define vx_ccaps(c) vx_info_ccaps(current_vx_info(), (c))
9131 +/* network flags */
9133 +#define __nx_flags(n) ((n) ? (n)->nx_flags : 0)
9135 +#define nx_current_flags() __nx_flags(current_nx_info())
9137 +#define nx_info_flags(n, m, f) \
9138 + vs_check_flags(__nx_flags(n), m, f)
9140 +#define task_nx_flags(t, m, f) \
9141 + ((t) && nx_info_flags((t)->nx_info, m, f))
9143 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
9148 +#define __nx_ncaps(n) ((n) ? (n)->nx_ncaps : 0)
9150 +#define nx_current_ncaps() __nx_ncaps(current_nx_info())
9152 +#define nx_info_ncaps(n, c) (__nx_ncaps(n) & (c))
9154 +#define nx_ncaps(c) nx_info_ncaps(current_nx_info(), c)
9157 +/* context mask capabilities */
9159 +#define __vx_mcaps(v) ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
9161 +#define vx_info_mcaps(v, c) (__vx_mcaps(v) & (c))
9163 +#define vx_mcaps(c) vx_info_mcaps(current_vx_info(), c)
9166 +/* context bcap mask */
9168 +#define __vx_bcaps(v) ((v)->vx_bcaps)
9170 +#define vx_current_bcaps() __vx_bcaps(current_vx_info())
9173 +/* mask given bcaps */
9175 +#define vx_info_mbcaps(v, c) ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
9177 +#define vx_mbcaps(c) vx_info_mbcaps(current_vx_info(), c)
9180 +/* masked cap_bset */
9182 +#define vx_info_cap_bset(v) vx_info_mbcaps(v, current->cap_bset)
9184 +#define vx_current_cap_bset() vx_info_cap_bset(current_vx_info())
9187 +#define vx_info_mbcap(v, b) \
9188 + (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
9189 + vx_info_bcaps(v, b) : (b))
9191 +#define task_vx_mbcap(t, b) \
9192 + vx_info_mbcap((t)->vx_info, (t)->b)
9194 +#define vx_mbcap(b) task_vx_mbcap(current, b)
9197 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
9199 +#define vx_capable(b, c) (capable(b) || \
9200 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
9202 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
9203 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
9205 +#define nx_capable(b, c) (capable(b) || \
9206 + (cap_raised(current_cap(), b) && nx_ncaps(c)))
9208 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
9209 + (cap_raised(current_cap(), b) && nx_ncaps(c)))
9211 +#define vx_task_initpid(t, n) \
9212 + ((t)->vx_info && \
9213 + ((t)->vx_info->vx_initpid == (n)))
9215 +#define vx_current_initpid(n) vx_task_initpid(current, n)
9218 +/* context unshare mask */
9220 +#define __vx_umask(v) ((v)->vx_umask)
9222 +#define vx_current_umask() __vx_umask(current_vx_info())
9224 +#define vx_can_unshare(b, f) (capable(b) || \
9225 + (cap_raised(current_cap(), b) && \
9226 + !((f) & ~vx_current_umask())))
9228 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
9229 + (cap_raised(current_cap(), b) && \
9230 + !((f) & ~vx_current_umask())))
9232 +#define __vx_wmask(v) ((v)->vx_wmask)
9234 +#define vx_current_wmask() __vx_wmask(current_vx_info())
9237 +#define __vx_state(v) ((v) ? ((v)->vx_state) : 0)
9239 +#define vx_info_state(v, m) (__vx_state(v) & (m))
9242 +#define __nx_state(n) ((n) ? ((n)->nx_state) : 0)
9244 +#define nx_info_state(n, m) (__nx_state(n) & (m))
9247 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/cacct.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/cacct.h
9248 --- linux-4.9.76/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
9249 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/cacct.h 2018-01-10 02:50:49.000000000 +0000
9251 +#ifndef _VSERVER_CACCT_H
9252 +#define _VSERVER_CACCT_H
9255 +enum sock_acc_field {
9256 + VXA_SOCK_UNSPEC = 0,
9262 + VXA_SOCK_SIZE /* array size */
9265 +#endif /* _VSERVER_CACCT_H */
9266 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/cacct_cmd.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/cacct_cmd.h
9267 --- linux-4.9.76/include/linux/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
9268 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/cacct_cmd.h 2018-01-10 02:50:49.000000000 +0000
9270 +#ifndef _VSERVER_CACCT_CMD_H
9271 +#define _VSERVER_CACCT_CMD_H
9274 +#include <linux/compiler.h>
9275 +#include <uapi/vserver/cacct_cmd.h>
9277 +extern int vc_sock_stat(struct vx_info *, void __user *);
9279 +#endif /* _VSERVER_CACCT_CMD_H */
9280 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/cacct_def.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/cacct_def.h
9281 --- linux-4.9.76/include/linux/vserver/cacct_def.h 1970-01-01 00:00:00.000000000 +0000
9282 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/cacct_def.h 2018-01-10 02:50:49.000000000 +0000
9284 +#ifndef _VSERVER_CACCT_DEF_H
9285 +#define _VSERVER_CACCT_DEF_H
9287 +#include <asm/atomic.h>
9288 +#include <linux/vserver/cacct.h>
9291 +struct _vx_sock_acc {
9292 + atomic_long_t count;
9293 + atomic_long_t total;
9296 +/* context sub struct */
9299 + struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
9301 + atomic_t page[6][8];
9304 +#ifdef CONFIG_VSERVER_DEBUG
9306 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
9310 + printk("\t_vx_cacct:");
9311 + for (i = 0; i < 6; i++) {
9312 + struct _vx_sock_acc *ptr = cacct->sock[i];
9314 + printk("\t [%d] =", i);
9315 + for (j = 0; j < 3; j++) {
9316 + printk(" [%d] = %8lu, %8lu", j,
9317 + atomic_long_read(&ptr[j].count),
9318 + atomic_long_read(&ptr[j].total));
9326 +#endif /* _VSERVER_CACCT_DEF_H */
9327 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/cacct_int.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/cacct_int.h
9328 --- linux-4.9.76/include/linux/vserver/cacct_int.h 1970-01-01 00:00:00.000000000 +0000
9329 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/cacct_int.h 2018-01-10 02:50:49.000000000 +0000
9331 +#ifndef _VSERVER_CACCT_INT_H
9332 +#define _VSERVER_CACCT_INT_H
9335 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
9337 + return atomic_long_read(&cacct->sock[type][pos].count);
9342 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
9344 + return atomic_long_read(&cacct->sock[type][pos].total);
9347 +#endif /* _VSERVER_CACCT_INT_H */
9348 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/check.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/check.h
9349 --- linux-4.9.76/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
9350 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/check.h 2018-01-10 02:50:49.000000000 +0000
9352 +#ifndef _VSERVER_CHECK_H
9353 +#define _VSERVER_CHECK_H
9356 +#define MAX_S_CONTEXT 65535 /* Arbitrary limit */
9358 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
9359 +#define MIN_D_CONTEXT 49152 /* dynamic contexts start here */
9361 +#define MIN_D_CONTEXT 65536
9364 +/* check conditions */
9366 +#define VS_ADMIN 0x0001
9367 +#define VS_WATCH 0x0002
9368 +#define VS_HIDE 0x0004
9369 +#define VS_HOSTID 0x0008
9371 +#define VS_IDENT 0x0010
9372 +#define VS_EQUIV 0x0020
9373 +#define VS_PARENT 0x0040
9374 +#define VS_CHILD 0x0080
9376 +#define VS_ARG_MASK 0x00F0
9378 +#define VS_DYNAMIC 0x0100
9379 +#define VS_STATIC 0x0200
9381 +#define VS_ATR_MASK 0x0F00
9383 +#ifdef CONFIG_VSERVER_PRIVACY
9384 +#define VS_ADMIN_P (0)
9385 +#define VS_WATCH_P (0)
9387 +#define VS_ADMIN_P VS_ADMIN
9388 +#define VS_WATCH_P VS_WATCH
9391 +#define VS_HARDIRQ 0x1000
9392 +#define VS_SOFTIRQ 0x2000
9393 +#define VS_IRQ 0x4000
9395 +#define VS_IRQ_MASK 0xF000
9397 +#include <linux/hardirq.h>
9400 + * check current context for ADMIN/WATCH and
9401 + * optionally against supplied argument
9403 +static inline int __vs_check(int cid, int id, unsigned int mode)
9405 + if (mode & VS_ARG_MASK) {
9406 + if ((mode & VS_IDENT) && (id == cid))
9409 + if (mode & VS_ATR_MASK) {
9410 + if ((mode & VS_DYNAMIC) &&
9411 + (id >= MIN_D_CONTEXT) &&
9412 + (id <= MAX_S_CONTEXT))
9414 + if ((mode & VS_STATIC) &&
9415 + (id > 1) && (id < MIN_D_CONTEXT))
9418 + if (mode & VS_IRQ_MASK) {
9419 + if ((mode & VS_IRQ) && unlikely(in_interrupt()))
9421 + if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
9423 + if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
9426 + return (((mode & VS_ADMIN) && (cid == 0)) ||
9427 + ((mode & VS_WATCH) && (cid == 1)) ||
9428 + ((mode & VS_HOSTID) && (id == 0)));
9431 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
9433 +#define vx_weak_check(c, m) ((m) ? vx_check(c, m) : 1)
9436 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
9438 +#define nx_weak_check(c, m) ((m) ? nx_check(c, m) : 1)
9441 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/context.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/context.h
9442 --- linux-4.9.76/include/linux/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
9443 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/context.h 2018-01-10 02:50:49.000000000 +0000
9445 +#ifndef _VSERVER_CONTEXT_H
9446 +#define _VSERVER_CONTEXT_H
9449 +#include <linux/list.h>
9450 +#include <linux/spinlock.h>
9451 +#include <linux/rcupdate.h>
9452 +#include <uapi/vserver/context.h>
9454 +#include "limit_def.h"
9455 +#include "sched_def.h"
9456 +#include "cvirt_def.h"
9457 +#include "cacct_def.h"
9458 +#include "device_def.h"
9460 +#define VX_SPACES 2
9462 +struct _vx_info_pc {
9463 + struct _vx_sched_pc sched_pc;
9464 + struct _vx_cvirt_pc cvirt_pc;
9468 + unsigned long vx_nsmask; /* assignment mask */
9469 + struct nsproxy *vx_nsproxy; /* private namespaces */
9470 + struct fs_struct *vx_fs; /* private namespace fs */
9471 + const struct cred *vx_cred; /* task credentials */
9475 + struct hlist_node vx_hlist; /* linked list of contexts */
9476 + vxid_t vx_id; /* context id */
9477 + atomic_t vx_usecnt; /* usage count */
9478 + atomic_t vx_tasks; /* tasks count */
9479 + struct vx_info *vx_parent; /* parent context */
9480 + int vx_state; /* context state */
9482 + struct _vx_space space[VX_SPACES]; /* namespace store */
9484 + uint64_t vx_flags; /* context flags */
9485 + uint64_t vx_ccaps; /* context caps (vserver) */
9486 + uint64_t vx_umask; /* unshare mask (guest) */
9487 + uint64_t vx_wmask; /* warn mask (guest) */
9488 + kernel_cap_t vx_bcaps; /* bounding caps (system) */
9490 + struct task_struct *vx_reaper; /* guest reaper process */
9491 + pid_t vx_initpid; /* PID of guest init */
9492 + int64_t vx_badness_bias; /* OOM points bias */
9494 + struct _vx_limit limit; /* vserver limits */
9495 + struct _vx_sched sched; /* vserver scheduler */
9496 + struct _vx_cvirt cvirt; /* virtual/bias stuff */
9497 + struct _vx_cacct cacct; /* context accounting */
9499 + struct _vx_device dmap; /* default device map targets */
9502 + struct _vx_info_pc info_pc; /* per cpu data */
9504 + struct _vx_info_pc *ptr_pc; /* per cpu array */
9507 + wait_queue_head_t vx_wait; /* context exit waitqueue */
9508 + int reboot_cmd; /* last sys_reboot() cmd */
9509 + int exit_code; /* last process exit code */
9511 + char vx_name[65]; /* vserver name */
9515 +#define vx_ptr_pc(vxi) (&(vxi)->info_pc)
9516 +#define vx_per_cpu(vxi, v, id) vx_ptr_pc(vxi)->v
9518 +#define vx_ptr_pc(vxi) ((vxi)->ptr_pc)
9519 +#define vx_per_cpu(vxi, v, id) per_cpu_ptr(vx_ptr_pc(vxi), id)->v
9522 +#define vx_cpu(vxi, v) vx_per_cpu(vxi, v, smp_processor_id())
9525 +struct vx_info_save {
9526 + struct vx_info *vxi;
9533 +#define VXS_HASHED 0x0001
9534 +#define VXS_PAUSED 0x0010
9535 +#define VXS_SHUTDOWN 0x0100
9536 +#define VXS_HELPER 0x1000
9537 +#define VXS_RELEASED 0x8000
9540 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
9541 +extern void release_vx_info(struct vx_info *, struct task_struct *);
9543 +extern struct vx_info *lookup_vx_info(int);
9544 +extern struct vx_info *lookup_or_create_vx_info(int);
9546 +extern int get_xid_list(int, unsigned int *, int);
9547 +extern int xid_is_hashed(vxid_t);
9549 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
9551 +extern long vs_state_change(struct vx_info *, unsigned int);
9554 +#endif /* _VSERVER_CONTEXT_H */
9555 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/context_cmd.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/context_cmd.h
9556 --- linux-4.9.76/include/linux/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
9557 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/context_cmd.h 2018-01-10 02:50:49.000000000 +0000
9559 +#ifndef _VSERVER_CONTEXT_CMD_H
9560 +#define _VSERVER_CONTEXT_CMD_H
9562 +#include <uapi/vserver/context_cmd.h>
9564 +extern int vc_task_xid(uint32_t);
9566 +extern int vc_vx_info(struct vx_info *, void __user *);
9568 +extern int vc_ctx_stat(struct vx_info *, void __user *);
9570 +extern int vc_ctx_create(uint32_t, void __user *);
9571 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
9573 +extern int vc_get_cflags(struct vx_info *, void __user *);
9574 +extern int vc_set_cflags(struct vx_info *, void __user *);
9576 +extern int vc_get_ccaps(struct vx_info *, void __user *);
9577 +extern int vc_set_ccaps(struct vx_info *, void __user *);
9579 +extern int vc_get_bcaps(struct vx_info *, void __user *);
9580 +extern int vc_set_bcaps(struct vx_info *, void __user *);
9582 +extern int vc_get_umask(struct vx_info *, void __user *);
9583 +extern int vc_set_umask(struct vx_info *, void __user *);
9585 +extern int vc_get_wmask(struct vx_info *, void __user *);
9586 +extern int vc_set_wmask(struct vx_info *, void __user *);
9588 +extern int vc_get_badness(struct vx_info *, void __user *);
9589 +extern int vc_set_badness(struct vx_info *, void __user *);
9591 +#endif /* _VSERVER_CONTEXT_CMD_H */
9592 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/cvirt.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/cvirt.h
9593 --- linux-4.9.76/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
9594 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/cvirt.h 2018-01-10 02:50:49.000000000 +0000
9596 +#ifndef _VSERVER_CVIRT_H
9597 +#define _VSERVER_CVIRT_H
9601 +void vx_vsi_boottime(struct timespec *);
9603 +void vx_vsi_uptime(struct timespec *, struct timespec *);
9608 +void vx_update_load(struct vx_info *);
9611 +int vx_do_syslog(int, char __user *, int);
9613 +#endif /* _VSERVER_CVIRT_H */
9614 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/cvirt_cmd.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/cvirt_cmd.h
9615 --- linux-4.9.76/include/linux/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
9616 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/cvirt_cmd.h 2018-01-10 02:50:49.000000000 +0000
9618 +#ifndef _VSERVER_CVIRT_CMD_H
9619 +#define _VSERVER_CVIRT_CMD_H
9622 +#include <linux/compiler.h>
9623 +#include <uapi/vserver/cvirt_cmd.h>
9625 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
9626 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
9628 +extern int vc_virt_stat(struct vx_info *, void __user *);
9630 +#endif /* _VSERVER_CVIRT_CMD_H */
9631 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/cvirt_def.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/cvirt_def.h
9632 --- linux-4.9.76/include/linux/vserver/cvirt_def.h 1970-01-01 00:00:00.000000000 +0000
9633 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/cvirt_def.h 2018-01-10 10:07:41.000000000 +0000
9635 +#ifndef _VSERVER_CVIRT_DEF_H
9636 +#define _VSERVER_CVIRT_DEF_H
9638 +#include <linux/jiffies.h>
9639 +#include <linux/spinlock.h>
9640 +#include <linux/wait.h>
9641 +#include <linux/time.h>
9642 +#include <asm/atomic.h>
9645 +struct _vx_usage_stat {
9655 +struct _vx_syslog {
9656 + wait_queue_head_t log_wait;
9657 + spinlock_t logbuf_lock; /* lock for the log buffer */
9659 + unsigned long log_start; /* next char to be read by syslog() */
9660 + unsigned long con_start; /* next char to be sent to consoles */
9661 + unsigned long log_end; /* most-recently-written-char + 1 */
9662 + unsigned long logged_chars; /* #chars since last read+clear operation */
9664 + char log_buf[1024];
9668 +/* context sub struct */
9671 + atomic_t nr_threads; /* number of current threads */
9672 + atomic_t nr_running; /* number of running threads */
9673 + atomic_t nr_uninterruptible; /* number of uninterruptible threads */
9675 + atomic_t nr_onhold; /* processes on hold */
9676 + uint32_t onhold_last; /* jiffies when put on hold */
9678 + struct timespec64 bias_ts; /* time offset to the host */
9679 + struct timespec64 bias_idle;
9680 + struct timespec64 bias_uptime; /* context creation point */
9681 + uint64_t bias_clock; /* offset in clock_t */
9683 + spinlock_t load_lock; /* lock for the load averages */
9684 + atomic_t load_updates; /* nr of load updates done so far */
9685 + uint32_t load_last; /* last time load was calculated */
9686 + uint32_t load[3]; /* load averages 1,5,15 */
9688 + atomic_t total_forks; /* number of forks so far */
9690 + struct _vx_syslog syslog;
9693 +struct _vx_cvirt_pc {
9694 + struct _vx_usage_stat cpustat;
9698 +#ifdef CONFIG_VSERVER_DEBUG
9700 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
9702 + printk("\t_vx_cvirt:\n");
9703 + printk("\t threads: %4d, %4d, %4d, %4d\n",
9704 + atomic_read(&cvirt->nr_threads),
9705 + atomic_read(&cvirt->nr_running),
9706 + atomic_read(&cvirt->nr_uninterruptible),
9707 + atomic_read(&cvirt->nr_onhold));
9708 + /* add rest here */
9709 + printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
9714 +#endif /* _VSERVER_CVIRT_DEF_H */
9715 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/debug.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/debug.h
9716 --- linux-4.9.76/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
9717 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/debug.h 2018-01-10 02:50:49.000000000 +0000
9719 +#ifndef _VSERVER_DEBUG_H
9720 +#define _VSERVER_DEBUG_H
9723 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
9724 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
9725 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
9727 +#define VXD_DEV(d) (d), (d)->bd_inode->i_ino, \
9728 + imajor((d)->bd_inode), iminor((d)->bd_inode)
9729 +#define VXF_DEV "%p[%lu,%d:%d]"
9731 +#if defined(CONFIG_QUOTES_UTF8)
9732 +#define VS_Q_LQM "\xc2\xbb"
9733 +#define VS_Q_RQM "\xc2\xab"
9734 +#elif defined(CONFIG_QUOTES_ASCII)
9735 +#define VS_Q_LQM "\x27"
9736 +#define VS_Q_RQM "\x27"
9738 +#define VS_Q_LQM "\xbb"
9739 +#define VS_Q_RQM "\xab"
9742 +#define VS_Q(f) VS_Q_LQM f VS_Q_RQM
9745 +#define vxd_path(p) \
9746 + ({ static char _buffer[PATH_MAX]; \
9747 + d_path(p, _buffer, sizeof(_buffer)); })
9749 +#define vxd_cond_path(n) \
9750 + ((n) ? vxd_path(&(n)->path) : "<null>" )
9753 +#ifdef CONFIG_VSERVER_DEBUG
9755 +extern unsigned int vs_debug_switch;
9756 +extern unsigned int vs_debug_xid;
9757 +extern unsigned int vs_debug_nid;
9758 +extern unsigned int vs_debug_tag;
9759 +extern unsigned int vs_debug_net;
9760 +extern unsigned int vs_debug_limit;
9761 +extern unsigned int vs_debug_cres;
9762 +extern unsigned int vs_debug_dlim;
9763 +extern unsigned int vs_debug_quota;
9764 +extern unsigned int vs_debug_cvirt;
9765 +extern unsigned int vs_debug_space;
9766 +extern unsigned int vs_debug_perm;
9767 +extern unsigned int vs_debug_misc;
9770 +#define VX_LOGLEVEL "vxD: "
9771 +#define VX_PROC_FMT "%p: "
9772 +#define VX_PROCESS current
9774 +#define vxdprintk(c, f, x...) \
9777 + printk(VX_LOGLEVEL VX_PROC_FMT f "\n", \
9778 + VX_PROCESS , ##x); \
9781 +#define vxlprintk(c, f, x...) \
9784 + printk(VX_LOGLEVEL f " @%s:%d\n", x); \
9787 +#define vxfprintk(c, f, x...) \
9790 + printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
9796 +void dump_vx_info(struct vx_info *, int);
9797 +void dump_vx_info_inactive(int);
9799 +#else /* CONFIG_VSERVER_DEBUG */
9801 +#define vs_debug_switch 0
9802 +#define vs_debug_xid 0
9803 +#define vs_debug_nid 0
9804 +#define vs_debug_tag 0
9805 +#define vs_debug_net 0
9806 +#define vs_debug_limit 0
9807 +#define vs_debug_cres 0
9808 +#define vs_debug_dlim 0
9809 +#define vs_debug_quota 0
9810 +#define vs_debug_cvirt 0
9811 +#define vs_debug_space 0
9812 +#define vs_debug_perm 0
9813 +#define vs_debug_misc 0
9815 +#define vxdprintk(x...) do { } while (0)
9816 +#define vxlprintk(x...) do { } while (0)
9817 +#define vxfprintk(x...) do { } while (0)
9819 +#endif /* CONFIG_VSERVER_DEBUG */
9822 +#ifdef CONFIG_VSERVER_WARN
9824 +#define VX_WARNLEVEL KERN_WARNING "vxW: "
9825 +#define VX_WARN_TASK "[" VS_Q("%s") ",%u:#%u|%u|%u] "
9826 +#define VX_WARN_XID "[xid #%u] "
9827 +#define VX_WARN_NID "[nid #%u] "
9828 +#define VX_WARN_TAG "[tag #%u] "
9830 +#define vxwprintk(c, f, x...) \
9833 + printk(VX_WARNLEVEL f "\n", ##x); \
9836 +#else /* CONFIG_VSERVER_WARN */
9838 +#define vxwprintk(x...) do { } while (0)
9840 +#endif /* CONFIG_VSERVER_WARN */
9842 +#define vxwprintk_task(c, f, x...) \
9843 + vxwprintk(c, VX_WARN_TASK f, \
9844 + current->comm, current->pid, \
9845 + current->xid, current->nid, \
9846 + current->tag, ##x)
9847 +#define vxwprintk_xid(c, f, x...) \
9848 + vxwprintk(c, VX_WARN_XID f, current->xid, x)
9849 +#define vxwprintk_nid(c, f, x...) \
9850 + vxwprintk(c, VX_WARN_NID f, current->nid, x)
9851 +#define vxwprintk_tag(c, f, x...) \
9852 + vxwprintk(c, VX_WARN_TAG f, current->tag, x)
9854 +#ifdef CONFIG_VSERVER_DEBUG
9855 +#define vxd_assert_lock(l) assert_spin_locked(l)
9856 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
9857 + "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
9859 +#define vxd_assert_lock(l) do { } while (0)
9860 +#define vxd_assert(c, f, x...) do { } while (0)
9864 +#endif /* _VSERVER_DEBUG_H */
9865 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/debug_cmd.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/debug_cmd.h
9866 --- linux-4.9.76/include/linux/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
9867 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/debug_cmd.h 2018-01-10 02:50:49.000000000 +0000
9869 +#ifndef _VSERVER_DEBUG_CMD_H
9870 +#define _VSERVER_DEBUG_CMD_H
9872 +#include <uapi/vserver/debug_cmd.h>
9875 +#ifdef CONFIG_COMPAT
9877 +#include <asm/compat.h>
9879 +struct vcmd_read_history_v0_x32 {
9882 + compat_uptr_t data_ptr;
9885 +struct vcmd_read_monitor_v0_x32 {
9888 + compat_uptr_t data_ptr;
9891 +#endif /* CONFIG_COMPAT */
9893 +extern int vc_dump_history(uint32_t);
9895 +extern int vc_read_history(uint32_t, void __user *);
9896 +extern int vc_read_monitor(uint32_t, void __user *);
9898 +#ifdef CONFIG_COMPAT
9900 +extern int vc_read_history_x32(uint32_t, void __user *);
9901 +extern int vc_read_monitor_x32(uint32_t, void __user *);
9903 +#endif /* CONFIG_COMPAT */
9905 +#endif /* _VSERVER_DEBUG_CMD_H */
9906 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/device.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/device.h
9907 --- linux-4.9.76/include/linux/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
9908 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/device.h 2018-01-10 02:50:49.000000000 +0000
9910 +#ifndef _VSERVER_DEVICE_H
9911 +#define _VSERVER_DEVICE_H
9914 +#include <uapi/vserver/device.h>
9916 +#else /* _VSERVER_DEVICE_H */
9917 +#warning duplicate inclusion
9918 +#endif /* _VSERVER_DEVICE_H */
9919 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/device_cmd.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/device_cmd.h
9920 --- linux-4.9.76/include/linux/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
9921 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/device_cmd.h 2018-01-10 02:50:49.000000000 +0000
9923 +#ifndef _VSERVER_DEVICE_CMD_H
9924 +#define _VSERVER_DEVICE_CMD_H
9926 +#include <uapi/vserver/device_cmd.h>
9929 +#ifdef CONFIG_COMPAT
9931 +#include <asm/compat.h>
9933 +struct vcmd_set_mapping_v0_x32 {
9934 + compat_uptr_t device_ptr;
9935 + compat_uptr_t target_ptr;
9939 +#endif /* CONFIG_COMPAT */
9941 +#include <linux/compiler.h>
9943 +extern int vc_set_mapping(struct vx_info *, void __user *);
9944 +extern int vc_unset_mapping(struct vx_info *, void __user *);
9946 +#ifdef CONFIG_COMPAT
9948 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
9949 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
9951 +#endif /* CONFIG_COMPAT */
9953 +#endif /* _VSERVER_DEVICE_CMD_H */
9954 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/device_def.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/device_def.h
9955 --- linux-4.9.76/include/linux/vserver/device_def.h 1970-01-01 00:00:00.000000000 +0000
9956 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/device_def.h 2018-01-10 02:50:49.000000000 +0000
9958 +#ifndef _VSERVER_DEVICE_DEF_H
9959 +#define _VSERVER_DEVICE_DEF_H
9961 +#include <linux/types.h>
9963 +struct vx_dmap_target {
9968 +struct _vx_device {
9969 +#ifdef CONFIG_VSERVER_DEVICE
9970 + struct vx_dmap_target targets[2];
9974 +#endif /* _VSERVER_DEVICE_DEF_H */
9975 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/dlimit.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/dlimit.h
9976 --- linux-4.9.76/include/linux/vserver/dlimit.h 1970-01-01 00:00:00.000000000 +0000
9977 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/dlimit.h 2018-01-10 02:50:49.000000000 +0000
9979 +#ifndef _VSERVER_DLIMIT_H
9980 +#define _VSERVER_DLIMIT_H
9982 +#include "switch.h"
9987 +/* keep in sync with CDLIM_INFINITY */
9989 +#define DLIM_INFINITY (~0ULL)
9991 +#include <linux/spinlock.h>
9992 +#include <linux/rcupdate.h>
9994 +struct super_block;
9997 + struct hlist_node dl_hlist; /* linked list of contexts */
9998 + struct rcu_head dl_rcu; /* the rcu head */
9999 + vtag_t dl_tag; /* context tag */
10000 + atomic_t dl_usecnt; /* usage count */
10001 + atomic_t dl_refcnt; /* reference count */
10003 + struct super_block *dl_sb; /* associated superblock */
10005 + spinlock_t dl_lock; /* protect the values */
10007 + unsigned long long dl_space_used; /* used space in bytes */
10008 + unsigned long long dl_space_total; /* maximum space in bytes */
10009 + unsigned long dl_inodes_used; /* used inodes */
10010 + unsigned long dl_inodes_total; /* maximum inodes */
10012 + unsigned int dl_nrlmult; /* non root limit mult */
10017 +extern void rcu_free_dl_info(struct rcu_head *);
10018 +extern void unhash_dl_info(struct dl_info *);
10020 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
10025 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
10027 +typedef uint64_t dlsize_t;
10029 +#endif /* __KERNEL__ */
10030 +#else /* _VSERVER_DLIMIT_H */
10031 +#warning duplicate inclusion
10032 +#endif /* _VSERVER_DLIMIT_H */
10033 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/dlimit_cmd.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/dlimit_cmd.h
10034 --- linux-4.9.76/include/linux/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
10035 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/dlimit_cmd.h 2018-01-10 02:50:49.000000000 +0000
10037 +#ifndef _VSERVER_DLIMIT_CMD_H
10038 +#define _VSERVER_DLIMIT_CMD_H
10040 +#include <uapi/vserver/dlimit_cmd.h>
10043 +#ifdef CONFIG_COMPAT
10045 +#include <asm/compat.h>
10047 +struct vcmd_ctx_dlimit_base_v0_x32 {
10048 + compat_uptr_t name_ptr;
10052 +struct vcmd_ctx_dlimit_v0_x32 {
10053 + compat_uptr_t name_ptr;
10054 + uint32_t space_used; /* used space in kbytes */
10055 + uint32_t space_total; /* maximum space in kbytes */
10056 + uint32_t inodes_used; /* used inodes */
10057 + uint32_t inodes_total; /* maximum inodes */
10058 + uint32_t reserved; /* reserved for root in % */
10062 +#endif /* CONFIG_COMPAT */
10064 +#include <linux/compiler.h>
10066 +extern int vc_add_dlimit(uint32_t, void __user *);
10067 +extern int vc_rem_dlimit(uint32_t, void __user *);
10069 +extern int vc_set_dlimit(uint32_t, void __user *);
10070 +extern int vc_get_dlimit(uint32_t, void __user *);
10072 +#ifdef CONFIG_COMPAT
10074 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
10075 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
10077 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
10078 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
10080 +#endif /* CONFIG_COMPAT */
10082 +#endif /* _VSERVER_DLIMIT_CMD_H */
10083 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/global.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/global.h
10084 --- linux-4.9.76/include/linux/vserver/global.h 1970-01-01 00:00:00.000000000 +0000
10085 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/global.h 2018-01-13 03:51:55.000000000 +0000
10087 +#ifndef _VSERVER_GLOBAL_H
10088 +#define _VSERVER_GLOBAL_H
10091 +extern atomic_t vx_global_ctotal;
10092 +extern atomic_t vx_global_cactive;
10094 +extern atomic_t nx_global_ctotal;
10095 +extern atomic_t nx_global_cactive;
10097 +extern atomic_t vs_global_nsproxy;
10098 +extern atomic_t vs_global_fs;
10099 +extern atomic_t vs_global_mnt_ns;
10100 +extern atomic_t vs_global_uts_ns;
10101 +extern atomic_t vs_global_ipc_ns;
10102 +extern atomic_t vs_global_user_ns;
10103 +extern atomic_t vs_global_pid_ns;
10106 +#endif /* _VSERVER_GLOBAL_H */
10107 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/history.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/history.h
10108 --- linux-4.9.76/include/linux/vserver/history.h 1970-01-01 00:00:00.000000000 +0000
10109 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/history.h 2018-01-10 02:50:49.000000000 +0000
10111 +#ifndef _VSERVER_HISTORY_H
10112 +#define _VSERVER_HISTORY_H
10117 + VXH_THROW_OOPS = 1,
10121 + VXH_INIT_VX_INFO,
10124 + VXH_CLAIM_VX_INFO,
10125 + VXH_RELEASE_VX_INFO,
10126 + VXH_ALLOC_VX_INFO,
10127 + VXH_DEALLOC_VX_INFO,
10128 + VXH_HASH_VX_INFO,
10129 + VXH_UNHASH_VX_INFO,
10131 + VXH_LOOKUP_VX_INFO,
10132 + VXH_CREATE_VX_INFO,
10135 +struct _vxhe_vxi {
10136 + struct vx_info *ptr;
10142 +struct _vxhe_set_clr {
10146 +struct _vxhe_loc_lookup {
10150 +struct _vx_hist_entry {
10152 + unsigned short seq;
10153 + unsigned short type;
10154 + struct _vxhe_vxi vxi;
10156 + struct _vxhe_set_clr sc;
10157 + struct _vxhe_loc_lookup ll;
10161 +#ifdef CONFIG_VSERVER_HISTORY
10163 +extern unsigned volatile int vxh_active;
10165 +struct _vx_hist_entry *vxh_advance(void *loc);
10169 +void __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
10171 + entry->vxi.ptr = vxi;
10173 + entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
10174 + entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
10175 + entry->vxi.xid = vxi->vx_id;
10180 +#define __HERE__ current_text_addr()
10182 +#define __VXH_BODY(__type, __data, __here) \
10183 + struct _vx_hist_entry *entry; \
10185 + preempt_disable(); \
10186 + entry = vxh_advance(__here); \
10188 + entry->type = __type; \
10189 + preempt_enable();
10192 + /* pass vxi only */
10194 +#define __VXH_SMPL \
10195 + __vxh_copy_vxi(entry, vxi)
10198 +void __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
10200 + __VXH_BODY(__type, __VXH_SMPL, __here)
10203 + /* pass vxi and data (void *) */
10205 +#define __VXH_DATA \
10206 + __vxh_copy_vxi(entry, vxi); \
10207 + entry->sc.data = data
10210 +void __vxh_data(struct vx_info *vxi, void *data,
10211 + int __type, void *__here)
10213 + __VXH_BODY(__type, __VXH_DATA, __here)
10216 + /* pass vxi and arg (long) */
10218 +#define __VXH_LONG \
10219 + __vxh_copy_vxi(entry, vxi); \
10220 + entry->ll.arg = arg
10223 +void __vxh_long(struct vx_info *vxi, long arg,
10224 + int __type, void *__here)
10226 + __VXH_BODY(__type, __VXH_LONG, __here)
10231 +void __vxh_throw_oops(void *__here)
10233 + __VXH_BODY(VXH_THROW_OOPS, {}, __here);
10234 + /* prevent further acquisition */
10239 +#define vxh_throw_oops() __vxh_throw_oops(__HERE__);
10241 +#define __vxh_get_vx_info(v, h) __vxh_smpl(v, VXH_GET_VX_INFO, h);
10242 +#define __vxh_put_vx_info(v, h) __vxh_smpl(v, VXH_PUT_VX_INFO, h);
10244 +#define __vxh_init_vx_info(v, d, h) \
10245 + __vxh_data(v, d, VXH_INIT_VX_INFO, h);
10246 +#define __vxh_set_vx_info(v, d, h) \
10247 + __vxh_data(v, d, VXH_SET_VX_INFO, h);
10248 +#define __vxh_clr_vx_info(v, d, h) \
10249 + __vxh_data(v, d, VXH_CLR_VX_INFO, h);
10251 +#define __vxh_claim_vx_info(v, d, h) \
10252 + __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
10253 +#define __vxh_release_vx_info(v, d, h) \
10254 + __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
10256 +#define vxh_alloc_vx_info(v) \
10257 + __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
10258 +#define vxh_dealloc_vx_info(v) \
10259 + __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
10261 +#define vxh_hash_vx_info(v) \
10262 + __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
10263 +#define vxh_unhash_vx_info(v) \
10264 + __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
10266 +#define vxh_loc_vx_info(v, l) \
10267 + __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
10268 +#define vxh_lookup_vx_info(v, l) \
10269 + __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
10270 +#define vxh_create_vx_info(v, l) \
10271 + __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
10273 +extern void vxh_dump_history(void);
10276 +#else /* CONFIG_VSERVER_HISTORY */
10278 +#define __HERE__ 0
10280 +#define vxh_throw_oops() do { } while (0)
10282 +#define __vxh_get_vx_info(v, h) do { } while (0)
10283 +#define __vxh_put_vx_info(v, h) do { } while (0)
10285 +#define __vxh_init_vx_info(v, d, h) do { } while (0)
10286 +#define __vxh_set_vx_info(v, d, h) do { } while (0)
10287 +#define __vxh_clr_vx_info(v, d, h) do { } while (0)
10289 +#define __vxh_claim_vx_info(v, d, h) do { } while (0)
10290 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
10292 +#define vxh_alloc_vx_info(v) do { } while (0)
10293 +#define vxh_dealloc_vx_info(v) do { } while (0)
10295 +#define vxh_hash_vx_info(v) do { } while (0)
10296 +#define vxh_unhash_vx_info(v) do { } while (0)
10298 +#define vxh_loc_vx_info(v, l) do { } while (0)
10299 +#define vxh_lookup_vx_info(v, l) do { } while (0)
10300 +#define vxh_create_vx_info(v, l) do { } while (0)
10302 +#define vxh_dump_history() do { } while (0)
10305 +#endif /* CONFIG_VSERVER_HISTORY */
10307 +#endif /* _VSERVER_HISTORY_H */
10308 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/inode.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/inode.h
10309 --- linux-4.9.76/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
10310 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/inode.h 2018-01-10 02:50:49.000000000 +0000
10312 +#ifndef _VSERVER_INODE_H
10313 +#define _VSERVER_INODE_H
10315 +#include <uapi/vserver/inode.h>
10318 +#ifdef CONFIG_VSERVER_PROC_SECURE
10319 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN | IATTR_HIDE )
10320 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
10322 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN )
10323 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
10326 +#define vx_hide_check(c, m) (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
10328 +#else /* _VSERVER_INODE_H */
10329 +#warning duplicate inclusion
10330 +#endif /* _VSERVER_INODE_H */
10331 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/inode_cmd.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/inode_cmd.h
10332 --- linux-4.9.76/include/linux/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
10333 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/inode_cmd.h 2018-01-10 02:50:49.000000000 +0000
10335 +#ifndef _VSERVER_INODE_CMD_H
10336 +#define _VSERVER_INODE_CMD_H
10338 +#include <uapi/vserver/inode_cmd.h>
10342 +#ifdef CONFIG_COMPAT
10344 +#include <asm/compat.h>
10346 +struct vcmd_ctx_iattr_v1_x32 {
10347 + compat_uptr_t name_ptr;
10353 +#endif /* CONFIG_COMPAT */
10355 +#include <linux/compiler.h>
10357 +extern int vc_get_iattr(void __user *);
10358 +extern int vc_set_iattr(void __user *);
10360 +extern int vc_fget_iattr(uint32_t, void __user *);
10361 +extern int vc_fset_iattr(uint32_t, void __user *);
10363 +#ifdef CONFIG_COMPAT
10365 +extern int vc_get_iattr_x32(void __user *);
10366 +extern int vc_set_iattr_x32(void __user *);
10368 +#endif /* CONFIG_COMPAT */
10370 +#endif /* _VSERVER_INODE_CMD_H */
10371 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/limit.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/limit.h
10372 --- linux-4.9.76/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
10373 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/limit.h 2018-01-10 02:50:49.000000000 +0000
10375 +#ifndef _VSERVER_LIMIT_H
10376 +#define _VSERVER_LIMIT_H
10378 +#include <uapi/vserver/limit.h>
10381 +#define VLIM_NOCHECK ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
10383 +/* keep in sync with CRLIM_INFINITY */
10385 +#define VLIM_INFINITY (~0ULL)
10387 +#include <asm/atomic.h>
10388 +#include <asm/resource.h>
10390 +#ifndef RLIM_INFINITY
10391 +#warning RLIM_INFINITY is undefined
10394 +#define __rlim_val(l, r, v) ((l)->res[r].v)
10396 +#define __rlim_soft(l, r) __rlim_val(l, r, soft)
10397 +#define __rlim_hard(l, r) __rlim_val(l, r, hard)
10399 +#define __rlim_rcur(l, r) __rlim_val(l, r, rcur)
10400 +#define __rlim_rmin(l, r) __rlim_val(l, r, rmin)
10401 +#define __rlim_rmax(l, r) __rlim_val(l, r, rmax)
10403 +#define __rlim_lhit(l, r) __rlim_val(l, r, lhit)
10404 +#define __rlim_hit(l, r) atomic_inc(&__rlim_lhit(l, r))
10406 +typedef atomic_long_t rlim_atomic_t;
10407 +typedef unsigned long rlim_t;
10409 +#define __rlim_get(l, r) atomic_long_read(&__rlim_rcur(l, r))
10410 +#define __rlim_set(l, r, v) atomic_long_set(&__rlim_rcur(l, r), v)
10411 +#define __rlim_inc(l, r) atomic_long_inc(&__rlim_rcur(l, r))
10412 +#define __rlim_dec(l, r) atomic_long_dec(&__rlim_rcur(l, r))
10413 +#define __rlim_add(l, r, v) atomic_long_add(v, &__rlim_rcur(l, r))
10414 +#define __rlim_sub(l, r, v) atomic_long_sub(v, &__rlim_rcur(l, r))
10417 +#if (RLIM_INFINITY == VLIM_INFINITY)
10418 +#define VX_VLIM(r) ((long long)(long)(r))
10419 +#define VX_RLIM(v) ((rlim_t)(v))
10421 +#define VX_VLIM(r) (((r) == RLIM_INFINITY) \
10422 + ? VLIM_INFINITY : (long long)(r))
10423 +#define VX_RLIM(v) (((v) == VLIM_INFINITY) \
10424 + ? RLIM_INFINITY : (rlim_t)(v))
10429 +#ifdef CONFIG_MEMCG
10430 +void vx_vsi_meminfo(struct sysinfo *);
10431 +void vx_vsi_swapinfo(struct sysinfo *);
10432 +long vx_vsi_cached(struct sysinfo *);
10433 +#else /* !CONFIG_MEMCG */
10434 +#define vx_vsi_meminfo(s) do { } while (0)
10435 +#define vx_vsi_swapinfo(s) do { } while (0)
10436 +#define vx_vsi_cached(s) (0L)
10437 +#endif /* !CONFIG_MEMCG */
10439 +#define NUM_LIMITS 24
10441 +#endif /* _VSERVER_LIMIT_H */
10442 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/limit_cmd.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/limit_cmd.h
10443 --- linux-4.9.76/include/linux/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
10444 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/limit_cmd.h 2018-01-10 02:50:49.000000000 +0000
10446 +#ifndef _VSERVER_LIMIT_CMD_H
10447 +#define _VSERVER_LIMIT_CMD_H
10449 +#include <uapi/vserver/limit_cmd.h>
10452 +#ifdef CONFIG_IA32_EMULATION
10454 +struct vcmd_ctx_rlimit_v0_x32 {
10456 + uint64_t minimum;
10457 + uint64_t softlimit;
10458 + uint64_t maximum;
10459 +} __attribute__ ((packed));
10461 +#endif /* CONFIG_IA32_EMULATION */
10463 +#include <linux/compiler.h>
10465 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
10466 +extern int vc_get_rlimit(struct vx_info *, void __user *);
10467 +extern int vc_set_rlimit(struct vx_info *, void __user *);
10468 +extern int vc_reset_hits(struct vx_info *, void __user *);
10469 +extern int vc_reset_minmax(struct vx_info *, void __user *);
10471 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
10473 +#ifdef CONFIG_IA32_EMULATION
10475 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
10476 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
10478 +#endif /* CONFIG_IA32_EMULATION */
10480 +#endif /* _VSERVER_LIMIT_CMD_H */
10481 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/limit_def.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/limit_def.h
10482 --- linux-4.9.76/include/linux/vserver/limit_def.h 1970-01-01 00:00:00.000000000 +0000
10483 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/limit_def.h 2018-01-10 02:50:49.000000000 +0000
10485 +#ifndef _VSERVER_LIMIT_DEF_H
10486 +#define _VSERVER_LIMIT_DEF_H
10488 +#include <asm/atomic.h>
10489 +#include <asm/resource.h>
10491 +#include "limit.h"
10494 +struct _vx_res_limit {
10495 + rlim_t soft; /* Context soft limit */
10496 + rlim_t hard; /* Context hard limit */
10498 + rlim_atomic_t rcur; /* Current value */
10499 + rlim_t rmin; /* Context minimum */
10500 + rlim_t rmax; /* Context maximum */
10502 + atomic_t lhit; /* Limit hits */
10505 +/* context sub struct */
10507 +struct _vx_limit {
10508 + struct _vx_res_limit res[NUM_LIMITS];
10511 +#ifdef CONFIG_VSERVER_DEBUG
10513 +static inline void __dump_vx_limit(struct _vx_limit *limit)
10517 + printk("\t_vx_limit:");
10518 + for (i = 0; i < NUM_LIMITS; i++) {
10519 + printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
10520 + i, (unsigned long)__rlim_get(limit, i),
10521 + (unsigned long)__rlim_rmin(limit, i),
10522 + (unsigned long)__rlim_rmax(limit, i),
10523 + (long)__rlim_soft(limit, i),
10524 + (long)__rlim_hard(limit, i),
10525 + atomic_read(&__rlim_lhit(limit, i)));
10531 +#endif /* _VSERVER_LIMIT_DEF_H */
10532 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/limit_int.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/limit_int.h
10533 --- linux-4.9.76/include/linux/vserver/limit_int.h 1970-01-01 00:00:00.000000000 +0000
10534 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/limit_int.h 2018-01-10 02:50:49.000000000 +0000
10536 +#ifndef _VSERVER_LIMIT_INT_H
10537 +#define _VSERVER_LIMIT_INT_H
10539 +#define VXD_RCRES_COND(r) VXD_CBIT(cres, r)
10540 +#define VXD_RLIMIT_COND(r) VXD_CBIT(limit, r)
10542 +extern const char *vlimit_name[NUM_LIMITS];
10544 +static inline void __vx_acc_cres(struct vx_info *vxi,
10545 + int res, int dir, void *_data, char *_file, int _line)
10547 + if (VXD_RCRES_COND(res))
10548 + vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
10549 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10550 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10551 + (dir > 0) ? "++" : "--", _data, _file, _line);
10556 + __rlim_inc(&vxi->limit, res);
10558 + __rlim_dec(&vxi->limit, res);
10561 +static inline void __vx_add_cres(struct vx_info *vxi,
10562 + int res, int amount, void *_data, char *_file, int _line)
10564 + if (VXD_RCRES_COND(res))
10565 + vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
10566 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10567 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10568 + amount, _data, _file, _line);
10573 + __rlim_add(&vxi->limit, res, amount);
10577 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
10579 + int cond = (value > __rlim_rmax(limit, res));
10582 + __rlim_rmax(limit, res) = value;
10587 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
10589 + int cond = (value < __rlim_rmin(limit, res));
10592 + __rlim_rmin(limit, res) = value;
10597 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
10599 + if (!__vx_cres_adjust_max(limit, res, value))
10600 + __vx_cres_adjust_min(limit, res, value);
10605 + +1 ... no limit hit
10606 + -1 ... over soft limit
10607 + 0 ... over hard limit */
10609 +static inline int __vx_cres_avail(struct vx_info *vxi,
10610 + int res, int num, char *_file, int _line)
10612 + struct _vx_limit *limit;
10615 + if (VXD_RLIMIT_COND(res))
10616 + vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
10617 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10618 + (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
10619 + (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
10620 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10621 + num, _file, _line);
10625 + limit = &vxi->limit;
10626 + value = __rlim_get(limit, res);
10628 + if (!__vx_cres_adjust_max(limit, res, value))
10629 + __vx_cres_adjust_min(limit, res, value);
10634 + if (__rlim_soft(limit, res) == RLIM_INFINITY)
10636 + if (value + num <= __rlim_soft(limit, res))
10639 + if (__rlim_hard(limit, res) == RLIM_INFINITY)
10641 + if (value + num <= __rlim_hard(limit, res))
10644 + __rlim_hit(limit, res);
10649 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
10652 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
10654 + rlim_t value, sum = 0;
10657 + while ((res = *array++)) {
10658 + value = __rlim_get(limit, res);
10659 + __vx_cres_fixup(limit, res, value);
10666 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
10668 + rlim_t value = __vx_cres_array_sum(limit, array + 1);
10669 + int res = *array;
10671 + if (value == __rlim_get(limit, res))
10674 + __rlim_set(limit, res, value);
10675 + /* now adjust min/max */
10676 + if (!__vx_cres_adjust_max(limit, res, value))
10677 + __vx_cres_adjust_min(limit, res, value);
10682 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
10683 + const int *array, int num, char *_file, int _line)
10685 + struct _vx_limit *limit;
10686 + rlim_t value = 0;
10694 + limit = &vxi->limit;
10696 + value = __vx_cres_array_sum(limit, array + 1);
10698 + __rlim_set(limit, res, value);
10699 + __vx_cres_fixup(limit, res, value);
10701 + return __vx_cres_avail(vxi, res, num, _file, _line);
10705 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
10710 + /* complex resources first */
10711 + if ((id < 0) || (id == RLIMIT_RSS))
10712 + __vx_cres_array_fixup(limit, VLA_RSS);
10714 + for (res = 0; res < NUM_LIMITS; res++) {
10715 + if ((id > 0) && (res != id))
10718 + value = __rlim_get(limit, res);
10719 + __vx_cres_fixup(limit, res, value);
10721 + /* not supposed to happen, maybe warn? */
10722 + if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
10723 + __rlim_rmax(limit, res) = __rlim_hard(limit, res);
10728 +#endif /* _VSERVER_LIMIT_INT_H */
10729 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/monitor.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/monitor.h
10730 --- linux-4.9.76/include/linux/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
10731 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/monitor.h 2018-01-10 02:50:49.000000000 +0000
10733 +#ifndef _VSERVER_MONITOR_H
10734 +#define _VSERVER_MONITOR_H
10736 +#include <uapi/vserver/monitor.h>
10738 +#endif /* _VSERVER_MONITOR_H */
10739 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/network.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/network.h
10740 --- linux-4.9.76/include/linux/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
10741 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/network.h 2018-01-10 02:50:49.000000000 +0000
10743 +#ifndef _VSERVER_NETWORK_H
10744 +#define _VSERVER_NETWORK_H
10747 +#include <linux/list.h>
10748 +#include <linux/spinlock.h>
10749 +#include <linux/rcupdate.h>
10750 +#include <linux/in.h>
10751 +#include <linux/in6.h>
10752 +#include <asm/atomic.h>
10753 +#include <uapi/vserver/network.h>
10755 +struct nx_addr_v4 {
10756 + struct nx_addr_v4 *next;
10757 + struct in_addr ip[2];
10758 + struct in_addr mask;
10763 +struct nx_addr_v6 {
10764 + struct nx_addr_v6 *next;
10765 + struct in6_addr ip;
10766 + struct in6_addr mask;
10773 + struct hlist_node nx_hlist; /* linked list of nxinfos */
10774 + vnid_t nx_id; /* vnet id */
10775 + atomic_t nx_usecnt; /* usage count */
10776 + atomic_t nx_tasks; /* tasks count */
10777 + int nx_state; /* context state */
10779 + uint64_t nx_flags; /* network flag word */
10780 + uint64_t nx_ncaps; /* network capabilities */
10782 + spinlock_t addr_lock; /* protect address changes */
10783 + struct in_addr v4_lback; /* Loopback address */
10784 + struct in_addr v4_bcast; /* Broadcast address */
10785 + struct nx_addr_v4 v4; /* First/Single ipv4 address */
10786 +#ifdef CONFIG_IPV6
10787 + struct nx_addr_v6 v6; /* First/Single ipv6 address */
10789 + char nx_name[65]; /* network context name */
10793 +/* status flags */
10795 +#define NXS_HASHED 0x0001
10796 +#define NXS_SHUTDOWN 0x0100
10797 +#define NXS_RELEASED 0x8000
10799 +extern struct nx_info *lookup_nx_info(int);
10801 +extern int get_nid_list(int, unsigned int *, int);
10802 +extern int nid_is_hashed(vnid_t);
10804 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
10806 +extern long vs_net_change(struct nx_info *, unsigned int);
10811 +#define NX_IPV4(n) ((n)->v4.type != NXA_TYPE_NONE)
10812 +#ifdef CONFIG_IPV6
10813 +#define NX_IPV6(n) ((n)->v6.type != NXA_TYPE_NONE)
10815 +#define NX_IPV6(n) (0)
10818 +#endif /* _VSERVER_NETWORK_H */
10819 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/network_cmd.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/network_cmd.h
10820 --- linux-4.9.76/include/linux/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
10821 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/network_cmd.h 2018-01-10 02:50:49.000000000 +0000
10823 +#ifndef _VSERVER_NETWORK_CMD_H
10824 +#define _VSERVER_NETWORK_CMD_H
10826 +#include <uapi/vserver/network_cmd.h>
10828 +extern int vc_task_nid(uint32_t);
10830 +extern int vc_nx_info(struct nx_info *, void __user *);
10832 +extern int vc_net_create(uint32_t, void __user *);
10833 +extern int vc_net_migrate(struct nx_info *, void __user *);
10835 +extern int vc_net_add(struct nx_info *, void __user *);
10836 +extern int vc_net_remove(struct nx_info *, void __user *);
10838 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
10839 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
10841 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
10842 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
10844 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
10845 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
10847 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
10848 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
10850 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
10851 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
10853 +extern int vc_get_nflags(struct nx_info *, void __user *);
10854 +extern int vc_set_nflags(struct nx_info *, void __user *);
10856 +extern int vc_get_ncaps(struct nx_info *, void __user *);
10857 +extern int vc_set_ncaps(struct nx_info *, void __user *);
10859 +#endif /* _VSERVER_CONTEXT_CMD_H */
10860 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/percpu.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/percpu.h
10861 --- linux-4.9.76/include/linux/vserver/percpu.h 1970-01-01 00:00:00.000000000 +0000
10862 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/percpu.h 2018-01-10 02:50:49.000000000 +0000
10864 +#ifndef _VSERVER_PERCPU_H
10865 +#define _VSERVER_PERCPU_H
10867 +#include "cvirt_def.h"
10868 +#include "sched_def.h"
10870 +struct _vx_percpu {
10871 + struct _vx_cvirt_pc cvirt;
10872 + struct _vx_sched_pc sched;
10875 +#define PERCPU_PERCTX (sizeof(struct _vx_percpu))
10877 +#endif /* _VSERVER_PERCPU_H */
10878 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/pid.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/pid.h
10879 --- linux-4.9.76/include/linux/vserver/pid.h 1970-01-01 00:00:00.000000000 +0000
10880 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/pid.h 2018-01-10 02:50:49.000000000 +0000
10882 +#ifndef _VSERVER_PID_H
10883 +#define _VSERVER_PID_H
10885 +/* pid faking stuff */
10887 +#define vx_info_map_pid(v, p) \
10888 + __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
10889 +#define vx_info_map_tgid(v,p) vx_info_map_pid(v,p)
10890 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
10891 +#define vx_map_tgid(p) vx_map_pid(p)
10893 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
10894 + const char *func, const char *file, int line)
10896 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
10897 + vxfprintk(VXD_CBIT(cvirt, 2),
10898 + "vx_map_tgid: %p/%llx: %d -> %d",
10899 + vxi, (long long)vxi->vx_flags, pid,
10900 + (pid && pid == vxi->vx_initpid) ? 1 : pid,
10901 + func, file, line);
10904 + if (pid == vxi->vx_initpid)
10910 +#define vx_info_rmap_pid(v, p) \
10911 + __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
10912 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
10913 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
10915 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
10916 + const char *func, const char *file, int line)
10918 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
10919 + vxfprintk(VXD_CBIT(cvirt, 2),
10920 + "vx_rmap_tgid: %p/%llx: %d -> %d",
10921 + vxi, (long long)vxi->vx_flags, pid,
10922 + (pid == 1) ? vxi->vx_initpid : pid,
10923 + func, file, line);
10924 + if ((pid == 1) && vxi->vx_initpid)
10925 + return vxi->vx_initpid;
10926 + if (pid == vxi->vx_initpid)
10933 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/sched.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/sched.h
10934 --- linux-4.9.76/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
10935 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/sched.h 2018-01-10 02:50:49.000000000 +0000
10937 +#ifndef _VSERVER_SCHED_H
10938 +#define _VSERVER_SCHED_H
10945 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10950 +void vx_update_load(struct vx_info *);
10953 +void vx_update_sched_param(struct _vx_sched *sched,
10954 + struct _vx_sched_pc *sched_pc);
10956 +#endif /* __KERNEL__ */
10957 +#else /* _VSERVER_SCHED_H */
10958 +#warning duplicate inclusion
10959 +#endif /* _VSERVER_SCHED_H */
10960 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/sched_cmd.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/sched_cmd.h
10961 --- linux-4.9.76/include/linux/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
10962 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/sched_cmd.h 2018-01-10 02:50:49.000000000 +0000
10964 +#ifndef _VSERVER_SCHED_CMD_H
10965 +#define _VSERVER_SCHED_CMD_H
10968 +#include <linux/compiler.h>
10969 +#include <uapi/vserver/sched_cmd.h>
10971 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
10972 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
10974 +#endif /* _VSERVER_SCHED_CMD_H */
10975 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/sched_def.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/sched_def.h
10976 --- linux-4.9.76/include/linux/vserver/sched_def.h 1970-01-01 00:00:00.000000000 +0000
10977 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/sched_def.h 2018-01-10 02:50:49.000000000 +0000
10979 +#ifndef _VSERVER_SCHED_DEF_H
10980 +#define _VSERVER_SCHED_DEF_H
10982 +#include <linux/spinlock.h>
10983 +#include <linux/jiffies.h>
10984 +#include <linux/cpumask.h>
10985 +#include <asm/atomic.h>
10986 +#include <asm/param.h>
10989 +/* context sub struct */
10991 +struct _vx_sched {
10992 + int prio_bias; /* bias offset for priority */
10994 + cpumask_t update; /* CPUs which should update */
10997 +struct _vx_sched_pc {
10998 + int prio_bias; /* bias offset for priority */
11000 + uint64_t user_ticks; /* token tick events */
11001 + uint64_t sys_ticks; /* token tick events */
11002 + uint64_t hold_ticks; /* token ticks paused */
11006 +#ifdef CONFIG_VSERVER_DEBUG
11008 +static inline void __dump_vx_sched(struct _vx_sched *sched)
11010 + printk("\t_vx_sched:\n");
11011 + printk("\t priority = %4d\n", sched->prio_bias);
11016 +#endif /* _VSERVER_SCHED_DEF_H */
11017 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/signal.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/signal.h
11018 --- linux-4.9.76/include/linux/vserver/signal.h 1970-01-01 00:00:00.000000000 +0000
11019 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/signal.h 2018-01-10 02:50:49.000000000 +0000
11021 +#ifndef _VSERVER_SIGNAL_H
11022 +#define _VSERVER_SIGNAL_H
11029 +int vx_info_kill(struct vx_info *, int, int);
11031 +#endif /* __KERNEL__ */
11032 +#else /* _VSERVER_SIGNAL_H */
11033 +#warning duplicate inclusion
11034 +#endif /* _VSERVER_SIGNAL_H */
11035 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/signal_cmd.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/signal_cmd.h
11036 --- linux-4.9.76/include/linux/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
11037 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/signal_cmd.h 2018-01-10 02:50:49.000000000 +0000
11039 +#ifndef _VSERVER_SIGNAL_CMD_H
11040 +#define _VSERVER_SIGNAL_CMD_H
11042 +#include <uapi/vserver/signal_cmd.h>
11045 +extern int vc_ctx_kill(struct vx_info *, void __user *);
11046 +extern int vc_wait_exit(struct vx_info *, void __user *);
11049 +extern int vc_get_pflags(uint32_t pid, void __user *);
11050 +extern int vc_set_pflags(uint32_t pid, void __user *);
11052 +#endif /* _VSERVER_SIGNAL_CMD_H */
11053 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/space.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/space.h
11054 --- linux-4.9.76/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
11055 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/space.h 2018-01-10 02:50:49.000000000 +0000
11057 +#ifndef _VSERVER_SPACE_H
11058 +#define _VSERVER_SPACE_H
11060 +#include <linux/types.h>
11064 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
11066 +#else /* _VSERVER_SPACE_H */
11067 +#warning duplicate inclusion
11068 +#endif /* _VSERVER_SPACE_H */
11069 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/space_cmd.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/space_cmd.h
11070 --- linux-4.9.76/include/linux/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
11071 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/space_cmd.h 2018-01-10 02:50:49.000000000 +0000
11073 +#ifndef _VSERVER_SPACE_CMD_H
11074 +#define _VSERVER_SPACE_CMD_H
11076 +#include <uapi/vserver/space_cmd.h>
11079 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
11080 +extern int vc_set_space_v1(struct vx_info *, void __user *);
11081 +extern int vc_enter_space(struct vx_info *, void __user *);
11082 +extern int vc_set_space(struct vx_info *, void __user *);
11083 +extern int vc_get_space_mask(void __user *, int);
11085 +#endif /* _VSERVER_SPACE_CMD_H */
11086 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/switch.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/switch.h
11087 --- linux-4.9.76/include/linux/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
11088 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/switch.h 2018-01-10 02:50:49.000000000 +0000
11090 +#ifndef _VSERVER_SWITCH_H
11091 +#define _VSERVER_SWITCH_H
11094 +#include <linux/errno.h>
11095 +#include <uapi/vserver/switch.h>
11097 +#endif /* _VSERVER_SWITCH_H */
11098 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/tag.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/tag.h
11099 --- linux-4.9.76/include/linux/vserver/tag.h 1970-01-01 00:00:00.000000000 +0000
11100 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/tag.h 2018-01-10 02:50:49.000000000 +0000
11105 +#include <linux/types.h>
11106 +#include <linux/uidgid.h>
11109 +#define DX_TAG(in) (IS_TAGGED(in))
11112 +#ifdef CONFIG_TAG_NFSD
11113 +#define DX_TAG_NFSD 1
11115 +#define DX_TAG_NFSD 0
11119 +#ifdef CONFIG_TAGGING_NONE
11121 +#define MAX_UID 0xFFFFFFFF
11122 +#define MAX_GID 0xFFFFFFFF
11124 +#define INOTAG_TAG(cond, uid, gid, tag) (0)
11126 +#define TAGINO_UID(cond, uid, tag) (uid)
11127 +#define TAGINO_GID(cond, gid, tag) (gid)
11132 +#ifdef CONFIG_TAGGING_GID16
11134 +#define MAX_UID 0xFFFFFFFF
11135 +#define MAX_GID 0x0000FFFF
11137 +#define INOTAG_TAG(cond, uid, gid, tag) \
11138 + ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
11140 +#define TAGINO_UID(cond, uid, tag) (uid)
11141 +#define TAGINO_GID(cond, gid, tag) \
11142 + ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
11147 +#ifdef CONFIG_TAGGING_ID24
11149 +#define MAX_UID 0x00FFFFFF
11150 +#define MAX_GID 0x00FFFFFF
11152 +#define INOTAG_TAG(cond, uid, gid, tag) \
11153 + ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
11155 +#define TAGINO_UID(cond, uid, tag) \
11156 + ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
11157 +#define TAGINO_GID(cond, gid, tag) \
11158 + ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
11163 +#ifdef CONFIG_TAGGING_UID16
11165 +#define MAX_UID 0x0000FFFF
11166 +#define MAX_GID 0xFFFFFFFF
11168 +#define INOTAG_TAG(cond, uid, gid, tag) \
11169 + ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
11171 +#define TAGINO_UID(cond, uid, tag) \
11172 + ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
11173 +#define TAGINO_GID(cond, gid, tag) (gid)
11178 +#ifdef CONFIG_TAGGING_INTERN
11180 +#define MAX_UID 0xFFFFFFFF
11181 +#define MAX_GID 0xFFFFFFFF
11183 +#define INOTAG_TAG(cond, uid, gid, tag) \
11184 + ((cond) ? (tag) : 0)
11186 +#define TAGINO_UID(cond, uid, tag) (uid)
11187 +#define TAGINO_GID(cond, gid, tag) (gid)
11192 +#ifndef CONFIG_TAGGING_NONE
11193 +#define dx_current_fstag(sb) \
11194 + ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
11196 +#define dx_current_fstag(sb) (0)
11199 +#ifndef CONFIG_TAGGING_INTERN
11200 +#define TAGINO_TAG(cond, tag) (0)
11202 +#define TAGINO_TAG(cond, tag) ((cond) ? (tag) : 0)
11205 +#define TAGINO_KUID(cond, kuid, ktag) \
11206 + KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
11207 +#define TAGINO_KGID(cond, kgid, ktag) \
11208 + KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
11209 +#define TAGINO_KTAG(cond, ktag) \
11210 + KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
11213 +#define INOTAG_UID(cond, uid, gid) \
11214 + ((cond) ? ((uid) & MAX_UID) : (uid))
11215 +#define INOTAG_GID(cond, uid, gid) \
11216 + ((cond) ? ((gid) & MAX_GID) : (gid))
11218 +#define INOTAG_KUID(cond, kuid, kgid) \
11219 + KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11220 +#define INOTAG_KGID(cond, kuid, kgid) \
11221 + KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11222 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
11223 + KTAGT_INIT(INOTAG_TAG(cond, \
11224 + __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
11227 +static inline uid_t dx_map_uid(uid_t uid)
11229 + if ((uid > MAX_UID) && (uid != -1))
11231 + return (uid & MAX_UID);
11234 +static inline gid_t dx_map_gid(gid_t gid)
11236 + if ((gid > MAX_GID) && (gid != -1))
11238 + return (gid & MAX_GID);
11246 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
11248 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
11249 + unsigned long *flags);
11251 +#ifdef CONFIG_PROPAGATE
11253 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
11255 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
11258 +#define dx_propagate_tag(n, i) do { } while (0)
11261 +#endif /* _DX_TAG_H */
11262 diff -NurpP --minimal linux-4.9.76/include/linux/vserver/tag_cmd.h linux-4.9.76-vs2.3.9.5/include/linux/vserver/tag_cmd.h
11263 --- linux-4.9.76/include/linux/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
11264 +++ linux-4.9.76-vs2.3.9.5/include/linux/vserver/tag_cmd.h 2018-01-10 02:50:49.000000000 +0000
11266 +#ifndef _VSERVER_TAG_CMD_H
11267 +#define _VSERVER_TAG_CMD_H
11269 +#include <uapi/vserver/tag_cmd.h>
11271 +extern int vc_task_tag(uint32_t);
11273 +extern int vc_tag_migrate(uint32_t);
11275 +#endif /* _VSERVER_TAG_CMD_H */
11276 diff -NurpP --minimal linux-4.9.76/include/net/addrconf.h linux-4.9.76-vs2.3.9.5/include/net/addrconf.h
11277 --- linux-4.9.76/include/net/addrconf.h 2018-01-13 21:29:00.000000000 +0000
11278 +++ linux-4.9.76-vs2.3.9.5/include/net/addrconf.h 2018-01-10 02:50:49.000000000 +0000
11279 @@ -85,7 +85,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
11281 int ipv6_dev_get_saddr(struct net *net, const struct net_device *dev,
11282 const struct in6_addr *daddr, unsigned int srcprefs,
11283 - struct in6_addr *saddr);
11284 + struct in6_addr *saddr, struct nx_info *nxi);
11285 int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
11287 int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
11288 diff -NurpP --minimal linux-4.9.76/include/net/af_unix.h linux-4.9.76-vs2.3.9.5/include/net/af_unix.h
11289 --- linux-4.9.76/include/net/af_unix.h 2016-12-11 19:17:54.000000000 +0000
11290 +++ linux-4.9.76-vs2.3.9.5/include/net/af_unix.h 2018-01-10 02:50:49.000000000 +0000
11292 #include <linux/socket.h>
11293 #include <linux/un.h>
11294 #include <linux/mutex.h>
11295 +// #include <linux/vs_base.h>
11296 #include <net/sock.h>
11298 void unix_inflight(struct user_struct *user, struct file *fp);
11299 diff -NurpP --minimal linux-4.9.76/include/net/inet_timewait_sock.h linux-4.9.76-vs2.3.9.5/include/net/inet_timewait_sock.h
11300 --- linux-4.9.76/include/net/inet_timewait_sock.h 2016-12-11 19:17:54.000000000 +0000
11301 +++ linux-4.9.76-vs2.3.9.5/include/net/inet_timewait_sock.h 2018-01-10 02:50:49.000000000 +0000
11302 @@ -71,6 +71,10 @@ struct inet_timewait_sock {
11303 #define tw_num __tw_common.skc_num
11304 #define tw_cookie __tw_common.skc_cookie
11305 #define tw_dr __tw_common.skc_tw_dr
11306 +#define tw_xid __tw_common.skc_xid
11307 +#define tw_vx_info __tw_common.skc_vx_info
11308 +#define tw_nid __tw_common.skc_nid
11309 +#define tw_nx_info __tw_common.skc_nx_info
11312 volatile unsigned char tw_substate;
11313 diff -NurpP --minimal linux-4.9.76/include/net/ip6_route.h linux-4.9.76-vs2.3.9.5/include/net/ip6_route.h
11314 --- linux-4.9.76/include/net/ip6_route.h 2018-01-13 21:29:00.000000000 +0000
11315 +++ linux-4.9.76-vs2.3.9.5/include/net/ip6_route.h 2018-01-13 06:10:51.000000000 +0000
11316 @@ -26,6 +26,7 @@ struct route_info {
11317 #include <linux/ip.h>
11318 #include <linux/ipv6.h>
11319 #include <linux/route.h>
11320 +#include <linux/vs_inet6.h>
11322 #define RT6_LOOKUP_F_IFACE 0x00000001
11323 #define RT6_LOOKUP_F_REACHABLE 0x00000002
11324 @@ -98,17 +99,19 @@ int ip6_del_rt(struct rt6_info *);
11325 static inline int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
11326 const struct in6_addr *daddr,
11327 unsigned int prefs,
11328 - struct in6_addr *saddr)
11329 + struct in6_addr *saddr,
11330 + struct nx_info *nxi)
11332 struct inet6_dev *idev =
11333 rt ? ip6_dst_idev((struct dst_entry *)rt) : NULL;
11336 - if (rt && rt->rt6i_prefsrc.plen)
11337 + if (rt && rt->rt6i_prefsrc.plen && (!nxi ||
11338 + v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
11339 *saddr = rt->rt6i_prefsrc.addr;
11341 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
11342 - daddr, prefs, saddr);
11343 + daddr, prefs, saddr, nxi);
11347 diff -NurpP --minimal linux-4.9.76/include/net/route.h linux-4.9.76-vs2.3.9.5/include/net/route.h
11348 --- linux-4.9.76/include/net/route.h 2016-12-11 19:17:54.000000000 +0000
11349 +++ linux-4.9.76-vs2.3.9.5/include/net/route.h 2018-01-10 07:57:27.000000000 +0000
11350 @@ -225,6 +225,9 @@ static inline void ip_rt_put(struct rtab
11351 dst_release(&rt->dst);
11354 +#include <linux/vs_base.h>
11355 +#include <linux/vs_inet.h>
11357 #define IPTOS_RT_MASK (IPTOS_TOS_MASK & ~3)
11359 extern const __u8 ip_tos2prio[16];
11360 @@ -272,6 +275,9 @@ static inline void ip_route_connect_init
11361 protocol, flow_flags, dst, src, dport, sport);
11364 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
11365 + struct flowi4 *);
11367 static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
11368 __be32 dst, __be32 src, u32 tos,
11369 int oif, u8 protocol,
11370 @@ -280,11 +286,25 @@ static inline struct rtable *ip_route_co
11372 struct net *net = sock_net(sk);
11374 + struct nx_info *nx_info = current_nx_info();
11376 ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
11379 - if (!dst || !src) {
11381 + nx_info = sk->sk_nx_info;
11383 + vxdprintk(VXD_CBIT(net, 4),
11384 + "ip_route_connect(%p) %p,%p;%lx",
11385 + sk, nx_info, sk->sk_socket,
11386 + (sk->sk_socket?sk->sk_socket->flags:0));
11388 + rt = ip_v4_find_src(net, nx_info, fl4);
11393 + if (!fl4->daddr || !fl4->saddr) {
11394 rt = __ip_route_output_key(net, fl4);
11397 diff -NurpP --minimal linux-4.9.76/include/net/sock.h linux-4.9.76-vs2.3.9.5/include/net/sock.h
11398 --- linux-4.9.76/include/net/sock.h 2018-01-13 21:29:00.000000000 +0000
11399 +++ linux-4.9.76-vs2.3.9.5/include/net/sock.h 2018-01-10 02:50:49.000000000 +0000
11400 @@ -187,6 +187,10 @@ struct sock_common {
11401 struct in6_addr skc_v6_daddr;
11402 struct in6_addr skc_v6_rcv_saddr;
11405 + struct vx_info *skc_vx_info;
11407 + struct nx_info *skc_nx_info;
11409 atomic64_t skc_cookie;
11411 @@ -336,8 +340,12 @@ struct sock {
11412 #define sk_prot __sk_common.skc_prot
11413 #define sk_net __sk_common.skc_net
11414 #define sk_v6_daddr __sk_common.skc_v6_daddr
11415 -#define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
11416 +#define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
11417 #define sk_cookie __sk_common.skc_cookie
11418 +#define sk_xid __sk_common.skc_xid
11419 +#define sk_vx_info __sk_common.skc_vx_info
11420 +#define sk_nid __sk_common.skc_nid
11421 +#define sk_nx_info __sk_common.skc_nx_info
11422 #define sk_incoming_cpu __sk_common.skc_incoming_cpu
11423 #define sk_flags __sk_common.skc_flags
11424 #define sk_rxhash __sk_common.skc_rxhash
11425 diff -NurpP --minimal linux-4.9.76/include/uapi/Kbuild linux-4.9.76-vs2.3.9.5/include/uapi/Kbuild
11426 --- linux-4.9.76/include/uapi/Kbuild 2016-12-11 19:17:54.000000000 +0000
11427 +++ linux-4.9.76-vs2.3.9.5/include/uapi/Kbuild 2018-01-10 02:50:49.000000000 +0000
11428 @@ -13,3 +13,4 @@ header-y += drm/
11432 +header-y += vserver/
11433 diff -NurpP --minimal linux-4.9.76/include/uapi/linux/btrfs_tree.h linux-4.9.76-vs2.3.9.5/include/uapi/linux/btrfs_tree.h
11434 --- linux-4.9.76/include/uapi/linux/btrfs_tree.h 2016-12-11 19:17:54.000000000 +0000
11435 +++ linux-4.9.76-vs2.3.9.5/include/uapi/linux/btrfs_tree.h 2018-01-13 01:45:34.000000000 +0000
11436 @@ -563,11 +563,14 @@ struct btrfs_inode_item {
11437 /* modification sequence number for NFS */
11442 * a little future expansion, for more than this we can
11443 * just grow the inode item and version it
11445 - __le64 reserved[4];
11446 + __le16 reserved16;
11447 + __le32 reserved32;
11448 + __le64 reserved[3];
11449 struct btrfs_timespec atime;
11450 struct btrfs_timespec ctime;
11451 struct btrfs_timespec mtime;
11452 diff -NurpP --minimal linux-4.9.76/include/uapi/linux/capability.h linux-4.9.76-vs2.3.9.5/include/uapi/linux/capability.h
11453 --- linux-4.9.76/include/uapi/linux/capability.h 2016-12-11 19:17:54.000000000 +0000
11454 +++ linux-4.9.76-vs2.3.9.5/include/uapi/linux/capability.h 2018-01-10 02:50:49.000000000 +0000
11455 @@ -257,6 +257,7 @@ struct vfs_cap_data {
11456 arbitrary SCSI commands */
11457 /* Allow setting encryption key on loopback filesystem */
11458 /* Allow setting zone reclaim policy */
11459 +/* Allow the selection of a security context */
11461 #define CAP_SYS_ADMIN 21
11463 @@ -352,7 +353,12 @@ struct vfs_cap_data {
11465 #define CAP_LAST_CAP CAP_AUDIT_READ
11467 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
11468 +/* Allow context manipulations */
11469 +/* Allow changing context info on files */
11471 +#define CAP_CONTEXT 63
11473 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
11476 * Bit location of each capability (used by user-space library and kernel)
11477 diff -NurpP --minimal linux-4.9.76/include/uapi/linux/fs.h linux-4.9.76-vs2.3.9.5/include/uapi/linux/fs.h
11478 --- linux-4.9.76/include/uapi/linux/fs.h 2018-01-13 21:29:00.000000000 +0000
11479 +++ linux-4.9.76-vs2.3.9.5/include/uapi/linux/fs.h 2018-01-10 08:09:10.000000000 +0000
11480 @@ -130,6 +130,9 @@ struct inodes_stat_t {
11481 #define MS_I_VERSION (1<<23) /* Update inode I_version field */
11482 #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
11483 #define MS_LAZYTIME (1<<25) /* Update the on-disk [acm]times lazily */
11484 +#define MS_TAGGED (1<<8) /* use generic inode tagging */
11485 +#define MS_NOTAGCHECK (1<<9) /* don't check tags */
11486 +#define MS_TAGID (1<<26) /* use specific tag for this mount */
11488 /* These sb flags are internal to the kernel */
11489 #define MS_SUBMOUNT (1<<26)
11490 @@ -313,13 +316,16 @@ struct fscrypt_policy {
11491 #define FS_EA_INODE_FL 0x00200000 /* Inode used for large EA */
11492 #define FS_EOFBLOCKS_FL 0x00400000 /* Reserved for ext4 */
11493 #define FS_NOCOW_FL 0x00800000 /* Do not cow file */
11494 +#define FS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
11495 #define FS_INLINE_DATA_FL 0x10000000 /* Reserved for ext4 */
11496 #define FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */
11497 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
11499 -#define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
11500 -#define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
11501 +#define FS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
11502 +#define FS_COW_FL 0x20000000 /* Copy on Write marker */
11504 +#define FS_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
11505 +#define FS_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
11507 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
11508 #define SYNC_FILE_RANGE_WRITE 2
11509 diff -NurpP --minimal linux-4.9.76/include/uapi/linux/gfs2_ondisk.h linux-4.9.76-vs2.3.9.5/include/uapi/linux/gfs2_ondisk.h
11510 --- linux-4.9.76/include/uapi/linux/gfs2_ondisk.h 2016-12-11 19:17:54.000000000 +0000
11511 +++ linux-4.9.76-vs2.3.9.5/include/uapi/linux/gfs2_ondisk.h 2018-01-10 02:50:49.000000000 +0000
11512 @@ -225,6 +225,9 @@ enum {
11515 gfs2fl_TopLevel = 10,
11516 + gfs2fl_IXUnlink = 16,
11517 + gfs2fl_Barrier = 17,
11519 gfs2fl_TruncInProg = 29,
11520 gfs2fl_InheritDirectio = 30,
11521 gfs2fl_InheritJdata = 31,
11522 @@ -242,6 +245,9 @@ enum {
11523 #define GFS2_DIF_SYNC 0x00000100
11524 #define GFS2_DIF_SYSTEM 0x00000200 /* New in gfs2 */
11525 #define GFS2_DIF_TOPDIR 0x00000400 /* New in gfs2 */
11526 +#define GFS2_DIF_IXUNLINK 0x00010000
11527 +#define GFS2_DIF_BARRIER 0x00020000
11528 +#define GFS2_DIF_COW 0x00040000
11529 #define GFS2_DIF_TRUNC_IN_PROG 0x20000000 /* New in gfs2 */
11530 #define GFS2_DIF_INHERIT_DIRECTIO 0x40000000 /* only in gfs1 */
11531 #define GFS2_DIF_INHERIT_JDATA 0x80000000
11532 diff -NurpP --minimal linux-4.9.76/include/uapi/linux/if_tun.h linux-4.9.76-vs2.3.9.5/include/uapi/linux/if_tun.h
11533 --- linux-4.9.76/include/uapi/linux/if_tun.h 2016-12-11 19:17:54.000000000 +0000
11534 +++ linux-4.9.76-vs2.3.9.5/include/uapi/linux/if_tun.h 2018-01-10 02:50:49.000000000 +0000
11537 #define TUNSETVNETBE _IOW('T', 222, int)
11538 #define TUNGETVNETBE _IOR('T', 223, int)
11539 +#define TUNSETNID _IOW('T', 224, int)
11541 /* TUNSETIFF ifr flags */
11542 #define IFF_TUN 0x0001
11543 diff -NurpP --minimal linux-4.9.76/include/uapi/linux/major.h linux-4.9.76-vs2.3.9.5/include/uapi/linux/major.h
11544 --- linux-4.9.76/include/uapi/linux/major.h 2016-12-11 19:17:54.000000000 +0000
11545 +++ linux-4.9.76-vs2.3.9.5/include/uapi/linux/major.h 2018-01-10 02:50:49.000000000 +0000
11547 #define HD_MAJOR IDE0_MAJOR
11548 #define PTY_SLAVE_MAJOR 3
11549 #define TTY_MAJOR 4
11550 +#define VROOT_MAJOR 4
11551 #define TTYAUX_MAJOR 5
11553 #define VCS_MAJOR 7
11554 diff -NurpP --minimal linux-4.9.76/include/uapi/linux/nfs_mount.h linux-4.9.76-vs2.3.9.5/include/uapi/linux/nfs_mount.h
11555 --- linux-4.9.76/include/uapi/linux/nfs_mount.h 2016-12-11 19:17:54.000000000 +0000
11556 +++ linux-4.9.76-vs2.3.9.5/include/uapi/linux/nfs_mount.h 2018-01-10 02:50:49.000000000 +0000
11557 @@ -63,7 +63,8 @@ struct nfs_mount_data {
11558 #define NFS_MOUNT_SECFLAVOUR 0x2000 /* 5 non-text parsed mount data only */
11559 #define NFS_MOUNT_NORDIRPLUS 0x4000 /* 5 */
11560 #define NFS_MOUNT_UNSHARED 0x8000 /* 5 */
11561 -#define NFS_MOUNT_FLAGMASK 0xFFFF
11562 +#define NFS_MOUNT_TAGGED 0x10000 /* context tagging */
11563 +#define NFS_MOUNT_FLAGMASK 0x1FFFF
11565 /* The following are for internal use only */
11566 #define NFS_MOUNT_LOOKUP_CACHE_NONEG 0x10000
11567 diff -NurpP --minimal linux-4.9.76/include/uapi/linux/reboot.h linux-4.9.76-vs2.3.9.5/include/uapi/linux/reboot.h
11568 --- linux-4.9.76/include/uapi/linux/reboot.h 2016-12-11 19:17:54.000000000 +0000
11569 +++ linux-4.9.76-vs2.3.9.5/include/uapi/linux/reboot.h 2018-01-10 02:50:49.000000000 +0000
11571 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
11572 #define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
11573 #define LINUX_REBOOT_CMD_KEXEC 0x45584543
11575 +#define LINUX_REBOOT_CMD_OOM 0xDEADBEEF
11578 #endif /* _UAPI_LINUX_REBOOT_H */
11579 diff -NurpP --minimal linux-4.9.76/include/uapi/linux/sysctl.h linux-4.9.76-vs2.3.9.5/include/uapi/linux/sysctl.h
11580 --- linux-4.9.76/include/uapi/linux/sysctl.h 2016-12-11 19:17:54.000000000 +0000
11581 +++ linux-4.9.76-vs2.3.9.5/include/uapi/linux/sysctl.h 2018-01-10 02:50:49.000000000 +0000
11582 @@ -58,6 +58,7 @@ enum
11583 CTL_ABI=9, /* Binary emulation */
11584 CTL_CPU=10, /* CPU stuff (speed scaling, etc) */
11585 CTL_ARLAN=254, /* arlan wireless driver */
11586 + CTL_VSERVER=4242, /* Linux-VServer debug */
11587 CTL_S390DBF=5677, /* s390 debug */
11588 CTL_SUNRPC=7249, /* sunrpc debug */
11589 CTL_PM=9899, /* frv power management */
11590 @@ -92,6 +93,7 @@ enum
11592 KERN_PANIC=15, /* int: panic timeout */
11593 KERN_REALROOTDEV=16, /* real root device to mount after initrd */
11594 + KERN_VSHELPER=17, /* string: path to vshelper policy agent */
11596 KERN_SPARC_REBOOT=21, /* reboot command on Sparc */
11597 KERN_CTLALTDEL=22, /* int: allow ctl-alt-del to reboot */
11598 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/Kbuild linux-4.9.76-vs2.3.9.5/include/uapi/vserver/Kbuild
11599 --- linux-4.9.76/include/uapi/vserver/Kbuild 1970-01-01 00:00:00.000000000 +0000
11600 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/Kbuild 2018-01-10 02:50:49.000000000 +0000
11603 +header-y += context_cmd.h network_cmd.h space_cmd.h \
11604 + cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11605 + inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11606 + debug_cmd.h device_cmd.h
11608 +header-y += switch.h context.h network.h monitor.h \
11609 + limit.h inode.h device.h
11611 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/cacct_cmd.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/cacct_cmd.h
11612 --- linux-4.9.76/include/uapi/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
11613 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/cacct_cmd.h 2018-01-10 02:50:49.000000000 +0000
11615 +#ifndef _UAPI_VS_CACCT_CMD_H
11616 +#define _UAPI_VS_CACCT_CMD_H
11619 +/* virtual host info name commands */
11621 +#define VCMD_sock_stat VC_CMD(VSTAT, 5, 0)
11623 +struct vcmd_sock_stat_v0 {
11625 + uint32_t count[3];
11626 + uint64_t total[3];
11629 +#endif /* _UAPI_VS_CACCT_CMD_H */
11630 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/context.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/context.h
11631 --- linux-4.9.76/include/uapi/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
11632 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/context.h 2018-01-10 02:50:49.000000000 +0000
11634 +#ifndef _UAPI_VS_CONTEXT_H
11635 +#define _UAPI_VS_CONTEXT_H
11637 +#include <linux/types.h>
11638 +#include <linux/capability.h>
11641 +/* context flags */
11643 +#define VXF_INFO_SCHED 0x00000002
11644 +#define VXF_INFO_NPROC 0x00000004
11645 +#define VXF_INFO_PRIVATE 0x00000008
11647 +#define VXF_INFO_INIT 0x00000010
11648 +#define VXF_INFO_HIDE 0x00000020
11649 +#define VXF_INFO_ULIMIT 0x00000040
11650 +#define VXF_INFO_NSPACE 0x00000080
11652 +#define VXF_SCHED_HARD 0x00000100
11653 +#define VXF_SCHED_PRIO 0x00000200
11654 +#define VXF_SCHED_PAUSE 0x00000400
11656 +#define VXF_VIRT_MEM 0x00010000
11657 +#define VXF_VIRT_UPTIME 0x00020000
11658 +#define VXF_VIRT_CPU 0x00040000
11659 +#define VXF_VIRT_LOAD 0x00080000
11660 +#define VXF_VIRT_TIME 0x00100000
11662 +#define VXF_HIDE_MOUNT 0x01000000
11663 +/* was VXF_HIDE_NETIF 0x02000000 */
11664 +#define VXF_HIDE_VINFO 0x04000000
11666 +#define VXF_STATE_SETUP (1ULL << 32)
11667 +#define VXF_STATE_INIT (1ULL << 33)
11668 +#define VXF_STATE_ADMIN (1ULL << 34)
11670 +#define VXF_SC_HELPER (1ULL << 36)
11671 +#define VXF_REBOOT_KILL (1ULL << 37)
11672 +#define VXF_PERSISTENT (1ULL << 38)
11674 +#define VXF_FORK_RSS (1ULL << 48)
11675 +#define VXF_PROLIFIC (1ULL << 49)
11677 +#define VXF_IGNEG_NICE (1ULL << 52)
11679 +#define VXF_ONE_TIME (0x0007ULL << 32)
11681 +#define VXF_INIT_SET (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11684 +/* context migration */
11686 +#define VXM_SET_INIT 0x00000001
11687 +#define VXM_SET_REAPER 0x00000002
11689 +/* context caps */
11691 +#define VXC_SET_UTSNAME 0x00000001
11692 +#define VXC_SET_RLIMIT 0x00000002
11693 +#define VXC_FS_SECURITY 0x00000004
11694 +#define VXC_FS_TRUSTED 0x00000008
11695 +#define VXC_TIOCSTI 0x00000010
11697 +/* was VXC_RAW_ICMP 0x00000100 */
11698 +#define VXC_SYSLOG 0x00001000
11699 +#define VXC_OOM_ADJUST 0x00002000
11700 +#define VXC_AUDIT_CONTROL 0x00004000
11702 +#define VXC_SECURE_MOUNT 0x00010000
11703 +/* #define VXC_SECURE_REMOUNT 0x00020000 */
11704 +#define VXC_BINARY_MOUNT 0x00040000
11705 +#define VXC_DEV_MOUNT 0x00080000
11707 +#define VXC_QUOTA_CTL 0x00100000
11708 +#define VXC_ADMIN_MAPPER 0x00200000
11709 +#define VXC_ADMIN_CLOOP 0x00400000
11711 +#define VXC_KTHREAD 0x01000000
11712 +#define VXC_NAMESPACE 0x02000000
11714 +#endif /* _UAPI_VS_CONTEXT_H */
11715 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/context_cmd.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/context_cmd.h
11716 --- linux-4.9.76/include/uapi/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
11717 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/context_cmd.h 2018-01-10 02:50:49.000000000 +0000
11719 +#ifndef _UAPI_VS_CONTEXT_CMD_H
11720 +#define _UAPI_VS_CONTEXT_CMD_H
11723 +/* vinfo commands */
11725 +#define VCMD_task_xid VC_CMD(VINFO, 1, 0)
11728 +#define VCMD_vx_info VC_CMD(VINFO, 5, 0)
11730 +struct vcmd_vx_info_v0 {
11732 + uint32_t initpid;
11733 + /* more to come */
11737 +#define VCMD_ctx_stat VC_CMD(VSTAT, 0, 0)
11739 +struct vcmd_ctx_stat_v0 {
11742 + /* more to come */
11746 +/* context commands */
11748 +#define VCMD_ctx_create_v0 VC_CMD(VPROC, 1, 0)
11749 +#define VCMD_ctx_create VC_CMD(VPROC, 1, 1)
11751 +struct vcmd_ctx_create {
11752 + uint64_t flagword;
11755 +#define VCMD_ctx_migrate_v0 VC_CMD(PROCMIG, 1, 0)
11756 +#define VCMD_ctx_migrate VC_CMD(PROCMIG, 1, 1)
11758 +struct vcmd_ctx_migrate {
11759 + uint64_t flagword;
11764 +/* flag commands */
11766 +#define VCMD_get_cflags VC_CMD(FLAGS, 1, 0)
11767 +#define VCMD_set_cflags VC_CMD(FLAGS, 2, 0)
11769 +struct vcmd_ctx_flags_v0 {
11770 + uint64_t flagword;
11776 +/* context caps commands */
11778 +#define VCMD_get_ccaps VC_CMD(FLAGS, 3, 1)
11779 +#define VCMD_set_ccaps VC_CMD(FLAGS, 4, 1)
11781 +struct vcmd_ctx_caps_v1 {
11788 +/* bcaps commands */
11790 +#define VCMD_get_bcaps VC_CMD(FLAGS, 9, 0)
11791 +#define VCMD_set_bcaps VC_CMD(FLAGS, 10, 0)
11793 +struct vcmd_bcaps {
11800 +/* umask commands */
11802 +#define VCMD_get_umask VC_CMD(FLAGS, 13, 0)
11803 +#define VCMD_set_umask VC_CMD(FLAGS, 14, 0)
11805 +struct vcmd_umask {
11812 +/* wmask commands */
11814 +#define VCMD_get_wmask VC_CMD(FLAGS, 15, 0)
11815 +#define VCMD_set_wmask VC_CMD(FLAGS, 16, 0)
11817 +struct vcmd_wmask {
11826 +#define VCMD_get_badness VC_CMD(MEMCTRL, 5, 0)
11827 +#define VCMD_set_badness VC_CMD(MEMCTRL, 6, 0)
11829 +struct vcmd_badness_v0 {
11833 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
11834 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/cvirt_cmd.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/cvirt_cmd.h
11835 --- linux-4.9.76/include/uapi/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
11836 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/cvirt_cmd.h 2018-01-10 02:50:49.000000000 +0000
11838 +#ifndef _UAPI_VS_CVIRT_CMD_H
11839 +#define _UAPI_VS_CVIRT_CMD_H
11842 +/* virtual host info name commands */
11844 +#define VCMD_set_vhi_name VC_CMD(VHOST, 1, 0)
11845 +#define VCMD_get_vhi_name VC_CMD(VHOST, 2, 0)
11847 +struct vcmd_vhi_name_v0 {
11853 +enum vhi_name_field {
11854 + VHIN_CONTEXT = 0,
11865 +#define VCMD_virt_stat VC_CMD(VSTAT, 3, 0)
11867 +struct vcmd_virt_stat_v0 {
11870 + uint32_t nr_threads;
11871 + uint32_t nr_running;
11872 + uint32_t nr_uninterruptible;
11873 + uint32_t nr_onhold;
11874 + uint32_t nr_forks;
11875 + uint32_t load[3];
11878 +#endif /* _UAPI_VS_CVIRT_CMD_H */
11879 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/debug_cmd.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/debug_cmd.h
11880 --- linux-4.9.76/include/uapi/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
11881 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/debug_cmd.h 2018-01-10 02:50:49.000000000 +0000
11883 +#ifndef _UAPI_VS_DEBUG_CMD_H
11884 +#define _UAPI_VS_DEBUG_CMD_H
11887 +/* debug commands */
11889 +#define VCMD_dump_history VC_CMD(DEBUG, 1, 0)
11891 +#define VCMD_read_history VC_CMD(DEBUG, 5, 0)
11892 +#define VCMD_read_monitor VC_CMD(DEBUG, 6, 0)
11894 +struct vcmd_read_history_v0 {
11897 + char __user *data;
11900 +struct vcmd_read_monitor_v0 {
11903 + char __user *data;
11906 +#endif /* _UAPI_VS_DEBUG_CMD_H */
11907 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/device.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/device.h
11908 --- linux-4.9.76/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
11909 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/device.h 2018-01-10 02:50:49.000000000 +0000
11911 +#ifndef _UAPI_VS_DEVICE_H
11912 +#define _UAPI_VS_DEVICE_H
11915 +#define DATTR_CREATE 0x00000001
11916 +#define DATTR_OPEN 0x00000002
11918 +#define DATTR_REMAP 0x00000010
11920 +#define DATTR_MASK 0x00000013
11922 +#endif /* _UAPI_VS_DEVICE_H */
11923 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/device_cmd.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/device_cmd.h
11924 --- linux-4.9.76/include/uapi/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
11925 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/device_cmd.h 2018-01-10 02:50:49.000000000 +0000
11927 +#ifndef _UAPI_VS_DEVICE_CMD_H
11928 +#define _UAPI_VS_DEVICE_CMD_H
11931 +/* device vserver commands */
11933 +#define VCMD_set_mapping VC_CMD(DEVICE, 1, 0)
11934 +#define VCMD_unset_mapping VC_CMD(DEVICE, 2, 0)
11936 +struct vcmd_set_mapping_v0 {
11937 + const char __user *device;
11938 + const char __user *target;
11942 +#endif /* _UAPI_VS_DEVICE_CMD_H */
11943 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/dlimit_cmd.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/dlimit_cmd.h
11944 --- linux-4.9.76/include/uapi/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
11945 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/dlimit_cmd.h 2018-01-10 02:50:49.000000000 +0000
11947 +#ifndef _UAPI_VS_DLIMIT_CMD_H
11948 +#define _UAPI_VS_DLIMIT_CMD_H
11951 +/* dlimit vserver commands */
11953 +#define VCMD_add_dlimit VC_CMD(DLIMIT, 1, 0)
11954 +#define VCMD_rem_dlimit VC_CMD(DLIMIT, 2, 0)
11956 +#define VCMD_set_dlimit VC_CMD(DLIMIT, 5, 0)
11957 +#define VCMD_get_dlimit VC_CMD(DLIMIT, 6, 0)
11959 +struct vcmd_ctx_dlimit_base_v0 {
11960 + const char __user *name;
11964 +struct vcmd_ctx_dlimit_v0 {
11965 + const char __user *name;
11966 + uint32_t space_used; /* used space in kbytes */
11967 + uint32_t space_total; /* maximum space in kbytes */
11968 + uint32_t inodes_used; /* used inodes */
11969 + uint32_t inodes_total; /* maximum inodes */
11970 + uint32_t reserved; /* reserved for root in % */
11974 +#define CDLIM_UNSET ((uint32_t)0UL)
11975 +#define CDLIM_INFINITY ((uint32_t)~0UL)
11976 +#define CDLIM_KEEP ((uint32_t)~1UL)
11978 +#define DLIME_UNIT 0
11979 +#define DLIME_KILO 1
11980 +#define DLIME_MEGA 2
11981 +#define DLIME_GIGA 3
11983 +#define DLIMF_SHIFT 0x10
11985 +#define DLIMS_USED 0
11986 +#define DLIMS_TOTAL 2
11989 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11991 + int exp = (flags & DLIMF_SHIFT) ?
11992 + (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11993 + return ((uint64_t)val) << (10 * exp);
11997 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12001 + if (*flags & DLIMF_SHIFT) {
12002 + while (val > (1LL << 32) && (exp < 3)) {
12006 + *flags &= ~(DLIME_GIGA << shift);
12007 + *flags |= exp << shift;
12013 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
12014 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/inode.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/inode.h
12015 --- linux-4.9.76/include/uapi/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
12016 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/inode.h 2018-01-10 02:50:49.000000000 +0000
12018 +#ifndef _UAPI_VS_INODE_H
12019 +#define _UAPI_VS_INODE_H
12022 +#define IATTR_TAG 0x01000000
12024 +#define IATTR_ADMIN 0x00000001
12025 +#define IATTR_WATCH 0x00000002
12026 +#define IATTR_HIDE 0x00000004
12027 +#define IATTR_FLAGS 0x00000007
12029 +#define IATTR_BARRIER 0x00010000
12030 +#define IATTR_IXUNLINK 0x00020000
12031 +#define IATTR_IMMUTABLE 0x00040000
12032 +#define IATTR_COW 0x00080000
12035 +/* inode ioctls */
12037 +#define FIOC_GETXFLG _IOR('x', 5, long)
12038 +#define FIOC_SETXFLG _IOW('x', 6, long)
12040 +#endif /* _UAPI_VS_INODE_H */
12041 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/inode_cmd.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/inode_cmd.h
12042 --- linux-4.9.76/include/uapi/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
12043 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/inode_cmd.h 2018-01-10 02:50:49.000000000 +0000
12045 +#ifndef _UAPI_VS_INODE_CMD_H
12046 +#define _UAPI_VS_INODE_CMD_H
12049 +/* inode vserver commands */
12051 +#define VCMD_get_iattr VC_CMD(INODE, 1, 1)
12052 +#define VCMD_set_iattr VC_CMD(INODE, 2, 1)
12054 +#define VCMD_fget_iattr VC_CMD(INODE, 3, 0)
12055 +#define VCMD_fset_iattr VC_CMD(INODE, 4, 0)
12057 +struct vcmd_ctx_iattr_v1 {
12058 + const char __user *name;
12064 +struct vcmd_ctx_fiattr_v0 {
12070 +#endif /* _UAPI_VS_INODE_CMD_H */
12071 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/limit.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/limit.h
12072 --- linux-4.9.76/include/uapi/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
12073 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/limit.h 2018-01-10 02:50:49.000000000 +0000
12075 +#ifndef _UAPI_VS_LIMIT_H
12076 +#define _UAPI_VS_LIMIT_H
12079 +#define VLIMIT_NSOCK 16
12080 +#define VLIMIT_OPENFD 17
12081 +#define VLIMIT_ANON 18
12082 +#define VLIMIT_SHMEM 19
12083 +#define VLIMIT_SEMARY 20
12084 +#define VLIMIT_NSEMS 21
12085 +#define VLIMIT_DENTRY 22
12086 +#define VLIMIT_MAPPED 23
12088 +#endif /* _UAPI_VS_LIMIT_H */
12089 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/limit_cmd.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/limit_cmd.h
12090 --- linux-4.9.76/include/uapi/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
12091 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/limit_cmd.h 2018-01-10 02:50:49.000000000 +0000
12093 +#ifndef _UAPI_VS_LIMIT_CMD_H
12094 +#define _UAPI_VS_LIMIT_CMD_H
12097 +/* rlimit vserver commands */
12099 +#define VCMD_get_rlimit VC_CMD(RLIMIT, 1, 0)
12100 +#define VCMD_set_rlimit VC_CMD(RLIMIT, 2, 0)
12101 +#define VCMD_get_rlimit_mask VC_CMD(RLIMIT, 3, 0)
12102 +#define VCMD_reset_hits VC_CMD(RLIMIT, 7, 0)
12103 +#define VCMD_reset_minmax VC_CMD(RLIMIT, 9, 0)
12105 +struct vcmd_ctx_rlimit_v0 {
12107 + uint64_t minimum;
12108 + uint64_t softlimit;
12109 + uint64_t maximum;
12112 +struct vcmd_ctx_rlimit_mask_v0 {
12113 + uint32_t minimum;
12114 + uint32_t softlimit;
12115 + uint32_t maximum;
12118 +#define VCMD_rlimit_stat VC_CMD(VSTAT, 1, 0)
12120 +struct vcmd_rlimit_stat_v0 {
12124 + uint64_t minimum;
12125 + uint64_t maximum;
12128 +#define CRLIM_UNSET (0ULL)
12129 +#define CRLIM_INFINITY (~0ULL)
12130 +#define CRLIM_KEEP (~1ULL)
12132 +#endif /* _UAPI_VS_LIMIT_CMD_H */
12133 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/monitor.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/monitor.h
12134 --- linux-4.9.76/include/uapi/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
12135 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/monitor.h 2018-01-10 02:50:49.000000000 +0000
12137 +#ifndef _UAPI_VS_MONITOR_H
12138 +#define _UAPI_VS_MONITOR_H
12140 +#include <linux/types.h>
12148 + VXM_UPDATE = 0x20,
12152 + VXM_RQINFO_1 = 0x24,
12155 + VXM_ACTIVATE = 0x40,
12162 + VXM_MIGRATE = 0x48,
12165 + /* all other bits are flags */
12166 + VXM_SCHED = 0x80,
12169 +struct _vxm_update_1 {
12170 + uint32_t tokens_max;
12171 + uint32_t fill_rate;
12172 + uint32_t interval;
12175 +struct _vxm_update_2 {
12176 + uint32_t tokens_min;
12177 + uint32_t fill_rate;
12178 + uint32_t interval;
12181 +struct _vxm_rqinfo_1 {
12182 + uint16_t running;
12186 + uint32_t idle_tokens;
12189 +struct _vxm_rqinfo_2 {
12190 + uint32_t norm_time;
12191 + uint32_t idle_time;
12192 + uint32_t idle_skip;
12195 +struct _vxm_sched {
12197 + uint32_t norm_time;
12198 + uint32_t idle_time;
12201 +struct _vxm_task {
12206 +struct _vxm_event {
12215 + struct _vxm_task tsk;
12219 +struct _vx_mon_entry {
12223 + struct _vxm_event ev;
12224 + struct _vxm_sched sd;
12225 + struct _vxm_update_1 u1;
12226 + struct _vxm_update_2 u2;
12227 + struct _vxm_rqinfo_1 q1;
12228 + struct _vxm_rqinfo_2 q2;
12232 +#endif /* _UAPI_VS_MONITOR_H */
12233 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/network.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/network.h
12234 --- linux-4.9.76/include/uapi/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
12235 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/network.h 2018-01-10 02:50:49.000000000 +0000
12237 +#ifndef _UAPI_VS_NETWORK_H
12238 +#define _UAPI_VS_NETWORK_H
12240 +#include <linux/types.h>
12243 +#define MAX_N_CONTEXT 65535 /* Arbitrary limit */
12246 +/* network flags */
12248 +#define NXF_INFO_PRIVATE 0x00000008
12250 +#define NXF_SINGLE_IP 0x00000100
12251 +#define NXF_LBACK_REMAP 0x00000200
12252 +#define NXF_LBACK_ALLOW 0x00000400
12254 +#define NXF_HIDE_NETIF 0x02000000
12255 +#define NXF_HIDE_LBACK 0x04000000
12257 +#define NXF_STATE_SETUP (1ULL << 32)
12258 +#define NXF_STATE_ADMIN (1ULL << 34)
12260 +#define NXF_SC_HELPER (1ULL << 36)
12261 +#define NXF_PERSISTENT (1ULL << 38)
12263 +#define NXF_ONE_TIME (0x0005ULL << 32)
12266 +#define NXF_INIT_SET (__nxf_init_set())
12268 +static inline uint64_t __nxf_init_set(void) {
12269 + return NXF_STATE_ADMIN
12270 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12271 + | NXF_LBACK_REMAP
12274 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12277 + | NXF_HIDE_NETIF;
12281 +/* network caps */
12283 +#define NXC_TUN_CREATE 0x00000001
12285 +#define NXC_RAW_ICMP 0x00000100
12287 +#define NXC_MULTICAST 0x00001000
12290 +/* address types */
12292 +#define NXA_TYPE_IPV4 0x0001
12293 +#define NXA_TYPE_IPV6 0x0002
12295 +#define NXA_TYPE_NONE 0x0000
12296 +#define NXA_TYPE_ANY 0x00FF
12298 +#define NXA_TYPE_ADDR 0x0010
12299 +#define NXA_TYPE_MASK 0x0020
12300 +#define NXA_TYPE_RANGE 0x0040
12302 +#define NXA_MASK_ALL (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12304 +#define NXA_MOD_BCAST 0x0100
12305 +#define NXA_MOD_LBACK 0x0200
12307 +#define NXA_LOOPBACK 0x1000
12309 +#define NXA_MASK_BIND (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12310 +#define NXA_MASK_SHOW (NXA_MASK_ALL | NXA_LOOPBACK)
12312 +#endif /* _UAPI_VS_NETWORK_H */
12313 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/network_cmd.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/network_cmd.h
12314 --- linux-4.9.76/include/uapi/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
12315 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/network_cmd.h 2018-01-10 02:50:49.000000000 +0000
12317 +#ifndef _UAPI_VS_NETWORK_CMD_H
12318 +#define _UAPI_VS_NETWORK_CMD_H
12321 +/* vinfo commands */
12323 +#define VCMD_task_nid VC_CMD(VINFO, 2, 0)
12326 +#define VCMD_nx_info VC_CMD(VINFO, 6, 0)
12328 +struct vcmd_nx_info_v0 {
12330 + /* more to come */
12334 +#include <linux/in.h>
12335 +#include <linux/in6.h>
12337 +#define VCMD_net_create_v0 VC_CMD(VNET, 1, 0)
12338 +#define VCMD_net_create VC_CMD(VNET, 1, 1)
12340 +struct vcmd_net_create {
12341 + uint64_t flagword;
12344 +#define VCMD_net_migrate VC_CMD(NETMIG, 1, 0)
12346 +#define VCMD_net_add VC_CMD(NETALT, 1, 0)
12347 +#define VCMD_net_remove VC_CMD(NETALT, 2, 0)
12349 +struct vcmd_net_addr_v0 {
12352 + struct in_addr ip[4];
12353 + struct in_addr mask[4];
12356 +#define VCMD_net_add_ipv4_v1 VC_CMD(NETALT, 1, 1)
12357 +#define VCMD_net_rem_ipv4_v1 VC_CMD(NETALT, 2, 1)
12359 +struct vcmd_net_addr_ipv4_v1 {
12362 + struct in_addr ip;
12363 + struct in_addr mask;
12366 +#define VCMD_net_add_ipv4 VC_CMD(NETALT, 1, 2)
12367 +#define VCMD_net_rem_ipv4 VC_CMD(NETALT, 2, 2)
12369 +struct vcmd_net_addr_ipv4_v2 {
12372 + struct in_addr ip;
12373 + struct in_addr ip2;
12374 + struct in_addr mask;
12377 +#define VCMD_net_add_ipv6 VC_CMD(NETALT, 3, 1)
12378 +#define VCMD_net_remove_ipv6 VC_CMD(NETALT, 4, 1)
12380 +struct vcmd_net_addr_ipv6_v1 {
12384 + struct in6_addr ip;
12385 + struct in6_addr mask;
12388 +#define VCMD_add_match_ipv4 VC_CMD(NETALT, 5, 0)
12389 +#define VCMD_get_match_ipv4 VC_CMD(NETALT, 6, 0)
12391 +struct vcmd_match_ipv4_v0 {
12396 + struct in_addr ip;
12397 + struct in_addr ip2;
12398 + struct in_addr mask;
12401 +#define VCMD_add_match_ipv6 VC_CMD(NETALT, 7, 0)
12402 +#define VCMD_get_match_ipv6 VC_CMD(NETALT, 8, 0)
12404 +struct vcmd_match_ipv6_v0 {
12409 + struct in6_addr ip;
12410 + struct in6_addr ip2;
12411 + struct in6_addr mask;
12417 +/* flag commands */
12419 +#define VCMD_get_nflags VC_CMD(FLAGS, 5, 0)
12420 +#define VCMD_set_nflags VC_CMD(FLAGS, 6, 0)
12422 +struct vcmd_net_flags_v0 {
12423 + uint64_t flagword;
12429 +/* network caps commands */
12431 +#define VCMD_get_ncaps VC_CMD(FLAGS, 7, 0)
12432 +#define VCMD_set_ncaps VC_CMD(FLAGS, 8, 0)
12434 +struct vcmd_net_caps_v0 {
12439 +#endif /* _UAPI_VS_NETWORK_CMD_H */
12440 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/sched_cmd.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/sched_cmd.h
12441 --- linux-4.9.76/include/uapi/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
12442 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/sched_cmd.h 2018-01-10 02:50:49.000000000 +0000
12444 +#ifndef _UAPI_VS_SCHED_CMD_H
12445 +#define _UAPI_VS_SCHED_CMD_H
12448 +struct vcmd_prio_bias {
12450 + int32_t prio_bias;
12453 +#define VCMD_set_prio_bias VC_CMD(SCHED, 4, 0)
12454 +#define VCMD_get_prio_bias VC_CMD(SCHED, 5, 0)
12456 +#endif /* _UAPI_VS_SCHED_CMD_H */
12457 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/signal_cmd.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/signal_cmd.h
12458 --- linux-4.9.76/include/uapi/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
12459 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/signal_cmd.h 2018-01-10 02:50:49.000000000 +0000
12461 +#ifndef _UAPI_VS_SIGNAL_CMD_H
12462 +#define _UAPI_VS_SIGNAL_CMD_H
12465 +/* signalling vserver commands */
12467 +#define VCMD_ctx_kill VC_CMD(PROCTRL, 1, 0)
12468 +#define VCMD_wait_exit VC_CMD(EVENT, 99, 0)
12470 +struct vcmd_ctx_kill_v0 {
12475 +struct vcmd_wait_exit_v0 {
12476 + int32_t reboot_cmd;
12477 + int32_t exit_code;
12481 +/* process alteration commands */
12483 +#define VCMD_get_pflags VC_CMD(PROCALT, 5, 0)
12484 +#define VCMD_set_pflags VC_CMD(PROCALT, 6, 0)
12486 +struct vcmd_pflags_v0 {
12487 + uint32_t flagword;
12491 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
12492 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/space_cmd.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/space_cmd.h
12493 --- linux-4.9.76/include/uapi/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
12494 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/space_cmd.h 2018-01-10 02:50:49.000000000 +0000
12496 +#ifndef _UAPI_VS_SPACE_CMD_H
12497 +#define _UAPI_VS_SPACE_CMD_H
12500 +#define VCMD_enter_space_v0 VC_CMD(PROCALT, 1, 0)
12501 +#define VCMD_enter_space_v1 VC_CMD(PROCALT, 1, 1)
12502 +#define VCMD_enter_space VC_CMD(PROCALT, 1, 2)
12504 +#define VCMD_set_space_v0 VC_CMD(PROCALT, 3, 0)
12505 +#define VCMD_set_space_v1 VC_CMD(PROCALT, 3, 1)
12506 +#define VCMD_set_space VC_CMD(PROCALT, 3, 2)
12508 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12510 +#define VCMD_get_space_mask VC_CMD(VSPACE, 0, 1)
12511 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12514 +struct vcmd_space_mask_v1 {
12518 +struct vcmd_space_mask_v2 {
12523 +#endif /* _UAPI_VS_SPACE_CMD_H */
12524 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/switch.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/switch.h
12525 --- linux-4.9.76/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12526 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/switch.h 2018-01-10 02:50:49.000000000 +0000
12528 +#ifndef _UAPI_VS_SWITCH_H
12529 +#define _UAPI_VS_SWITCH_H
12531 +#include <linux/types.h>
12534 +#define VC_CATEGORY(c) (((c) >> 24) & 0x3F)
12535 +#define VC_COMMAND(c) (((c) >> 16) & 0xFF)
12536 +#define VC_VERSION(c) ((c) & 0xFFF)
12538 +#define VC_CMD(c, i, v) ((((VC_CAT_ ## c) & 0x3F) << 24) \
12539 + | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12543 + Syscall Matrix V2.8
12545 + |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12546 + |STATS |DESTROY|ALTER |CHANGE |LIMIT |TEST | | | |
12547 + |INFO |SETUP | |MOVE | | | | | |
12548 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12549 + SYSTEM |VERSION|VSETUP |VHOST | | | | |DEVICE | |
12550 + HOST | 00| 01| 02| 03| 04| 05| | 06| 07|
12551 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12552 + CPU | |VPROC |PROCALT|PROCMIG|PROCTRL| | |SCHED. | |
12553 + PROCESS| 08| 09| 10| 11| 12| 13| | 14| 15|
12554 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12555 + MEMORY | | | | |MEMCTRL| | |SWAP | |
12556 + | 16| 17| 18| 19| 20| 21| | 22| 23|
12557 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12558 + NETWORK| |VNET |NETALT |NETMIG |NETCTL | | |SERIAL | |
12559 + | 24| 25| 26| 27| 28| 29| | 30| 31|
12560 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12561 + DISK | | | |TAGMIG |DLIMIT | | |INODE | |
12562 + VFS | 32| 33| 34| 35| 36| 37| | 38| 39|
12563 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12564 + OTHER |VSTAT | | | | | | |VINFO | |
12565 + | 40| 41| 42| 43| 44| 45| | 46| 47|
12566 + =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12567 + SPECIAL|EVENT | | | |FLAGS | | |VSPACE | |
12568 + | 48| 49| 50| 51| 52| 53| | 54| 55|
12569 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12570 + SPECIAL|DEBUG | | | |RLIMIT |SYSCALL| | |COMPAT |
12571 + | 56| 57| 58| 59| 60|TEST 61| | 62| 63|
12572 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12576 +#define VC_CAT_VERSION 0
12578 +#define VC_CAT_VSETUP 1
12579 +#define VC_CAT_VHOST 2
12581 +#define VC_CAT_DEVICE 6
12583 +#define VC_CAT_VPROC 9
12584 +#define VC_CAT_PROCALT 10
12585 +#define VC_CAT_PROCMIG 11
12586 +#define VC_CAT_PROCTRL 12
12588 +#define VC_CAT_SCHED 14
12589 +#define VC_CAT_MEMCTRL 20
12591 +#define VC_CAT_VNET 25
12592 +#define VC_CAT_NETALT 26
12593 +#define VC_CAT_NETMIG 27
12594 +#define VC_CAT_NETCTRL 28
12596 +#define VC_CAT_TAGMIG 35
12597 +#define VC_CAT_DLIMIT 36
12598 +#define VC_CAT_INODE 38
12600 +#define VC_CAT_VSTAT 40
12601 +#define VC_CAT_VINFO 46
12602 +#define VC_CAT_EVENT 48
12604 +#define VC_CAT_FLAGS 52
12605 +#define VC_CAT_VSPACE 54
12606 +#define VC_CAT_DEBUG 56
12607 +#define VC_CAT_RLIMIT 60
12609 +#define VC_CAT_SYSTEST 61
12610 +#define VC_CAT_COMPAT 63
12612 +/* query version */
12614 +#define VCMD_get_version VC_CMD(VERSION, 0, 0)
12615 +#define VCMD_get_vci VC_CMD(VERSION, 1, 0)
12617 +#endif /* _UAPI_VS_SWITCH_H */
12618 diff -NurpP --minimal linux-4.9.76/include/uapi/vserver/tag_cmd.h linux-4.9.76-vs2.3.9.5/include/uapi/vserver/tag_cmd.h
12619 --- linux-4.9.76/include/uapi/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12620 +++ linux-4.9.76-vs2.3.9.5/include/uapi/vserver/tag_cmd.h 2018-01-10 02:50:49.000000000 +0000
12622 +#ifndef _UAPI_VS_TAG_CMD_H
12623 +#define _UAPI_VS_TAG_CMD_H
12626 +/* vinfo commands */
12628 +#define VCMD_task_tag VC_CMD(VINFO, 3, 0)
12631 +/* context commands */
12633 +#define VCMD_tag_migrate VC_CMD(TAGMIG, 1, 0)
12635 +#endif /* _UAPI_VS_TAG_CMD_H */
12636 diff -NurpP --minimal linux-4.9.76/init/Kconfig linux-4.9.76-vs2.3.9.5/init/Kconfig
12637 --- linux-4.9.76/init/Kconfig 2016-12-11 19:17:54.000000000 +0000
12638 +++ linux-4.9.76-vs2.3.9.5/init/Kconfig 2018-01-10 02:50:49.000000000 +0000
12639 @@ -958,6 +958,7 @@ config NUMA_BALANCING_DEFAULT_ENABLED
12641 bool "Control Group support"
12645 This option adds support for grouping sets of processes together, for
12646 use with process control subsystems such as Cpusets, CFS, memory
12647 diff -NurpP --minimal linux-4.9.76/init/main.c linux-4.9.76-vs2.3.9.5/init/main.c
12648 --- linux-4.9.76/init/main.c 2018-01-13 21:29:00.000000000 +0000
12649 +++ linux-4.9.76-vs2.3.9.5/init/main.c 2018-01-10 02:50:49.000000000 +0000
12651 #include <linux/proc_ns.h>
12652 #include <linux/io.h>
12653 #include <linux/kaiser.h>
12654 +#include <linux/vserver/percpu.h>
12656 #include <asm/io.h>
12657 #include <asm/bugs.h>
12658 diff -NurpP --minimal linux-4.9.76/ipc/mqueue.c linux-4.9.76-vs2.3.9.5/ipc/mqueue.c
12659 --- linux-4.9.76/ipc/mqueue.c 2018-01-13 21:29:00.000000000 +0000
12660 +++ linux-4.9.76-vs2.3.9.5/ipc/mqueue.c 2018-01-10 02:50:49.000000000 +0000
12662 #include <linux/ipc_namespace.h>
12663 #include <linux/user_namespace.h>
12664 #include <linux/slab.h>
12665 +#include <linux/vs_context.h>
12666 +#include <linux/vs_limit.h>
12668 #include <net/sock.h>
12670 @@ -75,6 +77,7 @@ struct mqueue_inode_info {
12671 struct pid *notify_owner;
12672 struct user_namespace *notify_user_ns;
12673 struct user_struct *user; /* user who created, for accounting */
12674 + struct vx_info *vxi;
12675 struct sock *notify_sock;
12676 struct sk_buff *notify_cookie;
12678 @@ -230,6 +233,7 @@ static struct inode *mqueue_get_inode(st
12679 if (S_ISREG(mode)) {
12680 struct mqueue_inode_info *info;
12681 unsigned long mq_bytes, mq_treesize;
12682 + struct vx_info *vxi = current_vx_info();
12684 inode->i_fop = &mqueue_file_operations;
12685 inode->i_size = FILENT_SIZE;
12686 @@ -243,6 +247,7 @@ static struct inode *mqueue_get_inode(st
12687 info->notify_user_ns = NULL;
12689 info->user = NULL; /* set when all is ok */
12690 + info->vxi = NULL;
12691 info->msg_tree = RB_ROOT;
12692 info->node_cache = NULL;
12693 memset(&info->attr, 0, sizeof(info->attr));
12694 @@ -276,17 +281,20 @@ static struct inode *mqueue_get_inode(st
12696 spin_lock(&mq_lock);
12697 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
12698 - u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
12699 + u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
12700 + !vx_ipcmsg_avail(vxi, mq_bytes)) {
12701 spin_unlock(&mq_lock);
12702 /* mqueue_evict_inode() releases info->messages */
12706 u->mq_bytes += mq_bytes;
12707 + vx_ipcmsg_add(vxi, u, mq_bytes);
12708 spin_unlock(&mq_lock);
12711 info->user = get_uid(u);
12712 + info->vxi = get_vx_info(vxi);
12713 } else if (S_ISDIR(mode)) {
12715 /* Some things misbehave if size == 0 on a directory */
12716 @@ -396,8 +404,11 @@ static void mqueue_evict_inode(struct in
12720 + struct vx_info *vxi = info->vxi;
12722 spin_lock(&mq_lock);
12723 user->mq_bytes -= mq_bytes;
12724 + vx_ipcmsg_sub(vxi, user, mq_bytes);
12726 * get_ns_from_inode() ensures that the
12727 * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
12728 @@ -407,6 +418,7 @@ static void mqueue_evict_inode(struct in
12730 ipc_ns->mq_queues_count--;
12731 spin_unlock(&mq_lock);
12732 + put_vx_info(vxi);
12736 diff -NurpP --minimal linux-4.9.76/ipc/msg.c linux-4.9.76-vs2.3.9.5/ipc/msg.c
12737 --- linux-4.9.76/ipc/msg.c 2016-12-11 19:17:54.000000000 +0000
12738 +++ linux-4.9.76-vs2.3.9.5/ipc/msg.c 2018-01-10 02:50:49.000000000 +0000
12740 #include <linux/rwsem.h>
12741 #include <linux/nsproxy.h>
12742 #include <linux/ipc_namespace.h>
12743 +#include <linux/vs_base.h>
12745 #include <asm/current.h>
12746 #include <linux/uaccess.h>
12747 @@ -124,6 +125,7 @@ static int newque(struct ipc_namespace *
12749 msq->q_perm.mode = msgflg & S_IRWXUGO;
12750 msq->q_perm.key = key;
12751 + msq->q_perm.xid = vx_current_xid();
12753 msq->q_perm.security = NULL;
12754 retval = security_msg_queue_alloc(msq);
12755 diff -NurpP --minimal linux-4.9.76/ipc/namespace.c linux-4.9.76-vs2.3.9.5/ipc/namespace.c
12756 --- linux-4.9.76/ipc/namespace.c 2016-12-11 19:17:54.000000000 +0000
12757 +++ linux-4.9.76-vs2.3.9.5/ipc/namespace.c 2018-01-13 03:52:55.000000000 +0000
12759 #include <linux/mount.h>
12760 #include <linux/user_namespace.h>
12761 #include <linux/proc_ns.h>
12762 +#include <linux/vserver/global.h>
12766 @@ -59,6 +60,7 @@ static struct ipc_namespace *create_ipc_
12770 + atomic_inc(&vs_global_ipc_ns);
12774 @@ -121,6 +123,7 @@ static void free_ipc_ns(struct ipc_names
12775 dec_ipc_namespaces(ns->ucounts);
12776 put_user_ns(ns->user_ns);
12777 ns_free_inum(&ns->ns);
12778 + atomic_dec(&vs_global_ipc_ns);
12782 diff -NurpP --minimal linux-4.9.76/ipc/sem.c linux-4.9.76-vs2.3.9.5/ipc/sem.c
12783 --- linux-4.9.76/ipc/sem.c 2016-12-11 19:17:54.000000000 +0000
12784 +++ linux-4.9.76-vs2.3.9.5/ipc/sem.c 2018-01-10 02:50:49.000000000 +0000
12786 #include <linux/rwsem.h>
12787 #include <linux/nsproxy.h>
12788 #include <linux/ipc_namespace.h>
12789 +#include <linux/vs_base.h>
12790 +#include <linux/vs_limit.h>
12792 #include <linux/uaccess.h>
12794 @@ -537,6 +539,7 @@ static int newary(struct ipc_namespace *
12796 sma->sem_perm.mode = (semflg & S_IRWXUGO);
12797 sma->sem_perm.key = key;
12798 + sma->sem_perm.xid = vx_current_xid();
12800 sma->sem_perm.security = NULL;
12801 retval = security_sem_alloc(sma);
12802 @@ -567,6 +570,9 @@ static int newary(struct ipc_namespace *
12805 ns->used_sems += nsems;
12806 + /* FIXME: obsoleted? */
12807 + vx_semary_inc(sma);
12808 + vx_nsems_add(sma, nsems);
12810 sem_unlock(sma, -1);
12812 @@ -1155,6 +1161,9 @@ static void freeary(struct ipc_namespace
12814 wake_up_sem_queue_do(&tasks);
12815 ns->used_sems -= sma->sem_nsems;
12816 + /* FIXME: obsoleted? */
12817 + vx_nsems_sub(sma, sma->sem_nsems);
12818 + vx_semary_dec(sma);
12819 ipc_rcu_putref(sma, sem_rcu_free);
12822 diff -NurpP --minimal linux-4.9.76/ipc/shm.c linux-4.9.76-vs2.3.9.5/ipc/shm.c
12823 --- linux-4.9.76/ipc/shm.c 2018-01-13 21:29:00.000000000 +0000
12824 +++ linux-4.9.76-vs2.3.9.5/ipc/shm.c 2018-01-10 02:50:49.000000000 +0000
12826 #include <linux/nsproxy.h>
12827 #include <linux/mount.h>
12828 #include <linux/ipc_namespace.h>
12829 +#include <linux/vs_context.h>
12830 +#include <linux/vs_limit.h>
12832 #include <linux/uaccess.h>
12834 @@ -228,10 +230,14 @@ static void shm_open(struct vm_area_stru
12835 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
12837 struct file *shm_file;
12838 + struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
12839 + int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
12841 shm_file = shp->shm_file;
12842 shp->shm_file = NULL;
12843 - ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
12844 + vx_ipcshm_sub(vxi, shp, numpages);
12845 + ns->shm_tot -= numpages;
12849 if (!is_file_hugepages(shm_file))
12850 @@ -240,6 +246,7 @@ static void shm_destroy(struct ipc_names
12851 user_shm_unlock(i_size_read(file_inode(shm_file)),
12854 + put_vx_info(vxi);
12855 ipc_rcu_putref(shp, shm_rcu_free);
12858 @@ -539,11 +546,15 @@ static int newseg(struct ipc_namespace *
12859 ns->shm_tot + numpages > ns->shm_ctlall)
12862 + if (!vx_ipcshm_avail(current_vx_info(), numpages))
12865 shp = ipc_rcu_alloc(sizeof(*shp));
12869 shp->shm_perm.key = key;
12870 + shp->shm_perm.xid = vx_current_xid();
12871 shp->shm_perm.mode = (shmflg & S_IRWXUGO);
12872 shp->mlock_user = NULL;
12874 @@ -614,6 +625,7 @@ static int newseg(struct ipc_namespace *
12876 ipc_unlock_object(&shp->shm_perm);
12878 + vx_ipcshm_add(current_vx_info(), key, numpages);
12882 diff -NurpP --minimal linux-4.9.76/kernel/Makefile linux-4.9.76-vs2.3.9.5/kernel/Makefile
12883 --- linux-4.9.76/kernel/Makefile 2018-01-13 21:29:00.000000000 +0000
12884 +++ linux-4.9.76-vs2.3.9.5/kernel/Makefile 2018-01-10 02:50:49.000000000 +0000
12885 @@ -39,6 +39,7 @@ obj-y += printk/
12888 obj-y += livepatch/
12891 obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
12892 obj-$(CONFIG_FREEZER) += freezer.o
12893 diff -NurpP --minimal linux-4.9.76/kernel/auditsc.c linux-4.9.76-vs2.3.9.5/kernel/auditsc.c
12894 --- linux-4.9.76/kernel/auditsc.c 2016-12-11 19:17:54.000000000 +0000
12895 +++ linux-4.9.76-vs2.3.9.5/kernel/auditsc.c 2018-01-10 02:50:49.000000000 +0000
12896 @@ -1965,7 +1965,7 @@ static int audit_set_loginuid_perm(kuid_
12897 if (is_audit_feature_set(AUDIT_FEATURE_LOGINUID_IMMUTABLE))
12899 /* it is set, you need permission */
12900 - if (!capable(CAP_AUDIT_CONTROL))
12901 + if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
12903 /* reject if this is not an unset and we don't allow that */
12904 if (is_audit_feature_set(AUDIT_FEATURE_ONLY_UNSET_LOGINUID) && uid_valid(loginuid))
12905 diff -NurpP --minimal linux-4.9.76/kernel/capability.c linux-4.9.76-vs2.3.9.5/kernel/capability.c
12906 --- linux-4.9.76/kernel/capability.c 2018-01-13 21:29:00.000000000 +0000
12907 +++ linux-4.9.76-vs2.3.9.5/kernel/capability.c 2018-01-10 02:50:49.000000000 +0000
12909 #include <linux/syscalls.h>
12910 #include <linux/pid_namespace.h>
12911 #include <linux/user_namespace.h>
12912 +#include <linux/vs_context.h>
12913 #include <asm/uaccess.h>
12916 @@ -107,6 +108,7 @@ static int cap_validate_magic(cap_user_h
12922 * The only thing that can change the capabilities of the current
12923 * process is the current process. As such, we can't be in this code
12924 @@ -344,6 +346,8 @@ bool has_ns_capability_noaudit(struct ta
12928 +#include <linux/vserver/base.h>
12931 * has_capability_noaudit - Does a task have a capability (unaudited) in the
12933 diff -NurpP --minimal linux-4.9.76/kernel/compat.c linux-4.9.76-vs2.3.9.5/kernel/compat.c
12934 --- linux-4.9.76/kernel/compat.c 2016-12-11 19:17:54.000000000 +0000
12935 +++ linux-4.9.76-vs2.3.9.5/kernel/compat.c 2018-01-10 02:50:49.000000000 +0000
12937 #include <linux/times.h>
12938 #include <linux/ptrace.h>
12939 #include <linux/gfp.h>
12940 +#include <linux/vs_time.h>
12942 #include <asm/uaccess.h>
12944 @@ -1059,7 +1060,7 @@ COMPAT_SYSCALL_DEFINE1(stime, compat_tim
12948 - do_settimeofday(&tv);
12949 + vx_settimeofday(&tv);
12953 diff -NurpP --minimal linux-4.9.76/kernel/cred.c linux-4.9.76-vs2.3.9.5/kernel/cred.c
12954 --- linux-4.9.76/kernel/cred.c 2016-12-11 19:17:54.000000000 +0000
12955 +++ linux-4.9.76-vs2.3.9.5/kernel/cred.c 2018-01-10 02:50:49.000000000 +0000
12956 @@ -64,31 +64,6 @@ struct cred init_cred = {
12957 .group_info = &init_groups,
12960 -static inline void set_cred_subscribers(struct cred *cred, int n)
12962 -#ifdef CONFIG_DEBUG_CREDENTIALS
12963 - atomic_set(&cred->subscribers, n);
12967 -static inline int read_cred_subscribers(const struct cred *cred)
12969 -#ifdef CONFIG_DEBUG_CREDENTIALS
12970 - return atomic_read(&cred->subscribers);
12976 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
12978 -#ifdef CONFIG_DEBUG_CREDENTIALS
12979 - struct cred *cred = (struct cred *) _cred;
12981 - atomic_add(n, &cred->subscribers);
12986 * The RCU callback to actually dispose of a set of credentials
12988 @@ -240,21 +215,16 @@ error:
12990 * Call commit_creds() or abort_creds() to clean up.
12992 -struct cred *prepare_creds(void)
12993 +struct cred *__prepare_creds(const struct cred *old)
12995 - struct task_struct *task = current;
12996 - const struct cred *old;
12999 - validate_process_creds();
13001 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13005 kdebug("prepare_creds() alloc %p", new);
13007 - old = task->cred;
13008 memcpy(new, old, sizeof(struct cred));
13010 atomic_set(&new->usage, 1);
13011 @@ -283,6 +253,13 @@ error:
13016 +struct cred *prepare_creds(void)
13018 + validate_process_creds();
13020 + return __prepare_creds(current->cred);
13022 EXPORT_SYMBOL(prepare_creds);
13025 diff -NurpP --minimal linux-4.9.76/kernel/exit.c linux-4.9.76-vs2.3.9.5/kernel/exit.c
13026 --- linux-4.9.76/kernel/exit.c 2016-12-11 19:17:54.000000000 +0000
13027 +++ linux-4.9.76-vs2.3.9.5/kernel/exit.c 2018-01-10 09:02:31.000000000 +0000
13029 #include <linux/fs_struct.h>
13030 #include <linux/init_task.h>
13031 #include <linux/perf_event.h>
13032 +#include <linux/vs_limit.h>
13033 +#include <linux/vs_context.h>
13034 +#include <linux/vs_network.h>
13035 +#include <linux/vs_pid.h>
13036 #include <trace/events/sched.h>
13037 #include <linux/hw_breakpoint.h>
13038 #include <linux/oom.h>
13039 @@ -531,14 +535,24 @@ static struct task_struct *find_child_re
13041 struct pid_namespace *pid_ns = task_active_pid_ns(father);
13042 struct task_struct *reaper = pid_ns->child_reaper;
13043 + struct vx_info *vxi = task_get_vx_info(father);
13046 + BUG_ON(!vxi->vx_reaper);
13047 + if (vxi->vx_reaper != init_pid_ns.child_reaper &&
13048 + vxi->vx_reaper != father) {
13049 + reaper = vxi->vx_reaper;
13054 if (likely(reaper != father))
13058 reaper = find_alive_thread(father);
13060 pid_ns->child_reaper = reaper;
13065 write_unlock_irq(&tasklist_lock);
13066 @@ -549,7 +563,10 @@ static struct task_struct *find_child_re
13067 zap_pid_ns_processes(pid_ns);
13068 write_lock_irq(&tasklist_lock);
13073 + put_vx_info(vxi);
13078 @@ -637,9 +654,13 @@ static void forget_original_parent(struc
13081 reaper = find_new_reaper(father, reaper);
13082 - list_for_each_entry(p, &father->children, sibling) {
13083 + for (p = list_first_entry(&father->children, struct task_struct, sibling);
13084 + &p->sibling != &father->children; ) {
13085 + struct task_struct *next, *this_reaper = reaper;
13087 + this_reaper = task_active_pid_ns(reaper)->child_reaper;
13088 for_each_thread(p, t) {
13089 - t->real_parent = reaper;
13090 + t->real_parent = this_reaper;
13091 BUG_ON((!t->ptrace) != (t->parent == father));
13092 if (likely(!t->ptrace))
13093 t->parent = t->real_parent;
13094 @@ -651,10 +672,13 @@ static void forget_original_parent(struc
13095 * If this is a threaded reparent there is no need to
13096 * notify anyone anything has happened.
13098 - if (!same_thread_group(reaper, father))
13099 + if (!same_thread_group(this_reaper, father))
13100 reparent_leader(father, p, dead);
13101 + next = list_next_entry(p, sibling);
13102 + list_add(&p->sibling, &this_reaper->children);
13105 - list_splice_tail_init(&father->children, &reaper->children);
13106 + INIT_LIST_HEAD(&father->children);
13110 @@ -844,6 +868,9 @@ void __noreturn do_exit(long code)
13112 flush_ptrace_hw_breakpoint(tsk);
13114 + /* needs to stay before exit_notify() */
13115 + exit_vx_info_early(tsk, code);
13117 TASKS_RCU(preempt_disable());
13118 TASKS_RCU(tasks_rcu_i = __srcu_read_lock(&tasks_rcu_exit_srcu));
13119 TASKS_RCU(preempt_enable());
13120 @@ -883,6 +910,10 @@ void __noreturn do_exit(long code)
13122 TASKS_RCU(__srcu_read_unlock(&tasks_rcu_exit_srcu, tasks_rcu_i));
13124 + /* needs to stay after exit_notify() */
13125 + exit_vx_info(tsk, code);
13126 + exit_nx_info(tsk);
13130 EXPORT_SYMBOL_GPL(do_exit);
13131 diff -NurpP --minimal linux-4.9.76/kernel/fork.c linux-4.9.76-vs2.3.9.5/kernel/fork.c
13132 --- linux-4.9.76/kernel/fork.c 2018-01-13 21:29:00.000000000 +0000
13133 +++ linux-4.9.76-vs2.3.9.5/kernel/fork.c 2018-01-10 09:23:14.000000000 +0000
13135 #include <linux/compiler.h>
13136 #include <linux/sysctl.h>
13137 #include <linux/kcov.h>
13138 +#include <linux/vs_context.h>
13139 +#include <linux/vs_network.h>
13140 +#include <linux/vs_limit.h>
13142 #include <asm/pgtable.h>
13143 #include <asm/pgalloc.h>
13144 @@ -353,6 +356,8 @@ void free_task(struct task_struct *tsk)
13145 WARN_ON_ONCE(atomic_read(&tsk->stack_refcount) != 0);
13147 rt_mutex_debug_task_free(tsk);
13148 + clr_vx_info(&tsk->vx_info);
13149 + clr_nx_info(&tsk->nx_info);
13150 ftrace_graph_exit_task(tsk);
13151 put_seccomp_filter(tsk);
13152 arch_release_task_struct(tsk);
13153 @@ -1475,6 +1480,8 @@ static __latent_entropy struct task_stru
13156 struct task_struct *p;
13157 + struct vx_info *vxi;
13158 + struct nx_info *nxi;
13160 if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
13161 return ERR_PTR(-EINVAL);
13162 @@ -1535,7 +1542,12 @@ static __latent_entropy struct task_stru
13163 DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
13164 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
13166 + init_vx_info(&p->vx_info, current_vx_info());
13167 + init_nx_info(&p->nx_info, current_nx_info());
13170 + if (!vx_nproc_avail(1))
13171 + goto bad_fork_free;
13172 if (atomic_read(&p->real_cred->user->processes) >=
13173 task_rlimit(p, RLIMIT_NPROC)) {
13174 if (p->real_cred->user != INIT_USER &&
13175 @@ -1832,6 +1844,18 @@ static __latent_entropy struct task_stru
13177 spin_unlock(¤t->sighand->siglock);
13178 syscall_tracepoint_update(p);
13180 + /* p is copy of current */
13181 + vxi = p->vx_info;
13183 + claim_vx_info(vxi, p);
13184 + atomic_inc(&vxi->cvirt.nr_threads);
13185 + atomic_inc(&vxi->cvirt.total_forks);
13188 + nxi = p->nx_info;
13190 + claim_nx_info(nxi, p);
13191 write_unlock_irq(&tasklist_lock);
13193 proc_fork_connector(p);
13194 diff -NurpP --minimal linux-4.9.76/kernel/kthread.c linux-4.9.76-vs2.3.9.5/kernel/kthread.c
13195 --- linux-4.9.76/kernel/kthread.c 2018-01-13 21:29:01.000000000 +0000
13196 +++ linux-4.9.76-vs2.3.9.5/kernel/kthread.c 2018-01-10 02:50:49.000000000 +0000
13198 #include <linux/ptrace.h>
13199 #include <linux/uaccess.h>
13200 #include <linux/cgroup.h>
13201 +#include <linux/vs_pid.h>
13202 #include <trace/events/sched.h>
13204 static DEFINE_SPINLOCK(kthread_create_lock);
13205 diff -NurpP --minimal linux-4.9.76/kernel/nsproxy.c linux-4.9.76-vs2.3.9.5/kernel/nsproxy.c
13206 --- linux-4.9.76/kernel/nsproxy.c 2016-12-11 19:17:54.000000000 +0000
13207 +++ linux-4.9.76-vs2.3.9.5/kernel/nsproxy.c 2018-01-14 06:25:23.000000000 +0000
13208 @@ -20,12 +20,15 @@
13209 #include <linux/mnt_namespace.h>
13210 #include <linux/utsname.h>
13211 #include <linux/pid_namespace.h>
13212 +#include <linux/vserver/global.h>
13213 +#include <linux/vserver/debug.h>
13214 #include <net/net_namespace.h>
13215 #include <linux/ipc_namespace.h>
13216 #include <linux/proc_ns.h>
13217 #include <linux/file.h>
13218 #include <linux/syscalls.h>
13219 #include <linux/cgroup.h>
13220 +#include "../fs/mount.h"
13222 static struct kmem_cache *nsproxy_cachep;
13224 @@ -50,8 +53,11 @@ static inline struct nsproxy *create_nsp
13225 struct nsproxy *nsproxy;
13227 nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
13230 atomic_set(&nsproxy->count, 1);
13231 + atomic_inc(&vs_global_nsproxy);
13233 + vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
13237 @@ -60,9 +66,12 @@ static inline struct nsproxy *create_nsp
13238 * Return the newly created nsproxy. Do not attach this to the task,
13239 * leave it to the caller to do proper locking and attach it to task.
13241 -static struct nsproxy *create_new_namespaces(unsigned long flags,
13242 - struct task_struct *tsk, struct user_namespace *user_ns,
13243 - struct fs_struct *new_fs)
13244 +static struct nsproxy *unshare_namespaces(
13245 + unsigned long flags,
13246 + struct nsproxy *orig,
13247 + struct fs_struct *new_fs,
13248 + struct user_namespace *new_user,
13249 + struct pid_namespace *new_pid)
13251 struct nsproxy *new_nsp;
13253 @@ -71,39 +80,37 @@ static struct nsproxy *create_new_namesp
13255 return ERR_PTR(-ENOMEM);
13257 - new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
13258 + new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
13259 if (IS_ERR(new_nsp->mnt_ns)) {
13260 err = PTR_ERR(new_nsp->mnt_ns);
13264 - new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
13265 + new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
13266 if (IS_ERR(new_nsp->uts_ns)) {
13267 err = PTR_ERR(new_nsp->uts_ns);
13271 - new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
13272 + new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
13273 if (IS_ERR(new_nsp->ipc_ns)) {
13274 err = PTR_ERR(new_nsp->ipc_ns);
13278 - new_nsp->pid_ns_for_children =
13279 - copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
13280 + new_nsp->pid_ns_for_children = copy_pid_ns(flags, new_user, new_pid);
13281 if (IS_ERR(new_nsp->pid_ns_for_children)) {
13282 err = PTR_ERR(new_nsp->pid_ns_for_children);
13286 - new_nsp->cgroup_ns = copy_cgroup_ns(flags, user_ns,
13287 - tsk->nsproxy->cgroup_ns);
13288 + new_nsp->cgroup_ns = copy_cgroup_ns(flags, new_user, orig->cgroup_ns);
13289 if (IS_ERR(new_nsp->cgroup_ns)) {
13290 err = PTR_ERR(new_nsp->cgroup_ns);
13294 - new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
13295 + new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
13296 if (IS_ERR(new_nsp->net_ns)) {
13297 err = PTR_ERR(new_nsp->net_ns);
13299 @@ -130,6 +137,43 @@ out_ns:
13300 return ERR_PTR(err);
13303 +static struct nsproxy *create_new_namespaces(unsigned long flags,
13304 + struct task_struct *tsk, struct user_namespace *user_ns,
13305 + struct fs_struct *new_fs)
13308 + return unshare_namespaces(flags, tsk->nsproxy,
13309 + new_fs, user_ns, task_active_pid_ns(tsk));
13313 + * copies the nsproxy, setting refcount to 1, and grabbing a
13314 + * reference to all contained namespaces.
13316 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
13318 + struct nsproxy *ns = create_nsproxy();
13321 + memcpy(ns, orig, sizeof(struct nsproxy));
13322 + atomic_set(&ns->count, 1);
13325 + get_mnt_ns(ns->mnt_ns);
13327 + get_uts_ns(ns->uts_ns);
13329 + get_ipc_ns(ns->ipc_ns);
13330 + if (ns->pid_ns_for_children)
13331 + get_pid_ns(ns->pid_ns_for_children);
13333 + get_net(ns->net_ns);
13334 + if (ns->cgroup_ns)
13335 + get_cgroup_ns(ns->cgroup_ns);
13341 * called from clone. This now handles copy for nsproxy and all
13342 * namespaces therein.
13343 @@ -138,7 +182,10 @@ int copy_namespaces(unsigned long flags,
13345 struct nsproxy *old_ns = tsk->nsproxy;
13346 struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
13347 - struct nsproxy *new_ns;
13348 + struct nsproxy *new_ns = NULL;
13350 + vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
13351 + flags, tsk, old_ns);
13353 if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13354 CLONE_NEWPID | CLONE_NEWNET |
13355 @@ -147,7 +194,7 @@ int copy_namespaces(unsigned long flags,
13359 - if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13360 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags))
13364 @@ -166,6 +213,9 @@ int copy_namespaces(unsigned long flags,
13365 return PTR_ERR(new_ns);
13367 tsk->nsproxy = new_ns;
13368 + vxdprintk(VXD_CBIT(space, 3),
13369 + "copy_namespaces(0x%08lx,%p[%p]) = [%p]",
13370 + flags, tsk, old_ns, new_ns);
13374 @@ -179,8 +229,10 @@ void free_nsproxy(struct nsproxy *ns)
13375 put_ipc_ns(ns->ipc_ns);
13376 if (ns->pid_ns_for_children)
13377 put_pid_ns(ns->pid_ns_for_children);
13379 + put_net(ns->net_ns);
13380 put_cgroup_ns(ns->cgroup_ns);
13381 - put_net(ns->net_ns);
13382 + atomic_dec(&vs_global_nsproxy);
13383 kmem_cache_free(nsproxy_cachep, ns);
13386 @@ -194,12 +246,16 @@ int unshare_nsproxy_namespaces(unsigned
13387 struct user_namespace *user_ns;
13390 + vxdprintk(VXD_CBIT(space, 4),
13391 + "unshare_nsproxy_namespaces(0x%08lx,[%p])",
13392 + unshare_flags, current->nsproxy);
13394 if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13395 CLONE_NEWNET | CLONE_NEWPID | CLONE_NEWCGROUP)))
13398 user_ns = new_cred ? new_cred->user_ns : current_user_ns();
13399 - if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13400 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
13403 *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
13404 diff -NurpP --minimal linux-4.9.76/kernel/pid.c linux-4.9.76-vs2.3.9.5/kernel/pid.c
13405 --- linux-4.9.76/kernel/pid.c 2018-01-13 21:29:01.000000000 +0000
13406 +++ linux-4.9.76-vs2.3.9.5/kernel/pid.c 2018-01-10 02:50:49.000000000 +0000
13408 #include <linux/syscalls.h>
13409 #include <linux/proc_ns.h>
13410 #include <linux/proc_fs.h>
13411 +#include <linux/vs_pid.h>
13413 #define pid_hashfn(nr, ns) \
13414 hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
13415 @@ -379,7 +380,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
13417 struct pid *find_vpid(int nr)
13419 - return find_pid_ns(nr, task_active_pid_ns(current));
13420 + return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
13422 EXPORT_SYMBOL_GPL(find_vpid);
13424 @@ -435,6 +436,9 @@ void transfer_pid(struct task_struct *ol
13425 struct task_struct *pid_task(struct pid *pid, enum pid_type type)
13427 struct task_struct *result = NULL;
13429 + if (type == __PIDTYPE_REALPID)
13430 + type = PIDTYPE_PID;
13432 struct hlist_node *first;
13433 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
13434 @@ -453,7 +457,7 @@ struct task_struct *find_task_by_pid_ns(
13436 RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
13437 "find_task_by_pid_ns() needs rcu_read_lock() protection");
13438 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
13439 + return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
13442 struct task_struct *find_task_by_vpid(pid_t vnr)
13443 @@ -497,7 +501,7 @@ struct pid *find_get_pid(pid_t nr)
13445 EXPORT_SYMBOL_GPL(find_get_pid);
13447 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13448 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
13452 @@ -511,6 +515,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
13454 EXPORT_SYMBOL_GPL(pid_nr_ns);
13456 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13458 + return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
13461 pid_t pid_vnr(struct pid *pid)
13463 return pid_nr_ns(pid, task_active_pid_ns(current));
13464 diff -NurpP --minimal linux-4.9.76/kernel/pid_namespace.c linux-4.9.76-vs2.3.9.5/kernel/pid_namespace.c
13465 --- linux-4.9.76/kernel/pid_namespace.c 2018-01-13 21:29:01.000000000 +0000
13466 +++ linux-4.9.76-vs2.3.9.5/kernel/pid_namespace.c 2018-01-10 02:50:49.000000000 +0000
13468 #include <linux/proc_ns.h>
13469 #include <linux/reboot.h>
13470 #include <linux/export.h>
13471 +#include <linux/vserver/global.h>
13475 @@ -124,6 +125,7 @@ static struct pid_namespace *create_pid_
13476 ns->ns.ops = &pidns_operations;
13478 kref_init(&ns->kref);
13479 + atomic_inc(&vs_global_pid_ns);
13481 ns->parent = get_pid_ns(parent_pid_ns);
13482 ns->user_ns = get_user_ns(user_ns);
13483 @@ -142,6 +144,7 @@ static struct pid_namespace *create_pid_
13485 kfree(ns->pidmap[0].page);
13487 + atomic_dec(&vs_global_pid_ns);
13488 kmem_cache_free(pid_ns_cachep, ns);
13490 dec_pid_namespaces(ucounts);
13491 diff -NurpP --minimal linux-4.9.76/kernel/printk/printk.c linux-4.9.76-vs2.3.9.5/kernel/printk/printk.c
13492 --- linux-4.9.76/kernel/printk/printk.c 2018-01-13 21:29:01.000000000 +0000
13493 +++ linux-4.9.76-vs2.3.9.5/kernel/printk/printk.c 2018-01-10 02:50:49.000000000 +0000
13495 #include <linux/utsname.h>
13496 #include <linux/ctype.h>
13497 #include <linux/uio.h>
13498 +#include <linux/vs_cvirt.h>
13500 #include <asm/uaccess.h>
13501 #include <asm/sections.h>
13502 @@ -612,7 +613,7 @@ int check_syslog_permissions(int type, i
13505 if (syslog_action_restricted(type)) {
13506 - if (capable(CAP_SYSLOG))
13507 + if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
13510 * For historical reasons, accept CAP_SYS_ADMIN too, with
13511 @@ -1432,12 +1433,9 @@ int do_syslog(int type, char __user *buf
13516 - case SYSLOG_ACTION_CLOSE: /* Close log */
13518 - case SYSLOG_ACTION_OPEN: /* Open log */
13520 - case SYSLOG_ACTION_READ: /* Read from log */
13521 + if ((type == SYSLOG_ACTION_READ) ||
13522 + (type == SYSLOG_ACTION_READ_ALL) ||
13523 + (type == SYSLOG_ACTION_READ_CLEAR)) {
13525 if (!buf || len < 0)
13527 @@ -1448,6 +1446,16 @@ int do_syslog(int type, char __user *buf
13532 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
13533 + return vx_do_syslog(type, buf, len);
13536 + case SYSLOG_ACTION_CLOSE: /* Close log */
13538 + case SYSLOG_ACTION_OPEN: /* Open log */
13540 + case SYSLOG_ACTION_READ: /* Read from log */
13541 error = wait_event_interruptible(log_wait,
13542 syslog_seq != log_next_seq);
13544 @@ -1460,16 +1468,6 @@ int do_syslog(int type, char __user *buf
13546 /* Read last kernel messages */
13547 case SYSLOG_ACTION_READ_ALL:
13549 - if (!buf || len < 0)
13554 - if (!access_ok(VERIFY_WRITE, buf, len)) {
13558 error = syslog_print_all(buf, len, clear);
13560 /* Clear ring buffer */
13561 diff -NurpP --minimal linux-4.9.76/kernel/ptrace.c linux-4.9.76-vs2.3.9.5/kernel/ptrace.c
13562 --- linux-4.9.76/kernel/ptrace.c 2018-01-13 21:29:01.000000000 +0000
13563 +++ linux-4.9.76-vs2.3.9.5/kernel/ptrace.c 2018-01-10 02:50:49.000000000 +0000
13565 #include <linux/syscalls.h>
13566 #include <linux/uaccess.h>
13567 #include <linux/regset.h>
13568 +#include <linux/vs_context.h>
13569 #include <linux/hw_breakpoint.h>
13570 #include <linux/cn_proc.h>
13571 #include <linux/compat.h>
13572 @@ -325,6 +326,11 @@ ok:
13573 !ptrace_has_cap(mm->user_ns, mode)))
13576 + if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
13578 + if (!vx_check(task->xid, VS_IDENT) &&
13579 + !task_vx_flags(task, VXF_STATE_ADMIN, 0))
13581 return security_ptrace_access_check(task, mode);
13584 diff -NurpP --minimal linux-4.9.76/kernel/reboot.c linux-4.9.76-vs2.3.9.5/kernel/reboot.c
13585 --- linux-4.9.76/kernel/reboot.c 2016-12-11 19:17:54.000000000 +0000
13586 +++ linux-4.9.76-vs2.3.9.5/kernel/reboot.c 2018-01-10 02:50:49.000000000 +0000
13588 #include <linux/syscalls.h>
13589 #include <linux/syscore_ops.h>
13590 #include <linux/uaccess.h>
13591 +#include <linux/vs_pid.h>
13594 * this indicates whether you can reboot with ctrl-alt-del: the default is yes
13595 @@ -269,6 +270,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
13597 static DEFINE_MUTEX(reboot_mutex);
13599 +long vs_reboot(unsigned int, void __user *);
13602 * Reboot system call: for obvious reasons only root may call it,
13603 * and even root needs to set up some magic numbers in the registers
13604 @@ -311,6 +314,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
13605 if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
13606 cmd = LINUX_REBOOT_CMD_HALT;
13608 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
13609 + return vs_reboot(cmd, arg);
13611 mutex_lock(&reboot_mutex);
13613 case LINUX_REBOOT_CMD_RESTART:
13614 diff -NurpP --minimal linux-4.9.76/kernel/sched/core.c linux-4.9.76-vs2.3.9.5/kernel/sched/core.c
13615 --- linux-4.9.76/kernel/sched/core.c 2018-01-13 21:29:01.000000000 +0000
13616 +++ linux-4.9.76-vs2.3.9.5/kernel/sched/core.c 2018-01-10 09:06:27.000000000 +0000
13618 #include <linux/compiler.h>
13619 #include <linux/frame.h>
13620 #include <linux/prefetch.h>
13621 +#include <linux/vs_sched.h>
13622 +#include <linux/vs_cvirt.h>
13624 #include <asm/switch_to.h>
13625 #include <asm/tlb.h>
13626 @@ -3429,6 +3431,7 @@ void __noreturn do_task_dead(void)
13627 __set_current_state(TASK_DEAD);
13628 current->flags |= PF_NOFREEZE; /* tell freezer to ignore us */
13630 + printk("bad task: %p [%lx]\n", current, current->state);
13632 /* Avoid "noreturn function does return". */
13634 @@ -3822,7 +3825,7 @@ SYSCALL_DEFINE1(nice, int, increment)
13636 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
13637 if (increment < 0 && !can_nice(current, nice))
13639 + return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
13641 retval = security_task_setnice(current, nice);
13643 diff -NurpP --minimal linux-4.9.76/kernel/sched/cputime.c linux-4.9.76-vs2.3.9.5/kernel/sched/cputime.c
13644 --- linux-4.9.76/kernel/sched/cputime.c 2016-12-11 19:17:54.000000000 +0000
13645 +++ linux-4.9.76-vs2.3.9.5/kernel/sched/cputime.c 2018-01-10 02:50:49.000000000 +0000
13647 #include <linux/kernel_stat.h>
13648 #include <linux/static_key.h>
13649 #include <linux/context_tracking.h>
13650 +#include <linux/vs_sched.h>
13652 #ifdef CONFIG_PARAVIRT
13653 #include <asm/paravirt.h>
13654 @@ -133,14 +134,17 @@ static inline void task_group_account_fi
13655 void account_user_time(struct task_struct *p, cputime_t cputime,
13656 cputime_t cputime_scaled)
13658 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
13659 + int nice = (task_nice(p) > 0);
13662 /* Add user time to process. */
13663 p->utime += cputime;
13664 p->utimescaled += cputime_scaled;
13665 + vx_account_user(vxi, cputime, nice);
13666 account_group_user_time(p, cputime);
13668 - index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
13669 + index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
13671 /* Add user time to cpustat. */
13672 task_group_account_field(p, index, (__force u64) cputime);
13673 @@ -187,9 +191,12 @@ static inline
13674 void __account_system_time(struct task_struct *p, cputime_t cputime,
13675 cputime_t cputime_scaled, int index)
13677 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
13679 /* Add system time to process. */
13680 p->stime += cputime;
13681 p->stimescaled += cputime_scaled;
13682 + vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
13683 account_group_system_time(p, cputime);
13685 /* Add system time to cpustat. */
13686 diff -NurpP --minimal linux-4.9.76/kernel/sched/fair.c linux-4.9.76-vs2.3.9.5/kernel/sched/fair.c
13687 --- linux-4.9.76/kernel/sched/fair.c 2018-01-13 21:29:01.000000000 +0000
13688 +++ linux-4.9.76-vs2.3.9.5/kernel/sched/fair.c 2018-01-10 02:50:49.000000000 +0000
13690 #include <linux/mempolicy.h>
13691 #include <linux/migrate.h>
13692 #include <linux/task_work.h>
13693 +#include <linux/vs_cvirt.h>
13695 #include <trace/events/sched.h>
13697 @@ -3410,6 +3411,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
13698 __enqueue_entity(cfs_rq, se);
13701 + if (entity_is_task(se))
13702 + vx_activate_task(task_of(se));
13703 if (cfs_rq->nr_running == 1) {
13704 list_add_leaf_cfs_rq(cfs_rq);
13705 check_enqueue_throttle(cfs_rq);
13706 @@ -3479,6 +3482,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
13707 if (se != cfs_rq->curr)
13708 __dequeue_entity(cfs_rq, se);
13710 + if (entity_is_task(se))
13711 + vx_deactivate_task(task_of(se));
13712 account_entity_dequeue(cfs_rq, se);
13715 diff -NurpP --minimal linux-4.9.76/kernel/signal.c linux-4.9.76-vs2.3.9.5/kernel/signal.c
13716 --- linux-4.9.76/kernel/signal.c 2018-01-13 21:29:01.000000000 +0000
13717 +++ linux-4.9.76-vs2.3.9.5/kernel/signal.c 2018-01-13 21:30:31.000000000 +0000
13719 #include <linux/compat.h>
13720 #include <linux/cn_proc.h>
13721 #include <linux/compiler.h>
13722 +#include <linux/vs_context.h>
13723 +#include <linux/vs_pid.h>
13725 #define CREATE_TRACE_POINTS
13726 #include <trace/events/signal.h>
13727 @@ -726,9 +728,18 @@ static int check_kill_permission(int sig
13731 + vxdprintk(VXD_CBIT(misc, 7),
13732 + "check_kill_permission(%d,%p,%p[#%u,%u])",
13733 + sig, info, t, vx_task_xid(t), t->pid);
13735 if (!valid_signal(sig))
13738 +/* FIXME: needed? if so, why?
13739 + if ((info != SEND_SIG_NOINFO) &&
13740 + (is_si_special(info) || !si_fromuser(info)))
13743 if (!si_fromuser(info))
13746 @@ -752,6 +763,20 @@ static int check_kill_permission(int sig
13751 + if (t->pid == 1 && current->xid)
13755 + /* FIXME: we shouldn't return ESRCH ever, to avoid
13756 + loops, maybe ENOENT or EACCES? */
13757 + if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
13758 + vxdprintk(current->xid || VXD_CBIT(misc, 7),
13759 + "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
13760 + sig, info, t, vx_task_xid(t), t->pid, current->xid);
13764 return security_task_kill(t, info, sig, 0);
13767 @@ -1303,8 +1328,14 @@ int kill_pid_info(int sig, struct siginf
13770 p = pid_task(pid, PIDTYPE_PID);
13772 - error = group_send_sig_info(sig, info, p);
13774 + if (vx_check(vx_task_xid(p), VS_IDENT))
13775 + error = group_send_sig_info(sig, info, p);
13777 + rcu_read_unlock();
13782 if (likely(!p || error != -ESRCH))
13784 @@ -1349,7 +1380,7 @@ int kill_pid_info_as_cred(int sig, struc
13787 p = pid_task(pid, PIDTYPE_PID);
13789 + if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
13793 @@ -1401,8 +1432,10 @@ static int kill_something_info(int sig,
13794 struct task_struct * p;
13796 for_each_process(p) {
13797 - if (task_pid_vnr(p) > 1 &&
13798 - !same_thread_group(p, current)) {
13799 + if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
13800 + task_pid_vnr(p) > 1 &&
13801 + !same_thread_group(p, current) &&
13802 + !vx_current_initpid(p->pid)) {
13803 int err = group_send_sig_info(sig, info, p);
13806 @@ -2255,6 +2288,11 @@ relock:
13807 !sig_kernel_only(signr))
13810 + /* virtual init is protected against user signals */
13811 + if ((ksig->info.si_code == SI_USER) &&
13812 + vx_current_initpid(current->pid))
13815 if (sig_kernel_stop(signr)) {
13817 * The default action is to stop all threads in
13818 diff -NurpP --minimal linux-4.9.76/kernel/softirq.c linux-4.9.76-vs2.3.9.5/kernel/softirq.c
13819 --- linux-4.9.76/kernel/softirq.c 2016-12-11 19:17:54.000000000 +0000
13820 +++ linux-4.9.76-vs2.3.9.5/kernel/softirq.c 2018-01-10 02:50:49.000000000 +0000
13822 #include <linux/smpboot.h>
13823 #include <linux/tick.h>
13824 #include <linux/irq.h>
13825 +#include <linux/vs_context.h>
13827 #define CREATE_TRACE_POINTS
13828 #include <trace/events/irq.h>
13829 diff -NurpP --minimal linux-4.9.76/kernel/sys.c linux-4.9.76-vs2.3.9.5/kernel/sys.c
13830 --- linux-4.9.76/kernel/sys.c 2016-12-11 19:17:54.000000000 +0000
13831 +++ linux-4.9.76-vs2.3.9.5/kernel/sys.c 2018-01-10 02:50:49.000000000 +0000
13833 #include <linux/cred.h>
13835 #include <linux/kmsg_dump.h>
13836 +#include <linux/vs_pid.h>
13837 /* Move somewhere else to avoid recompiling? */
13838 #include <generated/utsrelease.h>
13840 @@ -157,7 +158,10 @@ static int set_one_prio(struct task_stru
13843 if (niceval < task_nice(p) && !can_nice(p, niceval)) {
13845 + if (vx_flags(VXF_IGNEG_NICE, 0))
13851 no_nice = security_task_setnice(p, niceval);
13852 @@ -208,6 +212,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
13854 pgrp = task_pgrp(current);
13855 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
13856 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
13858 error = set_one_prio(p, niceval, error);
13859 } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
13861 @@ -274,6 +280,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
13863 pgrp = task_pgrp(current);
13864 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
13865 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
13867 niceval = nice_to_rlimit(task_nice(p));
13868 if (niceval > retval)
13870 @@ -290,6 +298,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
13871 goto out_unlock; /* No processes for this user */
13873 do_each_thread(g, p) {
13874 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
13876 if (uid_eq(task_uid(p), uid) && task_pid_vnr(p)) {
13877 niceval = nice_to_rlimit(task_nice(p));
13878 if (niceval > retval)
13879 @@ -1217,7 +1227,8 @@ SYSCALL_DEFINE2(sethostname, char __user
13881 char tmp[__NEW_UTS_LEN];
13883 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
13884 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
13885 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
13888 if (len < 0 || len > __NEW_UTS_LEN)
13889 @@ -1268,7 +1279,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
13891 char tmp[__NEW_UTS_LEN];
13893 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
13894 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
13895 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
13897 if (len < 0 || len > __NEW_UTS_LEN)
13899 @@ -1386,7 +1398,7 @@ int do_prlimit(struct task_struct *tsk,
13900 /* Keep the capable check against init_user_ns until
13901 cgroups can contain all limits */
13902 if (new_rlim->rlim_max > rlim->rlim_max &&
13903 - !capable(CAP_SYS_RESOURCE))
13904 + !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
13907 retval = security_task_setrlimit(tsk->group_leader,
13908 @@ -1439,7 +1451,8 @@ static int check_prlimit_permission(stru
13909 gid_eq(cred->gid, tcred->sgid) &&
13910 gid_eq(cred->gid, tcred->gid))
13912 - if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
13913 + if (vx_ns_capable(tcred->user_ns,
13914 + CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
13918 diff -NurpP --minimal linux-4.9.76/kernel/sysctl.c linux-4.9.76-vs2.3.9.5/kernel/sysctl.c
13919 --- linux-4.9.76/kernel/sysctl.c 2018-01-13 21:29:01.000000000 +0000
13920 +++ linux-4.9.76-vs2.3.9.5/kernel/sysctl.c 2018-01-10 02:50:49.000000000 +0000
13922 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
13923 #include <linux/lockdep.h>
13925 +extern char vshelper_path[];
13926 #ifdef CONFIG_CHR_DEV_SG
13927 #include <scsi/sg.h>
13929 @@ -282,6 +283,13 @@ static int max_extfrag_threshold = 1000;
13931 static struct ctl_table kern_table[] = {
13933 + .procname = "vshelper",
13934 + .data = &vshelper_path,
13937 + .proc_handler = proc_dostring,
13940 .procname = "sched_child_runs_first",
13941 .data = &sysctl_sched_child_runs_first,
13942 .maxlen = sizeof(unsigned int),
13943 @@ -1426,7 +1434,6 @@ static struct ctl_table vm_table[] = {
13948 #endif /* CONFIG_COMPACTION */
13950 .procname = "min_free_kbytes",
13951 diff -NurpP --minimal linux-4.9.76/kernel/sysctl_binary.c linux-4.9.76-vs2.3.9.5/kernel/sysctl_binary.c
13952 --- linux-4.9.76/kernel/sysctl_binary.c 2016-12-11 19:17:54.000000000 +0000
13953 +++ linux-4.9.76-vs2.3.9.5/kernel/sysctl_binary.c 2018-01-10 02:50:49.000000000 +0000
13954 @@ -74,6 +74,7 @@ static const struct bin_table bin_kern_t
13956 { CTL_INT, KERN_PANIC, "panic" },
13957 { CTL_INT, KERN_REALROOTDEV, "real-root-dev" },
13958 + { CTL_STR, KERN_VSHELPER, "vshelper" },
13960 { CTL_STR, KERN_SPARC_REBOOT, "reboot-cmd" },
13961 { CTL_INT, KERN_CTLALTDEL, "ctrl-alt-del" },
13962 diff -NurpP --minimal linux-4.9.76/kernel/time/posix-timers.c linux-4.9.76-vs2.3.9.5/kernel/time/posix-timers.c
13963 --- linux-4.9.76/kernel/time/posix-timers.c 2016-12-11 19:17:54.000000000 +0000
13964 +++ linux-4.9.76-vs2.3.9.5/kernel/time/posix-timers.c 2018-01-10 02:50:49.000000000 +0000
13966 #include <linux/workqueue.h>
13967 #include <linux/export.h>
13968 #include <linux/hashtable.h>
13969 +#include <linux/vs_context.h>
13971 #include "timekeeping.h"
13973 @@ -407,6 +408,7 @@ int posix_timer_event(struct k_itimer *t
13975 struct task_struct *task;
13976 int shared, ret = -1;
13979 * FIXME: if ->sigq is queued we can race with
13980 * dequeue_signal()->do_schedule_next_timer().
13981 @@ -423,10 +425,18 @@ int posix_timer_event(struct k_itimer *t
13983 task = pid_task(timr->it_pid, PIDTYPE_PID);
13985 + struct vx_info_save vxis;
13986 + struct vx_info *vxi;
13988 + vxi = get_vx_info(task->vx_info);
13989 + enter_vx_info(vxi, &vxis);
13990 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
13991 ret = send_sigqueue(timr->sigq, task, shared);
13992 + leave_vx_info(&vxis);
13993 + put_vx_info(vxi);
13997 /* If we failed to send the signal the timer stops. */
14000 diff -NurpP --minimal linux-4.9.76/kernel/time/time.c linux-4.9.76-vs2.3.9.5/kernel/time/time.c
14001 --- linux-4.9.76/kernel/time/time.c 2016-12-11 19:17:54.000000000 +0000
14002 +++ linux-4.9.76-vs2.3.9.5/kernel/time/time.c 2018-01-10 09:31:11.000000000 +0000
14004 #include <linux/fs.h>
14005 #include <linux/math64.h>
14006 #include <linux/ptrace.h>
14007 +#include <linux/vs_time.h>
14009 #include <asm/uaccess.h>
14010 #include <asm/unistd.h>
14011 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
14015 - do_settimeofday(&tv);
14016 + vx_settimeofday(&tv);
14020 @@ -186,7 +187,7 @@ int do_sys_settimeofday64(const struct t
14024 - return do_settimeofday64(tv);
14025 + return vx_settimeofday64(tv);
14029 diff -NurpP --minimal linux-4.9.76/kernel/time/timekeeping.c linux-4.9.76-vs2.3.9.5/kernel/time/timekeeping.c
14030 --- linux-4.9.76/kernel/time/timekeeping.c 2018-01-13 21:29:01.000000000 +0000
14031 +++ linux-4.9.76-vs2.3.9.5/kernel/time/timekeeping.c 2018-01-10 02:50:49.000000000 +0000
14033 #include <linux/stop_machine.h>
14034 #include <linux/pvclock_gtod.h>
14035 #include <linux/compiler.h>
14036 +#include <linux/vs_time.h>
14038 #include "tick-internal.h"
14039 #include "ntp_internal.h"
14040 diff -NurpP --minimal linux-4.9.76/kernel/time/timer.c linux-4.9.76-vs2.3.9.5/kernel/time/timer.c
14041 --- linux-4.9.76/kernel/time/timer.c 2018-01-13 21:29:01.000000000 +0000
14042 +++ linux-4.9.76-vs2.3.9.5/kernel/time/timer.c 2018-01-10 02:50:49.000000000 +0000
14044 #include <linux/sched/sysctl.h>
14045 #include <linux/slab.h>
14046 #include <linux/compat.h>
14047 +#include <linux/vs_base.h>
14048 +#include <linux/vs_cvirt.h>
14049 +#include <linux/vs_pid.h>
14050 +#include <linux/vserver/sched.h>
14052 #include <asm/uaccess.h>
14053 #include <asm/unistd.h>
14054 diff -NurpP --minimal linux-4.9.76/kernel/user_namespace.c linux-4.9.76-vs2.3.9.5/kernel/user_namespace.c
14055 --- linux-4.9.76/kernel/user_namespace.c 2016-12-11 19:17:54.000000000 +0000
14056 +++ linux-4.9.76-vs2.3.9.5/kernel/user_namespace.c 2018-01-10 02:50:49.000000000 +0000
14058 #include <linux/ctype.h>
14059 #include <linux/projid.h>
14060 #include <linux/fs_struct.h>
14061 +#include <linux/vserver/global.h>
14063 static struct kmem_cache *user_ns_cachep __read_mostly;
14064 static DEFINE_MUTEX(userns_state_mutex);
14065 @@ -115,6 +116,7 @@ int create_user_ns(struct cred *new)
14067 atomic_set(&ns->count, 1);
14068 /* Leave the new->user_ns reference with the new user namespace. */
14069 + atomic_inc(&vs_global_user_ns);
14070 ns->parent = parent_ns;
14071 ns->level = parent_ns->level + 1;
14073 @@ -185,6 +187,7 @@ static void free_user_ns(struct work_str
14074 key_put(ns->persistent_keyring_register);
14076 ns_free_inum(&ns->ns);
14077 + atomic_dec(&vs_global_user_ns);
14078 kmem_cache_free(user_ns_cachep, ns);
14079 dec_user_namespaces(ucounts);
14081 @@ -404,6 +407,18 @@ gid_t from_kgid_munged(struct user_names
14083 EXPORT_SYMBOL(from_kgid_munged);
14085 +ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
14087 + return KTAGT_INIT(tag);
14089 +EXPORT_SYMBOL(make_ktag);
14091 +vtag_t from_ktag(struct user_namespace *to, ktag_t tag)
14093 + return __ktag_val(tag);
14095 +EXPORT_SYMBOL(from_ktag);
14098 * make_kprojid - Map a user-namespace projid pair into a kprojid.
14099 * @ns: User namespace that the projid is in
14100 diff -NurpP --minimal linux-4.9.76/kernel/utsname.c linux-4.9.76-vs2.3.9.5/kernel/utsname.c
14101 --- linux-4.9.76/kernel/utsname.c 2016-12-11 19:17:54.000000000 +0000
14102 +++ linux-4.9.76-vs2.3.9.5/kernel/utsname.c 2018-01-10 09:05:33.000000000 +0000
14104 #include <linux/slab.h>
14105 #include <linux/user_namespace.h>
14106 #include <linux/proc_ns.h>
14107 +#include <linux/vserver/global.h>
14109 static struct ucounts *inc_uts_namespaces(struct user_namespace *ns)
14111 @@ -32,8 +33,10 @@ static struct uts_namespace *create_uts_
14112 struct uts_namespace *uts_ns;
14114 uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
14117 kref_init(&uts_ns->kref);
14118 + atomic_inc(&vs_global_uts_ns);
14123 @@ -111,6 +114,7 @@ void free_uts_ns(struct kref *kref)
14124 dec_uts_namespaces(ns->ucounts);
14125 put_user_ns(ns->user_ns);
14126 ns_free_inum(&ns->ns);
14127 + atomic_dec(&vs_global_uts_ns);
14131 diff -NurpP --minimal linux-4.9.76/kernel/vserver/Kconfig linux-4.9.76-vs2.3.9.5/kernel/vserver/Kconfig
14132 --- linux-4.9.76/kernel/vserver/Kconfig 1970-01-01 00:00:00.000000000 +0000
14133 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/Kconfig 2018-01-10 02:50:49.000000000 +0000
14136 +# Linux VServer configuration
14139 +menu "Linux VServer"
14141 +config VSERVER_AUTO_LBACK
14142 + bool "Automatically Assign Loopback IP"
14145 + Automatically assign a guest specific loopback
14146 + IP and add it to the kernel network stack on
14149 +config VSERVER_AUTO_SINGLE
14150 + bool "Automatic Single IP Special Casing"
14153 + This allows network contexts with a single IP to
14154 + automatically remap 0.0.0.0 bindings to that IP,
14155 + avoiding further network checks and improving
14158 + (note: such guests do not allow to change the ip
14159 + on the fly and do not show loopback addresses)
14161 +config VSERVER_COWBL
14162 + bool "Enable COW Immutable Link Breaking"
14165 + This enables the COW (Copy-On-Write) link break code.
14166 + It allows you to treat unified files like normal files
14167 + when writing to them (which will implicitely break the
14168 + link and create a copy of the unified file)
14170 +config VSERVER_VTIME
14171 + bool "Enable Virtualized Guest Time (EXPERIMENTAL)"
14174 + This enables per guest time offsets to allow for
14175 + adjusting the system clock individually per guest.
14176 + this adds some overhead to the time functions and
14177 + therefore should not be enabled without good reason.
14179 +config VSERVER_DEVICE
14180 + bool "Enable Guest Device Mapping (EXPERIMENTAL)"
14183 + This enables generic device remapping.
14185 +config VSERVER_PROC_SECURE
14186 + bool "Enable Proc Security"
14187 + depends on PROC_FS
14190 + This configures ProcFS security to initially hide
14191 + non-process entries for all contexts except the main and
14192 + spectator context (i.e. for all guests), which is a secure
14195 + (note: on 1.2x the entries were visible by default)
14198 + prompt "Persistent Inode Tagging"
14199 + default TAGGING_ID24
14201 + This adds persistent context information to filesystems
14202 + mounted with the tagxid option. Tagging is a requirement
14203 + for per-context disk limits and per-context quota.
14206 +config TAGGING_NONE
14209 + do not store per-context information in inodes.
14211 +config TAGGING_UID16
14212 + bool "UID16/GID32"
14214 + reduces UID to 16 bit, but leaves GID at 32 bit.
14216 +config TAGGING_GID16
14217 + bool "UID32/GID16"
14219 + reduces GID to 16 bit, but leaves UID at 32 bit.
14221 +config TAGGING_ID24
14222 + bool "UID24/GID24"
14224 + uses the upper 8bit from UID and GID for XID tagging
14225 + which leaves 24bit for UID/GID each, which should be
14226 + more than sufficient for normal use.
14228 +config TAGGING_INTERN
14229 + bool "UID32/GID32"
14231 + this uses otherwise reserved inode fields in the on
14232 + disk representation, which limits the use to a few
14233 + filesystems (currently ext2 and ext3)
14238 + bool "Tag NFSD User Auth and Files"
14241 + Enable this if you do want the in-kernel NFS
14242 + Server to use the tagging specified above.
14243 + (will require patched clients too)
14245 +config VSERVER_PRIVACY
14246 + bool "Honor Privacy Aspects of Guests"
14249 + When enabled, most context checks will disallow
14250 + access to structures assigned to a specific context,
14251 + like ptys or loop devices.
14253 +config VSERVER_CONTEXTS
14254 + int "Maximum number of Contexts (1-65533)" if EMBEDDED
14256 + default "768" if 64BIT
14259 + This setting will optimize certain data structures
14260 + and memory allocations according to the expected
14263 + note: this is not a strict upper limit.
14265 +config VSERVER_WARN
14266 + bool "VServer Warnings"
14269 + This enables various runtime warnings, which will
14270 + notify about potential manipulation attempts or
14271 + resource shortage. It is generally considered to
14272 + be a good idea to have that enabled.
14274 +config VSERVER_WARN_DEVPTS
14275 + bool "VServer DevPTS Warnings"
14276 + depends on VSERVER_WARN
14279 + This enables DevPTS related warnings, issued when a
14280 + process inside a context tries to lookup or access
14281 + a dynamic pts from the host or a different context.
14283 +config VSERVER_DEBUG
14284 + bool "VServer Debugging Code"
14287 + Set this to yes if you want to be able to activate
14288 + debugging output at runtime. It adds a very small
14289 + overhead to all vserver related functions and
14290 + increases the kernel size by about 20k.
14292 +config VSERVER_HISTORY
14293 + bool "VServer History Tracing"
14294 + depends on VSERVER_DEBUG
14297 + Set this to yes if you want to record the history of
14298 + linux-vserver activities, so they can be replayed in
14299 + the event of a kernel panic or oops.
14301 +config VSERVER_HISTORY_SIZE
14302 + int "Per-CPU History Size (32-65536)"
14303 + depends on VSERVER_HISTORY
14307 + This allows you to specify the number of entries in
14308 + the per-CPU history buffer.
14310 +config VSERVER_EXTRA_MNT_CHECK
14311 + bool "Extra Checks for Reachability"
14314 + Set this to yes if you want to do extra checks for
14315 + vfsmount reachability in the proc filesystem code.
14316 + This shouldn't be required on any setup utilizing
14320 + prompt "Quotes used in debug and warn messages"
14321 + default QUOTES_ISO8859
14323 +config QUOTES_ISO8859
14324 + bool "Extended ASCII (ISO 8859) angle quotes"
14326 + This uses the extended ASCII characters \xbb
14327 + and \xab for quoting file and process names.
14329 +config QUOTES_UTF8
14330 + bool "UTF-8 angle quotes"
14332 + This uses the the UTF-8 sequences for angle
14333 + quotes to quote file and process names.
14335 +config QUOTES_ASCII
14336 + bool "ASCII single quotes"
14338 + This uses the ASCII single quote character
14339 + (\x27) to quote file and process names.
14349 + select NAMESPACES
14355 +config VSERVER_SECURITY
14357 + depends on SECURITY
14359 + select SECURITY_CAPABILITIES
14361 +config VSERVER_DISABLED
14365 diff -NurpP --minimal linux-4.9.76/kernel/vserver/Makefile linux-4.9.76-vs2.3.9.5/kernel/vserver/Makefile
14366 --- linux-4.9.76/kernel/vserver/Makefile 1970-01-01 00:00:00.000000000 +0000
14367 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/Makefile 2018-01-10 02:50:49.000000000 +0000
14370 +# Makefile for the Linux vserver routines.
14374 +obj-y += vserver.o
14376 +vserver-y := switch.o context.o space.o sched.o network.o inode.o \
14377 + limit.o cvirt.o cacct.o signal.o helper.o init.o \
14380 +vserver-$(CONFIG_INET) += inet.o
14381 +vserver-$(CONFIG_PROC_FS) += proc.o
14382 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
14383 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
14384 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
14385 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
14387 diff -NurpP --minimal linux-4.9.76/kernel/vserver/cacct.c linux-4.9.76-vs2.3.9.5/kernel/vserver/cacct.c
14388 --- linux-4.9.76/kernel/vserver/cacct.c 1970-01-01 00:00:00.000000000 +0000
14389 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/cacct.c 2018-01-10 02:50:49.000000000 +0000
14392 + * linux/kernel/vserver/cacct.c
14394 + * Virtual Server: Context Accounting
14396 + * Copyright (C) 2006-2007 Herbert P?tzl
14398 + * V0.01 added accounting stats
14402 +#include <linux/types.h>
14403 +#include <linux/vs_context.h>
14404 +#include <linux/vserver/cacct_cmd.h>
14405 +#include <linux/vserver/cacct_int.h>
14407 +#include <asm/errno.h>
14408 +#include <asm/uaccess.h>
14411 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
14413 + struct vcmd_sock_stat_v0 vc_data;
14416 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
14419 + field = vc_data.field;
14420 + if ((field < 0) || (field >= VXA_SOCK_SIZE))
14423 + for (j = 0; j < 3; j++) {
14424 + vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
14425 + vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
14428 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
14433 diff -NurpP --minimal linux-4.9.76/kernel/vserver/cacct_init.h linux-4.9.76-vs2.3.9.5/kernel/vserver/cacct_init.h
14434 --- linux-4.9.76/kernel/vserver/cacct_init.h 1970-01-01 00:00:00.000000000 +0000
14435 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/cacct_init.h 2018-01-10 02:50:49.000000000 +0000
14439 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
14444 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
14445 + for (j = 0; j < 3; j++) {
14446 + atomic_long_set(&cacct->sock[i][j].count, 0);
14447 + atomic_long_set(&cacct->sock[i][j].total, 0);
14450 + for (i = 0; i < 8; i++)
14451 + atomic_set(&cacct->slab[i], 0);
14452 + for (i = 0; i < 5; i++)
14453 + for (j = 0; j < 4; j++)
14454 + atomic_set(&cacct->page[i][j], 0);
14457 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
14462 diff -NurpP --minimal linux-4.9.76/kernel/vserver/cacct_proc.h linux-4.9.76-vs2.3.9.5/kernel/vserver/cacct_proc.h
14463 --- linux-4.9.76/kernel/vserver/cacct_proc.h 1970-01-01 00:00:00.000000000 +0000
14464 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/cacct_proc.h 2018-01-10 02:50:49.000000000 +0000
14466 +#ifndef _VX_CACCT_PROC_H
14467 +#define _VX_CACCT_PROC_H
14469 +#include <linux/vserver/cacct_int.h>
14472 +#define VX_SOCKA_TOP \
14473 + "Type\t recv #/bytes\t\t send #/bytes\t\t fail #/bytes\n"
14475 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
14477 + int i, j, length = 0;
14478 + static char *type[VXA_SOCK_SIZE] = {
14479 + "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
14482 + length += sprintf(buffer + length, VX_SOCKA_TOP);
14483 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
14484 + length += sprintf(buffer + length, "%s:", type[i]);
14485 + for (j = 0; j < 3; j++) {
14486 + length += sprintf(buffer + length,
14487 + "\t%10lu/%-10lu",
14488 + vx_sock_count(cacct, i, j),
14489 + vx_sock_total(cacct, i, j));
14491 + buffer[length++] = '\n';
14494 + length += sprintf(buffer + length, "\n");
14495 + length += sprintf(buffer + length,
14496 + "slab:\t %8u %8u %8u %8u\n",
14497 + atomic_read(&cacct->slab[1]),
14498 + atomic_read(&cacct->slab[4]),
14499 + atomic_read(&cacct->slab[0]),
14500 + atomic_read(&cacct->slab[2]));
14502 + length += sprintf(buffer + length, "\n");
14503 + for (i = 0; i < 5; i++) {
14504 + length += sprintf(buffer + length,
14505 + "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
14506 + atomic_read(&cacct->page[i][0]),
14507 + atomic_read(&cacct->page[i][1]),
14508 + atomic_read(&cacct->page[i][2]),
14509 + atomic_read(&cacct->page[i][3]),
14510 + atomic_read(&cacct->page[i][4]),
14511 + atomic_read(&cacct->page[i][5]),
14512 + atomic_read(&cacct->page[i][6]),
14513 + atomic_read(&cacct->page[i][7]));
14518 +#endif /* _VX_CACCT_PROC_H */
14519 diff -NurpP --minimal linux-4.9.76/kernel/vserver/context.c linux-4.9.76-vs2.3.9.5/kernel/vserver/context.c
14520 --- linux-4.9.76/kernel/vserver/context.c 1970-01-01 00:00:00.000000000 +0000
14521 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/context.c 2018-01-10 02:50:49.000000000 +0000
14524 + * linux/kernel/vserver/context.c
14526 + * Virtual Server: Context Support
14528 + * Copyright (C) 2003-2011 Herbert P?tzl
14530 + * V0.01 context helper
14531 + * V0.02 vx_ctx_kill syscall command
14532 + * V0.03 replaced context_info calls
14533 + * V0.04 redesign of struct (de)alloc
14534 + * V0.05 rlimit basic implementation
14535 + * V0.06 task_xid and info commands
14536 + * V0.07 context flags and caps
14537 + * V0.08 switch to RCU based hash
14538 + * V0.09 revert to non RCU for now
14539 + * V0.10 and back to working RCU hash
14540 + * V0.11 and back to locking again
14541 + * V0.12 referenced context store
14542 + * V0.13 separate per cpu data
14543 + * V0.14 changed vcmds to vxi arg
14544 + * V0.15 added context stat
14545 + * V0.16 have __create claim() the vxi
14546 + * V0.17 removed older and legacy stuff
14547 + * V0.18 added user credentials
14548 + * V0.19 added warn mask
14552 +#include <linux/slab.h>
14553 +#include <linux/types.h>
14554 +#include <linux/security.h>
14555 +#include <linux/pid_namespace.h>
14556 +#include <linux/capability.h>
14558 +#include <linux/vserver/context.h>
14559 +#include <linux/vserver/network.h>
14560 +#include <linux/vserver/debug.h>
14561 +#include <linux/vserver/limit.h>
14562 +#include <linux/vserver/limit_int.h>
14563 +#include <linux/vserver/space.h>
14564 +#include <linux/init_task.h>
14565 +#include <linux/fs_struct.h>
14566 +#include <linux/cred.h>
14568 +#include <linux/vs_context.h>
14569 +#include <linux/vs_limit.h>
14570 +#include <linux/vs_pid.h>
14571 +#include <linux/vserver/context_cmd.h>
14573 +#include "cvirt_init.h"
14574 +#include "cacct_init.h"
14575 +#include "limit_init.h"
14576 +#include "sched_init.h"
14579 +atomic_t vx_global_ctotal = ATOMIC_INIT(0);
14580 +atomic_t vx_global_cactive = ATOMIC_INIT(0);
14583 +/* now inactive context structures */
14585 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
14587 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
14590 +/* __alloc_vx_info()
14592 + * allocate an initialized vx_info struct
14593 + * doesn't make it visible (hash) */
14595 +static struct vx_info *__alloc_vx_info(vxid_t xid)
14597 + struct vx_info *new = NULL;
14600 + vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
14602 + /* would this benefit from a slab cache? */
14603 + new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
14607 + memset(new, 0, sizeof(struct vx_info));
14609 + new->ptr_pc = alloc_percpu(struct _vx_info_pc);
14610 + if (!new->ptr_pc)
14613 + new->vx_id = xid;
14614 + INIT_HLIST_NODE(&new->vx_hlist);
14615 + atomic_set(&new->vx_usecnt, 0);
14616 + atomic_set(&new->vx_tasks, 0);
14617 + new->vx_parent = NULL;
14618 + new->vx_state = 0;
14619 + init_waitqueue_head(&new->vx_wait);
14621 + /* prepare reaper */
14622 + get_task_struct(init_pid_ns.child_reaper);
14623 + new->vx_reaper = init_pid_ns.child_reaper;
14624 + new->vx_badness_bias = 0;
14626 + /* rest of init goes here */
14627 + vx_info_init_limit(&new->limit);
14628 + vx_info_init_sched(&new->sched);
14629 + vx_info_init_cvirt(&new->cvirt);
14630 + vx_info_init_cacct(&new->cacct);
14632 + /* per cpu data structures */
14633 + for_each_possible_cpu(cpu) {
14634 + vx_info_init_sched_pc(
14635 + &vx_per_cpu(new, sched_pc, cpu), cpu);
14636 + vx_info_init_cvirt_pc(
14637 + &vx_per_cpu(new, cvirt_pc, cpu), cpu);
14640 + new->vx_flags = VXF_INIT_SET;
14641 + new->vx_bcaps = CAP_FULL_SET; // maybe ~CAP_SETPCAP
14642 + new->vx_ccaps = 0;
14643 + new->vx_umask = 0;
14644 + new->vx_wmask = 0;
14646 + new->reboot_cmd = 0;
14647 + new->exit_code = 0;
14649 + // preconfig spaces
14650 + for (index = 0; index < VX_SPACES; index++) {
14651 + struct _vx_space *space = &new->space[index];
14654 + spin_lock(&init_fs.lock);
14656 + spin_unlock(&init_fs.lock);
14657 + space->vx_fs = &init_fs;
14659 + /* FIXME: do we want defaults? */
14660 + // space->vx_real_cred = 0;
14661 + // space->vx_cred = 0;
14665 + vxdprintk(VXD_CBIT(xid, 0),
14666 + "alloc_vx_info(%d) = %p", xid, new);
14667 + vxh_alloc_vx_info(new);
14668 + atomic_inc(&vx_global_ctotal);
14677 +/* __dealloc_vx_info()
14679 + * final disposal of vx_info */
14681 +static void __dealloc_vx_info(struct vx_info *vxi)
14683 +#ifdef CONFIG_VSERVER_WARN
14684 + struct vx_info_save vxis;
14687 + vxdprintk(VXD_CBIT(xid, 0),
14688 + "dealloc_vx_info(%p)", vxi);
14689 + vxh_dealloc_vx_info(vxi);
14691 +#ifdef CONFIG_VSERVER_WARN
14692 + enter_vx_info(vxi, &vxis);
14693 + vx_info_exit_limit(&vxi->limit);
14694 + vx_info_exit_sched(&vxi->sched);
14695 + vx_info_exit_cvirt(&vxi->cvirt);
14696 + vx_info_exit_cacct(&vxi->cacct);
14698 + for_each_possible_cpu(cpu) {
14699 + vx_info_exit_sched_pc(
14700 + &vx_per_cpu(vxi, sched_pc, cpu), cpu);
14701 + vx_info_exit_cvirt_pc(
14702 + &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
14704 + leave_vx_info(&vxis);
14708 + vxi->vx_state |= VXS_RELEASED;
14711 + free_percpu(vxi->ptr_pc);
14714 + atomic_dec(&vx_global_ctotal);
14717 +static void __shutdown_vx_info(struct vx_info *vxi)
14719 + struct nsproxy *nsproxy;
14720 + struct fs_struct *fs;
14721 + struct cred *cred;
14726 + vxi->vx_state |= VXS_SHUTDOWN;
14727 + vs_state_change(vxi, VSC_SHUTDOWN);
14729 + for (index = 0; index < VX_SPACES; index++) {
14730 + struct _vx_space *space = &vxi->space[index];
14732 + nsproxy = xchg(&space->vx_nsproxy, NULL);
14734 + put_nsproxy(nsproxy);
14736 + fs = xchg(&space->vx_fs, NULL);
14737 + spin_lock(&fs->lock);
14738 + kill = !--fs->users;
14739 + spin_unlock(&fs->lock);
14741 + free_fs_struct(fs);
14743 + cred = (struct cred *)xchg(&space->vx_cred, NULL);
14745 + abort_creds(cred);
14749 +/* exported stuff */
14751 +void free_vx_info(struct vx_info *vxi)
14753 + unsigned long flags;
14756 + /* check for reference counts first */
14757 + BUG_ON(atomic_read(&vxi->vx_usecnt));
14758 + BUG_ON(atomic_read(&vxi->vx_tasks));
14760 + /* context must not be hashed */
14761 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
14763 + /* context shutdown is mandatory */
14764 + BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
14766 + /* spaces check */
14767 + for (index = 0; index < VX_SPACES; index++) {
14768 + struct _vx_space *space = &vxi->space[index];
14770 + BUG_ON(space->vx_nsproxy);
14771 + BUG_ON(space->vx_fs);
14772 + // BUG_ON(space->vx_real_cred);
14773 + // BUG_ON(space->vx_cred);
14776 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
14777 + hlist_del(&vxi->vx_hlist);
14778 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
14780 + __dealloc_vx_info(vxi);
14784 +/* hash table for vx_info hash */
14786 +#define VX_HASH_SIZE 13
14788 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
14789 + { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
14791 +static DEFINE_SPINLOCK(vx_info_hash_lock);
14794 +static inline unsigned int __hashval(vxid_t xid)
14796 + return (xid % VX_HASH_SIZE);
14801 +/* __hash_vx_info()
14803 + * add the vxi to the global hash table
14804 + * requires the hash_lock to be held */
14806 +static inline void __hash_vx_info(struct vx_info *vxi)
14808 + struct hlist_head *head;
14810 + vxd_assert_lock(&vx_info_hash_lock);
14811 + vxdprintk(VXD_CBIT(xid, 4),
14812 + "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
14813 + vxh_hash_vx_info(vxi);
14815 + /* context must not be hashed */
14816 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
14818 + vxi->vx_state |= VXS_HASHED;
14819 + head = &vx_info_hash[__hashval(vxi->vx_id)];
14820 + hlist_add_head(&vxi->vx_hlist, head);
14821 + atomic_inc(&vx_global_cactive);
14824 +/* __unhash_vx_info()
14826 + * remove the vxi from the global hash table
14827 + * requires the hash_lock to be held */
14829 +static inline void __unhash_vx_info(struct vx_info *vxi)
14831 + unsigned long flags;
14833 + vxd_assert_lock(&vx_info_hash_lock);
14834 + vxdprintk(VXD_CBIT(xid, 4),
14835 + "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
14836 + atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
14837 + vxh_unhash_vx_info(vxi);
14839 + /* context must be hashed */
14840 + BUG_ON(!vx_info_state(vxi, VXS_HASHED));
14841 + /* but without tasks */
14842 + BUG_ON(atomic_read(&vxi->vx_tasks));
14844 + vxi->vx_state &= ~VXS_HASHED;
14845 + hlist_del_init(&vxi->vx_hlist);
14846 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
14847 + hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
14848 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
14849 + atomic_dec(&vx_global_cactive);
14853 +/* __lookup_vx_info()
14855 + * requires the hash_lock to be held
14856 + * doesn't increment the vx_refcnt */
14858 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
14860 + struct hlist_head *head = &vx_info_hash[__hashval(xid)];
14861 + struct hlist_node *pos;
14862 + struct vx_info *vxi;
14864 + vxd_assert_lock(&vx_info_hash_lock);
14865 + hlist_for_each(pos, head) {
14866 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
14868 + if (vxi->vx_id == xid)
14873 + vxdprintk(VXD_CBIT(xid, 0),
14874 + "__lookup_vx_info(#%u): %p[#%u]",
14875 + xid, vxi, vxi ? vxi->vx_id : 0);
14876 + vxh_lookup_vx_info(vxi, xid);
14881 +/* __create_vx_info()
14883 + * create the requested context
14884 + * get(), claim() and hash it */
14886 +static struct vx_info *__create_vx_info(int id)
14888 + struct vx_info *new, *vxi = NULL;
14890 + vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
14892 + if (!(new = __alloc_vx_info(id)))
14893 + return ERR_PTR(-ENOMEM);
14895 + /* required to make dynamic xids unique */
14896 + spin_lock(&vx_info_hash_lock);
14898 + /* static context requested */
14899 + if ((vxi = __lookup_vx_info(id))) {
14900 + vxdprintk(VXD_CBIT(xid, 0),
14901 + "create_vx_info(%d) = %p (already there)", id, vxi);
14902 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
14903 + vxi = ERR_PTR(-EBUSY);
14905 + vxi = ERR_PTR(-EEXIST);
14908 + /* new context */
14909 + vxdprintk(VXD_CBIT(xid, 0),
14910 + "create_vx_info(%d) = %p (new)", id, new);
14911 + claim_vx_info(new, NULL);
14912 + __hash_vx_info(get_vx_info(new));
14913 + vxi = new, new = NULL;
14916 + spin_unlock(&vx_info_hash_lock);
14917 + vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
14919 + __dealloc_vx_info(new);
14924 +/* exported stuff */
14927 +void unhash_vx_info(struct vx_info *vxi)
14929 + spin_lock(&vx_info_hash_lock);
14930 + __unhash_vx_info(vxi);
14931 + spin_unlock(&vx_info_hash_lock);
14932 + __shutdown_vx_info(vxi);
14933 + __wakeup_vx_info(vxi);
14937 +/* lookup_vx_info()
14939 + * search for a vx_info and get() it
14940 + * negative id means current */
14942 +struct vx_info *lookup_vx_info(int id)
14944 + struct vx_info *vxi = NULL;
14947 + vxi = get_vx_info(current_vx_info());
14948 + } else if (id > 1) {
14949 + spin_lock(&vx_info_hash_lock);
14950 + vxi = get_vx_info(__lookup_vx_info(id));
14951 + spin_unlock(&vx_info_hash_lock);
14956 +/* xid_is_hashed()
14958 + * verify that xid is still hashed */
14960 +int xid_is_hashed(vxid_t xid)
14964 + spin_lock(&vx_info_hash_lock);
14965 + hashed = (__lookup_vx_info(xid) != NULL);
14966 + spin_unlock(&vx_info_hash_lock);
14970 +#ifdef CONFIG_PROC_FS
14974 + * get a subset of hashed xids for proc
14975 + * assumes size is at least one */
14977 +int get_xid_list(int index, unsigned int *xids, int size)
14979 + int hindex, nr_xids = 0;
14981 + /* only show current and children */
14982 + if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
14985 + xids[nr_xids] = vx_current_xid();
14989 + for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
14990 + struct hlist_head *head = &vx_info_hash[hindex];
14991 + struct hlist_node *pos;
14993 + spin_lock(&vx_info_hash_lock);
14994 + hlist_for_each(pos, head) {
14995 + struct vx_info *vxi;
15000 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15001 + xids[nr_xids] = vxi->vx_id;
15002 + if (++nr_xids >= size) {
15003 + spin_unlock(&vx_info_hash_lock);
15007 + /* keep the lock time short */
15008 + spin_unlock(&vx_info_hash_lock);
15015 +#ifdef CONFIG_VSERVER_DEBUG
15017 +void dump_vx_info_inactive(int level)
15019 + struct hlist_node *entry, *next;
15021 + hlist_for_each_safe(entry, next, &vx_info_inactive) {
15022 + struct vx_info *vxi =
15023 + list_entry(entry, struct vx_info, vx_hlist);
15025 + dump_vx_info(vxi, level);
15032 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
15034 + struct user_struct *new_user, *old_user;
15039 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
15042 + new_user = alloc_uid(vxi->vx_id, p->uid);
15046 + old_user = p->user;
15047 + if (new_user != old_user) {
15048 + atomic_inc(&new_user->processes);
15049 + atomic_dec(&old_user->processes);
15050 + p->user = new_user;
15052 + free_uid(old_user);
15058 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
15060 + // p->cap_effective &= vxi->vx_cap_bset;
15061 + p->cap_effective =
15062 + cap_intersect(p->cap_effective, vxi->cap_bset);
15063 + // p->cap_inheritable &= vxi->vx_cap_bset;
15064 + p->cap_inheritable =
15065 + cap_intersect(p->cap_inheritable, vxi->cap_bset);
15066 + // p->cap_permitted &= vxi->vx_cap_bset;
15067 + p->cap_permitted =
15068 + cap_intersect(p->cap_permitted, vxi->cap_bset);
15073 +#include <linux/file.h>
15074 +#include <linux/fdtable.h>
15076 +static int vx_openfd_task(struct task_struct *tsk)
15078 + struct files_struct *files = tsk->files;
15079 + struct fdtable *fdt;
15080 + const unsigned long *bptr;
15081 + int count, total;
15083 + /* no rcu_read_lock() because of spin_lock() */
15084 + spin_lock(&files->file_lock);
15085 + fdt = files_fdtable(files);
15086 + bptr = fdt->open_fds;
15087 + count = fdt->max_fds / (sizeof(unsigned long) * 8);
15088 + for (total = 0; count > 0; count--) {
15090 + total += hweight_long(*bptr);
15093 + spin_unlock(&files->file_lock);
15098 +/* for *space compatibility */
15100 +asmlinkage long sys_unshare(unsigned long);
15103 + * migrate task to new context
15104 + * gets vxi, puts old_vxi on change
15105 + * optionally unshares namespaces (hack)
15108 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
15110 + struct vx_info *old_vxi;
15116 + vxdprintk(VXD_CBIT(xid, 5),
15117 + "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
15118 + vxi->vx_id, atomic_read(&vxi->vx_usecnt));
15120 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
15121 + !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15124 + if (vx_info_state(vxi, VXS_SHUTDOWN))
15127 + old_vxi = task_get_vx_info(p);
15128 + if (old_vxi == vxi)
15131 +// if (!(ret = vx_migrate_user(p, vxi))) {
15136 + openfd = vx_openfd_task(p);
15139 + atomic_dec(&old_vxi->cvirt.nr_threads);
15140 + atomic_dec(&old_vxi->cvirt.nr_running);
15141 + __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
15142 + /* FIXME: what about the struct files here? */
15143 + __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
15144 + /* account for the executable */
15145 + __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
15147 + atomic_inc(&vxi->cvirt.nr_threads);
15148 + atomic_inc(&vxi->cvirt.nr_running);
15149 + __rlim_inc(&vxi->limit, RLIMIT_NPROC);
15150 + /* FIXME: what about the struct files here? */
15151 + __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
15152 + /* account for the executable */
15153 + __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
15156 + release_vx_info(old_vxi, p);
15157 + clr_vx_info(&p->vx_info);
15159 + claim_vx_info(vxi, p);
15160 + set_vx_info(&p->vx_info, vxi);
15161 + p->xid = vxi->vx_id;
15163 + vxdprintk(VXD_CBIT(xid, 5),
15164 + "moved task %p into vxi:%p[#%d]",
15165 + p, vxi, vxi->vx_id);
15167 + // vx_mask_cap_bset(vxi, p);
15170 + /* hack for *spaces to provide compatibility */
15172 + struct nsproxy *old_nsp, *new_nsp;
15174 + ret = unshare_nsproxy_namespaces(
15175 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
15176 + &new_nsp, NULL, NULL);
15180 + old_nsp = xchg(&p->nsproxy, new_nsp);
15181 + vx_set_space(vxi,
15182 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
15183 + put_nsproxy(old_nsp);
15187 + put_vx_info(old_vxi);
15191 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
15193 + struct task_struct *old_reaper;
15194 + struct vx_info *reaper_vxi;
15199 + vxdprintk(VXD_CBIT(xid, 6),
15200 + "vx_set_reaper(%p[#%d],%p[#%d,%d])",
15201 + vxi, vxi->vx_id, p, p->xid, p->pid);
15203 + old_reaper = vxi->vx_reaper;
15204 + if (old_reaper == p)
15207 + reaper_vxi = task_get_vx_info(p);
15208 + if (reaper_vxi && reaper_vxi != vxi) {
15210 + "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
15212 + p->comm, p->pid, p->xid, vx_current_xid());
15216 + /* set new child reaper */
15217 + get_task_struct(p);
15218 + vxi->vx_reaper = p;
15219 + put_task_struct(old_reaper);
15221 + put_vx_info(reaper_vxi);
15225 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
15230 + vxdprintk(VXD_CBIT(xid, 6),
15231 + "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
15232 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15234 + vxi->vx_flags &= ~VXF_STATE_INIT;
15235 + // vxi->vx_initpid = p->tgid;
15236 + vxi->vx_initpid = p->pid;
15240 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
15242 + vxdprintk(VXD_CBIT(xid, 6),
15243 + "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
15244 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15246 + vxi->exit_code = code;
15247 + vxi->vx_initpid = 0;
15251 +void vx_set_persistent(struct vx_info *vxi)
15253 + vxdprintk(VXD_CBIT(xid, 6),
15254 + "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
15256 + get_vx_info(vxi);
15257 + claim_vx_info(vxi, NULL);
15260 +void vx_clear_persistent(struct vx_info *vxi)
15262 + vxdprintk(VXD_CBIT(xid, 6),
15263 + "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
15265 + release_vx_info(vxi, NULL);
15266 + put_vx_info(vxi);
15269 +void vx_update_persistent(struct vx_info *vxi)
15271 + if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
15272 + vx_set_persistent(vxi);
15274 + vx_clear_persistent(vxi);
15278 +/* task must be current or locked */
15280 +void exit_vx_info(struct task_struct *p, int code)
15282 + struct vx_info *vxi = p->vx_info;
15285 + atomic_dec(&vxi->cvirt.nr_threads);
15288 + vxi->exit_code = code;
15289 + release_vx_info(vxi, p);
15293 +void exit_vx_info_early(struct task_struct *p, int code)
15295 + struct vx_info *vxi = p->vx_info;
15298 + if (vxi->vx_initpid == p->pid)
15299 + vx_exit_init(vxi, p, code);
15300 + if (vxi->vx_reaper == p)
15301 + vx_set_reaper(vxi, init_pid_ns.child_reaper);
15306 +/* vserver syscall commands below here */
15308 +/* taks xid and vx_info functions */
15310 +#include <asm/uaccess.h>
15313 +int vc_task_xid(uint32_t id)
15318 + struct task_struct *tsk;
15321 + tsk = find_task_by_real_pid(id);
15322 + xid = (tsk) ? tsk->xid : -ESRCH;
15323 + rcu_read_unlock();
15325 + xid = vx_current_xid();
15330 +int vc_vx_info(struct vx_info *vxi, void __user *data)
15332 + struct vcmd_vx_info_v0 vc_data;
15334 + vc_data.xid = vxi->vx_id;
15335 + vc_data.initpid = vxi->vx_initpid;
15337 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15343 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
15345 + struct vcmd_ctx_stat_v0 vc_data;
15347 + vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
15348 + vc_data.tasks = atomic_read(&vxi->vx_tasks);
15350 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15356 +/* context functions */
15358 +int vc_ctx_create(uint32_t xid, void __user *data)
15360 + struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
15361 + struct vx_info *new_vxi;
15364 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15367 + if ((xid > MAX_S_CONTEXT) || (xid < 2))
15370 + new_vxi = __create_vx_info(xid);
15371 + if (IS_ERR(new_vxi))
15372 + return PTR_ERR(new_vxi);
15374 + /* initial flags */
15375 + new_vxi->vx_flags = vc_data.flagword;
15378 + if (vs_state_change(new_vxi, VSC_STARTUP))
15381 + ret = vx_migrate_task(current, new_vxi, (!data));
15385 + /* return context id on success */
15386 + ret = new_vxi->vx_id;
15388 + /* get a reference for persistent contexts */
15389 + if ((vc_data.flagword & VXF_PERSISTENT))
15390 + vx_set_persistent(new_vxi);
15392 + release_vx_info(new_vxi, NULL);
15393 + put_vx_info(new_vxi);
15398 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
15400 + struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
15403 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15406 + ret = vx_migrate_task(current, vxi, 0);
15409 + if (vc_data.flagword & VXM_SET_INIT)
15410 + ret = vx_set_init(vxi, current);
15413 + if (vc_data.flagword & VXM_SET_REAPER)
15414 + ret = vx_set_reaper(vxi, current);
15419 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
15421 + struct vcmd_ctx_flags_v0 vc_data;
15423 + vc_data.flagword = vxi->vx_flags;
15425 + /* special STATE flag handling */
15426 + vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
15428 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15433 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
15435 + struct vcmd_ctx_flags_v0 vc_data;
15436 + uint64_t mask, trigger;
15438 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15441 + /* special STATE flag handling */
15442 + mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
15443 + trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
15445 + if (vxi == current_vx_info()) {
15446 + /* if (trigger & VXF_STATE_SETUP)
15447 + vx_mask_cap_bset(vxi, current); */
15448 + if (trigger & VXF_STATE_INIT) {
15451 + ret = vx_set_init(vxi, current);
15454 + ret = vx_set_reaper(vxi, current);
15460 + vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
15461 + vc_data.flagword, mask);
15462 + if (trigger & VXF_PERSISTENT)
15463 + vx_update_persistent(vxi);
15469 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
15471 + uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
15473 + // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
15477 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
15479 + kernel_cap_t c = __cap_empty_set;
15481 + c.cap[0] = v & 0xFFFFFFFF;
15482 + c.cap[1] = (v >> 32) & 0xFFFFFFFF;
15484 + // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
15489 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
15492 + *bcaps = caps_from_cap_t(vxi->vx_bcaps);
15494 + *ccaps = vxi->vx_ccaps;
15499 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
15501 + struct vcmd_ctx_caps_v1 vc_data;
15504 + ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
15507 + vc_data.cmask = ~0ULL;
15509 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15514 +static int do_set_caps(struct vx_info *vxi,
15515 + uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
15517 + uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
15520 + printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
15521 + bcaps, bmask, ccaps, cmask);
15523 + vxi->vx_bcaps = cap_t_from_caps(
15524 + vs_mask_flags(bcold, bcaps, bmask));
15525 + vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
15530 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
15532 + struct vcmd_ctx_caps_v1 vc_data;
15534 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15537 + return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
15540 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
15542 + struct vcmd_bcaps vc_data;
15545 + ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
15548 + vc_data.bmask = ~0ULL;
15550 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15555 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
15557 + struct vcmd_bcaps vc_data;
15559 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15562 + return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
15566 +int vc_get_umask(struct vx_info *vxi, void __user *data)
15568 + struct vcmd_umask vc_data;
15570 + vc_data.umask = vxi->vx_umask;
15571 + vc_data.mask = ~0ULL;
15573 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15578 +int vc_set_umask(struct vx_info *vxi, void __user *data)
15580 + struct vcmd_umask vc_data;
15582 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15585 + vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
15586 + vc_data.umask, vc_data.mask);
15591 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
15593 + struct vcmd_wmask vc_data;
15595 + vc_data.wmask = vxi->vx_wmask;
15596 + vc_data.mask = ~0ULL;
15598 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15603 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
15605 + struct vcmd_wmask vc_data;
15607 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15610 + vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
15611 + vc_data.wmask, vc_data.mask);
15616 +int vc_get_badness(struct vx_info *vxi, void __user *data)
15618 + struct vcmd_badness_v0 vc_data;
15620 + vc_data.bias = vxi->vx_badness_bias;
15622 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15627 +int vc_set_badness(struct vx_info *vxi, void __user *data)
15629 + struct vcmd_badness_v0 vc_data;
15631 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15634 + vxi->vx_badness_bias = vc_data.bias;
15638 +#include <linux/module.h>
15640 +EXPORT_SYMBOL_GPL(free_vx_info);
15642 diff -NurpP --minimal linux-4.9.76/kernel/vserver/cvirt.c linux-4.9.76-vs2.3.9.5/kernel/vserver/cvirt.c
15643 --- linux-4.9.76/kernel/vserver/cvirt.c 1970-01-01 00:00:00.000000000 +0000
15644 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/cvirt.c 2018-01-11 08:36:23.000000000 +0000
15647 + * linux/kernel/vserver/cvirt.c
15649 + * Virtual Server: Context Virtualization
15651 + * Copyright (C) 2004-2007 Herbert P?tzl
15653 + * V0.01 broken out from limit.c
15654 + * V0.02 added utsname stuff
15655 + * V0.03 changed vcmds to vxi arg
15659 +#include <linux/types.h>
15660 +#include <linux/utsname.h>
15661 +#include <linux/vs_cvirt.h>
15662 +#include <linux/vserver/switch.h>
15663 +#include <linux/vserver/cvirt_cmd.h>
15665 +#include <asm/uaccess.h>
15668 +void vx_vsi_boottime(struct timespec *boottime)
15670 + struct vx_info *vxi = current_vx_info();
15672 + set_normalized_timespec(boottime,
15673 + boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
15674 + boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
15678 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
15680 + struct vx_info *vxi = current_vx_info();
15682 + set_normalized_timespec(uptime,
15683 + uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
15684 + uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
15687 + set_normalized_timespec(idle,
15688 + idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
15689 + idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
15693 +uint64_t vx_idle_jiffies(void)
15695 + return init_task.utime + init_task.stime;
15700 +static inline uint32_t __update_loadavg(uint32_t load,
15701 + int wsize, int delta, int n)
15703 + unsigned long long calc, prev;
15705 + /* just set it to n */
15706 + if (unlikely(delta >= wsize))
15707 + return (n << FSHIFT);
15709 + calc = delta * n;
15711 + prev = (wsize - delta);
15714 + do_div(calc, wsize);
15719 +void vx_update_load(struct vx_info *vxi)
15721 + uint32_t now, last, delta;
15722 + unsigned int nr_running, nr_uninterruptible;
15723 + unsigned int total;
15724 + unsigned long flags;
15726 + spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
15729 + last = vxi->cvirt.load_last;
15730 + delta = now - last;
15732 + if (delta < 5*HZ)
15735 + nr_running = atomic_read(&vxi->cvirt.nr_running);
15736 + nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
15737 + total = nr_running + nr_uninterruptible;
15739 + vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
15740 + 60*HZ, delta, total);
15741 + vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
15742 + 5*60*HZ, delta, total);
15743 + vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
15744 + 15*60*HZ, delta, total);
15746 + vxi->cvirt.load_last = now;
15748 + atomic_inc(&vxi->cvirt.load_updates);
15749 + spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
15754 + * Commands to do_syslog:
15756 + * 0 -- Close the log. Currently a NOP.
15757 + * 1 -- Open the log. Currently a NOP.
15758 + * 2 -- Read from the log.
15759 + * 3 -- Read all messages remaining in the ring buffer.
15760 + * 4 -- Read and clear all messages remaining in the ring buffer
15761 + * 5 -- Clear ring buffer.
15762 + * 6 -- Disable printk's to console
15763 + * 7 -- Enable printk's to console
15764 + * 8 -- Set level of messages printed to console
15765 + * 9 -- Return number of unread characters in the log buffer
15766 + * 10 -- Return size of the log buffer
15768 +int vx_do_syslog(int type, char __user *buf, int len)
15771 + int do_clear = 0;
15772 + struct vx_info *vxi = current_vx_info();
15773 + struct _vx_syslog *log;
15777 + log = &vxi->cvirt.syslog;
15780 + case 0: /* Close log */
15781 + case 1: /* Open log */
15783 + case 2: /* Read from log */
15784 + error = wait_event_interruptible(log->log_wait,
15785 + (log->log_start - log->log_end));
15788 + spin_lock_irq(&log->logbuf_lock);
15789 + spin_unlock_irq(&log->logbuf_lock);
15791 + case 4: /* Read/clear last kernel messages */
15793 + /* fall through */
15794 + case 3: /* Read last kernel messages */
15797 + case 5: /* Clear ring buffer */
15800 + case 6: /* Disable logging to console */
15801 + case 7: /* Enable logging to console */
15802 + case 8: /* Set level of messages printed to console */
15805 + case 9: /* Number of chars in the log buffer */
15807 + case 10: /* Size of the log buffer */
15817 +/* virtual host info names */
15819 +static char *vx_vhi_name(struct vx_info *vxi, int id)
15821 + struct nsproxy *nsproxy;
15822 + struct uts_namespace *uts;
15824 + if (id == VHIN_CONTEXT)
15825 + return vxi->vx_name;
15827 + nsproxy = vxi->space[0].vx_nsproxy;
15831 + uts = nsproxy->uts_ns;
15836 + case VHIN_SYSNAME:
15837 + return uts->name.sysname;
15838 + case VHIN_NODENAME:
15839 + return uts->name.nodename;
15840 + case VHIN_RELEASE:
15841 + return uts->name.release;
15842 + case VHIN_VERSION:
15843 + return uts->name.version;
15844 + case VHIN_MACHINE:
15845 + return uts->name.machine;
15846 + case VHIN_DOMAINNAME:
15847 + return uts->name.domainname;
15854 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
15856 + struct vcmd_vhi_name_v0 vc_data;
15859 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15862 + name = vx_vhi_name(vxi, vc_data.field);
15866 + memcpy(name, vc_data.name, 65);
15870 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
15872 + struct vcmd_vhi_name_v0 vc_data;
15875 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15878 + name = vx_vhi_name(vxi, vc_data.field);
15882 + memcpy(vc_data.name, name, 65);
15883 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15889 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
15891 + struct vcmd_virt_stat_v0 vc_data;
15892 + struct _vx_cvirt *cvirt = &vxi->cvirt;
15893 + struct timespec64 uptime;
15895 + ktime_get_ts(&uptime);
15896 + set_normalized_timespec(&uptime,
15897 + uptime.tv_sec - cvirt->bias_uptime.tv_sec,
15898 + uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
15900 + vc_data.offset = timespec64_to_ns(&cvirt->bias_ts);
15901 + vc_data.uptime = timespec64_to_ns(&uptime);
15902 + vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
15903 + vc_data.nr_running = atomic_read(&cvirt->nr_running);
15904 + vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
15905 + vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
15906 + vc_data.nr_forks = atomic_read(&cvirt->total_forks);
15907 + vc_data.load[0] = cvirt->load[0];
15908 + vc_data.load[1] = cvirt->load[1];
15909 + vc_data.load[2] = cvirt->load[2];
15911 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15917 +#ifdef CONFIG_VSERVER_VTIME
15919 +/* virtualized time base */
15921 +void vx_adjust_timespec(struct timespec *ts)
15923 + struct vx_info *vxi;
15925 + if (!vx_flags(VXF_VIRT_TIME, 0))
15928 + vxi = current_vx_info();
15929 + ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
15930 + ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
15932 + if (ts->tv_nsec >= NSEC_PER_SEC) {
15934 + ts->tv_nsec -= NSEC_PER_SEC;
15935 + } else if (ts->tv_nsec < 0) {
15937 + ts->tv_nsec += NSEC_PER_SEC;
15941 +void vx_adjust_timespec64(struct timespec64 *ts)
15943 + struct vx_info *vxi;
15945 + if (!vx_flags(VXF_VIRT_TIME, 0))
15948 + vxi = current_vx_info();
15949 + ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
15950 + ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
15952 + if (ts->tv_nsec >= NSEC_PER_SEC) {
15954 + ts->tv_nsec -= NSEC_PER_SEC;
15955 + } else if (ts->tv_nsec < 0) {
15957 + ts->tv_nsec += NSEC_PER_SEC;
15961 +int vx_settimeofday(const struct timespec *ts)
15963 + struct timespec ats, delta;
15964 + struct vx_info *vxi;
15966 + if (!vx_flags(VXF_VIRT_TIME, 0))
15967 + return do_settimeofday(ts);
15969 + getnstimeofday(&ats);
15970 + delta = timespec_sub(*ts, ats);
15972 + vxi = current_vx_info();
15973 + vxi->cvirt.bias_ts = timespec64_add(vxi->cvirt.bias_ts,
15974 + timespec_to_timespec64(delta));
15978 +int vx_settimeofday64(const struct timespec64 *ts)
15980 + struct timespec64 ats, delta;
15981 + struct vx_info *vxi;
15983 + if (!vx_flags(VXF_VIRT_TIME, 0))
15984 + return do_settimeofday64(ts);
15986 + getnstimeofday64(&ats);
15987 + delta = timespec64_sub(*ts, ats);
15989 + vxi = current_vx_info();
15990 + vxi->cvirt.bias_ts = timespec64_add(vxi->cvirt.bias_ts, delta);
15996 diff -NurpP --minimal linux-4.9.76/kernel/vserver/cvirt_init.h linux-4.9.76-vs2.3.9.5/kernel/vserver/cvirt_init.h
15997 --- linux-4.9.76/kernel/vserver/cvirt_init.h 1970-01-01 00:00:00.000000000 +0000
15998 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/cvirt_init.h 2018-01-11 08:38:34.000000000 +0000
16002 +extern uint64_t vx_idle_jiffies(void);
16004 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16006 + uint64_t idle_jiffies = vx_idle_jiffies();
16007 + uint64_t nsuptime;
16009 + ktime_get_ts64(&cvirt->bias_uptime);
16010 + nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16011 + * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16012 + cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16013 + cvirt->bias_ts.tv_sec = 0;
16014 + cvirt->bias_ts.tv_nsec = 0;
16016 + jiffies_to_timespec64(idle_jiffies, &cvirt->bias_idle);
16017 + atomic_set(&cvirt->nr_threads, 0);
16018 + atomic_set(&cvirt->nr_running, 0);
16019 + atomic_set(&cvirt->nr_uninterruptible, 0);
16020 + atomic_set(&cvirt->nr_onhold, 0);
16022 + spin_lock_init(&cvirt->load_lock);
16023 + cvirt->load_last = jiffies;
16024 + atomic_set(&cvirt->load_updates, 0);
16025 + cvirt->load[0] = 0;
16026 + cvirt->load[1] = 0;
16027 + cvirt->load[2] = 0;
16028 + atomic_set(&cvirt->total_forks, 0);
16030 + spin_lock_init(&cvirt->syslog.logbuf_lock);
16031 + init_waitqueue_head(&cvirt->syslog.log_wait);
16032 + cvirt->syslog.log_start = 0;
16033 + cvirt->syslog.log_end = 0;
16034 + cvirt->syslog.con_start = 0;
16035 + cvirt->syslog.logged_chars = 0;
16039 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16041 + // cvirt_pc->cpustat = { 0 };
16044 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16046 +#ifdef CONFIG_VSERVER_WARN
16049 + vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16050 + "!!! cvirt: %p[nr_threads] = %d on exit.",
16052 + vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16053 + "!!! cvirt: %p[nr_running] = %d on exit.",
16055 + vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16056 + "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16058 + vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16059 + "!!! cvirt: %p[nr_onhold] = %d on exit.",
16065 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16070 diff -NurpP --minimal linux-4.9.76/kernel/vserver/cvirt_proc.h linux-4.9.76-vs2.3.9.5/kernel/vserver/cvirt_proc.h
16071 --- linux-4.9.76/kernel/vserver/cvirt_proc.h 1970-01-01 00:00:00.000000000 +0000
16072 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/cvirt_proc.h 2018-01-11 08:39:19.000000000 +0000
16074 +#ifndef _VX_CVIRT_PROC_H
16075 +#define _VX_CVIRT_PROC_H
16077 +#include <linux/nsproxy.h>
16078 +#include <linux/mnt_namespace.h>
16079 +#include <linux/ipc_namespace.h>
16080 +#include <linux/utsname.h>
16081 +#include <linux/ipc.h>
16083 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
16086 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
16088 + struct mnt_namespace *ns;
16089 + struct uts_namespace *uts;
16090 + struct ipc_namespace *ipc;
16096 + length += sprintf(buffer + length,
16097 + "NSProxy:\t%p [%p,%p,%p]\n",
16098 + nsproxy, nsproxy->mnt_ns,
16099 + nsproxy->uts_ns, nsproxy->ipc_ns);
16101 + ns = nsproxy->mnt_ns;
16105 + length += vx_info_mnt_namespace(ns, buffer + length);
16109 + uts = nsproxy->uts_ns;
16113 + length += sprintf(buffer + length,
16114 + "SysName:\t%.*s\n"
16115 + "NodeName:\t%.*s\n"
16116 + "Release:\t%.*s\n"
16117 + "Version:\t%.*s\n"
16118 + "Machine:\t%.*s\n"
16119 + "DomainName:\t%.*s\n",
16120 + __NEW_UTS_LEN, uts->name.sysname,
16121 + __NEW_UTS_LEN, uts->name.nodename,
16122 + __NEW_UTS_LEN, uts->name.release,
16123 + __NEW_UTS_LEN, uts->name.version,
16124 + __NEW_UTS_LEN, uts->name.machine,
16125 + __NEW_UTS_LEN, uts->name.domainname);
16128 + ipc = nsproxy->ipc_ns;
16132 + length += sprintf(buffer + length,
16133 + "SEMS:\t\t%d %d %d %d %d\n"
16134 + "MSG:\t\t%d %d %d\n"
16135 + "SHM:\t\t%lu %lu %d %ld\n",
16136 + ipc->sem_ctls[0], ipc->sem_ctls[1],
16137 + ipc->sem_ctls[2], ipc->sem_ctls[3],
16139 + ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
16140 + (unsigned long)ipc->shm_ctlmax,
16141 + (unsigned long)ipc->shm_ctlall,
16142 + ipc->shm_ctlmni, ipc->shm_tot);
16149 +#include <linux/sched.h>
16151 +#define LOAD_INT(x) ((x) >> FSHIFT)
16152 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
16155 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
16160 + length += sprintf(buffer + length,
16161 + "BiasUptime:\t%llu.%02lu\n",
16162 + (unsigned long long)cvirt->bias_uptime.tv_sec,
16163 + (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
16165 + a = cvirt->load[0] + (FIXED_1 / 200);
16166 + b = cvirt->load[1] + (FIXED_1 / 200);
16167 + c = cvirt->load[2] + (FIXED_1 / 200);
16168 + length += sprintf(buffer + length,
16169 + "nr_threads:\t%d\n"
16170 + "nr_running:\t%d\n"
16171 + "nr_unintr:\t%d\n"
16172 + "nr_onhold:\t%d\n"
16173 + "load_updates:\t%d\n"
16174 + "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
16175 + "total_forks:\t%d\n",
16176 + atomic_read(&cvirt->nr_threads),
16177 + atomic_read(&cvirt->nr_running),
16178 + atomic_read(&cvirt->nr_uninterruptible),
16179 + atomic_read(&cvirt->nr_onhold),
16180 + atomic_read(&cvirt->load_updates),
16181 + LOAD_INT(a), LOAD_FRAC(a),
16182 + LOAD_INT(b), LOAD_FRAC(b),
16183 + LOAD_INT(c), LOAD_FRAC(c),
16184 + atomic_read(&cvirt->total_forks));
16189 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
16190 + char *buffer, int cpu)
16196 +#endif /* _VX_CVIRT_PROC_H */
16197 diff -NurpP --minimal linux-4.9.76/kernel/vserver/debug.c linux-4.9.76-vs2.3.9.5/kernel/vserver/debug.c
16198 --- linux-4.9.76/kernel/vserver/debug.c 1970-01-01 00:00:00.000000000 +0000
16199 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/debug.c 2018-01-10 02:50:49.000000000 +0000
16202 + * kernel/vserver/debug.c
16204 + * Copyright (C) 2005-2007 Herbert P?tzl
16206 + * V0.01 vx_info dump support
16210 +#include <linux/module.h>
16212 +#include <linux/vserver/context.h>
16215 +void dump_vx_info(struct vx_info *vxi, int level)
16217 + printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
16218 + atomic_read(&vxi->vx_usecnt),
16219 + atomic_read(&vxi->vx_tasks),
16222 + __dump_vx_limit(&vxi->limit);
16223 + __dump_vx_sched(&vxi->sched);
16224 + __dump_vx_cvirt(&vxi->cvirt);
16225 + __dump_vx_cacct(&vxi->cacct);
16231 +EXPORT_SYMBOL_GPL(dump_vx_info);
16233 diff -NurpP --minimal linux-4.9.76/kernel/vserver/device.c linux-4.9.76-vs2.3.9.5/kernel/vserver/device.c
16234 --- linux-4.9.76/kernel/vserver/device.c 1970-01-01 00:00:00.000000000 +0000
16235 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/device.c 2018-01-10 02:50:49.000000000 +0000
16238 + * linux/kernel/vserver/device.c
16240 + * Linux-VServer: Device Support
16242 + * Copyright (C) 2006 Herbert P?tzl
16243 + * Copyright (C) 2007 Daniel Hokka Zakrisson
16245 + * V0.01 device mapping basics
16246 + * V0.02 added defaults
16250 +#include <linux/slab.h>
16251 +#include <linux/rcupdate.h>
16252 +#include <linux/fs.h>
16253 +#include <linux/namei.h>
16254 +#include <linux/hash.h>
16256 +#include <asm/errno.h>
16257 +#include <asm/uaccess.h>
16258 +#include <linux/vserver/base.h>
16259 +#include <linux/vserver/debug.h>
16260 +#include <linux/vserver/context.h>
16261 +#include <linux/vserver/device.h>
16262 +#include <linux/vserver/device_cmd.h>
16265 +#define DMAP_HASH_BITS 4
16268 +struct vs_mapping {
16270 + struct hlist_node hlist;
16271 + struct list_head list;
16273 +#define dm_hlist u.hlist
16274 +#define dm_list u.list
16277 + struct vx_dmap_target target;
16281 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
16283 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
16285 +static struct vx_dmap_target dmap_defaults[2] = {
16286 + { .flags = DATTR_OPEN },
16287 + { .flags = DATTR_OPEN },
16291 +struct kmem_cache *dmap_cachep __read_mostly;
16293 +int __init dmap_cache_init(void)
16295 + dmap_cachep = kmem_cache_create("dmap_cache",
16296 + sizeof(struct vs_mapping), 0,
16297 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
16301 +__initcall(dmap_cache_init);
16304 +static inline unsigned int __hashval(dev_t dev, int bits)
16306 + return hash_long((unsigned long)dev, bits);
16310 +/* __hash_mapping()
16311 + * add the mapping to the hash table
16313 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
16315 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16316 + struct hlist_head *head, *hash = dmap_main_hash;
16317 + int device = vdm->device;
16319 + spin_lock(hash_lock);
16320 + vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
16321 + vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
16323 + head = &hash[__hashval(device, DMAP_HASH_BITS)];
16324 + hlist_add_head(&vdm->dm_hlist, head);
16325 + spin_unlock(hash_lock);
16329 +static inline int __mode_to_default(umode_t mode)
16342 +/* __set_default()
16345 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
16346 + struct vx_dmap_target *vdmt)
16348 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16349 + spin_lock(hash_lock);
16352 + vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
16354 + dmap_defaults[__mode_to_default(mode)] = *vdmt;
16357 + spin_unlock(hash_lock);
16359 + vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
16360 + vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
16364 +/* __remove_default()
16365 + * remove a default
16367 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
16369 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16370 + spin_lock(hash_lock);
16373 + vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
16374 + else /* remove == reset */
16375 + dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
16377 + spin_unlock(hash_lock);
16382 +/* __find_mapping()
16383 + * find a mapping in the hash table
16385 + * caller must hold hash_lock
16387 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
16388 + struct vs_mapping **local, struct vs_mapping **global)
16390 + struct hlist_head *hash = dmap_main_hash;
16391 + struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
16392 + struct hlist_node *pos;
16393 + struct vs_mapping *vdm;
16399 + hlist_for_each(pos, head) {
16400 + vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
16402 + if ((vdm->device == device) &&
16403 + !((vdm->target.flags ^ mode) & S_IFMT)) {
16404 + if (vdm->xid == xid) {
16407 + } else if (global && vdm->xid == 0)
16412 + if (global && *global)
16419 +/* __lookup_mapping()
16420 + * find a mapping and store the result in target and flags
16422 +static inline int __lookup_mapping(struct vx_info *vxi,
16423 + dev_t device, dev_t *target, int *flags, umode_t mode)
16425 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16426 + struct vs_mapping *vdm, *global;
16427 + struct vx_dmap_target *vdmt;
16429 + vxid_t xid = vxi->vx_id;
16432 + spin_lock(hash_lock);
16433 + if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
16435 + vdmt = &vdm->target;
16439 + index = __mode_to_default(mode);
16440 + if (vxi && vxi->dmap.targets[index].flags) {
16442 + vdmt = &vxi->dmap.targets[index];
16443 + } else if (global) {
16445 + vdmt = &global->target;
16449 + vdmt = &dmap_defaults[index];
16453 + if (target && (vdmt->flags & DATTR_REMAP))
16454 + *target = vdmt->target;
16456 + *target = device;
16458 + *flags = vdmt->flags;
16460 + spin_unlock(hash_lock);
16466 +/* __remove_mapping()
16467 + * remove a mapping from the hash table
16469 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
16472 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16473 + struct vs_mapping *vdm = NULL;
16476 + spin_lock(hash_lock);
16478 + ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
16480 + vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
16481 + vxi, vxi ? vxi->vx_id : 0, device, mode);
16484 + hlist_del(&vdm->dm_hlist);
16487 + spin_unlock(hash_lock);
16489 + kmem_cache_free(dmap_cachep, vdm);
16495 +int vs_map_device(struct vx_info *vxi,
16496 + dev_t device, dev_t *target, umode_t mode)
16498 + int ret, flags = DATTR_MASK;
16502 + *target = device;
16505 + ret = __lookup_mapping(vxi, device, target, &flags, mode);
16506 + vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
16507 + device, target ? *target : 0, flags, mode, ret);
16509 + return (flags & DATTR_MASK);
16514 +static int do_set_mapping(struct vx_info *vxi,
16515 + dev_t device, dev_t target, int flags, umode_t mode)
16518 + struct vs_mapping *new;
16520 + new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
16524 + INIT_HLIST_NODE(&new->dm_hlist);
16525 + new->device = device;
16526 + new->target.target = target;
16527 + new->target.flags = flags | mode;
16528 + new->xid = (vxi ? vxi->vx_id : 0);
16530 + vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
16531 + __hash_mapping(vxi, new);
16533 + struct vx_dmap_target new = {
16534 + .target = target,
16535 + .flags = flags | mode,
16537 + __set_default(vxi, mode, &new);
16543 +static int do_unset_mapping(struct vx_info *vxi,
16544 + dev_t device, dev_t target, int flags, umode_t mode)
16546 + int ret = -EINVAL;
16549 + ret = __remove_mapping(vxi, device, mode);
16553 + ret = __remove_default(vxi, mode);
16563 +static inline int __user_device(const char __user *name, dev_t *dev,
16566 + struct path path;
16573 + ret = user_lpath(name, &path);
16576 + if (path.dentry->d_inode) {
16577 + *dev = path.dentry->d_inode->i_rdev;
16578 + *mode = path.dentry->d_inode->i_mode;
16584 +static inline int __mapping_mode(dev_t device, dev_t target,
16585 + umode_t device_mode, umode_t target_mode, umode_t *mode)
16588 + *mode = device_mode & S_IFMT;
16590 + *mode = target_mode & S_IFMT;
16594 + /* if both given, device and target mode have to match */
16595 + if (device && target &&
16596 + ((device_mode ^ target_mode) & S_IFMT))
16602 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
16603 + const char __user *target_path, int flags, int set)
16605 + dev_t device = ~0, target = ~0;
16606 + umode_t device_mode = 0, target_mode = 0, mode;
16609 + ret = __user_device(device_path, &device, &device_mode);
16612 + ret = __user_device(target_path, &target, &target_mode);
16616 + ret = __mapping_mode(device, target,
16617 + device_mode, target_mode, &mode);
16622 + return do_set_mapping(vxi, device, target,
16625 + return do_unset_mapping(vxi, device, target,
16630 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
16632 + struct vcmd_set_mapping_v0 vc_data;
16634 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16637 + return do_mapping(vxi, vc_data.device, vc_data.target,
16638 + vc_data.flags, 1);
16641 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
16643 + struct vcmd_set_mapping_v0 vc_data;
16645 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16648 + return do_mapping(vxi, vc_data.device, vc_data.target,
16649 + vc_data.flags, 0);
16653 +#ifdef CONFIG_COMPAT
16655 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
16657 + struct vcmd_set_mapping_v0_x32 vc_data;
16659 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16662 + return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16663 + compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
16666 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
16668 + struct vcmd_set_mapping_v0_x32 vc_data;
16670 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16673 + return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16674 + compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
16677 +#endif /* CONFIG_COMPAT */
16680 diff -NurpP --minimal linux-4.9.76/kernel/vserver/dlimit.c linux-4.9.76-vs2.3.9.5/kernel/vserver/dlimit.c
16681 --- linux-4.9.76/kernel/vserver/dlimit.c 1970-01-01 00:00:00.000000000 +0000
16682 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/dlimit.c 2018-01-10 02:50:49.000000000 +0000
16685 + * linux/kernel/vserver/dlimit.c
16687 + * Virtual Server: Context Disk Limits
16689 + * Copyright (C) 2004-2009 Herbert P?tzl
16691 + * V0.01 initial version
16692 + * V0.02 compat32 splitup
16693 + * V0.03 extended interface
16697 +#include <linux/statfs.h>
16698 +#include <linux/sched.h>
16699 +#include <linux/namei.h>
16700 +#include <linux/vs_tag.h>
16701 +#include <linux/vs_dlimit.h>
16702 +#include <linux/vserver/dlimit_cmd.h>
16703 +#include <linux/slab.h>
16704 +// #include <linux/gfp.h>
16706 +#include <asm/uaccess.h>
16708 +/* __alloc_dl_info()
16710 + * allocate an initialized dl_info struct
16711 + * doesn't make it visible (hash) */
16713 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
16715 + struct dl_info *new = NULL;
16717 + vxdprintk(VXD_CBIT(dlim, 5),
16718 + "alloc_dl_info(%p,%d)*", sb, tag);
16720 + /* would this benefit from a slab cache? */
16721 + new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
16725 + memset(new, 0, sizeof(struct dl_info));
16726 + new->dl_tag = tag;
16728 + // INIT_RCU_HEAD(&new->dl_rcu);
16729 + INIT_HLIST_NODE(&new->dl_hlist);
16730 + spin_lock_init(&new->dl_lock);
16731 + atomic_set(&new->dl_refcnt, 0);
16732 + atomic_set(&new->dl_usecnt, 0);
16734 + /* rest of init goes here */
16736 + vxdprintk(VXD_CBIT(dlim, 4),
16737 + "alloc_dl_info(%p,%d) = %p", sb, tag, new);
16741 +/* __dealloc_dl_info()
16743 + * final disposal of dl_info */
16745 +static void __dealloc_dl_info(struct dl_info *dli)
16747 + vxdprintk(VXD_CBIT(dlim, 4),
16748 + "dealloc_dl_info(%p)", dli);
16750 + dli->dl_hlist.next = LIST_POISON1;
16751 + dli->dl_tag = -1;
16754 + BUG_ON(atomic_read(&dli->dl_usecnt));
16755 + BUG_ON(atomic_read(&dli->dl_refcnt));
16761 +/* hash table for dl_info hash */
16763 +#define DL_HASH_SIZE 13
16765 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
16767 +static DEFINE_SPINLOCK(dl_info_hash_lock);
16770 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
16772 + return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
16777 +/* __hash_dl_info()
16779 + * add the dli to the global hash table
16780 + * requires the hash_lock to be held */
16782 +static inline void __hash_dl_info(struct dl_info *dli)
16784 + struct hlist_head *head;
16786 + vxdprintk(VXD_CBIT(dlim, 6),
16787 + "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
16788 + get_dl_info(dli);
16789 + head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
16790 + hlist_add_head_rcu(&dli->dl_hlist, head);
16793 +/* __unhash_dl_info()
16795 + * remove the dli from the global hash table
16796 + * requires the hash_lock to be held */
16798 +static inline void __unhash_dl_info(struct dl_info *dli)
16800 + vxdprintk(VXD_CBIT(dlim, 6),
16801 + "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
16802 + hlist_del_rcu(&dli->dl_hlist);
16803 + put_dl_info(dli);
16807 +/* __lookup_dl_info()
16809 + * requires the rcu_read_lock()
16810 + * doesn't increment the dl_refcnt */
16812 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
16814 + struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
16815 + struct dl_info *dli;
16817 + hlist_for_each_entry_rcu(dli, head, dl_hlist) {
16818 + if (dli->dl_tag == tag && dli->dl_sb == sb)
16825 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
16827 + struct dl_info *dli;
16830 + dli = get_dl_info(__lookup_dl_info(sb, tag));
16831 + vxdprintk(VXD_CBIT(dlim, 7),
16832 + "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
16833 + rcu_read_unlock();
16837 +void rcu_free_dl_info(struct rcu_head *head)
16839 + struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
16840 + int usecnt, refcnt;
16842 + BUG_ON(!dli || !head);
16844 + usecnt = atomic_read(&dli->dl_usecnt);
16845 + BUG_ON(usecnt < 0);
16847 + refcnt = atomic_read(&dli->dl_refcnt);
16848 + BUG_ON(refcnt < 0);
16850 + vxdprintk(VXD_CBIT(dlim, 3),
16851 + "rcu_free_dl_info(%p)", dli);
16853 + __dealloc_dl_info(dli);
16855 + printk("!!! rcu didn't free\n");
16861 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
16862 + uint32_t flags, int add)
16864 + struct path path;
16867 + ret = user_lpath(name, &path);
16869 + struct super_block *sb;
16870 + struct dl_info *dli;
16873 + if (!path.dentry->d_inode)
16874 + goto out_release;
16875 + if (!(sb = path.dentry->d_inode->i_sb))
16876 + goto out_release;
16879 + dli = __alloc_dl_info(sb, id);
16880 + spin_lock(&dl_info_hash_lock);
16883 + if (__lookup_dl_info(sb, id))
16885 + __hash_dl_info(dli);
16888 + spin_lock(&dl_info_hash_lock);
16889 + dli = __lookup_dl_info(sb, id);
16894 + __unhash_dl_info(dli);
16898 + spin_unlock(&dl_info_hash_lock);
16900 + __dealloc_dl_info(dli);
16907 +int vc_add_dlimit(uint32_t id, void __user *data)
16909 + struct vcmd_ctx_dlimit_base_v0 vc_data;
16911 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16914 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
16917 +int vc_rem_dlimit(uint32_t id, void __user *data)
16919 + struct vcmd_ctx_dlimit_base_v0 vc_data;
16921 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16924 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
16927 +#ifdef CONFIG_COMPAT
16929 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
16931 + struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
16933 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16936 + return do_addrem_dlimit(id,
16937 + compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
16940 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
16942 + struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
16944 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16947 + return do_addrem_dlimit(id,
16948 + compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
16951 +#endif /* CONFIG_COMPAT */
16955 +int do_set_dlimit(uint32_t id, const char __user *name,
16956 + uint32_t space_used, uint32_t space_total,
16957 + uint32_t inodes_used, uint32_t inodes_total,
16958 + uint32_t reserved, uint32_t flags)
16960 + struct path path;
16963 + ret = user_lpath(name, &path);
16965 + struct super_block *sb;
16966 + struct dl_info *dli;
16969 + if (!path.dentry->d_inode)
16970 + goto out_release;
16971 + if (!(sb = path.dentry->d_inode->i_sb))
16972 + goto out_release;
16974 + /* sanity checks */
16975 + if ((reserved != CDLIM_KEEP &&
16976 + reserved > 100) ||
16977 + (inodes_used != CDLIM_KEEP &&
16978 + inodes_used > inodes_total) ||
16979 + (space_used != CDLIM_KEEP &&
16980 + space_used > space_total))
16981 + goto out_release;
16984 + dli = locate_dl_info(sb, id);
16986 + goto out_release;
16988 + spin_lock(&dli->dl_lock);
16990 + if (inodes_used != CDLIM_KEEP)
16991 + dli->dl_inodes_used = inodes_used;
16992 + if (inodes_total != CDLIM_KEEP)
16993 + dli->dl_inodes_total = inodes_total;
16994 + if (space_used != CDLIM_KEEP)
16995 + dli->dl_space_used = dlimit_space_32to64(
16996 + space_used, flags, DLIMS_USED);
16998 + if (space_total == CDLIM_INFINITY)
16999 + dli->dl_space_total = DLIM_INFINITY;
17000 + else if (space_total != CDLIM_KEEP)
17001 + dli->dl_space_total = dlimit_space_32to64(
17002 + space_total, flags, DLIMS_TOTAL);
17004 + if (reserved != CDLIM_KEEP)
17005 + dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17007 + spin_unlock(&dli->dl_lock);
17009 + put_dl_info(dli);
17018 +int vc_set_dlimit(uint32_t id, void __user *data)
17020 + struct vcmd_ctx_dlimit_v0 vc_data;
17022 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17025 + return do_set_dlimit(id, vc_data.name,
17026 + vc_data.space_used, vc_data.space_total,
17027 + vc_data.inodes_used, vc_data.inodes_total,
17028 + vc_data.reserved, vc_data.flags);
17031 +#ifdef CONFIG_COMPAT
17033 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17035 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
17037 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17040 + return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17041 + vc_data.space_used, vc_data.space_total,
17042 + vc_data.inodes_used, vc_data.inodes_total,
17043 + vc_data.reserved, vc_data.flags);
17046 +#endif /* CONFIG_COMPAT */
17050 +int do_get_dlimit(uint32_t id, const char __user *name,
17051 + uint32_t *space_used, uint32_t *space_total,
17052 + uint32_t *inodes_used, uint32_t *inodes_total,
17053 + uint32_t *reserved, uint32_t *flags)
17055 + struct path path;
17058 + ret = user_lpath(name, &path);
17060 + struct super_block *sb;
17061 + struct dl_info *dli;
17064 + if (!path.dentry->d_inode)
17065 + goto out_release;
17066 + if (!(sb = path.dentry->d_inode->i_sb))
17067 + goto out_release;
17070 + dli = locate_dl_info(sb, id);
17072 + goto out_release;
17074 + spin_lock(&dli->dl_lock);
17075 + *inodes_used = dli->dl_inodes_used;
17076 + *inodes_total = dli->dl_inodes_total;
17078 + *space_used = dlimit_space_64to32(
17079 + dli->dl_space_used, flags, DLIMS_USED);
17081 + if (dli->dl_space_total == DLIM_INFINITY)
17082 + *space_total = CDLIM_INFINITY;
17084 + *space_total = dlimit_space_64to32(
17085 + dli->dl_space_total, flags, DLIMS_TOTAL);
17087 + *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
17088 + spin_unlock(&dli->dl_lock);
17090 + put_dl_info(dli);
17101 +int vc_get_dlimit(uint32_t id, void __user *data)
17103 + struct vcmd_ctx_dlimit_v0 vc_data;
17106 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17109 + ret = do_get_dlimit(id, vc_data.name,
17110 + &vc_data.space_used, &vc_data.space_total,
17111 + &vc_data.inodes_used, &vc_data.inodes_total,
17112 + &vc_data.reserved, &vc_data.flags);
17116 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17121 +#ifdef CONFIG_COMPAT
17123 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
17125 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
17128 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17131 + ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
17132 + &vc_data.space_used, &vc_data.space_total,
17133 + &vc_data.inodes_used, &vc_data.inodes_total,
17134 + &vc_data.reserved, &vc_data.flags);
17138 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17143 +#endif /* CONFIG_COMPAT */
17146 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
17148 + struct dl_info *dli;
17149 + __u64 blimit, bfree, bavail;
17152 + dli = locate_dl_info(sb, dx_current_tag());
17156 + spin_lock(&dli->dl_lock);
17157 + if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
17160 + /* reduce max inodes available to limit */
17161 + if (buf->f_files > dli->dl_inodes_total)
17162 + buf->f_files = dli->dl_inodes_total;
17164 + ifree = dli->dl_inodes_total - dli->dl_inodes_used;
17165 + /* reduce free inodes to min */
17166 + if (ifree < buf->f_ffree)
17167 + buf->f_ffree = ifree;
17170 + if (dli->dl_space_total == DLIM_INFINITY)
17173 + blimit = dli->dl_space_total >> sb->s_blocksize_bits;
17175 + if (dli->dl_space_total < dli->dl_space_used)
17178 + bfree = (dli->dl_space_total - dli->dl_space_used)
17179 + >> sb->s_blocksize_bits;
17181 + bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
17182 + if (bavail < dli->dl_space_used)
17185 + bavail = (bavail - dli->dl_space_used)
17186 + >> sb->s_blocksize_bits;
17188 + /* reduce max space available to limit */
17189 + if (buf->f_blocks > blimit)
17190 + buf->f_blocks = blimit;
17192 + /* reduce free space to min */
17193 + if (bfree < buf->f_bfree)
17194 + buf->f_bfree = bfree;
17196 + /* reduce avail space to min */
17197 + if (bavail < buf->f_bavail)
17198 + buf->f_bavail = bavail;
17201 + spin_unlock(&dli->dl_lock);
17202 + put_dl_info(dli);
17207 +#include <linux/module.h>
17209 +EXPORT_SYMBOL_GPL(locate_dl_info);
17210 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
17212 diff -NurpP --minimal linux-4.9.76/kernel/vserver/helper.c linux-4.9.76-vs2.3.9.5/kernel/vserver/helper.c
17213 --- linux-4.9.76/kernel/vserver/helper.c 1970-01-01 00:00:00.000000000 +0000
17214 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/helper.c 2018-01-10 02:50:49.000000000 +0000
17217 + * linux/kernel/vserver/helper.c
17219 + * Virtual Context Support
17221 + * Copyright (C) 2004-2007 Herbert P?tzl
17223 + * V0.01 basic helper
17227 +#include <linux/kmod.h>
17228 +#include <linux/reboot.h>
17229 +#include <linux/vs_context.h>
17230 +#include <linux/vs_network.h>
17231 +#include <linux/vserver/signal.h>
17234 +char vshelper_path[255] = "/sbin/vshelper";
17236 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
17238 + current->flags &= ~PF_NO_SETAFFINITY;
17242 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
17244 + struct subprocess_info *info;
17245 + gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
17247 + info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
17248 + vshelper_init, NULL, NULL);
17249 + if (info == NULL)
17252 + return call_usermodehelper_exec(info, wait);
17255 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
17259 + if ((ret = vs_call_usermodehelper(name, argv, envp,
17260 + sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
17261 + printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
17262 + name, argv[1], argv[2],
17263 + sync ? "sync" : "async", ret);
17265 + vxdprintk(VXD_CBIT(switch, 4),
17266 + "%s: (%s %s) returned %s with %d",
17267 + name, argv[1], argv[2], sync ? "sync" : "async", ret);
17272 + * vshelper path is set via /proc/sys
17273 + * invoked by vserver sys_reboot(), with
17274 + * the following arguments
17276 + * argv [0] = vshelper_path;
17277 + * argv [1] = action: "restart", "halt", "poweroff", ...
17278 + * argv [2] = context identifier
17280 + * envp [*] = type-specific parameters
17283 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
17285 + char id_buf[8], cmd_buf[16];
17286 + char uid_buf[16], pid_buf[16];
17289 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
17290 + char *envp[] = {"HOME=/", "TERM=linux",
17291 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
17292 + uid_buf, pid_buf, cmd_buf, 0};
17294 + if (vx_info_state(vxi, VXS_HELPER))
17296 + vxi->vx_state |= VXS_HELPER;
17298 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17300 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17301 + snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
17302 + from_kuid(&init_user_ns, current_uid()));
17303 + snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
17306 + case LINUX_REBOOT_CMD_RESTART:
17307 + argv[1] = "restart";
17310 + case LINUX_REBOOT_CMD_HALT:
17311 + argv[1] = "halt";
17314 + case LINUX_REBOOT_CMD_POWER_OFF:
17315 + argv[1] = "poweroff";
17318 + case LINUX_REBOOT_CMD_SW_SUSPEND:
17319 + argv[1] = "swsusp";
17322 + case LINUX_REBOOT_CMD_OOM:
17327 + vxi->vx_state &= ~VXS_HELPER;
17331 + ret = do_vshelper(vshelper_path, argv, envp, 0);
17332 + vxi->vx_state &= ~VXS_HELPER;
17333 + __wakeup_vx_info(vxi);
17334 + return (ret) ? -EPERM : 0;
17338 +long vs_reboot(unsigned int cmd, void __user *arg)
17340 + struct vx_info *vxi = current_vx_info();
17343 + vxdprintk(VXD_CBIT(misc, 5),
17344 + "vs_reboot(%p[#%d],%u)",
17345 + vxi, vxi ? vxi->vx_id : 0, cmd);
17347 + ret = vs_reboot_helper(vxi, cmd, arg);
17351 + vxi->reboot_cmd = cmd;
17352 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17354 + case LINUX_REBOOT_CMD_RESTART:
17355 + case LINUX_REBOOT_CMD_HALT:
17356 + case LINUX_REBOOT_CMD_POWER_OFF:
17357 + vx_info_kill(vxi, 0, SIGKILL);
17358 + vx_info_kill(vxi, 1, SIGKILL);
17366 +long vs_oom_action(unsigned int cmd)
17368 + struct vx_info *vxi = current_vx_info();
17371 + vxdprintk(VXD_CBIT(misc, 5),
17372 + "vs_oom_action(%p[#%d],%u)",
17373 + vxi, vxi ? vxi->vx_id : 0, cmd);
17375 + ret = vs_reboot_helper(vxi, cmd, NULL);
17379 + vxi->reboot_cmd = cmd;
17380 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17381 + vx_info_kill(vxi, 0, SIGKILL);
17382 + vx_info_kill(vxi, 1, SIGKILL);
17388 + * argv [0] = vshelper_path;
17389 + * argv [1] = action: "startup", "shutdown"
17390 + * argv [2] = context identifier
17392 + * envp [*] = type-specific parameters
17395 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
17397 + char id_buf[8], cmd_buf[16];
17398 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
17399 + char *envp[] = {"HOME=/", "TERM=linux",
17400 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17402 + if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
17405 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17406 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17409 + case VSC_STARTUP:
17410 + argv[1] = "startup";
17412 + case VSC_SHUTDOWN:
17413 + argv[1] = "shutdown";
17419 + return do_vshelper(vshelper_path, argv, envp, 1);
17424 + * argv [0] = vshelper_path;
17425 + * argv [1] = action: "netup", "netdown"
17426 + * argv [2] = context identifier
17428 + * envp [*] = type-specific parameters
17431 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
17433 + char id_buf[8], cmd_buf[16];
17434 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
17435 + char *envp[] = {"HOME=/", "TERM=linux",
17436 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17438 + if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
17441 + snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
17442 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17446 + argv[1] = "netup";
17448 + case VSC_NETDOWN:
17449 + argv[1] = "netdown";
17455 + return do_vshelper(vshelper_path, argv, envp, 1);
17458 diff -NurpP --minimal linux-4.9.76/kernel/vserver/history.c linux-4.9.76-vs2.3.9.5/kernel/vserver/history.c
17459 --- linux-4.9.76/kernel/vserver/history.c 1970-01-01 00:00:00.000000000 +0000
17460 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/history.c 2018-01-10 02:50:49.000000000 +0000
17463 + * kernel/vserver/history.c
17465 + * Virtual Context History Backtrace
17467 + * Copyright (C) 2004-2007 Herbert P?tzl
17469 + * V0.01 basic structure
17470 + * V0.02 hash/unhash and trace
17471 + * V0.03 preemption fixes
17475 +#include <linux/module.h>
17476 +#include <asm/uaccess.h>
17478 +#include <linux/vserver/context.h>
17479 +#include <linux/vserver/debug.h>
17480 +#include <linux/vserver/debug_cmd.h>
17481 +#include <linux/vserver/history.h>
17484 +#ifdef CONFIG_VSERVER_HISTORY
17485 +#define VXH_SIZE CONFIG_VSERVER_HISTORY_SIZE
17487 +#define VXH_SIZE 64
17490 +struct _vx_history {
17491 + unsigned int counter;
17493 + struct _vx_hist_entry entry[VXH_SIZE + 1];
17497 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
17499 +unsigned volatile int vxh_active = 1;
17501 +static atomic_t sequence = ATOMIC_INIT(0);
17506 + * requires disabled preemption */
17508 +struct _vx_hist_entry *vxh_advance(void *loc)
17510 + unsigned int cpu = smp_processor_id();
17511 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17512 + struct _vx_hist_entry *entry;
17513 + unsigned int index;
17515 + index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
17516 + entry = &hist->entry[index];
17518 + entry->seq = atomic_inc_return(&sequence);
17519 + entry->loc = loc;
17523 +EXPORT_SYMBOL_GPL(vxh_advance);
17526 +#define VXH_LOC_FMTS "(#%04x,*%d):%p"
17528 +#define VXH_LOC_ARGS(e) (e)->seq, cpu, (e)->loc
17531 +#define VXH_VXI_FMTS "%p[#%d,%d.%d]"
17533 +#define VXH_VXI_ARGS(e) (e)->vxi.ptr, \
17534 + (e)->vxi.ptr ? (e)->vxi.xid : 0, \
17535 + (e)->vxi.ptr ? (e)->vxi.usecnt : 0, \
17536 + (e)->vxi.ptr ? (e)->vxi.tasks : 0
17538 +void vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
17540 + switch (e->type) {
17541 + case VXH_THROW_OOPS:
17542 + printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
17545 + case VXH_GET_VX_INFO:
17546 + case VXH_PUT_VX_INFO:
17547 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17549 + (e->type == VXH_GET_VX_INFO) ? "get" : "put",
17550 + VXH_VXI_ARGS(e));
17553 + case VXH_INIT_VX_INFO:
17554 + case VXH_SET_VX_INFO:
17555 + case VXH_CLR_VX_INFO:
17556 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17558 + (e->type == VXH_INIT_VX_INFO) ? "init" :
17559 + ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
17560 + VXH_VXI_ARGS(e), e->sc.data);
17563 + case VXH_CLAIM_VX_INFO:
17564 + case VXH_RELEASE_VX_INFO:
17565 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17567 + (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
17568 + VXH_VXI_ARGS(e), e->sc.data);
17571 + case VXH_ALLOC_VX_INFO:
17572 + case VXH_DEALLOC_VX_INFO:
17573 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17575 + (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
17576 + VXH_VXI_ARGS(e));
17579 + case VXH_HASH_VX_INFO:
17580 + case VXH_UNHASH_VX_INFO:
17581 + printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
17583 + (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
17584 + VXH_VXI_ARGS(e));
17587 + case VXH_LOC_VX_INFO:
17588 + case VXH_LOOKUP_VX_INFO:
17589 + case VXH_CREATE_VX_INFO:
17590 + printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
17592 + (e->type == VXH_CREATE_VX_INFO) ? "create" :
17593 + ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
17594 + e->ll.arg, VXH_VXI_ARGS(e));
17599 +static void __vxh_dump_history(void)
17601 + unsigned int i, cpu;
17603 + printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
17604 + atomic_read(&sequence), NR_CPUS);
17606 + for (i = 0; i < VXH_SIZE; i++) {
17607 + for_each_online_cpu(cpu) {
17608 + struct _vx_history *hist =
17609 + &per_cpu(vx_history_buffer, cpu);
17610 + unsigned int index = (hist->counter - i) % VXH_SIZE;
17611 + struct _vx_hist_entry *entry = &hist->entry[index];
17613 + vxh_dump_entry(entry, cpu);
17618 +void vxh_dump_history(void)
17622 + local_irq_enable();
17624 + local_irq_disable();
17626 + __vxh_dump_history();
17630 +/* vserver syscall commands below here */
17633 +int vc_dump_history(uint32_t id)
17636 + __vxh_dump_history();
17643 +int do_read_history(struct __user _vx_hist_entry *data,
17644 + int cpu, uint32_t *index, uint32_t *count)
17646 + int pos, ret = 0;
17647 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17648 + int end = hist->counter;
17649 + int start = end - VXH_SIZE + 2;
17650 + int idx = *index;
17652 + /* special case: get current pos */
17658 + /* have we lost some data? */
17662 + for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
17663 + struct _vx_hist_entry *entry =
17664 + &hist->entry[idx % VXH_SIZE];
17666 + /* send entry to userspace */
17667 + ret = copy_to_user(&data[pos], entry, sizeof(*entry));
17671 + /* save new index and count */
17674 + return ret ? ret : (*index < end);
17677 +int vc_read_history(uint32_t id, void __user *data)
17679 + struct vcmd_read_history_v0 vc_data;
17682 + if (id >= NR_CPUS)
17685 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17688 + ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
17689 + id, &vc_data.index, &vc_data.count);
17691 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17696 +#ifdef CONFIG_COMPAT
17698 +int vc_read_history_x32(uint32_t id, void __user *data)
17700 + struct vcmd_read_history_v0_x32 vc_data;
17703 + if (id >= NR_CPUS)
17706 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17709 + ret = do_read_history((struct __user _vx_hist_entry *)
17710 + compat_ptr(vc_data.data_ptr),
17711 + id, &vc_data.index, &vc_data.count);
17713 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17718 +#endif /* CONFIG_COMPAT */
17720 diff -NurpP --minimal linux-4.9.76/kernel/vserver/inet.c linux-4.9.76-vs2.3.9.5/kernel/vserver/inet.c
17721 --- linux-4.9.76/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
17722 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/inet.c 2018-01-10 02:50:49.000000000 +0000
17725 +#include <linux/in.h>
17726 +#include <linux/inetdevice.h>
17727 +#include <linux/export.h>
17728 +#include <linux/vs_inet.h>
17729 +#include <linux/vs_inet6.h>
17730 +#include <linux/vserver/debug.h>
17731 +#include <net/route.h>
17732 +#include <net/addrconf.h>
17735 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17739 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
17742 + struct nx_addr_v4 *ptr;
17743 + unsigned long irqflags;
17745 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
17746 + for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
17747 + if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
17752 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
17755 + vxdprintk(VXD_CBIT(net, 2),
17756 + "nx_v4_addr_conflict(%p,%p): %d",
17757 + nxi1, nxi2, ret);
17763 +#ifdef CONFIG_IPV6
17765 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17769 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
17772 + struct nx_addr_v6 *ptr;
17773 + unsigned long irqflags;
17775 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
17776 + for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
17777 + if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
17782 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
17785 + vxdprintk(VXD_CBIT(net, 2),
17786 + "nx_v6_addr_conflict(%p,%p): %d",
17787 + nxi1, nxi2, ret);
17794 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
17796 + struct in_device *in_dev;
17797 + struct in_ifaddr **ifap;
17798 + struct in_ifaddr *ifa;
17803 + in_dev = in_dev_get(dev);
17807 + for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
17808 + ifap = &ifa->ifa_next) {
17809 + if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
17814 + in_dev_put(in_dev);
17820 +#ifdef CONFIG_IPV6
17822 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
17824 + struct inet6_dev *in_dev;
17825 + struct inet6_ifaddr *ifa;
17830 + in_dev = in6_dev_get(dev);
17834 + // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
17835 + list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
17836 + if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
17841 + in6_dev_put(in_dev);
17848 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
17854 + if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
17856 +#ifdef CONFIG_IPV6
17858 + if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
17863 + vxdprintk(VXD_CBIT(net, 3),
17864 + "dev_in_nx_info(%p,%p[#%d]) = %d",
17865 + dev, nxi, nxi ? nxi->nx_id : 0, ret);
17869 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
17870 + struct flowi4 *fl4)
17872 + struct rtable *rt;
17877 + /* FIXME: handle lback only case */
17878 + if (!NX_IPV4(nxi))
17879 + return ERR_PTR(-EPERM);
17881 + vxdprintk(VXD_CBIT(net, 4),
17882 + "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
17883 + nxi, nxi ? nxi->nx_id : 0,
17884 + NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
17886 + /* single IP is unconditional */
17887 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
17888 + (fl4->saddr == INADDR_ANY))
17889 + fl4->saddr = nxi->v4.ip[0].s_addr;
17891 + if (fl4->saddr == INADDR_ANY) {
17892 + struct nx_addr_v4 *ptr;
17893 + __be32 found = 0;
17895 + rt = __ip_route_output_key(net, fl4);
17896 + if (!IS_ERR(rt)) {
17897 + found = fl4->saddr;
17899 + vxdprintk(VXD_CBIT(net, 4),
17900 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
17901 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
17902 + if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
17906 + WARN_ON_ONCE(in_irq());
17907 + spin_lock_bh(&nxi->addr_lock);
17908 + for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
17909 + __be32 primary = ptr->ip[0].s_addr;
17910 + __be32 mask = ptr->mask.s_addr;
17911 + __be32 neta = primary & mask;
17913 + vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
17914 + NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
17915 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
17916 + NIPQUAD(mask), NIPQUAD(neta));
17917 + if ((found & mask) != neta)
17920 + fl4->saddr = primary;
17921 + rt = __ip_route_output_key(net, fl4);
17922 + vxdprintk(VXD_CBIT(net, 4),
17923 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
17924 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
17925 + if (!IS_ERR(rt)) {
17926 + found = fl4->saddr;
17928 + if (found == primary)
17929 + goto found_unlock;
17932 + /* still no source ip? */
17933 + found = ipv4_is_loopback(fl4->daddr)
17934 + ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
17936 + spin_unlock_bh(&nxi->addr_lock);
17938 + /* assign src ip to flow */
17939 + fl4->saddr = found;
17942 + if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
17943 + return ERR_PTR(-EPERM);
17946 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
17947 + if (ipv4_is_loopback(fl4->daddr))
17948 + fl4->daddr = nxi->v4_lback.s_addr;
17949 + if (ipv4_is_loopback(fl4->saddr))
17950 + fl4->saddr = nxi->v4_lback.s_addr;
17951 + } else if (ipv4_is_loopback(fl4->daddr) &&
17952 + !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
17953 + return ERR_PTR(-EPERM);
17958 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
17960 diff -NurpP --minimal linux-4.9.76/kernel/vserver/init.c linux-4.9.76-vs2.3.9.5/kernel/vserver/init.c
17961 --- linux-4.9.76/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
17962 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/init.c 2018-01-10 02:50:49.000000000 +0000
17965 + * linux/kernel/init.c
17967 + * Virtual Server Init
17969 + * Copyright (C) 2004-2007 Herbert P?tzl
17971 + * V0.01 basic structure
17975 +#include <linux/init.h>
17976 +#include <linux/module.h>
17978 +int vserver_register_sysctl(void);
17979 +void vserver_unregister_sysctl(void);
17982 +static int __init init_vserver(void)
17986 +#ifdef CONFIG_VSERVER_DEBUG
17987 + vserver_register_sysctl();
17993 +static void __exit exit_vserver(void)
17996 +#ifdef CONFIG_VSERVER_DEBUG
17997 + vserver_unregister_sysctl();
18002 +/* FIXME: GFP_ZONETYPES gone
18003 +long vx_slab[GFP_ZONETYPES]; */
18007 +module_init(init_vserver);
18008 +module_exit(exit_vserver);
18010 diff -NurpP --minimal linux-4.9.76/kernel/vserver/inode.c linux-4.9.76-vs2.3.9.5/kernel/vserver/inode.c
18011 --- linux-4.9.76/kernel/vserver/inode.c 1970-01-01 00:00:00.000000000 +0000
18012 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/inode.c 2018-01-13 03:26:08.000000000 +0000
18015 + * linux/kernel/vserver/inode.c
18017 + * Virtual Server: File System Support
18019 + * Copyright (C) 2004-2007 Herbert P?tzl
18021 + * V0.01 separated from vcontext V0.05
18022 + * V0.02 moved to tag (instead of xid)
18026 +#include <linux/tty.h>
18027 +#include <linux/proc_fs.h>
18028 +#include <linux/devpts_fs.h>
18029 +#include <linux/fs.h>
18030 +#include <linux/file.h>
18031 +#include <linux/mount.h>
18032 +#include <linux/parser.h>
18033 +#include <linux/namei.h>
18034 +#include <linux/magic.h>
18035 +#include <linux/slab.h>
18036 +#include <linux/vserver/inode.h>
18037 +#include <linux/vserver/inode_cmd.h>
18038 +#include <linux/vs_base.h>
18039 +#include <linux/vs_tag.h>
18041 +#include <asm/uaccess.h>
18042 +#include <../../fs/proc/internal.h>
18045 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18047 + struct proc_dir_entry *entry;
18049 + if (!in || !in->i_sb)
18052 + *flags = IATTR_TAG
18053 + | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18054 + | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18055 + | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18056 + | (IS_COW(in) ? IATTR_COW : 0);
18057 + *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18059 + if (S_ISDIR(in->i_mode))
18060 + *mask |= IATTR_BARRIER;
18062 + if (IS_TAGGED(in)) {
18063 + *tag = i_tag_read(in);
18064 + *mask |= IATTR_TAG;
18067 + switch (in->i_sb->s_magic) {
18068 + case PROC_SUPER_MAGIC:
18069 + entry = PROC_I(in)->pde;
18071 + /* check for specific inodes? */
18073 + *mask |= IATTR_FLAGS;
18075 + *flags |= (entry->vx_flags & IATTR_FLAGS);
18077 + *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
18080 + case DEVPTS_SUPER_MAGIC:
18081 + *tag = i_tag_read(in);
18082 + *mask |= IATTR_TAG;
18091 +int vc_get_iattr(void __user *data)
18093 + struct path path;
18094 + struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
18097 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18100 + ret = user_lpath(vc_data.name, &path);
18102 + ret = __vc_get_iattr(path.dentry->d_inode,
18103 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18109 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18114 +#ifdef CONFIG_COMPAT
18116 +int vc_get_iattr_x32(void __user *data)
18118 + struct path path;
18119 + struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
18122 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18125 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18127 + ret = __vc_get_iattr(path.dentry->d_inode,
18128 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18134 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18139 +#endif /* CONFIG_COMPAT */
18142 +int vc_fget_iattr(uint32_t fd, void __user *data)
18144 + struct file *filp;
18145 + struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
18148 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18152 + if (!filp || !filp->f_path.dentry || !filp->f_path.dentry->d_inode)
18155 + ret = __vc_get_iattr(filp->f_path.dentry->d_inode,
18156 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18160 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18166 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18168 + struct inode *in = de->d_inode;
18169 + int error = 0, is_proc = 0, has_tag = 0;
18170 + struct iattr attr = { 0 };
18172 + if (!in || !in->i_sb)
18175 + is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
18176 + if ((*mask & IATTR_FLAGS) && !is_proc)
18179 + has_tag = IS_TAGGED(in) ||
18180 + (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
18181 + if ((*mask & IATTR_TAG) && !has_tag)
18185 + if (*mask & IATTR_TAG) {
18186 + attr.ia_tag = make_ktag(&init_user_ns, *tag);
18187 + attr.ia_valid |= ATTR_TAG;
18190 + if (*mask & IATTR_FLAGS) {
18191 + struct proc_dir_entry *entry = PROC_I(in)->pde;
18192 + unsigned int iflags = PROC_I(in)->vx_flags;
18194 + iflags = (iflags & ~(*mask & IATTR_FLAGS))
18195 + | (*flags & IATTR_FLAGS);
18196 + PROC_I(in)->vx_flags = iflags;
18198 + entry->vx_flags = iflags;
18201 + if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
18202 + IATTR_BARRIER | IATTR_COW)) {
18203 + int iflags = in->i_flags;
18204 + int vflags = in->i_vflags;
18206 + if (*mask & IATTR_IMMUTABLE) {
18207 + if (*flags & IATTR_IMMUTABLE)
18208 + iflags |= S_IMMUTABLE;
18210 + iflags &= ~S_IMMUTABLE;
18212 + if (*mask & IATTR_IXUNLINK) {
18213 + if (*flags & IATTR_IXUNLINK)
18214 + iflags |= S_IXUNLINK;
18216 + iflags &= ~S_IXUNLINK;
18218 + if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
18219 + if (*flags & IATTR_BARRIER)
18220 + vflags |= V_BARRIER;
18222 + vflags &= ~V_BARRIER;
18224 + if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
18225 + if (*flags & IATTR_COW)
18228 + vflags &= ~V_COW;
18230 + if (in->i_op && in->i_op->sync_flags) {
18231 + error = in->i_op->sync_flags(in, iflags, vflags);
18237 + if (attr.ia_valid) {
18238 + if (in->i_op && in->i_op->setattr)
18239 + error = in->i_op->setattr(de, &attr);
18241 + error = setattr_prepare(de, &attr);
18243 + setattr_copy(in, &attr);
18244 + mark_inode_dirty(in);
18250 + inode_unlock(in);
18254 +int vc_set_iattr(void __user *data)
18256 + struct path path;
18257 + struct vcmd_ctx_iattr_v1 vc_data;
18260 + if (!capable(CAP_LINUX_IMMUTABLE))
18262 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18265 + ret = user_lpath(vc_data.name, &path);
18267 + ret = __vc_set_iattr(path.dentry,
18268 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18272 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18277 +#ifdef CONFIG_COMPAT
18279 +int vc_set_iattr_x32(void __user *data)
18281 + struct path path;
18282 + struct vcmd_ctx_iattr_v1_x32 vc_data;
18285 + if (!capable(CAP_LINUX_IMMUTABLE))
18287 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18290 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18292 + ret = __vc_set_iattr(path.dentry,
18293 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18297 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18302 +#endif /* CONFIG_COMPAT */
18304 +int vc_fset_iattr(uint32_t fd, void __user *data)
18306 + struct file *filp;
18307 + struct vcmd_ctx_fiattr_v0 vc_data;
18310 + if (!capable(CAP_LINUX_IMMUTABLE))
18312 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18316 + if (!filp || !filp->f_path.dentry || !filp->f_path.dentry->d_inode)
18319 + ret = __vc_set_iattr(filp->f_path.dentry, &vc_data.tag,
18320 + &vc_data.flags, &vc_data.mask);
18324 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18330 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
18332 +static match_table_t tokens = {
18333 + {Opt_notagcheck, "notagcheck"},
18334 +#ifdef CONFIG_PROPAGATE
18335 + {Opt_notag, "notag"},
18336 + {Opt_tag, "tag"},
18337 + {Opt_tagid, "tagid=%u"},
18343 +static void __dx_parse_remove(char *string, char *opt)
18345 + char *p = strstr(string, opt);
18349 + while (*q != '\0' && *q != ',')
18358 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
18359 + unsigned long *flags)
18362 + substring_t args[MAX_OPT_ARGS];
18364 + char *s, *p, *opts;
18365 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
18371 + s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
18376 + while ((p = strsep(&opts, ",")) != NULL) {
18377 + token = match_token(p, tokens, args);
18380 +#ifdef CONFIG_PROPAGATE
18385 + __dx_parse_remove(s, "tag");
18386 + *mnt_flags |= MNT_TAGID;
18387 + set |= MNT_TAGID;
18391 + __dx_parse_remove(s, "notag");
18392 + *mnt_flags |= MNT_NOTAG;
18393 + set |= MNT_NOTAG;
18396 + if (tag && !match_int(args, &option))
18399 + __dx_parse_remove(s, "tagid");
18400 + *mnt_flags |= MNT_TAGID;
18401 + set |= MNT_TAGID;
18403 +#endif /* CONFIG_PROPAGATE */
18404 + case Opt_notagcheck:
18406 + __dx_parse_remove(s, "notagcheck");
18407 + *flags |= MS_NOTAGCHECK;
18408 + set |= MS_NOTAGCHECK;
18411 + vxdprintk(VXD_CBIT(tag, 7),
18412 + "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
18413 + p, token, option);
18416 + strcpy(string, s);
18421 +#ifdef CONFIG_PROPAGATE
18423 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
18425 + vtag_t new_tag = 0;
18426 + struct vfsmount *mnt;
18431 + mnt = nd->path.mnt;
18435 + propagate = (mnt->mnt_flags & MNT_TAGID);
18437 + new_tag = mnt->mnt_tag;
18439 + vxdprintk(VXD_CBIT(tag, 7),
18440 + "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
18441 + inode, inode->i_ino, inode->i_tag,
18442 + new_tag, (propagate) ? 1 : 0);
18445 + i_tag_write(inode, new_tag);
18448 +#include <linux/module.h>
18450 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
18452 +#endif /* CONFIG_PROPAGATE */
18454 diff -NurpP --minimal linux-4.9.76/kernel/vserver/limit.c linux-4.9.76-vs2.3.9.5/kernel/vserver/limit.c
18455 --- linux-4.9.76/kernel/vserver/limit.c 1970-01-01 00:00:00.000000000 +0000
18456 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/limit.c 2018-01-10 02:50:49.000000000 +0000
18459 + * linux/kernel/vserver/limit.c
18461 + * Virtual Server: Context Limits
18463 + * Copyright (C) 2004-2010 Herbert P?tzl
18465 + * V0.01 broken out from vcontext V0.05
18466 + * V0.02 changed vcmds to vxi arg
18467 + * V0.03 added memory cgroup support
18471 +#include <linux/sched.h>
18472 +#include <linux/module.h>
18473 +#include <linux/memcontrol.h>
18474 +#include <linux/page_counter.h>
18475 +#include <linux/vs_limit.h>
18476 +#include <linux/vserver/limit.h>
18477 +#include <linux/vserver/limit_cmd.h>
18479 +#include <asm/uaccess.h>
18482 +const char *vlimit_name[NUM_LIMITS] = {
18483 + [RLIMIT_CPU] = "CPU",
18484 + [RLIMIT_NPROC] = "NPROC",
18485 + [RLIMIT_NOFILE] = "NOFILE",
18486 + [RLIMIT_LOCKS] = "LOCKS",
18487 + [RLIMIT_SIGPENDING] = "SIGP",
18488 + [RLIMIT_MSGQUEUE] = "MSGQ",
18490 + [VLIMIT_NSOCK] = "NSOCK",
18491 + [VLIMIT_OPENFD] = "OPENFD",
18492 + [VLIMIT_SHMEM] = "SHMEM",
18493 + [VLIMIT_DENTRY] = "DENTRY",
18496 +EXPORT_SYMBOL_GPL(vlimit_name);
18498 +#define MASK_ENTRY(x) (1 << (x))
18500 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
18503 + , /* softlimit */
18506 + MASK_ENTRY( RLIMIT_NPROC ) |
18507 + MASK_ENTRY( RLIMIT_NOFILE ) |
18508 + MASK_ENTRY( RLIMIT_LOCKS ) |
18509 + MASK_ENTRY( RLIMIT_MSGQUEUE ) |
18511 + MASK_ENTRY( VLIMIT_NSOCK ) |
18512 + MASK_ENTRY( VLIMIT_OPENFD ) |
18513 + MASK_ENTRY( VLIMIT_SHMEM ) |
18514 + MASK_ENTRY( VLIMIT_DENTRY ) |
18517 + /* accounting only */
18518 +uint32_t account_mask =
18519 + MASK_ENTRY( VLIMIT_SEMARY ) |
18520 + MASK_ENTRY( VLIMIT_NSEMS ) |
18521 + MASK_ENTRY( VLIMIT_MAPPED ) |
18525 +static int is_valid_vlimit(int id)
18527 + uint32_t mask = vlimit_mask.minimum |
18528 + vlimit_mask.softlimit | vlimit_mask.maximum;
18529 + return mask & (1 << id);
18532 +static int is_accounted_vlimit(int id)
18534 + if (is_valid_vlimit(id))
18536 + return account_mask & (1 << id);
18540 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
18542 + rlim_t limit = __rlim_soft(&vxi->limit, id);
18543 + return VX_VLIM(limit);
18546 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
18548 + rlim_t limit = __rlim_hard(&vxi->limit, id);
18549 + return VX_VLIM(limit);
18552 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
18553 + uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
18555 + if (!is_valid_vlimit(id))
18559 + *minimum = CRLIM_UNSET;
18561 + *softlimit = vc_get_soft(vxi, id);
18563 + *maximum = vc_get_hard(vxi, id);
18567 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
18569 + struct vcmd_ctx_rlimit_v0 vc_data;
18572 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18575 + ret = do_get_rlimit(vxi, vc_data.id,
18576 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18580 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18585 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
18586 + uint64_t minimum, uint64_t softlimit, uint64_t maximum)
18588 + if (!is_valid_vlimit(id))
18591 + if (maximum != CRLIM_KEEP)
18592 + __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
18593 + if (softlimit != CRLIM_KEEP)
18594 + __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
18596 + /* clamp soft limit */
18597 + if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
18598 + __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
18603 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
18605 + struct vcmd_ctx_rlimit_v0 vc_data;
18607 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18610 + return do_set_rlimit(vxi, vc_data.id,
18611 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18614 +#ifdef CONFIG_IA32_EMULATION
18616 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
18618 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
18620 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18623 + return do_set_rlimit(vxi, vc_data.id,
18624 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18627 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
18629 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
18632 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18635 + ret = do_get_rlimit(vxi, vc_data.id,
18636 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18640 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18645 +#endif /* CONFIG_IA32_EMULATION */
18648 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
18650 + if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
18656 +static inline void vx_reset_hits(struct _vx_limit *limit)
18660 + for (lim = 0; lim < NUM_LIMITS; lim++) {
18661 + atomic_set(&__rlim_lhit(limit, lim), 0);
18665 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
18667 + vx_reset_hits(&vxi->limit);
18671 +static inline void vx_reset_minmax(struct _vx_limit *limit)
18676 + for (lim = 0; lim < NUM_LIMITS; lim++) {
18677 + value = __rlim_get(limit, lim);
18678 + __rlim_rmax(limit, lim) = value;
18679 + __rlim_rmin(limit, lim) = value;
18683 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
18685 + vx_reset_minmax(&vxi->limit);
18690 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
18692 + struct vcmd_rlimit_stat_v0 vc_data;
18693 + struct _vx_limit *limit = &vxi->limit;
18696 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18700 + if (!is_accounted_vlimit(id))
18703 + vx_limit_fixup(limit, id);
18704 + vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
18705 + vc_data.value = __rlim_get(limit, id);
18706 + vc_data.minimum = __rlim_rmin(limit, id);
18707 + vc_data.maximum = __rlim_rmax(limit, id);
18709 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18715 +#ifdef CONFIG_MEMCG
18716 +void vx_vsi_meminfo(struct sysinfo *val)
18718 + struct mem_cgroup *mcg;
18719 + u64 res_limit, res_usage;
18722 + mcg = mem_cgroup_from_task(current);
18723 + rcu_read_unlock();
18727 + res_limit = mem_cgroup_mem_limit_pages(mcg);
18728 + res_usage = mem_cgroup_mem_usage_pages(mcg);
18730 + if (res_limit != PAGE_COUNTER_MAX)
18731 + val->totalram = res_limit;
18732 + val->freeram = val->totalram - res_usage;
18733 + val->bufferram = 0;
18734 + val->totalhigh = 0;
18735 + val->freehigh = 0;
18740 +void vx_vsi_swapinfo(struct sysinfo *val)
18742 +#ifdef CONFIG_MEMCG_SWAP
18743 + struct mem_cgroup *mcg;
18744 + u64 res_limit, res_usage, memsw_limit, memsw_usage;
18745 + s64 swap_limit, swap_usage;
18748 + mcg = mem_cgroup_from_task(current);
18749 + rcu_read_unlock();
18753 + res_limit = mem_cgroup_mem_limit_pages(mcg);
18754 + res_usage = mem_cgroup_mem_usage_pages(mcg);
18755 + memsw_limit = mem_cgroup_memsw_limit_pages(mcg);
18756 + memsw_usage = mem_cgroup_memsw_usage_pages(mcg);
18758 + /* memory unlimited */
18759 + if (res_limit == PAGE_COUNTER_MAX)
18762 + swap_limit = memsw_limit - res_limit;
18763 + /* we have a swap limit? */
18764 + if (memsw_limit != PAGE_COUNTER_MAX)
18765 + val->totalswap = swap_limit;
18767 + /* calculate swap part */
18768 + swap_usage = (memsw_usage > res_usage) ?
18769 + memsw_usage - res_usage : 0;
18771 + /* total shown minus usage gives free swap */
18772 + val->freeswap = (swap_usage < swap_limit) ?
18773 + val->totalswap - swap_usage : 0;
18775 +#else /* !CONFIG_MEMCG_SWAP */
18776 + val->totalswap = 0;
18777 + val->freeswap = 0;
18778 +#endif /* !CONFIG_MEMCG_SWAP */
18782 +long vx_vsi_cached(struct sysinfo *val)
18785 +#ifdef CONFIG_MEMCG_BROKEN
18786 + struct mem_cgroup *mcg;
18789 + mcg = mem_cgroup_from_task(current);
18790 + rcu_read_unlock();
18794 + // cache = mem_cgroup_stat_read_cache(mcg);
18799 +#endif /* !CONFIG_MEMCG */
18801 diff -NurpP --minimal linux-4.9.76/kernel/vserver/limit_init.h linux-4.9.76-vs2.3.9.5/kernel/vserver/limit_init.h
18802 --- linux-4.9.76/kernel/vserver/limit_init.h 1970-01-01 00:00:00.000000000 +0000
18803 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/limit_init.h 2018-01-10 02:50:49.000000000 +0000
18807 +static inline void vx_info_init_limit(struct _vx_limit *limit)
18811 + for (lim = 0; lim < NUM_LIMITS; lim++) {
18812 + __rlim_soft(limit, lim) = RLIM_INFINITY;
18813 + __rlim_hard(limit, lim) = RLIM_INFINITY;
18814 + __rlim_set(limit, lim, 0);
18815 + atomic_set(&__rlim_lhit(limit, lim), 0);
18816 + __rlim_rmin(limit, lim) = 0;
18817 + __rlim_rmax(limit, lim) = 0;
18821 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
18826 + for (lim = 0; lim < NUM_LIMITS; lim++) {
18827 + if ((1 << lim) & VLIM_NOCHECK)
18829 + value = __rlim_get(limit, lim);
18830 + vxwprintk_xid(value,
18831 + "!!! limit: %p[%s,%d] = %ld on exit.",
18832 + limit, vlimit_name[lim], lim, (long)value);
18836 diff -NurpP --minimal linux-4.9.76/kernel/vserver/limit_proc.h linux-4.9.76-vs2.3.9.5/kernel/vserver/limit_proc.h
18837 --- linux-4.9.76/kernel/vserver/limit_proc.h 1970-01-01 00:00:00.000000000 +0000
18838 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/limit_proc.h 2018-01-10 02:50:49.000000000 +0000
18840 +#ifndef _VX_LIMIT_PROC_H
18841 +#define _VX_LIMIT_PROC_H
18843 +#include <linux/vserver/limit_int.h>
18846 +#define VX_LIMIT_FMT ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
18847 +#define VX_LIMIT_TOP \
18848 + "Limit\t current\t min/max\t\t soft/hard\t\thits\n"
18850 +#define VX_LIMIT_ARG(r) \
18851 + (unsigned long)__rlim_get(limit, r), \
18852 + (unsigned long)__rlim_rmin(limit, r), \
18853 + (unsigned long)__rlim_rmax(limit, r), \
18854 + VX_VLIM(__rlim_soft(limit, r)), \
18855 + VX_VLIM(__rlim_hard(limit, r)), \
18856 + atomic_read(&__rlim_lhit(limit, r))
18858 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
18860 + vx_limit_fixup(limit, -1);
18861 + return sprintf(buffer, VX_LIMIT_TOP
18862 + "PROC" VX_LIMIT_FMT
18863 + "VM" VX_LIMIT_FMT
18864 + "VML" VX_LIMIT_FMT
18865 + "RSS" VX_LIMIT_FMT
18866 + "ANON" VX_LIMIT_FMT
18867 + "RMAP" VX_LIMIT_FMT
18868 + "FILES" VX_LIMIT_FMT
18869 + "OFD" VX_LIMIT_FMT
18870 + "LOCKS" VX_LIMIT_FMT
18871 + "SOCK" VX_LIMIT_FMT
18872 + "MSGQ" VX_LIMIT_FMT
18873 + "SHM" VX_LIMIT_FMT
18874 + "SEMA" VX_LIMIT_FMT
18875 + "SEMS" VX_LIMIT_FMT
18876 + "DENT" VX_LIMIT_FMT,
18877 + VX_LIMIT_ARG(RLIMIT_NPROC),
18878 + VX_LIMIT_ARG(RLIMIT_AS),
18879 + VX_LIMIT_ARG(RLIMIT_MEMLOCK),
18880 + VX_LIMIT_ARG(RLIMIT_RSS),
18881 + VX_LIMIT_ARG(VLIMIT_ANON),
18882 + VX_LIMIT_ARG(VLIMIT_MAPPED),
18883 + VX_LIMIT_ARG(RLIMIT_NOFILE),
18884 + VX_LIMIT_ARG(VLIMIT_OPENFD),
18885 + VX_LIMIT_ARG(RLIMIT_LOCKS),
18886 + VX_LIMIT_ARG(VLIMIT_NSOCK),
18887 + VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
18888 + VX_LIMIT_ARG(VLIMIT_SHMEM),
18889 + VX_LIMIT_ARG(VLIMIT_SEMARY),
18890 + VX_LIMIT_ARG(VLIMIT_NSEMS),
18891 + VX_LIMIT_ARG(VLIMIT_DENTRY));
18894 +#endif /* _VX_LIMIT_PROC_H */
18897 diff -NurpP --minimal linux-4.9.76/kernel/vserver/network.c linux-4.9.76-vs2.3.9.5/kernel/vserver/network.c
18898 --- linux-4.9.76/kernel/vserver/network.c 1970-01-01 00:00:00.000000000 +0000
18899 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/network.c 2018-01-10 02:50:49.000000000 +0000
18902 + * linux/kernel/vserver/network.c
18904 + * Virtual Server: Network Support
18906 + * Copyright (C) 2003-2007 Herbert P?tzl
18908 + * V0.01 broken out from vcontext V0.05
18909 + * V0.02 cleaned up implementation
18910 + * V0.03 added equiv nx commands
18911 + * V0.04 switch to RCU based hash
18912 + * V0.05 and back to locking again
18913 + * V0.06 changed vcmds to nxi arg
18914 + * V0.07 have __create claim() the nxi
18918 +#include <linux/err.h>
18919 +#include <linux/slab.h>
18920 +#include <linux/rcupdate.h>
18921 +#include <net/ipv6.h>
18923 +#include <linux/vs_network.h>
18924 +#include <linux/vs_pid.h>
18925 +#include <linux/vserver/network_cmd.h>
18928 +atomic_t nx_global_ctotal = ATOMIC_INIT(0);
18929 +atomic_t nx_global_cactive = ATOMIC_INIT(0);
18931 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
18932 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
18935 +static int __init init_network(void)
18937 + nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
18938 + sizeof(struct nx_addr_v4), 0,
18939 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18940 + nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
18941 + sizeof(struct nx_addr_v6), 0,
18942 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18947 +/* __alloc_nx_addr_v4() */
18949 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
18951 + struct nx_addr_v4 *nxa = kmem_cache_alloc(
18952 + nx_addr_v4_cachep, GFP_KERNEL);
18954 + if (!IS_ERR(nxa))
18955 + memset(nxa, 0, sizeof(*nxa));
18959 +/* __dealloc_nx_addr_v4() */
18961 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
18963 + kmem_cache_free(nx_addr_v4_cachep, nxa);
18966 +/* __dealloc_nx_addr_v4_all() */
18968 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
18971 + struct nx_addr_v4 *next = nxa->next;
18973 + __dealloc_nx_addr_v4(nxa);
18979 +#ifdef CONFIG_IPV6
18981 +/* __alloc_nx_addr_v6() */
18983 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
18985 + struct nx_addr_v6 *nxa = kmem_cache_alloc(
18986 + nx_addr_v6_cachep, GFP_KERNEL);
18988 + if (!IS_ERR(nxa))
18989 + memset(nxa, 0, sizeof(*nxa));
18993 +/* __dealloc_nx_addr_v6() */
18995 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
18997 + kmem_cache_free(nx_addr_v6_cachep, nxa);
19000 +/* __dealloc_nx_addr_v6_all() */
19002 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19005 + struct nx_addr_v6 *next = nxa->next;
19007 + __dealloc_nx_addr_v6(nxa);
19012 +#endif /* CONFIG_IPV6 */
19014 +/* __alloc_nx_info()
19016 + * allocate an initialized nx_info struct
19017 + * doesn't make it visible (hash) */
19019 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19021 + struct nx_info *new = NULL;
19023 + vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19025 + /* would this benefit from a slab cache? */
19026 + new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19030 + memset(new, 0, sizeof(struct nx_info));
19031 + new->nx_id = nid;
19032 + INIT_HLIST_NODE(&new->nx_hlist);
19033 + atomic_set(&new->nx_usecnt, 0);
19034 + atomic_set(&new->nx_tasks, 0);
19035 + spin_lock_init(&new->addr_lock);
19036 + new->nx_state = 0;
19038 + new->nx_flags = NXF_INIT_SET;
19040 + /* rest of init goes here */
19042 + new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19043 + new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19045 + vxdprintk(VXD_CBIT(nid, 0),
19046 + "alloc_nx_info(%d) = %p", nid, new);
19047 + atomic_inc(&nx_global_ctotal);
19051 +/* __dealloc_nx_info()
19053 + * final disposal of nx_info */
19055 +static void __dealloc_nx_info(struct nx_info *nxi)
19057 + vxdprintk(VXD_CBIT(nid, 0),
19058 + "dealloc_nx_info(%p)", nxi);
19060 + nxi->nx_hlist.next = LIST_POISON1;
19063 + BUG_ON(atomic_read(&nxi->nx_usecnt));
19064 + BUG_ON(atomic_read(&nxi->nx_tasks));
19066 + __dealloc_nx_addr_v4_all(nxi->v4.next);
19067 +#ifdef CONFIG_IPV6
19068 + __dealloc_nx_addr_v6_all(nxi->v6.next);
19071 + nxi->nx_state |= NXS_RELEASED;
19073 + atomic_dec(&nx_global_ctotal);
19076 +static void __shutdown_nx_info(struct nx_info *nxi)
19078 + nxi->nx_state |= NXS_SHUTDOWN;
19079 + vs_net_change(nxi, VSC_NETDOWN);
19082 +/* exported stuff */
19084 +void free_nx_info(struct nx_info *nxi)
19086 + /* context shutdown is mandatory */
19087 + BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
19089 + /* context must not be hashed */
19090 + BUG_ON(nxi->nx_state & NXS_HASHED);
19092 + BUG_ON(atomic_read(&nxi->nx_usecnt));
19093 + BUG_ON(atomic_read(&nxi->nx_tasks));
19095 + __dealloc_nx_info(nxi);
19099 +void __nx_set_lback(struct nx_info *nxi)
19101 + int nid = nxi->nx_id;
19102 + __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
19104 + nxi->v4_lback.s_addr = lback;
19107 +extern int __nx_inet_add_lback(__be32 addr);
19108 +extern int __nx_inet_del_lback(__be32 addr);
19111 +/* hash table for nx_info hash */
19113 +#define NX_HASH_SIZE 13
19115 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
19117 +static DEFINE_SPINLOCK(nx_info_hash_lock);
19120 +static inline unsigned int __hashval(vnid_t nid)
19122 + return (nid % NX_HASH_SIZE);
19127 +/* __hash_nx_info()
19129 + * add the nxi to the global hash table
19130 + * requires the hash_lock to be held */
19132 +static inline void __hash_nx_info(struct nx_info *nxi)
19134 + struct hlist_head *head;
19136 + vxd_assert_lock(&nx_info_hash_lock);
19137 + vxdprintk(VXD_CBIT(nid, 4),
19138 + "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
19140 + /* context must not be hashed */
19141 + BUG_ON(nx_info_state(nxi, NXS_HASHED));
19143 + nxi->nx_state |= NXS_HASHED;
19144 + head = &nx_info_hash[__hashval(nxi->nx_id)];
19145 + hlist_add_head(&nxi->nx_hlist, head);
19146 + atomic_inc(&nx_global_cactive);
19149 +/* __unhash_nx_info()
19151 + * remove the nxi from the global hash table
19152 + * requires the hash_lock to be held */
19154 +static inline void __unhash_nx_info(struct nx_info *nxi)
19156 + vxd_assert_lock(&nx_info_hash_lock);
19157 + vxdprintk(VXD_CBIT(nid, 4),
19158 + "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
19159 + atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
19161 + /* context must be hashed */
19162 + BUG_ON(!nx_info_state(nxi, NXS_HASHED));
19163 + /* but without tasks */
19164 + BUG_ON(atomic_read(&nxi->nx_tasks));
19166 + nxi->nx_state &= ~NXS_HASHED;
19167 + hlist_del(&nxi->nx_hlist);
19168 + atomic_dec(&nx_global_cactive);
19172 +/* __lookup_nx_info()
19174 + * requires the hash_lock to be held
19175 + * doesn't increment the nx_refcnt */
19177 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
19179 + struct hlist_head *head = &nx_info_hash[__hashval(nid)];
19180 + struct hlist_node *pos;
19181 + struct nx_info *nxi;
19183 + vxd_assert_lock(&nx_info_hash_lock);
19184 + hlist_for_each(pos, head) {
19185 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19187 + if (nxi->nx_id == nid)
19192 + vxdprintk(VXD_CBIT(nid, 0),
19193 + "__lookup_nx_info(#%u): %p[#%u]",
19194 + nid, nxi, nxi ? nxi->nx_id : 0);
19199 +/* __create_nx_info()
19201 + * create the requested context
19202 + * get(), claim() and hash it */
19204 +static struct nx_info *__create_nx_info(int id)
19206 + struct nx_info *new, *nxi = NULL;
19208 + vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
19210 + if (!(new = __alloc_nx_info(id)))
19211 + return ERR_PTR(-ENOMEM);
19213 + /* required to make dynamic xids unique */
19214 + spin_lock(&nx_info_hash_lock);
19216 + /* static context requested */
19217 + if ((nxi = __lookup_nx_info(id))) {
19218 + vxdprintk(VXD_CBIT(nid, 0),
19219 + "create_nx_info(%d) = %p (already there)", id, nxi);
19220 + if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19221 + nxi = ERR_PTR(-EBUSY);
19223 + nxi = ERR_PTR(-EEXIST);
19226 + /* new context */
19227 + vxdprintk(VXD_CBIT(nid, 0),
19228 + "create_nx_info(%d) = %p (new)", id, new);
19229 + claim_nx_info(new, NULL);
19230 + __nx_set_lback(new);
19231 + __hash_nx_info(get_nx_info(new));
19232 + nxi = new, new = NULL;
19235 + spin_unlock(&nx_info_hash_lock);
19237 + __dealloc_nx_info(new);
19243 +/* exported stuff */
19246 +void unhash_nx_info(struct nx_info *nxi)
19248 + __shutdown_nx_info(nxi);
19249 + spin_lock(&nx_info_hash_lock);
19250 + __unhash_nx_info(nxi);
19251 + spin_unlock(&nx_info_hash_lock);
19254 +/* lookup_nx_info()
19256 + * search for a nx_info and get() it
19257 + * negative id means current */
19259 +struct nx_info *lookup_nx_info(int id)
19261 + struct nx_info *nxi = NULL;
19264 + nxi = get_nx_info(current_nx_info());
19265 + } else if (id > 1) {
19266 + spin_lock(&nx_info_hash_lock);
19267 + nxi = get_nx_info(__lookup_nx_info(id));
19268 + spin_unlock(&nx_info_hash_lock);
19273 +/* nid_is_hashed()
19275 + * verify that nid is still hashed */
19277 +int nid_is_hashed(vnid_t nid)
19281 + spin_lock(&nx_info_hash_lock);
19282 + hashed = (__lookup_nx_info(nid) != NULL);
19283 + spin_unlock(&nx_info_hash_lock);
19288 +#ifdef CONFIG_PROC_FS
19292 + * get a subset of hashed nids for proc
19293 + * assumes size is at least one */
19295 +int get_nid_list(int index, unsigned int *nids, int size)
19297 + int hindex, nr_nids = 0;
19299 + /* only show current and children */
19300 + if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
19303 + nids[nr_nids] = nx_current_nid();
19307 + for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
19308 + struct hlist_head *head = &nx_info_hash[hindex];
19309 + struct hlist_node *pos;
19311 + spin_lock(&nx_info_hash_lock);
19312 + hlist_for_each(pos, head) {
19313 + struct nx_info *nxi;
19318 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19319 + nids[nr_nids] = nxi->nx_id;
19320 + if (++nr_nids >= size) {
19321 + spin_unlock(&nx_info_hash_lock);
19325 + /* keep the lock time short */
19326 + spin_unlock(&nx_info_hash_lock);
19335 + * migrate task to new network
19336 + * gets nxi, puts old_nxi on change
19339 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
19341 + struct nx_info *old_nxi;
19347 + vxdprintk(VXD_CBIT(nid, 5),
19348 + "nx_migrate_task(%p,%p[#%d.%d.%d])",
19349 + p, nxi, nxi->nx_id,
19350 + atomic_read(&nxi->nx_usecnt),
19351 + atomic_read(&nxi->nx_tasks));
19353 + if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
19354 + !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19357 + if (nx_info_state(nxi, NXS_SHUTDOWN))
19360 + /* maybe disallow this completely? */
19361 + old_nxi = task_get_nx_info(p);
19362 + if (old_nxi == nxi)
19367 + clr_nx_info(&p->nx_info);
19368 + claim_nx_info(nxi, p);
19369 + set_nx_info(&p->nx_info, nxi);
19370 + p->nid = nxi->nx_id;
19373 + vxdprintk(VXD_CBIT(nid, 5),
19374 + "moved task %p into nxi:%p[#%d]",
19375 + p, nxi, nxi->nx_id);
19378 + release_nx_info(old_nxi, p);
19381 + put_nx_info(old_nxi);
19386 +void nx_set_persistent(struct nx_info *nxi)
19388 + vxdprintk(VXD_CBIT(nid, 6),
19389 + "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
19391 + get_nx_info(nxi);
19392 + claim_nx_info(nxi, NULL);
19395 +void nx_clear_persistent(struct nx_info *nxi)
19397 + vxdprintk(VXD_CBIT(nid, 6),
19398 + "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
19400 + release_nx_info(nxi, NULL);
19401 + put_nx_info(nxi);
19404 +void nx_update_persistent(struct nx_info *nxi)
19406 + if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
19407 + nx_set_persistent(nxi);
19409 + nx_clear_persistent(nxi);
19412 +/* vserver syscall commands below here */
19414 +/* taks nid and nx_info functions */
19416 +#include <asm/uaccess.h>
19419 +int vc_task_nid(uint32_t id)
19424 + struct task_struct *tsk;
19427 + tsk = find_task_by_real_pid(id);
19428 + nid = (tsk) ? tsk->nid : -ESRCH;
19429 + rcu_read_unlock();
19431 + nid = nx_current_nid();
19436 +int vc_nx_info(struct nx_info *nxi, void __user *data)
19438 + struct vcmd_nx_info_v0 vc_data;
19440 + vc_data.nid = nxi->nx_id;
19442 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19448 +/* network functions */
19450 +int vc_net_create(uint32_t nid, void __user *data)
19452 + struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
19453 + struct nx_info *new_nxi;
19456 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19459 + if ((nid > MAX_S_CONTEXT) || (nid < 2))
19462 + new_nxi = __create_nx_info(nid);
19463 + if (IS_ERR(new_nxi))
19464 + return PTR_ERR(new_nxi);
19466 + /* initial flags */
19467 + new_nxi->nx_flags = vc_data.flagword;
19470 + if (vs_net_change(new_nxi, VSC_NETUP))
19473 + ret = nx_migrate_task(current, new_nxi);
19477 + /* return context id on success */
19478 + ret = new_nxi->nx_id;
19480 + /* get a reference for persistent contexts */
19481 + if ((vc_data.flagword & NXF_PERSISTENT))
19482 + nx_set_persistent(new_nxi);
19484 + release_nx_info(new_nxi, NULL);
19485 + put_nx_info(new_nxi);
19490 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
19492 + return nx_migrate_task(current, nxi);
19497 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
19498 + __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
19499 + struct nx_addr_v4 **prev)
19501 + struct nx_addr_v4 *nxa = &nxi->v4;
19503 + for (; nxa; nxa = nxa->next) {
19504 + if ((nxa->ip[0].s_addr == ip) &&
19505 + (nxa->ip[1].s_addr == ip2) &&
19506 + (nxa->mask.s_addr == mask) &&
19507 + (nxa->type == type) &&
19508 + (nxa->flags == flags))
19511 + /* save previous entry */
19518 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19519 + uint16_t type, uint16_t flags)
19521 + struct nx_addr_v4 *nxa = NULL;
19522 + struct nx_addr_v4 *new = __alloc_nx_addr_v4();
19523 + unsigned long irqflags;
19524 + int ret = -EEXIST;
19527 + return PTR_ERR(new);
19529 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
19530 + if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
19533 + if (NX_IPV4(nxi)) {
19538 + /* remove single ip for ip list */
19539 + nxi->nx_flags &= ~NXF_SINGLE_IP;
19542 + nxa->ip[0].s_addr = ip;
19543 + nxa->ip[1].s_addr = ip2;
19544 + nxa->mask.s_addr = mask;
19545 + nxa->type = type;
19546 + nxa->flags = flags;
19549 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19551 + __dealloc_nx_addr_v4(new);
19555 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19556 + uint16_t type, uint16_t flags)
19558 + struct nx_addr_v4 *nxa = NULL;
19559 + struct nx_addr_v4 *old = NULL;
19560 + unsigned long irqflags;
19563 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
19565 + case NXA_TYPE_ADDR:
19566 + old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
19569 + nxa->next = old->next;
19570 + old->next = NULL;
19576 + old->next = NULL;
19578 + memset(old, 0, sizeof(*old));
19586 + case NXA_TYPE_ANY:
19589 + memset(nxa, 0, sizeof(*nxa));
19595 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19596 + __dealloc_nx_addr_v4_all(old);
19601 +int vc_net_add(struct nx_info *nxi, void __user *data)
19603 + struct vcmd_net_addr_v0 vc_data;
19604 + int index, ret = 0;
19606 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19609 + switch (vc_data.type) {
19610 + case NXA_TYPE_IPV4:
19611 + if ((vc_data.count < 1) || (vc_data.count > 4))
19615 + while (index < vc_data.count) {
19616 + ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
19617 + vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
19625 + case NXA_TYPE_IPV4|NXA_MOD_BCAST:
19626 + nxi->v4_bcast = vc_data.ip[0];
19630 + case NXA_TYPE_IPV4|NXA_MOD_LBACK:
19631 + nxi->v4_lback = vc_data.ip[0];
19642 +int vc_net_remove(struct nx_info *nxi, void __user *data)
19644 + struct vcmd_net_addr_v0 vc_data;
19646 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19649 + switch (vc_data.type) {
19650 + case NXA_TYPE_ANY:
19651 + return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
19659 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
19661 + struct vcmd_net_addr_ipv4_v1 vc_data;
19663 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19666 + switch (vc_data.type) {
19667 + case NXA_TYPE_ADDR:
19668 + case NXA_TYPE_MASK:
19669 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
19670 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19672 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19673 + nxi->v4_bcast = vc_data.ip;
19676 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19677 + nxi->v4_lback = vc_data.ip;
19686 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
19688 + struct vcmd_net_addr_ipv4_v2 vc_data;
19690 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19693 + switch (vc_data.type) {
19694 + case NXA_TYPE_ADDR:
19695 + case NXA_TYPE_MASK:
19696 + case NXA_TYPE_RANGE:
19697 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19698 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19700 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19701 + nxi->v4_bcast = vc_data.ip;
19704 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19705 + nxi->v4_lback = vc_data.ip;
19714 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
19716 + struct vcmd_net_addr_ipv4_v1 vc_data;
19718 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19721 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
19722 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19725 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
19727 + struct vcmd_net_addr_ipv4_v2 vc_data;
19729 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19732 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19733 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19736 +#ifdef CONFIG_IPV6
19739 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
19740 + struct in6_addr *ip, struct in6_addr *mask,
19741 + uint32_t prefix, uint16_t type, uint16_t flags,
19742 + struct nx_addr_v6 **prev)
19744 + struct nx_addr_v6 *nxa = &nxi->v6;
19746 + for (; nxa; nxa = nxa->next) {
19747 + if (ipv6_addr_equal(&nxa->ip, ip) &&
19748 + ipv6_addr_equal(&nxa->mask, mask) &&
19749 + (nxa->prefix == prefix) &&
19750 + (nxa->type == type) &&
19751 + (nxa->flags == flags))
19754 + /* save previous entry */
19762 +int do_add_v6_addr(struct nx_info *nxi,
19763 + struct in6_addr *ip, struct in6_addr *mask,
19764 + uint32_t prefix, uint16_t type, uint16_t flags)
19766 + struct nx_addr_v6 *nxa = NULL;
19767 + struct nx_addr_v6 *new = __alloc_nx_addr_v6();
19768 + unsigned long irqflags;
19769 + int ret = -EEXIST;
19772 + return PTR_ERR(new);
19774 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
19775 + if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
19778 + if (NX_IPV6(nxi)) {
19785 + nxa->mask = *mask;
19786 + nxa->prefix = prefix;
19787 + nxa->type = type;
19788 + nxa->flags = flags;
19791 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19793 + __dealloc_nx_addr_v6(new);
19797 +int do_remove_v6_addr(struct nx_info *nxi,
19798 + struct in6_addr *ip, struct in6_addr *mask,
19799 + uint32_t prefix, uint16_t type, uint16_t flags)
19801 + struct nx_addr_v6 *nxa = NULL;
19802 + struct nx_addr_v6 *old = NULL;
19803 + unsigned long irqflags;
19806 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
19808 + case NXA_TYPE_ADDR:
19809 + old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
19812 + nxa->next = old->next;
19813 + old->next = NULL;
19819 + old->next = NULL;
19821 + memset(old, 0, sizeof(*old));
19829 + case NXA_TYPE_ANY:
19832 + memset(nxa, 0, sizeof(*nxa));
19838 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19839 + __dealloc_nx_addr_v6_all(old);
19843 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
19845 + struct vcmd_net_addr_ipv6_v1 vc_data;
19847 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19850 + switch (vc_data.type) {
19851 + case NXA_TYPE_ADDR:
19852 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
19853 + /* fallthrough */
19854 + case NXA_TYPE_MASK:
19855 + return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
19856 + vc_data.prefix, vc_data.type, vc_data.flags);
19863 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
19865 + struct vcmd_net_addr_ipv6_v1 vc_data;
19867 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19870 + switch (vc_data.type) {
19871 + case NXA_TYPE_ADDR:
19872 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
19873 + /* fallthrough */
19874 + case NXA_TYPE_MASK:
19875 + return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
19876 + vc_data.prefix, vc_data.type, vc_data.flags);
19877 + case NXA_TYPE_ANY:
19878 + return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
19885 +#endif /* CONFIG_IPV6 */
19888 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
19890 + struct vcmd_net_flags_v0 vc_data;
19892 + vc_data.flagword = nxi->nx_flags;
19894 + /* special STATE flag handling */
19895 + vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
19897 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19902 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
19904 + struct vcmd_net_flags_v0 vc_data;
19905 + uint64_t mask, trigger;
19907 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19910 + /* special STATE flag handling */
19911 + mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
19912 + trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
19914 + nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
19915 + vc_data.flagword, mask);
19916 + if (trigger & NXF_PERSISTENT)
19917 + nx_update_persistent(nxi);
19922 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
19924 + struct vcmd_net_caps_v0 vc_data;
19926 + vc_data.ncaps = nxi->nx_ncaps;
19927 + vc_data.cmask = ~0ULL;
19929 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19934 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
19936 + struct vcmd_net_caps_v0 vc_data;
19938 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19941 + nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
19942 + vc_data.ncaps, vc_data.cmask);
19947 +#include <linux/module.h>
19949 +module_init(init_network);
19951 +EXPORT_SYMBOL_GPL(free_nx_info);
19952 +EXPORT_SYMBOL_GPL(unhash_nx_info);
19954 diff -NurpP --minimal linux-4.9.76/kernel/vserver/proc.c linux-4.9.76-vs2.3.9.5/kernel/vserver/proc.c
19955 --- linux-4.9.76/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
19956 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/proc.c 2018-01-13 04:17:12.000000000 +0000
19959 + * linux/kernel/vserver/proc.c
19961 + * Virtual Context Support
19963 + * Copyright (C) 2003-2011 Herbert P?tzl
19965 + * V0.01 basic structure
19966 + * V0.02 adaptation vs1.3.0
19967 + * V0.03 proc permissions
19968 + * V0.04 locking/generic
19969 + * V0.05 next generation procfs
19970 + * V0.06 inode validation
19971 + * V0.07 generic rewrite vid
19972 + * V0.08 remove inode type
19973 + * V0.09 added u/wmask info
19977 +#include <linux/proc_fs.h>
19978 +#include <linux/fs_struct.h>
19979 +#include <linux/mount.h>
19980 +#include <linux/namei.h>
19981 +#include <asm/unistd.h>
19983 +#include <linux/vs_context.h>
19984 +#include <linux/vs_network.h>
19985 +#include <linux/vs_cvirt.h>
19987 +#include <linux/in.h>
19988 +#include <linux/inetdevice.h>
19989 +#include <linux/vs_inet.h>
19990 +#include <linux/vs_inet6.h>
19992 +#include <linux/vserver/global.h>
19994 +#include "cvirt_proc.h"
19995 +#include "cacct_proc.h"
19996 +#include "limit_proc.h"
19997 +#include "sched_proc.h"
19998 +#include "vci_config.h"
20000 +#include <../../fs/proc/internal.h>
20003 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20007 + CAP_FOR_EACH_U32(__capi) {
20008 + buffer += sprintf(buffer, "%08x",
20009 + c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20015 +static struct proc_dir_entry *proc_virtual;
20017 +static struct proc_dir_entry *proc_virtnet;
20020 +/* first the actual feeds */
20023 +static int proc_vci(char *buffer)
20025 + return sprintf(buffer,
20026 + "VCIVersion:\t%04x:%04x\n"
20027 + "VCISyscall:\t%d\n"
20028 + "VCIKernel:\t%08x\n",
20029 + VCI_VERSION >> 16,
20030 + VCI_VERSION & 0xFFFF,
20032 + vci_kernel_config());
20035 +static int proc_virtual_info(char *buffer)
20037 + return proc_vci(buffer);
20040 +static int proc_virtual_status(char *buffer)
20042 + return sprintf(buffer,
20044 + "#CActive:\t%d\n"
20045 + "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20046 + "#InitTask:\t%d\t%d %d\n",
20047 + atomic_read(&vx_global_ctotal),
20048 + atomic_read(&vx_global_cactive),
20049 + atomic_read(&vs_global_nsproxy),
20050 + atomic_read(&vs_global_fs),
20051 + atomic_read(&vs_global_mnt_ns),
20052 + atomic_read(&vs_global_uts_ns),
20053 + atomic_read(&vs_global_ipc_ns),
20054 + atomic_read(&vs_global_user_ns),
20055 + atomic_read(&vs_global_pid_ns),
20056 + atomic_read(&init_task.usage),
20057 + atomic_read(&init_task.nsproxy->count),
20058 + init_task.fs->users);
20062 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20066 + length = sprintf(buffer,
20074 + vxi->vx_badness_bias);
20078 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
20080 + char *orig = buffer;
20082 + buffer += sprintf(buffer,
20085 + "Flags:\t%016llx\n",
20086 + atomic_read(&vxi->vx_usecnt),
20087 + atomic_read(&vxi->vx_tasks),
20088 + (unsigned long long)vxi->vx_flags);
20090 + buffer += sprintf(buffer, "BCaps:\t");
20091 + buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20092 + buffer += sprintf(buffer, "\n");
20094 + buffer += sprintf(buffer,
20095 + "CCaps:\t%016llx\n"
20096 + "Umask:\t%16llx\n"
20097 + "Wmask:\t%16llx\n"
20098 + "Spaces:\t%08lx %08lx\n",
20099 + (unsigned long long)vxi->vx_ccaps,
20100 + (unsigned long long)vxi->vx_umask,
20101 + (unsigned long long)vxi->vx_wmask,
20102 + vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20103 + return buffer - orig;
20106 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20108 + return vx_info_proc_limit(&vxi->limit, buffer);
20111 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20115 + length = vx_info_proc_sched(&vxi->sched, buffer);
20116 + for_each_online_cpu(cpu) {
20117 + length += vx_info_proc_sched_pc(
20118 + &vx_per_cpu(vxi, sched_pc, cpu),
20119 + buffer + length, cpu);
20124 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20126 + return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20129 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20131 + return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20134 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20138 + vx_update_load(vxi);
20139 + length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20140 + for_each_online_cpu(cpu) {
20141 + length += vx_info_proc_cvirt_pc(
20142 + &vx_per_cpu(vxi, cvirt_pc, cpu),
20143 + buffer + length, cpu);
20148 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20150 + return vx_info_proc_cacct(&vxi->cacct, buffer);
20154 +static int proc_virtnet_info(char *buffer)
20156 + return proc_vci(buffer);
20159 +static int proc_virtnet_status(char *buffer)
20161 + return sprintf(buffer,
20163 + "#CActive:\t%d\n",
20164 + atomic_read(&nx_global_ctotal),
20165 + atomic_read(&nx_global_cactive));
20168 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
20170 + struct nx_addr_v4 *v4a;
20171 +#ifdef CONFIG_IPV6
20172 + struct nx_addr_v6 *v6a;
20176 + length = sprintf(buffer,
20179 + "Bcast:\t" NIPQUAD_FMT "\n"
20180 + "Lback:\t" NIPQUAD_FMT "\n",
20183 + NIPQUAD(nxi->v4_bcast.s_addr),
20184 + NIPQUAD(nxi->v4_lback.s_addr));
20186 + if (!NX_IPV4(nxi))
20188 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20189 + length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20192 +#ifdef CONFIG_IPV6
20193 + if (!NX_IPV6(nxi))
20195 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20196 + length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
20203 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
20207 + length = sprintf(buffer,
20210 + "Flags:\t%016llx\n"
20211 + "NCaps:\t%016llx\n",
20212 + atomic_read(&nxi->nx_usecnt),
20213 + atomic_read(&nxi->nx_tasks),
20214 + (unsigned long long)nxi->nx_flags,
20215 + (unsigned long long)nxi->nx_ncaps);
20221 +/* here the inode helpers */
20227 + struct inode_operations *iop;
20228 + struct file_operations *fop;
20229 + union proc_op op;
20232 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
20234 + struct inode *inode = new_inode(sb);
20239 + inode->i_mode = p->mode;
20241 + inode->i_op = p->iop;
20243 + inode->i_fop = p->fop;
20245 + set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
20246 + inode->i_flags |= S_IMMUTABLE;
20248 + inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
20250 + i_uid_write(inode, 0);
20251 + i_gid_write(inode, 0);
20252 + i_tag_write(inode, 0);
20257 +static struct dentry *vs_proc_instantiate(struct inode *dir,
20258 + struct dentry *dentry, int id, void *ptr)
20260 + struct vs_entry *p = ptr;
20261 + struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
20262 + struct dentry *error = ERR_PTR(-EINVAL);
20267 + PROC_I(inode)->op = p->op;
20268 + PROC_I(inode)->fd = id;
20269 + d_add(dentry, inode);
20277 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
20281 + * Fill a directory entry.
20283 + * If possible create the dcache entry and derive our inode number and
20284 + * file type from dcache entry.
20286 + * Since all of the proc inode numbers are dynamically generated, the inode
20287 + * numbers do not exist until the inode is cache. This means creating the
20288 + * the dcache entry in iterate is necessary to keep the inode numbers
20289 + * reported by iterate in sync with the inode numbers reported
20292 +static int vx_proc_fill_cache(struct file *filp, struct dir_context *ctx,
20293 + char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
20295 + struct dentry *child, *dir = filp->f_path.dentry;
20296 + struct inode *inode;
20297 + struct qstr qname;
20299 + unsigned type = DT_UNKNOWN;
20301 + qname.name = name;
20303 + qname.hash = full_name_hash(NULL, name, len);
20305 + child = d_lookup(dir, &qname);
20307 + struct dentry *new;
20308 + new = d_alloc(dir, &qname);
20310 + child = instantiate(dir->d_inode, new, id, ptr);
20317 + if (!child || IS_ERR(child) || !child->d_inode)
20318 + goto end_instantiate;
20319 + inode = child->d_inode;
20321 + ino = inode->i_ino;
20322 + type = inode->i_mode >> 12;
20328 + return !dir_emit(ctx, name, len, ino, type);
20333 +/* get and revalidate vx_info/xid */
20336 +struct vx_info *get_proc_vx_info(struct inode *inode)
20338 + return lookup_vx_info(PROC_I(inode)->fd);
20341 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
20343 + struct inode *inode = dentry->d_inode;
20344 + vxid_t xid = PROC_I(inode)->fd;
20346 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20349 + if (!xid || xid_is_hashed(xid))
20356 +/* get and revalidate nx_info/nid */
20358 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
20360 + struct inode *inode = dentry->d_inode;
20361 + vnid_t nid = PROC_I(inode)->fd;
20363 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20366 + if (!nid || nid_is_hashed(nid))
20374 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
20376 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
20377 + size_t count, loff_t *ppos)
20379 + struct inode *inode = file->f_path.dentry->d_inode;
20380 + unsigned long page;
20381 + ssize_t length = 0;
20383 + if (count > PROC_BLOCK_SIZE)
20384 + count = PROC_BLOCK_SIZE;
20386 + /* fade that out as soon as stable */
20387 + WARN_ON(PROC_I(inode)->fd);
20389 + if (!(page = __get_free_page(GFP_KERNEL)))
20392 + BUG_ON(!PROC_I(inode)->op.proc_vs_read);
20393 + length = PROC_I(inode)->op.proc_vs_read((char *)page);
20396 + length = simple_read_from_buffer(buf, count, ppos,
20397 + (char *)page, length);
20403 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
20404 + size_t count, loff_t *ppos)
20406 + struct inode *inode = file->f_path.dentry->d_inode;
20407 + struct vx_info *vxi = NULL;
20408 + vxid_t xid = PROC_I(inode)->fd;
20409 + unsigned long page;
20410 + ssize_t length = 0;
20412 + if (count > PROC_BLOCK_SIZE)
20413 + count = PROC_BLOCK_SIZE;
20415 + /* fade that out as soon as stable */
20417 + vxi = lookup_vx_info(xid);
20421 + length = -ENOMEM;
20422 + if (!(page = __get_free_page(GFP_KERNEL)))
20425 + BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
20426 + length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
20429 + length = simple_read_from_buffer(buf, count, ppos,
20430 + (char *)page, length);
20434 + put_vx_info(vxi);
20439 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
20440 + size_t count, loff_t *ppos)
20442 + struct inode *inode = file->f_path.dentry->d_inode;
20443 + struct nx_info *nxi = NULL;
20444 + vnid_t nid = PROC_I(inode)->fd;
20445 + unsigned long page;
20446 + ssize_t length = 0;
20448 + if (count > PROC_BLOCK_SIZE)
20449 + count = PROC_BLOCK_SIZE;
20451 + /* fade that out as soon as stable */
20453 + nxi = lookup_nx_info(nid);
20457 + length = -ENOMEM;
20458 + if (!(page = __get_free_page(GFP_KERNEL)))
20461 + BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
20462 + length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
20465 + length = simple_read_from_buffer(buf, count, ppos,
20466 + (char *)page, length);
20470 + put_nx_info(nxi);
20477 +/* here comes the lower level */
20480 +#define NOD(NAME, MODE, IOP, FOP, OP) { \
20481 + .len = sizeof(NAME) - 1, \
20482 + .name = (NAME), \
20490 +#define DIR(NAME, MODE, OTYPE) \
20491 + NOD(NAME, (S_IFDIR | (MODE)), \
20492 + &proc_ ## OTYPE ## _inode_operations, \
20493 + &proc_ ## OTYPE ## _file_operations, { } )
20495 +#define INF(NAME, MODE, OTYPE) \
20496 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
20497 + &proc_vs_info_file_operations, \
20498 + { .proc_vs_read = &proc_##OTYPE } )
20500 +#define VINF(NAME, MODE, OTYPE) \
20501 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
20502 + &proc_vx_info_file_operations, \
20503 + { .proc_vxi_read = &proc_##OTYPE } )
20505 +#define NINF(NAME, MODE, OTYPE) \
20506 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
20507 + &proc_nx_info_file_operations, \
20508 + { .proc_nxi_read = &proc_##OTYPE } )
20511 +static struct file_operations proc_vs_info_file_operations = {
20512 + .read = proc_vs_info_read,
20515 +static struct file_operations proc_vx_info_file_operations = {
20516 + .read = proc_vx_info_read,
20519 +static struct dentry_operations proc_xid_dentry_operations = {
20520 + .d_revalidate = proc_xid_revalidate,
20523 +static struct vs_entry vx_base_stuff[] = {
20524 + VINF("info", S_IRUGO, vxi_info),
20525 + VINF("status", S_IRUGO, vxi_status),
20526 + VINF("limit", S_IRUGO, vxi_limit),
20527 + VINF("sched", S_IRUGO, vxi_sched),
20528 + VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
20529 + VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
20530 + VINF("cvirt", S_IRUGO, vxi_cvirt),
20531 + VINF("cacct", S_IRUGO, vxi_cacct),
20538 +static struct dentry *proc_xid_instantiate(struct inode *dir,
20539 + struct dentry *dentry, int id, void *ptr)
20541 + dentry->d_op = &proc_xid_dentry_operations;
20542 + return vs_proc_instantiate(dir, dentry, id, ptr);
20545 +static struct dentry *proc_xid_lookup(struct inode *dir,
20546 + struct dentry *dentry, unsigned int flags)
20548 + struct vs_entry *p = vx_base_stuff;
20549 + struct dentry *error = ERR_PTR(-ENOENT);
20551 + for (; p->name; p++) {
20552 + if (p->len != dentry->d_name.len)
20554 + if (!memcmp(dentry->d_name.name, p->name, p->len))
20560 + error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20565 +static int proc_xid_iterate(struct file *filp, struct dir_context *ctx)
20567 + struct dentry *dentry = filp->f_path.dentry;
20568 + struct inode *inode = dentry->d_inode;
20569 + struct vs_entry *p = vx_base_stuff;
20570 + int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
20573 + if (!dir_emit_dots(filp, ctx))
20576 + index = ctx->pos - 2;
20577 + if (index < size) {
20578 + for (p += index; p->name; p++) {
20579 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20580 + vs_proc_instantiate, PROC_I(inode)->fd, p))
20590 +static struct file_operations proc_nx_info_file_operations = {
20591 + .read = proc_nx_info_read,
20594 +static struct dentry_operations proc_nid_dentry_operations = {
20595 + .d_revalidate = proc_nid_revalidate,
20598 +static struct vs_entry nx_base_stuff[] = {
20599 + NINF("info", S_IRUGO, nxi_info),
20600 + NINF("status", S_IRUGO, nxi_status),
20605 +static struct dentry *proc_nid_instantiate(struct inode *dir,
20606 + struct dentry *dentry, int id, void *ptr)
20608 + dentry->d_op = &proc_nid_dentry_operations;
20609 + return vs_proc_instantiate(dir, dentry, id, ptr);
20612 +static struct dentry *proc_nid_lookup(struct inode *dir,
20613 + struct dentry *dentry, unsigned int flags)
20615 + struct vs_entry *p = nx_base_stuff;
20616 + struct dentry *error = ERR_PTR(-ENOENT);
20618 + for (; p->name; p++) {
20619 + if (p->len != dentry->d_name.len)
20621 + if (!memcmp(dentry->d_name.name, p->name, p->len))
20627 + error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20632 +static int proc_nid_iterate(struct file *filp, struct dir_context *ctx)
20634 + struct dentry *dentry = filp->f_path.dentry;
20635 + struct inode *inode = dentry->d_inode;
20636 + struct vs_entry *p = nx_base_stuff;
20637 + int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
20640 + if (!dir_emit_dots(filp, ctx))
20643 + index = ctx->pos - 2;
20644 + if (index < size) {
20645 + for (p += index; p->name; p++) {
20646 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20647 + vs_proc_instantiate, PROC_I(inode)->fd, p))
20656 +#define MAX_MULBY10 ((~0U - 9) / 10)
20658 +static inline int atovid(const char *str, int len)
20663 + while (len-- > 0) {
20668 + if (vid >= MAX_MULBY10)
20678 +/* now the upper level (virtual) */
20681 +static struct file_operations proc_xid_file_operations = {
20682 + .read = generic_read_dir,
20683 + .iterate = proc_xid_iterate,
20686 +static struct inode_operations proc_xid_inode_operations = {
20687 + .lookup = proc_xid_lookup,
20690 +static struct vs_entry vx_virtual_stuff[] = {
20691 + INF("info", S_IRUGO, virtual_info),
20692 + INF("status", S_IRUGO, virtual_status),
20693 + DIR(NULL, S_IRUGO | S_IXUGO, xid),
20697 +static struct dentry *proc_virtual_lookup(struct inode *dir,
20698 + struct dentry *dentry, unsigned int flags)
20700 + struct vs_entry *p = vx_virtual_stuff;
20701 + struct dentry *error = ERR_PTR(-ENOENT);
20704 + for (; p->name; p++) {
20705 + if (p->len != dentry->d_name.len)
20707 + if (!memcmp(dentry->d_name.name, p->name, p->len))
20711 + goto instantiate;
20713 + id = atovid(dentry->d_name.name, dentry->d_name.len);
20714 + if ((id < 0) || !xid_is_hashed(id))
20718 + error = proc_xid_instantiate(dir, dentry, id, p);
20723 +static struct file_operations proc_nid_file_operations = {
20724 + .read = generic_read_dir,
20725 + .iterate = proc_nid_iterate,
20728 +static struct inode_operations proc_nid_inode_operations = {
20729 + .lookup = proc_nid_lookup,
20732 +static struct vs_entry nx_virtnet_stuff[] = {
20733 + INF("info", S_IRUGO, virtnet_info),
20734 + INF("status", S_IRUGO, virtnet_status),
20735 + DIR(NULL, S_IRUGO | S_IXUGO, nid),
20739 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
20740 + struct dentry *dentry, unsigned int flags)
20742 + struct vs_entry *p = nx_virtnet_stuff;
20743 + struct dentry *error = ERR_PTR(-ENOENT);
20746 + for (; p->name; p++) {
20747 + if (p->len != dentry->d_name.len)
20749 + if (!memcmp(dentry->d_name.name, p->name, p->len))
20753 + goto instantiate;
20755 + id = atovid(dentry->d_name.name, dentry->d_name.len);
20756 + if ((id < 0) || !nid_is_hashed(id))
20760 + error = proc_nid_instantiate(dir, dentry, id, p);
20766 +#define PROC_MAXVIDS 32
20768 +int proc_virtual_iterate(struct file *filp, struct dir_context *ctx)
20770 + struct vs_entry *p = vx_virtual_stuff;
20771 + int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
20773 + unsigned int xid_array[PROC_MAXVIDS];
20774 + char buf[PROC_NUMBUF];
20775 + unsigned int nr_xids, i;
20777 + if (!dir_emit_dots(filp, ctx))
20780 + index = ctx->pos - 2;
20781 + if (index < size) {
20782 + for (p += index; p->name; p++) {
20783 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20784 + vs_proc_instantiate, 0, p))
20790 + index = ctx->pos - size;
20791 + p = &vx_virtual_stuff[size - 1];
20792 + nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
20793 + for (i = 0; i < nr_xids; i++) {
20794 + int n, xid = xid_array[i];
20795 + unsigned int j = PROC_NUMBUF;
20799 + buf[--j] = '0' + (n % 10);
20802 + if (vx_proc_fill_cache(filp, ctx,
20803 + buf + j, PROC_NUMBUF - j,
20804 + vs_proc_instantiate, xid, p))
20811 +static int proc_virtual_getattr(struct vfsmount *mnt,
20812 + struct dentry *dentry, struct kstat *stat)
20814 + struct inode *inode = dentry->d_inode;
20816 + generic_fillattr(inode, stat);
20817 + stat->nlink = 2 + atomic_read(&vx_global_cactive);
20821 +static struct file_operations proc_virtual_dir_operations = {
20822 + .read = generic_read_dir,
20823 + .iterate = proc_virtual_iterate,
20826 +static struct inode_operations proc_virtual_dir_inode_operations = {
20827 + .getattr = proc_virtual_getattr,
20828 + .lookup = proc_virtual_lookup,
20833 +int proc_virtnet_iterate(struct file *filp, struct dir_context *ctx)
20835 + struct vs_entry *p = nx_virtnet_stuff;
20836 + int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
20838 + unsigned int nid_array[PROC_MAXVIDS];
20839 + char buf[PROC_NUMBUF];
20840 + unsigned int nr_nids, i;
20842 + if (!dir_emit_dots(filp, ctx))
20845 + index = ctx->pos - 2;
20846 + if (index < size) {
20847 + for (p += index; p->name; p++) {
20848 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20849 + vs_proc_instantiate, 0, p))
20855 + index = ctx->pos - size;
20856 + p = &nx_virtnet_stuff[size - 1];
20857 + nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
20858 + for (i = 0; i < nr_nids; i++) {
20859 + int n, nid = nid_array[i];
20860 + unsigned int j = PROC_NUMBUF;
20864 + buf[--j] = '0' + (n % 10);
20867 + if (vx_proc_fill_cache(filp, ctx,
20868 + buf + j, PROC_NUMBUF - j,
20869 + vs_proc_instantiate, nid, p))
20876 +static int proc_virtnet_getattr(struct vfsmount *mnt,
20877 + struct dentry *dentry, struct kstat *stat)
20879 + struct inode *inode = dentry->d_inode;
20881 + generic_fillattr(inode, stat);
20882 + stat->nlink = 2 + atomic_read(&nx_global_cactive);
20886 +static struct file_operations proc_virtnet_dir_operations = {
20887 + .read = generic_read_dir,
20888 + .iterate = proc_virtnet_iterate,
20891 +static struct inode_operations proc_virtnet_dir_inode_operations = {
20892 + .getattr = proc_virtnet_getattr,
20893 + .lookup = proc_virtnet_lookup,
20898 +void proc_vx_init(void)
20900 + struct proc_dir_entry *ent;
20902 + ent = proc_mkdir("virtual", 0);
20904 + ent->proc_fops = &proc_virtual_dir_operations;
20905 + ent->proc_iops = &proc_virtual_dir_inode_operations;
20907 + proc_virtual = ent;
20909 + ent = proc_mkdir("virtnet", 0);
20911 + ent->proc_fops = &proc_virtnet_dir_operations;
20912 + ent->proc_iops = &proc_virtnet_dir_inode_operations;
20914 + proc_virtnet = ent;
20920 +/* per pid info */
20922 +void render_cap_t(struct seq_file *, const char *,
20923 + struct vx_info *, kernel_cap_t *);
20926 +int proc_pid_vx_info(
20927 + struct seq_file *m,
20928 + struct pid_namespace *ns,
20930 + struct task_struct *p)
20932 + struct vx_info *vxi;
20934 + seq_printf(m, "XID:\t%d\n", vx_task_xid(p));
20936 + vxi = task_get_vx_info(p);
20940 + render_cap_t(m, "BCaps:\t", vxi, &vxi->vx_bcaps);
20941 + seq_printf(m, "CCaps:\t%016llx\n",
20942 + (unsigned long long)vxi->vx_ccaps);
20943 + seq_printf(m, "CFlags:\t%016llx\n",
20944 + (unsigned long long)vxi->vx_flags);
20945 + seq_printf(m, "CIPid:\t%d\n", vxi->vx_initpid);
20947 + put_vx_info(vxi);
20952 +int proc_pid_nx_info(
20953 + struct seq_file *m,
20954 + struct pid_namespace *ns,
20956 + struct task_struct *p)
20958 + struct nx_info *nxi;
20959 + struct nx_addr_v4 *v4a;
20960 +#ifdef CONFIG_IPV6
20961 + struct nx_addr_v6 *v6a;
20965 + seq_printf(m, "NID:\t%d\n", nx_task_nid(p));
20967 + nxi = task_get_nx_info(p);
20971 + seq_printf(m, "NCaps:\t%016llx\n",
20972 + (unsigned long long)nxi->nx_ncaps);
20973 + seq_printf(m, "NFlags:\t%016llx\n",
20974 + (unsigned long long)nxi->nx_flags);
20976 + seq_printf(m, "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
20977 + NIPQUAD(nxi->v4_bcast.s_addr));
20978 + seq_printf(m, "V4Root[lback]:\t" NIPQUAD_FMT "\n",
20979 + NIPQUAD(nxi->v4_lback.s_addr));
20980 + if (!NX_IPV4(nxi))
20982 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20983 + seq_printf(m, "V4Root[%d]:\t" NXAV4_FMT "\n",
20986 +#ifdef CONFIG_IPV6
20987 + if (!NX_IPV6(nxi))
20989 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20990 + seq_printf(m, "V6Root[%d]:\t" NXAV6_FMT "\n",
20994 + put_nx_info(nxi);
20998 diff -NurpP --minimal linux-4.9.76/kernel/vserver/sched.c linux-4.9.76-vs2.3.9.5/kernel/vserver/sched.c
20999 --- linux-4.9.76/kernel/vserver/sched.c 1970-01-01 00:00:00.000000000 +0000
21000 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/sched.c 2018-01-10 02:50:49.000000000 +0000
21003 + * linux/kernel/vserver/sched.c
21005 + * Virtual Server: Scheduler Support
21007 + * Copyright (C) 2004-2010 Herbert P?tzl
21009 + * V0.01 adapted Sam Vilains version to 2.6.3
21010 + * V0.02 removed legacy interface
21011 + * V0.03 changed vcmds to vxi arg
21012 + * V0.04 removed older and legacy interfaces
21013 + * V0.05 removed scheduler code/commands
21017 +#include <linux/vs_context.h>
21018 +#include <linux/vs_sched.h>
21019 +#include <linux/cpumask.h>
21020 +#include <linux/vserver/sched_cmd.h>
21022 +#include <asm/uaccess.h>
21025 +void vx_update_sched_param(struct _vx_sched *sched,
21026 + struct _vx_sched_pc *sched_pc)
21028 + sched_pc->prio_bias = sched->prio_bias;
21031 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21035 + if (data->prio_bias > MAX_PRIO_BIAS)
21036 + data->prio_bias = MAX_PRIO_BIAS;
21037 + if (data->prio_bias < MIN_PRIO_BIAS)
21038 + data->prio_bias = MIN_PRIO_BIAS;
21040 + if (data->cpu_id != ~0) {
21041 + vxi->sched.update = *get_cpu_mask(data->cpu_id);
21042 + cpumask_and(&vxi->sched.update, &vxi->sched.update,
21043 + cpu_online_mask);
21045 + cpumask_copy(&vxi->sched.update, cpu_online_mask);
21047 + for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)vxi->sched.update)
21048 + vx_update_sched_param(&vxi->sched,
21049 + &vx_per_cpu(vxi, sched_pc, cpu));
21053 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21055 + struct vcmd_prio_bias vc_data;
21057 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21060 + return do_set_prio_bias(vxi, &vc_data);
21063 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21065 + struct vcmd_prio_bias vc_data;
21066 + struct _vx_sched_pc *pcd;
21069 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21072 + cpu = vc_data.cpu_id;
21074 + if (!cpu_possible(cpu))
21077 + pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21078 + vc_data.prio_bias = pcd->prio_bias;
21080 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21085 diff -NurpP --minimal linux-4.9.76/kernel/vserver/sched_init.h linux-4.9.76-vs2.3.9.5/kernel/vserver/sched_init.h
21086 --- linux-4.9.76/kernel/vserver/sched_init.h 1970-01-01 00:00:00.000000000 +0000
21087 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/sched_init.h 2018-01-10 02:50:49.000000000 +0000
21090 +static inline void vx_info_init_sched(struct _vx_sched *sched)
21092 + /* scheduling; hard code starting values as constants */
21093 + sched->prio_bias = 0;
21097 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21099 + sched_pc->prio_bias = 0;
21101 + sched_pc->user_ticks = 0;
21102 + sched_pc->sys_ticks = 0;
21103 + sched_pc->hold_ticks = 0;
21106 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
21112 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21116 diff -NurpP --minimal linux-4.9.76/kernel/vserver/sched_proc.h linux-4.9.76-vs2.3.9.5/kernel/vserver/sched_proc.h
21117 --- linux-4.9.76/kernel/vserver/sched_proc.h 1970-01-01 00:00:00.000000000 +0000
21118 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/sched_proc.h 2018-01-10 02:50:49.000000000 +0000
21120 +#ifndef _VX_SCHED_PROC_H
21121 +#define _VX_SCHED_PROC_H
21125 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
21129 + length += sprintf(buffer,
21130 + "PrioBias:\t%8d\n",
21131 + sched->prio_bias);
21136 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
21137 + char *buffer, int cpu)
21141 + length += sprintf(buffer + length,
21142 + "cpu %d: %lld %lld %lld", cpu,
21143 + (unsigned long long)sched_pc->user_ticks,
21144 + (unsigned long long)sched_pc->sys_ticks,
21145 + (unsigned long long)sched_pc->hold_ticks);
21146 + length += sprintf(buffer + length,
21147 + " %d\n", sched_pc->prio_bias);
21151 +#endif /* _VX_SCHED_PROC_H */
21152 diff -NurpP --minimal linux-4.9.76/kernel/vserver/signal.c linux-4.9.76-vs2.3.9.5/kernel/vserver/signal.c
21153 --- linux-4.9.76/kernel/vserver/signal.c 1970-01-01 00:00:00.000000000 +0000
21154 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/signal.c 2018-01-10 02:50:49.000000000 +0000
21157 + * linux/kernel/vserver/signal.c
21159 + * Virtual Server: Signal Support
21161 + * Copyright (C) 2003-2007 Herbert P?tzl
21163 + * V0.01 broken out from vcontext V0.05
21164 + * V0.02 changed vcmds to vxi arg
21165 + * V0.03 adjusted siginfo for kill
21169 +#include <asm/uaccess.h>
21171 +#include <linux/vs_context.h>
21172 +#include <linux/vs_pid.h>
21173 +#include <linux/vserver/signal_cmd.h>
21176 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
21178 + int retval, count = 0;
21179 + struct task_struct *p;
21180 + struct siginfo *sip = SEND_SIG_PRIV;
21183 + vxdprintk(VXD_CBIT(misc, 4),
21184 + "vx_info_kill(%p[#%d],%d,%d)*",
21185 + vxi, vxi->vx_id, pid, sig);
21186 + read_lock(&tasklist_lock);
21190 + for_each_process(p) {
21193 + if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
21194 + (pid && vxi->vx_initpid == p->pid))
21197 + err = group_send_sig_info(sig, sip, p);
21199 + if (err != -EPERM)
21205 + if (vxi->vx_initpid) {
21206 + pid = vxi->vx_initpid;
21207 + /* for now, only SIGINT to private init ... */
21208 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21209 + /* ... as long as there are tasks left */
21210 + (atomic_read(&vxi->vx_tasks) > 1))
21213 + /* fallthrough */
21216 + p = find_task_by_real_pid(pid);
21217 + rcu_read_unlock();
21219 + if (vx_task_xid(p) == vxi->vx_id)
21220 + retval = group_send_sig_info(sig, sip, p);
21224 + read_unlock(&tasklist_lock);
21225 + vxdprintk(VXD_CBIT(misc, 4),
21226 + "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
21227 + vxi, vxi->vx_id, pid, sig, (long)sip, retval);
21231 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
21233 + struct vcmd_ctx_kill_v0 vc_data;
21235 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21238 + /* special check to allow guest shutdown */
21239 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21240 + /* forbid killall pid=0 when init is present */
21241 + (((vc_data.pid < 1) && vxi->vx_initpid) ||
21242 + (vc_data.pid > 1)))
21245 + return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
21249 +static int __wait_exit(struct vx_info *vxi)
21251 + DECLARE_WAITQUEUE(wait, current);
21254 + add_wait_queue(&vxi->vx_wait, &wait);
21255 + set_current_state(TASK_INTERRUPTIBLE);
21258 + if (vx_info_state(vxi,
21259 + VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
21261 + if (signal_pending(current)) {
21262 + ret = -ERESTARTSYS;
21269 + set_current_state(TASK_RUNNING);
21270 + remove_wait_queue(&vxi->vx_wait, &wait);
21276 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
21278 + struct vcmd_wait_exit_v0 vc_data;
21281 + ret = __wait_exit(vxi);
21282 + vc_data.reboot_cmd = vxi->reboot_cmd;
21283 + vc_data.exit_code = vxi->exit_code;
21285 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21290 diff -NurpP --minimal linux-4.9.76/kernel/vserver/space.c linux-4.9.76-vs2.3.9.5/kernel/vserver/space.c
21291 --- linux-4.9.76/kernel/vserver/space.c 1970-01-01 00:00:00.000000000 +0000
21292 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/space.c 2018-01-13 03:42:01.000000000 +0000
21295 + * linux/kernel/vserver/space.c
21297 + * Virtual Server: Context Space Support
21299 + * Copyright (C) 2003-2010 Herbert P?tzl
21301 + * V0.01 broken out from context.c 0.07
21302 + * V0.02 added task locking for namespace
21303 + * V0.03 broken out vx_enter_namespace
21304 + * V0.04 added *space support and commands
21305 + * V0.05 added credential support
21309 +#include <linux/utsname.h>
21310 +#include <linux/nsproxy.h>
21311 +#include <linux/err.h>
21312 +#include <linux/fs_struct.h>
21313 +#include <linux/cred.h>
21314 +#include <asm/uaccess.h>
21316 +#include <linux/vs_context.h>
21317 +#include <linux/vserver/space.h>
21318 +#include <linux/vserver/space_cmd.h>
21320 +atomic_t vs_global_nsproxy = ATOMIC_INIT(0);
21321 +atomic_t vs_global_fs = ATOMIC_INIT(0);
21322 +atomic_t vs_global_mnt_ns = ATOMIC_INIT(0);
21323 +atomic_t vs_global_uts_ns = ATOMIC_INIT(0);
21324 +atomic_t vs_global_ipc_ns = ATOMIC_INIT(0);
21325 +atomic_t vs_global_user_ns = ATOMIC_INIT(0);
21326 +atomic_t vs_global_pid_ns = ATOMIC_INIT(0);
21329 +/* namespace functions */
21331 +#include <linux/mnt_namespace.h>
21332 +#include <linux/user_namespace.h>
21333 +#include <linux/pid_namespace.h>
21334 +#include <linux/ipc_namespace.h>
21335 +#include <net/net_namespace.h>
21336 +#include "../fs/mount.h"
21339 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
21340 + .mask = CLONE_FS |
21342 +#ifdef CONFIG_UTS_NS
21345 +#ifdef CONFIG_IPC_NS
21348 +#ifdef CONFIG_USER_NS
21354 +static const struct vcmd_space_mask_v1 space_mask = {
21355 + .mask = CLONE_FS |
21357 +#ifdef CONFIG_UTS_NS
21360 +#ifdef CONFIG_IPC_NS
21363 +#ifdef CONFIG_USER_NS
21366 +#ifdef CONFIG_PID_NS
21369 +#ifdef CONFIG_NET_NS
21375 +static const struct vcmd_space_mask_v1 default_space_mask = {
21376 + .mask = CLONE_FS |
21378 +#ifdef CONFIG_UTS_NS
21381 +#ifdef CONFIG_IPC_NS
21384 +#ifdef CONFIG_USER_NS
21385 +// CLONE_NEWUSER |
21387 +#ifdef CONFIG_PID_NS
21394 + * build a new nsproxy mix
21395 + * assumes that both proxies are 'const'
21396 + * does not touch nsproxy refcounts
21397 + * will hold a reference on the result.
21400 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
21401 + struct nsproxy *new_nsproxy, unsigned long mask)
21403 + struct mnt_namespace *old_ns;
21404 + struct uts_namespace *old_uts;
21405 + struct ipc_namespace *old_ipc;
21406 +#ifdef CONFIG_PID_NS
21407 + struct pid_namespace *old_pid;
21409 +#ifdef CONFIG_NET_NS
21410 + struct net *old_net;
21412 + struct nsproxy *nsproxy;
21414 + nsproxy = copy_nsproxy(old_nsproxy);
21418 + if (mask & CLONE_NEWNS) {
21419 + old_ns = nsproxy->mnt_ns;
21420 + nsproxy->mnt_ns = new_nsproxy->mnt_ns;
21421 + if (nsproxy->mnt_ns)
21422 + get_mnt_ns(nsproxy->mnt_ns);
21426 + if (mask & CLONE_NEWUTS) {
21427 + old_uts = nsproxy->uts_ns;
21428 + nsproxy->uts_ns = new_nsproxy->uts_ns;
21429 + if (nsproxy->uts_ns)
21430 + get_uts_ns(nsproxy->uts_ns);
21434 + if (mask & CLONE_NEWIPC) {
21435 + old_ipc = nsproxy->ipc_ns;
21436 + nsproxy->ipc_ns = new_nsproxy->ipc_ns;
21437 + if (nsproxy->ipc_ns)
21438 + get_ipc_ns(nsproxy->ipc_ns);
21442 +#ifdef CONFIG_PID_NS
21443 + if (mask & CLONE_NEWPID) {
21444 + old_pid = nsproxy->pid_ns_for_children;
21445 + nsproxy->pid_ns_for_children = new_nsproxy->pid_ns_for_children;
21446 + if (nsproxy->pid_ns_for_children)
21447 + get_pid_ns(nsproxy->pid_ns_for_children);
21451 +#ifdef CONFIG_NET_NS
21452 + if (mask & CLONE_NEWNET) {
21453 + old_net = nsproxy->net_ns;
21454 + nsproxy->net_ns = new_nsproxy->net_ns;
21455 + if (nsproxy->net_ns)
21456 + get_net(nsproxy->net_ns);
21461 + put_mnt_ns(old_ns);
21463 + put_uts_ns(old_uts);
21465 + put_ipc_ns(old_ipc);
21466 +#ifdef CONFIG_PID_NS
21468 + put_pid_ns(old_pid);
21470 +#ifdef CONFIG_NET_NS
21472 + put_net(old_net);
21480 + * merge two nsproxy structs into a new one.
21481 + * will hold a reference on the result.
21485 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
21486 + struct nsproxy *proxy, unsigned long mask)
21488 + struct nsproxy null_proxy = { .mnt_ns = NULL };
21494 + /* vs_mix_nsproxy returns with reference */
21495 + return vs_mix_nsproxy(old ? old : &null_proxy,
21498 + get_nsproxy(proxy);
21503 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21505 + struct nsproxy *proxy, *proxy_cur, *proxy_new;
21506 + struct fs_struct *fs_cur, *fs = NULL;
21507 + struct _vx_space *space;
21508 + int ret, kill = 0;
21510 + vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
21511 + vxi, vxi->vx_id, mask, index);
21513 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
21516 + if (index >= VX_SPACES)
21519 + space = &vxi->space[index];
21522 + mask = space->vx_nsmask;
21524 + if ((mask & space->vx_nsmask) != mask)
21527 + if (mask & CLONE_FS) {
21528 + fs = copy_fs_struct(space->vx_fs);
21532 + proxy = space->vx_nsproxy;
21534 + vxdprintk(VXD_CBIT(space, 9),
21535 + "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
21536 + vxi, vxi->vx_id, mask, index, proxy, fs);
21538 + task_lock(current);
21539 + fs_cur = current->fs;
21541 + if (mask & CLONE_FS) {
21542 + spin_lock(&fs_cur->lock);
21543 + current->fs = fs;
21544 + kill = !--fs_cur->users;
21545 + spin_unlock(&fs_cur->lock);
21548 + proxy_cur = current->nsproxy;
21549 + get_nsproxy(proxy_cur);
21550 + task_unlock(current);
21553 + free_fs_struct(fs_cur);
21555 + proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
21556 + if (IS_ERR(proxy_new)) {
21557 + ret = PTR_ERR(proxy_new);
21561 + proxy_new = xchg(¤t->nsproxy, proxy_new);
21563 + if (mask & CLONE_NEWUSER) {
21564 + struct cred *cred;
21566 + vxdprintk(VXD_CBIT(space, 10),
21567 + "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
21568 + vxi, vxi->vx_id, space->vx_cred,
21569 + current->real_cred, current->cred);
21571 + if (space->vx_cred) {
21572 + cred = __prepare_creds(space->vx_cred);
21574 + commit_creds(cred);
21581 + put_nsproxy(proxy_new);
21584 + put_nsproxy(proxy_cur);
21589 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21591 + struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
21592 + struct fs_struct *fs_vxi, *fs = NULL;
21593 + struct _vx_space *space;
21594 + int ret, kill = 0;
21596 + vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
21597 + vxi, vxi->vx_id, mask, index);
21599 + if ((mask & space_mask.mask) != mask)
21602 + if (index >= VX_SPACES)
21605 + space = &vxi->space[index];
21607 + proxy_vxi = space->vx_nsproxy;
21608 + fs_vxi = space->vx_fs;
21610 + if (mask & CLONE_FS) {
21611 + fs = copy_fs_struct(current->fs);
21616 + task_lock(current);
21618 + if (mask & CLONE_FS) {
21619 + spin_lock(&fs_vxi->lock);
21620 + space->vx_fs = fs;
21621 + kill = !--fs_vxi->users;
21622 + spin_unlock(&fs_vxi->lock);
21625 + proxy_cur = current->nsproxy;
21626 + get_nsproxy(proxy_cur);
21627 + task_unlock(current);
21630 + free_fs_struct(fs_vxi);
21632 + proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
21633 + if (IS_ERR(proxy_new)) {
21634 + ret = PTR_ERR(proxy_new);
21638 + proxy_new = xchg(&space->vx_nsproxy, proxy_new);
21639 + space->vx_nsmask |= mask;
21641 + if (mask & CLONE_NEWUSER) {
21642 + struct cred *cred;
21644 + vxdprintk(VXD_CBIT(space, 10),
21645 + "vx_set_space(%p[#%u],%p) cred (%p,%p)",
21646 + vxi, vxi->vx_id, space->vx_cred,
21647 + current->real_cred, current->cred);
21649 + cred = prepare_creds();
21650 + cred = (struct cred *)xchg(&space->vx_cred, cred);
21652 + abort_creds(cred);
21658 + put_nsproxy(proxy_new);
21661 + put_nsproxy(proxy_cur);
21666 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
21668 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21670 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21673 + return vx_enter_space(vxi, vc_data.mask, 0);
21676 +int vc_enter_space(struct vx_info *vxi, void __user *data)
21678 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21680 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21683 + if (vc_data.index >= VX_SPACES)
21686 + return vx_enter_space(vxi, vc_data.mask, vc_data.index);
21689 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
21691 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21693 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21696 + return vx_set_space(vxi, vc_data.mask, 0);
21699 +int vc_set_space(struct vx_info *vxi, void __user *data)
21701 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21703 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21706 + if (vc_data.index >= VX_SPACES)
21709 + return vx_set_space(vxi, vc_data.mask, vc_data.index);
21712 +int vc_get_space_mask(void __user *data, int type)
21714 + const struct vcmd_space_mask_v1 *mask;
21717 + mask = &space_mask_v0;
21718 + else if (type == 1)
21719 + mask = &space_mask;
21721 + mask = &default_space_mask;
21723 + vxdprintk(VXD_CBIT(space, 10),
21724 + "vc_get_space_mask(%d) = %08llx", type, mask->mask);
21726 + if (copy_to_user(data, mask, sizeof(*mask)))
21731 diff -NurpP --minimal linux-4.9.76/kernel/vserver/switch.c linux-4.9.76-vs2.3.9.5/kernel/vserver/switch.c
21732 --- linux-4.9.76/kernel/vserver/switch.c 1970-01-01 00:00:00.000000000 +0000
21733 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/switch.c 2018-01-10 02:50:49.000000000 +0000
21736 + * linux/kernel/vserver/switch.c
21738 + * Virtual Server: Syscall Switch
21740 + * Copyright (C) 2003-2011 Herbert P?tzl
21742 + * V0.01 syscall switch
21743 + * V0.02 added signal to context
21744 + * V0.03 added rlimit functions
21745 + * V0.04 added iattr, task/xid functions
21746 + * V0.05 added debug/history stuff
21747 + * V0.06 added compat32 layer
21748 + * V0.07 vcmd args and perms
21749 + * V0.08 added status commands
21750 + * V0.09 added tag commands
21751 + * V0.10 added oom bias
21752 + * V0.11 added device commands
21753 + * V0.12 added warn mask
21757 +#include <linux/vs_context.h>
21758 +#include <linux/vs_network.h>
21759 +#include <linux/vserver/switch.h>
21761 +#include "vci_config.h"
21765 +int vc_get_version(uint32_t id)
21767 + return VCI_VERSION;
21771 +int vc_get_vci(uint32_t id)
21773 + return vci_kernel_config();
21776 +#include <linux/vserver/context_cmd.h>
21777 +#include <linux/vserver/cvirt_cmd.h>
21778 +#include <linux/vserver/cacct_cmd.h>
21779 +#include <linux/vserver/limit_cmd.h>
21780 +#include <linux/vserver/network_cmd.h>
21781 +#include <linux/vserver/sched_cmd.h>
21782 +#include <linux/vserver/debug_cmd.h>
21783 +#include <linux/vserver/inode_cmd.h>
21784 +#include <linux/vserver/dlimit_cmd.h>
21785 +#include <linux/vserver/signal_cmd.h>
21786 +#include <linux/vserver/space_cmd.h>
21787 +#include <linux/vserver/tag_cmd.h>
21788 +#include <linux/vserver/device_cmd.h>
21790 +#include <linux/vserver/inode.h>
21791 +#include <linux/vserver/dlimit.h>
21794 +#ifdef CONFIG_COMPAT
21795 +#define __COMPAT(name, id, data, compat) \
21796 + (compat) ? name ## _x32(id, data) : name(id, data)
21797 +#define __COMPAT_NO_ID(name, data, compat) \
21798 + (compat) ? name ## _x32(data) : name(data)
21800 +#define __COMPAT(name, id, data, compat) \
21802 +#define __COMPAT_NO_ID(name, data, compat) \
21808 +long do_vcmd(uint32_t cmd, uint32_t id,
21809 + struct vx_info *vxi, struct nx_info *nxi,
21810 + void __user *data, int compat)
21814 + case VCMD_get_version:
21815 + return vc_get_version(id);
21816 + case VCMD_get_vci:
21817 + return vc_get_vci(id);
21819 + case VCMD_task_xid:
21820 + return vc_task_xid(id);
21821 + case VCMD_vx_info:
21822 + return vc_vx_info(vxi, data);
21824 + case VCMD_task_nid:
21825 + return vc_task_nid(id);
21826 + case VCMD_nx_info:
21827 + return vc_nx_info(nxi, data);
21829 + case VCMD_task_tag:
21830 + return vc_task_tag(id);
21832 + case VCMD_set_space_v1:
21833 + return vc_set_space_v1(vxi, data);
21834 + /* this is version 2 */
21835 + case VCMD_set_space:
21836 + return vc_set_space(vxi, data);
21838 + case VCMD_get_space_mask_v0:
21839 + return vc_get_space_mask(data, 0);
21840 + /* this is version 1 */
21841 + case VCMD_get_space_mask:
21842 + return vc_get_space_mask(data, 1);
21844 + case VCMD_get_space_default:
21845 + return vc_get_space_mask(data, -1);
21847 + case VCMD_set_umask:
21848 + return vc_set_umask(vxi, data);
21850 + case VCMD_get_umask:
21851 + return vc_get_umask(vxi, data);
21853 + case VCMD_set_wmask:
21854 + return vc_set_wmask(vxi, data);
21856 + case VCMD_get_wmask:
21857 + return vc_get_wmask(vxi, data);
21858 +#ifdef CONFIG_IA32_EMULATION
21859 + case VCMD_get_rlimit:
21860 + return __COMPAT(vc_get_rlimit, vxi, data, compat);
21861 + case VCMD_set_rlimit:
21862 + return __COMPAT(vc_set_rlimit, vxi, data, compat);
21864 + case VCMD_get_rlimit:
21865 + return vc_get_rlimit(vxi, data);
21866 + case VCMD_set_rlimit:
21867 + return vc_set_rlimit(vxi, data);
21869 + case VCMD_get_rlimit_mask:
21870 + return vc_get_rlimit_mask(id, data);
21871 + case VCMD_reset_hits:
21872 + return vc_reset_hits(vxi, data);
21873 + case VCMD_reset_minmax:
21874 + return vc_reset_minmax(vxi, data);
21876 + case VCMD_get_vhi_name:
21877 + return vc_get_vhi_name(vxi, data);
21878 + case VCMD_set_vhi_name:
21879 + return vc_set_vhi_name(vxi, data);
21881 + case VCMD_ctx_stat:
21882 + return vc_ctx_stat(vxi, data);
21883 + case VCMD_virt_stat:
21884 + return vc_virt_stat(vxi, data);
21885 + case VCMD_sock_stat:
21886 + return vc_sock_stat(vxi, data);
21887 + case VCMD_rlimit_stat:
21888 + return vc_rlimit_stat(vxi, data);
21890 + case VCMD_set_cflags:
21891 + return vc_set_cflags(vxi, data);
21892 + case VCMD_get_cflags:
21893 + return vc_get_cflags(vxi, data);
21895 + /* this is version 1 */
21896 + case VCMD_set_ccaps:
21897 + return vc_set_ccaps(vxi, data);
21898 + /* this is version 1 */
21899 + case VCMD_get_ccaps:
21900 + return vc_get_ccaps(vxi, data);
21901 + case VCMD_set_bcaps:
21902 + return vc_set_bcaps(vxi, data);
21903 + case VCMD_get_bcaps:
21904 + return vc_get_bcaps(vxi, data);
21906 + case VCMD_set_badness:
21907 + return vc_set_badness(vxi, data);
21908 + case VCMD_get_badness:
21909 + return vc_get_badness(vxi, data);
21911 + case VCMD_set_nflags:
21912 + return vc_set_nflags(nxi, data);
21913 + case VCMD_get_nflags:
21914 + return vc_get_nflags(nxi, data);
21916 + case VCMD_set_ncaps:
21917 + return vc_set_ncaps(nxi, data);
21918 + case VCMD_get_ncaps:
21919 + return vc_get_ncaps(nxi, data);
21921 + case VCMD_set_prio_bias:
21922 + return vc_set_prio_bias(vxi, data);
21923 + case VCMD_get_prio_bias:
21924 + return vc_get_prio_bias(vxi, data);
21925 + case VCMD_add_dlimit:
21926 + return __COMPAT(vc_add_dlimit, id, data, compat);
21927 + case VCMD_rem_dlimit:
21928 + return __COMPAT(vc_rem_dlimit, id, data, compat);
21929 + case VCMD_set_dlimit:
21930 + return __COMPAT(vc_set_dlimit, id, data, compat);
21931 + case VCMD_get_dlimit:
21932 + return __COMPAT(vc_get_dlimit, id, data, compat);
21934 + case VCMD_ctx_kill:
21935 + return vc_ctx_kill(vxi, data);
21937 + case VCMD_wait_exit:
21938 + return vc_wait_exit(vxi, data);
21940 + case VCMD_get_iattr:
21941 + return __COMPAT_NO_ID(vc_get_iattr, data, compat);
21942 + case VCMD_set_iattr:
21943 + return __COMPAT_NO_ID(vc_set_iattr, data, compat);
21945 + case VCMD_fget_iattr:
21946 + return vc_fget_iattr(id, data);
21947 + case VCMD_fset_iattr:
21948 + return vc_fset_iattr(id, data);
21950 + case VCMD_enter_space_v0:
21951 + return vc_enter_space_v1(vxi, NULL);
21952 + case VCMD_enter_space_v1:
21953 + return vc_enter_space_v1(vxi, data);
21954 + /* this is version 2 */
21955 + case VCMD_enter_space:
21956 + return vc_enter_space(vxi, data);
21958 + case VCMD_ctx_create_v0:
21959 + return vc_ctx_create(id, NULL);
21960 + case VCMD_ctx_create:
21961 + return vc_ctx_create(id, data);
21962 + case VCMD_ctx_migrate_v0:
21963 + return vc_ctx_migrate(vxi, NULL);
21964 + case VCMD_ctx_migrate:
21965 + return vc_ctx_migrate(vxi, data);
21967 + case VCMD_net_create_v0:
21968 + return vc_net_create(id, NULL);
21969 + case VCMD_net_create:
21970 + return vc_net_create(id, data);
21971 + case VCMD_net_migrate:
21972 + return vc_net_migrate(nxi, data);
21974 + case VCMD_tag_migrate:
21975 + return vc_tag_migrate(id);
21977 + case VCMD_net_add:
21978 + return vc_net_add(nxi, data);
21979 + case VCMD_net_remove:
21980 + return vc_net_remove(nxi, data);
21982 + case VCMD_net_add_ipv4_v1:
21983 + return vc_net_add_ipv4_v1(nxi, data);
21984 + /* this is version 2 */
21985 + case VCMD_net_add_ipv4:
21986 + return vc_net_add_ipv4(nxi, data);
21988 + case VCMD_net_rem_ipv4_v1:
21989 + return vc_net_rem_ipv4_v1(nxi, data);
21990 + /* this is version 2 */
21991 + case VCMD_net_rem_ipv4:
21992 + return vc_net_rem_ipv4(nxi, data);
21993 +#ifdef CONFIG_IPV6
21994 + case VCMD_net_add_ipv6:
21995 + return vc_net_add_ipv6(nxi, data);
21996 + case VCMD_net_remove_ipv6:
21997 + return vc_net_remove_ipv6(nxi, data);
21999 +/* case VCMD_add_match_ipv4:
22000 + return vc_add_match_ipv4(nxi, data);
22001 + case VCMD_get_match_ipv4:
22002 + return vc_get_match_ipv4(nxi, data);
22003 +#ifdef CONFIG_IPV6
22004 + case VCMD_add_match_ipv6:
22005 + return vc_add_match_ipv6(nxi, data);
22006 + case VCMD_get_match_ipv6:
22007 + return vc_get_match_ipv6(nxi, data);
22010 +#ifdef CONFIG_VSERVER_DEVICE
22011 + case VCMD_set_mapping:
22012 + return __COMPAT(vc_set_mapping, vxi, data, compat);
22013 + case VCMD_unset_mapping:
22014 + return __COMPAT(vc_unset_mapping, vxi, data, compat);
22016 +#ifdef CONFIG_VSERVER_HISTORY
22017 + case VCMD_dump_history:
22018 + return vc_dump_history(id);
22019 + case VCMD_read_history:
22020 + return __COMPAT(vc_read_history, id, data, compat);
22023 + vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
22024 + VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22030 +#define __VCMD(vcmd, _perm, _args, _flags) \
22031 + case VCMD_ ## vcmd: perm = _perm; \
22032 + args = _args; flags = _flags; break
22035 +#define VCA_NONE 0x00
22036 +#define VCA_VXI 0x01
22037 +#define VCA_NXI 0x02
22039 +#define VCF_NONE 0x00
22040 +#define VCF_INFO 0x01
22041 +#define VCF_ADMIN 0x02
22042 +#define VCF_ARES 0x06 /* includes admin */
22043 +#define VCF_SETUP 0x08
22045 +#define VCF_ZIDOK 0x10 /* zero id okay */
22049 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22052 + int permit = -1, state = 0;
22053 + int perm = -1, args = 0, flags = 0;
22054 + struct vx_info *vxi = NULL;
22055 + struct nx_info *nxi = NULL;
22058 + /* unpriviledged commands */
22059 + __VCMD(get_version, 0, VCA_NONE, 0);
22060 + __VCMD(get_vci, 0, VCA_NONE, 0);
22061 + __VCMD(get_rlimit_mask, 0, VCA_NONE, 0);
22062 + __VCMD(get_space_mask_v0,0, VCA_NONE, 0);
22063 + __VCMD(get_space_mask, 0, VCA_NONE, 0);
22064 + __VCMD(get_space_default,0, VCA_NONE, 0);
22066 + /* info commands */
22067 + __VCMD(task_xid, 2, VCA_NONE, 0);
22068 + __VCMD(reset_hits, 2, VCA_VXI, 0);
22069 + __VCMD(reset_minmax, 2, VCA_VXI, 0);
22070 + __VCMD(vx_info, 3, VCA_VXI, VCF_INFO);
22071 + __VCMD(get_bcaps, 3, VCA_VXI, VCF_INFO);
22072 + __VCMD(get_ccaps, 3, VCA_VXI, VCF_INFO);
22073 + __VCMD(get_cflags, 3, VCA_VXI, VCF_INFO);
22074 + __VCMD(get_umask, 3, VCA_VXI, VCF_INFO);
22075 + __VCMD(get_wmask, 3, VCA_VXI, VCF_INFO);
22076 + __VCMD(get_badness, 3, VCA_VXI, VCF_INFO);
22077 + __VCMD(get_vhi_name, 3, VCA_VXI, VCF_INFO);
22078 + __VCMD(get_rlimit, 3, VCA_VXI, VCF_INFO);
22080 + __VCMD(ctx_stat, 3, VCA_VXI, VCF_INFO);
22081 + __VCMD(virt_stat, 3, VCA_VXI, VCF_INFO);
22082 + __VCMD(sock_stat, 3, VCA_VXI, VCF_INFO);
22083 + __VCMD(rlimit_stat, 3, VCA_VXI, VCF_INFO);
22085 + __VCMD(task_nid, 2, VCA_NONE, 0);
22086 + __VCMD(nx_info, 3, VCA_NXI, VCF_INFO);
22087 + __VCMD(get_ncaps, 3, VCA_NXI, VCF_INFO);
22088 + __VCMD(get_nflags, 3, VCA_NXI, VCF_INFO);
22090 + __VCMD(task_tag, 2, VCA_NONE, 0);
22092 + __VCMD(get_iattr, 2, VCA_NONE, 0);
22093 + __VCMD(fget_iattr, 2, VCA_NONE, 0);
22094 + __VCMD(get_dlimit, 3, VCA_NONE, VCF_INFO);
22095 + __VCMD(get_prio_bias, 3, VCA_VXI, VCF_INFO);
22097 + /* lower admin commands */
22098 + __VCMD(wait_exit, 4, VCA_VXI, VCF_INFO);
22099 + __VCMD(ctx_create_v0, 5, VCA_NONE, 0);
22100 + __VCMD(ctx_create, 5, VCA_NONE, 0);
22101 + __VCMD(ctx_migrate_v0, 5, VCA_VXI, VCF_ADMIN);
22102 + __VCMD(ctx_migrate, 5, VCA_VXI, VCF_ADMIN);
22103 + __VCMD(enter_space_v0, 5, VCA_VXI, VCF_ADMIN);
22104 + __VCMD(enter_space_v1, 5, VCA_VXI, VCF_ADMIN);
22105 + __VCMD(enter_space, 5, VCA_VXI, VCF_ADMIN);
22107 + __VCMD(net_create_v0, 5, VCA_NONE, 0);
22108 + __VCMD(net_create, 5, VCA_NONE, 0);
22109 + __VCMD(net_migrate, 5, VCA_NXI, VCF_ADMIN);
22111 + __VCMD(tag_migrate, 5, VCA_NONE, VCF_ADMIN);
22113 + /* higher admin commands */
22114 + __VCMD(ctx_kill, 6, VCA_VXI, VCF_ARES);
22115 + __VCMD(set_space_v1, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22116 + __VCMD(set_space, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22118 + __VCMD(set_ccaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22119 + __VCMD(set_bcaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22120 + __VCMD(set_cflags, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22121 + __VCMD(set_umask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22122 + __VCMD(set_wmask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22123 + __VCMD(set_badness, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22125 + __VCMD(set_vhi_name, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22126 + __VCMD(set_rlimit, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22127 + __VCMD(set_prio_bias, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22129 + __VCMD(set_ncaps, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
22130 + __VCMD(set_nflags, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
22131 + __VCMD(net_add, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22132 + __VCMD(net_remove, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22133 + __VCMD(net_add_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22134 + __VCMD(net_rem_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22135 + __VCMD(net_add_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22136 + __VCMD(net_rem_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22137 +#ifdef CONFIG_IPV6
22138 + __VCMD(net_add_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22139 + __VCMD(net_remove_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22141 + __VCMD(set_iattr, 7, VCA_NONE, 0);
22142 + __VCMD(fset_iattr, 7, VCA_NONE, 0);
22143 + __VCMD(set_dlimit, 7, VCA_NONE, VCF_ARES);
22144 + __VCMD(add_dlimit, 8, VCA_NONE, VCF_ARES);
22145 + __VCMD(rem_dlimit, 8, VCA_NONE, VCF_ARES);
22147 +#ifdef CONFIG_VSERVER_DEVICE
22148 + __VCMD(set_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
22149 + __VCMD(unset_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
22151 + /* debug level admin commands */
22152 +#ifdef CONFIG_VSERVER_HISTORY
22153 + __VCMD(dump_history, 9, VCA_NONE, 0);
22154 + __VCMD(read_history, 9, VCA_NONE, 0);
22161 + vxdprintk(VXD_CBIT(switch, 0),
22162 + "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
22163 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
22164 + VC_VERSION(cmd), id, data, compat,
22165 + perm, args, flags);
22172 + if (!capable(CAP_CONTEXT))
22176 + /* moved here from the individual commands */
22178 + if ((perm > 1) && !capable(CAP_SYS_ADMIN))
22182 + /* vcmd involves resource management */
22184 + if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
22188 + /* various legacy exceptions */
22190 + /* will go away when spectator is a cap */
22191 + case VCMD_ctx_migrate_v0:
22192 + case VCMD_ctx_migrate:
22194 + current->xid = 1;
22200 + /* will go away when spectator is a cap */
22201 + case VCMD_net_migrate:
22203 + current->nid = 1;
22210 + /* vcmds are fine by default */
22213 + /* admin type vcmds require admin ... */
22214 + if (flags & VCF_ADMIN)
22215 + permit = vx_check(0, VS_ADMIN) ? 1 : 0;
22217 + /* ... but setup type vcmds override that */
22218 + if (!permit && (flags & VCF_SETUP))
22219 + permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
22227 + if (!id && (flags & VCF_ZIDOK))
22231 + if (args & VCA_VXI) {
22232 + vxi = lookup_vx_info(id);
22236 + if ((flags & VCF_ADMIN) &&
22237 + /* special case kill for shutdown */
22238 + (cmd != VCMD_ctx_kill) &&
22239 + /* can context be administrated? */
22240 + !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
22246 + if (args & VCA_NXI) {
22247 + nxi = lookup_nx_info(id);
22251 + if ((flags & VCF_ADMIN) &&
22252 + /* can context be administrated? */
22253 + !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
22260 + ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
22263 + if ((args & VCA_NXI) && nxi)
22264 + put_nx_info(nxi);
22266 + if ((args & VCA_VXI) && vxi)
22267 + put_vx_info(vxi);
22269 + vxdprintk(VXD_CBIT(switch, 1),
22270 + "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
22271 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
22272 + VC_VERSION(cmd), ret, ret, state, permit);
22277 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
22279 + return do_vserver(cmd, id, data, 0);
22282 +#ifdef CONFIG_COMPAT
22285 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
22287 + return do_vserver(cmd, id, data, 1);
22290 +#endif /* CONFIG_COMPAT */
22291 diff -NurpP --minimal linux-4.9.76/kernel/vserver/sysctl.c linux-4.9.76-vs2.3.9.5/kernel/vserver/sysctl.c
22292 --- linux-4.9.76/kernel/vserver/sysctl.c 1970-01-01 00:00:00.000000000 +0000
22293 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/sysctl.c 2018-01-13 05:37:59.000000000 +0000
22296 + * kernel/vserver/sysctl.c
22298 + * Virtual Context Support
22300 + * Copyright (C) 2004-2007 Herbert P?tzl
22302 + * V0.01 basic structure
22306 +#include <linux/module.h>
22307 +#include <linux/ctype.h>
22308 +#include <linux/sysctl.h>
22309 +#include <linux/parser.h>
22310 +#include <linux/utsname.h>
22312 +#include <asm/uaccess.h>
22313 +#include <asm/sections.h>
22316 + CTL_DEBUG_ERROR = 0,
22317 + CTL_DEBUG_SWITCH = 1,
22333 +unsigned int vs_debug_switch = 0;
22334 +unsigned int vs_debug_xid = 0;
22335 +unsigned int vs_debug_nid = 0;
22336 +unsigned int vs_debug_tag = 0;
22337 +unsigned int vs_debug_net = 0;
22338 +unsigned int vs_debug_limit = 0;
22339 +unsigned int vs_debug_cres = 0;
22340 +unsigned int vs_debug_dlim = 0;
22341 +unsigned int vs_debug_quota = 0;
22342 +unsigned int vs_debug_cvirt = 0;
22343 +unsigned int vs_debug_space = 0;
22344 +unsigned int vs_debug_perm = 0;
22345 +unsigned int vs_debug_misc = 0;
22348 +static struct ctl_table_header *vserver_table_header;
22349 +static struct ctl_table vserver_root_table[];
22352 +void vserver_register_sysctl(void)
22354 + if (!vserver_table_header) {
22355 + vserver_table_header = register_sysctl_table(vserver_root_table);
22360 +void vserver_unregister_sysctl(void)
22362 + if (vserver_table_header) {
22363 + unregister_sysctl_table(vserver_table_header);
22364 + vserver_table_header = NULL;
22368 +static int proc_dodebug(struct ctl_table *table, int write,
22369 + void __user *buffer, size_t *lenp, loff_t *ppos)
22371 + char tmpbuf[20], *p, c;
22372 + unsigned int value;
22373 + size_t left, len;
22375 + if ((*ppos && !write) || !*lenp) {
22383 + if (!access_ok(VERIFY_READ, buffer, left))
22385 + p = (char *)buffer;
22386 + while (left && __get_user(c, p) >= 0 && isspace(c))
22391 + if (left > sizeof(tmpbuf) - 1)
22393 + if (copy_from_user(tmpbuf, p, left))
22395 + tmpbuf[left] = '\0';
22397 + for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
22398 + value = 10 * value + (*p - '0');
22399 + if (*p && !isspace(*p))
22401 + while (left && isspace(*p))
22403 + *(unsigned int *)table->data = value;
22405 + if (!access_ok(VERIFY_WRITE, buffer, left))
22407 + len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
22410 + if (__copy_to_user(buffer, tmpbuf, len))
22412 + if ((left -= len) > 0) {
22413 + if (put_user('\n', (char *)buffer + len))
22427 +#define CTL_ENTRY(ctl, name) \
22429 + .procname = #name, \
22430 + .data = &vs_ ## name, \
22431 + .maxlen = sizeof(int), \
22433 + .proc_handler = &proc_dodebug, \
22434 + .extra1 = &zero, \
22435 + .extra2 = &zero, \
22438 +static struct ctl_table vserver_debug_table[] = {
22439 + CTL_ENTRY(CTL_DEBUG_SWITCH, debug_switch),
22440 + CTL_ENTRY(CTL_DEBUG_XID, debug_xid),
22441 + CTL_ENTRY(CTL_DEBUG_NID, debug_nid),
22442 + CTL_ENTRY(CTL_DEBUG_TAG, debug_tag),
22443 + CTL_ENTRY(CTL_DEBUG_NET, debug_net),
22444 + CTL_ENTRY(CTL_DEBUG_LIMIT, debug_limit),
22445 + CTL_ENTRY(CTL_DEBUG_CRES, debug_cres),
22446 + CTL_ENTRY(CTL_DEBUG_DLIM, debug_dlim),
22447 + CTL_ENTRY(CTL_DEBUG_QUOTA, debug_quota),
22448 + CTL_ENTRY(CTL_DEBUG_CVIRT, debug_cvirt),
22449 + CTL_ENTRY(CTL_DEBUG_SPACE, debug_space),
22450 + CTL_ENTRY(CTL_DEBUG_PERM, debug_perm),
22451 + CTL_ENTRY(CTL_DEBUG_MISC, debug_misc),
22455 +static struct ctl_table vserver_root_table[] = {
22457 + .procname = "vserver",
22459 + .child = vserver_debug_table
22465 +static match_table_t tokens = {
22466 + { CTL_DEBUG_SWITCH, "switch=%x" },
22467 + { CTL_DEBUG_XID, "xid=%x" },
22468 + { CTL_DEBUG_NID, "nid=%x" },
22469 + { CTL_DEBUG_TAG, "tag=%x" },
22470 + { CTL_DEBUG_NET, "net=%x" },
22471 + { CTL_DEBUG_LIMIT, "limit=%x" },
22472 + { CTL_DEBUG_CRES, "cres=%x" },
22473 + { CTL_DEBUG_DLIM, "dlim=%x" },
22474 + { CTL_DEBUG_QUOTA, "quota=%x" },
22475 + { CTL_DEBUG_CVIRT, "cvirt=%x" },
22476 + { CTL_DEBUG_SPACE, "space=%x" },
22477 + { CTL_DEBUG_PERM, "perm=%x" },
22478 + { CTL_DEBUG_MISC, "misc=%x" },
22479 + { CTL_DEBUG_ERROR, NULL }
22482 +#define HANDLE_CASE(id, name, val) \
22483 + case CTL_DEBUG_ ## id: \
22484 + vs_debug_ ## name = val; \
22485 + printk("vs_debug_" #name "=0x%x\n", val); \
22489 +static int __init vs_debug_setup(char *str)
22494 + printk("vs_debug_setup(%s)\n", str);
22495 + while ((p = strsep(&str, ",")) != NULL) {
22496 + substring_t args[MAX_OPT_ARGS];
22497 + unsigned int value;
22502 + token = match_token(p, tokens, args);
22503 + value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
22506 + HANDLE_CASE(SWITCH, switch, value);
22507 + HANDLE_CASE(XID, xid, value);
22508 + HANDLE_CASE(NID, nid, value);
22509 + HANDLE_CASE(TAG, tag, value);
22510 + HANDLE_CASE(NET, net, value);
22511 + HANDLE_CASE(LIMIT, limit, value);
22512 + HANDLE_CASE(CRES, cres, value);
22513 + HANDLE_CASE(DLIM, dlim, value);
22514 + HANDLE_CASE(QUOTA, quota, value);
22515 + HANDLE_CASE(CVIRT, cvirt, value);
22516 + HANDLE_CASE(SPACE, space, value);
22517 + HANDLE_CASE(PERM, perm, value);
22518 + HANDLE_CASE(MISC, misc, value);
22527 +__setup("vsdebug=", vs_debug_setup);
22531 +EXPORT_SYMBOL_GPL(vs_debug_switch);
22532 +EXPORT_SYMBOL_GPL(vs_debug_xid);
22533 +EXPORT_SYMBOL_GPL(vs_debug_nid);
22534 +EXPORT_SYMBOL_GPL(vs_debug_net);
22535 +EXPORT_SYMBOL_GPL(vs_debug_limit);
22536 +EXPORT_SYMBOL_GPL(vs_debug_cres);
22537 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
22538 +EXPORT_SYMBOL_GPL(vs_debug_quota);
22539 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
22540 +EXPORT_SYMBOL_GPL(vs_debug_space);
22541 +EXPORT_SYMBOL_GPL(vs_debug_perm);
22542 +EXPORT_SYMBOL_GPL(vs_debug_misc);
22544 diff -NurpP --minimal linux-4.9.76/kernel/vserver/tag.c linux-4.9.76-vs2.3.9.5/kernel/vserver/tag.c
22545 --- linux-4.9.76/kernel/vserver/tag.c 1970-01-01 00:00:00.000000000 +0000
22546 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/tag.c 2018-01-10 02:50:49.000000000 +0000
22549 + * linux/kernel/vserver/tag.c
22551 + * Virtual Server: Shallow Tag Space
22553 + * Copyright (C) 2007 Herbert P?tzl
22555 + * V0.01 basic implementation
22559 +#include <linux/sched.h>
22560 +#include <linux/vserver/debug.h>
22561 +#include <linux/vs_pid.h>
22562 +#include <linux/vs_tag.h>
22564 +#include <linux/vserver/tag_cmd.h>
22567 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
22572 + vxdprintk(VXD_CBIT(tag, 5),
22573 + "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
22579 + vxdprintk(VXD_CBIT(tag, 5),
22580 + "moved task %p into [#%d]", p, tag);
22584 +/* vserver syscall commands below here */
22586 +/* taks xid and vx_info functions */
22589 +int vc_task_tag(uint32_t id)
22594 + struct task_struct *tsk;
22596 + tsk = find_task_by_real_pid(id);
22597 + tag = (tsk) ? tsk->tag : -ESRCH;
22598 + rcu_read_unlock();
22600 + tag = dx_current_tag();
22605 +int vc_tag_migrate(uint32_t tag)
22607 + return dx_migrate_task(current, tag & 0xFFFF);
22611 diff -NurpP --minimal linux-4.9.76/kernel/vserver/vci_config.h linux-4.9.76-vs2.3.9.5/kernel/vserver/vci_config.h
22612 --- linux-4.9.76/kernel/vserver/vci_config.h 1970-01-01 00:00:00.000000000 +0000
22613 +++ linux-4.9.76-vs2.3.9.5/kernel/vserver/vci_config.h 2018-01-10 02:50:49.000000000 +0000
22616 +/* interface version */
22618 +#define VCI_VERSION 0x00020308
22622 + VCI_KCBIT_NO_DYNAMIC = 0,
22624 + VCI_KCBIT_PROC_SECURE = 4,
22625 + /* VCI_KCBIT_HARDCPU = 5, */
22626 + /* VCI_KCBIT_IDLELIMIT = 6, */
22627 + /* VCI_KCBIT_IDLETIME = 7, */
22629 + VCI_KCBIT_COWBL = 8,
22630 + VCI_KCBIT_FULLCOWBL = 9,
22631 + VCI_KCBIT_SPACES = 10,
22632 + VCI_KCBIT_NETV2 = 11,
22633 + VCI_KCBIT_MEMCG = 12,
22634 + VCI_KCBIT_MEMCG_SWAP = 13,
22636 + VCI_KCBIT_DEBUG = 16,
22637 + VCI_KCBIT_HISTORY = 20,
22638 + VCI_KCBIT_TAGGED = 24,
22639 + VCI_KCBIT_PPTAG = 28,
22641 + VCI_KCBIT_MORE = 31,
22645 +static inline uint32_t vci_kernel_config(void)
22648 + (1 << VCI_KCBIT_NO_DYNAMIC) |
22650 + /* configured features */
22651 +#ifdef CONFIG_VSERVER_PROC_SECURE
22652 + (1 << VCI_KCBIT_PROC_SECURE) |
22654 +#ifdef CONFIG_VSERVER_COWBL
22655 + (1 << VCI_KCBIT_COWBL) |
22656 + (1 << VCI_KCBIT_FULLCOWBL) |
22658 + (1 << VCI_KCBIT_SPACES) |
22659 + (1 << VCI_KCBIT_NETV2) |
22660 +#ifdef CONFIG_MEMCG
22661 + (1 << VCI_KCBIT_MEMCG) |
22663 +#ifdef CONFIG_MEMCG_SWAP
22664 + (1 << VCI_KCBIT_MEMCG_SWAP) |
22667 + /* debug options */
22668 +#ifdef CONFIG_VSERVER_DEBUG
22669 + (1 << VCI_KCBIT_DEBUG) |
22671 +#ifdef CONFIG_VSERVER_HISTORY
22672 + (1 << VCI_KCBIT_HISTORY) |
22675 + /* inode context tagging */
22676 +#if defined(CONFIG_TAGGING_NONE)
22677 + (0 << VCI_KCBIT_TAGGED) |
22678 +#elif defined(CONFIG_TAGGING_UID16)
22679 + (1 << VCI_KCBIT_TAGGED) |
22680 +#elif defined(CONFIG_TAGGING_GID16)
22681 + (2 << VCI_KCBIT_TAGGED) |
22682 +#elif defined(CONFIG_TAGGING_ID24)
22683 + (3 << VCI_KCBIT_TAGGED) |
22684 +#elif defined(CONFIG_TAGGING_INTERN)
22685 + (4 << VCI_KCBIT_TAGGED) |
22686 +#elif defined(CONFIG_TAGGING_RUNTIME)
22687 + (5 << VCI_KCBIT_TAGGED) |
22689 + (7 << VCI_KCBIT_TAGGED) |
22691 + (1 << VCI_KCBIT_PPTAG) |
22695 diff -NurpP --minimal linux-4.9.76/mm/memcontrol.c linux-4.9.76-vs2.3.9.5/mm/memcontrol.c
22696 --- linux-4.9.76/mm/memcontrol.c 2018-01-13 21:29:01.000000000 +0000
22697 +++ linux-4.9.76-vs2.3.9.5/mm/memcontrol.c 2018-01-10 08:42:06.000000000 +0000
22698 @@ -2825,6 +2825,26 @@ static u64 mem_cgroup_read_u64(struct cg
22702 +u64 mem_cgroup_mem_usage_pages(struct mem_cgroup *memcg)
22704 + return mem_cgroup_usage(memcg, false) >> PAGE_SHIFT;
22707 +u64 mem_cgroup_mem_limit_pages(struct mem_cgroup *memcg)
22709 + return (u64)memcg->memory.limit;
22712 +u64 mem_cgroup_memsw_usage_pages(struct mem_cgroup *memcg)
22714 + return mem_cgroup_usage(memcg, true) >> PAGE_SHIFT;
22717 +u64 mem_cgroup_memsw_limit_pages(struct mem_cgroup *memcg)
22719 + return (u64)memcg->memsw.limit;
22722 #ifndef CONFIG_SLOB
22723 static int memcg_online_kmem(struct mem_cgroup *memcg)
22725 diff -NurpP --minimal linux-4.9.76/mm/oom_kill.c linux-4.9.76-vs2.3.9.5/mm/oom_kill.c
22726 --- linux-4.9.76/mm/oom_kill.c 2018-01-13 21:29:01.000000000 +0000
22727 +++ linux-4.9.76-vs2.3.9.5/mm/oom_kill.c 2018-01-10 08:54:40.000000000 +0000
22729 #include <linux/kthread.h>
22730 #include <linux/init.h>
22731 #include <linux/mmu_notifier.h>
22732 +#include <linux/reboot.h>
22733 +#include <linux/vs_context.h>
22735 #include <asm/tlb.h>
22736 #include "internal.h"
22737 @@ -142,11 +144,18 @@ static inline bool is_memcg_oom(struct o
22738 static bool oom_unkillable_task(struct task_struct *p,
22739 struct mem_cgroup *memcg, const nodemask_t *nodemask)
22741 - if (is_global_init(p))
22742 + unsigned xid = vx_current_xid();
22744 + /* skip the init task, global and per guest */
22745 + if (task_is_init(p))
22747 if (p->flags & PF_KTHREAD)
22750 + /* skip other guest and host processes if oom in guest */
22751 + if (xid && vx_task_xid(p) != xid)
22754 /* When mem_cgroup_out_of_memory() and p is not member of the group */
22755 if (memcg && !task_in_mem_cgroup(p, memcg))
22757 @@ -851,8 +860,8 @@ static void oom_kill_process(struct oom_
22758 if (__ratelimit(&oom_rs))
22759 dump_header(oc, p);
22761 - pr_err("%s: Kill process %d (%s) score %u or sacrifice child\n",
22762 - message, task_pid_nr(p), p->comm, points);
22763 + pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
22764 + message, task_pid_nr(p), p->xid, p->comm, points);
22767 * If any of p's children has a different mm and is eligible for kill,
22768 @@ -902,8 +911,8 @@ static void oom_kill_process(struct oom_
22770 do_send_sig_info(SIGKILL, SEND_SIG_FORCED, victim, true);
22771 mark_oom_victim(victim);
22772 - pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB\n",
22773 - task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
22774 + pr_err("Killed process %d:%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB\n",
22775 + task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
22776 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
22777 K(get_mm_counter(victim->mm, MM_FILEPAGES)),
22778 K(get_mm_counter(victim->mm, MM_SHMEMPAGES)));
22779 @@ -950,6 +959,8 @@ static void oom_kill_process(struct oom_
22783 +long vs_oom_action(unsigned int);
22786 * Determines whether the kernel must panic because of the panic_on_oom sysctl.
22788 @@ -1055,7 +1066,12 @@ bool out_of_memory(struct oom_control *o
22789 /* Found nothing?!?! Either we hang forever, or we panic. */
22790 if (!oc->chosen && !is_sysrq_oom(oc) && !is_memcg_oom(oc)) {
22791 dump_header(oc, NULL);
22792 - panic("Out of memory and no killable processes...\n");
22794 + /* avoid panic for guest OOM */
22795 + if (vx_current_xid())
22796 + vs_oom_action(LINUX_REBOOT_CMD_OOM);
22798 + panic("Out of memory and no killable processes...\n");
22800 if (oc->chosen && oc->chosen != (void *)-1UL) {
22801 oom_kill_process(oc, !is_memcg_oom(oc) ? "Out of memory" :
22802 diff -NurpP --minimal linux-4.9.76/mm/page_alloc.c linux-4.9.76-vs2.3.9.5/mm/page_alloc.c
22803 --- linux-4.9.76/mm/page_alloc.c 2018-01-13 21:29:01.000000000 +0000
22804 +++ linux-4.9.76-vs2.3.9.5/mm/page_alloc.c 2018-01-10 08:55:35.000000000 +0000
22806 #include <linux/page_owner.h>
22807 #include <linux/kthread.h>
22808 #include <linux/memcontrol.h>
22809 +#include <linux/vs_base.h>
22810 +#include <linux/vs_limit.h>
22812 #include <asm/sections.h>
22813 #include <asm/tlbflush.h>
22814 @@ -4205,6 +4207,9 @@ void si_meminfo(struct sysinfo *val)
22815 val->totalhigh = totalhigh_pages;
22816 val->freehigh = nr_free_highpages();
22817 val->mem_unit = PAGE_SIZE;
22819 + if (vx_flags(VXF_VIRT_MEM, 0))
22820 + vx_vsi_meminfo(val);
22823 EXPORT_SYMBOL(si_meminfo);
22824 @@ -4239,6 +4244,9 @@ void si_meminfo_node(struct sysinfo *val
22825 val->freehigh = free_highpages;
22827 val->mem_unit = PAGE_SIZE;
22829 + if (vx_flags(VXF_VIRT_MEM, 0))
22830 + vx_vsi_meminfo(val);
22834 diff -NurpP --minimal linux-4.9.76/mm/pgtable-generic.c linux-4.9.76-vs2.3.9.5/mm/pgtable-generic.c
22835 --- linux-4.9.76/mm/pgtable-generic.c 2016-12-11 19:17:54.000000000 +0000
22836 +++ linux-4.9.76-vs2.3.9.5/mm/pgtable-generic.c 2018-01-10 02:50:49.000000000 +0000
22838 * Copyright (C) 2010 Linus Torvalds
22841 +#include <linux/mm.h>
22843 #include <linux/pagemap.h>
22844 #include <asm/tlb.h>
22845 #include <asm-generic/pgtable.h>
22846 diff -NurpP --minimal linux-4.9.76/mm/shmem.c linux-4.9.76-vs2.3.9.5/mm/shmem.c
22847 --- linux-4.9.76/mm/shmem.c 2018-01-13 21:29:01.000000000 +0000
22848 +++ linux-4.9.76-vs2.3.9.5/mm/shmem.c 2018-01-10 08:36:49.000000000 +0000
22849 @@ -2785,7 +2785,7 @@ static int shmem_statfs(struct dentry *d
22851 struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
22853 - buf->f_type = TMPFS_MAGIC;
22854 + buf->f_type = TMPFS_SUPER_MAGIC;
22855 buf->f_bsize = PAGE_SIZE;
22856 buf->f_namelen = NAME_MAX;
22857 if (sbinfo->max_blocks) {
22858 @@ -3606,7 +3606,7 @@ int shmem_fill_super(struct super_block
22859 sb->s_maxbytes = MAX_LFS_FILESIZE;
22860 sb->s_blocksize = PAGE_SIZE;
22861 sb->s_blocksize_bits = PAGE_SHIFT;
22862 - sb->s_magic = TMPFS_MAGIC;
22863 + sb->s_magic = TMPFS_SUPER_MAGIC;
22864 sb->s_op = &shmem_ops;
22865 sb->s_time_gran = 1;
22866 #ifdef CONFIG_TMPFS_XATTR
22867 diff -NurpP --minimal linux-4.9.76/mm/slab.c linux-4.9.76-vs2.3.9.5/mm/slab.c
22868 --- linux-4.9.76/mm/slab.c 2018-01-13 21:29:01.000000000 +0000
22869 +++ linux-4.9.76-vs2.3.9.5/mm/slab.c 2018-01-10 02:50:49.000000000 +0000
22870 @@ -307,6 +307,8 @@ static void kmem_cache_node_init(struct
22871 #define STATS_INC_FREEMISS(x) do { } while (0)
22874 +#include "slab_vs.h"
22879 @@ -3341,6 +3343,7 @@ slab_alloc_node(struct kmem_cache *cache
22880 /* ___cache_alloc_node can fall back to other nodes */
22881 ptr = ____cache_alloc_node(cachep, flags, nodeid);
22883 + vx_slab_alloc(cachep, flags);
22884 local_irq_restore(save_flags);
22885 ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
22887 @@ -3522,6 +3525,7 @@ void ___cache_free(struct kmem_cache *ca
22889 kmemleak_free_recursive(objp, cachep->flags);
22890 objp = cache_free_debugcheck(cachep, objp, caller);
22891 + vx_slab_free(cachep);
22893 kmemcheck_slab_free(cachep, objp, cachep->object_size);
22895 diff -NurpP --minimal linux-4.9.76/mm/slab_vs.h linux-4.9.76-vs2.3.9.5/mm/slab_vs.h
22896 --- linux-4.9.76/mm/slab_vs.h 1970-01-01 00:00:00.000000000 +0000
22897 +++ linux-4.9.76-vs2.3.9.5/mm/slab_vs.h 2018-01-10 02:50:49.000000000 +0000
22900 +#include <linux/vserver/context.h>
22902 +#include <linux/vs_context.h>
22905 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
22907 + int what = gfp_zone(cachep->allocflags);
22908 + struct vx_info *vxi = current_vx_info();
22913 + atomic_add(cachep->size, &vxi->cacct.slab[what]);
22917 +void vx_slab_free(struct kmem_cache *cachep)
22919 + int what = gfp_zone(cachep->allocflags);
22920 + struct vx_info *vxi = current_vx_info();
22925 + atomic_sub(cachep->size, &vxi->cacct.slab[what]);
22928 diff -NurpP --minimal linux-4.9.76/mm/swapfile.c linux-4.9.76-vs2.3.9.5/mm/swapfile.c
22929 --- linux-4.9.76/mm/swapfile.c 2018-01-13 21:29:01.000000000 +0000
22930 +++ linux-4.9.76-vs2.3.9.5/mm/swapfile.c 2018-01-10 02:50:49.000000000 +0000
22932 #include <asm/tlbflush.h>
22933 #include <linux/swapops.h>
22934 #include <linux/swap_cgroup.h>
22935 +#include <linux/vs_base.h>
22937 static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
22939 @@ -2083,6 +2084,16 @@ static int swap_show(struct seq_file *sw
22941 if (si == SEQ_START_TOKEN) {
22942 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
22943 + if (vx_flags(VXF_VIRT_MEM, 0)) {
22944 + struct sysinfo si = { 0 };
22946 + vx_vsi_swapinfo(&si);
22947 + if (si.totalswap < (1 << 10))
22949 + seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
22950 + "hdv0", "partition", si.totalswap >> 10,
22951 + (si.totalswap - si.freeswap) >> 10, -1);
22956 @@ -2612,6 +2623,8 @@ void si_swapinfo(struct sysinfo *val)
22957 val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
22958 val->totalswap = total_swap_pages + nr_to_be_unused;
22959 spin_unlock(&swap_lock);
22960 + if (vx_flags(VXF_VIRT_MEM, 0))
22961 + vx_vsi_swapinfo(val);
22965 diff -NurpP --minimal linux-4.9.76/net/bridge/br_multicast.c linux-4.9.76-vs2.3.9.5/net/bridge/br_multicast.c
22966 --- linux-4.9.76/net/bridge/br_multicast.c 2016-12-11 19:17:54.000000000 +0000
22967 +++ linux-4.9.76-vs2.3.9.5/net/bridge/br_multicast.c 2018-01-10 02:50:49.000000000 +0000
22968 @@ -465,7 +465,7 @@ static struct sk_buff *br_ip6_multicast_
22969 ip6h->hop_limit = 1;
22970 ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
22971 if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
22973 + &ip6h->saddr, NULL)) {
22975 br->has_ipv6_addr = 0;
22977 diff -NurpP --minimal linux-4.9.76/net/core/dev.c linux-4.9.76-vs2.3.9.5/net/core/dev.c
22978 --- linux-4.9.76/net/core/dev.c 2018-01-13 21:29:01.000000000 +0000
22979 +++ linux-4.9.76-vs2.3.9.5/net/core/dev.c 2018-01-10 02:50:49.000000000 +0000
22980 @@ -126,6 +126,7 @@
22981 #include <linux/in.h>
22982 #include <linux/jhash.h>
22983 #include <linux/random.h>
22984 +#include <linux/vs_inet.h>
22985 #include <trace/events/napi.h>
22986 #include <trace/events/net.h>
22987 #include <trace/events/skb.h>
22988 @@ -730,7 +731,8 @@ struct net_device *__dev_get_by_name(str
22989 struct hlist_head *head = dev_name_hash(net, name);
22991 hlist_for_each_entry(dev, head, name_hlist)
22992 - if (!strncmp(dev->name, name, IFNAMSIZ))
22993 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
22994 + nx_dev_visible(current_nx_info(), dev))
22998 @@ -755,7 +757,8 @@ struct net_device *dev_get_by_name_rcu(s
22999 struct hlist_head *head = dev_name_hash(net, name);
23001 hlist_for_each_entry_rcu(dev, head, name_hlist)
23002 - if (!strncmp(dev->name, name, IFNAMSIZ))
23003 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
23004 + nx_dev_visible(current_nx_info(), dev))
23008 @@ -805,7 +808,8 @@ struct net_device *__dev_get_by_index(st
23009 struct hlist_head *head = dev_index_hash(net, ifindex);
23011 hlist_for_each_entry(dev, head, index_hlist)
23012 - if (dev->ifindex == ifindex)
23013 + if ((dev->ifindex == ifindex) &&
23014 + nx_dev_visible(current_nx_info(), dev))
23018 @@ -823,7 +827,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
23019 * about locking. The caller must hold RCU lock.
23022 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23023 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
23025 struct net_device *dev;
23026 struct hlist_head *head = dev_index_hash(net, ifindex);
23027 @@ -834,6 +838,16 @@ struct net_device *dev_get_by_index_rcu(
23031 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23033 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23035 + struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23037 + if (nx_dev_visible(current_nx_info(), dev))
23041 EXPORT_SYMBOL(dev_get_by_index_rcu);
23044 @@ -916,7 +930,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23046 for_each_netdev_rcu(net, dev)
23047 if (dev->type == type &&
23048 - !memcmp(dev->dev_addr, ha, dev->addr_len))
23049 + !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23050 + nx_dev_visible(current_nx_info(), dev))
23054 @@ -928,9 +943,11 @@ struct net_device *__dev_getfirstbyhwtyp
23055 struct net_device *dev;
23058 - for_each_netdev(net, dev)
23059 - if (dev->type == type)
23060 + for_each_netdev(net, dev) {
23061 + if ((dev->type == type) &&
23062 + nx_dev_visible(current_nx_info(), dev))
23068 @@ -942,7 +959,8 @@ struct net_device *dev_getfirstbyhwtype(
23071 for_each_netdev_rcu(net, dev)
23072 - if (dev->type == type) {
23073 + if ((dev->type == type) &&
23074 + nx_dev_visible(current_nx_info(), dev)) {
23078 @@ -972,7 +990,8 @@ struct net_device *__dev_get_by_flags(st
23081 for_each_netdev(net, dev) {
23082 - if (((dev->flags ^ if_flags) & mask) == 0) {
23083 + if ((((dev->flags ^ if_flags) & mask) == 0) &&
23084 + nx_dev_visible(current_nx_info(), dev)) {
23088 @@ -1050,6 +1069,8 @@ static int __dev_alloc_name(struct net *
23090 if (i < 0 || i >= max_netdevices)
23092 + if (!nx_dev_visible(current_nx_info(), d))
23095 /* avoid cases where sscanf is not exact inverse of printf */
23096 snprintf(buf, IFNAMSIZ, name, i);
23097 diff -NurpP --minimal linux-4.9.76/net/core/net-procfs.c linux-4.9.76-vs2.3.9.5/net/core/net-procfs.c
23098 --- linux-4.9.76/net/core/net-procfs.c 2016-12-11 19:17:54.000000000 +0000
23099 +++ linux-4.9.76-vs2.3.9.5/net/core/net-procfs.c 2018-01-10 02:50:49.000000000 +0000
23101 #include <linux/netdevice.h>
23102 #include <linux/proc_fs.h>
23103 #include <linux/seq_file.h>
23104 +#include <linux/vs_inet.h>
23105 #include <net/wext.h>
23107 #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
23108 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
23109 static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
23111 struct rtnl_link_stats64 temp;
23112 - const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23113 + const struct rtnl_link_stats64 *stats;
23115 + /* device visible inside network context? */
23116 + if (!nx_dev_visible(current_nx_info(), dev))
23119 + stats = dev_get_stats(dev, &temp);
23120 seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23121 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23122 dev->name, stats->rx_bytes, stats->rx_packets,
23123 diff -NurpP --minimal linux-4.9.76/net/core/rtnetlink.c linux-4.9.76-vs2.3.9.5/net/core/rtnetlink.c
23124 --- linux-4.9.76/net/core/rtnetlink.c 2018-01-13 21:29:02.000000000 +0000
23125 +++ linux-4.9.76-vs2.3.9.5/net/core/rtnetlink.c 2018-01-10 02:50:49.000000000 +0000
23126 @@ -1615,6 +1615,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23130 + if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23132 err = rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23133 NETLINK_CB(cb->skb).portid,
23134 cb->nlh->nlmsg_seq, 0,
23135 @@ -2811,6 +2813,9 @@ void rtmsg_ifinfo(int type, struct net_d
23137 struct sk_buff *skb;
23139 + if (!nx_dev_visible(current_nx_info(), dev))
23142 if (dev->reg_state != NETREG_REGISTERED)
23145 diff -NurpP --minimal linux-4.9.76/net/core/sock.c linux-4.9.76-vs2.3.9.5/net/core/sock.c
23146 --- linux-4.9.76/net/core/sock.c 2018-01-13 21:29:02.000000000 +0000
23147 +++ linux-4.9.76-vs2.3.9.5/net/core/sock.c 2018-01-13 00:48:01.000000000 +0000
23148 @@ -135,6 +135,10 @@
23150 #include <linux/filter.h>
23151 #include <net/sock_reuseport.h>
23152 +#include <linux/vs_socket.h>
23153 +#include <linux/vs_limit.h>
23154 +#include <linux/vs_context.h>
23155 +#include <linux/vs_network.h>
23157 #include <trace/events/sock.h>
23159 @@ -1339,6 +1343,8 @@ static struct sock *sk_prot_alloc(struct
23161 sk_tx_queue_clear(sk);
23163 + sock_vx_init(sk);
23164 + sock_nx_init(sk);
23168 @@ -1444,6 +1450,11 @@ static void __sk_destruct(struct rcu_hea
23169 put_pid(sk->sk_peer_pid);
23170 if (likely(sk->sk_net_refcnt))
23171 put_net(sock_net(sk));
23173 + clr_vx_info(&sk->sk_vx_info);
23175 + clr_nx_info(&sk->sk_nx_info);
23177 sk_prot_free(sk->sk_prot_creator, sk);
23180 @@ -1498,6 +1509,8 @@ struct sock *sk_clone_lock(const struct
23182 if (likely(newsk->sk_net_refcnt))
23183 get_net(sock_net(newsk));
23184 + sock_vx_init(newsk);
23185 + sock_nx_init(newsk);
23186 sk_node_init(&newsk->sk_node);
23187 sock_lock_init(newsk);
23188 bh_lock_sock(newsk);
23189 @@ -1568,6 +1581,12 @@ struct sock *sk_clone_lock(const struct
23191 atomic_set(&newsk->sk_refcnt, 2);
23193 + set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
23194 + newsk->sk_xid = sk->sk_xid;
23195 + vx_sock_inc(newsk);
23196 + set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
23197 + newsk->sk_nid = sk->sk_nid;
23200 * Increment the counter in the same struct proto as the master
23201 * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
23202 @@ -2468,6 +2487,12 @@ void sock_init_data(struct socket *sock,
23204 sk->sk_stamp = ktime_set(-1L, 0);
23206 + set_vx_info(&sk->sk_vx_info, current_vx_info());
23207 + sk->sk_xid = vx_current_xid();
23209 + set_nx_info(&sk->sk_nx_info, current_nx_info());
23210 + sk->sk_nid = nx_current_nid();
23212 #ifdef CONFIG_NET_RX_BUSY_POLL
23213 sk->sk_napi_id = 0;
23214 sk->sk_ll_usec = sysctl_net_busy_read;
23215 diff -NurpP --minimal linux-4.9.76/net/ipv4/af_inet.c linux-4.9.76-vs2.3.9.5/net/ipv4/af_inet.c
23216 --- linux-4.9.76/net/ipv4/af_inet.c 2018-01-13 21:29:02.000000000 +0000
23217 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/af_inet.c 2018-01-10 02:50:49.000000000 +0000
23218 @@ -303,10 +303,15 @@ lookup_protocol:
23222 + if ((protocol == IPPROTO_ICMP) &&
23223 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
23226 if (sock->type == SOCK_RAW && !kern &&
23227 !ns_capable(net->user_ns, CAP_NET_RAW))
23228 goto out_rcu_unlock;
23231 sock->ops = answer->ops;
23232 answer_prot = answer->prot;
23233 answer_flags = answer->flags;
23234 @@ -424,6 +429,7 @@ int inet_bind(struct socket *sock, struc
23235 struct sock *sk = sock->sk;
23236 struct inet_sock *inet = inet_sk(sk);
23237 struct net *net = sock_net(sk);
23238 + struct nx_v4_sock_addr nsa;
23239 unsigned short snum;
23241 u32 tb_id = RT_TABLE_LOCAL;
23242 @@ -449,7 +455,11 @@ int inet_bind(struct socket *sock, struc
23245 tb_id = l3mdev_fib_table_by_index(net, sk->sk_bound_dev_if) ? : tb_id;
23246 - chk_addr_ret = inet_addr_type_table(net, addr->sin_addr.s_addr, tb_id);
23247 + err = v4_map_sock_addr(inet, addr, &nsa);
23251 + chk_addr_ret = inet_addr_type_table(net, nsa.saddr, tb_id);
23253 /* Not specified by any standard per-se, however it breaks too
23254 * many applications when removed. It is unfortunate since
23255 @@ -461,7 +471,7 @@ int inet_bind(struct socket *sock, struc
23256 err = -EADDRNOTAVAIL;
23257 if (!net->ipv4.sysctl_ip_nonlocal_bind &&
23258 !(inet->freebind || inet->transparent) &&
23259 - addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
23260 + nsa.saddr != htonl(INADDR_ANY) &&
23261 chk_addr_ret != RTN_LOCAL &&
23262 chk_addr_ret != RTN_MULTICAST &&
23263 chk_addr_ret != RTN_BROADCAST)
23264 @@ -487,7 +497,7 @@ int inet_bind(struct socket *sock, struc
23265 if (sk->sk_state != TCP_CLOSE || inet->inet_num)
23266 goto out_release_sock;
23268 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23269 + v4_set_sock_addr(inet, &nsa);
23270 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23271 inet->inet_saddr = 0; /* Use device */
23273 @@ -706,11 +716,13 @@ int inet_getname(struct socket *sock, st
23276 sin->sin_port = inet->inet_dport;
23277 - sin->sin_addr.s_addr = inet->inet_daddr;
23278 + sin->sin_addr.s_addr =
23279 + nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
23281 __be32 addr = inet->inet_rcv_saddr;
23283 addr = inet->inet_saddr;
23284 + addr = nx_map_sock_lback(sk->sk_nx_info, addr);
23285 sin->sin_port = inet->inet_sport;
23286 sin->sin_addr.s_addr = addr;
23288 @@ -894,6 +906,7 @@ static int inet_compat_ioctl(struct sock
23292 +#include <linux/vs_limit.h>
23294 const struct proto_ops inet_stream_ops = {
23296 diff -NurpP --minimal linux-4.9.76/net/ipv4/arp.c linux-4.9.76-vs2.3.9.5/net/ipv4/arp.c
23297 --- linux-4.9.76/net/ipv4/arp.c 2018-01-13 21:29:02.000000000 +0000
23298 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/arp.c 2018-01-10 02:50:49.000000000 +0000
23299 @@ -1303,6 +1303,7 @@ static void arp_format_neigh_entry(struc
23300 struct net_device *dev = n->dev;
23301 int hatype = dev->type;
23303 + /* FIXME: check for network context */
23304 read_lock(&n->lock);
23305 /* Convert hardware address to XX:XX:XX:XX ... form. */
23306 #if IS_ENABLED(CONFIG_AX25)
23307 @@ -1334,6 +1335,7 @@ static void arp_format_pneigh_entry(stru
23308 int hatype = dev ? dev->type : 0;
23311 + /* FIXME: check for network context */
23312 sprintf(tbuf, "%pI4", n->key);
23313 seq_printf(seq, "%-16s 0x%-10x0x%-10x%s * %s\n",
23314 tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
23315 diff -NurpP --minimal linux-4.9.76/net/ipv4/devinet.c linux-4.9.76-vs2.3.9.5/net/ipv4/devinet.c
23316 --- linux-4.9.76/net/ipv4/devinet.c 2018-01-13 21:29:02.000000000 +0000
23317 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/devinet.c 2018-01-10 02:50:49.000000000 +0000
23318 @@ -538,6 +538,7 @@ struct in_device *inetdev_by_index(struc
23320 EXPORT_SYMBOL(inetdev_by_index);
23323 /* Called only from RTNL semaphored context. No locks. */
23325 struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
23326 @@ -992,6 +993,8 @@ int devinet_ioctl(struct net *net, unsig
23328 in_dev = __in_dev_get_rtnl(dev);
23330 + struct nx_info *nxi = current_nx_info();
23332 if (tryaddrmatch) {
23333 /* Matthias Andree */
23334 /* compare label and address (4.4BSD style) */
23335 @@ -1000,6 +1003,8 @@ int devinet_ioctl(struct net *net, unsig
23336 This is checked above. */
23337 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23338 ifap = &ifa->ifa_next) {
23339 + if (!nx_v4_ifa_visible(nxi, ifa))
23341 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
23342 sin_orig.sin_addr.s_addr ==
23344 @@ -1012,9 +1017,12 @@ int devinet_ioctl(struct net *net, unsig
23345 comparing just the label */
23347 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23348 - ifap = &ifa->ifa_next)
23349 + ifap = &ifa->ifa_next) {
23350 + if (!nx_v4_ifa_visible(nxi, ifa))
23352 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
23358 @@ -1168,6 +1176,8 @@ static int inet_gifconf(struct net_devic
23361 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
23362 + if (!nx_v4_ifa_visible(current_nx_info(), ifa))
23365 done += sizeof(ifr);
23367 @@ -1595,6 +1605,7 @@ static int inet_dump_ifaddr(struct sk_bu
23368 struct net_device *dev;
23369 struct in_device *in_dev;
23370 struct in_ifaddr *ifa;
23371 + struct sock *sk = skb->sk;
23372 struct hlist_head *head;
23375 @@ -1618,6 +1629,8 @@ static int inet_dump_ifaddr(struct sk_bu
23377 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
23378 ifa = ifa->ifa_next, ip_idx++) {
23379 + if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
23381 if (ip_idx < s_ip_idx)
23383 if (inet_fill_ifaddr(skb, ifa,
23384 diff -NurpP --minimal linux-4.9.76/net/ipv4/fib_trie.c linux-4.9.76-vs2.3.9.5/net/ipv4/fib_trie.c
23385 --- linux-4.9.76/net/ipv4/fib_trie.c 2018-01-13 21:29:02.000000000 +0000
23386 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/fib_trie.c 2018-01-10 02:50:49.000000000 +0000
23387 @@ -2617,6 +2617,7 @@ static int fib_route_seq_show(struct seq
23389 seq_setwidth(seq, 127);
23391 + /* FIXME: check for network context? */
23394 "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
23395 diff -NurpP --minimal linux-4.9.76/net/ipv4/inet_connection_sock.c linux-4.9.76-vs2.3.9.5/net/ipv4/inet_connection_sock.c
23396 --- linux-4.9.76/net/ipv4/inet_connection_sock.c 2018-01-13 21:29:02.000000000 +0000
23397 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/inet_connection_sock.c 2018-01-13 20:20:30.000000000 +0000
23399 #include <linux/module.h>
23400 #include <linux/jhash.h>
23402 +#include <net/addrconf.h>
23403 #include <net/inet_connection_sock.h>
23404 #include <net/inet_hashtables.h>
23405 #include <net/inet_timewait_sock.h>
23406 @@ -44,6 +45,7 @@ void inet_get_local_port_range(struct ne
23408 EXPORT_SYMBOL(inet_get_local_port_range);
23411 int inet_csk_bind_conflict(const struct sock *sk,
23412 const struct inet_bind_bucket *tb, bool relax)
23414 @@ -72,15 +74,13 @@ int inet_csk_bind_conflict(const struct
23415 (sk2->sk_state != TCP_TIME_WAIT &&
23416 !uid_eq(uid, sock_i_uid(sk2))))) {
23418 - if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23419 - sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23420 + if (ipv4_rcv_saddr_equal(sk, sk2, true))
23423 if (!relax && reuse && sk2->sk_reuse &&
23424 sk2->sk_state != TCP_LISTEN) {
23426 - if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23427 - sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23428 + if (ipv4_rcv_saddr_equal(sk, sk2, true))
23432 diff -NurpP --minimal linux-4.9.76/net/ipv4/inet_diag.c linux-4.9.76-vs2.3.9.5/net/ipv4/inet_diag.c
23433 --- linux-4.9.76/net/ipv4/inet_diag.c 2016-12-11 19:17:54.000000000 +0000
23434 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/inet_diag.c 2018-01-10 02:50:49.000000000 +0000
23437 #include <linux/inet.h>
23438 #include <linux/stddef.h>
23439 +#include <linux/vs_network.h>
23440 +#include <linux/vs_inet.h>
23442 #include <linux/inet_diag.h>
23443 #include <linux/sock_diag.h>
23444 @@ -879,6 +881,8 @@ void inet_diag_dump_icsk(struct inet_has
23445 if (!net_eq(sock_net(sk), net))
23448 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23453 @@ -941,6 +945,8 @@ skip_listen_ht:
23455 if (!net_eq(sock_net(sk), net))
23457 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23461 state = (sk->sk_state == TCP_TIME_WAIT) ?
23462 diff -NurpP --minimal linux-4.9.76/net/ipv4/inet_hashtables.c linux-4.9.76-vs2.3.9.5/net/ipv4/inet_hashtables.c
23463 --- linux-4.9.76/net/ipv4/inet_hashtables.c 2018-01-13 21:29:02.000000000 +0000
23464 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/inet_hashtables.c 2018-01-10 02:50:49.000000000 +0000
23466 #include <net/inet_connection_sock.h>
23467 #include <net/inet_hashtables.h>
23468 #include <net/secure_seq.h>
23469 +#include <net/route.h>
23470 #include <net/ip.h>
23471 #include <net/tcp.h>
23472 #include <net/sock_reuseport.h>
23473 @@ -186,6 +187,11 @@ static inline int compute_score(struct s
23474 if (rcv_saddr != daddr)
23478 + /* block non nx_info ips */
23479 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
23480 + daddr, NXA_MASK_BIND))
23483 if (sk->sk_bound_dev_if || exact_dif) {
23484 if (sk->sk_bound_dev_if != dif)
23485 @@ -300,6 +306,7 @@ begin:
23491 * if the nulls value we got at the end of this lookup is
23492 * not the expected one, we must restart lookup.
23493 diff -NurpP --minimal linux-4.9.76/net/ipv4/netfilter.c linux-4.9.76-vs2.3.9.5/net/ipv4/netfilter.c
23494 --- linux-4.9.76/net/ipv4/netfilter.c 2018-01-13 21:29:02.000000000 +0000
23495 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/netfilter.c 2018-01-10 02:50:49.000000000 +0000
23497 #include <linux/skbuff.h>
23498 #include <linux/gfp.h>
23499 #include <linux/export.h>
23500 -#include <net/route.h>
23501 +// #include <net/route.h>
23502 #include <net/xfrm.h>
23503 #include <net/ip.h>
23504 #include <net/netfilter/nf_queue.h>
23505 diff -NurpP --minimal linux-4.9.76/net/ipv4/raw.c linux-4.9.76-vs2.3.9.5/net/ipv4/raw.c
23506 --- linux-4.9.76/net/ipv4/raw.c 2018-01-13 21:29:02.000000000 +0000
23507 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/raw.c 2018-01-10 02:50:49.000000000 +0000
23508 @@ -128,7 +128,7 @@ static struct sock *__raw_v4_lookup(stru
23510 if (net_eq(sock_net(sk), net) && inet->inet_num == num &&
23511 !(inet->inet_daddr && inet->inet_daddr != raddr) &&
23512 - !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
23513 + v4_sock_addr_match(sk->sk_nx_info, inet, laddr) &&
23514 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23515 goto found; /* gotcha */
23517 @@ -418,6 +418,12 @@ static int raw_send_hdrinc(struct sock *
23518 skb_transport_header(skb))->type);
23522 + if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
23523 + sk->sk_nx_info &&
23524 + !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
23527 err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT,
23528 net, sk, skb, NULL, rt->dst.dev,
23530 @@ -623,6 +629,16 @@ static int raw_sendmsg(struct sock *sk,
23534 + if (sk->sk_nx_info) {
23535 + rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
23536 + if (IS_ERR(rt)) {
23537 + err = PTR_ERR(rt);
23544 security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
23545 rt = ip_route_output_flow(net, &fl4, sk);
23547 @@ -701,17 +717,19 @@ static int raw_bind(struct sock *sk, str
23549 struct inet_sock *inet = inet_sk(sk);
23550 struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
23551 + struct nx_v4_sock_addr nsa = { 0 };
23555 if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
23557 - chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
23558 + v4_map_sock_addr(inet, addr, &nsa);
23559 + chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
23560 ret = -EADDRNOTAVAIL;
23561 - if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
23562 + if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
23563 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
23565 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23566 + v4_set_sock_addr(inet, &nsa);
23567 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23568 inet->inet_saddr = 0; /* Use device */
23570 @@ -760,7 +778,8 @@ static int raw_recvmsg(struct sock *sk,
23571 /* Copy the address. */
23573 sin->sin_family = AF_INET;
23574 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
23575 + sin->sin_addr.s_addr =
23576 + nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
23578 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
23579 *addr_len = sizeof(*sin);
23580 @@ -956,7 +975,8 @@ static struct sock *raw_get_first(struct
23581 for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
23583 sk_for_each(sk, &state->h->ht[state->bucket])
23584 - if (sock_net(sk) == seq_file_net(seq))
23585 + if ((sock_net(sk) == seq_file_net(seq)) &&
23586 + nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23590 @@ -972,7 +992,8 @@ static struct sock *raw_get_next(struct
23594 - } while (sk && sock_net(sk) != seq_file_net(seq));
23595 + } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
23596 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
23598 if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
23599 sk = sk_head(&state->h->ht[state->bucket]);
23600 diff -NurpP --minimal linux-4.9.76/net/ipv4/route.c linux-4.9.76-vs2.3.9.5/net/ipv4/route.c
23601 --- linux-4.9.76/net/ipv4/route.c 2018-01-13 21:29:02.000000000 +0000
23602 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/route.c 2018-01-10 02:50:49.000000000 +0000
23603 @@ -2238,7 +2238,7 @@ struct rtable *__ip_route_output_key_has
23606 if (fl4->flowi4_oif) {
23607 - dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
23608 + dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
23609 rth = ERR_PTR(-ENODEV);
23612 diff -NurpP --minimal linux-4.9.76/net/ipv4/tcp.c linux-4.9.76-vs2.3.9.5/net/ipv4/tcp.c
23613 --- linux-4.9.76/net/ipv4/tcp.c 2018-01-13 21:29:02.000000000 +0000
23614 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/tcp.c 2018-01-10 02:50:49.000000000 +0000
23615 @@ -269,6 +269,7 @@
23616 #include <linux/err.h>
23617 #include <linux/time.h>
23618 #include <linux/slab.h>
23619 +#include <linux/in.h>
23621 #include <net/icmp.h>
23622 #include <net/inet_common.h>
23623 diff -NurpP --minimal linux-4.9.76/net/ipv4/tcp_ipv4.c linux-4.9.76-vs2.3.9.5/net/ipv4/tcp_ipv4.c
23624 --- linux-4.9.76/net/ipv4/tcp_ipv4.c 2018-01-13 21:29:02.000000000 +0000
23625 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/tcp_ipv4.c 2018-01-10 02:50:49.000000000 +0000
23626 @@ -1982,6 +1982,11 @@ static void *established_get_first(struc
23628 spin_lock_bh(lock);
23629 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
23630 + vxdprintk(VXD_CBIT(net, 6),
23631 + "sk,egf: %p [#%d] (from %d)",
23632 + sk, sk->sk_nid, nx_current_nid());
23633 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23635 if (sk->sk_family != st->family ||
23636 !net_eq(sock_net(sk), net)) {
23638 @@ -2008,6 +2013,11 @@ static void *established_get_next(struct
23639 sk = sk_nulls_next(sk);
23641 sk_nulls_for_each_from(sk, node) {
23642 + vxdprintk(VXD_CBIT(net, 6),
23643 + "sk,egn: %p [#%d] (from %d)",
23644 + sk, sk->sk_nid, nx_current_nid());
23645 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23647 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
23650 @@ -2199,9 +2209,9 @@ static void get_openreq4(const struct re
23651 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
23652 " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK",
23654 - ireq->ir_loc_addr,
23655 + nx_map_sock_lback(current_nx_info(), ireq->ir_loc_addr),
23657 - ireq->ir_rmt_addr,
23658 + nx_map_sock_lback(current_nx_info(), ireq->ir_rmt_addr),
23659 ntohs(ireq->ir_rmt_port),
23661 0, 0, /* could print option size, but that is af dependent. */
23662 @@ -2224,8 +2234,8 @@ static void get_tcp4_sock(struct sock *s
23663 const struct inet_connection_sock *icsk = inet_csk(sk);
23664 const struct inet_sock *inet = inet_sk(sk);
23665 const struct fastopen_queue *fastopenq = &icsk->icsk_accept_queue.fastopenq;
23666 - __be32 dest = inet->inet_daddr;
23667 - __be32 src = inet->inet_rcv_saddr;
23668 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
23669 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
23670 __u16 destp = ntohs(inet->inet_dport);
23671 __u16 srcp = ntohs(inet->inet_sport);
23673 @@ -2284,8 +2294,8 @@ static void get_timewait4_sock(const str
23677 - dest = tw->tw_daddr;
23678 - src = tw->tw_rcv_saddr;
23679 + dest = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
23680 + src = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
23681 destp = ntohs(tw->tw_dport);
23682 srcp = ntohs(tw->tw_sport);
23684 diff -NurpP --minimal linux-4.9.76/net/ipv4/tcp_minisocks.c linux-4.9.76-vs2.3.9.5/net/ipv4/tcp_minisocks.c
23685 --- linux-4.9.76/net/ipv4/tcp_minisocks.c 2018-01-13 21:29:02.000000000 +0000
23686 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/tcp_minisocks.c 2018-01-10 02:50:49.000000000 +0000
23688 #include <linux/slab.h>
23689 #include <linux/sysctl.h>
23690 #include <linux/workqueue.h>
23691 +#include <linux/vs_limit.h>
23692 +#include <linux/vs_socket.h>
23693 +#include <linux/vs_context.h>
23694 #include <net/tcp.h>
23695 #include <net/inet_common.h>
23696 #include <net/xfrm.h>
23697 @@ -285,6 +288,11 @@ void tcp_time_wait(struct sock *sk, int
23698 tcptw->tw_ts_offset = tp->tsoffset;
23699 tcptw->tw_last_oow_ack_time = 0;
23701 + tw->tw_xid = sk->sk_xid;
23702 + tw->tw_vx_info = NULL;
23703 + tw->tw_nid = sk->sk_nid;
23704 + tw->tw_nx_info = NULL;
23706 #if IS_ENABLED(CONFIG_IPV6)
23707 if (tw->tw_family == PF_INET6) {
23708 struct ipv6_pinfo *np = inet6_sk(sk);
23709 diff -NurpP --minimal linux-4.9.76/net/ipv4/udp.c linux-4.9.76-vs2.3.9.5/net/ipv4/udp.c
23710 --- linux-4.9.76/net/ipv4/udp.c 2018-01-13 21:29:02.000000000 +0000
23711 +++ linux-4.9.76-vs2.3.9.5/net/ipv4/udp.c 2018-01-13 20:43:44.000000000 +0000
23712 @@ -361,13 +361,27 @@ int ipv4_rcv_saddr_equal(const struct so
23713 bool match_wildcard)
23715 struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
23716 + __be32 sk1_rcv_saddr = inet1->inet_rcv_saddr,
23717 + sk2_rcv_saddr = inet2->inet_rcv_saddr;
23719 - if (!ipv6_only_sock(sk2)) {
23720 - if (inet1->inet_rcv_saddr == inet2->inet_rcv_saddr)
23722 - if (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr)
23723 - return match_wildcard;
23725 + if (ipv6_only_sock(sk2))
23728 + if (sk1_rcv_saddr && sk2_rcv_saddr && sk1_rcv_saddr == sk2_rcv_saddr)
23731 + if (match_wildcard) {
23732 + if (!sk2_rcv_saddr && !sk1_rcv_saddr)
23733 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
23735 + if (!sk2_rcv_saddr && sk1_rcv_saddr)
23736 + return v4_addr_in_nx_info(sk2->sk_nx_info,
23737 + sk1_rcv_saddr, NXA_MASK_BIND);
23739 + if (!sk1_rcv_saddr && sk2_rcv_saddr)
23740 + return v4_addr_in_nx_info(sk1->sk_nx_info,
23741 + sk2_rcv_saddr, NXA_MASK_BIND);
23746 @@ -408,6 +422,11 @@ static int compute_score(struct sock *sk
23747 if (inet->inet_rcv_saddr != daddr)
23751 + /* block non nx_info ips */
23752 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
23753 + daddr, NXA_MASK_BIND))
23757 if (inet->inet_daddr) {
23758 @@ -483,6 +502,7 @@ static struct sock *udp4_lib_lookup2(str
23763 /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
23764 * harder than this. -DaveM
23766 @@ -603,7 +623,7 @@ static inline bool __udp_is_mcast_sock(s
23767 udp_sk(sk)->udp_port_hash != hnum ||
23768 (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
23769 (inet->inet_dport != rmt_port && inet->inet_dport) ||
23770 - (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
23771 + !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
23772 ipv6_only_sock(sk) ||
23773 (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23775 @@ -1018,6 +1038,16 @@ int udp_sendmsg(struct sock *sk, struct
23777 faddr, saddr, dport, inet->inet_sport);
23779 + if (sk->sk_nx_info) {
23780 + rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
23781 + if (IS_ERR(rt)) {
23782 + err = PTR_ERR(rt);
23789 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
23790 rt = ip_route_output_flow(net, fl4, sk);
23792 @@ -1314,7 +1344,8 @@ try_again:
23794 sin->sin_family = AF_INET;
23795 sin->sin_port = udp_hdr(skb)->source;
23796 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
23797 + sin->sin_addr.s_addr = nx_map_sock_lback(
23798 + skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
23799 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
23800 *addr_len = sizeof(*sin);
23802 @@ -2260,6 +2291,8 @@ static struct sock *udp_get_first(struct
23803 sk_for_each(sk, &hslot->head) {
23804 if (!net_eq(sock_net(sk), net))
23806 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23808 if (sk->sk_family == state->family)
23811 @@ -2277,7 +2310,9 @@ static struct sock *udp_get_next(struct
23815 - } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
23816 + } while (sk && (!net_eq(sock_net(sk), net) ||
23817 + sk->sk_family != state->family ||
23818 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
23821 if (state->bucket <= state->udp_table->mask)
23822 @@ -2373,8 +2408,8 @@ static void udp4_format_sock(struct sock
23825 struct inet_sock *inet = inet_sk(sp);
23826 - __be32 dest = inet->inet_daddr;
23827 - __be32 src = inet->inet_rcv_saddr;
23828 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
23829 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
23830 __u16 destp = ntohs(inet->inet_dport);
23831 __u16 srcp = ntohs(inet->inet_sport);
23833 diff -NurpP --minimal linux-4.9.76/net/ipv6/addrconf.c linux-4.9.76-vs2.3.9.5/net/ipv6/addrconf.c
23834 --- linux-4.9.76/net/ipv6/addrconf.c 2018-01-13 21:29:02.000000000 +0000
23835 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/addrconf.c 2018-01-13 22:09:44.000000000 +0000
23837 #include <linux/proc_fs.h>
23838 #include <linux/seq_file.h>
23839 #include <linux/export.h>
23840 +#include <linux/vs_network.h>
23842 /* Set to 3 to get tracing... */
23843 #define ACONF_DEBUG 2
23844 @@ -1494,7 +1495,8 @@ static int __ipv6_dev_get_saddr(struct n
23845 struct ipv6_saddr_dst *dst,
23846 struct inet6_dev *idev,
23847 struct ipv6_saddr_score *scores,
23850 + struct nx_info *nxi)
23852 struct ipv6_saddr_score *score = &scores[1 - hiscore_idx], *hiscore = &scores[hiscore_idx];
23854 @@ -1524,6 +1526,8 @@ static int __ipv6_dev_get_saddr(struct n
23858 + if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
23862 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
23863 @@ -1574,26 +1578,27 @@ static int ipv6_get_saddr_master(struct
23864 const struct net_device *master,
23865 struct ipv6_saddr_dst *dst,
23866 struct ipv6_saddr_score *scores,
23869 + struct nx_info *nxi)
23871 struct inet6_dev *idev;
23873 idev = __in6_dev_get(dst_dev);
23875 - hiscore_idx = __ipv6_dev_get_saddr(net, dst, idev,
23876 - scores, hiscore_idx);
23877 + hiscore_idx = __ipv6_dev_get_saddr(net, dst,
23878 + idev, scores, hiscore_idx, nxi);
23880 idev = __in6_dev_get(master);
23882 - hiscore_idx = __ipv6_dev_get_saddr(net, dst, idev,
23883 - scores, hiscore_idx);
23884 + hiscore_idx = __ipv6_dev_get_saddr(net, dst,
23885 + idev, scores, hiscore_idx, nxi);
23887 return hiscore_idx;
23890 int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
23891 const struct in6_addr *daddr, unsigned int prefs,
23892 - struct in6_addr *saddr)
23893 + struct in6_addr *saddr, struct nx_info *nxi)
23895 struct ipv6_saddr_score scores[2], *hiscore;
23896 struct ipv6_saddr_dst dst;
23897 @@ -1642,7 +1647,8 @@ int ipv6_dev_get_saddr(struct net *net,
23899 if (use_oif_addr) {
23901 - hiscore_idx = __ipv6_dev_get_saddr(net, &dst, idev, scores, hiscore_idx);
23902 + hiscore_idx = __ipv6_dev_get_saddr(net,
23903 + &dst, idev, scores, hiscore_idx, nxi);
23905 const struct net_device *master;
23906 int master_idx = 0;
23907 @@ -1656,8 +1662,8 @@ int ipv6_dev_get_saddr(struct net *net,
23908 master_idx = master->ifindex;
23910 hiscore_idx = ipv6_get_saddr_master(net, dst_dev,
23912 - scores, hiscore_idx);
23913 + master, &dst, scores,
23914 + hiscore_idx, nxi);
23916 if (scores[hiscore_idx].ifa)
23918 @@ -1672,7 +1678,8 @@ int ipv6_dev_get_saddr(struct net *net,
23919 idev = __in6_dev_get(dev);
23922 - hiscore_idx = __ipv6_dev_get_saddr(net, &dst, idev, scores, hiscore_idx);
23923 + hiscore_idx = __ipv6_dev_get_saddr(net,
23924 + &dst, idev, scores, hiscore_idx, nxi);
23928 @@ -4128,7 +4135,10 @@ static void if6_seq_stop(struct seq_file
23929 static int if6_seq_show(struct seq_file *seq, void *v)
23931 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
23932 - seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
23934 + if (nx_check(0, VS_ADMIN|VS_WATCH) ||
23935 + v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
23936 + seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
23938 ifp->idev->dev->ifindex,
23940 @@ -4712,6 +4722,11 @@ static int in6_dump_addrs(struct inet6_d
23941 struct ifacaddr6 *ifaca;
23943 int ip_idx = *p_ip_idx;
23944 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
23946 + /* disable ipv6 on non v6 guests */
23947 + if (nxi && !nx_info_has_v6(nxi))
23950 read_lock_bh(&idev->lock);
23952 @@ -4722,6 +4737,8 @@ static int in6_dump_addrs(struct inet6_d
23953 list_for_each_entry(ifa, &idev->addr_list, if_list) {
23954 if (++ip_idx < s_ip_idx)
23956 + if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
23958 err = inet6_fill_ifaddr(skb, ifa,
23959 NETLINK_CB(cb->skb).portid,
23960 cb->nlh->nlmsg_seq,
23961 @@ -4739,6 +4756,8 @@ static int in6_dump_addrs(struct inet6_d
23962 ifmca = ifmca->next, ip_idx++) {
23963 if (ip_idx < s_ip_idx)
23965 + if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
23967 err = inet6_fill_ifmcaddr(skb, ifmca,
23968 NETLINK_CB(cb->skb).portid,
23969 cb->nlh->nlmsg_seq,
23970 @@ -4754,6 +4773,8 @@ static int in6_dump_addrs(struct inet6_d
23971 ifaca = ifaca->aca_next, ip_idx++) {
23972 if (ip_idx < s_ip_idx)
23974 + if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
23976 err = inet6_fill_ifacaddr(skb, ifaca,
23977 NETLINK_CB(cb->skb).portid,
23978 cb->nlh->nlmsg_seq,
23979 @@ -4782,6 +4803,10 @@ static int inet6_dump_addr(struct sk_buf
23980 struct inet6_dev *idev;
23981 struct hlist_head *head;
23983 + /* FIXME: maybe disable ipv6 on non v6 guests?
23984 + if (skb->sk && skb->sk->sk_vx_info)
23985 + return skb->len; */
23988 s_idx = idx = cb->args[1];
23989 s_ip_idx = ip_idx = cb->args[2];
23990 @@ -5300,6 +5325,7 @@ static int inet6_dump_ifinfo(struct sk_b
23991 struct net_device *dev;
23992 struct inet6_dev *idev;
23993 struct hlist_head *head;
23994 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
23997 s_idx = cb->args[1];
23998 @@ -5311,6 +5337,8 @@ static int inet6_dump_ifinfo(struct sk_b
23999 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24002 + if (!v6_dev_in_nx_info(dev, nxi))
24004 idev = __in6_dev_get(dev);
24007 diff -NurpP --minimal linux-4.9.76/net/ipv6/af_inet6.c linux-4.9.76-vs2.3.9.5/net/ipv6/af_inet6.c
24008 --- linux-4.9.76/net/ipv6/af_inet6.c 2018-01-13 21:29:02.000000000 +0000
24009 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/af_inet6.c 2018-01-13 22:10:07.000000000 +0000
24011 #include <linux/netdevice.h>
24012 #include <linux/icmpv6.h>
24013 #include <linux/netfilter_ipv6.h>
24014 +#include <linux/vs_inet.h>
24016 #include <net/ip.h>
24017 #include <net/ipv6.h>
24018 @@ -167,10 +168,13 @@ lookup_protocol:
24022 + if ((protocol == IPPROTO_ICMPV6) &&
24023 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24025 if (sock->type == SOCK_RAW && !kern &&
24026 !ns_capable(net->user_ns, CAP_NET_RAW))
24027 goto out_rcu_unlock;
24030 sock->ops = answer->ops;
24031 answer_prot = answer->prot;
24032 answer_flags = answer->flags;
24033 @@ -272,6 +276,7 @@ int inet6_bind(struct socket *sock, stru
24034 struct inet_sock *inet = inet_sk(sk);
24035 struct ipv6_pinfo *np = inet6_sk(sk);
24036 struct net *net = sock_net(sk);
24037 + struct nx_v6_sock_addr nsa;
24039 unsigned short snum;
24041 @@ -287,6 +292,10 @@ int inet6_bind(struct socket *sock, stru
24042 if (addr->sin6_family != AF_INET6)
24043 return -EAFNOSUPPORT;
24045 + err = v6_map_sock_addr(inet, addr, &nsa);
24049 addr_type = ipv6_addr_type(&addr->sin6_addr);
24050 if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
24052 @@ -327,6 +336,10 @@ int inet6_bind(struct socket *sock, stru
24053 err = -EADDRNOTAVAIL;
24056 + if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
24057 + err = -EADDRNOTAVAIL;
24061 if (addr_type != IPV6_ADDR_ANY) {
24062 struct net_device *dev = NULL;
24063 @@ -353,6 +366,11 @@ int inet6_bind(struct socket *sock, stru
24067 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24068 + err = -EADDRNOTAVAIL;
24072 /* ipv4 addr of the socket is invalid. Only the
24073 * unspecified and mapped address have a v4 equivalent.
24075 @@ -370,6 +388,9 @@ int inet6_bind(struct socket *sock, stru
24079 + /* what's that for? */
24080 + v6_set_sock_addr(inet, &nsa);
24082 inet->inet_rcv_saddr = v4addr;
24083 inet->inet_saddr = v4addr;
24085 @@ -474,9 +495,11 @@ int inet6_getname(struct socket *sock, s
24087 sin->sin6_port = inet->inet_dport;
24088 sin->sin6_addr = sk->sk_v6_daddr;
24089 + /* FIXME: remap lback? */
24091 sin->sin6_flowinfo = np->flow_label;
24093 + /* FIXME: remap lback? */
24094 if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
24095 sin->sin6_addr = np->saddr;
24097 diff -NurpP --minimal linux-4.9.76/net/ipv6/datagram.c linux-4.9.76-vs2.3.9.5/net/ipv6/datagram.c
24098 --- linux-4.9.76/net/ipv6/datagram.c 2018-01-13 21:29:02.000000000 +0000
24099 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/datagram.c 2018-01-10 02:50:49.000000000 +0000
24100 @@ -777,7 +777,7 @@ int ip6_datagram_send_ctl(struct net *ne
24103 if (fl6->flowi6_oif) {
24104 - dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
24105 + dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
24109 diff -NurpP --minimal linux-4.9.76/net/ipv6/fib6_rules.c linux-4.9.76-vs2.3.9.5/net/ipv6/fib6_rules.c
24110 --- linux-4.9.76/net/ipv6/fib6_rules.c 2018-01-13 21:29:02.000000000 +0000
24111 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/fib6_rules.c 2018-01-10 02:50:49.000000000 +0000
24112 @@ -102,7 +102,7 @@ static int fib6_rule_action(struct fib_r
24113 ip6_dst_idev(&rt->dst)->dev,
24115 rt6_flags2srcprefs(flags),
24119 if (!ipv6_prefix_equal(&saddr, &r->src.addr,
24121 diff -NurpP --minimal linux-4.9.76/net/ipv6/inet6_hashtables.c linux-4.9.76-vs2.3.9.5/net/ipv6/inet6_hashtables.c
24122 --- linux-4.9.76/net/ipv6/inet6_hashtables.c 2016-12-11 19:17:54.000000000 +0000
24123 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/inet6_hashtables.c 2018-01-13 00:26:28.000000000 +0000
24126 #include <linux/module.h>
24127 #include <linux/random.h>
24128 +#include <linux/vs_inet6.h>
24130 #include <net/addrconf.h>
24131 #include <net/inet_connection_sock.h>
24132 @@ -108,6 +109,9 @@ static inline int compute_score(struct s
24133 if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24137 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24140 if (sk->sk_bound_dev_if || exact_dif) {
24141 if (sk->sk_bound_dev_if != dif)
24142 @@ -282,39 +286,71 @@ EXPORT_SYMBOL_GPL(inet6_hash);
24143 * IPV6_ADDR_ANY only equals to IPV6_ADDR_ANY,
24144 * and 0.0.0.0 equals to 0.0.0.0 only
24146 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2,
24147 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2,
24148 bool match_wildcard)
24150 + const struct in6_addr *sk1_rcv_saddr6 = inet6_rcv_saddr(sk1);
24151 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
24152 + __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr;
24153 + __be32 sk2_rcv_saddr = sk2->sk_rcv_saddr;
24154 + int sk1_ipv6only = inet_v6_ipv6only(sk1);
24155 int sk2_ipv6only = inet_v6_ipv6only(sk2);
24156 - int addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
24157 + int addr_type1 = ipv6_addr_type(sk1_rcv_saddr6);
24158 int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
24161 + /* if one is mapped and the other is ipv6only exit early */
24162 + if (addr_type1 == IPV6_ADDR_MAPPED && sk2_ipv6only)
24165 + if (addr_type2 == IPV6_ADDR_MAPPED && sk1_ipv6only)
24168 /* if both are mapped, treat as IPv4 */
24169 - if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
24170 - if (!sk2_ipv6only) {
24171 - if (sk->sk_rcv_saddr == sk2->sk_rcv_saddr)
24173 - if (!sk->sk_rcv_saddr || !sk2->sk_rcv_saddr)
24174 - return match_wildcard;
24176 + if (addr_type1 == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
24177 + if (sk1_rcv_saddr == sk2_rcv_saddr)
24179 + if ((!sk1_rcv_saddr || !sk2_rcv_saddr) && match_wildcard)
24184 - if (addr_type == IPV6_ADDR_ANY && addr_type2 == IPV6_ADDR_ANY)
24186 + /* if both are wildcards, check for overlap */
24187 + if (addr_type1 == IPV6_ADDR_ANY && addr_type2 == IPV6_ADDR_ANY)
24188 + return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24190 - if (addr_type2 == IPV6_ADDR_ANY && match_wildcard &&
24191 - !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
24192 + /* if both are valid ipv6 addresses, mapped handled above */
24193 + if (addr_type1 != IPV6_ADDR_ANY && addr_type2 != IPV6_ADDR_ANY &&
24194 + sk2_rcv_saddr6 && ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
24197 - if (addr_type == IPV6_ADDR_ANY && match_wildcard &&
24198 - !(ipv6_only_sock(sk) && addr_type2 == IPV6_ADDR_MAPPED))
24200 + if (addr_type1 == IPV6_ADDR_ANY && match_wildcard) {
24201 + /* ipv6only case handled above */
24202 + if (addr_type2 == IPV6_ADDR_MAPPED)
24203 + return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
24205 + return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
24208 - if (sk2_rcv_saddr6 &&
24209 - ipv6_addr_equal(&sk->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24211 + if (addr_type2 == IPV6_ADDR_ANY && match_wildcard) {
24212 + /* ipv6only case handled above */
24213 + if (addr_type1 == IPV6_ADDR_MAPPED)
24214 + return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
24216 + return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
24222 + if (!sk1_rcv_saddr && !sk2_rcv_saddr)
24223 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24225 + if (!sk2_rcv_saddr)
24226 + return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
24228 + if (!sk1_rcv_saddr)
24229 + return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
24233 diff -NurpP --minimal linux-4.9.76/net/ipv6/ip6_fib.c linux-4.9.76-vs2.3.9.5/net/ipv6/ip6_fib.c
24234 --- linux-4.9.76/net/ipv6/ip6_fib.c 2018-01-13 21:29:02.000000000 +0000
24235 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/ip6_fib.c 2018-01-10 02:50:49.000000000 +0000
24236 @@ -1976,6 +1976,7 @@ static int ipv6_route_seq_show(struct se
24237 struct rt6_info *rt = v;
24238 struct ipv6_route_iter *iter = seq->private;
24240 + /* FIXME: check for network context? */
24241 seq_printf(seq, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
24243 #ifdef CONFIG_IPV6_SUBTREES
24244 diff -NurpP --minimal linux-4.9.76/net/ipv6/ip6_output.c linux-4.9.76-vs2.3.9.5/net/ipv6/ip6_output.c
24245 --- linux-4.9.76/net/ipv6/ip6_output.c 2018-01-13 21:29:02.000000000 +0000
24246 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/ip6_output.c 2018-01-10 02:50:49.000000000 +0000
24247 @@ -956,7 +956,8 @@ static int ip6_dst_lookup_tail(struct ne
24248 rt = (*dst)->error ? NULL : (struct rt6_info *)*dst;
24249 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
24250 sk ? inet6_sk(sk)->srcprefs : 0,
24253 + sk ? sk->sk_nx_info : NULL);
24255 goto out_err_release;
24257 diff -NurpP --minimal linux-4.9.76/net/ipv6/ip6_tunnel.c linux-4.9.76-vs2.3.9.5/net/ipv6/ip6_tunnel.c
24258 --- linux-4.9.76/net/ipv6/ip6_tunnel.c 2018-01-13 21:29:02.000000000 +0000
24259 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/ip6_tunnel.c 2018-01-10 08:24:13.000000000 +0000
24260 @@ -1108,7 +1108,7 @@ route_lookup:
24262 if (t->parms.collect_md &&
24263 ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
24264 - &fl6->daddr, 0, &fl6->saddr))
24265 + &fl6->daddr, 0, &fl6->saddr, NULL))
24266 goto tx_err_link_failure;
24269 diff -NurpP --minimal linux-4.9.76/net/ipv6/ndisc.c linux-4.9.76-vs2.3.9.5/net/ipv6/ndisc.c
24270 --- linux-4.9.76/net/ipv6/ndisc.c 2016-12-11 19:17:54.000000000 +0000
24271 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/ndisc.c 2018-01-10 02:50:49.000000000 +0000
24272 @@ -512,7 +512,7 @@ void ndisc_send_na(struct net_device *de
24274 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
24275 inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
24279 src_addr = &tmpaddr;
24281 diff -NurpP --minimal linux-4.9.76/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c linux-4.9.76-vs2.3.9.5/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c
24282 --- linux-4.9.76/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c 2016-12-11 19:17:54.000000000 +0000
24283 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c 2018-01-10 02:50:49.000000000 +0000
24284 @@ -39,7 +39,7 @@ nf_nat_masquerade_ipv6(struct sk_buff *s
24285 ctinfo == IP_CT_RELATED_REPLY));
24287 if (ipv6_dev_get_saddr(nf_ct_net(ct), out,
24288 - &ipv6_hdr(skb)->daddr, 0, &src) < 0)
24289 + &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
24292 nfct_nat(ct)->masq_index = out->ifindex;
24293 diff -NurpP --minimal linux-4.9.76/net/ipv6/raw.c linux-4.9.76-vs2.3.9.5/net/ipv6/raw.c
24294 --- linux-4.9.76/net/ipv6/raw.c 2018-01-13 21:29:02.000000000 +0000
24295 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/raw.c 2018-01-13 22:10:35.000000000 +0000
24296 @@ -291,6 +291,13 @@ static int rawv6_bind(struct sock *sk, s
24300 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24301 + err = -EADDRNOTAVAIL;
24307 /* ipv4 addr of the socket is invalid. Only the
24308 * unspecified and mapped address have a v4 equivalent.
24310 diff -NurpP --minimal linux-4.9.76/net/ipv6/route.c linux-4.9.76-vs2.3.9.5/net/ipv6/route.c
24311 --- linux-4.9.76/net/ipv6/route.c 2018-01-13 21:29:02.000000000 +0000
24312 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/route.c 2018-01-13 22:10:45.000000000 +0000
24313 @@ -3288,7 +3288,8 @@ static int rt6_fill_node(struct net *net
24314 goto nla_put_failure;
24316 struct in6_addr saddr_buf;
24317 - if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
24318 + if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
24319 + (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
24320 nla_put_in6_addr(skb, RTA_PREFSRC, &saddr_buf))
24321 goto nla_put_failure;
24323 diff -NurpP --minimal linux-4.9.76/net/ipv6/tcp_ipv6.c linux-4.9.76-vs2.3.9.5/net/ipv6/tcp_ipv6.c
24324 --- linux-4.9.76/net/ipv6/tcp_ipv6.c 2018-01-13 21:29:02.000000000 +0000
24325 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/tcp_ipv6.c 2018-01-13 22:10:53.000000000 +0000
24326 @@ -149,11 +149,18 @@ static int tcp_v6_connect(struct sock *s
24329 if (ipv6_addr_any(&usin->sin6_addr)) {
24330 - if (ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
24331 - ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK),
24332 - &usin->sin6_addr);
24334 - usin->sin6_addr = in6addr_loopback;
24335 + struct nx_info *nxi = sk->sk_nx_info;
24337 + if (nxi && nx_info_has_v6(nxi))
24338 + /* FIXME: remap lback? */
24339 + usin->sin6_addr = nxi->v6.ip;
24341 + if (ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
24342 + ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK),
24343 + &usin->sin6_addr);
24345 + usin->sin6_addr = in6addr_loopback;
24349 addr_type = ipv6_addr_type(&usin->sin6_addr);
24350 diff -NurpP --minimal linux-4.9.76/net/ipv6/udp.c linux-4.9.76-vs2.3.9.5/net/ipv6/udp.c
24351 --- linux-4.9.76/net/ipv6/udp.c 2018-01-13 21:29:02.000000000 +0000
24352 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/udp.c 2018-01-13 22:11:04.000000000 +0000
24353 @@ -135,6 +135,10 @@ static int compute_score(struct sock *sk
24354 if (inet->inet_dport != sport)
24358 + /* block non nx_info ips */
24359 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24363 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
24364 diff -NurpP --minimal linux-4.9.76/net/ipv6/xfrm6_policy.c linux-4.9.76-vs2.3.9.5/net/ipv6/xfrm6_policy.c
24365 --- linux-4.9.76/net/ipv6/xfrm6_policy.c 2016-12-11 19:17:54.000000000 +0000
24366 +++ linux-4.9.76-vs2.3.9.5/net/ipv6/xfrm6_policy.c 2018-01-10 02:50:49.000000000 +0000
24367 @@ -64,7 +64,8 @@ static int xfrm6_get_saddr(struct net *n
24368 return -EHOSTUNREACH;
24370 dev = ip6_dst_idev(dst)->dev;
24371 - ipv6_dev_get_saddr(dev_net(dev), dev, &daddr->in6, 0, &saddr->in6);
24372 + ipv6_dev_get_saddr(dev_net(dev), dev, &daddr->in6,
24373 + 0, &saddr->in6, NULL);
24377 diff -NurpP --minimal linux-4.9.76/net/netfilter/ipvs/ip_vs_xmit.c linux-4.9.76-vs2.3.9.5/net/netfilter/ipvs/ip_vs_xmit.c
24378 --- linux-4.9.76/net/netfilter/ipvs/ip_vs_xmit.c 2016-12-11 19:17:54.000000000 +0000
24379 +++ linux-4.9.76-vs2.3.9.5/net/netfilter/ipvs/ip_vs_xmit.c 2018-01-10 02:50:49.000000000 +0000
24380 @@ -381,7 +381,7 @@ __ip_vs_route_output_v6(struct net *net,
24382 if (ipv6_addr_any(&fl6.saddr) &&
24383 ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
24384 - &fl6.daddr, 0, &fl6.saddr) < 0)
24385 + &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
24388 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
24389 diff -NurpP --minimal linux-4.9.76/net/netlink/af_netlink.c linux-4.9.76-vs2.3.9.5/net/netlink/af_netlink.c
24390 --- linux-4.9.76/net/netlink/af_netlink.c 2018-01-13 21:29:02.000000000 +0000
24391 +++ linux-4.9.76-vs2.3.9.5/net/netlink/af_netlink.c 2018-01-10 02:50:49.000000000 +0000
24393 #include <asm/cacheflush.h>
24394 #include <linux/hash.h>
24395 #include <linux/genetlink.h>
24396 +#include <linux/vs_context.h>
24397 +#include <linux/vs_network.h>
24399 #include <net/net_namespace.h>
24400 #include <net/sock.h>
24401 @@ -2463,7 +2465,8 @@ static void *__netlink_seq_next(struct s
24403 return ERR_PTR(err);
24405 - } while (sock_net(&nlk->sk) != seq_file_net(seq));
24406 + } while ((sock_net(&nlk->sk) != seq_file_net(seq)) ||
24407 + !nx_check(nlk->sk.sk_nid, VS_WATCH_P | VS_IDENT));
24411 diff -NurpP --minimal linux-4.9.76/net/socket.c linux-4.9.76-vs2.3.9.5/net/socket.c
24412 --- linux-4.9.76/net/socket.c 2018-01-13 21:29:03.000000000 +0000
24413 +++ linux-4.9.76-vs2.3.9.5/net/socket.c 2018-01-10 02:50:49.000000000 +0000
24414 @@ -99,10 +99,12 @@
24416 #include <net/sock.h>
24417 #include <linux/netfilter.h>
24418 +#include <linux/vs_socket.h>
24419 +#include <linux/vs_inet.h>
24420 +#include <linux/vs_inet6.h>
24422 #include <linux/if_tun.h>
24423 #include <linux/ipv6_route.h>
24424 -#include <linux/route.h>
24425 #include <linux/sockios.h>
24426 #include <linux/atalk.h>
24427 #include <net/busy_poll.h>
24428 @@ -618,8 +620,24 @@ EXPORT_SYMBOL(__sock_tx_timestamp);
24430 static inline int sock_sendmsg_nosec(struct socket *sock, struct msghdr *msg)
24432 - int ret = sock->ops->sendmsg(sock, msg, msg_data_left(msg));
24433 - BUG_ON(ret == -EIOCBQUEUED);
24434 + size_t size = msg_data_left(msg);
24435 + int ret = sock->ops->sendmsg(sock, msg, size);
24439 + vx_sock_fail(sock->sk, size);
24441 + vx_sock_send(sock->sk, size);
24444 + vxdprintk(VXD_CBIT(net, 7),
24445 + "sock_sendmsg_nosec: %p[%p,%p,%p;%d/%d]:%zu/%zu",
24447 + (sock->sk)?sock->sk->sk_nx_info:0,
24448 + (sock->sk)?sock->sk->sk_vx_info:0,
24449 + (sock->sk)?sock->sk->sk_xid:0,
24450 + (sock->sk)?sock->sk->sk_nid:0,
24451 + size, msg_data_left(msg));
24455 @@ -1109,6 +1127,13 @@ int __sock_create(struct net *net, int f
24456 if (type < 0 || type >= SOCK_MAX)
24459 + if (!nx_check(0, VS_ADMIN)) {
24460 + if (family == PF_INET && !current_nx_info_has_v4())
24461 + return -EAFNOSUPPORT;
24462 + if (family == PF_INET6 && !current_nx_info_has_v6())
24463 + return -EAFNOSUPPORT;
24468 This uglymoron is moved from INET layer to here to avoid
24469 @@ -1239,6 +1264,7 @@ SYSCALL_DEFINE3(socket, int, family, int
24473 + set_bit(SOCK_USER_SOCKET, &sock->flags);
24474 retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
24477 @@ -1280,10 +1306,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
24478 err = sock_create(family, type, protocol, &sock1);
24481 + set_bit(SOCK_USER_SOCKET, &sock1->flags);
24483 err = sock_create(family, type, protocol, &sock2);
24485 goto out_release_1;
24486 + set_bit(SOCK_USER_SOCKET, &sock2->flags);
24488 err = sock1->ops->socketpair(sock1, sock2);
24490 diff -NurpP --minimal linux-4.9.76/net/sunrpc/auth.c linux-4.9.76-vs2.3.9.5/net/sunrpc/auth.c
24491 --- linux-4.9.76/net/sunrpc/auth.c 2016-12-11 19:17:54.000000000 +0000
24492 +++ linux-4.9.76-vs2.3.9.5/net/sunrpc/auth.c 2018-01-10 02:50:49.000000000 +0000
24494 #include <linux/sunrpc/clnt.h>
24495 #include <linux/sunrpc/gss_api.h>
24496 #include <linux/spinlock.h>
24497 +#include <linux/vs_tag.h>
24499 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
24500 # define RPCDBG_FACILITY RPCDBG_AUTH
24501 @@ -630,6 +631,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
24502 memset(&acred, 0, sizeof(acred));
24503 acred.uid = cred->fsuid;
24504 acred.gid = cred->fsgid;
24505 + acred.tag = make_ktag(&init_user_ns, dx_current_tag());
24506 acred.group_info = cred->group_info;
24507 ret = auth->au_ops->lookup_cred(auth, &acred, flags);
24509 @@ -669,6 +671,7 @@ rpcauth_bind_root_cred(struct rpc_task *
24510 struct auth_cred acred = {
24511 .uid = GLOBAL_ROOT_UID,
24512 .gid = GLOBAL_ROOT_GID,
24513 + .tag = KTAGT_INIT(dx_current_tag()),
24516 dprintk("RPC: %5u looking up %s cred\n",
24517 diff -NurpP --minimal linux-4.9.76/net/sunrpc/auth_unix.c linux-4.9.76-vs2.3.9.5/net/sunrpc/auth_unix.c
24518 --- linux-4.9.76/net/sunrpc/auth_unix.c 2016-12-11 19:17:54.000000000 +0000
24519 +++ linux-4.9.76-vs2.3.9.5/net/sunrpc/auth_unix.c 2018-01-10 02:50:49.000000000 +0000
24520 @@ -13,11 +13,13 @@
24521 #include <linux/sunrpc/clnt.h>
24522 #include <linux/sunrpc/auth.h>
24523 #include <linux/user_namespace.h>
24524 +#include <linux/vs_tag.h>
24526 #define NFS_NGROUPS 16
24529 struct rpc_cred uc_base;
24532 kgid_t uc_gids[NFS_NGROUPS];
24534 @@ -86,6 +88,7 @@ unx_create_cred(struct rpc_auth *auth, s
24535 groups = NFS_NGROUPS;
24537 cred->uc_gid = acred->gid;
24538 + cred->uc_tag = acred->tag;
24539 for (i = 0; i < groups; i++)
24540 cred->uc_gids[i] = acred->group_info->gid[i];
24541 if (i < NFS_NGROUPS)
24542 @@ -127,7 +130,9 @@ unx_match(struct auth_cred *acred, struc
24546 - if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
24547 + if (!uid_eq(cred->uc_uid, acred->uid) ||
24548 + !gid_eq(cred->uc_gid, acred->gid) ||
24549 + !tag_eq(cred->uc_tag, acred->tag))
24552 if (acred->group_info != NULL)
24553 @@ -152,7 +157,7 @@ unx_marshal(struct rpc_task *task, __be3
24554 struct rpc_clnt *clnt = task->tk_client;
24555 struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
24556 __be32 *base, *hold;
24560 *p++ = htonl(RPC_AUTH_UNIX);
24562 @@ -163,8 +168,11 @@ unx_marshal(struct rpc_task *task, __be3
24564 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
24566 - *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
24567 - *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
24568 + tag = task->tk_client->cl_tag;
24569 + *p++ = htonl((u32) from_kuid(&init_user_ns,
24570 + TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
24571 + *p++ = htonl((u32) from_kgid(&init_user_ns,
24572 + TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
24574 for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
24575 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
24576 diff -NurpP --minimal linux-4.9.76/net/sunrpc/clnt.c linux-4.9.76-vs2.3.9.5/net/sunrpc/clnt.c
24577 --- linux-4.9.76/net/sunrpc/clnt.c 2018-01-13 21:29:03.000000000 +0000
24578 +++ linux-4.9.76-vs2.3.9.5/net/sunrpc/clnt.c 2018-01-10 02:50:49.000000000 +0000
24580 #include <linux/in.h>
24581 #include <linux/in6.h>
24582 #include <linux/un.h>
24583 +#include <linux/vs_cvirt.h>
24585 #include <linux/sunrpc/clnt.h>
24586 #include <linux/sunrpc/addr.h>
24587 @@ -496,6 +497,9 @@ static struct rpc_clnt *rpc_create_xprt(
24588 if (!(args->flags & RPC_CLNT_CREATE_QUIET))
24589 clnt->cl_chatty = 1;
24591 + /* TODO: handle RPC_CLNT_CREATE_TAGGED
24592 + if (args->flags & RPC_CLNT_CREATE_TAGGED)
24593 + clnt->cl_tag = 1; */
24597 diff -NurpP --minimal linux-4.9.76/net/unix/af_unix.c linux-4.9.76-vs2.3.9.5/net/unix/af_unix.c
24598 --- linux-4.9.76/net/unix/af_unix.c 2018-01-13 21:29:03.000000000 +0000
24599 +++ linux-4.9.76-vs2.3.9.5/net/unix/af_unix.c 2018-01-10 02:50:49.000000000 +0000
24600 @@ -117,6 +117,8 @@
24601 #include <net/checksum.h>
24602 #include <linux/security.h>
24603 #include <linux/freezer.h>
24604 +#include <linux/vs_context.h>
24605 +#include <linux/vs_limit.h>
24607 struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
24608 EXPORT_SYMBOL_GPL(unix_socket_table);
24609 @@ -282,6 +284,8 @@ static struct sock *__unix_find_socket_b
24610 if (!net_eq(sock_net(s), net))
24613 + if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
24615 if (u->addr->len == len &&
24616 !memcmp(u->addr->name, sunname, len))
24618 @@ -2732,6 +2736,8 @@ static struct sock *unix_from_bucket(str
24619 for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
24620 if (sock_net(sk) != seq_file_net(seq))
24622 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24624 if (++count == offset)
24627 @@ -2749,6 +2755,8 @@ static struct sock *unix_next_socket(str
24631 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24633 if (sock_net(sk) == seq_file_net(seq))
24636 diff -NurpP --minimal linux-4.9.76/scripts/checksyscalls.sh linux-4.9.76-vs2.3.9.5/scripts/checksyscalls.sh
24637 --- linux-4.9.76/scripts/checksyscalls.sh 2016-12-11 19:17:54.000000000 +0000
24638 +++ linux-4.9.76-vs2.3.9.5/scripts/checksyscalls.sh 2018-01-10 02:50:49.000000000 +0000
24639 @@ -196,7 +196,6 @@ cat << EOF
24640 #define __IGNORE_afs_syscall
24641 #define __IGNORE_getpmsg
24642 #define __IGNORE_putpmsg
24643 -#define __IGNORE_vserver
24647 diff -NurpP --minimal linux-4.9.76/security/commoncap.c linux-4.9.76-vs2.3.9.5/security/commoncap.c
24648 --- linux-4.9.76/security/commoncap.c 2016-12-11 19:17:54.000000000 +0000
24649 +++ linux-4.9.76-vs2.3.9.5/security/commoncap.c 2018-01-10 02:50:49.000000000 +0000
24650 @@ -71,6 +71,7 @@ static void warn_setuid_and_fcaps_mixed(
24651 int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
24652 int cap, int audit)
24654 + struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
24655 struct user_namespace *ns = targ_ns;
24657 /* See if cred has the capability in the target user namespace
24658 @@ -79,8 +80,12 @@ int cap_capable(const struct cred *cred,
24661 /* Do we have the necessary capabilities? */
24662 - if (ns == cred->user_ns)
24663 - return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
24664 + if (ns == cred->user_ns) {
24665 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
24666 + cap_raised(cred->cap_effective, cap))
24668 + return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
24671 /* Have we tried all of the parent namespaces? */
24672 if (ns == &init_user_ns)
24673 @@ -667,7 +672,7 @@ int cap_inode_setxattr(struct dentry *de
24675 if (!strncmp(name, XATTR_SECURITY_PREFIX,
24676 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
24677 - !capable(CAP_SYS_ADMIN))
24678 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
24682 @@ -693,7 +698,7 @@ int cap_inode_removexattr(struct dentry
24684 if (!strncmp(name, XATTR_SECURITY_PREFIX,
24685 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
24686 - !capable(CAP_SYS_ADMIN))
24687 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
24691 diff -NurpP --minimal linux-4.9.76/security/selinux/hooks.c linux-4.9.76-vs2.3.9.5/security/selinux/hooks.c
24692 --- linux-4.9.76/security/selinux/hooks.c 2018-01-13 21:29:03.000000000 +0000
24693 +++ linux-4.9.76-vs2.3.9.5/security/selinux/hooks.c 2018-01-10 02:50:49.000000000 +0000
24695 #include <linux/dccp.h>
24696 #include <linux/quota.h>
24697 #include <linux/un.h> /* for Unix socket types */
24698 -#include <net/af_unix.h> /* for Unix socket types */
24699 #include <linux/parser.h>
24700 #include <linux/nfs_mount.h>
24701 #include <net/ipv6.h>