]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- vserver builds without CONFIG_BLK_DEV_VROOT and CONFIG_VSERVER_COWBL; should be...
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-4.4.110/Documentation/vserver/debug.txt linux-4.4.110-vs2.3.9/Documentation/vserver/debug.txt
2 --- linux-4.4.110/Documentation/vserver/debug.txt       1970-01-01 00:00:00.000000000 +0000
3 +++ linux-4.4.110-vs2.3.9/Documentation/vserver/debug.txt       2018-01-09 16:36:20.000000000 +0000
4 @@ -0,0 +1,154 @@
5 +
6 +debug_cvirt:
7 +
8 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
9 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
10 +
11 +debug_dlim:
12 +
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"
29 +
30 +debug_misc:
31 +
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?)"
39 +       "temp copy ?%s?"
40 + 2   4 "dentry_open(new): %p"
41 +       "dentry_open(old): %p"
42 +       "lookup_create(new): %p"
43 +       "old path ?%s?"
44 +       "path_lookup(old): %d"
45 +       "vfs_create(new): %d"
46 +       "vfs_rename: %d"
47 +       "vfs_sendfile: %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]"
54 +
55 +debug_net:
56 +
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"
69 +
70 +debug_nid:
71 +
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])"
94 +
95 +debug_quota:
96 +
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)"
102 +
103 +debug_switch:
104 +
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"
108 +
109 +debug_tag:
110 +
111 + 7  80 "dx_parse_tag(?%s?): %d:#%d"
112 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
113 +
114 +debug_xid:
115 +
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)*"
127 +       "loc_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]"
149 +
150 +
151 +debug_limit:
152 +
153 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
155 +
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.4.110/arch/alpha/Kconfig linux-4.4.110-vs2.3.9/arch/alpha/Kconfig
160 --- linux-4.4.110/arch/alpha/Kconfig    2016-07-05 04:11:34.000000000 +0000
161 +++ linux-4.4.110-vs2.3.9/arch/alpha/Kconfig    2018-01-09 16:36:20.000000000 +0000
162 @@ -745,6 +745,8 @@ config DUMMY_CONSOLE
163         depends on VGA_HOSE
164         default y
165  
166 +source "kernel/vserver/Kconfig"
167 +
168  source "security/Kconfig"
169  
170  source "crypto/Kconfig"
171 diff -NurpP --minimal linux-4.4.110/arch/alpha/kernel/systbls.S linux-4.4.110-vs2.3.9/arch/alpha/kernel/systbls.S
172 --- linux-4.4.110/arch/alpha/kernel/systbls.S   2015-07-06 20:41:36.000000000 +0000
173 +++ linux-4.4.110-vs2.3.9/arch/alpha/kernel/systbls.S   2018-01-09 16:36:20.000000000 +0000
174 @@ -446,7 +446,7 @@ sys_call_table:
175         .quad sys_stat64                        /* 425 */
176         .quad sys_lstat64
177         .quad sys_fstat64
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.4.110/arch/alpha/kernel/traps.c linux-4.4.110-vs2.3.9/arch/alpha/kernel/traps.c
184 --- linux-4.4.110/arch/alpha/kernel/traps.c     2015-07-06 20:41:36.000000000 +0000
185 +++ linux-4.4.110-vs2.3.9/arch/alpha/kernel/traps.c     2018-01-09 16:36:20.000000000 +0000
186 @@ -174,7 +174,8 @@ die_if_kernel(char * str, struct pt_regs
187  #ifdef CONFIG_SMP
188         printk("CPU %d ", hard_smp_processor_id());
189  #endif
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.4.110/arch/arm/Kconfig linux-4.4.110-vs2.3.9/arch/arm/Kconfig
197 --- linux-4.4.110/arch/arm/Kconfig      2016-07-05 04:14:23.000000000 +0000
198 +++ linux-4.4.110-vs2.3.9/arch/arm/Kconfig      2018-01-09 16:36:20.000000000 +0000
199 @@ -2159,6 +2159,8 @@ source "fs/Kconfig"
200  
201  source "arch/arm/Kconfig.debug"
202  
203 +source "kernel/vserver/Kconfig"
204 +
205  source "security/Kconfig"
206  
207  source "crypto/Kconfig"
208 diff -NurpP --minimal linux-4.4.110/arch/arm/kernel/calls.S linux-4.4.110-vs2.3.9/arch/arm/kernel/calls.S
209 --- linux-4.4.110/arch/arm/kernel/calls.S       2016-07-05 04:14:26.000000000 +0000
210 +++ linux-4.4.110-vs2.3.9/arch/arm/kernel/calls.S       2018-01-09 16:36:20.000000000 +0000
211 @@ -322,7 +322,7 @@
212  /* 310 */      CALL(sys_request_key)
213                 CALL(sys_keyctl)
214                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
215 -/* vserver */  CALL(sys_ni_syscall)
216 +               CALL(sys_vserver)
217                 CALL(sys_ioprio_set)
218  /* 315 */      CALL(sys_ioprio_get)
219                 CALL(sys_inotify_init)
220 diff -NurpP --minimal linux-4.4.110/arch/arm/kernel/traps.c linux-4.4.110-vs2.3.9/arch/arm/kernel/traps.c
221 --- linux-4.4.110/arch/arm/kernel/traps.c       2018-01-09 16:34:28.000000000 +0000
222 +++ linux-4.4.110-vs2.3.9/arch/arm/kernel/traps.c       2018-01-09 16:36:20.000000000 +0000
223 @@ -258,8 +258,8 @@ static int __die(const char *str, int er
224  
225         print_modules();
226         __show_regs(regs);
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));
231  
232         if (!user_mode(regs) || in_interrupt()) {
233                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
234 diff -NurpP --minimal linux-4.4.110/arch/cris/Kconfig linux-4.4.110-vs2.3.9/arch/cris/Kconfig
235 --- linux-4.4.110/arch/cris/Kconfig     2016-07-05 04:14:27.000000000 +0000
236 +++ linux-4.4.110-vs2.3.9/arch/cris/Kconfig     2018-01-09 16:36:20.000000000 +0000
237 @@ -581,6 +581,8 @@ source "fs/Kconfig"
238  
239  source "arch/cris/Kconfig.debug"
240  
241 +source "kernel/vserver/Kconfig"
242 +
243  source "security/Kconfig"
244  
245  source "crypto/Kconfig"
246 diff -NurpP --minimal linux-4.4.110/arch/ia64/Kconfig linux-4.4.110-vs2.3.9/arch/ia64/Kconfig
247 --- linux-4.4.110/arch/ia64/Kconfig     2016-07-05 04:11:39.000000000 +0000
248 +++ linux-4.4.110-vs2.3.9/arch/ia64/Kconfig     2018-01-09 16:36:21.000000000 +0000
249 @@ -606,6 +606,8 @@ source "fs/Kconfig"
250  
251  source "arch/ia64/Kconfig.debug"
252  
253 +source "kernel/vserver/Kconfig"
254 +
255  source "security/Kconfig"
256  
257  source "crypto/Kconfig"
258 diff -NurpP --minimal linux-4.4.110/arch/ia64/kernel/entry.S linux-4.4.110-vs2.3.9/arch/ia64/kernel/entry.S
259 --- linux-4.4.110/arch/ia64/kernel/entry.S      2016-07-05 04:14:27.000000000 +0000
260 +++ linux-4.4.110-vs2.3.9/arch/ia64/kernel/entry.S      2018-01-09 16:36:21.000000000 +0000
261 @@ -1694,7 +1694,7 @@ sys_call_table:
262         data8 sys_mq_notify
263         data8 sys_mq_getsetattr
264         data8 sys_kexec_load
265 -       data8 sys_ni_syscall                    // reserved for vserver
266 +       data8 sys_vserver
267         data8 sys_waitid                        // 1270
268         data8 sys_add_key
269         data8 sys_request_key
270 diff -NurpP --minimal linux-4.4.110/arch/ia64/kernel/ptrace.c linux-4.4.110-vs2.3.9/arch/ia64/kernel/ptrace.c
271 --- linux-4.4.110/arch/ia64/kernel/ptrace.c     2015-04-12 22:12:50.000000000 +0000
272 +++ linux-4.4.110-vs2.3.9/arch/ia64/kernel/ptrace.c     2018-01-09 16:36:21.000000000 +0000
273 @@ -21,6 +21,7 @@
274  #include <linux/regset.h>
275  #include <linux/elf.h>
276  #include <linux/tracehook.h>
277 +#include <linux/vs_base.h>
278  
279  #include <asm/pgtable.h>
280  #include <asm/processor.h>
281 diff -NurpP --minimal linux-4.4.110/arch/ia64/kernel/traps.c linux-4.4.110-vs2.3.9/arch/ia64/kernel/traps.c
282 --- linux-4.4.110/arch/ia64/kernel/traps.c      2015-04-12 22:12:50.000000000 +0000
283 +++ linux-4.4.110-vs2.3.9/arch/ia64/kernel/traps.c      2018-01-09 16:36:21.000000000 +0000
284 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
285         put_cpu();
286  
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)
294                     != NOTIFY_STOP)
295                         show_regs(regs);
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;
299                                 printk(KERN_WARNING
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);
305                         }
306                 }
307         }
308 diff -NurpP --minimal linux-4.4.110/arch/m32r/kernel/traps.c linux-4.4.110-vs2.3.9/arch/m32r/kernel/traps.c
309 --- linux-4.4.110/arch/m32r/kernel/traps.c      2015-04-12 22:12:50.000000000 +0000
310 +++ linux-4.4.110-vs2.3.9/arch/m32r/kernel/traps.c      2018-01-09 16:36:21.000000000 +0000
311 @@ -184,8 +184,9 @@ static void show_registers(struct pt_reg
312         } else {
313                 printk("SPI: %08lx\n", sp);
314         }
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);
320  
321         /*
322          * When in-kernel, we also print out the stack and code at the
323 diff -NurpP --minimal linux-4.4.110/arch/m68k/Kconfig linux-4.4.110-vs2.3.9/arch/m68k/Kconfig
324 --- linux-4.4.110/arch/m68k/Kconfig     2016-07-05 04:11:39.000000000 +0000
325 +++ linux-4.4.110-vs2.3.9/arch/m68k/Kconfig     2018-01-09 16:36:21.000000000 +0000
326 @@ -164,6 +164,8 @@ source "fs/Kconfig"
327  
328  source "arch/m68k/Kconfig.debug"
329  
330 +source "kernel/vserver/Kconfig"
331 +
332  source "security/Kconfig"
333  
334  source "crypto/Kconfig"
335 diff -NurpP --minimal linux-4.4.110/arch/mips/Kconfig linux-4.4.110-vs2.3.9/arch/mips/Kconfig
336 --- linux-4.4.110/arch/mips/Kconfig     2018-01-09 16:34:30.000000000 +0000
337 +++ linux-4.4.110-vs2.3.9/arch/mips/Kconfig     2018-01-09 16:36:21.000000000 +0000
338 @@ -3026,6 +3026,8 @@ source "fs/Kconfig"
339  
340  source "arch/mips/Kconfig.debug"
341  
342 +source "kernel/vserver/Kconfig"
343 +
344  source "security/Kconfig"
345  
346  source "crypto/Kconfig"
347 diff -NurpP --minimal linux-4.4.110/arch/mips/kernel/ptrace.c linux-4.4.110-vs2.3.9/arch/mips/kernel/ptrace.c
348 --- linux-4.4.110/arch/mips/kernel/ptrace.c     2018-01-09 16:34:30.000000000 +0000
349 +++ linux-4.4.110-vs2.3.9/arch/mips/kernel/ptrace.c     2018-01-09 16:36:21.000000000 +0000
350 @@ -30,6 +30,7 @@
351  #include <linux/audit.h>
352  #include <linux/seccomp.h>
353  #include <linux/ftrace.h>
354 +#include <linux/vs_base.h>
355  
356  #include <asm/byteorder.h>
357  #include <asm/cpu.h>
358 @@ -690,6 +691,9 @@ long arch_ptrace(struct task_struct *chi
359         void __user *datavp = (void __user *) data;
360         unsigned long __user *datalp = (void __user *) data;
361  
362 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
363 +               goto out;
364 +
365         switch (request) {
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.4.110/arch/mips/kernel/scall32-o32.S linux-4.4.110-vs2.3.9/arch/mips/kernel/scall32-o32.S
369 --- linux-4.4.110/arch/mips/kernel/scall32-o32.S        2018-01-09 16:34:30.000000000 +0000
370 +++ linux-4.4.110-vs2.3.9/arch/mips/kernel/scall32-o32.S        2018-01-09 16:36:21.000000000 +0000
371 @@ -512,7 +512,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 */
376 +       PTR     sys_vserver
377         PTR     sys_waitid
378         PTR     sys_ni_syscall                  /* available, was setaltroot */
379         PTR     sys_add_key                     /* 4280 */
380 diff -NurpP --minimal linux-4.4.110/arch/mips/kernel/scall64-64.S linux-4.4.110-vs2.3.9/arch/mips/kernel/scall64-64.S
381 --- linux-4.4.110/arch/mips/kernel/scall64-64.S 2018-01-09 16:34:30.000000000 +0000
382 +++ linux-4.4.110-vs2.3.9/arch/mips/kernel/scall64-64.S 2018-01-09 16:36:21.000000000 +0000
383 @@ -349,7 +349,7 @@ EXPORT(sys_call_table)
384         PTR     sys_mq_timedreceive
385         PTR     sys_mq_notify
386         PTR     sys_mq_getsetattr               /* 5235 */
387 -       PTR     sys_ni_syscall                  /* sys_vserver */
388 +       PTR     sys_vserver
389         PTR     sys_waitid
390         PTR     sys_ni_syscall                  /* available, was setaltroot */
391         PTR     sys_add_key
392 diff -NurpP --minimal linux-4.4.110/arch/mips/kernel/scall64-n32.S linux-4.4.110-vs2.3.9/arch/mips/kernel/scall64-n32.S
393 --- linux-4.4.110/arch/mips/kernel/scall64-n32.S        2018-01-09 16:34:30.000000000 +0000
394 +++ linux-4.4.110-vs2.3.9/arch/mips/kernel/scall64-n32.S        2018-01-09 16:36:21.000000000 +0000
395 @@ -339,7 +339,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 */
403         PTR     sys_add_key
404 diff -NurpP --minimal linux-4.4.110/arch/mips/kernel/scall64-o32.S linux-4.4.110-vs2.3.9/arch/mips/kernel/scall64-o32.S
405 --- linux-4.4.110/arch/mips/kernel/scall64-o32.S        2018-01-09 16:34:30.000000000 +0000
406 +++ linux-4.4.110-vs2.3.9/arch/mips/kernel/scall64-o32.S        2018-01-09 16:36:21.000000000 +0000
407 @@ -495,7 +495,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 */
412 +       PTR     sys32_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.4.110/arch/mips/kernel/traps.c linux-4.4.110-vs2.3.9/arch/mips/kernel/traps.c
417 --- linux-4.4.110/arch/mips/kernel/traps.c      2018-01-09 16:34:30.000000000 +0000
418 +++ linux-4.4.110-vs2.3.9/arch/mips/kernel/traps.c      2018-01-09 16:36:21.000000000 +0000
419 @@ -353,9 +353,10 @@ void show_registers(struct pt_regs *regs
420  
421         __show_regs(regs);
422         print_modules();
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) {
431                 unsigned long tls;
432  
433 diff -NurpP --minimal linux-4.4.110/arch/parisc/Kconfig linux-4.4.110-vs2.3.9/arch/parisc/Kconfig
434 --- linux-4.4.110/arch/parisc/Kconfig   2016-07-05 04:14:29.000000000 +0000
435 +++ linux-4.4.110-vs2.3.9/arch/parisc/Kconfig   2018-01-09 16:36:21.000000000 +0000
436 @@ -341,6 +341,8 @@ config SECCOMP
437  
438           If unsure, say Y. Only embedded should say N here.
439  
440 +source "kernel/vserver/Kconfig"
441 +
442  source "security/Kconfig"
443  
444  source "crypto/Kconfig"
445 diff -NurpP --minimal linux-4.4.110/arch/parisc/kernel/syscall_table.S linux-4.4.110-vs2.3.9/arch/parisc/kernel/syscall_table.S
446 --- linux-4.4.110/arch/parisc/kernel/syscall_table.S    2018-01-09 16:34:31.000000000 +0000
447 +++ linux-4.4.110-vs2.3.9/arch/parisc/kernel/syscall_table.S    2018-01-09 16:36:21.000000000 +0000
448 @@ -358,7 +358,7 @@
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)
454         ENTRY_SAME(add_key)
455         ENTRY_SAME(request_key)         /* 265 */
456         ENTRY_COMP(keyctl)
457 diff -NurpP --minimal linux-4.4.110/arch/parisc/kernel/traps.c linux-4.4.110-vs2.3.9/arch/parisc/kernel/traps.c
458 --- linux-4.4.110/arch/parisc/kernel/traps.c    2018-01-09 16:34:31.000000000 +0000
459 +++ linux-4.4.110-vs2.3.9/arch/parisc/kernel/traps.c    2018-01-09 16:36:21.000000000 +0000
460 @@ -235,8 +235,9 @@ void die_if_kernel(char *str, struct pt_
461                         return; /* STFU */
462  
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]);
469  
470                 return;
471         }
472 @@ -266,8 +267,8 @@ void die_if_kernel(char *str, struct pt_
473                 pdc_console_restart();
474         
475         if (err)
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);
480  
481         /* Wot's wrong wif bein' racy? */
482         if (current->thread.flags & PARISC_KERNEL_DEATH) {
483 diff -NurpP --minimal linux-4.4.110/arch/powerpc/Kconfig linux-4.4.110-vs2.3.9/arch/powerpc/Kconfig
484 --- linux-4.4.110/arch/powerpc/Kconfig  2018-01-09 16:34:31.000000000 +0000
485 +++ linux-4.4.110-vs2.3.9/arch/powerpc/Kconfig  2018-01-09 16:36:21.000000000 +0000
486 @@ -1080,6 +1080,8 @@ source "lib/Kconfig"
487  
488  source "arch/powerpc/Kconfig.debug"
489  
490 +source "kernel/vserver/Kconfig"
491 +
492  source "security/Kconfig"
493  
494  source "crypto/Kconfig"
495 diff -NurpP --minimal linux-4.4.110/arch/powerpc/include/uapi/asm/unistd.h linux-4.4.110-vs2.3.9/arch/powerpc/include/uapi/asm/unistd.h
496 --- linux-4.4.110/arch/powerpc/include/uapi/asm/unistd.h        2016-07-05 04:14:29.000000000 +0000
497 +++ linux-4.4.110-vs2.3.9/arch/powerpc/include/uapi/asm/unistd.h        2018-01-09 16:36:21.000000000 +0000
498 @@ -275,7 +275,7 @@
499  #endif
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.4.110/arch/powerpc/kernel/traps.c linux-4.4.110-vs2.3.9/arch/powerpc/kernel/traps.c
508 --- linux-4.4.110/arch/powerpc/kernel/traps.c   2018-01-09 16:34:31.000000000 +0000
509 +++ linux-4.4.110-vs2.3.9/arch/powerpc/kernel/traps.c   2018-01-09 16:36:21.000000000 +0000
510 @@ -1315,8 +1315,9 @@ void nonrecoverable_exception(struct pt_
511  
512  void trace_syscall(struct pt_regs *regs)
513  {
514 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
515 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
516 +       printk("Task: %p(%d:#%u), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
517 +              current, task_pid_nr(current), current->xid,
518 +              regs->nip, regs->link, regs->gpr[0],
519                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
520  }
521  
522 diff -NurpP --minimal linux-4.4.110/arch/s390/Kconfig linux-4.4.110-vs2.3.9/arch/s390/Kconfig
523 --- linux-4.4.110/arch/s390/Kconfig     2018-01-09 16:34:32.000000000 +0000
524 +++ linux-4.4.110-vs2.3.9/arch/s390/Kconfig     2018-01-09 16:36:21.000000000 +0000
525 @@ -729,6 +729,8 @@ source "fs/Kconfig"
526  
527  source "arch/s390/Kconfig.debug"
528  
529 +source "kernel/vserver/Kconfig"
530 +
531  source "security/Kconfig"
532  
533  source "crypto/Kconfig"
534 diff -NurpP --minimal linux-4.4.110/arch/s390/include/asm/tlb.h linux-4.4.110-vs2.3.9/arch/s390/include/asm/tlb.h
535 --- linux-4.4.110/arch/s390/include/asm/tlb.h   2015-07-06 20:41:37.000000000 +0000
536 +++ linux-4.4.110-vs2.3.9/arch/s390/include/asm/tlb.h   2018-01-09 16:36:21.000000000 +0000
537 @@ -24,6 +24,7 @@
538  #include <linux/mm.h>
539  #include <linux/pagemap.h>
540  #include <linux/swap.h>
541 +
542  #include <asm/processor.h>
543  #include <asm/pgalloc.h>
544  #include <asm/tlbflush.h>
545 diff -NurpP --minimal linux-4.4.110/arch/s390/include/uapi/asm/unistd.h linux-4.4.110-vs2.3.9/arch/s390/include/uapi/asm/unistd.h
546 --- linux-4.4.110/arch/s390/include/uapi/asm/unistd.h   2016-07-05 04:14:30.000000000 +0000
547 +++ linux-4.4.110-vs2.3.9/arch/s390/include/uapi/asm/unistd.h   2018-01-09 16:48:33.000000000 +0000
548 @@ -200,7 +200,7 @@
549  #define __NR_clock_gettime     260
550  #define __NR_clock_getres      261
551  #define __NR_clock_nanosleep   262
552 -/* Number 263 is reserved for vserver */
553 +#define __NR_vserver           263
554  #define __NR_statfs64          265
555  #define __NR_fstatfs64         266
556  #define __NR_remap_file_pages  267
557 diff -NurpP --minimal linux-4.4.110/arch/s390/kernel/ptrace.c linux-4.4.110-vs2.3.9/arch/s390/kernel/ptrace.c
558 --- linux-4.4.110/arch/s390/kernel/ptrace.c     2018-01-09 16:34:32.000000000 +0000
559 +++ linux-4.4.110-vs2.3.9/arch/s390/kernel/ptrace.c     2018-01-09 16:36:21.000000000 +0000
560 @@ -21,6 +21,7 @@
561  #include <linux/tracehook.h>
562  #include <linux/seccomp.h>
563  #include <linux/compat.h>
564 +#include <linux/vs_base.h>
565  #include <trace/syscall.h>
566  #include <asm/segment.h>
567  #include <asm/page.h>
568 diff -NurpP --minimal linux-4.4.110/arch/s390/kernel/syscalls.S linux-4.4.110-vs2.3.9/arch/s390/kernel/syscalls.S
569 --- linux-4.4.110/arch/s390/kernel/syscalls.S   2018-01-09 16:34:32.000000000 +0000
570 +++ linux-4.4.110-vs2.3.9/arch/s390/kernel/syscalls.S   2018-01-09 16:36:21.000000000 +0000
571 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,compat_sys_clo
572  SYSCALL(sys_clock_gettime,compat_sys_clock_gettime)    /* 260 */
573  SYSCALL(sys_clock_getres,compat_sys_clock_getres)
574  SYSCALL(sys_clock_nanosleep,compat_sys_clock_nanosleep)
575 -NI_SYSCALL                                             /* reserved for vserver */
576 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
577  SYSCALL(sys_ni_syscall,compat_sys_s390_fadvise64_64)
578  SYSCALL(sys_statfs64,compat_sys_statfs64)
579  SYSCALL(sys_fstatfs64,compat_sys_fstatfs64)
580 diff -NurpP --minimal linux-4.4.110/arch/sh/Kconfig linux-4.4.110-vs2.3.9/arch/sh/Kconfig
581 --- linux-4.4.110/arch/sh/Kconfig       2016-07-05 04:11:46.000000000 +0000
582 +++ linux-4.4.110-vs2.3.9/arch/sh/Kconfig       2018-01-09 16:36:21.000000000 +0000
583 @@ -883,6 +883,8 @@ source "fs/Kconfig"
584  
585  source "arch/sh/Kconfig.debug"
586  
587 +source "kernel/vserver/Kconfig"
588 +
589  source "security/Kconfig"
590  
591  source "crypto/Kconfig"
592 diff -NurpP --minimal linux-4.4.110/arch/sh/kernel/irq.c linux-4.4.110-vs2.3.9/arch/sh/kernel/irq.c
593 --- linux-4.4.110/arch/sh/kernel/irq.c  2016-07-05 04:11:46.000000000 +0000
594 +++ linux-4.4.110-vs2.3.9/arch/sh/kernel/irq.c  2018-01-09 16:36:21.000000000 +0000
595 @@ -14,6 +14,7 @@
596  #include <linux/ftrace.h>
597  #include <linux/delay.h>
598  #include <linux/ratelimit.h>
599 +// #include <linux/vs_context.h>
600  #include <asm/processor.h>
601  #include <asm/machvec.h>
602  #include <asm/uaccess.h>
603 diff -NurpP --minimal linux-4.4.110/arch/sparc/Kconfig linux-4.4.110-vs2.3.9/arch/sparc/Kconfig
604 --- linux-4.4.110/arch/sparc/Kconfig    2018-01-09 16:34:32.000000000 +0000
605 +++ linux-4.4.110-vs2.3.9/arch/sparc/Kconfig    2018-01-09 16:36:21.000000000 +0000
606 @@ -561,6 +561,8 @@ source "fs/Kconfig"
607  
608  source "arch/sparc/Kconfig.debug"
609  
610 +source "kernel/vserver/Kconfig"
611 +
612  source "security/Kconfig"
613  
614  source "crypto/Kconfig"
615 diff -NurpP --minimal linux-4.4.110/arch/sparc/include/uapi/asm/unistd.h linux-4.4.110-vs2.3.9/arch/sparc/include/uapi/asm/unistd.h
616 --- linux-4.4.110/arch/sparc/include/uapi/asm/unistd.h  2016-07-05 04:14:33.000000000 +0000
617 +++ linux-4.4.110-vs2.3.9/arch/sparc/include/uapi/asm/unistd.h  2018-01-09 16:36:21.000000000 +0000
618 @@ -332,7 +332,7 @@
619  #define __NR_timer_getoverrun  264
620  #define __NR_timer_delete      265
621  #define __NR_timer_create      266
622 -/* #define __NR_vserver                267 Reserved for VSERVER */
623 +#define __NR_vserver           267
624  #define __NR_io_setup          268
625  #define __NR_io_destroy                269
626  #define __NR_io_submit         270
627 diff -NurpP --minimal linux-4.4.110/arch/sparc/kernel/systbls_32.S linux-4.4.110-vs2.3.9/arch/sparc/kernel/systbls_32.S
628 --- linux-4.4.110/arch/sparc/kernel/systbls_32.S        2016-07-05 04:14:33.000000000 +0000
629 +++ linux-4.4.110-vs2.3.9/arch/sparc/kernel/systbls_32.S        2018-01-09 16:36:21.000000000 +0000
630 @@ -70,7 +70,7 @@ sys_call_table:
631  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
632  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
633  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
634 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
635 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
636  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
637  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
638  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
639 diff -NurpP --minimal linux-4.4.110/arch/sparc/kernel/systbls_64.S linux-4.4.110-vs2.3.9/arch/sparc/kernel/systbls_64.S
640 --- linux-4.4.110/arch/sparc/kernel/systbls_64.S        2016-07-05 04:14:33.000000000 +0000
641 +++ linux-4.4.110-vs2.3.9/arch/sparc/kernel/systbls_64.S        2018-01-09 16:36:21.000000000 +0000
642 @@ -71,7 +71,7 @@ sys_call_table32:
643  /*250*/        .word sys_mremap, compat_sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
644         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
645  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
646 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
647 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
648  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
649         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
650  /*280*/        .word sys_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
651 @@ -152,7 +152,7 @@ sys_call_table:
652  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
653         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
654  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
655 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
656 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
657  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
658         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
659  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
660 diff -NurpP --minimal linux-4.4.110/arch/um/Kconfig.rest linux-4.4.110-vs2.3.9/arch/um/Kconfig.rest
661 --- linux-4.4.110/arch/um/Kconfig.rest  2015-04-12 22:12:50.000000000 +0000
662 +++ linux-4.4.110-vs2.3.9/arch/um/Kconfig.rest  2018-01-09 16:36:21.000000000 +0000
663 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
664  
665  source "fs/Kconfig"
666  
667 +source "kernel/vserver/Kconfig"
668 +
669  source "security/Kconfig"
670  
671  source "crypto/Kconfig"
672 diff -NurpP --minimal linux-4.4.110/arch/x86/Kconfig linux-4.4.110-vs2.3.9/arch/x86/Kconfig
673 --- linux-4.4.110/arch/x86/Kconfig      2018-01-09 16:34:33.000000000 +0000
674 +++ linux-4.4.110-vs2.3.9/arch/x86/Kconfig      2018-01-09 16:36:21.000000000 +0000
675 @@ -2672,6 +2672,8 @@ source "fs/Kconfig"
676  
677  source "arch/x86/Kconfig.debug"
678  
679 +source "kernel/vserver/Kconfig"
680 +
681  source "security/Kconfig"
682  
683  source "crypto/Kconfig"
684 diff -NurpP --minimal linux-4.4.110/arch/x86/entry/syscalls/syscall_32.tbl linux-4.4.110-vs2.3.9/arch/x86/entry/syscalls/syscall_32.tbl
685 --- linux-4.4.110/arch/x86/entry/syscalls/syscall_32.tbl        2018-01-09 16:34:33.000000000 +0000
686 +++ linux-4.4.110-vs2.3.9/arch/x86/entry/syscalls/syscall_32.tbl        2018-01-10 01:51:14.000000000 +0000
687 @@ -279,7 +279,7 @@
688  270    i386    tgkill                  sys_tgkill
689  271    i386    utimes                  sys_utimes                      compat_sys_utimes
690  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
691 -273    i386    vserver
692 +273    i386    vserver                 sys_vserver                     sys32_vserver
693  274    i386    mbind                   sys_mbind
694  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
695  276    i386    set_mempolicy           sys_set_mempolicy
696 diff -NurpP --minimal linux-4.4.110/arch/x86/entry/syscalls/syscall_64.tbl linux-4.4.110-vs2.3.9/arch/x86/entry/syscalls/syscall_64.tbl
697 --- linux-4.4.110/arch/x86/entry/syscalls/syscall_64.tbl        2016-07-05 04:14:33.000000000 +0000
698 +++ linux-4.4.110-vs2.3.9/arch/x86/entry/syscalls/syscall_64.tbl        2018-01-10 01:51:32.000000000 +0000
699 @@ -242,7 +242,7 @@
700  233    common  epoll_ctl               sys_epoll_ctl
701  234    common  tgkill                  sys_tgkill
702  235    common  utimes                  sys_utimes
703 -236    64      vserver
704 +236    64      vserver                 sys_vserver
705  237    common  mbind                   sys_mbind
706  238    common  set_mempolicy           sys_set_mempolicy
707  239    common  get_mempolicy           sys_get_mempolicy
708 diff -NurpP --minimal linux-4.4.110/block/ioprio.c linux-4.4.110-vs2.3.9/block/ioprio.c
709 --- linux-4.4.110/block/ioprio.c        2018-01-09 16:34:34.000000000 +0000
710 +++ linux-4.4.110-vs2.3.9/block/ioprio.c        2018-01-09 16:36:23.000000000 +0000
711 @@ -28,6 +28,7 @@
712  #include <linux/syscalls.h>
713  #include <linux/security.h>
714  #include <linux/pid_namespace.h>
715 +#include <linux/vs_base.h>
716  
717  int set_task_ioprio(struct task_struct *task, int ioprio)
718  {
719 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
720                         else
721                                 pgrp = find_vpid(who);
722                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
723 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
724 +                                       continue;
725                                 ret = set_task_ioprio(p, ioprio);
726                                 if (ret)
727                                         break;
728 @@ -203,6 +206,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
729                         else
730                                 pgrp = find_vpid(who);
731                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
732 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
733 +                                       continue;
734                                 tmpio = get_task_ioprio(p);
735                                 if (tmpio < 0)
736                                         continue;
737 diff -NurpP --minimal linux-4.4.110/drivers/block/Kconfig linux-4.4.110-vs2.3.9/drivers/block/Kconfig
738 --- linux-4.4.110/drivers/block/Kconfig 2016-07-05 04:14:35.000000000 +0000
739 +++ linux-4.4.110-vs2.3.9/drivers/block/Kconfig 2018-01-09 16:36:23.000000000 +0000
740 @@ -283,6 +283,13 @@ config BLK_DEV_CRYPTOLOOP
741  
742  source "drivers/block/drbd/Kconfig"
743  
744 +config BLK_DEV_VROOT
745 +       tristate "Virtual Root device support"
746 +       depends on QUOTACTL
747 +       ---help---
748 +         Saying Y here will allow you to use quota/fs ioctls on a shared
749 +         partition within a virtual server without compromising security.
750 +
751  config BLK_DEV_NBD
752         tristate "Network block device support"
753         depends on NET
754 diff -NurpP --minimal linux-4.4.110/drivers/block/Makefile linux-4.4.110-vs2.3.9/drivers/block/Makefile
755 --- linux-4.4.110/drivers/block/Makefile        2016-07-05 04:14:35.000000000 +0000
756 +++ linux-4.4.110-vs2.3.9/drivers/block/Makefile        2018-01-09 16:36:23.000000000 +0000
757 @@ -32,6 +32,7 @@ obj-$(CONFIG_VIRTIO_BLK)      += virtio_blk.o
758  
759  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
760  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
761 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
762  
763  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
764  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
765 diff -NurpP --minimal linux-4.4.110/drivers/block/loop.c linux-4.4.110-vs2.3.9/drivers/block/loop.c
766 --- linux-4.4.110/drivers/block/loop.c  2018-01-09 16:34:35.000000000 +0000
767 +++ linux-4.4.110-vs2.3.9/drivers/block/loop.c  2018-01-09 23:00:25.000000000 +0000
768 @@ -76,6 +76,7 @@
769  #include <linux/miscdevice.h>
770  #include <linux/falloc.h>
771  #include <linux/uio.h>
772 +#include <linux/vs_context.h>
773  #include "loop.h"
774  
775  #include <asm/uaccess.h>
776 @@ -935,6 +936,7 @@ static int loop_set_fd(struct loop_devic
777         lo->lo_blocksize = lo_blocksize;
778         lo->lo_device = bdev;
779         lo->lo_flags = lo_flags;
780 +       lo->lo_xid = vx_current_xid();
781         lo->lo_backing_file = file;
782         lo->transfer = NULL;
783         lo->ioctl = NULL;
784 @@ -1055,6 +1057,7 @@ static int loop_clr_fd(struct loop_devic
785         lo->lo_offset = 0;
786         lo->lo_sizelimit = 0;
787         lo->lo_encrypt_key_size = 0;
788 +       lo->lo_xid = 0;
789         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
790         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
791         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
792 @@ -1101,7 +1104,7 @@ loop_set_status(struct loop_device *lo,
793  
794         if (lo->lo_encrypt_key_size &&
795             !uid_eq(lo->lo_key_owner, uid) &&
796 -           !capable(CAP_SYS_ADMIN))
797 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
798                 return -EPERM;
799         if (lo->lo_state != Lo_bound)
800                 return -ENXIO;
801 @@ -1202,7 +1205,8 @@ loop_get_status(struct loop_device *lo,
802         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
803         info->lo_encrypt_type =
804                 lo->lo_encryption ? lo->lo_encryption->number : 0;
805 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
806 +       if (lo->lo_encrypt_key_size &&
807 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
808                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
809                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
810                        lo->lo_encrypt_key_size);
811 @@ -1563,6 +1567,11 @@ static int lo_open(struct block_device *
812                 goto out;
813         }
814  
815 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
816 +               err = -EACCES;
817 +               goto out;
818 +       }
819 +
820         atomic_inc(&lo->lo_refcnt);
821  out:
822         mutex_unlock(&loop_index_mutex);
823 diff -NurpP --minimal linux-4.4.110/drivers/block/loop.h linux-4.4.110-vs2.3.9/drivers/block/loop.h
824 --- linux-4.4.110/drivers/block/loop.h  2016-07-05 04:14:35.000000000 +0000
825 +++ linux-4.4.110-vs2.3.9/drivers/block/loop.h  2018-01-09 16:36:23.000000000 +0000
826 @@ -43,6 +43,7 @@ struct loop_device {
827         struct loop_func_table *lo_encryption;
828         __u32           lo_init[2];
829         kuid_t          lo_key_owner;   /* Who set the key */
830 +       vxid_t          lo_xid;
831         int             (*ioctl)(struct loop_device *, int cmd, 
832                                  unsigned long arg); 
833  
834 diff -NurpP --minimal linux-4.4.110/drivers/block/vroot.c linux-4.4.110-vs2.3.9/drivers/block/vroot.c
835 --- linux-4.4.110/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
836 +++ linux-4.4.110-vs2.3.9/drivers/block/vroot.c 2018-01-09 16:36:23.000000000 +0000
837 @@ -0,0 +1,290 @@
838 +/*
839 + *  linux/drivers/block/vroot.c
840 + *
841 + *  written by Herbert P?tzl, 9/11/2002
842 + *  ported to 2.6.10 by Herbert P?tzl, 30/12/2004
843 + *
844 + *  based on the loop.c code by Theodore Ts'o.
845 + *
846 + * Copyright (C) 2002-2007 by Herbert P?tzl.
847 + * Redistribution of this file is permitted under the
848 + * GNU General Public License.
849 + *
850 + */
851 +
852 +#include <linux/module.h>
853 +#include <linux/moduleparam.h>
854 +#include <linux/file.h>
855 +#include <linux/major.h>
856 +#include <linux/blkdev.h>
857 +#include <linux/slab.h>
858 +
859 +#include <linux/vroot.h>
860 +#include <linux/vs_context.h>
861 +
862 +
863 +static int max_vroot = 8;
864 +
865 +static struct vroot_device *vroot_dev;
866 +static struct gendisk **disks;
867 +
868 +
869 +static int vroot_set_dev(
870 +       struct vroot_device *vr,
871 +       struct block_device *bdev,
872 +       unsigned int arg)
873 +{
874 +       struct block_device *real_bdev;
875 +       struct file *file;
876 +       struct inode *inode;
877 +       int error;
878 +
879 +       error = -EBUSY;
880 +       if (vr->vr_state != Vr_unbound)
881 +               goto out;
882 +
883 +       error = -EBADF;
884 +       file = fget(arg);
885 +       if (!file)
886 +               goto out;
887 +
888 +       error = -EINVAL;
889 +       inode = file->f_path.dentry->d_inode;
890 +
891 +
892 +       if (S_ISBLK(inode->i_mode)) {
893 +               real_bdev = inode->i_bdev;
894 +               vr->vr_device = real_bdev;
895 +               __iget(real_bdev->bd_inode);
896 +       } else
897 +               goto out_fput;
898 +
899 +       vxdprintk(VXD_CBIT(misc, 0),
900 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
901 +               vr->vr_number, VXD_DEV(real_bdev));
902 +
903 +       vr->vr_state = Vr_bound;
904 +       error = 0;
905 +
906 + out_fput:
907 +       fput(file);
908 + out:
909 +       return error;
910 +}
911 +
912 +static int vroot_clr_dev(
913 +       struct vroot_device *vr,
914 +       struct block_device *bdev)
915 +{
916 +       struct block_device *real_bdev;
917 +
918 +       if (vr->vr_state != Vr_bound)
919 +               return -ENXIO;
920 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
921 +               return -EBUSY;
922 +
923 +       real_bdev = vr->vr_device;
924 +
925 +       vxdprintk(VXD_CBIT(misc, 0),
926 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
927 +               vr->vr_number, VXD_DEV(real_bdev));
928 +
929 +       bdput(real_bdev);
930 +       vr->vr_state = Vr_unbound;
931 +       vr->vr_device = NULL;
932 +       return 0;
933 +}
934 +
935 +
936 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
937 +       unsigned int cmd, unsigned long arg)
938 +{
939 +       struct vroot_device *vr = bdev->bd_disk->private_data;
940 +       int err;
941 +
942 +       down(&vr->vr_ctl_mutex);
943 +       switch (cmd) {
944 +       case VROOT_SET_DEV:
945 +               err = vroot_set_dev(vr, bdev, arg);
946 +               break;
947 +       case VROOT_CLR_DEV:
948 +               err = vroot_clr_dev(vr, bdev);
949 +               break;
950 +       default:
951 +               err = -EINVAL;
952 +               break;
953 +       }
954 +       up(&vr->vr_ctl_mutex);
955 +       return err;
956 +}
957 +
958 +static int vr_open(struct block_device *bdev, fmode_t mode)
959 +{
960 +       struct vroot_device *vr = bdev->bd_disk->private_data;
961 +
962 +       down(&vr->vr_ctl_mutex);
963 +       vr->vr_refcnt++;
964 +       up(&vr->vr_ctl_mutex);
965 +       return 0;
966 +}
967 +
968 +static void vr_release(struct gendisk *disk, fmode_t mode)
969 +{
970 +       struct vroot_device *vr = disk->private_data;
971 +
972 +       down(&vr->vr_ctl_mutex);
973 +       --vr->vr_refcnt;
974 +       up(&vr->vr_ctl_mutex);
975 +}
976 +
977 +static struct block_device_operations vr_fops = {
978 +       .owner =        THIS_MODULE,
979 +       .open =         vr_open,
980 +       .release =      vr_release,
981 +       .ioctl =        vr_ioctl,
982 +};
983 +
984 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
985 +{
986 +       printk("vroot_make_request %p, %p\n", q, bio);
987 +       bio_io_error(bio);
988 +}
989 +
990 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
991 +{
992 +       struct inode *inode = bdev->bd_inode;
993 +       struct vroot_device *vr;
994 +       struct block_device *real_bdev;
995 +       int minor = iminor(inode);
996 +
997 +       vr = &vroot_dev[minor];
998 +       real_bdev = vr->vr_device;
999 +
1000 +       vxdprintk(VXD_CBIT(misc, 0),
1001 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1002 +               vr->vr_number, VXD_DEV(real_bdev));
1003 +
1004 +       if (vr->vr_state != Vr_bound)
1005 +               return ERR_PTR(-ENXIO);
1006 +
1007 +       __iget(real_bdev->bd_inode);
1008 +       return real_bdev;
1009 +}
1010 +
1011 +
1012 +
1013 +/*
1014 + * And now the modules code and kernel interface.
1015 + */
1016 +
1017 +module_param(max_vroot, int, 0);
1018 +
1019 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1020 +MODULE_LICENSE("GPL");
1021 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1022 +
1023 +MODULE_AUTHOR ("Herbert P?tzl");
1024 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1025 +
1026 +
1027 +int __init vroot_init(void)
1028 +{
1029 +       int err, i;
1030 +
1031 +       if (max_vroot < 1 || max_vroot > 256) {
1032 +               max_vroot = MAX_VROOT_DEFAULT;
1033 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1034 +                       "(must be between 1 and 256), "
1035 +                       "using default (%d)\n", max_vroot);
1036 +       }
1037 +
1038 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1039 +               return -EIO;
1040 +
1041 +       err = -ENOMEM;
1042 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1043 +       if (!vroot_dev)
1044 +               goto out_mem1;
1045 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1046 +
1047 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1048 +       if (!disks)
1049 +               goto out_mem2;
1050 +
1051 +       for (i = 0; i < max_vroot; i++) {
1052 +               disks[i] = alloc_disk(1);
1053 +               if (!disks[i])
1054 +                       goto out_mem3;
1055 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1056 +               if (!disks[i]->queue)
1057 +                       goto out_mem3;
1058 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1059 +       }
1060 +
1061 +       for (i = 0; i < max_vroot; i++) {
1062 +               struct vroot_device *vr = &vroot_dev[i];
1063 +               struct gendisk *disk = disks[i];
1064 +
1065 +               memset(vr, 0, sizeof(*vr));
1066 +               sema_init(&vr->vr_ctl_mutex, 1);
1067 +               vr->vr_number = i;
1068 +               disk->major = VROOT_MAJOR;
1069 +               disk->first_minor = i;
1070 +               disk->fops = &vr_fops;
1071 +               sprintf(disk->disk_name, "vroot%d", i);
1072 +               disk->private_data = vr;
1073 +       }
1074 +
1075 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1076 +       if (err)
1077 +               goto out_mem3;
1078 +
1079 +       for (i = 0; i < max_vroot; i++)
1080 +               add_disk(disks[i]);
1081 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1082 +       return 0;
1083 +
1084 +out_mem3:
1085 +       while (i--)
1086 +               put_disk(disks[i]);
1087 +       kfree(disks);
1088 +out_mem2:
1089 +       kfree(vroot_dev);
1090 +out_mem1:
1091 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1092 +       printk(KERN_ERR "vroot: ran out of memory\n");
1093 +       return err;
1094 +}
1095 +
1096 +void vroot_exit(void)
1097 +{
1098 +       int i;
1099 +
1100 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1101 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1102 +
1103 +       for (i = 0; i < max_vroot; i++) {
1104 +               del_gendisk(disks[i]);
1105 +               put_disk(disks[i]);
1106 +       }
1107 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1108 +
1109 +       kfree(disks);
1110 +       kfree(vroot_dev);
1111 +}
1112 +
1113 +module_init(vroot_init);
1114 +module_exit(vroot_exit);
1115 +
1116 +#ifndef MODULE
1117 +
1118 +static int __init max_vroot_setup(char *str)
1119 +{
1120 +       max_vroot = simple_strtol(str, NULL, 0);
1121 +       return 1;
1122 +}
1123 +
1124 +__setup("max_vroot=", max_vroot_setup);
1125 +
1126 +#endif
1127 +
1128 diff -NurpP --minimal linux-4.4.110/drivers/infiniband/core/addr.c linux-4.4.110-vs2.3.9/drivers/infiniband/core/addr.c
1129 --- linux-4.4.110/drivers/infiniband/core/addr.c        2018-01-09 16:34:44.000000000 +0000
1130 +++ linux-4.4.110-vs2.3.9/drivers/infiniband/core/addr.c        2018-01-09 16:49:06.000000000 +0000
1131 @@ -283,7 +283,7 @@ static int addr6_resolve(struct sockaddr
1132  
1133         if (ipv6_addr_any(&fl6.saddr)) {
1134                 ret = ipv6_dev_get_saddr(addr->net, ip6_dst_idev(dst)->dev,
1135 -                                        &fl6.daddr, 0, &fl6.saddr);
1136 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1137                 if (ret)
1138                         goto put;
1139  
1140 diff -NurpP --minimal linux-4.4.110/drivers/md/dm-ioctl.c linux-4.4.110-vs2.3.9/drivers/md/dm-ioctl.c
1141 --- linux-4.4.110/drivers/md/dm-ioctl.c 2018-01-09 16:34:46.000000000 +0000
1142 +++ linux-4.4.110-vs2.3.9/drivers/md/dm-ioctl.c 2018-01-09 16:36:23.000000000 +0000
1143 @@ -16,6 +16,7 @@
1144  #include <linux/dm-ioctl.h>
1145  #include <linux/hdreg.h>
1146  #include <linux/compat.h>
1147 +#include <linux/vs_context.h>
1148  
1149  #include <asm/uaccess.h>
1150  
1151 @@ -114,7 +115,8 @@ static struct hash_cell *__get_name_cell
1152         unsigned int h = hash_str(str);
1153  
1154         list_for_each_entry (hc, _name_buckets + h, name_list)
1155 -               if (!strcmp(hc->name, str)) {
1156 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1157 +                       !strcmp(hc->name, str)) {
1158                         dm_get(hc->md);
1159                         return hc;
1160                 }
1161 @@ -128,7 +130,8 @@ static struct hash_cell *__get_uuid_cell
1162         unsigned int h = hash_str(str);
1163  
1164         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1165 -               if (!strcmp(hc->uuid, str)) {
1166 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1167 +                       !strcmp(hc->uuid, str)) {
1168                         dm_get(hc->md);
1169                         return hc;
1170                 }
1171 @@ -139,13 +142,15 @@ static struct hash_cell *__get_uuid_cell
1172  static struct hash_cell *__get_dev_cell(uint64_t dev)
1173  {
1174         struct mapped_device *md;
1175 -       struct hash_cell *hc;
1176 +       struct hash_cell *hc = NULL;
1177  
1178         md = dm_get_md(huge_decode_dev(dev));
1179         if (!md)
1180                 return NULL;
1181  
1182 -       hc = dm_get_mdptr(md);
1183 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1184 +               hc = dm_get_mdptr(md);
1185 +
1186         if (!hc) {
1187                 dm_put(md);
1188                 return NULL;
1189 @@ -467,6 +472,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1190  
1191  static int remove_all(struct dm_ioctl *param, size_t param_size)
1192  {
1193 +       if (!vx_check(0, VS_ADMIN))
1194 +               return -EPERM;
1195 +
1196         dm_hash_remove_all(true, !!(param->flags & DM_DEFERRED_REMOVE), false);
1197         param->data_size = 0;
1198         return 0;
1199 @@ -514,6 +522,8 @@ static int list_devices(struct dm_ioctl
1200          */
1201         for (i = 0; i < NUM_BUCKETS; i++) {
1202                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1203 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1204 +                               continue;
1205                         needed += sizeof(struct dm_name_list);
1206                         needed += strlen(hc->name) + 1;
1207                         needed += ALIGN_MASK;
1208 @@ -537,6 +547,8 @@ static int list_devices(struct dm_ioctl
1209          */
1210         for (i = 0; i < NUM_BUCKETS; i++) {
1211                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1212 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1213 +                               continue;
1214                         if (old_nl)
1215                                 old_nl->next = (uint32_t) ((void *) nl -
1216                                                            (void *) old_nl);
1217 @@ -1801,8 +1813,8 @@ static int ctl_ioctl(uint command, struc
1218         size_t input_param_size;
1219         struct dm_ioctl param_kernel;
1220  
1221 -       /* only root can play with this */
1222 -       if (!capable(CAP_SYS_ADMIN))
1223 +       /* only root and certain contexts can play with this */
1224 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1225                 return -EACCES;
1226  
1227         if (_IOC_TYPE(command) != DM_IOCTL)
1228 diff -NurpP --minimal linux-4.4.110/drivers/md/dm.c linux-4.4.110-vs2.3.9/drivers/md/dm.c
1229 --- linux-4.4.110/drivers/md/dm.c       2018-01-09 16:34:46.000000000 +0000
1230 +++ linux-4.4.110-vs2.3.9/drivers/md/dm.c       2018-01-09 16:49:30.000000000 +0000
1231 @@ -25,6 +25,7 @@
1232  #include <linux/elevator.h> /* for rq_end_sector() */
1233  #include <linux/blk-mq.h>
1234  #include <linux/pr.h>
1235 +#include <linux/vs_base.h>
1236  
1237  #include <trace/events/block.h>
1238  
1239 @@ -144,6 +145,7 @@ struct mapped_device {
1240         struct mutex suspend_lock;
1241         atomic_t holders;
1242         atomic_t open_count;
1243 +       vxid_t xid;
1244  
1245         /*
1246          * The current mapping.
1247 @@ -445,6 +447,7 @@ int dm_deleting_md(struct mapped_device
1248  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1249  {
1250         struct mapped_device *md;
1251 +       int ret = -ENXIO;
1252  
1253         spin_lock(&_minor_lock);
1254  
1255 @@ -453,17 +456,19 @@ static int dm_blk_open(struct block_devi
1256                 goto out;
1257  
1258         if (test_bit(DMF_FREEING, &md->flags) ||
1259 -           dm_deleting_md(md)) {
1260 -               md = NULL;
1261 +           dm_deleting_md(md))
1262 +               goto out;
1263 +
1264 +       ret = -EACCES;
1265 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1266                 goto out;
1267 -       }
1268  
1269         dm_get(md);
1270         atomic_inc(&md->open_count);
1271 +       ret = 0;
1272  out:
1273         spin_unlock(&_minor_lock);
1274 -
1275 -       return md ? 0 : -ENXIO;
1276 +       return ret;
1277  }
1278  
1279  static void dm_blk_close(struct gendisk *disk, fmode_t mode)
1280 @@ -909,6 +914,14 @@ int dm_set_geometry(struct mapped_device
1281         return 0;
1282  }
1283  
1284 +/*
1285 + * Get the xid associated with a dm device
1286 + */
1287 +vxid_t dm_get_xid(struct mapped_device *md)
1288 +{
1289 +       return md->xid;
1290 +}
1291 +
1292  /*-----------------------------------------------------------------
1293   * CRUD START:
1294   *   A more elegant soln is in the works that uses the queue
1295 @@ -2380,6 +2393,7 @@ static struct mapped_device *alloc_dev(i
1296         INIT_LIST_HEAD(&md->table_devices);
1297         spin_lock_init(&md->uevent_lock);
1298  
1299 +       md->xid = vx_current_xid();
1300         md->queue = blk_alloc_queue(GFP_KERNEL);
1301         if (!md->queue)
1302                 goto bad;
1303 diff -NurpP --minimal linux-4.4.110/drivers/md/dm.h linux-4.4.110-vs2.3.9/drivers/md/dm.h
1304 --- linux-4.4.110/drivers/md/dm.h       2016-07-05 04:12:06.000000000 +0000
1305 +++ linux-4.4.110-vs2.3.9/drivers/md/dm.h       2018-01-09 16:36:24.000000000 +0000
1306 @@ -52,6 +52,8 @@ struct dm_dev_internal {
1307  struct dm_table;
1308  struct dm_md_mempools;
1309  
1310 +vxid_t dm_get_xid(struct mapped_device *md);
1311 +
1312  /*-----------------------------------------------------------------
1313   * Internal table functions.
1314   *---------------------------------------------------------------*/
1315 diff -NurpP --minimal linux-4.4.110/drivers/net/tun.c linux-4.4.110-vs2.3.9/drivers/net/tun.c
1316 --- linux-4.4.110/drivers/net/tun.c     2018-01-09 16:34:53.000000000 +0000
1317 +++ linux-4.4.110-vs2.3.9/drivers/net/tun.c     2018-01-09 16:36:24.000000000 +0000
1318 @@ -65,6 +65,7 @@
1319  #include <linux/nsproxy.h>
1320  #include <linux/virtio_net.h>
1321  #include <linux/rcupdate.h>
1322 +#include <linux/vs_network.h>
1323  #include <net/net_namespace.h>
1324  #include <net/netns/generic.h>
1325  #include <net/rtnetlink.h>
1326 @@ -181,6 +182,7 @@ struct tun_struct {
1327         unsigned int            flags;
1328         kuid_t                  owner;
1329         kgid_t                  group;
1330 +       vnid_t                  nid;
1331  
1332         struct net_device       *dev;
1333         netdev_features_t       set_features;
1334 @@ -475,6 +477,7 @@ static inline bool tun_not_capable(struc
1335         return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1336                   (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1337                 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1338 +               /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1339  }
1340  
1341  static void tun_set_real_num_queues(struct tun_struct *tun)
1342 @@ -1463,6 +1466,7 @@ static void tun_setup(struct net_device
1343  
1344         tun->owner = INVALID_UID;
1345         tun->group = INVALID_GID;
1346 +       tun->nid = nx_current_nid();
1347  
1348         dev->ethtool_ops = &tun_ethtool_ops;
1349         dev->destructor = tun_free_netdev;
1350 @@ -1657,7 +1661,7 @@ static int tun_set_iff(struct net *net,
1351                 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1352                              MAX_TAP_QUEUES : 1;
1353  
1354 -               if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1355 +               if (!nx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1356                         return -EPERM;
1357                 err = security_tun_dev_create();
1358                 if (err < 0)
1359 @@ -2010,6 +2014,16 @@ static long __tun_chr_ioctl(struct file
1360                           from_kgid(&init_user_ns, tun->group));
1361                 break;
1362  
1363 +       case TUNSETNID:
1364 +               if (!capable(CAP_CONTEXT))
1365 +                       return -EPERM;
1366 +
1367 +               /* Set nid owner of the device */
1368 +               tun->nid = (vnid_t) arg;
1369 +
1370 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1371 +               break;
1372 +
1373         case TUNSETLINK:
1374                 /* Only allow setting the type when the interface is down */
1375                 if (tun->dev->flags & IFF_UP) {
1376 diff -NurpP --minimal linux-4.4.110/drivers/scsi/cxgbi/libcxgbi.c linux-4.4.110-vs2.3.9/drivers/scsi/cxgbi/libcxgbi.c
1377 --- linux-4.4.110/drivers/scsi/cxgbi/libcxgbi.c 2015-10-29 09:21:24.000000000 +0000
1378 +++ linux-4.4.110-vs2.3.9/drivers/scsi/cxgbi/libcxgbi.c 2018-01-09 16:36:24.000000000 +0000
1379 @@ -768,7 +768,8 @@ static struct cxgbi_sock *cxgbi_check_ro
1380                 struct inet6_dev *idev = ip6_dst_idev((struct dst_entry *)rt);
1381  
1382                 err = ipv6_dev_get_saddr(&init_net, idev ? idev->dev : NULL,
1383 -                                        &daddr6->sin6_addr, 0, &pref_saddr);
1384 +                                        &daddr6->sin6_addr, 0, &pref_saddr,
1385 +                                        NULL);
1386                 if (err) {
1387                         pr_info("failed to get source address to reach %pI6\n",
1388                                 &daddr6->sin6_addr);
1389 diff -NurpP --minimal linux-4.4.110/drivers/tty/sysrq.c linux-4.4.110-vs2.3.9/drivers/tty/sysrq.c
1390 --- linux-4.4.110/drivers/tty/sysrq.c   2018-01-09 16:35:02.000000000 +0000
1391 +++ linux-4.4.110-vs2.3.9/drivers/tty/sysrq.c   2018-01-09 16:36:24.000000000 +0000
1392 @@ -47,6 +47,7 @@
1393  #include <linux/syscalls.h>
1394  #include <linux/of.h>
1395  #include <linux/rcupdate.h>
1396 +#include <linux/vserver/debug.h>
1397  
1398  #include <asm/ptrace.h>
1399  #include <asm/irq_regs.h>
1400 @@ -421,6 +422,21 @@ static struct sysrq_key_op sysrq_unrt_op
1401         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1402  };
1403  
1404 +
1405 +#ifdef CONFIG_VSERVER_DEBUG
1406 +static void sysrq_handle_vxinfo(int key)
1407 +{
1408 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1409 +}
1410 +
1411 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1412 +       .handler        = sysrq_handle_vxinfo,
1413 +       .help_msg       = "conteXt",
1414 +       .action_msg     = "Show Context Info",
1415 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1416 +};
1417 +#endif
1418 +
1419  /* Key Operations table and lock */
1420  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1421  
1422 @@ -477,7 +493,11 @@ static struct sysrq_key_op *sysrq_key_ta
1423         /* x: May be registered on mips for TLB dump */
1424         /* x: May be registered on ppc/powerpc for xmon */
1425         /* x: May be registered on sparc64 for global PMU dump */
1426 +#ifdef CONFIG_VSERVER_DEBUG
1427 +       &sysrq_showvxinfo_op,           /* x */
1428 +#else
1429         NULL,                           /* x */
1430 +#endif
1431         /* y: May be registered on sparc64 for global register dump */
1432         NULL,                           /* y */
1433         &sysrq_ftrace_dump_op,          /* z */
1434 @@ -492,6 +512,8 @@ static int sysrq_key_table_key2index(int
1435                 retval = key - '0';
1436         else if ((key >= 'a') && (key <= 'z'))
1437                 retval = key + 10 - 'a';
1438 +       else if ((key >= 'A') && (key <= 'Z'))
1439 +               retval = key + 10 - 'A';
1440         else
1441                 retval = -1;
1442         return retval;
1443 diff -NurpP --minimal linux-4.4.110/drivers/tty/tty_io.c linux-4.4.110-vs2.3.9/drivers/tty/tty_io.c
1444 --- linux-4.4.110/drivers/tty/tty_io.c  2018-01-09 16:35:02.000000000 +0000
1445 +++ linux-4.4.110-vs2.3.9/drivers/tty/tty_io.c  2018-01-09 16:36:24.000000000 +0000
1446 @@ -104,6 +104,7 @@
1447  
1448  #include <linux/kmod.h>
1449  #include <linux/nsproxy.h>
1450 +#include <linux/vs_pid.h>
1451  
1452  #undef TTY_DEBUG_HANGUP
1453  #ifdef TTY_DEBUG_HANGUP
1454 @@ -2280,7 +2281,8 @@ static int tiocsti(struct tty_struct *tt
1455         char ch, mbz = 0;
1456         struct tty_ldisc *ld;
1457  
1458 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1459 +       if (((current->signal->tty != tty) &&
1460 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1461                 return -EPERM;
1462         if (get_user(ch, p))
1463                 return -EFAULT;
1464 @@ -2593,6 +2595,7 @@ static int tiocspgrp(struct tty_struct *
1465                 return -ENOTTY;
1466         if (get_user(pgrp_nr, p))
1467                 return -EFAULT;
1468 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1469         if (pgrp_nr < 0)
1470                 return -EINVAL;
1471         rcu_read_lock();
1472 diff -NurpP --minimal linux-4.4.110/fs/attr.c linux-4.4.110-vs2.3.9/fs/attr.c
1473 --- linux-4.4.110/fs/attr.c     2018-01-09 16:35:04.000000000 +0000
1474 +++ linux-4.4.110-vs2.3.9/fs/attr.c     2018-01-09 17:27:12.000000000 +0000
1475 @@ -15,6 +15,9 @@
1476  #include <linux/security.h>
1477  #include <linux/evm.h>
1478  #include <linux/ima.h>
1479 +#include <linux/proc_fs.h>
1480 +#include <linux/devpts_fs.h>
1481 +#include <linux/vs_tag.h>
1482  
1483  /**
1484   * inode_change_ok - check if attribute changes to an inode are allowed
1485 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1486                         return -EPERM;
1487         }
1488  
1489 +       /* check for inode tag permission */
1490 +       if (dx_permission(inode, MAY_WRITE))
1491 +               return -EACCES;
1492 +
1493         return 0;
1494  }
1495  EXPORT_SYMBOL(inode_change_ok);
1496 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1497                 inode->i_uid = attr->ia_uid;
1498         if (ia_valid & ATTR_GID)
1499                 inode->i_gid = attr->ia_gid;
1500 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1501 +               inode->i_tag = attr->ia_tag;
1502         if (ia_valid & ATTR_ATIME)
1503                 inode->i_atime = timespec_trunc(attr->ia_atime,
1504                                                 inode->i_sb->s_time_gran);
1505 @@ -197,7 +206,8 @@ int notify_change(struct dentry * dentry
1506  
1507         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1508  
1509 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1510 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1511 +               ATTR_TAG | ATTR_TIMES_SET)) {
1512                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1513                         return -EPERM;
1514         }
1515 diff -NurpP --minimal linux-4.4.110/fs/block_dev.c linux-4.4.110-vs2.3.9/fs/block_dev.c
1516 --- linux-4.4.110/fs/block_dev.c        2018-01-09 16:35:04.000000000 +0000
1517 +++ linux-4.4.110-vs2.3.9/fs/block_dev.c        2018-01-09 17:16:29.000000000 +0000
1518 @@ -29,6 +29,7 @@
1519  #include <linux/log2.h>
1520  #include <linux/cleancache.h>
1521  #include <linux/dax.h>
1522 +#include <linux/vs_device.h>
1523  #include <asm/uaccess.h>
1524  #include "internal.h"
1525  
1526 @@ -645,6 +646,7 @@ struct block_device *bdget(dev_t dev)
1527                 bdev->bd_invalidated = 0;
1528                 inode->i_mode = S_IFBLK;
1529                 inode->i_rdev = dev;
1530 +               inode->i_mdev = dev;
1531                 inode->i_bdev = bdev;
1532                 inode->i_data.a_ops = &def_blk_aops;
1533                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1534 @@ -691,6 +693,11 @@ EXPORT_SYMBOL(bdput);
1535  static struct block_device *bd_acquire(struct inode *inode)
1536  {
1537         struct block_device *bdev;
1538 +       dev_t mdev;
1539 +
1540 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1541 +               return NULL;
1542 +       inode->i_mdev = mdev;
1543  
1544         spin_lock(&bdev_lock);
1545         bdev = inode->i_bdev;
1546 @@ -701,7 +708,7 @@ static struct block_device *bd_acquire(s
1547         }
1548         spin_unlock(&bdev_lock);
1549  
1550 -       bdev = bdget(inode->i_rdev);
1551 +       bdev = bdget(mdev);
1552         if (bdev) {
1553                 spin_lock(&bdev_lock);
1554                 if (!inode->i_bdev) {
1555 diff -NurpP --minimal linux-4.4.110/fs/btrfs/ctree.h linux-4.4.110-vs2.3.9/fs/btrfs/ctree.h
1556 --- linux-4.4.110/fs/btrfs/ctree.h      2018-01-09 16:35:04.000000000 +0000
1557 +++ linux-4.4.110-vs2.3.9/fs/btrfs/ctree.h      2018-01-09 16:36:24.000000000 +0000
1558 @@ -731,11 +731,14 @@ struct btrfs_inode_item {
1559         /* modification sequence number for NFS */
1560         __le64 sequence;
1561  
1562 +       __le16 tag;
1563         /*
1564          * a little future expansion, for more than this we can
1565          * just grow the inode item and version it
1566          */
1567 -       __le64 reserved[4];
1568 +       __le16 reserved16;
1569 +       __le32 reserved32;
1570 +       __le64 reserved[3];
1571         struct btrfs_timespec atime;
1572         struct btrfs_timespec ctime;
1573         struct btrfs_timespec mtime;
1574 @@ -2189,6 +2192,8 @@ struct btrfs_ioctl_defrag_range_args {
1575  #define BTRFS_DEFAULT_COMMIT_INTERVAL  (30)
1576  #define BTRFS_DEFAULT_MAX_INLINE       (8192)
1577  
1578 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1579 +
1580  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1581  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1582  #define btrfs_raw_test_opt(o, opt)     ((o) & BTRFS_MOUNT_##opt)
1583 @@ -2528,6 +2533,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1584  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1585  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1586  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1587 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1588  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1589  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1590  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1591 @@ -2575,6 +2581,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1592  
1593  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1594  
1595 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1596 +#define BTRFS_INODE_BARRIER            (1 << 25)
1597 +#define BTRFS_INODE_COW                        (1 << 26)
1598 +
1599  
1600  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1601  
1602 @@ -4022,6 +4032,7 @@ long btrfs_ioctl(struct file *file, unsi
1603  void btrfs_update_iflags(struct inode *inode);
1604  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1605  int btrfs_is_empty_uuid(u8 *uuid);
1606 +int btrfs_sync_flags(struct inode *inode, int, int);
1607  int btrfs_defrag_file(struct inode *inode, struct file *file,
1608                       struct btrfs_ioctl_defrag_range_args *range,
1609                       u64 newer_than, unsigned long max_pages);
1610 diff -NurpP --minimal linux-4.4.110/fs/btrfs/disk-io.c linux-4.4.110-vs2.3.9/fs/btrfs/disk-io.c
1611 --- linux-4.4.110/fs/btrfs/disk-io.c    2018-01-09 16:35:05.000000000 +0000
1612 +++ linux-4.4.110-vs2.3.9/fs/btrfs/disk-io.c    2018-01-09 16:36:24.000000000 +0000
1613 @@ -2736,6 +2736,9 @@ int open_ctree(struct super_block *sb,
1614                 goto fail_alloc;
1615         }
1616  
1617 +       if (btrfs_test_opt(tree_root, TAGGED))
1618 +               sb->s_flags |= MS_TAGGED;
1619 +
1620         features = btrfs_super_incompat_flags(disk_super) &
1621                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1622         if (features) {
1623 diff -NurpP --minimal linux-4.4.110/fs/btrfs/inode.c linux-4.4.110-vs2.3.9/fs/btrfs/inode.c
1624 --- linux-4.4.110/fs/btrfs/inode.c      2018-01-09 16:35:05.000000000 +0000
1625 +++ linux-4.4.110-vs2.3.9/fs/btrfs/inode.c      2018-01-09 16:36:24.000000000 +0000
1626 @@ -43,6 +43,7 @@
1627  #include <linux/blkdev.h>
1628  #include <linux/posix_acl_xattr.h>
1629  #include <linux/uio.h>
1630 +#include <linux/vs_tag.h>
1631  #include "ctree.h"
1632  #include "disk-io.h"
1633  #include "transaction.h"
1634 @@ -3611,6 +3612,9 @@ static void btrfs_read_locked_inode(stru
1635         unsigned long ptr;
1636         int maybe_acls;
1637         u32 rdev;
1638 +       kuid_t kuid;
1639 +       kgid_t kgid;
1640 +       ktag_t ktag;
1641         int ret;
1642         bool filled = false;
1643         int first_xattr_slot;
1644 @@ -3638,8 +3642,14 @@ static void btrfs_read_locked_inode(stru
1645                                     struct btrfs_inode_item);
1646         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1647         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1648 -       i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1649 -       i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1650 +
1651 +       kuid = make_kuid(&init_user_ns, btrfs_inode_uid(leaf, inode_item));
1652 +       kgid = make_kgid(&init_user_ns, btrfs_inode_gid(leaf, inode_item));
1653 +       ktag = make_ktag(&init_user_ns, btrfs_inode_tag(leaf, inode_item));
1654 +
1655 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
1656 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
1657 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
1658         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1659  
1660         inode->i_atime.tv_sec = btrfs_timespec_sec(leaf, &inode_item->atime);
1661 @@ -3795,11 +3805,18 @@ static void fill_inode_item(struct btrfs
1662                             struct inode *inode)
1663  {
1664         struct btrfs_map_token token;
1665 +       uid_t uid = from_kuid(&init_user_ns,
1666 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
1667 +       gid_t gid = from_kgid(&init_user_ns,
1668 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
1669  
1670         btrfs_init_map_token(&token);
1671  
1672 -       btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1673 -       btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1674 +       btrfs_set_token_inode_uid(leaf, item, uid, &token);
1675 +       btrfs_set_token_inode_gid(leaf, item, gid, &token);
1676 +#ifdef CONFIG_TAGGING_INTERN
1677 +       btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1678 +#endif
1679         btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1680                                    &token);
1681         btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1682 @@ -10062,6 +10079,7 @@ static const struct inode_operations btr
1683         .listxattr      = btrfs_listxattr,
1684         .removexattr    = btrfs_removexattr,
1685         .permission     = btrfs_permission,
1686 +       .sync_flags     = btrfs_sync_flags,
1687         .get_acl        = btrfs_get_acl,
1688         .set_acl        = btrfs_set_acl,
1689         .update_time    = btrfs_update_time,
1690 @@ -10070,6 +10088,7 @@ static const struct inode_operations btr
1691  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1692         .lookup         = btrfs_lookup,
1693         .permission     = btrfs_permission,
1694 +       .sync_flags     = btrfs_sync_flags,
1695         .get_acl        = btrfs_get_acl,
1696         .set_acl        = btrfs_set_acl,
1697         .update_time    = btrfs_update_time,
1698 @@ -10140,6 +10159,7 @@ static const struct inode_operations btr
1699         .removexattr    = btrfs_removexattr,
1700         .permission     = btrfs_permission,
1701         .fiemap         = btrfs_fiemap,
1702 +       .sync_flags     = btrfs_sync_flags,
1703         .get_acl        = btrfs_get_acl,
1704         .set_acl        = btrfs_set_acl,
1705         .update_time    = btrfs_update_time,
1706 diff -NurpP --minimal linux-4.4.110/fs/btrfs/ioctl.c linux-4.4.110-vs2.3.9/fs/btrfs/ioctl.c
1707 --- linux-4.4.110/fs/btrfs/ioctl.c      2018-01-09 16:35:05.000000000 +0000
1708 +++ linux-4.4.110-vs2.3.9/fs/btrfs/ioctl.c      2018-01-09 16:36:24.000000000 +0000
1709 @@ -108,10 +108,13 @@ static unsigned int btrfs_flags_to_ioctl
1710  {
1711         unsigned int iflags = 0;
1712  
1713 -       if (flags & BTRFS_INODE_SYNC)
1714 -               iflags |= FS_SYNC_FL;
1715         if (flags & BTRFS_INODE_IMMUTABLE)
1716                 iflags |= FS_IMMUTABLE_FL;
1717 +       if (flags & BTRFS_INODE_IXUNLINK)
1718 +               iflags |= FS_IXUNLINK_FL;
1719 +
1720 +       if (flags & BTRFS_INODE_SYNC)
1721 +               iflags |= FS_SYNC_FL;
1722         if (flags & BTRFS_INODE_APPEND)
1723                 iflags |= FS_APPEND_FL;
1724         if (flags & BTRFS_INODE_NODUMP)
1725 @@ -128,34 +131,84 @@ static unsigned int btrfs_flags_to_ioctl
1726         else if (flags & BTRFS_INODE_NOCOMPRESS)
1727                 iflags |= FS_NOCOMP_FL;
1728  
1729 +       if (flags & BTRFS_INODE_BARRIER)
1730 +               iflags |= FS_BARRIER_FL;
1731 +       if (flags & BTRFS_INODE_COW)
1732 +               iflags |= FS_COW_FL;
1733         return iflags;
1734  }
1735  
1736  /*
1737 - * Update inode->i_flags based on the btrfs internal flags.
1738 + * Update inode->i_(v)flags based on the btrfs internal flags.
1739   */
1740  void btrfs_update_iflags(struct inode *inode)
1741  {
1742         struct btrfs_inode *ip = BTRFS_I(inode);
1743         unsigned int new_fl = 0;
1744  
1745 -       if (ip->flags & BTRFS_INODE_SYNC)
1746 -               new_fl |= S_SYNC;
1747         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1748                 new_fl |= S_IMMUTABLE;
1749 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1750 +               new_fl |= S_IXUNLINK;
1751 +
1752 +       if (ip->flags & BTRFS_INODE_SYNC)
1753 +               new_fl |= S_SYNC;
1754         if (ip->flags & BTRFS_INODE_APPEND)
1755                 new_fl |= S_APPEND;
1756         if (ip->flags & BTRFS_INODE_NOATIME)
1757                 new_fl |= S_NOATIME;
1758         if (ip->flags & BTRFS_INODE_DIRSYNC)
1759                 new_fl |= S_DIRSYNC;
1760 -
1761         set_mask_bits(&inode->i_flags,
1762 -                     S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | S_DIRSYNC,
1763 +                     S_SYNC | S_APPEND | S_IMMUTABLE | S_IXUNLINK | S_NOATIME | S_DIRSYNC,
1764                       new_fl);
1765 +
1766 +       new_fl = 0;
1767 +       if (ip->flags & BTRFS_INODE_BARRIER)
1768 +               new_fl |= V_BARRIER;
1769 +       if (ip->flags & BTRFS_INODE_COW)
1770 +               new_fl |= V_COW;
1771 +
1772 +       set_mask_bits(&inode->i_vflags,
1773 +               V_BARRIER | V_COW, new_fl);
1774  }
1775  
1776  /*
1777 + * Update btrfs internal flags from inode->i_(v)flags.
1778 + */
1779 +void btrfs_update_flags(struct inode *inode)
1780 +{
1781 +       struct btrfs_inode *ip = BTRFS_I(inode);
1782 +
1783 +       unsigned int flags = inode->i_flags;
1784 +       unsigned int vflags = inode->i_vflags;
1785 +
1786 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1787 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1788 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1789 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1790 +
1791 +       if (flags & S_IMMUTABLE)
1792 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1793 +       if (flags & S_IXUNLINK)
1794 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1795 +
1796 +       if (flags & S_SYNC)
1797 +               ip->flags |= BTRFS_INODE_SYNC;
1798 +       if (flags & S_APPEND)
1799 +               ip->flags |= BTRFS_INODE_APPEND;
1800 +       if (flags & S_NOATIME)
1801 +               ip->flags |= BTRFS_INODE_NOATIME;
1802 +       if (flags & S_DIRSYNC)
1803 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1804 +
1805 +       if (vflags & V_BARRIER)
1806 +               ip->flags |= BTRFS_INODE_BARRIER;
1807 +       if (vflags & V_COW)
1808 +               ip->flags |= BTRFS_INODE_COW;
1809 + }
1810 +
1811 +/*
1812   * Inherit flags from the parent inode.
1813   *
1814   * Currently only the compression flags and the cow flags are inherited.
1815 @@ -168,6 +221,7 @@ void btrfs_inherit_iflags(struct inode *
1816                 return;
1817  
1818         flags = BTRFS_I(dir)->flags;
1819 +       flags &= ~BTRFS_INODE_BARRIER;
1820  
1821         if (flags & BTRFS_INODE_NOCOMPRESS) {
1822                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1823 @@ -186,6 +240,30 @@ void btrfs_inherit_iflags(struct inode *
1824         btrfs_update_iflags(inode);
1825  }
1826  
1827 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1828 +{
1829 +       struct btrfs_inode *ip = BTRFS_I(inode);
1830 +       struct btrfs_root *root = ip->root;
1831 +       struct btrfs_trans_handle *trans;
1832 +       int ret;
1833 +
1834 +       trans = btrfs_join_transaction(root);
1835 +       BUG_ON(!trans);
1836 +
1837 +       inode->i_flags = flags;
1838 +       inode->i_vflags = vflags;
1839 +       btrfs_update_flags(inode);
1840 +
1841 +       ret = btrfs_update_inode(trans, root, inode);
1842 +       BUG_ON(ret);
1843 +
1844 +       btrfs_update_iflags(inode);
1845 +       inode->i_ctime = CURRENT_TIME;
1846 +       btrfs_end_transaction(trans, root);
1847 +
1848 +       return 0;
1849 +}
1850 +
1851  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1852  {
1853         struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1854 @@ -248,21 +326,27 @@ static int btrfs_ioctl_setflags(struct f
1855  
1856         flags = btrfs_mask_flags(inode->i_mode, flags);
1857         oldflags = btrfs_flags_to_ioctl(ip->flags);
1858 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1859 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1860 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1861                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1862                         ret = -EPERM;
1863                         goto out_unlock;
1864                 }
1865         }
1866  
1867 -       if (flags & FS_SYNC_FL)
1868 -               ip->flags |= BTRFS_INODE_SYNC;
1869 -       else
1870 -               ip->flags &= ~BTRFS_INODE_SYNC;
1871         if (flags & FS_IMMUTABLE_FL)
1872                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1873         else
1874                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1875 +       if (flags & FS_IXUNLINK_FL)
1876 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1877 +       else
1878 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1879 +
1880 +       if (flags & FS_SYNC_FL)
1881 +               ip->flags |= BTRFS_INODE_SYNC;
1882 +       else
1883 +               ip->flags &= ~BTRFS_INODE_SYNC;
1884         if (flags & FS_APPEND_FL)
1885                 ip->flags |= BTRFS_INODE_APPEND;
1886         else
1887 diff -NurpP --minimal linux-4.4.110/fs/btrfs/super.c linux-4.4.110-vs2.3.9/fs/btrfs/super.c
1888 --- linux-4.4.110/fs/btrfs/super.c      2018-01-09 16:35:05.000000000 +0000
1889 +++ linux-4.4.110-vs2.3.9/fs/btrfs/super.c      2018-01-09 17:25:27.000000000 +0000
1890 @@ -306,7 +306,7 @@ enum {
1891  #ifdef CONFIG_BTRFS_DEBUG
1892         Opt_fragment_data, Opt_fragment_metadata, Opt_fragment_all,
1893  #endif
1894 -       Opt_err,
1895 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1896  };
1897  
1898  static match_table_t tokens = {
1899 @@ -363,6 +363,9 @@ static match_table_t tokens = {
1900         {Opt_fragment_metadata, "fragment=metadata"},
1901         {Opt_fragment_all, "fragment=all"},
1902  #endif
1903 +       {Opt_tag, "tag"},
1904 +       {Opt_notag, "notag"},
1905 +       {Opt_tagid, "tagid=%u"},
1906         {Opt_err, NULL},
1907  };
1908  
1909 @@ -745,6 +748,22 @@ int btrfs_parse_options(struct btrfs_roo
1910                         btrfs_set_opt(info->mount_opt, FRAGMENT_DATA);
1911                         break;
1912  #endif
1913 +#ifndef CONFIG_TAGGING_NONE
1914 +               case Opt_tag:
1915 +                       printk(KERN_INFO "btrfs: use tagging\n");
1916 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1917 +                       break;
1918 +               case Opt_notag:
1919 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
1920 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
1921 +                       break;
1922 +#endif
1923 +#ifdef CONFIG_PROPAGATE
1924 +               case Opt_tagid:
1925 +                       /* use args[0] */
1926 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1927 +                       break;
1928 +#endif
1929                 case Opt_err:
1930                         btrfs_info(root->fs_info, "unrecognized mount option '%s'", p);
1931                         ret = -EINVAL;
1932 @@ -1647,6 +1666,12 @@ static int btrfs_remount(struct super_bl
1933         btrfs_resize_thread_pool(fs_info,
1934                 fs_info->thread_pool_size, old_thread_pool_size);
1935  
1936 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1937 +               printk("btrfs: %s: tagging not permitted on remount.\n",
1938 +                       sb->s_id);
1939 +               return -EINVAL;
1940 +       }
1941 +
1942         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1943                 goto out;
1944  
1945 diff -NurpP --minimal linux-4.4.110/fs/char_dev.c linux-4.4.110-vs2.3.9/fs/char_dev.c
1946 --- linux-4.4.110/fs/char_dev.c 2016-07-05 04:12:30.000000000 +0000
1947 +++ linux-4.4.110-vs2.3.9/fs/char_dev.c 2018-01-09 16:36:24.000000000 +0000
1948 @@ -21,6 +21,8 @@
1949  #include <linux/mutex.h>
1950  #include <linux/backing-dev.h>
1951  #include <linux/tty.h>
1952 +#include <linux/vs_context.h>
1953 +#include <linux/vs_device.h>
1954  
1955  #include "internal.h"
1956  
1957 @@ -350,14 +352,21 @@ static int chrdev_open(struct inode *ino
1958         struct cdev *p;
1959         struct cdev *new = NULL;
1960         int ret = 0;
1961 +       dev_t mdev;
1962 +
1963 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1964 +               return -EPERM;
1965 +       inode->i_mdev = mdev;
1966  
1967         spin_lock(&cdev_lock);
1968         p = inode->i_cdev;
1969         if (!p) {
1970                 struct kobject *kobj;
1971                 int idx;
1972 +
1973                 spin_unlock(&cdev_lock);
1974 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1975 +
1976 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
1977                 if (!kobj)
1978                         return -ENXIO;
1979                 new = container_of(kobj, struct cdev, kobj);
1980 diff -NurpP --minimal linux-4.4.110/fs/dcache.c linux-4.4.110-vs2.3.9/fs/dcache.c
1981 --- linux-4.4.110/fs/dcache.c   2018-01-09 16:35:05.000000000 +0000
1982 +++ linux-4.4.110-vs2.3.9/fs/dcache.c   2018-01-09 16:36:24.000000000 +0000
1983 @@ -39,6 +39,7 @@
1984  #include <linux/ratelimit.h>
1985  #include <linux/list_lru.h>
1986  #include <linux/kasan.h>
1987 +#include <linux/vs_limit.h>
1988  
1989  #include "internal.h"
1990  #include "mount.h"
1991 @@ -677,6 +678,7 @@ static inline bool fast_dput(struct dent
1992                 spin_lock(&dentry->d_lock);
1993                 if (dentry->d_lockref.count > 1) {
1994                         dentry->d_lockref.count--;
1995 +                       vx_dentry_dec(dentry);
1996                         spin_unlock(&dentry->d_lock);
1997                         return 1;
1998                 }
1999 @@ -806,6 +808,7 @@ repeat:
2000         dentry_lru_add(dentry);
2001  
2002         dentry->d_lockref.count--;
2003 +       vx_dentry_dec(dentry);
2004         spin_unlock(&dentry->d_lock);
2005         return;
2006  
2007 @@ -823,6 +826,7 @@ EXPORT_SYMBOL(dput);
2008  static inline void __dget_dlock(struct dentry *dentry)
2009  {
2010         dentry->d_lockref.count++;
2011 +       vx_dentry_inc(dentry);
2012  }
2013  
2014  static inline void __dget(struct dentry *dentry)
2015 @@ -835,6 +839,8 @@ struct dentry *dget_parent(struct dentry
2016         int gotref;
2017         struct dentry *ret;
2018  
2019 +       vx_dentry_dec(dentry);
2020 +
2021         /*
2022          * Do optimistic parent lookup without any
2023          * locking.
2024 @@ -865,6 +871,7 @@ repeat:
2025         rcu_read_unlock();
2026         BUG_ON(!ret->d_lockref.count);
2027         ret->d_lockref.count++;
2028 +       vx_dentry_inc(ret);
2029         spin_unlock(&ret->d_lock);
2030         return ret;
2031  }
2032 @@ -1019,6 +1026,7 @@ static void shrink_dentry_list(struct li
2033                         parent = lock_parent(dentry);
2034                         if (dentry->d_lockref.count != 1) {
2035                                 dentry->d_lockref.count--;
2036 +                               vx_dentry_dec(dentry);
2037                                 spin_unlock(&dentry->d_lock);
2038                                 if (parent)
2039                                         spin_unlock(&parent->d_lock);
2040 @@ -1581,6 +1589,9 @@ struct dentry *__d_alloc(struct super_bl
2041         struct dentry *dentry;
2042         char *dname;
2043  
2044 +       if (!vx_dentry_avail(1))
2045 +               return NULL;
2046 +
2047         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2048         if (!dentry)
2049                 return NULL;
2050 @@ -1619,6 +1630,7 @@ struct dentry *__d_alloc(struct super_bl
2051  
2052         dentry->d_lockref.count = 1;
2053         dentry->d_flags = 0;
2054 +       vx_dentry_inc(dentry);
2055         spin_lock_init(&dentry->d_lock);
2056         seqcount_init(&dentry->d_seq);
2057         dentry->d_inode = NULL;
2058 @@ -2355,6 +2367,7 @@ struct dentry *__d_lookup(const struct d
2059                 }
2060  
2061                 dentry->d_lockref.count++;
2062 +               vx_dentry_inc(dentry);
2063                 found = dentry;
2064                 spin_unlock(&dentry->d_lock);
2065                 break;
2066 @@ -3371,6 +3384,7 @@ static enum d_walk_ret d_genocide_kill(v
2067                 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
2068                         dentry->d_flags |= DCACHE_GENOCIDE;
2069                         dentry->d_lockref.count--;
2070 +                       vx_dentry_dec(dentry);
2071                 }
2072         }
2073         return D_WALK_CONTINUE;
2074 diff -NurpP --minimal linux-4.4.110/fs/devpts/inode.c linux-4.4.110-vs2.3.9/fs/devpts/inode.c
2075 --- linux-4.4.110/fs/devpts/inode.c     2018-01-09 16:35:05.000000000 +0000
2076 +++ linux-4.4.110-vs2.3.9/fs/devpts/inode.c     2018-01-09 16:36:24.000000000 +0000
2077 @@ -27,6 +27,7 @@
2078  #include <linux/parser.h>
2079  #include <linux/fsnotify.h>
2080  #include <linux/seq_file.h>
2081 +#include <linux/vs_base.h>
2082  
2083  #define DEVPTS_DEFAULT_MODE 0600
2084  /*
2085 @@ -38,6 +39,21 @@
2086  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2087  #define PTMX_MINOR     2
2088  
2089 +static int devpts_permission(struct inode *inode, int mask)
2090 +{
2091 +       int ret = -EACCES;
2092 +
2093 +       /* devpts is xid tagged */
2094 +       if (vx_check((vxid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2095 +               ret = generic_permission(inode, mask);
2096 +       return ret;
2097 +}
2098 +
2099 +static struct inode_operations devpts_file_inode_operations = {
2100 +       .permission     = devpts_permission,
2101 +};
2102 +
2103 +
2104  /*
2105   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2106   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2107 @@ -353,6 +369,34 @@ static int devpts_show_options(struct se
2108         return 0;
2109  }
2110  
2111 +static int devpts_filter(struct dentry *de)
2112 +{
2113 +       vxid_t xid = 0;
2114 +
2115 +       /* devpts is xid tagged */
2116 +       if (de && de->d_inode)
2117 +               xid = (vxid_t)i_tag_read(de->d_inode);
2118 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2119 +       else
2120 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2121 +                       de->d_name.len, de->d_name.name);
2122 +#endif
2123 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2124 +}
2125 +
2126 +static int devpts_readdir(struct file * filp, struct dir_context *ctx)
2127 +{
2128 +       return dcache_readdir_filter(filp, ctx, devpts_filter);
2129 +}
2130 +
2131 +static struct file_operations devpts_dir_operations = {
2132 +       .open           = dcache_dir_open,
2133 +       .release        = dcache_dir_close,
2134 +       .llseek         = dcache_dir_lseek,
2135 +       .read           = generic_read_dir,
2136 +       .iterate        = devpts_readdir,
2137 +};
2138 +
2139  static const struct super_operations devpts_sops = {
2140         .statfs         = simple_statfs,
2141         .remount_fs     = devpts_remount,
2142 @@ -397,8 +441,10 @@ devpts_fill_super(struct super_block *s,
2143         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2144         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2145         inode->i_op = &simple_dir_inode_operations;
2146 -       inode->i_fop = &simple_dir_operations;
2147 +       inode->i_fop = &devpts_dir_operations;
2148         set_nlink(inode, 2);
2149 +       /* devpts is xid tagged */
2150 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2151  
2152         s->s_root = d_make_root(inode);
2153         if (s->s_root)
2154 @@ -630,6 +676,9 @@ struct inode *devpts_pty_new(struct pts_
2155         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2156         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2157         init_special_inode(inode, S_IFCHR|opts->mode, device);
2158 +       /* devpts is xid tagged */
2159 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2160 +       inode->i_op = &devpts_file_inode_operations;
2161         inode->i_private = priv;
2162  
2163         sprintf(s, "%d", index);
2164 diff -NurpP --minimal linux-4.4.110/fs/ext2/balloc.c linux-4.4.110-vs2.3.9/fs/ext2/balloc.c
2165 --- linux-4.4.110/fs/ext2/balloc.c      2015-04-12 22:12:50.000000000 +0000
2166 +++ linux-4.4.110-vs2.3.9/fs/ext2/balloc.c      2018-01-09 16:36:24.000000000 +0000
2167 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2168                         start = 0;
2169                 end = EXT2_BLOCKS_PER_GROUP(sb);
2170         }
2171 -
2172         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2173  
2174  repeat:
2175 diff -NurpP --minimal linux-4.4.110/fs/ext2/ext2.h linux-4.4.110-vs2.3.9/fs/ext2/ext2.h
2176 --- linux-4.4.110/fs/ext2/ext2.h        2016-07-05 04:15:07.000000000 +0000
2177 +++ linux-4.4.110-vs2.3.9/fs/ext2/ext2.h        2018-01-09 16:36:24.000000000 +0000
2178 @@ -244,8 +244,12 @@ struct ext2_group_desc
2179  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2180  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2181  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2182 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2183  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2184  
2185 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2186 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2187 +
2188  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2189  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2190  
2191 @@ -329,7 +333,8 @@ struct ext2_inode {
2192                         __u16   i_pad1;
2193                         __le16  l_i_uid_high;   /* these 2 fields    */
2194                         __le16  l_i_gid_high;   /* were reserved2[0] */
2195 -                       __u32   l_i_reserved2;
2196 +                       __le16  l_i_tag;        /* Context Tag */
2197 +                       __u16   l_i_reserved2;
2198                 } linux2;
2199                 struct {
2200                         __u8    h_i_frag;       /* Fragment number */
2201 @@ -357,6 +362,7 @@ struct ext2_inode {
2202  #define i_gid_low      i_gid
2203  #define i_uid_high     osd2.linux2.l_i_uid_high
2204  #define i_gid_high     osd2.linux2.l_i_gid_high
2205 +#define i_raw_tag      osd2.linux2.l_i_tag
2206  #define i_reserved2    osd2.linux2.l_i_reserved2
2207  
2208  /*
2209 @@ -389,6 +395,7 @@ struct ext2_inode {
2210  #else
2211  #define EXT2_MOUNT_DAX                 0
2212  #endif
2213 +#define EXT2_MOUNT_TAGGED              0x200000  /* Enable Context Tags */
2214  
2215  
2216  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2217 @@ -776,6 +783,7 @@ extern void ext2_set_inode_flags(struct
2218  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2219  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2220                        u64 start, u64 len);
2221 +extern int ext2_sync_flags(struct inode *, int, int);
2222  
2223  /* ioctl.c */
2224  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2225 diff -NurpP --minimal linux-4.4.110/fs/ext2/file.c linux-4.4.110-vs2.3.9/fs/ext2/file.c
2226 --- linux-4.4.110/fs/ext2/file.c        2016-07-05 04:15:07.000000000 +0000
2227 +++ linux-4.4.110-vs2.3.9/fs/ext2/file.c        2018-01-09 16:36:24.000000000 +0000
2228 @@ -202,4 +202,5 @@ const struct inode_operations ext2_file_
2229         .get_acl        = ext2_get_acl,
2230         .set_acl        = ext2_set_acl,
2231         .fiemap         = ext2_fiemap,
2232 +       .sync_flags     = ext2_sync_flags,
2233  };
2234 diff -NurpP --minimal linux-4.4.110/fs/ext2/ialloc.c linux-4.4.110-vs2.3.9/fs/ext2/ialloc.c
2235 --- linux-4.4.110/fs/ext2/ialloc.c      2016-07-05 04:12:30.000000000 +0000
2236 +++ linux-4.4.110-vs2.3.9/fs/ext2/ialloc.c      2018-01-09 16:36:24.000000000 +0000
2237 @@ -17,6 +17,7 @@
2238  #include <linux/backing-dev.h>
2239  #include <linux/buffer_head.h>
2240  #include <linux/random.h>
2241 +#include <linux/vs_tag.h>
2242  #include "ext2.h"
2243  #include "xattr.h"
2244  #include "acl.h"
2245 @@ -546,6 +547,7 @@ got:
2246                 inode->i_mode = mode;
2247                 inode->i_uid = current_fsuid();
2248                 inode->i_gid = dir->i_gid;
2249 +               i_tag_write(inode, dx_current_fstag(sb));
2250         } else
2251                 inode_init_owner(inode, dir, mode);
2252  
2253 diff -NurpP --minimal linux-4.4.110/fs/ext2/inode.c linux-4.4.110-vs2.3.9/fs/ext2/inode.c
2254 --- linux-4.4.110/fs/ext2/inode.c       2016-07-05 04:15:07.000000000 +0000
2255 +++ linux-4.4.110-vs2.3.9/fs/ext2/inode.c       2018-01-09 16:36:24.000000000 +0000
2256 @@ -33,6 +33,7 @@
2257  #include <linux/fiemap.h>
2258  #include <linux/namei.h>
2259  #include <linux/uio.h>
2260 +#include <linux/vs_tag.h>
2261  #include "ext2.h"
2262  #include "acl.h"
2263  #include "xattr.h"
2264 @@ -1188,7 +1189,7 @@ static void ext2_truncate_blocks(struct
2265                 return;
2266         if (ext2_inode_is_fast_symlink(inode))
2267                 return;
2268 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2269 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2270                 return;
2271  
2272         dax_sem_down_write(EXT2_I(inode));
2273 @@ -1284,39 +1285,62 @@ void ext2_set_inode_flags(struct inode *
2274  {
2275         unsigned int flags = EXT2_I(inode)->i_flags;
2276  
2277 -       inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME |
2278 -                               S_DIRSYNC | S_DAX);
2279 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK | S_DAX |
2280 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2281 +
2282 +       if (flags & EXT2_IMMUTABLE_FL)
2283 +               inode->i_flags |= S_IMMUTABLE;
2284 +       if (flags & EXT2_IXUNLINK_FL)
2285 +               inode->i_flags |= S_IXUNLINK;
2286 +
2287         if (flags & EXT2_SYNC_FL)
2288                 inode->i_flags |= S_SYNC;
2289         if (flags & EXT2_APPEND_FL)
2290                 inode->i_flags |= S_APPEND;
2291 -       if (flags & EXT2_IMMUTABLE_FL)
2292 -               inode->i_flags |= S_IMMUTABLE;
2293         if (flags & EXT2_NOATIME_FL)
2294                 inode->i_flags |= S_NOATIME;
2295         if (flags & EXT2_DIRSYNC_FL)
2296                 inode->i_flags |= S_DIRSYNC;
2297         if (test_opt(inode->i_sb, DAX))
2298                 inode->i_flags |= S_DAX;
2299 +
2300 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2301 +
2302 +       if (flags & EXT2_BARRIER_FL)
2303 +               inode->i_vflags |= V_BARRIER;
2304 +       if (flags & EXT2_COW_FL)
2305 +               inode->i_vflags |= V_COW;
2306  }
2307  
2308  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2309  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2310  {
2311         unsigned int flags = ei->vfs_inode.i_flags;
2312 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2313 +
2314 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2315 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2316 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2317 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2318 +
2319 +       if (flags & S_IMMUTABLE)
2320 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2321 +       if (flags & S_IXUNLINK)
2322 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2323  
2324 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2325 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2326         if (flags & S_SYNC)
2327                 ei->i_flags |= EXT2_SYNC_FL;
2328         if (flags & S_APPEND)
2329                 ei->i_flags |= EXT2_APPEND_FL;
2330 -       if (flags & S_IMMUTABLE)
2331 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2332         if (flags & S_NOATIME)
2333                 ei->i_flags |= EXT2_NOATIME_FL;
2334         if (flags & S_DIRSYNC)
2335                 ei->i_flags |= EXT2_DIRSYNC_FL;
2336 +
2337 +       if (vflags & V_BARRIER)
2338 +               ei->i_flags |= EXT2_BARRIER_FL;
2339 +       if (vflags & V_COW)
2340 +               ei->i_flags |= EXT2_COW_FL;
2341  }
2342  
2343  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2344 @@ -1352,8 +1376,10 @@ struct inode *ext2_iget (struct super_bl
2345                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2346                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2347         }
2348 -       i_uid_write(inode, i_uid);
2349 -       i_gid_write(inode, i_gid);
2350 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2351 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2352 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2353 +               le16_to_cpu(raw_inode->i_raw_tag)));
2354         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2355         inode->i_size = le32_to_cpu(raw_inode->i_size);
2356         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2357 @@ -1449,8 +1475,10 @@ static int __ext2_write_inode(struct ino
2358         struct ext2_inode_info *ei = EXT2_I(inode);
2359         struct super_block *sb = inode->i_sb;
2360         ino_t ino = inode->i_ino;
2361 -       uid_t uid = i_uid_read(inode);
2362 -       gid_t gid = i_gid_read(inode);
2363 +       uid_t uid = from_kuid(&init_user_ns,
2364 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2365 +       gid_t gid = from_kgid(&init_user_ns,
2366 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2367         struct buffer_head * bh;
2368         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2369         int n;
2370 @@ -1486,6 +1514,9 @@ static int __ext2_write_inode(struct ino
2371                 raw_inode->i_uid_high = 0;
2372                 raw_inode->i_gid_high = 0;
2373         }
2374 +#ifdef CONFIG_TAGGING_INTERN
2375 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2376 +#endif
2377         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2378         raw_inode->i_size = cpu_to_le32(inode->i_size);
2379         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2380 @@ -1569,7 +1600,8 @@ int ext2_setattr(struct dentry *dentry,
2381                         return error;
2382         }
2383         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2384 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2385 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2386 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2387                 error = dquot_transfer(inode, iattr);
2388                 if (error)
2389                         return error;
2390 diff -NurpP --minimal linux-4.4.110/fs/ext2/ioctl.c linux-4.4.110-vs2.3.9/fs/ext2/ioctl.c
2391 --- linux-4.4.110/fs/ext2/ioctl.c       2015-04-12 22:12:50.000000000 +0000
2392 +++ linux-4.4.110-vs2.3.9/fs/ext2/ioctl.c       2018-01-09 16:36:24.000000000 +0000
2393 @@ -17,6 +17,16 @@
2394  #include <asm/uaccess.h>
2395  
2396  
2397 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2398 +{
2399 +       inode->i_flags = flags;
2400 +       inode->i_vflags = vflags;
2401 +       ext2_get_inode_flags(EXT2_I(inode));
2402 +       inode->i_ctime = CURRENT_TIME_SEC;
2403 +       mark_inode_dirty(inode);
2404 +       return 0;
2405 +}
2406 +
2407  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2408  {
2409         struct inode *inode = file_inode(filp);
2410 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2411  
2412                 flags = ext2_mask_flags(inode->i_mode, flags);
2413  
2414 +               if (IS_BARRIER(inode)) {
2415 +                       vxwprintk_task(1, "messing with the barrier.");
2416 +                       return -EACCES;
2417 +               }
2418 +
2419                 mutex_lock(&inode->i_mutex);
2420                 /* Is it quota file? Do not allow user to mess with it */
2421                 if (IS_NOQUOTA(inode)) {
2422 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2423                  *
2424                  * This test looks nicer. Thanks to Pauline Middelink
2425                  */
2426 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2427 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2428 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2429 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2430                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2431                                 mutex_unlock(&inode->i_mutex);
2432                                 ret = -EPERM;
2433 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2434                         }
2435                 }
2436  
2437 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2438 +               flags &= EXT2_FL_USER_MODIFIABLE;
2439                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2440                 ei->i_flags = flags;
2441  
2442 diff -NurpP --minimal linux-4.4.110/fs/ext2/namei.c linux-4.4.110-vs2.3.9/fs/ext2/namei.c
2443 --- linux-4.4.110/fs/ext2/namei.c       2016-07-05 04:15:07.000000000 +0000
2444 +++ linux-4.4.110-vs2.3.9/fs/ext2/namei.c       2018-01-09 16:36:24.000000000 +0000
2445 @@ -32,6 +32,7 @@
2446  
2447  #include <linux/pagemap.h>
2448  #include <linux/quotaops.h>
2449 +#include <linux/vs_tag.h>
2450  #include "ext2.h"
2451  #include "xattr.h"
2452  #include "acl.h"
2453 @@ -72,6 +73,7 @@ static struct dentry *ext2_lookup(struct
2454                                         (unsigned long) ino);
2455                         return ERR_PTR(-EIO);
2456                 }
2457 +               dx_propagate_tag(nd, inode);
2458         }
2459         return d_splice_alias(inode, dentry);
2460  }
2461 @@ -446,6 +448,7 @@ const struct inode_operations ext2_speci
2462         .removexattr    = generic_removexattr,
2463  #endif
2464         .setattr        = ext2_setattr,
2465 +       .sync_flags     = ext2_sync_flags,
2466         .get_acl        = ext2_get_acl,
2467         .set_acl        = ext2_set_acl,
2468  };
2469 diff -NurpP --minimal linux-4.4.110/fs/ext2/super.c linux-4.4.110-vs2.3.9/fs/ext2/super.c
2470 --- linux-4.4.110/fs/ext2/super.c       2016-07-05 04:15:07.000000000 +0000
2471 +++ linux-4.4.110-vs2.3.9/fs/ext2/super.c       2018-01-09 16:36:24.000000000 +0000
2472 @@ -408,7 +408,8 @@ enum {
2473         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2474         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2475         Opt_acl, Opt_noacl, Opt_xip, Opt_dax, Opt_ignore, Opt_err, Opt_quota,
2476 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2477 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2478 +       Opt_tag, Opt_notag, Opt_tagid
2479  };
2480  
2481  static const match_table_t tokens = {
2482 @@ -436,6 +437,9 @@ static const match_table_t tokens = {
2483         {Opt_acl, "acl"},
2484         {Opt_noacl, "noacl"},
2485         {Opt_xip, "xip"},
2486 +       {Opt_tag, "tag"},
2487 +       {Opt_notag, "notag"},
2488 +       {Opt_tagid, "tagid=%u"},
2489         {Opt_dax, "dax"},
2490         {Opt_grpquota, "grpquota"},
2491         {Opt_ignore, "noquota"},
2492 @@ -520,6 +524,20 @@ static int parse_options(char *options,
2493                 case Opt_nouid32:
2494                         set_opt (sbi->s_mount_opt, NO_UID32);
2495                         break;
2496 +#ifndef CONFIG_TAGGING_NONE
2497 +               case Opt_tag:
2498 +                       set_opt (sbi->s_mount_opt, TAGGED);
2499 +                       break;
2500 +               case Opt_notag:
2501 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2502 +                       break;
2503 +#endif
2504 +#ifdef CONFIG_PROPAGATE
2505 +               case Opt_tagid:
2506 +                       /* use args[0] */
2507 +                       set_opt (sbi->s_mount_opt, TAGGED);
2508 +                       break;
2509 +#endif
2510                 case Opt_nocheck:
2511                         clear_opt (sbi->s_mount_opt, CHECK);
2512                         break;
2513 @@ -884,6 +902,8 @@ static int ext2_fill_super(struct super_
2514         if (!parse_options((char *) data, sb))
2515                 goto failed_mount;
2516  
2517 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2518 +               sb->s_flags |= MS_TAGGED;
2519         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2520                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2521                  MS_POSIXACL : 0);
2522 @@ -1294,6 +1314,14 @@ static int ext2_remount (struct super_bl
2523                 err = -EINVAL;
2524                 goto restore_opts;
2525         }
2526 +
2527 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2528 +               !(sb->s_flags & MS_TAGGED)) {
2529 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2530 +                      sb->s_id);
2531 +               err = -EINVAL;
2532 +               goto restore_opts;
2533 +       }
2534  
2535         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2536                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2537 diff -NurpP --minimal linux-4.4.110/fs/ext4/ext4.h linux-4.4.110-vs2.3.9/fs/ext4/ext4.h
2538 --- linux-4.4.110/fs/ext4/ext4.h        2018-01-09 16:35:06.000000000 +0000
2539 +++ linux-4.4.110-vs2.3.9/fs/ext4/ext4.h        2018-01-09 17:33:10.000000000 +0000
2540 @@ -375,8 +375,11 @@ struct flex_groups {
2541  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2542  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2543  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2544 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2545 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2546  #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data. */
2547  #define EXT4_PROJINHERIT_FL            0x20000000 /* Create with parents projid */
2548 +#define EXT4_COW_FL                    0x40000000 /* Copy on Write marker */
2549  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2550  
2551  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2552 @@ -674,7 +677,7 @@ struct ext4_inode {
2553                         __le16  l_i_uid_high;   /* these 2 fields */
2554                         __le16  l_i_gid_high;   /* were reserved2[0] */
2555                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2556 -                       __le16  l_i_reserved;
2557 +                       __le16  l_i_tag;        /* Context Tag */
2558                 } linux2;
2559                 struct {
2560                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
2561 @@ -831,6 +834,7 @@ do {                                                                               \
2562  #define i_gid_low      i_gid
2563  #define i_uid_high     osd2.linux2.l_i_uid_high
2564  #define i_gid_high     osd2.linux2.l_i_gid_high
2565 +#define i_raw_tag      osd2.linux2.l_i_tag
2566  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
2567  
2568  #elif defined(__GNU__)
2569 @@ -1068,6 +1072,7 @@ struct ext4_inode_info {
2570  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
2571  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
2572  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
2573 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
2574  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
2575  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
2576  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2577 @@ -2501,6 +2506,7 @@ extern int ext4_punch_hole(struct inode
2578  extern int ext4_truncate_restart_trans(handle_t *, struct inode *, int nblocks);
2579  extern void ext4_set_inode_flags(struct inode *);
2580  extern void ext4_get_inode_flags(struct ext4_inode_info *);
2581 +extern int ext4_sync_flags(struct inode *, int, int);
2582  extern int ext4_alloc_da_blocks(struct inode *inode);
2583  extern void ext4_set_aops(struct inode *inode);
2584  extern int ext4_writepage_trans_blocks(struct inode *);
2585 diff -NurpP --minimal linux-4.4.110/fs/ext4/file.c linux-4.4.110-vs2.3.9/fs/ext4/file.c
2586 --- linux-4.4.110/fs/ext4/file.c        2018-01-09 16:35:06.000000000 +0000
2587 +++ linux-4.4.110-vs2.3.9/fs/ext4/file.c        2018-01-09 16:36:31.000000000 +0000
2588 @@ -749,5 +749,6 @@ const struct inode_operations ext4_file_
2589         .get_acl        = ext4_get_acl,
2590         .set_acl        = ext4_set_acl,
2591         .fiemap         = ext4_fiemap,
2592 +       .sync_flags     = ext4_sync_flags,
2593  };
2594  
2595 diff -NurpP --minimal linux-4.4.110/fs/ext4/ialloc.c linux-4.4.110-vs2.3.9/fs/ext4/ialloc.c
2596 --- linux-4.4.110/fs/ext4/ialloc.c      2018-01-09 16:35:06.000000000 +0000
2597 +++ linux-4.4.110-vs2.3.9/fs/ext4/ialloc.c      2018-01-09 16:36:31.000000000 +0000
2598 @@ -21,6 +21,7 @@
2599  #include <linux/random.h>
2600  #include <linux/bitops.h>
2601  #include <linux/blkdev.h>
2602 +#include <linux/vs_tag.h>
2603  #include <asm/byteorder.h>
2604  
2605  #include "ext4.h"
2606 @@ -799,6 +800,7 @@ struct inode *__ext4_new_inode(handle_t
2607                 inode->i_mode = mode;
2608                 inode->i_uid = current_fsuid();
2609                 inode->i_gid = dir->i_gid;
2610 +               i_tag_write(inode, dx_current_fstag(sb));
2611         } else
2612                 inode_init_owner(inode, dir, mode);
2613         err = dquot_initialize(inode);
2614 diff -NurpP --minimal linux-4.4.110/fs/ext4/inode.c linux-4.4.110-vs2.3.9/fs/ext4/inode.c
2615 --- linux-4.4.110/fs/ext4/inode.c       2018-01-09 16:35:06.000000000 +0000
2616 +++ linux-4.4.110-vs2.3.9/fs/ext4/inode.c       2018-01-09 16:36:31.000000000 +0000
2617 @@ -37,6 +37,7 @@
2618  #include <linux/printk.h>
2619  #include <linux/slab.h>
2620  #include <linux/bitops.h>
2621 +#include <linux/vs_tag.h>
2622  
2623  #include "ext4_jbd2.h"
2624  #include "xattr.h"
2625 @@ -4128,12 +4129,15 @@ void ext4_set_inode_flags(struct inode *
2626         unsigned int flags = EXT4_I(inode)->i_flags;
2627         unsigned int new_fl = 0;
2628  
2629 +       if (flags & EXT4_IMMUTABLE_FL)
2630 +               new_fl |= S_IMMUTABLE;
2631 +       if (flags & EXT4_IXUNLINK_FL)
2632 +               new_fl |= S_IXUNLINK;
2633 +
2634         if (flags & EXT4_SYNC_FL)
2635                 new_fl |= S_SYNC;
2636         if (flags & EXT4_APPEND_FL)
2637                 new_fl |= S_APPEND;
2638 -       if (flags & EXT4_IMMUTABLE_FL)
2639 -               new_fl |= S_IMMUTABLE;
2640         if (flags & EXT4_NOATIME_FL)
2641                 new_fl |= S_NOATIME;
2642         if (flags & EXT4_DIRSYNC_FL)
2643 @@ -4141,31 +4145,52 @@ void ext4_set_inode_flags(struct inode *
2644         if (test_opt(inode->i_sb, DAX))
2645                 new_fl |= S_DAX;
2646         inode_set_flags(inode, new_fl,
2647 -                       S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_DAX);
2648 +               S_IXUNLINK | S_IMMUTABLE | S_DAX |
2649 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2650 +
2651 +       new_fl = 0;
2652 +       if (flags & EXT4_BARRIER_FL)
2653 +               new_fl |= V_BARRIER;
2654 +       if (flags & EXT4_COW_FL)
2655 +               new_fl |= V_COW;
2656 +
2657 +       set_mask_bits(&inode->i_vflags,
2658 +               V_BARRIER | V_COW, new_fl);
2659  }
2660  
2661  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2662  void ext4_get_inode_flags(struct ext4_inode_info *ei)
2663  {
2664 -       unsigned int vfs_fl;
2665 +       unsigned int vfs_fl, vfs_vf;
2666         unsigned long old_fl, new_fl;
2667  
2668         do {
2669                 vfs_fl = ei->vfs_inode.i_flags;
2670 +               vfs_vf = ei->vfs_inode.i_vflags;
2671                 old_fl = ei->i_flags;
2672                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2673                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2674 -                               EXT4_DIRSYNC_FL);
2675 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2676 +                               EXT4_COW_FL);
2677 +
2678 +               if (vfs_fl & S_IMMUTABLE)
2679 +                       new_fl |= EXT4_IMMUTABLE_FL;
2680 +               if (vfs_fl & S_IXUNLINK)
2681 +                       new_fl |= EXT4_IXUNLINK_FL;
2682 +
2683                 if (vfs_fl & S_SYNC)
2684                         new_fl |= EXT4_SYNC_FL;
2685                 if (vfs_fl & S_APPEND)
2686                         new_fl |= EXT4_APPEND_FL;
2687 -               if (vfs_fl & S_IMMUTABLE)
2688 -                       new_fl |= EXT4_IMMUTABLE_FL;
2689                 if (vfs_fl & S_NOATIME)
2690                         new_fl |= EXT4_NOATIME_FL;
2691                 if (vfs_fl & S_DIRSYNC)
2692                         new_fl |= EXT4_DIRSYNC_FL;
2693 +
2694 +               if (vfs_vf & V_BARRIER)
2695 +                       new_fl |= EXT4_BARRIER_FL;
2696 +               if (vfs_vf & V_COW)
2697 +                       new_fl |= EXT4_COW_FL;
2698         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
2699  }
2700  
2701 @@ -4269,8 +4294,10 @@ struct inode *ext4_iget(struct super_blo
2702                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2703                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2704         }
2705 -       i_uid_write(inode, i_uid);
2706 -       i_gid_write(inode, i_gid);
2707 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2708 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2709 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2710 +               le16_to_cpu(raw_inode->i_raw_tag)));
2711         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2712  
2713         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
2714 @@ -4583,8 +4610,10 @@ static int ext4_do_update_inode(handle_t
2715  
2716         ext4_get_inode_flags(ei);
2717         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2718 -       i_uid = i_uid_read(inode);
2719 -       i_gid = i_gid_read(inode);
2720 +       i_uid = from_kuid(&init_user_ns,
2721 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2722 +       i_gid = from_kgid(&init_user_ns,
2723 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2724         if (!(test_opt(inode->i_sb, NO_UID32))) {
2725                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2726                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2727 @@ -4607,6 +4636,9 @@ static int ext4_do_update_inode(handle_t
2728                 raw_inode->i_uid_high = 0;
2729                 raw_inode->i_gid_high = 0;
2730         }
2731 +#ifdef CONFIG_TAGGING_INTERN
2732 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2733 +#endif
2734         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2735  
2736         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
2737 @@ -4852,7 +4884,8 @@ int ext4_setattr(struct dentry *dentry,
2738                         return error;
2739         }
2740         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2741 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2742 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2743 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2744                 handle_t *handle;
2745  
2746                 /* (user+group)*(old+new) structure, inode write (sb,
2747 @@ -4875,6 +4908,8 @@ int ext4_setattr(struct dentry *dentry,
2748                         inode->i_uid = attr->ia_uid;
2749                 if (attr->ia_valid & ATTR_GID)
2750                         inode->i_gid = attr->ia_gid;
2751 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2752 +                       inode->i_tag = attr->ia_tag;
2753                 error = ext4_mark_inode_dirty(handle, inode);
2754                 ext4_journal_stop(handle);
2755         }
2756 diff -NurpP --minimal linux-4.4.110/fs/ext4/ioctl.c linux-4.4.110-vs2.3.9/fs/ext4/ioctl.c
2757 --- linux-4.4.110/fs/ext4/ioctl.c       2018-01-09 16:35:06.000000000 +0000
2758 +++ linux-4.4.110-vs2.3.9/fs/ext4/ioctl.c       2018-01-09 16:36:31.000000000 +0000
2759 @@ -14,6 +14,7 @@
2760  #include <linux/mount.h>
2761  #include <linux/file.h>
2762  #include <linux/random.h>
2763 +#include <linux/vs_tag.h>
2764  #include <asm/uaccess.h>
2765  #include "ext4_jbd2.h"
2766  #include "ext4.h"
2767 @@ -202,6 +203,33 @@ static int uuid_is_zero(__u8 u[16])
2768         return 1;
2769  }
2770  
2771 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
2772 +{
2773 +       handle_t *handle = NULL;
2774 +       struct ext4_iloc iloc;
2775 +       int err;
2776 +
2777 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
2778 +       if (IS_ERR(handle))
2779 +               return PTR_ERR(handle);
2780 +
2781 +       if (IS_SYNC(inode))
2782 +               ext4_handle_sync(handle);
2783 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
2784 +       if (err)
2785 +               goto flags_err;
2786 +
2787 +       inode->i_flags = flags;
2788 +       inode->i_vflags = vflags;
2789 +       ext4_get_inode_flags(EXT4_I(inode));
2790 +       inode->i_ctime = ext4_current_time(inode);
2791 +
2792 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
2793 +flags_err:
2794 +       ext4_journal_stop(handle);
2795 +       return err;
2796 +}
2797 +
2798  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2799  {
2800         struct inode *inode = file_inode(filp);
2801 @@ -235,6 +263,11 @@ long ext4_ioctl(struct file *filp, unsig
2802  
2803                 flags = ext4_mask_flags(inode->i_mode, flags);
2804  
2805 +               if (IS_BARRIER(inode)) {
2806 +                       vxwprintk_task(1, "messing with the barrier.");
2807 +                       return -EACCES;
2808 +               }
2809 +
2810                 err = -EPERM;
2811                 mutex_lock(&inode->i_mutex);
2812                 /* Is it quota file? Do not allow user to mess with it */
2813 @@ -252,7 +285,9 @@ long ext4_ioctl(struct file *filp, unsig
2814                  *
2815                  * This test looks nicer. Thanks to Pauline Middelink
2816                  */
2817 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
2818 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
2819 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
2820 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
2821                         if (!capable(CAP_LINUX_IMMUTABLE))
2822                                 goto flags_out;
2823                 }
2824 diff -NurpP --minimal linux-4.4.110/fs/ext4/namei.c linux-4.4.110-vs2.3.9/fs/ext4/namei.c
2825 --- linux-4.4.110/fs/ext4/namei.c       2018-01-09 16:35:06.000000000 +0000
2826 +++ linux-4.4.110-vs2.3.9/fs/ext4/namei.c       2018-01-09 16:36:31.000000000 +0000
2827 @@ -33,6 +33,7 @@
2828  #include <linux/quotaops.h>
2829  #include <linux/buffer_head.h>
2830  #include <linux/bio.h>
2831 +#include <linux/vs_tag.h>
2832  #include "ext4.h"
2833  #include "ext4_jbd2.h"
2834  
2835 @@ -1444,6 +1445,7 @@ restart:
2836                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
2837                                                     1, &bh);
2838                         }
2839 +               dx_propagate_tag(nd, inode);
2840                 }
2841                 if ((bh = bh_use[ra_ptr++]) == NULL)
2842                         goto next;
2843 @@ -3881,6 +3883,7 @@ const struct inode_operations ext4_dir_i
2844         .get_acl        = ext4_get_acl,
2845         .set_acl        = ext4_set_acl,
2846         .fiemap         = ext4_fiemap,
2847 +       .sync_flags     = ext4_sync_flags,
2848  };
2849  
2850  const struct inode_operations ext4_special_inode_operations = {
2851 diff -NurpP --minimal linux-4.4.110/fs/ext4/super.c linux-4.4.110-vs2.3.9/fs/ext4/super.c
2852 --- linux-4.4.110/fs/ext4/super.c       2018-01-09 16:35:06.000000000 +0000
2853 +++ linux-4.4.110-vs2.3.9/fs/ext4/super.c       2018-01-09 16:36:32.000000000 +0000
2854 @@ -1165,6 +1165,7 @@ enum {
2855         Opt_dioread_nolock, Opt_dioread_lock,
2856         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
2857         Opt_max_dir_size_kb, Opt_nojournal_checksum,
2858 +       Opt_tag, Opt_notag, Opt_tagid
2859  };
2860  
2861  static const match_table_t tokens = {
2862 @@ -1250,6 +1251,9 @@ static const match_table_t tokens = {
2863         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
2864         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
2865         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
2866 +       {Opt_tag, "tag"},
2867 +       {Opt_notag, "notag"},
2868 +       {Opt_tagid, "tagid=%u"},
2869         {Opt_err, NULL},
2870  };
2871  
2872 @@ -1492,6 +1496,20 @@ static int handle_mount_opt(struct super
2873         case Opt_nolazytime:
2874                 sb->s_flags &= ~MS_LAZYTIME;
2875                 return 1;
2876 +#ifndef CONFIG_TAGGING_NONE
2877 +       case Opt_tag:
2878 +               set_opt(sb, TAGGED);
2879 +               return 1;
2880 +       case Opt_notag:
2881 +               clear_opt(sb, TAGGED);
2882 +               return 1;
2883 +#endif
2884 +#ifdef CONFIG_PROPAGATE
2885 +       case Opt_tagid:
2886 +               /* use args[0] */
2887 +               set_opt(sb, TAGGED);
2888 +               return 1;
2889 +#endif
2890         }
2891  
2892         for (m = ext4_mount_opts; m->token != Opt_err; m++)
2893 @@ -3379,6 +3397,9 @@ static int ext4_fill_super(struct super_
2894                 sb->s_iflags |= SB_I_CGROUPWB;
2895         }
2896  
2897 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
2898 +               sb->s_flags |= MS_TAGGED;
2899 +
2900         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2901                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2902  
2903 @@ -4727,6 +4748,14 @@ static int ext4_remount(struct super_blo
2904         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
2905                 ext4_abort(sb, "Abort forced by user");
2906  
2907 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
2908 +               !(sb->s_flags & MS_TAGGED)) {
2909 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
2910 +                       sb->s_id);
2911 +               err = -EINVAL;
2912 +               goto restore_opts;
2913 +       }
2914 +
2915         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2916                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2917  
2918 diff -NurpP --minimal linux-4.4.110/fs/fcntl.c linux-4.4.110-vs2.3.9/fs/fcntl.c
2919 --- linux-4.4.110/fs/fcntl.c    2018-01-09 16:35:06.000000000 +0000
2920 +++ linux-4.4.110-vs2.3.9/fs/fcntl.c    2018-01-09 16:36:32.000000000 +0000
2921 @@ -22,6 +22,7 @@
2922  #include <linux/pid_namespace.h>
2923  #include <linux/user_namespace.h>
2924  #include <linux/shmem_fs.h>
2925 +#include <linux/vs_limit.h>
2926  
2927  #include <asm/poll.h>
2928  #include <asm/siginfo.h>
2929 @@ -385,6 +386,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
2930  
2931         if (!f.file)
2932                 goto out;
2933 +       if (!vx_files_avail(1))
2934 +               goto out;
2935  
2936         if (unlikely(f.file->f_mode & FMODE_PATH)) {
2937                 if (!check_fcntl_cmd(cmd))
2938 diff -NurpP --minimal linux-4.4.110/fs/file.c linux-4.4.110-vs2.3.9/fs/file.c
2939 --- linux-4.4.110/fs/file.c     2016-07-05 04:15:07.000000000 +0000
2940 +++ linux-4.4.110-vs2.3.9/fs/file.c     2018-01-09 16:36:32.000000000 +0000
2941 @@ -22,6 +22,7 @@
2942  #include <linux/spinlock.h>
2943  #include <linux/rcupdate.h>
2944  #include <linux/workqueue.h>
2945 +#include <linux/vs_limit.h>
2946  
2947  int sysctl_nr_open __read_mostly = 1024*1024;
2948  int sysctl_nr_open_min = BITS_PER_LONG;
2949 @@ -356,6 +357,8 @@ struct files_struct *dup_fd(struct files
2950                 struct file *f = *old_fds++;
2951                 if (f) {
2952                         get_file(f);
2953 +                       /* TODO: sum it first for check and performance */
2954 +                       vx_openfd_inc(open_files - i);
2955                 } else {
2956                         /*
2957                          * The fd may be claimed in the fd bitmap but not yet
2958 @@ -405,9 +408,11 @@ static struct fdtable *close_files(struc
2959                                         filp_close(file, files);
2960                                         cond_resched_rcu_qs();
2961                                 }
2962 +                               vx_openfd_dec(i);
2963                         }
2964                         i++;
2965                         set >>= 1;
2966 +                       cond_resched();
2967                 }
2968         }
2969  
2970 @@ -538,6 +543,7 @@ repeat:
2971         else
2972                 __clear_close_on_exec(fd, fdt);
2973         error = fd;
2974 +       vx_openfd_inc(fd);
2975  #if 1
2976         /* Sanity check */
2977         if (rcu_access_pointer(fdt->fd[fd]) != NULL) {
2978 @@ -568,6 +574,7 @@ static void __put_unused_fd(struct files
2979         __clear_open_fd(fd, fdt);
2980         if (fd < files->next_fd)
2981                 files->next_fd = fd;
2982 +       vx_openfd_dec(fd);
2983  }
2984  
2985  void put_unused_fd(unsigned int fd)
2986 @@ -850,6 +857,8 @@ __releases(&files->file_lock)
2987  
2988         if (tofree)
2989                 filp_close(tofree, files);
2990 +       else
2991 +               vx_openfd_inc(fd);      /* fd was unused */
2992  
2993         return fd;
2994  
2995 diff -NurpP --minimal linux-4.4.110/fs/file_table.c linux-4.4.110-vs2.3.9/fs/file_table.c
2996 --- linux-4.4.110/fs/file_table.c       2015-10-29 09:21:35.000000000 +0000
2997 +++ linux-4.4.110-vs2.3.9/fs/file_table.c       2018-01-09 17:25:51.000000000 +0000
2998 @@ -26,6 +26,8 @@
2999  #include <linux/task_work.h>
3000  #include <linux/ima.h>
3001  #include <linux/swap.h>
3002 +#include <linux/vs_limit.h>
3003 +#include <linux/vs_context.h>
3004  
3005  #include <linux/atomic.h>
3006  
3007 @@ -137,6 +139,8 @@ struct file *get_empty_filp(void)
3008         mutex_init(&f->f_pos_lock);
3009         eventpoll_init_file(f);
3010         /* f->f_version: 0 */
3011 +       f->f_xid = vx_current_xid();
3012 +       vx_files_inc(f);
3013         return f;
3014  
3015  over:
3016 @@ -219,6 +223,8 @@ static void __fput(struct file *file)
3017                 put_write_access(inode);
3018                 __mnt_drop_write(mnt);
3019         }
3020 +       vx_files_dec(file);
3021 +       file->f_xid = 0;
3022         file->f_path.dentry = NULL;
3023         file->f_path.mnt = NULL;
3024         file->f_inode = NULL;
3025 @@ -305,6 +311,8 @@ void put_filp(struct file *file)
3026  {
3027         if (atomic_long_dec_and_test(&file->f_count)) {
3028                 security_file_free(file);
3029 +               vx_files_dec(file);
3030 +               file->f_xid = 0;
3031                 file_free(file);
3032         }
3033  }
3034 diff -NurpP --minimal linux-4.4.110/fs/fs_struct.c linux-4.4.110-vs2.3.9/fs/fs_struct.c
3035 --- linux-4.4.110/fs/fs_struct.c        2015-04-12 22:12:50.000000000 +0000
3036 +++ linux-4.4.110-vs2.3.9/fs/fs_struct.c        2018-01-09 16:36:32.000000000 +0000
3037 @@ -4,6 +4,7 @@
3038  #include <linux/path.h>
3039  #include <linux/slab.h>
3040  #include <linux/fs_struct.h>
3041 +#include <linux/vserver/global.h>
3042  #include "internal.h"
3043  
3044  /*
3045 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3046  {
3047         path_put(&fs->root);
3048         path_put(&fs->pwd);
3049 +       atomic_dec(&vs_global_fs);
3050         kmem_cache_free(fs_cachep, fs);
3051  }
3052  
3053 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3054                 fs->pwd = old->pwd;
3055                 path_get(&fs->pwd);
3056                 spin_unlock(&old->lock);
3057 +               atomic_inc(&vs_global_fs);
3058         }
3059         return fs;
3060  }
3061 diff -NurpP --minimal linux-4.4.110/fs/gfs2/file.c linux-4.4.110-vs2.3.9/fs/gfs2/file.c
3062 --- linux-4.4.110/fs/gfs2/file.c        2018-01-09 16:35:06.000000000 +0000
3063 +++ linux-4.4.110-vs2.3.9/fs/gfs2/file.c        2018-01-09 17:23:53.000000000 +0000
3064 @@ -137,6 +137,9 @@ static const u32 fsflags_to_gfs2[32] = {
3065         [12] = GFS2_DIF_EXHASH,
3066         [14] = GFS2_DIF_INHERIT_JDATA,
3067         [17] = GFS2_DIF_TOPDIR,
3068 +       [27] = GFS2_DIF_IXUNLINK,
3069 +       [26] = GFS2_DIF_BARRIER,
3070 +       [29] = GFS2_DIF_COW,
3071  };
3072  
3073  static const u32 gfs2_to_fsflags[32] = {
3074 @@ -147,6 +150,9 @@ static const u32 gfs2_to_fsflags[32] = {
3075         [gfs2fl_ExHash] = FS_INDEX_FL,
3076         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3077         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3078 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3079 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3080 +       [gfs2fl_Cow] = FS_COW_FL,
3081  };
3082  
3083  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3084 @@ -177,12 +183,17 @@ void gfs2_set_inode_flags(struct inode *
3085  {
3086         struct gfs2_inode *ip = GFS2_I(inode);
3087         unsigned int flags = inode->i_flags;
3088 +       unsigned int vflags = inode->i_vflags;
3089  
3090 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3091 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3092 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3093 +
3094         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3095                 flags |= S_NOSEC;
3096         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3097                 flags |= S_IMMUTABLE;
3098 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3099 +               flags |= S_IXUNLINK;
3100         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3101                 flags |= S_APPEND;
3102         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3103 @@ -190,6 +201,43 @@ void gfs2_set_inode_flags(struct inode *
3104         if (ip->i_diskflags & GFS2_DIF_SYNC)
3105                 flags |= S_SYNC;
3106         inode->i_flags = flags;
3107 +
3108 +       vflags &= ~(V_BARRIER | V_COW);
3109 +
3110 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3111 +               vflags |= V_BARRIER;
3112 +       if (ip->i_diskflags & GFS2_DIF_COW)
3113 +               vflags |= V_COW;
3114 +       inode->i_vflags = vflags;
3115 +}
3116 +
3117 +void gfs2_get_inode_flags(struct inode *inode)
3118 +{
3119 +       struct gfs2_inode *ip = GFS2_I(inode);
3120 +       unsigned int flags = inode->i_flags;
3121 +       unsigned int vflags = inode->i_vflags;
3122 +
3123 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3124 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3125 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3126 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3127 +
3128 +       if (flags & S_IMMUTABLE)
3129 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3130 +       if (flags & S_IXUNLINK)
3131 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3132 +
3133 +       if (flags & S_APPEND)
3134 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3135 +       if (flags & S_NOATIME)
3136 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3137 +       if (flags & S_SYNC)
3138 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3139 +
3140 +       if (vflags & V_BARRIER)
3141 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3142 +       if (vflags & V_COW)
3143 +               ip->i_diskflags |= GFS2_DIF_COW;
3144  }
3145  
3146  /* Flags that can be set by user space */
3147 @@ -305,6 +353,37 @@ static int gfs2_set_flags(struct file *f
3148         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3149  }
3150  
3151 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3152 +{
3153 +       struct gfs2_inode *ip = GFS2_I(inode);
3154 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3155 +       struct buffer_head *bh;
3156 +       struct gfs2_holder gh;
3157 +       int error;
3158 +
3159 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3160 +       if (error)
3161 +               return error;
3162 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3163 +       if (error)
3164 +               goto out;
3165 +       error = gfs2_meta_inode_buffer(ip, &bh);
3166 +       if (error)
3167 +               goto out_trans_end;
3168 +       gfs2_trans_add_meta(ip->i_gl, bh);
3169 +       inode->i_flags = flags;
3170 +       inode->i_vflags = vflags;
3171 +       gfs2_get_inode_flags(inode);
3172 +       gfs2_dinode_out(ip, bh->b_data);
3173 +       brelse(bh);
3174 +       gfs2_set_aops(inode);
3175 +out_trans_end:
3176 +       gfs2_trans_end(sdp);
3177 +out:
3178 +       gfs2_glock_dq_uninit(&gh);
3179 +       return error;
3180 +}
3181 +
3182  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3183  {
3184         switch(cmd) {
3185 diff -NurpP --minimal linux-4.4.110/fs/gfs2/inode.h linux-4.4.110-vs2.3.9/fs/gfs2/inode.h
3186 --- linux-4.4.110/fs/gfs2/inode.h       2015-04-12 22:12:50.000000000 +0000
3187 +++ linux-4.4.110-vs2.3.9/fs/gfs2/inode.h       2018-01-09 16:36:32.000000000 +0000
3188 @@ -118,6 +118,7 @@ extern const struct file_operations gfs2
3189  extern const struct file_operations gfs2_dir_fops_nolock;
3190  
3191  extern void gfs2_set_inode_flags(struct inode *inode);
3192 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3193   
3194  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3195  extern const struct file_operations gfs2_file_fops;
3196 diff -NurpP --minimal linux-4.4.110/fs/hostfs/hostfs.h linux-4.4.110-vs2.3.9/fs/hostfs/hostfs.h
3197 --- linux-4.4.110/fs/hostfs/hostfs.h    2015-07-06 20:41:42.000000000 +0000
3198 +++ linux-4.4.110-vs2.3.9/fs/hostfs/hostfs.h    2018-01-09 16:36:32.000000000 +0000
3199 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3200         unsigned short  ia_mode;
3201         uid_t           ia_uid;
3202         gid_t           ia_gid;
3203 +       vtag_t          ia_tag;
3204         loff_t          ia_size;
3205         struct timespec ia_atime;
3206         struct timespec ia_mtime;
3207 diff -NurpP --minimal linux-4.4.110/fs/inode.c linux-4.4.110-vs2.3.9/fs/inode.c
3208 --- linux-4.4.110/fs/inode.c    2018-01-09 16:35:06.000000000 +0000
3209 +++ linux-4.4.110-vs2.3.9/fs/inode.c    2018-01-09 16:36:32.000000000 +0000
3210 @@ -18,6 +18,7 @@
3211  #include <linux/buffer_head.h> /* for inode_has_buffers */
3212  #include <linux/ratelimit.h>
3213  #include <linux/list_lru.h>
3214 +#include <linux/vs_tag.h>
3215  #include <trace/events/writeback.h>
3216  #include "internal.h"
3217  
3218 @@ -133,6 +134,8 @@ int inode_init_always(struct super_block
3219         struct address_space *const mapping = &inode->i_data;
3220  
3221         inode->i_sb = sb;
3222 +
3223 +       /* essential because of inode slab reuse */
3224         inode->i_blkbits = sb->s_blocksize_bits;
3225         inode->i_flags = 0;
3226         atomic_set(&inode->i_count, 1);
3227 @@ -142,6 +145,7 @@ int inode_init_always(struct super_block
3228         inode->i_opflags = 0;
3229         i_uid_write(inode, 0);
3230         i_gid_write(inode, 0);
3231 +       i_tag_write(inode, 0);
3232         atomic_set(&inode->i_writecount, 0);
3233         inode->i_size = 0;
3234         inode->i_blocks = 0;
3235 @@ -152,6 +156,7 @@ int inode_init_always(struct super_block
3236         inode->i_cdev = NULL;
3237         inode->i_link = NULL;
3238         inode->i_rdev = 0;
3239 +       inode->i_mdev = 0;
3240         inode->dirtied_when = 0;
3241  
3242         if (security_inode_alloc(inode))
3243 @@ -469,6 +474,8 @@ void __insert_inode_hash(struct inode *i
3244  }
3245  EXPORT_SYMBOL(__insert_inode_hash);
3246  
3247 +EXPORT_SYMBOL_GPL(__iget);
3248 +
3249  /**
3250   *     __remove_inode_hash - remove an inode from the hash
3251   *     @inode: inode to unhash
3252 @@ -1911,9 +1918,11 @@ void init_special_inode(struct inode *in
3253         if (S_ISCHR(mode)) {
3254                 inode->i_fop = &def_chr_fops;
3255                 inode->i_rdev = rdev;
3256 +               inode->i_mdev = rdev;
3257         } else if (S_ISBLK(mode)) {
3258                 inode->i_fop = &def_blk_fops;
3259                 inode->i_rdev = rdev;
3260 +               inode->i_mdev = rdev;
3261         } else if (S_ISFIFO(mode))
3262                 inode->i_fop = &pipefifo_fops;
3263         else if (S_ISSOCK(mode))
3264 @@ -1942,6 +1951,7 @@ void inode_init_owner(struct inode *inod
3265         } else
3266                 inode->i_gid = current_fsgid();
3267         inode->i_mode = mode;
3268 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3269  }
3270  EXPORT_SYMBOL(inode_init_owner);
3271  
3272 diff -NurpP --minimal linux-4.4.110/fs/ioctl.c linux-4.4.110-vs2.3.9/fs/ioctl.c
3273 --- linux-4.4.110/fs/ioctl.c    2015-04-12 22:12:50.000000000 +0000
3274 +++ linux-4.4.110-vs2.3.9/fs/ioctl.c    2018-01-09 16:36:32.000000000 +0000
3275 @@ -15,6 +15,9 @@
3276  #include <linux/writeback.h>
3277  #include <linux/buffer_head.h>
3278  #include <linux/falloc.h>
3279 +#include <linux/proc_fs.h>
3280 +#include <linux/vserver/inode.h>
3281 +#include <linux/vs_tag.h>
3282  
3283  #include <asm/ioctls.h>
3284  
3285 diff -NurpP --minimal linux-4.4.110/fs/jfs/file.c linux-4.4.110-vs2.3.9/fs/jfs/file.c
3286 --- linux-4.4.110/fs/jfs/file.c 2016-07-05 04:12:33.000000000 +0000
3287 +++ linux-4.4.110-vs2.3.9/fs/jfs/file.c 2018-01-09 16:36:32.000000000 +0000
3288 @@ -113,7 +113,8 @@ int jfs_setattr(struct dentry *dentry, s
3289                         return rc;
3290         }
3291         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3292 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3293 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3294 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3295                 rc = dquot_transfer(inode, iattr);
3296                 if (rc)
3297                         return rc;
3298 @@ -149,6 +150,7 @@ const struct inode_operations jfs_file_i
3299         .get_acl        = jfs_get_acl,
3300         .set_acl        = jfs_set_acl,
3301  #endif
3302 +       .sync_flags     = jfs_sync_flags,
3303  };
3304  
3305  const struct file_operations jfs_file_operations = {
3306 diff -NurpP --minimal linux-4.4.110/fs/jfs/ioctl.c linux-4.4.110-vs2.3.9/fs/jfs/ioctl.c
3307 --- linux-4.4.110/fs/jfs/ioctl.c        2015-10-29 09:21:36.000000000 +0000
3308 +++ linux-4.4.110-vs2.3.9/fs/jfs/ioctl.c        2018-01-09 16:36:32.000000000 +0000
3309 @@ -12,6 +12,7 @@
3310  #include <linux/time.h>
3311  #include <linux/sched.h>
3312  #include <linux/blkdev.h>
3313 +#include <linux/mount.h>
3314  #include <asm/current.h>
3315  #include <asm/uaccess.h>
3316  
3317 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3318  }
3319  
3320  
3321 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3322 +{
3323 +       inode->i_flags = flags;
3324 +       inode->i_vflags = vflags;
3325 +       jfs_get_inode_flags(JFS_IP(inode));
3326 +       inode->i_ctime = CURRENT_TIME_SEC;
3327 +       mark_inode_dirty(inode);
3328 +       return 0;
3329 +}
3330 +
3331  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3332  {
3333         struct inode *inode = file_inode(filp);
3334 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3335                 if (!S_ISDIR(inode->i_mode))
3336                         flags &= ~JFS_DIRSYNC_FL;
3337  
3338 +               if (IS_BARRIER(inode)) {
3339 +                       vxwprintk_task(1, "messing with the barrier.");
3340 +                       return -EACCES;
3341 +               }
3342 +
3343                 /* Is it quota file? Do not allow user to mess with it */
3344                 if (IS_NOQUOTA(inode)) {
3345                         err = -EPERM;
3346 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3347                  * the relevant capability.
3348                  */
3349                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3350 -                       ((flags ^ oldflags) &
3351 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3352 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3353 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3354                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3355                                 mutex_unlock(&inode->i_mutex);
3356                                 err = -EPERM;
3357 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3358                         }
3359                 }
3360  
3361 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3362 +               flags &= JFS_FL_USER_MODIFIABLE;
3363                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3364                 jfs_inode->mode2 = flags;
3365  
3366 diff -NurpP --minimal linux-4.4.110/fs/jfs/jfs_dinode.h linux-4.4.110-vs2.3.9/fs/jfs/jfs_dinode.h
3367 --- linux-4.4.110/fs/jfs/jfs_dinode.h   2015-04-12 22:12:50.000000000 +0000
3368 +++ linux-4.4.110-vs2.3.9/fs/jfs/jfs_dinode.h   2018-01-09 16:36:32.000000000 +0000
3369 @@ -161,9 +161,13 @@ struct dinode {
3370  
3371  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3372  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3373 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3374  
3375 -#define JFS_FL_USER_VISIBLE    0x03F80000
3376 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3377 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3378 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3379 +
3380 +#define JFS_FL_USER_VISIBLE    0x07F80000
3381 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3382  #define JFS_FL_INHERIT         0x03C80000
3383  
3384  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3385 diff -NurpP --minimal linux-4.4.110/fs/jfs/jfs_filsys.h linux-4.4.110-vs2.3.9/fs/jfs/jfs_filsys.h
3386 --- linux-4.4.110/fs/jfs/jfs_filsys.h   2015-04-12 22:12:50.000000000 +0000
3387 +++ linux-4.4.110-vs2.3.9/fs/jfs/jfs_filsys.h   2018-01-09 16:36:32.000000000 +0000
3388 @@ -266,6 +266,7 @@
3389  #define JFS_NAME_MAX   255
3390  #define JFS_PATH_MAX   BPSIZE
3391  
3392 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3393  
3394  /*
3395   *     file system state (superblock state)
3396 diff -NurpP --minimal linux-4.4.110/fs/jfs/jfs_imap.c linux-4.4.110-vs2.3.9/fs/jfs/jfs_imap.c
3397 --- linux-4.4.110/fs/jfs/jfs_imap.c     2015-04-12 22:12:50.000000000 +0000
3398 +++ linux-4.4.110-vs2.3.9/fs/jfs/jfs_imap.c     2018-01-09 16:36:32.000000000 +0000
3399 @@ -46,6 +46,7 @@
3400  #include <linux/pagemap.h>
3401  #include <linux/quotaops.h>
3402  #include <linux/slab.h>
3403 +#include <linux/vs_tag.h>
3404  
3405  #include "jfs_incore.h"
3406  #include "jfs_inode.h"
3407 @@ -3047,6 +3048,8 @@ static int copy_from_dinode(struct dinod
3408  {
3409         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3410         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3411 +       kuid_t kuid;
3412 +       kgid_t kgid;
3413  
3414         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3415         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3416 @@ -3067,14 +3070,18 @@ static int copy_from_dinode(struct dinod
3417         }
3418         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3419  
3420 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3421 +       kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3422 +       kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3423 +       ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3424 +
3425 +       jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3426         if (!uid_valid(sbi->uid))
3427                 ip->i_uid = jfs_ip->saved_uid;
3428         else {
3429                 ip->i_uid = sbi->uid;
3430         }
3431  
3432 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3433 +       jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3434         if (!gid_valid(sbi->gid))
3435                 ip->i_gid = jfs_ip->saved_gid;
3436         else {
3437 @@ -3139,16 +3146,14 @@ static void copy_to_dinode(struct dinode
3438         dip->di_size = cpu_to_le64(ip->i_size);
3439         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3440         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3441 -       if (!uid_valid(sbi->uid))
3442 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3443 -       else
3444 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3445 -                                                  jfs_ip->saved_uid));
3446 -       if (!gid_valid(sbi->gid))
3447 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3448 -       else
3449 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3450 -                                                   jfs_ip->saved_gid));
3451 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3452 +               TAGINO_KUID(DX_TAG(ip),
3453 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3454 +               ip->i_tag)));
3455 +       dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3456 +               TAGINO_KGID(DX_TAG(ip),
3457 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3458 +               ip->i_tag)));
3459         jfs_get_inode_flags(jfs_ip);
3460         /*
3461          * mode2 is only needed for storing the higher order bits.
3462 diff -NurpP --minimal linux-4.4.110/fs/jfs/jfs_inode.c linux-4.4.110-vs2.3.9/fs/jfs/jfs_inode.c
3463 --- linux-4.4.110/fs/jfs/jfs_inode.c    2016-07-05 04:12:33.000000000 +0000
3464 +++ linux-4.4.110-vs2.3.9/fs/jfs/jfs_inode.c    2018-01-09 16:36:32.000000000 +0000
3465 @@ -18,6 +18,7 @@
3466  
3467  #include <linux/fs.h>
3468  #include <linux/quotaops.h>
3469 +#include <linux/vs_tag.h>
3470  #include "jfs_incore.h"
3471  #include "jfs_inode.h"
3472  #include "jfs_filsys.h"
3473 @@ -33,26 +34,45 @@ void jfs_set_inode_flags(struct inode *i
3474  
3475         if (flags & JFS_IMMUTABLE_FL)
3476                 new_fl |= S_IMMUTABLE;
3477 +       if (flags & JFS_IXUNLINK_FL)
3478 +               inode->i_flags |= S_IXUNLINK;
3479 +
3480 +       if (flags & JFS_SYNC_FL)
3481 +               inode->i_flags |= S_SYNC;
3482         if (flags & JFS_APPEND_FL)
3483                 new_fl |= S_APPEND;
3484         if (flags & JFS_NOATIME_FL)
3485                 new_fl |= S_NOATIME;
3486         if (flags & JFS_DIRSYNC_FL)
3487                 new_fl |= S_DIRSYNC;
3488 -       if (flags & JFS_SYNC_FL)
3489 -               new_fl |= S_SYNC;
3490 -       inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND | S_NOATIME |
3491 +       inode_set_flags(inode, new_fl, S_IMMUTABLE | S_IXUNLINK | S_APPEND | S_NOATIME |
3492                         S_DIRSYNC | S_SYNC);
3493 +
3494 +       new_fl = 0;
3495 +       if (flags & JFS_BARRIER_FL)
3496 +               new_fl |= V_BARRIER;
3497 +       if (flags & JFS_COW_FL)
3498 +               new_fl |= V_COW;
3499 +
3500 +       set_mask_bits(&inode->i_vflags,
3501 +               V_BARRIER | V_COW, new_fl);
3502  }
3503  
3504  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3505  {
3506         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3507 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3508 +
3509 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3510 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3511 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3512 +                          JFS_BARRIER_FL | JFS_COW_FL);
3513  
3514 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3515 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3516         if (flags & S_IMMUTABLE)
3517                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3518 +       if (flags & S_IXUNLINK)
3519 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3520 +
3521         if (flags & S_APPEND)
3522                 jfs_ip->mode2 |= JFS_APPEND_FL;
3523         if (flags & S_NOATIME)
3524 @@ -61,6 +81,11 @@ void jfs_get_inode_flags(struct jfs_inod
3525                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3526         if (flags & S_SYNC)
3527                 jfs_ip->mode2 |= JFS_SYNC_FL;
3528 +
3529 +       if (vflags & V_BARRIER)
3530 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3531 +       if (vflags & V_COW)
3532 +               jfs_ip->mode2 |= JFS_COW_FL;
3533  }
3534  
3535  /*
3536 diff -NurpP --minimal linux-4.4.110/fs/jfs/jfs_inode.h linux-4.4.110-vs2.3.9/fs/jfs/jfs_inode.h
3537 --- linux-4.4.110/fs/jfs/jfs_inode.h    2015-04-12 22:12:50.000000000 +0000
3538 +++ linux-4.4.110-vs2.3.9/fs/jfs/jfs_inode.h    2018-01-09 16:36:32.000000000 +0000
3539 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3540  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3541         int fh_len, int fh_type);
3542  extern void jfs_set_inode_flags(struct inode *);
3543 +extern int jfs_sync_flags(struct inode *, int, int);
3544  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3545  extern int jfs_setattr(struct dentry *, struct iattr *);
3546  
3547 diff -NurpP --minimal linux-4.4.110/fs/jfs/namei.c linux-4.4.110-vs2.3.9/fs/jfs/namei.c
3548 --- linux-4.4.110/fs/jfs/namei.c        2016-07-05 04:15:08.000000000 +0000
3549 +++ linux-4.4.110-vs2.3.9/fs/jfs/namei.c        2018-01-09 16:36:32.000000000 +0000
3550 @@ -22,6 +22,7 @@
3551  #include <linux/ctype.h>
3552  #include <linux/quotaops.h>
3553  #include <linux/exportfs.h>
3554 +#include <linux/vs_tag.h>
3555  #include "jfs_incore.h"
3556  #include "jfs_superblock.h"
3557  #include "jfs_inode.h"
3558 @@ -1480,6 +1481,7 @@ static struct dentry *jfs_lookup(struct
3559                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3560         }
3561  
3562 +       dx_propagate_tag(nd, ip);
3563         return d_splice_alias(ip, dentry);
3564  }
3565  
3566 @@ -1545,6 +1547,7 @@ const struct inode_operations jfs_dir_in
3567         .get_acl        = jfs_get_acl,
3568         .set_acl        = jfs_set_acl,
3569  #endif
3570 +       .sync_flags     = jfs_sync_flags,
3571  };
3572  
3573  const struct file_operations jfs_dir_operations = {
3574 diff -NurpP --minimal linux-4.4.110/fs/jfs/super.c linux-4.4.110-vs2.3.9/fs/jfs/super.c
3575 --- linux-4.4.110/fs/jfs/super.c        2018-01-09 16:35:06.000000000 +0000
3576 +++ linux-4.4.110-vs2.3.9/fs/jfs/super.c        2018-01-09 16:36:32.000000000 +0000
3577 @@ -206,7 +206,8 @@ enum {
3578         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3579         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3580         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3581 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
3582 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
3583 +       Opt_tag, Opt_notag, Opt_tagid
3584  };
3585  
3586  static const match_table_t tokens = {
3587 @@ -216,6 +217,10 @@ static const match_table_t tokens = {
3588         {Opt_resize, "resize=%u"},
3589         {Opt_resize_nosize, "resize"},
3590         {Opt_errors, "errors=%s"},
3591 +       {Opt_tag, "tag"},
3592 +       {Opt_notag, "notag"},
3593 +       {Opt_tagid, "tagid=%u"},
3594 +       {Opt_tag, "tagxid"},
3595         {Opt_ignore, "noquota"},
3596         {Opt_ignore, "quota"},
3597         {Opt_usrquota, "usrquota"},
3598 @@ -405,7 +410,20 @@ static int parse_options(char *options,
3599                                 pr_err("JFS: discard option not supported on device\n");
3600                         break;
3601                 }
3602 -
3603 +#ifndef CONFIG_TAGGING_NONE
3604 +               case Opt_tag:
3605 +                       *flag |= JFS_TAGGED;
3606 +                       break;
3607 +               case Opt_notag:
3608 +                       *flag &= JFS_TAGGED;
3609 +                       break;
3610 +#endif
3611 +#ifdef CONFIG_PROPAGATE
3612 +               case Opt_tagid:
3613 +                       /* use args[0] */
3614 +                       *flag |= JFS_TAGGED;
3615 +                       break;
3616 +#endif
3617                 default:
3618                         printk("jfs: Unrecognized mount option \"%s\" or missing value\n",
3619                                p);
3620 @@ -437,6 +455,12 @@ static int jfs_remount(struct super_bloc
3621         if (!parse_options(data, sb, &newLVSize, &flag))
3622                 return -EINVAL;
3623  
3624 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3625 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
3626 +                       sb->s_id);
3627 +               return -EINVAL;
3628 +       }
3629 +
3630         if (newLVSize) {
3631                 if (sb->s_flags & MS_RDONLY) {
3632                         pr_err("JFS: resize requires volume to be mounted read-write\n");
3633 @@ -517,6 +541,9 @@ static int jfs_fill_super(struct super_b
3634  #ifdef CONFIG_JFS_POSIX_ACL
3635         sb->s_flags |= MS_POSIXACL;
3636  #endif
3637 +       /* map mount option tagxid */
3638 +       if (sbi->flag & JFS_TAGGED)
3639 +               sb->s_flags |= MS_TAGGED;
3640  
3641         if (newLVSize) {
3642                 pr_err("resize option for remount only\n");
3643 diff -NurpP --minimal linux-4.4.110/fs/libfs.c linux-4.4.110-vs2.3.9/fs/libfs.c
3644 --- linux-4.4.110/fs/libfs.c    2016-07-05 04:12:33.000000000 +0000
3645 +++ linux-4.4.110-vs2.3.9/fs/libfs.c    2018-01-09 16:36:32.000000000 +0000
3646 @@ -141,13 +141,14 @@ static inline unsigned char dt_type(stru
3647   * both impossible due to the lock on directory.
3648   */
3649  
3650 -int dcache_readdir(struct file *file, struct dir_context *ctx)
3651 +static inline int do_dcache_readdir_filter(struct file *filp,
3652 +       struct dir_context *ctx, int (*filter)(struct dentry *dentry))
3653  {
3654 -       struct dentry *dentry = file->f_path.dentry;
3655 -       struct dentry *cursor = file->private_data;
3656 +       struct dentry *dentry = filp->f_path.dentry;
3657 +       struct dentry *cursor = filp->private_data;
3658         struct list_head *p, *q = &cursor->d_child;
3659  
3660 -       if (!dir_emit_dots(file, ctx))
3661 +       if (!dir_emit_dots(filp, ctx))
3662                 return 0;
3663         spin_lock(&dentry->d_lock);
3664         if (ctx->pos == 2)
3665 @@ -155,6 +156,8 @@ int dcache_readdir(struct file *file, st
3666  
3667         for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
3668                 struct dentry *next = list_entry(p, struct dentry, d_child);
3669 +               if (filter && !filter(next))
3670 +                       continue;
3671                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
3672                 if (!simple_positive(next)) {
3673                         spin_unlock(&next->d_lock);
3674 @@ -177,8 +180,22 @@ int dcache_readdir(struct file *file, st
3675         spin_unlock(&dentry->d_lock);
3676         return 0;
3677  }
3678 +
3679  EXPORT_SYMBOL(dcache_readdir);
3680  
3681 +int dcache_readdir(struct file *filp, struct dir_context *ctx)
3682 +{
3683 +       return do_dcache_readdir_filter(filp, ctx, NULL);
3684 +}
3685 +
3686 +EXPORT_SYMBOL(dcache_readdir_filter);
3687 +
3688 +int dcache_readdir_filter(struct file *filp, struct dir_context *ctx,
3689 +       int (*filter)(struct dentry *))
3690 +{
3691 +       return do_dcache_readdir_filter(filp, ctx, filter);
3692 +}
3693 +
3694  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
3695  {
3696         return -EISDIR;
3697 diff -NurpP --minimal linux-4.4.110/fs/locks.c linux-4.4.110-vs2.3.9/fs/locks.c
3698 --- linux-4.4.110/fs/locks.c    2018-01-09 16:35:06.000000000 +0000
3699 +++ linux-4.4.110-vs2.3.9/fs/locks.c    2018-01-09 16:36:32.000000000 +0000
3700 @@ -129,6 +129,8 @@
3701  #include <linux/hashtable.h>
3702  #include <linux/percpu.h>
3703  #include <linux/lglock.h>
3704 +#include <linux/vs_base.h>
3705 +#include <linux/vs_limit.h>
3706  
3707  #define CREATE_TRACE_POINTS
3708  #include <trace/events/filelock.h>
3709 @@ -255,11 +257,15 @@ static void locks_init_lock_heads(struct
3710  /* Allocate an empty lock structure. */
3711  struct file_lock *locks_alloc_lock(void)
3712  {
3713 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
3714 +       struct file_lock *fl;
3715  
3716 -       if (fl)
3717 -               locks_init_lock_heads(fl);
3718 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
3719  
3720 +       if (fl) {
3721 +               locks_init_lock_heads(fl);
3722 +               vx_locks_inc(fl);
3723 +               fl->fl_xid = -1;
3724 +       }
3725         return fl;
3726  }
3727  EXPORT_SYMBOL_GPL(locks_alloc_lock);
3728 @@ -311,6 +317,7 @@ void locks_init_lock(struct file_lock *f
3729  {
3730         memset(fl, 0, sizeof(struct file_lock));
3731         locks_init_lock_heads(fl);
3732 +       fl->fl_xid = -1;
3733  }
3734  
3735  EXPORT_SYMBOL(locks_init_lock);
3736 @@ -328,6 +335,7 @@ void locks_copy_conflock(struct file_loc
3737         new->fl_start = fl->fl_start;
3738         new->fl_end = fl->fl_end;
3739         new->fl_lmops = fl->fl_lmops;
3740 +       new->fl_xid = fl->fl_xid;
3741         new->fl_ops = NULL;
3742  
3743         if (fl->fl_lmops) {
3744 @@ -389,7 +397,10 @@ flock_make_lock(struct file *filp, unsig
3745         fl->fl_flags = FL_FLOCK;
3746         fl->fl_type = type;
3747         fl->fl_end = OFFSET_MAX;
3748 -       
3749 +
3750 +       vxd_assert(filp->f_xid == vx_current_xid(),
3751 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
3752 +       fl->fl_xid = filp->f_xid;
3753         return fl;
3754  }
3755  
3756 @@ -511,6 +522,7 @@ static int lease_init(struct file *filp,
3757  
3758         fl->fl_owner = filp;
3759         fl->fl_pid = current->tgid;
3760 +       fl->fl_xid = vx_current_xid();
3761  
3762         fl->fl_file = filp;
3763         fl->fl_flags = FL_LEASE;
3764 @@ -530,6 +542,10 @@ static struct file_lock *lease_alloc(str
3765         if (fl == NULL)
3766                 return ERR_PTR(error);
3767  
3768 +       fl->fl_xid = vx_current_xid();
3769 +       if (filp)
3770 +               vxd_assert(filp->f_xid == fl->fl_xid,
3771 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
3772         error = lease_init(filp, type, fl);
3773         if (error) {
3774                 locks_free_lock(fl);
3775 @@ -908,6 +924,7 @@ static int flock_lock_inode(struct inode
3776                 goto out;
3777         }
3778  
3779 +       new_fl->fl_xid = -1;
3780  find_conflict:
3781         list_for_each_entry(fl, &ctx->flc_flock, fl_list) {
3782                 if (!flock_locks_conflict(request, fl))
3783 @@ -934,7 +951,8 @@ out:
3784         return error;
3785  }
3786  
3787 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
3788 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
3789 +       struct file_lock *conflock, vxid_t xid)
3790  {
3791         struct file_lock *fl, *tmp;
3792         struct file_lock *new_fl = NULL;
3793 @@ -950,6 +968,9 @@ static int __posix_lock_file(struct inod
3794         if (!ctx)
3795                 return (request->fl_type == F_UNLCK) ? 0 : -ENOMEM;
3796  
3797 +       if (xid)
3798 +               vxd_assert(xid == vx_current_xid(),
3799 +                       "xid(%d) == current(%d)", xid, vx_current_xid());
3800         /*
3801          * We may need two file_lock structures for this operation,
3802          * so we get them in advance to avoid races.
3803 @@ -960,7 +981,11 @@ static int __posix_lock_file(struct inod
3804             (request->fl_type != F_UNLCK ||
3805              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
3806                 new_fl = locks_alloc_lock();
3807 +               new_fl->fl_xid = xid;
3808 +               // vx_locks_inc(new_fl);
3809                 new_fl2 = locks_alloc_lock();
3810 +               new_fl2->fl_xid = xid;
3811 +               // vx_locks_inc(new_fl2);
3812         }
3813  
3814         spin_lock(&ctx->flc_lock);
3815 @@ -1162,7 +1187,8 @@ static int __posix_lock_file(struct inod
3816  int posix_lock_file(struct file *filp, struct file_lock *fl,
3817                         struct file_lock *conflock)
3818  {
3819 -       return __posix_lock_file(file_inode(filp), fl, conflock);
3820 +       return __posix_lock_file(file_inode(filp),
3821 +               fl, conflock, filp->f_xid);
3822  }
3823  EXPORT_SYMBOL(posix_lock_file);
3824  
3825 @@ -1178,7 +1204,7 @@ static int posix_lock_inode_wait(struct
3826         int error;
3827         might_sleep ();
3828         for (;;) {
3829 -               error = __posix_lock_file(inode, fl, NULL);
3830 +               error = __posix_lock_file(inode, fl, NULL, 0);
3831                 if (error != FILE_LOCK_DEFERRED)
3832                         break;
3833                 error = wait_event_interruptible(fl->fl_wait, !fl->fl_next);
3834 @@ -1257,10 +1283,13 @@ int locks_mandatory_area(int read_write,
3835         fl.fl_end = offset + count - 1;
3836  
3837         for (;;) {
3838 +               vxid_t f_xid = 0;
3839 +
3840                 if (filp) {
3841                         fl.fl_owner = filp;
3842                         fl.fl_flags &= ~FL_SLEEP;
3843 -                       error = __posix_lock_file(inode, &fl, NULL);
3844 +                       f_xid = filp->f_xid;
3845 +                       error = __posix_lock_file(inode, &fl, NULL, f_xid);
3846                         if (!error)
3847                                 break;
3848                 }
3849 @@ -1268,7 +1297,7 @@ int locks_mandatory_area(int read_write,
3850                 if (sleep)
3851                         fl.fl_flags |= FL_SLEEP;
3852                 fl.fl_owner = current->files;
3853 -               error = __posix_lock_file(inode, &fl, NULL);
3854 +               error = __posix_lock_file(inode, &fl, NULL, f_xid);
3855                 if (error != FILE_LOCK_DEFERRED)
3856                         break;
3857                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
3858 @@ -2165,6 +2194,11 @@ int fcntl_setlk(unsigned int fd, struct
3859         if (file_lock == NULL)
3860                 return -ENOLCK;
3861  
3862 +       vxd_assert(filp->f_xid == vx_current_xid(),
3863 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
3864 +       file_lock->fl_xid = filp->f_xid;
3865 +       // vx_locks_inc(file_lock);
3866 +
3867         /*
3868          * This might block, so we do it before checking the inode.
3869          */
3870 @@ -2307,6 +2341,11 @@ int fcntl_setlk64(unsigned int fd, struc
3871         if (file_lock == NULL)
3872                 return -ENOLCK;
3873  
3874 +       vxd_assert(filp->f_xid == vx_current_xid(),
3875 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
3876 +       file_lock->fl_xid = filp->f_xid;
3877 +       // vx_locks_inc(file_lock);
3878 +
3879         /*
3880          * This might block, so we do it before checking the inode.
3881          */
3882 @@ -2620,8 +2659,11 @@ static int locks_show(struct seq_file *f
3883  
3884         lock_get_status(f, fl, iter->li_pos, "");
3885  
3886 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
3887 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
3888 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
3889 +                       continue;
3890                 lock_get_status(f, bfl, iter->li_pos, " ->");
3891 +       }
3892  
3893         return 0;
3894  }
3895 diff -NurpP --minimal linux-4.4.110/fs/mount.h linux-4.4.110-vs2.3.9/fs/mount.h
3896 --- linux-4.4.110/fs/mount.h    2018-01-09 16:35:06.000000000 +0000
3897 +++ linux-4.4.110-vs2.3.9/fs/mount.h    2018-01-09 16:36:32.000000000 +0000
3898 @@ -68,6 +68,7 @@ struct mount {
3899         struct hlist_head mnt_pins;
3900         struct fs_pin mnt_umount;
3901         struct dentry *mnt_ex_mountpoint;
3902 +       vtag_t mnt_tag;                 /* tagging used for vfsmount */
3903  };
3904  
3905  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
3906 diff -NurpP --minimal linux-4.4.110/fs/namei.c linux-4.4.110-vs2.3.9/fs/namei.c
3907 --- linux-4.4.110/fs/namei.c    2018-01-09 16:35:06.000000000 +0000
3908 +++ linux-4.4.110-vs2.3.9/fs/namei.c    2018-01-09 17:21:19.000000000 +0000
3909 @@ -34,10 +34,20 @@
3910  #include <linux/device_cgroup.h>
3911  #include <linux/fs_struct.h>
3912  #include <linux/posix_acl.h>
3913 +#include <linux/proc_fs.h>
3914 +#include <linux/magic.h>
3915 +#include <linux/vserver/inode.h>
3916 +#include <linux/vs_base.h>
3917 +#include <linux/vs_tag.h>
3918 +#include <linux/vs_cowbl.h>
3919 +#include <linux/vs_device.h>
3920 +#include <linux/vs_context.h>
3921 +#include <linux/pid_namespace.h>
3922  #include <linux/hash.h>
3923  #include <asm/uaccess.h>
3924  
3925  #include "internal.h"
3926 +#include "proc/internal.h"
3927  #include "mount.h"
3928  
3929  /* [Feb-1997 T. Schoebel-Theuer]
3930 @@ -283,6 +293,93 @@ static int check_acl(struct inode *inode
3931         return -EAGAIN;
3932  }
3933  
3934 +static inline int dx_barrier(const struct inode *inode)
3935 +{
3936 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
3937 +               vxwprintk_task(1, "did hit the barrier.");
3938 +               return 1;
3939 +       }
3940 +       return 0;
3941 +}
3942 +
3943 +static int __dx_permission(const struct inode *inode, int mask)
3944 +{
3945 +       if (dx_barrier(inode))
3946 +               return -EACCES;
3947 +
3948 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
3949 +               /* devpts is xid tagged */
3950 +               if (S_ISDIR(inode->i_mode) ||
3951 +                   vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
3952 +                       return 0;
3953 +
3954 +               /* just pretend we didn't find anything */
3955 +               return -ENOENT;
3956 +       }
3957 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
3958 +               struct proc_dir_entry *de = PDE(inode);
3959 +
3960 +               if (de && !vx_hide_check(0, de->vx_flags)) {
3961 +                       vxdprintk(VXD_CBIT(misc, 9),
3962 +                               VS_Q("%*s") " hidden by _dx_permission",
3963 +                               de->namelen, de->name);
3964 +                       goto out;
3965 +               }
3966 +
3967 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
3968 +                       struct pid *pid;
3969 +                       struct task_struct *tsk;
3970 +
3971 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
3972 +                           vx_flags(VXF_STATE_SETUP, 0))
3973 +                               return 0;
3974 +
3975 +                       pid = PROC_I(inode)->pid;
3976 +                       if (!pid)
3977 +                               goto out;
3978 +
3979 +                       rcu_read_lock();
3980 +                       tsk = pid_task(pid, PIDTYPE_PID);
3981 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
3982 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
3983 +                       if (tsk &&
3984 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
3985 +                               rcu_read_unlock();
3986 +                               return 0;
3987 +                       }
3988 +                       rcu_read_unlock();
3989 +               }
3990 +               else {
3991 +                       /* FIXME: Should we block some entries here? */
3992 +                       return 0;
3993 +               }
3994 +       }
3995 +       else {
3996 +               if (dx_notagcheck(inode->i_sb) ||
3997 +                   dx_check((vxid_t)i_tag_read(inode),
3998 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
3999 +                       return 0;
4000 +       }
4001 +
4002 +out:
4003 +       return -EACCES;
4004 +}
4005 +
4006 +int dx_permission(const struct inode *inode, int mask)
4007 +{
4008 +       int ret = __dx_permission(inode, mask);
4009 +       if (unlikely(ret)) {
4010 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4011 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4012 +#endif
4013 +                   vxwprintk_task(1,
4014 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4015 +                       mask, inode->i_sb->s_id, inode,
4016 +                       i_tag_read(inode), inode->i_ino);
4017 +       }
4018 +       return ret;
4019 +}
4020 +
4021  /*
4022   * This does the basic permission checking
4023   */
4024 @@ -407,10 +504,14 @@ int __inode_permission(struct inode *ino
4025                 /*
4026                  * Nobody gets write access to an immutable file.
4027                  */
4028 -               if (IS_IMMUTABLE(inode))
4029 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4030                         return -EACCES;
4031         }
4032  
4033 +       retval = dx_permission(inode, mask);
4034 +       if (retval)
4035 +               return retval;
4036 +
4037         retval = do_inode_permission(inode, mask);
4038         if (retval)
4039                 return retval;
4040 @@ -1583,6 +1684,9 @@ static int lookup_fast(struct nameidata
4041                  */
4042                 if (negative)
4043                         return -ENOENT;
4044 +
4045 +               /* FIXME: check dx permission */
4046 +
4047                 path->mnt = mnt;
4048                 path->dentry = dentry;
4049                 if (likely(__follow_mount_rcu(nd, path, inode, seqp)))
4050 @@ -1613,6 +1717,8 @@ unlazy:
4051                 dput(dentry);
4052                 return -ENOENT;
4053         }
4054 +
4055 +       /* FIXME: check dx permission */
4056         path->mnt = mnt;
4057         path->dentry = dentry;
4058         err = follow_managed(path, nd);
4059 @@ -2571,7 +2677,7 @@ static int may_delete(struct inode *dir,
4060                 return -EPERM;
4061  
4062         if (check_sticky(dir, inode) || IS_APPEND(inode) ||
4063 -           IS_IMMUTABLE(inode) || IS_SWAPFILE(inode))
4064 +               IS_IXORUNLINK(inode) || IS_SWAPFILE(inode))
4065                 return -EPERM;
4066         if (isdir) {
4067                 if (!d_is_dir(victim))
4068 @@ -2653,19 +2759,25 @@ int vfs_create(struct inode *dir, struct
4069                 bool want_excl)
4070  {
4071         int error = may_create(dir, dentry);
4072 -       if (error)
4073 +       if (error) {
4074 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4075                 return error;
4076 +       }
4077  
4078         if (!dir->i_op->create)
4079                 return -EACCES; /* shouldn't it be ENOSYS? */
4080         mode &= S_IALLUGO;
4081         mode |= S_IFREG;
4082         error = security_inode_create(dir, dentry, mode);
4083 -       if (error)
4084 +       if (error) {
4085 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4086                 return error;
4087 +       }
4088         error = dir->i_op->create(dir, dentry, mode, want_excl);
4089         if (!error)
4090                 fsnotify_create(dir, dentry);
4091 +       else
4092 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4093         return error;
4094  }
4095  EXPORT_SYMBOL(vfs_create);
4096 @@ -2701,6 +2813,15 @@ static int may_open(struct path *path, i
4097                 break;
4098         }
4099  
4100 +#ifdef CONFIG_VSERVER_COWBL
4101 +       if (IS_COW(inode) &&
4102 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4103 +               if (IS_COW_LINK(inode))
4104 +                       return -EMLINK;
4105 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4106 +               mark_inode_dirty(inode);
4107 +       }
4108 +#endif
4109         error = inode_permission(inode, acc_mode);
4110         if (error)
4111                 return error;
4112 @@ -3178,6 +3299,16 @@ finish_open:
4113         }
4114  finish_open_created:
4115         error = may_open(&nd->path, acc_mode, open_flag);
4116 +#ifdef CONFIG_VSERVER_COWBL
4117 +       if (error == -EMLINK) {
4118 +               struct dentry *dentry;
4119 +               dentry = cow_break_link(name->name);
4120 +               if (IS_ERR(dentry))
4121 +                       error = PTR_ERR(dentry);
4122 +               else
4123 +                       dput(dentry);
4124 +       }
4125 +#endif
4126         if (error)
4127                 goto out;
4128  
4129 @@ -3302,6 +3433,9 @@ static struct file *path_openat(struct n
4130         int opened = 0;
4131         int error;
4132  
4133 +#ifdef CONFIG_VSERVER_COWBL
4134 +restart:
4135 +#endif
4136         file = get_empty_filp();
4137         if (IS_ERR(file))
4138                 return file;
4139 @@ -3448,6 +3582,11 @@ static struct dentry *filename_create(in
4140                 goto fail;
4141         }
4142         putname(name);
4143 +       vxdprintk(VXD_CBIT(misc, 3), "filename_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4144 +               path->dentry, path->dentry->d_name.len,
4145 +               path->dentry->d_name.name, dentry,
4146 +               dentry->d_name.len, dentry->d_name.name,
4147 +               path->dentry->d_inode);
4148         return dentry;
4149  fail:
4150         dput(dentry);
4151 @@ -3564,6 +3703,13 @@ retry:
4152                         error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
4153                         break;
4154         }
4155 +
4156 +#ifdef CONFIG_VSERVER_COWBL
4157 +       if (error == -EMLINK) {
4158 +               path_cleanup(nd);
4159 +               goto restart;
4160 +       }
4161 +#endif
4162  out:
4163         done_path_create(&path, dentry);
4164         if (retry_estale(error, lookup_flags)) {
4165 @@ -4010,7 +4156,7 @@ int vfs_link(struct dentry *old_dentry,
4166         /*
4167          * A link to an append-only or immutable file cannot be created.
4168          */
4169 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4170 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4171                 return -EPERM;
4172         if (!dir->i_op->link)
4173                 return -EPERM;
4174 @@ -4519,6 +4665,295 @@ int generic_readlink(struct dentry *dent
4175  }
4176  EXPORT_SYMBOL(generic_readlink);
4177  
4178 +
4179 +#ifdef CONFIG_VSERVER_COWBL
4180 +
4181 +static inline
4182 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4183 +{
4184 +       loff_t ppos = 0;
4185 +       loff_t opos = 0;
4186 +
4187 +       return do_splice_direct(in, &ppos, out, &opos, len, 0);
4188 +}
4189 +
4190 +struct dentry *cow_break_link(const char *pathname)
4191 +{
4192 +       int ret, mode, pathlen, redo = 0, drop = 1;
4193 +       struct nameidata old_nd, dir_nd;
4194 +       struct path dir_path, *old_path, *new_path;
4195 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4196 +       struct file *old_file;
4197 +       struct file *new_file;
4198 +       char *to, *path, pad='\251';
4199 +       loff_t size;
4200 +       struct filename *filename = getname_kernel(pathname);
4201 +       struct filename *to_filename;
4202 +
4203 +       vxdprintk(VXD_CBIT(misc, 1),
4204 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4205 +
4206 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4207 +       ret = -ENOMEM;
4208 +       if (!path || IS_ERR(filename))
4209 +               goto out;
4210 +
4211 +       /* old_nd.path will have refs to dentry and mnt */
4212 +       ret = filename_lookup(AT_FDCWD, filename, LOOKUP_FOLLOW, &old_nd);
4213 +       vxdprintk(VXD_CBIT(misc, 2),
4214 +               "do_path_lookup(old): %d", ret);
4215 +       if (ret < 0)
4216 +               goto out_free_path;
4217 +
4218 +       /* dentry/mnt refs handed over to old_path */
4219 +       old_path = &old_nd.path;
4220 +       /* no explicit reference for old_dentry here */
4221 +       old_dentry = old_path->dentry;
4222 +
4223 +       mode = old_dentry->d_inode->i_mode;
4224 +       to = d_path(old_path, path, PATH_MAX-2);
4225 +       pathlen = strlen(to);
4226 +       vxdprintk(VXD_CBIT(misc, 2),
4227 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4228 +               old_dentry,
4229 +               old_dentry->d_name.len, old_dentry->d_name.name,
4230 +               old_dentry->d_name.len);
4231 +
4232 +       to[pathlen + 1] = 0;
4233 +retry:
4234 +       new_dentry = NULL;
4235 +       to[pathlen] = pad--;
4236 +       ret = -ELOOP;
4237 +       if (pad <= '\240')
4238 +               goto out_rel_old;
4239 +
4240 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4241 +
4242 +       /* dir_nd.path will have refs to dentry and mnt */
4243 +       to_filename = getname_kernel(to);
4244 +       ret = filename_lookup(AT_FDCWD, to_filename,
4245 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4246 +       putname(to_filename);
4247 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4248 +       if (ret < 0)
4249 +               goto retry;
4250 +
4251 +       /* this puppy downs the dir inode mutex if successful.
4252 +          dir_path will hold refs to dentry and mnt and
4253 +          we'll have write access to the mnt */
4254 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4255 +       if (!new_dentry || IS_ERR(new_dentry)) {
4256 +               path_put(&dir_nd.path);
4257 +               vxdprintk(VXD_CBIT(misc, 2),
4258 +                       "kern_path_create(new) failed with %ld",
4259 +                       PTR_ERR(new_dentry));
4260 +               goto retry;
4261 +       }
4262 +       vxdprintk(VXD_CBIT(misc, 2),
4263 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4264 +               new_dentry,
4265 +               new_dentry->d_name.len, new_dentry->d_name.name,
4266 +               new_dentry->d_name.len);
4267 +
4268 +       /* take a reference on new_dentry */
4269 +       dget(new_dentry);
4270 +
4271 +       /* dentry/mnt refs handed over to new_path */
4272 +       new_path = &dir_path;
4273 +
4274 +       /* dentry for old/new dir */
4275 +       dir = dir_nd.path.dentry;
4276 +
4277 +       /* give up reference on dir */
4278 +       dput(new_path->dentry);
4279 +
4280 +       /* new_dentry already has a reference */
4281 +       new_path->dentry = new_dentry;
4282 +
4283 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4284 +       vxdprintk(VXD_CBIT(misc, 2),
4285 +               "vfs_create(new): %d", ret);
4286 +       if (ret == -EEXIST) {
4287 +               path_put(&dir_nd.path);
4288 +               mutex_unlock(&dir->d_inode->i_mutex);
4289 +               mnt_drop_write(new_path->mnt);
4290 +               path_put(new_path);
4291 +               new_dentry = NULL;
4292 +               goto retry;
4293 +       }
4294 +       else if (ret < 0)
4295 +               goto out_unlock_new;
4296 +
4297 +       /* the old file went away */
4298 +       ret = -ENOENT;
4299 +       if ((redo = d_unhashed(old_dentry)))
4300 +               goto out_unlock_new;
4301 +
4302 +       /* doesn't change refs for old_path */
4303 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4304 +       vxdprintk(VXD_CBIT(misc, 2),
4305 +               "dentry_open(old): %p", old_file);
4306 +       if (IS_ERR(old_file)) {
4307 +               ret = PTR_ERR(old_file);
4308 +               goto out_unlock_new;
4309 +       }
4310 +
4311 +       /* doesn't change refs for new_path */
4312 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4313 +       vxdprintk(VXD_CBIT(misc, 2),
4314 +               "dentry_open(new): %p", new_file);
4315 +       if (IS_ERR(new_file)) {
4316 +               ret = PTR_ERR(new_file);
4317 +               goto out_fput_old;
4318 +       }
4319 +
4320 +       /* unlock the inode mutex from kern_path_create() */
4321 +       mutex_unlock(&dir->d_inode->i_mutex);
4322 +
4323 +       /* drop write access to mnt */
4324 +       mnt_drop_write(new_path->mnt);
4325 +
4326 +       drop = 0;
4327 +
4328 +       size = i_size_read(old_file->f_path.dentry->d_inode);
4329 +       ret = do_cow_splice(old_file, new_file, size);
4330 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4331 +       if (ret < 0) {
4332 +               goto out_fput_both;
4333 +       } else if (ret < size) {
4334 +               ret = -ENOSPC;
4335 +               goto out_fput_both;
4336 +       } else {
4337 +               struct inode *old_inode = old_dentry->d_inode;
4338 +               struct inode *new_inode = new_dentry->d_inode;
4339 +               struct iattr attr = {
4340 +                       .ia_uid = old_inode->i_uid,
4341 +                       .ia_gid = old_inode->i_gid,
4342 +                       .ia_valid = ATTR_UID | ATTR_GID
4343 +                       };
4344 +
4345 +               setattr_copy(new_inode, &attr);
4346 +               mark_inode_dirty(new_inode);
4347 +       }
4348 +
4349 +       /* lock rename mutex */
4350 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4351 +
4352 +       /* drop out late */
4353 +       ret = -ENOENT;
4354 +       if ((redo = d_unhashed(old_dentry)))
4355 +               goto out_unlock;
4356 +
4357 +       vxdprintk(VXD_CBIT(misc, 2),
4358 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4359 +               new_dentry->d_name.len, new_dentry->d_name.name,
4360 +               new_dentry->d_name.len,
4361 +               old_dentry->d_name.len, old_dentry->d_name.name,
4362 +               old_dentry->d_name.len);
4363 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4364 +               old_dentry->d_parent->d_inode, old_dentry, NULL, 0);
4365 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4366 +
4367 +out_unlock:
4368 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4369 +
4370 +out_fput_both:
4371 +       vxdprintk(VXD_CBIT(misc, 3),
4372 +               "fput(new_file=%p[#%ld])", new_file,
4373 +               atomic_long_read(&new_file->f_count));
4374 +       fput(new_file);
4375 +
4376 +out_fput_old:
4377 +       vxdprintk(VXD_CBIT(misc, 3),
4378 +               "fput(old_file=%p[#%ld])", old_file,
4379 +               atomic_long_read(&old_file->f_count));
4380 +       fput(old_file);
4381 +
4382 +out_unlock_new:
4383 +       /* drop references from dir_nd.path */
4384 +       path_put(&dir_nd.path);
4385 +
4386 +       if (drop) {
4387 +               /* unlock the inode mutex from kern_path_create() */
4388 +               mutex_unlock(&dir->d_inode->i_mutex);
4389 +
4390 +               /* drop write access to mnt */
4391 +               mnt_drop_write(new_path->mnt);
4392 +       }
4393 +
4394 +       if (!ret)
4395 +               goto out_redo;
4396 +
4397 +       /* error path cleanup */
4398 +       vfs_unlink(dir->d_inode, new_dentry, NULL);
4399 +
4400 +out_redo:
4401 +       if (!redo)
4402 +               goto out_rel_both;
4403 +
4404 +       /* lookup dentry once again
4405 +          old_nd.path will be freed as old_path in out_rel_old */
4406 +       ret = filename_lookup(AT_FDCWD, filename, LOOKUP_FOLLOW, &old_nd);
4407 +       if (ret)
4408 +               goto out_rel_both;
4409 +
4410 +       /* drop reference on new_dentry */
4411 +       dput(new_dentry);
4412 +       new_dentry = old_path->dentry;
4413 +       dget(new_dentry);
4414 +       vxdprintk(VXD_CBIT(misc, 2),
4415 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4416 +               new_dentry,
4417 +               new_dentry->d_name.len, new_dentry->d_name.name,
4418 +               new_dentry->d_name.len);
4419 +
4420 +out_rel_both:
4421 +       if (new_path)
4422 +               path_put(new_path);
4423 +out_rel_old:
4424 +       path_put(old_path);
4425 +out_free_path:
4426 +       kfree(path);
4427 +out:
4428 +       if (ret) {
4429 +               dput(new_dentry);
4430 +               new_dentry = ERR_PTR(ret);
4431 +       }
4432 +       if (!IS_ERR(filename))
4433 +               putname(filename);
4434 +       vxdprintk(VXD_CBIT(misc, 3),
4435 +               "cow_break_link returning with %p", new_dentry);
4436 +       return new_dentry;
4437 +}
4438 +
4439 +#endif
4440 +
4441 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4442 +{
4443 +       struct path path;
4444 +       struct vfsmount *vmnt;
4445 +       char *pstr, *root;
4446 +       int length = 0;
4447 +
4448 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4449 +       if (!pstr)
4450 +               return 0;
4451 +
4452 +       vmnt = &ns->root->mnt;
4453 +       path.mnt = vmnt;
4454 +       path.dentry = vmnt->mnt_root;
4455 +       root = d_path(&path, pstr, PATH_MAX - 2);
4456 +       length = sprintf(buffer + length,
4457 +               "Namespace:\t%p [#%u]\n"
4458 +               "RootPath:\t%s\n",
4459 +               ns, atomic_read(&ns->count),
4460 +               root);
4461 +       kfree(pstr);
4462 +       return length;
4463 +}
4464 +
4465 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4466 +
4467  /* get the link contents into pagecache */
4468  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4469  {
4470 diff -NurpP --minimal linux-4.4.110/fs/namespace.c linux-4.4.110-vs2.3.9/fs/namespace.c
4471 --- linux-4.4.110/fs/namespace.c        2018-01-09 16:35:06.000000000 +0000
4472 +++ linux-4.4.110-vs2.3.9/fs/namespace.c        2018-01-09 16:36:32.000000000 +0000
4473 @@ -24,6 +24,11 @@
4474  #include <linux/magic.h>
4475  #include <linux/bootmem.h>
4476  #include <linux/task_work.h>
4477 +#include <linux/vs_base.h>
4478 +#include <linux/vs_context.h>
4479 +#include <linux/vs_tag.h>
4480 +#include <linux/vserver/space.h>
4481 +#include <linux/vserver/global.h>
4482  #include "pnode.h"
4483  #include "internal.h"
4484  
4485 @@ -971,6 +976,10 @@ vfs_kern_mount(struct file_system_type *
4486         if (!type)
4487                 return ERR_PTR(-ENODEV);
4488  
4489 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4490 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4491 +               return ERR_PTR(-EPERM);
4492 +
4493         mnt = alloc_vfsmnt(name);
4494         if (!mnt)
4495                 return ERR_PTR(-ENOMEM);
4496 @@ -1046,6 +1055,7 @@ static struct mount *clone_mnt(struct mo
4497         mnt->mnt.mnt_root = dget(root);
4498         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4499         mnt->mnt_parent = mnt;
4500 +       mnt->mnt_tag = old->mnt_tag;
4501         lock_mount_hash();
4502         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4503         unlock_mount_hash();
4504 @@ -1620,7 +1630,8 @@ out_unlock:
4505   */
4506  static inline bool may_mount(void)
4507  {
4508 -       return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4509 +       return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4510 +               CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4511  }
4512  
4513  /*
4514 @@ -2121,6 +2132,7 @@ static int do_change_type(struct path *p
4515                 if (err)
4516                         goto out_unlock;
4517         }
4518 +       // mnt->mnt_flags = mnt_flags;
4519  
4520         lock_mount_hash();
4521         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4522 @@ -2149,12 +2161,14 @@ static bool has_locked_children(struct m
4523   * do loopback mount.
4524   */
4525  static int do_loopback(struct path *path, const char *old_name,
4526 -                               int recurse)
4527 +       vtag_t tag, unsigned long flags, int mnt_flags)
4528  {
4529         struct path old_path;
4530         struct mount *mnt = NULL, *old, *parent;
4531         struct mountpoint *mp;
4532 +       int recurse = flags & MS_REC;
4533         int err;
4534 +
4535         if (!old_name || !*old_name)
4536                 return -EINVAL;
4537         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4538 @@ -2234,7 +2248,7 @@ static int change_mount_flags(struct vfs
4539   * on it - tough luck.
4540   */
4541  static int do_remount(struct path *path, int flags, int mnt_flags,
4542 -                     void *data)
4543 +       void *data, vxid_t xid)
4544  {
4545         int err;
4546         struct super_block *sb = path->mnt->mnt_sb;
4547 @@ -2742,6 +2756,7 @@ long do_mount(const char *dev_name, cons
4548         struct path path;
4549         int retval = 0;
4550         int mnt_flags = 0;
4551 +       vtag_t tag = 0;
4552  
4553         /* Discard magic */
4554         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4555 @@ -2767,6 +2782,12 @@ long do_mount(const char *dev_name, cons
4556         if (!(flags & MS_NOATIME))
4557                 mnt_flags |= MNT_RELATIME;
4558  
4559 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4560 +               /* FIXME: bind and re-mounts get the tag flag? */
4561 +               if (flags & (MS_BIND|MS_REMOUNT))
4562 +                       flags |= MS_TAGID;
4563 +       }
4564 +
4565         /* Separate the per-mountpoint flags */
4566         if (flags & MS_NOSUID)
4567                 mnt_flags |= MNT_NOSUID;
4568 @@ -2791,15 +2812,17 @@ long do_mount(const char *dev_name, cons
4569                 mnt_flags |= path.mnt->mnt_flags & MNT_ATIME_MASK;
4570         }
4571  
4572 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4573 +               mnt_flags |= MNT_NODEV;
4574         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4575                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4576                    MS_STRICTATIME);
4577  
4578         if (flags & MS_REMOUNT)
4579                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4580 -                                   data_page);
4581 +                                   data_page, tag);
4582         else if (flags & MS_BIND)
4583 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
4584 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4585         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4586                 retval = do_change_type(&path, flags);
4587         else if (flags & MS_MOVE)
4588 @@ -2919,6 +2942,7 @@ struct mnt_namespace *copy_mnt_ns(unsign
4589                         p = next_mnt(p, old);
4590         }
4591         namespace_unlock();
4592 +       atomic_inc(&vs_global_mnt_ns);
4593  
4594         if (rootmnt)
4595                 mntput(rootmnt);
4596 @@ -3094,9 +3118,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4597         new_mnt = real_mount(new.mnt);
4598         root_mnt = real_mount(root.mnt);
4599         old_mnt = real_mount(old.mnt);
4600 -       if (IS_MNT_SHARED(old_mnt) ||
4601 +       if ((IS_MNT_SHARED(old_mnt) ||
4602                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4603 -               IS_MNT_SHARED(root_mnt->mnt_parent))
4604 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4605 +               !vx_flags(VXF_STATE_SETUP, 0))
4606                 goto out4;
4607         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4608                 goto out4;
4609 @@ -3234,6 +3259,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4610         if (!atomic_dec_and_test(&ns->count))
4611                 return;
4612         drop_collected_mounts(&ns->root->mnt);
4613 +       atomic_dec(&vs_global_mnt_ns);
4614         free_mnt_ns(ns);
4615  }
4616  
4617 diff -NurpP --minimal linux-4.4.110/fs/nfs/client.c linux-4.4.110-vs2.3.9/fs/nfs/client.c
4618 --- linux-4.4.110/fs/nfs/client.c       2016-07-05 04:15:08.000000000 +0000
4619 +++ linux-4.4.110-vs2.3.9/fs/nfs/client.c       2018-01-09 16:36:32.000000000 +0000
4620 @@ -583,6 +583,9 @@ int nfs_init_server_rpcclient(struct nfs
4621         if (server->flags & NFS_MOUNT_SOFT)
4622                 server->client->cl_softrtry = 1;
4623  
4624 +       server->client->cl_tag = 0;
4625 +       if (server->flags & NFS_MOUNT_TAGGED)
4626 +               server->client->cl_tag = 1;
4627         return 0;
4628  }
4629  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4630 @@ -760,6 +763,10 @@ static void nfs_server_set_fsinfo(struct
4631                 server->acdirmin = server->acdirmax = 0;
4632         }
4633  
4634 +       /* FIXME: needs fsinfo
4635 +       if (server->flags & NFS_MOUNT_TAGGED)
4636 +               sb->s_flags |= MS_TAGGED;       */
4637 +
4638         server->maxfilesize = fsinfo->maxfilesize;
4639  
4640         server->time_delta = fsinfo->time_delta;
4641 diff -NurpP --minimal linux-4.4.110/fs/nfs/dir.c linux-4.4.110-vs2.3.9/fs/nfs/dir.c
4642 --- linux-4.4.110/fs/nfs/dir.c  2018-01-09 16:35:07.000000000 +0000
4643 +++ linux-4.4.110-vs2.3.9/fs/nfs/dir.c  2018-01-09 16:36:32.000000000 +0000
4644 @@ -37,6 +37,7 @@
4645  #include <linux/sched.h>
4646  #include <linux/kmemleak.h>
4647  #include <linux/xattr.h>
4648 +#include <linux/vs_tag.h>
4649  
4650  #include "delegation.h"
4651  #include "iostat.h"
4652 @@ -1396,6 +1397,7 @@ struct dentry *nfs_lookup(struct inode *
4653         /* Success: notify readdir to use READDIRPLUS */
4654         nfs_advise_use_readdirplus(dir);
4655  
4656 +       dx_propagate_tag(nd, inode);
4657  no_entry:
4658         res = d_splice_alias(inode, dentry);
4659         if (res != NULL) {
4660 diff -NurpP --minimal linux-4.4.110/fs/nfs/inode.c linux-4.4.110-vs2.3.9/fs/nfs/inode.c
4661 --- linux-4.4.110/fs/nfs/inode.c        2018-01-09 16:35:07.000000000 +0000
4662 +++ linux-4.4.110-vs2.3.9/fs/nfs/inode.c        2018-01-09 16:36:32.000000000 +0000
4663 @@ -38,6 +38,7 @@
4664  #include <linux/slab.h>
4665  #include <linux/compat.h>
4666  #include <linux/freezer.h>
4667 +#include <linux/vs_tag.h>
4668  
4669  #include <asm/uaccess.h>
4670  
4671 @@ -376,6 +377,8 @@ nfs_fhget(struct super_block *sb, struct
4672         if (inode->i_state & I_NEW) {
4673                 struct nfs_inode *nfsi = NFS_I(inode);
4674                 unsigned long now = jiffies;
4675 +               kuid_t kuid;
4676 +               kgid_t kgid;
4677  
4678                 /* We set i_ino for the few things that still rely on it,
4679                  * such as stat(2) */
4680 @@ -419,8 +422,8 @@ nfs_fhget(struct super_block *sb, struct
4681                 inode->i_version = 0;
4682                 inode->i_size = 0;
4683                 clear_nlink(inode);
4684 -               inode->i_uid = make_kuid(&init_user_ns, -2);
4685 -               inode->i_gid = make_kgid(&init_user_ns, -2);
4686 +               kuid = make_kuid(&init_user_ns, -2);
4687 +               kgid = make_kgid(&init_user_ns, -2);
4688                 inode->i_blocks = 0;
4689                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
4690                 nfsi->write_io = 0;
4691 @@ -455,11 +458,11 @@ nfs_fhget(struct super_block *sb, struct
4692                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
4693                         nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
4694                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
4695 -                       inode->i_uid = fattr->uid;
4696 +                       kuid = fattr->uid;
4697                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
4698                         nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
4699                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
4700 -                       inode->i_gid = fattr->gid;
4701 +                       kgid = fattr->gid;
4702                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
4703                         nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
4704                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
4705 @@ -470,6 +473,10 @@ nfs_fhget(struct super_block *sb, struct
4706                          */
4707                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
4708                 }
4709 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
4710 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
4711 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
4712 +                               /* maybe fattr->xid someday */
4713  
4714                 nfs_setsecurity(inode, fattr, label);
4715  
4716 @@ -611,6 +618,8 @@ void nfs_setattr_update_inode(struct ino
4717                         inode->i_uid = attr->ia_uid;
4718                 if ((attr->ia_valid & ATTR_GID) != 0)
4719                         inode->i_gid = attr->ia_gid;
4720 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4721 +                       inode->i_tag = attr->ia_tag;
4722                 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ACCESS
4723                                 | NFS_INO_INVALID_ACL);
4724         }
4725 @@ -1235,7 +1244,9 @@ static int nfs_check_inode_attributes(st
4726         struct nfs_inode *nfsi = NFS_I(inode);
4727         loff_t cur_size, new_isize;
4728         unsigned long invalid = 0;
4729 -
4730 +       kuid_t kuid;
4731 +       kgid_t kgid;
4732 +       ktag_t ktag;
4733  
4734         if (nfs_have_delegated_attributes(inode))
4735                 return 0;
4736 @@ -1262,13 +1273,18 @@ static int nfs_check_inode_attributes(st
4737         if (nfsi->nrequests != 0)
4738                 invalid &= ~NFS_INO_REVAL_PAGECACHE;
4739  
4740 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
4741 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
4742 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
4743 +
4744         /* Have any file permissions changed? */
4745         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
4746                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
4747 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
4748 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
4749                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
4750 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
4751 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
4752                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
4753 +               /* maybe check for tag too? */
4754  
4755         /* Has the link count changed? */
4756         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
4757 @@ -1642,6 +1658,9 @@ static int nfs_update_inode(struct inode
4758         unsigned long now = jiffies;
4759         unsigned long save_cache_validity;
4760         bool cache_revalidated = true;
4761 +       kuid_t kuid;
4762 +       kgid_t kgid;
4763 +       ktag_t ktag;
4764  
4765         dfprintk(VFS, "NFS: %s(%s/%lu fh_crc=0x%08x ct=%d info=0x%x)\n",
4766                         __func__, inode->i_sb->s_id, inode->i_ino,
4767 @@ -1752,6 +1771,9 @@ static int nfs_update_inode(struct inode
4768                 cache_revalidated = false;
4769         }
4770  
4771 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4772 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4773 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
4774  
4775         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
4776                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
4777 @@ -1806,6 +1828,10 @@ static int nfs_update_inode(struct inode
4778                 cache_revalidated = false;
4779         }
4780  
4781 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
4782 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
4783 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
4784 +
4785         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
4786                 if (inode->i_nlink != fattr->nlink) {
4787                         invalid |= NFS_INO_INVALID_ATTR;
4788 diff -NurpP --minimal linux-4.4.110/fs/nfs/nfs3xdr.c linux-4.4.110-vs2.3.9/fs/nfs/nfs3xdr.c
4789 --- linux-4.4.110/fs/nfs/nfs3xdr.c      2016-07-05 04:12:33.000000000 +0000
4790 +++ linux-4.4.110-vs2.3.9/fs/nfs/nfs3xdr.c      2018-01-09 17:17:07.000000000 +0000
4791 @@ -20,6 +20,7 @@
4792  #include <linux/nfs3.h>
4793  #include <linux/nfs_fs.h>
4794  #include <linux/nfsacl.h>
4795 +#include <linux/vs_tag.h>
4796  #include "internal.h"
4797  
4798  #define NFSDBG_FACILITY                NFSDBG_XDR
4799 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
4800   *             set_mtime       mtime;
4801   *     };
4802   */
4803 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
4804 +static void encode_sattr3(struct xdr_stream *xdr,
4805 +       const struct iattr *attr, int tag)
4806  {
4807         u32 nbytes;
4808         __be32 *p;
4809 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
4810         } else
4811                 *p++ = xdr_zero;
4812  
4813 -       if (attr->ia_valid & ATTR_UID) {
4814 +       if (attr->ia_valid & ATTR_UID ||
4815 +               (tag && (attr->ia_valid & ATTR_TAG))) {
4816                 *p++ = xdr_one;
4817 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
4818 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
4819 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
4820         } else
4821                 *p++ = xdr_zero;
4822  
4823 -       if (attr->ia_valid & ATTR_GID) {
4824 +       if (attr->ia_valid & ATTR_GID ||
4825 +               (tag && (attr->ia_valid & ATTR_TAG))) {
4826                 *p++ = xdr_one;
4827 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
4828 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
4829 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
4830         } else
4831                 *p++ = xdr_zero;
4832  
4833 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
4834                                       const struct nfs3_sattrargs *args)
4835  {
4836         encode_nfs_fh3(xdr, args->fh);
4837 -       encode_sattr3(xdr, args->sattr);
4838 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
4839         encode_sattrguard3(xdr, args);
4840  }
4841  
4842 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
4843   *     };
4844   */
4845  static void encode_createhow3(struct xdr_stream *xdr,
4846 -                             const struct nfs3_createargs *args)
4847 +       const struct nfs3_createargs *args, int tag)
4848  {
4849         encode_uint32(xdr, args->createmode);
4850         switch (args->createmode) {
4851         case NFS3_CREATE_UNCHECKED:
4852         case NFS3_CREATE_GUARDED:
4853 -               encode_sattr3(xdr, args->sattr);
4854 +               encode_sattr3(xdr, args->sattr, tag);
4855                 break;
4856         case NFS3_CREATE_EXCLUSIVE:
4857                 encode_createverf3(xdr, args->verifier);
4858 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
4859                                      const struct nfs3_createargs *args)
4860  {
4861         encode_diropargs3(xdr, args->fh, args->name, args->len);
4862 -       encode_createhow3(xdr, args);
4863 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
4864  }
4865  
4866  /*
4867 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
4868                                     const struct nfs3_mkdirargs *args)
4869  {
4870         encode_diropargs3(xdr, args->fh, args->name, args->len);
4871 -       encode_sattr3(xdr, args->sattr);
4872 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
4873  }
4874  
4875  /*
4876 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
4877   *     };
4878   */
4879  static void encode_symlinkdata3(struct xdr_stream *xdr,
4880 -                               const struct nfs3_symlinkargs *args)
4881 +       const struct nfs3_symlinkargs *args, int tag)
4882  {
4883 -       encode_sattr3(xdr, args->sattr);
4884 +       encode_sattr3(xdr, args->sattr, tag);
4885         encode_nfspath3(xdr, args->pages, args->pathlen);
4886  }
4887  
4888 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
4889                                       const struct nfs3_symlinkargs *args)
4890  {
4891         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
4892 -       encode_symlinkdata3(xdr, args);
4893 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
4894         xdr->buf->flags |= XDRBUF_WRITE;
4895  }
4896  
4897 @@ -1131,24 +1137,24 @@ static void nfs3_xdr_enc_symlink3args(st
4898   *     };
4899   */
4900  static void encode_devicedata3(struct xdr_stream *xdr,
4901 -                              const struct nfs3_mknodargs *args)
4902 +       const struct nfs3_mknodargs *args, int tag)
4903  {
4904 -       encode_sattr3(xdr, args->sattr);
4905 +       encode_sattr3(xdr, args->sattr, tag);
4906         encode_specdata3(xdr, args->rdev);
4907  }
4908  
4909  static void encode_mknoddata3(struct xdr_stream *xdr,
4910 -                             const struct nfs3_mknodargs *args)
4911 +       const struct nfs3_mknodargs *args, int tag)
4912  {
4913         encode_ftype3(xdr, args->type);
4914         switch (args->type) {
4915         case NF3CHR:
4916         case NF3BLK:
4917 -               encode_devicedata3(xdr, args);
4918 +               encode_devicedata3(xdr, args, tag);
4919                 break;
4920         case NF3SOCK:
4921         case NF3FIFO:
4922 -               encode_sattr3(xdr, args->sattr);
4923 +               encode_sattr3(xdr, args->sattr, tag);
4924                 break;
4925         case NF3REG:
4926         case NF3DIR:
4927 @@ -1163,7 +1169,7 @@ static void nfs3_xdr_enc_mknod3args(stru
4928                                     const struct nfs3_mknodargs *args)
4929  {
4930         encode_diropargs3(xdr, args->fh, args->name, args->len);
4931 -       encode_mknoddata3(xdr, args);
4932 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
4933  }
4934  
4935  /*
4936 diff -NurpP --minimal linux-4.4.110/fs/nfs/super.c linux-4.4.110-vs2.3.9/fs/nfs/super.c
4937 --- linux-4.4.110/fs/nfs/super.c        2018-01-09 16:35:07.000000000 +0000
4938 +++ linux-4.4.110-vs2.3.9/fs/nfs/super.c        2018-01-09 16:36:32.000000000 +0000
4939 @@ -54,6 +54,7 @@
4940  #include <linux/parser.h>
4941  #include <linux/nsproxy.h>
4942  #include <linux/rcupdate.h>
4943 +#include <linux/vs_tag.h>
4944  
4945  #include <asm/uaccess.h>
4946  
4947 @@ -102,6 +103,7 @@ enum {
4948         Opt_mountport,
4949         Opt_mountvers,
4950         Opt_minorversion,
4951 +       Opt_tagid,
4952  
4953         /* Mount options that take string arguments */
4954         Opt_nfsvers,
4955 @@ -114,6 +116,9 @@ enum {
4956         /* Special mount options */
4957         Opt_userspace, Opt_deprecated, Opt_sloppy,
4958  
4959 +       /* Linux-VServer tagging options */
4960 +       Opt_tag, Opt_notag,
4961 +
4962         Opt_err
4963  };
4964  
4965 @@ -183,6 +188,10 @@ static const match_table_t nfs_mount_opt
4966         { Opt_fscache_uniq, "fsc=%s" },
4967         { Opt_local_lock, "local_lock=%s" },
4968  
4969 +       { Opt_tag, "tag" },
4970 +       { Opt_notag, "notag" },
4971 +       { Opt_tagid, "tagid=%u" },
4972 +
4973         /* The following needs to be listed after all other options */
4974         { Opt_nfsvers, "v%s" },
4975  
4976 @@ -642,6 +651,7 @@ static void nfs_show_mount_options(struc
4977                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
4978                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
4979                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
4980 +               { NFS_MOUNT_TAGGED, ",tag", "" },
4981                 { 0, NULL, NULL }
4982         };
4983         const struct proc_nfs_info *nfs_infop;
4984 @@ -1324,6 +1334,14 @@ static int nfs_parse_mount_options(char
4985                 case Opt_nomigration:
4986                         mnt->options &= ~NFS_OPTION_MIGRATION;
4987                         break;
4988 +#ifndef CONFIG_TAGGING_NONE
4989 +               case Opt_tag:
4990 +                       mnt->flags |= NFS_MOUNT_TAGGED;
4991 +                       break;
4992 +               case Opt_notag:
4993 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
4994 +                       break;
4995 +#endif
4996  
4997                 /*
4998                  * options that take numeric values
4999 @@ -1410,6 +1428,12 @@ static int nfs_parse_mount_options(char
5000                                 goto out_invalid_value;
5001                         mnt->minorversion = option;
5002                         break;
5003 +#ifdef CONFIG_PROPAGATE
5004 +               case Opt_tagid:
5005 +                       /* use args[0] */
5006 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5007 +                       break;
5008 +#endif
5009  
5010                 /*
5011                  * options that take text values
5012 diff -NurpP --minimal linux-4.4.110/fs/nfsd/auth.c linux-4.4.110-vs2.3.9/fs/nfsd/auth.c
5013 --- linux-4.4.110/fs/nfsd/auth.c        2015-04-12 22:12:50.000000000 +0000
5014 +++ linux-4.4.110-vs2.3.9/fs/nfsd/auth.c        2018-01-09 16:36:32.000000000 +0000
5015 @@ -1,6 +1,7 @@
5016  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
5017  
5018  #include <linux/sched.h>
5019 +#include <linux/vs_tag.h>
5020  #include "nfsd.h"
5021  #include "auth.h"
5022  
5023 @@ -35,6 +36,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5024  
5025         new->fsuid = rqstp->rq_cred.cr_uid;
5026         new->fsgid = rqstp->rq_cred.cr_gid;
5027 +       /* FIXME: this desperately needs a tag :)
5028 +       new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5029 +                       */
5030  
5031         rqgi = rqstp->rq_cred.cr_group_info;
5032  
5033 diff -NurpP --minimal linux-4.4.110/fs/nfsd/nfs3xdr.c linux-4.4.110-vs2.3.9/fs/nfsd/nfs3xdr.c
5034 --- linux-4.4.110/fs/nfsd/nfs3xdr.c     2018-01-09 16:35:07.000000000 +0000
5035 +++ linux-4.4.110-vs2.3.9/fs/nfsd/nfs3xdr.c     2018-01-09 16:36:32.000000000 +0000
5036 @@ -8,6 +8,7 @@
5037  
5038  #include <linux/namei.h>
5039  #include <linux/sunrpc/svc_xprt.h>
5040 +#include <linux/vs_tag.h>
5041  #include "xdr3.h"
5042  #include "auth.h"
5043  #include "netns.h"
5044 @@ -98,6 +99,8 @@ static __be32 *
5045  decode_sattr3(__be32 *p, struct iattr *iap)
5046  {
5047         u32     tmp;
5048 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5049 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5050  
5051         iap->ia_valid = 0;
5052  
5053 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5054                 iap->ia_mode = ntohl(*p++);
5055         }
5056         if (*p++) {
5057 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5058 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5059                 if (uid_valid(iap->ia_uid))
5060                         iap->ia_valid |= ATTR_UID;
5061         }
5062         if (*p++) {
5063 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5064 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5065                 if (gid_valid(iap->ia_gid))
5066                         iap->ia_valid |= ATTR_GID;
5067         }
5068 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5069 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5070 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5071         if (*p++) {
5072                 u64     newsize;
5073  
5074 @@ -167,8 +173,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5075         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5076         *p++ = htonl((u32) (stat->mode & S_IALLUGO));
5077         *p++ = htonl((u32) stat->nlink);
5078 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5079 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5080 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5081 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5082 +               stat->uid, stat->tag)));
5083 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5084 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5085 +               stat->gid, stat->tag)));
5086         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5087                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5088         } else {
5089 diff -NurpP --minimal linux-4.4.110/fs/nfsd/nfs4xdr.c linux-4.4.110-vs2.3.9/fs/nfsd/nfs4xdr.c
5090 --- linux-4.4.110/fs/nfsd/nfs4xdr.c     2018-01-09 16:35:07.000000000 +0000
5091 +++ linux-4.4.110-vs2.3.9/fs/nfsd/nfs4xdr.c     2018-01-09 16:36:32.000000000 +0000
5092 @@ -40,6 +40,7 @@
5093  #include <linux/utsname.h>
5094  #include <linux/pagemap.h>
5095  #include <linux/sunrpc/svcauth_gss.h>
5096 +#include <linux/vs_tag.h>
5097  
5098  #include "idmap.h"
5099  #include "acl.h"
5100 @@ -2637,12 +2638,16 @@ out_acl:
5101                 *p++ = cpu_to_be32(stat.nlink);
5102         }
5103         if (bmval1 & FATTR4_WORD1_OWNER) {
5104 -               status = nfsd4_encode_user(xdr, rqstp, stat.uid);
5105 +               status = nfsd4_encode_user(xdr, rqstp,
5106 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5107 +                               stat.uid, stat.tag));
5108                 if (status)
5109                         goto out;
5110         }
5111         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5112 -               status = nfsd4_encode_group(xdr, rqstp, stat.gid);
5113 +               status = nfsd4_encode_group(xdr, rqstp,
5114 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5115 +                               stat.gid, stat.tag));
5116                 if (status)
5117                         goto out;
5118         }
5119 diff -NurpP --minimal linux-4.4.110/fs/nfsd/nfsxdr.c linux-4.4.110-vs2.3.9/fs/nfsd/nfsxdr.c
5120 --- linux-4.4.110/fs/nfsd/nfsxdr.c      2018-01-09 16:35:07.000000000 +0000
5121 +++ linux-4.4.110-vs2.3.9/fs/nfsd/nfsxdr.c      2018-01-09 16:36:32.000000000 +0000
5122 @@ -7,6 +7,7 @@
5123  #include "vfs.h"
5124  #include "xdr.h"
5125  #include "auth.h"
5126 +#include <linux/vs_tag.h>
5127  
5128  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5129  
5130 @@ -89,6 +90,8 @@ static __be32 *
5131  decode_sattr(__be32 *p, struct iattr *iap)
5132  {
5133         u32     tmp, tmp1;
5134 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5135 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5136  
5137         iap->ia_valid = 0;
5138  
5139 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5140                 iap->ia_mode = tmp;
5141         }
5142         if ((tmp = ntohl(*p++)) != (u32)-1) {
5143 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5144 +               kuid = make_kuid(&init_user_ns, tmp);
5145                 if (uid_valid(iap->ia_uid))
5146                         iap->ia_valid |= ATTR_UID;
5147         }
5148         if ((tmp = ntohl(*p++)) != (u32)-1) {
5149 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5150 +               kgid = make_kgid(&init_user_ns, tmp);
5151                 if (gid_valid(iap->ia_gid))
5152                         iap->ia_valid |= ATTR_GID;
5153         }
5154 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5155 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5156 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5157         if ((tmp = ntohl(*p++)) != (u32)-1) {
5158                 iap->ia_valid |= ATTR_SIZE;
5159                 iap->ia_size = tmp;
5160 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5161         *p++ = htonl(nfs_ftypes[type >> 12]);
5162         *p++ = htonl((u32) stat->mode);
5163         *p++ = htonl((u32) stat->nlink);
5164 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5165 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5166 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5167 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5168 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5169 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5170  
5171         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5172                 *p++ = htonl(NFS_MAXPATHLEN);
5173 diff -NurpP --minimal linux-4.4.110/fs/ocfs2/dlmglue.c linux-4.4.110-vs2.3.9/fs/ocfs2/dlmglue.c
5174 --- linux-4.4.110/fs/ocfs2/dlmglue.c    2018-01-09 16:35:07.000000000 +0000
5175 +++ linux-4.4.110-vs2.3.9/fs/ocfs2/dlmglue.c    2018-01-09 16:36:32.000000000 +0000
5176 @@ -2128,6 +2128,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5177         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5178         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5179         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5180 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5181         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5182         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5183         lvb->lvb_iatime_packed  =
5184 @@ -2178,6 +2179,7 @@ static void ocfs2_refresh_inode_from_lvb
5185  
5186         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5187         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5188 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5189         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5190         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5191         ocfs2_unpack_timespec(&inode->i_atime,
5192 diff -NurpP --minimal linux-4.4.110/fs/ocfs2/dlmglue.h linux-4.4.110-vs2.3.9/fs/ocfs2/dlmglue.h
5193 --- linux-4.4.110/fs/ocfs2/dlmglue.h    2018-01-09 16:35:07.000000000 +0000
5194 +++ linux-4.4.110-vs2.3.9/fs/ocfs2/dlmglue.h    2018-01-09 16:36:32.000000000 +0000
5195 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5196         __be16       lvb_inlink;
5197         __be32       lvb_iattr;
5198         __be32       lvb_igeneration;
5199 -       __be32       lvb_reserved2;
5200 +       __be16       lvb_itag;
5201 +       __be16       lvb_reserved2;
5202  };
5203  
5204  #define OCFS2_QINFO_LVB_VERSION 1
5205 diff -NurpP --minimal linux-4.4.110/fs/ocfs2/file.c linux-4.4.110-vs2.3.9/fs/ocfs2/file.c
5206 --- linux-4.4.110/fs/ocfs2/file.c       2018-01-09 16:35:07.000000000 +0000
5207 +++ linux-4.4.110-vs2.3.9/fs/ocfs2/file.c       2018-01-09 16:36:32.000000000 +0000
5208 @@ -1151,7 +1151,7 @@ int ocfs2_setattr(struct dentry *dentry,
5209                 attr->ia_valid &= ~ATTR_SIZE;
5210  
5211  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5212 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5213 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5214         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5215                 return 0;
5216  
5217 diff -NurpP --minimal linux-4.4.110/fs/ocfs2/inode.c linux-4.4.110-vs2.3.9/fs/ocfs2/inode.c
5218 --- linux-4.4.110/fs/ocfs2/inode.c      2016-07-05 04:12:34.000000000 +0000
5219 +++ linux-4.4.110-vs2.3.9/fs/ocfs2/inode.c      2018-01-09 16:36:32.000000000 +0000
5220 @@ -28,6 +28,7 @@
5221  #include <linux/highmem.h>
5222  #include <linux/pagemap.h>
5223  #include <linux/quotaops.h>
5224 +#include <linux/vs_tag.h>
5225  
5226  #include <asm/byteorder.h>
5227  
5228 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5229  {
5230         unsigned int flags = OCFS2_I(inode)->ip_attr;
5231  
5232 -       inode->i_flags &= ~(S_IMMUTABLE |
5233 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5234                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5235  
5236         if (flags & OCFS2_IMMUTABLE_FL)
5237                 inode->i_flags |= S_IMMUTABLE;
5238 +       if (flags & OCFS2_IXUNLINK_FL)
5239 +               inode->i_flags |= S_IXUNLINK;
5240  
5241         if (flags & OCFS2_SYNC_FL)
5242                 inode->i_flags |= S_SYNC;
5243 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5244                 inode->i_flags |= S_NOATIME;
5245         if (flags & OCFS2_DIRSYNC_FL)
5246                 inode->i_flags |= S_DIRSYNC;
5247 +
5248 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5249 +
5250 +       if (flags & OCFS2_BARRIER_FL)
5251 +               inode->i_vflags |= V_BARRIER;
5252 +       if (flags & OCFS2_COW_FL)
5253 +               inode->i_vflags |= V_COW;
5254  }
5255  
5256  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5257  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5258  {
5259         unsigned int flags = oi->vfs_inode.i_flags;
5260 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5261 +
5262 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5263 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5264 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5265 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5266 +
5267 +       if (flags & S_IMMUTABLE)
5268 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5269 +       if (flags & S_IXUNLINK)
5270 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5271  
5272 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5273 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5274         if (flags & S_SYNC)
5275                 oi->ip_attr |= OCFS2_SYNC_FL;
5276         if (flags & S_APPEND)
5277                 oi->ip_attr |= OCFS2_APPEND_FL;
5278 -       if (flags & S_IMMUTABLE)
5279 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5280         if (flags & S_NOATIME)
5281                 oi->ip_attr |= OCFS2_NOATIME_FL;
5282         if (flags & S_DIRSYNC)
5283                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5284 +
5285 +       if (vflags & V_BARRIER)
5286 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5287 +       if (vflags & V_COW)
5288 +               oi->ip_attr |= OCFS2_COW_FL;
5289  }
5290  
5291  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5292 @@ -268,6 +290,8 @@ void ocfs2_populate_inode(struct inode *
5293         struct super_block *sb;
5294         struct ocfs2_super *osb;
5295         int use_plocks = 1;
5296 +       uid_t uid;
5297 +       gid_t gid;
5298  
5299         sb = inode->i_sb;
5300         osb = OCFS2_SB(sb);
5301 @@ -296,8 +320,12 @@ void ocfs2_populate_inode(struct inode *
5302         inode->i_generation = le32_to_cpu(fe->i_generation);
5303         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5304         inode->i_mode = le16_to_cpu(fe->i_mode);
5305 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5306 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5307 +       uid = le32_to_cpu(fe->i_uid);
5308 +       gid = le32_to_cpu(fe->i_gid);
5309 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5310 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5311 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5312 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5313  
5314         /* Fast symlinks will have i_size but no allocated clusters. */
5315         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5316 diff -NurpP --minimal linux-4.4.110/fs/ocfs2/inode.h linux-4.4.110-vs2.3.9/fs/ocfs2/inode.h
5317 --- linux-4.4.110/fs/ocfs2/inode.h      2016-07-05 04:15:08.000000000 +0000
5318 +++ linux-4.4.110-vs2.3.9/fs/ocfs2/inode.h      2018-01-09 16:36:32.000000000 +0000
5319 @@ -161,6 +161,7 @@ struct buffer_head *ocfs2_bread(struct i
5320  
5321  void ocfs2_set_inode_flags(struct inode *inode);
5322  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5323 +int ocfs2_sync_flags(struct inode *inode, int, int);
5324  
5325  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5326  {
5327 diff -NurpP --minimal linux-4.4.110/fs/ocfs2/ioctl.c linux-4.4.110-vs2.3.9/fs/ocfs2/ioctl.c
5328 --- linux-4.4.110/fs/ocfs2/ioctl.c      2015-10-29 09:21:37.000000000 +0000
5329 +++ linux-4.4.110-vs2.3.9/fs/ocfs2/ioctl.c      2018-01-09 16:36:32.000000000 +0000
5330 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5331         return status;
5332  }
5333  
5334 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5335 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5336 +{
5337 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5338 +       struct buffer_head *bh = NULL;
5339 +       handle_t *handle = NULL;
5340 +       int status;
5341 +
5342 +       status = ocfs2_inode_lock(inode, &bh, 1);
5343 +       if (status < 0) {
5344 +               mlog_errno(status);
5345 +               return status;
5346 +       }
5347 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5348 +       if (IS_ERR(handle)) {
5349 +               status = PTR_ERR(handle);
5350 +               mlog_errno(status);
5351 +               goto bail_unlock;
5352 +       }
5353 +
5354 +       inode->i_flags = flags;
5355 +       inode->i_vflags = vflags;
5356 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5357 +
5358 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5359 +       if (status < 0)
5360 +               mlog_errno(status);
5361 +
5362 +       ocfs2_commit_trans(osb, handle);
5363 +bail_unlock:
5364 +       ocfs2_inode_unlock(inode, 1);
5365 +       brelse(bh);
5366 +       return status;
5367 +}
5368 +
5369 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5370                                 unsigned mask)
5371  {
5372         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5373 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5374                         goto bail_unlock;
5375         }
5376  
5377 +       if (IS_BARRIER(inode)) {
5378 +               vxwprintk_task(1, "messing with the barrier.");
5379 +               goto bail_unlock;
5380 +       }
5381 +
5382         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5383         if (IS_ERR(handle)) {
5384                 status = PTR_ERR(handle);
5385 @@ -841,6 +880,7 @@ bail:
5386         return status;
5387  }
5388  
5389 +
5390  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5391  {
5392         struct inode *inode = file_inode(filp);
5393 diff -NurpP --minimal linux-4.4.110/fs/ocfs2/namei.c linux-4.4.110-vs2.3.9/fs/ocfs2/namei.c
5394 --- linux-4.4.110/fs/ocfs2/namei.c      2018-01-09 16:35:07.000000000 +0000
5395 +++ linux-4.4.110-vs2.3.9/fs/ocfs2/namei.c      2018-01-09 16:36:32.000000000 +0000
5396 @@ -41,6 +41,7 @@
5397  #include <linux/slab.h>
5398  #include <linux/highmem.h>
5399  #include <linux/quotaops.h>
5400 +#include <linux/vs_tag.h>
5401  
5402  #include <cluster/masklog.h>
5403  
5404 @@ -516,6 +517,7 @@ static int __ocfs2_mknod_locked(struct i
5405         struct ocfs2_extent_list *fel;
5406         u16 feat;
5407         struct ocfs2_inode_info *oi = OCFS2_I(inode);
5408 +       ktag_t ktag;
5409  
5410         *new_fe_bh = NULL;
5411  
5412 @@ -553,8 +555,13 @@ static int __ocfs2_mknod_locked(struct i
5413         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5414         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5415         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5416 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5417 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5418 +
5419 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5420 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5421 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5422 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5423 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5424 +       inode->i_tag = ktag; /* is this correct? */
5425         fe->i_mode = cpu_to_le16(inode->i_mode);
5426         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5427                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5428 diff -NurpP --minimal linux-4.4.110/fs/ocfs2/ocfs2.h linux-4.4.110-vs2.3.9/fs/ocfs2/ocfs2.h
5429 --- linux-4.4.110/fs/ocfs2/ocfs2.h      2018-01-09 16:35:07.000000000 +0000
5430 +++ linux-4.4.110-vs2.3.9/fs/ocfs2/ocfs2.h      2018-01-09 17:21:54.000000000 +0000
5431 @@ -289,6 +289,7 @@ enum ocfs2_mount_options
5432         OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT = 1 << 15,  /* Journal Async Commit */
5433         OCFS2_MOUNT_ERRORS_CONT = 1 << 16, /* Return EIO to the calling process on error */
5434         OCFS2_MOUNT_ERRORS_ROFS = 1 << 17, /* Change filesystem to read-only on error */
5435 +       OCFS2_MOUNT_TAGGED = 1 << 18, /* use tagging */
5436  };
5437  
5438  #define OCFS2_OSB_SOFT_RO      0x0001
5439 diff -NurpP --minimal linux-4.4.110/fs/ocfs2/ocfs2_fs.h linux-4.4.110-vs2.3.9/fs/ocfs2/ocfs2_fs.h
5440 --- linux-4.4.110/fs/ocfs2/ocfs2_fs.h   2016-07-05 04:12:34.000000000 +0000
5441 +++ linux-4.4.110-vs2.3.9/fs/ocfs2/ocfs2_fs.h   2018-01-09 16:36:32.000000000 +0000
5442 @@ -275,6 +275,11 @@
5443  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5444  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5445  
5446 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5447 +
5448 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5449 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5450 +
5451  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5452  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5453  
5454 diff -NurpP --minimal linux-4.4.110/fs/ocfs2/super.c linux-4.4.110-vs2.3.9/fs/ocfs2/super.c
5455 --- linux-4.4.110/fs/ocfs2/super.c      2016-07-05 04:12:34.000000000 +0000
5456 +++ linux-4.4.110-vs2.3.9/fs/ocfs2/super.c      2018-01-09 17:22:51.000000000 +0000
5457 @@ -193,6 +193,7 @@ enum {
5458         Opt_dir_resv_level,
5459         Opt_journal_async_commit,
5460         Opt_err_cont,
5461 +       Opt_tag, Opt_notag, Opt_tagid,
5462         Opt_err,
5463  };
5464  
5465 @@ -226,6 +227,9 @@ static const match_table_t tokens = {
5466         {Opt_dir_resv_level, "dir_resv_level=%u"},
5467         {Opt_journal_async_commit, "journal_async_commit"},
5468         {Opt_err_cont, "errors=continue"},
5469 +       {Opt_tag, "tag"},
5470 +       {Opt_notag, "notag"},
5471 +       {Opt_tagid, "tagid=%u"},
5472         {Opt_err, NULL}
5473  };
5474  
5475 @@ -677,6 +681,13 @@ static int ocfs2_remount(struct super_bl
5476                 goto out;
5477         }
5478  
5479 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5480 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5481 +               ret = -EINVAL;
5482 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5483 +               goto out;
5484 +       }
5485 +
5486         /* We're going to/from readonly mode. */
5487         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5488                 /* Disable quota accounting before remounting RO */
5489 @@ -1166,6 +1177,9 @@ static int ocfs2_fill_super(struct super
5490  
5491         ocfs2_complete_mount_recovery(osb);
5492  
5493 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5494 +               sb->s_flags |= MS_TAGGED;
5495 +
5496         if (ocfs2_mount_local(osb))
5497                 snprintf(nodestr, sizeof(nodestr), "local");
5498         else
5499 @@ -1486,6 +1500,20 @@ static int ocfs2_parse_options(struct su
5500                 case Opt_journal_async_commit:
5501                         mopt->mount_opt |= OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT;
5502                         break;
5503 +#ifndef CONFIG_TAGGING_NONE
5504 +               case Opt_tag:
5505 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5506 +                       break;
5507 +               case Opt_notag:
5508 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5509 +                       break;
5510 +#endif
5511 +#ifdef CONFIG_PROPAGATE
5512 +               case Opt_tagid:
5513 +                       /* use args[0] */
5514 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5515 +                       break;
5516 +#endif
5517                 default:
5518                         mlog(ML_ERROR,
5519                              "Unrecognized mount option \"%s\" "
5520 diff -NurpP --minimal linux-4.4.110/fs/open.c linux-4.4.110-vs2.3.9/fs/open.c
5521 --- linux-4.4.110/fs/open.c     2018-01-09 16:35:07.000000000 +0000
5522 +++ linux-4.4.110-vs2.3.9/fs/open.c     2018-01-09 16:36:32.000000000 +0000
5523 @@ -31,6 +31,11 @@
5524  #include <linux/ima.h>
5525  #include <linux/dnotify.h>
5526  #include <linux/compat.h>
5527 +#include <linux/vs_base.h>
5528 +#include <linux/vs_limit.h>
5529 +#include <linux/vs_tag.h>
5530 +#include <linux/vs_cowbl.h>
5531 +#include <linux/vserver/dlimit.h>
5532  
5533  #include "internal.h"
5534  
5535 @@ -70,6 +75,11 @@ long vfs_truncate(struct path *path, lof
5536         struct inode *inode;
5537         long error;
5538  
5539 +#ifdef CONFIG_VSERVER_COWBL
5540 +       error = cow_check_and_break(path);
5541 +       if (error)
5542 +               goto out;
5543 +#endif
5544         inode = path->dentry->d_inode;
5545  
5546         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5547 @@ -548,6 +558,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5548         unsigned int lookup_flags = LOOKUP_FOLLOW;
5549  retry:
5550         error = user_path_at(dfd, filename, lookup_flags, &path);
5551 +#ifdef CONFIG_VSERVER_COWBL
5552 +       if (!error) {
5553 +               error = cow_check_and_break(&path);
5554 +               if (error)
5555 +                       path_put(&path);
5556 +       }
5557 +#endif
5558         if (!error) {
5559                 error = chmod_common(&path, mode);
5560                 path_put(&path);
5561 @@ -582,13 +599,15 @@ retry_deleg:
5562                 if (!uid_valid(uid))
5563                         return -EINVAL;
5564                 newattrs.ia_valid |= ATTR_UID;
5565 -               newattrs.ia_uid = uid;
5566 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5567 +                       dx_map_uid(user));
5568         }
5569         if (group != (gid_t) -1) {
5570                 if (!gid_valid(gid))
5571                         return -EINVAL;
5572                 newattrs.ia_valid |= ATTR_GID;
5573 -               newattrs.ia_gid = gid;
5574 +               newattrs.ia_gid = make_kgid(&init_user_ns,
5575 +                       dx_map_gid(group));
5576         }
5577         if (!S_ISDIR(inode->i_mode))
5578                 newattrs.ia_valid |=
5579 @@ -626,6 +645,10 @@ retry:
5580         error = mnt_want_write(path.mnt);
5581         if (error)
5582                 goto out_release;
5583 +#ifdef CONFIG_VSERVER_COWBL
5584 +       error = cow_check_and_break(&path);
5585 +       if (!error)
5586 +#endif
5587         error = chown_common(&path, user, group);
5588         mnt_drop_write(path.mnt);
5589  out_release:
5590 diff -NurpP --minimal linux-4.4.110/fs/proc/array.c linux-4.4.110-vs2.3.9/fs/proc/array.c
5591 --- linux-4.4.110/fs/proc/array.c       2018-01-09 16:35:07.000000000 +0000
5592 +++ linux-4.4.110-vs2.3.9/fs/proc/array.c       2018-01-09 17:30:44.000000000 +0000
5593 @@ -83,6 +83,8 @@
5594  #include <linux/tracehook.h>
5595  #include <linux/string_helpers.h>
5596  #include <linux/user_namespace.h>
5597 +#include <linux/vs_context.h>
5598 +#include <linux/vs_network.h>
5599  
5600  #include <asm/pgtable.h>
5601  #include <asm/processor.h>
5602 @@ -154,6 +156,9 @@ static inline void task_state(struct seq
5603         ppid = pid_alive(p) ?
5604                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5605  
5606 +       if (unlikely(vx_current_initpid(p->pid)))
5607 +               ppid = 0;
5608 +
5609         tracer = ptrace_parent(p);
5610         if (tracer)
5611                 tpid = task_pid_nr_ns(tracer, ns);
5612 @@ -292,8 +297,8 @@ static inline void task_sig(struct seq_f
5613         render_sigset_t(m, "SigCgt:\t", &caught);
5614  }
5615  
5616 -static void render_cap_t(struct seq_file *m, const char *header,
5617 -                       kernel_cap_t *a)
5618 +void render_cap_t(struct seq_file *m, const char *header,
5619 +                       struct vx_info *vxi, kernel_cap_t *a)
5620  {
5621         unsigned __capi;
5622  
5623 @@ -320,11 +325,12 @@ static inline void task_cap(struct seq_f
5624         cap_ambient     = cred->cap_ambient;
5625         rcu_read_unlock();
5626  
5627 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
5628 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
5629 -       render_cap_t(m, "CapEff:\t", &cap_effective);
5630 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
5631 -       render_cap_t(m, "CapAmb:\t", &cap_ambient);
5632 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5633 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5634 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5635 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5636 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5637 +       render_cap_t(m, "CapAmb:\t", p->vx_info, &cap_ambient);
5638  }
5639  
5640  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
5641 @@ -351,6 +357,43 @@ static void task_cpus_allowed(struct seq
5642                    cpumask_pr_args(&task->cpus_allowed));
5643  }
5644  
5645 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
5646 +                       struct pid *pid, struct task_struct *task)
5647 +{
5648 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
5649 +                       "Count:\t%u\n"
5650 +                       "uts:\t%p(%c)\n"
5651 +                       "ipc:\t%p(%c)\n"
5652 +                       "mnt:\t%p(%c)\n"
5653 +                       "pid:\t%p(%c)\n"
5654 +                       "net:\t%p(%c)\n",
5655 +                       task->nsproxy,
5656 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
5657 +                       atomic_read(&task->nsproxy->count),
5658 +                       task->nsproxy->uts_ns,
5659 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
5660 +                       task->nsproxy->ipc_ns,
5661 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
5662 +                       task->nsproxy->mnt_ns,
5663 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
5664 +                       task->nsproxy->pid_ns_for_children,
5665 +                       (task->nsproxy->pid_ns_for_children ==
5666 +                               init_task.nsproxy->pid_ns_for_children ? 'I' : '-'),
5667 +                       task->nsproxy->net_ns,
5668 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
5669 +       return 0;
5670 +}
5671 +
5672 +void task_vs_id(struct seq_file *m, struct task_struct *task)
5673 +{
5674 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
5675 +               return;
5676 +
5677 +       seq_printf(m, "VxID:\t%d\n", vx_task_xid(task));
5678 +       seq_printf(m, "NxID:\t%d\n", nx_task_nid(task));
5679 +}
5680 +
5681 +
5682  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
5683                         struct pid *pid, struct task_struct *task)
5684  {
5685 @@ -368,6 +411,7 @@ int proc_pid_status(struct seq_file *m,
5686         task_seccomp(m, task);
5687         task_cpus_allowed(m, task);
5688         cpuset_task_status_allowed(m, task);
5689 +       task_vs_id(m, task);
5690         task_context_switch_counts(m, task);
5691         return 0;
5692  }
5693 @@ -471,6 +515,17 @@ static int do_task_stat(struct seq_file
5694         /* convert nsec -> ticks */
5695         start_time = nsec_to_clock_t(task->real_start_time);
5696  
5697 +       /* fixup start time for virt uptime */
5698 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
5699 +               unsigned long long bias =
5700 +                       current->vx_info->cvirt.bias_clock;
5701 +
5702 +               if (start_time > bias)
5703 +                       start_time -= bias;
5704 +               else
5705 +                       start_time = 0;
5706 +       }
5707 +
5708         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
5709         seq_put_decimal_ll(m, ' ', ppid);
5710         seq_put_decimal_ll(m, ' ', pgid);
5711 diff -NurpP --minimal linux-4.4.110/fs/proc/base.c linux-4.4.110-vs2.3.9/fs/proc/base.c
5712 --- linux-4.4.110/fs/proc/base.c        2018-01-09 16:35:07.000000000 +0000
5713 +++ linux-4.4.110-vs2.3.9/fs/proc/base.c        2018-01-09 16:36:32.000000000 +0000
5714 @@ -87,6 +87,8 @@
5715  #include <linux/slab.h>
5716  #include <linux/flex_array.h>
5717  #include <linux/posix-timers.h>
5718 +#include <linux/vs_context.h>
5719 +#include <linux/vs_network.h>
5720  #ifdef CONFIG_HARDWALL
5721  #include <asm/hardwall.h>
5722  #endif
5723 @@ -1097,11 +1099,15 @@ static ssize_t oom_adj_write(struct file
5724                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
5725  
5726         if (oom_adj < task->signal->oom_score_adj &&
5727 -           !capable(CAP_SYS_RESOURCE)) {
5728 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
5729                 err = -EACCES;
5730                 goto err_sighand;
5731         }
5732  
5733 +       /* prevent guest processes from circumventing the oom killer */
5734 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
5735 +               oom_adj = OOM_ADJUST_MIN;
5736 +
5737         /*
5738          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
5739          * /proc/pid/oom_score_adj instead.
5740 @@ -1666,6 +1672,8 @@ struct inode *proc_pid_make_inode(struct
5741                 inode->i_gid = cred->egid;
5742                 rcu_read_unlock();
5743         }
5744 +       /* procfs is xid tagged */
5745 +       i_tag_write(inode, (vtag_t)vx_task_xid(task));
5746         security_task_to_inode(task, inode);
5747  
5748  out:
5749 @@ -1711,6 +1719,8 @@ int pid_getattr(struct vfsmount *mnt, st
5750  
5751  /* dentry stuff */
5752  
5753 +// static unsigned name_to_int(struct dentry *dentry);
5754 +
5755  /*
5756   *     Exceptional case: normally we are not allowed to unhash a busy
5757   * directory. In this case, however, we can do it - no aliasing problems
5758 @@ -1739,6 +1749,19 @@ int pid_revalidate(struct dentry *dentry
5759         task = get_proc_task(inode);
5760  
5761         if (task) {
5762 +               unsigned pid = name_to_int(&dentry->d_name);
5763 +
5764 +               if (pid != ~0U && pid != vx_map_pid(task->pid) &&
5765 +                       pid != __task_pid_nr_ns(task, PIDTYPE_PID,
5766 +                               task_active_pid_ns(task))) {
5767 +                       vxdprintk(VXD_CBIT(misc, 10),
5768 +                               VS_Q("%*s") " dropped by pid_revalidate(%d!=%d)",
5769 +                               dentry->d_name.len, dentry->d_name.name,
5770 +                               pid, vx_map_pid(task->pid));
5771 +                       put_task_struct(task);
5772 +                       d_drop(dentry);
5773 +                       return 0;
5774 +               }
5775                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
5776                     task_dumpable(task)) {
5777                         rcu_read_lock();
5778 @@ -2283,6 +2306,13 @@ static struct dentry *proc_pident_lookup
5779         if (!task)
5780                 goto out_no_task;
5781  
5782 +       /* TODO: maybe we can come up with a generic approach? */
5783 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
5784 +               (dentry->d_name.len == 5) &&
5785 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
5786 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
5787 +               goto out;
5788 +
5789         /*
5790          * Yes, it does not scale. And it should not. Don't add
5791          * new entries into /proc/<tgid>/ without very good reasons.
5792 @@ -2725,6 +2755,11 @@ static int proc_pid_personality(struct s
5793  static const struct file_operations proc_task_operations;
5794  static const struct inode_operations proc_task_inode_operations;
5795  
5796 +extern int proc_pid_vx_info(struct seq_file *,
5797 +       struct pid_namespace *, struct pid *, struct task_struct *);
5798 +extern int proc_pid_nx_info(struct seq_file *,
5799 +       struct pid_namespace *, struct pid *, struct task_struct *);
5800 +
5801  static const struct pid_entry tgid_base_stuff[] = {
5802         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
5803         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
5804 @@ -2789,6 +2824,8 @@ static const struct pid_entry tgid_base_
5805  #ifdef CONFIG_CGROUPS
5806         ONE("cgroup",  S_IRUGO, proc_cgroup_show),
5807  #endif
5808 +       ONE("vinfo",      S_IRUGO, proc_pid_vx_info),
5809 +       ONE("ninfo",      S_IRUGO, proc_pid_nx_info),
5810         ONE("oom_score",  S_IRUGO, proc_oom_score),
5811         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
5812         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
5813 @@ -3003,7 +3040,7 @@ retry:
5814         iter.task = NULL;
5815         pid = find_ge_pid(iter.tgid, ns);
5816         if (pid) {
5817 -               iter.tgid = pid_nr_ns(pid, ns);
5818 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
5819                 iter.task = pid_task(pid, PIDTYPE_PID);
5820                 /* What we to know is if the pid we have find is the
5821                  * pid of a thread_group_leader.  Testing for task
5822 @@ -3063,8 +3100,10 @@ int proc_pid_readdir(struct file *file,
5823                 if (!has_pid_permissions(ns, iter.task, 2))
5824                         continue;
5825  
5826 -               len = snprintf(name, sizeof(name), "%d", iter.tgid);
5827 +               len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
5828                 ctx->pos = iter.tgid + TGID_OFFSET;
5829 +               if (!vx_proc_task_visible(iter.task))
5830 +                       continue;
5831                 if (!proc_fill_cache(file, ctx, name, len,
5832                                      proc_pid_instantiate, iter.task, NULL)) {
5833                         put_task_struct(iter.task);
5834 @@ -3161,6 +3200,7 @@ static const struct pid_entry tid_base_s
5835         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
5836         REG("setgroups",  S_IRUGO|S_IWUSR, proc_setgroups_operations),
5837  #endif
5838 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
5839  };
5840  
5841  static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
5842 @@ -3227,6 +3267,8 @@ static struct dentry *proc_task_lookup(s
5843         tid = name_to_int(&dentry->d_name);
5844         if (tid == ~0U)
5845                 goto out;
5846 +       if (vx_current_initpid(tid))
5847 +               goto out;
5848  
5849         ns = dentry->d_sb->s_fs_info;
5850         rcu_read_lock();
5851 diff -NurpP --minimal linux-4.4.110/fs/proc/generic.c linux-4.4.110-vs2.3.9/fs/proc/generic.c
5852 --- linux-4.4.110/fs/proc/generic.c     2018-01-09 16:35:07.000000000 +0000
5853 +++ linux-4.4.110-vs2.3.9/fs/proc/generic.c     2018-01-09 17:29:24.000000000 +0000
5854 @@ -22,6 +22,7 @@
5855  #include <linux/bitops.h>
5856  #include <linux/spinlock.h>
5857  #include <linux/completion.h>
5858 +#include <linux/vserver/inode.h>
5859  #include <asm/uaccess.h>
5860  
5861  #include "internal.h"
5862 @@ -66,8 +67,16 @@ static struct proc_dir_entry *pde_subdir
5863                         node = node->rb_left;
5864                 else if (result > 0)
5865                         node = node->rb_right;
5866 -               else
5867 +               else {
5868 +                       if (!vx_hide_check(0, de->vx_flags)) {
5869 +                               vxdprintk(VXD_CBIT(misc, 9),
5870 +                                       VS_Q("%*s")
5871 +                                       " hidden in pde_subdir_find()",
5872 +                                       de->namelen, de->name);
5873 +                               return 0;
5874 +                       }
5875                         return de;
5876 +               }
5877         }
5878         return NULL;
5879  }
5880 @@ -241,6 +250,8 @@ struct dentry *proc_lookup_de(struct pro
5881                         return ERR_PTR(-ENOMEM);
5882                 d_set_d_op(dentry, &simple_dentry_operations);
5883                 d_add(dentry, inode);
5884 +                       /* generic proc entries belong to the host */
5885 +                       i_tag_write(inode, 0);
5886                 return NULL;
5887         }
5888         read_unlock(&proc_subdir_lock);
5889 @@ -287,6 +298,12 @@ int proc_readdir_de(struct proc_dir_entr
5890         do {
5891                 struct proc_dir_entry *next;
5892                 pde_get(de);
5893 +               if (!vx_hide_check(0, de->vx_flags)) {
5894 +                       vxdprintk(VXD_CBIT(misc, 9),
5895 +                               VS_Q("%*s") " hidden in proc_readdir_de()",
5896 +                               de->namelen, de->name);
5897 +                       goto skip;
5898 +               }
5899                 read_unlock(&proc_subdir_lock);
5900                 if (!dir_emit(ctx, de->name, de->namelen,
5901                             de->low_ino, de->mode >> 12)) {
5902 @@ -294,6 +311,7 @@ int proc_readdir_de(struct proc_dir_entr
5903                         return 0;
5904                 }
5905                 read_lock(&proc_subdir_lock);
5906 +       skip:
5907                 ctx->pos++;
5908                 next = pde_subdir_next(de);
5909                 pde_put(de);
5910 @@ -387,6 +405,7 @@ static struct proc_dir_entry *__proc_cre
5911         ent->mode = mode;
5912         ent->nlink = nlink;
5913         ent->subdir = RB_ROOT;
5914 +       ent->vx_flags = IATTR_PROC_DEFAULT;
5915         atomic_set(&ent->count, 1);
5916         spin_lock_init(&ent->pde_unload_lock);
5917         INIT_LIST_HEAD(&ent->pde_openers);
5918 @@ -411,7 +430,8 @@ struct proc_dir_entry *proc_symlink(cons
5919                                 kfree(ent->data);
5920                                 kfree(ent);
5921                                 ent = NULL;
5922 -                       }
5923 +                       } else
5924 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
5925                 } else {
5926                         kfree(ent);
5927                         ent = NULL;
5928 diff -NurpP --minimal linux-4.4.110/fs/proc/inode.c linux-4.4.110-vs2.3.9/fs/proc/inode.c
5929 --- linux-4.4.110/fs/proc/inode.c       2015-10-29 09:21:39.000000000 +0000
5930 +++ linux-4.4.110-vs2.3.9/fs/proc/inode.c       2018-01-09 16:36:32.000000000 +0000
5931 @@ -431,6 +431,8 @@ struct inode *proc_get_inode(struct supe
5932                         inode->i_uid = de->uid;
5933                         inode->i_gid = de->gid;
5934                 }
5935 +               if (de->vx_flags)
5936 +                       PROC_I(inode)->vx_flags = de->vx_flags;
5937                 if (de->size)
5938                         inode->i_size = de->size;
5939                 if (de->nlink)
5940 diff -NurpP --minimal linux-4.4.110/fs/proc/internal.h linux-4.4.110-vs2.3.9/fs/proc/internal.h
5941 --- linux-4.4.110/fs/proc/internal.h    2015-10-29 09:21:39.000000000 +0000
5942 +++ linux-4.4.110-vs2.3.9/fs/proc/internal.h    2018-01-09 16:36:32.000000000 +0000
5943 @@ -14,6 +14,7 @@
5944  #include <linux/spinlock.h>
5945  #include <linux/atomic.h>
5946  #include <linux/binfmts.h>
5947 +#include <linux/vs_pid.h>
5948  
5949  struct ctl_table_header;
5950  struct mempolicy;
5951 @@ -34,6 +35,7 @@ struct proc_dir_entry {
5952         nlink_t nlink;
5953         kuid_t uid;
5954         kgid_t gid;
5955 +       int vx_flags;
5956         loff_t size;
5957         const struct inode_operations *proc_iops;
5958         const struct file_operations *proc_fops;
5959 @@ -51,15 +53,22 @@ struct proc_dir_entry {
5960         char name[];
5961  };
5962  
5963 +struct vx_info;
5964 +struct nx_info;
5965 +
5966  union proc_op {
5967         int (*proc_get_link)(struct dentry *, struct path *);
5968         int (*proc_show)(struct seq_file *m,
5969                 struct pid_namespace *ns, struct pid *pid,
5970                 struct task_struct *task);
5971 +       int (*proc_vs_read)(char *page);
5972 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
5973 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
5974  };
5975  
5976  struct proc_inode {
5977         struct pid *pid;
5978 +       int vx_flags;
5979         int fd;
5980         union proc_op op;
5981         struct proc_dir_entry *pde;
5982 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
5983         return PROC_I(inode)->pid;
5984  }
5985  
5986 -static inline struct task_struct *get_proc_task(struct inode *inode)
5987 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
5988  {
5989         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
5990  }
5991  
5992 +static inline struct task_struct *get_proc_task(struct inode *inode)
5993 +{
5994 +       return vx_get_proc_task(inode, proc_pid(inode));
5995 +}
5996 +
5997  static inline int task_dumpable(struct task_struct *task)
5998  {
5999         int dumpable = 0;
6000 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6001                            struct pid *, struct task_struct *);
6002  extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6003                           struct pid *, struct task_struct *);
6004 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6005 +                           struct pid *pid, struct task_struct *task);
6006  
6007  /*
6008   * base.c
6009 diff -NurpP --minimal linux-4.4.110/fs/proc/loadavg.c linux-4.4.110-vs2.3.9/fs/proc/loadavg.c
6010 --- linux-4.4.110/fs/proc/loadavg.c     2015-04-12 22:12:50.000000000 +0000
6011 +++ linux-4.4.110-vs2.3.9/fs/proc/loadavg.c     2018-01-09 16:36:32.000000000 +0000
6012 @@ -12,15 +12,27 @@
6013  
6014  static int loadavg_proc_show(struct seq_file *m, void *v)
6015  {
6016 +       unsigned long running;
6017 +       unsigned int threads;
6018         unsigned long avnrun[3];
6019  
6020         get_avenrun(avnrun, FIXED_1/200, 0);
6021  
6022 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6023 +               struct vx_info *vxi = current_vx_info();
6024 +
6025 +               running = atomic_read(&vxi->cvirt.nr_running);
6026 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6027 +       } else {
6028 +               running = nr_running();
6029 +               threads = nr_threads;
6030 +       }
6031 +
6032         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6033                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6034                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6035                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6036 -               nr_running(), nr_threads,
6037 +               running, threads,
6038                 task_active_pid_ns(current)->last_pid);
6039         return 0;
6040  }
6041 diff -NurpP --minimal linux-4.4.110/fs/proc/meminfo.c linux-4.4.110-vs2.3.9/fs/proc/meminfo.c
6042 --- linux-4.4.110/fs/proc/meminfo.c     2016-07-05 04:15:09.000000000 +0000
6043 +++ linux-4.4.110-vs2.3.9/fs/proc/meminfo.c     2018-01-09 16:36:32.000000000 +0000
6044 @@ -43,7 +43,8 @@ static int meminfo_proc_show(struct seq_
6045         si_swapinfo(&i);
6046         committed = percpu_counter_read_positive(&vm_committed_as);
6047  
6048 -       cached = global_page_state(NR_FILE_PAGES) -
6049 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6050 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6051                         total_swapcache_pages() - i.bufferram;
6052         if (cached < 0)
6053                 cached = 0;
6054 diff -NurpP --minimal linux-4.4.110/fs/proc/root.c linux-4.4.110-vs2.3.9/fs/proc/root.c
6055 --- linux-4.4.110/fs/proc/root.c        2018-01-09 16:35:08.000000000 +0000
6056 +++ linux-4.4.110-vs2.3.9/fs/proc/root.c        2018-01-09 16:36:32.000000000 +0000
6057 @@ -20,9 +20,14 @@
6058  #include <linux/mount.h>
6059  #include <linux/pid_namespace.h>
6060  #include <linux/parser.h>
6061 +#include <linux/vserver/inode.h>
6062  
6063  #include "internal.h"
6064  
6065 +struct proc_dir_entry *proc_virtual;
6066 +
6067 +extern void proc_vx_init(void);
6068 +
6069  static int proc_test_super(struct super_block *sb, void *data)
6070  {
6071         return sb->s_fs_info == data;
6072 @@ -113,7 +118,8 @@ static struct dentry *proc_mount(struct
6073                 options = data;
6074  
6075                 /* Does the mounter have privilege over the pid namespace? */
6076 -               if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6077 +               if (!vx_ns_capable(ns->user_ns,
6078 +                       CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6079                         return ERR_PTR(-EPERM);
6080         }
6081  
6082 @@ -196,6 +202,7 @@ void __init proc_root_init(void)
6083         proc_tty_init();
6084         proc_mkdir("bus", NULL);
6085         proc_sys_init();
6086 +       proc_vx_init();
6087  }
6088  
6089  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6090 @@ -257,6 +264,7 @@ struct proc_dir_entry proc_root = {
6091         .proc_iops      = &proc_root_inode_operations, 
6092         .proc_fops      = &proc_root_operations,
6093         .parent         = &proc_root,
6094 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6095         .subdir         = RB_ROOT,
6096         .name           = "/proc",
6097  };
6098 diff -NurpP --minimal linux-4.4.110/fs/proc/self.c linux-4.4.110-vs2.3.9/fs/proc/self.c
6099 --- linux-4.4.110/fs/proc/self.c        2015-10-29 09:21:39.000000000 +0000
6100 +++ linux-4.4.110-vs2.3.9/fs/proc/self.c        2018-01-09 16:36:32.000000000 +0000
6101 @@ -1,6 +1,7 @@
6102  #include <linux/sched.h>
6103  #include <linux/slab.h>
6104  #include <linux/pid_namespace.h>
6105 +#include <linux/vserver/inode.h>
6106  #include "internal.h"
6107  
6108  /*
6109 @@ -52,6 +53,8 @@ int proc_setup_self(struct super_block *
6110         self = d_alloc_name(s->s_root, "self");
6111         if (self) {
6112                 struct inode *inode = new_inode_pseudo(s);
6113 +
6114 +               // self->vx_flags = IATTR_PROC_SYMLINK;
6115                 if (inode) {
6116                         inode->i_ino = self_inum;
6117                         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6118 diff -NurpP --minimal linux-4.4.110/fs/proc/stat.c linux-4.4.110-vs2.3.9/fs/proc/stat.c
6119 --- linux-4.4.110/fs/proc/stat.c        2015-04-12 22:12:50.000000000 +0000
6120 +++ linux-4.4.110-vs2.3.9/fs/proc/stat.c        2018-01-09 16:36:32.000000000 +0000
6121 @@ -9,8 +9,10 @@
6122  #include <linux/slab.h>
6123  #include <linux/time.h>
6124  #include <linux/irqnr.h>
6125 +#include <linux/vserver/cvirt.h>
6126  #include <linux/cputime.h>
6127  #include <linux/tick.h>
6128 +#include <linux/cpuset.h>
6129  
6130  #ifndef arch_irq_stat_cpu
6131  #define arch_irq_stat_cpu(cpu) 0
6132 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6133         u64 sum_softirq = 0;
6134         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6135         struct timespec boottime;
6136 +       cpumask_var_t cpus_allowed;
6137 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6138  
6139         user = nice = system = idle = iowait =
6140                 irq = softirq = steal = 0;
6141         guest = guest_nice = 0;
6142         getboottime(&boottime);
6143 +
6144 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6145 +               vx_vsi_boottime(&boottime);
6146 +
6147 +       if (virt_cpu)
6148 +               cpuset_cpus_allowed(current, cpus_allowed);
6149 +
6150         jif = boottime.tv_sec;
6151  
6152         for_each_possible_cpu(i) {
6153 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6154 +                       continue;
6155 +
6156                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6157                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6158                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6159 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6160         seq_putc(p, '\n');
6161  
6162         for_each_online_cpu(i) {
6163 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6164 +                       continue;
6165 +
6166                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6167                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6168                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6169 diff -NurpP --minimal linux-4.4.110/fs/proc/uptime.c linux-4.4.110-vs2.3.9/fs/proc/uptime.c
6170 --- linux-4.4.110/fs/proc/uptime.c      2015-04-12 22:12:50.000000000 +0000
6171 +++ linux-4.4.110-vs2.3.9/fs/proc/uptime.c      2018-01-09 16:36:32.000000000 +0000
6172 @@ -5,6 +5,7 @@
6173  #include <linux/seq_file.h>
6174  #include <linux/time.h>
6175  #include <linux/kernel_stat.h>
6176 +#include <linux/vserver/cvirt.h>
6177  #include <linux/cputime.h>
6178  
6179  static int uptime_proc_show(struct seq_file *m, void *v)
6180 @@ -24,6 +25,10 @@ static int uptime_proc_show(struct seq_f
6181         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6182         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6183         idle.tv_nsec = rem;
6184 +
6185 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6186 +               vx_vsi_uptime(&uptime, &idle);
6187 +
6188         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6189                         (unsigned long) uptime.tv_sec,
6190                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6191 diff -NurpP --minimal linux-4.4.110/fs/proc_namespace.c linux-4.4.110-vs2.3.9/fs/proc_namespace.c
6192 --- linux-4.4.110/fs/proc_namespace.c   2018-01-09 16:35:08.000000000 +0000
6193 +++ linux-4.4.110-vs2.3.9/fs/proc_namespace.c   2018-01-09 16:36:32.000000000 +0000
6194 @@ -46,6 +46,8 @@ static int show_sb_opts(struct seq_file
6195                 { MS_DIRSYNC, ",dirsync" },
6196                 { MS_MANDLOCK, ",mand" },
6197                 { MS_LAZYTIME, ",lazytime" },
6198 +               { MS_TAGGED, ",tag" },
6199 +               { MS_NOTAGCHECK, ",notagcheck" },
6200                 { 0, NULL }
6201         };
6202         const struct proc_fs_info *fs_infop;
6203 @@ -82,6 +84,38 @@ static inline void mangle(struct seq_fil
6204         seq_escape(m, s, " \t\n\\");
6205  }
6206  
6207 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6208 +
6209 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6210 +{
6211 +       struct path root;
6212 +       struct dentry *point;
6213 +       struct mount *mnt = real_mount(vfsmnt);
6214 +       struct mount *root_mnt;
6215 +       int ret;
6216 +
6217 +       if (mnt == mnt->mnt_ns->root)
6218 +               return 1;
6219 +
6220 +       rcu_read_lock();
6221 +       root = current->fs->root;
6222 +       root_mnt = real_mount(root.mnt);
6223 +       point = root.dentry;
6224 +
6225 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6226 +               point = mnt->mnt_mountpoint;
6227 +               mnt = mnt->mnt_parent;
6228 +       }
6229 +       rcu_read_unlock();
6230 +
6231 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6232 +       return ret;
6233 +}
6234 +
6235 +#else
6236 +#define        mnt_is_reachable(v)     (1)
6237 +#endif
6238 +
6239  static void show_type(struct seq_file *m, struct super_block *sb)
6240  {
6241         mangle(m, sb->s_type->name);
6242 @@ -99,6 +133,17 @@ static int show_vfsmnt(struct seq_file *
6243         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6244         struct super_block *sb = mnt_path.dentry->d_sb;
6245  
6246 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6247 +               return SEQ_SKIP;
6248 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6249 +               return SEQ_SKIP;
6250 +
6251 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6252 +               mnt == current->fs->root.mnt) {
6253 +               seq_puts(m, "/dev/root / ");
6254 +               goto type;
6255 +       }
6256 +
6257         if (sb->s_op->show_devname) {
6258                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6259                 if (err)
6260 @@ -112,6 +157,7 @@ static int show_vfsmnt(struct seq_file *
6261         if (err)
6262                 goto out;
6263         seq_putc(m, ' ');
6264 +type:
6265         show_type(m, sb);
6266         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6267         err = show_sb_opts(m, sb);
6268 @@ -133,6 +179,11 @@ static int show_mountinfo(struct seq_fil
6269         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6270         int err = 0;
6271  
6272 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6273 +               return SEQ_SKIP;
6274 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6275 +               return SEQ_SKIP;
6276 +
6277         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6278                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6279         if (sb->s_op->show_path)
6280 @@ -193,6 +244,17 @@ static int show_vfsstat(struct seq_file
6281         struct super_block *sb = mnt_path.dentry->d_sb;
6282         int err = 0;
6283  
6284 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6285 +               return SEQ_SKIP;
6286 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6287 +               return SEQ_SKIP;
6288 +
6289 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6290 +               mnt == current->fs->root.mnt) {
6291 +               seq_puts(m, "device /dev/root mounted on / ");
6292 +               goto type;
6293 +       }
6294 +
6295         /* device */
6296         if (sb->s_op->show_devname) {
6297                 seq_puts(m, "device ");
6298 @@ -214,7 +276,7 @@ static int show_vfsstat(struct seq_file
6299         if (err)
6300                 goto out;
6301         seq_putc(m, ' ');
6302 -
6303 +type:
6304         /* file system type */
6305         seq_puts(m, "with fstype ");
6306         show_type(m, sb);
6307 diff -NurpP --minimal linux-4.4.110/fs/quota/dquot.c linux-4.4.110-vs2.3.9/fs/quota/dquot.c
6308 --- linux-4.4.110/fs/quota/dquot.c      2018-01-09 16:35:08.000000000 +0000
6309 +++ linux-4.4.110-vs2.3.9/fs/quota/dquot.c      2018-01-09 16:36:32.000000000 +0000
6310 @@ -1643,6 +1643,9 @@ int __dquot_alloc_space(struct inode *in
6311         int reserve = flags & DQUOT_SPACE_RESERVE;
6312         struct dquot **dquots;
6313  
6314 +       if ((ret = dl_alloc_space(inode, number)))
6315 +               return ret;
6316 +
6317         if (!dquot_active(inode)) {
6318                 inode_incr_space(inode, number, reserve);
6319                 goto out;
6320 @@ -1695,6 +1698,9 @@ int dquot_alloc_inode(struct inode *inod
6321         struct dquot_warn warn[MAXQUOTAS];
6322         struct dquot * const *dquots;
6323  
6324 +       if ((ret = dl_alloc_inode(inode)))
6325 +               return ret;
6326 +
6327         if (!dquot_active(inode))
6328                 return 0;
6329         for (cnt = 0; cnt < MAXQUOTAS; cnt++)
6330 @@ -1797,6 +1803,8 @@ void __dquot_free_space(struct inode *in
6331         struct dquot **dquots;
6332         int reserve = flags & DQUOT_SPACE_RESERVE, index;
6333  
6334 +       dl_free_space(inode, number);
6335 +
6336         if (!dquot_active(inode)) {
6337                 inode_decr_space(inode, number, reserve);
6338                 return;
6339 @@ -1841,6 +1849,8 @@ void dquot_free_inode(struct inode *inod
6340         struct dquot * const *dquots;
6341         int index;
6342  
6343 +       dl_free_inode(inode);
6344 +
6345         if (!dquot_active(inode))
6346                 return;
6347  
6348 diff -NurpP --minimal linux-4.4.110/fs/quota/quota.c linux-4.4.110-vs2.3.9/fs/quota/quota.c
6349 --- linux-4.4.110/fs/quota/quota.c      2016-07-05 04:12:34.000000000 +0000
6350 +++ linux-4.4.110-vs2.3.9/fs/quota/quota.c      2018-01-09 16:36:32.000000000 +0000
6351 @@ -8,6 +8,7 @@
6352  #include <linux/fs.h>
6353  #include <linux/namei.h>
6354  #include <linux/slab.h>
6355 +#include <linux/vs_context.h>
6356  #include <asm/current.h>
6357  #include <linux/uaccess.h>
6358  #include <linux/kernel.h>
6359 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6360                         break;
6361                 /*FALLTHROUGH*/
6362         default:
6363 -               if (!capable(CAP_SYS_ADMIN))
6364 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6365                         return -EPERM;
6366         }
6367  
6368 @@ -702,6 +703,46 @@ static int do_quotactl(struct super_bloc
6369  
6370  #ifdef CONFIG_BLOCK
6371  
6372 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6373 +
6374 +#include <linux/vroot.h>
6375 +#include <linux/major.h>
6376 +#include <linux/module.h>
6377 +#include <linux/kallsyms.h>
6378 +#include <linux/vserver/debug.h>
6379 +
6380 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6381 +
6382 +static DEFINE_SPINLOCK(vroot_grb_lock);
6383 +
6384 +int register_vroot_grb(vroot_grb_func *func) {
6385 +       int ret = -EBUSY;
6386 +
6387 +       spin_lock(&vroot_grb_lock);
6388 +       if (!vroot_get_real_bdev) {
6389 +               vroot_get_real_bdev = func;
6390 +               ret = 0;
6391 +       }
6392 +       spin_unlock(&vroot_grb_lock);
6393 +       return ret;
6394 +}
6395 +EXPORT_SYMBOL(register_vroot_grb);
6396 +
6397 +int unregister_vroot_grb(vroot_grb_func *func) {
6398 +       int ret = -EINVAL;
6399 +
6400 +       spin_lock(&vroot_grb_lock);
6401 +       if (vroot_get_real_bdev) {
6402 +               vroot_get_real_bdev = NULL;
6403 +               ret = 0;
6404 +       }
6405 +       spin_unlock(&vroot_grb_lock);
6406 +       return ret;
6407 +}
6408 +EXPORT_SYMBOL(unregister_vroot_grb);
6409 +
6410 +#endif
6411 +
6412  /* Return 1 if 'cmd' will block on frozen filesystem */
6413  static int quotactl_cmd_write(int cmd)
6414  {
6415 @@ -737,6 +778,22 @@ static struct super_block *quotactl_bloc
6416         putname(tmp);
6417         if (IS_ERR(bdev))
6418                 return ERR_CAST(bdev);
6419 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6420 +       if (bdev && bdev->bd_inode &&
6421 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6422 +               struct block_device *bdnew = (void *)-EINVAL;
6423 +
6424 +               if (vroot_get_real_bdev)
6425 +                       bdnew = vroot_get_real_bdev(bdev);
6426 +               else
6427 +                       vxdprintk(VXD_CBIT(misc, 0),
6428 +                                       "vroot_get_real_bdev not set");
6429 +               bdput(bdev);
6430 +               if (IS_ERR(bdnew))
6431 +                       return ERR_PTR(PTR_ERR(bdnew));
6432 +               bdev = bdnew;
6433 +       }
6434 +#endif
6435         if (quotactl_cmd_write(cmd))
6436                 sb = get_super_thawed(bdev);
6437         else
6438 diff -NurpP --minimal linux-4.4.110/fs/stat.c linux-4.4.110-vs2.3.9/fs/stat.c
6439 --- linux-4.4.110/fs/stat.c     2018-01-09 16:35:08.000000000 +0000
6440 +++ linux-4.4.110-vs2.3.9/fs/stat.c     2018-01-09 16:36:32.000000000 +0000
6441 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6442         stat->nlink = inode->i_nlink;
6443         stat->uid = inode->i_uid;
6444         stat->gid = inode->i_gid;
6445 +       stat->tag = inode->i_tag;
6446         stat->rdev = inode->i_rdev;
6447         stat->size = i_size_read(inode);
6448         stat->atime = inode->i_atime;
6449 diff -NurpP --minimal linux-4.4.110/fs/statfs.c linux-4.4.110-vs2.3.9/fs/statfs.c
6450 --- linux-4.4.110/fs/statfs.c   2015-04-12 22:12:50.000000000 +0000
6451 +++ linux-4.4.110-vs2.3.9/fs/statfs.c   2018-01-09 16:36:32.000000000 +0000
6452 @@ -7,6 +7,8 @@
6453  #include <linux/statfs.h>
6454  #include <linux/security.h>
6455  #include <linux/uaccess.h>
6456 +#include <linux/vs_base.h>
6457 +#include <linux/vs_dlimit.h>
6458  #include "internal.h"
6459  
6460  static int flags_by_mnt(int mnt_flags)
6461 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6462         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6463         if (retval == 0 && buf->f_frsize == 0)
6464                 buf->f_frsize = buf->f_bsize;
6465 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6466 +               vx_vsi_statfs(dentry->d_sb, buf);
6467         return retval;
6468  }
6469  
6470 diff -NurpP --minimal linux-4.4.110/fs/super.c linux-4.4.110-vs2.3.9/fs/super.c
6471 --- linux-4.4.110/fs/super.c    2018-01-09 16:35:08.000000000 +0000
6472 +++ linux-4.4.110-vs2.3.9/fs/super.c    2018-01-09 16:36:32.000000000 +0000
6473 @@ -33,6 +33,8 @@
6474  #include <linux/cleancache.h>
6475  #include <linux/fsnotify.h>
6476  #include <linux/lockdep.h>
6477 +#include <linux/magic.h>
6478 +#include <linux/vs_context.h>
6479  #include "internal.h"
6480  
6481  
6482 @@ -1131,6 +1133,13 @@ mount_fs(struct file_system_type *type,
6483         WARN_ON(!sb->s_bdi);
6484         sb->s_flags |= MS_BORN;
6485  
6486 +       error = -EPERM;
6487 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6488 +               !sb->s_bdev &&
6489 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6490 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6491 +               goto out_sb;
6492 +
6493         error = security_sb_kern_mount(sb, flags, secdata);
6494         if (error)
6495                 goto out_sb;
6496 diff -NurpP --minimal linux-4.4.110/fs/utimes.c linux-4.4.110-vs2.3.9/fs/utimes.c
6497 --- linux-4.4.110/fs/utimes.c   2018-01-09 16:35:08.000000000 +0000
6498 +++ linux-4.4.110-vs2.3.9/fs/utimes.c   2018-01-09 16:36:32.000000000 +0000
6499 @@ -8,6 +8,8 @@
6500  #include <linux/stat.h>
6501  #include <linux/utime.h>
6502  #include <linux/syscalls.h>
6503 +#include <linux/mount.h>
6504 +#include <linux/vs_cowbl.h>
6505  #include <asm/uaccess.h>
6506  #include <asm/unistd.h>
6507  
6508 @@ -52,13 +54,19 @@ static int utimes_common(struct path *pa
6509  {
6510         int error;
6511         struct iattr newattrs;
6512 -       struct inode *inode = path->dentry->d_inode;
6513         struct inode *delegated_inode = NULL;
6514 +       struct inode *inode;
6515 +
6516 +       error = cow_check_and_break(path);
6517 +       if (error)
6518 +               goto out;
6519  
6520         error = mnt_want_write(path->mnt);
6521         if (error)
6522                 goto out;
6523  
6524 +       inode = path->dentry->d_inode;
6525 +
6526         if (times && times[0].tv_nsec == UTIME_NOW &&
6527                      times[1].tv_nsec == UTIME_NOW)
6528                 times = NULL;
6529 diff -NurpP --minimal linux-4.4.110/fs/xattr.c linux-4.4.110-vs2.3.9/fs/xattr.c
6530 --- linux-4.4.110/fs/xattr.c    2018-01-09 16:35:08.000000000 +0000
6531 +++ linux-4.4.110-vs2.3.9/fs/xattr.c    2018-01-09 16:36:32.000000000 +0000
6532 @@ -21,6 +21,7 @@
6533  #include <linux/audit.h>
6534  #include <linux/vmalloc.h>
6535  #include <linux/posix_acl_xattr.h>
6536 +#include <linux/mount.h>
6537  
6538  #include <asm/uaccess.h>
6539  
6540 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6541          * The trusted.* namespace can only be accessed by privileged users.
6542          */
6543         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6544 -               if (!capable(CAP_SYS_ADMIN))
6545 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6546                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6547                 return 0;
6548         }
6549 diff -NurpP --minimal linux-4.4.110/include/linux/capability.h linux-4.4.110-vs2.3.9/include/linux/capability.h
6550 --- linux-4.4.110/include/linux/capability.h    2018-01-09 16:35:09.000000000 +0000
6551 +++ linux-4.4.110-vs2.3.9/include/linux/capability.h    2018-01-09 16:36:32.000000000 +0000
6552 @@ -77,7 +77,8 @@ extern const kernel_cap_t __cap_init_eff
6553  #else /* HAND-CODED capability initializers */
6554  
6555  #define CAP_LAST_U32                   ((_KERNEL_CAPABILITY_U32S) - 1)
6556 -#define CAP_LAST_U32_VALID_MASK                (CAP_TO_MASK(CAP_LAST_CAP + 1) -1)
6557 +#define CAP_LAST_U32_VALID_MASK                ((CAP_TO_MASK(CAP_LAST_CAP + 1) -1) \
6558 +                                       | CAP_TO_MASK(CAP_CONTEXT))
6559  
6560  # define CAP_EMPTY_SET    ((kernel_cap_t){{ 0, 0 }})
6561  # define CAP_FULL_SET     ((kernel_cap_t){{ ~0, CAP_LAST_U32_VALID_MASK }})
6562 diff -NurpP --minimal linux-4.4.110/include/linux/cred.h linux-4.4.110-vs2.3.9/include/linux/cred.h
6563 --- linux-4.4.110/include/linux/cred.h  2018-01-09 16:35:09.000000000 +0000
6564 +++ linux-4.4.110-vs2.3.9/include/linux/cred.h  2018-01-09 16:36:32.000000000 +0000
6565 @@ -160,6 +160,7 @@ extern void exit_creds(struct task_struc
6566  extern int copy_creds(struct task_struct *, unsigned long);
6567  extern const struct cred *get_task_cred(struct task_struct *);
6568  extern struct cred *cred_alloc_blank(void);
6569 +extern struct cred *__prepare_creds(const struct cred *);
6570  extern struct cred *prepare_creds(void);
6571  extern struct cred *prepare_exec_creds(void);
6572  extern int commit_creds(struct cred *);
6573 @@ -220,6 +221,31 @@ static inline bool cap_ambient_invariant
6574                                           cred->cap_inheritable));
6575  }
6576  
6577 +static inline void set_cred_subscribers(struct cred *cred, int n)
6578 +{
6579 +#ifdef CONFIG_DEBUG_CREDENTIALS
6580 +       atomic_set(&cred->subscribers, n);
6581 +#endif
6582 +}
6583 +
6584 +static inline int read_cred_subscribers(const struct cred *cred)
6585 +{
6586 +#ifdef CONFIG_DEBUG_CREDENTIALS
6587 +       return atomic_read(&cred->subscribers);
6588 +#else
6589 +       return 0;
6590 +#endif
6591 +}
6592 +
6593 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
6594 +{
6595 +#ifdef CONFIG_DEBUG_CREDENTIALS
6596 +       struct cred *cred = (struct cred *) _cred;
6597 +
6598 +       atomic_add(n, &cred->subscribers);
6599 +#endif
6600 +}
6601 +
6602  /**
6603   * get_new_cred - Get a reference on a new set of credentials
6604   * @cred: The new credentials to reference
6605 diff -NurpP --minimal linux-4.4.110/include/linux/dcache.h linux-4.4.110-vs2.3.9/include/linux/dcache.h
6606 --- linux-4.4.110/include/linux/dcache.h        2018-01-09 16:35:09.000000000 +0000
6607 +++ linux-4.4.110-vs2.3.9/include/linux/dcache.h        2018-01-09 16:36:32.000000000 +0000
6608 @@ -10,6 +10,7 @@
6609  #include <linux/cache.h>
6610  #include <linux/rcupdate.h>
6611  #include <linux/lockref.h>
6612 +// #include <linux/vs_limit.h>
6613  
6614  struct path;
6615  struct vfsmount;
6616 @@ -351,8 +352,10 @@ extern char *dentry_path(struct dentry *
6617   */
6618  static inline struct dentry *dget_dlock(struct dentry *dentry)
6619  {
6620 -       if (dentry)
6621 +       if (dentry) {
6622                 dentry->d_lockref.count++;
6623 +               // vx_dentry_inc(dentry);
6624 +       }
6625         return dentry;
6626  }
6627  
6628 diff -NurpP --minimal linux-4.4.110/include/linux/devpts_fs.h linux-4.4.110-vs2.3.9/include/linux/devpts_fs.h
6629 --- linux-4.4.110/include/linux/devpts_fs.h     2018-01-09 16:35:09.000000000 +0000
6630 +++ linux-4.4.110-vs2.3.9/include/linux/devpts_fs.h     2018-01-09 16:36:32.000000000 +0000
6631 @@ -35,5 +35,4 @@ void devpts_pty_kill(struct inode *inode
6632  
6633  #endif
6634  
6635 -
6636  #endif /* _LINUX_DEVPTS_FS_H */
6637 diff -NurpP --minimal linux-4.4.110/include/linux/fs.h linux-4.4.110-vs2.3.9/include/linux/fs.h
6638 --- linux-4.4.110/include/linux/fs.h    2018-01-09 16:35:09.000000000 +0000
6639 +++ linux-4.4.110-vs2.3.9/include/linux/fs.h    2018-01-09 16:43:56.000000000 +0000
6640 @@ -227,6 +227,7 @@ typedef void (dax_iodone_t)(struct buffe
6641  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
6642  #define ATTR_TIMES_SET (1 << 16)
6643  #define ATTR_TOUCH     (1 << 17)
6644 +#define ATTR_TAG       (1 << 18)
6645  
6646  /*
6647   * Whiteout is represented by a char device.  The following constants define the
6648 @@ -249,6 +250,7 @@ struct iattr {
6649         umode_t         ia_mode;
6650         kuid_t          ia_uid;
6651         kgid_t          ia_gid;
6652 +       ktag_t          ia_tag;
6653         loff_t          ia_size;
6654         struct timespec ia_atime;
6655         struct timespec ia_mtime;
6656 @@ -587,7 +589,9 @@ struct inode {
6657         unsigned short          i_opflags;
6658         kuid_t                  i_uid;
6659         kgid_t                  i_gid;
6660 -       unsigned int            i_flags;
6661 +       ktag_t                  i_tag;
6662 +       unsigned short          i_flags;
6663 +       unsigned short          i_vflags;
6664  
6665  #ifdef CONFIG_FS_POSIX_ACL
6666         struct posix_acl        *i_acl;
6667 @@ -616,6 +620,7 @@ struct inode {
6668                 unsigned int __i_nlink;
6669         };
6670         dev_t                   i_rdev;
6671 +       dev_t                   i_mdev;
6672         loff_t                  i_size;
6673         struct timespec         i_atime;
6674         struct timespec         i_mtime;
6675 @@ -814,6 +819,11 @@ static inline gid_t i_gid_read(const str
6676         return from_kgid(&init_user_ns, inode->i_gid);
6677  }
6678  
6679 +static inline vtag_t i_tag_read(const struct inode *inode)
6680 +{
6681 +       return from_ktag(&init_user_ns, inode->i_tag);
6682 +}
6683 +
6684  static inline void i_uid_write(struct inode *inode, uid_t uid)
6685  {
6686         inode->i_uid = make_kuid(&init_user_ns, uid);
6687 @@ -824,14 +834,19 @@ static inline void i_gid_write(struct in
6688         inode->i_gid = make_kgid(&init_user_ns, gid);
6689  }
6690  
6691 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
6692 +{
6693 +       inode->i_tag = make_ktag(&init_user_ns, tag);
6694 +}
6695 +
6696  static inline unsigned iminor(const struct inode *inode)
6697  {
6698 -       return MINOR(inode->i_rdev);
6699 +       return MINOR(inode->i_mdev);
6700  }
6701  
6702  static inline unsigned imajor(const struct inode *inode)
6703  {
6704 -       return MAJOR(inode->i_rdev);
6705 +       return MAJOR(inode->i_mdev);
6706  }
6707  
6708  extern struct block_device *I_BDEV(struct inode *inode);
6709 @@ -888,6 +903,7 @@ struct file {
6710         loff_t                  f_pos;
6711         struct fown_struct      f_owner;
6712         const struct cred       *f_cred;
6713 +       vxid_t                  f_xid;
6714         struct file_ra_state    f_ra;
6715  
6716         u64                     f_version;
6717 @@ -1022,6 +1038,7 @@ struct file_lock {
6718         struct file *fl_file;
6719         loff_t fl_start;
6720         loff_t fl_end;
6721 +       vxid_t fl_xid;
6722  
6723         struct fasync_struct *  fl_fasync; /* for lease break notifications */
6724         /* for lease breaks: */
6725 @@ -1698,6 +1715,7 @@ struct inode_operations {
6726         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
6727         ssize_t (*listxattr) (struct dentry *, char *, size_t);
6728         int (*removexattr) (struct dentry *, const char *);
6729 +       int (*sync_flags) (struct inode *, int, int);
6730         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
6731                       u64 len);
6732         int (*update_time)(struct inode *, struct timespec *, int);
6733 @@ -1712,6 +1730,7 @@ ssize_t rw_copy_check_uvector(int type,
6734                               unsigned long nr_segs, unsigned long fast_segs,
6735                               struct iovec *fast_pointer,
6736                               struct iovec **ret_pointer);
6737 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
6738  
6739  extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
6740  extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *);
6741 @@ -1777,6 +1796,14 @@ struct super_operations {
6742  #else
6743  #define S_DAX          0       /* Make all the DAX code disappear */
6744  #endif
6745 +#define S_IXUNLINK     16384   /* Immutable Invert on unlink */
6746 +
6747 +/* Linux-VServer related Inode flags */
6748 +
6749 +#define V_VALID                1
6750 +#define V_XATTR                2
6751 +#define V_BARRIER      4       /* Barrier for chroot() */
6752 +#define V_COW          8       /* Copy on Write */
6753  
6754  /*
6755   * Note that nosuid etc flags are inode-specific: setting some file-system
6756 @@ -1801,10 +1828,13 @@ struct super_operations {
6757  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
6758  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
6759  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
6760 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
6761  
6762  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
6763  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
6764  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
6765 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
6766 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
6767  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
6768  
6769  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
6770 @@ -1819,6 +1849,16 @@ struct super_operations {
6771  #define IS_WHITEOUT(inode)     (S_ISCHR(inode->i_mode) && \
6772                                  (inode)->i_rdev == WHITEOUT_DEV)
6773  
6774 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
6775 +
6776 +#ifdef CONFIG_VSERVER_COWBL
6777 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
6778 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
6779 +#else
6780 +#  define IS_COW(inode)                (0)
6781 +#  define IS_COW_LINK(inode)   (0)
6782 +#endif
6783 +
6784  /*
6785   * Inode state bits.  Protected by inode->i_lock
6786   *
6787 @@ -2075,6 +2115,9 @@ extern struct kobject *fs_kobj;
6788  extern int locks_mandatory_locked(struct file *);
6789  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
6790  
6791 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
6792 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
6793 +
6794  /*
6795   * Candidates for mandatory locking have the setgid bit set
6796   * but no group execute bit -  an otherwise meaningless combination.
6797 @@ -2830,6 +2873,7 @@ extern int dcache_dir_open(struct inode
6798  extern int dcache_dir_close(struct inode *, struct file *);
6799  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
6800  extern int dcache_readdir(struct file *, struct dir_context *);
6801 +extern int dcache_readdir_filter(struct file *, struct dir_context *, int (*)(struct dentry *));
6802  extern int simple_setattr(struct dentry *, struct iattr *);
6803  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
6804  extern int simple_statfs(struct dentry *, struct kstatfs *);
6805 diff -NurpP --minimal linux-4.4.110/include/linux/init_task.h linux-4.4.110-vs2.3.9/include/linux/init_task.h
6806 --- linux-4.4.110/include/linux/init_task.h     2016-07-05 04:15:10.000000000 +0000
6807 +++ linux-4.4.110-vs2.3.9/include/linux/init_task.h     2018-01-09 16:36:32.000000000 +0000
6808 @@ -260,6 +260,10 @@ extern struct task_group root_task_group
6809         INIT_VTIME(tsk)                                                 \
6810         INIT_NUMA_BALANCING(tsk)                                        \
6811         INIT_KASAN(tsk)                                                 \
6812 +       .xid            = 0,                                            \
6813 +       .vx_info        = NULL,                                         \
6814 +       .nid            = 0,                                            \
6815 +       .nx_info        = NULL,                                         \
6816  }
6817  
6818  
6819 diff -NurpP --minimal linux-4.4.110/include/linux/ipc.h linux-4.4.110-vs2.3.9/include/linux/ipc.h
6820 --- linux-4.4.110/include/linux/ipc.h   2015-04-12 22:12:50.000000000 +0000
6821 +++ linux-4.4.110-vs2.3.9/include/linux/ipc.h   2018-01-09 16:36:32.000000000 +0000
6822 @@ -16,6 +16,7 @@ struct kern_ipc_perm
6823         key_t           key;
6824         kuid_t          uid;
6825         kgid_t          gid;
6826 +       vxid_t          xid;
6827         kuid_t          cuid;
6828         kgid_t          cgid;
6829         umode_t         mode; 
6830 diff -NurpP --minimal linux-4.4.110/include/linux/memcontrol.h linux-4.4.110-vs2.3.9/include/linux/memcontrol.h
6831 --- linux-4.4.110/include/linux/memcontrol.h    2018-01-09 16:35:09.000000000 +0000
6832 +++ linux-4.4.110-vs2.3.9/include/linux/memcontrol.h    2018-01-09 16:36:32.000000000 +0000
6833 @@ -113,6 +113,7 @@ struct cg_proto {
6834         struct mem_cgroup       *memcg;
6835  };
6836  
6837 +
6838  #ifdef CONFIG_MEMCG
6839  struct mem_cgroup_stat_cpu {
6840         long count[MEM_CGROUP_STAT_NSTATS];
6841 @@ -338,6 +339,11 @@ static inline bool mem_cgroup_is_descend
6842         return cgroup_is_descendant(memcg->css.cgroup, root->css.cgroup);
6843  }
6844  
6845 +extern u64 mem_cgroup_mem_usage_pages(struct mem_cgroup *memcg);
6846 +extern u64 mem_cgroup_mem_limit_pages(struct mem_cgroup *memcg);
6847 +extern u64 mem_cgroup_memsw_usage_pages(struct mem_cgroup *memcg);
6848 +extern u64 mem_cgroup_memsw_limit_pages(struct mem_cgroup *memcg);
6849 +
6850  static inline bool mm_match_cgroup(struct mm_struct *mm,
6851                                    struct mem_cgroup *memcg)
6852  {
6853 diff -NurpP --minimal linux-4.4.110/include/linux/mount.h linux-4.4.110-vs2.3.9/include/linux/mount.h
6854 --- linux-4.4.110/include/linux/mount.h 2018-01-09 16:35:09.000000000 +0000
6855 +++ linux-4.4.110-vs2.3.9/include/linux/mount.h 2018-01-09 16:36:32.000000000 +0000
6856 @@ -63,6 +63,9 @@ struct mnt_namespace;
6857  #define MNT_MARKED             0x4000000
6858  #define MNT_UMOUNT             0x8000000
6859  
6860 +#define MNT_TAGID      0x10000
6861 +#define MNT_NOTAG      0x20000
6862 +
6863  struct vfsmount {
6864         struct dentry *mnt_root;        /* root of the mounted tree */
6865         struct super_block *mnt_sb;     /* pointer to superblock */
6866 diff -NurpP --minimal linux-4.4.110/include/linux/net.h linux-4.4.110-vs2.3.9/include/linux/net.h
6867 --- linux-4.4.110/include/linux/net.h   2018-01-09 16:35:09.000000000 +0000
6868 +++ linux-4.4.110-vs2.3.9/include/linux/net.h   2018-01-09 16:42:30.000000000 +0000
6869 @@ -43,6 +43,7 @@ struct net;
6870  #define SOCK_NOSPACE           2
6871  #define SOCK_PASSCRED          3
6872  #define SOCK_PASSSEC           4
6873 +#define SOCK_USER_SOCKET       5
6874  
6875  #ifndef ARCH_HAS_SOCKET_TYPES
6876  /**
6877 diff -NurpP --minimal linux-4.4.110/include/linux/netdevice.h linux-4.4.110-vs2.3.9/include/linux/netdevice.h
6878 --- linux-4.4.110/include/linux/netdevice.h     2018-01-09 16:35:09.000000000 +0000
6879 +++ linux-4.4.110-vs2.3.9/include/linux/netdevice.h     2018-01-09 16:36:32.000000000 +0000
6880 @@ -2296,6 +2296,7 @@ static inline int dev_recursion_level(vo
6881  
6882  struct net_device *dev_get_by_index(struct net *net, int ifindex);
6883  struct net_device *__dev_get_by_index(struct net *net, int ifindex);
6884 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
6885  struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
6886  int netdev_get_name(struct net *net, char *name, int ifindex);
6887  int dev_restart(struct net_device *dev);
6888 diff -NurpP --minimal linux-4.4.110/include/linux/nsproxy.h linux-4.4.110-vs2.3.9/include/linux/nsproxy.h
6889 --- linux-4.4.110/include/linux/nsproxy.h       2015-04-12 22:12:50.000000000 +0000
6890 +++ linux-4.4.110-vs2.3.9/include/linux/nsproxy.h       2018-01-09 16:36:32.000000000 +0000
6891 @@ -3,6 +3,7 @@
6892  
6893  #include <linux/spinlock.h>
6894  #include <linux/sched.h>
6895 +#include <linux/vserver/debug.h>
6896  
6897  struct mnt_namespace;
6898  struct uts_namespace;
6899 @@ -63,6 +64,7 @@ extern struct nsproxy init_nsproxy;
6900   */
6901  
6902  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
6903 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
6904  void exit_task_namespaces(struct task_struct *tsk);
6905  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
6906  void free_nsproxy(struct nsproxy *ns);
6907 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
6908         struct cred *, struct fs_struct *);
6909  int __init nsproxy_cache_init(void);
6910  
6911 -static inline void put_nsproxy(struct nsproxy *ns)
6912 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
6913 +
6914 +static inline void __get_nsproxy(struct nsproxy *ns,
6915 +       const char *_file, int _line)
6916  {
6917 -       if (atomic_dec_and_test(&ns->count)) {
6918 -               free_nsproxy(ns);
6919 -       }
6920 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
6921 +               ns, atomic_read(&ns->count), _file, _line);
6922 +       atomic_inc(&ns->count);
6923  }
6924  
6925 -static inline void get_nsproxy(struct nsproxy *ns)
6926 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
6927 +
6928 +static inline void __put_nsproxy(struct nsproxy *ns,
6929 +       const char *_file, int _line)
6930  {
6931 -       atomic_inc(&ns->count);
6932 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
6933 +               ns, atomic_read(&ns->count), _file, _line);
6934 +       if (atomic_dec_and_test(&ns->count)) {
6935 +               free_nsproxy(ns);
6936 +       }
6937  }
6938  
6939  #endif
6940 diff -NurpP --minimal linux-4.4.110/include/linux/pid.h linux-4.4.110-vs2.3.9/include/linux/pid.h
6941 --- linux-4.4.110/include/linux/pid.h   2018-01-09 16:35:09.000000000 +0000
6942 +++ linux-4.4.110-vs2.3.9/include/linux/pid.h   2018-01-09 16:45:21.000000000 +0000
6943 @@ -10,7 +10,8 @@ enum pid_type
6944         PIDTYPE_SID,
6945         PIDTYPE_MAX,
6946         /* only valid to __task_pid_nr_ns() */
6947 -       __PIDTYPE_TGID
6948 +       __PIDTYPE_TGID,
6949 +       __PIDTYPE_REALPID
6950  };
6951  
6952  /*
6953 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
6954  }
6955  
6956  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
6957 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
6958  pid_t pid_vnr(struct pid *pid);
6959  
6960  #define do_each_pid_task(pid, type, task)                              \
6961 diff -NurpP --minimal linux-4.4.110/include/linux/quotaops.h linux-4.4.110-vs2.3.9/include/linux/quotaops.h
6962 --- linux-4.4.110/include/linux/quotaops.h      2016-07-05 04:12:37.000000000 +0000
6963 +++ linux-4.4.110-vs2.3.9/include/linux/quotaops.h      2018-01-09 16:36:32.000000000 +0000
6964 @@ -8,6 +8,7 @@
6965  #define _LINUX_QUOTAOPS_
6966  
6967  #include <linux/fs.h>
6968 +#include <linux/vs_dlimit.h>
6969  
6970  #define DQUOT_SPACE_WARN       0x1
6971  #define DQUOT_SPACE_RESERVE    0x2
6972 @@ -211,11 +212,12 @@ static inline void dquot_drop(struct ino
6973  
6974  static inline int dquot_alloc_inode(struct inode *inode)
6975  {
6976 -       return 0;
6977 +       return dl_alloc_inode(inode);
6978  }
6979  
6980  static inline void dquot_free_inode(struct inode *inode)
6981  {
6982 +       dl_free_inode(inode);
6983  }
6984  
6985  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
6986 @@ -226,6 +228,10 @@ static inline int dquot_transfer(struct
6987  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
6988                 int flags)
6989  {
6990 +       int ret = 0;
6991 +
6992 +       if ((ret = dl_alloc_space(inode, number)))
6993 +               return ret;
6994         if (!(flags & DQUOT_SPACE_RESERVE))
6995                 inode_add_bytes(inode, number);
6996         return 0;
6997 @@ -236,6 +242,7 @@ static inline void __dquot_free_space(st
6998  {
6999         if (!(flags & DQUOT_SPACE_RESERVE))
7000                 inode_sub_bytes(inode, number);
7001 +       dl_free_space(inode, number);
7002  }
7003  
7004  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7005 diff -NurpP --minimal linux-4.4.110/include/linux/sched.h linux-4.4.110-vs2.3.9/include/linux/sched.h
7006 --- linux-4.4.110/include/linux/sched.h 2018-01-09 16:35:09.000000000 +0000
7007 +++ linux-4.4.110-vs2.3.9/include/linux/sched.h 2018-01-09 16:36:32.000000000 +0000
7008 @@ -1600,6 +1600,14 @@ struct task_struct {
7009  #endif
7010         struct seccomp seccomp;
7011  
7012 +/* vserver context data */
7013 +       struct vx_info *vx_info;
7014 +       struct nx_info *nx_info;
7015 +
7016 +       vxid_t xid;
7017 +       vnid_t nid;
7018 +       vtag_t tag;
7019 +
7020  /* Thread group tracking */
7021         u32 parent_exec_id;
7022         u32 self_exec_id;
7023 @@ -1927,6 +1935,11 @@ struct pid_namespace;
7024  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
7025                         struct pid_namespace *ns);
7026  
7027 +#include <linux/vserver/base.h>
7028 +#include <linux/vserver/context.h>
7029 +#include <linux/vserver/debug.h>
7030 +#include <linux/vserver/pid.h>
7031 +
7032  static inline pid_t task_pid_nr(struct task_struct *tsk)
7033  {
7034         return tsk->pid;
7035 @@ -1940,7 +1953,8 @@ static inline pid_t task_pid_nr_ns(struc
7036  
7037  static inline pid_t task_pid_vnr(struct task_struct *tsk)
7038  {
7039 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7040 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7041 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
7042  }
7043  
7044  
7045 diff -NurpP --minimal linux-4.4.110/include/linux/shmem_fs.h linux-4.4.110-vs2.3.9/include/linux/shmem_fs.h
7046 --- linux-4.4.110/include/linux/shmem_fs.h      2018-01-09 16:35:09.000000000 +0000
7047 +++ linux-4.4.110-vs2.3.9/include/linux/shmem_fs.h      2018-01-09 16:36:32.000000000 +0000
7048 @@ -10,6 +10,9 @@
7049  
7050  /* inode in-kernel data */
7051  
7052 +#define TMPFS_SUPER_MAGIC      0x01021994
7053 +
7054 +
7055  struct shmem_inode_info {
7056         spinlock_t              lock;
7057         unsigned int            seals;          /* shmem seals */
7058 diff -NurpP --minimal linux-4.4.110/include/linux/stat.h linux-4.4.110-vs2.3.9/include/linux/stat.h
7059 --- linux-4.4.110/include/linux/stat.h  2015-04-12 22:12:50.000000000 +0000
7060 +++ linux-4.4.110-vs2.3.9/include/linux/stat.h  2018-01-09 16:36:32.000000000 +0000
7061 @@ -25,6 +25,7 @@ struct kstat {
7062         unsigned int    nlink;
7063         kuid_t          uid;
7064         kgid_t          gid;
7065 +       ktag_t          tag;
7066         dev_t           rdev;
7067         loff_t          size;
7068         struct timespec  atime;
7069 diff -NurpP --minimal linux-4.4.110/include/linux/sunrpc/auth.h linux-4.4.110-vs2.3.9/include/linux/sunrpc/auth.h
7070 --- linux-4.4.110/include/linux/sunrpc/auth.h   2016-07-05 04:12:37.000000000 +0000
7071 +++ linux-4.4.110-vs2.3.9/include/linux/sunrpc/auth.h   2018-01-09 16:36:32.000000000 +0000
7072 @@ -40,6 +40,7 @@ enum {
7073  struct auth_cred {
7074         kuid_t  uid;
7075         kgid_t  gid;
7076 +       ktag_t  tag;
7077         struct group_info *group_info;
7078         const char *principal;
7079         unsigned long ac_flags;
7080 diff -NurpP --minimal linux-4.4.110/include/linux/sunrpc/clnt.h linux-4.4.110-vs2.3.9/include/linux/sunrpc/clnt.h
7081 --- linux-4.4.110/include/linux/sunrpc/clnt.h   2018-01-09 16:35:09.000000000 +0000
7082 +++ linux-4.4.110-vs2.3.9/include/linux/sunrpc/clnt.h   2018-01-09 16:36:32.000000000 +0000
7083 @@ -51,7 +51,8 @@ struct rpc_clnt {
7084                                 cl_discrtry : 1,/* disconnect before retry */
7085                                 cl_noretranstimeo: 1,/* No retransmit timeouts */
7086                                 cl_autobind : 1,/* use getport() */
7087 -                               cl_chatty   : 1;/* be verbose */
7088 +                               cl_chatty   : 1,/* be verbose */
7089 +                               cl_tag      : 1;/* context tagging */
7090  
7091         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
7092         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
7093 diff -NurpP --minimal linux-4.4.110/include/linux/types.h linux-4.4.110-vs2.3.9/include/linux/types.h
7094 --- linux-4.4.110/include/linux/types.h 2016-07-05 04:15:11.000000000 +0000
7095 +++ linux-4.4.110-vs2.3.9/include/linux/types.h 2018-01-09 16:36:32.000000000 +0000
7096 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
7097  typedef __kernel_gid32_t       gid_t;
7098  typedef __kernel_uid16_t        uid16_t;
7099  typedef __kernel_gid16_t        gid16_t;
7100 +typedef unsigned int           vxid_t;
7101 +typedef unsigned int           vnid_t;
7102 +typedef unsigned int           vtag_t;
7103  
7104  typedef unsigned long          uintptr_t;
7105  
7106 diff -NurpP --minimal linux-4.4.110/include/linux/uidgid.h linux-4.4.110-vs2.3.9/include/linux/uidgid.h
7107 --- linux-4.4.110/include/linux/uidgid.h        2015-07-06 20:41:43.000000000 +0000
7108 +++ linux-4.4.110-vs2.3.9/include/linux/uidgid.h        2018-01-09 16:36:32.000000000 +0000
7109 @@ -21,13 +21,17 @@ typedef struct {
7110         uid_t val;
7111  } kuid_t;
7112  
7113 -
7114  typedef struct {
7115         gid_t val;
7116  } kgid_t;
7117  
7118 +typedef struct {
7119 +       vtag_t val;
7120 +} ktag_t;
7121 +
7122  #define KUIDT_INIT(value) (kuid_t){ value }
7123  #define KGIDT_INIT(value) (kgid_t){ value }
7124 +#define KTAGT_INIT(value) (ktag_t){ value }
7125  
7126  #ifdef CONFIG_MULTIUSER
7127  static inline uid_t __kuid_val(kuid_t uid)
7128 @@ -51,11 +55,18 @@ static inline gid_t __kgid_val(kgid_t gi
7129  }
7130  #endif
7131  
7132 +static inline vtag_t __ktag_val(ktag_t tag)
7133 +{
7134 +       return tag.val;
7135 +}
7136 +
7137  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
7138  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
7139 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
7140  
7141  #define INVALID_UID KUIDT_INIT(-1)
7142  #define INVALID_GID KGIDT_INIT(-1)
7143 +#define INVALID_TAG KTAGT_INIT(-1)
7144  
7145  static inline bool uid_eq(kuid_t left, kuid_t right)
7146  {
7147 @@ -67,6 +78,11 @@ static inline bool gid_eq(kgid_t left, k
7148         return __kgid_val(left) == __kgid_val(right);
7149  }
7150  
7151 +static inline bool tag_eq(ktag_t left, ktag_t right)
7152 +{
7153 +       return __ktag_val(left) == __ktag_val(right);
7154 +}
7155 +
7156  static inline bool uid_gt(kuid_t left, kuid_t right)
7157  {
7158         return __kuid_val(left) > __kuid_val(right);
7159 @@ -117,13 +133,21 @@ static inline bool gid_valid(kgid_t gid)
7160         return __kgid_val(gid) != (gid_t) -1;
7161  }
7162  
7163 +static inline bool tag_valid(ktag_t tag)
7164 +{
7165 +       return !tag_eq(tag, INVALID_TAG);
7166 +}
7167 +
7168  #ifdef CONFIG_USER_NS
7169  
7170  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
7171  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
7172 +extern ktag_t make_ktag(struct user_namespace *from, gid_t gid);
7173  
7174  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
7175  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
7176 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
7177 +
7178  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
7179  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
7180  
7181 @@ -149,6 +173,11 @@ static inline kgid_t make_kgid(struct us
7182         return KGIDT_INIT(gid);
7183  }
7184  
7185 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
7186 +{
7187 +       return KTAGT_INIT(tag);
7188 +}
7189 +
7190  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
7191  {
7192         return __kuid_val(kuid);
7193 @@ -159,6 +188,11 @@ static inline gid_t from_kgid(struct use
7194         return __kgid_val(kgid);
7195  }
7196  
7197 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
7198 +{
7199 +       return __ktag_val(ktag);
7200 +}
7201 +
7202  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
7203  {
7204         uid_t uid = from_kuid(to, kuid);
7205 diff -NurpP --minimal linux-4.4.110/include/linux/vroot.h linux-4.4.110-vs2.3.9/include/linux/vroot.h
7206 --- linux-4.4.110/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
7207 +++ linux-4.4.110-vs2.3.9/include/linux/vroot.h 2018-01-09 16:36:32.000000000 +0000
7208 @@ -0,0 +1,51 @@
7209 +
7210 +/*
7211 + * include/linux/vroot.h
7212 + *
7213 + * written by Herbert P?tzl, 9/11/2002
7214 + * ported to 2.6 by Herbert P?tzl, 30/12/2004
7215 + *
7216 + * Copyright (C) 2002-2007 by Herbert P?tzl.
7217 + * Redistribution of this file is permitted under the
7218 + * GNU General Public License.
7219 + */
7220 +
7221 +#ifndef _LINUX_VROOT_H
7222 +#define _LINUX_VROOT_H
7223 +
7224 +
7225 +#ifdef __KERNEL__
7226 +
7227 +/* Possible states of device */
7228 +enum {
7229 +       Vr_unbound,
7230 +       Vr_bound,
7231 +};
7232 +
7233 +struct vroot_device {
7234 +       int             vr_number;
7235 +       int             vr_refcnt;
7236 +
7237 +       struct semaphore        vr_ctl_mutex;
7238 +       struct block_device    *vr_device;
7239 +       int                     vr_state;
7240 +};
7241 +
7242 +
7243 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
7244 +
7245 +extern int register_vroot_grb(vroot_grb_func *);
7246 +extern int unregister_vroot_grb(vroot_grb_func *);
7247 +
7248 +#endif /* __KERNEL__ */
7249 +
7250 +#define MAX_VROOT_DEFAULT      8
7251 +
7252 +/*
7253 + * IOCTL commands --- we will commandeer 0x56 ('V')
7254 + */
7255 +
7256 +#define VROOT_SET_DEV          0x5600
7257 +#define VROOT_CLR_DEV          0x5601
7258 +
7259 +#endif /* _LINUX_VROOT_H */
7260 diff -NurpP --minimal linux-4.4.110/include/linux/vs_base.h linux-4.4.110-vs2.3.9/include/linux/vs_base.h
7261 --- linux-4.4.110/include/linux/vs_base.h       1970-01-01 00:00:00.000000000 +0000
7262 +++ linux-4.4.110-vs2.3.9/include/linux/vs_base.h       2018-01-09 16:36:32.000000000 +0000
7263 @@ -0,0 +1,10 @@
7264 +#ifndef _VS_BASE_H
7265 +#define _VS_BASE_H
7266 +
7267 +#include "vserver/base.h"
7268 +#include "vserver/check.h"
7269 +#include "vserver/debug.h"
7270 +
7271 +#else
7272 +#warning duplicate inclusion
7273 +#endif
7274 diff -NurpP --minimal linux-4.4.110/include/linux/vs_context.h linux-4.4.110-vs2.3.9/include/linux/vs_context.h
7275 --- linux-4.4.110/include/linux/vs_context.h    1970-01-01 00:00:00.000000000 +0000
7276 +++ linux-4.4.110-vs2.3.9/include/linux/vs_context.h    2018-01-09 16:36:32.000000000 +0000
7277 @@ -0,0 +1,242 @@
7278 +#ifndef _VS_CONTEXT_H
7279 +#define _VS_CONTEXT_H
7280 +
7281 +#include "vserver/base.h"
7282 +#include "vserver/check.h"
7283 +#include "vserver/context.h"
7284 +#include "vserver/history.h"
7285 +#include "vserver/debug.h"
7286 +
7287 +#include <linux/sched.h>
7288 +
7289 +
7290 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
7291 +
7292 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
7293 +       const char *_file, int _line, void *_here)
7294 +{
7295 +       if (!vxi)
7296 +               return NULL;
7297 +
7298 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
7299 +               vxi, vxi ? vxi->vx_id : 0,
7300 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7301 +               _file, _line);
7302 +       __vxh_get_vx_info(vxi, _here);
7303 +
7304 +       atomic_inc(&vxi->vx_usecnt);
7305 +       return vxi;
7306 +}
7307 +
7308 +
7309 +extern void free_vx_info(struct vx_info *);
7310 +
7311 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
7312 +
7313 +static inline void __put_vx_info(struct vx_info *vxi,
7314 +       const char *_file, int _line, void *_here)
7315 +{
7316 +       if (!vxi)
7317 +               return;
7318 +
7319 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
7320 +               vxi, vxi ? vxi->vx_id : 0,
7321 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7322 +               _file, _line);
7323 +       __vxh_put_vx_info(vxi, _here);
7324 +
7325 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
7326 +               free_vx_info(vxi);
7327 +}
7328 +
7329 +
7330 +#define init_vx_info(p, i) \
7331 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7332 +
7333 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7334 +       const char *_file, int _line, void *_here)
7335 +{
7336 +       if (vxi) {
7337 +               vxlprintk(VXD_CBIT(xid, 3),
7338 +                       "init_vx_info(%p[#%d.%d])",
7339 +                       vxi, vxi ? vxi->vx_id : 0,
7340 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7341 +                       _file, _line);
7342 +               __vxh_init_vx_info(vxi, vxp, _here);
7343 +
7344 +               atomic_inc(&vxi->vx_usecnt);
7345 +       }
7346 +       *vxp = vxi;
7347 +}
7348 +
7349 +
7350 +#define set_vx_info(p, i) \
7351 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7352 +
7353 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7354 +       const char *_file, int _line, void *_here)
7355 +{
7356 +       struct vx_info *vxo;
7357 +
7358 +       if (!vxi)
7359 +               return;
7360 +
7361 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
7362 +               vxi, vxi ? vxi->vx_id : 0,
7363 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7364 +               _file, _line);
7365 +       __vxh_set_vx_info(vxi, vxp, _here);
7366 +
7367 +       atomic_inc(&vxi->vx_usecnt);
7368 +       vxo = xchg(vxp, vxi);
7369 +       BUG_ON(vxo);
7370 +}
7371 +
7372 +
7373 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
7374 +
7375 +static inline void __clr_vx_info(struct vx_info **vxp,
7376 +       const char *_file, int _line, void *_here)
7377 +{
7378 +       struct vx_info *vxo;
7379 +
7380 +       vxo = xchg(vxp, NULL);
7381 +       if (!vxo)
7382 +               return;
7383 +
7384 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
7385 +               vxo, vxo ? vxo->vx_id : 0,
7386 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
7387 +               _file, _line);
7388 +       __vxh_clr_vx_info(vxo, vxp, _here);
7389 +
7390 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
7391 +               free_vx_info(vxo);
7392 +}
7393 +
7394 +
7395 +#define claim_vx_info(v, p) \
7396 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7397 +
7398 +static inline void __claim_vx_info(struct vx_info *vxi,
7399 +       struct task_struct *task,
7400 +       const char *_file, int _line, void *_here)
7401 +{
7402 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
7403 +               vxi, vxi ? vxi->vx_id : 0,
7404 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7405 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7406 +               task, _file, _line);
7407 +       __vxh_claim_vx_info(vxi, task, _here);
7408 +
7409 +       atomic_inc(&vxi->vx_tasks);
7410 +}
7411 +
7412 +
7413 +extern void unhash_vx_info(struct vx_info *);
7414 +
7415 +#define release_vx_info(v, p) \
7416 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7417 +
7418 +static inline void __release_vx_info(struct vx_info *vxi,
7419 +       struct task_struct *task,
7420 +       const char *_file, int _line, void *_here)
7421 +{
7422 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
7423 +               vxi, vxi ? vxi->vx_id : 0,
7424 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7425 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7426 +               task, _file, _line);
7427 +       __vxh_release_vx_info(vxi, task, _here);
7428 +
7429 +       might_sleep();
7430 +
7431 +       if (atomic_dec_and_test(&vxi->vx_tasks))
7432 +               unhash_vx_info(vxi);
7433 +}
7434 +
7435 +
7436 +#define task_get_vx_info(p) \
7437 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
7438 +
7439 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
7440 +       const char *_file, int _line, void *_here)
7441 +{
7442 +       struct vx_info *vxi;
7443 +
7444 +       task_lock(p);
7445 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
7446 +               p, _file, _line);
7447 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
7448 +       task_unlock(p);
7449 +       return vxi;
7450 +}
7451 +
7452 +
7453 +static inline void __wakeup_vx_info(struct vx_info *vxi)
7454 +{
7455 +       if (waitqueue_active(&vxi->vx_wait))
7456 +               wake_up_interruptible(&vxi->vx_wait);
7457 +}
7458 +
7459 +
7460 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
7461 +
7462 +static inline void __enter_vx_info(struct vx_info *vxi,
7463 +       struct vx_info_save *vxis, const char *_file, int _line)
7464 +{
7465 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
7466 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
7467 +               current->xid, current->vx_info, _file, _line);
7468 +       vxis->vxi = xchg(&current->vx_info, vxi);
7469 +       vxis->xid = current->xid;
7470 +       current->xid = vxi ? vxi->vx_id : 0;
7471 +}
7472 +
7473 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
7474 +
7475 +static inline void __leave_vx_info(struct vx_info_save *vxis,
7476 +       const char *_file, int _line)
7477 +{
7478 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
7479 +               vxis, vxis->xid, vxis->vxi, current,
7480 +               current->xid, current->vx_info, _file, _line);
7481 +       (void)xchg(&current->vx_info, vxis->vxi);
7482 +       current->xid = vxis->xid;
7483 +}
7484 +
7485 +
7486 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
7487 +{
7488 +       vxis->vxi = xchg(&current->vx_info, NULL);
7489 +       vxis->xid = xchg(&current->xid, (vxid_t)0);
7490 +}
7491 +
7492 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
7493 +{
7494 +       (void)xchg(&current->xid, vxis->xid);
7495 +       (void)xchg(&current->vx_info, vxis->vxi);
7496 +}
7497 +
7498 +#define task_is_init(p) \
7499 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
7500 +
7501 +static inline int __task_is_init(struct task_struct *p,
7502 +       const char *_file, int _line, void *_here)
7503 +{
7504 +       int is_init = is_global_init(p);
7505 +
7506 +       task_lock(p);
7507 +       if (p->vx_info)
7508 +               is_init = p->vx_info->vx_initpid == p->pid;
7509 +       task_unlock(p);
7510 +       return is_init;
7511 +}
7512 +
7513 +extern void exit_vx_info(struct task_struct *, int);
7514 +extern void exit_vx_info_early(struct task_struct *, int);
7515 +
7516 +
7517 +#else
7518 +#warning duplicate inclusion
7519 +#endif
7520 diff -NurpP --minimal linux-4.4.110/include/linux/vs_cowbl.h linux-4.4.110-vs2.3.9/include/linux/vs_cowbl.h
7521 --- linux-4.4.110/include/linux/vs_cowbl.h      1970-01-01 00:00:00.000000000 +0000
7522 +++ linux-4.4.110-vs2.3.9/include/linux/vs_cowbl.h      2018-01-09 16:36:32.000000000 +0000
7523 @@ -0,0 +1,48 @@
7524 +#ifndef _VS_COWBL_H
7525 +#define _VS_COWBL_H
7526 +
7527 +#include <linux/fs.h>
7528 +#include <linux/dcache.h>
7529 +#include <linux/namei.h>
7530 +#include <linux/slab.h>
7531 +
7532 +extern struct dentry *cow_break_link(const char *pathname);
7533 +
7534 +static inline int cow_check_and_break(struct path *path)
7535 +{
7536 +       struct inode *inode = path->dentry->d_inode;
7537 +       int error = 0;
7538 +
7539 +       /* do we need this check? */
7540 +       if (IS_RDONLY(inode))
7541 +               return -EROFS;
7542 +
7543 +       if (IS_COW(inode)) {
7544 +               if (IS_COW_LINK(inode)) {
7545 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
7546 +                       char *pp, *buf;
7547 +
7548 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
7549 +                       if (!buf) {
7550 +                               return -ENOMEM;
7551 +                       }
7552 +                       pp = d_path(path, buf, PATH_MAX);
7553 +                       new_dentry = cow_break_link(pp);
7554 +                       kfree(buf);
7555 +                       if (!IS_ERR(new_dentry)) {
7556 +                               path->dentry = new_dentry;
7557 +                               dput(old_dentry);
7558 +                       } else
7559 +                               error = PTR_ERR(new_dentry);
7560 +               } else {
7561 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
7562 +                       inode->i_ctime = CURRENT_TIME;
7563 +                       mark_inode_dirty(inode);
7564 +               }
7565 +       }
7566 +       return error;
7567 +}
7568 +
7569 +#else
7570 +#warning duplicate inclusion
7571 +#endif
7572 diff -NurpP --minimal linux-4.4.110/include/linux/vs_cvirt.h linux-4.4.110-vs2.3.9/include/linux/vs_cvirt.h
7573 --- linux-4.4.110/include/linux/vs_cvirt.h      1970-01-01 00:00:00.000000000 +0000
7574 +++ linux-4.4.110-vs2.3.9/include/linux/vs_cvirt.h      2018-01-09 16:36:32.000000000 +0000
7575 @@ -0,0 +1,50 @@
7576 +#ifndef _VS_CVIRT_H
7577 +#define _VS_CVIRT_H
7578 +
7579 +#include "vserver/cvirt.h"
7580 +#include "vserver/context.h"
7581 +#include "vserver/base.h"
7582 +#include "vserver/check.h"
7583 +#include "vserver/debug.h"
7584 +
7585 +
7586 +static inline void vx_activate_task(struct task_struct *p)
7587 +{
7588 +       struct vx_info *vxi;
7589 +
7590 +       if ((vxi = p->vx_info)) {
7591 +               vx_update_load(vxi);
7592 +               atomic_inc(&vxi->cvirt.nr_running);
7593 +       }
7594 +}
7595 +
7596 +static inline void vx_deactivate_task(struct task_struct *p)
7597 +{
7598 +       struct vx_info *vxi;
7599 +
7600 +       if ((vxi = p->vx_info)) {
7601 +               vx_update_load(vxi);
7602 +               atomic_dec(&vxi->cvirt.nr_running);
7603 +       }
7604 +}
7605 +
7606 +static inline void vx_uninterruptible_inc(struct task_struct *p)
7607 +{
7608 +       struct vx_info *vxi;
7609 +
7610 +       if ((vxi = p->vx_info))
7611 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
7612 +}
7613 +
7614 +static inline void vx_uninterruptible_dec(struct task_struct *p)
7615 +{
7616 +       struct vx_info *vxi;
7617 +
7618 +       if ((vxi = p->vx_info))
7619 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
7620 +}
7621 +
7622 +
7623 +#else
7624 +#warning duplicate inclusion
7625 +#endif
7626 diff -NurpP --minimal linux-4.4.110/include/linux/vs_device.h linux-4.4.110-vs2.3.9/include/linux/vs_device.h
7627 --- linux-4.4.110/include/linux/vs_device.h     1970-01-01 00:00:00.000000000 +0000
7628 +++ linux-4.4.110-vs2.3.9/include/linux/vs_device.h     2018-01-09 16:36:32.000000000 +0000
7629 @@ -0,0 +1,45 @@
7630 +#ifndef _VS_DEVICE_H
7631 +#define _VS_DEVICE_H
7632 +
7633 +#include "vserver/base.h"
7634 +#include "vserver/device.h"
7635 +#include "vserver/debug.h"
7636 +
7637 +
7638 +#ifdef CONFIG_VSERVER_DEVICE
7639 +
7640 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
7641 +
7642 +#define vs_device_perm(v, d, m, p) \
7643 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
7644 +
7645 +#else
7646 +
7647 +static inline
7648 +int vs_map_device(struct vx_info *vxi,
7649 +       dev_t device, dev_t *target, umode_t mode)
7650 +{
7651 +       if (target)
7652 +               *target = device;
7653 +       return ~0;
7654 +}
7655 +
7656 +#define vs_device_perm(v, d, m, p) ((p) == (p))
7657 +
7658 +#endif
7659 +
7660 +
7661 +#define vs_map_chrdev(d, t, p) \
7662 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
7663 +#define vs_map_blkdev(d, t, p) \
7664 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
7665 +
7666 +#define vs_chrdev_perm(d, p) \
7667 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
7668 +#define vs_blkdev_perm(d, p) \
7669 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
7670 +
7671 +
7672 +#else
7673 +#warning duplicate inclusion
7674 +#endif
7675 diff -NurpP --minimal linux-4.4.110/include/linux/vs_dlimit.h linux-4.4.110-vs2.3.9/include/linux/vs_dlimit.h
7676 --- linux-4.4.110/include/linux/vs_dlimit.h     1970-01-01 00:00:00.000000000 +0000
7677 +++ linux-4.4.110-vs2.3.9/include/linux/vs_dlimit.h     2018-01-09 16:36:32.000000000 +0000
7678 @@ -0,0 +1,215 @@
7679 +#ifndef _VS_DLIMIT_H
7680 +#define _VS_DLIMIT_H
7681 +
7682 +#include <linux/fs.h>
7683 +
7684 +#include "vserver/dlimit.h"
7685 +#include "vserver/base.h"
7686 +#include "vserver/debug.h"
7687 +
7688 +
7689 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
7690 +
7691 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
7692 +       const char *_file, int _line)
7693 +{
7694 +       if (!dli)
7695 +               return NULL;
7696 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
7697 +               dli, dli ? dli->dl_tag : 0,
7698 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
7699 +               _file, _line);
7700 +       atomic_inc(&dli->dl_usecnt);
7701 +       return dli;
7702 +}
7703 +
7704 +
7705 +#define free_dl_info(i) \
7706 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
7707 +
7708 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
7709 +
7710 +static inline void __put_dl_info(struct dl_info *dli,
7711 +       const char *_file, int _line)
7712 +{
7713 +       if (!dli)
7714 +               return;
7715 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
7716 +               dli, dli ? dli->dl_tag : 0,
7717 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
7718 +               _file, _line);
7719 +       if (atomic_dec_and_test(&dli->dl_usecnt))
7720 +               free_dl_info(dli);
7721 +}
7722 +
7723 +
7724 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
7725 +
7726 +static inline int __dl_alloc_space(struct super_block *sb,
7727 +       vtag_t tag, dlsize_t nr, const char *file, int line)
7728 +{
7729 +       struct dl_info *dli = NULL;
7730 +       int ret = 0;
7731 +
7732 +       if (nr == 0)
7733 +               goto out;
7734 +       dli = locate_dl_info(sb, tag);
7735 +       if (!dli)
7736 +               goto out;
7737 +
7738 +       spin_lock(&dli->dl_lock);
7739 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
7740 +       if (!ret)
7741 +               dli->dl_space_used += nr;
7742 +       spin_unlock(&dli->dl_lock);
7743 +       put_dl_info(dli);
7744 +out:
7745 +       vxlprintk(VXD_CBIT(dlim, 1),
7746 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
7747 +               sb, tag, __dlimit_char(dli), (long long)nr,
7748 +               ret, file, line);
7749 +       return ret ? -ENOSPC : 0;
7750 +}
7751 +
7752 +static inline void __dl_free_space(struct super_block *sb,
7753 +       vtag_t tag, dlsize_t nr, const char *_file, int _line)
7754 +{
7755 +       struct dl_info *dli = NULL;
7756 +
7757 +       if (nr == 0)
7758 +               goto out;
7759 +       dli = locate_dl_info(sb, tag);
7760 +       if (!dli)
7761 +               goto out;
7762 +
7763 +       spin_lock(&dli->dl_lock);
7764 +       if (dli->dl_space_used > nr)
7765 +               dli->dl_space_used -= nr;
7766 +       else
7767 +               dli->dl_space_used = 0;
7768 +       spin_unlock(&dli->dl_lock);
7769 +       put_dl_info(dli);
7770 +out:
7771 +       vxlprintk(VXD_CBIT(dlim, 1),
7772 +               "FREE  (%p,#%d)%c %lld bytes",
7773 +               sb, tag, __dlimit_char(dli), (long long)nr,
7774 +               _file, _line);
7775 +}
7776 +
7777 +static inline int __dl_alloc_inode(struct super_block *sb,
7778 +       vtag_t tag, const char *_file, int _line)
7779 +{
7780 +       struct dl_info *dli;
7781 +       int ret = 0;
7782 +
7783 +       dli = locate_dl_info(sb, tag);
7784 +       if (!dli)
7785 +               goto out;
7786 +
7787 +       spin_lock(&dli->dl_lock);
7788 +       dli->dl_inodes_used++;
7789 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
7790 +       spin_unlock(&dli->dl_lock);
7791 +       put_dl_info(dli);
7792 +out:
7793 +       vxlprintk(VXD_CBIT(dlim, 0),
7794 +               "ALLOC (%p,#%d)%c inode (%d)",
7795 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
7796 +       return ret ? -ENOSPC : 0;
7797 +}
7798 +
7799 +static inline void __dl_free_inode(struct super_block *sb,
7800 +       vtag_t tag, const char *_file, int _line)
7801 +{
7802 +       struct dl_info *dli;
7803 +
7804 +       dli = locate_dl_info(sb, tag);
7805 +       if (!dli)
7806 +               goto out;
7807 +
7808 +       spin_lock(&dli->dl_lock);
7809 +       if (dli->dl_inodes_used > 1)
7810 +               dli->dl_inodes_used--;
7811 +       else
7812 +               dli->dl_inodes_used = 0;
7813 +       spin_unlock(&dli->dl_lock);
7814 +       put_dl_info(dli);
7815 +out:
7816 +       vxlprintk(VXD_CBIT(dlim, 0),
7817 +               "FREE  (%p,#%d)%c inode",
7818 +               sb, tag, __dlimit_char(dli), _file, _line);
7819 +}
7820 +
7821 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
7822 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
7823 +       const char *_file, int _line)
7824 +{
7825 +       struct dl_info *dli;
7826 +       uint64_t broot, bfree;
7827 +
7828 +       dli = locate_dl_info(sb, tag);
7829 +       if (!dli)
7830 +               return;
7831 +
7832 +       spin_lock(&dli->dl_lock);
7833 +       broot = (dli->dl_space_total -
7834 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
7835 +               >> sb->s_blocksize_bits;
7836 +       bfree = (dli->dl_space_total - dli->dl_space_used)
7837 +                       >> sb->s_blocksize_bits;
7838 +       spin_unlock(&dli->dl_lock);
7839 +
7840 +       vxlprintk(VXD_CBIT(dlim, 2),
7841 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
7842 +               (long long)bfree, (long long)broot,
7843 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
7844 +               _file, _line);
7845 +       if (free_blocks) {
7846 +               if (*free_blocks > bfree)
7847 +                       *free_blocks = bfree;
7848 +       }
7849 +       if (root_blocks) {
7850 +               if (*root_blocks > broot)
7851 +                       *root_blocks = broot;
7852 +       }
7853 +       put_dl_info(dli);
7854 +}
7855 +
7856 +#define dl_prealloc_space(in, bytes) \
7857 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7858 +               __FILE__, __LINE__ )
7859 +
7860 +#define dl_alloc_space(in, bytes) \
7861 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7862 +               __FILE__, __LINE__ )
7863 +
7864 +#define dl_reserve_space(in, bytes) \
7865 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7866 +               __FILE__, __LINE__ )
7867 +
7868 +#define dl_claim_space(in, bytes) (0)
7869 +
7870 +#define dl_release_space(in, bytes) \
7871 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7872 +               __FILE__, __LINE__ )
7873 +
7874 +#define dl_free_space(in, bytes) \
7875 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7876 +               __FILE__, __LINE__ )
7877 +
7878 +
7879 +
7880 +#define dl_alloc_inode(in) \
7881 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
7882 +
7883 +#define dl_free_inode(in) \
7884 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
7885 +
7886 +
7887 +#define dl_adjust_block(sb, tag, fb, rb) \
7888 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
7889 +
7890 +
7891 +#else
7892 +#warning duplicate inclusion
7893 +#endif
7894 diff -NurpP --minimal linux-4.4.110/include/linux/vs_inet.h linux-4.4.110-vs2.3.9/include/linux/vs_inet.h
7895 --- linux-4.4.110/include/linux/vs_inet.h       1970-01-01 00:00:00.000000000 +0000
7896 +++ linux-4.4.110-vs2.3.9/include/linux/vs_inet.h       2018-01-09 16:36:32.000000000 +0000
7897 @@ -0,0 +1,364 @@
7898 +#ifndef _VS_INET_H
7899 +#define _VS_INET_H
7900 +
7901 +#include "vserver/base.h"
7902 +#include "vserver/network.h"
7903 +#include "vserver/debug.h"
7904 +
7905 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
7906 +
7907 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
7908 +                       NIPQUAD((a)->mask), (a)->type
7909 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
7910 +
7911 +#define NIPQUAD(addr) \
7912 +       ((unsigned char *)&addr)[0], \
7913 +       ((unsigned char *)&addr)[1], \
7914 +       ((unsigned char *)&addr)[2], \
7915 +       ((unsigned char *)&addr)[3]
7916 +
7917 +#define NIPQUAD_FMT "%u.%u.%u.%u"
7918 +
7919 +
7920 +static inline
7921 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
7922 +{
7923 +       __be32 ip = nxa->ip[0].s_addr;
7924 +       __be32 mask = nxa->mask.s_addr;
7925 +       __be32 bcast = ip | ~mask;
7926 +       int ret = 0;
7927 +
7928 +       switch (nxa->type & tmask) {
7929 +       case NXA_TYPE_MASK:
7930 +               ret = (ip == (addr & mask));
7931 +               break;
7932 +       case NXA_TYPE_ADDR:
7933 +               ret = 3;
7934 +               if (addr == ip)
7935 +                       break;
7936 +               /* fall through to broadcast */
7937 +       case NXA_MOD_BCAST:
7938 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
7939 +               break;
7940 +       case NXA_TYPE_RANGE:
7941 +               ret = ((nxa->ip[0].s_addr <= addr) &&
7942 +                       (nxa->ip[1].s_addr > addr));
7943 +               break;
7944 +       case NXA_TYPE_ANY:
7945 +               ret = 2;
7946 +               break;
7947 +       }
7948 +
7949 +       vxdprintk(VXD_CBIT(net, 0),
7950 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
7951 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
7952 +       return ret;
7953 +}
7954 +
7955 +static inline
7956 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
7957 +{
7958 +       struct nx_addr_v4 *nxa;
7959 +       unsigned long irqflags;
7960 +       int ret = 1;
7961 +
7962 +       if (!nxi)
7963 +               goto out;
7964 +
7965 +       ret = 2;
7966 +       /* allow 127.0.0.1 when remapping lback */
7967 +       if ((tmask & NXA_LOOPBACK) &&
7968 +               (addr == IPI_LOOPBACK) &&
7969 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
7970 +               goto out;
7971 +       ret = 3;
7972 +       /* check for lback address */
7973 +       if ((tmask & NXA_MOD_LBACK) &&
7974 +               (nxi->v4_lback.s_addr == addr))
7975 +               goto out;
7976 +       ret = 4;
7977 +       /* check for broadcast address */
7978 +       if ((tmask & NXA_MOD_BCAST) &&
7979 +               (nxi->v4_bcast.s_addr == addr))
7980 +               goto out;
7981 +       ret = 5;
7982 +
7983 +       /* check for v4 addresses */
7984 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
7985 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
7986 +               if (v4_addr_match(nxa, addr, tmask))
7987 +                       goto out_unlock;
7988 +       ret = 0;
7989 +out_unlock:
7990 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
7991 +out:
7992 +       vxdprintk(VXD_CBIT(net, 0),
7993 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
7994 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
7995 +       return ret;
7996 +}
7997 +
7998 +static inline
7999 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
8000 +{
8001 +       /* FIXME: needs full range checks */
8002 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
8003 +}
8004 +
8005 +static inline
8006 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
8007 +{
8008 +       struct nx_addr_v4 *ptr;
8009 +       unsigned long irqflags;
8010 +       int ret = 1;
8011 +
8012 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8013 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
8014 +               if (v4_nx_addr_match(ptr, nxa, mask))
8015 +                       goto out_unlock;
8016 +       ret = 0;
8017 +out_unlock:
8018 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8019 +       return ret;
8020 +}
8021 +
8022 +#include <net/inet_sock.h>
8023 +
8024 +/*
8025 + *     Check if a given address matches for a socket
8026 + *
8027 + *     nxi:            the socket's nx_info if any
8028 + *     addr:           to be verified address
8029 + */
8030 +static inline
8031 +int v4_sock_addr_match (
8032 +       struct nx_info *nxi,
8033 +       struct inet_sock *inet,
8034 +       __be32 addr)
8035 +{
8036 +       __be32 saddr = inet->inet_rcv_saddr;
8037 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
8038 +
8039 +       if (addr && (saddr == addr || bcast == addr))
8040 +               return 1;
8041 +       if (!saddr)
8042 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
8043 +       return 0;
8044 +}
8045 +
8046 +
8047 +/* inet related checks and helpers */
8048 +
8049 +
8050 +struct in_ifaddr;
8051 +struct net_device;
8052 +struct sock;
8053 +
8054 +#ifdef CONFIG_INET
8055 +
8056 +#include <linux/netdevice.h>
8057 +#include <linux/inetdevice.h>
8058 +#include <net/inet_sock.h>
8059 +#include <net/inet_timewait_sock.h>
8060 +
8061 +
8062 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8063 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
8064 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
8065 +
8066 +
8067 +/*
8068 + *     check if address is covered by socket
8069 + *
8070 + *     sk:     the socket to check against
8071 + *     addr:   the address in question (must be != 0)
8072 + */
8073 +
8074 +static inline
8075 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
8076 +{
8077 +       struct nx_info *nxi = sk->sk_nx_info;
8078 +       __be32 saddr = sk->sk_rcv_saddr;
8079 +
8080 +       vxdprintk(VXD_CBIT(net, 5),
8081 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
8082 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
8083 +               (sk->sk_socket?sk->sk_socket->flags:0));
8084 +
8085 +       if (saddr) {            /* direct address match */
8086 +               return v4_addr_match(nxa, saddr, -1);
8087 +       } else if (nxi) {       /* match against nx_info */
8088 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
8089 +       } else {                /* unrestricted any socket */
8090 +               return 1;
8091 +       }
8092 +}
8093 +
8094 +
8095 +
8096 +static inline
8097 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
8098 +{
8099 +       vxdprintk(VXD_CBIT(net, 1),
8100 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
8101 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
8102 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
8103 +
8104 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8105 +               return 1;
8106 +       if (dev_in_nx_info(dev, nxi))
8107 +               return 1;
8108 +       return 0;
8109 +}
8110 +
8111 +
8112 +static inline
8113 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
8114 +{
8115 +       if (!nxi)
8116 +               return 1;
8117 +       if (!ifa)
8118 +               return 0;
8119 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
8120 +}
8121 +
8122 +static inline
8123 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
8124 +{
8125 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
8126 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8127 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
8128 +
8129 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8130 +               return 1;
8131 +       if (v4_ifa_in_nx_info(ifa, nxi))
8132 +               return 1;
8133 +       return 0;
8134 +}
8135 +
8136 +
8137 +struct nx_v4_sock_addr {
8138 +       __be32 saddr;   /* Address used for validation */
8139 +       __be32 baddr;   /* Address used for socket bind */
8140 +};
8141 +
8142 +static inline
8143 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
8144 +       struct nx_v4_sock_addr *nsa)
8145 +{
8146 +       struct sock *sk = &inet->sk;
8147 +       struct nx_info *nxi = sk->sk_nx_info;
8148 +       __be32 saddr = addr->sin_addr.s_addr;
8149 +       __be32 baddr = saddr;
8150 +
8151 +       vxdprintk(VXD_CBIT(net, 3),
8152 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
8153 +               sk, sk->sk_nx_info, sk->sk_socket,
8154 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
8155 +               NIPQUAD(saddr));
8156 +
8157 +       if (nxi) {
8158 +               if (saddr == INADDR_ANY) {
8159 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
8160 +                               baddr = nxi->v4.ip[0].s_addr;
8161 +               } else if (saddr == IPI_LOOPBACK) {
8162 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8163 +                               baddr = nxi->v4_lback.s_addr;
8164 +               } else if (!ipv4_is_multicast(saddr) ||
8165 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
8166 +                       /* normal address bind */
8167 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
8168 +                               return -EADDRNOTAVAIL;
8169 +               }
8170 +       }
8171 +
8172 +       vxdprintk(VXD_CBIT(net, 3),
8173 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
8174 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
8175 +
8176 +       nsa->saddr = saddr;
8177 +       nsa->baddr = baddr;
8178 +       return 0;
8179 +}
8180 +
8181 +static inline
8182 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
8183 +{
8184 +       inet->inet_saddr = nsa->baddr;
8185 +       inet->inet_rcv_saddr = nsa->baddr;
8186 +}
8187 +
8188 +
8189 +/*
8190 + *      helper to simplify inet_lookup_listener
8191 + *
8192 + *      nxi:   the socket's nx_info if any
8193 + *      addr:  to be verified address
8194 + *      saddr: socket address
8195 + */
8196 +static inline int v4_inet_addr_match (
8197 +       struct nx_info *nxi,
8198 +       __be32 addr,
8199 +       __be32 saddr)
8200 +{
8201 +       if (addr && (saddr == addr))
8202 +               return 1;
8203 +       if (!saddr)
8204 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
8205 +       return 0;
8206 +}
8207 +
8208 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
8209 +{
8210 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
8211 +               (addr == nxi->v4_lback.s_addr))
8212 +               return IPI_LOOPBACK;
8213 +       return addr;
8214 +}
8215 +
8216 +static inline
8217 +int nx_info_has_v4(struct nx_info *nxi)
8218 +{
8219 +       if (!nxi)
8220 +               return 1;
8221 +       if (NX_IPV4(nxi))
8222 +               return 1;
8223 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8224 +               return 1;
8225 +       return 0;
8226 +}
8227 +
8228 +#else /* CONFIG_INET */
8229 +
8230 +static inline
8231 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
8232 +{
8233 +       return 1;
8234 +}
8235 +
8236 +static inline
8237 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8238 +{
8239 +       return 1;
8240 +}
8241 +
8242 +static inline
8243 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8244 +{
8245 +       return 1;
8246 +}
8247 +
8248 +static inline
8249 +int nx_info_has_v4(struct nx_info *nxi)
8250 +{
8251 +       return 0;
8252 +}
8253 +
8254 +#endif /* CONFIG_INET */
8255 +
8256 +#define current_nx_info_has_v4() \
8257 +       nx_info_has_v4(current_nx_info())
8258 +
8259 +#else
8260 +// #warning duplicate inclusion
8261 +#endif
8262 diff -NurpP --minimal linux-4.4.110/include/linux/vs_inet6.h linux-4.4.110-vs2.3.9/include/linux/vs_inet6.h
8263 --- linux-4.4.110/include/linux/vs_inet6.h      1970-01-01 00:00:00.000000000 +0000
8264 +++ linux-4.4.110-vs2.3.9/include/linux/vs_inet6.h      2018-01-09 16:36:32.000000000 +0000
8265 @@ -0,0 +1,257 @@
8266 +#ifndef _VS_INET6_H
8267 +#define _VS_INET6_H
8268 +
8269 +#include "vserver/base.h"
8270 +#include "vserver/network.h"
8271 +#include "vserver/debug.h"
8272 +
8273 +#include <net/ipv6.h>
8274 +
8275 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
8276 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
8277 +
8278 +
8279 +#ifdef CONFIG_IPV6
8280 +
8281 +static inline
8282 +int v6_addr_match(struct nx_addr_v6 *nxa,
8283 +       const struct in6_addr *addr, uint16_t mask)
8284 +{
8285 +       int ret = 0;
8286 +
8287 +       switch (nxa->type & mask) {
8288 +       case NXA_TYPE_MASK:
8289 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
8290 +               break;
8291 +       case NXA_TYPE_ADDR:
8292 +               ret = ipv6_addr_equal(&nxa->ip, addr);
8293 +               break;
8294 +       case NXA_TYPE_ANY:
8295 +               ret = 1;
8296 +               break;
8297 +       }
8298 +       vxdprintk(VXD_CBIT(net, 0),
8299 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
8300 +               nxa, NXAV6(nxa), addr, mask, ret);
8301 +       return ret;
8302 +}
8303 +
8304 +static inline
8305 +int v6_addr_in_nx_info(struct nx_info *nxi,
8306 +       const struct in6_addr *addr, uint16_t mask)
8307 +{
8308 +       struct nx_addr_v6 *nxa;
8309 +       unsigned long irqflags;
8310 +       int ret = 1;
8311 +
8312 +       if (!nxi)
8313 +               goto out;
8314 +
8315 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8316 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
8317 +               if (v6_addr_match(nxa, addr, mask))
8318 +                       goto out_unlock;
8319 +       ret = 0;
8320 +out_unlock:
8321 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8322 +out:
8323 +       vxdprintk(VXD_CBIT(net, 0),
8324 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
8325 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
8326 +       return ret;
8327 +}
8328 +
8329 +static inline
8330 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
8331 +{
8332 +       /* FIXME: needs full range checks */
8333 +       return v6_addr_match(nxa, &addr->ip, mask);
8334 +}
8335 +
8336 +static inline
8337 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
8338 +{
8339 +       struct nx_addr_v6 *ptr;
8340 +       unsigned long irqflags;
8341 +       int ret = 1;
8342 +
8343 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8344 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
8345 +               if (v6_nx_addr_match(ptr, nxa, mask))
8346 +                       goto out_unlock;
8347 +       ret = 0;
8348 +out_unlock:
8349 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8350 +       return ret;
8351 +}
8352 +
8353 +
8354 +/*
8355 + *     Check if a given address matches for a socket
8356 + *
8357 + *     nxi:            the socket's nx_info if any
8358 + *     addr:           to be verified address
8359 + */
8360 +static inline
8361 +int v6_sock_addr_match (
8362 +       struct nx_info *nxi,
8363 +       struct inet_sock *inet,
8364 +       struct in6_addr *addr)
8365 +{
8366 +       struct sock *sk = &inet->sk;
8367 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8368 +
8369 +       if (!ipv6_addr_any(addr) &&
8370 +               ipv6_addr_equal(saddr, addr))
8371 +               return 1;
8372 +       if (ipv6_addr_any(saddr))
8373 +               return v6_addr_in_nx_info(nxi, addr, -1);
8374 +       return 0;
8375 +}
8376 +
8377 +/*
8378 + *     check if address is covered by socket
8379 + *
8380 + *     sk:     the socket to check against
8381 + *     addr:   the address in question (must be != 0)
8382 + */
8383 +
8384 +static inline
8385 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
8386 +{
8387 +       struct nx_info *nxi = sk->sk_nx_info;
8388 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8389 +
8390 +       vxdprintk(VXD_CBIT(net, 5),
8391 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
8392 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
8393 +               (sk->sk_socket?sk->sk_socket->flags:0));
8394 +
8395 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
8396 +               return v6_addr_match(nxa, saddr, -1);
8397 +       } else if (nxi) {               /* match against nx_info */
8398 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
8399 +       } else {                        /* unrestricted any socket */
8400 +               return 1;
8401 +       }
8402 +}
8403 +
8404 +
8405 +/* inet related checks and helpers */
8406 +
8407 +
8408 +struct in_ifaddr;
8409 +struct net_device;
8410 +struct sock;
8411 +
8412 +
8413 +#include <linux/netdevice.h>
8414 +#include <linux/inetdevice.h>
8415 +#include <net/inet_timewait_sock.h>
8416 +
8417 +
8418 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8419 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
8420 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
8421 +
8422 +
8423 +
8424 +static inline
8425 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
8426 +{
8427 +       if (!nxi)
8428 +               return 1;
8429 +       if (!ifa)
8430 +               return 0;
8431 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
8432 +}
8433 +
8434 +static inline
8435 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
8436 +{
8437 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
8438 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8439 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
8440 +
8441 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8442 +               return 1;
8443 +       if (v6_ifa_in_nx_info(ifa, nxi))
8444 +               return 1;
8445 +       return 0;
8446 +}
8447 +
8448 +
8449 +struct nx_v6_sock_addr {
8450 +       struct in6_addr saddr;  /* Address used for validation */
8451 +       struct in6_addr baddr;  /* Address used for socket bind */
8452 +};
8453 +
8454 +static inline
8455 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
8456 +       struct nx_v6_sock_addr *nsa)
8457 +{
8458 +       // struct sock *sk = &inet->sk;
8459 +       // struct nx_info *nxi = sk->sk_nx_info;
8460 +       struct in6_addr saddr = addr->sin6_addr;
8461 +       struct in6_addr baddr = saddr;
8462 +
8463 +       nsa->saddr = saddr;
8464 +       nsa->baddr = baddr;
8465 +       return 0;
8466 +}
8467 +
8468 +static inline
8469 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
8470 +{
8471 +       // struct sock *sk = &inet->sk;
8472 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
8473 +
8474 +       // *saddr = nsa->baddr;
8475 +       // inet->inet_saddr = nsa->baddr;
8476 +}
8477 +
8478 +static inline
8479 +int nx_info_has_v6(struct nx_info *nxi)
8480 +{
8481 +       if (!nxi)
8482 +               return 1;
8483 +       if (NX_IPV6(nxi))
8484 +               return 1;
8485 +       return 0;
8486 +}
8487 +
8488 +#else /* CONFIG_IPV6 */
8489 +
8490 +static inline
8491 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
8492 +{
8493 +       return 1;
8494 +}
8495 +
8496 +
8497 +static inline
8498 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8499 +{
8500 +       return 1;
8501 +}
8502 +
8503 +static inline
8504 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8505 +{
8506 +       return 1;
8507 +}
8508 +
8509 +static inline
8510 +int nx_info_has_v6(struct nx_info *nxi)
8511 +{
8512 +       return 0;
8513 +}
8514 +
8515 +#endif /* CONFIG_IPV6 */
8516 +
8517 +#define current_nx_info_has_v6() \
8518 +       nx_info_has_v6(current_nx_info())
8519 +
8520 +#else
8521 +#warning duplicate inclusion
8522 +#endif
8523 diff -NurpP --minimal linux-4.4.110/include/linux/vs_limit.h linux-4.4.110-vs2.3.9/include/linux/vs_limit.h
8524 --- linux-4.4.110/include/linux/vs_limit.h      1970-01-01 00:00:00.000000000 +0000
8525 +++ linux-4.4.110-vs2.3.9/include/linux/vs_limit.h      2018-01-09 16:36:32.000000000 +0000
8526 @@ -0,0 +1,140 @@
8527 +#ifndef _VS_LIMIT_H
8528 +#define _VS_LIMIT_H
8529 +
8530 +#include "vserver/limit.h"
8531 +#include "vserver/base.h"
8532 +#include "vserver/context.h"
8533 +#include "vserver/debug.h"
8534 +#include "vserver/context.h"
8535 +#include "vserver/limit_int.h"
8536 +
8537 +
8538 +#define vx_acc_cres(v, d, p, r) \
8539 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
8540 +
8541 +#define vx_acc_cres_cond(x, d, p, r) \
8542 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8543 +       r, d, p, __FILE__, __LINE__)
8544 +
8545 +
8546 +#define vx_add_cres(v, a, p, r) \
8547 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
8548 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
8549 +
8550 +#define vx_add_cres_cond(x, a, p, r) \
8551 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8552 +       r, a, p, __FILE__, __LINE__)
8553 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
8554 +
8555 +
8556 +/* process and file limits */
8557 +
8558 +#define vx_nproc_inc(p) \
8559 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
8560 +
8561 +#define vx_nproc_dec(p) \
8562 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
8563 +
8564 +#define vx_files_inc(f) \
8565 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
8566 +
8567 +#define vx_files_dec(f) \
8568 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
8569 +
8570 +#define vx_locks_inc(l) \
8571 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
8572 +
8573 +#define vx_locks_dec(l) \
8574 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
8575 +
8576 +#define vx_openfd_inc(f) \
8577 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
8578 +
8579 +#define vx_openfd_dec(f) \
8580 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
8581 +
8582 +
8583 +#define vx_cres_avail(v, n, r) \
8584 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
8585 +
8586 +
8587 +#define vx_nproc_avail(n) \
8588 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
8589 +
8590 +#define vx_files_avail(n) \
8591 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
8592 +
8593 +#define vx_locks_avail(n) \
8594 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
8595 +
8596 +#define vx_openfd_avail(n) \
8597 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
8598 +
8599 +
8600 +/* dentry limits */
8601 +
8602 +#define vx_dentry_inc(d) do {                                          \
8603 +       if (d_count(d) == 1)                                            \
8604 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
8605 +       } while (0)
8606 +
8607 +#define vx_dentry_dec(d) do {                                          \
8608 +       if (d_count(d) == 0)                                            \
8609 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
8610 +       } while (0)
8611 +
8612 +#define vx_dentry_avail(n) \
8613 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
8614 +
8615 +
8616 +/* socket limits */
8617 +
8618 +#define vx_sock_inc(s) \
8619 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
8620 +
8621 +#define vx_sock_dec(s) \
8622 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
8623 +
8624 +#define vx_sock_avail(n) \
8625 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
8626 +
8627 +
8628 +/* ipc resource limits */
8629 +
8630 +#define vx_ipcmsg_add(v, u, a) \
8631 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
8632 +
8633 +#define vx_ipcmsg_sub(v, u, a) \
8634 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
8635 +
8636 +#define vx_ipcmsg_avail(v, a) \
8637 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
8638 +
8639 +
8640 +#define vx_ipcshm_add(v, k, a) \
8641 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8642 +
8643 +#define vx_ipcshm_sub(v, k, a) \
8644 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8645 +
8646 +#define vx_ipcshm_avail(v, a) \
8647 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
8648 +
8649 +
8650 +#define vx_semary_inc(a) \
8651 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
8652 +
8653 +#define vx_semary_dec(a) \
8654 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
8655 +
8656 +
8657 +#define vx_nsems_add(a,n) \
8658 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8659 +
8660 +#define vx_nsems_sub(a,n) \
8661 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8662 +
8663 +
8664 +#else
8665 +#warning duplicate inclusion
8666 +#endif
8667 diff -NurpP --minimal linux-4.4.110/include/linux/vs_network.h linux-4.4.110-vs2.3.9/include/linux/vs_network.h
8668 --- linux-4.4.110/include/linux/vs_network.h    1970-01-01 00:00:00.000000000 +0000
8669 +++ linux-4.4.110-vs2.3.9/include/linux/vs_network.h    2018-01-09 16:36:32.000000000 +0000
8670 @@ -0,0 +1,169 @@
8671 +#ifndef _NX_VS_NETWORK_H
8672 +#define _NX_VS_NETWORK_H
8673 +
8674 +#include "vserver/context.h"
8675 +#include "vserver/network.h"
8676 +#include "vserver/base.h"
8677 +#include "vserver/check.h"
8678 +#include "vserver/debug.h"
8679 +
8680 +#include <linux/sched.h>
8681 +
8682 +
8683 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
8684 +
8685 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
8686 +       const char *_file, int _line)
8687 +{
8688 +       if (!nxi)
8689 +               return NULL;
8690 +
8691 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
8692 +               nxi, nxi ? nxi->nx_id : 0,
8693 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8694 +               _file, _line);
8695 +
8696 +       atomic_inc(&nxi->nx_usecnt);
8697 +       return nxi;
8698 +}
8699 +
8700 +
8701 +extern void free_nx_info(struct nx_info *);
8702 +
8703 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
8704 +
8705 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
8706 +{
8707 +       if (!nxi)
8708 +               return;
8709 +
8710 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
8711 +               nxi, nxi ? nxi->nx_id : 0,
8712 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8713 +               _file, _line);
8714 +
8715 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
8716 +               free_nx_info(nxi);
8717 +}
8718 +
8719 +
8720 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
8721 +
8722 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
8723 +               const char *_file, int _line)
8724 +{
8725 +       if (nxi) {
8726 +               vxlprintk(VXD_CBIT(nid, 3),
8727 +                       "init_nx_info(%p[#%d.%d])",
8728 +                       nxi, nxi ? nxi->nx_id : 0,
8729 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8730 +                       _file, _line);
8731 +
8732 +               atomic_inc(&nxi->nx_usecnt);
8733 +       }
8734 +       *nxp = nxi;
8735 +}
8736 +
8737 +
8738 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
8739 +
8740 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
8741 +       const char *_file, int _line)
8742 +{
8743 +       struct nx_info *nxo;
8744 +
8745 +       if (!nxi)
8746 +               return;
8747 +
8748 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
8749 +               nxi, nxi ? nxi->nx_id : 0,
8750 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8751 +               _file, _line);
8752 +
8753 +       atomic_inc(&nxi->nx_usecnt);
8754 +       nxo = xchg(nxp, nxi);
8755 +       BUG_ON(nxo);
8756 +}
8757 +
8758 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
8759 +
8760 +static inline void __clr_nx_info(struct nx_info **nxp,
8761 +       const char *_file, int _line)
8762 +{
8763 +       struct nx_info *nxo;
8764 +
8765 +       nxo = xchg(nxp, NULL);
8766 +       if (!nxo)
8767 +               return;
8768 +
8769 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
8770 +               nxo, nxo ? nxo->nx_id : 0,
8771 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
8772 +               _file, _line);
8773 +
8774 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
8775 +               free_nx_info(nxo);
8776 +}
8777 +
8778 +
8779 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
8780 +
8781 +static inline void __claim_nx_info(struct nx_info *nxi,
8782 +       struct task_struct *task, const char *_file, int _line)
8783 +{
8784 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
8785 +               nxi, nxi ? nxi->nx_id : 0,
8786 +               nxi?atomic_read(&nxi->nx_usecnt):0,
8787 +               nxi?atomic_read(&nxi->nx_tasks):0,
8788 +               task, _file, _line);
8789 +
8790 +       atomic_inc(&nxi->nx_tasks);
8791 +}
8792 +
8793 +
8794 +extern void unhash_nx_info(struct nx_info *);
8795 +
8796 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
8797 +
8798 +static inline void __release_nx_info(struct nx_info *nxi,
8799 +       struct task_struct *task, const char *_file, int _line)
8800 +{
8801 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
8802 +               nxi, nxi ? nxi->nx_id : 0,
8803 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8804 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
8805 +               task, _file, _line);
8806 +
8807 +       might_sleep();
8808 +
8809 +       if (atomic_dec_and_test(&nxi->nx_tasks))
8810 +               unhash_nx_info(nxi);
8811 +}
8812 +
8813 +
8814 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
8815 +
8816 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
8817 +       const char *_file, int _line)
8818 +{
8819 +       struct nx_info *nxi;
8820 +
8821 +       task_lock(p);
8822 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
8823 +               p, _file, _line);
8824 +       nxi = __get_nx_info(p->nx_info, _file, _line);
8825 +       task_unlock(p);
8826 +       return nxi;
8827 +}
8828 +
8829 +
8830 +static inline void exit_nx_info(struct task_struct *p)
8831 +{
8832 +       if (p->nx_info)
8833 +               release_nx_info(p->nx_info, p);
8834 +}
8835 +
8836 +
8837 +#else
8838 +#warning duplicate inclusion
8839 +#endif
8840 diff -NurpP --minimal linux-4.4.110/include/linux/vs_pid.h linux-4.4.110-vs2.3.9/include/linux/vs_pid.h
8841 --- linux-4.4.110/include/linux/vs_pid.h        1970-01-01 00:00:00.000000000 +0000
8842 +++ linux-4.4.110-vs2.3.9/include/linux/vs_pid.h        2018-01-09 16:36:32.000000000 +0000
8843 @@ -0,0 +1,50 @@
8844 +#ifndef _VS_PID_H
8845 +#define _VS_PID_H
8846 +
8847 +#include "vserver/base.h"
8848 +#include "vserver/check.h"
8849 +#include "vserver/context.h"
8850 +#include "vserver/debug.h"
8851 +#include "vserver/pid.h"
8852 +#include <linux/pid_namespace.h>
8853 +
8854 +
8855 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
8856 +
8857 +static inline
8858 +int vx_proc_task_visible(struct task_struct *task)
8859 +{
8860 +       if ((task->pid == 1) &&
8861 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
8862 +               /* show a blend through init */
8863 +               goto visible;
8864 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
8865 +               goto visible;
8866 +       return 0;
8867 +visible:
8868 +       return 1;
8869 +}
8870 +
8871 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
8872 +
8873 +
8874 +static inline
8875 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
8876 +{
8877 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
8878 +
8879 +       if (task && !vx_proc_task_visible(task)) {
8880 +               vxdprintk(VXD_CBIT(misc, 6),
8881 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
8882 +                       task, task->xid, task->pid,
8883 +                       current, current->xid, current->pid);
8884 +               put_task_struct(task);
8885 +               task = NULL;
8886 +       }
8887 +       return task;
8888 +}
8889 +
8890 +
8891 +#else
8892 +#warning duplicate inclusion
8893 +#endif
8894 diff -NurpP --minimal linux-4.4.110/include/linux/vs_sched.h linux-4.4.110-vs2.3.9/include/linux/vs_sched.h
8895 --- linux-4.4.110/include/linux/vs_sched.h      1970-01-01 00:00:00.000000000 +0000
8896 +++ linux-4.4.110-vs2.3.9/include/linux/vs_sched.h      2018-01-09 16:36:32.000000000 +0000
8897 @@ -0,0 +1,40 @@
8898 +#ifndef _VS_SCHED_H
8899 +#define _VS_SCHED_H
8900 +
8901 +#include "vserver/base.h"
8902 +#include "vserver/context.h"
8903 +#include "vserver/sched.h"
8904 +
8905 +
8906 +#define MAX_PRIO_BIAS           20
8907 +#define MIN_PRIO_BIAS          -20
8908 +
8909 +static inline
8910 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
8911 +{
8912 +       struct vx_info *vxi = p->vx_info;
8913 +
8914 +       if (vxi)
8915 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
8916 +       return prio;
8917 +}
8918 +
8919 +static inline void vx_account_user(struct vx_info *vxi,
8920 +       cputime_t cputime, int nice)
8921 +{
8922 +       if (!vxi)
8923 +               return;
8924 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
8925 +}
8926 +
8927 +static inline void vx_account_system(struct vx_info *vxi,
8928 +       cputime_t cputime, int idle)
8929 +{
8930 +       if (!vxi)
8931 +               return;
8932 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
8933 +}
8934 +
8935 +#else
8936 +#warning duplicate inclusion
8937 +#endif
8938 diff -NurpP --minimal linux-4.4.110/include/linux/vs_socket.h linux-4.4.110-vs2.3.9/include/linux/vs_socket.h
8939 --- linux-4.4.110/include/linux/vs_socket.h     1970-01-01 00:00:00.000000000 +0000
8940 +++ linux-4.4.110-vs2.3.9/include/linux/vs_socket.h     2018-01-09 16:36:32.000000000 +0000
8941 @@ -0,0 +1,67 @@
8942 +#ifndef _VS_SOCKET_H
8943 +#define _VS_SOCKET_H
8944 +
8945 +#include "vserver/debug.h"
8946 +#include "vserver/base.h"
8947 +#include "vserver/cacct.h"
8948 +#include "vserver/context.h"
8949 +#include "vserver/tag.h"
8950 +
8951 +
8952 +/* socket accounting */
8953 +
8954 +#include <linux/socket.h>
8955 +
8956 +static inline int vx_sock_type(int family)
8957 +{
8958 +       switch (family) {
8959 +       case PF_UNSPEC:
8960 +               return VXA_SOCK_UNSPEC;
8961 +       case PF_UNIX:
8962 +               return VXA_SOCK_UNIX;
8963 +       case PF_INET:
8964 +               return VXA_SOCK_INET;
8965 +       case PF_INET6:
8966 +               return VXA_SOCK_INET6;
8967 +       case PF_PACKET:
8968 +               return VXA_SOCK_PACKET;
8969 +       default:
8970 +               return VXA_SOCK_OTHER;
8971 +       }
8972 +}
8973 +
8974 +#define vx_acc_sock(v, f, p, s) \
8975 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
8976 +
8977 +static inline void __vx_acc_sock(struct vx_info *vxi,
8978 +       int family, int pos, int size, char *file, int line)
8979 +{
8980 +       if (vxi) {
8981 +               int type = vx_sock_type(family);
8982 +
8983 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
8984 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
8985 +       }
8986 +}
8987 +
8988 +#define vx_sock_recv(sk, s) \
8989 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
8990 +#define vx_sock_send(sk, s) \
8991 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
8992 +#define vx_sock_fail(sk, s) \
8993 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
8994 +
8995 +
8996 +#define sock_vx_init(s) do {           \
8997 +       (s)->sk_xid = 0;                \
8998 +       (s)->sk_vx_info = NULL;         \
8999 +       } while (0)
9000 +
9001 +#define sock_nx_init(s) do {           \
9002 +       (s)->sk_nid = 0;                \
9003 +       (s)->sk_nx_info = NULL;         \
9004 +       } while (0)
9005 +
9006 +#else
9007 +#warning duplicate inclusion
9008 +#endif
9009 diff -NurpP --minimal linux-4.4.110/include/linux/vs_tag.h linux-4.4.110-vs2.3.9/include/linux/vs_tag.h
9010 --- linux-4.4.110/include/linux/vs_tag.h        1970-01-01 00:00:00.000000000 +0000
9011 +++ linux-4.4.110-vs2.3.9/include/linux/vs_tag.h        2018-01-09 16:36:32.000000000 +0000
9012 @@ -0,0 +1,47 @@
9013 +#ifndef _VS_TAG_H
9014 +#define _VS_TAG_H
9015 +
9016 +#include <linux/vserver/tag.h>
9017 +
9018 +/* check conditions */
9019 +
9020 +#define DX_ADMIN       0x0001
9021 +#define DX_WATCH       0x0002
9022 +#define DX_HOSTID      0x0008
9023 +
9024 +#define DX_IDENT       0x0010
9025 +
9026 +#define DX_ARG_MASK    0x0010
9027 +
9028 +
9029 +#define dx_task_tag(t) ((t)->tag)
9030 +
9031 +#define dx_current_tag() dx_task_tag(current)
9032 +
9033 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
9034 +
9035 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
9036 +
9037 +
9038 +/*
9039 + * check current context for ADMIN/WATCH and
9040 + * optionally against supplied argument
9041 + */
9042 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
9043 +{
9044 +       if (mode & DX_ARG_MASK) {
9045 +               if ((mode & DX_IDENT) && (id == cid))
9046 +                       return 1;
9047 +       }
9048 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
9049 +               ((mode & DX_WATCH) && (cid == 1)) ||
9050 +               ((mode & DX_HOSTID) && (id == 0)));
9051 +}
9052 +
9053 +struct inode;
9054 +int dx_permission(const struct inode *inode, int mask);
9055 +
9056 +
9057 +#else
9058 +#warning duplicate inclusion
9059 +#endif
9060 diff -NurpP --minimal linux-4.4.110/include/linux/vs_time.h linux-4.4.110-vs2.3.9/include/linux/vs_time.h
9061 --- linux-4.4.110/include/linux/vs_time.h       1970-01-01 00:00:00.000000000 +0000
9062 +++ linux-4.4.110-vs2.3.9/include/linux/vs_time.h       2018-01-09 16:36:32.000000000 +0000
9063 @@ -0,0 +1,19 @@
9064 +#ifndef _VS_TIME_H
9065 +#define _VS_TIME_H
9066 +
9067 +
9068 +/* time faking stuff */
9069 +
9070 +#ifdef CONFIG_VSERVER_VTIME
9071 +
9072 +extern void vx_adjust_timespec(struct timespec *ts);
9073 +extern int vx_settimeofday(const struct timespec *ts);
9074 +
9075 +#else
9076 +#define        vx_adjust_timespec(t)   do { } while (0)
9077 +#define        vx_settimeofday(t)      do_settimeofday(t)
9078 +#endif
9079 +
9080 +#else
9081 +#warning duplicate inclusion
9082 +#endif
9083 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/base.h linux-4.4.110-vs2.3.9/include/linux/vserver/base.h
9084 --- linux-4.4.110/include/linux/vserver/base.h  1970-01-01 00:00:00.000000000 +0000
9085 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/base.h  2018-01-09 16:36:32.000000000 +0000
9086 @@ -0,0 +1,184 @@
9087 +#ifndef _VSERVER_BASE_H
9088 +#define _VSERVER_BASE_H
9089 +
9090 +
9091 +/* context state changes */
9092 +
9093 +enum {
9094 +       VSC_STARTUP = 1,
9095 +       VSC_SHUTDOWN,
9096 +
9097 +       VSC_NETUP,
9098 +       VSC_NETDOWN,
9099 +};
9100 +
9101 +
9102 +
9103 +#define vx_task_xid(t) ((t)->xid)
9104 +
9105 +#define vx_current_xid() vx_task_xid(current)
9106 +
9107 +#define current_vx_info() (current->vx_info)
9108 +
9109 +
9110 +#define nx_task_nid(t) ((t)->nid)
9111 +
9112 +#define nx_current_nid() nx_task_nid(current)
9113 +
9114 +#define current_nx_info() (current->nx_info)
9115 +
9116 +
9117 +/* generic flag merging */
9118 +
9119 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
9120 +
9121 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
9122 +
9123 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
9124 +
9125 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
9126 +
9127 +
9128 +/* context flags */
9129 +
9130 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
9131 +
9132 +#define vx_current_flags()     __vx_flags(current_vx_info())
9133 +
9134 +#define vx_info_flags(v, m, f) \
9135 +       vs_check_flags(__vx_flags(v), m, f)
9136 +
9137 +#define task_vx_flags(t, m, f) \
9138 +       ((t) && vx_info_flags((t)->vx_info, m, f))
9139 +
9140 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
9141 +
9142 +
9143 +/* context caps */
9144 +
9145 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
9146 +
9147 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
9148 +
9149 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
9150 +
9151 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
9152 +
9153 +
9154 +
9155 +/* network flags */
9156 +
9157 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
9158 +
9159 +#define nx_current_flags()     __nx_flags(current_nx_info())
9160 +
9161 +#define nx_info_flags(n, m, f) \
9162 +       vs_check_flags(__nx_flags(n), m, f)
9163 +
9164 +#define task_nx_flags(t, m, f) \
9165 +       ((t) && nx_info_flags((t)->nx_info, m, f))
9166 +
9167 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
9168 +
9169 +
9170 +/* network caps */
9171 +
9172 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
9173 +
9174 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
9175 +
9176 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
9177 +
9178 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
9179 +
9180 +
9181 +/* context mask capabilities */
9182 +
9183 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
9184 +
9185 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
9186 +
9187 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
9188 +
9189 +
9190 +/* context bcap mask */
9191 +
9192 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
9193 +
9194 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
9195 +
9196 +
9197 +/* mask given bcaps */
9198 +
9199 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
9200 +
9201 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
9202 +
9203 +
9204 +/* masked cap_bset */
9205 +
9206 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
9207 +
9208 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
9209 +
9210 +#if 0
9211 +#define vx_info_mbcap(v, b) \
9212 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
9213 +       vx_info_bcaps(v, b) : (b))
9214 +
9215 +#define task_vx_mbcap(t, b) \
9216 +       vx_info_mbcap((t)->vx_info, (t)->b)
9217 +
9218 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
9219 +#endif
9220 +
9221 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
9222 +
9223 +#define vx_capable(b, c) (capable(b) || \
9224 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9225 +
9226 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
9227 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9228 +
9229 +#define nx_capable(b, c) (capable(b) || \
9230 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9231 +
9232 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
9233 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9234 +
9235 +#define vx_task_initpid(t, n) \
9236 +       ((t)->vx_info && \
9237 +       ((t)->vx_info->vx_initpid == (n)))
9238 +
9239 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
9240 +
9241 +
9242 +/* context unshare mask */
9243 +
9244 +#define __vx_umask(v)          ((v)->vx_umask)
9245 +
9246 +#define vx_current_umask()     __vx_umask(current_vx_info())
9247 +
9248 +#define vx_can_unshare(b, f) (capable(b) || \
9249 +       (cap_raised(current_cap(), b) && \
9250 +       !((f) & ~vx_current_umask())))
9251 +
9252 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
9253 +       (cap_raised(current_cap(), b) && \
9254 +       !((f) & ~vx_current_umask())))
9255 +
9256 +#define __vx_wmask(v)          ((v)->vx_wmask)
9257 +
9258 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
9259 +
9260 +
9261 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
9262 +
9263 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
9264 +
9265 +
9266 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
9267 +
9268 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
9269 +
9270 +#endif
9271 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/cacct.h linux-4.4.110-vs2.3.9/include/linux/vserver/cacct.h
9272 --- linux-4.4.110/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
9273 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/cacct.h 2018-01-09 16:36:32.000000000 +0000
9274 @@ -0,0 +1,15 @@
9275 +#ifndef _VSERVER_CACCT_H
9276 +#define _VSERVER_CACCT_H
9277 +
9278 +
9279 +enum sock_acc_field {
9280 +       VXA_SOCK_UNSPEC = 0,
9281 +       VXA_SOCK_UNIX,
9282 +       VXA_SOCK_INET,
9283 +       VXA_SOCK_INET6,
9284 +       VXA_SOCK_PACKET,
9285 +       VXA_SOCK_OTHER,
9286 +       VXA_SOCK_SIZE   /* array size */
9287 +};
9288 +
9289 +#endif /* _VSERVER_CACCT_H */
9290 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/cacct_cmd.h linux-4.4.110-vs2.3.9/include/linux/vserver/cacct_cmd.h
9291 --- linux-4.4.110/include/linux/vserver/cacct_cmd.h     1970-01-01 00:00:00.000000000 +0000
9292 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/cacct_cmd.h     2018-01-09 16:36:32.000000000 +0000
9293 @@ -0,0 +1,10 @@
9294 +#ifndef _VSERVER_CACCT_CMD_H
9295 +#define _VSERVER_CACCT_CMD_H
9296 +
9297 +
9298 +#include <linux/compiler.h>
9299 +#include <uapi/vserver/cacct_cmd.h>
9300 +
9301 +extern int vc_sock_stat(struct vx_info *, void __user *);
9302 +
9303 +#endif /* _VSERVER_CACCT_CMD_H */
9304 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/cacct_def.h linux-4.4.110-vs2.3.9/include/linux/vserver/cacct_def.h
9305 --- linux-4.4.110/include/linux/vserver/cacct_def.h     1970-01-01 00:00:00.000000000 +0000
9306 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/cacct_def.h     2018-01-09 16:36:32.000000000 +0000
9307 @@ -0,0 +1,43 @@
9308 +#ifndef _VSERVER_CACCT_DEF_H
9309 +#define _VSERVER_CACCT_DEF_H
9310 +
9311 +#include <asm/atomic.h>
9312 +#include <linux/vserver/cacct.h>
9313 +
9314 +
9315 +struct _vx_sock_acc {
9316 +       atomic_long_t count;
9317 +       atomic_long_t total;
9318 +};
9319 +
9320 +/* context sub struct */
9321 +
9322 +struct _vx_cacct {
9323 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
9324 +       atomic_t slab[8];
9325 +       atomic_t page[6][8];
9326 +};
9327 +
9328 +#ifdef CONFIG_VSERVER_DEBUG
9329 +
9330 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
9331 +{
9332 +       int i, j;
9333 +
9334 +       printk("\t_vx_cacct:");
9335 +       for (i = 0; i < 6; i++) {
9336 +               struct _vx_sock_acc *ptr = cacct->sock[i];
9337 +
9338 +               printk("\t [%d] =", i);
9339 +               for (j = 0; j < 3; j++) {
9340 +                       printk(" [%d] = %8lu, %8lu", j,
9341 +                               atomic_long_read(&ptr[j].count),
9342 +                               atomic_long_read(&ptr[j].total));
9343 +               }
9344 +               printk("\n");
9345 +       }
9346 +}
9347 +
9348 +#endif
9349 +
9350 +#endif /* _VSERVER_CACCT_DEF_H */
9351 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/cacct_int.h linux-4.4.110-vs2.3.9/include/linux/vserver/cacct_int.h
9352 --- linux-4.4.110/include/linux/vserver/cacct_int.h     1970-01-01 00:00:00.000000000 +0000
9353 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/cacct_int.h     2018-01-09 16:36:32.000000000 +0000
9354 @@ -0,0 +1,17 @@
9355 +#ifndef _VSERVER_CACCT_INT_H
9356 +#define _VSERVER_CACCT_INT_H
9357 +
9358 +static inline
9359 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
9360 +{
9361 +       return atomic_long_read(&cacct->sock[type][pos].count);
9362 +}
9363 +
9364 +
9365 +static inline
9366 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
9367 +{
9368 +       return atomic_long_read(&cacct->sock[type][pos].total);
9369 +}
9370 +
9371 +#endif /* _VSERVER_CACCT_INT_H */
9372 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/check.h linux-4.4.110-vs2.3.9/include/linux/vserver/check.h
9373 --- linux-4.4.110/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
9374 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/check.h 2018-01-09 16:36:32.000000000 +0000
9375 @@ -0,0 +1,89 @@
9376 +#ifndef _VSERVER_CHECK_H
9377 +#define _VSERVER_CHECK_H
9378 +
9379 +
9380 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
9381 +
9382 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
9383 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
9384 +#else
9385 +#define MIN_D_CONTEXT  65536
9386 +#endif
9387 +
9388 +/* check conditions */
9389 +
9390 +#define VS_ADMIN       0x0001
9391 +#define VS_WATCH       0x0002
9392 +#define VS_HIDE                0x0004
9393 +#define VS_HOSTID      0x0008
9394 +
9395 +#define VS_IDENT       0x0010
9396 +#define VS_EQUIV       0x0020
9397 +#define VS_PARENT      0x0040
9398 +#define VS_CHILD       0x0080
9399 +
9400 +#define VS_ARG_MASK    0x00F0
9401 +
9402 +#define VS_DYNAMIC     0x0100
9403 +#define VS_STATIC      0x0200
9404 +
9405 +#define VS_ATR_MASK    0x0F00
9406 +
9407 +#ifdef CONFIG_VSERVER_PRIVACY
9408 +#define VS_ADMIN_P     (0)
9409 +#define VS_WATCH_P     (0)
9410 +#else
9411 +#define VS_ADMIN_P     VS_ADMIN
9412 +#define VS_WATCH_P     VS_WATCH
9413 +#endif
9414 +
9415 +#define VS_HARDIRQ     0x1000
9416 +#define VS_SOFTIRQ     0x2000
9417 +#define VS_IRQ         0x4000
9418 +
9419 +#define VS_IRQ_MASK    0xF000
9420 +
9421 +#include <linux/hardirq.h>
9422 +
9423 +/*
9424 + * check current context for ADMIN/WATCH and
9425 + * optionally against supplied argument
9426 + */
9427 +static inline int __vs_check(int cid, int id, unsigned int mode)
9428 +{
9429 +       if (mode & VS_ARG_MASK) {
9430 +               if ((mode & VS_IDENT) && (id == cid))
9431 +                       return 1;
9432 +       }
9433 +       if (mode & VS_ATR_MASK) {
9434 +               if ((mode & VS_DYNAMIC) &&
9435 +                       (id >= MIN_D_CONTEXT) &&
9436 +                       (id <= MAX_S_CONTEXT))
9437 +                       return 1;
9438 +               if ((mode & VS_STATIC) &&
9439 +                       (id > 1) && (id < MIN_D_CONTEXT))
9440 +                       return 1;
9441 +       }
9442 +       if (mode & VS_IRQ_MASK) {
9443 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
9444 +                       return 1;
9445 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
9446 +                       return 1;
9447 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
9448 +                       return 1;
9449 +       }
9450 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
9451 +               ((mode & VS_WATCH) && (cid == 1)) ||
9452 +               ((mode & VS_HOSTID) && (id == 0)));
9453 +}
9454 +
9455 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
9456 +
9457 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
9458 +
9459 +
9460 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
9461 +
9462 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
9463 +
9464 +#endif
9465 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/context.h linux-4.4.110-vs2.3.9/include/linux/vserver/context.h
9466 --- linux-4.4.110/include/linux/vserver/context.h       1970-01-01 00:00:00.000000000 +0000
9467 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/context.h       2018-01-09 16:36:32.000000000 +0000
9468 @@ -0,0 +1,110 @@
9469 +#ifndef _VSERVER_CONTEXT_H
9470 +#define _VSERVER_CONTEXT_H
9471 +
9472 +
9473 +#include <linux/list.h>
9474 +#include <linux/spinlock.h>
9475 +#include <linux/rcupdate.h>
9476 +#include <uapi/vserver/context.h>
9477 +
9478 +#include "limit_def.h"
9479 +#include "sched_def.h"
9480 +#include "cvirt_def.h"
9481 +#include "cacct_def.h"
9482 +#include "device_def.h"
9483 +
9484 +#define VX_SPACES      2
9485 +
9486 +struct _vx_info_pc {
9487 +       struct _vx_sched_pc sched_pc;
9488 +       struct _vx_cvirt_pc cvirt_pc;
9489 +};
9490 +
9491 +struct _vx_space {
9492 +       unsigned long vx_nsmask;                /* assignment mask */
9493 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
9494 +       struct fs_struct *vx_fs;                /* private namespace fs */
9495 +       const struct cred *vx_cred;             /* task credentials */
9496 +};
9497 +
9498 +struct vx_info {
9499 +       struct hlist_node vx_hlist;             /* linked list of contexts */
9500 +       vxid_t vx_id;                           /* context id */
9501 +       atomic_t vx_usecnt;                     /* usage count */
9502 +       atomic_t vx_tasks;                      /* tasks count */
9503 +       struct vx_info *vx_parent;              /* parent context */
9504 +       int vx_state;                           /* context state */
9505 +
9506 +       struct _vx_space space[VX_SPACES];      /* namespace store */
9507 +
9508 +       uint64_t vx_flags;                      /* context flags */
9509 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
9510 +       uint64_t vx_umask;                      /* unshare mask (guest) */
9511 +       uint64_t vx_wmask;                      /* warn mask (guest) */
9512 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
9513 +
9514 +       struct task_struct *vx_reaper;          /* guest reaper process */
9515 +       pid_t vx_initpid;                       /* PID of guest init */
9516 +       int64_t vx_badness_bias;                /* OOM points bias */
9517 +
9518 +       struct _vx_limit limit;                 /* vserver limits */
9519 +       struct _vx_sched sched;                 /* vserver scheduler */
9520 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
9521 +       struct _vx_cacct cacct;                 /* context accounting */
9522 +
9523 +       struct _vx_device dmap;                 /* default device map targets */
9524 +
9525 +#ifndef CONFIG_SMP
9526 +       struct _vx_info_pc info_pc;             /* per cpu data */
9527 +#else
9528 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
9529 +#endif
9530 +
9531 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
9532 +       int reboot_cmd;                         /* last sys_reboot() cmd */
9533 +       int exit_code;                          /* last process exit code */
9534 +
9535 +       char vx_name[65];                       /* vserver name */
9536 +};
9537 +
9538 +#ifndef CONFIG_SMP
9539 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
9540 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
9541 +#else
9542 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
9543 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
9544 +#endif
9545 +
9546 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
9547 +
9548 +
9549 +struct vx_info_save {
9550 +       struct vx_info *vxi;
9551 +       vxid_t xid;
9552 +};
9553 +
9554 +
9555 +/* status flags */
9556 +
9557 +#define VXS_HASHED     0x0001
9558 +#define VXS_PAUSED     0x0010
9559 +#define VXS_SHUTDOWN   0x0100
9560 +#define VXS_HELPER     0x1000
9561 +#define VXS_RELEASED   0x8000
9562 +
9563 +
9564 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
9565 +extern void release_vx_info(struct vx_info *, struct task_struct *);
9566 +
9567 +extern struct vx_info *lookup_vx_info(int);
9568 +extern struct vx_info *lookup_or_create_vx_info(int);
9569 +
9570 +extern int get_xid_list(int, unsigned int *, int);
9571 +extern int xid_is_hashed(vxid_t);
9572 +
9573 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
9574 +
9575 +extern long vs_state_change(struct vx_info *, unsigned int);
9576 +
9577 +
9578 +#endif /* _VSERVER_CONTEXT_H */
9579 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/context_cmd.h linux-4.4.110-vs2.3.9/include/linux/vserver/context_cmd.h
9580 --- linux-4.4.110/include/linux/vserver/context_cmd.h   1970-01-01 00:00:00.000000000 +0000
9581 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/context_cmd.h   2018-01-09 16:36:32.000000000 +0000
9582 @@ -0,0 +1,33 @@
9583 +#ifndef _VSERVER_CONTEXT_CMD_H
9584 +#define _VSERVER_CONTEXT_CMD_H
9585 +
9586 +#include <uapi/vserver/context_cmd.h>
9587 +
9588 +extern int vc_task_xid(uint32_t);
9589 +
9590 +extern int vc_vx_info(struct vx_info *, void __user *);
9591 +
9592 +extern int vc_ctx_stat(struct vx_info *, void __user *);
9593 +
9594 +extern int vc_ctx_create(uint32_t, void __user *);
9595 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
9596 +
9597 +extern int vc_get_cflags(struct vx_info *, void __user *);
9598 +extern int vc_set_cflags(struct vx_info *, void __user *);
9599 +
9600 +extern int vc_get_ccaps(struct vx_info *, void __user *);
9601 +extern int vc_set_ccaps(struct vx_info *, void __user *);
9602 +
9603 +extern int vc_get_bcaps(struct vx_info *, void __user *);
9604 +extern int vc_set_bcaps(struct vx_info *, void __user *);
9605 +
9606 +extern int vc_get_umask(struct vx_info *, void __user *);
9607 +extern int vc_set_umask(struct vx_info *, void __user *);
9608 +
9609 +extern int vc_get_wmask(struct vx_info *, void __user *);
9610 +extern int vc_set_wmask(struct vx_info *, void __user *);
9611 +
9612 +extern int vc_get_badness(struct vx_info *, void __user *);
9613 +extern int vc_set_badness(struct vx_info *, void __user *);
9614 +
9615 +#endif /* _VSERVER_CONTEXT_CMD_H */
9616 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/cvirt.h linux-4.4.110-vs2.3.9/include/linux/vserver/cvirt.h
9617 --- linux-4.4.110/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
9618 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/cvirt.h 2018-01-09 16:36:32.000000000 +0000
9619 @@ -0,0 +1,18 @@
9620 +#ifndef _VSERVER_CVIRT_H
9621 +#define _VSERVER_CVIRT_H
9622 +
9623 +struct timespec;
9624 +
9625 +void vx_vsi_boottime(struct timespec *);
9626 +
9627 +void vx_vsi_uptime(struct timespec *, struct timespec *);
9628 +
9629 +
9630 +struct vx_info;
9631 +
9632 +void vx_update_load(struct vx_info *);
9633 +
9634 +
9635 +int vx_do_syslog(int, char __user *, int);
9636 +
9637 +#endif /* _VSERVER_CVIRT_H */
9638 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/cvirt_cmd.h linux-4.4.110-vs2.3.9/include/linux/vserver/cvirt_cmd.h
9639 --- linux-4.4.110/include/linux/vserver/cvirt_cmd.h     1970-01-01 00:00:00.000000000 +0000
9640 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/cvirt_cmd.h     2018-01-09 16:36:32.000000000 +0000
9641 @@ -0,0 +1,13 @@
9642 +#ifndef _VSERVER_CVIRT_CMD_H
9643 +#define _VSERVER_CVIRT_CMD_H
9644 +
9645 +
9646 +#include <linux/compiler.h>
9647 +#include <uapi/vserver/cvirt_cmd.h>
9648 +
9649 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
9650 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
9651 +
9652 +extern int vc_virt_stat(struct vx_info *, void __user *);
9653 +
9654 +#endif /* _VSERVER_CVIRT_CMD_H */
9655 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/cvirt_def.h linux-4.4.110-vs2.3.9/include/linux/vserver/cvirt_def.h
9656 --- linux-4.4.110/include/linux/vserver/cvirt_def.h     1970-01-01 00:00:00.000000000 +0000
9657 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/cvirt_def.h     2018-01-09 16:36:32.000000000 +0000
9658 @@ -0,0 +1,80 @@
9659 +#ifndef _VSERVER_CVIRT_DEF_H
9660 +#define _VSERVER_CVIRT_DEF_H
9661 +
9662 +#include <linux/jiffies.h>
9663 +#include <linux/spinlock.h>
9664 +#include <linux/wait.h>
9665 +#include <linux/time.h>
9666 +#include <asm/atomic.h>
9667 +
9668 +
9669 +struct _vx_usage_stat {
9670 +       uint64_t user;
9671 +       uint64_t nice;
9672 +       uint64_t system;
9673 +       uint64_t softirq;
9674 +       uint64_t irq;
9675 +       uint64_t idle;
9676 +       uint64_t iowait;
9677 +};
9678 +
9679 +struct _vx_syslog {
9680 +       wait_queue_head_t log_wait;
9681 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
9682 +
9683 +       unsigned long log_start;        /* next char to be read by syslog() */
9684 +       unsigned long con_start;        /* next char to be sent to consoles */
9685 +       unsigned long log_end;  /* most-recently-written-char + 1 */
9686 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
9687 +
9688 +       char log_buf[1024];
9689 +};
9690 +
9691 +
9692 +/* context sub struct */
9693 +
9694 +struct _vx_cvirt {
9695 +       atomic_t nr_threads;            /* number of current threads */
9696 +       atomic_t nr_running;            /* number of running threads */
9697 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
9698 +
9699 +       atomic_t nr_onhold;             /* processes on hold */
9700 +       uint32_t onhold_last;           /* jiffies when put on hold */
9701 +
9702 +       struct timespec bias_ts;        /* time offset to the host */
9703 +       struct timespec bias_idle;
9704 +       struct timespec bias_uptime;    /* context creation point */
9705 +       uint64_t bias_clock;            /* offset in clock_t */
9706 +
9707 +       spinlock_t load_lock;           /* lock for the load averages */
9708 +       atomic_t load_updates;          /* nr of load updates done so far */
9709 +       uint32_t load_last;             /* last time load was calculated */
9710 +       uint32_t load[3];               /* load averages 1,5,15 */
9711 +
9712 +       atomic_t total_forks;           /* number of forks so far */
9713 +
9714 +       struct _vx_syslog syslog;
9715 +};
9716 +
9717 +struct _vx_cvirt_pc {
9718 +       struct _vx_usage_stat cpustat;
9719 +};
9720 +
9721 +
9722 +#ifdef CONFIG_VSERVER_DEBUG
9723 +
9724 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
9725 +{
9726 +       printk("\t_vx_cvirt:\n");
9727 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
9728 +               atomic_read(&cvirt->nr_threads),
9729 +               atomic_read(&cvirt->nr_running),
9730 +               atomic_read(&cvirt->nr_uninterruptible),
9731 +               atomic_read(&cvirt->nr_onhold));
9732 +       /* add rest here */
9733 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
9734 +}
9735 +
9736 +#endif
9737 +
9738 +#endif /* _VSERVER_CVIRT_DEF_H */
9739 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/debug.h linux-4.4.110-vs2.3.9/include/linux/vserver/debug.h
9740 --- linux-4.4.110/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
9741 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/debug.h 2018-01-09 16:36:32.000000000 +0000
9742 @@ -0,0 +1,146 @@
9743 +#ifndef _VSERVER_DEBUG_H
9744 +#define _VSERVER_DEBUG_H
9745 +
9746 +
9747 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
9748 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
9749 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
9750 +
9751 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
9752 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
9753 +#define VXF_DEV                "%p[%lu,%d:%d]"
9754 +
9755 +#if    defined(CONFIG_QUOTES_UTF8)
9756 +#define        VS_Q_LQM        "\xc2\xbb"
9757 +#define        VS_Q_RQM        "\xc2\xab"
9758 +#elif  defined(CONFIG_QUOTES_ASCII)
9759 +#define        VS_Q_LQM        "\x27"
9760 +#define        VS_Q_RQM        "\x27"
9761 +#else
9762 +#define        VS_Q_LQM        "\xbb"
9763 +#define        VS_Q_RQM        "\xab"
9764 +#endif
9765 +
9766 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
9767 +
9768 +
9769 +#define vxd_path(p)                                            \
9770 +       ({ static char _buffer[PATH_MAX];                       \
9771 +          d_path(p, _buffer, sizeof(_buffer)); })
9772 +
9773 +#define vxd_cond_path(n)                                       \
9774 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
9775 +
9776 +
9777 +#ifdef CONFIG_VSERVER_DEBUG
9778 +
9779 +extern unsigned int vs_debug_switch;
9780 +extern unsigned int vs_debug_xid;
9781 +extern unsigned int vs_debug_nid;
9782 +extern unsigned int vs_debug_tag;
9783 +extern unsigned int vs_debug_net;
9784 +extern unsigned int vs_debug_limit;
9785 +extern unsigned int vs_debug_cres;
9786 +extern unsigned int vs_debug_dlim;
9787 +extern unsigned int vs_debug_quota;
9788 +extern unsigned int vs_debug_cvirt;
9789 +extern unsigned int vs_debug_space;
9790 +extern unsigned int vs_debug_perm;
9791 +extern unsigned int vs_debug_misc;
9792 +
9793 +
9794 +#define VX_LOGLEVEL    "vxD: "
9795 +#define VX_PROC_FMT    "%p: "
9796 +#define VX_PROCESS     current
9797 +
9798 +#define vxdprintk(c, f, x...)                                  \
9799 +       do {                                                    \
9800 +               if (c)                                          \
9801 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
9802 +                               VX_PROCESS , ##x);              \
9803 +       } while (0)
9804 +
9805 +#define vxlprintk(c, f, x...)                                  \
9806 +       do {                                                    \
9807 +               if (c)                                          \
9808 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
9809 +       } while (0)
9810 +
9811 +#define vxfprintk(c, f, x...)                                  \
9812 +       do {                                                    \
9813 +               if (c)                                          \
9814 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
9815 +       } while (0)
9816 +
9817 +
9818 +struct vx_info;
9819 +
9820 +void dump_vx_info(struct vx_info *, int);
9821 +void dump_vx_info_inactive(int);
9822 +
9823 +#else  /* CONFIG_VSERVER_DEBUG */
9824 +
9825 +#define vs_debug_switch        0
9826 +#define vs_debug_xid   0
9827 +#define vs_debug_nid   0
9828 +#define vs_debug_tag   0
9829 +#define vs_debug_net   0
9830 +#define vs_debug_limit 0
9831 +#define vs_debug_cres  0
9832 +#define vs_debug_dlim  0
9833 +#define vs_debug_quota 0
9834 +#define vs_debug_cvirt 0
9835 +#define vs_debug_space 0
9836 +#define vs_debug_perm  0
9837 +#define vs_debug_misc  0
9838 +
9839 +#define vxdprintk(x...) do { } while (0)
9840 +#define vxlprintk(x...) do { } while (0)
9841 +#define vxfprintk(x...) do { } while (0)
9842 +
9843 +#endif /* CONFIG_VSERVER_DEBUG */
9844 +
9845 +
9846 +#ifdef CONFIG_VSERVER_WARN
9847 +
9848 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
9849 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
9850 +#define VX_WARN_XID    "[xid #%u] "
9851 +#define VX_WARN_NID    "[nid #%u] "
9852 +#define VX_WARN_TAG    "[tag #%u] "
9853 +
9854 +#define vxwprintk(c, f, x...)                                  \
9855 +       do {                                                    \
9856 +               if (c)                                          \
9857 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
9858 +       } while (0)
9859 +
9860 +#else  /* CONFIG_VSERVER_WARN */
9861 +
9862 +#define vxwprintk(x...) do { } while (0)
9863 +
9864 +#endif /* CONFIG_VSERVER_WARN */
9865 +
9866 +#define vxwprintk_task(c, f, x...)                             \
9867 +       vxwprintk(c, VX_WARN_TASK f,                            \
9868 +               current->comm, current->pid,                    \
9869 +               current->xid, current->nid,                     \
9870 +               current->tag, ##x)
9871 +#define vxwprintk_xid(c, f, x...)                              \
9872 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
9873 +#define vxwprintk_nid(c, f, x...)                              \
9874 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
9875 +#define vxwprintk_tag(c, f, x...)                              \
9876 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
9877 +
9878 +#ifdef CONFIG_VSERVER_DEBUG
9879 +#define vxd_assert_lock(l)     assert_spin_locked(l)
9880 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
9881 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
9882 +#else
9883 +#define vxd_assert_lock(l)     do { } while (0)
9884 +#define vxd_assert(c, f, x...) do { } while (0)
9885 +#endif
9886 +
9887 +
9888 +#endif /* _VSERVER_DEBUG_H */
9889 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/debug_cmd.h linux-4.4.110-vs2.3.9/include/linux/vserver/debug_cmd.h
9890 --- linux-4.4.110/include/linux/vserver/debug_cmd.h     1970-01-01 00:00:00.000000000 +0000
9891 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/debug_cmd.h     2018-01-09 16:36:32.000000000 +0000
9892 @@ -0,0 +1,37 @@
9893 +#ifndef _VSERVER_DEBUG_CMD_H
9894 +#define _VSERVER_DEBUG_CMD_H
9895 +
9896 +#include <uapi/vserver/debug_cmd.h>
9897 +
9898 +
9899 +#ifdef CONFIG_COMPAT
9900 +
9901 +#include <asm/compat.h>
9902 +
9903 +struct vcmd_read_history_v0_x32 {
9904 +       uint32_t index;
9905 +       uint32_t count;
9906 +       compat_uptr_t data_ptr;
9907 +};
9908 +
9909 +struct vcmd_read_monitor_v0_x32 {
9910 +       uint32_t index;
9911 +       uint32_t count;
9912 +       compat_uptr_t data_ptr;
9913 +};
9914 +
9915 +#endif  /* CONFIG_COMPAT */
9916 +
9917 +extern int vc_dump_history(uint32_t);
9918 +
9919 +extern int vc_read_history(uint32_t, void __user *);
9920 +extern int vc_read_monitor(uint32_t, void __user *);
9921 +
9922 +#ifdef CONFIG_COMPAT
9923 +
9924 +extern int vc_read_history_x32(uint32_t, void __user *);
9925 +extern int vc_read_monitor_x32(uint32_t, void __user *);
9926 +
9927 +#endif  /* CONFIG_COMPAT */
9928 +
9929 +#endif /* _VSERVER_DEBUG_CMD_H */
9930 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/device.h linux-4.4.110-vs2.3.9/include/linux/vserver/device.h
9931 --- linux-4.4.110/include/linux/vserver/device.h        1970-01-01 00:00:00.000000000 +0000
9932 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/device.h        2018-01-09 16:36:32.000000000 +0000
9933 @@ -0,0 +1,9 @@
9934 +#ifndef _VSERVER_DEVICE_H
9935 +#define _VSERVER_DEVICE_H
9936 +
9937 +
9938 +#include <uapi/vserver/device.h>
9939 +
9940 +#else  /* _VSERVER_DEVICE_H */
9941 +#warning duplicate inclusion
9942 +#endif /* _VSERVER_DEVICE_H */
9943 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/device_cmd.h linux-4.4.110-vs2.3.9/include/linux/vserver/device_cmd.h
9944 --- linux-4.4.110/include/linux/vserver/device_cmd.h    1970-01-01 00:00:00.000000000 +0000
9945 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/device_cmd.h    2018-01-09 16:36:32.000000000 +0000
9946 @@ -0,0 +1,31 @@
9947 +#ifndef _VSERVER_DEVICE_CMD_H
9948 +#define _VSERVER_DEVICE_CMD_H
9949 +
9950 +#include <uapi/vserver/device_cmd.h>
9951 +
9952 +
9953 +#ifdef CONFIG_COMPAT
9954 +
9955 +#include <asm/compat.h>
9956 +
9957 +struct vcmd_set_mapping_v0_x32 {
9958 +       compat_uptr_t device_ptr;
9959 +       compat_uptr_t target_ptr;
9960 +       uint32_t flags;
9961 +};
9962 +
9963 +#endif /* CONFIG_COMPAT */
9964 +
9965 +#include <linux/compiler.h>
9966 +
9967 +extern int vc_set_mapping(struct vx_info *, void __user *);
9968 +extern int vc_unset_mapping(struct vx_info *, void __user *);
9969 +
9970 +#ifdef CONFIG_COMPAT
9971 +
9972 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
9973 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
9974 +
9975 +#endif /* CONFIG_COMPAT */
9976 +
9977 +#endif /* _VSERVER_DEVICE_CMD_H */
9978 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/device_def.h linux-4.4.110-vs2.3.9/include/linux/vserver/device_def.h
9979 --- linux-4.4.110/include/linux/vserver/device_def.h    1970-01-01 00:00:00.000000000 +0000
9980 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/device_def.h    2018-01-09 16:36:32.000000000 +0000
9981 @@ -0,0 +1,17 @@
9982 +#ifndef _VSERVER_DEVICE_DEF_H
9983 +#define _VSERVER_DEVICE_DEF_H
9984 +
9985 +#include <linux/types.h>
9986 +
9987 +struct vx_dmap_target {
9988 +       dev_t target;
9989 +       uint32_t flags;
9990 +};
9991 +
9992 +struct _vx_device {
9993 +#ifdef CONFIG_VSERVER_DEVICE
9994 +       struct vx_dmap_target targets[2];
9995 +#endif
9996 +};
9997 +
9998 +#endif /* _VSERVER_DEVICE_DEF_H */
9999 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/dlimit.h linux-4.4.110-vs2.3.9/include/linux/vserver/dlimit.h
10000 --- linux-4.4.110/include/linux/vserver/dlimit.h        1970-01-01 00:00:00.000000000 +0000
10001 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/dlimit.h        2018-01-09 16:36:32.000000000 +0000
10002 @@ -0,0 +1,54 @@
10003 +#ifndef _VSERVER_DLIMIT_H
10004 +#define _VSERVER_DLIMIT_H
10005 +
10006 +#include "switch.h"
10007 +
10008 +
10009 +#ifdef __KERNEL__
10010 +
10011 +/*      keep in sync with CDLIM_INFINITY       */
10012 +
10013 +#define DLIM_INFINITY          (~0ULL)
10014 +
10015 +#include <linux/spinlock.h>
10016 +#include <linux/rcupdate.h>
10017 +
10018 +struct super_block;
10019 +
10020 +struct dl_info {
10021 +       struct hlist_node dl_hlist;             /* linked list of contexts */
10022 +       struct rcu_head dl_rcu;                 /* the rcu head */
10023 +       vtag_t dl_tag;                          /* context tag */
10024 +       atomic_t dl_usecnt;                     /* usage count */
10025 +       atomic_t dl_refcnt;                     /* reference count */
10026 +
10027 +       struct super_block *dl_sb;              /* associated superblock */
10028 +
10029 +       spinlock_t dl_lock;                     /* protect the values */
10030 +
10031 +       unsigned long long dl_space_used;       /* used space in bytes */
10032 +       unsigned long long dl_space_total;      /* maximum space in bytes */
10033 +       unsigned long dl_inodes_used;           /* used inodes */
10034 +       unsigned long dl_inodes_total;          /* maximum inodes */
10035 +
10036 +       unsigned int dl_nrlmult;                /* non root limit mult */
10037 +};
10038 +
10039 +struct rcu_head;
10040 +
10041 +extern void rcu_free_dl_info(struct rcu_head *);
10042 +extern void unhash_dl_info(struct dl_info *);
10043 +
10044 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
10045 +
10046 +
10047 +struct kstatfs;
10048 +
10049 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
10050 +
10051 +typedef uint64_t dlsize_t;
10052 +
10053 +#endif /* __KERNEL__ */
10054 +#else  /* _VSERVER_DLIMIT_H */
10055 +#warning duplicate inclusion
10056 +#endif /* _VSERVER_DLIMIT_H */
10057 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/dlimit_cmd.h linux-4.4.110-vs2.3.9/include/linux/vserver/dlimit_cmd.h
10058 --- linux-4.4.110/include/linux/vserver/dlimit_cmd.h    1970-01-01 00:00:00.000000000 +0000
10059 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/dlimit_cmd.h    2018-01-09 16:36:32.000000000 +0000
10060 @@ -0,0 +1,46 @@
10061 +#ifndef _VSERVER_DLIMIT_CMD_H
10062 +#define _VSERVER_DLIMIT_CMD_H
10063 +
10064 +#include <uapi/vserver/dlimit_cmd.h>
10065 +
10066 +
10067 +#ifdef CONFIG_COMPAT
10068 +
10069 +#include <asm/compat.h>
10070 +
10071 +struct vcmd_ctx_dlimit_base_v0_x32 {
10072 +       compat_uptr_t name_ptr;
10073 +       uint32_t flags;
10074 +};
10075 +
10076 +struct vcmd_ctx_dlimit_v0_x32 {
10077 +       compat_uptr_t name_ptr;
10078 +       uint32_t space_used;                    /* used space in kbytes */
10079 +       uint32_t space_total;                   /* maximum space in kbytes */
10080 +       uint32_t inodes_used;                   /* used inodes */
10081 +       uint32_t inodes_total;                  /* maximum inodes */
10082 +       uint32_t reserved;                      /* reserved for root in % */
10083 +       uint32_t flags;
10084 +};
10085 +
10086 +#endif /* CONFIG_COMPAT */
10087 +
10088 +#include <linux/compiler.h>
10089 +
10090 +extern int vc_add_dlimit(uint32_t, void __user *);
10091 +extern int vc_rem_dlimit(uint32_t, void __user *);
10092 +
10093 +extern int vc_set_dlimit(uint32_t, void __user *);
10094 +extern int vc_get_dlimit(uint32_t, void __user *);
10095 +
10096 +#ifdef CONFIG_COMPAT
10097 +
10098 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
10099 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
10100 +
10101 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
10102 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
10103 +
10104 +#endif /* CONFIG_COMPAT */
10105 +
10106 +#endif /* _VSERVER_DLIMIT_CMD_H */
10107 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/global.h linux-4.4.110-vs2.3.9/include/linux/vserver/global.h
10108 --- linux-4.4.110/include/linux/vserver/global.h        1970-01-01 00:00:00.000000000 +0000
10109 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/global.h        2018-01-09 16:36:32.000000000 +0000
10110 @@ -0,0 +1,19 @@
10111 +#ifndef _VSERVER_GLOBAL_H
10112 +#define _VSERVER_GLOBAL_H
10113 +
10114 +
10115 +extern atomic_t vx_global_ctotal;
10116 +extern atomic_t vx_global_cactive;
10117 +
10118 +extern atomic_t nx_global_ctotal;
10119 +extern atomic_t nx_global_cactive;
10120 +
10121 +extern atomic_t vs_global_nsproxy;
10122 +extern atomic_t vs_global_fs;
10123 +extern atomic_t vs_global_mnt_ns;
10124 +extern atomic_t vs_global_uts_ns;
10125 +extern atomic_t vs_global_user_ns;
10126 +extern atomic_t vs_global_pid_ns;
10127 +
10128 +
10129 +#endif /* _VSERVER_GLOBAL_H */
10130 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/history.h linux-4.4.110-vs2.3.9/include/linux/vserver/history.h
10131 --- linux-4.4.110/include/linux/vserver/history.h       1970-01-01 00:00:00.000000000 +0000
10132 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/history.h       2018-01-09 16:36:32.000000000 +0000
10133 @@ -0,0 +1,197 @@
10134 +#ifndef _VSERVER_HISTORY_H
10135 +#define _VSERVER_HISTORY_H
10136 +
10137 +
10138 +enum {
10139 +       VXH_UNUSED = 0,
10140 +       VXH_THROW_OOPS = 1,
10141 +
10142 +       VXH_GET_VX_INFO,
10143 +       VXH_PUT_VX_INFO,
10144 +       VXH_INIT_VX_INFO,
10145 +       VXH_SET_VX_INFO,
10146 +       VXH_CLR_VX_INFO,
10147 +       VXH_CLAIM_VX_INFO,
10148 +       VXH_RELEASE_VX_INFO,
10149 +       VXH_ALLOC_VX_INFO,
10150 +       VXH_DEALLOC_VX_INFO,
10151 +       VXH_HASH_VX_INFO,
10152 +       VXH_UNHASH_VX_INFO,
10153 +       VXH_LOC_VX_INFO,
10154 +       VXH_LOOKUP_VX_INFO,
10155 +       VXH_CREATE_VX_INFO,
10156 +};
10157 +
10158 +struct _vxhe_vxi {
10159 +       struct vx_info *ptr;
10160 +       unsigned xid;
10161 +       unsigned usecnt;
10162 +       unsigned tasks;
10163 +};
10164 +
10165 +struct _vxhe_set_clr {
10166 +       void *data;
10167 +};
10168 +
10169 +struct _vxhe_loc_lookup {
10170 +       unsigned arg;
10171 +};
10172 +
10173 +struct _vx_hist_entry {
10174 +       void *loc;
10175 +       unsigned short seq;
10176 +       unsigned short type;
10177 +       struct _vxhe_vxi vxi;
10178 +       union {
10179 +               struct _vxhe_set_clr sc;
10180 +               struct _vxhe_loc_lookup ll;
10181 +       };
10182 +};
10183 +
10184 +#ifdef CONFIG_VSERVER_HISTORY
10185 +
10186 +extern unsigned volatile int vxh_active;
10187 +
10188 +struct _vx_hist_entry *vxh_advance(void *loc);
10189 +
10190 +
10191 +static inline
10192 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
10193 +{
10194 +       entry->vxi.ptr = vxi;
10195 +       if (vxi) {
10196 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
10197 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
10198 +               entry->vxi.xid = vxi->vx_id;
10199 +       }
10200 +}
10201 +
10202 +
10203 +#define        __HERE__ current_text_addr()
10204 +
10205 +#define __VXH_BODY(__type, __data, __here)     \
10206 +       struct _vx_hist_entry *entry;           \
10207 +                                               \
10208 +       preempt_disable();                      \
10209 +       entry = vxh_advance(__here);            \
10210 +       __data;                                 \
10211 +       entry->type = __type;                   \
10212 +       preempt_enable();
10213 +
10214 +
10215 +       /* pass vxi only */
10216 +
10217 +#define __VXH_SMPL                             \
10218 +       __vxh_copy_vxi(entry, vxi)
10219 +
10220 +static inline
10221 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
10222 +{
10223 +       __VXH_BODY(__type, __VXH_SMPL, __here)
10224 +}
10225 +
10226 +       /* pass vxi and data (void *) */
10227 +
10228 +#define __VXH_DATA                             \
10229 +       __vxh_copy_vxi(entry, vxi);             \
10230 +       entry->sc.data = data
10231 +
10232 +static inline
10233 +void   __vxh_data(struct vx_info *vxi, void *data,
10234 +                       int __type, void *__here)
10235 +{
10236 +       __VXH_BODY(__type, __VXH_DATA, __here)
10237 +}
10238 +
10239 +       /* pass vxi and arg (long) */
10240 +
10241 +#define __VXH_LONG                             \
10242 +       __vxh_copy_vxi(entry, vxi);             \
10243 +       entry->ll.arg = arg
10244 +
10245 +static inline
10246 +void   __vxh_long(struct vx_info *vxi, long arg,
10247 +                       int __type, void *__here)
10248 +{
10249 +       __VXH_BODY(__type, __VXH_LONG, __here)
10250 +}
10251 +
10252 +
10253 +static inline
10254 +void   __vxh_throw_oops(void *__here)
10255 +{
10256 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
10257 +       /* prevent further acquisition */
10258 +       vxh_active = 0;
10259 +}
10260 +
10261 +
10262 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
10263 +
10264 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
10265 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
10266 +
10267 +#define __vxh_init_vx_info(v, d, h) \
10268 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
10269 +#define __vxh_set_vx_info(v, d, h) \
10270 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
10271 +#define __vxh_clr_vx_info(v, d, h) \
10272 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
10273 +
10274 +#define __vxh_claim_vx_info(v, d, h) \
10275 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
10276 +#define __vxh_release_vx_info(v, d, h) \
10277 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
10278 +
10279 +#define vxh_alloc_vx_info(v) \
10280 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
10281 +#define vxh_dealloc_vx_info(v) \
10282 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
10283 +
10284 +#define vxh_hash_vx_info(v) \
10285 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
10286 +#define vxh_unhash_vx_info(v) \
10287 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
10288 +
10289 +#define vxh_loc_vx_info(v, l) \
10290 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
10291 +#define vxh_lookup_vx_info(v, l) \
10292 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
10293 +#define vxh_create_vx_info(v, l) \
10294 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
10295 +
10296 +extern void vxh_dump_history(void);
10297 +
10298 +
10299 +#else  /* CONFIG_VSERVER_HISTORY */
10300 +
10301 +#define        __HERE__        0
10302 +
10303 +#define vxh_throw_oops()               do { } while (0)
10304 +
10305 +#define __vxh_get_vx_info(v, h)                do { } while (0)
10306 +#define __vxh_put_vx_info(v, h)                do { } while (0)
10307 +
10308 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
10309 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
10310 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
10311 +
10312 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
10313 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
10314 +
10315 +#define vxh_alloc_vx_info(v)           do { } while (0)
10316 +#define vxh_dealloc_vx_info(v)         do { } while (0)
10317 +
10318 +#define vxh_hash_vx_info(v)            do { } while (0)
10319 +#define vxh_unhash_vx_info(v)          do { } while (0)
10320 +
10321 +#define vxh_loc_vx_info(v, l)          do { } while (0)
10322 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
10323 +#define vxh_create_vx_info(v, l)       do { } while (0)
10324 +
10325 +#define vxh_dump_history()             do { } while (0)
10326 +
10327 +
10328 +#endif /* CONFIG_VSERVER_HISTORY */
10329 +
10330 +#endif /* _VSERVER_HISTORY_H */
10331 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/inode.h linux-4.4.110-vs2.3.9/include/linux/vserver/inode.h
10332 --- linux-4.4.110/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
10333 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/inode.h 2018-01-09 16:36:32.000000000 +0000
10334 @@ -0,0 +1,19 @@
10335 +#ifndef _VSERVER_INODE_H
10336 +#define _VSERVER_INODE_H
10337 +
10338 +#include <uapi/vserver/inode.h>
10339 +
10340 +
10341 +#ifdef CONFIG_VSERVER_PROC_SECURE
10342 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
10343 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10344 +#else
10345 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
10346 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10347 +#endif
10348 +
10349 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
10350 +
10351 +#else  /* _VSERVER_INODE_H */
10352 +#warning duplicate inclusion
10353 +#endif /* _VSERVER_INODE_H */
10354 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/inode_cmd.h linux-4.4.110-vs2.3.9/include/linux/vserver/inode_cmd.h
10355 --- linux-4.4.110/include/linux/vserver/inode_cmd.h     1970-01-01 00:00:00.000000000 +0000
10356 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/inode_cmd.h     2018-01-09 16:36:32.000000000 +0000
10357 @@ -0,0 +1,36 @@
10358 +#ifndef _VSERVER_INODE_CMD_H
10359 +#define _VSERVER_INODE_CMD_H
10360 +
10361 +#include <uapi/vserver/inode_cmd.h>
10362 +
10363 +
10364 +
10365 +#ifdef CONFIG_COMPAT
10366 +
10367 +#include <asm/compat.h>
10368 +
10369 +struct vcmd_ctx_iattr_v1_x32 {
10370 +       compat_uptr_t name_ptr;
10371 +       uint32_t tag;
10372 +       uint32_t flags;
10373 +       uint32_t mask;
10374 +};
10375 +
10376 +#endif /* CONFIG_COMPAT */
10377 +
10378 +#include <linux/compiler.h>
10379 +
10380 +extern int vc_get_iattr(void __user *);
10381 +extern int vc_set_iattr(void __user *);
10382 +
10383 +extern int vc_fget_iattr(uint32_t, void __user *);
10384 +extern int vc_fset_iattr(uint32_t, void __user *);
10385 +
10386 +#ifdef CONFIG_COMPAT
10387 +
10388 +extern int vc_get_iattr_x32(void __user *);
10389 +extern int vc_set_iattr_x32(void __user *);
10390 +
10391 +#endif /* CONFIG_COMPAT */
10392 +
10393 +#endif /* _VSERVER_INODE_CMD_H */
10394 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/limit.h linux-4.4.110-vs2.3.9/include/linux/vserver/limit.h
10395 --- linux-4.4.110/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
10396 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/limit.h 2018-01-09 16:36:32.000000000 +0000
10397 @@ -0,0 +1,67 @@
10398 +#ifndef _VSERVER_LIMIT_H
10399 +#define _VSERVER_LIMIT_H
10400 +
10401 +#include <uapi/vserver/limit.h>
10402 +
10403 +
10404 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
10405 +
10406 +/*     keep in sync with CRLIM_INFINITY */
10407 +
10408 +#define        VLIM_INFINITY   (~0ULL)
10409 +
10410 +#include <asm/atomic.h>
10411 +#include <asm/resource.h>
10412 +
10413 +#ifndef RLIM_INFINITY
10414 +#warning RLIM_INFINITY is undefined
10415 +#endif
10416 +
10417 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
10418 +
10419 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
10420 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
10421 +
10422 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
10423 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
10424 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
10425 +
10426 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
10427 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
10428 +
10429 +typedef atomic_long_t rlim_atomic_t;
10430 +typedef unsigned long rlim_t;
10431 +
10432 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
10433 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
10434 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
10435 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
10436 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
10437 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
10438 +
10439 +
10440 +#if    (RLIM_INFINITY == VLIM_INFINITY)
10441 +#define        VX_VLIM(r) ((long long)(long)(r))
10442 +#define        VX_RLIM(v) ((rlim_t)(v))
10443 +#else
10444 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
10445 +               ? VLIM_INFINITY : (long long)(r))
10446 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
10447 +               ? RLIM_INFINITY : (rlim_t)(v))
10448 +#endif
10449 +
10450 +struct sysinfo;
10451 +
10452 +#ifdef CONFIG_MEMCG
10453 +void vx_vsi_meminfo(struct sysinfo *);
10454 +void vx_vsi_swapinfo(struct sysinfo *);
10455 +long vx_vsi_cached(struct sysinfo *);
10456 +#else  /* !CONFIG_MEMCG */
10457 +#define vx_vsi_meminfo(s) do { } while (0)
10458 +#define vx_vsi_swapinfo(s) do { } while (0)
10459 +#define vx_vsi_cached(s) (0L)
10460 +#endif /* !CONFIG_MEMCG */
10461 +
10462 +#define NUM_LIMITS     24
10463 +
10464 +#endif /* _VSERVER_LIMIT_H */
10465 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/limit_cmd.h linux-4.4.110-vs2.3.9/include/linux/vserver/limit_cmd.h
10466 --- linux-4.4.110/include/linux/vserver/limit_cmd.h     1970-01-01 00:00:00.000000000 +0000
10467 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/limit_cmd.h     2018-01-09 16:36:32.000000000 +0000
10468 @@ -0,0 +1,35 @@
10469 +#ifndef _VSERVER_LIMIT_CMD_H
10470 +#define _VSERVER_LIMIT_CMD_H
10471 +
10472 +#include <uapi/vserver/limit_cmd.h>
10473 +
10474 +
10475 +#ifdef CONFIG_IA32_EMULATION
10476 +
10477 +struct vcmd_ctx_rlimit_v0_x32 {
10478 +       uint32_t id;
10479 +       uint64_t minimum;
10480 +       uint64_t softlimit;
10481 +       uint64_t maximum;
10482 +} __attribute__ ((packed));
10483 +
10484 +#endif /* CONFIG_IA32_EMULATION */
10485 +
10486 +#include <linux/compiler.h>
10487 +
10488 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
10489 +extern int vc_get_rlimit(struct vx_info *, void __user *);
10490 +extern int vc_set_rlimit(struct vx_info *, void __user *);
10491 +extern int vc_reset_hits(struct vx_info *, void __user *);
10492 +extern int vc_reset_minmax(struct vx_info *, void __user *);
10493 +
10494 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
10495 +
10496 +#ifdef CONFIG_IA32_EMULATION
10497 +
10498 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
10499 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
10500 +
10501 +#endif /* CONFIG_IA32_EMULATION */
10502 +
10503 +#endif /* _VSERVER_LIMIT_CMD_H */
10504 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/limit_def.h linux-4.4.110-vs2.3.9/include/linux/vserver/limit_def.h
10505 --- linux-4.4.110/include/linux/vserver/limit_def.h     1970-01-01 00:00:00.000000000 +0000
10506 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/limit_def.h     2018-01-09 16:36:32.000000000 +0000
10507 @@ -0,0 +1,47 @@
10508 +#ifndef _VSERVER_LIMIT_DEF_H
10509 +#define _VSERVER_LIMIT_DEF_H
10510 +
10511 +#include <asm/atomic.h>
10512 +#include <asm/resource.h>
10513 +
10514 +#include "limit.h"
10515 +
10516 +
10517 +struct _vx_res_limit {
10518 +       rlim_t soft;            /* Context soft limit */
10519 +       rlim_t hard;            /* Context hard limit */
10520 +
10521 +       rlim_atomic_t rcur;     /* Current value */
10522 +       rlim_t rmin;            /* Context minimum */
10523 +       rlim_t rmax;            /* Context maximum */
10524 +
10525 +       atomic_t lhit;          /* Limit hits */
10526 +};
10527 +
10528 +/* context sub struct */
10529 +
10530 +struct _vx_limit {
10531 +       struct _vx_res_limit res[NUM_LIMITS];
10532 +};
10533 +
10534 +#ifdef CONFIG_VSERVER_DEBUG
10535 +
10536 +static inline void __dump_vx_limit(struct _vx_limit *limit)
10537 +{
10538 +       int i;
10539 +
10540 +       printk("\t_vx_limit:");
10541 +       for (i = 0; i < NUM_LIMITS; i++) {
10542 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
10543 +                       i, (unsigned long)__rlim_get(limit, i),
10544 +                       (unsigned long)__rlim_rmin(limit, i),
10545 +                       (unsigned long)__rlim_rmax(limit, i),
10546 +                       (long)__rlim_soft(limit, i),
10547 +                       (long)__rlim_hard(limit, i),
10548 +                       atomic_read(&__rlim_lhit(limit, i)));
10549 +       }
10550 +}
10551 +
10552 +#endif
10553 +
10554 +#endif /* _VSERVER_LIMIT_DEF_H */
10555 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/limit_int.h linux-4.4.110-vs2.3.9/include/linux/vserver/limit_int.h
10556 --- linux-4.4.110/include/linux/vserver/limit_int.h     1970-01-01 00:00:00.000000000 +0000
10557 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/limit_int.h     2018-01-09 16:36:32.000000000 +0000
10558 @@ -0,0 +1,193 @@
10559 +#ifndef _VSERVER_LIMIT_INT_H
10560 +#define _VSERVER_LIMIT_INT_H
10561 +
10562 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
10563 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
10564 +
10565 +extern const char *vlimit_name[NUM_LIMITS];
10566 +
10567 +static inline void __vx_acc_cres(struct vx_info *vxi,
10568 +       int res, int dir, void *_data, char *_file, int _line)
10569 +{
10570 +       if (VXD_RCRES_COND(res))
10571 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
10572 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10573 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10574 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
10575 +       if (!vxi)
10576 +               return;
10577 +
10578 +       if (dir > 0)
10579 +               __rlim_inc(&vxi->limit, res);
10580 +       else
10581 +               __rlim_dec(&vxi->limit, res);
10582 +}
10583 +
10584 +static inline void __vx_add_cres(struct vx_info *vxi,
10585 +       int res, int amount, void *_data, char *_file, int _line)
10586 +{
10587 +       if (VXD_RCRES_COND(res))
10588 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
10589 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10590 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10591 +                       amount, _data, _file, _line);
10592 +       if (amount == 0)
10593 +               return;
10594 +       if (!vxi)
10595 +               return;
10596 +       __rlim_add(&vxi->limit, res, amount);
10597 +}
10598 +
10599 +static inline
10600 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
10601 +{
10602 +       int cond = (value > __rlim_rmax(limit, res));
10603 +
10604 +       if (cond)
10605 +               __rlim_rmax(limit, res) = value;
10606 +       return cond;
10607 +}
10608 +
10609 +static inline
10610 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
10611 +{
10612 +       int cond = (value < __rlim_rmin(limit, res));
10613 +
10614 +       if (cond)
10615 +               __rlim_rmin(limit, res) = value;
10616 +       return cond;
10617 +}
10618 +
10619 +static inline
10620 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
10621 +{
10622 +       if (!__vx_cres_adjust_max(limit, res, value))
10623 +               __vx_cres_adjust_min(limit, res, value);
10624 +}
10625 +
10626 +
10627 +/*     return values:
10628 +        +1 ... no limit hit
10629 +        -1 ... over soft limit
10630 +         0 ... over hard limit         */
10631 +
10632 +static inline int __vx_cres_avail(struct vx_info *vxi,
10633 +       int res, int num, char *_file, int _line)
10634 +{
10635 +       struct _vx_limit *limit;
10636 +       rlim_t value;
10637 +
10638 +       if (VXD_RLIMIT_COND(res))
10639 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
10640 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10641 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
10642 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
10643 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10644 +                       num, _file, _line);
10645 +       if (!vxi)
10646 +               return 1;
10647 +
10648 +       limit = &vxi->limit;
10649 +       value = __rlim_get(limit, res);
10650 +
10651 +       if (!__vx_cres_adjust_max(limit, res, value))
10652 +               __vx_cres_adjust_min(limit, res, value);
10653 +
10654 +       if (num == 0)
10655 +               return 1;
10656 +
10657 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
10658 +               return -1;
10659 +       if (value + num <= __rlim_soft(limit, res))
10660 +               return -1;
10661 +
10662 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
10663 +               return 1;
10664 +       if (value + num <= __rlim_hard(limit, res))
10665 +               return 1;
10666 +
10667 +       __rlim_hit(limit, res);
10668 +       return 0;
10669 +}
10670 +
10671 +
10672 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
10673 +
10674 +static inline
10675 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
10676 +{
10677 +       rlim_t value, sum = 0;
10678 +       int res;
10679 +
10680 +       while ((res = *array++)) {
10681 +               value = __rlim_get(limit, res);
10682 +               __vx_cres_fixup(limit, res, value);
10683 +               sum += value;
10684 +       }
10685 +       return sum;
10686 +}
10687 +
10688 +static inline
10689 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
10690 +{
10691 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
10692 +       int res = *array;
10693 +
10694 +       if (value == __rlim_get(limit, res))
10695 +               return value;
10696 +
10697 +       __rlim_set(limit, res, value);
10698 +       /* now adjust min/max */
10699 +       if (!__vx_cres_adjust_max(limit, res, value))
10700 +               __vx_cres_adjust_min(limit, res, value);
10701 +
10702 +       return value;
10703 +}
10704 +
10705 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
10706 +       const int *array, int num, char *_file, int _line)
10707 +{
10708 +       struct _vx_limit *limit;
10709 +       rlim_t value = 0;
10710 +       int res;
10711 +
10712 +       if (num == 0)
10713 +               return 1;
10714 +       if (!vxi)
10715 +               return 1;
10716 +
10717 +       limit = &vxi->limit;
10718 +       res = *array;
10719 +       value = __vx_cres_array_sum(limit, array + 1);
10720 +
10721 +       __rlim_set(limit, res, value);
10722 +       __vx_cres_fixup(limit, res, value);
10723 +
10724 +       return __vx_cres_avail(vxi, res, num, _file, _line);
10725 +}
10726 +
10727 +
10728 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
10729 +{
10730 +       rlim_t value;
10731 +       int res;
10732 +
10733 +       /* complex resources first */
10734 +       if ((id < 0) || (id == RLIMIT_RSS))
10735 +               __vx_cres_array_fixup(limit, VLA_RSS);
10736 +
10737 +       for (res = 0; res < NUM_LIMITS; res++) {
10738 +               if ((id > 0) && (res != id))
10739 +                       continue;
10740 +
10741 +               value = __rlim_get(limit, res);
10742 +               __vx_cres_fixup(limit, res, value);
10743 +
10744 +               /* not supposed to happen, maybe warn? */
10745 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
10746 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
10747 +       }
10748 +}
10749 +
10750 +
10751 +#endif /* _VSERVER_LIMIT_INT_H */
10752 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/monitor.h linux-4.4.110-vs2.3.9/include/linux/vserver/monitor.h
10753 --- linux-4.4.110/include/linux/vserver/monitor.h       1970-01-01 00:00:00.000000000 +0000
10754 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/monitor.h       2018-01-09 16:36:32.000000000 +0000
10755 @@ -0,0 +1,6 @@
10756 +#ifndef _VSERVER_MONITOR_H
10757 +#define _VSERVER_MONITOR_H
10758 +
10759 +#include <uapi/vserver/monitor.h>
10760 +
10761 +#endif /* _VSERVER_MONITOR_H */
10762 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/network.h linux-4.4.110-vs2.3.9/include/linux/vserver/network.h
10763 --- linux-4.4.110/include/linux/vserver/network.h       1970-01-01 00:00:00.000000000 +0000
10764 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/network.h       2018-01-09 16:36:32.000000000 +0000
10765 @@ -0,0 +1,76 @@
10766 +#ifndef _VSERVER_NETWORK_H
10767 +#define _VSERVER_NETWORK_H
10768 +
10769 +
10770 +#include <linux/list.h>
10771 +#include <linux/spinlock.h>
10772 +#include <linux/rcupdate.h>
10773 +#include <linux/in.h>
10774 +#include <linux/in6.h>
10775 +#include <asm/atomic.h>
10776 +#include <uapi/vserver/network.h>
10777 +
10778 +struct nx_addr_v4 {
10779 +       struct nx_addr_v4 *next;
10780 +       struct in_addr ip[2];
10781 +       struct in_addr mask;
10782 +       uint16_t type;
10783 +       uint16_t flags;
10784 +};
10785 +
10786 +struct nx_addr_v6 {
10787 +       struct nx_addr_v6 *next;
10788 +       struct in6_addr ip;
10789 +       struct in6_addr mask;
10790 +       uint32_t prefix;
10791 +       uint16_t type;
10792 +       uint16_t flags;
10793 +};
10794 +
10795 +struct nx_info {
10796 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
10797 +       vnid_t nx_id;                   /* vnet id */
10798 +       atomic_t nx_usecnt;             /* usage count */
10799 +       atomic_t nx_tasks;              /* tasks count */
10800 +       int nx_state;                   /* context state */
10801 +
10802 +       uint64_t nx_flags;              /* network flag word */
10803 +       uint64_t nx_ncaps;              /* network capabilities */
10804 +
10805 +       spinlock_t addr_lock;           /* protect address changes */
10806 +       struct in_addr v4_lback;        /* Loopback address */
10807 +       struct in_addr v4_bcast;        /* Broadcast address */
10808 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
10809 +#ifdef CONFIG_IPV6
10810 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
10811 +#endif
10812 +       char nx_name[65];               /* network context name */
10813 +};
10814 +
10815 +
10816 +/* status flags */
10817 +
10818 +#define NXS_HASHED      0x0001
10819 +#define NXS_SHUTDOWN    0x0100
10820 +#define NXS_RELEASED    0x8000
10821 +
10822 +extern struct nx_info *lookup_nx_info(int);
10823 +
10824 +extern int get_nid_list(int, unsigned int *, int);
10825 +extern int nid_is_hashed(vnid_t);
10826 +
10827 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
10828 +
10829 +extern long vs_net_change(struct nx_info *, unsigned int);
10830 +
10831 +struct sock;
10832 +
10833 +
10834 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
10835 +#ifdef  CONFIG_IPV6
10836 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
10837 +#else
10838 +#define NX_IPV6(n)     (0)
10839 +#endif
10840 +
10841 +#endif /* _VSERVER_NETWORK_H */
10842 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/network_cmd.h linux-4.4.110-vs2.3.9/include/linux/vserver/network_cmd.h
10843 --- linux-4.4.110/include/linux/vserver/network_cmd.h   1970-01-01 00:00:00.000000000 +0000
10844 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/network_cmd.h   2018-01-09 16:36:32.000000000 +0000
10845 @@ -0,0 +1,37 @@
10846 +#ifndef _VSERVER_NETWORK_CMD_H
10847 +#define _VSERVER_NETWORK_CMD_H
10848 +
10849 +#include <uapi/vserver/network_cmd.h>
10850 +
10851 +extern int vc_task_nid(uint32_t);
10852 +
10853 +extern int vc_nx_info(struct nx_info *, void __user *);
10854 +
10855 +extern int vc_net_create(uint32_t, void __user *);
10856 +extern int vc_net_migrate(struct nx_info *, void __user *);
10857 +
10858 +extern int vc_net_add(struct nx_info *, void __user *);
10859 +extern int vc_net_remove(struct nx_info *, void __user *);
10860 +
10861 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
10862 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
10863 +
10864 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
10865 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
10866 +
10867 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
10868 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
10869 +
10870 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
10871 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
10872 +
10873 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
10874 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
10875 +
10876 +extern int vc_get_nflags(struct nx_info *, void __user *);
10877 +extern int vc_set_nflags(struct nx_info *, void __user *);
10878 +
10879 +extern int vc_get_ncaps(struct nx_info *, void __user *);
10880 +extern int vc_set_ncaps(struct nx_info *, void __user *);
10881 +
10882 +#endif /* _VSERVER_CONTEXT_CMD_H */
10883 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/percpu.h linux-4.4.110-vs2.3.9/include/linux/vserver/percpu.h
10884 --- linux-4.4.110/include/linux/vserver/percpu.h        1970-01-01 00:00:00.000000000 +0000
10885 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/percpu.h        2018-01-09 16:36:32.000000000 +0000
10886 @@ -0,0 +1,14 @@
10887 +#ifndef _VSERVER_PERCPU_H
10888 +#define _VSERVER_PERCPU_H
10889 +
10890 +#include "cvirt_def.h"
10891 +#include "sched_def.h"
10892 +
10893 +struct _vx_percpu {
10894 +       struct _vx_cvirt_pc cvirt;
10895 +       struct _vx_sched_pc sched;
10896 +};
10897 +
10898 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
10899 +
10900 +#endif /* _VSERVER_PERCPU_H */
10901 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/pid.h linux-4.4.110-vs2.3.9/include/linux/vserver/pid.h
10902 --- linux-4.4.110/include/linux/vserver/pid.h   1970-01-01 00:00:00.000000000 +0000
10903 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/pid.h   2018-01-09 16:36:32.000000000 +0000
10904 @@ -0,0 +1,51 @@
10905 +#ifndef _VSERVER_PID_H
10906 +#define _VSERVER_PID_H
10907 +
10908 +/* pid faking stuff */
10909 +
10910 +#define vx_info_map_pid(v, p) \
10911 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
10912 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
10913 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
10914 +#define vx_map_tgid(p) vx_map_pid(p)
10915 +
10916 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
10917 +       const char *func, const char *file, int line)
10918 +{
10919 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
10920 +               vxfprintk(VXD_CBIT(cvirt, 2),
10921 +                       "vx_map_tgid: %p/%llx: %d -> %d",
10922 +                       vxi, (long long)vxi->vx_flags, pid,
10923 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
10924 +                       func, file, line);
10925 +               if (pid == 0)
10926 +                       return 0;
10927 +               if (pid == vxi->vx_initpid)
10928 +                       return 1;
10929 +       }
10930 +       return pid;
10931 +}
10932 +
10933 +#define vx_info_rmap_pid(v, p) \
10934 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
10935 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
10936 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
10937 +
10938 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
10939 +       const char *func, const char *file, int line)
10940 +{
10941 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
10942 +               vxfprintk(VXD_CBIT(cvirt, 2),
10943 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
10944 +                       vxi, (long long)vxi->vx_flags, pid,
10945 +                       (pid == 1) ? vxi->vx_initpid : pid,
10946 +                       func, file, line);
10947 +               if ((pid == 1) && vxi->vx_initpid)
10948 +                       return vxi->vx_initpid;
10949 +               if (pid == vxi->vx_initpid)
10950 +                       return ~0U;
10951 +       }
10952 +       return pid;
10953 +}
10954 +
10955 +#endif
10956 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/sched.h linux-4.4.110-vs2.3.9/include/linux/vserver/sched.h
10957 --- linux-4.4.110/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
10958 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/sched.h 2018-01-09 16:36:32.000000000 +0000
10959 @@ -0,0 +1,23 @@
10960 +#ifndef _VSERVER_SCHED_H
10961 +#define _VSERVER_SCHED_H
10962 +
10963 +
10964 +#ifdef __KERNEL__
10965 +
10966 +struct timespec;
10967 +
10968 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10969 +
10970 +
10971 +struct vx_info;
10972 +
10973 +void vx_update_load(struct vx_info *);
10974 +
10975 +
10976 +void vx_update_sched_param(struct _vx_sched *sched,
10977 +       struct _vx_sched_pc *sched_pc);
10978 +
10979 +#endif /* __KERNEL__ */
10980 +#else  /* _VSERVER_SCHED_H */
10981 +#warning duplicate inclusion
10982 +#endif /* _VSERVER_SCHED_H */
10983 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/sched_cmd.h linux-4.4.110-vs2.3.9/include/linux/vserver/sched_cmd.h
10984 --- linux-4.4.110/include/linux/vserver/sched_cmd.h     1970-01-01 00:00:00.000000000 +0000
10985 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/sched_cmd.h     2018-01-09 16:36:32.000000000 +0000
10986 @@ -0,0 +1,11 @@
10987 +#ifndef _VSERVER_SCHED_CMD_H
10988 +#define _VSERVER_SCHED_CMD_H
10989 +
10990 +
10991 +#include <linux/compiler.h>
10992 +#include <uapi/vserver/sched_cmd.h>
10993 +
10994 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
10995 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
10996 +
10997 +#endif /* _VSERVER_SCHED_CMD_H */
10998 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/sched_def.h linux-4.4.110-vs2.3.9/include/linux/vserver/sched_def.h
10999 --- linux-4.4.110/include/linux/vserver/sched_def.h     1970-01-01 00:00:00.000000000 +0000
11000 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/sched_def.h     2018-01-09 16:36:32.000000000 +0000
11001 @@ -0,0 +1,38 @@
11002 +#ifndef _VSERVER_SCHED_DEF_H
11003 +#define _VSERVER_SCHED_DEF_H
11004 +
11005 +#include <linux/spinlock.h>
11006 +#include <linux/jiffies.h>
11007 +#include <linux/cpumask.h>
11008 +#include <asm/atomic.h>
11009 +#include <asm/param.h>
11010 +
11011 +
11012 +/* context sub struct */
11013 +
11014 +struct _vx_sched {
11015 +       int prio_bias;                  /* bias offset for priority */
11016 +
11017 +       cpumask_t update;               /* CPUs which should update */
11018 +};
11019 +
11020 +struct _vx_sched_pc {
11021 +       int prio_bias;                  /* bias offset for priority */
11022 +
11023 +       uint64_t user_ticks;            /* token tick events */
11024 +       uint64_t sys_ticks;             /* token tick events */
11025 +       uint64_t hold_ticks;            /* token ticks paused */
11026 +};
11027 +
11028 +
11029 +#ifdef CONFIG_VSERVER_DEBUG
11030 +
11031 +static inline void __dump_vx_sched(struct _vx_sched *sched)
11032 +{
11033 +       printk("\t_vx_sched:\n");
11034 +       printk("\t priority = %4d\n", sched->prio_bias);
11035 +}
11036 +
11037 +#endif
11038 +
11039 +#endif /* _VSERVER_SCHED_DEF_H */
11040 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/signal.h linux-4.4.110-vs2.3.9/include/linux/vserver/signal.h
11041 --- linux-4.4.110/include/linux/vserver/signal.h        1970-01-01 00:00:00.000000000 +0000
11042 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/signal.h        2018-01-09 16:36:32.000000000 +0000
11043 @@ -0,0 +1,14 @@
11044 +#ifndef _VSERVER_SIGNAL_H
11045 +#define _VSERVER_SIGNAL_H
11046 +
11047 +
11048 +#ifdef __KERNEL__
11049 +
11050 +struct vx_info;
11051 +
11052 +int vx_info_kill(struct vx_info *, int, int);
11053 +
11054 +#endif /* __KERNEL__ */
11055 +#else  /* _VSERVER_SIGNAL_H */
11056 +#warning duplicate inclusion
11057 +#endif /* _VSERVER_SIGNAL_H */
11058 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/signal_cmd.h linux-4.4.110-vs2.3.9/include/linux/vserver/signal_cmd.h
11059 --- linux-4.4.110/include/linux/vserver/signal_cmd.h    1970-01-01 00:00:00.000000000 +0000
11060 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/signal_cmd.h    2018-01-09 16:36:32.000000000 +0000
11061 @@ -0,0 +1,14 @@
11062 +#ifndef _VSERVER_SIGNAL_CMD_H
11063 +#define _VSERVER_SIGNAL_CMD_H
11064 +
11065 +#include <uapi/vserver/signal_cmd.h>
11066 +
11067 +
11068 +extern int vc_ctx_kill(struct vx_info *, void __user *);
11069 +extern int vc_wait_exit(struct vx_info *, void __user *);
11070 +
11071 +
11072 +extern int vc_get_pflags(uint32_t pid, void __user *);
11073 +extern int vc_set_pflags(uint32_t pid, void __user *);
11074 +
11075 +#endif /* _VSERVER_SIGNAL_CMD_H */
11076 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/space.h linux-4.4.110-vs2.3.9/include/linux/vserver/space.h
11077 --- linux-4.4.110/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
11078 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/space.h 2018-01-09 16:36:32.000000000 +0000
11079 @@ -0,0 +1,12 @@
11080 +#ifndef _VSERVER_SPACE_H
11081 +#define _VSERVER_SPACE_H
11082 +
11083 +#include <linux/types.h>
11084 +
11085 +struct vx_info;
11086 +
11087 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
11088 +
11089 +#else  /* _VSERVER_SPACE_H */
11090 +#warning duplicate inclusion
11091 +#endif /* _VSERVER_SPACE_H */
11092 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/space_cmd.h linux-4.4.110-vs2.3.9/include/linux/vserver/space_cmd.h
11093 --- linux-4.4.110/include/linux/vserver/space_cmd.h     1970-01-01 00:00:00.000000000 +0000
11094 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/space_cmd.h     2018-01-09 16:36:32.000000000 +0000
11095 @@ -0,0 +1,13 @@
11096 +#ifndef _VSERVER_SPACE_CMD_H
11097 +#define _VSERVER_SPACE_CMD_H
11098 +
11099 +#include <uapi/vserver/space_cmd.h>
11100 +
11101 +
11102 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
11103 +extern int vc_set_space_v1(struct vx_info *, void __user *);
11104 +extern int vc_enter_space(struct vx_info *, void __user *);
11105 +extern int vc_set_space(struct vx_info *, void __user *);
11106 +extern int vc_get_space_mask(void __user *, int);
11107 +
11108 +#endif /* _VSERVER_SPACE_CMD_H */
11109 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/switch.h linux-4.4.110-vs2.3.9/include/linux/vserver/switch.h
11110 --- linux-4.4.110/include/linux/vserver/switch.h        1970-01-01 00:00:00.000000000 +0000
11111 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/switch.h        2018-01-09 16:36:32.000000000 +0000
11112 @@ -0,0 +1,8 @@
11113 +#ifndef _VSERVER_SWITCH_H
11114 +#define _VSERVER_SWITCH_H
11115 +
11116 +
11117 +#include <linux/errno.h>
11118 +#include <uapi/vserver/switch.h>
11119 +
11120 +#endif /* _VSERVER_SWITCH_H */
11121 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/tag.h linux-4.4.110-vs2.3.9/include/linux/vserver/tag.h
11122 --- linux-4.4.110/include/linux/vserver/tag.h   1970-01-01 00:00:00.000000000 +0000
11123 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/tag.h   2018-01-09 16:36:32.000000000 +0000
11124 @@ -0,0 +1,160 @@
11125 +#ifndef _DX_TAG_H
11126 +#define _DX_TAG_H
11127 +
11128 +#include <linux/types.h>
11129 +#include <linux/uidgid.h>
11130 +
11131 +
11132 +#define DX_TAG(in)     (IS_TAGGED(in))
11133 +
11134 +
11135 +#ifdef CONFIG_TAG_NFSD
11136 +#define DX_TAG_NFSD    1
11137 +#else
11138 +#define DX_TAG_NFSD    0
11139 +#endif
11140 +
11141 +
11142 +#ifdef CONFIG_TAGGING_NONE
11143 +
11144 +#define MAX_UID                0xFFFFFFFF
11145 +#define MAX_GID                0xFFFFFFFF
11146 +
11147 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
11148 +
11149 +#define TAGINO_UID(cond, uid, tag)     (uid)
11150 +#define TAGINO_GID(cond, gid, tag)     (gid)
11151 +
11152 +#endif
11153 +
11154 +
11155 +#ifdef CONFIG_TAGGING_GID16
11156 +
11157 +#define MAX_UID                0xFFFFFFFF
11158 +#define MAX_GID                0x0000FFFF
11159 +
11160 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11161 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
11162 +
11163 +#define TAGINO_UID(cond, uid, tag)     (uid)
11164 +#define TAGINO_GID(cond, gid, tag)     \
11165 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
11166 +
11167 +#endif
11168 +
11169 +
11170 +#ifdef CONFIG_TAGGING_ID24
11171 +
11172 +#define MAX_UID                0x00FFFFFF
11173 +#define MAX_GID                0x00FFFFFF
11174 +
11175 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11176 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
11177 +
11178 +#define TAGINO_UID(cond, uid, tag)     \
11179 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
11180 +#define TAGINO_GID(cond, gid, tag)     \
11181 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
11182 +
11183 +#endif
11184 +
11185 +
11186 +#ifdef CONFIG_TAGGING_UID16
11187 +
11188 +#define MAX_UID                0x0000FFFF
11189 +#define MAX_GID                0xFFFFFFFF
11190 +
11191 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11192 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
11193 +
11194 +#define TAGINO_UID(cond, uid, tag)     \
11195 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
11196 +#define TAGINO_GID(cond, gid, tag)     (gid)
11197 +
11198 +#endif
11199 +
11200 +
11201 +#ifdef CONFIG_TAGGING_INTERN
11202 +
11203 +#define MAX_UID                0xFFFFFFFF
11204 +#define MAX_GID                0xFFFFFFFF
11205 +
11206 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11207 +       ((cond) ? (tag) : 0)
11208 +
11209 +#define TAGINO_UID(cond, uid, tag)     (uid)
11210 +#define TAGINO_GID(cond, gid, tag)     (gid)
11211 +
11212 +#endif
11213 +
11214 +
11215 +#ifndef CONFIG_TAGGING_NONE
11216 +#define dx_current_fstag(sb)   \
11217 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
11218 +#else
11219 +#define dx_current_fstag(sb)   (0)
11220 +#endif
11221 +
11222 +#ifndef CONFIG_TAGGING_INTERN
11223 +#define TAGINO_TAG(cond, tag)  (0)
11224 +#else
11225 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
11226 +#endif
11227 +
11228 +#define TAGINO_KUID(cond, kuid, ktag)  \
11229 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
11230 +#define TAGINO_KGID(cond, kgid, ktag)  \
11231 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
11232 +#define TAGINO_KTAG(cond, ktag)                \
11233 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
11234 +
11235 +
11236 +#define INOTAG_UID(cond, uid, gid)     \
11237 +       ((cond) ? ((uid) & MAX_UID) : (uid))
11238 +#define INOTAG_GID(cond, uid, gid)     \
11239 +       ((cond) ? ((gid) & MAX_GID) : (gid))
11240 +
11241 +#define INOTAG_KUID(cond, kuid, kgid)  \
11242 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11243 +#define INOTAG_KGID(cond, kuid, kgid)  \
11244 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11245 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
11246 +       KTAGT_INIT(INOTAG_TAG(cond, \
11247 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
11248 +
11249 +
11250 +static inline uid_t dx_map_uid(uid_t uid)
11251 +{
11252 +       if ((uid > MAX_UID) && (uid != -1))
11253 +               uid = -2;
11254 +       return (uid & MAX_UID);
11255 +}
11256 +
11257 +static inline gid_t dx_map_gid(gid_t gid)
11258 +{
11259 +       if ((gid > MAX_GID) && (gid != -1))
11260 +               gid = -2;
11261 +       return (gid & MAX_GID);
11262 +}
11263 +
11264 +struct peer_tag {
11265 +       int32_t xid;
11266 +       int32_t nid;
11267 +};
11268 +
11269 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
11270 +
11271 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
11272 +                unsigned long *flags);
11273 +
11274 +#ifdef CONFIG_PROPAGATE
11275 +
11276 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
11277 +
11278 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
11279 +
11280 +#else
11281 +#define dx_propagate_tag(n, i) do { } while (0)
11282 +#endif
11283 +
11284 +#endif /* _DX_TAG_H */
11285 diff -NurpP --minimal linux-4.4.110/include/linux/vserver/tag_cmd.h linux-4.4.110-vs2.3.9/include/linux/vserver/tag_cmd.h
11286 --- linux-4.4.110/include/linux/vserver/tag_cmd.h       1970-01-01 00:00:00.000000000 +0000
11287 +++ linux-4.4.110-vs2.3.9/include/linux/vserver/tag_cmd.h       2018-01-09 16:36:32.000000000 +0000
11288 @@ -0,0 +1,10 @@
11289 +#ifndef _VSERVER_TAG_CMD_H
11290 +#define _VSERVER_TAG_CMD_H
11291 +
11292 +#include <uapi/vserver/tag_cmd.h>
11293 +
11294 +extern int vc_task_tag(uint32_t);
11295 +
11296 +extern int vc_tag_migrate(uint32_t);
11297 +
11298 +#endif /* _VSERVER_TAG_CMD_H */
11299 diff -NurpP --minimal linux-4.4.110/include/net/addrconf.h linux-4.4.110-vs2.3.9/include/net/addrconf.h
11300 --- linux-4.4.110/include/net/addrconf.h        2018-01-09 16:35:10.000000000 +0000
11301 +++ linux-4.4.110-vs2.3.9/include/net/addrconf.h        2018-01-09 16:36:32.000000000 +0000
11302 @@ -84,7 +84,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
11303  
11304  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dev,
11305                        const struct in6_addr *daddr, unsigned int srcprefs,
11306 -                      struct in6_addr *saddr);
11307 +                      struct in6_addr *saddr, struct nx_info *nxi);
11308  int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
11309                       u32 banned_flags);
11310  int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
11311 diff -NurpP --minimal linux-4.4.110/include/net/af_unix.h linux-4.4.110-vs2.3.9/include/net/af_unix.h
11312 --- linux-4.4.110/include/net/af_unix.h 2018-01-09 16:35:10.000000000 +0000
11313 +++ linux-4.4.110-vs2.3.9/include/net/af_unix.h 2018-01-09 16:36:32.000000000 +0000
11314 @@ -4,6 +4,7 @@
11315  #include <linux/socket.h>
11316  #include <linux/un.h>
11317  #include <linux/mutex.h>
11318 +// #include <linux/vs_base.h>
11319  #include <net/sock.h>
11320  
11321  void unix_inflight(struct user_struct *user, struct file *fp);
11322 diff -NurpP --minimal linux-4.4.110/include/net/inet_timewait_sock.h linux-4.4.110-vs2.3.9/include/net/inet_timewait_sock.h
11323 --- linux-4.4.110/include/net/inet_timewait_sock.h      2016-07-05 04:15:11.000000000 +0000
11324 +++ linux-4.4.110-vs2.3.9/include/net/inet_timewait_sock.h      2018-01-09 16:40:17.000000000 +0000
11325 @@ -71,6 +71,10 @@ struct inet_timewait_sock {
11326  #define tw_num                 __tw_common.skc_num
11327  #define tw_cookie              __tw_common.skc_cookie
11328  #define tw_dr                  __tw_common.skc_tw_dr
11329 +#define tw_xid                 __tw_common.skc_xid
11330 +#define tw_vx_info             __tw_common.skc_vx_info
11331 +#define tw_nid                 __tw_common.skc_nid
11332 +#define tw_nx_info             __tw_common.skc_nx_info
11333  
11334         int                     tw_timeout;
11335         volatile unsigned char  tw_substate;
11336 diff -NurpP --minimal linux-4.4.110/include/net/ip6_route.h linux-4.4.110-vs2.3.9/include/net/ip6_route.h
11337 --- linux-4.4.110/include/net/ip6_route.h       2018-01-09 16:35:10.000000000 +0000
11338 +++ linux-4.4.110-vs2.3.9/include/net/ip6_route.h       2018-01-09 16:36:32.000000000 +0000
11339 @@ -90,7 +90,7 @@ int ip6_del_rt(struct rt6_info *);
11340  
11341  int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
11342                         const struct in6_addr *daddr, unsigned int prefs,
11343 -                       struct in6_addr *saddr);
11344 +                       struct in6_addr *saddr, struct nx_info *nxi);
11345  
11346  struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
11347                             const struct in6_addr *saddr, int oif, int flags);
11348 diff -NurpP --minimal linux-4.4.110/include/net/route.h linux-4.4.110-vs2.3.9/include/net/route.h
11349 --- linux-4.4.110/include/net/route.h   2016-07-05 04:15:11.000000000 +0000
11350 +++ linux-4.4.110-vs2.3.9/include/net/route.h   2018-01-09 16:39:47.000000000 +0000
11351 @@ -223,6 +223,9 @@ static inline void ip_rt_put(struct rtab
11352         dst_release(&rt->dst);
11353  }
11354  
11355 +#include <linux/vs_base.h>
11356 +#include <linux/vs_inet.h>
11357 +
11358  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
11359  
11360  extern const __u8 ip_tos2prio[16];
11361 @@ -270,6 +273,9 @@ static inline void ip_route_connect_init
11362                            protocol, flow_flags, dst, src, dport, sport);
11363  }
11364  
11365 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
11366 +       struct flowi4 *);
11367 +
11368  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
11369                                               __be32 dst, __be32 src, u32 tos,
11370                                               int oif, u8 protocol,
11371 @@ -278,6 +284,7 @@ static inline struct rtable *ip_route_co
11372  {
11373         struct net *net = sock_net(sk);
11374         struct rtable *rt;
11375 +       struct nx_info *nx_info = current_nx_info();
11376  
11377         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
11378                               sport, dport, sk);
11379 @@ -291,7 +298,21 @@ static inline struct rtable *ip_route_co
11380  
11381                 src = fl4->saddr;
11382         }
11383 -       if (!dst || !src) {
11384 +
11385 +       if (sk)
11386 +               nx_info = sk->sk_nx_info;
11387 +
11388 +       vxdprintk(VXD_CBIT(net, 4),
11389 +               "ip_route_connect(%p) %p,%p;%lx",
11390 +               sk, nx_info, sk->sk_socket,
11391 +               (sk->sk_socket?sk->sk_socket->flags:0));
11392 +
11393 +       rt = ip_v4_find_src(net, nx_info, fl4);
11394 +       if (IS_ERR(rt))
11395 +               return rt;
11396 +       ip_rt_put(rt);
11397 +
11398 +       if (!fl4->daddr || !fl4->saddr) {
11399                 rt = __ip_route_output_key(net, fl4);
11400                 if (IS_ERR(rt))
11401                         return rt;
11402 diff -NurpP --minimal linux-4.4.110/include/net/sock.h linux-4.4.110-vs2.3.9/include/net/sock.h
11403 --- linux-4.4.110/include/net/sock.h    2018-01-09 16:35:10.000000000 +0000
11404 +++ linux-4.4.110-vs2.3.9/include/net/sock.h    2018-01-09 16:41:40.000000000 +0000
11405 @@ -201,6 +201,10 @@ struct sock_common {
11406         struct in6_addr         skc_v6_daddr;
11407         struct in6_addr         skc_v6_rcv_saddr;
11408  #endif
11409 +       vxid_t                  skc_xid;
11410 +       struct vx_info          *skc_vx_info;
11411 +       vnid_t                  skc_nid;
11412 +       struct nx_info          *skc_nx_info;
11413  
11414         atomic64_t              skc_cookie;
11415  
11416 @@ -349,8 +353,12 @@ struct sock {
11417  #define sk_prot                        __sk_common.skc_prot
11418  #define sk_net                 __sk_common.skc_net
11419  #define sk_v6_daddr            __sk_common.skc_v6_daddr
11420 -#define sk_v6_rcv_saddr        __sk_common.skc_v6_rcv_saddr
11421 +#define sk_v6_rcv_saddr                __sk_common.skc_v6_rcv_saddr
11422  #define sk_cookie              __sk_common.skc_cookie
11423 +#define sk_xid                 __sk_common.skc_xid
11424 +#define sk_vx_info             __sk_common.skc_vx_info
11425 +#define sk_nid                 __sk_common.skc_nid
11426 +#define sk_nx_info             __sk_common.skc_nx_info
11427  #define sk_incoming_cpu                __sk_common.skc_incoming_cpu
11428  #define sk_flags               __sk_common.skc_flags
11429  #define sk_rxhash              __sk_common.skc_rxhash
11430 diff -NurpP --minimal linux-4.4.110/include/uapi/Kbuild linux-4.4.110-vs2.3.9/include/uapi/Kbuild
11431 --- linux-4.4.110/include/uapi/Kbuild   2015-04-12 22:12:50.000000000 +0000
11432 +++ linux-4.4.110-vs2.3.9/include/uapi/Kbuild   2018-01-09 16:36:32.000000000 +0000
11433 @@ -13,3 +13,4 @@ header-y += drm/
11434  header-y += xen/
11435  header-y += scsi/
11436  header-y += misc/
11437 +header-y += vserver/
11438 diff -NurpP --minimal linux-4.4.110/include/uapi/linux/capability.h linux-4.4.110-vs2.3.9/include/uapi/linux/capability.h
11439 --- linux-4.4.110/include/uapi/linux/capability.h       2015-04-12 22:12:50.000000000 +0000
11440 +++ linux-4.4.110-vs2.3.9/include/uapi/linux/capability.h       2018-01-09 16:36:32.000000000 +0000
11441 @@ -259,6 +259,7 @@ struct vfs_cap_data {
11442     arbitrary SCSI commands */
11443  /* Allow setting encryption key on loopback filesystem */
11444  /* Allow setting zone reclaim policy */
11445 +/* Allow the selection of a security context */
11446  
11447  #define CAP_SYS_ADMIN        21
11448  
11449 @@ -354,7 +355,12 @@ struct vfs_cap_data {
11450  
11451  #define CAP_LAST_CAP         CAP_AUDIT_READ
11452  
11453 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
11454 +/* Allow context manipulations */
11455 +/* Allow changing context info on files */
11456 +
11457 +#define CAP_CONTEXT         63
11458 +
11459 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
11460  
11461  /*
11462   * Bit location of each capability (used by user-space library and kernel)
11463 diff -NurpP --minimal linux-4.4.110/include/uapi/linux/fs.h linux-4.4.110-vs2.3.9/include/uapi/linux/fs.h
11464 --- linux-4.4.110/include/uapi/linux/fs.h       2016-07-05 04:15:11.000000000 +0000
11465 +++ linux-4.4.110-vs2.3.9/include/uapi/linux/fs.h       2018-01-09 16:47:48.000000000 +0000
11466 @@ -91,6 +91,9 @@ struct inodes_stat_t {
11467  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
11468  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
11469  #define MS_LAZYTIME    (1<<25) /* Update the on-disk [acm]times lazily */
11470 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
11471 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
11472 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
11473  
11474  /* These sb flags are internal to the kernel */
11475  #define MS_NOSEC       (1<<28)
11476 @@ -197,12 +200,15 @@ struct inodes_stat_t {
11477  #define FS_EXTENT_FL                   0x00080000 /* Extents */
11478  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
11479  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
11480 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
11481  #define FS_PROJINHERIT_FL              0x20000000 /* Create with parents projid */
11482  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
11483  
11484 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
11485 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
11486 -
11487 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
11488 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
11489 +
11490 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
11491 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
11492  
11493  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
11494  #define SYNC_FILE_RANGE_WRITE          2
11495 diff -NurpP --minimal linux-4.4.110/include/uapi/linux/gfs2_ondisk.h linux-4.4.110-vs2.3.9/include/uapi/linux/gfs2_ondisk.h
11496 --- linux-4.4.110/include/uapi/linux/gfs2_ondisk.h      2015-04-12 22:12:50.000000000 +0000
11497 +++ linux-4.4.110-vs2.3.9/include/uapi/linux/gfs2_ondisk.h      2018-01-09 16:36:32.000000000 +0000
11498 @@ -225,6 +225,9 @@ enum {
11499         gfs2fl_Sync             = 8,
11500         gfs2fl_System           = 9,
11501         gfs2fl_TopLevel         = 10,
11502 +       gfs2fl_IXUnlink         = 16,
11503 +       gfs2fl_Barrier          = 17,
11504 +       gfs2fl_Cow              = 18,
11505         gfs2fl_TruncInProg      = 29,
11506         gfs2fl_InheritDirectio  = 30,
11507         gfs2fl_InheritJdata     = 31,
11508 @@ -242,6 +245,9 @@ enum {
11509  #define GFS2_DIF_SYNC                  0x00000100
11510  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
11511  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
11512 +#define GFS2_DIF_IXUNLINK               0x00010000
11513 +#define GFS2_DIF_BARRIER                0x00020000
11514 +#define GFS2_DIF_COW                    0x00040000
11515  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
11516  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
11517  #define GFS2_DIF_INHERIT_JDATA         0x80000000
11518 diff -NurpP --minimal linux-4.4.110/include/uapi/linux/if_tun.h linux-4.4.110-vs2.3.9/include/uapi/linux/if_tun.h
11519 --- linux-4.4.110/include/uapi/linux/if_tun.h   2015-10-29 09:21:42.000000000 +0000
11520 +++ linux-4.4.110-vs2.3.9/include/uapi/linux/if_tun.h   2018-01-09 16:46:34.000000000 +0000
11521 @@ -56,6 +56,7 @@
11522   */
11523  #define TUNSETVNETBE _IOW('T', 222, int)
11524  #define TUNGETVNETBE _IOR('T', 223, int)
11525 +#define TUNSETNID    _IOW('T', 224, int)
11526  
11527  /* TUNSETIFF ifr flags */
11528  #define IFF_TUN                0x0001
11529 diff -NurpP --minimal linux-4.4.110/include/uapi/linux/major.h linux-4.4.110-vs2.3.9/include/uapi/linux/major.h
11530 --- linux-4.4.110/include/uapi/linux/major.h    2015-04-12 22:12:50.000000000 +0000
11531 +++ linux-4.4.110-vs2.3.9/include/uapi/linux/major.h    2018-01-09 16:36:33.000000000 +0000
11532 @@ -15,6 +15,7 @@
11533  #define HD_MAJOR               IDE0_MAJOR
11534  #define PTY_SLAVE_MAJOR                3
11535  #define TTY_MAJOR              4
11536 +#define VROOT_MAJOR            4
11537  #define TTYAUX_MAJOR           5
11538  #define LP_MAJOR               6
11539  #define VCS_MAJOR              7
11540 diff -NurpP --minimal linux-4.4.110/include/uapi/linux/nfs_mount.h linux-4.4.110-vs2.3.9/include/uapi/linux/nfs_mount.h
11541 --- linux-4.4.110/include/uapi/linux/nfs_mount.h        2015-04-12 22:12:50.000000000 +0000
11542 +++ linux-4.4.110-vs2.3.9/include/uapi/linux/nfs_mount.h        2018-01-09 16:36:33.000000000 +0000
11543 @@ -63,7 +63,8 @@ struct nfs_mount_data {
11544  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 non-text parsed mount data only */
11545  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
11546  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
11547 -#define NFS_MOUNT_FLAGMASK     0xFFFF
11548 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
11549 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
11550  
11551  /* The following are for internal use only */
11552  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
11553 diff -NurpP --minimal linux-4.4.110/include/uapi/linux/reboot.h linux-4.4.110-vs2.3.9/include/uapi/linux/reboot.h
11554 --- linux-4.4.110/include/uapi/linux/reboot.h   2015-04-12 22:12:50.000000000 +0000
11555 +++ linux-4.4.110-vs2.3.9/include/uapi/linux/reboot.h   2018-01-09 16:36:33.000000000 +0000
11556 @@ -33,7 +33,7 @@
11557  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
11558  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
11559  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
11560 -
11561 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
11562  
11563  
11564  #endif /* _UAPI_LINUX_REBOOT_H */
11565 diff -NurpP --minimal linux-4.4.110/include/uapi/linux/sysctl.h linux-4.4.110-vs2.3.9/include/uapi/linux/sysctl.h
11566 --- linux-4.4.110/include/uapi/linux/sysctl.h   2015-04-12 22:12:50.000000000 +0000
11567 +++ linux-4.4.110-vs2.3.9/include/uapi/linux/sysctl.h   2018-01-09 16:36:33.000000000 +0000
11568 @@ -60,6 +60,7 @@ enum
11569         CTL_ABI=9,              /* Binary emulation */
11570         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
11571         CTL_ARLAN=254,          /* arlan wireless driver */
11572 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
11573         CTL_S390DBF=5677,       /* s390 debug */
11574         CTL_SUNRPC=7249,        /* sunrpc debug */
11575         CTL_PM=9899,            /* frv power management */
11576 @@ -94,6 +95,7 @@ enum
11577  
11578         KERN_PANIC=15,          /* int: panic timeout */
11579         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11580 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11581  
11582         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11583         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11584 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/Kbuild linux-4.4.110-vs2.3.9/include/uapi/vserver/Kbuild
11585 --- linux-4.4.110/include/uapi/vserver/Kbuild   1970-01-01 00:00:00.000000000 +0000
11586 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/Kbuild   2018-01-09 16:36:33.000000000 +0000
11587 @@ -0,0 +1,9 @@
11588 +
11589 +header-y += context_cmd.h network_cmd.h space_cmd.h \
11590 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11591 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11592 +       debug_cmd.h device_cmd.h
11593 +
11594 +header-y += switch.h context.h network.h monitor.h \
11595 +       limit.h inode.h device.h
11596 +
11597 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/cacct_cmd.h linux-4.4.110-vs2.3.9/include/uapi/vserver/cacct_cmd.h
11598 --- linux-4.4.110/include/uapi/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
11599 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/cacct_cmd.h      2018-01-09 16:36:33.000000000 +0000
11600 @@ -0,0 +1,15 @@
11601 +#ifndef _UAPI_VS_CACCT_CMD_H
11602 +#define _UAPI_VS_CACCT_CMD_H
11603 +
11604 +
11605 +/* virtual host info name commands */
11606 +
11607 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11608 +
11609 +struct vcmd_sock_stat_v0 {
11610 +       uint32_t field;
11611 +       uint32_t count[3];
11612 +       uint64_t total[3];
11613 +};
11614 +
11615 +#endif /* _UAPI_VS_CACCT_CMD_H */
11616 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/context.h linux-4.4.110-vs2.3.9/include/uapi/vserver/context.h
11617 --- linux-4.4.110/include/uapi/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
11618 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/context.h        2018-01-09 16:36:33.000000000 +0000
11619 @@ -0,0 +1,81 @@
11620 +#ifndef _UAPI_VS_CONTEXT_H
11621 +#define _UAPI_VS_CONTEXT_H
11622 +
11623 +#include <linux/types.h>
11624 +#include <linux/capability.h>
11625 +
11626 +
11627 +/* context flags */
11628 +
11629 +#define VXF_INFO_SCHED         0x00000002
11630 +#define VXF_INFO_NPROC         0x00000004
11631 +#define VXF_INFO_PRIVATE       0x00000008
11632 +
11633 +#define VXF_INFO_INIT          0x00000010
11634 +#define VXF_INFO_HIDE          0x00000020
11635 +#define VXF_INFO_ULIMIT                0x00000040
11636 +#define VXF_INFO_NSPACE                0x00000080
11637 +
11638 +#define VXF_SCHED_HARD         0x00000100
11639 +#define VXF_SCHED_PRIO         0x00000200
11640 +#define VXF_SCHED_PAUSE                0x00000400
11641 +
11642 +#define VXF_VIRT_MEM           0x00010000
11643 +#define VXF_VIRT_UPTIME                0x00020000
11644 +#define VXF_VIRT_CPU           0x00040000
11645 +#define VXF_VIRT_LOAD          0x00080000
11646 +#define VXF_VIRT_TIME          0x00100000
11647 +
11648 +#define VXF_HIDE_MOUNT         0x01000000
11649 +/* was VXF_HIDE_NETIF          0x02000000 */
11650 +#define VXF_HIDE_VINFO         0x04000000
11651 +
11652 +#define VXF_STATE_SETUP                (1ULL << 32)
11653 +#define VXF_STATE_INIT         (1ULL << 33)
11654 +#define VXF_STATE_ADMIN                (1ULL << 34)
11655 +
11656 +#define VXF_SC_HELPER          (1ULL << 36)
11657 +#define VXF_REBOOT_KILL                (1ULL << 37)
11658 +#define VXF_PERSISTENT         (1ULL << 38)
11659 +
11660 +#define VXF_FORK_RSS           (1ULL << 48)
11661 +#define VXF_PROLIFIC           (1ULL << 49)
11662 +
11663 +#define VXF_IGNEG_NICE         (1ULL << 52)
11664 +
11665 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11666 +
11667 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11668 +
11669 +
11670 +/* context migration */
11671 +
11672 +#define VXM_SET_INIT           0x00000001
11673 +#define VXM_SET_REAPER         0x00000002
11674 +
11675 +/* context caps */
11676 +
11677 +#define VXC_SET_UTSNAME                0x00000001
11678 +#define VXC_SET_RLIMIT         0x00000002
11679 +#define VXC_FS_SECURITY                0x00000004
11680 +#define VXC_FS_TRUSTED         0x00000008
11681 +#define VXC_TIOCSTI            0x00000010
11682 +
11683 +/* was VXC_RAW_ICMP            0x00000100 */
11684 +#define VXC_SYSLOG             0x00001000
11685 +#define VXC_OOM_ADJUST         0x00002000
11686 +#define VXC_AUDIT_CONTROL      0x00004000
11687 +
11688 +#define VXC_SECURE_MOUNT       0x00010000
11689 +/* #define VXC_SECURE_REMOUNT  0x00020000 */
11690 +#define VXC_BINARY_MOUNT       0x00040000
11691 +#define VXC_DEV_MOUNT          0x00080000
11692 +
11693 +#define VXC_QUOTA_CTL          0x00100000
11694 +#define VXC_ADMIN_MAPPER       0x00200000
11695 +#define VXC_ADMIN_CLOOP                0x00400000
11696 +
11697 +#define VXC_KTHREAD            0x01000000
11698 +#define VXC_NAMESPACE          0x02000000
11699 +
11700 +#endif /* _UAPI_VS_CONTEXT_H */
11701 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/context_cmd.h linux-4.4.110-vs2.3.9/include/uapi/vserver/context_cmd.h
11702 --- linux-4.4.110/include/uapi/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
11703 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/context_cmd.h    2018-01-09 16:36:33.000000000 +0000
11704 @@ -0,0 +1,115 @@
11705 +#ifndef _UAPI_VS_CONTEXT_CMD_H
11706 +#define _UAPI_VS_CONTEXT_CMD_H
11707 +
11708 +
11709 +/* vinfo commands */
11710 +
11711 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11712 +
11713 +
11714 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11715 +
11716 +struct vcmd_vx_info_v0 {
11717 +       uint32_t xid;
11718 +       uint32_t initpid;
11719 +       /* more to come */
11720 +};
11721 +
11722 +
11723 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11724 +
11725 +struct vcmd_ctx_stat_v0 {
11726 +       uint32_t usecnt;
11727 +       uint32_t tasks;
11728 +       /* more to come */
11729 +};
11730 +
11731 +
11732 +/* context commands */
11733 +
11734 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11735 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11736 +
11737 +struct vcmd_ctx_create {
11738 +       uint64_t flagword;
11739 +};
11740 +
11741 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11742 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11743 +
11744 +struct vcmd_ctx_migrate {
11745 +       uint64_t flagword;
11746 +};
11747 +
11748 +
11749 +
11750 +/* flag commands */
11751 +
11752 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11753 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11754 +
11755 +struct vcmd_ctx_flags_v0 {
11756 +       uint64_t flagword;
11757 +       uint64_t mask;
11758 +};
11759 +
11760 +
11761 +
11762 +/* context caps commands */
11763 +
11764 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11765 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11766 +
11767 +struct vcmd_ctx_caps_v1 {
11768 +       uint64_t ccaps;
11769 +       uint64_t cmask;
11770 +};
11771 +
11772 +
11773 +
11774 +/* bcaps commands */
11775 +
11776 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11777 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11778 +
11779 +struct vcmd_bcaps {
11780 +       uint64_t bcaps;
11781 +       uint64_t bmask;
11782 +};
11783 +
11784 +
11785 +
11786 +/* umask commands */
11787 +
11788 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11789 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11790 +
11791 +struct vcmd_umask {
11792 +       uint64_t umask;
11793 +       uint64_t mask;
11794 +};
11795 +
11796 +
11797 +
11798 +/* wmask commands */
11799 +
11800 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11801 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11802 +
11803 +struct vcmd_wmask {
11804 +       uint64_t wmask;
11805 +       uint64_t mask;
11806 +};
11807 +
11808 +
11809 +
11810 +/* OOM badness */
11811 +
11812 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11813 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11814 +
11815 +struct vcmd_badness_v0 {
11816 +       int64_t bias;
11817 +};
11818 +
11819 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
11820 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/cvirt_cmd.h linux-4.4.110-vs2.3.9/include/uapi/vserver/cvirt_cmd.h
11821 --- linux-4.4.110/include/uapi/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
11822 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/cvirt_cmd.h      2018-01-09 16:36:33.000000000 +0000
11823 @@ -0,0 +1,41 @@
11824 +#ifndef _UAPI_VS_CVIRT_CMD_H
11825 +#define _UAPI_VS_CVIRT_CMD_H
11826 +
11827 +
11828 +/* virtual host info name commands */
11829 +
11830 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11831 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11832 +
11833 +struct vcmd_vhi_name_v0 {
11834 +       uint32_t field;
11835 +       char name[65];
11836 +};
11837 +
11838 +
11839 +enum vhi_name_field {
11840 +       VHIN_CONTEXT = 0,
11841 +       VHIN_SYSNAME,
11842 +       VHIN_NODENAME,
11843 +       VHIN_RELEASE,
11844 +       VHIN_VERSION,
11845 +       VHIN_MACHINE,
11846 +       VHIN_DOMAINNAME,
11847 +};
11848 +
11849 +
11850 +
11851 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11852 +
11853 +struct vcmd_virt_stat_v0 {
11854 +       uint64_t offset;
11855 +       uint64_t uptime;
11856 +       uint32_t nr_threads;
11857 +       uint32_t nr_running;
11858 +       uint32_t nr_uninterruptible;
11859 +       uint32_t nr_onhold;
11860 +       uint32_t nr_forks;
11861 +       uint32_t load[3];
11862 +};
11863 +
11864 +#endif /* _UAPI_VS_CVIRT_CMD_H */
11865 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/debug_cmd.h linux-4.4.110-vs2.3.9/include/uapi/vserver/debug_cmd.h
11866 --- linux-4.4.110/include/uapi/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
11867 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/debug_cmd.h      2018-01-09 16:36:33.000000000 +0000
11868 @@ -0,0 +1,24 @@
11869 +#ifndef _UAPI_VS_DEBUG_CMD_H
11870 +#define _UAPI_VS_DEBUG_CMD_H
11871 +
11872 +
11873 +/* debug commands */
11874 +
11875 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11876 +
11877 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11878 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11879 +
11880 +struct  vcmd_read_history_v0 {
11881 +       uint32_t index;
11882 +       uint32_t count;
11883 +       char __user *data;
11884 +};
11885 +
11886 +struct  vcmd_read_monitor_v0 {
11887 +       uint32_t index;
11888 +       uint32_t count;
11889 +       char __user *data;
11890 +};
11891 +
11892 +#endif /* _UAPI_VS_DEBUG_CMD_H */
11893 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/device.h linux-4.4.110-vs2.3.9/include/uapi/vserver/device.h
11894 --- linux-4.4.110/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
11895 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/device.h 2018-01-09 16:36:33.000000000 +0000
11896 @@ -0,0 +1,12 @@
11897 +#ifndef _UAPI_VS_DEVICE_H
11898 +#define _UAPI_VS_DEVICE_H
11899 +
11900 +
11901 +#define DATTR_CREATE   0x00000001
11902 +#define DATTR_OPEN     0x00000002
11903 +
11904 +#define DATTR_REMAP    0x00000010
11905 +
11906 +#define DATTR_MASK     0x00000013
11907 +
11908 +#endif /* _UAPI_VS_DEVICE_H */
11909 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/device_cmd.h linux-4.4.110-vs2.3.9/include/uapi/vserver/device_cmd.h
11910 --- linux-4.4.110/include/uapi/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
11911 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/device_cmd.h     2018-01-09 16:36:33.000000000 +0000
11912 @@ -0,0 +1,16 @@
11913 +#ifndef _UAPI_VS_DEVICE_CMD_H
11914 +#define _UAPI_VS_DEVICE_CMD_H
11915 +
11916 +
11917 +/*  device vserver commands */
11918 +
11919 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11920 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11921 +
11922 +struct vcmd_set_mapping_v0 {
11923 +       const char __user *device;
11924 +       const char __user *target;
11925 +       uint32_t flags;
11926 +};
11927 +
11928 +#endif /* _UAPI_VS_DEVICE_CMD_H */
11929 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/dlimit_cmd.h linux-4.4.110-vs2.3.9/include/uapi/vserver/dlimit_cmd.h
11930 --- linux-4.4.110/include/uapi/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
11931 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/dlimit_cmd.h     2018-01-09 16:36:33.000000000 +0000
11932 @@ -0,0 +1,67 @@
11933 +#ifndef _UAPI_VS_DLIMIT_CMD_H
11934 +#define _UAPI_VS_DLIMIT_CMD_H
11935 +
11936 +
11937 +/*  dlimit vserver commands */
11938 +
11939 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11940 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11941 +
11942 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11943 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11944 +
11945 +struct vcmd_ctx_dlimit_base_v0 {
11946 +       const char __user *name;
11947 +       uint32_t flags;
11948 +};
11949 +
11950 +struct vcmd_ctx_dlimit_v0 {
11951 +       const char __user *name;
11952 +       uint32_t space_used;                    /* used space in kbytes */
11953 +       uint32_t space_total;                   /* maximum space in kbytes */
11954 +       uint32_t inodes_used;                   /* used inodes */
11955 +       uint32_t inodes_total;                  /* maximum inodes */
11956 +       uint32_t reserved;                      /* reserved for root in % */
11957 +       uint32_t flags;
11958 +};
11959 +
11960 +#define CDLIM_UNSET            ((uint32_t)0UL)
11961 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11962 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11963 +
11964 +#define DLIME_UNIT     0
11965 +#define DLIME_KILO     1
11966 +#define DLIME_MEGA     2
11967 +#define DLIME_GIGA     3
11968 +
11969 +#define DLIMF_SHIFT    0x10
11970 +
11971 +#define DLIMS_USED     0
11972 +#define DLIMS_TOTAL    2
11973 +
11974 +static inline
11975 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11976 +{
11977 +       int exp = (flags & DLIMF_SHIFT) ?
11978 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11979 +       return ((uint64_t)val) << (10 * exp);
11980 +}
11981 +
11982 +static inline
11983 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11984 +{
11985 +       int exp = 0;
11986 +
11987 +       if (*flags & DLIMF_SHIFT) {
11988 +               while (val > (1LL << 32) && (exp < 3)) {
11989 +                       val >>= 10;
11990 +                       exp++;
11991 +               }
11992 +               *flags &= ~(DLIME_GIGA << shift);
11993 +               *flags |= exp << shift;
11994 +       } else
11995 +               val >>= 10;
11996 +       return val;
11997 +}
11998 +
11999 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
12000 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/inode.h linux-4.4.110-vs2.3.9/include/uapi/vserver/inode.h
12001 --- linux-4.4.110/include/uapi/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
12002 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/inode.h  2018-01-09 16:36:33.000000000 +0000
12003 @@ -0,0 +1,23 @@
12004 +#ifndef _UAPI_VS_INODE_H
12005 +#define _UAPI_VS_INODE_H
12006 +
12007 +
12008 +#define IATTR_TAG      0x01000000
12009 +
12010 +#define IATTR_ADMIN    0x00000001
12011 +#define IATTR_WATCH    0x00000002
12012 +#define IATTR_HIDE     0x00000004
12013 +#define IATTR_FLAGS    0x00000007
12014 +
12015 +#define IATTR_BARRIER  0x00010000
12016 +#define IATTR_IXUNLINK 0x00020000
12017 +#define IATTR_IMMUTABLE 0x00040000
12018 +#define IATTR_COW      0x00080000
12019 +
12020 +
12021 +/* inode ioctls */
12022 +
12023 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12024 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12025 +
12026 +#endif /* _UAPI_VS_INODE_H */
12027 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/inode_cmd.h linux-4.4.110-vs2.3.9/include/uapi/vserver/inode_cmd.h
12028 --- linux-4.4.110/include/uapi/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
12029 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/inode_cmd.h      2018-01-09 16:36:33.000000000 +0000
12030 @@ -0,0 +1,26 @@
12031 +#ifndef _UAPI_VS_INODE_CMD_H
12032 +#define _UAPI_VS_INODE_CMD_H
12033 +
12034 +
12035 +/*  inode vserver commands */
12036 +
12037 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12038 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12039 +
12040 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12041 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12042 +
12043 +struct vcmd_ctx_iattr_v1 {
12044 +       const char __user *name;
12045 +       uint32_t tag;
12046 +       uint32_t flags;
12047 +       uint32_t mask;
12048 +};
12049 +
12050 +struct vcmd_ctx_fiattr_v0 {
12051 +       uint32_t tag;
12052 +       uint32_t flags;
12053 +       uint32_t mask;
12054 +};
12055 +
12056 +#endif /* _UAPI_VS_INODE_CMD_H */
12057 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/limit.h linux-4.4.110-vs2.3.9/include/uapi/vserver/limit.h
12058 --- linux-4.4.110/include/uapi/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
12059 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/limit.h  2018-01-09 16:36:33.000000000 +0000
12060 @@ -0,0 +1,14 @@
12061 +#ifndef _UAPI_VS_LIMIT_H
12062 +#define _UAPI_VS_LIMIT_H
12063 +
12064 +
12065 +#define VLIMIT_NSOCK   16
12066 +#define VLIMIT_OPENFD  17
12067 +#define VLIMIT_ANON    18
12068 +#define VLIMIT_SHMEM   19
12069 +#define VLIMIT_SEMARY  20
12070 +#define VLIMIT_NSEMS   21
12071 +#define VLIMIT_DENTRY  22
12072 +#define VLIMIT_MAPPED  23
12073 +
12074 +#endif /* _UAPI_VS_LIMIT_H */
12075 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/limit_cmd.h linux-4.4.110-vs2.3.9/include/uapi/vserver/limit_cmd.h
12076 --- linux-4.4.110/include/uapi/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
12077 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/limit_cmd.h      2018-01-09 16:36:33.000000000 +0000
12078 @@ -0,0 +1,40 @@
12079 +#ifndef _UAPI_VS_LIMIT_CMD_H
12080 +#define _UAPI_VS_LIMIT_CMD_H
12081 +
12082 +
12083 +/*  rlimit vserver commands */
12084 +
12085 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12086 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12087 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12088 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12089 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12090 +
12091 +struct vcmd_ctx_rlimit_v0 {
12092 +       uint32_t id;
12093 +       uint64_t minimum;
12094 +       uint64_t softlimit;
12095 +       uint64_t maximum;
12096 +};
12097 +
12098 +struct vcmd_ctx_rlimit_mask_v0 {
12099 +       uint32_t minimum;
12100 +       uint32_t softlimit;
12101 +       uint32_t maximum;
12102 +};
12103 +
12104 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12105 +
12106 +struct vcmd_rlimit_stat_v0 {
12107 +       uint32_t id;
12108 +       uint32_t hits;
12109 +       uint64_t value;
12110 +       uint64_t minimum;
12111 +       uint64_t maximum;
12112 +};
12113 +
12114 +#define CRLIM_UNSET            (0ULL)
12115 +#define CRLIM_INFINITY         (~0ULL)
12116 +#define CRLIM_KEEP             (~1ULL)
12117 +
12118 +#endif /* _UAPI_VS_LIMIT_CMD_H */
12119 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/monitor.h linux-4.4.110-vs2.3.9/include/uapi/vserver/monitor.h
12120 --- linux-4.4.110/include/uapi/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
12121 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/monitor.h        2018-01-09 16:36:33.000000000 +0000
12122 @@ -0,0 +1,96 @@
12123 +#ifndef _UAPI_VS_MONITOR_H
12124 +#define _UAPI_VS_MONITOR_H
12125 +
12126 +#include <linux/types.h>
12127 +
12128 +
12129 +enum {
12130 +       VXM_UNUSED = 0,
12131 +
12132 +       VXM_SYNC = 0x10,
12133 +
12134 +       VXM_UPDATE = 0x20,
12135 +       VXM_UPDATE_1,
12136 +       VXM_UPDATE_2,
12137 +
12138 +       VXM_RQINFO_1 = 0x24,
12139 +       VXM_RQINFO_2,
12140 +
12141 +       VXM_ACTIVATE = 0x40,
12142 +       VXM_DEACTIVATE,
12143 +       VXM_IDLE,
12144 +
12145 +       VXM_HOLD = 0x44,
12146 +       VXM_UNHOLD,
12147 +
12148 +       VXM_MIGRATE = 0x48,
12149 +       VXM_RESCHED,
12150 +
12151 +       /* all other bits are flags */
12152 +       VXM_SCHED = 0x80,
12153 +};
12154 +
12155 +struct _vxm_update_1 {
12156 +       uint32_t tokens_max;
12157 +       uint32_t fill_rate;
12158 +       uint32_t interval;
12159 +};
12160 +
12161 +struct _vxm_update_2 {
12162 +       uint32_t tokens_min;
12163 +       uint32_t fill_rate;
12164 +       uint32_t interval;
12165 +};
12166 +
12167 +struct _vxm_rqinfo_1 {
12168 +       uint16_t running;
12169 +       uint16_t onhold;
12170 +       uint16_t iowait;
12171 +       uint16_t uintr;
12172 +       uint32_t idle_tokens;
12173 +};
12174 +
12175 +struct _vxm_rqinfo_2 {
12176 +       uint32_t norm_time;
12177 +       uint32_t idle_time;
12178 +       uint32_t idle_skip;
12179 +};
12180 +
12181 +struct _vxm_sched {
12182 +       uint32_t tokens;
12183 +       uint32_t norm_time;
12184 +       uint32_t idle_time;
12185 +};
12186 +
12187 +struct _vxm_task {
12188 +       uint16_t pid;
12189 +       uint16_t state;
12190 +};
12191 +
12192 +struct _vxm_event {
12193 +       uint32_t jif;
12194 +       union {
12195 +               uint32_t seq;
12196 +               uint32_t sec;
12197 +       };
12198 +       union {
12199 +               uint32_t tokens;
12200 +               uint32_t nsec;
12201 +               struct _vxm_task tsk;
12202 +       };
12203 +};
12204 +
12205 +struct _vx_mon_entry {
12206 +       uint16_t type;
12207 +       uint16_t xid;
12208 +       union {
12209 +               struct _vxm_event ev;
12210 +               struct _vxm_sched sd;
12211 +               struct _vxm_update_1 u1;
12212 +               struct _vxm_update_2 u2;
12213 +               struct _vxm_rqinfo_1 q1;
12214 +               struct _vxm_rqinfo_2 q2;
12215 +       };
12216 +};
12217 +
12218 +#endif /* _UAPI_VS_MONITOR_H */
12219 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/network.h linux-4.4.110-vs2.3.9/include/uapi/vserver/network.h
12220 --- linux-4.4.110/include/uapi/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
12221 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/network.h        2018-01-09 16:36:33.000000000 +0000
12222 @@ -0,0 +1,76 @@
12223 +#ifndef _UAPI_VS_NETWORK_H
12224 +#define _UAPI_VS_NETWORK_H
12225 +
12226 +#include <linux/types.h>
12227 +
12228 +
12229 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12230 +
12231 +
12232 +/* network flags */
12233 +
12234 +#define NXF_INFO_PRIVATE       0x00000008
12235 +
12236 +#define NXF_SINGLE_IP          0x00000100
12237 +#define NXF_LBACK_REMAP                0x00000200
12238 +#define NXF_LBACK_ALLOW                0x00000400
12239 +
12240 +#define NXF_HIDE_NETIF         0x02000000
12241 +#define NXF_HIDE_LBACK         0x04000000
12242 +
12243 +#define NXF_STATE_SETUP                (1ULL << 32)
12244 +#define NXF_STATE_ADMIN                (1ULL << 34)
12245 +
12246 +#define NXF_SC_HELPER          (1ULL << 36)
12247 +#define NXF_PERSISTENT         (1ULL << 38)
12248 +
12249 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12250 +
12251 +
12252 +#define        NXF_INIT_SET            (__nxf_init_set())
12253 +
12254 +static inline uint64_t __nxf_init_set(void) {
12255 +       return    NXF_STATE_ADMIN
12256 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12257 +               | NXF_LBACK_REMAP
12258 +               | NXF_HIDE_LBACK
12259 +#endif
12260 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12261 +               | NXF_SINGLE_IP
12262 +#endif
12263 +               | NXF_HIDE_NETIF;
12264 +}
12265 +
12266 +
12267 +/* network caps */
12268 +
12269 +#define NXC_TUN_CREATE         0x00000001
12270 +
12271 +#define NXC_RAW_ICMP           0x00000100
12272 +
12273 +#define NXC_MULTICAST          0x00001000
12274 +
12275 +
12276 +/* address types */
12277 +
12278 +#define NXA_TYPE_IPV4          0x0001
12279 +#define NXA_TYPE_IPV6          0x0002
12280 +
12281 +#define NXA_TYPE_NONE          0x0000
12282 +#define NXA_TYPE_ANY           0x00FF
12283 +
12284 +#define NXA_TYPE_ADDR          0x0010
12285 +#define NXA_TYPE_MASK          0x0020
12286 +#define NXA_TYPE_RANGE         0x0040
12287 +
12288 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12289 +
12290 +#define NXA_MOD_BCAST          0x0100
12291 +#define NXA_MOD_LBACK          0x0200
12292 +
12293 +#define NXA_LOOPBACK           0x1000
12294 +
12295 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12296 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12297 +
12298 +#endif /* _UAPI_VS_NETWORK_H */
12299 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/network_cmd.h linux-4.4.110-vs2.3.9/include/uapi/vserver/network_cmd.h
12300 --- linux-4.4.110/include/uapi/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
12301 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/network_cmd.h    2018-01-09 16:36:33.000000000 +0000
12302 @@ -0,0 +1,123 @@
12303 +#ifndef _UAPI_VS_NETWORK_CMD_H
12304 +#define _UAPI_VS_NETWORK_CMD_H
12305 +
12306 +
12307 +/* vinfo commands */
12308 +
12309 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12310 +
12311 +
12312 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12313 +
12314 +struct vcmd_nx_info_v0 {
12315 +       uint32_t nid;
12316 +       /* more to come */
12317 +};
12318 +
12319 +
12320 +#include <linux/in.h>
12321 +#include <linux/in6.h>
12322 +
12323 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12324 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12325 +
12326 +struct  vcmd_net_create {
12327 +       uint64_t flagword;
12328 +};
12329 +
12330 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12331 +
12332 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12333 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12334 +
12335 +struct vcmd_net_addr_v0 {
12336 +       uint16_t type;
12337 +       uint16_t count;
12338 +       struct in_addr ip[4];
12339 +       struct in_addr mask[4];
12340 +};
12341 +
12342 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
12343 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
12344 +
12345 +struct vcmd_net_addr_ipv4_v1 {
12346 +       uint16_t type;
12347 +       uint16_t flags;
12348 +       struct in_addr ip;
12349 +       struct in_addr mask;
12350 +};
12351 +
12352 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
12353 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
12354 +
12355 +struct vcmd_net_addr_ipv4_v2 {
12356 +       uint16_t type;
12357 +       uint16_t flags;
12358 +       struct in_addr ip;
12359 +       struct in_addr ip2;
12360 +       struct in_addr mask;
12361 +};
12362 +
12363 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12364 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12365 +
12366 +struct vcmd_net_addr_ipv6_v1 {
12367 +       uint16_t type;
12368 +       uint16_t flags;
12369 +       uint32_t prefix;
12370 +       struct in6_addr ip;
12371 +       struct in6_addr mask;
12372 +};
12373 +
12374 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12375 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12376 +
12377 +struct vcmd_match_ipv4_v0 {
12378 +       uint16_t type;
12379 +       uint16_t flags;
12380 +       uint16_t parent;
12381 +       uint16_t prefix;
12382 +       struct in_addr ip;
12383 +       struct in_addr ip2;
12384 +       struct in_addr mask;
12385 +};
12386 +
12387 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12388 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12389 +
12390 +struct vcmd_match_ipv6_v0 {
12391 +       uint16_t type;
12392 +       uint16_t flags;
12393 +       uint16_t parent;
12394 +       uint16_t prefix;
12395 +       struct in6_addr ip;
12396 +       struct in6_addr ip2;
12397 +       struct in6_addr mask;
12398 +};
12399 +
12400 +
12401 +
12402 +
12403 +/* flag commands */
12404 +
12405 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12406 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12407 +
12408 +struct vcmd_net_flags_v0 {
12409 +       uint64_t flagword;
12410 +       uint64_t mask;
12411 +};
12412 +
12413 +
12414 +
12415 +/* network caps commands */
12416 +
12417 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12418 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12419 +
12420 +struct vcmd_net_caps_v0 {
12421 +       uint64_t ncaps;
12422 +       uint64_t cmask;
12423 +};
12424 +
12425 +#endif /* _UAPI_VS_NETWORK_CMD_H */
12426 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/sched_cmd.h linux-4.4.110-vs2.3.9/include/uapi/vserver/sched_cmd.h
12427 --- linux-4.4.110/include/uapi/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
12428 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/sched_cmd.h      2018-01-09 16:36:33.000000000 +0000
12429 @@ -0,0 +1,13 @@
12430 +#ifndef _UAPI_VS_SCHED_CMD_H
12431 +#define _UAPI_VS_SCHED_CMD_H
12432 +
12433 +
12434 +struct vcmd_prio_bias {
12435 +       int32_t cpu_id;
12436 +       int32_t prio_bias;
12437 +};
12438 +
12439 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
12440 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
12441 +
12442 +#endif /* _UAPI_VS_SCHED_CMD_H */
12443 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/signal_cmd.h linux-4.4.110-vs2.3.9/include/uapi/vserver/signal_cmd.h
12444 --- linux-4.4.110/include/uapi/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
12445 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/signal_cmd.h     2018-01-09 16:36:33.000000000 +0000
12446 @@ -0,0 +1,31 @@
12447 +#ifndef _UAPI_VS_SIGNAL_CMD_H
12448 +#define _UAPI_VS_SIGNAL_CMD_H
12449 +
12450 +
12451 +/*  signalling vserver commands */
12452 +
12453 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12454 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12455 +
12456 +struct vcmd_ctx_kill_v0 {
12457 +       int32_t pid;
12458 +       int32_t sig;
12459 +};
12460 +
12461 +struct vcmd_wait_exit_v0 {
12462 +       int32_t reboot_cmd;
12463 +       int32_t exit_code;
12464 +};
12465 +
12466 +
12467 +/*  process alteration commands */
12468 +
12469 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12470 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12471 +
12472 +struct vcmd_pflags_v0 {
12473 +       uint32_t flagword;
12474 +       uint32_t mask;
12475 +};
12476 +
12477 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
12478 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/space_cmd.h linux-4.4.110-vs2.3.9/include/uapi/vserver/space_cmd.h
12479 --- linux-4.4.110/include/uapi/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
12480 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/space_cmd.h      2018-01-09 16:36:33.000000000 +0000
12481 @@ -0,0 +1,28 @@
12482 +#ifndef _UAPI_VS_SPACE_CMD_H
12483 +#define _UAPI_VS_SPACE_CMD_H
12484 +
12485 +
12486 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12487 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12488 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12489 +
12490 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12491 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12492 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12493 +
12494 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12495 +
12496 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12497 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12498 +
12499 +
12500 +struct vcmd_space_mask_v1 {
12501 +       uint64_t mask;
12502 +};
12503 +
12504 +struct vcmd_space_mask_v2 {
12505 +       uint64_t mask;
12506 +       uint32_t index;
12507 +};
12508 +
12509 +#endif /* _UAPI_VS_SPACE_CMD_H */
12510 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/switch.h linux-4.4.110-vs2.3.9/include/uapi/vserver/switch.h
12511 --- linux-4.4.110/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12512 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/switch.h 2018-01-09 16:36:33.000000000 +0000
12513 @@ -0,0 +1,90 @@
12514 +#ifndef _UAPI_VS_SWITCH_H
12515 +#define _UAPI_VS_SWITCH_H
12516 +
12517 +#include <linux/types.h>
12518 +
12519 +
12520 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12521 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12522 +#define VC_VERSION(c)          ((c) & 0xFFF)
12523 +
12524 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12525 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12526 +
12527 +/*
12528 +
12529 +  Syscall Matrix V2.8
12530 +
12531 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12532 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12533 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12534 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12535 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
12536 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
12537 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12538 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
12539 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
12540 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12541 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
12542 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
12543 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12544 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
12545 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
12546 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12547 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
12548 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
12549 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12550 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
12551 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
12552 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12553 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
12554 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
12555 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12556 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
12557 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
12558 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12559 +
12560 +*/
12561 +
12562 +#define VC_CAT_VERSION         0
12563 +
12564 +#define VC_CAT_VSETUP          1
12565 +#define VC_CAT_VHOST           2
12566 +
12567 +#define VC_CAT_DEVICE          6
12568 +
12569 +#define VC_CAT_VPROC           9
12570 +#define VC_CAT_PROCALT         10
12571 +#define VC_CAT_PROCMIG         11
12572 +#define VC_CAT_PROCTRL         12
12573 +
12574 +#define VC_CAT_SCHED           14
12575 +#define VC_CAT_MEMCTRL         20
12576 +
12577 +#define VC_CAT_VNET            25
12578 +#define VC_CAT_NETALT          26
12579 +#define VC_CAT_NETMIG          27
12580 +#define VC_CAT_NETCTRL         28
12581 +
12582 +#define VC_CAT_TAGMIG          35
12583 +#define VC_CAT_DLIMIT          36
12584 +#define VC_CAT_INODE           38
12585 +
12586 +#define VC_CAT_VSTAT           40
12587 +#define VC_CAT_VINFO           46
12588 +#define VC_CAT_EVENT           48
12589 +
12590 +#define VC_CAT_FLAGS           52
12591 +#define VC_CAT_VSPACE          54
12592 +#define VC_CAT_DEBUG           56
12593 +#define VC_CAT_RLIMIT          60
12594 +
12595 +#define VC_CAT_SYSTEST         61
12596 +#define VC_CAT_COMPAT          63
12597 +
12598 +/*  query version */
12599 +
12600 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
12601 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
12602 +
12603 +#endif /* _UAPI_VS_SWITCH_H */
12604 diff -NurpP --minimal linux-4.4.110/include/uapi/vserver/tag_cmd.h linux-4.4.110-vs2.3.9/include/uapi/vserver/tag_cmd.h
12605 --- linux-4.4.110/include/uapi/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
12606 +++ linux-4.4.110-vs2.3.9/include/uapi/vserver/tag_cmd.h        2018-01-09 16:36:33.000000000 +0000
12607 @@ -0,0 +1,14 @@
12608 +#ifndef _UAPI_VS_TAG_CMD_H
12609 +#define _UAPI_VS_TAG_CMD_H
12610 +
12611 +
12612 +/* vinfo commands */
12613 +
12614 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
12615 +
12616 +
12617 +/* context commands */
12618 +
12619 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
12620 +
12621 +#endif /* _UAPI_VS_TAG_CMD_H */
12622 diff -NurpP --minimal linux-4.4.110/init/Kconfig linux-4.4.110-vs2.3.9/init/Kconfig
12623 --- linux-4.4.110/init/Kconfig  2016-07-05 04:15:12.000000000 +0000
12624 +++ linux-4.4.110-vs2.3.9/init/Kconfig  2018-01-09 16:36:33.000000000 +0000
12625 @@ -927,6 +927,7 @@ config NUMA_BALANCING_DEFAULT_ENABLED
12626  menuconfig CGROUPS
12627         bool "Control Group support"
12628         select KERNFS
12629 +       default y
12630         help
12631           This option adds support for grouping sets of processes together, for
12632           use with process control subsystems such as Cpusets, CFS, memory
12633 diff -NurpP --minimal linux-4.4.110/init/main.c linux-4.4.110-vs2.3.9/init/main.c
12634 --- linux-4.4.110/init/main.c   2018-01-09 16:35:10.000000000 +0000
12635 +++ linux-4.4.110-vs2.3.9/init/main.c   2018-01-09 16:58:21.000000000 +0000
12636 @@ -82,6 +82,7 @@
12637  #include <linux/proc_ns.h>
12638  #include <linux/io.h>
12639  #include <linux/kaiser.h>
12640 +#include <linux/vserver/percpu.h>
12641  
12642  #include <asm/io.h>
12643  #include <asm/bugs.h>
12644 diff -NurpP --minimal linux-4.4.110/ipc/mqueue.c linux-4.4.110-vs2.3.9/ipc/mqueue.c
12645 --- linux-4.4.110/ipc/mqueue.c  2018-01-09 16:35:10.000000000 +0000
12646 +++ linux-4.4.110-vs2.3.9/ipc/mqueue.c  2018-01-09 16:36:33.000000000 +0000
12647 @@ -35,6 +35,8 @@
12648  #include <linux/ipc_namespace.h>
12649  #include <linux/user_namespace.h>
12650  #include <linux/slab.h>
12651 +#include <linux/vs_context.h>
12652 +#include <linux/vs_limit.h>
12653  
12654  #include <net/sock.h>
12655  #include "util.h"
12656 @@ -75,6 +77,7 @@ struct mqueue_inode_info {
12657         struct pid *notify_owner;
12658         struct user_namespace *notify_user_ns;
12659         struct user_struct *user;       /* user who created, for accounting */
12660 +       struct vx_info *vxi;
12661         struct sock *notify_sock;
12662         struct sk_buff *notify_cookie;
12663  
12664 @@ -230,6 +233,7 @@ static struct inode *mqueue_get_inode(st
12665         if (S_ISREG(mode)) {
12666                 struct mqueue_inode_info *info;
12667                 unsigned long mq_bytes, mq_treesize;
12668 +               struct vx_info *vxi = current_vx_info();
12669  
12670                 inode->i_fop = &mqueue_file_operations;
12671                 inode->i_size = FILENT_SIZE;
12672 @@ -243,6 +247,7 @@ static struct inode *mqueue_get_inode(st
12673                 info->notify_user_ns = NULL;
12674                 info->qsize = 0;
12675                 info->user = NULL;      /* set when all is ok */
12676 +               info->vxi = NULL;
12677                 info->msg_tree = RB_ROOT;
12678                 info->node_cache = NULL;
12679                 memset(&info->attr, 0, sizeof(info->attr));
12680 @@ -276,17 +281,20 @@ static struct inode *mqueue_get_inode(st
12681  
12682                 spin_lock(&mq_lock);
12683                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
12684 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
12685 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
12686 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
12687                         spin_unlock(&mq_lock);
12688                         /* mqueue_evict_inode() releases info->messages */
12689                         ret = -EMFILE;
12690                         goto out_inode;
12691                 }
12692                 u->mq_bytes += mq_bytes;
12693 +               vx_ipcmsg_add(vxi, u, mq_bytes);
12694                 spin_unlock(&mq_lock);
12695  
12696                 /* all is ok */
12697                 info->user = get_uid(u);
12698 +               info->vxi = get_vx_info(vxi);
12699         } else if (S_ISDIR(mode)) {
12700                 inc_nlink(inode);
12701                 /* Some things misbehave if size == 0 on a directory */
12702 @@ -398,8 +406,11 @@ static void mqueue_evict_inode(struct in
12703  
12704         user = info->user;
12705         if (user) {
12706 +               struct vx_info *vxi = info->vxi;
12707 +
12708                 spin_lock(&mq_lock);
12709                 user->mq_bytes -= mq_bytes;
12710 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
12711                 /*
12712                  * get_ns_from_inode() ensures that the
12713                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
12714 @@ -409,6 +420,7 @@ static void mqueue_evict_inode(struct in
12715                 if (ipc_ns)
12716                         ipc_ns->mq_queues_count--;
12717                 spin_unlock(&mq_lock);
12718 +               put_vx_info(vxi);
12719                 free_uid(user);
12720         }
12721         if (ipc_ns)
12722 diff -NurpP --minimal linux-4.4.110/ipc/msg.c linux-4.4.110-vs2.3.9/ipc/msg.c
12723 --- linux-4.4.110/ipc/msg.c     2018-01-09 16:35:10.000000000 +0000
12724 +++ linux-4.4.110-vs2.3.9/ipc/msg.c     2018-01-09 16:36:33.000000000 +0000
12725 @@ -37,6 +37,7 @@
12726  #include <linux/rwsem.h>
12727  #include <linux/nsproxy.h>
12728  #include <linux/ipc_namespace.h>
12729 +#include <linux/vs_base.h>
12730  
12731  #include <asm/current.h>
12732  #include <linux/uaccess.h>
12733 @@ -129,6 +130,7 @@ static int newque(struct ipc_namespace *
12734  
12735         msq->q_perm.mode = msgflg & S_IRWXUGO;
12736         msq->q_perm.key = key;
12737 +       msq->q_perm.xid = vx_current_xid();
12738  
12739         msq->q_perm.security = NULL;
12740         retval = security_msg_queue_alloc(msq);
12741 diff -NurpP --minimal linux-4.4.110/ipc/sem.c linux-4.4.110-vs2.3.9/ipc/sem.c
12742 --- linux-4.4.110/ipc/sem.c     2018-01-09 16:35:10.000000000 +0000
12743 +++ linux-4.4.110-vs2.3.9/ipc/sem.c     2018-01-09 16:36:33.000000000 +0000
12744 @@ -85,6 +85,8 @@
12745  #include <linux/rwsem.h>
12746  #include <linux/nsproxy.h>
12747  #include <linux/ipc_namespace.h>
12748 +#include <linux/vs_base.h>
12749 +#include <linux/vs_limit.h>
12750  
12751  #include <linux/uaccess.h>
12752  #include "util.h"
12753 @@ -533,6 +535,7 @@ static int newary(struct ipc_namespace *
12754  
12755         sma->sem_perm.mode = (semflg & S_IRWXUGO);
12756         sma->sem_perm.key = key;
12757 +       sma->sem_perm.xid = vx_current_xid();
12758  
12759         sma->sem_perm.security = NULL;
12760         retval = security_sem_alloc(sma);
12761 @@ -563,6 +566,9 @@ static int newary(struct ipc_namespace *
12762                 return id;
12763         }
12764         ns->used_sems += nsems;
12765 +       /* FIXME: obsoleted? */
12766 +       vx_semary_inc(sma);
12767 +       vx_nsems_add(sma, nsems);
12768  
12769         sem_unlock(sma, -1);
12770         rcu_read_unlock();
12771 @@ -1151,6 +1157,9 @@ static void freeary(struct ipc_namespace
12772  
12773         wake_up_sem_queue_do(&tasks);
12774         ns->used_sems -= sma->sem_nsems;
12775 +       /* FIXME: obsoleted? */
12776 +       vx_nsems_sub(sma, sma->sem_nsems);
12777 +       vx_semary_dec(sma);
12778         ipc_rcu_putref(sma, sem_rcu_free);
12779  }
12780  
12781 diff -NurpP --minimal linux-4.4.110/ipc/shm.c linux-4.4.110-vs2.3.9/ipc/shm.c
12782 --- linux-4.4.110/ipc/shm.c     2018-01-09 16:35:10.000000000 +0000
12783 +++ linux-4.4.110-vs2.3.9/ipc/shm.c     2018-01-09 16:36:33.000000000 +0000
12784 @@ -42,6 +42,8 @@
12785  #include <linux/nsproxy.h>
12786  #include <linux/mount.h>
12787  #include <linux/ipc_namespace.h>
12788 +#include <linux/vs_context.h>
12789 +#include <linux/vs_limit.h>
12790  
12791  #include <linux/uaccess.h>
12792  
12793 @@ -228,10 +230,14 @@ static void shm_open(struct vm_area_stru
12794  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
12795  {
12796         struct file *shm_file;
12797 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
12798 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
12799  
12800         shm_file = shp->shm_file;
12801         shp->shm_file = NULL;
12802 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
12803 +       vx_ipcshm_sub(vxi, shp, numpages);
12804 +       ns->shm_tot -= numpages;
12805 +
12806         shm_rmid(ns, shp);
12807         shm_unlock(shp);
12808         if (!is_file_hugepages(shm_file))
12809 @@ -240,6 +246,7 @@ static void shm_destroy(struct ipc_names
12810                 user_shm_unlock(i_size_read(file_inode(shm_file)),
12811                                 shp->mlock_user);
12812         fput(shm_file);
12813 +       put_vx_info(vxi);
12814         ipc_rcu_putref(shp, shm_rcu_free);
12815  }
12816  
12817 @@ -537,11 +544,15 @@ static int newseg(struct ipc_namespace *
12818                         ns->shm_tot + numpages > ns->shm_ctlall)
12819                 return -ENOSPC;
12820  
12821 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
12822 +               return -ENOSPC;
12823 +
12824         shp = ipc_rcu_alloc(sizeof(*shp));
12825         if (!shp)
12826                 return -ENOMEM;
12827  
12828         shp->shm_perm.key = key;
12829 +       shp->shm_perm.xid = vx_current_xid();
12830         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
12831         shp->mlock_user = NULL;
12832  
12833 @@ -612,6 +623,7 @@ static int newseg(struct ipc_namespace *
12834  
12835         ipc_unlock_object(&shp->shm_perm);
12836         rcu_read_unlock();
12837 +       vx_ipcshm_add(current_vx_info(), key, numpages);
12838         return error;
12839  
12840  no_id:
12841 diff -NurpP --minimal linux-4.4.110/kernel/Makefile linux-4.4.110-vs2.3.9/kernel/Makefile
12842 --- linux-4.4.110/kernel/Makefile       2016-07-05 04:12:38.000000000 +0000
12843 +++ linux-4.4.110-vs2.3.9/kernel/Makefile       2018-01-09 16:36:33.000000000 +0000
12844 @@ -29,6 +29,7 @@ obj-y += printk/
12845  obj-y += irq/
12846  obj-y += rcu/
12847  obj-y += livepatch/
12848 +obj-y += vserver/
12849  
12850  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
12851  obj-$(CONFIG_FREEZER) += freezer.o
12852 diff -NurpP --minimal linux-4.4.110/kernel/auditsc.c linux-4.4.110-vs2.3.9/kernel/auditsc.c
12853 --- linux-4.4.110/kernel/auditsc.c      2018-01-09 16:35:12.000000000 +0000
12854 +++ linux-4.4.110-vs2.3.9/kernel/auditsc.c      2018-01-09 16:36:33.000000000 +0000
12855 @@ -1962,7 +1962,7 @@ static int audit_set_loginuid_perm(kuid_
12856         if (is_audit_feature_set(AUDIT_FEATURE_LOGINUID_IMMUTABLE))
12857                 return -EPERM;
12858         /* it is set, you need permission */
12859 -       if (!capable(CAP_AUDIT_CONTROL))
12860 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
12861                 return -EPERM;
12862         /* reject if this is not an unset and we don't allow that */
12863         if (is_audit_feature_set(AUDIT_FEATURE_ONLY_UNSET_LOGINUID) && uid_valid(loginuid))
12864 diff -NurpP --minimal linux-4.4.110/kernel/capability.c linux-4.4.110-vs2.3.9/kernel/capability.c
12865 --- linux-4.4.110/kernel/capability.c   2018-01-09 16:35:12.000000000 +0000
12866 +++ linux-4.4.110-vs2.3.9/kernel/capability.c   2018-01-09 16:36:33.000000000 +0000
12867 @@ -17,6 +17,7 @@
12868  #include <linux/syscalls.h>
12869  #include <linux/pid_namespace.h>
12870  #include <linux/user_namespace.h>
12871 +#include <linux/vs_context.h>
12872  #include <asm/uaccess.h>
12873  
12874  /*
12875 @@ -107,6 +108,7 @@ static int cap_validate_magic(cap_user_h
12876         return 0;
12877  }
12878  
12879 +
12880  /*
12881   * The only thing that can change the capabilities of the current
12882   * process is the current process. As such, we can't be in this code
12883 @@ -344,6 +346,8 @@ bool has_ns_capability_noaudit(struct ta
12884         return (ret == 0);
12885  }
12886  
12887 +#include <linux/vserver/base.h>
12888 +
12889  /**
12890   * has_capability_noaudit - Does a task have a capability (unaudited) in the
12891   * initial user ns
12892 diff -NurpP --minimal linux-4.4.110/kernel/compat.c linux-4.4.110-vs2.3.9/kernel/compat.c
12893 --- linux-4.4.110/kernel/compat.c       2015-07-06 20:41:43.000000000 +0000
12894 +++ linux-4.4.110-vs2.3.9/kernel/compat.c       2018-01-09 16:36:33.000000000 +0000
12895 @@ -27,6 +27,7 @@
12896  #include <linux/times.h>
12897  #include <linux/ptrace.h>
12898  #include <linux/gfp.h>
12899 +#include <linux/vs_time.h>
12900  
12901  #include <asm/uaccess.h>
12902  
12903 @@ -1059,7 +1060,7 @@ COMPAT_SYSCALL_DEFINE1(stime, compat_tim
12904         if (err)
12905                 return err;
12906  
12907 -       do_settimeofday(&tv);
12908 +       vx_settimeofday(&tv);
12909         return 0;
12910  }
12911  
12912 diff -NurpP --minimal linux-4.4.110/kernel/cred.c linux-4.4.110-vs2.3.9/kernel/cred.c
12913 --- linux-4.4.110/kernel/cred.c 2018-01-09 16:35:12.000000000 +0000
12914 +++ linux-4.4.110-vs2.3.9/kernel/cred.c 2018-01-09 16:36:33.000000000 +0000
12915 @@ -64,31 +64,6 @@ struct cred init_cred = {
12916         .group_info             = &init_groups,
12917  };
12918  
12919 -static inline void set_cred_subscribers(struct cred *cred, int n)
12920 -{
12921 -#ifdef CONFIG_DEBUG_CREDENTIALS
12922 -       atomic_set(&cred->subscribers, n);
12923 -#endif
12924 -}
12925 -
12926 -static inline int read_cred_subscribers(const struct cred *cred)
12927 -{
12928 -#ifdef CONFIG_DEBUG_CREDENTIALS
12929 -       return atomic_read(&cred->subscribers);
12930 -#else
12931 -       return 0;
12932 -#endif
12933 -}
12934 -
12935 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
12936 -{
12937 -#ifdef CONFIG_DEBUG_CREDENTIALS
12938 -       struct cred *cred = (struct cred *) _cred;
12939 -
12940 -       atomic_add(n, &cred->subscribers);
12941 -#endif
12942 -}
12943 -
12944  /*
12945   * The RCU callback to actually dispose of a set of credentials
12946   */
12947 @@ -240,21 +215,16 @@ error:
12948   *
12949   * Call commit_creds() or abort_creds() to clean up.
12950   */
12951 -struct cred *prepare_creds(void)
12952 +struct cred *__prepare_creds(const struct cred *old)
12953  {
12954 -       struct task_struct *task = current;
12955 -       const struct cred *old;
12956         struct cred *new;
12957  
12958 -       validate_process_creds();
12959 -
12960         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
12961         if (!new)
12962                 return NULL;
12963  
12964         kdebug("prepare_creds() alloc %p", new);
12965  
12966 -       old = task->cred;
12967         memcpy(new, old, sizeof(struct cred));
12968  
12969         atomic_set(&new->usage, 1);
12970 @@ -283,6 +253,13 @@ error:
12971         abort_creds(new);
12972         return NULL;
12973  }
12974 +
12975 +struct cred *prepare_creds(void)
12976 +{
12977 +       validate_process_creds();
12978 +
12979 +       return __prepare_creds(current->cred);
12980 +}
12981  EXPORT_SYMBOL(prepare_creds);
12982  
12983  /*
12984 diff -NurpP --minimal linux-4.4.110/kernel/exit.c linux-4.4.110-vs2.3.9/kernel/exit.c
12985 --- linux-4.4.110/kernel/exit.c 2018-01-09 16:35:12.000000000 +0000
12986 +++ linux-4.4.110-vs2.3.9/kernel/exit.c 2018-01-09 16:59:03.000000000 +0000
12987 @@ -48,6 +48,10 @@
12988  #include <linux/fs_struct.h>
12989  #include <linux/init_task.h>
12990  #include <linux/perf_event.h>
12991 +#include <linux/vs_limit.h>
12992 +#include <linux/vs_context.h>
12993 +#include <linux/vs_network.h>
12994 +#include <linux/vs_pid.h>
12995  #include <trace/events/sched.h>
12996  #include <linux/hw_breakpoint.h>
12997  #include <linux/oom.h>
12998 @@ -456,14 +460,24 @@ static struct task_struct *find_child_re
12999  {
13000         struct pid_namespace *pid_ns = task_active_pid_ns(father);
13001         struct task_struct *reaper = pid_ns->child_reaper;
13002 +       struct vx_info *vxi = task_get_vx_info(father);
13003 +
13004 +       if (vxi) {
13005 +               BUG_ON(!vxi->vx_reaper);
13006 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
13007 +                   vxi->vx_reaper != father) {
13008 +                       reaper = vxi->vx_reaper;
13009 +                       goto out_put;
13010 +               }
13011 +       }
13012  
13013         if (likely(reaper != father))
13014 -               return reaper;
13015 +               goto out_put;
13016  
13017         reaper = find_alive_thread(father);
13018         if (reaper) {
13019                 pid_ns->child_reaper = reaper;
13020 -               return reaper;
13021 +               goto out_put;
13022         }
13023  
13024         write_unlock_irq(&tasklist_lock);
13025 @@ -474,7 +488,10 @@ static struct task_struct *find_child_re
13026         zap_pid_ns_processes(pid_ns);
13027         write_lock_irq(&tasklist_lock);
13028  
13029 -       return father;
13030 +       reaper = father;
13031 +out_put:
13032 +       put_vx_info(vxi);
13033 +       return reaper;
13034  }
13035  
13036  /*
13037 @@ -562,9 +579,13 @@ static void forget_original_parent(struc
13038                 return;
13039  
13040         reaper = find_new_reaper(father, reaper);
13041 -       list_for_each_entry(p, &father->children, sibling) {
13042 +       for (p = list_first_entry(&father->children, struct task_struct, sibling);
13043 +            &p->sibling != &father->children; ) {
13044 +               struct task_struct *next, *this_reaper = reaper;
13045 +               if (p == reaper)
13046 +                       this_reaper = task_active_pid_ns(reaper)->child_reaper;
13047                 for_each_thread(p, t) {
13048 -                       t->real_parent = reaper;
13049 +                       t->real_parent = this_reaper;
13050                         BUG_ON((!t->ptrace) != (t->parent == father));
13051                         if (likely(!t->ptrace))
13052                                 t->parent = t->real_parent;
13053 @@ -576,10 +597,13 @@ static void forget_original_parent(struc
13054                  * If this is a threaded reparent there is no need to
13055                  * notify anyone anything has happened.
13056                  */
13057 -               if (!same_thread_group(reaper, father))
13058 +               if (!same_thread_group(this_reaper, father))
13059                         reparent_leader(father, p, dead);
13060 +               next = list_next_entry(p, sibling);
13061 +               list_add(&p->sibling, &this_reaper->children);
13062 +               p = next;
13063         }
13064 -       list_splice_tail_init(&father->children, &reaper->children);
13065 +       INIT_LIST_HEAD(&father->children);
13066  }
13067  
13068  /*
13069 @@ -763,6 +787,9 @@ void do_exit(long code)
13070          */
13071         flush_ptrace_hw_breakpoint(tsk);
13072  
13073 +       /* needs to stay before exit_notify() */
13074 +       exit_vx_info_early(tsk, code);
13075 +
13076         TASKS_RCU(preempt_disable());
13077         TASKS_RCU(tasks_rcu_i = __srcu_read_lock(&tasks_rcu_exit_srcu));
13078         TASKS_RCU(preempt_enable());
13079 @@ -822,10 +849,15 @@ void do_exit(long code)
13080         smp_mb();
13081         raw_spin_unlock_wait(&tsk->pi_lock);
13082  
13083 +       /* needs to stay after exit_notify() */
13084 +       exit_vx_info(tsk, code);
13085 +       exit_nx_info(tsk);
13086 +
13087         /* causes final put_task_struct in finish_task_switch(). */
13088         tsk->state = TASK_DEAD;
13089         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
13090         schedule();
13091 +       printk("bad task: %p [%lx]\n", current, current->state);
13092         BUG();
13093         /* Avoid "noreturn function does return".  */
13094         for (;;)
13095 diff -NurpP --minimal linux-4.4.110/kernel/fork.c linux-4.4.110-vs2.3.9/kernel/fork.c
13096 --- linux-4.4.110/kernel/fork.c 2018-01-09 16:35:12.000000000 +0000
13097 +++ linux-4.4.110-vs2.3.9/kernel/fork.c 2018-01-09 17:00:00.000000000 +0000
13098 @@ -76,6 +76,9 @@
13099  #include <linux/aio.h>
13100  #include <linux/compiler.h>
13101  #include <linux/sysctl.h>
13102 +#include <linux/vs_context.h>
13103 +#include <linux/vs_network.h>
13104 +#include <linux/vs_limit.h>
13105  
13106  #include <asm/pgtable.h>
13107  #include <asm/pgalloc.h>
13108 @@ -227,6 +230,8 @@ void free_task(struct task_struct *tsk)
13109         arch_release_thread_info(tsk->stack);
13110         free_thread_info(tsk->stack);
13111         rt_mutex_debug_task_free(tsk);
13112 +       clr_vx_info(&tsk->vx_info);
13113 +       clr_nx_info(&tsk->nx_info);
13114         ftrace_graph_exit_task(tsk);
13115         put_seccomp_filter(tsk);
13116         arch_release_task_struct(tsk);
13117 @@ -1282,6 +1287,8 @@ static struct task_struct *copy_process(
13118  {
13119         int retval;
13120         struct task_struct *p;
13121 +       struct vx_info *vxi;
13122 +       struct nx_info *nxi;
13123         void *cgrp_ss_priv[CGROUP_CANFORK_COUNT] = {};
13124  
13125         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
13126 @@ -1343,7 +1350,12 @@ static struct task_struct *copy_process(
13127         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
13128         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
13129  #endif
13130 +       init_vx_info(&p->vx_info, current_vx_info());
13131 +       init_nx_info(&p->nx_info, current_nx_info());
13132 +
13133         retval = -EAGAIN;
13134 +       if (!vx_nproc_avail(1))
13135 +               goto bad_fork_free;
13136         if (atomic_read(&p->real_cred->user->processes) >=
13137                         task_rlimit(p, RLIMIT_NPROC)) {
13138                 if (p->real_cred->user != INIT_USER &&
13139 @@ -1640,6 +1652,18 @@ static struct task_struct *copy_process(
13140         total_forks++;
13141         spin_unlock(&current->sighand->siglock);
13142         syscall_tracepoint_update(p);
13143 +
13144 +       /* p is copy of current */
13145 +       vxi = p->vx_info;
13146 +       if (vxi) {
13147 +               claim_vx_info(vxi, p);
13148 +               atomic_inc(&vxi->cvirt.nr_threads);
13149 +               atomic_inc(&vxi->cvirt.total_forks);
13150 +               vx_nproc_inc(p);
13151 +       }
13152 +       nxi = p->nx_info;
13153 +       if (nxi)
13154 +               claim_nx_info(nxi, p);
13155         write_unlock_irq(&tasklist_lock);
13156  
13157         proc_fork_connector(p);
13158 diff -NurpP --minimal linux-4.4.110/kernel/kthread.c linux-4.4.110-vs2.3.9/kernel/kthread.c
13159 --- linux-4.4.110/kernel/kthread.c      2018-01-09 16:35:12.000000000 +0000
13160 +++ linux-4.4.110-vs2.3.9/kernel/kthread.c      2018-01-09 17:01:06.000000000 +0000
13161 @@ -19,6 +19,7 @@
13162  #include <linux/ptrace.h>
13163  #include <linux/uaccess.h>
13164  #include <linux/cgroup.h>
13165 +#include <linux/vs_pid.h>
13166  #include <trace/events/sched.h>
13167  
13168  static DEFINE_SPINLOCK(kthread_create_lock);
13169 diff -NurpP --minimal linux-4.4.110/kernel/nsproxy.c linux-4.4.110-vs2.3.9/kernel/nsproxy.c
13170 --- linux-4.4.110/kernel/nsproxy.c      2015-04-12 22:12:50.000000000 +0000
13171 +++ linux-4.4.110-vs2.3.9/kernel/nsproxy.c      2018-01-09 16:36:33.000000000 +0000
13172 @@ -20,11 +20,14 @@
13173  #include <linux/mnt_namespace.h>
13174  #include <linux/utsname.h>
13175  #include <linux/pid_namespace.h>
13176 +#include <linux/vserver/global.h>
13177 +#include <linux/vserver/debug.h>
13178  #include <net/net_namespace.h>
13179  #include <linux/ipc_namespace.h>
13180  #include <linux/proc_ns.h>
13181  #include <linux/file.h>
13182  #include <linux/syscalls.h>
13183 +#include "../fs/mount.h"
13184  
13185  static struct kmem_cache *nsproxy_cachep;
13186  
13187 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
13188         struct nsproxy *nsproxy;
13189  
13190         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
13191 -       if (nsproxy)
13192 +       if (nsproxy) {
13193                 atomic_set(&nsproxy->count, 1);
13194 +               atomic_inc(&vs_global_nsproxy);
13195 +       }
13196 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
13197         return nsproxy;
13198  }
13199  
13200 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
13201   * Return the newly created nsproxy.  Do not attach this to the task,
13202   * leave it to the caller to do proper locking and attach it to task.
13203   */
13204 -static struct nsproxy *create_new_namespaces(unsigned long flags,
13205 -       struct task_struct *tsk, struct user_namespace *user_ns,
13206 -       struct fs_struct *new_fs)
13207 +static struct nsproxy *unshare_namespaces(
13208 +       unsigned long flags,
13209 +       struct nsproxy *orig,
13210 +       struct fs_struct *new_fs,
13211 +       struct user_namespace *new_user,
13212 +       struct pid_namespace *new_pid)
13213  {
13214         struct nsproxy *new_nsp;
13215         int err;
13216 @@ -67,32 +76,31 @@ static struct nsproxy *create_new_namesp
13217         if (!new_nsp)
13218                 return ERR_PTR(-ENOMEM);
13219  
13220 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
13221 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
13222         if (IS_ERR(new_nsp->mnt_ns)) {
13223                 err = PTR_ERR(new_nsp->mnt_ns);
13224                 goto out_ns;
13225         }
13226  
13227 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
13228 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
13229         if (IS_ERR(new_nsp->uts_ns)) {
13230                 err = PTR_ERR(new_nsp->uts_ns);
13231                 goto out_uts;
13232         }
13233  
13234 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
13235 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
13236         if (IS_ERR(new_nsp->ipc_ns)) {
13237                 err = PTR_ERR(new_nsp->ipc_ns);
13238                 goto out_ipc;
13239         }
13240  
13241 -       new_nsp->pid_ns_for_children =
13242 -               copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
13243 +       new_nsp->pid_ns_for_children = copy_pid_ns(flags, new_user, new_pid);
13244         if (IS_ERR(new_nsp->pid_ns_for_children)) {
13245                 err = PTR_ERR(new_nsp->pid_ns_for_children);
13246                 goto out_pid;
13247         }
13248  
13249 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
13250 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
13251         if (IS_ERR(new_nsp->net_ns)) {
13252                 err = PTR_ERR(new_nsp->net_ns);
13253                 goto out_net;
13254 @@ -117,6 +125,41 @@ out_ns:
13255         return ERR_PTR(err);
13256  }
13257  
13258 +static struct nsproxy *create_new_namespaces(unsigned long flags,
13259 +       struct task_struct *tsk, struct user_namespace *user_ns,
13260 +       struct fs_struct *new_fs)
13261 +
13262 +{
13263 +       return unshare_namespaces(flags, tsk->nsproxy,
13264 +               new_fs, user_ns, task_active_pid_ns(tsk));
13265 +}
13266 +
13267 +/*
13268 + * copies the nsproxy, setting refcount to 1, and grabbing a
13269 + * reference to all contained namespaces.
13270 + */
13271 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
13272 +{
13273 +       struct nsproxy *ns = create_nsproxy();
13274 +
13275 +       if (ns) {
13276 +               memcpy(ns, orig, sizeof(struct nsproxy));
13277 +               atomic_set(&ns->count, 1);
13278 +
13279 +               if (ns->mnt_ns)
13280 +                       get_mnt_ns(ns->mnt_ns);
13281 +               if (ns->uts_ns)
13282 +                       get_uts_ns(ns->uts_ns);
13283 +               if (ns->ipc_ns)
13284 +                       get_ipc_ns(ns->ipc_ns);
13285 +               if (ns->pid_ns_for_children)
13286 +                       get_pid_ns(ns->pid_ns_for_children);
13287 +               if (ns->net_ns)
13288 +                       get_net(ns->net_ns);
13289 +       }
13290 +       return ns;
13291 +}
13292 +
13293  /*
13294   * called from clone.  This now handles copy for nsproxy and all
13295   * namespaces therein.
13296 @@ -125,7 +168,10 @@ int copy_namespaces(unsigned long flags,
13297  {
13298         struct nsproxy *old_ns = tsk->nsproxy;
13299         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
13300 -       struct nsproxy *new_ns;
13301 +       struct nsproxy *new_ns = NULL;
13302 +
13303 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
13304 +               flags, tsk, old_ns);
13305  
13306         if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13307                               CLONE_NEWPID | CLONE_NEWNET)))) {
13308 @@ -133,7 +179,7 @@ int copy_namespaces(unsigned long flags,
13309                 return 0;
13310         }
13311  
13312 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13313 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags))
13314                 return -EPERM;
13315  
13316         /*
13317 @@ -152,6 +198,9 @@ int copy_namespaces(unsigned long flags,
13318                 return  PTR_ERR(new_ns);
13319  
13320         tsk->nsproxy = new_ns;
13321 +       vxdprintk(VXD_CBIT(space, 3),
13322 +               "copy_namespaces(0x%08lx,%p[%p]) = [%p]",
13323 +               flags, tsk, old_ns, new_ns);
13324         return 0;
13325  }
13326  
13327 @@ -165,7 +214,9 @@ void free_nsproxy(struct nsproxy *ns)
13328                 put_ipc_ns(ns->ipc_ns);
13329         if (ns->pid_ns_for_children)
13330                 put_pid_ns(ns->pid_ns_for_children);
13331 -       put_net(ns->net_ns);
13332 +       if (ns->net_ns)
13333 +               put_net(ns->net_ns);
13334 +       atomic_dec(&vs_global_nsproxy);
13335         kmem_cache_free(nsproxy_cachep, ns);
13336  }
13337  
13338 @@ -179,12 +230,16 @@ int unshare_nsproxy_namespaces(unsigned
13339         struct user_namespace *user_ns;
13340         int err = 0;
13341  
13342 +       vxdprintk(VXD_CBIT(space, 4),
13343 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
13344 +               unshare_flags, current->nsproxy);
13345 +
13346         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13347                                CLONE_NEWNET | CLONE_NEWPID)))
13348                 return 0;
13349  
13350         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
13351 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13352 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
13353                 return -EPERM;
13354  
13355         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
13356 diff -NurpP --minimal linux-4.4.110/kernel/pid.c linux-4.4.110-vs2.3.9/kernel/pid.c
13357 --- linux-4.4.110/kernel/pid.c  2018-01-09 16:35:13.000000000 +0000
13358 +++ linux-4.4.110-vs2.3.9/kernel/pid.c  2018-01-09 21:54:23.000000000 +0000
13359 @@ -38,6 +38,7 @@
13360  #include <linux/syscalls.h>
13361  #include <linux/proc_ns.h>
13362  #include <linux/proc_fs.h>
13363 +#include <linux/vs_pid.h>
13364  
13365  #define pid_hashfn(nr, ns)     \
13366         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
13367 @@ -379,7 +380,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
13368  
13369  struct pid *find_vpid(int nr)
13370  {
13371 -       return find_pid_ns(nr, task_active_pid_ns(current));
13372 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
13373  }
13374  EXPORT_SYMBOL_GPL(find_vpid);
13375  
13376 @@ -435,6 +436,9 @@ void transfer_pid(struct task_struct *ol
13377  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
13378  {
13379         struct task_struct *result = NULL;
13380 +
13381 +       if (type == __PIDTYPE_REALPID)
13382 +               type = PIDTYPE_PID;
13383         if (pid) {
13384                 struct hlist_node *first;
13385                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
13386 @@ -453,7 +457,7 @@ struct task_struct *find_task_by_pid_ns(
13387  {
13388         RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
13389                          "find_task_by_pid_ns() needs rcu_read_lock() protection");
13390 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
13391 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
13392  }
13393  
13394  struct task_struct *find_task_by_vpid(pid_t vnr)
13395 @@ -497,7 +501,7 @@ struct pid *find_get_pid(pid_t nr)
13396  }
13397  EXPORT_SYMBOL_GPL(find_get_pid);
13398  
13399 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13400 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
13401  {
13402         struct upid *upid;
13403         pid_t nr = 0;
13404 @@ -511,6 +515,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
13405  }
13406  EXPORT_SYMBOL_GPL(pid_nr_ns);
13407  
13408 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13409 +{
13410 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
13411 +}
13412 +
13413  pid_t pid_vnr(struct pid *pid)
13414  {
13415         return pid_nr_ns(pid, task_active_pid_ns(current));
13416 diff -NurpP --minimal linux-4.4.110/kernel/pid_namespace.c linux-4.4.110-vs2.3.9/kernel/pid_namespace.c
13417 --- linux-4.4.110/kernel/pid_namespace.c        2018-01-09 16:35:13.000000000 +0000
13418 +++ linux-4.4.110-vs2.3.9/kernel/pid_namespace.c        2018-01-09 16:36:33.000000000 +0000
13419 @@ -18,6 +18,7 @@
13420  #include <linux/proc_ns.h>
13421  #include <linux/reboot.h>
13422  #include <linux/export.h>
13423 +#include <linux/vserver/global.h>
13424  
13425  struct pid_cache {
13426         int nr_ids;
13427 @@ -111,6 +112,7 @@ static struct pid_namespace *create_pid_
13428         ns->ns.ops = &pidns_operations;
13429  
13430         kref_init(&ns->kref);
13431 +       atomic_inc(&vs_global_pid_ns);
13432         ns->level = level;
13433         ns->parent = get_pid_ns(parent_pid_ns);
13434         ns->user_ns = get_user_ns(user_ns);
13435 @@ -128,6 +130,7 @@ static struct pid_namespace *create_pid_
13436  out_free_map:
13437         kfree(ns->pidmap[0].page);
13438  out_free:
13439 +       atomic_dec(&vs_global_pid_ns);
13440         kmem_cache_free(pid_ns_cachep, ns);
13441  out:
13442         return ERR_PTR(err);
13443 diff -NurpP --minimal linux-4.4.110/kernel/printk/printk.c linux-4.4.110-vs2.3.9/kernel/printk/printk.c
13444 --- linux-4.4.110/kernel/printk/printk.c        2018-01-09 16:35:13.000000000 +0000
13445 +++ linux-4.4.110-vs2.3.9/kernel/printk/printk.c        2018-01-09 16:36:33.000000000 +0000
13446 @@ -46,6 +46,7 @@
13447  #include <linux/utsname.h>
13448  #include <linux/ctype.h>
13449  #include <linux/uio.h>
13450 +#include <linux/vs_cvirt.h>
13451  
13452  #include <asm/uaccess.h>
13453  
13454 @@ -502,7 +503,7 @@ int check_syslog_permissions(int type, i
13455                 goto ok;
13456  
13457         if (syslog_action_restricted(type)) {
13458 -               if (capable(CAP_SYSLOG))
13459 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
13460                         goto ok;
13461                 /*
13462                  * For historical reasons, accept CAP_SYS_ADMIN too, with
13463 @@ -1304,12 +1305,9 @@ int do_syslog(int type, char __user *buf
13464         if (error)
13465                 goto out;
13466  
13467 -       switch (type) {
13468 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
13469 -               break;
13470 -       case SYSLOG_ACTION_OPEN:        /* Open log */
13471 -               break;
13472 -       case SYSLOG_ACTION_READ:        /* Read from log */
13473 +       if ((type == SYSLOG_ACTION_READ) ||
13474 +           (type == SYSLOG_ACTION_READ_ALL) ||
13475 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
13476                 error = -EINVAL;
13477                 if (!buf || len < 0)
13478                         goto out;
13479 @@ -1320,6 +1318,16 @@ int do_syslog(int type, char __user *buf
13480                         error = -EFAULT;
13481                         goto out;
13482                 }
13483 +       }
13484 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13485 +               return vx_do_syslog(type, buf, len);
13486 +
13487 +       switch (type) {
13488 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
13489 +               break;
13490 +       case SYSLOG_ACTION_OPEN:        /* Open log */
13491 +               break;
13492 +       case SYSLOG_ACTION_READ:        /* Read from log */
13493                 error = wait_event_interruptible(log_wait,
13494                                                  syslog_seq != log_next_seq);
13495                 if (error)
13496 @@ -1332,16 +1340,6 @@ int do_syslog(int type, char __user *buf
13497                 /* FALL THRU */
13498         /* Read last kernel messages */
13499         case SYSLOG_ACTION_READ_ALL:
13500 -               error = -EINVAL;
13501 -               if (!buf || len < 0)
13502 -                       goto out;
13503 -               error = 0;
13504 -               if (!len)
13505 -                       goto out;
13506 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
13507 -                       error = -EFAULT;
13508 -                       goto out;
13509 -               }
13510                 error = syslog_print_all(buf, len, clear);
13511                 break;
13512         /* Clear ring buffer */
13513 diff -NurpP --minimal linux-4.4.110/kernel/ptrace.c linux-4.4.110-vs2.3.9/kernel/ptrace.c
13514 --- linux-4.4.110/kernel/ptrace.c       2018-01-09 16:35:13.000000000 +0000
13515 +++ linux-4.4.110-vs2.3.9/kernel/ptrace.c       2018-01-09 16:36:33.000000000 +0000
13516 @@ -23,6 +23,7 @@
13517  #include <linux/syscalls.h>
13518  #include <linux/uaccess.h>
13519  #include <linux/regset.h>
13520 +#include <linux/vs_context.h>
13521  #include <linux/hw_breakpoint.h>
13522  #include <linux/cn_proc.h>
13523  #include <linux/compat.h>
13524 @@ -295,6 +296,11 @@ ok:
13525              !ptrace_has_cap(mm->user_ns, mode)))
13526             return -EPERM;
13527  
13528 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
13529 +               return -EPERM;
13530 +       if (!vx_check(task->xid, VS_IDENT) &&
13531 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
13532 +               return -EACCES;
13533         return security_ptrace_access_check(task, mode);
13534  }
13535  
13536 diff -NurpP --minimal linux-4.4.110/kernel/reboot.c linux-4.4.110-vs2.3.9/kernel/reboot.c
13537 --- linux-4.4.110/kernel/reboot.c       2016-07-05 04:12:39.000000000 +0000
13538 +++ linux-4.4.110-vs2.3.9/kernel/reboot.c       2018-01-09 16:36:33.000000000 +0000
13539 @@ -16,6 +16,7 @@
13540  #include <linux/syscalls.h>
13541  #include <linux/syscore_ops.h>
13542  #include <linux/uaccess.h>
13543 +#include <linux/vs_pid.h>
13544  
13545  /*
13546   * this indicates whether you can reboot with ctrl-alt-del: the default is yes
13547 @@ -269,6 +270,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
13548  
13549  static DEFINE_MUTEX(reboot_mutex);
13550  
13551 +long vs_reboot(unsigned int, void __user *);
13552 +
13553  /*
13554   * Reboot system call: for obvious reasons only root may call it,
13555   * and even root needs to set up some magic numbers in the registers
13556 @@ -311,6 +314,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
13557         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
13558                 cmd = LINUX_REBOOT_CMD_HALT;
13559  
13560 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13561 +               return vs_reboot(cmd, arg);
13562 +
13563         mutex_lock(&reboot_mutex);
13564         switch (cmd) {
13565         case LINUX_REBOOT_CMD_RESTART:
13566 diff -NurpP --minimal linux-4.4.110/kernel/sched/core.c linux-4.4.110-vs2.3.9/kernel/sched/core.c
13567 --- linux-4.4.110/kernel/sched/core.c   2018-01-09 16:35:13.000000000 +0000
13568 +++ linux-4.4.110-vs2.3.9/kernel/sched/core.c   2018-01-09 16:36:33.000000000 +0000
13569 @@ -74,6 +74,8 @@
13570  #include <linux/binfmts.h>
13571  #include <linux/context_tracking.h>
13572  #include <linux/compiler.h>
13573 +#include <linux/vs_sched.h>
13574 +#include <linux/vs_cvirt.h>
13575  
13576  #include <asm/switch_to.h>
13577  #include <asm/tlb.h>
13578 @@ -3558,7 +3560,7 @@ SYSCALL_DEFINE1(nice, int, increment)
13579  
13580         nice = clamp_val(nice, MIN_NICE, MAX_NICE);
13581         if (increment < 0 && !can_nice(current, nice))
13582 -               return -EPERM;
13583 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
13584  
13585         retval = security_task_setnice(current, nice);
13586         if (retval)
13587 diff -NurpP --minimal linux-4.4.110/kernel/sched/cputime.c linux-4.4.110-vs2.3.9/kernel/sched/cputime.c
13588 --- linux-4.4.110/kernel/sched/cputime.c        2018-01-09 16:35:13.000000000 +0000
13589 +++ linux-4.4.110-vs2.3.9/kernel/sched/cputime.c        2018-01-09 16:36:33.000000000 +0000
13590 @@ -4,6 +4,7 @@
13591  #include <linux/kernel_stat.h>
13592  #include <linux/static_key.h>
13593  #include <linux/context_tracking.h>
13594 +#include <linux/vs_sched.h>
13595  #include "sched.h"
13596  
13597  
13598 @@ -135,14 +136,17 @@ static inline void task_group_account_fi
13599  void account_user_time(struct task_struct *p, cputime_t cputime,
13600                        cputime_t cputime_scaled)
13601  {
13602 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
13603 +       int nice = (task_nice(p) > 0);
13604         int index;
13605  
13606         /* Add user time to process. */
13607         p->utime += cputime;
13608         p->utimescaled += cputime_scaled;
13609 +       vx_account_user(vxi, cputime, nice);
13610         account_group_user_time(p, cputime);
13611  
13612 -       index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
13613 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
13614  
13615         /* Add user time to cpustat. */
13616         task_group_account_field(p, index, (__force u64) cputime);
13617 @@ -189,9 +193,12 @@ static inline
13618  void __account_system_time(struct task_struct *p, cputime_t cputime,
13619                         cputime_t cputime_scaled, int index)
13620  {
13621 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
13622 +
13623         /* Add system time to process. */
13624         p->stime += cputime;
13625         p->stimescaled += cputime_scaled;
13626 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
13627         account_group_system_time(p, cputime);
13628  
13629         /* Add system time to cpustat. */
13630 diff -NurpP --minimal linux-4.4.110/kernel/sched/fair.c linux-4.4.110-vs2.3.9/kernel/sched/fair.c
13631 --- linux-4.4.110/kernel/sched/fair.c   2018-01-09 16:35:13.000000000 +0000
13632 +++ linux-4.4.110-vs2.3.9/kernel/sched/fair.c   2018-01-09 16:36:33.000000000 +0000
13633 @@ -30,6 +30,7 @@
13634  #include <linux/mempolicy.h>
13635  #include <linux/migrate.h>
13636  #include <linux/task_work.h>
13637 +#include <linux/vs_cvirt.h>
13638  
13639  #include <trace/events/sched.h>
13640  
13641 @@ -3055,6 +3056,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
13642                 __enqueue_entity(cfs_rq, se);
13643         se->on_rq = 1;
13644  
13645 +       if (entity_is_task(se))
13646 +               vx_activate_task(task_of(se));
13647         if (cfs_rq->nr_running == 1) {
13648                 list_add_leaf_cfs_rq(cfs_rq);
13649                 check_enqueue_throttle(cfs_rq);
13650 @@ -3136,6 +3139,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
13651         if (se != cfs_rq->curr)
13652                 __dequeue_entity(cfs_rq, se);
13653         se->on_rq = 0;
13654 +       if (entity_is_task(se))
13655 +               vx_deactivate_task(task_of(se));
13656         account_entity_dequeue(cfs_rq, se);
13657  
13658         /*
13659 diff -NurpP --minimal linux-4.4.110/kernel/signal.c linux-4.4.110-vs2.3.9/kernel/signal.c
13660 --- linux-4.4.110/kernel/signal.c       2018-01-09 16:35:13.000000000 +0000
13661 +++ linux-4.4.110-vs2.3.9/kernel/signal.c       2018-01-09 16:36:34.000000000 +0000
13662 @@ -34,6 +34,8 @@
13663  #include <linux/compat.h>
13664  #include <linux/cn_proc.h>
13665  #include <linux/compiler.h>
13666 +#include <linux/vs_context.h>
13667 +#include <linux/vs_pid.h>
13668  
13669  #define CREATE_TRACE_POINTS
13670  #include <trace/events/signal.h>
13671 @@ -724,9 +726,18 @@ static int check_kill_permission(int sig
13672         struct pid *sid;
13673         int error;
13674  
13675 +       vxdprintk(VXD_CBIT(misc, 7),
13676 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
13677 +               sig, info, t, vx_task_xid(t), t->pid);
13678 +
13679         if (!valid_signal(sig))
13680                 return -EINVAL;
13681  
13682 +/*     FIXME: needed? if so, why?
13683 +       if ((info != SEND_SIG_NOINFO) &&
13684 +               (is_si_special(info) || !si_fromuser(info)))
13685 +               goto skip;      */
13686 +
13687         if (!si_fromuser(info))
13688                 return 0;
13689  
13690 @@ -750,6 +761,20 @@ static int check_kill_permission(int sig
13691                 }
13692         }
13693  
13694 +       error = -EPERM;
13695 +       if (t->pid == 1 && current->xid)
13696 +               return error;
13697 +
13698 +       error = -ESRCH;
13699 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
13700 +                 loops, maybe ENOENT or EACCES? */
13701 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
13702 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
13703 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
13704 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
13705 +               return error;
13706 +       }
13707 +/* skip: */
13708         return security_task_kill(t, info, sig, 0);
13709  }
13710  
13711 @@ -1301,8 +1326,14 @@ int kill_pid_info(int sig, struct siginf
13712         for (;;) {
13713                 rcu_read_lock();
13714                 p = pid_task(pid, PIDTYPE_PID);
13715 -               if (p)
13716 -                       error = group_send_sig_info(sig, info, p);
13717 +               if (p) {
13718 +                       if (vx_check(vx_task_xid(p), VS_IDENT))
13719 +                               error = group_send_sig_info(sig, info, p);
13720 +                       else {
13721 +                               rcu_read_unlock();
13722 +                               return -ESRCH;
13723 +                       }
13724 +               }
13725                 rcu_read_unlock();
13726                 if (likely(!p || error != -ESRCH))
13727                         return error;
13728 @@ -1347,7 +1378,7 @@ int kill_pid_info_as_cred(int sig, struc
13729  
13730         rcu_read_lock();
13731         p = pid_task(pid, PIDTYPE_PID);
13732 -       if (!p) {
13733 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
13734                 ret = -ESRCH;
13735                 goto out_unlock;
13736         }
13737 @@ -1399,8 +1430,10 @@ static int kill_something_info(int sig,
13738                 struct task_struct * p;
13739  
13740                 for_each_process(p) {
13741 -                       if (task_pid_vnr(p) > 1 &&
13742 -                                       !same_thread_group(p, current)) {
13743 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
13744 +                               task_pid_vnr(p) > 1 &&
13745 +                               !same_thread_group(p, current) &&
13746 +                               !vx_current_initpid(p->pid)) {
13747                                 int err = group_send_sig_info(sig, info, p);
13748                                 ++count;
13749                                 if (err != -EPERM)
13750 @@ -2253,6 +2286,11 @@ relock:
13751                                 !sig_kernel_only(signr))
13752                         continue;
13753  
13754 +               /* virtual init is protected against user signals */
13755 +               if ((ksig->info.si_code == SI_USER) &&
13756 +                       vx_current_initpid(current->pid))
13757 +                       continue;
13758 +
13759                 if (sig_kernel_stop(signr)) {
13760                         /*
13761                          * The default action is to stop all threads in
13762 diff -NurpP --minimal linux-4.4.110/kernel/softirq.c linux-4.4.110-vs2.3.9/kernel/softirq.c
13763 --- linux-4.4.110/kernel/softirq.c      2015-04-12 22:12:50.000000000 +0000
13764 +++ linux-4.4.110-vs2.3.9/kernel/softirq.c      2018-01-09 16:36:34.000000000 +0000
13765 @@ -26,6 +26,7 @@
13766  #include <linux/smpboot.h>
13767  #include <linux/tick.h>
13768  #include <linux/irq.h>
13769 +#include <linux/vs_context.h>
13770  
13771  #define CREATE_TRACE_POINTS
13772  #include <trace/events/irq.h>
13773 diff -NurpP --minimal linux-4.4.110/kernel/sys.c linux-4.4.110-vs2.3.9/kernel/sys.c
13774 --- linux-4.4.110/kernel/sys.c  2018-01-09 16:35:13.000000000 +0000
13775 +++ linux-4.4.110-vs2.3.9/kernel/sys.c  2018-01-09 17:00:36.000000000 +0000
13776 @@ -54,6 +54,7 @@
13777  #include <linux/cred.h>
13778  
13779  #include <linux/kmsg_dump.h>
13780 +#include <linux/vs_pid.h>
13781  /* Move somewhere else to avoid recompiling? */
13782  #include <generated/utsrelease.h>
13783  
13784 @@ -157,7 +158,10 @@ static int set_one_prio(struct task_stru
13785                 goto out;
13786         }
13787         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
13788 -               error = -EACCES;
13789 +               if (vx_flags(VXF_IGNEG_NICE, 0))
13790 +                       error = 0;
13791 +               else
13792 +                       error = -EACCES;
13793                 goto out;
13794         }
13795         no_nice = security_task_setnice(p, niceval);
13796 @@ -208,6 +212,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
13797                 else
13798                         pgrp = task_pgrp(current);
13799                 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
13800 +                       if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
13801 +                               continue;
13802                         error = set_one_prio(p, niceval, error);
13803                 } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
13804                 break;
13805 @@ -274,6 +280,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
13806                 else
13807                         pgrp = task_pgrp(current);
13808                 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
13809 +                       if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
13810 +                               continue;
13811                         niceval = nice_to_rlimit(task_nice(p));
13812                         if (niceval > retval)
13813                                 retval = niceval;
13814 @@ -290,6 +298,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
13815                                 goto out_unlock;        /* No processes for this user */
13816                 }
13817                 do_each_thread(g, p) {
13818 +                       if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
13819 +                               continue;
13820                         if (uid_eq(task_uid(p), uid) && task_pid_vnr(p)) {
13821                                 niceval = nice_to_rlimit(task_nice(p));
13822                                 if (niceval > retval)
13823 @@ -1217,7 +1227,8 @@ SYSCALL_DEFINE2(sethostname, char __user
13824         int errno;
13825         char tmp[__NEW_UTS_LEN];
13826  
13827 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
13828 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
13829 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
13830                 return -EPERM;
13831  
13832         if (len < 0 || len > __NEW_UTS_LEN)
13833 @@ -1268,7 +1279,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
13834         int errno;
13835         char tmp[__NEW_UTS_LEN];
13836  
13837 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
13838 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
13839 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
13840                 return -EPERM;
13841         if (len < 0 || len > __NEW_UTS_LEN)
13842                 return -EINVAL;
13843 @@ -1386,7 +1398,7 @@ int do_prlimit(struct task_struct *tsk,
13844                 /* Keep the capable check against init_user_ns until
13845                    cgroups can contain all limits */
13846                 if (new_rlim->rlim_max > rlim->rlim_max &&
13847 -                               !capable(CAP_SYS_RESOURCE))
13848 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
13849                         retval = -EPERM;
13850                 if (!retval)
13851                         retval = security_task_setrlimit(tsk->group_leader,
13852 @@ -1439,7 +1451,8 @@ static int check_prlimit_permission(stru
13853             gid_eq(cred->gid, tcred->sgid) &&
13854             gid_eq(cred->gid, tcred->gid))
13855                 return 0;
13856 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
13857 +       if (vx_ns_capable(tcred->user_ns,
13858 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
13859                 return 0;
13860  
13861         return -EPERM;
13862 diff -NurpP --minimal linux-4.4.110/kernel/sysctl.c linux-4.4.110-vs2.3.9/kernel/sysctl.c
13863 --- linux-4.4.110/kernel/sysctl.c       2018-01-09 16:35:13.000000000 +0000
13864 +++ linux-4.4.110-vs2.3.9/kernel/sysctl.c       2018-01-09 16:36:34.000000000 +0000
13865 @@ -87,6 +87,7 @@
13866  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
13867  #include <linux/lockdep.h>
13868  #endif
13869 +extern char vshelper_path[];
13870  #ifdef CONFIG_CHR_DEV_SG
13871  #include <scsi/sg.h>
13872  #endif
13873 @@ -279,6 +280,13 @@ static int max_extfrag_threshold = 1000;
13874  
13875  static struct ctl_table kern_table[] = {
13876         {
13877 +               .procname       = "vshelper",
13878 +               .data           = &vshelper_path,
13879 +               .maxlen         = 256,
13880 +               .mode           = 0644,
13881 +               .proc_handler   = proc_dostring,
13882 +       },
13883 +       {
13884                 .procname       = "sched_child_runs_first",
13885                 .data           = &sysctl_sched_child_runs_first,
13886                 .maxlen         = sizeof(unsigned int),
13887 @@ -1385,7 +1393,6 @@ static struct ctl_table vm_table[] = {
13888                 .extra1         = &zero,
13889                 .extra2         = &one,
13890         },
13891 -
13892  #endif /* CONFIG_COMPACTION */
13893         {
13894                 .procname       = "min_free_kbytes",
13895 diff -NurpP --minimal linux-4.4.110/kernel/sysctl_binary.c linux-4.4.110-vs2.3.9/kernel/sysctl_binary.c
13896 --- linux-4.4.110/kernel/sysctl_binary.c        2018-01-09 16:35:13.000000000 +0000
13897 +++ linux-4.4.110-vs2.3.9/kernel/sysctl_binary.c        2018-01-09 16:36:34.000000000 +0000
13898 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
13899  
13900         { CTL_INT,      KERN_PANIC,                     "panic" },
13901         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
13902 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
13903  
13904         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
13905         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
13906 diff -NurpP --minimal linux-4.4.110/kernel/time/posix-timers.c linux-4.4.110-vs2.3.9/kernel/time/posix-timers.c
13907 --- linux-4.4.110/kernel/time/posix-timers.c    2018-01-09 16:35:13.000000000 +0000
13908 +++ linux-4.4.110-vs2.3.9/kernel/time/posix-timers.c    2018-01-09 16:36:34.000000000 +0000
13909 @@ -48,6 +48,7 @@
13910  #include <linux/workqueue.h>
13911  #include <linux/export.h>
13912  #include <linux/hashtable.h>
13913 +#include <linux/vs_context.h>
13914  
13915  #include "timekeeping.h"
13916  
13917 @@ -407,6 +408,7 @@ int posix_timer_event(struct k_itimer *t
13918  {
13919         struct task_struct *task;
13920         int shared, ret = -1;
13921 +
13922         /*
13923          * FIXME: if ->sigq is queued we can race with
13924          * dequeue_signal()->do_schedule_next_timer().
13925 @@ -423,10 +425,18 @@ int posix_timer_event(struct k_itimer *t
13926         rcu_read_lock();
13927         task = pid_task(timr->it_pid, PIDTYPE_PID);
13928         if (task) {
13929 +               struct vx_info_save vxis;
13930 +               struct vx_info *vxi;
13931 +
13932 +               vxi = get_vx_info(task->vx_info);
13933 +               enter_vx_info(vxi, &vxis);
13934                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
13935                 ret = send_sigqueue(timr->sigq, task, shared);
13936 +               leave_vx_info(&vxis);
13937 +               put_vx_info(vxi);
13938         }
13939         rcu_read_unlock();
13940 +
13941         /* If we failed to send the signal the timer stops. */
13942         return ret > 0;
13943  }
13944 diff -NurpP --minimal linux-4.4.110/kernel/time/time.c linux-4.4.110-vs2.3.9/kernel/time/time.c
13945 --- linux-4.4.110/kernel/time/time.c    2016-07-05 04:12:39.000000000 +0000
13946 +++ linux-4.4.110-vs2.3.9/kernel/time/time.c    2018-01-09 16:36:34.000000000 +0000
13947 @@ -37,6 +37,7 @@
13948  #include <linux/fs.h>
13949  #include <linux/math64.h>
13950  #include <linux/ptrace.h>
13951 +#include <linux/vs_time.h>
13952  
13953  #include <asm/uaccess.h>
13954  #include <asm/unistd.h>
13955 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
13956         if (err)
13957                 return err;
13958  
13959 -       do_settimeofday(&tv);
13960 +       vx_settimeofday(&tv);
13961         return 0;
13962  }
13963  
13964 @@ -186,7 +187,7 @@ int do_sys_settimeofday(const struct tim
13965                 }
13966         }
13967         if (tv)
13968 -               return do_settimeofday(tv);
13969 +               return vx_settimeofday(tv);
13970         return 0;
13971  }
13972  
13973 diff -NurpP --minimal linux-4.4.110/kernel/time/timekeeping.c linux-4.4.110-vs2.3.9/kernel/time/timekeeping.c
13974 --- linux-4.4.110/kernel/time/timekeeping.c     2018-01-09 16:35:13.000000000 +0000
13975 +++ linux-4.4.110-vs2.3.9/kernel/time/timekeeping.c     2018-01-09 17:02:47.000000000 +0000
13976 @@ -23,6 +23,7 @@
13977  #include <linux/stop_machine.h>
13978  #include <linux/pvclock_gtod.h>
13979  #include <linux/compiler.h>
13980 +#include <linux/vs_time.h>
13981  
13982  #include "tick-internal.h"
13983  #include "ntp_internal.h"
13984 @@ -921,7 +922,9 @@ void ktime_get_raw_and_real_ts64(struct
13985         } while (read_seqcount_retry(&tk_core.seq, seq));
13986  
13987         timespec64_add_ns(ts_raw, nsecs_raw);
13988 +       vx_adjust_timespec(ts_raw);
13989         timespec64_add_ns(ts_real, nsecs_real);
13990 +       vx_adjust_timespec(ts_real);
13991  }
13992  EXPORT_SYMBOL(ktime_get_raw_and_real_ts64);
13993  
13994 diff -NurpP --minimal linux-4.4.110/kernel/time/timer.c linux-4.4.110-vs2.3.9/kernel/time/timer.c
13995 --- linux-4.4.110/kernel/time/timer.c   2018-01-09 16:35:13.000000000 +0000
13996 +++ linux-4.4.110-vs2.3.9/kernel/time/timer.c   2018-01-09 16:36:34.000000000 +0000
13997 @@ -42,6 +42,10 @@
13998  #include <linux/sched/sysctl.h>
13999  #include <linux/slab.h>
14000  #include <linux/compat.h>
14001 +#include <linux/vs_base.h>
14002 +#include <linux/vs_cvirt.h>
14003 +#include <linux/vs_pid.h>
14004 +#include <linux/vserver/sched.h>
14005  
14006  #include <asm/uaccess.h>
14007  #include <asm/unistd.h>
14008 diff -NurpP --minimal linux-4.4.110/kernel/user_namespace.c linux-4.4.110-vs2.3.9/kernel/user_namespace.c
14009 --- linux-4.4.110/kernel/user_namespace.c       2016-07-05 04:12:39.000000000 +0000
14010 +++ linux-4.4.110-vs2.3.9/kernel/user_namespace.c       2018-01-09 16:36:34.000000000 +0000
14011 @@ -22,6 +22,7 @@
14012  #include <linux/ctype.h>
14013  #include <linux/projid.h>
14014  #include <linux/fs_struct.h>
14015 +#include <linux/vserver/global.h>
14016  
14017  static struct kmem_cache *user_ns_cachep __read_mostly;
14018  static DEFINE_MUTEX(userns_state_mutex);
14019 @@ -97,6 +98,7 @@ int create_user_ns(struct cred *new)
14020  
14021         atomic_set(&ns->count, 1);
14022         /* Leave the new->user_ns reference with the new user namespace. */
14023 +       atomic_inc(&vs_global_user_ns);
14024         ns->parent = parent_ns;
14025         ns->level = parent_ns->level + 1;
14026         ns->owner = owner;
14027 @@ -145,6 +147,7 @@ void free_user_ns(struct user_namespace
14028                 key_put(ns->persistent_keyring_register);
14029  #endif
14030                 ns_free_inum(&ns->ns);
14031 +               atomic_dec(&vs_global_user_ns);
14032                 kmem_cache_free(user_ns_cachep, ns);
14033                 ns = parent;
14034         } while (atomic_dec_and_test(&parent->count));
14035 @@ -358,6 +361,18 @@ gid_t from_kgid_munged(struct user_names
14036  }
14037  EXPORT_SYMBOL(from_kgid_munged);
14038  
14039 +ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
14040 +{
14041 +       return KTAGT_INIT(tag);
14042 +}
14043 +EXPORT_SYMBOL(make_ktag);
14044 +
14045 +vtag_t from_ktag(struct user_namespace *to, ktag_t tag)
14046 +{
14047 +       return __ktag_val(tag);
14048 +}
14049 +EXPORT_SYMBOL(from_ktag);
14050 +
14051  /**
14052   *     make_kprojid - Map a user-namespace projid pair into a kprojid.
14053   *     @ns:  User namespace that the projid is in
14054 diff -NurpP --minimal linux-4.4.110/kernel/utsname.c linux-4.4.110-vs2.3.9/kernel/utsname.c
14055 --- linux-4.4.110/kernel/utsname.c      2015-04-12 22:12:50.000000000 +0000
14056 +++ linux-4.4.110-vs2.3.9/kernel/utsname.c      2018-01-09 16:36:34.000000000 +0000
14057 @@ -16,14 +16,17 @@
14058  #include <linux/slab.h>
14059  #include <linux/user_namespace.h>
14060  #include <linux/proc_ns.h>
14061 +#include <linux/vserver/global.h>
14062  
14063  static struct uts_namespace *create_uts_ns(void)
14064  {
14065         struct uts_namespace *uts_ns;
14066  
14067         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
14068 -       if (uts_ns)
14069 +       if (uts_ns) {
14070                 kref_init(&uts_ns->kref);
14071 +               atomic_inc(&vs_global_uts_ns);
14072 +       }
14073         return uts_ns;
14074  }
14075  
14076 @@ -87,6 +90,7 @@ void free_uts_ns(struct kref *kref)
14077         ns = container_of(kref, struct uts_namespace, kref);
14078         put_user_ns(ns->user_ns);
14079         ns_free_inum(&ns->ns);
14080 +       atomic_dec(&vs_global_uts_ns);
14081         kfree(ns);
14082  }
14083  
14084 diff -NurpP --minimal linux-4.4.110/kernel/vserver/Kconfig linux-4.4.110-vs2.3.9/kernel/vserver/Kconfig
14085 --- linux-4.4.110/kernel/vserver/Kconfig        1970-01-01 00:00:00.000000000 +0000
14086 +++ linux-4.4.110-vs2.3.9/kernel/vserver/Kconfig        2018-01-09 16:36:34.000000000 +0000
14087 @@ -0,0 +1,230 @@
14088 +#
14089 +# Linux VServer configuration
14090 +#
14091 +
14092 +menu "Linux VServer"
14093 +
14094 +config VSERVER_AUTO_LBACK
14095 +       bool    "Automatically Assign Loopback IP"
14096 +       default y
14097 +       help
14098 +         Automatically assign a guest specific loopback
14099 +         IP and add it to the kernel network stack on
14100 +         startup.
14101 +
14102 +config VSERVER_AUTO_SINGLE
14103 +       bool    "Automatic Single IP Special Casing"
14104 +       default n
14105 +       help
14106 +         This allows network contexts with a single IP to
14107 +         automatically remap 0.0.0.0 bindings to that IP,
14108 +         avoiding further network checks and improving
14109 +         performance.
14110 +
14111 +         (note: such guests do not allow to change the ip
14112 +          on the fly and do not show loopback addresses)
14113 +
14114 +config VSERVER_COWBL
14115 +       bool    "Enable COW Immutable Link Breaking"
14116 +       default y
14117 +       help
14118 +         This enables the COW (Copy-On-Write) link break code.
14119 +         It allows you to treat unified files like normal files
14120 +         when writing to them (which will implicitely break the
14121 +         link and create a copy of the unified file)
14122 +
14123 +config VSERVER_VTIME
14124 +       bool    "Enable Virtualized Guest Time (EXPERIMENTAL)"
14125 +       default n
14126 +       help
14127 +         This enables per guest time offsets to allow for
14128 +         adjusting the system clock individually per guest.
14129 +         this adds some overhead to the time functions and
14130 +         therefore should not be enabled without good reason.
14131 +
14132 +config VSERVER_DEVICE
14133 +       bool    "Enable Guest Device Mapping (EXPERIMENTAL)"
14134 +       default n
14135 +       help
14136 +         This enables generic device remapping.
14137 +
14138 +config VSERVER_PROC_SECURE
14139 +       bool    "Enable Proc Security"
14140 +       depends on PROC_FS
14141 +       default y
14142 +       help
14143 +         This configures ProcFS security to initially hide
14144 +         non-process entries for all contexts except the main and
14145 +         spectator context (i.e. for all guests), which is a secure
14146 +         default.
14147 +
14148 +         (note: on 1.2x the entries were visible by default)
14149 +
14150 +choice
14151 +       prompt  "Persistent Inode Tagging"
14152 +       default TAGGING_ID24
14153 +       help
14154 +         This adds persistent context information to filesystems
14155 +         mounted with the tagxid option. Tagging is a requirement
14156 +         for per-context disk limits and per-context quota.
14157 +
14158 +
14159 +config TAGGING_NONE
14160 +       bool    "Disabled"
14161 +       help
14162 +         do not store per-context information in inodes.
14163 +
14164 +config TAGGING_UID16
14165 +       bool    "UID16/GID32"
14166 +       help
14167 +         reduces UID to 16 bit, but leaves GID at 32 bit.
14168 +
14169 +config TAGGING_GID16
14170 +       bool    "UID32/GID16"
14171 +       help
14172 +         reduces GID to 16 bit, but leaves UID at 32 bit.
14173 +
14174 +config TAGGING_ID24
14175 +       bool    "UID24/GID24"
14176 +       help
14177 +         uses the upper 8bit from UID and GID for XID tagging
14178 +         which leaves 24bit for UID/GID each, which should be
14179 +         more than sufficient for normal use.
14180 +
14181 +config TAGGING_INTERN
14182 +       bool    "UID32/GID32"
14183 +       help
14184 +         this uses otherwise reserved inode fields in the on
14185 +         disk representation, which limits the use to a few
14186 +         filesystems (currently ext2 and ext3)
14187 +
14188 +endchoice
14189 +
14190 +config TAG_NFSD
14191 +       bool    "Tag NFSD User Auth and Files"
14192 +       default n
14193 +       help
14194 +         Enable this if you do want the in-kernel NFS
14195 +         Server to use the tagging specified above.
14196 +         (will require patched clients too)
14197 +
14198 +config VSERVER_PRIVACY
14199 +       bool    "Honor Privacy Aspects of Guests"
14200 +       default n
14201 +       help
14202 +         When enabled, most context checks will disallow
14203 +         access to structures assigned to a specific context,
14204 +         like ptys or loop devices.
14205 +
14206 +config VSERVER_CONTEXTS
14207 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
14208 +       range 1 65533
14209 +       default "768"   if 64BIT
14210 +       default "256"
14211 +       help
14212 +         This setting will optimize certain data structures
14213 +         and memory allocations according to the expected
14214 +         maximum.
14215 +
14216 +         note: this is not a strict upper limit.
14217 +
14218 +config VSERVER_WARN
14219 +       bool    "VServer Warnings"
14220 +       default y
14221 +       help
14222 +         This enables various runtime warnings, which will
14223 +         notify about potential manipulation attempts or
14224 +         resource shortage. It is generally considered to
14225 +         be a good idea to have that enabled.
14226 +
14227 +config VSERVER_WARN_DEVPTS
14228 +       bool    "VServer DevPTS Warnings"
14229 +       depends on VSERVER_WARN
14230 +       default y
14231 +       help
14232 +         This enables DevPTS related warnings, issued when a
14233 +         process inside a context tries to lookup or access
14234 +         a dynamic pts from the host or a different context.
14235 +
14236 +config VSERVER_DEBUG
14237 +       bool    "VServer Debugging Code"
14238 +       default n
14239 +       help
14240 +         Set this to yes if you want to be able to activate
14241 +         debugging output at runtime. It adds a very small
14242 +         overhead to all vserver related functions and
14243 +         increases the kernel size by about 20k.
14244 +
14245 +config VSERVER_HISTORY
14246 +       bool    "VServer History Tracing"
14247 +       depends on VSERVER_DEBUG
14248 +       default n
14249 +       help
14250 +         Set this to yes if you want to record the history of
14251 +         linux-vserver activities, so they can be replayed in
14252 +         the event of a kernel panic or oops.
14253 +
14254 +config VSERVER_HISTORY_SIZE
14255 +       int     "Per-CPU History Size (32-65536)"
14256 +       depends on VSERVER_HISTORY
14257 +       range 32 65536
14258 +       default 64
14259 +       help
14260 +         This allows you to specify the number of entries in
14261 +         the per-CPU history buffer.
14262 +
14263 +config VSERVER_EXTRA_MNT_CHECK
14264 +       bool    "Extra Checks for Reachability"
14265 +       default n
14266 +       help
14267 +         Set this to yes if you want to do extra checks for
14268 +         vfsmount reachability in the proc filesystem code.
14269 +         This shouldn't be required on any setup utilizing
14270 +         mnt namespaces.
14271 +
14272 +choice
14273 +       prompt  "Quotes used in debug and warn messages"
14274 +       default QUOTES_ISO8859
14275 +
14276 +config QUOTES_ISO8859
14277 +       bool    "Extended ASCII (ISO 8859) angle quotes"
14278 +       help
14279 +         This uses the extended ASCII characters \xbb
14280 +         and \xab for quoting file and process names.
14281 +
14282 +config QUOTES_UTF8
14283 +       bool    "UTF-8 angle quotes"
14284 +       help
14285 +         This uses the the UTF-8 sequences for angle
14286 +         quotes to quote file and process names.
14287 +
14288 +config QUOTES_ASCII
14289 +       bool    "ASCII single quotes"
14290 +       help
14291 +         This uses the ASCII single quote character
14292 +         (\x27) to quote file and process names.
14293 +
14294 +endchoice
14295 +
14296 +endmenu
14297 +
14298 +
14299 +config VSERVER
14300 +       bool
14301 +       default y
14302 +       select NAMESPACES
14303 +       select UTS_NS
14304 +       select IPC_NS
14305 +#      select USER_NS
14306 +       select SYSVIPC
14307 +
14308 +config VSERVER_SECURITY
14309 +       bool
14310 +       depends on SECURITY
14311 +       default y
14312 +       select SECURITY_CAPABILITIES
14313 +
14314 +config VSERVER_DISABLED
14315 +       bool
14316 +       default n
14317 +
14318 diff -NurpP --minimal linux-4.4.110/kernel/vserver/Makefile linux-4.4.110-vs2.3.9/kernel/vserver/Makefile
14319 --- linux-4.4.110/kernel/vserver/Makefile       1970-01-01 00:00:00.000000000 +0000
14320 +++ linux-4.4.110-vs2.3.9/kernel/vserver/Makefile       2018-01-09 16:36:34.000000000 +0000
14321 @@ -0,0 +1,18 @@
14322 +#
14323 +# Makefile for the Linux vserver routines.
14324 +#
14325 +
14326 +
14327 +obj-y          += vserver.o
14328 +
14329 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
14330 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
14331 +                  dlimit.o tag.o
14332 +
14333 +vserver-$(CONFIG_INET) += inet.o
14334 +vserver-$(CONFIG_PROC_FS) += proc.o
14335 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
14336 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
14337 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
14338 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
14339 +
14340 diff -NurpP --minimal linux-4.4.110/kernel/vserver/cacct.c linux-4.4.110-vs2.3.9/kernel/vserver/cacct.c
14341 --- linux-4.4.110/kernel/vserver/cacct.c        1970-01-01 00:00:00.000000000 +0000
14342 +++ linux-4.4.110-vs2.3.9/kernel/vserver/cacct.c        2018-01-09 16:36:34.000000000 +0000
14343 @@ -0,0 +1,42 @@
14344 +/*
14345 + *  linux/kernel/vserver/cacct.c
14346 + *
14347 + *  Virtual Server: Context Accounting
14348 + *
14349 + *  Copyright (C) 2006-2007 Herbert P?tzl
14350 + *
14351 + *  V0.01  added accounting stats
14352 + *
14353 + */
14354 +
14355 +#include <linux/types.h>
14356 +#include <linux/vs_context.h>
14357 +#include <linux/vserver/cacct_cmd.h>
14358 +#include <linux/vserver/cacct_int.h>
14359 +
14360 +#include <asm/errno.h>
14361 +#include <asm/uaccess.h>
14362 +
14363 +
14364 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
14365 +{
14366 +       struct vcmd_sock_stat_v0 vc_data;
14367 +       int j, field;
14368 +
14369 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
14370 +               return -EFAULT;
14371 +
14372 +       field = vc_data.field;
14373 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
14374 +               return -EINVAL;
14375 +
14376 +       for (j = 0; j < 3; j++) {
14377 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
14378 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
14379 +       }
14380 +
14381 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
14382 +               return -EFAULT;
14383 +       return 0;
14384 +}
14385 +
14386 diff -NurpP --minimal linux-4.4.110/kernel/vserver/cacct_init.h linux-4.4.110-vs2.3.9/kernel/vserver/cacct_init.h
14387 --- linux-4.4.110/kernel/vserver/cacct_init.h   1970-01-01 00:00:00.000000000 +0000
14388 +++ linux-4.4.110-vs2.3.9/kernel/vserver/cacct_init.h   2018-01-09 16:36:34.000000000 +0000
14389 @@ -0,0 +1,25 @@
14390 +
14391 +
14392 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
14393 +{
14394 +       int i, j;
14395 +
14396 +
14397 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14398 +               for (j = 0; j < 3; j++) {
14399 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
14400 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
14401 +               }
14402 +       }
14403 +       for (i = 0; i < 8; i++)
14404 +               atomic_set(&cacct->slab[i], 0);
14405 +       for (i = 0; i < 5; i++)
14406 +               for (j = 0; j < 4; j++)
14407 +                       atomic_set(&cacct->page[i][j], 0);
14408 +}
14409 +
14410 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
14411 +{
14412 +       return;
14413 +}
14414 +
14415 diff -NurpP --minimal linux-4.4.110/kernel/vserver/cacct_proc.h linux-4.4.110-vs2.3.9/kernel/vserver/cacct_proc.h
14416 --- linux-4.4.110/kernel/vserver/cacct_proc.h   1970-01-01 00:00:00.000000000 +0000
14417 +++ linux-4.4.110-vs2.3.9/kernel/vserver/cacct_proc.h   2018-01-09 16:36:34.000000000 +0000
14418 @@ -0,0 +1,53 @@
14419 +#ifndef _VX_CACCT_PROC_H
14420 +#define _VX_CACCT_PROC_H
14421 +
14422 +#include <linux/vserver/cacct_int.h>
14423 +
14424 +
14425 +#define VX_SOCKA_TOP   \
14426 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
14427 +
14428 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
14429 +{
14430 +       int i, j, length = 0;
14431 +       static char *type[VXA_SOCK_SIZE] = {
14432 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
14433 +       };
14434 +
14435 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
14436 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14437 +               length += sprintf(buffer + length, "%s:", type[i]);
14438 +               for (j = 0; j < 3; j++) {
14439 +                       length += sprintf(buffer + length,
14440 +                               "\t%10lu/%-10lu",
14441 +                               vx_sock_count(cacct, i, j),
14442 +                               vx_sock_total(cacct, i, j));
14443 +               }
14444 +               buffer[length++] = '\n';
14445 +       }
14446 +
14447 +       length += sprintf(buffer + length, "\n");
14448 +       length += sprintf(buffer + length,
14449 +               "slab:\t %8u %8u %8u %8u\n",
14450 +               atomic_read(&cacct->slab[1]),
14451 +               atomic_read(&cacct->slab[4]),
14452 +               atomic_read(&cacct->slab[0]),
14453 +               atomic_read(&cacct->slab[2]));
14454 +
14455 +       length += sprintf(buffer + length, "\n");
14456 +       for (i = 0; i < 5; i++) {
14457 +               length += sprintf(buffer + length,
14458 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
14459 +                       atomic_read(&cacct->page[i][0]),
14460 +                       atomic_read(&cacct->page[i][1]),
14461 +                       atomic_read(&cacct->page[i][2]),
14462 +                       atomic_read(&cacct->page[i][3]),
14463 +                       atomic_read(&cacct->page[i][4]),
14464 +                       atomic_read(&cacct->page[i][5]),
14465 +                       atomic_read(&cacct->page[i][6]),
14466 +                       atomic_read(&cacct->page[i][7]));
14467 +       }
14468 +       return length;
14469 +}
14470 +
14471 +#endif /* _VX_CACCT_PROC_H */
14472 diff -NurpP --minimal linux-4.4.110/kernel/vserver/context.c linux-4.4.110-vs2.3.9/kernel/vserver/context.c
14473 --- linux-4.4.110/kernel/vserver/context.c      1970-01-01 00:00:00.000000000 +0000
14474 +++ linux-4.4.110-vs2.3.9/kernel/vserver/context.c      2018-01-09 16:36:34.000000000 +0000
14475 @@ -0,0 +1,1119 @@
14476 +/*
14477 + *  linux/kernel/vserver/context.c
14478 + *
14479 + *  Virtual Server: Context Support
14480 + *
14481 + *  Copyright (C) 2003-2011  Herbert P?tzl
14482 + *
14483 + *  V0.01  context helper
14484 + *  V0.02  vx_ctx_kill syscall command
14485 + *  V0.03  replaced context_info calls
14486 + *  V0.04  redesign of struct (de)alloc
14487 + *  V0.05  rlimit basic implementation
14488 + *  V0.06  task_xid and info commands
14489 + *  V0.07  context flags and caps
14490 + *  V0.08  switch to RCU based hash
14491 + *  V0.09  revert to non RCU for now
14492 + *  V0.10  and back to working RCU hash
14493 + *  V0.11  and back to locking again
14494 + *  V0.12  referenced context store
14495 + *  V0.13  separate per cpu data
14496 + *  V0.14  changed vcmds to vxi arg
14497 + *  V0.15  added context stat
14498 + *  V0.16  have __create claim() the vxi
14499 + *  V0.17  removed older and legacy stuff
14500 + *  V0.18  added user credentials
14501 + *  V0.19  added warn mask
14502 + *
14503 + */
14504 +
14505 +#include <linux/slab.h>
14506 +#include <linux/types.h>
14507 +#include <linux/security.h>
14508 +#include <linux/pid_namespace.h>
14509 +#include <linux/capability.h>
14510 +
14511 +#include <linux/vserver/context.h>
14512 +#include <linux/vserver/network.h>
14513 +#include <linux/vserver/debug.h>
14514 +#include <linux/vserver/limit.h>
14515 +#include <linux/vserver/limit_int.h>
14516 +#include <linux/vserver/space.h>
14517 +#include <linux/init_task.h>
14518 +#include <linux/fs_struct.h>
14519 +#include <linux/cred.h>
14520 +
14521 +#include <linux/vs_context.h>
14522 +#include <linux/vs_limit.h>
14523 +#include <linux/vs_pid.h>
14524 +#include <linux/vserver/context_cmd.h>
14525 +
14526 +#include "cvirt_init.h"
14527 +#include "cacct_init.h"
14528 +#include "limit_init.h"
14529 +#include "sched_init.h"
14530 +
14531 +
14532 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
14533 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
14534 +
14535 +
14536 +/*     now inactive context structures */
14537 +
14538 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
14539 +
14540 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
14541 +
14542 +
14543 +/*     __alloc_vx_info()
14544 +
14545 +       * allocate an initialized vx_info struct
14546 +       * doesn't make it visible (hash)                        */
14547 +
14548 +static struct vx_info *__alloc_vx_info(vxid_t xid)
14549 +{
14550 +       struct vx_info *new = NULL;
14551 +       int cpu, index;
14552 +
14553 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
14554 +
14555 +       /* would this benefit from a slab cache? */
14556 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
14557 +       if (!new)
14558 +               return 0;
14559 +
14560 +       memset(new, 0, sizeof(struct vx_info));
14561 +#ifdef CONFIG_SMP
14562 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
14563 +       if (!new->ptr_pc)
14564 +               goto error;
14565 +#endif
14566 +       new->vx_id = xid;
14567 +       INIT_HLIST_NODE(&new->vx_hlist);
14568 +       atomic_set(&new->vx_usecnt, 0);
14569 +       atomic_set(&new->vx_tasks, 0);
14570 +       new->vx_parent = NULL;
14571 +       new->vx_state = 0;
14572 +       init_waitqueue_head(&new->vx_wait);
14573 +
14574 +       /* prepare reaper */
14575 +       get_task_struct(init_pid_ns.child_reaper);
14576 +       new->vx_reaper = init_pid_ns.child_reaper;
14577 +       new->vx_badness_bias = 0;
14578 +
14579 +       /* rest of init goes here */
14580 +       vx_info_init_limit(&new->limit);
14581 +       vx_info_init_sched(&new->sched);
14582 +       vx_info_init_cvirt(&new->cvirt);
14583 +       vx_info_init_cacct(&new->cacct);
14584 +
14585 +       /* per cpu data structures */
14586 +       for_each_possible_cpu(cpu) {
14587 +               vx_info_init_sched_pc(
14588 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
14589 +               vx_info_init_cvirt_pc(
14590 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
14591 +       }
14592 +
14593 +       new->vx_flags = VXF_INIT_SET;
14594 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
14595 +       new->vx_ccaps = 0;
14596 +       new->vx_umask = 0;
14597 +       new->vx_wmask = 0;
14598 +
14599 +       new->reboot_cmd = 0;
14600 +       new->exit_code = 0;
14601 +
14602 +       // preconfig spaces
14603 +       for (index = 0; index < VX_SPACES; index++) {
14604 +               struct _vx_space *space = &new->space[index];
14605 +
14606 +               // filesystem
14607 +               spin_lock(&init_fs.lock);
14608 +               init_fs.users++;
14609 +               spin_unlock(&init_fs.lock);
14610 +               space->vx_fs = &init_fs;
14611 +
14612 +               /* FIXME: do we want defaults? */
14613 +               // space->vx_real_cred = 0;
14614 +               // space->vx_cred = 0;
14615 +       }
14616 +
14617 +
14618 +       vxdprintk(VXD_CBIT(xid, 0),
14619 +               "alloc_vx_info(%d) = %p", xid, new);
14620 +       vxh_alloc_vx_info(new);
14621 +       atomic_inc(&vx_global_ctotal);
14622 +       return new;
14623 +#ifdef CONFIG_SMP
14624 +error:
14625 +       kfree(new);
14626 +       return 0;
14627 +#endif
14628 +}
14629 +
14630 +/*     __dealloc_vx_info()
14631 +
14632 +       * final disposal of vx_info                             */
14633 +
14634 +static void __dealloc_vx_info(struct vx_info *vxi)
14635 +{
14636 +#ifdef CONFIG_VSERVER_WARN
14637 +       struct vx_info_save vxis;
14638 +       int cpu;
14639 +#endif
14640 +       vxdprintk(VXD_CBIT(xid, 0),
14641 +               "dealloc_vx_info(%p)", vxi);
14642 +       vxh_dealloc_vx_info(vxi);
14643 +
14644 +#ifdef CONFIG_VSERVER_WARN
14645 +       enter_vx_info(vxi, &vxis);
14646 +       vx_info_exit_limit(&vxi->limit);
14647 +       vx_info_exit_sched(&vxi->sched);
14648 +       vx_info_exit_cvirt(&vxi->cvirt);
14649 +       vx_info_exit_cacct(&vxi->cacct);
14650 +
14651 +       for_each_possible_cpu(cpu) {
14652 +               vx_info_exit_sched_pc(
14653 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
14654 +               vx_info_exit_cvirt_pc(
14655 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
14656 +       }
14657 +       leave_vx_info(&vxis);
14658 +#endif
14659 +
14660 +       vxi->vx_id = -1;
14661 +       vxi->vx_state |= VXS_RELEASED;
14662 +
14663 +#ifdef CONFIG_SMP
14664 +       free_percpu(vxi->ptr_pc);
14665 +#endif
14666 +       kfree(vxi);
14667 +       atomic_dec(&vx_global_ctotal);
14668 +}
14669 +
14670 +static void __shutdown_vx_info(struct vx_info *vxi)
14671 +{
14672 +       struct nsproxy *nsproxy;
14673 +       struct fs_struct *fs;
14674 +       struct cred *cred;
14675 +       int index, kill;
14676 +
14677 +       might_sleep();
14678 +
14679 +       vxi->vx_state |= VXS_SHUTDOWN;
14680 +       vs_state_change(vxi, VSC_SHUTDOWN);
14681 +
14682 +       for (index = 0; index < VX_SPACES; index++) {
14683 +               struct _vx_space *space = &vxi->space[index];
14684 +
14685 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
14686 +               if (nsproxy)
14687 +                       put_nsproxy(nsproxy);
14688 +
14689 +               fs = xchg(&space->vx_fs, NULL);
14690 +               spin_lock(&fs->lock);
14691 +               kill = !--fs->users;
14692 +               spin_unlock(&fs->lock);
14693 +               if (kill)
14694 +                       free_fs_struct(fs);
14695 +
14696 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
14697 +               if (cred)
14698 +                       abort_creds(cred);
14699 +       }
14700 +}
14701 +
14702 +/* exported stuff */
14703 +
14704 +void free_vx_info(struct vx_info *vxi)
14705 +{
14706 +       unsigned long flags;
14707 +       unsigned index;
14708 +
14709 +       /* check for reference counts first */
14710 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
14711 +       BUG_ON(atomic_read(&vxi->vx_tasks));
14712 +
14713 +       /* context must not be hashed */
14714 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
14715 +
14716 +       /* context shutdown is mandatory */
14717 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
14718 +
14719 +       /* spaces check */
14720 +       for (index = 0; index < VX_SPACES; index++) {
14721 +               struct _vx_space *space = &vxi->space[index];
14722 +
14723 +               BUG_ON(space->vx_nsproxy);
14724 +               BUG_ON(space->vx_fs);
14725 +               // BUG_ON(space->vx_real_cred);
14726 +               // BUG_ON(space->vx_cred);
14727 +       }
14728 +
14729 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
14730 +       hlist_del(&vxi->vx_hlist);
14731 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
14732 +
14733 +       __dealloc_vx_info(vxi);
14734 +}
14735 +
14736 +
14737 +/*     hash table for vx_info hash */
14738 +
14739 +#define VX_HASH_SIZE   13
14740 +
14741 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
14742 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
14743 +
14744 +static DEFINE_SPINLOCK(vx_info_hash_lock);
14745 +
14746 +
14747 +static inline unsigned int __hashval(vxid_t xid)
14748 +{
14749 +       return (xid % VX_HASH_SIZE);
14750 +}
14751 +
14752 +
14753 +
14754 +/*     __hash_vx_info()
14755 +
14756 +       * add the vxi to the global hash table
14757 +       * requires the hash_lock to be held                     */
14758 +
14759 +static inline void __hash_vx_info(struct vx_info *vxi)
14760 +{
14761 +       struct hlist_head *head;
14762 +
14763 +       vxd_assert_lock(&vx_info_hash_lock);
14764 +       vxdprintk(VXD_CBIT(xid, 4),
14765 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
14766 +       vxh_hash_vx_info(vxi);
14767 +
14768 +       /* context must not be hashed */
14769 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
14770 +
14771 +       vxi->vx_state |= VXS_HASHED;
14772 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
14773 +       hlist_add_head(&vxi->vx_hlist, head);
14774 +       atomic_inc(&vx_global_cactive);
14775 +}
14776 +
14777 +/*     __unhash_vx_info()
14778 +
14779 +       * remove the vxi from the global hash table
14780 +       * requires the hash_lock to be held                     */
14781 +
14782 +static inline void __unhash_vx_info(struct vx_info *vxi)
14783 +{
14784 +       unsigned long flags;
14785 +
14786 +       vxd_assert_lock(&vx_info_hash_lock);
14787 +       vxdprintk(VXD_CBIT(xid, 4),
14788 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
14789 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
14790 +       vxh_unhash_vx_info(vxi);
14791 +
14792 +       /* context must be hashed */
14793 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
14794 +       /* but without tasks */
14795 +       BUG_ON(atomic_read(&vxi->vx_tasks));
14796 +
14797 +       vxi->vx_state &= ~VXS_HASHED;
14798 +       hlist_del_init(&vxi->vx_hlist);
14799 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
14800 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
14801 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
14802 +       atomic_dec(&vx_global_cactive);
14803 +}
14804 +
14805 +
14806 +/*     __lookup_vx_info()
14807 +
14808 +       * requires the hash_lock to be held
14809 +       * doesn't increment the vx_refcnt                       */
14810 +
14811 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
14812 +{
14813 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
14814 +       struct hlist_node *pos;
14815 +       struct vx_info *vxi;
14816 +
14817 +       vxd_assert_lock(&vx_info_hash_lock);
14818 +       hlist_for_each(pos, head) {
14819 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
14820 +
14821 +               if (vxi->vx_id == xid)
14822 +                       goto found;
14823 +       }
14824 +       vxi = NULL;
14825 +found:
14826 +       vxdprintk(VXD_CBIT(xid, 0),
14827 +               "__lookup_vx_info(#%u): %p[#%u]",
14828 +               xid, vxi, vxi ? vxi->vx_id : 0);
14829 +       vxh_lookup_vx_info(vxi, xid);
14830 +       return vxi;
14831 +}
14832 +
14833 +
14834 +/*     __create_vx_info()
14835 +
14836 +       * create the requested context
14837 +       * get(), claim() and hash it                            */
14838 +
14839 +static struct vx_info *__create_vx_info(int id)
14840 +{
14841 +       struct vx_info *new, *vxi = NULL;
14842 +
14843 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
14844 +
14845 +       if (!(new = __alloc_vx_info(id)))
14846 +               return ERR_PTR(-ENOMEM);
14847 +
14848 +       /* required to make dynamic xids unique */
14849 +       spin_lock(&vx_info_hash_lock);
14850 +
14851 +       /* static context requested */
14852 +       if ((vxi = __lookup_vx_info(id))) {
14853 +               vxdprintk(VXD_CBIT(xid, 0),
14854 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
14855 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
14856 +                       vxi = ERR_PTR(-EBUSY);
14857 +               else
14858 +                       vxi = ERR_PTR(-EEXIST);
14859 +               goto out_unlock;
14860 +       }
14861 +       /* new context */
14862 +       vxdprintk(VXD_CBIT(xid, 0),
14863 +               "create_vx_info(%d) = %p (new)", id, new);
14864 +       claim_vx_info(new, NULL);
14865 +       __hash_vx_info(get_vx_info(new));
14866 +       vxi = new, new = NULL;
14867 +
14868 +out_unlock:
14869 +       spin_unlock(&vx_info_hash_lock);
14870 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
14871 +       if (new)
14872 +               __dealloc_vx_info(new);
14873 +       return vxi;
14874 +}
14875 +
14876 +
14877 +/*     exported stuff                                          */
14878 +
14879 +
14880 +void unhash_vx_info(struct vx_info *vxi)
14881 +{
14882 +       spin_lock(&vx_info_hash_lock);
14883 +       __unhash_vx_info(vxi);
14884 +       spin_unlock(&vx_info_hash_lock);
14885 +       __shutdown_vx_info(vxi);
14886 +       __wakeup_vx_info(vxi);
14887 +}
14888 +
14889 +
14890 +/*     lookup_vx_info()
14891 +
14892 +       * search for a vx_info and get() it
14893 +       * negative id means current                             */
14894 +
14895 +struct vx_info *lookup_vx_info(int id)
14896 +{
14897 +       struct vx_info *vxi = NULL;
14898 +
14899 +       if (id < 0) {
14900 +               vxi = get_vx_info(current_vx_info());
14901 +       } else if (id > 1) {
14902 +               spin_lock(&vx_info_hash_lock);
14903 +               vxi = get_vx_info(__lookup_vx_info(id));
14904 +               spin_unlock(&vx_info_hash_lock);
14905 +       }
14906 +       return vxi;
14907 +}
14908 +
14909 +/*     xid_is_hashed()
14910 +
14911 +       * verify that xid is still hashed                       */
14912 +
14913 +int xid_is_hashed(vxid_t xid)
14914 +{
14915 +       int hashed;
14916 +
14917 +       spin_lock(&vx_info_hash_lock);
14918 +       hashed = (__lookup_vx_info(xid) != NULL);
14919 +       spin_unlock(&vx_info_hash_lock);
14920 +       return hashed;
14921 +}
14922 +
14923 +#ifdef CONFIG_PROC_FS
14924 +
14925 +/*     get_xid_list()
14926 +
14927 +       * get a subset of hashed xids for proc
14928 +       * assumes size is at least one                          */
14929 +
14930 +int get_xid_list(int index, unsigned int *xids, int size)
14931 +{
14932 +       int hindex, nr_xids = 0;
14933 +
14934 +       /* only show current and children */
14935 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
14936 +               if (index > 0)
14937 +                       return 0;
14938 +               xids[nr_xids] = vx_current_xid();
14939 +               return 1;
14940 +       }
14941 +
14942 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
14943 +               struct hlist_head *head = &vx_info_hash[hindex];
14944 +               struct hlist_node *pos;
14945 +
14946 +               spin_lock(&vx_info_hash_lock);
14947 +               hlist_for_each(pos, head) {
14948 +                       struct vx_info *vxi;
14949 +
14950 +                       if (--index > 0)
14951 +                               continue;
14952 +
14953 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
14954 +                       xids[nr_xids] = vxi->vx_id;
14955 +                       if (++nr_xids >= size) {
14956 +                               spin_unlock(&vx_info_hash_lock);
14957 +                               goto out;
14958 +                       }
14959 +               }
14960 +               /* keep the lock time short */
14961 +               spin_unlock(&vx_info_hash_lock);
14962 +       }
14963 +out:
14964 +       return nr_xids;
14965 +}
14966 +#endif
14967 +
14968 +#ifdef CONFIG_VSERVER_DEBUG
14969 +
14970 +void   dump_vx_info_inactive(int level)
14971 +{
14972 +       struct hlist_node *entry, *next;
14973 +
14974 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
14975 +               struct vx_info *vxi =
14976 +                       list_entry(entry, struct vx_info, vx_hlist);
14977 +
14978 +               dump_vx_info(vxi, level);
14979 +       }
14980 +}
14981 +
14982 +#endif
14983 +
14984 +#if 0
14985 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
14986 +{
14987 +       struct user_struct *new_user, *old_user;
14988 +
14989 +       if (!p || !vxi)
14990 +               BUG();
14991 +
14992 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
14993 +               return -EACCES;
14994 +
14995 +       new_user = alloc_uid(vxi->vx_id, p->uid);
14996 +       if (!new_user)
14997 +               return -ENOMEM;
14998 +
14999 +       old_user = p->user;
15000 +       if (new_user != old_user) {
15001 +               atomic_inc(&new_user->processes);
15002 +               atomic_dec(&old_user->processes);
15003 +               p->user = new_user;
15004 +       }
15005 +       free_uid(old_user);
15006 +       return 0;
15007 +}
15008 +#endif
15009 +
15010 +#if 0
15011 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
15012 +{
15013 +       // p->cap_effective &= vxi->vx_cap_bset;
15014 +       p->cap_effective =
15015 +               cap_intersect(p->cap_effective, vxi->cap_bset);
15016 +       // p->cap_inheritable &= vxi->vx_cap_bset;
15017 +       p->cap_inheritable =
15018 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
15019 +       // p->cap_permitted &= vxi->vx_cap_bset;
15020 +       p->cap_permitted =
15021 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
15022 +}
15023 +#endif
15024 +
15025 +
15026 +#include <linux/file.h>
15027 +#include <linux/fdtable.h>
15028 +
15029 +static int vx_openfd_task(struct task_struct *tsk)
15030 +{
15031 +       struct files_struct *files = tsk->files;
15032 +       struct fdtable *fdt;
15033 +       const unsigned long *bptr;
15034 +       int count, total;
15035 +
15036 +       /* no rcu_read_lock() because of spin_lock() */
15037 +       spin_lock(&files->file_lock);
15038 +       fdt = files_fdtable(files);
15039 +       bptr = fdt->open_fds;
15040 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
15041 +       for (total = 0; count > 0; count--) {
15042 +               if (*bptr)
15043 +                       total += hweight_long(*bptr);
15044 +               bptr++;
15045 +       }
15046 +       spin_unlock(&files->file_lock);
15047 +       return total;
15048 +}
15049 +
15050 +
15051 +/*     for *space compatibility */
15052 +
15053 +asmlinkage long sys_unshare(unsigned long);
15054 +
15055 +/*
15056 + *     migrate task to new context
15057 + *     gets vxi, puts old_vxi on change
15058 + *     optionally unshares namespaces (hack)
15059 + */
15060 +
15061 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
15062 +{
15063 +       struct vx_info *old_vxi;
15064 +       int ret = 0;
15065 +
15066 +       if (!p || !vxi)
15067 +               BUG();
15068 +
15069 +       vxdprintk(VXD_CBIT(xid, 5),
15070 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
15071 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
15072 +
15073 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
15074 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15075 +               return -EACCES;
15076 +
15077 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
15078 +               return -EFAULT;
15079 +
15080 +       old_vxi = task_get_vx_info(p);
15081 +       if (old_vxi == vxi)
15082 +               goto out;
15083 +
15084 +//     if (!(ret = vx_migrate_user(p, vxi))) {
15085 +       {
15086 +               int openfd;
15087 +
15088 +               task_lock(p);
15089 +               openfd = vx_openfd_task(p);
15090 +
15091 +               if (old_vxi) {
15092 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
15093 +                       atomic_dec(&old_vxi->cvirt.nr_running);
15094 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
15095 +                       /* FIXME: what about the struct files here? */
15096 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
15097 +                       /* account for the executable */
15098 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
15099 +               }
15100 +               atomic_inc(&vxi->cvirt.nr_threads);
15101 +               atomic_inc(&vxi->cvirt.nr_running);
15102 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
15103 +               /* FIXME: what about the struct files here? */
15104 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
15105 +               /* account for the executable */
15106 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
15107 +
15108 +               if (old_vxi) {
15109 +                       release_vx_info(old_vxi, p);
15110 +                       clr_vx_info(&p->vx_info);
15111 +               }
15112 +               claim_vx_info(vxi, p);
15113 +               set_vx_info(&p->vx_info, vxi);
15114 +               p->xid = vxi->vx_id;
15115 +
15116 +               vxdprintk(VXD_CBIT(xid, 5),
15117 +                       "moved task %p into vxi:%p[#%d]",
15118 +                       p, vxi, vxi->vx_id);
15119 +
15120 +               // vx_mask_cap_bset(vxi, p);
15121 +               task_unlock(p);
15122 +
15123 +               /* hack for *spaces to provide compatibility */
15124 +               if (unshare) {
15125 +                       struct nsproxy *old_nsp, *new_nsp;
15126 +
15127 +                       ret = unshare_nsproxy_namespaces(
15128 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
15129 +                               &new_nsp, NULL, NULL);
15130 +                       if (ret)
15131 +                               goto out;
15132 +
15133 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
15134 +                       vx_set_space(vxi,
15135 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
15136 +                       put_nsproxy(old_nsp);
15137 +               }
15138 +       }
15139 +out:
15140 +       put_vx_info(old_vxi);
15141 +       return ret;
15142 +}
15143 +
15144 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
15145 +{
15146 +       struct task_struct *old_reaper;
15147 +       struct vx_info *reaper_vxi;
15148 +
15149 +       if (!vxi)
15150 +               return -EINVAL;
15151 +
15152 +       vxdprintk(VXD_CBIT(xid, 6),
15153 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
15154 +               vxi, vxi->vx_id, p, p->xid, p->pid);
15155 +
15156 +       old_reaper = vxi->vx_reaper;
15157 +       if (old_reaper == p)
15158 +               return 0;
15159 +
15160 +       reaper_vxi = task_get_vx_info(p);
15161 +       if (reaper_vxi && reaper_vxi != vxi) {
15162 +               vxwprintk(1,
15163 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
15164 +                       "for [xid #%u]",
15165 +                       p->comm, p->pid, p->xid, vx_current_xid());
15166 +               goto out;
15167 +       }
15168 +
15169 +       /* set new child reaper */
15170 +       get_task_struct(p);
15171 +       vxi->vx_reaper = p;
15172 +       put_task_struct(old_reaper);
15173 +out:
15174 +       put_vx_info(reaper_vxi);
15175 +       return 0;
15176 +}
15177 +
15178 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
15179 +{
15180 +       if (!vxi)
15181 +               return -EINVAL;
15182 +
15183 +       vxdprintk(VXD_CBIT(xid, 6),
15184 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
15185 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15186 +
15187 +       vxi->vx_flags &= ~VXF_STATE_INIT;
15188 +       // vxi->vx_initpid = p->tgid;
15189 +       vxi->vx_initpid = p->pid;
15190 +       return 0;
15191 +}
15192 +
15193 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
15194 +{
15195 +       vxdprintk(VXD_CBIT(xid, 6),
15196 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
15197 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15198 +
15199 +       vxi->exit_code = code;
15200 +       vxi->vx_initpid = 0;
15201 +}
15202 +
15203 +
15204 +void vx_set_persistent(struct vx_info *vxi)
15205 +{
15206 +       vxdprintk(VXD_CBIT(xid, 6),
15207 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
15208 +
15209 +       get_vx_info(vxi);
15210 +       claim_vx_info(vxi, NULL);
15211 +}
15212 +
15213 +void vx_clear_persistent(struct vx_info *vxi)
15214 +{
15215 +       vxdprintk(VXD_CBIT(xid, 6),
15216 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
15217 +
15218 +       release_vx_info(vxi, NULL);
15219 +       put_vx_info(vxi);
15220 +}
15221 +
15222 +void vx_update_persistent(struct vx_info *vxi)
15223 +{
15224 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
15225 +               vx_set_persistent(vxi);
15226 +       else
15227 +               vx_clear_persistent(vxi);
15228 +}
15229 +
15230 +
15231 +/*     task must be current or locked          */
15232 +
15233 +void   exit_vx_info(struct task_struct *p, int code)
15234 +{
15235 +       struct vx_info *vxi = p->vx_info;
15236 +
15237 +       if (vxi) {
15238 +               atomic_dec(&vxi->cvirt.nr_threads);
15239 +               vx_nproc_dec(p);
15240 +
15241 +               vxi->exit_code = code;
15242 +               release_vx_info(vxi, p);
15243 +       }
15244 +}
15245 +
15246 +void   exit_vx_info_early(struct task_struct *p, int code)
15247 +{
15248 +       struct vx_info *vxi = p->vx_info;
15249 +
15250 +       if (vxi) {
15251 +               if (vxi->vx_initpid == p->pid)
15252 +                       vx_exit_init(vxi, p, code);
15253 +               if (vxi->vx_reaper == p)
15254 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
15255 +       }
15256 +}
15257 +
15258 +
15259 +/* vserver syscall commands below here */
15260 +
15261 +/* taks xid and vx_info functions */
15262 +
15263 +#include <asm/uaccess.h>
15264 +
15265 +
15266 +int vc_task_xid(uint32_t id)
15267 +{
15268 +       vxid_t xid;
15269 +
15270 +       if (id) {
15271 +               struct task_struct *tsk;
15272 +
15273 +               rcu_read_lock();
15274 +               tsk = find_task_by_real_pid(id);
15275 +               xid = (tsk) ? tsk->xid : -ESRCH;
15276 +               rcu_read_unlock();
15277 +       } else
15278 +               xid = vx_current_xid();
15279 +       return xid;
15280 +}
15281 +
15282 +
15283 +int vc_vx_info(struct vx_info *vxi, void __user *data)
15284 +{
15285 +       struct vcmd_vx_info_v0 vc_data;
15286 +
15287 +       vc_data.xid = vxi->vx_id;
15288 +       vc_data.initpid = vxi->vx_initpid;
15289 +
15290 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15291 +               return -EFAULT;
15292 +       return 0;
15293 +}
15294 +
15295 +
15296 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
15297 +{
15298 +       struct vcmd_ctx_stat_v0 vc_data;
15299 +
15300 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
15301 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
15302 +
15303 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15304 +               return -EFAULT;
15305 +       return 0;
15306 +}
15307 +
15308 +
15309 +/* context functions */
15310 +
15311 +int vc_ctx_create(uint32_t xid, void __user *data)
15312 +{
15313 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
15314 +       struct vx_info *new_vxi;
15315 +       int ret;
15316 +
15317 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15318 +               return -EFAULT;
15319 +
15320 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
15321 +               return -EINVAL;
15322 +
15323 +       new_vxi = __create_vx_info(xid);
15324 +       if (IS_ERR(new_vxi))
15325 +               return PTR_ERR(new_vxi);
15326 +
15327 +       /* initial flags */
15328 +       new_vxi->vx_flags = vc_data.flagword;
15329 +
15330 +       ret = -ENOEXEC;
15331 +       if (vs_state_change(new_vxi, VSC_STARTUP))
15332 +               goto out;
15333 +
15334 +       ret = vx_migrate_task(current, new_vxi, (!data));
15335 +       if (ret)
15336 +               goto out;
15337 +
15338 +       /* return context id on success */
15339 +       ret = new_vxi->vx_id;
15340 +
15341 +       /* get a reference for persistent contexts */
15342 +       if ((vc_data.flagword & VXF_PERSISTENT))
15343 +               vx_set_persistent(new_vxi);
15344 +out:
15345 +       release_vx_info(new_vxi, NULL);
15346 +       put_vx_info(new_vxi);
15347 +       return ret;
15348 +}
15349 +
15350 +
15351 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
15352 +{
15353 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
15354 +       int ret;
15355 +
15356 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15357 +               return -EFAULT;
15358 +
15359 +       ret = vx_migrate_task(current, vxi, 0);
15360 +       if (ret)
15361 +               return ret;
15362 +       if (vc_data.flagword & VXM_SET_INIT)
15363 +               ret = vx_set_init(vxi, current);
15364 +       if (ret)
15365 +               return ret;
15366 +       if (vc_data.flagword & VXM_SET_REAPER)
15367 +               ret = vx_set_reaper(vxi, current);
15368 +       return ret;
15369 +}
15370 +
15371 +
15372 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
15373 +{
15374 +       struct vcmd_ctx_flags_v0 vc_data;
15375 +
15376 +       vc_data.flagword = vxi->vx_flags;
15377 +
15378 +       /* special STATE flag handling */
15379 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
15380 +
15381 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15382 +               return -EFAULT;
15383 +       return 0;
15384 +}
15385 +
15386 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
15387 +{
15388 +       struct vcmd_ctx_flags_v0 vc_data;
15389 +       uint64_t mask, trigger;
15390 +
15391 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15392 +               return -EFAULT;
15393 +
15394 +       /* special STATE flag handling */
15395 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
15396 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
15397 +
15398 +       if (vxi == current_vx_info()) {
15399 +               /* if (trigger & VXF_STATE_SETUP)
15400 +                       vx_mask_cap_bset(vxi, current); */
15401 +               if (trigger & VXF_STATE_INIT) {
15402 +                       int ret;
15403 +
15404 +                       ret = vx_set_init(vxi, current);
15405 +                       if (ret)
15406 +                               return ret;
15407 +                       ret = vx_set_reaper(vxi, current);
15408 +                       if (ret)
15409 +                               return ret;
15410 +               }
15411 +       }
15412 +
15413 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
15414 +               vc_data.flagword, mask);
15415 +       if (trigger & VXF_PERSISTENT)
15416 +               vx_update_persistent(vxi);
15417 +
15418 +       return 0;
15419 +}
15420 +
15421 +
15422 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
15423 +{
15424 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
15425 +
15426 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
15427 +       return v;
15428 +}
15429 +
15430 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
15431 +{
15432 +       kernel_cap_t c = __cap_empty_set;
15433 +
15434 +       c.cap[0] = v & 0xFFFFFFFF;
15435 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
15436 +
15437 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
15438 +       return c;
15439 +}
15440 +
15441 +
15442 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
15443 +{
15444 +       if (bcaps)
15445 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
15446 +       if (ccaps)
15447 +               *ccaps = vxi->vx_ccaps;
15448 +
15449 +       return 0;
15450 +}
15451 +
15452 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
15453 +{
15454 +       struct vcmd_ctx_caps_v1 vc_data;
15455 +       int ret;
15456 +
15457 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
15458 +       if (ret)
15459 +               return ret;
15460 +       vc_data.cmask = ~0ULL;
15461 +
15462 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15463 +               return -EFAULT;
15464 +       return 0;
15465 +}
15466 +
15467 +static int do_set_caps(struct vx_info *vxi,
15468 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
15469 +{
15470 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
15471 +
15472 +#if 0
15473 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
15474 +               bcaps, bmask, ccaps, cmask);
15475 +#endif
15476 +       vxi->vx_bcaps = cap_t_from_caps(
15477 +               vs_mask_flags(bcold, bcaps, bmask));
15478 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
15479 +
15480 +       return 0;
15481 +}
15482 +
15483 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
15484 +{
15485 +       struct vcmd_ctx_caps_v1 vc_data;
15486 +
15487 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15488 +               return -EFAULT;
15489 +
15490 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
15491 +}
15492 +
15493 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
15494 +{
15495 +       struct vcmd_bcaps vc_data;
15496 +       int ret;
15497 +
15498 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
15499 +       if (ret)
15500 +               return ret;
15501 +       vc_data.bmask = ~0ULL;
15502 +
15503 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15504 +               return -EFAULT;
15505 +       return 0;
15506 +}
15507 +
15508 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
15509 +{
15510 +       struct vcmd_bcaps vc_data;
15511 +
15512 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15513 +               return -EFAULT;
15514 +
15515 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
15516 +}
15517 +
15518 +
15519 +int vc_get_umask(struct vx_info *vxi, void __user *data)
15520 +{
15521 +       struct vcmd_umask vc_data;
15522 +
15523 +       vc_data.umask = vxi->vx_umask;
15524 +       vc_data.mask = ~0ULL;
15525 +
15526 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15527 +               return -EFAULT;
15528 +       return 0;
15529 +}
15530 +
15531 +int vc_set_umask(struct vx_info *vxi, void __user *data)
15532 +{
15533 +       struct vcmd_umask vc_data;
15534 +
15535 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15536 +               return -EFAULT;
15537 +
15538 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
15539 +               vc_data.umask, vc_data.mask);
15540 +       return 0;
15541 +}
15542 +
15543 +
15544 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
15545 +{
15546 +       struct vcmd_wmask vc_data;
15547 +
15548 +       vc_data.wmask = vxi->vx_wmask;
15549 +       vc_data.mask = ~0ULL;
15550 +
15551 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15552 +               return -EFAULT;
15553 +       return 0;
15554 +}
15555 +
15556 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
15557 +{
15558 +       struct vcmd_wmask vc_data;
15559 +
15560 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15561 +               return -EFAULT;
15562 +
15563 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
15564 +               vc_data.wmask, vc_data.mask);
15565 +       return 0;
15566 +}
15567 +
15568 +
15569 +int vc_get_badness(struct vx_info *vxi, void __user *data)
15570 +{
15571 +       struct vcmd_badness_v0 vc_data;
15572 +
15573 +       vc_data.bias = vxi->vx_badness_bias;
15574 +
15575 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15576 +               return -EFAULT;
15577 +       return 0;
15578 +}
15579 +
15580 +int vc_set_badness(struct vx_info *vxi, void __user *data)
15581 +{
15582 +       struct vcmd_badness_v0 vc_data;
15583 +
15584 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15585 +               return -EFAULT;
15586 +
15587 +       vxi->vx_badness_bias = vc_data.bias;
15588 +       return 0;
15589 +}
15590 +
15591 +#include <linux/module.h>
15592 +
15593 +EXPORT_SYMBOL_GPL(free_vx_info);
15594 +
15595 diff -NurpP --minimal linux-4.4.110/kernel/vserver/cvirt.c linux-4.4.110-vs2.3.9/kernel/vserver/cvirt.c
15596 --- linux-4.4.110/kernel/vserver/cvirt.c        1970-01-01 00:00:00.000000000 +0000
15597 +++ linux-4.4.110-vs2.3.9/kernel/vserver/cvirt.c        2018-01-09 22:27:39.000000000 +0000
15598 @@ -0,0 +1,313 @@
15599 +/*
15600 + *  linux/kernel/vserver/cvirt.c
15601 + *
15602 + *  Virtual Server: Context Virtualization
15603 + *
15604 + *  Copyright (C) 2004-2007  Herbert P?tzl
15605 + *
15606 + *  V0.01  broken out from limit.c
15607 + *  V0.02  added utsname stuff
15608 + *  V0.03  changed vcmds to vxi arg
15609 + *
15610 + */
15611 +
15612 +#include <linux/types.h>
15613 +#include <linux/utsname.h>
15614 +#include <linux/vs_cvirt.h>
15615 +#include <linux/vserver/switch.h>
15616 +#include <linux/vserver/cvirt_cmd.h>
15617 +
15618 +#include <asm/uaccess.h>
15619 +
15620 +
15621 +void vx_vsi_boottime(struct timespec *boottime)
15622 +{
15623 +       struct vx_info *vxi = current_vx_info();
15624 +
15625 +       set_normalized_timespec(boottime,
15626 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
15627 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
15628 +       return;
15629 +}
15630 +
15631 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
15632 +{
15633 +       struct vx_info *vxi = current_vx_info();
15634 +
15635 +       set_normalized_timespec(uptime,
15636 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
15637 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
15638 +       if (!idle)
15639 +               return;
15640 +       set_normalized_timespec(idle,
15641 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
15642 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
15643 +       return;
15644 +}
15645 +
15646 +uint64_t vx_idle_jiffies(void)
15647 +{
15648 +       return init_task.utime + init_task.stime;
15649 +}
15650 +
15651 +
15652 +
15653 +static inline uint32_t __update_loadavg(uint32_t load,
15654 +       int wsize, int delta, int n)
15655 +{
15656 +       unsigned long long calc, prev;
15657 +
15658 +       /* just set it to n */
15659 +       if (unlikely(delta >= wsize))
15660 +               return (n << FSHIFT);
15661 +
15662 +       calc = delta * n;
15663 +       calc <<= FSHIFT;
15664 +       prev = (wsize - delta);
15665 +       prev *= load;
15666 +       calc += prev;
15667 +       do_div(calc, wsize);
15668 +       return calc;
15669 +}
15670 +
15671 +
15672 +void vx_update_load(struct vx_info *vxi)
15673 +{
15674 +       uint32_t now, last, delta;
15675 +       unsigned int nr_running, nr_uninterruptible;
15676 +       unsigned int total;
15677 +       unsigned long flags;
15678 +
15679 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
15680 +
15681 +       now = jiffies;
15682 +       last = vxi->cvirt.load_last;
15683 +       delta = now - last;
15684 +
15685 +       if (delta < 5*HZ)
15686 +               goto out;
15687 +
15688 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
15689 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
15690 +       total = nr_running + nr_uninterruptible;
15691 +
15692 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
15693 +               60*HZ, delta, total);
15694 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
15695 +               5*60*HZ, delta, total);
15696 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
15697 +               15*60*HZ, delta, total);
15698 +
15699 +       vxi->cvirt.load_last = now;
15700 +out:
15701 +       atomic_inc(&vxi->cvirt.load_updates);
15702 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
15703 +}
15704 +
15705 +
15706 +/*
15707 + * Commands to do_syslog:
15708 + *
15709 + *      0 -- Close the log.  Currently a NOP.
15710 + *      1 -- Open the log. Currently a NOP.
15711 + *      2 -- Read from the log.
15712 + *      3 -- Read all messages remaining in the ring buffer.
15713 + *      4 -- Read and clear all messages remaining in the ring buffer
15714 + *      5 -- Clear ring buffer.
15715 + *      6 -- Disable printk's to console
15716 + *      7 -- Enable printk's to console
15717 + *      8 -- Set level of messages printed to console
15718 + *      9 -- Return number of unread characters in the log buffer
15719 + *     10 -- Return size of the log buffer
15720 + */
15721 +int vx_do_syslog(int type, char __user *buf, int len)
15722 +{
15723 +       int error = 0;
15724 +       int do_clear = 0;
15725 +       struct vx_info *vxi = current_vx_info();
15726 +       struct _vx_syslog *log;
15727 +
15728 +       if (!vxi)
15729 +               return -EINVAL;
15730 +       log = &vxi->cvirt.syslog;
15731 +
15732 +       switch (type) {
15733 +       case 0:         /* Close log */
15734 +       case 1:         /* Open log */
15735 +               break;
15736 +       case 2:         /* Read from log */
15737 +               error = wait_event_interruptible(log->log_wait,
15738 +                       (log->log_start - log->log_end));
15739 +               if (error)
15740 +                       break;
15741 +               spin_lock_irq(&log->logbuf_lock);
15742 +               spin_unlock_irq(&log->logbuf_lock);
15743 +               break;
15744 +       case 4:         /* Read/clear last kernel messages */
15745 +               do_clear = 1;
15746 +               /* fall through */
15747 +       case 3:         /* Read last kernel messages */
15748 +               return 0;
15749 +
15750 +       case 5:         /* Clear ring buffer */
15751 +               return 0;
15752 +
15753 +       case 6:         /* Disable logging to console */
15754 +       case 7:         /* Enable logging to console */
15755 +       case 8:         /* Set level of messages printed to console */
15756 +               break;
15757 +
15758 +       case 9:         /* Number of chars in the log buffer */
15759 +               return 0;
15760 +       case 10:        /* Size of the log buffer */
15761 +               return 0;
15762 +       default:
15763 +               error = -EINVAL;
15764 +               break;
15765 +       }
15766 +       return error;
15767 +}
15768 +
15769 +
15770 +/* virtual host info names */
15771 +
15772 +static char *vx_vhi_name(struct vx_info *vxi, int id)
15773 +{
15774 +       struct nsproxy *nsproxy;
15775 +       struct uts_namespace *uts;
15776 +
15777 +       if (id == VHIN_CONTEXT)
15778 +               return vxi->vx_name;
15779 +
15780 +       nsproxy = vxi->space[0].vx_nsproxy;
15781 +       if (!nsproxy)
15782 +               return NULL;
15783 +
15784 +       uts = nsproxy->uts_ns;
15785 +       if (!uts)
15786 +               return NULL;
15787 +
15788 +       switch (id) {
15789 +       case VHIN_SYSNAME:
15790 +               return uts->name.sysname;
15791 +       case VHIN_NODENAME:
15792 +               return uts->name.nodename;
15793 +       case VHIN_RELEASE:
15794 +               return uts->name.release;
15795 +       case VHIN_VERSION:
15796 +               return uts->name.version;
15797 +       case VHIN_MACHINE:
15798 +               return uts->name.machine;
15799 +       case VHIN_DOMAINNAME:
15800 +               return uts->name.domainname;
15801 +       default:
15802 +               return NULL;
15803 +       }
15804 +       return NULL;
15805 +}
15806 +
15807 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
15808 +{
15809 +       struct vcmd_vhi_name_v0 vc_data;
15810 +       char *name;
15811 +
15812 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15813 +               return -EFAULT;
15814 +
15815 +       name = vx_vhi_name(vxi, vc_data.field);
15816 +       if (!name)
15817 +               return -EINVAL;
15818 +
15819 +       memcpy(name, vc_data.name, 65);
15820 +       return 0;
15821 +}
15822 +
15823 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
15824 +{
15825 +       struct vcmd_vhi_name_v0 vc_data;
15826 +       char *name;
15827 +
15828 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15829 +               return -EFAULT;
15830 +
15831 +       name = vx_vhi_name(vxi, vc_data.field);
15832 +       if (!name)
15833 +               return -EINVAL;
15834 +
15835 +       memcpy(vc_data.name, name, 65);
15836 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15837 +               return -EFAULT;
15838 +       return 0;
15839 +}
15840 +
15841 +
15842 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
15843 +{
15844 +       struct vcmd_virt_stat_v0 vc_data;
15845 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
15846 +       struct timespec uptime;
15847 +
15848 +       ktime_get_ts(&uptime);
15849 +       set_normalized_timespec(&uptime,
15850 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
15851 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
15852 +
15853 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
15854 +       vc_data.uptime = timespec_to_ns(&uptime);
15855 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
15856 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
15857 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
15858 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
15859 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
15860 +       vc_data.load[0] = cvirt->load[0];
15861 +       vc_data.load[1] = cvirt->load[1];
15862 +       vc_data.load[2] = cvirt->load[2];
15863 +
15864 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15865 +               return -EFAULT;
15866 +       return 0;
15867 +}
15868 +
15869 +
15870 +#ifdef CONFIG_VSERVER_VTIME
15871 +
15872 +/* virtualized time base */
15873 +
15874 +void vx_adjust_timespec(struct timespec *ts)
15875 +{
15876 +       struct vx_info *vxi;
15877 +
15878 +       if (!vx_flags(VXF_VIRT_TIME, 0))
15879 +               return;
15880 +
15881 +       vxi = current_vx_info();
15882 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
15883 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
15884 +
15885 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
15886 +               ts->tv_sec++;
15887 +               ts->tv_nsec -= NSEC_PER_SEC;
15888 +       } else if (ts->tv_nsec < 0) {
15889 +               ts->tv_sec--;
15890 +               ts->tv_nsec += NSEC_PER_SEC;
15891 +       }
15892 +}
15893 +
15894 +int vx_settimeofday(const struct timespec *ts)
15895 +{
15896 +       struct timespec ats, delta;
15897 +       struct vx_info *vxi;
15898 +
15899 +       if (!vx_flags(VXF_VIRT_TIME, 0))
15900 +               return do_settimeofday(ts);
15901 +
15902 +       getnstimeofday(&ats);
15903 +       delta = timespec_sub(*ts, ats);
15904 +
15905 +       vxi = current_vx_info();
15906 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
15907 +       return 0;
15908 +}
15909 +
15910 +#endif
15911 +
15912 diff -NurpP --minimal linux-4.4.110/kernel/vserver/cvirt_init.h linux-4.4.110-vs2.3.9/kernel/vserver/cvirt_init.h
15913 --- linux-4.4.110/kernel/vserver/cvirt_init.h   1970-01-01 00:00:00.000000000 +0000
15914 +++ linux-4.4.110-vs2.3.9/kernel/vserver/cvirt_init.h   2018-01-09 22:16:00.000000000 +0000
15915 @@ -0,0 +1,70 @@
15916 +
15917 +
15918 +extern uint64_t vx_idle_jiffies(void);
15919 +
15920 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
15921 +{
15922 +       uint64_t idle_jiffies = vx_idle_jiffies();
15923 +       uint64_t nsuptime;
15924 +
15925 +       ktime_get_ts(&cvirt->bias_uptime);
15926 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
15927 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
15928 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
15929 +       cvirt->bias_ts.tv_sec = 0;
15930 +       cvirt->bias_ts.tv_nsec = 0;
15931 +
15932 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
15933 +       atomic_set(&cvirt->nr_threads, 0);
15934 +       atomic_set(&cvirt->nr_running, 0);
15935 +       atomic_set(&cvirt->nr_uninterruptible, 0);
15936 +       atomic_set(&cvirt->nr_onhold, 0);
15937 +
15938 +       spin_lock_init(&cvirt->load_lock);
15939 +       cvirt->load_last = jiffies;
15940 +       atomic_set(&cvirt->load_updates, 0);
15941 +       cvirt->load[0] = 0;
15942 +       cvirt->load[1] = 0;
15943 +       cvirt->load[2] = 0;
15944 +       atomic_set(&cvirt->total_forks, 0);
15945 +
15946 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
15947 +       init_waitqueue_head(&cvirt->syslog.log_wait);
15948 +       cvirt->syslog.log_start = 0;
15949 +       cvirt->syslog.log_end = 0;
15950 +       cvirt->syslog.con_start = 0;
15951 +       cvirt->syslog.logged_chars = 0;
15952 +}
15953 +
15954 +static inline
15955 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
15956 +{
15957 +       // cvirt_pc->cpustat = { 0 };
15958 +}
15959 +
15960 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
15961 +{
15962 +#ifdef CONFIG_VSERVER_WARN
15963 +       int value;
15964 +#endif
15965 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
15966 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
15967 +               cvirt, value);
15968 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
15969 +               "!!! cvirt: %p[nr_running] = %d on exit.",
15970 +               cvirt, value);
15971 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
15972 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
15973 +               cvirt, value);
15974 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
15975 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
15976 +               cvirt, value);
15977 +       return;
15978 +}
15979 +
15980 +static inline
15981 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
15982 +{
15983 +       return;
15984 +}
15985 +
15986 diff -NurpP --minimal linux-4.4.110/kernel/vserver/cvirt_proc.h linux-4.4.110-vs2.3.9/kernel/vserver/cvirt_proc.h
15987 --- linux-4.4.110/kernel/vserver/cvirt_proc.h   1970-01-01 00:00:00.000000000 +0000
15988 +++ linux-4.4.110-vs2.3.9/kernel/vserver/cvirt_proc.h   2018-01-09 16:36:34.000000000 +0000
15989 @@ -0,0 +1,123 @@
15990 +#ifndef _VX_CVIRT_PROC_H
15991 +#define _VX_CVIRT_PROC_H
15992 +
15993 +#include <linux/nsproxy.h>
15994 +#include <linux/mnt_namespace.h>
15995 +#include <linux/ipc_namespace.h>
15996 +#include <linux/utsname.h>
15997 +#include <linux/ipc.h>
15998 +
15999 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
16000 +
16001 +static inline
16002 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
16003 +{
16004 +       struct mnt_namespace *ns;
16005 +       struct uts_namespace *uts;
16006 +       struct ipc_namespace *ipc;
16007 +       int length = 0;
16008 +
16009 +       if (!nsproxy)
16010 +               goto out;
16011 +
16012 +       length += sprintf(buffer + length,
16013 +               "NSProxy:\t%p [%p,%p,%p]\n",
16014 +               nsproxy, nsproxy->mnt_ns,
16015 +               nsproxy->uts_ns, nsproxy->ipc_ns);
16016 +
16017 +       ns = nsproxy->mnt_ns;
16018 +       if (!ns)
16019 +               goto skip_ns;
16020 +
16021 +       length += vx_info_mnt_namespace(ns, buffer + length);
16022 +
16023 +skip_ns:
16024 +
16025 +       uts = nsproxy->uts_ns;
16026 +       if (!uts)
16027 +               goto skip_uts;
16028 +
16029 +       length += sprintf(buffer + length,
16030 +               "SysName:\t%.*s\n"
16031 +               "NodeName:\t%.*s\n"
16032 +               "Release:\t%.*s\n"
16033 +               "Version:\t%.*s\n"
16034 +               "Machine:\t%.*s\n"
16035 +               "DomainName:\t%.*s\n",
16036 +               __NEW_UTS_LEN, uts->name.sysname,
16037 +               __NEW_UTS_LEN, uts->name.nodename,
16038 +               __NEW_UTS_LEN, uts->name.release,
16039 +               __NEW_UTS_LEN, uts->name.version,
16040 +               __NEW_UTS_LEN, uts->name.machine,
16041 +               __NEW_UTS_LEN, uts->name.domainname);
16042 +skip_uts:
16043 +
16044 +       ipc = nsproxy->ipc_ns;
16045 +       if (!ipc)
16046 +               goto skip_ipc;
16047 +
16048 +       length += sprintf(buffer + length,
16049 +               "SEMS:\t\t%d %d %d %d  %d\n"
16050 +               "MSG:\t\t%d %d %d\n"
16051 +               "SHM:\t\t%lu %lu  %d %ld\n",
16052 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
16053 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
16054 +               ipc->used_sems,
16055 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
16056 +               (unsigned long)ipc->shm_ctlmax,
16057 +               (unsigned long)ipc->shm_ctlall,
16058 +               ipc->shm_ctlmni, ipc->shm_tot);
16059 +skip_ipc:
16060 +out:
16061 +       return length;
16062 +}
16063 +
16064 +
16065 +#include <linux/sched.h>
16066 +
16067 +#define LOAD_INT(x) ((x) >> FSHIFT)
16068 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
16069 +
16070 +static inline
16071 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
16072 +{
16073 +       int length = 0;
16074 +       int a, b, c;
16075 +
16076 +       length += sprintf(buffer + length,
16077 +               "BiasUptime:\t%lu.%02lu\n",
16078 +               (unsigned long)cvirt->bias_uptime.tv_sec,
16079 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
16080 +
16081 +       a = cvirt->load[0] + (FIXED_1 / 200);
16082 +       b = cvirt->load[1] + (FIXED_1 / 200);
16083 +       c = cvirt->load[2] + (FIXED_1 / 200);
16084 +       length += sprintf(buffer + length,
16085 +               "nr_threads:\t%d\n"
16086 +               "nr_running:\t%d\n"
16087 +               "nr_unintr:\t%d\n"
16088 +               "nr_onhold:\t%d\n"
16089 +               "load_updates:\t%d\n"
16090 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
16091 +               "total_forks:\t%d\n",
16092 +               atomic_read(&cvirt->nr_threads),
16093 +               atomic_read(&cvirt->nr_running),
16094 +               atomic_read(&cvirt->nr_uninterruptible),
16095 +               atomic_read(&cvirt->nr_onhold),
16096 +               atomic_read(&cvirt->load_updates),
16097 +               LOAD_INT(a), LOAD_FRAC(a),
16098 +               LOAD_INT(b), LOAD_FRAC(b),
16099 +               LOAD_INT(c), LOAD_FRAC(c),
16100 +               atomic_read(&cvirt->total_forks));
16101 +       return length;
16102 +}
16103 +
16104 +static inline
16105 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
16106 +       char *buffer, int cpu)
16107 +{
16108 +       int length = 0;
16109 +       return length;
16110 +}
16111 +
16112 +#endif /* _VX_CVIRT_PROC_H */
16113 diff -NurpP --minimal linux-4.4.110/kernel/vserver/debug.c linux-4.4.110-vs2.3.9/kernel/vserver/debug.c
16114 --- linux-4.4.110/kernel/vserver/debug.c        1970-01-01 00:00:00.000000000 +0000
16115 +++ linux-4.4.110-vs2.3.9/kernel/vserver/debug.c        2018-01-09 16:36:34.000000000 +0000
16116 @@ -0,0 +1,32 @@
16117 +/*
16118 + *  kernel/vserver/debug.c
16119 + *
16120 + *  Copyright (C) 2005-2007 Herbert P?tzl
16121 + *
16122 + *  V0.01  vx_info dump support
16123 + *
16124 + */
16125 +
16126 +#include <linux/module.h>
16127 +
16128 +#include <linux/vserver/context.h>
16129 +
16130 +
16131 +void   dump_vx_info(struct vx_info *vxi, int level)
16132 +{
16133 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
16134 +               atomic_read(&vxi->vx_usecnt),
16135 +               atomic_read(&vxi->vx_tasks),
16136 +               vxi->vx_state);
16137 +       if (level > 0) {
16138 +               __dump_vx_limit(&vxi->limit);
16139 +               __dump_vx_sched(&vxi->sched);
16140 +               __dump_vx_cvirt(&vxi->cvirt);
16141 +               __dump_vx_cacct(&vxi->cacct);
16142 +       }
16143 +       printk("---\n");
16144 +}
16145 +
16146 +
16147 +EXPORT_SYMBOL_GPL(dump_vx_info);
16148 +
16149 diff -NurpP --minimal linux-4.4.110/kernel/vserver/device.c linux-4.4.110-vs2.3.9/kernel/vserver/device.c
16150 --- linux-4.4.110/kernel/vserver/device.c       1970-01-01 00:00:00.000000000 +0000
16151 +++ linux-4.4.110-vs2.3.9/kernel/vserver/device.c       2018-01-09 16:36:34.000000000 +0000
16152 @@ -0,0 +1,443 @@
16153 +/*
16154 + *  linux/kernel/vserver/device.c
16155 + *
16156 + *  Linux-VServer: Device Support
16157 + *
16158 + *  Copyright (C) 2006  Herbert P?tzl
16159 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
16160 + *
16161 + *  V0.01  device mapping basics
16162 + *  V0.02  added defaults
16163 + *
16164 + */
16165 +
16166 +#include <linux/slab.h>
16167 +#include <linux/rcupdate.h>
16168 +#include <linux/fs.h>
16169 +#include <linux/namei.h>
16170 +#include <linux/hash.h>
16171 +
16172 +#include <asm/errno.h>
16173 +#include <asm/uaccess.h>
16174 +#include <linux/vserver/base.h>
16175 +#include <linux/vserver/debug.h>
16176 +#include <linux/vserver/context.h>
16177 +#include <linux/vserver/device.h>
16178 +#include <linux/vserver/device_cmd.h>
16179 +
16180 +
16181 +#define DMAP_HASH_BITS 4
16182 +
16183 +
16184 +struct vs_mapping {
16185 +       union {
16186 +               struct hlist_node hlist;
16187 +               struct list_head list;
16188 +       } u;
16189 +#define dm_hlist       u.hlist
16190 +#define dm_list                u.list
16191 +       vxid_t xid;
16192 +       dev_t device;
16193 +       struct vx_dmap_target target;
16194 +};
16195 +
16196 +
16197 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
16198 +
16199 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
16200 +
16201 +static struct vx_dmap_target dmap_defaults[2] = {
16202 +       { .flags = DATTR_OPEN },
16203 +       { .flags = DATTR_OPEN },
16204 +};
16205 +
16206 +
16207 +struct kmem_cache *dmap_cachep __read_mostly;
16208 +
16209 +int __init dmap_cache_init(void)
16210 +{
16211 +       dmap_cachep = kmem_cache_create("dmap_cache",
16212 +               sizeof(struct vs_mapping), 0,
16213 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
16214 +       return 0;
16215 +}
16216 +
16217 +__initcall(dmap_cache_init);
16218 +
16219 +
16220 +static inline unsigned int __hashval(dev_t dev, int bits)
16221 +{
16222 +       return hash_long((unsigned long)dev, bits);
16223 +}
16224 +
16225 +
16226 +/*     __hash_mapping()
16227 + *     add the mapping to the hash table
16228 + */
16229 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
16230 +{
16231 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16232 +       struct hlist_head *head, *hash = dmap_main_hash;
16233 +       int device = vdm->device;
16234 +
16235 +       spin_lock(hash_lock);
16236 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
16237 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
16238 +
16239 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
16240 +       hlist_add_head(&vdm->dm_hlist, head);
16241 +       spin_unlock(hash_lock);
16242 +}
16243 +
16244 +
16245 +static inline int __mode_to_default(umode_t mode)
16246 +{
16247 +       switch (mode) {
16248 +       case S_IFBLK:
16249 +               return 0;
16250 +       case S_IFCHR:
16251 +               return 1;
16252 +       default:
16253 +               BUG();
16254 +       }
16255 +}
16256 +
16257 +
16258 +/*     __set_default()
16259 + *     set a default
16260 + */
16261 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
16262 +       struct vx_dmap_target *vdmt)
16263 +{
16264 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16265 +       spin_lock(hash_lock);
16266 +
16267 +       if (vxi)
16268 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
16269 +       else
16270 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
16271 +
16272 +
16273 +       spin_unlock(hash_lock);
16274 +
16275 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
16276 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
16277 +}
16278 +
16279 +
16280 +/*     __remove_default()
16281 + *     remove a default
16282 + */
16283 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
16284 +{
16285 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16286 +       spin_lock(hash_lock);
16287 +
16288 +       if (vxi)
16289 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
16290 +       else    /* remove == reset */
16291 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
16292 +
16293 +       spin_unlock(hash_lock);
16294 +       return 0;
16295 +}
16296 +
16297 +
16298 +/*     __find_mapping()
16299 + *     find a mapping in the hash table
16300 + *
16301 + *     caller must hold hash_lock
16302 + */
16303 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
16304 +       struct vs_mapping **local, struct vs_mapping **global)
16305 +{
16306 +       struct hlist_head *hash = dmap_main_hash;
16307 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
16308 +       struct hlist_node *pos;
16309 +       struct vs_mapping *vdm;
16310 +
16311 +       *local = NULL;
16312 +       if (global)
16313 +               *global = NULL;
16314 +
16315 +       hlist_for_each(pos, head) {
16316 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
16317 +
16318 +               if ((vdm->device == device) &&
16319 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
16320 +                       if (vdm->xid == xid) {
16321 +                               *local = vdm;
16322 +                               return 1;
16323 +                       } else if (global && vdm->xid == 0)
16324 +                               *global = vdm;
16325 +               }
16326 +       }
16327 +
16328 +       if (global && *global)
16329 +               return 0;
16330 +       else
16331 +               return -ENOENT;
16332 +}
16333 +
16334 +
16335 +/*     __lookup_mapping()
16336 + *     find a mapping and store the result in target and flags
16337 + */
16338 +static inline int __lookup_mapping(struct vx_info *vxi,
16339 +       dev_t device, dev_t *target, int *flags, umode_t mode)
16340 +{
16341 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16342 +       struct vs_mapping *vdm, *global;
16343 +       struct vx_dmap_target *vdmt;
16344 +       int ret = 0;
16345 +       vxid_t xid = vxi->vx_id;
16346 +       int index;
16347 +
16348 +       spin_lock(hash_lock);
16349 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
16350 +               ret = 1;
16351 +               vdmt = &vdm->target;
16352 +               goto found;
16353 +       }
16354 +
16355 +       index = __mode_to_default(mode);
16356 +       if (vxi && vxi->dmap.targets[index].flags) {
16357 +               ret = 2;
16358 +               vdmt = &vxi->dmap.targets[index];
16359 +       } else if (global) {
16360 +               ret = 3;
16361 +               vdmt = &global->target;
16362 +               goto found;
16363 +       } else {
16364 +               ret = 4;
16365 +               vdmt = &dmap_defaults[index];
16366 +       }
16367 +
16368 +found:
16369 +       if (target && (vdmt->flags & DATTR_REMAP))
16370 +               *target = vdmt->target;
16371 +       else if (target)
16372 +               *target = device;
16373 +       if (flags)
16374 +               *flags = vdmt->flags;
16375 +
16376 +       spin_unlock(hash_lock);
16377 +
16378 +       return ret;
16379 +}
16380 +
16381 +
16382 +/*     __remove_mapping()
16383 + *     remove a mapping from the hash table
16384 + */
16385 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
16386 +       umode_t mode)
16387 +{
16388 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16389 +       struct vs_mapping *vdm = NULL;
16390 +       int ret = 0;
16391 +
16392 +       spin_lock(hash_lock);
16393 +
16394 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
16395 +               NULL);
16396 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
16397 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
16398 +       if (ret < 0)
16399 +               goto out;
16400 +       hlist_del(&vdm->dm_hlist);
16401 +
16402 +out:
16403 +       spin_unlock(hash_lock);
16404 +       if (vdm)
16405 +               kmem_cache_free(dmap_cachep, vdm);
16406 +       return ret;
16407 +}
16408 +
16409 +
16410 +
16411 +int vs_map_device(struct vx_info *vxi,
16412 +       dev_t device, dev_t *target, umode_t mode)
16413 +{
16414 +       int ret, flags = DATTR_MASK;
16415 +
16416 +       if (!vxi) {
16417 +               if (target)
16418 +                       *target = device;
16419 +               goto out;
16420 +       }
16421 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
16422 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
16423 +               device, target ? *target : 0, flags, mode, ret);
16424 +out:
16425 +       return (flags & DATTR_MASK);
16426 +}
16427 +
16428 +
16429 +
16430 +static int do_set_mapping(struct vx_info *vxi,
16431 +       dev_t device, dev_t target, int flags, umode_t mode)
16432 +{
16433 +       if (device) {
16434 +               struct vs_mapping *new;
16435 +
16436 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
16437 +               if (!new)
16438 +                       return -ENOMEM;
16439 +
16440 +               INIT_HLIST_NODE(&new->dm_hlist);
16441 +               new->device = device;
16442 +               new->target.target = target;
16443 +               new->target.flags = flags | mode;
16444 +               new->xid = (vxi ? vxi->vx_id : 0);
16445 +
16446 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
16447 +               __hash_mapping(vxi, new);
16448 +       } else {
16449 +               struct vx_dmap_target new = {
16450 +                       .target = target,
16451 +                       .flags = flags | mode,
16452 +               };
16453 +               __set_default(vxi, mode, &new);
16454 +       }
16455 +       return 0;
16456 +}
16457 +
16458 +
16459 +static int do_unset_mapping(struct vx_info *vxi,
16460 +       dev_t device, dev_t target, int flags, umode_t mode)
16461 +{
16462 +       int ret = -EINVAL;
16463 +
16464 +       if (device) {
16465 +               ret = __remove_mapping(vxi, device, mode);
16466 +               if (ret < 0)
16467 +                       goto out;
16468 +       } else {
16469 +               ret = __remove_default(vxi, mode);
16470 +               if (ret < 0)
16471 +                       goto out;
16472 +       }
16473 +
16474 +out:
16475 +       return ret;
16476 +}
16477 +
16478 +
16479 +static inline int __user_device(const char __user *name, dev_t *dev,
16480 +       umode_t *mode)
16481 +{
16482 +       struct path path;
16483 +       int ret;
16484 +
16485 +       if (!name) {
16486 +               *dev = 0;
16487 +               return 0;
16488 +       }
16489 +       ret = user_lpath(name, &path);
16490 +       if (ret)
16491 +               return ret;
16492 +       if (path.dentry->d_inode) {
16493 +               *dev = path.dentry->d_inode->i_rdev;
16494 +               *mode = path.dentry->d_inode->i_mode;
16495 +       }
16496 +       path_put(&path);
16497 +       return 0;
16498 +}
16499 +
16500 +static inline int __mapping_mode(dev_t device, dev_t target,
16501 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
16502 +{
16503 +       if (device)
16504 +               *mode = device_mode & S_IFMT;
16505 +       else if (target)
16506 +               *mode = target_mode & S_IFMT;
16507 +       else
16508 +               return -EINVAL;
16509 +
16510 +       /* if both given, device and target mode have to match */
16511 +       if (device && target &&
16512 +               ((device_mode ^ target_mode) & S_IFMT))
16513 +               return -EINVAL;
16514 +       return 0;
16515 +}
16516 +
16517 +
16518 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
16519 +       const char __user *target_path, int flags, int set)
16520 +{
16521 +       dev_t device = ~0, target = ~0;
16522 +       umode_t device_mode = 0, target_mode = 0, mode;
16523 +       int ret;
16524 +
16525 +       ret = __user_device(device_path, &device, &device_mode);
16526 +       if (ret)
16527 +               return ret;
16528 +       ret = __user_device(target_path, &target, &target_mode);
16529 +       if (ret)
16530 +               return ret;
16531 +
16532 +       ret = __mapping_mode(device, target,
16533 +               device_mode, target_mode, &mode);
16534 +       if (ret)
16535 +               return ret;
16536 +
16537 +       if (set)
16538 +               return do_set_mapping(vxi, device, target,
16539 +                       flags, mode);
16540 +       else
16541 +               return do_unset_mapping(vxi, device, target,
16542 +                       flags, mode);
16543 +}
16544 +
16545 +
16546 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
16547 +{
16548 +       struct vcmd_set_mapping_v0 vc_data;
16549 +
16550 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16551 +               return -EFAULT;
16552 +
16553 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16554 +               vc_data.flags, 1);
16555 +}
16556 +
16557 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
16558 +{
16559 +       struct vcmd_set_mapping_v0 vc_data;
16560 +
16561 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16562 +               return -EFAULT;
16563 +
16564 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16565 +               vc_data.flags, 0);
16566 +}
16567 +
16568 +
16569 +#ifdef CONFIG_COMPAT
16570 +
16571 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
16572 +{
16573 +       struct vcmd_set_mapping_v0_x32 vc_data;
16574 +
16575 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16576 +               return -EFAULT;
16577 +
16578 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16579 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
16580 +}
16581 +
16582 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
16583 +{
16584 +       struct vcmd_set_mapping_v0_x32 vc_data;
16585 +
16586 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16587 +               return -EFAULT;
16588 +
16589 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16590 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
16591 +}
16592 +
16593 +#endif /* CONFIG_COMPAT */
16594 +
16595 +
16596 diff -NurpP --minimal linux-4.4.110/kernel/vserver/dlimit.c linux-4.4.110-vs2.3.9/kernel/vserver/dlimit.c
16597 --- linux-4.4.110/kernel/vserver/dlimit.c       1970-01-01 00:00:00.000000000 +0000
16598 +++ linux-4.4.110-vs2.3.9/kernel/vserver/dlimit.c       2018-01-09 16:36:34.000000000 +0000
16599 @@ -0,0 +1,528 @@
16600 +/*
16601 + *  linux/kernel/vserver/dlimit.c
16602 + *
16603 + *  Virtual Server: Context Disk Limits
16604 + *
16605 + *  Copyright (C) 2004-2009  Herbert P?tzl
16606 + *
16607 + *  V0.01  initial version
16608 + *  V0.02  compat32 splitup
16609 + *  V0.03  extended interface
16610 + *
16611 + */
16612 +
16613 +#include <linux/statfs.h>
16614 +#include <linux/sched.h>
16615 +#include <linux/namei.h>
16616 +#include <linux/vs_tag.h>
16617 +#include <linux/vs_dlimit.h>
16618 +#include <linux/vserver/dlimit_cmd.h>
16619 +#include <linux/slab.h>
16620 +// #include <linux/gfp.h>
16621 +
16622 +#include <asm/uaccess.h>
16623 +
16624 +/*     __alloc_dl_info()
16625 +
16626 +       * allocate an initialized dl_info struct
16627 +       * doesn't make it visible (hash)                        */
16628 +
16629 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
16630 +{
16631 +       struct dl_info *new = NULL;
16632 +
16633 +       vxdprintk(VXD_CBIT(dlim, 5),
16634 +               "alloc_dl_info(%p,%d)*", sb, tag);
16635 +
16636 +       /* would this benefit from a slab cache? */
16637 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
16638 +       if (!new)
16639 +               return 0;
16640 +
16641 +       memset(new, 0, sizeof(struct dl_info));
16642 +       new->dl_tag = tag;
16643 +       new->dl_sb = sb;
16644 +       // INIT_RCU_HEAD(&new->dl_rcu);
16645 +       INIT_HLIST_NODE(&new->dl_hlist);
16646 +       spin_lock_init(&new->dl_lock);
16647 +       atomic_set(&new->dl_refcnt, 0);
16648 +       atomic_set(&new->dl_usecnt, 0);
16649 +
16650 +       /* rest of init goes here */
16651 +
16652 +       vxdprintk(VXD_CBIT(dlim, 4),
16653 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
16654 +       return new;
16655 +}
16656 +
16657 +/*     __dealloc_dl_info()
16658 +
16659 +       * final disposal of dl_info                             */
16660 +
16661 +static void __dealloc_dl_info(struct dl_info *dli)
16662 +{
16663 +       vxdprintk(VXD_CBIT(dlim, 4),
16664 +               "dealloc_dl_info(%p)", dli);
16665 +
16666 +       dli->dl_hlist.next = LIST_POISON1;
16667 +       dli->dl_tag = -1;
16668 +       dli->dl_sb = 0;
16669 +
16670 +       BUG_ON(atomic_read(&dli->dl_usecnt));
16671 +       BUG_ON(atomic_read(&dli->dl_refcnt));
16672 +
16673 +       kfree(dli);
16674 +}
16675 +
16676 +
16677 +/*     hash table for dl_info hash */
16678 +
16679 +#define DL_HASH_SIZE   13
16680 +
16681 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
16682 +
16683 +static DEFINE_SPINLOCK(dl_info_hash_lock);
16684 +
16685 +
16686 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
16687 +{
16688 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
16689 +}
16690 +
16691 +
16692 +
16693 +/*     __hash_dl_info()
16694 +
16695 +       * add the dli to the global hash table
16696 +       * requires the hash_lock to be held                     */
16697 +
16698 +static inline void __hash_dl_info(struct dl_info *dli)
16699 +{
16700 +       struct hlist_head *head;
16701 +
16702 +       vxdprintk(VXD_CBIT(dlim, 6),
16703 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
16704 +       get_dl_info(dli);
16705 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
16706 +       hlist_add_head_rcu(&dli->dl_hlist, head);
16707 +}
16708 +
16709 +/*     __unhash_dl_info()
16710 +
16711 +       * remove the dli from the global hash table
16712 +       * requires the hash_lock to be held                     */
16713 +
16714 +static inline void __unhash_dl_info(struct dl_info *dli)
16715 +{
16716 +       vxdprintk(VXD_CBIT(dlim, 6),
16717 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
16718 +       hlist_del_rcu(&dli->dl_hlist);
16719 +       put_dl_info(dli);
16720 +}
16721 +
16722 +
16723 +/*     __lookup_dl_info()
16724 +
16725 +       * requires the rcu_read_lock()
16726 +       * doesn't increment the dl_refcnt                       */
16727 +
16728 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
16729 +{
16730 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
16731 +       struct dl_info *dli;
16732 +
16733 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
16734 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
16735 +                       return dli;
16736 +       }
16737 +       return NULL;
16738 +}
16739 +
16740 +
16741 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
16742 +{
16743 +       struct dl_info *dli;
16744 +
16745 +       rcu_read_lock();
16746 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
16747 +       vxdprintk(VXD_CBIT(dlim, 7),
16748 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
16749 +       rcu_read_unlock();
16750 +       return dli;
16751 +}
16752 +
16753 +void rcu_free_dl_info(struct rcu_head *head)
16754 +{
16755 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
16756 +       int usecnt, refcnt;
16757 +
16758 +       BUG_ON(!dli || !head);
16759 +
16760 +       usecnt = atomic_read(&dli->dl_usecnt);
16761 +       BUG_ON(usecnt < 0);
16762 +
16763 +       refcnt = atomic_read(&dli->dl_refcnt);
16764 +       BUG_ON(refcnt < 0);
16765 +
16766 +       vxdprintk(VXD_CBIT(dlim, 3),
16767 +               "rcu_free_dl_info(%p)", dli);
16768 +       if (!usecnt)
16769 +               __dealloc_dl_info(dli);
16770 +       else
16771 +               printk("!!! rcu didn't free\n");
16772 +}
16773 +
16774 +
16775 +
16776 +
16777 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
16778 +       uint32_t flags, int add)
16779 +{
16780 +       struct path path;
16781 +       int ret;
16782 +
16783 +       ret = user_lpath(name, &path);
16784 +       if (!ret) {
16785 +               struct super_block *sb;
16786 +               struct dl_info *dli;
16787 +
16788 +               ret = -EINVAL;
16789 +               if (!path.dentry->d_inode)
16790 +                       goto out_release;
16791 +               if (!(sb = path.dentry->d_inode->i_sb))
16792 +                       goto out_release;
16793 +
16794 +               if (add) {
16795 +                       dli = __alloc_dl_info(sb, id);
16796 +                       spin_lock(&dl_info_hash_lock);
16797 +
16798 +                       ret = -EEXIST;
16799 +                       if (__lookup_dl_info(sb, id))
16800 +                               goto out_unlock;
16801 +                       __hash_dl_info(dli);
16802 +                       dli = NULL;
16803 +               } else {
16804 +                       spin_lock(&dl_info_hash_lock);
16805 +                       dli = __lookup_dl_info(sb, id);
16806 +
16807 +                       ret = -ESRCH;
16808 +                       if (!dli)
16809 +                               goto out_unlock;
16810 +                       __unhash_dl_info(dli);
16811 +               }
16812 +               ret = 0;
16813 +       out_unlock:
16814 +               spin_unlock(&dl_info_hash_lock);
16815 +               if (add && dli)
16816 +                       __dealloc_dl_info(dli);
16817 +       out_release:
16818 +               path_put(&path);
16819 +       }
16820 +       return ret;
16821 +}
16822 +
16823 +int vc_add_dlimit(uint32_t id, void __user *data)
16824 +{
16825 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
16826 +
16827 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16828 +               return -EFAULT;
16829 +
16830 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
16831 +}
16832 +
16833 +int vc_rem_dlimit(uint32_t id, void __user *data)
16834 +{
16835 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
16836 +
16837 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16838 +               return -EFAULT;
16839 +
16840 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
16841 +}
16842 +
16843 +#ifdef CONFIG_COMPAT
16844 +
16845 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
16846 +{
16847 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
16848 +
16849 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16850 +               return -EFAULT;
16851 +
16852 +       return do_addrem_dlimit(id,
16853 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
16854 +}
16855 +
16856 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
16857 +{
16858 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
16859 +
16860 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16861 +               return -EFAULT;
16862 +
16863 +       return do_addrem_dlimit(id,
16864 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
16865 +}
16866 +
16867 +#endif /* CONFIG_COMPAT */
16868 +
16869 +
16870 +static inline
16871 +int do_set_dlimit(uint32_t id, const char __user *name,
16872 +       uint32_t space_used, uint32_t space_total,
16873 +       uint32_t inodes_used, uint32_t inodes_total,
16874 +       uint32_t reserved, uint32_t flags)
16875 +{
16876 +       struct path path;
16877 +       int ret;
16878 +
16879 +       ret = user_lpath(name, &path);
16880 +       if (!ret) {
16881 +               struct super_block *sb;
16882 +               struct dl_info *dli;
16883 +
16884 +               ret = -EINVAL;
16885 +               if (!path.dentry->d_inode)
16886 +                       goto out_release;
16887 +               if (!(sb = path.dentry->d_inode->i_sb))
16888 +                       goto out_release;
16889 +
16890 +               /* sanity checks */
16891 +               if ((reserved != CDLIM_KEEP &&
16892 +                       reserved > 100) ||
16893 +                       (inodes_used != CDLIM_KEEP &&
16894 +                       inodes_used > inodes_total) ||
16895 +                       (space_used != CDLIM_KEEP &&
16896 +                       space_used > space_total))
16897 +                       goto out_release;
16898 +
16899 +               ret = -ESRCH;
16900 +               dli = locate_dl_info(sb, id);
16901 +               if (!dli)
16902 +                       goto out_release;
16903 +
16904 +               spin_lock(&dli->dl_lock);
16905 +
16906 +               if (inodes_used != CDLIM_KEEP)
16907 +                       dli->dl_inodes_used = inodes_used;
16908 +               if (inodes_total != CDLIM_KEEP)
16909 +                       dli->dl_inodes_total = inodes_total;
16910 +               if (space_used != CDLIM_KEEP)
16911 +                       dli->dl_space_used = dlimit_space_32to64(
16912 +                               space_used, flags, DLIMS_USED);
16913 +
16914 +               if (space_total == CDLIM_INFINITY)
16915 +                       dli->dl_space_total = DLIM_INFINITY;
16916 +               else if (space_total != CDLIM_KEEP)
16917 +                       dli->dl_space_total = dlimit_space_32to64(
16918 +                               space_total, flags, DLIMS_TOTAL);
16919 +
16920 +               if (reserved != CDLIM_KEEP)
16921 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
16922 +
16923 +               spin_unlock(&dli->dl_lock);
16924 +
16925 +               put_dl_info(dli);
16926 +               ret = 0;
16927 +
16928 +       out_release:
16929 +               path_put(&path);
16930 +       }
16931 +       return ret;
16932 +}
16933 +
16934 +int vc_set_dlimit(uint32_t id, void __user *data)
16935 +{
16936 +       struct vcmd_ctx_dlimit_v0 vc_data;
16937 +
16938 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16939 +               return -EFAULT;
16940 +
16941 +       return do_set_dlimit(id, vc_data.name,
16942 +               vc_data.space_used, vc_data.space_total,
16943 +               vc_data.inodes_used, vc_data.inodes_total,
16944 +               vc_data.reserved, vc_data.flags);
16945 +}
16946 +
16947 +#ifdef CONFIG_COMPAT
16948 +
16949 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
16950 +{
16951 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
16952 +
16953 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16954 +               return -EFAULT;
16955 +
16956 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
16957 +               vc_data.space_used, vc_data.space_total,
16958 +               vc_data.inodes_used, vc_data.inodes_total,
16959 +               vc_data.reserved, vc_data.flags);
16960 +}
16961 +
16962 +#endif /* CONFIG_COMPAT */
16963 +
16964 +
16965 +static inline
16966 +int do_get_dlimit(uint32_t id, const char __user *name,
16967 +       uint32_t *space_used, uint32_t *space_total,
16968 +       uint32_t *inodes_used, uint32_t *inodes_total,
16969 +       uint32_t *reserved, uint32_t *flags)
16970 +{
16971 +       struct path path;
16972 +       int ret;
16973 +
16974 +       ret = user_lpath(name, &path);
16975 +       if (!ret) {
16976 +               struct super_block *sb;
16977 +               struct dl_info *dli;
16978 +
16979 +               ret = -EINVAL;
16980 +               if (!path.dentry->d_inode)
16981 +                       goto out_release;
16982 +               if (!(sb = path.dentry->d_inode->i_sb))
16983 +                       goto out_release;
16984 +
16985 +               ret = -ESRCH;
16986 +               dli = locate_dl_info(sb, id);
16987 +               if (!dli)
16988 +                       goto out_release;
16989 +
16990 +               spin_lock(&dli->dl_lock);
16991 +               *inodes_used = dli->dl_inodes_used;
16992 +               *inodes_total = dli->dl_inodes_total;
16993 +
16994 +               *space_used = dlimit_space_64to32(
16995 +                       dli->dl_space_used, flags, DLIMS_USED);
16996 +
16997 +               if (dli->dl_space_total == DLIM_INFINITY)
16998 +                       *space_total = CDLIM_INFINITY;
16999 +               else
17000 +                       *space_total = dlimit_space_64to32(
17001 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
17002 +
17003 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
17004 +               spin_unlock(&dli->dl_lock);
17005 +
17006 +               put_dl_info(dli);
17007 +               ret = -EFAULT;
17008 +
17009 +               ret = 0;
17010 +       out_release:
17011 +               path_put(&path);
17012 +       }
17013 +       return ret;
17014 +}
17015 +
17016 +
17017 +int vc_get_dlimit(uint32_t id, void __user *data)
17018 +{
17019 +       struct vcmd_ctx_dlimit_v0 vc_data;
17020 +       int ret;
17021 +
17022 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17023 +               return -EFAULT;
17024 +
17025 +       ret = do_get_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);
17029 +       if (ret)
17030 +               return ret;
17031 +
17032 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17033 +               return -EFAULT;
17034 +       return 0;
17035 +}
17036 +
17037 +#ifdef CONFIG_COMPAT
17038 +
17039 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
17040 +{
17041 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17042 +       int ret;
17043 +
17044 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17045 +               return -EFAULT;
17046 +
17047 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
17048 +               &vc_data.space_used, &vc_data.space_total,
17049 +               &vc_data.inodes_used, &vc_data.inodes_total,
17050 +               &vc_data.reserved, &vc_data.flags);
17051 +       if (ret)
17052 +               return ret;
17053 +
17054 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17055 +               return -EFAULT;
17056 +       return 0;
17057 +}
17058 +
17059 +#endif /* CONFIG_COMPAT */
17060 +
17061 +
17062 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
17063 +{
17064 +       struct dl_info *dli;
17065 +       __u64 blimit, bfree, bavail;
17066 +       __u32 ifree;
17067 +
17068 +       dli = locate_dl_info(sb, dx_current_tag());
17069 +       if (!dli)
17070 +               return;
17071 +
17072 +       spin_lock(&dli->dl_lock);
17073 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
17074 +               goto no_ilim;
17075 +
17076 +       /* reduce max inodes available to limit */
17077 +       if (buf->f_files > dli->dl_inodes_total)
17078 +               buf->f_files = dli->dl_inodes_total;
17079 +
17080 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
17081 +       /* reduce free inodes to min */
17082 +       if (ifree < buf->f_ffree)
17083 +               buf->f_ffree = ifree;
17084 +
17085 +no_ilim:
17086 +       if (dli->dl_space_total == DLIM_INFINITY)
17087 +               goto no_blim;
17088 +
17089 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
17090 +
17091 +       if (dli->dl_space_total < dli->dl_space_used)
17092 +               bfree = 0;
17093 +       else
17094 +               bfree = (dli->dl_space_total - dli->dl_space_used)
17095 +                       >> sb->s_blocksize_bits;
17096 +
17097 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
17098 +       if (bavail < dli->dl_space_used)
17099 +               bavail = 0;
17100 +       else
17101 +               bavail = (bavail - dli->dl_space_used)
17102 +                       >> sb->s_blocksize_bits;
17103 +
17104 +       /* reduce max space available to limit */
17105 +       if (buf->f_blocks > blimit)
17106 +               buf->f_blocks = blimit;
17107 +
17108 +       /* reduce free space to min */
17109 +       if (bfree < buf->f_bfree)
17110 +               buf->f_bfree = bfree;
17111 +
17112 +       /* reduce avail space to min */
17113 +       if (bavail < buf->f_bavail)
17114 +               buf->f_bavail = bavail;
17115 +
17116 +no_blim:
17117 +       spin_unlock(&dli->dl_lock);
17118 +       put_dl_info(dli);
17119 +
17120 +       return;
17121 +}
17122 +
17123 +#include <linux/module.h>
17124 +
17125 +EXPORT_SYMBOL_GPL(locate_dl_info);
17126 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
17127 +
17128 diff -NurpP --minimal linux-4.4.110/kernel/vserver/helper.c linux-4.4.110-vs2.3.9/kernel/vserver/helper.c
17129 --- linux-4.4.110/kernel/vserver/helper.c       1970-01-01 00:00:00.000000000 +0000
17130 +++ linux-4.4.110-vs2.3.9/kernel/vserver/helper.c       2018-01-09 16:36:34.000000000 +0000
17131 @@ -0,0 +1,242 @@
17132 +/*
17133 + *  linux/kernel/vserver/helper.c
17134 + *
17135 + *  Virtual Context Support
17136 + *
17137 + *  Copyright (C) 2004-2007  Herbert P?tzl
17138 + *
17139 + *  V0.01  basic helper
17140 + *
17141 + */
17142 +
17143 +#include <linux/kmod.h>
17144 +#include <linux/reboot.h>
17145 +#include <linux/vs_context.h>
17146 +#include <linux/vs_network.h>
17147 +#include <linux/vserver/signal.h>
17148 +
17149 +
17150 +char vshelper_path[255] = "/sbin/vshelper";
17151 +
17152 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
17153 +{
17154 +       current->flags &= ~PF_NO_SETAFFINITY;
17155 +       return 0;
17156 +}
17157 +
17158 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
17159 +{
17160 +       struct subprocess_info *info;
17161 +       gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
17162 +
17163 +       info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
17164 +                                        vshelper_init, NULL, NULL);
17165 +       if (info == NULL)
17166 +               return -ENOMEM;
17167 +
17168 +       return call_usermodehelper_exec(info, wait);
17169 +}
17170 +
17171 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
17172 +{
17173 +       int ret;
17174 +
17175 +       if ((ret = vs_call_usermodehelper(name, argv, envp,
17176 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
17177 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
17178 +                       name, argv[1], argv[2],
17179 +                       sync ? "sync" : "async", ret);
17180 +       }
17181 +       vxdprintk(VXD_CBIT(switch, 4),
17182 +               "%s: (%s %s) returned %s with %d",
17183 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
17184 +       return ret;
17185 +}
17186 +
17187 +/*
17188 + *      vshelper path is set via /proc/sys
17189 + *      invoked by vserver sys_reboot(), with
17190 + *      the following arguments
17191 + *
17192 + *      argv [0] = vshelper_path;
17193 + *      argv [1] = action: "restart", "halt", "poweroff", ...
17194 + *      argv [2] = context identifier
17195 + *
17196 + *      envp [*] = type-specific parameters
17197 + */
17198 +
17199 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
17200 +{
17201 +       char id_buf[8], cmd_buf[16];
17202 +       char uid_buf[16], pid_buf[16];
17203 +       int ret;
17204 +
17205 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17206 +       char *envp[] = {"HOME=/", "TERM=linux",
17207 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
17208 +                       uid_buf, pid_buf, cmd_buf, 0};
17209 +
17210 +       if (vx_info_state(vxi, VXS_HELPER))
17211 +               return -EAGAIN;
17212 +       vxi->vx_state |= VXS_HELPER;
17213 +
17214 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17215 +
17216 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17217 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
17218 +               from_kuid(&init_user_ns, current_uid()));
17219 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
17220 +
17221 +       switch (cmd) {
17222 +       case LINUX_REBOOT_CMD_RESTART:
17223 +               argv[1] = "restart";
17224 +               break;
17225 +
17226 +       case LINUX_REBOOT_CMD_HALT:
17227 +               argv[1] = "halt";
17228 +               break;
17229 +
17230 +       case LINUX_REBOOT_CMD_POWER_OFF:
17231 +               argv[1] = "poweroff";
17232 +               break;
17233 +
17234 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
17235 +               argv[1] = "swsusp";
17236 +               break;
17237 +
17238 +       case LINUX_REBOOT_CMD_OOM:
17239 +               argv[1] = "oom";
17240 +               break;
17241 +
17242 +       default:
17243 +               vxi->vx_state &= ~VXS_HELPER;
17244 +               return 0;
17245 +       }
17246 +
17247 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
17248 +       vxi->vx_state &= ~VXS_HELPER;
17249 +       __wakeup_vx_info(vxi);
17250 +       return (ret) ? -EPERM : 0;
17251 +}
17252 +
17253 +
17254 +long vs_reboot(unsigned int cmd, void __user *arg)
17255 +{
17256 +       struct vx_info *vxi = current_vx_info();
17257 +       long ret = 0;
17258 +
17259 +       vxdprintk(VXD_CBIT(misc, 5),
17260 +               "vs_reboot(%p[#%d],%u)",
17261 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17262 +
17263 +       ret = vs_reboot_helper(vxi, cmd, arg);
17264 +       if (ret)
17265 +               return ret;
17266 +
17267 +       vxi->reboot_cmd = cmd;
17268 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17269 +               switch (cmd) {
17270 +               case LINUX_REBOOT_CMD_RESTART:
17271 +               case LINUX_REBOOT_CMD_HALT:
17272 +               case LINUX_REBOOT_CMD_POWER_OFF:
17273 +                       vx_info_kill(vxi, 0, SIGKILL);
17274 +                       vx_info_kill(vxi, 1, SIGKILL);
17275 +               default:
17276 +                       break;
17277 +               }
17278 +       }
17279 +       return 0;
17280 +}
17281 +
17282 +long vs_oom_action(unsigned int cmd)
17283 +{
17284 +       struct vx_info *vxi = current_vx_info();
17285 +       long ret = 0;
17286 +
17287 +       vxdprintk(VXD_CBIT(misc, 5),
17288 +               "vs_oom_action(%p[#%d],%u)",
17289 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17290 +
17291 +       ret = vs_reboot_helper(vxi, cmd, NULL);
17292 +       if (ret)
17293 +               return ret;
17294 +
17295 +       vxi->reboot_cmd = cmd;
17296 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17297 +               vx_info_kill(vxi, 0, SIGKILL);
17298 +               vx_info_kill(vxi, 1, SIGKILL);
17299 +       }
17300 +       return 0;
17301 +}
17302 +
17303 +/*
17304 + *      argv [0] = vshelper_path;
17305 + *      argv [1] = action: "startup", "shutdown"
17306 + *      argv [2] = context identifier
17307 + *
17308 + *      envp [*] = type-specific parameters
17309 + */
17310 +
17311 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
17312 +{
17313 +       char id_buf[8], cmd_buf[16];
17314 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17315 +       char *envp[] = {"HOME=/", "TERM=linux",
17316 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17317 +
17318 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
17319 +               return 0;
17320 +
17321 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17322 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17323 +
17324 +       switch (cmd) {
17325 +       case VSC_STARTUP:
17326 +               argv[1] = "startup";
17327 +               break;
17328 +       case VSC_SHUTDOWN:
17329 +               argv[1] = "shutdown";
17330 +               break;
17331 +       default:
17332 +               return 0;
17333 +       }
17334 +
17335 +       return do_vshelper(vshelper_path, argv, envp, 1);
17336 +}
17337 +
17338 +
17339 +/*
17340 + *      argv [0] = vshelper_path;
17341 + *      argv [1] = action: "netup", "netdown"
17342 + *      argv [2] = context identifier
17343 + *
17344 + *      envp [*] = type-specific parameters
17345 + */
17346 +
17347 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
17348 +{
17349 +       char id_buf[8], cmd_buf[16];
17350 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17351 +       char *envp[] = {"HOME=/", "TERM=linux",
17352 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17353 +
17354 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
17355 +               return 0;
17356 +
17357 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
17358 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17359 +
17360 +       switch (cmd) {
17361 +       case VSC_NETUP:
17362 +               argv[1] = "netup";
17363 +               break;
17364 +       case VSC_NETDOWN:
17365 +               argv[1] = "netdown";
17366 +               break;
17367 +       default:
17368 +               return 0;
17369 +       }
17370 +
17371 +       return do_vshelper(vshelper_path, argv, envp, 1);
17372 +}
17373 +
17374 diff -NurpP --minimal linux-4.4.110/kernel/vserver/history.c linux-4.4.110-vs2.3.9/kernel/vserver/history.c
17375 --- linux-4.4.110/kernel/vserver/history.c      1970-01-01 00:00:00.000000000 +0000
17376 +++ linux-4.4.110-vs2.3.9/kernel/vserver/history.c      2018-01-09 16:36:34.000000000 +0000
17377 @@ -0,0 +1,258 @@
17378 +/*
17379 + *  kernel/vserver/history.c
17380 + *
17381 + *  Virtual Context History Backtrace
17382 + *
17383 + *  Copyright (C) 2004-2007  Herbert P?tzl
17384 + *
17385 + *  V0.01  basic structure
17386 + *  V0.02  hash/unhash and trace
17387 + *  V0.03  preemption fixes
17388 + *
17389 + */
17390 +
17391 +#include <linux/module.h>
17392 +#include <asm/uaccess.h>
17393 +
17394 +#include <linux/vserver/context.h>
17395 +#include <linux/vserver/debug.h>
17396 +#include <linux/vserver/debug_cmd.h>
17397 +#include <linux/vserver/history.h>
17398 +
17399 +
17400 +#ifdef CONFIG_VSERVER_HISTORY
17401 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
17402 +#else
17403 +#define VXH_SIZE       64
17404 +#endif
17405 +
17406 +struct _vx_history {
17407 +       unsigned int counter;
17408 +
17409 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
17410 +};
17411 +
17412 +
17413 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
17414 +
17415 +unsigned volatile int vxh_active = 1;
17416 +
17417 +static atomic_t sequence = ATOMIC_INIT(0);
17418 +
17419 +
17420 +/*     vxh_advance()
17421 +
17422 +       * requires disabled preemption                          */
17423 +
17424 +struct _vx_hist_entry *vxh_advance(void *loc)
17425 +{
17426 +       unsigned int cpu = smp_processor_id();
17427 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17428 +       struct _vx_hist_entry *entry;
17429 +       unsigned int index;
17430 +
17431 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
17432 +       entry = &hist->entry[index];
17433 +
17434 +       entry->seq = atomic_inc_return(&sequence);
17435 +       entry->loc = loc;
17436 +       return entry;
17437 +}
17438 +
17439 +EXPORT_SYMBOL_GPL(vxh_advance);
17440 +
17441 +
17442 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
17443 +
17444 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
17445 +
17446 +
17447 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
17448 +
17449 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
17450 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
17451 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
17452 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
17453 +
17454 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
17455 +{
17456 +       switch (e->type) {
17457 +       case VXH_THROW_OOPS:
17458 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
17459 +               break;
17460 +
17461 +       case VXH_GET_VX_INFO:
17462 +       case VXH_PUT_VX_INFO:
17463 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17464 +                       VXH_LOC_ARGS(e),
17465 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
17466 +                       VXH_VXI_ARGS(e));
17467 +               break;
17468 +
17469 +       case VXH_INIT_VX_INFO:
17470 +       case VXH_SET_VX_INFO:
17471 +       case VXH_CLR_VX_INFO:
17472 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17473 +                       VXH_LOC_ARGS(e),
17474 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
17475 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
17476 +                       VXH_VXI_ARGS(e), e->sc.data);
17477 +               break;
17478 +
17479 +       case VXH_CLAIM_VX_INFO:
17480 +       case VXH_RELEASE_VX_INFO:
17481 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17482 +                       VXH_LOC_ARGS(e),
17483 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
17484 +                       VXH_VXI_ARGS(e), e->sc.data);
17485 +               break;
17486 +
17487 +       case VXH_ALLOC_VX_INFO:
17488 +       case VXH_DEALLOC_VX_INFO:
17489 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17490 +                       VXH_LOC_ARGS(e),
17491 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
17492 +                       VXH_VXI_ARGS(e));
17493 +               break;
17494 +
17495 +       case VXH_HASH_VX_INFO:
17496 +       case VXH_UNHASH_VX_INFO:
17497 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
17498 +                       VXH_LOC_ARGS(e),
17499 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
17500 +                       VXH_VXI_ARGS(e));
17501 +               break;
17502 +
17503 +       case VXH_LOC_VX_INFO:
17504 +       case VXH_LOOKUP_VX_INFO:
17505 +       case VXH_CREATE_VX_INFO:
17506 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
17507 +                       VXH_LOC_ARGS(e),
17508 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
17509 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
17510 +                       e->ll.arg, VXH_VXI_ARGS(e));
17511 +               break;
17512 +       }
17513 +}
17514 +
17515 +static void __vxh_dump_history(void)
17516 +{
17517 +       unsigned int i, cpu;
17518 +
17519 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
17520 +               atomic_read(&sequence), NR_CPUS);
17521 +
17522 +       for (i = 0; i < VXH_SIZE; i++) {
17523 +               for_each_online_cpu(cpu) {
17524 +                       struct _vx_history *hist =
17525 +                               &per_cpu(vx_history_buffer, cpu);
17526 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
17527 +                       struct _vx_hist_entry *entry = &hist->entry[index];
17528 +
17529 +                       vxh_dump_entry(entry, cpu);
17530 +               }
17531 +       }
17532 +}
17533 +
17534 +void   vxh_dump_history(void)
17535 +{
17536 +       vxh_active = 0;
17537 +#ifdef CONFIG_SMP
17538 +       local_irq_enable();
17539 +       smp_send_stop();
17540 +       local_irq_disable();
17541 +#endif
17542 +       __vxh_dump_history();
17543 +}
17544 +
17545 +
17546 +/* vserver syscall commands below here */
17547 +
17548 +
17549 +int vc_dump_history(uint32_t id)
17550 +{
17551 +       vxh_active = 0;
17552 +       __vxh_dump_history();
17553 +       vxh_active = 1;
17554 +
17555 +       return 0;
17556 +}
17557 +
17558 +
17559 +int do_read_history(struct __user _vx_hist_entry *data,
17560 +       int cpu, uint32_t *index, uint32_t *count)
17561 +{
17562 +       int pos, ret = 0;
17563 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17564 +       int end = hist->counter;
17565 +       int start = end - VXH_SIZE + 2;
17566 +       int idx = *index;
17567 +
17568 +       /* special case: get current pos */
17569 +       if (!*count) {
17570 +               *index = end;
17571 +               return 0;
17572 +       }
17573 +
17574 +       /* have we lost some data? */
17575 +       if (idx < start)
17576 +               idx = start;
17577 +
17578 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
17579 +               struct _vx_hist_entry *entry =
17580 +                       &hist->entry[idx % VXH_SIZE];
17581 +
17582 +               /* send entry to userspace */
17583 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
17584 +               if (ret)
17585 +                       break;
17586 +       }
17587 +       /* save new index and count */
17588 +       *index = idx;
17589 +       *count = pos;
17590 +       return ret ? ret : (*index < end);
17591 +}
17592 +
17593 +int vc_read_history(uint32_t id, void __user *data)
17594 +{
17595 +       struct vcmd_read_history_v0 vc_data;
17596 +       int ret;
17597 +
17598 +       if (id >= NR_CPUS)
17599 +               return -EINVAL;
17600 +
17601 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17602 +               return -EFAULT;
17603 +
17604 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
17605 +               id, &vc_data.index, &vc_data.count);
17606 +
17607 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17608 +               return -EFAULT;
17609 +       return ret;
17610 +}
17611 +
17612 +#ifdef CONFIG_COMPAT
17613 +
17614 +int vc_read_history_x32(uint32_t id, void __user *data)
17615 +{
17616 +       struct vcmd_read_history_v0_x32 vc_data;
17617 +       int ret;
17618 +
17619 +       if (id >= NR_CPUS)
17620 +               return -EINVAL;
17621 +
17622 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17623 +               return -EFAULT;
17624 +
17625 +       ret = do_read_history((struct __user _vx_hist_entry *)
17626 +               compat_ptr(vc_data.data_ptr),
17627 +               id, &vc_data.index, &vc_data.count);
17628 +
17629 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17630 +               return -EFAULT;
17631 +       return ret;
17632 +}
17633 +
17634 +#endif /* CONFIG_COMPAT */
17635 +
17636 diff -NurpP --minimal linux-4.4.110/kernel/vserver/inet.c linux-4.4.110-vs2.3.9/kernel/vserver/inet.c
17637 --- linux-4.4.110/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
17638 +++ linux-4.4.110-vs2.3.9/kernel/vserver/inet.c 2018-01-09 16:36:34.000000000 +0000
17639 @@ -0,0 +1,236 @@
17640 +
17641 +#include <linux/in.h>
17642 +#include <linux/inetdevice.h>
17643 +#include <linux/export.h>
17644 +#include <linux/vs_inet.h>
17645 +#include <linux/vs_inet6.h>
17646 +#include <linux/vserver/debug.h>
17647 +#include <net/route.h>
17648 +#include <net/addrconf.h>
17649 +
17650 +
17651 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17652 +{
17653 +       int ret = 0;
17654 +
17655 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
17656 +               ret = 1;
17657 +       else {
17658 +               struct nx_addr_v4 *ptr;
17659 +               unsigned long irqflags;
17660 +
17661 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
17662 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
17663 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
17664 +                               ret = 1;
17665 +                               break;
17666 +                       }
17667 +               }
17668 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
17669 +       }
17670 +
17671 +       vxdprintk(VXD_CBIT(net, 2),
17672 +               "nx_v4_addr_conflict(%p,%p): %d",
17673 +               nxi1, nxi2, ret);
17674 +
17675 +       return ret;
17676 +}
17677 +
17678 +
17679 +#ifdef CONFIG_IPV6
17680 +
17681 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17682 +{
17683 +       int ret = 0;
17684 +
17685 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
17686 +               ret = 1;
17687 +       else {
17688 +               struct nx_addr_v6 *ptr;
17689 +               unsigned long irqflags;
17690 +
17691 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
17692 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
17693 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
17694 +                               ret = 1;
17695 +                               break;
17696 +                       }
17697 +               }
17698 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
17699 +       }
17700 +
17701 +       vxdprintk(VXD_CBIT(net, 2),
17702 +               "nx_v6_addr_conflict(%p,%p): %d",
17703 +               nxi1, nxi2, ret);
17704 +
17705 +       return ret;
17706 +}
17707 +
17708 +#endif
17709 +
17710 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
17711 +{
17712 +       struct in_device *in_dev;
17713 +       struct in_ifaddr **ifap;
17714 +       struct in_ifaddr *ifa;
17715 +       int ret = 0;
17716 +
17717 +       if (!dev)
17718 +               goto out;
17719 +       in_dev = in_dev_get(dev);
17720 +       if (!in_dev)
17721 +               goto out;
17722 +
17723 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
17724 +               ifap = &ifa->ifa_next) {
17725 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
17726 +                       ret = 1;
17727 +                       break;
17728 +               }
17729 +       }
17730 +       in_dev_put(in_dev);
17731 +out:
17732 +       return ret;
17733 +}
17734 +
17735 +
17736 +#ifdef CONFIG_IPV6
17737 +
17738 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
17739 +{
17740 +       struct inet6_dev *in_dev;
17741 +       struct inet6_ifaddr *ifa;
17742 +       int ret = 0;
17743 +
17744 +       if (!dev)
17745 +               goto out;
17746 +       in_dev = in6_dev_get(dev);
17747 +       if (!in_dev)
17748 +               goto out;
17749 +
17750 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
17751 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
17752 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
17753 +                       ret = 1;
17754 +                       break;
17755 +               }
17756 +       }
17757 +       in6_dev_put(in_dev);
17758 +out:
17759 +       return ret;
17760 +}
17761 +
17762 +#endif
17763 +
17764 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
17765 +{
17766 +       int ret = 1;
17767 +
17768 +       if (!nxi)
17769 +               goto out;
17770 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
17771 +               goto out;
17772 +#ifdef CONFIG_IPV6
17773 +       ret = 2;
17774 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
17775 +               goto out;
17776 +#endif
17777 +       ret = 0;
17778 +out:
17779 +       vxdprintk(VXD_CBIT(net, 3),
17780 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
17781 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
17782 +       return ret;
17783 +}
17784 +
17785 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
17786 +       struct flowi4 *fl4)
17787 +{
17788 +       struct rtable *rt;
17789 +
17790 +       if (!nxi)
17791 +               return NULL;
17792 +
17793 +       /* FIXME: handle lback only case */
17794 +       if (!NX_IPV4(nxi))
17795 +               return ERR_PTR(-EPERM);
17796 +
17797 +       vxdprintk(VXD_CBIT(net, 4),
17798 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
17799 +               nxi, nxi ? nxi->nx_id : 0,
17800 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
17801 +
17802 +       /* single IP is unconditional */
17803 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
17804 +               (fl4->saddr == INADDR_ANY))
17805 +               fl4->saddr = nxi->v4.ip[0].s_addr;
17806 +
17807 +       if (fl4->saddr == INADDR_ANY) {
17808 +               struct nx_addr_v4 *ptr;
17809 +               __be32 found = 0;
17810 +
17811 +               rt = __ip_route_output_key(net, fl4);
17812 +               if (!IS_ERR(rt)) {
17813 +                       found = fl4->saddr;
17814 +                       ip_rt_put(rt);
17815 +                       vxdprintk(VXD_CBIT(net, 4),
17816 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
17817 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
17818 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
17819 +                               goto found;
17820 +               }
17821 +
17822 +               WARN_ON_ONCE(in_irq());
17823 +               spin_lock_bh(&nxi->addr_lock);
17824 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
17825 +                       __be32 primary = ptr->ip[0].s_addr;
17826 +                       __be32 mask = ptr->mask.s_addr;
17827 +                       __be32 neta = primary & mask;
17828 +
17829 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
17830 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
17831 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
17832 +                               NIPQUAD(mask), NIPQUAD(neta));
17833 +                       if ((found & mask) != neta)
17834 +                               continue;
17835 +
17836 +                       fl4->saddr = primary;
17837 +                       rt = __ip_route_output_key(net, fl4);
17838 +                       vxdprintk(VXD_CBIT(net, 4),
17839 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
17840 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
17841 +                       if (!IS_ERR(rt)) {
17842 +                               found = fl4->saddr;
17843 +                               ip_rt_put(rt);
17844 +                               if (found == primary)
17845 +                                       goto found_unlock;
17846 +                       }
17847 +               }
17848 +               /* still no source ip? */
17849 +               found = ipv4_is_loopback(fl4->daddr)
17850 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
17851 +       found_unlock:
17852 +               spin_unlock_bh(&nxi->addr_lock);
17853 +       found:
17854 +               /* assign src ip to flow */
17855 +               fl4->saddr = found;
17856 +
17857 +       } else {
17858 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
17859 +                       return ERR_PTR(-EPERM);
17860 +       }
17861 +
17862 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
17863 +               if (ipv4_is_loopback(fl4->daddr))
17864 +                       fl4->daddr = nxi->v4_lback.s_addr;
17865 +               if (ipv4_is_loopback(fl4->saddr))
17866 +                       fl4->saddr = nxi->v4_lback.s_addr;
17867 +       } else if (ipv4_is_loopback(fl4->daddr) &&
17868 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
17869 +               return ERR_PTR(-EPERM);
17870 +
17871 +       return NULL;
17872 +}
17873 +
17874 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
17875 +
17876 diff -NurpP --minimal linux-4.4.110/kernel/vserver/init.c linux-4.4.110-vs2.3.9/kernel/vserver/init.c
17877 --- linux-4.4.110/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
17878 +++ linux-4.4.110-vs2.3.9/kernel/vserver/init.c 2018-01-09 22:31:39.000000000 +0000
17879 @@ -0,0 +1,46 @@
17880 +/*
17881 + *  linux/kernel/init.c
17882 + *
17883 + *  Virtual Server Init
17884 + *
17885 + *  Copyright (C) 2004-2007  Herbert P?tzl
17886 + *
17887 + *  V0.01  basic structure
17888 + *
17889 + */
17890 +
17891 +#include <linux/init.h>
17892 +#include <linux/module.h>
17893 +
17894 +int    vserver_register_sysctl(void);
17895 +void   vserver_unregister_sysctl(void);
17896 +
17897 +
17898 +static int __init init_vserver(void)
17899 +{
17900 +       int ret = 0;
17901 +
17902 +#ifdef CONFIG_VSERVER_DEBUG
17903 +       vserver_register_sysctl();
17904 +#endif
17905 +       return ret;
17906 +}
17907 +
17908 +
17909 +static void __exit exit_vserver(void)
17910 +{
17911 +
17912 +#ifdef CONFIG_VSERVER_DEBUG
17913 +       vserver_unregister_sysctl();
17914 +#endif
17915 +       return;
17916 +}
17917 +
17918 +/* FIXME: GFP_ZONETYPES gone
17919 +long vx_slab[GFP_ZONETYPES]; */
17920 +long vx_area;
17921 +
17922 +
17923 +module_init(init_vserver);
17924 +module_exit(exit_vserver);
17925 +
17926 diff -NurpP --minimal linux-4.4.110/kernel/vserver/inode.c linux-4.4.110-vs2.3.9/kernel/vserver/inode.c
17927 --- linux-4.4.110/kernel/vserver/inode.c        1970-01-01 00:00:00.000000000 +0000
17928 +++ linux-4.4.110-vs2.3.9/kernel/vserver/inode.c        2018-01-09 22:24:56.000000000 +0000
17929 @@ -0,0 +1,440 @@
17930 +/*
17931 + *  linux/kernel/vserver/inode.c
17932 + *
17933 + *  Virtual Server: File System Support
17934 + *
17935 + *  Copyright (C) 2004-2007  Herbert P?tzl
17936 + *
17937 + *  V0.01  separated from vcontext V0.05
17938 + *  V0.02  moved to tag (instead of xid)
17939 + *
17940 + */
17941 +
17942 +#include <linux/tty.h>
17943 +#include <linux/proc_fs.h>
17944 +#include <linux/devpts_fs.h>
17945 +#include <linux/fs.h>
17946 +#include <linux/file.h>
17947 +#include <linux/mount.h>
17948 +#include <linux/parser.h>
17949 +#include <linux/namei.h>
17950 +#include <linux/magic.h>
17951 +#include <linux/slab.h>
17952 +#include <linux/vserver/inode.h>
17953 +#include <linux/vserver/inode_cmd.h>
17954 +#include <linux/vs_base.h>
17955 +#include <linux/vs_tag.h>
17956 +
17957 +#include <asm/uaccess.h>
17958 +#include <../../fs/proc/internal.h>
17959 +
17960 +
17961 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
17962 +{
17963 +       struct proc_dir_entry *entry;
17964 +
17965 +       if (!in || !in->i_sb)
17966 +               return -ESRCH;
17967 +
17968 +       *flags = IATTR_TAG
17969 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
17970 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
17971 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
17972 +               | (IS_COW(in) ? IATTR_COW : 0);
17973 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
17974 +
17975 +       if (S_ISDIR(in->i_mode))
17976 +               *mask |= IATTR_BARRIER;
17977 +
17978 +       if (IS_TAGGED(in)) {
17979 +               *tag = i_tag_read(in);
17980 +               *mask |= IATTR_TAG;
17981 +       }
17982 +
17983 +       switch (in->i_sb->s_magic) {
17984 +       case PROC_SUPER_MAGIC:
17985 +               entry = PROC_I(in)->pde;
17986 +
17987 +               /* check for specific inodes? */
17988 +               if (entry)
17989 +                       *mask |= IATTR_FLAGS;
17990 +               if (entry)
17991 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
17992 +               else
17993 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
17994 +               break;
17995 +
17996 +       case DEVPTS_SUPER_MAGIC:
17997 +               *tag = i_tag_read(in);
17998 +               *mask |= IATTR_TAG;
17999 +               break;
18000 +
18001 +       default:
18002 +               break;
18003 +       }
18004 +       return 0;
18005 +}
18006 +
18007 +int vc_get_iattr(void __user *data)
18008 +{
18009 +       struct path path;
18010 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
18011 +       int ret;
18012 +
18013 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18014 +               return -EFAULT;
18015 +
18016 +       ret = user_lpath(vc_data.name, &path);
18017 +       if (!ret) {
18018 +               ret = __vc_get_iattr(path.dentry->d_inode,
18019 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18020 +               path_put(&path);
18021 +       }
18022 +       if (ret)
18023 +               return ret;
18024 +
18025 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18026 +               ret = -EFAULT;
18027 +       return ret;
18028 +}
18029 +
18030 +#ifdef CONFIG_COMPAT
18031 +
18032 +int vc_get_iattr_x32(void __user *data)
18033 +{
18034 +       struct path path;
18035 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
18036 +       int ret;
18037 +
18038 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18039 +               return -EFAULT;
18040 +
18041 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18042 +       if (!ret) {
18043 +               ret = __vc_get_iattr(path.dentry->d_inode,
18044 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18045 +               path_put(&path);
18046 +       }
18047 +       if (ret)
18048 +               return ret;
18049 +
18050 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18051 +               ret = -EFAULT;
18052 +       return ret;
18053 +}
18054 +
18055 +#endif /* CONFIG_COMPAT */
18056 +
18057 +
18058 +int vc_fget_iattr(uint32_t fd, void __user *data)
18059 +{
18060 +       struct file *filp;
18061 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
18062 +       int ret;
18063 +
18064 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18065 +               return -EFAULT;
18066 +
18067 +       filp = fget(fd);
18068 +       if (!filp || !filp->f_path.dentry || !filp->f_path.dentry->d_inode)
18069 +               return -EBADF;
18070 +
18071 +       ret = __vc_get_iattr(filp->f_path.dentry->d_inode,
18072 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
18073 +
18074 +       fput(filp);
18075 +
18076 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18077 +               ret = -EFAULT;
18078 +       return ret;
18079 +}
18080 +
18081 +
18082 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18083 +{
18084 +       struct inode *in = de->d_inode;
18085 +       int error = 0, is_proc = 0, has_tag = 0;
18086 +       struct iattr attr = { 0 };
18087 +
18088 +       if (!in || !in->i_sb)
18089 +               return -ESRCH;
18090 +
18091 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
18092 +       if ((*mask & IATTR_FLAGS) && !is_proc)
18093 +               return -EINVAL;
18094 +
18095 +       has_tag = IS_TAGGED(in) ||
18096 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
18097 +       if ((*mask & IATTR_TAG) && !has_tag)
18098 +               return -EINVAL;
18099 +
18100 +       mutex_lock(&in->i_mutex);
18101 +       if (*mask & IATTR_TAG) {
18102 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
18103 +               attr.ia_valid |= ATTR_TAG;
18104 +       }
18105 +
18106 +       if (*mask & IATTR_FLAGS) {
18107 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
18108 +               unsigned int iflags = PROC_I(in)->vx_flags;
18109 +
18110 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
18111 +                       | (*flags & IATTR_FLAGS);
18112 +               PROC_I(in)->vx_flags = iflags;
18113 +               if (entry)
18114 +                       entry->vx_flags = iflags;
18115 +       }
18116 +
18117 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
18118 +               IATTR_BARRIER | IATTR_COW)) {
18119 +               int iflags = in->i_flags;
18120 +               int vflags = in->i_vflags;
18121 +
18122 +               if (*mask & IATTR_IMMUTABLE) {
18123 +                       if (*flags & IATTR_IMMUTABLE)
18124 +                               iflags |= S_IMMUTABLE;
18125 +                       else
18126 +                               iflags &= ~S_IMMUTABLE;
18127 +               }
18128 +               if (*mask & IATTR_IXUNLINK) {
18129 +                       if (*flags & IATTR_IXUNLINK)
18130 +                               iflags |= S_IXUNLINK;
18131 +                       else
18132 +                               iflags &= ~S_IXUNLINK;
18133 +               }
18134 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
18135 +                       if (*flags & IATTR_BARRIER)
18136 +                               vflags |= V_BARRIER;
18137 +                       else
18138 +                               vflags &= ~V_BARRIER;
18139 +               }
18140 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
18141 +                       if (*flags & IATTR_COW)
18142 +                               vflags |= V_COW;
18143 +                       else
18144 +                               vflags &= ~V_COW;
18145 +               }
18146 +               if (in->i_op && in->i_op->sync_flags) {
18147 +                       error = in->i_op->sync_flags(in, iflags, vflags);
18148 +                       if (error)
18149 +                               goto out;
18150 +               }
18151 +       }
18152 +
18153 +       if (attr.ia_valid) {
18154 +               if (in->i_op && in->i_op->setattr)
18155 +                       error = in->i_op->setattr(de, &attr);
18156 +               else {
18157 +                       error = inode_change_ok(in, &attr);
18158 +                       if (!error) {
18159 +                               setattr_copy(in, &attr);
18160 +                               mark_inode_dirty(in);
18161 +                       }
18162 +               }
18163 +       }
18164 +
18165 +out:
18166 +       mutex_unlock(&in->i_mutex);
18167 +       return error;
18168 +}
18169 +
18170 +int vc_set_iattr(void __user *data)
18171 +{
18172 +       struct path path;
18173 +       struct vcmd_ctx_iattr_v1 vc_data;
18174 +       int ret;
18175 +
18176 +       if (!capable(CAP_LINUX_IMMUTABLE))
18177 +               return -EPERM;
18178 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18179 +               return -EFAULT;
18180 +
18181 +       ret = user_lpath(vc_data.name, &path);
18182 +       if (!ret) {
18183 +               ret = __vc_set_iattr(path.dentry,
18184 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18185 +               path_put(&path);
18186 +       }
18187 +
18188 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18189 +               ret = -EFAULT;
18190 +       return ret;
18191 +}
18192 +
18193 +#ifdef CONFIG_COMPAT
18194 +
18195 +int vc_set_iattr_x32(void __user *data)
18196 +{
18197 +       struct path path;
18198 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
18199 +       int ret;
18200 +
18201 +       if (!capable(CAP_LINUX_IMMUTABLE))
18202 +               return -EPERM;
18203 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18204 +               return -EFAULT;
18205 +
18206 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18207 +       if (!ret) {
18208 +               ret = __vc_set_iattr(path.dentry,
18209 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18210 +               path_put(&path);
18211 +       }
18212 +
18213 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18214 +               ret = -EFAULT;
18215 +       return ret;
18216 +}
18217 +
18218 +#endif /* CONFIG_COMPAT */
18219 +
18220 +int vc_fset_iattr(uint32_t fd, void __user *data)
18221 +{
18222 +       struct file *filp;
18223 +       struct vcmd_ctx_fiattr_v0 vc_data;
18224 +       int ret;
18225 +
18226 +       if (!capable(CAP_LINUX_IMMUTABLE))
18227 +               return -EPERM;
18228 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18229 +               return -EFAULT;
18230 +
18231 +       filp = fget(fd);
18232 +       if (!filp || !filp->f_path.dentry || !filp->f_path.dentry->d_inode)
18233 +               return -EBADF;
18234 +
18235 +       ret = __vc_set_iattr(filp->f_path.dentry, &vc_data.tag,
18236 +               &vc_data.flags, &vc_data.mask);
18237 +
18238 +       fput(filp);
18239 +
18240 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18241 +               return -EFAULT;
18242 +       return ret;
18243 +}
18244 +
18245 +
18246 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
18247 +
18248 +static match_table_t tokens = {
18249 +       {Opt_notagcheck, "notagcheck"},
18250 +#ifdef CONFIG_PROPAGATE
18251 +       {Opt_notag, "notag"},
18252 +       {Opt_tag, "tag"},
18253 +       {Opt_tagid, "tagid=%u"},
18254 +#endif
18255 +       {Opt_err, NULL}
18256 +};
18257 +
18258 +
18259 +static void __dx_parse_remove(char *string, char *opt)
18260 +{
18261 +       char *p = strstr(string, opt);
18262 +       char *q = p;
18263 +
18264 +       if (p) {
18265 +               while (*q != '\0' && *q != ',')
18266 +                       q++;
18267 +               while (*q)
18268 +                       *p++ = *q++;
18269 +               while (*p)
18270 +                       *p++ = '\0';
18271 +       }
18272 +}
18273 +
18274 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
18275 +                unsigned long *flags)
18276 +{
18277 +       int set = 0;
18278 +       substring_t args[MAX_OPT_ARGS];
18279 +       int token;
18280 +       char *s, *p, *opts;
18281 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
18282 +       int option = 0;
18283 +#endif
18284 +
18285 +       if (!string)
18286 +               return 0;
18287 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
18288 +       if (!s)
18289 +               return 0;
18290 +
18291 +       opts = s;
18292 +       while ((p = strsep(&opts, ",")) != NULL) {
18293 +               token = match_token(p, tokens, args);
18294 +
18295 +               switch (token) {
18296 +#ifdef CONFIG_PROPAGATE
18297 +               case Opt_tag:
18298 +                       if (tag)
18299 +                               *tag = 0;
18300 +                       if (remove)
18301 +                               __dx_parse_remove(s, "tag");
18302 +                       *mnt_flags |= MNT_TAGID;
18303 +                       set |= MNT_TAGID;
18304 +                       break;
18305 +               case Opt_notag:
18306 +                       if (remove)
18307 +                               __dx_parse_remove(s, "notag");
18308 +                       *mnt_flags |= MNT_NOTAG;
18309 +                       set |= MNT_NOTAG;
18310 +                       break;
18311 +               case Opt_tagid:
18312 +                       if (tag && !match_int(args, &option))
18313 +                               *tag = option;
18314 +                       if (remove)
18315 +                               __dx_parse_remove(s, "tagid");
18316 +                       *mnt_flags |= MNT_TAGID;
18317 +                       set |= MNT_TAGID;
18318 +                       break;
18319 +#endif /* CONFIG_PROPAGATE */
18320 +               case Opt_notagcheck:
18321 +                       if (remove)
18322 +                               __dx_parse_remove(s, "notagcheck");
18323 +                       *flags |= MS_NOTAGCHECK;
18324 +                       set |= MS_NOTAGCHECK;
18325 +                       break;
18326 +               }
18327 +               vxdprintk(VXD_CBIT(tag, 7),
18328 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
18329 +                       p, token, option);
18330 +       }
18331 +       if (set)
18332 +               strcpy(string, s);
18333 +       kfree(s);
18334 +       return set;
18335 +}
18336 +
18337 +#ifdef CONFIG_PROPAGATE
18338 +
18339 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
18340 +{
18341 +       vtag_t new_tag = 0;
18342 +       struct vfsmount *mnt;
18343 +       int propagate;
18344 +
18345 +       if (!nd)
18346 +               return;
18347 +       mnt = nd->path.mnt;
18348 +       if (!mnt)
18349 +               return;
18350 +
18351 +       propagate = (mnt->mnt_flags & MNT_TAGID);
18352 +       if (propagate)
18353 +               new_tag = mnt->mnt_tag;
18354 +
18355 +       vxdprintk(VXD_CBIT(tag, 7),
18356 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
18357 +               inode, inode->i_ino, inode->i_tag,
18358 +               new_tag, (propagate) ? 1 : 0);
18359 +
18360 +       if (propagate)
18361 +               i_tag_write(inode, new_tag);
18362 +}
18363 +
18364 +#include <linux/module.h>
18365 +
18366 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
18367 +
18368 +#endif /* CONFIG_PROPAGATE */
18369 +
18370 diff -NurpP --minimal linux-4.4.110/kernel/vserver/limit.c linux-4.4.110-vs2.3.9/kernel/vserver/limit.c
18371 --- linux-4.4.110/kernel/vserver/limit.c        1970-01-01 00:00:00.000000000 +0000
18372 +++ linux-4.4.110-vs2.3.9/kernel/vserver/limit.c        2018-01-09 16:36:34.000000000 +0000
18373 @@ -0,0 +1,343 @@
18374 +/*
18375 + *  linux/kernel/vserver/limit.c
18376 + *
18377 + *  Virtual Server: Context Limits
18378 + *
18379 + *  Copyright (C) 2004-2010  Herbert P?tzl
18380 + *
18381 + *  V0.01  broken out from vcontext V0.05
18382 + *  V0.02  changed vcmds to vxi arg
18383 + *  V0.03  added memory cgroup support
18384 + *
18385 + */
18386 +
18387 +#include <linux/sched.h>
18388 +#include <linux/module.h>
18389 +#include <linux/memcontrol.h>
18390 +#include <linux/page_counter.h>
18391 +#include <linux/vs_limit.h>
18392 +#include <linux/vserver/limit.h>
18393 +#include <linux/vserver/limit_cmd.h>
18394 +
18395 +#include <asm/uaccess.h>
18396 +
18397 +
18398 +const char *vlimit_name[NUM_LIMITS] = {
18399 +       [RLIMIT_CPU]            = "CPU",
18400 +       [RLIMIT_NPROC]          = "NPROC",
18401 +       [RLIMIT_NOFILE]         = "NOFILE",
18402 +       [RLIMIT_LOCKS]          = "LOCKS",
18403 +       [RLIMIT_SIGPENDING]     = "SIGP",
18404 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
18405 +
18406 +       [VLIMIT_NSOCK]          = "NSOCK",
18407 +       [VLIMIT_OPENFD]         = "OPENFD",
18408 +       [VLIMIT_SHMEM]          = "SHMEM",
18409 +       [VLIMIT_DENTRY]         = "DENTRY",
18410 +};
18411 +
18412 +EXPORT_SYMBOL_GPL(vlimit_name);
18413 +
18414 +#define MASK_ENTRY(x)  (1 << (x))
18415 +
18416 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
18417 +               /* minimum */
18418 +       0
18419 +       ,       /* softlimit */
18420 +       0
18421 +       ,       /* maximum */
18422 +       MASK_ENTRY( RLIMIT_NPROC        ) |
18423 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
18424 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
18425 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
18426 +
18427 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
18428 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
18429 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
18430 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
18431 +       0
18432 +};
18433 +               /* accounting only */
18434 +uint32_t account_mask =
18435 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
18436 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
18437 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
18438 +       0;
18439 +
18440 +
18441 +static int is_valid_vlimit(int id)
18442 +{
18443 +       uint32_t mask = vlimit_mask.minimum |
18444 +               vlimit_mask.softlimit | vlimit_mask.maximum;
18445 +       return mask & (1 << id);
18446 +}
18447 +
18448 +static int is_accounted_vlimit(int id)
18449 +{
18450 +       if (is_valid_vlimit(id))
18451 +               return 1;
18452 +       return account_mask & (1 << id);
18453 +}
18454 +
18455 +
18456 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
18457 +{
18458 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
18459 +       return VX_VLIM(limit);
18460 +}
18461 +
18462 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
18463 +{
18464 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
18465 +       return VX_VLIM(limit);
18466 +}
18467 +
18468 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
18469 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
18470 +{
18471 +       if (!is_valid_vlimit(id))
18472 +               return -EINVAL;
18473 +
18474 +       if (minimum)
18475 +               *minimum = CRLIM_UNSET;
18476 +       if (softlimit)
18477 +               *softlimit = vc_get_soft(vxi, id);
18478 +       if (maximum)
18479 +               *maximum = vc_get_hard(vxi, id);
18480 +       return 0;
18481 +}
18482 +
18483 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
18484 +{
18485 +       struct vcmd_ctx_rlimit_v0 vc_data;
18486 +       int ret;
18487 +
18488 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18489 +               return -EFAULT;
18490 +
18491 +       ret = do_get_rlimit(vxi, vc_data.id,
18492 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18493 +       if (ret)
18494 +               return ret;
18495 +
18496 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18497 +               return -EFAULT;
18498 +       return 0;
18499 +}
18500 +
18501 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
18502 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
18503 +{
18504 +       if (!is_valid_vlimit(id))
18505 +               return -EINVAL;
18506 +
18507 +       if (maximum != CRLIM_KEEP)
18508 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
18509 +       if (softlimit != CRLIM_KEEP)
18510 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
18511 +
18512 +       /* clamp soft limit */
18513 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
18514 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
18515 +
18516 +       return 0;
18517 +}
18518 +
18519 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
18520 +{
18521 +       struct vcmd_ctx_rlimit_v0 vc_data;
18522 +
18523 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18524 +               return -EFAULT;
18525 +
18526 +       return do_set_rlimit(vxi, vc_data.id,
18527 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18528 +}
18529 +
18530 +#ifdef CONFIG_IA32_EMULATION
18531 +
18532 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
18533 +{
18534 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18535 +
18536 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18537 +               return -EFAULT;
18538 +
18539 +       return do_set_rlimit(vxi, vc_data.id,
18540 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18541 +}
18542 +
18543 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
18544 +{
18545 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18546 +       int ret;
18547 +
18548 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18549 +               return -EFAULT;
18550 +
18551 +       ret = do_get_rlimit(vxi, vc_data.id,
18552 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18553 +       if (ret)
18554 +               return ret;
18555 +
18556 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18557 +               return -EFAULT;
18558 +       return 0;
18559 +}
18560 +
18561 +#endif /* CONFIG_IA32_EMULATION */
18562 +
18563 +
18564 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
18565 +{
18566 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
18567 +               return -EFAULT;
18568 +       return 0;
18569 +}
18570 +
18571 +
18572 +static inline void vx_reset_hits(struct _vx_limit *limit)
18573 +{
18574 +       int lim;
18575 +
18576 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18577 +               atomic_set(&__rlim_lhit(limit, lim), 0);
18578 +       }
18579 +}
18580 +
18581 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
18582 +{
18583 +       vx_reset_hits(&vxi->limit);
18584 +       return 0;
18585 +}
18586 +
18587 +static inline void vx_reset_minmax(struct _vx_limit *limit)
18588 +{
18589 +       rlim_t value;
18590 +       int lim;
18591 +
18592 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18593 +               value = __rlim_get(limit, lim);
18594 +               __rlim_rmax(limit, lim) = value;
18595 +               __rlim_rmin(limit, lim) = value;
18596 +       }
18597 +}
18598 +
18599 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
18600 +{
18601 +       vx_reset_minmax(&vxi->limit);
18602 +       return 0;
18603 +}
18604 +
18605 +
18606 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
18607 +{
18608 +       struct vcmd_rlimit_stat_v0 vc_data;
18609 +       struct _vx_limit *limit = &vxi->limit;
18610 +       int id;
18611 +
18612 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18613 +               return -EFAULT;
18614 +
18615 +       id = vc_data.id;
18616 +       if (!is_accounted_vlimit(id))
18617 +               return -EINVAL;
18618 +
18619 +       vx_limit_fixup(limit, id);
18620 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
18621 +       vc_data.value = __rlim_get(limit, id);
18622 +       vc_data.minimum = __rlim_rmin(limit, id);
18623 +       vc_data.maximum = __rlim_rmax(limit, id);
18624 +
18625 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18626 +               return -EFAULT;
18627 +       return 0;
18628 +}
18629 +
18630 +
18631 +#ifdef CONFIG_MEMCG
18632 +void vx_vsi_meminfo(struct sysinfo *val)
18633 +{
18634 +       struct mem_cgroup *mcg;
18635 +       u64 res_limit, res_usage;
18636 +
18637 +       rcu_read_lock();
18638 +       mcg = mem_cgroup_from_task(current);
18639 +       rcu_read_unlock();
18640 +       if (!mcg)
18641 +               goto out;
18642 +
18643 +       res_limit = mem_cgroup_mem_limit_pages(mcg);
18644 +       res_usage = mem_cgroup_mem_usage_pages(mcg);
18645 +
18646 +       if (res_limit != PAGE_COUNTER_MAX)
18647 +               val->totalram = res_limit;
18648 +       val->freeram = val->totalram - res_usage;
18649 +       val->bufferram = 0;
18650 +       val->totalhigh = 0;
18651 +       val->freehigh = 0;
18652 +out:
18653 +       return;
18654 +}
18655 +
18656 +void vx_vsi_swapinfo(struct sysinfo *val)
18657 +{
18658 +#ifdef CONFIG_MEMCG_SWAP
18659 +       struct mem_cgroup *mcg;
18660 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
18661 +       s64 swap_limit, swap_usage;
18662 +
18663 +       rcu_read_lock();
18664 +       mcg = mem_cgroup_from_task(current);
18665 +       rcu_read_unlock();
18666 +       if (!mcg)
18667 +               goto out;
18668 +
18669 +       res_limit = mem_cgroup_mem_limit_pages(mcg);
18670 +       res_usage = mem_cgroup_mem_usage_pages(mcg);
18671 +       memsw_limit = mem_cgroup_memsw_limit_pages(mcg);
18672 +       memsw_usage = mem_cgroup_memsw_usage_pages(mcg);
18673 +
18674 +       /* memory unlimited */
18675 +       if (res_limit == PAGE_COUNTER_MAX)
18676 +               goto out;
18677 +
18678 +       swap_limit = memsw_limit - res_limit;
18679 +       /* we have a swap limit? */
18680 +       if (memsw_limit != PAGE_COUNTER_MAX)
18681 +               val->totalswap = swap_limit;
18682 +
18683 +       /* calculate swap part */
18684 +       swap_usage = (memsw_usage > res_usage) ?
18685 +               memsw_usage - res_usage : 0;
18686 +
18687 +       /* total shown minus usage gives free swap */
18688 +       val->freeswap = (swap_usage < swap_limit) ?
18689 +               val->totalswap - swap_usage : 0;
18690 +out:
18691 +#else  /* !CONFIG_MEMCG_SWAP */
18692 +       val->totalswap = 0;
18693 +       val->freeswap = 0;
18694 +#endif /* !CONFIG_MEMCG_SWAP */
18695 +       return;
18696 +}
18697 +
18698 +long vx_vsi_cached(struct sysinfo *val)
18699 +{
18700 +       long cache = 0;
18701 +#ifdef CONFIG_MEMCG_BROKEN
18702 +       struct mem_cgroup *mcg;
18703 +
18704 +       rcu_read_lock();
18705 +       mcg = mem_cgroup_from_task(current);
18706 +       rcu_read_unlock();
18707 +       if (!mcg)
18708 +               goto out;
18709 +
18710 +       // cache = mem_cgroup_stat_read_cache(mcg);
18711 +out:
18712 +#endif
18713 +       return cache;
18714 +}
18715 +#endif /* !CONFIG_MEMCG */
18716 +
18717 diff -NurpP --minimal linux-4.4.110/kernel/vserver/limit_init.h linux-4.4.110-vs2.3.9/kernel/vserver/limit_init.h
18718 --- linux-4.4.110/kernel/vserver/limit_init.h   1970-01-01 00:00:00.000000000 +0000
18719 +++ linux-4.4.110-vs2.3.9/kernel/vserver/limit_init.h   2018-01-09 16:36:34.000000000 +0000
18720 @@ -0,0 +1,31 @@
18721 +
18722 +
18723 +static inline void vx_info_init_limit(struct _vx_limit *limit)
18724 +{
18725 +       int lim;
18726 +
18727 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18728 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
18729 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
18730 +               __rlim_set(limit, lim, 0);
18731 +               atomic_set(&__rlim_lhit(limit, lim), 0);
18732 +               __rlim_rmin(limit, lim) = 0;
18733 +               __rlim_rmax(limit, lim) = 0;
18734 +       }
18735 +}
18736 +
18737 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
18738 +{
18739 +       rlim_t value;
18740 +       int lim;
18741 +
18742 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18743 +               if ((1 << lim) & VLIM_NOCHECK)
18744 +                       continue;
18745 +               value = __rlim_get(limit, lim);
18746 +               vxwprintk_xid(value,
18747 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
18748 +                       limit, vlimit_name[lim], lim, (long)value);
18749 +       }
18750 +}
18751 +
18752 diff -NurpP --minimal linux-4.4.110/kernel/vserver/limit_proc.h linux-4.4.110-vs2.3.9/kernel/vserver/limit_proc.h
18753 --- linux-4.4.110/kernel/vserver/limit_proc.h   1970-01-01 00:00:00.000000000 +0000
18754 +++ linux-4.4.110-vs2.3.9/kernel/vserver/limit_proc.h   2018-01-09 16:36:34.000000000 +0000
18755 @@ -0,0 +1,57 @@
18756 +#ifndef _VX_LIMIT_PROC_H
18757 +#define _VX_LIMIT_PROC_H
18758 +
18759 +#include <linux/vserver/limit_int.h>
18760 +
18761 +
18762 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
18763 +#define VX_LIMIT_TOP   \
18764 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
18765 +
18766 +#define VX_LIMIT_ARG(r)                                \
18767 +       (unsigned long)__rlim_get(limit, r),    \
18768 +       (unsigned long)__rlim_rmin(limit, r),   \
18769 +       (unsigned long)__rlim_rmax(limit, r),   \
18770 +       VX_VLIM(__rlim_soft(limit, r)),         \
18771 +       VX_VLIM(__rlim_hard(limit, r)),         \
18772 +       atomic_read(&__rlim_lhit(limit, r))
18773 +
18774 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
18775 +{
18776 +       vx_limit_fixup(limit, -1);
18777 +       return sprintf(buffer, VX_LIMIT_TOP
18778 +               "PROC"  VX_LIMIT_FMT
18779 +               "VM"    VX_LIMIT_FMT
18780 +               "VML"   VX_LIMIT_FMT
18781 +               "RSS"   VX_LIMIT_FMT
18782 +               "ANON"  VX_LIMIT_FMT
18783 +               "RMAP"  VX_LIMIT_FMT
18784 +               "FILES" VX_LIMIT_FMT
18785 +               "OFD"   VX_LIMIT_FMT
18786 +               "LOCKS" VX_LIMIT_FMT
18787 +               "SOCK"  VX_LIMIT_FMT
18788 +               "MSGQ"  VX_LIMIT_FMT
18789 +               "SHM"   VX_LIMIT_FMT
18790 +               "SEMA"  VX_LIMIT_FMT
18791 +               "SEMS"  VX_LIMIT_FMT
18792 +               "DENT"  VX_LIMIT_FMT,
18793 +               VX_LIMIT_ARG(RLIMIT_NPROC),
18794 +               VX_LIMIT_ARG(RLIMIT_AS),
18795 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
18796 +               VX_LIMIT_ARG(RLIMIT_RSS),
18797 +               VX_LIMIT_ARG(VLIMIT_ANON),
18798 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
18799 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
18800 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
18801 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
18802 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
18803 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
18804 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
18805 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
18806 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
18807 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
18808 +}
18809 +
18810 +#endif /* _VX_LIMIT_PROC_H */
18811 +
18812 +
18813 diff -NurpP --minimal linux-4.4.110/kernel/vserver/network.c linux-4.4.110-vs2.3.9/kernel/vserver/network.c
18814 --- linux-4.4.110/kernel/vserver/network.c      1970-01-01 00:00:00.000000000 +0000
18815 +++ linux-4.4.110-vs2.3.9/kernel/vserver/network.c      2018-01-09 16:36:34.000000000 +0000
18816 @@ -0,0 +1,1053 @@
18817 +/*
18818 + *  linux/kernel/vserver/network.c
18819 + *
18820 + *  Virtual Server: Network Support
18821 + *
18822 + *  Copyright (C) 2003-2007  Herbert P?tzl
18823 + *
18824 + *  V0.01  broken out from vcontext V0.05
18825 + *  V0.02  cleaned up implementation
18826 + *  V0.03  added equiv nx commands
18827 + *  V0.04  switch to RCU based hash
18828 + *  V0.05  and back to locking again
18829 + *  V0.06  changed vcmds to nxi arg
18830 + *  V0.07  have __create claim() the nxi
18831 + *
18832 + */
18833 +
18834 +#include <linux/err.h>
18835 +#include <linux/slab.h>
18836 +#include <linux/rcupdate.h>
18837 +#include <net/ipv6.h>
18838 +
18839 +#include <linux/vs_network.h>
18840 +#include <linux/vs_pid.h>
18841 +#include <linux/vserver/network_cmd.h>
18842 +
18843 +
18844 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
18845 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
18846 +
18847 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
18848 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
18849 +
18850 +
18851 +static int __init init_network(void)
18852 +{
18853 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
18854 +               sizeof(struct nx_addr_v4), 0,
18855 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18856 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
18857 +               sizeof(struct nx_addr_v6), 0,
18858 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18859 +       return 0;
18860 +}
18861 +
18862 +
18863 +/*     __alloc_nx_addr_v4()                                    */
18864 +
18865 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
18866 +{
18867 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
18868 +               nx_addr_v4_cachep, GFP_KERNEL);
18869 +
18870 +       if (!IS_ERR(nxa))
18871 +               memset(nxa, 0, sizeof(*nxa));
18872 +       return nxa;
18873 +}
18874 +
18875 +/*     __dealloc_nx_addr_v4()                                  */
18876 +
18877 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
18878 +{
18879 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
18880 +}
18881 +
18882 +/*     __dealloc_nx_addr_v4_all()                              */
18883 +
18884 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
18885 +{
18886 +       while (nxa) {
18887 +               struct nx_addr_v4 *next = nxa->next;
18888 +
18889 +               __dealloc_nx_addr_v4(nxa);
18890 +               nxa = next;
18891 +       }
18892 +}
18893 +
18894 +
18895 +#ifdef CONFIG_IPV6
18896 +
18897 +/*     __alloc_nx_addr_v6()                                    */
18898 +
18899 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
18900 +{
18901 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
18902 +               nx_addr_v6_cachep, GFP_KERNEL);
18903 +
18904 +       if (!IS_ERR(nxa))
18905 +               memset(nxa, 0, sizeof(*nxa));
18906 +       return nxa;
18907 +}
18908 +
18909 +/*     __dealloc_nx_addr_v6()                                  */
18910 +
18911 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
18912 +{
18913 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
18914 +}
18915 +
18916 +/*     __dealloc_nx_addr_v6_all()                              */
18917 +
18918 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
18919 +{
18920 +       while (nxa) {
18921 +               struct nx_addr_v6 *next = nxa->next;
18922 +
18923 +               __dealloc_nx_addr_v6(nxa);
18924 +               nxa = next;
18925 +       }
18926 +}
18927 +
18928 +#endif /* CONFIG_IPV6 */
18929 +
18930 +/*     __alloc_nx_info()
18931 +
18932 +       * allocate an initialized nx_info struct
18933 +       * doesn't make it visible (hash)                        */
18934 +
18935 +static struct nx_info *__alloc_nx_info(vnid_t nid)
18936 +{
18937 +       struct nx_info *new = NULL;
18938 +
18939 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
18940 +
18941 +       /* would this benefit from a slab cache? */
18942 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
18943 +       if (!new)
18944 +               return 0;
18945 +
18946 +       memset(new, 0, sizeof(struct nx_info));
18947 +       new->nx_id = nid;
18948 +       INIT_HLIST_NODE(&new->nx_hlist);
18949 +       atomic_set(&new->nx_usecnt, 0);
18950 +       atomic_set(&new->nx_tasks, 0);
18951 +       spin_lock_init(&new->addr_lock);
18952 +       new->nx_state = 0;
18953 +
18954 +       new->nx_flags = NXF_INIT_SET;
18955 +
18956 +       /* rest of init goes here */
18957 +
18958 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
18959 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
18960 +
18961 +       vxdprintk(VXD_CBIT(nid, 0),
18962 +               "alloc_nx_info(%d) = %p", nid, new);
18963 +       atomic_inc(&nx_global_ctotal);
18964 +       return new;
18965 +}
18966 +
18967 +/*     __dealloc_nx_info()
18968 +
18969 +       * final disposal of nx_info                             */
18970 +
18971 +static void __dealloc_nx_info(struct nx_info *nxi)
18972 +{
18973 +       vxdprintk(VXD_CBIT(nid, 0),
18974 +               "dealloc_nx_info(%p)", nxi);
18975 +
18976 +       nxi->nx_hlist.next = LIST_POISON1;
18977 +       nxi->nx_id = -1;
18978 +
18979 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
18980 +       BUG_ON(atomic_read(&nxi->nx_tasks));
18981 +
18982 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
18983 +#ifdef CONFIG_IPV6
18984 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
18985 +#endif
18986 +
18987 +       nxi->nx_state |= NXS_RELEASED;
18988 +       kfree(nxi);
18989 +       atomic_dec(&nx_global_ctotal);
18990 +}
18991 +
18992 +static void __shutdown_nx_info(struct nx_info *nxi)
18993 +{
18994 +       nxi->nx_state |= NXS_SHUTDOWN;
18995 +       vs_net_change(nxi, VSC_NETDOWN);
18996 +}
18997 +
18998 +/*     exported stuff                                          */
18999 +
19000 +void free_nx_info(struct nx_info *nxi)
19001 +{
19002 +       /* context shutdown is mandatory */
19003 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
19004 +
19005 +       /* context must not be hashed */
19006 +       BUG_ON(nxi->nx_state & NXS_HASHED);
19007 +
19008 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19009 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19010 +
19011 +       __dealloc_nx_info(nxi);
19012 +}
19013 +
19014 +
19015 +void __nx_set_lback(struct nx_info *nxi)
19016 +{
19017 +       int nid = nxi->nx_id;
19018 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
19019 +
19020 +       nxi->v4_lback.s_addr = lback;
19021 +}
19022 +
19023 +extern int __nx_inet_add_lback(__be32 addr);
19024 +extern int __nx_inet_del_lback(__be32 addr);
19025 +
19026 +
19027 +/*     hash table for nx_info hash */
19028 +
19029 +#define NX_HASH_SIZE   13
19030 +
19031 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
19032 +
19033 +static DEFINE_SPINLOCK(nx_info_hash_lock);
19034 +
19035 +
19036 +static inline unsigned int __hashval(vnid_t nid)
19037 +{
19038 +       return (nid % NX_HASH_SIZE);
19039 +}
19040 +
19041 +
19042 +
19043 +/*     __hash_nx_info()
19044 +
19045 +       * add the nxi to the global hash table
19046 +       * requires the hash_lock to be held                     */
19047 +
19048 +static inline void __hash_nx_info(struct nx_info *nxi)
19049 +{
19050 +       struct hlist_head *head;
19051 +
19052 +       vxd_assert_lock(&nx_info_hash_lock);
19053 +       vxdprintk(VXD_CBIT(nid, 4),
19054 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
19055 +
19056 +       /* context must not be hashed */
19057 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
19058 +
19059 +       nxi->nx_state |= NXS_HASHED;
19060 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
19061 +       hlist_add_head(&nxi->nx_hlist, head);
19062 +       atomic_inc(&nx_global_cactive);
19063 +}
19064 +
19065 +/*     __unhash_nx_info()
19066 +
19067 +       * remove the nxi from the global hash table
19068 +       * requires the hash_lock to be held                     */
19069 +
19070 +static inline void __unhash_nx_info(struct nx_info *nxi)
19071 +{
19072 +       vxd_assert_lock(&nx_info_hash_lock);
19073 +       vxdprintk(VXD_CBIT(nid, 4),
19074 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
19075 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
19076 +
19077 +       /* context must be hashed */
19078 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
19079 +       /* but without tasks */
19080 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19081 +
19082 +       nxi->nx_state &= ~NXS_HASHED;
19083 +       hlist_del(&nxi->nx_hlist);
19084 +       atomic_dec(&nx_global_cactive);
19085 +}
19086 +
19087 +
19088 +/*     __lookup_nx_info()
19089 +
19090 +       * requires the hash_lock to be held
19091 +       * doesn't increment the nx_refcnt                       */
19092 +
19093 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
19094 +{
19095 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
19096 +       struct hlist_node *pos;
19097 +       struct nx_info *nxi;
19098 +
19099 +       vxd_assert_lock(&nx_info_hash_lock);
19100 +       hlist_for_each(pos, head) {
19101 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19102 +
19103 +               if (nxi->nx_id == nid)
19104 +                       goto found;
19105 +       }
19106 +       nxi = NULL;
19107 +found:
19108 +       vxdprintk(VXD_CBIT(nid, 0),
19109 +               "__lookup_nx_info(#%u): %p[#%u]",
19110 +               nid, nxi, nxi ? nxi->nx_id : 0);
19111 +       return nxi;
19112 +}
19113 +
19114 +
19115 +/*     __create_nx_info()
19116 +
19117 +       * create the requested context
19118 +       * get(), claim() and hash it                            */
19119 +
19120 +static struct nx_info *__create_nx_info(int id)
19121 +{
19122 +       struct nx_info *new, *nxi = NULL;
19123 +
19124 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
19125 +
19126 +       if (!(new = __alloc_nx_info(id)))
19127 +               return ERR_PTR(-ENOMEM);
19128 +
19129 +       /* required to make dynamic xids unique */
19130 +       spin_lock(&nx_info_hash_lock);
19131 +
19132 +       /* static context requested */
19133 +       if ((nxi = __lookup_nx_info(id))) {
19134 +               vxdprintk(VXD_CBIT(nid, 0),
19135 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
19136 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19137 +                       nxi = ERR_PTR(-EBUSY);
19138 +               else
19139 +                       nxi = ERR_PTR(-EEXIST);
19140 +               goto out_unlock;
19141 +       }
19142 +       /* new context */
19143 +       vxdprintk(VXD_CBIT(nid, 0),
19144 +               "create_nx_info(%d) = %p (new)", id, new);
19145 +       claim_nx_info(new, NULL);
19146 +       __nx_set_lback(new);
19147 +       __hash_nx_info(get_nx_info(new));
19148 +       nxi = new, new = NULL;
19149 +
19150 +out_unlock:
19151 +       spin_unlock(&nx_info_hash_lock);
19152 +       if (new)
19153 +               __dealloc_nx_info(new);
19154 +       return nxi;
19155 +}
19156 +
19157 +
19158 +
19159 +/*     exported stuff                                          */
19160 +
19161 +
19162 +void unhash_nx_info(struct nx_info *nxi)
19163 +{
19164 +       __shutdown_nx_info(nxi);
19165 +       spin_lock(&nx_info_hash_lock);
19166 +       __unhash_nx_info(nxi);
19167 +       spin_unlock(&nx_info_hash_lock);
19168 +}
19169 +
19170 +/*     lookup_nx_info()
19171 +
19172 +       * search for a nx_info and get() it
19173 +       * negative id means current                             */
19174 +
19175 +struct nx_info *lookup_nx_info(int id)
19176 +{
19177 +       struct nx_info *nxi = NULL;
19178 +
19179 +       if (id < 0) {
19180 +               nxi = get_nx_info(current_nx_info());
19181 +       } else if (id > 1) {
19182 +               spin_lock(&nx_info_hash_lock);
19183 +               nxi = get_nx_info(__lookup_nx_info(id));
19184 +               spin_unlock(&nx_info_hash_lock);
19185 +       }
19186 +       return nxi;
19187 +}
19188 +
19189 +/*     nid_is_hashed()
19190 +
19191 +       * verify that nid is still hashed                       */
19192 +
19193 +int nid_is_hashed(vnid_t nid)
19194 +{
19195 +       int hashed;
19196 +
19197 +       spin_lock(&nx_info_hash_lock);
19198 +       hashed = (__lookup_nx_info(nid) != NULL);
19199 +       spin_unlock(&nx_info_hash_lock);
19200 +       return hashed;
19201 +}
19202 +
19203 +
19204 +#ifdef CONFIG_PROC_FS
19205 +
19206 +/*     get_nid_list()
19207 +
19208 +       * get a subset of hashed nids for proc
19209 +       * assumes size is at least one                          */
19210 +
19211 +int get_nid_list(int index, unsigned int *nids, int size)
19212 +{
19213 +       int hindex, nr_nids = 0;
19214 +
19215 +       /* only show current and children */
19216 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
19217 +               if (index > 0)
19218 +                       return 0;
19219 +               nids[nr_nids] = nx_current_nid();
19220 +               return 1;
19221 +       }
19222 +
19223 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
19224 +               struct hlist_head *head = &nx_info_hash[hindex];
19225 +               struct hlist_node *pos;
19226 +
19227 +               spin_lock(&nx_info_hash_lock);
19228 +               hlist_for_each(pos, head) {
19229 +                       struct nx_info *nxi;
19230 +
19231 +                       if (--index > 0)
19232 +                               continue;
19233 +
19234 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19235 +                       nids[nr_nids] = nxi->nx_id;
19236 +                       if (++nr_nids >= size) {
19237 +                               spin_unlock(&nx_info_hash_lock);
19238 +                               goto out;
19239 +                       }
19240 +               }
19241 +               /* keep the lock time short */
19242 +               spin_unlock(&nx_info_hash_lock);
19243 +       }
19244 +out:
19245 +       return nr_nids;
19246 +}
19247 +#endif
19248 +
19249 +
19250 +/*
19251 + *     migrate task to new network
19252 + *     gets nxi, puts old_nxi on change
19253 + */
19254 +
19255 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
19256 +{
19257 +       struct nx_info *old_nxi;
19258 +       int ret = 0;
19259 +
19260 +       if (!p || !nxi)
19261 +               BUG();
19262 +
19263 +       vxdprintk(VXD_CBIT(nid, 5),
19264 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
19265 +               p, nxi, nxi->nx_id,
19266 +               atomic_read(&nxi->nx_usecnt),
19267 +               atomic_read(&nxi->nx_tasks));
19268 +
19269 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
19270 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19271 +               return -EACCES;
19272 +
19273 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
19274 +               return -EFAULT;
19275 +
19276 +       /* maybe disallow this completely? */
19277 +       old_nxi = task_get_nx_info(p);
19278 +       if (old_nxi == nxi)
19279 +               goto out;
19280 +
19281 +       task_lock(p);
19282 +       if (old_nxi)
19283 +               clr_nx_info(&p->nx_info);
19284 +       claim_nx_info(nxi, p);
19285 +       set_nx_info(&p->nx_info, nxi);
19286 +       p->nid = nxi->nx_id;
19287 +       task_unlock(p);
19288 +
19289 +       vxdprintk(VXD_CBIT(nid, 5),
19290 +               "moved task %p into nxi:%p[#%d]",
19291 +               p, nxi, nxi->nx_id);
19292 +
19293 +       if (old_nxi)
19294 +               release_nx_info(old_nxi, p);
19295 +       ret = 0;
19296 +out:
19297 +       put_nx_info(old_nxi);
19298 +       return ret;
19299 +}
19300 +
19301 +
19302 +void nx_set_persistent(struct nx_info *nxi)
19303 +{
19304 +       vxdprintk(VXD_CBIT(nid, 6),
19305 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
19306 +
19307 +       get_nx_info(nxi);
19308 +       claim_nx_info(nxi, NULL);
19309 +}
19310 +
19311 +void nx_clear_persistent(struct nx_info *nxi)
19312 +{
19313 +       vxdprintk(VXD_CBIT(nid, 6),
19314 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
19315 +
19316 +       release_nx_info(nxi, NULL);
19317 +       put_nx_info(nxi);
19318 +}
19319 +
19320 +void nx_update_persistent(struct nx_info *nxi)
19321 +{
19322 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
19323 +               nx_set_persistent(nxi);
19324 +       else
19325 +               nx_clear_persistent(nxi);
19326 +}
19327 +
19328 +/* vserver syscall commands below here */
19329 +
19330 +/* taks nid and nx_info functions */
19331 +
19332 +#include <asm/uaccess.h>
19333 +
19334 +
19335 +int vc_task_nid(uint32_t id)
19336 +{
19337 +       vnid_t nid;
19338 +
19339 +       if (id) {
19340 +               struct task_struct *tsk;
19341 +
19342 +               rcu_read_lock();
19343 +               tsk = find_task_by_real_pid(id);
19344 +               nid = (tsk) ? tsk->nid : -ESRCH;
19345 +               rcu_read_unlock();
19346 +       } else
19347 +               nid = nx_current_nid();
19348 +       return nid;
19349 +}
19350 +
19351 +
19352 +int vc_nx_info(struct nx_info *nxi, void __user *data)
19353 +{
19354 +       struct vcmd_nx_info_v0 vc_data;
19355 +
19356 +       vc_data.nid = nxi->nx_id;
19357 +
19358 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19359 +               return -EFAULT;
19360 +       return 0;
19361 +}
19362 +
19363 +
19364 +/* network functions */
19365 +
19366 +int vc_net_create(uint32_t nid, void __user *data)
19367 +{
19368 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
19369 +       struct nx_info *new_nxi;
19370 +       int ret;
19371 +
19372 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19373 +               return -EFAULT;
19374 +
19375 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
19376 +               return -EINVAL;
19377 +
19378 +       new_nxi = __create_nx_info(nid);
19379 +       if (IS_ERR(new_nxi))
19380 +               return PTR_ERR(new_nxi);
19381 +
19382 +       /* initial flags */
19383 +       new_nxi->nx_flags = vc_data.flagword;
19384 +
19385 +       ret = -ENOEXEC;
19386 +       if (vs_net_change(new_nxi, VSC_NETUP))
19387 +               goto out;
19388 +
19389 +       ret = nx_migrate_task(current, new_nxi);
19390 +       if (ret)
19391 +               goto out;
19392 +
19393 +       /* return context id on success */
19394 +       ret = new_nxi->nx_id;
19395 +
19396 +       /* get a reference for persistent contexts */
19397 +       if ((vc_data.flagword & NXF_PERSISTENT))
19398 +               nx_set_persistent(new_nxi);
19399 +out:
19400 +       release_nx_info(new_nxi, NULL);
19401 +       put_nx_info(new_nxi);
19402 +       return ret;
19403 +}
19404 +
19405 +
19406 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
19407 +{
19408 +       return nx_migrate_task(current, nxi);
19409 +}
19410 +
19411 +
19412 +static inline
19413 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
19414 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
19415 +       struct nx_addr_v4 **prev)
19416 +{
19417 +       struct nx_addr_v4 *nxa = &nxi->v4;
19418 +
19419 +       for (; nxa; nxa = nxa->next) {
19420 +               if ((nxa->ip[0].s_addr == ip) &&
19421 +                   (nxa->ip[1].s_addr == ip2) &&
19422 +                   (nxa->mask.s_addr == mask) &&
19423 +                   (nxa->type == type) &&
19424 +                   (nxa->flags == flags))
19425 +                   return nxa;
19426 +
19427 +               /* save previous entry */
19428 +               if (prev)
19429 +                       *prev = nxa;
19430 +       }
19431 +       return NULL;
19432 +}
19433 +
19434 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19435 +       uint16_t type, uint16_t flags)
19436 +{
19437 +       struct nx_addr_v4 *nxa = NULL;
19438 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
19439 +       unsigned long irqflags;
19440 +       int ret = -EEXIST;
19441 +
19442 +       if (IS_ERR(new))
19443 +               return PTR_ERR(new);
19444 +
19445 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19446 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
19447 +               goto out_unlock;
19448 +
19449 +       if (NX_IPV4(nxi)) {
19450 +               nxa->next = new;
19451 +               nxa = new;
19452 +               new = NULL;
19453 +
19454 +               /* remove single ip for ip list */
19455 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
19456 +       }
19457 +
19458 +       nxa->ip[0].s_addr = ip;
19459 +       nxa->ip[1].s_addr = ip2;
19460 +       nxa->mask.s_addr = mask;
19461 +       nxa->type = type;
19462 +       nxa->flags = flags;
19463 +       ret = 0;
19464 +out_unlock:
19465 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19466 +       if (new)
19467 +               __dealloc_nx_addr_v4(new);
19468 +       return ret;
19469 +}
19470 +
19471 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19472 +       uint16_t type, uint16_t flags)
19473 +{
19474 +       struct nx_addr_v4 *nxa = NULL;
19475 +       struct nx_addr_v4 *old = NULL;
19476 +       unsigned long irqflags;
19477 +       int ret = 0;
19478 +
19479 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19480 +       switch (type) {
19481 +       case NXA_TYPE_ADDR:
19482 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
19483 +               if (old) {
19484 +                       if (nxa) {
19485 +                               nxa->next = old->next;
19486 +                               old->next = NULL;
19487 +                       } else {
19488 +                               if (old->next) {
19489 +                                       nxa = old;
19490 +                                       old = old->next;
19491 +                                       *nxa = *old;
19492 +                                       old->next = NULL;
19493 +                               } else {
19494 +                                       memset(old, 0, sizeof(*old));
19495 +                                       old = NULL;
19496 +                               }
19497 +                       }
19498 +               } else
19499 +                       ret = -ESRCH;
19500 +               break;
19501 +
19502 +       case NXA_TYPE_ANY:
19503 +               nxa = &nxi->v4;
19504 +               old = nxa->next;
19505 +               memset(nxa, 0, sizeof(*nxa));
19506 +               break;
19507 +
19508 +       default:
19509 +               ret = -EINVAL;
19510 +       }
19511 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19512 +       __dealloc_nx_addr_v4_all(old);
19513 +       return ret;
19514 +}
19515 +
19516 +
19517 +int vc_net_add(struct nx_info *nxi, void __user *data)
19518 +{
19519 +       struct vcmd_net_addr_v0 vc_data;
19520 +       int index, ret = 0;
19521 +
19522 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19523 +               return -EFAULT;
19524 +
19525 +       switch (vc_data.type) {
19526 +       case NXA_TYPE_IPV4:
19527 +               if ((vc_data.count < 1) || (vc_data.count > 4))
19528 +                       return -EINVAL;
19529 +
19530 +               index = 0;
19531 +               while (index < vc_data.count) {
19532 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
19533 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
19534 +                       if (ret)
19535 +                               return ret;
19536 +                       index++;
19537 +               }
19538 +               ret = index;
19539 +               break;
19540 +
19541 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
19542 +               nxi->v4_bcast = vc_data.ip[0];
19543 +               ret = 1;
19544 +               break;
19545 +
19546 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
19547 +               nxi->v4_lback = vc_data.ip[0];
19548 +               ret = 1;
19549 +               break;
19550 +
19551 +       default:
19552 +               ret = -EINVAL;
19553 +               break;
19554 +       }
19555 +       return ret;
19556 +}
19557 +
19558 +int vc_net_remove(struct nx_info *nxi, void __user *data)
19559 +{
19560 +       struct vcmd_net_addr_v0 vc_data;
19561 +
19562 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19563 +               return -EFAULT;
19564 +
19565 +       switch (vc_data.type) {
19566 +       case NXA_TYPE_ANY:
19567 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
19568 +       default:
19569 +               return -EINVAL;
19570 +       }
19571 +       return 0;
19572 +}
19573 +
19574 +
19575 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
19576 +{
19577 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19578 +
19579 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19580 +               return -EFAULT;
19581 +
19582 +       switch (vc_data.type) {
19583 +       case NXA_TYPE_ADDR:
19584 +       case NXA_TYPE_MASK:
19585 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
19586 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19587 +
19588 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19589 +               nxi->v4_bcast = vc_data.ip;
19590 +               break;
19591 +
19592 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19593 +               nxi->v4_lback = vc_data.ip;
19594 +               break;
19595 +
19596 +       default:
19597 +               return -EINVAL;
19598 +       }
19599 +       return 0;
19600 +}
19601 +
19602 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
19603 +{
19604 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19605 +
19606 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19607 +               return -EFAULT;
19608 +
19609 +       switch (vc_data.type) {
19610 +       case NXA_TYPE_ADDR:
19611 +       case NXA_TYPE_MASK:
19612 +       case NXA_TYPE_RANGE:
19613 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19614 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19615 +
19616 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19617 +               nxi->v4_bcast = vc_data.ip;
19618 +               break;
19619 +
19620 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19621 +               nxi->v4_lback = vc_data.ip;
19622 +               break;
19623 +
19624 +       default:
19625 +               return -EINVAL;
19626 +       }
19627 +       return 0;
19628 +}
19629 +
19630 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
19631 +{
19632 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19633 +
19634 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19635 +               return -EFAULT;
19636 +
19637 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
19638 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19639 +}
19640 +
19641 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
19642 +{
19643 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19644 +
19645 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19646 +               return -EFAULT;
19647 +
19648 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19649 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19650 +}
19651 +
19652 +#ifdef CONFIG_IPV6
19653 +
19654 +static inline
19655 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
19656 +       struct in6_addr *ip, struct in6_addr *mask,
19657 +       uint32_t prefix, uint16_t type, uint16_t flags,
19658 +       struct nx_addr_v6 **prev)
19659 +{
19660 +       struct nx_addr_v6 *nxa = &nxi->v6;
19661 +
19662 +       for (; nxa; nxa = nxa->next) {
19663 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
19664 +                   ipv6_addr_equal(&nxa->mask, mask) &&
19665 +                   (nxa->prefix == prefix) &&
19666 +                   (nxa->type == type) &&
19667 +                   (nxa->flags == flags))
19668 +                   return nxa;
19669 +
19670 +               /* save previous entry */
19671 +               if (prev)
19672 +                       *prev = nxa;
19673 +       }
19674 +       return NULL;
19675 +}
19676 +
19677 +
19678 +int do_add_v6_addr(struct nx_info *nxi,
19679 +       struct in6_addr *ip, struct in6_addr *mask,
19680 +       uint32_t prefix, uint16_t type, uint16_t flags)
19681 +{
19682 +       struct nx_addr_v6 *nxa = NULL;
19683 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
19684 +       unsigned long irqflags;
19685 +       int ret = -EEXIST;
19686 +
19687 +       if (IS_ERR(new))
19688 +               return PTR_ERR(new);
19689 +
19690 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19691 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
19692 +               goto out_unlock;
19693 +
19694 +       if (NX_IPV6(nxi)) {
19695 +               nxa->next = new;
19696 +               nxa = new;
19697 +               new = NULL;
19698 +       }
19699 +
19700 +       nxa->ip = *ip;
19701 +       nxa->mask = *mask;
19702 +       nxa->prefix = prefix;
19703 +       nxa->type = type;
19704 +       nxa->flags = flags;
19705 +       ret = 0;
19706 +out_unlock:
19707 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19708 +       if (new)
19709 +               __dealloc_nx_addr_v6(new);
19710 +       return ret;
19711 +}
19712 +
19713 +int do_remove_v6_addr(struct nx_info *nxi,
19714 +       struct in6_addr *ip, struct in6_addr *mask,
19715 +       uint32_t prefix, uint16_t type, uint16_t flags)
19716 +{
19717 +       struct nx_addr_v6 *nxa = NULL;
19718 +       struct nx_addr_v6 *old = NULL;
19719 +       unsigned long irqflags;
19720 +       int ret = 0;
19721 +
19722 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19723 +       switch (type) {
19724 +       case NXA_TYPE_ADDR:
19725 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
19726 +               if (old) {
19727 +                       if (nxa) {
19728 +                               nxa->next = old->next;
19729 +                               old->next = NULL;
19730 +                       } else {
19731 +                               if (old->next) {
19732 +                                       nxa = old;
19733 +                                       old = old->next;
19734 +                                       *nxa = *old;
19735 +                                       old->next = NULL;
19736 +                               } else {
19737 +                                       memset(old, 0, sizeof(*old));
19738 +                                       old = NULL;
19739 +                               }
19740 +                       }
19741 +               } else
19742 +                       ret = -ESRCH;
19743 +               break;
19744 +
19745 +       case NXA_TYPE_ANY:
19746 +               nxa = &nxi->v6;
19747 +               old = nxa->next;
19748 +               memset(nxa, 0, sizeof(*nxa));
19749 +               break;
19750 +
19751 +       default:
19752 +               ret = -EINVAL;
19753 +       }
19754 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19755 +       __dealloc_nx_addr_v6_all(old);
19756 +       return ret;
19757 +}
19758 +
19759 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
19760 +{
19761 +       struct vcmd_net_addr_ipv6_v1 vc_data;
19762 +
19763 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19764 +               return -EFAULT;
19765 +
19766 +       switch (vc_data.type) {
19767 +       case NXA_TYPE_ADDR:
19768 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
19769 +               /* fallthrough */
19770 +       case NXA_TYPE_MASK:
19771 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
19772 +                       vc_data.prefix, vc_data.type, vc_data.flags);
19773 +       default:
19774 +               return -EINVAL;
19775 +       }
19776 +       return 0;
19777 +}
19778 +
19779 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
19780 +{
19781 +       struct vcmd_net_addr_ipv6_v1 vc_data;
19782 +
19783 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19784 +               return -EFAULT;
19785 +
19786 +       switch (vc_data.type) {
19787 +       case NXA_TYPE_ADDR:
19788 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
19789 +               /* fallthrough */
19790 +       case NXA_TYPE_MASK:
19791 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
19792 +                       vc_data.prefix, vc_data.type, vc_data.flags);
19793 +       case NXA_TYPE_ANY:
19794 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
19795 +       default:
19796 +               return -EINVAL;
19797 +       }
19798 +       return 0;
19799 +}
19800 +
19801 +#endif /* CONFIG_IPV6 */
19802 +
19803 +
19804 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
19805 +{
19806 +       struct vcmd_net_flags_v0 vc_data;
19807 +
19808 +       vc_data.flagword = nxi->nx_flags;
19809 +
19810 +       /* special STATE flag handling */
19811 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
19812 +
19813 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19814 +               return -EFAULT;
19815 +       return 0;
19816 +}
19817 +
19818 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
19819 +{
19820 +       struct vcmd_net_flags_v0 vc_data;
19821 +       uint64_t mask, trigger;
19822 +
19823 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19824 +               return -EFAULT;
19825 +
19826 +       /* special STATE flag handling */
19827 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
19828 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
19829 +
19830 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
19831 +               vc_data.flagword, mask);
19832 +       if (trigger & NXF_PERSISTENT)
19833 +               nx_update_persistent(nxi);
19834 +
19835 +       return 0;
19836 +}
19837 +
19838 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
19839 +{
19840 +       struct vcmd_net_caps_v0 vc_data;
19841 +
19842 +       vc_data.ncaps = nxi->nx_ncaps;
19843 +       vc_data.cmask = ~0ULL;
19844 +
19845 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19846 +               return -EFAULT;
19847 +       return 0;
19848 +}
19849 +
19850 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
19851 +{
19852 +       struct vcmd_net_caps_v0 vc_data;
19853 +
19854 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19855 +               return -EFAULT;
19856 +
19857 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
19858 +               vc_data.ncaps, vc_data.cmask);
19859 +       return 0;
19860 +}
19861 +
19862 +
19863 +#include <linux/module.h>
19864 +
19865 +module_init(init_network);
19866 +
19867 +EXPORT_SYMBOL_GPL(free_nx_info);
19868 +EXPORT_SYMBOL_GPL(unhash_nx_info);
19869 +
19870 diff -NurpP --minimal linux-4.4.110/kernel/vserver/proc.c linux-4.4.110-vs2.3.9/kernel/vserver/proc.c
19871 --- linux-4.4.110/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
19872 +++ linux-4.4.110-vs2.3.9/kernel/vserver/proc.c 2018-01-09 16:36:34.000000000 +0000
19873 @@ -0,0 +1,1100 @@
19874 +/*
19875 + *  linux/kernel/vserver/proc.c
19876 + *
19877 + *  Virtual Context Support
19878 + *
19879 + *  Copyright (C) 2003-2011  Herbert P?tzl
19880 + *
19881 + *  V0.01  basic structure
19882 + *  V0.02  adaptation vs1.3.0
19883 + *  V0.03  proc permissions
19884 + *  V0.04  locking/generic
19885 + *  V0.05  next generation procfs
19886 + *  V0.06  inode validation
19887 + *  V0.07  generic rewrite vid
19888 + *  V0.08  remove inode type
19889 + *  V0.09  added u/wmask info
19890 + *
19891 + */
19892 +
19893 +#include <linux/proc_fs.h>
19894 +#include <linux/fs_struct.h>
19895 +#include <linux/mount.h>
19896 +#include <linux/namei.h>
19897 +#include <asm/unistd.h>
19898 +
19899 +#include <linux/vs_context.h>
19900 +#include <linux/vs_network.h>
19901 +#include <linux/vs_cvirt.h>
19902 +
19903 +#include <linux/in.h>
19904 +#include <linux/inetdevice.h>
19905 +#include <linux/vs_inet.h>
19906 +#include <linux/vs_inet6.h>
19907 +
19908 +#include <linux/vserver/global.h>
19909 +
19910 +#include "cvirt_proc.h"
19911 +#include "cacct_proc.h"
19912 +#include "limit_proc.h"
19913 +#include "sched_proc.h"
19914 +#include "vci_config.h"
19915 +
19916 +#include <../../fs/proc/internal.h>
19917 +
19918 +
19919 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
19920 +{
19921 +       unsigned __capi;
19922 +
19923 +       CAP_FOR_EACH_U32(__capi) {
19924 +               buffer += sprintf(buffer, "%08x",
19925 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
19926 +       }
19927 +       return buffer;
19928 +}
19929 +
19930 +
19931 +static struct proc_dir_entry *proc_virtual;
19932 +
19933 +static struct proc_dir_entry *proc_virtnet;
19934 +
19935 +
19936 +/* first the actual feeds */
19937 +
19938 +
19939 +static int proc_vci(char *buffer)
19940 +{
19941 +       return sprintf(buffer,
19942 +               "VCIVersion:\t%04x:%04x\n"
19943 +               "VCISyscall:\t%d\n"
19944 +               "VCIKernel:\t%08x\n",
19945 +               VCI_VERSION >> 16,
19946 +               VCI_VERSION & 0xFFFF,
19947 +               __NR_vserver,
19948 +               vci_kernel_config());
19949 +}
19950 +
19951 +static int proc_virtual_info(char *buffer)
19952 +{
19953 +       return proc_vci(buffer);
19954 +}
19955 +
19956 +static int proc_virtual_status(char *buffer)
19957 +{
19958 +       return sprintf(buffer,
19959 +               "#CTotal:\t%d\n"
19960 +               "#CActive:\t%d\n"
19961 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
19962 +               "#InitTask:\t%d\t%d %d\n",
19963 +               atomic_read(&vx_global_ctotal),
19964 +               atomic_read(&vx_global_cactive),
19965 +               atomic_read(&vs_global_nsproxy),
19966 +               atomic_read(&vs_global_fs),
19967 +               atomic_read(&vs_global_mnt_ns),
19968 +               atomic_read(&vs_global_uts_ns),
19969 +               atomic_read(&nr_ipc_ns),
19970 +               atomic_read(&vs_global_user_ns),
19971 +               atomic_read(&vs_global_pid_ns),
19972 +               atomic_read(&init_task.usage),
19973 +               atomic_read(&init_task.nsproxy->count),
19974 +               init_task.fs->users);
19975 +}
19976 +
19977 +
19978 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
19979 +{
19980 +       int length;
19981 +
19982 +       length = sprintf(buffer,
19983 +               "ID:\t%d\n"
19984 +               "Info:\t%p\n"
19985 +               "Init:\t%d\n"
19986 +               "OOM:\t%lld\n",
19987 +               vxi->vx_id,
19988 +               vxi,
19989 +               vxi->vx_initpid,
19990 +               vxi->vx_badness_bias);
19991 +       return length;
19992 +}
19993 +
19994 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
19995 +{
19996 +       char *orig = buffer;
19997 +
19998 +       buffer += sprintf(buffer,
19999 +               "UseCnt:\t%d\n"
20000 +               "Tasks:\t%d\n"
20001 +               "Flags:\t%016llx\n",
20002 +               atomic_read(&vxi->vx_usecnt),
20003 +               atomic_read(&vxi->vx_tasks),
20004 +               (unsigned long long)vxi->vx_flags);
20005 +
20006 +       buffer += sprintf(buffer, "BCaps:\t");
20007 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20008 +       buffer += sprintf(buffer, "\n");
20009 +
20010 +       buffer += sprintf(buffer,
20011 +               "CCaps:\t%016llx\n"
20012 +               "Umask:\t%16llx\n"
20013 +               "Wmask:\t%16llx\n"
20014 +               "Spaces:\t%08lx %08lx\n",
20015 +               (unsigned long long)vxi->vx_ccaps,
20016 +               (unsigned long long)vxi->vx_umask,
20017 +               (unsigned long long)vxi->vx_wmask,
20018 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20019 +       return buffer - orig;
20020 +}
20021 +
20022 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20023 +{
20024 +       return vx_info_proc_limit(&vxi->limit, buffer);
20025 +}
20026 +
20027 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20028 +{
20029 +       int cpu, length;
20030 +
20031 +       length = vx_info_proc_sched(&vxi->sched, buffer);
20032 +       for_each_online_cpu(cpu) {
20033 +               length += vx_info_proc_sched_pc(
20034 +                       &vx_per_cpu(vxi, sched_pc, cpu),
20035 +                       buffer + length, cpu);
20036 +       }
20037 +       return length;
20038 +}
20039 +
20040 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20041 +{
20042 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20043 +}
20044 +
20045 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20046 +{
20047 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20048 +}
20049 +
20050 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20051 +{
20052 +       int cpu, length;
20053 +
20054 +       vx_update_load(vxi);
20055 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20056 +       for_each_online_cpu(cpu) {
20057 +               length += vx_info_proc_cvirt_pc(
20058 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
20059 +                       buffer + length, cpu);
20060 +       }
20061 +       return length;
20062 +}
20063 +
20064 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20065 +{
20066 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
20067 +}
20068 +
20069 +
20070 +static int proc_virtnet_info(char *buffer)
20071 +{
20072 +       return proc_vci(buffer);
20073 +}
20074 +
20075 +static int proc_virtnet_status(char *buffer)
20076 +{
20077 +       return sprintf(buffer,
20078 +               "#CTotal:\t%d\n"
20079 +               "#CActive:\t%d\n",
20080 +               atomic_read(&nx_global_ctotal),
20081 +               atomic_read(&nx_global_cactive));
20082 +}
20083 +
20084 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
20085 +{
20086 +       struct nx_addr_v4 *v4a;
20087 +#ifdef CONFIG_IPV6
20088 +       struct nx_addr_v6 *v6a;
20089 +#endif
20090 +       int length, i;
20091 +
20092 +       length = sprintf(buffer,
20093 +               "ID:\t%d\n"
20094 +               "Info:\t%p\n"
20095 +               "Bcast:\t" NIPQUAD_FMT "\n"
20096 +               "Lback:\t" NIPQUAD_FMT "\n",
20097 +               nxi->nx_id,
20098 +               nxi,
20099 +               NIPQUAD(nxi->v4_bcast.s_addr),
20100 +               NIPQUAD(nxi->v4_lback.s_addr));
20101 +
20102 +       if (!NX_IPV4(nxi))
20103 +               goto skip_v4;
20104 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20105 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20106 +                       i, NXAV4(v4a));
20107 +skip_v4:
20108 +#ifdef CONFIG_IPV6
20109 +       if (!NX_IPV6(nxi))
20110 +               goto skip_v6;
20111 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20112 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
20113 +                       i, NXAV6(v6a));
20114 +skip_v6:
20115 +#endif
20116 +       return length;
20117 +}
20118 +
20119 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
20120 +{
20121 +       int length;
20122 +
20123 +       length = sprintf(buffer,
20124 +               "UseCnt:\t%d\n"
20125 +               "Tasks:\t%d\n"
20126 +               "Flags:\t%016llx\n"
20127 +               "NCaps:\t%016llx\n",
20128 +               atomic_read(&nxi->nx_usecnt),
20129 +               atomic_read(&nxi->nx_tasks),
20130 +               (unsigned long long)nxi->nx_flags,
20131 +               (unsigned long long)nxi->nx_ncaps);
20132 +       return length;
20133 +}
20134 +
20135 +
20136 +
20137 +/* here the inode helpers */
20138 +
20139 +struct vs_entry {
20140 +       int len;
20141 +       char *name;
20142 +       mode_t mode;
20143 +       struct inode_operations *iop;
20144 +       struct file_operations *fop;
20145 +       union proc_op op;
20146 +};
20147 +
20148 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
20149 +{
20150 +       struct inode *inode = new_inode(sb);
20151 +
20152 +       if (!inode)
20153 +               goto out;
20154 +
20155 +       inode->i_mode = p->mode;
20156 +       if (p->iop)
20157 +               inode->i_op = p->iop;
20158 +       if (p->fop)
20159 +               inode->i_fop = p->fop;
20160 +
20161 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
20162 +       inode->i_flags |= S_IMMUTABLE;
20163 +
20164 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
20165 +
20166 +       i_uid_write(inode, 0);
20167 +       i_gid_write(inode, 0);
20168 +       i_tag_write(inode, 0);
20169 +out:
20170 +       return inode;
20171 +}
20172 +
20173 +static struct dentry *vs_proc_instantiate(struct inode *dir,
20174 +       struct dentry *dentry, int id, void *ptr)
20175 +{
20176 +       struct vs_entry *p = ptr;
20177 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
20178 +       struct dentry *error = ERR_PTR(-EINVAL);
20179 +
20180 +       if (!inode)
20181 +               goto out;
20182 +
20183 +       PROC_I(inode)->op = p->op;
20184 +       PROC_I(inode)->fd = id;
20185 +       d_add(dentry, inode);
20186 +       error = NULL;
20187 +out:
20188 +       return error;
20189 +}
20190 +
20191 +/* Lookups */
20192 +
20193 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
20194 +
20195 +
20196 +/*
20197 + * Fill a directory entry.
20198 + *
20199 + * If possible create the dcache entry and derive our inode number and
20200 + * file type from dcache entry.
20201 + *
20202 + * Since all of the proc inode numbers are dynamically generated, the inode
20203 + * numbers do not exist until the inode is cache.  This means creating the
20204 + * the dcache entry in iterate is necessary to keep the inode numbers
20205 + * reported by iterate in sync with the inode numbers reported
20206 + * by stat.
20207 + */
20208 +static int vx_proc_fill_cache(struct file *filp, struct dir_context *ctx,
20209 +       char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
20210 +{
20211 +       struct dentry *child, *dir = filp->f_path.dentry;
20212 +       struct inode *inode;
20213 +       struct qstr qname;
20214 +       ino_t ino = 0;
20215 +       unsigned type = DT_UNKNOWN;
20216 +
20217 +       qname.name = name;
20218 +       qname.len  = len;
20219 +       qname.hash = full_name_hash(name, len);
20220 +
20221 +       child = d_lookup(dir, &qname);
20222 +       if (!child) {
20223 +               struct dentry *new;
20224 +               new = d_alloc(dir, &qname);
20225 +               if (new) {
20226 +                       child = instantiate(dir->d_inode, new, id, ptr);
20227 +                       if (child)
20228 +                               dput(new);
20229 +                       else
20230 +                               child = new;
20231 +               }
20232 +       }
20233 +       if (!child || IS_ERR(child) || !child->d_inode)
20234 +               goto end_instantiate;
20235 +       inode = child->d_inode;
20236 +       if (inode) {
20237 +               ino = inode->i_ino;
20238 +               type = inode->i_mode >> 12;
20239 +       }
20240 +       dput(child);
20241 +end_instantiate:
20242 +       if (!ino)
20243 +               ino = 1;
20244 +       return !dir_emit(ctx, name, len, ino, type);
20245 +}
20246 +
20247 +
20248 +
20249 +/* get and revalidate vx_info/xid */
20250 +
20251 +static inline
20252 +struct vx_info *get_proc_vx_info(struct inode *inode)
20253 +{
20254 +       return lookup_vx_info(PROC_I(inode)->fd);
20255 +}
20256 +
20257 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
20258 +{
20259 +       struct inode *inode = dentry->d_inode;
20260 +       vxid_t xid = PROC_I(inode)->fd;
20261 +
20262 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20263 +               return -ECHILD;
20264 +
20265 +       if (!xid || xid_is_hashed(xid))
20266 +               return 1;
20267 +       d_drop(dentry);
20268 +       return 0;
20269 +}
20270 +
20271 +
20272 +/* get and revalidate nx_info/nid */
20273 +
20274 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
20275 +{
20276 +       struct inode *inode = dentry->d_inode;
20277 +       vnid_t nid = PROC_I(inode)->fd;
20278 +
20279 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20280 +               return -ECHILD;
20281 +
20282 +       if (!nid || nid_is_hashed(nid))
20283 +               return 1;
20284 +       d_drop(dentry);
20285 +       return 0;
20286 +}
20287 +
20288 +
20289 +
20290 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
20291 +
20292 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
20293 +                         size_t count, loff_t *ppos)
20294 +{
20295 +       struct inode *inode = file->f_path.dentry->d_inode;
20296 +       unsigned long page;
20297 +       ssize_t length = 0;
20298 +
20299 +       if (count > PROC_BLOCK_SIZE)
20300 +               count = PROC_BLOCK_SIZE;
20301 +
20302 +       /* fade that out as soon as stable */
20303 +       WARN_ON(PROC_I(inode)->fd);
20304 +
20305 +       if (!(page = __get_free_page(GFP_KERNEL)))
20306 +               return -ENOMEM;
20307 +
20308 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
20309 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
20310 +
20311 +       if (length >= 0)
20312 +               length = simple_read_from_buffer(buf, count, ppos,
20313 +                       (char *)page, length);
20314 +
20315 +       free_page(page);
20316 +       return length;
20317 +}
20318 +
20319 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
20320 +                         size_t count, loff_t *ppos)
20321 +{
20322 +       struct inode *inode = file->f_path.dentry->d_inode;
20323 +       struct vx_info *vxi = NULL;
20324 +       vxid_t xid = PROC_I(inode)->fd;
20325 +       unsigned long page;
20326 +       ssize_t length = 0;
20327 +
20328 +       if (count > PROC_BLOCK_SIZE)
20329 +               count = PROC_BLOCK_SIZE;
20330 +
20331 +       /* fade that out as soon as stable */
20332 +       WARN_ON(!xid);
20333 +       vxi = lookup_vx_info(xid);
20334 +       if (!vxi)
20335 +               goto out;
20336 +
20337 +       length = -ENOMEM;
20338 +       if (!(page = __get_free_page(GFP_KERNEL)))
20339 +               goto out_put;
20340 +
20341 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
20342 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
20343 +
20344 +       if (length >= 0)
20345 +               length = simple_read_from_buffer(buf, count, ppos,
20346 +                       (char *)page, length);
20347 +
20348 +       free_page(page);
20349 +out_put:
20350 +       put_vx_info(vxi);
20351 +out:
20352 +       return length;
20353 +}
20354 +
20355 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
20356 +                         size_t count, loff_t *ppos)
20357 +{
20358 +       struct inode *inode = file->f_path.dentry->d_inode;
20359 +       struct nx_info *nxi = NULL;
20360 +       vnid_t nid = PROC_I(inode)->fd;
20361 +       unsigned long page;
20362 +       ssize_t length = 0;
20363 +
20364 +       if (count > PROC_BLOCK_SIZE)
20365 +               count = PROC_BLOCK_SIZE;
20366 +
20367 +       /* fade that out as soon as stable */
20368 +       WARN_ON(!nid);
20369 +       nxi = lookup_nx_info(nid);
20370 +       if (!nxi)
20371 +               goto out;
20372 +
20373 +       length = -ENOMEM;
20374 +       if (!(page = __get_free_page(GFP_KERNEL)))
20375 +               goto out_put;
20376 +
20377 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
20378 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
20379 +
20380 +       if (length >= 0)
20381 +               length = simple_read_from_buffer(buf, count, ppos,
20382 +                       (char *)page, length);
20383 +
20384 +       free_page(page);
20385 +out_put:
20386 +       put_nx_info(nxi);
20387 +out:
20388 +       return length;
20389 +}
20390 +
20391 +
20392 +
20393 +/* here comes the lower level */
20394 +
20395 +
20396 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
20397 +       .len  = sizeof(NAME) - 1,       \
20398 +       .name = (NAME),                 \
20399 +       .mode = MODE,                   \
20400 +       .iop  = IOP,                    \
20401 +       .fop  = FOP,                    \
20402 +       .op   = OP,                     \
20403 +}
20404 +
20405 +
20406 +#define DIR(NAME, MODE, OTYPE)                         \
20407 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
20408 +               &proc_ ## OTYPE ## _inode_operations,   \
20409 +               &proc_ ## OTYPE ## _file_operations, { } )
20410 +
20411 +#define INF(NAME, MODE, OTYPE)                         \
20412 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20413 +               &proc_vs_info_file_operations,          \
20414 +               { .proc_vs_read = &proc_##OTYPE } )
20415 +
20416 +#define VINF(NAME, MODE, OTYPE)                                \
20417 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20418 +               &proc_vx_info_file_operations,          \
20419 +               { .proc_vxi_read = &proc_##OTYPE } )
20420 +
20421 +#define NINF(NAME, MODE, OTYPE)                                \
20422 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20423 +               &proc_nx_info_file_operations,          \
20424 +               { .proc_nxi_read = &proc_##OTYPE } )
20425 +
20426 +
20427 +static struct file_operations proc_vs_info_file_operations = {
20428 +       .read =         proc_vs_info_read,
20429 +};
20430 +
20431 +static struct file_operations proc_vx_info_file_operations = {
20432 +       .read =         proc_vx_info_read,
20433 +};
20434 +
20435 +static struct dentry_operations proc_xid_dentry_operations = {
20436 +       .d_revalidate = proc_xid_revalidate,
20437 +};
20438 +
20439 +static struct vs_entry vx_base_stuff[] = {
20440 +       VINF("info",    S_IRUGO, vxi_info),
20441 +       VINF("status",  S_IRUGO, vxi_status),
20442 +       VINF("limit",   S_IRUGO, vxi_limit),
20443 +       VINF("sched",   S_IRUGO, vxi_sched),
20444 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
20445 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
20446 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
20447 +       VINF("cacct",   S_IRUGO, vxi_cacct),
20448 +       {}
20449 +};
20450 +
20451 +
20452 +
20453 +
20454 +static struct dentry *proc_xid_instantiate(struct inode *dir,
20455 +       struct dentry *dentry, int id, void *ptr)
20456 +{
20457 +       dentry->d_op = &proc_xid_dentry_operations;
20458 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20459 +}
20460 +
20461 +static struct dentry *proc_xid_lookup(struct inode *dir,
20462 +       struct dentry *dentry, unsigned int flags)
20463 +{
20464 +       struct vs_entry *p = vx_base_stuff;
20465 +       struct dentry *error = ERR_PTR(-ENOENT);
20466 +
20467 +       for (; p->name; p++) {
20468 +               if (p->len != dentry->d_name.len)
20469 +                       continue;
20470 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20471 +                       break;
20472 +       }
20473 +       if (!p->name)
20474 +               goto out;
20475 +
20476 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20477 +out:
20478 +       return error;
20479 +}
20480 +
20481 +static int proc_xid_iterate(struct file *filp, struct dir_context *ctx)
20482 +{
20483 +       struct dentry *dentry = filp->f_path.dentry;
20484 +       struct inode *inode = dentry->d_inode;
20485 +       struct vs_entry *p = vx_base_stuff;
20486 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
20487 +       int index;
20488 +       u64 ino;
20489 +
20490 +       switch (ctx->pos) {
20491 +       case 0:
20492 +               ino = inode->i_ino;
20493 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20494 +                       goto out;
20495 +               ctx->pos++;
20496 +               /* fall through */
20497 +       case 1:
20498 +               ino = parent_ino(dentry);
20499 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20500 +                       goto out;
20501 +               ctx->pos++;
20502 +               /* fall through */
20503 +       default:
20504 +               index = ctx->pos - 2;
20505 +               if (index >= size)
20506 +                       goto out;
20507 +               for (p += index; p->name; p++) {
20508 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20509 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20510 +                               goto out;
20511 +                       ctx->pos++;
20512 +               }
20513 +       }
20514 +out:
20515 +       return 1;
20516 +}
20517 +
20518 +
20519 +
20520 +static struct file_operations proc_nx_info_file_operations = {
20521 +       .read =         proc_nx_info_read,
20522 +};
20523 +
20524 +static struct dentry_operations proc_nid_dentry_operations = {
20525 +       .d_revalidate = proc_nid_revalidate,
20526 +};
20527 +
20528 +static struct vs_entry nx_base_stuff[] = {
20529 +       NINF("info",    S_IRUGO, nxi_info),
20530 +       NINF("status",  S_IRUGO, nxi_status),
20531 +       {}
20532 +};
20533 +
20534 +
20535 +static struct dentry *proc_nid_instantiate(struct inode *dir,
20536 +       struct dentry *dentry, int id, void *ptr)
20537 +{
20538 +       dentry->d_op = &proc_nid_dentry_operations;
20539 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20540 +}
20541 +
20542 +static struct dentry *proc_nid_lookup(struct inode *dir,
20543 +       struct dentry *dentry, unsigned int flags)
20544 +{
20545 +       struct vs_entry *p = nx_base_stuff;
20546 +       struct dentry *error = ERR_PTR(-ENOENT);
20547 +
20548 +       for (; p->name; p++) {
20549 +               if (p->len != dentry->d_name.len)
20550 +                       continue;
20551 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20552 +                       break;
20553 +       }
20554 +       if (!p->name)
20555 +               goto out;
20556 +
20557 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20558 +out:
20559 +       return error;
20560 +}
20561 +
20562 +static int proc_nid_iterate(struct file *filp, struct dir_context *ctx)
20563 +{
20564 +       struct dentry *dentry = filp->f_path.dentry;
20565 +       struct inode *inode = dentry->d_inode;
20566 +       struct vs_entry *p = nx_base_stuff;
20567 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
20568 +       int index;
20569 +       u64 ino;
20570 +
20571 +       switch (ctx->pos) {
20572 +       case 0:
20573 +               ino = inode->i_ino;
20574 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20575 +                       goto out;
20576 +               ctx->pos++;
20577 +               /* fall through */
20578 +       case 1:
20579 +               ino = parent_ino(dentry);
20580 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20581 +                       goto out;
20582 +               ctx->pos++;
20583 +               /* fall through */
20584 +       default:
20585 +               index = ctx->pos - 2;
20586 +               if (index >= size)
20587 +                       goto out;
20588 +               for (p += index; p->name; p++) {
20589 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20590 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20591 +                               goto out;
20592 +                       ctx->pos++;
20593 +               }
20594 +       }
20595 +out:
20596 +       return 1;
20597 +}
20598 +
20599 +
20600 +#define MAX_MULBY10    ((~0U - 9) / 10)
20601 +
20602 +static inline int atovid(const char *str, int len)
20603 +{
20604 +       int vid, c;
20605 +
20606 +       vid = 0;
20607 +       while (len-- > 0) {
20608 +               c = *str - '0';
20609 +               str++;
20610 +               if (c > 9)
20611 +                       return -1;
20612 +               if (vid >= MAX_MULBY10)
20613 +                       return -1;
20614 +               vid *= 10;
20615 +               vid += c;
20616 +               if (!vid)
20617 +                       return -1;
20618 +       }
20619 +       return vid;
20620 +}
20621 +
20622 +/* now the upper level (virtual) */
20623 +
20624 +
20625 +static struct file_operations proc_xid_file_operations = {
20626 +       .read =         generic_read_dir,
20627 +       .iterate =      proc_xid_iterate,
20628 +};
20629 +
20630 +static struct inode_operations proc_xid_inode_operations = {
20631 +       .lookup =       proc_xid_lookup,
20632 +};
20633 +
20634 +static struct vs_entry vx_virtual_stuff[] = {
20635 +       INF("info",     S_IRUGO, virtual_info),
20636 +       INF("status",   S_IRUGO, virtual_status),
20637 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
20638 +};
20639 +
20640 +
20641 +static struct dentry *proc_virtual_lookup(struct inode *dir,
20642 +       struct dentry *dentry, unsigned int flags)
20643 +{
20644 +       struct vs_entry *p = vx_virtual_stuff;
20645 +       struct dentry *error = ERR_PTR(-ENOENT);
20646 +       int id = 0;
20647 +
20648 +       for (; p->name; p++) {
20649 +               if (p->len != dentry->d_name.len)
20650 +                       continue;
20651 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20652 +                       break;
20653 +       }
20654 +       if (p->name)
20655 +               goto instantiate;
20656 +
20657 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
20658 +       if ((id < 0) || !xid_is_hashed(id))
20659 +               goto out;
20660 +
20661 +instantiate:
20662 +       error = proc_xid_instantiate(dir, dentry, id, p);
20663 +out:
20664 +       return error;
20665 +}
20666 +
20667 +static struct file_operations proc_nid_file_operations = {
20668 +       .read =         generic_read_dir,
20669 +       .iterate =      proc_nid_iterate,
20670 +};
20671 +
20672 +static struct inode_operations proc_nid_inode_operations = {
20673 +       .lookup =       proc_nid_lookup,
20674 +};
20675 +
20676 +static struct vs_entry nx_virtnet_stuff[] = {
20677 +       INF("info",     S_IRUGO, virtnet_info),
20678 +       INF("status",   S_IRUGO, virtnet_status),
20679 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
20680 +};
20681 +
20682 +
20683 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
20684 +       struct dentry *dentry, unsigned int flags)
20685 +{
20686 +       struct vs_entry *p = nx_virtnet_stuff;
20687 +       struct dentry *error = ERR_PTR(-ENOENT);
20688 +       int id = 0;
20689 +
20690 +       for (; p->name; p++) {
20691 +               if (p->len != dentry->d_name.len)
20692 +                       continue;
20693 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20694 +                       break;
20695 +       }
20696 +       if (p->name)
20697 +               goto instantiate;
20698 +
20699 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
20700 +       if ((id < 0) || !nid_is_hashed(id))
20701 +               goto out;
20702 +
20703 +instantiate:
20704 +       error = proc_nid_instantiate(dir, dentry, id, p);
20705 +out:
20706 +       return error;
20707 +}
20708 +
20709 +
20710 +#define PROC_MAXVIDS 32
20711 +
20712 +int proc_virtual_iterate(struct file *filp, struct dir_context *ctx)
20713 +{
20714 +       struct dentry *dentry = filp->f_path.dentry;
20715 +       struct inode *inode = dentry->d_inode;
20716 +       struct vs_entry *p = vx_virtual_stuff;
20717 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
20718 +       int index;
20719 +       unsigned int xid_array[PROC_MAXVIDS];
20720 +       char buf[PROC_NUMBUF];
20721 +       unsigned int nr_xids, i;
20722 +       u64 ino;
20723 +
20724 +       switch (ctx->pos) {
20725 +       case 0:
20726 +               ino = inode->i_ino;
20727 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20728 +                       goto out;
20729 +               ctx->pos++;
20730 +               /* fall through */
20731 +       case 1:
20732 +               ino = parent_ino(dentry);
20733 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20734 +                       goto out;
20735 +               ctx->pos++;
20736 +               /* fall through */
20737 +       default:
20738 +               index = ctx->pos - 2;
20739 +               if (index >= size)
20740 +                       goto entries;
20741 +               for (p += index; p->name; p++) {
20742 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20743 +                               vs_proc_instantiate, 0, p))
20744 +                               goto out;
20745 +                       ctx->pos++;
20746 +               }
20747 +       entries:
20748 +               index = ctx->pos - size;
20749 +               p = &vx_virtual_stuff[size - 1];
20750 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
20751 +               for (i = 0; i < nr_xids; i++) {
20752 +                       int n, xid = xid_array[i];
20753 +                       unsigned int j = PROC_NUMBUF;
20754 +
20755 +                       n = xid;
20756 +                       do
20757 +                               buf[--j] = '0' + (n % 10);
20758 +                       while (n /= 10);
20759 +
20760 +                       if (vx_proc_fill_cache(filp, ctx,
20761 +                               buf + j, PROC_NUMBUF - j,
20762 +                               vs_proc_instantiate, xid, p))
20763 +                               goto out;
20764 +                       ctx->pos++;
20765 +               }
20766 +       }
20767 +out:
20768 +       return 0;
20769 +}
20770 +
20771 +static int proc_virtual_getattr(struct vfsmount *mnt,
20772 +       struct dentry *dentry, struct kstat *stat)
20773 +{
20774 +       struct inode *inode = dentry->d_inode;
20775 +
20776 +       generic_fillattr(inode, stat);
20777 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
20778 +       return 0;
20779 +}
20780 +
20781 +static struct file_operations proc_virtual_dir_operations = {
20782 +       .read =         generic_read_dir,
20783 +       .iterate =      proc_virtual_iterate,
20784 +};
20785 +
20786 +static struct inode_operations proc_virtual_dir_inode_operations = {
20787 +       .getattr =      proc_virtual_getattr,
20788 +       .lookup =       proc_virtual_lookup,
20789 +};
20790 +
20791 +
20792 +
20793 +int proc_virtnet_iterate(struct file *filp, struct dir_context *ctx)
20794 +{
20795 +       struct dentry *dentry = filp->f_path.dentry;
20796 +       struct inode *inode = dentry->d_inode;
20797 +       struct vs_entry *p = nx_virtnet_stuff;
20798 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
20799 +       int index;
20800 +       unsigned int nid_array[PROC_MAXVIDS];
20801 +       char buf[PROC_NUMBUF];
20802 +       unsigned int nr_nids, i;
20803 +       u64 ino;
20804 +
20805 +       switch (ctx->pos) {
20806 +       case 0:
20807 +               ino = inode->i_ino;
20808 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20809 +                       goto out;
20810 +               ctx->pos++;
20811 +               /* fall through */
20812 +       case 1:
20813 +               ino = parent_ino(dentry);
20814 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20815 +                       goto out;
20816 +               ctx->pos++;
20817 +               /* fall through */
20818 +       default:
20819 +               index = ctx->pos - 2;
20820 +               if (index >= size)
20821 +                       goto entries;
20822 +               for (p += index; p->name; p++) {
20823 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20824 +                               vs_proc_instantiate, 0, p))
20825 +                               goto out;
20826 +                       ctx->pos++;
20827 +               }
20828 +       entries:
20829 +               index = ctx->pos - size;
20830 +               p = &nx_virtnet_stuff[size - 1];
20831 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
20832 +               for (i = 0; i < nr_nids; i++) {
20833 +                       int n, nid = nid_array[i];
20834 +                       unsigned int j = PROC_NUMBUF;
20835 +
20836 +                       n = nid;
20837 +                       do
20838 +                               buf[--j] = '0' + (n % 10);
20839 +                       while (n /= 10);
20840 +
20841 +                       if (vx_proc_fill_cache(filp, ctx,
20842 +                               buf + j, PROC_NUMBUF - j,
20843 +                               vs_proc_instantiate, nid, p))
20844 +                               goto out;
20845 +                       ctx->pos++;
20846 +               }
20847 +       }
20848 +out:
20849 +       return 0;
20850 +}
20851 +
20852 +static int proc_virtnet_getattr(struct vfsmount *mnt,
20853 +       struct dentry *dentry, struct kstat *stat)
20854 +{
20855 +       struct inode *inode = dentry->d_inode;
20856 +
20857 +       generic_fillattr(inode, stat);
20858 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
20859 +       return 0;
20860 +}
20861 +
20862 +static struct file_operations proc_virtnet_dir_operations = {
20863 +       .read =         generic_read_dir,
20864 +       .iterate =      proc_virtnet_iterate,
20865 +};
20866 +
20867 +static struct inode_operations proc_virtnet_dir_inode_operations = {
20868 +       .getattr =      proc_virtnet_getattr,
20869 +       .lookup =       proc_virtnet_lookup,
20870 +};
20871 +
20872 +
20873 +
20874 +void proc_vx_init(void)
20875 +{
20876 +       struct proc_dir_entry *ent;
20877 +
20878 +       ent = proc_mkdir("virtual", 0);
20879 +       if (ent) {
20880 +               ent->proc_fops = &proc_virtual_dir_operations;
20881 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
20882 +       }
20883 +       proc_virtual = ent;
20884 +
20885 +       ent = proc_mkdir("virtnet", 0);
20886 +       if (ent) {
20887 +               ent->proc_fops = &proc_virtnet_dir_operations;
20888 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
20889 +       }
20890 +       proc_virtnet = ent;
20891 +}
20892 +
20893 +
20894 +
20895 +
20896 +/* per pid info */
20897 +
20898 +void render_cap_t(struct seq_file *, const char *,
20899 +       struct vx_info *, kernel_cap_t *);
20900 +
20901 +
20902 +int proc_pid_vx_info(
20903 +       struct seq_file *m,
20904 +       struct pid_namespace *ns,
20905 +       struct pid *pid,
20906 +       struct task_struct *p)
20907 +{
20908 +       struct vx_info *vxi;
20909 +
20910 +       seq_printf(m, "XID:\t%d\n", vx_task_xid(p));
20911 +
20912 +       vxi = task_get_vx_info(p);
20913 +       if (!vxi)
20914 +               return 0;
20915 +
20916 +       render_cap_t(m, "BCaps:\t", vxi, &vxi->vx_bcaps);
20917 +       seq_printf(m, "CCaps:\t%016llx\n",
20918 +               (unsigned long long)vxi->vx_ccaps);
20919 +       seq_printf(m, "CFlags:\t%016llx\n",
20920 +               (unsigned long long)vxi->vx_flags);
20921 +       seq_printf(m, "CIPid:\t%d\n", vxi->vx_initpid);
20922 +
20923 +       put_vx_info(vxi);
20924 +       return 0;
20925 +}
20926 +
20927 +
20928 +int proc_pid_nx_info(
20929 +       struct seq_file *m,
20930 +       struct pid_namespace *ns,
20931 +       struct pid *pid,
20932 +       struct task_struct *p)
20933 +{
20934 +       struct nx_info *nxi;
20935 +       struct nx_addr_v4 *v4a;
20936 +#ifdef CONFIG_IPV6
20937 +       struct nx_addr_v6 *v6a;
20938 +#endif
20939 +       int i;
20940 +
20941 +       seq_printf(m, "NID:\t%d\n", nx_task_nid(p));
20942 +
20943 +       nxi = task_get_nx_info(p);
20944 +       if (!nxi)
20945 +               return 0;
20946 +
20947 +       seq_printf(m, "NCaps:\t%016llx\n",
20948 +               (unsigned long long)nxi->nx_ncaps);
20949 +       seq_printf(m, "NFlags:\t%016llx\n",
20950 +               (unsigned long long)nxi->nx_flags);
20951 +
20952 +       seq_printf(m, "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
20953 +               NIPQUAD(nxi->v4_bcast.s_addr));
20954 +       seq_printf(m, "V4Root[lback]:\t" NIPQUAD_FMT "\n",
20955 +               NIPQUAD(nxi->v4_lback.s_addr));
20956 +       if (!NX_IPV4(nxi))
20957 +               goto skip_v4;
20958 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20959 +               seq_printf(m, "V4Root[%d]:\t" NXAV4_FMT "\n",
20960 +                       i, NXAV4(v4a));
20961 +skip_v4:
20962 +#ifdef CONFIG_IPV6
20963 +       if (!NX_IPV6(nxi))
20964 +               goto skip_v6;
20965 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20966 +               seq_printf(m, "V6Root[%d]:\t" NXAV6_FMT "\n",
20967 +                       i, NXAV6(v6a));
20968 +skip_v6:
20969 +#endif
20970 +       put_nx_info(nxi);
20971 +       return 0;
20972 +}
20973 +
20974 diff -NurpP --minimal linux-4.4.110/kernel/vserver/sched.c linux-4.4.110-vs2.3.9/kernel/vserver/sched.c
20975 --- linux-4.4.110/kernel/vserver/sched.c        1970-01-01 00:00:00.000000000 +0000
20976 +++ linux-4.4.110-vs2.3.9/kernel/vserver/sched.c        2018-01-09 16:36:34.000000000 +0000
20977 @@ -0,0 +1,83 @@
20978 +/*
20979 + *  linux/kernel/vserver/sched.c
20980 + *
20981 + *  Virtual Server: Scheduler Support
20982 + *
20983 + *  Copyright (C) 2004-2010  Herbert P?tzl
20984 + *
20985 + *  V0.01  adapted Sam Vilains version to 2.6.3
20986 + *  V0.02  removed legacy interface
20987 + *  V0.03  changed vcmds to vxi arg
20988 + *  V0.04  removed older and legacy interfaces
20989 + *  V0.05  removed scheduler code/commands
20990 + *
20991 + */
20992 +
20993 +#include <linux/vs_context.h>
20994 +#include <linux/vs_sched.h>
20995 +#include <linux/cpumask.h>
20996 +#include <linux/vserver/sched_cmd.h>
20997 +
20998 +#include <asm/uaccess.h>
20999 +
21000 +
21001 +void vx_update_sched_param(struct _vx_sched *sched,
21002 +       struct _vx_sched_pc *sched_pc)
21003 +{
21004 +       sched_pc->prio_bias = sched->prio_bias;
21005 +}
21006 +
21007 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21008 +{
21009 +       int cpu;
21010 +
21011 +       if (data->prio_bias > MAX_PRIO_BIAS)
21012 +               data->prio_bias = MAX_PRIO_BIAS;
21013 +       if (data->prio_bias < MIN_PRIO_BIAS)
21014 +               data->prio_bias = MIN_PRIO_BIAS;
21015 +
21016 +       if (data->cpu_id != ~0) {
21017 +               vxi->sched.update = *get_cpu_mask(data->cpu_id);
21018 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
21019 +                       cpu_online_mask);
21020 +       } else
21021 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
21022 +
21023 +       for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)vxi->sched.update)
21024 +               vx_update_sched_param(&vxi->sched,
21025 +                       &vx_per_cpu(vxi, sched_pc, cpu));
21026 +       return 0;
21027 +}
21028 +
21029 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21030 +{
21031 +       struct vcmd_prio_bias vc_data;
21032 +
21033 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21034 +               return -EFAULT;
21035 +
21036 +       return do_set_prio_bias(vxi, &vc_data);
21037 +}
21038 +
21039 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21040 +{
21041 +       struct vcmd_prio_bias vc_data;
21042 +       struct _vx_sched_pc *pcd;
21043 +       int cpu;
21044 +
21045 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21046 +               return -EFAULT;
21047 +
21048 +       cpu = vc_data.cpu_id;
21049 +
21050 +       if (!cpu_possible(cpu))
21051 +               return -EINVAL;
21052 +
21053 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21054 +       vc_data.prio_bias = pcd->prio_bias;
21055 +
21056 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21057 +               return -EFAULT;
21058 +       return 0;
21059 +}
21060 +
21061 diff -NurpP --minimal linux-4.4.110/kernel/vserver/sched_init.h linux-4.4.110-vs2.3.9/kernel/vserver/sched_init.h
21062 --- linux-4.4.110/kernel/vserver/sched_init.h   1970-01-01 00:00:00.000000000 +0000
21063 +++ linux-4.4.110-vs2.3.9/kernel/vserver/sched_init.h   2018-01-09 16:36:34.000000000 +0000
21064 @@ -0,0 +1,27 @@
21065 +
21066 +static inline void vx_info_init_sched(struct _vx_sched *sched)
21067 +{
21068 +       /* scheduling; hard code starting values as constants */
21069 +       sched->prio_bias = 0;
21070 +}
21071 +
21072 +static inline
21073 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21074 +{
21075 +       sched_pc->prio_bias = 0;
21076 +
21077 +       sched_pc->user_ticks = 0;
21078 +       sched_pc->sys_ticks = 0;
21079 +       sched_pc->hold_ticks = 0;
21080 +}
21081 +
21082 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
21083 +{
21084 +       return;
21085 +}
21086 +
21087 +static inline
21088 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21089 +{
21090 +       return;
21091 +}
21092 diff -NurpP --minimal linux-4.4.110/kernel/vserver/sched_proc.h linux-4.4.110-vs2.3.9/kernel/vserver/sched_proc.h
21093 --- linux-4.4.110/kernel/vserver/sched_proc.h   1970-01-01 00:00:00.000000000 +0000
21094 +++ linux-4.4.110-vs2.3.9/kernel/vserver/sched_proc.h   2018-01-09 16:36:34.000000000 +0000
21095 @@ -0,0 +1,32 @@
21096 +#ifndef _VX_SCHED_PROC_H
21097 +#define _VX_SCHED_PROC_H
21098 +
21099 +
21100 +static inline
21101 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
21102 +{
21103 +       int length = 0;
21104 +
21105 +       length += sprintf(buffer,
21106 +               "PrioBias:\t%8d\n",
21107 +               sched->prio_bias);
21108 +       return length;
21109 +}
21110 +
21111 +static inline
21112 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
21113 +       char *buffer, int cpu)
21114 +{
21115 +       int length = 0;
21116 +
21117 +       length += sprintf(buffer + length,
21118 +               "cpu %d: %lld %lld %lld", cpu,
21119 +               (unsigned long long)sched_pc->user_ticks,
21120 +               (unsigned long long)sched_pc->sys_ticks,
21121 +               (unsigned long long)sched_pc->hold_ticks);
21122 +       length += sprintf(buffer + length,
21123 +               " %d\n", sched_pc->prio_bias);
21124 +       return length;
21125 +}
21126 +
21127 +#endif /* _VX_SCHED_PROC_H */
21128 diff -NurpP --minimal linux-4.4.110/kernel/vserver/signal.c linux-4.4.110-vs2.3.9/kernel/vserver/signal.c
21129 --- linux-4.4.110/kernel/vserver/signal.c       1970-01-01 00:00:00.000000000 +0000
21130 +++ linux-4.4.110-vs2.3.9/kernel/vserver/signal.c       2018-01-09 16:36:34.000000000 +0000
21131 @@ -0,0 +1,134 @@
21132 +/*
21133 + *  linux/kernel/vserver/signal.c
21134 + *
21135 + *  Virtual Server: Signal Support
21136 + *
21137 + *  Copyright (C) 2003-2007  Herbert P?tzl
21138 + *
21139 + *  V0.01  broken out from vcontext V0.05
21140 + *  V0.02  changed vcmds to vxi arg
21141 + *  V0.03  adjusted siginfo for kill
21142 + *
21143 + */
21144 +
21145 +#include <asm/uaccess.h>
21146 +
21147 +#include <linux/vs_context.h>
21148 +#include <linux/vs_pid.h>
21149 +#include <linux/vserver/signal_cmd.h>
21150 +
21151 +
21152 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
21153 +{
21154 +       int retval, count = 0;
21155 +       struct task_struct *p;
21156 +       struct siginfo *sip = SEND_SIG_PRIV;
21157 +
21158 +       retval = -ESRCH;
21159 +       vxdprintk(VXD_CBIT(misc, 4),
21160 +               "vx_info_kill(%p[#%d],%d,%d)*",
21161 +               vxi, vxi->vx_id, pid, sig);
21162 +       read_lock(&tasklist_lock);
21163 +       switch (pid) {
21164 +       case  0:
21165 +       case -1:
21166 +               for_each_process(p) {
21167 +                       int err = 0;
21168 +
21169 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
21170 +                               (pid && vxi->vx_initpid == p->pid))
21171 +                               continue;
21172 +
21173 +                       err = group_send_sig_info(sig, sip, p);
21174 +                       ++count;
21175 +                       if (err != -EPERM)
21176 +                               retval = err;
21177 +               }
21178 +               break;
21179 +
21180 +       case 1:
21181 +               if (vxi->vx_initpid) {
21182 +                       pid = vxi->vx_initpid;
21183 +                       /* for now, only SIGINT to private init ... */
21184 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21185 +                               /* ... as long as there are tasks left */
21186 +                               (atomic_read(&vxi->vx_tasks) > 1))
21187 +                               sig = SIGINT;
21188 +               }
21189 +               /* fallthrough */
21190 +       default:
21191 +               rcu_read_lock();
21192 +               p = find_task_by_real_pid(pid);
21193 +               rcu_read_unlock();
21194 +               if (p) {
21195 +                       if (vx_task_xid(p) == vxi->vx_id)
21196 +                               retval = group_send_sig_info(sig, sip, p);
21197 +               }
21198 +               break;
21199 +       }
21200 +       read_unlock(&tasklist_lock);
21201 +       vxdprintk(VXD_CBIT(misc, 4),
21202 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
21203 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
21204 +       return retval;
21205 +}
21206 +
21207 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
21208 +{
21209 +       struct vcmd_ctx_kill_v0 vc_data;
21210 +
21211 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21212 +               return -EFAULT;
21213 +
21214 +       /* special check to allow guest shutdown */
21215 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21216 +               /* forbid killall pid=0 when init is present */
21217 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
21218 +               (vc_data.pid > 1)))
21219 +               return -EACCES;
21220 +
21221 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
21222 +}
21223 +
21224 +
21225 +static int __wait_exit(struct vx_info *vxi)
21226 +{
21227 +       DECLARE_WAITQUEUE(wait, current);
21228 +       int ret = 0;
21229 +
21230 +       add_wait_queue(&vxi->vx_wait, &wait);
21231 +       set_current_state(TASK_INTERRUPTIBLE);
21232 +
21233 +wait:
21234 +       if (vx_info_state(vxi,
21235 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
21236 +               goto out;
21237 +       if (signal_pending(current)) {
21238 +               ret = -ERESTARTSYS;
21239 +               goto out;
21240 +       }
21241 +       schedule();
21242 +       goto wait;
21243 +
21244 +out:
21245 +       set_current_state(TASK_RUNNING);
21246 +       remove_wait_queue(&vxi->vx_wait, &wait);
21247 +       return ret;
21248 +}
21249 +
21250 +
21251 +
21252 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
21253 +{
21254 +       struct vcmd_wait_exit_v0 vc_data;
21255 +       int ret;
21256 +
21257 +       ret = __wait_exit(vxi);
21258 +       vc_data.reboot_cmd = vxi->reboot_cmd;
21259 +       vc_data.exit_code = vxi->exit_code;
21260 +
21261 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21262 +               ret = -EFAULT;
21263 +       return ret;
21264 +}
21265 +
21266 diff -NurpP --minimal linux-4.4.110/kernel/vserver/space.c linux-4.4.110-vs2.3.9/kernel/vserver/space.c
21267 --- linux-4.4.110/kernel/vserver/space.c        1970-01-01 00:00:00.000000000 +0000
21268 +++ linux-4.4.110-vs2.3.9/kernel/vserver/space.c        2018-01-09 16:36:34.000000000 +0000
21269 @@ -0,0 +1,436 @@
21270 +/*
21271 + *  linux/kernel/vserver/space.c
21272 + *
21273 + *  Virtual Server: Context Space Support
21274 + *
21275 + *  Copyright (C) 2003-2010  Herbert P?tzl
21276 + *
21277 + *  V0.01  broken out from context.c 0.07
21278 + *  V0.02  added task locking for namespace
21279 + *  V0.03  broken out vx_enter_namespace
21280 + *  V0.04  added *space support and commands
21281 + *  V0.05  added credential support
21282 + *
21283 + */
21284 +
21285 +#include <linux/utsname.h>
21286 +#include <linux/nsproxy.h>
21287 +#include <linux/err.h>
21288 +#include <linux/fs_struct.h>
21289 +#include <linux/cred.h>
21290 +#include <asm/uaccess.h>
21291 +
21292 +#include <linux/vs_context.h>
21293 +#include <linux/vserver/space.h>
21294 +#include <linux/vserver/space_cmd.h>
21295 +
21296 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
21297 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
21298 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
21299 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
21300 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
21301 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
21302 +
21303 +
21304 +/* namespace functions */
21305 +
21306 +#include <linux/mnt_namespace.h>
21307 +#include <linux/user_namespace.h>
21308 +#include <linux/pid_namespace.h>
21309 +#include <linux/ipc_namespace.h>
21310 +#include <net/net_namespace.h>
21311 +#include "../fs/mount.h"
21312 +
21313 +
21314 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
21315 +       .mask = CLONE_FS |
21316 +               CLONE_NEWNS |
21317 +#ifdef CONFIG_UTS_NS
21318 +               CLONE_NEWUTS |
21319 +#endif
21320 +#ifdef CONFIG_IPC_NS
21321 +               CLONE_NEWIPC |
21322 +#endif
21323 +#ifdef CONFIG_USER_NS
21324 +               CLONE_NEWUSER |
21325 +#endif
21326 +               0
21327 +};
21328 +
21329 +static const struct vcmd_space_mask_v1 space_mask = {
21330 +       .mask = CLONE_FS |
21331 +               CLONE_NEWNS |
21332 +#ifdef CONFIG_UTS_NS
21333 +               CLONE_NEWUTS |
21334 +#endif
21335 +#ifdef CONFIG_IPC_NS
21336 +               CLONE_NEWIPC |
21337 +#endif
21338 +#ifdef CONFIG_USER_NS
21339 +               CLONE_NEWUSER |
21340 +#endif
21341 +#ifdef CONFIG_PID_NS
21342 +               CLONE_NEWPID |
21343 +#endif
21344 +#ifdef CONFIG_NET_NS
21345 +               CLONE_NEWNET |
21346 +#endif
21347 +               0
21348 +};
21349 +
21350 +static const struct vcmd_space_mask_v1 default_space_mask = {
21351 +       .mask = CLONE_FS |
21352 +               CLONE_NEWNS |
21353 +#ifdef CONFIG_UTS_NS
21354 +               CLONE_NEWUTS |
21355 +#endif
21356 +#ifdef CONFIG_IPC_NS
21357 +               CLONE_NEWIPC |
21358 +#endif
21359 +#ifdef CONFIG_USER_NS
21360 +//             CLONE_NEWUSER |
21361 +#endif
21362 +#ifdef CONFIG_PID_NS
21363 +//             CLONE_NEWPID |
21364 +#endif
21365 +               0
21366 +};
21367 +
21368 +/*
21369 + *     build a new nsproxy mix
21370 + *      assumes that both proxies are 'const'
21371 + *     does not touch nsproxy refcounts
21372 + *     will hold a reference on the result.
21373 + */
21374 +
21375 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
21376 +       struct nsproxy *new_nsproxy, unsigned long mask)
21377 +{
21378 +       struct mnt_namespace *old_ns;
21379 +       struct uts_namespace *old_uts;
21380 +       struct ipc_namespace *old_ipc;
21381 +#ifdef CONFIG_PID_NS
21382 +       struct pid_namespace *old_pid;
21383 +#endif
21384 +#ifdef CONFIG_NET_NS
21385 +       struct net *old_net;
21386 +#endif
21387 +       struct nsproxy *nsproxy;
21388 +
21389 +       nsproxy = copy_nsproxy(old_nsproxy);
21390 +       if (!nsproxy)
21391 +               goto out;
21392 +
21393 +       if (mask & CLONE_NEWNS) {
21394 +               old_ns = nsproxy->mnt_ns;
21395 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
21396 +               if (nsproxy->mnt_ns)
21397 +                       get_mnt_ns(nsproxy->mnt_ns);
21398 +       } else
21399 +               old_ns = NULL;
21400 +
21401 +       if (mask & CLONE_NEWUTS) {
21402 +               old_uts = nsproxy->uts_ns;
21403 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
21404 +               if (nsproxy->uts_ns)
21405 +                       get_uts_ns(nsproxy->uts_ns);
21406 +       } else
21407 +               old_uts = NULL;
21408 +
21409 +       if (mask & CLONE_NEWIPC) {
21410 +               old_ipc = nsproxy->ipc_ns;
21411 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
21412 +               if (nsproxy->ipc_ns)
21413 +                       get_ipc_ns(nsproxy->ipc_ns);
21414 +       } else
21415 +               old_ipc = NULL;
21416 +
21417 +#ifdef CONFIG_PID_NS
21418 +       if (mask & CLONE_NEWPID) {
21419 +               old_pid = nsproxy->pid_ns_for_children;
21420 +               nsproxy->pid_ns_for_children = new_nsproxy->pid_ns_for_children;
21421 +               if (nsproxy->pid_ns_for_children)
21422 +                       get_pid_ns(nsproxy->pid_ns_for_children);
21423 +       } else
21424 +               old_pid = NULL;
21425 +#endif
21426 +#ifdef CONFIG_NET_NS
21427 +       if (mask & CLONE_NEWNET) {
21428 +               old_net = nsproxy->net_ns;
21429 +               nsproxy->net_ns = new_nsproxy->net_ns;
21430 +               if (nsproxy->net_ns)
21431 +                       get_net(nsproxy->net_ns);
21432 +       } else
21433 +               old_net = NULL;
21434 +#endif
21435 +       if (old_ns)
21436 +               put_mnt_ns(old_ns);
21437 +       if (old_uts)
21438 +               put_uts_ns(old_uts);
21439 +       if (old_ipc)
21440 +               put_ipc_ns(old_ipc);
21441 +#ifdef CONFIG_PID_NS
21442 +       if (old_pid)
21443 +               put_pid_ns(old_pid);
21444 +#endif
21445 +#ifdef CONFIG_NET_NS
21446 +       if (old_net)
21447 +               put_net(old_net);
21448 +#endif
21449 +out:
21450 +       return nsproxy;
21451 +}
21452 +
21453 +
21454 +/*
21455 + *     merge two nsproxy structs into a new one.
21456 + *     will hold a reference on the result.
21457 + */
21458 +
21459 +static inline
21460 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
21461 +       struct nsproxy *proxy, unsigned long mask)
21462 +{
21463 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
21464 +
21465 +       if (!proxy)
21466 +               return NULL;
21467 +
21468 +       if (mask) {
21469 +               /* vs_mix_nsproxy returns with reference */
21470 +               return vs_mix_nsproxy(old ? old : &null_proxy,
21471 +                       proxy, mask);
21472 +       }
21473 +       get_nsproxy(proxy);
21474 +       return proxy;
21475 +}
21476 +
21477 +
21478 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21479 +{
21480 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
21481 +       struct fs_struct *fs_cur, *fs = NULL;
21482 +       struct _vx_space *space;
21483 +       int ret, kill = 0;
21484 +
21485 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
21486 +               vxi, vxi->vx_id, mask, index);
21487 +
21488 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
21489 +               return -EACCES;
21490 +
21491 +       if (index >= VX_SPACES)
21492 +               return -EINVAL;
21493 +
21494 +       space = &vxi->space[index];
21495 +
21496 +       if (!mask)
21497 +               mask = space->vx_nsmask;
21498 +
21499 +       if ((mask & space->vx_nsmask) != mask)
21500 +               return -EINVAL;
21501 +
21502 +       if (mask & CLONE_FS) {
21503 +               fs = copy_fs_struct(space->vx_fs);
21504 +               if (!fs)
21505 +                       return -ENOMEM;
21506 +       }
21507 +       proxy = space->vx_nsproxy;
21508 +
21509 +       vxdprintk(VXD_CBIT(space, 9),
21510 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
21511 +               vxi, vxi->vx_id, mask, index, proxy, fs);
21512 +
21513 +       task_lock(current);
21514 +       fs_cur = current->fs;
21515 +
21516 +       if (mask & CLONE_FS) {
21517 +               spin_lock(&fs_cur->lock);
21518 +               current->fs = fs;
21519 +               kill = !--fs_cur->users;
21520 +               spin_unlock(&fs_cur->lock);
21521 +       }
21522 +
21523 +       proxy_cur = current->nsproxy;
21524 +       get_nsproxy(proxy_cur);
21525 +       task_unlock(current);
21526 +
21527 +       if (kill)
21528 +               free_fs_struct(fs_cur);
21529 +
21530 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
21531 +       if (IS_ERR(proxy_new)) {
21532 +               ret = PTR_ERR(proxy_new);
21533 +               goto out_put;
21534 +       }
21535 +
21536 +       proxy_new = xchg(&current->nsproxy, proxy_new);
21537 +
21538 +       if (mask & CLONE_NEWUSER) {
21539 +               struct cred *cred;
21540 +
21541 +               vxdprintk(VXD_CBIT(space, 10),
21542 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
21543 +                       vxi, vxi->vx_id, space->vx_cred,
21544 +                       current->real_cred, current->cred);
21545 +
21546 +               if (space->vx_cred) {
21547 +                       cred = __prepare_creds(space->vx_cred);
21548 +                       if (cred)
21549 +                               commit_creds(cred);
21550 +               }
21551 +       }
21552 +
21553 +       ret = 0;
21554 +
21555 +       if (proxy_new)
21556 +               put_nsproxy(proxy_new);
21557 +out_put:
21558 +       if (proxy_cur)
21559 +               put_nsproxy(proxy_cur);
21560 +       return ret;
21561 +}
21562 +
21563 +
21564 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21565 +{
21566 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
21567 +       struct fs_struct *fs_vxi, *fs = NULL;
21568 +       struct _vx_space *space;
21569 +       int ret, kill = 0;
21570 +
21571 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
21572 +               vxi, vxi->vx_id, mask, index);
21573 +
21574 +       if ((mask & space_mask.mask) != mask)
21575 +               return -EINVAL;
21576 +
21577 +       if (index >= VX_SPACES)
21578 +               return -EINVAL;
21579 +
21580 +       space = &vxi->space[index];
21581 +
21582 +       proxy_vxi = space->vx_nsproxy;
21583 +       fs_vxi = space->vx_fs;
21584 +
21585 +       if (mask & CLONE_FS) {
21586 +               fs = copy_fs_struct(current->fs);
21587 +               if (!fs)
21588 +                       return -ENOMEM;
21589 +       }
21590 +
21591 +       task_lock(current);
21592 +
21593 +       if (mask & CLONE_FS) {
21594 +               spin_lock(&fs_vxi->lock);
21595 +               space->vx_fs = fs;
21596 +               kill = !--fs_vxi->users;
21597 +               spin_unlock(&fs_vxi->lock);
21598 +       }
21599 +
21600 +       proxy_cur = current->nsproxy;
21601 +       get_nsproxy(proxy_cur);
21602 +       task_unlock(current);
21603 +
21604 +       if (kill)
21605 +               free_fs_struct(fs_vxi);
21606 +
21607 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
21608 +       if (IS_ERR(proxy_new)) {
21609 +               ret = PTR_ERR(proxy_new);
21610 +               goto out_put;
21611 +       }
21612 +
21613 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
21614 +       space->vx_nsmask |= mask;
21615 +
21616 +       if (mask & CLONE_NEWUSER) {
21617 +               struct cred *cred;
21618 +
21619 +               vxdprintk(VXD_CBIT(space, 10),
21620 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
21621 +                       vxi, vxi->vx_id, space->vx_cred,
21622 +                       current->real_cred, current->cred);
21623 +
21624 +               cred = prepare_creds();
21625 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
21626 +               if (cred)
21627 +                       abort_creds(cred);
21628 +       }
21629 +
21630 +       ret = 0;
21631 +
21632 +       if (proxy_new)
21633 +               put_nsproxy(proxy_new);
21634 +out_put:
21635 +       if (proxy_cur)
21636 +               put_nsproxy(proxy_cur);
21637 +       return ret;
21638 +}
21639 +
21640 +
21641 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
21642 +{
21643 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21644 +
21645 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21646 +               return -EFAULT;
21647 +
21648 +       return vx_enter_space(vxi, vc_data.mask, 0);
21649 +}
21650 +
21651 +int vc_enter_space(struct vx_info *vxi, void __user *data)
21652 +{
21653 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21654 +
21655 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21656 +               return -EFAULT;
21657 +
21658 +       if (vc_data.index >= VX_SPACES)
21659 +               return -EINVAL;
21660 +
21661 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
21662 +}
21663 +
21664 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
21665 +{
21666 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21667 +
21668 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21669 +               return -EFAULT;
21670 +
21671 +       return vx_set_space(vxi, vc_data.mask, 0);
21672 +}
21673 +
21674 +int vc_set_space(struct vx_info *vxi, void __user *data)
21675 +{
21676 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21677 +
21678 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21679 +               return -EFAULT;
21680 +
21681 +       if (vc_data.index >= VX_SPACES)
21682 +               return -EINVAL;
21683 +
21684 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
21685 +}
21686 +
21687 +int vc_get_space_mask(void __user *data, int type)
21688 +{
21689 +       const struct vcmd_space_mask_v1 *mask;
21690 +
21691 +       if (type == 0)
21692 +               mask = &space_mask_v0;
21693 +       else if (type == 1)
21694 +               mask = &space_mask;
21695 +       else
21696 +               mask = &default_space_mask;
21697 +
21698 +       vxdprintk(VXD_CBIT(space, 10),
21699 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
21700 +
21701 +       if (copy_to_user(data, mask, sizeof(*mask)))
21702 +               return -EFAULT;
21703 +       return 0;
21704 +}
21705 +
21706 diff -NurpP --minimal linux-4.4.110/kernel/vserver/switch.c linux-4.4.110-vs2.3.9/kernel/vserver/switch.c
21707 --- linux-4.4.110/kernel/vserver/switch.c       1970-01-01 00:00:00.000000000 +0000
21708 +++ linux-4.4.110-vs2.3.9/kernel/vserver/switch.c       2018-01-09 16:36:34.000000000 +0000
21709 @@ -0,0 +1,556 @@
21710 +/*
21711 + *  linux/kernel/vserver/switch.c
21712 + *
21713 + *  Virtual Server: Syscall Switch
21714 + *
21715 + *  Copyright (C) 2003-2011  Herbert P?tzl
21716 + *
21717 + *  V0.01  syscall switch
21718 + *  V0.02  added signal to context
21719 + *  V0.03  added rlimit functions
21720 + *  V0.04  added iattr, task/xid functions
21721 + *  V0.05  added debug/history stuff
21722 + *  V0.06  added compat32 layer
21723 + *  V0.07  vcmd args and perms
21724 + *  V0.08  added status commands
21725 + *  V0.09  added tag commands
21726 + *  V0.10  added oom bias
21727 + *  V0.11  added device commands
21728 + *  V0.12  added warn mask
21729 + *
21730 + */
21731 +
21732 +#include <linux/vs_context.h>
21733 +#include <linux/vs_network.h>
21734 +#include <linux/vserver/switch.h>
21735 +
21736 +#include "vci_config.h"
21737 +
21738 +
21739 +static inline
21740 +int vc_get_version(uint32_t id)
21741 +{
21742 +       return VCI_VERSION;
21743 +}
21744 +
21745 +static inline
21746 +int vc_get_vci(uint32_t id)
21747 +{
21748 +       return vci_kernel_config();
21749 +}
21750 +
21751 +#include <linux/vserver/context_cmd.h>
21752 +#include <linux/vserver/cvirt_cmd.h>
21753 +#include <linux/vserver/cacct_cmd.h>
21754 +#include <linux/vserver/limit_cmd.h>
21755 +#include <linux/vserver/network_cmd.h>
21756 +#include <linux/vserver/sched_cmd.h>
21757 +#include <linux/vserver/debug_cmd.h>
21758 +#include <linux/vserver/inode_cmd.h>
21759 +#include <linux/vserver/dlimit_cmd.h>
21760 +#include <linux/vserver/signal_cmd.h>
21761 +#include <linux/vserver/space_cmd.h>
21762 +#include <linux/vserver/tag_cmd.h>
21763 +#include <linux/vserver/device_cmd.h>
21764 +
21765 +#include <linux/vserver/inode.h>
21766 +#include <linux/vserver/dlimit.h>
21767 +
21768 +
21769 +#ifdef CONFIG_COMPAT
21770 +#define __COMPAT(name, id, data, compat)       \
21771 +       (compat) ? name ## _x32(id, data) : name(id, data)
21772 +#define __COMPAT_NO_ID(name, data, compat)     \
21773 +       (compat) ? name ## _x32(data) : name(data)
21774 +#else
21775 +#define __COMPAT(name, id, data, compat)       \
21776 +       name(id, data)
21777 +#define __COMPAT_NO_ID(name, data, compat)     \
21778 +       name(data)
21779 +#endif
21780 +
21781 +
21782 +static inline
21783 +long do_vcmd(uint32_t cmd, uint32_t id,
21784 +       struct vx_info *vxi, struct nx_info *nxi,
21785 +       void __user *data, int compat)
21786 +{
21787 +       switch (cmd) {
21788 +
21789 +       case VCMD_get_version:
21790 +               return vc_get_version(id);
21791 +       case VCMD_get_vci:
21792 +               return vc_get_vci(id);
21793 +
21794 +       case VCMD_task_xid:
21795 +               return vc_task_xid(id);
21796 +       case VCMD_vx_info:
21797 +               return vc_vx_info(vxi, data);
21798 +
21799 +       case VCMD_task_nid:
21800 +               return vc_task_nid(id);
21801 +       case VCMD_nx_info:
21802 +               return vc_nx_info(nxi, data);
21803 +
21804 +       case VCMD_task_tag:
21805 +               return vc_task_tag(id);
21806 +
21807 +       case VCMD_set_space_v1:
21808 +               return vc_set_space_v1(vxi, data);
21809 +       /* this is version 2 */
21810 +       case VCMD_set_space:
21811 +               return vc_set_space(vxi, data);
21812 +
21813 +       case VCMD_get_space_mask_v0:
21814 +               return vc_get_space_mask(data, 0);
21815 +       /* this is version 1 */
21816 +       case VCMD_get_space_mask:
21817 +               return vc_get_space_mask(data, 1);
21818 +
21819 +       case VCMD_get_space_default:
21820 +               return vc_get_space_mask(data, -1);
21821 +
21822 +       case VCMD_set_umask:
21823 +               return vc_set_umask(vxi, data);
21824 +
21825 +       case VCMD_get_umask:
21826 +               return vc_get_umask(vxi, data);
21827 +
21828 +       case VCMD_set_wmask:
21829 +               return vc_set_wmask(vxi, data);
21830 +
21831 +       case VCMD_get_wmask:
21832 +               return vc_get_wmask(vxi, data);
21833 +#ifdef CONFIG_IA32_EMULATION
21834 +       case VCMD_get_rlimit:
21835 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
21836 +       case VCMD_set_rlimit:
21837 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
21838 +#else
21839 +       case VCMD_get_rlimit:
21840 +               return vc_get_rlimit(vxi, data);
21841 +       case VCMD_set_rlimit:
21842 +               return vc_set_rlimit(vxi, data);
21843 +#endif
21844 +       case VCMD_get_rlimit_mask:
21845 +               return vc_get_rlimit_mask(id, data);
21846 +       case VCMD_reset_hits:
21847 +               return vc_reset_hits(vxi, data);
21848 +       case VCMD_reset_minmax:
21849 +               return vc_reset_minmax(vxi, data);
21850 +
21851 +       case VCMD_get_vhi_name:
21852 +               return vc_get_vhi_name(vxi, data);
21853 +       case VCMD_set_vhi_name:
21854 +               return vc_set_vhi_name(vxi, data);
21855 +
21856 +       case VCMD_ctx_stat:
21857 +               return vc_ctx_stat(vxi, data);
21858 +       case VCMD_virt_stat:
21859 +               return vc_virt_stat(vxi, data);
21860 +       case VCMD_sock_stat:
21861 +               return vc_sock_stat(vxi, data);
21862 +       case VCMD_rlimit_stat:
21863 +               return vc_rlimit_stat(vxi, data);
21864 +
21865 +       case VCMD_set_cflags:
21866 +               return vc_set_cflags(vxi, data);
21867 +       case VCMD_get_cflags:
21868 +               return vc_get_cflags(vxi, data);
21869 +
21870 +       /* this is version 1 */
21871 +       case VCMD_set_ccaps:
21872 +               return vc_set_ccaps(vxi, data);
21873 +       /* this is version 1 */
21874 +       case VCMD_get_ccaps:
21875 +               return vc_get_ccaps(vxi, data);
21876 +       case VCMD_set_bcaps:
21877 +               return vc_set_bcaps(vxi, data);
21878 +       case VCMD_get_bcaps:
21879 +               return vc_get_bcaps(vxi, data);
21880 +
21881 +       case VCMD_set_badness:
21882 +               return vc_set_badness(vxi, data);
21883 +       case VCMD_get_badness:
21884 +               return vc_get_badness(vxi, data);
21885 +
21886 +       case VCMD_set_nflags:
21887 +               return vc_set_nflags(nxi, data);
21888 +       case VCMD_get_nflags:
21889 +               return vc_get_nflags(nxi, data);
21890 +
21891 +       case VCMD_set_ncaps:
21892 +               return vc_set_ncaps(nxi, data);
21893 +       case VCMD_get_ncaps:
21894 +               return vc_get_ncaps(nxi, data);
21895 +
21896 +       case VCMD_set_prio_bias:
21897 +               return vc_set_prio_bias(vxi, data);
21898 +       case VCMD_get_prio_bias:
21899 +               return vc_get_prio_bias(vxi, data);
21900 +       case VCMD_add_dlimit:
21901 +               return __COMPAT(vc_add_dlimit, id, data, compat);
21902 +       case VCMD_rem_dlimit:
21903 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
21904 +       case VCMD_set_dlimit:
21905 +               return __COMPAT(vc_set_dlimit, id, data, compat);
21906 +       case VCMD_get_dlimit:
21907 +               return __COMPAT(vc_get_dlimit, id, data, compat);
21908 +
21909 +       case VCMD_ctx_kill:
21910 +               return vc_ctx_kill(vxi, data);
21911 +
21912 +       case VCMD_wait_exit:
21913 +               return vc_wait_exit(vxi, data);
21914 +
21915 +       case VCMD_get_iattr:
21916 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
21917 +       case VCMD_set_iattr:
21918 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
21919 +
21920 +       case VCMD_fget_iattr:
21921 +               return vc_fget_iattr(id, data);
21922 +       case VCMD_fset_iattr:
21923 +               return vc_fset_iattr(id, data);
21924 +
21925 +       case VCMD_enter_space_v0:
21926 +               return vc_enter_space_v1(vxi, NULL);
21927 +       case VCMD_enter_space_v1:
21928 +               return vc_enter_space_v1(vxi, data);
21929 +       /* this is version 2 */
21930 +       case VCMD_enter_space:
21931 +               return vc_enter_space(vxi, data);
21932 +
21933 +       case VCMD_ctx_create_v0:
21934 +               return vc_ctx_create(id, NULL);
21935 +       case VCMD_ctx_create:
21936 +               return vc_ctx_create(id, data);
21937 +       case VCMD_ctx_migrate_v0:
21938 +               return vc_ctx_migrate(vxi, NULL);
21939 +       case VCMD_ctx_migrate:
21940 +               return vc_ctx_migrate(vxi, data);
21941 +
21942 +       case VCMD_net_create_v0:
21943 +               return vc_net_create(id, NULL);
21944 +       case VCMD_net_create:
21945 +               return vc_net_create(id, data);
21946 +       case VCMD_net_migrate:
21947 +               return vc_net_migrate(nxi, data);
21948 +
21949 +       case VCMD_tag_migrate:
21950 +               return vc_tag_migrate(id);
21951 +
21952 +       case VCMD_net_add:
21953 +               return vc_net_add(nxi, data);
21954 +       case VCMD_net_remove:
21955 +               return vc_net_remove(nxi, data);
21956 +
21957 +       case VCMD_net_add_ipv4_v1:
21958 +               return vc_net_add_ipv4_v1(nxi, data);
21959 +       /* this is version 2 */
21960 +       case VCMD_net_add_ipv4:
21961 +               return vc_net_add_ipv4(nxi, data);
21962 +
21963 +       case VCMD_net_rem_ipv4_v1:
21964 +               return vc_net_rem_ipv4_v1(nxi, data);
21965 +       /* this is version 2 */
21966 +       case VCMD_net_rem_ipv4:
21967 +               return vc_net_rem_ipv4(nxi, data);
21968 +#ifdef CONFIG_IPV6
21969 +       case VCMD_net_add_ipv6:
21970 +               return vc_net_add_ipv6(nxi, data);
21971 +       case VCMD_net_remove_ipv6:
21972 +               return vc_net_remove_ipv6(nxi, data);
21973 +#endif
21974 +/*     case VCMD_add_match_ipv4:
21975 +               return vc_add_match_ipv4(nxi, data);
21976 +       case VCMD_get_match_ipv4:
21977 +               return vc_get_match_ipv4(nxi, data);
21978 +#ifdef CONFIG_IPV6
21979 +       case VCMD_add_match_ipv6:
21980 +               return vc_add_match_ipv6(nxi, data);
21981 +       case VCMD_get_match_ipv6:
21982 +               return vc_get_match_ipv6(nxi, data);
21983 +#endif */
21984 +
21985 +#ifdef CONFIG_VSERVER_DEVICE
21986 +       case VCMD_set_mapping:
21987 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
21988 +       case VCMD_unset_mapping:
21989 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
21990 +#endif
21991 +#ifdef CONFIG_VSERVER_HISTORY
21992 +       case VCMD_dump_history:
21993 +               return vc_dump_history(id);
21994 +       case VCMD_read_history:
21995 +               return __COMPAT(vc_read_history, id, data, compat);
21996 +#endif
21997 +       default:
21998 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
21999 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22000 +       }
22001 +       return -ENOSYS;
22002 +}
22003 +
22004 +
22005 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
22006 +       case VCMD_ ## vcmd: perm = _perm;               \
22007 +               args = _args; flags = _flags; break
22008 +
22009 +
22010 +#define VCA_NONE       0x00
22011 +#define VCA_VXI                0x01
22012 +#define VCA_NXI                0x02
22013 +
22014 +#define VCF_NONE       0x00
22015 +#define VCF_INFO       0x01
22016 +#define VCF_ADMIN      0x02
22017 +#define VCF_ARES       0x06    /* includes admin */
22018 +#define VCF_SETUP      0x08
22019 +
22020 +#define VCF_ZIDOK      0x10    /* zero id okay */
22021 +
22022 +
22023 +static inline
22024 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22025 +{
22026 +       long ret;
22027 +       int permit = -1, state = 0;
22028 +       int perm = -1, args = 0, flags = 0;
22029 +       struct vx_info *vxi = NULL;
22030 +       struct nx_info *nxi = NULL;
22031 +
22032 +       switch (cmd) {
22033 +       /* unpriviledged commands */
22034 +       __VCMD(get_version,      0, VCA_NONE,   0);
22035 +       __VCMD(get_vci,          0, VCA_NONE,   0);
22036 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
22037 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
22038 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
22039 +       __VCMD(get_space_default,0, VCA_NONE,   0);
22040 +
22041 +       /* info commands */
22042 +       __VCMD(task_xid,         2, VCA_NONE,   0);
22043 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
22044 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
22045 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
22046 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
22047 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
22048 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
22049 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
22050 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
22051 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
22052 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
22053 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
22054 +
22055 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
22056 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
22057 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
22058 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
22059 +
22060 +       __VCMD(task_nid,         2, VCA_NONE,   0);
22061 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
22062 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
22063 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
22064 +
22065 +       __VCMD(task_tag,         2, VCA_NONE,   0);
22066 +
22067 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
22068 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
22069 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
22070 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
22071 +
22072 +       /* lower admin commands */
22073 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
22074 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
22075 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
22076 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
22077 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
22078 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
22079 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
22080 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
22081 +
22082 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
22083 +       __VCMD(net_create,       5, VCA_NONE,   0);
22084 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
22085 +
22086 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
22087 +
22088 +       /* higher admin commands */
22089 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
22090 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22091 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22092 +
22093 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22094 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22095 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22096 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22097 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22098 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22099 +
22100 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22101 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22102 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22103 +
22104 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22105 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22106 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22107 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22108 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22109 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22110 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22111 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22112 +#ifdef CONFIG_IPV6
22113 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22114 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22115 +#endif
22116 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
22117 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
22118 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
22119 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
22120 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
22121 +
22122 +#ifdef CONFIG_VSERVER_DEVICE
22123 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22124 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22125 +#endif
22126 +       /* debug level admin commands */
22127 +#ifdef CONFIG_VSERVER_HISTORY
22128 +       __VCMD(dump_history,     9, VCA_NONE,   0);
22129 +       __VCMD(read_history,     9, VCA_NONE,   0);
22130 +#endif
22131 +
22132 +       default:
22133 +               perm = -1;
22134 +       }
22135 +
22136 +       vxdprintk(VXD_CBIT(switch, 0),
22137 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
22138 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22139 +               VC_VERSION(cmd), id, data, compat,
22140 +               perm, args, flags);
22141 +
22142 +       ret = -ENOSYS;
22143 +       if (perm < 0)
22144 +               goto out;
22145 +
22146 +       state = 1;
22147 +       if (!capable(CAP_CONTEXT))
22148 +               goto out;
22149 +
22150 +       state = 2;
22151 +       /* moved here from the individual commands */
22152 +       ret = -EPERM;
22153 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
22154 +               goto out;
22155 +
22156 +       state = 3;
22157 +       /* vcmd involves resource management  */
22158 +       ret = -EPERM;
22159 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
22160 +               goto out;
22161 +
22162 +       state = 4;
22163 +       /* various legacy exceptions */
22164 +       switch (cmd) {
22165 +       /* will go away when spectator is a cap */
22166 +       case VCMD_ctx_migrate_v0:
22167 +       case VCMD_ctx_migrate:
22168 +               if (id == 1) {
22169 +                       current->xid = 1;
22170 +                       ret = 1;
22171 +                       goto out;
22172 +               }
22173 +               break;
22174 +
22175 +       /* will go away when spectator is a cap */
22176 +       case VCMD_net_migrate:
22177 +               if (id == 1) {
22178 +                       current->nid = 1;
22179 +                       ret = 1;
22180 +                       goto out;
22181 +               }
22182 +               break;
22183 +       }
22184 +
22185 +       /* vcmds are fine by default */
22186 +       permit = 1;
22187 +
22188 +       /* admin type vcmds require admin ... */
22189 +       if (flags & VCF_ADMIN)
22190 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
22191 +
22192 +       /* ... but setup type vcmds override that */
22193 +       if (!permit && (flags & VCF_SETUP))
22194 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
22195 +
22196 +       state = 5;
22197 +       ret = -EPERM;
22198 +       if (!permit)
22199 +               goto out;
22200 +
22201 +       state = 6;
22202 +       if (!id && (flags & VCF_ZIDOK))
22203 +               goto skip_id;
22204 +
22205 +       ret = -ESRCH;
22206 +       if (args & VCA_VXI) {
22207 +               vxi = lookup_vx_info(id);
22208 +               if (!vxi)
22209 +                       goto out;
22210 +
22211 +               if ((flags & VCF_ADMIN) &&
22212 +                       /* special case kill for shutdown */
22213 +                       (cmd != VCMD_ctx_kill) &&
22214 +                       /* can context be administrated? */
22215 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
22216 +                       ret = -EACCES;
22217 +                       goto out_vxi;
22218 +               }
22219 +       }
22220 +       state = 7;
22221 +       if (args & VCA_NXI) {
22222 +               nxi = lookup_nx_info(id);
22223 +               if (!nxi)
22224 +                       goto out_vxi;
22225 +
22226 +               if ((flags & VCF_ADMIN) &&
22227 +                       /* can context be administrated? */
22228 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
22229 +                       ret = -EACCES;
22230 +                       goto out_nxi;
22231 +               }
22232 +       }
22233 +skip_id:
22234 +       state = 8;
22235 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
22236 +
22237 +out_nxi:
22238 +       if ((args & VCA_NXI) && nxi)
22239 +               put_nx_info(nxi);
22240 +out_vxi:
22241 +       if ((args & VCA_VXI) && vxi)
22242 +               put_vx_info(vxi);
22243 +out:
22244 +       vxdprintk(VXD_CBIT(switch, 1),
22245 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
22246 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22247 +               VC_VERSION(cmd), ret, ret, state, permit);
22248 +       return ret;
22249 +}
22250 +
22251 +asmlinkage long
22252 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
22253 +{
22254 +       return do_vserver(cmd, id, data, 0);
22255 +}
22256 +
22257 +#ifdef CONFIG_COMPAT
22258 +
22259 +asmlinkage long
22260 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
22261 +{
22262 +       return do_vserver(cmd, id, data, 1);
22263 +}
22264 +
22265 +#endif /* CONFIG_COMPAT */
22266 diff -NurpP --minimal linux-4.4.110/kernel/vserver/sysctl.c linux-4.4.110-vs2.3.9/kernel/vserver/sysctl.c
22267 --- linux-4.4.110/kernel/vserver/sysctl.c       1970-01-01 00:00:00.000000000 +0000
22268 +++ linux-4.4.110-vs2.3.9/kernel/vserver/sysctl.c       2018-01-09 16:36:34.000000000 +0000
22269 @@ -0,0 +1,247 @@
22270 +/*
22271 + *  kernel/vserver/sysctl.c
22272 + *
22273 + *  Virtual Context Support
22274 + *
22275 + *  Copyright (C) 2004-2007  Herbert P?tzl
22276 + *
22277 + *  V0.01  basic structure
22278 + *
22279 + */
22280 +
22281 +#include <linux/module.h>
22282 +#include <linux/ctype.h>
22283 +#include <linux/sysctl.h>
22284 +#include <linux/parser.h>
22285 +#include <asm/uaccess.h>
22286 +
22287 +enum {
22288 +       CTL_DEBUG_ERROR         = 0,
22289 +       CTL_DEBUG_SWITCH        = 1,
22290 +       CTL_DEBUG_XID,
22291 +       CTL_DEBUG_NID,
22292 +       CTL_DEBUG_TAG,
22293 +       CTL_DEBUG_NET,
22294 +       CTL_DEBUG_LIMIT,
22295 +       CTL_DEBUG_CRES,
22296 +       CTL_DEBUG_DLIM,
22297 +       CTL_DEBUG_QUOTA,
22298 +       CTL_DEBUG_CVIRT,
22299 +       CTL_DEBUG_SPACE,
22300 +       CTL_DEBUG_PERM,
22301 +       CTL_DEBUG_MISC,
22302 +};
22303 +
22304 +
22305 +unsigned int vs_debug_switch   = 0;
22306 +unsigned int vs_debug_xid      = 0;
22307 +unsigned int vs_debug_nid      = 0;
22308 +unsigned int vs_debug_tag      = 0;
22309 +unsigned int vs_debug_net      = 0;
22310 +unsigned int vs_debug_limit    = 0;
22311 +unsigned int vs_debug_cres     = 0;
22312 +unsigned int vs_debug_dlim     = 0;
22313 +unsigned int vs_debug_quota    = 0;
22314 +unsigned int vs_debug_cvirt    = 0;
22315 +unsigned int vs_debug_space    = 0;
22316 +unsigned int vs_debug_perm     = 0;
22317 +unsigned int vs_debug_misc     = 0;
22318 +
22319 +
22320 +static struct ctl_table_header *vserver_table_header;
22321 +static struct ctl_table vserver_root_table[];
22322 +
22323 +
22324 +void vserver_register_sysctl(void)
22325 +{
22326 +       if (!vserver_table_header) {
22327 +               vserver_table_header = register_sysctl_table(vserver_root_table);
22328 +       }
22329 +
22330 +}
22331 +
22332 +void vserver_unregister_sysctl(void)
22333 +{
22334 +       if (vserver_table_header) {
22335 +               unregister_sysctl_table(vserver_table_header);
22336 +               vserver_table_header = NULL;
22337 +       }
22338 +}
22339 +
22340 +
22341 +static int proc_dodebug(struct ctl_table *table, int write,
22342 +       void __user *buffer, size_t *lenp, loff_t *ppos)
22343 +{
22344 +       char            tmpbuf[20], *p, c;
22345 +       unsigned int    value;
22346 +       size_t          left, len;
22347 +
22348 +       if ((*ppos && !write) || !*lenp) {
22349 +               *lenp = 0;
22350 +               return 0;
22351 +       }
22352 +
22353 +       left = *lenp;
22354 +
22355 +       if (write) {
22356 +               if (!access_ok(VERIFY_READ, buffer, left))
22357 +                       return -EFAULT;
22358 +               p = (char *)buffer;
22359 +               while (left && __get_user(c, p) >= 0 && isspace(c))
22360 +                       left--, p++;
22361 +               if (!left)
22362 +                       goto done;
22363 +
22364 +               if (left > sizeof(tmpbuf) - 1)
22365 +                       return -EINVAL;
22366 +               if (copy_from_user(tmpbuf, p, left))
22367 +                       return -EFAULT;
22368 +               tmpbuf[left] = '\0';
22369 +
22370 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
22371 +                       value = 10 * value + (*p - '0');
22372 +               if (*p && !isspace(*p))
22373 +                       return -EINVAL;
22374 +               while (left && isspace(*p))
22375 +                       left--, p++;
22376 +               *(unsigned int *)table->data = value;
22377 +       } else {
22378 +               if (!access_ok(VERIFY_WRITE, buffer, left))
22379 +                       return -EFAULT;
22380 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
22381 +               if (len > left)
22382 +                       len = left;
22383 +               if (__copy_to_user(buffer, tmpbuf, len))
22384 +                       return -EFAULT;
22385 +               if ((left -= len) > 0) {
22386 +                       if (put_user('\n', (char *)buffer + len))
22387 +                               return -EFAULT;
22388 +                       left--;
22389 +               }
22390 +       }
22391 +
22392 +done:
22393 +       *lenp -= left;
22394 +       *ppos += *lenp;
22395 +       return 0;
22396 +}
22397 +
22398 +static int zero;
22399 +
22400 +#define        CTL_ENTRY(ctl, name)                            \
22401 +       {                                               \
22402 +               .procname       = #name,                \
22403 +               .data           = &vs_ ## name,         \
22404 +               .maxlen         = sizeof(int),          \
22405 +               .mode           = 0644,                 \
22406 +               .proc_handler   = &proc_dodebug,        \
22407 +               .extra1         = &zero,                \
22408 +               .extra2         = &zero,                \
22409 +       }
22410 +
22411 +static struct ctl_table vserver_debug_table[] = {
22412 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
22413 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
22414 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
22415 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
22416 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
22417 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
22418 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
22419 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
22420 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
22421 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
22422 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
22423 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
22424 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
22425 +       { 0 }
22426 +};
22427 +
22428 +static struct ctl_table vserver_root_table[] = {
22429 +       {
22430 +               .procname       = "vserver",
22431 +               .mode           = 0555,
22432 +               .child          = vserver_debug_table
22433 +       },
22434 +       { 0 }
22435 +};
22436 +
22437 +
22438 +static match_table_t tokens = {
22439 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
22440 +       { CTL_DEBUG_XID,        "xid=%x"        },
22441 +       { CTL_DEBUG_NID,        "nid=%x"        },
22442 +       { CTL_DEBUG_TAG,        "tag=%x"        },
22443 +       { CTL_DEBUG_NET,        "net=%x"        },
22444 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
22445 +       { CTL_DEBUG_CRES,       "cres=%x"       },
22446 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
22447 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
22448 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
22449 +       { CTL_DEBUG_SPACE,      "space=%x"      },
22450 +       { CTL_DEBUG_PERM,       "perm=%x"       },
22451 +       { CTL_DEBUG_MISC,       "misc=%x"       },
22452 +       { CTL_DEBUG_ERROR,      NULL            }
22453 +};
22454 +
22455 +#define        HANDLE_CASE(id, name, val)                              \
22456 +       case CTL_DEBUG_ ## id:                                  \
22457 +               vs_debug_ ## name = val;                        \
22458 +               printk("vs_debug_" #name "=0x%x\n", val);       \
22459 +               break
22460 +
22461 +
22462 +static int __init vs_debug_setup(char *str)
22463 +{
22464 +       char *p;
22465 +       int token;
22466 +
22467 +       printk("vs_debug_setup(%s)\n", str);
22468 +       while ((p = strsep(&str, ",")) != NULL) {
22469 +               substring_t args[MAX_OPT_ARGS];
22470 +               unsigned int value;
22471 +
22472 +               if (!*p)
22473 +                       continue;
22474 +
22475 +               token = match_token(p, tokens, args);
22476 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
22477 +
22478 +               switch (token) {
22479 +               HANDLE_CASE(SWITCH, switch, value);
22480 +               HANDLE_CASE(XID,    xid,    value);
22481 +               HANDLE_CASE(NID,    nid,    value);
22482 +               HANDLE_CASE(TAG,    tag,    value);
22483 +               HANDLE_CASE(NET,    net,    value);
22484 +               HANDLE_CASE(LIMIT,  limit,  value);
22485 +               HANDLE_CASE(CRES,   cres,   value);
22486 +               HANDLE_CASE(DLIM,   dlim,   value);
22487 +               HANDLE_CASE(QUOTA,  quota,  value);
22488 +               HANDLE_CASE(CVIRT,  cvirt,  value);
22489 +               HANDLE_CASE(SPACE,  space,  value);
22490 +               HANDLE_CASE(PERM,   perm,   value);
22491 +               HANDLE_CASE(MISC,   misc,   value);
22492 +               default:
22493 +                       return -EINVAL;
22494 +                       break;
22495 +               }
22496 +       }
22497 +       return 1;
22498 +}
22499 +
22500 +__setup("vsdebug=", vs_debug_setup);
22501 +
22502 +
22503 +
22504 +EXPORT_SYMBOL_GPL(vs_debug_switch);
22505 +EXPORT_SYMBOL_GPL(vs_debug_xid);
22506 +EXPORT_SYMBOL_GPL(vs_debug_nid);
22507 +EXPORT_SYMBOL_GPL(vs_debug_net);
22508 +EXPORT_SYMBOL_GPL(vs_debug_limit);
22509 +EXPORT_SYMBOL_GPL(vs_debug_cres);
22510 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
22511 +EXPORT_SYMBOL_GPL(vs_debug_quota);
22512 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
22513 +EXPORT_SYMBOL_GPL(vs_debug_space);
22514 +EXPORT_SYMBOL_GPL(vs_debug_perm);
22515 +EXPORT_SYMBOL_GPL(vs_debug_misc);
22516 +
22517 diff -NurpP --minimal linux-4.4.110/kernel/vserver/tag.c linux-4.4.110-vs2.3.9/kernel/vserver/tag.c
22518 --- linux-4.4.110/kernel/vserver/tag.c  1970-01-01 00:00:00.000000000 +0000
22519 +++ linux-4.4.110-vs2.3.9/kernel/vserver/tag.c  2018-01-09 16:36:34.000000000 +0000
22520 @@ -0,0 +1,63 @@
22521 +/*
22522 + *  linux/kernel/vserver/tag.c
22523 + *
22524 + *  Virtual Server: Shallow Tag Space
22525 + *
22526 + *  Copyright (C) 2007  Herbert P?tzl
22527 + *
22528 + *  V0.01  basic implementation
22529 + *
22530 + */
22531 +
22532 +#include <linux/sched.h>
22533 +#include <linux/vserver/debug.h>
22534 +#include <linux/vs_pid.h>
22535 +#include <linux/vs_tag.h>
22536 +
22537 +#include <linux/vserver/tag_cmd.h>
22538 +
22539 +
22540 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
22541 +{
22542 +       if (!p)
22543 +               BUG();
22544 +
22545 +       vxdprintk(VXD_CBIT(tag, 5),
22546 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
22547 +
22548 +       task_lock(p);
22549 +       p->tag = tag;
22550 +       task_unlock(p);
22551 +
22552 +       vxdprintk(VXD_CBIT(tag, 5),
22553 +               "moved task %p into [#%d]", p, tag);
22554 +       return 0;
22555 +}
22556 +
22557 +/* vserver syscall commands below here */
22558 +
22559 +/* taks xid and vx_info functions */
22560 +
22561 +
22562 +int vc_task_tag(uint32_t id)
22563 +{
22564 +       vtag_t tag;
22565 +
22566 +       if (id) {
22567 +               struct task_struct *tsk;
22568 +               rcu_read_lock();
22569 +               tsk = find_task_by_real_pid(id);
22570 +               tag = (tsk) ? tsk->tag : -ESRCH;
22571 +               rcu_read_unlock();
22572 +       } else
22573 +               tag = dx_current_tag();
22574 +       return tag;
22575 +}
22576 +
22577 +
22578 +int vc_tag_migrate(uint32_t tag)
22579 +{
22580 +       return dx_migrate_task(current, tag & 0xFFFF);
22581 +}
22582 +
22583 +
22584 diff -NurpP --minimal linux-4.4.110/kernel/vserver/vci_config.h linux-4.4.110-vs2.3.9/kernel/vserver/vci_config.h
22585 --- linux-4.4.110/kernel/vserver/vci_config.h   1970-01-01 00:00:00.000000000 +0000
22586 +++ linux-4.4.110-vs2.3.9/kernel/vserver/vci_config.h   2018-01-09 16:36:34.000000000 +0000
22587 @@ -0,0 +1,80 @@
22588 +
22589 +/*  interface version */
22590 +
22591 +#define VCI_VERSION            0x00020308
22592 +
22593 +
22594 +enum {
22595 +       VCI_KCBIT_NO_DYNAMIC = 0,
22596 +
22597 +       VCI_KCBIT_PROC_SECURE = 4,
22598 +       /* VCI_KCBIT_HARDCPU = 5, */
22599 +       /* VCI_KCBIT_IDLELIMIT = 6, */
22600 +       /* VCI_KCBIT_IDLETIME = 7, */
22601 +
22602 +       VCI_KCBIT_COWBL = 8,
22603 +       VCI_KCBIT_FULLCOWBL = 9,
22604 +       VCI_KCBIT_SPACES = 10,
22605 +       VCI_KCBIT_NETV2 = 11,
22606 +       VCI_KCBIT_MEMCG = 12,
22607 +       VCI_KCBIT_MEMCG_SWAP = 13,
22608 +
22609 +       VCI_KCBIT_DEBUG = 16,
22610 +       VCI_KCBIT_HISTORY = 20,
22611 +       VCI_KCBIT_TAGGED = 24,
22612 +       VCI_KCBIT_PPTAG = 28,
22613 +
22614 +       VCI_KCBIT_MORE = 31,
22615 +};
22616 +
22617 +
22618 +static inline uint32_t vci_kernel_config(void)
22619 +{
22620 +       return
22621 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
22622 +
22623 +       /* configured features */
22624 +#ifdef CONFIG_VSERVER_PROC_SECURE
22625 +       (1 << VCI_KCBIT_PROC_SECURE) |
22626 +#endif
22627 +#ifdef CONFIG_VSERVER_COWBL
22628 +       (1 << VCI_KCBIT_COWBL) |
22629 +       (1 << VCI_KCBIT_FULLCOWBL) |
22630 +#endif
22631 +       (1 << VCI_KCBIT_SPACES) |
22632 +       (1 << VCI_KCBIT_NETV2) |
22633 +#ifdef CONFIG_MEMCG
22634 +       (1 << VCI_KCBIT_MEMCG) |
22635 +#endif
22636 +#ifdef CONFIG_MEMCG_SWAP
22637 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
22638 +#endif
22639 +
22640 +       /* debug options */
22641 +#ifdef CONFIG_VSERVER_DEBUG
22642 +       (1 << VCI_KCBIT_DEBUG) |
22643 +#endif
22644 +#ifdef CONFIG_VSERVER_HISTORY
22645 +       (1 << VCI_KCBIT_HISTORY) |
22646 +#endif
22647 +
22648 +       /* inode context tagging */
22649 +#if    defined(CONFIG_TAGGING_NONE)
22650 +       (0 << VCI_KCBIT_TAGGED) |
22651 +#elif  defined(CONFIG_TAGGING_UID16)
22652 +       (1 << VCI_KCBIT_TAGGED) |
22653 +#elif  defined(CONFIG_TAGGING_GID16)
22654 +       (2 << VCI_KCBIT_TAGGED) |
22655 +#elif  defined(CONFIG_TAGGING_ID24)
22656 +       (3 << VCI_KCBIT_TAGGED) |
22657 +#elif  defined(CONFIG_TAGGING_INTERN)
22658 +       (4 << VCI_KCBIT_TAGGED) |
22659 +#elif  defined(CONFIG_TAGGING_RUNTIME)
22660 +       (5 << VCI_KCBIT_TAGGED) |
22661 +#else
22662 +       (7 << VCI_KCBIT_TAGGED) |
22663 +#endif
22664 +       (1 << VCI_KCBIT_PPTAG) |
22665 +       0;
22666 +}
22667 +
22668 diff -NurpP --minimal linux-4.4.110/mm/memcontrol.c linux-4.4.110-vs2.3.9/mm/memcontrol.c
22669 --- linux-4.4.110/mm/memcontrol.c       2018-01-09 16:35:14.000000000 +0000
22670 +++ linux-4.4.110-vs2.3.9/mm/memcontrol.c       2018-01-09 16:36:34.000000000 +0000
22671 @@ -2888,6 +2888,28 @@ static u64 mem_cgroup_read_u64(struct cg
22672         }
22673  }
22674  
22675 +u64 mem_cgroup_mem_usage_pages(struct mem_cgroup *memcg)
22676 +{
22677 +       return mem_cgroup_usage(memcg, false) >> PAGE_SHIFT;
22678 +}
22679 +
22680 +u64 mem_cgroup_mem_limit_pages(struct mem_cgroup *memcg)
22681 +{
22682 +       return (u64)memcg->memory.limit;
22683 +}
22684 +
22685 +u64 mem_cgroup_memsw_usage_pages(struct mem_cgroup *memcg)
22686 +{
22687 +       return mem_cgroup_usage(memcg, true) >> PAGE_SHIFT;
22688 +}
22689 +
22690 +u64 mem_cgroup_memsw_limit_pages(struct mem_cgroup *memcg)
22691 +{
22692 +       return (u64)memcg->memsw.limit;
22693 +}
22694 +
22695 +
22696 +
22697  #ifdef CONFIG_MEMCG_KMEM
22698  static int memcg_activate_kmem(struct mem_cgroup *memcg,
22699                                unsigned long nr_pages)
22700 diff -NurpP --minimal linux-4.4.110/mm/oom_kill.c linux-4.4.110-vs2.3.9/mm/oom_kill.c
22701 --- linux-4.4.110/mm/oom_kill.c 2016-07-05 04:15:13.000000000 +0000
22702 +++ linux-4.4.110-vs2.3.9/mm/oom_kill.c 2018-01-09 16:56:23.000000000 +0000
22703 @@ -35,6 +35,8 @@
22704  #include <linux/freezer.h>
22705  #include <linux/ftrace.h>
22706  #include <linux/ratelimit.h>
22707 +#include <linux/reboot.h>
22708 +#include <linux/vs_context.h>
22709  
22710  #define CREATE_TRACE_POINTS
22711  #include <trace/events/oom.h>
22712 @@ -131,11 +133,18 @@ static inline bool is_sysrq_oom(struct o
22713  static bool oom_unkillable_task(struct task_struct *p,
22714                 struct mem_cgroup *memcg, const nodemask_t *nodemask)
22715  {
22716 -       if (is_global_init(p))
22717 +       unsigned xid = vx_current_xid();
22718 +
22719 +       /* skip the init task, global and per guest */
22720 +       if (task_is_init(p))
22721                 return true;
22722         if (p->flags & PF_KTHREAD)
22723                 return true;
22724  
22725 +       /* skip other guest and host processes if oom in guest */
22726 +       if (xid && vx_task_xid(p) != xid)
22727 +               return true;
22728 +
22729         /* When mem_cgroup_out_of_memory() and p is not member of the group */
22730         if (memcg && !task_in_mem_cgroup(p, memcg))
22731                 return true;
22732 @@ -534,8 +543,8 @@ void oom_kill_process(struct oom_control
22733         if (__ratelimit(&oom_rs))
22734                 dump_header(oc, p, memcg);
22735  
22736 -       pr_err("%s: Kill process %d (%s) score %u or sacrifice child\n",
22737 -               message, task_pid_nr(p), p->comm, points);
22738 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
22739 +               message, task_pid_nr(p), p->xid, p->comm, points);
22740  
22741         /*
22742          * If any of p's children has a different mm and is eligible for kill,
22743 @@ -585,8 +594,8 @@ void oom_kill_process(struct oom_control
22744          */
22745         do_send_sig_info(SIGKILL, SEND_SIG_FORCED, victim, true);
22746         mark_oom_victim(victim);
22747 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
22748 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
22749 +       pr_err("Killed process %d:%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
22750 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
22751                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
22752                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
22753         task_unlock(victim);
22754 @@ -622,6 +631,8 @@ void oom_kill_process(struct oom_control
22755  }
22756  #undef K
22757  
22758 +long vs_oom_action(unsigned int);
22759 +
22760  /*
22761   * Determines whether the kernel must panic because of the panic_on_oom sysctl.
22762   */
22763 @@ -722,7 +733,12 @@ bool out_of_memory(struct oom_control *o
22764         /* Found nothing?!?! Either we hang forever, or we panic. */
22765         if (!p && !is_sysrq_oom(oc)) {
22766                 dump_header(oc, NULL, NULL);
22767 -               panic("Out of memory and no killable processes...\n");
22768 +
22769 +               /* avoid panic for guest OOM */
22770 +               if (vx_current_xid())
22771 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
22772 +               else
22773 +                       panic("Out of memory and no killable processes...\n");
22774         }
22775         if (p && p != (void *)-1UL) {
22776                 oom_kill_process(oc, p, points, totalpages, NULL,
22777 diff -NurpP --minimal linux-4.4.110/mm/page_alloc.c linux-4.4.110-vs2.3.9/mm/page_alloc.c
22778 --- linux-4.4.110/mm/page_alloc.c       2018-01-09 16:35:14.000000000 +0000
22779 +++ linux-4.4.110-vs2.3.9/mm/page_alloc.c       2018-01-09 16:57:52.000000000 +0000
22780 @@ -62,6 +62,8 @@
22781  #include <linux/sched/rt.h>
22782  #include <linux/page_owner.h>
22783  #include <linux/kthread.h>
22784 +#include <linux/vs_base.h>
22785 +#include <linux/vs_limit.h>
22786  
22787  #include <asm/sections.h>
22788  #include <asm/tlbflush.h>
22789 @@ -3661,6 +3663,9 @@ void si_meminfo(struct sysinfo *val)
22790         val->totalhigh = totalhigh_pages;
22791         val->freehigh = nr_free_highpages();
22792         val->mem_unit = PAGE_SIZE;
22793 +
22794 +       if (vx_flags(VXF_VIRT_MEM, 0))
22795 +               vx_vsi_meminfo(val);
22796  }
22797  
22798  EXPORT_SYMBOL(si_meminfo);
22799 @@ -3686,6 +3691,9 @@ void si_meminfo_node(struct sysinfo *val
22800         val->freehigh = 0;
22801  #endif
22802         val->mem_unit = PAGE_SIZE;
22803 +
22804 +       if (vx_flags(VXF_VIRT_MEM, 0))
22805 +               vx_vsi_meminfo(val);
22806  }
22807  #endif
22808  
22809 diff -NurpP --minimal linux-4.4.110/mm/pgtable-generic.c linux-4.4.110-vs2.3.9/mm/pgtable-generic.c
22810 --- linux-4.4.110/mm/pgtable-generic.c  2018-01-09 16:35:14.000000000 +0000
22811 +++ linux-4.4.110-vs2.3.9/mm/pgtable-generic.c  2018-01-09 16:36:34.000000000 +0000
22812 @@ -6,6 +6,8 @@
22813   *  Copyright (C) 2010  Linus Torvalds
22814   */
22815  
22816 +#include <linux/mm.h>
22817 +
22818  #include <linux/pagemap.h>
22819  #include <asm/tlb.h>
22820  #include <asm-generic/pgtable.h>
22821 diff -NurpP --minimal linux-4.4.110/mm/shmem.c linux-4.4.110-vs2.3.9/mm/shmem.c
22822 --- linux-4.4.110/mm/shmem.c    2018-01-09 16:35:14.000000000 +0000
22823 +++ linux-4.4.110-vs2.3.9/mm/shmem.c    2018-01-09 16:36:34.000000000 +0000
22824 @@ -2198,7 +2198,7 @@ static int shmem_statfs(struct dentry *d
22825  {
22826         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
22827  
22828 -       buf->f_type = TMPFS_MAGIC;
22829 +       buf->f_type = TMPFS_SUPER_MAGIC;
22830         buf->f_bsize = PAGE_CACHE_SIZE;
22831         buf->f_namelen = NAME_MAX;
22832         if (sbinfo->max_blocks) {
22833 @@ -3044,7 +3044,7 @@ int shmem_fill_super(struct super_block
22834         sb->s_maxbytes = MAX_LFS_FILESIZE;
22835         sb->s_blocksize = PAGE_CACHE_SIZE;
22836         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
22837 -       sb->s_magic = TMPFS_MAGIC;
22838 +       sb->s_magic = TMPFS_SUPER_MAGIC;
22839         sb->s_op = &shmem_ops;
22840         sb->s_time_gran = 1;
22841  #ifdef CONFIG_TMPFS_XATTR
22842 diff -NurpP --minimal linux-4.4.110/mm/slab.c linux-4.4.110-vs2.3.9/mm/slab.c
22843 --- linux-4.4.110/mm/slab.c     2016-07-05 04:15:13.000000000 +0000
22844 +++ linux-4.4.110-vs2.3.9/mm/slab.c     2018-01-09 16:36:34.000000000 +0000
22845 @@ -337,6 +337,8 @@ static void kmem_cache_node_init(struct
22846  #define STATS_INC_FREEMISS(x)  do { } while (0)
22847  #endif
22848  
22849 +#include "slab_vs.h"
22850 +
22851  #if DEBUG
22852  
22853  /*
22854 @@ -3183,6 +3185,7 @@ slab_alloc_node(struct kmem_cache *cache
22855         /* ___cache_alloc_node can fall back to other nodes */
22856         ptr = ____cache_alloc_node(cachep, flags, nodeid);
22857    out:
22858 +       vx_slab_alloc(cachep, flags);
22859         local_irq_restore(save_flags);
22860         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
22861         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
22862 @@ -3371,6 +3374,7 @@ static inline void __cache_free(struct k
22863         check_irq_off();
22864         kmemleak_free_recursive(objp, cachep->flags);
22865         objp = cache_free_debugcheck(cachep, objp, caller);
22866 +       vx_slab_free(cachep);
22867  
22868         kmemcheck_slab_free(cachep, objp, cachep->object_size);
22869  
22870 diff -NurpP --minimal linux-4.4.110/mm/slab_vs.h linux-4.4.110-vs2.3.9/mm/slab_vs.h
22871 --- linux-4.4.110/mm/slab_vs.h  1970-01-01 00:00:00.000000000 +0000
22872 +++ linux-4.4.110-vs2.3.9/mm/slab_vs.h  2018-01-09 16:36:34.000000000 +0000
22873 @@ -0,0 +1,29 @@
22874 +
22875 +#include <linux/vserver/context.h>
22876 +
22877 +#include <linux/vs_context.h>
22878 +
22879 +static inline
22880 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
22881 +{
22882 +       int what = gfp_zone(cachep->allocflags);
22883 +       struct vx_info *vxi = current_vx_info();
22884 +
22885 +       if (!vxi)
22886 +               return;
22887 +
22888 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
22889 +}
22890 +
22891 +static inline
22892 +void vx_slab_free(struct kmem_cache *cachep)
22893 +{
22894 +       int what = gfp_zone(cachep->allocflags);
22895 +       struct vx_info *vxi = current_vx_info();
22896 +
22897 +       if (!vxi)
22898 +               return;
22899 +
22900 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
22901 +}
22902 +
22903 diff -NurpP --minimal linux-4.4.110/mm/swapfile.c linux-4.4.110-vs2.3.9/mm/swapfile.c
22904 --- linux-4.4.110/mm/swapfile.c 2018-01-09 16:35:14.000000000 +0000
22905 +++ linux-4.4.110-vs2.3.9/mm/swapfile.c 2018-01-09 16:36:34.000000000 +0000
22906 @@ -39,6 +39,7 @@
22907  #include <asm/tlbflush.h>
22908  #include <linux/swapops.h>
22909  #include <linux/swap_cgroup.h>
22910 +#include <linux/vs_base.h>
22911  
22912  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
22913                                  unsigned char);
22914 @@ -2070,6 +2071,16 @@ static int swap_show(struct seq_file *sw
22915  
22916         if (si == SEQ_START_TOKEN) {
22917                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
22918 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
22919 +                       struct sysinfo si = { 0 };
22920 +
22921 +                       vx_vsi_swapinfo(&si);
22922 +                       if (si.totalswap < (1 << 10))
22923 +                               return 0;
22924 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
22925 +                               "hdv0", "partition", si.totalswap >> 10,
22926 +                               (si.totalswap - si.freeswap) >> 10, -1);
22927 +               }
22928                 return 0;
22929         }
22930  
22931 @@ -2609,6 +2620,8 @@ void si_swapinfo(struct sysinfo *val)
22932         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
22933         val->totalswap = total_swap_pages + nr_to_be_unused;
22934         spin_unlock(&swap_lock);
22935 +       if (vx_flags(VXF_VIRT_MEM, 0))
22936 +               vx_vsi_swapinfo(val);
22937  }
22938  
22939  /*
22940 diff -NurpP --minimal linux-4.4.110/net/bridge/br_multicast.c linux-4.4.110-vs2.3.9/net/bridge/br_multicast.c
22941 --- linux-4.4.110/net/bridge/br_multicast.c     2018-01-09 16:35:14.000000000 +0000
22942 +++ linux-4.4.110-vs2.3.9/net/bridge/br_multicast.c     2018-01-09 16:36:34.000000000 +0000
22943 @@ -462,7 +462,7 @@ static struct sk_buff *br_ip6_multicast_
22944         ip6h->hop_limit = 1;
22945         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
22946         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
22947 -                              &ip6h->saddr)) {
22948 +                              &ip6h->saddr, NULL)) {
22949                 kfree_skb(skb);
22950                 br->has_ipv6_addr = 0;
22951                 return NULL;
22952 diff -NurpP --minimal linux-4.4.110/net/core/dev.c linux-4.4.110-vs2.3.9/net/core/dev.c
22953 --- linux-4.4.110/net/core/dev.c        2018-01-09 16:35:15.000000000 +0000
22954 +++ linux-4.4.110-vs2.3.9/net/core/dev.c        2018-01-09 16:36:34.000000000 +0000
22955 @@ -124,6 +124,7 @@
22956  #include <linux/in.h>
22957  #include <linux/jhash.h>
22958  #include <linux/random.h>
22959 +#include <linux/vs_inet.h>
22960  #include <trace/events/napi.h>
22961  #include <trace/events/net.h>
22962  #include <trace/events/skb.h>
22963 @@ -726,7 +727,8 @@ struct net_device *__dev_get_by_name(str
22964         struct hlist_head *head = dev_name_hash(net, name);
22965  
22966         hlist_for_each_entry(dev, head, name_hlist)
22967 -               if (!strncmp(dev->name, name, IFNAMSIZ))
22968 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
22969 +                   nx_dev_visible(current_nx_info(), dev))
22970                         return dev;
22971  
22972         return NULL;
22973 @@ -751,7 +753,8 @@ struct net_device *dev_get_by_name_rcu(s
22974         struct hlist_head *head = dev_name_hash(net, name);
22975  
22976         hlist_for_each_entry_rcu(dev, head, name_hlist)
22977 -               if (!strncmp(dev->name, name, IFNAMSIZ))
22978 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
22979 +                   nx_dev_visible(current_nx_info(), dev))
22980                         return dev;
22981  
22982         return NULL;
22983 @@ -801,7 +804,8 @@ struct net_device *__dev_get_by_index(st
22984         struct hlist_head *head = dev_index_hash(net, ifindex);
22985  
22986         hlist_for_each_entry(dev, head, index_hlist)
22987 -               if (dev->ifindex == ifindex)
22988 +               if ((dev->ifindex == ifindex) &&
22989 +                   nx_dev_visible(current_nx_info(), dev))
22990                         return dev;
22991  
22992         return NULL;
22993 @@ -819,7 +823,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
22994   *     about locking. The caller must hold RCU lock.
22995   */
22996  
22997 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
22998 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
22999  {
23000         struct net_device *dev;
23001         struct hlist_head *head = dev_index_hash(net, ifindex);
23002 @@ -830,6 +834,16 @@ struct net_device *dev_get_by_index_rcu(
23003  
23004         return NULL;
23005  }
23006 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23007 +
23008 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23009 +{
23010 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23011 +
23012 +       if (nx_dev_visible(current_nx_info(), dev))
23013 +               return dev;
23014 +       return NULL;
23015 +}
23016  EXPORT_SYMBOL(dev_get_by_index_rcu);
23017  
23018  
23019 @@ -912,7 +926,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23020  
23021         for_each_netdev_rcu(net, dev)
23022                 if (dev->type == type &&
23023 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
23024 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23025 +                   nx_dev_visible(current_nx_info(), dev))
23026                         return dev;
23027  
23028         return NULL;
23029 @@ -924,9 +939,11 @@ struct net_device *__dev_getfirstbyhwtyp
23030         struct net_device *dev;
23031  
23032         ASSERT_RTNL();
23033 -       for_each_netdev(net, dev)
23034 -               if (dev->type == type)
23035 +       for_each_netdev(net, dev) {
23036 +               if ((dev->type == type) &&
23037 +                   nx_dev_visible(current_nx_info(), dev))
23038                         return dev;
23039 +       }
23040  
23041         return NULL;
23042  }
23043 @@ -938,7 +955,8 @@ struct net_device *dev_getfirstbyhwtype(
23044  
23045         rcu_read_lock();
23046         for_each_netdev_rcu(net, dev)
23047 -               if (dev->type == type) {
23048 +               if ((dev->type == type) &&
23049 +                   nx_dev_visible(current_nx_info(), dev)) {
23050                         dev_hold(dev);
23051                         ret = dev;
23052                         break;
23053 @@ -968,7 +986,8 @@ struct net_device *__dev_get_by_flags(st
23054  
23055         ret = NULL;
23056         for_each_netdev(net, dev) {
23057 -               if (((dev->flags ^ if_flags) & mask) == 0) {
23058 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
23059 +                       nx_dev_visible(current_nx_info(), dev)) {
23060                         ret = dev;
23061                         break;
23062                 }
23063 @@ -1046,6 +1065,8 @@ static int __dev_alloc_name(struct net *
23064                                 continue;
23065                         if (i < 0 || i >= max_netdevices)
23066                                 continue;
23067 +                       if (!nx_dev_visible(current_nx_info(), d))
23068 +                               continue;
23069  
23070                         /*  avoid cases where sscanf is not exact inverse of printf */
23071                         snprintf(buf, IFNAMSIZ, name, i);
23072 diff -NurpP --minimal linux-4.4.110/net/core/net-procfs.c linux-4.4.110-vs2.3.9/net/core/net-procfs.c
23073 --- linux-4.4.110/net/core/net-procfs.c 2015-04-12 22:12:50.000000000 +0000
23074 +++ linux-4.4.110-vs2.3.9/net/core/net-procfs.c 2018-01-09 16:36:34.000000000 +0000
23075 @@ -1,6 +1,7 @@
23076  #include <linux/netdevice.h>
23077  #include <linux/proc_fs.h>
23078  #include <linux/seq_file.h>
23079 +#include <linux/vs_inet.h>
23080  #include <net/wext.h>
23081  
23082  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
23083 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
23084  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
23085  {
23086         struct rtnl_link_stats64 temp;
23087 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23088 +       const struct rtnl_link_stats64 *stats;
23089 +
23090 +       /* device visible inside network context? */
23091 +       if (!nx_dev_visible(current_nx_info(), dev))
23092 +               return;
23093  
23094 +       stats = dev_get_stats(dev, &temp);
23095         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23096                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23097                    dev->name, stats->rx_bytes, stats->rx_packets,
23098 diff -NurpP --minimal linux-4.4.110/net/core/rtnetlink.c linux-4.4.110-vs2.3.9/net/core/rtnetlink.c
23099 --- linux-4.4.110/net/core/rtnetlink.c  2018-01-09 16:35:15.000000000 +0000
23100 +++ linux-4.4.110-vs2.3.9/net/core/rtnetlink.c  2018-01-09 16:36:34.000000000 +0000
23101 @@ -1456,6 +1456,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23102                 hlist_for_each_entry(dev, head, index_hlist) {
23103                         if (idx < s_idx)
23104                                 goto cont;
23105 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23106 +                               continue;
23107                         err = rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23108                                                NETLINK_CB(cb->skb).portid,
23109                                                cb->nlh->nlmsg_seq, 0,
23110 @@ -2559,6 +2561,9 @@ void rtmsg_ifinfo(int type, struct net_d
23111  {
23112         struct sk_buff *skb;
23113  
23114 +       if (!nx_dev_visible(current_nx_info(), dev))
23115 +               return;
23116 +
23117         if (dev->reg_state != NETREG_REGISTERED)
23118                 return;
23119  
23120 diff -NurpP --minimal linux-4.4.110/net/core/sock.c linux-4.4.110-vs2.3.9/net/core/sock.c
23121 --- linux-4.4.110/net/core/sock.c       2018-01-09 16:35:15.000000000 +0000
23122 +++ linux-4.4.110-vs2.3.9/net/core/sock.c       2018-01-09 17:15:58.000000000 +0000
23123 @@ -134,6 +134,10 @@
23124  #include <linux/sock_diag.h>
23125  
23126  #include <linux/filter.h>
23127 +#include <linux/vs_socket.h>
23128 +#include <linux/vs_limit.h>
23129 +#include <linux/vs_context.h>
23130 +#include <linux/vs_network.h>
23131  
23132  #include <trace/events/sock.h>
23133  
23134 @@ -1363,6 +1367,8 @@ static struct sock *sk_prot_alloc(struct
23135                         goto out_free_sec;
23136                 sk_tx_queue_clear(sk);
23137         }
23138 +               sock_vx_init(sk);
23139 +               sock_nx_init(sk);
23140  
23141         return sk;
23142  
23143 @@ -1469,6 +1475,11 @@ void sk_destruct(struct sock *sk)
23144         put_pid(sk->sk_peer_pid);
23145         if (likely(sk->sk_net_refcnt))
23146                 put_net(sock_net(sk));
23147 +       vx_sock_dec(sk);
23148 +       clr_vx_info(&sk->sk_vx_info);
23149 +       sk->sk_xid = -1;
23150 +       clr_nx_info(&sk->sk_nx_info);
23151 +       sk->sk_nid = -1;
23152         sk_prot_free(sk->sk_prot_creator, sk);
23153  }
23154  
23155 @@ -1521,6 +1532,8 @@ struct sock *sk_clone_lock(const struct
23156                 /* SANITY */
23157                 if (likely(newsk->sk_net_refcnt))
23158                         get_net(sock_net(newsk));
23159 +               sock_vx_init(newsk);
23160 +               sock_nx_init(newsk);
23161                 sk_node_init(&newsk->sk_node);
23162                 sock_lock_init(newsk);
23163                 bh_lock_sock(newsk);
23164 @@ -1586,6 +1599,12 @@ struct sock *sk_clone_lock(const struct
23165                 smp_wmb();
23166                 atomic_set(&newsk->sk_refcnt, 2);
23167  
23168 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
23169 +               newsk->sk_xid = sk->sk_xid;
23170 +               vx_sock_inc(newsk);
23171 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
23172 +               newsk->sk_nid = sk->sk_nid;
23173 +
23174                 /*
23175                  * Increment the counter in the same struct proto as the master
23176                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
23177 @@ -2424,6 +2443,12 @@ void sock_init_data(struct socket *sock,
23178  
23179         sk->sk_stamp = ktime_set(-1L, 0);
23180  
23181 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
23182 +       sk->sk_xid = vx_current_xid();
23183 +       vx_sock_inc(sk);
23184 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
23185 +       sk->sk_nid = nx_current_nid();
23186 +
23187  #ifdef CONFIG_NET_RX_BUSY_POLL
23188         sk->sk_napi_id          =       0;
23189         sk->sk_ll_usec          =       sysctl_net_busy_read;
23190 diff -NurpP --minimal linux-4.4.110/net/ipv4/af_inet.c linux-4.4.110-vs2.3.9/net/ipv4/af_inet.c
23191 --- linux-4.4.110/net/ipv4/af_inet.c    2018-01-09 16:35:15.000000000 +0000
23192 +++ linux-4.4.110-vs2.3.9/net/ipv4/af_inet.c    2018-01-09 17:11:11.000000000 +0000
23193 @@ -308,10 +308,15 @@ lookup_protocol:
23194         }
23195  
23196         err = -EPERM;
23197 +       if ((protocol == IPPROTO_ICMP) &&
23198 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
23199 +               goto override;
23200 +
23201         if (sock->type == SOCK_RAW && !kern &&
23202             !ns_capable(net->user_ns, CAP_NET_RAW))
23203                 goto out_rcu_unlock;
23204  
23205 +override:
23206         sock->ops = answer->ops;
23207         answer_prot = answer->prot;
23208         answer_flags = answer->flags;
23209 @@ -425,6 +430,7 @@ int inet_bind(struct socket *sock, struc
23210         struct sock *sk = sock->sk;
23211         struct inet_sock *inet = inet_sk(sk);
23212         struct net *net = sock_net(sk);
23213 +       struct nx_v4_sock_addr nsa;
23214         unsigned short snum;
23215         int chk_addr_ret;
23216         u32 tb_id = RT_TABLE_LOCAL;
23217 @@ -450,7 +456,11 @@ int inet_bind(struct socket *sock, struc
23218         }
23219  
23220         tb_id = l3mdev_fib_table_by_index(net, sk->sk_bound_dev_if) ? : tb_id;
23221 -       chk_addr_ret = inet_addr_type_table(net, addr->sin_addr.s_addr, tb_id);
23222 +       err = v4_map_sock_addr(inet, addr, &nsa);
23223 +       if (err)
23224 +               goto out;
23225 +
23226 +       chk_addr_ret = inet_addr_type_table(net, nsa.saddr, tb_id);
23227  
23228         /* Not specified by any standard per-se, however it breaks too
23229          * many applications when removed.  It is unfortunate since
23230 @@ -462,7 +472,7 @@ int inet_bind(struct socket *sock, struc
23231         err = -EADDRNOTAVAIL;
23232         if (!net->ipv4.sysctl_ip_nonlocal_bind &&
23233             !(inet->freebind || inet->transparent) &&
23234 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
23235 +           nsa.saddr != htonl(INADDR_ANY) &&
23236             chk_addr_ret != RTN_LOCAL &&
23237             chk_addr_ret != RTN_MULTICAST &&
23238             chk_addr_ret != RTN_BROADCAST)
23239 @@ -488,7 +498,7 @@ int inet_bind(struct socket *sock, struc
23240         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
23241                 goto out_release_sock;
23242  
23243 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23244 +       v4_set_sock_addr(inet, &nsa);
23245         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23246                 inet->inet_saddr = 0;  /* Use device */
23247  
23248 @@ -708,11 +718,13 @@ int inet_getname(struct socket *sock, st
23249                      peer == 1))
23250                         return -ENOTCONN;
23251                 sin->sin_port = inet->inet_dport;
23252 -               sin->sin_addr.s_addr = inet->inet_daddr;
23253 +               sin->sin_addr.s_addr =
23254 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
23255         } else {
23256                 __be32 addr = inet->inet_rcv_saddr;
23257                 if (!addr)
23258                         addr = inet->inet_saddr;
23259 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
23260                 sin->sin_port = inet->inet_sport;
23261                 sin->sin_addr.s_addr = addr;
23262         }
23263 @@ -896,6 +908,7 @@ static int inet_compat_ioctl(struct sock
23264         return err;
23265  }
23266  #endif
23267 +#include <linux/vs_limit.h>
23268  
23269  const struct proto_ops inet_stream_ops = {
23270         .family            = PF_INET,
23271 diff -NurpP --minimal linux-4.4.110/net/ipv4/arp.c linux-4.4.110-vs2.3.9/net/ipv4/arp.c
23272 --- linux-4.4.110/net/ipv4/arp.c        2018-01-09 16:35:15.000000000 +0000
23273 +++ linux-4.4.110-vs2.3.9/net/ipv4/arp.c        2018-01-09 16:36:34.000000000 +0000
23274 @@ -1290,6 +1290,7 @@ static void arp_format_neigh_entry(struc
23275         struct net_device *dev = n->dev;
23276         int hatype = dev->type;
23277  
23278 +       /* FIXME: check for network context */
23279         read_lock(&n->lock);
23280         /* Convert hardware address to XX:XX:XX:XX ... form. */
23281  #if IS_ENABLED(CONFIG_AX25)
23282 @@ -1321,6 +1322,7 @@ static void arp_format_pneigh_entry(stru
23283         int hatype = dev ? dev->type : 0;
23284         char tbuf[16];
23285  
23286 +       /* FIXME: check for network context */
23287         sprintf(tbuf, "%pI4", n->key);
23288         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
23289                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
23290 diff -NurpP --minimal linux-4.4.110/net/ipv4/devinet.c linux-4.4.110-vs2.3.9/net/ipv4/devinet.c
23291 --- linux-4.4.110/net/ipv4/devinet.c    2018-01-09 16:35:15.000000000 +0000
23292 +++ linux-4.4.110-vs2.3.9/net/ipv4/devinet.c    2018-01-09 16:36:34.000000000 +0000
23293 @@ -538,6 +538,7 @@ struct in_device *inetdev_by_index(struc
23294  }
23295  EXPORT_SYMBOL(inetdev_by_index);
23296  
23297 +
23298  /* Called only from RTNL semaphored context. No locks. */
23299  
23300  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
23301 @@ -992,6 +993,8 @@ int devinet_ioctl(struct net *net, unsig
23302  
23303         in_dev = __in_dev_get_rtnl(dev);
23304         if (in_dev) {
23305 +               struct nx_info *nxi = current_nx_info();
23306 +
23307                 if (tryaddrmatch) {
23308                         /* Matthias Andree */
23309                         /* compare label and address (4.4BSD style) */
23310 @@ -1000,6 +1003,8 @@ int devinet_ioctl(struct net *net, unsig
23311                            This is checked above. */
23312                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23313                              ifap = &ifa->ifa_next) {
23314 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23315 +                                       continue;
23316                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
23317                                     sin_orig.sin_addr.s_addr ==
23318                                                         ifa->ifa_local) {
23319 @@ -1012,9 +1017,12 @@ int devinet_ioctl(struct net *net, unsig
23320                    comparing just the label */
23321                 if (!ifa) {
23322                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23323 -                            ifap = &ifa->ifa_next)
23324 +                            ifap = &ifa->ifa_next) {
23325 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23326 +                                       continue;
23327                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
23328                                         break;
23329 +                       }
23330                 }
23331         }
23332  
23333 @@ -1168,6 +1176,8 @@ static int inet_gifconf(struct net_devic
23334                 goto out;
23335  
23336         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
23337 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
23338 +                       continue;
23339                 if (!buf) {
23340                         done += sizeof(ifr);
23341                         continue;
23342 @@ -1573,6 +1583,7 @@ static int inet_dump_ifaddr(struct sk_bu
23343         struct net_device *dev;
23344         struct in_device *in_dev;
23345         struct in_ifaddr *ifa;
23346 +       struct sock *sk = skb->sk;
23347         struct hlist_head *head;
23348  
23349         s_h = cb->args[0];
23350 @@ -1596,6 +1607,8 @@ static int inet_dump_ifaddr(struct sk_bu
23351  
23352                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
23353                              ifa = ifa->ifa_next, ip_idx++) {
23354 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
23355 +                               continue;
23356                                 if (ip_idx < s_ip_idx)
23357                                         continue;
23358                                 if (inet_fill_ifaddr(skb, ifa,
23359 diff -NurpP --minimal linux-4.4.110/net/ipv4/fib_trie.c linux-4.4.110-vs2.3.9/net/ipv4/fib_trie.c
23360 --- linux-4.4.110/net/ipv4/fib_trie.c   2018-01-09 16:35:15.000000000 +0000
23361 +++ linux-4.4.110-vs2.3.9/net/ipv4/fib_trie.c   2018-01-09 16:36:34.000000000 +0000
23362 @@ -2591,6 +2591,7 @@ static int fib_route_seq_show(struct seq
23363  
23364                 seq_setwidth(seq, 127);
23365  
23366 +               /* FIXME: check for network context? */
23367                 if (fi)
23368                         seq_printf(seq,
23369                                    "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
23370 diff -NurpP --minimal linux-4.4.110/net/ipv4/inet_connection_sock.c linux-4.4.110-vs2.3.9/net/ipv4/inet_connection_sock.c
23371 --- linux-4.4.110/net/ipv4/inet_connection_sock.c       2018-01-09 16:35:15.000000000 +0000
23372 +++ linux-4.4.110-vs2.3.9/net/ipv4/inet_connection_sock.c       2018-01-09 16:36:34.000000000 +0000
23373 @@ -43,6 +43,37 @@ void inet_get_local_port_range(struct ne
23374  }
23375  EXPORT_SYMBOL(inet_get_local_port_range);
23376  
23377 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23378 +{
23379 +       __be32  sk1_rcv_saddr = sk1->sk_rcv_saddr,
23380 +               sk2_rcv_saddr = sk2->sk_rcv_saddr;
23381 +
23382 +       if (inet_v6_ipv6only(sk2))
23383 +               return 0;
23384 +
23385 +       if (sk1_rcv_saddr &&
23386 +           sk2_rcv_saddr &&
23387 +           sk1_rcv_saddr == sk2_rcv_saddr)
23388 +               return 1;
23389 +
23390 +       if (sk1_rcv_saddr &&
23391 +           !sk2_rcv_saddr &&
23392 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
23393 +               return 1;
23394 +
23395 +       if (sk2_rcv_saddr &&
23396 +           !sk1_rcv_saddr &&
23397 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
23398 +               return 1;
23399 +
23400 +       if (!sk1_rcv_saddr &&
23401 +           !sk2_rcv_saddr &&
23402 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
23403 +               return 1;
23404 +
23405 +       return 0;
23406 +}
23407 +
23408  int inet_csk_bind_conflict(const struct sock *sk,
23409                            const struct inet_bind_bucket *tb, bool relax)
23410  {
23411 @@ -70,15 +101,13 @@ int inet_csk_bind_conflict(const struct
23412                             (sk2->sk_state != TCP_TIME_WAIT &&
23413                              !uid_eq(uid, sock_i_uid(sk2))))) {
23414  
23415 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23416 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23417 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23418                                         break;
23419                         }
23420                         if (!relax && reuse && sk2->sk_reuse &&
23421                             sk2->sk_state != TCP_LISTEN) {
23422  
23423 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23424 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23425 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23426                                         break;
23427                         }
23428                 }
23429 diff -NurpP --minimal linux-4.4.110/net/ipv4/inet_diag.c linux-4.4.110-vs2.3.9/net/ipv4/inet_diag.c
23430 --- linux-4.4.110/net/ipv4/inet_diag.c  2016-07-05 04:15:14.000000000 +0000
23431 +++ linux-4.4.110-vs2.3.9/net/ipv4/inet_diag.c  2018-01-09 16:36:34.000000000 +0000
23432 @@ -31,6 +31,8 @@
23433  
23434  #include <linux/inet.h>
23435  #include <linux/stddef.h>
23436 +#include <linux/vs_network.h>
23437 +#include <linux/vs_inet.h>
23438  
23439  #include <linux/inet_diag.h>
23440  #include <linux/sock_diag.h>
23441 @@ -761,6 +763,8 @@ void inet_diag_dump_icsk(struct inet_has
23442                                 if (!net_eq(sock_net(sk), net))
23443                                         continue;
23444  
23445 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23446 +                                       continue;
23447                                 if (num < s_num) {
23448                                         num++;
23449                                         continue;
23450 @@ -822,6 +826,8 @@ skip_listen_ht:
23451  
23452                         if (!net_eq(sock_net(sk), net))
23453                                 continue;
23454 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23455 +                               continue;
23456                         if (num < s_num)
23457                                 goto next_normal;
23458                         state = (sk->sk_state == TCP_TIME_WAIT) ?
23459 diff -NurpP --minimal linux-4.4.110/net/ipv4/inet_hashtables.c linux-4.4.110-vs2.3.9/net/ipv4/inet_hashtables.c
23460 --- linux-4.4.110/net/ipv4/inet_hashtables.c    2016-07-05 04:15:14.000000000 +0000
23461 +++ linux-4.4.110-vs2.3.9/net/ipv4/inet_hashtables.c    2018-01-09 16:36:34.000000000 +0000
23462 @@ -23,6 +23,7 @@
23463  #include <net/inet_connection_sock.h>
23464  #include <net/inet_hashtables.h>
23465  #include <net/secure_seq.h>
23466 +#include <net/route.h>
23467  #include <net/ip.h>
23468  
23469  static u32 inet_ehashfn(const struct net *net, const __be32 laddr,
23470 @@ -183,6 +184,11 @@ static inline int compute_score(struct s
23471                         if (rcv_saddr != daddr)
23472                                 return -1;
23473                         score += 4;
23474 +               } else {
23475 +                       /* block non nx_info ips */
23476 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
23477 +                               daddr, NXA_MASK_BIND))
23478 +                               return -1;
23479                 }
23480                 if (sk->sk_bound_dev_if) {
23481                         if (sk->sk_bound_dev_if != dif)
23482 @@ -202,7 +208,6 @@ static inline int compute_score(struct s
23483   * wildcarded during the search since they can never be otherwise.
23484   */
23485  
23486 -
23487  struct sock *__inet_lookup_listener(struct net *net,
23488                                     struct inet_hashinfo *hashinfo,
23489                                     const __be32 saddr, __be16 sport,
23490 @@ -238,6 +243,7 @@ begin:
23491                         phash = next_pseudo_random32(phash);
23492                 }
23493         }
23494 +
23495         /*
23496          * if the nulls value we got at the end of this lookup is
23497          * not the expected one, we must restart lookup.
23498 diff -NurpP --minimal linux-4.4.110/net/ipv4/netfilter.c linux-4.4.110-vs2.3.9/net/ipv4/netfilter.c
23499 --- linux-4.4.110/net/ipv4/netfilter.c  2016-07-05 04:15:14.000000000 +0000
23500 +++ linux-4.4.110-vs2.3.9/net/ipv4/netfilter.c  2018-01-09 16:36:34.000000000 +0000
23501 @@ -11,7 +11,7 @@
23502  #include <linux/skbuff.h>
23503  #include <linux/gfp.h>
23504  #include <linux/export.h>
23505 -#include <net/route.h>
23506 +// #include <net/route.h>
23507  #include <net/xfrm.h>
23508  #include <net/ip.h>
23509  #include <net/netfilter/nf_queue.h>
23510 diff -NurpP --minimal linux-4.4.110/net/ipv4/raw.c linux-4.4.110-vs2.3.9/net/ipv4/raw.c
23511 --- linux-4.4.110/net/ipv4/raw.c        2018-01-09 16:35:15.000000000 +0000
23512 +++ linux-4.4.110-vs2.3.9/net/ipv4/raw.c        2018-01-09 17:06:10.000000000 +0000
23513 @@ -126,7 +126,7 @@ static struct sock *__raw_v4_lookup(stru
23514  
23515                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
23516                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
23517 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
23518 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
23519                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23520                         goto found; /* gotcha */
23521         }
23522 @@ -416,6 +416,12 @@ static int raw_send_hdrinc(struct sock *
23523                                 skb_transport_header(skb))->type);
23524         }
23525  
23526 +       err = -EPERM;
23527 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
23528 +               sk->sk_nx_info &&
23529 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
23530 +               goto error_free;
23531 +
23532         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT,
23533                       net, sk, skb, NULL, rt->dst.dev,
23534                       dst_output);
23535 @@ -626,6 +632,16 @@ static int raw_sendmsg(struct sock *sk,
23536                         goto done;
23537         }
23538  
23539 +       if (sk->sk_nx_info) {
23540 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
23541 +               if (IS_ERR(rt)) {
23542 +                       err = PTR_ERR(rt);
23543 +                       rt = NULL;
23544 +                       goto done;
23545 +               }
23546 +               ip_rt_put(rt);
23547 +       }
23548 +
23549         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
23550         rt = ip_route_output_flow(net, &fl4, sk);
23551         if (IS_ERR(rt)) {
23552 @@ -704,17 +720,19 @@ static int raw_bind(struct sock *sk, str
23553  {
23554         struct inet_sock *inet = inet_sk(sk);
23555         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
23556 +       struct nx_v4_sock_addr nsa = { 0 };
23557         int ret = -EINVAL;
23558         int chk_addr_ret;
23559  
23560         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
23561                 goto out;
23562 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
23563 +       v4_map_sock_addr(inet, addr, &nsa);
23564 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
23565         ret = -EADDRNOTAVAIL;
23566 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
23567 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
23568             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
23569                 goto out;
23570 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23571 +       v4_set_sock_addr(inet, &nsa);
23572         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23573                 inet->inet_saddr = 0;  /* Use device */
23574         sk_dst_reset(sk);
23575 @@ -763,7 +781,8 @@ static int raw_recvmsg(struct sock *sk,
23576         /* Copy the address. */
23577         if (sin) {
23578                 sin->sin_family = AF_INET;
23579 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
23580 +               sin->sin_addr.s_addr =
23581 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
23582                 sin->sin_port = 0;
23583                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
23584                 *addr_len = sizeof(*sin);
23585 @@ -959,7 +978,8 @@ static struct sock *raw_get_first(struct
23586         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
23587                         ++state->bucket) {
23588                 sk_for_each(sk, &state->h->ht[state->bucket])
23589 -                       if (sock_net(sk) == seq_file_net(seq))
23590 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
23591 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23592                                 goto found;
23593         }
23594         sk = NULL;
23595 @@ -975,7 +995,8 @@ static struct sock *raw_get_next(struct
23596                 sk = sk_next(sk);
23597  try_again:
23598                 ;
23599 -       } while (sk && sock_net(sk) != seq_file_net(seq));
23600 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
23601 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
23602  
23603         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
23604                 sk = sk_head(&state->h->ht[state->bucket]);
23605 diff -NurpP --minimal linux-4.4.110/net/ipv4/route.c linux-4.4.110-vs2.3.9/net/ipv4/route.c
23606 --- linux-4.4.110/net/ipv4/route.c      2018-01-09 16:35:15.000000000 +0000
23607 +++ linux-4.4.110-vs2.3.9/net/ipv4/route.c      2018-01-09 16:36:34.000000000 +0000
23608 @@ -2226,7 +2226,7 @@ struct rtable *__ip_route_output_key_has
23609  
23610  
23611         if (fl4->flowi4_oif) {
23612 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
23613 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
23614                 rth = ERR_PTR(-ENODEV);
23615                 if (!dev_out)
23616                         goto out;
23617 diff -NurpP --minimal linux-4.4.110/net/ipv4/tcp.c linux-4.4.110-vs2.3.9/net/ipv4/tcp.c
23618 --- linux-4.4.110/net/ipv4/tcp.c        2018-01-09 16:35:15.000000000 +0000
23619 +++ linux-4.4.110-vs2.3.9/net/ipv4/tcp.c        2018-01-09 16:36:34.000000000 +0000
23620 @@ -269,6 +269,7 @@
23621  #include <linux/crypto.h>
23622  #include <linux/time.h>
23623  #include <linux/slab.h>
23624 +#include <linux/in.h>
23625  
23626  #include <net/icmp.h>
23627  #include <net/inet_common.h>
23628 diff -NurpP --minimal linux-4.4.110/net/ipv4/tcp_ipv4.c linux-4.4.110-vs2.3.9/net/ipv4/tcp_ipv4.c
23629 --- linux-4.4.110/net/ipv4/tcp_ipv4.c   2018-01-09 16:35:15.000000000 +0000
23630 +++ linux-4.4.110-vs2.3.9/net/ipv4/tcp_ipv4.c   2018-01-09 17:13:45.000000000 +0000
23631 @@ -1885,6 +1885,10 @@ static void *listening_get_next(struct s
23632         sk = sk_nulls_next(sk);
23633  get_sk:
23634         sk_nulls_for_each_from(sk, node) {
23635 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
23636 +                       sk, sk->sk_nid, nx_current_nid());
23637 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23638 +                       continue;
23639                 if (!net_eq(sock_net(sk), net))
23640                         continue;
23641                 if (sk->sk_family == st->family) {
23642 @@ -1949,6 +1953,11 @@ static void *established_get_first(struc
23643  
23644                 spin_lock_bh(lock);
23645                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
23646 +                       vxdprintk(VXD_CBIT(net, 6),
23647 +                               "sk,egf: %p [#%d] (from %d)",
23648 +                               sk, sk->sk_nid, nx_current_nid());
23649 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23650 +                               continue;
23651                         if (sk->sk_family != st->family ||
23652                             !net_eq(sock_net(sk), net)) {
23653                                 continue;
23654 @@ -1975,6 +1984,11 @@ static void *established_get_next(struct
23655         sk = sk_nulls_next(sk);
23656  
23657         sk_nulls_for_each_from(sk, node) {
23658 +               vxdprintk(VXD_CBIT(net, 6),
23659 +                       "sk,egn: %p [#%d] (from %d)",
23660 +                       sk, sk->sk_nid, nx_current_nid());
23661 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23662 +                       continue;
23663                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
23664                         return sk;
23665         }
23666 @@ -2166,9 +2180,9 @@ static void get_openreq4(const struct re
23667         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
23668                 " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK",
23669                 i,
23670 -               ireq->ir_loc_addr,
23671 +               nx_map_sock_lback(current_nx_info(), ireq->ir_loc_addr),
23672                 ireq->ir_num,
23673 -               ireq->ir_rmt_addr,
23674 +               nx_map_sock_lback(current_nx_info(), ireq->ir_rmt_addr),
23675                 ntohs(ireq->ir_rmt_port),
23676                 TCP_SYN_RECV,
23677                 0, 0, /* could print option size, but that is af dependent. */
23678 @@ -2191,8 +2205,8 @@ static void get_tcp4_sock(struct sock *s
23679         const struct inet_connection_sock *icsk = inet_csk(sk);
23680         const struct inet_sock *inet = inet_sk(sk);
23681         const struct fastopen_queue *fastopenq = &icsk->icsk_accept_queue.fastopenq;
23682 -       __be32 dest = inet->inet_daddr;
23683 -       __be32 src = inet->inet_rcv_saddr;
23684 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
23685 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
23686         __u16 destp = ntohs(inet->inet_dport);
23687         __u16 srcp = ntohs(inet->inet_sport);
23688         int rx_queue;
23689 @@ -2251,8 +2265,8 @@ static void get_timewait4_sock(const str
23690         __be32 dest, src;
23691         __u16 destp, srcp;
23692  
23693 -       dest  = tw->tw_daddr;
23694 -       src   = tw->tw_rcv_saddr;
23695 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
23696 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
23697         destp = ntohs(tw->tw_dport);
23698         srcp  = ntohs(tw->tw_sport);
23699  
23700 diff -NurpP --minimal linux-4.4.110/net/ipv4/tcp_minisocks.c linux-4.4.110-vs2.3.9/net/ipv4/tcp_minisocks.c
23701 --- linux-4.4.110/net/ipv4/tcp_minisocks.c      2018-01-09 16:35:15.000000000 +0000
23702 +++ linux-4.4.110-vs2.3.9/net/ipv4/tcp_minisocks.c      2018-01-09 16:36:34.000000000 +0000
23703 @@ -23,6 +23,9 @@
23704  #include <linux/slab.h>
23705  #include <linux/sysctl.h>
23706  #include <linux/workqueue.h>
23707 +#include <linux/vs_limit.h>
23708 +#include <linux/vs_socket.h>
23709 +#include <linux/vs_context.h>
23710  #include <net/tcp.h>
23711  #include <net/inet_common.h>
23712  #include <net/xfrm.h>
23713 @@ -291,6 +294,11 @@ void tcp_time_wait(struct sock *sk, int
23714                 tcptw->tw_ts_offset     = tp->tsoffset;
23715                 tcptw->tw_last_oow_ack_time = 0;
23716  
23717 +               tw->tw_xid              = sk->sk_xid;
23718 +               tw->tw_vx_info          = NULL;
23719 +               tw->tw_nid              = sk->sk_nid;
23720 +               tw->tw_nx_info          = NULL;
23721 +
23722  #if IS_ENABLED(CONFIG_IPV6)
23723                 if (tw->tw_family == PF_INET6) {
23724                         struct ipv6_pinfo *np = inet6_sk(sk);
23725 diff -NurpP --minimal linux-4.4.110/net/ipv4/udp.c linux-4.4.110-vs2.3.9/net/ipv4/udp.c
23726 --- linux-4.4.110/net/ipv4/udp.c        2018-01-09 16:35:15.000000000 +0000
23727 +++ linux-4.4.110-vs2.3.9/net/ipv4/udp.c        2018-01-09 16:36:34.000000000 +0000
23728 @@ -309,14 +309,7 @@ fail:
23729  }
23730  EXPORT_SYMBOL(udp_lib_get_port);
23731  
23732 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23733 -{
23734 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
23735 -
23736 -       return  (!ipv6_only_sock(sk2)  &&
23737 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
23738 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
23739 -}
23740 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
23741  
23742  static u32 udp4_portaddr_hash(const struct net *net, __be32 saddr,
23743                               unsigned int port)
23744 @@ -355,6 +348,11 @@ static inline int compute_score(struct s
23745                 if (inet->inet_rcv_saddr != daddr)
23746                         return -1;
23747                 score += 4;
23748 +               } else {
23749 +                       /* block non nx_info ips */
23750 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
23751 +                               daddr, NXA_MASK_BIND))
23752 +                               return -1;
23753         }
23754  
23755         if (inet->inet_daddr) {
23756 @@ -489,6 +487,7 @@ begin:
23757         return result;
23758  }
23759  
23760 +
23761  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
23762   * harder than this. -DaveM
23763   */
23764 @@ -535,6 +534,11 @@ begin:
23765         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
23766                 score = compute_score(sk, net, saddr, hnum, sport,
23767                                       daddr, dport, dif);
23768 +               /* FIXME: disabled?
23769 +               if (score == 9) {
23770 +                       result = sk;
23771 +                       break;
23772 +               } else */
23773                 if (score > badness) {
23774                         result = sk;
23775                         badness = score;
23776 @@ -559,6 +563,7 @@ begin:
23777         if (get_nulls_value(node) != slot)
23778                 goto begin;
23779  
23780 +
23781         if (result) {
23782                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
23783                         result = NULL;
23784 @@ -568,6 +573,7 @@ begin:
23785                         goto begin;
23786                 }
23787         }
23788 +
23789         rcu_read_unlock();
23790         return result;
23791  }
23792 @@ -602,7 +608,7 @@ static inline bool __udp_is_mcast_sock(s
23793             udp_sk(sk)->udp_port_hash != hnum ||
23794             (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
23795             (inet->inet_dport != rmt_port && inet->inet_dport) ||
23796 -           (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
23797 +           !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
23798             ipv6_only_sock(sk) ||
23799             (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23800                 return false;
23801 @@ -1033,6 +1039,16 @@ int udp_sendmsg(struct sock *sk, struct
23802                                 goto out;
23803                 }
23804  
23805 +               if (sk->sk_nx_info) {
23806 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
23807 +                       if (IS_ERR(rt)) {
23808 +                               err = PTR_ERR(rt);
23809 +                               rt = NULL;
23810 +                               goto out;
23811 +                       }
23812 +                       ip_rt_put(rt);
23813 +               }
23814 +
23815                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
23816                 rt = ip_route_output_flow(net, fl4, sk);
23817                 if (IS_ERR(rt)) {
23818 @@ -1337,7 +1353,8 @@ try_again:
23819         if (sin) {
23820                 sin->sin_family = AF_INET;
23821                 sin->sin_port = udp_hdr(skb)->source;
23822 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
23823 +               sin->sin_addr.s_addr = nx_map_sock_lback(
23824 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
23825                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
23826                 *addr_len = sizeof(*sin);
23827         }
23828 @@ -2319,6 +2336,8 @@ static struct sock *udp_get_first(struct
23829                 sk_nulls_for_each(sk, node, &hslot->head) {
23830                         if (!net_eq(sock_net(sk), net))
23831                                 continue;
23832 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23833 +                               continue;
23834                         if (sk->sk_family == state->family)
23835                                 goto found;
23836                 }
23837 @@ -2336,7 +2355,9 @@ static struct sock *udp_get_next(struct
23838  
23839         do {
23840                 sk = sk_nulls_next(sk);
23841 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
23842 +       } while (sk && (!net_eq(sock_net(sk), net) ||
23843 +               sk->sk_family != state->family ||
23844 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
23845  
23846         if (!sk) {
23847                 if (state->bucket <= state->udp_table->mask)
23848 @@ -2432,8 +2453,8 @@ static void udp4_format_sock(struct sock
23849                 int bucket)
23850  {
23851         struct inet_sock *inet = inet_sk(sp);
23852 -       __be32 dest = inet->inet_daddr;
23853 -       __be32 src  = inet->inet_rcv_saddr;
23854 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
23855 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
23856         __u16 destp       = ntohs(inet->inet_dport);
23857         __u16 srcp        = ntohs(inet->inet_sport);
23858  
23859 diff -NurpP --minimal linux-4.4.110/net/ipv6/addrconf.c linux-4.4.110-vs2.3.9/net/ipv6/addrconf.c
23860 --- linux-4.4.110/net/ipv6/addrconf.c   2018-01-09 16:35:15.000000000 +0000
23861 +++ linux-4.4.110-vs2.3.9/net/ipv6/addrconf.c   2018-01-09 23:41:55.000000000 +0000
23862 @@ -92,6 +92,8 @@
23863  #include <linux/proc_fs.h>
23864  #include <linux/seq_file.h>
23865  #include <linux/export.h>
23866 +#include <linux/vs_network.h>
23867 +#include <linux/vs_inet6.h>
23868  
23869  /* Set to 3 to get tracing... */
23870  #define ACONF_DEBUG 2
23871 @@ -1442,7 +1444,8 @@ static int __ipv6_dev_get_saddr(struct n
23872                                 struct ipv6_saddr_dst *dst,
23873                                 struct inet6_dev *idev,
23874                                 struct ipv6_saddr_score *scores,
23875 -                               int hiscore_idx)
23876 +                               int hiscore_idx,
23877 +                               struct nx_info *nxi)
23878  {
23879         struct ipv6_saddr_score *score = &scores[1 - hiscore_idx], *hiscore = &scores[hiscore_idx];
23880  
23881 @@ -1472,6 +1475,8 @@ static int __ipv6_dev_get_saddr(struct n
23882                                             idev->dev->name);
23883                         continue;
23884                 }
23885 +               if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
23886 +                       continue;
23887  
23888                 score->rule = -1;
23889                 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
23890 @@ -1519,7 +1524,7 @@ out:
23891  
23892  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
23893                        const struct in6_addr *daddr, unsigned int prefs,
23894 -                      struct in6_addr *saddr)
23895 +                      struct in6_addr *saddr, struct nx_info *nxi)
23896  {
23897         struct ipv6_saddr_score scores[2], *hiscore;
23898         struct ipv6_saddr_dst dst;
23899 @@ -1568,13 +1573,15 @@ int ipv6_dev_get_saddr(struct net *net,
23900  
23901         if (use_oif_addr) {
23902                 if (idev)
23903 -                       hiscore_idx = __ipv6_dev_get_saddr(net, &dst, idev, scores, hiscore_idx);
23904 +                       hiscore_idx = __ipv6_dev_get_saddr(net, &dst,
23905 +                               idev, scores, hiscore_idx, nxi);
23906         } else {
23907                 for_each_netdev_rcu(net, dev) {
23908                         idev = __in6_dev_get(dev);
23909                         if (!idev)
23910                                 continue;
23911 -                       hiscore_idx = __ipv6_dev_get_saddr(net, &dst, idev, scores, hiscore_idx);
23912 +                       hiscore_idx = __ipv6_dev_get_saddr(net, &dst,
23913 +                               idev, scores, hiscore_idx, nxi);
23914                 }
23915         }
23916         rcu_read_unlock();
23917 @@ -3846,7 +3853,10 @@ static void if6_seq_stop(struct seq_file
23918  static int if6_seq_show(struct seq_file *seq, void *v)
23919  {
23920         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
23921 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
23922 +
23923 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
23924 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
23925 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
23926                    &ifp->addr,
23927                    ifp->idev->dev->ifindex,
23928                    ifp->prefix_len,
23929 @@ -4430,6 +4440,11 @@ static int in6_dump_addrs(struct inet6_d
23930         struct ifacaddr6 *ifaca;
23931         int err = 1;
23932         int ip_idx = *p_ip_idx;
23933 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
23934 +
23935 +       /* disable ipv6 on non v6 guests */
23936 +       if (nxi && !nx_info_has_v6(nxi))
23937 +               return skb->len;
23938  
23939         read_lock_bh(&idev->lock);
23940         switch (type) {
23941 @@ -4440,6 +4455,8 @@ static int in6_dump_addrs(struct inet6_d
23942                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
23943                         if (++ip_idx < s_ip_idx)
23944                                 continue;
23945 +                       if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
23946 +                               continue;
23947                         err = inet6_fill_ifaddr(skb, ifa,
23948                                                 NETLINK_CB(cb->skb).portid,
23949                                                 cb->nlh->nlmsg_seq,
23950 @@ -4457,6 +4474,8 @@ static int in6_dump_addrs(struct inet6_d
23951                      ifmca = ifmca->next, ip_idx++) {
23952                         if (ip_idx < s_ip_idx)
23953                                 continue;
23954 +                       if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
23955 +                               continue;
23956                         err = inet6_fill_ifmcaddr(skb, ifmca,
23957                                                   NETLINK_CB(cb->skb).portid,
23958                                                   cb->nlh->nlmsg_seq,
23959 @@ -4472,6 +4491,8 @@ static int in6_dump_addrs(struct inet6_d
23960                      ifaca = ifaca->aca_next, ip_idx++) {
23961                         if (ip_idx < s_ip_idx)
23962                                 continue;
23963 +                       if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
23964 +                               continue;
23965                         err = inet6_fill_ifacaddr(skb, ifaca,
23966                                                   NETLINK_CB(cb->skb).portid,
23967                                                   cb->nlh->nlmsg_seq,
23968 @@ -4500,6 +4521,10 @@ static int inet6_dump_addr(struct sk_buf
23969         struct inet6_dev *idev;
23970         struct hlist_head *head;
23971  
23972 +       /* FIXME: maybe disable ipv6 on non v6 guests?
23973 +       if (skb->sk && skb->sk->sk_vx_info)
23974 +               return skb->len; */
23975 +
23976         s_h = cb->args[0];
23977         s_idx = idx = cb->args[1];
23978         s_ip_idx = ip_idx = cb->args[2];
23979 @@ -5008,6 +5033,7 @@ static int inet6_dump_ifinfo(struct sk_b
23980         struct net_device *dev;
23981         struct inet6_dev *idev;
23982         struct hlist_head *head;
23983 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
23984  
23985         s_h = cb->args[0];
23986         s_idx = cb->args[1];
23987 @@ -5019,6 +5045,8 @@ static int inet6_dump_ifinfo(struct sk_b
23988                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
23989                         if (idx < s_idx)
23990                                 goto cont;
23991 +                       if (!v6_dev_in_nx_info(dev, nxi))
23992 +                               goto cont;
23993                         idev = __in6_dev_get(dev);
23994                         if (!idev)
23995                                 goto cont;
23996 diff -NurpP --minimal linux-4.4.110/net/ipv6/af_inet6.c linux-4.4.110-vs2.3.9/net/ipv6/af_inet6.c
23997 --- linux-4.4.110/net/ipv6/af_inet6.c   2018-01-09 16:35:15.000000000 +0000
23998 +++ linux-4.4.110-vs2.3.9/net/ipv6/af_inet6.c   2018-01-09 16:36:34.000000000 +0000
23999 @@ -43,6 +43,8 @@
24000  #include <linux/netdevice.h>
24001  #include <linux/icmpv6.h>
24002  #include <linux/netfilter_ipv6.h>
24003 +#include <linux/vs_inet.h>
24004 +#include <linux/vs_inet6.h>
24005  
24006  #include <net/ip.h>
24007  #include <net/ipv6.h>
24008 @@ -158,10 +160,13 @@ lookup_protocol:
24009         }
24010  
24011         err = -EPERM;
24012 +       if ((protocol == IPPROTO_ICMPV6) &&
24013 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24014 +               goto override;
24015         if (sock->type == SOCK_RAW && !kern &&
24016             !ns_capable(net->user_ns, CAP_NET_RAW))
24017                 goto out_rcu_unlock;
24018 -
24019 +override:
24020         sock->ops = answer->ops;
24021         answer_prot = answer->prot;
24022         answer_flags = answer->flags;
24023 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
24024         struct inet_sock *inet = inet_sk(sk);
24025         struct ipv6_pinfo *np = inet6_sk(sk);
24026         struct net *net = sock_net(sk);
24027 +       struct nx_v6_sock_addr nsa;
24028         __be32 v4addr = 0;
24029         unsigned short snum;
24030         int addr_type = 0;
24031 @@ -274,6 +280,10 @@ int inet6_bind(struct socket *sock, stru
24032         if (addr->sin6_family != AF_INET6)
24033                 return -EAFNOSUPPORT;
24034  
24035 +       err = v6_map_sock_addr(inet, addr, &nsa);
24036 +       if (err)
24037 +               return err;
24038 +
24039         addr_type = ipv6_addr_type(&addr->sin6_addr);
24040         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
24041                 return -EINVAL;
24042 @@ -314,6 +324,10 @@ int inet6_bind(struct socket *sock, stru
24043                         err = -EADDRNOTAVAIL;
24044                         goto out;
24045                 }
24046 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
24047 +                       err = -EADDRNOTAVAIL;
24048 +                       goto out;
24049 +               }
24050         } else {
24051                 if (addr_type != IPV6_ADDR_ANY) {
24052                         struct net_device *dev = NULL;
24053 @@ -340,6 +354,11 @@ int inet6_bind(struct socket *sock, stru
24054                                 }
24055                         }
24056  
24057 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24058 +                               err = -EADDRNOTAVAIL;
24059 +                               goto out_unlock;
24060 +                       }
24061 +
24062                         /* ipv4 addr of the socket is invalid.  Only the
24063                          * unspecified and mapped address have a v4 equivalent.
24064                          */
24065 @@ -357,6 +376,9 @@ int inet6_bind(struct socket *sock, stru
24066                 }
24067         }
24068  
24069 +       /* what's that for? */
24070 +       v6_set_sock_addr(inet, &nsa);
24071 +
24072         inet->inet_rcv_saddr = v4addr;
24073         inet->inet_saddr = v4addr;
24074  
24075 @@ -461,9 +483,11 @@ int inet6_getname(struct socket *sock, s
24076                         return -ENOTCONN;
24077                 sin->sin6_port = inet->inet_dport;
24078                 sin->sin6_addr = sk->sk_v6_daddr;
24079 +               /* FIXME: remap lback? */
24080                 if (np->sndflow)
24081                         sin->sin6_flowinfo = np->flow_label;
24082         } else {
24083 +               /* FIXME: remap lback? */
24084                 if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
24085                         sin->sin6_addr = np->saddr;
24086                 else
24087 diff -NurpP --minimal linux-4.4.110/net/ipv6/datagram.c linux-4.4.110-vs2.3.9/net/ipv6/datagram.c
24088 --- linux-4.4.110/net/ipv6/datagram.c   2018-01-09 16:35:15.000000000 +0000
24089 +++ linux-4.4.110-vs2.3.9/net/ipv6/datagram.c   2018-01-09 16:36:34.000000000 +0000
24090 @@ -733,7 +733,7 @@ int ip6_datagram_send_ctl(struct net *ne
24091  
24092                         rcu_read_lock();
24093                         if (fl6->flowi6_oif) {
24094 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
24095 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
24096                                 if (!dev) {
24097                                         rcu_read_unlock();
24098                                         return -ENODEV;
24099 diff -NurpP --minimal linux-4.4.110/net/ipv6/fib6_rules.c linux-4.4.110-vs2.3.9/net/ipv6/fib6_rules.c
24100 --- linux-4.4.110/net/ipv6/fib6_rules.c 2018-01-09 16:35:15.000000000 +0000
24101 +++ linux-4.4.110-vs2.3.9/net/ipv6/fib6_rules.c 2018-01-09 16:36:34.000000000 +0000
24102 @@ -97,7 +97,7 @@ static int fib6_rule_action(struct fib_r
24103                                                ip6_dst_idev(&rt->dst)->dev,
24104                                                &flp6->daddr,
24105                                                rt6_flags2srcprefs(flags),
24106 -                                              &saddr))
24107 +                                              &saddr, NULL))
24108                                 goto again;
24109                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
24110                                                r->src.plen))
24111 diff -NurpP --minimal linux-4.4.110/net/ipv6/inet6_hashtables.c linux-4.4.110-vs2.3.9/net/ipv6/inet6_hashtables.c
24112 --- linux-4.4.110/net/ipv6/inet6_hashtables.c   2016-07-05 04:15:14.000000000 +0000
24113 +++ linux-4.4.110-vs2.3.9/net/ipv6/inet6_hashtables.c   2018-01-09 16:36:34.000000000 +0000
24114 @@ -16,6 +16,7 @@
24115  
24116  #include <linux/module.h>
24117  #include <linux/random.h>
24118 +#include <linux/vs_inet6.h>
24119  
24120  #include <net/inet_connection_sock.h>
24121  #include <net/inet_hashtables.h>
24122 @@ -66,7 +67,6 @@ struct sock *__inet6_lookup_established(
24123         unsigned int slot = hash & hashinfo->ehash_mask;
24124         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
24125  
24126 -
24127         rcu_read_lock();
24128  begin:
24129         sk_nulls_for_each_rcu(sk, node, &head->chain) {
24130 @@ -108,6 +108,9 @@ static inline int compute_score(struct s
24131                         if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24132                                 return -1;
24133                         score++;
24134 +               } else {
24135 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24136 +                               return -1;
24137                 }
24138                 if (sk->sk_bound_dev_if) {
24139                         if (sk->sk_bound_dev_if != dif)
24140 diff -NurpP --minimal linux-4.4.110/net/ipv6/ip6_fib.c linux-4.4.110-vs2.3.9/net/ipv6/ip6_fib.c
24141 --- linux-4.4.110/net/ipv6/ip6_fib.c    2018-01-09 16:35:15.000000000 +0000
24142 +++ linux-4.4.110-vs2.3.9/net/ipv6/ip6_fib.c    2018-01-09 16:36:34.000000000 +0000
24143 @@ -1968,6 +1968,7 @@ static int ipv6_route_seq_show(struct se
24144         struct rt6_info *rt = v;
24145         struct ipv6_route_iter *iter = seq->private;
24146  
24147 +       /* FIXME: check for network context? */
24148         seq_printf(seq, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
24149  
24150  #ifdef CONFIG_IPV6_SUBTREES
24151 diff -NurpP --minimal linux-4.4.110/net/ipv6/ip6_output.c linux-4.4.110-vs2.3.9/net/ipv6/ip6_output.c
24152 --- linux-4.4.110/net/ipv6/ip6_output.c 2018-01-09 16:35:15.000000000 +0000
24153 +++ linux-4.4.110-vs2.3.9/net/ipv6/ip6_output.c 2018-01-09 16:36:34.000000000 +0000
24154 @@ -941,7 +941,8 @@ static int ip6_dst_lookup_tail(struct ne
24155                 rt = (*dst)->error ? NULL : (struct rt6_info *)*dst;
24156                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
24157                                           sk ? inet6_sk(sk)->srcprefs : 0,
24158 -                                         &fl6->saddr);
24159 +                                         &fl6->saddr,
24160 +                                         sk ? sk->sk_nx_info : NULL);
24161                 if (err)
24162                         goto out_err_release;
24163  
24164 diff -NurpP --minimal linux-4.4.110/net/ipv6/ndisc.c linux-4.4.110-vs2.3.9/net/ipv6/ndisc.c
24165 --- linux-4.4.110/net/ipv6/ndisc.c      2016-07-05 04:15:14.000000000 +0000
24166 +++ linux-4.4.110-vs2.3.9/net/ipv6/ndisc.c      2018-01-09 16:36:34.000000000 +0000
24167 @@ -501,7 +501,7 @@ void ndisc_send_na(struct net_device *de
24168         } else {
24169                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
24170                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
24171 -                                      &tmpaddr))
24172 +                                      &tmpaddr, NULL))
24173                         return;
24174                 src_addr = &tmpaddr;
24175         }
24176 diff -NurpP --minimal linux-4.4.110/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c linux-4.4.110-vs2.3.9/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c
24177 --- linux-4.4.110/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c   2016-07-05 04:15:14.000000000 +0000
24178 +++ linux-4.4.110-vs2.3.9/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c   2018-01-09 17:04:44.000000000 +0000
24179 @@ -35,7 +35,7 @@ nf_nat_masquerade_ipv6(struct sk_buff *s
24180                             ctinfo == IP_CT_RELATED_REPLY));
24181  
24182         if (ipv6_dev_get_saddr(nf_ct_net(ct), out,
24183 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
24184 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
24185                 return NF_DROP;
24186  
24187         nfct_nat(ct)->masq_index = out->ifindex;
24188 diff -NurpP --minimal linux-4.4.110/net/ipv6/raw.c linux-4.4.110-vs2.3.9/net/ipv6/raw.c
24189 --- linux-4.4.110/net/ipv6/raw.c        2018-01-09 16:35:16.000000000 +0000
24190 +++ linux-4.4.110-vs2.3.9/net/ipv6/raw.c        2018-01-09 16:36:34.000000000 +0000
24191 @@ -30,6 +30,7 @@
24192  #include <linux/icmpv6.h>
24193  #include <linux/netfilter.h>
24194  #include <linux/netfilter_ipv6.h>
24195 +#include <linux/vs_inet6.h>
24196  #include <linux/skbuff.h>
24197  #include <linux/compat.h>
24198  #include <linux/uaccess.h>
24199 @@ -291,6 +292,13 @@ static int rawv6_bind(struct sock *sk, s
24200                                 goto out_unlock;
24201                 }
24202  
24203 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24204 +                       err = -EADDRNOTAVAIL;
24205 +                       if (dev)
24206 +                               dev_put(dev);
24207 +                       goto out;
24208 +               }
24209 +
24210                 /* ipv4 addr of the socket is invalid.  Only the
24211                  * unspecified and mapped address have a v4 equivalent.
24212                  */
24213 diff -NurpP --minimal linux-4.4.110/net/ipv6/route.c linux-4.4.110-vs2.3.9/net/ipv6/route.c
24214 --- linux-4.4.110/net/ipv6/route.c      2018-01-09 16:35:16.000000000 +0000
24215 +++ linux-4.4.110-vs2.3.9/net/ipv6/route.c      2018-01-09 17:03:24.000000000 +0000
24216 @@ -62,6 +62,7 @@
24217  #include <net/lwtunnel.h>
24218  #include <net/ip_tunnels.h>
24219  #include <net/l3mdev.h>
24220 +#include <linux/vs_inet6.h>
24221  
24222  #include <asm/uaccess.h>
24223  
24224 @@ -2545,16 +2546,18 @@ int ip6_route_get_saddr(struct net *net,
24225                         struct rt6_info *rt,
24226                         const struct in6_addr *daddr,
24227                         unsigned int prefs,
24228 -                       struct in6_addr *saddr)
24229 +                       struct in6_addr *saddr,
24230 +                       struct nx_info *nxi)
24231  {
24232         struct inet6_dev *idev =
24233                 rt ? ip6_dst_idev((struct dst_entry *)rt) : NULL;
24234         int err = 0;
24235 -       if (rt && rt->rt6i_prefsrc.plen)
24236 +       if (rt && rt->rt6i_prefsrc.plen && (!nxi ||
24237 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
24238                 *saddr = rt->rt6i_prefsrc.addr;
24239         else
24240                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
24241 -                                        daddr, prefs, saddr);
24242 +                                        daddr, prefs, saddr, nxi);
24243         return err;
24244  }
24245  
24246 @@ -3168,7 +3171,8 @@ static int rt6_fill_node(struct net *net
24247                                 goto nla_put_failure;
24248         } else if (dst) {
24249                 struct in6_addr saddr_buf;
24250 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
24251 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
24252 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
24253                     nla_put_in6_addr(skb, RTA_PREFSRC, &saddr_buf))
24254                         goto nla_put_failure;
24255         }
24256 diff -NurpP --minimal linux-4.4.110/net/ipv6/tcp_ipv6.c linux-4.4.110-vs2.3.9/net/ipv6/tcp_ipv6.c
24257 --- linux-4.4.110/net/ipv6/tcp_ipv6.c   2018-01-09 16:35:16.000000000 +0000
24258 +++ linux-4.4.110-vs2.3.9/net/ipv6/tcp_ipv6.c   2018-01-09 16:36:34.000000000 +0000
24259 @@ -69,6 +69,7 @@
24260  
24261  #include <linux/crypto.h>
24262  #include <linux/scatterlist.h>
24263 +#include <linux/vs_inet6.h>
24264  
24265  static void    tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb);
24266  static void    tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,
24267 @@ -150,11 +151,18 @@ static int tcp_v6_connect(struct sock *s
24268          */
24269  
24270         if (ipv6_addr_any(&usin->sin6_addr)) {
24271 -               if (ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
24272 -                       ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK),
24273 -                                              &usin->sin6_addr);
24274 -               else
24275 -                       usin->sin6_addr = in6addr_loopback;
24276 +               struct nx_info *nxi =  sk->sk_nx_info;
24277 +
24278 +               if (nxi && nx_info_has_v6(nxi))
24279 +                       /* FIXME: remap lback? */
24280 +                       usin->sin6_addr = nxi->v6.ip;
24281 +               else {
24282 +                       if (ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
24283 +                               ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK),
24284 +                                                      &usin->sin6_addr);
24285 +                       else
24286 +                               usin->sin6_addr = in6addr_loopback;
24287 +               }
24288         }
24289  
24290         addr_type = ipv6_addr_type(&usin->sin6_addr);
24291 diff -NurpP --minimal linux-4.4.110/net/ipv6/udp.c linux-4.4.110-vs2.3.9/net/ipv6/udp.c
24292 --- linux-4.4.110/net/ipv6/udp.c        2018-01-09 16:35:16.000000000 +0000
24293 +++ linux-4.4.110-vs2.3.9/net/ipv6/udp.c        2018-01-09 16:36:34.000000000 +0000
24294 @@ -47,6 +47,7 @@
24295  #include <net/xfrm.h>
24296  #include <net/inet6_hashtables.h>
24297  #include <net/busy_poll.h>
24298 +#include <linux/vs_inet6.h>
24299  
24300  #include <linux/proc_fs.h>
24301  #include <linux/seq_file.h>
24302 @@ -76,32 +77,60 @@ static u32 udp6_ehashfn(const struct net
24303                                udp_ipv6_hash_secret + net_hash_mix(net));
24304  }
24305  
24306 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
24307 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24308  {
24309 +       const struct in6_addr *sk1_rcv_saddr6 = inet6_rcv_saddr(sk1);
24310         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
24311 +       __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr;
24312 +       __be32 sk2_rcv_saddr = sk2->sk_rcv_saddr;
24313         int sk2_ipv6only = inet_v6_ipv6only(sk2);
24314 -       int addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
24315 +       int addr_type1 = ipv6_addr_type(sk1_rcv_saddr6);
24316         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
24317  
24318         /* if both are mapped, treat as IPv4 */
24319 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
24320 -               return (!sk2_ipv6only &&
24321 -                       (!sk->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24322 -                         sk->sk_rcv_saddr == sk2->sk_rcv_saddr));
24323 +       if (addr_type1 == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
24324 +               if (!sk2_ipv6only &&
24325 +                       (!sk1->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24326 +                         sk1->sk_rcv_saddr == sk2->sk_rcv_saddr))
24327 +                       goto vs_v4;
24328 +               else
24329 +                       return 0;
24330 +       }
24331  
24332         if (addr_type2 == IPV6_ADDR_ANY &&
24333 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
24334 -               return 1;
24335 +           !(sk2_ipv6only && addr_type1 == IPV6_ADDR_MAPPED))
24336 +               goto vs;
24337  
24338 -       if (addr_type == IPV6_ADDR_ANY &&
24339 -           !(ipv6_only_sock(sk) && addr_type2 == IPV6_ADDR_MAPPED))
24340 -               return 1;
24341 +       if (addr_type1 == IPV6_ADDR_ANY &&
24342 +           !(ipv6_only_sock(sk1) && addr_type2 == IPV6_ADDR_MAPPED))
24343 +               goto vs;
24344  
24345         if (sk2_rcv_saddr6 &&
24346 -           ipv6_addr_equal(&sk->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24347 -               return 1;
24348 +           ipv6_addr_equal(&sk1->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24349 +               goto vs;
24350  
24351         return 0;
24352 +
24353 +vs_v4:
24354 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
24355 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24356 +       if (!sk2_rcv_saddr)
24357 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
24358 +       if (!sk1_rcv_saddr)
24359 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
24360 +       return 1;
24361 +vs:
24362 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type1 == IPV6_ADDR_ANY)
24363 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24364 +       else if (addr_type2 == IPV6_ADDR_ANY)
24365 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
24366 +       else if (addr_type1 == IPV6_ADDR_ANY) {
24367 +               if (addr_type2 == IPV6_ADDR_MAPPED)
24368 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24369 +               else
24370 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
24371 +       }
24372 +       return 1;
24373  }
24374  
24375  static u32 udp6_portaddr_hash(const struct net *net,
24376 @@ -162,6 +191,10 @@ static inline int compute_score(struct s
24377                 if (inet->inet_dport != sport)
24378                         return -1;
24379                 score++;
24380 +               } else {
24381 +                       /* block non nx_info ips */
24382 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24383 +                               return -1;
24384         }
24385  
24386         if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
24387 diff -NurpP --minimal linux-4.4.110/net/ipv6/xfrm6_policy.c linux-4.4.110-vs2.3.9/net/ipv6/xfrm6_policy.c
24388 --- linux-4.4.110/net/ipv6/xfrm6_policy.c       2016-07-05 04:15:14.000000000 +0000
24389 +++ linux-4.4.110-vs2.3.9/net/ipv6/xfrm6_policy.c       2018-01-09 16:36:34.000000000 +0000
24390 @@ -64,7 +64,8 @@ static int xfrm6_get_saddr(struct net *n
24391                 return -EHOSTUNREACH;
24392  
24393         dev = ip6_dst_idev(dst)->dev;
24394 -       ipv6_dev_get_saddr(dev_net(dev), dev, &daddr->in6, 0, &saddr->in6);
24395 +       ipv6_dev_get_saddr(dev_net(dev), dev, &daddr->in6,
24396 +               0, &saddr->in6, NULL);
24397         dst_release(dst);
24398         return 0;
24399  }
24400 diff -NurpP --minimal linux-4.4.110/net/netfilter/ipvs/ip_vs_xmit.c linux-4.4.110-vs2.3.9/net/netfilter/ipvs/ip_vs_xmit.c
24401 --- linux-4.4.110/net/netfilter/ipvs/ip_vs_xmit.c       2016-07-05 04:15:15.000000000 +0000
24402 +++ linux-4.4.110-vs2.3.9/net/netfilter/ipvs/ip_vs_xmit.c       2018-01-09 16:36:34.000000000 +0000
24403 @@ -381,7 +381,7 @@ __ip_vs_route_output_v6(struct net *net,
24404                 return dst;
24405         if (ipv6_addr_any(&fl6.saddr) &&
24406             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
24407 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
24408 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
24409                 goto out_err;
24410         if (do_xfrm) {
24411                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
24412 diff -NurpP --minimal linux-4.4.110/net/netlink/af_netlink.c linux-4.4.110-vs2.3.9/net/netlink/af_netlink.c
24413 --- linux-4.4.110/net/netlink/af_netlink.c      2018-01-09 16:35:16.000000000 +0000
24414 +++ linux-4.4.110-vs2.3.9/net/netlink/af_netlink.c      2018-01-09 16:36:34.000000000 +0000
24415 @@ -62,6 +62,8 @@
24416  #include <asm/cacheflush.h>
24417  #include <linux/hash.h>
24418  #include <linux/genetlink.h>
24419 +#include <linux/vs_context.h>
24420 +#include <linux/vs_network.h>
24421  
24422  #include <net/net_namespace.h>
24423  #include <net/sock.h>
24424 @@ -2460,7 +2462,8 @@ static void *__netlink_seq_next(struct s
24425                         if (err)
24426                                 return ERR_PTR(err);
24427                 }
24428 -       } while (sock_net(&nlk->sk) != seq_file_net(seq));
24429 +       } while ((sock_net(&nlk->sk) != seq_file_net(seq)) ||
24430 +               !nx_check(nlk->sk.sk_nid, VS_WATCH_P | VS_IDENT));
24431  
24432         return nlk;
24433  }
24434 diff -NurpP --minimal linux-4.4.110/net/socket.c linux-4.4.110-vs2.3.9/net/socket.c
24435 --- linux-4.4.110/net/socket.c  2018-01-09 16:35:17.000000000 +0000
24436 +++ linux-4.4.110-vs2.3.9/net/socket.c  2018-01-09 16:36:34.000000000 +0000
24437 @@ -99,10 +99,12 @@
24438  
24439  #include <net/sock.h>
24440  #include <linux/netfilter.h>
24441 +#include <linux/vs_socket.h>
24442 +#include <linux/vs_inet.h>
24443 +#include <linux/vs_inet6.h>
24444  
24445  #include <linux/if_tun.h>
24446  #include <linux/ipv6_route.h>
24447 -#include <linux/route.h>
24448  #include <linux/sockios.h>
24449  #include <linux/atalk.h>
24450  #include <net/busy_poll.h>
24451 @@ -608,8 +610,24 @@ EXPORT_SYMBOL(__sock_tx_timestamp);
24452  
24453  static inline int sock_sendmsg_nosec(struct socket *sock, struct msghdr *msg)
24454  {
24455 -       int ret = sock->ops->sendmsg(sock, msg, msg_data_left(msg));
24456 -       BUG_ON(ret == -EIOCBQUEUED);
24457 +       size_t size = msg_data_left(msg);
24458 +       int ret = sock->ops->sendmsg(sock, msg, size);
24459 +#if 0
24460 +       if (sock->sk) {
24461 +               if (!ret)
24462 +                       vx_sock_fail(sock->sk, size);
24463 +               else
24464 +                       vx_sock_send(sock->sk, size);
24465 +       }
24466 +#endif
24467 +       vxdprintk(VXD_CBIT(net, 7),
24468 +               "sock_sendmsg_nosec: %p[%p,%p,%p;%d/%d]:%zu/%zu",
24469 +               sock, sock->sk,
24470 +               (sock->sk)?sock->sk->sk_nx_info:0,
24471 +               (sock->sk)?sock->sk->sk_vx_info:0,
24472 +               (sock->sk)?sock->sk->sk_xid:0,
24473 +               (sock->sk)?sock->sk->sk_nid:0,
24474 +               size, msg_data_left(msg));
24475         return ret;
24476  }
24477  
24478 @@ -1100,6 +1118,13 @@ int __sock_create(struct net *net, int f
24479         if (type < 0 || type >= SOCK_MAX)
24480                 return -EINVAL;
24481  
24482 +       if (!nx_check(0, VS_ADMIN)) {
24483 +               if (family == PF_INET && !current_nx_info_has_v4())
24484 +                       return -EAFNOSUPPORT;
24485 +               if (family == PF_INET6 && !current_nx_info_has_v6())
24486 +                       return -EAFNOSUPPORT;
24487 +       }
24488 +
24489         /* Compatibility.
24490  
24491            This uglymoron is moved from INET layer to here to avoid
24492 @@ -1234,6 +1259,7 @@ SYSCALL_DEFINE3(socket, int, family, int
24493         if (retval < 0)
24494                 goto out;
24495  
24496 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
24497         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
24498         if (retval < 0)
24499                 goto out_release;
24500 @@ -1275,10 +1301,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
24501         err = sock_create(family, type, protocol, &sock1);
24502         if (err < 0)
24503                 goto out;
24504 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
24505  
24506         err = sock_create(family, type, protocol, &sock2);
24507         if (err < 0)
24508                 goto out_release_1;
24509 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
24510  
24511         err = sock1->ops->socketpair(sock1, sock2);
24512         if (err < 0)
24513 diff -NurpP --minimal linux-4.4.110/net/sunrpc/auth.c linux-4.4.110-vs2.3.9/net/sunrpc/auth.c
24514 --- linux-4.4.110/net/sunrpc/auth.c     2015-10-29 09:21:46.000000000 +0000
24515 +++ linux-4.4.110-vs2.3.9/net/sunrpc/auth.c     2018-01-09 16:36:34.000000000 +0000
24516 @@ -15,6 +15,7 @@
24517  #include <linux/sunrpc/clnt.h>
24518  #include <linux/sunrpc/gss_api.h>
24519  #include <linux/spinlock.h>
24520 +#include <linux/vs_tag.h>
24521  
24522  #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
24523  # define RPCDBG_FACILITY       RPCDBG_AUTH
24524 @@ -630,6 +631,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
24525         memset(&acred, 0, sizeof(acred));
24526         acred.uid = cred->fsuid;
24527         acred.gid = cred->fsgid;
24528 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
24529         acred.group_info = cred->group_info;
24530         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
24531         return ret;
24532 @@ -669,6 +671,7 @@ rpcauth_bind_root_cred(struct rpc_task *
24533         struct auth_cred acred = {
24534                 .uid = GLOBAL_ROOT_UID,
24535                 .gid = GLOBAL_ROOT_GID,
24536 +               .tag = KTAGT_INIT(dx_current_tag()),
24537         };
24538  
24539         dprintk("RPC: %5u looking up %s cred\n",
24540 diff -NurpP --minimal linux-4.4.110/net/sunrpc/auth_unix.c linux-4.4.110-vs2.3.9/net/sunrpc/auth_unix.c
24541 --- linux-4.4.110/net/sunrpc/auth_unix.c        2016-07-05 04:12:45.000000000 +0000
24542 +++ linux-4.4.110-vs2.3.9/net/sunrpc/auth_unix.c        2018-01-09 16:36:34.000000000 +0000
24543 @@ -13,11 +13,13 @@
24544  #include <linux/sunrpc/clnt.h>
24545  #include <linux/sunrpc/auth.h>
24546  #include <linux/user_namespace.h>
24547 +#include <linux/vs_tag.h>
24548  
24549  #define NFS_NGROUPS    16
24550  
24551  struct unx_cred {
24552         struct rpc_cred         uc_base;
24553 +       ktag_t                  uc_tag;
24554         kgid_t                  uc_gid;
24555         kgid_t                  uc_gids[NFS_NGROUPS];
24556  };
24557 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
24558                 groups = NFS_NGROUPS;
24559  
24560         cred->uc_gid = acred->gid;
24561 +       cred->uc_tag = acred->tag;
24562         for (i = 0; i < groups; i++)
24563                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
24564         if (i < NFS_NGROUPS)
24565 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
24566         unsigned int i;
24567  
24568  
24569 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
24570 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
24571 +           !gid_eq(cred->uc_gid, acred->gid) ||
24572 +           !tag_eq(cred->uc_tag, acred->tag))
24573                 return 0;
24574  
24575         if (acred->group_info != NULL)
24576 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
24577         struct rpc_clnt *clnt = task->tk_client;
24578         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
24579         __be32          *base, *hold;
24580 -       int             i;
24581 +       int             i, tag;
24582  
24583         *p++ = htonl(RPC_AUTH_UNIX);
24584         base = p++;
24585 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
24586          */
24587         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
24588  
24589 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
24590 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
24591 +       tag = task->tk_client->cl_tag;
24592 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
24593 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
24594 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
24595 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
24596         hold = p++;
24597         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
24598                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
24599 diff -NurpP --minimal linux-4.4.110/net/sunrpc/clnt.c linux-4.4.110-vs2.3.9/net/sunrpc/clnt.c
24600 --- linux-4.4.110/net/sunrpc/clnt.c     2018-01-09 16:35:17.000000000 +0000
24601 +++ linux-4.4.110-vs2.3.9/net/sunrpc/clnt.c     2018-01-09 16:36:34.000000000 +0000
24602 @@ -31,6 +31,7 @@
24603  #include <linux/in.h>
24604  #include <linux/in6.h>
24605  #include <linux/un.h>
24606 +#include <linux/vs_cvirt.h>
24607  
24608  #include <linux/sunrpc/clnt.h>
24609  #include <linux/sunrpc/addr.h>
24610 @@ -477,6 +478,9 @@ static struct rpc_clnt *rpc_create_xprt(
24611         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
24612                 clnt->cl_chatty = 1;
24613  
24614 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
24615 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
24616 +               clnt->cl_tag = 1; */
24617         return clnt;
24618  }
24619  
24620 diff -NurpP --minimal linux-4.4.110/net/unix/af_unix.c linux-4.4.110-vs2.3.9/net/unix/af_unix.c
24621 --- linux-4.4.110/net/unix/af_unix.c    2018-01-09 16:35:17.000000000 +0000
24622 +++ linux-4.4.110-vs2.3.9/net/unix/af_unix.c    2018-01-09 16:36:34.000000000 +0000
24623 @@ -117,6 +117,8 @@
24624  #include <net/checksum.h>
24625  #include <linux/security.h>
24626  #include <linux/freezer.h>
24627 +#include <linux/vs_context.h>
24628 +#include <linux/vs_limit.h>
24629  
24630  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
24631  EXPORT_SYMBOL_GPL(unix_socket_table);
24632 @@ -282,6 +284,8 @@ static struct sock *__unix_find_socket_b
24633                 if (!net_eq(sock_net(s), net))
24634                         continue;
24635  
24636 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
24637 +                       continue;
24638                 if (u->addr->len == len &&
24639                     !memcmp(u->addr->name, sunname, len))
24640                         goto found;
24641 @@ -2741,6 +2745,8 @@ static struct sock *unix_from_bucket(str
24642         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
24643                 if (sock_net(sk) != seq_file_net(seq))
24644                         continue;
24645 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24646 +                       continue;
24647                 if (++count == offset)
24648                         break;
24649         }
24650 @@ -2758,6 +2764,8 @@ static struct sock *unix_next_socket(str
24651                 sk = sk_next(sk);
24652                 if (!sk)
24653                         goto next_bucket;
24654 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24655 +                       continue;
24656                 if (sock_net(sk) == seq_file_net(seq))
24657                         return sk;
24658         }
24659 diff -NurpP --minimal linux-4.4.110/scripts/checksyscalls.sh linux-4.4.110-vs2.3.9/scripts/checksyscalls.sh
24660 --- linux-4.4.110/scripts/checksyscalls.sh      2015-10-29 09:21:46.000000000 +0000
24661 +++ linux-4.4.110-vs2.3.9/scripts/checksyscalls.sh      2018-01-09 16:36:34.000000000 +0000
24662 @@ -196,7 +196,6 @@ cat << EOF
24663  #define __IGNORE_afs_syscall
24664  #define __IGNORE_getpmsg
24665  #define __IGNORE_putpmsg
24666 -#define __IGNORE_vserver
24667  EOF
24668  }
24669  
24670 diff -NurpP --minimal linux-4.4.110/security/commoncap.c linux-4.4.110-vs2.3.9/security/commoncap.c
24671 --- linux-4.4.110/security/commoncap.c  2018-01-09 16:35:18.000000000 +0000
24672 +++ linux-4.4.110-vs2.3.9/security/commoncap.c  2018-01-09 16:36:34.000000000 +0000
24673 @@ -71,6 +71,7 @@ static void warn_setuid_and_fcaps_mixed(
24674  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
24675                 int cap, int audit)
24676  {
24677 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
24678         struct user_namespace *ns = targ_ns;
24679  
24680         /* See if cred has the capability in the target user namespace
24681 @@ -79,8 +80,12 @@ int cap_capable(const struct cred *cred,
24682          */
24683         for (;;) {
24684                 /* Do we have the necessary capabilities? */
24685 -               if (ns == cred->user_ns)
24686 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
24687 +               if (ns == cred->user_ns) {
24688 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
24689 +                           cap_raised(cred->cap_effective, cap))
24690 +                               return 0;
24691 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
24692 +               }
24693  
24694                 /* Have we tried all of the parent namespaces? */
24695                 if (ns == &init_user_ns)
24696 @@ -664,7 +669,7 @@ int cap_inode_setxattr(struct dentry *de
24697  
24698         if (!strncmp(name, XATTR_SECURITY_PREFIX,
24699                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
24700 -           !capable(CAP_SYS_ADMIN))
24701 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
24702                 return -EPERM;
24703         return 0;
24704  }
24705 @@ -690,7 +695,7 @@ int cap_inode_removexattr(struct dentry
24706  
24707         if (!strncmp(name, XATTR_SECURITY_PREFIX,
24708                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
24709 -           !capable(CAP_SYS_ADMIN))
24710 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
24711                 return -EPERM;
24712         return 0;
24713  }
24714 diff -NurpP --minimal linux-4.4.110/security/selinux/hooks.c linux-4.4.110-vs2.3.9/security/selinux/hooks.c
24715 --- linux-4.4.110/security/selinux/hooks.c      2018-01-09 16:35:18.000000000 +0000
24716 +++ linux-4.4.110-vs2.3.9/security/selinux/hooks.c      2018-01-09 16:36:34.000000000 +0000
24717 @@ -67,7 +67,6 @@
24718  #include <linux/dccp.h>
24719  #include <linux/quota.h>
24720  #include <linux/un.h>          /* for Unix socket types */
24721 -#include <net/af_unix.h>       /* for Unix socket types */
24722  #include <linux/parser.h>
24723  #include <linux/nfs_mount.h>
24724  #include <net/ipv6.h>
This page took 2.073909 seconds and 3 git commands to generate.