]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
95359eb1211aba0d0449267e9a2dd9e871ee7922
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-4.4.115/Documentation/vserver/debug.txt linux-4.4.115-vs2.3.9.7/Documentation/vserver/debug.txt
2 --- linux-4.4.115/Documentation/vserver/debug.txt       1970-01-01 00:00:00.000000000 +0000
3 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/alpha/Kconfig linux-4.4.115-vs2.3.9.7/arch/alpha/Kconfig
160 --- linux-4.4.115/arch/alpha/Kconfig    2016-07-05 04:11:34.000000000 +0000
161 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/alpha/kernel/systbls.S linux-4.4.115-vs2.3.9.7/arch/alpha/kernel/systbls.S
172 --- linux-4.4.115/arch/alpha/kernel/systbls.S   2015-07-06 20:41:36.000000000 +0000
173 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/alpha/kernel/traps.c linux-4.4.115-vs2.3.9.7/arch/alpha/kernel/traps.c
184 --- linux-4.4.115/arch/alpha/kernel/traps.c     2015-07-06 20:41:36.000000000 +0000
185 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/arm/Kconfig linux-4.4.115-vs2.3.9.7/arch/arm/Kconfig
197 --- linux-4.4.115/arch/arm/Kconfig      2016-07-05 04:14:23.000000000 +0000
198 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/arm/kernel/calls.S linux-4.4.115-vs2.3.9.7/arch/arm/kernel/calls.S
209 --- linux-4.4.115/arch/arm/kernel/calls.S       2016-07-05 04:14:26.000000000 +0000
210 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/arm/kernel/traps.c linux-4.4.115-vs2.3.9.7/arch/arm/kernel/traps.c
221 --- linux-4.4.115/arch/arm/kernel/traps.c       2018-02-10 14:37:57.000000000 +0000
222 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/cris/Kconfig linux-4.4.115-vs2.3.9.7/arch/cris/Kconfig
235 --- linux-4.4.115/arch/cris/Kconfig     2016-07-05 04:14:27.000000000 +0000
236 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/ia64/Kconfig linux-4.4.115-vs2.3.9.7/arch/ia64/Kconfig
247 --- linux-4.4.115/arch/ia64/Kconfig     2016-07-05 04:11:39.000000000 +0000
248 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/ia64/kernel/entry.S linux-4.4.115-vs2.3.9.7/arch/ia64/kernel/entry.S
259 --- linux-4.4.115/arch/ia64/kernel/entry.S      2016-07-05 04:14:27.000000000 +0000
260 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/ia64/kernel/ptrace.c linux-4.4.115-vs2.3.9.7/arch/ia64/kernel/ptrace.c
271 --- linux-4.4.115/arch/ia64/kernel/ptrace.c     2015-04-12 22:12:50.000000000 +0000
272 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/ia64/kernel/traps.c linux-4.4.115-vs2.3.9.7/arch/ia64/kernel/traps.c
282 --- linux-4.4.115/arch/ia64/kernel/traps.c      2015-04-12 22:12:50.000000000 +0000
283 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/m32r/kernel/traps.c linux-4.4.115-vs2.3.9.7/arch/m32r/kernel/traps.c
309 --- linux-4.4.115/arch/m32r/kernel/traps.c      2015-04-12 22:12:50.000000000 +0000
310 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/m68k/Kconfig linux-4.4.115-vs2.3.9.7/arch/m68k/Kconfig
324 --- linux-4.4.115/arch/m68k/Kconfig     2016-07-05 04:11:39.000000000 +0000
325 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/mips/Kconfig linux-4.4.115-vs2.3.9.7/arch/mips/Kconfig
336 --- linux-4.4.115/arch/mips/Kconfig     2018-02-10 14:37:59.000000000 +0000
337 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/mips/kernel/ptrace.c linux-4.4.115-vs2.3.9.7/arch/mips/kernel/ptrace.c
348 --- linux-4.4.115/arch/mips/kernel/ptrace.c     2018-02-10 14:37:59.000000000 +0000
349 +++ linux-4.4.115-vs2.3.9.7/arch/mips/kernel/ptrace.c   2018-01-25 00:25:00.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 @@ -787,6 +788,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.115/arch/mips/kernel/scall32-o32.S linux-4.4.115-vs2.3.9.7/arch/mips/kernel/scall32-o32.S
369 --- linux-4.4.115/arch/mips/kernel/scall32-o32.S        2018-02-10 14:37:59.000000000 +0000
370 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/mips/kernel/scall64-64.S linux-4.4.115-vs2.3.9.7/arch/mips/kernel/scall64-64.S
381 --- linux-4.4.115/arch/mips/kernel/scall64-64.S 2018-02-10 14:37:59.000000000 +0000
382 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/mips/kernel/scall64-n32.S linux-4.4.115-vs2.3.9.7/arch/mips/kernel/scall64-n32.S
393 --- linux-4.4.115/arch/mips/kernel/scall64-n32.S        2018-02-10 14:37:59.000000000 +0000
394 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/mips/kernel/scall64-o32.S linux-4.4.115-vs2.3.9.7/arch/mips/kernel/scall64-o32.S
405 --- linux-4.4.115/arch/mips/kernel/scall64-o32.S        2018-02-10 14:37:59.000000000 +0000
406 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/mips/kernel/traps.c linux-4.4.115-vs2.3.9.7/arch/mips/kernel/traps.c
417 --- linux-4.4.115/arch/mips/kernel/traps.c      2018-02-10 14:37:59.000000000 +0000
418 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/parisc/Kconfig linux-4.4.115-vs2.3.9.7/arch/parisc/Kconfig
434 --- linux-4.4.115/arch/parisc/Kconfig   2016-07-05 04:14:29.000000000 +0000
435 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/parisc/kernel/syscall_table.S linux-4.4.115-vs2.3.9.7/arch/parisc/kernel/syscall_table.S
446 --- linux-4.4.115/arch/parisc/kernel/syscall_table.S    2018-02-10 14:38:00.000000000 +0000
447 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/parisc/kernel/traps.c linux-4.4.115-vs2.3.9.7/arch/parisc/kernel/traps.c
458 --- linux-4.4.115/arch/parisc/kernel/traps.c    2018-02-10 14:38:00.000000000 +0000
459 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/powerpc/Kconfig linux-4.4.115-vs2.3.9.7/arch/powerpc/Kconfig
484 --- linux-4.4.115/arch/powerpc/Kconfig  2018-02-10 14:38:00.000000000 +0000
485 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/powerpc/include/uapi/asm/unistd.h linux-4.4.115-vs2.3.9.7/arch/powerpc/include/uapi/asm/unistd.h
496 --- linux-4.4.115/arch/powerpc/include/uapi/asm/unistd.h        2016-07-05 04:14:29.000000000 +0000
497 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/powerpc/kernel/traps.c linux-4.4.115-vs2.3.9.7/arch/powerpc/kernel/traps.c
508 --- linux-4.4.115/arch/powerpc/kernel/traps.c   2018-02-10 14:38:00.000000000 +0000
509 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/s390/Kconfig linux-4.4.115-vs2.3.9.7/arch/s390/Kconfig
523 --- linux-4.4.115/arch/s390/Kconfig     2018-02-10 14:38:01.000000000 +0000
524 +++ linux-4.4.115-vs2.3.9.7/arch/s390/Kconfig   2018-02-10 15:16:50.000000000 +0000
525 @@ -730,6 +730,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.115/arch/s390/include/asm/tlb.h linux-4.4.115-vs2.3.9.7/arch/s390/include/asm/tlb.h
535 --- linux-4.4.115/arch/s390/include/asm/tlb.h   2015-07-06 20:41:37.000000000 +0000
536 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/s390/include/uapi/asm/unistd.h linux-4.4.115-vs2.3.9.7/arch/s390/include/uapi/asm/unistd.h
546 --- linux-4.4.115/arch/s390/include/uapi/asm/unistd.h   2016-07-05 04:14:30.000000000 +0000
547 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/s390/kernel/ptrace.c linux-4.4.115-vs2.3.9.7/arch/s390/kernel/ptrace.c
558 --- linux-4.4.115/arch/s390/kernel/ptrace.c     2018-02-10 14:38:01.000000000 +0000
559 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/s390/kernel/syscalls.S linux-4.4.115-vs2.3.9.7/arch/s390/kernel/syscalls.S
569 --- linux-4.4.115/arch/s390/kernel/syscalls.S   2018-02-10 14:38:01.000000000 +0000
570 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/sh/Kconfig linux-4.4.115-vs2.3.9.7/arch/sh/Kconfig
581 --- linux-4.4.115/arch/sh/Kconfig       2016-07-05 04:11:46.000000000 +0000
582 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/sh/kernel/irq.c linux-4.4.115-vs2.3.9.7/arch/sh/kernel/irq.c
593 --- linux-4.4.115/arch/sh/kernel/irq.c  2016-07-05 04:11:46.000000000 +0000
594 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/sparc/Kconfig linux-4.4.115-vs2.3.9.7/arch/sparc/Kconfig
604 --- linux-4.4.115/arch/sparc/Kconfig    2018-02-10 14:38:01.000000000 +0000
605 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/sparc/include/uapi/asm/unistd.h linux-4.4.115-vs2.3.9.7/arch/sparc/include/uapi/asm/unistd.h
616 --- linux-4.4.115/arch/sparc/include/uapi/asm/unistd.h  2016-07-05 04:14:33.000000000 +0000
617 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/sparc/kernel/systbls_32.S linux-4.4.115-vs2.3.9.7/arch/sparc/kernel/systbls_32.S
628 --- linux-4.4.115/arch/sparc/kernel/systbls_32.S        2016-07-05 04:14:33.000000000 +0000
629 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/sparc/kernel/systbls_64.S linux-4.4.115-vs2.3.9.7/arch/sparc/kernel/systbls_64.S
640 --- linux-4.4.115/arch/sparc/kernel/systbls_64.S        2016-07-05 04:14:33.000000000 +0000
641 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/um/Kconfig.rest linux-4.4.115-vs2.3.9.7/arch/um/Kconfig.rest
661 --- linux-4.4.115/arch/um/Kconfig.rest  2015-04-12 22:12:50.000000000 +0000
662 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/x86/Kconfig linux-4.4.115-vs2.3.9.7/arch/x86/Kconfig
673 --- linux-4.4.115/arch/x86/Kconfig      2018-02-10 14:38:02.000000000 +0000
674 +++ linux-4.4.115-vs2.3.9.7/arch/x86/Kconfig    2018-02-10 15:16:50.000000000 +0000
675 @@ -2687,6 +2687,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.115/arch/x86/entry/syscalls/syscall_32.tbl linux-4.4.115-vs2.3.9.7/arch/x86/entry/syscalls/syscall_32.tbl
685 --- linux-4.4.115/arch/x86/entry/syscalls/syscall_32.tbl        2018-02-10 14:38:02.000000000 +0000
686 +++ linux-4.4.115-vs2.3.9.7/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.115/arch/x86/entry/syscalls/syscall_64.tbl linux-4.4.115-vs2.3.9.7/arch/x86/entry/syscalls/syscall_64.tbl
697 --- linux-4.4.115/arch/x86/entry/syscalls/syscall_64.tbl        2016-07-05 04:14:33.000000000 +0000
698 +++ linux-4.4.115-vs2.3.9.7/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.115/block/ioprio.c linux-4.4.115-vs2.3.9.7/block/ioprio.c
709 --- linux-4.4.115/block/ioprio.c        2018-02-10 14:38:03.000000000 +0000
710 +++ linux-4.4.115-vs2.3.9.7/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.115/drivers/block/Kconfig linux-4.4.115-vs2.3.9.7/drivers/block/Kconfig
738 --- linux-4.4.115/drivers/block/Kconfig 2016-07-05 04:14:35.000000000 +0000
739 +++ linux-4.4.115-vs2.3.9.7/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.115/drivers/block/Makefile linux-4.4.115-vs2.3.9.7/drivers/block/Makefile
755 --- linux-4.4.115/drivers/block/Makefile        2016-07-05 04:14:35.000000000 +0000
756 +++ linux-4.4.115-vs2.3.9.7/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.115/drivers/block/loop.c linux-4.4.115-vs2.3.9.7/drivers/block/loop.c
766 --- linux-4.4.115/drivers/block/loop.c  2018-02-10 14:38:04.000000000 +0000
767 +++ linux-4.4.115-vs2.3.9.7/drivers/block/loop.c        2018-02-10 15:16:50.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.115/drivers/block/loop.h linux-4.4.115-vs2.3.9.7/drivers/block/loop.h
824 --- linux-4.4.115/drivers/block/loop.h  2016-07-05 04:14:35.000000000 +0000
825 +++ linux-4.4.115-vs2.3.9.7/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.115/drivers/block/vroot.c linux-4.4.115-vs2.3.9.7/drivers/block/vroot.c
835 --- linux-4.4.115/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
836 +++ linux-4.4.115-vs2.3.9.7/drivers/block/vroot.c       2018-01-11 07:37:22.000000000 +0000
837 @@ -0,0 +1,291 @@
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 blk_qc_t 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 +       return BLK_QC_T_NONE;
989 +}
990 +
991 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
992 +{
993 +       struct inode *inode = bdev->bd_inode;
994 +       struct vroot_device *vr;
995 +       struct block_device *real_bdev;
996 +       int minor = iminor(inode);
997 +
998 +       vr = &vroot_dev[minor];
999 +       real_bdev = vr->vr_device;
1000 +
1001 +       vxdprintk(VXD_CBIT(misc, 0),
1002 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1003 +               vr->vr_number, VXD_DEV(real_bdev));
1004 +
1005 +       if (vr->vr_state != Vr_bound)
1006 +               return ERR_PTR(-ENXIO);
1007 +
1008 +       __iget(real_bdev->bd_inode);
1009 +       return real_bdev;
1010 +}
1011 +
1012 +
1013 +
1014 +/*
1015 + * And now the modules code and kernel interface.
1016 + */
1017 +
1018 +module_param(max_vroot, int, 0);
1019 +
1020 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1021 +MODULE_LICENSE("GPL");
1022 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1023 +
1024 +MODULE_AUTHOR ("Herbert Pötzl");
1025 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1026 +
1027 +
1028 +int __init vroot_init(void)
1029 +{
1030 +       int err, i;
1031 +
1032 +       if (max_vroot < 1 || max_vroot > 256) {
1033 +               max_vroot = MAX_VROOT_DEFAULT;
1034 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1035 +                       "(must be between 1 and 256), "
1036 +                       "using default (%d)\n", max_vroot);
1037 +       }
1038 +
1039 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1040 +               return -EIO;
1041 +
1042 +       err = -ENOMEM;
1043 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1044 +       if (!vroot_dev)
1045 +               goto out_mem1;
1046 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1047 +
1048 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1049 +       if (!disks)
1050 +               goto out_mem2;
1051 +
1052 +       for (i = 0; i < max_vroot; i++) {
1053 +               disks[i] = alloc_disk(1);
1054 +               if (!disks[i])
1055 +                       goto out_mem3;
1056 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1057 +               if (!disks[i]->queue)
1058 +                       goto out_mem3;
1059 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1060 +       }
1061 +
1062 +       for (i = 0; i < max_vroot; i++) {
1063 +               struct vroot_device *vr = &vroot_dev[i];
1064 +               struct gendisk *disk = disks[i];
1065 +
1066 +               memset(vr, 0, sizeof(*vr));
1067 +               sema_init(&vr->vr_ctl_mutex, 1);
1068 +               vr->vr_number = i;
1069 +               disk->major = VROOT_MAJOR;
1070 +               disk->first_minor = i;
1071 +               disk->fops = &vr_fops;
1072 +               sprintf(disk->disk_name, "vroot%d", i);
1073 +               disk->private_data = vr;
1074 +       }
1075 +
1076 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1077 +       if (err)
1078 +               goto out_mem3;
1079 +
1080 +       for (i = 0; i < max_vroot; i++)
1081 +               add_disk(disks[i]);
1082 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1083 +       return 0;
1084 +
1085 +out_mem3:
1086 +       while (i--)
1087 +               put_disk(disks[i]);
1088 +       kfree(disks);
1089 +out_mem2:
1090 +       kfree(vroot_dev);
1091 +out_mem1:
1092 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1093 +       printk(KERN_ERR "vroot: ran out of memory\n");
1094 +       return err;
1095 +}
1096 +
1097 +void vroot_exit(void)
1098 +{
1099 +       int i;
1100 +
1101 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1102 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1103 +
1104 +       for (i = 0; i < max_vroot; i++) {
1105 +               del_gendisk(disks[i]);
1106 +               put_disk(disks[i]);
1107 +       }
1108 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1109 +
1110 +       kfree(disks);
1111 +       kfree(vroot_dev);
1112 +}
1113 +
1114 +module_init(vroot_init);
1115 +module_exit(vroot_exit);
1116 +
1117 +#ifndef MODULE
1118 +
1119 +static int __init max_vroot_setup(char *str)
1120 +{
1121 +       max_vroot = simple_strtol(str, NULL, 0);
1122 +       return 1;
1123 +}
1124 +
1125 +__setup("max_vroot=", max_vroot_setup);
1126 +
1127 +#endif
1128 +
1129 diff -NurpP --minimal linux-4.4.115/drivers/infiniband/core/addr.c linux-4.4.115-vs2.3.9.7/drivers/infiniband/core/addr.c
1130 --- linux-4.4.115/drivers/infiniband/core/addr.c        2018-02-10 14:38:12.000000000 +0000
1131 +++ linux-4.4.115-vs2.3.9.7/drivers/infiniband/core/addr.c      2018-01-09 16:49:06.000000000 +0000
1132 @@ -283,7 +283,7 @@ static int addr6_resolve(struct sockaddr
1133  
1134         if (ipv6_addr_any(&fl6.saddr)) {
1135                 ret = ipv6_dev_get_saddr(addr->net, ip6_dst_idev(dst)->dev,
1136 -                                        &fl6.daddr, 0, &fl6.saddr);
1137 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1138                 if (ret)
1139                         goto put;
1140  
1141 diff -NurpP --minimal linux-4.4.115/drivers/md/dm-ioctl.c linux-4.4.115-vs2.3.9.7/drivers/md/dm-ioctl.c
1142 --- linux-4.4.115/drivers/md/dm-ioctl.c 2018-02-10 14:38:14.000000000 +0000
1143 +++ linux-4.4.115-vs2.3.9.7/drivers/md/dm-ioctl.c       2018-01-09 16:36:23.000000000 +0000
1144 @@ -16,6 +16,7 @@
1145  #include <linux/dm-ioctl.h>
1146  #include <linux/hdreg.h>
1147  #include <linux/compat.h>
1148 +#include <linux/vs_context.h>
1149  
1150  #include <asm/uaccess.h>
1151  
1152 @@ -114,7 +115,8 @@ static struct hash_cell *__get_name_cell
1153         unsigned int h = hash_str(str);
1154  
1155         list_for_each_entry (hc, _name_buckets + h, name_list)
1156 -               if (!strcmp(hc->name, str)) {
1157 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1158 +                       !strcmp(hc->name, str)) {
1159                         dm_get(hc->md);
1160                         return hc;
1161                 }
1162 @@ -128,7 +130,8 @@ static struct hash_cell *__get_uuid_cell
1163         unsigned int h = hash_str(str);
1164  
1165         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1166 -               if (!strcmp(hc->uuid, str)) {
1167 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1168 +                       !strcmp(hc->uuid, str)) {
1169                         dm_get(hc->md);
1170                         return hc;
1171                 }
1172 @@ -139,13 +142,15 @@ static struct hash_cell *__get_uuid_cell
1173  static struct hash_cell *__get_dev_cell(uint64_t dev)
1174  {
1175         struct mapped_device *md;
1176 -       struct hash_cell *hc;
1177 +       struct hash_cell *hc = NULL;
1178  
1179         md = dm_get_md(huge_decode_dev(dev));
1180         if (!md)
1181                 return NULL;
1182  
1183 -       hc = dm_get_mdptr(md);
1184 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1185 +               hc = dm_get_mdptr(md);
1186 +
1187         if (!hc) {
1188                 dm_put(md);
1189                 return NULL;
1190 @@ -467,6 +472,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1191  
1192  static int remove_all(struct dm_ioctl *param, size_t param_size)
1193  {
1194 +       if (!vx_check(0, VS_ADMIN))
1195 +               return -EPERM;
1196 +
1197         dm_hash_remove_all(true, !!(param->flags & DM_DEFERRED_REMOVE), false);
1198         param->data_size = 0;
1199         return 0;
1200 @@ -514,6 +522,8 @@ static int list_devices(struct dm_ioctl
1201          */
1202         for (i = 0; i < NUM_BUCKETS; i++) {
1203                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1204 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1205 +                               continue;
1206                         needed += sizeof(struct dm_name_list);
1207                         needed += strlen(hc->name) + 1;
1208                         needed += ALIGN_MASK;
1209 @@ -537,6 +547,8 @@ static int list_devices(struct dm_ioctl
1210          */
1211         for (i = 0; i < NUM_BUCKETS; i++) {
1212                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1213 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1214 +                               continue;
1215                         if (old_nl)
1216                                 old_nl->next = (uint32_t) ((void *) nl -
1217                                                            (void *) old_nl);
1218 @@ -1801,8 +1813,8 @@ static int ctl_ioctl(uint command, struc
1219         size_t input_param_size;
1220         struct dm_ioctl param_kernel;
1221  
1222 -       /* only root can play with this */
1223 -       if (!capable(CAP_SYS_ADMIN))
1224 +       /* only root and certain contexts can play with this */
1225 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1226                 return -EACCES;
1227  
1228         if (_IOC_TYPE(command) != DM_IOCTL)
1229 diff -NurpP --minimal linux-4.4.115/drivers/md/dm.c linux-4.4.115-vs2.3.9.7/drivers/md/dm.c
1230 --- linux-4.4.115/drivers/md/dm.c       2018-02-10 14:38:14.000000000 +0000
1231 +++ linux-4.4.115-vs2.3.9.7/drivers/md/dm.c     2018-01-09 16:49:30.000000000 +0000
1232 @@ -25,6 +25,7 @@
1233  #include <linux/elevator.h> /* for rq_end_sector() */
1234  #include <linux/blk-mq.h>
1235  #include <linux/pr.h>
1236 +#include <linux/vs_base.h>
1237  
1238  #include <trace/events/block.h>
1239  
1240 @@ -144,6 +145,7 @@ struct mapped_device {
1241         struct mutex suspend_lock;
1242         atomic_t holders;
1243         atomic_t open_count;
1244 +       vxid_t xid;
1245  
1246         /*
1247          * The current mapping.
1248 @@ -445,6 +447,7 @@ int dm_deleting_md(struct mapped_device
1249  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1250  {
1251         struct mapped_device *md;
1252 +       int ret = -ENXIO;
1253  
1254         spin_lock(&_minor_lock);
1255  
1256 @@ -453,17 +456,19 @@ static int dm_blk_open(struct block_devi
1257                 goto out;
1258  
1259         if (test_bit(DMF_FREEING, &md->flags) ||
1260 -           dm_deleting_md(md)) {
1261 -               md = NULL;
1262 +           dm_deleting_md(md))
1263 +               goto out;
1264 +
1265 +       ret = -EACCES;
1266 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1267                 goto out;
1268 -       }
1269  
1270         dm_get(md);
1271         atomic_inc(&md->open_count);
1272 +       ret = 0;
1273  out:
1274         spin_unlock(&_minor_lock);
1275 -
1276 -       return md ? 0 : -ENXIO;
1277 +       return ret;
1278  }
1279  
1280  static void dm_blk_close(struct gendisk *disk, fmode_t mode)
1281 @@ -909,6 +914,14 @@ int dm_set_geometry(struct mapped_device
1282         return 0;
1283  }
1284  
1285 +/*
1286 + * Get the xid associated with a dm device
1287 + */
1288 +vxid_t dm_get_xid(struct mapped_device *md)
1289 +{
1290 +       return md->xid;
1291 +}
1292 +
1293  /*-----------------------------------------------------------------
1294   * CRUD START:
1295   *   A more elegant soln is in the works that uses the queue
1296 @@ -2380,6 +2393,7 @@ static struct mapped_device *alloc_dev(i
1297         INIT_LIST_HEAD(&md->table_devices);
1298         spin_lock_init(&md->uevent_lock);
1299  
1300 +       md->xid = vx_current_xid();
1301         md->queue = blk_alloc_queue(GFP_KERNEL);
1302         if (!md->queue)
1303                 goto bad;
1304 diff -NurpP --minimal linux-4.4.115/drivers/md/dm.h linux-4.4.115-vs2.3.9.7/drivers/md/dm.h
1305 --- linux-4.4.115/drivers/md/dm.h       2016-07-05 04:12:06.000000000 +0000
1306 +++ linux-4.4.115-vs2.3.9.7/drivers/md/dm.h     2018-01-09 16:36:24.000000000 +0000
1307 @@ -52,6 +52,8 @@ struct dm_dev_internal {
1308  struct dm_table;
1309  struct dm_md_mempools;
1310  
1311 +vxid_t dm_get_xid(struct mapped_device *md);
1312 +
1313  /*-----------------------------------------------------------------
1314   * Internal table functions.
1315   *---------------------------------------------------------------*/
1316 diff -NurpP --minimal linux-4.4.115/drivers/net/tun.c linux-4.4.115-vs2.3.9.7/drivers/net/tun.c
1317 --- linux-4.4.115/drivers/net/tun.c     2018-02-10 14:38:22.000000000 +0000
1318 +++ linux-4.4.115-vs2.3.9.7/drivers/net/tun.c   2018-01-09 16:36:24.000000000 +0000
1319 @@ -65,6 +65,7 @@
1320  #include <linux/nsproxy.h>
1321  #include <linux/virtio_net.h>
1322  #include <linux/rcupdate.h>
1323 +#include <linux/vs_network.h>
1324  #include <net/net_namespace.h>
1325  #include <net/netns/generic.h>
1326  #include <net/rtnetlink.h>
1327 @@ -181,6 +182,7 @@ struct tun_struct {
1328         unsigned int            flags;
1329         kuid_t                  owner;
1330         kgid_t                  group;
1331 +       vnid_t                  nid;
1332  
1333         struct net_device       *dev;
1334         netdev_features_t       set_features;
1335 @@ -475,6 +477,7 @@ static inline bool tun_not_capable(struc
1336         return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1337                   (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1338                 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1339 +               /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1340  }
1341  
1342  static void tun_set_real_num_queues(struct tun_struct *tun)
1343 @@ -1463,6 +1466,7 @@ static void tun_setup(struct net_device
1344  
1345         tun->owner = INVALID_UID;
1346         tun->group = INVALID_GID;
1347 +       tun->nid = nx_current_nid();
1348  
1349         dev->ethtool_ops = &tun_ethtool_ops;
1350         dev->destructor = tun_free_netdev;
1351 @@ -1657,7 +1661,7 @@ static int tun_set_iff(struct net *net,
1352                 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1353                              MAX_TAP_QUEUES : 1;
1354  
1355 -               if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1356 +               if (!nx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1357                         return -EPERM;
1358                 err = security_tun_dev_create();
1359                 if (err < 0)
1360 @@ -2010,6 +2014,16 @@ static long __tun_chr_ioctl(struct file
1361                           from_kgid(&init_user_ns, tun->group));
1362                 break;
1363  
1364 +       case TUNSETNID:
1365 +               if (!capable(CAP_CONTEXT))
1366 +                       return -EPERM;
1367 +
1368 +               /* Set nid owner of the device */
1369 +               tun->nid = (vnid_t) arg;
1370 +
1371 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1372 +               break;
1373 +
1374         case TUNSETLINK:
1375                 /* Only allow setting the type when the interface is down */
1376                 if (tun->dev->flags & IFF_UP) {
1377 diff -NurpP --minimal linux-4.4.115/drivers/scsi/cxgbi/libcxgbi.c linux-4.4.115-vs2.3.9.7/drivers/scsi/cxgbi/libcxgbi.c
1378 --- linux-4.4.115/drivers/scsi/cxgbi/libcxgbi.c 2015-10-29 09:21:24.000000000 +0000
1379 +++ linux-4.4.115-vs2.3.9.7/drivers/scsi/cxgbi/libcxgbi.c       2018-01-09 16:36:24.000000000 +0000
1380 @@ -768,7 +768,8 @@ static struct cxgbi_sock *cxgbi_check_ro
1381                 struct inet6_dev *idev = ip6_dst_idev((struct dst_entry *)rt);
1382  
1383                 err = ipv6_dev_get_saddr(&init_net, idev ? idev->dev : NULL,
1384 -                                        &daddr6->sin6_addr, 0, &pref_saddr);
1385 +                                        &daddr6->sin6_addr, 0, &pref_saddr,
1386 +                                        NULL);
1387                 if (err) {
1388                         pr_info("failed to get source address to reach %pI6\n",
1389                                 &daddr6->sin6_addr);
1390 diff -NurpP --minimal linux-4.4.115/drivers/tty/sysrq.c linux-4.4.115-vs2.3.9.7/drivers/tty/sysrq.c
1391 --- linux-4.4.115/drivers/tty/sysrq.c   2018-02-10 14:38:36.000000000 +0000
1392 +++ linux-4.4.115-vs2.3.9.7/drivers/tty/sysrq.c 2018-01-25 00:25:02.000000000 +0000
1393 @@ -47,6 +47,7 @@
1394  #include <linux/syscalls.h>
1395  #include <linux/of.h>
1396  #include <linux/rcupdate.h>
1397 +#include <linux/vserver/debug.h>
1398  
1399  #include <asm/ptrace.h>
1400  #include <asm/irq_regs.h>
1401 @@ -427,6 +428,21 @@ static struct sysrq_key_op sysrq_unrt_op
1402         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1403  };
1404  
1405 +
1406 +#ifdef CONFIG_VSERVER_DEBUG
1407 +static void sysrq_handle_vxinfo(int key)
1408 +{
1409 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1410 +}
1411 +
1412 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1413 +       .handler        = sysrq_handle_vxinfo,
1414 +       .help_msg       = "conteXt",
1415 +       .action_msg     = "Show Context Info",
1416 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1417 +};
1418 +#endif
1419 +
1420  /* Key Operations table and lock */
1421  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1422  
1423 @@ -483,7 +499,11 @@ static struct sysrq_key_op *sysrq_key_ta
1424         /* x: May be registered on mips for TLB dump */
1425         /* x: May be registered on ppc/powerpc for xmon */
1426         /* x: May be registered on sparc64 for global PMU dump */
1427 +#ifdef CONFIG_VSERVER_DEBUG
1428 +       &sysrq_showvxinfo_op,           /* x */
1429 +#else
1430         NULL,                           /* x */
1431 +#endif
1432         /* y: May be registered on sparc64 for global register dump */
1433         NULL,                           /* y */
1434         &sysrq_ftrace_dump_op,          /* z */
1435 @@ -498,6 +518,8 @@ static int sysrq_key_table_key2index(int
1436                 retval = key - '0';
1437         else if ((key >= 'a') && (key <= 'z'))
1438                 retval = key + 10 - 'a';
1439 +       else if ((key >= 'A') && (key <= 'Z'))
1440 +               retval = key + 10 - 'A';
1441         else
1442                 retval = -1;
1443         return retval;
1444 diff -NurpP --minimal linux-4.4.115/drivers/tty/tty_io.c linux-4.4.115-vs2.3.9.7/drivers/tty/tty_io.c
1445 --- linux-4.4.115/drivers/tty/tty_io.c  2018-02-10 14:38:36.000000000 +0000
1446 +++ linux-4.4.115-vs2.3.9.7/drivers/tty/tty_io.c        2018-01-09 16:36:24.000000000 +0000
1447 @@ -104,6 +104,7 @@
1448  
1449  #include <linux/kmod.h>
1450  #include <linux/nsproxy.h>
1451 +#include <linux/vs_pid.h>
1452  
1453  #undef TTY_DEBUG_HANGUP
1454  #ifdef TTY_DEBUG_HANGUP
1455 @@ -2280,7 +2281,8 @@ static int tiocsti(struct tty_struct *tt
1456         char ch, mbz = 0;
1457         struct tty_ldisc *ld;
1458  
1459 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1460 +       if (((current->signal->tty != tty) &&
1461 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1462                 return -EPERM;
1463         if (get_user(ch, p))
1464                 return -EFAULT;
1465 @@ -2593,6 +2595,7 @@ static int tiocspgrp(struct tty_struct *
1466                 return -ENOTTY;
1467         if (get_user(pgrp_nr, p))
1468                 return -EFAULT;
1469 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1470         if (pgrp_nr < 0)
1471                 return -EINVAL;
1472         rcu_read_lock();
1473 diff -NurpP --minimal linux-4.4.115/fs/attr.c linux-4.4.115-vs2.3.9.7/fs/attr.c
1474 --- linux-4.4.115/fs/attr.c     2018-02-10 14:38:39.000000000 +0000
1475 +++ linux-4.4.115-vs2.3.9.7/fs/attr.c   2018-01-09 17:27:12.000000000 +0000
1476 @@ -15,6 +15,9 @@
1477  #include <linux/security.h>
1478  #include <linux/evm.h>
1479  #include <linux/ima.h>
1480 +#include <linux/proc_fs.h>
1481 +#include <linux/devpts_fs.h>
1482 +#include <linux/vs_tag.h>
1483  
1484  /**
1485   * inode_change_ok - check if attribute changes to an inode are allowed
1486 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1487                         return -EPERM;
1488         }
1489  
1490 +       /* check for inode tag permission */
1491 +       if (dx_permission(inode, MAY_WRITE))
1492 +               return -EACCES;
1493 +
1494         return 0;
1495  }
1496  EXPORT_SYMBOL(inode_change_ok);
1497 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1498                 inode->i_uid = attr->ia_uid;
1499         if (ia_valid & ATTR_GID)
1500                 inode->i_gid = attr->ia_gid;
1501 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1502 +               inode->i_tag = attr->ia_tag;
1503         if (ia_valid & ATTR_ATIME)
1504                 inode->i_atime = timespec_trunc(attr->ia_atime,
1505                                                 inode->i_sb->s_time_gran);
1506 @@ -197,7 +206,8 @@ int notify_change(struct dentry * dentry
1507  
1508         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1509  
1510 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1511 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1512 +               ATTR_TAG | ATTR_TIMES_SET)) {
1513                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1514                         return -EPERM;
1515         }
1516 diff -NurpP --minimal linux-4.4.115/fs/block_dev.c linux-4.4.115-vs2.3.9.7/fs/block_dev.c
1517 --- linux-4.4.115/fs/block_dev.c        2018-02-10 14:38:39.000000000 +0000
1518 +++ linux-4.4.115-vs2.3.9.7/fs/block_dev.c      2018-01-09 17:16:29.000000000 +0000
1519 @@ -29,6 +29,7 @@
1520  #include <linux/log2.h>
1521  #include <linux/cleancache.h>
1522  #include <linux/dax.h>
1523 +#include <linux/vs_device.h>
1524  #include <asm/uaccess.h>
1525  #include "internal.h"
1526  
1527 @@ -645,6 +646,7 @@ struct block_device *bdget(dev_t dev)
1528                 bdev->bd_invalidated = 0;
1529                 inode->i_mode = S_IFBLK;
1530                 inode->i_rdev = dev;
1531 +               inode->i_mdev = dev;
1532                 inode->i_bdev = bdev;
1533                 inode->i_data.a_ops = &def_blk_aops;
1534                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1535 @@ -691,6 +693,11 @@ EXPORT_SYMBOL(bdput);
1536  static struct block_device *bd_acquire(struct inode *inode)
1537  {
1538         struct block_device *bdev;
1539 +       dev_t mdev;
1540 +
1541 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1542 +               return NULL;
1543 +       inode->i_mdev = mdev;
1544  
1545         spin_lock(&bdev_lock);
1546         bdev = inode->i_bdev;
1547 @@ -701,7 +708,7 @@ static struct block_device *bd_acquire(s
1548         }
1549         spin_unlock(&bdev_lock);
1550  
1551 -       bdev = bdget(inode->i_rdev);
1552 +       bdev = bdget(mdev);
1553         if (bdev) {
1554                 spin_lock(&bdev_lock);
1555                 if (!inode->i_bdev) {
1556 diff -NurpP --minimal linux-4.4.115/fs/btrfs/ctree.h linux-4.4.115-vs2.3.9.7/fs/btrfs/ctree.h
1557 --- linux-4.4.115/fs/btrfs/ctree.h      2018-02-10 14:38:39.000000000 +0000
1558 +++ linux-4.4.115-vs2.3.9.7/fs/btrfs/ctree.h    2018-01-09 16:36:24.000000000 +0000
1559 @@ -731,11 +731,14 @@ struct btrfs_inode_item {
1560         /* modification sequence number for NFS */
1561         __le64 sequence;
1562  
1563 +       __le16 tag;
1564         /*
1565          * a little future expansion, for more than this we can
1566          * just grow the inode item and version it
1567          */
1568 -       __le64 reserved[4];
1569 +       __le16 reserved16;
1570 +       __le32 reserved32;
1571 +       __le64 reserved[3];
1572         struct btrfs_timespec atime;
1573         struct btrfs_timespec ctime;
1574         struct btrfs_timespec mtime;
1575 @@ -2189,6 +2192,8 @@ struct btrfs_ioctl_defrag_range_args {
1576  #define BTRFS_DEFAULT_COMMIT_INTERVAL  (30)
1577  #define BTRFS_DEFAULT_MAX_INLINE       (8192)
1578  
1579 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1580 +
1581  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1582  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1583  #define btrfs_raw_test_opt(o, opt)     ((o) & BTRFS_MOUNT_##opt)
1584 @@ -2528,6 +2533,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1585  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1586  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1587  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1588 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1589  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1590  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1591  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1592 @@ -2575,6 +2581,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1593  
1594  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1595  
1596 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1597 +#define BTRFS_INODE_BARRIER            (1 << 25)
1598 +#define BTRFS_INODE_COW                        (1 << 26)
1599 +
1600  
1601  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1602  
1603 @@ -4022,6 +4032,7 @@ long btrfs_ioctl(struct file *file, unsi
1604  void btrfs_update_iflags(struct inode *inode);
1605  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1606  int btrfs_is_empty_uuid(u8 *uuid);
1607 +int btrfs_sync_flags(struct inode *inode, int, int);
1608  int btrfs_defrag_file(struct inode *inode, struct file *file,
1609                       struct btrfs_ioctl_defrag_range_args *range,
1610                       u64 newer_than, unsigned long max_pages);
1611 diff -NurpP --minimal linux-4.4.115/fs/btrfs/disk-io.c linux-4.4.115-vs2.3.9.7/fs/btrfs/disk-io.c
1612 --- linux-4.4.115/fs/btrfs/disk-io.c    2018-02-10 14:38:39.000000000 +0000
1613 +++ linux-4.4.115-vs2.3.9.7/fs/btrfs/disk-io.c  2018-01-09 16:36:24.000000000 +0000
1614 @@ -2736,6 +2736,9 @@ int open_ctree(struct super_block *sb,
1615                 goto fail_alloc;
1616         }
1617  
1618 +       if (btrfs_test_opt(tree_root, TAGGED))
1619 +               sb->s_flags |= MS_TAGGED;
1620 +
1621         features = btrfs_super_incompat_flags(disk_super) &
1622                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1623         if (features) {
1624 diff -NurpP --minimal linux-4.4.115/fs/btrfs/inode.c linux-4.4.115-vs2.3.9.7/fs/btrfs/inode.c
1625 --- linux-4.4.115/fs/btrfs/inode.c      2018-02-10 14:38:39.000000000 +0000
1626 +++ linux-4.4.115-vs2.3.9.7/fs/btrfs/inode.c    2018-01-09 16:36:24.000000000 +0000
1627 @@ -43,6 +43,7 @@
1628  #include <linux/blkdev.h>
1629  #include <linux/posix_acl_xattr.h>
1630  #include <linux/uio.h>
1631 +#include <linux/vs_tag.h>
1632  #include "ctree.h"
1633  #include "disk-io.h"
1634  #include "transaction.h"
1635 @@ -3611,6 +3612,9 @@ static void btrfs_read_locked_inode(stru
1636         unsigned long ptr;
1637         int maybe_acls;
1638         u32 rdev;
1639 +       kuid_t kuid;
1640 +       kgid_t kgid;
1641 +       ktag_t ktag;
1642         int ret;
1643         bool filled = false;
1644         int first_xattr_slot;
1645 @@ -3638,8 +3642,14 @@ static void btrfs_read_locked_inode(stru
1646                                     struct btrfs_inode_item);
1647         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1648         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1649 -       i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1650 -       i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1651 +
1652 +       kuid = make_kuid(&init_user_ns, btrfs_inode_uid(leaf, inode_item));
1653 +       kgid = make_kgid(&init_user_ns, btrfs_inode_gid(leaf, inode_item));
1654 +       ktag = make_ktag(&init_user_ns, btrfs_inode_tag(leaf, inode_item));
1655 +
1656 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
1657 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
1658 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
1659         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1660  
1661         inode->i_atime.tv_sec = btrfs_timespec_sec(leaf, &inode_item->atime);
1662 @@ -3795,11 +3805,18 @@ static void fill_inode_item(struct btrfs
1663                             struct inode *inode)
1664  {
1665         struct btrfs_map_token token;
1666 +       uid_t uid = from_kuid(&init_user_ns,
1667 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
1668 +       gid_t gid = from_kgid(&init_user_ns,
1669 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
1670  
1671         btrfs_init_map_token(&token);
1672  
1673 -       btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1674 -       btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1675 +       btrfs_set_token_inode_uid(leaf, item, uid, &token);
1676 +       btrfs_set_token_inode_gid(leaf, item, gid, &token);
1677 +#ifdef CONFIG_TAGGING_INTERN
1678 +       btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1679 +#endif
1680         btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1681                                    &token);
1682         btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1683 @@ -10062,6 +10079,7 @@ static const struct inode_operations btr
1684         .listxattr      = btrfs_listxattr,
1685         .removexattr    = btrfs_removexattr,
1686         .permission     = btrfs_permission,
1687 +       .sync_flags     = btrfs_sync_flags,
1688         .get_acl        = btrfs_get_acl,
1689         .set_acl        = btrfs_set_acl,
1690         .update_time    = btrfs_update_time,
1691 @@ -10070,6 +10088,7 @@ static const struct inode_operations btr
1692  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1693         .lookup         = btrfs_lookup,
1694         .permission     = btrfs_permission,
1695 +       .sync_flags     = btrfs_sync_flags,
1696         .get_acl        = btrfs_get_acl,
1697         .set_acl        = btrfs_set_acl,
1698         .update_time    = btrfs_update_time,
1699 @@ -10140,6 +10159,7 @@ static const struct inode_operations btr
1700         .removexattr    = btrfs_removexattr,
1701         .permission     = btrfs_permission,
1702         .fiemap         = btrfs_fiemap,
1703 +       .sync_flags     = btrfs_sync_flags,
1704         .get_acl        = btrfs_get_acl,
1705         .set_acl        = btrfs_set_acl,
1706         .update_time    = btrfs_update_time,
1707 diff -NurpP --minimal linux-4.4.115/fs/btrfs/ioctl.c linux-4.4.115-vs2.3.9.7/fs/btrfs/ioctl.c
1708 --- linux-4.4.115/fs/btrfs/ioctl.c      2018-02-10 14:38:39.000000000 +0000
1709 +++ linux-4.4.115-vs2.3.9.7/fs/btrfs/ioctl.c    2018-01-09 16:36:24.000000000 +0000
1710 @@ -108,10 +108,13 @@ static unsigned int btrfs_flags_to_ioctl
1711  {
1712         unsigned int iflags = 0;
1713  
1714 -       if (flags & BTRFS_INODE_SYNC)
1715 -               iflags |= FS_SYNC_FL;
1716         if (flags & BTRFS_INODE_IMMUTABLE)
1717                 iflags |= FS_IMMUTABLE_FL;
1718 +       if (flags & BTRFS_INODE_IXUNLINK)
1719 +               iflags |= FS_IXUNLINK_FL;
1720 +
1721 +       if (flags & BTRFS_INODE_SYNC)
1722 +               iflags |= FS_SYNC_FL;
1723         if (flags & BTRFS_INODE_APPEND)
1724                 iflags |= FS_APPEND_FL;
1725         if (flags & BTRFS_INODE_NODUMP)
1726 @@ -128,34 +131,84 @@ static unsigned int btrfs_flags_to_ioctl
1727         else if (flags & BTRFS_INODE_NOCOMPRESS)
1728                 iflags |= FS_NOCOMP_FL;
1729  
1730 +       if (flags & BTRFS_INODE_BARRIER)
1731 +               iflags |= FS_BARRIER_FL;
1732 +       if (flags & BTRFS_INODE_COW)
1733 +               iflags |= FS_COW_FL;
1734         return iflags;
1735  }
1736  
1737  /*
1738 - * Update inode->i_flags based on the btrfs internal flags.
1739 + * Update inode->i_(v)flags based on the btrfs internal flags.
1740   */
1741  void btrfs_update_iflags(struct inode *inode)
1742  {
1743         struct btrfs_inode *ip = BTRFS_I(inode);
1744         unsigned int new_fl = 0;
1745  
1746 -       if (ip->flags & BTRFS_INODE_SYNC)
1747 -               new_fl |= S_SYNC;
1748         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1749                 new_fl |= S_IMMUTABLE;
1750 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1751 +               new_fl |= S_IXUNLINK;
1752 +
1753 +       if (ip->flags & BTRFS_INODE_SYNC)
1754 +               new_fl |= S_SYNC;
1755         if (ip->flags & BTRFS_INODE_APPEND)
1756                 new_fl |= S_APPEND;
1757         if (ip->flags & BTRFS_INODE_NOATIME)
1758                 new_fl |= S_NOATIME;
1759         if (ip->flags & BTRFS_INODE_DIRSYNC)
1760                 new_fl |= S_DIRSYNC;
1761 -
1762         set_mask_bits(&inode->i_flags,
1763 -                     S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | S_DIRSYNC,
1764 +                     S_SYNC | S_APPEND | S_IMMUTABLE | S_IXUNLINK | S_NOATIME | S_DIRSYNC,
1765                       new_fl);
1766 +
1767 +       new_fl = 0;
1768 +       if (ip->flags & BTRFS_INODE_BARRIER)
1769 +               new_fl |= V_BARRIER;
1770 +       if (ip->flags & BTRFS_INODE_COW)
1771 +               new_fl |= V_COW;
1772 +
1773 +       set_mask_bits(&inode->i_vflags,
1774 +               V_BARRIER | V_COW, new_fl);
1775  }
1776  
1777  /*
1778 + * Update btrfs internal flags from inode->i_(v)flags.
1779 + */
1780 +void btrfs_update_flags(struct inode *inode)
1781 +{
1782 +       struct btrfs_inode *ip = BTRFS_I(inode);
1783 +
1784 +       unsigned int flags = inode->i_flags;
1785 +       unsigned int vflags = inode->i_vflags;
1786 +
1787 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1788 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1789 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1790 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1791 +
1792 +       if (flags & S_IMMUTABLE)
1793 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1794 +       if (flags & S_IXUNLINK)
1795 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1796 +
1797 +       if (flags & S_SYNC)
1798 +               ip->flags |= BTRFS_INODE_SYNC;
1799 +       if (flags & S_APPEND)
1800 +               ip->flags |= BTRFS_INODE_APPEND;
1801 +       if (flags & S_NOATIME)
1802 +               ip->flags |= BTRFS_INODE_NOATIME;
1803 +       if (flags & S_DIRSYNC)
1804 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1805 +
1806 +       if (vflags & V_BARRIER)
1807 +               ip->flags |= BTRFS_INODE_BARRIER;
1808 +       if (vflags & V_COW)
1809 +               ip->flags |= BTRFS_INODE_COW;
1810 + }
1811 +
1812 +/*
1813   * Inherit flags from the parent inode.
1814   *
1815   * Currently only the compression flags and the cow flags are inherited.
1816 @@ -168,6 +221,7 @@ void btrfs_inherit_iflags(struct inode *
1817                 return;
1818  
1819         flags = BTRFS_I(dir)->flags;
1820 +       flags &= ~BTRFS_INODE_BARRIER;
1821  
1822         if (flags & BTRFS_INODE_NOCOMPRESS) {
1823                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1824 @@ -186,6 +240,30 @@ void btrfs_inherit_iflags(struct inode *
1825         btrfs_update_iflags(inode);
1826  }
1827  
1828 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1829 +{
1830 +       struct btrfs_inode *ip = BTRFS_I(inode);
1831 +       struct btrfs_root *root = ip->root;
1832 +       struct btrfs_trans_handle *trans;
1833 +       int ret;
1834 +
1835 +       trans = btrfs_join_transaction(root);
1836 +       BUG_ON(!trans);
1837 +
1838 +       inode->i_flags = flags;
1839 +       inode->i_vflags = vflags;
1840 +       btrfs_update_flags(inode);
1841 +
1842 +       ret = btrfs_update_inode(trans, root, inode);
1843 +       BUG_ON(ret);
1844 +
1845 +       btrfs_update_iflags(inode);
1846 +       inode->i_ctime = CURRENT_TIME;
1847 +       btrfs_end_transaction(trans, root);
1848 +
1849 +       return 0;
1850 +}
1851 +
1852  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1853  {
1854         struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1855 @@ -248,21 +326,27 @@ static int btrfs_ioctl_setflags(struct f
1856  
1857         flags = btrfs_mask_flags(inode->i_mode, flags);
1858         oldflags = btrfs_flags_to_ioctl(ip->flags);
1859 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1860 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1861 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1862                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1863                         ret = -EPERM;
1864                         goto out_unlock;
1865                 }
1866         }
1867  
1868 -       if (flags & FS_SYNC_FL)
1869 -               ip->flags |= BTRFS_INODE_SYNC;
1870 -       else
1871 -               ip->flags &= ~BTRFS_INODE_SYNC;
1872         if (flags & FS_IMMUTABLE_FL)
1873                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1874         else
1875                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1876 +       if (flags & FS_IXUNLINK_FL)
1877 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1878 +       else
1879 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1880 +
1881 +       if (flags & FS_SYNC_FL)
1882 +               ip->flags |= BTRFS_INODE_SYNC;
1883 +       else
1884 +               ip->flags &= ~BTRFS_INODE_SYNC;
1885         if (flags & FS_APPEND_FL)
1886                 ip->flags |= BTRFS_INODE_APPEND;
1887         else
1888 diff -NurpP --minimal linux-4.4.115/fs/btrfs/super.c linux-4.4.115-vs2.3.9.7/fs/btrfs/super.c
1889 --- linux-4.4.115/fs/btrfs/super.c      2018-02-10 14:38:40.000000000 +0000
1890 +++ linux-4.4.115-vs2.3.9.7/fs/btrfs/super.c    2018-01-09 17:25:27.000000000 +0000
1891 @@ -306,7 +306,7 @@ enum {
1892  #ifdef CONFIG_BTRFS_DEBUG
1893         Opt_fragment_data, Opt_fragment_metadata, Opt_fragment_all,
1894  #endif
1895 -       Opt_err,
1896 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1897  };
1898  
1899  static match_table_t tokens = {
1900 @@ -363,6 +363,9 @@ static match_table_t tokens = {
1901         {Opt_fragment_metadata, "fragment=metadata"},
1902         {Opt_fragment_all, "fragment=all"},
1903  #endif
1904 +       {Opt_tag, "tag"},
1905 +       {Opt_notag, "notag"},
1906 +       {Opt_tagid, "tagid=%u"},
1907         {Opt_err, NULL},
1908  };
1909  
1910 @@ -745,6 +748,22 @@ int btrfs_parse_options(struct btrfs_roo
1911                         btrfs_set_opt(info->mount_opt, FRAGMENT_DATA);
1912                         break;
1913  #endif
1914 +#ifndef CONFIG_TAGGING_NONE
1915 +               case Opt_tag:
1916 +                       printk(KERN_INFO "btrfs: use tagging\n");
1917 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1918 +                       break;
1919 +               case Opt_notag:
1920 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
1921 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
1922 +                       break;
1923 +#endif
1924 +#ifdef CONFIG_PROPAGATE
1925 +               case Opt_tagid:
1926 +                       /* use args[0] */
1927 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1928 +                       break;
1929 +#endif
1930                 case Opt_err:
1931                         btrfs_info(root->fs_info, "unrecognized mount option '%s'", p);
1932                         ret = -EINVAL;
1933 @@ -1647,6 +1666,12 @@ static int btrfs_remount(struct super_bl
1934         btrfs_resize_thread_pool(fs_info,
1935                 fs_info->thread_pool_size, old_thread_pool_size);
1936  
1937 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1938 +               printk("btrfs: %s: tagging not permitted on remount.\n",
1939 +                       sb->s_id);
1940 +               return -EINVAL;
1941 +       }
1942 +
1943         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1944                 goto out;
1945  
1946 diff -NurpP --minimal linux-4.4.115/fs/char_dev.c linux-4.4.115-vs2.3.9.7/fs/char_dev.c
1947 --- linux-4.4.115/fs/char_dev.c 2016-07-05 04:12:30.000000000 +0000
1948 +++ linux-4.4.115-vs2.3.9.7/fs/char_dev.c       2018-01-09 16:36:24.000000000 +0000
1949 @@ -21,6 +21,8 @@
1950  #include <linux/mutex.h>
1951  #include <linux/backing-dev.h>
1952  #include <linux/tty.h>
1953 +#include <linux/vs_context.h>
1954 +#include <linux/vs_device.h>
1955  
1956  #include "internal.h"
1957  
1958 @@ -350,14 +352,21 @@ static int chrdev_open(struct inode *ino
1959         struct cdev *p;
1960         struct cdev *new = NULL;
1961         int ret = 0;
1962 +       dev_t mdev;
1963 +
1964 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1965 +               return -EPERM;
1966 +       inode->i_mdev = mdev;
1967  
1968         spin_lock(&cdev_lock);
1969         p = inode->i_cdev;
1970         if (!p) {
1971                 struct kobject *kobj;
1972                 int idx;
1973 +
1974                 spin_unlock(&cdev_lock);
1975 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1976 +
1977 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
1978                 if (!kobj)
1979                         return -ENXIO;
1980                 new = container_of(kobj, struct cdev, kobj);
1981 diff -NurpP --minimal linux-4.4.115/fs/dcache.c linux-4.4.115-vs2.3.9.7/fs/dcache.c
1982 --- linux-4.4.115/fs/dcache.c   2018-02-10 14:38:45.000000000 +0000
1983 +++ linux-4.4.115-vs2.3.9.7/fs/dcache.c 2018-01-09 16:36:24.000000000 +0000
1984 @@ -39,6 +39,7 @@
1985  #include <linux/ratelimit.h>
1986  #include <linux/list_lru.h>
1987  #include <linux/kasan.h>
1988 +#include <linux/vs_limit.h>
1989  
1990  #include "internal.h"
1991  #include "mount.h"
1992 @@ -677,6 +678,7 @@ static inline bool fast_dput(struct dent
1993                 spin_lock(&dentry->d_lock);
1994                 if (dentry->d_lockref.count > 1) {
1995                         dentry->d_lockref.count--;
1996 +                       vx_dentry_dec(dentry);
1997                         spin_unlock(&dentry->d_lock);
1998                         return 1;
1999                 }
2000 @@ -806,6 +808,7 @@ repeat:
2001         dentry_lru_add(dentry);
2002  
2003         dentry->d_lockref.count--;
2004 +       vx_dentry_dec(dentry);
2005         spin_unlock(&dentry->d_lock);
2006         return;
2007  
2008 @@ -823,6 +826,7 @@ EXPORT_SYMBOL(dput);
2009  static inline void __dget_dlock(struct dentry *dentry)
2010  {
2011         dentry->d_lockref.count++;
2012 +       vx_dentry_inc(dentry);
2013  }
2014  
2015  static inline void __dget(struct dentry *dentry)
2016 @@ -835,6 +839,8 @@ struct dentry *dget_parent(struct dentry
2017         int gotref;
2018         struct dentry *ret;
2019  
2020 +       vx_dentry_dec(dentry);
2021 +
2022         /*
2023          * Do optimistic parent lookup without any
2024          * locking.
2025 @@ -865,6 +871,7 @@ repeat:
2026         rcu_read_unlock();
2027         BUG_ON(!ret->d_lockref.count);
2028         ret->d_lockref.count++;
2029 +       vx_dentry_inc(ret);
2030         spin_unlock(&ret->d_lock);
2031         return ret;
2032  }
2033 @@ -1019,6 +1026,7 @@ static void shrink_dentry_list(struct li
2034                         parent = lock_parent(dentry);
2035                         if (dentry->d_lockref.count != 1) {
2036                                 dentry->d_lockref.count--;
2037 +                               vx_dentry_dec(dentry);
2038                                 spin_unlock(&dentry->d_lock);
2039                                 if (parent)
2040                                         spin_unlock(&parent->d_lock);
2041 @@ -1581,6 +1589,9 @@ struct dentry *__d_alloc(struct super_bl
2042         struct dentry *dentry;
2043         char *dname;
2044  
2045 +       if (!vx_dentry_avail(1))
2046 +               return NULL;
2047 +
2048         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2049         if (!dentry)
2050                 return NULL;
2051 @@ -1619,6 +1630,7 @@ struct dentry *__d_alloc(struct super_bl
2052  
2053         dentry->d_lockref.count = 1;
2054         dentry->d_flags = 0;
2055 +       vx_dentry_inc(dentry);
2056         spin_lock_init(&dentry->d_lock);
2057         seqcount_init(&dentry->d_seq);
2058         dentry->d_inode = NULL;
2059 @@ -2355,6 +2367,7 @@ struct dentry *__d_lookup(const struct d
2060                 }
2061  
2062                 dentry->d_lockref.count++;
2063 +               vx_dentry_inc(dentry);
2064                 found = dentry;
2065                 spin_unlock(&dentry->d_lock);
2066                 break;
2067 @@ -3371,6 +3384,7 @@ static enum d_walk_ret d_genocide_kill(v
2068                 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
2069                         dentry->d_flags |= DCACHE_GENOCIDE;
2070                         dentry->d_lockref.count--;
2071 +                       vx_dentry_dec(dentry);
2072                 }
2073         }
2074         return D_WALK_CONTINUE;
2075 diff -NurpP --minimal linux-4.4.115/fs/devpts/inode.c linux-4.4.115-vs2.3.9.7/fs/devpts/inode.c
2076 --- linux-4.4.115/fs/devpts/inode.c     2018-02-10 14:38:45.000000000 +0000
2077 +++ linux-4.4.115-vs2.3.9.7/fs/devpts/inode.c   2018-01-09 16:36:24.000000000 +0000
2078 @@ -27,6 +27,7 @@
2079  #include <linux/parser.h>
2080  #include <linux/fsnotify.h>
2081  #include <linux/seq_file.h>
2082 +#include <linux/vs_base.h>
2083  
2084  #define DEVPTS_DEFAULT_MODE 0600
2085  /*
2086 @@ -38,6 +39,21 @@
2087  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2088  #define PTMX_MINOR     2
2089  
2090 +static int devpts_permission(struct inode *inode, int mask)
2091 +{
2092 +       int ret = -EACCES;
2093 +
2094 +       /* devpts is xid tagged */
2095 +       if (vx_check((vxid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2096 +               ret = generic_permission(inode, mask);
2097 +       return ret;
2098 +}
2099 +
2100 +static struct inode_operations devpts_file_inode_operations = {
2101 +       .permission     = devpts_permission,
2102 +};
2103 +
2104 +
2105  /*
2106   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2107   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2108 @@ -353,6 +369,34 @@ static int devpts_show_options(struct se
2109         return 0;
2110  }
2111  
2112 +static int devpts_filter(struct dentry *de)
2113 +{
2114 +       vxid_t xid = 0;
2115 +
2116 +       /* devpts is xid tagged */
2117 +       if (de && de->d_inode)
2118 +               xid = (vxid_t)i_tag_read(de->d_inode);
2119 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2120 +       else
2121 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2122 +                       de->d_name.len, de->d_name.name);
2123 +#endif
2124 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2125 +}
2126 +
2127 +static int devpts_readdir(struct file * filp, struct dir_context *ctx)
2128 +{
2129 +       return dcache_readdir_filter(filp, ctx, devpts_filter);
2130 +}
2131 +
2132 +static struct file_operations devpts_dir_operations = {
2133 +       .open           = dcache_dir_open,
2134 +       .release        = dcache_dir_close,
2135 +       .llseek         = dcache_dir_lseek,
2136 +       .read           = generic_read_dir,
2137 +       .iterate        = devpts_readdir,
2138 +};
2139 +
2140  static const struct super_operations devpts_sops = {
2141         .statfs         = simple_statfs,
2142         .remount_fs     = devpts_remount,
2143 @@ -397,8 +441,10 @@ devpts_fill_super(struct super_block *s,
2144         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2145         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2146         inode->i_op = &simple_dir_inode_operations;
2147 -       inode->i_fop = &simple_dir_operations;
2148 +       inode->i_fop = &devpts_dir_operations;
2149         set_nlink(inode, 2);
2150 +       /* devpts is xid tagged */
2151 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2152  
2153         s->s_root = d_make_root(inode);
2154         if (s->s_root)
2155 @@ -630,6 +676,9 @@ struct inode *devpts_pty_new(struct pts_
2156         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2157         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2158         init_special_inode(inode, S_IFCHR|opts->mode, device);
2159 +       /* devpts is xid tagged */
2160 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2161 +       inode->i_op = &devpts_file_inode_operations;
2162         inode->i_private = priv;
2163  
2164         sprintf(s, "%d", index);
2165 diff -NurpP --minimal linux-4.4.115/fs/ext2/balloc.c linux-4.4.115-vs2.3.9.7/fs/ext2/balloc.c
2166 --- linux-4.4.115/fs/ext2/balloc.c      2015-04-12 22:12:50.000000000 +0000
2167 +++ linux-4.4.115-vs2.3.9.7/fs/ext2/balloc.c    2018-01-09 16:36:24.000000000 +0000
2168 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2169                         start = 0;
2170                 end = EXT2_BLOCKS_PER_GROUP(sb);
2171         }
2172 -
2173         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2174  
2175  repeat:
2176 diff -NurpP --minimal linux-4.4.115/fs/ext2/ext2.h linux-4.4.115-vs2.3.9.7/fs/ext2/ext2.h
2177 --- linux-4.4.115/fs/ext2/ext2.h        2016-07-05 04:15:07.000000000 +0000
2178 +++ linux-4.4.115-vs2.3.9.7/fs/ext2/ext2.h      2018-01-09 16:36:24.000000000 +0000
2179 @@ -244,8 +244,12 @@ struct ext2_group_desc
2180  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2181  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2182  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2183 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2184  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2185  
2186 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2187 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2188 +
2189  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2190  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2191  
2192 @@ -329,7 +333,8 @@ struct ext2_inode {
2193                         __u16   i_pad1;
2194                         __le16  l_i_uid_high;   /* these 2 fields    */
2195                         __le16  l_i_gid_high;   /* were reserved2[0] */
2196 -                       __u32   l_i_reserved2;
2197 +                       __le16  l_i_tag;        /* Context Tag */
2198 +                       __u16   l_i_reserved2;
2199                 } linux2;
2200                 struct {
2201                         __u8    h_i_frag;       /* Fragment number */
2202 @@ -357,6 +362,7 @@ struct ext2_inode {
2203  #define i_gid_low      i_gid
2204  #define i_uid_high     osd2.linux2.l_i_uid_high
2205  #define i_gid_high     osd2.linux2.l_i_gid_high
2206 +#define i_raw_tag      osd2.linux2.l_i_tag
2207  #define i_reserved2    osd2.linux2.l_i_reserved2
2208  
2209  /*
2210 @@ -389,6 +395,7 @@ struct ext2_inode {
2211  #else
2212  #define EXT2_MOUNT_DAX                 0
2213  #endif
2214 +#define EXT2_MOUNT_TAGGED              0x200000  /* Enable Context Tags */
2215  
2216  
2217  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2218 @@ -776,6 +783,7 @@ extern void ext2_set_inode_flags(struct
2219  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2220  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2221                        u64 start, u64 len);
2222 +extern int ext2_sync_flags(struct inode *, int, int);
2223  
2224  /* ioctl.c */
2225  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2226 diff -NurpP --minimal linux-4.4.115/fs/ext2/file.c linux-4.4.115-vs2.3.9.7/fs/ext2/file.c
2227 --- linux-4.4.115/fs/ext2/file.c        2016-07-05 04:15:07.000000000 +0000
2228 +++ linux-4.4.115-vs2.3.9.7/fs/ext2/file.c      2018-01-09 16:36:24.000000000 +0000
2229 @@ -202,4 +202,5 @@ const struct inode_operations ext2_file_
2230         .get_acl        = ext2_get_acl,
2231         .set_acl        = ext2_set_acl,
2232         .fiemap         = ext2_fiemap,
2233 +       .sync_flags     = ext2_sync_flags,
2234  };
2235 diff -NurpP --minimal linux-4.4.115/fs/ext2/ialloc.c linux-4.4.115-vs2.3.9.7/fs/ext2/ialloc.c
2236 --- linux-4.4.115/fs/ext2/ialloc.c      2016-07-05 04:12:30.000000000 +0000
2237 +++ linux-4.4.115-vs2.3.9.7/fs/ext2/ialloc.c    2018-01-09 16:36:24.000000000 +0000
2238 @@ -17,6 +17,7 @@
2239  #include <linux/backing-dev.h>
2240  #include <linux/buffer_head.h>
2241  #include <linux/random.h>
2242 +#include <linux/vs_tag.h>
2243  #include "ext2.h"
2244  #include "xattr.h"
2245  #include "acl.h"
2246 @@ -546,6 +547,7 @@ got:
2247                 inode->i_mode = mode;
2248                 inode->i_uid = current_fsuid();
2249                 inode->i_gid = dir->i_gid;
2250 +               i_tag_write(inode, dx_current_fstag(sb));
2251         } else
2252                 inode_init_owner(inode, dir, mode);
2253  
2254 diff -NurpP --minimal linux-4.4.115/fs/ext2/inode.c linux-4.4.115-vs2.3.9.7/fs/ext2/inode.c
2255 --- linux-4.4.115/fs/ext2/inode.c       2016-07-05 04:15:07.000000000 +0000
2256 +++ linux-4.4.115-vs2.3.9.7/fs/ext2/inode.c     2018-01-09 16:36:24.000000000 +0000
2257 @@ -33,6 +33,7 @@
2258  #include <linux/fiemap.h>
2259  #include <linux/namei.h>
2260  #include <linux/uio.h>
2261 +#include <linux/vs_tag.h>
2262  #include "ext2.h"
2263  #include "acl.h"
2264  #include "xattr.h"
2265 @@ -1188,7 +1189,7 @@ static void ext2_truncate_blocks(struct
2266                 return;
2267         if (ext2_inode_is_fast_symlink(inode))
2268                 return;
2269 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2270 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2271                 return;
2272  
2273         dax_sem_down_write(EXT2_I(inode));
2274 @@ -1284,39 +1285,62 @@ void ext2_set_inode_flags(struct inode *
2275  {
2276         unsigned int flags = EXT2_I(inode)->i_flags;
2277  
2278 -       inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME |
2279 -                               S_DIRSYNC | S_DAX);
2280 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK | S_DAX |
2281 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2282 +
2283 +       if (flags & EXT2_IMMUTABLE_FL)
2284 +               inode->i_flags |= S_IMMUTABLE;
2285 +       if (flags & EXT2_IXUNLINK_FL)
2286 +               inode->i_flags |= S_IXUNLINK;
2287 +
2288         if (flags & EXT2_SYNC_FL)
2289                 inode->i_flags |= S_SYNC;
2290         if (flags & EXT2_APPEND_FL)
2291                 inode->i_flags |= S_APPEND;
2292 -       if (flags & EXT2_IMMUTABLE_FL)
2293 -               inode->i_flags |= S_IMMUTABLE;
2294         if (flags & EXT2_NOATIME_FL)
2295                 inode->i_flags |= S_NOATIME;
2296         if (flags & EXT2_DIRSYNC_FL)
2297                 inode->i_flags |= S_DIRSYNC;
2298         if (test_opt(inode->i_sb, DAX))
2299                 inode->i_flags |= S_DAX;
2300 +
2301 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2302 +
2303 +       if (flags & EXT2_BARRIER_FL)
2304 +               inode->i_vflags |= V_BARRIER;
2305 +       if (flags & EXT2_COW_FL)
2306 +               inode->i_vflags |= V_COW;
2307  }
2308  
2309  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2310  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2311  {
2312         unsigned int flags = ei->vfs_inode.i_flags;
2313 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2314 +
2315 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2316 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2317 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2318 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2319 +
2320 +       if (flags & S_IMMUTABLE)
2321 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2322 +       if (flags & S_IXUNLINK)
2323 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2324  
2325 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2326 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2327         if (flags & S_SYNC)
2328                 ei->i_flags |= EXT2_SYNC_FL;
2329         if (flags & S_APPEND)
2330                 ei->i_flags |= EXT2_APPEND_FL;
2331 -       if (flags & S_IMMUTABLE)
2332 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2333         if (flags & S_NOATIME)
2334                 ei->i_flags |= EXT2_NOATIME_FL;
2335         if (flags & S_DIRSYNC)
2336                 ei->i_flags |= EXT2_DIRSYNC_FL;
2337 +
2338 +       if (vflags & V_BARRIER)
2339 +               ei->i_flags |= EXT2_BARRIER_FL;
2340 +       if (vflags & V_COW)
2341 +               ei->i_flags |= EXT2_COW_FL;
2342  }
2343  
2344  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2345 @@ -1352,8 +1376,10 @@ struct inode *ext2_iget (struct super_bl
2346                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2347                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2348         }
2349 -       i_uid_write(inode, i_uid);
2350 -       i_gid_write(inode, i_gid);
2351 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2352 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2353 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2354 +               le16_to_cpu(raw_inode->i_raw_tag)));
2355         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2356         inode->i_size = le32_to_cpu(raw_inode->i_size);
2357         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2358 @@ -1449,8 +1475,10 @@ static int __ext2_write_inode(struct ino
2359         struct ext2_inode_info *ei = EXT2_I(inode);
2360         struct super_block *sb = inode->i_sb;
2361         ino_t ino = inode->i_ino;
2362 -       uid_t uid = i_uid_read(inode);
2363 -       gid_t gid = i_gid_read(inode);
2364 +       uid_t uid = from_kuid(&init_user_ns,
2365 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2366 +       gid_t gid = from_kgid(&init_user_ns,
2367 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2368         struct buffer_head * bh;
2369         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2370         int n;
2371 @@ -1486,6 +1514,9 @@ static int __ext2_write_inode(struct ino
2372                 raw_inode->i_uid_high = 0;
2373                 raw_inode->i_gid_high = 0;
2374         }
2375 +#ifdef CONFIG_TAGGING_INTERN
2376 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2377 +#endif
2378         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2379         raw_inode->i_size = cpu_to_le32(inode->i_size);
2380         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2381 @@ -1569,7 +1600,8 @@ int ext2_setattr(struct dentry *dentry,
2382                         return error;
2383         }
2384         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2385 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2386 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2387 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2388                 error = dquot_transfer(inode, iattr);
2389                 if (error)
2390                         return error;
2391 diff -NurpP --minimal linux-4.4.115/fs/ext2/ioctl.c linux-4.4.115-vs2.3.9.7/fs/ext2/ioctl.c
2392 --- linux-4.4.115/fs/ext2/ioctl.c       2015-04-12 22:12:50.000000000 +0000
2393 +++ linux-4.4.115-vs2.3.9.7/fs/ext2/ioctl.c     2018-01-09 16:36:24.000000000 +0000
2394 @@ -17,6 +17,16 @@
2395  #include <asm/uaccess.h>
2396  
2397  
2398 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2399 +{
2400 +       inode->i_flags = flags;
2401 +       inode->i_vflags = vflags;
2402 +       ext2_get_inode_flags(EXT2_I(inode));
2403 +       inode->i_ctime = CURRENT_TIME_SEC;
2404 +       mark_inode_dirty(inode);
2405 +       return 0;
2406 +}
2407 +
2408  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2409  {
2410         struct inode *inode = file_inode(filp);
2411 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2412  
2413                 flags = ext2_mask_flags(inode->i_mode, flags);
2414  
2415 +               if (IS_BARRIER(inode)) {
2416 +                       vxwprintk_task(1, "messing with the barrier.");
2417 +                       return -EACCES;
2418 +               }
2419 +
2420                 mutex_lock(&inode->i_mutex);
2421                 /* Is it quota file? Do not allow user to mess with it */
2422                 if (IS_NOQUOTA(inode)) {
2423 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2424                  *
2425                  * This test looks nicer. Thanks to Pauline Middelink
2426                  */
2427 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2428 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2429 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2430 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2431                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2432                                 mutex_unlock(&inode->i_mutex);
2433                                 ret = -EPERM;
2434 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2435                         }
2436                 }
2437  
2438 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2439 +               flags &= EXT2_FL_USER_MODIFIABLE;
2440                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2441                 ei->i_flags = flags;
2442  
2443 diff -NurpP --minimal linux-4.4.115/fs/ext2/namei.c linux-4.4.115-vs2.3.9.7/fs/ext2/namei.c
2444 --- linux-4.4.115/fs/ext2/namei.c       2016-07-05 04:15:07.000000000 +0000
2445 +++ linux-4.4.115-vs2.3.9.7/fs/ext2/namei.c     2018-01-09 16:36:24.000000000 +0000
2446 @@ -32,6 +32,7 @@
2447  
2448  #include <linux/pagemap.h>
2449  #include <linux/quotaops.h>
2450 +#include <linux/vs_tag.h>
2451  #include "ext2.h"
2452  #include "xattr.h"
2453  #include "acl.h"
2454 @@ -72,6 +73,7 @@ static struct dentry *ext2_lookup(struct
2455                                         (unsigned long) ino);
2456                         return ERR_PTR(-EIO);
2457                 }
2458 +               dx_propagate_tag(nd, inode);
2459         }
2460         return d_splice_alias(inode, dentry);
2461  }
2462 @@ -446,6 +448,7 @@ const struct inode_operations ext2_speci
2463         .removexattr    = generic_removexattr,
2464  #endif
2465         .setattr        = ext2_setattr,
2466 +       .sync_flags     = ext2_sync_flags,
2467         .get_acl        = ext2_get_acl,
2468         .set_acl        = ext2_set_acl,
2469  };
2470 diff -NurpP --minimal linux-4.4.115/fs/ext2/super.c linux-4.4.115-vs2.3.9.7/fs/ext2/super.c
2471 --- linux-4.4.115/fs/ext2/super.c       2016-07-05 04:15:07.000000000 +0000
2472 +++ linux-4.4.115-vs2.3.9.7/fs/ext2/super.c     2018-01-09 16:36:24.000000000 +0000
2473 @@ -408,7 +408,8 @@ enum {
2474         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2475         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2476         Opt_acl, Opt_noacl, Opt_xip, Opt_dax, Opt_ignore, Opt_err, Opt_quota,
2477 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2478 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2479 +       Opt_tag, Opt_notag, Opt_tagid
2480  };
2481  
2482  static const match_table_t tokens = {
2483 @@ -436,6 +437,9 @@ static const match_table_t tokens = {
2484         {Opt_acl, "acl"},
2485         {Opt_noacl, "noacl"},
2486         {Opt_xip, "xip"},
2487 +       {Opt_tag, "tag"},
2488 +       {Opt_notag, "notag"},
2489 +       {Opt_tagid, "tagid=%u"},
2490         {Opt_dax, "dax"},
2491         {Opt_grpquota, "grpquota"},
2492         {Opt_ignore, "noquota"},
2493 @@ -520,6 +524,20 @@ static int parse_options(char *options,
2494                 case Opt_nouid32:
2495                         set_opt (sbi->s_mount_opt, NO_UID32);
2496                         break;
2497 +#ifndef CONFIG_TAGGING_NONE
2498 +               case Opt_tag:
2499 +                       set_opt (sbi->s_mount_opt, TAGGED);
2500 +                       break;
2501 +               case Opt_notag:
2502 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2503 +                       break;
2504 +#endif
2505 +#ifdef CONFIG_PROPAGATE
2506 +               case Opt_tagid:
2507 +                       /* use args[0] */
2508 +                       set_opt (sbi->s_mount_opt, TAGGED);
2509 +                       break;
2510 +#endif
2511                 case Opt_nocheck:
2512                         clear_opt (sbi->s_mount_opt, CHECK);
2513                         break;
2514 @@ -884,6 +902,8 @@ static int ext2_fill_super(struct super_
2515         if (!parse_options((char *) data, sb))
2516                 goto failed_mount;
2517  
2518 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2519 +               sb->s_flags |= MS_TAGGED;
2520         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2521                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2522                  MS_POSIXACL : 0);
2523 @@ -1294,6 +1314,14 @@ static int ext2_remount (struct super_bl
2524                 err = -EINVAL;
2525                 goto restore_opts;
2526         }
2527 +
2528 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2529 +               !(sb->s_flags & MS_TAGGED)) {
2530 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2531 +                      sb->s_id);
2532 +               err = -EINVAL;
2533 +               goto restore_opts;
2534 +       }
2535  
2536         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2537                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2538 diff -NurpP --minimal linux-4.4.115/fs/ext4/ext4.h linux-4.4.115-vs2.3.9.7/fs/ext4/ext4.h
2539 --- linux-4.4.115/fs/ext4/ext4.h        2018-02-10 14:38:45.000000000 +0000
2540 +++ linux-4.4.115-vs2.3.9.7/fs/ext4/ext4.h      2018-01-09 17:33:10.000000000 +0000
2541 @@ -375,8 +375,11 @@ struct flex_groups {
2542  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2543  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2544  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2545 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2546 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2547  #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data. */
2548  #define EXT4_PROJINHERIT_FL            0x20000000 /* Create with parents projid */
2549 +#define EXT4_COW_FL                    0x40000000 /* Copy on Write marker */
2550  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2551  
2552  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2553 @@ -674,7 +677,7 @@ struct ext4_inode {
2554                         __le16  l_i_uid_high;   /* these 2 fields */
2555                         __le16  l_i_gid_high;   /* were reserved2[0] */
2556                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2557 -                       __le16  l_i_reserved;
2558 +                       __le16  l_i_tag;        /* Context Tag */
2559                 } linux2;
2560                 struct {
2561                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
2562 @@ -831,6 +834,7 @@ do {                                                                               \
2563  #define i_gid_low      i_gid
2564  #define i_uid_high     osd2.linux2.l_i_uid_high
2565  #define i_gid_high     osd2.linux2.l_i_gid_high
2566 +#define i_raw_tag      osd2.linux2.l_i_tag
2567  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
2568  
2569  #elif defined(__GNU__)
2570 @@ -1068,6 +1072,7 @@ struct ext4_inode_info {
2571  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
2572  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
2573  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
2574 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
2575  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
2576  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
2577  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2578 @@ -2501,6 +2506,7 @@ extern int ext4_punch_hole(struct inode
2579  extern int ext4_truncate_restart_trans(handle_t *, struct inode *, int nblocks);
2580  extern void ext4_set_inode_flags(struct inode *);
2581  extern void ext4_get_inode_flags(struct ext4_inode_info *);
2582 +extern int ext4_sync_flags(struct inode *, int, int);
2583  extern int ext4_alloc_da_blocks(struct inode *inode);
2584  extern void ext4_set_aops(struct inode *inode);
2585  extern int ext4_writepage_trans_blocks(struct inode *);
2586 diff -NurpP --minimal linux-4.4.115/fs/ext4/file.c linux-4.4.115-vs2.3.9.7/fs/ext4/file.c
2587 --- linux-4.4.115/fs/ext4/file.c        2018-02-10 14:38:45.000000000 +0000
2588 +++ linux-4.4.115-vs2.3.9.7/fs/ext4/file.c      2018-01-09 16:36:31.000000000 +0000
2589 @@ -749,5 +749,6 @@ const struct inode_operations ext4_file_
2590         .get_acl        = ext4_get_acl,
2591         .set_acl        = ext4_set_acl,
2592         .fiemap         = ext4_fiemap,
2593 +       .sync_flags     = ext4_sync_flags,
2594  };
2595  
2596 diff -NurpP --minimal linux-4.4.115/fs/ext4/ialloc.c linux-4.4.115-vs2.3.9.7/fs/ext4/ialloc.c
2597 --- linux-4.4.115/fs/ext4/ialloc.c      2018-02-10 14:38:45.000000000 +0000
2598 +++ linux-4.4.115-vs2.3.9.7/fs/ext4/ialloc.c    2018-01-09 16:36:31.000000000 +0000
2599 @@ -21,6 +21,7 @@
2600  #include <linux/random.h>
2601  #include <linux/bitops.h>
2602  #include <linux/blkdev.h>
2603 +#include <linux/vs_tag.h>
2604  #include <asm/byteorder.h>
2605  
2606  #include "ext4.h"
2607 @@ -799,6 +800,7 @@ struct inode *__ext4_new_inode(handle_t
2608                 inode->i_mode = mode;
2609                 inode->i_uid = current_fsuid();
2610                 inode->i_gid = dir->i_gid;
2611 +               i_tag_write(inode, dx_current_fstag(sb));
2612         } else
2613                 inode_init_owner(inode, dir, mode);
2614         err = dquot_initialize(inode);
2615 diff -NurpP --minimal linux-4.4.115/fs/ext4/inode.c linux-4.4.115-vs2.3.9.7/fs/ext4/inode.c
2616 --- linux-4.4.115/fs/ext4/inode.c       2018-02-10 14:38:45.000000000 +0000
2617 +++ linux-4.4.115-vs2.3.9.7/fs/ext4/inode.c     2018-01-09 16:36:31.000000000 +0000
2618 @@ -37,6 +37,7 @@
2619  #include <linux/printk.h>
2620  #include <linux/slab.h>
2621  #include <linux/bitops.h>
2622 +#include <linux/vs_tag.h>
2623  
2624  #include "ext4_jbd2.h"
2625  #include "xattr.h"
2626 @@ -4128,12 +4129,15 @@ void ext4_set_inode_flags(struct inode *
2627         unsigned int flags = EXT4_I(inode)->i_flags;
2628         unsigned int new_fl = 0;
2629  
2630 +       if (flags & EXT4_IMMUTABLE_FL)
2631 +               new_fl |= S_IMMUTABLE;
2632 +       if (flags & EXT4_IXUNLINK_FL)
2633 +               new_fl |= S_IXUNLINK;
2634 +
2635         if (flags & EXT4_SYNC_FL)
2636                 new_fl |= S_SYNC;
2637         if (flags & EXT4_APPEND_FL)
2638                 new_fl |= S_APPEND;
2639 -       if (flags & EXT4_IMMUTABLE_FL)
2640 -               new_fl |= S_IMMUTABLE;
2641         if (flags & EXT4_NOATIME_FL)
2642                 new_fl |= S_NOATIME;
2643         if (flags & EXT4_DIRSYNC_FL)
2644 @@ -4141,31 +4145,52 @@ void ext4_set_inode_flags(struct inode *
2645         if (test_opt(inode->i_sb, DAX))
2646                 new_fl |= S_DAX;
2647         inode_set_flags(inode, new_fl,
2648 -                       S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_DAX);
2649 +               S_IXUNLINK | S_IMMUTABLE | S_DAX |
2650 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2651 +
2652 +       new_fl = 0;
2653 +       if (flags & EXT4_BARRIER_FL)
2654 +               new_fl |= V_BARRIER;
2655 +       if (flags & EXT4_COW_FL)
2656 +               new_fl |= V_COW;
2657 +
2658 +       set_mask_bits(&inode->i_vflags,
2659 +               V_BARRIER | V_COW, new_fl);
2660  }
2661  
2662  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2663  void ext4_get_inode_flags(struct ext4_inode_info *ei)
2664  {
2665 -       unsigned int vfs_fl;
2666 +       unsigned int vfs_fl, vfs_vf;
2667         unsigned long old_fl, new_fl;
2668  
2669         do {
2670                 vfs_fl = ei->vfs_inode.i_flags;
2671 +               vfs_vf = ei->vfs_inode.i_vflags;
2672                 old_fl = ei->i_flags;
2673                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2674                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2675 -                               EXT4_DIRSYNC_FL);
2676 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2677 +                               EXT4_COW_FL);
2678 +
2679 +               if (vfs_fl & S_IMMUTABLE)
2680 +                       new_fl |= EXT4_IMMUTABLE_FL;
2681 +               if (vfs_fl & S_IXUNLINK)
2682 +                       new_fl |= EXT4_IXUNLINK_FL;
2683 +
2684                 if (vfs_fl & S_SYNC)
2685                         new_fl |= EXT4_SYNC_FL;
2686                 if (vfs_fl & S_APPEND)
2687                         new_fl |= EXT4_APPEND_FL;
2688 -               if (vfs_fl & S_IMMUTABLE)
2689 -                       new_fl |= EXT4_IMMUTABLE_FL;
2690                 if (vfs_fl & S_NOATIME)
2691                         new_fl |= EXT4_NOATIME_FL;
2692                 if (vfs_fl & S_DIRSYNC)
2693                         new_fl |= EXT4_DIRSYNC_FL;
2694 +
2695 +               if (vfs_vf & V_BARRIER)
2696 +                       new_fl |= EXT4_BARRIER_FL;
2697 +               if (vfs_vf & V_COW)
2698 +                       new_fl |= EXT4_COW_FL;
2699         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
2700  }
2701  
2702 @@ -4269,8 +4294,10 @@ struct inode *ext4_iget(struct super_blo
2703                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2704                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2705         }
2706 -       i_uid_write(inode, i_uid);
2707 -       i_gid_write(inode, i_gid);
2708 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2709 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2710 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2711 +               le16_to_cpu(raw_inode->i_raw_tag)));
2712         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2713  
2714         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
2715 @@ -4583,8 +4610,10 @@ static int ext4_do_update_inode(handle_t
2716  
2717         ext4_get_inode_flags(ei);
2718         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2719 -       i_uid = i_uid_read(inode);
2720 -       i_gid = i_gid_read(inode);
2721 +       i_uid = from_kuid(&init_user_ns,
2722 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2723 +       i_gid = from_kgid(&init_user_ns,
2724 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2725         if (!(test_opt(inode->i_sb, NO_UID32))) {
2726                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2727                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2728 @@ -4607,6 +4636,9 @@ static int ext4_do_update_inode(handle_t
2729                 raw_inode->i_uid_high = 0;
2730                 raw_inode->i_gid_high = 0;
2731         }
2732 +#ifdef CONFIG_TAGGING_INTERN
2733 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2734 +#endif
2735         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2736  
2737         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
2738 @@ -4852,7 +4884,8 @@ int ext4_setattr(struct dentry *dentry,
2739                         return error;
2740         }
2741         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2742 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2743 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2744 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2745                 handle_t *handle;
2746  
2747                 /* (user+group)*(old+new) structure, inode write (sb,
2748 @@ -4875,6 +4908,8 @@ int ext4_setattr(struct dentry *dentry,
2749                         inode->i_uid = attr->ia_uid;
2750                 if (attr->ia_valid & ATTR_GID)
2751                         inode->i_gid = attr->ia_gid;
2752 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2753 +                       inode->i_tag = attr->ia_tag;
2754                 error = ext4_mark_inode_dirty(handle, inode);
2755                 ext4_journal_stop(handle);
2756         }
2757 diff -NurpP --minimal linux-4.4.115/fs/ext4/ioctl.c linux-4.4.115-vs2.3.9.7/fs/ext4/ioctl.c
2758 --- linux-4.4.115/fs/ext4/ioctl.c       2018-02-10 14:38:45.000000000 +0000
2759 +++ linux-4.4.115-vs2.3.9.7/fs/ext4/ioctl.c     2018-01-09 16:36:31.000000000 +0000
2760 @@ -14,6 +14,7 @@
2761  #include <linux/mount.h>
2762  #include <linux/file.h>
2763  #include <linux/random.h>
2764 +#include <linux/vs_tag.h>
2765  #include <asm/uaccess.h>
2766  #include "ext4_jbd2.h"
2767  #include "ext4.h"
2768 @@ -202,6 +203,33 @@ static int uuid_is_zero(__u8 u[16])
2769         return 1;
2770  }
2771  
2772 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
2773 +{
2774 +       handle_t *handle = NULL;
2775 +       struct ext4_iloc iloc;
2776 +       int err;
2777 +
2778 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
2779 +       if (IS_ERR(handle))
2780 +               return PTR_ERR(handle);
2781 +
2782 +       if (IS_SYNC(inode))
2783 +               ext4_handle_sync(handle);
2784 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
2785 +       if (err)
2786 +               goto flags_err;
2787 +
2788 +       inode->i_flags = flags;
2789 +       inode->i_vflags = vflags;
2790 +       ext4_get_inode_flags(EXT4_I(inode));
2791 +       inode->i_ctime = ext4_current_time(inode);
2792 +
2793 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
2794 +flags_err:
2795 +       ext4_journal_stop(handle);
2796 +       return err;
2797 +}
2798 +
2799  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2800  {
2801         struct inode *inode = file_inode(filp);
2802 @@ -235,6 +263,11 @@ long ext4_ioctl(struct file *filp, unsig
2803  
2804                 flags = ext4_mask_flags(inode->i_mode, flags);
2805  
2806 +               if (IS_BARRIER(inode)) {
2807 +                       vxwprintk_task(1, "messing with the barrier.");
2808 +                       return -EACCES;
2809 +               }
2810 +
2811                 err = -EPERM;
2812                 mutex_lock(&inode->i_mutex);
2813                 /* Is it quota file? Do not allow user to mess with it */
2814 @@ -252,7 +285,9 @@ long ext4_ioctl(struct file *filp, unsig
2815                  *
2816                  * This test looks nicer. Thanks to Pauline Middelink
2817                  */
2818 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
2819 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
2820 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
2821 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
2822                         if (!capable(CAP_LINUX_IMMUTABLE))
2823                                 goto flags_out;
2824                 }
2825 diff -NurpP --minimal linux-4.4.115/fs/ext4/namei.c linux-4.4.115-vs2.3.9.7/fs/ext4/namei.c
2826 --- linux-4.4.115/fs/ext4/namei.c       2018-02-10 14:38:46.000000000 +0000
2827 +++ linux-4.4.115-vs2.3.9.7/fs/ext4/namei.c     2018-01-09 16:36:31.000000000 +0000
2828 @@ -33,6 +33,7 @@
2829  #include <linux/quotaops.h>
2830  #include <linux/buffer_head.h>
2831  #include <linux/bio.h>
2832 +#include <linux/vs_tag.h>
2833  #include "ext4.h"
2834  #include "ext4_jbd2.h"
2835  
2836 @@ -1444,6 +1445,7 @@ restart:
2837                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
2838                                                     1, &bh);
2839                         }
2840 +               dx_propagate_tag(nd, inode);
2841                 }
2842                 if ((bh = bh_use[ra_ptr++]) == NULL)
2843                         goto next;
2844 @@ -3881,6 +3883,7 @@ const struct inode_operations ext4_dir_i
2845         .get_acl        = ext4_get_acl,
2846         .set_acl        = ext4_set_acl,
2847         .fiemap         = ext4_fiemap,
2848 +       .sync_flags     = ext4_sync_flags,
2849  };
2850  
2851  const struct inode_operations ext4_special_inode_operations = {
2852 diff -NurpP --minimal linux-4.4.115/fs/ext4/super.c linux-4.4.115-vs2.3.9.7/fs/ext4/super.c
2853 --- linux-4.4.115/fs/ext4/super.c       2018-02-10 14:38:46.000000000 +0000
2854 +++ linux-4.4.115-vs2.3.9.7/fs/ext4/super.c     2018-01-09 16:36:32.000000000 +0000
2855 @@ -1165,6 +1165,7 @@ enum {
2856         Opt_dioread_nolock, Opt_dioread_lock,
2857         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
2858         Opt_max_dir_size_kb, Opt_nojournal_checksum,
2859 +       Opt_tag, Opt_notag, Opt_tagid
2860  };
2861  
2862  static const match_table_t tokens = {
2863 @@ -1250,6 +1251,9 @@ static const match_table_t tokens = {
2864         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
2865         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
2866         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
2867 +       {Opt_tag, "tag"},
2868 +       {Opt_notag, "notag"},
2869 +       {Opt_tagid, "tagid=%u"},
2870         {Opt_err, NULL},
2871  };
2872  
2873 @@ -1492,6 +1496,20 @@ static int handle_mount_opt(struct super
2874         case Opt_nolazytime:
2875                 sb->s_flags &= ~MS_LAZYTIME;
2876                 return 1;
2877 +#ifndef CONFIG_TAGGING_NONE
2878 +       case Opt_tag:
2879 +               set_opt(sb, TAGGED);
2880 +               return 1;
2881 +       case Opt_notag:
2882 +               clear_opt(sb, TAGGED);
2883 +               return 1;
2884 +#endif
2885 +#ifdef CONFIG_PROPAGATE
2886 +       case Opt_tagid:
2887 +               /* use args[0] */
2888 +               set_opt(sb, TAGGED);
2889 +               return 1;
2890 +#endif
2891         }
2892  
2893         for (m = ext4_mount_opts; m->token != Opt_err; m++)
2894 @@ -3379,6 +3397,9 @@ static int ext4_fill_super(struct super_
2895                 sb->s_iflags |= SB_I_CGROUPWB;
2896         }
2897  
2898 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
2899 +               sb->s_flags |= MS_TAGGED;
2900 +
2901         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2902                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2903  
2904 @@ -4727,6 +4748,14 @@ static int ext4_remount(struct super_blo
2905         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
2906                 ext4_abort(sb, "Abort forced by user");
2907  
2908 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
2909 +               !(sb->s_flags & MS_TAGGED)) {
2910 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
2911 +                       sb->s_id);
2912 +               err = -EINVAL;
2913 +               goto restore_opts;
2914 +       }
2915 +
2916         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2917                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2918  
2919 diff -NurpP --minimal linux-4.4.115/fs/fcntl.c linux-4.4.115-vs2.3.9.7/fs/fcntl.c
2920 --- linux-4.4.115/fs/fcntl.c    2018-02-10 14:38:46.000000000 +0000
2921 +++ linux-4.4.115-vs2.3.9.7/fs/fcntl.c  2018-02-10 15:16:50.000000000 +0000
2922 @@ -22,6 +22,7 @@
2923  #include <linux/pid_namespace.h>
2924  #include <linux/user_namespace.h>
2925  #include <linux/shmem_fs.h>
2926 +#include <linux/vs_limit.h>
2927  
2928  #include <asm/poll.h>
2929  #include <asm/siginfo.h>
2930 @@ -389,6 +390,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
2931  
2932         if (!f.file)
2933                 goto out;
2934 +       if (!vx_files_avail(1))
2935 +               goto out;
2936  
2937         if (unlikely(f.file->f_mode & FMODE_PATH)) {
2938                 if (!check_fcntl_cmd(cmd))
2939 diff -NurpP --minimal linux-4.4.115/fs/file.c linux-4.4.115-vs2.3.9.7/fs/file.c
2940 --- linux-4.4.115/fs/file.c     2016-07-05 04:15:07.000000000 +0000
2941 +++ linux-4.4.115-vs2.3.9.7/fs/file.c   2018-01-09 16:36:32.000000000 +0000
2942 @@ -22,6 +22,7 @@
2943  #include <linux/spinlock.h>
2944  #include <linux/rcupdate.h>
2945  #include <linux/workqueue.h>
2946 +#include <linux/vs_limit.h>
2947  
2948  int sysctl_nr_open __read_mostly = 1024*1024;
2949  int sysctl_nr_open_min = BITS_PER_LONG;
2950 @@ -356,6 +357,8 @@ struct files_struct *dup_fd(struct files
2951                 struct file *f = *old_fds++;
2952                 if (f) {
2953                         get_file(f);
2954 +                       /* TODO: sum it first for check and performance */
2955 +                       vx_openfd_inc(open_files - i);
2956                 } else {
2957                         /*
2958                          * The fd may be claimed in the fd bitmap but not yet
2959 @@ -405,9 +408,11 @@ static struct fdtable *close_files(struc
2960                                         filp_close(file, files);
2961                                         cond_resched_rcu_qs();
2962                                 }
2963 +                               vx_openfd_dec(i);
2964                         }
2965                         i++;
2966                         set >>= 1;
2967 +                       cond_resched();
2968                 }
2969         }
2970  
2971 @@ -538,6 +543,7 @@ repeat:
2972         else
2973                 __clear_close_on_exec(fd, fdt);
2974         error = fd;
2975 +       vx_openfd_inc(fd);
2976  #if 1
2977         /* Sanity check */
2978         if (rcu_access_pointer(fdt->fd[fd]) != NULL) {
2979 @@ -568,6 +574,7 @@ static void __put_unused_fd(struct files
2980         __clear_open_fd(fd, fdt);
2981         if (fd < files->next_fd)
2982                 files->next_fd = fd;
2983 +       vx_openfd_dec(fd);
2984  }
2985  
2986  void put_unused_fd(unsigned int fd)
2987 @@ -850,6 +857,8 @@ __releases(&files->file_lock)
2988  
2989         if (tofree)
2990                 filp_close(tofree, files);
2991 +       else
2992 +               vx_openfd_inc(fd);      /* fd was unused */
2993  
2994         return fd;
2995  
2996 diff -NurpP --minimal linux-4.4.115/fs/file_table.c linux-4.4.115-vs2.3.9.7/fs/file_table.c
2997 --- linux-4.4.115/fs/file_table.c       2015-10-29 09:21:35.000000000 +0000
2998 +++ linux-4.4.115-vs2.3.9.7/fs/file_table.c     2018-01-09 17:25:51.000000000 +0000
2999 @@ -26,6 +26,8 @@
3000  #include <linux/task_work.h>
3001  #include <linux/ima.h>
3002  #include <linux/swap.h>
3003 +#include <linux/vs_limit.h>
3004 +#include <linux/vs_context.h>
3005  
3006  #include <linux/atomic.h>
3007  
3008 @@ -137,6 +139,8 @@ struct file *get_empty_filp(void)
3009         mutex_init(&f->f_pos_lock);
3010         eventpoll_init_file(f);
3011         /* f->f_version: 0 */
3012 +       f->f_xid = vx_current_xid();
3013 +       vx_files_inc(f);
3014         return f;
3015  
3016  over:
3017 @@ -219,6 +223,8 @@ static void __fput(struct file *file)
3018                 put_write_access(inode);
3019                 __mnt_drop_write(mnt);
3020         }
3021 +       vx_files_dec(file);
3022 +       file->f_xid = 0;
3023         file->f_path.dentry = NULL;
3024         file->f_path.mnt = NULL;
3025         file->f_inode = NULL;
3026 @@ -305,6 +311,8 @@ void put_filp(struct file *file)
3027  {
3028         if (atomic_long_dec_and_test(&file->f_count)) {
3029                 security_file_free(file);
3030 +               vx_files_dec(file);
3031 +               file->f_xid = 0;
3032                 file_free(file);
3033         }
3034  }
3035 diff -NurpP --minimal linux-4.4.115/fs/fs_struct.c linux-4.4.115-vs2.3.9.7/fs/fs_struct.c
3036 --- linux-4.4.115/fs/fs_struct.c        2015-04-12 22:12:50.000000000 +0000
3037 +++ linux-4.4.115-vs2.3.9.7/fs/fs_struct.c      2018-01-09 16:36:32.000000000 +0000
3038 @@ -4,6 +4,7 @@
3039  #include <linux/path.h>
3040  #include <linux/slab.h>
3041  #include <linux/fs_struct.h>
3042 +#include <linux/vserver/global.h>
3043  #include "internal.h"
3044  
3045  /*
3046 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3047  {
3048         path_put(&fs->root);
3049         path_put(&fs->pwd);
3050 +       atomic_dec(&vs_global_fs);
3051         kmem_cache_free(fs_cachep, fs);
3052  }
3053  
3054 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3055                 fs->pwd = old->pwd;
3056                 path_get(&fs->pwd);
3057                 spin_unlock(&old->lock);
3058 +               atomic_inc(&vs_global_fs);
3059         }
3060         return fs;
3061  }
3062 diff -NurpP --minimal linux-4.4.115/fs/gfs2/file.c linux-4.4.115-vs2.3.9.7/fs/gfs2/file.c
3063 --- linux-4.4.115/fs/gfs2/file.c        2018-02-10 14:38:46.000000000 +0000
3064 +++ linux-4.4.115-vs2.3.9.7/fs/gfs2/file.c      2018-01-09 17:23:53.000000000 +0000
3065 @@ -137,6 +137,9 @@ static const u32 fsflags_to_gfs2[32] = {
3066         [12] = GFS2_DIF_EXHASH,
3067         [14] = GFS2_DIF_INHERIT_JDATA,
3068         [17] = GFS2_DIF_TOPDIR,
3069 +       [27] = GFS2_DIF_IXUNLINK,
3070 +       [26] = GFS2_DIF_BARRIER,
3071 +       [29] = GFS2_DIF_COW,
3072  };
3073  
3074  static const u32 gfs2_to_fsflags[32] = {
3075 @@ -147,6 +150,9 @@ static const u32 gfs2_to_fsflags[32] = {
3076         [gfs2fl_ExHash] = FS_INDEX_FL,
3077         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3078         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3079 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3080 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3081 +       [gfs2fl_Cow] = FS_COW_FL,
3082  };
3083  
3084  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3085 @@ -177,12 +183,17 @@ void gfs2_set_inode_flags(struct inode *
3086  {
3087         struct gfs2_inode *ip = GFS2_I(inode);
3088         unsigned int flags = inode->i_flags;
3089 +       unsigned int vflags = inode->i_vflags;
3090  
3091 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3092 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3093 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3094 +
3095         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3096                 flags |= S_NOSEC;
3097         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3098                 flags |= S_IMMUTABLE;
3099 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3100 +               flags |= S_IXUNLINK;
3101         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3102                 flags |= S_APPEND;
3103         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3104 @@ -190,6 +201,43 @@ void gfs2_set_inode_flags(struct inode *
3105         if (ip->i_diskflags & GFS2_DIF_SYNC)
3106                 flags |= S_SYNC;
3107         inode->i_flags = flags;
3108 +
3109 +       vflags &= ~(V_BARRIER | V_COW);
3110 +
3111 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3112 +               vflags |= V_BARRIER;
3113 +       if (ip->i_diskflags & GFS2_DIF_COW)
3114 +               vflags |= V_COW;
3115 +       inode->i_vflags = vflags;
3116 +}
3117 +
3118 +void gfs2_get_inode_flags(struct inode *inode)
3119 +{
3120 +       struct gfs2_inode *ip = GFS2_I(inode);
3121 +       unsigned int flags = inode->i_flags;
3122 +       unsigned int vflags = inode->i_vflags;
3123 +
3124 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3125 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3126 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3127 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3128 +
3129 +       if (flags & S_IMMUTABLE)
3130 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3131 +       if (flags & S_IXUNLINK)
3132 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3133 +
3134 +       if (flags & S_APPEND)
3135 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3136 +       if (flags & S_NOATIME)
3137 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3138 +       if (flags & S_SYNC)
3139 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3140 +
3141 +       if (vflags & V_BARRIER)
3142 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3143 +       if (vflags & V_COW)
3144 +               ip->i_diskflags |= GFS2_DIF_COW;
3145  }
3146  
3147  /* Flags that can be set by user space */
3148 @@ -305,6 +353,37 @@ static int gfs2_set_flags(struct file *f
3149         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3150  }
3151  
3152 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3153 +{
3154 +       struct gfs2_inode *ip = GFS2_I(inode);
3155 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3156 +       struct buffer_head *bh;
3157 +       struct gfs2_holder gh;
3158 +       int error;
3159 +
3160 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3161 +       if (error)
3162 +               return error;
3163 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3164 +       if (error)
3165 +               goto out;
3166 +       error = gfs2_meta_inode_buffer(ip, &bh);
3167 +       if (error)
3168 +               goto out_trans_end;
3169 +       gfs2_trans_add_meta(ip->i_gl, bh);
3170 +       inode->i_flags = flags;
3171 +       inode->i_vflags = vflags;
3172 +       gfs2_get_inode_flags(inode);
3173 +       gfs2_dinode_out(ip, bh->b_data);
3174 +       brelse(bh);
3175 +       gfs2_set_aops(inode);
3176 +out_trans_end:
3177 +       gfs2_trans_end(sdp);
3178 +out:
3179 +       gfs2_glock_dq_uninit(&gh);
3180 +       return error;
3181 +}
3182 +
3183  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3184  {
3185         switch(cmd) {
3186 diff -NurpP --minimal linux-4.4.115/fs/gfs2/inode.h linux-4.4.115-vs2.3.9.7/fs/gfs2/inode.h
3187 --- linux-4.4.115/fs/gfs2/inode.h       2015-04-12 22:12:50.000000000 +0000
3188 +++ linux-4.4.115-vs2.3.9.7/fs/gfs2/inode.h     2018-01-09 16:36:32.000000000 +0000
3189 @@ -118,6 +118,7 @@ extern const struct file_operations gfs2
3190  extern const struct file_operations gfs2_dir_fops_nolock;
3191  
3192  extern void gfs2_set_inode_flags(struct inode *inode);
3193 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3194   
3195  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3196  extern const struct file_operations gfs2_file_fops;
3197 diff -NurpP --minimal linux-4.4.115/fs/hostfs/hostfs.h linux-4.4.115-vs2.3.9.7/fs/hostfs/hostfs.h
3198 --- linux-4.4.115/fs/hostfs/hostfs.h    2015-07-06 20:41:42.000000000 +0000
3199 +++ linux-4.4.115-vs2.3.9.7/fs/hostfs/hostfs.h  2018-01-09 16:36:32.000000000 +0000
3200 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3201         unsigned short  ia_mode;
3202         uid_t           ia_uid;
3203         gid_t           ia_gid;
3204 +       vtag_t          ia_tag;
3205         loff_t          ia_size;
3206         struct timespec ia_atime;
3207         struct timespec ia_mtime;
3208 diff -NurpP --minimal linux-4.4.115/fs/inode.c linux-4.4.115-vs2.3.9.7/fs/inode.c
3209 --- linux-4.4.115/fs/inode.c    2018-02-10 14:38:46.000000000 +0000
3210 +++ linux-4.4.115-vs2.3.9.7/fs/inode.c  2018-01-09 16:36:32.000000000 +0000
3211 @@ -18,6 +18,7 @@
3212  #include <linux/buffer_head.h> /* for inode_has_buffers */
3213  #include <linux/ratelimit.h>
3214  #include <linux/list_lru.h>
3215 +#include <linux/vs_tag.h>
3216  #include <trace/events/writeback.h>
3217  #include "internal.h"
3218  
3219 @@ -133,6 +134,8 @@ int inode_init_always(struct super_block
3220         struct address_space *const mapping = &inode->i_data;
3221  
3222         inode->i_sb = sb;
3223 +
3224 +       /* essential because of inode slab reuse */
3225         inode->i_blkbits = sb->s_blocksize_bits;
3226         inode->i_flags = 0;
3227         atomic_set(&inode->i_count, 1);
3228 @@ -142,6 +145,7 @@ int inode_init_always(struct super_block
3229         inode->i_opflags = 0;
3230         i_uid_write(inode, 0);
3231         i_gid_write(inode, 0);
3232 +       i_tag_write(inode, 0);
3233         atomic_set(&inode->i_writecount, 0);
3234         inode->i_size = 0;
3235         inode->i_blocks = 0;
3236 @@ -152,6 +156,7 @@ int inode_init_always(struct super_block
3237         inode->i_cdev = NULL;
3238         inode->i_link = NULL;
3239         inode->i_rdev = 0;
3240 +       inode->i_mdev = 0;
3241         inode->dirtied_when = 0;
3242  
3243         if (security_inode_alloc(inode))
3244 @@ -469,6 +474,8 @@ void __insert_inode_hash(struct inode *i
3245  }
3246  EXPORT_SYMBOL(__insert_inode_hash);
3247  
3248 +EXPORT_SYMBOL_GPL(__iget);
3249 +
3250  /**
3251   *     __remove_inode_hash - remove an inode from the hash
3252   *     @inode: inode to unhash
3253 @@ -1911,9 +1918,11 @@ void init_special_inode(struct inode *in
3254         if (S_ISCHR(mode)) {
3255                 inode->i_fop = &def_chr_fops;
3256                 inode->i_rdev = rdev;
3257 +               inode->i_mdev = rdev;
3258         } else if (S_ISBLK(mode)) {
3259                 inode->i_fop = &def_blk_fops;
3260                 inode->i_rdev = rdev;
3261 +               inode->i_mdev = rdev;
3262         } else if (S_ISFIFO(mode))
3263                 inode->i_fop = &pipefifo_fops;
3264         else if (S_ISSOCK(mode))
3265 @@ -1942,6 +1951,7 @@ void inode_init_owner(struct inode *inod
3266         } else
3267                 inode->i_gid = current_fsgid();
3268         inode->i_mode = mode;
3269 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3270  }
3271  EXPORT_SYMBOL(inode_init_owner);
3272  
3273 diff -NurpP --minimal linux-4.4.115/fs/ioctl.c linux-4.4.115-vs2.3.9.7/fs/ioctl.c
3274 --- linux-4.4.115/fs/ioctl.c    2015-04-12 22:12:50.000000000 +0000
3275 +++ linux-4.4.115-vs2.3.9.7/fs/ioctl.c  2018-01-09 16:36:32.000000000 +0000
3276 @@ -15,6 +15,9 @@
3277  #include <linux/writeback.h>
3278  #include <linux/buffer_head.h>
3279  #include <linux/falloc.h>
3280 +#include <linux/proc_fs.h>
3281 +#include <linux/vserver/inode.h>
3282 +#include <linux/vs_tag.h>
3283  
3284  #include <asm/ioctls.h>
3285  
3286 diff -NurpP --minimal linux-4.4.115/fs/jfs/file.c linux-4.4.115-vs2.3.9.7/fs/jfs/file.c
3287 --- linux-4.4.115/fs/jfs/file.c 2016-07-05 04:12:33.000000000 +0000
3288 +++ linux-4.4.115-vs2.3.9.7/fs/jfs/file.c       2018-01-09 16:36:32.000000000 +0000
3289 @@ -113,7 +113,8 @@ int jfs_setattr(struct dentry *dentry, s
3290                         return rc;
3291         }
3292         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3293 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3294 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3295 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3296                 rc = dquot_transfer(inode, iattr);
3297                 if (rc)
3298                         return rc;
3299 @@ -149,6 +150,7 @@ const struct inode_operations jfs_file_i
3300         .get_acl        = jfs_get_acl,
3301         .set_acl        = jfs_set_acl,
3302  #endif
3303 +       .sync_flags     = jfs_sync_flags,
3304  };
3305  
3306  const struct file_operations jfs_file_operations = {
3307 diff -NurpP --minimal linux-4.4.115/fs/jfs/ioctl.c linux-4.4.115-vs2.3.9.7/fs/jfs/ioctl.c
3308 --- linux-4.4.115/fs/jfs/ioctl.c        2015-10-29 09:21:36.000000000 +0000
3309 +++ linux-4.4.115-vs2.3.9.7/fs/jfs/ioctl.c      2018-01-09 16:36:32.000000000 +0000
3310 @@ -12,6 +12,7 @@
3311  #include <linux/time.h>
3312  #include <linux/sched.h>
3313  #include <linux/blkdev.h>
3314 +#include <linux/mount.h>
3315  #include <asm/current.h>
3316  #include <asm/uaccess.h>
3317  
3318 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3319  }
3320  
3321  
3322 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3323 +{
3324 +       inode->i_flags = flags;
3325 +       inode->i_vflags = vflags;
3326 +       jfs_get_inode_flags(JFS_IP(inode));
3327 +       inode->i_ctime = CURRENT_TIME_SEC;
3328 +       mark_inode_dirty(inode);
3329 +       return 0;
3330 +}
3331 +
3332  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3333  {
3334         struct inode *inode = file_inode(filp);
3335 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3336                 if (!S_ISDIR(inode->i_mode))
3337                         flags &= ~JFS_DIRSYNC_FL;
3338  
3339 +               if (IS_BARRIER(inode)) {
3340 +                       vxwprintk_task(1, "messing with the barrier.");
3341 +                       return -EACCES;
3342 +               }
3343 +
3344                 /* Is it quota file? Do not allow user to mess with it */
3345                 if (IS_NOQUOTA(inode)) {
3346                         err = -EPERM;
3347 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3348                  * the relevant capability.
3349                  */
3350                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3351 -                       ((flags ^ oldflags) &
3352 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3353 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3354 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3355                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3356                                 mutex_unlock(&inode->i_mutex);
3357                                 err = -EPERM;
3358 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3359                         }
3360                 }
3361  
3362 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3363 +               flags &= JFS_FL_USER_MODIFIABLE;
3364                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3365                 jfs_inode->mode2 = flags;
3366  
3367 diff -NurpP --minimal linux-4.4.115/fs/jfs/jfs_dinode.h linux-4.4.115-vs2.3.9.7/fs/jfs/jfs_dinode.h
3368 --- linux-4.4.115/fs/jfs/jfs_dinode.h   2015-04-12 22:12:50.000000000 +0000
3369 +++ linux-4.4.115-vs2.3.9.7/fs/jfs/jfs_dinode.h 2018-01-09 16:36:32.000000000 +0000
3370 @@ -161,9 +161,13 @@ struct dinode {
3371  
3372  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3373  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3374 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3375  
3376 -#define JFS_FL_USER_VISIBLE    0x03F80000
3377 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3378 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3379 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3380 +
3381 +#define JFS_FL_USER_VISIBLE    0x07F80000
3382 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3383  #define JFS_FL_INHERIT         0x03C80000
3384  
3385  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3386 diff -NurpP --minimal linux-4.4.115/fs/jfs/jfs_filsys.h linux-4.4.115-vs2.3.9.7/fs/jfs/jfs_filsys.h
3387 --- linux-4.4.115/fs/jfs/jfs_filsys.h   2015-04-12 22:12:50.000000000 +0000
3388 +++ linux-4.4.115-vs2.3.9.7/fs/jfs/jfs_filsys.h 2018-01-09 16:36:32.000000000 +0000
3389 @@ -266,6 +266,7 @@
3390  #define JFS_NAME_MAX   255
3391  #define JFS_PATH_MAX   BPSIZE
3392  
3393 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3394  
3395  /*
3396   *     file system state (superblock state)
3397 diff -NurpP --minimal linux-4.4.115/fs/jfs/jfs_imap.c linux-4.4.115-vs2.3.9.7/fs/jfs/jfs_imap.c
3398 --- linux-4.4.115/fs/jfs/jfs_imap.c     2015-04-12 22:12:50.000000000 +0000
3399 +++ linux-4.4.115-vs2.3.9.7/fs/jfs/jfs_imap.c   2018-01-09 16:36:32.000000000 +0000
3400 @@ -46,6 +46,7 @@
3401  #include <linux/pagemap.h>
3402  #include <linux/quotaops.h>
3403  #include <linux/slab.h>
3404 +#include <linux/vs_tag.h>
3405  
3406  #include "jfs_incore.h"
3407  #include "jfs_inode.h"
3408 @@ -3047,6 +3048,8 @@ static int copy_from_dinode(struct dinod
3409  {
3410         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3411         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3412 +       kuid_t kuid;
3413 +       kgid_t kgid;
3414  
3415         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3416         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3417 @@ -3067,14 +3070,18 @@ static int copy_from_dinode(struct dinod
3418         }
3419         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3420  
3421 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3422 +       kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3423 +       kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3424 +       ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3425 +
3426 +       jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3427         if (!uid_valid(sbi->uid))
3428                 ip->i_uid = jfs_ip->saved_uid;
3429         else {
3430                 ip->i_uid = sbi->uid;
3431         }
3432  
3433 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3434 +       jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3435         if (!gid_valid(sbi->gid))
3436                 ip->i_gid = jfs_ip->saved_gid;
3437         else {
3438 @@ -3139,16 +3146,14 @@ static void copy_to_dinode(struct dinode
3439         dip->di_size = cpu_to_le64(ip->i_size);
3440         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3441         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3442 -       if (!uid_valid(sbi->uid))
3443 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3444 -       else
3445 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3446 -                                                  jfs_ip->saved_uid));
3447 -       if (!gid_valid(sbi->gid))
3448 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3449 -       else
3450 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3451 -                                                   jfs_ip->saved_gid));
3452 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3453 +               TAGINO_KUID(DX_TAG(ip),
3454 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3455 +               ip->i_tag)));
3456 +       dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3457 +               TAGINO_KGID(DX_TAG(ip),
3458 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3459 +               ip->i_tag)));
3460         jfs_get_inode_flags(jfs_ip);
3461         /*
3462          * mode2 is only needed for storing the higher order bits.
3463 diff -NurpP --minimal linux-4.4.115/fs/jfs/jfs_inode.c linux-4.4.115-vs2.3.9.7/fs/jfs/jfs_inode.c
3464 --- linux-4.4.115/fs/jfs/jfs_inode.c    2016-07-05 04:12:33.000000000 +0000
3465 +++ linux-4.4.115-vs2.3.9.7/fs/jfs/jfs_inode.c  2018-01-14 06:39:51.000000000 +0000
3466 @@ -18,6 +18,7 @@
3467  
3468  #include <linux/fs.h>
3469  #include <linux/quotaops.h>
3470 +#include <linux/vs_tag.h>
3471  #include "jfs_incore.h"
3472  #include "jfs_inode.h"
3473  #include "jfs_filsys.h"
3474 @@ -33,6 +34,9 @@ void jfs_set_inode_flags(struct inode *i
3475  
3476         if (flags & JFS_IMMUTABLE_FL)
3477                 new_fl |= S_IMMUTABLE;
3478 +       if (flags & JFS_IXUNLINK_FL)
3479 +               new_fl |= S_IXUNLINK;
3480 +
3481         if (flags & JFS_APPEND_FL)
3482                 new_fl |= S_APPEND;
3483         if (flags & JFS_NOATIME_FL)
3484 @@ -41,18 +45,35 @@ void jfs_set_inode_flags(struct inode *i
3485                 new_fl |= S_DIRSYNC;
3486         if (flags & JFS_SYNC_FL)
3487                 new_fl |= S_SYNC;
3488 -       inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND | S_NOATIME |
3489 -                       S_DIRSYNC | S_SYNC);
3490 +
3491 +       inode_set_flags(inode, new_fl, S_IMMUTABLE | S_IXUNLINK |
3492 +                       S_APPEND | S_NOATIME | 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 +82,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.115/fs/jfs/jfs_inode.h linux-4.4.115-vs2.3.9.7/fs/jfs/jfs_inode.h
3537 --- linux-4.4.115/fs/jfs/jfs_inode.h    2015-04-12 22:12:50.000000000 +0000
3538 +++ linux-4.4.115-vs2.3.9.7/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.115/fs/jfs/namei.c linux-4.4.115-vs2.3.9.7/fs/jfs/namei.c
3548 --- linux-4.4.115/fs/jfs/namei.c        2016-07-05 04:15:08.000000000 +0000
3549 +++ linux-4.4.115-vs2.3.9.7/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.115/fs/jfs/super.c linux-4.4.115-vs2.3.9.7/fs/jfs/super.c
3575 --- linux-4.4.115/fs/jfs/super.c        2018-02-10 14:38:46.000000000 +0000
3576 +++ linux-4.4.115-vs2.3.9.7/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.115/fs/libfs.c linux-4.4.115-vs2.3.9.7/fs/libfs.c
3644 --- linux-4.4.115/fs/libfs.c    2016-07-05 04:12:33.000000000 +0000
3645 +++ linux-4.4.115-vs2.3.9.7/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.115/fs/locks.c linux-4.4.115-vs2.3.9.7/fs/locks.c
3698 --- linux-4.4.115/fs/locks.c    2018-02-10 14:38:46.000000000 +0000
3699 +++ linux-4.4.115-vs2.3.9.7/fs/locks.c  2018-01-25 00:25:02.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 @@ -2309,6 +2343,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 @@ -2624,8 +2663,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.115/fs/mount.h linux-4.4.115-vs2.3.9.7/fs/mount.h
3896 --- linux-4.4.115/fs/mount.h    2018-02-10 14:38:46.000000000 +0000
3897 +++ linux-4.4.115-vs2.3.9.7/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.115/fs/namei.c linux-4.4.115-vs2.3.9.7/fs/namei.c
3907 --- linux-4.4.115/fs/namei.c    2018-02-10 14:38:46.000000000 +0000
3908 +++ linux-4.4.115-vs2.3.9.7/fs/namei.c  2018-01-13 03:11:55.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(nd->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 @@ -3328,6 +3462,12 @@ static struct file *path_openat(struct n
4140                 }
4141         }
4142         terminate_walk(nd);
4143 +#ifdef CONFIG_VSERVER_COWBL
4144 +       if (error == -EMLINK) {
4145 +               // path_cleanup(nd);
4146 +               goto restart;
4147 +       }
4148 +#endif
4149  out2:
4150         if (!(opened & FILE_OPENED)) {
4151                 BUG_ON(!error);
4152 @@ -3448,6 +3588,11 @@ static struct dentry *filename_create(in
4153                 goto fail;
4154         }
4155         putname(name);
4156 +       vxdprintk(VXD_CBIT(misc, 3), "filename_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4157 +               path->dentry, path->dentry->d_name.len,
4158 +               path->dentry->d_name.name, dentry,
4159 +               dentry->d_name.len, dentry->d_name.name,
4160 +               path->dentry->d_inode);
4161         return dentry;
4162  fail:
4163         dput(dentry);
4164 @@ -3564,6 +3709,7 @@ retry:
4165                         error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
4166                         break;
4167         }
4168 +
4169  out:
4170         done_path_create(&path, dentry);
4171         if (retry_estale(error, lookup_flags)) {
4172 @@ -4010,7 +4156,7 @@ int vfs_link(struct dentry *old_dentry,
4173         /*
4174          * A link to an append-only or immutable file cannot be created.
4175          */
4176 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4177 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4178                 return -EPERM;
4179         if (!dir->i_op->link)
4180                 return -EPERM;
4181 @@ -4519,6 +4665,330 @@ int generic_readlink(struct dentry *dent
4182  }
4183  EXPORT_SYMBOL(generic_readlink);
4184  
4185 +
4186 +#ifdef CONFIG_VSERVER_COWBL
4187 +
4188 +static inline
4189 +void dump_path(const char *name, struct path *path)
4190 +{
4191 +       vxdprintk(VXD_CBIT(misc, 3),
4192 +               "%s: path=%p mnt=%p dentry=%p", name, path,
4193 +               path ? path->mnt : NULL,
4194 +               path ? path->dentry : NULL);
4195 +
4196 +       if (path && path->mnt)
4197 +               vxdprintk(VXD_CBIT(misc, 3),
4198 +               "%s: path mnt_sb=%p[#%d,#%d] mnt_root=%p[#%d]", name,
4199 +               path->mnt->mnt_sb,
4200 +               path->mnt->mnt_sb ? path->mnt->mnt_sb->s_count : -1,
4201 +               path->mnt->mnt_sb ? atomic_read(&path->mnt->mnt_sb->s_active) : -1,
4202 +               path->mnt->mnt_root,
4203 +               path->mnt->mnt_root ? path->mnt->mnt_root->d_lockref.count : -1);
4204 +
4205 +       if (path && path->dentry)
4206 +               vxdprintk(VXD_CBIT(misc, 3),
4207 +               "%s: path dentry=%p[#%d]", name,
4208 +               path->dentry,
4209 +               path->dentry ? path->dentry->d_lockref.count : -1);
4210 +}
4211 +
4212 +static inline
4213 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4214 +{
4215 +       loff_t ppos = 0;
4216 +       loff_t opos = 0;
4217 +
4218 +       return do_splice_direct(in, &ppos, out, &opos, len, 0);
4219 +}
4220 +
4221 +struct dentry *cow_break_link(const char *pathname)
4222 +{
4223 +       int ret, mode, pathlen, redo = 0, drop = 1;
4224 +       struct path old_path = {}, par_path = {}, dir_path = {}, *new_path = NULL;
4225 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4226 +       struct file *old_file;
4227 +       struct file *new_file;
4228 +       struct qstr new_qstr;
4229 +       int new_type;
4230 +       char *to, *path, pad='\251';
4231 +       loff_t size;
4232 +       struct filename *filename = getname_kernel(pathname);
4233 +       struct filename *to_filename;
4234 +
4235 +       vxdprintk(VXD_CBIT(misc, 1),
4236 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4237 +
4238 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4239 +       ret = -ENOMEM;
4240 +       if (!path || IS_ERR(filename))
4241 +               goto out;
4242 +
4243 +       /* old_path will have refs to dentry and mnt */
4244 +       ret = filename_lookup(AT_FDCWD, filename, LOOKUP_FOLLOW, &old_path, NULL);
4245 +       vxdprintk(VXD_CBIT(misc, 2),
4246 +               "do_path_lookup(old): %d", ret);
4247 +       if (ret < 0)
4248 +               goto out_free_path;
4249 +
4250 +       dump_path("cow (old)", &old_path);
4251 +
4252 +       /* no explicit reference for old_dentry here */
4253 +       old_dentry = old_path.dentry;
4254 +
4255 +       /* speculative put */
4256 +       // dput(old_dentry);
4257 +
4258 +       mode = old_dentry->d_inode->i_mode;
4259 +       to = d_path(&old_path, path, PATH_MAX-2);
4260 +       pathlen = strlen(to);
4261 +       vxdprintk(VXD_CBIT(misc, 2),
4262 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4263 +               old_dentry,
4264 +               old_dentry->d_name.len, old_dentry->d_name.name,
4265 +               old_dentry->d_name.len);
4266 +
4267 +       to[pathlen + 1] = 0;
4268 +retry:
4269 +       new_dentry = NULL;
4270 +       to[pathlen] = pad--;
4271 +       ret = -ELOOP;
4272 +       if (pad <= '\240')
4273 +               goto out_rel_old;
4274 +
4275 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4276 +
4277 +       /* dir_path will have refs to dentry and mnt */
4278 +       to_filename = getname_kernel(to);
4279 +       to_filename = filename_parentat(AT_FDCWD, to_filename,
4280 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &par_path, &new_qstr, &new_type);
4281 +       vxdprintk(VXD_CBIT(misc, 2), "filename_parentat(new): %p", to_filename);
4282 +       dump_path("cow (par)", &par_path);
4283 +       if (IS_ERR(to_filename))
4284 +               goto retry;
4285 +
4286 +       vxdprintk(VXD_CBIT(misc, 2), "to_filename refcnt=%d", to_filename->refcnt);
4287 +       // putname(to_filename);
4288 +
4289 +       /* this puppy downs the dir inode mutex if successful.
4290 +          dir_path will hold refs to dentry and mnt and
4291 +          we'll have write access to the mnt */
4292 +       new_dentry = filename_create(AT_FDCWD, to_filename, &dir_path, 0);
4293 +       if (!new_dentry || IS_ERR(new_dentry)) {
4294 +               path_put(&par_path);
4295 +               vxdprintk(VXD_CBIT(misc, 2),
4296 +                       "filename_create(new) failed with %ld",
4297 +                       PTR_ERR(new_dentry));
4298 +               goto retry;
4299 +       }
4300 +       vxdprintk(VXD_CBIT(misc, 2),
4301 +               "filename_create(new): %p [" VS_Q("%.*s") ":%d]",
4302 +               new_dentry,
4303 +               new_dentry->d_name.len, new_dentry->d_name.name,
4304 +               new_dentry->d_name.len);
4305 +
4306 +       dump_path("cow (dir)", &dir_path);
4307 +
4308 +       /* take a reference on new_dentry */
4309 +       dget(new_dentry);
4310 +
4311 +       /* dentry/mnt refs handed over to new_path */
4312 +       new_path = &dir_path;
4313 +
4314 +       /* dentry for old/new dir */
4315 +       dir = par_path.dentry;
4316 +
4317 +       /* give up reference on dir */
4318 +       dput(new_path->dentry);
4319 +
4320 +       /* new_dentry already has a reference */
4321 +       new_path->dentry = new_dentry;
4322 +
4323 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4324 +       vxdprintk(VXD_CBIT(misc, 2),
4325 +               "vfs_create(new): %d", ret);
4326 +       if (ret == -EEXIST) {
4327 +               path_put(&par_path);
4328 +               mutex_unlock(&dir->d_inode->i_mutex);
4329 +               mnt_drop_write(new_path->mnt);
4330 +               path_put(new_path);
4331 +               new_dentry = NULL;
4332 +               goto retry;
4333 +       }
4334 +       else if (ret < 0)
4335 +               goto out_unlock_new;
4336 +
4337 +       /* the old file went away */
4338 +       ret = -ENOENT;
4339 +       if ((redo = d_unhashed(old_dentry)))
4340 +               goto out_unlock_new;
4341 +
4342 +       /* doesn't change refs for old_path */
4343 +       old_file = dentry_open(&old_path, O_RDONLY, current_cred());
4344 +       vxdprintk(VXD_CBIT(misc, 2),
4345 +               "dentry_open(old): %p", old_file);
4346 +       if (IS_ERR(old_file)) {
4347 +               ret = PTR_ERR(old_file);
4348 +               goto out_unlock_new;
4349 +       }
4350 +
4351 +       /* doesn't change refs for new_path */
4352 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4353 +       vxdprintk(VXD_CBIT(misc, 2),
4354 +               "dentry_open(new): %p", new_file);
4355 +       if (IS_ERR(new_file)) {
4356 +               ret = PTR_ERR(new_file);
4357 +               goto out_fput_old;
4358 +       }
4359 +
4360 +       /* unlock the inode mutex from filename_create() */
4361 +       mutex_unlock(&dir->d_inode->i_mutex);
4362 +
4363 +       /* drop write access to mnt */
4364 +       mnt_drop_write(new_path->mnt);
4365 +
4366 +       drop = 0;
4367 +
4368 +       size = i_size_read(old_file->f_path.dentry->d_inode);
4369 +       ret = do_cow_splice(old_file, new_file, size);
4370 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4371 +       if (ret < 0) {
4372 +               goto out_fput_both;
4373 +       } else if (ret < size) {
4374 +               ret = -ENOSPC;
4375 +               goto out_fput_both;
4376 +       } else {
4377 +               struct inode *old_inode = old_dentry->d_inode;
4378 +               struct inode *new_inode = new_dentry->d_inode;
4379 +               struct iattr attr = {
4380 +                       .ia_uid = old_inode->i_uid,
4381 +                       .ia_gid = old_inode->i_gid,
4382 +                       .ia_valid = ATTR_UID | ATTR_GID
4383 +                       };
4384 +
4385 +               setattr_copy(new_inode, &attr);
4386 +               mark_inode_dirty(new_inode);
4387 +       }
4388 +
4389 +       /* lock rename mutex */
4390 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4391 +
4392 +       /* drop out late */
4393 +       ret = -ENOENT;
4394 +       if ((redo = d_unhashed(old_dentry)))
4395 +               goto out_unlock;
4396 +
4397 +       vxdprintk(VXD_CBIT(misc, 2),
4398 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4399 +               new_dentry->d_name.len, new_dentry->d_name.name,
4400 +               new_dentry->d_name.len,
4401 +               old_dentry->d_name.len, old_dentry->d_name.name,
4402 +               old_dentry->d_name.len);
4403 +       ret = vfs_rename(par_path.dentry->d_inode, new_dentry,
4404 +               old_dentry->d_parent->d_inode, old_dentry, NULL, 0);
4405 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4406 +
4407 +out_unlock:
4408 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4409 +
4410 +out_fput_both:
4411 +       vxdprintk(VXD_CBIT(misc, 3),
4412 +               "fput(new_file=%p[#%ld])", new_file,
4413 +               atomic_long_read(&new_file->f_count));
4414 +       fput(new_file);
4415 +
4416 +out_fput_old:
4417 +       vxdprintk(VXD_CBIT(misc, 3),
4418 +               "fput(old_file=%p[#%ld])", old_file,
4419 +               atomic_long_read(&old_file->f_count));
4420 +       fput(old_file);
4421 +
4422 +out_unlock_new:
4423 +       /* drop references from par_path */
4424 +       path_put(&par_path);
4425 +
4426 +       if (drop) {
4427 +               /* unlock the inode mutex from filename_create() */
4428 +               mutex_unlock(&dir->d_inode->i_mutex);
4429 +
4430 +               /* drop write access to mnt */
4431 +               mnt_drop_write(new_path->mnt);
4432 +       }
4433 +
4434 +       if (!ret)
4435 +               goto out_redo;
4436 +
4437 +       /* error path cleanup */
4438 +       vfs_unlink(dir->d_inode, new_dentry, NULL);
4439 +
4440 +out_redo:
4441 +       if (!redo)
4442 +               goto out_rel_both;
4443 +
4444 +       /* lookup dentry once again
4445 +          old_path will be freed as old_path in out_rel_old */
4446 +       ret = filename_lookup(AT_FDCWD, filename, LOOKUP_FOLLOW, &old_path, NULL);
4447 +       if (ret)
4448 +               goto out_rel_both;
4449 +
4450 +       /* drop reference on new_dentry */
4451 +       dput(new_dentry);
4452 +       new_dentry = old_path.dentry;
4453 +       dget(new_dentry);
4454 +       vxdprintk(VXD_CBIT(misc, 2),
4455 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4456 +               new_dentry,
4457 +               new_dentry->d_name.len, new_dentry->d_name.name,
4458 +               new_dentry->d_name.len);
4459 +
4460 +out_rel_both:
4461 +       dump_path("put (new)", new_path);
4462 +       if (new_path)
4463 +               path_put(new_path);
4464 +out_rel_old:
4465 +       dump_path("put (old)", &old_path);
4466 +       path_put(&old_path);
4467 +out_free_path:
4468 +       kfree(path);
4469 +out:
4470 +       if (ret) {
4471 +               dput(new_dentry);
4472 +               new_dentry = ERR_PTR(ret);
4473 +       }
4474 +       // if (!IS_ERR(filename))
4475 +       //        putname(filename);
4476 +       vxdprintk(VXD_CBIT(misc, 3),
4477 +               "cow_break_link returning with %p", new_dentry);
4478 +       return new_dentry;
4479 +}
4480 +
4481 +#endif
4482 +
4483 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4484 +{
4485 +       struct path path;
4486 +       struct vfsmount *vmnt;
4487 +       char *pstr, *root;
4488 +       int length = 0;
4489 +
4490 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4491 +       if (!pstr)
4492 +               return 0;
4493 +
4494 +       vmnt = &ns->root->mnt;
4495 +       path.mnt = vmnt;
4496 +       path.dentry = vmnt->mnt_root;
4497 +       root = d_path(&path, pstr, PATH_MAX - 2);
4498 +       length = sprintf(buffer + length,
4499 +               "Namespace:\t%p [#%u]\n"
4500 +               "RootPath:\t%s\n",
4501 +               ns, atomic_read(&ns->count),
4502 +               root);
4503 +       kfree(pstr);
4504 +       return length;
4505 +}
4506 +
4507 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4508 +
4509  /* get the link contents into pagecache */
4510  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4511  {
4512 diff -NurpP --minimal linux-4.4.115/fs/namespace.c linux-4.4.115-vs2.3.9.7/fs/namespace.c
4513 --- linux-4.4.115/fs/namespace.c        2018-02-10 14:38:46.000000000 +0000
4514 +++ linux-4.4.115-vs2.3.9.7/fs/namespace.c      2018-01-09 16:36:32.000000000 +0000
4515 @@ -24,6 +24,11 @@
4516  #include <linux/magic.h>
4517  #include <linux/bootmem.h>
4518  #include <linux/task_work.h>
4519 +#include <linux/vs_base.h>
4520 +#include <linux/vs_context.h>
4521 +#include <linux/vs_tag.h>
4522 +#include <linux/vserver/space.h>
4523 +#include <linux/vserver/global.h>
4524  #include "pnode.h"
4525  #include "internal.h"
4526  
4527 @@ -971,6 +976,10 @@ vfs_kern_mount(struct file_system_type *
4528         if (!type)
4529                 return ERR_PTR(-ENODEV);
4530  
4531 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4532 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4533 +               return ERR_PTR(-EPERM);
4534 +
4535         mnt = alloc_vfsmnt(name);
4536         if (!mnt)
4537                 return ERR_PTR(-ENOMEM);
4538 @@ -1046,6 +1055,7 @@ static struct mount *clone_mnt(struct mo
4539         mnt->mnt.mnt_root = dget(root);
4540         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4541         mnt->mnt_parent = mnt;
4542 +       mnt->mnt_tag = old->mnt_tag;
4543         lock_mount_hash();
4544         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4545         unlock_mount_hash();
4546 @@ -1620,7 +1630,8 @@ out_unlock:
4547   */
4548  static inline bool may_mount(void)
4549  {
4550 -       return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4551 +       return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4552 +               CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4553  }
4554  
4555  /*
4556 @@ -2121,6 +2132,7 @@ static int do_change_type(struct path *p
4557                 if (err)
4558                         goto out_unlock;
4559         }
4560 +       // mnt->mnt_flags = mnt_flags;
4561  
4562         lock_mount_hash();
4563         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4564 @@ -2149,12 +2161,14 @@ static bool has_locked_children(struct m
4565   * do loopback mount.
4566   */
4567  static int do_loopback(struct path *path, const char *old_name,
4568 -                               int recurse)
4569 +       vtag_t tag, unsigned long flags, int mnt_flags)
4570  {
4571         struct path old_path;
4572         struct mount *mnt = NULL, *old, *parent;
4573         struct mountpoint *mp;
4574 +       int recurse = flags & MS_REC;
4575         int err;
4576 +
4577         if (!old_name || !*old_name)
4578                 return -EINVAL;
4579         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4580 @@ -2234,7 +2248,7 @@ static int change_mount_flags(struct vfs
4581   * on it - tough luck.
4582   */
4583  static int do_remount(struct path *path, int flags, int mnt_flags,
4584 -                     void *data)
4585 +       void *data, vxid_t xid)
4586  {
4587         int err;
4588         struct super_block *sb = path->mnt->mnt_sb;
4589 @@ -2742,6 +2756,7 @@ long do_mount(const char *dev_name, cons
4590         struct path path;
4591         int retval = 0;
4592         int mnt_flags = 0;
4593 +       vtag_t tag = 0;
4594  
4595         /* Discard magic */
4596         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4597 @@ -2767,6 +2782,12 @@ long do_mount(const char *dev_name, cons
4598         if (!(flags & MS_NOATIME))
4599                 mnt_flags |= MNT_RELATIME;
4600  
4601 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4602 +               /* FIXME: bind and re-mounts get the tag flag? */
4603 +               if (flags & (MS_BIND|MS_REMOUNT))
4604 +                       flags |= MS_TAGID;
4605 +       }
4606 +
4607         /* Separate the per-mountpoint flags */
4608         if (flags & MS_NOSUID)
4609                 mnt_flags |= MNT_NOSUID;
4610 @@ -2791,15 +2812,17 @@ long do_mount(const char *dev_name, cons
4611                 mnt_flags |= path.mnt->mnt_flags & MNT_ATIME_MASK;
4612         }
4613  
4614 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4615 +               mnt_flags |= MNT_NODEV;
4616         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4617                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4618                    MS_STRICTATIME);
4619  
4620         if (flags & MS_REMOUNT)
4621                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4622 -                                   data_page);
4623 +                                   data_page, tag);
4624         else if (flags & MS_BIND)
4625 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
4626 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4627         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4628                 retval = do_change_type(&path, flags);
4629         else if (flags & MS_MOVE)
4630 @@ -2919,6 +2942,7 @@ struct mnt_namespace *copy_mnt_ns(unsign
4631                         p = next_mnt(p, old);
4632         }
4633         namespace_unlock();
4634 +       atomic_inc(&vs_global_mnt_ns);
4635  
4636         if (rootmnt)
4637                 mntput(rootmnt);
4638 @@ -3094,9 +3118,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4639         new_mnt = real_mount(new.mnt);
4640         root_mnt = real_mount(root.mnt);
4641         old_mnt = real_mount(old.mnt);
4642 -       if (IS_MNT_SHARED(old_mnt) ||
4643 +       if ((IS_MNT_SHARED(old_mnt) ||
4644                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4645 -               IS_MNT_SHARED(root_mnt->mnt_parent))
4646 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4647 +               !vx_flags(VXF_STATE_SETUP, 0))
4648                 goto out4;
4649         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4650                 goto out4;
4651 @@ -3234,6 +3259,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4652         if (!atomic_dec_and_test(&ns->count))
4653                 return;
4654         drop_collected_mounts(&ns->root->mnt);
4655 +       atomic_dec(&vs_global_mnt_ns);
4656         free_mnt_ns(ns);
4657  }
4658  
4659 diff -NurpP --minimal linux-4.4.115/fs/nfs/client.c linux-4.4.115-vs2.3.9.7/fs/nfs/client.c
4660 --- linux-4.4.115/fs/nfs/client.c       2016-07-05 04:15:08.000000000 +0000
4661 +++ linux-4.4.115-vs2.3.9.7/fs/nfs/client.c     2018-01-09 16:36:32.000000000 +0000
4662 @@ -583,6 +583,9 @@ int nfs_init_server_rpcclient(struct nfs
4663         if (server->flags & NFS_MOUNT_SOFT)
4664                 server->client->cl_softrtry = 1;
4665  
4666 +       server->client->cl_tag = 0;
4667 +       if (server->flags & NFS_MOUNT_TAGGED)
4668 +               server->client->cl_tag = 1;
4669         return 0;
4670  }
4671  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4672 @@ -760,6 +763,10 @@ static void nfs_server_set_fsinfo(struct
4673                 server->acdirmin = server->acdirmax = 0;
4674         }
4675  
4676 +       /* FIXME: needs fsinfo
4677 +       if (server->flags & NFS_MOUNT_TAGGED)
4678 +               sb->s_flags |= MS_TAGGED;       */
4679 +
4680         server->maxfilesize = fsinfo->maxfilesize;
4681  
4682         server->time_delta = fsinfo->time_delta;
4683 diff -NurpP --minimal linux-4.4.115/fs/nfs/dir.c linux-4.4.115-vs2.3.9.7/fs/nfs/dir.c
4684 --- linux-4.4.115/fs/nfs/dir.c  2018-02-10 14:38:47.000000000 +0000
4685 +++ linux-4.4.115-vs2.3.9.7/fs/nfs/dir.c        2018-01-09 16:36:32.000000000 +0000
4686 @@ -37,6 +37,7 @@
4687  #include <linux/sched.h>
4688  #include <linux/kmemleak.h>
4689  #include <linux/xattr.h>
4690 +#include <linux/vs_tag.h>
4691  
4692  #include "delegation.h"
4693  #include "iostat.h"
4694 @@ -1396,6 +1397,7 @@ struct dentry *nfs_lookup(struct inode *
4695         /* Success: notify readdir to use READDIRPLUS */
4696         nfs_advise_use_readdirplus(dir);
4697  
4698 +       dx_propagate_tag(nd, inode);
4699  no_entry:
4700         res = d_splice_alias(inode, dentry);
4701         if (res != NULL) {
4702 diff -NurpP --minimal linux-4.4.115/fs/nfs/inode.c linux-4.4.115-vs2.3.9.7/fs/nfs/inode.c
4703 --- linux-4.4.115/fs/nfs/inode.c        2018-02-10 14:38:47.000000000 +0000
4704 +++ linux-4.4.115-vs2.3.9.7/fs/nfs/inode.c      2018-01-09 16:36:32.000000000 +0000
4705 @@ -38,6 +38,7 @@
4706  #include <linux/slab.h>
4707  #include <linux/compat.h>
4708  #include <linux/freezer.h>
4709 +#include <linux/vs_tag.h>
4710  
4711  #include <asm/uaccess.h>
4712  
4713 @@ -376,6 +377,8 @@ nfs_fhget(struct super_block *sb, struct
4714         if (inode->i_state & I_NEW) {
4715                 struct nfs_inode *nfsi = NFS_I(inode);
4716                 unsigned long now = jiffies;
4717 +               kuid_t kuid;
4718 +               kgid_t kgid;
4719  
4720                 /* We set i_ino for the few things that still rely on it,
4721                  * such as stat(2) */
4722 @@ -419,8 +422,8 @@ nfs_fhget(struct super_block *sb, struct
4723                 inode->i_version = 0;
4724                 inode->i_size = 0;
4725                 clear_nlink(inode);
4726 -               inode->i_uid = make_kuid(&init_user_ns, -2);
4727 -               inode->i_gid = make_kgid(&init_user_ns, -2);
4728 +               kuid = make_kuid(&init_user_ns, -2);
4729 +               kgid = make_kgid(&init_user_ns, -2);
4730                 inode->i_blocks = 0;
4731                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
4732                 nfsi->write_io = 0;
4733 @@ -455,11 +458,11 @@ nfs_fhget(struct super_block *sb, struct
4734                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
4735                         nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
4736                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
4737 -                       inode->i_uid = fattr->uid;
4738 +                       kuid = fattr->uid;
4739                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
4740                         nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
4741                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
4742 -                       inode->i_gid = fattr->gid;
4743 +                       kgid = fattr->gid;
4744                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
4745                         nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
4746                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
4747 @@ -470,6 +473,10 @@ nfs_fhget(struct super_block *sb, struct
4748                          */
4749                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
4750                 }
4751 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
4752 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
4753 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
4754 +                               /* maybe fattr->xid someday */
4755  
4756                 nfs_setsecurity(inode, fattr, label);
4757  
4758 @@ -611,6 +618,8 @@ void nfs_setattr_update_inode(struct ino
4759                         inode->i_uid = attr->ia_uid;
4760                 if ((attr->ia_valid & ATTR_GID) != 0)
4761                         inode->i_gid = attr->ia_gid;
4762 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4763 +                       inode->i_tag = attr->ia_tag;
4764                 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ACCESS
4765                                 | NFS_INO_INVALID_ACL);
4766         }
4767 @@ -1235,7 +1244,9 @@ static int nfs_check_inode_attributes(st
4768         struct nfs_inode *nfsi = NFS_I(inode);
4769         loff_t cur_size, new_isize;
4770         unsigned long invalid = 0;
4771 -
4772 +       kuid_t kuid;
4773 +       kgid_t kgid;
4774 +       ktag_t ktag;
4775  
4776         if (nfs_have_delegated_attributes(inode))
4777                 return 0;
4778 @@ -1262,13 +1273,18 @@ static int nfs_check_inode_attributes(st
4779         if (nfsi->nrequests != 0)
4780                 invalid &= ~NFS_INO_REVAL_PAGECACHE;
4781  
4782 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
4783 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
4784 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
4785 +
4786         /* Have any file permissions changed? */
4787         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
4788                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
4789 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
4790 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
4791                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
4792 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
4793 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
4794                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
4795 +               /* maybe check for tag too? */
4796  
4797         /* Has the link count changed? */
4798         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
4799 @@ -1642,6 +1658,9 @@ static int nfs_update_inode(struct inode
4800         unsigned long now = jiffies;
4801         unsigned long save_cache_validity;
4802         bool cache_revalidated = true;
4803 +       kuid_t kuid;
4804 +       kgid_t kgid;
4805 +       ktag_t ktag;
4806  
4807         dfprintk(VFS, "NFS: %s(%s/%lu fh_crc=0x%08x ct=%d info=0x%x)\n",
4808                         __func__, inode->i_sb->s_id, inode->i_ino,
4809 @@ -1752,6 +1771,9 @@ static int nfs_update_inode(struct inode
4810                 cache_revalidated = false;
4811         }
4812  
4813 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4814 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4815 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
4816  
4817         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
4818                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
4819 @@ -1806,6 +1828,10 @@ static int nfs_update_inode(struct inode
4820                 cache_revalidated = false;
4821         }
4822  
4823 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
4824 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
4825 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
4826 +
4827         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
4828                 if (inode->i_nlink != fattr->nlink) {
4829                         invalid |= NFS_INO_INVALID_ATTR;
4830 diff -NurpP --minimal linux-4.4.115/fs/nfs/nfs3xdr.c linux-4.4.115-vs2.3.9.7/fs/nfs/nfs3xdr.c
4831 --- linux-4.4.115/fs/nfs/nfs3xdr.c      2016-07-05 04:12:33.000000000 +0000
4832 +++ linux-4.4.115-vs2.3.9.7/fs/nfs/nfs3xdr.c    2018-01-09 17:17:07.000000000 +0000
4833 @@ -20,6 +20,7 @@
4834  #include <linux/nfs3.h>
4835  #include <linux/nfs_fs.h>
4836  #include <linux/nfsacl.h>
4837 +#include <linux/vs_tag.h>
4838  #include "internal.h"
4839  
4840  #define NFSDBG_FACILITY                NFSDBG_XDR
4841 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
4842   *             set_mtime       mtime;
4843   *     };
4844   */
4845 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
4846 +static void encode_sattr3(struct xdr_stream *xdr,
4847 +       const struct iattr *attr, int tag)
4848  {
4849         u32 nbytes;
4850         __be32 *p;
4851 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
4852         } else
4853                 *p++ = xdr_zero;
4854  
4855 -       if (attr->ia_valid & ATTR_UID) {
4856 +       if (attr->ia_valid & ATTR_UID ||
4857 +               (tag && (attr->ia_valid & ATTR_TAG))) {
4858                 *p++ = xdr_one;
4859 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
4860 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
4861 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
4862         } else
4863                 *p++ = xdr_zero;
4864  
4865 -       if (attr->ia_valid & ATTR_GID) {
4866 +       if (attr->ia_valid & ATTR_GID ||
4867 +               (tag && (attr->ia_valid & ATTR_TAG))) {
4868                 *p++ = xdr_one;
4869 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
4870 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
4871 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
4872         } else
4873                 *p++ = xdr_zero;
4874  
4875 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
4876                                       const struct nfs3_sattrargs *args)
4877  {
4878         encode_nfs_fh3(xdr, args->fh);
4879 -       encode_sattr3(xdr, args->sattr);
4880 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
4881         encode_sattrguard3(xdr, args);
4882  }
4883  
4884 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
4885   *     };
4886   */
4887  static void encode_createhow3(struct xdr_stream *xdr,
4888 -                             const struct nfs3_createargs *args)
4889 +       const struct nfs3_createargs *args, int tag)
4890  {
4891         encode_uint32(xdr, args->createmode);
4892         switch (args->createmode) {
4893         case NFS3_CREATE_UNCHECKED:
4894         case NFS3_CREATE_GUARDED:
4895 -               encode_sattr3(xdr, args->sattr);
4896 +               encode_sattr3(xdr, args->sattr, tag);
4897                 break;
4898         case NFS3_CREATE_EXCLUSIVE:
4899                 encode_createverf3(xdr, args->verifier);
4900 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
4901                                      const struct nfs3_createargs *args)
4902  {
4903         encode_diropargs3(xdr, args->fh, args->name, args->len);
4904 -       encode_createhow3(xdr, args);
4905 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
4906  }
4907  
4908  /*
4909 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
4910                                     const struct nfs3_mkdirargs *args)
4911  {
4912         encode_diropargs3(xdr, args->fh, args->name, args->len);
4913 -       encode_sattr3(xdr, args->sattr);
4914 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
4915  }
4916  
4917  /*
4918 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
4919   *     };
4920   */
4921  static void encode_symlinkdata3(struct xdr_stream *xdr,
4922 -                               const struct nfs3_symlinkargs *args)
4923 +       const struct nfs3_symlinkargs *args, int tag)
4924  {
4925 -       encode_sattr3(xdr, args->sattr);
4926 +       encode_sattr3(xdr, args->sattr, tag);
4927         encode_nfspath3(xdr, args->pages, args->pathlen);
4928  }
4929  
4930 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
4931                                       const struct nfs3_symlinkargs *args)
4932  {
4933         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
4934 -       encode_symlinkdata3(xdr, args);
4935 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
4936         xdr->buf->flags |= XDRBUF_WRITE;
4937  }
4938  
4939 @@ -1131,24 +1137,24 @@ static void nfs3_xdr_enc_symlink3args(st
4940   *     };
4941   */
4942  static void encode_devicedata3(struct xdr_stream *xdr,
4943 -                              const struct nfs3_mknodargs *args)
4944 +       const struct nfs3_mknodargs *args, int tag)
4945  {
4946 -       encode_sattr3(xdr, args->sattr);
4947 +       encode_sattr3(xdr, args->sattr, tag);
4948         encode_specdata3(xdr, args->rdev);
4949  }
4950  
4951  static void encode_mknoddata3(struct xdr_stream *xdr,
4952 -                             const struct nfs3_mknodargs *args)
4953 +       const struct nfs3_mknodargs *args, int tag)
4954  {
4955         encode_ftype3(xdr, args->type);
4956         switch (args->type) {
4957         case NF3CHR:
4958         case NF3BLK:
4959 -               encode_devicedata3(xdr, args);
4960 +               encode_devicedata3(xdr, args, tag);
4961                 break;
4962         case NF3SOCK:
4963         case NF3FIFO:
4964 -               encode_sattr3(xdr, args->sattr);
4965 +               encode_sattr3(xdr, args->sattr, tag);
4966                 break;
4967         case NF3REG:
4968         case NF3DIR:
4969 @@ -1163,7 +1169,7 @@ static void nfs3_xdr_enc_mknod3args(stru
4970                                     const struct nfs3_mknodargs *args)
4971  {
4972         encode_diropargs3(xdr, args->fh, args->name, args->len);
4973 -       encode_mknoddata3(xdr, args);
4974 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
4975  }
4976  
4977  /*
4978 diff -NurpP --minimal linux-4.4.115/fs/nfs/super.c linux-4.4.115-vs2.3.9.7/fs/nfs/super.c
4979 --- linux-4.4.115/fs/nfs/super.c        2018-02-10 14:38:47.000000000 +0000
4980 +++ linux-4.4.115-vs2.3.9.7/fs/nfs/super.c      2018-01-09 16:36:32.000000000 +0000
4981 @@ -54,6 +54,7 @@
4982  #include <linux/parser.h>
4983  #include <linux/nsproxy.h>
4984  #include <linux/rcupdate.h>
4985 +#include <linux/vs_tag.h>
4986  
4987  #include <asm/uaccess.h>
4988  
4989 @@ -102,6 +103,7 @@ enum {
4990         Opt_mountport,
4991         Opt_mountvers,
4992         Opt_minorversion,
4993 +       Opt_tagid,
4994  
4995         /* Mount options that take string arguments */
4996         Opt_nfsvers,
4997 @@ -114,6 +116,9 @@ enum {
4998         /* Special mount options */
4999         Opt_userspace, Opt_deprecated, Opt_sloppy,
5000  
5001 +       /* Linux-VServer tagging options */
5002 +       Opt_tag, Opt_notag,
5003 +
5004         Opt_err
5005  };
5006  
5007 @@ -183,6 +188,10 @@ static const match_table_t nfs_mount_opt
5008         { Opt_fscache_uniq, "fsc=%s" },
5009         { Opt_local_lock, "local_lock=%s" },
5010  
5011 +       { Opt_tag, "tag" },
5012 +       { Opt_notag, "notag" },
5013 +       { Opt_tagid, "tagid=%u" },
5014 +
5015         /* The following needs to be listed after all other options */
5016         { Opt_nfsvers, "v%s" },
5017  
5018 @@ -642,6 +651,7 @@ static void nfs_show_mount_options(struc
5019                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5020                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5021                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5022 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5023                 { 0, NULL, NULL }
5024         };
5025         const struct proc_nfs_info *nfs_infop;
5026 @@ -1324,6 +1334,14 @@ static int nfs_parse_mount_options(char
5027                 case Opt_nomigration:
5028                         mnt->options &= ~NFS_OPTION_MIGRATION;
5029                         break;
5030 +#ifndef CONFIG_TAGGING_NONE
5031 +               case Opt_tag:
5032 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5033 +                       break;
5034 +               case Opt_notag:
5035 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5036 +                       break;
5037 +#endif
5038  
5039                 /*
5040                  * options that take numeric values
5041 @@ -1410,6 +1428,12 @@ static int nfs_parse_mount_options(char
5042                                 goto out_invalid_value;
5043                         mnt->minorversion = option;
5044                         break;
5045 +#ifdef CONFIG_PROPAGATE
5046 +               case Opt_tagid:
5047 +                       /* use args[0] */
5048 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5049 +                       break;
5050 +#endif
5051  
5052                 /*
5053                  * options that take text values
5054 diff -NurpP --minimal linux-4.4.115/fs/nfsd/auth.c linux-4.4.115-vs2.3.9.7/fs/nfsd/auth.c
5055 --- linux-4.4.115/fs/nfsd/auth.c        2018-02-10 14:38:47.000000000 +0000
5056 +++ linux-4.4.115-vs2.3.9.7/fs/nfsd/auth.c      2018-02-10 15:16:50.000000000 +0000
5057 @@ -1,6 +1,7 @@
5058  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
5059  
5060  #include <linux/sched.h>
5061 +#include <linux/vs_tag.h>
5062  #include "nfsd.h"
5063  #include "auth.h"
5064  
5065 @@ -35,6 +36,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5066  
5067         new->fsuid = rqstp->rq_cred.cr_uid;
5068         new->fsgid = rqstp->rq_cred.cr_gid;
5069 +       /* FIXME: this desperately needs a tag :)
5070 +       new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5071 +                       */
5072  
5073         rqgi = rqstp->rq_cred.cr_group_info;
5074  
5075 diff -NurpP --minimal linux-4.4.115/fs/nfsd/nfs3xdr.c linux-4.4.115-vs2.3.9.7/fs/nfsd/nfs3xdr.c
5076 --- linux-4.4.115/fs/nfsd/nfs3xdr.c     2018-02-10 14:38:47.000000000 +0000
5077 +++ linux-4.4.115-vs2.3.9.7/fs/nfsd/nfs3xdr.c   2018-01-09 16:36:32.000000000 +0000
5078 @@ -8,6 +8,7 @@
5079  
5080  #include <linux/namei.h>
5081  #include <linux/sunrpc/svc_xprt.h>
5082 +#include <linux/vs_tag.h>
5083  #include "xdr3.h"
5084  #include "auth.h"
5085  #include "netns.h"
5086 @@ -98,6 +99,8 @@ static __be32 *
5087  decode_sattr3(__be32 *p, struct iattr *iap)
5088  {
5089         u32     tmp;
5090 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5091 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5092  
5093         iap->ia_valid = 0;
5094  
5095 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5096                 iap->ia_mode = ntohl(*p++);
5097         }
5098         if (*p++) {
5099 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5100 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5101                 if (uid_valid(iap->ia_uid))
5102                         iap->ia_valid |= ATTR_UID;
5103         }
5104         if (*p++) {
5105 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5106 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5107                 if (gid_valid(iap->ia_gid))
5108                         iap->ia_valid |= ATTR_GID;
5109         }
5110 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5111 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5112 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5113         if (*p++) {
5114                 u64     newsize;
5115  
5116 @@ -167,8 +173,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5117         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5118         *p++ = htonl((u32) (stat->mode & S_IALLUGO));
5119         *p++ = htonl((u32) stat->nlink);
5120 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5121 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5122 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5123 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5124 +               stat->uid, stat->tag)));
5125 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5126 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5127 +               stat->gid, stat->tag)));
5128         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5129                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5130         } else {
5131 diff -NurpP --minimal linux-4.4.115/fs/nfsd/nfs4xdr.c linux-4.4.115-vs2.3.9.7/fs/nfsd/nfs4xdr.c
5132 --- linux-4.4.115/fs/nfsd/nfs4xdr.c     2018-02-10 14:38:47.000000000 +0000
5133 +++ linux-4.4.115-vs2.3.9.7/fs/nfsd/nfs4xdr.c   2018-01-09 16:36:32.000000000 +0000
5134 @@ -40,6 +40,7 @@
5135  #include <linux/utsname.h>
5136  #include <linux/pagemap.h>
5137  #include <linux/sunrpc/svcauth_gss.h>
5138 +#include <linux/vs_tag.h>
5139  
5140  #include "idmap.h"
5141  #include "acl.h"
5142 @@ -2637,12 +2638,16 @@ out_acl:
5143                 *p++ = cpu_to_be32(stat.nlink);
5144         }
5145         if (bmval1 & FATTR4_WORD1_OWNER) {
5146 -               status = nfsd4_encode_user(xdr, rqstp, stat.uid);
5147 +               status = nfsd4_encode_user(xdr, rqstp,
5148 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5149 +                               stat.uid, stat.tag));
5150                 if (status)
5151                         goto out;
5152         }
5153         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5154 -               status = nfsd4_encode_group(xdr, rqstp, stat.gid);
5155 +               status = nfsd4_encode_group(xdr, rqstp,
5156 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5157 +                               stat.gid, stat.tag));
5158                 if (status)
5159                         goto out;
5160         }
5161 diff -NurpP --minimal linux-4.4.115/fs/nfsd/nfsxdr.c linux-4.4.115-vs2.3.9.7/fs/nfsd/nfsxdr.c
5162 --- linux-4.4.115/fs/nfsd/nfsxdr.c      2018-02-10 14:38:47.000000000 +0000
5163 +++ linux-4.4.115-vs2.3.9.7/fs/nfsd/nfsxdr.c    2018-01-09 16:36:32.000000000 +0000
5164 @@ -7,6 +7,7 @@
5165  #include "vfs.h"
5166  #include "xdr.h"
5167  #include "auth.h"
5168 +#include <linux/vs_tag.h>
5169  
5170  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5171  
5172 @@ -89,6 +90,8 @@ static __be32 *
5173  decode_sattr(__be32 *p, struct iattr *iap)
5174  {
5175         u32     tmp, tmp1;
5176 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5177 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5178  
5179         iap->ia_valid = 0;
5180  
5181 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5182                 iap->ia_mode = tmp;
5183         }
5184         if ((tmp = ntohl(*p++)) != (u32)-1) {
5185 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5186 +               kuid = make_kuid(&init_user_ns, tmp);
5187                 if (uid_valid(iap->ia_uid))
5188                         iap->ia_valid |= ATTR_UID;
5189         }
5190         if ((tmp = ntohl(*p++)) != (u32)-1) {
5191 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5192 +               kgid = make_kgid(&init_user_ns, tmp);
5193                 if (gid_valid(iap->ia_gid))
5194                         iap->ia_valid |= ATTR_GID;
5195         }
5196 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5197 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5198 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5199         if ((tmp = ntohl(*p++)) != (u32)-1) {
5200                 iap->ia_valid |= ATTR_SIZE;
5201                 iap->ia_size = tmp;
5202 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5203         *p++ = htonl(nfs_ftypes[type >> 12]);
5204         *p++ = htonl((u32) stat->mode);
5205         *p++ = htonl((u32) stat->nlink);
5206 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5207 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5208 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5209 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5210 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5211 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5212  
5213         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5214                 *p++ = htonl(NFS_MAXPATHLEN);
5215 diff -NurpP --minimal linux-4.4.115/fs/ocfs2/dlmglue.c linux-4.4.115-vs2.3.9.7/fs/ocfs2/dlmglue.c
5216 --- linux-4.4.115/fs/ocfs2/dlmglue.c    2018-02-10 14:38:48.000000000 +0000
5217 +++ linux-4.4.115-vs2.3.9.7/fs/ocfs2/dlmglue.c  2018-01-09 16:36:32.000000000 +0000
5218 @@ -2128,6 +2128,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5219         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5220         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5221         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5222 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5223         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5224         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5225         lvb->lvb_iatime_packed  =
5226 @@ -2178,6 +2179,7 @@ static void ocfs2_refresh_inode_from_lvb
5227  
5228         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5229         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5230 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5231         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5232         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5233         ocfs2_unpack_timespec(&inode->i_atime,
5234 diff -NurpP --minimal linux-4.4.115/fs/ocfs2/dlmglue.h linux-4.4.115-vs2.3.9.7/fs/ocfs2/dlmglue.h
5235 --- linux-4.4.115/fs/ocfs2/dlmglue.h    2018-02-10 14:38:48.000000000 +0000
5236 +++ linux-4.4.115-vs2.3.9.7/fs/ocfs2/dlmglue.h  2018-01-09 16:36:32.000000000 +0000
5237 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5238         __be16       lvb_inlink;
5239         __be32       lvb_iattr;
5240         __be32       lvb_igeneration;
5241 -       __be32       lvb_reserved2;
5242 +       __be16       lvb_itag;
5243 +       __be16       lvb_reserved2;
5244  };
5245  
5246  #define OCFS2_QINFO_LVB_VERSION 1
5247 diff -NurpP --minimal linux-4.4.115/fs/ocfs2/file.c linux-4.4.115-vs2.3.9.7/fs/ocfs2/file.c
5248 --- linux-4.4.115/fs/ocfs2/file.c       2018-02-10 14:38:48.000000000 +0000
5249 +++ linux-4.4.115-vs2.3.9.7/fs/ocfs2/file.c     2018-01-09 16:36:32.000000000 +0000
5250 @@ -1151,7 +1151,7 @@ int ocfs2_setattr(struct dentry *dentry,
5251                 attr->ia_valid &= ~ATTR_SIZE;
5252  
5253  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5254 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5255 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5256         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5257                 return 0;
5258  
5259 diff -NurpP --minimal linux-4.4.115/fs/ocfs2/inode.c linux-4.4.115-vs2.3.9.7/fs/ocfs2/inode.c
5260 --- linux-4.4.115/fs/ocfs2/inode.c      2016-07-05 04:12:34.000000000 +0000
5261 +++ linux-4.4.115-vs2.3.9.7/fs/ocfs2/inode.c    2018-01-09 16:36:32.000000000 +0000
5262 @@ -28,6 +28,7 @@
5263  #include <linux/highmem.h>
5264  #include <linux/pagemap.h>
5265  #include <linux/quotaops.h>
5266 +#include <linux/vs_tag.h>
5267  
5268  #include <asm/byteorder.h>
5269  
5270 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5271  {
5272         unsigned int flags = OCFS2_I(inode)->ip_attr;
5273  
5274 -       inode->i_flags &= ~(S_IMMUTABLE |
5275 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5276                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5277  
5278         if (flags & OCFS2_IMMUTABLE_FL)
5279                 inode->i_flags |= S_IMMUTABLE;
5280 +       if (flags & OCFS2_IXUNLINK_FL)
5281 +               inode->i_flags |= S_IXUNLINK;
5282  
5283         if (flags & OCFS2_SYNC_FL)
5284                 inode->i_flags |= S_SYNC;
5285 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5286                 inode->i_flags |= S_NOATIME;
5287         if (flags & OCFS2_DIRSYNC_FL)
5288                 inode->i_flags |= S_DIRSYNC;
5289 +
5290 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5291 +
5292 +       if (flags & OCFS2_BARRIER_FL)
5293 +               inode->i_vflags |= V_BARRIER;
5294 +       if (flags & OCFS2_COW_FL)
5295 +               inode->i_vflags |= V_COW;
5296  }
5297  
5298  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5299  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5300  {
5301         unsigned int flags = oi->vfs_inode.i_flags;
5302 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5303 +
5304 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5305 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5306 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5307 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5308 +
5309 +       if (flags & S_IMMUTABLE)
5310 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5311 +       if (flags & S_IXUNLINK)
5312 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5313  
5314 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5315 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5316         if (flags & S_SYNC)
5317                 oi->ip_attr |= OCFS2_SYNC_FL;
5318         if (flags & S_APPEND)
5319                 oi->ip_attr |= OCFS2_APPEND_FL;
5320 -       if (flags & S_IMMUTABLE)
5321 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5322         if (flags & S_NOATIME)
5323                 oi->ip_attr |= OCFS2_NOATIME_FL;
5324         if (flags & S_DIRSYNC)
5325                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5326 +
5327 +       if (vflags & V_BARRIER)
5328 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5329 +       if (vflags & V_COW)
5330 +               oi->ip_attr |= OCFS2_COW_FL;
5331  }
5332  
5333  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5334 @@ -268,6 +290,8 @@ void ocfs2_populate_inode(struct inode *
5335         struct super_block *sb;
5336         struct ocfs2_super *osb;
5337         int use_plocks = 1;
5338 +       uid_t uid;
5339 +       gid_t gid;
5340  
5341         sb = inode->i_sb;
5342         osb = OCFS2_SB(sb);
5343 @@ -296,8 +320,12 @@ void ocfs2_populate_inode(struct inode *
5344         inode->i_generation = le32_to_cpu(fe->i_generation);
5345         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5346         inode->i_mode = le16_to_cpu(fe->i_mode);
5347 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5348 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5349 +       uid = le32_to_cpu(fe->i_uid);
5350 +       gid = le32_to_cpu(fe->i_gid);
5351 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5352 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5353 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5354 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5355  
5356         /* Fast symlinks will have i_size but no allocated clusters. */
5357         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5358 diff -NurpP --minimal linux-4.4.115/fs/ocfs2/inode.h linux-4.4.115-vs2.3.9.7/fs/ocfs2/inode.h
5359 --- linux-4.4.115/fs/ocfs2/inode.h      2016-07-05 04:15:08.000000000 +0000
5360 +++ linux-4.4.115-vs2.3.9.7/fs/ocfs2/inode.h    2018-01-09 16:36:32.000000000 +0000
5361 @@ -161,6 +161,7 @@ struct buffer_head *ocfs2_bread(struct i
5362  
5363  void ocfs2_set_inode_flags(struct inode *inode);
5364  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5365 +int ocfs2_sync_flags(struct inode *inode, int, int);
5366  
5367  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5368  {
5369 diff -NurpP --minimal linux-4.4.115/fs/ocfs2/ioctl.c linux-4.4.115-vs2.3.9.7/fs/ocfs2/ioctl.c
5370 --- linux-4.4.115/fs/ocfs2/ioctl.c      2015-10-29 09:21:37.000000000 +0000
5371 +++ linux-4.4.115-vs2.3.9.7/fs/ocfs2/ioctl.c    2018-01-09 16:36:32.000000000 +0000
5372 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5373         return status;
5374  }
5375  
5376 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5377 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5378 +{
5379 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5380 +       struct buffer_head *bh = NULL;
5381 +       handle_t *handle = NULL;
5382 +       int status;
5383 +
5384 +       status = ocfs2_inode_lock(inode, &bh, 1);
5385 +       if (status < 0) {
5386 +               mlog_errno(status);
5387 +               return status;
5388 +       }
5389 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5390 +       if (IS_ERR(handle)) {
5391 +               status = PTR_ERR(handle);
5392 +               mlog_errno(status);
5393 +               goto bail_unlock;
5394 +       }
5395 +
5396 +       inode->i_flags = flags;
5397 +       inode->i_vflags = vflags;
5398 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5399 +
5400 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5401 +       if (status < 0)
5402 +               mlog_errno(status);
5403 +
5404 +       ocfs2_commit_trans(osb, handle);
5405 +bail_unlock:
5406 +       ocfs2_inode_unlock(inode, 1);
5407 +       brelse(bh);
5408 +       return status;
5409 +}
5410 +
5411 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5412                                 unsigned mask)
5413  {
5414         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5415 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5416                         goto bail_unlock;
5417         }
5418  
5419 +       if (IS_BARRIER(inode)) {
5420 +               vxwprintk_task(1, "messing with the barrier.");
5421 +               goto bail_unlock;
5422 +       }
5423 +
5424         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5425         if (IS_ERR(handle)) {
5426                 status = PTR_ERR(handle);
5427 @@ -841,6 +880,7 @@ bail:
5428         return status;
5429  }
5430  
5431 +
5432  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5433  {
5434         struct inode *inode = file_inode(filp);
5435 diff -NurpP --minimal linux-4.4.115/fs/ocfs2/namei.c linux-4.4.115-vs2.3.9.7/fs/ocfs2/namei.c
5436 --- linux-4.4.115/fs/ocfs2/namei.c      2018-02-10 14:38:48.000000000 +0000
5437 +++ linux-4.4.115-vs2.3.9.7/fs/ocfs2/namei.c    2018-01-09 16:36:32.000000000 +0000
5438 @@ -41,6 +41,7 @@
5439  #include <linux/slab.h>
5440  #include <linux/highmem.h>
5441  #include <linux/quotaops.h>
5442 +#include <linux/vs_tag.h>
5443  
5444  #include <cluster/masklog.h>
5445  
5446 @@ -516,6 +517,7 @@ static int __ocfs2_mknod_locked(struct i
5447         struct ocfs2_extent_list *fel;
5448         u16 feat;
5449         struct ocfs2_inode_info *oi = OCFS2_I(inode);
5450 +       ktag_t ktag;
5451  
5452         *new_fe_bh = NULL;
5453  
5454 @@ -553,8 +555,13 @@ static int __ocfs2_mknod_locked(struct i
5455         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5456         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5457         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5458 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5459 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5460 +
5461 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5462 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5463 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5464 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5465 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5466 +       inode->i_tag = ktag; /* is this correct? */
5467         fe->i_mode = cpu_to_le16(inode->i_mode);
5468         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5469                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5470 diff -NurpP --minimal linux-4.4.115/fs/ocfs2/ocfs2.h linux-4.4.115-vs2.3.9.7/fs/ocfs2/ocfs2.h
5471 --- linux-4.4.115/fs/ocfs2/ocfs2.h      2018-02-10 14:38:48.000000000 +0000
5472 +++ linux-4.4.115-vs2.3.9.7/fs/ocfs2/ocfs2.h    2018-01-09 17:21:54.000000000 +0000
5473 @@ -289,6 +289,7 @@ enum ocfs2_mount_options
5474         OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT = 1 << 15,  /* Journal Async Commit */
5475         OCFS2_MOUNT_ERRORS_CONT = 1 << 16, /* Return EIO to the calling process on error */
5476         OCFS2_MOUNT_ERRORS_ROFS = 1 << 17, /* Change filesystem to read-only on error */
5477 +       OCFS2_MOUNT_TAGGED = 1 << 18, /* use tagging */
5478  };
5479  
5480  #define OCFS2_OSB_SOFT_RO      0x0001
5481 diff -NurpP --minimal linux-4.4.115/fs/ocfs2/ocfs2_fs.h linux-4.4.115-vs2.3.9.7/fs/ocfs2/ocfs2_fs.h
5482 --- linux-4.4.115/fs/ocfs2/ocfs2_fs.h   2016-07-05 04:12:34.000000000 +0000
5483 +++ linux-4.4.115-vs2.3.9.7/fs/ocfs2/ocfs2_fs.h 2018-01-09 16:36:32.000000000 +0000
5484 @@ -275,6 +275,11 @@
5485  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5486  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5487  
5488 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5489 +
5490 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5491 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5492 +
5493  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5494  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5495  
5496 diff -NurpP --minimal linux-4.4.115/fs/ocfs2/super.c linux-4.4.115-vs2.3.9.7/fs/ocfs2/super.c
5497 --- linux-4.4.115/fs/ocfs2/super.c      2016-07-05 04:12:34.000000000 +0000
5498 +++ linux-4.4.115-vs2.3.9.7/fs/ocfs2/super.c    2018-01-09 17:22:51.000000000 +0000
5499 @@ -193,6 +193,7 @@ enum {
5500         Opt_dir_resv_level,
5501         Opt_journal_async_commit,
5502         Opt_err_cont,
5503 +       Opt_tag, Opt_notag, Opt_tagid,
5504         Opt_err,
5505  };
5506  
5507 @@ -226,6 +227,9 @@ static const match_table_t tokens = {
5508         {Opt_dir_resv_level, "dir_resv_level=%u"},
5509         {Opt_journal_async_commit, "journal_async_commit"},
5510         {Opt_err_cont, "errors=continue"},
5511 +       {Opt_tag, "tag"},
5512 +       {Opt_notag, "notag"},
5513 +       {Opt_tagid, "tagid=%u"},
5514         {Opt_err, NULL}
5515  };
5516  
5517 @@ -677,6 +681,13 @@ static int ocfs2_remount(struct super_bl
5518                 goto out;
5519         }
5520  
5521 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5522 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5523 +               ret = -EINVAL;
5524 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5525 +               goto out;
5526 +       }
5527 +
5528         /* We're going to/from readonly mode. */
5529         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5530                 /* Disable quota accounting before remounting RO */
5531 @@ -1166,6 +1177,9 @@ static int ocfs2_fill_super(struct super
5532  
5533         ocfs2_complete_mount_recovery(osb);
5534  
5535 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5536 +               sb->s_flags |= MS_TAGGED;
5537 +
5538         if (ocfs2_mount_local(osb))
5539                 snprintf(nodestr, sizeof(nodestr), "local");
5540         else
5541 @@ -1486,6 +1500,20 @@ static int ocfs2_parse_options(struct su
5542                 case Opt_journal_async_commit:
5543                         mopt->mount_opt |= OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT;
5544                         break;
5545 +#ifndef CONFIG_TAGGING_NONE
5546 +               case Opt_tag:
5547 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5548 +                       break;
5549 +               case Opt_notag:
5550 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5551 +                       break;
5552 +#endif
5553 +#ifdef CONFIG_PROPAGATE
5554 +               case Opt_tagid:
5555 +                       /* use args[0] */
5556 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5557 +                       break;
5558 +#endif
5559                 default:
5560                         mlog(ML_ERROR,
5561                              "Unrecognized mount option \"%s\" "
5562 diff -NurpP --minimal linux-4.4.115/fs/open.c linux-4.4.115-vs2.3.9.7/fs/open.c
5563 --- linux-4.4.115/fs/open.c     2018-02-10 14:38:48.000000000 +0000
5564 +++ linux-4.4.115-vs2.3.9.7/fs/open.c   2018-01-09 16:36:32.000000000 +0000
5565 @@ -31,6 +31,11 @@
5566  #include <linux/ima.h>
5567  #include <linux/dnotify.h>
5568  #include <linux/compat.h>
5569 +#include <linux/vs_base.h>
5570 +#include <linux/vs_limit.h>
5571 +#include <linux/vs_tag.h>
5572 +#include <linux/vs_cowbl.h>
5573 +#include <linux/vserver/dlimit.h>
5574  
5575  #include "internal.h"
5576  
5577 @@ -70,6 +75,11 @@ long vfs_truncate(struct path *path, lof
5578         struct inode *inode;
5579         long error;
5580  
5581 +#ifdef CONFIG_VSERVER_COWBL
5582 +       error = cow_check_and_break(path);
5583 +       if (error)
5584 +               goto out;
5585 +#endif
5586         inode = path->dentry->d_inode;
5587  
5588         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5589 @@ -548,6 +558,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5590         unsigned int lookup_flags = LOOKUP_FOLLOW;
5591  retry:
5592         error = user_path_at(dfd, filename, lookup_flags, &path);
5593 +#ifdef CONFIG_VSERVER_COWBL
5594 +       if (!error) {
5595 +               error = cow_check_and_break(&path);
5596 +               if (error)
5597 +                       path_put(&path);
5598 +       }
5599 +#endif
5600         if (!error) {
5601                 error = chmod_common(&path, mode);
5602                 path_put(&path);
5603 @@ -582,13 +599,15 @@ retry_deleg:
5604                 if (!uid_valid(uid))
5605                         return -EINVAL;
5606                 newattrs.ia_valid |= ATTR_UID;
5607 -               newattrs.ia_uid = uid;
5608 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5609 +                       dx_map_uid(user));
5610         }
5611         if (group != (gid_t) -1) {
5612                 if (!gid_valid(gid))
5613                         return -EINVAL;
5614                 newattrs.ia_valid |= ATTR_GID;
5615 -               newattrs.ia_gid = gid;
5616 +               newattrs.ia_gid = make_kgid(&init_user_ns,
5617 +                       dx_map_gid(group));
5618         }
5619         if (!S_ISDIR(inode->i_mode))
5620                 newattrs.ia_valid |=
5621 @@ -626,6 +645,10 @@ retry:
5622         error = mnt_want_write(path.mnt);
5623         if (error)
5624                 goto out_release;
5625 +#ifdef CONFIG_VSERVER_COWBL
5626 +       error = cow_check_and_break(&path);
5627 +       if (!error)
5628 +#endif
5629         error = chown_common(&path, user, group);
5630         mnt_drop_write(path.mnt);
5631  out_release:
5632 diff -NurpP --minimal linux-4.4.115/fs/proc/array.c linux-4.4.115-vs2.3.9.7/fs/proc/array.c
5633 --- linux-4.4.115/fs/proc/array.c       2018-02-10 14:38:48.000000000 +0000
5634 +++ linux-4.4.115-vs2.3.9.7/fs/proc/array.c     2018-01-09 17:30:44.000000000 +0000
5635 @@ -83,6 +83,8 @@
5636  #include <linux/tracehook.h>
5637  #include <linux/string_helpers.h>
5638  #include <linux/user_namespace.h>
5639 +#include <linux/vs_context.h>
5640 +#include <linux/vs_network.h>
5641  
5642  #include <asm/pgtable.h>
5643  #include <asm/processor.h>
5644 @@ -154,6 +156,9 @@ static inline void task_state(struct seq
5645         ppid = pid_alive(p) ?
5646                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5647  
5648 +       if (unlikely(vx_current_initpid(p->pid)))
5649 +               ppid = 0;
5650 +
5651         tracer = ptrace_parent(p);
5652         if (tracer)
5653                 tpid = task_pid_nr_ns(tracer, ns);
5654 @@ -292,8 +297,8 @@ static inline void task_sig(struct seq_f
5655         render_sigset_t(m, "SigCgt:\t", &caught);
5656  }
5657  
5658 -static void render_cap_t(struct seq_file *m, const char *header,
5659 -                       kernel_cap_t *a)
5660 +void render_cap_t(struct seq_file *m, const char *header,
5661 +                       struct vx_info *vxi, kernel_cap_t *a)
5662  {
5663         unsigned __capi;
5664  
5665 @@ -320,11 +325,12 @@ static inline void task_cap(struct seq_f
5666         cap_ambient     = cred->cap_ambient;
5667         rcu_read_unlock();
5668  
5669 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
5670 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
5671 -       render_cap_t(m, "CapEff:\t", &cap_effective);
5672 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
5673 -       render_cap_t(m, "CapAmb:\t", &cap_ambient);
5674 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5675 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5676 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5677 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5678 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5679 +       render_cap_t(m, "CapAmb:\t", p->vx_info, &cap_ambient);
5680  }
5681  
5682  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
5683 @@ -351,6 +357,43 @@ static void task_cpus_allowed(struct seq
5684                    cpumask_pr_args(&task->cpus_allowed));
5685  }
5686  
5687 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
5688 +                       struct pid *pid, struct task_struct *task)
5689 +{
5690 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
5691 +                       "Count:\t%u\n"
5692 +                       "uts:\t%p(%c)\n"
5693 +                       "ipc:\t%p(%c)\n"
5694 +                       "mnt:\t%p(%c)\n"
5695 +                       "pid:\t%p(%c)\n"
5696 +                       "net:\t%p(%c)\n",
5697 +                       task->nsproxy,
5698 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
5699 +                       atomic_read(&task->nsproxy->count),
5700 +                       task->nsproxy->uts_ns,
5701 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
5702 +                       task->nsproxy->ipc_ns,
5703 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
5704 +                       task->nsproxy->mnt_ns,
5705 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
5706 +                       task->nsproxy->pid_ns_for_children,
5707 +                       (task->nsproxy->pid_ns_for_children ==
5708 +                               init_task.nsproxy->pid_ns_for_children ? 'I' : '-'),
5709 +                       task->nsproxy->net_ns,
5710 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
5711 +       return 0;
5712 +}
5713 +
5714 +void task_vs_id(struct seq_file *m, struct task_struct *task)
5715 +{
5716 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
5717 +               return;
5718 +
5719 +       seq_printf(m, "VxID:\t%d\n", vx_task_xid(task));
5720 +       seq_printf(m, "NxID:\t%d\n", nx_task_nid(task));
5721 +}
5722 +
5723 +
5724  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
5725                         struct pid *pid, struct task_struct *task)
5726  {
5727 @@ -368,6 +411,7 @@ int proc_pid_status(struct seq_file *m,
5728         task_seccomp(m, task);
5729         task_cpus_allowed(m, task);
5730         cpuset_task_status_allowed(m, task);
5731 +       task_vs_id(m, task);
5732         task_context_switch_counts(m, task);
5733         return 0;
5734  }
5735 @@ -471,6 +515,17 @@ static int do_task_stat(struct seq_file
5736         /* convert nsec -> ticks */
5737         start_time = nsec_to_clock_t(task->real_start_time);
5738  
5739 +       /* fixup start time for virt uptime */
5740 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
5741 +               unsigned long long bias =
5742 +                       current->vx_info->cvirt.bias_clock;
5743 +
5744 +               if (start_time > bias)
5745 +                       start_time -= bias;
5746 +               else
5747 +                       start_time = 0;
5748 +       }
5749 +
5750         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
5751         seq_put_decimal_ll(m, ' ', ppid);
5752         seq_put_decimal_ll(m, ' ', pgid);
5753 diff -NurpP --minimal linux-4.4.115/fs/proc/base.c linux-4.4.115-vs2.3.9.7/fs/proc/base.c
5754 --- linux-4.4.115/fs/proc/base.c        2018-02-10 14:38:48.000000000 +0000
5755 +++ linux-4.4.115-vs2.3.9.7/fs/proc/base.c      2018-01-09 16:36:32.000000000 +0000
5756 @@ -87,6 +87,8 @@
5757  #include <linux/slab.h>
5758  #include <linux/flex_array.h>
5759  #include <linux/posix-timers.h>
5760 +#include <linux/vs_context.h>
5761 +#include <linux/vs_network.h>
5762  #ifdef CONFIG_HARDWALL
5763  #include <asm/hardwall.h>
5764  #endif
5765 @@ -1097,11 +1099,15 @@ static ssize_t oom_adj_write(struct file
5766                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
5767  
5768         if (oom_adj < task->signal->oom_score_adj &&
5769 -           !capable(CAP_SYS_RESOURCE)) {
5770 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
5771                 err = -EACCES;
5772                 goto err_sighand;
5773         }
5774  
5775 +       /* prevent guest processes from circumventing the oom killer */
5776 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
5777 +               oom_adj = OOM_ADJUST_MIN;
5778 +
5779         /*
5780          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
5781          * /proc/pid/oom_score_adj instead.
5782 @@ -1666,6 +1672,8 @@ struct inode *proc_pid_make_inode(struct
5783                 inode->i_gid = cred->egid;
5784                 rcu_read_unlock();
5785         }
5786 +       /* procfs is xid tagged */
5787 +       i_tag_write(inode, (vtag_t)vx_task_xid(task));
5788         security_task_to_inode(task, inode);
5789  
5790  out:
5791 @@ -1711,6 +1719,8 @@ int pid_getattr(struct vfsmount *mnt, st
5792  
5793  /* dentry stuff */
5794  
5795 +// static unsigned name_to_int(struct dentry *dentry);
5796 +
5797  /*
5798   *     Exceptional case: normally we are not allowed to unhash a busy
5799   * directory. In this case, however, we can do it - no aliasing problems
5800 @@ -1739,6 +1749,19 @@ int pid_revalidate(struct dentry *dentry
5801         task = get_proc_task(inode);
5802  
5803         if (task) {
5804 +               unsigned pid = name_to_int(&dentry->d_name);
5805 +
5806 +               if (pid != ~0U && pid != vx_map_pid(task->pid) &&
5807 +                       pid != __task_pid_nr_ns(task, PIDTYPE_PID,
5808 +                               task_active_pid_ns(task))) {
5809 +                       vxdprintk(VXD_CBIT(misc, 10),
5810 +                               VS_Q("%*s") " dropped by pid_revalidate(%d!=%d)",
5811 +                               dentry->d_name.len, dentry->d_name.name,
5812 +                               pid, vx_map_pid(task->pid));
5813 +                       put_task_struct(task);
5814 +                       d_drop(dentry);
5815 +                       return 0;
5816 +               }
5817                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
5818                     task_dumpable(task)) {
5819                         rcu_read_lock();
5820 @@ -2283,6 +2306,13 @@ static struct dentry *proc_pident_lookup
5821         if (!task)
5822                 goto out_no_task;
5823  
5824 +       /* TODO: maybe we can come up with a generic approach? */
5825 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
5826 +               (dentry->d_name.len == 5) &&
5827 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
5828 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
5829 +               goto out;
5830 +
5831         /*
5832          * Yes, it does not scale. And it should not. Don't add
5833          * new entries into /proc/<tgid>/ without very good reasons.
5834 @@ -2725,6 +2755,11 @@ static int proc_pid_personality(struct s
5835  static const struct file_operations proc_task_operations;
5836  static const struct inode_operations proc_task_inode_operations;
5837  
5838 +extern int proc_pid_vx_info(struct seq_file *,
5839 +       struct pid_namespace *, struct pid *, struct task_struct *);
5840 +extern int proc_pid_nx_info(struct seq_file *,
5841 +       struct pid_namespace *, struct pid *, struct task_struct *);
5842 +
5843  static const struct pid_entry tgid_base_stuff[] = {
5844         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
5845         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
5846 @@ -2789,6 +2824,8 @@ static const struct pid_entry tgid_base_
5847  #ifdef CONFIG_CGROUPS
5848         ONE("cgroup",  S_IRUGO, proc_cgroup_show),
5849  #endif
5850 +       ONE("vinfo",      S_IRUGO, proc_pid_vx_info),
5851 +       ONE("ninfo",      S_IRUGO, proc_pid_nx_info),
5852         ONE("oom_score",  S_IRUGO, proc_oom_score),
5853         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
5854         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
5855 @@ -3003,7 +3040,7 @@ retry:
5856         iter.task = NULL;
5857         pid = find_ge_pid(iter.tgid, ns);
5858         if (pid) {
5859 -               iter.tgid = pid_nr_ns(pid, ns);
5860 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
5861                 iter.task = pid_task(pid, PIDTYPE_PID);
5862                 /* What we to know is if the pid we have find is the
5863                  * pid of a thread_group_leader.  Testing for task
5864 @@ -3063,8 +3100,10 @@ int proc_pid_readdir(struct file *file,
5865                 if (!has_pid_permissions(ns, iter.task, 2))
5866                         continue;
5867  
5868 -               len = snprintf(name, sizeof(name), "%d", iter.tgid);
5869 +               len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
5870                 ctx->pos = iter.tgid + TGID_OFFSET;
5871 +               if (!vx_proc_task_visible(iter.task))
5872 +                       continue;
5873                 if (!proc_fill_cache(file, ctx, name, len,
5874                                      proc_pid_instantiate, iter.task, NULL)) {
5875                         put_task_struct(iter.task);
5876 @@ -3161,6 +3200,7 @@ static const struct pid_entry tid_base_s
5877         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
5878         REG("setgroups",  S_IRUGO|S_IWUSR, proc_setgroups_operations),
5879  #endif
5880 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
5881  };
5882  
5883  static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
5884 @@ -3227,6 +3267,8 @@ static struct dentry *proc_task_lookup(s
5885         tid = name_to_int(&dentry->d_name);
5886         if (tid == ~0U)
5887                 goto out;
5888 +       if (vx_current_initpid(tid))
5889 +               goto out;
5890  
5891         ns = dentry->d_sb->s_fs_info;
5892         rcu_read_lock();
5893 diff -NurpP --minimal linux-4.4.115/fs/proc/generic.c linux-4.4.115-vs2.3.9.7/fs/proc/generic.c
5894 --- linux-4.4.115/fs/proc/generic.c     2018-02-10 14:38:48.000000000 +0000
5895 +++ linux-4.4.115-vs2.3.9.7/fs/proc/generic.c   2018-01-09 17:29:24.000000000 +0000
5896 @@ -22,6 +22,7 @@
5897  #include <linux/bitops.h>
5898  #include <linux/spinlock.h>
5899  #include <linux/completion.h>
5900 +#include <linux/vserver/inode.h>
5901  #include <asm/uaccess.h>
5902  
5903  #include "internal.h"
5904 @@ -66,8 +67,16 @@ static struct proc_dir_entry *pde_subdir
5905                         node = node->rb_left;
5906                 else if (result > 0)
5907                         node = node->rb_right;
5908 -               else
5909 +               else {
5910 +                       if (!vx_hide_check(0, de->vx_flags)) {
5911 +                               vxdprintk(VXD_CBIT(misc, 9),
5912 +                                       VS_Q("%*s")
5913 +                                       " hidden in pde_subdir_find()",
5914 +                                       de->namelen, de->name);
5915 +                               return 0;
5916 +                       }
5917                         return de;
5918 +               }
5919         }
5920         return NULL;
5921  }
5922 @@ -241,6 +250,8 @@ struct dentry *proc_lookup_de(struct pro
5923                         return ERR_PTR(-ENOMEM);
5924                 d_set_d_op(dentry, &simple_dentry_operations);
5925                 d_add(dentry, inode);
5926 +                       /* generic proc entries belong to the host */
5927 +                       i_tag_write(inode, 0);
5928                 return NULL;
5929         }
5930         read_unlock(&proc_subdir_lock);
5931 @@ -287,6 +298,12 @@ int proc_readdir_de(struct proc_dir_entr
5932         do {
5933                 struct proc_dir_entry *next;
5934                 pde_get(de);
5935 +               if (!vx_hide_check(0, de->vx_flags)) {
5936 +                       vxdprintk(VXD_CBIT(misc, 9),
5937 +                               VS_Q("%*s") " hidden in proc_readdir_de()",
5938 +                               de->namelen, de->name);
5939 +                       goto skip;
5940 +               }
5941                 read_unlock(&proc_subdir_lock);
5942                 if (!dir_emit(ctx, de->name, de->namelen,
5943                             de->low_ino, de->mode >> 12)) {
5944 @@ -294,6 +311,7 @@ int proc_readdir_de(struct proc_dir_entr
5945                         return 0;
5946                 }
5947                 read_lock(&proc_subdir_lock);
5948 +       skip:
5949                 ctx->pos++;
5950                 next = pde_subdir_next(de);
5951                 pde_put(de);
5952 @@ -387,6 +405,7 @@ static struct proc_dir_entry *__proc_cre
5953         ent->mode = mode;
5954         ent->nlink = nlink;
5955         ent->subdir = RB_ROOT;
5956 +       ent->vx_flags = IATTR_PROC_DEFAULT;
5957         atomic_set(&ent->count, 1);
5958         spin_lock_init(&ent->pde_unload_lock);
5959         INIT_LIST_HEAD(&ent->pde_openers);
5960 @@ -411,7 +430,8 @@ struct proc_dir_entry *proc_symlink(cons
5961                                 kfree(ent->data);
5962                                 kfree(ent);
5963                                 ent = NULL;
5964 -                       }
5965 +                       } else
5966 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
5967                 } else {
5968                         kfree(ent);
5969                         ent = NULL;
5970 diff -NurpP --minimal linux-4.4.115/fs/proc/inode.c linux-4.4.115-vs2.3.9.7/fs/proc/inode.c
5971 --- linux-4.4.115/fs/proc/inode.c       2015-10-29 09:21:39.000000000 +0000
5972 +++ linux-4.4.115-vs2.3.9.7/fs/proc/inode.c     2018-01-09 16:36:32.000000000 +0000
5973 @@ -431,6 +431,8 @@ struct inode *proc_get_inode(struct supe
5974                         inode->i_uid = de->uid;
5975                         inode->i_gid = de->gid;
5976                 }
5977 +               if (de->vx_flags)
5978 +                       PROC_I(inode)->vx_flags = de->vx_flags;
5979                 if (de->size)
5980                         inode->i_size = de->size;
5981                 if (de->nlink)
5982 diff -NurpP --minimal linux-4.4.115/fs/proc/internal.h linux-4.4.115-vs2.3.9.7/fs/proc/internal.h
5983 --- linux-4.4.115/fs/proc/internal.h    2015-10-29 09:21:39.000000000 +0000
5984 +++ linux-4.4.115-vs2.3.9.7/fs/proc/internal.h  2018-01-09 16:36:32.000000000 +0000
5985 @@ -14,6 +14,7 @@
5986  #include <linux/spinlock.h>
5987  #include <linux/atomic.h>
5988  #include <linux/binfmts.h>
5989 +#include <linux/vs_pid.h>
5990  
5991  struct ctl_table_header;
5992  struct mempolicy;
5993 @@ -34,6 +35,7 @@ struct proc_dir_entry {
5994         nlink_t nlink;
5995         kuid_t uid;
5996         kgid_t gid;
5997 +       int vx_flags;
5998         loff_t size;
5999         const struct inode_operations *proc_iops;
6000         const struct file_operations *proc_fops;
6001 @@ -51,15 +53,22 @@ struct proc_dir_entry {
6002         char name[];
6003  };
6004  
6005 +struct vx_info;
6006 +struct nx_info;
6007 +
6008  union proc_op {
6009         int (*proc_get_link)(struct dentry *, struct path *);
6010         int (*proc_show)(struct seq_file *m,
6011                 struct pid_namespace *ns, struct pid *pid,
6012                 struct task_struct *task);
6013 +       int (*proc_vs_read)(char *page);
6014 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6015 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6016  };
6017  
6018  struct proc_inode {
6019         struct pid *pid;
6020 +       int vx_flags;
6021         int fd;
6022         union proc_op op;
6023         struct proc_dir_entry *pde;
6024 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6025         return PROC_I(inode)->pid;
6026  }
6027  
6028 -static inline struct task_struct *get_proc_task(struct inode *inode)
6029 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6030  {
6031         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6032  }
6033  
6034 +static inline struct task_struct *get_proc_task(struct inode *inode)
6035 +{
6036 +       return vx_get_proc_task(inode, proc_pid(inode));
6037 +}
6038 +
6039  static inline int task_dumpable(struct task_struct *task)
6040  {
6041         int dumpable = 0;
6042 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6043                            struct pid *, struct task_struct *);
6044  extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6045                           struct pid *, struct task_struct *);
6046 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6047 +                           struct pid *pid, struct task_struct *task);
6048  
6049  /*
6050   * base.c
6051 diff -NurpP --minimal linux-4.4.115/fs/proc/loadavg.c linux-4.4.115-vs2.3.9.7/fs/proc/loadavg.c
6052 --- linux-4.4.115/fs/proc/loadavg.c     2015-04-12 22:12:50.000000000 +0000
6053 +++ linux-4.4.115-vs2.3.9.7/fs/proc/loadavg.c   2018-01-09 16:36:32.000000000 +0000
6054 @@ -12,15 +12,27 @@
6055  
6056  static int loadavg_proc_show(struct seq_file *m, void *v)
6057  {
6058 +       unsigned long running;
6059 +       unsigned int threads;
6060         unsigned long avnrun[3];
6061  
6062         get_avenrun(avnrun, FIXED_1/200, 0);
6063  
6064 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6065 +               struct vx_info *vxi = current_vx_info();
6066 +
6067 +               running = atomic_read(&vxi->cvirt.nr_running);
6068 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6069 +       } else {
6070 +               running = nr_running();
6071 +               threads = nr_threads;
6072 +       }
6073 +
6074         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6075                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6076                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6077                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6078 -               nr_running(), nr_threads,
6079 +               running, threads,
6080                 task_active_pid_ns(current)->last_pid);
6081         return 0;
6082  }
6083 diff -NurpP --minimal linux-4.4.115/fs/proc/meminfo.c linux-4.4.115-vs2.3.9.7/fs/proc/meminfo.c
6084 --- linux-4.4.115/fs/proc/meminfo.c     2016-07-05 04:15:09.000000000 +0000
6085 +++ linux-4.4.115-vs2.3.9.7/fs/proc/meminfo.c   2018-01-12 18:43:53.000000000 +0000
6086 @@ -43,7 +43,8 @@ static int meminfo_proc_show(struct seq_
6087         si_swapinfo(&i);
6088         committed = percpu_counter_read_positive(&vm_committed_as);
6089  
6090 -       cached = global_page_state(NR_FILE_PAGES) -
6091 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6092 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6093                         total_swapcache_pages() - i.bufferram;
6094         if (cached < 0)
6095                 cached = 0;
6096 @@ -70,13 +71,16 @@ static int meminfo_proc_show(struct seq_
6097          */
6098         pagecache = pages[LRU_ACTIVE_FILE] + pages[LRU_INACTIVE_FILE];
6099         pagecache -= min(pagecache / 2, wmark_low);
6100 -       available += pagecache;
6101 +
6102 +       if (!vx_flags(VXF_VIRT_MEM, 0))
6103 +               available += pagecache;
6104  
6105         /*
6106          * Part of the reclaimable slab consists of items that are in use,
6107          * and cannot be freed. Cap this estimate at the low watermark.
6108          */
6109 -       available += global_page_state(NR_SLAB_RECLAIMABLE) -
6110 +       if (!vx_flags(VXF_VIRT_MEM, 0))
6111 +               available += global_page_state(NR_SLAB_RECLAIMABLE) -
6112                      min(global_page_state(NR_SLAB_RECLAIMABLE) / 2, wmark_low);
6113  
6114         if (available < 0)
6115 diff -NurpP --minimal linux-4.4.115/fs/proc/root.c linux-4.4.115-vs2.3.9.7/fs/proc/root.c
6116 --- linux-4.4.115/fs/proc/root.c        2018-02-10 14:38:49.000000000 +0000
6117 +++ linux-4.4.115-vs2.3.9.7/fs/proc/root.c      2018-01-09 16:36:32.000000000 +0000
6118 @@ -20,9 +20,14 @@
6119  #include <linux/mount.h>
6120  #include <linux/pid_namespace.h>
6121  #include <linux/parser.h>
6122 +#include <linux/vserver/inode.h>
6123  
6124  #include "internal.h"
6125  
6126 +struct proc_dir_entry *proc_virtual;
6127 +
6128 +extern void proc_vx_init(void);
6129 +
6130  static int proc_test_super(struct super_block *sb, void *data)
6131  {
6132         return sb->s_fs_info == data;
6133 @@ -113,7 +118,8 @@ static struct dentry *proc_mount(struct
6134                 options = data;
6135  
6136                 /* Does the mounter have privilege over the pid namespace? */
6137 -               if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6138 +               if (!vx_ns_capable(ns->user_ns,
6139 +                       CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6140                         return ERR_PTR(-EPERM);
6141         }
6142  
6143 @@ -196,6 +202,7 @@ void __init proc_root_init(void)
6144         proc_tty_init();
6145         proc_mkdir("bus", NULL);
6146         proc_sys_init();
6147 +       proc_vx_init();
6148  }
6149  
6150  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6151 @@ -257,6 +264,7 @@ struct proc_dir_entry proc_root = {
6152         .proc_iops      = &proc_root_inode_operations, 
6153         .proc_fops      = &proc_root_operations,
6154         .parent         = &proc_root,
6155 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6156         .subdir         = RB_ROOT,
6157         .name           = "/proc",
6158  };
6159 diff -NurpP --minimal linux-4.4.115/fs/proc/self.c linux-4.4.115-vs2.3.9.7/fs/proc/self.c
6160 --- linux-4.4.115/fs/proc/self.c        2015-10-29 09:21:39.000000000 +0000
6161 +++ linux-4.4.115-vs2.3.9.7/fs/proc/self.c      2018-01-09 16:36:32.000000000 +0000
6162 @@ -1,6 +1,7 @@
6163  #include <linux/sched.h>
6164  #include <linux/slab.h>
6165  #include <linux/pid_namespace.h>
6166 +#include <linux/vserver/inode.h>
6167  #include "internal.h"
6168  
6169  /*
6170 @@ -52,6 +53,8 @@ int proc_setup_self(struct super_block *
6171         self = d_alloc_name(s->s_root, "self");
6172         if (self) {
6173                 struct inode *inode = new_inode_pseudo(s);
6174 +
6175 +               // self->vx_flags = IATTR_PROC_SYMLINK;
6176                 if (inode) {
6177                         inode->i_ino = self_inum;
6178                         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6179 diff -NurpP --minimal linux-4.4.115/fs/proc/stat.c linux-4.4.115-vs2.3.9.7/fs/proc/stat.c
6180 --- linux-4.4.115/fs/proc/stat.c        2015-04-12 22:12:50.000000000 +0000
6181 +++ linux-4.4.115-vs2.3.9.7/fs/proc/stat.c      2018-01-09 16:36:32.000000000 +0000
6182 @@ -9,8 +9,10 @@
6183  #include <linux/slab.h>
6184  #include <linux/time.h>
6185  #include <linux/irqnr.h>
6186 +#include <linux/vserver/cvirt.h>
6187  #include <linux/cputime.h>
6188  #include <linux/tick.h>
6189 +#include <linux/cpuset.h>
6190  
6191  #ifndef arch_irq_stat_cpu
6192  #define arch_irq_stat_cpu(cpu) 0
6193 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6194         u64 sum_softirq = 0;
6195         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6196         struct timespec boottime;
6197 +       cpumask_var_t cpus_allowed;
6198 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6199  
6200         user = nice = system = idle = iowait =
6201                 irq = softirq = steal = 0;
6202         guest = guest_nice = 0;
6203         getboottime(&boottime);
6204 +
6205 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6206 +               vx_vsi_boottime(&boottime);
6207 +
6208 +       if (virt_cpu)
6209 +               cpuset_cpus_allowed(current, cpus_allowed);
6210 +
6211         jif = boottime.tv_sec;
6212  
6213         for_each_possible_cpu(i) {
6214 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6215 +                       continue;
6216 +
6217                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6218                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6219                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6220 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6221         seq_putc(p, '\n');
6222  
6223         for_each_online_cpu(i) {
6224 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6225 +                       continue;
6226 +
6227                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6228                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6229                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6230 diff -NurpP --minimal linux-4.4.115/fs/proc/uptime.c linux-4.4.115-vs2.3.9.7/fs/proc/uptime.c
6231 --- linux-4.4.115/fs/proc/uptime.c      2015-04-12 22:12:50.000000000 +0000
6232 +++ linux-4.4.115-vs2.3.9.7/fs/proc/uptime.c    2018-01-09 16:36:32.000000000 +0000
6233 @@ -5,6 +5,7 @@
6234  #include <linux/seq_file.h>
6235  #include <linux/time.h>
6236  #include <linux/kernel_stat.h>
6237 +#include <linux/vserver/cvirt.h>
6238  #include <linux/cputime.h>
6239  
6240  static int uptime_proc_show(struct seq_file *m, void *v)
6241 @@ -24,6 +25,10 @@ static int uptime_proc_show(struct seq_f
6242         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6243         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6244         idle.tv_nsec = rem;
6245 +
6246 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6247 +               vx_vsi_uptime(&uptime, &idle);
6248 +
6249         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6250                         (unsigned long) uptime.tv_sec,
6251                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6252 diff -NurpP --minimal linux-4.4.115/fs/proc_namespace.c linux-4.4.115-vs2.3.9.7/fs/proc_namespace.c
6253 --- linux-4.4.115/fs/proc_namespace.c   2018-02-10 14:38:49.000000000 +0000
6254 +++ linux-4.4.115-vs2.3.9.7/fs/proc_namespace.c 2018-01-09 16:36:32.000000000 +0000
6255 @@ -46,6 +46,8 @@ static int show_sb_opts(struct seq_file
6256                 { MS_DIRSYNC, ",dirsync" },
6257                 { MS_MANDLOCK, ",mand" },
6258                 { MS_LAZYTIME, ",lazytime" },
6259 +               { MS_TAGGED, ",tag" },
6260 +               { MS_NOTAGCHECK, ",notagcheck" },
6261                 { 0, NULL }
6262         };
6263         const struct proc_fs_info *fs_infop;
6264 @@ -82,6 +84,38 @@ static inline void mangle(struct seq_fil
6265         seq_escape(m, s, " \t\n\\");
6266  }
6267  
6268 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6269 +
6270 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6271 +{
6272 +       struct path root;
6273 +       struct dentry *point;
6274 +       struct mount *mnt = real_mount(vfsmnt);
6275 +       struct mount *root_mnt;
6276 +       int ret;
6277 +
6278 +       if (mnt == mnt->mnt_ns->root)
6279 +               return 1;
6280 +
6281 +       rcu_read_lock();
6282 +       root = current->fs->root;
6283 +       root_mnt = real_mount(root.mnt);
6284 +       point = root.dentry;
6285 +
6286 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6287 +               point = mnt->mnt_mountpoint;
6288 +               mnt = mnt->mnt_parent;
6289 +       }
6290 +       rcu_read_unlock();
6291 +
6292 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6293 +       return ret;
6294 +}
6295 +
6296 +#else
6297 +#define        mnt_is_reachable(v)     (1)
6298 +#endif
6299 +
6300  static void show_type(struct seq_file *m, struct super_block *sb)
6301  {
6302         mangle(m, sb->s_type->name);
6303 @@ -99,6 +133,17 @@ static int show_vfsmnt(struct seq_file *
6304         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6305         struct super_block *sb = mnt_path.dentry->d_sb;
6306  
6307 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6308 +               return SEQ_SKIP;
6309 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6310 +               return SEQ_SKIP;
6311 +
6312 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6313 +               mnt == current->fs->root.mnt) {
6314 +               seq_puts(m, "/dev/root / ");
6315 +               goto type;
6316 +       }
6317 +
6318         if (sb->s_op->show_devname) {
6319                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6320                 if (err)
6321 @@ -112,6 +157,7 @@ static int show_vfsmnt(struct seq_file *
6322         if (err)
6323                 goto out;
6324         seq_putc(m, ' ');
6325 +type:
6326         show_type(m, sb);
6327         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6328         err = show_sb_opts(m, sb);
6329 @@ -133,6 +179,11 @@ static int show_mountinfo(struct seq_fil
6330         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6331         int err = 0;
6332  
6333 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6334 +               return SEQ_SKIP;
6335 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6336 +               return SEQ_SKIP;
6337 +
6338         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6339                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6340         if (sb->s_op->show_path)
6341 @@ -193,6 +244,17 @@ static int show_vfsstat(struct seq_file
6342         struct super_block *sb = mnt_path.dentry->d_sb;
6343         int err = 0;
6344  
6345 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6346 +               return SEQ_SKIP;
6347 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6348 +               return SEQ_SKIP;
6349 +
6350 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6351 +               mnt == current->fs->root.mnt) {
6352 +               seq_puts(m, "device /dev/root mounted on / ");
6353 +               goto type;
6354 +       }
6355 +
6356         /* device */
6357         if (sb->s_op->show_devname) {
6358                 seq_puts(m, "device ");
6359 @@ -214,7 +276,7 @@ static int show_vfsstat(struct seq_file
6360         if (err)
6361                 goto out;
6362         seq_putc(m, ' ');
6363 -
6364 +type:
6365         /* file system type */
6366         seq_puts(m, "with fstype ");
6367         show_type(m, sb);
6368 diff -NurpP --minimal linux-4.4.115/fs/quota/dquot.c linux-4.4.115-vs2.3.9.7/fs/quota/dquot.c
6369 --- linux-4.4.115/fs/quota/dquot.c      2018-02-10 14:38:49.000000000 +0000
6370 +++ linux-4.4.115-vs2.3.9.7/fs/quota/dquot.c    2018-02-10 15:16:50.000000000 +0000
6371 @@ -1643,6 +1643,9 @@ int __dquot_alloc_space(struct inode *in
6372         int reserve = flags & DQUOT_SPACE_RESERVE;
6373         struct dquot **dquots;
6374  
6375 +       if ((ret = dl_alloc_space(inode, number)))
6376 +               return ret;
6377 +
6378         if (!dquot_active(inode)) {
6379                 inode_incr_space(inode, number, reserve);
6380                 goto out;
6381 @@ -1695,6 +1698,9 @@ int dquot_alloc_inode(struct inode *inod
6382         struct dquot_warn warn[MAXQUOTAS];
6383         struct dquot * const *dquots;
6384  
6385 +       if ((ret = dl_alloc_inode(inode)))
6386 +               return ret;
6387 +
6388         if (!dquot_active(inode))
6389                 return 0;
6390         for (cnt = 0; cnt < MAXQUOTAS; cnt++)
6391 @@ -1797,6 +1803,8 @@ void __dquot_free_space(struct inode *in
6392         struct dquot **dquots;
6393         int reserve = flags & DQUOT_SPACE_RESERVE, index;
6394  
6395 +       dl_free_space(inode, number);
6396 +
6397         if (!dquot_active(inode)) {
6398                 inode_decr_space(inode, number, reserve);
6399                 return;
6400 @@ -1841,6 +1849,8 @@ void dquot_free_inode(struct inode *inod
6401         struct dquot * const *dquots;
6402         int index;
6403  
6404 +       dl_free_inode(inode);
6405 +
6406         if (!dquot_active(inode))
6407                 return;
6408  
6409 diff -NurpP --minimal linux-4.4.115/fs/quota/quota.c linux-4.4.115-vs2.3.9.7/fs/quota/quota.c
6410 --- linux-4.4.115/fs/quota/quota.c      2016-07-05 04:12:34.000000000 +0000
6411 +++ linux-4.4.115-vs2.3.9.7/fs/quota/quota.c    2018-01-09 16:36:32.000000000 +0000
6412 @@ -8,6 +8,7 @@
6413  #include <linux/fs.h>
6414  #include <linux/namei.h>
6415  #include <linux/slab.h>
6416 +#include <linux/vs_context.h>
6417  #include <asm/current.h>
6418  #include <linux/uaccess.h>
6419  #include <linux/kernel.h>
6420 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6421                         break;
6422                 /*FALLTHROUGH*/
6423         default:
6424 -               if (!capable(CAP_SYS_ADMIN))
6425 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6426                         return -EPERM;
6427         }
6428  
6429 @@ -702,6 +703,46 @@ static int do_quotactl(struct super_bloc
6430  
6431  #ifdef CONFIG_BLOCK
6432  
6433 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6434 +
6435 +#include <linux/vroot.h>
6436 +#include <linux/major.h>
6437 +#include <linux/module.h>
6438 +#include <linux/kallsyms.h>
6439 +#include <linux/vserver/debug.h>
6440 +
6441 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6442 +
6443 +static DEFINE_SPINLOCK(vroot_grb_lock);
6444 +
6445 +int register_vroot_grb(vroot_grb_func *func) {
6446 +       int ret = -EBUSY;
6447 +
6448 +       spin_lock(&vroot_grb_lock);
6449 +       if (!vroot_get_real_bdev) {
6450 +               vroot_get_real_bdev = func;
6451 +               ret = 0;
6452 +       }
6453 +       spin_unlock(&vroot_grb_lock);
6454 +       return ret;
6455 +}
6456 +EXPORT_SYMBOL(register_vroot_grb);
6457 +
6458 +int unregister_vroot_grb(vroot_grb_func *func) {
6459 +       int ret = -EINVAL;
6460 +
6461 +       spin_lock(&vroot_grb_lock);
6462 +       if (vroot_get_real_bdev) {
6463 +               vroot_get_real_bdev = NULL;
6464 +               ret = 0;
6465 +       }
6466 +       spin_unlock(&vroot_grb_lock);
6467 +       return ret;
6468 +}
6469 +EXPORT_SYMBOL(unregister_vroot_grb);
6470 +
6471 +#endif
6472 +
6473  /* Return 1 if 'cmd' will block on frozen filesystem */
6474  static int quotactl_cmd_write(int cmd)
6475  {
6476 @@ -737,6 +778,22 @@ static struct super_block *quotactl_bloc
6477         putname(tmp);
6478         if (IS_ERR(bdev))
6479                 return ERR_CAST(bdev);
6480 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6481 +       if (bdev && bdev->bd_inode &&
6482 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6483 +               struct block_device *bdnew = (void *)-EINVAL;
6484 +
6485 +               if (vroot_get_real_bdev)
6486 +                       bdnew = vroot_get_real_bdev(bdev);
6487 +               else
6488 +                       vxdprintk(VXD_CBIT(misc, 0),
6489 +                                       "vroot_get_real_bdev not set");
6490 +               bdput(bdev);
6491 +               if (IS_ERR(bdnew))
6492 +                       return ERR_PTR(PTR_ERR(bdnew));
6493 +               bdev = bdnew;
6494 +       }
6495 +#endif
6496         if (quotactl_cmd_write(cmd))
6497                 sb = get_super_thawed(bdev);
6498         else
6499 diff -NurpP --minimal linux-4.4.115/fs/stat.c linux-4.4.115-vs2.3.9.7/fs/stat.c
6500 --- linux-4.4.115/fs/stat.c     2018-02-10 14:38:49.000000000 +0000
6501 +++ linux-4.4.115-vs2.3.9.7/fs/stat.c   2018-01-09 16:36:32.000000000 +0000
6502 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6503         stat->nlink = inode->i_nlink;
6504         stat->uid = inode->i_uid;
6505         stat->gid = inode->i_gid;
6506 +       stat->tag = inode->i_tag;
6507         stat->rdev = inode->i_rdev;
6508         stat->size = i_size_read(inode);
6509         stat->atime = inode->i_atime;
6510 diff -NurpP --minimal linux-4.4.115/fs/statfs.c linux-4.4.115-vs2.3.9.7/fs/statfs.c
6511 --- linux-4.4.115/fs/statfs.c   2015-04-12 22:12:50.000000000 +0000
6512 +++ linux-4.4.115-vs2.3.9.7/fs/statfs.c 2018-01-09 16:36:32.000000000 +0000
6513 @@ -7,6 +7,8 @@
6514  #include <linux/statfs.h>
6515  #include <linux/security.h>
6516  #include <linux/uaccess.h>
6517 +#include <linux/vs_base.h>
6518 +#include <linux/vs_dlimit.h>
6519  #include "internal.h"
6520  
6521  static int flags_by_mnt(int mnt_flags)
6522 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6523         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6524         if (retval == 0 && buf->f_frsize == 0)
6525                 buf->f_frsize = buf->f_bsize;
6526 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6527 +               vx_vsi_statfs(dentry->d_sb, buf);
6528         return retval;
6529  }
6530  
6531 diff -NurpP --minimal linux-4.4.115/fs/super.c linux-4.4.115-vs2.3.9.7/fs/super.c
6532 --- linux-4.4.115/fs/super.c    2018-02-10 14:38:49.000000000 +0000
6533 +++ linux-4.4.115-vs2.3.9.7/fs/super.c  2018-01-09 16:36:32.000000000 +0000
6534 @@ -33,6 +33,8 @@
6535  #include <linux/cleancache.h>
6536  #include <linux/fsnotify.h>
6537  #include <linux/lockdep.h>
6538 +#include <linux/magic.h>
6539 +#include <linux/vs_context.h>
6540  #include "internal.h"
6541  
6542  
6543 @@ -1131,6 +1133,13 @@ mount_fs(struct file_system_type *type,
6544         WARN_ON(!sb->s_bdi);
6545         sb->s_flags |= MS_BORN;
6546  
6547 +       error = -EPERM;
6548 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6549 +               !sb->s_bdev &&
6550 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6551 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6552 +               goto out_sb;
6553 +
6554         error = security_sb_kern_mount(sb, flags, secdata);
6555         if (error)
6556                 goto out_sb;
6557 diff -NurpP --minimal linux-4.4.115/fs/utimes.c linux-4.4.115-vs2.3.9.7/fs/utimes.c
6558 --- linux-4.4.115/fs/utimes.c   2018-02-10 14:38:49.000000000 +0000
6559 +++ linux-4.4.115-vs2.3.9.7/fs/utimes.c 2018-01-09 16:36:32.000000000 +0000
6560 @@ -8,6 +8,8 @@
6561  #include <linux/stat.h>
6562  #include <linux/utime.h>
6563  #include <linux/syscalls.h>
6564 +#include <linux/mount.h>
6565 +#include <linux/vs_cowbl.h>
6566  #include <asm/uaccess.h>
6567  #include <asm/unistd.h>
6568  
6569 @@ -52,13 +54,19 @@ static int utimes_common(struct path *pa
6570  {
6571         int error;
6572         struct iattr newattrs;
6573 -       struct inode *inode = path->dentry->d_inode;
6574         struct inode *delegated_inode = NULL;
6575 +       struct inode *inode;
6576 +
6577 +       error = cow_check_and_break(path);
6578 +       if (error)
6579 +               goto out;
6580  
6581         error = mnt_want_write(path->mnt);
6582         if (error)
6583                 goto out;
6584  
6585 +       inode = path->dentry->d_inode;
6586 +
6587         if (times && times[0].tv_nsec == UTIME_NOW &&
6588                      times[1].tv_nsec == UTIME_NOW)
6589                 times = NULL;
6590 diff -NurpP --minimal linux-4.4.115/fs/xattr.c linux-4.4.115-vs2.3.9.7/fs/xattr.c
6591 --- linux-4.4.115/fs/xattr.c    2018-02-10 14:38:49.000000000 +0000
6592 +++ linux-4.4.115-vs2.3.9.7/fs/xattr.c  2018-01-09 16:36:32.000000000 +0000
6593 @@ -21,6 +21,7 @@
6594  #include <linux/audit.h>
6595  #include <linux/vmalloc.h>
6596  #include <linux/posix_acl_xattr.h>
6597 +#include <linux/mount.h>
6598  
6599  #include <asm/uaccess.h>
6600  
6601 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6602          * The trusted.* namespace can only be accessed by privileged users.
6603          */
6604         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6605 -               if (!capable(CAP_SYS_ADMIN))
6606 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6607                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6608                 return 0;
6609         }
6610 diff -NurpP --minimal linux-4.4.115/include/linux/capability.h linux-4.4.115-vs2.3.9.7/include/linux/capability.h
6611 --- linux-4.4.115/include/linux/capability.h    2018-02-10 14:38:52.000000000 +0000
6612 +++ linux-4.4.115-vs2.3.9.7/include/linux/capability.h  2018-01-09 16:36:32.000000000 +0000
6613 @@ -77,7 +77,8 @@ extern const kernel_cap_t __cap_init_eff
6614  #else /* HAND-CODED capability initializers */
6615  
6616  #define CAP_LAST_U32                   ((_KERNEL_CAPABILITY_U32S) - 1)
6617 -#define CAP_LAST_U32_VALID_MASK                (CAP_TO_MASK(CAP_LAST_CAP + 1) -1)
6618 +#define CAP_LAST_U32_VALID_MASK                ((CAP_TO_MASK(CAP_LAST_CAP + 1) -1) \
6619 +                                       | CAP_TO_MASK(CAP_CONTEXT))
6620  
6621  # define CAP_EMPTY_SET    ((kernel_cap_t){{ 0, 0 }})
6622  # define CAP_FULL_SET     ((kernel_cap_t){{ ~0, CAP_LAST_U32_VALID_MASK }})
6623 diff -NurpP --minimal linux-4.4.115/include/linux/cred.h linux-4.4.115-vs2.3.9.7/include/linux/cred.h
6624 --- linux-4.4.115/include/linux/cred.h  2018-02-10 14:38:53.000000000 +0000
6625 +++ linux-4.4.115-vs2.3.9.7/include/linux/cred.h        2018-01-11 08:03:00.000000000 +0000
6626 @@ -161,6 +161,7 @@ extern void exit_creds(struct task_struc
6627  extern int copy_creds(struct task_struct *, unsigned long);
6628  extern const struct cred *get_task_cred(struct task_struct *);
6629  extern struct cred *cred_alloc_blank(void);
6630 +extern struct cred *__prepare_creds(const struct cred *);
6631  extern struct cred *prepare_creds(void);
6632  extern struct cred *prepare_exec_creds(void);
6633  extern int commit_creds(struct cred *);
6634 @@ -221,6 +222,31 @@ static inline bool cap_ambient_invariant
6635                                           cred->cap_inheritable));
6636  }
6637  
6638 +static inline void set_cred_subscribers(struct cred *cred, int n)
6639 +{
6640 +#ifdef CONFIG_DEBUG_CREDENTIALS
6641 +       atomic_set(&cred->subscribers, n);
6642 +#endif
6643 +}
6644 +
6645 +static inline int read_cred_subscribers(const struct cred *cred)
6646 +{
6647 +#ifdef CONFIG_DEBUG_CREDENTIALS
6648 +       return atomic_read(&cred->subscribers);
6649 +#else
6650 +       return 0;
6651 +#endif
6652 +}
6653 +
6654 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
6655 +{
6656 +#ifdef CONFIG_DEBUG_CREDENTIALS
6657 +       struct cred *cred = (struct cred *) _cred;
6658 +
6659 +       atomic_add(n, &cred->subscribers);
6660 +#endif
6661 +}
6662 +
6663  /**
6664   * get_new_cred - Get a reference on a new set of credentials
6665   * @cred: The new credentials to reference
6666 diff -NurpP --minimal linux-4.4.115/include/linux/dcache.h linux-4.4.115-vs2.3.9.7/include/linux/dcache.h
6667 --- linux-4.4.115/include/linux/dcache.h        2018-02-10 14:38:53.000000000 +0000
6668 +++ linux-4.4.115-vs2.3.9.7/include/linux/dcache.h      2018-01-09 16:36:32.000000000 +0000
6669 @@ -10,6 +10,7 @@
6670  #include <linux/cache.h>
6671  #include <linux/rcupdate.h>
6672  #include <linux/lockref.h>
6673 +// #include <linux/vs_limit.h>
6674  
6675  struct path;
6676  struct vfsmount;
6677 @@ -351,8 +352,10 @@ extern char *dentry_path(struct dentry *
6678   */
6679  static inline struct dentry *dget_dlock(struct dentry *dentry)
6680  {
6681 -       if (dentry)
6682 +       if (dentry) {
6683                 dentry->d_lockref.count++;
6684 +               // vx_dentry_inc(dentry);
6685 +       }
6686         return dentry;
6687  }
6688  
6689 diff -NurpP --minimal linux-4.4.115/include/linux/devpts_fs.h linux-4.4.115-vs2.3.9.7/include/linux/devpts_fs.h
6690 --- linux-4.4.115/include/linux/devpts_fs.h     2018-02-10 14:38:53.000000000 +0000
6691 +++ linux-4.4.115-vs2.3.9.7/include/linux/devpts_fs.h   2018-01-09 16:36:32.000000000 +0000
6692 @@ -35,5 +35,4 @@ void devpts_pty_kill(struct inode *inode
6693  
6694  #endif
6695  
6696 -
6697  #endif /* _LINUX_DEVPTS_FS_H */
6698 diff -NurpP --minimal linux-4.4.115/include/linux/fs.h linux-4.4.115-vs2.3.9.7/include/linux/fs.h
6699 --- linux-4.4.115/include/linux/fs.h    2018-02-10 14:38:53.000000000 +0000
6700 +++ linux-4.4.115-vs2.3.9.7/include/linux/fs.h  2018-01-09 16:43:56.000000000 +0000
6701 @@ -227,6 +227,7 @@ typedef void (dax_iodone_t)(struct buffe
6702  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
6703  #define ATTR_TIMES_SET (1 << 16)
6704  #define ATTR_TOUCH     (1 << 17)
6705 +#define ATTR_TAG       (1 << 18)
6706  
6707  /*
6708   * Whiteout is represented by a char device.  The following constants define the
6709 @@ -249,6 +250,7 @@ struct iattr {
6710         umode_t         ia_mode;
6711         kuid_t          ia_uid;
6712         kgid_t          ia_gid;
6713 +       ktag_t          ia_tag;
6714         loff_t          ia_size;
6715         struct timespec ia_atime;
6716         struct timespec ia_mtime;
6717 @@ -587,7 +589,9 @@ struct inode {
6718         unsigned short          i_opflags;
6719         kuid_t                  i_uid;
6720         kgid_t                  i_gid;
6721 -       unsigned int            i_flags;
6722 +       ktag_t                  i_tag;
6723 +       unsigned short          i_flags;
6724 +       unsigned short          i_vflags;
6725  
6726  #ifdef CONFIG_FS_POSIX_ACL
6727         struct posix_acl        *i_acl;
6728 @@ -616,6 +620,7 @@ struct inode {
6729                 unsigned int __i_nlink;
6730         };
6731         dev_t                   i_rdev;
6732 +       dev_t                   i_mdev;
6733         loff_t                  i_size;
6734         struct timespec         i_atime;
6735         struct timespec         i_mtime;
6736 @@ -814,6 +819,11 @@ static inline gid_t i_gid_read(const str
6737         return from_kgid(&init_user_ns, inode->i_gid);
6738  }
6739  
6740 +static inline vtag_t i_tag_read(const struct inode *inode)
6741 +{
6742 +       return from_ktag(&init_user_ns, inode->i_tag);
6743 +}
6744 +
6745  static inline void i_uid_write(struct inode *inode, uid_t uid)
6746  {
6747         inode->i_uid = make_kuid(&init_user_ns, uid);
6748 @@ -824,14 +834,19 @@ static inline void i_gid_write(struct in
6749         inode->i_gid = make_kgid(&init_user_ns, gid);
6750  }
6751  
6752 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
6753 +{
6754 +       inode->i_tag = make_ktag(&init_user_ns, tag);
6755 +}
6756 +
6757  static inline unsigned iminor(const struct inode *inode)
6758  {
6759 -       return MINOR(inode->i_rdev);
6760 +       return MINOR(inode->i_mdev);
6761  }
6762  
6763  static inline unsigned imajor(const struct inode *inode)
6764  {
6765 -       return MAJOR(inode->i_rdev);
6766 +       return MAJOR(inode->i_mdev);
6767  }
6768  
6769  extern struct block_device *I_BDEV(struct inode *inode);
6770 @@ -888,6 +903,7 @@ struct file {
6771         loff_t                  f_pos;
6772         struct fown_struct      f_owner;
6773         const struct cred       *f_cred;
6774 +       vxid_t                  f_xid;
6775         struct file_ra_state    f_ra;
6776  
6777         u64                     f_version;
6778 @@ -1022,6 +1038,7 @@ struct file_lock {
6779         struct file *fl_file;
6780         loff_t fl_start;
6781         loff_t fl_end;
6782 +       vxid_t fl_xid;
6783  
6784         struct fasync_struct *  fl_fasync; /* for lease break notifications */
6785         /* for lease breaks: */
6786 @@ -1698,6 +1715,7 @@ struct inode_operations {
6787         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
6788         ssize_t (*listxattr) (struct dentry *, char *, size_t);
6789         int (*removexattr) (struct dentry *, const char *);
6790 +       int (*sync_flags) (struct inode *, int, int);
6791         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
6792                       u64 len);
6793         int (*update_time)(struct inode *, struct timespec *, int);
6794 @@ -1712,6 +1730,7 @@ ssize_t rw_copy_check_uvector(int type,
6795                               unsigned long nr_segs, unsigned long fast_segs,
6796                               struct iovec *fast_pointer,
6797                               struct iovec **ret_pointer);
6798 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
6799  
6800  extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
6801  extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *);
6802 @@ -1777,6 +1796,14 @@ struct super_operations {
6803  #else
6804  #define S_DAX          0       /* Make all the DAX code disappear */
6805  #endif
6806 +#define S_IXUNLINK     16384   /* Immutable Invert on unlink */
6807 +
6808 +/* Linux-VServer related Inode flags */
6809 +
6810 +#define V_VALID                1
6811 +#define V_XATTR                2
6812 +#define V_BARRIER      4       /* Barrier for chroot() */
6813 +#define V_COW          8       /* Copy on Write */
6814  
6815  /*
6816   * Note that nosuid etc flags are inode-specific: setting some file-system
6817 @@ -1801,10 +1828,13 @@ struct super_operations {
6818  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
6819  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
6820  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
6821 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
6822  
6823  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
6824  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
6825  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
6826 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
6827 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
6828  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
6829  
6830  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
6831 @@ -1819,6 +1849,16 @@ struct super_operations {
6832  #define IS_WHITEOUT(inode)     (S_ISCHR(inode->i_mode) && \
6833                                  (inode)->i_rdev == WHITEOUT_DEV)
6834  
6835 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
6836 +
6837 +#ifdef CONFIG_VSERVER_COWBL
6838 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
6839 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
6840 +#else
6841 +#  define IS_COW(inode)                (0)
6842 +#  define IS_COW_LINK(inode)   (0)
6843 +#endif
6844 +
6845  /*
6846   * Inode state bits.  Protected by inode->i_lock
6847   *
6848 @@ -2075,6 +2115,9 @@ extern struct kobject *fs_kobj;
6849  extern int locks_mandatory_locked(struct file *);
6850  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
6851  
6852 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
6853 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
6854 +
6855  /*
6856   * Candidates for mandatory locking have the setgid bit set
6857   * but no group execute bit -  an otherwise meaningless combination.
6858 @@ -2830,6 +2873,7 @@ extern int dcache_dir_open(struct inode
6859  extern int dcache_dir_close(struct inode *, struct file *);
6860  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
6861  extern int dcache_readdir(struct file *, struct dir_context *);
6862 +extern int dcache_readdir_filter(struct file *, struct dir_context *, int (*)(struct dentry *));
6863  extern int simple_setattr(struct dentry *, struct iattr *);
6864  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
6865  extern int simple_statfs(struct dentry *, struct kstatfs *);
6866 diff -NurpP --minimal linux-4.4.115/include/linux/init_task.h linux-4.4.115-vs2.3.9.7/include/linux/init_task.h
6867 --- linux-4.4.115/include/linux/init_task.h     2016-07-05 04:15:10.000000000 +0000
6868 +++ linux-4.4.115-vs2.3.9.7/include/linux/init_task.h   2018-01-09 16:36:32.000000000 +0000
6869 @@ -260,6 +260,10 @@ extern struct task_group root_task_group
6870         INIT_VTIME(tsk)                                                 \
6871         INIT_NUMA_BALANCING(tsk)                                        \
6872         INIT_KASAN(tsk)                                                 \
6873 +       .xid            = 0,                                            \
6874 +       .vx_info        = NULL,                                         \
6875 +       .nid            = 0,                                            \
6876 +       .nx_info        = NULL,                                         \
6877  }
6878  
6879  
6880 diff -NurpP --minimal linux-4.4.115/include/linux/ipc.h linux-4.4.115-vs2.3.9.7/include/linux/ipc.h
6881 --- linux-4.4.115/include/linux/ipc.h   2015-04-12 22:12:50.000000000 +0000
6882 +++ linux-4.4.115-vs2.3.9.7/include/linux/ipc.h 2018-01-09 16:36:32.000000000 +0000
6883 @@ -16,6 +16,7 @@ struct kern_ipc_perm
6884         key_t           key;
6885         kuid_t          uid;
6886         kgid_t          gid;
6887 +       vxid_t          xid;
6888         kuid_t          cuid;
6889         kgid_t          cgid;
6890         umode_t         mode; 
6891 diff -NurpP --minimal linux-4.4.115/include/linux/memcontrol.h linux-4.4.115-vs2.3.9.7/include/linux/memcontrol.h
6892 --- linux-4.4.115/include/linux/memcontrol.h    2018-02-10 14:38:53.000000000 +0000
6893 +++ linux-4.4.115-vs2.3.9.7/include/linux/memcontrol.h  2018-01-24 22:44:17.000000000 +0000
6894 @@ -113,6 +113,7 @@ struct cg_proto {
6895         struct mem_cgroup       *memcg;
6896  };
6897  
6898 +
6899  #ifdef CONFIG_MEMCG
6900  struct mem_cgroup_stat_cpu {
6901         long count[MEM_CGROUP_STAT_NSTATS];
6902 @@ -338,6 +339,12 @@ static inline bool mem_cgroup_is_descend
6903         return cgroup_is_descendant(memcg->css.cgroup, root->css.cgroup);
6904  }
6905  
6906 +extern unsigned long mem_cgroup_mem_usage_pages(struct mem_cgroup *memcg);
6907 +extern unsigned long mem_cgroup_mem_limit_pages(struct mem_cgroup *memcg);
6908 +extern unsigned long mem_cgroup_memsw_usage_pages(struct mem_cgroup *memcg);
6909 +extern unsigned long mem_cgroup_memsw_limit_pages(struct mem_cgroup *memcg);
6910 +extern void dump_mem_cgroup(struct mem_cgroup *memcg);
6911 +
6912  static inline bool mm_match_cgroup(struct mm_struct *mm,
6913                                    struct mem_cgroup *memcg)
6914  {
6915 diff -NurpP --minimal linux-4.4.115/include/linux/mount.h linux-4.4.115-vs2.3.9.7/include/linux/mount.h
6916 --- linux-4.4.115/include/linux/mount.h 2018-02-10 14:38:54.000000000 +0000
6917 +++ linux-4.4.115-vs2.3.9.7/include/linux/mount.h       2018-01-09 16:36:32.000000000 +0000
6918 @@ -63,6 +63,9 @@ struct mnt_namespace;
6919  #define MNT_MARKED             0x4000000
6920  #define MNT_UMOUNT             0x8000000
6921  
6922 +#define MNT_TAGID      0x10000
6923 +#define MNT_NOTAG      0x20000
6924 +
6925  struct vfsmount {
6926         struct dentry *mnt_root;        /* root of the mounted tree */
6927         struct super_block *mnt_sb;     /* pointer to superblock */
6928 diff -NurpP --minimal linux-4.4.115/include/linux/net.h linux-4.4.115-vs2.3.9.7/include/linux/net.h
6929 --- linux-4.4.115/include/linux/net.h   2018-02-10 14:38:54.000000000 +0000
6930 +++ linux-4.4.115-vs2.3.9.7/include/linux/net.h 2018-01-09 16:42:30.000000000 +0000
6931 @@ -43,6 +43,7 @@ struct net;
6932  #define SOCK_NOSPACE           2
6933  #define SOCK_PASSCRED          3
6934  #define SOCK_PASSSEC           4
6935 +#define SOCK_USER_SOCKET       5
6936  
6937  #ifndef ARCH_HAS_SOCKET_TYPES
6938  /**
6939 diff -NurpP --minimal linux-4.4.115/include/linux/netdevice.h linux-4.4.115-vs2.3.9.7/include/linux/netdevice.h
6940 --- linux-4.4.115/include/linux/netdevice.h     2018-02-10 14:38:54.000000000 +0000
6941 +++ linux-4.4.115-vs2.3.9.7/include/linux/netdevice.h   2018-01-09 16:36:32.000000000 +0000
6942 @@ -2296,6 +2296,7 @@ static inline int dev_recursion_level(vo
6943  
6944  struct net_device *dev_get_by_index(struct net *net, int ifindex);
6945  struct net_device *__dev_get_by_index(struct net *net, int ifindex);
6946 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
6947  struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
6948  int netdev_get_name(struct net *net, char *name, int ifindex);
6949  int dev_restart(struct net_device *dev);
6950 diff -NurpP --minimal linux-4.4.115/include/linux/nsproxy.h linux-4.4.115-vs2.3.9.7/include/linux/nsproxy.h
6951 --- linux-4.4.115/include/linux/nsproxy.h       2015-04-12 22:12:50.000000000 +0000
6952 +++ linux-4.4.115-vs2.3.9.7/include/linux/nsproxy.h     2018-01-09 16:36:32.000000000 +0000
6953 @@ -3,6 +3,7 @@
6954  
6955  #include <linux/spinlock.h>
6956  #include <linux/sched.h>
6957 +#include <linux/vserver/debug.h>
6958  
6959  struct mnt_namespace;
6960  struct uts_namespace;
6961 @@ -63,6 +64,7 @@ extern struct nsproxy init_nsproxy;
6962   */
6963  
6964  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
6965 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
6966  void exit_task_namespaces(struct task_struct *tsk);
6967  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
6968  void free_nsproxy(struct nsproxy *ns);
6969 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
6970         struct cred *, struct fs_struct *);
6971  int __init nsproxy_cache_init(void);
6972  
6973 -static inline void put_nsproxy(struct nsproxy *ns)
6974 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
6975 +
6976 +static inline void __get_nsproxy(struct nsproxy *ns,
6977 +       const char *_file, int _line)
6978  {
6979 -       if (atomic_dec_and_test(&ns->count)) {
6980 -               free_nsproxy(ns);
6981 -       }
6982 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
6983 +               ns, atomic_read(&ns->count), _file, _line);
6984 +       atomic_inc(&ns->count);
6985  }
6986  
6987 -static inline void get_nsproxy(struct nsproxy *ns)
6988 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
6989 +
6990 +static inline void __put_nsproxy(struct nsproxy *ns,
6991 +       const char *_file, int _line)
6992  {
6993 -       atomic_inc(&ns->count);
6994 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
6995 +               ns, atomic_read(&ns->count), _file, _line);
6996 +       if (atomic_dec_and_test(&ns->count)) {
6997 +               free_nsproxy(ns);
6998 +       }
6999  }
7000  
7001  #endif
7002 diff -NurpP --minimal linux-4.4.115/include/linux/pid.h linux-4.4.115-vs2.3.9.7/include/linux/pid.h
7003 --- linux-4.4.115/include/linux/pid.h   2018-02-10 14:38:54.000000000 +0000
7004 +++ linux-4.4.115-vs2.3.9.7/include/linux/pid.h 2018-01-09 16:45:21.000000000 +0000
7005 @@ -10,7 +10,8 @@ enum pid_type
7006         PIDTYPE_SID,
7007         PIDTYPE_MAX,
7008         /* only valid to __task_pid_nr_ns() */
7009 -       __PIDTYPE_TGID
7010 +       __PIDTYPE_TGID,
7011 +       __PIDTYPE_REALPID
7012  };
7013  
7014  /*
7015 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
7016  }
7017  
7018  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7019 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7020  pid_t pid_vnr(struct pid *pid);
7021  
7022  #define do_each_pid_task(pid, type, task)                              \
7023 diff -NurpP --minimal linux-4.4.115/include/linux/quotaops.h linux-4.4.115-vs2.3.9.7/include/linux/quotaops.h
7024 --- linux-4.4.115/include/linux/quotaops.h      2016-07-05 04:12:37.000000000 +0000
7025 +++ linux-4.4.115-vs2.3.9.7/include/linux/quotaops.h    2018-01-09 16:36:32.000000000 +0000
7026 @@ -8,6 +8,7 @@
7027  #define _LINUX_QUOTAOPS_
7028  
7029  #include <linux/fs.h>
7030 +#include <linux/vs_dlimit.h>
7031  
7032  #define DQUOT_SPACE_WARN       0x1
7033  #define DQUOT_SPACE_RESERVE    0x2
7034 @@ -211,11 +212,12 @@ static inline void dquot_drop(struct ino
7035  
7036  static inline int dquot_alloc_inode(struct inode *inode)
7037  {
7038 -       return 0;
7039 +       return dl_alloc_inode(inode);
7040  }
7041  
7042  static inline void dquot_free_inode(struct inode *inode)
7043  {
7044 +       dl_free_inode(inode);
7045  }
7046  
7047  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7048 @@ -226,6 +228,10 @@ static inline int dquot_transfer(struct
7049  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7050                 int flags)
7051  {
7052 +       int ret = 0;
7053 +
7054 +       if ((ret = dl_alloc_space(inode, number)))
7055 +               return ret;
7056         if (!(flags & DQUOT_SPACE_RESERVE))
7057                 inode_add_bytes(inode, number);
7058         return 0;
7059 @@ -236,6 +242,7 @@ static inline void __dquot_free_space(st
7060  {
7061         if (!(flags & DQUOT_SPACE_RESERVE))
7062                 inode_sub_bytes(inode, number);
7063 +       dl_free_space(inode, number);
7064  }
7065  
7066  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7067 diff -NurpP --minimal linux-4.4.115/include/linux/sched.h linux-4.4.115-vs2.3.9.7/include/linux/sched.h
7068 --- linux-4.4.115/include/linux/sched.h 2018-02-10 14:38:54.000000000 +0000
7069 +++ linux-4.4.115-vs2.3.9.7/include/linux/sched.h       2018-02-10 15:16:50.000000000 +0000
7070 @@ -1601,6 +1601,14 @@ struct task_struct {
7071  #endif
7072         struct seccomp seccomp;
7073  
7074 +/* vserver context data */
7075 +       struct vx_info *vx_info;
7076 +       struct nx_info *nx_info;
7077 +
7078 +       vxid_t xid;
7079 +       vnid_t nid;
7080 +       vtag_t tag;
7081 +
7082  /* Thread group tracking */
7083         u32 parent_exec_id;
7084         u32 self_exec_id;
7085 @@ -1928,6 +1936,11 @@ struct pid_namespace;
7086  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
7087                         struct pid_namespace *ns);
7088  
7089 +#include <linux/vserver/base.h>
7090 +#include <linux/vserver/context.h>
7091 +#include <linux/vserver/debug.h>
7092 +#include <linux/vserver/pid.h>
7093 +
7094  static inline pid_t task_pid_nr(struct task_struct *tsk)
7095  {
7096         return tsk->pid;
7097 @@ -1941,7 +1954,8 @@ static inline pid_t task_pid_nr_ns(struc
7098  
7099  static inline pid_t task_pid_vnr(struct task_struct *tsk)
7100  {
7101 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7102 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7103 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
7104  }
7105  
7106  
7107 diff -NurpP --minimal linux-4.4.115/include/linux/shmem_fs.h linux-4.4.115-vs2.3.9.7/include/linux/shmem_fs.h
7108 --- linux-4.4.115/include/linux/shmem_fs.h      2018-02-10 14:38:54.000000000 +0000
7109 +++ linux-4.4.115-vs2.3.9.7/include/linux/shmem_fs.h    2018-01-09 16:36:32.000000000 +0000
7110 @@ -10,6 +10,9 @@
7111  
7112  /* inode in-kernel data */
7113  
7114 +#define TMPFS_SUPER_MAGIC      0x01021994
7115 +
7116 +
7117  struct shmem_inode_info {
7118         spinlock_t              lock;
7119         unsigned int            seals;          /* shmem seals */
7120 diff -NurpP --minimal linux-4.4.115/include/linux/stat.h linux-4.4.115-vs2.3.9.7/include/linux/stat.h
7121 --- linux-4.4.115/include/linux/stat.h  2015-04-12 22:12:50.000000000 +0000
7122 +++ linux-4.4.115-vs2.3.9.7/include/linux/stat.h        2018-01-09 16:36:32.000000000 +0000
7123 @@ -25,6 +25,7 @@ struct kstat {
7124         unsigned int    nlink;
7125         kuid_t          uid;
7126         kgid_t          gid;
7127 +       ktag_t          tag;
7128         dev_t           rdev;
7129         loff_t          size;
7130         struct timespec  atime;
7131 diff -NurpP --minimal linux-4.4.115/include/linux/sunrpc/auth.h linux-4.4.115-vs2.3.9.7/include/linux/sunrpc/auth.h
7132 --- linux-4.4.115/include/linux/sunrpc/auth.h   2016-07-05 04:12:37.000000000 +0000
7133 +++ linux-4.4.115-vs2.3.9.7/include/linux/sunrpc/auth.h 2018-01-09 16:36:32.000000000 +0000
7134 @@ -40,6 +40,7 @@ enum {
7135  struct auth_cred {
7136         kuid_t  uid;
7137         kgid_t  gid;
7138 +       ktag_t  tag;
7139         struct group_info *group_info;
7140         const char *principal;
7141         unsigned long ac_flags;
7142 diff -NurpP --minimal linux-4.4.115/include/linux/sunrpc/clnt.h linux-4.4.115-vs2.3.9.7/include/linux/sunrpc/clnt.h
7143 --- linux-4.4.115/include/linux/sunrpc/clnt.h   2018-02-10 14:38:55.000000000 +0000
7144 +++ linux-4.4.115-vs2.3.9.7/include/linux/sunrpc/clnt.h 2018-01-09 16:36:32.000000000 +0000
7145 @@ -51,7 +51,8 @@ struct rpc_clnt {
7146                                 cl_discrtry : 1,/* disconnect before retry */
7147                                 cl_noretranstimeo: 1,/* No retransmit timeouts */
7148                                 cl_autobind : 1,/* use getport() */
7149 -                               cl_chatty   : 1;/* be verbose */
7150 +                               cl_chatty   : 1,/* be verbose */
7151 +                               cl_tag      : 1;/* context tagging */
7152  
7153         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
7154         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
7155 diff -NurpP --minimal linux-4.4.115/include/linux/types.h linux-4.4.115-vs2.3.9.7/include/linux/types.h
7156 --- linux-4.4.115/include/linux/types.h 2016-07-05 04:15:11.000000000 +0000
7157 +++ linux-4.4.115-vs2.3.9.7/include/linux/types.h       2018-01-09 16:36:32.000000000 +0000
7158 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
7159  typedef __kernel_gid32_t       gid_t;
7160  typedef __kernel_uid16_t        uid16_t;
7161  typedef __kernel_gid16_t        gid16_t;
7162 +typedef unsigned int           vxid_t;
7163 +typedef unsigned int           vnid_t;
7164 +typedef unsigned int           vtag_t;
7165  
7166  typedef unsigned long          uintptr_t;
7167  
7168 diff -NurpP --minimal linux-4.4.115/include/linux/uidgid.h linux-4.4.115-vs2.3.9.7/include/linux/uidgid.h
7169 --- linux-4.4.115/include/linux/uidgid.h        2015-07-06 20:41:43.000000000 +0000
7170 +++ linux-4.4.115-vs2.3.9.7/include/linux/uidgid.h      2018-01-09 16:36:32.000000000 +0000
7171 @@ -21,13 +21,17 @@ typedef struct {
7172         uid_t val;
7173  } kuid_t;
7174  
7175 -
7176  typedef struct {
7177         gid_t val;
7178  } kgid_t;
7179  
7180 +typedef struct {
7181 +       vtag_t val;
7182 +} ktag_t;
7183 +
7184  #define KUIDT_INIT(value) (kuid_t){ value }
7185  #define KGIDT_INIT(value) (kgid_t){ value }
7186 +#define KTAGT_INIT(value) (ktag_t){ value }
7187  
7188  #ifdef CONFIG_MULTIUSER
7189  static inline uid_t __kuid_val(kuid_t uid)
7190 @@ -51,11 +55,18 @@ static inline gid_t __kgid_val(kgid_t gi
7191  }
7192  #endif
7193  
7194 +static inline vtag_t __ktag_val(ktag_t tag)
7195 +{
7196 +       return tag.val;
7197 +}
7198 +
7199  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
7200  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
7201 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
7202  
7203  #define INVALID_UID KUIDT_INIT(-1)
7204  #define INVALID_GID KGIDT_INIT(-1)
7205 +#define INVALID_TAG KTAGT_INIT(-1)
7206  
7207  static inline bool uid_eq(kuid_t left, kuid_t right)
7208  {
7209 @@ -67,6 +78,11 @@ static inline bool gid_eq(kgid_t left, k
7210         return __kgid_val(left) == __kgid_val(right);
7211  }
7212  
7213 +static inline bool tag_eq(ktag_t left, ktag_t right)
7214 +{
7215 +       return __ktag_val(left) == __ktag_val(right);
7216 +}
7217 +
7218  static inline bool uid_gt(kuid_t left, kuid_t right)
7219  {
7220         return __kuid_val(left) > __kuid_val(right);
7221 @@ -117,13 +133,21 @@ static inline bool gid_valid(kgid_t gid)
7222         return __kgid_val(gid) != (gid_t) -1;
7223  }
7224  
7225 +static inline bool tag_valid(ktag_t tag)
7226 +{
7227 +       return !tag_eq(tag, INVALID_TAG);
7228 +}
7229 +
7230  #ifdef CONFIG_USER_NS
7231  
7232  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
7233  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
7234 +extern ktag_t make_ktag(struct user_namespace *from, gid_t gid);
7235  
7236  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
7237  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
7238 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
7239 +
7240  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
7241  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
7242  
7243 @@ -149,6 +173,11 @@ static inline kgid_t make_kgid(struct us
7244         return KGIDT_INIT(gid);
7245  }
7246  
7247 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
7248 +{
7249 +       return KTAGT_INIT(tag);
7250 +}
7251 +
7252  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
7253  {
7254         return __kuid_val(kuid);
7255 @@ -159,6 +188,11 @@ static inline gid_t from_kgid(struct use
7256         return __kgid_val(kgid);
7257  }
7258  
7259 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
7260 +{
7261 +       return __ktag_val(ktag);
7262 +}
7263 +
7264  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
7265  {
7266         uid_t uid = from_kuid(to, kuid);
7267 diff -NurpP --minimal linux-4.4.115/include/linux/vroot.h linux-4.4.115-vs2.3.9.7/include/linux/vroot.h
7268 --- linux-4.4.115/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
7269 +++ linux-4.4.115-vs2.3.9.7/include/linux/vroot.h       2018-01-09 16:36:32.000000000 +0000
7270 @@ -0,0 +1,51 @@
7271 +
7272 +/*
7273 + * include/linux/vroot.h
7274 + *
7275 + * written by Herbert Pötzl, 9/11/2002
7276 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
7277 + *
7278 + * Copyright (C) 2002-2007 by Herbert Pötzl.
7279 + * Redistribution of this file is permitted under the
7280 + * GNU General Public License.
7281 + */
7282 +
7283 +#ifndef _LINUX_VROOT_H
7284 +#define _LINUX_VROOT_H
7285 +
7286 +
7287 +#ifdef __KERNEL__
7288 +
7289 +/* Possible states of device */
7290 +enum {
7291 +       Vr_unbound,
7292 +       Vr_bound,
7293 +};
7294 +
7295 +struct vroot_device {
7296 +       int             vr_number;
7297 +       int             vr_refcnt;
7298 +
7299 +       struct semaphore        vr_ctl_mutex;
7300 +       struct block_device    *vr_device;
7301 +       int                     vr_state;
7302 +};
7303 +
7304 +
7305 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
7306 +
7307 +extern int register_vroot_grb(vroot_grb_func *);
7308 +extern int unregister_vroot_grb(vroot_grb_func *);
7309 +
7310 +#endif /* __KERNEL__ */
7311 +
7312 +#define MAX_VROOT_DEFAULT      8
7313 +
7314 +/*
7315 + * IOCTL commands --- we will commandeer 0x56 ('V')
7316 + */
7317 +
7318 +#define VROOT_SET_DEV          0x5600
7319 +#define VROOT_CLR_DEV          0x5601
7320 +
7321 +#endif /* _LINUX_VROOT_H */
7322 diff -NurpP --minimal linux-4.4.115/include/linux/vs_base.h linux-4.4.115-vs2.3.9.7/include/linux/vs_base.h
7323 --- linux-4.4.115/include/linux/vs_base.h       1970-01-01 00:00:00.000000000 +0000
7324 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_base.h     2018-01-09 16:36:32.000000000 +0000
7325 @@ -0,0 +1,10 @@
7326 +#ifndef _VS_BASE_H
7327 +#define _VS_BASE_H
7328 +
7329 +#include "vserver/base.h"
7330 +#include "vserver/check.h"
7331 +#include "vserver/debug.h"
7332 +
7333 +#else
7334 +#warning duplicate inclusion
7335 +#endif
7336 diff -NurpP --minimal linux-4.4.115/include/linux/vs_context.h linux-4.4.115-vs2.3.9.7/include/linux/vs_context.h
7337 --- linux-4.4.115/include/linux/vs_context.h    1970-01-01 00:00:00.000000000 +0000
7338 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_context.h  2018-01-09 16:36:32.000000000 +0000
7339 @@ -0,0 +1,242 @@
7340 +#ifndef _VS_CONTEXT_H
7341 +#define _VS_CONTEXT_H
7342 +
7343 +#include "vserver/base.h"
7344 +#include "vserver/check.h"
7345 +#include "vserver/context.h"
7346 +#include "vserver/history.h"
7347 +#include "vserver/debug.h"
7348 +
7349 +#include <linux/sched.h>
7350 +
7351 +
7352 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
7353 +
7354 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
7355 +       const char *_file, int _line, void *_here)
7356 +{
7357 +       if (!vxi)
7358 +               return NULL;
7359 +
7360 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
7361 +               vxi, vxi ? vxi->vx_id : 0,
7362 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7363 +               _file, _line);
7364 +       __vxh_get_vx_info(vxi, _here);
7365 +
7366 +       atomic_inc(&vxi->vx_usecnt);
7367 +       return vxi;
7368 +}
7369 +
7370 +
7371 +extern void free_vx_info(struct vx_info *);
7372 +
7373 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
7374 +
7375 +static inline void __put_vx_info(struct vx_info *vxi,
7376 +       const char *_file, int _line, void *_here)
7377 +{
7378 +       if (!vxi)
7379 +               return;
7380 +
7381 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
7382 +               vxi, vxi ? vxi->vx_id : 0,
7383 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7384 +               _file, _line);
7385 +       __vxh_put_vx_info(vxi, _here);
7386 +
7387 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
7388 +               free_vx_info(vxi);
7389 +}
7390 +
7391 +
7392 +#define init_vx_info(p, i) \
7393 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7394 +
7395 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7396 +       const char *_file, int _line, void *_here)
7397 +{
7398 +       if (vxi) {
7399 +               vxlprintk(VXD_CBIT(xid, 3),
7400 +                       "init_vx_info(%p[#%d.%d])",
7401 +                       vxi, vxi ? vxi->vx_id : 0,
7402 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7403 +                       _file, _line);
7404 +               __vxh_init_vx_info(vxi, vxp, _here);
7405 +
7406 +               atomic_inc(&vxi->vx_usecnt);
7407 +       }
7408 +       *vxp = vxi;
7409 +}
7410 +
7411 +
7412 +#define set_vx_info(p, i) \
7413 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7414 +
7415 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7416 +       const char *_file, int _line, void *_here)
7417 +{
7418 +       struct vx_info *vxo;
7419 +
7420 +       if (!vxi)
7421 +               return;
7422 +
7423 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
7424 +               vxi, vxi ? vxi->vx_id : 0,
7425 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7426 +               _file, _line);
7427 +       __vxh_set_vx_info(vxi, vxp, _here);
7428 +
7429 +       atomic_inc(&vxi->vx_usecnt);
7430 +       vxo = xchg(vxp, vxi);
7431 +       BUG_ON(vxo);
7432 +}
7433 +
7434 +
7435 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
7436 +
7437 +static inline void __clr_vx_info(struct vx_info **vxp,
7438 +       const char *_file, int _line, void *_here)
7439 +{
7440 +       struct vx_info *vxo;
7441 +
7442 +       vxo = xchg(vxp, NULL);
7443 +       if (!vxo)
7444 +               return;
7445 +
7446 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
7447 +               vxo, vxo ? vxo->vx_id : 0,
7448 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
7449 +               _file, _line);
7450 +       __vxh_clr_vx_info(vxo, vxp, _here);
7451 +
7452 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
7453 +               free_vx_info(vxo);
7454 +}
7455 +
7456 +
7457 +#define claim_vx_info(v, p) \
7458 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7459 +
7460 +static inline void __claim_vx_info(struct vx_info *vxi,
7461 +       struct task_struct *task,
7462 +       const char *_file, int _line, void *_here)
7463 +{
7464 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
7465 +               vxi, vxi ? vxi->vx_id : 0,
7466 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7467 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7468 +               task, _file, _line);
7469 +       __vxh_claim_vx_info(vxi, task, _here);
7470 +
7471 +       atomic_inc(&vxi->vx_tasks);
7472 +}
7473 +
7474 +
7475 +extern void unhash_vx_info(struct vx_info *);
7476 +
7477 +#define release_vx_info(v, p) \
7478 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7479 +
7480 +static inline void __release_vx_info(struct vx_info *vxi,
7481 +       struct task_struct *task,
7482 +       const char *_file, int _line, void *_here)
7483 +{
7484 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
7485 +               vxi, vxi ? vxi->vx_id : 0,
7486 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7487 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7488 +               task, _file, _line);
7489 +       __vxh_release_vx_info(vxi, task, _here);
7490 +
7491 +       might_sleep();
7492 +
7493 +       if (atomic_dec_and_test(&vxi->vx_tasks))
7494 +               unhash_vx_info(vxi);
7495 +}
7496 +
7497 +
7498 +#define task_get_vx_info(p) \
7499 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
7500 +
7501 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
7502 +       const char *_file, int _line, void *_here)
7503 +{
7504 +       struct vx_info *vxi;
7505 +
7506 +       task_lock(p);
7507 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
7508 +               p, _file, _line);
7509 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
7510 +       task_unlock(p);
7511 +       return vxi;
7512 +}
7513 +
7514 +
7515 +static inline void __wakeup_vx_info(struct vx_info *vxi)
7516 +{
7517 +       if (waitqueue_active(&vxi->vx_wait))
7518 +               wake_up_interruptible(&vxi->vx_wait);
7519 +}
7520 +
7521 +
7522 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
7523 +
7524 +static inline void __enter_vx_info(struct vx_info *vxi,
7525 +       struct vx_info_save *vxis, const char *_file, int _line)
7526 +{
7527 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
7528 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
7529 +               current->xid, current->vx_info, _file, _line);
7530 +       vxis->vxi = xchg(&current->vx_info, vxi);
7531 +       vxis->xid = current->xid;
7532 +       current->xid = vxi ? vxi->vx_id : 0;
7533 +}
7534 +
7535 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
7536 +
7537 +static inline void __leave_vx_info(struct vx_info_save *vxis,
7538 +       const char *_file, int _line)
7539 +{
7540 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
7541 +               vxis, vxis->xid, vxis->vxi, current,
7542 +               current->xid, current->vx_info, _file, _line);
7543 +       (void)xchg(&current->vx_info, vxis->vxi);
7544 +       current->xid = vxis->xid;
7545 +}
7546 +
7547 +
7548 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
7549 +{
7550 +       vxis->vxi = xchg(&current->vx_info, NULL);
7551 +       vxis->xid = xchg(&current->xid, (vxid_t)0);
7552 +}
7553 +
7554 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
7555 +{
7556 +       (void)xchg(&current->xid, vxis->xid);
7557 +       (void)xchg(&current->vx_info, vxis->vxi);
7558 +}
7559 +
7560 +#define task_is_init(p) \
7561 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
7562 +
7563 +static inline int __task_is_init(struct task_struct *p,
7564 +       const char *_file, int _line, void *_here)
7565 +{
7566 +       int is_init = is_global_init(p);
7567 +
7568 +       task_lock(p);
7569 +       if (p->vx_info)
7570 +               is_init = p->vx_info->vx_initpid == p->pid;
7571 +       task_unlock(p);
7572 +       return is_init;
7573 +}
7574 +
7575 +extern void exit_vx_info(struct task_struct *, int);
7576 +extern void exit_vx_info_early(struct task_struct *, int);
7577 +
7578 +
7579 +#else
7580 +#warning duplicate inclusion
7581 +#endif
7582 diff -NurpP --minimal linux-4.4.115/include/linux/vs_cowbl.h linux-4.4.115-vs2.3.9.7/include/linux/vs_cowbl.h
7583 --- linux-4.4.115/include/linux/vs_cowbl.h      1970-01-01 00:00:00.000000000 +0000
7584 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_cowbl.h    2018-01-09 16:36:32.000000000 +0000
7585 @@ -0,0 +1,48 @@
7586 +#ifndef _VS_COWBL_H
7587 +#define _VS_COWBL_H
7588 +
7589 +#include <linux/fs.h>
7590 +#include <linux/dcache.h>
7591 +#include <linux/namei.h>
7592 +#include <linux/slab.h>
7593 +
7594 +extern struct dentry *cow_break_link(const char *pathname);
7595 +
7596 +static inline int cow_check_and_break(struct path *path)
7597 +{
7598 +       struct inode *inode = path->dentry->d_inode;
7599 +       int error = 0;
7600 +
7601 +       /* do we need this check? */
7602 +       if (IS_RDONLY(inode))
7603 +               return -EROFS;
7604 +
7605 +       if (IS_COW(inode)) {
7606 +               if (IS_COW_LINK(inode)) {
7607 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
7608 +                       char *pp, *buf;
7609 +
7610 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
7611 +                       if (!buf) {
7612 +                               return -ENOMEM;
7613 +                       }
7614 +                       pp = d_path(path, buf, PATH_MAX);
7615 +                       new_dentry = cow_break_link(pp);
7616 +                       kfree(buf);
7617 +                       if (!IS_ERR(new_dentry)) {
7618 +                               path->dentry = new_dentry;
7619 +                               dput(old_dentry);
7620 +                       } else
7621 +                               error = PTR_ERR(new_dentry);
7622 +               } else {
7623 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
7624 +                       inode->i_ctime = CURRENT_TIME;
7625 +                       mark_inode_dirty(inode);
7626 +               }
7627 +       }
7628 +       return error;
7629 +}
7630 +
7631 +#else
7632 +#warning duplicate inclusion
7633 +#endif
7634 diff -NurpP --minimal linux-4.4.115/include/linux/vs_cvirt.h linux-4.4.115-vs2.3.9.7/include/linux/vs_cvirt.h
7635 --- linux-4.4.115/include/linux/vs_cvirt.h      1970-01-01 00:00:00.000000000 +0000
7636 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_cvirt.h    2018-01-09 16:36:32.000000000 +0000
7637 @@ -0,0 +1,50 @@
7638 +#ifndef _VS_CVIRT_H
7639 +#define _VS_CVIRT_H
7640 +
7641 +#include "vserver/cvirt.h"
7642 +#include "vserver/context.h"
7643 +#include "vserver/base.h"
7644 +#include "vserver/check.h"
7645 +#include "vserver/debug.h"
7646 +
7647 +
7648 +static inline void vx_activate_task(struct task_struct *p)
7649 +{
7650 +       struct vx_info *vxi;
7651 +
7652 +       if ((vxi = p->vx_info)) {
7653 +               vx_update_load(vxi);
7654 +               atomic_inc(&vxi->cvirt.nr_running);
7655 +       }
7656 +}
7657 +
7658 +static inline void vx_deactivate_task(struct task_struct *p)
7659 +{
7660 +       struct vx_info *vxi;
7661 +
7662 +       if ((vxi = p->vx_info)) {
7663 +               vx_update_load(vxi);
7664 +               atomic_dec(&vxi->cvirt.nr_running);
7665 +       }
7666 +}
7667 +
7668 +static inline void vx_uninterruptible_inc(struct task_struct *p)
7669 +{
7670 +       struct vx_info *vxi;
7671 +
7672 +       if ((vxi = p->vx_info))
7673 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
7674 +}
7675 +
7676 +static inline void vx_uninterruptible_dec(struct task_struct *p)
7677 +{
7678 +       struct vx_info *vxi;
7679 +
7680 +       if ((vxi = p->vx_info))
7681 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
7682 +}
7683 +
7684 +
7685 +#else
7686 +#warning duplicate inclusion
7687 +#endif
7688 diff -NurpP --minimal linux-4.4.115/include/linux/vs_device.h linux-4.4.115-vs2.3.9.7/include/linux/vs_device.h
7689 --- linux-4.4.115/include/linux/vs_device.h     1970-01-01 00:00:00.000000000 +0000
7690 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_device.h   2018-01-09 16:36:32.000000000 +0000
7691 @@ -0,0 +1,45 @@
7692 +#ifndef _VS_DEVICE_H
7693 +#define _VS_DEVICE_H
7694 +
7695 +#include "vserver/base.h"
7696 +#include "vserver/device.h"
7697 +#include "vserver/debug.h"
7698 +
7699 +
7700 +#ifdef CONFIG_VSERVER_DEVICE
7701 +
7702 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
7703 +
7704 +#define vs_device_perm(v, d, m, p) \
7705 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
7706 +
7707 +#else
7708 +
7709 +static inline
7710 +int vs_map_device(struct vx_info *vxi,
7711 +       dev_t device, dev_t *target, umode_t mode)
7712 +{
7713 +       if (target)
7714 +               *target = device;
7715 +       return ~0;
7716 +}
7717 +
7718 +#define vs_device_perm(v, d, m, p) ((p) == (p))
7719 +
7720 +#endif
7721 +
7722 +
7723 +#define vs_map_chrdev(d, t, p) \
7724 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
7725 +#define vs_map_blkdev(d, t, p) \
7726 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
7727 +
7728 +#define vs_chrdev_perm(d, p) \
7729 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
7730 +#define vs_blkdev_perm(d, p) \
7731 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
7732 +
7733 +
7734 +#else
7735 +#warning duplicate inclusion
7736 +#endif
7737 diff -NurpP --minimal linux-4.4.115/include/linux/vs_dlimit.h linux-4.4.115-vs2.3.9.7/include/linux/vs_dlimit.h
7738 --- linux-4.4.115/include/linux/vs_dlimit.h     1970-01-01 00:00:00.000000000 +0000
7739 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_dlimit.h   2018-01-09 16:36:32.000000000 +0000
7740 @@ -0,0 +1,215 @@
7741 +#ifndef _VS_DLIMIT_H
7742 +#define _VS_DLIMIT_H
7743 +
7744 +#include <linux/fs.h>
7745 +
7746 +#include "vserver/dlimit.h"
7747 +#include "vserver/base.h"
7748 +#include "vserver/debug.h"
7749 +
7750 +
7751 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
7752 +
7753 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
7754 +       const char *_file, int _line)
7755 +{
7756 +       if (!dli)
7757 +               return NULL;
7758 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
7759 +               dli, dli ? dli->dl_tag : 0,
7760 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
7761 +               _file, _line);
7762 +       atomic_inc(&dli->dl_usecnt);
7763 +       return dli;
7764 +}
7765 +
7766 +
7767 +#define free_dl_info(i) \
7768 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
7769 +
7770 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
7771 +
7772 +static inline void __put_dl_info(struct dl_info *dli,
7773 +       const char *_file, int _line)
7774 +{
7775 +       if (!dli)
7776 +               return;
7777 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
7778 +               dli, dli ? dli->dl_tag : 0,
7779 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
7780 +               _file, _line);
7781 +       if (atomic_dec_and_test(&dli->dl_usecnt))
7782 +               free_dl_info(dli);
7783 +}
7784 +
7785 +
7786 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
7787 +
7788 +static inline int __dl_alloc_space(struct super_block *sb,
7789 +       vtag_t tag, dlsize_t nr, const char *file, int line)
7790 +{
7791 +       struct dl_info *dli = NULL;
7792 +       int ret = 0;
7793 +
7794 +       if (nr == 0)
7795 +               goto out;
7796 +       dli = locate_dl_info(sb, tag);
7797 +       if (!dli)
7798 +               goto out;
7799 +
7800 +       spin_lock(&dli->dl_lock);
7801 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
7802 +       if (!ret)
7803 +               dli->dl_space_used += nr;
7804 +       spin_unlock(&dli->dl_lock);
7805 +       put_dl_info(dli);
7806 +out:
7807 +       vxlprintk(VXD_CBIT(dlim, 1),
7808 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
7809 +               sb, tag, __dlimit_char(dli), (long long)nr,
7810 +               ret, file, line);
7811 +       return ret ? -ENOSPC : 0;
7812 +}
7813 +
7814 +static inline void __dl_free_space(struct super_block *sb,
7815 +       vtag_t tag, dlsize_t nr, const char *_file, int _line)
7816 +{
7817 +       struct dl_info *dli = NULL;
7818 +
7819 +       if (nr == 0)
7820 +               goto out;
7821 +       dli = locate_dl_info(sb, tag);
7822 +       if (!dli)
7823 +               goto out;
7824 +
7825 +       spin_lock(&dli->dl_lock);
7826 +       if (dli->dl_space_used > nr)
7827 +               dli->dl_space_used -= nr;
7828 +       else
7829 +               dli->dl_space_used = 0;
7830 +       spin_unlock(&dli->dl_lock);
7831 +       put_dl_info(dli);
7832 +out:
7833 +       vxlprintk(VXD_CBIT(dlim, 1),
7834 +               "FREE  (%p,#%d)%c %lld bytes",
7835 +               sb, tag, __dlimit_char(dli), (long long)nr,
7836 +               _file, _line);
7837 +}
7838 +
7839 +static inline int __dl_alloc_inode(struct super_block *sb,
7840 +       vtag_t tag, const char *_file, int _line)
7841 +{
7842 +       struct dl_info *dli;
7843 +       int ret = 0;
7844 +
7845 +       dli = locate_dl_info(sb, tag);
7846 +       if (!dli)
7847 +               goto out;
7848 +
7849 +       spin_lock(&dli->dl_lock);
7850 +       dli->dl_inodes_used++;
7851 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
7852 +       spin_unlock(&dli->dl_lock);
7853 +       put_dl_info(dli);
7854 +out:
7855 +       vxlprintk(VXD_CBIT(dlim, 0),
7856 +               "ALLOC (%p,#%d)%c inode (%d)",
7857 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
7858 +       return ret ? -ENOSPC : 0;
7859 +}
7860 +
7861 +static inline void __dl_free_inode(struct super_block *sb,
7862 +       vtag_t tag, const char *_file, int _line)
7863 +{
7864 +       struct dl_info *dli;
7865 +
7866 +       dli = locate_dl_info(sb, tag);
7867 +       if (!dli)
7868 +               goto out;
7869 +
7870 +       spin_lock(&dli->dl_lock);
7871 +       if (dli->dl_inodes_used > 1)
7872 +               dli->dl_inodes_used--;
7873 +       else
7874 +               dli->dl_inodes_used = 0;
7875 +       spin_unlock(&dli->dl_lock);
7876 +       put_dl_info(dli);
7877 +out:
7878 +       vxlprintk(VXD_CBIT(dlim, 0),
7879 +               "FREE  (%p,#%d)%c inode",
7880 +               sb, tag, __dlimit_char(dli), _file, _line);
7881 +}
7882 +
7883 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
7884 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
7885 +       const char *_file, int _line)
7886 +{
7887 +       struct dl_info *dli;
7888 +       uint64_t broot, bfree;
7889 +
7890 +       dli = locate_dl_info(sb, tag);
7891 +       if (!dli)
7892 +               return;
7893 +
7894 +       spin_lock(&dli->dl_lock);
7895 +       broot = (dli->dl_space_total -
7896 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
7897 +               >> sb->s_blocksize_bits;
7898 +       bfree = (dli->dl_space_total - dli->dl_space_used)
7899 +                       >> sb->s_blocksize_bits;
7900 +       spin_unlock(&dli->dl_lock);
7901 +
7902 +       vxlprintk(VXD_CBIT(dlim, 2),
7903 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
7904 +               (long long)bfree, (long long)broot,
7905 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
7906 +               _file, _line);
7907 +       if (free_blocks) {
7908 +               if (*free_blocks > bfree)
7909 +                       *free_blocks = bfree;
7910 +       }
7911 +       if (root_blocks) {
7912 +               if (*root_blocks > broot)
7913 +                       *root_blocks = broot;
7914 +       }
7915 +       put_dl_info(dli);
7916 +}
7917 +
7918 +#define dl_prealloc_space(in, bytes) \
7919 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7920 +               __FILE__, __LINE__ )
7921 +
7922 +#define dl_alloc_space(in, bytes) \
7923 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7924 +               __FILE__, __LINE__ )
7925 +
7926 +#define dl_reserve_space(in, bytes) \
7927 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7928 +               __FILE__, __LINE__ )
7929 +
7930 +#define dl_claim_space(in, bytes) (0)
7931 +
7932 +#define dl_release_space(in, bytes) \
7933 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7934 +               __FILE__, __LINE__ )
7935 +
7936 +#define dl_free_space(in, bytes) \
7937 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7938 +               __FILE__, __LINE__ )
7939 +
7940 +
7941 +
7942 +#define dl_alloc_inode(in) \
7943 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
7944 +
7945 +#define dl_free_inode(in) \
7946 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
7947 +
7948 +
7949 +#define dl_adjust_block(sb, tag, fb, rb) \
7950 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
7951 +
7952 +
7953 +#else
7954 +#warning duplicate inclusion
7955 +#endif
7956 diff -NurpP --minimal linux-4.4.115/include/linux/vs_inet.h linux-4.4.115-vs2.3.9.7/include/linux/vs_inet.h
7957 --- linux-4.4.115/include/linux/vs_inet.h       1970-01-01 00:00:00.000000000 +0000
7958 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_inet.h     2018-01-09 16:36:32.000000000 +0000
7959 @@ -0,0 +1,364 @@
7960 +#ifndef _VS_INET_H
7961 +#define _VS_INET_H
7962 +
7963 +#include "vserver/base.h"
7964 +#include "vserver/network.h"
7965 +#include "vserver/debug.h"
7966 +
7967 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
7968 +
7969 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
7970 +                       NIPQUAD((a)->mask), (a)->type
7971 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
7972 +
7973 +#define NIPQUAD(addr) \
7974 +       ((unsigned char *)&addr)[0], \
7975 +       ((unsigned char *)&addr)[1], \
7976 +       ((unsigned char *)&addr)[2], \
7977 +       ((unsigned char *)&addr)[3]
7978 +
7979 +#define NIPQUAD_FMT "%u.%u.%u.%u"
7980 +
7981 +
7982 +static inline
7983 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
7984 +{
7985 +       __be32 ip = nxa->ip[0].s_addr;
7986 +       __be32 mask = nxa->mask.s_addr;
7987 +       __be32 bcast = ip | ~mask;
7988 +       int ret = 0;
7989 +
7990 +       switch (nxa->type & tmask) {
7991 +       case NXA_TYPE_MASK:
7992 +               ret = (ip == (addr & mask));
7993 +               break;
7994 +       case NXA_TYPE_ADDR:
7995 +               ret = 3;
7996 +               if (addr == ip)
7997 +                       break;
7998 +               /* fall through to broadcast */
7999 +       case NXA_MOD_BCAST:
8000 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
8001 +               break;
8002 +       case NXA_TYPE_RANGE:
8003 +               ret = ((nxa->ip[0].s_addr <= addr) &&
8004 +                       (nxa->ip[1].s_addr > addr));
8005 +               break;
8006 +       case NXA_TYPE_ANY:
8007 +               ret = 2;
8008 +               break;
8009 +       }
8010 +
8011 +       vxdprintk(VXD_CBIT(net, 0),
8012 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8013 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8014 +       return ret;
8015 +}
8016 +
8017 +static inline
8018 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8019 +{
8020 +       struct nx_addr_v4 *nxa;
8021 +       unsigned long irqflags;
8022 +       int ret = 1;
8023 +
8024 +       if (!nxi)
8025 +               goto out;
8026 +
8027 +       ret = 2;
8028 +       /* allow 127.0.0.1 when remapping lback */
8029 +       if ((tmask & NXA_LOOPBACK) &&
8030 +               (addr == IPI_LOOPBACK) &&
8031 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8032 +               goto out;
8033 +       ret = 3;
8034 +       /* check for lback address */
8035 +       if ((tmask & NXA_MOD_LBACK) &&
8036 +               (nxi->v4_lback.s_addr == addr))
8037 +               goto out;
8038 +       ret = 4;
8039 +       /* check for broadcast address */
8040 +       if ((tmask & NXA_MOD_BCAST) &&
8041 +               (nxi->v4_bcast.s_addr == addr))
8042 +               goto out;
8043 +       ret = 5;
8044 +
8045 +       /* check for v4 addresses */
8046 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8047 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
8048 +               if (v4_addr_match(nxa, addr, tmask))
8049 +                       goto out_unlock;
8050 +       ret = 0;
8051 +out_unlock:
8052 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8053 +out:
8054 +       vxdprintk(VXD_CBIT(net, 0),
8055 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
8056 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
8057 +       return ret;
8058 +}
8059 +
8060 +static inline
8061 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
8062 +{
8063 +       /* FIXME: needs full range checks */
8064 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
8065 +}
8066 +
8067 +static inline
8068 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
8069 +{
8070 +       struct nx_addr_v4 *ptr;
8071 +       unsigned long irqflags;
8072 +       int ret = 1;
8073 +
8074 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8075 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
8076 +               if (v4_nx_addr_match(ptr, nxa, mask))
8077 +                       goto out_unlock;
8078 +       ret = 0;
8079 +out_unlock:
8080 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8081 +       return ret;
8082 +}
8083 +
8084 +#include <net/inet_sock.h>
8085 +
8086 +/*
8087 + *     Check if a given address matches for a socket
8088 + *
8089 + *     nxi:            the socket's nx_info if any
8090 + *     addr:           to be verified address
8091 + */
8092 +static inline
8093 +int v4_sock_addr_match (
8094 +       struct nx_info *nxi,
8095 +       struct inet_sock *inet,
8096 +       __be32 addr)
8097 +{
8098 +       __be32 saddr = inet->inet_rcv_saddr;
8099 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
8100 +
8101 +       if (addr && (saddr == addr || bcast == addr))
8102 +               return 1;
8103 +       if (!saddr)
8104 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
8105 +       return 0;
8106 +}
8107 +
8108 +
8109 +/* inet related checks and helpers */
8110 +
8111 +
8112 +struct in_ifaddr;
8113 +struct net_device;
8114 +struct sock;
8115 +
8116 +#ifdef CONFIG_INET
8117 +
8118 +#include <linux/netdevice.h>
8119 +#include <linux/inetdevice.h>
8120 +#include <net/inet_sock.h>
8121 +#include <net/inet_timewait_sock.h>
8122 +
8123 +
8124 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8125 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
8126 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
8127 +
8128 +
8129 +/*
8130 + *     check if address is covered by socket
8131 + *
8132 + *     sk:     the socket to check against
8133 + *     addr:   the address in question (must be != 0)
8134 + */
8135 +
8136 +static inline
8137 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
8138 +{
8139 +       struct nx_info *nxi = sk->sk_nx_info;
8140 +       __be32 saddr = sk->sk_rcv_saddr;
8141 +
8142 +       vxdprintk(VXD_CBIT(net, 5),
8143 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
8144 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
8145 +               (sk->sk_socket?sk->sk_socket->flags:0));
8146 +
8147 +       if (saddr) {            /* direct address match */
8148 +               return v4_addr_match(nxa, saddr, -1);
8149 +       } else if (nxi) {       /* match against nx_info */
8150 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
8151 +       } else {                /* unrestricted any socket */
8152 +               return 1;
8153 +       }
8154 +}
8155 +
8156 +
8157 +
8158 +static inline
8159 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
8160 +{
8161 +       vxdprintk(VXD_CBIT(net, 1),
8162 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
8163 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
8164 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
8165 +
8166 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8167 +               return 1;
8168 +       if (dev_in_nx_info(dev, nxi))
8169 +               return 1;
8170 +       return 0;
8171 +}
8172 +
8173 +
8174 +static inline
8175 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
8176 +{
8177 +       if (!nxi)
8178 +               return 1;
8179 +       if (!ifa)
8180 +               return 0;
8181 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
8182 +}
8183 +
8184 +static inline
8185 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
8186 +{
8187 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
8188 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8189 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
8190 +
8191 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8192 +               return 1;
8193 +       if (v4_ifa_in_nx_info(ifa, nxi))
8194 +               return 1;
8195 +       return 0;
8196 +}
8197 +
8198 +
8199 +struct nx_v4_sock_addr {
8200 +       __be32 saddr;   /* Address used for validation */
8201 +       __be32 baddr;   /* Address used for socket bind */
8202 +};
8203 +
8204 +static inline
8205 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
8206 +       struct nx_v4_sock_addr *nsa)
8207 +{
8208 +       struct sock *sk = &inet->sk;
8209 +       struct nx_info *nxi = sk->sk_nx_info;
8210 +       __be32 saddr = addr->sin_addr.s_addr;
8211 +       __be32 baddr = saddr;
8212 +
8213 +       vxdprintk(VXD_CBIT(net, 3),
8214 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
8215 +               sk, sk->sk_nx_info, sk->sk_socket,
8216 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
8217 +               NIPQUAD(saddr));
8218 +
8219 +       if (nxi) {
8220 +               if (saddr == INADDR_ANY) {
8221 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
8222 +                               baddr = nxi->v4.ip[0].s_addr;
8223 +               } else if (saddr == IPI_LOOPBACK) {
8224 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8225 +                               baddr = nxi->v4_lback.s_addr;
8226 +               } else if (!ipv4_is_multicast(saddr) ||
8227 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
8228 +                       /* normal address bind */
8229 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
8230 +                               return -EADDRNOTAVAIL;
8231 +               }
8232 +       }
8233 +
8234 +       vxdprintk(VXD_CBIT(net, 3),
8235 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
8236 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
8237 +
8238 +       nsa->saddr = saddr;
8239 +       nsa->baddr = baddr;
8240 +       return 0;
8241 +}
8242 +
8243 +static inline
8244 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
8245 +{
8246 +       inet->inet_saddr = nsa->baddr;
8247 +       inet->inet_rcv_saddr = nsa->baddr;
8248 +}
8249 +
8250 +
8251 +/*
8252 + *      helper to simplify inet_lookup_listener
8253 + *
8254 + *      nxi:   the socket's nx_info if any
8255 + *      addr:  to be verified address
8256 + *      saddr: socket address
8257 + */
8258 +static inline int v4_inet_addr_match (
8259 +       struct nx_info *nxi,
8260 +       __be32 addr,
8261 +       __be32 saddr)
8262 +{
8263 +       if (addr && (saddr == addr))
8264 +               return 1;
8265 +       if (!saddr)
8266 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
8267 +       return 0;
8268 +}
8269 +
8270 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
8271 +{
8272 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
8273 +               (addr == nxi->v4_lback.s_addr))
8274 +               return IPI_LOOPBACK;
8275 +       return addr;
8276 +}
8277 +
8278 +static inline
8279 +int nx_info_has_v4(struct nx_info *nxi)
8280 +{
8281 +       if (!nxi)
8282 +               return 1;
8283 +       if (NX_IPV4(nxi))
8284 +               return 1;
8285 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8286 +               return 1;
8287 +       return 0;
8288 +}
8289 +
8290 +#else /* CONFIG_INET */
8291 +
8292 +static inline
8293 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
8294 +{
8295 +       return 1;
8296 +}
8297 +
8298 +static inline
8299 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8300 +{
8301 +       return 1;
8302 +}
8303 +
8304 +static inline
8305 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8306 +{
8307 +       return 1;
8308 +}
8309 +
8310 +static inline
8311 +int nx_info_has_v4(struct nx_info *nxi)
8312 +{
8313 +       return 0;
8314 +}
8315 +
8316 +#endif /* CONFIG_INET */
8317 +
8318 +#define current_nx_info_has_v4() \
8319 +       nx_info_has_v4(current_nx_info())
8320 +
8321 +#else
8322 +// #warning duplicate inclusion
8323 +#endif
8324 diff -NurpP --minimal linux-4.4.115/include/linux/vs_inet6.h linux-4.4.115-vs2.3.9.7/include/linux/vs_inet6.h
8325 --- linux-4.4.115/include/linux/vs_inet6.h      1970-01-01 00:00:00.000000000 +0000
8326 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_inet6.h    2018-01-09 16:36:32.000000000 +0000
8327 @@ -0,0 +1,257 @@
8328 +#ifndef _VS_INET6_H
8329 +#define _VS_INET6_H
8330 +
8331 +#include "vserver/base.h"
8332 +#include "vserver/network.h"
8333 +#include "vserver/debug.h"
8334 +
8335 +#include <net/ipv6.h>
8336 +
8337 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
8338 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
8339 +
8340 +
8341 +#ifdef CONFIG_IPV6
8342 +
8343 +static inline
8344 +int v6_addr_match(struct nx_addr_v6 *nxa,
8345 +       const struct in6_addr *addr, uint16_t mask)
8346 +{
8347 +       int ret = 0;
8348 +
8349 +       switch (nxa->type & mask) {
8350 +       case NXA_TYPE_MASK:
8351 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
8352 +               break;
8353 +       case NXA_TYPE_ADDR:
8354 +               ret = ipv6_addr_equal(&nxa->ip, addr);
8355 +               break;
8356 +       case NXA_TYPE_ANY:
8357 +               ret = 1;
8358 +               break;
8359 +       }
8360 +       vxdprintk(VXD_CBIT(net, 0),
8361 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
8362 +               nxa, NXAV6(nxa), addr, mask, ret);
8363 +       return ret;
8364 +}
8365 +
8366 +static inline
8367 +int v6_addr_in_nx_info(struct nx_info *nxi,
8368 +       const struct in6_addr *addr, uint16_t mask)
8369 +{
8370 +       struct nx_addr_v6 *nxa;
8371 +       unsigned long irqflags;
8372 +       int ret = 1;
8373 +
8374 +       if (!nxi)
8375 +               goto out;
8376 +
8377 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8378 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
8379 +               if (v6_addr_match(nxa, addr, mask))
8380 +                       goto out_unlock;
8381 +       ret = 0;
8382 +out_unlock:
8383 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8384 +out:
8385 +       vxdprintk(VXD_CBIT(net, 0),
8386 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
8387 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
8388 +       return ret;
8389 +}
8390 +
8391 +static inline
8392 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
8393 +{
8394 +       /* FIXME: needs full range checks */
8395 +       return v6_addr_match(nxa, &addr->ip, mask);
8396 +}
8397 +
8398 +static inline
8399 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
8400 +{
8401 +       struct nx_addr_v6 *ptr;
8402 +       unsigned long irqflags;
8403 +       int ret = 1;
8404 +
8405 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8406 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
8407 +               if (v6_nx_addr_match(ptr, nxa, mask))
8408 +                       goto out_unlock;
8409 +       ret = 0;
8410 +out_unlock:
8411 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8412 +       return ret;
8413 +}
8414 +
8415 +
8416 +/*
8417 + *     Check if a given address matches for a socket
8418 + *
8419 + *     nxi:            the socket's nx_info if any
8420 + *     addr:           to be verified address
8421 + */
8422 +static inline
8423 +int v6_sock_addr_match (
8424 +       struct nx_info *nxi,
8425 +       struct inet_sock *inet,
8426 +       struct in6_addr *addr)
8427 +{
8428 +       struct sock *sk = &inet->sk;
8429 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8430 +
8431 +       if (!ipv6_addr_any(addr) &&
8432 +               ipv6_addr_equal(saddr, addr))
8433 +               return 1;
8434 +       if (ipv6_addr_any(saddr))
8435 +               return v6_addr_in_nx_info(nxi, addr, -1);
8436 +       return 0;
8437 +}
8438 +
8439 +/*
8440 + *     check if address is covered by socket
8441 + *
8442 + *     sk:     the socket to check against
8443 + *     addr:   the address in question (must be != 0)
8444 + */
8445 +
8446 +static inline
8447 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
8448 +{
8449 +       struct nx_info *nxi = sk->sk_nx_info;
8450 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8451 +
8452 +       vxdprintk(VXD_CBIT(net, 5),
8453 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
8454 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
8455 +               (sk->sk_socket?sk->sk_socket->flags:0));
8456 +
8457 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
8458 +               return v6_addr_match(nxa, saddr, -1);
8459 +       } else if (nxi) {               /* match against nx_info */
8460 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
8461 +       } else {                        /* unrestricted any socket */
8462 +               return 1;
8463 +       }
8464 +}
8465 +
8466 +
8467 +/* inet related checks and helpers */
8468 +
8469 +
8470 +struct in_ifaddr;
8471 +struct net_device;
8472 +struct sock;
8473 +
8474 +
8475 +#include <linux/netdevice.h>
8476 +#include <linux/inetdevice.h>
8477 +#include <net/inet_timewait_sock.h>
8478 +
8479 +
8480 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8481 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
8482 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
8483 +
8484 +
8485 +
8486 +static inline
8487 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
8488 +{
8489 +       if (!nxi)
8490 +               return 1;
8491 +       if (!ifa)
8492 +               return 0;
8493 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
8494 +}
8495 +
8496 +static inline
8497 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
8498 +{
8499 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
8500 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8501 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
8502 +
8503 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8504 +               return 1;
8505 +       if (v6_ifa_in_nx_info(ifa, nxi))
8506 +               return 1;
8507 +       return 0;
8508 +}
8509 +
8510 +
8511 +struct nx_v6_sock_addr {
8512 +       struct in6_addr saddr;  /* Address used for validation */
8513 +       struct in6_addr baddr;  /* Address used for socket bind */
8514 +};
8515 +
8516 +static inline
8517 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
8518 +       struct nx_v6_sock_addr *nsa)
8519 +{
8520 +       // struct sock *sk = &inet->sk;
8521 +       // struct nx_info *nxi = sk->sk_nx_info;
8522 +       struct in6_addr saddr = addr->sin6_addr;
8523 +       struct in6_addr baddr = saddr;
8524 +
8525 +       nsa->saddr = saddr;
8526 +       nsa->baddr = baddr;
8527 +       return 0;
8528 +}
8529 +
8530 +static inline
8531 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
8532 +{
8533 +       // struct sock *sk = &inet->sk;
8534 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
8535 +
8536 +       // *saddr = nsa->baddr;
8537 +       // inet->inet_saddr = nsa->baddr;
8538 +}
8539 +
8540 +static inline
8541 +int nx_info_has_v6(struct nx_info *nxi)
8542 +{
8543 +       if (!nxi)
8544 +               return 1;
8545 +       if (NX_IPV6(nxi))
8546 +               return 1;
8547 +       return 0;
8548 +}
8549 +
8550 +#else /* CONFIG_IPV6 */
8551 +
8552 +static inline
8553 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
8554 +{
8555 +       return 1;
8556 +}
8557 +
8558 +
8559 +static inline
8560 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8561 +{
8562 +       return 1;
8563 +}
8564 +
8565 +static inline
8566 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8567 +{
8568 +       return 1;
8569 +}
8570 +
8571 +static inline
8572 +int nx_info_has_v6(struct nx_info *nxi)
8573 +{
8574 +       return 0;
8575 +}
8576 +
8577 +#endif /* CONFIG_IPV6 */
8578 +
8579 +#define current_nx_info_has_v6() \
8580 +       nx_info_has_v6(current_nx_info())
8581 +
8582 +#else
8583 +#warning duplicate inclusion
8584 +#endif
8585 diff -NurpP --minimal linux-4.4.115/include/linux/vs_limit.h linux-4.4.115-vs2.3.9.7/include/linux/vs_limit.h
8586 --- linux-4.4.115/include/linux/vs_limit.h      1970-01-01 00:00:00.000000000 +0000
8587 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_limit.h    2018-01-09 16:36:32.000000000 +0000
8588 @@ -0,0 +1,140 @@
8589 +#ifndef _VS_LIMIT_H
8590 +#define _VS_LIMIT_H
8591 +
8592 +#include "vserver/limit.h"
8593 +#include "vserver/base.h"
8594 +#include "vserver/context.h"
8595 +#include "vserver/debug.h"
8596 +#include "vserver/context.h"
8597 +#include "vserver/limit_int.h"
8598 +
8599 +
8600 +#define vx_acc_cres(v, d, p, r) \
8601 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
8602 +
8603 +#define vx_acc_cres_cond(x, d, p, r) \
8604 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8605 +       r, d, p, __FILE__, __LINE__)
8606 +
8607 +
8608 +#define vx_add_cres(v, a, p, r) \
8609 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
8610 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
8611 +
8612 +#define vx_add_cres_cond(x, a, p, r) \
8613 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8614 +       r, a, p, __FILE__, __LINE__)
8615 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
8616 +
8617 +
8618 +/* process and file limits */
8619 +
8620 +#define vx_nproc_inc(p) \
8621 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
8622 +
8623 +#define vx_nproc_dec(p) \
8624 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
8625 +
8626 +#define vx_files_inc(f) \
8627 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
8628 +
8629 +#define vx_files_dec(f) \
8630 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
8631 +
8632 +#define vx_locks_inc(l) \
8633 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
8634 +
8635 +#define vx_locks_dec(l) \
8636 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
8637 +
8638 +#define vx_openfd_inc(f) \
8639 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
8640 +
8641 +#define vx_openfd_dec(f) \
8642 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
8643 +
8644 +
8645 +#define vx_cres_avail(v, n, r) \
8646 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
8647 +
8648 +
8649 +#define vx_nproc_avail(n) \
8650 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
8651 +
8652 +#define vx_files_avail(n) \
8653 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
8654 +
8655 +#define vx_locks_avail(n) \
8656 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
8657 +
8658 +#define vx_openfd_avail(n) \
8659 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
8660 +
8661 +
8662 +/* dentry limits */
8663 +
8664 +#define vx_dentry_inc(d) do {                                          \
8665 +       if (d_count(d) == 1)                                            \
8666 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
8667 +       } while (0)
8668 +
8669 +#define vx_dentry_dec(d) do {                                          \
8670 +       if (d_count(d) == 0)                                            \
8671 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
8672 +       } while (0)
8673 +
8674 +#define vx_dentry_avail(n) \
8675 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
8676 +
8677 +
8678 +/* socket limits */
8679 +
8680 +#define vx_sock_inc(s) \
8681 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
8682 +
8683 +#define vx_sock_dec(s) \
8684 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
8685 +
8686 +#define vx_sock_avail(n) \
8687 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
8688 +
8689 +
8690 +/* ipc resource limits */
8691 +
8692 +#define vx_ipcmsg_add(v, u, a) \
8693 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
8694 +
8695 +#define vx_ipcmsg_sub(v, u, a) \
8696 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
8697 +
8698 +#define vx_ipcmsg_avail(v, a) \
8699 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
8700 +
8701 +
8702 +#define vx_ipcshm_add(v, k, a) \
8703 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8704 +
8705 +#define vx_ipcshm_sub(v, k, a) \
8706 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8707 +
8708 +#define vx_ipcshm_avail(v, a) \
8709 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
8710 +
8711 +
8712 +#define vx_semary_inc(a) \
8713 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
8714 +
8715 +#define vx_semary_dec(a) \
8716 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
8717 +
8718 +
8719 +#define vx_nsems_add(a,n) \
8720 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8721 +
8722 +#define vx_nsems_sub(a,n) \
8723 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8724 +
8725 +
8726 +#else
8727 +#warning duplicate inclusion
8728 +#endif
8729 diff -NurpP --minimal linux-4.4.115/include/linux/vs_network.h linux-4.4.115-vs2.3.9.7/include/linux/vs_network.h
8730 --- linux-4.4.115/include/linux/vs_network.h    1970-01-01 00:00:00.000000000 +0000
8731 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_network.h  2018-01-09 16:36:32.000000000 +0000
8732 @@ -0,0 +1,169 @@
8733 +#ifndef _NX_VS_NETWORK_H
8734 +#define _NX_VS_NETWORK_H
8735 +
8736 +#include "vserver/context.h"
8737 +#include "vserver/network.h"
8738 +#include "vserver/base.h"
8739 +#include "vserver/check.h"
8740 +#include "vserver/debug.h"
8741 +
8742 +#include <linux/sched.h>
8743 +
8744 +
8745 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
8746 +
8747 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
8748 +       const char *_file, int _line)
8749 +{
8750 +       if (!nxi)
8751 +               return NULL;
8752 +
8753 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
8754 +               nxi, nxi ? nxi->nx_id : 0,
8755 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8756 +               _file, _line);
8757 +
8758 +       atomic_inc(&nxi->nx_usecnt);
8759 +       return nxi;
8760 +}
8761 +
8762 +
8763 +extern void free_nx_info(struct nx_info *);
8764 +
8765 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
8766 +
8767 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
8768 +{
8769 +       if (!nxi)
8770 +               return;
8771 +
8772 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
8773 +               nxi, nxi ? nxi->nx_id : 0,
8774 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8775 +               _file, _line);
8776 +
8777 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
8778 +               free_nx_info(nxi);
8779 +}
8780 +
8781 +
8782 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
8783 +
8784 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
8785 +               const char *_file, int _line)
8786 +{
8787 +       if (nxi) {
8788 +               vxlprintk(VXD_CBIT(nid, 3),
8789 +                       "init_nx_info(%p[#%d.%d])",
8790 +                       nxi, nxi ? nxi->nx_id : 0,
8791 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8792 +                       _file, _line);
8793 +
8794 +               atomic_inc(&nxi->nx_usecnt);
8795 +       }
8796 +       *nxp = nxi;
8797 +}
8798 +
8799 +
8800 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
8801 +
8802 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
8803 +       const char *_file, int _line)
8804 +{
8805 +       struct nx_info *nxo;
8806 +
8807 +       if (!nxi)
8808 +               return;
8809 +
8810 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
8811 +               nxi, nxi ? nxi->nx_id : 0,
8812 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8813 +               _file, _line);
8814 +
8815 +       atomic_inc(&nxi->nx_usecnt);
8816 +       nxo = xchg(nxp, nxi);
8817 +       BUG_ON(nxo);
8818 +}
8819 +
8820 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
8821 +
8822 +static inline void __clr_nx_info(struct nx_info **nxp,
8823 +       const char *_file, int _line)
8824 +{
8825 +       struct nx_info *nxo;
8826 +
8827 +       nxo = xchg(nxp, NULL);
8828 +       if (!nxo)
8829 +               return;
8830 +
8831 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
8832 +               nxo, nxo ? nxo->nx_id : 0,
8833 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
8834 +               _file, _line);
8835 +
8836 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
8837 +               free_nx_info(nxo);
8838 +}
8839 +
8840 +
8841 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
8842 +
8843 +static inline void __claim_nx_info(struct nx_info *nxi,
8844 +       struct task_struct *task, const char *_file, int _line)
8845 +{
8846 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
8847 +               nxi, nxi ? nxi->nx_id : 0,
8848 +               nxi?atomic_read(&nxi->nx_usecnt):0,
8849 +               nxi?atomic_read(&nxi->nx_tasks):0,
8850 +               task, _file, _line);
8851 +
8852 +       atomic_inc(&nxi->nx_tasks);
8853 +}
8854 +
8855 +
8856 +extern void unhash_nx_info(struct nx_info *);
8857 +
8858 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
8859 +
8860 +static inline void __release_nx_info(struct nx_info *nxi,
8861 +       struct task_struct *task, const char *_file, int _line)
8862 +{
8863 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
8864 +               nxi, nxi ? nxi->nx_id : 0,
8865 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8866 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
8867 +               task, _file, _line);
8868 +
8869 +       might_sleep();
8870 +
8871 +       if (atomic_dec_and_test(&nxi->nx_tasks))
8872 +               unhash_nx_info(nxi);
8873 +}
8874 +
8875 +
8876 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
8877 +
8878 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
8879 +       const char *_file, int _line)
8880 +{
8881 +       struct nx_info *nxi;
8882 +
8883 +       task_lock(p);
8884 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
8885 +               p, _file, _line);
8886 +       nxi = __get_nx_info(p->nx_info, _file, _line);
8887 +       task_unlock(p);
8888 +       return nxi;
8889 +}
8890 +
8891 +
8892 +static inline void exit_nx_info(struct task_struct *p)
8893 +{
8894 +       if (p->nx_info)
8895 +               release_nx_info(p->nx_info, p);
8896 +}
8897 +
8898 +
8899 +#else
8900 +#warning duplicate inclusion
8901 +#endif
8902 diff -NurpP --minimal linux-4.4.115/include/linux/vs_pid.h linux-4.4.115-vs2.3.9.7/include/linux/vs_pid.h
8903 --- linux-4.4.115/include/linux/vs_pid.h        1970-01-01 00:00:00.000000000 +0000
8904 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_pid.h      2018-01-09 16:36:32.000000000 +0000
8905 @@ -0,0 +1,50 @@
8906 +#ifndef _VS_PID_H
8907 +#define _VS_PID_H
8908 +
8909 +#include "vserver/base.h"
8910 +#include "vserver/check.h"
8911 +#include "vserver/context.h"
8912 +#include "vserver/debug.h"
8913 +#include "vserver/pid.h"
8914 +#include <linux/pid_namespace.h>
8915 +
8916 +
8917 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
8918 +
8919 +static inline
8920 +int vx_proc_task_visible(struct task_struct *task)
8921 +{
8922 +       if ((task->pid == 1) &&
8923 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
8924 +               /* show a blend through init */
8925 +               goto visible;
8926 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
8927 +               goto visible;
8928 +       return 0;
8929 +visible:
8930 +       return 1;
8931 +}
8932 +
8933 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
8934 +
8935 +
8936 +static inline
8937 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
8938 +{
8939 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
8940 +
8941 +       if (task && !vx_proc_task_visible(task)) {
8942 +               vxdprintk(VXD_CBIT(misc, 6),
8943 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
8944 +                       task, task->xid, task->pid,
8945 +                       current, current->xid, current->pid);
8946 +               put_task_struct(task);
8947 +               task = NULL;
8948 +       }
8949 +       return task;
8950 +}
8951 +
8952 +
8953 +#else
8954 +#warning duplicate inclusion
8955 +#endif
8956 diff -NurpP --minimal linux-4.4.115/include/linux/vs_sched.h linux-4.4.115-vs2.3.9.7/include/linux/vs_sched.h
8957 --- linux-4.4.115/include/linux/vs_sched.h      1970-01-01 00:00:00.000000000 +0000
8958 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_sched.h    2018-01-09 16:36:32.000000000 +0000
8959 @@ -0,0 +1,40 @@
8960 +#ifndef _VS_SCHED_H
8961 +#define _VS_SCHED_H
8962 +
8963 +#include "vserver/base.h"
8964 +#include "vserver/context.h"
8965 +#include "vserver/sched.h"
8966 +
8967 +
8968 +#define MAX_PRIO_BIAS           20
8969 +#define MIN_PRIO_BIAS          -20
8970 +
8971 +static inline
8972 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
8973 +{
8974 +       struct vx_info *vxi = p->vx_info;
8975 +
8976 +       if (vxi)
8977 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
8978 +       return prio;
8979 +}
8980 +
8981 +static inline void vx_account_user(struct vx_info *vxi,
8982 +       cputime_t cputime, int nice)
8983 +{
8984 +       if (!vxi)
8985 +               return;
8986 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
8987 +}
8988 +
8989 +static inline void vx_account_system(struct vx_info *vxi,
8990 +       cputime_t cputime, int idle)
8991 +{
8992 +       if (!vxi)
8993 +               return;
8994 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
8995 +}
8996 +
8997 +#else
8998 +#warning duplicate inclusion
8999 +#endif
9000 diff -NurpP --minimal linux-4.4.115/include/linux/vs_socket.h linux-4.4.115-vs2.3.9.7/include/linux/vs_socket.h
9001 --- linux-4.4.115/include/linux/vs_socket.h     1970-01-01 00:00:00.000000000 +0000
9002 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_socket.h   2018-01-09 16:36:32.000000000 +0000
9003 @@ -0,0 +1,67 @@
9004 +#ifndef _VS_SOCKET_H
9005 +#define _VS_SOCKET_H
9006 +
9007 +#include "vserver/debug.h"
9008 +#include "vserver/base.h"
9009 +#include "vserver/cacct.h"
9010 +#include "vserver/context.h"
9011 +#include "vserver/tag.h"
9012 +
9013 +
9014 +/* socket accounting */
9015 +
9016 +#include <linux/socket.h>
9017 +
9018 +static inline int vx_sock_type(int family)
9019 +{
9020 +       switch (family) {
9021 +       case PF_UNSPEC:
9022 +               return VXA_SOCK_UNSPEC;
9023 +       case PF_UNIX:
9024 +               return VXA_SOCK_UNIX;
9025 +       case PF_INET:
9026 +               return VXA_SOCK_INET;
9027 +       case PF_INET6:
9028 +               return VXA_SOCK_INET6;
9029 +       case PF_PACKET:
9030 +               return VXA_SOCK_PACKET;
9031 +       default:
9032 +               return VXA_SOCK_OTHER;
9033 +       }
9034 +}
9035 +
9036 +#define vx_acc_sock(v, f, p, s) \
9037 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
9038 +
9039 +static inline void __vx_acc_sock(struct vx_info *vxi,
9040 +       int family, int pos, int size, char *file, int line)
9041 +{
9042 +       if (vxi) {
9043 +               int type = vx_sock_type(family);
9044 +
9045 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
9046 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
9047 +       }
9048 +}
9049 +
9050 +#define vx_sock_recv(sk, s) \
9051 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
9052 +#define vx_sock_send(sk, s) \
9053 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
9054 +#define vx_sock_fail(sk, s) \
9055 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
9056 +
9057 +
9058 +#define sock_vx_init(s) do {           \
9059 +       (s)->sk_xid = 0;                \
9060 +       (s)->sk_vx_info = NULL;         \
9061 +       } while (0)
9062 +
9063 +#define sock_nx_init(s) do {           \
9064 +       (s)->sk_nid = 0;                \
9065 +       (s)->sk_nx_info = NULL;         \
9066 +       } while (0)
9067 +
9068 +#else
9069 +#warning duplicate inclusion
9070 +#endif
9071 diff -NurpP --minimal linux-4.4.115/include/linux/vs_tag.h linux-4.4.115-vs2.3.9.7/include/linux/vs_tag.h
9072 --- linux-4.4.115/include/linux/vs_tag.h        1970-01-01 00:00:00.000000000 +0000
9073 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_tag.h      2018-01-09 16:36:32.000000000 +0000
9074 @@ -0,0 +1,47 @@
9075 +#ifndef _VS_TAG_H
9076 +#define _VS_TAG_H
9077 +
9078 +#include <linux/vserver/tag.h>
9079 +
9080 +/* check conditions */
9081 +
9082 +#define DX_ADMIN       0x0001
9083 +#define DX_WATCH       0x0002
9084 +#define DX_HOSTID      0x0008
9085 +
9086 +#define DX_IDENT       0x0010
9087 +
9088 +#define DX_ARG_MASK    0x0010
9089 +
9090 +
9091 +#define dx_task_tag(t) ((t)->tag)
9092 +
9093 +#define dx_current_tag() dx_task_tag(current)
9094 +
9095 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
9096 +
9097 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
9098 +
9099 +
9100 +/*
9101 + * check current context for ADMIN/WATCH and
9102 + * optionally against supplied argument
9103 + */
9104 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
9105 +{
9106 +       if (mode & DX_ARG_MASK) {
9107 +               if ((mode & DX_IDENT) && (id == cid))
9108 +                       return 1;
9109 +       }
9110 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
9111 +               ((mode & DX_WATCH) && (cid == 1)) ||
9112 +               ((mode & DX_HOSTID) && (id == 0)));
9113 +}
9114 +
9115 +struct inode;
9116 +int dx_permission(const struct inode *inode, int mask);
9117 +
9118 +
9119 +#else
9120 +#warning duplicate inclusion
9121 +#endif
9122 diff -NurpP --minimal linux-4.4.115/include/linux/vs_time.h linux-4.4.115-vs2.3.9.7/include/linux/vs_time.h
9123 --- linux-4.4.115/include/linux/vs_time.h       1970-01-01 00:00:00.000000000 +0000
9124 +++ linux-4.4.115-vs2.3.9.7/include/linux/vs_time.h     2018-01-09 16:36:32.000000000 +0000
9125 @@ -0,0 +1,19 @@
9126 +#ifndef _VS_TIME_H
9127 +#define _VS_TIME_H
9128 +
9129 +
9130 +/* time faking stuff */
9131 +
9132 +#ifdef CONFIG_VSERVER_VTIME
9133 +
9134 +extern void vx_adjust_timespec(struct timespec *ts);
9135 +extern int vx_settimeofday(const struct timespec *ts);
9136 +
9137 +#else
9138 +#define        vx_adjust_timespec(t)   do { } while (0)
9139 +#define        vx_settimeofday(t)      do_settimeofday(t)
9140 +#endif
9141 +
9142 +#else
9143 +#warning duplicate inclusion
9144 +#endif
9145 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/base.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/base.h
9146 --- linux-4.4.115/include/linux/vserver/base.h  1970-01-01 00:00:00.000000000 +0000
9147 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/base.h        2018-01-09 16:36:32.000000000 +0000
9148 @@ -0,0 +1,184 @@
9149 +#ifndef _VSERVER_BASE_H
9150 +#define _VSERVER_BASE_H
9151 +
9152 +
9153 +/* context state changes */
9154 +
9155 +enum {
9156 +       VSC_STARTUP = 1,
9157 +       VSC_SHUTDOWN,
9158 +
9159 +       VSC_NETUP,
9160 +       VSC_NETDOWN,
9161 +};
9162 +
9163 +
9164 +
9165 +#define vx_task_xid(t) ((t)->xid)
9166 +
9167 +#define vx_current_xid() vx_task_xid(current)
9168 +
9169 +#define current_vx_info() (current->vx_info)
9170 +
9171 +
9172 +#define nx_task_nid(t) ((t)->nid)
9173 +
9174 +#define nx_current_nid() nx_task_nid(current)
9175 +
9176 +#define current_nx_info() (current->nx_info)
9177 +
9178 +
9179 +/* generic flag merging */
9180 +
9181 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
9182 +
9183 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
9184 +
9185 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
9186 +
9187 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
9188 +
9189 +
9190 +/* context flags */
9191 +
9192 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
9193 +
9194 +#define vx_current_flags()     __vx_flags(current_vx_info())
9195 +
9196 +#define vx_info_flags(v, m, f) \
9197 +       vs_check_flags(__vx_flags(v), m, f)
9198 +
9199 +#define task_vx_flags(t, m, f) \
9200 +       ((t) && vx_info_flags((t)->vx_info, m, f))
9201 +
9202 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
9203 +
9204 +
9205 +/* context caps */
9206 +
9207 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
9208 +
9209 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
9210 +
9211 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
9212 +
9213 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
9214 +
9215 +
9216 +
9217 +/* network flags */
9218 +
9219 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
9220 +
9221 +#define nx_current_flags()     __nx_flags(current_nx_info())
9222 +
9223 +#define nx_info_flags(n, m, f) \
9224 +       vs_check_flags(__nx_flags(n), m, f)
9225 +
9226 +#define task_nx_flags(t, m, f) \
9227 +       ((t) && nx_info_flags((t)->nx_info, m, f))
9228 +
9229 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
9230 +
9231 +
9232 +/* network caps */
9233 +
9234 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
9235 +
9236 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
9237 +
9238 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
9239 +
9240 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
9241 +
9242 +
9243 +/* context mask capabilities */
9244 +
9245 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
9246 +
9247 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
9248 +
9249 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
9250 +
9251 +
9252 +/* context bcap mask */
9253 +
9254 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
9255 +
9256 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
9257 +
9258 +
9259 +/* mask given bcaps */
9260 +
9261 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
9262 +
9263 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
9264 +
9265 +
9266 +/* masked cap_bset */
9267 +
9268 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
9269 +
9270 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
9271 +
9272 +#if 0
9273 +#define vx_info_mbcap(v, b) \
9274 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
9275 +       vx_info_bcaps(v, b) : (b))
9276 +
9277 +#define task_vx_mbcap(t, b) \
9278 +       vx_info_mbcap((t)->vx_info, (t)->b)
9279 +
9280 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
9281 +#endif
9282 +
9283 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
9284 +
9285 +#define vx_capable(b, c) (capable(b) || \
9286 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9287 +
9288 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
9289 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9290 +
9291 +#define nx_capable(b, c) (capable(b) || \
9292 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9293 +
9294 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
9295 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9296 +
9297 +#define vx_task_initpid(t, n) \
9298 +       ((t)->vx_info && \
9299 +       ((t)->vx_info->vx_initpid == (n)))
9300 +
9301 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
9302 +
9303 +
9304 +/* context unshare mask */
9305 +
9306 +#define __vx_umask(v)          ((v)->vx_umask)
9307 +
9308 +#define vx_current_umask()     __vx_umask(current_vx_info())
9309 +
9310 +#define vx_can_unshare(b, f) (capable(b) || \
9311 +       (cap_raised(current_cap(), b) && \
9312 +       !((f) & ~vx_current_umask())))
9313 +
9314 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
9315 +       (cap_raised(current_cap(), b) && \
9316 +       !((f) & ~vx_current_umask())))
9317 +
9318 +#define __vx_wmask(v)          ((v)->vx_wmask)
9319 +
9320 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
9321 +
9322 +
9323 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
9324 +
9325 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
9326 +
9327 +
9328 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
9329 +
9330 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
9331 +
9332 +#endif
9333 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/cacct.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/cacct.h
9334 --- linux-4.4.115/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
9335 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/cacct.h       2018-01-09 16:36:32.000000000 +0000
9336 @@ -0,0 +1,15 @@
9337 +#ifndef _VSERVER_CACCT_H
9338 +#define _VSERVER_CACCT_H
9339 +
9340 +
9341 +enum sock_acc_field {
9342 +       VXA_SOCK_UNSPEC = 0,
9343 +       VXA_SOCK_UNIX,
9344 +       VXA_SOCK_INET,
9345 +       VXA_SOCK_INET6,
9346 +       VXA_SOCK_PACKET,
9347 +       VXA_SOCK_OTHER,
9348 +       VXA_SOCK_SIZE   /* array size */
9349 +};
9350 +
9351 +#endif /* _VSERVER_CACCT_H */
9352 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/cacct_cmd.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/cacct_cmd.h
9353 --- linux-4.4.115/include/linux/vserver/cacct_cmd.h     1970-01-01 00:00:00.000000000 +0000
9354 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/cacct_cmd.h   2018-01-09 16:36:32.000000000 +0000
9355 @@ -0,0 +1,10 @@
9356 +#ifndef _VSERVER_CACCT_CMD_H
9357 +#define _VSERVER_CACCT_CMD_H
9358 +
9359 +
9360 +#include <linux/compiler.h>
9361 +#include <uapi/vserver/cacct_cmd.h>
9362 +
9363 +extern int vc_sock_stat(struct vx_info *, void __user *);
9364 +
9365 +#endif /* _VSERVER_CACCT_CMD_H */
9366 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/cacct_def.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/cacct_def.h
9367 --- linux-4.4.115/include/linux/vserver/cacct_def.h     1970-01-01 00:00:00.000000000 +0000
9368 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/cacct_def.h   2018-01-09 16:36:32.000000000 +0000
9369 @@ -0,0 +1,43 @@
9370 +#ifndef _VSERVER_CACCT_DEF_H
9371 +#define _VSERVER_CACCT_DEF_H
9372 +
9373 +#include <asm/atomic.h>
9374 +#include <linux/vserver/cacct.h>
9375 +
9376 +
9377 +struct _vx_sock_acc {
9378 +       atomic_long_t count;
9379 +       atomic_long_t total;
9380 +};
9381 +
9382 +/* context sub struct */
9383 +
9384 +struct _vx_cacct {
9385 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
9386 +       atomic_t slab[8];
9387 +       atomic_t page[6][8];
9388 +};
9389 +
9390 +#ifdef CONFIG_VSERVER_DEBUG
9391 +
9392 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
9393 +{
9394 +       int i, j;
9395 +
9396 +       printk("\t_vx_cacct:");
9397 +       for (i = 0; i < 6; i++) {
9398 +               struct _vx_sock_acc *ptr = cacct->sock[i];
9399 +
9400 +               printk("\t [%d] =", i);
9401 +               for (j = 0; j < 3; j++) {
9402 +                       printk(" [%d] = %8lu, %8lu", j,
9403 +                               atomic_long_read(&ptr[j].count),
9404 +                               atomic_long_read(&ptr[j].total));
9405 +               }
9406 +               printk("\n");
9407 +       }
9408 +}
9409 +
9410 +#endif
9411 +
9412 +#endif /* _VSERVER_CACCT_DEF_H */
9413 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/cacct_int.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/cacct_int.h
9414 --- linux-4.4.115/include/linux/vserver/cacct_int.h     1970-01-01 00:00:00.000000000 +0000
9415 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/cacct_int.h   2018-01-09 16:36:32.000000000 +0000
9416 @@ -0,0 +1,17 @@
9417 +#ifndef _VSERVER_CACCT_INT_H
9418 +#define _VSERVER_CACCT_INT_H
9419 +
9420 +static inline
9421 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
9422 +{
9423 +       return atomic_long_read(&cacct->sock[type][pos].count);
9424 +}
9425 +
9426 +
9427 +static inline
9428 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
9429 +{
9430 +       return atomic_long_read(&cacct->sock[type][pos].total);
9431 +}
9432 +
9433 +#endif /* _VSERVER_CACCT_INT_H */
9434 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/check.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/check.h
9435 --- linux-4.4.115/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
9436 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/check.h       2018-01-09 16:36:32.000000000 +0000
9437 @@ -0,0 +1,89 @@
9438 +#ifndef _VSERVER_CHECK_H
9439 +#define _VSERVER_CHECK_H
9440 +
9441 +
9442 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
9443 +
9444 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
9445 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
9446 +#else
9447 +#define MIN_D_CONTEXT  65536
9448 +#endif
9449 +
9450 +/* check conditions */
9451 +
9452 +#define VS_ADMIN       0x0001
9453 +#define VS_WATCH       0x0002
9454 +#define VS_HIDE                0x0004
9455 +#define VS_HOSTID      0x0008
9456 +
9457 +#define VS_IDENT       0x0010
9458 +#define VS_EQUIV       0x0020
9459 +#define VS_PARENT      0x0040
9460 +#define VS_CHILD       0x0080
9461 +
9462 +#define VS_ARG_MASK    0x00F0
9463 +
9464 +#define VS_DYNAMIC     0x0100
9465 +#define VS_STATIC      0x0200
9466 +
9467 +#define VS_ATR_MASK    0x0F00
9468 +
9469 +#ifdef CONFIG_VSERVER_PRIVACY
9470 +#define VS_ADMIN_P     (0)
9471 +#define VS_WATCH_P     (0)
9472 +#else
9473 +#define VS_ADMIN_P     VS_ADMIN
9474 +#define VS_WATCH_P     VS_WATCH
9475 +#endif
9476 +
9477 +#define VS_HARDIRQ     0x1000
9478 +#define VS_SOFTIRQ     0x2000
9479 +#define VS_IRQ         0x4000
9480 +
9481 +#define VS_IRQ_MASK    0xF000
9482 +
9483 +#include <linux/hardirq.h>
9484 +
9485 +/*
9486 + * check current context for ADMIN/WATCH and
9487 + * optionally against supplied argument
9488 + */
9489 +static inline int __vs_check(int cid, int id, unsigned int mode)
9490 +{
9491 +       if (mode & VS_ARG_MASK) {
9492 +               if ((mode & VS_IDENT) && (id == cid))
9493 +                       return 1;
9494 +       }
9495 +       if (mode & VS_ATR_MASK) {
9496 +               if ((mode & VS_DYNAMIC) &&
9497 +                       (id >= MIN_D_CONTEXT) &&
9498 +                       (id <= MAX_S_CONTEXT))
9499 +                       return 1;
9500 +               if ((mode & VS_STATIC) &&
9501 +                       (id > 1) && (id < MIN_D_CONTEXT))
9502 +                       return 1;
9503 +       }
9504 +       if (mode & VS_IRQ_MASK) {
9505 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
9506 +                       return 1;
9507 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
9508 +                       return 1;
9509 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
9510 +                       return 1;
9511 +       }
9512 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
9513 +               ((mode & VS_WATCH) && (cid == 1)) ||
9514 +               ((mode & VS_HOSTID) && (id == 0)));
9515 +}
9516 +
9517 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
9518 +
9519 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
9520 +
9521 +
9522 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
9523 +
9524 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
9525 +
9526 +#endif
9527 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/context.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/context.h
9528 --- linux-4.4.115/include/linux/vserver/context.h       1970-01-01 00:00:00.000000000 +0000
9529 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/context.h     2018-01-09 16:36:32.000000000 +0000
9530 @@ -0,0 +1,110 @@
9531 +#ifndef _VSERVER_CONTEXT_H
9532 +#define _VSERVER_CONTEXT_H
9533 +
9534 +
9535 +#include <linux/list.h>
9536 +#include <linux/spinlock.h>
9537 +#include <linux/rcupdate.h>
9538 +#include <uapi/vserver/context.h>
9539 +
9540 +#include "limit_def.h"
9541 +#include "sched_def.h"
9542 +#include "cvirt_def.h"
9543 +#include "cacct_def.h"
9544 +#include "device_def.h"
9545 +
9546 +#define VX_SPACES      2
9547 +
9548 +struct _vx_info_pc {
9549 +       struct _vx_sched_pc sched_pc;
9550 +       struct _vx_cvirt_pc cvirt_pc;
9551 +};
9552 +
9553 +struct _vx_space {
9554 +       unsigned long vx_nsmask;                /* assignment mask */
9555 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
9556 +       struct fs_struct *vx_fs;                /* private namespace fs */
9557 +       const struct cred *vx_cred;             /* task credentials */
9558 +};
9559 +
9560 +struct vx_info {
9561 +       struct hlist_node vx_hlist;             /* linked list of contexts */
9562 +       vxid_t vx_id;                           /* context id */
9563 +       atomic_t vx_usecnt;                     /* usage count */
9564 +       atomic_t vx_tasks;                      /* tasks count */
9565 +       struct vx_info *vx_parent;              /* parent context */
9566 +       int vx_state;                           /* context state */
9567 +
9568 +       struct _vx_space space[VX_SPACES];      /* namespace store */
9569 +
9570 +       uint64_t vx_flags;                      /* context flags */
9571 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
9572 +       uint64_t vx_umask;                      /* unshare mask (guest) */
9573 +       uint64_t vx_wmask;                      /* warn mask (guest) */
9574 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
9575 +
9576 +       struct task_struct *vx_reaper;          /* guest reaper process */
9577 +       pid_t vx_initpid;                       /* PID of guest init */
9578 +       int64_t vx_badness_bias;                /* OOM points bias */
9579 +
9580 +       struct _vx_limit limit;                 /* vserver limits */
9581 +       struct _vx_sched sched;                 /* vserver scheduler */
9582 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
9583 +       struct _vx_cacct cacct;                 /* context accounting */
9584 +
9585 +       struct _vx_device dmap;                 /* default device map targets */
9586 +
9587 +#ifndef CONFIG_SMP
9588 +       struct _vx_info_pc info_pc;             /* per cpu data */
9589 +#else
9590 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
9591 +#endif
9592 +
9593 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
9594 +       int reboot_cmd;                         /* last sys_reboot() cmd */
9595 +       int exit_code;                          /* last process exit code */
9596 +
9597 +       char vx_name[65];                       /* vserver name */
9598 +};
9599 +
9600 +#ifndef CONFIG_SMP
9601 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
9602 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
9603 +#else
9604 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
9605 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
9606 +#endif
9607 +
9608 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
9609 +
9610 +
9611 +struct vx_info_save {
9612 +       struct vx_info *vxi;
9613 +       vxid_t xid;
9614 +};
9615 +
9616 +
9617 +/* status flags */
9618 +
9619 +#define VXS_HASHED     0x0001
9620 +#define VXS_PAUSED     0x0010
9621 +#define VXS_SHUTDOWN   0x0100
9622 +#define VXS_HELPER     0x1000
9623 +#define VXS_RELEASED   0x8000
9624 +
9625 +
9626 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
9627 +extern void release_vx_info(struct vx_info *, struct task_struct *);
9628 +
9629 +extern struct vx_info *lookup_vx_info(int);
9630 +extern struct vx_info *lookup_or_create_vx_info(int);
9631 +
9632 +extern int get_xid_list(int, unsigned int *, int);
9633 +extern int xid_is_hashed(vxid_t);
9634 +
9635 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
9636 +
9637 +extern long vs_state_change(struct vx_info *, unsigned int);
9638 +
9639 +
9640 +#endif /* _VSERVER_CONTEXT_H */
9641 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/context_cmd.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/context_cmd.h
9642 --- linux-4.4.115/include/linux/vserver/context_cmd.h   1970-01-01 00:00:00.000000000 +0000
9643 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/context_cmd.h 2018-01-09 16:36:32.000000000 +0000
9644 @@ -0,0 +1,33 @@
9645 +#ifndef _VSERVER_CONTEXT_CMD_H
9646 +#define _VSERVER_CONTEXT_CMD_H
9647 +
9648 +#include <uapi/vserver/context_cmd.h>
9649 +
9650 +extern int vc_task_xid(uint32_t);
9651 +
9652 +extern int vc_vx_info(struct vx_info *, void __user *);
9653 +
9654 +extern int vc_ctx_stat(struct vx_info *, void __user *);
9655 +
9656 +extern int vc_ctx_create(uint32_t, void __user *);
9657 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
9658 +
9659 +extern int vc_get_cflags(struct vx_info *, void __user *);
9660 +extern int vc_set_cflags(struct vx_info *, void __user *);
9661 +
9662 +extern int vc_get_ccaps(struct vx_info *, void __user *);
9663 +extern int vc_set_ccaps(struct vx_info *, void __user *);
9664 +
9665 +extern int vc_get_bcaps(struct vx_info *, void __user *);
9666 +extern int vc_set_bcaps(struct vx_info *, void __user *);
9667 +
9668 +extern int vc_get_umask(struct vx_info *, void __user *);
9669 +extern int vc_set_umask(struct vx_info *, void __user *);
9670 +
9671 +extern int vc_get_wmask(struct vx_info *, void __user *);
9672 +extern int vc_set_wmask(struct vx_info *, void __user *);
9673 +
9674 +extern int vc_get_badness(struct vx_info *, void __user *);
9675 +extern int vc_set_badness(struct vx_info *, void __user *);
9676 +
9677 +#endif /* _VSERVER_CONTEXT_CMD_H */
9678 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/cvirt.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/cvirt.h
9679 --- linux-4.4.115/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
9680 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/cvirt.h       2018-01-09 16:36:32.000000000 +0000
9681 @@ -0,0 +1,18 @@
9682 +#ifndef _VSERVER_CVIRT_H
9683 +#define _VSERVER_CVIRT_H
9684 +
9685 +struct timespec;
9686 +
9687 +void vx_vsi_boottime(struct timespec *);
9688 +
9689 +void vx_vsi_uptime(struct timespec *, struct timespec *);
9690 +
9691 +
9692 +struct vx_info;
9693 +
9694 +void vx_update_load(struct vx_info *);
9695 +
9696 +
9697 +int vx_do_syslog(int, char __user *, int);
9698 +
9699 +#endif /* _VSERVER_CVIRT_H */
9700 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/cvirt_cmd.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/cvirt_cmd.h
9701 --- linux-4.4.115/include/linux/vserver/cvirt_cmd.h     1970-01-01 00:00:00.000000000 +0000
9702 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/cvirt_cmd.h   2018-01-09 16:36:32.000000000 +0000
9703 @@ -0,0 +1,13 @@
9704 +#ifndef _VSERVER_CVIRT_CMD_H
9705 +#define _VSERVER_CVIRT_CMD_H
9706 +
9707 +
9708 +#include <linux/compiler.h>
9709 +#include <uapi/vserver/cvirt_cmd.h>
9710 +
9711 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
9712 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
9713 +
9714 +extern int vc_virt_stat(struct vx_info *, void __user *);
9715 +
9716 +#endif /* _VSERVER_CVIRT_CMD_H */
9717 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/cvirt_def.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/cvirt_def.h
9718 --- linux-4.4.115/include/linux/vserver/cvirt_def.h     1970-01-01 00:00:00.000000000 +0000
9719 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/cvirt_def.h   2018-01-09 16:36:32.000000000 +0000
9720 @@ -0,0 +1,80 @@
9721 +#ifndef _VSERVER_CVIRT_DEF_H
9722 +#define _VSERVER_CVIRT_DEF_H
9723 +
9724 +#include <linux/jiffies.h>
9725 +#include <linux/spinlock.h>
9726 +#include <linux/wait.h>
9727 +#include <linux/time.h>
9728 +#include <asm/atomic.h>
9729 +
9730 +
9731 +struct _vx_usage_stat {
9732 +       uint64_t user;
9733 +       uint64_t nice;
9734 +       uint64_t system;
9735 +       uint64_t softirq;
9736 +       uint64_t irq;
9737 +       uint64_t idle;
9738 +       uint64_t iowait;
9739 +};
9740 +
9741 +struct _vx_syslog {
9742 +       wait_queue_head_t log_wait;
9743 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
9744 +
9745 +       unsigned long log_start;        /* next char to be read by syslog() */
9746 +       unsigned long con_start;        /* next char to be sent to consoles */
9747 +       unsigned long log_end;  /* most-recently-written-char + 1 */
9748 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
9749 +
9750 +       char log_buf[1024];
9751 +};
9752 +
9753 +
9754 +/* context sub struct */
9755 +
9756 +struct _vx_cvirt {
9757 +       atomic_t nr_threads;            /* number of current threads */
9758 +       atomic_t nr_running;            /* number of running threads */
9759 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
9760 +
9761 +       atomic_t nr_onhold;             /* processes on hold */
9762 +       uint32_t onhold_last;           /* jiffies when put on hold */
9763 +
9764 +       struct timespec bias_ts;        /* time offset to the host */
9765 +       struct timespec bias_idle;
9766 +       struct timespec bias_uptime;    /* context creation point */
9767 +       uint64_t bias_clock;            /* offset in clock_t */
9768 +
9769 +       spinlock_t load_lock;           /* lock for the load averages */
9770 +       atomic_t load_updates;          /* nr of load updates done so far */
9771 +       uint32_t load_last;             /* last time load was calculated */
9772 +       uint32_t load[3];               /* load averages 1,5,15 */
9773 +
9774 +       atomic_t total_forks;           /* number of forks so far */
9775 +
9776 +       struct _vx_syslog syslog;
9777 +};
9778 +
9779 +struct _vx_cvirt_pc {
9780 +       struct _vx_usage_stat cpustat;
9781 +};
9782 +
9783 +
9784 +#ifdef CONFIG_VSERVER_DEBUG
9785 +
9786 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
9787 +{
9788 +       printk("\t_vx_cvirt:\n");
9789 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
9790 +               atomic_read(&cvirt->nr_threads),
9791 +               atomic_read(&cvirt->nr_running),
9792 +               atomic_read(&cvirt->nr_uninterruptible),
9793 +               atomic_read(&cvirt->nr_onhold));
9794 +       /* add rest here */
9795 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
9796 +}
9797 +
9798 +#endif
9799 +
9800 +#endif /* _VSERVER_CVIRT_DEF_H */
9801 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/debug.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/debug.h
9802 --- linux-4.4.115/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
9803 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/debug.h       2018-01-09 16:36:32.000000000 +0000
9804 @@ -0,0 +1,146 @@
9805 +#ifndef _VSERVER_DEBUG_H
9806 +#define _VSERVER_DEBUG_H
9807 +
9808 +
9809 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
9810 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
9811 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
9812 +
9813 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
9814 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
9815 +#define VXF_DEV                "%p[%lu,%d:%d]"
9816 +
9817 +#if    defined(CONFIG_QUOTES_UTF8)
9818 +#define        VS_Q_LQM        "\xc2\xbb"
9819 +#define        VS_Q_RQM        "\xc2\xab"
9820 +#elif  defined(CONFIG_QUOTES_ASCII)
9821 +#define        VS_Q_LQM        "\x27"
9822 +#define        VS_Q_RQM        "\x27"
9823 +#else
9824 +#define        VS_Q_LQM        "\xbb"
9825 +#define        VS_Q_RQM        "\xab"
9826 +#endif
9827 +
9828 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
9829 +
9830 +
9831 +#define vxd_path(p)                                            \
9832 +       ({ static char _buffer[PATH_MAX];                       \
9833 +          d_path(p, _buffer, sizeof(_buffer)); })
9834 +
9835 +#define vxd_cond_path(n)                                       \
9836 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
9837 +
9838 +
9839 +#ifdef CONFIG_VSERVER_DEBUG
9840 +
9841 +extern unsigned int vs_debug_switch;
9842 +extern unsigned int vs_debug_xid;
9843 +extern unsigned int vs_debug_nid;
9844 +extern unsigned int vs_debug_tag;
9845 +extern unsigned int vs_debug_net;
9846 +extern unsigned int vs_debug_limit;
9847 +extern unsigned int vs_debug_cres;
9848 +extern unsigned int vs_debug_dlim;
9849 +extern unsigned int vs_debug_quota;
9850 +extern unsigned int vs_debug_cvirt;
9851 +extern unsigned int vs_debug_space;
9852 +extern unsigned int vs_debug_perm;
9853 +extern unsigned int vs_debug_misc;
9854 +
9855 +
9856 +#define VX_LOGLEVEL    "vxD: "
9857 +#define VX_PROC_FMT    "%p: "
9858 +#define VX_PROCESS     current
9859 +
9860 +#define vxdprintk(c, f, x...)                                  \
9861 +       do {                                                    \
9862 +               if (c)                                          \
9863 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
9864 +                               VX_PROCESS , ##x);              \
9865 +       } while (0)
9866 +
9867 +#define vxlprintk(c, f, x...)                                  \
9868 +       do {                                                    \
9869 +               if (c)                                          \
9870 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
9871 +       } while (0)
9872 +
9873 +#define vxfprintk(c, f, x...)                                  \
9874 +       do {                                                    \
9875 +               if (c)                                          \
9876 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
9877 +       } while (0)
9878 +
9879 +
9880 +struct vx_info;
9881 +
9882 +void dump_vx_info(struct vx_info *, int);
9883 +void dump_vx_info_inactive(int);
9884 +
9885 +#else  /* CONFIG_VSERVER_DEBUG */
9886 +
9887 +#define vs_debug_switch        0
9888 +#define vs_debug_xid   0
9889 +#define vs_debug_nid   0
9890 +#define vs_debug_tag   0
9891 +#define vs_debug_net   0
9892 +#define vs_debug_limit 0
9893 +#define vs_debug_cres  0
9894 +#define vs_debug_dlim  0
9895 +#define vs_debug_quota 0
9896 +#define vs_debug_cvirt 0
9897 +#define vs_debug_space 0
9898 +#define vs_debug_perm  0
9899 +#define vs_debug_misc  0
9900 +
9901 +#define vxdprintk(x...) do { } while (0)
9902 +#define vxlprintk(x...) do { } while (0)
9903 +#define vxfprintk(x...) do { } while (0)
9904 +
9905 +#endif /* CONFIG_VSERVER_DEBUG */
9906 +
9907 +
9908 +#ifdef CONFIG_VSERVER_WARN
9909 +
9910 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
9911 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
9912 +#define VX_WARN_XID    "[xid #%u] "
9913 +#define VX_WARN_NID    "[nid #%u] "
9914 +#define VX_WARN_TAG    "[tag #%u] "
9915 +
9916 +#define vxwprintk(c, f, x...)                                  \
9917 +       do {                                                    \
9918 +               if (c)                                          \
9919 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
9920 +       } while (0)
9921 +
9922 +#else  /* CONFIG_VSERVER_WARN */
9923 +
9924 +#define vxwprintk(x...) do { } while (0)
9925 +
9926 +#endif /* CONFIG_VSERVER_WARN */
9927 +
9928 +#define vxwprintk_task(c, f, x...)                             \
9929 +       vxwprintk(c, VX_WARN_TASK f,                            \
9930 +               current->comm, current->pid,                    \
9931 +               current->xid, current->nid,                     \
9932 +               current->tag, ##x)
9933 +#define vxwprintk_xid(c, f, x...)                              \
9934 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
9935 +#define vxwprintk_nid(c, f, x...)                              \
9936 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
9937 +#define vxwprintk_tag(c, f, x...)                              \
9938 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
9939 +
9940 +#ifdef CONFIG_VSERVER_DEBUG
9941 +#define vxd_assert_lock(l)     assert_spin_locked(l)
9942 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
9943 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
9944 +#else
9945 +#define vxd_assert_lock(l)     do { } while (0)
9946 +#define vxd_assert(c, f, x...) do { } while (0)
9947 +#endif
9948 +
9949 +
9950 +#endif /* _VSERVER_DEBUG_H */
9951 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/debug_cmd.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/debug_cmd.h
9952 --- linux-4.4.115/include/linux/vserver/debug_cmd.h     1970-01-01 00:00:00.000000000 +0000
9953 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/debug_cmd.h   2018-01-09 16:36:32.000000000 +0000
9954 @@ -0,0 +1,37 @@
9955 +#ifndef _VSERVER_DEBUG_CMD_H
9956 +#define _VSERVER_DEBUG_CMD_H
9957 +
9958 +#include <uapi/vserver/debug_cmd.h>
9959 +
9960 +
9961 +#ifdef CONFIG_COMPAT
9962 +
9963 +#include <asm/compat.h>
9964 +
9965 +struct vcmd_read_history_v0_x32 {
9966 +       uint32_t index;
9967 +       uint32_t count;
9968 +       compat_uptr_t data_ptr;
9969 +};
9970 +
9971 +struct vcmd_read_monitor_v0_x32 {
9972 +       uint32_t index;
9973 +       uint32_t count;
9974 +       compat_uptr_t data_ptr;
9975 +};
9976 +
9977 +#endif  /* CONFIG_COMPAT */
9978 +
9979 +extern int vc_dump_history(uint32_t);
9980 +
9981 +extern int vc_read_history(uint32_t, void __user *);
9982 +extern int vc_read_monitor(uint32_t, void __user *);
9983 +
9984 +#ifdef CONFIG_COMPAT
9985 +
9986 +extern int vc_read_history_x32(uint32_t, void __user *);
9987 +extern int vc_read_monitor_x32(uint32_t, void __user *);
9988 +
9989 +#endif  /* CONFIG_COMPAT */
9990 +
9991 +#endif /* _VSERVER_DEBUG_CMD_H */
9992 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/device.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/device.h
9993 --- linux-4.4.115/include/linux/vserver/device.h        1970-01-01 00:00:00.000000000 +0000
9994 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/device.h      2018-01-09 16:36:32.000000000 +0000
9995 @@ -0,0 +1,9 @@
9996 +#ifndef _VSERVER_DEVICE_H
9997 +#define _VSERVER_DEVICE_H
9998 +
9999 +
10000 +#include <uapi/vserver/device.h>
10001 +
10002 +#else  /* _VSERVER_DEVICE_H */
10003 +#warning duplicate inclusion
10004 +#endif /* _VSERVER_DEVICE_H */
10005 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/device_cmd.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/device_cmd.h
10006 --- linux-4.4.115/include/linux/vserver/device_cmd.h    1970-01-01 00:00:00.000000000 +0000
10007 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/device_cmd.h  2018-01-09 16:36:32.000000000 +0000
10008 @@ -0,0 +1,31 @@
10009 +#ifndef _VSERVER_DEVICE_CMD_H
10010 +#define _VSERVER_DEVICE_CMD_H
10011 +
10012 +#include <uapi/vserver/device_cmd.h>
10013 +
10014 +
10015 +#ifdef CONFIG_COMPAT
10016 +
10017 +#include <asm/compat.h>
10018 +
10019 +struct vcmd_set_mapping_v0_x32 {
10020 +       compat_uptr_t device_ptr;
10021 +       compat_uptr_t target_ptr;
10022 +       uint32_t flags;
10023 +};
10024 +
10025 +#endif /* CONFIG_COMPAT */
10026 +
10027 +#include <linux/compiler.h>
10028 +
10029 +extern int vc_set_mapping(struct vx_info *, void __user *);
10030 +extern int vc_unset_mapping(struct vx_info *, void __user *);
10031 +
10032 +#ifdef CONFIG_COMPAT
10033 +
10034 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
10035 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
10036 +
10037 +#endif /* CONFIG_COMPAT */
10038 +
10039 +#endif /* _VSERVER_DEVICE_CMD_H */
10040 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/device_def.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/device_def.h
10041 --- linux-4.4.115/include/linux/vserver/device_def.h    1970-01-01 00:00:00.000000000 +0000
10042 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/device_def.h  2018-01-09 16:36:32.000000000 +0000
10043 @@ -0,0 +1,17 @@
10044 +#ifndef _VSERVER_DEVICE_DEF_H
10045 +#define _VSERVER_DEVICE_DEF_H
10046 +
10047 +#include <linux/types.h>
10048 +
10049 +struct vx_dmap_target {
10050 +       dev_t target;
10051 +       uint32_t flags;
10052 +};
10053 +
10054 +struct _vx_device {
10055 +#ifdef CONFIG_VSERVER_DEVICE
10056 +       struct vx_dmap_target targets[2];
10057 +#endif
10058 +};
10059 +
10060 +#endif /* _VSERVER_DEVICE_DEF_H */
10061 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/dlimit.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/dlimit.h
10062 --- linux-4.4.115/include/linux/vserver/dlimit.h        1970-01-01 00:00:00.000000000 +0000
10063 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/dlimit.h      2018-01-09 16:36:32.000000000 +0000
10064 @@ -0,0 +1,54 @@
10065 +#ifndef _VSERVER_DLIMIT_H
10066 +#define _VSERVER_DLIMIT_H
10067 +
10068 +#include "switch.h"
10069 +
10070 +
10071 +#ifdef __KERNEL__
10072 +
10073 +/*      keep in sync with CDLIM_INFINITY       */
10074 +
10075 +#define DLIM_INFINITY          (~0ULL)
10076 +
10077 +#include <linux/spinlock.h>
10078 +#include <linux/rcupdate.h>
10079 +
10080 +struct super_block;
10081 +
10082 +struct dl_info {
10083 +       struct hlist_node dl_hlist;             /* linked list of contexts */
10084 +       struct rcu_head dl_rcu;                 /* the rcu head */
10085 +       vtag_t dl_tag;                          /* context tag */
10086 +       atomic_t dl_usecnt;                     /* usage count */
10087 +       atomic_t dl_refcnt;                     /* reference count */
10088 +
10089 +       struct super_block *dl_sb;              /* associated superblock */
10090 +
10091 +       spinlock_t dl_lock;                     /* protect the values */
10092 +
10093 +       unsigned long long dl_space_used;       /* used space in bytes */
10094 +       unsigned long long dl_space_total;      /* maximum space in bytes */
10095 +       unsigned long dl_inodes_used;           /* used inodes */
10096 +       unsigned long dl_inodes_total;          /* maximum inodes */
10097 +
10098 +       unsigned int dl_nrlmult;                /* non root limit mult */
10099 +};
10100 +
10101 +struct rcu_head;
10102 +
10103 +extern void rcu_free_dl_info(struct rcu_head *);
10104 +extern void unhash_dl_info(struct dl_info *);
10105 +
10106 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
10107 +
10108 +
10109 +struct kstatfs;
10110 +
10111 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
10112 +
10113 +typedef uint64_t dlsize_t;
10114 +
10115 +#endif /* __KERNEL__ */
10116 +#else  /* _VSERVER_DLIMIT_H */
10117 +#warning duplicate inclusion
10118 +#endif /* _VSERVER_DLIMIT_H */
10119 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/dlimit_cmd.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/dlimit_cmd.h
10120 --- linux-4.4.115/include/linux/vserver/dlimit_cmd.h    1970-01-01 00:00:00.000000000 +0000
10121 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/dlimit_cmd.h  2018-01-09 16:36:32.000000000 +0000
10122 @@ -0,0 +1,46 @@
10123 +#ifndef _VSERVER_DLIMIT_CMD_H
10124 +#define _VSERVER_DLIMIT_CMD_H
10125 +
10126 +#include <uapi/vserver/dlimit_cmd.h>
10127 +
10128 +
10129 +#ifdef CONFIG_COMPAT
10130 +
10131 +#include <asm/compat.h>
10132 +
10133 +struct vcmd_ctx_dlimit_base_v0_x32 {
10134 +       compat_uptr_t name_ptr;
10135 +       uint32_t flags;
10136 +};
10137 +
10138 +struct vcmd_ctx_dlimit_v0_x32 {
10139 +       compat_uptr_t name_ptr;
10140 +       uint32_t space_used;                    /* used space in kbytes */
10141 +       uint32_t space_total;                   /* maximum space in kbytes */
10142 +       uint32_t inodes_used;                   /* used inodes */
10143 +       uint32_t inodes_total;                  /* maximum inodes */
10144 +       uint32_t reserved;                      /* reserved for root in % */
10145 +       uint32_t flags;
10146 +};
10147 +
10148 +#endif /* CONFIG_COMPAT */
10149 +
10150 +#include <linux/compiler.h>
10151 +
10152 +extern int vc_add_dlimit(uint32_t, void __user *);
10153 +extern int vc_rem_dlimit(uint32_t, void __user *);
10154 +
10155 +extern int vc_set_dlimit(uint32_t, void __user *);
10156 +extern int vc_get_dlimit(uint32_t, void __user *);
10157 +
10158 +#ifdef CONFIG_COMPAT
10159 +
10160 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
10161 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
10162 +
10163 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
10164 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
10165 +
10166 +#endif /* CONFIG_COMPAT */
10167 +
10168 +#endif /* _VSERVER_DLIMIT_CMD_H */
10169 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/global.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/global.h
10170 --- linux-4.4.115/include/linux/vserver/global.h        1970-01-01 00:00:00.000000000 +0000
10171 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/global.h      2018-01-09 16:36:32.000000000 +0000
10172 @@ -0,0 +1,19 @@
10173 +#ifndef _VSERVER_GLOBAL_H
10174 +#define _VSERVER_GLOBAL_H
10175 +
10176 +
10177 +extern atomic_t vx_global_ctotal;
10178 +extern atomic_t vx_global_cactive;
10179 +
10180 +extern atomic_t nx_global_ctotal;
10181 +extern atomic_t nx_global_cactive;
10182 +
10183 +extern atomic_t vs_global_nsproxy;
10184 +extern atomic_t vs_global_fs;
10185 +extern atomic_t vs_global_mnt_ns;
10186 +extern atomic_t vs_global_uts_ns;
10187 +extern atomic_t vs_global_user_ns;
10188 +extern atomic_t vs_global_pid_ns;
10189 +
10190 +
10191 +#endif /* _VSERVER_GLOBAL_H */
10192 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/history.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/history.h
10193 --- linux-4.4.115/include/linux/vserver/history.h       1970-01-01 00:00:00.000000000 +0000
10194 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/history.h     2018-01-09 16:36:32.000000000 +0000
10195 @@ -0,0 +1,197 @@
10196 +#ifndef _VSERVER_HISTORY_H
10197 +#define _VSERVER_HISTORY_H
10198 +
10199 +
10200 +enum {
10201 +       VXH_UNUSED = 0,
10202 +       VXH_THROW_OOPS = 1,
10203 +
10204 +       VXH_GET_VX_INFO,
10205 +       VXH_PUT_VX_INFO,
10206 +       VXH_INIT_VX_INFO,
10207 +       VXH_SET_VX_INFO,
10208 +       VXH_CLR_VX_INFO,
10209 +       VXH_CLAIM_VX_INFO,
10210 +       VXH_RELEASE_VX_INFO,
10211 +       VXH_ALLOC_VX_INFO,
10212 +       VXH_DEALLOC_VX_INFO,
10213 +       VXH_HASH_VX_INFO,
10214 +       VXH_UNHASH_VX_INFO,
10215 +       VXH_LOC_VX_INFO,
10216 +       VXH_LOOKUP_VX_INFO,
10217 +       VXH_CREATE_VX_INFO,
10218 +};
10219 +
10220 +struct _vxhe_vxi {
10221 +       struct vx_info *ptr;
10222 +       unsigned xid;
10223 +       unsigned usecnt;
10224 +       unsigned tasks;
10225 +};
10226 +
10227 +struct _vxhe_set_clr {
10228 +       void *data;
10229 +};
10230 +
10231 +struct _vxhe_loc_lookup {
10232 +       unsigned arg;
10233 +};
10234 +
10235 +struct _vx_hist_entry {
10236 +       void *loc;
10237 +       unsigned short seq;
10238 +       unsigned short type;
10239 +       struct _vxhe_vxi vxi;
10240 +       union {
10241 +               struct _vxhe_set_clr sc;
10242 +               struct _vxhe_loc_lookup ll;
10243 +       };
10244 +};
10245 +
10246 +#ifdef CONFIG_VSERVER_HISTORY
10247 +
10248 +extern unsigned volatile int vxh_active;
10249 +
10250 +struct _vx_hist_entry *vxh_advance(void *loc);
10251 +
10252 +
10253 +static inline
10254 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
10255 +{
10256 +       entry->vxi.ptr = vxi;
10257 +       if (vxi) {
10258 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
10259 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
10260 +               entry->vxi.xid = vxi->vx_id;
10261 +       }
10262 +}
10263 +
10264 +
10265 +#define        __HERE__ current_text_addr()
10266 +
10267 +#define __VXH_BODY(__type, __data, __here)     \
10268 +       struct _vx_hist_entry *entry;           \
10269 +                                               \
10270 +       preempt_disable();                      \
10271 +       entry = vxh_advance(__here);            \
10272 +       __data;                                 \
10273 +       entry->type = __type;                   \
10274 +       preempt_enable();
10275 +
10276 +
10277 +       /* pass vxi only */
10278 +
10279 +#define __VXH_SMPL                             \
10280 +       __vxh_copy_vxi(entry, vxi)
10281 +
10282 +static inline
10283 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
10284 +{
10285 +       __VXH_BODY(__type, __VXH_SMPL, __here)
10286 +}
10287 +
10288 +       /* pass vxi and data (void *) */
10289 +
10290 +#define __VXH_DATA                             \
10291 +       __vxh_copy_vxi(entry, vxi);             \
10292 +       entry->sc.data = data
10293 +
10294 +static inline
10295 +void   __vxh_data(struct vx_info *vxi, void *data,
10296 +                       int __type, void *__here)
10297 +{
10298 +       __VXH_BODY(__type, __VXH_DATA, __here)
10299 +}
10300 +
10301 +       /* pass vxi and arg (long) */
10302 +
10303 +#define __VXH_LONG                             \
10304 +       __vxh_copy_vxi(entry, vxi);             \
10305 +       entry->ll.arg = arg
10306 +
10307 +static inline
10308 +void   __vxh_long(struct vx_info *vxi, long arg,
10309 +                       int __type, void *__here)
10310 +{
10311 +       __VXH_BODY(__type, __VXH_LONG, __here)
10312 +}
10313 +
10314 +
10315 +static inline
10316 +void   __vxh_throw_oops(void *__here)
10317 +{
10318 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
10319 +       /* prevent further acquisition */
10320 +       vxh_active = 0;
10321 +}
10322 +
10323 +
10324 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
10325 +
10326 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
10327 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
10328 +
10329 +#define __vxh_init_vx_info(v, d, h) \
10330 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
10331 +#define __vxh_set_vx_info(v, d, h) \
10332 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
10333 +#define __vxh_clr_vx_info(v, d, h) \
10334 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
10335 +
10336 +#define __vxh_claim_vx_info(v, d, h) \
10337 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
10338 +#define __vxh_release_vx_info(v, d, h) \
10339 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
10340 +
10341 +#define vxh_alloc_vx_info(v) \
10342 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
10343 +#define vxh_dealloc_vx_info(v) \
10344 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
10345 +
10346 +#define vxh_hash_vx_info(v) \
10347 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
10348 +#define vxh_unhash_vx_info(v) \
10349 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
10350 +
10351 +#define vxh_loc_vx_info(v, l) \
10352 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
10353 +#define vxh_lookup_vx_info(v, l) \
10354 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
10355 +#define vxh_create_vx_info(v, l) \
10356 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
10357 +
10358 +extern void vxh_dump_history(void);
10359 +
10360 +
10361 +#else  /* CONFIG_VSERVER_HISTORY */
10362 +
10363 +#define        __HERE__        0
10364 +
10365 +#define vxh_throw_oops()               do { } while (0)
10366 +
10367 +#define __vxh_get_vx_info(v, h)                do { } while (0)
10368 +#define __vxh_put_vx_info(v, h)                do { } while (0)
10369 +
10370 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
10371 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
10372 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
10373 +
10374 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
10375 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
10376 +
10377 +#define vxh_alloc_vx_info(v)           do { } while (0)
10378 +#define vxh_dealloc_vx_info(v)         do { } while (0)
10379 +
10380 +#define vxh_hash_vx_info(v)            do { } while (0)
10381 +#define vxh_unhash_vx_info(v)          do { } while (0)
10382 +
10383 +#define vxh_loc_vx_info(v, l)          do { } while (0)
10384 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
10385 +#define vxh_create_vx_info(v, l)       do { } while (0)
10386 +
10387 +#define vxh_dump_history()             do { } while (0)
10388 +
10389 +
10390 +#endif /* CONFIG_VSERVER_HISTORY */
10391 +
10392 +#endif /* _VSERVER_HISTORY_H */
10393 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/inode.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/inode.h
10394 --- linux-4.4.115/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
10395 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/inode.h       2018-01-09 16:36:32.000000000 +0000
10396 @@ -0,0 +1,19 @@
10397 +#ifndef _VSERVER_INODE_H
10398 +#define _VSERVER_INODE_H
10399 +
10400 +#include <uapi/vserver/inode.h>
10401 +
10402 +
10403 +#ifdef CONFIG_VSERVER_PROC_SECURE
10404 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
10405 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10406 +#else
10407 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
10408 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10409 +#endif
10410 +
10411 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
10412 +
10413 +#else  /* _VSERVER_INODE_H */
10414 +#warning duplicate inclusion
10415 +#endif /* _VSERVER_INODE_H */
10416 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/inode_cmd.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/inode_cmd.h
10417 --- linux-4.4.115/include/linux/vserver/inode_cmd.h     1970-01-01 00:00:00.000000000 +0000
10418 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/inode_cmd.h   2018-01-09 16:36:32.000000000 +0000
10419 @@ -0,0 +1,36 @@
10420 +#ifndef _VSERVER_INODE_CMD_H
10421 +#define _VSERVER_INODE_CMD_H
10422 +
10423 +#include <uapi/vserver/inode_cmd.h>
10424 +
10425 +
10426 +
10427 +#ifdef CONFIG_COMPAT
10428 +
10429 +#include <asm/compat.h>
10430 +
10431 +struct vcmd_ctx_iattr_v1_x32 {
10432 +       compat_uptr_t name_ptr;
10433 +       uint32_t tag;
10434 +       uint32_t flags;
10435 +       uint32_t mask;
10436 +};
10437 +
10438 +#endif /* CONFIG_COMPAT */
10439 +
10440 +#include <linux/compiler.h>
10441 +
10442 +extern int vc_get_iattr(void __user *);
10443 +extern int vc_set_iattr(void __user *);
10444 +
10445 +extern int vc_fget_iattr(uint32_t, void __user *);
10446 +extern int vc_fset_iattr(uint32_t, void __user *);
10447 +
10448 +#ifdef CONFIG_COMPAT
10449 +
10450 +extern int vc_get_iattr_x32(void __user *);
10451 +extern int vc_set_iattr_x32(void __user *);
10452 +
10453 +#endif /* CONFIG_COMPAT */
10454 +
10455 +#endif /* _VSERVER_INODE_CMD_H */
10456 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/limit.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/limit.h
10457 --- linux-4.4.115/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
10458 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/limit.h       2018-01-09 16:36:32.000000000 +0000
10459 @@ -0,0 +1,67 @@
10460 +#ifndef _VSERVER_LIMIT_H
10461 +#define _VSERVER_LIMIT_H
10462 +
10463 +#include <uapi/vserver/limit.h>
10464 +
10465 +
10466 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
10467 +
10468 +/*     keep in sync with CRLIM_INFINITY */
10469 +
10470 +#define        VLIM_INFINITY   (~0ULL)
10471 +
10472 +#include <asm/atomic.h>
10473 +#include <asm/resource.h>
10474 +
10475 +#ifndef RLIM_INFINITY
10476 +#warning RLIM_INFINITY is undefined
10477 +#endif
10478 +
10479 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
10480 +
10481 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
10482 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
10483 +
10484 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
10485 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
10486 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
10487 +
10488 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
10489 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
10490 +
10491 +typedef atomic_long_t rlim_atomic_t;
10492 +typedef unsigned long rlim_t;
10493 +
10494 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
10495 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
10496 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
10497 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
10498 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
10499 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
10500 +
10501 +
10502 +#if    (RLIM_INFINITY == VLIM_INFINITY)
10503 +#define        VX_VLIM(r) ((long long)(long)(r))
10504 +#define        VX_RLIM(v) ((rlim_t)(v))
10505 +#else
10506 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
10507 +               ? VLIM_INFINITY : (long long)(r))
10508 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
10509 +               ? RLIM_INFINITY : (rlim_t)(v))
10510 +#endif
10511 +
10512 +struct sysinfo;
10513 +
10514 +#ifdef CONFIG_MEMCG
10515 +void vx_vsi_meminfo(struct sysinfo *);
10516 +void vx_vsi_swapinfo(struct sysinfo *);
10517 +long vx_vsi_cached(struct sysinfo *);
10518 +#else  /* !CONFIG_MEMCG */
10519 +#define vx_vsi_meminfo(s) do { } while (0)
10520 +#define vx_vsi_swapinfo(s) do { } while (0)
10521 +#define vx_vsi_cached(s) (0L)
10522 +#endif /* !CONFIG_MEMCG */
10523 +
10524 +#define NUM_LIMITS     24
10525 +
10526 +#endif /* _VSERVER_LIMIT_H */
10527 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/limit_cmd.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/limit_cmd.h
10528 --- linux-4.4.115/include/linux/vserver/limit_cmd.h     1970-01-01 00:00:00.000000000 +0000
10529 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/limit_cmd.h   2018-01-09 16:36:32.000000000 +0000
10530 @@ -0,0 +1,35 @@
10531 +#ifndef _VSERVER_LIMIT_CMD_H
10532 +#define _VSERVER_LIMIT_CMD_H
10533 +
10534 +#include <uapi/vserver/limit_cmd.h>
10535 +
10536 +
10537 +#ifdef CONFIG_IA32_EMULATION
10538 +
10539 +struct vcmd_ctx_rlimit_v0_x32 {
10540 +       uint32_t id;
10541 +       uint64_t minimum;
10542 +       uint64_t softlimit;
10543 +       uint64_t maximum;
10544 +} __attribute__ ((packed));
10545 +
10546 +#endif /* CONFIG_IA32_EMULATION */
10547 +
10548 +#include <linux/compiler.h>
10549 +
10550 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
10551 +extern int vc_get_rlimit(struct vx_info *, void __user *);
10552 +extern int vc_set_rlimit(struct vx_info *, void __user *);
10553 +extern int vc_reset_hits(struct vx_info *, void __user *);
10554 +extern int vc_reset_minmax(struct vx_info *, void __user *);
10555 +
10556 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
10557 +
10558 +#ifdef CONFIG_IA32_EMULATION
10559 +
10560 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
10561 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
10562 +
10563 +#endif /* CONFIG_IA32_EMULATION */
10564 +
10565 +#endif /* _VSERVER_LIMIT_CMD_H */
10566 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/limit_def.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/limit_def.h
10567 --- linux-4.4.115/include/linux/vserver/limit_def.h     1970-01-01 00:00:00.000000000 +0000
10568 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/limit_def.h   2018-01-09 16:36:32.000000000 +0000
10569 @@ -0,0 +1,47 @@
10570 +#ifndef _VSERVER_LIMIT_DEF_H
10571 +#define _VSERVER_LIMIT_DEF_H
10572 +
10573 +#include <asm/atomic.h>
10574 +#include <asm/resource.h>
10575 +
10576 +#include "limit.h"
10577 +
10578 +
10579 +struct _vx_res_limit {
10580 +       rlim_t soft;            /* Context soft limit */
10581 +       rlim_t hard;            /* Context hard limit */
10582 +
10583 +       rlim_atomic_t rcur;     /* Current value */
10584 +       rlim_t rmin;            /* Context minimum */
10585 +       rlim_t rmax;            /* Context maximum */
10586 +
10587 +       atomic_t lhit;          /* Limit hits */
10588 +};
10589 +
10590 +/* context sub struct */
10591 +
10592 +struct _vx_limit {
10593 +       struct _vx_res_limit res[NUM_LIMITS];
10594 +};
10595 +
10596 +#ifdef CONFIG_VSERVER_DEBUG
10597 +
10598 +static inline void __dump_vx_limit(struct _vx_limit *limit)
10599 +{
10600 +       int i;
10601 +
10602 +       printk("\t_vx_limit:");
10603 +       for (i = 0; i < NUM_LIMITS; i++) {
10604 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
10605 +                       i, (unsigned long)__rlim_get(limit, i),
10606 +                       (unsigned long)__rlim_rmin(limit, i),
10607 +                       (unsigned long)__rlim_rmax(limit, i),
10608 +                       (long)__rlim_soft(limit, i),
10609 +                       (long)__rlim_hard(limit, i),
10610 +                       atomic_read(&__rlim_lhit(limit, i)));
10611 +       }
10612 +}
10613 +
10614 +#endif
10615 +
10616 +#endif /* _VSERVER_LIMIT_DEF_H */
10617 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/limit_int.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/limit_int.h
10618 --- linux-4.4.115/include/linux/vserver/limit_int.h     1970-01-01 00:00:00.000000000 +0000
10619 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/limit_int.h   2018-01-09 16:36:32.000000000 +0000
10620 @@ -0,0 +1,193 @@
10621 +#ifndef _VSERVER_LIMIT_INT_H
10622 +#define _VSERVER_LIMIT_INT_H
10623 +
10624 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
10625 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
10626 +
10627 +extern const char *vlimit_name[NUM_LIMITS];
10628 +
10629 +static inline void __vx_acc_cres(struct vx_info *vxi,
10630 +       int res, int dir, void *_data, char *_file, int _line)
10631 +{
10632 +       if (VXD_RCRES_COND(res))
10633 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
10634 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10635 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10636 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
10637 +       if (!vxi)
10638 +               return;
10639 +
10640 +       if (dir > 0)
10641 +               __rlim_inc(&vxi->limit, res);
10642 +       else
10643 +               __rlim_dec(&vxi->limit, res);
10644 +}
10645 +
10646 +static inline void __vx_add_cres(struct vx_info *vxi,
10647 +       int res, int amount, void *_data, char *_file, int _line)
10648 +{
10649 +       if (VXD_RCRES_COND(res))
10650 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
10651 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10652 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10653 +                       amount, _data, _file, _line);
10654 +       if (amount == 0)
10655 +               return;
10656 +       if (!vxi)
10657 +               return;
10658 +       __rlim_add(&vxi->limit, res, amount);
10659 +}
10660 +
10661 +static inline
10662 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
10663 +{
10664 +       int cond = (value > __rlim_rmax(limit, res));
10665 +
10666 +       if (cond)
10667 +               __rlim_rmax(limit, res) = value;
10668 +       return cond;
10669 +}
10670 +
10671 +static inline
10672 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
10673 +{
10674 +       int cond = (value < __rlim_rmin(limit, res));
10675 +
10676 +       if (cond)
10677 +               __rlim_rmin(limit, res) = value;
10678 +       return cond;
10679 +}
10680 +
10681 +static inline
10682 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
10683 +{
10684 +       if (!__vx_cres_adjust_max(limit, res, value))
10685 +               __vx_cres_adjust_min(limit, res, value);
10686 +}
10687 +
10688 +
10689 +/*     return values:
10690 +        +1 ... no limit hit
10691 +        -1 ... over soft limit
10692 +         0 ... over hard limit         */
10693 +
10694 +static inline int __vx_cres_avail(struct vx_info *vxi,
10695 +       int res, int num, char *_file, int _line)
10696 +{
10697 +       struct _vx_limit *limit;
10698 +       rlim_t value;
10699 +
10700 +       if (VXD_RLIMIT_COND(res))
10701 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
10702 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10703 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
10704 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
10705 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10706 +                       num, _file, _line);
10707 +       if (!vxi)
10708 +               return 1;
10709 +
10710 +       limit = &vxi->limit;
10711 +       value = __rlim_get(limit, res);
10712 +
10713 +       if (!__vx_cres_adjust_max(limit, res, value))
10714 +               __vx_cres_adjust_min(limit, res, value);
10715 +
10716 +       if (num == 0)
10717 +               return 1;
10718 +
10719 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
10720 +               return -1;
10721 +       if (value + num <= __rlim_soft(limit, res))
10722 +               return -1;
10723 +
10724 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
10725 +               return 1;
10726 +       if (value + num <= __rlim_hard(limit, res))
10727 +               return 1;
10728 +
10729 +       __rlim_hit(limit, res);
10730 +       return 0;
10731 +}
10732 +
10733 +
10734 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
10735 +
10736 +static inline
10737 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
10738 +{
10739 +       rlim_t value, sum = 0;
10740 +       int res;
10741 +
10742 +       while ((res = *array++)) {
10743 +               value = __rlim_get(limit, res);
10744 +               __vx_cres_fixup(limit, res, value);
10745 +               sum += value;
10746 +       }
10747 +       return sum;
10748 +}
10749 +
10750 +static inline
10751 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
10752 +{
10753 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
10754 +       int res = *array;
10755 +
10756 +       if (value == __rlim_get(limit, res))
10757 +               return value;
10758 +
10759 +       __rlim_set(limit, res, value);
10760 +       /* now adjust min/max */
10761 +       if (!__vx_cres_adjust_max(limit, res, value))
10762 +               __vx_cres_adjust_min(limit, res, value);
10763 +
10764 +       return value;
10765 +}
10766 +
10767 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
10768 +       const int *array, int num, char *_file, int _line)
10769 +{
10770 +       struct _vx_limit *limit;
10771 +       rlim_t value = 0;
10772 +       int res;
10773 +
10774 +       if (num == 0)
10775 +               return 1;
10776 +       if (!vxi)
10777 +               return 1;
10778 +
10779 +       limit = &vxi->limit;
10780 +       res = *array;
10781 +       value = __vx_cres_array_sum(limit, array + 1);
10782 +
10783 +       __rlim_set(limit, res, value);
10784 +       __vx_cres_fixup(limit, res, value);
10785 +
10786 +       return __vx_cres_avail(vxi, res, num, _file, _line);
10787 +}
10788 +
10789 +
10790 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
10791 +{
10792 +       rlim_t value;
10793 +       int res;
10794 +
10795 +       /* complex resources first */
10796 +       if ((id < 0) || (id == RLIMIT_RSS))
10797 +               __vx_cres_array_fixup(limit, VLA_RSS);
10798 +
10799 +       for (res = 0; res < NUM_LIMITS; res++) {
10800 +               if ((id > 0) && (res != id))
10801 +                       continue;
10802 +
10803 +               value = __rlim_get(limit, res);
10804 +               __vx_cres_fixup(limit, res, value);
10805 +
10806 +               /* not supposed to happen, maybe warn? */
10807 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
10808 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
10809 +       }
10810 +}
10811 +
10812 +
10813 +#endif /* _VSERVER_LIMIT_INT_H */
10814 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/monitor.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/monitor.h
10815 --- linux-4.4.115/include/linux/vserver/monitor.h       1970-01-01 00:00:00.000000000 +0000
10816 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/monitor.h     2018-01-09 16:36:32.000000000 +0000
10817 @@ -0,0 +1,6 @@
10818 +#ifndef _VSERVER_MONITOR_H
10819 +#define _VSERVER_MONITOR_H
10820 +
10821 +#include <uapi/vserver/monitor.h>
10822 +
10823 +#endif /* _VSERVER_MONITOR_H */
10824 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/network.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/network.h
10825 --- linux-4.4.115/include/linux/vserver/network.h       1970-01-01 00:00:00.000000000 +0000
10826 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/network.h     2018-01-09 16:36:32.000000000 +0000
10827 @@ -0,0 +1,76 @@
10828 +#ifndef _VSERVER_NETWORK_H
10829 +#define _VSERVER_NETWORK_H
10830 +
10831 +
10832 +#include <linux/list.h>
10833 +#include <linux/spinlock.h>
10834 +#include <linux/rcupdate.h>
10835 +#include <linux/in.h>
10836 +#include <linux/in6.h>
10837 +#include <asm/atomic.h>
10838 +#include <uapi/vserver/network.h>
10839 +
10840 +struct nx_addr_v4 {
10841 +       struct nx_addr_v4 *next;
10842 +       struct in_addr ip[2];
10843 +       struct in_addr mask;
10844 +       uint16_t type;
10845 +       uint16_t flags;
10846 +};
10847 +
10848 +struct nx_addr_v6 {
10849 +       struct nx_addr_v6 *next;
10850 +       struct in6_addr ip;
10851 +       struct in6_addr mask;
10852 +       uint32_t prefix;
10853 +       uint16_t type;
10854 +       uint16_t flags;
10855 +};
10856 +
10857 +struct nx_info {
10858 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
10859 +       vnid_t nx_id;                   /* vnet id */
10860 +       atomic_t nx_usecnt;             /* usage count */
10861 +       atomic_t nx_tasks;              /* tasks count */
10862 +       int nx_state;                   /* context state */
10863 +
10864 +       uint64_t nx_flags;              /* network flag word */
10865 +       uint64_t nx_ncaps;              /* network capabilities */
10866 +
10867 +       spinlock_t addr_lock;           /* protect address changes */
10868 +       struct in_addr v4_lback;        /* Loopback address */
10869 +       struct in_addr v4_bcast;        /* Broadcast address */
10870 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
10871 +#ifdef CONFIG_IPV6
10872 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
10873 +#endif
10874 +       char nx_name[65];               /* network context name */
10875 +};
10876 +
10877 +
10878 +/* status flags */
10879 +
10880 +#define NXS_HASHED      0x0001
10881 +#define NXS_SHUTDOWN    0x0100
10882 +#define NXS_RELEASED    0x8000
10883 +
10884 +extern struct nx_info *lookup_nx_info(int);
10885 +
10886 +extern int get_nid_list(int, unsigned int *, int);
10887 +extern int nid_is_hashed(vnid_t);
10888 +
10889 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
10890 +
10891 +extern long vs_net_change(struct nx_info *, unsigned int);
10892 +
10893 +struct sock;
10894 +
10895 +
10896 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
10897 +#ifdef  CONFIG_IPV6
10898 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
10899 +#else
10900 +#define NX_IPV6(n)     (0)
10901 +#endif
10902 +
10903 +#endif /* _VSERVER_NETWORK_H */
10904 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/network_cmd.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/network_cmd.h
10905 --- linux-4.4.115/include/linux/vserver/network_cmd.h   1970-01-01 00:00:00.000000000 +0000
10906 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/network_cmd.h 2018-01-09 16:36:32.000000000 +0000
10907 @@ -0,0 +1,37 @@
10908 +#ifndef _VSERVER_NETWORK_CMD_H
10909 +#define _VSERVER_NETWORK_CMD_H
10910 +
10911 +#include <uapi/vserver/network_cmd.h>
10912 +
10913 +extern int vc_task_nid(uint32_t);
10914 +
10915 +extern int vc_nx_info(struct nx_info *, void __user *);
10916 +
10917 +extern int vc_net_create(uint32_t, void __user *);
10918 +extern int vc_net_migrate(struct nx_info *, void __user *);
10919 +
10920 +extern int vc_net_add(struct nx_info *, void __user *);
10921 +extern int vc_net_remove(struct nx_info *, void __user *);
10922 +
10923 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
10924 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
10925 +
10926 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
10927 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
10928 +
10929 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
10930 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
10931 +
10932 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
10933 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
10934 +
10935 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
10936 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
10937 +
10938 +extern int vc_get_nflags(struct nx_info *, void __user *);
10939 +extern int vc_set_nflags(struct nx_info *, void __user *);
10940 +
10941 +extern int vc_get_ncaps(struct nx_info *, void __user *);
10942 +extern int vc_set_ncaps(struct nx_info *, void __user *);
10943 +
10944 +#endif /* _VSERVER_CONTEXT_CMD_H */
10945 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/percpu.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/percpu.h
10946 --- linux-4.4.115/include/linux/vserver/percpu.h        1970-01-01 00:00:00.000000000 +0000
10947 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/percpu.h      2018-01-09 16:36:32.000000000 +0000
10948 @@ -0,0 +1,14 @@
10949 +#ifndef _VSERVER_PERCPU_H
10950 +#define _VSERVER_PERCPU_H
10951 +
10952 +#include "cvirt_def.h"
10953 +#include "sched_def.h"
10954 +
10955 +struct _vx_percpu {
10956 +       struct _vx_cvirt_pc cvirt;
10957 +       struct _vx_sched_pc sched;
10958 +};
10959 +
10960 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
10961 +
10962 +#endif /* _VSERVER_PERCPU_H */
10963 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/pid.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/pid.h
10964 --- linux-4.4.115/include/linux/vserver/pid.h   1970-01-01 00:00:00.000000000 +0000
10965 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/pid.h 2018-01-09 16:36:32.000000000 +0000
10966 @@ -0,0 +1,51 @@
10967 +#ifndef _VSERVER_PID_H
10968 +#define _VSERVER_PID_H
10969 +
10970 +/* pid faking stuff */
10971 +
10972 +#define vx_info_map_pid(v, p) \
10973 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
10974 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
10975 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
10976 +#define vx_map_tgid(p) vx_map_pid(p)
10977 +
10978 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
10979 +       const char *func, const char *file, int line)
10980 +{
10981 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
10982 +               vxfprintk(VXD_CBIT(cvirt, 2),
10983 +                       "vx_map_tgid: %p/%llx: %d -> %d",
10984 +                       vxi, (long long)vxi->vx_flags, pid,
10985 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
10986 +                       func, file, line);
10987 +               if (pid == 0)
10988 +                       return 0;
10989 +               if (pid == vxi->vx_initpid)
10990 +                       return 1;
10991 +       }
10992 +       return pid;
10993 +}
10994 +
10995 +#define vx_info_rmap_pid(v, p) \
10996 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
10997 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
10998 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
10999 +
11000 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
11001 +       const char *func, const char *file, int line)
11002 +{
11003 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11004 +               vxfprintk(VXD_CBIT(cvirt, 2),
11005 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
11006 +                       vxi, (long long)vxi->vx_flags, pid,
11007 +                       (pid == 1) ? vxi->vx_initpid : pid,
11008 +                       func, file, line);
11009 +               if ((pid == 1) && vxi->vx_initpid)
11010 +                       return vxi->vx_initpid;
11011 +               if (pid == vxi->vx_initpid)
11012 +                       return ~0U;
11013 +       }
11014 +       return pid;
11015 +}
11016 +
11017 +#endif
11018 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/sched.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/sched.h
11019 --- linux-4.4.115/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
11020 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/sched.h       2018-01-09 16:36:32.000000000 +0000
11021 @@ -0,0 +1,23 @@
11022 +#ifndef _VSERVER_SCHED_H
11023 +#define _VSERVER_SCHED_H
11024 +
11025 +
11026 +#ifdef __KERNEL__
11027 +
11028 +struct timespec;
11029 +
11030 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11031 +
11032 +
11033 +struct vx_info;
11034 +
11035 +void vx_update_load(struct vx_info *);
11036 +
11037 +
11038 +void vx_update_sched_param(struct _vx_sched *sched,
11039 +       struct _vx_sched_pc *sched_pc);
11040 +
11041 +#endif /* __KERNEL__ */
11042 +#else  /* _VSERVER_SCHED_H */
11043 +#warning duplicate inclusion
11044 +#endif /* _VSERVER_SCHED_H */
11045 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/sched_cmd.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/sched_cmd.h
11046 --- linux-4.4.115/include/linux/vserver/sched_cmd.h     1970-01-01 00:00:00.000000000 +0000
11047 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/sched_cmd.h   2018-01-09 16:36:32.000000000 +0000
11048 @@ -0,0 +1,11 @@
11049 +#ifndef _VSERVER_SCHED_CMD_H
11050 +#define _VSERVER_SCHED_CMD_H
11051 +
11052 +
11053 +#include <linux/compiler.h>
11054 +#include <uapi/vserver/sched_cmd.h>
11055 +
11056 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
11057 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
11058 +
11059 +#endif /* _VSERVER_SCHED_CMD_H */
11060 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/sched_def.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/sched_def.h
11061 --- linux-4.4.115/include/linux/vserver/sched_def.h     1970-01-01 00:00:00.000000000 +0000
11062 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/sched_def.h   2018-01-09 16:36:32.000000000 +0000
11063 @@ -0,0 +1,38 @@
11064 +#ifndef _VSERVER_SCHED_DEF_H
11065 +#define _VSERVER_SCHED_DEF_H
11066 +
11067 +#include <linux/spinlock.h>
11068 +#include <linux/jiffies.h>
11069 +#include <linux/cpumask.h>
11070 +#include <asm/atomic.h>
11071 +#include <asm/param.h>
11072 +
11073 +
11074 +/* context sub struct */
11075 +
11076 +struct _vx_sched {
11077 +       int prio_bias;                  /* bias offset for priority */
11078 +
11079 +       cpumask_t update;               /* CPUs which should update */
11080 +};
11081 +
11082 +struct _vx_sched_pc {
11083 +       int prio_bias;                  /* bias offset for priority */
11084 +
11085 +       uint64_t user_ticks;            /* token tick events */
11086 +       uint64_t sys_ticks;             /* token tick events */
11087 +       uint64_t hold_ticks;            /* token ticks paused */
11088 +};
11089 +
11090 +
11091 +#ifdef CONFIG_VSERVER_DEBUG
11092 +
11093 +static inline void __dump_vx_sched(struct _vx_sched *sched)
11094 +{
11095 +       printk("\t_vx_sched:\n");
11096 +       printk("\t priority = %4d\n", sched->prio_bias);
11097 +}
11098 +
11099 +#endif
11100 +
11101 +#endif /* _VSERVER_SCHED_DEF_H */
11102 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/signal.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/signal.h
11103 --- linux-4.4.115/include/linux/vserver/signal.h        1970-01-01 00:00:00.000000000 +0000
11104 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/signal.h      2018-01-09 16:36:32.000000000 +0000
11105 @@ -0,0 +1,14 @@
11106 +#ifndef _VSERVER_SIGNAL_H
11107 +#define _VSERVER_SIGNAL_H
11108 +
11109 +
11110 +#ifdef __KERNEL__
11111 +
11112 +struct vx_info;
11113 +
11114 +int vx_info_kill(struct vx_info *, int, int);
11115 +
11116 +#endif /* __KERNEL__ */
11117 +#else  /* _VSERVER_SIGNAL_H */
11118 +#warning duplicate inclusion
11119 +#endif /* _VSERVER_SIGNAL_H */
11120 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/signal_cmd.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/signal_cmd.h
11121 --- linux-4.4.115/include/linux/vserver/signal_cmd.h    1970-01-01 00:00:00.000000000 +0000
11122 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/signal_cmd.h  2018-01-09 16:36:32.000000000 +0000
11123 @@ -0,0 +1,14 @@
11124 +#ifndef _VSERVER_SIGNAL_CMD_H
11125 +#define _VSERVER_SIGNAL_CMD_H
11126 +
11127 +#include <uapi/vserver/signal_cmd.h>
11128 +
11129 +
11130 +extern int vc_ctx_kill(struct vx_info *, void __user *);
11131 +extern int vc_wait_exit(struct vx_info *, void __user *);
11132 +
11133 +
11134 +extern int vc_get_pflags(uint32_t pid, void __user *);
11135 +extern int vc_set_pflags(uint32_t pid, void __user *);
11136 +
11137 +#endif /* _VSERVER_SIGNAL_CMD_H */
11138 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/space.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/space.h
11139 --- linux-4.4.115/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
11140 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/space.h       2018-01-09 16:36:32.000000000 +0000
11141 @@ -0,0 +1,12 @@
11142 +#ifndef _VSERVER_SPACE_H
11143 +#define _VSERVER_SPACE_H
11144 +
11145 +#include <linux/types.h>
11146 +
11147 +struct vx_info;
11148 +
11149 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
11150 +
11151 +#else  /* _VSERVER_SPACE_H */
11152 +#warning duplicate inclusion
11153 +#endif /* _VSERVER_SPACE_H */
11154 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/space_cmd.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/space_cmd.h
11155 --- linux-4.4.115/include/linux/vserver/space_cmd.h     1970-01-01 00:00:00.000000000 +0000
11156 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/space_cmd.h   2018-01-09 16:36:32.000000000 +0000
11157 @@ -0,0 +1,13 @@
11158 +#ifndef _VSERVER_SPACE_CMD_H
11159 +#define _VSERVER_SPACE_CMD_H
11160 +
11161 +#include <uapi/vserver/space_cmd.h>
11162 +
11163 +
11164 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
11165 +extern int vc_set_space_v1(struct vx_info *, void __user *);
11166 +extern int vc_enter_space(struct vx_info *, void __user *);
11167 +extern int vc_set_space(struct vx_info *, void __user *);
11168 +extern int vc_get_space_mask(void __user *, int);
11169 +
11170 +#endif /* _VSERVER_SPACE_CMD_H */
11171 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/switch.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/switch.h
11172 --- linux-4.4.115/include/linux/vserver/switch.h        1970-01-01 00:00:00.000000000 +0000
11173 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/switch.h      2018-01-09 16:36:32.000000000 +0000
11174 @@ -0,0 +1,8 @@
11175 +#ifndef _VSERVER_SWITCH_H
11176 +#define _VSERVER_SWITCH_H
11177 +
11178 +
11179 +#include <linux/errno.h>
11180 +#include <uapi/vserver/switch.h>
11181 +
11182 +#endif /* _VSERVER_SWITCH_H */
11183 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/tag.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/tag.h
11184 --- linux-4.4.115/include/linux/vserver/tag.h   1970-01-01 00:00:00.000000000 +0000
11185 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/tag.h 2018-01-09 16:36:32.000000000 +0000
11186 @@ -0,0 +1,160 @@
11187 +#ifndef _DX_TAG_H
11188 +#define _DX_TAG_H
11189 +
11190 +#include <linux/types.h>
11191 +#include <linux/uidgid.h>
11192 +
11193 +
11194 +#define DX_TAG(in)     (IS_TAGGED(in))
11195 +
11196 +
11197 +#ifdef CONFIG_TAG_NFSD
11198 +#define DX_TAG_NFSD    1
11199 +#else
11200 +#define DX_TAG_NFSD    0
11201 +#endif
11202 +
11203 +
11204 +#ifdef CONFIG_TAGGING_NONE
11205 +
11206 +#define MAX_UID                0xFFFFFFFF
11207 +#define MAX_GID                0xFFFFFFFF
11208 +
11209 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
11210 +
11211 +#define TAGINO_UID(cond, uid, tag)     (uid)
11212 +#define TAGINO_GID(cond, gid, tag)     (gid)
11213 +
11214 +#endif
11215 +
11216 +
11217 +#ifdef CONFIG_TAGGING_GID16
11218 +
11219 +#define MAX_UID                0xFFFFFFFF
11220 +#define MAX_GID                0x0000FFFF
11221 +
11222 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11223 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
11224 +
11225 +#define TAGINO_UID(cond, uid, tag)     (uid)
11226 +#define TAGINO_GID(cond, gid, tag)     \
11227 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
11228 +
11229 +#endif
11230 +
11231 +
11232 +#ifdef CONFIG_TAGGING_ID24
11233 +
11234 +#define MAX_UID                0x00FFFFFF
11235 +#define MAX_GID                0x00FFFFFF
11236 +
11237 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11238 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
11239 +
11240 +#define TAGINO_UID(cond, uid, tag)     \
11241 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
11242 +#define TAGINO_GID(cond, gid, tag)     \
11243 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
11244 +
11245 +#endif
11246 +
11247 +
11248 +#ifdef CONFIG_TAGGING_UID16
11249 +
11250 +#define MAX_UID                0x0000FFFF
11251 +#define MAX_GID                0xFFFFFFFF
11252 +
11253 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11254 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
11255 +
11256 +#define TAGINO_UID(cond, uid, tag)     \
11257 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
11258 +#define TAGINO_GID(cond, gid, tag)     (gid)
11259 +
11260 +#endif
11261 +
11262 +
11263 +#ifdef CONFIG_TAGGING_INTERN
11264 +
11265 +#define MAX_UID                0xFFFFFFFF
11266 +#define MAX_GID                0xFFFFFFFF
11267 +
11268 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11269 +       ((cond) ? (tag) : 0)
11270 +
11271 +#define TAGINO_UID(cond, uid, tag)     (uid)
11272 +#define TAGINO_GID(cond, gid, tag)     (gid)
11273 +
11274 +#endif
11275 +
11276 +
11277 +#ifndef CONFIG_TAGGING_NONE
11278 +#define dx_current_fstag(sb)   \
11279 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
11280 +#else
11281 +#define dx_current_fstag(sb)   (0)
11282 +#endif
11283 +
11284 +#ifndef CONFIG_TAGGING_INTERN
11285 +#define TAGINO_TAG(cond, tag)  (0)
11286 +#else
11287 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
11288 +#endif
11289 +
11290 +#define TAGINO_KUID(cond, kuid, ktag)  \
11291 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
11292 +#define TAGINO_KGID(cond, kgid, ktag)  \
11293 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
11294 +#define TAGINO_KTAG(cond, ktag)                \
11295 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
11296 +
11297 +
11298 +#define INOTAG_UID(cond, uid, gid)     \
11299 +       ((cond) ? ((uid) & MAX_UID) : (uid))
11300 +#define INOTAG_GID(cond, uid, gid)     \
11301 +       ((cond) ? ((gid) & MAX_GID) : (gid))
11302 +
11303 +#define INOTAG_KUID(cond, kuid, kgid)  \
11304 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11305 +#define INOTAG_KGID(cond, kuid, kgid)  \
11306 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11307 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
11308 +       KTAGT_INIT(INOTAG_TAG(cond, \
11309 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
11310 +
11311 +
11312 +static inline uid_t dx_map_uid(uid_t uid)
11313 +{
11314 +       if ((uid > MAX_UID) && (uid != -1))
11315 +               uid = -2;
11316 +       return (uid & MAX_UID);
11317 +}
11318 +
11319 +static inline gid_t dx_map_gid(gid_t gid)
11320 +{
11321 +       if ((gid > MAX_GID) && (gid != -1))
11322 +               gid = -2;
11323 +       return (gid & MAX_GID);
11324 +}
11325 +
11326 +struct peer_tag {
11327 +       int32_t xid;
11328 +       int32_t nid;
11329 +};
11330 +
11331 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
11332 +
11333 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
11334 +                unsigned long *flags);
11335 +
11336 +#ifdef CONFIG_PROPAGATE
11337 +
11338 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
11339 +
11340 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
11341 +
11342 +#else
11343 +#define dx_propagate_tag(n, i) do { } while (0)
11344 +#endif
11345 +
11346 +#endif /* _DX_TAG_H */
11347 diff -NurpP --minimal linux-4.4.115/include/linux/vserver/tag_cmd.h linux-4.4.115-vs2.3.9.7/include/linux/vserver/tag_cmd.h
11348 --- linux-4.4.115/include/linux/vserver/tag_cmd.h       1970-01-01 00:00:00.000000000 +0000
11349 +++ linux-4.4.115-vs2.3.9.7/include/linux/vserver/tag_cmd.h     2018-01-09 16:36:32.000000000 +0000
11350 @@ -0,0 +1,10 @@
11351 +#ifndef _VSERVER_TAG_CMD_H
11352 +#define _VSERVER_TAG_CMD_H
11353 +
11354 +#include <uapi/vserver/tag_cmd.h>
11355 +
11356 +extern int vc_task_tag(uint32_t);
11357 +
11358 +extern int vc_tag_migrate(uint32_t);
11359 +
11360 +#endif /* _VSERVER_TAG_CMD_H */
11361 diff -NurpP --minimal linux-4.4.115/include/net/addrconf.h linux-4.4.115-vs2.3.9.7/include/net/addrconf.h
11362 --- linux-4.4.115/include/net/addrconf.h        2018-02-10 14:38:55.000000000 +0000
11363 +++ linux-4.4.115-vs2.3.9.7/include/net/addrconf.h      2018-01-09 16:36:32.000000000 +0000
11364 @@ -84,7 +84,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
11365  
11366  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dev,
11367                        const struct in6_addr *daddr, unsigned int srcprefs,
11368 -                      struct in6_addr *saddr);
11369 +                      struct in6_addr *saddr, struct nx_info *nxi);
11370  int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
11371                       u32 banned_flags);
11372  int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
11373 diff -NurpP --minimal linux-4.4.115/include/net/af_unix.h linux-4.4.115-vs2.3.9.7/include/net/af_unix.h
11374 --- linux-4.4.115/include/net/af_unix.h 2018-02-10 14:38:55.000000000 +0000
11375 +++ linux-4.4.115-vs2.3.9.7/include/net/af_unix.h       2018-01-09 16:36:32.000000000 +0000
11376 @@ -4,6 +4,7 @@
11377  #include <linux/socket.h>
11378  #include <linux/un.h>
11379  #include <linux/mutex.h>
11380 +// #include <linux/vs_base.h>
11381  #include <net/sock.h>
11382  
11383  void unix_inflight(struct user_struct *user, struct file *fp);
11384 diff -NurpP --minimal linux-4.4.115/include/net/inet_timewait_sock.h linux-4.4.115-vs2.3.9.7/include/net/inet_timewait_sock.h
11385 --- linux-4.4.115/include/net/inet_timewait_sock.h      2016-07-05 04:15:11.000000000 +0000
11386 +++ linux-4.4.115-vs2.3.9.7/include/net/inet_timewait_sock.h    2018-01-09 16:40:17.000000000 +0000
11387 @@ -71,6 +71,10 @@ struct inet_timewait_sock {
11388  #define tw_num                 __tw_common.skc_num
11389  #define tw_cookie              __tw_common.skc_cookie
11390  #define tw_dr                  __tw_common.skc_tw_dr
11391 +#define tw_xid                 __tw_common.skc_xid
11392 +#define tw_vx_info             __tw_common.skc_vx_info
11393 +#define tw_nid                 __tw_common.skc_nid
11394 +#define tw_nx_info             __tw_common.skc_nx_info
11395  
11396         int                     tw_timeout;
11397         volatile unsigned char  tw_substate;
11398 diff -NurpP --minimal linux-4.4.115/include/net/ip6_route.h linux-4.4.115-vs2.3.9.7/include/net/ip6_route.h
11399 --- linux-4.4.115/include/net/ip6_route.h       2018-02-10 14:38:55.000000000 +0000
11400 +++ linux-4.4.115-vs2.3.9.7/include/net/ip6_route.h     2018-01-09 16:36:32.000000000 +0000
11401 @@ -90,7 +90,7 @@ int ip6_del_rt(struct rt6_info *);
11402  
11403  int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
11404                         const struct in6_addr *daddr, unsigned int prefs,
11405 -                       struct in6_addr *saddr);
11406 +                       struct in6_addr *saddr, struct nx_info *nxi);
11407  
11408  struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
11409                             const struct in6_addr *saddr, int oif, int flags);
11410 diff -NurpP --minimal linux-4.4.115/include/net/route.h linux-4.4.115-vs2.3.9.7/include/net/route.h
11411 --- linux-4.4.115/include/net/route.h   2016-07-05 04:15:11.000000000 +0000
11412 +++ linux-4.4.115-vs2.3.9.7/include/net/route.h 2018-01-09 16:39:47.000000000 +0000
11413 @@ -223,6 +223,9 @@ static inline void ip_rt_put(struct rtab
11414         dst_release(&rt->dst);
11415  }
11416  
11417 +#include <linux/vs_base.h>
11418 +#include <linux/vs_inet.h>
11419 +
11420  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
11421  
11422  extern const __u8 ip_tos2prio[16];
11423 @@ -270,6 +273,9 @@ static inline void ip_route_connect_init
11424                            protocol, flow_flags, dst, src, dport, sport);
11425  }
11426  
11427 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
11428 +       struct flowi4 *);
11429 +
11430  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
11431                                               __be32 dst, __be32 src, u32 tos,
11432                                               int oif, u8 protocol,
11433 @@ -278,6 +284,7 @@ static inline struct rtable *ip_route_co
11434  {
11435         struct net *net = sock_net(sk);
11436         struct rtable *rt;
11437 +       struct nx_info *nx_info = current_nx_info();
11438  
11439         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
11440                               sport, dport, sk);
11441 @@ -291,7 +298,21 @@ static inline struct rtable *ip_route_co
11442  
11443                 src = fl4->saddr;
11444         }
11445 -       if (!dst || !src) {
11446 +
11447 +       if (sk)
11448 +               nx_info = sk->sk_nx_info;
11449 +
11450 +       vxdprintk(VXD_CBIT(net, 4),
11451 +               "ip_route_connect(%p) %p,%p;%lx",
11452 +               sk, nx_info, sk->sk_socket,
11453 +               (sk->sk_socket?sk->sk_socket->flags:0));
11454 +
11455 +       rt = ip_v4_find_src(net, nx_info, fl4);
11456 +       if (IS_ERR(rt))
11457 +               return rt;
11458 +       ip_rt_put(rt);
11459 +
11460 +       if (!fl4->daddr || !fl4->saddr) {
11461                 rt = __ip_route_output_key(net, fl4);
11462                 if (IS_ERR(rt))
11463                         return rt;
11464 diff -NurpP --minimal linux-4.4.115/include/net/sock.h linux-4.4.115-vs2.3.9.7/include/net/sock.h
11465 --- linux-4.4.115/include/net/sock.h    2018-02-10 14:38:56.000000000 +0000
11466 +++ linux-4.4.115-vs2.3.9.7/include/net/sock.h  2018-01-09 16:41:40.000000000 +0000
11467 @@ -201,6 +201,10 @@ struct sock_common {
11468         struct in6_addr         skc_v6_daddr;
11469         struct in6_addr         skc_v6_rcv_saddr;
11470  #endif
11471 +       vxid_t                  skc_xid;
11472 +       struct vx_info          *skc_vx_info;
11473 +       vnid_t                  skc_nid;
11474 +       struct nx_info          *skc_nx_info;
11475  
11476         atomic64_t              skc_cookie;
11477  
11478 @@ -349,8 +353,12 @@ struct sock {
11479  #define sk_prot                        __sk_common.skc_prot
11480  #define sk_net                 __sk_common.skc_net
11481  #define sk_v6_daddr            __sk_common.skc_v6_daddr
11482 -#define sk_v6_rcv_saddr        __sk_common.skc_v6_rcv_saddr
11483 +#define sk_v6_rcv_saddr                __sk_common.skc_v6_rcv_saddr
11484  #define sk_cookie              __sk_common.skc_cookie
11485 +#define sk_xid                 __sk_common.skc_xid
11486 +#define sk_vx_info             __sk_common.skc_vx_info
11487 +#define sk_nid                 __sk_common.skc_nid
11488 +#define sk_nx_info             __sk_common.skc_nx_info
11489  #define sk_incoming_cpu                __sk_common.skc_incoming_cpu
11490  #define sk_flags               __sk_common.skc_flags
11491  #define sk_rxhash              __sk_common.skc_rxhash
11492 diff -NurpP --minimal linux-4.4.115/include/uapi/Kbuild linux-4.4.115-vs2.3.9.7/include/uapi/Kbuild
11493 --- linux-4.4.115/include/uapi/Kbuild   2015-04-12 22:12:50.000000000 +0000
11494 +++ linux-4.4.115-vs2.3.9.7/include/uapi/Kbuild 2018-01-09 16:36:32.000000000 +0000
11495 @@ -13,3 +13,4 @@ header-y += drm/
11496  header-y += xen/
11497  header-y += scsi/
11498  header-y += misc/
11499 +header-y += vserver/
11500 diff -NurpP --minimal linux-4.4.115/include/uapi/linux/capability.h linux-4.4.115-vs2.3.9.7/include/uapi/linux/capability.h
11501 --- linux-4.4.115/include/uapi/linux/capability.h       2015-04-12 22:12:50.000000000 +0000
11502 +++ linux-4.4.115-vs2.3.9.7/include/uapi/linux/capability.h     2018-01-09 16:36:32.000000000 +0000
11503 @@ -259,6 +259,7 @@ struct vfs_cap_data {
11504     arbitrary SCSI commands */
11505  /* Allow setting encryption key on loopback filesystem */
11506  /* Allow setting zone reclaim policy */
11507 +/* Allow the selection of a security context */
11508  
11509  #define CAP_SYS_ADMIN        21
11510  
11511 @@ -354,7 +355,12 @@ struct vfs_cap_data {
11512  
11513  #define CAP_LAST_CAP         CAP_AUDIT_READ
11514  
11515 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
11516 +/* Allow context manipulations */
11517 +/* Allow changing context info on files */
11518 +
11519 +#define CAP_CONTEXT         63
11520 +
11521 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
11522  
11523  /*
11524   * Bit location of each capability (used by user-space library and kernel)
11525 diff -NurpP --minimal linux-4.4.115/include/uapi/linux/fs.h linux-4.4.115-vs2.3.9.7/include/uapi/linux/fs.h
11526 --- linux-4.4.115/include/uapi/linux/fs.h       2016-07-05 04:15:11.000000000 +0000
11527 +++ linux-4.4.115-vs2.3.9.7/include/uapi/linux/fs.h     2018-01-09 16:47:48.000000000 +0000
11528 @@ -91,6 +91,9 @@ struct inodes_stat_t {
11529  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
11530  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
11531  #define MS_LAZYTIME    (1<<25) /* Update the on-disk [acm]times lazily */
11532 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
11533 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
11534 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
11535  
11536  /* These sb flags are internal to the kernel */
11537  #define MS_NOSEC       (1<<28)
11538 @@ -197,12 +200,15 @@ struct inodes_stat_t {
11539  #define FS_EXTENT_FL                   0x00080000 /* Extents */
11540  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
11541  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
11542 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
11543  #define FS_PROJINHERIT_FL              0x20000000 /* Create with parents projid */
11544  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
11545  
11546 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
11547 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
11548 -
11549 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
11550 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
11551 +
11552 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
11553 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
11554  
11555  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
11556  #define SYNC_FILE_RANGE_WRITE          2
11557 diff -NurpP --minimal linux-4.4.115/include/uapi/linux/gfs2_ondisk.h linux-4.4.115-vs2.3.9.7/include/uapi/linux/gfs2_ondisk.h
11558 --- linux-4.4.115/include/uapi/linux/gfs2_ondisk.h      2015-04-12 22:12:50.000000000 +0000
11559 +++ linux-4.4.115-vs2.3.9.7/include/uapi/linux/gfs2_ondisk.h    2018-01-09 16:36:32.000000000 +0000
11560 @@ -225,6 +225,9 @@ enum {
11561         gfs2fl_Sync             = 8,
11562         gfs2fl_System           = 9,
11563         gfs2fl_TopLevel         = 10,
11564 +       gfs2fl_IXUnlink         = 16,
11565 +       gfs2fl_Barrier          = 17,
11566 +       gfs2fl_Cow              = 18,
11567         gfs2fl_TruncInProg      = 29,
11568         gfs2fl_InheritDirectio  = 30,
11569         gfs2fl_InheritJdata     = 31,
11570 @@ -242,6 +245,9 @@ enum {
11571  #define GFS2_DIF_SYNC                  0x00000100
11572  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
11573  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
11574 +#define GFS2_DIF_IXUNLINK               0x00010000
11575 +#define GFS2_DIF_BARRIER                0x00020000
11576 +#define GFS2_DIF_COW                    0x00040000
11577  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
11578  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
11579  #define GFS2_DIF_INHERIT_JDATA         0x80000000
11580 diff -NurpP --minimal linux-4.4.115/include/uapi/linux/if_tun.h linux-4.4.115-vs2.3.9.7/include/uapi/linux/if_tun.h
11581 --- linux-4.4.115/include/uapi/linux/if_tun.h   2015-10-29 09:21:42.000000000 +0000
11582 +++ linux-4.4.115-vs2.3.9.7/include/uapi/linux/if_tun.h 2018-01-09 16:46:34.000000000 +0000
11583 @@ -56,6 +56,7 @@
11584   */
11585  #define TUNSETVNETBE _IOW('T', 222, int)
11586  #define TUNGETVNETBE _IOR('T', 223, int)
11587 +#define TUNSETNID    _IOW('T', 224, int)
11588  
11589  /* TUNSETIFF ifr flags */
11590  #define IFF_TUN                0x0001
11591 diff -NurpP --minimal linux-4.4.115/include/uapi/linux/major.h linux-4.4.115-vs2.3.9.7/include/uapi/linux/major.h
11592 --- linux-4.4.115/include/uapi/linux/major.h    2015-04-12 22:12:50.000000000 +0000
11593 +++ linux-4.4.115-vs2.3.9.7/include/uapi/linux/major.h  2018-01-09 16:36:33.000000000 +0000
11594 @@ -15,6 +15,7 @@
11595  #define HD_MAJOR               IDE0_MAJOR
11596  #define PTY_SLAVE_MAJOR                3
11597  #define TTY_MAJOR              4
11598 +#define VROOT_MAJOR            4
11599  #define TTYAUX_MAJOR           5
11600  #define LP_MAJOR               6
11601  #define VCS_MAJOR              7
11602 diff -NurpP --minimal linux-4.4.115/include/uapi/linux/nfs_mount.h linux-4.4.115-vs2.3.9.7/include/uapi/linux/nfs_mount.h
11603 --- linux-4.4.115/include/uapi/linux/nfs_mount.h        2015-04-12 22:12:50.000000000 +0000
11604 +++ linux-4.4.115-vs2.3.9.7/include/uapi/linux/nfs_mount.h      2018-01-09 16:36:33.000000000 +0000
11605 @@ -63,7 +63,8 @@ struct nfs_mount_data {
11606  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 non-text parsed mount data only */
11607  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
11608  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
11609 -#define NFS_MOUNT_FLAGMASK     0xFFFF
11610 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
11611 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
11612  
11613  /* The following are for internal use only */
11614  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
11615 diff -NurpP --minimal linux-4.4.115/include/uapi/linux/reboot.h linux-4.4.115-vs2.3.9.7/include/uapi/linux/reboot.h
11616 --- linux-4.4.115/include/uapi/linux/reboot.h   2015-04-12 22:12:50.000000000 +0000
11617 +++ linux-4.4.115-vs2.3.9.7/include/uapi/linux/reboot.h 2018-01-09 16:36:33.000000000 +0000
11618 @@ -33,7 +33,7 @@
11619  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
11620  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
11621  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
11622 -
11623 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
11624  
11625  
11626  #endif /* _UAPI_LINUX_REBOOT_H */
11627 diff -NurpP --minimal linux-4.4.115/include/uapi/linux/sysctl.h linux-4.4.115-vs2.3.9.7/include/uapi/linux/sysctl.h
11628 --- linux-4.4.115/include/uapi/linux/sysctl.h   2015-04-12 22:12:50.000000000 +0000
11629 +++ linux-4.4.115-vs2.3.9.7/include/uapi/linux/sysctl.h 2018-01-09 16:36:33.000000000 +0000
11630 @@ -60,6 +60,7 @@ enum
11631         CTL_ABI=9,              /* Binary emulation */
11632         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
11633         CTL_ARLAN=254,          /* arlan wireless driver */
11634 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
11635         CTL_S390DBF=5677,       /* s390 debug */
11636         CTL_SUNRPC=7249,        /* sunrpc debug */
11637         CTL_PM=9899,            /* frv power management */
11638 @@ -94,6 +95,7 @@ enum
11639  
11640         KERN_PANIC=15,          /* int: panic timeout */
11641         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11642 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11643  
11644         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11645         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11646 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/Kbuild linux-4.4.115-vs2.3.9.7/include/uapi/vserver/Kbuild
11647 --- linux-4.4.115/include/uapi/vserver/Kbuild   1970-01-01 00:00:00.000000000 +0000
11648 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/Kbuild 2018-01-09 16:36:33.000000000 +0000
11649 @@ -0,0 +1,9 @@
11650 +
11651 +header-y += context_cmd.h network_cmd.h space_cmd.h \
11652 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11653 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11654 +       debug_cmd.h device_cmd.h
11655 +
11656 +header-y += switch.h context.h network.h monitor.h \
11657 +       limit.h inode.h device.h
11658 +
11659 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/cacct_cmd.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/cacct_cmd.h
11660 --- linux-4.4.115/include/uapi/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
11661 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/cacct_cmd.h    2018-01-09 16:36:33.000000000 +0000
11662 @@ -0,0 +1,15 @@
11663 +#ifndef _UAPI_VS_CACCT_CMD_H
11664 +#define _UAPI_VS_CACCT_CMD_H
11665 +
11666 +
11667 +/* virtual host info name commands */
11668 +
11669 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11670 +
11671 +struct vcmd_sock_stat_v0 {
11672 +       uint32_t field;
11673 +       uint32_t count[3];
11674 +       uint64_t total[3];
11675 +};
11676 +
11677 +#endif /* _UAPI_VS_CACCT_CMD_H */
11678 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/context.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/context.h
11679 --- linux-4.4.115/include/uapi/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
11680 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/context.h      2018-01-09 16:36:33.000000000 +0000
11681 @@ -0,0 +1,81 @@
11682 +#ifndef _UAPI_VS_CONTEXT_H
11683 +#define _UAPI_VS_CONTEXT_H
11684 +
11685 +#include <linux/types.h>
11686 +#include <linux/capability.h>
11687 +
11688 +
11689 +/* context flags */
11690 +
11691 +#define VXF_INFO_SCHED         0x00000002
11692 +#define VXF_INFO_NPROC         0x00000004
11693 +#define VXF_INFO_PRIVATE       0x00000008
11694 +
11695 +#define VXF_INFO_INIT          0x00000010
11696 +#define VXF_INFO_HIDE          0x00000020
11697 +#define VXF_INFO_ULIMIT                0x00000040
11698 +#define VXF_INFO_NSPACE                0x00000080
11699 +
11700 +#define VXF_SCHED_HARD         0x00000100
11701 +#define VXF_SCHED_PRIO         0x00000200
11702 +#define VXF_SCHED_PAUSE                0x00000400
11703 +
11704 +#define VXF_VIRT_MEM           0x00010000
11705 +#define VXF_VIRT_UPTIME                0x00020000
11706 +#define VXF_VIRT_CPU           0x00040000
11707 +#define VXF_VIRT_LOAD          0x00080000
11708 +#define VXF_VIRT_TIME          0x00100000
11709 +
11710 +#define VXF_HIDE_MOUNT         0x01000000
11711 +/* was VXF_HIDE_NETIF          0x02000000 */
11712 +#define VXF_HIDE_VINFO         0x04000000
11713 +
11714 +#define VXF_STATE_SETUP                (1ULL << 32)
11715 +#define VXF_STATE_INIT         (1ULL << 33)
11716 +#define VXF_STATE_ADMIN                (1ULL << 34)
11717 +
11718 +#define VXF_SC_HELPER          (1ULL << 36)
11719 +#define VXF_REBOOT_KILL                (1ULL << 37)
11720 +#define VXF_PERSISTENT         (1ULL << 38)
11721 +
11722 +#define VXF_FORK_RSS           (1ULL << 48)
11723 +#define VXF_PROLIFIC           (1ULL << 49)
11724 +
11725 +#define VXF_IGNEG_NICE         (1ULL << 52)
11726 +
11727 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11728 +
11729 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11730 +
11731 +
11732 +/* context migration */
11733 +
11734 +#define VXM_SET_INIT           0x00000001
11735 +#define VXM_SET_REAPER         0x00000002
11736 +
11737 +/* context caps */
11738 +
11739 +#define VXC_SET_UTSNAME                0x00000001
11740 +#define VXC_SET_RLIMIT         0x00000002
11741 +#define VXC_FS_SECURITY                0x00000004
11742 +#define VXC_FS_TRUSTED         0x00000008
11743 +#define VXC_TIOCSTI            0x00000010
11744 +
11745 +/* was VXC_RAW_ICMP            0x00000100 */
11746 +#define VXC_SYSLOG             0x00001000
11747 +#define VXC_OOM_ADJUST         0x00002000
11748 +#define VXC_AUDIT_CONTROL      0x00004000
11749 +
11750 +#define VXC_SECURE_MOUNT       0x00010000
11751 +/* #define VXC_SECURE_REMOUNT  0x00020000 */
11752 +#define VXC_BINARY_MOUNT       0x00040000
11753 +#define VXC_DEV_MOUNT          0x00080000
11754 +
11755 +#define VXC_QUOTA_CTL          0x00100000
11756 +#define VXC_ADMIN_MAPPER       0x00200000
11757 +#define VXC_ADMIN_CLOOP                0x00400000
11758 +
11759 +#define VXC_KTHREAD            0x01000000
11760 +#define VXC_NAMESPACE          0x02000000
11761 +
11762 +#endif /* _UAPI_VS_CONTEXT_H */
11763 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/context_cmd.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/context_cmd.h
11764 --- linux-4.4.115/include/uapi/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
11765 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/context_cmd.h  2018-01-09 16:36:33.000000000 +0000
11766 @@ -0,0 +1,115 @@
11767 +#ifndef _UAPI_VS_CONTEXT_CMD_H
11768 +#define _UAPI_VS_CONTEXT_CMD_H
11769 +
11770 +
11771 +/* vinfo commands */
11772 +
11773 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11774 +
11775 +
11776 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11777 +
11778 +struct vcmd_vx_info_v0 {
11779 +       uint32_t xid;
11780 +       uint32_t initpid;
11781 +       /* more to come */
11782 +};
11783 +
11784 +
11785 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11786 +
11787 +struct vcmd_ctx_stat_v0 {
11788 +       uint32_t usecnt;
11789 +       uint32_t tasks;
11790 +       /* more to come */
11791 +};
11792 +
11793 +
11794 +/* context commands */
11795 +
11796 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11797 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11798 +
11799 +struct vcmd_ctx_create {
11800 +       uint64_t flagword;
11801 +};
11802 +
11803 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11804 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11805 +
11806 +struct vcmd_ctx_migrate {
11807 +       uint64_t flagword;
11808 +};
11809 +
11810 +
11811 +
11812 +/* flag commands */
11813 +
11814 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11815 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11816 +
11817 +struct vcmd_ctx_flags_v0 {
11818 +       uint64_t flagword;
11819 +       uint64_t mask;
11820 +};
11821 +
11822 +
11823 +
11824 +/* context caps commands */
11825 +
11826 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11827 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11828 +
11829 +struct vcmd_ctx_caps_v1 {
11830 +       uint64_t ccaps;
11831 +       uint64_t cmask;
11832 +};
11833 +
11834 +
11835 +
11836 +/* bcaps commands */
11837 +
11838 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11839 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11840 +
11841 +struct vcmd_bcaps {
11842 +       uint64_t bcaps;
11843 +       uint64_t bmask;
11844 +};
11845 +
11846 +
11847 +
11848 +/* umask commands */
11849 +
11850 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11851 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11852 +
11853 +struct vcmd_umask {
11854 +       uint64_t umask;
11855 +       uint64_t mask;
11856 +};
11857 +
11858 +
11859 +
11860 +/* wmask commands */
11861 +
11862 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11863 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11864 +
11865 +struct vcmd_wmask {
11866 +       uint64_t wmask;
11867 +       uint64_t mask;
11868 +};
11869 +
11870 +
11871 +
11872 +/* OOM badness */
11873 +
11874 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11875 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11876 +
11877 +struct vcmd_badness_v0 {
11878 +       int64_t bias;
11879 +};
11880 +
11881 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
11882 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/cvirt_cmd.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/cvirt_cmd.h
11883 --- linux-4.4.115/include/uapi/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
11884 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/cvirt_cmd.h    2018-01-09 16:36:33.000000000 +0000
11885 @@ -0,0 +1,41 @@
11886 +#ifndef _UAPI_VS_CVIRT_CMD_H
11887 +#define _UAPI_VS_CVIRT_CMD_H
11888 +
11889 +
11890 +/* virtual host info name commands */
11891 +
11892 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11893 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11894 +
11895 +struct vcmd_vhi_name_v0 {
11896 +       uint32_t field;
11897 +       char name[65];
11898 +};
11899 +
11900 +
11901 +enum vhi_name_field {
11902 +       VHIN_CONTEXT = 0,
11903 +       VHIN_SYSNAME,
11904 +       VHIN_NODENAME,
11905 +       VHIN_RELEASE,
11906 +       VHIN_VERSION,
11907 +       VHIN_MACHINE,
11908 +       VHIN_DOMAINNAME,
11909 +};
11910 +
11911 +
11912 +
11913 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11914 +
11915 +struct vcmd_virt_stat_v0 {
11916 +       uint64_t offset;
11917 +       uint64_t uptime;
11918 +       uint32_t nr_threads;
11919 +       uint32_t nr_running;
11920 +       uint32_t nr_uninterruptible;
11921 +       uint32_t nr_onhold;
11922 +       uint32_t nr_forks;
11923 +       uint32_t load[3];
11924 +};
11925 +
11926 +#endif /* _UAPI_VS_CVIRT_CMD_H */
11927 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/debug_cmd.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/debug_cmd.h
11928 --- linux-4.4.115/include/uapi/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
11929 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/debug_cmd.h    2018-01-09 16:36:33.000000000 +0000
11930 @@ -0,0 +1,24 @@
11931 +#ifndef _UAPI_VS_DEBUG_CMD_H
11932 +#define _UAPI_VS_DEBUG_CMD_H
11933 +
11934 +
11935 +/* debug commands */
11936 +
11937 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11938 +
11939 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11940 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11941 +
11942 +struct  vcmd_read_history_v0 {
11943 +       uint32_t index;
11944 +       uint32_t count;
11945 +       char __user *data;
11946 +};
11947 +
11948 +struct  vcmd_read_monitor_v0 {
11949 +       uint32_t index;
11950 +       uint32_t count;
11951 +       char __user *data;
11952 +};
11953 +
11954 +#endif /* _UAPI_VS_DEBUG_CMD_H */
11955 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/device.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/device.h
11956 --- linux-4.4.115/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
11957 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/device.h       2018-01-09 16:36:33.000000000 +0000
11958 @@ -0,0 +1,12 @@
11959 +#ifndef _UAPI_VS_DEVICE_H
11960 +#define _UAPI_VS_DEVICE_H
11961 +
11962 +
11963 +#define DATTR_CREATE   0x00000001
11964 +#define DATTR_OPEN     0x00000002
11965 +
11966 +#define DATTR_REMAP    0x00000010
11967 +
11968 +#define DATTR_MASK     0x00000013
11969 +
11970 +#endif /* _UAPI_VS_DEVICE_H */
11971 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/device_cmd.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/device_cmd.h
11972 --- linux-4.4.115/include/uapi/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
11973 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/device_cmd.h   2018-01-09 16:36:33.000000000 +0000
11974 @@ -0,0 +1,16 @@
11975 +#ifndef _UAPI_VS_DEVICE_CMD_H
11976 +#define _UAPI_VS_DEVICE_CMD_H
11977 +
11978 +
11979 +/*  device vserver commands */
11980 +
11981 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11982 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11983 +
11984 +struct vcmd_set_mapping_v0 {
11985 +       const char __user *device;
11986 +       const char __user *target;
11987 +       uint32_t flags;
11988 +};
11989 +
11990 +#endif /* _UAPI_VS_DEVICE_CMD_H */
11991 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/dlimit_cmd.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/dlimit_cmd.h
11992 --- linux-4.4.115/include/uapi/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
11993 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/dlimit_cmd.h   2018-01-09 16:36:33.000000000 +0000
11994 @@ -0,0 +1,67 @@
11995 +#ifndef _UAPI_VS_DLIMIT_CMD_H
11996 +#define _UAPI_VS_DLIMIT_CMD_H
11997 +
11998 +
11999 +/*  dlimit vserver commands */
12000 +
12001 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12002 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12003 +
12004 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12005 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12006 +
12007 +struct vcmd_ctx_dlimit_base_v0 {
12008 +       const char __user *name;
12009 +       uint32_t flags;
12010 +};
12011 +
12012 +struct vcmd_ctx_dlimit_v0 {
12013 +       const char __user *name;
12014 +       uint32_t space_used;                    /* used space in kbytes */
12015 +       uint32_t space_total;                   /* maximum space in kbytes */
12016 +       uint32_t inodes_used;                   /* used inodes */
12017 +       uint32_t inodes_total;                  /* maximum inodes */
12018 +       uint32_t reserved;                      /* reserved for root in % */
12019 +       uint32_t flags;
12020 +};
12021 +
12022 +#define CDLIM_UNSET            ((uint32_t)0UL)
12023 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12024 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12025 +
12026 +#define DLIME_UNIT     0
12027 +#define DLIME_KILO     1
12028 +#define DLIME_MEGA     2
12029 +#define DLIME_GIGA     3
12030 +
12031 +#define DLIMF_SHIFT    0x10
12032 +
12033 +#define DLIMS_USED     0
12034 +#define DLIMS_TOTAL    2
12035 +
12036 +static inline
12037 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12038 +{
12039 +       int exp = (flags & DLIMF_SHIFT) ?
12040 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12041 +       return ((uint64_t)val) << (10 * exp);
12042 +}
12043 +
12044 +static inline
12045 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12046 +{
12047 +       int exp = 0;
12048 +
12049 +       if (*flags & DLIMF_SHIFT) {
12050 +               while (val > (1LL << 32) && (exp < 3)) {
12051 +                       val >>= 10;
12052 +                       exp++;
12053 +               }
12054 +               *flags &= ~(DLIME_GIGA << shift);
12055 +               *flags |= exp << shift;
12056 +       } else
12057 +               val >>= 10;
12058 +       return val;
12059 +}
12060 +
12061 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
12062 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/inode.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/inode.h
12063 --- linux-4.4.115/include/uapi/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
12064 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/inode.h        2018-01-09 16:36:33.000000000 +0000
12065 @@ -0,0 +1,23 @@
12066 +#ifndef _UAPI_VS_INODE_H
12067 +#define _UAPI_VS_INODE_H
12068 +
12069 +
12070 +#define IATTR_TAG      0x01000000
12071 +
12072 +#define IATTR_ADMIN    0x00000001
12073 +#define IATTR_WATCH    0x00000002
12074 +#define IATTR_HIDE     0x00000004
12075 +#define IATTR_FLAGS    0x00000007
12076 +
12077 +#define IATTR_BARRIER  0x00010000
12078 +#define IATTR_IXUNLINK 0x00020000
12079 +#define IATTR_IMMUTABLE 0x00040000
12080 +#define IATTR_COW      0x00080000
12081 +
12082 +
12083 +/* inode ioctls */
12084 +
12085 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12086 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12087 +
12088 +#endif /* _UAPI_VS_INODE_H */
12089 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/inode_cmd.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/inode_cmd.h
12090 --- linux-4.4.115/include/uapi/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
12091 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/inode_cmd.h    2018-01-09 16:36:33.000000000 +0000
12092 @@ -0,0 +1,26 @@
12093 +#ifndef _UAPI_VS_INODE_CMD_H
12094 +#define _UAPI_VS_INODE_CMD_H
12095 +
12096 +
12097 +/*  inode vserver commands */
12098 +
12099 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12100 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12101 +
12102 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12103 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12104 +
12105 +struct vcmd_ctx_iattr_v1 {
12106 +       const char __user *name;
12107 +       uint32_t tag;
12108 +       uint32_t flags;
12109 +       uint32_t mask;
12110 +};
12111 +
12112 +struct vcmd_ctx_fiattr_v0 {
12113 +       uint32_t tag;
12114 +       uint32_t flags;
12115 +       uint32_t mask;
12116 +};
12117 +
12118 +#endif /* _UAPI_VS_INODE_CMD_H */
12119 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/limit.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/limit.h
12120 --- linux-4.4.115/include/uapi/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
12121 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/limit.h        2018-01-09 16:36:33.000000000 +0000
12122 @@ -0,0 +1,14 @@
12123 +#ifndef _UAPI_VS_LIMIT_H
12124 +#define _UAPI_VS_LIMIT_H
12125 +
12126 +
12127 +#define VLIMIT_NSOCK   16
12128 +#define VLIMIT_OPENFD  17
12129 +#define VLIMIT_ANON    18
12130 +#define VLIMIT_SHMEM   19
12131 +#define VLIMIT_SEMARY  20
12132 +#define VLIMIT_NSEMS   21
12133 +#define VLIMIT_DENTRY  22
12134 +#define VLIMIT_MAPPED  23
12135 +
12136 +#endif /* _UAPI_VS_LIMIT_H */
12137 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/limit_cmd.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/limit_cmd.h
12138 --- linux-4.4.115/include/uapi/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
12139 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/limit_cmd.h    2018-01-09 16:36:33.000000000 +0000
12140 @@ -0,0 +1,40 @@
12141 +#ifndef _UAPI_VS_LIMIT_CMD_H
12142 +#define _UAPI_VS_LIMIT_CMD_H
12143 +
12144 +
12145 +/*  rlimit vserver commands */
12146 +
12147 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12148 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12149 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12150 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12151 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12152 +
12153 +struct vcmd_ctx_rlimit_v0 {
12154 +       uint32_t id;
12155 +       uint64_t minimum;
12156 +       uint64_t softlimit;
12157 +       uint64_t maximum;
12158 +};
12159 +
12160 +struct vcmd_ctx_rlimit_mask_v0 {
12161 +       uint32_t minimum;
12162 +       uint32_t softlimit;
12163 +       uint32_t maximum;
12164 +};
12165 +
12166 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12167 +
12168 +struct vcmd_rlimit_stat_v0 {
12169 +       uint32_t id;
12170 +       uint32_t hits;
12171 +       uint64_t value;
12172 +       uint64_t minimum;
12173 +       uint64_t maximum;
12174 +};
12175 +
12176 +#define CRLIM_UNSET            (0ULL)
12177 +#define CRLIM_INFINITY         (~0ULL)
12178 +#define CRLIM_KEEP             (~1ULL)
12179 +
12180 +#endif /* _UAPI_VS_LIMIT_CMD_H */
12181 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/monitor.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/monitor.h
12182 --- linux-4.4.115/include/uapi/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
12183 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/monitor.h      2018-01-09 16:36:33.000000000 +0000
12184 @@ -0,0 +1,96 @@
12185 +#ifndef _UAPI_VS_MONITOR_H
12186 +#define _UAPI_VS_MONITOR_H
12187 +
12188 +#include <linux/types.h>
12189 +
12190 +
12191 +enum {
12192 +       VXM_UNUSED = 0,
12193 +
12194 +       VXM_SYNC = 0x10,
12195 +
12196 +       VXM_UPDATE = 0x20,
12197 +       VXM_UPDATE_1,
12198 +       VXM_UPDATE_2,
12199 +
12200 +       VXM_RQINFO_1 = 0x24,
12201 +       VXM_RQINFO_2,
12202 +
12203 +       VXM_ACTIVATE = 0x40,
12204 +       VXM_DEACTIVATE,
12205 +       VXM_IDLE,
12206 +
12207 +       VXM_HOLD = 0x44,
12208 +       VXM_UNHOLD,
12209 +
12210 +       VXM_MIGRATE = 0x48,
12211 +       VXM_RESCHED,
12212 +
12213 +       /* all other bits are flags */
12214 +       VXM_SCHED = 0x80,
12215 +};
12216 +
12217 +struct _vxm_update_1 {
12218 +       uint32_t tokens_max;
12219 +       uint32_t fill_rate;
12220 +       uint32_t interval;
12221 +};
12222 +
12223 +struct _vxm_update_2 {
12224 +       uint32_t tokens_min;
12225 +       uint32_t fill_rate;
12226 +       uint32_t interval;
12227 +};
12228 +
12229 +struct _vxm_rqinfo_1 {
12230 +       uint16_t running;
12231 +       uint16_t onhold;
12232 +       uint16_t iowait;
12233 +       uint16_t uintr;
12234 +       uint32_t idle_tokens;
12235 +};
12236 +
12237 +struct _vxm_rqinfo_2 {
12238 +       uint32_t norm_time;
12239 +       uint32_t idle_time;
12240 +       uint32_t idle_skip;
12241 +};
12242 +
12243 +struct _vxm_sched {
12244 +       uint32_t tokens;
12245 +       uint32_t norm_time;
12246 +       uint32_t idle_time;
12247 +};
12248 +
12249 +struct _vxm_task {
12250 +       uint16_t pid;
12251 +       uint16_t state;
12252 +};
12253 +
12254 +struct _vxm_event {
12255 +       uint32_t jif;
12256 +       union {
12257 +               uint32_t seq;
12258 +               uint32_t sec;
12259 +       };
12260 +       union {
12261 +               uint32_t tokens;
12262 +               uint32_t nsec;
12263 +               struct _vxm_task tsk;
12264 +       };
12265 +};
12266 +
12267 +struct _vx_mon_entry {
12268 +       uint16_t type;
12269 +       uint16_t xid;
12270 +       union {
12271 +               struct _vxm_event ev;
12272 +               struct _vxm_sched sd;
12273 +               struct _vxm_update_1 u1;
12274 +               struct _vxm_update_2 u2;
12275 +               struct _vxm_rqinfo_1 q1;
12276 +               struct _vxm_rqinfo_2 q2;
12277 +       };
12278 +};
12279 +
12280 +#endif /* _UAPI_VS_MONITOR_H */
12281 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/network.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/network.h
12282 --- linux-4.4.115/include/uapi/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
12283 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/network.h      2018-01-09 16:36:33.000000000 +0000
12284 @@ -0,0 +1,76 @@
12285 +#ifndef _UAPI_VS_NETWORK_H
12286 +#define _UAPI_VS_NETWORK_H
12287 +
12288 +#include <linux/types.h>
12289 +
12290 +
12291 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12292 +
12293 +
12294 +/* network flags */
12295 +
12296 +#define NXF_INFO_PRIVATE       0x00000008
12297 +
12298 +#define NXF_SINGLE_IP          0x00000100
12299 +#define NXF_LBACK_REMAP                0x00000200
12300 +#define NXF_LBACK_ALLOW                0x00000400
12301 +
12302 +#define NXF_HIDE_NETIF         0x02000000
12303 +#define NXF_HIDE_LBACK         0x04000000
12304 +
12305 +#define NXF_STATE_SETUP                (1ULL << 32)
12306 +#define NXF_STATE_ADMIN                (1ULL << 34)
12307 +
12308 +#define NXF_SC_HELPER          (1ULL << 36)
12309 +#define NXF_PERSISTENT         (1ULL << 38)
12310 +
12311 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12312 +
12313 +
12314 +#define        NXF_INIT_SET            (__nxf_init_set())
12315 +
12316 +static inline uint64_t __nxf_init_set(void) {
12317 +       return    NXF_STATE_ADMIN
12318 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12319 +               | NXF_LBACK_REMAP
12320 +               | NXF_HIDE_LBACK
12321 +#endif
12322 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12323 +               | NXF_SINGLE_IP
12324 +#endif
12325 +               | NXF_HIDE_NETIF;
12326 +}
12327 +
12328 +
12329 +/* network caps */
12330 +
12331 +#define NXC_TUN_CREATE         0x00000001
12332 +
12333 +#define NXC_RAW_ICMP           0x00000100
12334 +
12335 +#define NXC_MULTICAST          0x00001000
12336 +
12337 +
12338 +/* address types */
12339 +
12340 +#define NXA_TYPE_IPV4          0x0001
12341 +#define NXA_TYPE_IPV6          0x0002
12342 +
12343 +#define NXA_TYPE_NONE          0x0000
12344 +#define NXA_TYPE_ANY           0x00FF
12345 +
12346 +#define NXA_TYPE_ADDR          0x0010
12347 +#define NXA_TYPE_MASK          0x0020
12348 +#define NXA_TYPE_RANGE         0x0040
12349 +
12350 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12351 +
12352 +#define NXA_MOD_BCAST          0x0100
12353 +#define NXA_MOD_LBACK          0x0200
12354 +
12355 +#define NXA_LOOPBACK           0x1000
12356 +
12357 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12358 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12359 +
12360 +#endif /* _UAPI_VS_NETWORK_H */
12361 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/network_cmd.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/network_cmd.h
12362 --- linux-4.4.115/include/uapi/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
12363 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/network_cmd.h  2018-01-09 16:36:33.000000000 +0000
12364 @@ -0,0 +1,123 @@
12365 +#ifndef _UAPI_VS_NETWORK_CMD_H
12366 +#define _UAPI_VS_NETWORK_CMD_H
12367 +
12368 +
12369 +/* vinfo commands */
12370 +
12371 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12372 +
12373 +
12374 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12375 +
12376 +struct vcmd_nx_info_v0 {
12377 +       uint32_t nid;
12378 +       /* more to come */
12379 +};
12380 +
12381 +
12382 +#include <linux/in.h>
12383 +#include <linux/in6.h>
12384 +
12385 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12386 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12387 +
12388 +struct  vcmd_net_create {
12389 +       uint64_t flagword;
12390 +};
12391 +
12392 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12393 +
12394 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12395 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12396 +
12397 +struct vcmd_net_addr_v0 {
12398 +       uint16_t type;
12399 +       uint16_t count;
12400 +       struct in_addr ip[4];
12401 +       struct in_addr mask[4];
12402 +};
12403 +
12404 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
12405 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
12406 +
12407 +struct vcmd_net_addr_ipv4_v1 {
12408 +       uint16_t type;
12409 +       uint16_t flags;
12410 +       struct in_addr ip;
12411 +       struct in_addr mask;
12412 +};
12413 +
12414 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
12415 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
12416 +
12417 +struct vcmd_net_addr_ipv4_v2 {
12418 +       uint16_t type;
12419 +       uint16_t flags;
12420 +       struct in_addr ip;
12421 +       struct in_addr ip2;
12422 +       struct in_addr mask;
12423 +};
12424 +
12425 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12426 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12427 +
12428 +struct vcmd_net_addr_ipv6_v1 {
12429 +       uint16_t type;
12430 +       uint16_t flags;
12431 +       uint32_t prefix;
12432 +       struct in6_addr ip;
12433 +       struct in6_addr mask;
12434 +};
12435 +
12436 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12437 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12438 +
12439 +struct vcmd_match_ipv4_v0 {
12440 +       uint16_t type;
12441 +       uint16_t flags;
12442 +       uint16_t parent;
12443 +       uint16_t prefix;
12444 +       struct in_addr ip;
12445 +       struct in_addr ip2;
12446 +       struct in_addr mask;
12447 +};
12448 +
12449 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12450 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12451 +
12452 +struct vcmd_match_ipv6_v0 {
12453 +       uint16_t type;
12454 +       uint16_t flags;
12455 +       uint16_t parent;
12456 +       uint16_t prefix;
12457 +       struct in6_addr ip;
12458 +       struct in6_addr ip2;
12459 +       struct in6_addr mask;
12460 +};
12461 +
12462 +
12463 +
12464 +
12465 +/* flag commands */
12466 +
12467 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12468 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12469 +
12470 +struct vcmd_net_flags_v0 {
12471 +       uint64_t flagword;
12472 +       uint64_t mask;
12473 +};
12474 +
12475 +
12476 +
12477 +/* network caps commands */
12478 +
12479 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12480 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12481 +
12482 +struct vcmd_net_caps_v0 {
12483 +       uint64_t ncaps;
12484 +       uint64_t cmask;
12485 +};
12486 +
12487 +#endif /* _UAPI_VS_NETWORK_CMD_H */
12488 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/sched_cmd.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/sched_cmd.h
12489 --- linux-4.4.115/include/uapi/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
12490 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/sched_cmd.h    2018-01-09 16:36:33.000000000 +0000
12491 @@ -0,0 +1,13 @@
12492 +#ifndef _UAPI_VS_SCHED_CMD_H
12493 +#define _UAPI_VS_SCHED_CMD_H
12494 +
12495 +
12496 +struct vcmd_prio_bias {
12497 +       int32_t cpu_id;
12498 +       int32_t prio_bias;
12499 +};
12500 +
12501 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
12502 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
12503 +
12504 +#endif /* _UAPI_VS_SCHED_CMD_H */
12505 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/signal_cmd.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/signal_cmd.h
12506 --- linux-4.4.115/include/uapi/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
12507 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/signal_cmd.h   2018-01-09 16:36:33.000000000 +0000
12508 @@ -0,0 +1,31 @@
12509 +#ifndef _UAPI_VS_SIGNAL_CMD_H
12510 +#define _UAPI_VS_SIGNAL_CMD_H
12511 +
12512 +
12513 +/*  signalling vserver commands */
12514 +
12515 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12516 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12517 +
12518 +struct vcmd_ctx_kill_v0 {
12519 +       int32_t pid;
12520 +       int32_t sig;
12521 +};
12522 +
12523 +struct vcmd_wait_exit_v0 {
12524 +       int32_t reboot_cmd;
12525 +       int32_t exit_code;
12526 +};
12527 +
12528 +
12529 +/*  process alteration commands */
12530 +
12531 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12532 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12533 +
12534 +struct vcmd_pflags_v0 {
12535 +       uint32_t flagword;
12536 +       uint32_t mask;
12537 +};
12538 +
12539 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
12540 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/space_cmd.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/space_cmd.h
12541 --- linux-4.4.115/include/uapi/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
12542 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/space_cmd.h    2018-01-09 16:36:33.000000000 +0000
12543 @@ -0,0 +1,28 @@
12544 +#ifndef _UAPI_VS_SPACE_CMD_H
12545 +#define _UAPI_VS_SPACE_CMD_H
12546 +
12547 +
12548 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12549 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12550 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12551 +
12552 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12553 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12554 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12555 +
12556 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12557 +
12558 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12559 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12560 +
12561 +
12562 +struct vcmd_space_mask_v1 {
12563 +       uint64_t mask;
12564 +};
12565 +
12566 +struct vcmd_space_mask_v2 {
12567 +       uint64_t mask;
12568 +       uint32_t index;
12569 +};
12570 +
12571 +#endif /* _UAPI_VS_SPACE_CMD_H */
12572 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/switch.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/switch.h
12573 --- linux-4.4.115/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12574 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/switch.h       2018-01-09 16:36:33.000000000 +0000
12575 @@ -0,0 +1,90 @@
12576 +#ifndef _UAPI_VS_SWITCH_H
12577 +#define _UAPI_VS_SWITCH_H
12578 +
12579 +#include <linux/types.h>
12580 +
12581 +
12582 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12583 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12584 +#define VC_VERSION(c)          ((c) & 0xFFF)
12585 +
12586 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12587 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12588 +
12589 +/*
12590 +
12591 +  Syscall Matrix V2.8
12592 +
12593 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12594 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12595 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12596 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12597 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
12598 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
12599 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12600 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
12601 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
12602 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12603 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
12604 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
12605 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12606 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
12607 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
12608 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12609 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
12610 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
12611 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12612 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
12613 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
12614 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12615 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
12616 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
12617 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12618 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
12619 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
12620 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12621 +
12622 +*/
12623 +
12624 +#define VC_CAT_VERSION         0
12625 +
12626 +#define VC_CAT_VSETUP          1
12627 +#define VC_CAT_VHOST           2
12628 +
12629 +#define VC_CAT_DEVICE          6
12630 +
12631 +#define VC_CAT_VPROC           9
12632 +#define VC_CAT_PROCALT         10
12633 +#define VC_CAT_PROCMIG         11
12634 +#define VC_CAT_PROCTRL         12
12635 +
12636 +#define VC_CAT_SCHED           14
12637 +#define VC_CAT_MEMCTRL         20
12638 +
12639 +#define VC_CAT_VNET            25
12640 +#define VC_CAT_NETALT          26
12641 +#define VC_CAT_NETMIG          27
12642 +#define VC_CAT_NETCTRL         28
12643 +
12644 +#define VC_CAT_TAGMIG          35
12645 +#define VC_CAT_DLIMIT          36
12646 +#define VC_CAT_INODE           38
12647 +
12648 +#define VC_CAT_VSTAT           40
12649 +#define VC_CAT_VINFO           46
12650 +#define VC_CAT_EVENT           48
12651 +
12652 +#define VC_CAT_FLAGS           52
12653 +#define VC_CAT_VSPACE          54
12654 +#define VC_CAT_DEBUG           56
12655 +#define VC_CAT_RLIMIT          60
12656 +
12657 +#define VC_CAT_SYSTEST         61
12658 +#define VC_CAT_COMPAT          63
12659 +
12660 +/*  query version */
12661 +
12662 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
12663 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
12664 +
12665 +#endif /* _UAPI_VS_SWITCH_H */
12666 diff -NurpP --minimal linux-4.4.115/include/uapi/vserver/tag_cmd.h linux-4.4.115-vs2.3.9.7/include/uapi/vserver/tag_cmd.h
12667 --- linux-4.4.115/include/uapi/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
12668 +++ linux-4.4.115-vs2.3.9.7/include/uapi/vserver/tag_cmd.h      2018-01-09 16:36:33.000000000 +0000
12669 @@ -0,0 +1,14 @@
12670 +#ifndef _UAPI_VS_TAG_CMD_H
12671 +#define _UAPI_VS_TAG_CMD_H
12672 +
12673 +
12674 +/* vinfo commands */
12675 +
12676 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
12677 +
12678 +
12679 +/* context commands */
12680 +
12681 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
12682 +
12683 +#endif /* _UAPI_VS_TAG_CMD_H */
12684 diff -NurpP --minimal linux-4.4.115/init/Kconfig linux-4.4.115-vs2.3.9.7/init/Kconfig
12685 --- linux-4.4.115/init/Kconfig  2018-02-10 14:38:56.000000000 +0000
12686 +++ linux-4.4.115-vs2.3.9.7/init/Kconfig        2018-02-10 15:16:50.000000000 +0000
12687 @@ -927,6 +927,7 @@ config NUMA_BALANCING_DEFAULT_ENABLED
12688  menuconfig CGROUPS
12689         bool "Control Group support"
12690         select KERNFS
12691 +       default y
12692         help
12693           This option adds support for grouping sets of processes together, for
12694           use with process control subsystems such as Cpusets, CFS, memory
12695 diff -NurpP --minimal linux-4.4.115/init/main.c linux-4.4.115-vs2.3.9.7/init/main.c
12696 --- linux-4.4.115/init/main.c   2018-02-10 14:38:56.000000000 +0000
12697 +++ linux-4.4.115-vs2.3.9.7/init/main.c 2018-01-09 16:58:21.000000000 +0000
12698 @@ -82,6 +82,7 @@
12699  #include <linux/proc_ns.h>
12700  #include <linux/io.h>
12701  #include <linux/kaiser.h>
12702 +#include <linux/vserver/percpu.h>
12703  
12704  #include <asm/io.h>
12705  #include <asm/bugs.h>
12706 diff -NurpP --minimal linux-4.4.115/ipc/mqueue.c linux-4.4.115-vs2.3.9.7/ipc/mqueue.c
12707 --- linux-4.4.115/ipc/mqueue.c  2018-02-10 14:38:56.000000000 +0000
12708 +++ linux-4.4.115-vs2.3.9.7/ipc/mqueue.c        2018-01-09 16:36:33.000000000 +0000
12709 @@ -35,6 +35,8 @@
12710  #include <linux/ipc_namespace.h>
12711  #include <linux/user_namespace.h>
12712  #include <linux/slab.h>
12713 +#include <linux/vs_context.h>
12714 +#include <linux/vs_limit.h>
12715  
12716  #include <net/sock.h>
12717  #include "util.h"
12718 @@ -75,6 +77,7 @@ struct mqueue_inode_info {
12719         struct pid *notify_owner;
12720         struct user_namespace *notify_user_ns;
12721         struct user_struct *user;       /* user who created, for accounting */
12722 +       struct vx_info *vxi;
12723         struct sock *notify_sock;
12724         struct sk_buff *notify_cookie;
12725  
12726 @@ -230,6 +233,7 @@ static struct inode *mqueue_get_inode(st
12727         if (S_ISREG(mode)) {
12728                 struct mqueue_inode_info *info;
12729                 unsigned long mq_bytes, mq_treesize;
12730 +               struct vx_info *vxi = current_vx_info();
12731  
12732                 inode->i_fop = &mqueue_file_operations;
12733                 inode->i_size = FILENT_SIZE;
12734 @@ -243,6 +247,7 @@ static struct inode *mqueue_get_inode(st
12735                 info->notify_user_ns = NULL;
12736                 info->qsize = 0;
12737                 info->user = NULL;      /* set when all is ok */
12738 +               info->vxi = NULL;
12739                 info->msg_tree = RB_ROOT;
12740                 info->node_cache = NULL;
12741                 memset(&info->attr, 0, sizeof(info->attr));
12742 @@ -276,17 +281,20 @@ static struct inode *mqueue_get_inode(st
12743  
12744                 spin_lock(&mq_lock);
12745                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
12746 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
12747 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
12748 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
12749                         spin_unlock(&mq_lock);
12750                         /* mqueue_evict_inode() releases info->messages */
12751                         ret = -EMFILE;
12752                         goto out_inode;
12753                 }
12754                 u->mq_bytes += mq_bytes;
12755 +               vx_ipcmsg_add(vxi, u, mq_bytes);
12756                 spin_unlock(&mq_lock);
12757  
12758                 /* all is ok */
12759                 info->user = get_uid(u);
12760 +               info->vxi = get_vx_info(vxi);
12761         } else if (S_ISDIR(mode)) {
12762                 inc_nlink(inode);
12763                 /* Some things misbehave if size == 0 on a directory */
12764 @@ -398,8 +406,11 @@ static void mqueue_evict_inode(struct in
12765  
12766         user = info->user;
12767         if (user) {
12768 +               struct vx_info *vxi = info->vxi;
12769 +
12770                 spin_lock(&mq_lock);
12771                 user->mq_bytes -= mq_bytes;
12772 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
12773                 /*
12774                  * get_ns_from_inode() ensures that the
12775                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
12776 @@ -409,6 +420,7 @@ static void mqueue_evict_inode(struct in
12777                 if (ipc_ns)
12778                         ipc_ns->mq_queues_count--;
12779                 spin_unlock(&mq_lock);
12780 +               put_vx_info(vxi);
12781                 free_uid(user);
12782         }
12783         if (ipc_ns)
12784 diff -NurpP --minimal linux-4.4.115/ipc/msg.c linux-4.4.115-vs2.3.9.7/ipc/msg.c
12785 --- linux-4.4.115/ipc/msg.c     2018-02-10 14:38:56.000000000 +0000
12786 +++ linux-4.4.115-vs2.3.9.7/ipc/msg.c   2018-02-10 15:16:50.000000000 +0000
12787 @@ -37,6 +37,7 @@
12788  #include <linux/rwsem.h>
12789  #include <linux/nsproxy.h>
12790  #include <linux/ipc_namespace.h>
12791 +#include <linux/vs_base.h>
12792  
12793  #include <asm/current.h>
12794  #include <linux/uaccess.h>
12795 @@ -129,6 +130,7 @@ static int newque(struct ipc_namespace *
12796  
12797         msq->q_perm.mode = msgflg & S_IRWXUGO;
12798         msq->q_perm.key = key;
12799 +       msq->q_perm.xid = vx_current_xid();
12800  
12801         msq->q_perm.security = NULL;
12802         retval = security_msg_queue_alloc(msq);
12803 diff -NurpP --minimal linux-4.4.115/ipc/sem.c linux-4.4.115-vs2.3.9.7/ipc/sem.c
12804 --- linux-4.4.115/ipc/sem.c     2018-02-10 14:38:56.000000000 +0000
12805 +++ linux-4.4.115-vs2.3.9.7/ipc/sem.c   2018-01-09 16:36:33.000000000 +0000
12806 @@ -85,6 +85,8 @@
12807  #include <linux/rwsem.h>
12808  #include <linux/nsproxy.h>
12809  #include <linux/ipc_namespace.h>
12810 +#include <linux/vs_base.h>
12811 +#include <linux/vs_limit.h>
12812  
12813  #include <linux/uaccess.h>
12814  #include "util.h"
12815 @@ -533,6 +535,7 @@ static int newary(struct ipc_namespace *
12816  
12817         sma->sem_perm.mode = (semflg & S_IRWXUGO);
12818         sma->sem_perm.key = key;
12819 +       sma->sem_perm.xid = vx_current_xid();
12820  
12821         sma->sem_perm.security = NULL;
12822         retval = security_sem_alloc(sma);
12823 @@ -563,6 +566,9 @@ static int newary(struct ipc_namespace *
12824                 return id;
12825         }
12826         ns->used_sems += nsems;
12827 +       /* FIXME: obsoleted? */
12828 +       vx_semary_inc(sma);
12829 +       vx_nsems_add(sma, nsems);
12830  
12831         sem_unlock(sma, -1);
12832         rcu_read_unlock();
12833 @@ -1151,6 +1157,9 @@ static void freeary(struct ipc_namespace
12834  
12835         wake_up_sem_queue_do(&tasks);
12836         ns->used_sems -= sma->sem_nsems;
12837 +       /* FIXME: obsoleted? */
12838 +       vx_nsems_sub(sma, sma->sem_nsems);
12839 +       vx_semary_dec(sma);
12840         ipc_rcu_putref(sma, sem_rcu_free);
12841  }
12842  
12843 diff -NurpP --minimal linux-4.4.115/ipc/shm.c linux-4.4.115-vs2.3.9.7/ipc/shm.c
12844 --- linux-4.4.115/ipc/shm.c     2018-02-10 14:38:56.000000000 +0000
12845 +++ linux-4.4.115-vs2.3.9.7/ipc/shm.c   2018-01-09 16:36:33.000000000 +0000
12846 @@ -42,6 +42,8 @@
12847  #include <linux/nsproxy.h>
12848  #include <linux/mount.h>
12849  #include <linux/ipc_namespace.h>
12850 +#include <linux/vs_context.h>
12851 +#include <linux/vs_limit.h>
12852  
12853  #include <linux/uaccess.h>
12854  
12855 @@ -228,10 +230,14 @@ static void shm_open(struct vm_area_stru
12856  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
12857  {
12858         struct file *shm_file;
12859 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
12860 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
12861  
12862         shm_file = shp->shm_file;
12863         shp->shm_file = NULL;
12864 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
12865 +       vx_ipcshm_sub(vxi, shp, numpages);
12866 +       ns->shm_tot -= numpages;
12867 +
12868         shm_rmid(ns, shp);
12869         shm_unlock(shp);
12870         if (!is_file_hugepages(shm_file))
12871 @@ -240,6 +246,7 @@ static void shm_destroy(struct ipc_names
12872                 user_shm_unlock(i_size_read(file_inode(shm_file)),
12873                                 shp->mlock_user);
12874         fput(shm_file);
12875 +       put_vx_info(vxi);
12876         ipc_rcu_putref(shp, shm_rcu_free);
12877  }
12878  
12879 @@ -537,11 +544,15 @@ static int newseg(struct ipc_namespace *
12880                         ns->shm_tot + numpages > ns->shm_ctlall)
12881                 return -ENOSPC;
12882  
12883 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
12884 +               return -ENOSPC;
12885 +
12886         shp = ipc_rcu_alloc(sizeof(*shp));
12887         if (!shp)
12888                 return -ENOMEM;
12889  
12890         shp->shm_perm.key = key;
12891 +       shp->shm_perm.xid = vx_current_xid();
12892         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
12893         shp->mlock_user = NULL;
12894  
12895 @@ -612,6 +623,7 @@ static int newseg(struct ipc_namespace *
12896  
12897         ipc_unlock_object(&shp->shm_perm);
12898         rcu_read_unlock();
12899 +       vx_ipcshm_add(current_vx_info(), key, numpages);
12900         return error;
12901  
12902  no_id:
12903 diff -NurpP --minimal linux-4.4.115/kernel/Makefile linux-4.4.115-vs2.3.9.7/kernel/Makefile
12904 --- linux-4.4.115/kernel/Makefile       2016-07-05 04:12:38.000000000 +0000
12905 +++ linux-4.4.115-vs2.3.9.7/kernel/Makefile     2018-01-09 16:36:33.000000000 +0000
12906 @@ -29,6 +29,7 @@ obj-y += printk/
12907  obj-y += irq/
12908  obj-y += rcu/
12909  obj-y += livepatch/
12910 +obj-y += vserver/
12911  
12912  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
12913  obj-$(CONFIG_FREEZER) += freezer.o
12914 diff -NurpP --minimal linux-4.4.115/kernel/auditsc.c linux-4.4.115-vs2.3.9.7/kernel/auditsc.c
12915 --- linux-4.4.115/kernel/auditsc.c      2018-02-10 14:38:56.000000000 +0000
12916 +++ linux-4.4.115-vs2.3.9.7/kernel/auditsc.c    2018-01-09 16:36:33.000000000 +0000
12917 @@ -1962,7 +1962,7 @@ static int audit_set_loginuid_perm(kuid_
12918         if (is_audit_feature_set(AUDIT_FEATURE_LOGINUID_IMMUTABLE))
12919                 return -EPERM;
12920         /* it is set, you need permission */
12921 -       if (!capable(CAP_AUDIT_CONTROL))
12922 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
12923                 return -EPERM;
12924         /* reject if this is not an unset and we don't allow that */
12925         if (is_audit_feature_set(AUDIT_FEATURE_ONLY_UNSET_LOGINUID) && uid_valid(loginuid))
12926 diff -NurpP --minimal linux-4.4.115/kernel/capability.c linux-4.4.115-vs2.3.9.7/kernel/capability.c
12927 --- linux-4.4.115/kernel/capability.c   2018-02-10 14:38:56.000000000 +0000
12928 +++ linux-4.4.115-vs2.3.9.7/kernel/capability.c 2018-01-09 16:36:33.000000000 +0000
12929 @@ -17,6 +17,7 @@
12930  #include <linux/syscalls.h>
12931  #include <linux/pid_namespace.h>
12932  #include <linux/user_namespace.h>
12933 +#include <linux/vs_context.h>
12934  #include <asm/uaccess.h>
12935  
12936  /*
12937 @@ -107,6 +108,7 @@ static int cap_validate_magic(cap_user_h
12938         return 0;
12939  }
12940  
12941 +
12942  /*
12943   * The only thing that can change the capabilities of the current
12944   * process is the current process. As such, we can't be in this code
12945 @@ -344,6 +346,8 @@ bool has_ns_capability_noaudit(struct ta
12946         return (ret == 0);
12947  }
12948  
12949 +#include <linux/vserver/base.h>
12950 +
12951  /**
12952   * has_capability_noaudit - Does a task have a capability (unaudited) in the
12953   * initial user ns
12954 diff -NurpP --minimal linux-4.4.115/kernel/compat.c linux-4.4.115-vs2.3.9.7/kernel/compat.c
12955 --- linux-4.4.115/kernel/compat.c       2015-07-06 20:41:43.000000000 +0000
12956 +++ linux-4.4.115-vs2.3.9.7/kernel/compat.c     2018-01-09 16:36:33.000000000 +0000
12957 @@ -27,6 +27,7 @@
12958  #include <linux/times.h>
12959  #include <linux/ptrace.h>
12960  #include <linux/gfp.h>
12961 +#include <linux/vs_time.h>
12962  
12963  #include <asm/uaccess.h>
12964  
12965 @@ -1059,7 +1060,7 @@ COMPAT_SYSCALL_DEFINE1(stime, compat_tim
12966         if (err)
12967                 return err;
12968  
12969 -       do_settimeofday(&tv);
12970 +       vx_settimeofday(&tv);
12971         return 0;
12972  }
12973  
12974 diff -NurpP --minimal linux-4.4.115/kernel/cred.c linux-4.4.115-vs2.3.9.7/kernel/cred.c
12975 --- linux-4.4.115/kernel/cred.c 2018-02-10 14:38:56.000000000 +0000
12976 +++ linux-4.4.115-vs2.3.9.7/kernel/cred.c       2018-01-09 16:36:33.000000000 +0000
12977 @@ -64,31 +64,6 @@ struct cred init_cred = {
12978         .group_info             = &init_groups,
12979  };
12980  
12981 -static inline void set_cred_subscribers(struct cred *cred, int n)
12982 -{
12983 -#ifdef CONFIG_DEBUG_CREDENTIALS
12984 -       atomic_set(&cred->subscribers, n);
12985 -#endif
12986 -}
12987 -
12988 -static inline int read_cred_subscribers(const struct cred *cred)
12989 -{
12990 -#ifdef CONFIG_DEBUG_CREDENTIALS
12991 -       return atomic_read(&cred->subscribers);
12992 -#else
12993 -       return 0;
12994 -#endif
12995 -}
12996 -
12997 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
12998 -{
12999 -#ifdef CONFIG_DEBUG_CREDENTIALS
13000 -       struct cred *cred = (struct cred *) _cred;
13001 -
13002 -       atomic_add(n, &cred->subscribers);
13003 -#endif
13004 -}
13005 -
13006  /*
13007   * The RCU callback to actually dispose of a set of credentials
13008   */
13009 @@ -240,21 +215,16 @@ error:
13010   *
13011   * Call commit_creds() or abort_creds() to clean up.
13012   */
13013 -struct cred *prepare_creds(void)
13014 +struct cred *__prepare_creds(const struct cred *old)
13015  {
13016 -       struct task_struct *task = current;
13017 -       const struct cred *old;
13018         struct cred *new;
13019  
13020 -       validate_process_creds();
13021 -
13022         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13023         if (!new)
13024                 return NULL;
13025  
13026         kdebug("prepare_creds() alloc %p", new);
13027  
13028 -       old = task->cred;
13029         memcpy(new, old, sizeof(struct cred));
13030  
13031         atomic_set(&new->usage, 1);
13032 @@ -283,6 +253,13 @@ error:
13033         abort_creds(new);
13034         return NULL;
13035  }
13036 +
13037 +struct cred *prepare_creds(void)
13038 +{
13039 +       validate_process_creds();
13040 +
13041 +       return __prepare_creds(current->cred);
13042 +}
13043  EXPORT_SYMBOL(prepare_creds);
13044  
13045  /*
13046 diff -NurpP --minimal linux-4.4.115/kernel/exit.c linux-4.4.115-vs2.3.9.7/kernel/exit.c
13047 --- linux-4.4.115/kernel/exit.c 2018-02-10 14:38:56.000000000 +0000
13048 +++ linux-4.4.115-vs2.3.9.7/kernel/exit.c       2018-02-06 17:16:09.000000000 +0000
13049 @@ -48,6 +48,10 @@
13050  #include <linux/fs_struct.h>
13051  #include <linux/init_task.h>
13052  #include <linux/perf_event.h>
13053 +#include <linux/vs_limit.h>
13054 +#include <linux/vs_context.h>
13055 +#include <linux/vs_network.h>
13056 +#include <linux/vs_pid.h>
13057  #include <trace/events/sched.h>
13058  #include <linux/hw_breakpoint.h>
13059  #include <linux/oom.h>
13060 @@ -456,14 +460,24 @@ static struct task_struct *find_child_re
13061  {
13062         struct pid_namespace *pid_ns = task_active_pid_ns(father);
13063         struct task_struct *reaper = pid_ns->child_reaper;
13064 +       struct vx_info *vxi = task_get_vx_info(father);
13065 +
13066 +       if (vxi) {
13067 +               BUG_ON(!vxi->vx_reaper);
13068 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
13069 +                   vxi->vx_reaper != father) {
13070 +                       reaper = vxi->vx_reaper;
13071 +                       goto out_put;
13072 +               }
13073 +       }
13074  
13075         if (likely(reaper != father))
13076 -               return reaper;
13077 +               goto out_put;
13078  
13079         reaper = find_alive_thread(father);
13080         if (reaper) {
13081                 pid_ns->child_reaper = reaper;
13082 -               return reaper;
13083 +               goto out_put;
13084         }
13085  
13086         write_unlock_irq(&tasklist_lock);
13087 @@ -474,7 +488,10 @@ static struct task_struct *find_child_re
13088         zap_pid_ns_processes(pid_ns);
13089         write_lock_irq(&tasklist_lock);
13090  
13091 -       return father;
13092 +       reaper = father;
13093 +out_put:
13094 +       put_vx_info(vxi);
13095 +       return reaper;
13096  }
13097  
13098  /*
13099 @@ -562,9 +579,13 @@ static void forget_original_parent(struc
13100                 return;
13101  
13102         reaper = find_new_reaper(father, reaper);
13103 -       list_for_each_entry(p, &father->children, sibling) {
13104 +       for (p = list_first_entry(&father->children, struct task_struct, sibling);
13105 +            &p->sibling != &father->children; ) {
13106 +               struct task_struct *next, *this_reaper = reaper;
13107 +               if (p == reaper)
13108 +                       this_reaper = task_active_pid_ns(reaper)->child_reaper;
13109                 for_each_thread(p, t) {
13110 -                       t->real_parent = reaper;
13111 +                       t->real_parent = this_reaper;
13112                         BUG_ON((!t->ptrace) != (t->parent == father));
13113                         if (likely(!t->ptrace))
13114                                 t->parent = t->real_parent;
13115 @@ -576,10 +597,13 @@ static void forget_original_parent(struc
13116                  * If this is a threaded reparent there is no need to
13117                  * notify anyone anything has happened.
13118                  */
13119 -               if (!same_thread_group(reaper, father))
13120 +               if (!same_thread_group(this_reaper, father))
13121                         reparent_leader(father, p, dead);
13122 +               next = list_next_entry(p, sibling);
13123 +               list_add(&p->sibling, &this_reaper->children);
13124 +               p = next;
13125         }
13126 -       list_splice_tail_init(&father->children, &reaper->children);
13127 +       INIT_LIST_HEAD(&father->children);
13128  }
13129  
13130  /*
13131 @@ -763,6 +787,9 @@ void do_exit(long code)
13132          */
13133         flush_ptrace_hw_breakpoint(tsk);
13134  
13135 +       /* needs to stay before exit_notify() */
13136 +       exit_vx_info_early(tsk, code);
13137 +
13138         TASKS_RCU(preempt_disable());
13139         TASKS_RCU(tasks_rcu_i = __srcu_read_lock(&tasks_rcu_exit_srcu));
13140         TASKS_RCU(preempt_enable());
13141 @@ -800,6 +827,10 @@ void do_exit(long code)
13142  
13143         validate_creds_for_do_exit(tsk);
13144  
13145 +       /* needs to stay after exit_notify() and before preempt_disable() */
13146 +       exit_vx_info(tsk, code);
13147 +       exit_nx_info(tsk);
13148 +
13149         check_stack_usage();
13150         preempt_disable();
13151         if (tsk->nr_dirtied)
13152 @@ -826,6 +857,7 @@ void do_exit(long code)
13153         tsk->state = TASK_DEAD;
13154         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
13155         schedule();
13156 +       printk("bad task: %p [%lx]\n", current, current->state);
13157         BUG();
13158         /* Avoid "noreturn function does return".  */
13159         for (;;)
13160 diff -NurpP --minimal linux-4.4.115/kernel/fork.c linux-4.4.115-vs2.3.9.7/kernel/fork.c
13161 --- linux-4.4.115/kernel/fork.c 2018-02-10 14:38:56.000000000 +0000
13162 +++ linux-4.4.115-vs2.3.9.7/kernel/fork.c       2018-01-09 17:00:00.000000000 +0000
13163 @@ -76,6 +76,9 @@
13164  #include <linux/aio.h>
13165  #include <linux/compiler.h>
13166  #include <linux/sysctl.h>
13167 +#include <linux/vs_context.h>
13168 +#include <linux/vs_network.h>
13169 +#include <linux/vs_limit.h>
13170  
13171  #include <asm/pgtable.h>
13172  #include <asm/pgalloc.h>
13173 @@ -227,6 +230,8 @@ void free_task(struct task_struct *tsk)
13174         arch_release_thread_info(tsk->stack);
13175         free_thread_info(tsk->stack);
13176         rt_mutex_debug_task_free(tsk);
13177 +       clr_vx_info(&tsk->vx_info);
13178 +       clr_nx_info(&tsk->nx_info);
13179         ftrace_graph_exit_task(tsk);
13180         put_seccomp_filter(tsk);
13181         arch_release_task_struct(tsk);
13182 @@ -1282,6 +1287,8 @@ static struct task_struct *copy_process(
13183  {
13184         int retval;
13185         struct task_struct *p;
13186 +       struct vx_info *vxi;
13187 +       struct nx_info *nxi;
13188         void *cgrp_ss_priv[CGROUP_CANFORK_COUNT] = {};
13189  
13190         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
13191 @@ -1343,7 +1350,12 @@ static struct task_struct *copy_process(
13192         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
13193         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
13194  #endif
13195 +       init_vx_info(&p->vx_info, current_vx_info());
13196 +       init_nx_info(&p->nx_info, current_nx_info());
13197 +
13198         retval = -EAGAIN;
13199 +       if (!vx_nproc_avail(1))
13200 +               goto bad_fork_free;
13201         if (atomic_read(&p->real_cred->user->processes) >=
13202                         task_rlimit(p, RLIMIT_NPROC)) {
13203                 if (p->real_cred->user != INIT_USER &&
13204 @@ -1640,6 +1652,18 @@ static struct task_struct *copy_process(
13205         total_forks++;
13206         spin_unlock(&current->sighand->siglock);
13207         syscall_tracepoint_update(p);
13208 +
13209 +       /* p is copy of current */
13210 +       vxi = p->vx_info;
13211 +       if (vxi) {
13212 +               claim_vx_info(vxi, p);
13213 +               atomic_inc(&vxi->cvirt.nr_threads);
13214 +               atomic_inc(&vxi->cvirt.total_forks);
13215 +               vx_nproc_inc(p);
13216 +       }
13217 +       nxi = p->nx_info;
13218 +       if (nxi)
13219 +               claim_nx_info(nxi, p);
13220         write_unlock_irq(&tasklist_lock);
13221  
13222         proc_fork_connector(p);
13223 diff -NurpP --minimal linux-4.4.115/kernel/kthread.c linux-4.4.115-vs2.3.9.7/kernel/kthread.c
13224 --- linux-4.4.115/kernel/kthread.c      2018-02-10 14:38:57.000000000 +0000
13225 +++ linux-4.4.115-vs2.3.9.7/kernel/kthread.c    2018-01-09 17:01:06.000000000 +0000
13226 @@ -19,6 +19,7 @@
13227  #include <linux/ptrace.h>
13228  #include <linux/uaccess.h>
13229  #include <linux/cgroup.h>
13230 +#include <linux/vs_pid.h>
13231  #include <trace/events/sched.h>
13232  
13233  static DEFINE_SPINLOCK(kthread_create_lock);
13234 diff -NurpP --minimal linux-4.4.115/kernel/nsproxy.c linux-4.4.115-vs2.3.9.7/kernel/nsproxy.c
13235 --- linux-4.4.115/kernel/nsproxy.c      2015-04-12 22:12:50.000000000 +0000
13236 +++ linux-4.4.115-vs2.3.9.7/kernel/nsproxy.c    2018-01-09 16:36:33.000000000 +0000
13237 @@ -20,11 +20,14 @@
13238  #include <linux/mnt_namespace.h>
13239  #include <linux/utsname.h>
13240  #include <linux/pid_namespace.h>
13241 +#include <linux/vserver/global.h>
13242 +#include <linux/vserver/debug.h>
13243  #include <net/net_namespace.h>
13244  #include <linux/ipc_namespace.h>
13245  #include <linux/proc_ns.h>
13246  #include <linux/file.h>
13247  #include <linux/syscalls.h>
13248 +#include "../fs/mount.h"
13249  
13250  static struct kmem_cache *nsproxy_cachep;
13251  
13252 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
13253         struct nsproxy *nsproxy;
13254  
13255         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
13256 -       if (nsproxy)
13257 +       if (nsproxy) {
13258                 atomic_set(&nsproxy->count, 1);
13259 +               atomic_inc(&vs_global_nsproxy);
13260 +       }
13261 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
13262         return nsproxy;
13263  }
13264  
13265 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
13266   * Return the newly created nsproxy.  Do not attach this to the task,
13267   * leave it to the caller to do proper locking and attach it to task.
13268   */
13269 -static struct nsproxy *create_new_namespaces(unsigned long flags,
13270 -       struct task_struct *tsk, struct user_namespace *user_ns,
13271 -       struct fs_struct *new_fs)
13272 +static struct nsproxy *unshare_namespaces(
13273 +       unsigned long flags,
13274 +       struct nsproxy *orig,
13275 +       struct fs_struct *new_fs,
13276 +       struct user_namespace *new_user,
13277 +       struct pid_namespace *new_pid)
13278  {
13279         struct nsproxy *new_nsp;
13280         int err;
13281 @@ -67,32 +76,31 @@ static struct nsproxy *create_new_namesp
13282         if (!new_nsp)
13283                 return ERR_PTR(-ENOMEM);
13284  
13285 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
13286 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
13287         if (IS_ERR(new_nsp->mnt_ns)) {
13288                 err = PTR_ERR(new_nsp->mnt_ns);
13289                 goto out_ns;
13290         }
13291  
13292 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
13293 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
13294         if (IS_ERR(new_nsp->uts_ns)) {
13295                 err = PTR_ERR(new_nsp->uts_ns);
13296                 goto out_uts;
13297         }
13298  
13299 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
13300 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
13301         if (IS_ERR(new_nsp->ipc_ns)) {
13302                 err = PTR_ERR(new_nsp->ipc_ns);
13303                 goto out_ipc;
13304         }
13305  
13306 -       new_nsp->pid_ns_for_children =
13307 -               copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
13308 +       new_nsp->pid_ns_for_children = copy_pid_ns(flags, new_user, new_pid);
13309         if (IS_ERR(new_nsp->pid_ns_for_children)) {
13310                 err = PTR_ERR(new_nsp->pid_ns_for_children);
13311                 goto out_pid;
13312         }
13313  
13314 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
13315 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
13316         if (IS_ERR(new_nsp->net_ns)) {
13317                 err = PTR_ERR(new_nsp->net_ns);
13318                 goto out_net;
13319 @@ -117,6 +125,41 @@ out_ns:
13320         return ERR_PTR(err);
13321  }
13322  
13323 +static struct nsproxy *create_new_namespaces(unsigned long flags,
13324 +       struct task_struct *tsk, struct user_namespace *user_ns,
13325 +       struct fs_struct *new_fs)
13326 +
13327 +{
13328 +       return unshare_namespaces(flags, tsk->nsproxy,
13329 +               new_fs, user_ns, task_active_pid_ns(tsk));
13330 +}
13331 +
13332 +/*
13333 + * copies the nsproxy, setting refcount to 1, and grabbing a
13334 + * reference to all contained namespaces.
13335 + */
13336 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
13337 +{
13338 +       struct nsproxy *ns = create_nsproxy();
13339 +
13340 +       if (ns) {
13341 +               memcpy(ns, orig, sizeof(struct nsproxy));
13342 +               atomic_set(&ns->count, 1);
13343 +
13344 +               if (ns->mnt_ns)
13345 +                       get_mnt_ns(ns->mnt_ns);
13346 +               if (ns->uts_ns)
13347 +                       get_uts_ns(ns->uts_ns);
13348 +               if (ns->ipc_ns)
13349 +                       get_ipc_ns(ns->ipc_ns);
13350 +               if (ns->pid_ns_for_children)
13351 +                       get_pid_ns(ns->pid_ns_for_children);
13352 +               if (ns->net_ns)
13353 +                       get_net(ns->net_ns);
13354 +       }
13355 +       return ns;
13356 +}
13357 +
13358  /*
13359   * called from clone.  This now handles copy for nsproxy and all
13360   * namespaces therein.
13361 @@ -125,7 +168,10 @@ int copy_namespaces(unsigned long flags,
13362  {
13363         struct nsproxy *old_ns = tsk->nsproxy;
13364         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
13365 -       struct nsproxy *new_ns;
13366 +       struct nsproxy *new_ns = NULL;
13367 +
13368 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
13369 +               flags, tsk, old_ns);
13370  
13371         if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13372                               CLONE_NEWPID | CLONE_NEWNET)))) {
13373 @@ -133,7 +179,7 @@ int copy_namespaces(unsigned long flags,
13374                 return 0;
13375         }
13376  
13377 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13378 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags))
13379                 return -EPERM;
13380  
13381         /*
13382 @@ -152,6 +198,9 @@ int copy_namespaces(unsigned long flags,
13383                 return  PTR_ERR(new_ns);
13384  
13385         tsk->nsproxy = new_ns;
13386 +       vxdprintk(VXD_CBIT(space, 3),
13387 +               "copy_namespaces(0x%08lx,%p[%p]) = [%p]",
13388 +               flags, tsk, old_ns, new_ns);
13389         return 0;
13390  }
13391  
13392 @@ -165,7 +214,9 @@ void free_nsproxy(struct nsproxy *ns)
13393                 put_ipc_ns(ns->ipc_ns);
13394         if (ns->pid_ns_for_children)
13395                 put_pid_ns(ns->pid_ns_for_children);
13396 -       put_net(ns->net_ns);
13397 +       if (ns->net_ns)
13398 +               put_net(ns->net_ns);
13399 +       atomic_dec(&vs_global_nsproxy);
13400         kmem_cache_free(nsproxy_cachep, ns);
13401  }
13402  
13403 @@ -179,12 +230,16 @@ int unshare_nsproxy_namespaces(unsigned
13404         struct user_namespace *user_ns;
13405         int err = 0;
13406  
13407 +       vxdprintk(VXD_CBIT(space, 4),
13408 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
13409 +               unshare_flags, current->nsproxy);
13410 +
13411         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13412                                CLONE_NEWNET | CLONE_NEWPID)))
13413                 return 0;
13414  
13415         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
13416 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13417 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
13418                 return -EPERM;
13419  
13420         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
13421 diff -NurpP --minimal linux-4.4.115/kernel/pid.c linux-4.4.115-vs2.3.9.7/kernel/pid.c
13422 --- linux-4.4.115/kernel/pid.c  2018-02-10 14:38:57.000000000 +0000
13423 +++ linux-4.4.115-vs2.3.9.7/kernel/pid.c        2018-01-09 21:54:23.000000000 +0000
13424 @@ -38,6 +38,7 @@
13425  #include <linux/syscalls.h>
13426  #include <linux/proc_ns.h>
13427  #include <linux/proc_fs.h>
13428 +#include <linux/vs_pid.h>
13429  
13430  #define pid_hashfn(nr, ns)     \
13431         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
13432 @@ -379,7 +380,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
13433  
13434  struct pid *find_vpid(int nr)
13435  {
13436 -       return find_pid_ns(nr, task_active_pid_ns(current));
13437 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
13438  }
13439  EXPORT_SYMBOL_GPL(find_vpid);
13440  
13441 @@ -435,6 +436,9 @@ void transfer_pid(struct task_struct *ol
13442  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
13443  {
13444         struct task_struct *result = NULL;
13445 +
13446 +       if (type == __PIDTYPE_REALPID)
13447 +               type = PIDTYPE_PID;
13448         if (pid) {
13449                 struct hlist_node *first;
13450                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
13451 @@ -453,7 +457,7 @@ struct task_struct *find_task_by_pid_ns(
13452  {
13453         RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
13454                          "find_task_by_pid_ns() needs rcu_read_lock() protection");
13455 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
13456 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
13457  }
13458  
13459  struct task_struct *find_task_by_vpid(pid_t vnr)
13460 @@ -497,7 +501,7 @@ struct pid *find_get_pid(pid_t nr)
13461  }
13462  EXPORT_SYMBOL_GPL(find_get_pid);
13463  
13464 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13465 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
13466  {
13467         struct upid *upid;
13468         pid_t nr = 0;
13469 @@ -511,6 +515,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
13470  }
13471  EXPORT_SYMBOL_GPL(pid_nr_ns);
13472  
13473 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13474 +{
13475 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
13476 +}
13477 +
13478  pid_t pid_vnr(struct pid *pid)
13479  {
13480         return pid_nr_ns(pid, task_active_pid_ns(current));
13481 diff -NurpP --minimal linux-4.4.115/kernel/pid_namespace.c linux-4.4.115-vs2.3.9.7/kernel/pid_namespace.c
13482 --- linux-4.4.115/kernel/pid_namespace.c        2018-02-10 14:38:57.000000000 +0000
13483 +++ linux-4.4.115-vs2.3.9.7/kernel/pid_namespace.c      2018-01-09 16:36:33.000000000 +0000
13484 @@ -18,6 +18,7 @@
13485  #include <linux/proc_ns.h>
13486  #include <linux/reboot.h>
13487  #include <linux/export.h>
13488 +#include <linux/vserver/global.h>
13489  
13490  struct pid_cache {
13491         int nr_ids;
13492 @@ -111,6 +112,7 @@ static struct pid_namespace *create_pid_
13493         ns->ns.ops = &pidns_operations;
13494  
13495         kref_init(&ns->kref);
13496 +       atomic_inc(&vs_global_pid_ns);
13497         ns->level = level;
13498         ns->parent = get_pid_ns(parent_pid_ns);
13499         ns->user_ns = get_user_ns(user_ns);
13500 @@ -128,6 +130,7 @@ static struct pid_namespace *create_pid_
13501  out_free_map:
13502         kfree(ns->pidmap[0].page);
13503  out_free:
13504 +       atomic_dec(&vs_global_pid_ns);
13505         kmem_cache_free(pid_ns_cachep, ns);
13506  out:
13507         return ERR_PTR(err);
13508 diff -NurpP --minimal linux-4.4.115/kernel/printk/printk.c linux-4.4.115-vs2.3.9.7/kernel/printk/printk.c
13509 --- linux-4.4.115/kernel/printk/printk.c        2018-02-10 14:38:57.000000000 +0000
13510 +++ linux-4.4.115-vs2.3.9.7/kernel/printk/printk.c      2018-01-09 16:36:33.000000000 +0000
13511 @@ -46,6 +46,7 @@
13512  #include <linux/utsname.h>
13513  #include <linux/ctype.h>
13514  #include <linux/uio.h>
13515 +#include <linux/vs_cvirt.h>
13516  
13517  #include <asm/uaccess.h>
13518  
13519 @@ -502,7 +503,7 @@ int check_syslog_permissions(int type, i
13520                 goto ok;
13521  
13522         if (syslog_action_restricted(type)) {
13523 -               if (capable(CAP_SYSLOG))
13524 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
13525                         goto ok;
13526                 /*
13527                  * For historical reasons, accept CAP_SYS_ADMIN too, with
13528 @@ -1304,12 +1305,9 @@ int do_syslog(int type, char __user *buf
13529         if (error)
13530                 goto out;
13531  
13532 -       switch (type) {
13533 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
13534 -               break;
13535 -       case SYSLOG_ACTION_OPEN:        /* Open log */
13536 -               break;
13537 -       case SYSLOG_ACTION_READ:        /* Read from log */
13538 +       if ((type == SYSLOG_ACTION_READ) ||
13539 +           (type == SYSLOG_ACTION_READ_ALL) ||
13540 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
13541                 error = -EINVAL;
13542                 if (!buf || len < 0)
13543                         goto out;
13544 @@ -1320,6 +1318,16 @@ int do_syslog(int type, char __user *buf
13545                         error = -EFAULT;
13546                         goto out;
13547                 }
13548 +       }
13549 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13550 +               return vx_do_syslog(type, buf, len);
13551 +
13552 +       switch (type) {
13553 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
13554 +               break;
13555 +       case SYSLOG_ACTION_OPEN:        /* Open log */
13556 +               break;
13557 +       case SYSLOG_ACTION_READ:        /* Read from log */
13558                 error = wait_event_interruptible(log_wait,
13559                                                  syslog_seq != log_next_seq);
13560                 if (error)
13561 @@ -1332,16 +1340,6 @@ int do_syslog(int type, char __user *buf
13562                 /* FALL THRU */
13563         /* Read last kernel messages */
13564         case SYSLOG_ACTION_READ_ALL:
13565 -               error = -EINVAL;
13566 -               if (!buf || len < 0)
13567 -                       goto out;
13568 -               error = 0;
13569 -               if (!len)
13570 -                       goto out;
13571 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
13572 -                       error = -EFAULT;
13573 -                       goto out;
13574 -               }
13575                 error = syslog_print_all(buf, len, clear);
13576                 break;
13577         /* Clear ring buffer */
13578 diff -NurpP --minimal linux-4.4.115/kernel/ptrace.c linux-4.4.115-vs2.3.9.7/kernel/ptrace.c
13579 --- linux-4.4.115/kernel/ptrace.c       2018-02-10 14:38:57.000000000 +0000
13580 +++ linux-4.4.115-vs2.3.9.7/kernel/ptrace.c     2018-01-09 16:36:33.000000000 +0000
13581 @@ -23,6 +23,7 @@
13582  #include <linux/syscalls.h>
13583  #include <linux/uaccess.h>
13584  #include <linux/regset.h>
13585 +#include <linux/vs_context.h>
13586  #include <linux/hw_breakpoint.h>
13587  #include <linux/cn_proc.h>
13588  #include <linux/compat.h>
13589 @@ -295,6 +296,11 @@ ok:
13590              !ptrace_has_cap(mm->user_ns, mode)))
13591             return -EPERM;
13592  
13593 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
13594 +               return -EPERM;
13595 +       if (!vx_check(task->xid, VS_IDENT) &&
13596 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
13597 +               return -EACCES;
13598         return security_ptrace_access_check(task, mode);
13599  }
13600  
13601 diff -NurpP --minimal linux-4.4.115/kernel/reboot.c linux-4.4.115-vs2.3.9.7/kernel/reboot.c
13602 --- linux-4.4.115/kernel/reboot.c       2016-07-05 04:12:39.000000000 +0000
13603 +++ linux-4.4.115-vs2.3.9.7/kernel/reboot.c     2018-01-09 16:36:33.000000000 +0000
13604 @@ -16,6 +16,7 @@
13605  #include <linux/syscalls.h>
13606  #include <linux/syscore_ops.h>
13607  #include <linux/uaccess.h>
13608 +#include <linux/vs_pid.h>
13609  
13610  /*
13611   * this indicates whether you can reboot with ctrl-alt-del: the default is yes
13612 @@ -269,6 +270,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
13613  
13614  static DEFINE_MUTEX(reboot_mutex);
13615  
13616 +long vs_reboot(unsigned int, void __user *);
13617 +
13618  /*
13619   * Reboot system call: for obvious reasons only root may call it,
13620   * and even root needs to set up some magic numbers in the registers
13621 @@ -311,6 +314,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
13622         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
13623                 cmd = LINUX_REBOOT_CMD_HALT;
13624  
13625 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13626 +               return vs_reboot(cmd, arg);
13627 +
13628         mutex_lock(&reboot_mutex);
13629         switch (cmd) {
13630         case LINUX_REBOOT_CMD_RESTART:
13631 diff -NurpP --minimal linux-4.4.115/kernel/sched/core.c linux-4.4.115-vs2.3.9.7/kernel/sched/core.c
13632 --- linux-4.4.115/kernel/sched/core.c   2018-02-10 14:38:57.000000000 +0000
13633 +++ linux-4.4.115-vs2.3.9.7/kernel/sched/core.c 2018-02-10 15:16:50.000000000 +0000
13634 @@ -74,6 +74,8 @@
13635  #include <linux/binfmts.h>
13636  #include <linux/context_tracking.h>
13637  #include <linux/compiler.h>
13638 +#include <linux/vs_sched.h>
13639 +#include <linux/vs_cvirt.h>
13640  
13641  #include <asm/switch_to.h>
13642  #include <asm/tlb.h>
13643 @@ -3559,7 +3561,7 @@ SYSCALL_DEFINE1(nice, int, increment)
13644  
13645         nice = clamp_val(nice, MIN_NICE, MAX_NICE);
13646         if (increment < 0 && !can_nice(current, nice))
13647 -               return -EPERM;
13648 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
13649  
13650         retval = security_task_setnice(current, nice);
13651         if (retval)
13652 diff -NurpP --minimal linux-4.4.115/kernel/sched/cputime.c linux-4.4.115-vs2.3.9.7/kernel/sched/cputime.c
13653 --- linux-4.4.115/kernel/sched/cputime.c        2018-02-10 14:38:57.000000000 +0000
13654 +++ linux-4.4.115-vs2.3.9.7/kernel/sched/cputime.c      2018-01-09 16:36:33.000000000 +0000
13655 @@ -4,6 +4,7 @@
13656  #include <linux/kernel_stat.h>
13657  #include <linux/static_key.h>
13658  #include <linux/context_tracking.h>
13659 +#include <linux/vs_sched.h>
13660  #include "sched.h"
13661  
13662  
13663 @@ -135,14 +136,17 @@ static inline void task_group_account_fi
13664  void account_user_time(struct task_struct *p, cputime_t cputime,
13665                        cputime_t cputime_scaled)
13666  {
13667 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
13668 +       int nice = (task_nice(p) > 0);
13669         int index;
13670  
13671         /* Add user time to process. */
13672         p->utime += cputime;
13673         p->utimescaled += cputime_scaled;
13674 +       vx_account_user(vxi, cputime, nice);
13675         account_group_user_time(p, cputime);
13676  
13677 -       index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
13678 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
13679  
13680         /* Add user time to cpustat. */
13681         task_group_account_field(p, index, (__force u64) cputime);
13682 @@ -189,9 +193,12 @@ static inline
13683  void __account_system_time(struct task_struct *p, cputime_t cputime,
13684                         cputime_t cputime_scaled, int index)
13685  {
13686 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
13687 +
13688         /* Add system time to process. */
13689         p->stime += cputime;
13690         p->stimescaled += cputime_scaled;
13691 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
13692         account_group_system_time(p, cputime);
13693  
13694         /* Add system time to cpustat. */
13695 diff -NurpP --minimal linux-4.4.115/kernel/sched/fair.c linux-4.4.115-vs2.3.9.7/kernel/sched/fair.c
13696 --- linux-4.4.115/kernel/sched/fair.c   2018-02-10 14:38:57.000000000 +0000
13697 +++ linux-4.4.115-vs2.3.9.7/kernel/sched/fair.c 2018-01-09 16:36:33.000000000 +0000
13698 @@ -30,6 +30,7 @@
13699  #include <linux/mempolicy.h>
13700  #include <linux/migrate.h>
13701  #include <linux/task_work.h>
13702 +#include <linux/vs_cvirt.h>
13703  
13704  #include <trace/events/sched.h>
13705  
13706 @@ -3055,6 +3056,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
13707                 __enqueue_entity(cfs_rq, se);
13708         se->on_rq = 1;
13709  
13710 +       if (entity_is_task(se))
13711 +               vx_activate_task(task_of(se));
13712         if (cfs_rq->nr_running == 1) {
13713                 list_add_leaf_cfs_rq(cfs_rq);
13714                 check_enqueue_throttle(cfs_rq);
13715 @@ -3136,6 +3139,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
13716         if (se != cfs_rq->curr)
13717                 __dequeue_entity(cfs_rq, se);
13718         se->on_rq = 0;
13719 +       if (entity_is_task(se))
13720 +               vx_deactivate_task(task_of(se));
13721         account_entity_dequeue(cfs_rq, se);
13722  
13723         /*
13724 diff -NurpP --minimal linux-4.4.115/kernel/sched/loadavg.c linux-4.4.115-vs2.3.9.7/kernel/sched/loadavg.c
13725 --- linux-4.4.115/kernel/sched/loadavg.c        2018-02-10 14:38:57.000000000 +0000
13726 +++ linux-4.4.115-vs2.3.9.7/kernel/sched/loadavg.c      2018-01-24 23:01:30.000000000 +0000
13727 @@ -73,9 +73,16 @@ EXPORT_SYMBOL(avenrun); /* should be rem
13728   */
13729  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
13730  {
13731 -       loads[0] = (avenrun[0] + offset) << shift;
13732 -       loads[1] = (avenrun[1] + offset) << shift;
13733 -       loads[2] = (avenrun[2] + offset) << shift;
13734 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
13735 +               struct vx_info *vxi = current_vx_info();
13736 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
13737 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
13738 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
13739 +       } else {
13740 +               loads[0] = (avenrun[0] + offset) << shift;
13741 +               loads[1] = (avenrun[1] + offset) << shift;
13742 +               loads[2] = (avenrun[2] + offset) << shift;
13743 +       }
13744  }
13745  
13746  long calc_load_fold_active(struct rq *this_rq)
13747 diff -NurpP --minimal linux-4.4.115/kernel/signal.c linux-4.4.115-vs2.3.9.7/kernel/signal.c
13748 --- linux-4.4.115/kernel/signal.c       2018-02-10 14:38:57.000000000 +0000
13749 +++ linux-4.4.115-vs2.3.9.7/kernel/signal.c     2018-01-11 08:03:00.000000000 +0000
13750 @@ -34,6 +34,8 @@
13751  #include <linux/compat.h>
13752  #include <linux/cn_proc.h>
13753  #include <linux/compiler.h>
13754 +#include <linux/vs_context.h>
13755 +#include <linux/vs_pid.h>
13756  
13757  #define CREATE_TRACE_POINTS
13758  #include <trace/events/signal.h>
13759 @@ -726,9 +728,18 @@ static int check_kill_permission(int sig
13760         struct pid *sid;
13761         int error;
13762  
13763 +       vxdprintk(VXD_CBIT(misc, 7),
13764 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
13765 +               sig, info, t, vx_task_xid(t), t->pid);
13766 +
13767         if (!valid_signal(sig))
13768                 return -EINVAL;
13769  
13770 +/*     FIXME: needed? if so, why?
13771 +       if ((info != SEND_SIG_NOINFO) &&
13772 +               (is_si_special(info) || !si_fromuser(info)))
13773 +               goto skip;      */
13774 +
13775         if (!si_fromuser(info))
13776                 return 0;
13777  
13778 @@ -752,6 +763,20 @@ static int check_kill_permission(int sig
13779                 }
13780         }
13781  
13782 +       error = -EPERM;
13783 +       if (t->pid == 1 && current->xid)
13784 +               return error;
13785 +
13786 +       error = -ESRCH;
13787 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
13788 +                 loops, maybe ENOENT or EACCES? */
13789 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
13790 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
13791 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
13792 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
13793 +               return error;
13794 +       }
13795 +/* skip: */
13796         return security_task_kill(t, info, sig, 0);
13797  }
13798  
13799 @@ -1303,8 +1328,14 @@ int kill_pid_info(int sig, struct siginf
13800         for (;;) {
13801                 rcu_read_lock();
13802                 p = pid_task(pid, PIDTYPE_PID);
13803 -               if (p)
13804 -                       error = group_send_sig_info(sig, info, p);
13805 +               if (p) {
13806 +                       if (vx_check(vx_task_xid(p), VS_IDENT))
13807 +                               error = group_send_sig_info(sig, info, p);
13808 +                       else {
13809 +                               rcu_read_unlock();
13810 +                               return -ESRCH;
13811 +                       }
13812 +               }
13813                 rcu_read_unlock();
13814                 if (likely(!p || error != -ESRCH))
13815                         return error;
13816 @@ -1349,7 +1380,7 @@ int kill_pid_info_as_cred(int sig, struc
13817  
13818         rcu_read_lock();
13819         p = pid_task(pid, PIDTYPE_PID);
13820 -       if (!p) {
13821 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
13822                 ret = -ESRCH;
13823                 goto out_unlock;
13824         }
13825 @@ -1401,8 +1432,10 @@ static int kill_something_info(int sig,
13826                 struct task_struct * p;
13827  
13828                 for_each_process(p) {
13829 -                       if (task_pid_vnr(p) > 1 &&
13830 -                                       !same_thread_group(p, current)) {
13831 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
13832 +                               task_pid_vnr(p) > 1 &&
13833 +                               !same_thread_group(p, current) &&
13834 +                               !vx_current_initpid(p->pid)) {
13835                                 int err = group_send_sig_info(sig, info, p);
13836                                 ++count;
13837                                 if (err != -EPERM)
13838 @@ -2255,6 +2288,11 @@ relock:
13839                                 !sig_kernel_only(signr))
13840                         continue;
13841  
13842 +               /* virtual init is protected against user signals */
13843 +               if ((ksig->info.si_code == SI_USER) &&
13844 +                       vx_current_initpid(current->pid))
13845 +                       continue;
13846 +
13847                 if (sig_kernel_stop(signr)) {
13848                         /*
13849                          * The default action is to stop all threads in
13850 diff -NurpP --minimal linux-4.4.115/kernel/softirq.c linux-4.4.115-vs2.3.9.7/kernel/softirq.c
13851 --- linux-4.4.115/kernel/softirq.c      2015-04-12 22:12:50.000000000 +0000
13852 +++ linux-4.4.115-vs2.3.9.7/kernel/softirq.c    2018-01-09 16:36:34.000000000 +0000
13853 @@ -26,6 +26,7 @@
13854  #include <linux/smpboot.h>
13855  #include <linux/tick.h>
13856  #include <linux/irq.h>
13857 +#include <linux/vs_context.h>
13858  
13859  #define CREATE_TRACE_POINTS
13860  #include <trace/events/irq.h>
13861 diff -NurpP --minimal linux-4.4.115/kernel/sys.c linux-4.4.115-vs2.3.9.7/kernel/sys.c
13862 --- linux-4.4.115/kernel/sys.c  2018-02-10 14:38:57.000000000 +0000
13863 +++ linux-4.4.115-vs2.3.9.7/kernel/sys.c        2018-01-09 17:00:36.000000000 +0000
13864 @@ -54,6 +54,7 @@
13865  #include <linux/cred.h>
13866  
13867  #include <linux/kmsg_dump.h>
13868 +#include <linux/vs_pid.h>
13869  /* Move somewhere else to avoid recompiling? */
13870  #include <generated/utsrelease.h>
13871  
13872 @@ -157,7 +158,10 @@ static int set_one_prio(struct task_stru
13873                 goto out;
13874         }
13875         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
13876 -               error = -EACCES;
13877 +               if (vx_flags(VXF_IGNEG_NICE, 0))
13878 +                       error = 0;
13879 +               else
13880 +                       error = -EACCES;
13881                 goto out;
13882         }
13883         no_nice = security_task_setnice(p, niceval);
13884 @@ -208,6 +212,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
13885                 else
13886                         pgrp = task_pgrp(current);
13887                 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
13888 +                       if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
13889 +                               continue;
13890                         error = set_one_prio(p, niceval, error);
13891                 } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
13892                 break;
13893 @@ -274,6 +280,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
13894                 else
13895                         pgrp = task_pgrp(current);
13896                 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
13897 +                       if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
13898 +                               continue;
13899                         niceval = nice_to_rlimit(task_nice(p));
13900                         if (niceval > retval)
13901                                 retval = niceval;
13902 @@ -290,6 +298,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
13903                                 goto out_unlock;        /* No processes for this user */
13904                 }
13905                 do_each_thread(g, p) {
13906 +                       if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
13907 +                               continue;
13908                         if (uid_eq(task_uid(p), uid) && task_pid_vnr(p)) {
13909                                 niceval = nice_to_rlimit(task_nice(p));
13910                                 if (niceval > retval)
13911 @@ -1217,7 +1227,8 @@ SYSCALL_DEFINE2(sethostname, char __user
13912         int errno;
13913         char tmp[__NEW_UTS_LEN];
13914  
13915 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
13916 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
13917 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
13918                 return -EPERM;
13919  
13920         if (len < 0 || len > __NEW_UTS_LEN)
13921 @@ -1268,7 +1279,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
13922         int errno;
13923         char tmp[__NEW_UTS_LEN];
13924  
13925 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
13926 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
13927 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
13928                 return -EPERM;
13929         if (len < 0 || len > __NEW_UTS_LEN)
13930                 return -EINVAL;
13931 @@ -1386,7 +1398,7 @@ int do_prlimit(struct task_struct *tsk,
13932                 /* Keep the capable check against init_user_ns until
13933                    cgroups can contain all limits */
13934                 if (new_rlim->rlim_max > rlim->rlim_max &&
13935 -                               !capable(CAP_SYS_RESOURCE))
13936 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
13937                         retval = -EPERM;
13938                 if (!retval)
13939                         retval = security_task_setrlimit(tsk->group_leader,
13940 @@ -1439,7 +1451,8 @@ static int check_prlimit_permission(stru
13941             gid_eq(cred->gid, tcred->sgid) &&
13942             gid_eq(cred->gid, tcred->gid))
13943                 return 0;
13944 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
13945 +       if (vx_ns_capable(tcred->user_ns,
13946 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
13947                 return 0;
13948  
13949         return -EPERM;
13950 diff -NurpP --minimal linux-4.4.115/kernel/sysctl.c linux-4.4.115-vs2.3.9.7/kernel/sysctl.c
13951 --- linux-4.4.115/kernel/sysctl.c       2018-02-10 14:38:57.000000000 +0000
13952 +++ linux-4.4.115-vs2.3.9.7/kernel/sysctl.c     2018-01-09 16:36:34.000000000 +0000
13953 @@ -87,6 +87,7 @@
13954  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
13955  #include <linux/lockdep.h>
13956  #endif
13957 +extern char vshelper_path[];
13958  #ifdef CONFIG_CHR_DEV_SG
13959  #include <scsi/sg.h>
13960  #endif
13961 @@ -279,6 +280,13 @@ static int max_extfrag_threshold = 1000;
13962  
13963  static struct ctl_table kern_table[] = {
13964         {
13965 +               .procname       = "vshelper",
13966 +               .data           = &vshelper_path,
13967 +               .maxlen         = 256,
13968 +               .mode           = 0644,
13969 +               .proc_handler   = proc_dostring,
13970 +       },
13971 +       {
13972                 .procname       = "sched_child_runs_first",
13973                 .data           = &sysctl_sched_child_runs_first,
13974                 .maxlen         = sizeof(unsigned int),
13975 @@ -1385,7 +1393,6 @@ static struct ctl_table vm_table[] = {
13976                 .extra1         = &zero,
13977                 .extra2         = &one,
13978         },
13979 -
13980  #endif /* CONFIG_COMPACTION */
13981         {
13982                 .procname       = "min_free_kbytes",
13983 diff -NurpP --minimal linux-4.4.115/kernel/sysctl_binary.c linux-4.4.115-vs2.3.9.7/kernel/sysctl_binary.c
13984 --- linux-4.4.115/kernel/sysctl_binary.c        2018-02-10 14:38:57.000000000 +0000
13985 +++ linux-4.4.115-vs2.3.9.7/kernel/sysctl_binary.c      2018-01-09 16:36:34.000000000 +0000
13986 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
13987  
13988         { CTL_INT,      KERN_PANIC,                     "panic" },
13989         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
13990 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
13991  
13992         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
13993         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
13994 diff -NurpP --minimal linux-4.4.115/kernel/time/posix-timers.c linux-4.4.115-vs2.3.9.7/kernel/time/posix-timers.c
13995 --- linux-4.4.115/kernel/time/posix-timers.c    2018-02-10 14:38:57.000000000 +0000
13996 +++ linux-4.4.115-vs2.3.9.7/kernel/time/posix-timers.c  2018-01-09 16:36:34.000000000 +0000
13997 @@ -48,6 +48,7 @@
13998  #include <linux/workqueue.h>
13999  #include <linux/export.h>
14000  #include <linux/hashtable.h>
14001 +#include <linux/vs_context.h>
14002  
14003  #include "timekeeping.h"
14004  
14005 @@ -407,6 +408,7 @@ int posix_timer_event(struct k_itimer *t
14006  {
14007         struct task_struct *task;
14008         int shared, ret = -1;
14009 +
14010         /*
14011          * FIXME: if ->sigq is queued we can race with
14012          * dequeue_signal()->do_schedule_next_timer().
14013 @@ -423,10 +425,18 @@ int posix_timer_event(struct k_itimer *t
14014         rcu_read_lock();
14015         task = pid_task(timr->it_pid, PIDTYPE_PID);
14016         if (task) {
14017 +               struct vx_info_save vxis;
14018 +               struct vx_info *vxi;
14019 +
14020 +               vxi = get_vx_info(task->vx_info);
14021 +               enter_vx_info(vxi, &vxis);
14022                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14023                 ret = send_sigqueue(timr->sigq, task, shared);
14024 +               leave_vx_info(&vxis);
14025 +               put_vx_info(vxi);
14026         }
14027         rcu_read_unlock();
14028 +
14029         /* If we failed to send the signal the timer stops. */
14030         return ret > 0;
14031  }
14032 diff -NurpP --minimal linux-4.4.115/kernel/time/time.c linux-4.4.115-vs2.3.9.7/kernel/time/time.c
14033 --- linux-4.4.115/kernel/time/time.c    2016-07-05 04:12:39.000000000 +0000
14034 +++ linux-4.4.115-vs2.3.9.7/kernel/time/time.c  2018-01-09 16:36:34.000000000 +0000
14035 @@ -37,6 +37,7 @@
14036  #include <linux/fs.h>
14037  #include <linux/math64.h>
14038  #include <linux/ptrace.h>
14039 +#include <linux/vs_time.h>
14040  
14041  #include <asm/uaccess.h>
14042  #include <asm/unistd.h>
14043 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
14044         if (err)
14045                 return err;
14046  
14047 -       do_settimeofday(&tv);
14048 +       vx_settimeofday(&tv);
14049         return 0;
14050  }
14051  
14052 @@ -186,7 +187,7 @@ int do_sys_settimeofday(const struct tim
14053                 }
14054         }
14055         if (tv)
14056 -               return do_settimeofday(tv);
14057 +               return vx_settimeofday(tv);
14058         return 0;
14059  }
14060  
14061 diff -NurpP --minimal linux-4.4.115/kernel/time/timekeeping.c linux-4.4.115-vs2.3.9.7/kernel/time/timekeeping.c
14062 --- linux-4.4.115/kernel/time/timekeeping.c     2018-02-10 14:38:57.000000000 +0000
14063 +++ linux-4.4.115-vs2.3.9.7/kernel/time/timekeeping.c   2018-01-09 17:02:47.000000000 +0000
14064 @@ -23,6 +23,7 @@
14065  #include <linux/stop_machine.h>
14066  #include <linux/pvclock_gtod.h>
14067  #include <linux/compiler.h>
14068 +#include <linux/vs_time.h>
14069  
14070  #include "tick-internal.h"
14071  #include "ntp_internal.h"
14072 @@ -921,7 +922,9 @@ void ktime_get_raw_and_real_ts64(struct
14073         } while (read_seqcount_retry(&tk_core.seq, seq));
14074  
14075         timespec64_add_ns(ts_raw, nsecs_raw);
14076 +       vx_adjust_timespec(ts_raw);
14077         timespec64_add_ns(ts_real, nsecs_real);
14078 +       vx_adjust_timespec(ts_real);
14079  }
14080  EXPORT_SYMBOL(ktime_get_raw_and_real_ts64);
14081  
14082 diff -NurpP --minimal linux-4.4.115/kernel/time/timer.c linux-4.4.115-vs2.3.9.7/kernel/time/timer.c
14083 --- linux-4.4.115/kernel/time/timer.c   2018-02-10 14:38:57.000000000 +0000
14084 +++ linux-4.4.115-vs2.3.9.7/kernel/time/timer.c 2018-02-10 15:16:50.000000000 +0000
14085 @@ -42,6 +42,10 @@
14086  #include <linux/sched/sysctl.h>
14087  #include <linux/slab.h>
14088  #include <linux/compat.h>
14089 +#include <linux/vs_base.h>
14090 +#include <linux/vs_cvirt.h>
14091 +#include <linux/vs_pid.h>
14092 +#include <linux/vserver/sched.h>
14093  
14094  #include <asm/uaccess.h>
14095  #include <asm/unistd.h>
14096 diff -NurpP --minimal linux-4.4.115/kernel/user_namespace.c linux-4.4.115-vs2.3.9.7/kernel/user_namespace.c
14097 --- linux-4.4.115/kernel/user_namespace.c       2016-07-05 04:12:39.000000000 +0000
14098 +++ linux-4.4.115-vs2.3.9.7/kernel/user_namespace.c     2018-01-09 16:36:34.000000000 +0000
14099 @@ -22,6 +22,7 @@
14100  #include <linux/ctype.h>
14101  #include <linux/projid.h>
14102  #include <linux/fs_struct.h>
14103 +#include <linux/vserver/global.h>
14104  
14105  static struct kmem_cache *user_ns_cachep __read_mostly;
14106  static DEFINE_MUTEX(userns_state_mutex);
14107 @@ -97,6 +98,7 @@ int create_user_ns(struct cred *new)
14108  
14109         atomic_set(&ns->count, 1);
14110         /* Leave the new->user_ns reference with the new user namespace. */
14111 +       atomic_inc(&vs_global_user_ns);
14112         ns->parent = parent_ns;
14113         ns->level = parent_ns->level + 1;
14114         ns->owner = owner;
14115 @@ -145,6 +147,7 @@ void free_user_ns(struct user_namespace
14116                 key_put(ns->persistent_keyring_register);
14117  #endif
14118                 ns_free_inum(&ns->ns);
14119 +               atomic_dec(&vs_global_user_ns);
14120                 kmem_cache_free(user_ns_cachep, ns);
14121                 ns = parent;
14122         } while (atomic_dec_and_test(&parent->count));
14123 @@ -358,6 +361,18 @@ gid_t from_kgid_munged(struct user_names
14124  }
14125  EXPORT_SYMBOL(from_kgid_munged);
14126  
14127 +ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
14128 +{
14129 +       return KTAGT_INIT(tag);
14130 +}
14131 +EXPORT_SYMBOL(make_ktag);
14132 +
14133 +vtag_t from_ktag(struct user_namespace *to, ktag_t tag)
14134 +{
14135 +       return __ktag_val(tag);
14136 +}
14137 +EXPORT_SYMBOL(from_ktag);
14138 +
14139  /**
14140   *     make_kprojid - Map a user-namespace projid pair into a kprojid.
14141   *     @ns:  User namespace that the projid is in
14142 diff -NurpP --minimal linux-4.4.115/kernel/utsname.c linux-4.4.115-vs2.3.9.7/kernel/utsname.c
14143 --- linux-4.4.115/kernel/utsname.c      2015-04-12 22:12:50.000000000 +0000
14144 +++ linux-4.4.115-vs2.3.9.7/kernel/utsname.c    2018-01-09 16:36:34.000000000 +0000
14145 @@ -16,14 +16,17 @@
14146  #include <linux/slab.h>
14147  #include <linux/user_namespace.h>
14148  #include <linux/proc_ns.h>
14149 +#include <linux/vserver/global.h>
14150  
14151  static struct uts_namespace *create_uts_ns(void)
14152  {
14153         struct uts_namespace *uts_ns;
14154  
14155         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
14156 -       if (uts_ns)
14157 +       if (uts_ns) {
14158                 kref_init(&uts_ns->kref);
14159 +               atomic_inc(&vs_global_uts_ns);
14160 +       }
14161         return uts_ns;
14162  }
14163  
14164 @@ -87,6 +90,7 @@ void free_uts_ns(struct kref *kref)
14165         ns = container_of(kref, struct uts_namespace, kref);
14166         put_user_ns(ns->user_ns);
14167         ns_free_inum(&ns->ns);
14168 +       atomic_dec(&vs_global_uts_ns);
14169         kfree(ns);
14170  }
14171  
14172 diff -NurpP --minimal linux-4.4.115/kernel/vserver/Kconfig linux-4.4.115-vs2.3.9.7/kernel/vserver/Kconfig
14173 --- linux-4.4.115/kernel/vserver/Kconfig        1970-01-01 00:00:00.000000000 +0000
14174 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/Kconfig      2018-01-09 16:36:34.000000000 +0000
14175 @@ -0,0 +1,230 @@
14176 +#
14177 +# Linux VServer configuration
14178 +#
14179 +
14180 +menu "Linux VServer"
14181 +
14182 +config VSERVER_AUTO_LBACK
14183 +       bool    "Automatically Assign Loopback IP"
14184 +       default y
14185 +       help
14186 +         Automatically assign a guest specific loopback
14187 +         IP and add it to the kernel network stack on
14188 +         startup.
14189 +
14190 +config VSERVER_AUTO_SINGLE
14191 +       bool    "Automatic Single IP Special Casing"
14192 +       default n
14193 +       help
14194 +         This allows network contexts with a single IP to
14195 +         automatically remap 0.0.0.0 bindings to that IP,
14196 +         avoiding further network checks and improving
14197 +         performance.
14198 +
14199 +         (note: such guests do not allow to change the ip
14200 +          on the fly and do not show loopback addresses)
14201 +
14202 +config VSERVER_COWBL
14203 +       bool    "Enable COW Immutable Link Breaking"
14204 +       default y
14205 +       help
14206 +         This enables the COW (Copy-On-Write) link break code.
14207 +         It allows you to treat unified files like normal files
14208 +         when writing to them (which will implicitely break the
14209 +         link and create a copy of the unified file)
14210 +
14211 +config VSERVER_VTIME
14212 +       bool    "Enable Virtualized Guest Time (EXPERIMENTAL)"
14213 +       default n
14214 +       help
14215 +         This enables per guest time offsets to allow for
14216 +         adjusting the system clock individually per guest.
14217 +         this adds some overhead to the time functions and
14218 +         therefore should not be enabled without good reason.
14219 +
14220 +config VSERVER_DEVICE
14221 +       bool    "Enable Guest Device Mapping (EXPERIMENTAL)"
14222 +       default n
14223 +       help
14224 +         This enables generic device remapping.
14225 +
14226 +config VSERVER_PROC_SECURE
14227 +       bool    "Enable Proc Security"
14228 +       depends on PROC_FS
14229 +       default y
14230 +       help
14231 +         This configures ProcFS security to initially hide
14232 +         non-process entries for all contexts except the main and
14233 +         spectator context (i.e. for all guests), which is a secure
14234 +         default.
14235 +
14236 +         (note: on 1.2x the entries were visible by default)
14237 +
14238 +choice
14239 +       prompt  "Persistent Inode Tagging"
14240 +       default TAGGING_ID24
14241 +       help
14242 +         This adds persistent context information to filesystems
14243 +         mounted with the tagxid option. Tagging is a requirement
14244 +         for per-context disk limits and per-context quota.
14245 +
14246 +
14247 +config TAGGING_NONE
14248 +       bool    "Disabled"
14249 +       help
14250 +         do not store per-context information in inodes.
14251 +
14252 +config TAGGING_UID16
14253 +       bool    "UID16/GID32"
14254 +       help
14255 +         reduces UID to 16 bit, but leaves GID at 32 bit.
14256 +
14257 +config TAGGING_GID16
14258 +       bool    "UID32/GID16"
14259 +       help
14260 +         reduces GID to 16 bit, but leaves UID at 32 bit.
14261 +
14262 +config TAGGING_ID24
14263 +       bool    "UID24/GID24"
14264 +       help
14265 +         uses the upper 8bit from UID and GID for XID tagging
14266 +         which leaves 24bit for UID/GID each, which should be
14267 +         more than sufficient for normal use.
14268 +
14269 +config TAGGING_INTERN
14270 +       bool    "UID32/GID32"
14271 +       help
14272 +         this uses otherwise reserved inode fields in the on
14273 +         disk representation, which limits the use to a few
14274 +         filesystems (currently ext2 and ext3)
14275 +
14276 +endchoice
14277 +
14278 +config TAG_NFSD
14279 +       bool    "Tag NFSD User Auth and Files"
14280 +       default n
14281 +       help
14282 +         Enable this if you do want the in-kernel NFS
14283 +         Server to use the tagging specified above.
14284 +         (will require patched clients too)
14285 +
14286 +config VSERVER_PRIVACY
14287 +       bool    "Honor Privacy Aspects of Guests"
14288 +       default n
14289 +       help
14290 +         When enabled, most context checks will disallow
14291 +         access to structures assigned to a specific context,
14292 +         like ptys or loop devices.
14293 +
14294 +config VSERVER_CONTEXTS
14295 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
14296 +       range 1 65533
14297 +       default "768"   if 64BIT
14298 +       default "256"
14299 +       help
14300 +         This setting will optimize certain data structures
14301 +         and memory allocations according to the expected
14302 +         maximum.
14303 +
14304 +         note: this is not a strict upper limit.
14305 +
14306 +config VSERVER_WARN
14307 +       bool    "VServer Warnings"
14308 +       default y
14309 +       help
14310 +         This enables various runtime warnings, which will
14311 +         notify about potential manipulation attempts or
14312 +         resource shortage. It is generally considered to
14313 +         be a good idea to have that enabled.
14314 +
14315 +config VSERVER_WARN_DEVPTS
14316 +       bool    "VServer DevPTS Warnings"
14317 +       depends on VSERVER_WARN
14318 +       default y
14319 +       help
14320 +         This enables DevPTS related warnings, issued when a
14321 +         process inside a context tries to lookup or access
14322 +         a dynamic pts from the host or a different context.
14323 +
14324 +config VSERVER_DEBUG
14325 +       bool    "VServer Debugging Code"
14326 +       default n
14327 +       help
14328 +         Set this to yes if you want to be able to activate
14329 +         debugging output at runtime. It adds a very small
14330 +         overhead to all vserver related functions and
14331 +         increases the kernel size by about 20k.
14332 +
14333 +config VSERVER_HISTORY
14334 +       bool    "VServer History Tracing"
14335 +       depends on VSERVER_DEBUG
14336 +       default n
14337 +       help
14338 +         Set this to yes if you want to record the history of
14339 +         linux-vserver activities, so they can be replayed in
14340 +         the event of a kernel panic or oops.
14341 +
14342 +config VSERVER_HISTORY_SIZE
14343 +       int     "Per-CPU History Size (32-65536)"
14344 +       depends on VSERVER_HISTORY
14345 +       range 32 65536
14346 +       default 64
14347 +       help
14348 +         This allows you to specify the number of entries in
14349 +         the per-CPU history buffer.
14350 +
14351 +config VSERVER_EXTRA_MNT_CHECK
14352 +       bool    "Extra Checks for Reachability"
14353 +       default n
14354 +       help
14355 +         Set this to yes if you want to do extra checks for
14356 +         vfsmount reachability in the proc filesystem code.
14357 +         This shouldn't be required on any setup utilizing
14358 +         mnt namespaces.
14359 +
14360 +choice
14361 +       prompt  "Quotes used in debug and warn messages"
14362 +       default QUOTES_ISO8859
14363 +
14364 +config QUOTES_ISO8859
14365 +       bool    "Extended ASCII (ISO 8859) angle quotes"
14366 +       help
14367 +         This uses the extended ASCII characters \xbb
14368 +         and \xab for quoting file and process names.
14369 +
14370 +config QUOTES_UTF8
14371 +       bool    "UTF-8 angle quotes"
14372 +       help
14373 +         This uses the the UTF-8 sequences for angle
14374 +         quotes to quote file and process names.
14375 +
14376 +config QUOTES_ASCII
14377 +       bool    "ASCII single quotes"
14378 +       help
14379 +         This uses the ASCII single quote character
14380 +         (\x27) to quote file and process names.
14381 +
14382 +endchoice
14383 +
14384 +endmenu
14385 +
14386 +
14387 +config VSERVER
14388 +       bool
14389 +       default y
14390 +       select NAMESPACES
14391 +       select UTS_NS
14392 +       select IPC_NS
14393 +#      select USER_NS
14394 +       select SYSVIPC
14395 +
14396 +config VSERVER_SECURITY
14397 +       bool
14398 +       depends on SECURITY
14399 +       default y
14400 +       select SECURITY_CAPABILITIES
14401 +
14402 +config VSERVER_DISABLED
14403 +       bool
14404 +       default n
14405 +
14406 diff -NurpP --minimal linux-4.4.115/kernel/vserver/Makefile linux-4.4.115-vs2.3.9.7/kernel/vserver/Makefile
14407 --- linux-4.4.115/kernel/vserver/Makefile       1970-01-01 00:00:00.000000000 +0000
14408 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/Makefile     2018-01-09 16:36:34.000000000 +0000
14409 @@ -0,0 +1,18 @@
14410 +#
14411 +# Makefile for the Linux vserver routines.
14412 +#
14413 +
14414 +
14415 +obj-y          += vserver.o
14416 +
14417 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
14418 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
14419 +                  dlimit.o tag.o
14420 +
14421 +vserver-$(CONFIG_INET) += inet.o
14422 +vserver-$(CONFIG_PROC_FS) += proc.o
14423 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
14424 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
14425 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
14426 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
14427 +
14428 diff -NurpP --minimal linux-4.4.115/kernel/vserver/cacct.c linux-4.4.115-vs2.3.9.7/kernel/vserver/cacct.c
14429 --- linux-4.4.115/kernel/vserver/cacct.c        1970-01-01 00:00:00.000000000 +0000
14430 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/cacct.c      2018-01-09 16:36:34.000000000 +0000
14431 @@ -0,0 +1,42 @@
14432 +/*
14433 + *  linux/kernel/vserver/cacct.c
14434 + *
14435 + *  Virtual Server: Context Accounting
14436 + *
14437 + *  Copyright (C) 2006-2007 Herbert Pötzl
14438 + *
14439 + *  V0.01  added accounting stats
14440 + *
14441 + */
14442 +
14443 +#include <linux/types.h>
14444 +#include <linux/vs_context.h>
14445 +#include <linux/vserver/cacct_cmd.h>
14446 +#include <linux/vserver/cacct_int.h>
14447 +
14448 +#include <asm/errno.h>
14449 +#include <asm/uaccess.h>
14450 +
14451 +
14452 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
14453 +{
14454 +       struct vcmd_sock_stat_v0 vc_data;
14455 +       int j, field;
14456 +
14457 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
14458 +               return -EFAULT;
14459 +
14460 +       field = vc_data.field;
14461 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
14462 +               return -EINVAL;
14463 +
14464 +       for (j = 0; j < 3; j++) {
14465 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
14466 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
14467 +       }
14468 +
14469 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
14470 +               return -EFAULT;
14471 +       return 0;
14472 +}
14473 +
14474 diff -NurpP --minimal linux-4.4.115/kernel/vserver/cacct_init.h linux-4.4.115-vs2.3.9.7/kernel/vserver/cacct_init.h
14475 --- linux-4.4.115/kernel/vserver/cacct_init.h   1970-01-01 00:00:00.000000000 +0000
14476 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/cacct_init.h 2018-01-09 16:36:34.000000000 +0000
14477 @@ -0,0 +1,25 @@
14478 +
14479 +
14480 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
14481 +{
14482 +       int i, j;
14483 +
14484 +
14485 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14486 +               for (j = 0; j < 3; j++) {
14487 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
14488 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
14489 +               }
14490 +       }
14491 +       for (i = 0; i < 8; i++)
14492 +               atomic_set(&cacct->slab[i], 0);
14493 +       for (i = 0; i < 5; i++)
14494 +               for (j = 0; j < 4; j++)
14495 +                       atomic_set(&cacct->page[i][j], 0);
14496 +}
14497 +
14498 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
14499 +{
14500 +       return;
14501 +}
14502 +
14503 diff -NurpP --minimal linux-4.4.115/kernel/vserver/cacct_proc.h linux-4.4.115-vs2.3.9.7/kernel/vserver/cacct_proc.h
14504 --- linux-4.4.115/kernel/vserver/cacct_proc.h   1970-01-01 00:00:00.000000000 +0000
14505 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/cacct_proc.h 2018-01-09 16:36:34.000000000 +0000
14506 @@ -0,0 +1,53 @@
14507 +#ifndef _VX_CACCT_PROC_H
14508 +#define _VX_CACCT_PROC_H
14509 +
14510 +#include <linux/vserver/cacct_int.h>
14511 +
14512 +
14513 +#define VX_SOCKA_TOP   \
14514 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
14515 +
14516 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
14517 +{
14518 +       int i, j, length = 0;
14519 +       static char *type[VXA_SOCK_SIZE] = {
14520 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
14521 +       };
14522 +
14523 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
14524 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14525 +               length += sprintf(buffer + length, "%s:", type[i]);
14526 +               for (j = 0; j < 3; j++) {
14527 +                       length += sprintf(buffer + length,
14528 +                               "\t%10lu/%-10lu",
14529 +                               vx_sock_count(cacct, i, j),
14530 +                               vx_sock_total(cacct, i, j));
14531 +               }
14532 +               buffer[length++] = '\n';
14533 +       }
14534 +
14535 +       length += sprintf(buffer + length, "\n");
14536 +       length += sprintf(buffer + length,
14537 +               "slab:\t %8u %8u %8u %8u\n",
14538 +               atomic_read(&cacct->slab[1]),
14539 +               atomic_read(&cacct->slab[4]),
14540 +               atomic_read(&cacct->slab[0]),
14541 +               atomic_read(&cacct->slab[2]));
14542 +
14543 +       length += sprintf(buffer + length, "\n");
14544 +       for (i = 0; i < 5; i++) {
14545 +               length += sprintf(buffer + length,
14546 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
14547 +                       atomic_read(&cacct->page[i][0]),
14548 +                       atomic_read(&cacct->page[i][1]),
14549 +                       atomic_read(&cacct->page[i][2]),
14550 +                       atomic_read(&cacct->page[i][3]),
14551 +                       atomic_read(&cacct->page[i][4]),
14552 +                       atomic_read(&cacct->page[i][5]),
14553 +                       atomic_read(&cacct->page[i][6]),
14554 +                       atomic_read(&cacct->page[i][7]));
14555 +       }
14556 +       return length;
14557 +}
14558 +
14559 +#endif /* _VX_CACCT_PROC_H */
14560 diff -NurpP --minimal linux-4.4.115/kernel/vserver/context.c linux-4.4.115-vs2.3.9.7/kernel/vserver/context.c
14561 --- linux-4.4.115/kernel/vserver/context.c      1970-01-01 00:00:00.000000000 +0000
14562 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/context.c    2018-01-09 16:36:34.000000000 +0000
14563 @@ -0,0 +1,1119 @@
14564 +/*
14565 + *  linux/kernel/vserver/context.c
14566 + *
14567 + *  Virtual Server: Context Support
14568 + *
14569 + *  Copyright (C) 2003-2011  Herbert Pötzl
14570 + *
14571 + *  V0.01  context helper
14572 + *  V0.02  vx_ctx_kill syscall command
14573 + *  V0.03  replaced context_info calls
14574 + *  V0.04  redesign of struct (de)alloc
14575 + *  V0.05  rlimit basic implementation
14576 + *  V0.06  task_xid and info commands
14577 + *  V0.07  context flags and caps
14578 + *  V0.08  switch to RCU based hash
14579 + *  V0.09  revert to non RCU for now
14580 + *  V0.10  and back to working RCU hash
14581 + *  V0.11  and back to locking again
14582 + *  V0.12  referenced context store
14583 + *  V0.13  separate per cpu data
14584 + *  V0.14  changed vcmds to vxi arg
14585 + *  V0.15  added context stat
14586 + *  V0.16  have __create claim() the vxi
14587 + *  V0.17  removed older and legacy stuff
14588 + *  V0.18  added user credentials
14589 + *  V0.19  added warn mask
14590 + *
14591 + */
14592 +
14593 +#include <linux/slab.h>
14594 +#include <linux/types.h>
14595 +#include <linux/security.h>
14596 +#include <linux/pid_namespace.h>
14597 +#include <linux/capability.h>
14598 +
14599 +#include <linux/vserver/context.h>
14600 +#include <linux/vserver/network.h>
14601 +#include <linux/vserver/debug.h>
14602 +#include <linux/vserver/limit.h>
14603 +#include <linux/vserver/limit_int.h>
14604 +#include <linux/vserver/space.h>
14605 +#include <linux/init_task.h>
14606 +#include <linux/fs_struct.h>
14607 +#include <linux/cred.h>
14608 +
14609 +#include <linux/vs_context.h>
14610 +#include <linux/vs_limit.h>
14611 +#include <linux/vs_pid.h>
14612 +#include <linux/vserver/context_cmd.h>
14613 +
14614 +#include "cvirt_init.h"
14615 +#include "cacct_init.h"
14616 +#include "limit_init.h"
14617 +#include "sched_init.h"
14618 +
14619 +
14620 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
14621 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
14622 +
14623 +
14624 +/*     now inactive context structures */
14625 +
14626 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
14627 +
14628 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
14629 +
14630 +
14631 +/*     __alloc_vx_info()
14632 +
14633 +       * allocate an initialized vx_info struct
14634 +       * doesn't make it visible (hash)                        */
14635 +
14636 +static struct vx_info *__alloc_vx_info(vxid_t xid)
14637 +{
14638 +       struct vx_info *new = NULL;
14639 +       int cpu, index;
14640 +
14641 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
14642 +
14643 +       /* would this benefit from a slab cache? */
14644 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
14645 +       if (!new)
14646 +               return 0;
14647 +
14648 +       memset(new, 0, sizeof(struct vx_info));
14649 +#ifdef CONFIG_SMP
14650 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
14651 +       if (!new->ptr_pc)
14652 +               goto error;
14653 +#endif
14654 +       new->vx_id = xid;
14655 +       INIT_HLIST_NODE(&new->vx_hlist);
14656 +       atomic_set(&new->vx_usecnt, 0);
14657 +       atomic_set(&new->vx_tasks, 0);
14658 +       new->vx_parent = NULL;
14659 +       new->vx_state = 0;
14660 +       init_waitqueue_head(&new->vx_wait);
14661 +
14662 +       /* prepare reaper */
14663 +       get_task_struct(init_pid_ns.child_reaper);
14664 +       new->vx_reaper = init_pid_ns.child_reaper;
14665 +       new->vx_badness_bias = 0;
14666 +
14667 +       /* rest of init goes here */
14668 +       vx_info_init_limit(&new->limit);
14669 +       vx_info_init_sched(&new->sched);
14670 +       vx_info_init_cvirt(&new->cvirt);
14671 +       vx_info_init_cacct(&new->cacct);
14672 +
14673 +       /* per cpu data structures */
14674 +       for_each_possible_cpu(cpu) {
14675 +               vx_info_init_sched_pc(
14676 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
14677 +               vx_info_init_cvirt_pc(
14678 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
14679 +       }
14680 +
14681 +       new->vx_flags = VXF_INIT_SET;
14682 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
14683 +       new->vx_ccaps = 0;
14684 +       new->vx_umask = 0;
14685 +       new->vx_wmask = 0;
14686 +
14687 +       new->reboot_cmd = 0;
14688 +       new->exit_code = 0;
14689 +
14690 +       // preconfig spaces
14691 +       for (index = 0; index < VX_SPACES; index++) {
14692 +               struct _vx_space *space = &new->space[index];
14693 +
14694 +               // filesystem
14695 +               spin_lock(&init_fs.lock);
14696 +               init_fs.users++;
14697 +               spin_unlock(&init_fs.lock);
14698 +               space->vx_fs = &init_fs;
14699 +
14700 +               /* FIXME: do we want defaults? */
14701 +               // space->vx_real_cred = 0;
14702 +               // space->vx_cred = 0;
14703 +       }
14704 +
14705 +
14706 +       vxdprintk(VXD_CBIT(xid, 0),
14707 +               "alloc_vx_info(%d) = %p", xid, new);
14708 +       vxh_alloc_vx_info(new);
14709 +       atomic_inc(&vx_global_ctotal);
14710 +       return new;
14711 +#ifdef CONFIG_SMP
14712 +error:
14713 +       kfree(new);
14714 +       return 0;
14715 +#endif
14716 +}
14717 +
14718 +/*     __dealloc_vx_info()
14719 +
14720 +       * final disposal of vx_info                             */
14721 +
14722 +static void __dealloc_vx_info(struct vx_info *vxi)
14723 +{
14724 +#ifdef CONFIG_VSERVER_WARN
14725 +       struct vx_info_save vxis;
14726 +       int cpu;
14727 +#endif
14728 +       vxdprintk(VXD_CBIT(xid, 0),
14729 +               "dealloc_vx_info(%p)", vxi);
14730 +       vxh_dealloc_vx_info(vxi);
14731 +
14732 +#ifdef CONFIG_VSERVER_WARN
14733 +       enter_vx_info(vxi, &vxis);
14734 +       vx_info_exit_limit(&vxi->limit);
14735 +       vx_info_exit_sched(&vxi->sched);
14736 +       vx_info_exit_cvirt(&vxi->cvirt);
14737 +       vx_info_exit_cacct(&vxi->cacct);
14738 +
14739 +       for_each_possible_cpu(cpu) {
14740 +               vx_info_exit_sched_pc(
14741 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
14742 +               vx_info_exit_cvirt_pc(
14743 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
14744 +       }
14745 +       leave_vx_info(&vxis);
14746 +#endif
14747 +
14748 +       vxi->vx_id = -1;
14749 +       vxi->vx_state |= VXS_RELEASED;
14750 +
14751 +#ifdef CONFIG_SMP
14752 +       free_percpu(vxi->ptr_pc);
14753 +#endif
14754 +       kfree(vxi);
14755 +       atomic_dec(&vx_global_ctotal);
14756 +}
14757 +
14758 +static void __shutdown_vx_info(struct vx_info *vxi)
14759 +{
14760 +       struct nsproxy *nsproxy;
14761 +       struct fs_struct *fs;
14762 +       struct cred *cred;
14763 +       int index, kill;
14764 +
14765 +       might_sleep();
14766 +
14767 +       vxi->vx_state |= VXS_SHUTDOWN;
14768 +       vs_state_change(vxi, VSC_SHUTDOWN);
14769 +
14770 +       for (index = 0; index < VX_SPACES; index++) {
14771 +               struct _vx_space *space = &vxi->space[index];
14772 +
14773 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
14774 +               if (nsproxy)
14775 +                       put_nsproxy(nsproxy);
14776 +
14777 +               fs = xchg(&space->vx_fs, NULL);
14778 +               spin_lock(&fs->lock);
14779 +               kill = !--fs->users;
14780 +               spin_unlock(&fs->lock);
14781 +               if (kill)
14782 +                       free_fs_struct(fs);
14783 +
14784 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
14785 +               if (cred)
14786 +                       abort_creds(cred);
14787 +       }
14788 +}
14789 +
14790 +/* exported stuff */
14791 +
14792 +void free_vx_info(struct vx_info *vxi)
14793 +{
14794 +       unsigned long flags;
14795 +       unsigned index;
14796 +
14797 +       /* check for reference counts first */
14798 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
14799 +       BUG_ON(atomic_read(&vxi->vx_tasks));
14800 +
14801 +       /* context must not be hashed */
14802 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
14803 +
14804 +       /* context shutdown is mandatory */
14805 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
14806 +
14807 +       /* spaces check */
14808 +       for (index = 0; index < VX_SPACES; index++) {
14809 +               struct _vx_space *space = &vxi->space[index];
14810 +
14811 +               BUG_ON(space->vx_nsproxy);
14812 +               BUG_ON(space->vx_fs);
14813 +               // BUG_ON(space->vx_real_cred);
14814 +               // BUG_ON(space->vx_cred);
14815 +       }
14816 +
14817 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
14818 +       hlist_del(&vxi->vx_hlist);
14819 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
14820 +
14821 +       __dealloc_vx_info(vxi);
14822 +}
14823 +
14824 +
14825 +/*     hash table for vx_info hash */
14826 +
14827 +#define VX_HASH_SIZE   13
14828 +
14829 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
14830 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
14831 +
14832 +static DEFINE_SPINLOCK(vx_info_hash_lock);
14833 +
14834 +
14835 +static inline unsigned int __hashval(vxid_t xid)
14836 +{
14837 +       return (xid % VX_HASH_SIZE);
14838 +}
14839 +
14840 +
14841 +
14842 +/*     __hash_vx_info()
14843 +
14844 +       * add the vxi to the global hash table
14845 +       * requires the hash_lock to be held                     */
14846 +
14847 +static inline void __hash_vx_info(struct vx_info *vxi)
14848 +{
14849 +       struct hlist_head *head;
14850 +
14851 +       vxd_assert_lock(&vx_info_hash_lock);
14852 +       vxdprintk(VXD_CBIT(xid, 4),
14853 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
14854 +       vxh_hash_vx_info(vxi);
14855 +
14856 +       /* context must not be hashed */
14857 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
14858 +
14859 +       vxi->vx_state |= VXS_HASHED;
14860 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
14861 +       hlist_add_head(&vxi->vx_hlist, head);
14862 +       atomic_inc(&vx_global_cactive);
14863 +}
14864 +
14865 +/*     __unhash_vx_info()
14866 +
14867 +       * remove the vxi from the global hash table
14868 +       * requires the hash_lock to be held                     */
14869 +
14870 +static inline void __unhash_vx_info(struct vx_info *vxi)
14871 +{
14872 +       unsigned long flags;
14873 +
14874 +       vxd_assert_lock(&vx_info_hash_lock);
14875 +       vxdprintk(VXD_CBIT(xid, 4),
14876 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
14877 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
14878 +       vxh_unhash_vx_info(vxi);
14879 +
14880 +       /* context must be hashed */
14881 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
14882 +       /* but without tasks */
14883 +       BUG_ON(atomic_read(&vxi->vx_tasks));
14884 +
14885 +       vxi->vx_state &= ~VXS_HASHED;
14886 +       hlist_del_init(&vxi->vx_hlist);
14887 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
14888 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
14889 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
14890 +       atomic_dec(&vx_global_cactive);
14891 +}
14892 +
14893 +
14894 +/*     __lookup_vx_info()
14895 +
14896 +       * requires the hash_lock to be held
14897 +       * doesn't increment the vx_refcnt                       */
14898 +
14899 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
14900 +{
14901 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
14902 +       struct hlist_node *pos;
14903 +       struct vx_info *vxi;
14904 +
14905 +       vxd_assert_lock(&vx_info_hash_lock);
14906 +       hlist_for_each(pos, head) {
14907 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
14908 +
14909 +               if (vxi->vx_id == xid)
14910 +                       goto found;
14911 +       }
14912 +       vxi = NULL;
14913 +found:
14914 +       vxdprintk(VXD_CBIT(xid, 0),
14915 +               "__lookup_vx_info(#%u): %p[#%u]",
14916 +               xid, vxi, vxi ? vxi->vx_id : 0);
14917 +       vxh_lookup_vx_info(vxi, xid);
14918 +       return vxi;
14919 +}
14920 +
14921 +
14922 +/*     __create_vx_info()
14923 +
14924 +       * create the requested context
14925 +       * get(), claim() and hash it                            */
14926 +
14927 +static struct vx_info *__create_vx_info(int id)
14928 +{
14929 +       struct vx_info *new, *vxi = NULL;
14930 +
14931 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
14932 +
14933 +       if (!(new = __alloc_vx_info(id)))
14934 +               return ERR_PTR(-ENOMEM);
14935 +
14936 +       /* required to make dynamic xids unique */
14937 +       spin_lock(&vx_info_hash_lock);
14938 +
14939 +       /* static context requested */
14940 +       if ((vxi = __lookup_vx_info(id))) {
14941 +               vxdprintk(VXD_CBIT(xid, 0),
14942 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
14943 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
14944 +                       vxi = ERR_PTR(-EBUSY);
14945 +               else
14946 +                       vxi = ERR_PTR(-EEXIST);
14947 +               goto out_unlock;
14948 +       }
14949 +       /* new context */
14950 +       vxdprintk(VXD_CBIT(xid, 0),
14951 +               "create_vx_info(%d) = %p (new)", id, new);
14952 +       claim_vx_info(new, NULL);
14953 +       __hash_vx_info(get_vx_info(new));
14954 +       vxi = new, new = NULL;
14955 +
14956 +out_unlock:
14957 +       spin_unlock(&vx_info_hash_lock);
14958 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
14959 +       if (new)
14960 +               __dealloc_vx_info(new);
14961 +       return vxi;
14962 +}
14963 +
14964 +
14965 +/*     exported stuff                                          */
14966 +
14967 +
14968 +void unhash_vx_info(struct vx_info *vxi)
14969 +{
14970 +       spin_lock(&vx_info_hash_lock);
14971 +       __unhash_vx_info(vxi);
14972 +       spin_unlock(&vx_info_hash_lock);
14973 +       __shutdown_vx_info(vxi);
14974 +       __wakeup_vx_info(vxi);
14975 +}
14976 +
14977 +
14978 +/*     lookup_vx_info()
14979 +
14980 +       * search for a vx_info and get() it
14981 +       * negative id means current                             */
14982 +
14983 +struct vx_info *lookup_vx_info(int id)
14984 +{
14985 +       struct vx_info *vxi = NULL;
14986 +
14987 +       if (id < 0) {
14988 +               vxi = get_vx_info(current_vx_info());
14989 +       } else if (id > 1) {
14990 +               spin_lock(&vx_info_hash_lock);
14991 +               vxi = get_vx_info(__lookup_vx_info(id));
14992 +               spin_unlock(&vx_info_hash_lock);
14993 +       }
14994 +       return vxi;
14995 +}
14996 +
14997 +/*     xid_is_hashed()
14998 +
14999 +       * verify that xid is still hashed                       */
15000 +
15001 +int xid_is_hashed(vxid_t xid)
15002 +{
15003 +       int hashed;
15004 +
15005 +       spin_lock(&vx_info_hash_lock);
15006 +       hashed = (__lookup_vx_info(xid) != NULL);
15007 +       spin_unlock(&vx_info_hash_lock);
15008 +       return hashed;
15009 +}
15010 +
15011 +#ifdef CONFIG_PROC_FS
15012 +
15013 +/*     get_xid_list()
15014 +
15015 +       * get a subset of hashed xids for proc
15016 +       * assumes size is at least one                          */
15017 +
15018 +int get_xid_list(int index, unsigned int *xids, int size)
15019 +{
15020 +       int hindex, nr_xids = 0;
15021 +
15022 +       /* only show current and children */
15023 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15024 +               if (index > 0)
15025 +                       return 0;
15026 +               xids[nr_xids] = vx_current_xid();
15027 +               return 1;
15028 +       }
15029 +
15030 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15031 +               struct hlist_head *head = &vx_info_hash[hindex];
15032 +               struct hlist_node *pos;
15033 +
15034 +               spin_lock(&vx_info_hash_lock);
15035 +               hlist_for_each(pos, head) {
15036 +                       struct vx_info *vxi;
15037 +
15038 +                       if (--index > 0)
15039 +                               continue;
15040 +
15041 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15042 +                       xids[nr_xids] = vxi->vx_id;
15043 +                       if (++nr_xids >= size) {
15044 +                               spin_unlock(&vx_info_hash_lock);
15045 +                               goto out;
15046 +                       }
15047 +               }
15048 +               /* keep the lock time short */
15049 +               spin_unlock(&vx_info_hash_lock);
15050 +       }
15051 +out:
15052 +       return nr_xids;
15053 +}
15054 +#endif
15055 +
15056 +#ifdef CONFIG_VSERVER_DEBUG
15057 +
15058 +void   dump_vx_info_inactive(int level)
15059 +{
15060 +       struct hlist_node *entry, *next;
15061 +
15062 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
15063 +               struct vx_info *vxi =
15064 +                       list_entry(entry, struct vx_info, vx_hlist);
15065 +
15066 +               dump_vx_info(vxi, level);
15067 +       }
15068 +}
15069 +
15070 +#endif
15071 +
15072 +#if 0
15073 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
15074 +{
15075 +       struct user_struct *new_user, *old_user;
15076 +
15077 +       if (!p || !vxi)
15078 +               BUG();
15079 +
15080 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
15081 +               return -EACCES;
15082 +
15083 +       new_user = alloc_uid(vxi->vx_id, p->uid);
15084 +       if (!new_user)
15085 +               return -ENOMEM;
15086 +
15087 +       old_user = p->user;
15088 +       if (new_user != old_user) {
15089 +               atomic_inc(&new_user->processes);
15090 +               atomic_dec(&old_user->processes);
15091 +               p->user = new_user;
15092 +       }
15093 +       free_uid(old_user);
15094 +       return 0;
15095 +}
15096 +#endif
15097 +
15098 +#if 0
15099 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
15100 +{
15101 +       // p->cap_effective &= vxi->vx_cap_bset;
15102 +       p->cap_effective =
15103 +               cap_intersect(p->cap_effective, vxi->cap_bset);
15104 +       // p->cap_inheritable &= vxi->vx_cap_bset;
15105 +       p->cap_inheritable =
15106 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
15107 +       // p->cap_permitted &= vxi->vx_cap_bset;
15108 +       p->cap_permitted =
15109 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
15110 +}
15111 +#endif
15112 +
15113 +
15114 +#include <linux/file.h>
15115 +#include <linux/fdtable.h>
15116 +
15117 +static int vx_openfd_task(struct task_struct *tsk)
15118 +{
15119 +       struct files_struct *files = tsk->files;
15120 +       struct fdtable *fdt;
15121 +       const unsigned long *bptr;
15122 +       int count, total;
15123 +
15124 +       /* no rcu_read_lock() because of spin_lock() */
15125 +       spin_lock(&files->file_lock);
15126 +       fdt = files_fdtable(files);
15127 +       bptr = fdt->open_fds;
15128 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
15129 +       for (total = 0; count > 0; count--) {
15130 +               if (*bptr)
15131 +                       total += hweight_long(*bptr);
15132 +               bptr++;
15133 +       }
15134 +       spin_unlock(&files->file_lock);
15135 +       return total;
15136 +}
15137 +
15138 +
15139 +/*     for *space compatibility */
15140 +
15141 +asmlinkage long sys_unshare(unsigned long);
15142 +
15143 +/*
15144 + *     migrate task to new context
15145 + *     gets vxi, puts old_vxi on change
15146 + *     optionally unshares namespaces (hack)
15147 + */
15148 +
15149 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
15150 +{
15151 +       struct vx_info *old_vxi;
15152 +       int ret = 0;
15153 +
15154 +       if (!p || !vxi)
15155 +               BUG();
15156 +
15157 +       vxdprintk(VXD_CBIT(xid, 5),
15158 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
15159 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
15160 +
15161 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
15162 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15163 +               return -EACCES;
15164 +
15165 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
15166 +               return -EFAULT;
15167 +
15168 +       old_vxi = task_get_vx_info(p);
15169 +       if (old_vxi == vxi)
15170 +               goto out;
15171 +
15172 +//     if (!(ret = vx_migrate_user(p, vxi))) {
15173 +       {
15174 +               int openfd;
15175 +
15176 +               task_lock(p);
15177 +               openfd = vx_openfd_task(p);
15178 +
15179 +               if (old_vxi) {
15180 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
15181 +                       atomic_dec(&old_vxi->cvirt.nr_running);
15182 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
15183 +                       /* FIXME: what about the struct files here? */
15184 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
15185 +                       /* account for the executable */
15186 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
15187 +               }
15188 +               atomic_inc(&vxi->cvirt.nr_threads);
15189 +               atomic_inc(&vxi->cvirt.nr_running);
15190 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
15191 +               /* FIXME: what about the struct files here? */
15192 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
15193 +               /* account for the executable */
15194 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
15195 +
15196 +               if (old_vxi) {
15197 +                       release_vx_info(old_vxi, p);
15198 +                       clr_vx_info(&p->vx_info);
15199 +               }
15200 +               claim_vx_info(vxi, p);
15201 +               set_vx_info(&p->vx_info, vxi);
15202 +               p->xid = vxi->vx_id;
15203 +
15204 +               vxdprintk(VXD_CBIT(xid, 5),
15205 +                       "moved task %p into vxi:%p[#%d]",
15206 +                       p, vxi, vxi->vx_id);
15207 +
15208 +               // vx_mask_cap_bset(vxi, p);
15209 +               task_unlock(p);
15210 +
15211 +               /* hack for *spaces to provide compatibility */
15212 +               if (unshare) {
15213 +                       struct nsproxy *old_nsp, *new_nsp;
15214 +
15215 +                       ret = unshare_nsproxy_namespaces(
15216 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
15217 +                               &new_nsp, NULL, NULL);
15218 +                       if (ret)
15219 +                               goto out;
15220 +
15221 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
15222 +                       vx_set_space(vxi,
15223 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
15224 +                       put_nsproxy(old_nsp);
15225 +               }
15226 +       }
15227 +out:
15228 +       put_vx_info(old_vxi);
15229 +       return ret;
15230 +}
15231 +
15232 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
15233 +{
15234 +       struct task_struct *old_reaper;
15235 +       struct vx_info *reaper_vxi;
15236 +
15237 +       if (!vxi)
15238 +               return -EINVAL;
15239 +
15240 +       vxdprintk(VXD_CBIT(xid, 6),
15241 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
15242 +               vxi, vxi->vx_id, p, p->xid, p->pid);
15243 +
15244 +       old_reaper = vxi->vx_reaper;
15245 +       if (old_reaper == p)
15246 +               return 0;
15247 +
15248 +       reaper_vxi = task_get_vx_info(p);
15249 +       if (reaper_vxi && reaper_vxi != vxi) {
15250 +               vxwprintk(1,
15251 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
15252 +                       "for [xid #%u]",
15253 +                       p->comm, p->pid, p->xid, vx_current_xid());
15254 +               goto out;
15255 +       }
15256 +
15257 +       /* set new child reaper */
15258 +       get_task_struct(p);
15259 +       vxi->vx_reaper = p;
15260 +       put_task_struct(old_reaper);
15261 +out:
15262 +       put_vx_info(reaper_vxi);
15263 +       return 0;
15264 +}
15265 +
15266 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
15267 +{
15268 +       if (!vxi)
15269 +               return -EINVAL;
15270 +
15271 +       vxdprintk(VXD_CBIT(xid, 6),
15272 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
15273 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15274 +
15275 +       vxi->vx_flags &= ~VXF_STATE_INIT;
15276 +       // vxi->vx_initpid = p->tgid;
15277 +       vxi->vx_initpid = p->pid;
15278 +       return 0;
15279 +}
15280 +
15281 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
15282 +{
15283 +       vxdprintk(VXD_CBIT(xid, 6),
15284 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
15285 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15286 +
15287 +       vxi->exit_code = code;
15288 +       vxi->vx_initpid = 0;
15289 +}
15290 +
15291 +
15292 +void vx_set_persistent(struct vx_info *vxi)
15293 +{
15294 +       vxdprintk(VXD_CBIT(xid, 6),
15295 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
15296 +
15297 +       get_vx_info(vxi);
15298 +       claim_vx_info(vxi, NULL);
15299 +}
15300 +
15301 +void vx_clear_persistent(struct vx_info *vxi)
15302 +{
15303 +       vxdprintk(VXD_CBIT(xid, 6),
15304 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
15305 +
15306 +       release_vx_info(vxi, NULL);
15307 +       put_vx_info(vxi);
15308 +}
15309 +
15310 +void vx_update_persistent(struct vx_info *vxi)
15311 +{
15312 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
15313 +               vx_set_persistent(vxi);
15314 +       else
15315 +               vx_clear_persistent(vxi);
15316 +}
15317 +
15318 +
15319 +/*     task must be current or locked          */
15320 +
15321 +void   exit_vx_info(struct task_struct *p, int code)
15322 +{
15323 +       struct vx_info *vxi = p->vx_info;
15324 +
15325 +       if (vxi) {
15326 +               atomic_dec(&vxi->cvirt.nr_threads);
15327 +               vx_nproc_dec(p);
15328 +
15329 +               vxi->exit_code = code;
15330 +               release_vx_info(vxi, p);
15331 +       }
15332 +}
15333 +
15334 +void   exit_vx_info_early(struct task_struct *p, int code)
15335 +{
15336 +       struct vx_info *vxi = p->vx_info;
15337 +
15338 +       if (vxi) {
15339 +               if (vxi->vx_initpid == p->pid)
15340 +                       vx_exit_init(vxi, p, code);
15341 +               if (vxi->vx_reaper == p)
15342 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
15343 +       }
15344 +}
15345 +
15346 +
15347 +/* vserver syscall commands below here */
15348 +
15349 +/* taks xid and vx_info functions */
15350 +
15351 +#include <asm/uaccess.h>
15352 +
15353 +
15354 +int vc_task_xid(uint32_t id)
15355 +{
15356 +       vxid_t xid;
15357 +
15358 +       if (id) {
15359 +               struct task_struct *tsk;
15360 +
15361 +               rcu_read_lock();
15362 +               tsk = find_task_by_real_pid(id);
15363 +               xid = (tsk) ? tsk->xid : -ESRCH;
15364 +               rcu_read_unlock();
15365 +       } else
15366 +               xid = vx_current_xid();
15367 +       return xid;
15368 +}
15369 +
15370 +
15371 +int vc_vx_info(struct vx_info *vxi, void __user *data)
15372 +{
15373 +       struct vcmd_vx_info_v0 vc_data;
15374 +
15375 +       vc_data.xid = vxi->vx_id;
15376 +       vc_data.initpid = vxi->vx_initpid;
15377 +
15378 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15379 +               return -EFAULT;
15380 +       return 0;
15381 +}
15382 +
15383 +
15384 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
15385 +{
15386 +       struct vcmd_ctx_stat_v0 vc_data;
15387 +
15388 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
15389 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
15390 +
15391 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15392 +               return -EFAULT;
15393 +       return 0;
15394 +}
15395 +
15396 +
15397 +/* context functions */
15398 +
15399 +int vc_ctx_create(uint32_t xid, void __user *data)
15400 +{
15401 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
15402 +       struct vx_info *new_vxi;
15403 +       int ret;
15404 +
15405 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15406 +               return -EFAULT;
15407 +
15408 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
15409 +               return -EINVAL;
15410 +
15411 +       new_vxi = __create_vx_info(xid);
15412 +       if (IS_ERR(new_vxi))
15413 +               return PTR_ERR(new_vxi);
15414 +
15415 +       /* initial flags */
15416 +       new_vxi->vx_flags = vc_data.flagword;
15417 +
15418 +       ret = -ENOEXEC;
15419 +       if (vs_state_change(new_vxi, VSC_STARTUP))
15420 +               goto out;
15421 +
15422 +       ret = vx_migrate_task(current, new_vxi, (!data));
15423 +       if (ret)
15424 +               goto out;
15425 +
15426 +       /* return context id on success */
15427 +       ret = new_vxi->vx_id;
15428 +
15429 +       /* get a reference for persistent contexts */
15430 +       if ((vc_data.flagword & VXF_PERSISTENT))
15431 +               vx_set_persistent(new_vxi);
15432 +out:
15433 +       release_vx_info(new_vxi, NULL);
15434 +       put_vx_info(new_vxi);
15435 +       return ret;
15436 +}
15437 +
15438 +
15439 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
15440 +{
15441 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
15442 +       int ret;
15443 +
15444 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15445 +               return -EFAULT;
15446 +
15447 +       ret = vx_migrate_task(current, vxi, 0);
15448 +       if (ret)
15449 +               return ret;
15450 +       if (vc_data.flagword & VXM_SET_INIT)
15451 +               ret = vx_set_init(vxi, current);
15452 +       if (ret)
15453 +               return ret;
15454 +       if (vc_data.flagword & VXM_SET_REAPER)
15455 +               ret = vx_set_reaper(vxi, current);
15456 +       return ret;
15457 +}
15458 +
15459 +
15460 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
15461 +{
15462 +       struct vcmd_ctx_flags_v0 vc_data;
15463 +
15464 +       vc_data.flagword = vxi->vx_flags;
15465 +
15466 +       /* special STATE flag handling */
15467 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
15468 +
15469 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15470 +               return -EFAULT;
15471 +       return 0;
15472 +}
15473 +
15474 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
15475 +{
15476 +       struct vcmd_ctx_flags_v0 vc_data;
15477 +       uint64_t mask, trigger;
15478 +
15479 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15480 +               return -EFAULT;
15481 +
15482 +       /* special STATE flag handling */
15483 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
15484 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
15485 +
15486 +       if (vxi == current_vx_info()) {
15487 +               /* if (trigger & VXF_STATE_SETUP)
15488 +                       vx_mask_cap_bset(vxi, current); */
15489 +               if (trigger & VXF_STATE_INIT) {
15490 +                       int ret;
15491 +
15492 +                       ret = vx_set_init(vxi, current);
15493 +                       if (ret)
15494 +                               return ret;
15495 +                       ret = vx_set_reaper(vxi, current);
15496 +                       if (ret)
15497 +                               return ret;
15498 +               }
15499 +       }
15500 +
15501 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
15502 +               vc_data.flagword, mask);
15503 +       if (trigger & VXF_PERSISTENT)
15504 +               vx_update_persistent(vxi);
15505 +
15506 +       return 0;
15507 +}
15508 +
15509 +
15510 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
15511 +{
15512 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
15513 +
15514 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
15515 +       return v;
15516 +}
15517 +
15518 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
15519 +{
15520 +       kernel_cap_t c = __cap_empty_set;
15521 +
15522 +       c.cap[0] = v & 0xFFFFFFFF;
15523 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
15524 +
15525 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
15526 +       return c;
15527 +}
15528 +
15529 +
15530 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
15531 +{
15532 +       if (bcaps)
15533 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
15534 +       if (ccaps)
15535 +               *ccaps = vxi->vx_ccaps;
15536 +
15537 +       return 0;
15538 +}
15539 +
15540 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
15541 +{
15542 +       struct vcmd_ctx_caps_v1 vc_data;
15543 +       int ret;
15544 +
15545 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
15546 +       if (ret)
15547 +               return ret;
15548 +       vc_data.cmask = ~0ULL;
15549 +
15550 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15551 +               return -EFAULT;
15552 +       return 0;
15553 +}
15554 +
15555 +static int do_set_caps(struct vx_info *vxi,
15556 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
15557 +{
15558 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
15559 +
15560 +#if 0
15561 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
15562 +               bcaps, bmask, ccaps, cmask);
15563 +#endif
15564 +       vxi->vx_bcaps = cap_t_from_caps(
15565 +               vs_mask_flags(bcold, bcaps, bmask));
15566 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
15567 +
15568 +       return 0;
15569 +}
15570 +
15571 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
15572 +{
15573 +       struct vcmd_ctx_caps_v1 vc_data;
15574 +
15575 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15576 +               return -EFAULT;
15577 +
15578 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
15579 +}
15580 +
15581 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
15582 +{
15583 +       struct vcmd_bcaps vc_data;
15584 +       int ret;
15585 +
15586 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
15587 +       if (ret)
15588 +               return ret;
15589 +       vc_data.bmask = ~0ULL;
15590 +
15591 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15592 +               return -EFAULT;
15593 +       return 0;
15594 +}
15595 +
15596 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
15597 +{
15598 +       struct vcmd_bcaps vc_data;
15599 +
15600 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15601 +               return -EFAULT;
15602 +
15603 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
15604 +}
15605 +
15606 +
15607 +int vc_get_umask(struct vx_info *vxi, void __user *data)
15608 +{
15609 +       struct vcmd_umask vc_data;
15610 +
15611 +       vc_data.umask = vxi->vx_umask;
15612 +       vc_data.mask = ~0ULL;
15613 +
15614 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15615 +               return -EFAULT;
15616 +       return 0;
15617 +}
15618 +
15619 +int vc_set_umask(struct vx_info *vxi, void __user *data)
15620 +{
15621 +       struct vcmd_umask vc_data;
15622 +
15623 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15624 +               return -EFAULT;
15625 +
15626 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
15627 +               vc_data.umask, vc_data.mask);
15628 +       return 0;
15629 +}
15630 +
15631 +
15632 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
15633 +{
15634 +       struct vcmd_wmask vc_data;
15635 +
15636 +       vc_data.wmask = vxi->vx_wmask;
15637 +       vc_data.mask = ~0ULL;
15638 +
15639 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15640 +               return -EFAULT;
15641 +       return 0;
15642 +}
15643 +
15644 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
15645 +{
15646 +       struct vcmd_wmask vc_data;
15647 +
15648 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15649 +               return -EFAULT;
15650 +
15651 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
15652 +               vc_data.wmask, vc_data.mask);
15653 +       return 0;
15654 +}
15655 +
15656 +
15657 +int vc_get_badness(struct vx_info *vxi, void __user *data)
15658 +{
15659 +       struct vcmd_badness_v0 vc_data;
15660 +
15661 +       vc_data.bias = vxi->vx_badness_bias;
15662 +
15663 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15664 +               return -EFAULT;
15665 +       return 0;
15666 +}
15667 +
15668 +int vc_set_badness(struct vx_info *vxi, void __user *data)
15669 +{
15670 +       struct vcmd_badness_v0 vc_data;
15671 +
15672 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15673 +               return -EFAULT;
15674 +
15675 +       vxi->vx_badness_bias = vc_data.bias;
15676 +       return 0;
15677 +}
15678 +
15679 +#include <linux/module.h>
15680 +
15681 +EXPORT_SYMBOL_GPL(free_vx_info);
15682 +
15683 diff -NurpP --minimal linux-4.4.115/kernel/vserver/cvirt.c linux-4.4.115-vs2.3.9.7/kernel/vserver/cvirt.c
15684 --- linux-4.4.115/kernel/vserver/cvirt.c        1970-01-01 00:00:00.000000000 +0000
15685 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/cvirt.c      2018-01-09 22:27:39.000000000 +0000
15686 @@ -0,0 +1,313 @@
15687 +/*
15688 + *  linux/kernel/vserver/cvirt.c
15689 + *
15690 + *  Virtual Server: Context Virtualization
15691 + *
15692 + *  Copyright (C) 2004-2007  Herbert Pötzl
15693 + *
15694 + *  V0.01  broken out from limit.c
15695 + *  V0.02  added utsname stuff
15696 + *  V0.03  changed vcmds to vxi arg
15697 + *
15698 + */
15699 +
15700 +#include <linux/types.h>
15701 +#include <linux/utsname.h>
15702 +#include <linux/vs_cvirt.h>
15703 +#include <linux/vserver/switch.h>
15704 +#include <linux/vserver/cvirt_cmd.h>
15705 +
15706 +#include <asm/uaccess.h>
15707 +
15708 +
15709 +void vx_vsi_boottime(struct timespec *boottime)
15710 +{
15711 +       struct vx_info *vxi = current_vx_info();
15712 +
15713 +       set_normalized_timespec(boottime,
15714 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
15715 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
15716 +       return;
15717 +}
15718 +
15719 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
15720 +{
15721 +       struct vx_info *vxi = current_vx_info();
15722 +
15723 +       set_normalized_timespec(uptime,
15724 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
15725 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
15726 +       if (!idle)
15727 +               return;
15728 +       set_normalized_timespec(idle,
15729 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
15730 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
15731 +       return;
15732 +}
15733 +
15734 +uint64_t vx_idle_jiffies(void)
15735 +{
15736 +       return init_task.utime + init_task.stime;
15737 +}
15738 +
15739 +
15740 +
15741 +static inline uint32_t __update_loadavg(uint32_t load,
15742 +       int wsize, int delta, int n)
15743 +{
15744 +       unsigned long long calc, prev;
15745 +
15746 +       /* just set it to n */
15747 +       if (unlikely(delta >= wsize))
15748 +               return (n << FSHIFT);
15749 +
15750 +       calc = delta * n;
15751 +       calc <<= FSHIFT;
15752 +       prev = (wsize - delta);
15753 +       prev *= load;
15754 +       calc += prev;
15755 +       do_div(calc, wsize);
15756 +       return calc;
15757 +}
15758 +
15759 +
15760 +void vx_update_load(struct vx_info *vxi)
15761 +{
15762 +       uint32_t now, last, delta;
15763 +       unsigned int nr_running, nr_uninterruptible;
15764 +       unsigned int total;
15765 +       unsigned long flags;
15766 +
15767 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
15768 +
15769 +       now = jiffies;
15770 +       last = vxi->cvirt.load_last;
15771 +       delta = now - last;
15772 +
15773 +       if (delta < 5*HZ)
15774 +               goto out;
15775 +
15776 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
15777 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
15778 +       total = nr_running + nr_uninterruptible;
15779 +
15780 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
15781 +               60*HZ, delta, total);
15782 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
15783 +               5*60*HZ, delta, total);
15784 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
15785 +               15*60*HZ, delta, total);
15786 +
15787 +       vxi->cvirt.load_last = now;
15788 +out:
15789 +       atomic_inc(&vxi->cvirt.load_updates);
15790 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
15791 +}
15792 +
15793 +
15794 +/*
15795 + * Commands to do_syslog:
15796 + *
15797 + *      0 -- Close the log.  Currently a NOP.
15798 + *      1 -- Open the log. Currently a NOP.
15799 + *      2 -- Read from the log.
15800 + *      3 -- Read all messages remaining in the ring buffer.
15801 + *      4 -- Read and clear all messages remaining in the ring buffer
15802 + *      5 -- Clear ring buffer.
15803 + *      6 -- Disable printk's to console
15804 + *      7 -- Enable printk's to console
15805 + *      8 -- Set level of messages printed to console
15806 + *      9 -- Return number of unread characters in the log buffer
15807 + *     10 -- Return size of the log buffer
15808 + */
15809 +int vx_do_syslog(int type, char __user *buf, int len)
15810 +{
15811 +       int error = 0;
15812 +       int do_clear = 0;
15813 +       struct vx_info *vxi = current_vx_info();
15814 +       struct _vx_syslog *log;
15815 +
15816 +       if (!vxi)
15817 +               return -EINVAL;
15818 +       log = &vxi->cvirt.syslog;
15819 +
15820 +       switch (type) {
15821 +       case 0:         /* Close log */
15822 +       case 1:         /* Open log */
15823 +               break;
15824 +       case 2:         /* Read from log */
15825 +               error = wait_event_interruptible(log->log_wait,
15826 +                       (log->log_start - log->log_end));
15827 +               if (error)
15828 +                       break;
15829 +               spin_lock_irq(&log->logbuf_lock);
15830 +               spin_unlock_irq(&log->logbuf_lock);
15831 +               break;
15832 +       case 4:         /* Read/clear last kernel messages */
15833 +               do_clear = 1;
15834 +               /* fall through */
15835 +       case 3:         /* Read last kernel messages */
15836 +               return 0;
15837 +
15838 +       case 5:         /* Clear ring buffer */
15839 +               return 0;
15840 +
15841 +       case 6:         /* Disable logging to console */
15842 +       case 7:         /* Enable logging to console */
15843 +       case 8:         /* Set level of messages printed to console */
15844 +               break;
15845 +
15846 +       case 9:         /* Number of chars in the log buffer */
15847 +               return 0;
15848 +       case 10:        /* Size of the log buffer */
15849 +               return 0;
15850 +       default:
15851 +               error = -EINVAL;
15852 +               break;
15853 +       }
15854 +       return error;
15855 +}
15856 +
15857 +
15858 +/* virtual host info names */
15859 +
15860 +static char *vx_vhi_name(struct vx_info *vxi, int id)
15861 +{
15862 +       struct nsproxy *nsproxy;
15863 +       struct uts_namespace *uts;
15864 +
15865 +       if (id == VHIN_CONTEXT)
15866 +               return vxi->vx_name;
15867 +
15868 +       nsproxy = vxi->space[0].vx_nsproxy;
15869 +       if (!nsproxy)
15870 +               return NULL;
15871 +
15872 +       uts = nsproxy->uts_ns;
15873 +       if (!uts)
15874 +               return NULL;
15875 +
15876 +       switch (id) {
15877 +       case VHIN_SYSNAME:
15878 +               return uts->name.sysname;
15879 +       case VHIN_NODENAME:
15880 +               return uts->name.nodename;
15881 +       case VHIN_RELEASE:
15882 +               return uts->name.release;
15883 +       case VHIN_VERSION:
15884 +               return uts->name.version;
15885 +       case VHIN_MACHINE:
15886 +               return uts->name.machine;
15887 +       case VHIN_DOMAINNAME:
15888 +               return uts->name.domainname;
15889 +       default:
15890 +               return NULL;
15891 +       }
15892 +       return NULL;
15893 +}
15894 +
15895 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
15896 +{
15897 +       struct vcmd_vhi_name_v0 vc_data;
15898 +       char *name;
15899 +
15900 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15901 +               return -EFAULT;
15902 +
15903 +       name = vx_vhi_name(vxi, vc_data.field);
15904 +       if (!name)
15905 +               return -EINVAL;
15906 +
15907 +       memcpy(name, vc_data.name, 65);
15908 +       return 0;
15909 +}
15910 +
15911 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
15912 +{
15913 +       struct vcmd_vhi_name_v0 vc_data;
15914 +       char *name;
15915 +
15916 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15917 +               return -EFAULT;
15918 +
15919 +       name = vx_vhi_name(vxi, vc_data.field);
15920 +       if (!name)
15921 +               return -EINVAL;
15922 +
15923 +       memcpy(vc_data.name, name, 65);
15924 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15925 +               return -EFAULT;
15926 +       return 0;
15927 +}
15928 +
15929 +
15930 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
15931 +{
15932 +       struct vcmd_virt_stat_v0 vc_data;
15933 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
15934 +       struct timespec uptime;
15935 +
15936 +       ktime_get_ts(&uptime);
15937 +       set_normalized_timespec(&uptime,
15938 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
15939 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
15940 +
15941 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
15942 +       vc_data.uptime = timespec_to_ns(&uptime);
15943 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
15944 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
15945 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
15946 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
15947 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
15948 +       vc_data.load[0] = cvirt->load[0];
15949 +       vc_data.load[1] = cvirt->load[1];
15950 +       vc_data.load[2] = cvirt->load[2];
15951 +
15952 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15953 +               return -EFAULT;
15954 +       return 0;
15955 +}
15956 +
15957 +
15958 +#ifdef CONFIG_VSERVER_VTIME
15959 +
15960 +/* virtualized time base */
15961 +
15962 +void vx_adjust_timespec(struct timespec *ts)
15963 +{
15964 +       struct vx_info *vxi;
15965 +
15966 +       if (!vx_flags(VXF_VIRT_TIME, 0))
15967 +               return;
15968 +
15969 +       vxi = current_vx_info();
15970 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
15971 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
15972 +
15973 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
15974 +               ts->tv_sec++;
15975 +               ts->tv_nsec -= NSEC_PER_SEC;
15976 +       } else if (ts->tv_nsec < 0) {
15977 +               ts->tv_sec--;
15978 +               ts->tv_nsec += NSEC_PER_SEC;
15979 +       }
15980 +}
15981 +
15982 +int vx_settimeofday(const struct timespec *ts)
15983 +{
15984 +       struct timespec ats, delta;
15985 +       struct vx_info *vxi;
15986 +
15987 +       if (!vx_flags(VXF_VIRT_TIME, 0))
15988 +               return do_settimeofday(ts);
15989 +
15990 +       getnstimeofday(&ats);
15991 +       delta = timespec_sub(*ts, ats);
15992 +
15993 +       vxi = current_vx_info();
15994 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
15995 +       return 0;
15996 +}
15997 +
15998 +#endif
15999 +
16000 diff -NurpP --minimal linux-4.4.115/kernel/vserver/cvirt_init.h linux-4.4.115-vs2.3.9.7/kernel/vserver/cvirt_init.h
16001 --- linux-4.4.115/kernel/vserver/cvirt_init.h   1970-01-01 00:00:00.000000000 +0000
16002 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/cvirt_init.h 2018-01-09 22:16:00.000000000 +0000
16003 @@ -0,0 +1,70 @@
16004 +
16005 +
16006 +extern uint64_t vx_idle_jiffies(void);
16007 +
16008 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16009 +{
16010 +       uint64_t idle_jiffies = vx_idle_jiffies();
16011 +       uint64_t nsuptime;
16012 +
16013 +       ktime_get_ts(&cvirt->bias_uptime);
16014 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16015 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16016 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16017 +       cvirt->bias_ts.tv_sec = 0;
16018 +       cvirt->bias_ts.tv_nsec = 0;
16019 +
16020 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16021 +       atomic_set(&cvirt->nr_threads, 0);
16022 +       atomic_set(&cvirt->nr_running, 0);
16023 +       atomic_set(&cvirt->nr_uninterruptible, 0);
16024 +       atomic_set(&cvirt->nr_onhold, 0);
16025 +
16026 +       spin_lock_init(&cvirt->load_lock);
16027 +       cvirt->load_last = jiffies;
16028 +       atomic_set(&cvirt->load_updates, 0);
16029 +       cvirt->load[0] = 0;
16030 +       cvirt->load[1] = 0;
16031 +       cvirt->load[2] = 0;
16032 +       atomic_set(&cvirt->total_forks, 0);
16033 +
16034 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
16035 +       init_waitqueue_head(&cvirt->syslog.log_wait);
16036 +       cvirt->syslog.log_start = 0;
16037 +       cvirt->syslog.log_end = 0;
16038 +       cvirt->syslog.con_start = 0;
16039 +       cvirt->syslog.logged_chars = 0;
16040 +}
16041 +
16042 +static inline
16043 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16044 +{
16045 +       // cvirt_pc->cpustat = { 0 };
16046 +}
16047 +
16048 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16049 +{
16050 +#ifdef CONFIG_VSERVER_WARN
16051 +       int value;
16052 +#endif
16053 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16054 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
16055 +               cvirt, value);
16056 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16057 +               "!!! cvirt: %p[nr_running] = %d on exit.",
16058 +               cvirt, value);
16059 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16060 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16061 +               cvirt, value);
16062 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16063 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
16064 +               cvirt, value);
16065 +       return;
16066 +}
16067 +
16068 +static inline
16069 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16070 +{
16071 +       return;
16072 +}
16073 +
16074 diff -NurpP --minimal linux-4.4.115/kernel/vserver/cvirt_proc.h linux-4.4.115-vs2.3.9.7/kernel/vserver/cvirt_proc.h
16075 --- linux-4.4.115/kernel/vserver/cvirt_proc.h   1970-01-01 00:00:00.000000000 +0000
16076 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/cvirt_proc.h 2018-01-09 16:36:34.000000000 +0000
16077 @@ -0,0 +1,123 @@
16078 +#ifndef _VX_CVIRT_PROC_H
16079 +#define _VX_CVIRT_PROC_H
16080 +
16081 +#include <linux/nsproxy.h>
16082 +#include <linux/mnt_namespace.h>
16083 +#include <linux/ipc_namespace.h>
16084 +#include <linux/utsname.h>
16085 +#include <linux/ipc.h>
16086 +
16087 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
16088 +
16089 +static inline
16090 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
16091 +{
16092 +       struct mnt_namespace *ns;
16093 +       struct uts_namespace *uts;
16094 +       struct ipc_namespace *ipc;
16095 +       int length = 0;
16096 +
16097 +       if (!nsproxy)
16098 +               goto out;
16099 +
16100 +       length += sprintf(buffer + length,
16101 +               "NSProxy:\t%p [%p,%p,%p]\n",
16102 +               nsproxy, nsproxy->mnt_ns,
16103 +               nsproxy->uts_ns, nsproxy->ipc_ns);
16104 +
16105 +       ns = nsproxy->mnt_ns;
16106 +       if (!ns)
16107 +               goto skip_ns;
16108 +
16109 +       length += vx_info_mnt_namespace(ns, buffer + length);
16110 +
16111 +skip_ns:
16112 +
16113 +       uts = nsproxy->uts_ns;
16114 +       if (!uts)
16115 +               goto skip_uts;
16116 +
16117 +       length += sprintf(buffer + length,
16118 +               "SysName:\t%.*s\n"
16119 +               "NodeName:\t%.*s\n"
16120 +               "Release:\t%.*s\n"
16121 +               "Version:\t%.*s\n"
16122 +               "Machine:\t%.*s\n"
16123 +               "DomainName:\t%.*s\n",
16124 +               __NEW_UTS_LEN, uts->name.sysname,
16125 +               __NEW_UTS_LEN, uts->name.nodename,
16126 +               __NEW_UTS_LEN, uts->name.release,
16127 +               __NEW_UTS_LEN, uts->name.version,
16128 +               __NEW_UTS_LEN, uts->name.machine,
16129 +               __NEW_UTS_LEN, uts->name.domainname);
16130 +skip_uts:
16131 +
16132 +       ipc = nsproxy->ipc_ns;
16133 +       if (!ipc)
16134 +               goto skip_ipc;
16135 +
16136 +       length += sprintf(buffer + length,
16137 +               "SEMS:\t\t%d %d %d %d  %d\n"
16138 +               "MSG:\t\t%d %d %d\n"
16139 +               "SHM:\t\t%lu %lu  %d %ld\n",
16140 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
16141 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
16142 +               ipc->used_sems,
16143 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
16144 +               (unsigned long)ipc->shm_ctlmax,
16145 +               (unsigned long)ipc->shm_ctlall,
16146 +               ipc->shm_ctlmni, ipc->shm_tot);
16147 +skip_ipc:
16148 +out:
16149 +       return length;
16150 +}
16151 +
16152 +
16153 +#include <linux/sched.h>
16154 +
16155 +#define LOAD_INT(x) ((x) >> FSHIFT)
16156 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
16157 +
16158 +static inline
16159 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
16160 +{
16161 +       int length = 0;
16162 +       int a, b, c;
16163 +
16164 +       length += sprintf(buffer + length,
16165 +               "BiasUptime:\t%lu.%02lu\n",
16166 +               (unsigned long)cvirt->bias_uptime.tv_sec,
16167 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
16168 +
16169 +       a = cvirt->load[0] + (FIXED_1 / 200);
16170 +       b = cvirt->load[1] + (FIXED_1 / 200);
16171 +       c = cvirt->load[2] + (FIXED_1 / 200);
16172 +       length += sprintf(buffer + length,
16173 +               "nr_threads:\t%d\n"
16174 +               "nr_running:\t%d\n"
16175 +               "nr_unintr:\t%d\n"
16176 +               "nr_onhold:\t%d\n"
16177 +               "load_updates:\t%d\n"
16178 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
16179 +               "total_forks:\t%d\n",
16180 +               atomic_read(&cvirt->nr_threads),
16181 +               atomic_read(&cvirt->nr_running),
16182 +               atomic_read(&cvirt->nr_uninterruptible),
16183 +               atomic_read(&cvirt->nr_onhold),
16184 +               atomic_read(&cvirt->load_updates),
16185 +               LOAD_INT(a), LOAD_FRAC(a),
16186 +               LOAD_INT(b), LOAD_FRAC(b),
16187 +               LOAD_INT(c), LOAD_FRAC(c),
16188 +               atomic_read(&cvirt->total_forks));
16189 +       return length;
16190 +}
16191 +
16192 +static inline
16193 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
16194 +       char *buffer, int cpu)
16195 +{
16196 +       int length = 0;
16197 +       return length;
16198 +}
16199 +
16200 +#endif /* _VX_CVIRT_PROC_H */
16201 diff -NurpP --minimal linux-4.4.115/kernel/vserver/debug.c linux-4.4.115-vs2.3.9.7/kernel/vserver/debug.c
16202 --- linux-4.4.115/kernel/vserver/debug.c        1970-01-01 00:00:00.000000000 +0000
16203 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/debug.c      2018-01-09 16:36:34.000000000 +0000
16204 @@ -0,0 +1,32 @@
16205 +/*
16206 + *  kernel/vserver/debug.c
16207 + *
16208 + *  Copyright (C) 2005-2007 Herbert Pötzl
16209 + *
16210 + *  V0.01  vx_info dump support
16211 + *
16212 + */
16213 +
16214 +#include <linux/module.h>
16215 +
16216 +#include <linux/vserver/context.h>
16217 +
16218 +
16219 +void   dump_vx_info(struct vx_info *vxi, int level)
16220 +{
16221 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
16222 +               atomic_read(&vxi->vx_usecnt),
16223 +               atomic_read(&vxi->vx_tasks),
16224 +               vxi->vx_state);
16225 +       if (level > 0) {
16226 +               __dump_vx_limit(&vxi->limit);
16227 +               __dump_vx_sched(&vxi->sched);
16228 +               __dump_vx_cvirt(&vxi->cvirt);
16229 +               __dump_vx_cacct(&vxi->cacct);
16230 +       }
16231 +       printk("---\n");
16232 +}
16233 +
16234 +
16235 +EXPORT_SYMBOL_GPL(dump_vx_info);
16236 +
16237 diff -NurpP --minimal linux-4.4.115/kernel/vserver/device.c linux-4.4.115-vs2.3.9.7/kernel/vserver/device.c
16238 --- linux-4.4.115/kernel/vserver/device.c       1970-01-01 00:00:00.000000000 +0000
16239 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/device.c     2018-01-09 16:36:34.000000000 +0000
16240 @@ -0,0 +1,443 @@
16241 +/*
16242 + *  linux/kernel/vserver/device.c
16243 + *
16244 + *  Linux-VServer: Device Support
16245 + *
16246 + *  Copyright (C) 2006  Herbert Pötzl
16247 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
16248 + *
16249 + *  V0.01  device mapping basics
16250 + *  V0.02  added defaults
16251 + *
16252 + */
16253 +
16254 +#include <linux/slab.h>
16255 +#include <linux/rcupdate.h>
16256 +#include <linux/fs.h>
16257 +#include <linux/namei.h>
16258 +#include <linux/hash.h>
16259 +
16260 +#include <asm/errno.h>
16261 +#include <asm/uaccess.h>
16262 +#include <linux/vserver/base.h>
16263 +#include <linux/vserver/debug.h>
16264 +#include <linux/vserver/context.h>
16265 +#include <linux/vserver/device.h>
16266 +#include <linux/vserver/device_cmd.h>
16267 +
16268 +
16269 +#define DMAP_HASH_BITS 4
16270 +
16271 +
16272 +struct vs_mapping {
16273 +       union {
16274 +               struct hlist_node hlist;
16275 +               struct list_head list;
16276 +       } u;
16277 +#define dm_hlist       u.hlist
16278 +#define dm_list                u.list
16279 +       vxid_t xid;
16280 +       dev_t device;
16281 +       struct vx_dmap_target target;
16282 +};
16283 +
16284 +
16285 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
16286 +
16287 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
16288 +
16289 +static struct vx_dmap_target dmap_defaults[2] = {
16290 +       { .flags = DATTR_OPEN },
16291 +       { .flags = DATTR_OPEN },
16292 +};
16293 +
16294 +
16295 +struct kmem_cache *dmap_cachep __read_mostly;
16296 +
16297 +int __init dmap_cache_init(void)
16298 +{
16299 +       dmap_cachep = kmem_cache_create("dmap_cache",
16300 +               sizeof(struct vs_mapping), 0,
16301 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
16302 +       return 0;
16303 +}
16304 +
16305 +__initcall(dmap_cache_init);
16306 +
16307 +
16308 +static inline unsigned int __hashval(dev_t dev, int bits)
16309 +{
16310 +       return hash_long((unsigned long)dev, bits);
16311 +}
16312 +
16313 +
16314 +/*     __hash_mapping()
16315 + *     add the mapping to the hash table
16316 + */
16317 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
16318 +{
16319 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16320 +       struct hlist_head *head, *hash = dmap_main_hash;
16321 +       int device = vdm->device;
16322 +
16323 +       spin_lock(hash_lock);
16324 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
16325 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
16326 +
16327 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
16328 +       hlist_add_head(&vdm->dm_hlist, head);
16329 +       spin_unlock(hash_lock);
16330 +}
16331 +
16332 +
16333 +static inline int __mode_to_default(umode_t mode)
16334 +{
16335 +       switch (mode) {
16336 +       case S_IFBLK:
16337 +               return 0;
16338 +       case S_IFCHR:
16339 +               return 1;
16340 +       default:
16341 +               BUG();
16342 +       }
16343 +}
16344 +
16345 +
16346 +/*     __set_default()
16347 + *     set a default
16348 + */
16349 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
16350 +       struct vx_dmap_target *vdmt)
16351 +{
16352 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16353 +       spin_lock(hash_lock);
16354 +
16355 +       if (vxi)
16356 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
16357 +       else
16358 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
16359 +
16360 +
16361 +       spin_unlock(hash_lock);
16362 +
16363 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
16364 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
16365 +}
16366 +
16367 +
16368 +/*     __remove_default()
16369 + *     remove a default
16370 + */
16371 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
16372 +{
16373 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16374 +       spin_lock(hash_lock);
16375 +
16376 +       if (vxi)
16377 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
16378 +       else    /* remove == reset */
16379 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
16380 +
16381 +       spin_unlock(hash_lock);
16382 +       return 0;
16383 +}
16384 +
16385 +
16386 +/*     __find_mapping()
16387 + *     find a mapping in the hash table
16388 + *
16389 + *     caller must hold hash_lock
16390 + */
16391 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
16392 +       struct vs_mapping **local, struct vs_mapping **global)
16393 +{
16394 +       struct hlist_head *hash = dmap_main_hash;
16395 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
16396 +       struct hlist_node *pos;
16397 +       struct vs_mapping *vdm;
16398 +
16399 +       *local = NULL;
16400 +       if (global)
16401 +               *global = NULL;
16402 +
16403 +       hlist_for_each(pos, head) {
16404 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
16405 +
16406 +               if ((vdm->device == device) &&
16407 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
16408 +                       if (vdm->xid == xid) {
16409 +                               *local = vdm;
16410 +                               return 1;
16411 +                       } else if (global && vdm->xid == 0)
16412 +                               *global = vdm;
16413 +               }
16414 +       }
16415 +
16416 +       if (global && *global)
16417 +               return 0;
16418 +       else
16419 +               return -ENOENT;
16420 +}
16421 +
16422 +
16423 +/*     __lookup_mapping()
16424 + *     find a mapping and store the result in target and flags
16425 + */
16426 +static inline int __lookup_mapping(struct vx_info *vxi,
16427 +       dev_t device, dev_t *target, int *flags, umode_t mode)
16428 +{
16429 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16430 +       struct vs_mapping *vdm, *global;
16431 +       struct vx_dmap_target *vdmt;
16432 +       int ret = 0;
16433 +       vxid_t xid = vxi->vx_id;
16434 +       int index;
16435 +
16436 +       spin_lock(hash_lock);
16437 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
16438 +               ret = 1;
16439 +               vdmt = &vdm->target;
16440 +               goto found;
16441 +       }
16442 +
16443 +       index = __mode_to_default(mode);
16444 +       if (vxi && vxi->dmap.targets[index].flags) {
16445 +               ret = 2;
16446 +               vdmt = &vxi->dmap.targets[index];
16447 +       } else if (global) {
16448 +               ret = 3;
16449 +               vdmt = &global->target;
16450 +               goto found;
16451 +       } else {
16452 +               ret = 4;
16453 +               vdmt = &dmap_defaults[index];
16454 +       }
16455 +
16456 +found:
16457 +       if (target && (vdmt->flags & DATTR_REMAP))
16458 +               *target = vdmt->target;
16459 +       else if (target)
16460 +               *target = device;
16461 +       if (flags)
16462 +               *flags = vdmt->flags;
16463 +
16464 +       spin_unlock(hash_lock);
16465 +
16466 +       return ret;
16467 +}
16468 +
16469 +
16470 +/*     __remove_mapping()
16471 + *     remove a mapping from the hash table
16472 + */
16473 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
16474 +       umode_t mode)
16475 +{
16476 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16477 +       struct vs_mapping *vdm = NULL;
16478 +       int ret = 0;
16479 +
16480 +       spin_lock(hash_lock);
16481 +
16482 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
16483 +               NULL);
16484 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
16485 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
16486 +       if (ret < 0)
16487 +               goto out;
16488 +       hlist_del(&vdm->dm_hlist);
16489 +
16490 +out:
16491 +       spin_unlock(hash_lock);
16492 +       if (vdm)
16493 +               kmem_cache_free(dmap_cachep, vdm);
16494 +       return ret;
16495 +}
16496 +
16497 +
16498 +
16499 +int vs_map_device(struct vx_info *vxi,
16500 +       dev_t device, dev_t *target, umode_t mode)
16501 +{
16502 +       int ret, flags = DATTR_MASK;
16503 +
16504 +       if (!vxi) {
16505 +               if (target)
16506 +                       *target = device;
16507 +               goto out;
16508 +       }
16509 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
16510 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
16511 +               device, target ? *target : 0, flags, mode, ret);
16512 +out:
16513 +       return (flags & DATTR_MASK);
16514 +}
16515 +
16516 +
16517 +
16518 +static int do_set_mapping(struct vx_info *vxi,
16519 +       dev_t device, dev_t target, int flags, umode_t mode)
16520 +{
16521 +       if (device) {
16522 +               struct vs_mapping *new;
16523 +
16524 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
16525 +               if (!new)
16526 +                       return -ENOMEM;
16527 +
16528 +               INIT_HLIST_NODE(&new->dm_hlist);
16529 +               new->device = device;
16530 +               new->target.target = target;
16531 +               new->target.flags = flags | mode;
16532 +               new->xid = (vxi ? vxi->vx_id : 0);
16533 +
16534 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
16535 +               __hash_mapping(vxi, new);
16536 +       } else {
16537 +               struct vx_dmap_target new = {
16538 +                       .target = target,
16539 +                       .flags = flags | mode,
16540 +               };
16541 +               __set_default(vxi, mode, &new);
16542 +       }
16543 +       return 0;
16544 +}
16545 +
16546 +
16547 +static int do_unset_mapping(struct vx_info *vxi,
16548 +       dev_t device, dev_t target, int flags, umode_t mode)
16549 +{
16550 +       int ret = -EINVAL;
16551 +
16552 +       if (device) {
16553 +               ret = __remove_mapping(vxi, device, mode);
16554 +               if (ret < 0)
16555 +                       goto out;
16556 +       } else {
16557 +               ret = __remove_default(vxi, mode);
16558 +               if (ret < 0)
16559 +                       goto out;
16560 +       }
16561 +
16562 +out:
16563 +       return ret;
16564 +}
16565 +
16566 +
16567 +static inline int __user_device(const char __user *name, dev_t *dev,
16568 +       umode_t *mode)
16569 +{
16570 +       struct path path;
16571 +       int ret;
16572 +
16573 +       if (!name) {
16574 +               *dev = 0;
16575 +               return 0;
16576 +       }
16577 +       ret = user_lpath(name, &path);
16578 +       if (ret)
16579 +               return ret;
16580 +       if (path.dentry->d_inode) {
16581 +               *dev = path.dentry->d_inode->i_rdev;
16582 +               *mode = path.dentry->d_inode->i_mode;
16583 +       }
16584 +       path_put(&path);
16585 +       return 0;
16586 +}
16587 +
16588 +static inline int __mapping_mode(dev_t device, dev_t target,
16589 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
16590 +{
16591 +       if (device)
16592 +               *mode = device_mode & S_IFMT;
16593 +       else if (target)
16594 +               *mode = target_mode & S_IFMT;
16595 +       else
16596 +               return -EINVAL;
16597 +
16598 +       /* if both given, device and target mode have to match */
16599 +       if (device && target &&
16600 +               ((device_mode ^ target_mode) & S_IFMT))
16601 +               return -EINVAL;
16602 +       return 0;
16603 +}
16604 +
16605 +
16606 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
16607 +       const char __user *target_path, int flags, int set)
16608 +{
16609 +       dev_t device = ~0, target = ~0;
16610 +       umode_t device_mode = 0, target_mode = 0, mode;
16611 +       int ret;
16612 +
16613 +       ret = __user_device(device_path, &device, &device_mode);
16614 +       if (ret)
16615 +               return ret;
16616 +       ret = __user_device(target_path, &target, &target_mode);
16617 +       if (ret)
16618 +               return ret;
16619 +
16620 +       ret = __mapping_mode(device, target,
16621 +               device_mode, target_mode, &mode);
16622 +       if (ret)
16623 +               return ret;
16624 +
16625 +       if (set)
16626 +               return do_set_mapping(vxi, device, target,
16627 +                       flags, mode);
16628 +       else
16629 +               return do_unset_mapping(vxi, device, target,
16630 +                       flags, mode);
16631 +}
16632 +
16633 +
16634 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
16635 +{
16636 +       struct vcmd_set_mapping_v0 vc_data;
16637 +
16638 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16639 +               return -EFAULT;
16640 +
16641 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16642 +               vc_data.flags, 1);
16643 +}
16644 +
16645 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
16646 +{
16647 +       struct vcmd_set_mapping_v0 vc_data;
16648 +
16649 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16650 +               return -EFAULT;
16651 +
16652 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16653 +               vc_data.flags, 0);
16654 +}
16655 +
16656 +
16657 +#ifdef CONFIG_COMPAT
16658 +
16659 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
16660 +{
16661 +       struct vcmd_set_mapping_v0_x32 vc_data;
16662 +
16663 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16664 +               return -EFAULT;
16665 +
16666 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16667 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
16668 +}
16669 +
16670 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
16671 +{
16672 +       struct vcmd_set_mapping_v0_x32 vc_data;
16673 +
16674 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16675 +               return -EFAULT;
16676 +
16677 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16678 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
16679 +}
16680 +
16681 +#endif /* CONFIG_COMPAT */
16682 +
16683 +
16684 diff -NurpP --minimal linux-4.4.115/kernel/vserver/dlimit.c linux-4.4.115-vs2.3.9.7/kernel/vserver/dlimit.c
16685 --- linux-4.4.115/kernel/vserver/dlimit.c       1970-01-01 00:00:00.000000000 +0000
16686 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/dlimit.c     2018-01-09 16:36:34.000000000 +0000
16687 @@ -0,0 +1,528 @@
16688 +/*
16689 + *  linux/kernel/vserver/dlimit.c
16690 + *
16691 + *  Virtual Server: Context Disk Limits
16692 + *
16693 + *  Copyright (C) 2004-2009  Herbert Pötzl
16694 + *
16695 + *  V0.01  initial version
16696 + *  V0.02  compat32 splitup
16697 + *  V0.03  extended interface
16698 + *
16699 + */
16700 +
16701 +#include <linux/statfs.h>
16702 +#include <linux/sched.h>
16703 +#include <linux/namei.h>
16704 +#include <linux/vs_tag.h>
16705 +#include <linux/vs_dlimit.h>
16706 +#include <linux/vserver/dlimit_cmd.h>
16707 +#include <linux/slab.h>
16708 +// #include <linux/gfp.h>
16709 +
16710 +#include <asm/uaccess.h>
16711 +
16712 +/*     __alloc_dl_info()
16713 +
16714 +       * allocate an initialized dl_info struct
16715 +       * doesn't make it visible (hash)                        */
16716 +
16717 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
16718 +{
16719 +       struct dl_info *new = NULL;
16720 +
16721 +       vxdprintk(VXD_CBIT(dlim, 5),
16722 +               "alloc_dl_info(%p,%d)*", sb, tag);
16723 +
16724 +       /* would this benefit from a slab cache? */
16725 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
16726 +       if (!new)
16727 +               return 0;
16728 +
16729 +       memset(new, 0, sizeof(struct dl_info));
16730 +       new->dl_tag = tag;
16731 +       new->dl_sb = sb;
16732 +       // INIT_RCU_HEAD(&new->dl_rcu);
16733 +       INIT_HLIST_NODE(&new->dl_hlist);
16734 +       spin_lock_init(&new->dl_lock);
16735 +       atomic_set(&new->dl_refcnt, 0);
16736 +       atomic_set(&new->dl_usecnt, 0);
16737 +
16738 +       /* rest of init goes here */
16739 +
16740 +       vxdprintk(VXD_CBIT(dlim, 4),
16741 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
16742 +       return new;
16743 +}
16744 +
16745 +/*     __dealloc_dl_info()
16746 +
16747 +       * final disposal of dl_info                             */
16748 +
16749 +static void __dealloc_dl_info(struct dl_info *dli)
16750 +{
16751 +       vxdprintk(VXD_CBIT(dlim, 4),
16752 +               "dealloc_dl_info(%p)", dli);
16753 +
16754 +       dli->dl_hlist.next = LIST_POISON1;
16755 +       dli->dl_tag = -1;
16756 +       dli->dl_sb = 0;
16757 +
16758 +       BUG_ON(atomic_read(&dli->dl_usecnt));
16759 +       BUG_ON(atomic_read(&dli->dl_refcnt));
16760 +
16761 +       kfree(dli);
16762 +}
16763 +
16764 +
16765 +/*     hash table for dl_info hash */
16766 +
16767 +#define DL_HASH_SIZE   13
16768 +
16769 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
16770 +
16771 +static DEFINE_SPINLOCK(dl_info_hash_lock);
16772 +
16773 +
16774 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
16775 +{
16776 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
16777 +}
16778 +
16779 +
16780 +
16781 +/*     __hash_dl_info()
16782 +
16783 +       * add the dli to the global hash table
16784 +       * requires the hash_lock to be held                     */
16785 +
16786 +static inline void __hash_dl_info(struct dl_info *dli)
16787 +{
16788 +       struct hlist_head *head;
16789 +
16790 +       vxdprintk(VXD_CBIT(dlim, 6),
16791 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
16792 +       get_dl_info(dli);
16793 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
16794 +       hlist_add_head_rcu(&dli->dl_hlist, head);
16795 +}
16796 +
16797 +/*     __unhash_dl_info()
16798 +
16799 +       * remove the dli from the global hash table
16800 +       * requires the hash_lock to be held                     */
16801 +
16802 +static inline void __unhash_dl_info(struct dl_info *dli)
16803 +{
16804 +       vxdprintk(VXD_CBIT(dlim, 6),
16805 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
16806 +       hlist_del_rcu(&dli->dl_hlist);
16807 +       put_dl_info(dli);
16808 +}
16809 +
16810 +
16811 +/*     __lookup_dl_info()
16812 +
16813 +       * requires the rcu_read_lock()
16814 +       * doesn't increment the dl_refcnt                       */
16815 +
16816 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
16817 +{
16818 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
16819 +       struct dl_info *dli;
16820 +
16821 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
16822 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
16823 +                       return dli;
16824 +       }
16825 +       return NULL;
16826 +}
16827 +
16828 +
16829 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
16830 +{
16831 +       struct dl_info *dli;
16832 +
16833 +       rcu_read_lock();
16834 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
16835 +       vxdprintk(VXD_CBIT(dlim, 7),
16836 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
16837 +       rcu_read_unlock();
16838 +       return dli;
16839 +}
16840 +
16841 +void rcu_free_dl_info(struct rcu_head *head)
16842 +{
16843 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
16844 +       int usecnt, refcnt;
16845 +
16846 +       BUG_ON(!dli || !head);
16847 +
16848 +       usecnt = atomic_read(&dli->dl_usecnt);
16849 +       BUG_ON(usecnt < 0);
16850 +
16851 +       refcnt = atomic_read(&dli->dl_refcnt);
16852 +       BUG_ON(refcnt < 0);
16853 +
16854 +       vxdprintk(VXD_CBIT(dlim, 3),
16855 +               "rcu_free_dl_info(%p)", dli);
16856 +       if (!usecnt)
16857 +               __dealloc_dl_info(dli);
16858 +       else
16859 +               printk("!!! rcu didn't free\n");
16860 +}
16861 +
16862 +
16863 +
16864 +
16865 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
16866 +       uint32_t flags, int add)
16867 +{
16868 +       struct path path;
16869 +       int ret;
16870 +
16871 +       ret = user_lpath(name, &path);
16872 +       if (!ret) {
16873 +               struct super_block *sb;
16874 +               struct dl_info *dli;
16875 +
16876 +               ret = -EINVAL;
16877 +               if (!path.dentry->d_inode)
16878 +                       goto out_release;
16879 +               if (!(sb = path.dentry->d_inode->i_sb))
16880 +                       goto out_release;
16881 +
16882 +               if (add) {
16883 +                       dli = __alloc_dl_info(sb, id);
16884 +                       spin_lock(&dl_info_hash_lock);
16885 +
16886 +                       ret = -EEXIST;
16887 +                       if (__lookup_dl_info(sb, id))
16888 +                               goto out_unlock;
16889 +                       __hash_dl_info(dli);
16890 +                       dli = NULL;
16891 +               } else {
16892 +                       spin_lock(&dl_info_hash_lock);
16893 +                       dli = __lookup_dl_info(sb, id);
16894 +
16895 +                       ret = -ESRCH;
16896 +                       if (!dli)
16897 +                               goto out_unlock;
16898 +                       __unhash_dl_info(dli);
16899 +               }
16900 +               ret = 0;
16901 +       out_unlock:
16902 +               spin_unlock(&dl_info_hash_lock);
16903 +               if (add && dli)
16904 +                       __dealloc_dl_info(dli);
16905 +       out_release:
16906 +               path_put(&path);
16907 +       }
16908 +       return ret;
16909 +}
16910 +
16911 +int vc_add_dlimit(uint32_t id, void __user *data)
16912 +{
16913 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
16914 +
16915 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16916 +               return -EFAULT;
16917 +
16918 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
16919 +}
16920 +
16921 +int vc_rem_dlimit(uint32_t id, void __user *data)
16922 +{
16923 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
16924 +
16925 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16926 +               return -EFAULT;
16927 +
16928 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
16929 +}
16930 +
16931 +#ifdef CONFIG_COMPAT
16932 +
16933 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
16934 +{
16935 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
16936 +
16937 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16938 +               return -EFAULT;
16939 +
16940 +       return do_addrem_dlimit(id,
16941 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
16942 +}
16943 +
16944 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
16945 +{
16946 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
16947 +
16948 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16949 +               return -EFAULT;
16950 +
16951 +       return do_addrem_dlimit(id,
16952 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
16953 +}
16954 +
16955 +#endif /* CONFIG_COMPAT */
16956 +
16957 +
16958 +static inline
16959 +int do_set_dlimit(uint32_t id, const char __user *name,
16960 +       uint32_t space_used, uint32_t space_total,
16961 +       uint32_t inodes_used, uint32_t inodes_total,
16962 +       uint32_t reserved, uint32_t flags)
16963 +{
16964 +       struct path path;
16965 +       int ret;
16966 +
16967 +       ret = user_lpath(name, &path);
16968 +       if (!ret) {
16969 +               struct super_block *sb;
16970 +               struct dl_info *dli;
16971 +
16972 +               ret = -EINVAL;
16973 +               if (!path.dentry->d_inode)
16974 +                       goto out_release;
16975 +               if (!(sb = path.dentry->d_inode->i_sb))
16976 +                       goto out_release;
16977 +
16978 +               /* sanity checks */
16979 +               if ((reserved != CDLIM_KEEP &&
16980 +                       reserved > 100) ||
16981 +                       (inodes_used != CDLIM_KEEP &&
16982 +                       inodes_used > inodes_total) ||
16983 +                       (space_used != CDLIM_KEEP &&
16984 +                       space_used > space_total))
16985 +                       goto out_release;
16986 +
16987 +               ret = -ESRCH;
16988 +               dli = locate_dl_info(sb, id);
16989 +               if (!dli)
16990 +                       goto out_release;
16991 +
16992 +               spin_lock(&dli->dl_lock);
16993 +
16994 +               if (inodes_used != CDLIM_KEEP)
16995 +                       dli->dl_inodes_used = inodes_used;
16996 +               if (inodes_total != CDLIM_KEEP)
16997 +                       dli->dl_inodes_total = inodes_total;
16998 +               if (space_used != CDLIM_KEEP)
16999 +                       dli->dl_space_used = dlimit_space_32to64(
17000 +                               space_used, flags, DLIMS_USED);
17001 +
17002 +               if (space_total == CDLIM_INFINITY)
17003 +                       dli->dl_space_total = DLIM_INFINITY;
17004 +               else if (space_total != CDLIM_KEEP)
17005 +                       dli->dl_space_total = dlimit_space_32to64(
17006 +                               space_total, flags, DLIMS_TOTAL);
17007 +
17008 +               if (reserved != CDLIM_KEEP)
17009 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17010 +
17011 +               spin_unlock(&dli->dl_lock);
17012 +
17013 +               put_dl_info(dli);
17014 +               ret = 0;
17015 +
17016 +       out_release:
17017 +               path_put(&path);
17018 +       }
17019 +       return ret;
17020 +}
17021 +
17022 +int vc_set_dlimit(uint32_t id, void __user *data)
17023 +{
17024 +       struct vcmd_ctx_dlimit_v0 vc_data;
17025 +
17026 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17027 +               return -EFAULT;
17028 +
17029 +       return do_set_dlimit(id, vc_data.name,
17030 +               vc_data.space_used, vc_data.space_total,
17031 +               vc_data.inodes_used, vc_data.inodes_total,
17032 +               vc_data.reserved, vc_data.flags);
17033 +}
17034 +
17035 +#ifdef CONFIG_COMPAT
17036 +
17037 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17038 +{
17039 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17040 +
17041 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17042 +               return -EFAULT;
17043 +
17044 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17045 +               vc_data.space_used, vc_data.space_total,
17046 +               vc_data.inodes_used, vc_data.inodes_total,
17047 +               vc_data.reserved, vc_data.flags);
17048 +}
17049 +
17050 +#endif /* CONFIG_COMPAT */
17051 +
17052 +
17053 +static inline
17054 +int do_get_dlimit(uint32_t id, const char __user *name,
17055 +       uint32_t *space_used, uint32_t *space_total,
17056 +       uint32_t *inodes_used, uint32_t *inodes_total,
17057 +       uint32_t *reserved, uint32_t *flags)
17058 +{
17059 +       struct path path;
17060 +       int ret;
17061 +
17062 +       ret = user_lpath(name, &path);
17063 +       if (!ret) {
17064 +               struct super_block *sb;
17065 +               struct dl_info *dli;
17066 +
17067 +               ret = -EINVAL;
17068 +               if (!path.dentry->d_inode)
17069 +                       goto out_release;
17070 +               if (!(sb = path.dentry->d_inode->i_sb))
17071 +                       goto out_release;
17072 +
17073 +               ret = -ESRCH;
17074 +               dli = locate_dl_info(sb, id);
17075 +               if (!dli)
17076 +                       goto out_release;
17077 +
17078 +               spin_lock(&dli->dl_lock);
17079 +               *inodes_used = dli->dl_inodes_used;
17080 +               *inodes_total = dli->dl_inodes_total;
17081 +
17082 +               *space_used = dlimit_space_64to32(
17083 +                       dli->dl_space_used, flags, DLIMS_USED);
17084 +
17085 +               if (dli->dl_space_total == DLIM_INFINITY)
17086 +                       *space_total = CDLIM_INFINITY;
17087 +               else
17088 +                       *space_total = dlimit_space_64to32(
17089 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
17090 +
17091 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
17092 +               spin_unlock(&dli->dl_lock);
17093 +
17094 +               put_dl_info(dli);
17095 +               ret = -EFAULT;
17096 +
17097 +               ret = 0;
17098 +       out_release:
17099 +               path_put(&path);
17100 +       }
17101 +       return ret;
17102 +}
17103 +
17104 +
17105 +int vc_get_dlimit(uint32_t id, void __user *data)
17106 +{
17107 +       struct vcmd_ctx_dlimit_v0 vc_data;
17108 +       int ret;
17109 +
17110 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17111 +               return -EFAULT;
17112 +
17113 +       ret = do_get_dlimit(id, vc_data.name,
17114 +               &vc_data.space_used, &vc_data.space_total,
17115 +               &vc_data.inodes_used, &vc_data.inodes_total,
17116 +               &vc_data.reserved, &vc_data.flags);
17117 +       if (ret)
17118 +               return ret;
17119 +
17120 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17121 +               return -EFAULT;
17122 +       return 0;
17123 +}
17124 +
17125 +#ifdef CONFIG_COMPAT
17126 +
17127 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
17128 +{
17129 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17130 +       int ret;
17131 +
17132 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17133 +               return -EFAULT;
17134 +
17135 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
17136 +               &vc_data.space_used, &vc_data.space_total,
17137 +               &vc_data.inodes_used, &vc_data.inodes_total,
17138 +               &vc_data.reserved, &vc_data.flags);
17139 +       if (ret)
17140 +               return ret;
17141 +
17142 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17143 +               return -EFAULT;
17144 +       return 0;
17145 +}
17146 +
17147 +#endif /* CONFIG_COMPAT */
17148 +
17149 +
17150 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
17151 +{
17152 +       struct dl_info *dli;
17153 +       __u64 blimit, bfree, bavail;
17154 +       __u32 ifree;
17155 +
17156 +       dli = locate_dl_info(sb, dx_current_tag());
17157 +       if (!dli)
17158 +               return;
17159 +
17160 +       spin_lock(&dli->dl_lock);
17161 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
17162 +               goto no_ilim;
17163 +
17164 +       /* reduce max inodes available to limit */
17165 +       if (buf->f_files > dli->dl_inodes_total)
17166 +               buf->f_files = dli->dl_inodes_total;
17167 +
17168 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
17169 +       /* reduce free inodes to min */
17170 +       if (ifree < buf->f_ffree)
17171 +               buf->f_ffree = ifree;
17172 +
17173 +no_ilim:
17174 +       if (dli->dl_space_total == DLIM_INFINITY)
17175 +               goto no_blim;
17176 +
17177 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
17178 +
17179 +       if (dli->dl_space_total < dli->dl_space_used)
17180 +               bfree = 0;
17181 +       else
17182 +               bfree = (dli->dl_space_total - dli->dl_space_used)
17183 +                       >> sb->s_blocksize_bits;
17184 +
17185 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
17186 +       if (bavail < dli->dl_space_used)
17187 +               bavail = 0;
17188 +       else
17189 +               bavail = (bavail - dli->dl_space_used)
17190 +                       >> sb->s_blocksize_bits;
17191 +
17192 +       /* reduce max space available to limit */
17193 +       if (buf->f_blocks > blimit)
17194 +               buf->f_blocks = blimit;
17195 +
17196 +       /* reduce free space to min */
17197 +       if (bfree < buf->f_bfree)
17198 +               buf->f_bfree = bfree;
17199 +
17200 +       /* reduce avail space to min */
17201 +       if (bavail < buf->f_bavail)
17202 +               buf->f_bavail = bavail;
17203 +
17204 +no_blim:
17205 +       spin_unlock(&dli->dl_lock);
17206 +       put_dl_info(dli);
17207 +
17208 +       return;
17209 +}
17210 +
17211 +#include <linux/module.h>
17212 +
17213 +EXPORT_SYMBOL_GPL(locate_dl_info);
17214 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
17215 +
17216 diff -NurpP --minimal linux-4.4.115/kernel/vserver/helper.c linux-4.4.115-vs2.3.9.7/kernel/vserver/helper.c
17217 --- linux-4.4.115/kernel/vserver/helper.c       1970-01-01 00:00:00.000000000 +0000
17218 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/helper.c     2018-01-09 16:36:34.000000000 +0000
17219 @@ -0,0 +1,242 @@
17220 +/*
17221 + *  linux/kernel/vserver/helper.c
17222 + *
17223 + *  Virtual Context Support
17224 + *
17225 + *  Copyright (C) 2004-2007  Herbert Pötzl
17226 + *
17227 + *  V0.01  basic helper
17228 + *
17229 + */
17230 +
17231 +#include <linux/kmod.h>
17232 +#include <linux/reboot.h>
17233 +#include <linux/vs_context.h>
17234 +#include <linux/vs_network.h>
17235 +#include <linux/vserver/signal.h>
17236 +
17237 +
17238 +char vshelper_path[255] = "/sbin/vshelper";
17239 +
17240 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
17241 +{
17242 +       current->flags &= ~PF_NO_SETAFFINITY;
17243 +       return 0;
17244 +}
17245 +
17246 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
17247 +{
17248 +       struct subprocess_info *info;
17249 +       gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
17250 +
17251 +       info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
17252 +                                        vshelper_init, NULL, NULL);
17253 +       if (info == NULL)
17254 +               return -ENOMEM;
17255 +
17256 +       return call_usermodehelper_exec(info, wait);
17257 +}
17258 +
17259 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
17260 +{
17261 +       int ret;
17262 +
17263 +       if ((ret = vs_call_usermodehelper(name, argv, envp,
17264 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
17265 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
17266 +                       name, argv[1], argv[2],
17267 +                       sync ? "sync" : "async", ret);
17268 +       }
17269 +       vxdprintk(VXD_CBIT(switch, 4),
17270 +               "%s: (%s %s) returned %s with %d",
17271 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
17272 +       return ret;
17273 +}
17274 +
17275 +/*
17276 + *      vshelper path is set via /proc/sys
17277 + *      invoked by vserver sys_reboot(), with
17278 + *      the following arguments
17279 + *
17280 + *      argv [0] = vshelper_path;
17281 + *      argv [1] = action: "restart", "halt", "poweroff", ...
17282 + *      argv [2] = context identifier
17283 + *
17284 + *      envp [*] = type-specific parameters
17285 + */
17286 +
17287 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
17288 +{
17289 +       char id_buf[8], cmd_buf[16];
17290 +       char uid_buf[16], pid_buf[16];
17291 +       int ret;
17292 +
17293 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17294 +       char *envp[] = {"HOME=/", "TERM=linux",
17295 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
17296 +                       uid_buf, pid_buf, cmd_buf, 0};
17297 +
17298 +       if (vx_info_state(vxi, VXS_HELPER))
17299 +               return -EAGAIN;
17300 +       vxi->vx_state |= VXS_HELPER;
17301 +
17302 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17303 +
17304 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17305 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
17306 +               from_kuid(&init_user_ns, current_uid()));
17307 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
17308 +
17309 +       switch (cmd) {
17310 +       case LINUX_REBOOT_CMD_RESTART:
17311 +               argv[1] = "restart";
17312 +               break;
17313 +
17314 +       case LINUX_REBOOT_CMD_HALT:
17315 +               argv[1] = "halt";
17316 +               break;
17317 +
17318 +       case LINUX_REBOOT_CMD_POWER_OFF:
17319 +               argv[1] = "poweroff";
17320 +               break;
17321 +
17322 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
17323 +               argv[1] = "swsusp";
17324 +               break;
17325 +
17326 +       case LINUX_REBOOT_CMD_OOM:
17327 +               argv[1] = "oom";
17328 +               break;
17329 +
17330 +       default:
17331 +               vxi->vx_state &= ~VXS_HELPER;
17332 +               return 0;
17333 +       }
17334 +
17335 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
17336 +       vxi->vx_state &= ~VXS_HELPER;
17337 +       __wakeup_vx_info(vxi);
17338 +       return (ret) ? -EPERM : 0;
17339 +}
17340 +
17341 +
17342 +long vs_reboot(unsigned int cmd, void __user *arg)
17343 +{
17344 +       struct vx_info *vxi = current_vx_info();
17345 +       long ret = 0;
17346 +
17347 +       vxdprintk(VXD_CBIT(misc, 5),
17348 +               "vs_reboot(%p[#%d],%u)",
17349 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17350 +
17351 +       ret = vs_reboot_helper(vxi, cmd, arg);
17352 +       if (ret)
17353 +               return ret;
17354 +
17355 +       vxi->reboot_cmd = cmd;
17356 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17357 +               switch (cmd) {
17358 +               case LINUX_REBOOT_CMD_RESTART:
17359 +               case LINUX_REBOOT_CMD_HALT:
17360 +               case LINUX_REBOOT_CMD_POWER_OFF:
17361 +                       vx_info_kill(vxi, 0, SIGKILL);
17362 +                       vx_info_kill(vxi, 1, SIGKILL);
17363 +               default:
17364 +                       break;
17365 +               }
17366 +       }
17367 +       return 0;
17368 +}
17369 +
17370 +long vs_oom_action(unsigned int cmd)
17371 +{
17372 +       struct vx_info *vxi = current_vx_info();
17373 +       long ret = 0;
17374 +
17375 +       vxdprintk(VXD_CBIT(misc, 5),
17376 +               "vs_oom_action(%p[#%d],%u)",
17377 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17378 +
17379 +       ret = vs_reboot_helper(vxi, cmd, NULL);
17380 +       if (ret)
17381 +               return ret;
17382 +
17383 +       vxi->reboot_cmd = cmd;
17384 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17385 +               vx_info_kill(vxi, 0, SIGKILL);
17386 +               vx_info_kill(vxi, 1, SIGKILL);
17387 +       }
17388 +       return 0;
17389 +}
17390 +
17391 +/*
17392 + *      argv [0] = vshelper_path;
17393 + *      argv [1] = action: "startup", "shutdown"
17394 + *      argv [2] = context identifier
17395 + *
17396 + *      envp [*] = type-specific parameters
17397 + */
17398 +
17399 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
17400 +{
17401 +       char id_buf[8], cmd_buf[16];
17402 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17403 +       char *envp[] = {"HOME=/", "TERM=linux",
17404 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17405 +
17406 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
17407 +               return 0;
17408 +
17409 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17410 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17411 +
17412 +       switch (cmd) {
17413 +       case VSC_STARTUP:
17414 +               argv[1] = "startup";
17415 +               break;
17416 +       case VSC_SHUTDOWN:
17417 +               argv[1] = "shutdown";
17418 +               break;
17419 +       default:
17420 +               return 0;
17421 +       }
17422 +
17423 +       return do_vshelper(vshelper_path, argv, envp, 1);
17424 +}
17425 +
17426 +
17427 +/*
17428 + *      argv [0] = vshelper_path;
17429 + *      argv [1] = action: "netup", "netdown"
17430 + *      argv [2] = context identifier
17431 + *
17432 + *      envp [*] = type-specific parameters
17433 + */
17434 +
17435 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
17436 +{
17437 +       char id_buf[8], cmd_buf[16];
17438 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17439 +       char *envp[] = {"HOME=/", "TERM=linux",
17440 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17441 +
17442 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
17443 +               return 0;
17444 +
17445 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
17446 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17447 +
17448 +       switch (cmd) {
17449 +       case VSC_NETUP:
17450 +               argv[1] = "netup";
17451 +               break;
17452 +       case VSC_NETDOWN:
17453 +               argv[1] = "netdown";
17454 +               break;
17455 +       default:
17456 +               return 0;
17457 +       }
17458 +
17459 +       return do_vshelper(vshelper_path, argv, envp, 1);
17460 +}
17461 +
17462 diff -NurpP --minimal linux-4.4.115/kernel/vserver/history.c linux-4.4.115-vs2.3.9.7/kernel/vserver/history.c
17463 --- linux-4.4.115/kernel/vserver/history.c      1970-01-01 00:00:00.000000000 +0000
17464 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/history.c    2018-01-09 16:36:34.000000000 +0000
17465 @@ -0,0 +1,258 @@
17466 +/*
17467 + *  kernel/vserver/history.c
17468 + *
17469 + *  Virtual Context History Backtrace
17470 + *
17471 + *  Copyright (C) 2004-2007  Herbert Pötzl
17472 + *
17473 + *  V0.01  basic structure
17474 + *  V0.02  hash/unhash and trace
17475 + *  V0.03  preemption fixes
17476 + *
17477 + */
17478 +
17479 +#include <linux/module.h>
17480 +#include <asm/uaccess.h>
17481 +
17482 +#include <linux/vserver/context.h>
17483 +#include <linux/vserver/debug.h>
17484 +#include <linux/vserver/debug_cmd.h>
17485 +#include <linux/vserver/history.h>
17486 +
17487 +
17488 +#ifdef CONFIG_VSERVER_HISTORY
17489 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
17490 +#else
17491 +#define VXH_SIZE       64
17492 +#endif
17493 +
17494 +struct _vx_history {
17495 +       unsigned int counter;
17496 +
17497 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
17498 +};
17499 +
17500 +
17501 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
17502 +
17503 +unsigned volatile int vxh_active = 1;
17504 +
17505 +static atomic_t sequence = ATOMIC_INIT(0);
17506 +
17507 +
17508 +/*     vxh_advance()
17509 +
17510 +       * requires disabled preemption                          */
17511 +
17512 +struct _vx_hist_entry *vxh_advance(void *loc)
17513 +{
17514 +       unsigned int cpu = smp_processor_id();
17515 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17516 +       struct _vx_hist_entry *entry;
17517 +       unsigned int index;
17518 +
17519 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
17520 +       entry = &hist->entry[index];
17521 +
17522 +       entry->seq = atomic_inc_return(&sequence);
17523 +       entry->loc = loc;
17524 +       return entry;
17525 +}
17526 +
17527 +EXPORT_SYMBOL_GPL(vxh_advance);
17528 +
17529 +
17530 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
17531 +
17532 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
17533 +
17534 +
17535 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
17536 +
17537 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
17538 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
17539 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
17540 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
17541 +
17542 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
17543 +{
17544 +       switch (e->type) {
17545 +       case VXH_THROW_OOPS:
17546 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
17547 +               break;
17548 +
17549 +       case VXH_GET_VX_INFO:
17550 +       case VXH_PUT_VX_INFO:
17551 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17552 +                       VXH_LOC_ARGS(e),
17553 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
17554 +                       VXH_VXI_ARGS(e));
17555 +               break;
17556 +
17557 +       case VXH_INIT_VX_INFO:
17558 +       case VXH_SET_VX_INFO:
17559 +       case VXH_CLR_VX_INFO:
17560 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17561 +                       VXH_LOC_ARGS(e),
17562 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
17563 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
17564 +                       VXH_VXI_ARGS(e), e->sc.data);
17565 +               break;
17566 +
17567 +       case VXH_CLAIM_VX_INFO:
17568 +       case VXH_RELEASE_VX_INFO:
17569 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17570 +                       VXH_LOC_ARGS(e),
17571 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
17572 +                       VXH_VXI_ARGS(e), e->sc.data);
17573 +               break;
17574 +
17575 +       case VXH_ALLOC_VX_INFO:
17576 +       case VXH_DEALLOC_VX_INFO:
17577 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17578 +                       VXH_LOC_ARGS(e),
17579 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
17580 +                       VXH_VXI_ARGS(e));
17581 +               break;
17582 +
17583 +       case VXH_HASH_VX_INFO:
17584 +       case VXH_UNHASH_VX_INFO:
17585 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
17586 +                       VXH_LOC_ARGS(e),
17587 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
17588 +                       VXH_VXI_ARGS(e));
17589 +               break;
17590 +
17591 +       case VXH_LOC_VX_INFO:
17592 +       case VXH_LOOKUP_VX_INFO:
17593 +       case VXH_CREATE_VX_INFO:
17594 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
17595 +                       VXH_LOC_ARGS(e),
17596 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
17597 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
17598 +                       e->ll.arg, VXH_VXI_ARGS(e));
17599 +               break;
17600 +       }
17601 +}
17602 +
17603 +static void __vxh_dump_history(void)
17604 +{
17605 +       unsigned int i, cpu;
17606 +
17607 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
17608 +               atomic_read(&sequence), NR_CPUS);
17609 +
17610 +       for (i = 0; i < VXH_SIZE; i++) {
17611 +               for_each_online_cpu(cpu) {
17612 +                       struct _vx_history *hist =
17613 +                               &per_cpu(vx_history_buffer, cpu);
17614 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
17615 +                       struct _vx_hist_entry *entry = &hist->entry[index];
17616 +
17617 +                       vxh_dump_entry(entry, cpu);
17618 +               }
17619 +       }
17620 +}
17621 +
17622 +void   vxh_dump_history(void)
17623 +{
17624 +       vxh_active = 0;
17625 +#ifdef CONFIG_SMP
17626 +       local_irq_enable();
17627 +       smp_send_stop();
17628 +       local_irq_disable();
17629 +#endif
17630 +       __vxh_dump_history();
17631 +}
17632 +
17633 +
17634 +/* vserver syscall commands below here */
17635 +
17636 +
17637 +int vc_dump_history(uint32_t id)
17638 +{
17639 +       vxh_active = 0;
17640 +       __vxh_dump_history();
17641 +       vxh_active = 1;
17642 +
17643 +       return 0;
17644 +}
17645 +
17646 +
17647 +int do_read_history(struct __user _vx_hist_entry *data,
17648 +       int cpu, uint32_t *index, uint32_t *count)
17649 +{
17650 +       int pos, ret = 0;
17651 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17652 +       int end = hist->counter;
17653 +       int start = end - VXH_SIZE + 2;
17654 +       int idx = *index;
17655 +
17656 +       /* special case: get current pos */
17657 +       if (!*count) {
17658 +               *index = end;
17659 +               return 0;
17660 +       }
17661 +
17662 +       /* have we lost some data? */
17663 +       if (idx < start)
17664 +               idx = start;
17665 +
17666 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
17667 +               struct _vx_hist_entry *entry =
17668 +                       &hist->entry[idx % VXH_SIZE];
17669 +
17670 +               /* send entry to userspace */
17671 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
17672 +               if (ret)
17673 +                       break;
17674 +       }
17675 +       /* save new index and count */
17676 +       *index = idx;
17677 +       *count = pos;
17678 +       return ret ? ret : (*index < end);
17679 +}
17680 +
17681 +int vc_read_history(uint32_t id, void __user *data)
17682 +{
17683 +       struct vcmd_read_history_v0 vc_data;
17684 +       int ret;
17685 +
17686 +       if (id >= NR_CPUS)
17687 +               return -EINVAL;
17688 +
17689 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17690 +               return -EFAULT;
17691 +
17692 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
17693 +               id, &vc_data.index, &vc_data.count);
17694 +
17695 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17696 +               return -EFAULT;
17697 +       return ret;
17698 +}
17699 +
17700 +#ifdef CONFIG_COMPAT
17701 +
17702 +int vc_read_history_x32(uint32_t id, void __user *data)
17703 +{
17704 +       struct vcmd_read_history_v0_x32 vc_data;
17705 +       int ret;
17706 +
17707 +       if (id >= NR_CPUS)
17708 +               return -EINVAL;
17709 +
17710 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17711 +               return -EFAULT;
17712 +
17713 +       ret = do_read_history((struct __user _vx_hist_entry *)
17714 +               compat_ptr(vc_data.data_ptr),
17715 +               id, &vc_data.index, &vc_data.count);
17716 +
17717 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17718 +               return -EFAULT;
17719 +       return ret;
17720 +}
17721 +
17722 +#endif /* CONFIG_COMPAT */
17723 +
17724 diff -NurpP --minimal linux-4.4.115/kernel/vserver/inet.c linux-4.4.115-vs2.3.9.7/kernel/vserver/inet.c
17725 --- linux-4.4.115/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
17726 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/inet.c       2018-01-09 16:36:34.000000000 +0000
17727 @@ -0,0 +1,236 @@
17728 +
17729 +#include <linux/in.h>
17730 +#include <linux/inetdevice.h>
17731 +#include <linux/export.h>
17732 +#include <linux/vs_inet.h>
17733 +#include <linux/vs_inet6.h>
17734 +#include <linux/vserver/debug.h>
17735 +#include <net/route.h>
17736 +#include <net/addrconf.h>
17737 +
17738 +
17739 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17740 +{
17741 +       int ret = 0;
17742 +
17743 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
17744 +               ret = 1;
17745 +       else {
17746 +               struct nx_addr_v4 *ptr;
17747 +               unsigned long irqflags;
17748 +
17749 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
17750 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
17751 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
17752 +                               ret = 1;
17753 +                               break;
17754 +                       }
17755 +               }
17756 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
17757 +       }
17758 +
17759 +       vxdprintk(VXD_CBIT(net, 2),
17760 +               "nx_v4_addr_conflict(%p,%p): %d",
17761 +               nxi1, nxi2, ret);
17762 +
17763 +       return ret;
17764 +}
17765 +
17766 +
17767 +#ifdef CONFIG_IPV6
17768 +
17769 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17770 +{
17771 +       int ret = 0;
17772 +
17773 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
17774 +               ret = 1;
17775 +       else {
17776 +               struct nx_addr_v6 *ptr;
17777 +               unsigned long irqflags;
17778 +
17779 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
17780 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
17781 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
17782 +                               ret = 1;
17783 +                               break;
17784 +                       }
17785 +               }
17786 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
17787 +       }
17788 +
17789 +       vxdprintk(VXD_CBIT(net, 2),
17790 +               "nx_v6_addr_conflict(%p,%p): %d",
17791 +               nxi1, nxi2, ret);
17792 +
17793 +       return ret;
17794 +}
17795 +
17796 +#endif
17797 +
17798 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
17799 +{
17800 +       struct in_device *in_dev;
17801 +       struct in_ifaddr **ifap;
17802 +       struct in_ifaddr *ifa;
17803 +       int ret = 0;
17804 +
17805 +       if (!dev)
17806 +               goto out;
17807 +       in_dev = in_dev_get(dev);
17808 +       if (!in_dev)
17809 +               goto out;
17810 +
17811 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
17812 +               ifap = &ifa->ifa_next) {
17813 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
17814 +                       ret = 1;
17815 +                       break;
17816 +               }
17817 +       }
17818 +       in_dev_put(in_dev);
17819 +out:
17820 +       return ret;
17821 +}
17822 +
17823 +
17824 +#ifdef CONFIG_IPV6
17825 +
17826 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
17827 +{
17828 +       struct inet6_dev *in_dev;
17829 +       struct inet6_ifaddr *ifa;
17830 +       int ret = 0;
17831 +
17832 +       if (!dev)
17833 +               goto out;
17834 +       in_dev = in6_dev_get(dev);
17835 +       if (!in_dev)
17836 +               goto out;
17837 +
17838 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
17839 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
17840 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
17841 +                       ret = 1;
17842 +                       break;
17843 +               }
17844 +       }
17845 +       in6_dev_put(in_dev);
17846 +out:
17847 +       return ret;
17848 +}
17849 +
17850 +#endif
17851 +
17852 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
17853 +{
17854 +       int ret = 1;
17855 +
17856 +       if (!nxi)
17857 +               goto out;
17858 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
17859 +               goto out;
17860 +#ifdef CONFIG_IPV6
17861 +       ret = 2;
17862 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
17863 +               goto out;
17864 +#endif
17865 +       ret = 0;
17866 +out:
17867 +       vxdprintk(VXD_CBIT(net, 3),
17868 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
17869 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
17870 +       return ret;
17871 +}
17872 +
17873 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
17874 +       struct flowi4 *fl4)
17875 +{
17876 +       struct rtable *rt;
17877 +
17878 +       if (!nxi)
17879 +               return NULL;
17880 +
17881 +       /* FIXME: handle lback only case */
17882 +       if (!NX_IPV4(nxi))
17883 +               return ERR_PTR(-EPERM);
17884 +
17885 +       vxdprintk(VXD_CBIT(net, 4),
17886 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
17887 +               nxi, nxi ? nxi->nx_id : 0,
17888 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
17889 +
17890 +       /* single IP is unconditional */
17891 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
17892 +               (fl4->saddr == INADDR_ANY))
17893 +               fl4->saddr = nxi->v4.ip[0].s_addr;
17894 +
17895 +       if (fl4->saddr == INADDR_ANY) {
17896 +               struct nx_addr_v4 *ptr;
17897 +               __be32 found = 0;
17898 +
17899 +               rt = __ip_route_output_key(net, fl4);
17900 +               if (!IS_ERR(rt)) {
17901 +                       found = fl4->saddr;
17902 +                       ip_rt_put(rt);
17903 +                       vxdprintk(VXD_CBIT(net, 4),
17904 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
17905 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
17906 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
17907 +                               goto found;
17908 +               }
17909 +
17910 +               WARN_ON_ONCE(in_irq());
17911 +               spin_lock_bh(&nxi->addr_lock);
17912 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
17913 +                       __be32 primary = ptr->ip[0].s_addr;
17914 +                       __be32 mask = ptr->mask.s_addr;
17915 +                       __be32 neta = primary & mask;
17916 +
17917 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
17918 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
17919 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
17920 +                               NIPQUAD(mask), NIPQUAD(neta));
17921 +                       if ((found & mask) != neta)
17922 +                               continue;
17923 +
17924 +                       fl4->saddr = primary;
17925 +                       rt = __ip_route_output_key(net, fl4);
17926 +                       vxdprintk(VXD_CBIT(net, 4),
17927 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
17928 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
17929 +                       if (!IS_ERR(rt)) {
17930 +                               found = fl4->saddr;
17931 +                               ip_rt_put(rt);
17932 +                               if (found == primary)
17933 +                                       goto found_unlock;
17934 +                       }
17935 +               }
17936 +               /* still no source ip? */
17937 +               found = ipv4_is_loopback(fl4->daddr)
17938 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
17939 +       found_unlock:
17940 +               spin_unlock_bh(&nxi->addr_lock);
17941 +       found:
17942 +               /* assign src ip to flow */
17943 +               fl4->saddr = found;
17944 +
17945 +       } else {
17946 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
17947 +                       return ERR_PTR(-EPERM);
17948 +       }
17949 +
17950 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
17951 +               if (ipv4_is_loopback(fl4->daddr))
17952 +                       fl4->daddr = nxi->v4_lback.s_addr;
17953 +               if (ipv4_is_loopback(fl4->saddr))
17954 +                       fl4->saddr = nxi->v4_lback.s_addr;
17955 +       } else if (ipv4_is_loopback(fl4->daddr) &&
17956 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
17957 +               return ERR_PTR(-EPERM);
17958 +
17959 +       return NULL;
17960 +}
17961 +
17962 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
17963 +
17964 diff -NurpP --minimal linux-4.4.115/kernel/vserver/init.c linux-4.4.115-vs2.3.9.7/kernel/vserver/init.c
17965 --- linux-4.4.115/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
17966 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/init.c       2018-01-09 22:31:39.000000000 +0000
17967 @@ -0,0 +1,46 @@
17968 +/*
17969 + *  linux/kernel/init.c
17970 + *
17971 + *  Virtual Server Init
17972 + *
17973 + *  Copyright (C) 2004-2007  Herbert Pötzl
17974 + *
17975 + *  V0.01  basic structure
17976 + *
17977 + */
17978 +
17979 +#include <linux/init.h>
17980 +#include <linux/module.h>
17981 +
17982 +int    vserver_register_sysctl(void);
17983 +void   vserver_unregister_sysctl(void);
17984 +
17985 +
17986 +static int __init init_vserver(void)
17987 +{
17988 +       int ret = 0;
17989 +
17990 +#ifdef CONFIG_VSERVER_DEBUG
17991 +       vserver_register_sysctl();
17992 +#endif
17993 +       return ret;
17994 +}
17995 +
17996 +
17997 +static void __exit exit_vserver(void)
17998 +{
17999 +
18000 +#ifdef CONFIG_VSERVER_DEBUG
18001 +       vserver_unregister_sysctl();
18002 +#endif
18003 +       return;
18004 +}
18005 +
18006 +/* FIXME: GFP_ZONETYPES gone
18007 +long vx_slab[GFP_ZONETYPES]; */
18008 +long vx_area;
18009 +
18010 +
18011 +module_init(init_vserver);
18012 +module_exit(exit_vserver);
18013 +
18014 diff -NurpP --minimal linux-4.4.115/kernel/vserver/inode.c linux-4.4.115-vs2.3.9.7/kernel/vserver/inode.c
18015 --- linux-4.4.115/kernel/vserver/inode.c        1970-01-01 00:00:00.000000000 +0000
18016 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/inode.c      2018-01-09 22:24:56.000000000 +0000
18017 @@ -0,0 +1,440 @@
18018 +/*
18019 + *  linux/kernel/vserver/inode.c
18020 + *
18021 + *  Virtual Server: File System Support
18022 + *
18023 + *  Copyright (C) 2004-2007  Herbert Pötzl
18024 + *
18025 + *  V0.01  separated from vcontext V0.05
18026 + *  V0.02  moved to tag (instead of xid)
18027 + *
18028 + */
18029 +
18030 +#include <linux/tty.h>
18031 +#include <linux/proc_fs.h>
18032 +#include <linux/devpts_fs.h>
18033 +#include <linux/fs.h>
18034 +#include <linux/file.h>
18035 +#include <linux/mount.h>
18036 +#include <linux/parser.h>
18037 +#include <linux/namei.h>
18038 +#include <linux/magic.h>
18039 +#include <linux/slab.h>
18040 +#include <linux/vserver/inode.h>
18041 +#include <linux/vserver/inode_cmd.h>
18042 +#include <linux/vs_base.h>
18043 +#include <linux/vs_tag.h>
18044 +
18045 +#include <asm/uaccess.h>
18046 +#include <../../fs/proc/internal.h>
18047 +
18048 +
18049 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18050 +{
18051 +       struct proc_dir_entry *entry;
18052 +
18053 +       if (!in || !in->i_sb)
18054 +               return -ESRCH;
18055 +
18056 +       *flags = IATTR_TAG
18057 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18058 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18059 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18060 +               | (IS_COW(in) ? IATTR_COW : 0);
18061 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18062 +
18063 +       if (S_ISDIR(in->i_mode))
18064 +               *mask |= IATTR_BARRIER;
18065 +
18066 +       if (IS_TAGGED(in)) {
18067 +               *tag = i_tag_read(in);
18068 +               *mask |= IATTR_TAG;
18069 +       }
18070 +
18071 +       switch (in->i_sb->s_magic) {
18072 +       case PROC_SUPER_MAGIC:
18073 +               entry = PROC_I(in)->pde;
18074 +
18075 +               /* check for specific inodes? */
18076 +               if (entry)
18077 +                       *mask |= IATTR_FLAGS;
18078 +               if (entry)
18079 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
18080 +               else
18081 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
18082 +               break;
18083 +
18084 +       case DEVPTS_SUPER_MAGIC:
18085 +               *tag = i_tag_read(in);
18086 +               *mask |= IATTR_TAG;
18087 +               break;
18088 +
18089 +       default:
18090 +               break;
18091 +       }
18092 +       return 0;
18093 +}
18094 +
18095 +int vc_get_iattr(void __user *data)
18096 +{
18097 +       struct path path;
18098 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
18099 +       int ret;
18100 +
18101 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18102 +               return -EFAULT;
18103 +
18104 +       ret = user_lpath(vc_data.name, &path);
18105 +       if (!ret) {
18106 +               ret = __vc_get_iattr(path.dentry->d_inode,
18107 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18108 +               path_put(&path);
18109 +       }
18110 +       if (ret)
18111 +               return ret;
18112 +
18113 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18114 +               ret = -EFAULT;
18115 +       return ret;
18116 +}
18117 +
18118 +#ifdef CONFIG_COMPAT
18119 +
18120 +int vc_get_iattr_x32(void __user *data)
18121 +{
18122 +       struct path path;
18123 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
18124 +       int ret;
18125 +
18126 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18127 +               return -EFAULT;
18128 +
18129 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18130 +       if (!ret) {
18131 +               ret = __vc_get_iattr(path.dentry->d_inode,
18132 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18133 +               path_put(&path);
18134 +       }
18135 +       if (ret)
18136 +               return ret;
18137 +
18138 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18139 +               ret = -EFAULT;
18140 +       return ret;
18141 +}
18142 +
18143 +#endif /* CONFIG_COMPAT */
18144 +
18145 +
18146 +int vc_fget_iattr(uint32_t fd, void __user *data)
18147 +{
18148 +       struct file *filp;
18149 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
18150 +       int ret;
18151 +
18152 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18153 +               return -EFAULT;
18154 +
18155 +       filp = fget(fd);
18156 +       if (!filp || !filp->f_path.dentry || !filp->f_path.dentry->d_inode)
18157 +               return -EBADF;
18158 +
18159 +       ret = __vc_get_iattr(filp->f_path.dentry->d_inode,
18160 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
18161 +
18162 +       fput(filp);
18163 +
18164 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18165 +               ret = -EFAULT;
18166 +       return ret;
18167 +}
18168 +
18169 +
18170 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18171 +{
18172 +       struct inode *in = de->d_inode;
18173 +       int error = 0, is_proc = 0, has_tag = 0;
18174 +       struct iattr attr = { 0 };
18175 +
18176 +       if (!in || !in->i_sb)
18177 +               return -ESRCH;
18178 +
18179 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
18180 +       if ((*mask & IATTR_FLAGS) && !is_proc)
18181 +               return -EINVAL;
18182 +
18183 +       has_tag = IS_TAGGED(in) ||
18184 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
18185 +       if ((*mask & IATTR_TAG) && !has_tag)
18186 +               return -EINVAL;
18187 +
18188 +       mutex_lock(&in->i_mutex);
18189 +       if (*mask & IATTR_TAG) {
18190 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
18191 +               attr.ia_valid |= ATTR_TAG;
18192 +       }
18193 +
18194 +       if (*mask & IATTR_FLAGS) {
18195 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
18196 +               unsigned int iflags = PROC_I(in)->vx_flags;
18197 +
18198 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
18199 +                       | (*flags & IATTR_FLAGS);
18200 +               PROC_I(in)->vx_flags = iflags;
18201 +               if (entry)
18202 +                       entry->vx_flags = iflags;
18203 +       }
18204 +
18205 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
18206 +               IATTR_BARRIER | IATTR_COW)) {
18207 +               int iflags = in->i_flags;
18208 +               int vflags = in->i_vflags;
18209 +
18210 +               if (*mask & IATTR_IMMUTABLE) {
18211 +                       if (*flags & IATTR_IMMUTABLE)
18212 +                               iflags |= S_IMMUTABLE;
18213 +                       else
18214 +                               iflags &= ~S_IMMUTABLE;
18215 +               }
18216 +               if (*mask & IATTR_IXUNLINK) {
18217 +                       if (*flags & IATTR_IXUNLINK)
18218 +                               iflags |= S_IXUNLINK;
18219 +                       else
18220 +                               iflags &= ~S_IXUNLINK;
18221 +               }
18222 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
18223 +                       if (*flags & IATTR_BARRIER)
18224 +                               vflags |= V_BARRIER;
18225 +                       else
18226 +                               vflags &= ~V_BARRIER;
18227 +               }
18228 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
18229 +                       if (*flags & IATTR_COW)
18230 +                               vflags |= V_COW;
18231 +                       else
18232 +                               vflags &= ~V_COW;
18233 +               }
18234 +               if (in->i_op && in->i_op->sync_flags) {
18235 +                       error = in->i_op->sync_flags(in, iflags, vflags);
18236 +                       if (error)
18237 +                               goto out;
18238 +               }
18239 +       }
18240 +
18241 +       if (attr.ia_valid) {
18242 +               if (in->i_op && in->i_op->setattr)
18243 +                       error = in->i_op->setattr(de, &attr);
18244 +               else {
18245 +                       error = inode_change_ok(in, &attr);
18246 +                       if (!error) {
18247 +                               setattr_copy(in, &attr);
18248 +                               mark_inode_dirty(in);
18249 +                       }
18250 +               }
18251 +       }
18252 +
18253 +out:
18254 +       mutex_unlock(&in->i_mutex);
18255 +       return error;
18256 +}
18257 +
18258 +int vc_set_iattr(void __user *data)
18259 +{
18260 +       struct path path;
18261 +       struct vcmd_ctx_iattr_v1 vc_data;
18262 +       int ret;
18263 +
18264 +       if (!capable(CAP_LINUX_IMMUTABLE))
18265 +               return -EPERM;
18266 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18267 +               return -EFAULT;
18268 +
18269 +       ret = user_lpath(vc_data.name, &path);
18270 +       if (!ret) {
18271 +               ret = __vc_set_iattr(path.dentry,
18272 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18273 +               path_put(&path);
18274 +       }
18275 +
18276 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18277 +               ret = -EFAULT;
18278 +       return ret;
18279 +}
18280 +
18281 +#ifdef CONFIG_COMPAT
18282 +
18283 +int vc_set_iattr_x32(void __user *data)
18284 +{
18285 +       struct path path;
18286 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
18287 +       int ret;
18288 +
18289 +       if (!capable(CAP_LINUX_IMMUTABLE))
18290 +               return -EPERM;
18291 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18292 +               return -EFAULT;
18293 +
18294 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18295 +       if (!ret) {
18296 +               ret = __vc_set_iattr(path.dentry,
18297 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18298 +               path_put(&path);
18299 +       }
18300 +
18301 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18302 +               ret = -EFAULT;
18303 +       return ret;
18304 +}
18305 +
18306 +#endif /* CONFIG_COMPAT */
18307 +
18308 +int vc_fset_iattr(uint32_t fd, void __user *data)
18309 +{
18310 +       struct file *filp;
18311 +       struct vcmd_ctx_fiattr_v0 vc_data;
18312 +       int ret;
18313 +
18314 +       if (!capable(CAP_LINUX_IMMUTABLE))
18315 +               return -EPERM;
18316 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18317 +               return -EFAULT;
18318 +
18319 +       filp = fget(fd);
18320 +       if (!filp || !filp->f_path.dentry || !filp->f_path.dentry->d_inode)
18321 +               return -EBADF;
18322 +
18323 +       ret = __vc_set_iattr(filp->f_path.dentry, &vc_data.tag,
18324 +               &vc_data.flags, &vc_data.mask);
18325 +
18326 +       fput(filp);
18327 +
18328 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18329 +               return -EFAULT;
18330 +       return ret;
18331 +}
18332 +
18333 +
18334 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
18335 +
18336 +static match_table_t tokens = {
18337 +       {Opt_notagcheck, "notagcheck"},
18338 +#ifdef CONFIG_PROPAGATE
18339 +       {Opt_notag, "notag"},
18340 +       {Opt_tag, "tag"},
18341 +       {Opt_tagid, "tagid=%u"},
18342 +#endif
18343 +       {Opt_err, NULL}
18344 +};
18345 +
18346 +
18347 +static void __dx_parse_remove(char *string, char *opt)
18348 +{
18349 +       char *p = strstr(string, opt);
18350 +       char *q = p;
18351 +
18352 +       if (p) {
18353 +               while (*q != '\0' && *q != ',')
18354 +                       q++;
18355 +               while (*q)
18356 +                       *p++ = *q++;
18357 +               while (*p)
18358 +                       *p++ = '\0';
18359 +       }
18360 +}
18361 +
18362 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
18363 +                unsigned long *flags)
18364 +{
18365 +       int set = 0;
18366 +       substring_t args[MAX_OPT_ARGS];
18367 +       int token;
18368 +       char *s, *p, *opts;
18369 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
18370 +       int option = 0;
18371 +#endif
18372 +
18373 +       if (!string)
18374 +               return 0;
18375 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
18376 +       if (!s)
18377 +               return 0;
18378 +
18379 +       opts = s;
18380 +       while ((p = strsep(&opts, ",")) != NULL) {
18381 +               token = match_token(p, tokens, args);
18382 +
18383 +               switch (token) {
18384 +#ifdef CONFIG_PROPAGATE
18385 +               case Opt_tag:
18386 +                       if (tag)
18387 +                               *tag = 0;
18388 +                       if (remove)
18389 +                               __dx_parse_remove(s, "tag");
18390 +                       *mnt_flags |= MNT_TAGID;
18391 +                       set |= MNT_TAGID;
18392 +                       break;
18393 +               case Opt_notag:
18394 +                       if (remove)
18395 +                               __dx_parse_remove(s, "notag");
18396 +                       *mnt_flags |= MNT_NOTAG;
18397 +                       set |= MNT_NOTAG;
18398 +                       break;
18399 +               case Opt_tagid:
18400 +                       if (tag && !match_int(args, &option))
18401 +                               *tag = option;
18402 +                       if (remove)
18403 +                               __dx_parse_remove(s, "tagid");
18404 +                       *mnt_flags |= MNT_TAGID;
18405 +                       set |= MNT_TAGID;
18406 +                       break;
18407 +#endif /* CONFIG_PROPAGATE */
18408 +               case Opt_notagcheck:
18409 +                       if (remove)
18410 +                               __dx_parse_remove(s, "notagcheck");
18411 +                       *flags |= MS_NOTAGCHECK;
18412 +                       set |= MS_NOTAGCHECK;
18413 +                       break;
18414 +               }
18415 +               vxdprintk(VXD_CBIT(tag, 7),
18416 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
18417 +                       p, token, option);
18418 +       }
18419 +       if (set)
18420 +               strcpy(string, s);
18421 +       kfree(s);
18422 +       return set;
18423 +}
18424 +
18425 +#ifdef CONFIG_PROPAGATE
18426 +
18427 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
18428 +{
18429 +       vtag_t new_tag = 0;
18430 +       struct vfsmount *mnt;
18431 +       int propagate;
18432 +
18433 +       if (!nd)
18434 +               return;
18435 +       mnt = nd->path.mnt;
18436 +       if (!mnt)
18437 +               return;
18438 +
18439 +       propagate = (mnt->mnt_flags & MNT_TAGID);
18440 +       if (propagate)
18441 +               new_tag = mnt->mnt_tag;
18442 +
18443 +       vxdprintk(VXD_CBIT(tag, 7),
18444 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
18445 +               inode, inode->i_ino, inode->i_tag,
18446 +               new_tag, (propagate) ? 1 : 0);
18447 +
18448 +       if (propagate)
18449 +               i_tag_write(inode, new_tag);
18450 +}
18451 +
18452 +#include <linux/module.h>
18453 +
18454 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
18455 +
18456 +#endif /* CONFIG_PROPAGATE */
18457 +
18458 diff -NurpP --minimal linux-4.4.115/kernel/vserver/limit.c linux-4.4.115-vs2.3.9.7/kernel/vserver/limit.c
18459 --- linux-4.4.115/kernel/vserver/limit.c        1970-01-01 00:00:00.000000000 +0000
18460 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/limit.c      2018-01-24 23:13:15.000000000 +0000
18461 @@ -0,0 +1,386 @@
18462 +/*
18463 + *  linux/kernel/vserver/limit.c
18464 + *
18465 + *  Virtual Server: Context Limits
18466 + *
18467 + *  Copyright (C) 2004-2010  Herbert Pötzl
18468 + *
18469 + *  V0.01  broken out from vcontext V0.05
18470 + *  V0.02  changed vcmds to vxi arg
18471 + *  V0.03  added memory cgroup support
18472 + *
18473 + */
18474 +
18475 +#include <linux/sched.h>
18476 +#include <linux/module.h>
18477 +#include <linux/memcontrol.h>
18478 +#include <linux/page_counter.h>
18479 +#include <linux/vs_limit.h>
18480 +#include <linux/vserver/limit.h>
18481 +#include <linux/vserver/limit_cmd.h>
18482 +
18483 +#include <asm/uaccess.h>
18484 +
18485 +
18486 +const char *vlimit_name[NUM_LIMITS] = {
18487 +       [RLIMIT_CPU]            = "CPU",
18488 +       [RLIMIT_NPROC]          = "NPROC",
18489 +       [RLIMIT_NOFILE]         = "NOFILE",
18490 +       [RLIMIT_LOCKS]          = "LOCKS",
18491 +       [RLIMIT_SIGPENDING]     = "SIGP",
18492 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
18493 +
18494 +       [VLIMIT_NSOCK]          = "NSOCK",
18495 +       [VLIMIT_OPENFD]         = "OPENFD",
18496 +       [VLIMIT_SHMEM]          = "SHMEM",
18497 +       [VLIMIT_DENTRY]         = "DENTRY",
18498 +};
18499 +
18500 +EXPORT_SYMBOL_GPL(vlimit_name);
18501 +
18502 +#define MASK_ENTRY(x)  (1 << (x))
18503 +
18504 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
18505 +               /* minimum */
18506 +       0
18507 +       ,       /* softlimit */
18508 +       0
18509 +       ,       /* maximum */
18510 +       MASK_ENTRY( RLIMIT_NPROC        ) |
18511 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
18512 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
18513 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
18514 +
18515 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
18516 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
18517 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
18518 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
18519 +       0
18520 +};
18521 +               /* accounting only */
18522 +uint32_t account_mask =
18523 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
18524 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
18525 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
18526 +       0;
18527 +
18528 +
18529 +static int is_valid_vlimit(int id)
18530 +{
18531 +       uint32_t mask = vlimit_mask.minimum |
18532 +               vlimit_mask.softlimit | vlimit_mask.maximum;
18533 +       return mask & (1 << id);
18534 +}
18535 +
18536 +static int is_accounted_vlimit(int id)
18537 +{
18538 +       if (is_valid_vlimit(id))
18539 +               return 1;
18540 +       return account_mask & (1 << id);
18541 +}
18542 +
18543 +
18544 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
18545 +{
18546 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
18547 +       return VX_VLIM(limit);
18548 +}
18549 +
18550 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
18551 +{
18552 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
18553 +       return VX_VLIM(limit);
18554 +}
18555 +
18556 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
18557 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
18558 +{
18559 +       if (!is_valid_vlimit(id))
18560 +               return -EINVAL;
18561 +
18562 +       if (minimum)
18563 +               *minimum = CRLIM_UNSET;
18564 +       if (softlimit)
18565 +               *softlimit = vc_get_soft(vxi, id);
18566 +       if (maximum)
18567 +               *maximum = vc_get_hard(vxi, id);
18568 +       return 0;
18569 +}
18570 +
18571 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
18572 +{
18573 +       struct vcmd_ctx_rlimit_v0 vc_data;
18574 +       int ret;
18575 +
18576 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18577 +               return -EFAULT;
18578 +
18579 +       ret = do_get_rlimit(vxi, vc_data.id,
18580 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18581 +       if (ret)
18582 +               return ret;
18583 +
18584 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18585 +               return -EFAULT;
18586 +       return 0;
18587 +}
18588 +
18589 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
18590 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
18591 +{
18592 +       if (!is_valid_vlimit(id))
18593 +               return -EINVAL;
18594 +
18595 +       if (maximum != CRLIM_KEEP)
18596 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
18597 +       if (softlimit != CRLIM_KEEP)
18598 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
18599 +
18600 +       /* clamp soft limit */
18601 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
18602 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
18603 +
18604 +       return 0;
18605 +}
18606 +
18607 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
18608 +{
18609 +       struct vcmd_ctx_rlimit_v0 vc_data;
18610 +
18611 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18612 +               return -EFAULT;
18613 +
18614 +       return do_set_rlimit(vxi, vc_data.id,
18615 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18616 +}
18617 +
18618 +#ifdef CONFIG_IA32_EMULATION
18619 +
18620 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
18621 +{
18622 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18623 +
18624 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18625 +               return -EFAULT;
18626 +
18627 +       return do_set_rlimit(vxi, vc_data.id,
18628 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18629 +}
18630 +
18631 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
18632 +{
18633 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18634 +       int ret;
18635 +
18636 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18637 +               return -EFAULT;
18638 +
18639 +       ret = do_get_rlimit(vxi, vc_data.id,
18640 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18641 +       if (ret)
18642 +               return ret;
18643 +
18644 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18645 +               return -EFAULT;
18646 +       return 0;
18647 +}
18648 +
18649 +#endif /* CONFIG_IA32_EMULATION */
18650 +
18651 +
18652 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
18653 +{
18654 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
18655 +               return -EFAULT;
18656 +       return 0;
18657 +}
18658 +
18659 +
18660 +static inline void vx_reset_hits(struct _vx_limit *limit)
18661 +{
18662 +       int lim;
18663 +
18664 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18665 +               atomic_set(&__rlim_lhit(limit, lim), 0);
18666 +       }
18667 +}
18668 +
18669 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
18670 +{
18671 +       vx_reset_hits(&vxi->limit);
18672 +       return 0;
18673 +}
18674 +
18675 +static inline void vx_reset_minmax(struct _vx_limit *limit)
18676 +{
18677 +       rlim_t value;
18678 +       int lim;
18679 +
18680 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18681 +               value = __rlim_get(limit, lim);
18682 +               __rlim_rmax(limit, lim) = value;
18683 +               __rlim_rmin(limit, lim) = value;
18684 +       }
18685 +}
18686 +
18687 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
18688 +{
18689 +       vx_reset_minmax(&vxi->limit);
18690 +       return 0;
18691 +}
18692 +
18693 +
18694 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
18695 +{
18696 +       struct vcmd_rlimit_stat_v0 vc_data;
18697 +       struct _vx_limit *limit = &vxi->limit;
18698 +       int id;
18699 +
18700 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18701 +               return -EFAULT;
18702 +
18703 +       id = vc_data.id;
18704 +       if (!is_accounted_vlimit(id))
18705 +               return -EINVAL;
18706 +
18707 +       vx_limit_fixup(limit, id);
18708 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
18709 +       vc_data.value = __rlim_get(limit, id);
18710 +       vc_data.minimum = __rlim_rmin(limit, id);
18711 +       vc_data.maximum = __rlim_rmax(limit, id);
18712 +
18713 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18714 +               return -EFAULT;
18715 +       return 0;
18716 +}
18717 +
18718 +
18719 +#ifdef CONFIG_MEMCG
18720 +
18721 +void dump_sysinfo(struct sysinfo *si)
18722 +{
18723 +       printk(KERN_INFO "sysinfo: memunit=%u\n"
18724 +               "\ttotalram:\t%lu\n"
18725 +               "\tfreeram:\t%lu\n"
18726 +               "\tsharedram:\t%lu\n"
18727 +               "\tbufferram:\t%lu\n"
18728 +               "\ttotalswap:\t%lu\n"
18729 +               "\tfreeswap:\t%lu\n"
18730 +               "\ttotalhigh:\t%lu\n"
18731 +               "\tfreehigh:\t%lu\n",
18732 +               si->mem_unit,
18733 +               si->totalram,
18734 +               si->freeram,
18735 +               si->sharedram,
18736 +               si->bufferram,
18737 +               si->totalswap,
18738 +               si->freeswap,
18739 +               si->totalhigh,
18740 +               si->freehigh);
18741 +}
18742 +
18743 +void vx_vsi_meminfo(struct sysinfo *val)
18744 +{
18745 +       struct mem_cgroup *mcg;
18746 +       unsigned long res_limit, res_usage;
18747 +       unsigned shift;
18748 +
18749 +       if (VXD_CBIT(cvirt, 4))
18750 +               dump_sysinfo(val);
18751 +
18752 +       rcu_read_lock();
18753 +       mcg = mem_cgroup_from_task(current);
18754 +       if (VXD_CBIT(cvirt, 5))
18755 +               dump_mem_cgroup(mcg);
18756 +       rcu_read_unlock();
18757 +       if (!mcg)
18758 +               goto out;
18759 +
18760 +       res_limit = mem_cgroup_mem_limit_pages(mcg);
18761 +       res_usage = mem_cgroup_mem_usage_pages(mcg);
18762 +       shift = val->mem_unit == 1 ? PAGE_SHIFT : 0;
18763 +
18764 +       if (res_limit != PAGE_COUNTER_MAX)
18765 +               val->totalram = res_limit << shift;
18766 +       val->freeram = val->totalram - (res_usage << shift);
18767 +       val->bufferram = 0;
18768 +       val->totalhigh = 0;
18769 +       val->freehigh = 0;
18770 +out:
18771 +       return;
18772 +}
18773 +
18774 +void vx_vsi_swapinfo(struct sysinfo *val)
18775 +{
18776 +#ifdef CONFIG_MEMCG_SWAP
18777 +       struct mem_cgroup *mcg;
18778 +       unsigned long res_limit, res_usage, memsw_limit, memsw_usage;
18779 +       signed long swap_limit, swap_usage;
18780 +       unsigned shift;
18781 +
18782 +       if (VXD_CBIT(cvirt, 6))
18783 +               dump_sysinfo(val);
18784 +
18785 +       rcu_read_lock();
18786 +       mcg = mem_cgroup_from_task(current);
18787 +       if (VXD_CBIT(cvirt, 7))
18788 +               dump_mem_cgroup(mcg);
18789 +       rcu_read_unlock();
18790 +       if (!mcg)
18791 +               goto out;
18792 +
18793 +       res_limit = mem_cgroup_mem_limit_pages(mcg);
18794 +
18795 +       /* memory unlimited */
18796 +       if (res_limit == PAGE_COUNTER_MAX)
18797 +               goto out;
18798 +
18799 +       res_usage = mem_cgroup_mem_usage_pages(mcg);
18800 +       memsw_limit = mem_cgroup_memsw_limit_pages(mcg);
18801 +       memsw_usage = mem_cgroup_memsw_usage_pages(mcg);
18802 +       shift = val->mem_unit == 1 ? PAGE_SHIFT : 0;
18803 +
18804 +       swap_limit = memsw_limit - res_limit;
18805 +       /* we have a swap limit? */
18806 +       if (memsw_limit != PAGE_COUNTER_MAX)
18807 +               val->totalswap = swap_limit << shift;
18808 +
18809 +       /* calculate swap part */
18810 +       swap_usage = (memsw_usage > res_usage) ?
18811 +               memsw_usage - res_usage : 0;
18812 +
18813 +       /* total shown minus usage gives free swap */
18814 +       val->freeswap = (swap_usage < swap_limit) ?
18815 +               val->totalswap - (swap_usage << shift) : 0;
18816 +out:
18817 +#else  /* !CONFIG_MEMCG_SWAP */
18818 +       val->totalswap = 0;
18819 +       val->freeswap = 0;
18820 +#endif /* !CONFIG_MEMCG_SWAP */
18821 +       return;
18822 +}
18823 +
18824 +long vx_vsi_cached(struct sysinfo *val)
18825 +{
18826 +       long cache = 0;
18827 +#ifdef CONFIG_MEMCG_BROKEN
18828 +       struct mem_cgroup *mcg;
18829 +
18830 +       if (VXD_CBIT(cvirt, 8))
18831 +               dump_sysinfo(val);
18832 +
18833 +       rcu_read_lock();
18834 +       mcg = mem_cgroup_from_task(current);
18835 +       if (VXD_CBIT(cvirt, 9))
18836 +               dump_mem_cgroup(mcg);
18837 +       rcu_read_unlock();
18838 +       if (!mcg)
18839 +               goto out;
18840 +
18841 +       // cache = mem_cgroup_stat_read_cache(mcg);
18842 +out:
18843 +#endif
18844 +       return cache;
18845 +}
18846 +#endif /* !CONFIG_MEMCG */
18847 +
18848 diff -NurpP --minimal linux-4.4.115/kernel/vserver/limit_init.h linux-4.4.115-vs2.3.9.7/kernel/vserver/limit_init.h
18849 --- linux-4.4.115/kernel/vserver/limit_init.h   1970-01-01 00:00:00.000000000 +0000
18850 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/limit_init.h 2018-01-09 16:36:34.000000000 +0000
18851 @@ -0,0 +1,31 @@
18852 +
18853 +
18854 +static inline void vx_info_init_limit(struct _vx_limit *limit)
18855 +{
18856 +       int lim;
18857 +
18858 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18859 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
18860 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
18861 +               __rlim_set(limit, lim, 0);
18862 +               atomic_set(&__rlim_lhit(limit, lim), 0);
18863 +               __rlim_rmin(limit, lim) = 0;
18864 +               __rlim_rmax(limit, lim) = 0;
18865 +       }
18866 +}
18867 +
18868 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
18869 +{
18870 +       rlim_t value;
18871 +       int lim;
18872 +
18873 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18874 +               if ((1 << lim) & VLIM_NOCHECK)
18875 +                       continue;
18876 +               value = __rlim_get(limit, lim);
18877 +               vxwprintk_xid(value,
18878 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
18879 +                       limit, vlimit_name[lim], lim, (long)value);
18880 +       }
18881 +}
18882 +
18883 diff -NurpP --minimal linux-4.4.115/kernel/vserver/limit_proc.h linux-4.4.115-vs2.3.9.7/kernel/vserver/limit_proc.h
18884 --- linux-4.4.115/kernel/vserver/limit_proc.h   1970-01-01 00:00:00.000000000 +0000
18885 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/limit_proc.h 2018-01-09 16:36:34.000000000 +0000
18886 @@ -0,0 +1,57 @@
18887 +#ifndef _VX_LIMIT_PROC_H
18888 +#define _VX_LIMIT_PROC_H
18889 +
18890 +#include <linux/vserver/limit_int.h>
18891 +
18892 +
18893 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
18894 +#define VX_LIMIT_TOP   \
18895 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
18896 +
18897 +#define VX_LIMIT_ARG(r)                                \
18898 +       (unsigned long)__rlim_get(limit, r),    \
18899 +       (unsigned long)__rlim_rmin(limit, r),   \
18900 +       (unsigned long)__rlim_rmax(limit, r),   \
18901 +       VX_VLIM(__rlim_soft(limit, r)),         \
18902 +       VX_VLIM(__rlim_hard(limit, r)),         \
18903 +       atomic_read(&__rlim_lhit(limit, r))
18904 +
18905 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
18906 +{
18907 +       vx_limit_fixup(limit, -1);
18908 +       return sprintf(buffer, VX_LIMIT_TOP
18909 +               "PROC"  VX_LIMIT_FMT
18910 +               "VM"    VX_LIMIT_FMT
18911 +               "VML"   VX_LIMIT_FMT
18912 +               "RSS"   VX_LIMIT_FMT
18913 +               "ANON"  VX_LIMIT_FMT
18914 +               "RMAP"  VX_LIMIT_FMT
18915 +               "FILES" VX_LIMIT_FMT
18916 +               "OFD"   VX_LIMIT_FMT
18917 +               "LOCKS" VX_LIMIT_FMT
18918 +               "SOCK"  VX_LIMIT_FMT
18919 +               "MSGQ"  VX_LIMIT_FMT
18920 +               "SHM"   VX_LIMIT_FMT
18921 +               "SEMA"  VX_LIMIT_FMT
18922 +               "SEMS"  VX_LIMIT_FMT
18923 +               "DENT"  VX_LIMIT_FMT,
18924 +               VX_LIMIT_ARG(RLIMIT_NPROC),
18925 +               VX_LIMIT_ARG(RLIMIT_AS),
18926 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
18927 +               VX_LIMIT_ARG(RLIMIT_RSS),
18928 +               VX_LIMIT_ARG(VLIMIT_ANON),
18929 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
18930 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
18931 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
18932 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
18933 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
18934 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
18935 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
18936 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
18937 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
18938 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
18939 +}
18940 +
18941 +#endif /* _VX_LIMIT_PROC_H */
18942 +
18943 +
18944 diff -NurpP --minimal linux-4.4.115/kernel/vserver/network.c linux-4.4.115-vs2.3.9.7/kernel/vserver/network.c
18945 --- linux-4.4.115/kernel/vserver/network.c      1970-01-01 00:00:00.000000000 +0000
18946 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/network.c    2018-01-09 16:36:34.000000000 +0000
18947 @@ -0,0 +1,1053 @@
18948 +/*
18949 + *  linux/kernel/vserver/network.c
18950 + *
18951 + *  Virtual Server: Network Support
18952 + *
18953 + *  Copyright (C) 2003-2007  Herbert Pötzl
18954 + *
18955 + *  V0.01  broken out from vcontext V0.05
18956 + *  V0.02  cleaned up implementation
18957 + *  V0.03  added equiv nx commands
18958 + *  V0.04  switch to RCU based hash
18959 + *  V0.05  and back to locking again
18960 + *  V0.06  changed vcmds to nxi arg
18961 + *  V0.07  have __create claim() the nxi
18962 + *
18963 + */
18964 +
18965 +#include <linux/err.h>
18966 +#include <linux/slab.h>
18967 +#include <linux/rcupdate.h>
18968 +#include <net/ipv6.h>
18969 +
18970 +#include <linux/vs_network.h>
18971 +#include <linux/vs_pid.h>
18972 +#include <linux/vserver/network_cmd.h>
18973 +
18974 +
18975 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
18976 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
18977 +
18978 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
18979 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
18980 +
18981 +
18982 +static int __init init_network(void)
18983 +{
18984 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
18985 +               sizeof(struct nx_addr_v4), 0,
18986 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18987 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
18988 +               sizeof(struct nx_addr_v6), 0,
18989 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18990 +       return 0;
18991 +}
18992 +
18993 +
18994 +/*     __alloc_nx_addr_v4()                                    */
18995 +
18996 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
18997 +{
18998 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
18999 +               nx_addr_v4_cachep, GFP_KERNEL);
19000 +
19001 +       if (!IS_ERR(nxa))
19002 +               memset(nxa, 0, sizeof(*nxa));
19003 +       return nxa;
19004 +}
19005 +
19006 +/*     __dealloc_nx_addr_v4()                                  */
19007 +
19008 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19009 +{
19010 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19011 +}
19012 +
19013 +/*     __dealloc_nx_addr_v4_all()                              */
19014 +
19015 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19016 +{
19017 +       while (nxa) {
19018 +               struct nx_addr_v4 *next = nxa->next;
19019 +
19020 +               __dealloc_nx_addr_v4(nxa);
19021 +               nxa = next;
19022 +       }
19023 +}
19024 +
19025 +
19026 +#ifdef CONFIG_IPV6
19027 +
19028 +/*     __alloc_nx_addr_v6()                                    */
19029 +
19030 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19031 +{
19032 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19033 +               nx_addr_v6_cachep, GFP_KERNEL);
19034 +
19035 +       if (!IS_ERR(nxa))
19036 +               memset(nxa, 0, sizeof(*nxa));
19037 +       return nxa;
19038 +}
19039 +
19040 +/*     __dealloc_nx_addr_v6()                                  */
19041 +
19042 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19043 +{
19044 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19045 +}
19046 +
19047 +/*     __dealloc_nx_addr_v6_all()                              */
19048 +
19049 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19050 +{
19051 +       while (nxa) {
19052 +               struct nx_addr_v6 *next = nxa->next;
19053 +
19054 +               __dealloc_nx_addr_v6(nxa);
19055 +               nxa = next;
19056 +       }
19057 +}
19058 +
19059 +#endif /* CONFIG_IPV6 */
19060 +
19061 +/*     __alloc_nx_info()
19062 +
19063 +       * allocate an initialized nx_info struct
19064 +       * doesn't make it visible (hash)                        */
19065 +
19066 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19067 +{
19068 +       struct nx_info *new = NULL;
19069 +
19070 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19071 +
19072 +       /* would this benefit from a slab cache? */
19073 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19074 +       if (!new)
19075 +               return 0;
19076 +
19077 +       memset(new, 0, sizeof(struct nx_info));
19078 +       new->nx_id = nid;
19079 +       INIT_HLIST_NODE(&new->nx_hlist);
19080 +       atomic_set(&new->nx_usecnt, 0);
19081 +       atomic_set(&new->nx_tasks, 0);
19082 +       spin_lock_init(&new->addr_lock);
19083 +       new->nx_state = 0;
19084 +
19085 +       new->nx_flags = NXF_INIT_SET;
19086 +
19087 +       /* rest of init goes here */
19088 +
19089 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19090 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19091 +
19092 +       vxdprintk(VXD_CBIT(nid, 0),
19093 +               "alloc_nx_info(%d) = %p", nid, new);
19094 +       atomic_inc(&nx_global_ctotal);
19095 +       return new;
19096 +}
19097 +
19098 +/*     __dealloc_nx_info()
19099 +
19100 +       * final disposal of nx_info                             */
19101 +
19102 +static void __dealloc_nx_info(struct nx_info *nxi)
19103 +{
19104 +       vxdprintk(VXD_CBIT(nid, 0),
19105 +               "dealloc_nx_info(%p)", nxi);
19106 +
19107 +       nxi->nx_hlist.next = LIST_POISON1;
19108 +       nxi->nx_id = -1;
19109 +
19110 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19111 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19112 +
19113 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
19114 +#ifdef CONFIG_IPV6
19115 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
19116 +#endif
19117 +
19118 +       nxi->nx_state |= NXS_RELEASED;
19119 +       kfree(nxi);
19120 +       atomic_dec(&nx_global_ctotal);
19121 +}
19122 +
19123 +static void __shutdown_nx_info(struct nx_info *nxi)
19124 +{
19125 +       nxi->nx_state |= NXS_SHUTDOWN;
19126 +       vs_net_change(nxi, VSC_NETDOWN);
19127 +}
19128 +
19129 +/*     exported stuff                                          */
19130 +
19131 +void free_nx_info(struct nx_info *nxi)
19132 +{
19133 +       /* context shutdown is mandatory */
19134 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
19135 +
19136 +       /* context must not be hashed */
19137 +       BUG_ON(nxi->nx_state & NXS_HASHED);
19138 +
19139 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19140 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19141 +
19142 +       __dealloc_nx_info(nxi);
19143 +}
19144 +
19145 +
19146 +void __nx_set_lback(struct nx_info *nxi)
19147 +{
19148 +       int nid = nxi->nx_id;
19149 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
19150 +
19151 +       nxi->v4_lback.s_addr = lback;
19152 +}
19153 +
19154 +extern int __nx_inet_add_lback(__be32 addr);
19155 +extern int __nx_inet_del_lback(__be32 addr);
19156 +
19157 +
19158 +/*     hash table for nx_info hash */
19159 +
19160 +#define NX_HASH_SIZE   13
19161 +
19162 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
19163 +
19164 +static DEFINE_SPINLOCK(nx_info_hash_lock);
19165 +
19166 +
19167 +static inline unsigned int __hashval(vnid_t nid)
19168 +{
19169 +       return (nid % NX_HASH_SIZE);
19170 +}
19171 +
19172 +
19173 +
19174 +/*     __hash_nx_info()
19175 +
19176 +       * add the nxi to the global hash table
19177 +       * requires the hash_lock to be held                     */
19178 +
19179 +static inline void __hash_nx_info(struct nx_info *nxi)
19180 +{
19181 +       struct hlist_head *head;
19182 +
19183 +       vxd_assert_lock(&nx_info_hash_lock);
19184 +       vxdprintk(VXD_CBIT(nid, 4),
19185 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
19186 +
19187 +       /* context must not be hashed */
19188 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
19189 +
19190 +       nxi->nx_state |= NXS_HASHED;
19191 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
19192 +       hlist_add_head(&nxi->nx_hlist, head);
19193 +       atomic_inc(&nx_global_cactive);
19194 +}
19195 +
19196 +/*     __unhash_nx_info()
19197 +
19198 +       * remove the nxi from the global hash table
19199 +       * requires the hash_lock to be held                     */
19200 +
19201 +static inline void __unhash_nx_info(struct nx_info *nxi)
19202 +{
19203 +       vxd_assert_lock(&nx_info_hash_lock);
19204 +       vxdprintk(VXD_CBIT(nid, 4),
19205 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
19206 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
19207 +
19208 +       /* context must be hashed */
19209 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
19210 +       /* but without tasks */
19211 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19212 +
19213 +       nxi->nx_state &= ~NXS_HASHED;
19214 +       hlist_del(&nxi->nx_hlist);
19215 +       atomic_dec(&nx_global_cactive);
19216 +}
19217 +
19218 +
19219 +/*     __lookup_nx_info()
19220 +
19221 +       * requires the hash_lock to be held
19222 +       * doesn't increment the nx_refcnt                       */
19223 +
19224 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
19225 +{
19226 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
19227 +       struct hlist_node *pos;
19228 +       struct nx_info *nxi;
19229 +
19230 +       vxd_assert_lock(&nx_info_hash_lock);
19231 +       hlist_for_each(pos, head) {
19232 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19233 +
19234 +               if (nxi->nx_id == nid)
19235 +                       goto found;
19236 +       }
19237 +       nxi = NULL;
19238 +found:
19239 +       vxdprintk(VXD_CBIT(nid, 0),
19240 +               "__lookup_nx_info(#%u): %p[#%u]",
19241 +               nid, nxi, nxi ? nxi->nx_id : 0);
19242 +       return nxi;
19243 +}
19244 +
19245 +
19246 +/*     __create_nx_info()
19247 +
19248 +       * create the requested context
19249 +       * get(), claim() and hash it                            */
19250 +
19251 +static struct nx_info *__create_nx_info(int id)
19252 +{
19253 +       struct nx_info *new, *nxi = NULL;
19254 +
19255 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
19256 +
19257 +       if (!(new = __alloc_nx_info(id)))
19258 +               return ERR_PTR(-ENOMEM);
19259 +
19260 +       /* required to make dynamic xids unique */
19261 +       spin_lock(&nx_info_hash_lock);
19262 +
19263 +       /* static context requested */
19264 +       if ((nxi = __lookup_nx_info(id))) {
19265 +               vxdprintk(VXD_CBIT(nid, 0),
19266 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
19267 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19268 +                       nxi = ERR_PTR(-EBUSY);
19269 +               else
19270 +                       nxi = ERR_PTR(-EEXIST);
19271 +               goto out_unlock;
19272 +       }
19273 +       /* new context */
19274 +       vxdprintk(VXD_CBIT(nid, 0),
19275 +               "create_nx_info(%d) = %p (new)", id, new);
19276 +       claim_nx_info(new, NULL);
19277 +       __nx_set_lback(new);
19278 +       __hash_nx_info(get_nx_info(new));
19279 +       nxi = new, new = NULL;
19280 +
19281 +out_unlock:
19282 +       spin_unlock(&nx_info_hash_lock);
19283 +       if (new)
19284 +               __dealloc_nx_info(new);
19285 +       return nxi;
19286 +}
19287 +
19288 +
19289 +
19290 +/*     exported stuff                                          */
19291 +
19292 +
19293 +void unhash_nx_info(struct nx_info *nxi)
19294 +{
19295 +       __shutdown_nx_info(nxi);
19296 +       spin_lock(&nx_info_hash_lock);
19297 +       __unhash_nx_info(nxi);
19298 +       spin_unlock(&nx_info_hash_lock);
19299 +}
19300 +
19301 +/*     lookup_nx_info()
19302 +
19303 +       * search for a nx_info and get() it
19304 +       * negative id means current                             */
19305 +
19306 +struct nx_info *lookup_nx_info(int id)
19307 +{
19308 +       struct nx_info *nxi = NULL;
19309 +
19310 +       if (id < 0) {
19311 +               nxi = get_nx_info(current_nx_info());
19312 +       } else if (id > 1) {
19313 +               spin_lock(&nx_info_hash_lock);
19314 +               nxi = get_nx_info(__lookup_nx_info(id));
19315 +               spin_unlock(&nx_info_hash_lock);
19316 +       }
19317 +       return nxi;
19318 +}
19319 +
19320 +/*     nid_is_hashed()
19321 +
19322 +       * verify that nid is still hashed                       */
19323 +
19324 +int nid_is_hashed(vnid_t nid)
19325 +{
19326 +       int hashed;
19327 +
19328 +       spin_lock(&nx_info_hash_lock);
19329 +       hashed = (__lookup_nx_info(nid) != NULL);
19330 +       spin_unlock(&nx_info_hash_lock);
19331 +       return hashed;
19332 +}
19333 +
19334 +
19335 +#ifdef CONFIG_PROC_FS
19336 +
19337 +/*     get_nid_list()
19338 +
19339 +       * get a subset of hashed nids for proc
19340 +       * assumes size is at least one                          */
19341 +
19342 +int get_nid_list(int index, unsigned int *nids, int size)
19343 +{
19344 +       int hindex, nr_nids = 0;
19345 +
19346 +       /* only show current and children */
19347 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
19348 +               if (index > 0)
19349 +                       return 0;
19350 +               nids[nr_nids] = nx_current_nid();
19351 +               return 1;
19352 +       }
19353 +
19354 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
19355 +               struct hlist_head *head = &nx_info_hash[hindex];
19356 +               struct hlist_node *pos;
19357 +
19358 +               spin_lock(&nx_info_hash_lock);
19359 +               hlist_for_each(pos, head) {
19360 +                       struct nx_info *nxi;
19361 +
19362 +                       if (--index > 0)
19363 +                               continue;
19364 +
19365 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19366 +                       nids[nr_nids] = nxi->nx_id;
19367 +                       if (++nr_nids >= size) {
19368 +                               spin_unlock(&nx_info_hash_lock);
19369 +                               goto out;
19370 +                       }
19371 +               }
19372 +               /* keep the lock time short */
19373 +               spin_unlock(&nx_info_hash_lock);
19374 +       }
19375 +out:
19376 +       return nr_nids;
19377 +}
19378 +#endif
19379 +
19380 +
19381 +/*
19382 + *     migrate task to new network
19383 + *     gets nxi, puts old_nxi on change
19384 + */
19385 +
19386 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
19387 +{
19388 +       struct nx_info *old_nxi;
19389 +       int ret = 0;
19390 +
19391 +       if (!p || !nxi)
19392 +               BUG();
19393 +
19394 +       vxdprintk(VXD_CBIT(nid, 5),
19395 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
19396 +               p, nxi, nxi->nx_id,
19397 +               atomic_read(&nxi->nx_usecnt),
19398 +               atomic_read(&nxi->nx_tasks));
19399 +
19400 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
19401 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19402 +               return -EACCES;
19403 +
19404 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
19405 +               return -EFAULT;
19406 +
19407 +       /* maybe disallow this completely? */
19408 +       old_nxi = task_get_nx_info(p);
19409 +       if (old_nxi == nxi)
19410 +               goto out;
19411 +
19412 +       task_lock(p);
19413 +       if (old_nxi)
19414 +               clr_nx_info(&p->nx_info);
19415 +       claim_nx_info(nxi, p);
19416 +       set_nx_info(&p->nx_info, nxi);
19417 +       p->nid = nxi->nx_id;
19418 +       task_unlock(p);
19419 +
19420 +       vxdprintk(VXD_CBIT(nid, 5),
19421 +               "moved task %p into nxi:%p[#%d]",
19422 +               p, nxi, nxi->nx_id);
19423 +
19424 +       if (old_nxi)
19425 +               release_nx_info(old_nxi, p);
19426 +       ret = 0;
19427 +out:
19428 +       put_nx_info(old_nxi);
19429 +       return ret;
19430 +}
19431 +
19432 +
19433 +void nx_set_persistent(struct nx_info *nxi)
19434 +{
19435 +       vxdprintk(VXD_CBIT(nid, 6),
19436 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
19437 +
19438 +       get_nx_info(nxi);
19439 +       claim_nx_info(nxi, NULL);
19440 +}
19441 +
19442 +void nx_clear_persistent(struct nx_info *nxi)
19443 +{
19444 +       vxdprintk(VXD_CBIT(nid, 6),
19445 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
19446 +
19447 +       release_nx_info(nxi, NULL);
19448 +       put_nx_info(nxi);
19449 +}
19450 +
19451 +void nx_update_persistent(struct nx_info *nxi)
19452 +{
19453 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
19454 +               nx_set_persistent(nxi);
19455 +       else
19456 +               nx_clear_persistent(nxi);
19457 +}
19458 +
19459 +/* vserver syscall commands below here */
19460 +
19461 +/* taks nid and nx_info functions */
19462 +
19463 +#include <asm/uaccess.h>
19464 +
19465 +
19466 +int vc_task_nid(uint32_t id)
19467 +{
19468 +       vnid_t nid;
19469 +
19470 +       if (id) {
19471 +               struct task_struct *tsk;
19472 +
19473 +               rcu_read_lock();
19474 +               tsk = find_task_by_real_pid(id);
19475 +               nid = (tsk) ? tsk->nid : -ESRCH;
19476 +               rcu_read_unlock();
19477 +       } else
19478 +               nid = nx_current_nid();
19479 +       return nid;
19480 +}
19481 +
19482 +
19483 +int vc_nx_info(struct nx_info *nxi, void __user *data)
19484 +{
19485 +       struct vcmd_nx_info_v0 vc_data;
19486 +
19487 +       vc_data.nid = nxi->nx_id;
19488 +
19489 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19490 +               return -EFAULT;
19491 +       return 0;
19492 +}
19493 +
19494 +
19495 +/* network functions */
19496 +
19497 +int vc_net_create(uint32_t nid, void __user *data)
19498 +{
19499 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
19500 +       struct nx_info *new_nxi;
19501 +       int ret;
19502 +
19503 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19504 +               return -EFAULT;
19505 +
19506 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
19507 +               return -EINVAL;
19508 +
19509 +       new_nxi = __create_nx_info(nid);
19510 +       if (IS_ERR(new_nxi))
19511 +               return PTR_ERR(new_nxi);
19512 +
19513 +       /* initial flags */
19514 +       new_nxi->nx_flags = vc_data.flagword;
19515 +
19516 +       ret = -ENOEXEC;
19517 +       if (vs_net_change(new_nxi, VSC_NETUP))
19518 +               goto out;
19519 +
19520 +       ret = nx_migrate_task(current, new_nxi);
19521 +       if (ret)
19522 +               goto out;
19523 +
19524 +       /* return context id on success */
19525 +       ret = new_nxi->nx_id;
19526 +
19527 +       /* get a reference for persistent contexts */
19528 +       if ((vc_data.flagword & NXF_PERSISTENT))
19529 +               nx_set_persistent(new_nxi);
19530 +out:
19531 +       release_nx_info(new_nxi, NULL);
19532 +       put_nx_info(new_nxi);
19533 +       return ret;
19534 +}
19535 +
19536 +
19537 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
19538 +{
19539 +       return nx_migrate_task(current, nxi);
19540 +}
19541 +
19542 +
19543 +static inline
19544 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
19545 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
19546 +       struct nx_addr_v4 **prev)
19547 +{
19548 +       struct nx_addr_v4 *nxa = &nxi->v4;
19549 +
19550 +       for (; nxa; nxa = nxa->next) {
19551 +               if ((nxa->ip[0].s_addr == ip) &&
19552 +                   (nxa->ip[1].s_addr == ip2) &&
19553 +                   (nxa->mask.s_addr == mask) &&
19554 +                   (nxa->type == type) &&
19555 +                   (nxa->flags == flags))
19556 +                   return nxa;
19557 +
19558 +               /* save previous entry */
19559 +               if (prev)
19560 +                       *prev = nxa;
19561 +       }
19562 +       return NULL;
19563 +}
19564 +
19565 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19566 +       uint16_t type, uint16_t flags)
19567 +{
19568 +       struct nx_addr_v4 *nxa = NULL;
19569 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
19570 +       unsigned long irqflags;
19571 +       int ret = -EEXIST;
19572 +
19573 +       if (IS_ERR(new))
19574 +               return PTR_ERR(new);
19575 +
19576 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19577 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
19578 +               goto out_unlock;
19579 +
19580 +       if (NX_IPV4(nxi)) {
19581 +               nxa->next = new;
19582 +               nxa = new;
19583 +               new = NULL;
19584 +
19585 +               /* remove single ip for ip list */
19586 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
19587 +       }
19588 +
19589 +       nxa->ip[0].s_addr = ip;
19590 +       nxa->ip[1].s_addr = ip2;
19591 +       nxa->mask.s_addr = mask;
19592 +       nxa->type = type;
19593 +       nxa->flags = flags;
19594 +       ret = 0;
19595 +out_unlock:
19596 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19597 +       if (new)
19598 +               __dealloc_nx_addr_v4(new);
19599 +       return ret;
19600 +}
19601 +
19602 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19603 +       uint16_t type, uint16_t flags)
19604 +{
19605 +       struct nx_addr_v4 *nxa = NULL;
19606 +       struct nx_addr_v4 *old = NULL;
19607 +       unsigned long irqflags;
19608 +       int ret = 0;
19609 +
19610 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19611 +       switch (type) {
19612 +       case NXA_TYPE_ADDR:
19613 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
19614 +               if (old) {
19615 +                       if (nxa) {
19616 +                               nxa->next = old->next;
19617 +                               old->next = NULL;
19618 +                       } else {
19619 +                               if (old->next) {
19620 +                                       nxa = old;
19621 +                                       old = old->next;
19622 +                                       *nxa = *old;
19623 +                                       old->next = NULL;
19624 +                               } else {
19625 +                                       memset(old, 0, sizeof(*old));
19626 +                                       old = NULL;
19627 +                               }
19628 +                       }
19629 +               } else
19630 +                       ret = -ESRCH;
19631 +               break;
19632 +
19633 +       case NXA_TYPE_ANY:
19634 +               nxa = &nxi->v4;
19635 +               old = nxa->next;
19636 +               memset(nxa, 0, sizeof(*nxa));
19637 +               break;
19638 +
19639 +       default:
19640 +               ret = -EINVAL;
19641 +       }
19642 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19643 +       __dealloc_nx_addr_v4_all(old);
19644 +       return ret;
19645 +}
19646 +
19647 +
19648 +int vc_net_add(struct nx_info *nxi, void __user *data)
19649 +{
19650 +       struct vcmd_net_addr_v0 vc_data;
19651 +       int index, ret = 0;
19652 +
19653 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19654 +               return -EFAULT;
19655 +
19656 +       switch (vc_data.type) {
19657 +       case NXA_TYPE_IPV4:
19658 +               if ((vc_data.count < 1) || (vc_data.count > 4))
19659 +                       return -EINVAL;
19660 +
19661 +               index = 0;
19662 +               while (index < vc_data.count) {
19663 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
19664 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
19665 +                       if (ret)
19666 +                               return ret;
19667 +                       index++;
19668 +               }
19669 +               ret = index;
19670 +               break;
19671 +
19672 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
19673 +               nxi->v4_bcast = vc_data.ip[0];
19674 +               ret = 1;
19675 +               break;
19676 +
19677 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
19678 +               nxi->v4_lback = vc_data.ip[0];
19679 +               ret = 1;
19680 +               break;
19681 +
19682 +       default:
19683 +               ret = -EINVAL;
19684 +               break;
19685 +       }
19686 +       return ret;
19687 +}
19688 +
19689 +int vc_net_remove(struct nx_info *nxi, void __user *data)
19690 +{
19691 +       struct vcmd_net_addr_v0 vc_data;
19692 +
19693 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19694 +               return -EFAULT;
19695 +
19696 +       switch (vc_data.type) {
19697 +       case NXA_TYPE_ANY:
19698 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
19699 +       default:
19700 +               return -EINVAL;
19701 +       }
19702 +       return 0;
19703 +}
19704 +
19705 +
19706 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
19707 +{
19708 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19709 +
19710 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19711 +               return -EFAULT;
19712 +
19713 +       switch (vc_data.type) {
19714 +       case NXA_TYPE_ADDR:
19715 +       case NXA_TYPE_MASK:
19716 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
19717 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19718 +
19719 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19720 +               nxi->v4_bcast = vc_data.ip;
19721 +               break;
19722 +
19723 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19724 +               nxi->v4_lback = vc_data.ip;
19725 +               break;
19726 +
19727 +       default:
19728 +               return -EINVAL;
19729 +       }
19730 +       return 0;
19731 +}
19732 +
19733 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
19734 +{
19735 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19736 +
19737 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19738 +               return -EFAULT;
19739 +
19740 +       switch (vc_data.type) {
19741 +       case NXA_TYPE_ADDR:
19742 +       case NXA_TYPE_MASK:
19743 +       case NXA_TYPE_RANGE:
19744 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19745 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19746 +
19747 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19748 +               nxi->v4_bcast = vc_data.ip;
19749 +               break;
19750 +
19751 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19752 +               nxi->v4_lback = vc_data.ip;
19753 +               break;
19754 +
19755 +       default:
19756 +               return -EINVAL;
19757 +       }
19758 +       return 0;
19759 +}
19760 +
19761 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
19762 +{
19763 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19764 +
19765 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19766 +               return -EFAULT;
19767 +
19768 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
19769 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19770 +}
19771 +
19772 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
19773 +{
19774 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19775 +
19776 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19777 +               return -EFAULT;
19778 +
19779 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19780 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19781 +}
19782 +
19783 +#ifdef CONFIG_IPV6
19784 +
19785 +static inline
19786 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
19787 +       struct in6_addr *ip, struct in6_addr *mask,
19788 +       uint32_t prefix, uint16_t type, uint16_t flags,
19789 +       struct nx_addr_v6 **prev)
19790 +{
19791 +       struct nx_addr_v6 *nxa = &nxi->v6;
19792 +
19793 +       for (; nxa; nxa = nxa->next) {
19794 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
19795 +                   ipv6_addr_equal(&nxa->mask, mask) &&
19796 +                   (nxa->prefix == prefix) &&
19797 +                   (nxa->type == type) &&
19798 +                   (nxa->flags == flags))
19799 +                   return nxa;
19800 +
19801 +               /* save previous entry */
19802 +               if (prev)
19803 +                       *prev = nxa;
19804 +       }
19805 +       return NULL;
19806 +}
19807 +
19808 +
19809 +int do_add_v6_addr(struct nx_info *nxi,
19810 +       struct in6_addr *ip, struct in6_addr *mask,
19811 +       uint32_t prefix, uint16_t type, uint16_t flags)
19812 +{
19813 +       struct nx_addr_v6 *nxa = NULL;
19814 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
19815 +       unsigned long irqflags;
19816 +       int ret = -EEXIST;
19817 +
19818 +       if (IS_ERR(new))
19819 +               return PTR_ERR(new);
19820 +
19821 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19822 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
19823 +               goto out_unlock;
19824 +
19825 +       if (NX_IPV6(nxi)) {
19826 +               nxa->next = new;
19827 +               nxa = new;
19828 +               new = NULL;
19829 +       }
19830 +
19831 +       nxa->ip = *ip;
19832 +       nxa->mask = *mask;
19833 +       nxa->prefix = prefix;
19834 +       nxa->type = type;
19835 +       nxa->flags = flags;
19836 +       ret = 0;
19837 +out_unlock:
19838 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19839 +       if (new)
19840 +               __dealloc_nx_addr_v6(new);
19841 +       return ret;
19842 +}
19843 +
19844 +int do_remove_v6_addr(struct nx_info *nxi,
19845 +       struct in6_addr *ip, struct in6_addr *mask,
19846 +       uint32_t prefix, uint16_t type, uint16_t flags)
19847 +{
19848 +       struct nx_addr_v6 *nxa = NULL;
19849 +       struct nx_addr_v6 *old = NULL;
19850 +       unsigned long irqflags;
19851 +       int ret = 0;
19852 +
19853 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19854 +       switch (type) {
19855 +       case NXA_TYPE_ADDR:
19856 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
19857 +               if (old) {
19858 +                       if (nxa) {
19859 +                               nxa->next = old->next;
19860 +                               old->next = NULL;
19861 +                       } else {
19862 +                               if (old->next) {
19863 +                                       nxa = old;
19864 +                                       old = old->next;
19865 +                                       *nxa = *old;
19866 +                                       old->next = NULL;
19867 +                               } else {
19868 +                                       memset(old, 0, sizeof(*old));
19869 +                                       old = NULL;
19870 +                               }
19871 +                       }
19872 +               } else
19873 +                       ret = -ESRCH;
19874 +               break;
19875 +
19876 +       case NXA_TYPE_ANY:
19877 +               nxa = &nxi->v6;
19878 +               old = nxa->next;
19879 +               memset(nxa, 0, sizeof(*nxa));
19880 +               break;
19881 +
19882 +       default:
19883 +               ret = -EINVAL;
19884 +       }
19885 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19886 +       __dealloc_nx_addr_v6_all(old);
19887 +       return ret;
19888 +}
19889 +
19890 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
19891 +{
19892 +       struct vcmd_net_addr_ipv6_v1 vc_data;
19893 +
19894 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19895 +               return -EFAULT;
19896 +
19897 +       switch (vc_data.type) {
19898 +       case NXA_TYPE_ADDR:
19899 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
19900 +               /* fallthrough */
19901 +       case NXA_TYPE_MASK:
19902 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
19903 +                       vc_data.prefix, vc_data.type, vc_data.flags);
19904 +       default:
19905 +               return -EINVAL;
19906 +       }
19907 +       return 0;
19908 +}
19909 +
19910 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
19911 +{
19912 +       struct vcmd_net_addr_ipv6_v1 vc_data;
19913 +
19914 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19915 +               return -EFAULT;
19916 +
19917 +       switch (vc_data.type) {
19918 +       case NXA_TYPE_ADDR:
19919 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
19920 +               /* fallthrough */
19921 +       case NXA_TYPE_MASK:
19922 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
19923 +                       vc_data.prefix, vc_data.type, vc_data.flags);
19924 +       case NXA_TYPE_ANY:
19925 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
19926 +       default:
19927 +               return -EINVAL;
19928 +       }
19929 +       return 0;
19930 +}
19931 +
19932 +#endif /* CONFIG_IPV6 */
19933 +
19934 +
19935 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
19936 +{
19937 +       struct vcmd_net_flags_v0 vc_data;
19938 +
19939 +       vc_data.flagword = nxi->nx_flags;
19940 +
19941 +       /* special STATE flag handling */
19942 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
19943 +
19944 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19945 +               return -EFAULT;
19946 +       return 0;
19947 +}
19948 +
19949 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
19950 +{
19951 +       struct vcmd_net_flags_v0 vc_data;
19952 +       uint64_t mask, trigger;
19953 +
19954 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19955 +               return -EFAULT;
19956 +
19957 +       /* special STATE flag handling */
19958 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
19959 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
19960 +
19961 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
19962 +               vc_data.flagword, mask);
19963 +       if (trigger & NXF_PERSISTENT)
19964 +               nx_update_persistent(nxi);
19965 +
19966 +       return 0;
19967 +}
19968 +
19969 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
19970 +{
19971 +       struct vcmd_net_caps_v0 vc_data;
19972 +
19973 +       vc_data.ncaps = nxi->nx_ncaps;
19974 +       vc_data.cmask = ~0ULL;
19975 +
19976 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19977 +               return -EFAULT;
19978 +       return 0;
19979 +}
19980 +
19981 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
19982 +{
19983 +       struct vcmd_net_caps_v0 vc_data;
19984 +
19985 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19986 +               return -EFAULT;
19987 +
19988 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
19989 +               vc_data.ncaps, vc_data.cmask);
19990 +       return 0;
19991 +}
19992 +
19993 +
19994 +#include <linux/module.h>
19995 +
19996 +module_init(init_network);
19997 +
19998 +EXPORT_SYMBOL_GPL(free_nx_info);
19999 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20000 +
20001 diff -NurpP --minimal linux-4.4.115/kernel/vserver/proc.c linux-4.4.115-vs2.3.9.7/kernel/vserver/proc.c
20002 --- linux-4.4.115/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20003 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/proc.c       2018-01-11 12:02:42.000000000 +0000
20004 @@ -0,0 +1,1040 @@
20005 +/*
20006 + *  linux/kernel/vserver/proc.c
20007 + *
20008 + *  Virtual Context Support
20009 + *
20010 + *  Copyright (C) 2003-2011  Herbert Pötzl
20011 + *
20012 + *  V0.01  basic structure
20013 + *  V0.02  adaptation vs1.3.0
20014 + *  V0.03  proc permissions
20015 + *  V0.04  locking/generic
20016 + *  V0.05  next generation procfs
20017 + *  V0.06  inode validation
20018 + *  V0.07  generic rewrite vid
20019 + *  V0.08  remove inode type
20020 + *  V0.09  added u/wmask info
20021 + *
20022 + */
20023 +
20024 +#include <linux/proc_fs.h>
20025 +#include <linux/fs_struct.h>
20026 +#include <linux/mount.h>
20027 +#include <linux/namei.h>
20028 +#include <asm/unistd.h>
20029 +
20030 +#include <linux/vs_context.h>
20031 +#include <linux/vs_network.h>
20032 +#include <linux/vs_cvirt.h>
20033 +
20034 +#include <linux/in.h>
20035 +#include <linux/inetdevice.h>
20036 +#include <linux/vs_inet.h>
20037 +#include <linux/vs_inet6.h>
20038 +
20039 +#include <linux/vserver/global.h>
20040 +
20041 +#include "cvirt_proc.h"
20042 +#include "cacct_proc.h"
20043 +#include "limit_proc.h"
20044 +#include "sched_proc.h"
20045 +#include "vci_config.h"
20046 +
20047 +#include <../../fs/proc/internal.h>
20048 +
20049 +
20050 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20051 +{
20052 +       unsigned __capi;
20053 +
20054 +       CAP_FOR_EACH_U32(__capi) {
20055 +               buffer += sprintf(buffer, "%08x",
20056 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20057 +       }
20058 +       return buffer;
20059 +}
20060 +
20061 +
20062 +static struct proc_dir_entry *proc_virtual;
20063 +
20064 +static struct proc_dir_entry *proc_virtnet;
20065 +
20066 +
20067 +/* first the actual feeds */
20068 +
20069 +
20070 +static int proc_vci(char *buffer)
20071 +{
20072 +       return sprintf(buffer,
20073 +               "VCIVersion:\t%04x:%04x\n"
20074 +               "VCISyscall:\t%d\n"
20075 +               "VCIKernel:\t%08x\n",
20076 +               VCI_VERSION >> 16,
20077 +               VCI_VERSION & 0xFFFF,
20078 +               __NR_vserver,
20079 +               vci_kernel_config());
20080 +}
20081 +
20082 +static int proc_virtual_info(char *buffer)
20083 +{
20084 +       return proc_vci(buffer);
20085 +}
20086 +
20087 +static int proc_virtual_status(char *buffer)
20088 +{
20089 +       return sprintf(buffer,
20090 +               "#CTotal:\t%d\n"
20091 +               "#CActive:\t%d\n"
20092 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20093 +               "#InitTask:\t%d\t%d %d\n",
20094 +               atomic_read(&vx_global_ctotal),
20095 +               atomic_read(&vx_global_cactive),
20096 +               atomic_read(&vs_global_nsproxy),
20097 +               atomic_read(&vs_global_fs),
20098 +               atomic_read(&vs_global_mnt_ns),
20099 +               atomic_read(&vs_global_uts_ns),
20100 +               atomic_read(&nr_ipc_ns),
20101 +               atomic_read(&vs_global_user_ns),
20102 +               atomic_read(&vs_global_pid_ns),
20103 +               atomic_read(&init_task.usage),
20104 +               atomic_read(&init_task.nsproxy->count),
20105 +               init_task.fs->users);
20106 +}
20107 +
20108 +
20109 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20110 +{
20111 +       int length;
20112 +
20113 +       length = sprintf(buffer,
20114 +               "ID:\t%d\n"
20115 +               "Info:\t%p\n"
20116 +               "Init:\t%d\n"
20117 +               "OOM:\t%lld\n",
20118 +               vxi->vx_id,
20119 +               vxi,
20120 +               vxi->vx_initpid,
20121 +               vxi->vx_badness_bias);
20122 +       return length;
20123 +}
20124 +
20125 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
20126 +{
20127 +       char *orig = buffer;
20128 +
20129 +       buffer += sprintf(buffer,
20130 +               "UseCnt:\t%d\n"
20131 +               "Tasks:\t%d\n"
20132 +               "Flags:\t%016llx\n",
20133 +               atomic_read(&vxi->vx_usecnt),
20134 +               atomic_read(&vxi->vx_tasks),
20135 +               (unsigned long long)vxi->vx_flags);
20136 +
20137 +       buffer += sprintf(buffer, "BCaps:\t");
20138 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20139 +       buffer += sprintf(buffer, "\n");
20140 +
20141 +       buffer += sprintf(buffer,
20142 +               "CCaps:\t%016llx\n"
20143 +               "Umask:\t%16llx\n"
20144 +               "Wmask:\t%16llx\n"
20145 +               "Spaces:\t%08lx %08lx\n",
20146 +               (unsigned long long)vxi->vx_ccaps,
20147 +               (unsigned long long)vxi->vx_umask,
20148 +               (unsigned long long)vxi->vx_wmask,
20149 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20150 +       return buffer - orig;
20151 +}
20152 +
20153 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20154 +{
20155 +       return vx_info_proc_limit(&vxi->limit, buffer);
20156 +}
20157 +
20158 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20159 +{
20160 +       int cpu, length;
20161 +
20162 +       length = vx_info_proc_sched(&vxi->sched, buffer);
20163 +       for_each_online_cpu(cpu) {
20164 +               length += vx_info_proc_sched_pc(
20165 +                       &vx_per_cpu(vxi, sched_pc, cpu),
20166 +                       buffer + length, cpu);
20167 +       }
20168 +       return length;
20169 +}
20170 +
20171 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20172 +{
20173 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20174 +}
20175 +
20176 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20177 +{
20178 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20179 +}
20180 +
20181 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20182 +{
20183 +       int cpu, length;
20184 +
20185 +       vx_update_load(vxi);
20186 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20187 +       for_each_online_cpu(cpu) {
20188 +               length += vx_info_proc_cvirt_pc(
20189 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
20190 +                       buffer + length, cpu);
20191 +       }
20192 +       return length;
20193 +}
20194 +
20195 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20196 +{
20197 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
20198 +}
20199 +
20200 +
20201 +static int proc_virtnet_info(char *buffer)
20202 +{
20203 +       return proc_vci(buffer);
20204 +}
20205 +
20206 +static int proc_virtnet_status(char *buffer)
20207 +{
20208 +       return sprintf(buffer,
20209 +               "#CTotal:\t%d\n"
20210 +               "#CActive:\t%d\n",
20211 +               atomic_read(&nx_global_ctotal),
20212 +               atomic_read(&nx_global_cactive));
20213 +}
20214 +
20215 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
20216 +{
20217 +       struct nx_addr_v4 *v4a;
20218 +#ifdef CONFIG_IPV6
20219 +       struct nx_addr_v6 *v6a;
20220 +#endif
20221 +       int length, i;
20222 +
20223 +       length = sprintf(buffer,
20224 +               "ID:\t%d\n"
20225 +               "Info:\t%p\n"
20226 +               "Bcast:\t" NIPQUAD_FMT "\n"
20227 +               "Lback:\t" NIPQUAD_FMT "\n",
20228 +               nxi->nx_id,
20229 +               nxi,
20230 +               NIPQUAD(nxi->v4_bcast.s_addr),
20231 +               NIPQUAD(nxi->v4_lback.s_addr));
20232 +
20233 +       if (!NX_IPV4(nxi))
20234 +               goto skip_v4;
20235 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20236 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20237 +                       i, NXAV4(v4a));
20238 +skip_v4:
20239 +#ifdef CONFIG_IPV6
20240 +       if (!NX_IPV6(nxi))
20241 +               goto skip_v6;
20242 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20243 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
20244 +                       i, NXAV6(v6a));
20245 +skip_v6:
20246 +#endif
20247 +       return length;
20248 +}
20249 +
20250 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
20251 +{
20252 +       int length;
20253 +
20254 +       length = sprintf(buffer,
20255 +               "UseCnt:\t%d\n"
20256 +               "Tasks:\t%d\n"
20257 +               "Flags:\t%016llx\n"
20258 +               "NCaps:\t%016llx\n",
20259 +               atomic_read(&nxi->nx_usecnt),
20260 +               atomic_read(&nxi->nx_tasks),
20261 +               (unsigned long long)nxi->nx_flags,
20262 +               (unsigned long long)nxi->nx_ncaps);
20263 +       return length;
20264 +}
20265 +
20266 +
20267 +
20268 +/* here the inode helpers */
20269 +
20270 +struct vs_entry {
20271 +       int len;
20272 +       char *name;
20273 +       mode_t mode;
20274 +       struct inode_operations *iop;
20275 +       struct file_operations *fop;
20276 +       union proc_op op;
20277 +};
20278 +
20279 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
20280 +{
20281 +       struct inode *inode = new_inode(sb);
20282 +
20283 +       if (!inode)
20284 +               goto out;
20285 +
20286 +       inode->i_mode = p->mode;
20287 +       if (p->iop)
20288 +               inode->i_op = p->iop;
20289 +       if (p->fop)
20290 +               inode->i_fop = p->fop;
20291 +
20292 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
20293 +       inode->i_flags |= S_IMMUTABLE;
20294 +
20295 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
20296 +
20297 +       i_uid_write(inode, 0);
20298 +       i_gid_write(inode, 0);
20299 +       i_tag_write(inode, 0);
20300 +out:
20301 +       return inode;
20302 +}
20303 +
20304 +static struct dentry *vs_proc_instantiate(struct inode *dir,
20305 +       struct dentry *dentry, int id, void *ptr)
20306 +{
20307 +       struct vs_entry *p = ptr;
20308 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
20309 +       struct dentry *error = ERR_PTR(-EINVAL);
20310 +
20311 +       if (!inode)
20312 +               goto out;
20313 +
20314 +       PROC_I(inode)->op = p->op;
20315 +       PROC_I(inode)->fd = id;
20316 +       d_add(dentry, inode);
20317 +       error = NULL;
20318 +out:
20319 +       return error;
20320 +}
20321 +
20322 +/* Lookups */
20323 +
20324 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
20325 +
20326 +
20327 +/*
20328 + * Fill a directory entry.
20329 + *
20330 + * If possible create the dcache entry and derive our inode number and
20331 + * file type from dcache entry.
20332 + *
20333 + * Since all of the proc inode numbers are dynamically generated, the inode
20334 + * numbers do not exist until the inode is cache.  This means creating the
20335 + * the dcache entry in iterate is necessary to keep the inode numbers
20336 + * reported by iterate in sync with the inode numbers reported
20337 + * by stat.
20338 + */
20339 +static int vx_proc_fill_cache(struct file *filp, struct dir_context *ctx,
20340 +       char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
20341 +{
20342 +       struct dentry *child, *dir = filp->f_path.dentry;
20343 +       struct inode *inode;
20344 +       struct qstr qname;
20345 +       ino_t ino = 0;
20346 +       unsigned type = DT_UNKNOWN;
20347 +
20348 +       qname.name = name;
20349 +       qname.len  = len;
20350 +       qname.hash = full_name_hash(name, len);
20351 +
20352 +       child = d_lookup(dir, &qname);
20353 +       if (!child) {
20354 +               struct dentry *new;
20355 +               new = d_alloc(dir, &qname);
20356 +               if (new) {
20357 +                       child = instantiate(dir->d_inode, new, id, ptr);
20358 +                       if (child)
20359 +                               dput(new);
20360 +                       else
20361 +                               child = new;
20362 +               }
20363 +       }
20364 +       if (!child || IS_ERR(child) || !child->d_inode)
20365 +               goto end_instantiate;
20366 +       inode = child->d_inode;
20367 +       if (inode) {
20368 +               ino = inode->i_ino;
20369 +               type = inode->i_mode >> 12;
20370 +       }
20371 +       dput(child);
20372 +end_instantiate:
20373 +       if (!ino)
20374 +               ino = 1;
20375 +       return !dir_emit(ctx, name, len, ino, type);
20376 +}
20377 +
20378 +
20379 +
20380 +/* get and revalidate vx_info/xid */
20381 +
20382 +static inline
20383 +struct vx_info *get_proc_vx_info(struct inode *inode)
20384 +{
20385 +       return lookup_vx_info(PROC_I(inode)->fd);
20386 +}
20387 +
20388 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
20389 +{
20390 +       struct inode *inode = dentry->d_inode;
20391 +       vxid_t xid = PROC_I(inode)->fd;
20392 +
20393 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20394 +               return -ECHILD;
20395 +
20396 +       if (!xid || xid_is_hashed(xid))
20397 +               return 1;
20398 +       d_drop(dentry);
20399 +       return 0;
20400 +}
20401 +
20402 +
20403 +/* get and revalidate nx_info/nid */
20404 +
20405 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
20406 +{
20407 +       struct inode *inode = dentry->d_inode;
20408 +       vnid_t nid = PROC_I(inode)->fd;
20409 +
20410 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20411 +               return -ECHILD;
20412 +
20413 +       if (!nid || nid_is_hashed(nid))
20414 +               return 1;
20415 +       d_drop(dentry);
20416 +       return 0;
20417 +}
20418 +
20419 +
20420 +
20421 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
20422 +
20423 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
20424 +                         size_t count, loff_t *ppos)
20425 +{
20426 +       struct inode *inode = file->f_path.dentry->d_inode;
20427 +       unsigned long page;
20428 +       ssize_t length = 0;
20429 +
20430 +       if (count > PROC_BLOCK_SIZE)
20431 +               count = PROC_BLOCK_SIZE;
20432 +
20433 +       /* fade that out as soon as stable */
20434 +       WARN_ON(PROC_I(inode)->fd);
20435 +
20436 +       if (!(page = __get_free_page(GFP_KERNEL)))
20437 +               return -ENOMEM;
20438 +
20439 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
20440 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
20441 +
20442 +       if (length >= 0)
20443 +               length = simple_read_from_buffer(buf, count, ppos,
20444 +                       (char *)page, length);
20445 +
20446 +       free_page(page);
20447 +       return length;
20448 +}
20449 +
20450 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
20451 +                         size_t count, loff_t *ppos)
20452 +{
20453 +       struct inode *inode = file->f_path.dentry->d_inode;
20454 +       struct vx_info *vxi = NULL;
20455 +       vxid_t xid = PROC_I(inode)->fd;
20456 +       unsigned long page;
20457 +       ssize_t length = 0;
20458 +
20459 +       if (count > PROC_BLOCK_SIZE)
20460 +               count = PROC_BLOCK_SIZE;
20461 +
20462 +       /* fade that out as soon as stable */
20463 +       WARN_ON(!xid);
20464 +       vxi = lookup_vx_info(xid);
20465 +       if (!vxi)
20466 +               goto out;
20467 +
20468 +       length = -ENOMEM;
20469 +       if (!(page = __get_free_page(GFP_KERNEL)))
20470 +               goto out_put;
20471 +
20472 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
20473 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
20474 +
20475 +       if (length >= 0)
20476 +               length = simple_read_from_buffer(buf, count, ppos,
20477 +                       (char *)page, length);
20478 +
20479 +       free_page(page);
20480 +out_put:
20481 +       put_vx_info(vxi);
20482 +out:
20483 +       return length;
20484 +}
20485 +
20486 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
20487 +                         size_t count, loff_t *ppos)
20488 +{
20489 +       struct inode *inode = file->f_path.dentry->d_inode;
20490 +       struct nx_info *nxi = NULL;
20491 +       vnid_t nid = PROC_I(inode)->fd;
20492 +       unsigned long page;
20493 +       ssize_t length = 0;
20494 +
20495 +       if (count > PROC_BLOCK_SIZE)
20496 +               count = PROC_BLOCK_SIZE;
20497 +
20498 +       /* fade that out as soon as stable */
20499 +       WARN_ON(!nid);
20500 +       nxi = lookup_nx_info(nid);
20501 +       if (!nxi)
20502 +               goto out;
20503 +
20504 +       length = -ENOMEM;
20505 +       if (!(page = __get_free_page(GFP_KERNEL)))
20506 +               goto out_put;
20507 +
20508 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
20509 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
20510 +
20511 +       if (length >= 0)
20512 +               length = simple_read_from_buffer(buf, count, ppos,
20513 +                       (char *)page, length);
20514 +
20515 +       free_page(page);
20516 +out_put:
20517 +       put_nx_info(nxi);
20518 +out:
20519 +       return length;
20520 +}
20521 +
20522 +
20523 +
20524 +/* here comes the lower level */
20525 +
20526 +
20527 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
20528 +       .len  = sizeof(NAME) - 1,       \
20529 +       .name = (NAME),                 \
20530 +       .mode = MODE,                   \
20531 +       .iop  = IOP,                    \
20532 +       .fop  = FOP,                    \
20533 +       .op   = OP,                     \
20534 +}
20535 +
20536 +
20537 +#define DIR(NAME, MODE, OTYPE)                         \
20538 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
20539 +               &proc_ ## OTYPE ## _inode_operations,   \
20540 +               &proc_ ## OTYPE ## _file_operations, { } )
20541 +
20542 +#define INF(NAME, MODE, OTYPE)                         \
20543 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20544 +               &proc_vs_info_file_operations,          \
20545 +               { .proc_vs_read = &proc_##OTYPE } )
20546 +
20547 +#define VINF(NAME, MODE, OTYPE)                                \
20548 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20549 +               &proc_vx_info_file_operations,          \
20550 +               { .proc_vxi_read = &proc_##OTYPE } )
20551 +
20552 +#define NINF(NAME, MODE, OTYPE)                                \
20553 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20554 +               &proc_nx_info_file_operations,          \
20555 +               { .proc_nxi_read = &proc_##OTYPE } )
20556 +
20557 +
20558 +static struct file_operations proc_vs_info_file_operations = {
20559 +       .read =         proc_vs_info_read,
20560 +};
20561 +
20562 +static struct file_operations proc_vx_info_file_operations = {
20563 +       .read =         proc_vx_info_read,
20564 +};
20565 +
20566 +static struct dentry_operations proc_xid_dentry_operations = {
20567 +       .d_revalidate = proc_xid_revalidate,
20568 +};
20569 +
20570 +static struct vs_entry vx_base_stuff[] = {
20571 +       VINF("info",    S_IRUGO, vxi_info),
20572 +       VINF("status",  S_IRUGO, vxi_status),
20573 +       VINF("limit",   S_IRUGO, vxi_limit),
20574 +       VINF("sched",   S_IRUGO, vxi_sched),
20575 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
20576 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
20577 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
20578 +       VINF("cacct",   S_IRUGO, vxi_cacct),
20579 +       {}
20580 +};
20581 +
20582 +
20583 +
20584 +
20585 +static struct dentry *proc_xid_instantiate(struct inode *dir,
20586 +       struct dentry *dentry, int id, void *ptr)
20587 +{
20588 +       dentry->d_op = &proc_xid_dentry_operations;
20589 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20590 +}
20591 +
20592 +static struct dentry *proc_xid_lookup(struct inode *dir,
20593 +       struct dentry *dentry, unsigned int flags)
20594 +{
20595 +       struct vs_entry *p = vx_base_stuff;
20596 +       struct dentry *error = ERR_PTR(-ENOENT);
20597 +
20598 +       for (; p->name; p++) {
20599 +               if (p->len != dentry->d_name.len)
20600 +                       continue;
20601 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20602 +                       break;
20603 +       }
20604 +       if (!p->name)
20605 +               goto out;
20606 +
20607 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20608 +out:
20609 +       return error;
20610 +}
20611 +
20612 +static int proc_xid_iterate(struct file *filp, struct dir_context *ctx)
20613 +{
20614 +       struct dentry *dentry = filp->f_path.dentry;
20615 +       struct inode *inode = dentry->d_inode;
20616 +       struct vs_entry *p = vx_base_stuff;
20617 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
20618 +       int index;
20619 +
20620 +       if (!dir_emit_dots(filp, ctx))
20621 +               return 0;
20622 +
20623 +       index = ctx->pos - 2;
20624 +       if (index < size) {
20625 +               for (p += index; p->name; p++) {
20626 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20627 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20628 +                               return 0;
20629 +                       ctx->pos++;
20630 +               }
20631 +       }
20632 +       return 1;
20633 +}
20634 +
20635 +
20636 +
20637 +static struct file_operations proc_nx_info_file_operations = {
20638 +       .read =         proc_nx_info_read,
20639 +};
20640 +
20641 +static struct dentry_operations proc_nid_dentry_operations = {
20642 +       .d_revalidate = proc_nid_revalidate,
20643 +};
20644 +
20645 +static struct vs_entry nx_base_stuff[] = {
20646 +       NINF("info",    S_IRUGO, nxi_info),
20647 +       NINF("status",  S_IRUGO, nxi_status),
20648 +       {}
20649 +};
20650 +
20651 +
20652 +static struct dentry *proc_nid_instantiate(struct inode *dir,
20653 +       struct dentry *dentry, int id, void *ptr)
20654 +{
20655 +       dentry->d_op = &proc_nid_dentry_operations;
20656 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20657 +}
20658 +
20659 +static struct dentry *proc_nid_lookup(struct inode *dir,
20660 +       struct dentry *dentry, unsigned int flags)
20661 +{
20662 +       struct vs_entry *p = nx_base_stuff;
20663 +       struct dentry *error = ERR_PTR(-ENOENT);
20664 +
20665 +       for (; p->name; p++) {
20666 +               if (p->len != dentry->d_name.len)
20667 +                       continue;
20668 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20669 +                       break;
20670 +       }
20671 +       if (!p->name)
20672 +               goto out;
20673 +
20674 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20675 +out:
20676 +       return error;
20677 +}
20678 +
20679 +static int proc_nid_iterate(struct file *filp, struct dir_context *ctx)
20680 +{
20681 +       struct dentry *dentry = filp->f_path.dentry;
20682 +       struct inode *inode = dentry->d_inode;
20683 +       struct vs_entry *p = nx_base_stuff;
20684 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
20685 +       int index;
20686 +
20687 +       if (!dir_emit_dots(filp, ctx))
20688 +               return 0;
20689 +
20690 +       index = ctx->pos - 2;
20691 +       if (index < size) {
20692 +               for (p += index; p->name; p++) {
20693 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20694 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20695 +                               return 0;
20696 +                       ctx->pos++;
20697 +               }
20698 +       }
20699 +       return 1;
20700 +}
20701 +
20702 +
20703 +#define MAX_MULBY10    ((~0U - 9) / 10)
20704 +
20705 +static inline int atovid(const char *str, int len)
20706 +{
20707 +       int vid, c;
20708 +
20709 +       vid = 0;
20710 +       while (len-- > 0) {
20711 +               c = *str - '0';
20712 +               str++;
20713 +               if (c > 9)
20714 +                       return -1;
20715 +               if (vid >= MAX_MULBY10)
20716 +                       return -1;
20717 +               vid *= 10;
20718 +               vid += c;
20719 +               if (!vid)
20720 +                       return -1;
20721 +       }
20722 +       return vid;
20723 +}
20724 +
20725 +/* now the upper level (virtual) */
20726 +
20727 +
20728 +static struct file_operations proc_xid_file_operations = {
20729 +       .read =         generic_read_dir,
20730 +       .iterate =      proc_xid_iterate,
20731 +};
20732 +
20733 +static struct inode_operations proc_xid_inode_operations = {
20734 +       .lookup =       proc_xid_lookup,
20735 +};
20736 +
20737 +static struct vs_entry vx_virtual_stuff[] = {
20738 +       INF("info",     S_IRUGO, virtual_info),
20739 +       INF("status",   S_IRUGO, virtual_status),
20740 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
20741 +};
20742 +
20743 +
20744 +static struct dentry *proc_virtual_lookup(struct inode *dir,
20745 +       struct dentry *dentry, unsigned int flags)
20746 +{
20747 +       struct vs_entry *p = vx_virtual_stuff;
20748 +       struct dentry *error = ERR_PTR(-ENOENT);
20749 +       int id = 0;
20750 +
20751 +       for (; p->name; p++) {
20752 +               if (p->len != dentry->d_name.len)
20753 +                       continue;
20754 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20755 +                       break;
20756 +       }
20757 +       if (p->name)
20758 +               goto instantiate;
20759 +
20760 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
20761 +       if ((id < 0) || !xid_is_hashed(id))
20762 +               goto out;
20763 +
20764 +instantiate:
20765 +       error = proc_xid_instantiate(dir, dentry, id, p);
20766 +out:
20767 +       return error;
20768 +}
20769 +
20770 +static struct file_operations proc_nid_file_operations = {
20771 +       .read =         generic_read_dir,
20772 +       .iterate =      proc_nid_iterate,
20773 +};
20774 +
20775 +static struct inode_operations proc_nid_inode_operations = {
20776 +       .lookup =       proc_nid_lookup,
20777 +};
20778 +
20779 +static struct vs_entry nx_virtnet_stuff[] = {
20780 +       INF("info",     S_IRUGO, virtnet_info),
20781 +       INF("status",   S_IRUGO, virtnet_status),
20782 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
20783 +};
20784 +
20785 +
20786 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
20787 +       struct dentry *dentry, unsigned int flags)
20788 +{
20789 +       struct vs_entry *p = nx_virtnet_stuff;
20790 +       struct dentry *error = ERR_PTR(-ENOENT);
20791 +       int id = 0;
20792 +
20793 +       for (; p->name; p++) {
20794 +               if (p->len != dentry->d_name.len)
20795 +                       continue;
20796 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20797 +                       break;
20798 +       }
20799 +       if (p->name)
20800 +               goto instantiate;
20801 +
20802 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
20803 +       if ((id < 0) || !nid_is_hashed(id))
20804 +               goto out;
20805 +
20806 +instantiate:
20807 +       error = proc_nid_instantiate(dir, dentry, id, p);
20808 +out:
20809 +       return error;
20810 +}
20811 +
20812 +
20813 +#define PROC_MAXVIDS 32
20814 +
20815 +int proc_virtual_iterate(struct file *filp, struct dir_context *ctx)
20816 +{
20817 +       struct vs_entry *p = vx_virtual_stuff;
20818 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
20819 +       int index;
20820 +       unsigned int xid_array[PROC_MAXVIDS];
20821 +       char buf[PROC_NUMBUF];
20822 +       unsigned int nr_xids, i;
20823 +
20824 +       if (!dir_emit_dots(filp, ctx))
20825 +               return 0;
20826 +
20827 +       index = ctx->pos - 2;
20828 +       if (index < size) {
20829 +               for (p += index; p->name; p++) {
20830 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20831 +                               vs_proc_instantiate, 0, p))
20832 +                               return 0;
20833 +                       ctx->pos++;
20834 +               }
20835 +       }
20836 +
20837 +       index = ctx->pos - size;
20838 +       p = &vx_virtual_stuff[size - 1];
20839 +       nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
20840 +       for (i = 0; i < nr_xids; i++) {
20841 +               int n, xid = xid_array[i];
20842 +               unsigned int j = PROC_NUMBUF;
20843 +
20844 +               n = xid;
20845 +               do
20846 +                       buf[--j] = '0' + (n % 10);
20847 +               while (n /= 10);
20848 +
20849 +               if (vx_proc_fill_cache(filp, ctx,
20850 +                       buf + j, PROC_NUMBUF - j,
20851 +                       vs_proc_instantiate, xid, p))
20852 +                       return 0;
20853 +               ctx->pos++;
20854 +       }
20855 +       return 0;
20856 +}
20857 +
20858 +static int proc_virtual_getattr(struct vfsmount *mnt,
20859 +       struct dentry *dentry, struct kstat *stat)
20860 +{
20861 +       struct inode *inode = dentry->d_inode;
20862 +
20863 +       generic_fillattr(inode, stat);
20864 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
20865 +       return 0;
20866 +}
20867 +
20868 +static struct file_operations proc_virtual_dir_operations = {
20869 +       .read =         generic_read_dir,
20870 +       .iterate =      proc_virtual_iterate,
20871 +};
20872 +
20873 +static struct inode_operations proc_virtual_dir_inode_operations = {
20874 +       .getattr =      proc_virtual_getattr,
20875 +       .lookup =       proc_virtual_lookup,
20876 +};
20877 +
20878 +
20879 +
20880 +int proc_virtnet_iterate(struct file *filp, struct dir_context *ctx)
20881 +{
20882 +       struct vs_entry *p = nx_virtnet_stuff;
20883 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
20884 +       int index;
20885 +       unsigned int nid_array[PROC_MAXVIDS];
20886 +       char buf[PROC_NUMBUF];
20887 +       unsigned int nr_nids, i;
20888 +
20889 +       if (!dir_emit_dots(filp, ctx))
20890 +               return 0;
20891 +
20892 +       index = ctx->pos - 2;
20893 +       if (index < size) {
20894 +               for (p += index; p->name; p++) {
20895 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20896 +                               vs_proc_instantiate, 0, p))
20897 +                               return 0;
20898 +                       ctx->pos++;
20899 +               }
20900 +       }
20901 +
20902 +       index = ctx->pos - size;
20903 +       p = &nx_virtnet_stuff[size - 1];
20904 +       nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
20905 +       for (i = 0; i < nr_nids; i++) {
20906 +               int n, nid = nid_array[i];
20907 +               unsigned int j = PROC_NUMBUF;
20908 +
20909 +               n = nid;
20910 +               do
20911 +                       buf[--j] = '0' + (n % 10);
20912 +               while (n /= 10);
20913 +
20914 +               if (vx_proc_fill_cache(filp, ctx,
20915 +                       buf + j, PROC_NUMBUF - j,
20916 +                       vs_proc_instantiate, nid, p))
20917 +                       return 0;
20918 +               ctx->pos++;
20919 +       }
20920 +       return 0;
20921 +}
20922 +
20923 +static int proc_virtnet_getattr(struct vfsmount *mnt,
20924 +       struct dentry *dentry, struct kstat *stat)
20925 +{
20926 +       struct inode *inode = dentry->d_inode;
20927 +
20928 +       generic_fillattr(inode, stat);
20929 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
20930 +       return 0;
20931 +}
20932 +
20933 +static struct file_operations proc_virtnet_dir_operations = {
20934 +       .read =         generic_read_dir,
20935 +       .iterate =      proc_virtnet_iterate,
20936 +};
20937 +
20938 +static struct inode_operations proc_virtnet_dir_inode_operations = {
20939 +       .getattr =      proc_virtnet_getattr,
20940 +       .lookup =       proc_virtnet_lookup,
20941 +};
20942 +
20943 +
20944 +
20945 +void proc_vx_init(void)
20946 +{
20947 +       struct proc_dir_entry *ent;
20948 +
20949 +       ent = proc_mkdir("virtual", 0);
20950 +       if (ent) {
20951 +               ent->proc_fops = &proc_virtual_dir_operations;
20952 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
20953 +       }
20954 +       proc_virtual = ent;
20955 +
20956 +       ent = proc_mkdir("virtnet", 0);
20957 +       if (ent) {
20958 +               ent->proc_fops = &proc_virtnet_dir_operations;
20959 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
20960 +       }
20961 +       proc_virtnet = ent;
20962 +}
20963 +
20964 +
20965 +
20966 +
20967 +/* per pid info */
20968 +
20969 +void render_cap_t(struct seq_file *, const char *,
20970 +       struct vx_info *, kernel_cap_t *);
20971 +
20972 +
20973 +int proc_pid_vx_info(
20974 +       struct seq_file *m,
20975 +       struct pid_namespace *ns,
20976 +       struct pid *pid,
20977 +       struct task_struct *p)
20978 +{
20979 +       struct vx_info *vxi;
20980 +
20981 +       seq_printf(m, "XID:\t%d\n", vx_task_xid(p));
20982 +
20983 +       vxi = task_get_vx_info(p);
20984 +       if (!vxi)
20985 +               return 0;
20986 +
20987 +       render_cap_t(m, "BCaps:\t", vxi, &vxi->vx_bcaps);
20988 +       seq_printf(m, "CCaps:\t%016llx\n",
20989 +               (unsigned long long)vxi->vx_ccaps);
20990 +       seq_printf(m, "CFlags:\t%016llx\n",
20991 +               (unsigned long long)vxi->vx_flags);
20992 +       seq_printf(m, "CIPid:\t%d\n", vxi->vx_initpid);
20993 +
20994 +       put_vx_info(vxi);
20995 +       return 0;
20996 +}
20997 +
20998 +
20999 +int proc_pid_nx_info(
21000 +       struct seq_file *m,
21001 +       struct pid_namespace *ns,
21002 +       struct pid *pid,
21003 +       struct task_struct *p)
21004 +{
21005 +       struct nx_info *nxi;
21006 +       struct nx_addr_v4 *v4a;
21007 +#ifdef CONFIG_IPV6
21008 +       struct nx_addr_v6 *v6a;
21009 +#endif
21010 +       int i;
21011 +
21012 +       seq_printf(m, "NID:\t%d\n", nx_task_nid(p));
21013 +
21014 +       nxi = task_get_nx_info(p);
21015 +       if (!nxi)
21016 +               return 0;
21017 +
21018 +       seq_printf(m, "NCaps:\t%016llx\n",
21019 +               (unsigned long long)nxi->nx_ncaps);
21020 +       seq_printf(m, "NFlags:\t%016llx\n",
21021 +               (unsigned long long)nxi->nx_flags);
21022 +
21023 +       seq_printf(m, "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21024 +               NIPQUAD(nxi->v4_bcast.s_addr));
21025 +       seq_printf(m, "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21026 +               NIPQUAD(nxi->v4_lback.s_addr));
21027 +       if (!NX_IPV4(nxi))
21028 +               goto skip_v4;
21029 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21030 +               seq_printf(m, "V4Root[%d]:\t" NXAV4_FMT "\n",
21031 +                       i, NXAV4(v4a));
21032 +skip_v4:
21033 +#ifdef CONFIG_IPV6
21034 +       if (!NX_IPV6(nxi))
21035 +               goto skip_v6;
21036 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21037 +               seq_printf(m, "V6Root[%d]:\t" NXAV6_FMT "\n",
21038 +                       i, NXAV6(v6a));
21039 +skip_v6:
21040 +#endif
21041 +       put_nx_info(nxi);
21042 +       return 0;
21043 +}
21044 +
21045 diff -NurpP --minimal linux-4.4.115/kernel/vserver/sched.c linux-4.4.115-vs2.3.9.7/kernel/vserver/sched.c
21046 --- linux-4.4.115/kernel/vserver/sched.c        1970-01-01 00:00:00.000000000 +0000
21047 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/sched.c      2018-01-09 16:36:34.000000000 +0000
21048 @@ -0,0 +1,83 @@
21049 +/*
21050 + *  linux/kernel/vserver/sched.c
21051 + *
21052 + *  Virtual Server: Scheduler Support
21053 + *
21054 + *  Copyright (C) 2004-2010  Herbert Pötzl
21055 + *
21056 + *  V0.01  adapted Sam Vilains version to 2.6.3
21057 + *  V0.02  removed legacy interface
21058 + *  V0.03  changed vcmds to vxi arg
21059 + *  V0.04  removed older and legacy interfaces
21060 + *  V0.05  removed scheduler code/commands
21061 + *
21062 + */
21063 +
21064 +#include <linux/vs_context.h>
21065 +#include <linux/vs_sched.h>
21066 +#include <linux/cpumask.h>
21067 +#include <linux/vserver/sched_cmd.h>
21068 +
21069 +#include <asm/uaccess.h>
21070 +
21071 +
21072 +void vx_update_sched_param(struct _vx_sched *sched,
21073 +       struct _vx_sched_pc *sched_pc)
21074 +{
21075 +       sched_pc->prio_bias = sched->prio_bias;
21076 +}
21077 +
21078 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21079 +{
21080 +       int cpu;
21081 +
21082 +       if (data->prio_bias > MAX_PRIO_BIAS)
21083 +               data->prio_bias = MAX_PRIO_BIAS;
21084 +       if (data->prio_bias < MIN_PRIO_BIAS)
21085 +               data->prio_bias = MIN_PRIO_BIAS;
21086 +
21087 +       if (data->cpu_id != ~0) {
21088 +               vxi->sched.update = *get_cpu_mask(data->cpu_id);
21089 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
21090 +                       cpu_online_mask);
21091 +       } else
21092 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
21093 +
21094 +       for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)vxi->sched.update)
21095 +               vx_update_sched_param(&vxi->sched,
21096 +                       &vx_per_cpu(vxi, sched_pc, cpu));
21097 +       return 0;
21098 +}
21099 +
21100 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21101 +{
21102 +       struct vcmd_prio_bias vc_data;
21103 +
21104 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21105 +               return -EFAULT;
21106 +
21107 +       return do_set_prio_bias(vxi, &vc_data);
21108 +}
21109 +
21110 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21111 +{
21112 +       struct vcmd_prio_bias vc_data;
21113 +       struct _vx_sched_pc *pcd;
21114 +       int cpu;
21115 +
21116 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21117 +               return -EFAULT;
21118 +
21119 +       cpu = vc_data.cpu_id;
21120 +
21121 +       if (!cpu_possible(cpu))
21122 +               return -EINVAL;
21123 +
21124 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21125 +       vc_data.prio_bias = pcd->prio_bias;
21126 +
21127 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21128 +               return -EFAULT;
21129 +       return 0;
21130 +}
21131 +
21132 diff -NurpP --minimal linux-4.4.115/kernel/vserver/sched_init.h linux-4.4.115-vs2.3.9.7/kernel/vserver/sched_init.h
21133 --- linux-4.4.115/kernel/vserver/sched_init.h   1970-01-01 00:00:00.000000000 +0000
21134 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/sched_init.h 2018-01-09 16:36:34.000000000 +0000
21135 @@ -0,0 +1,27 @@
21136 +
21137 +static inline void vx_info_init_sched(struct _vx_sched *sched)
21138 +{
21139 +       /* scheduling; hard code starting values as constants */
21140 +       sched->prio_bias = 0;
21141 +}
21142 +
21143 +static inline
21144 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21145 +{
21146 +       sched_pc->prio_bias = 0;
21147 +
21148 +       sched_pc->user_ticks = 0;
21149 +       sched_pc->sys_ticks = 0;
21150 +       sched_pc->hold_ticks = 0;
21151 +}
21152 +
21153 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
21154 +{
21155 +       return;
21156 +}
21157 +
21158 +static inline
21159 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21160 +{
21161 +       return;
21162 +}
21163 diff -NurpP --minimal linux-4.4.115/kernel/vserver/sched_proc.h linux-4.4.115-vs2.3.9.7/kernel/vserver/sched_proc.h
21164 --- linux-4.4.115/kernel/vserver/sched_proc.h   1970-01-01 00:00:00.000000000 +0000
21165 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/sched_proc.h 2018-01-09 16:36:34.000000000 +0000
21166 @@ -0,0 +1,32 @@
21167 +#ifndef _VX_SCHED_PROC_H
21168 +#define _VX_SCHED_PROC_H
21169 +
21170 +
21171 +static inline
21172 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
21173 +{
21174 +       int length = 0;
21175 +
21176 +       length += sprintf(buffer,
21177 +               "PrioBias:\t%8d\n",
21178 +               sched->prio_bias);
21179 +       return length;
21180 +}
21181 +
21182 +static inline
21183 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
21184 +       char *buffer, int cpu)
21185 +{
21186 +       int length = 0;
21187 +
21188 +       length += sprintf(buffer + length,
21189 +               "cpu %d: %lld %lld %lld", cpu,
21190 +               (unsigned long long)sched_pc->user_ticks,
21191 +               (unsigned long long)sched_pc->sys_ticks,
21192 +               (unsigned long long)sched_pc->hold_ticks);
21193 +       length += sprintf(buffer + length,
21194 +               " %d\n", sched_pc->prio_bias);
21195 +       return length;
21196 +}
21197 +
21198 +#endif /* _VX_SCHED_PROC_H */
21199 diff -NurpP --minimal linux-4.4.115/kernel/vserver/signal.c linux-4.4.115-vs2.3.9.7/kernel/vserver/signal.c
21200 --- linux-4.4.115/kernel/vserver/signal.c       1970-01-01 00:00:00.000000000 +0000
21201 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/signal.c     2018-01-09 16:36:34.000000000 +0000
21202 @@ -0,0 +1,134 @@
21203 +/*
21204 + *  linux/kernel/vserver/signal.c
21205 + *
21206 + *  Virtual Server: Signal Support
21207 + *
21208 + *  Copyright (C) 2003-2007  Herbert Pötzl
21209 + *
21210 + *  V0.01  broken out from vcontext V0.05
21211 + *  V0.02  changed vcmds to vxi arg
21212 + *  V0.03  adjusted siginfo for kill
21213 + *
21214 + */
21215 +
21216 +#include <asm/uaccess.h>
21217 +
21218 +#include <linux/vs_context.h>
21219 +#include <linux/vs_pid.h>
21220 +#include <linux/vserver/signal_cmd.h>
21221 +
21222 +
21223 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
21224 +{
21225 +       int retval, count = 0;
21226 +       struct task_struct *p;
21227 +       struct siginfo *sip = SEND_SIG_PRIV;
21228 +
21229 +       retval = -ESRCH;
21230 +       vxdprintk(VXD_CBIT(misc, 4),
21231 +               "vx_info_kill(%p[#%d],%d,%d)*",
21232 +               vxi, vxi->vx_id, pid, sig);
21233 +       read_lock(&tasklist_lock);
21234 +       switch (pid) {
21235 +       case  0:
21236 +       case -1:
21237 +               for_each_process(p) {
21238 +                       int err = 0;
21239 +
21240 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
21241 +                               (pid && vxi->vx_initpid == p->pid))
21242 +                               continue;
21243 +
21244 +                       err = group_send_sig_info(sig, sip, p);
21245 +                       ++count;
21246 +                       if (err != -EPERM)
21247 +                               retval = err;
21248 +               }
21249 +               break;
21250 +
21251 +       case 1:
21252 +               if (vxi->vx_initpid) {
21253 +                       pid = vxi->vx_initpid;
21254 +                       /* for now, only SIGINT to private init ... */
21255 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21256 +                               /* ... as long as there are tasks left */
21257 +                               (atomic_read(&vxi->vx_tasks) > 1))
21258 +                               sig = SIGINT;
21259 +               }
21260 +               /* fallthrough */
21261 +       default:
21262 +               rcu_read_lock();
21263 +               p = find_task_by_real_pid(pid);
21264 +               rcu_read_unlock();
21265 +               if (p) {
21266 +                       if (vx_task_xid(p) == vxi->vx_id)
21267 +                               retval = group_send_sig_info(sig, sip, p);
21268 +               }
21269 +               break;
21270 +       }
21271 +       read_unlock(&tasklist_lock);
21272 +       vxdprintk(VXD_CBIT(misc, 4),
21273 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
21274 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
21275 +       return retval;
21276 +}
21277 +
21278 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
21279 +{
21280 +       struct vcmd_ctx_kill_v0 vc_data;
21281 +
21282 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21283 +               return -EFAULT;
21284 +
21285 +       /* special check to allow guest shutdown */
21286 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21287 +               /* forbid killall pid=0 when init is present */
21288 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
21289 +               (vc_data.pid > 1)))
21290 +               return -EACCES;
21291 +
21292 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
21293 +}
21294 +
21295 +
21296 +static int __wait_exit(struct vx_info *vxi)
21297 +{
21298 +       DECLARE_WAITQUEUE(wait, current);
21299 +       int ret = 0;
21300 +
21301 +       add_wait_queue(&vxi->vx_wait, &wait);
21302 +       set_current_state(TASK_INTERRUPTIBLE);
21303 +
21304 +wait:
21305 +       if (vx_info_state(vxi,
21306 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
21307 +               goto out;
21308 +       if (signal_pending(current)) {
21309 +               ret = -ERESTARTSYS;
21310 +               goto out;
21311 +       }
21312 +       schedule();
21313 +       goto wait;
21314 +
21315 +out:
21316 +       set_current_state(TASK_RUNNING);
21317 +       remove_wait_queue(&vxi->vx_wait, &wait);
21318 +       return ret;
21319 +}
21320 +
21321 +
21322 +
21323 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
21324 +{
21325 +       struct vcmd_wait_exit_v0 vc_data;
21326 +       int ret;
21327 +
21328 +       ret = __wait_exit(vxi);
21329 +       vc_data.reboot_cmd = vxi->reboot_cmd;
21330 +       vc_data.exit_code = vxi->exit_code;
21331 +
21332 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21333 +               ret = -EFAULT;
21334 +       return ret;
21335 +}
21336 +
21337 diff -NurpP --minimal linux-4.4.115/kernel/vserver/space.c linux-4.4.115-vs2.3.9.7/kernel/vserver/space.c
21338 --- linux-4.4.115/kernel/vserver/space.c        1970-01-01 00:00:00.000000000 +0000
21339 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/space.c      2018-01-09 16:36:34.000000000 +0000
21340 @@ -0,0 +1,436 @@
21341 +/*
21342 + *  linux/kernel/vserver/space.c
21343 + *
21344 + *  Virtual Server: Context Space Support
21345 + *
21346 + *  Copyright (C) 2003-2010  Herbert Pötzl
21347 + *
21348 + *  V0.01  broken out from context.c 0.07
21349 + *  V0.02  added task locking for namespace
21350 + *  V0.03  broken out vx_enter_namespace
21351 + *  V0.04  added *space support and commands
21352 + *  V0.05  added credential support
21353 + *
21354 + */
21355 +
21356 +#include <linux/utsname.h>
21357 +#include <linux/nsproxy.h>
21358 +#include <linux/err.h>
21359 +#include <linux/fs_struct.h>
21360 +#include <linux/cred.h>
21361 +#include <asm/uaccess.h>
21362 +
21363 +#include <linux/vs_context.h>
21364 +#include <linux/vserver/space.h>
21365 +#include <linux/vserver/space_cmd.h>
21366 +
21367 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
21368 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
21369 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
21370 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
21371 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
21372 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
21373 +
21374 +
21375 +/* namespace functions */
21376 +
21377 +#include <linux/mnt_namespace.h>
21378 +#include <linux/user_namespace.h>
21379 +#include <linux/pid_namespace.h>
21380 +#include <linux/ipc_namespace.h>
21381 +#include <net/net_namespace.h>
21382 +#include "../fs/mount.h"
21383 +
21384 +
21385 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
21386 +       .mask = CLONE_FS |
21387 +               CLONE_NEWNS |
21388 +#ifdef CONFIG_UTS_NS
21389 +               CLONE_NEWUTS |
21390 +#endif
21391 +#ifdef CONFIG_IPC_NS
21392 +               CLONE_NEWIPC |
21393 +#endif
21394 +#ifdef CONFIG_USER_NS
21395 +               CLONE_NEWUSER |
21396 +#endif
21397 +               0
21398 +};
21399 +
21400 +static const struct vcmd_space_mask_v1 space_mask = {
21401 +       .mask = CLONE_FS |
21402 +               CLONE_NEWNS |
21403 +#ifdef CONFIG_UTS_NS
21404 +               CLONE_NEWUTS |
21405 +#endif
21406 +#ifdef CONFIG_IPC_NS
21407 +               CLONE_NEWIPC |
21408 +#endif
21409 +#ifdef CONFIG_USER_NS
21410 +               CLONE_NEWUSER |
21411 +#endif
21412 +#ifdef CONFIG_PID_NS
21413 +               CLONE_NEWPID |
21414 +#endif
21415 +#ifdef CONFIG_NET_NS
21416 +               CLONE_NEWNET |
21417 +#endif
21418 +               0
21419 +};
21420 +
21421 +static const struct vcmd_space_mask_v1 default_space_mask = {
21422 +       .mask = CLONE_FS |
21423 +               CLONE_NEWNS |
21424 +#ifdef CONFIG_UTS_NS
21425 +               CLONE_NEWUTS |
21426 +#endif
21427 +#ifdef CONFIG_IPC_NS
21428 +               CLONE_NEWIPC |
21429 +#endif
21430 +#ifdef CONFIG_USER_NS
21431 +//             CLONE_NEWUSER |
21432 +#endif
21433 +#ifdef CONFIG_PID_NS
21434 +//             CLONE_NEWPID |
21435 +#endif
21436 +               0
21437 +};
21438 +
21439 +/*
21440 + *     build a new nsproxy mix
21441 + *      assumes that both proxies are 'const'
21442 + *     does not touch nsproxy refcounts
21443 + *     will hold a reference on the result.
21444 + */
21445 +
21446 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
21447 +       struct nsproxy *new_nsproxy, unsigned long mask)
21448 +{
21449 +       struct mnt_namespace *old_ns;
21450 +       struct uts_namespace *old_uts;
21451 +       struct ipc_namespace *old_ipc;
21452 +#ifdef CONFIG_PID_NS
21453 +       struct pid_namespace *old_pid;
21454 +#endif
21455 +#ifdef CONFIG_NET_NS
21456 +       struct net *old_net;
21457 +#endif
21458 +       struct nsproxy *nsproxy;
21459 +
21460 +       nsproxy = copy_nsproxy(old_nsproxy);
21461 +       if (!nsproxy)
21462 +               goto out;
21463 +
21464 +       if (mask & CLONE_NEWNS) {
21465 +               old_ns = nsproxy->mnt_ns;
21466 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
21467 +               if (nsproxy->mnt_ns)
21468 +                       get_mnt_ns(nsproxy->mnt_ns);
21469 +       } else
21470 +               old_ns = NULL;
21471 +
21472 +       if (mask & CLONE_NEWUTS) {
21473 +               old_uts = nsproxy->uts_ns;
21474 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
21475 +               if (nsproxy->uts_ns)
21476 +                       get_uts_ns(nsproxy->uts_ns);
21477 +       } else
21478 +               old_uts = NULL;
21479 +
21480 +       if (mask & CLONE_NEWIPC) {
21481 +               old_ipc = nsproxy->ipc_ns;
21482 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
21483 +               if (nsproxy->ipc_ns)
21484 +                       get_ipc_ns(nsproxy->ipc_ns);
21485 +       } else
21486 +               old_ipc = NULL;
21487 +
21488 +#ifdef CONFIG_PID_NS
21489 +       if (mask & CLONE_NEWPID) {
21490 +               old_pid = nsproxy->pid_ns_for_children;
21491 +               nsproxy->pid_ns_for_children = new_nsproxy->pid_ns_for_children;
21492 +               if (nsproxy->pid_ns_for_children)
21493 +                       get_pid_ns(nsproxy->pid_ns_for_children);
21494 +       } else
21495 +               old_pid = NULL;
21496 +#endif
21497 +#ifdef CONFIG_NET_NS
21498 +       if (mask & CLONE_NEWNET) {
21499 +               old_net = nsproxy->net_ns;
21500 +               nsproxy->net_ns = new_nsproxy->net_ns;
21501 +               if (nsproxy->net_ns)
21502 +                       get_net(nsproxy->net_ns);
21503 +       } else
21504 +               old_net = NULL;
21505 +#endif
21506 +       if (old_ns)
21507 +               put_mnt_ns(old_ns);
21508 +       if (old_uts)
21509 +               put_uts_ns(old_uts);
21510 +       if (old_ipc)
21511 +               put_ipc_ns(old_ipc);
21512 +#ifdef CONFIG_PID_NS
21513 +       if (old_pid)
21514 +               put_pid_ns(old_pid);
21515 +#endif
21516 +#ifdef CONFIG_NET_NS
21517 +       if (old_net)
21518 +               put_net(old_net);
21519 +#endif
21520 +out:
21521 +       return nsproxy;
21522 +}
21523 +
21524 +
21525 +/*
21526 + *     merge two nsproxy structs into a new one.
21527 + *     will hold a reference on the result.
21528 + */
21529 +
21530 +static inline
21531 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
21532 +       struct nsproxy *proxy, unsigned long mask)
21533 +{
21534 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
21535 +
21536 +       if (!proxy)
21537 +               return NULL;
21538 +
21539 +       if (mask) {
21540 +               /* vs_mix_nsproxy returns with reference */
21541 +               return vs_mix_nsproxy(old ? old : &null_proxy,
21542 +                       proxy, mask);
21543 +       }
21544 +       get_nsproxy(proxy);
21545 +       return proxy;
21546 +}
21547 +
21548 +
21549 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21550 +{
21551 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
21552 +       struct fs_struct *fs_cur, *fs = NULL;
21553 +       struct _vx_space *space;
21554 +       int ret, kill = 0;
21555 +
21556 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
21557 +               vxi, vxi->vx_id, mask, index);
21558 +
21559 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
21560 +               return -EACCES;
21561 +
21562 +       if (index >= VX_SPACES)
21563 +               return -EINVAL;
21564 +
21565 +       space = &vxi->space[index];
21566 +
21567 +       if (!mask)
21568 +               mask = space->vx_nsmask;
21569 +
21570 +       if ((mask & space->vx_nsmask) != mask)
21571 +               return -EINVAL;
21572 +
21573 +       if (mask & CLONE_FS) {
21574 +               fs = copy_fs_struct(space->vx_fs);
21575 +               if (!fs)
21576 +                       return -ENOMEM;
21577 +       }
21578 +       proxy = space->vx_nsproxy;
21579 +
21580 +       vxdprintk(VXD_CBIT(space, 9),
21581 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
21582 +               vxi, vxi->vx_id, mask, index, proxy, fs);
21583 +
21584 +       task_lock(current);
21585 +       fs_cur = current->fs;
21586 +
21587 +       if (mask & CLONE_FS) {
21588 +               spin_lock(&fs_cur->lock);
21589 +               current->fs = fs;
21590 +               kill = !--fs_cur->users;
21591 +               spin_unlock(&fs_cur->lock);
21592 +       }
21593 +
21594 +       proxy_cur = current->nsproxy;
21595 +       get_nsproxy(proxy_cur);
21596 +       task_unlock(current);
21597 +
21598 +       if (kill)
21599 +               free_fs_struct(fs_cur);
21600 +
21601 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
21602 +       if (IS_ERR(proxy_new)) {
21603 +               ret = PTR_ERR(proxy_new);
21604 +               goto out_put;
21605 +       }
21606 +
21607 +       proxy_new = xchg(&current->nsproxy, proxy_new);
21608 +
21609 +       if (mask & CLONE_NEWUSER) {
21610 +               struct cred *cred;
21611 +
21612 +               vxdprintk(VXD_CBIT(space, 10),
21613 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
21614 +                       vxi, vxi->vx_id, space->vx_cred,
21615 +                       current->real_cred, current->cred);
21616 +
21617 +               if (space->vx_cred) {
21618 +                       cred = __prepare_creds(space->vx_cred);
21619 +                       if (cred)
21620 +                               commit_creds(cred);
21621 +               }
21622 +       }
21623 +
21624 +       ret = 0;
21625 +
21626 +       if (proxy_new)
21627 +               put_nsproxy(proxy_new);
21628 +out_put:
21629 +       if (proxy_cur)
21630 +               put_nsproxy(proxy_cur);
21631 +       return ret;
21632 +}
21633 +
21634 +
21635 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21636 +{
21637 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
21638 +       struct fs_struct *fs_vxi, *fs = NULL;
21639 +       struct _vx_space *space;
21640 +       int ret, kill = 0;
21641 +
21642 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
21643 +               vxi, vxi->vx_id, mask, index);
21644 +
21645 +       if ((mask & space_mask.mask) != mask)
21646 +               return -EINVAL;
21647 +
21648 +       if (index >= VX_SPACES)
21649 +               return -EINVAL;
21650 +
21651 +       space = &vxi->space[index];
21652 +
21653 +       proxy_vxi = space->vx_nsproxy;
21654 +       fs_vxi = space->vx_fs;
21655 +
21656 +       if (mask & CLONE_FS) {
21657 +               fs = copy_fs_struct(current->fs);
21658 +               if (!fs)
21659 +                       return -ENOMEM;
21660 +       }
21661 +
21662 +       task_lock(current);
21663 +
21664 +       if (mask & CLONE_FS) {
21665 +               spin_lock(&fs_vxi->lock);
21666 +               space->vx_fs = fs;
21667 +               kill = !--fs_vxi->users;
21668 +               spin_unlock(&fs_vxi->lock);
21669 +       }
21670 +
21671 +       proxy_cur = current->nsproxy;
21672 +       get_nsproxy(proxy_cur);
21673 +       task_unlock(current);
21674 +
21675 +       if (kill)
21676 +               free_fs_struct(fs_vxi);
21677 +
21678 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
21679 +       if (IS_ERR(proxy_new)) {
21680 +               ret = PTR_ERR(proxy_new);
21681 +               goto out_put;
21682 +       }
21683 +
21684 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
21685 +       space->vx_nsmask |= mask;
21686 +
21687 +       if (mask & CLONE_NEWUSER) {
21688 +               struct cred *cred;
21689 +
21690 +               vxdprintk(VXD_CBIT(space, 10),
21691 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
21692 +                       vxi, vxi->vx_id, space->vx_cred,
21693 +                       current->real_cred, current->cred);
21694 +
21695 +               cred = prepare_creds();
21696 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
21697 +               if (cred)
21698 +                       abort_creds(cred);
21699 +       }
21700 +
21701 +       ret = 0;
21702 +
21703 +       if (proxy_new)
21704 +               put_nsproxy(proxy_new);
21705 +out_put:
21706 +       if (proxy_cur)
21707 +               put_nsproxy(proxy_cur);
21708 +       return ret;
21709 +}
21710 +
21711 +
21712 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
21713 +{
21714 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21715 +
21716 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21717 +               return -EFAULT;
21718 +
21719 +       return vx_enter_space(vxi, vc_data.mask, 0);
21720 +}
21721 +
21722 +int vc_enter_space(struct vx_info *vxi, void __user *data)
21723 +{
21724 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21725 +
21726 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21727 +               return -EFAULT;
21728 +
21729 +       if (vc_data.index >= VX_SPACES)
21730 +               return -EINVAL;
21731 +
21732 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
21733 +}
21734 +
21735 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
21736 +{
21737 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21738 +
21739 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21740 +               return -EFAULT;
21741 +
21742 +       return vx_set_space(vxi, vc_data.mask, 0);
21743 +}
21744 +
21745 +int vc_set_space(struct vx_info *vxi, void __user *data)
21746 +{
21747 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21748 +
21749 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21750 +               return -EFAULT;
21751 +
21752 +       if (vc_data.index >= VX_SPACES)
21753 +               return -EINVAL;
21754 +
21755 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
21756 +}
21757 +
21758 +int vc_get_space_mask(void __user *data, int type)
21759 +{
21760 +       const struct vcmd_space_mask_v1 *mask;
21761 +
21762 +       if (type == 0)
21763 +               mask = &space_mask_v0;
21764 +       else if (type == 1)
21765 +               mask = &space_mask;
21766 +       else
21767 +               mask = &default_space_mask;
21768 +
21769 +       vxdprintk(VXD_CBIT(space, 10),
21770 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
21771 +
21772 +       if (copy_to_user(data, mask, sizeof(*mask)))
21773 +               return -EFAULT;
21774 +       return 0;
21775 +}
21776 +
21777 diff -NurpP --minimal linux-4.4.115/kernel/vserver/switch.c linux-4.4.115-vs2.3.9.7/kernel/vserver/switch.c
21778 --- linux-4.4.115/kernel/vserver/switch.c       1970-01-01 00:00:00.000000000 +0000
21779 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/switch.c     2018-01-09 16:36:34.000000000 +0000
21780 @@ -0,0 +1,556 @@
21781 +/*
21782 + *  linux/kernel/vserver/switch.c
21783 + *
21784 + *  Virtual Server: Syscall Switch
21785 + *
21786 + *  Copyright (C) 2003-2011  Herbert Pötzl
21787 + *
21788 + *  V0.01  syscall switch
21789 + *  V0.02  added signal to context
21790 + *  V0.03  added rlimit functions
21791 + *  V0.04  added iattr, task/xid functions
21792 + *  V0.05  added debug/history stuff
21793 + *  V0.06  added compat32 layer
21794 + *  V0.07  vcmd args and perms
21795 + *  V0.08  added status commands
21796 + *  V0.09  added tag commands
21797 + *  V0.10  added oom bias
21798 + *  V0.11  added device commands
21799 + *  V0.12  added warn mask
21800 + *
21801 + */
21802 +
21803 +#include <linux/vs_context.h>
21804 +#include <linux/vs_network.h>
21805 +#include <linux/vserver/switch.h>
21806 +
21807 +#include "vci_config.h"
21808 +
21809 +
21810 +static inline
21811 +int vc_get_version(uint32_t id)
21812 +{
21813 +       return VCI_VERSION;
21814 +}
21815 +
21816 +static inline
21817 +int vc_get_vci(uint32_t id)
21818 +{
21819 +       return vci_kernel_config();
21820 +}
21821 +
21822 +#include <linux/vserver/context_cmd.h>
21823 +#include <linux/vserver/cvirt_cmd.h>
21824 +#include <linux/vserver/cacct_cmd.h>
21825 +#include <linux/vserver/limit_cmd.h>
21826 +#include <linux/vserver/network_cmd.h>
21827 +#include <linux/vserver/sched_cmd.h>
21828 +#include <linux/vserver/debug_cmd.h>
21829 +#include <linux/vserver/inode_cmd.h>
21830 +#include <linux/vserver/dlimit_cmd.h>
21831 +#include <linux/vserver/signal_cmd.h>
21832 +#include <linux/vserver/space_cmd.h>
21833 +#include <linux/vserver/tag_cmd.h>
21834 +#include <linux/vserver/device_cmd.h>
21835 +
21836 +#include <linux/vserver/inode.h>
21837 +#include <linux/vserver/dlimit.h>
21838 +
21839 +
21840 +#ifdef CONFIG_COMPAT
21841 +#define __COMPAT(name, id, data, compat)       \
21842 +       (compat) ? name ## _x32(id, data) : name(id, data)
21843 +#define __COMPAT_NO_ID(name, data, compat)     \
21844 +       (compat) ? name ## _x32(data) : name(data)
21845 +#else
21846 +#define __COMPAT(name, id, data, compat)       \
21847 +       name(id, data)
21848 +#define __COMPAT_NO_ID(name, data, compat)     \
21849 +       name(data)
21850 +#endif
21851 +
21852 +
21853 +static inline
21854 +long do_vcmd(uint32_t cmd, uint32_t id,
21855 +       struct vx_info *vxi, struct nx_info *nxi,
21856 +       void __user *data, int compat)
21857 +{
21858 +       switch (cmd) {
21859 +
21860 +       case VCMD_get_version:
21861 +               return vc_get_version(id);
21862 +       case VCMD_get_vci:
21863 +               return vc_get_vci(id);
21864 +
21865 +       case VCMD_task_xid:
21866 +               return vc_task_xid(id);
21867 +       case VCMD_vx_info:
21868 +               return vc_vx_info(vxi, data);
21869 +
21870 +       case VCMD_task_nid:
21871 +               return vc_task_nid(id);
21872 +       case VCMD_nx_info:
21873 +               return vc_nx_info(nxi, data);
21874 +
21875 +       case VCMD_task_tag:
21876 +               return vc_task_tag(id);
21877 +
21878 +       case VCMD_set_space_v1:
21879 +               return vc_set_space_v1(vxi, data);
21880 +       /* this is version 2 */
21881 +       case VCMD_set_space:
21882 +               return vc_set_space(vxi, data);
21883 +
21884 +       case VCMD_get_space_mask_v0:
21885 +               return vc_get_space_mask(data, 0);
21886 +       /* this is version 1 */
21887 +       case VCMD_get_space_mask:
21888 +               return vc_get_space_mask(data, 1);
21889 +
21890 +       case VCMD_get_space_default:
21891 +               return vc_get_space_mask(data, -1);
21892 +
21893 +       case VCMD_set_umask:
21894 +               return vc_set_umask(vxi, data);
21895 +
21896 +       case VCMD_get_umask:
21897 +               return vc_get_umask(vxi, data);
21898 +
21899 +       case VCMD_set_wmask:
21900 +               return vc_set_wmask(vxi, data);
21901 +
21902 +       case VCMD_get_wmask:
21903 +               return vc_get_wmask(vxi, data);
21904 +#ifdef CONFIG_IA32_EMULATION
21905 +       case VCMD_get_rlimit:
21906 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
21907 +       case VCMD_set_rlimit:
21908 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
21909 +#else
21910 +       case VCMD_get_rlimit:
21911 +               return vc_get_rlimit(vxi, data);
21912 +       case VCMD_set_rlimit:
21913 +               return vc_set_rlimit(vxi, data);
21914 +#endif
21915 +       case VCMD_get_rlimit_mask:
21916 +               return vc_get_rlimit_mask(id, data);
21917 +       case VCMD_reset_hits:
21918 +               return vc_reset_hits(vxi, data);
21919 +       case VCMD_reset_minmax:
21920 +               return vc_reset_minmax(vxi, data);
21921 +
21922 +       case VCMD_get_vhi_name:
21923 +               return vc_get_vhi_name(vxi, data);
21924 +       case VCMD_set_vhi_name:
21925 +               return vc_set_vhi_name(vxi, data);
21926 +
21927 +       case VCMD_ctx_stat:
21928 +               return vc_ctx_stat(vxi, data);
21929 +       case VCMD_virt_stat:
21930 +               return vc_virt_stat(vxi, data);
21931 +       case VCMD_sock_stat:
21932 +               return vc_sock_stat(vxi, data);
21933 +       case VCMD_rlimit_stat:
21934 +               return vc_rlimit_stat(vxi, data);
21935 +
21936 +       case VCMD_set_cflags:
21937 +               return vc_set_cflags(vxi, data);
21938 +       case VCMD_get_cflags:
21939 +               return vc_get_cflags(vxi, data);
21940 +
21941 +       /* this is version 1 */
21942 +       case VCMD_set_ccaps:
21943 +               return vc_set_ccaps(vxi, data);
21944 +       /* this is version 1 */
21945 +       case VCMD_get_ccaps:
21946 +               return vc_get_ccaps(vxi, data);
21947 +       case VCMD_set_bcaps:
21948 +               return vc_set_bcaps(vxi, data);
21949 +       case VCMD_get_bcaps:
21950 +               return vc_get_bcaps(vxi, data);
21951 +
21952 +       case VCMD_set_badness:
21953 +               return vc_set_badness(vxi, data);
21954 +       case VCMD_get_badness:
21955 +               return vc_get_badness(vxi, data);
21956 +
21957 +       case VCMD_set_nflags:
21958 +               return vc_set_nflags(nxi, data);
21959 +       case VCMD_get_nflags:
21960 +               return vc_get_nflags(nxi, data);
21961 +
21962 +       case VCMD_set_ncaps:
21963 +               return vc_set_ncaps(nxi, data);
21964 +       case VCMD_get_ncaps:
21965 +               return vc_get_ncaps(nxi, data);
21966 +
21967 +       case VCMD_set_prio_bias:
21968 +               return vc_set_prio_bias(vxi, data);
21969 +       case VCMD_get_prio_bias:
21970 +               return vc_get_prio_bias(vxi, data);
21971 +       case VCMD_add_dlimit:
21972 +               return __COMPAT(vc_add_dlimit, id, data, compat);
21973 +       case VCMD_rem_dlimit:
21974 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
21975 +       case VCMD_set_dlimit:
21976 +               return __COMPAT(vc_set_dlimit, id, data, compat);
21977 +       case VCMD_get_dlimit:
21978 +               return __COMPAT(vc_get_dlimit, id, data, compat);
21979 +
21980 +       case VCMD_ctx_kill:
21981 +               return vc_ctx_kill(vxi, data);
21982 +
21983 +       case VCMD_wait_exit:
21984 +               return vc_wait_exit(vxi, data);
21985 +
21986 +       case VCMD_get_iattr:
21987 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
21988 +       case VCMD_set_iattr:
21989 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
21990 +
21991 +       case VCMD_fget_iattr:
21992 +               return vc_fget_iattr(id, data);
21993 +       case VCMD_fset_iattr:
21994 +               return vc_fset_iattr(id, data);
21995 +
21996 +       case VCMD_enter_space_v0:
21997 +               return vc_enter_space_v1(vxi, NULL);
21998 +       case VCMD_enter_space_v1:
21999 +               return vc_enter_space_v1(vxi, data);
22000 +       /* this is version 2 */
22001 +       case VCMD_enter_space:
22002 +               return vc_enter_space(vxi, data);
22003 +
22004 +       case VCMD_ctx_create_v0:
22005 +               return vc_ctx_create(id, NULL);
22006 +       case VCMD_ctx_create:
22007 +               return vc_ctx_create(id, data);
22008 +       case VCMD_ctx_migrate_v0:
22009 +               return vc_ctx_migrate(vxi, NULL);
22010 +       case VCMD_ctx_migrate:
22011 +               return vc_ctx_migrate(vxi, data);
22012 +
22013 +       case VCMD_net_create_v0:
22014 +               return vc_net_create(id, NULL);
22015 +       case VCMD_net_create:
22016 +               return vc_net_create(id, data);
22017 +       case VCMD_net_migrate:
22018 +               return vc_net_migrate(nxi, data);
22019 +
22020 +       case VCMD_tag_migrate:
22021 +               return vc_tag_migrate(id);
22022 +
22023 +       case VCMD_net_add:
22024 +               return vc_net_add(nxi, data);
22025 +       case VCMD_net_remove:
22026 +               return vc_net_remove(nxi, data);
22027 +
22028 +       case VCMD_net_add_ipv4_v1:
22029 +               return vc_net_add_ipv4_v1(nxi, data);
22030 +       /* this is version 2 */
22031 +       case VCMD_net_add_ipv4:
22032 +               return vc_net_add_ipv4(nxi, data);
22033 +
22034 +       case VCMD_net_rem_ipv4_v1:
22035 +               return vc_net_rem_ipv4_v1(nxi, data);
22036 +       /* this is version 2 */
22037 +       case VCMD_net_rem_ipv4:
22038 +               return vc_net_rem_ipv4(nxi, data);
22039 +#ifdef CONFIG_IPV6
22040 +       case VCMD_net_add_ipv6:
22041 +               return vc_net_add_ipv6(nxi, data);
22042 +       case VCMD_net_remove_ipv6:
22043 +               return vc_net_remove_ipv6(nxi, data);
22044 +#endif
22045 +/*     case VCMD_add_match_ipv4:
22046 +               return vc_add_match_ipv4(nxi, data);
22047 +       case VCMD_get_match_ipv4:
22048 +               return vc_get_match_ipv4(nxi, data);
22049 +#ifdef CONFIG_IPV6
22050 +       case VCMD_add_match_ipv6:
22051 +               return vc_add_match_ipv6(nxi, data);
22052 +       case VCMD_get_match_ipv6:
22053 +               return vc_get_match_ipv6(nxi, data);
22054 +#endif */
22055 +
22056 +#ifdef CONFIG_VSERVER_DEVICE
22057 +       case VCMD_set_mapping:
22058 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
22059 +       case VCMD_unset_mapping:
22060 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
22061 +#endif
22062 +#ifdef CONFIG_VSERVER_HISTORY
22063 +       case VCMD_dump_history:
22064 +               return vc_dump_history(id);
22065 +       case VCMD_read_history:
22066 +               return __COMPAT(vc_read_history, id, data, compat);
22067 +#endif
22068 +       default:
22069 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
22070 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22071 +       }
22072 +       return -ENOSYS;
22073 +}
22074 +
22075 +
22076 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
22077 +       case VCMD_ ## vcmd: perm = _perm;               \
22078 +               args = _args; flags = _flags; break
22079 +
22080 +
22081 +#define VCA_NONE       0x00
22082 +#define VCA_VXI                0x01
22083 +#define VCA_NXI                0x02
22084 +
22085 +#define VCF_NONE       0x00
22086 +#define VCF_INFO       0x01
22087 +#define VCF_ADMIN      0x02
22088 +#define VCF_ARES       0x06    /* includes admin */
22089 +#define VCF_SETUP      0x08
22090 +
22091 +#define VCF_ZIDOK      0x10    /* zero id okay */
22092 +
22093 +
22094 +static inline
22095 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22096 +{
22097 +       long ret;
22098 +       int permit = -1, state = 0;
22099 +       int perm = -1, args = 0, flags = 0;
22100 +       struct vx_info *vxi = NULL;
22101 +       struct nx_info *nxi = NULL;
22102 +
22103 +       switch (cmd) {
22104 +       /* unpriviledged commands */
22105 +       __VCMD(get_version,      0, VCA_NONE,   0);
22106 +       __VCMD(get_vci,          0, VCA_NONE,   0);
22107 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
22108 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
22109 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
22110 +       __VCMD(get_space_default,0, VCA_NONE,   0);
22111 +
22112 +       /* info commands */
22113 +       __VCMD(task_xid,         2, VCA_NONE,   0);
22114 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
22115 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
22116 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
22117 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
22118 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
22119 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
22120 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
22121 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
22122 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
22123 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
22124 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
22125 +
22126 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
22127 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
22128 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
22129 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
22130 +
22131 +       __VCMD(task_nid,         2, VCA_NONE,   0);
22132 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
22133 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
22134 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
22135 +
22136 +       __VCMD(task_tag,         2, VCA_NONE,   0);
22137 +
22138 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
22139 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
22140 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
22141 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
22142 +
22143 +       /* lower admin commands */
22144 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
22145 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
22146 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
22147 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
22148 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
22149 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
22150 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
22151 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
22152 +
22153 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
22154 +       __VCMD(net_create,       5, VCA_NONE,   0);
22155 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
22156 +
22157 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
22158 +
22159 +       /* higher admin commands */
22160 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
22161 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22162 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22163 +
22164 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22165 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22166 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22167 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22168 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22169 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22170 +
22171 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22172 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22173 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22174 +
22175 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22176 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22177 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22178 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22179 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22180 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22181 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22182 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22183 +#ifdef CONFIG_IPV6
22184 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22185 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22186 +#endif
22187 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
22188 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
22189 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
22190 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
22191 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
22192 +
22193 +#ifdef CONFIG_VSERVER_DEVICE
22194 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22195 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22196 +#endif
22197 +       /* debug level admin commands */
22198 +#ifdef CONFIG_VSERVER_HISTORY
22199 +       __VCMD(dump_history,     9, VCA_NONE,   0);
22200 +       __VCMD(read_history,     9, VCA_NONE,   0);
22201 +#endif
22202 +
22203 +       default:
22204 +               perm = -1;
22205 +       }
22206 +
22207 +       vxdprintk(VXD_CBIT(switch, 0),
22208 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
22209 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22210 +               VC_VERSION(cmd), id, data, compat,
22211 +               perm, args, flags);
22212 +
22213 +       ret = -ENOSYS;
22214 +       if (perm < 0)
22215 +               goto out;
22216 +
22217 +       state = 1;
22218 +       if (!capable(CAP_CONTEXT))
22219 +               goto out;
22220 +
22221 +       state = 2;
22222 +       /* moved here from the individual commands */
22223 +       ret = -EPERM;
22224 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
22225 +               goto out;
22226 +
22227 +       state = 3;
22228 +       /* vcmd involves resource management  */
22229 +       ret = -EPERM;
22230 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
22231 +               goto out;
22232 +
22233 +       state = 4;
22234 +       /* various legacy exceptions */
22235 +       switch (cmd) {
22236 +       /* will go away when spectator is a cap */
22237 +       case VCMD_ctx_migrate_v0:
22238 +       case VCMD_ctx_migrate:
22239 +               if (id == 1) {
22240 +                       current->xid = 1;
22241 +                       ret = 1;
22242 +                       goto out;
22243 +               }
22244 +               break;
22245 +
22246 +       /* will go away when spectator is a cap */
22247 +       case VCMD_net_migrate:
22248 +               if (id == 1) {
22249 +                       current->nid = 1;
22250 +                       ret = 1;
22251 +                       goto out;
22252 +               }
22253 +               break;
22254 +       }
22255 +
22256 +       /* vcmds are fine by default */
22257 +       permit = 1;
22258 +
22259 +       /* admin type vcmds require admin ... */
22260 +       if (flags & VCF_ADMIN)
22261 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
22262 +
22263 +       /* ... but setup type vcmds override that */
22264 +       if (!permit && (flags & VCF_SETUP))
22265 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
22266 +
22267 +       state = 5;
22268 +       ret = -EPERM;
22269 +       if (!permit)
22270 +               goto out;
22271 +
22272 +       state = 6;
22273 +       if (!id && (flags & VCF_ZIDOK))
22274 +               goto skip_id;
22275 +
22276 +       ret = -ESRCH;
22277 +       if (args & VCA_VXI) {
22278 +               vxi = lookup_vx_info(id);
22279 +               if (!vxi)
22280 +                       goto out;
22281 +
22282 +               if ((flags & VCF_ADMIN) &&
22283 +                       /* special case kill for shutdown */
22284 +                       (cmd != VCMD_ctx_kill) &&
22285 +                       /* can context be administrated? */
22286 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
22287 +                       ret = -EACCES;
22288 +                       goto out_vxi;
22289 +               }
22290 +       }
22291 +       state = 7;
22292 +       if (args & VCA_NXI) {
22293 +               nxi = lookup_nx_info(id);
22294 +               if (!nxi)
22295 +                       goto out_vxi;
22296 +
22297 +               if ((flags & VCF_ADMIN) &&
22298 +                       /* can context be administrated? */
22299 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
22300 +                       ret = -EACCES;
22301 +                       goto out_nxi;
22302 +               }
22303 +       }
22304 +skip_id:
22305 +       state = 8;
22306 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
22307 +
22308 +out_nxi:
22309 +       if ((args & VCA_NXI) && nxi)
22310 +               put_nx_info(nxi);
22311 +out_vxi:
22312 +       if ((args & VCA_VXI) && vxi)
22313 +               put_vx_info(vxi);
22314 +out:
22315 +       vxdprintk(VXD_CBIT(switch, 1),
22316 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
22317 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22318 +               VC_VERSION(cmd), ret, ret, state, permit);
22319 +       return ret;
22320 +}
22321 +
22322 +asmlinkage long
22323 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
22324 +{
22325 +       return do_vserver(cmd, id, data, 0);
22326 +}
22327 +
22328 +#ifdef CONFIG_COMPAT
22329 +
22330 +asmlinkage long
22331 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
22332 +{
22333 +       return do_vserver(cmd, id, data, 1);
22334 +}
22335 +
22336 +#endif /* CONFIG_COMPAT */
22337 diff -NurpP --minimal linux-4.4.115/kernel/vserver/sysctl.c linux-4.4.115-vs2.3.9.7/kernel/vserver/sysctl.c
22338 --- linux-4.4.115/kernel/vserver/sysctl.c       1970-01-01 00:00:00.000000000 +0000
22339 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/sysctl.c     2018-01-09 16:36:34.000000000 +0000
22340 @@ -0,0 +1,247 @@
22341 +/*
22342 + *  kernel/vserver/sysctl.c
22343 + *
22344 + *  Virtual Context Support
22345 + *
22346 + *  Copyright (C) 2004-2007  Herbert Pötzl
22347 + *
22348 + *  V0.01  basic structure
22349 + *
22350 + */
22351 +
22352 +#include <linux/module.h>
22353 +#include <linux/ctype.h>
22354 +#include <linux/sysctl.h>
22355 +#include <linux/parser.h>
22356 +#include <asm/uaccess.h>
22357 +
22358 +enum {
22359 +       CTL_DEBUG_ERROR         = 0,
22360 +       CTL_DEBUG_SWITCH        = 1,
22361 +       CTL_DEBUG_XID,
22362 +       CTL_DEBUG_NID,
22363 +       CTL_DEBUG_TAG,
22364 +       CTL_DEBUG_NET,
22365 +       CTL_DEBUG_LIMIT,
22366 +       CTL_DEBUG_CRES,
22367 +       CTL_DEBUG_DLIM,
22368 +       CTL_DEBUG_QUOTA,
22369 +       CTL_DEBUG_CVIRT,
22370 +       CTL_DEBUG_SPACE,
22371 +       CTL_DEBUG_PERM,
22372 +       CTL_DEBUG_MISC,
22373 +};
22374 +
22375 +
22376 +unsigned int vs_debug_switch   = 0;
22377 +unsigned int vs_debug_xid      = 0;
22378 +unsigned int vs_debug_nid      = 0;
22379 +unsigned int vs_debug_tag      = 0;
22380 +unsigned int vs_debug_net      = 0;
22381 +unsigned int vs_debug_limit    = 0;
22382 +unsigned int vs_debug_cres     = 0;
22383 +unsigned int vs_debug_dlim     = 0;
22384 +unsigned int vs_debug_quota    = 0;
22385 +unsigned int vs_debug_cvirt    = 0;
22386 +unsigned int vs_debug_space    = 0;
22387 +unsigned int vs_debug_perm     = 0;
22388 +unsigned int vs_debug_misc     = 0;
22389 +
22390 +
22391 +static struct ctl_table_header *vserver_table_header;
22392 +static struct ctl_table vserver_root_table[];
22393 +
22394 +
22395 +void vserver_register_sysctl(void)
22396 +{
22397 +       if (!vserver_table_header) {
22398 +               vserver_table_header = register_sysctl_table(vserver_root_table);
22399 +       }
22400 +
22401 +}
22402 +
22403 +void vserver_unregister_sysctl(void)
22404 +{
22405 +       if (vserver_table_header) {
22406 +               unregister_sysctl_table(vserver_table_header);
22407 +               vserver_table_header = NULL;
22408 +       }
22409 +}
22410 +
22411 +
22412 +static int proc_dodebug(struct ctl_table *table, int write,
22413 +       void __user *buffer, size_t *lenp, loff_t *ppos)
22414 +{
22415 +       char            tmpbuf[20], *p, c;
22416 +       unsigned int    value;
22417 +       size_t          left, len;
22418 +
22419 +       if ((*ppos && !write) || !*lenp) {
22420 +               *lenp = 0;
22421 +               return 0;
22422 +       }
22423 +
22424 +       left = *lenp;
22425 +
22426 +       if (write) {
22427 +               if (!access_ok(VERIFY_READ, buffer, left))
22428 +                       return -EFAULT;
22429 +               p = (char *)buffer;
22430 +               while (left && __get_user(c, p) >= 0 && isspace(c))
22431 +                       left--, p++;
22432 +               if (!left)
22433 +                       goto done;
22434 +
22435 +               if (left > sizeof(tmpbuf) - 1)
22436 +                       return -EINVAL;
22437 +               if (copy_from_user(tmpbuf, p, left))
22438 +                       return -EFAULT;
22439 +               tmpbuf[left] = '\0';
22440 +
22441 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
22442 +                       value = 10 * value + (*p - '0');
22443 +               if (*p && !isspace(*p))
22444 +                       return -EINVAL;
22445 +               while (left && isspace(*p))
22446 +                       left--, p++;
22447 +               *(unsigned int *)table->data = value;
22448 +       } else {
22449 +               if (!access_ok(VERIFY_WRITE, buffer, left))
22450 +                       return -EFAULT;
22451 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
22452 +               if (len > left)
22453 +                       len = left;
22454 +               if (__copy_to_user(buffer, tmpbuf, len))
22455 +                       return -EFAULT;
22456 +               if ((left -= len) > 0) {
22457 +                       if (put_user('\n', (char *)buffer + len))
22458 +                               return -EFAULT;
22459 +                       left--;
22460 +               }
22461 +       }
22462 +
22463 +done:
22464 +       *lenp -= left;
22465 +       *ppos += *lenp;
22466 +       return 0;
22467 +}
22468 +
22469 +static int zero;
22470 +
22471 +#define        CTL_ENTRY(ctl, name)                            \
22472 +       {                                               \
22473 +               .procname       = #name,                \
22474 +               .data           = &vs_ ## name,         \
22475 +               .maxlen         = sizeof(int),          \
22476 +               .mode           = 0644,                 \
22477 +               .proc_handler   = &proc_dodebug,        \
22478 +               .extra1         = &zero,                \
22479 +               .extra2         = &zero,                \
22480 +       }
22481 +
22482 +static struct ctl_table vserver_debug_table[] = {
22483 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
22484 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
22485 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
22486 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
22487 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
22488 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
22489 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
22490 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
22491 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
22492 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
22493 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
22494 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
22495 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
22496 +       { 0 }
22497 +};
22498 +
22499 +static struct ctl_table vserver_root_table[] = {
22500 +       {
22501 +               .procname       = "vserver",
22502 +               .mode           = 0555,
22503 +               .child          = vserver_debug_table
22504 +       },
22505 +       { 0 }
22506 +};
22507 +
22508 +
22509 +static match_table_t tokens = {
22510 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
22511 +       { CTL_DEBUG_XID,        "xid=%x"        },
22512 +       { CTL_DEBUG_NID,        "nid=%x"        },
22513 +       { CTL_DEBUG_TAG,        "tag=%x"        },
22514 +       { CTL_DEBUG_NET,        "net=%x"        },
22515 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
22516 +       { CTL_DEBUG_CRES,       "cres=%x"       },
22517 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
22518 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
22519 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
22520 +       { CTL_DEBUG_SPACE,      "space=%x"      },
22521 +       { CTL_DEBUG_PERM,       "perm=%x"       },
22522 +       { CTL_DEBUG_MISC,       "misc=%x"       },
22523 +       { CTL_DEBUG_ERROR,      NULL            }
22524 +};
22525 +
22526 +#define        HANDLE_CASE(id, name, val)                              \
22527 +       case CTL_DEBUG_ ## id:                                  \
22528 +               vs_debug_ ## name = val;                        \
22529 +               printk("vs_debug_" #name "=0x%x\n", val);       \
22530 +               break
22531 +
22532 +
22533 +static int __init vs_debug_setup(char *str)
22534 +{
22535 +       char *p;
22536 +       int token;
22537 +
22538 +       printk("vs_debug_setup(%s)\n", str);
22539 +       while ((p = strsep(&str, ",")) != NULL) {
22540 +               substring_t args[MAX_OPT_ARGS];
22541 +               unsigned int value;
22542 +
22543 +               if (!*p)
22544 +                       continue;
22545 +
22546 +               token = match_token(p, tokens, args);
22547 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
22548 +
22549 +               switch (token) {
22550 +               HANDLE_CASE(SWITCH, switch, value);
22551 +               HANDLE_CASE(XID,    xid,    value);
22552 +               HANDLE_CASE(NID,    nid,    value);
22553 +               HANDLE_CASE(TAG,    tag,    value);
22554 +               HANDLE_CASE(NET,    net,    value);
22555 +               HANDLE_CASE(LIMIT,  limit,  value);
22556 +               HANDLE_CASE(CRES,   cres,   value);
22557 +               HANDLE_CASE(DLIM,   dlim,   value);
22558 +               HANDLE_CASE(QUOTA,  quota,  value);
22559 +               HANDLE_CASE(CVIRT,  cvirt,  value);
22560 +               HANDLE_CASE(SPACE,  space,  value);
22561 +               HANDLE_CASE(PERM,   perm,   value);
22562 +               HANDLE_CASE(MISC,   misc,   value);
22563 +               default:
22564 +                       return -EINVAL;
22565 +                       break;
22566 +               }
22567 +       }
22568 +       return 1;
22569 +}
22570 +
22571 +__setup("vsdebug=", vs_debug_setup);
22572 +
22573 +
22574 +
22575 +EXPORT_SYMBOL_GPL(vs_debug_switch);
22576 +EXPORT_SYMBOL_GPL(vs_debug_xid);
22577 +EXPORT_SYMBOL_GPL(vs_debug_nid);
22578 +EXPORT_SYMBOL_GPL(vs_debug_net);
22579 +EXPORT_SYMBOL_GPL(vs_debug_limit);
22580 +EXPORT_SYMBOL_GPL(vs_debug_cres);
22581 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
22582 +EXPORT_SYMBOL_GPL(vs_debug_quota);
22583 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
22584 +EXPORT_SYMBOL_GPL(vs_debug_space);
22585 +EXPORT_SYMBOL_GPL(vs_debug_perm);
22586 +EXPORT_SYMBOL_GPL(vs_debug_misc);
22587 +
22588 diff -NurpP --minimal linux-4.4.115/kernel/vserver/tag.c linux-4.4.115-vs2.3.9.7/kernel/vserver/tag.c
22589 --- linux-4.4.115/kernel/vserver/tag.c  1970-01-01 00:00:00.000000000 +0000
22590 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/tag.c        2018-01-09 16:36:34.000000000 +0000
22591 @@ -0,0 +1,63 @@
22592 +/*
22593 + *  linux/kernel/vserver/tag.c
22594 + *
22595 + *  Virtual Server: Shallow Tag Space
22596 + *
22597 + *  Copyright (C) 2007  Herbert Pötzl
22598 + *
22599 + *  V0.01  basic implementation
22600 + *
22601 + */
22602 +
22603 +#include <linux/sched.h>
22604 +#include <linux/vserver/debug.h>
22605 +#include <linux/vs_pid.h>
22606 +#include <linux/vs_tag.h>
22607 +
22608 +#include <linux/vserver/tag_cmd.h>
22609 +
22610 +
22611 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
22612 +{
22613 +       if (!p)
22614 +               BUG();
22615 +
22616 +       vxdprintk(VXD_CBIT(tag, 5),
22617 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
22618 +
22619 +       task_lock(p);
22620 +       p->tag = tag;
22621 +       task_unlock(p);
22622 +
22623 +       vxdprintk(VXD_CBIT(tag, 5),
22624 +               "moved task %p into [#%d]", p, tag);
22625 +       return 0;
22626 +}
22627 +
22628 +/* vserver syscall commands below here */
22629 +
22630 +/* taks xid and vx_info functions */
22631 +
22632 +
22633 +int vc_task_tag(uint32_t id)
22634 +{
22635 +       vtag_t tag;
22636 +
22637 +       if (id) {
22638 +               struct task_struct *tsk;
22639 +               rcu_read_lock();
22640 +               tsk = find_task_by_real_pid(id);
22641 +               tag = (tsk) ? tsk->tag : -ESRCH;
22642 +               rcu_read_unlock();
22643 +       } else
22644 +               tag = dx_current_tag();
22645 +       return tag;
22646 +}
22647 +
22648 +
22649 +int vc_tag_migrate(uint32_t tag)
22650 +{
22651 +       return dx_migrate_task(current, tag & 0xFFFF);
22652 +}
22653 +
22654 +
22655 diff -NurpP --minimal linux-4.4.115/kernel/vserver/vci_config.h linux-4.4.115-vs2.3.9.7/kernel/vserver/vci_config.h
22656 --- linux-4.4.115/kernel/vserver/vci_config.h   1970-01-01 00:00:00.000000000 +0000
22657 +++ linux-4.4.115-vs2.3.9.7/kernel/vserver/vci_config.h 2018-01-09 16:36:34.000000000 +0000
22658 @@ -0,0 +1,80 @@
22659 +
22660 +/*  interface version */
22661 +
22662 +#define VCI_VERSION            0x00020308
22663 +
22664 +
22665 +enum {
22666 +       VCI_KCBIT_NO_DYNAMIC = 0,
22667 +
22668 +       VCI_KCBIT_PROC_SECURE = 4,
22669 +       /* VCI_KCBIT_HARDCPU = 5, */
22670 +       /* VCI_KCBIT_IDLELIMIT = 6, */
22671 +       /* VCI_KCBIT_IDLETIME = 7, */
22672 +
22673 +       VCI_KCBIT_COWBL = 8,
22674 +       VCI_KCBIT_FULLCOWBL = 9,
22675 +       VCI_KCBIT_SPACES = 10,
22676 +       VCI_KCBIT_NETV2 = 11,
22677 +       VCI_KCBIT_MEMCG = 12,
22678 +       VCI_KCBIT_MEMCG_SWAP = 13,
22679 +
22680 +       VCI_KCBIT_DEBUG = 16,
22681 +       VCI_KCBIT_HISTORY = 20,
22682 +       VCI_KCBIT_TAGGED = 24,
22683 +       VCI_KCBIT_PPTAG = 28,
22684 +
22685 +       VCI_KCBIT_MORE = 31,
22686 +};
22687 +
22688 +
22689 +static inline uint32_t vci_kernel_config(void)
22690 +{
22691 +       return
22692 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
22693 +
22694 +       /* configured features */
22695 +#ifdef CONFIG_VSERVER_PROC_SECURE
22696 +       (1 << VCI_KCBIT_PROC_SECURE) |
22697 +#endif
22698 +#ifdef CONFIG_VSERVER_COWBL
22699 +       (1 << VCI_KCBIT_COWBL) |
22700 +       (1 << VCI_KCBIT_FULLCOWBL) |
22701 +#endif
22702 +       (1 << VCI_KCBIT_SPACES) |
22703 +       (1 << VCI_KCBIT_NETV2) |
22704 +#ifdef CONFIG_MEMCG
22705 +       (1 << VCI_KCBIT_MEMCG) |
22706 +#endif
22707 +#ifdef CONFIG_MEMCG_SWAP
22708 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
22709 +#endif
22710 +
22711 +       /* debug options */
22712 +#ifdef CONFIG_VSERVER_DEBUG
22713 +       (1 << VCI_KCBIT_DEBUG) |
22714 +#endif
22715 +#ifdef CONFIG_VSERVER_HISTORY
22716 +       (1 << VCI_KCBIT_HISTORY) |
22717 +#endif
22718 +
22719 +       /* inode context tagging */
22720 +#if    defined(CONFIG_TAGGING_NONE)
22721 +       (0 << VCI_KCBIT_TAGGED) |
22722 +#elif  defined(CONFIG_TAGGING_UID16)
22723 +       (1 << VCI_KCBIT_TAGGED) |
22724 +#elif  defined(CONFIG_TAGGING_GID16)
22725 +       (2 << VCI_KCBIT_TAGGED) |
22726 +#elif  defined(CONFIG_TAGGING_ID24)
22727 +       (3 << VCI_KCBIT_TAGGED) |
22728 +#elif  defined(CONFIG_TAGGING_INTERN)
22729 +       (4 << VCI_KCBIT_TAGGED) |
22730 +#elif  defined(CONFIG_TAGGING_RUNTIME)
22731 +       (5 << VCI_KCBIT_TAGGED) |
22732 +#else
22733 +       (7 << VCI_KCBIT_TAGGED) |
22734 +#endif
22735 +       (1 << VCI_KCBIT_PPTAG) |
22736 +       0;
22737 +}
22738 +
22739 diff -NurpP --minimal linux-4.4.115/mm/memcontrol.c linux-4.4.115-vs2.3.9.7/mm/memcontrol.c
22740 --- linux-4.4.115/mm/memcontrol.c       2018-02-10 14:38:59.000000000 +0000
22741 +++ linux-4.4.115-vs2.3.9.7/mm/memcontrol.c     2018-02-10 15:16:50.000000000 +0000
22742 @@ -2888,6 +2888,42 @@ static u64 mem_cgroup_read_u64(struct cg
22743         }
22744  }
22745  
22746 +unsigned long mem_cgroup_mem_usage_pages(struct mem_cgroup *memcg)
22747 +{
22748 +       return mem_cgroup_usage(memcg, false);
22749 +}
22750 +
22751 +unsigned long mem_cgroup_mem_limit_pages(struct mem_cgroup *memcg)
22752 +{
22753 +       return (u64)memcg->memory.limit;
22754 +}
22755 +
22756 +unsigned long mem_cgroup_memsw_usage_pages(struct mem_cgroup *memcg)
22757 +{
22758 +       return mem_cgroup_usage(memcg, true);
22759 +}
22760 +
22761 +unsigned long mem_cgroup_memsw_limit_pages(struct mem_cgroup *memcg)
22762 +{
22763 +       return (u64)memcg->memsw.limit;
22764 +}
22765 +
22766 +void dump_mem_cgroup(struct mem_cgroup *memcg)
22767 +{
22768 +       printk(KERN_INFO "memcg: %p/%d:\n"
22769 +               "\tmemory:\t%lu/%lu %lu/%lu\n"
22770 +               "\tmemsw:\t%lu/%lu %lu/%lu\n"
22771 +               "\tkmem:\t%lu/%lu %lu/%lu\n",
22772 +               memcg, memcg->id.id,
22773 +               page_counter_read(&memcg->memory), memcg->memory.limit,
22774 +               memcg->memory.watermark, memcg->memory.failcnt,
22775 +               page_counter_read(&memcg->memsw), memcg->memsw.limit,
22776 +               memcg->memsw.watermark, memcg->memsw.failcnt,
22777 +               page_counter_read(&memcg->kmem), memcg->kmem.limit,
22778 +               memcg->kmem.watermark, memcg->kmem.failcnt);
22779 +}
22780 +
22781 +
22782  #ifdef CONFIG_MEMCG_KMEM
22783  static int memcg_activate_kmem(struct mem_cgroup *memcg,
22784                                unsigned long nr_pages)
22785 diff -NurpP --minimal linux-4.4.115/mm/oom_kill.c linux-4.4.115-vs2.3.9.7/mm/oom_kill.c
22786 --- linux-4.4.115/mm/oom_kill.c 2016-07-05 04:15:13.000000000 +0000
22787 +++ linux-4.4.115-vs2.3.9.7/mm/oom_kill.c       2018-01-09 16:56:23.000000000 +0000
22788 @@ -35,6 +35,8 @@
22789  #include <linux/freezer.h>
22790  #include <linux/ftrace.h>
22791  #include <linux/ratelimit.h>
22792 +#include <linux/reboot.h>
22793 +#include <linux/vs_context.h>
22794  
22795  #define CREATE_TRACE_POINTS
22796  #include <trace/events/oom.h>
22797 @@ -131,11 +133,18 @@ static inline bool is_sysrq_oom(struct o
22798  static bool oom_unkillable_task(struct task_struct *p,
22799                 struct mem_cgroup *memcg, const nodemask_t *nodemask)
22800  {
22801 -       if (is_global_init(p))
22802 +       unsigned xid = vx_current_xid();
22803 +
22804 +       /* skip the init task, global and per guest */
22805 +       if (task_is_init(p))
22806                 return true;
22807         if (p->flags & PF_KTHREAD)
22808                 return true;
22809  
22810 +       /* skip other guest and host processes if oom in guest */
22811 +       if (xid && vx_task_xid(p) != xid)
22812 +               return true;
22813 +
22814         /* When mem_cgroup_out_of_memory() and p is not member of the group */
22815         if (memcg && !task_in_mem_cgroup(p, memcg))
22816                 return true;
22817 @@ -534,8 +543,8 @@ void oom_kill_process(struct oom_control
22818         if (__ratelimit(&oom_rs))
22819                 dump_header(oc, p, memcg);
22820  
22821 -       pr_err("%s: Kill process %d (%s) score %u or sacrifice child\n",
22822 -               message, task_pid_nr(p), p->comm, points);
22823 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
22824 +               message, task_pid_nr(p), p->xid, p->comm, points);
22825  
22826         /*
22827          * If any of p's children has a different mm and is eligible for kill,
22828 @@ -585,8 +594,8 @@ void oom_kill_process(struct oom_control
22829          */
22830         do_send_sig_info(SIGKILL, SEND_SIG_FORCED, victim, true);
22831         mark_oom_victim(victim);
22832 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
22833 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
22834 +       pr_err("Killed process %d:%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
22835 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
22836                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
22837                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
22838         task_unlock(victim);
22839 @@ -622,6 +631,8 @@ void oom_kill_process(struct oom_control
22840  }
22841  #undef K
22842  
22843 +long vs_oom_action(unsigned int);
22844 +
22845  /*
22846   * Determines whether the kernel must panic because of the panic_on_oom sysctl.
22847   */
22848 @@ -722,7 +733,12 @@ bool out_of_memory(struct oom_control *o
22849         /* Found nothing?!?! Either we hang forever, or we panic. */
22850         if (!p && !is_sysrq_oom(oc)) {
22851                 dump_header(oc, NULL, NULL);
22852 -               panic("Out of memory and no killable processes...\n");
22853 +
22854 +               /* avoid panic for guest OOM */
22855 +               if (vx_current_xid())
22856 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
22857 +               else
22858 +                       panic("Out of memory and no killable processes...\n");
22859         }
22860         if (p && p != (void *)-1UL) {
22861                 oom_kill_process(oc, p, points, totalpages, NULL,
22862 diff -NurpP --minimal linux-4.4.115/mm/page_alloc.c linux-4.4.115-vs2.3.9.7/mm/page_alloc.c
22863 --- linux-4.4.115/mm/page_alloc.c       2018-02-10 14:38:59.000000000 +0000
22864 +++ linux-4.4.115-vs2.3.9.7/mm/page_alloc.c     2018-02-10 15:16:50.000000000 +0000
22865 @@ -62,6 +62,8 @@
22866  #include <linux/sched/rt.h>
22867  #include <linux/page_owner.h>
22868  #include <linux/kthread.h>
22869 +#include <linux/vs_base.h>
22870 +#include <linux/vs_limit.h>
22871  
22872  #include <asm/sections.h>
22873  #include <asm/tlbflush.h>
22874 @@ -3661,6 +3663,9 @@ void si_meminfo(struct sysinfo *val)
22875         val->totalhigh = totalhigh_pages;
22876         val->freehigh = nr_free_highpages();
22877         val->mem_unit = PAGE_SIZE;
22878 +
22879 +       if (vx_flags(VXF_VIRT_MEM, 0))
22880 +               vx_vsi_meminfo(val);
22881  }
22882  
22883  EXPORT_SYMBOL(si_meminfo);
22884 @@ -3686,6 +3691,9 @@ void si_meminfo_node(struct sysinfo *val
22885         val->freehigh = 0;
22886  #endif
22887         val->mem_unit = PAGE_SIZE;
22888 +
22889 +       if (vx_flags(VXF_VIRT_MEM, 0))
22890 +               vx_vsi_meminfo(val);
22891  }
22892  #endif
22893  
22894 diff -NurpP --minimal linux-4.4.115/mm/pgtable-generic.c linux-4.4.115-vs2.3.9.7/mm/pgtable-generic.c
22895 --- linux-4.4.115/mm/pgtable-generic.c  2018-02-10 14:38:59.000000000 +0000
22896 +++ linux-4.4.115-vs2.3.9.7/mm/pgtable-generic.c        2018-01-09 16:36:34.000000000 +0000
22897 @@ -6,6 +6,8 @@
22898   *  Copyright (C) 2010  Linus Torvalds
22899   */
22900  
22901 +#include <linux/mm.h>
22902 +
22903  #include <linux/pagemap.h>
22904  #include <asm/tlb.h>
22905  #include <asm-generic/pgtable.h>
22906 diff -NurpP --minimal linux-4.4.115/mm/shmem.c linux-4.4.115-vs2.3.9.7/mm/shmem.c
22907 --- linux-4.4.115/mm/shmem.c    2018-02-10 14:38:59.000000000 +0000
22908 +++ linux-4.4.115-vs2.3.9.7/mm/shmem.c  2018-01-09 16:36:34.000000000 +0000
22909 @@ -2198,7 +2198,7 @@ static int shmem_statfs(struct dentry *d
22910  {
22911         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
22912  
22913 -       buf->f_type = TMPFS_MAGIC;
22914 +       buf->f_type = TMPFS_SUPER_MAGIC;
22915         buf->f_bsize = PAGE_CACHE_SIZE;
22916         buf->f_namelen = NAME_MAX;
22917         if (sbinfo->max_blocks) {
22918 @@ -3044,7 +3044,7 @@ int shmem_fill_super(struct super_block
22919         sb->s_maxbytes = MAX_LFS_FILESIZE;
22920         sb->s_blocksize = PAGE_CACHE_SIZE;
22921         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
22922 -       sb->s_magic = TMPFS_MAGIC;
22923 +       sb->s_magic = TMPFS_SUPER_MAGIC;
22924         sb->s_op = &shmem_ops;
22925         sb->s_time_gran = 1;
22926  #ifdef CONFIG_TMPFS_XATTR
22927 diff -NurpP --minimal linux-4.4.115/mm/slab.c linux-4.4.115-vs2.3.9.7/mm/slab.c
22928 --- linux-4.4.115/mm/slab.c     2016-07-05 04:15:13.000000000 +0000
22929 +++ linux-4.4.115-vs2.3.9.7/mm/slab.c   2018-01-09 16:36:34.000000000 +0000
22930 @@ -337,6 +337,8 @@ static void kmem_cache_node_init(struct
22931  #define STATS_INC_FREEMISS(x)  do { } while (0)
22932  #endif
22933  
22934 +#include "slab_vs.h"
22935 +
22936  #if DEBUG
22937  
22938  /*
22939 @@ -3183,6 +3185,7 @@ slab_alloc_node(struct kmem_cache *cache
22940         /* ___cache_alloc_node can fall back to other nodes */
22941         ptr = ____cache_alloc_node(cachep, flags, nodeid);
22942    out:
22943 +       vx_slab_alloc(cachep, flags);
22944         local_irq_restore(save_flags);
22945         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
22946         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
22947 @@ -3371,6 +3374,7 @@ static inline void __cache_free(struct k
22948         check_irq_off();
22949         kmemleak_free_recursive(objp, cachep->flags);
22950         objp = cache_free_debugcheck(cachep, objp, caller);
22951 +       vx_slab_free(cachep);
22952  
22953         kmemcheck_slab_free(cachep, objp, cachep->object_size);
22954  
22955 diff -NurpP --minimal linux-4.4.115/mm/slab_vs.h linux-4.4.115-vs2.3.9.7/mm/slab_vs.h
22956 --- linux-4.4.115/mm/slab_vs.h  1970-01-01 00:00:00.000000000 +0000
22957 +++ linux-4.4.115-vs2.3.9.7/mm/slab_vs.h        2018-01-09 16:36:34.000000000 +0000
22958 @@ -0,0 +1,29 @@
22959 +
22960 +#include <linux/vserver/context.h>
22961 +
22962 +#include <linux/vs_context.h>
22963 +
22964 +static inline
22965 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
22966 +{
22967 +       int what = gfp_zone(cachep->allocflags);
22968 +       struct vx_info *vxi = current_vx_info();
22969 +
22970 +       if (!vxi)
22971 +               return;
22972 +
22973 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
22974 +}
22975 +
22976 +static inline
22977 +void vx_slab_free(struct kmem_cache *cachep)
22978 +{
22979 +       int what = gfp_zone(cachep->allocflags);
22980 +       struct vx_info *vxi = current_vx_info();
22981 +
22982 +       if (!vxi)
22983 +               return;
22984 +
22985 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
22986 +}
22987 +
22988 diff -NurpP --minimal linux-4.4.115/mm/swapfile.c linux-4.4.115-vs2.3.9.7/mm/swapfile.c
22989 --- linux-4.4.115/mm/swapfile.c 2018-02-10 14:38:59.000000000 +0000
22990 +++ linux-4.4.115-vs2.3.9.7/mm/swapfile.c       2018-01-09 16:36:34.000000000 +0000
22991 @@ -39,6 +39,7 @@
22992  #include <asm/tlbflush.h>
22993  #include <linux/swapops.h>
22994  #include <linux/swap_cgroup.h>
22995 +#include <linux/vs_base.h>
22996  
22997  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
22998                                  unsigned char);
22999 @@ -2070,6 +2071,16 @@ static int swap_show(struct seq_file *sw
23000  
23001         if (si == SEQ_START_TOKEN) {
23002                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23003 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23004 +                       struct sysinfo si = { 0 };
23005 +
23006 +                       vx_vsi_swapinfo(&si);
23007 +                       if (si.totalswap < (1 << 10))
23008 +                               return 0;
23009 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23010 +                               "hdv0", "partition", si.totalswap >> 10,
23011 +                               (si.totalswap - si.freeswap) >> 10, -1);
23012 +               }
23013                 return 0;
23014         }
23015  
23016 @@ -2609,6 +2620,8 @@ void si_swapinfo(struct sysinfo *val)
23017         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23018         val->totalswap = total_swap_pages + nr_to_be_unused;
23019         spin_unlock(&swap_lock);
23020 +       if (vx_flags(VXF_VIRT_MEM, 0))
23021 +               vx_vsi_swapinfo(val);
23022  }
23023  
23024  /*
23025 diff -NurpP --minimal linux-4.4.115/net/bridge/br_multicast.c linux-4.4.115-vs2.3.9.7/net/bridge/br_multicast.c
23026 --- linux-4.4.115/net/bridge/br_multicast.c     2018-02-10 14:39:02.000000000 +0000
23027 +++ linux-4.4.115-vs2.3.9.7/net/bridge/br_multicast.c   2018-01-09 16:36:34.000000000 +0000
23028 @@ -462,7 +462,7 @@ static struct sk_buff *br_ip6_multicast_
23029         ip6h->hop_limit = 1;
23030         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23031         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23032 -                              &ip6h->saddr)) {
23033 +                              &ip6h->saddr, NULL)) {
23034                 kfree_skb(skb);
23035                 br->has_ipv6_addr = 0;
23036                 return NULL;
23037 diff -NurpP --minimal linux-4.4.115/net/core/dev.c linux-4.4.115-vs2.3.9.7/net/core/dev.c
23038 --- linux-4.4.115/net/core/dev.c        2018-02-10 14:39:02.000000000 +0000
23039 +++ linux-4.4.115-vs2.3.9.7/net/core/dev.c      2018-02-10 15:16:50.000000000 +0000
23040 @@ -124,6 +124,7 @@
23041  #include <linux/in.h>
23042  #include <linux/jhash.h>
23043  #include <linux/random.h>
23044 +#include <linux/vs_inet.h>
23045  #include <trace/events/napi.h>
23046  #include <trace/events/net.h>
23047  #include <trace/events/skb.h>
23048 @@ -726,7 +727,8 @@ struct net_device *__dev_get_by_name(str
23049         struct hlist_head *head = dev_name_hash(net, name);
23050  
23051         hlist_for_each_entry(dev, head, name_hlist)
23052 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23053 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23054 +                   nx_dev_visible(current_nx_info(), dev))
23055                         return dev;
23056  
23057         return NULL;
23058 @@ -751,7 +753,8 @@ struct net_device *dev_get_by_name_rcu(s
23059         struct hlist_head *head = dev_name_hash(net, name);
23060  
23061         hlist_for_each_entry_rcu(dev, head, name_hlist)
23062 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23063 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23064 +                   nx_dev_visible(current_nx_info(), dev))
23065                         return dev;
23066  
23067         return NULL;
23068 @@ -801,7 +804,8 @@ struct net_device *__dev_get_by_index(st
23069         struct hlist_head *head = dev_index_hash(net, ifindex);
23070  
23071         hlist_for_each_entry(dev, head, index_hlist)
23072 -               if (dev->ifindex == ifindex)
23073 +               if ((dev->ifindex == ifindex) &&
23074 +                   nx_dev_visible(current_nx_info(), dev))
23075                         return dev;
23076  
23077         return NULL;
23078 @@ -819,7 +823,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
23079   *     about locking. The caller must hold RCU lock.
23080   */
23081  
23082 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23083 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
23084  {
23085         struct net_device *dev;
23086         struct hlist_head *head = dev_index_hash(net, ifindex);
23087 @@ -830,6 +834,16 @@ struct net_device *dev_get_by_index_rcu(
23088  
23089         return NULL;
23090  }
23091 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23092 +
23093 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23094 +{
23095 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23096 +
23097 +       if (nx_dev_visible(current_nx_info(), dev))
23098 +               return dev;
23099 +       return NULL;
23100 +}
23101  EXPORT_SYMBOL(dev_get_by_index_rcu);
23102  
23103  
23104 @@ -912,7 +926,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23105  
23106         for_each_netdev_rcu(net, dev)
23107                 if (dev->type == type &&
23108 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
23109 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23110 +                   nx_dev_visible(current_nx_info(), dev))
23111                         return dev;
23112  
23113         return NULL;
23114 @@ -924,9 +939,11 @@ struct net_device *__dev_getfirstbyhwtyp
23115         struct net_device *dev;
23116  
23117         ASSERT_RTNL();
23118 -       for_each_netdev(net, dev)
23119 -               if (dev->type == type)
23120 +       for_each_netdev(net, dev) {
23121 +               if ((dev->type == type) &&
23122 +                   nx_dev_visible(current_nx_info(), dev))
23123                         return dev;
23124 +       }
23125  
23126         return NULL;
23127  }
23128 @@ -938,7 +955,8 @@ struct net_device *dev_getfirstbyhwtype(
23129  
23130         rcu_read_lock();
23131         for_each_netdev_rcu(net, dev)
23132 -               if (dev->type == type) {
23133 +               if ((dev->type == type) &&
23134 +                   nx_dev_visible(current_nx_info(), dev)) {
23135                         dev_hold(dev);
23136                         ret = dev;
23137                         break;
23138 @@ -968,7 +986,8 @@ struct net_device *__dev_get_by_flags(st
23139  
23140         ret = NULL;
23141         for_each_netdev(net, dev) {
23142 -               if (((dev->flags ^ if_flags) & mask) == 0) {
23143 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
23144 +                       nx_dev_visible(current_nx_info(), dev)) {
23145                         ret = dev;
23146                         break;
23147                 }
23148 @@ -1046,6 +1065,8 @@ static int __dev_alloc_name(struct net *
23149                                 continue;
23150                         if (i < 0 || i >= max_netdevices)
23151                                 continue;
23152 +                       if (!nx_dev_visible(current_nx_info(), d))
23153 +                               continue;
23154  
23155                         /*  avoid cases where sscanf is not exact inverse of printf */
23156                         snprintf(buf, IFNAMSIZ, name, i);
23157 diff -NurpP --minimal linux-4.4.115/net/core/net-procfs.c linux-4.4.115-vs2.3.9.7/net/core/net-procfs.c
23158 --- linux-4.4.115/net/core/net-procfs.c 2015-04-12 22:12:50.000000000 +0000
23159 +++ linux-4.4.115-vs2.3.9.7/net/core/net-procfs.c       2018-01-09 16:36:34.000000000 +0000
23160 @@ -1,6 +1,7 @@
23161  #include <linux/netdevice.h>
23162  #include <linux/proc_fs.h>
23163  #include <linux/seq_file.h>
23164 +#include <linux/vs_inet.h>
23165  #include <net/wext.h>
23166  
23167  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
23168 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
23169  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
23170  {
23171         struct rtnl_link_stats64 temp;
23172 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23173 +       const struct rtnl_link_stats64 *stats;
23174 +
23175 +       /* device visible inside network context? */
23176 +       if (!nx_dev_visible(current_nx_info(), dev))
23177 +               return;
23178  
23179 +       stats = dev_get_stats(dev, &temp);
23180         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23181                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23182                    dev->name, stats->rx_bytes, stats->rx_packets,
23183 diff -NurpP --minimal linux-4.4.115/net/core/rtnetlink.c linux-4.4.115-vs2.3.9.7/net/core/rtnetlink.c
23184 --- linux-4.4.115/net/core/rtnetlink.c  2018-02-10 14:39:03.000000000 +0000
23185 +++ linux-4.4.115-vs2.3.9.7/net/core/rtnetlink.c        2018-01-09 16:36:34.000000000 +0000
23186 @@ -1456,6 +1456,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23187                 hlist_for_each_entry(dev, head, index_hlist) {
23188                         if (idx < s_idx)
23189                                 goto cont;
23190 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23191 +                               continue;
23192                         err = rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23193                                                NETLINK_CB(cb->skb).portid,
23194                                                cb->nlh->nlmsg_seq, 0,
23195 @@ -2559,6 +2561,9 @@ void rtmsg_ifinfo(int type, struct net_d
23196  {
23197         struct sk_buff *skb;
23198  
23199 +       if (!nx_dev_visible(current_nx_info(), dev))
23200 +               return;
23201 +
23202         if (dev->reg_state != NETREG_REGISTERED)
23203                 return;
23204  
23205 diff -NurpP --minimal linux-4.4.115/net/core/sock.c linux-4.4.115-vs2.3.9.7/net/core/sock.c
23206 --- linux-4.4.115/net/core/sock.c       2018-02-10 14:39:03.000000000 +0000
23207 +++ linux-4.4.115-vs2.3.9.7/net/core/sock.c     2018-01-09 17:15:58.000000000 +0000
23208 @@ -134,6 +134,10 @@
23209  #include <linux/sock_diag.h>
23210  
23211  #include <linux/filter.h>
23212 +#include <linux/vs_socket.h>
23213 +#include <linux/vs_limit.h>
23214 +#include <linux/vs_context.h>
23215 +#include <linux/vs_network.h>
23216  
23217  #include <trace/events/sock.h>
23218  
23219 @@ -1363,6 +1367,8 @@ static struct sock *sk_prot_alloc(struct
23220                         goto out_free_sec;
23221                 sk_tx_queue_clear(sk);
23222         }
23223 +               sock_vx_init(sk);
23224 +               sock_nx_init(sk);
23225  
23226         return sk;
23227  
23228 @@ -1469,6 +1475,11 @@ void sk_destruct(struct sock *sk)
23229         put_pid(sk->sk_peer_pid);
23230         if (likely(sk->sk_net_refcnt))
23231                 put_net(sock_net(sk));
23232 +       vx_sock_dec(sk);
23233 +       clr_vx_info(&sk->sk_vx_info);
23234 +       sk->sk_xid = -1;
23235 +       clr_nx_info(&sk->sk_nx_info);
23236 +       sk->sk_nid = -1;
23237         sk_prot_free(sk->sk_prot_creator, sk);
23238  }
23239  
23240 @@ -1521,6 +1532,8 @@ struct sock *sk_clone_lock(const struct
23241                 /* SANITY */
23242                 if (likely(newsk->sk_net_refcnt))
23243                         get_net(sock_net(newsk));
23244 +               sock_vx_init(newsk);
23245 +               sock_nx_init(newsk);
23246                 sk_node_init(&newsk->sk_node);
23247                 sock_lock_init(newsk);
23248                 bh_lock_sock(newsk);
23249 @@ -1586,6 +1599,12 @@ struct sock *sk_clone_lock(const struct
23250                 smp_wmb();
23251                 atomic_set(&newsk->sk_refcnt, 2);
23252  
23253 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
23254 +               newsk->sk_xid = sk->sk_xid;
23255 +               vx_sock_inc(newsk);
23256 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
23257 +               newsk->sk_nid = sk->sk_nid;
23258 +
23259                 /*
23260                  * Increment the counter in the same struct proto as the master
23261                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
23262 @@ -2424,6 +2443,12 @@ void sock_init_data(struct socket *sock,
23263  
23264         sk->sk_stamp = ktime_set(-1L, 0);
23265  
23266 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
23267 +       sk->sk_xid = vx_current_xid();
23268 +       vx_sock_inc(sk);
23269 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
23270 +       sk->sk_nid = nx_current_nid();
23271 +
23272  #ifdef CONFIG_NET_RX_BUSY_POLL
23273         sk->sk_napi_id          =       0;
23274         sk->sk_ll_usec          =       sysctl_net_busy_read;
23275 diff -NurpP --minimal linux-4.4.115/net/ipv4/af_inet.c linux-4.4.115-vs2.3.9.7/net/ipv4/af_inet.c
23276 --- linux-4.4.115/net/ipv4/af_inet.c    2018-02-10 14:39:03.000000000 +0000
23277 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/af_inet.c  2018-01-09 17:11:11.000000000 +0000
23278 @@ -308,10 +308,15 @@ lookup_protocol:
23279         }
23280  
23281         err = -EPERM;
23282 +       if ((protocol == IPPROTO_ICMP) &&
23283 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
23284 +               goto override;
23285 +
23286         if (sock->type == SOCK_RAW && !kern &&
23287             !ns_capable(net->user_ns, CAP_NET_RAW))
23288                 goto out_rcu_unlock;
23289  
23290 +override:
23291         sock->ops = answer->ops;
23292         answer_prot = answer->prot;
23293         answer_flags = answer->flags;
23294 @@ -425,6 +430,7 @@ int inet_bind(struct socket *sock, struc
23295         struct sock *sk = sock->sk;
23296         struct inet_sock *inet = inet_sk(sk);
23297         struct net *net = sock_net(sk);
23298 +       struct nx_v4_sock_addr nsa;
23299         unsigned short snum;
23300         int chk_addr_ret;
23301         u32 tb_id = RT_TABLE_LOCAL;
23302 @@ -450,7 +456,11 @@ int inet_bind(struct socket *sock, struc
23303         }
23304  
23305         tb_id = l3mdev_fib_table_by_index(net, sk->sk_bound_dev_if) ? : tb_id;
23306 -       chk_addr_ret = inet_addr_type_table(net, addr->sin_addr.s_addr, tb_id);
23307 +       err = v4_map_sock_addr(inet, addr, &nsa);
23308 +       if (err)
23309 +               goto out;
23310 +
23311 +       chk_addr_ret = inet_addr_type_table(net, nsa.saddr, tb_id);
23312  
23313         /* Not specified by any standard per-se, however it breaks too
23314          * many applications when removed.  It is unfortunate since
23315 @@ -462,7 +472,7 @@ int inet_bind(struct socket *sock, struc
23316         err = -EADDRNOTAVAIL;
23317         if (!net->ipv4.sysctl_ip_nonlocal_bind &&
23318             !(inet->freebind || inet->transparent) &&
23319 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
23320 +           nsa.saddr != htonl(INADDR_ANY) &&
23321             chk_addr_ret != RTN_LOCAL &&
23322             chk_addr_ret != RTN_MULTICAST &&
23323             chk_addr_ret != RTN_BROADCAST)
23324 @@ -488,7 +498,7 @@ int inet_bind(struct socket *sock, struc
23325         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
23326                 goto out_release_sock;
23327  
23328 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23329 +       v4_set_sock_addr(inet, &nsa);
23330         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23331                 inet->inet_saddr = 0;  /* Use device */
23332  
23333 @@ -708,11 +718,13 @@ int inet_getname(struct socket *sock, st
23334                      peer == 1))
23335                         return -ENOTCONN;
23336                 sin->sin_port = inet->inet_dport;
23337 -               sin->sin_addr.s_addr = inet->inet_daddr;
23338 +               sin->sin_addr.s_addr =
23339 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
23340         } else {
23341                 __be32 addr = inet->inet_rcv_saddr;
23342                 if (!addr)
23343                         addr = inet->inet_saddr;
23344 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
23345                 sin->sin_port = inet->inet_sport;
23346                 sin->sin_addr.s_addr = addr;
23347         }
23348 @@ -896,6 +908,7 @@ static int inet_compat_ioctl(struct sock
23349         return err;
23350  }
23351  #endif
23352 +#include <linux/vs_limit.h>
23353  
23354  const struct proto_ops inet_stream_ops = {
23355         .family            = PF_INET,
23356 diff -NurpP --minimal linux-4.4.115/net/ipv4/arp.c linux-4.4.115-vs2.3.9.7/net/ipv4/arp.c
23357 --- linux-4.4.115/net/ipv4/arp.c        2018-02-10 14:39:03.000000000 +0000
23358 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/arp.c      2018-02-10 15:16:50.000000000 +0000
23359 @@ -1295,6 +1295,7 @@ static void arp_format_neigh_entry(struc
23360         struct net_device *dev = n->dev;
23361         int hatype = dev->type;
23362  
23363 +       /* FIXME: check for network context */
23364         read_lock(&n->lock);
23365         /* Convert hardware address to XX:XX:XX:XX ... form. */
23366  #if IS_ENABLED(CONFIG_AX25)
23367 @@ -1326,6 +1327,7 @@ static void arp_format_pneigh_entry(stru
23368         int hatype = dev ? dev->type : 0;
23369         char tbuf[16];
23370  
23371 +       /* FIXME: check for network context */
23372         sprintf(tbuf, "%pI4", n->key);
23373         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
23374                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
23375 diff -NurpP --minimal linux-4.4.115/net/ipv4/devinet.c linux-4.4.115-vs2.3.9.7/net/ipv4/devinet.c
23376 --- linux-4.4.115/net/ipv4/devinet.c    2018-02-10 14:39:03.000000000 +0000
23377 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/devinet.c  2018-01-09 16:36:34.000000000 +0000
23378 @@ -538,6 +538,7 @@ struct in_device *inetdev_by_index(struc
23379  }
23380  EXPORT_SYMBOL(inetdev_by_index);
23381  
23382 +
23383  /* Called only from RTNL semaphored context. No locks. */
23384  
23385  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
23386 @@ -992,6 +993,8 @@ int devinet_ioctl(struct net *net, unsig
23387  
23388         in_dev = __in_dev_get_rtnl(dev);
23389         if (in_dev) {
23390 +               struct nx_info *nxi = current_nx_info();
23391 +
23392                 if (tryaddrmatch) {
23393                         /* Matthias Andree */
23394                         /* compare label and address (4.4BSD style) */
23395 @@ -1000,6 +1003,8 @@ int devinet_ioctl(struct net *net, unsig
23396                            This is checked above. */
23397                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23398                              ifap = &ifa->ifa_next) {
23399 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23400 +                                       continue;
23401                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
23402                                     sin_orig.sin_addr.s_addr ==
23403                                                         ifa->ifa_local) {
23404 @@ -1012,9 +1017,12 @@ int devinet_ioctl(struct net *net, unsig
23405                    comparing just the label */
23406                 if (!ifa) {
23407                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23408 -                            ifap = &ifa->ifa_next)
23409 +                            ifap = &ifa->ifa_next) {
23410 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23411 +                                       continue;
23412                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
23413                                         break;
23414 +                       }
23415                 }
23416         }
23417  
23418 @@ -1168,6 +1176,8 @@ static int inet_gifconf(struct net_devic
23419                 goto out;
23420  
23421         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
23422 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
23423 +                       continue;
23424                 if (!buf) {
23425                         done += sizeof(ifr);
23426                         continue;
23427 @@ -1573,6 +1583,7 @@ static int inet_dump_ifaddr(struct sk_bu
23428         struct net_device *dev;
23429         struct in_device *in_dev;
23430         struct in_ifaddr *ifa;
23431 +       struct sock *sk = skb->sk;
23432         struct hlist_head *head;
23433  
23434         s_h = cb->args[0];
23435 @@ -1596,6 +1607,8 @@ static int inet_dump_ifaddr(struct sk_bu
23436  
23437                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
23438                              ifa = ifa->ifa_next, ip_idx++) {
23439 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
23440 +                               continue;
23441                                 if (ip_idx < s_ip_idx)
23442                                         continue;
23443                                 if (inet_fill_ifaddr(skb, ifa,
23444 diff -NurpP --minimal linux-4.4.115/net/ipv4/fib_trie.c linux-4.4.115-vs2.3.9.7/net/ipv4/fib_trie.c
23445 --- linux-4.4.115/net/ipv4/fib_trie.c   2018-02-10 14:39:03.000000000 +0000
23446 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/fib_trie.c 2018-01-09 16:36:34.000000000 +0000
23447 @@ -2591,6 +2591,7 @@ static int fib_route_seq_show(struct seq
23448  
23449                 seq_setwidth(seq, 127);
23450  
23451 +               /* FIXME: check for network context? */
23452                 if (fi)
23453                         seq_printf(seq,
23454                                    "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
23455 diff -NurpP --minimal linux-4.4.115/net/ipv4/inet_connection_sock.c linux-4.4.115-vs2.3.9.7/net/ipv4/inet_connection_sock.c
23456 --- linux-4.4.115/net/ipv4/inet_connection_sock.c       2018-02-10 14:39:03.000000000 +0000
23457 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/inet_connection_sock.c     2018-01-09 16:36:34.000000000 +0000
23458 @@ -43,6 +43,37 @@ void inet_get_local_port_range(struct ne
23459  }
23460  EXPORT_SYMBOL(inet_get_local_port_range);
23461  
23462 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23463 +{
23464 +       __be32  sk1_rcv_saddr = sk1->sk_rcv_saddr,
23465 +               sk2_rcv_saddr = sk2->sk_rcv_saddr;
23466 +
23467 +       if (inet_v6_ipv6only(sk2))
23468 +               return 0;
23469 +
23470 +       if (sk1_rcv_saddr &&
23471 +           sk2_rcv_saddr &&
23472 +           sk1_rcv_saddr == sk2_rcv_saddr)
23473 +               return 1;
23474 +
23475 +       if (sk1_rcv_saddr &&
23476 +           !sk2_rcv_saddr &&
23477 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
23478 +               return 1;
23479 +
23480 +       if (sk2_rcv_saddr &&
23481 +           !sk1_rcv_saddr &&
23482 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
23483 +               return 1;
23484 +
23485 +       if (!sk1_rcv_saddr &&
23486 +           !sk2_rcv_saddr &&
23487 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
23488 +               return 1;
23489 +
23490 +       return 0;
23491 +}
23492 +
23493  int inet_csk_bind_conflict(const struct sock *sk,
23494                            const struct inet_bind_bucket *tb, bool relax)
23495  {
23496 @@ -70,15 +101,13 @@ int inet_csk_bind_conflict(const struct
23497                             (sk2->sk_state != TCP_TIME_WAIT &&
23498                              !uid_eq(uid, sock_i_uid(sk2))))) {
23499  
23500 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23501 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23502 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23503                                         break;
23504                         }
23505                         if (!relax && reuse && sk2->sk_reuse &&
23506                             sk2->sk_state != TCP_LISTEN) {
23507  
23508 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23509 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23510 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23511                                         break;
23512                         }
23513                 }
23514 diff -NurpP --minimal linux-4.4.115/net/ipv4/inet_diag.c linux-4.4.115-vs2.3.9.7/net/ipv4/inet_diag.c
23515 --- linux-4.4.115/net/ipv4/inet_diag.c  2016-07-05 04:15:14.000000000 +0000
23516 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/inet_diag.c        2018-01-09 16:36:34.000000000 +0000
23517 @@ -31,6 +31,8 @@
23518  
23519  #include <linux/inet.h>
23520  #include <linux/stddef.h>
23521 +#include <linux/vs_network.h>
23522 +#include <linux/vs_inet.h>
23523  
23524  #include <linux/inet_diag.h>
23525  #include <linux/sock_diag.h>
23526 @@ -761,6 +763,8 @@ void inet_diag_dump_icsk(struct inet_has
23527                                 if (!net_eq(sock_net(sk), net))
23528                                         continue;
23529  
23530 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23531 +                                       continue;
23532                                 if (num < s_num) {
23533                                         num++;
23534                                         continue;
23535 @@ -822,6 +826,8 @@ skip_listen_ht:
23536  
23537                         if (!net_eq(sock_net(sk), net))
23538                                 continue;
23539 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23540 +                               continue;
23541                         if (num < s_num)
23542                                 goto next_normal;
23543                         state = (sk->sk_state == TCP_TIME_WAIT) ?
23544 diff -NurpP --minimal linux-4.4.115/net/ipv4/inet_hashtables.c linux-4.4.115-vs2.3.9.7/net/ipv4/inet_hashtables.c
23545 --- linux-4.4.115/net/ipv4/inet_hashtables.c    2016-07-05 04:15:14.000000000 +0000
23546 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/inet_hashtables.c  2018-01-09 16:36:34.000000000 +0000
23547 @@ -23,6 +23,7 @@
23548  #include <net/inet_connection_sock.h>
23549  #include <net/inet_hashtables.h>
23550  #include <net/secure_seq.h>
23551 +#include <net/route.h>
23552  #include <net/ip.h>
23553  
23554  static u32 inet_ehashfn(const struct net *net, const __be32 laddr,
23555 @@ -183,6 +184,11 @@ static inline int compute_score(struct s
23556                         if (rcv_saddr != daddr)
23557                                 return -1;
23558                         score += 4;
23559 +               } else {
23560 +                       /* block non nx_info ips */
23561 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
23562 +                               daddr, NXA_MASK_BIND))
23563 +                               return -1;
23564                 }
23565                 if (sk->sk_bound_dev_if) {
23566                         if (sk->sk_bound_dev_if != dif)
23567 @@ -202,7 +208,6 @@ static inline int compute_score(struct s
23568   * wildcarded during the search since they can never be otherwise.
23569   */
23570  
23571 -
23572  struct sock *__inet_lookup_listener(struct net *net,
23573                                     struct inet_hashinfo *hashinfo,
23574                                     const __be32 saddr, __be16 sport,
23575 @@ -238,6 +243,7 @@ begin:
23576                         phash = next_pseudo_random32(phash);
23577                 }
23578         }
23579 +
23580         /*
23581          * if the nulls value we got at the end of this lookup is
23582          * not the expected one, we must restart lookup.
23583 diff -NurpP --minimal linux-4.4.115/net/ipv4/netfilter.c linux-4.4.115-vs2.3.9.7/net/ipv4/netfilter.c
23584 --- linux-4.4.115/net/ipv4/netfilter.c  2016-07-05 04:15:14.000000000 +0000
23585 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/netfilter.c        2018-01-09 16:36:34.000000000 +0000
23586 @@ -11,7 +11,7 @@
23587  #include <linux/skbuff.h>
23588  #include <linux/gfp.h>
23589  #include <linux/export.h>
23590 -#include <net/route.h>
23591 +// #include <net/route.h>
23592  #include <net/xfrm.h>
23593  #include <net/ip.h>
23594  #include <net/netfilter/nf_queue.h>
23595 diff -NurpP --minimal linux-4.4.115/net/ipv4/raw.c linux-4.4.115-vs2.3.9.7/net/ipv4/raw.c
23596 --- linux-4.4.115/net/ipv4/raw.c        2018-02-10 14:39:03.000000000 +0000
23597 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/raw.c      2018-01-09 17:06:10.000000000 +0000
23598 @@ -126,7 +126,7 @@ static struct sock *__raw_v4_lookup(stru
23599  
23600                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
23601                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
23602 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
23603 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
23604                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23605                         goto found; /* gotcha */
23606         }
23607 @@ -416,6 +416,12 @@ static int raw_send_hdrinc(struct sock *
23608                                 skb_transport_header(skb))->type);
23609         }
23610  
23611 +       err = -EPERM;
23612 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
23613 +               sk->sk_nx_info &&
23614 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
23615 +               goto error_free;
23616 +
23617         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT,
23618                       net, sk, skb, NULL, rt->dst.dev,
23619                       dst_output);
23620 @@ -626,6 +632,16 @@ static int raw_sendmsg(struct sock *sk,
23621                         goto done;
23622         }
23623  
23624 +       if (sk->sk_nx_info) {
23625 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
23626 +               if (IS_ERR(rt)) {
23627 +                       err = PTR_ERR(rt);
23628 +                       rt = NULL;
23629 +                       goto done;
23630 +               }
23631 +               ip_rt_put(rt);
23632 +       }
23633 +
23634         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
23635         rt = ip_route_output_flow(net, &fl4, sk);
23636         if (IS_ERR(rt)) {
23637 @@ -704,17 +720,19 @@ static int raw_bind(struct sock *sk, str
23638  {
23639         struct inet_sock *inet = inet_sk(sk);
23640         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
23641 +       struct nx_v4_sock_addr nsa = { 0 };
23642         int ret = -EINVAL;
23643         int chk_addr_ret;
23644  
23645         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
23646                 goto out;
23647 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
23648 +       v4_map_sock_addr(inet, addr, &nsa);
23649 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
23650         ret = -EADDRNOTAVAIL;
23651 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
23652 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
23653             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
23654                 goto out;
23655 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23656 +       v4_set_sock_addr(inet, &nsa);
23657         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23658                 inet->inet_saddr = 0;  /* Use device */
23659         sk_dst_reset(sk);
23660 @@ -763,7 +781,8 @@ static int raw_recvmsg(struct sock *sk,
23661         /* Copy the address. */
23662         if (sin) {
23663                 sin->sin_family = AF_INET;
23664 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
23665 +               sin->sin_addr.s_addr =
23666 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
23667                 sin->sin_port = 0;
23668                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
23669                 *addr_len = sizeof(*sin);
23670 @@ -959,7 +978,8 @@ static struct sock *raw_get_first(struct
23671         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
23672                         ++state->bucket) {
23673                 sk_for_each(sk, &state->h->ht[state->bucket])
23674 -                       if (sock_net(sk) == seq_file_net(seq))
23675 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
23676 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23677                                 goto found;
23678         }
23679         sk = NULL;
23680 @@ -975,7 +995,8 @@ static struct sock *raw_get_next(struct
23681                 sk = sk_next(sk);
23682  try_again:
23683                 ;
23684 -       } while (sk && sock_net(sk) != seq_file_net(seq));
23685 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
23686 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
23687  
23688         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
23689                 sk = sk_head(&state->h->ht[state->bucket]);
23690 diff -NurpP --minimal linux-4.4.115/net/ipv4/route.c linux-4.4.115-vs2.3.9.7/net/ipv4/route.c
23691 --- linux-4.4.115/net/ipv4/route.c      2018-02-10 14:39:03.000000000 +0000
23692 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/route.c    2018-01-09 16:36:34.000000000 +0000
23693 @@ -2226,7 +2226,7 @@ struct rtable *__ip_route_output_key_has
23694  
23695  
23696         if (fl4->flowi4_oif) {
23697 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
23698 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
23699                 rth = ERR_PTR(-ENODEV);
23700                 if (!dev_out)
23701                         goto out;
23702 diff -NurpP --minimal linux-4.4.115/net/ipv4/tcp.c linux-4.4.115-vs2.3.9.7/net/ipv4/tcp.c
23703 --- linux-4.4.115/net/ipv4/tcp.c        2018-02-10 14:39:03.000000000 +0000
23704 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/tcp.c      2018-02-10 15:16:50.000000000 +0000
23705 @@ -269,6 +269,7 @@
23706  #include <linux/crypto.h>
23707  #include <linux/time.h>
23708  #include <linux/slab.h>
23709 +#include <linux/in.h>
23710  
23711  #include <net/icmp.h>
23712  #include <net/inet_common.h>
23713 diff -NurpP --minimal linux-4.4.115/net/ipv4/tcp_ipv4.c linux-4.4.115-vs2.3.9.7/net/ipv4/tcp_ipv4.c
23714 --- linux-4.4.115/net/ipv4/tcp_ipv4.c   2018-02-10 14:39:03.000000000 +0000
23715 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/tcp_ipv4.c 2018-01-09 17:13:45.000000000 +0000
23716 @@ -1885,6 +1885,10 @@ static void *listening_get_next(struct s
23717         sk = sk_nulls_next(sk);
23718  get_sk:
23719         sk_nulls_for_each_from(sk, node) {
23720 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
23721 +                       sk, sk->sk_nid, nx_current_nid());
23722 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23723 +                       continue;
23724                 if (!net_eq(sock_net(sk), net))
23725                         continue;
23726                 if (sk->sk_family == st->family) {
23727 @@ -1949,6 +1953,11 @@ static void *established_get_first(struc
23728  
23729                 spin_lock_bh(lock);
23730                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
23731 +                       vxdprintk(VXD_CBIT(net, 6),
23732 +                               "sk,egf: %p [#%d] (from %d)",
23733 +                               sk, sk->sk_nid, nx_current_nid());
23734 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23735 +                               continue;
23736                         if (sk->sk_family != st->family ||
23737                             !net_eq(sock_net(sk), net)) {
23738                                 continue;
23739 @@ -1975,6 +1984,11 @@ static void *established_get_next(struct
23740         sk = sk_nulls_next(sk);
23741  
23742         sk_nulls_for_each_from(sk, node) {
23743 +               vxdprintk(VXD_CBIT(net, 6),
23744 +                       "sk,egn: %p [#%d] (from %d)",
23745 +                       sk, sk->sk_nid, nx_current_nid());
23746 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23747 +                       continue;
23748                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
23749                         return sk;
23750         }
23751 @@ -2166,9 +2180,9 @@ static void get_openreq4(const struct re
23752         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
23753                 " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK",
23754                 i,
23755 -               ireq->ir_loc_addr,
23756 +               nx_map_sock_lback(current_nx_info(), ireq->ir_loc_addr),
23757                 ireq->ir_num,
23758 -               ireq->ir_rmt_addr,
23759 +               nx_map_sock_lback(current_nx_info(), ireq->ir_rmt_addr),
23760                 ntohs(ireq->ir_rmt_port),
23761                 TCP_SYN_RECV,
23762                 0, 0, /* could print option size, but that is af dependent. */
23763 @@ -2191,8 +2205,8 @@ static void get_tcp4_sock(struct sock *s
23764         const struct inet_connection_sock *icsk = inet_csk(sk);
23765         const struct inet_sock *inet = inet_sk(sk);
23766         const struct fastopen_queue *fastopenq = &icsk->icsk_accept_queue.fastopenq;
23767 -       __be32 dest = inet->inet_daddr;
23768 -       __be32 src = inet->inet_rcv_saddr;
23769 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
23770 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
23771         __u16 destp = ntohs(inet->inet_dport);
23772         __u16 srcp = ntohs(inet->inet_sport);
23773         int rx_queue;
23774 @@ -2251,8 +2265,8 @@ static void get_timewait4_sock(const str
23775         __be32 dest, src;
23776         __u16 destp, srcp;
23777  
23778 -       dest  = tw->tw_daddr;
23779 -       src   = tw->tw_rcv_saddr;
23780 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
23781 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
23782         destp = ntohs(tw->tw_dport);
23783         srcp  = ntohs(tw->tw_sport);
23784  
23785 diff -NurpP --minimal linux-4.4.115/net/ipv4/tcp_minisocks.c linux-4.4.115-vs2.3.9.7/net/ipv4/tcp_minisocks.c
23786 --- linux-4.4.115/net/ipv4/tcp_minisocks.c      2018-02-10 14:39:03.000000000 +0000
23787 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/tcp_minisocks.c    2018-01-09 16:36:34.000000000 +0000
23788 @@ -23,6 +23,9 @@
23789  #include <linux/slab.h>
23790  #include <linux/sysctl.h>
23791  #include <linux/workqueue.h>
23792 +#include <linux/vs_limit.h>
23793 +#include <linux/vs_socket.h>
23794 +#include <linux/vs_context.h>
23795  #include <net/tcp.h>
23796  #include <net/inet_common.h>
23797  #include <net/xfrm.h>
23798 @@ -291,6 +294,11 @@ void tcp_time_wait(struct sock *sk, int
23799                 tcptw->tw_ts_offset     = tp->tsoffset;
23800                 tcptw->tw_last_oow_ack_time = 0;
23801  
23802 +               tw->tw_xid              = sk->sk_xid;
23803 +               tw->tw_vx_info          = NULL;
23804 +               tw->tw_nid              = sk->sk_nid;
23805 +               tw->tw_nx_info          = NULL;
23806 +
23807  #if IS_ENABLED(CONFIG_IPV6)
23808                 if (tw->tw_family == PF_INET6) {
23809                         struct ipv6_pinfo *np = inet6_sk(sk);
23810 diff -NurpP --minimal linux-4.4.115/net/ipv4/udp.c linux-4.4.115-vs2.3.9.7/net/ipv4/udp.c
23811 --- linux-4.4.115/net/ipv4/udp.c        2018-02-10 14:39:03.000000000 +0000
23812 +++ linux-4.4.115-vs2.3.9.7/net/ipv4/udp.c      2018-01-09 16:36:34.000000000 +0000
23813 @@ -309,14 +309,7 @@ fail:
23814  }
23815  EXPORT_SYMBOL(udp_lib_get_port);
23816  
23817 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23818 -{
23819 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
23820 -
23821 -       return  (!ipv6_only_sock(sk2)  &&
23822 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
23823 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
23824 -}
23825 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
23826  
23827  static u32 udp4_portaddr_hash(const struct net *net, __be32 saddr,
23828                               unsigned int port)
23829 @@ -355,6 +348,11 @@ static inline int compute_score(struct s
23830                 if (inet->inet_rcv_saddr != daddr)
23831                         return -1;
23832                 score += 4;
23833 +               } else {
23834 +                       /* block non nx_info ips */
23835 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
23836 +                               daddr, NXA_MASK_BIND))
23837 +                               return -1;
23838         }
23839  
23840         if (inet->inet_daddr) {
23841 @@ -489,6 +487,7 @@ begin:
23842         return result;
23843  }
23844  
23845 +
23846  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
23847   * harder than this. -DaveM
23848   */
23849 @@ -535,6 +534,11 @@ begin:
23850         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
23851                 score = compute_score(sk, net, saddr, hnum, sport,
23852                                       daddr, dport, dif);
23853 +               /* FIXME: disabled?
23854 +               if (score == 9) {
23855 +                       result = sk;
23856 +                       break;
23857 +               } else */
23858                 if (score > badness) {
23859                         result = sk;
23860                         badness = score;
23861 @@ -559,6 +563,7 @@ begin:
23862         if (get_nulls_value(node) != slot)
23863                 goto begin;
23864  
23865 +
23866         if (result) {
23867                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
23868                         result = NULL;
23869 @@ -568,6 +573,7 @@ begin:
23870                         goto begin;
23871                 }
23872         }
23873 +
23874         rcu_read_unlock();
23875         return result;
23876  }
23877 @@ -602,7 +608,7 @@ static inline bool __udp_is_mcast_sock(s
23878             udp_sk(sk)->udp_port_hash != hnum ||
23879             (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
23880             (inet->inet_dport != rmt_port && inet->inet_dport) ||
23881 -           (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
23882 +           !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
23883             ipv6_only_sock(sk) ||
23884             (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23885                 return false;
23886 @@ -1033,6 +1039,16 @@ int udp_sendmsg(struct sock *sk, struct
23887                                 goto out;
23888                 }
23889  
23890 +               if (sk->sk_nx_info) {
23891 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
23892 +                       if (IS_ERR(rt)) {
23893 +                               err = PTR_ERR(rt);
23894 +                               rt = NULL;
23895 +                               goto out;
23896 +                       }
23897 +                       ip_rt_put(rt);
23898 +               }
23899 +
23900                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
23901                 rt = ip_route_output_flow(net, fl4, sk);
23902                 if (IS_ERR(rt)) {
23903 @@ -1337,7 +1353,8 @@ try_again:
23904         if (sin) {
23905                 sin->sin_family = AF_INET;
23906                 sin->sin_port = udp_hdr(skb)->source;
23907 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
23908 +               sin->sin_addr.s_addr = nx_map_sock_lback(
23909 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
23910                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
23911                 *addr_len = sizeof(*sin);
23912         }
23913 @@ -2319,6 +2336,8 @@ static struct sock *udp_get_first(struct
23914                 sk_nulls_for_each(sk, node, &hslot->head) {
23915                         if (!net_eq(sock_net(sk), net))
23916                                 continue;
23917 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23918 +                               continue;
23919                         if (sk->sk_family == state->family)
23920                                 goto found;
23921                 }
23922 @@ -2336,7 +2355,9 @@ static struct sock *udp_get_next(struct
23923  
23924         do {
23925                 sk = sk_nulls_next(sk);
23926 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
23927 +       } while (sk && (!net_eq(sock_net(sk), net) ||
23928 +               sk->sk_family != state->family ||
23929 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
23930  
23931         if (!sk) {
23932                 if (state->bucket <= state->udp_table->mask)
23933 @@ -2432,8 +2453,8 @@ static void udp4_format_sock(struct sock
23934                 int bucket)
23935  {
23936         struct inet_sock *inet = inet_sk(sp);
23937 -       __be32 dest = inet->inet_daddr;
23938 -       __be32 src  = inet->inet_rcv_saddr;
23939 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
23940 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
23941         __u16 destp       = ntohs(inet->inet_dport);
23942         __u16 srcp        = ntohs(inet->inet_sport);
23943  
23944 diff -NurpP --minimal linux-4.4.115/net/ipv6/addrconf.c linux-4.4.115-vs2.3.9.7/net/ipv6/addrconf.c
23945 --- linux-4.4.115/net/ipv6/addrconf.c   2018-02-10 14:39:03.000000000 +0000
23946 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/addrconf.c 2018-01-09 23:41:55.000000000 +0000
23947 @@ -92,6 +92,8 @@
23948  #include <linux/proc_fs.h>
23949  #include <linux/seq_file.h>
23950  #include <linux/export.h>
23951 +#include <linux/vs_network.h>
23952 +#include <linux/vs_inet6.h>
23953  
23954  /* Set to 3 to get tracing... */
23955  #define ACONF_DEBUG 2
23956 @@ -1442,7 +1444,8 @@ static int __ipv6_dev_get_saddr(struct n
23957                                 struct ipv6_saddr_dst *dst,
23958                                 struct inet6_dev *idev,
23959                                 struct ipv6_saddr_score *scores,
23960 -                               int hiscore_idx)
23961 +                               int hiscore_idx,
23962 +                               struct nx_info *nxi)
23963  {
23964         struct ipv6_saddr_score *score = &scores[1 - hiscore_idx], *hiscore = &scores[hiscore_idx];
23965  
23966 @@ -1472,6 +1475,8 @@ static int __ipv6_dev_get_saddr(struct n
23967                                             idev->dev->name);
23968                         continue;
23969                 }
23970 +               if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
23971 +                       continue;
23972  
23973                 score->rule = -1;
23974                 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
23975 @@ -1519,7 +1524,7 @@ out:
23976  
23977  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
23978                        const struct in6_addr *daddr, unsigned int prefs,
23979 -                      struct in6_addr *saddr)
23980 +                      struct in6_addr *saddr, struct nx_info *nxi)
23981  {
23982         struct ipv6_saddr_score scores[2], *hiscore;
23983         struct ipv6_saddr_dst dst;
23984 @@ -1568,13 +1573,15 @@ int ipv6_dev_get_saddr(struct net *net,
23985  
23986         if (use_oif_addr) {
23987                 if (idev)
23988 -                       hiscore_idx = __ipv6_dev_get_saddr(net, &dst, idev, scores, hiscore_idx);
23989 +                       hiscore_idx = __ipv6_dev_get_saddr(net, &dst,
23990 +                               idev, scores, hiscore_idx, nxi);
23991         } else {
23992                 for_each_netdev_rcu(net, dev) {
23993                         idev = __in6_dev_get(dev);
23994                         if (!idev)
23995                                 continue;
23996 -                       hiscore_idx = __ipv6_dev_get_saddr(net, &dst, idev, scores, hiscore_idx);
23997 +                       hiscore_idx = __ipv6_dev_get_saddr(net, &dst,
23998 +                               idev, scores, hiscore_idx, nxi);
23999                 }
24000         }
24001         rcu_read_unlock();
24002 @@ -3846,7 +3853,10 @@ static void if6_seq_stop(struct seq_file
24003  static int if6_seq_show(struct seq_file *seq, void *v)
24004  {
24005         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
24006 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24007 +
24008 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
24009 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
24010 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24011                    &ifp->addr,
24012                    ifp->idev->dev->ifindex,
24013                    ifp->prefix_len,
24014 @@ -4430,6 +4440,11 @@ static int in6_dump_addrs(struct inet6_d
24015         struct ifacaddr6 *ifaca;
24016         int err = 1;
24017         int ip_idx = *p_ip_idx;
24018 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24019 +
24020 +       /* disable ipv6 on non v6 guests */
24021 +       if (nxi && !nx_info_has_v6(nxi))
24022 +               return skb->len;
24023  
24024         read_lock_bh(&idev->lock);
24025         switch (type) {
24026 @@ -4440,6 +4455,8 @@ static int in6_dump_addrs(struct inet6_d
24027                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
24028                         if (++ip_idx < s_ip_idx)
24029                                 continue;
24030 +                       if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
24031 +                               continue;
24032                         err = inet6_fill_ifaddr(skb, ifa,
24033                                                 NETLINK_CB(cb->skb).portid,
24034                                                 cb->nlh->nlmsg_seq,
24035 @@ -4457,6 +4474,8 @@ static int in6_dump_addrs(struct inet6_d
24036                      ifmca = ifmca->next, ip_idx++) {
24037                         if (ip_idx < s_ip_idx)
24038                                 continue;
24039 +                       if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
24040 +                               continue;
24041                         err = inet6_fill_ifmcaddr(skb, ifmca,
24042                                                   NETLINK_CB(cb->skb).portid,
24043                                                   cb->nlh->nlmsg_seq,
24044 @@ -4472,6 +4491,8 @@ static int in6_dump_addrs(struct inet6_d
24045                      ifaca = ifaca->aca_next, ip_idx++) {
24046                         if (ip_idx < s_ip_idx)
24047                                 continue;
24048 +                       if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
24049 +                               continue;
24050                         err = inet6_fill_ifacaddr(skb, ifaca,
24051                                                   NETLINK_CB(cb->skb).portid,
24052                                                   cb->nlh->nlmsg_seq,
24053 @@ -4500,6 +4521,10 @@ static int inet6_dump_addr(struct sk_buf
24054         struct inet6_dev *idev;
24055         struct hlist_head *head;
24056  
24057 +       /* FIXME: maybe disable ipv6 on non v6 guests?
24058 +       if (skb->sk && skb->sk->sk_vx_info)
24059 +               return skb->len; */
24060 +
24061         s_h = cb->args[0];
24062         s_idx = idx = cb->args[1];
24063         s_ip_idx = ip_idx = cb->args[2];
24064 @@ -5008,6 +5033,7 @@ static int inet6_dump_ifinfo(struct sk_b
24065         struct net_device *dev;
24066         struct inet6_dev *idev;
24067         struct hlist_head *head;
24068 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24069  
24070         s_h = cb->args[0];
24071         s_idx = cb->args[1];
24072 @@ -5019,6 +5045,8 @@ static int inet6_dump_ifinfo(struct sk_b
24073                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24074                         if (idx < s_idx)
24075                                 goto cont;
24076 +                       if (!v6_dev_in_nx_info(dev, nxi))
24077 +                               goto cont;
24078                         idev = __in6_dev_get(dev);
24079                         if (!idev)
24080                                 goto cont;
24081 diff -NurpP --minimal linux-4.4.115/net/ipv6/af_inet6.c linux-4.4.115-vs2.3.9.7/net/ipv6/af_inet6.c
24082 --- linux-4.4.115/net/ipv6/af_inet6.c   2018-02-10 14:39:03.000000000 +0000
24083 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/af_inet6.c 2018-01-09 16:36:34.000000000 +0000
24084 @@ -43,6 +43,8 @@
24085  #include <linux/netdevice.h>
24086  #include <linux/icmpv6.h>
24087  #include <linux/netfilter_ipv6.h>
24088 +#include <linux/vs_inet.h>
24089 +#include <linux/vs_inet6.h>
24090  
24091  #include <net/ip.h>
24092  #include <net/ipv6.h>
24093 @@ -158,10 +160,13 @@ lookup_protocol:
24094         }
24095  
24096         err = -EPERM;
24097 +       if ((protocol == IPPROTO_ICMPV6) &&
24098 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24099 +               goto override;
24100         if (sock->type == SOCK_RAW && !kern &&
24101             !ns_capable(net->user_ns, CAP_NET_RAW))
24102                 goto out_rcu_unlock;
24103 -
24104 +override:
24105         sock->ops = answer->ops;
24106         answer_prot = answer->prot;
24107         answer_flags = answer->flags;
24108 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
24109         struct inet_sock *inet = inet_sk(sk);
24110         struct ipv6_pinfo *np = inet6_sk(sk);
24111         struct net *net = sock_net(sk);
24112 +       struct nx_v6_sock_addr nsa;
24113         __be32 v4addr = 0;
24114         unsigned short snum;
24115         int addr_type = 0;
24116 @@ -274,6 +280,10 @@ int inet6_bind(struct socket *sock, stru
24117         if (addr->sin6_family != AF_INET6)
24118                 return -EAFNOSUPPORT;
24119  
24120 +       err = v6_map_sock_addr(inet, addr, &nsa);
24121 +       if (err)
24122 +               return err;
24123 +
24124         addr_type = ipv6_addr_type(&addr->sin6_addr);
24125         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
24126                 return -EINVAL;
24127 @@ -314,6 +324,10 @@ int inet6_bind(struct socket *sock, stru
24128                         err = -EADDRNOTAVAIL;
24129                         goto out;
24130                 }
24131 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
24132 +                       err = -EADDRNOTAVAIL;
24133 +                       goto out;
24134 +               }
24135         } else {
24136                 if (addr_type != IPV6_ADDR_ANY) {
24137                         struct net_device *dev = NULL;
24138 @@ -340,6 +354,11 @@ int inet6_bind(struct socket *sock, stru
24139                                 }
24140                         }
24141  
24142 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24143 +                               err = -EADDRNOTAVAIL;
24144 +                               goto out_unlock;
24145 +                       }
24146 +
24147                         /* ipv4 addr of the socket is invalid.  Only the
24148                          * unspecified and mapped address have a v4 equivalent.
24149                          */
24150 @@ -357,6 +376,9 @@ int inet6_bind(struct socket *sock, stru
24151                 }
24152         }
24153  
24154 +       /* what's that for? */
24155 +       v6_set_sock_addr(inet, &nsa);
24156 +
24157         inet->inet_rcv_saddr = v4addr;
24158         inet->inet_saddr = v4addr;
24159  
24160 @@ -461,9 +483,11 @@ int inet6_getname(struct socket *sock, s
24161                         return -ENOTCONN;
24162                 sin->sin6_port = inet->inet_dport;
24163                 sin->sin6_addr = sk->sk_v6_daddr;
24164 +               /* FIXME: remap lback? */
24165                 if (np->sndflow)
24166                         sin->sin6_flowinfo = np->flow_label;
24167         } else {
24168 +               /* FIXME: remap lback? */
24169                 if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
24170                         sin->sin6_addr = np->saddr;
24171                 else
24172 diff -NurpP --minimal linux-4.4.115/net/ipv6/datagram.c linux-4.4.115-vs2.3.9.7/net/ipv6/datagram.c
24173 --- linux-4.4.115/net/ipv6/datagram.c   2018-02-10 14:39:03.000000000 +0000
24174 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/datagram.c 2018-01-09 16:36:34.000000000 +0000
24175 @@ -733,7 +733,7 @@ int ip6_datagram_send_ctl(struct net *ne
24176  
24177                         rcu_read_lock();
24178                         if (fl6->flowi6_oif) {
24179 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
24180 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
24181                                 if (!dev) {
24182                                         rcu_read_unlock();
24183                                         return -ENODEV;
24184 diff -NurpP --minimal linux-4.4.115/net/ipv6/fib6_rules.c linux-4.4.115-vs2.3.9.7/net/ipv6/fib6_rules.c
24185 --- linux-4.4.115/net/ipv6/fib6_rules.c 2018-02-10 14:39:03.000000000 +0000
24186 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/fib6_rules.c       2018-01-09 16:36:34.000000000 +0000
24187 @@ -97,7 +97,7 @@ static int fib6_rule_action(struct fib_r
24188                                                ip6_dst_idev(&rt->dst)->dev,
24189                                                &flp6->daddr,
24190                                                rt6_flags2srcprefs(flags),
24191 -                                              &saddr))
24192 +                                              &saddr, NULL))
24193                                 goto again;
24194                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
24195                                                r->src.plen))
24196 diff -NurpP --minimal linux-4.4.115/net/ipv6/inet6_hashtables.c linux-4.4.115-vs2.3.9.7/net/ipv6/inet6_hashtables.c
24197 --- linux-4.4.115/net/ipv6/inet6_hashtables.c   2016-07-05 04:15:14.000000000 +0000
24198 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/inet6_hashtables.c 2018-01-09 16:36:34.000000000 +0000
24199 @@ -16,6 +16,7 @@
24200  
24201  #include <linux/module.h>
24202  #include <linux/random.h>
24203 +#include <linux/vs_inet6.h>
24204  
24205  #include <net/inet_connection_sock.h>
24206  #include <net/inet_hashtables.h>
24207 @@ -66,7 +67,6 @@ struct sock *__inet6_lookup_established(
24208         unsigned int slot = hash & hashinfo->ehash_mask;
24209         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
24210  
24211 -
24212         rcu_read_lock();
24213  begin:
24214         sk_nulls_for_each_rcu(sk, node, &head->chain) {
24215 @@ -108,6 +108,9 @@ static inline int compute_score(struct s
24216                         if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24217                                 return -1;
24218                         score++;
24219 +               } else {
24220 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24221 +                               return -1;
24222                 }
24223                 if (sk->sk_bound_dev_if) {
24224                         if (sk->sk_bound_dev_if != dif)
24225 diff -NurpP --minimal linux-4.4.115/net/ipv6/ip6_fib.c linux-4.4.115-vs2.3.9.7/net/ipv6/ip6_fib.c
24226 --- linux-4.4.115/net/ipv6/ip6_fib.c    2018-02-10 14:39:03.000000000 +0000
24227 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/ip6_fib.c  2018-01-09 16:36:34.000000000 +0000
24228 @@ -1968,6 +1968,7 @@ static int ipv6_route_seq_show(struct se
24229         struct rt6_info *rt = v;
24230         struct ipv6_route_iter *iter = seq->private;
24231  
24232 +       /* FIXME: check for network context? */
24233         seq_printf(seq, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
24234  
24235  #ifdef CONFIG_IPV6_SUBTREES
24236 diff -NurpP --minimal linux-4.4.115/net/ipv6/ip6_output.c linux-4.4.115-vs2.3.9.7/net/ipv6/ip6_output.c
24237 --- linux-4.4.115/net/ipv6/ip6_output.c 2018-02-10 14:39:04.000000000 +0000
24238 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/ip6_output.c       2018-02-10 15:16:50.000000000 +0000
24239 @@ -941,7 +941,8 @@ static int ip6_dst_lookup_tail(struct ne
24240                 rt = (*dst)->error ? NULL : (struct rt6_info *)*dst;
24241                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
24242                                           sk ? inet6_sk(sk)->srcprefs : 0,
24243 -                                         &fl6->saddr);
24244 +                                         &fl6->saddr,
24245 +                                         sk ? sk->sk_nx_info : NULL);
24246                 if (err)
24247                         goto out_err_release;
24248  
24249 diff -NurpP --minimal linux-4.4.115/net/ipv6/ndisc.c linux-4.4.115-vs2.3.9.7/net/ipv6/ndisc.c
24250 --- linux-4.4.115/net/ipv6/ndisc.c      2016-07-05 04:15:14.000000000 +0000
24251 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/ndisc.c    2018-01-09 16:36:34.000000000 +0000
24252 @@ -501,7 +501,7 @@ void ndisc_send_na(struct net_device *de
24253         } else {
24254                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
24255                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
24256 -                                      &tmpaddr))
24257 +                                      &tmpaddr, NULL))
24258                         return;
24259                 src_addr = &tmpaddr;
24260         }
24261 diff -NurpP --minimal linux-4.4.115/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c linux-4.4.115-vs2.3.9.7/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c
24262 --- linux-4.4.115/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c   2016-07-05 04:15:14.000000000 +0000
24263 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c 2018-01-09 17:04:44.000000000 +0000
24264 @@ -35,7 +35,7 @@ nf_nat_masquerade_ipv6(struct sk_buff *s
24265                             ctinfo == IP_CT_RELATED_REPLY));
24266  
24267         if (ipv6_dev_get_saddr(nf_ct_net(ct), out,
24268 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
24269 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
24270                 return NF_DROP;
24271  
24272         nfct_nat(ct)->masq_index = out->ifindex;
24273 diff -NurpP --minimal linux-4.4.115/net/ipv6/raw.c linux-4.4.115-vs2.3.9.7/net/ipv6/raw.c
24274 --- linux-4.4.115/net/ipv6/raw.c        2018-02-10 14:39:04.000000000 +0000
24275 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/raw.c      2018-01-09 16:36:34.000000000 +0000
24276 @@ -30,6 +30,7 @@
24277  #include <linux/icmpv6.h>
24278  #include <linux/netfilter.h>
24279  #include <linux/netfilter_ipv6.h>
24280 +#include <linux/vs_inet6.h>
24281  #include <linux/skbuff.h>
24282  #include <linux/compat.h>
24283  #include <linux/uaccess.h>
24284 @@ -291,6 +292,13 @@ static int rawv6_bind(struct sock *sk, s
24285                                 goto out_unlock;
24286                 }
24287  
24288 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24289 +                       err = -EADDRNOTAVAIL;
24290 +                       if (dev)
24291 +                               dev_put(dev);
24292 +                       goto out;
24293 +               }
24294 +
24295                 /* ipv4 addr of the socket is invalid.  Only the
24296                  * unspecified and mapped address have a v4 equivalent.
24297                  */
24298 diff -NurpP --minimal linux-4.4.115/net/ipv6/route.c linux-4.4.115-vs2.3.9.7/net/ipv6/route.c
24299 --- linux-4.4.115/net/ipv6/route.c      2018-02-10 14:39:04.000000000 +0000
24300 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/route.c    2018-01-09 17:03:24.000000000 +0000
24301 @@ -62,6 +62,7 @@
24302  #include <net/lwtunnel.h>
24303  #include <net/ip_tunnels.h>
24304  #include <net/l3mdev.h>
24305 +#include <linux/vs_inet6.h>
24306  
24307  #include <asm/uaccess.h>
24308  
24309 @@ -2545,16 +2546,18 @@ int ip6_route_get_saddr(struct net *net,
24310                         struct rt6_info *rt,
24311                         const struct in6_addr *daddr,
24312                         unsigned int prefs,
24313 -                       struct in6_addr *saddr)
24314 +                       struct in6_addr *saddr,
24315 +                       struct nx_info *nxi)
24316  {
24317         struct inet6_dev *idev =
24318                 rt ? ip6_dst_idev((struct dst_entry *)rt) : NULL;
24319         int err = 0;
24320 -       if (rt && rt->rt6i_prefsrc.plen)
24321 +       if (rt && rt->rt6i_prefsrc.plen && (!nxi ||
24322 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
24323                 *saddr = rt->rt6i_prefsrc.addr;
24324         else
24325                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
24326 -                                        daddr, prefs, saddr);
24327 +                                        daddr, prefs, saddr, nxi);
24328         return err;
24329  }
24330  
24331 @@ -3168,7 +3171,8 @@ static int rt6_fill_node(struct net *net
24332                                 goto nla_put_failure;
24333         } else if (dst) {
24334                 struct in6_addr saddr_buf;
24335 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
24336 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
24337 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
24338                     nla_put_in6_addr(skb, RTA_PREFSRC, &saddr_buf))
24339                         goto nla_put_failure;
24340         }
24341 diff -NurpP --minimal linux-4.4.115/net/ipv6/tcp_ipv6.c linux-4.4.115-vs2.3.9.7/net/ipv6/tcp_ipv6.c
24342 --- linux-4.4.115/net/ipv6/tcp_ipv6.c   2018-02-10 14:39:04.000000000 +0000
24343 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/tcp_ipv6.c 2018-01-09 16:36:34.000000000 +0000
24344 @@ -69,6 +69,7 @@
24345  
24346  #include <linux/crypto.h>
24347  #include <linux/scatterlist.h>
24348 +#include <linux/vs_inet6.h>
24349  
24350  static void    tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb);
24351  static void    tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,
24352 @@ -150,11 +151,18 @@ static int tcp_v6_connect(struct sock *s
24353          */
24354  
24355         if (ipv6_addr_any(&usin->sin6_addr)) {
24356 -               if (ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
24357 -                       ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK),
24358 -                                              &usin->sin6_addr);
24359 -               else
24360 -                       usin->sin6_addr = in6addr_loopback;
24361 +               struct nx_info *nxi =  sk->sk_nx_info;
24362 +
24363 +               if (nxi && nx_info_has_v6(nxi))
24364 +                       /* FIXME: remap lback? */
24365 +                       usin->sin6_addr = nxi->v6.ip;
24366 +               else {
24367 +                       if (ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
24368 +                               ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK),
24369 +                                                      &usin->sin6_addr);
24370 +                       else
24371 +                               usin->sin6_addr = in6addr_loopback;
24372 +               }
24373         }
24374  
24375         addr_type = ipv6_addr_type(&usin->sin6_addr);
24376 diff -NurpP --minimal linux-4.4.115/net/ipv6/udp.c linux-4.4.115-vs2.3.9.7/net/ipv6/udp.c
24377 --- linux-4.4.115/net/ipv6/udp.c        2018-02-10 14:39:04.000000000 +0000
24378 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/udp.c      2018-01-09 16:36:34.000000000 +0000
24379 @@ -47,6 +47,7 @@
24380  #include <net/xfrm.h>
24381  #include <net/inet6_hashtables.h>
24382  #include <net/busy_poll.h>
24383 +#include <linux/vs_inet6.h>
24384  
24385  #include <linux/proc_fs.h>
24386  #include <linux/seq_file.h>
24387 @@ -76,32 +77,60 @@ static u32 udp6_ehashfn(const struct net
24388                                udp_ipv6_hash_secret + net_hash_mix(net));
24389  }
24390  
24391 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
24392 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24393  {
24394 +       const struct in6_addr *sk1_rcv_saddr6 = inet6_rcv_saddr(sk1);
24395         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
24396 +       __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr;
24397 +       __be32 sk2_rcv_saddr = sk2->sk_rcv_saddr;
24398         int sk2_ipv6only = inet_v6_ipv6only(sk2);
24399 -       int addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
24400 +       int addr_type1 = ipv6_addr_type(sk1_rcv_saddr6);
24401         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
24402  
24403         /* if both are mapped, treat as IPv4 */
24404 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
24405 -               return (!sk2_ipv6only &&
24406 -                       (!sk->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24407 -                         sk->sk_rcv_saddr == sk2->sk_rcv_saddr));
24408 +       if (addr_type1 == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
24409 +               if (!sk2_ipv6only &&
24410 +                       (!sk1->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24411 +                         sk1->sk_rcv_saddr == sk2->sk_rcv_saddr))
24412 +                       goto vs_v4;
24413 +               else
24414 +                       return 0;
24415 +       }
24416  
24417         if (addr_type2 == IPV6_ADDR_ANY &&
24418 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
24419 -               return 1;
24420 +           !(sk2_ipv6only && addr_type1 == IPV6_ADDR_MAPPED))
24421 +               goto vs;
24422  
24423 -       if (addr_type == IPV6_ADDR_ANY &&
24424 -           !(ipv6_only_sock(sk) && addr_type2 == IPV6_ADDR_MAPPED))
24425 -               return 1;
24426 +       if (addr_type1 == IPV6_ADDR_ANY &&
24427 +           !(ipv6_only_sock(sk1) && addr_type2 == IPV6_ADDR_MAPPED))
24428 +               goto vs;
24429  
24430         if (sk2_rcv_saddr6 &&
24431 -           ipv6_addr_equal(&sk->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24432 -               return 1;
24433 +           ipv6_addr_equal(&sk1->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24434 +               goto vs;
24435  
24436         return 0;
24437 +
24438 +vs_v4:
24439 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
24440 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24441 +       if (!sk2_rcv_saddr)
24442 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
24443 +       if (!sk1_rcv_saddr)
24444 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
24445 +       return 1;
24446 +vs:
24447 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type1 == IPV6_ADDR_ANY)
24448 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24449 +       else if (addr_type2 == IPV6_ADDR_ANY)
24450 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
24451 +       else if (addr_type1 == IPV6_ADDR_ANY) {
24452 +               if (addr_type2 == IPV6_ADDR_MAPPED)
24453 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24454 +               else
24455 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
24456 +       }
24457 +       return 1;
24458  }
24459  
24460  static u32 udp6_portaddr_hash(const struct net *net,
24461 @@ -162,6 +191,10 @@ static inline int compute_score(struct s
24462                 if (inet->inet_dport != sport)
24463                         return -1;
24464                 score++;
24465 +               } else {
24466 +                       /* block non nx_info ips */
24467 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24468 +                               return -1;
24469         }
24470  
24471         if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
24472 diff -NurpP --minimal linux-4.4.115/net/ipv6/xfrm6_policy.c linux-4.4.115-vs2.3.9.7/net/ipv6/xfrm6_policy.c
24473 --- linux-4.4.115/net/ipv6/xfrm6_policy.c       2016-07-05 04:15:14.000000000 +0000
24474 +++ linux-4.4.115-vs2.3.9.7/net/ipv6/xfrm6_policy.c     2018-01-09 16:36:34.000000000 +0000
24475 @@ -64,7 +64,8 @@ static int xfrm6_get_saddr(struct net *n
24476                 return -EHOSTUNREACH;
24477  
24478         dev = ip6_dst_idev(dst)->dev;
24479 -       ipv6_dev_get_saddr(dev_net(dev), dev, &daddr->in6, 0, &saddr->in6);
24480 +       ipv6_dev_get_saddr(dev_net(dev), dev, &daddr->in6,
24481 +               0, &saddr->in6, NULL);
24482         dst_release(dst);
24483         return 0;
24484  }
24485 diff -NurpP --minimal linux-4.4.115/net/netfilter/ipvs/ip_vs_xmit.c linux-4.4.115-vs2.3.9.7/net/netfilter/ipvs/ip_vs_xmit.c
24486 --- linux-4.4.115/net/netfilter/ipvs/ip_vs_xmit.c       2016-07-05 04:15:15.000000000 +0000
24487 +++ linux-4.4.115-vs2.3.9.7/net/netfilter/ipvs/ip_vs_xmit.c     2018-01-09 16:36:34.000000000 +0000
24488 @@ -381,7 +381,7 @@ __ip_vs_route_output_v6(struct net *net,
24489                 return dst;
24490         if (ipv6_addr_any(&fl6.saddr) &&
24491             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
24492 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
24493 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
24494                 goto out_err;
24495         if (do_xfrm) {
24496                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
24497 diff -NurpP --minimal linux-4.4.115/net/netlink/af_netlink.c linux-4.4.115-vs2.3.9.7/net/netlink/af_netlink.c
24498 --- linux-4.4.115/net/netlink/af_netlink.c      2018-02-10 14:39:04.000000000 +0000
24499 +++ linux-4.4.115-vs2.3.9.7/net/netlink/af_netlink.c    2018-01-09 16:36:34.000000000 +0000
24500 @@ -62,6 +62,8 @@
24501  #include <asm/cacheflush.h>
24502  #include <linux/hash.h>
24503  #include <linux/genetlink.h>
24504 +#include <linux/vs_context.h>
24505 +#include <linux/vs_network.h>
24506  
24507  #include <net/net_namespace.h>
24508  #include <net/sock.h>
24509 @@ -2460,7 +2462,8 @@ static void *__netlink_seq_next(struct s
24510                         if (err)
24511                                 return ERR_PTR(err);
24512                 }
24513 -       } while (sock_net(&nlk->sk) != seq_file_net(seq));
24514 +       } while ((sock_net(&nlk->sk) != seq_file_net(seq)) ||
24515 +               !nx_check(nlk->sk.sk_nid, VS_WATCH_P | VS_IDENT));
24516  
24517         return nlk;
24518  }
24519 diff -NurpP --minimal linux-4.4.115/net/socket.c linux-4.4.115-vs2.3.9.7/net/socket.c
24520 --- linux-4.4.115/net/socket.c  2018-02-10 14:39:05.000000000 +0000
24521 +++ linux-4.4.115-vs2.3.9.7/net/socket.c        2018-02-10 15:16:50.000000000 +0000
24522 @@ -99,10 +99,12 @@
24523  
24524  #include <net/sock.h>
24525  #include <linux/netfilter.h>
24526 +#include <linux/vs_socket.h>
24527 +#include <linux/vs_inet.h>
24528 +#include <linux/vs_inet6.h>
24529  
24530  #include <linux/if_tun.h>
24531  #include <linux/ipv6_route.h>
24532 -#include <linux/route.h>
24533  #include <linux/sockios.h>
24534  #include <linux/atalk.h>
24535  #include <net/busy_poll.h>
24536 @@ -608,8 +610,24 @@ EXPORT_SYMBOL(__sock_tx_timestamp);
24537  
24538  static inline int sock_sendmsg_nosec(struct socket *sock, struct msghdr *msg)
24539  {
24540 -       int ret = sock->ops->sendmsg(sock, msg, msg_data_left(msg));
24541 -       BUG_ON(ret == -EIOCBQUEUED);
24542 +       size_t size = msg_data_left(msg);
24543 +       int ret = sock->ops->sendmsg(sock, msg, size);
24544 +#if 0
24545 +       if (sock->sk) {
24546 +               if (!ret)
24547 +                       vx_sock_fail(sock->sk, size);
24548 +               else
24549 +                       vx_sock_send(sock->sk, size);
24550 +       }
24551 +#endif
24552 +       vxdprintk(VXD_CBIT(net, 7),
24553 +               "sock_sendmsg_nosec: %p[%p,%p,%p;%d/%d]:%zu/%zu",
24554 +               sock, sock->sk,
24555 +               (sock->sk)?sock->sk->sk_nx_info:0,
24556 +               (sock->sk)?sock->sk->sk_vx_info:0,
24557 +               (sock->sk)?sock->sk->sk_xid:0,
24558 +               (sock->sk)?sock->sk->sk_nid:0,
24559 +               size, msg_data_left(msg));
24560         return ret;
24561  }
24562  
24563 @@ -1100,6 +1118,13 @@ int __sock_create(struct net *net, int f
24564         if (type < 0 || type >= SOCK_MAX)
24565                 return -EINVAL;
24566  
24567 +       if (!nx_check(0, VS_ADMIN)) {
24568 +               if (family == PF_INET && !current_nx_info_has_v4())
24569 +                       return -EAFNOSUPPORT;
24570 +               if (family == PF_INET6 && !current_nx_info_has_v6())
24571 +                       return -EAFNOSUPPORT;
24572 +       }
24573 +
24574         /* Compatibility.
24575  
24576            This uglymoron is moved from INET layer to here to avoid
24577 @@ -1234,6 +1259,7 @@ SYSCALL_DEFINE3(socket, int, family, int
24578         if (retval < 0)
24579                 goto out;
24580  
24581 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
24582         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
24583         if (retval < 0)
24584                 goto out_release;
24585 @@ -1275,10 +1301,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
24586         err = sock_create(family, type, protocol, &sock1);
24587         if (err < 0)
24588                 goto out;
24589 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
24590  
24591         err = sock_create(family, type, protocol, &sock2);
24592         if (err < 0)
24593                 goto out_release_1;
24594 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
24595  
24596         err = sock1->ops->socketpair(sock1, sock2);
24597         if (err < 0)
24598 diff -NurpP --minimal linux-4.4.115/net/sunrpc/auth.c linux-4.4.115-vs2.3.9.7/net/sunrpc/auth.c
24599 --- linux-4.4.115/net/sunrpc/auth.c     2015-10-29 09:21:46.000000000 +0000
24600 +++ linux-4.4.115-vs2.3.9.7/net/sunrpc/auth.c   2018-01-09 16:36:34.000000000 +0000
24601 @@ -15,6 +15,7 @@
24602  #include <linux/sunrpc/clnt.h>
24603  #include <linux/sunrpc/gss_api.h>
24604  #include <linux/spinlock.h>
24605 +#include <linux/vs_tag.h>
24606  
24607  #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
24608  # define RPCDBG_FACILITY       RPCDBG_AUTH
24609 @@ -630,6 +631,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
24610         memset(&acred, 0, sizeof(acred));
24611         acred.uid = cred->fsuid;
24612         acred.gid = cred->fsgid;
24613 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
24614         acred.group_info = cred->group_info;
24615         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
24616         return ret;
24617 @@ -669,6 +671,7 @@ rpcauth_bind_root_cred(struct rpc_task *
24618         struct auth_cred acred = {
24619                 .uid = GLOBAL_ROOT_UID,
24620                 .gid = GLOBAL_ROOT_GID,
24621 +               .tag = KTAGT_INIT(dx_current_tag()),
24622         };
24623  
24624         dprintk("RPC: %5u looking up %s cred\n",
24625 diff -NurpP --minimal linux-4.4.115/net/sunrpc/auth_unix.c linux-4.4.115-vs2.3.9.7/net/sunrpc/auth_unix.c
24626 --- linux-4.4.115/net/sunrpc/auth_unix.c        2016-07-05 04:12:45.000000000 +0000
24627 +++ linux-4.4.115-vs2.3.9.7/net/sunrpc/auth_unix.c      2018-01-09 16:36:34.000000000 +0000
24628 @@ -13,11 +13,13 @@
24629  #include <linux/sunrpc/clnt.h>
24630  #include <linux/sunrpc/auth.h>
24631  #include <linux/user_namespace.h>
24632 +#include <linux/vs_tag.h>
24633  
24634  #define NFS_NGROUPS    16
24635  
24636  struct unx_cred {
24637         struct rpc_cred         uc_base;
24638 +       ktag_t                  uc_tag;
24639         kgid_t                  uc_gid;
24640         kgid_t                  uc_gids[NFS_NGROUPS];
24641  };
24642 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
24643                 groups = NFS_NGROUPS;
24644  
24645         cred->uc_gid = acred->gid;
24646 +       cred->uc_tag = acred->tag;
24647         for (i = 0; i < groups; i++)
24648                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
24649         if (i < NFS_NGROUPS)
24650 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
24651         unsigned int i;
24652  
24653  
24654 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
24655 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
24656 +           !gid_eq(cred->uc_gid, acred->gid) ||
24657 +           !tag_eq(cred->uc_tag, acred->tag))
24658                 return 0;
24659  
24660         if (acred->group_info != NULL)
24661 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
24662         struct rpc_clnt *clnt = task->tk_client;
24663         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
24664         __be32          *base, *hold;
24665 -       int             i;
24666 +       int             i, tag;
24667  
24668         *p++ = htonl(RPC_AUTH_UNIX);
24669         base = p++;
24670 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
24671          */
24672         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
24673  
24674 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
24675 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
24676 +       tag = task->tk_client->cl_tag;
24677 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
24678 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
24679 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
24680 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
24681         hold = p++;
24682         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
24683                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
24684 diff -NurpP --minimal linux-4.4.115/net/sunrpc/clnt.c linux-4.4.115-vs2.3.9.7/net/sunrpc/clnt.c
24685 --- linux-4.4.115/net/sunrpc/clnt.c     2018-02-10 14:39:05.000000000 +0000
24686 +++ linux-4.4.115-vs2.3.9.7/net/sunrpc/clnt.c   2018-01-09 16:36:34.000000000 +0000
24687 @@ -31,6 +31,7 @@
24688  #include <linux/in.h>
24689  #include <linux/in6.h>
24690  #include <linux/un.h>
24691 +#include <linux/vs_cvirt.h>
24692  
24693  #include <linux/sunrpc/clnt.h>
24694  #include <linux/sunrpc/addr.h>
24695 @@ -477,6 +478,9 @@ static struct rpc_clnt *rpc_create_xprt(
24696         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
24697                 clnt->cl_chatty = 1;
24698  
24699 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
24700 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
24701 +               clnt->cl_tag = 1; */
24702         return clnt;
24703  }
24704  
24705 diff -NurpP --minimal linux-4.4.115/net/unix/af_unix.c linux-4.4.115-vs2.3.9.7/net/unix/af_unix.c
24706 --- linux-4.4.115/net/unix/af_unix.c    2018-02-10 14:39:06.000000000 +0000
24707 +++ linux-4.4.115-vs2.3.9.7/net/unix/af_unix.c  2018-01-09 16:36:34.000000000 +0000
24708 @@ -117,6 +117,8 @@
24709  #include <net/checksum.h>
24710  #include <linux/security.h>
24711  #include <linux/freezer.h>
24712 +#include <linux/vs_context.h>
24713 +#include <linux/vs_limit.h>
24714  
24715  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
24716  EXPORT_SYMBOL_GPL(unix_socket_table);
24717 @@ -282,6 +284,8 @@ static struct sock *__unix_find_socket_b
24718                 if (!net_eq(sock_net(s), net))
24719                         continue;
24720  
24721 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
24722 +                       continue;
24723                 if (u->addr->len == len &&
24724                     !memcmp(u->addr->name, sunname, len))
24725                         goto found;
24726 @@ -2741,6 +2745,8 @@ static struct sock *unix_from_bucket(str
24727         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
24728                 if (sock_net(sk) != seq_file_net(seq))
24729                         continue;
24730 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24731 +                       continue;
24732                 if (++count == offset)
24733                         break;
24734         }
24735 @@ -2758,6 +2764,8 @@ static struct sock *unix_next_socket(str
24736                 sk = sk_next(sk);
24737                 if (!sk)
24738                         goto next_bucket;
24739 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24740 +                       continue;
24741                 if (sock_net(sk) == seq_file_net(seq))
24742                         return sk;
24743         }
24744 diff -NurpP --minimal linux-4.4.115/scripts/checksyscalls.sh linux-4.4.115-vs2.3.9.7/scripts/checksyscalls.sh
24745 --- linux-4.4.115/scripts/checksyscalls.sh      2015-10-29 09:21:46.000000000 +0000
24746 +++ linux-4.4.115-vs2.3.9.7/scripts/checksyscalls.sh    2018-01-09 16:36:34.000000000 +0000
24747 @@ -196,7 +196,6 @@ cat << EOF
24748  #define __IGNORE_afs_syscall
24749  #define __IGNORE_getpmsg
24750  #define __IGNORE_putpmsg
24751 -#define __IGNORE_vserver
24752  EOF
24753  }
24754  
24755 diff -NurpP --minimal linux-4.4.115/security/commoncap.c linux-4.4.115-vs2.3.9.7/security/commoncap.c
24756 --- linux-4.4.115/security/commoncap.c  2018-02-10 14:39:06.000000000 +0000
24757 +++ linux-4.4.115-vs2.3.9.7/security/commoncap.c        2018-01-09 16:36:34.000000000 +0000
24758 @@ -71,6 +71,7 @@ static void warn_setuid_and_fcaps_mixed(
24759  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
24760                 int cap, int audit)
24761  {
24762 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
24763         struct user_namespace *ns = targ_ns;
24764  
24765         /* See if cred has the capability in the target user namespace
24766 @@ -79,8 +80,12 @@ int cap_capable(const struct cred *cred,
24767          */
24768         for (;;) {
24769                 /* Do we have the necessary capabilities? */
24770 -               if (ns == cred->user_ns)
24771 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
24772 +               if (ns == cred->user_ns) {
24773 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
24774 +                           cap_raised(cred->cap_effective, cap))
24775 +                               return 0;
24776 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
24777 +               }
24778  
24779                 /* Have we tried all of the parent namespaces? */
24780                 if (ns == &init_user_ns)
24781 @@ -664,7 +669,7 @@ int cap_inode_setxattr(struct dentry *de
24782  
24783         if (!strncmp(name, XATTR_SECURITY_PREFIX,
24784                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
24785 -           !capable(CAP_SYS_ADMIN))
24786 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
24787                 return -EPERM;
24788         return 0;
24789  }
24790 @@ -690,7 +695,7 @@ int cap_inode_removexattr(struct dentry
24791  
24792         if (!strncmp(name, XATTR_SECURITY_PREFIX,
24793                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
24794 -           !capable(CAP_SYS_ADMIN))
24795 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
24796                 return -EPERM;
24797         return 0;
24798  }
24799 diff -NurpP --minimal linux-4.4.115/security/selinux/hooks.c linux-4.4.115-vs2.3.9.7/security/selinux/hooks.c
24800 --- linux-4.4.115/security/selinux/hooks.c      2018-02-10 14:39:06.000000000 +0000
24801 +++ linux-4.4.115-vs2.3.9.7/security/selinux/hooks.c    2018-02-10 15:16:50.000000000 +0000
24802 @@ -67,7 +67,6 @@
24803  #include <linux/dccp.h>
24804  #include <linux/quota.h>
24805  #include <linux/un.h>          /* for Unix socket types */
24806 -#include <net/af_unix.h>       /* for Unix socket types */
24807  #include <linux/parser.h>
24808  #include <linux/nfs_mount.h>
24809  #include <net/ipv6.h>
This page took 2.531291 seconds and 3 git commands to generate.