]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- up to 4.4.180
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-4.4.161/Documentation/vserver/debug.txt linux-4.4.161-vs2.3.9.8/Documentation/vserver/debug.txt
2 --- linux-4.4.161/Documentation/vserver/debug.txt       1970-01-01 00:00:00.000000000 +0000
3 +++ linux-4.4.161-vs2.3.9.8/Documentation/vserver/debug.txt     2018-10-20 04:57:21.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.161/arch/alpha/Kconfig linux-4.4.161-vs2.3.9.8/arch/alpha/Kconfig
160 --- linux-4.4.161/arch/alpha/Kconfig    2016-01-10 23:01:32.000000000 +0000
161 +++ linux-4.4.161-vs2.3.9.8/arch/alpha/Kconfig  2018-10-20 04:57:21.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.161/arch/alpha/kernel/systbls.S linux-4.4.161-vs2.3.9.8/arch/alpha/kernel/systbls.S
172 --- linux-4.4.161/arch/alpha/kernel/systbls.S   2016-01-10 23:01:32.000000000 +0000
173 +++ linux-4.4.161-vs2.3.9.8/arch/alpha/kernel/systbls.S 2018-10-20 04:57:21.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.161/arch/alpha/kernel/traps.c linux-4.4.161-vs2.3.9.8/arch/alpha/kernel/traps.c
184 --- linux-4.4.161/arch/alpha/kernel/traps.c     2016-01-10 23:01:32.000000000 +0000
185 +++ linux-4.4.161-vs2.3.9.8/arch/alpha/kernel/traps.c   2018-10-20 04:57:21.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.161/arch/arm/Kconfig linux-4.4.161-vs2.3.9.8/arch/arm/Kconfig
197 --- linux-4.4.161/arch/arm/Kconfig      2016-01-10 23:01:32.000000000 +0000
198 +++ linux-4.4.161-vs2.3.9.8/arch/arm/Kconfig    2018-10-20 04:57:21.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.161/arch/arm/kernel/calls.S linux-4.4.161-vs2.3.9.8/arch/arm/kernel/calls.S
209 --- linux-4.4.161/arch/arm/kernel/calls.S       2016-01-10 23:01:32.000000000 +0000
210 +++ linux-4.4.161-vs2.3.9.8/arch/arm/kernel/calls.S     2018-10-20 04:57:21.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.161/arch/arm/kernel/traps.c linux-4.4.161-vs2.3.9.8/arch/arm/kernel/traps.c
221 --- linux-4.4.161/arch/arm/kernel/traps.c       2018-10-20 02:34:24.000000000 +0000
222 +++ linux-4.4.161-vs2.3.9.8/arch/arm/kernel/traps.c     2018-10-20 04:57:21.000000000 +0000
223 @@ -259,8 +259,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.161/arch/cris/Kconfig linux-4.4.161-vs2.3.9.8/arch/cris/Kconfig
235 --- linux-4.4.161/arch/cris/Kconfig     2016-01-10 23:01:32.000000000 +0000
236 +++ linux-4.4.161-vs2.3.9.8/arch/cris/Kconfig   2018-10-20 04:57:21.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.161/arch/ia64/Kconfig linux-4.4.161-vs2.3.9.8/arch/ia64/Kconfig
247 --- linux-4.4.161/arch/ia64/Kconfig     2016-01-10 23:01:32.000000000 +0000
248 +++ linux-4.4.161-vs2.3.9.8/arch/ia64/Kconfig   2018-10-20 04:57: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.161/arch/ia64/kernel/entry.S linux-4.4.161-vs2.3.9.8/arch/ia64/kernel/entry.S
259 --- linux-4.4.161/arch/ia64/kernel/entry.S      2016-01-10 23:01:32.000000000 +0000
260 +++ linux-4.4.161-vs2.3.9.8/arch/ia64/kernel/entry.S    2018-10-20 04:57: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.161/arch/ia64/kernel/ptrace.c linux-4.4.161-vs2.3.9.8/arch/ia64/kernel/ptrace.c
271 --- linux-4.4.161/arch/ia64/kernel/ptrace.c     2016-01-10 23:01:32.000000000 +0000
272 +++ linux-4.4.161-vs2.3.9.8/arch/ia64/kernel/ptrace.c   2018-10-20 04:57: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.161/arch/ia64/kernel/traps.c linux-4.4.161-vs2.3.9.8/arch/ia64/kernel/traps.c
282 --- linux-4.4.161/arch/ia64/kernel/traps.c      2016-01-10 23:01:32.000000000 +0000
283 +++ linux-4.4.161-vs2.3.9.8/arch/ia64/kernel/traps.c    2018-10-20 04:57: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.161/arch/m32r/kernel/traps.c linux-4.4.161-vs2.3.9.8/arch/m32r/kernel/traps.c
309 --- linux-4.4.161/arch/m32r/kernel/traps.c      2016-01-10 23:01:32.000000000 +0000
310 +++ linux-4.4.161-vs2.3.9.8/arch/m32r/kernel/traps.c    2018-10-20 04:57: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.161/arch/m68k/Kconfig linux-4.4.161-vs2.3.9.8/arch/m68k/Kconfig
324 --- linux-4.4.161/arch/m68k/Kconfig     2016-01-10 23:01:32.000000000 +0000
325 +++ linux-4.4.161-vs2.3.9.8/arch/m68k/Kconfig   2018-10-20 04:57: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.161/arch/mips/Kconfig linux-4.4.161-vs2.3.9.8/arch/mips/Kconfig
336 --- linux-4.4.161/arch/mips/Kconfig     2018-10-20 02:34:25.000000000 +0000
337 +++ linux-4.4.161-vs2.3.9.8/arch/mips/Kconfig   2018-10-20 04:57: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.161/arch/mips/kernel/ptrace.c linux-4.4.161-vs2.3.9.8/arch/mips/kernel/ptrace.c
348 --- linux-4.4.161/arch/mips/kernel/ptrace.c     2018-10-20 02:34:25.000000000 +0000
349 +++ linux-4.4.161-vs2.3.9.8/arch/mips/kernel/ptrace.c   2018-10-20 05:50:17.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 @@ -801,6 +802,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.161/arch/mips/kernel/scall32-o32.S linux-4.4.161-vs2.3.9.8/arch/mips/kernel/scall32-o32.S
369 --- linux-4.4.161/arch/mips/kernel/scall32-o32.S        2018-10-20 02:34:25.000000000 +0000
370 +++ linux-4.4.161-vs2.3.9.8/arch/mips/kernel/scall32-o32.S      2018-10-20 04:57: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.161/arch/mips/kernel/scall64-64.S linux-4.4.161-vs2.3.9.8/arch/mips/kernel/scall64-64.S
381 --- linux-4.4.161/arch/mips/kernel/scall64-64.S 2018-10-20 02:34:25.000000000 +0000
382 +++ linux-4.4.161-vs2.3.9.8/arch/mips/kernel/scall64-64.S       2018-10-20 04:57: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.161/arch/mips/kernel/scall64-n32.S linux-4.4.161-vs2.3.9.8/arch/mips/kernel/scall64-n32.S
393 --- linux-4.4.161/arch/mips/kernel/scall64-n32.S        2018-10-20 02:34:25.000000000 +0000
394 +++ linux-4.4.161-vs2.3.9.8/arch/mips/kernel/scall64-n32.S      2018-10-20 04:57: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.161/arch/mips/kernel/scall64-o32.S linux-4.4.161-vs2.3.9.8/arch/mips/kernel/scall64-o32.S
405 --- linux-4.4.161/arch/mips/kernel/scall64-o32.S        2018-10-20 02:34:25.000000000 +0000
406 +++ linux-4.4.161-vs2.3.9.8/arch/mips/kernel/scall64-o32.S      2018-10-20 04:57: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.161/arch/mips/kernel/traps.c linux-4.4.161-vs2.3.9.8/arch/mips/kernel/traps.c
417 --- linux-4.4.161/arch/mips/kernel/traps.c      2018-10-20 02:34:25.000000000 +0000
418 +++ linux-4.4.161-vs2.3.9.8/arch/mips/kernel/traps.c    2018-10-20 05:50:17.000000000 +0000
419 @@ -354,9 +354,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.161/arch/parisc/Kconfig linux-4.4.161-vs2.3.9.8/arch/parisc/Kconfig
434 --- linux-4.4.161/arch/parisc/Kconfig   2018-10-20 02:34:25.000000000 +0000
435 +++ linux-4.4.161-vs2.3.9.8/arch/parisc/Kconfig 2018-10-20 05:50:17.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.161/arch/parisc/kernel/syscall_table.S linux-4.4.161-vs2.3.9.8/arch/parisc/kernel/syscall_table.S
446 --- linux-4.4.161/arch/parisc/kernel/syscall_table.S    2018-10-20 02:34:25.000000000 +0000
447 +++ linux-4.4.161-vs2.3.9.8/arch/parisc/kernel/syscall_table.S  2018-10-20 04:57: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.161/arch/parisc/kernel/traps.c linux-4.4.161-vs2.3.9.8/arch/parisc/kernel/traps.c
458 --- linux-4.4.161/arch/parisc/kernel/traps.c    2018-10-20 02:34:25.000000000 +0000
459 +++ linux-4.4.161-vs2.3.9.8/arch/parisc/kernel/traps.c  2018-10-20 04:57: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.161/arch/powerpc/Kconfig linux-4.4.161-vs2.3.9.8/arch/powerpc/Kconfig
484 --- linux-4.4.161/arch/powerpc/Kconfig  2018-10-20 02:34:25.000000000 +0000
485 +++ linux-4.4.161-vs2.3.9.8/arch/powerpc/Kconfig        2018-10-20 04:57:21.000000000 +0000
486 @@ -1081,6 +1081,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.161/arch/powerpc/include/uapi/asm/unistd.h linux-4.4.161-vs2.3.9.8/arch/powerpc/include/uapi/asm/unistd.h
496 --- linux-4.4.161/arch/powerpc/include/uapi/asm/unistd.h        2016-01-10 23:01:32.000000000 +0000
497 +++ linux-4.4.161-vs2.3.9.8/arch/powerpc/include/uapi/asm/unistd.h      2018-10-20 04:57: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.161/arch/powerpc/kernel/traps.c linux-4.4.161-vs2.3.9.8/arch/powerpc/kernel/traps.c
508 --- linux-4.4.161/arch/powerpc/kernel/traps.c   2018-10-20 02:34:25.000000000 +0000
509 +++ linux-4.4.161-vs2.3.9.8/arch/powerpc/kernel/traps.c 2018-10-20 04:57: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.161/arch/s390/Kconfig linux-4.4.161-vs2.3.9.8/arch/s390/Kconfig
523 --- linux-4.4.161/arch/s390/Kconfig     2018-10-20 02:34:25.000000000 +0000
524 +++ linux-4.4.161-vs2.3.9.8/arch/s390/Kconfig   2018-10-20 04:57:21.000000000 +0000
525 @@ -776,6 +776,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.161/arch/s390/include/asm/tlb.h linux-4.4.161-vs2.3.9.8/arch/s390/include/asm/tlb.h
535 --- linux-4.4.161/arch/s390/include/asm/tlb.h   2016-01-10 23:01:32.000000000 +0000
536 +++ linux-4.4.161-vs2.3.9.8/arch/s390/include/asm/tlb.h 2018-10-20 04:57: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.161/arch/s390/include/uapi/asm/unistd.h linux-4.4.161-vs2.3.9.8/arch/s390/include/uapi/asm/unistd.h
546 --- linux-4.4.161/arch/s390/include/uapi/asm/unistd.h   2016-01-10 23:01:32.000000000 +0000
547 +++ linux-4.4.161-vs2.3.9.8/arch/s390/include/uapi/asm/unistd.h 2018-10-20 04:57:21.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.161/arch/s390/kernel/ptrace.c linux-4.4.161-vs2.3.9.8/arch/s390/kernel/ptrace.c
558 --- linux-4.4.161/arch/s390/kernel/ptrace.c     2018-10-20 02:34:25.000000000 +0000
559 +++ linux-4.4.161-vs2.3.9.8/arch/s390/kernel/ptrace.c   2018-10-20 04:57: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.161/arch/s390/kernel/syscalls.S linux-4.4.161-vs2.3.9.8/arch/s390/kernel/syscalls.S
569 --- linux-4.4.161/arch/s390/kernel/syscalls.S   2018-10-20 02:34:25.000000000 +0000
570 +++ linux-4.4.161-vs2.3.9.8/arch/s390/kernel/syscalls.S 2018-10-20 04:57: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.161/arch/sh/Kconfig linux-4.4.161-vs2.3.9.8/arch/sh/Kconfig
581 --- linux-4.4.161/arch/sh/Kconfig       2016-01-10 23:01:32.000000000 +0000
582 +++ linux-4.4.161-vs2.3.9.8/arch/sh/Kconfig     2018-10-20 04:57: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.161/arch/sh/kernel/irq.c linux-4.4.161-vs2.3.9.8/arch/sh/kernel/irq.c
593 --- linux-4.4.161/arch/sh/kernel/irq.c  2016-01-10 23:01:32.000000000 +0000
594 +++ linux-4.4.161-vs2.3.9.8/arch/sh/kernel/irq.c        2018-10-20 04:57: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.161/arch/sparc/Kconfig linux-4.4.161-vs2.3.9.8/arch/sparc/Kconfig
604 --- linux-4.4.161/arch/sparc/Kconfig    2018-10-20 02:34:25.000000000 +0000
605 +++ linux-4.4.161-vs2.3.9.8/arch/sparc/Kconfig  2018-10-20 04:57: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.161/arch/sparc/include/uapi/asm/unistd.h linux-4.4.161-vs2.3.9.8/arch/sparc/include/uapi/asm/unistd.h
616 --- linux-4.4.161/arch/sparc/include/uapi/asm/unistd.h  2016-01-10 23:01:32.000000000 +0000
617 +++ linux-4.4.161-vs2.3.9.8/arch/sparc/include/uapi/asm/unistd.h        2018-10-20 04:57: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.161/arch/sparc/kernel/systbls_32.S linux-4.4.161-vs2.3.9.8/arch/sparc/kernel/systbls_32.S
628 --- linux-4.4.161/arch/sparc/kernel/systbls_32.S        2016-01-10 23:01:32.000000000 +0000
629 +++ linux-4.4.161-vs2.3.9.8/arch/sparc/kernel/systbls_32.S      2018-10-20 04:57: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.161/arch/sparc/kernel/systbls_64.S linux-4.4.161-vs2.3.9.8/arch/sparc/kernel/systbls_64.S
640 --- linux-4.4.161/arch/sparc/kernel/systbls_64.S        2016-01-10 23:01:32.000000000 +0000
641 +++ linux-4.4.161-vs2.3.9.8/arch/sparc/kernel/systbls_64.S      2018-10-20 04:57: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.161/arch/um/Kconfig.rest linux-4.4.161-vs2.3.9.8/arch/um/Kconfig.rest
661 --- linux-4.4.161/arch/um/Kconfig.rest  2016-01-10 23:01:32.000000000 +0000
662 +++ linux-4.4.161-vs2.3.9.8/arch/um/Kconfig.rest        2018-10-20 04:57: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.161/arch/x86/Kconfig linux-4.4.161-vs2.3.9.8/arch/x86/Kconfig
673 --- linux-4.4.161/arch/x86/Kconfig      2018-10-20 02:34:25.000000000 +0000
674 +++ linux-4.4.161-vs2.3.9.8/arch/x86/Kconfig    2018-10-20 04:57:21.000000000 +0000
675 @@ -2693,6 +2693,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.161/arch/x86/entry/syscalls/syscall_32.tbl linux-4.4.161-vs2.3.9.8/arch/x86/entry/syscalls/syscall_32.tbl
685 --- linux-4.4.161/arch/x86/entry/syscalls/syscall_32.tbl        2018-10-20 02:34:25.000000000 +0000
686 +++ linux-4.4.161-vs2.3.9.8/arch/x86/entry/syscalls/syscall_32.tbl      2018-10-20 04:57:21.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.161/arch/x86/entry/syscalls/syscall_64.tbl linux-4.4.161-vs2.3.9.8/arch/x86/entry/syscalls/syscall_64.tbl
697 --- linux-4.4.161/arch/x86/entry/syscalls/syscall_64.tbl        2016-01-10 23:01:32.000000000 +0000
698 +++ linux-4.4.161-vs2.3.9.8/arch/x86/entry/syscalls/syscall_64.tbl      2018-10-20 04:57:21.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.161/block/ioprio.c linux-4.4.161-vs2.3.9.8/block/ioprio.c
709 --- linux-4.4.161/block/ioprio.c        2018-10-20 02:34:26.000000000 +0000
710 +++ linux-4.4.161-vs2.3.9.8/block/ioprio.c      2018-10-20 04:57:21.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.161/drivers/block/Kconfig linux-4.4.161-vs2.3.9.8/drivers/block/Kconfig
738 --- linux-4.4.161/drivers/block/Kconfig 2016-01-10 23:01:32.000000000 +0000
739 +++ linux-4.4.161-vs2.3.9.8/drivers/block/Kconfig       2018-10-20 04:57:21.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.161/drivers/block/Makefile linux-4.4.161-vs2.3.9.8/drivers/block/Makefile
755 --- linux-4.4.161/drivers/block/Makefile        2016-01-10 23:01:32.000000000 +0000
756 +++ linux-4.4.161-vs2.3.9.8/drivers/block/Makefile      2018-10-20 04:57:21.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.161/drivers/block/loop.c linux-4.4.161-vs2.3.9.8/drivers/block/loop.c
766 --- linux-4.4.161/drivers/block/loop.c  2018-10-20 02:34:26.000000000 +0000
767 +++ linux-4.4.161-vs2.3.9.8/drivers/block/loop.c        2018-10-20 04:57:21.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 @@ -947,6 +948,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 @@ -1067,6 +1069,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 @@ -1113,7 +1116,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 @@ -1218,7 +1221,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 @@ -1579,6 +1583,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.161/drivers/block/loop.h linux-4.4.161-vs2.3.9.8/drivers/block/loop.h
824 --- linux-4.4.161/drivers/block/loop.h  2018-10-20 02:34:26.000000000 +0000
825 +++ linux-4.4.161-vs2.3.9.8/drivers/block/loop.h        2018-10-20 04:57:21.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.161/drivers/block/vroot.c linux-4.4.161-vs2.3.9.8/drivers/block/vroot.c
835 --- linux-4.4.161/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
836 +++ linux-4.4.161-vs2.3.9.8/drivers/block/vroot.c       2018-10-20 04:57:21.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.161/drivers/infiniband/core/addr.c linux-4.4.161-vs2.3.9.8/drivers/infiniband/core/addr.c
1130 --- linux-4.4.161/drivers/infiniband/core/addr.c        2018-10-20 02:34:27.000000000 +0000
1131 +++ linux-4.4.161-vs2.3.9.8/drivers/infiniband/core/addr.c      2018-10-20 04:57:21.000000000 +0000
1132 @@ -299,7 +299,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.161/drivers/md/dm-ioctl.c linux-4.4.161-vs2.3.9.8/drivers/md/dm-ioctl.c
1142 --- linux-4.4.161/drivers/md/dm-ioctl.c 2018-10-20 02:34:27.000000000 +0000
1143 +++ linux-4.4.161-vs2.3.9.8/drivers/md/dm-ioctl.c       2018-10-20 04:57:21.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.161/drivers/md/dm.c linux-4.4.161-vs2.3.9.8/drivers/md/dm.c
1230 --- linux-4.4.161/drivers/md/dm.c       2018-10-20 02:34:27.000000000 +0000
1231 +++ linux-4.4.161-vs2.3.9.8/drivers/md/dm.c     2018-10-20 04:57:21.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 @@ -2381,6 +2394,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.161/drivers/md/dm.h linux-4.4.161-vs2.3.9.8/drivers/md/dm.h
1305 --- linux-4.4.161/drivers/md/dm.h       2016-01-10 23:01:32.000000000 +0000
1306 +++ linux-4.4.161-vs2.3.9.8/drivers/md/dm.h     2018-10-20 04:57:21.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.161/drivers/net/tun.c linux-4.4.161-vs2.3.9.8/drivers/net/tun.c
1317 --- linux-4.4.161/drivers/net/tun.c     2018-10-20 02:34:28.000000000 +0000
1318 +++ linux-4.4.161-vs2.3.9.8/drivers/net/tun.c   2018-10-20 04:57:21.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.161/drivers/scsi/cxgbi/libcxgbi.c linux-4.4.161-vs2.3.9.8/drivers/scsi/cxgbi/libcxgbi.c
1378 --- linux-4.4.161/drivers/scsi/cxgbi/libcxgbi.c 2016-01-10 23:01:32.000000000 +0000
1379 +++ linux-4.4.161-vs2.3.9.8/drivers/scsi/cxgbi/libcxgbi.c       2018-10-20 04:57:21.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.161/drivers/tty/sysrq.c linux-4.4.161-vs2.3.9.8/drivers/tty/sysrq.c
1391 --- linux-4.4.161/drivers/tty/sysrq.c   2018-10-20 02:34:29.000000000 +0000
1392 +++ linux-4.4.161-vs2.3.9.8/drivers/tty/sysrq.c 2018-10-20 04:57:21.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.161/drivers/tty/tty_io.c linux-4.4.161-vs2.3.9.8/drivers/tty/tty_io.c
1445 --- linux-4.4.161/drivers/tty/tty_io.c  2018-10-20 02:34:29.000000000 +0000
1446 +++ linux-4.4.161-vs2.3.9.8/drivers/tty/tty_io.c        2018-10-20 04:57:21.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 @@ -2291,7 +2292,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 @@ -2604,6 +2606,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.161/fs/attr.c linux-4.4.161-vs2.3.9.8/fs/attr.c
1474 --- linux-4.4.161/fs/attr.c     2018-10-20 02:34:30.000000000 +0000
1475 +++ linux-4.4.161-vs2.3.9.8/fs/attr.c   2018-10-20 04:57:21.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.161/fs/block_dev.c linux-4.4.161-vs2.3.9.8/fs/block_dev.c
1517 --- linux-4.4.161/fs/block_dev.c        2018-10-20 02:34:30.000000000 +0000
1518 +++ linux-4.4.161-vs2.3.9.8/fs/block_dev.c      2018-10-20 04:57:21.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.161/fs/btrfs/ctree.h linux-4.4.161-vs2.3.9.8/fs/btrfs/ctree.h
1557 --- linux-4.4.161/fs/btrfs/ctree.h      2018-10-20 02:34:30.000000000 +0000
1558 +++ linux-4.4.161-vs2.3.9.8/fs/btrfs/ctree.h    2018-10-20 04:57:21.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.161/fs/btrfs/disk-io.c linux-4.4.161-vs2.3.9.8/fs/btrfs/disk-io.c
1612 --- linux-4.4.161/fs/btrfs/disk-io.c    2018-10-20 02:34:30.000000000 +0000
1613 +++ linux-4.4.161-vs2.3.9.8/fs/btrfs/disk-io.c  2018-10-20 05:50:20.000000000 +0000
1614 @@ -2737,6 +2737,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.161/fs/btrfs/inode.c linux-4.4.161-vs2.3.9.8/fs/btrfs/inode.c
1625 --- linux-4.4.161/fs/btrfs/inode.c      2018-10-20 02:34:30.000000000 +0000
1626 +++ linux-4.4.161-vs2.3.9.8/fs/btrfs/inode.c    2018-10-20 04:57:21.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 @@ -3649,6 +3650,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 @@ -3676,8 +3680,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 @@ -3833,11 +3843,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 @@ -10092,6 +10109,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 @@ -10100,6 +10118,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 @@ -10170,6 +10189,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.161/fs/btrfs/ioctl.c linux-4.4.161-vs2.3.9.8/fs/btrfs/ioctl.c
1708 --- linux-4.4.161/fs/btrfs/ioctl.c      2018-10-20 02:34:30.000000000 +0000
1709 +++ linux-4.4.161-vs2.3.9.8/fs/btrfs/ioctl.c    2018-10-20 04:57:21.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.161/fs/btrfs/super.c linux-4.4.161-vs2.3.9.8/fs/btrfs/super.c
1889 --- linux-4.4.161/fs/btrfs/super.c      2018-10-20 02:34:30.000000000 +0000
1890 +++ linux-4.4.161-vs2.3.9.8/fs/btrfs/super.c    2018-10-20 04:57:21.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.161/fs/char_dev.c linux-4.4.161-vs2.3.9.8/fs/char_dev.c
1947 --- linux-4.4.161/fs/char_dev.c 2016-01-10 23:01:32.000000000 +0000
1948 +++ linux-4.4.161-vs2.3.9.8/fs/char_dev.c       2018-10-20 04:57:21.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.161/fs/dcache.c linux-4.4.161-vs2.3.9.8/fs/dcache.c
1982 --- linux-4.4.161/fs/dcache.c   2018-10-20 02:34:30.000000000 +0000
1983 +++ linux-4.4.161-vs2.3.9.8/fs/dcache.c 2018-10-20 05:50:20.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 @@ -683,6 +684,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 @@ -812,6 +814,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 @@ -829,6 +832,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 @@ -841,6 +845,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 @@ -871,6 +877,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 @@ -1025,6 +1032,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 @@ -1587,6 +1595,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 @@ -1625,6 +1636,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 @@ -2385,6 +2397,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 @@ -3401,6 +3414,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.161/fs/devpts/inode.c linux-4.4.161-vs2.3.9.8/fs/devpts/inode.c
2076 --- linux-4.4.161/fs/devpts/inode.c     2018-10-20 02:34:30.000000000 +0000
2077 +++ linux-4.4.161-vs2.3.9.8/fs/devpts/inode.c   2018-10-20 04:57:21.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.161/fs/ext2/balloc.c linux-4.4.161-vs2.3.9.8/fs/ext2/balloc.c
2166 --- linux-4.4.161/fs/ext2/balloc.c      2016-01-10 23:01:32.000000000 +0000
2167 +++ linux-4.4.161-vs2.3.9.8/fs/ext2/balloc.c    2018-10-20 04:57:21.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.161/fs/ext2/ext2.h linux-4.4.161-vs2.3.9.8/fs/ext2/ext2.h
2177 --- linux-4.4.161/fs/ext2/ext2.h        2016-01-10 23:01:32.000000000 +0000
2178 +++ linux-4.4.161-vs2.3.9.8/fs/ext2/ext2.h      2018-10-20 04:57:21.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.161/fs/ext2/file.c linux-4.4.161-vs2.3.9.8/fs/ext2/file.c
2227 --- linux-4.4.161/fs/ext2/file.c        2016-01-10 23:01:32.000000000 +0000
2228 +++ linux-4.4.161-vs2.3.9.8/fs/ext2/file.c      2018-10-20 04:57:21.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.161/fs/ext2/ialloc.c linux-4.4.161-vs2.3.9.8/fs/ext2/ialloc.c
2236 --- linux-4.4.161/fs/ext2/ialloc.c      2016-01-10 23:01:32.000000000 +0000
2237 +++ linux-4.4.161-vs2.3.9.8/fs/ext2/ialloc.c    2018-10-20 04:57:21.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.161/fs/ext2/inode.c linux-4.4.161-vs2.3.9.8/fs/ext2/inode.c
2255 --- linux-4.4.161/fs/ext2/inode.c       2018-10-20 02:34:30.000000000 +0000
2256 +++ linux-4.4.161-vs2.3.9.8/fs/ext2/inode.c     2018-10-20 04:57:21.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 @@ -1274,39 +1275,62 @@ void ext2_set_inode_flags(struct inode *
2266  {
2267         unsigned int flags = EXT2_I(inode)->i_flags;
2268  
2269 -       inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME |
2270 -                               S_DIRSYNC | S_DAX);
2271 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK | S_DAX |
2272 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2273 +
2274 +       if (flags & EXT2_IMMUTABLE_FL)
2275 +               inode->i_flags |= S_IMMUTABLE;
2276 +       if (flags & EXT2_IXUNLINK_FL)
2277 +               inode->i_flags |= S_IXUNLINK;
2278 +
2279         if (flags & EXT2_SYNC_FL)
2280                 inode->i_flags |= S_SYNC;
2281         if (flags & EXT2_APPEND_FL)
2282                 inode->i_flags |= S_APPEND;
2283 -       if (flags & EXT2_IMMUTABLE_FL)
2284 -               inode->i_flags |= S_IMMUTABLE;
2285         if (flags & EXT2_NOATIME_FL)
2286                 inode->i_flags |= S_NOATIME;
2287         if (flags & EXT2_DIRSYNC_FL)
2288                 inode->i_flags |= S_DIRSYNC;
2289         if (test_opt(inode->i_sb, DAX))
2290                 inode->i_flags |= S_DAX;
2291 +
2292 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2293 +
2294 +       if (flags & EXT2_BARRIER_FL)
2295 +               inode->i_vflags |= V_BARRIER;
2296 +       if (flags & EXT2_COW_FL)
2297 +               inode->i_vflags |= V_COW;
2298  }
2299  
2300  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2301  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2302  {
2303         unsigned int flags = ei->vfs_inode.i_flags;
2304 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2305 +
2306 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2307 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2308 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2309 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2310 +
2311 +       if (flags & S_IMMUTABLE)
2312 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2313 +       if (flags & S_IXUNLINK)
2314 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2315  
2316 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2317 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2318         if (flags & S_SYNC)
2319                 ei->i_flags |= EXT2_SYNC_FL;
2320         if (flags & S_APPEND)
2321                 ei->i_flags |= EXT2_APPEND_FL;
2322 -       if (flags & S_IMMUTABLE)
2323 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2324         if (flags & S_NOATIME)
2325                 ei->i_flags |= EXT2_NOATIME_FL;
2326         if (flags & S_DIRSYNC)
2327                 ei->i_flags |= EXT2_DIRSYNC_FL;
2328 +
2329 +       if (vflags & V_BARRIER)
2330 +               ei->i_flags |= EXT2_BARRIER_FL;
2331 +       if (vflags & V_COW)
2332 +               ei->i_flags |= EXT2_COW_FL;
2333  }
2334  
2335  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2336 @@ -1342,8 +1366,10 @@ struct inode *ext2_iget (struct super_bl
2337                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2338                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2339         }
2340 -       i_uid_write(inode, i_uid);
2341 -       i_gid_write(inode, i_gid);
2342 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2343 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2344 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2345 +               le16_to_cpu(raw_inode->i_raw_tag)));
2346         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2347         inode->i_size = le32_to_cpu(raw_inode->i_size);
2348         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2349 @@ -1439,8 +1465,10 @@ static int __ext2_write_inode(struct ino
2350         struct ext2_inode_info *ei = EXT2_I(inode);
2351         struct super_block *sb = inode->i_sb;
2352         ino_t ino = inode->i_ino;
2353 -       uid_t uid = i_uid_read(inode);
2354 -       gid_t gid = i_gid_read(inode);
2355 +       uid_t uid = from_kuid(&init_user_ns,
2356 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2357 +       gid_t gid = from_kgid(&init_user_ns,
2358 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2359         struct buffer_head * bh;
2360         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2361         int n;
2362 @@ -1476,6 +1504,9 @@ static int __ext2_write_inode(struct ino
2363                 raw_inode->i_uid_high = 0;
2364                 raw_inode->i_gid_high = 0;
2365         }
2366 +#ifdef CONFIG_TAGGING_INTERN
2367 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2368 +#endif
2369         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2370         raw_inode->i_size = cpu_to_le32(inode->i_size);
2371         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2372 @@ -1559,7 +1590,8 @@ int ext2_setattr(struct dentry *dentry,
2373                         return error;
2374         }
2375         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2376 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2377 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2378 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2379                 error = dquot_transfer(inode, iattr);
2380                 if (error)
2381                         return error;
2382 diff -NurpP --minimal linux-4.4.161/fs/ext2/ioctl.c linux-4.4.161-vs2.3.9.8/fs/ext2/ioctl.c
2383 --- linux-4.4.161/fs/ext2/ioctl.c       2016-01-10 23:01:32.000000000 +0000
2384 +++ linux-4.4.161-vs2.3.9.8/fs/ext2/ioctl.c     2018-10-20 04:57:21.000000000 +0000
2385 @@ -17,6 +17,16 @@
2386  #include <asm/uaccess.h>
2387  
2388  
2389 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2390 +{
2391 +       inode->i_flags = flags;
2392 +       inode->i_vflags = vflags;
2393 +       ext2_get_inode_flags(EXT2_I(inode));
2394 +       inode->i_ctime = CURRENT_TIME_SEC;
2395 +       mark_inode_dirty(inode);
2396 +       return 0;
2397 +}
2398 +
2399  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2400  {
2401         struct inode *inode = file_inode(filp);
2402 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2403  
2404                 flags = ext2_mask_flags(inode->i_mode, flags);
2405  
2406 +               if (IS_BARRIER(inode)) {
2407 +                       vxwprintk_task(1, "messing with the barrier.");
2408 +                       return -EACCES;
2409 +               }
2410 +
2411                 mutex_lock(&inode->i_mutex);
2412                 /* Is it quota file? Do not allow user to mess with it */
2413                 if (IS_NOQUOTA(inode)) {
2414 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2415                  *
2416                  * This test looks nicer. Thanks to Pauline Middelink
2417                  */
2418 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2419 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2420 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2421 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2422                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2423                                 mutex_unlock(&inode->i_mutex);
2424                                 ret = -EPERM;
2425 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2426                         }
2427                 }
2428  
2429 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2430 +               flags &= EXT2_FL_USER_MODIFIABLE;
2431                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2432                 ei->i_flags = flags;
2433  
2434 diff -NurpP --minimal linux-4.4.161/fs/ext2/namei.c linux-4.4.161-vs2.3.9.8/fs/ext2/namei.c
2435 --- linux-4.4.161/fs/ext2/namei.c       2018-10-20 02:34:30.000000000 +0000
2436 +++ linux-4.4.161-vs2.3.9.8/fs/ext2/namei.c     2018-10-20 04:57:21.000000000 +0000
2437 @@ -32,6 +32,7 @@
2438  
2439  #include <linux/pagemap.h>
2440  #include <linux/quotaops.h>
2441 +#include <linux/vs_tag.h>
2442  #include "ext2.h"
2443  #include "xattr.h"
2444  #include "acl.h"
2445 @@ -71,6 +72,7 @@ static struct dentry *ext2_lookup(struct
2446                                         (unsigned long) ino);
2447                         return ERR_PTR(-EIO);
2448                 }
2449 +               dx_propagate_tag(nd, inode);
2450         }
2451         return d_splice_alias(inode, dentry);
2452  }
2453 @@ -444,6 +446,7 @@ const struct inode_operations ext2_speci
2454         .removexattr    = generic_removexattr,
2455  #endif
2456         .setattr        = ext2_setattr,
2457 +       .sync_flags     = ext2_sync_flags,
2458         .get_acl        = ext2_get_acl,
2459         .set_acl        = ext2_set_acl,
2460  };
2461 diff -NurpP --minimal linux-4.4.161/fs/ext2/super.c linux-4.4.161-vs2.3.9.8/fs/ext2/super.c
2462 --- linux-4.4.161/fs/ext2/super.c       2016-01-10 23:01:32.000000000 +0000
2463 +++ linux-4.4.161-vs2.3.9.8/fs/ext2/super.c     2018-10-20 04:57:21.000000000 +0000
2464 @@ -408,7 +408,8 @@ enum {
2465         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2466         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2467         Opt_acl, Opt_noacl, Opt_xip, Opt_dax, Opt_ignore, Opt_err, Opt_quota,
2468 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2469 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2470 +       Opt_tag, Opt_notag, Opt_tagid
2471  };
2472  
2473  static const match_table_t tokens = {
2474 @@ -436,6 +437,9 @@ static const match_table_t tokens = {
2475         {Opt_acl, "acl"},
2476         {Opt_noacl, "noacl"},
2477         {Opt_xip, "xip"},
2478 +       {Opt_tag, "tag"},
2479 +       {Opt_notag, "notag"},
2480 +       {Opt_tagid, "tagid=%u"},
2481         {Opt_dax, "dax"},
2482         {Opt_grpquota, "grpquota"},
2483         {Opt_ignore, "noquota"},
2484 @@ -520,6 +524,20 @@ static int parse_options(char *options,
2485                 case Opt_nouid32:
2486                         set_opt (sbi->s_mount_opt, NO_UID32);
2487                         break;
2488 +#ifndef CONFIG_TAGGING_NONE
2489 +               case Opt_tag:
2490 +                       set_opt (sbi->s_mount_opt, TAGGED);
2491 +                       break;
2492 +               case Opt_notag:
2493 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2494 +                       break;
2495 +#endif
2496 +#ifdef CONFIG_PROPAGATE
2497 +               case Opt_tagid:
2498 +                       /* use args[0] */
2499 +                       set_opt (sbi->s_mount_opt, TAGGED);
2500 +                       break;
2501 +#endif
2502                 case Opt_nocheck:
2503                         clear_opt (sbi->s_mount_opt, CHECK);
2504                         break;
2505 @@ -884,6 +902,8 @@ static int ext2_fill_super(struct super_
2506         if (!parse_options((char *) data, sb))
2507                 goto failed_mount;
2508  
2509 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2510 +               sb->s_flags |= MS_TAGGED;
2511         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2512                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2513                  MS_POSIXACL : 0);
2514 @@ -1294,6 +1314,14 @@ static int ext2_remount (struct super_bl
2515                 err = -EINVAL;
2516                 goto restore_opts;
2517         }
2518 +
2519 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2520 +               !(sb->s_flags & MS_TAGGED)) {
2521 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2522 +                      sb->s_id);
2523 +               err = -EINVAL;
2524 +               goto restore_opts;
2525 +       }
2526  
2527         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2528                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2529 diff -NurpP --minimal linux-4.4.161/fs/ext4/ext4.h linux-4.4.161-vs2.3.9.8/fs/ext4/ext4.h
2530 --- linux-4.4.161/fs/ext4/ext4.h        2018-10-20 02:34:30.000000000 +0000
2531 +++ linux-4.4.161-vs2.3.9.8/fs/ext4/ext4.h      2018-10-20 04:57:21.000000000 +0000
2532 @@ -375,8 +375,11 @@ struct flex_groups {
2533  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2534  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2535  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2536 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2537 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2538  #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data. */
2539  #define EXT4_PROJINHERIT_FL            0x20000000 /* Create with parents projid */
2540 +#define EXT4_COW_FL                    0x40000000 /* Copy on Write marker */
2541  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2542  
2543  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2544 @@ -674,7 +677,7 @@ struct ext4_inode {
2545                         __le16  l_i_uid_high;   /* these 2 fields */
2546                         __le16  l_i_gid_high;   /* were reserved2[0] */
2547                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2548 -                       __le16  l_i_reserved;
2549 +                       __le16  l_i_tag;        /* Context Tag */
2550                 } linux2;
2551                 struct {
2552                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
2553 @@ -831,6 +834,7 @@ do {                                                                               \
2554  #define i_gid_low      i_gid
2555  #define i_uid_high     osd2.linux2.l_i_uid_high
2556  #define i_gid_high     osd2.linux2.l_i_gid_high
2557 +#define i_raw_tag      osd2.linux2.l_i_tag
2558  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
2559  
2560  #elif defined(__GNU__)
2561 @@ -1068,6 +1072,7 @@ struct ext4_inode_info {
2562  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
2563  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
2564  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
2565 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
2566  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
2567  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
2568  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2569 @@ -2496,6 +2501,7 @@ extern int ext4_punch_hole(struct inode
2570  extern int ext4_truncate_restart_trans(handle_t *, struct inode *, int nblocks);
2571  extern void ext4_set_inode_flags(struct inode *);
2572  extern void ext4_get_inode_flags(struct ext4_inode_info *);
2573 +extern int ext4_sync_flags(struct inode *, int, int);
2574  extern int ext4_alloc_da_blocks(struct inode *inode);
2575  extern void ext4_set_aops(struct inode *inode);
2576  extern int ext4_writepage_trans_blocks(struct inode *);
2577 diff -NurpP --minimal linux-4.4.161/fs/ext4/file.c linux-4.4.161-vs2.3.9.8/fs/ext4/file.c
2578 --- linux-4.4.161/fs/ext4/file.c        2018-10-20 02:34:30.000000000 +0000
2579 +++ linux-4.4.161-vs2.3.9.8/fs/ext4/file.c      2018-10-20 04:57:21.000000000 +0000
2580 @@ -749,5 +749,6 @@ const struct inode_operations ext4_file_
2581         .get_acl        = ext4_get_acl,
2582         .set_acl        = ext4_set_acl,
2583         .fiemap         = ext4_fiemap,
2584 +       .sync_flags     = ext4_sync_flags,
2585  };
2586  
2587 diff -NurpP --minimal linux-4.4.161/fs/ext4/ialloc.c linux-4.4.161-vs2.3.9.8/fs/ext4/ialloc.c
2588 --- linux-4.4.161/fs/ext4/ialloc.c      2018-10-20 02:34:30.000000000 +0000
2589 +++ linux-4.4.161-vs2.3.9.8/fs/ext4/ialloc.c    2018-10-20 05:50:20.000000000 +0000
2590 @@ -21,6 +21,7 @@
2591  #include <linux/random.h>
2592  #include <linux/bitops.h>
2593  #include <linux/blkdev.h>
2594 +#include <linux/vs_tag.h>
2595  #include <asm/byteorder.h>
2596  
2597  #include "ext4.h"
2598 @@ -777,6 +778,7 @@ struct inode *__ext4_new_inode(handle_t
2599                 inode->i_mode = mode;
2600                 inode->i_uid = current_fsuid();
2601                 inode->i_gid = dir->i_gid;
2602 +               i_tag_write(inode, dx_current_fstag(sb));
2603         } else
2604                 inode_init_owner(inode, dir, mode);
2605         err = dquot_initialize(inode);
2606 diff -NurpP --minimal linux-4.4.161/fs/ext4/inode.c linux-4.4.161-vs2.3.9.8/fs/ext4/inode.c
2607 --- linux-4.4.161/fs/ext4/inode.c       2018-10-20 02:34:30.000000000 +0000
2608 +++ linux-4.4.161-vs2.3.9.8/fs/ext4/inode.c     2018-10-20 05:50:20.000000000 +0000
2609 @@ -37,6 +37,7 @@
2610  #include <linux/printk.h>
2611  #include <linux/slab.h>
2612  #include <linux/bitops.h>
2613 +#include <linux/vs_tag.h>
2614  
2615  #include "ext4_jbd2.h"
2616  #include "xattr.h"
2617 @@ -4129,12 +4130,15 @@ void ext4_set_inode_flags(struct inode *
2618         unsigned int flags = EXT4_I(inode)->i_flags;
2619         unsigned int new_fl = 0;
2620  
2621 +       if (flags & EXT4_IMMUTABLE_FL)
2622 +               new_fl |= S_IMMUTABLE;
2623 +       if (flags & EXT4_IXUNLINK_FL)
2624 +               new_fl |= S_IXUNLINK;
2625 +
2626         if (flags & EXT4_SYNC_FL)
2627                 new_fl |= S_SYNC;
2628         if (flags & EXT4_APPEND_FL)
2629                 new_fl |= S_APPEND;
2630 -       if (flags & EXT4_IMMUTABLE_FL)
2631 -               new_fl |= S_IMMUTABLE;
2632         if (flags & EXT4_NOATIME_FL)
2633                 new_fl |= S_NOATIME;
2634         if (flags & EXT4_DIRSYNC_FL)
2635 @@ -4142,31 +4146,52 @@ void ext4_set_inode_flags(struct inode *
2636         if (test_opt(inode->i_sb, DAX))
2637                 new_fl |= S_DAX;
2638         inode_set_flags(inode, new_fl,
2639 -                       S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_DAX);
2640 +               S_IXUNLINK | S_IMMUTABLE | S_DAX |
2641 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2642 +
2643 +       new_fl = 0;
2644 +       if (flags & EXT4_BARRIER_FL)
2645 +               new_fl |= V_BARRIER;
2646 +       if (flags & EXT4_COW_FL)
2647 +               new_fl |= V_COW;
2648 +
2649 +       set_mask_bits(&inode->i_vflags,
2650 +               V_BARRIER | V_COW, new_fl);
2651  }
2652  
2653  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2654  void ext4_get_inode_flags(struct ext4_inode_info *ei)
2655  {
2656 -       unsigned int vfs_fl;
2657 +       unsigned int vfs_fl, vfs_vf;
2658         unsigned long old_fl, new_fl;
2659  
2660         do {
2661                 vfs_fl = ei->vfs_inode.i_flags;
2662 +               vfs_vf = ei->vfs_inode.i_vflags;
2663                 old_fl = ei->i_flags;
2664                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2665                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2666 -                               EXT4_DIRSYNC_FL);
2667 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2668 +                               EXT4_COW_FL);
2669 +
2670 +               if (vfs_fl & S_IMMUTABLE)
2671 +                       new_fl |= EXT4_IMMUTABLE_FL;
2672 +               if (vfs_fl & S_IXUNLINK)
2673 +                       new_fl |= EXT4_IXUNLINK_FL;
2674 +
2675                 if (vfs_fl & S_SYNC)
2676                         new_fl |= EXT4_SYNC_FL;
2677                 if (vfs_fl & S_APPEND)
2678                         new_fl |= EXT4_APPEND_FL;
2679 -               if (vfs_fl & S_IMMUTABLE)
2680 -                       new_fl |= EXT4_IMMUTABLE_FL;
2681                 if (vfs_fl & S_NOATIME)
2682                         new_fl |= EXT4_NOATIME_FL;
2683                 if (vfs_fl & S_DIRSYNC)
2684                         new_fl |= EXT4_DIRSYNC_FL;
2685 +
2686 +               if (vfs_vf & V_BARRIER)
2687 +                       new_fl |= EXT4_BARRIER_FL;
2688 +               if (vfs_vf & V_COW)
2689 +                       new_fl |= EXT4_COW_FL;
2690         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
2691  }
2692  
2693 @@ -4276,8 +4301,10 @@ struct inode *ext4_iget(struct super_blo
2694                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2695                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2696         }
2697 -       i_uid_write(inode, i_uid);
2698 -       i_gid_write(inode, i_gid);
2699 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2700 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2701 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2702 +               le16_to_cpu(raw_inode->i_raw_tag)));
2703         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2704  
2705         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
2706 @@ -4591,8 +4618,10 @@ static int ext4_do_update_inode(handle_t
2707  
2708         ext4_get_inode_flags(ei);
2709         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2710 -       i_uid = i_uid_read(inode);
2711 -       i_gid = i_gid_read(inode);
2712 +       i_uid = from_kuid(&init_user_ns,
2713 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2714 +       i_gid = from_kgid(&init_user_ns,
2715 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2716         if (!(test_opt(inode->i_sb, NO_UID32))) {
2717                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2718                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2719 @@ -4615,6 +4644,9 @@ static int ext4_do_update_inode(handle_t
2720                 raw_inode->i_uid_high = 0;
2721                 raw_inode->i_gid_high = 0;
2722         }
2723 +#ifdef CONFIG_TAGGING_INTERN
2724 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2725 +#endif
2726         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2727  
2728         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
2729 @@ -4860,7 +4892,8 @@ int ext4_setattr(struct dentry *dentry,
2730                         return error;
2731         }
2732         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2733 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2734 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2735 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2736                 handle_t *handle;
2737  
2738                 /* (user+group)*(old+new) structure, inode write (sb,
2739 @@ -4883,6 +4916,8 @@ int ext4_setattr(struct dentry *dentry,
2740                         inode->i_uid = attr->ia_uid;
2741                 if (attr->ia_valid & ATTR_GID)
2742                         inode->i_gid = attr->ia_gid;
2743 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2744 +                       inode->i_tag = attr->ia_tag;
2745                 error = ext4_mark_inode_dirty(handle, inode);
2746                 ext4_journal_stop(handle);
2747         }
2748 diff -NurpP --minimal linux-4.4.161/fs/ext4/ioctl.c linux-4.4.161-vs2.3.9.8/fs/ext4/ioctl.c
2749 --- linux-4.4.161/fs/ext4/ioctl.c       2018-10-20 02:34:30.000000000 +0000
2750 +++ linux-4.4.161-vs2.3.9.8/fs/ext4/ioctl.c     2018-10-20 04:57:21.000000000 +0000
2751 @@ -14,6 +14,7 @@
2752  #include <linux/mount.h>
2753  #include <linux/file.h>
2754  #include <linux/random.h>
2755 +#include <linux/vs_tag.h>
2756  #include <asm/uaccess.h>
2757  #include "ext4_jbd2.h"
2758  #include "ext4.h"
2759 @@ -202,6 +203,33 @@ static int uuid_is_zero(__u8 u[16])
2760         return 1;
2761  }
2762  
2763 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
2764 +{
2765 +       handle_t *handle = NULL;
2766 +       struct ext4_iloc iloc;
2767 +       int err;
2768 +
2769 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
2770 +       if (IS_ERR(handle))
2771 +               return PTR_ERR(handle);
2772 +
2773 +       if (IS_SYNC(inode))
2774 +               ext4_handle_sync(handle);
2775 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
2776 +       if (err)
2777 +               goto flags_err;
2778 +
2779 +       inode->i_flags = flags;
2780 +       inode->i_vflags = vflags;
2781 +       ext4_get_inode_flags(EXT4_I(inode));
2782 +       inode->i_ctime = ext4_current_time(inode);
2783 +
2784 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
2785 +flags_err:
2786 +       ext4_journal_stop(handle);
2787 +       return err;
2788 +}
2789 +
2790  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2791  {
2792         struct inode *inode = file_inode(filp);
2793 @@ -235,6 +263,11 @@ long ext4_ioctl(struct file *filp, unsig
2794  
2795                 flags = ext4_mask_flags(inode->i_mode, flags);
2796  
2797 +               if (IS_BARRIER(inode)) {
2798 +                       vxwprintk_task(1, "messing with the barrier.");
2799 +                       return -EACCES;
2800 +               }
2801 +
2802                 err = -EPERM;
2803                 mutex_lock(&inode->i_mutex);
2804                 /* Is it quota file? Do not allow user to mess with it */
2805 @@ -252,7 +285,9 @@ long ext4_ioctl(struct file *filp, unsig
2806                  *
2807                  * This test looks nicer. Thanks to Pauline Middelink
2808                  */
2809 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
2810 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
2811 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
2812 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
2813                         if (!capable(CAP_LINUX_IMMUTABLE))
2814                                 goto flags_out;
2815                 }
2816 diff -NurpP --minimal linux-4.4.161/fs/ext4/namei.c linux-4.4.161-vs2.3.9.8/fs/ext4/namei.c
2817 --- linux-4.4.161/fs/ext4/namei.c       2018-10-20 02:34:30.000000000 +0000
2818 +++ linux-4.4.161-vs2.3.9.8/fs/ext4/namei.c     2018-10-20 05:50:20.000000000 +0000
2819 @@ -33,6 +33,7 @@
2820  #include <linux/quotaops.h>
2821  #include <linux/buffer_head.h>
2822  #include <linux/bio.h>
2823 +#include <linux/vs_tag.h>
2824  #include "ext4.h"
2825  #include "ext4_jbd2.h"
2826  
2827 @@ -1445,6 +1446,7 @@ restart:
2828                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
2829                                                     1, &bh);
2830                         }
2831 +               dx_propagate_tag(nd, inode);
2832                 }
2833                 if ((bh = bh_use[ra_ptr++]) == NULL)
2834                         goto next;
2835 @@ -3881,6 +3883,7 @@ const struct inode_operations ext4_dir_i
2836         .get_acl        = ext4_get_acl,
2837         .set_acl        = ext4_set_acl,
2838         .fiemap         = ext4_fiemap,
2839 +       .sync_flags     = ext4_sync_flags,
2840  };
2841  
2842  const struct inode_operations ext4_special_inode_operations = {
2843 diff -NurpP --minimal linux-4.4.161/fs/ext4/super.c linux-4.4.161-vs2.3.9.8/fs/ext4/super.c
2844 --- linux-4.4.161/fs/ext4/super.c       2018-10-20 02:34:30.000000000 +0000
2845 +++ linux-4.4.161-vs2.3.9.8/fs/ext4/super.c     2018-10-20 05:50:20.000000000 +0000
2846 @@ -1166,6 +1166,7 @@ enum {
2847         Opt_dioread_nolock, Opt_dioread_lock,
2848         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
2849         Opt_max_dir_size_kb, Opt_nojournal_checksum,
2850 +       Opt_tag, Opt_notag, Opt_tagid
2851  };
2852  
2853  static const match_table_t tokens = {
2854 @@ -1251,6 +1252,9 @@ static const match_table_t tokens = {
2855         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
2856         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
2857         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
2858 +       {Opt_tag, "tag"},
2859 +       {Opt_notag, "notag"},
2860 +       {Opt_tagid, "tagid=%u"},
2861         {Opt_err, NULL},
2862  };
2863  
2864 @@ -1493,6 +1497,20 @@ static int handle_mount_opt(struct super
2865         case Opt_nolazytime:
2866                 sb->s_flags &= ~MS_LAZYTIME;
2867                 return 1;
2868 +#ifndef CONFIG_TAGGING_NONE
2869 +       case Opt_tag:
2870 +               set_opt(sb, TAGGED);
2871 +               return 1;
2872 +       case Opt_notag:
2873 +               clear_opt(sb, TAGGED);
2874 +               return 1;
2875 +#endif
2876 +#ifdef CONFIG_PROPAGATE
2877 +       case Opt_tagid:
2878 +               /* use args[0] */
2879 +               set_opt(sb, TAGGED);
2880 +               return 1;
2881 +#endif
2882         }
2883  
2884         for (m = ext4_mount_opts; m->token != Opt_err; m++)
2885 @@ -3414,6 +3432,9 @@ static int ext4_fill_super(struct super_
2886                 sb->s_iflags |= SB_I_CGROUPWB;
2887         }
2888  
2889 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
2890 +               sb->s_flags |= MS_TAGGED;
2891 +
2892         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2893                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2894  
2895 @@ -4792,6 +4813,14 @@ static int ext4_remount(struct super_blo
2896         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
2897                 ext4_abort(sb, "Abort forced by user");
2898  
2899 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
2900 +               !(sb->s_flags & MS_TAGGED)) {
2901 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
2902 +                       sb->s_id);
2903 +               err = -EINVAL;
2904 +               goto restore_opts;
2905 +       }
2906 +
2907         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2908                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2909  
2910 diff -NurpP --minimal linux-4.4.161/fs/fcntl.c linux-4.4.161-vs2.3.9.8/fs/fcntl.c
2911 --- linux-4.4.161/fs/fcntl.c    2018-10-20 02:34:30.000000000 +0000
2912 +++ linux-4.4.161-vs2.3.9.8/fs/fcntl.c  2018-10-20 04:57:21.000000000 +0000
2913 @@ -22,6 +22,7 @@
2914  #include <linux/pid_namespace.h>
2915  #include <linux/user_namespace.h>
2916  #include <linux/shmem_fs.h>
2917 +#include <linux/vs_limit.h>
2918  
2919  #include <asm/poll.h>
2920  #include <asm/siginfo.h>
2921 @@ -389,6 +390,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
2922  
2923         if (!f.file)
2924                 goto out;
2925 +       if (!vx_files_avail(1))
2926 +               goto out;
2927  
2928         if (unlikely(f.file->f_mode & FMODE_PATH)) {
2929                 if (!check_fcntl_cmd(cmd))
2930 diff -NurpP --minimal linux-4.4.161/fs/file.c linux-4.4.161-vs2.3.9.8/fs/file.c
2931 --- linux-4.4.161/fs/file.c     2016-01-10 23:01:32.000000000 +0000
2932 +++ linux-4.4.161-vs2.3.9.8/fs/file.c   2018-10-20 04:57:21.000000000 +0000
2933 @@ -22,6 +22,7 @@
2934  #include <linux/spinlock.h>
2935  #include <linux/rcupdate.h>
2936  #include <linux/workqueue.h>
2937 +#include <linux/vs_limit.h>
2938  
2939  int sysctl_nr_open __read_mostly = 1024*1024;
2940  int sysctl_nr_open_min = BITS_PER_LONG;
2941 @@ -356,6 +357,8 @@ struct files_struct *dup_fd(struct files
2942                 struct file *f = *old_fds++;
2943                 if (f) {
2944                         get_file(f);
2945 +                       /* TODO: sum it first for check and performance */
2946 +                       vx_openfd_inc(open_files - i);
2947                 } else {
2948                         /*
2949                          * The fd may be claimed in the fd bitmap but not yet
2950 @@ -405,9 +408,11 @@ static struct fdtable *close_files(struc
2951                                         filp_close(file, files);
2952                                         cond_resched_rcu_qs();
2953                                 }
2954 +                               vx_openfd_dec(i);
2955                         }
2956                         i++;
2957                         set >>= 1;
2958 +                       cond_resched();
2959                 }
2960         }
2961  
2962 @@ -538,6 +543,7 @@ repeat:
2963         else
2964                 __clear_close_on_exec(fd, fdt);
2965         error = fd;
2966 +       vx_openfd_inc(fd);
2967  #if 1
2968         /* Sanity check */
2969         if (rcu_access_pointer(fdt->fd[fd]) != NULL) {
2970 @@ -568,6 +574,7 @@ static void __put_unused_fd(struct files
2971         __clear_open_fd(fd, fdt);
2972         if (fd < files->next_fd)
2973                 files->next_fd = fd;
2974 +       vx_openfd_dec(fd);
2975  }
2976  
2977  void put_unused_fd(unsigned int fd)
2978 @@ -850,6 +857,8 @@ __releases(&files->file_lock)
2979  
2980         if (tofree)
2981                 filp_close(tofree, files);
2982 +       else
2983 +               vx_openfd_inc(fd);      /* fd was unused */
2984  
2985         return fd;
2986  
2987 diff -NurpP --minimal linux-4.4.161/fs/file_table.c linux-4.4.161-vs2.3.9.8/fs/file_table.c
2988 --- linux-4.4.161/fs/file_table.c       2016-01-10 23:01:32.000000000 +0000
2989 +++ linux-4.4.161-vs2.3.9.8/fs/file_table.c     2018-10-20 04:57:21.000000000 +0000
2990 @@ -26,6 +26,8 @@
2991  #include <linux/task_work.h>
2992  #include <linux/ima.h>
2993  #include <linux/swap.h>
2994 +#include <linux/vs_limit.h>
2995 +#include <linux/vs_context.h>
2996  
2997  #include <linux/atomic.h>
2998  
2999 @@ -137,6 +139,8 @@ struct file *get_empty_filp(void)
3000         mutex_init(&f->f_pos_lock);
3001         eventpoll_init_file(f);
3002         /* f->f_version: 0 */
3003 +       f->f_xid = vx_current_xid();
3004 +       vx_files_inc(f);
3005         return f;
3006  
3007  over:
3008 @@ -219,6 +223,8 @@ static void __fput(struct file *file)
3009                 put_write_access(inode);
3010                 __mnt_drop_write(mnt);
3011         }
3012 +       vx_files_dec(file);
3013 +       file->f_xid = 0;
3014         file->f_path.dentry = NULL;
3015         file->f_path.mnt = NULL;
3016         file->f_inode = NULL;
3017 @@ -305,6 +311,8 @@ void put_filp(struct file *file)
3018  {
3019         if (atomic_long_dec_and_test(&file->f_count)) {
3020                 security_file_free(file);
3021 +               vx_files_dec(file);
3022 +               file->f_xid = 0;
3023                 file_free(file);
3024         }
3025  }
3026 diff -NurpP --minimal linux-4.4.161/fs/fs_struct.c linux-4.4.161-vs2.3.9.8/fs/fs_struct.c
3027 --- linux-4.4.161/fs/fs_struct.c        2016-01-10 23:01:32.000000000 +0000
3028 +++ linux-4.4.161-vs2.3.9.8/fs/fs_struct.c      2018-10-20 04:57:21.000000000 +0000
3029 @@ -4,6 +4,7 @@
3030  #include <linux/path.h>
3031  #include <linux/slab.h>
3032  #include <linux/fs_struct.h>
3033 +#include <linux/vserver/global.h>
3034  #include "internal.h"
3035  
3036  /*
3037 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3038  {
3039         path_put(&fs->root);
3040         path_put(&fs->pwd);
3041 +       atomic_dec(&vs_global_fs);
3042         kmem_cache_free(fs_cachep, fs);
3043  }
3044  
3045 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3046                 fs->pwd = old->pwd;
3047                 path_get(&fs->pwd);
3048                 spin_unlock(&old->lock);
3049 +               atomic_inc(&vs_global_fs);
3050         }
3051         return fs;
3052  }
3053 diff -NurpP --minimal linux-4.4.161/fs/gfs2/file.c linux-4.4.161-vs2.3.9.8/fs/gfs2/file.c
3054 --- linux-4.4.161/fs/gfs2/file.c        2018-10-20 02:34:30.000000000 +0000
3055 +++ linux-4.4.161-vs2.3.9.8/fs/gfs2/file.c      2018-10-20 04:57:21.000000000 +0000
3056 @@ -137,6 +137,9 @@ static const u32 fsflags_to_gfs2[32] = {
3057         [12] = GFS2_DIF_EXHASH,
3058         [14] = GFS2_DIF_INHERIT_JDATA,
3059         [17] = GFS2_DIF_TOPDIR,
3060 +       [27] = GFS2_DIF_IXUNLINK,
3061 +       [26] = GFS2_DIF_BARRIER,
3062 +       [29] = GFS2_DIF_COW,
3063  };
3064  
3065  static const u32 gfs2_to_fsflags[32] = {
3066 @@ -147,6 +150,9 @@ static const u32 gfs2_to_fsflags[32] = {
3067         [gfs2fl_ExHash] = FS_INDEX_FL,
3068         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3069         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3070 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3071 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3072 +       [gfs2fl_Cow] = FS_COW_FL,
3073  };
3074  
3075  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3076 @@ -177,12 +183,17 @@ void gfs2_set_inode_flags(struct inode *
3077  {
3078         struct gfs2_inode *ip = GFS2_I(inode);
3079         unsigned int flags = inode->i_flags;
3080 +       unsigned int vflags = inode->i_vflags;
3081 +
3082 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3083 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3084  
3085 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3086         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3087                 flags |= S_NOSEC;
3088         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3089                 flags |= S_IMMUTABLE;
3090 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3091 +               flags |= S_IXUNLINK;
3092         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3093                 flags |= S_APPEND;
3094         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3095 @@ -190,6 +201,43 @@ void gfs2_set_inode_flags(struct inode *
3096         if (ip->i_diskflags & GFS2_DIF_SYNC)
3097                 flags |= S_SYNC;
3098         inode->i_flags = flags;
3099 +
3100 +       vflags &= ~(V_BARRIER | V_COW);
3101 +
3102 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3103 +               vflags |= V_BARRIER;
3104 +       if (ip->i_diskflags & GFS2_DIF_COW)
3105 +               vflags |= V_COW;
3106 +       inode->i_vflags = vflags;
3107 +}
3108 +
3109 +void gfs2_get_inode_flags(struct inode *inode)
3110 +{
3111 +       struct gfs2_inode *ip = GFS2_I(inode);
3112 +       unsigned int flags = inode->i_flags;
3113 +       unsigned int vflags = inode->i_vflags;
3114 +
3115 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3116 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3117 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3118 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3119 +
3120 +       if (flags & S_IMMUTABLE)
3121 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3122 +       if (flags & S_IXUNLINK)
3123 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3124 +
3125 +       if (flags & S_APPEND)
3126 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3127 +       if (flags & S_NOATIME)
3128 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3129 +       if (flags & S_SYNC)
3130 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3131 +
3132 +       if (vflags & V_BARRIER)
3133 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3134 +       if (vflags & V_COW)
3135 +               ip->i_diskflags |= GFS2_DIF_COW;
3136  }
3137  
3138  /* Flags that can be set by user space */
3139 @@ -305,6 +353,37 @@ static int gfs2_set_flags(struct file *f
3140         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3141  }
3142  
3143 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3144 +{
3145 +       struct gfs2_inode *ip = GFS2_I(inode);
3146 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3147 +       struct buffer_head *bh;
3148 +       struct gfs2_holder gh;
3149 +       int error;
3150 +
3151 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3152 +       if (error)
3153 +               return error;
3154 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3155 +       if (error)
3156 +               goto out;
3157 +       error = gfs2_meta_inode_buffer(ip, &bh);
3158 +       if (error)
3159 +               goto out_trans_end;
3160 +       gfs2_trans_add_meta(ip->i_gl, bh);
3161 +       inode->i_flags = flags;
3162 +       inode->i_vflags = vflags;
3163 +       gfs2_get_inode_flags(inode);
3164 +       gfs2_dinode_out(ip, bh->b_data);
3165 +       brelse(bh);
3166 +       gfs2_set_aops(inode);
3167 +out_trans_end:
3168 +       gfs2_trans_end(sdp);
3169 +out:
3170 +       gfs2_glock_dq_uninit(&gh);
3171 +       return error;
3172 +}
3173 +
3174  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3175  {
3176         switch(cmd) {
3177 diff -NurpP --minimal linux-4.4.161/fs/gfs2/inode.h linux-4.4.161-vs2.3.9.8/fs/gfs2/inode.h
3178 --- linux-4.4.161/fs/gfs2/inode.h       2016-01-10 23:01:32.000000000 +0000
3179 +++ linux-4.4.161-vs2.3.9.8/fs/gfs2/inode.h     2018-10-20 04:57:21.000000000 +0000
3180 @@ -118,6 +118,7 @@ extern const struct file_operations gfs2
3181  extern const struct file_operations gfs2_dir_fops_nolock;
3182  
3183  extern void gfs2_set_inode_flags(struct inode *inode);
3184 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3185   
3186  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3187  extern const struct file_operations gfs2_file_fops;
3188 diff -NurpP --minimal linux-4.4.161/fs/hostfs/hostfs.h linux-4.4.161-vs2.3.9.8/fs/hostfs/hostfs.h
3189 --- linux-4.4.161/fs/hostfs/hostfs.h    2016-01-10 23:01:32.000000000 +0000
3190 +++ linux-4.4.161-vs2.3.9.8/fs/hostfs/hostfs.h  2018-10-20 04:57:21.000000000 +0000
3191 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3192         unsigned short  ia_mode;
3193         uid_t           ia_uid;
3194         gid_t           ia_gid;
3195 +       vtag_t          ia_tag;
3196         loff_t          ia_size;
3197         struct timespec ia_atime;
3198         struct timespec ia_mtime;
3199 diff -NurpP --minimal linux-4.4.161/fs/inode.c linux-4.4.161-vs2.3.9.8/fs/inode.c
3200 --- linux-4.4.161/fs/inode.c    2018-10-20 02:34:30.000000000 +0000
3201 +++ linux-4.4.161-vs2.3.9.8/fs/inode.c  2018-10-20 04:57:21.000000000 +0000
3202 @@ -18,6 +18,7 @@
3203  #include <linux/buffer_head.h> /* for inode_has_buffers */
3204  #include <linux/ratelimit.h>
3205  #include <linux/list_lru.h>
3206 +#include <linux/vs_tag.h>
3207  #include <trace/events/writeback.h>
3208  #include "internal.h"
3209  
3210 @@ -133,6 +134,8 @@ int inode_init_always(struct super_block
3211         struct address_space *const mapping = &inode->i_data;
3212  
3213         inode->i_sb = sb;
3214 +
3215 +       /* essential because of inode slab reuse */
3216         inode->i_blkbits = sb->s_blocksize_bits;
3217         inode->i_flags = 0;
3218         atomic_set(&inode->i_count, 1);
3219 @@ -142,6 +145,7 @@ int inode_init_always(struct super_block
3220         inode->i_opflags = 0;
3221         i_uid_write(inode, 0);
3222         i_gid_write(inode, 0);
3223 +       i_tag_write(inode, 0);
3224         atomic_set(&inode->i_writecount, 0);
3225         inode->i_size = 0;
3226         inode->i_blocks = 0;
3227 @@ -152,6 +156,7 @@ int inode_init_always(struct super_block
3228         inode->i_cdev = NULL;
3229         inode->i_link = NULL;
3230         inode->i_rdev = 0;
3231 +       inode->i_mdev = 0;
3232         inode->dirtied_when = 0;
3233  
3234         if (security_inode_alloc(inode))
3235 @@ -469,6 +474,8 @@ void __insert_inode_hash(struct inode *i
3236  }
3237  EXPORT_SYMBOL(__insert_inode_hash);
3238  
3239 +EXPORT_SYMBOL_GPL(__iget);
3240 +
3241  /**
3242   *     __remove_inode_hash - remove an inode from the hash
3243   *     @inode: inode to unhash
3244 @@ -1911,9 +1918,11 @@ void init_special_inode(struct inode *in
3245         if (S_ISCHR(mode)) {
3246                 inode->i_fop = &def_chr_fops;
3247                 inode->i_rdev = rdev;
3248 +               inode->i_mdev = rdev;
3249         } else if (S_ISBLK(mode)) {
3250                 inode->i_fop = &def_blk_fops;
3251                 inode->i_rdev = rdev;
3252 +               inode->i_mdev = rdev;
3253         } else if (S_ISFIFO(mode))
3254                 inode->i_fop = &pipefifo_fops;
3255         else if (S_ISSOCK(mode))
3256 @@ -1948,6 +1957,7 @@ void inode_init_owner(struct inode *inod
3257         } else
3258                 inode->i_gid = current_fsgid();
3259         inode->i_mode = mode;
3260 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3261  }
3262  EXPORT_SYMBOL(inode_init_owner);
3263  
3264 diff -NurpP --minimal linux-4.4.161/fs/ioctl.c linux-4.4.161-vs2.3.9.8/fs/ioctl.c
3265 --- linux-4.4.161/fs/ioctl.c    2016-01-10 23:01:32.000000000 +0000
3266 +++ linux-4.4.161-vs2.3.9.8/fs/ioctl.c  2018-10-20 04:57:21.000000000 +0000
3267 @@ -15,6 +15,9 @@
3268  #include <linux/writeback.h>
3269  #include <linux/buffer_head.h>
3270  #include <linux/falloc.h>
3271 +#include <linux/proc_fs.h>
3272 +#include <linux/vserver/inode.h>
3273 +#include <linux/vs_tag.h>
3274  
3275  #include <asm/ioctls.h>
3276  
3277 diff -NurpP --minimal linux-4.4.161/fs/jfs/file.c linux-4.4.161-vs2.3.9.8/fs/jfs/file.c
3278 --- linux-4.4.161/fs/jfs/file.c 2016-01-10 23:01:32.000000000 +0000
3279 +++ linux-4.4.161-vs2.3.9.8/fs/jfs/file.c       2018-10-20 04:57:21.000000000 +0000
3280 @@ -113,7 +113,8 @@ int jfs_setattr(struct dentry *dentry, s
3281                         return rc;
3282         }
3283         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3284 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3285 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3286 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3287                 rc = dquot_transfer(inode, iattr);
3288                 if (rc)
3289                         return rc;
3290 @@ -149,6 +150,7 @@ const struct inode_operations jfs_file_i
3291         .get_acl        = jfs_get_acl,
3292         .set_acl        = jfs_set_acl,
3293  #endif
3294 +       .sync_flags     = jfs_sync_flags,
3295  };
3296  
3297  const struct file_operations jfs_file_operations = {
3298 diff -NurpP --minimal linux-4.4.161/fs/jfs/ioctl.c linux-4.4.161-vs2.3.9.8/fs/jfs/ioctl.c
3299 --- linux-4.4.161/fs/jfs/ioctl.c        2016-01-10 23:01:32.000000000 +0000
3300 +++ linux-4.4.161-vs2.3.9.8/fs/jfs/ioctl.c      2018-10-20 04:57:21.000000000 +0000
3301 @@ -12,6 +12,7 @@
3302  #include <linux/time.h>
3303  #include <linux/sched.h>
3304  #include <linux/blkdev.h>
3305 +#include <linux/mount.h>
3306  #include <asm/current.h>
3307  #include <asm/uaccess.h>
3308  
3309 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3310  }
3311  
3312  
3313 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3314 +{
3315 +       inode->i_flags = flags;
3316 +       inode->i_vflags = vflags;
3317 +       jfs_get_inode_flags(JFS_IP(inode));
3318 +       inode->i_ctime = CURRENT_TIME_SEC;
3319 +       mark_inode_dirty(inode);
3320 +       return 0;
3321 +}
3322 +
3323  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3324  {
3325         struct inode *inode = file_inode(filp);
3326 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3327                 if (!S_ISDIR(inode->i_mode))
3328                         flags &= ~JFS_DIRSYNC_FL;
3329  
3330 +               if (IS_BARRIER(inode)) {
3331 +                       vxwprintk_task(1, "messing with the barrier.");
3332 +                       return -EACCES;
3333 +               }
3334 +
3335                 /* Is it quota file? Do not allow user to mess with it */
3336                 if (IS_NOQUOTA(inode)) {
3337                         err = -EPERM;
3338 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3339                  * the relevant capability.
3340                  */
3341                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3342 -                       ((flags ^ oldflags) &
3343 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3344 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3345 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3346                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3347                                 mutex_unlock(&inode->i_mutex);
3348                                 err = -EPERM;
3349 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3350                         }
3351                 }
3352  
3353 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3354 +               flags &= JFS_FL_USER_MODIFIABLE;
3355                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3356                 jfs_inode->mode2 = flags;
3357  
3358 diff -NurpP --minimal linux-4.4.161/fs/jfs/jfs_dinode.h linux-4.4.161-vs2.3.9.8/fs/jfs/jfs_dinode.h
3359 --- linux-4.4.161/fs/jfs/jfs_dinode.h   2016-01-10 23:01:32.000000000 +0000
3360 +++ linux-4.4.161-vs2.3.9.8/fs/jfs/jfs_dinode.h 2018-10-20 04:57:21.000000000 +0000
3361 @@ -161,9 +161,13 @@ struct dinode {
3362  
3363  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3364  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3365 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3366  
3367 -#define JFS_FL_USER_VISIBLE    0x03F80000
3368 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3369 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3370 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3371 +
3372 +#define JFS_FL_USER_VISIBLE    0x07F80000
3373 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3374  #define JFS_FL_INHERIT         0x03C80000
3375  
3376  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3377 diff -NurpP --minimal linux-4.4.161/fs/jfs/jfs_filsys.h linux-4.4.161-vs2.3.9.8/fs/jfs/jfs_filsys.h
3378 --- linux-4.4.161/fs/jfs/jfs_filsys.h   2016-01-10 23:01:32.000000000 +0000
3379 +++ linux-4.4.161-vs2.3.9.8/fs/jfs/jfs_filsys.h 2018-10-20 04:57:21.000000000 +0000
3380 @@ -266,6 +266,7 @@
3381  #define JFS_NAME_MAX   255
3382  #define JFS_PATH_MAX   BPSIZE
3383  
3384 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3385  
3386  /*
3387   *     file system state (superblock state)
3388 diff -NurpP --minimal linux-4.4.161/fs/jfs/jfs_imap.c linux-4.4.161-vs2.3.9.8/fs/jfs/jfs_imap.c
3389 --- linux-4.4.161/fs/jfs/jfs_imap.c     2016-01-10 23:01:32.000000000 +0000
3390 +++ linux-4.4.161-vs2.3.9.8/fs/jfs/jfs_imap.c   2018-10-20 04:57:21.000000000 +0000
3391 @@ -46,6 +46,7 @@
3392  #include <linux/pagemap.h>
3393  #include <linux/quotaops.h>
3394  #include <linux/slab.h>
3395 +#include <linux/vs_tag.h>
3396  
3397  #include "jfs_incore.h"
3398  #include "jfs_inode.h"
3399 @@ -3047,6 +3048,8 @@ static int copy_from_dinode(struct dinod
3400  {
3401         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3402         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3403 +       kuid_t kuid;
3404 +       kgid_t kgid;
3405  
3406         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3407         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3408 @@ -3067,14 +3070,18 @@ static int copy_from_dinode(struct dinod
3409         }
3410         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3411  
3412 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3413 +       kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3414 +       kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3415 +       ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3416 +
3417 +       jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3418         if (!uid_valid(sbi->uid))
3419                 ip->i_uid = jfs_ip->saved_uid;
3420         else {
3421                 ip->i_uid = sbi->uid;
3422         }
3423  
3424 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3425 +       jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3426         if (!gid_valid(sbi->gid))
3427                 ip->i_gid = jfs_ip->saved_gid;
3428         else {
3429 @@ -3139,16 +3146,14 @@ static void copy_to_dinode(struct dinode
3430         dip->di_size = cpu_to_le64(ip->i_size);
3431         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3432         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3433 -       if (!uid_valid(sbi->uid))
3434 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3435 -       else
3436 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3437 -                                                  jfs_ip->saved_uid));
3438 -       if (!gid_valid(sbi->gid))
3439 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3440 -       else
3441 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3442 -                                                   jfs_ip->saved_gid));
3443 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3444 +               TAGINO_KUID(DX_TAG(ip),
3445 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3446 +               ip->i_tag)));
3447 +       dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3448 +               TAGINO_KGID(DX_TAG(ip),
3449 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3450 +               ip->i_tag)));
3451         jfs_get_inode_flags(jfs_ip);
3452         /*
3453          * mode2 is only needed for storing the higher order bits.
3454 diff -NurpP --minimal linux-4.4.161/fs/jfs/jfs_inode.c linux-4.4.161-vs2.3.9.8/fs/jfs/jfs_inode.c
3455 --- linux-4.4.161/fs/jfs/jfs_inode.c    2016-01-10 23:01:32.000000000 +0000
3456 +++ linux-4.4.161-vs2.3.9.8/fs/jfs/jfs_inode.c  2018-10-20 04:57:21.000000000 +0000
3457 @@ -18,6 +18,7 @@
3458  
3459  #include <linux/fs.h>
3460  #include <linux/quotaops.h>
3461 +#include <linux/vs_tag.h>
3462  #include "jfs_incore.h"
3463  #include "jfs_inode.h"
3464  #include "jfs_filsys.h"
3465 @@ -33,6 +34,9 @@ void jfs_set_inode_flags(struct inode *i
3466  
3467         if (flags & JFS_IMMUTABLE_FL)
3468                 new_fl |= S_IMMUTABLE;
3469 +       if (flags & JFS_IXUNLINK_FL)
3470 +               new_fl |= S_IXUNLINK;
3471 +
3472         if (flags & JFS_APPEND_FL)
3473                 new_fl |= S_APPEND;
3474         if (flags & JFS_NOATIME_FL)
3475 @@ -41,18 +45,35 @@ void jfs_set_inode_flags(struct inode *i
3476                 new_fl |= S_DIRSYNC;
3477         if (flags & JFS_SYNC_FL)
3478                 new_fl |= S_SYNC;
3479 -       inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND | S_NOATIME |
3480 -                       S_DIRSYNC | S_SYNC);
3481 +
3482 +       inode_set_flags(inode, new_fl, S_IMMUTABLE | S_IXUNLINK |
3483 +                       S_APPEND | S_NOATIME | S_DIRSYNC | S_SYNC);
3484 +
3485 +       new_fl = 0;
3486 +       if (flags & JFS_BARRIER_FL)
3487 +               new_fl |= V_BARRIER;
3488 +       if (flags & JFS_COW_FL)
3489 +               new_fl |= V_COW;
3490 +
3491 +       set_mask_bits(&inode->i_vflags,
3492 +               V_BARRIER | V_COW, new_fl);
3493  }
3494  
3495  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3496  {
3497         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3498 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3499 +
3500 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3501 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3502 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3503 +                          JFS_BARRIER_FL | JFS_COW_FL);
3504  
3505 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3506 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3507         if (flags & S_IMMUTABLE)
3508                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3509 +       if (flags & S_IXUNLINK)
3510 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3511 +
3512         if (flags & S_APPEND)
3513                 jfs_ip->mode2 |= JFS_APPEND_FL;
3514         if (flags & S_NOATIME)
3515 @@ -61,6 +82,11 @@ void jfs_get_inode_flags(struct jfs_inod
3516                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3517         if (flags & S_SYNC)
3518                 jfs_ip->mode2 |= JFS_SYNC_FL;
3519 +
3520 +       if (vflags & V_BARRIER)
3521 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3522 +       if (vflags & V_COW)
3523 +               jfs_ip->mode2 |= JFS_COW_FL;
3524  }
3525  
3526  /*
3527 diff -NurpP --minimal linux-4.4.161/fs/jfs/jfs_inode.h linux-4.4.161-vs2.3.9.8/fs/jfs/jfs_inode.h
3528 --- linux-4.4.161/fs/jfs/jfs_inode.h    2016-01-10 23:01:32.000000000 +0000
3529 +++ linux-4.4.161-vs2.3.9.8/fs/jfs/jfs_inode.h  2018-10-20 04:57:21.000000000 +0000
3530 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3531  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3532         int fh_len, int fh_type);
3533  extern void jfs_set_inode_flags(struct inode *);
3534 +extern int jfs_sync_flags(struct inode *, int, int);
3535  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3536  extern int jfs_setattr(struct dentry *, struct iattr *);
3537  
3538 diff -NurpP --minimal linux-4.4.161/fs/jfs/namei.c linux-4.4.161-vs2.3.9.8/fs/jfs/namei.c
3539 --- linux-4.4.161/fs/jfs/namei.c        2018-10-20 02:34:30.000000000 +0000
3540 +++ linux-4.4.161-vs2.3.9.8/fs/jfs/namei.c      2018-10-20 04:57:21.000000000 +0000
3541 @@ -22,6 +22,7 @@
3542  #include <linux/ctype.h>
3543  #include <linux/quotaops.h>
3544  #include <linux/exportfs.h>
3545 +#include <linux/vs_tag.h>
3546  #include "jfs_incore.h"
3547  #include "jfs_superblock.h"
3548  #include "jfs_inode.h"
3549 @@ -1476,6 +1477,7 @@ static struct dentry *jfs_lookup(struct
3550                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3551         }
3552  
3553 +       dx_propagate_tag(nd, ip);
3554         return d_splice_alias(ip, dentry);
3555  }
3556  
3557 @@ -1541,6 +1543,7 @@ const struct inode_operations jfs_dir_in
3558         .get_acl        = jfs_get_acl,
3559         .set_acl        = jfs_set_acl,
3560  #endif
3561 +       .sync_flags     = jfs_sync_flags,
3562  };
3563  
3564  const struct file_operations jfs_dir_operations = {
3565 diff -NurpP --minimal linux-4.4.161/fs/jfs/super.c linux-4.4.161-vs2.3.9.8/fs/jfs/super.c
3566 --- linux-4.4.161/fs/jfs/super.c        2018-10-20 02:34:30.000000000 +0000
3567 +++ linux-4.4.161-vs2.3.9.8/fs/jfs/super.c      2018-10-20 04:57:21.000000000 +0000
3568 @@ -206,7 +206,8 @@ enum {
3569         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3570         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3571         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3572 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
3573 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
3574 +       Opt_tag, Opt_notag, Opt_tagid
3575  };
3576  
3577  static const match_table_t tokens = {
3578 @@ -216,6 +217,10 @@ static const match_table_t tokens = {
3579         {Opt_resize, "resize=%u"},
3580         {Opt_resize_nosize, "resize"},
3581         {Opt_errors, "errors=%s"},
3582 +       {Opt_tag, "tag"},
3583 +       {Opt_notag, "notag"},
3584 +       {Opt_tagid, "tagid=%u"},
3585 +       {Opt_tag, "tagxid"},
3586         {Opt_ignore, "noquota"},
3587         {Opt_ignore, "quota"},
3588         {Opt_usrquota, "usrquota"},
3589 @@ -405,7 +410,20 @@ static int parse_options(char *options,
3590                                 pr_err("JFS: discard option not supported on device\n");
3591                         break;
3592                 }
3593 -
3594 +#ifndef CONFIG_TAGGING_NONE
3595 +               case Opt_tag:
3596 +                       *flag |= JFS_TAGGED;
3597 +                       break;
3598 +               case Opt_notag:
3599 +                       *flag &= JFS_TAGGED;
3600 +                       break;
3601 +#endif
3602 +#ifdef CONFIG_PROPAGATE
3603 +               case Opt_tagid:
3604 +                       /* use args[0] */
3605 +                       *flag |= JFS_TAGGED;
3606 +                       break;
3607 +#endif
3608                 default:
3609                         printk("jfs: Unrecognized mount option \"%s\" or missing value\n",
3610                                p);
3611 @@ -437,6 +455,12 @@ static int jfs_remount(struct super_bloc
3612         if (!parse_options(data, sb, &newLVSize, &flag))
3613                 return -EINVAL;
3614  
3615 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3616 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
3617 +                       sb->s_id);
3618 +               return -EINVAL;
3619 +       }
3620 +
3621         if (newLVSize) {
3622                 if (sb->s_flags & MS_RDONLY) {
3623                         pr_err("JFS: resize requires volume to be mounted read-write\n");
3624 @@ -517,6 +541,9 @@ static int jfs_fill_super(struct super_b
3625  #ifdef CONFIG_JFS_POSIX_ACL
3626         sb->s_flags |= MS_POSIXACL;
3627  #endif
3628 +       /* map mount option tagxid */
3629 +       if (sbi->flag & JFS_TAGGED)
3630 +               sb->s_flags |= MS_TAGGED;
3631  
3632         if (newLVSize) {
3633                 pr_err("resize option for remount only\n");
3634 diff -NurpP --minimal linux-4.4.161/fs/libfs.c linux-4.4.161-vs2.3.9.8/fs/libfs.c
3635 --- linux-4.4.161/fs/libfs.c    2016-01-10 23:01:32.000000000 +0000
3636 +++ linux-4.4.161-vs2.3.9.8/fs/libfs.c  2018-10-20 04:57:21.000000000 +0000
3637 @@ -141,13 +141,14 @@ static inline unsigned char dt_type(stru
3638   * both impossible due to the lock on directory.
3639   */
3640  
3641 -int dcache_readdir(struct file *file, struct dir_context *ctx)
3642 +static inline int do_dcache_readdir_filter(struct file *filp,
3643 +       struct dir_context *ctx, int (*filter)(struct dentry *dentry))
3644  {
3645 -       struct dentry *dentry = file->f_path.dentry;
3646 -       struct dentry *cursor = file->private_data;
3647 +       struct dentry *dentry = filp->f_path.dentry;
3648 +       struct dentry *cursor = filp->private_data;
3649         struct list_head *p, *q = &cursor->d_child;
3650  
3651 -       if (!dir_emit_dots(file, ctx))
3652 +       if (!dir_emit_dots(filp, ctx))
3653                 return 0;
3654         spin_lock(&dentry->d_lock);
3655         if (ctx->pos == 2)
3656 @@ -155,6 +156,8 @@ int dcache_readdir(struct file *file, st
3657  
3658         for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
3659                 struct dentry *next = list_entry(p, struct dentry, d_child);
3660 +               if (filter && !filter(next))
3661 +                       continue;
3662                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
3663                 if (!simple_positive(next)) {
3664                         spin_unlock(&next->d_lock);
3665 @@ -177,8 +180,22 @@ int dcache_readdir(struct file *file, st
3666         spin_unlock(&dentry->d_lock);
3667         return 0;
3668  }
3669 +
3670  EXPORT_SYMBOL(dcache_readdir);
3671  
3672 +int dcache_readdir(struct file *filp, struct dir_context *ctx)
3673 +{
3674 +       return do_dcache_readdir_filter(filp, ctx, NULL);
3675 +}
3676 +
3677 +EXPORT_SYMBOL(dcache_readdir_filter);
3678 +
3679 +int dcache_readdir_filter(struct file *filp, struct dir_context *ctx,
3680 +       int (*filter)(struct dentry *))
3681 +{
3682 +       return do_dcache_readdir_filter(filp, ctx, filter);
3683 +}
3684 +
3685  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
3686  {
3687         return -EISDIR;
3688 diff -NurpP --minimal linux-4.4.161/fs/locks.c linux-4.4.161-vs2.3.9.8/fs/locks.c
3689 --- linux-4.4.161/fs/locks.c    2018-10-20 02:34:30.000000000 +0000
3690 +++ linux-4.4.161-vs2.3.9.8/fs/locks.c  2018-10-20 04:57:21.000000000 +0000
3691 @@ -129,6 +129,8 @@
3692  #include <linux/hashtable.h>
3693  #include <linux/percpu.h>
3694  #include <linux/lglock.h>
3695 +#include <linux/vs_base.h>
3696 +#include <linux/vs_limit.h>
3697  
3698  #define CREATE_TRACE_POINTS
3699  #include <trace/events/filelock.h>
3700 @@ -255,11 +257,15 @@ static void locks_init_lock_heads(struct
3701  /* Allocate an empty lock structure. */
3702  struct file_lock *locks_alloc_lock(void)
3703  {
3704 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
3705 +       struct file_lock *fl;
3706  
3707 -       if (fl)
3708 -               locks_init_lock_heads(fl);
3709 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
3710  
3711 +       if (fl) {
3712 +               locks_init_lock_heads(fl);
3713 +               vx_locks_inc(fl);
3714 +               fl->fl_xid = -1;
3715 +       }
3716         return fl;
3717  }
3718  EXPORT_SYMBOL_GPL(locks_alloc_lock);
3719 @@ -311,6 +317,7 @@ void locks_init_lock(struct file_lock *f
3720  {
3721         memset(fl, 0, sizeof(struct file_lock));
3722         locks_init_lock_heads(fl);
3723 +       fl->fl_xid = -1;
3724  }
3725  
3726  EXPORT_SYMBOL(locks_init_lock);
3727 @@ -328,6 +335,7 @@ void locks_copy_conflock(struct file_loc
3728         new->fl_start = fl->fl_start;
3729         new->fl_end = fl->fl_end;
3730         new->fl_lmops = fl->fl_lmops;
3731 +       new->fl_xid = fl->fl_xid;
3732         new->fl_ops = NULL;
3733  
3734         if (fl->fl_lmops) {
3735 @@ -389,7 +397,10 @@ flock_make_lock(struct file *filp, unsig
3736         fl->fl_flags = FL_FLOCK;
3737         fl->fl_type = type;
3738         fl->fl_end = OFFSET_MAX;
3739 -       
3740 +
3741 +       vxd_assert(filp->f_xid == vx_current_xid(),
3742 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
3743 +       fl->fl_xid = filp->f_xid;
3744         return fl;
3745  }
3746  
3747 @@ -511,6 +522,7 @@ static int lease_init(struct file *filp,
3748  
3749         fl->fl_owner = filp;
3750         fl->fl_pid = current->tgid;
3751 +       fl->fl_xid = vx_current_xid();
3752  
3753         fl->fl_file = filp;
3754         fl->fl_flags = FL_LEASE;
3755 @@ -530,6 +542,10 @@ static struct file_lock *lease_alloc(str
3756         if (fl == NULL)
3757                 return ERR_PTR(error);
3758  
3759 +       fl->fl_xid = vx_current_xid();
3760 +       if (filp)
3761 +               vxd_assert(filp->f_xid == fl->fl_xid,
3762 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
3763         error = lease_init(filp, type, fl);
3764         if (error) {
3765                 locks_free_lock(fl);
3766 @@ -908,6 +924,7 @@ static int flock_lock_inode(struct inode
3767                 goto out;
3768         }
3769  
3770 +       new_fl->fl_xid = -1;
3771  find_conflict:
3772         list_for_each_entry(fl, &ctx->flc_flock, fl_list) {
3773                 if (!flock_locks_conflict(request, fl))
3774 @@ -934,7 +951,8 @@ out:
3775         return error;
3776  }
3777  
3778 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
3779 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
3780 +       struct file_lock *conflock, vxid_t xid)
3781  {
3782         struct file_lock *fl, *tmp;
3783         struct file_lock *new_fl = NULL;
3784 @@ -950,6 +968,9 @@ static int __posix_lock_file(struct inod
3785         if (!ctx)
3786                 return (request->fl_type == F_UNLCK) ? 0 : -ENOMEM;
3787  
3788 +       if (xid)
3789 +               vxd_assert(xid == vx_current_xid(),
3790 +                       "xid(%d) == current(%d)", xid, vx_current_xid());
3791         /*
3792          * We may need two file_lock structures for this operation,
3793          * so we get them in advance to avoid races.
3794 @@ -960,7 +981,11 @@ static int __posix_lock_file(struct inod
3795             (request->fl_type != F_UNLCK ||
3796              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
3797                 new_fl = locks_alloc_lock();
3798 +               new_fl->fl_xid = xid;
3799 +               // vx_locks_inc(new_fl);
3800                 new_fl2 = locks_alloc_lock();
3801 +               new_fl2->fl_xid = xid;
3802 +               // vx_locks_inc(new_fl2);
3803         }
3804  
3805         spin_lock(&ctx->flc_lock);
3806 @@ -1162,7 +1187,8 @@ static int __posix_lock_file(struct inod
3807  int posix_lock_file(struct file *filp, struct file_lock *fl,
3808                         struct file_lock *conflock)
3809  {
3810 -       return __posix_lock_file(file_inode(filp), fl, conflock);
3811 +       return __posix_lock_file(file_inode(filp),
3812 +               fl, conflock, filp->f_xid);
3813  }
3814  EXPORT_SYMBOL(posix_lock_file);
3815  
3816 @@ -1178,7 +1204,7 @@ static int posix_lock_inode_wait(struct
3817         int error;
3818         might_sleep ();
3819         for (;;) {
3820 -               error = __posix_lock_file(inode, fl, NULL);
3821 +               error = __posix_lock_file(inode, fl, NULL, 0);
3822                 if (error != FILE_LOCK_DEFERRED)
3823                         break;
3824                 error = wait_event_interruptible(fl->fl_wait, !fl->fl_next);
3825 @@ -1257,10 +1283,13 @@ int locks_mandatory_area(int read_write,
3826         fl.fl_end = offset + count - 1;
3827  
3828         for (;;) {
3829 +               vxid_t f_xid = 0;
3830 +
3831                 if (filp) {
3832                         fl.fl_owner = filp;
3833                         fl.fl_flags &= ~FL_SLEEP;
3834 -                       error = __posix_lock_file(inode, &fl, NULL);
3835 +                       f_xid = filp->f_xid;
3836 +                       error = __posix_lock_file(inode, &fl, NULL, f_xid);
3837                         if (!error)
3838                                 break;
3839                 }
3840 @@ -1268,7 +1297,7 @@ int locks_mandatory_area(int read_write,
3841                 if (sleep)
3842                         fl.fl_flags |= FL_SLEEP;
3843                 fl.fl_owner = current->files;
3844 -               error = __posix_lock_file(inode, &fl, NULL);
3845 +               error = __posix_lock_file(inode, &fl, NULL, f_xid);
3846                 if (error != FILE_LOCK_DEFERRED)
3847                         break;
3848                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
3849 @@ -2165,6 +2194,11 @@ int fcntl_setlk(unsigned int fd, struct
3850         if (file_lock == NULL)
3851                 return -ENOLCK;
3852  
3853 +       vxd_assert(filp->f_xid == vx_current_xid(),
3854 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
3855 +       file_lock->fl_xid = filp->f_xid;
3856 +       // vx_locks_inc(file_lock);
3857 +
3858         /*
3859          * This might block, so we do it before checking the inode.
3860          */
3861 @@ -2309,6 +2343,11 @@ int fcntl_setlk64(unsigned int fd, struc
3862         if (file_lock == NULL)
3863                 return -ENOLCK;
3864  
3865 +       vxd_assert(filp->f_xid == vx_current_xid(),
3866 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
3867 +       file_lock->fl_xid = filp->f_xid;
3868 +       // vx_locks_inc(file_lock);
3869 +
3870         /*
3871          * This might block, so we do it before checking the inode.
3872          */
3873 @@ -2624,8 +2663,11 @@ static int locks_show(struct seq_file *f
3874  
3875         lock_get_status(f, fl, iter->li_pos, "");
3876  
3877 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
3878 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
3879 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
3880 +                       continue;
3881                 lock_get_status(f, bfl, iter->li_pos, " ->");
3882 +       }
3883  
3884         return 0;
3885  }
3886 diff -NurpP --minimal linux-4.4.161/fs/mount.h linux-4.4.161-vs2.3.9.8/fs/mount.h
3887 --- linux-4.4.161/fs/mount.h    2018-10-20 02:34:30.000000000 +0000
3888 +++ linux-4.4.161-vs2.3.9.8/fs/mount.h  2018-10-20 04:57:21.000000000 +0000
3889 @@ -68,6 +68,7 @@ struct mount {
3890         struct hlist_head mnt_pins;
3891         struct fs_pin mnt_umount;
3892         struct dentry *mnt_ex_mountpoint;
3893 +       vtag_t mnt_tag;                 /* tagging used for vfsmount */
3894  };
3895  
3896  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
3897 diff -NurpP --minimal linux-4.4.161/fs/namei.c linux-4.4.161-vs2.3.9.8/fs/namei.c
3898 --- linux-4.4.161/fs/namei.c    2018-10-20 02:34:30.000000000 +0000
3899 +++ linux-4.4.161-vs2.3.9.8/fs/namei.c  2018-10-20 04:57:21.000000000 +0000
3900 @@ -34,10 +34,20 @@
3901  #include <linux/device_cgroup.h>
3902  #include <linux/fs_struct.h>
3903  #include <linux/posix_acl.h>
3904 +#include <linux/proc_fs.h>
3905 +#include <linux/magic.h>
3906 +#include <linux/vserver/inode.h>
3907 +#include <linux/vs_base.h>
3908 +#include <linux/vs_tag.h>
3909 +#include <linux/vs_cowbl.h>
3910 +#include <linux/vs_device.h>
3911 +#include <linux/vs_context.h>
3912 +#include <linux/pid_namespace.h>
3913  #include <linux/hash.h>
3914  #include <asm/uaccess.h>
3915  
3916  #include "internal.h"
3917 +#include "proc/internal.h"
3918  #include "mount.h"
3919  
3920  /* [Feb-1997 T. Schoebel-Theuer]
3921 @@ -284,6 +294,93 @@ static int check_acl(struct inode *inode
3922         return -EAGAIN;
3923  }
3924  
3925 +static inline int dx_barrier(const struct inode *inode)
3926 +{
3927 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
3928 +               vxwprintk_task(1, "did hit the barrier.");
3929 +               return 1;
3930 +       }
3931 +       return 0;
3932 +}
3933 +
3934 +static int __dx_permission(const struct inode *inode, int mask)
3935 +{
3936 +       if (dx_barrier(inode))
3937 +               return -EACCES;
3938 +
3939 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
3940 +               /* devpts is xid tagged */
3941 +               if (S_ISDIR(inode->i_mode) ||
3942 +                   vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
3943 +                       return 0;
3944 +
3945 +               /* just pretend we didn't find anything */
3946 +               return -ENOENT;
3947 +       }
3948 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
3949 +               struct proc_dir_entry *de = PDE(inode);
3950 +
3951 +               if (de && !vx_hide_check(0, de->vx_flags)) {
3952 +                       vxdprintk(VXD_CBIT(misc, 9),
3953 +                               VS_Q("%*s") " hidden by _dx_permission",
3954 +                               de->namelen, de->name);
3955 +                       goto out;
3956 +               }
3957 +
3958 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
3959 +                       struct pid *pid;
3960 +                       struct task_struct *tsk;
3961 +
3962 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
3963 +                           vx_flags(VXF_STATE_SETUP, 0))
3964 +                               return 0;
3965 +
3966 +                       pid = PROC_I(inode)->pid;
3967 +                       if (!pid)
3968 +                               goto out;
3969 +
3970 +                       rcu_read_lock();
3971 +                       tsk = pid_task(pid, PIDTYPE_PID);
3972 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
3973 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
3974 +                       if (tsk &&
3975 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
3976 +                               rcu_read_unlock();
3977 +                               return 0;
3978 +                       }
3979 +                       rcu_read_unlock();
3980 +               }
3981 +               else {
3982 +                       /* FIXME: Should we block some entries here? */
3983 +                       return 0;
3984 +               }
3985 +       }
3986 +       else {
3987 +               if (dx_notagcheck(inode->i_sb) ||
3988 +                   dx_check((vxid_t)i_tag_read(inode),
3989 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
3990 +                       return 0;
3991 +       }
3992 +
3993 +out:
3994 +       return -EACCES;
3995 +}
3996 +
3997 +int dx_permission(const struct inode *inode, int mask)
3998 +{
3999 +       int ret = __dx_permission(inode, mask);
4000 +       if (unlikely(ret)) {
4001 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4002 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4003 +#endif
4004 +                   vxwprintk_task(1,
4005 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4006 +                       mask, inode->i_sb->s_id, inode,
4007 +                       i_tag_read(inode), inode->i_ino);
4008 +       }
4009 +       return ret;
4010 +}
4011 +
4012  /*
4013   * This does the basic permission checking
4014   */
4015 @@ -408,10 +505,14 @@ int __inode_permission(struct inode *ino
4016                 /*
4017                  * Nobody gets write access to an immutable file.
4018                  */
4019 -               if (IS_IMMUTABLE(inode))
4020 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4021                         return -EACCES;
4022         }
4023  
4024 +       retval = dx_permission(inode, mask);
4025 +       if (retval)
4026 +               return retval;
4027 +
4028         retval = do_inode_permission(inode, mask);
4029         if (retval)
4030                 return retval;
4031 @@ -1585,6 +1686,9 @@ static int lookup_fast(struct nameidata
4032                  */
4033                 if (negative)
4034                         return -ENOENT;
4035 +
4036 +               /* FIXME: check dx permission */
4037 +
4038                 path->mnt = mnt;
4039                 path->dentry = dentry;
4040                 if (likely(__follow_mount_rcu(nd, path, inode, seqp)))
4041 @@ -1615,6 +1719,8 @@ unlazy:
4042                 dput(dentry);
4043                 return -ENOENT;
4044         }
4045 +
4046 +       /* FIXME: check dx permission */
4047         path->mnt = mnt;
4048         path->dentry = dentry;
4049         err = follow_managed(path, nd);
4050 @@ -2576,7 +2682,7 @@ static int may_delete(struct inode *dir,
4051                 return -EPERM;
4052  
4053         if (check_sticky(dir, inode) || IS_APPEND(inode) ||
4054 -           IS_IMMUTABLE(inode) || IS_SWAPFILE(inode))
4055 +               IS_IXORUNLINK(inode) || IS_SWAPFILE(inode))
4056                 return -EPERM;
4057         if (isdir) {
4058                 if (!d_is_dir(victim))
4059 @@ -2658,19 +2764,25 @@ int vfs_create(struct inode *dir, struct
4060                 bool want_excl)
4061  {
4062         int error = may_create(dir, dentry);
4063 -       if (error)
4064 +       if (error) {
4065 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4066                 return error;
4067 +       }
4068  
4069         if (!dir->i_op->create)
4070                 return -EACCES; /* shouldn't it be ENOSYS? */
4071         mode &= S_IALLUGO;
4072         mode |= S_IFREG;
4073         error = security_inode_create(dir, dentry, mode);
4074 -       if (error)
4075 +       if (error) {
4076 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4077                 return error;
4078 +       }
4079         error = dir->i_op->create(dir, dentry, mode, want_excl);
4080         if (!error)
4081                 fsnotify_create(dir, dentry);
4082 +       else
4083 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4084         return error;
4085  }
4086  EXPORT_SYMBOL(vfs_create);
4087 @@ -2706,6 +2818,15 @@ static int may_open(struct path *path, i
4088                 break;
4089         }
4090  
4091 +#ifdef CONFIG_VSERVER_COWBL
4092 +       if (IS_COW(inode) &&
4093 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4094 +               if (IS_COW_LINK(inode))
4095 +                       return -EMLINK;
4096 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4097 +               mark_inode_dirty(inode);
4098 +       }
4099 +#endif
4100         error = inode_permission(inode, acc_mode);
4101         if (error)
4102                 return error;
4103 @@ -3183,6 +3304,16 @@ finish_open:
4104         }
4105  finish_open_created:
4106         error = may_open(&nd->path, acc_mode, open_flag);
4107 +#ifdef CONFIG_VSERVER_COWBL
4108 +       if (error == -EMLINK) {
4109 +               struct dentry *dentry;
4110 +               dentry = cow_break_link(nd->name->name);
4111 +               if (IS_ERR(dentry))
4112 +                       error = PTR_ERR(dentry);
4113 +               else
4114 +                       dput(dentry);
4115 +       }
4116 +#endif
4117         if (error)
4118                 goto out;
4119  
4120 @@ -3307,6 +3438,9 @@ static struct file *path_openat(struct n
4121         int opened = 0;
4122         int error;
4123  
4124 +#ifdef CONFIG_VSERVER_COWBL
4125 +restart:
4126 +#endif
4127         file = get_empty_filp();
4128         if (IS_ERR(file))
4129                 return file;
4130 @@ -3333,6 +3467,12 @@ static struct file *path_openat(struct n
4131                 }
4132         }
4133         terminate_walk(nd);
4134 +#ifdef CONFIG_VSERVER_COWBL
4135 +       if (error == -EMLINK) {
4136 +               // path_cleanup(nd);
4137 +               goto restart;
4138 +       }
4139 +#endif
4140  out2:
4141         if (!(opened & FILE_OPENED)) {
4142                 BUG_ON(!error);
4143 @@ -3453,6 +3593,11 @@ static struct dentry *filename_create(in
4144                 goto fail;
4145         }
4146         putname(name);
4147 +       vxdprintk(VXD_CBIT(misc, 3), "filename_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4148 +               path->dentry, path->dentry->d_name.len,
4149 +               path->dentry->d_name.name, dentry,
4150 +               dentry->d_name.len, dentry->d_name.name,
4151 +               path->dentry->d_inode);
4152         return dentry;
4153  fail:
4154         dput(dentry);
4155 @@ -3569,6 +3714,7 @@ retry:
4156                         error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
4157                         break;
4158         }
4159 +
4160  out:
4161         done_path_create(&path, dentry);
4162         if (retry_estale(error, lookup_flags)) {
4163 @@ -4015,7 +4161,7 @@ int vfs_link(struct dentry *old_dentry,
4164         /*
4165          * A link to an append-only or immutable file cannot be created.
4166          */
4167 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4168 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4169                 return -EPERM;
4170         if (!dir->i_op->link)
4171                 return -EPERM;
4172 @@ -4524,6 +4670,330 @@ int generic_readlink(struct dentry *dent
4173  }
4174  EXPORT_SYMBOL(generic_readlink);
4175  
4176 +
4177 +#ifdef CONFIG_VSERVER_COWBL
4178 +
4179 +static inline
4180 +void dump_path(const char *name, struct path *path)
4181 +{
4182 +       vxdprintk(VXD_CBIT(misc, 3),
4183 +               "%s: path=%p mnt=%p dentry=%p", name, path,
4184 +               path ? path->mnt : NULL,
4185 +               path ? path->dentry : NULL);
4186 +
4187 +       if (path && path->mnt)
4188 +               vxdprintk(VXD_CBIT(misc, 3),
4189 +               "%s: path mnt_sb=%p[#%d,#%d] mnt_root=%p[#%d]", name,
4190 +               path->mnt->mnt_sb,
4191 +               path->mnt->mnt_sb ? path->mnt->mnt_sb->s_count : -1,
4192 +               path->mnt->mnt_sb ? atomic_read(&path->mnt->mnt_sb->s_active) : -1,
4193 +               path->mnt->mnt_root,
4194 +               path->mnt->mnt_root ? path->mnt->mnt_root->d_lockref.count : -1);
4195 +
4196 +       if (path && path->dentry)
4197 +               vxdprintk(VXD_CBIT(misc, 3),
4198 +               "%s: path dentry=%p[#%d]", name,
4199 +               path->dentry,
4200 +               path->dentry ? path->dentry->d_lockref.count : -1);
4201 +}
4202 +
4203 +static inline
4204 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4205 +{
4206 +       loff_t ppos = 0;
4207 +       loff_t opos = 0;
4208 +
4209 +       return do_splice_direct(in, &ppos, out, &opos, len, 0);
4210 +}
4211 +
4212 +struct dentry *cow_break_link(const char *pathname)
4213 +{
4214 +       int ret, mode, pathlen, redo = 0, drop = 1;
4215 +       struct path old_path = {}, par_path = {}, dir_path = {}, *new_path = NULL;
4216 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4217 +       struct file *old_file;
4218 +       struct file *new_file;
4219 +       struct qstr new_qstr;
4220 +       int new_type;
4221 +       char *to, *path, pad='\251';
4222 +       loff_t size;
4223 +       struct filename *filename = getname_kernel(pathname);
4224 +       struct filename *to_filename;
4225 +
4226 +       vxdprintk(VXD_CBIT(misc, 1),
4227 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4228 +
4229 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4230 +       ret = -ENOMEM;
4231 +       if (!path || IS_ERR(filename))
4232 +               goto out;
4233 +
4234 +       /* old_path will have refs to dentry and mnt */
4235 +       ret = filename_lookup(AT_FDCWD, filename, LOOKUP_FOLLOW, &old_path, NULL);
4236 +       vxdprintk(VXD_CBIT(misc, 2),
4237 +               "do_path_lookup(old): %d", ret);
4238 +       if (ret < 0)
4239 +               goto out_free_path;
4240 +
4241 +       dump_path("cow (old)", &old_path);
4242 +
4243 +       /* no explicit reference for old_dentry here */
4244 +       old_dentry = old_path.dentry;
4245 +
4246 +       /* speculative put */
4247 +       // dput(old_dentry);
4248 +
4249 +       mode = old_dentry->d_inode->i_mode;
4250 +       to = d_path(&old_path, path, PATH_MAX-2);
4251 +       pathlen = strlen(to);
4252 +       vxdprintk(VXD_CBIT(misc, 2),
4253 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4254 +               old_dentry,
4255 +               old_dentry->d_name.len, old_dentry->d_name.name,
4256 +               old_dentry->d_name.len);
4257 +
4258 +       to[pathlen + 1] = 0;
4259 +retry:
4260 +       new_dentry = NULL;
4261 +       to[pathlen] = pad--;
4262 +       ret = -ELOOP;
4263 +       if (pad <= '\240')
4264 +               goto out_rel_old;
4265 +
4266 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4267 +
4268 +       /* dir_path will have refs to dentry and mnt */
4269 +       to_filename = getname_kernel(to);
4270 +       to_filename = filename_parentat(AT_FDCWD, to_filename,
4271 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &par_path, &new_qstr, &new_type);
4272 +       vxdprintk(VXD_CBIT(misc, 2), "filename_parentat(new): %p", to_filename);
4273 +       dump_path("cow (par)", &par_path);
4274 +       if (IS_ERR(to_filename))
4275 +               goto retry;
4276 +
4277 +       vxdprintk(VXD_CBIT(misc, 2), "to_filename refcnt=%d", to_filename->refcnt);
4278 +       // putname(to_filename);
4279 +
4280 +       /* this puppy downs the dir inode mutex if successful.
4281 +          dir_path will hold refs to dentry and mnt and
4282 +          we'll have write access to the mnt */
4283 +       new_dentry = filename_create(AT_FDCWD, to_filename, &dir_path, 0);
4284 +       if (!new_dentry || IS_ERR(new_dentry)) {
4285 +               path_put(&par_path);
4286 +               vxdprintk(VXD_CBIT(misc, 2),
4287 +                       "filename_create(new) failed with %ld",
4288 +                       PTR_ERR(new_dentry));
4289 +               goto retry;
4290 +       }
4291 +       vxdprintk(VXD_CBIT(misc, 2),
4292 +               "filename_create(new): %p [" VS_Q("%.*s") ":%d]",
4293 +               new_dentry,
4294 +               new_dentry->d_name.len, new_dentry->d_name.name,
4295 +               new_dentry->d_name.len);
4296 +
4297 +       dump_path("cow (dir)", &dir_path);
4298 +
4299 +       /* take a reference on new_dentry */
4300 +       dget(new_dentry);
4301 +
4302 +       /* dentry/mnt refs handed over to new_path */
4303 +       new_path = &dir_path;
4304 +
4305 +       /* dentry for old/new dir */
4306 +       dir = par_path.dentry;
4307 +
4308 +       /* give up reference on dir */
4309 +       dput(new_path->dentry);
4310 +
4311 +       /* new_dentry already has a reference */
4312 +       new_path->dentry = new_dentry;
4313 +
4314 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4315 +       vxdprintk(VXD_CBIT(misc, 2),
4316 +               "vfs_create(new): %d", ret);
4317 +       if (ret == -EEXIST) {
4318 +               path_put(&par_path);
4319 +               mutex_unlock(&dir->d_inode->i_mutex);
4320 +               mnt_drop_write(new_path->mnt);
4321 +               path_put(new_path);
4322 +               new_dentry = NULL;
4323 +               goto retry;
4324 +       }
4325 +       else if (ret < 0)
4326 +               goto out_unlock_new;
4327 +
4328 +       /* the old file went away */
4329 +       ret = -ENOENT;
4330 +       if ((redo = d_unhashed(old_dentry)))
4331 +               goto out_unlock_new;
4332 +
4333 +       /* doesn't change refs for old_path */
4334 +       old_file = dentry_open(&old_path, O_RDONLY, current_cred());
4335 +       vxdprintk(VXD_CBIT(misc, 2),
4336 +               "dentry_open(old): %p", old_file);
4337 +       if (IS_ERR(old_file)) {
4338 +               ret = PTR_ERR(old_file);
4339 +               goto out_unlock_new;
4340 +       }
4341 +
4342 +       /* doesn't change refs for new_path */
4343 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4344 +       vxdprintk(VXD_CBIT(misc, 2),
4345 +               "dentry_open(new): %p", new_file);
4346 +       if (IS_ERR(new_file)) {
4347 +               ret = PTR_ERR(new_file);
4348 +               goto out_fput_old;
4349 +       }
4350 +
4351 +       /* unlock the inode mutex from filename_create() */
4352 +       mutex_unlock(&dir->d_inode->i_mutex);
4353 +
4354 +       /* drop write access to mnt */
4355 +       mnt_drop_write(new_path->mnt);
4356 +
4357 +       drop = 0;
4358 +
4359 +       size = i_size_read(old_file->f_path.dentry->d_inode);
4360 +       ret = do_cow_splice(old_file, new_file, size);
4361 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4362 +       if (ret < 0) {
4363 +               goto out_fput_both;
4364 +       } else if (ret < size) {
4365 +               ret = -ENOSPC;
4366 +               goto out_fput_both;
4367 +       } else {
4368 +               struct inode *old_inode = old_dentry->d_inode;
4369 +               struct inode *new_inode = new_dentry->d_inode;
4370 +               struct iattr attr = {
4371 +                       .ia_uid = old_inode->i_uid,
4372 +                       .ia_gid = old_inode->i_gid,
4373 +                       .ia_valid = ATTR_UID | ATTR_GID
4374 +                       };
4375 +
4376 +               setattr_copy(new_inode, &attr);
4377 +               mark_inode_dirty(new_inode);
4378 +       }
4379 +
4380 +       /* lock rename mutex */
4381 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4382 +
4383 +       /* drop out late */
4384 +       ret = -ENOENT;
4385 +       if ((redo = d_unhashed(old_dentry)))
4386 +               goto out_unlock;
4387 +
4388 +       vxdprintk(VXD_CBIT(misc, 2),
4389 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4390 +               new_dentry->d_name.len, new_dentry->d_name.name,
4391 +               new_dentry->d_name.len,
4392 +               old_dentry->d_name.len, old_dentry->d_name.name,
4393 +               old_dentry->d_name.len);
4394 +       ret = vfs_rename(par_path.dentry->d_inode, new_dentry,
4395 +               old_dentry->d_parent->d_inode, old_dentry, NULL, 0);
4396 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4397 +
4398 +out_unlock:
4399 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4400 +
4401 +out_fput_both:
4402 +       vxdprintk(VXD_CBIT(misc, 3),
4403 +               "fput(new_file=%p[#%ld])", new_file,
4404 +               atomic_long_read(&new_file->f_count));
4405 +       fput(new_file);
4406 +
4407 +out_fput_old:
4408 +       vxdprintk(VXD_CBIT(misc, 3),
4409 +               "fput(old_file=%p[#%ld])", old_file,
4410 +               atomic_long_read(&old_file->f_count));
4411 +       fput(old_file);
4412 +
4413 +out_unlock_new:
4414 +       /* drop references from par_path */
4415 +       path_put(&par_path);
4416 +
4417 +       if (drop) {
4418 +               /* unlock the inode mutex from filename_create() */
4419 +               mutex_unlock(&dir->d_inode->i_mutex);
4420 +
4421 +               /* drop write access to mnt */
4422 +               mnt_drop_write(new_path->mnt);
4423 +       }
4424 +
4425 +       if (!ret)
4426 +               goto out_redo;
4427 +
4428 +       /* error path cleanup */
4429 +       vfs_unlink(dir->d_inode, new_dentry, NULL);
4430 +
4431 +out_redo:
4432 +       if (!redo)
4433 +               goto out_rel_both;
4434 +
4435 +       /* lookup dentry once again
4436 +          old_path will be freed as old_path in out_rel_old */
4437 +       ret = filename_lookup(AT_FDCWD, filename, LOOKUP_FOLLOW, &old_path, NULL);
4438 +       if (ret)
4439 +               goto out_rel_both;
4440 +
4441 +       /* drop reference on new_dentry */
4442 +       dput(new_dentry);
4443 +       new_dentry = old_path.dentry;
4444 +       dget(new_dentry);
4445 +       vxdprintk(VXD_CBIT(misc, 2),
4446 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4447 +               new_dentry,
4448 +               new_dentry->d_name.len, new_dentry->d_name.name,
4449 +               new_dentry->d_name.len);
4450 +
4451 +out_rel_both:
4452 +       dump_path("put (new)", new_path);
4453 +       if (new_path)
4454 +               path_put(new_path);
4455 +out_rel_old:
4456 +       dump_path("put (old)", &old_path);
4457 +       path_put(&old_path);
4458 +out_free_path:
4459 +       kfree(path);
4460 +out:
4461 +       if (ret) {
4462 +               dput(new_dentry);
4463 +               new_dentry = ERR_PTR(ret);
4464 +       }
4465 +       // if (!IS_ERR(filename))
4466 +       //        putname(filename);
4467 +       vxdprintk(VXD_CBIT(misc, 3),
4468 +               "cow_break_link returning with %p", new_dentry);
4469 +       return new_dentry;
4470 +}
4471 +
4472 +#endif
4473 +
4474 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4475 +{
4476 +       struct path path;
4477 +       struct vfsmount *vmnt;
4478 +       char *pstr, *root;
4479 +       int length = 0;
4480 +
4481 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4482 +       if (!pstr)
4483 +               return 0;
4484 +
4485 +       vmnt = &ns->root->mnt;
4486 +       path.mnt = vmnt;
4487 +       path.dentry = vmnt->mnt_root;
4488 +       root = d_path(&path, pstr, PATH_MAX - 2);
4489 +       length = sprintf(buffer + length,
4490 +               "Namespace:\t%p [#%u]\n"
4491 +               "RootPath:\t%s\n",
4492 +               ns, atomic_read(&ns->count),
4493 +               root);
4494 +       kfree(pstr);
4495 +       return length;
4496 +}
4497 +
4498 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4499 +
4500  /* get the link contents into pagecache */
4501  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4502  {
4503 diff -NurpP --minimal linux-4.4.161/fs/namespace.c linux-4.4.161-vs2.3.9.8/fs/namespace.c
4504 --- linux-4.4.161/fs/namespace.c        2018-10-20 02:34:30.000000000 +0000
4505 +++ linux-4.4.161-vs2.3.9.8/fs/namespace.c      2018-10-20 05:50:20.000000000 +0000
4506 @@ -24,6 +24,11 @@
4507  #include <linux/magic.h>
4508  #include <linux/bootmem.h>
4509  #include <linux/task_work.h>
4510 +#include <linux/vs_base.h>
4511 +#include <linux/vs_context.h>
4512 +#include <linux/vs_tag.h>
4513 +#include <linux/vserver/space.h>
4514 +#include <linux/vserver/global.h>
4515  #include "pnode.h"
4516  #include "internal.h"
4517  
4518 @@ -980,6 +985,10 @@ vfs_kern_mount(struct file_system_type *
4519         if (!type)
4520                 return ERR_PTR(-ENODEV);
4521  
4522 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4523 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4524 +               return ERR_PTR(-EPERM);
4525 +
4526         mnt = alloc_vfsmnt(name);
4527         if (!mnt)
4528                 return ERR_PTR(-ENOMEM);
4529 @@ -1056,6 +1065,7 @@ static struct mount *clone_mnt(struct mo
4530         mnt->mnt.mnt_root = dget(root);
4531         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4532         mnt->mnt_parent = mnt;
4533 +       mnt->mnt_tag = old->mnt_tag;
4534         lock_mount_hash();
4535         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4536         unlock_mount_hash();
4537 @@ -1645,7 +1655,8 @@ out_unlock:
4538   */
4539  static inline bool may_mount(void)
4540  {
4541 -       return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4542 +       return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4543 +               CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4544  }
4545  
4546  /*
4547 @@ -2146,6 +2157,7 @@ static int do_change_type(struct path *p
4548                 if (err)
4549                         goto out_unlock;
4550         }
4551 +       // mnt->mnt_flags = mnt_flags;
4552  
4553         lock_mount_hash();
4554         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4555 @@ -2174,12 +2186,14 @@ static bool has_locked_children(struct m
4556   * do loopback mount.
4557   */
4558  static int do_loopback(struct path *path, const char *old_name,
4559 -                               int recurse)
4560 +       vtag_t tag, unsigned long flags, int mnt_flags)
4561  {
4562         struct path old_path;
4563         struct mount *mnt = NULL, *old, *parent;
4564         struct mountpoint *mp;
4565 +       int recurse = flags & MS_REC;
4566         int err;
4567 +
4568         if (!old_name || !*old_name)
4569                 return -EINVAL;
4570         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4571 @@ -2259,7 +2273,7 @@ static int change_mount_flags(struct vfs
4572   * on it - tough luck.
4573   */
4574  static int do_remount(struct path *path, int flags, int mnt_flags,
4575 -                     void *data)
4576 +       void *data, vxid_t xid)
4577  {
4578         int err;
4579         struct super_block *sb = path->mnt->mnt_sb;
4580 @@ -2767,6 +2781,7 @@ long do_mount(const char *dev_name, cons
4581         struct path path;
4582         int retval = 0;
4583         int mnt_flags = 0;
4584 +       vtag_t tag = 0;
4585  
4586         /* Discard magic */
4587         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4588 @@ -2792,6 +2807,12 @@ long do_mount(const char *dev_name, cons
4589         if (!(flags & MS_NOATIME))
4590                 mnt_flags |= MNT_RELATIME;
4591  
4592 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4593 +               /* FIXME: bind and re-mounts get the tag flag? */
4594 +               if (flags & (MS_BIND|MS_REMOUNT))
4595 +                       flags |= MS_TAGID;
4596 +       }
4597 +
4598         /* Separate the per-mountpoint flags */
4599         if (flags & MS_NOSUID)
4600                 mnt_flags |= MNT_NOSUID;
4601 @@ -2816,15 +2837,17 @@ long do_mount(const char *dev_name, cons
4602                 mnt_flags |= path.mnt->mnt_flags & MNT_ATIME_MASK;
4603         }
4604  
4605 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4606 +               mnt_flags |= MNT_NODEV;
4607         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4608                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4609                    MS_STRICTATIME);
4610  
4611         if (flags & MS_REMOUNT)
4612                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4613 -                                   data_page);
4614 +                                   data_page, tag);
4615         else if (flags & MS_BIND)
4616 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
4617 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4618         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4619                 retval = do_change_type(&path, flags);
4620         else if (flags & MS_MOVE)
4621 @@ -2944,6 +2967,7 @@ struct mnt_namespace *copy_mnt_ns(unsign
4622                         p = next_mnt(p, old);
4623         }
4624         namespace_unlock();
4625 +       atomic_inc(&vs_global_mnt_ns);
4626  
4627         if (rootmnt)
4628                 mntput(rootmnt);
4629 @@ -3119,9 +3143,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4630         new_mnt = real_mount(new.mnt);
4631         root_mnt = real_mount(root.mnt);
4632         old_mnt = real_mount(old.mnt);
4633 -       if (IS_MNT_SHARED(old_mnt) ||
4634 +       if ((IS_MNT_SHARED(old_mnt) ||
4635                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4636 -               IS_MNT_SHARED(root_mnt->mnt_parent))
4637 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4638 +               !vx_flags(VXF_STATE_SETUP, 0))
4639                 goto out4;
4640         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4641                 goto out4;
4642 @@ -3259,6 +3284,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4643         if (!atomic_dec_and_test(&ns->count))
4644                 return;
4645         drop_collected_mounts(&ns->root->mnt);
4646 +       atomic_dec(&vs_global_mnt_ns);
4647         free_mnt_ns(ns);
4648  }
4649  
4650 diff -NurpP --minimal linux-4.4.161/fs/nfs/client.c linux-4.4.161-vs2.3.9.8/fs/nfs/client.c
4651 --- linux-4.4.161/fs/nfs/client.c       2016-01-10 23:01:32.000000000 +0000
4652 +++ linux-4.4.161-vs2.3.9.8/fs/nfs/client.c     2018-10-20 04:57:21.000000000 +0000
4653 @@ -583,6 +583,9 @@ int nfs_init_server_rpcclient(struct nfs
4654         if (server->flags & NFS_MOUNT_SOFT)
4655                 server->client->cl_softrtry = 1;
4656  
4657 +       server->client->cl_tag = 0;
4658 +       if (server->flags & NFS_MOUNT_TAGGED)
4659 +               server->client->cl_tag = 1;
4660         return 0;
4661  }
4662  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4663 @@ -760,6 +763,10 @@ static void nfs_server_set_fsinfo(struct
4664                 server->acdirmin = server->acdirmax = 0;
4665         }
4666  
4667 +       /* FIXME: needs fsinfo
4668 +       if (server->flags & NFS_MOUNT_TAGGED)
4669 +               sb->s_flags |= MS_TAGGED;       */
4670 +
4671         server->maxfilesize = fsinfo->maxfilesize;
4672  
4673         server->time_delta = fsinfo->time_delta;
4674 diff -NurpP --minimal linux-4.4.161/fs/nfs/dir.c linux-4.4.161-vs2.3.9.8/fs/nfs/dir.c
4675 --- linux-4.4.161/fs/nfs/dir.c  2018-10-20 02:34:30.000000000 +0000
4676 +++ linux-4.4.161-vs2.3.9.8/fs/nfs/dir.c        2018-10-20 04:57:21.000000000 +0000
4677 @@ -37,6 +37,7 @@
4678  #include <linux/sched.h>
4679  #include <linux/kmemleak.h>
4680  #include <linux/xattr.h>
4681 +#include <linux/vs_tag.h>
4682  
4683  #include "delegation.h"
4684  #include "iostat.h"
4685 @@ -1396,6 +1397,7 @@ struct dentry *nfs_lookup(struct inode *
4686         /* Success: notify readdir to use READDIRPLUS */
4687         nfs_advise_use_readdirplus(dir);
4688  
4689 +       dx_propagate_tag(nd, inode);
4690  no_entry:
4691         res = d_splice_alias(inode, dentry);
4692         if (res != NULL) {
4693 diff -NurpP --minimal linux-4.4.161/fs/nfs/inode.c linux-4.4.161-vs2.3.9.8/fs/nfs/inode.c
4694 --- linux-4.4.161/fs/nfs/inode.c        2018-10-20 02:34:30.000000000 +0000
4695 +++ linux-4.4.161-vs2.3.9.8/fs/nfs/inode.c      2018-10-20 04:57:21.000000000 +0000
4696 @@ -38,6 +38,7 @@
4697  #include <linux/slab.h>
4698  #include <linux/compat.h>
4699  #include <linux/freezer.h>
4700 +#include <linux/vs_tag.h>
4701  
4702  #include <asm/uaccess.h>
4703  
4704 @@ -376,6 +377,8 @@ nfs_fhget(struct super_block *sb, struct
4705         if (inode->i_state & I_NEW) {
4706                 struct nfs_inode *nfsi = NFS_I(inode);
4707                 unsigned long now = jiffies;
4708 +               kuid_t kuid;
4709 +               kgid_t kgid;
4710  
4711                 /* We set i_ino for the few things that still rely on it,
4712                  * such as stat(2) */
4713 @@ -419,8 +422,8 @@ nfs_fhget(struct super_block *sb, struct
4714                 inode->i_version = 0;
4715                 inode->i_size = 0;
4716                 clear_nlink(inode);
4717 -               inode->i_uid = make_kuid(&init_user_ns, -2);
4718 -               inode->i_gid = make_kgid(&init_user_ns, -2);
4719 +               kuid = make_kuid(&init_user_ns, -2);
4720 +               kgid = make_kgid(&init_user_ns, -2);
4721                 inode->i_blocks = 0;
4722                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
4723                 nfsi->write_io = 0;
4724 @@ -455,11 +458,11 @@ nfs_fhget(struct super_block *sb, struct
4725                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
4726                         nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
4727                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
4728 -                       inode->i_uid = fattr->uid;
4729 +                       kuid = fattr->uid;
4730                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
4731                         nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
4732                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
4733 -                       inode->i_gid = fattr->gid;
4734 +                       kgid = fattr->gid;
4735                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
4736                         nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
4737                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
4738 @@ -470,6 +473,10 @@ nfs_fhget(struct super_block *sb, struct
4739                          */
4740                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
4741                 }
4742 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
4743 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
4744 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
4745 +                               /* maybe fattr->xid someday */
4746  
4747                 nfs_setsecurity(inode, fattr, label);
4748  
4749 @@ -611,6 +618,8 @@ void nfs_setattr_update_inode(struct ino
4750                         inode->i_uid = attr->ia_uid;
4751                 if ((attr->ia_valid & ATTR_GID) != 0)
4752                         inode->i_gid = attr->ia_gid;
4753 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4754 +                       inode->i_tag = attr->ia_tag;
4755                 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ACCESS
4756                                 | NFS_INO_INVALID_ACL);
4757         }
4758 @@ -1235,7 +1244,9 @@ static int nfs_check_inode_attributes(st
4759         struct nfs_inode *nfsi = NFS_I(inode);
4760         loff_t cur_size, new_isize;
4761         unsigned long invalid = 0;
4762 -
4763 +       kuid_t kuid;
4764 +       kgid_t kgid;
4765 +       ktag_t ktag;
4766  
4767         if (nfs_have_delegated_attributes(inode))
4768                 return 0;
4769 @@ -1262,13 +1273,18 @@ static int nfs_check_inode_attributes(st
4770         if (nfsi->nrequests != 0)
4771                 invalid &= ~NFS_INO_REVAL_PAGECACHE;
4772  
4773 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
4774 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
4775 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
4776 +
4777         /* Have any file permissions changed? */
4778         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
4779                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
4780 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
4781 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
4782                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
4783 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
4784 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
4785                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
4786 +               /* maybe check for tag too? */
4787  
4788         /* Has the link count changed? */
4789         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
4790 @@ -1642,6 +1658,9 @@ static int nfs_update_inode(struct inode
4791         unsigned long now = jiffies;
4792         unsigned long save_cache_validity;
4793         bool cache_revalidated = true;
4794 +       kuid_t kuid;
4795 +       kgid_t kgid;
4796 +       ktag_t ktag;
4797  
4798         dfprintk(VFS, "NFS: %s(%s/%lu fh_crc=0x%08x ct=%d info=0x%x)\n",
4799                         __func__, inode->i_sb->s_id, inode->i_ino,
4800 @@ -1752,6 +1771,9 @@ static int nfs_update_inode(struct inode
4801                 cache_revalidated = false;
4802         }
4803  
4804 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4805 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4806 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
4807  
4808         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
4809                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
4810 @@ -1806,6 +1828,10 @@ static int nfs_update_inode(struct inode
4811                 cache_revalidated = false;
4812         }
4813  
4814 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
4815 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
4816 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
4817 +
4818         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
4819                 if (inode->i_nlink != fattr->nlink) {
4820                         invalid |= NFS_INO_INVALID_ATTR;
4821 diff -NurpP --minimal linux-4.4.161/fs/nfs/nfs3xdr.c linux-4.4.161-vs2.3.9.8/fs/nfs/nfs3xdr.c
4822 --- linux-4.4.161/fs/nfs/nfs3xdr.c      2016-01-10 23:01:32.000000000 +0000
4823 +++ linux-4.4.161-vs2.3.9.8/fs/nfs/nfs3xdr.c    2018-10-20 04:57:21.000000000 +0000
4824 @@ -20,6 +20,7 @@
4825  #include <linux/nfs3.h>
4826  #include <linux/nfs_fs.h>
4827  #include <linux/nfsacl.h>
4828 +#include <linux/vs_tag.h>
4829  #include "internal.h"
4830  
4831  #define NFSDBG_FACILITY                NFSDBG_XDR
4832 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
4833   *             set_mtime       mtime;
4834   *     };
4835   */
4836 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
4837 +static void encode_sattr3(struct xdr_stream *xdr,
4838 +       const struct iattr *attr, int tag)
4839  {
4840         u32 nbytes;
4841         __be32 *p;
4842 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
4843         } else
4844                 *p++ = xdr_zero;
4845  
4846 -       if (attr->ia_valid & ATTR_UID) {
4847 +       if (attr->ia_valid & ATTR_UID ||
4848 +               (tag && (attr->ia_valid & ATTR_TAG))) {
4849                 *p++ = xdr_one;
4850 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
4851 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
4852 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
4853         } else
4854                 *p++ = xdr_zero;
4855  
4856 -       if (attr->ia_valid & ATTR_GID) {
4857 +       if (attr->ia_valid & ATTR_GID ||
4858 +               (tag && (attr->ia_valid & ATTR_TAG))) {
4859                 *p++ = xdr_one;
4860 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
4861 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
4862 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
4863         } else
4864                 *p++ = xdr_zero;
4865  
4866 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
4867                                       const struct nfs3_sattrargs *args)
4868  {
4869         encode_nfs_fh3(xdr, args->fh);
4870 -       encode_sattr3(xdr, args->sattr);
4871 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
4872         encode_sattrguard3(xdr, args);
4873  }
4874  
4875 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
4876   *     };
4877   */
4878  static void encode_createhow3(struct xdr_stream *xdr,
4879 -                             const struct nfs3_createargs *args)
4880 +       const struct nfs3_createargs *args, int tag)
4881  {
4882         encode_uint32(xdr, args->createmode);
4883         switch (args->createmode) {
4884         case NFS3_CREATE_UNCHECKED:
4885         case NFS3_CREATE_GUARDED:
4886 -               encode_sattr3(xdr, args->sattr);
4887 +               encode_sattr3(xdr, args->sattr, tag);
4888                 break;
4889         case NFS3_CREATE_EXCLUSIVE:
4890                 encode_createverf3(xdr, args->verifier);
4891 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
4892                                      const struct nfs3_createargs *args)
4893  {
4894         encode_diropargs3(xdr, args->fh, args->name, args->len);
4895 -       encode_createhow3(xdr, args);
4896 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
4897  }
4898  
4899  /*
4900 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
4901                                     const struct nfs3_mkdirargs *args)
4902  {
4903         encode_diropargs3(xdr, args->fh, args->name, args->len);
4904 -       encode_sattr3(xdr, args->sattr);
4905 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
4906  }
4907  
4908  /*
4909 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
4910   *     };
4911   */
4912  static void encode_symlinkdata3(struct xdr_stream *xdr,
4913 -                               const struct nfs3_symlinkargs *args)
4914 +       const struct nfs3_symlinkargs *args, int tag)
4915  {
4916 -       encode_sattr3(xdr, args->sattr);
4917 +       encode_sattr3(xdr, args->sattr, tag);
4918         encode_nfspath3(xdr, args->pages, args->pathlen);
4919  }
4920  
4921 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
4922                                       const struct nfs3_symlinkargs *args)
4923  {
4924         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
4925 -       encode_symlinkdata3(xdr, args);
4926 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
4927         xdr->buf->flags |= XDRBUF_WRITE;
4928  }
4929  
4930 @@ -1131,24 +1137,24 @@ static void nfs3_xdr_enc_symlink3args(st
4931   *     };
4932   */
4933  static void encode_devicedata3(struct xdr_stream *xdr,
4934 -                              const struct nfs3_mknodargs *args)
4935 +       const struct nfs3_mknodargs *args, int tag)
4936  {
4937 -       encode_sattr3(xdr, args->sattr);
4938 +       encode_sattr3(xdr, args->sattr, tag);
4939         encode_specdata3(xdr, args->rdev);
4940  }
4941  
4942  static void encode_mknoddata3(struct xdr_stream *xdr,
4943 -                             const struct nfs3_mknodargs *args)
4944 +       const struct nfs3_mknodargs *args, int tag)
4945  {
4946         encode_ftype3(xdr, args->type);
4947         switch (args->type) {
4948         case NF3CHR:
4949         case NF3BLK:
4950 -               encode_devicedata3(xdr, args);
4951 +               encode_devicedata3(xdr, args, tag);
4952                 break;
4953         case NF3SOCK:
4954         case NF3FIFO:
4955 -               encode_sattr3(xdr, args->sattr);
4956 +               encode_sattr3(xdr, args->sattr, tag);
4957                 break;
4958         case NF3REG:
4959         case NF3DIR:
4960 @@ -1163,7 +1169,7 @@ static void nfs3_xdr_enc_mknod3args(stru
4961                                     const struct nfs3_mknodargs *args)
4962  {
4963         encode_diropargs3(xdr, args->fh, args->name, args->len);
4964 -       encode_mknoddata3(xdr, args);
4965 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
4966  }
4967  
4968  /*
4969 diff -NurpP --minimal linux-4.4.161/fs/nfs/super.c linux-4.4.161-vs2.3.9.8/fs/nfs/super.c
4970 --- linux-4.4.161/fs/nfs/super.c        2018-10-20 02:34:30.000000000 +0000
4971 +++ linux-4.4.161-vs2.3.9.8/fs/nfs/super.c      2018-10-20 04:57:21.000000000 +0000
4972 @@ -54,6 +54,7 @@
4973  #include <linux/parser.h>
4974  #include <linux/nsproxy.h>
4975  #include <linux/rcupdate.h>
4976 +#include <linux/vs_tag.h>
4977  
4978  #include <asm/uaccess.h>
4979  
4980 @@ -102,6 +103,7 @@ enum {
4981         Opt_mountport,
4982         Opt_mountvers,
4983         Opt_minorversion,
4984 +       Opt_tagid,
4985  
4986         /* Mount options that take string arguments */
4987         Opt_nfsvers,
4988 @@ -114,6 +116,9 @@ enum {
4989         /* Special mount options */
4990         Opt_userspace, Opt_deprecated, Opt_sloppy,
4991  
4992 +       /* Linux-VServer tagging options */
4993 +       Opt_tag, Opt_notag,
4994 +
4995         Opt_err
4996  };
4997  
4998 @@ -183,6 +188,10 @@ static const match_table_t nfs_mount_opt
4999         { Opt_fscache_uniq, "fsc=%s" },
5000         { Opt_local_lock, "local_lock=%s" },
5001  
5002 +       { Opt_tag, "tag" },
5003 +       { Opt_notag, "notag" },
5004 +       { Opt_tagid, "tagid=%u" },
5005 +
5006         /* The following needs to be listed after all other options */
5007         { Opt_nfsvers, "v%s" },
5008  
5009 @@ -642,6 +651,7 @@ static void nfs_show_mount_options(struc
5010                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5011                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5012                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5013 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5014                 { 0, NULL, NULL }
5015         };
5016         const struct proc_nfs_info *nfs_infop;
5017 @@ -1324,6 +1334,14 @@ static int nfs_parse_mount_options(char
5018                 case Opt_nomigration:
5019                         mnt->options &= ~NFS_OPTION_MIGRATION;
5020                         break;
5021 +#ifndef CONFIG_TAGGING_NONE
5022 +               case Opt_tag:
5023 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5024 +                       break;
5025 +               case Opt_notag:
5026 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5027 +                       break;
5028 +#endif
5029  
5030                 /*
5031                  * options that take numeric values
5032 @@ -1410,6 +1428,12 @@ static int nfs_parse_mount_options(char
5033                                 goto out_invalid_value;
5034                         mnt->minorversion = option;
5035                         break;
5036 +#ifdef CONFIG_PROPAGATE
5037 +               case Opt_tagid:
5038 +                       /* use args[0] */
5039 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5040 +                       break;
5041 +#endif
5042  
5043                 /*
5044                  * options that take text values
5045 diff -NurpP --minimal linux-4.4.161/fs/nfsd/auth.c linux-4.4.161-vs2.3.9.8/fs/nfsd/auth.c
5046 --- linux-4.4.161/fs/nfsd/auth.c        2018-10-20 02:34:30.000000000 +0000
5047 +++ linux-4.4.161-vs2.3.9.8/fs/nfsd/auth.c      2018-10-20 04:57:21.000000000 +0000
5048 @@ -1,6 +1,7 @@
5049  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
5050  
5051  #include <linux/sched.h>
5052 +#include <linux/vs_tag.h>
5053  #include "nfsd.h"
5054  #include "auth.h"
5055  
5056 @@ -35,6 +36,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5057  
5058         new->fsuid = rqstp->rq_cred.cr_uid;
5059         new->fsgid = rqstp->rq_cred.cr_gid;
5060 +       /* FIXME: this desperately needs a tag :)
5061 +       new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5062 +                       */
5063  
5064         rqgi = rqstp->rq_cred.cr_group_info;
5065  
5066 diff -NurpP --minimal linux-4.4.161/fs/nfsd/nfs3xdr.c linux-4.4.161-vs2.3.9.8/fs/nfsd/nfs3xdr.c
5067 --- linux-4.4.161/fs/nfsd/nfs3xdr.c     2018-10-20 02:34:30.000000000 +0000
5068 +++ linux-4.4.161-vs2.3.9.8/fs/nfsd/nfs3xdr.c   2018-10-20 04:57:21.000000000 +0000
5069 @@ -8,6 +8,7 @@
5070  
5071  #include <linux/namei.h>
5072  #include <linux/sunrpc/svc_xprt.h>
5073 +#include <linux/vs_tag.h>
5074  #include "xdr3.h"
5075  #include "auth.h"
5076  #include "netns.h"
5077 @@ -98,6 +99,8 @@ static __be32 *
5078  decode_sattr3(__be32 *p, struct iattr *iap)
5079  {
5080         u32     tmp;
5081 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5082 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5083  
5084         iap->ia_valid = 0;
5085  
5086 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5087                 iap->ia_mode = ntohl(*p++);
5088         }
5089         if (*p++) {
5090 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5091 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5092                 if (uid_valid(iap->ia_uid))
5093                         iap->ia_valid |= ATTR_UID;
5094         }
5095         if (*p++) {
5096 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5097 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5098                 if (gid_valid(iap->ia_gid))
5099                         iap->ia_valid |= ATTR_GID;
5100         }
5101 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5102 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5103 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5104         if (*p++) {
5105                 u64     newsize;
5106  
5107 @@ -167,8 +173,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5108         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5109         *p++ = htonl((u32) (stat->mode & S_IALLUGO));
5110         *p++ = htonl((u32) stat->nlink);
5111 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5112 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5113 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5114 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5115 +               stat->uid, stat->tag)));
5116 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5117 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5118 +               stat->gid, stat->tag)));
5119         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5120                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5121         } else {
5122 diff -NurpP --minimal linux-4.4.161/fs/nfsd/nfs4xdr.c linux-4.4.161-vs2.3.9.8/fs/nfsd/nfs4xdr.c
5123 --- linux-4.4.161/fs/nfsd/nfs4xdr.c     2018-10-20 02:34:30.000000000 +0000
5124 +++ linux-4.4.161-vs2.3.9.8/fs/nfsd/nfs4xdr.c   2018-10-20 05:50:20.000000000 +0000
5125 @@ -40,6 +40,7 @@
5126  #include <linux/utsname.h>
5127  #include <linux/pagemap.h>
5128  #include <linux/sunrpc/svcauth_gss.h>
5129 +#include <linux/vs_tag.h>
5130  
5131  #include "idmap.h"
5132  #include "acl.h"
5133 @@ -2639,12 +2640,16 @@ out_acl:
5134                 *p++ = cpu_to_be32(stat.nlink);
5135         }
5136         if (bmval1 & FATTR4_WORD1_OWNER) {
5137 -               status = nfsd4_encode_user(xdr, rqstp, stat.uid);
5138 +               status = nfsd4_encode_user(xdr, rqstp,
5139 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5140 +                               stat.uid, stat.tag));
5141                 if (status)
5142                         goto out;
5143         }
5144         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5145 -               status = nfsd4_encode_group(xdr, rqstp, stat.gid);
5146 +               status = nfsd4_encode_group(xdr, rqstp,
5147 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5148 +                               stat.gid, stat.tag));
5149                 if (status)
5150                         goto out;
5151         }
5152 diff -NurpP --minimal linux-4.4.161/fs/nfsd/nfsxdr.c linux-4.4.161-vs2.3.9.8/fs/nfsd/nfsxdr.c
5153 --- linux-4.4.161/fs/nfsd/nfsxdr.c      2018-10-20 02:34:30.000000000 +0000
5154 +++ linux-4.4.161-vs2.3.9.8/fs/nfsd/nfsxdr.c    2018-10-20 04:57:21.000000000 +0000
5155 @@ -7,6 +7,7 @@
5156  #include "vfs.h"
5157  #include "xdr.h"
5158  #include "auth.h"
5159 +#include <linux/vs_tag.h>
5160  
5161  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5162  
5163 @@ -89,6 +90,8 @@ static __be32 *
5164  decode_sattr(__be32 *p, struct iattr *iap)
5165  {
5166         u32     tmp, tmp1;
5167 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5168 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5169  
5170         iap->ia_valid = 0;
5171  
5172 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5173                 iap->ia_mode = tmp;
5174         }
5175         if ((tmp = ntohl(*p++)) != (u32)-1) {
5176 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5177 +               kuid = make_kuid(&init_user_ns, tmp);
5178                 if (uid_valid(iap->ia_uid))
5179                         iap->ia_valid |= ATTR_UID;
5180         }
5181         if ((tmp = ntohl(*p++)) != (u32)-1) {
5182 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5183 +               kgid = make_kgid(&init_user_ns, tmp);
5184                 if (gid_valid(iap->ia_gid))
5185                         iap->ia_valid |= ATTR_GID;
5186         }
5187 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5188 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5189 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5190         if ((tmp = ntohl(*p++)) != (u32)-1) {
5191                 iap->ia_valid |= ATTR_SIZE;
5192                 iap->ia_size = tmp;
5193 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5194         *p++ = htonl(nfs_ftypes[type >> 12]);
5195         *p++ = htonl((u32) stat->mode);
5196         *p++ = htonl((u32) stat->nlink);
5197 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5198 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5199 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5200 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5201 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5202 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5203  
5204         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5205                 *p++ = htonl(NFS_MAXPATHLEN);
5206 diff -NurpP --minimal linux-4.4.161/fs/ocfs2/dlmglue.c linux-4.4.161-vs2.3.9.8/fs/ocfs2/dlmglue.c
5207 --- linux-4.4.161/fs/ocfs2/dlmglue.c    2018-10-20 02:34:30.000000000 +0000
5208 +++ linux-4.4.161-vs2.3.9.8/fs/ocfs2/dlmglue.c  2018-10-20 04:57:21.000000000 +0000
5209 @@ -2128,6 +2128,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5210         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5211         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5212         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5213 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5214         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5215         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5216         lvb->lvb_iatime_packed  =
5217 @@ -2178,6 +2179,7 @@ static void ocfs2_refresh_inode_from_lvb
5218  
5219         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5220         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5221 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5222         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5223         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5224         ocfs2_unpack_timespec(&inode->i_atime,
5225 diff -NurpP --minimal linux-4.4.161/fs/ocfs2/dlmglue.h linux-4.4.161-vs2.3.9.8/fs/ocfs2/dlmglue.h
5226 --- linux-4.4.161/fs/ocfs2/dlmglue.h    2018-10-20 02:34:30.000000000 +0000
5227 +++ linux-4.4.161-vs2.3.9.8/fs/ocfs2/dlmglue.h  2018-10-20 04:57:21.000000000 +0000
5228 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5229         __be16       lvb_inlink;
5230         __be32       lvb_iattr;
5231         __be32       lvb_igeneration;
5232 -       __be32       lvb_reserved2;
5233 +       __be16       lvb_itag;
5234 +       __be16       lvb_reserved2;
5235  };
5236  
5237  #define OCFS2_QINFO_LVB_VERSION 1
5238 diff -NurpP --minimal linux-4.4.161/fs/ocfs2/file.c linux-4.4.161-vs2.3.9.8/fs/ocfs2/file.c
5239 --- linux-4.4.161/fs/ocfs2/file.c       2018-10-20 02:34:30.000000000 +0000
5240 +++ linux-4.4.161-vs2.3.9.8/fs/ocfs2/file.c     2018-10-20 04:57:21.000000000 +0000
5241 @@ -1151,7 +1151,7 @@ int ocfs2_setattr(struct dentry *dentry,
5242                 attr->ia_valid &= ~ATTR_SIZE;
5243  
5244  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5245 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5246 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5247         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5248                 return 0;
5249  
5250 diff -NurpP --minimal linux-4.4.161/fs/ocfs2/inode.c linux-4.4.161-vs2.3.9.8/fs/ocfs2/inode.c
5251 --- linux-4.4.161/fs/ocfs2/inode.c      2016-01-10 23:01:32.000000000 +0000
5252 +++ linux-4.4.161-vs2.3.9.8/fs/ocfs2/inode.c    2018-10-20 04:57:21.000000000 +0000
5253 @@ -28,6 +28,7 @@
5254  #include <linux/highmem.h>
5255  #include <linux/pagemap.h>
5256  #include <linux/quotaops.h>
5257 +#include <linux/vs_tag.h>
5258  
5259  #include <asm/byteorder.h>
5260  
5261 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5262  {
5263         unsigned int flags = OCFS2_I(inode)->ip_attr;
5264  
5265 -       inode->i_flags &= ~(S_IMMUTABLE |
5266 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5267                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5268  
5269         if (flags & OCFS2_IMMUTABLE_FL)
5270                 inode->i_flags |= S_IMMUTABLE;
5271 +       if (flags & OCFS2_IXUNLINK_FL)
5272 +               inode->i_flags |= S_IXUNLINK;
5273  
5274         if (flags & OCFS2_SYNC_FL)
5275                 inode->i_flags |= S_SYNC;
5276 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5277                 inode->i_flags |= S_NOATIME;
5278         if (flags & OCFS2_DIRSYNC_FL)
5279                 inode->i_flags |= S_DIRSYNC;
5280 +
5281 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5282 +
5283 +       if (flags & OCFS2_BARRIER_FL)
5284 +               inode->i_vflags |= V_BARRIER;
5285 +       if (flags & OCFS2_COW_FL)
5286 +               inode->i_vflags |= V_COW;
5287  }
5288  
5289  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5290  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5291  {
5292         unsigned int flags = oi->vfs_inode.i_flags;
5293 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5294 +
5295 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5296 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5297 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5298 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5299 +
5300 +       if (flags & S_IMMUTABLE)
5301 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5302 +       if (flags & S_IXUNLINK)
5303 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5304  
5305 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5306 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5307         if (flags & S_SYNC)
5308                 oi->ip_attr |= OCFS2_SYNC_FL;
5309         if (flags & S_APPEND)
5310                 oi->ip_attr |= OCFS2_APPEND_FL;
5311 -       if (flags & S_IMMUTABLE)
5312 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5313         if (flags & S_NOATIME)
5314                 oi->ip_attr |= OCFS2_NOATIME_FL;
5315         if (flags & S_DIRSYNC)
5316                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5317 +
5318 +       if (vflags & V_BARRIER)
5319 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5320 +       if (vflags & V_COW)
5321 +               oi->ip_attr |= OCFS2_COW_FL;
5322  }
5323  
5324  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5325 @@ -268,6 +290,8 @@ void ocfs2_populate_inode(struct inode *
5326         struct super_block *sb;
5327         struct ocfs2_super *osb;
5328         int use_plocks = 1;
5329 +       uid_t uid;
5330 +       gid_t gid;
5331  
5332         sb = inode->i_sb;
5333         osb = OCFS2_SB(sb);
5334 @@ -296,8 +320,12 @@ void ocfs2_populate_inode(struct inode *
5335         inode->i_generation = le32_to_cpu(fe->i_generation);
5336         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5337         inode->i_mode = le16_to_cpu(fe->i_mode);
5338 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5339 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5340 +       uid = le32_to_cpu(fe->i_uid);
5341 +       gid = le32_to_cpu(fe->i_gid);
5342 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5343 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5344 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5345 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5346  
5347         /* Fast symlinks will have i_size but no allocated clusters. */
5348         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5349 diff -NurpP --minimal linux-4.4.161/fs/ocfs2/inode.h linux-4.4.161-vs2.3.9.8/fs/ocfs2/inode.h
5350 --- linux-4.4.161/fs/ocfs2/inode.h      2016-01-10 23:01:32.000000000 +0000
5351 +++ linux-4.4.161-vs2.3.9.8/fs/ocfs2/inode.h    2018-10-20 04:57:21.000000000 +0000
5352 @@ -161,6 +161,7 @@ struct buffer_head *ocfs2_bread(struct i
5353  
5354  void ocfs2_set_inode_flags(struct inode *inode);
5355  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5356 +int ocfs2_sync_flags(struct inode *inode, int, int);
5357  
5358  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5359  {
5360 diff -NurpP --minimal linux-4.4.161/fs/ocfs2/ioctl.c linux-4.4.161-vs2.3.9.8/fs/ocfs2/ioctl.c
5361 --- linux-4.4.161/fs/ocfs2/ioctl.c      2016-01-10 23:01:32.000000000 +0000
5362 +++ linux-4.4.161-vs2.3.9.8/fs/ocfs2/ioctl.c    2018-10-20 04:57:21.000000000 +0000
5363 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5364         return status;
5365  }
5366  
5367 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5368 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5369 +{
5370 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5371 +       struct buffer_head *bh = NULL;
5372 +       handle_t *handle = NULL;
5373 +       int status;
5374 +
5375 +       status = ocfs2_inode_lock(inode, &bh, 1);
5376 +       if (status < 0) {
5377 +               mlog_errno(status);
5378 +               return status;
5379 +       }
5380 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5381 +       if (IS_ERR(handle)) {
5382 +               status = PTR_ERR(handle);
5383 +               mlog_errno(status);
5384 +               goto bail_unlock;
5385 +       }
5386 +
5387 +       inode->i_flags = flags;
5388 +       inode->i_vflags = vflags;
5389 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5390 +
5391 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5392 +       if (status < 0)
5393 +               mlog_errno(status);
5394 +
5395 +       ocfs2_commit_trans(osb, handle);
5396 +bail_unlock:
5397 +       ocfs2_inode_unlock(inode, 1);
5398 +       brelse(bh);
5399 +       return status;
5400 +}
5401 +
5402 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5403                                 unsigned mask)
5404  {
5405         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5406 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5407                         goto bail_unlock;
5408         }
5409  
5410 +       if (IS_BARRIER(inode)) {
5411 +               vxwprintk_task(1, "messing with the barrier.");
5412 +               goto bail_unlock;
5413 +       }
5414 +
5415         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5416         if (IS_ERR(handle)) {
5417                 status = PTR_ERR(handle);
5418 @@ -841,6 +880,7 @@ bail:
5419         return status;
5420  }
5421  
5422 +
5423  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5424  {
5425         struct inode *inode = file_inode(filp);
5426 diff -NurpP --minimal linux-4.4.161/fs/ocfs2/namei.c linux-4.4.161-vs2.3.9.8/fs/ocfs2/namei.c
5427 --- linux-4.4.161/fs/ocfs2/namei.c      2018-10-20 02:34:30.000000000 +0000
5428 +++ linux-4.4.161-vs2.3.9.8/fs/ocfs2/namei.c    2018-10-20 04:57:21.000000000 +0000
5429 @@ -41,6 +41,7 @@
5430  #include <linux/slab.h>
5431  #include <linux/highmem.h>
5432  #include <linux/quotaops.h>
5433 +#include <linux/vs_tag.h>
5434  
5435  #include <cluster/masklog.h>
5436  
5437 @@ -516,6 +517,7 @@ static int __ocfs2_mknod_locked(struct i
5438         struct ocfs2_extent_list *fel;
5439         u16 feat;
5440         struct ocfs2_inode_info *oi = OCFS2_I(inode);
5441 +       ktag_t ktag;
5442  
5443         *new_fe_bh = NULL;
5444  
5445 @@ -553,8 +555,13 @@ static int __ocfs2_mknod_locked(struct i
5446         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5447         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5448         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5449 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5450 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5451 +
5452 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5453 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5454 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5455 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5456 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5457 +       inode->i_tag = ktag; /* is this correct? */
5458         fe->i_mode = cpu_to_le16(inode->i_mode);
5459         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5460                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5461 diff -NurpP --minimal linux-4.4.161/fs/ocfs2/ocfs2.h linux-4.4.161-vs2.3.9.8/fs/ocfs2/ocfs2.h
5462 --- linux-4.4.161/fs/ocfs2/ocfs2.h      2018-10-20 02:34:30.000000000 +0000
5463 +++ linux-4.4.161-vs2.3.9.8/fs/ocfs2/ocfs2.h    2018-10-20 04:57:21.000000000 +0000
5464 @@ -289,6 +289,7 @@ enum ocfs2_mount_options
5465         OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT = 1 << 15,  /* Journal Async Commit */
5466         OCFS2_MOUNT_ERRORS_CONT = 1 << 16, /* Return EIO to the calling process on error */
5467         OCFS2_MOUNT_ERRORS_ROFS = 1 << 17, /* Change filesystem to read-only on error */
5468 +       OCFS2_MOUNT_TAGGED = 1 << 18, /* use tagging */
5469  };
5470  
5471  #define OCFS2_OSB_SOFT_RO      0x0001
5472 diff -NurpP --minimal linux-4.4.161/fs/ocfs2/ocfs2_fs.h linux-4.4.161-vs2.3.9.8/fs/ocfs2/ocfs2_fs.h
5473 --- linux-4.4.161/fs/ocfs2/ocfs2_fs.h   2016-01-10 23:01:32.000000000 +0000
5474 +++ linux-4.4.161-vs2.3.9.8/fs/ocfs2/ocfs2_fs.h 2018-10-20 04:57:21.000000000 +0000
5475 @@ -275,6 +275,11 @@
5476  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5477  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5478  
5479 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5480 +
5481 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5482 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5483 +
5484  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5485  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5486  
5487 diff -NurpP --minimal linux-4.4.161/fs/ocfs2/super.c linux-4.4.161-vs2.3.9.8/fs/ocfs2/super.c
5488 --- linux-4.4.161/fs/ocfs2/super.c      2018-10-20 02:34:30.000000000 +0000
5489 +++ linux-4.4.161-vs2.3.9.8/fs/ocfs2/super.c    2018-10-20 04:57:21.000000000 +0000
5490 @@ -193,6 +193,7 @@ enum {
5491         Opt_dir_resv_level,
5492         Opt_journal_async_commit,
5493         Opt_err_cont,
5494 +       Opt_tag, Opt_notag, Opt_tagid,
5495         Opt_err,
5496  };
5497  
5498 @@ -226,6 +227,9 @@ static const match_table_t tokens = {
5499         {Opt_dir_resv_level, "dir_resv_level=%u"},
5500         {Opt_journal_async_commit, "journal_async_commit"},
5501         {Opt_err_cont, "errors=continue"},
5502 +       {Opt_tag, "tag"},
5503 +       {Opt_notag, "notag"},
5504 +       {Opt_tagid, "tagid=%u"},
5505         {Opt_err, NULL}
5506  };
5507  
5508 @@ -676,6 +680,13 @@ static int ocfs2_remount(struct super_bl
5509                 goto out;
5510         }
5511  
5512 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5513 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5514 +               ret = -EINVAL;
5515 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5516 +               goto out;
5517 +       }
5518 +
5519         /* We're going to/from readonly mode. */
5520         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5521                 /* Disable quota accounting before remounting RO */
5522 @@ -1165,6 +1176,9 @@ static int ocfs2_fill_super(struct super
5523  
5524         ocfs2_complete_mount_recovery(osb);
5525  
5526 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5527 +               sb->s_flags |= MS_TAGGED;
5528 +
5529         if (ocfs2_mount_local(osb))
5530                 snprintf(nodestr, sizeof(nodestr), "local");
5531         else
5532 @@ -1485,6 +1499,20 @@ static int ocfs2_parse_options(struct su
5533                 case Opt_journal_async_commit:
5534                         mopt->mount_opt |= OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT;
5535                         break;
5536 +#ifndef CONFIG_TAGGING_NONE
5537 +               case Opt_tag:
5538 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5539 +                       break;
5540 +               case Opt_notag:
5541 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5542 +                       break;
5543 +#endif
5544 +#ifdef CONFIG_PROPAGATE
5545 +               case Opt_tagid:
5546 +                       /* use args[0] */
5547 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5548 +                       break;
5549 +#endif
5550                 default:
5551                         mlog(ML_ERROR,
5552                              "Unrecognized mount option \"%s\" "
5553 diff -NurpP --minimal linux-4.4.161/fs/open.c linux-4.4.161-vs2.3.9.8/fs/open.c
5554 --- linux-4.4.161/fs/open.c     2018-10-20 02:34:30.000000000 +0000
5555 +++ linux-4.4.161-vs2.3.9.8/fs/open.c   2018-10-20 04:57:21.000000000 +0000
5556 @@ -31,6 +31,11 @@
5557  #include <linux/ima.h>
5558  #include <linux/dnotify.h>
5559  #include <linux/compat.h>
5560 +#include <linux/vs_base.h>
5561 +#include <linux/vs_limit.h>
5562 +#include <linux/vs_tag.h>
5563 +#include <linux/vs_cowbl.h>
5564 +#include <linux/vserver/dlimit.h>
5565  
5566  #include "internal.h"
5567  
5568 @@ -70,6 +75,11 @@ long vfs_truncate(struct path *path, lof
5569         struct inode *inode;
5570         long error;
5571  
5572 +#ifdef CONFIG_VSERVER_COWBL
5573 +       error = cow_check_and_break(path);
5574 +       if (error)
5575 +               goto out;
5576 +#endif
5577         inode = path->dentry->d_inode;
5578  
5579         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5580 @@ -548,6 +558,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5581         unsigned int lookup_flags = LOOKUP_FOLLOW;
5582  retry:
5583         error = user_path_at(dfd, filename, lookup_flags, &path);
5584 +#ifdef CONFIG_VSERVER_COWBL
5585 +       if (!error) {
5586 +               error = cow_check_and_break(&path);
5587 +               if (error)
5588 +                       path_put(&path);
5589 +       }
5590 +#endif
5591         if (!error) {
5592                 error = chmod_common(&path, mode);
5593                 path_put(&path);
5594 @@ -582,13 +599,15 @@ retry_deleg:
5595                 if (!uid_valid(uid))
5596                         return -EINVAL;
5597                 newattrs.ia_valid |= ATTR_UID;
5598 -               newattrs.ia_uid = uid;
5599 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5600 +                       dx_map_uid(user));
5601         }
5602         if (group != (gid_t) -1) {
5603                 if (!gid_valid(gid))
5604                         return -EINVAL;
5605                 newattrs.ia_valid |= ATTR_GID;
5606 -               newattrs.ia_gid = gid;
5607 +               newattrs.ia_gid = make_kgid(&init_user_ns,
5608 +                       dx_map_gid(group));
5609         }
5610         if (!S_ISDIR(inode->i_mode))
5611                 newattrs.ia_valid |=
5612 @@ -626,6 +645,10 @@ retry:
5613         error = mnt_want_write(path.mnt);
5614         if (error)
5615                 goto out_release;
5616 +#ifdef CONFIG_VSERVER_COWBL
5617 +       error = cow_check_and_break(&path);
5618 +       if (!error)
5619 +#endif
5620         error = chown_common(&path, user, group);
5621         mnt_drop_write(path.mnt);
5622  out_release:
5623 diff -NurpP --minimal linux-4.4.161/fs/proc/array.c linux-4.4.161-vs2.3.9.8/fs/proc/array.c
5624 --- linux-4.4.161/fs/proc/array.c       2018-10-20 02:34:30.000000000 +0000
5625 +++ linux-4.4.161-vs2.3.9.8/fs/proc/array.c     2018-10-20 05:50:20.000000000 +0000
5626 @@ -84,6 +84,8 @@
5627  #include <linux/tracehook.h>
5628  #include <linux/string_helpers.h>
5629  #include <linux/user_namespace.h>
5630 +#include <linux/vs_context.h>
5631 +#include <linux/vs_network.h>
5632  
5633  #include <asm/pgtable.h>
5634  #include <asm/processor.h>
5635 @@ -155,6 +157,9 @@ static inline void task_state(struct seq
5636         ppid = pid_alive(p) ?
5637                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5638  
5639 +       if (unlikely(vx_current_initpid(p->pid)))
5640 +               ppid = 0;
5641 +
5642         tracer = ptrace_parent(p);
5643         if (tracer)
5644                 tpid = task_pid_nr_ns(tracer, ns);
5645 @@ -293,8 +298,8 @@ static inline void task_sig(struct seq_f
5646         render_sigset_t(m, "SigCgt:\t", &caught);
5647  }
5648  
5649 -static void render_cap_t(struct seq_file *m, const char *header,
5650 -                       kernel_cap_t *a)
5651 +void render_cap_t(struct seq_file *m, const char *header,
5652 +                       struct vx_info *vxi, kernel_cap_t *a)
5653  {
5654         unsigned __capi;
5655  
5656 @@ -321,11 +326,12 @@ static inline void task_cap(struct seq_f
5657         cap_ambient     = cred->cap_ambient;
5658         rcu_read_unlock();
5659  
5660 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
5661 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
5662 -       render_cap_t(m, "CapEff:\t", &cap_effective);
5663 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
5664 -       render_cap_t(m, "CapAmb:\t", &cap_ambient);
5665 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5666 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5667 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5668 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5669 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5670 +       render_cap_t(m, "CapAmb:\t", p->vx_info, &cap_ambient);
5671  }
5672  
5673  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
5674 @@ -377,6 +383,43 @@ static void task_cpus_allowed(struct seq
5675                    cpumask_pr_args(&task->cpus_allowed));
5676  }
5677  
5678 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
5679 +                       struct pid *pid, struct task_struct *task)
5680 +{
5681 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
5682 +                       "Count:\t%u\n"
5683 +                       "uts:\t%p(%c)\n"
5684 +                       "ipc:\t%p(%c)\n"
5685 +                       "mnt:\t%p(%c)\n"
5686 +                       "pid:\t%p(%c)\n"
5687 +                       "net:\t%p(%c)\n",
5688 +                       task->nsproxy,
5689 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
5690 +                       atomic_read(&task->nsproxy->count),
5691 +                       task->nsproxy->uts_ns,
5692 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
5693 +                       task->nsproxy->ipc_ns,
5694 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
5695 +                       task->nsproxy->mnt_ns,
5696 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
5697 +                       task->nsproxy->pid_ns_for_children,
5698 +                       (task->nsproxy->pid_ns_for_children ==
5699 +                               init_task.nsproxy->pid_ns_for_children ? 'I' : '-'),
5700 +                       task->nsproxy->net_ns,
5701 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
5702 +       return 0;
5703 +}
5704 +
5705 +void task_vs_id(struct seq_file *m, struct task_struct *task)
5706 +{
5707 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
5708 +               return;
5709 +
5710 +       seq_printf(m, "VxID:\t%d\n", vx_task_xid(task));
5711 +       seq_printf(m, "NxID:\t%d\n", nx_task_nid(task));
5712 +}
5713 +
5714 +
5715  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
5716                         struct pid *pid, struct task_struct *task)
5717  {
5718 @@ -394,6 +437,7 @@ int proc_pid_status(struct seq_file *m,
5719         task_seccomp(m, task);
5720         task_cpus_allowed(m, task);
5721         cpuset_task_status_allowed(m, task);
5722 +       task_vs_id(m, task);
5723         task_context_switch_counts(m, task);
5724         return 0;
5725  }
5726 @@ -497,6 +541,17 @@ static int do_task_stat(struct seq_file
5727         /* convert nsec -> ticks */
5728         start_time = nsec_to_clock_t(task->real_start_time);
5729  
5730 +       /* fixup start time for virt uptime */
5731 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
5732 +               unsigned long long bias =
5733 +                       current->vx_info->cvirt.bias_clock;
5734 +
5735 +               if (start_time > bias)
5736 +                       start_time -= bias;
5737 +               else
5738 +                       start_time = 0;
5739 +       }
5740 +
5741         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
5742         seq_put_decimal_ll(m, ' ', ppid);
5743         seq_put_decimal_ll(m, ' ', pgid);
5744 diff -NurpP --minimal linux-4.4.161/fs/proc/base.c linux-4.4.161-vs2.3.9.8/fs/proc/base.c
5745 --- linux-4.4.161/fs/proc/base.c        2018-10-20 02:34:30.000000000 +0000
5746 +++ linux-4.4.161-vs2.3.9.8/fs/proc/base.c      2018-10-20 05:50:20.000000000 +0000
5747 @@ -87,6 +87,8 @@
5748  #include <linux/slab.h>
5749  #include <linux/flex_array.h>
5750  #include <linux/posix-timers.h>
5751 +#include <linux/vs_context.h>
5752 +#include <linux/vs_network.h>
5753  #ifdef CONFIG_HARDWALL
5754  #include <asm/hardwall.h>
5755  #endif
5756 @@ -1120,11 +1122,15 @@ static ssize_t oom_adj_write(struct file
5757                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
5758  
5759         if (oom_adj < task->signal->oom_score_adj &&
5760 -           !capable(CAP_SYS_RESOURCE)) {
5761 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
5762                 err = -EACCES;
5763                 goto err_sighand;
5764         }
5765  
5766 +       /* prevent guest processes from circumventing the oom killer */
5767 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
5768 +               oom_adj = OOM_ADJUST_MIN;
5769 +
5770         /*
5771          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
5772          * /proc/pid/oom_score_adj instead.
5773 @@ -1689,6 +1695,8 @@ struct inode *proc_pid_make_inode(struct
5774                 inode->i_gid = cred->egid;
5775                 rcu_read_unlock();
5776         }
5777 +       /* procfs is xid tagged */
5778 +       i_tag_write(inode, (vtag_t)vx_task_xid(task));
5779         security_task_to_inode(task, inode);
5780  
5781  out:
5782 @@ -1734,6 +1742,8 @@ int pid_getattr(struct vfsmount *mnt, st
5783  
5784  /* dentry stuff */
5785  
5786 +// static unsigned name_to_int(struct dentry *dentry);
5787 +
5788  /*
5789   *     Exceptional case: normally we are not allowed to unhash a busy
5790   * directory. In this case, however, we can do it - no aliasing problems
5791 @@ -1762,6 +1772,19 @@ int pid_revalidate(struct dentry *dentry
5792         task = get_proc_task(inode);
5793  
5794         if (task) {
5795 +               unsigned pid = name_to_int(&dentry->d_name);
5796 +
5797 +               if (pid != ~0U && pid != vx_map_pid(task->pid) &&
5798 +                       pid != __task_pid_nr_ns(task, PIDTYPE_PID,
5799 +                               task_active_pid_ns(task))) {
5800 +                       vxdprintk(VXD_CBIT(misc, 10),
5801 +                               VS_Q("%*s") " dropped by pid_revalidate(%d!=%d)",
5802 +                               dentry->d_name.len, dentry->d_name.name,
5803 +                               pid, vx_map_pid(task->pid));
5804 +                       put_task_struct(task);
5805 +                       d_drop(dentry);
5806 +                       return 0;
5807 +               }
5808                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
5809                     task_dumpable(task)) {
5810                         rcu_read_lock();
5811 @@ -2331,6 +2354,13 @@ static struct dentry *proc_pident_lookup
5812         if (!task)
5813                 goto out_no_task;
5814  
5815 +       /* TODO: maybe we can come up with a generic approach? */
5816 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
5817 +               (dentry->d_name.len == 5) &&
5818 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
5819 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
5820 +               goto out;
5821 +
5822         /*
5823          * Yes, it does not scale. And it should not. Don't add
5824          * new entries into /proc/<tgid>/ without very good reasons.
5825 @@ -2773,6 +2803,11 @@ static int proc_pid_personality(struct s
5826  static const struct file_operations proc_task_operations;
5827  static const struct inode_operations proc_task_inode_operations;
5828  
5829 +extern int proc_pid_vx_info(struct seq_file *,
5830 +       struct pid_namespace *, struct pid *, struct task_struct *);
5831 +extern int proc_pid_nx_info(struct seq_file *,
5832 +       struct pid_namespace *, struct pid *, struct task_struct *);
5833 +
5834  static const struct pid_entry tgid_base_stuff[] = {
5835         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
5836         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
5837 @@ -2837,6 +2872,8 @@ static const struct pid_entry tgid_base_
5838  #ifdef CONFIG_CGROUPS
5839         ONE("cgroup",  S_IRUGO, proc_cgroup_show),
5840  #endif
5841 +       ONE("vinfo",      S_IRUGO, proc_pid_vx_info),
5842 +       ONE("ninfo",      S_IRUGO, proc_pid_nx_info),
5843         ONE("oom_score",  S_IRUGO, proc_oom_score),
5844         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
5845         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
5846 @@ -3051,7 +3088,7 @@ retry:
5847         iter.task = NULL;
5848         pid = find_ge_pid(iter.tgid, ns);
5849         if (pid) {
5850 -               iter.tgid = pid_nr_ns(pid, ns);
5851 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
5852                 iter.task = pid_task(pid, PIDTYPE_PID);
5853                 /* What we to know is if the pid we have find is the
5854                  * pid of a thread_group_leader.  Testing for task
5855 @@ -3111,8 +3148,10 @@ int proc_pid_readdir(struct file *file,
5856                 if (!has_pid_permissions(ns, iter.task, 2))
5857                         continue;
5858  
5859 -               len = snprintf(name, sizeof(name), "%d", iter.tgid);
5860 +               len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
5861                 ctx->pos = iter.tgid + TGID_OFFSET;
5862 +               if (!vx_proc_task_visible(iter.task))
5863 +                       continue;
5864                 if (!proc_fill_cache(file, ctx, name, len,
5865                                      proc_pid_instantiate, iter.task, NULL)) {
5866                         put_task_struct(iter.task);
5867 @@ -3249,6 +3288,7 @@ static const struct pid_entry tid_base_s
5868         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
5869         REG("setgroups",  S_IRUGO|S_IWUSR, proc_setgroups_operations),
5870  #endif
5871 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
5872  };
5873  
5874  static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
5875 @@ -3315,6 +3355,8 @@ static struct dentry *proc_task_lookup(s
5876         tid = name_to_int(&dentry->d_name);
5877         if (tid == ~0U)
5878                 goto out;
5879 +       if (vx_current_initpid(tid))
5880 +               goto out;
5881  
5882         ns = dentry->d_sb->s_fs_info;
5883         rcu_read_lock();
5884 diff -NurpP --minimal linux-4.4.161/fs/proc/generic.c linux-4.4.161-vs2.3.9.8/fs/proc/generic.c
5885 --- linux-4.4.161/fs/proc/generic.c     2018-10-20 02:34:30.000000000 +0000
5886 +++ linux-4.4.161-vs2.3.9.8/fs/proc/generic.c   2018-10-20 04:57:21.000000000 +0000
5887 @@ -22,6 +22,7 @@
5888  #include <linux/bitops.h>
5889  #include <linux/spinlock.h>
5890  #include <linux/completion.h>
5891 +#include <linux/vserver/inode.h>
5892  #include <asm/uaccess.h>
5893  
5894  #include "internal.h"
5895 @@ -66,8 +67,16 @@ static struct proc_dir_entry *pde_subdir
5896                         node = node->rb_left;
5897                 else if (result > 0)
5898                         node = node->rb_right;
5899 -               else
5900 +               else {
5901 +                       if (!vx_hide_check(0, de->vx_flags)) {
5902 +                               vxdprintk(VXD_CBIT(misc, 9),
5903 +                                       VS_Q("%*s")
5904 +                                       " hidden in pde_subdir_find()",
5905 +                                       de->namelen, de->name);
5906 +                               return 0;
5907 +                       }
5908                         return de;
5909 +               }
5910         }
5911         return NULL;
5912  }
5913 @@ -241,6 +250,8 @@ struct dentry *proc_lookup_de(struct pro
5914                         return ERR_PTR(-ENOMEM);
5915                 d_set_d_op(dentry, &simple_dentry_operations);
5916                 d_add(dentry, inode);
5917 +                       /* generic proc entries belong to the host */
5918 +                       i_tag_write(inode, 0);
5919                 return NULL;
5920         }
5921         read_unlock(&proc_subdir_lock);
5922 @@ -287,6 +298,12 @@ int proc_readdir_de(struct proc_dir_entr
5923         do {
5924                 struct proc_dir_entry *next;
5925                 pde_get(de);
5926 +               if (!vx_hide_check(0, de->vx_flags)) {
5927 +                       vxdprintk(VXD_CBIT(misc, 9),
5928 +                               VS_Q("%*s") " hidden in proc_readdir_de()",
5929 +                               de->namelen, de->name);
5930 +                       goto skip;
5931 +               }
5932                 read_unlock(&proc_subdir_lock);
5933                 if (!dir_emit(ctx, de->name, de->namelen,
5934                             de->low_ino, de->mode >> 12)) {
5935 @@ -294,6 +311,7 @@ int proc_readdir_de(struct proc_dir_entr
5936                         return 0;
5937                 }
5938                 read_lock(&proc_subdir_lock);
5939 +       skip:
5940                 ctx->pos++;
5941                 next = pde_subdir_next(de);
5942                 pde_put(de);
5943 @@ -387,6 +405,7 @@ static struct proc_dir_entry *__proc_cre
5944         ent->mode = mode;
5945         ent->nlink = nlink;
5946         ent->subdir = RB_ROOT;
5947 +       ent->vx_flags = IATTR_PROC_DEFAULT;
5948         atomic_set(&ent->count, 1);
5949         spin_lock_init(&ent->pde_unload_lock);
5950         INIT_LIST_HEAD(&ent->pde_openers);
5951 @@ -411,7 +430,8 @@ struct proc_dir_entry *proc_symlink(cons
5952                                 kfree(ent->data);
5953                                 kfree(ent);
5954                                 ent = NULL;
5955 -                       }
5956 +                       } else
5957 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
5958                 } else {
5959                         kfree(ent);
5960                         ent = NULL;
5961 diff -NurpP --minimal linux-4.4.161/fs/proc/inode.c linux-4.4.161-vs2.3.9.8/fs/proc/inode.c
5962 --- linux-4.4.161/fs/proc/inode.c       2016-01-10 23:01:32.000000000 +0000
5963 +++ linux-4.4.161-vs2.3.9.8/fs/proc/inode.c     2018-10-20 04:57:21.000000000 +0000
5964 @@ -431,6 +431,8 @@ struct inode *proc_get_inode(struct supe
5965                         inode->i_uid = de->uid;
5966                         inode->i_gid = de->gid;
5967                 }
5968 +               if (de->vx_flags)
5969 +                       PROC_I(inode)->vx_flags = de->vx_flags;
5970                 if (de->size)
5971                         inode->i_size = de->size;
5972                 if (de->nlink)
5973 diff -NurpP --minimal linux-4.4.161/fs/proc/internal.h linux-4.4.161-vs2.3.9.8/fs/proc/internal.h
5974 --- linux-4.4.161/fs/proc/internal.h    2016-01-10 23:01:32.000000000 +0000
5975 +++ linux-4.4.161-vs2.3.9.8/fs/proc/internal.h  2018-10-20 04:57:21.000000000 +0000
5976 @@ -14,6 +14,7 @@
5977  #include <linux/spinlock.h>
5978  #include <linux/atomic.h>
5979  #include <linux/binfmts.h>
5980 +#include <linux/vs_pid.h>
5981  
5982  struct ctl_table_header;
5983  struct mempolicy;
5984 @@ -34,6 +35,7 @@ struct proc_dir_entry {
5985         nlink_t nlink;
5986         kuid_t uid;
5987         kgid_t gid;
5988 +       int vx_flags;
5989         loff_t size;
5990         const struct inode_operations *proc_iops;
5991         const struct file_operations *proc_fops;
5992 @@ -51,15 +53,22 @@ struct proc_dir_entry {
5993         char name[];
5994  };
5995  
5996 +struct vx_info;
5997 +struct nx_info;
5998 +
5999  union proc_op {
6000         int (*proc_get_link)(struct dentry *, struct path *);
6001         int (*proc_show)(struct seq_file *m,
6002                 struct pid_namespace *ns, struct pid *pid,
6003                 struct task_struct *task);
6004 +       int (*proc_vs_read)(char *page);
6005 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6006 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6007  };
6008  
6009  struct proc_inode {
6010         struct pid *pid;
6011 +       int vx_flags;
6012         int fd;
6013         union proc_op op;
6014         struct proc_dir_entry *pde;
6015 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6016         return PROC_I(inode)->pid;
6017  }
6018  
6019 -static inline struct task_struct *get_proc_task(struct inode *inode)
6020 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6021  {
6022         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6023  }
6024  
6025 +static inline struct task_struct *get_proc_task(struct inode *inode)
6026 +{
6027 +       return vx_get_proc_task(inode, proc_pid(inode));
6028 +}
6029 +
6030  static inline int task_dumpable(struct task_struct *task)
6031  {
6032         int dumpable = 0;
6033 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6034                            struct pid *, struct task_struct *);
6035  extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6036                           struct pid *, struct task_struct *);
6037 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6038 +                           struct pid *pid, struct task_struct *task);
6039  
6040  /*
6041   * base.c
6042 diff -NurpP --minimal linux-4.4.161/fs/proc/loadavg.c linux-4.4.161-vs2.3.9.8/fs/proc/loadavg.c
6043 --- linux-4.4.161/fs/proc/loadavg.c     2016-01-10 23:01:32.000000000 +0000
6044 +++ linux-4.4.161-vs2.3.9.8/fs/proc/loadavg.c   2018-10-20 04:57:21.000000000 +0000
6045 @@ -12,15 +12,27 @@
6046  
6047  static int loadavg_proc_show(struct seq_file *m, void *v)
6048  {
6049 +       unsigned long running;
6050 +       unsigned int threads;
6051         unsigned long avnrun[3];
6052  
6053         get_avenrun(avnrun, FIXED_1/200, 0);
6054  
6055 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6056 +               struct vx_info *vxi = current_vx_info();
6057 +
6058 +               running = atomic_read(&vxi->cvirt.nr_running);
6059 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6060 +       } else {
6061 +               running = nr_running();
6062 +               threads = nr_threads;
6063 +       }
6064 +
6065         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6066                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6067                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6068                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6069 -               nr_running(), nr_threads,
6070 +               running, threads,
6071                 task_active_pid_ns(current)->last_pid);
6072         return 0;
6073  }
6074 diff -NurpP --minimal linux-4.4.161/fs/proc/meminfo.c linux-4.4.161-vs2.3.9.8/fs/proc/meminfo.c
6075 --- linux-4.4.161/fs/proc/meminfo.c     2018-10-20 02:34:30.000000000 +0000
6076 +++ linux-4.4.161-vs2.3.9.8/fs/proc/meminfo.c   2018-10-20 04:57:21.000000000 +0000
6077 @@ -43,7 +43,8 @@ static int meminfo_proc_show(struct seq_
6078         si_swapinfo(&i);
6079         committed = percpu_counter_read_positive(&vm_committed_as);
6080  
6081 -       cached = global_page_state(NR_FILE_PAGES) -
6082 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6083 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6084                         total_swapcache_pages() - i.bufferram;
6085         if (cached < 0)
6086                 cached = 0;
6087 @@ -67,13 +68,16 @@ static int meminfo_proc_show(struct seq_
6088          */
6089         pagecache = pages[LRU_ACTIVE_FILE] + pages[LRU_INACTIVE_FILE];
6090         pagecache -= min(pagecache / 2, wmark_low);
6091 -       available += pagecache;
6092 +
6093 +       if (!vx_flags(VXF_VIRT_MEM, 0))
6094 +               available += pagecache;
6095  
6096         /*
6097          * Part of the reclaimable slab consists of items that are in use,
6098          * and cannot be freed. Cap this estimate at the low watermark.
6099          */
6100 -       available += global_page_state(NR_SLAB_RECLAIMABLE) -
6101 +       if (!vx_flags(VXF_VIRT_MEM, 0))
6102 +               available += global_page_state(NR_SLAB_RECLAIMABLE) -
6103                      min(global_page_state(NR_SLAB_RECLAIMABLE) / 2, wmark_low);
6104  
6105         if (available < 0)
6106 diff -NurpP --minimal linux-4.4.161/fs/proc/root.c linux-4.4.161-vs2.3.9.8/fs/proc/root.c
6107 --- linux-4.4.161/fs/proc/root.c        2018-10-20 02:34:30.000000000 +0000
6108 +++ linux-4.4.161-vs2.3.9.8/fs/proc/root.c      2018-10-20 04:57:21.000000000 +0000
6109 @@ -20,9 +20,14 @@
6110  #include <linux/mount.h>
6111  #include <linux/pid_namespace.h>
6112  #include <linux/parser.h>
6113 +#include <linux/vserver/inode.h>
6114  
6115  #include "internal.h"
6116  
6117 +struct proc_dir_entry *proc_virtual;
6118 +
6119 +extern void proc_vx_init(void);
6120 +
6121  static int proc_test_super(struct super_block *sb, void *data)
6122  {
6123         return sb->s_fs_info == data;
6124 @@ -113,7 +118,8 @@ static struct dentry *proc_mount(struct
6125                 options = data;
6126  
6127                 /* Does the mounter have privilege over the pid namespace? */
6128 -               if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6129 +               if (!vx_ns_capable(ns->user_ns,
6130 +                       CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6131                         return ERR_PTR(-EPERM);
6132         }
6133  
6134 @@ -196,6 +202,7 @@ void __init proc_root_init(void)
6135         proc_tty_init();
6136         proc_mkdir("bus", NULL);
6137         proc_sys_init();
6138 +       proc_vx_init();
6139  }
6140  
6141  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6142 @@ -257,6 +264,7 @@ struct proc_dir_entry proc_root = {
6143         .proc_iops      = &proc_root_inode_operations, 
6144         .proc_fops      = &proc_root_operations,
6145         .parent         = &proc_root,
6146 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6147         .subdir         = RB_ROOT,
6148         .name           = "/proc",
6149  };
6150 diff -NurpP --minimal linux-4.4.161/fs/proc/self.c linux-4.4.161-vs2.3.9.8/fs/proc/self.c
6151 --- linux-4.4.161/fs/proc/self.c        2016-01-10 23:01:32.000000000 +0000
6152 +++ linux-4.4.161-vs2.3.9.8/fs/proc/self.c      2018-10-20 04:57:21.000000000 +0000
6153 @@ -1,6 +1,7 @@
6154  #include <linux/sched.h>
6155  #include <linux/slab.h>
6156  #include <linux/pid_namespace.h>
6157 +#include <linux/vserver/inode.h>
6158  #include "internal.h"
6159  
6160  /*
6161 @@ -52,6 +53,8 @@ int proc_setup_self(struct super_block *
6162         self = d_alloc_name(s->s_root, "self");
6163         if (self) {
6164                 struct inode *inode = new_inode_pseudo(s);
6165 +
6166 +               // self->vx_flags = IATTR_PROC_SYMLINK;
6167                 if (inode) {
6168                         inode->i_ino = self_inum;
6169                         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6170 diff -NurpP --minimal linux-4.4.161/fs/proc/stat.c linux-4.4.161-vs2.3.9.8/fs/proc/stat.c
6171 --- linux-4.4.161/fs/proc/stat.c        2016-01-10 23:01:32.000000000 +0000
6172 +++ linux-4.4.161-vs2.3.9.8/fs/proc/stat.c      2018-10-20 04:57:21.000000000 +0000
6173 @@ -9,8 +9,10 @@
6174  #include <linux/slab.h>
6175  #include <linux/time.h>
6176  #include <linux/irqnr.h>
6177 +#include <linux/vserver/cvirt.h>
6178  #include <linux/cputime.h>
6179  #include <linux/tick.h>
6180 +#include <linux/cpuset.h>
6181  
6182  #ifndef arch_irq_stat_cpu
6183  #define arch_irq_stat_cpu(cpu) 0
6184 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6185         u64 sum_softirq = 0;
6186         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6187         struct timespec boottime;
6188 +       cpumask_var_t cpus_allowed;
6189 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6190  
6191         user = nice = system = idle = iowait =
6192                 irq = softirq = steal = 0;
6193         guest = guest_nice = 0;
6194         getboottime(&boottime);
6195 +
6196 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6197 +               vx_vsi_boottime(&boottime);
6198 +
6199 +       if (virt_cpu)
6200 +               cpuset_cpus_allowed(current, cpus_allowed);
6201 +
6202         jif = boottime.tv_sec;
6203  
6204         for_each_possible_cpu(i) {
6205 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6206 +                       continue;
6207 +
6208                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6209                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6210                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6211 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6212         seq_putc(p, '\n');
6213  
6214         for_each_online_cpu(i) {
6215 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6216 +                       continue;
6217 +
6218                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6219                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6220                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6221 diff -NurpP --minimal linux-4.4.161/fs/proc/uptime.c linux-4.4.161-vs2.3.9.8/fs/proc/uptime.c
6222 --- linux-4.4.161/fs/proc/uptime.c      2016-01-10 23:01:32.000000000 +0000
6223 +++ linux-4.4.161-vs2.3.9.8/fs/proc/uptime.c    2018-10-20 04:57:21.000000000 +0000
6224 @@ -5,6 +5,7 @@
6225  #include <linux/seq_file.h>
6226  #include <linux/time.h>
6227  #include <linux/kernel_stat.h>
6228 +#include <linux/vserver/cvirt.h>
6229  #include <linux/cputime.h>
6230  
6231  static int uptime_proc_show(struct seq_file *m, void *v)
6232 @@ -24,6 +25,10 @@ static int uptime_proc_show(struct seq_f
6233         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6234         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6235         idle.tv_nsec = rem;
6236 +
6237 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6238 +               vx_vsi_uptime(&uptime, &idle);
6239 +
6240         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6241                         (unsigned long) uptime.tv_sec,
6242                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6243 diff -NurpP --minimal linux-4.4.161/fs/proc_namespace.c linux-4.4.161-vs2.3.9.8/fs/proc_namespace.c
6244 --- linux-4.4.161/fs/proc_namespace.c   2018-10-20 02:34:30.000000000 +0000
6245 +++ linux-4.4.161-vs2.3.9.8/fs/proc_namespace.c 2018-10-20 04:57:21.000000000 +0000
6246 @@ -46,6 +46,8 @@ static int show_sb_opts(struct seq_file
6247                 { MS_DIRSYNC, ",dirsync" },
6248                 { MS_MANDLOCK, ",mand" },
6249                 { MS_LAZYTIME, ",lazytime" },
6250 +               { MS_TAGGED, ",tag" },
6251 +               { MS_NOTAGCHECK, ",notagcheck" },
6252                 { 0, NULL }
6253         };
6254         const struct proc_fs_info *fs_infop;
6255 @@ -82,6 +84,38 @@ static inline void mangle(struct seq_fil
6256         seq_escape(m, s, " \t\n\\");
6257  }
6258  
6259 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6260 +
6261 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6262 +{
6263 +       struct path root;
6264 +       struct dentry *point;
6265 +       struct mount *mnt = real_mount(vfsmnt);
6266 +       struct mount *root_mnt;
6267 +       int ret;
6268 +
6269 +       if (mnt == mnt->mnt_ns->root)
6270 +               return 1;
6271 +
6272 +       rcu_read_lock();
6273 +       root = current->fs->root;
6274 +       root_mnt = real_mount(root.mnt);
6275 +       point = root.dentry;
6276 +
6277 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6278 +               point = mnt->mnt_mountpoint;
6279 +               mnt = mnt->mnt_parent;
6280 +       }
6281 +       rcu_read_unlock();
6282 +
6283 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6284 +       return ret;
6285 +}
6286 +
6287 +#else
6288 +#define        mnt_is_reachable(v)     (1)
6289 +#endif
6290 +
6291  static void show_type(struct seq_file *m, struct super_block *sb)
6292  {
6293         mangle(m, sb->s_type->name);
6294 @@ -99,6 +133,17 @@ static int show_vfsmnt(struct seq_file *
6295         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6296         struct super_block *sb = mnt_path.dentry->d_sb;
6297  
6298 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6299 +               return SEQ_SKIP;
6300 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6301 +               return SEQ_SKIP;
6302 +
6303 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6304 +               mnt == current->fs->root.mnt) {
6305 +               seq_puts(m, "/dev/root / ");
6306 +               goto type;
6307 +       }
6308 +
6309         if (sb->s_op->show_devname) {
6310                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6311                 if (err)
6312 @@ -112,6 +157,7 @@ static int show_vfsmnt(struct seq_file *
6313         if (err)
6314                 goto out;
6315         seq_putc(m, ' ');
6316 +type:
6317         show_type(m, sb);
6318         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6319         err = show_sb_opts(m, sb);
6320 @@ -133,6 +179,11 @@ static int show_mountinfo(struct seq_fil
6321         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6322         int err = 0;
6323  
6324 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6325 +               return SEQ_SKIP;
6326 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6327 +               return SEQ_SKIP;
6328 +
6329         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6330                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6331         if (sb->s_op->show_path)
6332 @@ -193,6 +244,17 @@ static int show_vfsstat(struct seq_file
6333         struct super_block *sb = mnt_path.dentry->d_sb;
6334         int err = 0;
6335  
6336 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6337 +               return SEQ_SKIP;
6338 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6339 +               return SEQ_SKIP;
6340 +
6341 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6342 +               mnt == current->fs->root.mnt) {
6343 +               seq_puts(m, "device /dev/root mounted on / ");
6344 +               goto type;
6345 +       }
6346 +
6347         /* device */
6348         if (sb->s_op->show_devname) {
6349                 seq_puts(m, "device ");
6350 @@ -214,7 +276,7 @@ static int show_vfsstat(struct seq_file
6351         if (err)
6352                 goto out;
6353         seq_putc(m, ' ');
6354 -
6355 +type:
6356         /* file system type */
6357         seq_puts(m, "with fstype ");
6358         show_type(m, sb);
6359 diff -NurpP --minimal linux-4.4.161/fs/quota/dquot.c linux-4.4.161-vs2.3.9.8/fs/quota/dquot.c
6360 --- linux-4.4.161/fs/quota/dquot.c      2018-10-20 02:34:30.000000000 +0000
6361 +++ linux-4.4.161-vs2.3.9.8/fs/quota/dquot.c    2018-10-20 04:57:21.000000000 +0000
6362 @@ -1643,6 +1643,9 @@ int __dquot_alloc_space(struct inode *in
6363         int reserve = flags & DQUOT_SPACE_RESERVE;
6364         struct dquot **dquots;
6365  
6366 +       if ((ret = dl_alloc_space(inode, number)))
6367 +               return ret;
6368 +
6369         if (!dquot_active(inode)) {
6370                 inode_incr_space(inode, number, reserve);
6371                 goto out;
6372 @@ -1695,6 +1698,9 @@ int dquot_alloc_inode(struct inode *inod
6373         struct dquot_warn warn[MAXQUOTAS];
6374         struct dquot * const *dquots;
6375  
6376 +       if ((ret = dl_alloc_inode(inode)))
6377 +               return ret;
6378 +
6379         if (!dquot_active(inode))
6380                 return 0;
6381         for (cnt = 0; cnt < MAXQUOTAS; cnt++)
6382 @@ -1797,6 +1803,8 @@ void __dquot_free_space(struct inode *in
6383         struct dquot **dquots;
6384         int reserve = flags & DQUOT_SPACE_RESERVE, index;
6385  
6386 +       dl_free_space(inode, number);
6387 +
6388         if (!dquot_active(inode)) {
6389                 inode_decr_space(inode, number, reserve);
6390                 return;
6391 @@ -1841,6 +1849,8 @@ void dquot_free_inode(struct inode *inod
6392         struct dquot * const *dquots;
6393         int index;
6394  
6395 +       dl_free_inode(inode);
6396 +
6397         if (!dquot_active(inode))
6398                 return;
6399  
6400 diff -NurpP --minimal linux-4.4.161/fs/quota/quota.c linux-4.4.161-vs2.3.9.8/fs/quota/quota.c
6401 --- linux-4.4.161/fs/quota/quota.c      2018-10-20 02:34:30.000000000 +0000
6402 +++ linux-4.4.161-vs2.3.9.8/fs/quota/quota.c    2018-10-20 05:50:20.000000000 +0000
6403 @@ -8,6 +8,7 @@
6404  #include <linux/fs.h>
6405  #include <linux/namei.h>
6406  #include <linux/slab.h>
6407 +#include <linux/vs_context.h>
6408  #include <asm/current.h>
6409  #include <linux/uaccess.h>
6410  #include <linux/kernel.h>
6411 @@ -39,7 +40,7 @@ static int check_quotactl_permission(str
6412                         break;
6413                 /*FALLTHROUGH*/
6414         default:
6415 -               if (!capable(CAP_SYS_ADMIN))
6416 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6417                         return -EPERM;
6418         }
6419  
6420 @@ -704,6 +705,46 @@ static int do_quotactl(struct super_bloc
6421  
6422  #ifdef CONFIG_BLOCK
6423  
6424 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6425 +
6426 +#include <linux/vroot.h>
6427 +#include <linux/major.h>
6428 +#include <linux/module.h>
6429 +#include <linux/kallsyms.h>
6430 +#include <linux/vserver/debug.h>
6431 +
6432 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6433 +
6434 +static DEFINE_SPINLOCK(vroot_grb_lock);
6435 +
6436 +int register_vroot_grb(vroot_grb_func *func) {
6437 +       int ret = -EBUSY;
6438 +
6439 +       spin_lock(&vroot_grb_lock);
6440 +       if (!vroot_get_real_bdev) {
6441 +               vroot_get_real_bdev = func;
6442 +               ret = 0;
6443 +       }
6444 +       spin_unlock(&vroot_grb_lock);
6445 +       return ret;
6446 +}
6447 +EXPORT_SYMBOL(register_vroot_grb);
6448 +
6449 +int unregister_vroot_grb(vroot_grb_func *func) {
6450 +       int ret = -EINVAL;
6451 +
6452 +       spin_lock(&vroot_grb_lock);
6453 +       if (vroot_get_real_bdev) {
6454 +               vroot_get_real_bdev = NULL;
6455 +               ret = 0;
6456 +       }
6457 +       spin_unlock(&vroot_grb_lock);
6458 +       return ret;
6459 +}
6460 +EXPORT_SYMBOL(unregister_vroot_grb);
6461 +
6462 +#endif
6463 +
6464  /* Return 1 if 'cmd' will block on frozen filesystem */
6465  static int quotactl_cmd_write(int cmd)
6466  {
6467 @@ -739,6 +780,22 @@ static struct super_block *quotactl_bloc
6468         putname(tmp);
6469         if (IS_ERR(bdev))
6470                 return ERR_CAST(bdev);
6471 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6472 +       if (bdev && bdev->bd_inode &&
6473 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6474 +               struct block_device *bdnew = (void *)-EINVAL;
6475 +
6476 +               if (vroot_get_real_bdev)
6477 +                       bdnew = vroot_get_real_bdev(bdev);
6478 +               else
6479 +                       vxdprintk(VXD_CBIT(misc, 0),
6480 +                                       "vroot_get_real_bdev not set");
6481 +               bdput(bdev);
6482 +               if (IS_ERR(bdnew))
6483 +                       return ERR_PTR(PTR_ERR(bdnew));
6484 +               bdev = bdnew;
6485 +       }
6486 +#endif
6487         if (quotactl_cmd_write(cmd))
6488                 sb = get_super_thawed(bdev);
6489         else
6490 diff -NurpP --minimal linux-4.4.161/fs/stat.c linux-4.4.161-vs2.3.9.8/fs/stat.c
6491 --- linux-4.4.161/fs/stat.c     2018-10-20 02:34:30.000000000 +0000
6492 +++ linux-4.4.161-vs2.3.9.8/fs/stat.c   2018-10-20 04:57:21.000000000 +0000
6493 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6494         stat->nlink = inode->i_nlink;
6495         stat->uid = inode->i_uid;
6496         stat->gid = inode->i_gid;
6497 +       stat->tag = inode->i_tag;
6498         stat->rdev = inode->i_rdev;
6499         stat->size = i_size_read(inode);
6500         stat->atime = inode->i_atime;
6501 diff -NurpP --minimal linux-4.4.161/fs/statfs.c linux-4.4.161-vs2.3.9.8/fs/statfs.c
6502 --- linux-4.4.161/fs/statfs.c   2016-01-10 23:01:32.000000000 +0000
6503 +++ linux-4.4.161-vs2.3.9.8/fs/statfs.c 2018-10-20 04:57:21.000000000 +0000
6504 @@ -7,6 +7,8 @@
6505  #include <linux/statfs.h>
6506  #include <linux/security.h>
6507  #include <linux/uaccess.h>
6508 +#include <linux/vs_base.h>
6509 +#include <linux/vs_dlimit.h>
6510  #include "internal.h"
6511  
6512  static int flags_by_mnt(int mnt_flags)
6513 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6514         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6515         if (retval == 0 && buf->f_frsize == 0)
6516                 buf->f_frsize = buf->f_bsize;
6517 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6518 +               vx_vsi_statfs(dentry->d_sb, buf);
6519         return retval;
6520  }
6521  
6522 diff -NurpP --minimal linux-4.4.161/fs/super.c linux-4.4.161-vs2.3.9.8/fs/super.c
6523 --- linux-4.4.161/fs/super.c    2018-10-20 02:34:30.000000000 +0000
6524 +++ linux-4.4.161-vs2.3.9.8/fs/super.c  2018-10-20 04:57:21.000000000 +0000
6525 @@ -33,6 +33,8 @@
6526  #include <linux/cleancache.h>
6527  #include <linux/fsnotify.h>
6528  #include <linux/lockdep.h>
6529 +#include <linux/magic.h>
6530 +#include <linux/vs_context.h>
6531  #include "internal.h"
6532  
6533  
6534 @@ -1135,6 +1137,13 @@ mount_fs(struct file_system_type *type,
6535         WARN_ON(!sb->s_bdi);
6536         sb->s_flags |= MS_BORN;
6537  
6538 +       error = -EPERM;
6539 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6540 +               !sb->s_bdev &&
6541 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6542 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6543 +               goto out_sb;
6544 +
6545         error = security_sb_kern_mount(sb, flags, secdata);
6546         if (error)
6547                 goto out_sb;
6548 diff -NurpP --minimal linux-4.4.161/fs/utimes.c linux-4.4.161-vs2.3.9.8/fs/utimes.c
6549 --- linux-4.4.161/fs/utimes.c   2018-10-20 02:34:30.000000000 +0000
6550 +++ linux-4.4.161-vs2.3.9.8/fs/utimes.c 2018-10-20 04:57:21.000000000 +0000
6551 @@ -8,6 +8,8 @@
6552  #include <linux/stat.h>
6553  #include <linux/utime.h>
6554  #include <linux/syscalls.h>
6555 +#include <linux/mount.h>
6556 +#include <linux/vs_cowbl.h>
6557  #include <asm/uaccess.h>
6558  #include <asm/unistd.h>
6559  
6560 @@ -52,13 +54,19 @@ static int utimes_common(struct path *pa
6561  {
6562         int error;
6563         struct iattr newattrs;
6564 -       struct inode *inode = path->dentry->d_inode;
6565         struct inode *delegated_inode = NULL;
6566 +       struct inode *inode;
6567 +
6568 +       error = cow_check_and_break(path);
6569 +       if (error)
6570 +               goto out;
6571  
6572         error = mnt_want_write(path->mnt);
6573         if (error)
6574                 goto out;
6575  
6576 +       inode = path->dentry->d_inode;
6577 +
6578         if (times && times[0].tv_nsec == UTIME_NOW &&
6579                      times[1].tv_nsec == UTIME_NOW)
6580                 times = NULL;
6581 diff -NurpP --minimal linux-4.4.161/fs/xattr.c linux-4.4.161-vs2.3.9.8/fs/xattr.c
6582 --- linux-4.4.161/fs/xattr.c    2018-10-20 02:34:30.000000000 +0000
6583 +++ linux-4.4.161-vs2.3.9.8/fs/xattr.c  2018-10-20 05:50:20.000000000 +0000
6584 @@ -21,6 +21,7 @@
6585  #include <linux/audit.h>
6586  #include <linux/vmalloc.h>
6587  #include <linux/posix_acl_xattr.h>
6588 +#include <linux/mount.h>
6589  
6590  #include <asm/uaccess.h>
6591  
6592 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6593          * The trusted.* namespace can only be accessed by privileged users.
6594          */
6595         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6596 -               if (!capable(CAP_SYS_ADMIN))
6597 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6598                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6599                 return 0;
6600         }
6601 diff -NurpP --minimal linux-4.4.161/include/linux/capability.h linux-4.4.161-vs2.3.9.8/include/linux/capability.h
6602 --- linux-4.4.161/include/linux/capability.h    2018-10-20 02:34:30.000000000 +0000
6603 +++ linux-4.4.161-vs2.3.9.8/include/linux/capability.h  2018-10-20 04:57:21.000000000 +0000
6604 @@ -77,7 +77,8 @@ extern const kernel_cap_t __cap_init_eff
6605  #else /* HAND-CODED capability initializers */
6606  
6607  #define CAP_LAST_U32                   ((_KERNEL_CAPABILITY_U32S) - 1)
6608 -#define CAP_LAST_U32_VALID_MASK                (CAP_TO_MASK(CAP_LAST_CAP + 1) -1)
6609 +#define CAP_LAST_U32_VALID_MASK                ((CAP_TO_MASK(CAP_LAST_CAP + 1) -1) \
6610 +                                       | CAP_TO_MASK(CAP_CONTEXT))
6611  
6612  # define CAP_EMPTY_SET    ((kernel_cap_t){{ 0, 0 }})
6613  # define CAP_FULL_SET     ((kernel_cap_t){{ ~0, CAP_LAST_U32_VALID_MASK }})
6614 diff -NurpP --minimal linux-4.4.161/include/linux/cred.h linux-4.4.161-vs2.3.9.8/include/linux/cred.h
6615 --- linux-4.4.161/include/linux/cred.h  2018-10-20 02:34:30.000000000 +0000
6616 +++ linux-4.4.161-vs2.3.9.8/include/linux/cred.h        2018-10-20 04:57:21.000000000 +0000
6617 @@ -161,6 +161,7 @@ extern void exit_creds(struct task_struc
6618  extern int copy_creds(struct task_struct *, unsigned long);
6619  extern const struct cred *get_task_cred(struct task_struct *);
6620  extern struct cred *cred_alloc_blank(void);
6621 +extern struct cred *__prepare_creds(const struct cred *);
6622  extern struct cred *prepare_creds(void);
6623  extern struct cred *prepare_exec_creds(void);
6624  extern int commit_creds(struct cred *);
6625 @@ -221,6 +222,31 @@ static inline bool cap_ambient_invariant
6626                                           cred->cap_inheritable));
6627  }
6628  
6629 +static inline void set_cred_subscribers(struct cred *cred, int n)
6630 +{
6631 +#ifdef CONFIG_DEBUG_CREDENTIALS
6632 +       atomic_set(&cred->subscribers, n);
6633 +#endif
6634 +}
6635 +
6636 +static inline int read_cred_subscribers(const struct cred *cred)
6637 +{
6638 +#ifdef CONFIG_DEBUG_CREDENTIALS
6639 +       return atomic_read(&cred->subscribers);
6640 +#else
6641 +       return 0;
6642 +#endif
6643 +}
6644 +
6645 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
6646 +{
6647 +#ifdef CONFIG_DEBUG_CREDENTIALS
6648 +       struct cred *cred = (struct cred *) _cred;
6649 +
6650 +       atomic_add(n, &cred->subscribers);
6651 +#endif
6652 +}
6653 +
6654  /**
6655   * get_new_cred - Get a reference on a new set of credentials
6656   * @cred: The new credentials to reference
6657 diff -NurpP --minimal linux-4.4.161/include/linux/dcache.h linux-4.4.161-vs2.3.9.8/include/linux/dcache.h
6658 --- linux-4.4.161/include/linux/dcache.h        2018-10-20 02:34:30.000000000 +0000
6659 +++ linux-4.4.161-vs2.3.9.8/include/linux/dcache.h      2018-10-20 04:57:21.000000000 +0000
6660 @@ -10,6 +10,7 @@
6661  #include <linux/cache.h>
6662  #include <linux/rcupdate.h>
6663  #include <linux/lockref.h>
6664 +// #include <linux/vs_limit.h>
6665  
6666  struct path;
6667  struct vfsmount;
6668 @@ -352,8 +353,10 @@ extern char *dentry_path(struct dentry *
6669   */
6670  static inline struct dentry *dget_dlock(struct dentry *dentry)
6671  {
6672 -       if (dentry)
6673 +       if (dentry) {
6674                 dentry->d_lockref.count++;
6675 +               // vx_dentry_inc(dentry);
6676 +       }
6677         return dentry;
6678  }
6679  
6680 diff -NurpP --minimal linux-4.4.161/include/linux/devpts_fs.h linux-4.4.161-vs2.3.9.8/include/linux/devpts_fs.h
6681 --- linux-4.4.161/include/linux/devpts_fs.h     2018-10-20 02:34:30.000000000 +0000
6682 +++ linux-4.4.161-vs2.3.9.8/include/linux/devpts_fs.h   2018-10-20 04:57:21.000000000 +0000
6683 @@ -35,5 +35,4 @@ void devpts_pty_kill(struct inode *inode
6684  
6685  #endif
6686  
6687 -
6688  #endif /* _LINUX_DEVPTS_FS_H */
6689 diff -NurpP --minimal linux-4.4.161/include/linux/fs.h linux-4.4.161-vs2.3.9.8/include/linux/fs.h
6690 --- linux-4.4.161/include/linux/fs.h    2018-10-20 02:34:30.000000000 +0000
6691 +++ linux-4.4.161-vs2.3.9.8/include/linux/fs.h  2018-10-20 04:57:21.000000000 +0000
6692 @@ -227,6 +227,7 @@ typedef void (dax_iodone_t)(struct buffe
6693  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
6694  #define ATTR_TIMES_SET (1 << 16)
6695  #define ATTR_TOUCH     (1 << 17)
6696 +#define ATTR_TAG       (1 << 18)
6697  
6698  /*
6699   * Whiteout is represented by a char device.  The following constants define the
6700 @@ -249,6 +250,7 @@ struct iattr {
6701         umode_t         ia_mode;
6702         kuid_t          ia_uid;
6703         kgid_t          ia_gid;
6704 +       ktag_t          ia_tag;
6705         loff_t          ia_size;
6706         struct timespec ia_atime;
6707         struct timespec ia_mtime;
6708 @@ -587,7 +589,9 @@ struct inode {
6709         unsigned short          i_opflags;
6710         kuid_t                  i_uid;
6711         kgid_t                  i_gid;
6712 -       unsigned int            i_flags;
6713 +       ktag_t                  i_tag;
6714 +       unsigned short          i_flags;
6715 +       unsigned short          i_vflags;
6716  
6717  #ifdef CONFIG_FS_POSIX_ACL
6718         struct posix_acl        *i_acl;
6719 @@ -616,6 +620,7 @@ struct inode {
6720                 unsigned int __i_nlink;
6721         };
6722         dev_t                   i_rdev;
6723 +       dev_t                   i_mdev;
6724         loff_t                  i_size;
6725         struct timespec         i_atime;
6726         struct timespec         i_mtime;
6727 @@ -814,6 +819,11 @@ static inline gid_t i_gid_read(const str
6728         return from_kgid(&init_user_ns, inode->i_gid);
6729  }
6730  
6731 +static inline vtag_t i_tag_read(const struct inode *inode)
6732 +{
6733 +       return from_ktag(&init_user_ns, inode->i_tag);
6734 +}
6735 +
6736  static inline void i_uid_write(struct inode *inode, uid_t uid)
6737  {
6738         inode->i_uid = make_kuid(&init_user_ns, uid);
6739 @@ -824,14 +834,19 @@ static inline void i_gid_write(struct in
6740         inode->i_gid = make_kgid(&init_user_ns, gid);
6741  }
6742  
6743 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
6744 +{
6745 +       inode->i_tag = make_ktag(&init_user_ns, tag);
6746 +}
6747 +
6748  static inline unsigned iminor(const struct inode *inode)
6749  {
6750 -       return MINOR(inode->i_rdev);
6751 +       return MINOR(inode->i_mdev);
6752  }
6753  
6754  static inline unsigned imajor(const struct inode *inode)
6755  {
6756 -       return MAJOR(inode->i_rdev);
6757 +       return MAJOR(inode->i_mdev);
6758  }
6759  
6760  extern struct block_device *I_BDEV(struct inode *inode);
6761 @@ -888,6 +903,7 @@ struct file {
6762         loff_t                  f_pos;
6763         struct fown_struct      f_owner;
6764         const struct cred       *f_cred;
6765 +       vxid_t                  f_xid;
6766         struct file_ra_state    f_ra;
6767  
6768         u64                     f_version;
6769 @@ -1022,6 +1038,7 @@ struct file_lock {
6770         struct file *fl_file;
6771         loff_t fl_start;
6772         loff_t fl_end;
6773 +       vxid_t fl_xid;
6774  
6775         struct fasync_struct *  fl_fasync; /* for lease break notifications */
6776         /* for lease breaks: */
6777 @@ -1699,6 +1716,7 @@ struct inode_operations {
6778         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
6779         ssize_t (*listxattr) (struct dentry *, char *, size_t);
6780         int (*removexattr) (struct dentry *, const char *);
6781 +       int (*sync_flags) (struct inode *, int, int);
6782         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
6783                       u64 len);
6784         int (*update_time)(struct inode *, struct timespec *, int);
6785 @@ -1713,6 +1731,7 @@ ssize_t rw_copy_check_uvector(int type,
6786                               unsigned long nr_segs, unsigned long fast_segs,
6787                               struct iovec *fast_pointer,
6788                               struct iovec **ret_pointer);
6789 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
6790  
6791  extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
6792  extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *);
6793 @@ -1778,6 +1797,14 @@ struct super_operations {
6794  #else
6795  #define S_DAX          0       /* Make all the DAX code disappear */
6796  #endif
6797 +#define S_IXUNLINK     16384   /* Immutable Invert on unlink */
6798 +
6799 +/* Linux-VServer related Inode flags */
6800 +
6801 +#define V_VALID                1
6802 +#define V_XATTR                2
6803 +#define V_BARRIER      4       /* Barrier for chroot() */
6804 +#define V_COW          8       /* Copy on Write */
6805  
6806  /*
6807   * Note that nosuid etc flags are inode-specific: setting some file-system
6808 @@ -1802,10 +1829,13 @@ struct super_operations {
6809  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
6810  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
6811  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
6812 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
6813  
6814  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
6815  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
6816  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
6817 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
6818 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
6819  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
6820  
6821  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
6822 @@ -1820,6 +1850,16 @@ struct super_operations {
6823  #define IS_WHITEOUT(inode)     (S_ISCHR(inode->i_mode) && \
6824                                  (inode)->i_rdev == WHITEOUT_DEV)
6825  
6826 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
6827 +
6828 +#ifdef CONFIG_VSERVER_COWBL
6829 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
6830 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
6831 +#else
6832 +#  define IS_COW(inode)                (0)
6833 +#  define IS_COW_LINK(inode)   (0)
6834 +#endif
6835 +
6836  /*
6837   * Inode state bits.  Protected by inode->i_lock
6838   *
6839 @@ -2076,6 +2116,9 @@ extern struct kobject *fs_kobj;
6840  extern int locks_mandatory_locked(struct file *);
6841  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
6842  
6843 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
6844 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
6845 +
6846  /*
6847   * Candidates for mandatory locking have the setgid bit set
6848   * but no group execute bit -  an otherwise meaningless combination.
6849 @@ -2831,6 +2874,7 @@ extern int dcache_dir_open(struct inode
6850  extern int dcache_dir_close(struct inode *, struct file *);
6851  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
6852  extern int dcache_readdir(struct file *, struct dir_context *);
6853 +extern int dcache_readdir_filter(struct file *, struct dir_context *, int (*)(struct dentry *));
6854  extern int simple_setattr(struct dentry *, struct iattr *);
6855  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
6856  extern int simple_statfs(struct dentry *, struct kstatfs *);
6857 diff -NurpP --minimal linux-4.4.161/include/linux/init_task.h linux-4.4.161-vs2.3.9.8/include/linux/init_task.h
6858 --- linux-4.4.161/include/linux/init_task.h     2016-01-10 23:01:32.000000000 +0000
6859 +++ linux-4.4.161-vs2.3.9.8/include/linux/init_task.h   2018-10-20 04:57:21.000000000 +0000
6860 @@ -260,6 +260,10 @@ extern struct task_group root_task_group
6861         INIT_VTIME(tsk)                                                 \
6862         INIT_NUMA_BALANCING(tsk)                                        \
6863         INIT_KASAN(tsk)                                                 \
6864 +       .xid            = 0,                                            \
6865 +       .vx_info        = NULL,                                         \
6866 +       .nid            = 0,                                            \
6867 +       .nx_info        = NULL,                                         \
6868  }
6869  
6870  
6871 diff -NurpP --minimal linux-4.4.161/include/linux/ipc.h linux-4.4.161-vs2.3.9.8/include/linux/ipc.h
6872 --- linux-4.4.161/include/linux/ipc.h   2016-01-10 23:01:32.000000000 +0000
6873 +++ linux-4.4.161-vs2.3.9.8/include/linux/ipc.h 2018-10-20 04:57:21.000000000 +0000
6874 @@ -16,6 +16,7 @@ struct kern_ipc_perm
6875         key_t           key;
6876         kuid_t          uid;
6877         kgid_t          gid;
6878 +       vxid_t          xid;
6879         kuid_t          cuid;
6880         kgid_t          cgid;
6881         umode_t         mode; 
6882 diff -NurpP --minimal linux-4.4.161/include/linux/memcontrol.h linux-4.4.161-vs2.3.9.8/include/linux/memcontrol.h
6883 --- linux-4.4.161/include/linux/memcontrol.h    2018-10-20 02:34:30.000000000 +0000
6884 +++ linux-4.4.161-vs2.3.9.8/include/linux/memcontrol.h  2018-10-20 04:57:21.000000000 +0000
6885 @@ -113,6 +113,7 @@ struct cg_proto {
6886         struct mem_cgroup       *memcg;
6887  };
6888  
6889 +
6890  #ifdef CONFIG_MEMCG
6891  struct mem_cgroup_stat_cpu {
6892         long count[MEM_CGROUP_STAT_NSTATS];
6893 @@ -338,6 +339,12 @@ static inline bool mem_cgroup_is_descend
6894         return cgroup_is_descendant(memcg->css.cgroup, root->css.cgroup);
6895  }
6896  
6897 +extern unsigned long mem_cgroup_mem_usage_pages(struct mem_cgroup *memcg);
6898 +extern unsigned long mem_cgroup_mem_limit_pages(struct mem_cgroup *memcg);
6899 +extern unsigned long mem_cgroup_memsw_usage_pages(struct mem_cgroup *memcg);
6900 +extern unsigned long mem_cgroup_memsw_limit_pages(struct mem_cgroup *memcg);
6901 +extern void dump_mem_cgroup(struct mem_cgroup *memcg);
6902 +
6903  static inline bool mm_match_cgroup(struct mm_struct *mm,
6904                                    struct mem_cgroup *memcg)
6905  {
6906 diff -NurpP --minimal linux-4.4.161/include/linux/mount.h linux-4.4.161-vs2.3.9.8/include/linux/mount.h
6907 --- linux-4.4.161/include/linux/mount.h 2018-10-20 02:34:30.000000000 +0000
6908 +++ linux-4.4.161-vs2.3.9.8/include/linux/mount.h       2018-10-20 04:57:21.000000000 +0000
6909 @@ -63,6 +63,9 @@ struct mnt_namespace;
6910  #define MNT_MARKED             0x4000000
6911  #define MNT_UMOUNT             0x8000000
6912  
6913 +#define MNT_TAGID      0x10000
6914 +#define MNT_NOTAG      0x20000
6915 +
6916  struct vfsmount {
6917         struct dentry *mnt_root;        /* root of the mounted tree */
6918         struct super_block *mnt_sb;     /* pointer to superblock */
6919 diff -NurpP --minimal linux-4.4.161/include/linux/net.h linux-4.4.161-vs2.3.9.8/include/linux/net.h
6920 --- linux-4.4.161/include/linux/net.h   2018-10-20 02:34:30.000000000 +0000
6921 +++ linux-4.4.161-vs2.3.9.8/include/linux/net.h 2018-10-20 04:57:21.000000000 +0000
6922 @@ -43,6 +43,7 @@ struct net;
6923  #define SOCK_NOSPACE           2
6924  #define SOCK_PASSCRED          3
6925  #define SOCK_PASSSEC           4
6926 +#define SOCK_USER_SOCKET       5
6927  
6928  #ifndef ARCH_HAS_SOCKET_TYPES
6929  /**
6930 diff -NurpP --minimal linux-4.4.161/include/linux/netdevice.h linux-4.4.161-vs2.3.9.8/include/linux/netdevice.h
6931 --- linux-4.4.161/include/linux/netdevice.h     2018-10-20 02:34:30.000000000 +0000
6932 +++ linux-4.4.161-vs2.3.9.8/include/linux/netdevice.h   2018-10-20 04:57:21.000000000 +0000
6933 @@ -2296,6 +2296,7 @@ static inline int dev_recursion_level(vo
6934  
6935  struct net_device *dev_get_by_index(struct net *net, int ifindex);
6936  struct net_device *__dev_get_by_index(struct net *net, int ifindex);
6937 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
6938  struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
6939  int netdev_get_name(struct net *net, char *name, int ifindex);
6940  int dev_restart(struct net_device *dev);
6941 diff -NurpP --minimal linux-4.4.161/include/linux/nsproxy.h linux-4.4.161-vs2.3.9.8/include/linux/nsproxy.h
6942 --- linux-4.4.161/include/linux/nsproxy.h       2016-01-10 23:01:32.000000000 +0000
6943 +++ linux-4.4.161-vs2.3.9.8/include/linux/nsproxy.h     2018-10-20 04:57:21.000000000 +0000
6944 @@ -3,6 +3,7 @@
6945  
6946  #include <linux/spinlock.h>
6947  #include <linux/sched.h>
6948 +#include <linux/vserver/debug.h>
6949  
6950  struct mnt_namespace;
6951  struct uts_namespace;
6952 @@ -63,6 +64,7 @@ extern struct nsproxy init_nsproxy;
6953   */
6954  
6955  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
6956 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
6957  void exit_task_namespaces(struct task_struct *tsk);
6958  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
6959  void free_nsproxy(struct nsproxy *ns);
6960 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
6961         struct cred *, struct fs_struct *);
6962  int __init nsproxy_cache_init(void);
6963  
6964 -static inline void put_nsproxy(struct nsproxy *ns)
6965 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
6966 +
6967 +static inline void __get_nsproxy(struct nsproxy *ns,
6968 +       const char *_file, int _line)
6969  {
6970 -       if (atomic_dec_and_test(&ns->count)) {
6971 -               free_nsproxy(ns);
6972 -       }
6973 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
6974 +               ns, atomic_read(&ns->count), _file, _line);
6975 +       atomic_inc(&ns->count);
6976  }
6977  
6978 -static inline void get_nsproxy(struct nsproxy *ns)
6979 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
6980 +
6981 +static inline void __put_nsproxy(struct nsproxy *ns,
6982 +       const char *_file, int _line)
6983  {
6984 -       atomic_inc(&ns->count);
6985 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
6986 +               ns, atomic_read(&ns->count), _file, _line);
6987 +       if (atomic_dec_and_test(&ns->count)) {
6988 +               free_nsproxy(ns);
6989 +       }
6990  }
6991  
6992  #endif
6993 diff -NurpP --minimal linux-4.4.161/include/linux/pid.h linux-4.4.161-vs2.3.9.8/include/linux/pid.h
6994 --- linux-4.4.161/include/linux/pid.h   2018-10-20 02:34:30.000000000 +0000
6995 +++ linux-4.4.161-vs2.3.9.8/include/linux/pid.h 2018-10-20 04:57:21.000000000 +0000
6996 @@ -10,7 +10,8 @@ enum pid_type
6997         PIDTYPE_SID,
6998         PIDTYPE_MAX,
6999         /* only valid to __task_pid_nr_ns() */
7000 -       __PIDTYPE_TGID
7001 +       __PIDTYPE_TGID,
7002 +       __PIDTYPE_REALPID
7003  };
7004  
7005  /*
7006 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
7007  }
7008  
7009  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7010 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7011  pid_t pid_vnr(struct pid *pid);
7012  
7013  #define do_each_pid_task(pid, type, task)                              \
7014 diff -NurpP --minimal linux-4.4.161/include/linux/quotaops.h linux-4.4.161-vs2.3.9.8/include/linux/quotaops.h
7015 --- linux-4.4.161/include/linux/quotaops.h      2016-01-10 23:01:32.000000000 +0000
7016 +++ linux-4.4.161-vs2.3.9.8/include/linux/quotaops.h    2018-10-20 04:57:21.000000000 +0000
7017 @@ -8,6 +8,7 @@
7018  #define _LINUX_QUOTAOPS_
7019  
7020  #include <linux/fs.h>
7021 +#include <linux/vs_dlimit.h>
7022  
7023  #define DQUOT_SPACE_WARN       0x1
7024  #define DQUOT_SPACE_RESERVE    0x2
7025 @@ -211,11 +212,12 @@ static inline void dquot_drop(struct ino
7026  
7027  static inline int dquot_alloc_inode(struct inode *inode)
7028  {
7029 -       return 0;
7030 +       return dl_alloc_inode(inode);
7031  }
7032  
7033  static inline void dquot_free_inode(struct inode *inode)
7034  {
7035 +       dl_free_inode(inode);
7036  }
7037  
7038  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7039 @@ -226,6 +228,10 @@ static inline int dquot_transfer(struct
7040  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7041                 int flags)
7042  {
7043 +       int ret = 0;
7044 +
7045 +       if ((ret = dl_alloc_space(inode, number)))
7046 +               return ret;
7047         if (!(flags & DQUOT_SPACE_RESERVE))
7048                 inode_add_bytes(inode, number);
7049         return 0;
7050 @@ -236,6 +242,7 @@ static inline void __dquot_free_space(st
7051  {
7052         if (!(flags & DQUOT_SPACE_RESERVE))
7053                 inode_sub_bytes(inode, number);
7054 +       dl_free_space(inode, number);
7055  }
7056  
7057  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7058 diff -NurpP --minimal linux-4.4.161/include/linux/sched.h linux-4.4.161-vs2.3.9.8/include/linux/sched.h
7059 --- linux-4.4.161/include/linux/sched.h 2018-10-20 02:34:30.000000000 +0000
7060 +++ linux-4.4.161-vs2.3.9.8/include/linux/sched.h       2018-10-20 05:50:20.000000000 +0000
7061 @@ -1601,6 +1601,14 @@ struct task_struct {
7062  #endif
7063         struct seccomp seccomp;
7064  
7065 +/* vserver context data */
7066 +       struct vx_info *vx_info;
7067 +       struct nx_info *nx_info;
7068 +
7069 +       vxid_t xid;
7070 +       vnid_t nid;
7071 +       vtag_t tag;
7072 +
7073  /* Thread group tracking */
7074         u32 parent_exec_id;
7075         u32 self_exec_id;
7076 @@ -1928,6 +1936,11 @@ struct pid_namespace;
7077  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
7078                         struct pid_namespace *ns);
7079  
7080 +#include <linux/vserver/base.h>
7081 +#include <linux/vserver/context.h>
7082 +#include <linux/vserver/debug.h>
7083 +#include <linux/vserver/pid.h>
7084 +
7085  static inline pid_t task_pid_nr(struct task_struct *tsk)
7086  {
7087         return tsk->pid;
7088 @@ -1941,7 +1954,8 @@ static inline pid_t task_pid_nr_ns(struc
7089  
7090  static inline pid_t task_pid_vnr(struct task_struct *tsk)
7091  {
7092 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7093 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7094 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
7095  }
7096  
7097  
7098 diff -NurpP --minimal linux-4.4.161/include/linux/shmem_fs.h linux-4.4.161-vs2.3.9.8/include/linux/shmem_fs.h
7099 --- linux-4.4.161/include/linux/shmem_fs.h      2018-10-20 02:34:30.000000000 +0000
7100 +++ linux-4.4.161-vs2.3.9.8/include/linux/shmem_fs.h    2018-10-20 04:57:21.000000000 +0000
7101 @@ -10,6 +10,9 @@
7102  
7103  /* inode in-kernel data */
7104  
7105 +#define TMPFS_SUPER_MAGIC      0x01021994
7106 +
7107 +
7108  struct shmem_inode_info {
7109         spinlock_t              lock;
7110         unsigned int            seals;          /* shmem seals */
7111 diff -NurpP --minimal linux-4.4.161/include/linux/stat.h linux-4.4.161-vs2.3.9.8/include/linux/stat.h
7112 --- linux-4.4.161/include/linux/stat.h  2016-01-10 23:01:32.000000000 +0000
7113 +++ linux-4.4.161-vs2.3.9.8/include/linux/stat.h        2018-10-20 04:57:21.000000000 +0000
7114 @@ -25,6 +25,7 @@ struct kstat {
7115         unsigned int    nlink;
7116         kuid_t          uid;
7117         kgid_t          gid;
7118 +       ktag_t          tag;
7119         dev_t           rdev;
7120         loff_t          size;
7121         struct timespec  atime;
7122 diff -NurpP --minimal linux-4.4.161/include/linux/sunrpc/auth.h linux-4.4.161-vs2.3.9.8/include/linux/sunrpc/auth.h
7123 --- linux-4.4.161/include/linux/sunrpc/auth.h   2016-01-10 23:01:32.000000000 +0000
7124 +++ linux-4.4.161-vs2.3.9.8/include/linux/sunrpc/auth.h 2018-10-20 04:57:21.000000000 +0000
7125 @@ -40,6 +40,7 @@ enum {
7126  struct auth_cred {
7127         kuid_t  uid;
7128         kgid_t  gid;
7129 +       ktag_t  tag;
7130         struct group_info *group_info;
7131         const char *principal;
7132         unsigned long ac_flags;
7133 diff -NurpP --minimal linux-4.4.161/include/linux/sunrpc/clnt.h linux-4.4.161-vs2.3.9.8/include/linux/sunrpc/clnt.h
7134 --- linux-4.4.161/include/linux/sunrpc/clnt.h   2018-10-20 02:34:30.000000000 +0000
7135 +++ linux-4.4.161-vs2.3.9.8/include/linux/sunrpc/clnt.h 2018-10-20 04:57:21.000000000 +0000
7136 @@ -51,7 +51,8 @@ struct rpc_clnt {
7137                                 cl_discrtry : 1,/* disconnect before retry */
7138                                 cl_noretranstimeo: 1,/* No retransmit timeouts */
7139                                 cl_autobind : 1,/* use getport() */
7140 -                               cl_chatty   : 1;/* be verbose */
7141 +                               cl_chatty   : 1,/* be verbose */
7142 +                               cl_tag      : 1;/* context tagging */
7143  
7144         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
7145         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
7146 diff -NurpP --minimal linux-4.4.161/include/linux/types.h linux-4.4.161-vs2.3.9.8/include/linux/types.h
7147 --- linux-4.4.161/include/linux/types.h 2016-01-10 23:01:32.000000000 +0000
7148 +++ linux-4.4.161-vs2.3.9.8/include/linux/types.h       2018-10-20 04:57:21.000000000 +0000
7149 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
7150  typedef __kernel_gid32_t       gid_t;
7151  typedef __kernel_uid16_t        uid16_t;
7152  typedef __kernel_gid16_t        gid16_t;
7153 +typedef unsigned int           vxid_t;
7154 +typedef unsigned int           vnid_t;
7155 +typedef unsigned int           vtag_t;
7156  
7157  typedef unsigned long          uintptr_t;
7158  
7159 diff -NurpP --minimal linux-4.4.161/include/linux/uidgid.h linux-4.4.161-vs2.3.9.8/include/linux/uidgid.h
7160 --- linux-4.4.161/include/linux/uidgid.h        2016-01-10 23:01:32.000000000 +0000
7161 +++ linux-4.4.161-vs2.3.9.8/include/linux/uidgid.h      2018-10-20 04:57:21.000000000 +0000
7162 @@ -21,13 +21,17 @@ typedef struct {
7163         uid_t val;
7164  } kuid_t;
7165  
7166 -
7167  typedef struct {
7168         gid_t val;
7169  } kgid_t;
7170  
7171 +typedef struct {
7172 +       vtag_t val;
7173 +} ktag_t;
7174 +
7175  #define KUIDT_INIT(value) (kuid_t){ value }
7176  #define KGIDT_INIT(value) (kgid_t){ value }
7177 +#define KTAGT_INIT(value) (ktag_t){ value }
7178  
7179  #ifdef CONFIG_MULTIUSER
7180  static inline uid_t __kuid_val(kuid_t uid)
7181 @@ -51,11 +55,18 @@ static inline gid_t __kgid_val(kgid_t gi
7182  }
7183  #endif
7184  
7185 +static inline vtag_t __ktag_val(ktag_t tag)
7186 +{
7187 +       return tag.val;
7188 +}
7189 +
7190  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
7191  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
7192 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
7193  
7194  #define INVALID_UID KUIDT_INIT(-1)
7195  #define INVALID_GID KGIDT_INIT(-1)
7196 +#define INVALID_TAG KTAGT_INIT(-1)
7197  
7198  static inline bool uid_eq(kuid_t left, kuid_t right)
7199  {
7200 @@ -67,6 +78,11 @@ static inline bool gid_eq(kgid_t left, k
7201         return __kgid_val(left) == __kgid_val(right);
7202  }
7203  
7204 +static inline bool tag_eq(ktag_t left, ktag_t right)
7205 +{
7206 +       return __ktag_val(left) == __ktag_val(right);
7207 +}
7208 +
7209  static inline bool uid_gt(kuid_t left, kuid_t right)
7210  {
7211         return __kuid_val(left) > __kuid_val(right);
7212 @@ -117,13 +133,21 @@ static inline bool gid_valid(kgid_t gid)
7213         return __kgid_val(gid) != (gid_t) -1;
7214  }
7215  
7216 +static inline bool tag_valid(ktag_t tag)
7217 +{
7218 +       return !tag_eq(tag, INVALID_TAG);
7219 +}
7220 +
7221  #ifdef CONFIG_USER_NS
7222  
7223  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
7224  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
7225 +extern ktag_t make_ktag(struct user_namespace *from, gid_t gid);
7226  
7227  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
7228  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
7229 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
7230 +
7231  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
7232  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
7233  
7234 @@ -149,6 +173,11 @@ static inline kgid_t make_kgid(struct us
7235         return KGIDT_INIT(gid);
7236  }
7237  
7238 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
7239 +{
7240 +       return KTAGT_INIT(tag);
7241 +}
7242 +
7243  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
7244  {
7245         return __kuid_val(kuid);
7246 @@ -159,6 +188,11 @@ static inline gid_t from_kgid(struct use
7247         return __kgid_val(kgid);
7248  }
7249  
7250 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
7251 +{
7252 +       return __ktag_val(ktag);
7253 +}
7254 +
7255  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
7256  {
7257         uid_t uid = from_kuid(to, kuid);
7258 diff -NurpP --minimal linux-4.4.161/include/linux/vroot.h linux-4.4.161-vs2.3.9.8/include/linux/vroot.h
7259 --- linux-4.4.161/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
7260 +++ linux-4.4.161-vs2.3.9.8/include/linux/vroot.h       2018-10-20 04:57:21.000000000 +0000
7261 @@ -0,0 +1,51 @@
7262 +
7263 +/*
7264 + * include/linux/vroot.h
7265 + *
7266 + * written by Herbert P?tzl, 9/11/2002
7267 + * ported to 2.6 by Herbert P?tzl, 30/12/2004
7268 + *
7269 + * Copyright (C) 2002-2007 by Herbert P?tzl.
7270 + * Redistribution of this file is permitted under the
7271 + * GNU General Public License.
7272 + */
7273 +
7274 +#ifndef _LINUX_VROOT_H
7275 +#define _LINUX_VROOT_H
7276 +
7277 +
7278 +#ifdef __KERNEL__
7279 +
7280 +/* Possible states of device */
7281 +enum {
7282 +       Vr_unbound,
7283 +       Vr_bound,
7284 +};
7285 +
7286 +struct vroot_device {
7287 +       int             vr_number;
7288 +       int             vr_refcnt;
7289 +
7290 +       struct semaphore        vr_ctl_mutex;
7291 +       struct block_device    *vr_device;
7292 +       int                     vr_state;
7293 +};
7294 +
7295 +
7296 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
7297 +
7298 +extern int register_vroot_grb(vroot_grb_func *);
7299 +extern int unregister_vroot_grb(vroot_grb_func *);
7300 +
7301 +#endif /* __KERNEL__ */
7302 +
7303 +#define MAX_VROOT_DEFAULT      8
7304 +
7305 +/*
7306 + * IOCTL commands --- we will commandeer 0x56 ('V')
7307 + */
7308 +
7309 +#define VROOT_SET_DEV          0x5600
7310 +#define VROOT_CLR_DEV          0x5601
7311 +
7312 +#endif /* _LINUX_VROOT_H */
7313 diff -NurpP --minimal linux-4.4.161/include/linux/vs_base.h linux-4.4.161-vs2.3.9.8/include/linux/vs_base.h
7314 --- linux-4.4.161/include/linux/vs_base.h       1970-01-01 00:00:00.000000000 +0000
7315 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_base.h     2018-10-20 04:57:21.000000000 +0000
7316 @@ -0,0 +1,10 @@
7317 +#ifndef _VS_BASE_H
7318 +#define _VS_BASE_H
7319 +
7320 +#include "vserver/base.h"
7321 +#include "vserver/check.h"
7322 +#include "vserver/debug.h"
7323 +
7324 +#else
7325 +#warning duplicate inclusion
7326 +#endif
7327 diff -NurpP --minimal linux-4.4.161/include/linux/vs_context.h linux-4.4.161-vs2.3.9.8/include/linux/vs_context.h
7328 --- linux-4.4.161/include/linux/vs_context.h    1970-01-01 00:00:00.000000000 +0000
7329 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_context.h  2018-10-20 04:57:21.000000000 +0000
7330 @@ -0,0 +1,242 @@
7331 +#ifndef _VS_CONTEXT_H
7332 +#define _VS_CONTEXT_H
7333 +
7334 +#include "vserver/base.h"
7335 +#include "vserver/check.h"
7336 +#include "vserver/context.h"
7337 +#include "vserver/history.h"
7338 +#include "vserver/debug.h"
7339 +
7340 +#include <linux/sched.h>
7341 +
7342 +
7343 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
7344 +
7345 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
7346 +       const char *_file, int _line, void *_here)
7347 +{
7348 +       if (!vxi)
7349 +               return NULL;
7350 +
7351 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
7352 +               vxi, vxi ? vxi->vx_id : 0,
7353 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7354 +               _file, _line);
7355 +       __vxh_get_vx_info(vxi, _here);
7356 +
7357 +       atomic_inc(&vxi->vx_usecnt);
7358 +       return vxi;
7359 +}
7360 +
7361 +
7362 +extern void free_vx_info(struct vx_info *);
7363 +
7364 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
7365 +
7366 +static inline void __put_vx_info(struct vx_info *vxi,
7367 +       const char *_file, int _line, void *_here)
7368 +{
7369 +       if (!vxi)
7370 +               return;
7371 +
7372 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
7373 +               vxi, vxi ? vxi->vx_id : 0,
7374 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7375 +               _file, _line);
7376 +       __vxh_put_vx_info(vxi, _here);
7377 +
7378 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
7379 +               free_vx_info(vxi);
7380 +}
7381 +
7382 +
7383 +#define init_vx_info(p, i) \
7384 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7385 +
7386 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7387 +       const char *_file, int _line, void *_here)
7388 +{
7389 +       if (vxi) {
7390 +               vxlprintk(VXD_CBIT(xid, 3),
7391 +                       "init_vx_info(%p[#%d.%d])",
7392 +                       vxi, vxi ? vxi->vx_id : 0,
7393 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7394 +                       _file, _line);
7395 +               __vxh_init_vx_info(vxi, vxp, _here);
7396 +
7397 +               atomic_inc(&vxi->vx_usecnt);
7398 +       }
7399 +       *vxp = vxi;
7400 +}
7401 +
7402 +
7403 +#define set_vx_info(p, i) \
7404 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7405 +
7406 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7407 +       const char *_file, int _line, void *_here)
7408 +{
7409 +       struct vx_info *vxo;
7410 +
7411 +       if (!vxi)
7412 +               return;
7413 +
7414 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
7415 +               vxi, vxi ? vxi->vx_id : 0,
7416 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7417 +               _file, _line);
7418 +       __vxh_set_vx_info(vxi, vxp, _here);
7419 +
7420 +       atomic_inc(&vxi->vx_usecnt);
7421 +       vxo = xchg(vxp, vxi);
7422 +       BUG_ON(vxo);
7423 +}
7424 +
7425 +
7426 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
7427 +
7428 +static inline void __clr_vx_info(struct vx_info **vxp,
7429 +       const char *_file, int _line, void *_here)
7430 +{
7431 +       struct vx_info *vxo;
7432 +
7433 +       vxo = xchg(vxp, NULL);
7434 +       if (!vxo)
7435 +               return;
7436 +
7437 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
7438 +               vxo, vxo ? vxo->vx_id : 0,
7439 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
7440 +               _file, _line);
7441 +       __vxh_clr_vx_info(vxo, vxp, _here);
7442 +
7443 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
7444 +               free_vx_info(vxo);
7445 +}
7446 +
7447 +
7448 +#define claim_vx_info(v, p) \
7449 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7450 +
7451 +static inline void __claim_vx_info(struct vx_info *vxi,
7452 +       struct task_struct *task,
7453 +       const char *_file, int _line, void *_here)
7454 +{
7455 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
7456 +               vxi, vxi ? vxi->vx_id : 0,
7457 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7458 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7459 +               task, _file, _line);
7460 +       __vxh_claim_vx_info(vxi, task, _here);
7461 +
7462 +       atomic_inc(&vxi->vx_tasks);
7463 +}
7464 +
7465 +
7466 +extern void unhash_vx_info(struct vx_info *);
7467 +
7468 +#define release_vx_info(v, p) \
7469 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7470 +
7471 +static inline void __release_vx_info(struct vx_info *vxi,
7472 +       struct task_struct *task,
7473 +       const char *_file, int _line, void *_here)
7474 +{
7475 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
7476 +               vxi, vxi ? vxi->vx_id : 0,
7477 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7478 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7479 +               task, _file, _line);
7480 +       __vxh_release_vx_info(vxi, task, _here);
7481 +
7482 +       might_sleep();
7483 +
7484 +       if (atomic_dec_and_test(&vxi->vx_tasks))
7485 +               unhash_vx_info(vxi);
7486 +}
7487 +
7488 +
7489 +#define task_get_vx_info(p) \
7490 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
7491 +
7492 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
7493 +       const char *_file, int _line, void *_here)
7494 +{
7495 +       struct vx_info *vxi;
7496 +
7497 +       task_lock(p);
7498 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
7499 +               p, _file, _line);
7500 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
7501 +       task_unlock(p);
7502 +       return vxi;
7503 +}
7504 +
7505 +
7506 +static inline void __wakeup_vx_info(struct vx_info *vxi)
7507 +{
7508 +       if (waitqueue_active(&vxi->vx_wait))
7509 +               wake_up_interruptible(&vxi->vx_wait);
7510 +}
7511 +
7512 +
7513 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
7514 +
7515 +static inline void __enter_vx_info(struct vx_info *vxi,
7516 +       struct vx_info_save *vxis, const char *_file, int _line)
7517 +{
7518 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
7519 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
7520 +               current->xid, current->vx_info, _file, _line);
7521 +       vxis->vxi = xchg(&current->vx_info, vxi);
7522 +       vxis->xid = current->xid;
7523 +       current->xid = vxi ? vxi->vx_id : 0;
7524 +}
7525 +
7526 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
7527 +
7528 +static inline void __leave_vx_info(struct vx_info_save *vxis,
7529 +       const char *_file, int _line)
7530 +{
7531 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
7532 +               vxis, vxis->xid, vxis->vxi, current,
7533 +               current->xid, current->vx_info, _file, _line);
7534 +       (void)xchg(&current->vx_info, vxis->vxi);
7535 +       current->xid = vxis->xid;
7536 +}
7537 +
7538 +
7539 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
7540 +{
7541 +       vxis->vxi = xchg(&current->vx_info, NULL);
7542 +       vxis->xid = xchg(&current->xid, (vxid_t)0);
7543 +}
7544 +
7545 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
7546 +{
7547 +       (void)xchg(&current->xid, vxis->xid);
7548 +       (void)xchg(&current->vx_info, vxis->vxi);
7549 +}
7550 +
7551 +#define task_is_init(p) \
7552 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
7553 +
7554 +static inline int __task_is_init(struct task_struct *p,
7555 +       const char *_file, int _line, void *_here)
7556 +{
7557 +       int is_init = is_global_init(p);
7558 +
7559 +       task_lock(p);
7560 +       if (p->vx_info)
7561 +               is_init = p->vx_info->vx_initpid == p->pid;
7562 +       task_unlock(p);
7563 +       return is_init;
7564 +}
7565 +
7566 +extern void exit_vx_info(struct task_struct *, int);
7567 +extern void exit_vx_info_early(struct task_struct *, int);
7568 +
7569 +
7570 +#else
7571 +#warning duplicate inclusion
7572 +#endif
7573 diff -NurpP --minimal linux-4.4.161/include/linux/vs_cowbl.h linux-4.4.161-vs2.3.9.8/include/linux/vs_cowbl.h
7574 --- linux-4.4.161/include/linux/vs_cowbl.h      1970-01-01 00:00:00.000000000 +0000
7575 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_cowbl.h    2018-10-20 04:57:21.000000000 +0000
7576 @@ -0,0 +1,48 @@
7577 +#ifndef _VS_COWBL_H
7578 +#define _VS_COWBL_H
7579 +
7580 +#include <linux/fs.h>
7581 +#include <linux/dcache.h>
7582 +#include <linux/namei.h>
7583 +#include <linux/slab.h>
7584 +
7585 +extern struct dentry *cow_break_link(const char *pathname);
7586 +
7587 +static inline int cow_check_and_break(struct path *path)
7588 +{
7589 +       struct inode *inode = path->dentry->d_inode;
7590 +       int error = 0;
7591 +
7592 +       /* do we need this check? */
7593 +       if (IS_RDONLY(inode))
7594 +               return -EROFS;
7595 +
7596 +       if (IS_COW(inode)) {
7597 +               if (IS_COW_LINK(inode)) {
7598 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
7599 +                       char *pp, *buf;
7600 +
7601 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
7602 +                       if (!buf) {
7603 +                               return -ENOMEM;
7604 +                       }
7605 +                       pp = d_path(path, buf, PATH_MAX);
7606 +                       new_dentry = cow_break_link(pp);
7607 +                       kfree(buf);
7608 +                       if (!IS_ERR(new_dentry)) {
7609 +                               path->dentry = new_dentry;
7610 +                               dput(old_dentry);
7611 +                       } else
7612 +                               error = PTR_ERR(new_dentry);
7613 +               } else {
7614 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
7615 +                       inode->i_ctime = CURRENT_TIME;
7616 +                       mark_inode_dirty(inode);
7617 +               }
7618 +       }
7619 +       return error;
7620 +}
7621 +
7622 +#else
7623 +#warning duplicate inclusion
7624 +#endif
7625 diff -NurpP --minimal linux-4.4.161/include/linux/vs_cvirt.h linux-4.4.161-vs2.3.9.8/include/linux/vs_cvirt.h
7626 --- linux-4.4.161/include/linux/vs_cvirt.h      1970-01-01 00:00:00.000000000 +0000
7627 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_cvirt.h    2018-10-20 04:57:21.000000000 +0000
7628 @@ -0,0 +1,50 @@
7629 +#ifndef _VS_CVIRT_H
7630 +#define _VS_CVIRT_H
7631 +
7632 +#include "vserver/cvirt.h"
7633 +#include "vserver/context.h"
7634 +#include "vserver/base.h"
7635 +#include "vserver/check.h"
7636 +#include "vserver/debug.h"
7637 +
7638 +
7639 +static inline void vx_activate_task(struct task_struct *p)
7640 +{
7641 +       struct vx_info *vxi;
7642 +
7643 +       if ((vxi = p->vx_info)) {
7644 +               vx_update_load(vxi);
7645 +               atomic_inc(&vxi->cvirt.nr_running);
7646 +       }
7647 +}
7648 +
7649 +static inline void vx_deactivate_task(struct task_struct *p)
7650 +{
7651 +       struct vx_info *vxi;
7652 +
7653 +       if ((vxi = p->vx_info)) {
7654 +               vx_update_load(vxi);
7655 +               atomic_dec(&vxi->cvirt.nr_running);
7656 +       }
7657 +}
7658 +
7659 +static inline void vx_uninterruptible_inc(struct task_struct *p)
7660 +{
7661 +       struct vx_info *vxi;
7662 +
7663 +       if ((vxi = p->vx_info))
7664 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
7665 +}
7666 +
7667 +static inline void vx_uninterruptible_dec(struct task_struct *p)
7668 +{
7669 +       struct vx_info *vxi;
7670 +
7671 +       if ((vxi = p->vx_info))
7672 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
7673 +}
7674 +
7675 +
7676 +#else
7677 +#warning duplicate inclusion
7678 +#endif
7679 diff -NurpP --minimal linux-4.4.161/include/linux/vs_device.h linux-4.4.161-vs2.3.9.8/include/linux/vs_device.h
7680 --- linux-4.4.161/include/linux/vs_device.h     1970-01-01 00:00:00.000000000 +0000
7681 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_device.h   2018-10-20 04:57:21.000000000 +0000
7682 @@ -0,0 +1,45 @@
7683 +#ifndef _VS_DEVICE_H
7684 +#define _VS_DEVICE_H
7685 +
7686 +#include "vserver/base.h"
7687 +#include "vserver/device.h"
7688 +#include "vserver/debug.h"
7689 +
7690 +
7691 +#ifdef CONFIG_VSERVER_DEVICE
7692 +
7693 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
7694 +
7695 +#define vs_device_perm(v, d, m, p) \
7696 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
7697 +
7698 +#else
7699 +
7700 +static inline
7701 +int vs_map_device(struct vx_info *vxi,
7702 +       dev_t device, dev_t *target, umode_t mode)
7703 +{
7704 +       if (target)
7705 +               *target = device;
7706 +       return ~0;
7707 +}
7708 +
7709 +#define vs_device_perm(v, d, m, p) ((p) == (p))
7710 +
7711 +#endif
7712 +
7713 +
7714 +#define vs_map_chrdev(d, t, p) \
7715 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
7716 +#define vs_map_blkdev(d, t, p) \
7717 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
7718 +
7719 +#define vs_chrdev_perm(d, p) \
7720 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
7721 +#define vs_blkdev_perm(d, p) \
7722 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
7723 +
7724 +
7725 +#else
7726 +#warning duplicate inclusion
7727 +#endif
7728 diff -NurpP --minimal linux-4.4.161/include/linux/vs_dlimit.h linux-4.4.161-vs2.3.9.8/include/linux/vs_dlimit.h
7729 --- linux-4.4.161/include/linux/vs_dlimit.h     1970-01-01 00:00:00.000000000 +0000
7730 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_dlimit.h   2018-10-20 04:57:21.000000000 +0000
7731 @@ -0,0 +1,215 @@
7732 +#ifndef _VS_DLIMIT_H
7733 +#define _VS_DLIMIT_H
7734 +
7735 +#include <linux/fs.h>
7736 +
7737 +#include "vserver/dlimit.h"
7738 +#include "vserver/base.h"
7739 +#include "vserver/debug.h"
7740 +
7741 +
7742 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
7743 +
7744 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
7745 +       const char *_file, int _line)
7746 +{
7747 +       if (!dli)
7748 +               return NULL;
7749 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
7750 +               dli, dli ? dli->dl_tag : 0,
7751 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
7752 +               _file, _line);
7753 +       atomic_inc(&dli->dl_usecnt);
7754 +       return dli;
7755 +}
7756 +
7757 +
7758 +#define free_dl_info(i) \
7759 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
7760 +
7761 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
7762 +
7763 +static inline void __put_dl_info(struct dl_info *dli,
7764 +       const char *_file, int _line)
7765 +{
7766 +       if (!dli)
7767 +               return;
7768 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
7769 +               dli, dli ? dli->dl_tag : 0,
7770 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
7771 +               _file, _line);
7772 +       if (atomic_dec_and_test(&dli->dl_usecnt))
7773 +               free_dl_info(dli);
7774 +}
7775 +
7776 +
7777 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
7778 +
7779 +static inline int __dl_alloc_space(struct super_block *sb,
7780 +       vtag_t tag, dlsize_t nr, const char *file, int line)
7781 +{
7782 +       struct dl_info *dli = NULL;
7783 +       int ret = 0;
7784 +
7785 +       if (nr == 0)
7786 +               goto out;
7787 +       dli = locate_dl_info(sb, tag);
7788 +       if (!dli)
7789 +               goto out;
7790 +
7791 +       spin_lock(&dli->dl_lock);
7792 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
7793 +       if (!ret)
7794 +               dli->dl_space_used += nr;
7795 +       spin_unlock(&dli->dl_lock);
7796 +       put_dl_info(dli);
7797 +out:
7798 +       vxlprintk(VXD_CBIT(dlim, 1),
7799 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
7800 +               sb, tag, __dlimit_char(dli), (long long)nr,
7801 +               ret, file, line);
7802 +       return ret ? -ENOSPC : 0;
7803 +}
7804 +
7805 +static inline void __dl_free_space(struct super_block *sb,
7806 +       vtag_t tag, dlsize_t nr, const char *_file, int _line)
7807 +{
7808 +       struct dl_info *dli = NULL;
7809 +
7810 +       if (nr == 0)
7811 +               goto out;
7812 +       dli = locate_dl_info(sb, tag);
7813 +       if (!dli)
7814 +               goto out;
7815 +
7816 +       spin_lock(&dli->dl_lock);
7817 +       if (dli->dl_space_used > nr)
7818 +               dli->dl_space_used -= nr;
7819 +       else
7820 +               dli->dl_space_used = 0;
7821 +       spin_unlock(&dli->dl_lock);
7822 +       put_dl_info(dli);
7823 +out:
7824 +       vxlprintk(VXD_CBIT(dlim, 1),
7825 +               "FREE  (%p,#%d)%c %lld bytes",
7826 +               sb, tag, __dlimit_char(dli), (long long)nr,
7827 +               _file, _line);
7828 +}
7829 +
7830 +static inline int __dl_alloc_inode(struct super_block *sb,
7831 +       vtag_t tag, const char *_file, int _line)
7832 +{
7833 +       struct dl_info *dli;
7834 +       int ret = 0;
7835 +
7836 +       dli = locate_dl_info(sb, tag);
7837 +       if (!dli)
7838 +               goto out;
7839 +
7840 +       spin_lock(&dli->dl_lock);
7841 +       dli->dl_inodes_used++;
7842 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
7843 +       spin_unlock(&dli->dl_lock);
7844 +       put_dl_info(dli);
7845 +out:
7846 +       vxlprintk(VXD_CBIT(dlim, 0),
7847 +               "ALLOC (%p,#%d)%c inode (%d)",
7848 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
7849 +       return ret ? -ENOSPC : 0;
7850 +}
7851 +
7852 +static inline void __dl_free_inode(struct super_block *sb,
7853 +       vtag_t tag, const char *_file, int _line)
7854 +{
7855 +       struct dl_info *dli;
7856 +
7857 +       dli = locate_dl_info(sb, tag);
7858 +       if (!dli)
7859 +               goto out;
7860 +
7861 +       spin_lock(&dli->dl_lock);
7862 +       if (dli->dl_inodes_used > 1)
7863 +               dli->dl_inodes_used--;
7864 +       else
7865 +               dli->dl_inodes_used = 0;
7866 +       spin_unlock(&dli->dl_lock);
7867 +       put_dl_info(dli);
7868 +out:
7869 +       vxlprintk(VXD_CBIT(dlim, 0),
7870 +               "FREE  (%p,#%d)%c inode",
7871 +               sb, tag, __dlimit_char(dli), _file, _line);
7872 +}
7873 +
7874 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
7875 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
7876 +       const char *_file, int _line)
7877 +{
7878 +       struct dl_info *dli;
7879 +       uint64_t broot, bfree;
7880 +
7881 +       dli = locate_dl_info(sb, tag);
7882 +       if (!dli)
7883 +               return;
7884 +
7885 +       spin_lock(&dli->dl_lock);
7886 +       broot = (dli->dl_space_total -
7887 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
7888 +               >> sb->s_blocksize_bits;
7889 +       bfree = (dli->dl_space_total - dli->dl_space_used)
7890 +                       >> sb->s_blocksize_bits;
7891 +       spin_unlock(&dli->dl_lock);
7892 +
7893 +       vxlprintk(VXD_CBIT(dlim, 2),
7894 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
7895 +               (long long)bfree, (long long)broot,
7896 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
7897 +               _file, _line);
7898 +       if (free_blocks) {
7899 +               if (*free_blocks > bfree)
7900 +                       *free_blocks = bfree;
7901 +       }
7902 +       if (root_blocks) {
7903 +               if (*root_blocks > broot)
7904 +                       *root_blocks = broot;
7905 +       }
7906 +       put_dl_info(dli);
7907 +}
7908 +
7909 +#define dl_prealloc_space(in, bytes) \
7910 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7911 +               __FILE__, __LINE__ )
7912 +
7913 +#define dl_alloc_space(in, bytes) \
7914 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7915 +               __FILE__, __LINE__ )
7916 +
7917 +#define dl_reserve_space(in, bytes) \
7918 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7919 +               __FILE__, __LINE__ )
7920 +
7921 +#define dl_claim_space(in, bytes) (0)
7922 +
7923 +#define dl_release_space(in, bytes) \
7924 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7925 +               __FILE__, __LINE__ )
7926 +
7927 +#define dl_free_space(in, bytes) \
7928 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
7929 +               __FILE__, __LINE__ )
7930 +
7931 +
7932 +
7933 +#define dl_alloc_inode(in) \
7934 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
7935 +
7936 +#define dl_free_inode(in) \
7937 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
7938 +
7939 +
7940 +#define dl_adjust_block(sb, tag, fb, rb) \
7941 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
7942 +
7943 +
7944 +#else
7945 +#warning duplicate inclusion
7946 +#endif
7947 diff -NurpP --minimal linux-4.4.161/include/linux/vs_inet.h linux-4.4.161-vs2.3.9.8/include/linux/vs_inet.h
7948 --- linux-4.4.161/include/linux/vs_inet.h       1970-01-01 00:00:00.000000000 +0000
7949 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_inet.h     2018-10-20 04:57:21.000000000 +0000
7950 @@ -0,0 +1,364 @@
7951 +#ifndef _VS_INET_H
7952 +#define _VS_INET_H
7953 +
7954 +#include "vserver/base.h"
7955 +#include "vserver/network.h"
7956 +#include "vserver/debug.h"
7957 +
7958 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
7959 +
7960 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
7961 +                       NIPQUAD((a)->mask), (a)->type
7962 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
7963 +
7964 +#define NIPQUAD(addr) \
7965 +       ((unsigned char *)&addr)[0], \
7966 +       ((unsigned char *)&addr)[1], \
7967 +       ((unsigned char *)&addr)[2], \
7968 +       ((unsigned char *)&addr)[3]
7969 +
7970 +#define NIPQUAD_FMT "%u.%u.%u.%u"
7971 +
7972 +
7973 +static inline
7974 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
7975 +{
7976 +       __be32 ip = nxa->ip[0].s_addr;
7977 +       __be32 mask = nxa->mask.s_addr;
7978 +       __be32 bcast = ip | ~mask;
7979 +       int ret = 0;
7980 +
7981 +       switch (nxa->type & tmask) {
7982 +       case NXA_TYPE_MASK:
7983 +               ret = (ip == (addr & mask));
7984 +               break;
7985 +       case NXA_TYPE_ADDR:
7986 +               ret = 3;
7987 +               if (addr == ip)
7988 +                       break;
7989 +               /* fall through to broadcast */
7990 +       case NXA_MOD_BCAST:
7991 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
7992 +               break;
7993 +       case NXA_TYPE_RANGE:
7994 +               ret = ((nxa->ip[0].s_addr <= addr) &&
7995 +                       (nxa->ip[1].s_addr > addr));
7996 +               break;
7997 +       case NXA_TYPE_ANY:
7998 +               ret = 2;
7999 +               break;
8000 +       }
8001 +
8002 +       vxdprintk(VXD_CBIT(net, 0),
8003 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8004 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8005 +       return ret;
8006 +}
8007 +
8008 +static inline
8009 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8010 +{
8011 +       struct nx_addr_v4 *nxa;
8012 +       unsigned long irqflags;
8013 +       int ret = 1;
8014 +
8015 +       if (!nxi)
8016 +               goto out;
8017 +
8018 +       ret = 2;
8019 +       /* allow 127.0.0.1 when remapping lback */
8020 +       if ((tmask & NXA_LOOPBACK) &&
8021 +               (addr == IPI_LOOPBACK) &&
8022 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8023 +               goto out;
8024 +       ret = 3;
8025 +       /* check for lback address */
8026 +       if ((tmask & NXA_MOD_LBACK) &&
8027 +               (nxi->v4_lback.s_addr == addr))
8028 +               goto out;
8029 +       ret = 4;
8030 +       /* check for broadcast address */
8031 +       if ((tmask & NXA_MOD_BCAST) &&
8032 +               (nxi->v4_bcast.s_addr == addr))
8033 +               goto out;
8034 +       ret = 5;
8035 +
8036 +       /* check for v4 addresses */
8037 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8038 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
8039 +               if (v4_addr_match(nxa, addr, tmask))
8040 +                       goto out_unlock;
8041 +       ret = 0;
8042 +out_unlock:
8043 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8044 +out:
8045 +       vxdprintk(VXD_CBIT(net, 0),
8046 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
8047 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
8048 +       return ret;
8049 +}
8050 +
8051 +static inline
8052 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
8053 +{
8054 +       /* FIXME: needs full range checks */
8055 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
8056 +}
8057 +
8058 +static inline
8059 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
8060 +{
8061 +       struct nx_addr_v4 *ptr;
8062 +       unsigned long irqflags;
8063 +       int ret = 1;
8064 +
8065 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8066 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
8067 +               if (v4_nx_addr_match(ptr, nxa, mask))
8068 +                       goto out_unlock;
8069 +       ret = 0;
8070 +out_unlock:
8071 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8072 +       return ret;
8073 +}
8074 +
8075 +#include <net/inet_sock.h>
8076 +
8077 +/*
8078 + *     Check if a given address matches for a socket
8079 + *
8080 + *     nxi:            the socket's nx_info if any
8081 + *     addr:           to be verified address
8082 + */
8083 +static inline
8084 +int v4_sock_addr_match (
8085 +       struct nx_info *nxi,
8086 +       struct inet_sock *inet,
8087 +       __be32 addr)
8088 +{
8089 +       __be32 saddr = inet->inet_rcv_saddr;
8090 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
8091 +
8092 +       if (addr && (saddr == addr || bcast == addr))
8093 +               return 1;
8094 +       if (!saddr)
8095 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
8096 +       return 0;
8097 +}
8098 +
8099 +
8100 +/* inet related checks and helpers */
8101 +
8102 +
8103 +struct in_ifaddr;
8104 +struct net_device;
8105 +struct sock;
8106 +
8107 +#ifdef CONFIG_INET
8108 +
8109 +#include <linux/netdevice.h>
8110 +#include <linux/inetdevice.h>
8111 +#include <net/inet_sock.h>
8112 +#include <net/inet_timewait_sock.h>
8113 +
8114 +
8115 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8116 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
8117 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
8118 +
8119 +
8120 +/*
8121 + *     check if address is covered by socket
8122 + *
8123 + *     sk:     the socket to check against
8124 + *     addr:   the address in question (must be != 0)
8125 + */
8126 +
8127 +static inline
8128 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
8129 +{
8130 +       struct nx_info *nxi = sk->sk_nx_info;
8131 +       __be32 saddr = sk->sk_rcv_saddr;
8132 +
8133 +       vxdprintk(VXD_CBIT(net, 5),
8134 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
8135 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
8136 +               (sk->sk_socket?sk->sk_socket->flags:0));
8137 +
8138 +       if (saddr) {            /* direct address match */
8139 +               return v4_addr_match(nxa, saddr, -1);
8140 +       } else if (nxi) {       /* match against nx_info */
8141 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
8142 +       } else {                /* unrestricted any socket */
8143 +               return 1;
8144 +       }
8145 +}
8146 +
8147 +
8148 +
8149 +static inline
8150 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
8151 +{
8152 +       vxdprintk(VXD_CBIT(net, 1),
8153 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
8154 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
8155 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
8156 +
8157 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8158 +               return 1;
8159 +       if (dev_in_nx_info(dev, nxi))
8160 +               return 1;
8161 +       return 0;
8162 +}
8163 +
8164 +
8165 +static inline
8166 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
8167 +{
8168 +       if (!nxi)
8169 +               return 1;
8170 +       if (!ifa)
8171 +               return 0;
8172 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
8173 +}
8174 +
8175 +static inline
8176 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
8177 +{
8178 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
8179 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8180 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
8181 +
8182 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8183 +               return 1;
8184 +       if (v4_ifa_in_nx_info(ifa, nxi))
8185 +               return 1;
8186 +       return 0;
8187 +}
8188 +
8189 +
8190 +struct nx_v4_sock_addr {
8191 +       __be32 saddr;   /* Address used for validation */
8192 +       __be32 baddr;   /* Address used for socket bind */
8193 +};
8194 +
8195 +static inline
8196 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
8197 +       struct nx_v4_sock_addr *nsa)
8198 +{
8199 +       struct sock *sk = &inet->sk;
8200 +       struct nx_info *nxi = sk->sk_nx_info;
8201 +       __be32 saddr = addr->sin_addr.s_addr;
8202 +       __be32 baddr = saddr;
8203 +
8204 +       vxdprintk(VXD_CBIT(net, 3),
8205 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
8206 +               sk, sk->sk_nx_info, sk->sk_socket,
8207 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
8208 +               NIPQUAD(saddr));
8209 +
8210 +       if (nxi) {
8211 +               if (saddr == INADDR_ANY) {
8212 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
8213 +                               baddr = nxi->v4.ip[0].s_addr;
8214 +               } else if (saddr == IPI_LOOPBACK) {
8215 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8216 +                               baddr = nxi->v4_lback.s_addr;
8217 +               } else if (!ipv4_is_multicast(saddr) ||
8218 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
8219 +                       /* normal address bind */
8220 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
8221 +                               return -EADDRNOTAVAIL;
8222 +               }
8223 +       }
8224 +
8225 +       vxdprintk(VXD_CBIT(net, 3),
8226 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
8227 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
8228 +
8229 +       nsa->saddr = saddr;
8230 +       nsa->baddr = baddr;
8231 +       return 0;
8232 +}
8233 +
8234 +static inline
8235 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
8236 +{
8237 +       inet->inet_saddr = nsa->baddr;
8238 +       inet->inet_rcv_saddr = nsa->baddr;
8239 +}
8240 +
8241 +
8242 +/*
8243 + *      helper to simplify inet_lookup_listener
8244 + *
8245 + *      nxi:   the socket's nx_info if any
8246 + *      addr:  to be verified address
8247 + *      saddr: socket address
8248 + */
8249 +static inline int v4_inet_addr_match (
8250 +       struct nx_info *nxi,
8251 +       __be32 addr,
8252 +       __be32 saddr)
8253 +{
8254 +       if (addr && (saddr == addr))
8255 +               return 1;
8256 +       if (!saddr)
8257 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
8258 +       return 0;
8259 +}
8260 +
8261 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
8262 +{
8263 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
8264 +               (addr == nxi->v4_lback.s_addr))
8265 +               return IPI_LOOPBACK;
8266 +       return addr;
8267 +}
8268 +
8269 +static inline
8270 +int nx_info_has_v4(struct nx_info *nxi)
8271 +{
8272 +       if (!nxi)
8273 +               return 1;
8274 +       if (NX_IPV4(nxi))
8275 +               return 1;
8276 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8277 +               return 1;
8278 +       return 0;
8279 +}
8280 +
8281 +#else /* CONFIG_INET */
8282 +
8283 +static inline
8284 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
8285 +{
8286 +       return 1;
8287 +}
8288 +
8289 +static inline
8290 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8291 +{
8292 +       return 1;
8293 +}
8294 +
8295 +static inline
8296 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8297 +{
8298 +       return 1;
8299 +}
8300 +
8301 +static inline
8302 +int nx_info_has_v4(struct nx_info *nxi)
8303 +{
8304 +       return 0;
8305 +}
8306 +
8307 +#endif /* CONFIG_INET */
8308 +
8309 +#define current_nx_info_has_v4() \
8310 +       nx_info_has_v4(current_nx_info())
8311 +
8312 +#else
8313 +// #warning duplicate inclusion
8314 +#endif
8315 diff -NurpP --minimal linux-4.4.161/include/linux/vs_inet6.h linux-4.4.161-vs2.3.9.8/include/linux/vs_inet6.h
8316 --- linux-4.4.161/include/linux/vs_inet6.h      1970-01-01 00:00:00.000000000 +0000
8317 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_inet6.h    2018-10-20 04:57:21.000000000 +0000
8318 @@ -0,0 +1,257 @@
8319 +#ifndef _VS_INET6_H
8320 +#define _VS_INET6_H
8321 +
8322 +#include "vserver/base.h"
8323 +#include "vserver/network.h"
8324 +#include "vserver/debug.h"
8325 +
8326 +#include <net/ipv6.h>
8327 +
8328 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
8329 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
8330 +
8331 +
8332 +#ifdef CONFIG_IPV6
8333 +
8334 +static inline
8335 +int v6_addr_match(struct nx_addr_v6 *nxa,
8336 +       const struct in6_addr *addr, uint16_t mask)
8337 +{
8338 +       int ret = 0;
8339 +
8340 +       switch (nxa->type & mask) {
8341 +       case NXA_TYPE_MASK:
8342 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
8343 +               break;
8344 +       case NXA_TYPE_ADDR:
8345 +               ret = ipv6_addr_equal(&nxa->ip, addr);
8346 +               break;
8347 +       case NXA_TYPE_ANY:
8348 +               ret = 1;
8349 +               break;
8350 +       }
8351 +       vxdprintk(VXD_CBIT(net, 0),
8352 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
8353 +               nxa, NXAV6(nxa), addr, mask, ret);
8354 +       return ret;
8355 +}
8356 +
8357 +static inline
8358 +int v6_addr_in_nx_info(struct nx_info *nxi,
8359 +       const struct in6_addr *addr, uint16_t mask)
8360 +{
8361 +       struct nx_addr_v6 *nxa;
8362 +       unsigned long irqflags;
8363 +       int ret = 1;
8364 +
8365 +       if (!nxi)
8366 +               goto out;
8367 +
8368 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8369 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
8370 +               if (v6_addr_match(nxa, addr, mask))
8371 +                       goto out_unlock;
8372 +       ret = 0;
8373 +out_unlock:
8374 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8375 +out:
8376 +       vxdprintk(VXD_CBIT(net, 0),
8377 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
8378 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
8379 +       return ret;
8380 +}
8381 +
8382 +static inline
8383 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
8384 +{
8385 +       /* FIXME: needs full range checks */
8386 +       return v6_addr_match(nxa, &addr->ip, mask);
8387 +}
8388 +
8389 +static inline
8390 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
8391 +{
8392 +       struct nx_addr_v6 *ptr;
8393 +       unsigned long irqflags;
8394 +       int ret = 1;
8395 +
8396 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8397 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
8398 +               if (v6_nx_addr_match(ptr, nxa, mask))
8399 +                       goto out_unlock;
8400 +       ret = 0;
8401 +out_unlock:
8402 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8403 +       return ret;
8404 +}
8405 +
8406 +
8407 +/*
8408 + *     Check if a given address matches for a socket
8409 + *
8410 + *     nxi:            the socket's nx_info if any
8411 + *     addr:           to be verified address
8412 + */
8413 +static inline
8414 +int v6_sock_addr_match (
8415 +       struct nx_info *nxi,
8416 +       struct inet_sock *inet,
8417 +       struct in6_addr *addr)
8418 +{
8419 +       struct sock *sk = &inet->sk;
8420 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8421 +
8422 +       if (!ipv6_addr_any(addr) &&
8423 +               ipv6_addr_equal(saddr, addr))
8424 +               return 1;
8425 +       if (ipv6_addr_any(saddr))
8426 +               return v6_addr_in_nx_info(nxi, addr, -1);
8427 +       return 0;
8428 +}
8429 +
8430 +/*
8431 + *     check if address is covered by socket
8432 + *
8433 + *     sk:     the socket to check against
8434 + *     addr:   the address in question (must be != 0)
8435 + */
8436 +
8437 +static inline
8438 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
8439 +{
8440 +       struct nx_info *nxi = sk->sk_nx_info;
8441 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8442 +
8443 +       vxdprintk(VXD_CBIT(net, 5),
8444 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
8445 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
8446 +               (sk->sk_socket?sk->sk_socket->flags:0));
8447 +
8448 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
8449 +               return v6_addr_match(nxa, saddr, -1);
8450 +       } else if (nxi) {               /* match against nx_info */
8451 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
8452 +       } else {                        /* unrestricted any socket */
8453 +               return 1;
8454 +       }
8455 +}
8456 +
8457 +
8458 +/* inet related checks and helpers */
8459 +
8460 +
8461 +struct in_ifaddr;
8462 +struct net_device;
8463 +struct sock;
8464 +
8465 +
8466 +#include <linux/netdevice.h>
8467 +#include <linux/inetdevice.h>
8468 +#include <net/inet_timewait_sock.h>
8469 +
8470 +
8471 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8472 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
8473 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
8474 +
8475 +
8476 +
8477 +static inline
8478 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
8479 +{
8480 +       if (!nxi)
8481 +               return 1;
8482 +       if (!ifa)
8483 +               return 0;
8484 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
8485 +}
8486 +
8487 +static inline
8488 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
8489 +{
8490 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
8491 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8492 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
8493 +
8494 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8495 +               return 1;
8496 +       if (v6_ifa_in_nx_info(ifa, nxi))
8497 +               return 1;
8498 +       return 0;
8499 +}
8500 +
8501 +
8502 +struct nx_v6_sock_addr {
8503 +       struct in6_addr saddr;  /* Address used for validation */
8504 +       struct in6_addr baddr;  /* Address used for socket bind */
8505 +};
8506 +
8507 +static inline
8508 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
8509 +       struct nx_v6_sock_addr *nsa)
8510 +{
8511 +       // struct sock *sk = &inet->sk;
8512 +       // struct nx_info *nxi = sk->sk_nx_info;
8513 +       struct in6_addr saddr = addr->sin6_addr;
8514 +       struct in6_addr baddr = saddr;
8515 +
8516 +       nsa->saddr = saddr;
8517 +       nsa->baddr = baddr;
8518 +       return 0;
8519 +}
8520 +
8521 +static inline
8522 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
8523 +{
8524 +       // struct sock *sk = &inet->sk;
8525 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
8526 +
8527 +       // *saddr = nsa->baddr;
8528 +       // inet->inet_saddr = nsa->baddr;
8529 +}
8530 +
8531 +static inline
8532 +int nx_info_has_v6(struct nx_info *nxi)
8533 +{
8534 +       if (!nxi)
8535 +               return 1;
8536 +       if (NX_IPV6(nxi))
8537 +               return 1;
8538 +       return 0;
8539 +}
8540 +
8541 +#else /* CONFIG_IPV6 */
8542 +
8543 +static inline
8544 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
8545 +{
8546 +       return 1;
8547 +}
8548 +
8549 +
8550 +static inline
8551 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8552 +{
8553 +       return 1;
8554 +}
8555 +
8556 +static inline
8557 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8558 +{
8559 +       return 1;
8560 +}
8561 +
8562 +static inline
8563 +int nx_info_has_v6(struct nx_info *nxi)
8564 +{
8565 +       return 0;
8566 +}
8567 +
8568 +#endif /* CONFIG_IPV6 */
8569 +
8570 +#define current_nx_info_has_v6() \
8571 +       nx_info_has_v6(current_nx_info())
8572 +
8573 +#else
8574 +#warning duplicate inclusion
8575 +#endif
8576 diff -NurpP --minimal linux-4.4.161/include/linux/vs_limit.h linux-4.4.161-vs2.3.9.8/include/linux/vs_limit.h
8577 --- linux-4.4.161/include/linux/vs_limit.h      1970-01-01 00:00:00.000000000 +0000
8578 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_limit.h    2018-10-20 04:57:21.000000000 +0000
8579 @@ -0,0 +1,140 @@
8580 +#ifndef _VS_LIMIT_H
8581 +#define _VS_LIMIT_H
8582 +
8583 +#include "vserver/limit.h"
8584 +#include "vserver/base.h"
8585 +#include "vserver/context.h"
8586 +#include "vserver/debug.h"
8587 +#include "vserver/context.h"
8588 +#include "vserver/limit_int.h"
8589 +
8590 +
8591 +#define vx_acc_cres(v, d, p, r) \
8592 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
8593 +
8594 +#define vx_acc_cres_cond(x, d, p, r) \
8595 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8596 +       r, d, p, __FILE__, __LINE__)
8597 +
8598 +
8599 +#define vx_add_cres(v, a, p, r) \
8600 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
8601 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
8602 +
8603 +#define vx_add_cres_cond(x, a, p, r) \
8604 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8605 +       r, a, p, __FILE__, __LINE__)
8606 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
8607 +
8608 +
8609 +/* process and file limits */
8610 +
8611 +#define vx_nproc_inc(p) \
8612 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
8613 +
8614 +#define vx_nproc_dec(p) \
8615 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
8616 +
8617 +#define vx_files_inc(f) \
8618 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
8619 +
8620 +#define vx_files_dec(f) \
8621 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
8622 +
8623 +#define vx_locks_inc(l) \
8624 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
8625 +
8626 +#define vx_locks_dec(l) \
8627 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
8628 +
8629 +#define vx_openfd_inc(f) \
8630 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
8631 +
8632 +#define vx_openfd_dec(f) \
8633 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
8634 +
8635 +
8636 +#define vx_cres_avail(v, n, r) \
8637 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
8638 +
8639 +
8640 +#define vx_nproc_avail(n) \
8641 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
8642 +
8643 +#define vx_files_avail(n) \
8644 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
8645 +
8646 +#define vx_locks_avail(n) \
8647 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
8648 +
8649 +#define vx_openfd_avail(n) \
8650 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
8651 +
8652 +
8653 +/* dentry limits */
8654 +
8655 +#define vx_dentry_inc(d) do {                                          \
8656 +       if (d_count(d) == 1)                                            \
8657 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
8658 +       } while (0)
8659 +
8660 +#define vx_dentry_dec(d) do {                                          \
8661 +       if (d_count(d) == 0)                                            \
8662 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
8663 +       } while (0)
8664 +
8665 +#define vx_dentry_avail(n) \
8666 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
8667 +
8668 +
8669 +/* socket limits */
8670 +
8671 +#define vx_sock_inc(s) \
8672 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
8673 +
8674 +#define vx_sock_dec(s) \
8675 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
8676 +
8677 +#define vx_sock_avail(n) \
8678 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
8679 +
8680 +
8681 +/* ipc resource limits */
8682 +
8683 +#define vx_ipcmsg_add(v, u, a) \
8684 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
8685 +
8686 +#define vx_ipcmsg_sub(v, u, a) \
8687 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
8688 +
8689 +#define vx_ipcmsg_avail(v, a) \
8690 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
8691 +
8692 +
8693 +#define vx_ipcshm_add(v, k, a) \
8694 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8695 +
8696 +#define vx_ipcshm_sub(v, k, a) \
8697 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8698 +
8699 +#define vx_ipcshm_avail(v, a) \
8700 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
8701 +
8702 +
8703 +#define vx_semary_inc(a) \
8704 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
8705 +
8706 +#define vx_semary_dec(a) \
8707 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
8708 +
8709 +
8710 +#define vx_nsems_add(a,n) \
8711 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8712 +
8713 +#define vx_nsems_sub(a,n) \
8714 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8715 +
8716 +
8717 +#else
8718 +#warning duplicate inclusion
8719 +#endif
8720 diff -NurpP --minimal linux-4.4.161/include/linux/vs_network.h linux-4.4.161-vs2.3.9.8/include/linux/vs_network.h
8721 --- linux-4.4.161/include/linux/vs_network.h    1970-01-01 00:00:00.000000000 +0000
8722 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_network.h  2018-10-20 04:57:21.000000000 +0000
8723 @@ -0,0 +1,169 @@
8724 +#ifndef _NX_VS_NETWORK_H
8725 +#define _NX_VS_NETWORK_H
8726 +
8727 +#include "vserver/context.h"
8728 +#include "vserver/network.h"
8729 +#include "vserver/base.h"
8730 +#include "vserver/check.h"
8731 +#include "vserver/debug.h"
8732 +
8733 +#include <linux/sched.h>
8734 +
8735 +
8736 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
8737 +
8738 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
8739 +       const char *_file, int _line)
8740 +{
8741 +       if (!nxi)
8742 +               return NULL;
8743 +
8744 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
8745 +               nxi, nxi ? nxi->nx_id : 0,
8746 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8747 +               _file, _line);
8748 +
8749 +       atomic_inc(&nxi->nx_usecnt);
8750 +       return nxi;
8751 +}
8752 +
8753 +
8754 +extern void free_nx_info(struct nx_info *);
8755 +
8756 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
8757 +
8758 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
8759 +{
8760 +       if (!nxi)
8761 +               return;
8762 +
8763 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
8764 +               nxi, nxi ? nxi->nx_id : 0,
8765 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8766 +               _file, _line);
8767 +
8768 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
8769 +               free_nx_info(nxi);
8770 +}
8771 +
8772 +
8773 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
8774 +
8775 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
8776 +               const char *_file, int _line)
8777 +{
8778 +       if (nxi) {
8779 +               vxlprintk(VXD_CBIT(nid, 3),
8780 +                       "init_nx_info(%p[#%d.%d])",
8781 +                       nxi, nxi ? nxi->nx_id : 0,
8782 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8783 +                       _file, _line);
8784 +
8785 +               atomic_inc(&nxi->nx_usecnt);
8786 +       }
8787 +       *nxp = nxi;
8788 +}
8789 +
8790 +
8791 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
8792 +
8793 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
8794 +       const char *_file, int _line)
8795 +{
8796 +       struct nx_info *nxo;
8797 +
8798 +       if (!nxi)
8799 +               return;
8800 +
8801 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
8802 +               nxi, nxi ? nxi->nx_id : 0,
8803 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8804 +               _file, _line);
8805 +
8806 +       atomic_inc(&nxi->nx_usecnt);
8807 +       nxo = xchg(nxp, nxi);
8808 +       BUG_ON(nxo);
8809 +}
8810 +
8811 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
8812 +
8813 +static inline void __clr_nx_info(struct nx_info **nxp,
8814 +       const char *_file, int _line)
8815 +{
8816 +       struct nx_info *nxo;
8817 +
8818 +       nxo = xchg(nxp, NULL);
8819 +       if (!nxo)
8820 +               return;
8821 +
8822 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
8823 +               nxo, nxo ? nxo->nx_id : 0,
8824 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
8825 +               _file, _line);
8826 +
8827 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
8828 +               free_nx_info(nxo);
8829 +}
8830 +
8831 +
8832 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
8833 +
8834 +static inline void __claim_nx_info(struct nx_info *nxi,
8835 +       struct task_struct *task, const char *_file, int _line)
8836 +{
8837 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
8838 +               nxi, nxi ? nxi->nx_id : 0,
8839 +               nxi?atomic_read(&nxi->nx_usecnt):0,
8840 +               nxi?atomic_read(&nxi->nx_tasks):0,
8841 +               task, _file, _line);
8842 +
8843 +       atomic_inc(&nxi->nx_tasks);
8844 +}
8845 +
8846 +
8847 +extern void unhash_nx_info(struct nx_info *);
8848 +
8849 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
8850 +
8851 +static inline void __release_nx_info(struct nx_info *nxi,
8852 +       struct task_struct *task, const char *_file, int _line)
8853 +{
8854 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
8855 +               nxi, nxi ? nxi->nx_id : 0,
8856 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
8857 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
8858 +               task, _file, _line);
8859 +
8860 +       might_sleep();
8861 +
8862 +       if (atomic_dec_and_test(&nxi->nx_tasks))
8863 +               unhash_nx_info(nxi);
8864 +}
8865 +
8866 +
8867 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
8868 +
8869 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
8870 +       const char *_file, int _line)
8871 +{
8872 +       struct nx_info *nxi;
8873 +
8874 +       task_lock(p);
8875 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
8876 +               p, _file, _line);
8877 +       nxi = __get_nx_info(p->nx_info, _file, _line);
8878 +       task_unlock(p);
8879 +       return nxi;
8880 +}
8881 +
8882 +
8883 +static inline void exit_nx_info(struct task_struct *p)
8884 +{
8885 +       if (p->nx_info)
8886 +               release_nx_info(p->nx_info, p);
8887 +}
8888 +
8889 +
8890 +#else
8891 +#warning duplicate inclusion
8892 +#endif
8893 diff -NurpP --minimal linux-4.4.161/include/linux/vs_pid.h linux-4.4.161-vs2.3.9.8/include/linux/vs_pid.h
8894 --- linux-4.4.161/include/linux/vs_pid.h        1970-01-01 00:00:00.000000000 +0000
8895 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_pid.h      2018-10-20 04:57:21.000000000 +0000
8896 @@ -0,0 +1,50 @@
8897 +#ifndef _VS_PID_H
8898 +#define _VS_PID_H
8899 +
8900 +#include "vserver/base.h"
8901 +#include "vserver/check.h"
8902 +#include "vserver/context.h"
8903 +#include "vserver/debug.h"
8904 +#include "vserver/pid.h"
8905 +#include <linux/pid_namespace.h>
8906 +
8907 +
8908 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
8909 +
8910 +static inline
8911 +int vx_proc_task_visible(struct task_struct *task)
8912 +{
8913 +       if ((task->pid == 1) &&
8914 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
8915 +               /* show a blend through init */
8916 +               goto visible;
8917 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
8918 +               goto visible;
8919 +       return 0;
8920 +visible:
8921 +       return 1;
8922 +}
8923 +
8924 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
8925 +
8926 +
8927 +static inline
8928 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
8929 +{
8930 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
8931 +
8932 +       if (task && !vx_proc_task_visible(task)) {
8933 +               vxdprintk(VXD_CBIT(misc, 6),
8934 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
8935 +                       task, task->xid, task->pid,
8936 +                       current, current->xid, current->pid);
8937 +               put_task_struct(task);
8938 +               task = NULL;
8939 +       }
8940 +       return task;
8941 +}
8942 +
8943 +
8944 +#else
8945 +#warning duplicate inclusion
8946 +#endif
8947 diff -NurpP --minimal linux-4.4.161/include/linux/vs_sched.h linux-4.4.161-vs2.3.9.8/include/linux/vs_sched.h
8948 --- linux-4.4.161/include/linux/vs_sched.h      1970-01-01 00:00:00.000000000 +0000
8949 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_sched.h    2018-10-20 04:57:21.000000000 +0000
8950 @@ -0,0 +1,40 @@
8951 +#ifndef _VS_SCHED_H
8952 +#define _VS_SCHED_H
8953 +
8954 +#include "vserver/base.h"
8955 +#include "vserver/context.h"
8956 +#include "vserver/sched.h"
8957 +
8958 +
8959 +#define MAX_PRIO_BIAS           20
8960 +#define MIN_PRIO_BIAS          -20
8961 +
8962 +static inline
8963 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
8964 +{
8965 +       struct vx_info *vxi = p->vx_info;
8966 +
8967 +       if (vxi)
8968 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
8969 +       return prio;
8970 +}
8971 +
8972 +static inline void vx_account_user(struct vx_info *vxi,
8973 +       cputime_t cputime, int nice)
8974 +{
8975 +       if (!vxi)
8976 +               return;
8977 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
8978 +}
8979 +
8980 +static inline void vx_account_system(struct vx_info *vxi,
8981 +       cputime_t cputime, int idle)
8982 +{
8983 +       if (!vxi)
8984 +               return;
8985 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
8986 +}
8987 +
8988 +#else
8989 +#warning duplicate inclusion
8990 +#endif
8991 diff -NurpP --minimal linux-4.4.161/include/linux/vs_socket.h linux-4.4.161-vs2.3.9.8/include/linux/vs_socket.h
8992 --- linux-4.4.161/include/linux/vs_socket.h     1970-01-01 00:00:00.000000000 +0000
8993 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_socket.h   2018-10-20 04:57:21.000000000 +0000
8994 @@ -0,0 +1,67 @@
8995 +#ifndef _VS_SOCKET_H
8996 +#define _VS_SOCKET_H
8997 +
8998 +#include "vserver/debug.h"
8999 +#include "vserver/base.h"
9000 +#include "vserver/cacct.h"
9001 +#include "vserver/context.h"
9002 +#include "vserver/tag.h"
9003 +
9004 +
9005 +/* socket accounting */
9006 +
9007 +#include <linux/socket.h>
9008 +
9009 +static inline int vx_sock_type(int family)
9010 +{
9011 +       switch (family) {
9012 +       case PF_UNSPEC:
9013 +               return VXA_SOCK_UNSPEC;
9014 +       case PF_UNIX:
9015 +               return VXA_SOCK_UNIX;
9016 +       case PF_INET:
9017 +               return VXA_SOCK_INET;
9018 +       case PF_INET6:
9019 +               return VXA_SOCK_INET6;
9020 +       case PF_PACKET:
9021 +               return VXA_SOCK_PACKET;
9022 +       default:
9023 +               return VXA_SOCK_OTHER;
9024 +       }
9025 +}
9026 +
9027 +#define vx_acc_sock(v, f, p, s) \
9028 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
9029 +
9030 +static inline void __vx_acc_sock(struct vx_info *vxi,
9031 +       int family, int pos, int size, char *file, int line)
9032 +{
9033 +       if (vxi) {
9034 +               int type = vx_sock_type(family);
9035 +
9036 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
9037 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
9038 +       }
9039 +}
9040 +
9041 +#define vx_sock_recv(sk, s) \
9042 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
9043 +#define vx_sock_send(sk, s) \
9044 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
9045 +#define vx_sock_fail(sk, s) \
9046 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
9047 +
9048 +
9049 +#define sock_vx_init(s) do {           \
9050 +       (s)->sk_xid = 0;                \
9051 +       (s)->sk_vx_info = NULL;         \
9052 +       } while (0)
9053 +
9054 +#define sock_nx_init(s) do {           \
9055 +       (s)->sk_nid = 0;                \
9056 +       (s)->sk_nx_info = NULL;         \
9057 +       } while (0)
9058 +
9059 +#else
9060 +#warning duplicate inclusion
9061 +#endif
9062 diff -NurpP --minimal linux-4.4.161/include/linux/vs_tag.h linux-4.4.161-vs2.3.9.8/include/linux/vs_tag.h
9063 --- linux-4.4.161/include/linux/vs_tag.h        1970-01-01 00:00:00.000000000 +0000
9064 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_tag.h      2018-10-20 04:57:21.000000000 +0000
9065 @@ -0,0 +1,47 @@
9066 +#ifndef _VS_TAG_H
9067 +#define _VS_TAG_H
9068 +
9069 +#include <linux/vserver/tag.h>
9070 +
9071 +/* check conditions */
9072 +
9073 +#define DX_ADMIN       0x0001
9074 +#define DX_WATCH       0x0002
9075 +#define DX_HOSTID      0x0008
9076 +
9077 +#define DX_IDENT       0x0010
9078 +
9079 +#define DX_ARG_MASK    0x0010
9080 +
9081 +
9082 +#define dx_task_tag(t) ((t)->tag)
9083 +
9084 +#define dx_current_tag() dx_task_tag(current)
9085 +
9086 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
9087 +
9088 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
9089 +
9090 +
9091 +/*
9092 + * check current context for ADMIN/WATCH and
9093 + * optionally against supplied argument
9094 + */
9095 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
9096 +{
9097 +       if (mode & DX_ARG_MASK) {
9098 +               if ((mode & DX_IDENT) && (id == cid))
9099 +                       return 1;
9100 +       }
9101 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
9102 +               ((mode & DX_WATCH) && (cid == 1)) ||
9103 +               ((mode & DX_HOSTID) && (id == 0)));
9104 +}
9105 +
9106 +struct inode;
9107 +int dx_permission(const struct inode *inode, int mask);
9108 +
9109 +
9110 +#else
9111 +#warning duplicate inclusion
9112 +#endif
9113 diff -NurpP --minimal linux-4.4.161/include/linux/vs_time.h linux-4.4.161-vs2.3.9.8/include/linux/vs_time.h
9114 --- linux-4.4.161/include/linux/vs_time.h       1970-01-01 00:00:00.000000000 +0000
9115 +++ linux-4.4.161-vs2.3.9.8/include/linux/vs_time.h     2018-10-20 04:57:21.000000000 +0000
9116 @@ -0,0 +1,19 @@
9117 +#ifndef _VS_TIME_H
9118 +#define _VS_TIME_H
9119 +
9120 +
9121 +/* time faking stuff */
9122 +
9123 +#ifdef CONFIG_VSERVER_VTIME
9124 +
9125 +extern void vx_adjust_timespec(struct timespec *ts);
9126 +extern int vx_settimeofday(const struct timespec *ts);
9127 +
9128 +#else
9129 +#define        vx_adjust_timespec(t)   do { } while (0)
9130 +#define        vx_settimeofday(t)      do_settimeofday(t)
9131 +#endif
9132 +
9133 +#else
9134 +#warning duplicate inclusion
9135 +#endif
9136 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/base.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/base.h
9137 --- linux-4.4.161/include/linux/vserver/base.h  1970-01-01 00:00:00.000000000 +0000
9138 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/base.h        2018-10-20 04:57:21.000000000 +0000
9139 @@ -0,0 +1,184 @@
9140 +#ifndef _VSERVER_BASE_H
9141 +#define _VSERVER_BASE_H
9142 +
9143 +
9144 +/* context state changes */
9145 +
9146 +enum {
9147 +       VSC_STARTUP = 1,
9148 +       VSC_SHUTDOWN,
9149 +
9150 +       VSC_NETUP,
9151 +       VSC_NETDOWN,
9152 +};
9153 +
9154 +
9155 +
9156 +#define vx_task_xid(t) ((t)->xid)
9157 +
9158 +#define vx_current_xid() vx_task_xid(current)
9159 +
9160 +#define current_vx_info() (current->vx_info)
9161 +
9162 +
9163 +#define nx_task_nid(t) ((t)->nid)
9164 +
9165 +#define nx_current_nid() nx_task_nid(current)
9166 +
9167 +#define current_nx_info() (current->nx_info)
9168 +
9169 +
9170 +/* generic flag merging */
9171 +
9172 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
9173 +
9174 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
9175 +
9176 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
9177 +
9178 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
9179 +
9180 +
9181 +/* context flags */
9182 +
9183 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
9184 +
9185 +#define vx_current_flags()     __vx_flags(current_vx_info())
9186 +
9187 +#define vx_info_flags(v, m, f) \
9188 +       vs_check_flags(__vx_flags(v), m, f)
9189 +
9190 +#define task_vx_flags(t, m, f) \
9191 +       ((t) && vx_info_flags((t)->vx_info, m, f))
9192 +
9193 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
9194 +
9195 +
9196 +/* context caps */
9197 +
9198 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
9199 +
9200 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
9201 +
9202 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
9203 +
9204 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
9205 +
9206 +
9207 +
9208 +/* network flags */
9209 +
9210 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
9211 +
9212 +#define nx_current_flags()     __nx_flags(current_nx_info())
9213 +
9214 +#define nx_info_flags(n, m, f) \
9215 +       vs_check_flags(__nx_flags(n), m, f)
9216 +
9217 +#define task_nx_flags(t, m, f) \
9218 +       ((t) && nx_info_flags((t)->nx_info, m, f))
9219 +
9220 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
9221 +
9222 +
9223 +/* network caps */
9224 +
9225 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
9226 +
9227 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
9228 +
9229 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
9230 +
9231 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
9232 +
9233 +
9234 +/* context mask capabilities */
9235 +
9236 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
9237 +
9238 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
9239 +
9240 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
9241 +
9242 +
9243 +/* context bcap mask */
9244 +
9245 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
9246 +
9247 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
9248 +
9249 +
9250 +/* mask given bcaps */
9251 +
9252 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
9253 +
9254 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
9255 +
9256 +
9257 +/* masked cap_bset */
9258 +
9259 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
9260 +
9261 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
9262 +
9263 +#if 0
9264 +#define vx_info_mbcap(v, b) \
9265 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
9266 +       vx_info_bcaps(v, b) : (b))
9267 +
9268 +#define task_vx_mbcap(t, b) \
9269 +       vx_info_mbcap((t)->vx_info, (t)->b)
9270 +
9271 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
9272 +#endif
9273 +
9274 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
9275 +
9276 +#define vx_capable(b, c) (capable(b) || \
9277 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9278 +
9279 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
9280 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9281 +
9282 +#define nx_capable(b, c) (capable(b) || \
9283 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9284 +
9285 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
9286 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9287 +
9288 +#define vx_task_initpid(t, n) \
9289 +       ((t)->vx_info && \
9290 +       ((t)->vx_info->vx_initpid == (n)))
9291 +
9292 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
9293 +
9294 +
9295 +/* context unshare mask */
9296 +
9297 +#define __vx_umask(v)          ((v)->vx_umask)
9298 +
9299 +#define vx_current_umask()     __vx_umask(current_vx_info())
9300 +
9301 +#define vx_can_unshare(b, f) (capable(b) || \
9302 +       (cap_raised(current_cap(), b) && \
9303 +       !((f) & ~vx_current_umask())))
9304 +
9305 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
9306 +       (cap_raised(current_cap(), b) && \
9307 +       !((f) & ~vx_current_umask())))
9308 +
9309 +#define __vx_wmask(v)          ((v)->vx_wmask)
9310 +
9311 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
9312 +
9313 +
9314 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
9315 +
9316 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
9317 +
9318 +
9319 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
9320 +
9321 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
9322 +
9323 +#endif
9324 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/cacct.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/cacct.h
9325 --- linux-4.4.161/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
9326 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/cacct.h       2018-10-20 04:57:21.000000000 +0000
9327 @@ -0,0 +1,15 @@
9328 +#ifndef _VSERVER_CACCT_H
9329 +#define _VSERVER_CACCT_H
9330 +
9331 +
9332 +enum sock_acc_field {
9333 +       VXA_SOCK_UNSPEC = 0,
9334 +       VXA_SOCK_UNIX,
9335 +       VXA_SOCK_INET,
9336 +       VXA_SOCK_INET6,
9337 +       VXA_SOCK_PACKET,
9338 +       VXA_SOCK_OTHER,
9339 +       VXA_SOCK_SIZE   /* array size */
9340 +};
9341 +
9342 +#endif /* _VSERVER_CACCT_H */
9343 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/cacct_cmd.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/cacct_cmd.h
9344 --- linux-4.4.161/include/linux/vserver/cacct_cmd.h     1970-01-01 00:00:00.000000000 +0000
9345 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/cacct_cmd.h   2018-10-20 04:57:21.000000000 +0000
9346 @@ -0,0 +1,10 @@
9347 +#ifndef _VSERVER_CACCT_CMD_H
9348 +#define _VSERVER_CACCT_CMD_H
9349 +
9350 +
9351 +#include <linux/compiler.h>
9352 +#include <uapi/vserver/cacct_cmd.h>
9353 +
9354 +extern int vc_sock_stat(struct vx_info *, void __user *);
9355 +
9356 +#endif /* _VSERVER_CACCT_CMD_H */
9357 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/cacct_def.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/cacct_def.h
9358 --- linux-4.4.161/include/linux/vserver/cacct_def.h     1970-01-01 00:00:00.000000000 +0000
9359 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/cacct_def.h   2018-10-20 04:57:21.000000000 +0000
9360 @@ -0,0 +1,43 @@
9361 +#ifndef _VSERVER_CACCT_DEF_H
9362 +#define _VSERVER_CACCT_DEF_H
9363 +
9364 +#include <asm/atomic.h>
9365 +#include <linux/vserver/cacct.h>
9366 +
9367 +
9368 +struct _vx_sock_acc {
9369 +       atomic_long_t count;
9370 +       atomic_long_t total;
9371 +};
9372 +
9373 +/* context sub struct */
9374 +
9375 +struct _vx_cacct {
9376 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
9377 +       atomic_t slab[8];
9378 +       atomic_t page[6][8];
9379 +};
9380 +
9381 +#ifdef CONFIG_VSERVER_DEBUG
9382 +
9383 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
9384 +{
9385 +       int i, j;
9386 +
9387 +       printk("\t_vx_cacct:");
9388 +       for (i = 0; i < 6; i++) {
9389 +               struct _vx_sock_acc *ptr = cacct->sock[i];
9390 +
9391 +               printk("\t [%d] =", i);
9392 +               for (j = 0; j < 3; j++) {
9393 +                       printk(" [%d] = %8lu, %8lu", j,
9394 +                               atomic_long_read(&ptr[j].count),
9395 +                               atomic_long_read(&ptr[j].total));
9396 +               }
9397 +               printk("\n");
9398 +       }
9399 +}
9400 +
9401 +#endif
9402 +
9403 +#endif /* _VSERVER_CACCT_DEF_H */
9404 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/cacct_int.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/cacct_int.h
9405 --- linux-4.4.161/include/linux/vserver/cacct_int.h     1970-01-01 00:00:00.000000000 +0000
9406 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/cacct_int.h   2018-10-20 04:57:21.000000000 +0000
9407 @@ -0,0 +1,17 @@
9408 +#ifndef _VSERVER_CACCT_INT_H
9409 +#define _VSERVER_CACCT_INT_H
9410 +
9411 +static inline
9412 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
9413 +{
9414 +       return atomic_long_read(&cacct->sock[type][pos].count);
9415 +}
9416 +
9417 +
9418 +static inline
9419 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
9420 +{
9421 +       return atomic_long_read(&cacct->sock[type][pos].total);
9422 +}
9423 +
9424 +#endif /* _VSERVER_CACCT_INT_H */
9425 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/check.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/check.h
9426 --- linux-4.4.161/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
9427 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/check.h       2018-10-20 04:57:21.000000000 +0000
9428 @@ -0,0 +1,89 @@
9429 +#ifndef _VSERVER_CHECK_H
9430 +#define _VSERVER_CHECK_H
9431 +
9432 +
9433 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
9434 +
9435 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
9436 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
9437 +#else
9438 +#define MIN_D_CONTEXT  65536
9439 +#endif
9440 +
9441 +/* check conditions */
9442 +
9443 +#define VS_ADMIN       0x0001
9444 +#define VS_WATCH       0x0002
9445 +#define VS_HIDE                0x0004
9446 +#define VS_HOSTID      0x0008
9447 +
9448 +#define VS_IDENT       0x0010
9449 +#define VS_EQUIV       0x0020
9450 +#define VS_PARENT      0x0040
9451 +#define VS_CHILD       0x0080
9452 +
9453 +#define VS_ARG_MASK    0x00F0
9454 +
9455 +#define VS_DYNAMIC     0x0100
9456 +#define VS_STATIC      0x0200
9457 +
9458 +#define VS_ATR_MASK    0x0F00
9459 +
9460 +#ifdef CONFIG_VSERVER_PRIVACY
9461 +#define VS_ADMIN_P     (0)
9462 +#define VS_WATCH_P     (0)
9463 +#else
9464 +#define VS_ADMIN_P     VS_ADMIN
9465 +#define VS_WATCH_P     VS_WATCH
9466 +#endif
9467 +
9468 +#define VS_HARDIRQ     0x1000
9469 +#define VS_SOFTIRQ     0x2000
9470 +#define VS_IRQ         0x4000
9471 +
9472 +#define VS_IRQ_MASK    0xF000
9473 +
9474 +#include <linux/hardirq.h>
9475 +
9476 +/*
9477 + * check current context for ADMIN/WATCH and
9478 + * optionally against supplied argument
9479 + */
9480 +static inline int __vs_check(int cid, int id, unsigned int mode)
9481 +{
9482 +       if (mode & VS_ARG_MASK) {
9483 +               if ((mode & VS_IDENT) && (id == cid))
9484 +                       return 1;
9485 +       }
9486 +       if (mode & VS_ATR_MASK) {
9487 +               if ((mode & VS_DYNAMIC) &&
9488 +                       (id >= MIN_D_CONTEXT) &&
9489 +                       (id <= MAX_S_CONTEXT))
9490 +                       return 1;
9491 +               if ((mode & VS_STATIC) &&
9492 +                       (id > 1) && (id < MIN_D_CONTEXT))
9493 +                       return 1;
9494 +       }
9495 +       if (mode & VS_IRQ_MASK) {
9496 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
9497 +                       return 1;
9498 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
9499 +                       return 1;
9500 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
9501 +                       return 1;
9502 +       }
9503 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
9504 +               ((mode & VS_WATCH) && (cid == 1)) ||
9505 +               ((mode & VS_HOSTID) && (id == 0)));
9506 +}
9507 +
9508 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
9509 +
9510 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
9511 +
9512 +
9513 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
9514 +
9515 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
9516 +
9517 +#endif
9518 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/context.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/context.h
9519 --- linux-4.4.161/include/linux/vserver/context.h       1970-01-01 00:00:00.000000000 +0000
9520 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/context.h     2018-10-20 04:57:21.000000000 +0000
9521 @@ -0,0 +1,110 @@
9522 +#ifndef _VSERVER_CONTEXT_H
9523 +#define _VSERVER_CONTEXT_H
9524 +
9525 +
9526 +#include <linux/list.h>
9527 +#include <linux/spinlock.h>
9528 +#include <linux/rcupdate.h>
9529 +#include <uapi/vserver/context.h>
9530 +
9531 +#include "limit_def.h"
9532 +#include "sched_def.h"
9533 +#include "cvirt_def.h"
9534 +#include "cacct_def.h"
9535 +#include "device_def.h"
9536 +
9537 +#define VX_SPACES      2
9538 +
9539 +struct _vx_info_pc {
9540 +       struct _vx_sched_pc sched_pc;
9541 +       struct _vx_cvirt_pc cvirt_pc;
9542 +};
9543 +
9544 +struct _vx_space {
9545 +       unsigned long vx_nsmask;                /* assignment mask */
9546 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
9547 +       struct fs_struct *vx_fs;                /* private namespace fs */
9548 +       const struct cred *vx_cred;             /* task credentials */
9549 +};
9550 +
9551 +struct vx_info {
9552 +       struct hlist_node vx_hlist;             /* linked list of contexts */
9553 +       vxid_t vx_id;                           /* context id */
9554 +       atomic_t vx_usecnt;                     /* usage count */
9555 +       atomic_t vx_tasks;                      /* tasks count */
9556 +       struct vx_info *vx_parent;              /* parent context */
9557 +       int vx_state;                           /* context state */
9558 +
9559 +       struct _vx_space space[VX_SPACES];      /* namespace store */
9560 +
9561 +       uint64_t vx_flags;                      /* context flags */
9562 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
9563 +       uint64_t vx_umask;                      /* unshare mask (guest) */
9564 +       uint64_t vx_wmask;                      /* warn mask (guest) */
9565 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
9566 +
9567 +       struct task_struct *vx_reaper;          /* guest reaper process */
9568 +       pid_t vx_initpid;                       /* PID of guest init */
9569 +       int64_t vx_badness_bias;                /* OOM points bias */
9570 +
9571 +       struct _vx_limit limit;                 /* vserver limits */
9572 +       struct _vx_sched sched;                 /* vserver scheduler */
9573 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
9574 +       struct _vx_cacct cacct;                 /* context accounting */
9575 +
9576 +       struct _vx_device dmap;                 /* default device map targets */
9577 +
9578 +#ifndef CONFIG_SMP
9579 +       struct _vx_info_pc info_pc;             /* per cpu data */
9580 +#else
9581 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
9582 +#endif
9583 +
9584 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
9585 +       int reboot_cmd;                         /* last sys_reboot() cmd */
9586 +       int exit_code;                          /* last process exit code */
9587 +
9588 +       char vx_name[65];                       /* vserver name */
9589 +};
9590 +
9591 +#ifndef CONFIG_SMP
9592 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
9593 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
9594 +#else
9595 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
9596 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
9597 +#endif
9598 +
9599 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
9600 +
9601 +
9602 +struct vx_info_save {
9603 +       struct vx_info *vxi;
9604 +       vxid_t xid;
9605 +};
9606 +
9607 +
9608 +/* status flags */
9609 +
9610 +#define VXS_HASHED     0x0001
9611 +#define VXS_PAUSED     0x0010
9612 +#define VXS_SHUTDOWN   0x0100
9613 +#define VXS_HELPER     0x1000
9614 +#define VXS_RELEASED   0x8000
9615 +
9616 +
9617 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
9618 +extern void release_vx_info(struct vx_info *, struct task_struct *);
9619 +
9620 +extern struct vx_info *lookup_vx_info(int);
9621 +extern struct vx_info *lookup_or_create_vx_info(int);
9622 +
9623 +extern int get_xid_list(int, unsigned int *, int);
9624 +extern int xid_is_hashed(vxid_t);
9625 +
9626 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
9627 +
9628 +extern long vs_state_change(struct vx_info *, unsigned int);
9629 +
9630 +
9631 +#endif /* _VSERVER_CONTEXT_H */
9632 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/context_cmd.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/context_cmd.h
9633 --- linux-4.4.161/include/linux/vserver/context_cmd.h   1970-01-01 00:00:00.000000000 +0000
9634 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/context_cmd.h 2018-10-20 04:57:21.000000000 +0000
9635 @@ -0,0 +1,33 @@
9636 +#ifndef _VSERVER_CONTEXT_CMD_H
9637 +#define _VSERVER_CONTEXT_CMD_H
9638 +
9639 +#include <uapi/vserver/context_cmd.h>
9640 +
9641 +extern int vc_task_xid(uint32_t);
9642 +
9643 +extern int vc_vx_info(struct vx_info *, void __user *);
9644 +
9645 +extern int vc_ctx_stat(struct vx_info *, void __user *);
9646 +
9647 +extern int vc_ctx_create(uint32_t, void __user *);
9648 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
9649 +
9650 +extern int vc_get_cflags(struct vx_info *, void __user *);
9651 +extern int vc_set_cflags(struct vx_info *, void __user *);
9652 +
9653 +extern int vc_get_ccaps(struct vx_info *, void __user *);
9654 +extern int vc_set_ccaps(struct vx_info *, void __user *);
9655 +
9656 +extern int vc_get_bcaps(struct vx_info *, void __user *);
9657 +extern int vc_set_bcaps(struct vx_info *, void __user *);
9658 +
9659 +extern int vc_get_umask(struct vx_info *, void __user *);
9660 +extern int vc_set_umask(struct vx_info *, void __user *);
9661 +
9662 +extern int vc_get_wmask(struct vx_info *, void __user *);
9663 +extern int vc_set_wmask(struct vx_info *, void __user *);
9664 +
9665 +extern int vc_get_badness(struct vx_info *, void __user *);
9666 +extern int vc_set_badness(struct vx_info *, void __user *);
9667 +
9668 +#endif /* _VSERVER_CONTEXT_CMD_H */
9669 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/cvirt.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/cvirt.h
9670 --- linux-4.4.161/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
9671 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/cvirt.h       2018-10-20 04:57:21.000000000 +0000
9672 @@ -0,0 +1,18 @@
9673 +#ifndef _VSERVER_CVIRT_H
9674 +#define _VSERVER_CVIRT_H
9675 +
9676 +struct timespec;
9677 +
9678 +void vx_vsi_boottime(struct timespec *);
9679 +
9680 +void vx_vsi_uptime(struct timespec *, struct timespec *);
9681 +
9682 +
9683 +struct vx_info;
9684 +
9685 +void vx_update_load(struct vx_info *);
9686 +
9687 +
9688 +int vx_do_syslog(int, char __user *, int);
9689 +
9690 +#endif /* _VSERVER_CVIRT_H */
9691 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/cvirt_cmd.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/cvirt_cmd.h
9692 --- linux-4.4.161/include/linux/vserver/cvirt_cmd.h     1970-01-01 00:00:00.000000000 +0000
9693 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/cvirt_cmd.h   2018-10-20 04:57:21.000000000 +0000
9694 @@ -0,0 +1,13 @@
9695 +#ifndef _VSERVER_CVIRT_CMD_H
9696 +#define _VSERVER_CVIRT_CMD_H
9697 +
9698 +
9699 +#include <linux/compiler.h>
9700 +#include <uapi/vserver/cvirt_cmd.h>
9701 +
9702 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
9703 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
9704 +
9705 +extern int vc_virt_stat(struct vx_info *, void __user *);
9706 +
9707 +#endif /* _VSERVER_CVIRT_CMD_H */
9708 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/cvirt_def.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/cvirt_def.h
9709 --- linux-4.4.161/include/linux/vserver/cvirt_def.h     1970-01-01 00:00:00.000000000 +0000
9710 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/cvirt_def.h   2018-10-20 04:57:21.000000000 +0000
9711 @@ -0,0 +1,80 @@
9712 +#ifndef _VSERVER_CVIRT_DEF_H
9713 +#define _VSERVER_CVIRT_DEF_H
9714 +
9715 +#include <linux/jiffies.h>
9716 +#include <linux/spinlock.h>
9717 +#include <linux/wait.h>
9718 +#include <linux/time.h>
9719 +#include <asm/atomic.h>
9720 +
9721 +
9722 +struct _vx_usage_stat {
9723 +       uint64_t user;
9724 +       uint64_t nice;
9725 +       uint64_t system;
9726 +       uint64_t softirq;
9727 +       uint64_t irq;
9728 +       uint64_t idle;
9729 +       uint64_t iowait;
9730 +};
9731 +
9732 +struct _vx_syslog {
9733 +       wait_queue_head_t log_wait;
9734 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
9735 +
9736 +       unsigned long log_start;        /* next char to be read by syslog() */
9737 +       unsigned long con_start;        /* next char to be sent to consoles */
9738 +       unsigned long log_end;  /* most-recently-written-char + 1 */
9739 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
9740 +
9741 +       char log_buf[1024];
9742 +};
9743 +
9744 +
9745 +/* context sub struct */
9746 +
9747 +struct _vx_cvirt {
9748 +       atomic_t nr_threads;            /* number of current threads */
9749 +       atomic_t nr_running;            /* number of running threads */
9750 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
9751 +
9752 +       atomic_t nr_onhold;             /* processes on hold */
9753 +       uint32_t onhold_last;           /* jiffies when put on hold */
9754 +
9755 +       struct timespec bias_ts;        /* time offset to the host */
9756 +       struct timespec bias_idle;
9757 +       struct timespec bias_uptime;    /* context creation point */
9758 +       uint64_t bias_clock;            /* offset in clock_t */
9759 +
9760 +       spinlock_t load_lock;           /* lock for the load averages */
9761 +       atomic_t load_updates;          /* nr of load updates done so far */
9762 +       uint32_t load_last;             /* last time load was calculated */
9763 +       uint32_t load[3];               /* load averages 1,5,15 */
9764 +
9765 +       atomic_t total_forks;           /* number of forks so far */
9766 +
9767 +       struct _vx_syslog syslog;
9768 +};
9769 +
9770 +struct _vx_cvirt_pc {
9771 +       struct _vx_usage_stat cpustat;
9772 +};
9773 +
9774 +
9775 +#ifdef CONFIG_VSERVER_DEBUG
9776 +
9777 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
9778 +{
9779 +       printk("\t_vx_cvirt:\n");
9780 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
9781 +               atomic_read(&cvirt->nr_threads),
9782 +               atomic_read(&cvirt->nr_running),
9783 +               atomic_read(&cvirt->nr_uninterruptible),
9784 +               atomic_read(&cvirt->nr_onhold));
9785 +       /* add rest here */
9786 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
9787 +}
9788 +
9789 +#endif
9790 +
9791 +#endif /* _VSERVER_CVIRT_DEF_H */
9792 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/debug.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/debug.h
9793 --- linux-4.4.161/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
9794 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/debug.h       2018-10-20 04:57:21.000000000 +0000
9795 @@ -0,0 +1,146 @@
9796 +#ifndef _VSERVER_DEBUG_H
9797 +#define _VSERVER_DEBUG_H
9798 +
9799 +
9800 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
9801 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
9802 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
9803 +
9804 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
9805 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
9806 +#define VXF_DEV                "%p[%lu,%d:%d]"
9807 +
9808 +#if    defined(CONFIG_QUOTES_UTF8)
9809 +#define        VS_Q_LQM        "\xc2\xbb"
9810 +#define        VS_Q_RQM        "\xc2\xab"
9811 +#elif  defined(CONFIG_QUOTES_ASCII)
9812 +#define        VS_Q_LQM        "\x27"
9813 +#define        VS_Q_RQM        "\x27"
9814 +#else
9815 +#define        VS_Q_LQM        "\xbb"
9816 +#define        VS_Q_RQM        "\xab"
9817 +#endif
9818 +
9819 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
9820 +
9821 +
9822 +#define vxd_path(p)                                            \
9823 +       ({ static char _buffer[PATH_MAX];                       \
9824 +          d_path(p, _buffer, sizeof(_buffer)); })
9825 +
9826 +#define vxd_cond_path(n)                                       \
9827 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
9828 +
9829 +
9830 +#ifdef CONFIG_VSERVER_DEBUG
9831 +
9832 +extern unsigned int vs_debug_switch;
9833 +extern unsigned int vs_debug_xid;
9834 +extern unsigned int vs_debug_nid;
9835 +extern unsigned int vs_debug_tag;
9836 +extern unsigned int vs_debug_net;
9837 +extern unsigned int vs_debug_limit;
9838 +extern unsigned int vs_debug_cres;
9839 +extern unsigned int vs_debug_dlim;
9840 +extern unsigned int vs_debug_quota;
9841 +extern unsigned int vs_debug_cvirt;
9842 +extern unsigned int vs_debug_space;
9843 +extern unsigned int vs_debug_perm;
9844 +extern unsigned int vs_debug_misc;
9845 +
9846 +
9847 +#define VX_LOGLEVEL    "vxD: "
9848 +#define VX_PROC_FMT    "%p: "
9849 +#define VX_PROCESS     current
9850 +
9851 +#define vxdprintk(c, f, x...)                                  \
9852 +       do {                                                    \
9853 +               if (c)                                          \
9854 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
9855 +                               VX_PROCESS , ##x);              \
9856 +       } while (0)
9857 +
9858 +#define vxlprintk(c, f, x...)                                  \
9859 +       do {                                                    \
9860 +               if (c)                                          \
9861 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
9862 +       } while (0)
9863 +
9864 +#define vxfprintk(c, f, x...)                                  \
9865 +       do {                                                    \
9866 +               if (c)                                          \
9867 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
9868 +       } while (0)
9869 +
9870 +
9871 +struct vx_info;
9872 +
9873 +void dump_vx_info(struct vx_info *, int);
9874 +void dump_vx_info_inactive(int);
9875 +
9876 +#else  /* CONFIG_VSERVER_DEBUG */
9877 +
9878 +#define vs_debug_switch        0
9879 +#define vs_debug_xid   0
9880 +#define vs_debug_nid   0
9881 +#define vs_debug_tag   0
9882 +#define vs_debug_net   0
9883 +#define vs_debug_limit 0
9884 +#define vs_debug_cres  0
9885 +#define vs_debug_dlim  0
9886 +#define vs_debug_quota 0
9887 +#define vs_debug_cvirt 0
9888 +#define vs_debug_space 0
9889 +#define vs_debug_perm  0
9890 +#define vs_debug_misc  0
9891 +
9892 +#define vxdprintk(x...) do { } while (0)
9893 +#define vxlprintk(x...) do { } while (0)
9894 +#define vxfprintk(x...) do { } while (0)
9895 +
9896 +#endif /* CONFIG_VSERVER_DEBUG */
9897 +
9898 +
9899 +#ifdef CONFIG_VSERVER_WARN
9900 +
9901 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
9902 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
9903 +#define VX_WARN_XID    "[xid #%u] "
9904 +#define VX_WARN_NID    "[nid #%u] "
9905 +#define VX_WARN_TAG    "[tag #%u] "
9906 +
9907 +#define vxwprintk(c, f, x...)                                  \
9908 +       do {                                                    \
9909 +               if (c)                                          \
9910 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
9911 +       } while (0)
9912 +
9913 +#else  /* CONFIG_VSERVER_WARN */
9914 +
9915 +#define vxwprintk(x...) do { } while (0)
9916 +
9917 +#endif /* CONFIG_VSERVER_WARN */
9918 +
9919 +#define vxwprintk_task(c, f, x...)                             \
9920 +       vxwprintk(c, VX_WARN_TASK f,                            \
9921 +               current->comm, current->pid,                    \
9922 +               current->xid, current->nid,                     \
9923 +               current->tag, ##x)
9924 +#define vxwprintk_xid(c, f, x...)                              \
9925 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
9926 +#define vxwprintk_nid(c, f, x...)                              \
9927 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
9928 +#define vxwprintk_tag(c, f, x...)                              \
9929 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
9930 +
9931 +#ifdef CONFIG_VSERVER_DEBUG
9932 +#define vxd_assert_lock(l)     assert_spin_locked(l)
9933 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
9934 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
9935 +#else
9936 +#define vxd_assert_lock(l)     do { } while (0)
9937 +#define vxd_assert(c, f, x...) do { } while (0)
9938 +#endif
9939 +
9940 +
9941 +#endif /* _VSERVER_DEBUG_H */
9942 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/debug_cmd.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/debug_cmd.h
9943 --- linux-4.4.161/include/linux/vserver/debug_cmd.h     1970-01-01 00:00:00.000000000 +0000
9944 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/debug_cmd.h   2018-10-20 04:57:21.000000000 +0000
9945 @@ -0,0 +1,37 @@
9946 +#ifndef _VSERVER_DEBUG_CMD_H
9947 +#define _VSERVER_DEBUG_CMD_H
9948 +
9949 +#include <uapi/vserver/debug_cmd.h>
9950 +
9951 +
9952 +#ifdef CONFIG_COMPAT
9953 +
9954 +#include <asm/compat.h>
9955 +
9956 +struct vcmd_read_history_v0_x32 {
9957 +       uint32_t index;
9958 +       uint32_t count;
9959 +       compat_uptr_t data_ptr;
9960 +};
9961 +
9962 +struct vcmd_read_monitor_v0_x32 {
9963 +       uint32_t index;
9964 +       uint32_t count;
9965 +       compat_uptr_t data_ptr;
9966 +};
9967 +
9968 +#endif  /* CONFIG_COMPAT */
9969 +
9970 +extern int vc_dump_history(uint32_t);
9971 +
9972 +extern int vc_read_history(uint32_t, void __user *);
9973 +extern int vc_read_monitor(uint32_t, void __user *);
9974 +
9975 +#ifdef CONFIG_COMPAT
9976 +
9977 +extern int vc_read_history_x32(uint32_t, void __user *);
9978 +extern int vc_read_monitor_x32(uint32_t, void __user *);
9979 +
9980 +#endif  /* CONFIG_COMPAT */
9981 +
9982 +#endif /* _VSERVER_DEBUG_CMD_H */
9983 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/device.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/device.h
9984 --- linux-4.4.161/include/linux/vserver/device.h        1970-01-01 00:00:00.000000000 +0000
9985 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/device.h      2018-10-20 04:57:21.000000000 +0000
9986 @@ -0,0 +1,9 @@
9987 +#ifndef _VSERVER_DEVICE_H
9988 +#define _VSERVER_DEVICE_H
9989 +
9990 +
9991 +#include <uapi/vserver/device.h>
9992 +
9993 +#else  /* _VSERVER_DEVICE_H */
9994 +#warning duplicate inclusion
9995 +#endif /* _VSERVER_DEVICE_H */
9996 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/device_cmd.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/device_cmd.h
9997 --- linux-4.4.161/include/linux/vserver/device_cmd.h    1970-01-01 00:00:00.000000000 +0000
9998 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/device_cmd.h  2018-10-20 04:57:21.000000000 +0000
9999 @@ -0,0 +1,31 @@
10000 +#ifndef _VSERVER_DEVICE_CMD_H
10001 +#define _VSERVER_DEVICE_CMD_H
10002 +
10003 +#include <uapi/vserver/device_cmd.h>
10004 +
10005 +
10006 +#ifdef CONFIG_COMPAT
10007 +
10008 +#include <asm/compat.h>
10009 +
10010 +struct vcmd_set_mapping_v0_x32 {
10011 +       compat_uptr_t device_ptr;
10012 +       compat_uptr_t target_ptr;
10013 +       uint32_t flags;
10014 +};
10015 +
10016 +#endif /* CONFIG_COMPAT */
10017 +
10018 +#include <linux/compiler.h>
10019 +
10020 +extern int vc_set_mapping(struct vx_info *, void __user *);
10021 +extern int vc_unset_mapping(struct vx_info *, void __user *);
10022 +
10023 +#ifdef CONFIG_COMPAT
10024 +
10025 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
10026 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
10027 +
10028 +#endif /* CONFIG_COMPAT */
10029 +
10030 +#endif /* _VSERVER_DEVICE_CMD_H */
10031 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/device_def.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/device_def.h
10032 --- linux-4.4.161/include/linux/vserver/device_def.h    1970-01-01 00:00:00.000000000 +0000
10033 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/device_def.h  2018-10-20 04:57:21.000000000 +0000
10034 @@ -0,0 +1,17 @@
10035 +#ifndef _VSERVER_DEVICE_DEF_H
10036 +#define _VSERVER_DEVICE_DEF_H
10037 +
10038 +#include <linux/types.h>
10039 +
10040 +struct vx_dmap_target {
10041 +       dev_t target;
10042 +       uint32_t flags;
10043 +};
10044 +
10045 +struct _vx_device {
10046 +#ifdef CONFIG_VSERVER_DEVICE
10047 +       struct vx_dmap_target targets[2];
10048 +#endif
10049 +};
10050 +
10051 +#endif /* _VSERVER_DEVICE_DEF_H */
10052 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/dlimit.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/dlimit.h
10053 --- linux-4.4.161/include/linux/vserver/dlimit.h        1970-01-01 00:00:00.000000000 +0000
10054 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/dlimit.h      2018-10-20 04:57:21.000000000 +0000
10055 @@ -0,0 +1,54 @@
10056 +#ifndef _VSERVER_DLIMIT_H
10057 +#define _VSERVER_DLIMIT_H
10058 +
10059 +#include "switch.h"
10060 +
10061 +
10062 +#ifdef __KERNEL__
10063 +
10064 +/*      keep in sync with CDLIM_INFINITY       */
10065 +
10066 +#define DLIM_INFINITY          (~0ULL)
10067 +
10068 +#include <linux/spinlock.h>
10069 +#include <linux/rcupdate.h>
10070 +
10071 +struct super_block;
10072 +
10073 +struct dl_info {
10074 +       struct hlist_node dl_hlist;             /* linked list of contexts */
10075 +       struct rcu_head dl_rcu;                 /* the rcu head */
10076 +       vtag_t dl_tag;                          /* context tag */
10077 +       atomic_t dl_usecnt;                     /* usage count */
10078 +       atomic_t dl_refcnt;                     /* reference count */
10079 +
10080 +       struct super_block *dl_sb;              /* associated superblock */
10081 +
10082 +       spinlock_t dl_lock;                     /* protect the values */
10083 +
10084 +       unsigned long long dl_space_used;       /* used space in bytes */
10085 +       unsigned long long dl_space_total;      /* maximum space in bytes */
10086 +       unsigned long dl_inodes_used;           /* used inodes */
10087 +       unsigned long dl_inodes_total;          /* maximum inodes */
10088 +
10089 +       unsigned int dl_nrlmult;                /* non root limit mult */
10090 +};
10091 +
10092 +struct rcu_head;
10093 +
10094 +extern void rcu_free_dl_info(struct rcu_head *);
10095 +extern void unhash_dl_info(struct dl_info *);
10096 +
10097 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
10098 +
10099 +
10100 +struct kstatfs;
10101 +
10102 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
10103 +
10104 +typedef uint64_t dlsize_t;
10105 +
10106 +#endif /* __KERNEL__ */
10107 +#else  /* _VSERVER_DLIMIT_H */
10108 +#warning duplicate inclusion
10109 +#endif /* _VSERVER_DLIMIT_H */
10110 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/dlimit_cmd.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/dlimit_cmd.h
10111 --- linux-4.4.161/include/linux/vserver/dlimit_cmd.h    1970-01-01 00:00:00.000000000 +0000
10112 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/dlimit_cmd.h  2018-10-20 04:57:21.000000000 +0000
10113 @@ -0,0 +1,46 @@
10114 +#ifndef _VSERVER_DLIMIT_CMD_H
10115 +#define _VSERVER_DLIMIT_CMD_H
10116 +
10117 +#include <uapi/vserver/dlimit_cmd.h>
10118 +
10119 +
10120 +#ifdef CONFIG_COMPAT
10121 +
10122 +#include <asm/compat.h>
10123 +
10124 +struct vcmd_ctx_dlimit_base_v0_x32 {
10125 +       compat_uptr_t name_ptr;
10126 +       uint32_t flags;
10127 +};
10128 +
10129 +struct vcmd_ctx_dlimit_v0_x32 {
10130 +       compat_uptr_t name_ptr;
10131 +       uint32_t space_used;                    /* used space in kbytes */
10132 +       uint32_t space_total;                   /* maximum space in kbytes */
10133 +       uint32_t inodes_used;                   /* used inodes */
10134 +       uint32_t inodes_total;                  /* maximum inodes */
10135 +       uint32_t reserved;                      /* reserved for root in % */
10136 +       uint32_t flags;
10137 +};
10138 +
10139 +#endif /* CONFIG_COMPAT */
10140 +
10141 +#include <linux/compiler.h>
10142 +
10143 +extern int vc_add_dlimit(uint32_t, void __user *);
10144 +extern int vc_rem_dlimit(uint32_t, void __user *);
10145 +
10146 +extern int vc_set_dlimit(uint32_t, void __user *);
10147 +extern int vc_get_dlimit(uint32_t, void __user *);
10148 +
10149 +#ifdef CONFIG_COMPAT
10150 +
10151 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
10152 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
10153 +
10154 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
10155 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
10156 +
10157 +#endif /* CONFIG_COMPAT */
10158 +
10159 +#endif /* _VSERVER_DLIMIT_CMD_H */
10160 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/global.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/global.h
10161 --- linux-4.4.161/include/linux/vserver/global.h        1970-01-01 00:00:00.000000000 +0000
10162 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/global.h      2018-10-20 04:57:21.000000000 +0000
10163 @@ -0,0 +1,19 @@
10164 +#ifndef _VSERVER_GLOBAL_H
10165 +#define _VSERVER_GLOBAL_H
10166 +
10167 +
10168 +extern atomic_t vx_global_ctotal;
10169 +extern atomic_t vx_global_cactive;
10170 +
10171 +extern atomic_t nx_global_ctotal;
10172 +extern atomic_t nx_global_cactive;
10173 +
10174 +extern atomic_t vs_global_nsproxy;
10175 +extern atomic_t vs_global_fs;
10176 +extern atomic_t vs_global_mnt_ns;
10177 +extern atomic_t vs_global_uts_ns;
10178 +extern atomic_t vs_global_user_ns;
10179 +extern atomic_t vs_global_pid_ns;
10180 +
10181 +
10182 +#endif /* _VSERVER_GLOBAL_H */
10183 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/history.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/history.h
10184 --- linux-4.4.161/include/linux/vserver/history.h       1970-01-01 00:00:00.000000000 +0000
10185 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/history.h     2018-10-20 04:57:21.000000000 +0000
10186 @@ -0,0 +1,197 @@
10187 +#ifndef _VSERVER_HISTORY_H
10188 +#define _VSERVER_HISTORY_H
10189 +
10190 +
10191 +enum {
10192 +       VXH_UNUSED = 0,
10193 +       VXH_THROW_OOPS = 1,
10194 +
10195 +       VXH_GET_VX_INFO,
10196 +       VXH_PUT_VX_INFO,
10197 +       VXH_INIT_VX_INFO,
10198 +       VXH_SET_VX_INFO,
10199 +       VXH_CLR_VX_INFO,
10200 +       VXH_CLAIM_VX_INFO,
10201 +       VXH_RELEASE_VX_INFO,
10202 +       VXH_ALLOC_VX_INFO,
10203 +       VXH_DEALLOC_VX_INFO,
10204 +       VXH_HASH_VX_INFO,
10205 +       VXH_UNHASH_VX_INFO,
10206 +       VXH_LOC_VX_INFO,
10207 +       VXH_LOOKUP_VX_INFO,
10208 +       VXH_CREATE_VX_INFO,
10209 +};
10210 +
10211 +struct _vxhe_vxi {
10212 +       struct vx_info *ptr;
10213 +       unsigned xid;
10214 +       unsigned usecnt;
10215 +       unsigned tasks;
10216 +};
10217 +
10218 +struct _vxhe_set_clr {
10219 +       void *data;
10220 +};
10221 +
10222 +struct _vxhe_loc_lookup {
10223 +       unsigned arg;
10224 +};
10225 +
10226 +struct _vx_hist_entry {
10227 +       void *loc;
10228 +       unsigned short seq;
10229 +       unsigned short type;
10230 +       struct _vxhe_vxi vxi;
10231 +       union {
10232 +               struct _vxhe_set_clr sc;
10233 +               struct _vxhe_loc_lookup ll;
10234 +       };
10235 +};
10236 +
10237 +#ifdef CONFIG_VSERVER_HISTORY
10238 +
10239 +extern unsigned volatile int vxh_active;
10240 +
10241 +struct _vx_hist_entry *vxh_advance(void *loc);
10242 +
10243 +
10244 +static inline
10245 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
10246 +{
10247 +       entry->vxi.ptr = vxi;
10248 +       if (vxi) {
10249 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
10250 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
10251 +               entry->vxi.xid = vxi->vx_id;
10252 +       }
10253 +}
10254 +
10255 +
10256 +#define        __HERE__ current_text_addr()
10257 +
10258 +#define __VXH_BODY(__type, __data, __here)     \
10259 +       struct _vx_hist_entry *entry;           \
10260 +                                               \
10261 +       preempt_disable();                      \
10262 +       entry = vxh_advance(__here);            \
10263 +       __data;                                 \
10264 +       entry->type = __type;                   \
10265 +       preempt_enable();
10266 +
10267 +
10268 +       /* pass vxi only */
10269 +
10270 +#define __VXH_SMPL                             \
10271 +       __vxh_copy_vxi(entry, vxi)
10272 +
10273 +static inline
10274 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
10275 +{
10276 +       __VXH_BODY(__type, __VXH_SMPL, __here)
10277 +}
10278 +
10279 +       /* pass vxi and data (void *) */
10280 +
10281 +#define __VXH_DATA                             \
10282 +       __vxh_copy_vxi(entry, vxi);             \
10283 +       entry->sc.data = data
10284 +
10285 +static inline
10286 +void   __vxh_data(struct vx_info *vxi, void *data,
10287 +                       int __type, void *__here)
10288 +{
10289 +       __VXH_BODY(__type, __VXH_DATA, __here)
10290 +}
10291 +
10292 +       /* pass vxi and arg (long) */
10293 +
10294 +#define __VXH_LONG                             \
10295 +       __vxh_copy_vxi(entry, vxi);             \
10296 +       entry->ll.arg = arg
10297 +
10298 +static inline
10299 +void   __vxh_long(struct vx_info *vxi, long arg,
10300 +                       int __type, void *__here)
10301 +{
10302 +       __VXH_BODY(__type, __VXH_LONG, __here)
10303 +}
10304 +
10305 +
10306 +static inline
10307 +void   __vxh_throw_oops(void *__here)
10308 +{
10309 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
10310 +       /* prevent further acquisition */
10311 +       vxh_active = 0;
10312 +}
10313 +
10314 +
10315 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
10316 +
10317 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
10318 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
10319 +
10320 +#define __vxh_init_vx_info(v, d, h) \
10321 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
10322 +#define __vxh_set_vx_info(v, d, h) \
10323 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
10324 +#define __vxh_clr_vx_info(v, d, h) \
10325 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
10326 +
10327 +#define __vxh_claim_vx_info(v, d, h) \
10328 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
10329 +#define __vxh_release_vx_info(v, d, h) \
10330 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
10331 +
10332 +#define vxh_alloc_vx_info(v) \
10333 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
10334 +#define vxh_dealloc_vx_info(v) \
10335 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
10336 +
10337 +#define vxh_hash_vx_info(v) \
10338 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
10339 +#define vxh_unhash_vx_info(v) \
10340 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
10341 +
10342 +#define vxh_loc_vx_info(v, l) \
10343 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
10344 +#define vxh_lookup_vx_info(v, l) \
10345 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
10346 +#define vxh_create_vx_info(v, l) \
10347 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
10348 +
10349 +extern void vxh_dump_history(void);
10350 +
10351 +
10352 +#else  /* CONFIG_VSERVER_HISTORY */
10353 +
10354 +#define        __HERE__        0
10355 +
10356 +#define vxh_throw_oops()               do { } while (0)
10357 +
10358 +#define __vxh_get_vx_info(v, h)                do { } while (0)
10359 +#define __vxh_put_vx_info(v, h)                do { } while (0)
10360 +
10361 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
10362 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
10363 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
10364 +
10365 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
10366 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
10367 +
10368 +#define vxh_alloc_vx_info(v)           do { } while (0)
10369 +#define vxh_dealloc_vx_info(v)         do { } while (0)
10370 +
10371 +#define vxh_hash_vx_info(v)            do { } while (0)
10372 +#define vxh_unhash_vx_info(v)          do { } while (0)
10373 +
10374 +#define vxh_loc_vx_info(v, l)          do { } while (0)
10375 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
10376 +#define vxh_create_vx_info(v, l)       do { } while (0)
10377 +
10378 +#define vxh_dump_history()             do { } while (0)
10379 +
10380 +
10381 +#endif /* CONFIG_VSERVER_HISTORY */
10382 +
10383 +#endif /* _VSERVER_HISTORY_H */
10384 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/inode.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/inode.h
10385 --- linux-4.4.161/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
10386 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/inode.h       2018-10-20 04:57:21.000000000 +0000
10387 @@ -0,0 +1,19 @@
10388 +#ifndef _VSERVER_INODE_H
10389 +#define _VSERVER_INODE_H
10390 +
10391 +#include <uapi/vserver/inode.h>
10392 +
10393 +
10394 +#ifdef CONFIG_VSERVER_PROC_SECURE
10395 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
10396 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10397 +#else
10398 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
10399 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10400 +#endif
10401 +
10402 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
10403 +
10404 +#else  /* _VSERVER_INODE_H */
10405 +#warning duplicate inclusion
10406 +#endif /* _VSERVER_INODE_H */
10407 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/inode_cmd.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/inode_cmd.h
10408 --- linux-4.4.161/include/linux/vserver/inode_cmd.h     1970-01-01 00:00:00.000000000 +0000
10409 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/inode_cmd.h   2018-10-20 04:57:21.000000000 +0000
10410 @@ -0,0 +1,36 @@
10411 +#ifndef _VSERVER_INODE_CMD_H
10412 +#define _VSERVER_INODE_CMD_H
10413 +
10414 +#include <uapi/vserver/inode_cmd.h>
10415 +
10416 +
10417 +
10418 +#ifdef CONFIG_COMPAT
10419 +
10420 +#include <asm/compat.h>
10421 +
10422 +struct vcmd_ctx_iattr_v1_x32 {
10423 +       compat_uptr_t name_ptr;
10424 +       uint32_t tag;
10425 +       uint32_t flags;
10426 +       uint32_t mask;
10427 +};
10428 +
10429 +#endif /* CONFIG_COMPAT */
10430 +
10431 +#include <linux/compiler.h>
10432 +
10433 +extern int vc_get_iattr(void __user *);
10434 +extern int vc_set_iattr(void __user *);
10435 +
10436 +extern int vc_fget_iattr(uint32_t, void __user *);
10437 +extern int vc_fset_iattr(uint32_t, void __user *);
10438 +
10439 +#ifdef CONFIG_COMPAT
10440 +
10441 +extern int vc_get_iattr_x32(void __user *);
10442 +extern int vc_set_iattr_x32(void __user *);
10443 +
10444 +#endif /* CONFIG_COMPAT */
10445 +
10446 +#endif /* _VSERVER_INODE_CMD_H */
10447 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/limit.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/limit.h
10448 --- linux-4.4.161/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
10449 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/limit.h       2018-10-20 04:57:21.000000000 +0000
10450 @@ -0,0 +1,67 @@
10451 +#ifndef _VSERVER_LIMIT_H
10452 +#define _VSERVER_LIMIT_H
10453 +
10454 +#include <uapi/vserver/limit.h>
10455 +
10456 +
10457 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
10458 +
10459 +/*     keep in sync with CRLIM_INFINITY */
10460 +
10461 +#define        VLIM_INFINITY   (~0ULL)
10462 +
10463 +#include <asm/atomic.h>
10464 +#include <asm/resource.h>
10465 +
10466 +#ifndef RLIM_INFINITY
10467 +#warning RLIM_INFINITY is undefined
10468 +#endif
10469 +
10470 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
10471 +
10472 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
10473 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
10474 +
10475 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
10476 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
10477 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
10478 +
10479 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
10480 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
10481 +
10482 +typedef atomic_long_t rlim_atomic_t;
10483 +typedef unsigned long rlim_t;
10484 +
10485 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
10486 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
10487 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
10488 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
10489 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
10490 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
10491 +
10492 +
10493 +#if    (RLIM_INFINITY == VLIM_INFINITY)
10494 +#define        VX_VLIM(r) ((long long)(long)(r))
10495 +#define        VX_RLIM(v) ((rlim_t)(v))
10496 +#else
10497 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
10498 +               ? VLIM_INFINITY : (long long)(r))
10499 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
10500 +               ? RLIM_INFINITY : (rlim_t)(v))
10501 +#endif
10502 +
10503 +struct sysinfo;
10504 +
10505 +#ifdef CONFIG_MEMCG
10506 +void vx_vsi_meminfo(struct sysinfo *);
10507 +void vx_vsi_swapinfo(struct sysinfo *);
10508 +long vx_vsi_cached(struct sysinfo *);
10509 +#else  /* !CONFIG_MEMCG */
10510 +#define vx_vsi_meminfo(s) do { } while (0)
10511 +#define vx_vsi_swapinfo(s) do { } while (0)
10512 +#define vx_vsi_cached(s) (0L)
10513 +#endif /* !CONFIG_MEMCG */
10514 +
10515 +#define NUM_LIMITS     24
10516 +
10517 +#endif /* _VSERVER_LIMIT_H */
10518 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/limit_cmd.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/limit_cmd.h
10519 --- linux-4.4.161/include/linux/vserver/limit_cmd.h     1970-01-01 00:00:00.000000000 +0000
10520 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/limit_cmd.h   2018-10-20 04:57:21.000000000 +0000
10521 @@ -0,0 +1,35 @@
10522 +#ifndef _VSERVER_LIMIT_CMD_H
10523 +#define _VSERVER_LIMIT_CMD_H
10524 +
10525 +#include <uapi/vserver/limit_cmd.h>
10526 +
10527 +
10528 +#ifdef CONFIG_IA32_EMULATION
10529 +
10530 +struct vcmd_ctx_rlimit_v0_x32 {
10531 +       uint32_t id;
10532 +       uint64_t minimum;
10533 +       uint64_t softlimit;
10534 +       uint64_t maximum;
10535 +} __attribute__ ((packed));
10536 +
10537 +#endif /* CONFIG_IA32_EMULATION */
10538 +
10539 +#include <linux/compiler.h>
10540 +
10541 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
10542 +extern int vc_get_rlimit(struct vx_info *, void __user *);
10543 +extern int vc_set_rlimit(struct vx_info *, void __user *);
10544 +extern int vc_reset_hits(struct vx_info *, void __user *);
10545 +extern int vc_reset_minmax(struct vx_info *, void __user *);
10546 +
10547 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
10548 +
10549 +#ifdef CONFIG_IA32_EMULATION
10550 +
10551 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
10552 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
10553 +
10554 +#endif /* CONFIG_IA32_EMULATION */
10555 +
10556 +#endif /* _VSERVER_LIMIT_CMD_H */
10557 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/limit_def.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/limit_def.h
10558 --- linux-4.4.161/include/linux/vserver/limit_def.h     1970-01-01 00:00:00.000000000 +0000
10559 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/limit_def.h   2018-10-20 04:57:21.000000000 +0000
10560 @@ -0,0 +1,47 @@
10561 +#ifndef _VSERVER_LIMIT_DEF_H
10562 +#define _VSERVER_LIMIT_DEF_H
10563 +
10564 +#include <asm/atomic.h>
10565 +#include <asm/resource.h>
10566 +
10567 +#include "limit.h"
10568 +
10569 +
10570 +struct _vx_res_limit {
10571 +       rlim_t soft;            /* Context soft limit */
10572 +       rlim_t hard;            /* Context hard limit */
10573 +
10574 +       rlim_atomic_t rcur;     /* Current value */
10575 +       rlim_t rmin;            /* Context minimum */
10576 +       rlim_t rmax;            /* Context maximum */
10577 +
10578 +       atomic_t lhit;          /* Limit hits */
10579 +};
10580 +
10581 +/* context sub struct */
10582 +
10583 +struct _vx_limit {
10584 +       struct _vx_res_limit res[NUM_LIMITS];
10585 +};
10586 +
10587 +#ifdef CONFIG_VSERVER_DEBUG
10588 +
10589 +static inline void __dump_vx_limit(struct _vx_limit *limit)
10590 +{
10591 +       int i;
10592 +
10593 +       printk("\t_vx_limit:");
10594 +       for (i = 0; i < NUM_LIMITS; i++) {
10595 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
10596 +                       i, (unsigned long)__rlim_get(limit, i),
10597 +                       (unsigned long)__rlim_rmin(limit, i),
10598 +                       (unsigned long)__rlim_rmax(limit, i),
10599 +                       (long)__rlim_soft(limit, i),
10600 +                       (long)__rlim_hard(limit, i),
10601 +                       atomic_read(&__rlim_lhit(limit, i)));
10602 +       }
10603 +}
10604 +
10605 +#endif
10606 +
10607 +#endif /* _VSERVER_LIMIT_DEF_H */
10608 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/limit_int.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/limit_int.h
10609 --- linux-4.4.161/include/linux/vserver/limit_int.h     1970-01-01 00:00:00.000000000 +0000
10610 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/limit_int.h   2018-10-20 04:57:21.000000000 +0000
10611 @@ -0,0 +1,193 @@
10612 +#ifndef _VSERVER_LIMIT_INT_H
10613 +#define _VSERVER_LIMIT_INT_H
10614 +
10615 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
10616 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
10617 +
10618 +extern const char *vlimit_name[NUM_LIMITS];
10619 +
10620 +static inline void __vx_acc_cres(struct vx_info *vxi,
10621 +       int res, int dir, void *_data, char *_file, int _line)
10622 +{
10623 +       if (VXD_RCRES_COND(res))
10624 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
10625 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10626 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10627 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
10628 +       if (!vxi)
10629 +               return;
10630 +
10631 +       if (dir > 0)
10632 +               __rlim_inc(&vxi->limit, res);
10633 +       else
10634 +               __rlim_dec(&vxi->limit, res);
10635 +}
10636 +
10637 +static inline void __vx_add_cres(struct vx_info *vxi,
10638 +       int res, int amount, void *_data, char *_file, int _line)
10639 +{
10640 +       if (VXD_RCRES_COND(res))
10641 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
10642 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10643 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10644 +                       amount, _data, _file, _line);
10645 +       if (amount == 0)
10646 +               return;
10647 +       if (!vxi)
10648 +               return;
10649 +       __rlim_add(&vxi->limit, res, amount);
10650 +}
10651 +
10652 +static inline
10653 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
10654 +{
10655 +       int cond = (value > __rlim_rmax(limit, res));
10656 +
10657 +       if (cond)
10658 +               __rlim_rmax(limit, res) = value;
10659 +       return cond;
10660 +}
10661 +
10662 +static inline
10663 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
10664 +{
10665 +       int cond = (value < __rlim_rmin(limit, res));
10666 +
10667 +       if (cond)
10668 +               __rlim_rmin(limit, res) = value;
10669 +       return cond;
10670 +}
10671 +
10672 +static inline
10673 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
10674 +{
10675 +       if (!__vx_cres_adjust_max(limit, res, value))
10676 +               __vx_cres_adjust_min(limit, res, value);
10677 +}
10678 +
10679 +
10680 +/*     return values:
10681 +        +1 ... no limit hit
10682 +        -1 ... over soft limit
10683 +         0 ... over hard limit         */
10684 +
10685 +static inline int __vx_cres_avail(struct vx_info *vxi,
10686 +       int res, int num, char *_file, int _line)
10687 +{
10688 +       struct _vx_limit *limit;
10689 +       rlim_t value;
10690 +
10691 +       if (VXD_RLIMIT_COND(res))
10692 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
10693 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10694 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
10695 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
10696 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10697 +                       num, _file, _line);
10698 +       if (!vxi)
10699 +               return 1;
10700 +
10701 +       limit = &vxi->limit;
10702 +       value = __rlim_get(limit, res);
10703 +
10704 +       if (!__vx_cres_adjust_max(limit, res, value))
10705 +               __vx_cres_adjust_min(limit, res, value);
10706 +
10707 +       if (num == 0)
10708 +               return 1;
10709 +
10710 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
10711 +               return -1;
10712 +       if (value + num <= __rlim_soft(limit, res))
10713 +               return -1;
10714 +
10715 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
10716 +               return 1;
10717 +       if (value + num <= __rlim_hard(limit, res))
10718 +               return 1;
10719 +
10720 +       __rlim_hit(limit, res);
10721 +       return 0;
10722 +}
10723 +
10724 +
10725 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
10726 +
10727 +static inline
10728 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
10729 +{
10730 +       rlim_t value, sum = 0;
10731 +       int res;
10732 +
10733 +       while ((res = *array++)) {
10734 +               value = __rlim_get(limit, res);
10735 +               __vx_cres_fixup(limit, res, value);
10736 +               sum += value;
10737 +       }
10738 +       return sum;
10739 +}
10740 +
10741 +static inline
10742 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
10743 +{
10744 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
10745 +       int res = *array;
10746 +
10747 +       if (value == __rlim_get(limit, res))
10748 +               return value;
10749 +
10750 +       __rlim_set(limit, res, value);
10751 +       /* now adjust min/max */
10752 +       if (!__vx_cres_adjust_max(limit, res, value))
10753 +               __vx_cres_adjust_min(limit, res, value);
10754 +
10755 +       return value;
10756 +}
10757 +
10758 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
10759 +       const int *array, int num, char *_file, int _line)
10760 +{
10761 +       struct _vx_limit *limit;
10762 +       rlim_t value = 0;
10763 +       int res;
10764 +
10765 +       if (num == 0)
10766 +               return 1;
10767 +       if (!vxi)
10768 +               return 1;
10769 +
10770 +       limit = &vxi->limit;
10771 +       res = *array;
10772 +       value = __vx_cres_array_sum(limit, array + 1);
10773 +
10774 +       __rlim_set(limit, res, value);
10775 +       __vx_cres_fixup(limit, res, value);
10776 +
10777 +       return __vx_cres_avail(vxi, res, num, _file, _line);
10778 +}
10779 +
10780 +
10781 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
10782 +{
10783 +       rlim_t value;
10784 +       int res;
10785 +
10786 +       /* complex resources first */
10787 +       if ((id < 0) || (id == RLIMIT_RSS))
10788 +               __vx_cres_array_fixup(limit, VLA_RSS);
10789 +
10790 +       for (res = 0; res < NUM_LIMITS; res++) {
10791 +               if ((id > 0) && (res != id))
10792 +                       continue;
10793 +
10794 +               value = __rlim_get(limit, res);
10795 +               __vx_cres_fixup(limit, res, value);
10796 +
10797 +               /* not supposed to happen, maybe warn? */
10798 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
10799 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
10800 +       }
10801 +}
10802 +
10803 +
10804 +#endif /* _VSERVER_LIMIT_INT_H */
10805 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/monitor.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/monitor.h
10806 --- linux-4.4.161/include/linux/vserver/monitor.h       1970-01-01 00:00:00.000000000 +0000
10807 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/monitor.h     2018-10-20 04:57:21.000000000 +0000
10808 @@ -0,0 +1,6 @@
10809 +#ifndef _VSERVER_MONITOR_H
10810 +#define _VSERVER_MONITOR_H
10811 +
10812 +#include <uapi/vserver/monitor.h>
10813 +
10814 +#endif /* _VSERVER_MONITOR_H */
10815 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/network.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/network.h
10816 --- linux-4.4.161/include/linux/vserver/network.h       1970-01-01 00:00:00.000000000 +0000
10817 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/network.h     2018-10-20 04:57:21.000000000 +0000
10818 @@ -0,0 +1,76 @@
10819 +#ifndef _VSERVER_NETWORK_H
10820 +#define _VSERVER_NETWORK_H
10821 +
10822 +
10823 +#include <linux/list.h>
10824 +#include <linux/spinlock.h>
10825 +#include <linux/rcupdate.h>
10826 +#include <linux/in.h>
10827 +#include <linux/in6.h>
10828 +#include <asm/atomic.h>
10829 +#include <uapi/vserver/network.h>
10830 +
10831 +struct nx_addr_v4 {
10832 +       struct nx_addr_v4 *next;
10833 +       struct in_addr ip[2];
10834 +       struct in_addr mask;
10835 +       uint16_t type;
10836 +       uint16_t flags;
10837 +};
10838 +
10839 +struct nx_addr_v6 {
10840 +       struct nx_addr_v6 *next;
10841 +       struct in6_addr ip;
10842 +       struct in6_addr mask;
10843 +       uint32_t prefix;
10844 +       uint16_t type;
10845 +       uint16_t flags;
10846 +};
10847 +
10848 +struct nx_info {
10849 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
10850 +       vnid_t nx_id;                   /* vnet id */
10851 +       atomic_t nx_usecnt;             /* usage count */
10852 +       atomic_t nx_tasks;              /* tasks count */
10853 +       int nx_state;                   /* context state */
10854 +
10855 +       uint64_t nx_flags;              /* network flag word */
10856 +       uint64_t nx_ncaps;              /* network capabilities */
10857 +
10858 +       spinlock_t addr_lock;           /* protect address changes */
10859 +       struct in_addr v4_lback;        /* Loopback address */
10860 +       struct in_addr v4_bcast;        /* Broadcast address */
10861 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
10862 +#ifdef CONFIG_IPV6
10863 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
10864 +#endif
10865 +       char nx_name[65];               /* network context name */
10866 +};
10867 +
10868 +
10869 +/* status flags */
10870 +
10871 +#define NXS_HASHED      0x0001
10872 +#define NXS_SHUTDOWN    0x0100
10873 +#define NXS_RELEASED    0x8000
10874 +
10875 +extern struct nx_info *lookup_nx_info(int);
10876 +
10877 +extern int get_nid_list(int, unsigned int *, int);
10878 +extern int nid_is_hashed(vnid_t);
10879 +
10880 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
10881 +
10882 +extern long vs_net_change(struct nx_info *, unsigned int);
10883 +
10884 +struct sock;
10885 +
10886 +
10887 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
10888 +#ifdef  CONFIG_IPV6
10889 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
10890 +#else
10891 +#define NX_IPV6(n)     (0)
10892 +#endif
10893 +
10894 +#endif /* _VSERVER_NETWORK_H */
10895 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/network_cmd.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/network_cmd.h
10896 --- linux-4.4.161/include/linux/vserver/network_cmd.h   1970-01-01 00:00:00.000000000 +0000
10897 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/network_cmd.h 2018-10-20 04:57:21.000000000 +0000
10898 @@ -0,0 +1,37 @@
10899 +#ifndef _VSERVER_NETWORK_CMD_H
10900 +#define _VSERVER_NETWORK_CMD_H
10901 +
10902 +#include <uapi/vserver/network_cmd.h>
10903 +
10904 +extern int vc_task_nid(uint32_t);
10905 +
10906 +extern int vc_nx_info(struct nx_info *, void __user *);
10907 +
10908 +extern int vc_net_create(uint32_t, void __user *);
10909 +extern int vc_net_migrate(struct nx_info *, void __user *);
10910 +
10911 +extern int vc_net_add(struct nx_info *, void __user *);
10912 +extern int vc_net_remove(struct nx_info *, void __user *);
10913 +
10914 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
10915 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
10916 +
10917 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
10918 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
10919 +
10920 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
10921 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
10922 +
10923 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
10924 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
10925 +
10926 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
10927 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
10928 +
10929 +extern int vc_get_nflags(struct nx_info *, void __user *);
10930 +extern int vc_set_nflags(struct nx_info *, void __user *);
10931 +
10932 +extern int vc_get_ncaps(struct nx_info *, void __user *);
10933 +extern int vc_set_ncaps(struct nx_info *, void __user *);
10934 +
10935 +#endif /* _VSERVER_CONTEXT_CMD_H */
10936 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/percpu.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/percpu.h
10937 --- linux-4.4.161/include/linux/vserver/percpu.h        1970-01-01 00:00:00.000000000 +0000
10938 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/percpu.h      2018-10-20 04:57:21.000000000 +0000
10939 @@ -0,0 +1,14 @@
10940 +#ifndef _VSERVER_PERCPU_H
10941 +#define _VSERVER_PERCPU_H
10942 +
10943 +#include "cvirt_def.h"
10944 +#include "sched_def.h"
10945 +
10946 +struct _vx_percpu {
10947 +       struct _vx_cvirt_pc cvirt;
10948 +       struct _vx_sched_pc sched;
10949 +};
10950 +
10951 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
10952 +
10953 +#endif /* _VSERVER_PERCPU_H */
10954 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/pid.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/pid.h
10955 --- linux-4.4.161/include/linux/vserver/pid.h   1970-01-01 00:00:00.000000000 +0000
10956 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/pid.h 2018-10-20 04:57:21.000000000 +0000
10957 @@ -0,0 +1,51 @@
10958 +#ifndef _VSERVER_PID_H
10959 +#define _VSERVER_PID_H
10960 +
10961 +/* pid faking stuff */
10962 +
10963 +#define vx_info_map_pid(v, p) \
10964 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
10965 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
10966 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
10967 +#define vx_map_tgid(p) vx_map_pid(p)
10968 +
10969 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
10970 +       const char *func, const char *file, int line)
10971 +{
10972 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
10973 +               vxfprintk(VXD_CBIT(cvirt, 2),
10974 +                       "vx_map_tgid: %p/%llx: %d -> %d",
10975 +                       vxi, (long long)vxi->vx_flags, pid,
10976 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
10977 +                       func, file, line);
10978 +               if (pid == 0)
10979 +                       return 0;
10980 +               if (pid == vxi->vx_initpid)
10981 +                       return 1;
10982 +       }
10983 +       return pid;
10984 +}
10985 +
10986 +#define vx_info_rmap_pid(v, p) \
10987 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
10988 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
10989 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
10990 +
10991 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
10992 +       const char *func, const char *file, int line)
10993 +{
10994 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
10995 +               vxfprintk(VXD_CBIT(cvirt, 2),
10996 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
10997 +                       vxi, (long long)vxi->vx_flags, pid,
10998 +                       (pid == 1) ? vxi->vx_initpid : pid,
10999 +                       func, file, line);
11000 +               if ((pid == 1) && vxi->vx_initpid)
11001 +                       return vxi->vx_initpid;
11002 +               if (pid == vxi->vx_initpid)
11003 +                       return ~0U;
11004 +       }
11005 +       return pid;
11006 +}
11007 +
11008 +#endif
11009 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/sched.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/sched.h
11010 --- linux-4.4.161/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
11011 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/sched.h       2018-10-20 04:57:21.000000000 +0000
11012 @@ -0,0 +1,23 @@
11013 +#ifndef _VSERVER_SCHED_H
11014 +#define _VSERVER_SCHED_H
11015 +
11016 +
11017 +#ifdef __KERNEL__
11018 +
11019 +struct timespec;
11020 +
11021 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11022 +
11023 +
11024 +struct vx_info;
11025 +
11026 +void vx_update_load(struct vx_info *);
11027 +
11028 +
11029 +void vx_update_sched_param(struct _vx_sched *sched,
11030 +       struct _vx_sched_pc *sched_pc);
11031 +
11032 +#endif /* __KERNEL__ */
11033 +#else  /* _VSERVER_SCHED_H */
11034 +#warning duplicate inclusion
11035 +#endif /* _VSERVER_SCHED_H */
11036 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/sched_cmd.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/sched_cmd.h
11037 --- linux-4.4.161/include/linux/vserver/sched_cmd.h     1970-01-01 00:00:00.000000000 +0000
11038 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/sched_cmd.h   2018-10-20 04:57:21.000000000 +0000
11039 @@ -0,0 +1,11 @@
11040 +#ifndef _VSERVER_SCHED_CMD_H
11041 +#define _VSERVER_SCHED_CMD_H
11042 +
11043 +
11044 +#include <linux/compiler.h>
11045 +#include <uapi/vserver/sched_cmd.h>
11046 +
11047 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
11048 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
11049 +
11050 +#endif /* _VSERVER_SCHED_CMD_H */
11051 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/sched_def.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/sched_def.h
11052 --- linux-4.4.161/include/linux/vserver/sched_def.h     1970-01-01 00:00:00.000000000 +0000
11053 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/sched_def.h   2018-10-20 04:57:21.000000000 +0000
11054 @@ -0,0 +1,38 @@
11055 +#ifndef _VSERVER_SCHED_DEF_H
11056 +#define _VSERVER_SCHED_DEF_H
11057 +
11058 +#include <linux/spinlock.h>
11059 +#include <linux/jiffies.h>
11060 +#include <linux/cpumask.h>
11061 +#include <asm/atomic.h>
11062 +#include <asm/param.h>
11063 +
11064 +
11065 +/* context sub struct */
11066 +
11067 +struct _vx_sched {
11068 +       int prio_bias;                  /* bias offset for priority */
11069 +
11070 +       cpumask_t update;               /* CPUs which should update */
11071 +};
11072 +
11073 +struct _vx_sched_pc {
11074 +       int prio_bias;                  /* bias offset for priority */
11075 +
11076 +       uint64_t user_ticks;            /* token tick events */
11077 +       uint64_t sys_ticks;             /* token tick events */
11078 +       uint64_t hold_ticks;            /* token ticks paused */
11079 +};
11080 +
11081 +
11082 +#ifdef CONFIG_VSERVER_DEBUG
11083 +
11084 +static inline void __dump_vx_sched(struct _vx_sched *sched)
11085 +{
11086 +       printk("\t_vx_sched:\n");
11087 +       printk("\t priority = %4d\n", sched->prio_bias);
11088 +}
11089 +
11090 +#endif
11091 +
11092 +#endif /* _VSERVER_SCHED_DEF_H */
11093 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/signal.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/signal.h
11094 --- linux-4.4.161/include/linux/vserver/signal.h        1970-01-01 00:00:00.000000000 +0000
11095 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/signal.h      2018-10-20 04:57:21.000000000 +0000
11096 @@ -0,0 +1,14 @@
11097 +#ifndef _VSERVER_SIGNAL_H
11098 +#define _VSERVER_SIGNAL_H
11099 +
11100 +
11101 +#ifdef __KERNEL__
11102 +
11103 +struct vx_info;
11104 +
11105 +int vx_info_kill(struct vx_info *, int, int);
11106 +
11107 +#endif /* __KERNEL__ */
11108 +#else  /* _VSERVER_SIGNAL_H */
11109 +#warning duplicate inclusion
11110 +#endif /* _VSERVER_SIGNAL_H */
11111 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/signal_cmd.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/signal_cmd.h
11112 --- linux-4.4.161/include/linux/vserver/signal_cmd.h    1970-01-01 00:00:00.000000000 +0000
11113 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/signal_cmd.h  2018-10-20 04:57:21.000000000 +0000
11114 @@ -0,0 +1,14 @@
11115 +#ifndef _VSERVER_SIGNAL_CMD_H
11116 +#define _VSERVER_SIGNAL_CMD_H
11117 +
11118 +#include <uapi/vserver/signal_cmd.h>
11119 +
11120 +
11121 +extern int vc_ctx_kill(struct vx_info *, void __user *);
11122 +extern int vc_wait_exit(struct vx_info *, void __user *);
11123 +
11124 +
11125 +extern int vc_get_pflags(uint32_t pid, void __user *);
11126 +extern int vc_set_pflags(uint32_t pid, void __user *);
11127 +
11128 +#endif /* _VSERVER_SIGNAL_CMD_H */
11129 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/space.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/space.h
11130 --- linux-4.4.161/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
11131 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/space.h       2018-10-20 04:57:21.000000000 +0000
11132 @@ -0,0 +1,12 @@
11133 +#ifndef _VSERVER_SPACE_H
11134 +#define _VSERVER_SPACE_H
11135 +
11136 +#include <linux/types.h>
11137 +
11138 +struct vx_info;
11139 +
11140 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
11141 +
11142 +#else  /* _VSERVER_SPACE_H */
11143 +#warning duplicate inclusion
11144 +#endif /* _VSERVER_SPACE_H */
11145 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/space_cmd.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/space_cmd.h
11146 --- linux-4.4.161/include/linux/vserver/space_cmd.h     1970-01-01 00:00:00.000000000 +0000
11147 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/space_cmd.h   2018-10-20 04:57:21.000000000 +0000
11148 @@ -0,0 +1,13 @@
11149 +#ifndef _VSERVER_SPACE_CMD_H
11150 +#define _VSERVER_SPACE_CMD_H
11151 +
11152 +#include <uapi/vserver/space_cmd.h>
11153 +
11154 +
11155 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
11156 +extern int vc_set_space_v1(struct vx_info *, void __user *);
11157 +extern int vc_enter_space(struct vx_info *, void __user *);
11158 +extern int vc_set_space(struct vx_info *, void __user *);
11159 +extern int vc_get_space_mask(void __user *, int);
11160 +
11161 +#endif /* _VSERVER_SPACE_CMD_H */
11162 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/switch.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/switch.h
11163 --- linux-4.4.161/include/linux/vserver/switch.h        1970-01-01 00:00:00.000000000 +0000
11164 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/switch.h      2018-10-20 04:57:21.000000000 +0000
11165 @@ -0,0 +1,8 @@
11166 +#ifndef _VSERVER_SWITCH_H
11167 +#define _VSERVER_SWITCH_H
11168 +
11169 +
11170 +#include <linux/errno.h>
11171 +#include <uapi/vserver/switch.h>
11172 +
11173 +#endif /* _VSERVER_SWITCH_H */
11174 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/tag.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/tag.h
11175 --- linux-4.4.161/include/linux/vserver/tag.h   1970-01-01 00:00:00.000000000 +0000
11176 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/tag.h 2018-10-20 04:57:21.000000000 +0000
11177 @@ -0,0 +1,160 @@
11178 +#ifndef _DX_TAG_H
11179 +#define _DX_TAG_H
11180 +
11181 +#include <linux/types.h>
11182 +#include <linux/uidgid.h>
11183 +
11184 +
11185 +#define DX_TAG(in)     (IS_TAGGED(in))
11186 +
11187 +
11188 +#ifdef CONFIG_TAG_NFSD
11189 +#define DX_TAG_NFSD    1
11190 +#else
11191 +#define DX_TAG_NFSD    0
11192 +#endif
11193 +
11194 +
11195 +#ifdef CONFIG_TAGGING_NONE
11196 +
11197 +#define MAX_UID                0xFFFFFFFF
11198 +#define MAX_GID                0xFFFFFFFF
11199 +
11200 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
11201 +
11202 +#define TAGINO_UID(cond, uid, tag)     (uid)
11203 +#define TAGINO_GID(cond, gid, tag)     (gid)
11204 +
11205 +#endif
11206 +
11207 +
11208 +#ifdef CONFIG_TAGGING_GID16
11209 +
11210 +#define MAX_UID                0xFFFFFFFF
11211 +#define MAX_GID                0x0000FFFF
11212 +
11213 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11214 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
11215 +
11216 +#define TAGINO_UID(cond, uid, tag)     (uid)
11217 +#define TAGINO_GID(cond, gid, tag)     \
11218 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
11219 +
11220 +#endif
11221 +
11222 +
11223 +#ifdef CONFIG_TAGGING_ID24
11224 +
11225 +#define MAX_UID                0x00FFFFFF
11226 +#define MAX_GID                0x00FFFFFF
11227 +
11228 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11229 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
11230 +
11231 +#define TAGINO_UID(cond, uid, tag)     \
11232 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
11233 +#define TAGINO_GID(cond, gid, tag)     \
11234 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
11235 +
11236 +#endif
11237 +
11238 +
11239 +#ifdef CONFIG_TAGGING_UID16
11240 +
11241 +#define MAX_UID                0x0000FFFF
11242 +#define MAX_GID                0xFFFFFFFF
11243 +
11244 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11245 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
11246 +
11247 +#define TAGINO_UID(cond, uid, tag)     \
11248 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
11249 +#define TAGINO_GID(cond, gid, tag)     (gid)
11250 +
11251 +#endif
11252 +
11253 +
11254 +#ifdef CONFIG_TAGGING_INTERN
11255 +
11256 +#define MAX_UID                0xFFFFFFFF
11257 +#define MAX_GID                0xFFFFFFFF
11258 +
11259 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11260 +       ((cond) ? (tag) : 0)
11261 +
11262 +#define TAGINO_UID(cond, uid, tag)     (uid)
11263 +#define TAGINO_GID(cond, gid, tag)     (gid)
11264 +
11265 +#endif
11266 +
11267 +
11268 +#ifndef CONFIG_TAGGING_NONE
11269 +#define dx_current_fstag(sb)   \
11270 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
11271 +#else
11272 +#define dx_current_fstag(sb)   (0)
11273 +#endif
11274 +
11275 +#ifndef CONFIG_TAGGING_INTERN
11276 +#define TAGINO_TAG(cond, tag)  (0)
11277 +#else
11278 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
11279 +#endif
11280 +
11281 +#define TAGINO_KUID(cond, kuid, ktag)  \
11282 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
11283 +#define TAGINO_KGID(cond, kgid, ktag)  \
11284 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
11285 +#define TAGINO_KTAG(cond, ktag)                \
11286 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
11287 +
11288 +
11289 +#define INOTAG_UID(cond, uid, gid)     \
11290 +       ((cond) ? ((uid) & MAX_UID) : (uid))
11291 +#define INOTAG_GID(cond, uid, gid)     \
11292 +       ((cond) ? ((gid) & MAX_GID) : (gid))
11293 +
11294 +#define INOTAG_KUID(cond, kuid, kgid)  \
11295 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11296 +#define INOTAG_KGID(cond, kuid, kgid)  \
11297 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11298 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
11299 +       KTAGT_INIT(INOTAG_TAG(cond, \
11300 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
11301 +
11302 +
11303 +static inline uid_t dx_map_uid(uid_t uid)
11304 +{
11305 +       if ((uid > MAX_UID) && (uid != -1))
11306 +               uid = -2;
11307 +       return (uid & MAX_UID);
11308 +}
11309 +
11310 +static inline gid_t dx_map_gid(gid_t gid)
11311 +{
11312 +       if ((gid > MAX_GID) && (gid != -1))
11313 +               gid = -2;
11314 +       return (gid & MAX_GID);
11315 +}
11316 +
11317 +struct peer_tag {
11318 +       int32_t xid;
11319 +       int32_t nid;
11320 +};
11321 +
11322 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
11323 +
11324 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
11325 +                unsigned long *flags);
11326 +
11327 +#ifdef CONFIG_PROPAGATE
11328 +
11329 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
11330 +
11331 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
11332 +
11333 +#else
11334 +#define dx_propagate_tag(n, i) do { } while (0)
11335 +#endif
11336 +
11337 +#endif /* _DX_TAG_H */
11338 diff -NurpP --minimal linux-4.4.161/include/linux/vserver/tag_cmd.h linux-4.4.161-vs2.3.9.8/include/linux/vserver/tag_cmd.h
11339 --- linux-4.4.161/include/linux/vserver/tag_cmd.h       1970-01-01 00:00:00.000000000 +0000
11340 +++ linux-4.4.161-vs2.3.9.8/include/linux/vserver/tag_cmd.h     2018-10-20 04:57:21.000000000 +0000
11341 @@ -0,0 +1,10 @@
11342 +#ifndef _VSERVER_TAG_CMD_H
11343 +#define _VSERVER_TAG_CMD_H
11344 +
11345 +#include <uapi/vserver/tag_cmd.h>
11346 +
11347 +extern int vc_task_tag(uint32_t);
11348 +
11349 +extern int vc_tag_migrate(uint32_t);
11350 +
11351 +#endif /* _VSERVER_TAG_CMD_H */
11352 diff -NurpP --minimal linux-4.4.161/include/net/addrconf.h linux-4.4.161-vs2.3.9.8/include/net/addrconf.h
11353 --- linux-4.4.161/include/net/addrconf.h        2018-10-20 02:34:30.000000000 +0000
11354 +++ linux-4.4.161-vs2.3.9.8/include/net/addrconf.h      2018-10-20 04:57:21.000000000 +0000
11355 @@ -84,7 +84,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
11356  
11357  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dev,
11358                        const struct in6_addr *daddr, unsigned int srcprefs,
11359 -                      struct in6_addr *saddr);
11360 +                      struct in6_addr *saddr, struct nx_info *nxi);
11361  int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
11362                       u32 banned_flags);
11363  int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
11364 diff -NurpP --minimal linux-4.4.161/include/net/af_unix.h linux-4.4.161-vs2.3.9.8/include/net/af_unix.h
11365 --- linux-4.4.161/include/net/af_unix.h 2018-10-20 02:34:30.000000000 +0000
11366 +++ linux-4.4.161-vs2.3.9.8/include/net/af_unix.h       2018-10-20 04:57:21.000000000 +0000
11367 @@ -4,6 +4,7 @@
11368  #include <linux/socket.h>
11369  #include <linux/un.h>
11370  #include <linux/mutex.h>
11371 +// #include <linux/vs_base.h>
11372  #include <net/sock.h>
11373  
11374  void unix_inflight(struct user_struct *user, struct file *fp);
11375 diff -NurpP --minimal linux-4.4.161/include/net/inet_timewait_sock.h linux-4.4.161-vs2.3.9.8/include/net/inet_timewait_sock.h
11376 --- linux-4.4.161/include/net/inet_timewait_sock.h      2018-10-20 02:34:30.000000000 +0000
11377 +++ linux-4.4.161-vs2.3.9.8/include/net/inet_timewait_sock.h    2018-10-20 04:57:21.000000000 +0000
11378 @@ -72,6 +72,10 @@ struct inet_timewait_sock {
11379  #define tw_num                 __tw_common.skc_num
11380  #define tw_cookie              __tw_common.skc_cookie
11381  #define tw_dr                  __tw_common.skc_tw_dr
11382 +#define tw_xid                 __tw_common.skc_xid
11383 +#define tw_vx_info             __tw_common.skc_vx_info
11384 +#define tw_nid                 __tw_common.skc_nid
11385 +#define tw_nx_info             __tw_common.skc_nx_info
11386  
11387         int                     tw_timeout;
11388         volatile unsigned char  tw_substate;
11389 diff -NurpP --minimal linux-4.4.161/include/net/ip6_route.h linux-4.4.161-vs2.3.9.8/include/net/ip6_route.h
11390 --- linux-4.4.161/include/net/ip6_route.h       2018-10-20 02:34:30.000000000 +0000
11391 +++ linux-4.4.161-vs2.3.9.8/include/net/ip6_route.h     2018-10-20 04:57:21.000000000 +0000
11392 @@ -90,7 +90,7 @@ int ip6_del_rt(struct rt6_info *);
11393  
11394  int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
11395                         const struct in6_addr *daddr, unsigned int prefs,
11396 -                       struct in6_addr *saddr);
11397 +                       struct in6_addr *saddr, struct nx_info *nxi);
11398  
11399  struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
11400                             const struct in6_addr *saddr, int oif, int flags);
11401 diff -NurpP --minimal linux-4.4.161/include/net/route.h linux-4.4.161-vs2.3.9.8/include/net/route.h
11402 --- linux-4.4.161/include/net/route.h   2018-10-20 02:34:30.000000000 +0000
11403 +++ linux-4.4.161-vs2.3.9.8/include/net/route.h 2018-10-20 04:57:21.000000000 +0000
11404 @@ -224,6 +224,9 @@ static inline void ip_rt_put(struct rtab
11405         dst_release(&rt->dst);
11406  }
11407  
11408 +#include <linux/vs_base.h>
11409 +#include <linux/vs_inet.h>
11410 +
11411  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
11412  
11413  extern const __u8 ip_tos2prio[16];
11414 @@ -271,6 +274,9 @@ static inline void ip_route_connect_init
11415                            protocol, flow_flags, dst, src, dport, sport);
11416  }
11417  
11418 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
11419 +       struct flowi4 *);
11420 +
11421  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
11422                                               __be32 dst, __be32 src, u32 tos,
11423                                               int oif, u8 protocol,
11424 @@ -279,6 +285,7 @@ static inline struct rtable *ip_route_co
11425  {
11426         struct net *net = sock_net(sk);
11427         struct rtable *rt;
11428 +       struct nx_info *nx_info = current_nx_info();
11429  
11430         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
11431                               sport, dport, sk);
11432 @@ -292,7 +299,21 @@ static inline struct rtable *ip_route_co
11433  
11434                 src = fl4->saddr;
11435         }
11436 -       if (!dst || !src) {
11437 +
11438 +       if (sk)
11439 +               nx_info = sk->sk_nx_info;
11440 +
11441 +       vxdprintk(VXD_CBIT(net, 4),
11442 +               "ip_route_connect(%p) %p,%p;%lx",
11443 +               sk, nx_info, sk->sk_socket,
11444 +               (sk->sk_socket?sk->sk_socket->flags:0));
11445 +
11446 +       rt = ip_v4_find_src(net, nx_info, fl4);
11447 +       if (IS_ERR(rt))
11448 +               return rt;
11449 +       ip_rt_put(rt);
11450 +
11451 +       if (!fl4->daddr || !fl4->saddr) {
11452                 rt = __ip_route_output_key(net, fl4);
11453                 if (IS_ERR(rt))
11454                         return rt;
11455 diff -NurpP --minimal linux-4.4.161/include/net/sock.h linux-4.4.161-vs2.3.9.8/include/net/sock.h
11456 --- linux-4.4.161/include/net/sock.h    2018-10-20 02:34:30.000000000 +0000
11457 +++ linux-4.4.161-vs2.3.9.8/include/net/sock.h  2018-10-20 05:50:20.000000000 +0000
11458 @@ -201,6 +201,10 @@ struct sock_common {
11459         struct in6_addr         skc_v6_daddr;
11460         struct in6_addr         skc_v6_rcv_saddr;
11461  #endif
11462 +       vxid_t                  skc_xid;
11463 +       struct vx_info          *skc_vx_info;
11464 +       vnid_t                  skc_nid;
11465 +       struct nx_info          *skc_nx_info;
11466  
11467         atomic64_t              skc_cookie;
11468  
11469 @@ -349,8 +353,12 @@ struct sock {
11470  #define sk_prot                        __sk_common.skc_prot
11471  #define sk_net                 __sk_common.skc_net
11472  #define sk_v6_daddr            __sk_common.skc_v6_daddr
11473 -#define sk_v6_rcv_saddr        __sk_common.skc_v6_rcv_saddr
11474 +#define sk_v6_rcv_saddr                __sk_common.skc_v6_rcv_saddr
11475  #define sk_cookie              __sk_common.skc_cookie
11476 +#define sk_xid                 __sk_common.skc_xid
11477 +#define sk_vx_info             __sk_common.skc_vx_info
11478 +#define sk_nid                 __sk_common.skc_nid
11479 +#define sk_nx_info             __sk_common.skc_nx_info
11480  #define sk_incoming_cpu                __sk_common.skc_incoming_cpu
11481  #define sk_flags               __sk_common.skc_flags
11482  #define sk_rxhash              __sk_common.skc_rxhash
11483 diff -NurpP --minimal linux-4.4.161/include/uapi/Kbuild linux-4.4.161-vs2.3.9.8/include/uapi/Kbuild
11484 --- linux-4.4.161/include/uapi/Kbuild   2016-01-10 23:01:32.000000000 +0000
11485 +++ linux-4.4.161-vs2.3.9.8/include/uapi/Kbuild 2018-10-20 04:57:21.000000000 +0000
11486 @@ -13,3 +13,4 @@ header-y += drm/
11487  header-y += xen/
11488  header-y += scsi/
11489  header-y += misc/
11490 +header-y += vserver/
11491 diff -NurpP --minimal linux-4.4.161/include/uapi/linux/capability.h linux-4.4.161-vs2.3.9.8/include/uapi/linux/capability.h
11492 --- linux-4.4.161/include/uapi/linux/capability.h       2016-01-10 23:01:32.000000000 +0000
11493 +++ linux-4.4.161-vs2.3.9.8/include/uapi/linux/capability.h     2018-10-20 04:57:21.000000000 +0000
11494 @@ -259,6 +259,7 @@ struct vfs_cap_data {
11495     arbitrary SCSI commands */
11496  /* Allow setting encryption key on loopback filesystem */
11497  /* Allow setting zone reclaim policy */
11498 +/* Allow the selection of a security context */
11499  
11500  #define CAP_SYS_ADMIN        21
11501  
11502 @@ -354,7 +355,12 @@ struct vfs_cap_data {
11503  
11504  #define CAP_LAST_CAP         CAP_AUDIT_READ
11505  
11506 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
11507 +/* Allow context manipulations */
11508 +/* Allow changing context info on files */
11509 +
11510 +#define CAP_CONTEXT         63
11511 +
11512 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
11513  
11514  /*
11515   * Bit location of each capability (used by user-space library and kernel)
11516 diff -NurpP --minimal linux-4.4.161/include/uapi/linux/fs.h linux-4.4.161-vs2.3.9.8/include/uapi/linux/fs.h
11517 --- linux-4.4.161/include/uapi/linux/fs.h       2016-01-10 23:01:32.000000000 +0000
11518 +++ linux-4.4.161-vs2.3.9.8/include/uapi/linux/fs.h     2018-10-20 04:57:21.000000000 +0000
11519 @@ -91,6 +91,9 @@ struct inodes_stat_t {
11520  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
11521  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
11522  #define MS_LAZYTIME    (1<<25) /* Update the on-disk [acm]times lazily */
11523 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
11524 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
11525 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
11526  
11527  /* These sb flags are internal to the kernel */
11528  #define MS_NOSEC       (1<<28)
11529 @@ -197,12 +200,15 @@ struct inodes_stat_t {
11530  #define FS_EXTENT_FL                   0x00080000 /* Extents */
11531  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
11532  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
11533 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
11534  #define FS_PROJINHERIT_FL              0x20000000 /* Create with parents projid */
11535  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
11536  
11537 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
11538 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
11539 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
11540 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
11541  
11542 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
11543 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
11544  
11545  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
11546  #define SYNC_FILE_RANGE_WRITE          2
11547 diff -NurpP --minimal linux-4.4.161/include/uapi/linux/gfs2_ondisk.h linux-4.4.161-vs2.3.9.8/include/uapi/linux/gfs2_ondisk.h
11548 --- linux-4.4.161/include/uapi/linux/gfs2_ondisk.h      2016-01-10 23:01:32.000000000 +0000
11549 +++ linux-4.4.161-vs2.3.9.8/include/uapi/linux/gfs2_ondisk.h    2018-10-20 04:57:21.000000000 +0000
11550 @@ -225,6 +225,9 @@ enum {
11551         gfs2fl_Sync             = 8,
11552         gfs2fl_System           = 9,
11553         gfs2fl_TopLevel         = 10,
11554 +       gfs2fl_IXUnlink         = 16,
11555 +       gfs2fl_Barrier          = 17,
11556 +       gfs2fl_Cow              = 18,
11557         gfs2fl_TruncInProg      = 29,
11558         gfs2fl_InheritDirectio  = 30,
11559         gfs2fl_InheritJdata     = 31,
11560 @@ -242,6 +245,9 @@ enum {
11561  #define GFS2_DIF_SYNC                  0x00000100
11562  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
11563  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
11564 +#define GFS2_DIF_IXUNLINK               0x00010000
11565 +#define GFS2_DIF_BARRIER                0x00020000
11566 +#define GFS2_DIF_COW                    0x00040000
11567  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
11568  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
11569  #define GFS2_DIF_INHERIT_JDATA         0x80000000
11570 diff -NurpP --minimal linux-4.4.161/include/uapi/linux/if_tun.h linux-4.4.161-vs2.3.9.8/include/uapi/linux/if_tun.h
11571 --- linux-4.4.161/include/uapi/linux/if_tun.h   2016-01-10 23:01:32.000000000 +0000
11572 +++ linux-4.4.161-vs2.3.9.8/include/uapi/linux/if_tun.h 2018-10-20 04:57:21.000000000 +0000
11573 @@ -56,6 +56,7 @@
11574   */
11575  #define TUNSETVNETBE _IOW('T', 222, int)
11576  #define TUNGETVNETBE _IOR('T', 223, int)
11577 +#define TUNSETNID    _IOW('T', 224, int)
11578  
11579  /* TUNSETIFF ifr flags */
11580  #define IFF_TUN                0x0001
11581 diff -NurpP --minimal linux-4.4.161/include/uapi/linux/major.h linux-4.4.161-vs2.3.9.8/include/uapi/linux/major.h
11582 --- linux-4.4.161/include/uapi/linux/major.h    2016-01-10 23:01:32.000000000 +0000
11583 +++ linux-4.4.161-vs2.3.9.8/include/uapi/linux/major.h  2018-10-20 04:57:21.000000000 +0000
11584 @@ -15,6 +15,7 @@
11585  #define HD_MAJOR               IDE0_MAJOR
11586  #define PTY_SLAVE_MAJOR                3
11587  #define TTY_MAJOR              4
11588 +#define VROOT_MAJOR            4
11589  #define TTYAUX_MAJOR           5
11590  #define LP_MAJOR               6
11591  #define VCS_MAJOR              7
11592 diff -NurpP --minimal linux-4.4.161/include/uapi/linux/nfs_mount.h linux-4.4.161-vs2.3.9.8/include/uapi/linux/nfs_mount.h
11593 --- linux-4.4.161/include/uapi/linux/nfs_mount.h        2016-01-10 23:01:32.000000000 +0000
11594 +++ linux-4.4.161-vs2.3.9.8/include/uapi/linux/nfs_mount.h      2018-10-20 04:57:21.000000000 +0000
11595 @@ -63,7 +63,8 @@ struct nfs_mount_data {
11596  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 non-text parsed mount data only */
11597  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
11598  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
11599 -#define NFS_MOUNT_FLAGMASK     0xFFFF
11600 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
11601 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
11602  
11603  /* The following are for internal use only */
11604  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
11605 diff -NurpP --minimal linux-4.4.161/include/uapi/linux/reboot.h linux-4.4.161-vs2.3.9.8/include/uapi/linux/reboot.h
11606 --- linux-4.4.161/include/uapi/linux/reboot.h   2016-01-10 23:01:32.000000000 +0000
11607 +++ linux-4.4.161-vs2.3.9.8/include/uapi/linux/reboot.h 2018-10-20 04:57:21.000000000 +0000
11608 @@ -33,7 +33,7 @@
11609  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
11610  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
11611  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
11612 -
11613 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
11614  
11615  
11616  #endif /* _UAPI_LINUX_REBOOT_H */
11617 diff -NurpP --minimal linux-4.4.161/include/uapi/linux/sysctl.h linux-4.4.161-vs2.3.9.8/include/uapi/linux/sysctl.h
11618 --- linux-4.4.161/include/uapi/linux/sysctl.h   2016-01-10 23:01:32.000000000 +0000
11619 +++ linux-4.4.161-vs2.3.9.8/include/uapi/linux/sysctl.h 2018-10-20 04:57:21.000000000 +0000
11620 @@ -60,6 +60,7 @@ enum
11621         CTL_ABI=9,              /* Binary emulation */
11622         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
11623         CTL_ARLAN=254,          /* arlan wireless driver */
11624 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
11625         CTL_S390DBF=5677,       /* s390 debug */
11626         CTL_SUNRPC=7249,        /* sunrpc debug */
11627         CTL_PM=9899,            /* frv power management */
11628 @@ -94,6 +95,7 @@ enum
11629  
11630         KERN_PANIC=15,          /* int: panic timeout */
11631         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11632 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11633  
11634         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11635         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11636 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/Kbuild linux-4.4.161-vs2.3.9.8/include/uapi/vserver/Kbuild
11637 --- linux-4.4.161/include/uapi/vserver/Kbuild   1970-01-01 00:00:00.000000000 +0000
11638 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/Kbuild 2018-10-20 04:57:21.000000000 +0000
11639 @@ -0,0 +1,9 @@
11640 +
11641 +header-y += context_cmd.h network_cmd.h space_cmd.h \
11642 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11643 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11644 +       debug_cmd.h device_cmd.h
11645 +
11646 +header-y += switch.h context.h network.h monitor.h \
11647 +       limit.h inode.h device.h
11648 +
11649 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/cacct_cmd.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/cacct_cmd.h
11650 --- linux-4.4.161/include/uapi/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
11651 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/cacct_cmd.h    2018-10-20 04:57:21.000000000 +0000
11652 @@ -0,0 +1,15 @@
11653 +#ifndef _UAPI_VS_CACCT_CMD_H
11654 +#define _UAPI_VS_CACCT_CMD_H
11655 +
11656 +
11657 +/* virtual host info name commands */
11658 +
11659 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11660 +
11661 +struct vcmd_sock_stat_v0 {
11662 +       uint32_t field;
11663 +       uint32_t count[3];
11664 +       uint64_t total[3];
11665 +};
11666 +
11667 +#endif /* _UAPI_VS_CACCT_CMD_H */
11668 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/context.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/context.h
11669 --- linux-4.4.161/include/uapi/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
11670 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/context.h      2018-10-20 04:57:21.000000000 +0000
11671 @@ -0,0 +1,81 @@
11672 +#ifndef _UAPI_VS_CONTEXT_H
11673 +#define _UAPI_VS_CONTEXT_H
11674 +
11675 +#include <linux/types.h>
11676 +#include <linux/capability.h>
11677 +
11678 +
11679 +/* context flags */
11680 +
11681 +#define VXF_INFO_SCHED         0x00000002
11682 +#define VXF_INFO_NPROC         0x00000004
11683 +#define VXF_INFO_PRIVATE       0x00000008
11684 +
11685 +#define VXF_INFO_INIT          0x00000010
11686 +#define VXF_INFO_HIDE          0x00000020
11687 +#define VXF_INFO_ULIMIT                0x00000040
11688 +#define VXF_INFO_NSPACE                0x00000080
11689 +
11690 +#define VXF_SCHED_HARD         0x00000100
11691 +#define VXF_SCHED_PRIO         0x00000200
11692 +#define VXF_SCHED_PAUSE                0x00000400
11693 +
11694 +#define VXF_VIRT_MEM           0x00010000
11695 +#define VXF_VIRT_UPTIME                0x00020000
11696 +#define VXF_VIRT_CPU           0x00040000
11697 +#define VXF_VIRT_LOAD          0x00080000
11698 +#define VXF_VIRT_TIME          0x00100000
11699 +
11700 +#define VXF_HIDE_MOUNT         0x01000000
11701 +/* was VXF_HIDE_NETIF          0x02000000 */
11702 +#define VXF_HIDE_VINFO         0x04000000
11703 +
11704 +#define VXF_STATE_SETUP                (1ULL << 32)
11705 +#define VXF_STATE_INIT         (1ULL << 33)
11706 +#define VXF_STATE_ADMIN                (1ULL << 34)
11707 +
11708 +#define VXF_SC_HELPER          (1ULL << 36)
11709 +#define VXF_REBOOT_KILL                (1ULL << 37)
11710 +#define VXF_PERSISTENT         (1ULL << 38)
11711 +
11712 +#define VXF_FORK_RSS           (1ULL << 48)
11713 +#define VXF_PROLIFIC           (1ULL << 49)
11714 +
11715 +#define VXF_IGNEG_NICE         (1ULL << 52)
11716 +
11717 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11718 +
11719 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11720 +
11721 +
11722 +/* context migration */
11723 +
11724 +#define VXM_SET_INIT           0x00000001
11725 +#define VXM_SET_REAPER         0x00000002
11726 +
11727 +/* context caps */
11728 +
11729 +#define VXC_SET_UTSNAME                0x00000001
11730 +#define VXC_SET_RLIMIT         0x00000002
11731 +#define VXC_FS_SECURITY                0x00000004
11732 +#define VXC_FS_TRUSTED         0x00000008
11733 +#define VXC_TIOCSTI            0x00000010
11734 +
11735 +/* was VXC_RAW_ICMP            0x00000100 */
11736 +#define VXC_SYSLOG             0x00001000
11737 +#define VXC_OOM_ADJUST         0x00002000
11738 +#define VXC_AUDIT_CONTROL      0x00004000
11739 +
11740 +#define VXC_SECURE_MOUNT       0x00010000
11741 +/* #define VXC_SECURE_REMOUNT  0x00020000 */
11742 +#define VXC_BINARY_MOUNT       0x00040000
11743 +#define VXC_DEV_MOUNT          0x00080000
11744 +
11745 +#define VXC_QUOTA_CTL          0x00100000
11746 +#define VXC_ADMIN_MAPPER       0x00200000
11747 +#define VXC_ADMIN_CLOOP                0x00400000
11748 +
11749 +#define VXC_KTHREAD            0x01000000
11750 +#define VXC_NAMESPACE          0x02000000
11751 +
11752 +#endif /* _UAPI_VS_CONTEXT_H */
11753 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/context_cmd.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/context_cmd.h
11754 --- linux-4.4.161/include/uapi/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
11755 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/context_cmd.h  2018-10-20 04:57:21.000000000 +0000
11756 @@ -0,0 +1,115 @@
11757 +#ifndef _UAPI_VS_CONTEXT_CMD_H
11758 +#define _UAPI_VS_CONTEXT_CMD_H
11759 +
11760 +
11761 +/* vinfo commands */
11762 +
11763 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11764 +
11765 +
11766 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11767 +
11768 +struct vcmd_vx_info_v0 {
11769 +       uint32_t xid;
11770 +       uint32_t initpid;
11771 +       /* more to come */
11772 +};
11773 +
11774 +
11775 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11776 +
11777 +struct vcmd_ctx_stat_v0 {
11778 +       uint32_t usecnt;
11779 +       uint32_t tasks;
11780 +       /* more to come */
11781 +};
11782 +
11783 +
11784 +/* context commands */
11785 +
11786 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11787 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11788 +
11789 +struct vcmd_ctx_create {
11790 +       uint64_t flagword;
11791 +};
11792 +
11793 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11794 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11795 +
11796 +struct vcmd_ctx_migrate {
11797 +       uint64_t flagword;
11798 +};
11799 +
11800 +
11801 +
11802 +/* flag commands */
11803 +
11804 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11805 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11806 +
11807 +struct vcmd_ctx_flags_v0 {
11808 +       uint64_t flagword;
11809 +       uint64_t mask;
11810 +};
11811 +
11812 +
11813 +
11814 +/* context caps commands */
11815 +
11816 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11817 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11818 +
11819 +struct vcmd_ctx_caps_v1 {
11820 +       uint64_t ccaps;
11821 +       uint64_t cmask;
11822 +};
11823 +
11824 +
11825 +
11826 +/* bcaps commands */
11827 +
11828 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11829 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11830 +
11831 +struct vcmd_bcaps {
11832 +       uint64_t bcaps;
11833 +       uint64_t bmask;
11834 +};
11835 +
11836 +
11837 +
11838 +/* umask commands */
11839 +
11840 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11841 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11842 +
11843 +struct vcmd_umask {
11844 +       uint64_t umask;
11845 +       uint64_t mask;
11846 +};
11847 +
11848 +
11849 +
11850 +/* wmask commands */
11851 +
11852 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11853 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11854 +
11855 +struct vcmd_wmask {
11856 +       uint64_t wmask;
11857 +       uint64_t mask;
11858 +};
11859 +
11860 +
11861 +
11862 +/* OOM badness */
11863 +
11864 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11865 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11866 +
11867 +struct vcmd_badness_v0 {
11868 +       int64_t bias;
11869 +};
11870 +
11871 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
11872 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/cvirt_cmd.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/cvirt_cmd.h
11873 --- linux-4.4.161/include/uapi/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
11874 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/cvirt_cmd.h    2018-10-20 04:57:21.000000000 +0000
11875 @@ -0,0 +1,41 @@
11876 +#ifndef _UAPI_VS_CVIRT_CMD_H
11877 +#define _UAPI_VS_CVIRT_CMD_H
11878 +
11879 +
11880 +/* virtual host info name commands */
11881 +
11882 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11883 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11884 +
11885 +struct vcmd_vhi_name_v0 {
11886 +       uint32_t field;
11887 +       char name[65];
11888 +};
11889 +
11890 +
11891 +enum vhi_name_field {
11892 +       VHIN_CONTEXT = 0,
11893 +       VHIN_SYSNAME,
11894 +       VHIN_NODENAME,
11895 +       VHIN_RELEASE,
11896 +       VHIN_VERSION,
11897 +       VHIN_MACHINE,
11898 +       VHIN_DOMAINNAME,
11899 +};
11900 +
11901 +
11902 +
11903 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11904 +
11905 +struct vcmd_virt_stat_v0 {
11906 +       uint64_t offset;
11907 +       uint64_t uptime;
11908 +       uint32_t nr_threads;
11909 +       uint32_t nr_running;
11910 +       uint32_t nr_uninterruptible;
11911 +       uint32_t nr_onhold;
11912 +       uint32_t nr_forks;
11913 +       uint32_t load[3];
11914 +};
11915 +
11916 +#endif /* _UAPI_VS_CVIRT_CMD_H */
11917 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/debug_cmd.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/debug_cmd.h
11918 --- linux-4.4.161/include/uapi/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
11919 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/debug_cmd.h    2018-10-20 04:57:21.000000000 +0000
11920 @@ -0,0 +1,24 @@
11921 +#ifndef _UAPI_VS_DEBUG_CMD_H
11922 +#define _UAPI_VS_DEBUG_CMD_H
11923 +
11924 +
11925 +/* debug commands */
11926 +
11927 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11928 +
11929 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11930 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11931 +
11932 +struct  vcmd_read_history_v0 {
11933 +       uint32_t index;
11934 +       uint32_t count;
11935 +       char __user *data;
11936 +};
11937 +
11938 +struct  vcmd_read_monitor_v0 {
11939 +       uint32_t index;
11940 +       uint32_t count;
11941 +       char __user *data;
11942 +};
11943 +
11944 +#endif /* _UAPI_VS_DEBUG_CMD_H */
11945 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/device.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/device.h
11946 --- linux-4.4.161/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
11947 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/device.h       2018-10-20 04:57:21.000000000 +0000
11948 @@ -0,0 +1,12 @@
11949 +#ifndef _UAPI_VS_DEVICE_H
11950 +#define _UAPI_VS_DEVICE_H
11951 +
11952 +
11953 +#define DATTR_CREATE   0x00000001
11954 +#define DATTR_OPEN     0x00000002
11955 +
11956 +#define DATTR_REMAP    0x00000010
11957 +
11958 +#define DATTR_MASK     0x00000013
11959 +
11960 +#endif /* _UAPI_VS_DEVICE_H */
11961 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/device_cmd.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/device_cmd.h
11962 --- linux-4.4.161/include/uapi/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
11963 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/device_cmd.h   2018-10-20 04:57:21.000000000 +0000
11964 @@ -0,0 +1,16 @@
11965 +#ifndef _UAPI_VS_DEVICE_CMD_H
11966 +#define _UAPI_VS_DEVICE_CMD_H
11967 +
11968 +
11969 +/*  device vserver commands */
11970 +
11971 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11972 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11973 +
11974 +struct vcmd_set_mapping_v0 {
11975 +       const char __user *device;
11976 +       const char __user *target;
11977 +       uint32_t flags;
11978 +};
11979 +
11980 +#endif /* _UAPI_VS_DEVICE_CMD_H */
11981 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/dlimit_cmd.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/dlimit_cmd.h
11982 --- linux-4.4.161/include/uapi/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
11983 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/dlimit_cmd.h   2018-10-20 04:57:21.000000000 +0000
11984 @@ -0,0 +1,67 @@
11985 +#ifndef _UAPI_VS_DLIMIT_CMD_H
11986 +#define _UAPI_VS_DLIMIT_CMD_H
11987 +
11988 +
11989 +/*  dlimit vserver commands */
11990 +
11991 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11992 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11993 +
11994 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11995 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11996 +
11997 +struct vcmd_ctx_dlimit_base_v0 {
11998 +       const char __user *name;
11999 +       uint32_t flags;
12000 +};
12001 +
12002 +struct vcmd_ctx_dlimit_v0 {
12003 +       const char __user *name;
12004 +       uint32_t space_used;                    /* used space in kbytes */
12005 +       uint32_t space_total;                   /* maximum space in kbytes */
12006 +       uint32_t inodes_used;                   /* used inodes */
12007 +       uint32_t inodes_total;                  /* maximum inodes */
12008 +       uint32_t reserved;                      /* reserved for root in % */
12009 +       uint32_t flags;
12010 +};
12011 +
12012 +#define CDLIM_UNSET            ((uint32_t)0UL)
12013 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12014 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12015 +
12016 +#define DLIME_UNIT     0
12017 +#define DLIME_KILO     1
12018 +#define DLIME_MEGA     2
12019 +#define DLIME_GIGA     3
12020 +
12021 +#define DLIMF_SHIFT    0x10
12022 +
12023 +#define DLIMS_USED     0
12024 +#define DLIMS_TOTAL    2
12025 +
12026 +static inline
12027 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12028 +{
12029 +       int exp = (flags & DLIMF_SHIFT) ?
12030 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12031 +       return ((uint64_t)val) << (10 * exp);
12032 +}
12033 +
12034 +static inline
12035 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12036 +{
12037 +       int exp = 0;
12038 +
12039 +       if (*flags & DLIMF_SHIFT) {
12040 +               while (val > (1LL << 32) && (exp < 3)) {
12041 +                       val >>= 10;
12042 +                       exp++;
12043 +               }
12044 +               *flags &= ~(DLIME_GIGA << shift);
12045 +               *flags |= exp << shift;
12046 +       } else
12047 +               val >>= 10;
12048 +       return val;
12049 +}
12050 +
12051 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
12052 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/inode.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/inode.h
12053 --- linux-4.4.161/include/uapi/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
12054 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/inode.h        2018-10-20 04:57:21.000000000 +0000
12055 @@ -0,0 +1,23 @@
12056 +#ifndef _UAPI_VS_INODE_H
12057 +#define _UAPI_VS_INODE_H
12058 +
12059 +
12060 +#define IATTR_TAG      0x01000000
12061 +
12062 +#define IATTR_ADMIN    0x00000001
12063 +#define IATTR_WATCH    0x00000002
12064 +#define IATTR_HIDE     0x00000004
12065 +#define IATTR_FLAGS    0x00000007
12066 +
12067 +#define IATTR_BARRIER  0x00010000
12068 +#define IATTR_IXUNLINK 0x00020000
12069 +#define IATTR_IMMUTABLE 0x00040000
12070 +#define IATTR_COW      0x00080000
12071 +
12072 +
12073 +/* inode ioctls */
12074 +
12075 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12076 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12077 +
12078 +#endif /* _UAPI_VS_INODE_H */
12079 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/inode_cmd.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/inode_cmd.h
12080 --- linux-4.4.161/include/uapi/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
12081 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/inode_cmd.h    2018-10-20 04:57:21.000000000 +0000
12082 @@ -0,0 +1,26 @@
12083 +#ifndef _UAPI_VS_INODE_CMD_H
12084 +#define _UAPI_VS_INODE_CMD_H
12085 +
12086 +
12087 +/*  inode vserver commands */
12088 +
12089 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12090 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12091 +
12092 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12093 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12094 +
12095 +struct vcmd_ctx_iattr_v1 {
12096 +       const char __user *name;
12097 +       uint32_t tag;
12098 +       uint32_t flags;
12099 +       uint32_t mask;
12100 +};
12101 +
12102 +struct vcmd_ctx_fiattr_v0 {
12103 +       uint32_t tag;
12104 +       uint32_t flags;
12105 +       uint32_t mask;
12106 +};
12107 +
12108 +#endif /* _UAPI_VS_INODE_CMD_H */
12109 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/limit.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/limit.h
12110 --- linux-4.4.161/include/uapi/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
12111 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/limit.h        2018-10-20 04:57:21.000000000 +0000
12112 @@ -0,0 +1,14 @@
12113 +#ifndef _UAPI_VS_LIMIT_H
12114 +#define _UAPI_VS_LIMIT_H
12115 +
12116 +
12117 +#define VLIMIT_NSOCK   16
12118 +#define VLIMIT_OPENFD  17
12119 +#define VLIMIT_ANON    18
12120 +#define VLIMIT_SHMEM   19
12121 +#define VLIMIT_SEMARY  20
12122 +#define VLIMIT_NSEMS   21
12123 +#define VLIMIT_DENTRY  22
12124 +#define VLIMIT_MAPPED  23
12125 +
12126 +#endif /* _UAPI_VS_LIMIT_H */
12127 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/limit_cmd.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/limit_cmd.h
12128 --- linux-4.4.161/include/uapi/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
12129 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/limit_cmd.h    2018-10-20 04:57:21.000000000 +0000
12130 @@ -0,0 +1,40 @@
12131 +#ifndef _UAPI_VS_LIMIT_CMD_H
12132 +#define _UAPI_VS_LIMIT_CMD_H
12133 +
12134 +
12135 +/*  rlimit vserver commands */
12136 +
12137 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12138 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12139 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12140 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12141 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12142 +
12143 +struct vcmd_ctx_rlimit_v0 {
12144 +       uint32_t id;
12145 +       uint64_t minimum;
12146 +       uint64_t softlimit;
12147 +       uint64_t maximum;
12148 +};
12149 +
12150 +struct vcmd_ctx_rlimit_mask_v0 {
12151 +       uint32_t minimum;
12152 +       uint32_t softlimit;
12153 +       uint32_t maximum;
12154 +};
12155 +
12156 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12157 +
12158 +struct vcmd_rlimit_stat_v0 {
12159 +       uint32_t id;
12160 +       uint32_t hits;
12161 +       uint64_t value;
12162 +       uint64_t minimum;
12163 +       uint64_t maximum;
12164 +};
12165 +
12166 +#define CRLIM_UNSET            (0ULL)
12167 +#define CRLIM_INFINITY         (~0ULL)
12168 +#define CRLIM_KEEP             (~1ULL)
12169 +
12170 +#endif /* _UAPI_VS_LIMIT_CMD_H */
12171 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/monitor.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/monitor.h
12172 --- linux-4.4.161/include/uapi/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
12173 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/monitor.h      2018-10-20 04:57:21.000000000 +0000
12174 @@ -0,0 +1,96 @@
12175 +#ifndef _UAPI_VS_MONITOR_H
12176 +#define _UAPI_VS_MONITOR_H
12177 +
12178 +#include <linux/types.h>
12179 +
12180 +
12181 +enum {
12182 +       VXM_UNUSED = 0,
12183 +
12184 +       VXM_SYNC = 0x10,
12185 +
12186 +       VXM_UPDATE = 0x20,
12187 +       VXM_UPDATE_1,
12188 +       VXM_UPDATE_2,
12189 +
12190 +       VXM_RQINFO_1 = 0x24,
12191 +       VXM_RQINFO_2,
12192 +
12193 +       VXM_ACTIVATE = 0x40,
12194 +       VXM_DEACTIVATE,
12195 +       VXM_IDLE,
12196 +
12197 +       VXM_HOLD = 0x44,
12198 +       VXM_UNHOLD,
12199 +
12200 +       VXM_MIGRATE = 0x48,
12201 +       VXM_RESCHED,
12202 +
12203 +       /* all other bits are flags */
12204 +       VXM_SCHED = 0x80,
12205 +};
12206 +
12207 +struct _vxm_update_1 {
12208 +       uint32_t tokens_max;
12209 +       uint32_t fill_rate;
12210 +       uint32_t interval;
12211 +};
12212 +
12213 +struct _vxm_update_2 {
12214 +       uint32_t tokens_min;
12215 +       uint32_t fill_rate;
12216 +       uint32_t interval;
12217 +};
12218 +
12219 +struct _vxm_rqinfo_1 {
12220 +       uint16_t running;
12221 +       uint16_t onhold;
12222 +       uint16_t iowait;
12223 +       uint16_t uintr;
12224 +       uint32_t idle_tokens;
12225 +};
12226 +
12227 +struct _vxm_rqinfo_2 {
12228 +       uint32_t norm_time;
12229 +       uint32_t idle_time;
12230 +       uint32_t idle_skip;
12231 +};
12232 +
12233 +struct _vxm_sched {
12234 +       uint32_t tokens;
12235 +       uint32_t norm_time;
12236 +       uint32_t idle_time;
12237 +};
12238 +
12239 +struct _vxm_task {
12240 +       uint16_t pid;
12241 +       uint16_t state;
12242 +};
12243 +
12244 +struct _vxm_event {
12245 +       uint32_t jif;
12246 +       union {
12247 +               uint32_t seq;
12248 +               uint32_t sec;
12249 +       };
12250 +       union {
12251 +               uint32_t tokens;
12252 +               uint32_t nsec;
12253 +               struct _vxm_task tsk;
12254 +       };
12255 +};
12256 +
12257 +struct _vx_mon_entry {
12258 +       uint16_t type;
12259 +       uint16_t xid;
12260 +       union {
12261 +               struct _vxm_event ev;
12262 +               struct _vxm_sched sd;
12263 +               struct _vxm_update_1 u1;
12264 +               struct _vxm_update_2 u2;
12265 +               struct _vxm_rqinfo_1 q1;
12266 +               struct _vxm_rqinfo_2 q2;
12267 +       };
12268 +};
12269 +
12270 +#endif /* _UAPI_VS_MONITOR_H */
12271 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/network.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/network.h
12272 --- linux-4.4.161/include/uapi/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
12273 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/network.h      2018-10-20 04:57:21.000000000 +0000
12274 @@ -0,0 +1,76 @@
12275 +#ifndef _UAPI_VS_NETWORK_H
12276 +#define _UAPI_VS_NETWORK_H
12277 +
12278 +#include <linux/types.h>
12279 +
12280 +
12281 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12282 +
12283 +
12284 +/* network flags */
12285 +
12286 +#define NXF_INFO_PRIVATE       0x00000008
12287 +
12288 +#define NXF_SINGLE_IP          0x00000100
12289 +#define NXF_LBACK_REMAP                0x00000200
12290 +#define NXF_LBACK_ALLOW                0x00000400
12291 +
12292 +#define NXF_HIDE_NETIF         0x02000000
12293 +#define NXF_HIDE_LBACK         0x04000000
12294 +
12295 +#define NXF_STATE_SETUP                (1ULL << 32)
12296 +#define NXF_STATE_ADMIN                (1ULL << 34)
12297 +
12298 +#define NXF_SC_HELPER          (1ULL << 36)
12299 +#define NXF_PERSISTENT         (1ULL << 38)
12300 +
12301 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12302 +
12303 +
12304 +#define        NXF_INIT_SET            (__nxf_init_set())
12305 +
12306 +static inline uint64_t __nxf_init_set(void) {
12307 +       return    NXF_STATE_ADMIN
12308 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12309 +               | NXF_LBACK_REMAP
12310 +               | NXF_HIDE_LBACK
12311 +#endif
12312 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12313 +               | NXF_SINGLE_IP
12314 +#endif
12315 +               | NXF_HIDE_NETIF;
12316 +}
12317 +
12318 +
12319 +/* network caps */
12320 +
12321 +#define NXC_TUN_CREATE         0x00000001
12322 +
12323 +#define NXC_RAW_ICMP           0x00000100
12324 +
12325 +#define NXC_MULTICAST          0x00001000
12326 +
12327 +
12328 +/* address types */
12329 +
12330 +#define NXA_TYPE_IPV4          0x0001
12331 +#define NXA_TYPE_IPV6          0x0002
12332 +
12333 +#define NXA_TYPE_NONE          0x0000
12334 +#define NXA_TYPE_ANY           0x00FF
12335 +
12336 +#define NXA_TYPE_ADDR          0x0010
12337 +#define NXA_TYPE_MASK          0x0020
12338 +#define NXA_TYPE_RANGE         0x0040
12339 +
12340 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12341 +
12342 +#define NXA_MOD_BCAST          0x0100
12343 +#define NXA_MOD_LBACK          0x0200
12344 +
12345 +#define NXA_LOOPBACK           0x1000
12346 +
12347 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12348 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12349 +
12350 +#endif /* _UAPI_VS_NETWORK_H */
12351 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/network_cmd.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/network_cmd.h
12352 --- linux-4.4.161/include/uapi/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
12353 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/network_cmd.h  2018-10-20 04:57:21.000000000 +0000
12354 @@ -0,0 +1,123 @@
12355 +#ifndef _UAPI_VS_NETWORK_CMD_H
12356 +#define _UAPI_VS_NETWORK_CMD_H
12357 +
12358 +
12359 +/* vinfo commands */
12360 +
12361 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12362 +
12363 +
12364 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12365 +
12366 +struct vcmd_nx_info_v0 {
12367 +       uint32_t nid;
12368 +       /* more to come */
12369 +};
12370 +
12371 +
12372 +#include <linux/in.h>
12373 +#include <linux/in6.h>
12374 +
12375 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12376 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12377 +
12378 +struct  vcmd_net_create {
12379 +       uint64_t flagword;
12380 +};
12381 +
12382 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12383 +
12384 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12385 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12386 +
12387 +struct vcmd_net_addr_v0 {
12388 +       uint16_t type;
12389 +       uint16_t count;
12390 +       struct in_addr ip[4];
12391 +       struct in_addr mask[4];
12392 +};
12393 +
12394 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
12395 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
12396 +
12397 +struct vcmd_net_addr_ipv4_v1 {
12398 +       uint16_t type;
12399 +       uint16_t flags;
12400 +       struct in_addr ip;
12401 +       struct in_addr mask;
12402 +};
12403 +
12404 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
12405 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
12406 +
12407 +struct vcmd_net_addr_ipv4_v2 {
12408 +       uint16_t type;
12409 +       uint16_t flags;
12410 +       struct in_addr ip;
12411 +       struct in_addr ip2;
12412 +       struct in_addr mask;
12413 +};
12414 +
12415 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12416 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12417 +
12418 +struct vcmd_net_addr_ipv6_v1 {
12419 +       uint16_t type;
12420 +       uint16_t flags;
12421 +       uint32_t prefix;
12422 +       struct in6_addr ip;
12423 +       struct in6_addr mask;
12424 +};
12425 +
12426 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12427 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12428 +
12429 +struct vcmd_match_ipv4_v0 {
12430 +       uint16_t type;
12431 +       uint16_t flags;
12432 +       uint16_t parent;
12433 +       uint16_t prefix;
12434 +       struct in_addr ip;
12435 +       struct in_addr ip2;
12436 +       struct in_addr mask;
12437 +};
12438 +
12439 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12440 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12441 +
12442 +struct vcmd_match_ipv6_v0 {
12443 +       uint16_t type;
12444 +       uint16_t flags;
12445 +       uint16_t parent;
12446 +       uint16_t prefix;
12447 +       struct in6_addr ip;
12448 +       struct in6_addr ip2;
12449 +       struct in6_addr mask;
12450 +};
12451 +
12452 +
12453 +
12454 +
12455 +/* flag commands */
12456 +
12457 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12458 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12459 +
12460 +struct vcmd_net_flags_v0 {
12461 +       uint64_t flagword;
12462 +       uint64_t mask;
12463 +};
12464 +
12465 +
12466 +
12467 +/* network caps commands */
12468 +
12469 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12470 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12471 +
12472 +struct vcmd_net_caps_v0 {
12473 +       uint64_t ncaps;
12474 +       uint64_t cmask;
12475 +};
12476 +
12477 +#endif /* _UAPI_VS_NETWORK_CMD_H */
12478 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/sched_cmd.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/sched_cmd.h
12479 --- linux-4.4.161/include/uapi/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
12480 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/sched_cmd.h    2018-10-20 04:57:21.000000000 +0000
12481 @@ -0,0 +1,13 @@
12482 +#ifndef _UAPI_VS_SCHED_CMD_H
12483 +#define _UAPI_VS_SCHED_CMD_H
12484 +
12485 +
12486 +struct vcmd_prio_bias {
12487 +       int32_t cpu_id;
12488 +       int32_t prio_bias;
12489 +};
12490 +
12491 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
12492 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
12493 +
12494 +#endif /* _UAPI_VS_SCHED_CMD_H */
12495 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/signal_cmd.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/signal_cmd.h
12496 --- linux-4.4.161/include/uapi/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
12497 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/signal_cmd.h   2018-10-20 04:57:21.000000000 +0000
12498 @@ -0,0 +1,31 @@
12499 +#ifndef _UAPI_VS_SIGNAL_CMD_H
12500 +#define _UAPI_VS_SIGNAL_CMD_H
12501 +
12502 +
12503 +/*  signalling vserver commands */
12504 +
12505 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12506 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12507 +
12508 +struct vcmd_ctx_kill_v0 {
12509 +       int32_t pid;
12510 +       int32_t sig;
12511 +};
12512 +
12513 +struct vcmd_wait_exit_v0 {
12514 +       int32_t reboot_cmd;
12515 +       int32_t exit_code;
12516 +};
12517 +
12518 +
12519 +/*  process alteration commands */
12520 +
12521 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12522 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12523 +
12524 +struct vcmd_pflags_v0 {
12525 +       uint32_t flagword;
12526 +       uint32_t mask;
12527 +};
12528 +
12529 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
12530 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/space_cmd.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/space_cmd.h
12531 --- linux-4.4.161/include/uapi/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
12532 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/space_cmd.h    2018-10-20 04:57:21.000000000 +0000
12533 @@ -0,0 +1,28 @@
12534 +#ifndef _UAPI_VS_SPACE_CMD_H
12535 +#define _UAPI_VS_SPACE_CMD_H
12536 +
12537 +
12538 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12539 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12540 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12541 +
12542 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12543 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12544 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12545 +
12546 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12547 +
12548 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12549 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12550 +
12551 +
12552 +struct vcmd_space_mask_v1 {
12553 +       uint64_t mask;
12554 +};
12555 +
12556 +struct vcmd_space_mask_v2 {
12557 +       uint64_t mask;
12558 +       uint32_t index;
12559 +};
12560 +
12561 +#endif /* _UAPI_VS_SPACE_CMD_H */
12562 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/switch.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/switch.h
12563 --- linux-4.4.161/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12564 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/switch.h       2018-10-20 04:57:21.000000000 +0000
12565 @@ -0,0 +1,90 @@
12566 +#ifndef _UAPI_VS_SWITCH_H
12567 +#define _UAPI_VS_SWITCH_H
12568 +
12569 +#include <linux/types.h>
12570 +
12571 +
12572 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12573 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12574 +#define VC_VERSION(c)          ((c) & 0xFFF)
12575 +
12576 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12577 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12578 +
12579 +/*
12580 +
12581 +  Syscall Matrix V2.8
12582 +
12583 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12584 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12585 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12586 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12587 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
12588 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
12589 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12590 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
12591 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
12592 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12593 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
12594 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
12595 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12596 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
12597 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
12598 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12599 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
12600 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
12601 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12602 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
12603 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
12604 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12605 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
12606 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
12607 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12608 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
12609 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
12610 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12611 +
12612 +*/
12613 +
12614 +#define VC_CAT_VERSION         0
12615 +
12616 +#define VC_CAT_VSETUP          1
12617 +#define VC_CAT_VHOST           2
12618 +
12619 +#define VC_CAT_DEVICE          6
12620 +
12621 +#define VC_CAT_VPROC           9
12622 +#define VC_CAT_PROCALT         10
12623 +#define VC_CAT_PROCMIG         11
12624 +#define VC_CAT_PROCTRL         12
12625 +
12626 +#define VC_CAT_SCHED           14
12627 +#define VC_CAT_MEMCTRL         20
12628 +
12629 +#define VC_CAT_VNET            25
12630 +#define VC_CAT_NETALT          26
12631 +#define VC_CAT_NETMIG          27
12632 +#define VC_CAT_NETCTRL         28
12633 +
12634 +#define VC_CAT_TAGMIG          35
12635 +#define VC_CAT_DLIMIT          36
12636 +#define VC_CAT_INODE           38
12637 +
12638 +#define VC_CAT_VSTAT           40
12639 +#define VC_CAT_VINFO           46
12640 +#define VC_CAT_EVENT           48
12641 +
12642 +#define VC_CAT_FLAGS           52
12643 +#define VC_CAT_VSPACE          54
12644 +#define VC_CAT_DEBUG           56
12645 +#define VC_CAT_RLIMIT          60
12646 +
12647 +#define VC_CAT_SYSTEST         61
12648 +#define VC_CAT_COMPAT          63
12649 +
12650 +/*  query version */
12651 +
12652 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
12653 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
12654 +
12655 +#endif /* _UAPI_VS_SWITCH_H */
12656 diff -NurpP --minimal linux-4.4.161/include/uapi/vserver/tag_cmd.h linux-4.4.161-vs2.3.9.8/include/uapi/vserver/tag_cmd.h
12657 --- linux-4.4.161/include/uapi/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
12658 +++ linux-4.4.161-vs2.3.9.8/include/uapi/vserver/tag_cmd.h      2018-10-20 04:57:21.000000000 +0000
12659 @@ -0,0 +1,14 @@
12660 +#ifndef _UAPI_VS_TAG_CMD_H
12661 +#define _UAPI_VS_TAG_CMD_H
12662 +
12663 +
12664 +/* vinfo commands */
12665 +
12666 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
12667 +
12668 +
12669 +/* context commands */
12670 +
12671 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
12672 +
12673 +#endif /* _UAPI_VS_TAG_CMD_H */
12674 diff -NurpP --minimal linux-4.4.161/init/Kconfig linux-4.4.161-vs2.3.9.8/init/Kconfig
12675 --- linux-4.4.161/init/Kconfig  2018-10-20 02:34:31.000000000 +0000
12676 +++ linux-4.4.161-vs2.3.9.8/init/Kconfig        2018-10-20 04:57:21.000000000 +0000
12677 @@ -927,6 +927,7 @@ config NUMA_BALANCING_DEFAULT_ENABLED
12678  menuconfig CGROUPS
12679         bool "Control Group support"
12680         select KERNFS
12681 +       default y
12682         help
12683           This option adds support for grouping sets of processes together, for
12684           use with process control subsystems such as Cpusets, CFS, memory
12685 diff -NurpP --minimal linux-4.4.161/init/main.c linux-4.4.161-vs2.3.9.8/init/main.c
12686 --- linux-4.4.161/init/main.c   2018-10-20 02:34:31.000000000 +0000
12687 +++ linux-4.4.161-vs2.3.9.8/init/main.c 2018-10-20 04:57:21.000000000 +0000
12688 @@ -82,6 +82,7 @@
12689  #include <linux/proc_ns.h>
12690  #include <linux/io.h>
12691  #include <linux/kaiser.h>
12692 +#include <linux/vserver/percpu.h>
12693  
12694  #include <asm/io.h>
12695  #include <asm/bugs.h>
12696 diff -NurpP --minimal linux-4.4.161/ipc/mqueue.c linux-4.4.161-vs2.3.9.8/ipc/mqueue.c
12697 --- linux-4.4.161/ipc/mqueue.c  2018-10-20 02:34:31.000000000 +0000
12698 +++ linux-4.4.161-vs2.3.9.8/ipc/mqueue.c        2018-10-20 04:57:21.000000000 +0000
12699 @@ -35,6 +35,8 @@
12700  #include <linux/ipc_namespace.h>
12701  #include <linux/user_namespace.h>
12702  #include <linux/slab.h>
12703 +#include <linux/vs_context.h>
12704 +#include <linux/vs_limit.h>
12705  
12706  #include <net/sock.h>
12707  #include "util.h"
12708 @@ -75,6 +77,7 @@ struct mqueue_inode_info {
12709         struct pid *notify_owner;
12710         struct user_namespace *notify_user_ns;
12711         struct user_struct *user;       /* user who created, for accounting */
12712 +       struct vx_info *vxi;
12713         struct sock *notify_sock;
12714         struct sk_buff *notify_cookie;
12715  
12716 @@ -230,6 +233,7 @@ static struct inode *mqueue_get_inode(st
12717         if (S_ISREG(mode)) {
12718                 struct mqueue_inode_info *info;
12719                 unsigned long mq_bytes, mq_treesize;
12720 +               struct vx_info *vxi = current_vx_info();
12721  
12722                 inode->i_fop = &mqueue_file_operations;
12723                 inode->i_size = FILENT_SIZE;
12724 @@ -243,6 +247,7 @@ static struct inode *mqueue_get_inode(st
12725                 info->notify_user_ns = NULL;
12726                 info->qsize = 0;
12727                 info->user = NULL;      /* set when all is ok */
12728 +               info->vxi = NULL;
12729                 info->msg_tree = RB_ROOT;
12730                 info->node_cache = NULL;
12731                 memset(&info->attr, 0, sizeof(info->attr));
12732 @@ -276,17 +281,20 @@ static struct inode *mqueue_get_inode(st
12733  
12734                 spin_lock(&mq_lock);
12735                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
12736 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
12737 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
12738 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
12739                         spin_unlock(&mq_lock);
12740                         /* mqueue_evict_inode() releases info->messages */
12741                         ret = -EMFILE;
12742                         goto out_inode;
12743                 }
12744                 u->mq_bytes += mq_bytes;
12745 +               vx_ipcmsg_add(vxi, u, mq_bytes);
12746                 spin_unlock(&mq_lock);
12747  
12748                 /* all is ok */
12749                 info->user = get_uid(u);
12750 +               info->vxi = get_vx_info(vxi);
12751         } else if (S_ISDIR(mode)) {
12752                 inc_nlink(inode);
12753                 /* Some things misbehave if size == 0 on a directory */
12754 @@ -398,8 +406,11 @@ static void mqueue_evict_inode(struct in
12755  
12756         user = info->user;
12757         if (user) {
12758 +               struct vx_info *vxi = info->vxi;
12759 +
12760                 spin_lock(&mq_lock);
12761                 user->mq_bytes -= mq_bytes;
12762 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
12763                 /*
12764                  * get_ns_from_inode() ensures that the
12765                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
12766 @@ -409,6 +420,7 @@ static void mqueue_evict_inode(struct in
12767                 if (ipc_ns)
12768                         ipc_ns->mq_queues_count--;
12769                 spin_unlock(&mq_lock);
12770 +               put_vx_info(vxi);
12771                 free_uid(user);
12772         }
12773         if (ipc_ns)
12774 diff -NurpP --minimal linux-4.4.161/ipc/msg.c linux-4.4.161-vs2.3.9.8/ipc/msg.c
12775 --- linux-4.4.161/ipc/msg.c     2018-10-20 02:34:31.000000000 +0000
12776 +++ linux-4.4.161-vs2.3.9.8/ipc/msg.c   2018-10-20 04:57:21.000000000 +0000
12777 @@ -37,6 +37,7 @@
12778  #include <linux/rwsem.h>
12779  #include <linux/nsproxy.h>
12780  #include <linux/ipc_namespace.h>
12781 +#include <linux/vs_base.h>
12782  
12783  #include <asm/current.h>
12784  #include <linux/uaccess.h>
12785 @@ -129,6 +130,7 @@ static int newque(struct ipc_namespace *
12786  
12787         msq->q_perm.mode = msgflg & S_IRWXUGO;
12788         msq->q_perm.key = key;
12789 +       msq->q_perm.xid = vx_current_xid();
12790  
12791         msq->q_perm.security = NULL;
12792         retval = security_msg_queue_alloc(msq);
12793 diff -NurpP --minimal linux-4.4.161/ipc/sem.c linux-4.4.161-vs2.3.9.8/ipc/sem.c
12794 --- linux-4.4.161/ipc/sem.c     2018-10-20 02:34:31.000000000 +0000
12795 +++ linux-4.4.161-vs2.3.9.8/ipc/sem.c   2018-10-20 04:57:21.000000000 +0000
12796 @@ -85,6 +85,8 @@
12797  #include <linux/rwsem.h>
12798  #include <linux/nsproxy.h>
12799  #include <linux/ipc_namespace.h>
12800 +#include <linux/vs_base.h>
12801 +#include <linux/vs_limit.h>
12802  
12803  #include <linux/uaccess.h>
12804  #include "util.h"
12805 @@ -533,6 +535,7 @@ static int newary(struct ipc_namespace *
12806  
12807         sma->sem_perm.mode = (semflg & S_IRWXUGO);
12808         sma->sem_perm.key = key;
12809 +       sma->sem_perm.xid = vx_current_xid();
12810  
12811         sma->sem_perm.security = NULL;
12812         retval = security_sem_alloc(sma);
12813 @@ -563,6 +566,9 @@ static int newary(struct ipc_namespace *
12814                 return id;
12815         }
12816         ns->used_sems += nsems;
12817 +       /* FIXME: obsoleted? */
12818 +       vx_semary_inc(sma);
12819 +       vx_nsems_add(sma, nsems);
12820  
12821         sem_unlock(sma, -1);
12822         rcu_read_unlock();
12823 @@ -1151,6 +1157,9 @@ static void freeary(struct ipc_namespace
12824  
12825         wake_up_sem_queue_do(&tasks);
12826         ns->used_sems -= sma->sem_nsems;
12827 +       /* FIXME: obsoleted? */
12828 +       vx_nsems_sub(sma, sma->sem_nsems);
12829 +       vx_semary_dec(sma);
12830         ipc_rcu_putref(sma, sem_rcu_free);
12831  }
12832  
12833 diff -NurpP --minimal linux-4.4.161/ipc/shm.c linux-4.4.161-vs2.3.9.8/ipc/shm.c
12834 --- linux-4.4.161/ipc/shm.c     2018-10-20 02:34:31.000000000 +0000
12835 +++ linux-4.4.161-vs2.3.9.8/ipc/shm.c   2018-10-20 04:57:21.000000000 +0000
12836 @@ -42,6 +42,8 @@
12837  #include <linux/nsproxy.h>
12838  #include <linux/mount.h>
12839  #include <linux/ipc_namespace.h>
12840 +#include <linux/vs_context.h>
12841 +#include <linux/vs_limit.h>
12842  
12843  #include <linux/uaccess.h>
12844  
12845 @@ -234,10 +236,14 @@ static void shm_open(struct vm_area_stru
12846  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
12847  {
12848         struct file *shm_file;
12849 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
12850 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
12851  
12852         shm_file = shp->shm_file;
12853         shp->shm_file = NULL;
12854 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
12855 +       vx_ipcshm_sub(vxi, shp, numpages);
12856 +       ns->shm_tot -= numpages;
12857 +
12858         shm_rmid(ns, shp);
12859         shm_unlock(shp);
12860         if (!is_file_hugepages(shm_file))
12861 @@ -246,6 +252,7 @@ static void shm_destroy(struct ipc_names
12862                 user_shm_unlock(i_size_read(file_inode(shm_file)),
12863                                 shp->mlock_user);
12864         fput(shm_file);
12865 +       put_vx_info(vxi);
12866         ipc_rcu_putref(shp, shm_rcu_free);
12867  }
12868  
12869 @@ -545,11 +552,15 @@ static int newseg(struct ipc_namespace *
12870                         ns->shm_tot + numpages > ns->shm_ctlall)
12871                 return -ENOSPC;
12872  
12873 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
12874 +               return -ENOSPC;
12875 +
12876         shp = ipc_rcu_alloc(sizeof(*shp));
12877         if (!shp)
12878                 return -ENOMEM;
12879  
12880         shp->shm_perm.key = key;
12881 +       shp->shm_perm.xid = vx_current_xid();
12882         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
12883         shp->mlock_user = NULL;
12884  
12885 @@ -620,6 +631,7 @@ static int newseg(struct ipc_namespace *
12886  
12887         ipc_unlock_object(&shp->shm_perm);
12888         rcu_read_unlock();
12889 +       vx_ipcshm_add(current_vx_info(), key, numpages);
12890         return error;
12891  
12892  no_id:
12893 diff -NurpP --minimal linux-4.4.161/kernel/Makefile linux-4.4.161-vs2.3.9.8/kernel/Makefile
12894 --- linux-4.4.161/kernel/Makefile       2016-01-10 23:01:32.000000000 +0000
12895 +++ linux-4.4.161-vs2.3.9.8/kernel/Makefile     2018-10-20 04:57:21.000000000 +0000
12896 @@ -29,6 +29,7 @@ obj-y += printk/
12897  obj-y += irq/
12898  obj-y += rcu/
12899  obj-y += livepatch/
12900 +obj-y += vserver/
12901  
12902  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
12903  obj-$(CONFIG_FREEZER) += freezer.o
12904 diff -NurpP --minimal linux-4.4.161/kernel/auditsc.c linux-4.4.161-vs2.3.9.8/kernel/auditsc.c
12905 --- linux-4.4.161/kernel/auditsc.c      2018-10-20 02:34:31.000000000 +0000
12906 +++ linux-4.4.161-vs2.3.9.8/kernel/auditsc.c    2018-10-20 05:50:20.000000000 +0000
12907 @@ -1964,7 +1964,7 @@ static int audit_set_loginuid_perm(kuid_
12908         if (is_audit_feature_set(AUDIT_FEATURE_LOGINUID_IMMUTABLE))
12909                 return -EPERM;
12910         /* it is set, you need permission */
12911 -       if (!capable(CAP_AUDIT_CONTROL))
12912 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
12913                 return -EPERM;
12914         /* reject if this is not an unset and we don't allow that */
12915         if (is_audit_feature_set(AUDIT_FEATURE_ONLY_UNSET_LOGINUID) && uid_valid(loginuid))
12916 diff -NurpP --minimal linux-4.4.161/kernel/capability.c linux-4.4.161-vs2.3.9.8/kernel/capability.c
12917 --- linux-4.4.161/kernel/capability.c   2018-10-20 02:34:31.000000000 +0000
12918 +++ linux-4.4.161-vs2.3.9.8/kernel/capability.c 2018-10-20 04:57:21.000000000 +0000
12919 @@ -17,6 +17,7 @@
12920  #include <linux/syscalls.h>
12921  #include <linux/pid_namespace.h>
12922  #include <linux/user_namespace.h>
12923 +#include <linux/vs_context.h>
12924  #include <asm/uaccess.h>
12925  
12926  /*
12927 @@ -107,6 +108,7 @@ static int cap_validate_magic(cap_user_h
12928         return 0;
12929  }
12930  
12931 +
12932  /*
12933   * The only thing that can change the capabilities of the current
12934   * process is the current process. As such, we can't be in this code
12935 @@ -344,6 +346,8 @@ bool has_ns_capability_noaudit(struct ta
12936         return (ret == 0);
12937  }
12938  
12939 +#include <linux/vserver/base.h>
12940 +
12941  /**
12942   * has_capability_noaudit - Does a task have a capability (unaudited) in the
12943   * initial user ns
12944 diff -NurpP --minimal linux-4.4.161/kernel/compat.c linux-4.4.161-vs2.3.9.8/kernel/compat.c
12945 --- linux-4.4.161/kernel/compat.c       2016-01-10 23:01:32.000000000 +0000
12946 +++ linux-4.4.161-vs2.3.9.8/kernel/compat.c     2018-10-20 04:57:21.000000000 +0000
12947 @@ -27,6 +27,7 @@
12948  #include <linux/times.h>
12949  #include <linux/ptrace.h>
12950  #include <linux/gfp.h>
12951 +#include <linux/vs_time.h>
12952  
12953  #include <asm/uaccess.h>
12954  
12955 @@ -1059,7 +1060,7 @@ COMPAT_SYSCALL_DEFINE1(stime, compat_tim
12956         if (err)
12957                 return err;
12958  
12959 -       do_settimeofday(&tv);
12960 +       vx_settimeofday(&tv);
12961         return 0;
12962  }
12963  
12964 diff -NurpP --minimal linux-4.4.161/kernel/cred.c linux-4.4.161-vs2.3.9.8/kernel/cred.c
12965 --- linux-4.4.161/kernel/cred.c 2018-10-20 02:34:31.000000000 +0000
12966 +++ linux-4.4.161-vs2.3.9.8/kernel/cred.c       2018-10-20 04:57:21.000000000 +0000
12967 @@ -64,31 +64,6 @@ struct cred init_cred = {
12968         .group_info             = &init_groups,
12969  };
12970  
12971 -static inline void set_cred_subscribers(struct cred *cred, int n)
12972 -{
12973 -#ifdef CONFIG_DEBUG_CREDENTIALS
12974 -       atomic_set(&cred->subscribers, n);
12975 -#endif
12976 -}
12977 -
12978 -static inline int read_cred_subscribers(const struct cred *cred)
12979 -{
12980 -#ifdef CONFIG_DEBUG_CREDENTIALS
12981 -       return atomic_read(&cred->subscribers);
12982 -#else
12983 -       return 0;
12984 -#endif
12985 -}
12986 -
12987 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
12988 -{
12989 -#ifdef CONFIG_DEBUG_CREDENTIALS
12990 -       struct cred *cred = (struct cred *) _cred;
12991 -
12992 -       atomic_add(n, &cred->subscribers);
12993 -#endif
12994 -}
12995 -
12996  /*
12997   * The RCU callback to actually dispose of a set of credentials
12998   */
12999 @@ -240,21 +215,16 @@ error:
13000   *
13001   * Call commit_creds() or abort_creds() to clean up.
13002   */
13003 -struct cred *prepare_creds(void)
13004 +struct cred *__prepare_creds(const struct cred *old)
13005  {
13006 -       struct task_struct *task = current;
13007 -       const struct cred *old;
13008         struct cred *new;
13009  
13010 -       validate_process_creds();
13011 -
13012         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13013         if (!new)
13014                 return NULL;
13015  
13016         kdebug("prepare_creds() alloc %p", new);
13017  
13018 -       old = task->cred;
13019         memcpy(new, old, sizeof(struct cred));
13020  
13021         atomic_set(&new->usage, 1);
13022 @@ -283,6 +253,13 @@ error:
13023         abort_creds(new);
13024         return NULL;
13025  }
13026 +
13027 +struct cred *prepare_creds(void)
13028 +{
13029 +       validate_process_creds();
13030 +
13031 +       return __prepare_creds(current->cred);
13032 +}
13033  EXPORT_SYMBOL(prepare_creds);
13034  
13035  /*
13036 diff -NurpP --minimal linux-4.4.161/kernel/exit.c linux-4.4.161-vs2.3.9.8/kernel/exit.c
13037 --- linux-4.4.161/kernel/exit.c 2018-10-20 02:34:31.000000000 +0000
13038 +++ linux-4.4.161-vs2.3.9.8/kernel/exit.c       2018-10-20 04:57:21.000000000 +0000
13039 @@ -48,6 +48,10 @@
13040  #include <linux/fs_struct.h>
13041  #include <linux/init_task.h>
13042  #include <linux/perf_event.h>
13043 +#include <linux/vs_limit.h>
13044 +#include <linux/vs_context.h>
13045 +#include <linux/vs_network.h>
13046 +#include <linux/vs_pid.h>
13047  #include <trace/events/sched.h>
13048  #include <linux/hw_breakpoint.h>
13049  #include <linux/oom.h>
13050 @@ -456,14 +460,24 @@ static struct task_struct *find_child_re
13051         struct pid_namespace *pid_ns = task_active_pid_ns(father);
13052         struct task_struct *reaper = pid_ns->child_reaper;
13053         struct task_struct *p, *n;
13054 +       struct vx_info *vxi = task_get_vx_info(father);
13055 +
13056 +       if (vxi) {
13057 +               BUG_ON(!vxi->vx_reaper);
13058 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
13059 +                   vxi->vx_reaper != father) {
13060 +                       reaper = vxi->vx_reaper;
13061 +                       goto out_put;
13062 +               }
13063 +       }
13064  
13065         if (likely(reaper != father))
13066 -               return reaper;
13067 +               goto out_put;
13068  
13069         reaper = find_alive_thread(father);
13070         if (reaper) {
13071                 pid_ns->child_reaper = reaper;
13072 -               return reaper;
13073 +               goto out_put;
13074         }
13075  
13076         write_unlock_irq(&tasklist_lock);
13077 @@ -474,7 +488,10 @@ static struct task_struct *find_child_re
13078         zap_pid_ns_processes(pid_ns);
13079         write_lock_irq(&tasklist_lock);
13080  
13081 -       return father;
13082 +       reaper = father;
13083 +out_put:
13084 +       put_vx_info(vxi);
13085 +       return reaper;
13086  }
13087  
13088  /*
13089 @@ -562,9 +579,13 @@ static void forget_original_parent(struc
13090                 return;
13091  
13092         reaper = find_new_reaper(father, reaper);
13093 -       list_for_each_entry(p, &father->children, sibling) {
13094 +       for (p = list_first_entry(&father->children, struct task_struct, sibling);
13095 +            &p->sibling != &father->children; ) {
13096 +               struct task_struct *next, *this_reaper = reaper;
13097 +               if (p == reaper)
13098 +                       this_reaper = task_active_pid_ns(reaper)->child_reaper;
13099                 for_each_thread(p, t) {
13100 -                       t->real_parent = reaper;
13101 +                       t->real_parent = this_reaper;
13102                         BUG_ON((!t->ptrace) != (t->parent == father));
13103                         if (likely(!t->ptrace))
13104                                 t->parent = t->real_parent;
13105 @@ -576,10 +597,13 @@ static void forget_original_parent(struc
13106                  * If this is a threaded reparent there is no need to
13107                  * notify anyone anything has happened.
13108                  */
13109 -               if (!same_thread_group(reaper, father))
13110 +               if (!same_thread_group(this_reaper, father))
13111                         reparent_leader(father, p, dead);
13112 +               next = list_next_entry(p, sibling);
13113 +               list_add(&p->sibling, &this_reaper->children);
13114 +               p = next;
13115         }
13116 -       list_splice_tail_init(&father->children, &reaper->children);
13117 +       INIT_LIST_HEAD(&father->children);
13118  }
13119  
13120  /*
13121 @@ -763,6 +787,9 @@ void do_exit(long code)
13122          */
13123         flush_ptrace_hw_breakpoint(tsk);
13124  
13125 +       /* needs to stay before exit_notify() */
13126 +       exit_vx_info_early(tsk, code);
13127 +
13128         TASKS_RCU(preempt_disable());
13129         TASKS_RCU(tasks_rcu_i = __srcu_read_lock(&tasks_rcu_exit_srcu));
13130         TASKS_RCU(preempt_enable());
13131 @@ -800,6 +827,10 @@ void do_exit(long code)
13132  
13133         validate_creds_for_do_exit(tsk);
13134  
13135 +       /* needs to stay after exit_notify() and before preempt_disable() */
13136 +       exit_vx_info(tsk, code);
13137 +       exit_nx_info(tsk);
13138 +
13139         check_stack_usage();
13140         preempt_disable();
13141         if (tsk->nr_dirtied)
13142 @@ -826,6 +857,7 @@ void do_exit(long code)
13143         tsk->state = TASK_DEAD;
13144         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
13145         schedule();
13146 +       printk("bad task: %p [%lx]\n", current, current->state);
13147         BUG();
13148         /* Avoid "noreturn function does return".  */
13149         for (;;)
13150 diff -NurpP --minimal linux-4.4.161/kernel/fork.c linux-4.4.161-vs2.3.9.8/kernel/fork.c
13151 --- linux-4.4.161/kernel/fork.c 2018-10-20 02:34:31.000000000 +0000
13152 +++ linux-4.4.161-vs2.3.9.8/kernel/fork.c       2018-10-20 05:50:20.000000000 +0000
13153 @@ -76,6 +76,9 @@
13154  #include <linux/aio.h>
13155  #include <linux/compiler.h>
13156  #include <linux/sysctl.h>
13157 +#include <linux/vs_context.h>
13158 +#include <linux/vs_network.h>
13159 +#include <linux/vs_limit.h>
13160  
13161  #include <asm/pgtable.h>
13162  #include <asm/pgalloc.h>
13163 @@ -227,6 +230,8 @@ void free_task(struct task_struct *tsk)
13164         arch_release_thread_info(tsk->stack);
13165         free_thread_info(tsk->stack);
13166         rt_mutex_debug_task_free(tsk);
13167 +       clr_vx_info(&tsk->vx_info);
13168 +       clr_nx_info(&tsk->nx_info);
13169         ftrace_graph_exit_task(tsk);
13170         put_seccomp_filter(tsk);
13171         arch_release_task_struct(tsk);
13172 @@ -1284,6 +1289,8 @@ static struct task_struct *copy_process(
13173  {
13174         int retval;
13175         struct task_struct *p;
13176 +       struct vx_info *vxi;
13177 +       struct nx_info *nxi;
13178         void *cgrp_ss_priv[CGROUP_CANFORK_COUNT] = {};
13179  
13180         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
13181 @@ -1357,7 +1364,12 @@ static struct task_struct *copy_process(
13182         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
13183         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
13184  #endif
13185 +       init_vx_info(&p->vx_info, current_vx_info());
13186 +       init_nx_info(&p->nx_info, current_nx_info());
13187 +
13188         retval = -EAGAIN;
13189 +       if (!vx_nproc_avail(1))
13190 +               goto bad_fork_free;
13191         if (atomic_read(&p->real_cred->user->processes) >=
13192                         task_rlimit(p, RLIMIT_NPROC)) {
13193                 if (p->real_cred->user != INIT_USER &&
13194 @@ -1649,6 +1661,18 @@ static struct task_struct *copy_process(
13195         total_forks++;
13196         spin_unlock(&current->sighand->siglock);
13197         syscall_tracepoint_update(p);
13198 +
13199 +       /* p is copy of current */
13200 +       vxi = p->vx_info;
13201 +       if (vxi) {
13202 +               claim_vx_info(vxi, p);
13203 +               atomic_inc(&vxi->cvirt.nr_threads);
13204 +               atomic_inc(&vxi->cvirt.total_forks);
13205 +               vx_nproc_inc(p);
13206 +       }
13207 +       nxi = p->nx_info;
13208 +       if (nxi)
13209 +               claim_nx_info(nxi, p);
13210         write_unlock_irq(&tasklist_lock);
13211  
13212         proc_fork_connector(p);
13213 diff -NurpP --minimal linux-4.4.161/kernel/kthread.c linux-4.4.161-vs2.3.9.8/kernel/kthread.c
13214 --- linux-4.4.161/kernel/kthread.c      2018-10-20 02:34:31.000000000 +0000
13215 +++ linux-4.4.161-vs2.3.9.8/kernel/kthread.c    2018-10-20 05:50:20.000000000 +0000
13216 @@ -19,6 +19,7 @@
13217  #include <linux/ptrace.h>
13218  #include <linux/uaccess.h>
13219  #include <linux/cgroup.h>
13220 +#include <linux/vs_pid.h>
13221  #include <trace/events/sched.h>
13222  
13223  static DEFINE_SPINLOCK(kthread_create_lock);
13224 diff -NurpP --minimal linux-4.4.161/kernel/nsproxy.c linux-4.4.161-vs2.3.9.8/kernel/nsproxy.c
13225 --- linux-4.4.161/kernel/nsproxy.c      2016-01-10 23:01:32.000000000 +0000
13226 +++ linux-4.4.161-vs2.3.9.8/kernel/nsproxy.c    2018-10-20 04:57:21.000000000 +0000
13227 @@ -20,11 +20,14 @@
13228  #include <linux/mnt_namespace.h>
13229  #include <linux/utsname.h>
13230  #include <linux/pid_namespace.h>
13231 +#include <linux/vserver/global.h>
13232 +#include <linux/vserver/debug.h>
13233  #include <net/net_namespace.h>
13234  #include <linux/ipc_namespace.h>
13235  #include <linux/proc_ns.h>
13236  #include <linux/file.h>
13237  #include <linux/syscalls.h>
13238 +#include "../fs/mount.h"
13239  
13240  static struct kmem_cache *nsproxy_cachep;
13241  
13242 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
13243         struct nsproxy *nsproxy;
13244  
13245         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
13246 -       if (nsproxy)
13247 +       if (nsproxy) {
13248                 atomic_set(&nsproxy->count, 1);
13249 +               atomic_inc(&vs_global_nsproxy);
13250 +       }
13251 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
13252         return nsproxy;
13253  }
13254  
13255 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
13256   * Return the newly created nsproxy.  Do not attach this to the task,
13257   * leave it to the caller to do proper locking and attach it to task.
13258   */
13259 -static struct nsproxy *create_new_namespaces(unsigned long flags,
13260 -       struct task_struct *tsk, struct user_namespace *user_ns,
13261 -       struct fs_struct *new_fs)
13262 +static struct nsproxy *unshare_namespaces(
13263 +       unsigned long flags,
13264 +       struct nsproxy *orig,
13265 +       struct fs_struct *new_fs,
13266 +       struct user_namespace *new_user,
13267 +       struct pid_namespace *new_pid)
13268  {
13269         struct nsproxy *new_nsp;
13270         int err;
13271 @@ -67,32 +76,31 @@ static struct nsproxy *create_new_namesp
13272         if (!new_nsp)
13273                 return ERR_PTR(-ENOMEM);
13274  
13275 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
13276 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
13277         if (IS_ERR(new_nsp->mnt_ns)) {
13278                 err = PTR_ERR(new_nsp->mnt_ns);
13279                 goto out_ns;
13280         }
13281  
13282 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
13283 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
13284         if (IS_ERR(new_nsp->uts_ns)) {
13285                 err = PTR_ERR(new_nsp->uts_ns);
13286                 goto out_uts;
13287         }
13288  
13289 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
13290 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
13291         if (IS_ERR(new_nsp->ipc_ns)) {
13292                 err = PTR_ERR(new_nsp->ipc_ns);
13293                 goto out_ipc;
13294         }
13295  
13296 -       new_nsp->pid_ns_for_children =
13297 -               copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
13298 +       new_nsp->pid_ns_for_children = copy_pid_ns(flags, new_user, new_pid);
13299         if (IS_ERR(new_nsp->pid_ns_for_children)) {
13300                 err = PTR_ERR(new_nsp->pid_ns_for_children);
13301                 goto out_pid;
13302         }
13303  
13304 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
13305 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
13306         if (IS_ERR(new_nsp->net_ns)) {
13307                 err = PTR_ERR(new_nsp->net_ns);
13308                 goto out_net;
13309 @@ -117,6 +125,41 @@ out_ns:
13310         return ERR_PTR(err);
13311  }
13312  
13313 +static struct nsproxy *create_new_namespaces(unsigned long flags,
13314 +       struct task_struct *tsk, struct user_namespace *user_ns,
13315 +       struct fs_struct *new_fs)
13316 +
13317 +{
13318 +       return unshare_namespaces(flags, tsk->nsproxy,
13319 +               new_fs, user_ns, task_active_pid_ns(tsk));
13320 +}
13321 +
13322 +/*
13323 + * copies the nsproxy, setting refcount to 1, and grabbing a
13324 + * reference to all contained namespaces.
13325 + */
13326 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
13327 +{
13328 +       struct nsproxy *ns = create_nsproxy();
13329 +
13330 +       if (ns) {
13331 +               memcpy(ns, orig, sizeof(struct nsproxy));
13332 +               atomic_set(&ns->count, 1);
13333 +
13334 +               if (ns->mnt_ns)
13335 +                       get_mnt_ns(ns->mnt_ns);
13336 +               if (ns->uts_ns)
13337 +                       get_uts_ns(ns->uts_ns);
13338 +               if (ns->ipc_ns)
13339 +                       get_ipc_ns(ns->ipc_ns);
13340 +               if (ns->pid_ns_for_children)
13341 +                       get_pid_ns(ns->pid_ns_for_children);
13342 +               if (ns->net_ns)
13343 +                       get_net(ns->net_ns);
13344 +       }
13345 +       return ns;
13346 +}
13347 +
13348  /*
13349   * called from clone.  This now handles copy for nsproxy and all
13350   * namespaces therein.
13351 @@ -125,7 +168,10 @@ int copy_namespaces(unsigned long flags,
13352  {
13353         struct nsproxy *old_ns = tsk->nsproxy;
13354         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
13355 -       struct nsproxy *new_ns;
13356 +       struct nsproxy *new_ns = NULL;
13357 +
13358 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
13359 +               flags, tsk, old_ns);
13360  
13361         if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13362                               CLONE_NEWPID | CLONE_NEWNET)))) {
13363 @@ -133,7 +179,7 @@ int copy_namespaces(unsigned long flags,
13364                 return 0;
13365         }
13366  
13367 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13368 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags))
13369                 return -EPERM;
13370  
13371         /*
13372 @@ -152,6 +198,9 @@ int copy_namespaces(unsigned long flags,
13373                 return  PTR_ERR(new_ns);
13374  
13375         tsk->nsproxy = new_ns;
13376 +       vxdprintk(VXD_CBIT(space, 3),
13377 +               "copy_namespaces(0x%08lx,%p[%p]) = [%p]",
13378 +               flags, tsk, old_ns, new_ns);
13379         return 0;
13380  }
13381  
13382 @@ -165,7 +214,9 @@ void free_nsproxy(struct nsproxy *ns)
13383                 put_ipc_ns(ns->ipc_ns);
13384         if (ns->pid_ns_for_children)
13385                 put_pid_ns(ns->pid_ns_for_children);
13386 -       put_net(ns->net_ns);
13387 +       if (ns->net_ns)
13388 +               put_net(ns->net_ns);
13389 +       atomic_dec(&vs_global_nsproxy);
13390         kmem_cache_free(nsproxy_cachep, ns);
13391  }
13392  
13393 @@ -179,12 +230,16 @@ int unshare_nsproxy_namespaces(unsigned
13394         struct user_namespace *user_ns;
13395         int err = 0;
13396  
13397 +       vxdprintk(VXD_CBIT(space, 4),
13398 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
13399 +               unshare_flags, current->nsproxy);
13400 +
13401         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13402                                CLONE_NEWNET | CLONE_NEWPID)))
13403                 return 0;
13404  
13405         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
13406 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13407 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
13408                 return -EPERM;
13409  
13410         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
13411 diff -NurpP --minimal linux-4.4.161/kernel/pid.c linux-4.4.161-vs2.3.9.8/kernel/pid.c
13412 --- linux-4.4.161/kernel/pid.c  2018-10-20 02:34:31.000000000 +0000
13413 +++ linux-4.4.161-vs2.3.9.8/kernel/pid.c        2018-10-20 04:57:21.000000000 +0000
13414 @@ -38,6 +38,7 @@
13415  #include <linux/syscalls.h>
13416  #include <linux/proc_ns.h>
13417  #include <linux/proc_fs.h>
13418 +#include <linux/vs_pid.h>
13419  
13420  #define pid_hashfn(nr, ns)     \
13421         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
13422 @@ -381,7 +382,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
13423  
13424  struct pid *find_vpid(int nr)
13425  {
13426 -       return find_pid_ns(nr, task_active_pid_ns(current));
13427 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
13428  }
13429  EXPORT_SYMBOL_GPL(find_vpid);
13430  
13431 @@ -437,6 +438,9 @@ void transfer_pid(struct task_struct *ol
13432  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
13433  {
13434         struct task_struct *result = NULL;
13435 +
13436 +       if (type == __PIDTYPE_REALPID)
13437 +               type = PIDTYPE_PID;
13438         if (pid) {
13439                 struct hlist_node *first;
13440                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
13441 @@ -455,7 +459,7 @@ struct task_struct *find_task_by_pid_ns(
13442  {
13443         RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
13444                          "find_task_by_pid_ns() needs rcu_read_lock() protection");
13445 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
13446 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
13447  }
13448  
13449  struct task_struct *find_task_by_vpid(pid_t vnr)
13450 @@ -499,7 +503,7 @@ struct pid *find_get_pid(pid_t nr)
13451  }
13452  EXPORT_SYMBOL_GPL(find_get_pid);
13453  
13454 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13455 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
13456  {
13457         struct upid *upid;
13458         pid_t nr = 0;
13459 @@ -513,6 +517,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
13460  }
13461  EXPORT_SYMBOL_GPL(pid_nr_ns);
13462  
13463 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13464 +{
13465 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
13466 +}
13467 +
13468  pid_t pid_vnr(struct pid *pid)
13469  {
13470         return pid_nr_ns(pid, task_active_pid_ns(current));
13471 diff -NurpP --minimal linux-4.4.161/kernel/pid_namespace.c linux-4.4.161-vs2.3.9.8/kernel/pid_namespace.c
13472 --- linux-4.4.161/kernel/pid_namespace.c        2018-10-20 02:34:31.000000000 +0000
13473 +++ linux-4.4.161-vs2.3.9.8/kernel/pid_namespace.c      2018-10-20 04:57:21.000000000 +0000
13474 @@ -18,6 +18,7 @@
13475  #include <linux/proc_ns.h>
13476  #include <linux/reboot.h>
13477  #include <linux/export.h>
13478 +#include <linux/vserver/global.h>
13479  
13480  struct pid_cache {
13481         int nr_ids;
13482 @@ -111,6 +112,7 @@ static struct pid_namespace *create_pid_
13483         ns->ns.ops = &pidns_operations;
13484  
13485         kref_init(&ns->kref);
13486 +       atomic_inc(&vs_global_pid_ns);
13487         ns->level = level;
13488         ns->parent = get_pid_ns(parent_pid_ns);
13489         ns->user_ns = get_user_ns(user_ns);
13490 @@ -128,6 +130,7 @@ static struct pid_namespace *create_pid_
13491  out_free_map:
13492         kfree(ns->pidmap[0].page);
13493  out_free:
13494 +       atomic_dec(&vs_global_pid_ns);
13495         kmem_cache_free(pid_ns_cachep, ns);
13496  out:
13497         return ERR_PTR(err);
13498 diff -NurpP --minimal linux-4.4.161/kernel/printk/printk.c linux-4.4.161-vs2.3.9.8/kernel/printk/printk.c
13499 --- linux-4.4.161/kernel/printk/printk.c        2018-10-20 02:34:31.000000000 +0000
13500 +++ linux-4.4.161-vs2.3.9.8/kernel/printk/printk.c      2018-10-20 04:57:21.000000000 +0000
13501 @@ -46,6 +46,7 @@
13502  #include <linux/utsname.h>
13503  #include <linux/ctype.h>
13504  #include <linux/uio.h>
13505 +#include <linux/vs_cvirt.h>
13506  
13507  #include <asm/uaccess.h>
13508  
13509 @@ -502,7 +503,7 @@ int check_syslog_permissions(int type, i
13510                 goto ok;
13511  
13512         if (syslog_action_restricted(type)) {
13513 -               if (capable(CAP_SYSLOG))
13514 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
13515                         goto ok;
13516                 /*
13517                  * For historical reasons, accept CAP_SYS_ADMIN too, with
13518 @@ -1304,12 +1305,9 @@ int do_syslog(int type, char __user *buf
13519         if (error)
13520                 goto out;
13521  
13522 -       switch (type) {
13523 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
13524 -               break;
13525 -       case SYSLOG_ACTION_OPEN:        /* Open log */
13526 -               break;
13527 -       case SYSLOG_ACTION_READ:        /* Read from log */
13528 +       if ((type == SYSLOG_ACTION_READ) ||
13529 +           (type == SYSLOG_ACTION_READ_ALL) ||
13530 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
13531                 error = -EINVAL;
13532                 if (!buf || len < 0)
13533                         goto out;
13534 @@ -1320,6 +1318,16 @@ int do_syslog(int type, char __user *buf
13535                         error = -EFAULT;
13536                         goto out;
13537                 }
13538 +       }
13539 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13540 +               return vx_do_syslog(type, buf, len);
13541 +
13542 +       switch (type) {
13543 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
13544 +               break;
13545 +       case SYSLOG_ACTION_OPEN:        /* Open log */
13546 +               break;
13547 +       case SYSLOG_ACTION_READ:        /* Read from log */
13548                 error = wait_event_interruptible(log_wait,
13549                                                  syslog_seq != log_next_seq);
13550                 if (error)
13551 @@ -1332,16 +1340,6 @@ int do_syslog(int type, char __user *buf
13552                 /* FALL THRU */
13553         /* Read last kernel messages */
13554         case SYSLOG_ACTION_READ_ALL:
13555 -               error = -EINVAL;
13556 -               if (!buf || len < 0)
13557 -                       goto out;
13558 -               error = 0;
13559 -               if (!len)
13560 -                       goto out;
13561 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
13562 -                       error = -EFAULT;
13563 -                       goto out;
13564 -               }
13565                 error = syslog_print_all(buf, len, clear);
13566                 break;
13567         /* Clear ring buffer */
13568 diff -NurpP --minimal linux-4.4.161/kernel/ptrace.c linux-4.4.161-vs2.3.9.8/kernel/ptrace.c
13569 --- linux-4.4.161/kernel/ptrace.c       2018-10-20 02:34:31.000000000 +0000
13570 +++ linux-4.4.161-vs2.3.9.8/kernel/ptrace.c     2018-10-20 04:57:21.000000000 +0000
13571 @@ -23,6 +23,7 @@
13572  #include <linux/syscalls.h>
13573  #include <linux/uaccess.h>
13574  #include <linux/regset.h>
13575 +#include <linux/vs_context.h>
13576  #include <linux/hw_breakpoint.h>
13577  #include <linux/cn_proc.h>
13578  #include <linux/compat.h>
13579 @@ -301,6 +301,11 @@ ok:
13580  
13581         if (mode & PTRACE_MODE_SCHED)
13582                 return 0;
13583 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
13584 +               return -EPERM;
13585 +       if (!vx_check(task->xid, VS_IDENT) &&
13586 +                       !task_vx_flags(task, VXF_STATE_ADMIN, 0))
13587 +               return -EACCES;
13588         return security_ptrace_access_check(task, mode);
13589  }
13590  
13591 diff -NurpP --minimal linux-4.4.161/kernel/reboot.c linux-4.4.161-vs2.3.9.8/kernel/reboot.c
13592 --- linux-4.4.161/kernel/reboot.c       2016-01-10 23:01:32.000000000 +0000
13593 +++ linux-4.4.161-vs2.3.9.8/kernel/reboot.c     2018-10-20 04:57:21.000000000 +0000
13594 @@ -16,6 +16,7 @@
13595  #include <linux/syscalls.h>
13596  #include <linux/syscore_ops.h>
13597  #include <linux/uaccess.h>
13598 +#include <linux/vs_pid.h>
13599  
13600  /*
13601   * this indicates whether you can reboot with ctrl-alt-del: the default is yes
13602 @@ -269,6 +270,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
13603  
13604  static DEFINE_MUTEX(reboot_mutex);
13605  
13606 +long vs_reboot(unsigned int, void __user *);
13607 +
13608  /*
13609   * Reboot system call: for obvious reasons only root may call it,
13610   * and even root needs to set up some magic numbers in the registers
13611 @@ -311,6 +314,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
13612         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
13613                 cmd = LINUX_REBOOT_CMD_HALT;
13614  
13615 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13616 +               return vs_reboot(cmd, arg);
13617 +
13618         mutex_lock(&reboot_mutex);
13619         switch (cmd) {
13620         case LINUX_REBOOT_CMD_RESTART:
13621 diff -NurpP --minimal linux-4.4.161/kernel/sched/core.c linux-4.4.161-vs2.3.9.8/kernel/sched/core.c
13622 --- linux-4.4.161/kernel/sched/core.c   2018-10-20 02:34:31.000000000 +0000
13623 +++ linux-4.4.161-vs2.3.9.8/kernel/sched/core.c 2018-10-20 04:57:21.000000000 +0000
13624 @@ -74,6 +74,8 @@
13625  #include <linux/binfmts.h>
13626  #include <linux/context_tracking.h>
13627  #include <linux/compiler.h>
13628 +#include <linux/vs_sched.h>
13629 +#include <linux/vs_cvirt.h>
13630  
13631  #include <asm/switch_to.h>
13632  #include <asm/tlb.h>
13633 @@ -3560,7 +3562,7 @@ SYSCALL_DEFINE1(nice, int, increment)
13634  
13635         nice = clamp_val(nice, MIN_NICE, MAX_NICE);
13636         if (increment < 0 && !can_nice(current, nice))
13637 -               return -EPERM;
13638 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
13639  
13640         retval = security_task_setnice(current, nice);
13641         if (retval)
13642 diff -NurpP --minimal linux-4.4.161/kernel/sched/cputime.c linux-4.4.161-vs2.3.9.8/kernel/sched/cputime.c
13643 --- linux-4.4.161/kernel/sched/cputime.c        2018-10-20 02:34:31.000000000 +0000
13644 +++ linux-4.4.161-vs2.3.9.8/kernel/sched/cputime.c      2018-10-20 04:57:21.000000000 +0000
13645 @@ -4,6 +4,7 @@
13646  #include <linux/kernel_stat.h>
13647  #include <linux/static_key.h>
13648  #include <linux/context_tracking.h>
13649 +#include <linux/vs_sched.h>
13650  #include "sched.h"
13651  
13652  
13653 @@ -135,14 +136,17 @@ static inline void task_group_account_fi
13654  void account_user_time(struct task_struct *p, cputime_t cputime,
13655                        cputime_t cputime_scaled)
13656  {
13657 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
13658 +       int nice = (task_nice(p) > 0);
13659         int index;
13660  
13661         /* Add user time to process. */
13662         p->utime += cputime;
13663         p->utimescaled += cputime_scaled;
13664 +       vx_account_user(vxi, cputime, nice);
13665         account_group_user_time(p, cputime);
13666  
13667 -       index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
13668 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
13669  
13670         /* Add user time to cpustat. */
13671         task_group_account_field(p, index, (__force u64) cputime);
13672 @@ -189,9 +193,12 @@ static inline
13673  void __account_system_time(struct task_struct *p, cputime_t cputime,
13674                         cputime_t cputime_scaled, int index)
13675  {
13676 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
13677 +
13678         /* Add system time to process. */
13679         p->stime += cputime;
13680         p->stimescaled += cputime_scaled;
13681 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
13682         account_group_system_time(p, cputime);
13683  
13684         /* Add system time to cpustat. */
13685 diff -NurpP --minimal linux-4.4.161/kernel/sched/fair.c linux-4.4.161-vs2.3.9.8/kernel/sched/fair.c
13686 --- linux-4.4.161/kernel/sched/fair.c   2018-10-20 02:34:31.000000000 +0000
13687 +++ linux-4.4.161-vs2.3.9.8/kernel/sched/fair.c 2018-10-20 04:57:21.000000000 +0000
13688 @@ -30,6 +30,7 @@
13689  #include <linux/mempolicy.h>
13690  #include <linux/migrate.h>
13691  #include <linux/task_work.h>
13692 +#include <linux/vs_cvirt.h>
13693  
13694  #include <trace/events/sched.h>
13695  
13696 @@ -3056,6 +3057,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
13697                 __enqueue_entity(cfs_rq, se);
13698         se->on_rq = 1;
13699  
13700 +       if (entity_is_task(se))
13701 +               vx_activate_task(task_of(se));
13702         if (cfs_rq->nr_running == 1) {
13703                 list_add_leaf_cfs_rq(cfs_rq);
13704                 check_enqueue_throttle(cfs_rq);
13705 @@ -3137,6 +3140,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
13706         if (se != cfs_rq->curr)
13707                 __dequeue_entity(cfs_rq, se);
13708         se->on_rq = 0;
13709 +       if (entity_is_task(se))
13710 +               vx_deactivate_task(task_of(se));
13711         account_entity_dequeue(cfs_rq, se);
13712  
13713         /*
13714 diff -NurpP --minimal linux-4.4.161/kernel/sched/loadavg.c linux-4.4.161-vs2.3.9.8/kernel/sched/loadavg.c
13715 --- linux-4.4.161/kernel/sched/loadavg.c        2018-10-20 02:34:31.000000000 +0000
13716 +++ linux-4.4.161-vs2.3.9.8/kernel/sched/loadavg.c      2018-10-20 04:57:21.000000000 +0000
13717 @@ -73,9 +73,16 @@ EXPORT_SYMBOL(avenrun); /* should be rem
13718   */
13719  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
13720  {
13721 -       loads[0] = (avenrun[0] + offset) << shift;
13722 -       loads[1] = (avenrun[1] + offset) << shift;
13723 -       loads[2] = (avenrun[2] + offset) << shift;
13724 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
13725 +               struct vx_info *vxi = current_vx_info();
13726 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
13727 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
13728 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
13729 +       } else {
13730 +               loads[0] = (avenrun[0] + offset) << shift;
13731 +               loads[1] = (avenrun[1] + offset) << shift;
13732 +               loads[2] = (avenrun[2] + offset) << shift;
13733 +       }
13734  }
13735  
13736  long calc_load_fold_active(struct rq *this_rq)
13737 diff -NurpP --minimal linux-4.4.161/kernel/signal.c linux-4.4.161-vs2.3.9.8/kernel/signal.c
13738 --- linux-4.4.161/kernel/signal.c       2018-10-20 02:34:31.000000000 +0000
13739 +++ linux-4.4.161-vs2.3.9.8/kernel/signal.c     2018-10-20 04:57:21.000000000 +0000
13740 @@ -34,6 +34,8 @@
13741  #include <linux/compat.h>
13742  #include <linux/cn_proc.h>
13743  #include <linux/compiler.h>
13744 +#include <linux/vs_context.h>
13745 +#include <linux/vs_pid.h>
13746  
13747  #define CREATE_TRACE_POINTS
13748  #include <trace/events/signal.h>
13749 @@ -726,9 +728,18 @@ static int check_kill_permission(int sig
13750         struct pid *sid;
13751         int error;
13752  
13753 +       vxdprintk(VXD_CBIT(misc, 7),
13754 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
13755 +               sig, info, t, vx_task_xid(t), t->pid);
13756 +
13757         if (!valid_signal(sig))
13758                 return -EINVAL;
13759  
13760 +/*     FIXME: needed? if so, why?
13761 +       if ((info != SEND_SIG_NOINFO) &&
13762 +               (is_si_special(info) || !si_fromuser(info)))
13763 +               goto skip;      */
13764 +
13765         if (!si_fromuser(info))
13766                 return 0;
13767  
13768 @@ -752,6 +763,20 @@ static int check_kill_permission(int sig
13769                 }
13770         }
13771  
13772 +       error = -EPERM;
13773 +       if (t->pid == 1 && current->xid)
13774 +               return error;
13775 +
13776 +       error = -ESRCH;
13777 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
13778 +                 loops, maybe ENOENT or EACCES? */
13779 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
13780 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
13781 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
13782 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
13783 +               return error;
13784 +       }
13785 +/* skip: */
13786         return security_task_kill(t, info, sig, 0);
13787  }
13788  
13789 @@ -1303,8 +1328,14 @@ int kill_pid_info(int sig, struct siginf
13790         for (;;) {
13791                 rcu_read_lock();
13792                 p = pid_task(pid, PIDTYPE_PID);
13793 -               if (p)
13794 -                       error = group_send_sig_info(sig, info, p);
13795 +               if (p) {
13796 +                       if (vx_check(vx_task_xid(p), VS_IDENT))
13797 +                               error = group_send_sig_info(sig, info, p);
13798 +                       else {
13799 +                               rcu_read_unlock();
13800 +                               return -ESRCH;
13801 +                       }
13802 +               }
13803                 rcu_read_unlock();
13804                 if (likely(!p || error != -ESRCH))
13805                         return error;
13806 @@ -1349,7 +1380,7 @@ int kill_pid_info_as_cred(int sig, struc
13807  
13808         rcu_read_lock();
13809         p = pid_task(pid, PIDTYPE_PID);
13810 -       if (!p) {
13811 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
13812                 ret = -ESRCH;
13813                 goto out_unlock;
13814         }
13815 @@ -1405,8 +1436,10 @@ static int kill_something_info(int sig,
13816                 struct task_struct * p;
13817  
13818                 for_each_process(p) {
13819 -                       if (task_pid_vnr(p) > 1 &&
13820 -                                       !same_thread_group(p, current)) {
13821 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
13822 +                               task_pid_vnr(p) > 1 &&
13823 +                               !same_thread_group(p, current) &&
13824 +                               !vx_current_initpid(p->pid)) {
13825                                 int err = group_send_sig_info(sig, info, p);
13826                                 ++count;
13827                                 if (err != -EPERM)
13828 @@ -2259,6 +2292,11 @@ relock:
13829                                 !sig_kernel_only(signr))
13830                         continue;
13831  
13832 +               /* virtual init is protected against user signals */
13833 +               if ((ksig->info.si_code == SI_USER) &&
13834 +                       vx_current_initpid(current->pid))
13835 +                       continue;
13836 +
13837                 if (sig_kernel_stop(signr)) {
13838                         /*
13839                          * The default action is to stop all threads in
13840 diff -NurpP --minimal linux-4.4.161/kernel/softirq.c linux-4.4.161-vs2.3.9.8/kernel/softirq.c
13841 --- linux-4.4.161/kernel/softirq.c      2016-01-10 23:01:32.000000000 +0000
13842 +++ linux-4.4.161-vs2.3.9.8/kernel/softirq.c    2018-10-20 04:57:21.000000000 +0000
13843 @@ -26,6 +26,7 @@
13844  #include <linux/smpboot.h>
13845  #include <linux/tick.h>
13846  #include <linux/irq.h>
13847 +#include <linux/vs_context.h>
13848  
13849  #define CREATE_TRACE_POINTS
13850  #include <trace/events/irq.h>
13851 diff -NurpP --minimal linux-4.4.161/kernel/sys.c linux-4.4.161-vs2.3.9.8/kernel/sys.c
13852 --- linux-4.4.161/kernel/sys.c  2018-10-20 02:34:31.000000000 +0000
13853 +++ linux-4.4.161-vs2.3.9.8/kernel/sys.c        2018-10-20 05:50:20.000000000 +0000
13854 @@ -56,6 +56,7 @@
13855  #include <linux/nospec.h>
13856  
13857  #include <linux/kmsg_dump.h>
13858 +#include <linux/vs_pid.h>
13859  /* Move somewhere else to avoid recompiling? */
13860  #include <generated/utsrelease.h>
13861  
13862 @@ -159,7 +160,10 @@ static int set_one_prio(struct task_stru
13863                 goto out;
13864         }
13865         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
13866 -               error = -EACCES;
13867 +               if (vx_flags(VXF_IGNEG_NICE, 0))
13868 +                       error = 0;
13869 +               else
13870 +                       error = -EACCES;
13871                 goto out;
13872         }
13873         no_nice = security_task_setnice(p, niceval);
13874 @@ -210,6 +214,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
13875                 else
13876                         pgrp = task_pgrp(current);
13877                 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
13878 +                       if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
13879 +                               continue;
13880                         error = set_one_prio(p, niceval, error);
13881                 } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
13882                 break;
13883 @@ -276,6 +282,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
13884                 else
13885                         pgrp = task_pgrp(current);
13886                 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
13887 +                       if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
13888 +                               continue;
13889                         niceval = nice_to_rlimit(task_nice(p));
13890                         if (niceval > retval)
13891                                 retval = niceval;
13892 @@ -292,6 +300,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
13893                                 goto out_unlock;        /* No processes for this user */
13894                 }
13895                 do_each_thread(g, p) {
13896 +                       if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
13897 +                               continue;
13898                         if (uid_eq(task_uid(p), uid) && task_pid_vnr(p)) {
13899                                 niceval = nice_to_rlimit(task_nice(p));
13900                                 if (niceval > retval)
13901 @@ -1211,7 +1221,8 @@ SYSCALL_DEFINE2(sethostname, char __user
13902         int errno;
13903         char tmp[__NEW_UTS_LEN];
13904  
13905 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
13906 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
13907 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
13908                 return -EPERM;
13909  
13910         if (len < 0 || len > __NEW_UTS_LEN)
13911 @@ -1264,7 +1275,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
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         if (len < 0 || len > __NEW_UTS_LEN)
13920                 return -EINVAL;
13921 @@ -1384,7 +1396,7 @@ int do_prlimit(struct task_struct *tsk,
13922                 /* Keep the capable check against init_user_ns until
13923                    cgroups can contain all limits */
13924                 if (new_rlim->rlim_max > rlim->rlim_max &&
13925 -                               !capable(CAP_SYS_RESOURCE))
13926 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
13927                         retval = -EPERM;
13928                 if (!retval)
13929                         retval = security_task_setrlimit(tsk->group_leader,
13930 @@ -1437,7 +1449,8 @@ static int check_prlimit_permission(stru
13931             gid_eq(cred->gid, tcred->sgid) &&
13932             gid_eq(cred->gid, tcred->gid))
13933                 return 0;
13934 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
13935 +       if (vx_ns_capable(tcred->user_ns,
13936 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
13937                 return 0;
13938  
13939         return -EPERM;
13940 diff -NurpP --minimal linux-4.4.161/kernel/sysctl.c linux-4.4.161-vs2.3.9.8/kernel/sysctl.c
13941 --- linux-4.4.161/kernel/sysctl.c       2018-10-20 02:34:31.000000000 +0000
13942 +++ linux-4.4.161-vs2.3.9.8/kernel/sysctl.c     2018-10-20 05:50:20.000000000 +0000
13943 @@ -87,6 +87,7 @@
13944  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
13945  #include <linux/lockdep.h>
13946  #endif
13947 +extern char vshelper_path[];
13948  #ifdef CONFIG_CHR_DEV_SG
13949  #include <scsi/sg.h>
13950  #endif
13951 @@ -279,6 +280,13 @@ static int max_extfrag_threshold = 1000;
13952  
13953  static struct ctl_table kern_table[] = {
13954         {
13955 +               .procname       = "vshelper",
13956 +               .data           = &vshelper_path,
13957 +               .maxlen         = 256,
13958 +               .mode           = 0644,
13959 +               .proc_handler   = proc_dostring,
13960 +       },
13961 +       {
13962                 .procname       = "sched_child_runs_first",
13963                 .data           = &sysctl_sched_child_runs_first,
13964                 .maxlen         = sizeof(unsigned int),
13965 @@ -1386,7 +1394,6 @@ static struct ctl_table vm_table[] = {
13966                 .extra1         = &zero,
13967                 .extra2         = &one,
13968         },
13969 -
13970  #endif /* CONFIG_COMPACTION */
13971         {
13972                 .procname       = "min_free_kbytes",
13973 diff -NurpP --minimal linux-4.4.161/kernel/sysctl_binary.c linux-4.4.161-vs2.3.9.8/kernel/sysctl_binary.c
13974 --- linux-4.4.161/kernel/sysctl_binary.c        2018-10-20 02:34:31.000000000 +0000
13975 +++ linux-4.4.161-vs2.3.9.8/kernel/sysctl_binary.c      2018-10-20 04:57:21.000000000 +0000
13976 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
13977  
13978         { CTL_INT,      KERN_PANIC,                     "panic" },
13979         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
13980 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
13981  
13982         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
13983         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
13984 diff -NurpP --minimal linux-4.4.161/kernel/time/posix-timers.c linux-4.4.161-vs2.3.9.8/kernel/time/posix-timers.c
13985 --- linux-4.4.161/kernel/time/posix-timers.c    2018-10-20 02:34:31.000000000 +0000
13986 +++ linux-4.4.161-vs2.3.9.8/kernel/time/posix-timers.c  2018-10-20 04:57:21.000000000 +0000
13987 @@ -48,6 +48,7 @@
13988  #include <linux/workqueue.h>
13989  #include <linux/export.h>
13990  #include <linux/hashtable.h>
13991 +#include <linux/vs_context.h>
13992  
13993  #include "timekeeping.h"
13994  
13995 @@ -407,6 +408,7 @@ int posix_timer_event(struct k_itimer *t
13996  {
13997         struct task_struct *task;
13998         int shared, ret = -1;
13999 +
14000         /*
14001          * FIXME: if ->sigq is queued we can race with
14002          * dequeue_signal()->do_schedule_next_timer().
14003 @@ -423,10 +425,18 @@ int posix_timer_event(struct k_itimer *t
14004         rcu_read_lock();
14005         task = pid_task(timr->it_pid, PIDTYPE_PID);
14006         if (task) {
14007 +               struct vx_info_save vxis;
14008 +               struct vx_info *vxi;
14009 +
14010 +               vxi = get_vx_info(task->vx_info);
14011 +               enter_vx_info(vxi, &vxis);
14012                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14013                 ret = send_sigqueue(timr->sigq, task, shared);
14014 +               leave_vx_info(&vxis);
14015 +               put_vx_info(vxi);
14016         }
14017         rcu_read_unlock();
14018 +
14019         /* If we failed to send the signal the timer stops. */
14020         return ret > 0;
14021  }
14022 diff -NurpP --minimal linux-4.4.161/kernel/time/time.c linux-4.4.161-vs2.3.9.8/kernel/time/time.c
14023 --- linux-4.4.161/kernel/time/time.c    2018-10-20 02:34:31.000000000 +0000
14024 +++ linux-4.4.161-vs2.3.9.8/kernel/time/time.c  2018-10-20 04:57:21.000000000 +0000
14025 @@ -38,6 +38,7 @@
14026  #include <linux/fs.h>
14027  #include <linux/math64.h>
14028  #include <linux/ptrace.h>
14029 +#include <linux/vs_time.h>
14030  
14031  #include <asm/uaccess.h>
14032  #include <asm/unistd.h>
14033 @@ -94,7 +95,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
14034         if (err)
14035                 return err;
14036  
14037 -       do_settimeofday(&tv);
14038 +       vx_settimeofday(&tv);
14039         return 0;
14040  }
14041  
14042 @@ -187,7 +188,7 @@ int do_sys_settimeofday(const struct tim
14043                 }
14044         }
14045         if (tv)
14046 -               return do_settimeofday(tv);
14047 +               return vx_settimeofday(tv);
14048         return 0;
14049  }
14050  
14051 diff -NurpP --minimal linux-4.4.161/kernel/time/timekeeping.c linux-4.4.161-vs2.3.9.8/kernel/time/timekeeping.c
14052 --- linux-4.4.161/kernel/time/timekeeping.c     2018-10-20 02:34:31.000000000 +0000
14053 +++ linux-4.4.161-vs2.3.9.8/kernel/time/timekeeping.c   2018-10-20 04:57:21.000000000 +0000
14054 @@ -23,6 +23,7 @@
14055  #include <linux/stop_machine.h>
14056  #include <linux/pvclock_gtod.h>
14057  #include <linux/compiler.h>
14058 +#include <linux/vs_time.h>
14059  
14060  #include "tick-internal.h"
14061  #include "ntp_internal.h"
14062 @@ -920,7 +921,9 @@ void ktime_get_raw_and_real_ts64(struct
14063         } while (read_seqcount_retry(&tk_core.seq, seq));
14064  
14065         timespec64_add_ns(ts_raw, nsecs_raw);
14066 +       vx_adjust_timespec(ts_raw);
14067         timespec64_add_ns(ts_real, nsecs_real);
14068 +       vx_adjust_timespec(ts_real);
14069  }
14070  EXPORT_SYMBOL(ktime_get_raw_and_real_ts64);
14071  
14072 diff -NurpP --minimal linux-4.4.161/kernel/time/timer.c linux-4.4.161-vs2.3.9.8/kernel/time/timer.c
14073 --- linux-4.4.161/kernel/time/timer.c   2018-10-20 02:34:31.000000000 +0000
14074 +++ linux-4.4.161-vs2.3.9.8/kernel/time/timer.c 2018-10-20 04:57:21.000000000 +0000
14075 @@ -42,6 +42,10 @@
14076  #include <linux/sched/sysctl.h>
14077  #include <linux/slab.h>
14078  #include <linux/compat.h>
14079 +#include <linux/vs_base.h>
14080 +#include <linux/vs_cvirt.h>
14081 +#include <linux/vs_pid.h>
14082 +#include <linux/vserver/sched.h>
14083  
14084  #include <asm/uaccess.h>
14085  #include <asm/unistd.h>
14086 diff -NurpP --minimal linux-4.4.161/kernel/user_namespace.c linux-4.4.161-vs2.3.9.8/kernel/user_namespace.c
14087 --- linux-4.4.161/kernel/user_namespace.c       2018-10-20 02:34:31.000000000 +0000
14088 +++ linux-4.4.161-vs2.3.9.8/kernel/user_namespace.c     2018-10-20 05:50:20.000000000 +0000
14089 @@ -22,6 +22,7 @@
14090  #include <linux/ctype.h>
14091  #include <linux/projid.h>
14092  #include <linux/fs_struct.h>
14093 +#include <linux/vserver/global.h>
14094  
14095  static struct kmem_cache *user_ns_cachep __read_mostly;
14096  static DEFINE_MUTEX(userns_state_mutex);
14097 @@ -97,6 +98,7 @@ int create_user_ns(struct cred *new)
14098  
14099         atomic_set(&ns->count, 1);
14100         /* Leave the new->user_ns reference with the new user namespace. */
14101 +       atomic_inc(&vs_global_user_ns);
14102         ns->parent = parent_ns;
14103         ns->level = parent_ns->level + 1;
14104         ns->owner = owner;
14105 @@ -145,6 +147,7 @@ void free_user_ns(struct user_namespace
14106                 key_put(ns->persistent_keyring_register);
14107  #endif
14108                 ns_free_inum(&ns->ns);
14109 +               atomic_dec(&vs_global_user_ns);
14110                 kmem_cache_free(user_ns_cachep, ns);
14111                 ns = parent;
14112         } while (atomic_dec_and_test(&parent->count));
14113 @@ -358,6 +361,18 @@ gid_t from_kgid_munged(struct user_names
14114  }
14115  EXPORT_SYMBOL(from_kgid_munged);
14116  
14117 +ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
14118 +{
14119 +       return KTAGT_INIT(tag);
14120 +}
14121 +EXPORT_SYMBOL(make_ktag);
14122 +
14123 +vtag_t from_ktag(struct user_namespace *to, ktag_t tag)
14124 +{
14125 +       return __ktag_val(tag);
14126 +}
14127 +EXPORT_SYMBOL(from_ktag);
14128 +
14129  /**
14130   *     make_kprojid - Map a user-namespace projid pair into a kprojid.
14131   *     @ns:  User namespace that the projid is in
14132 diff -NurpP --minimal linux-4.4.161/kernel/utsname.c linux-4.4.161-vs2.3.9.8/kernel/utsname.c
14133 --- linux-4.4.161/kernel/utsname.c      2016-01-10 23:01:32.000000000 +0000
14134 +++ linux-4.4.161-vs2.3.9.8/kernel/utsname.c    2018-10-20 04:57:21.000000000 +0000
14135 @@ -16,14 +16,17 @@
14136  #include <linux/slab.h>
14137  #include <linux/user_namespace.h>
14138  #include <linux/proc_ns.h>
14139 +#include <linux/vserver/global.h>
14140  
14141  static struct uts_namespace *create_uts_ns(void)
14142  {
14143         struct uts_namespace *uts_ns;
14144  
14145         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
14146 -       if (uts_ns)
14147 +       if (uts_ns) {
14148                 kref_init(&uts_ns->kref);
14149 +               atomic_inc(&vs_global_uts_ns);
14150 +       }
14151         return uts_ns;
14152  }
14153  
14154 @@ -87,6 +90,7 @@ void free_uts_ns(struct kref *kref)
14155         ns = container_of(kref, struct uts_namespace, kref);
14156         put_user_ns(ns->user_ns);
14157         ns_free_inum(&ns->ns);
14158 +       atomic_dec(&vs_global_uts_ns);
14159         kfree(ns);
14160  }
14161  
14162 diff -NurpP --minimal linux-4.4.161/kernel/vserver/Kconfig linux-4.4.161-vs2.3.9.8/kernel/vserver/Kconfig
14163 --- linux-4.4.161/kernel/vserver/Kconfig        1970-01-01 00:00:00.000000000 +0000
14164 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/Kconfig      2018-10-20 04:57:21.000000000 +0000
14165 @@ -0,0 +1,230 @@
14166 +#
14167 +# Linux VServer configuration
14168 +#
14169 +
14170 +menu "Linux VServer"
14171 +
14172 +config VSERVER_AUTO_LBACK
14173 +       bool    "Automatically Assign Loopback IP"
14174 +       default y
14175 +       help
14176 +         Automatically assign a guest specific loopback
14177 +         IP and add it to the kernel network stack on
14178 +         startup.
14179 +
14180 +config VSERVER_AUTO_SINGLE
14181 +       bool    "Automatic Single IP Special Casing"
14182 +       default n
14183 +       help
14184 +         This allows network contexts with a single IP to
14185 +         automatically remap 0.0.0.0 bindings to that IP,
14186 +         avoiding further network checks and improving
14187 +         performance.
14188 +
14189 +         (note: such guests do not allow to change the ip
14190 +          on the fly and do not show loopback addresses)
14191 +
14192 +config VSERVER_COWBL
14193 +       bool    "Enable COW Immutable Link Breaking"
14194 +       default y
14195 +       help
14196 +         This enables the COW (Copy-On-Write) link break code.
14197 +         It allows you to treat unified files like normal files
14198 +         when writing to them (which will implicitely break the
14199 +         link and create a copy of the unified file)
14200 +
14201 +config VSERVER_VTIME
14202 +       bool    "Enable Virtualized Guest Time (EXPERIMENTAL)"
14203 +       default n
14204 +       help
14205 +         This enables per guest time offsets to allow for
14206 +         adjusting the system clock individually per guest.
14207 +         this adds some overhead to the time functions and
14208 +         therefore should not be enabled without good reason.
14209 +
14210 +config VSERVER_DEVICE
14211 +       bool    "Enable Guest Device Mapping (EXPERIMENTAL)"
14212 +       default n
14213 +       help
14214 +         This enables generic device remapping.
14215 +
14216 +config VSERVER_PROC_SECURE
14217 +       bool    "Enable Proc Security"
14218 +       depends on PROC_FS
14219 +       default y
14220 +       help
14221 +         This configures ProcFS security to initially hide
14222 +         non-process entries for all contexts except the main and
14223 +         spectator context (i.e. for all guests), which is a secure
14224 +         default.
14225 +
14226 +         (note: on 1.2x the entries were visible by default)
14227 +
14228 +choice
14229 +       prompt  "Persistent Inode Tagging"
14230 +       default TAGGING_ID24
14231 +       help
14232 +         This adds persistent context information to filesystems
14233 +         mounted with the tagxid option. Tagging is a requirement
14234 +         for per-context disk limits and per-context quota.
14235 +
14236 +
14237 +config TAGGING_NONE
14238 +       bool    "Disabled"
14239 +       help
14240 +         do not store per-context information in inodes.
14241 +
14242 +config TAGGING_UID16
14243 +       bool    "UID16/GID32"
14244 +       help
14245 +         reduces UID to 16 bit, but leaves GID at 32 bit.
14246 +
14247 +config TAGGING_GID16
14248 +       bool    "UID32/GID16"
14249 +       help
14250 +         reduces GID to 16 bit, but leaves UID at 32 bit.
14251 +
14252 +config TAGGING_ID24
14253 +       bool    "UID24/GID24"
14254 +       help
14255 +         uses the upper 8bit from UID and GID for XID tagging
14256 +         which leaves 24bit for UID/GID each, which should be
14257 +         more than sufficient for normal use.
14258 +
14259 +config TAGGING_INTERN
14260 +       bool    "UID32/GID32"
14261 +       help
14262 +         this uses otherwise reserved inode fields in the on
14263 +         disk representation, which limits the use to a few
14264 +         filesystems (currently ext2 and ext3)
14265 +
14266 +endchoice
14267 +
14268 +config TAG_NFSD
14269 +       bool    "Tag NFSD User Auth and Files"
14270 +       default n
14271 +       help
14272 +         Enable this if you do want the in-kernel NFS
14273 +         Server to use the tagging specified above.
14274 +         (will require patched clients too)
14275 +
14276 +config VSERVER_PRIVACY
14277 +       bool    "Honor Privacy Aspects of Guests"
14278 +       default n
14279 +       help
14280 +         When enabled, most context checks will disallow
14281 +         access to structures assigned to a specific context,
14282 +         like ptys or loop devices.
14283 +
14284 +config VSERVER_CONTEXTS
14285 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
14286 +       range 1 65533
14287 +       default "768"   if 64BIT
14288 +       default "256"
14289 +       help
14290 +         This setting will optimize certain data structures
14291 +         and memory allocations according to the expected
14292 +         maximum.
14293 +
14294 +         note: this is not a strict upper limit.
14295 +
14296 +config VSERVER_WARN
14297 +       bool    "VServer Warnings"
14298 +       default y
14299 +       help
14300 +         This enables various runtime warnings, which will
14301 +         notify about potential manipulation attempts or
14302 +         resource shortage. It is generally considered to
14303 +         be a good idea to have that enabled.
14304 +
14305 +config VSERVER_WARN_DEVPTS
14306 +       bool    "VServer DevPTS Warnings"
14307 +       depends on VSERVER_WARN
14308 +       default y
14309 +       help
14310 +         This enables DevPTS related warnings, issued when a
14311 +         process inside a context tries to lookup or access
14312 +         a dynamic pts from the host or a different context.
14313 +
14314 +config VSERVER_DEBUG
14315 +       bool    "VServer Debugging Code"
14316 +       default n
14317 +       help
14318 +         Set this to yes if you want to be able to activate
14319 +         debugging output at runtime. It adds a very small
14320 +         overhead to all vserver related functions and
14321 +         increases the kernel size by about 20k.
14322 +
14323 +config VSERVER_HISTORY
14324 +       bool    "VServer History Tracing"
14325 +       depends on VSERVER_DEBUG
14326 +       default n
14327 +       help
14328 +         Set this to yes if you want to record the history of
14329 +         linux-vserver activities, so they can be replayed in
14330 +         the event of a kernel panic or oops.
14331 +
14332 +config VSERVER_HISTORY_SIZE
14333 +       int     "Per-CPU History Size (32-65536)"
14334 +       depends on VSERVER_HISTORY
14335 +       range 32 65536
14336 +       default 64
14337 +       help
14338 +         This allows you to specify the number of entries in
14339 +         the per-CPU history buffer.
14340 +
14341 +config VSERVER_EXTRA_MNT_CHECK
14342 +       bool    "Extra Checks for Reachability"
14343 +       default n
14344 +       help
14345 +         Set this to yes if you want to do extra checks for
14346 +         vfsmount reachability in the proc filesystem code.
14347 +         This shouldn't be required on any setup utilizing
14348 +         mnt namespaces.
14349 +
14350 +choice
14351 +       prompt  "Quotes used in debug and warn messages"
14352 +       default QUOTES_ISO8859
14353 +
14354 +config QUOTES_ISO8859
14355 +       bool    "Extended ASCII (ISO 8859) angle quotes"
14356 +       help
14357 +         This uses the extended ASCII characters \xbb
14358 +         and \xab for quoting file and process names.
14359 +
14360 +config QUOTES_UTF8
14361 +       bool    "UTF-8 angle quotes"
14362 +       help
14363 +         This uses the the UTF-8 sequences for angle
14364 +         quotes to quote file and process names.
14365 +
14366 +config QUOTES_ASCII
14367 +       bool    "ASCII single quotes"
14368 +       help
14369 +         This uses the ASCII single quote character
14370 +         (\x27) to quote file and process names.
14371 +
14372 +endchoice
14373 +
14374 +endmenu
14375 +
14376 +
14377 +config VSERVER
14378 +       bool
14379 +       default y
14380 +       select NAMESPACES
14381 +       select UTS_NS
14382 +       select IPC_NS
14383 +#      select USER_NS
14384 +       select SYSVIPC
14385 +
14386 +config VSERVER_SECURITY
14387 +       bool
14388 +       depends on SECURITY
14389 +       default y
14390 +       select SECURITY_CAPABILITIES
14391 +
14392 +config VSERVER_DISABLED
14393 +       bool
14394 +       default n
14395 +
14396 diff -NurpP --minimal linux-4.4.161/kernel/vserver/Makefile linux-4.4.161-vs2.3.9.8/kernel/vserver/Makefile
14397 --- linux-4.4.161/kernel/vserver/Makefile       1970-01-01 00:00:00.000000000 +0000
14398 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/Makefile     2018-10-20 04:57:21.000000000 +0000
14399 @@ -0,0 +1,18 @@
14400 +#
14401 +# Makefile for the Linux vserver routines.
14402 +#
14403 +
14404 +
14405 +obj-y          += vserver.o
14406 +
14407 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
14408 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
14409 +                  dlimit.o tag.o
14410 +
14411 +vserver-$(CONFIG_INET) += inet.o
14412 +vserver-$(CONFIG_PROC_FS) += proc.o
14413 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
14414 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
14415 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
14416 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
14417 +
14418 diff -NurpP --minimal linux-4.4.161/kernel/vserver/cacct.c linux-4.4.161-vs2.3.9.8/kernel/vserver/cacct.c
14419 --- linux-4.4.161/kernel/vserver/cacct.c        1970-01-01 00:00:00.000000000 +0000
14420 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/cacct.c      2018-10-20 04:57:21.000000000 +0000
14421 @@ -0,0 +1,42 @@
14422 +/*
14423 + *  linux/kernel/vserver/cacct.c
14424 + *
14425 + *  Virtual Server: Context Accounting
14426 + *
14427 + *  Copyright (C) 2006-2007 Herbert P?tzl
14428 + *
14429 + *  V0.01  added accounting stats
14430 + *
14431 + */
14432 +
14433 +#include <linux/types.h>
14434 +#include <linux/vs_context.h>
14435 +#include <linux/vserver/cacct_cmd.h>
14436 +#include <linux/vserver/cacct_int.h>
14437 +
14438 +#include <asm/errno.h>
14439 +#include <asm/uaccess.h>
14440 +
14441 +
14442 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
14443 +{
14444 +       struct vcmd_sock_stat_v0 vc_data;
14445 +       int j, field;
14446 +
14447 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
14448 +               return -EFAULT;
14449 +
14450 +       field = vc_data.field;
14451 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
14452 +               return -EINVAL;
14453 +
14454 +       for (j = 0; j < 3; j++) {
14455 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
14456 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
14457 +       }
14458 +
14459 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
14460 +               return -EFAULT;
14461 +       return 0;
14462 +}
14463 +
14464 diff -NurpP --minimal linux-4.4.161/kernel/vserver/cacct_init.h linux-4.4.161-vs2.3.9.8/kernel/vserver/cacct_init.h
14465 --- linux-4.4.161/kernel/vserver/cacct_init.h   1970-01-01 00:00:00.000000000 +0000
14466 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/cacct_init.h 2018-10-20 04:57:21.000000000 +0000
14467 @@ -0,0 +1,25 @@
14468 +
14469 +
14470 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
14471 +{
14472 +       int i, j;
14473 +
14474 +
14475 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14476 +               for (j = 0; j < 3; j++) {
14477 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
14478 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
14479 +               }
14480 +       }
14481 +       for (i = 0; i < 8; i++)
14482 +               atomic_set(&cacct->slab[i], 0);
14483 +       for (i = 0; i < 5; i++)
14484 +               for (j = 0; j < 4; j++)
14485 +                       atomic_set(&cacct->page[i][j], 0);
14486 +}
14487 +
14488 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
14489 +{
14490 +       return;
14491 +}
14492 +
14493 diff -NurpP --minimal linux-4.4.161/kernel/vserver/cacct_proc.h linux-4.4.161-vs2.3.9.8/kernel/vserver/cacct_proc.h
14494 --- linux-4.4.161/kernel/vserver/cacct_proc.h   1970-01-01 00:00:00.000000000 +0000
14495 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/cacct_proc.h 2018-10-20 04:57:21.000000000 +0000
14496 @@ -0,0 +1,53 @@
14497 +#ifndef _VX_CACCT_PROC_H
14498 +#define _VX_CACCT_PROC_H
14499 +
14500 +#include <linux/vserver/cacct_int.h>
14501 +
14502 +
14503 +#define VX_SOCKA_TOP   \
14504 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
14505 +
14506 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
14507 +{
14508 +       int i, j, length = 0;
14509 +       static char *type[VXA_SOCK_SIZE] = {
14510 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
14511 +       };
14512 +
14513 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
14514 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14515 +               length += sprintf(buffer + length, "%s:", type[i]);
14516 +               for (j = 0; j < 3; j++) {
14517 +                       length += sprintf(buffer + length,
14518 +                               "\t%10lu/%-10lu",
14519 +                               vx_sock_count(cacct, i, j),
14520 +                               vx_sock_total(cacct, i, j));
14521 +               }
14522 +               buffer[length++] = '\n';
14523 +       }
14524 +
14525 +       length += sprintf(buffer + length, "\n");
14526 +       length += sprintf(buffer + length,
14527 +               "slab:\t %8u %8u %8u %8u\n",
14528 +               atomic_read(&cacct->slab[1]),
14529 +               atomic_read(&cacct->slab[4]),
14530 +               atomic_read(&cacct->slab[0]),
14531 +               atomic_read(&cacct->slab[2]));
14532 +
14533 +       length += sprintf(buffer + length, "\n");
14534 +       for (i = 0; i < 5; i++) {
14535 +               length += sprintf(buffer + length,
14536 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
14537 +                       atomic_read(&cacct->page[i][0]),
14538 +                       atomic_read(&cacct->page[i][1]),
14539 +                       atomic_read(&cacct->page[i][2]),
14540 +                       atomic_read(&cacct->page[i][3]),
14541 +                       atomic_read(&cacct->page[i][4]),
14542 +                       atomic_read(&cacct->page[i][5]),
14543 +                       atomic_read(&cacct->page[i][6]),
14544 +                       atomic_read(&cacct->page[i][7]));
14545 +       }
14546 +       return length;
14547 +}
14548 +
14549 +#endif /* _VX_CACCT_PROC_H */
14550 diff -NurpP --minimal linux-4.4.161/kernel/vserver/context.c linux-4.4.161-vs2.3.9.8/kernel/vserver/context.c
14551 --- linux-4.4.161/kernel/vserver/context.c      1970-01-01 00:00:00.000000000 +0000
14552 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/context.c    2018-10-20 04:57:21.000000000 +0000
14553 @@ -0,0 +1,1119 @@
14554 +/*
14555 + *  linux/kernel/vserver/context.c
14556 + *
14557 + *  Virtual Server: Context Support
14558 + *
14559 + *  Copyright (C) 2003-2011  Herbert P?tzl
14560 + *
14561 + *  V0.01  context helper
14562 + *  V0.02  vx_ctx_kill syscall command
14563 + *  V0.03  replaced context_info calls
14564 + *  V0.04  redesign of struct (de)alloc
14565 + *  V0.05  rlimit basic implementation
14566 + *  V0.06  task_xid and info commands
14567 + *  V0.07  context flags and caps
14568 + *  V0.08  switch to RCU based hash
14569 + *  V0.09  revert to non RCU for now
14570 + *  V0.10  and back to working RCU hash
14571 + *  V0.11  and back to locking again
14572 + *  V0.12  referenced context store
14573 + *  V0.13  separate per cpu data
14574 + *  V0.14  changed vcmds to vxi arg
14575 + *  V0.15  added context stat
14576 + *  V0.16  have __create claim() the vxi
14577 + *  V0.17  removed older and legacy stuff
14578 + *  V0.18  added user credentials
14579 + *  V0.19  added warn mask
14580 + *
14581 + */
14582 +
14583 +#include <linux/slab.h>
14584 +#include <linux/types.h>
14585 +#include <linux/security.h>
14586 +#include <linux/pid_namespace.h>
14587 +#include <linux/capability.h>
14588 +
14589 +#include <linux/vserver/context.h>
14590 +#include <linux/vserver/network.h>
14591 +#include <linux/vserver/debug.h>
14592 +#include <linux/vserver/limit.h>
14593 +#include <linux/vserver/limit_int.h>
14594 +#include <linux/vserver/space.h>
14595 +#include <linux/init_task.h>
14596 +#include <linux/fs_struct.h>
14597 +#include <linux/cred.h>
14598 +
14599 +#include <linux/vs_context.h>
14600 +#include <linux/vs_limit.h>
14601 +#include <linux/vs_pid.h>
14602 +#include <linux/vserver/context_cmd.h>
14603 +
14604 +#include "cvirt_init.h"
14605 +#include "cacct_init.h"
14606 +#include "limit_init.h"
14607 +#include "sched_init.h"
14608 +
14609 +
14610 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
14611 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
14612 +
14613 +
14614 +/*     now inactive context structures */
14615 +
14616 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
14617 +
14618 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
14619 +
14620 +
14621 +/*     __alloc_vx_info()
14622 +
14623 +       * allocate an initialized vx_info struct
14624 +       * doesn't make it visible (hash)                        */
14625 +
14626 +static struct vx_info *__alloc_vx_info(vxid_t xid)
14627 +{
14628 +       struct vx_info *new = NULL;
14629 +       int cpu, index;
14630 +
14631 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
14632 +
14633 +       /* would this benefit from a slab cache? */
14634 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
14635 +       if (!new)
14636 +               return 0;
14637 +
14638 +       memset(new, 0, sizeof(struct vx_info));
14639 +#ifdef CONFIG_SMP
14640 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
14641 +       if (!new->ptr_pc)
14642 +               goto error;
14643 +#endif
14644 +       new->vx_id = xid;
14645 +       INIT_HLIST_NODE(&new->vx_hlist);
14646 +       atomic_set(&new->vx_usecnt, 0);
14647 +       atomic_set(&new->vx_tasks, 0);
14648 +       new->vx_parent = NULL;
14649 +       new->vx_state = 0;
14650 +       init_waitqueue_head(&new->vx_wait);
14651 +
14652 +       /* prepare reaper */
14653 +       get_task_struct(init_pid_ns.child_reaper);
14654 +       new->vx_reaper = init_pid_ns.child_reaper;
14655 +       new->vx_badness_bias = 0;
14656 +
14657 +       /* rest of init goes here */
14658 +       vx_info_init_limit(&new->limit);
14659 +       vx_info_init_sched(&new->sched);
14660 +       vx_info_init_cvirt(&new->cvirt);
14661 +       vx_info_init_cacct(&new->cacct);
14662 +
14663 +       /* per cpu data structures */
14664 +       for_each_possible_cpu(cpu) {
14665 +               vx_info_init_sched_pc(
14666 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
14667 +               vx_info_init_cvirt_pc(
14668 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
14669 +       }
14670 +
14671 +       new->vx_flags = VXF_INIT_SET;
14672 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
14673 +       new->vx_ccaps = 0;
14674 +       new->vx_umask = 0;
14675 +       new->vx_wmask = 0;
14676 +
14677 +       new->reboot_cmd = 0;
14678 +       new->exit_code = 0;
14679 +
14680 +       // preconfig spaces
14681 +       for (index = 0; index < VX_SPACES; index++) {
14682 +               struct _vx_space *space = &new->space[index];
14683 +
14684 +               // filesystem
14685 +               spin_lock(&init_fs.lock);
14686 +               init_fs.users++;
14687 +               spin_unlock(&init_fs.lock);
14688 +               space->vx_fs = &init_fs;
14689 +
14690 +               /* FIXME: do we want defaults? */
14691 +               // space->vx_real_cred = 0;
14692 +               // space->vx_cred = 0;
14693 +       }
14694 +
14695 +
14696 +       vxdprintk(VXD_CBIT(xid, 0),
14697 +               "alloc_vx_info(%d) = %p", xid, new);
14698 +       vxh_alloc_vx_info(new);
14699 +       atomic_inc(&vx_global_ctotal);
14700 +       return new;
14701 +#ifdef CONFIG_SMP
14702 +error:
14703 +       kfree(new);
14704 +       return 0;
14705 +#endif
14706 +}
14707 +
14708 +/*     __dealloc_vx_info()
14709 +
14710 +       * final disposal of vx_info                             */
14711 +
14712 +static void __dealloc_vx_info(struct vx_info *vxi)
14713 +{
14714 +#ifdef CONFIG_VSERVER_WARN
14715 +       struct vx_info_save vxis;
14716 +       int cpu;
14717 +#endif
14718 +       vxdprintk(VXD_CBIT(xid, 0),
14719 +               "dealloc_vx_info(%p)", vxi);
14720 +       vxh_dealloc_vx_info(vxi);
14721 +
14722 +#ifdef CONFIG_VSERVER_WARN
14723 +       enter_vx_info(vxi, &vxis);
14724 +       vx_info_exit_limit(&vxi->limit);
14725 +       vx_info_exit_sched(&vxi->sched);
14726 +       vx_info_exit_cvirt(&vxi->cvirt);
14727 +       vx_info_exit_cacct(&vxi->cacct);
14728 +
14729 +       for_each_possible_cpu(cpu) {
14730 +               vx_info_exit_sched_pc(
14731 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
14732 +               vx_info_exit_cvirt_pc(
14733 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
14734 +       }
14735 +       leave_vx_info(&vxis);
14736 +#endif
14737 +
14738 +       vxi->vx_id = -1;
14739 +       vxi->vx_state |= VXS_RELEASED;
14740 +
14741 +#ifdef CONFIG_SMP
14742 +       free_percpu(vxi->ptr_pc);
14743 +#endif
14744 +       kfree(vxi);
14745 +       atomic_dec(&vx_global_ctotal);
14746 +}
14747 +
14748 +static void __shutdown_vx_info(struct vx_info *vxi)
14749 +{
14750 +       struct nsproxy *nsproxy;
14751 +       struct fs_struct *fs;
14752 +       struct cred *cred;
14753 +       int index, kill;
14754 +
14755 +       might_sleep();
14756 +
14757 +       vxi->vx_state |= VXS_SHUTDOWN;
14758 +       vs_state_change(vxi, VSC_SHUTDOWN);
14759 +
14760 +       for (index = 0; index < VX_SPACES; index++) {
14761 +               struct _vx_space *space = &vxi->space[index];
14762 +
14763 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
14764 +               if (nsproxy)
14765 +                       put_nsproxy(nsproxy);
14766 +
14767 +               fs = xchg(&space->vx_fs, NULL);
14768 +               spin_lock(&fs->lock);
14769 +               kill = !--fs->users;
14770 +               spin_unlock(&fs->lock);
14771 +               if (kill)
14772 +                       free_fs_struct(fs);
14773 +
14774 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
14775 +               if (cred)
14776 +                       abort_creds(cred);
14777 +       }
14778 +}
14779 +
14780 +/* exported stuff */
14781 +
14782 +void free_vx_info(struct vx_info *vxi)
14783 +{
14784 +       unsigned long flags;
14785 +       unsigned index;
14786 +
14787 +       /* check for reference counts first */
14788 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
14789 +       BUG_ON(atomic_read(&vxi->vx_tasks));
14790 +
14791 +       /* context must not be hashed */
14792 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
14793 +
14794 +       /* context shutdown is mandatory */
14795 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
14796 +
14797 +       /* spaces check */
14798 +       for (index = 0; index < VX_SPACES; index++) {
14799 +               struct _vx_space *space = &vxi->space[index];
14800 +
14801 +               BUG_ON(space->vx_nsproxy);
14802 +               BUG_ON(space->vx_fs);
14803 +               // BUG_ON(space->vx_real_cred);
14804 +               // BUG_ON(space->vx_cred);
14805 +       }
14806 +
14807 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
14808 +       hlist_del(&vxi->vx_hlist);
14809 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
14810 +
14811 +       __dealloc_vx_info(vxi);
14812 +}
14813 +
14814 +
14815 +/*     hash table for vx_info hash */
14816 +
14817 +#define VX_HASH_SIZE   13
14818 +
14819 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
14820 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
14821 +
14822 +static DEFINE_SPINLOCK(vx_info_hash_lock);
14823 +
14824 +
14825 +static inline unsigned int __hashval(vxid_t xid)
14826 +{
14827 +       return (xid % VX_HASH_SIZE);
14828 +}
14829 +
14830 +
14831 +
14832 +/*     __hash_vx_info()
14833 +
14834 +       * add the vxi to the global hash table
14835 +       * requires the hash_lock to be held                     */
14836 +
14837 +static inline void __hash_vx_info(struct vx_info *vxi)
14838 +{
14839 +       struct hlist_head *head;
14840 +
14841 +       vxd_assert_lock(&vx_info_hash_lock);
14842 +       vxdprintk(VXD_CBIT(xid, 4),
14843 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
14844 +       vxh_hash_vx_info(vxi);
14845 +
14846 +       /* context must not be hashed */
14847 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
14848 +
14849 +       vxi->vx_state |= VXS_HASHED;
14850 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
14851 +       hlist_add_head(&vxi->vx_hlist, head);
14852 +       atomic_inc(&vx_global_cactive);
14853 +}
14854 +
14855 +/*     __unhash_vx_info()
14856 +
14857 +       * remove the vxi from the global hash table
14858 +       * requires the hash_lock to be held                     */
14859 +
14860 +static inline void __unhash_vx_info(struct vx_info *vxi)
14861 +{
14862 +       unsigned long flags;
14863 +
14864 +       vxd_assert_lock(&vx_info_hash_lock);
14865 +       vxdprintk(VXD_CBIT(xid, 4),
14866 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
14867 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
14868 +       vxh_unhash_vx_info(vxi);
14869 +
14870 +       /* context must be hashed */
14871 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
14872 +       /* but without tasks */
14873 +       BUG_ON(atomic_read(&vxi->vx_tasks));
14874 +
14875 +       vxi->vx_state &= ~VXS_HASHED;
14876 +       hlist_del_init(&vxi->vx_hlist);
14877 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
14878 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
14879 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
14880 +       atomic_dec(&vx_global_cactive);
14881 +}
14882 +
14883 +
14884 +/*     __lookup_vx_info()
14885 +
14886 +       * requires the hash_lock to be held
14887 +       * doesn't increment the vx_refcnt                       */
14888 +
14889 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
14890 +{
14891 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
14892 +       struct hlist_node *pos;
14893 +       struct vx_info *vxi;
14894 +
14895 +       vxd_assert_lock(&vx_info_hash_lock);
14896 +       hlist_for_each(pos, head) {
14897 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
14898 +
14899 +               if (vxi->vx_id == xid)
14900 +                       goto found;
14901 +       }
14902 +       vxi = NULL;
14903 +found:
14904 +       vxdprintk(VXD_CBIT(xid, 0),
14905 +               "__lookup_vx_info(#%u): %p[#%u]",
14906 +               xid, vxi, vxi ? vxi->vx_id : 0);
14907 +       vxh_lookup_vx_info(vxi, xid);
14908 +       return vxi;
14909 +}
14910 +
14911 +
14912 +/*     __create_vx_info()
14913 +
14914 +       * create the requested context
14915 +       * get(), claim() and hash it                            */
14916 +
14917 +static struct vx_info *__create_vx_info(int id)
14918 +{
14919 +       struct vx_info *new, *vxi = NULL;
14920 +
14921 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
14922 +
14923 +       if (!(new = __alloc_vx_info(id)))
14924 +               return ERR_PTR(-ENOMEM);
14925 +
14926 +       /* required to make dynamic xids unique */
14927 +       spin_lock(&vx_info_hash_lock);
14928 +
14929 +       /* static context requested */
14930 +       if ((vxi = __lookup_vx_info(id))) {
14931 +               vxdprintk(VXD_CBIT(xid, 0),
14932 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
14933 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
14934 +                       vxi = ERR_PTR(-EBUSY);
14935 +               else
14936 +                       vxi = ERR_PTR(-EEXIST);
14937 +               goto out_unlock;
14938 +       }
14939 +       /* new context */
14940 +       vxdprintk(VXD_CBIT(xid, 0),
14941 +               "create_vx_info(%d) = %p (new)", id, new);
14942 +       claim_vx_info(new, NULL);
14943 +       __hash_vx_info(get_vx_info(new));
14944 +       vxi = new, new = NULL;
14945 +
14946 +out_unlock:
14947 +       spin_unlock(&vx_info_hash_lock);
14948 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
14949 +       if (new)
14950 +               __dealloc_vx_info(new);
14951 +       return vxi;
14952 +}
14953 +
14954 +
14955 +/*     exported stuff                                          */
14956 +
14957 +
14958 +void unhash_vx_info(struct vx_info *vxi)
14959 +{
14960 +       spin_lock(&vx_info_hash_lock);
14961 +       __unhash_vx_info(vxi);
14962 +       spin_unlock(&vx_info_hash_lock);
14963 +       __shutdown_vx_info(vxi);
14964 +       __wakeup_vx_info(vxi);
14965 +}
14966 +
14967 +
14968 +/*     lookup_vx_info()
14969 +
14970 +       * search for a vx_info and get() it
14971 +       * negative id means current                             */
14972 +
14973 +struct vx_info *lookup_vx_info(int id)
14974 +{
14975 +       struct vx_info *vxi = NULL;
14976 +
14977 +       if (id < 0) {
14978 +               vxi = get_vx_info(current_vx_info());
14979 +       } else if (id > 1) {
14980 +               spin_lock(&vx_info_hash_lock);
14981 +               vxi = get_vx_info(__lookup_vx_info(id));
14982 +               spin_unlock(&vx_info_hash_lock);
14983 +       }
14984 +       return vxi;
14985 +}
14986 +
14987 +/*     xid_is_hashed()
14988 +
14989 +       * verify that xid is still hashed                       */
14990 +
14991 +int xid_is_hashed(vxid_t xid)
14992 +{
14993 +       int hashed;
14994 +
14995 +       spin_lock(&vx_info_hash_lock);
14996 +       hashed = (__lookup_vx_info(xid) != NULL);
14997 +       spin_unlock(&vx_info_hash_lock);
14998 +       return hashed;
14999 +}
15000 +
15001 +#ifdef CONFIG_PROC_FS
15002 +
15003 +/*     get_xid_list()
15004 +
15005 +       * get a subset of hashed xids for proc
15006 +       * assumes size is at least one                          */
15007 +
15008 +int get_xid_list(int index, unsigned int *xids, int size)
15009 +{
15010 +       int hindex, nr_xids = 0;
15011 +
15012 +       /* only show current and children */
15013 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15014 +               if (index > 0)
15015 +                       return 0;
15016 +               xids[nr_xids] = vx_current_xid();
15017 +               return 1;
15018 +       }
15019 +
15020 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15021 +               struct hlist_head *head = &vx_info_hash[hindex];
15022 +               struct hlist_node *pos;
15023 +
15024 +               spin_lock(&vx_info_hash_lock);
15025 +               hlist_for_each(pos, head) {
15026 +                       struct vx_info *vxi;
15027 +
15028 +                       if (--index > 0)
15029 +                               continue;
15030 +
15031 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15032 +                       xids[nr_xids] = vxi->vx_id;
15033 +                       if (++nr_xids >= size) {
15034 +                               spin_unlock(&vx_info_hash_lock);
15035 +                               goto out;
15036 +                       }
15037 +               }
15038 +               /* keep the lock time short */
15039 +               spin_unlock(&vx_info_hash_lock);
15040 +       }
15041 +out:
15042 +       return nr_xids;
15043 +}
15044 +#endif
15045 +
15046 +#ifdef CONFIG_VSERVER_DEBUG
15047 +
15048 +void   dump_vx_info_inactive(int level)
15049 +{
15050 +       struct hlist_node *entry, *next;
15051 +
15052 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
15053 +               struct vx_info *vxi =
15054 +                       list_entry(entry, struct vx_info, vx_hlist);
15055 +
15056 +               dump_vx_info(vxi, level);
15057 +       }
15058 +}
15059 +
15060 +#endif
15061 +
15062 +#if 0
15063 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
15064 +{
15065 +       struct user_struct *new_user, *old_user;
15066 +
15067 +       if (!p || !vxi)
15068 +               BUG();
15069 +
15070 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
15071 +               return -EACCES;
15072 +
15073 +       new_user = alloc_uid(vxi->vx_id, p->uid);
15074 +       if (!new_user)
15075 +               return -ENOMEM;
15076 +
15077 +       old_user = p->user;
15078 +       if (new_user != old_user) {
15079 +               atomic_inc(&new_user->processes);
15080 +               atomic_dec(&old_user->processes);
15081 +               p->user = new_user;
15082 +       }
15083 +       free_uid(old_user);
15084 +       return 0;
15085 +}
15086 +#endif
15087 +
15088 +#if 0
15089 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
15090 +{
15091 +       // p->cap_effective &= vxi->vx_cap_bset;
15092 +       p->cap_effective =
15093 +               cap_intersect(p->cap_effective, vxi->cap_bset);
15094 +       // p->cap_inheritable &= vxi->vx_cap_bset;
15095 +       p->cap_inheritable =
15096 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
15097 +       // p->cap_permitted &= vxi->vx_cap_bset;
15098 +       p->cap_permitted =
15099 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
15100 +}
15101 +#endif
15102 +
15103 +
15104 +#include <linux/file.h>
15105 +#include <linux/fdtable.h>
15106 +
15107 +static int vx_openfd_task(struct task_struct *tsk)
15108 +{
15109 +       struct files_struct *files = tsk->files;
15110 +       struct fdtable *fdt;
15111 +       const unsigned long *bptr;
15112 +       int count, total;
15113 +
15114 +       /* no rcu_read_lock() because of spin_lock() */
15115 +       spin_lock(&files->file_lock);
15116 +       fdt = files_fdtable(files);
15117 +       bptr = fdt->open_fds;
15118 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
15119 +       for (total = 0; count > 0; count--) {
15120 +               if (*bptr)
15121 +                       total += hweight_long(*bptr);
15122 +               bptr++;
15123 +       }
15124 +       spin_unlock(&files->file_lock);
15125 +       return total;
15126 +}
15127 +
15128 +
15129 +/*     for *space compatibility */
15130 +
15131 +asmlinkage long sys_unshare(unsigned long);
15132 +
15133 +/*
15134 + *     migrate task to new context
15135 + *     gets vxi, puts old_vxi on change
15136 + *     optionally unshares namespaces (hack)
15137 + */
15138 +
15139 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
15140 +{
15141 +       struct vx_info *old_vxi;
15142 +       int ret = 0;
15143 +
15144 +       if (!p || !vxi)
15145 +               BUG();
15146 +
15147 +       vxdprintk(VXD_CBIT(xid, 5),
15148 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
15149 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
15150 +
15151 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
15152 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15153 +               return -EACCES;
15154 +
15155 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
15156 +               return -EFAULT;
15157 +
15158 +       old_vxi = task_get_vx_info(p);
15159 +       if (old_vxi == vxi)
15160 +               goto out;
15161 +
15162 +//     if (!(ret = vx_migrate_user(p, vxi))) {
15163 +       {
15164 +               int openfd;
15165 +
15166 +               task_lock(p);
15167 +               openfd = vx_openfd_task(p);
15168 +
15169 +               if (old_vxi) {
15170 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
15171 +                       atomic_dec(&old_vxi->cvirt.nr_running);
15172 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
15173 +                       /* FIXME: what about the struct files here? */
15174 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
15175 +                       /* account for the executable */
15176 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
15177 +               }
15178 +               atomic_inc(&vxi->cvirt.nr_threads);
15179 +               atomic_inc(&vxi->cvirt.nr_running);
15180 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
15181 +               /* FIXME: what about the struct files here? */
15182 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
15183 +               /* account for the executable */
15184 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
15185 +
15186 +               if (old_vxi) {
15187 +                       release_vx_info(old_vxi, p);
15188 +                       clr_vx_info(&p->vx_info);
15189 +               }
15190 +               claim_vx_info(vxi, p);
15191 +               set_vx_info(&p->vx_info, vxi);
15192 +               p->xid = vxi->vx_id;
15193 +
15194 +               vxdprintk(VXD_CBIT(xid, 5),
15195 +                       "moved task %p into vxi:%p[#%d]",
15196 +                       p, vxi, vxi->vx_id);
15197 +
15198 +               // vx_mask_cap_bset(vxi, p);
15199 +               task_unlock(p);
15200 +
15201 +               /* hack for *spaces to provide compatibility */
15202 +               if (unshare) {
15203 +                       struct nsproxy *old_nsp, *new_nsp;
15204 +
15205 +                       ret = unshare_nsproxy_namespaces(
15206 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
15207 +                               &new_nsp, NULL, NULL);
15208 +                       if (ret)
15209 +                               goto out;
15210 +
15211 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
15212 +                       vx_set_space(vxi,
15213 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
15214 +                       put_nsproxy(old_nsp);
15215 +               }
15216 +       }
15217 +out:
15218 +       put_vx_info(old_vxi);
15219 +       return ret;
15220 +}
15221 +
15222 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
15223 +{
15224 +       struct task_struct *old_reaper;
15225 +       struct vx_info *reaper_vxi;
15226 +
15227 +       if (!vxi)
15228 +               return -EINVAL;
15229 +
15230 +       vxdprintk(VXD_CBIT(xid, 6),
15231 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
15232 +               vxi, vxi->vx_id, p, p->xid, p->pid);
15233 +
15234 +       old_reaper = vxi->vx_reaper;
15235 +       if (old_reaper == p)
15236 +               return 0;
15237 +
15238 +       reaper_vxi = task_get_vx_info(p);
15239 +       if (reaper_vxi && reaper_vxi != vxi) {
15240 +               vxwprintk(1,
15241 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
15242 +                       "for [xid #%u]",
15243 +                       p->comm, p->pid, p->xid, vx_current_xid());
15244 +               goto out;
15245 +       }
15246 +
15247 +       /* set new child reaper */
15248 +       get_task_struct(p);
15249 +       vxi->vx_reaper = p;
15250 +       put_task_struct(old_reaper);
15251 +out:
15252 +       put_vx_info(reaper_vxi);
15253 +       return 0;
15254 +}
15255 +
15256 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
15257 +{
15258 +       if (!vxi)
15259 +               return -EINVAL;
15260 +
15261 +       vxdprintk(VXD_CBIT(xid, 6),
15262 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
15263 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15264 +
15265 +       vxi->vx_flags &= ~VXF_STATE_INIT;
15266 +       // vxi->vx_initpid = p->tgid;
15267 +       vxi->vx_initpid = p->pid;
15268 +       return 0;
15269 +}
15270 +
15271 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
15272 +{
15273 +       vxdprintk(VXD_CBIT(xid, 6),
15274 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
15275 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15276 +
15277 +       vxi->exit_code = code;
15278 +       vxi->vx_initpid = 0;
15279 +}
15280 +
15281 +
15282 +void vx_set_persistent(struct vx_info *vxi)
15283 +{
15284 +       vxdprintk(VXD_CBIT(xid, 6),
15285 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
15286 +
15287 +       get_vx_info(vxi);
15288 +       claim_vx_info(vxi, NULL);
15289 +}
15290 +
15291 +void vx_clear_persistent(struct vx_info *vxi)
15292 +{
15293 +       vxdprintk(VXD_CBIT(xid, 6),
15294 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
15295 +
15296 +       release_vx_info(vxi, NULL);
15297 +       put_vx_info(vxi);
15298 +}
15299 +
15300 +void vx_update_persistent(struct vx_info *vxi)
15301 +{
15302 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
15303 +               vx_set_persistent(vxi);
15304 +       else
15305 +               vx_clear_persistent(vxi);
15306 +}
15307 +
15308 +
15309 +/*     task must be current or locked          */
15310 +
15311 +void   exit_vx_info(struct task_struct *p, int code)
15312 +{
15313 +       struct vx_info *vxi = p->vx_info;
15314 +
15315 +       if (vxi) {
15316 +               atomic_dec(&vxi->cvirt.nr_threads);
15317 +               vx_nproc_dec(p);
15318 +
15319 +               vxi->exit_code = code;
15320 +               release_vx_info(vxi, p);
15321 +       }
15322 +}
15323 +
15324 +void   exit_vx_info_early(struct task_struct *p, int code)
15325 +{
15326 +       struct vx_info *vxi = p->vx_info;
15327 +
15328 +       if (vxi) {
15329 +               if (vxi->vx_initpid == p->pid)
15330 +                       vx_exit_init(vxi, p, code);
15331 +               if (vxi->vx_reaper == p)
15332 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
15333 +       }
15334 +}
15335 +
15336 +
15337 +/* vserver syscall commands below here */
15338 +
15339 +/* taks xid and vx_info functions */
15340 +
15341 +#include <asm/uaccess.h>
15342 +
15343 +
15344 +int vc_task_xid(uint32_t id)
15345 +{
15346 +       vxid_t xid;
15347 +
15348 +       if (id) {
15349 +               struct task_struct *tsk;
15350 +
15351 +               rcu_read_lock();
15352 +               tsk = find_task_by_real_pid(id);
15353 +               xid = (tsk) ? tsk->xid : -ESRCH;
15354 +               rcu_read_unlock();
15355 +       } else
15356 +               xid = vx_current_xid();
15357 +       return xid;
15358 +}
15359 +
15360 +
15361 +int vc_vx_info(struct vx_info *vxi, void __user *data)
15362 +{
15363 +       struct vcmd_vx_info_v0 vc_data;
15364 +
15365 +       vc_data.xid = vxi->vx_id;
15366 +       vc_data.initpid = vxi->vx_initpid;
15367 +
15368 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15369 +               return -EFAULT;
15370 +       return 0;
15371 +}
15372 +
15373 +
15374 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
15375 +{
15376 +       struct vcmd_ctx_stat_v0 vc_data;
15377 +
15378 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
15379 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
15380 +
15381 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15382 +               return -EFAULT;
15383 +       return 0;
15384 +}
15385 +
15386 +
15387 +/* context functions */
15388 +
15389 +int vc_ctx_create(uint32_t xid, void __user *data)
15390 +{
15391 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
15392 +       struct vx_info *new_vxi;
15393 +       int ret;
15394 +
15395 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15396 +               return -EFAULT;
15397 +
15398 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
15399 +               return -EINVAL;
15400 +
15401 +       new_vxi = __create_vx_info(xid);
15402 +       if (IS_ERR(new_vxi))
15403 +               return PTR_ERR(new_vxi);
15404 +
15405 +       /* initial flags */
15406 +       new_vxi->vx_flags = vc_data.flagword;
15407 +
15408 +       ret = -ENOEXEC;
15409 +       if (vs_state_change(new_vxi, VSC_STARTUP))
15410 +               goto out;
15411 +
15412 +       ret = vx_migrate_task(current, new_vxi, (!data));
15413 +       if (ret)
15414 +               goto out;
15415 +
15416 +       /* return context id on success */
15417 +       ret = new_vxi->vx_id;
15418 +
15419 +       /* get a reference for persistent contexts */
15420 +       if ((vc_data.flagword & VXF_PERSISTENT))
15421 +               vx_set_persistent(new_vxi);
15422 +out:
15423 +       release_vx_info(new_vxi, NULL);
15424 +       put_vx_info(new_vxi);
15425 +       return ret;
15426 +}
15427 +
15428 +
15429 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
15430 +{
15431 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
15432 +       int ret;
15433 +
15434 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15435 +               return -EFAULT;
15436 +
15437 +       ret = vx_migrate_task(current, vxi, 0);
15438 +       if (ret)
15439 +               return ret;
15440 +       if (vc_data.flagword & VXM_SET_INIT)
15441 +               ret = vx_set_init(vxi, current);
15442 +       if (ret)
15443 +               return ret;
15444 +       if (vc_data.flagword & VXM_SET_REAPER)
15445 +               ret = vx_set_reaper(vxi, current);
15446 +       return ret;
15447 +}
15448 +
15449 +
15450 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
15451 +{
15452 +       struct vcmd_ctx_flags_v0 vc_data;
15453 +
15454 +       vc_data.flagword = vxi->vx_flags;
15455 +
15456 +       /* special STATE flag handling */
15457 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
15458 +
15459 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15460 +               return -EFAULT;
15461 +       return 0;
15462 +}
15463 +
15464 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
15465 +{
15466 +       struct vcmd_ctx_flags_v0 vc_data;
15467 +       uint64_t mask, trigger;
15468 +
15469 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15470 +               return -EFAULT;
15471 +
15472 +       /* special STATE flag handling */
15473 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
15474 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
15475 +
15476 +       if (vxi == current_vx_info()) {
15477 +               /* if (trigger & VXF_STATE_SETUP)
15478 +                       vx_mask_cap_bset(vxi, current); */
15479 +               if (trigger & VXF_STATE_INIT) {
15480 +                       int ret;
15481 +
15482 +                       ret = vx_set_init(vxi, current);
15483 +                       if (ret)
15484 +                               return ret;
15485 +                       ret = vx_set_reaper(vxi, current);
15486 +                       if (ret)
15487 +                               return ret;
15488 +               }
15489 +       }
15490 +
15491 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
15492 +               vc_data.flagword, mask);
15493 +       if (trigger & VXF_PERSISTENT)
15494 +               vx_update_persistent(vxi);
15495 +
15496 +       return 0;
15497 +}
15498 +
15499 +
15500 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
15501 +{
15502 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
15503 +
15504 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
15505 +       return v;
15506 +}
15507 +
15508 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
15509 +{
15510 +       kernel_cap_t c = __cap_empty_set;
15511 +
15512 +       c.cap[0] = v & 0xFFFFFFFF;
15513 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
15514 +
15515 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
15516 +       return c;
15517 +}
15518 +
15519 +
15520 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
15521 +{
15522 +       if (bcaps)
15523 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
15524 +       if (ccaps)
15525 +               *ccaps = vxi->vx_ccaps;
15526 +
15527 +       return 0;
15528 +}
15529 +
15530 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
15531 +{
15532 +       struct vcmd_ctx_caps_v1 vc_data;
15533 +       int ret;
15534 +
15535 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
15536 +       if (ret)
15537 +               return ret;
15538 +       vc_data.cmask = ~0ULL;
15539 +
15540 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15541 +               return -EFAULT;
15542 +       return 0;
15543 +}
15544 +
15545 +static int do_set_caps(struct vx_info *vxi,
15546 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
15547 +{
15548 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
15549 +
15550 +#if 0
15551 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
15552 +               bcaps, bmask, ccaps, cmask);
15553 +#endif
15554 +       vxi->vx_bcaps = cap_t_from_caps(
15555 +               vs_mask_flags(bcold, bcaps, bmask));
15556 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
15557 +
15558 +       return 0;
15559 +}
15560 +
15561 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
15562 +{
15563 +       struct vcmd_ctx_caps_v1 vc_data;
15564 +
15565 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15566 +               return -EFAULT;
15567 +
15568 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
15569 +}
15570 +
15571 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
15572 +{
15573 +       struct vcmd_bcaps vc_data;
15574 +       int ret;
15575 +
15576 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
15577 +       if (ret)
15578 +               return ret;
15579 +       vc_data.bmask = ~0ULL;
15580 +
15581 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15582 +               return -EFAULT;
15583 +       return 0;
15584 +}
15585 +
15586 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
15587 +{
15588 +       struct vcmd_bcaps vc_data;
15589 +
15590 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15591 +               return -EFAULT;
15592 +
15593 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
15594 +}
15595 +
15596 +
15597 +int vc_get_umask(struct vx_info *vxi, void __user *data)
15598 +{
15599 +       struct vcmd_umask vc_data;
15600 +
15601 +       vc_data.umask = vxi->vx_umask;
15602 +       vc_data.mask = ~0ULL;
15603 +
15604 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15605 +               return -EFAULT;
15606 +       return 0;
15607 +}
15608 +
15609 +int vc_set_umask(struct vx_info *vxi, void __user *data)
15610 +{
15611 +       struct vcmd_umask vc_data;
15612 +
15613 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15614 +               return -EFAULT;
15615 +
15616 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
15617 +               vc_data.umask, vc_data.mask);
15618 +       return 0;
15619 +}
15620 +
15621 +
15622 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
15623 +{
15624 +       struct vcmd_wmask vc_data;
15625 +
15626 +       vc_data.wmask = vxi->vx_wmask;
15627 +       vc_data.mask = ~0ULL;
15628 +
15629 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15630 +               return -EFAULT;
15631 +       return 0;
15632 +}
15633 +
15634 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
15635 +{
15636 +       struct vcmd_wmask vc_data;
15637 +
15638 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15639 +               return -EFAULT;
15640 +
15641 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
15642 +               vc_data.wmask, vc_data.mask);
15643 +       return 0;
15644 +}
15645 +
15646 +
15647 +int vc_get_badness(struct vx_info *vxi, void __user *data)
15648 +{
15649 +       struct vcmd_badness_v0 vc_data;
15650 +
15651 +       vc_data.bias = vxi->vx_badness_bias;
15652 +
15653 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15654 +               return -EFAULT;
15655 +       return 0;
15656 +}
15657 +
15658 +int vc_set_badness(struct vx_info *vxi, void __user *data)
15659 +{
15660 +       struct vcmd_badness_v0 vc_data;
15661 +
15662 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15663 +               return -EFAULT;
15664 +
15665 +       vxi->vx_badness_bias = vc_data.bias;
15666 +       return 0;
15667 +}
15668 +
15669 +#include <linux/module.h>
15670 +
15671 +EXPORT_SYMBOL_GPL(free_vx_info);
15672 +
15673 diff -NurpP --minimal linux-4.4.161/kernel/vserver/cvirt.c linux-4.4.161-vs2.3.9.8/kernel/vserver/cvirt.c
15674 --- linux-4.4.161/kernel/vserver/cvirt.c        1970-01-01 00:00:00.000000000 +0000
15675 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/cvirt.c      2018-10-20 04:57:21.000000000 +0000
15676 @@ -0,0 +1,313 @@
15677 +/*
15678 + *  linux/kernel/vserver/cvirt.c
15679 + *
15680 + *  Virtual Server: Context Virtualization
15681 + *
15682 + *  Copyright (C) 2004-2007  Herbert P?tzl
15683 + *
15684 + *  V0.01  broken out from limit.c
15685 + *  V0.02  added utsname stuff
15686 + *  V0.03  changed vcmds to vxi arg
15687 + *
15688 + */
15689 +
15690 +#include <linux/types.h>
15691 +#include <linux/utsname.h>
15692 +#include <linux/vs_cvirt.h>
15693 +#include <linux/vserver/switch.h>
15694 +#include <linux/vserver/cvirt_cmd.h>
15695 +
15696 +#include <asm/uaccess.h>
15697 +
15698 +
15699 +void vx_vsi_boottime(struct timespec *boottime)
15700 +{
15701 +       struct vx_info *vxi = current_vx_info();
15702 +
15703 +       set_normalized_timespec(boottime,
15704 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
15705 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
15706 +       return;
15707 +}
15708 +
15709 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
15710 +{
15711 +       struct vx_info *vxi = current_vx_info();
15712 +
15713 +       set_normalized_timespec(uptime,
15714 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
15715 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
15716 +       if (!idle)
15717 +               return;
15718 +       set_normalized_timespec(idle,
15719 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
15720 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
15721 +       return;
15722 +}
15723 +
15724 +uint64_t vx_idle_jiffies(void)
15725 +{
15726 +       return init_task.utime + init_task.stime;
15727 +}
15728 +
15729 +
15730 +
15731 +static inline uint32_t __update_loadavg(uint32_t load,
15732 +       int wsize, int delta, int n)
15733 +{
15734 +       unsigned long long calc, prev;
15735 +
15736 +       /* just set it to n */
15737 +       if (unlikely(delta >= wsize))
15738 +               return (n << FSHIFT);
15739 +
15740 +       calc = delta * n;
15741 +       calc <<= FSHIFT;
15742 +       prev = (wsize - delta);
15743 +       prev *= load;
15744 +       calc += prev;
15745 +       do_div(calc, wsize);
15746 +       return calc;
15747 +}
15748 +
15749 +
15750 +void vx_update_load(struct vx_info *vxi)
15751 +{
15752 +       uint32_t now, last, delta;
15753 +       unsigned int nr_running, nr_uninterruptible;
15754 +       unsigned int total;
15755 +       unsigned long flags;
15756 +
15757 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
15758 +
15759 +       now = jiffies;
15760 +       last = vxi->cvirt.load_last;
15761 +       delta = now - last;
15762 +
15763 +       if (delta < 5*HZ)
15764 +               goto out;
15765 +
15766 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
15767 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
15768 +       total = nr_running + nr_uninterruptible;
15769 +
15770 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
15771 +               60*HZ, delta, total);
15772 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
15773 +               5*60*HZ, delta, total);
15774 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
15775 +               15*60*HZ, delta, total);
15776 +
15777 +       vxi->cvirt.load_last = now;
15778 +out:
15779 +       atomic_inc(&vxi->cvirt.load_updates);
15780 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
15781 +}
15782 +
15783 +
15784 +/*
15785 + * Commands to do_syslog:
15786 + *
15787 + *      0 -- Close the log.  Currently a NOP.
15788 + *      1 -- Open the log. Currently a NOP.
15789 + *      2 -- Read from the log.
15790 + *      3 -- Read all messages remaining in the ring buffer.
15791 + *      4 -- Read and clear all messages remaining in the ring buffer
15792 + *      5 -- Clear ring buffer.
15793 + *      6 -- Disable printk's to console
15794 + *      7 -- Enable printk's to console
15795 + *      8 -- Set level of messages printed to console
15796 + *      9 -- Return number of unread characters in the log buffer
15797 + *     10 -- Return size of the log buffer
15798 + */
15799 +int vx_do_syslog(int type, char __user *buf, int len)
15800 +{
15801 +       int error = 0;
15802 +       int do_clear = 0;
15803 +       struct vx_info *vxi = current_vx_info();
15804 +       struct _vx_syslog *log;
15805 +
15806 +       if (!vxi)
15807 +               return -EINVAL;
15808 +       log = &vxi->cvirt.syslog;
15809 +
15810 +       switch (type) {
15811 +       case 0:         /* Close log */
15812 +       case 1:         /* Open log */
15813 +               break;
15814 +       case 2:         /* Read from log */
15815 +               error = wait_event_interruptible(log->log_wait,
15816 +                       (log->log_start - log->log_end));
15817 +               if (error)
15818 +                       break;
15819 +               spin_lock_irq(&log->logbuf_lock);
15820 +               spin_unlock_irq(&log->logbuf_lock);
15821 +               break;
15822 +       case 4:         /* Read/clear last kernel messages */
15823 +               do_clear = 1;
15824 +               /* fall through */
15825 +       case 3:         /* Read last kernel messages */
15826 +               return 0;
15827 +
15828 +       case 5:         /* Clear ring buffer */
15829 +               return 0;
15830 +
15831 +       case 6:         /* Disable logging to console */
15832 +       case 7:         /* Enable logging to console */
15833 +       case 8:         /* Set level of messages printed to console */
15834 +               break;
15835 +
15836 +       case 9:         /* Number of chars in the log buffer */
15837 +               return 0;
15838 +       case 10:        /* Size of the log buffer */
15839 +               return 0;
15840 +       default:
15841 +               error = -EINVAL;
15842 +               break;
15843 +       }
15844 +       return error;
15845 +}
15846 +
15847 +
15848 +/* virtual host info names */
15849 +
15850 +static char *vx_vhi_name(struct vx_info *vxi, int id)
15851 +{
15852 +       struct nsproxy *nsproxy;
15853 +       struct uts_namespace *uts;
15854 +
15855 +       if (id == VHIN_CONTEXT)
15856 +               return vxi->vx_name;
15857 +
15858 +       nsproxy = vxi->space[0].vx_nsproxy;
15859 +       if (!nsproxy)
15860 +               return NULL;
15861 +
15862 +       uts = nsproxy->uts_ns;
15863 +       if (!uts)
15864 +               return NULL;
15865 +
15866 +       switch (id) {
15867 +       case VHIN_SYSNAME:
15868 +               return uts->name.sysname;
15869 +       case VHIN_NODENAME:
15870 +               return uts->name.nodename;
15871 +       case VHIN_RELEASE:
15872 +               return uts->name.release;
15873 +       case VHIN_VERSION:
15874 +               return uts->name.version;
15875 +       case VHIN_MACHINE:
15876 +               return uts->name.machine;
15877 +       case VHIN_DOMAINNAME:
15878 +               return uts->name.domainname;
15879 +       default:
15880 +               return NULL;
15881 +       }
15882 +       return NULL;
15883 +}
15884 +
15885 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
15886 +{
15887 +       struct vcmd_vhi_name_v0 vc_data;
15888 +       char *name;
15889 +
15890 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15891 +               return -EFAULT;
15892 +
15893 +       name = vx_vhi_name(vxi, vc_data.field);
15894 +       if (!name)
15895 +               return -EINVAL;
15896 +
15897 +       memcpy(name, vc_data.name, 65);
15898 +       return 0;
15899 +}
15900 +
15901 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
15902 +{
15903 +       struct vcmd_vhi_name_v0 vc_data;
15904 +       char *name;
15905 +
15906 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15907 +               return -EFAULT;
15908 +
15909 +       name = vx_vhi_name(vxi, vc_data.field);
15910 +       if (!name)
15911 +               return -EINVAL;
15912 +
15913 +       memcpy(vc_data.name, name, 65);
15914 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15915 +               return -EFAULT;
15916 +       return 0;
15917 +}
15918 +
15919 +
15920 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
15921 +{
15922 +       struct vcmd_virt_stat_v0 vc_data;
15923 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
15924 +       struct timespec uptime;
15925 +
15926 +       ktime_get_ts(&uptime);
15927 +       set_normalized_timespec(&uptime,
15928 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
15929 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
15930 +
15931 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
15932 +       vc_data.uptime = timespec_to_ns(&uptime);
15933 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
15934 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
15935 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
15936 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
15937 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
15938 +       vc_data.load[0] = cvirt->load[0];
15939 +       vc_data.load[1] = cvirt->load[1];
15940 +       vc_data.load[2] = cvirt->load[2];
15941 +
15942 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15943 +               return -EFAULT;
15944 +       return 0;
15945 +}
15946 +
15947 +
15948 +#ifdef CONFIG_VSERVER_VTIME
15949 +
15950 +/* virtualized time base */
15951 +
15952 +void vx_adjust_timespec(struct timespec *ts)
15953 +{
15954 +       struct vx_info *vxi;
15955 +
15956 +       if (!vx_flags(VXF_VIRT_TIME, 0))
15957 +               return;
15958 +
15959 +       vxi = current_vx_info();
15960 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
15961 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
15962 +
15963 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
15964 +               ts->tv_sec++;
15965 +               ts->tv_nsec -= NSEC_PER_SEC;
15966 +       } else if (ts->tv_nsec < 0) {
15967 +               ts->tv_sec--;
15968 +               ts->tv_nsec += NSEC_PER_SEC;
15969 +       }
15970 +}
15971 +
15972 +int vx_settimeofday(const struct timespec *ts)
15973 +{
15974 +       struct timespec ats, delta;
15975 +       struct vx_info *vxi;
15976 +
15977 +       if (!vx_flags(VXF_VIRT_TIME, 0))
15978 +               return do_settimeofday(ts);
15979 +
15980 +       getnstimeofday(&ats);
15981 +       delta = timespec_sub(*ts, ats);
15982 +
15983 +       vxi = current_vx_info();
15984 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
15985 +       return 0;
15986 +}
15987 +
15988 +#endif
15989 +
15990 diff -NurpP --minimal linux-4.4.161/kernel/vserver/cvirt_init.h linux-4.4.161-vs2.3.9.8/kernel/vserver/cvirt_init.h
15991 --- linux-4.4.161/kernel/vserver/cvirt_init.h   1970-01-01 00:00:00.000000000 +0000
15992 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/cvirt_init.h 2018-10-20 04:57:21.000000000 +0000
15993 @@ -0,0 +1,70 @@
15994 +
15995 +
15996 +extern uint64_t vx_idle_jiffies(void);
15997 +
15998 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
15999 +{
16000 +       uint64_t idle_jiffies = vx_idle_jiffies();
16001 +       uint64_t nsuptime;
16002 +
16003 +       ktime_get_ts(&cvirt->bias_uptime);
16004 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16005 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16006 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16007 +       cvirt->bias_ts.tv_sec = 0;
16008 +       cvirt->bias_ts.tv_nsec = 0;
16009 +
16010 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16011 +       atomic_set(&cvirt->nr_threads, 0);
16012 +       atomic_set(&cvirt->nr_running, 0);
16013 +       atomic_set(&cvirt->nr_uninterruptible, 0);
16014 +       atomic_set(&cvirt->nr_onhold, 0);
16015 +
16016 +       spin_lock_init(&cvirt->load_lock);
16017 +       cvirt->load_last = jiffies;
16018 +       atomic_set(&cvirt->load_updates, 0);
16019 +       cvirt->load[0] = 0;
16020 +       cvirt->load[1] = 0;
16021 +       cvirt->load[2] = 0;
16022 +       atomic_set(&cvirt->total_forks, 0);
16023 +
16024 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
16025 +       init_waitqueue_head(&cvirt->syslog.log_wait);
16026 +       cvirt->syslog.log_start = 0;
16027 +       cvirt->syslog.log_end = 0;
16028 +       cvirt->syslog.con_start = 0;
16029 +       cvirt->syslog.logged_chars = 0;
16030 +}
16031 +
16032 +static inline
16033 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16034 +{
16035 +       // cvirt_pc->cpustat = { 0 };
16036 +}
16037 +
16038 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16039 +{
16040 +#ifdef CONFIG_VSERVER_WARN
16041 +       int value;
16042 +#endif
16043 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16044 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
16045 +               cvirt, value);
16046 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16047 +               "!!! cvirt: %p[nr_running] = %d on exit.",
16048 +               cvirt, value);
16049 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16050 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16051 +               cvirt, value);
16052 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16053 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
16054 +               cvirt, value);
16055 +       return;
16056 +}
16057 +
16058 +static inline
16059 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16060 +{
16061 +       return;
16062 +}
16063 +
16064 diff -NurpP --minimal linux-4.4.161/kernel/vserver/cvirt_proc.h linux-4.4.161-vs2.3.9.8/kernel/vserver/cvirt_proc.h
16065 --- linux-4.4.161/kernel/vserver/cvirt_proc.h   1970-01-01 00:00:00.000000000 +0000
16066 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/cvirt_proc.h 2018-10-20 04:57:21.000000000 +0000
16067 @@ -0,0 +1,123 @@
16068 +#ifndef _VX_CVIRT_PROC_H
16069 +#define _VX_CVIRT_PROC_H
16070 +
16071 +#include <linux/nsproxy.h>
16072 +#include <linux/mnt_namespace.h>
16073 +#include <linux/ipc_namespace.h>
16074 +#include <linux/utsname.h>
16075 +#include <linux/ipc.h>
16076 +
16077 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
16078 +
16079 +static inline
16080 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
16081 +{
16082 +       struct mnt_namespace *ns;
16083 +       struct uts_namespace *uts;
16084 +       struct ipc_namespace *ipc;
16085 +       int length = 0;
16086 +
16087 +       if (!nsproxy)
16088 +               goto out;
16089 +
16090 +       length += sprintf(buffer + length,
16091 +               "NSProxy:\t%p [%p,%p,%p]\n",
16092 +               nsproxy, nsproxy->mnt_ns,
16093 +               nsproxy->uts_ns, nsproxy->ipc_ns);
16094 +
16095 +       ns = nsproxy->mnt_ns;
16096 +       if (!ns)
16097 +               goto skip_ns;
16098 +
16099 +       length += vx_info_mnt_namespace(ns, buffer + length);
16100 +
16101 +skip_ns:
16102 +
16103 +       uts = nsproxy->uts_ns;
16104 +       if (!uts)
16105 +               goto skip_uts;
16106 +
16107 +       length += sprintf(buffer + length,
16108 +               "SysName:\t%.*s\n"
16109 +               "NodeName:\t%.*s\n"
16110 +               "Release:\t%.*s\n"
16111 +               "Version:\t%.*s\n"
16112 +               "Machine:\t%.*s\n"
16113 +               "DomainName:\t%.*s\n",
16114 +               __NEW_UTS_LEN, uts->name.sysname,
16115 +               __NEW_UTS_LEN, uts->name.nodename,
16116 +               __NEW_UTS_LEN, uts->name.release,
16117 +               __NEW_UTS_LEN, uts->name.version,
16118 +               __NEW_UTS_LEN, uts->name.machine,
16119 +               __NEW_UTS_LEN, uts->name.domainname);
16120 +skip_uts:
16121 +
16122 +       ipc = nsproxy->ipc_ns;
16123 +       if (!ipc)
16124 +               goto skip_ipc;
16125 +
16126 +       length += sprintf(buffer + length,
16127 +               "SEMS:\t\t%d %d %d %d  %d\n"
16128 +               "MSG:\t\t%d %d %d\n"
16129 +               "SHM:\t\t%lu %lu  %d %ld\n",
16130 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
16131 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
16132 +               ipc->used_sems,
16133 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
16134 +               (unsigned long)ipc->shm_ctlmax,
16135 +               (unsigned long)ipc->shm_ctlall,
16136 +               ipc->shm_ctlmni, ipc->shm_tot);
16137 +skip_ipc:
16138 +out:
16139 +       return length;
16140 +}
16141 +
16142 +
16143 +#include <linux/sched.h>
16144 +
16145 +#define LOAD_INT(x) ((x) >> FSHIFT)
16146 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
16147 +
16148 +static inline
16149 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
16150 +{
16151 +       int length = 0;
16152 +       int a, b, c;
16153 +
16154 +       length += sprintf(buffer + length,
16155 +               "BiasUptime:\t%lu.%02lu\n",
16156 +               (unsigned long)cvirt->bias_uptime.tv_sec,
16157 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
16158 +
16159 +       a = cvirt->load[0] + (FIXED_1 / 200);
16160 +       b = cvirt->load[1] + (FIXED_1 / 200);
16161 +       c = cvirt->load[2] + (FIXED_1 / 200);
16162 +       length += sprintf(buffer + length,
16163 +               "nr_threads:\t%d\n"
16164 +               "nr_running:\t%d\n"
16165 +               "nr_unintr:\t%d\n"
16166 +               "nr_onhold:\t%d\n"
16167 +               "load_updates:\t%d\n"
16168 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
16169 +               "total_forks:\t%d\n",
16170 +               atomic_read(&cvirt->nr_threads),
16171 +               atomic_read(&cvirt->nr_running),
16172 +               atomic_read(&cvirt->nr_uninterruptible),
16173 +               atomic_read(&cvirt->nr_onhold),
16174 +               atomic_read(&cvirt->load_updates),
16175 +               LOAD_INT(a), LOAD_FRAC(a),
16176 +               LOAD_INT(b), LOAD_FRAC(b),
16177 +               LOAD_INT(c), LOAD_FRAC(c),
16178 +               atomic_read(&cvirt->total_forks));
16179 +       return length;
16180 +}
16181 +
16182 +static inline
16183 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
16184 +       char *buffer, int cpu)
16185 +{
16186 +       int length = 0;
16187 +       return length;
16188 +}
16189 +
16190 +#endif /* _VX_CVIRT_PROC_H */
16191 diff -NurpP --minimal linux-4.4.161/kernel/vserver/debug.c linux-4.4.161-vs2.3.9.8/kernel/vserver/debug.c
16192 --- linux-4.4.161/kernel/vserver/debug.c        1970-01-01 00:00:00.000000000 +0000
16193 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/debug.c      2018-10-20 04:57:21.000000000 +0000
16194 @@ -0,0 +1,32 @@
16195 +/*
16196 + *  kernel/vserver/debug.c
16197 + *
16198 + *  Copyright (C) 2005-2007 Herbert P?tzl
16199 + *
16200 + *  V0.01  vx_info dump support
16201 + *
16202 + */
16203 +
16204 +#include <linux/module.h>
16205 +
16206 +#include <linux/vserver/context.h>
16207 +
16208 +
16209 +void   dump_vx_info(struct vx_info *vxi, int level)
16210 +{
16211 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
16212 +               atomic_read(&vxi->vx_usecnt),
16213 +               atomic_read(&vxi->vx_tasks),
16214 +               vxi->vx_state);
16215 +       if (level > 0) {
16216 +               __dump_vx_limit(&vxi->limit);
16217 +               __dump_vx_sched(&vxi->sched);
16218 +               __dump_vx_cvirt(&vxi->cvirt);
16219 +               __dump_vx_cacct(&vxi->cacct);
16220 +       }
16221 +       printk("---\n");
16222 +}
16223 +
16224 +
16225 +EXPORT_SYMBOL_GPL(dump_vx_info);
16226 +
16227 diff -NurpP --minimal linux-4.4.161/kernel/vserver/device.c linux-4.4.161-vs2.3.9.8/kernel/vserver/device.c
16228 --- linux-4.4.161/kernel/vserver/device.c       1970-01-01 00:00:00.000000000 +0000
16229 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/device.c     2018-10-20 04:57:21.000000000 +0000
16230 @@ -0,0 +1,443 @@
16231 +/*
16232 + *  linux/kernel/vserver/device.c
16233 + *
16234 + *  Linux-VServer: Device Support
16235 + *
16236 + *  Copyright (C) 2006  Herbert P?tzl
16237 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
16238 + *
16239 + *  V0.01  device mapping basics
16240 + *  V0.02  added defaults
16241 + *
16242 + */
16243 +
16244 +#include <linux/slab.h>
16245 +#include <linux/rcupdate.h>
16246 +#include <linux/fs.h>
16247 +#include <linux/namei.h>
16248 +#include <linux/hash.h>
16249 +
16250 +#include <asm/errno.h>
16251 +#include <asm/uaccess.h>
16252 +#include <linux/vserver/base.h>
16253 +#include <linux/vserver/debug.h>
16254 +#include <linux/vserver/context.h>
16255 +#include <linux/vserver/device.h>
16256 +#include <linux/vserver/device_cmd.h>
16257 +
16258 +
16259 +#define DMAP_HASH_BITS 4
16260 +
16261 +
16262 +struct vs_mapping {
16263 +       union {
16264 +               struct hlist_node hlist;
16265 +               struct list_head list;
16266 +       } u;
16267 +#define dm_hlist       u.hlist
16268 +#define dm_list                u.list
16269 +       vxid_t xid;
16270 +       dev_t device;
16271 +       struct vx_dmap_target target;
16272 +};
16273 +
16274 +
16275 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
16276 +
16277 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
16278 +
16279 +static struct vx_dmap_target dmap_defaults[2] = {
16280 +       { .flags = DATTR_OPEN },
16281 +       { .flags = DATTR_OPEN },
16282 +};
16283 +
16284 +
16285 +struct kmem_cache *dmap_cachep __read_mostly;
16286 +
16287 +int __init dmap_cache_init(void)
16288 +{
16289 +       dmap_cachep = kmem_cache_create("dmap_cache",
16290 +               sizeof(struct vs_mapping), 0,
16291 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
16292 +       return 0;
16293 +}
16294 +
16295 +__initcall(dmap_cache_init);
16296 +
16297 +
16298 +static inline unsigned int __hashval(dev_t dev, int bits)
16299 +{
16300 +       return hash_long((unsigned long)dev, bits);
16301 +}
16302 +
16303 +
16304 +/*     __hash_mapping()
16305 + *     add the mapping to the hash table
16306 + */
16307 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
16308 +{
16309 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16310 +       struct hlist_head *head, *hash = dmap_main_hash;
16311 +       int device = vdm->device;
16312 +
16313 +       spin_lock(hash_lock);
16314 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
16315 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
16316 +
16317 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
16318 +       hlist_add_head(&vdm->dm_hlist, head);
16319 +       spin_unlock(hash_lock);
16320 +}
16321 +
16322 +
16323 +static inline int __mode_to_default(umode_t mode)
16324 +{
16325 +       switch (mode) {
16326 +       case S_IFBLK:
16327 +               return 0;
16328 +       case S_IFCHR:
16329 +               return 1;
16330 +       default:
16331 +               BUG();
16332 +       }
16333 +}
16334 +
16335 +
16336 +/*     __set_default()
16337 + *     set a default
16338 + */
16339 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
16340 +       struct vx_dmap_target *vdmt)
16341 +{
16342 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16343 +       spin_lock(hash_lock);
16344 +
16345 +       if (vxi)
16346 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
16347 +       else
16348 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
16349 +
16350 +
16351 +       spin_unlock(hash_lock);
16352 +
16353 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
16354 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
16355 +}
16356 +
16357 +
16358 +/*     __remove_default()
16359 + *     remove a default
16360 + */
16361 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
16362 +{
16363 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16364 +       spin_lock(hash_lock);
16365 +
16366 +       if (vxi)
16367 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
16368 +       else    /* remove == reset */
16369 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
16370 +
16371 +       spin_unlock(hash_lock);
16372 +       return 0;
16373 +}
16374 +
16375 +
16376 +/*     __find_mapping()
16377 + *     find a mapping in the hash table
16378 + *
16379 + *     caller must hold hash_lock
16380 + */
16381 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
16382 +       struct vs_mapping **local, struct vs_mapping **global)
16383 +{
16384 +       struct hlist_head *hash = dmap_main_hash;
16385 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
16386 +       struct hlist_node *pos;
16387 +       struct vs_mapping *vdm;
16388 +
16389 +       *local = NULL;
16390 +       if (global)
16391 +               *global = NULL;
16392 +
16393 +       hlist_for_each(pos, head) {
16394 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
16395 +
16396 +               if ((vdm->device == device) &&
16397 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
16398 +                       if (vdm->xid == xid) {
16399 +                               *local = vdm;
16400 +                               return 1;
16401 +                       } else if (global && vdm->xid == 0)
16402 +                               *global = vdm;
16403 +               }
16404 +       }
16405 +
16406 +       if (global && *global)
16407 +               return 0;
16408 +       else
16409 +               return -ENOENT;
16410 +}
16411 +
16412 +
16413 +/*     __lookup_mapping()
16414 + *     find a mapping and store the result in target and flags
16415 + */
16416 +static inline int __lookup_mapping(struct vx_info *vxi,
16417 +       dev_t device, dev_t *target, int *flags, umode_t mode)
16418 +{
16419 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16420 +       struct vs_mapping *vdm, *global;
16421 +       struct vx_dmap_target *vdmt;
16422 +       int ret = 0;
16423 +       vxid_t xid = vxi->vx_id;
16424 +       int index;
16425 +
16426 +       spin_lock(hash_lock);
16427 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
16428 +               ret = 1;
16429 +               vdmt = &vdm->target;
16430 +               goto found;
16431 +       }
16432 +
16433 +       index = __mode_to_default(mode);
16434 +       if (vxi && vxi->dmap.targets[index].flags) {
16435 +               ret = 2;
16436 +               vdmt = &vxi->dmap.targets[index];
16437 +       } else if (global) {
16438 +               ret = 3;
16439 +               vdmt = &global->target;
16440 +               goto found;
16441 +       } else {
16442 +               ret = 4;
16443 +               vdmt = &dmap_defaults[index];
16444 +       }
16445 +
16446 +found:
16447 +       if (target && (vdmt->flags & DATTR_REMAP))
16448 +               *target = vdmt->target;
16449 +       else if (target)
16450 +               *target = device;
16451 +       if (flags)
16452 +               *flags = vdmt->flags;
16453 +
16454 +       spin_unlock(hash_lock);
16455 +
16456 +       return ret;
16457 +}
16458 +
16459 +
16460 +/*     __remove_mapping()
16461 + *     remove a mapping from the hash table
16462 + */
16463 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
16464 +       umode_t mode)
16465 +{
16466 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16467 +       struct vs_mapping *vdm = NULL;
16468 +       int ret = 0;
16469 +
16470 +       spin_lock(hash_lock);
16471 +
16472 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
16473 +               NULL);
16474 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
16475 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
16476 +       if (ret < 0)
16477 +               goto out;
16478 +       hlist_del(&vdm->dm_hlist);
16479 +
16480 +out:
16481 +       spin_unlock(hash_lock);
16482 +       if (vdm)
16483 +               kmem_cache_free(dmap_cachep, vdm);
16484 +       return ret;
16485 +}
16486 +
16487 +
16488 +
16489 +int vs_map_device(struct vx_info *vxi,
16490 +       dev_t device, dev_t *target, umode_t mode)
16491 +{
16492 +       int ret, flags = DATTR_MASK;
16493 +
16494 +       if (!vxi) {
16495 +               if (target)
16496 +                       *target = device;
16497 +               goto out;
16498 +       }
16499 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
16500 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
16501 +               device, target ? *target : 0, flags, mode, ret);
16502 +out:
16503 +       return (flags & DATTR_MASK);
16504 +}
16505 +
16506 +
16507 +
16508 +static int do_set_mapping(struct vx_info *vxi,
16509 +       dev_t device, dev_t target, int flags, umode_t mode)
16510 +{
16511 +       if (device) {
16512 +               struct vs_mapping *new;
16513 +
16514 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
16515 +               if (!new)
16516 +                       return -ENOMEM;
16517 +
16518 +               INIT_HLIST_NODE(&new->dm_hlist);
16519 +               new->device = device;
16520 +               new->target.target = target;
16521 +               new->target.flags = flags | mode;
16522 +               new->xid = (vxi ? vxi->vx_id : 0);
16523 +
16524 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
16525 +               __hash_mapping(vxi, new);
16526 +       } else {
16527 +               struct vx_dmap_target new = {
16528 +                       .target = target,
16529 +                       .flags = flags | mode,
16530 +               };
16531 +               __set_default(vxi, mode, &new);
16532 +       }
16533 +       return 0;
16534 +}
16535 +
16536 +
16537 +static int do_unset_mapping(struct vx_info *vxi,
16538 +       dev_t device, dev_t target, int flags, umode_t mode)
16539 +{
16540 +       int ret = -EINVAL;
16541 +
16542 +       if (device) {
16543 +               ret = __remove_mapping(vxi, device, mode);
16544 +               if (ret < 0)
16545 +                       goto out;
16546 +       } else {
16547 +               ret = __remove_default(vxi, mode);
16548 +               if (ret < 0)
16549 +                       goto out;
16550 +       }
16551 +
16552 +out:
16553 +       return ret;
16554 +}
16555 +
16556 +
16557 +static inline int __user_device(const char __user *name, dev_t *dev,
16558 +       umode_t *mode)
16559 +{
16560 +       struct path path;
16561 +       int ret;
16562 +
16563 +       if (!name) {
16564 +               *dev = 0;
16565 +               return 0;
16566 +       }
16567 +       ret = user_lpath(name, &path);
16568 +       if (ret)
16569 +               return ret;
16570 +       if (path.dentry->d_inode) {
16571 +               *dev = path.dentry->d_inode->i_rdev;
16572 +               *mode = path.dentry->d_inode->i_mode;
16573 +       }
16574 +       path_put(&path);
16575 +       return 0;
16576 +}
16577 +
16578 +static inline int __mapping_mode(dev_t device, dev_t target,
16579 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
16580 +{
16581 +       if (device)
16582 +               *mode = device_mode & S_IFMT;
16583 +       else if (target)
16584 +               *mode = target_mode & S_IFMT;
16585 +       else
16586 +               return -EINVAL;
16587 +
16588 +       /* if both given, device and target mode have to match */
16589 +       if (device && target &&
16590 +               ((device_mode ^ target_mode) & S_IFMT))
16591 +               return -EINVAL;
16592 +       return 0;
16593 +}
16594 +
16595 +
16596 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
16597 +       const char __user *target_path, int flags, int set)
16598 +{
16599 +       dev_t device = ~0, target = ~0;
16600 +       umode_t device_mode = 0, target_mode = 0, mode;
16601 +       int ret;
16602 +
16603 +       ret = __user_device(device_path, &device, &device_mode);
16604 +       if (ret)
16605 +               return ret;
16606 +       ret = __user_device(target_path, &target, &target_mode);
16607 +       if (ret)
16608 +               return ret;
16609 +
16610 +       ret = __mapping_mode(device, target,
16611 +               device_mode, target_mode, &mode);
16612 +       if (ret)
16613 +               return ret;
16614 +
16615 +       if (set)
16616 +               return do_set_mapping(vxi, device, target,
16617 +                       flags, mode);
16618 +       else
16619 +               return do_unset_mapping(vxi, device, target,
16620 +                       flags, mode);
16621 +}
16622 +
16623 +
16624 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
16625 +{
16626 +       struct vcmd_set_mapping_v0 vc_data;
16627 +
16628 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16629 +               return -EFAULT;
16630 +
16631 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16632 +               vc_data.flags, 1);
16633 +}
16634 +
16635 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
16636 +{
16637 +       struct vcmd_set_mapping_v0 vc_data;
16638 +
16639 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16640 +               return -EFAULT;
16641 +
16642 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16643 +               vc_data.flags, 0);
16644 +}
16645 +
16646 +
16647 +#ifdef CONFIG_COMPAT
16648 +
16649 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
16650 +{
16651 +       struct vcmd_set_mapping_v0_x32 vc_data;
16652 +
16653 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16654 +               return -EFAULT;
16655 +
16656 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16657 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
16658 +}
16659 +
16660 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
16661 +{
16662 +       struct vcmd_set_mapping_v0_x32 vc_data;
16663 +
16664 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16665 +               return -EFAULT;
16666 +
16667 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16668 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
16669 +}
16670 +
16671 +#endif /* CONFIG_COMPAT */
16672 +
16673 +
16674 diff -NurpP --minimal linux-4.4.161/kernel/vserver/dlimit.c linux-4.4.161-vs2.3.9.8/kernel/vserver/dlimit.c
16675 --- linux-4.4.161/kernel/vserver/dlimit.c       1970-01-01 00:00:00.000000000 +0000
16676 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/dlimit.c     2018-10-20 04:57:21.000000000 +0000
16677 @@ -0,0 +1,528 @@
16678 +/*
16679 + *  linux/kernel/vserver/dlimit.c
16680 + *
16681 + *  Virtual Server: Context Disk Limits
16682 + *
16683 + *  Copyright (C) 2004-2009  Herbert P?tzl
16684 + *
16685 + *  V0.01  initial version
16686 + *  V0.02  compat32 splitup
16687 + *  V0.03  extended interface
16688 + *
16689 + */
16690 +
16691 +#include <linux/statfs.h>
16692 +#include <linux/sched.h>
16693 +#include <linux/namei.h>
16694 +#include <linux/vs_tag.h>
16695 +#include <linux/vs_dlimit.h>
16696 +#include <linux/vserver/dlimit_cmd.h>
16697 +#include <linux/slab.h>
16698 +// #include <linux/gfp.h>
16699 +
16700 +#include <asm/uaccess.h>
16701 +
16702 +/*     __alloc_dl_info()
16703 +
16704 +       * allocate an initialized dl_info struct
16705 +       * doesn't make it visible (hash)                        */
16706 +
16707 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
16708 +{
16709 +       struct dl_info *new = NULL;
16710 +
16711 +       vxdprintk(VXD_CBIT(dlim, 5),
16712 +               "alloc_dl_info(%p,%d)*", sb, tag);
16713 +
16714 +       /* would this benefit from a slab cache? */
16715 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
16716 +       if (!new)
16717 +               return 0;
16718 +
16719 +       memset(new, 0, sizeof(struct dl_info));
16720 +       new->dl_tag = tag;
16721 +       new->dl_sb = sb;
16722 +       // INIT_RCU_HEAD(&new->dl_rcu);
16723 +       INIT_HLIST_NODE(&new->dl_hlist);
16724 +       spin_lock_init(&new->dl_lock);
16725 +       atomic_set(&new->dl_refcnt, 0);
16726 +       atomic_set(&new->dl_usecnt, 0);
16727 +
16728 +       /* rest of init goes here */
16729 +
16730 +       vxdprintk(VXD_CBIT(dlim, 4),
16731 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
16732 +       return new;
16733 +}
16734 +
16735 +/*     __dealloc_dl_info()
16736 +
16737 +       * final disposal of dl_info                             */
16738 +
16739 +static void __dealloc_dl_info(struct dl_info *dli)
16740 +{
16741 +       vxdprintk(VXD_CBIT(dlim, 4),
16742 +               "dealloc_dl_info(%p)", dli);
16743 +
16744 +       dli->dl_hlist.next = LIST_POISON1;
16745 +       dli->dl_tag = -1;
16746 +       dli->dl_sb = 0;
16747 +
16748 +       BUG_ON(atomic_read(&dli->dl_usecnt));
16749 +       BUG_ON(atomic_read(&dli->dl_refcnt));
16750 +
16751 +       kfree(dli);
16752 +}
16753 +
16754 +
16755 +/*     hash table for dl_info hash */
16756 +
16757 +#define DL_HASH_SIZE   13
16758 +
16759 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
16760 +
16761 +static DEFINE_SPINLOCK(dl_info_hash_lock);
16762 +
16763 +
16764 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
16765 +{
16766 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
16767 +}
16768 +
16769 +
16770 +
16771 +/*     __hash_dl_info()
16772 +
16773 +       * add the dli to the global hash table
16774 +       * requires the hash_lock to be held                     */
16775 +
16776 +static inline void __hash_dl_info(struct dl_info *dli)
16777 +{
16778 +       struct hlist_head *head;
16779 +
16780 +       vxdprintk(VXD_CBIT(dlim, 6),
16781 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
16782 +       get_dl_info(dli);
16783 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
16784 +       hlist_add_head_rcu(&dli->dl_hlist, head);
16785 +}
16786 +
16787 +/*     __unhash_dl_info()
16788 +
16789 +       * remove the dli from the global hash table
16790 +       * requires the hash_lock to be held                     */
16791 +
16792 +static inline void __unhash_dl_info(struct dl_info *dli)
16793 +{
16794 +       vxdprintk(VXD_CBIT(dlim, 6),
16795 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
16796 +       hlist_del_rcu(&dli->dl_hlist);
16797 +       put_dl_info(dli);
16798 +}
16799 +
16800 +
16801 +/*     __lookup_dl_info()
16802 +
16803 +       * requires the rcu_read_lock()
16804 +       * doesn't increment the dl_refcnt                       */
16805 +
16806 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
16807 +{
16808 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
16809 +       struct dl_info *dli;
16810 +
16811 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
16812 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
16813 +                       return dli;
16814 +       }
16815 +       return NULL;
16816 +}
16817 +
16818 +
16819 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
16820 +{
16821 +       struct dl_info *dli;
16822 +
16823 +       rcu_read_lock();
16824 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
16825 +       vxdprintk(VXD_CBIT(dlim, 7),
16826 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
16827 +       rcu_read_unlock();
16828 +       return dli;
16829 +}
16830 +
16831 +void rcu_free_dl_info(struct rcu_head *head)
16832 +{
16833 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
16834 +       int usecnt, refcnt;
16835 +
16836 +       BUG_ON(!dli || !head);
16837 +
16838 +       usecnt = atomic_read(&dli->dl_usecnt);
16839 +       BUG_ON(usecnt < 0);
16840 +
16841 +       refcnt = atomic_read(&dli->dl_refcnt);
16842 +       BUG_ON(refcnt < 0);
16843 +
16844 +       vxdprintk(VXD_CBIT(dlim, 3),
16845 +               "rcu_free_dl_info(%p)", dli);
16846 +       if (!usecnt)
16847 +               __dealloc_dl_info(dli);
16848 +       else
16849 +               printk("!!! rcu didn't free\n");
16850 +}
16851 +
16852 +
16853 +
16854 +
16855 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
16856 +       uint32_t flags, int add)
16857 +{
16858 +       struct path path;
16859 +       int ret;
16860 +
16861 +       ret = user_lpath(name, &path);
16862 +       if (!ret) {
16863 +               struct super_block *sb;
16864 +               struct dl_info *dli;
16865 +
16866 +               ret = -EINVAL;
16867 +               if (!path.dentry->d_inode)
16868 +                       goto out_release;
16869 +               if (!(sb = path.dentry->d_inode->i_sb))
16870 +                       goto out_release;
16871 +
16872 +               if (add) {
16873 +                       dli = __alloc_dl_info(sb, id);
16874 +                       spin_lock(&dl_info_hash_lock);
16875 +
16876 +                       ret = -EEXIST;
16877 +                       if (__lookup_dl_info(sb, id))
16878 +                               goto out_unlock;
16879 +                       __hash_dl_info(dli);
16880 +                       dli = NULL;
16881 +               } else {
16882 +                       spin_lock(&dl_info_hash_lock);
16883 +                       dli = __lookup_dl_info(sb, id);
16884 +
16885 +                       ret = -ESRCH;
16886 +                       if (!dli)
16887 +                               goto out_unlock;
16888 +                       __unhash_dl_info(dli);
16889 +               }
16890 +               ret = 0;
16891 +       out_unlock:
16892 +               spin_unlock(&dl_info_hash_lock);
16893 +               if (add && dli)
16894 +                       __dealloc_dl_info(dli);
16895 +       out_release:
16896 +               path_put(&path);
16897 +       }
16898 +       return ret;
16899 +}
16900 +
16901 +int vc_add_dlimit(uint32_t id, void __user *data)
16902 +{
16903 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
16904 +
16905 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16906 +               return -EFAULT;
16907 +
16908 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
16909 +}
16910 +
16911 +int vc_rem_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, 0);
16919 +}
16920 +
16921 +#ifdef CONFIG_COMPAT
16922 +
16923 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
16924 +{
16925 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
16926 +
16927 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16928 +               return -EFAULT;
16929 +
16930 +       return do_addrem_dlimit(id,
16931 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
16932 +}
16933 +
16934 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
16935 +{
16936 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
16937 +
16938 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16939 +               return -EFAULT;
16940 +
16941 +       return do_addrem_dlimit(id,
16942 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
16943 +}
16944 +
16945 +#endif /* CONFIG_COMPAT */
16946 +
16947 +
16948 +static inline
16949 +int do_set_dlimit(uint32_t id, const char __user *name,
16950 +       uint32_t space_used, uint32_t space_total,
16951 +       uint32_t inodes_used, uint32_t inodes_total,
16952 +       uint32_t reserved, uint32_t flags)
16953 +{
16954 +       struct path path;
16955 +       int ret;
16956 +
16957 +       ret = user_lpath(name, &path);
16958 +       if (!ret) {
16959 +               struct super_block *sb;
16960 +               struct dl_info *dli;
16961 +
16962 +               ret = -EINVAL;
16963 +               if (!path.dentry->d_inode)
16964 +                       goto out_release;
16965 +               if (!(sb = path.dentry->d_inode->i_sb))
16966 +                       goto out_release;
16967 +
16968 +               /* sanity checks */
16969 +               if ((reserved != CDLIM_KEEP &&
16970 +                       reserved > 100) ||
16971 +                       (inodes_used != CDLIM_KEEP &&
16972 +                       inodes_used > inodes_total) ||
16973 +                       (space_used != CDLIM_KEEP &&
16974 +                       space_used > space_total))
16975 +                       goto out_release;
16976 +
16977 +               ret = -ESRCH;
16978 +               dli = locate_dl_info(sb, id);
16979 +               if (!dli)
16980 +                       goto out_release;
16981 +
16982 +               spin_lock(&dli->dl_lock);
16983 +
16984 +               if (inodes_used != CDLIM_KEEP)
16985 +                       dli->dl_inodes_used = inodes_used;
16986 +               if (inodes_total != CDLIM_KEEP)
16987 +                       dli->dl_inodes_total = inodes_total;
16988 +               if (space_used != CDLIM_KEEP)
16989 +                       dli->dl_space_used = dlimit_space_32to64(
16990 +                               space_used, flags, DLIMS_USED);
16991 +
16992 +               if (space_total == CDLIM_INFINITY)
16993 +                       dli->dl_space_total = DLIM_INFINITY;
16994 +               else if (space_total != CDLIM_KEEP)
16995 +                       dli->dl_space_total = dlimit_space_32to64(
16996 +                               space_total, flags, DLIMS_TOTAL);
16997 +
16998 +               if (reserved != CDLIM_KEEP)
16999 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17000 +
17001 +               spin_unlock(&dli->dl_lock);
17002 +
17003 +               put_dl_info(dli);
17004 +               ret = 0;
17005 +
17006 +       out_release:
17007 +               path_put(&path);
17008 +       }
17009 +       return ret;
17010 +}
17011 +
17012 +int vc_set_dlimit(uint32_t id, void __user *data)
17013 +{
17014 +       struct vcmd_ctx_dlimit_v0 vc_data;
17015 +
17016 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17017 +               return -EFAULT;
17018 +
17019 +       return do_set_dlimit(id, vc_data.name,
17020 +               vc_data.space_used, vc_data.space_total,
17021 +               vc_data.inodes_used, vc_data.inodes_total,
17022 +               vc_data.reserved, vc_data.flags);
17023 +}
17024 +
17025 +#ifdef CONFIG_COMPAT
17026 +
17027 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17028 +{
17029 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17030 +
17031 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17032 +               return -EFAULT;
17033 +
17034 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17035 +               vc_data.space_used, vc_data.space_total,
17036 +               vc_data.inodes_used, vc_data.inodes_total,
17037 +               vc_data.reserved, vc_data.flags);
17038 +}
17039 +
17040 +#endif /* CONFIG_COMPAT */
17041 +
17042 +
17043 +static inline
17044 +int do_get_dlimit(uint32_t id, const char __user *name,
17045 +       uint32_t *space_used, uint32_t *space_total,
17046 +       uint32_t *inodes_used, uint32_t *inodes_total,
17047 +       uint32_t *reserved, uint32_t *flags)
17048 +{
17049 +       struct path path;
17050 +       int ret;
17051 +
17052 +       ret = user_lpath(name, &path);
17053 +       if (!ret) {
17054 +               struct super_block *sb;
17055 +               struct dl_info *dli;
17056 +
17057 +               ret = -EINVAL;
17058 +               if (!path.dentry->d_inode)
17059 +                       goto out_release;
17060 +               if (!(sb = path.dentry->d_inode->i_sb))
17061 +                       goto out_release;
17062 +
17063 +               ret = -ESRCH;
17064 +               dli = locate_dl_info(sb, id);
17065 +               if (!dli)
17066 +                       goto out_release;
17067 +
17068 +               spin_lock(&dli->dl_lock);
17069 +               *inodes_used = dli->dl_inodes_used;
17070 +               *inodes_total = dli->dl_inodes_total;
17071 +
17072 +               *space_used = dlimit_space_64to32(
17073 +                       dli->dl_space_used, flags, DLIMS_USED);
17074 +
17075 +               if (dli->dl_space_total == DLIM_INFINITY)
17076 +                       *space_total = CDLIM_INFINITY;
17077 +               else
17078 +                       *space_total = dlimit_space_64to32(
17079 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
17080 +
17081 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
17082 +               spin_unlock(&dli->dl_lock);
17083 +
17084 +               put_dl_info(dli);
17085 +               ret = -EFAULT;
17086 +
17087 +               ret = 0;
17088 +       out_release:
17089 +               path_put(&path);
17090 +       }
17091 +       return ret;
17092 +}
17093 +
17094 +
17095 +int vc_get_dlimit(uint32_t id, void __user *data)
17096 +{
17097 +       struct vcmd_ctx_dlimit_v0 vc_data;
17098 +       int ret;
17099 +
17100 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17101 +               return -EFAULT;
17102 +
17103 +       ret = do_get_dlimit(id, vc_data.name,
17104 +               &vc_data.space_used, &vc_data.space_total,
17105 +               &vc_data.inodes_used, &vc_data.inodes_total,
17106 +               &vc_data.reserved, &vc_data.flags);
17107 +       if (ret)
17108 +               return ret;
17109 +
17110 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17111 +               return -EFAULT;
17112 +       return 0;
17113 +}
17114 +
17115 +#ifdef CONFIG_COMPAT
17116 +
17117 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
17118 +{
17119 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17120 +       int ret;
17121 +
17122 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17123 +               return -EFAULT;
17124 +
17125 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
17126 +               &vc_data.space_used, &vc_data.space_total,
17127 +               &vc_data.inodes_used, &vc_data.inodes_total,
17128 +               &vc_data.reserved, &vc_data.flags);
17129 +       if (ret)
17130 +               return ret;
17131 +
17132 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17133 +               return -EFAULT;
17134 +       return 0;
17135 +}
17136 +
17137 +#endif /* CONFIG_COMPAT */
17138 +
17139 +
17140 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
17141 +{
17142 +       struct dl_info *dli;
17143 +       __u64 blimit, bfree, bavail;
17144 +       __u32 ifree;
17145 +
17146 +       dli = locate_dl_info(sb, dx_current_tag());
17147 +       if (!dli)
17148 +               return;
17149 +
17150 +       spin_lock(&dli->dl_lock);
17151 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
17152 +               goto no_ilim;
17153 +
17154 +       /* reduce max inodes available to limit */
17155 +       if (buf->f_files > dli->dl_inodes_total)
17156 +               buf->f_files = dli->dl_inodes_total;
17157 +
17158 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
17159 +       /* reduce free inodes to min */
17160 +       if (ifree < buf->f_ffree)
17161 +               buf->f_ffree = ifree;
17162 +
17163 +no_ilim:
17164 +       if (dli->dl_space_total == DLIM_INFINITY)
17165 +               goto no_blim;
17166 +
17167 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
17168 +
17169 +       if (dli->dl_space_total < dli->dl_space_used)
17170 +               bfree = 0;
17171 +       else
17172 +               bfree = (dli->dl_space_total - dli->dl_space_used)
17173 +                       >> sb->s_blocksize_bits;
17174 +
17175 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
17176 +       if (bavail < dli->dl_space_used)
17177 +               bavail = 0;
17178 +       else
17179 +               bavail = (bavail - dli->dl_space_used)
17180 +                       >> sb->s_blocksize_bits;
17181 +
17182 +       /* reduce max space available to limit */
17183 +       if (buf->f_blocks > blimit)
17184 +               buf->f_blocks = blimit;
17185 +
17186 +       /* reduce free space to min */
17187 +       if (bfree < buf->f_bfree)
17188 +               buf->f_bfree = bfree;
17189 +
17190 +       /* reduce avail space to min */
17191 +       if (bavail < buf->f_bavail)
17192 +               buf->f_bavail = bavail;
17193 +
17194 +no_blim:
17195 +       spin_unlock(&dli->dl_lock);
17196 +       put_dl_info(dli);
17197 +
17198 +       return;
17199 +}
17200 +
17201 +#include <linux/module.h>
17202 +
17203 +EXPORT_SYMBOL_GPL(locate_dl_info);
17204 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
17205 +
17206 diff -NurpP --minimal linux-4.4.161/kernel/vserver/helper.c linux-4.4.161-vs2.3.9.8/kernel/vserver/helper.c
17207 --- linux-4.4.161/kernel/vserver/helper.c       1970-01-01 00:00:00.000000000 +0000
17208 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/helper.c     2018-10-20 04:57:21.000000000 +0000
17209 @@ -0,0 +1,242 @@
17210 +/*
17211 + *  linux/kernel/vserver/helper.c
17212 + *
17213 + *  Virtual Context Support
17214 + *
17215 + *  Copyright (C) 2004-2007  Herbert P?tzl
17216 + *
17217 + *  V0.01  basic helper
17218 + *
17219 + */
17220 +
17221 +#include <linux/kmod.h>
17222 +#include <linux/reboot.h>
17223 +#include <linux/vs_context.h>
17224 +#include <linux/vs_network.h>
17225 +#include <linux/vserver/signal.h>
17226 +
17227 +
17228 +char vshelper_path[255] = "/sbin/vshelper";
17229 +
17230 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
17231 +{
17232 +       current->flags &= ~PF_NO_SETAFFINITY;
17233 +       return 0;
17234 +}
17235 +
17236 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
17237 +{
17238 +       struct subprocess_info *info;
17239 +       gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
17240 +
17241 +       info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
17242 +                                        vshelper_init, NULL, NULL);
17243 +       if (info == NULL)
17244 +               return -ENOMEM;
17245 +
17246 +       return call_usermodehelper_exec(info, wait);
17247 +}
17248 +
17249 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
17250 +{
17251 +       int ret;
17252 +
17253 +       if ((ret = vs_call_usermodehelper(name, argv, envp,
17254 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
17255 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
17256 +                       name, argv[1], argv[2],
17257 +                       sync ? "sync" : "async", ret);
17258 +       }
17259 +       vxdprintk(VXD_CBIT(switch, 4),
17260 +               "%s: (%s %s) returned %s with %d",
17261 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
17262 +       return ret;
17263 +}
17264 +
17265 +/*
17266 + *      vshelper path is set via /proc/sys
17267 + *      invoked by vserver sys_reboot(), with
17268 + *      the following arguments
17269 + *
17270 + *      argv [0] = vshelper_path;
17271 + *      argv [1] = action: "restart", "halt", "poweroff", ...
17272 + *      argv [2] = context identifier
17273 + *
17274 + *      envp [*] = type-specific parameters
17275 + */
17276 +
17277 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
17278 +{
17279 +       char id_buf[8], cmd_buf[16];
17280 +       char uid_buf[16], pid_buf[16];
17281 +       int ret;
17282 +
17283 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17284 +       char *envp[] = {"HOME=/", "TERM=linux",
17285 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
17286 +                       uid_buf, pid_buf, cmd_buf, 0};
17287 +
17288 +       if (vx_info_state(vxi, VXS_HELPER))
17289 +               return -EAGAIN;
17290 +       vxi->vx_state |= VXS_HELPER;
17291 +
17292 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17293 +
17294 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17295 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
17296 +               from_kuid(&init_user_ns, current_uid()));
17297 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
17298 +
17299 +       switch (cmd) {
17300 +       case LINUX_REBOOT_CMD_RESTART:
17301 +               argv[1] = "restart";
17302 +               break;
17303 +
17304 +       case LINUX_REBOOT_CMD_HALT:
17305 +               argv[1] = "halt";
17306 +               break;
17307 +
17308 +       case LINUX_REBOOT_CMD_POWER_OFF:
17309 +               argv[1] = "poweroff";
17310 +               break;
17311 +
17312 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
17313 +               argv[1] = "swsusp";
17314 +               break;
17315 +
17316 +       case LINUX_REBOOT_CMD_OOM:
17317 +               argv[1] = "oom";
17318 +               break;
17319 +
17320 +       default:
17321 +               vxi->vx_state &= ~VXS_HELPER;
17322 +               return 0;
17323 +       }
17324 +
17325 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
17326 +       vxi->vx_state &= ~VXS_HELPER;
17327 +       __wakeup_vx_info(vxi);
17328 +       return (ret) ? -EPERM : 0;
17329 +}
17330 +
17331 +
17332 +long vs_reboot(unsigned int cmd, void __user *arg)
17333 +{
17334 +       struct vx_info *vxi = current_vx_info();
17335 +       long ret = 0;
17336 +
17337 +       vxdprintk(VXD_CBIT(misc, 5),
17338 +               "vs_reboot(%p[#%d],%u)",
17339 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17340 +
17341 +       ret = vs_reboot_helper(vxi, cmd, arg);
17342 +       if (ret)
17343 +               return ret;
17344 +
17345 +       vxi->reboot_cmd = cmd;
17346 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17347 +               switch (cmd) {
17348 +               case LINUX_REBOOT_CMD_RESTART:
17349 +               case LINUX_REBOOT_CMD_HALT:
17350 +               case LINUX_REBOOT_CMD_POWER_OFF:
17351 +                       vx_info_kill(vxi, 0, SIGKILL);
17352 +                       vx_info_kill(vxi, 1, SIGKILL);
17353 +               default:
17354 +                       break;
17355 +               }
17356 +       }
17357 +       return 0;
17358 +}
17359 +
17360 +long vs_oom_action(unsigned int cmd)
17361 +{
17362 +       struct vx_info *vxi = current_vx_info();
17363 +       long ret = 0;
17364 +
17365 +       vxdprintk(VXD_CBIT(misc, 5),
17366 +               "vs_oom_action(%p[#%d],%u)",
17367 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17368 +
17369 +       ret = vs_reboot_helper(vxi, cmd, NULL);
17370 +       if (ret)
17371 +               return ret;
17372 +
17373 +       vxi->reboot_cmd = cmd;
17374 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17375 +               vx_info_kill(vxi, 0, SIGKILL);
17376 +               vx_info_kill(vxi, 1, SIGKILL);
17377 +       }
17378 +       return 0;
17379 +}
17380 +
17381 +/*
17382 + *      argv [0] = vshelper_path;
17383 + *      argv [1] = action: "startup", "shutdown"
17384 + *      argv [2] = context identifier
17385 + *
17386 + *      envp [*] = type-specific parameters
17387 + */
17388 +
17389 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
17390 +{
17391 +       char id_buf[8], cmd_buf[16];
17392 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17393 +       char *envp[] = {"HOME=/", "TERM=linux",
17394 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17395 +
17396 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
17397 +               return 0;
17398 +
17399 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17400 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17401 +
17402 +       switch (cmd) {
17403 +       case VSC_STARTUP:
17404 +               argv[1] = "startup";
17405 +               break;
17406 +       case VSC_SHUTDOWN:
17407 +               argv[1] = "shutdown";
17408 +               break;
17409 +       default:
17410 +               return 0;
17411 +       }
17412 +
17413 +       return do_vshelper(vshelper_path, argv, envp, 1);
17414 +}
17415 +
17416 +
17417 +/*
17418 + *      argv [0] = vshelper_path;
17419 + *      argv [1] = action: "netup", "netdown"
17420 + *      argv [2] = context identifier
17421 + *
17422 + *      envp [*] = type-specific parameters
17423 + */
17424 +
17425 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
17426 +{
17427 +       char id_buf[8], cmd_buf[16];
17428 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17429 +       char *envp[] = {"HOME=/", "TERM=linux",
17430 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17431 +
17432 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
17433 +               return 0;
17434 +
17435 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
17436 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17437 +
17438 +       switch (cmd) {
17439 +       case VSC_NETUP:
17440 +               argv[1] = "netup";
17441 +               break;
17442 +       case VSC_NETDOWN:
17443 +               argv[1] = "netdown";
17444 +               break;
17445 +       default:
17446 +               return 0;
17447 +       }
17448 +
17449 +       return do_vshelper(vshelper_path, argv, envp, 1);
17450 +}
17451 +
17452 diff -NurpP --minimal linux-4.4.161/kernel/vserver/history.c linux-4.4.161-vs2.3.9.8/kernel/vserver/history.c
17453 --- linux-4.4.161/kernel/vserver/history.c      1970-01-01 00:00:00.000000000 +0000
17454 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/history.c    2018-10-20 04:57:21.000000000 +0000
17455 @@ -0,0 +1,258 @@
17456 +/*
17457 + *  kernel/vserver/history.c
17458 + *
17459 + *  Virtual Context History Backtrace
17460 + *
17461 + *  Copyright (C) 2004-2007  Herbert P?tzl
17462 + *
17463 + *  V0.01  basic structure
17464 + *  V0.02  hash/unhash and trace
17465 + *  V0.03  preemption fixes
17466 + *
17467 + */
17468 +
17469 +#include <linux/module.h>
17470 +#include <asm/uaccess.h>
17471 +
17472 +#include <linux/vserver/context.h>
17473 +#include <linux/vserver/debug.h>
17474 +#include <linux/vserver/debug_cmd.h>
17475 +#include <linux/vserver/history.h>
17476 +
17477 +
17478 +#ifdef CONFIG_VSERVER_HISTORY
17479 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
17480 +#else
17481 +#define VXH_SIZE       64
17482 +#endif
17483 +
17484 +struct _vx_history {
17485 +       unsigned int counter;
17486 +
17487 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
17488 +};
17489 +
17490 +
17491 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
17492 +
17493 +unsigned volatile int vxh_active = 1;
17494 +
17495 +static atomic_t sequence = ATOMIC_INIT(0);
17496 +
17497 +
17498 +/*     vxh_advance()
17499 +
17500 +       * requires disabled preemption                          */
17501 +
17502 +struct _vx_hist_entry *vxh_advance(void *loc)
17503 +{
17504 +       unsigned int cpu = smp_processor_id();
17505 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17506 +       struct _vx_hist_entry *entry;
17507 +       unsigned int index;
17508 +
17509 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
17510 +       entry = &hist->entry[index];
17511 +
17512 +       entry->seq = atomic_inc_return(&sequence);
17513 +       entry->loc = loc;
17514 +       return entry;
17515 +}
17516 +
17517 +EXPORT_SYMBOL_GPL(vxh_advance);
17518 +
17519 +
17520 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
17521 +
17522 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
17523 +
17524 +
17525 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
17526 +
17527 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
17528 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
17529 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
17530 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
17531 +
17532 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
17533 +{
17534 +       switch (e->type) {
17535 +       case VXH_THROW_OOPS:
17536 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
17537 +               break;
17538 +
17539 +       case VXH_GET_VX_INFO:
17540 +       case VXH_PUT_VX_INFO:
17541 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17542 +                       VXH_LOC_ARGS(e),
17543 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
17544 +                       VXH_VXI_ARGS(e));
17545 +               break;
17546 +
17547 +       case VXH_INIT_VX_INFO:
17548 +       case VXH_SET_VX_INFO:
17549 +       case VXH_CLR_VX_INFO:
17550 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17551 +                       VXH_LOC_ARGS(e),
17552 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
17553 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
17554 +                       VXH_VXI_ARGS(e), e->sc.data);
17555 +               break;
17556 +
17557 +       case VXH_CLAIM_VX_INFO:
17558 +       case VXH_RELEASE_VX_INFO:
17559 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17560 +                       VXH_LOC_ARGS(e),
17561 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
17562 +                       VXH_VXI_ARGS(e), e->sc.data);
17563 +               break;
17564 +
17565 +       case VXH_ALLOC_VX_INFO:
17566 +       case VXH_DEALLOC_VX_INFO:
17567 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17568 +                       VXH_LOC_ARGS(e),
17569 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
17570 +                       VXH_VXI_ARGS(e));
17571 +               break;
17572 +
17573 +       case VXH_HASH_VX_INFO:
17574 +       case VXH_UNHASH_VX_INFO:
17575 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
17576 +                       VXH_LOC_ARGS(e),
17577 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
17578 +                       VXH_VXI_ARGS(e));
17579 +               break;
17580 +
17581 +       case VXH_LOC_VX_INFO:
17582 +       case VXH_LOOKUP_VX_INFO:
17583 +       case VXH_CREATE_VX_INFO:
17584 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
17585 +                       VXH_LOC_ARGS(e),
17586 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
17587 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
17588 +                       e->ll.arg, VXH_VXI_ARGS(e));
17589 +               break;
17590 +       }
17591 +}
17592 +
17593 +static void __vxh_dump_history(void)
17594 +{
17595 +       unsigned int i, cpu;
17596 +
17597 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
17598 +               atomic_read(&sequence), NR_CPUS);
17599 +
17600 +       for (i = 0; i < VXH_SIZE; i++) {
17601 +               for_each_online_cpu(cpu) {
17602 +                       struct _vx_history *hist =
17603 +                               &per_cpu(vx_history_buffer, cpu);
17604 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
17605 +                       struct _vx_hist_entry *entry = &hist->entry[index];
17606 +
17607 +                       vxh_dump_entry(entry, cpu);
17608 +               }
17609 +       }
17610 +}
17611 +
17612 +void   vxh_dump_history(void)
17613 +{
17614 +       vxh_active = 0;
17615 +#ifdef CONFIG_SMP
17616 +       local_irq_enable();
17617 +       smp_send_stop();
17618 +       local_irq_disable();
17619 +#endif
17620 +       __vxh_dump_history();
17621 +}
17622 +
17623 +
17624 +/* vserver syscall commands below here */
17625 +
17626 +
17627 +int vc_dump_history(uint32_t id)
17628 +{
17629 +       vxh_active = 0;
17630 +       __vxh_dump_history();
17631 +       vxh_active = 1;
17632 +
17633 +       return 0;
17634 +}
17635 +
17636 +
17637 +int do_read_history(struct __user _vx_hist_entry *data,
17638 +       int cpu, uint32_t *index, uint32_t *count)
17639 +{
17640 +       int pos, ret = 0;
17641 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17642 +       int end = hist->counter;
17643 +       int start = end - VXH_SIZE + 2;
17644 +       int idx = *index;
17645 +
17646 +       /* special case: get current pos */
17647 +       if (!*count) {
17648 +               *index = end;
17649 +               return 0;
17650 +       }
17651 +
17652 +       /* have we lost some data? */
17653 +       if (idx < start)
17654 +               idx = start;
17655 +
17656 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
17657 +               struct _vx_hist_entry *entry =
17658 +                       &hist->entry[idx % VXH_SIZE];
17659 +
17660 +               /* send entry to userspace */
17661 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
17662 +               if (ret)
17663 +                       break;
17664 +       }
17665 +       /* save new index and count */
17666 +       *index = idx;
17667 +       *count = pos;
17668 +       return ret ? ret : (*index < end);
17669 +}
17670 +
17671 +int vc_read_history(uint32_t id, void __user *data)
17672 +{
17673 +       struct vcmd_read_history_v0 vc_data;
17674 +       int ret;
17675 +
17676 +       if (id >= NR_CPUS)
17677 +               return -EINVAL;
17678 +
17679 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17680 +               return -EFAULT;
17681 +
17682 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
17683 +               id, &vc_data.index, &vc_data.count);
17684 +
17685 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17686 +               return -EFAULT;
17687 +       return ret;
17688 +}
17689 +
17690 +#ifdef CONFIG_COMPAT
17691 +
17692 +int vc_read_history_x32(uint32_t id, void __user *data)
17693 +{
17694 +       struct vcmd_read_history_v0_x32 vc_data;
17695 +       int ret;
17696 +
17697 +       if (id >= NR_CPUS)
17698 +               return -EINVAL;
17699 +
17700 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17701 +               return -EFAULT;
17702 +
17703 +       ret = do_read_history((struct __user _vx_hist_entry *)
17704 +               compat_ptr(vc_data.data_ptr),
17705 +               id, &vc_data.index, &vc_data.count);
17706 +
17707 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17708 +               return -EFAULT;
17709 +       return ret;
17710 +}
17711 +
17712 +#endif /* CONFIG_COMPAT */
17713 +
17714 diff -NurpP --minimal linux-4.4.161/kernel/vserver/inet.c linux-4.4.161-vs2.3.9.8/kernel/vserver/inet.c
17715 --- linux-4.4.161/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
17716 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/inet.c       2018-10-20 04:57:21.000000000 +0000
17717 @@ -0,0 +1,236 @@
17718 +
17719 +#include <linux/in.h>
17720 +#include <linux/inetdevice.h>
17721 +#include <linux/export.h>
17722 +#include <linux/vs_inet.h>
17723 +#include <linux/vs_inet6.h>
17724 +#include <linux/vserver/debug.h>
17725 +#include <net/route.h>
17726 +#include <net/addrconf.h>
17727 +
17728 +
17729 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17730 +{
17731 +       int ret = 0;
17732 +
17733 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
17734 +               ret = 1;
17735 +       else {
17736 +               struct nx_addr_v4 *ptr;
17737 +               unsigned long irqflags;
17738 +
17739 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
17740 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
17741 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
17742 +                               ret = 1;
17743 +                               break;
17744 +                       }
17745 +               }
17746 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
17747 +       }
17748 +
17749 +       vxdprintk(VXD_CBIT(net, 2),
17750 +               "nx_v4_addr_conflict(%p,%p): %d",
17751 +               nxi1, nxi2, ret);
17752 +
17753 +       return ret;
17754 +}
17755 +
17756 +
17757 +#ifdef CONFIG_IPV6
17758 +
17759 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17760 +{
17761 +       int ret = 0;
17762 +
17763 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
17764 +               ret = 1;
17765 +       else {
17766 +               struct nx_addr_v6 *ptr;
17767 +               unsigned long irqflags;
17768 +
17769 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
17770 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
17771 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
17772 +                               ret = 1;
17773 +                               break;
17774 +                       }
17775 +               }
17776 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
17777 +       }
17778 +
17779 +       vxdprintk(VXD_CBIT(net, 2),
17780 +               "nx_v6_addr_conflict(%p,%p): %d",
17781 +               nxi1, nxi2, ret);
17782 +
17783 +       return ret;
17784 +}
17785 +
17786 +#endif
17787 +
17788 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
17789 +{
17790 +       struct in_device *in_dev;
17791 +       struct in_ifaddr **ifap;
17792 +       struct in_ifaddr *ifa;
17793 +       int ret = 0;
17794 +
17795 +       if (!dev)
17796 +               goto out;
17797 +       in_dev = in_dev_get(dev);
17798 +       if (!in_dev)
17799 +               goto out;
17800 +
17801 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
17802 +               ifap = &ifa->ifa_next) {
17803 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
17804 +                       ret = 1;
17805 +                       break;
17806 +               }
17807 +       }
17808 +       in_dev_put(in_dev);
17809 +out:
17810 +       return ret;
17811 +}
17812 +
17813 +
17814 +#ifdef CONFIG_IPV6
17815 +
17816 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
17817 +{
17818 +       struct inet6_dev *in_dev;
17819 +       struct inet6_ifaddr *ifa;
17820 +       int ret = 0;
17821 +
17822 +       if (!dev)
17823 +               goto out;
17824 +       in_dev = in6_dev_get(dev);
17825 +       if (!in_dev)
17826 +               goto out;
17827 +
17828 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
17829 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
17830 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
17831 +                       ret = 1;
17832 +                       break;
17833 +               }
17834 +       }
17835 +       in6_dev_put(in_dev);
17836 +out:
17837 +       return ret;
17838 +}
17839 +
17840 +#endif
17841 +
17842 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
17843 +{
17844 +       int ret = 1;
17845 +
17846 +       if (!nxi)
17847 +               goto out;
17848 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
17849 +               goto out;
17850 +#ifdef CONFIG_IPV6
17851 +       ret = 2;
17852 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
17853 +               goto out;
17854 +#endif
17855 +       ret = 0;
17856 +out:
17857 +       vxdprintk(VXD_CBIT(net, 3),
17858 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
17859 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
17860 +       return ret;
17861 +}
17862 +
17863 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
17864 +       struct flowi4 *fl4)
17865 +{
17866 +       struct rtable *rt;
17867 +
17868 +       if (!nxi)
17869 +               return NULL;
17870 +
17871 +       /* FIXME: handle lback only case */
17872 +       if (!NX_IPV4(nxi))
17873 +               return ERR_PTR(-EPERM);
17874 +
17875 +       vxdprintk(VXD_CBIT(net, 4),
17876 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
17877 +               nxi, nxi ? nxi->nx_id : 0,
17878 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
17879 +
17880 +       /* single IP is unconditional */
17881 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
17882 +               (fl4->saddr == INADDR_ANY))
17883 +               fl4->saddr = nxi->v4.ip[0].s_addr;
17884 +
17885 +       if (fl4->saddr == INADDR_ANY) {
17886 +               struct nx_addr_v4 *ptr;
17887 +               __be32 found = 0;
17888 +
17889 +               rt = __ip_route_output_key(net, fl4);
17890 +               if (!IS_ERR(rt)) {
17891 +                       found = fl4->saddr;
17892 +                       ip_rt_put(rt);
17893 +                       vxdprintk(VXD_CBIT(net, 4),
17894 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
17895 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
17896 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
17897 +                               goto found;
17898 +               }
17899 +
17900 +               WARN_ON_ONCE(in_irq());
17901 +               spin_lock_bh(&nxi->addr_lock);
17902 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
17903 +                       __be32 primary = ptr->ip[0].s_addr;
17904 +                       __be32 mask = ptr->mask.s_addr;
17905 +                       __be32 neta = primary & mask;
17906 +
17907 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
17908 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
17909 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
17910 +                               NIPQUAD(mask), NIPQUAD(neta));
17911 +                       if ((found & mask) != neta)
17912 +                               continue;
17913 +
17914 +                       fl4->saddr = primary;
17915 +                       rt = __ip_route_output_key(net, fl4);
17916 +                       vxdprintk(VXD_CBIT(net, 4),
17917 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
17918 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
17919 +                       if (!IS_ERR(rt)) {
17920 +                               found = fl4->saddr;
17921 +                               ip_rt_put(rt);
17922 +                               if (found == primary)
17923 +                                       goto found_unlock;
17924 +                       }
17925 +               }
17926 +               /* still no source ip? */
17927 +               found = ipv4_is_loopback(fl4->daddr)
17928 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
17929 +       found_unlock:
17930 +               spin_unlock_bh(&nxi->addr_lock);
17931 +       found:
17932 +               /* assign src ip to flow */
17933 +               fl4->saddr = found;
17934 +
17935 +       } else {
17936 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
17937 +                       return ERR_PTR(-EPERM);
17938 +       }
17939 +
17940 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
17941 +               if (ipv4_is_loopback(fl4->daddr))
17942 +                       fl4->daddr = nxi->v4_lback.s_addr;
17943 +               if (ipv4_is_loopback(fl4->saddr))
17944 +                       fl4->saddr = nxi->v4_lback.s_addr;
17945 +       } else if (ipv4_is_loopback(fl4->daddr) &&
17946 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
17947 +               return ERR_PTR(-EPERM);
17948 +
17949 +       return NULL;
17950 +}
17951 +
17952 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
17953 +
17954 diff -NurpP --minimal linux-4.4.161/kernel/vserver/init.c linux-4.4.161-vs2.3.9.8/kernel/vserver/init.c
17955 --- linux-4.4.161/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
17956 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/init.c       2018-10-20 04:57:21.000000000 +0000
17957 @@ -0,0 +1,46 @@
17958 +/*
17959 + *  linux/kernel/init.c
17960 + *
17961 + *  Virtual Server Init
17962 + *
17963 + *  Copyright (C) 2004-2007  Herbert P?tzl
17964 + *
17965 + *  V0.01  basic structure
17966 + *
17967 + */
17968 +
17969 +#include <linux/init.h>
17970 +#include <linux/module.h>
17971 +
17972 +int    vserver_register_sysctl(void);
17973 +void   vserver_unregister_sysctl(void);
17974 +
17975 +
17976 +static int __init init_vserver(void)
17977 +{
17978 +       int ret = 0;
17979 +
17980 +#ifdef CONFIG_VSERVER_DEBUG
17981 +       vserver_register_sysctl();
17982 +#endif
17983 +       return ret;
17984 +}
17985 +
17986 +
17987 +static void __exit exit_vserver(void)
17988 +{
17989 +
17990 +#ifdef CONFIG_VSERVER_DEBUG
17991 +       vserver_unregister_sysctl();
17992 +#endif
17993 +       return;
17994 +}
17995 +
17996 +/* FIXME: GFP_ZONETYPES gone
17997 +long vx_slab[GFP_ZONETYPES]; */
17998 +long vx_area;
17999 +
18000 +
18001 +module_init(init_vserver);
18002 +module_exit(exit_vserver);
18003 +
18004 diff -NurpP --minimal linux-4.4.161/kernel/vserver/inode.c linux-4.4.161-vs2.3.9.8/kernel/vserver/inode.c
18005 --- linux-4.4.161/kernel/vserver/inode.c        1970-01-01 00:00:00.000000000 +0000
18006 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/inode.c      2018-10-20 04:57:21.000000000 +0000
18007 @@ -0,0 +1,440 @@
18008 +/*
18009 + *  linux/kernel/vserver/inode.c
18010 + *
18011 + *  Virtual Server: File System Support
18012 + *
18013 + *  Copyright (C) 2004-2007  Herbert P?tzl
18014 + *
18015 + *  V0.01  separated from vcontext V0.05
18016 + *  V0.02  moved to tag (instead of xid)
18017 + *
18018 + */
18019 +
18020 +#include <linux/tty.h>
18021 +#include <linux/proc_fs.h>
18022 +#include <linux/devpts_fs.h>
18023 +#include <linux/fs.h>
18024 +#include <linux/file.h>
18025 +#include <linux/mount.h>
18026 +#include <linux/parser.h>
18027 +#include <linux/namei.h>
18028 +#include <linux/magic.h>
18029 +#include <linux/slab.h>
18030 +#include <linux/vserver/inode.h>
18031 +#include <linux/vserver/inode_cmd.h>
18032 +#include <linux/vs_base.h>
18033 +#include <linux/vs_tag.h>
18034 +
18035 +#include <asm/uaccess.h>
18036 +#include <../../fs/proc/internal.h>
18037 +
18038 +
18039 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18040 +{
18041 +       struct proc_dir_entry *entry;
18042 +
18043 +       if (!in || !in->i_sb)
18044 +               return -ESRCH;
18045 +
18046 +       *flags = IATTR_TAG
18047 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18048 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18049 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18050 +               | (IS_COW(in) ? IATTR_COW : 0);
18051 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18052 +
18053 +       if (S_ISDIR(in->i_mode))
18054 +               *mask |= IATTR_BARRIER;
18055 +
18056 +       if (IS_TAGGED(in)) {
18057 +               *tag = i_tag_read(in);
18058 +               *mask |= IATTR_TAG;
18059 +       }
18060 +
18061 +       switch (in->i_sb->s_magic) {
18062 +       case PROC_SUPER_MAGIC:
18063 +               entry = PROC_I(in)->pde;
18064 +
18065 +               /* check for specific inodes? */
18066 +               if (entry)
18067 +                       *mask |= IATTR_FLAGS;
18068 +               if (entry)
18069 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
18070 +               else
18071 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
18072 +               break;
18073 +
18074 +       case DEVPTS_SUPER_MAGIC:
18075 +               *tag = i_tag_read(in);
18076 +               *mask |= IATTR_TAG;
18077 +               break;
18078 +
18079 +       default:
18080 +               break;
18081 +       }
18082 +       return 0;
18083 +}
18084 +
18085 +int vc_get_iattr(void __user *data)
18086 +{
18087 +       struct path path;
18088 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
18089 +       int ret;
18090 +
18091 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18092 +               return -EFAULT;
18093 +
18094 +       ret = user_lpath(vc_data.name, &path);
18095 +       if (!ret) {
18096 +               ret = __vc_get_iattr(path.dentry->d_inode,
18097 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18098 +               path_put(&path);
18099 +       }
18100 +       if (ret)
18101 +               return ret;
18102 +
18103 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18104 +               ret = -EFAULT;
18105 +       return ret;
18106 +}
18107 +
18108 +#ifdef CONFIG_COMPAT
18109 +
18110 +int vc_get_iattr_x32(void __user *data)
18111 +{
18112 +       struct path path;
18113 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
18114 +       int ret;
18115 +
18116 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18117 +               return -EFAULT;
18118 +
18119 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18120 +       if (!ret) {
18121 +               ret = __vc_get_iattr(path.dentry->d_inode,
18122 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18123 +               path_put(&path);
18124 +       }
18125 +       if (ret)
18126 +               return ret;
18127 +
18128 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18129 +               ret = -EFAULT;
18130 +       return ret;
18131 +}
18132 +
18133 +#endif /* CONFIG_COMPAT */
18134 +
18135 +
18136 +int vc_fget_iattr(uint32_t fd, void __user *data)
18137 +{
18138 +       struct file *filp;
18139 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
18140 +       int ret;
18141 +
18142 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18143 +               return -EFAULT;
18144 +
18145 +       filp = fget(fd);
18146 +       if (!filp || !filp->f_path.dentry || !filp->f_path.dentry->d_inode)
18147 +               return -EBADF;
18148 +
18149 +       ret = __vc_get_iattr(filp->f_path.dentry->d_inode,
18150 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
18151 +
18152 +       fput(filp);
18153 +
18154 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18155 +               ret = -EFAULT;
18156 +       return ret;
18157 +}
18158 +
18159 +
18160 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18161 +{
18162 +       struct inode *in = de->d_inode;
18163 +       int error = 0, is_proc = 0, has_tag = 0;
18164 +       struct iattr attr = { 0 };
18165 +
18166 +       if (!in || !in->i_sb)
18167 +               return -ESRCH;
18168 +
18169 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
18170 +       if ((*mask & IATTR_FLAGS) && !is_proc)
18171 +               return -EINVAL;
18172 +
18173 +       has_tag = IS_TAGGED(in) ||
18174 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
18175 +       if ((*mask & IATTR_TAG) && !has_tag)
18176 +               return -EINVAL;
18177 +
18178 +       mutex_lock(&in->i_mutex);
18179 +       if (*mask & IATTR_TAG) {
18180 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
18181 +               attr.ia_valid |= ATTR_TAG;
18182 +       }
18183 +
18184 +       if (*mask & IATTR_FLAGS) {
18185 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
18186 +               unsigned int iflags = PROC_I(in)->vx_flags;
18187 +
18188 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
18189 +                       | (*flags & IATTR_FLAGS);
18190 +               PROC_I(in)->vx_flags = iflags;
18191 +               if (entry)
18192 +                       entry->vx_flags = iflags;
18193 +       }
18194 +
18195 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
18196 +               IATTR_BARRIER | IATTR_COW)) {
18197 +               int iflags = in->i_flags;
18198 +               int vflags = in->i_vflags;
18199 +
18200 +               if (*mask & IATTR_IMMUTABLE) {
18201 +                       if (*flags & IATTR_IMMUTABLE)
18202 +                               iflags |= S_IMMUTABLE;
18203 +                       else
18204 +                               iflags &= ~S_IMMUTABLE;
18205 +               }
18206 +               if (*mask & IATTR_IXUNLINK) {
18207 +                       if (*flags & IATTR_IXUNLINK)
18208 +                               iflags |= S_IXUNLINK;
18209 +                       else
18210 +                               iflags &= ~S_IXUNLINK;
18211 +               }
18212 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
18213 +                       if (*flags & IATTR_BARRIER)
18214 +                               vflags |= V_BARRIER;
18215 +                       else
18216 +                               vflags &= ~V_BARRIER;
18217 +               }
18218 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
18219 +                       if (*flags & IATTR_COW)
18220 +                               vflags |= V_COW;
18221 +                       else
18222 +                               vflags &= ~V_COW;
18223 +               }
18224 +               if (in->i_op && in->i_op->sync_flags) {
18225 +                       error = in->i_op->sync_flags(in, iflags, vflags);
18226 +                       if (error)
18227 +                               goto out;
18228 +               }
18229 +       }
18230 +
18231 +       if (attr.ia_valid) {
18232 +               if (in->i_op && in->i_op->setattr)
18233 +                       error = in->i_op->setattr(de, &attr);
18234 +               else {
18235 +                       error = inode_change_ok(in, &attr);
18236 +                       if (!error) {
18237 +                               setattr_copy(in, &attr);
18238 +                               mark_inode_dirty(in);
18239 +                       }
18240 +               }
18241 +       }
18242 +
18243 +out:
18244 +       mutex_unlock(&in->i_mutex);
18245 +       return error;
18246 +}
18247 +
18248 +int vc_set_iattr(void __user *data)
18249 +{
18250 +       struct path path;
18251 +       struct vcmd_ctx_iattr_v1 vc_data;
18252 +       int ret;
18253 +
18254 +       if (!capable(CAP_LINUX_IMMUTABLE))
18255 +               return -EPERM;
18256 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18257 +               return -EFAULT;
18258 +
18259 +       ret = user_lpath(vc_data.name, &path);
18260 +       if (!ret) {
18261 +               ret = __vc_set_iattr(path.dentry,
18262 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18263 +               path_put(&path);
18264 +       }
18265 +
18266 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18267 +               ret = -EFAULT;
18268 +       return ret;
18269 +}
18270 +
18271 +#ifdef CONFIG_COMPAT
18272 +
18273 +int vc_set_iattr_x32(void __user *data)
18274 +{
18275 +       struct path path;
18276 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
18277 +       int ret;
18278 +
18279 +       if (!capable(CAP_LINUX_IMMUTABLE))
18280 +               return -EPERM;
18281 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18282 +               return -EFAULT;
18283 +
18284 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18285 +       if (!ret) {
18286 +               ret = __vc_set_iattr(path.dentry,
18287 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18288 +               path_put(&path);
18289 +       }
18290 +
18291 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18292 +               ret = -EFAULT;
18293 +       return ret;
18294 +}
18295 +
18296 +#endif /* CONFIG_COMPAT */
18297 +
18298 +int vc_fset_iattr(uint32_t fd, void __user *data)
18299 +{
18300 +       struct file *filp;
18301 +       struct vcmd_ctx_fiattr_v0 vc_data;
18302 +       int ret;
18303 +
18304 +       if (!capable(CAP_LINUX_IMMUTABLE))
18305 +               return -EPERM;
18306 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18307 +               return -EFAULT;
18308 +
18309 +       filp = fget(fd);
18310 +       if (!filp || !filp->f_path.dentry || !filp->f_path.dentry->d_inode)
18311 +               return -EBADF;
18312 +
18313 +       ret = __vc_set_iattr(filp->f_path.dentry, &vc_data.tag,
18314 +               &vc_data.flags, &vc_data.mask);
18315 +
18316 +       fput(filp);
18317 +
18318 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18319 +               return -EFAULT;
18320 +       return ret;
18321 +}
18322 +
18323 +
18324 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
18325 +
18326 +static match_table_t tokens = {
18327 +       {Opt_notagcheck, "notagcheck"},
18328 +#ifdef CONFIG_PROPAGATE
18329 +       {Opt_notag, "notag"},
18330 +       {Opt_tag, "tag"},
18331 +       {Opt_tagid, "tagid=%u"},
18332 +#endif
18333 +       {Opt_err, NULL}
18334 +};
18335 +
18336 +
18337 +static void __dx_parse_remove(char *string, char *opt)
18338 +{
18339 +       char *p = strstr(string, opt);
18340 +       char *q = p;
18341 +
18342 +       if (p) {
18343 +               while (*q != '\0' && *q != ',')
18344 +                       q++;
18345 +               while (*q)
18346 +                       *p++ = *q++;
18347 +               while (*p)
18348 +                       *p++ = '\0';
18349 +       }
18350 +}
18351 +
18352 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
18353 +                unsigned long *flags)
18354 +{
18355 +       int set = 0;
18356 +       substring_t args[MAX_OPT_ARGS];
18357 +       int token;
18358 +       char *s, *p, *opts;
18359 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
18360 +       int option = 0;
18361 +#endif
18362 +
18363 +       if (!string)
18364 +               return 0;
18365 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
18366 +       if (!s)
18367 +               return 0;
18368 +
18369 +       opts = s;
18370 +       while ((p = strsep(&opts, ",")) != NULL) {
18371 +               token = match_token(p, tokens, args);
18372 +
18373 +               switch (token) {
18374 +#ifdef CONFIG_PROPAGATE
18375 +               case Opt_tag:
18376 +                       if (tag)
18377 +                               *tag = 0;
18378 +                       if (remove)
18379 +                               __dx_parse_remove(s, "tag");
18380 +                       *mnt_flags |= MNT_TAGID;
18381 +                       set |= MNT_TAGID;
18382 +                       break;
18383 +               case Opt_notag:
18384 +                       if (remove)
18385 +                               __dx_parse_remove(s, "notag");
18386 +                       *mnt_flags |= MNT_NOTAG;
18387 +                       set |= MNT_NOTAG;
18388 +                       break;
18389 +               case Opt_tagid:
18390 +                       if (tag && !match_int(args, &option))
18391 +                               *tag = option;
18392 +                       if (remove)
18393 +                               __dx_parse_remove(s, "tagid");
18394 +                       *mnt_flags |= MNT_TAGID;
18395 +                       set |= MNT_TAGID;
18396 +                       break;
18397 +#endif /* CONFIG_PROPAGATE */
18398 +               case Opt_notagcheck:
18399 +                       if (remove)
18400 +                               __dx_parse_remove(s, "notagcheck");
18401 +                       *flags |= MS_NOTAGCHECK;
18402 +                       set |= MS_NOTAGCHECK;
18403 +                       break;
18404 +               }
18405 +               vxdprintk(VXD_CBIT(tag, 7),
18406 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
18407 +                       p, token, option);
18408 +       }
18409 +       if (set)
18410 +               strcpy(string, s);
18411 +       kfree(s);
18412 +       return set;
18413 +}
18414 +
18415 +#ifdef CONFIG_PROPAGATE
18416 +
18417 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
18418 +{
18419 +       vtag_t new_tag = 0;
18420 +       struct vfsmount *mnt;
18421 +       int propagate;
18422 +
18423 +       if (!nd)
18424 +               return;
18425 +       mnt = nd->path.mnt;
18426 +       if (!mnt)
18427 +               return;
18428 +
18429 +       propagate = (mnt->mnt_flags & MNT_TAGID);
18430 +       if (propagate)
18431 +               new_tag = mnt->mnt_tag;
18432 +
18433 +       vxdprintk(VXD_CBIT(tag, 7),
18434 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
18435 +               inode, inode->i_ino, inode->i_tag,
18436 +               new_tag, (propagate) ? 1 : 0);
18437 +
18438 +       if (propagate)
18439 +               i_tag_write(inode, new_tag);
18440 +}
18441 +
18442 +#include <linux/module.h>
18443 +
18444 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
18445 +
18446 +#endif /* CONFIG_PROPAGATE */
18447 +
18448 diff -NurpP --minimal linux-4.4.161/kernel/vserver/limit.c linux-4.4.161-vs2.3.9.8/kernel/vserver/limit.c
18449 --- linux-4.4.161/kernel/vserver/limit.c        1970-01-01 00:00:00.000000000 +0000
18450 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/limit.c      2018-10-20 04:57:21.000000000 +0000
18451 @@ -0,0 +1,386 @@
18452 +/*
18453 + *  linux/kernel/vserver/limit.c
18454 + *
18455 + *  Virtual Server: Context Limits
18456 + *
18457 + *  Copyright (C) 2004-2010  Herbert P?tzl
18458 + *
18459 + *  V0.01  broken out from vcontext V0.05
18460 + *  V0.02  changed vcmds to vxi arg
18461 + *  V0.03  added memory cgroup support
18462 + *
18463 + */
18464 +
18465 +#include <linux/sched.h>
18466 +#include <linux/module.h>
18467 +#include <linux/memcontrol.h>
18468 +#include <linux/page_counter.h>
18469 +#include <linux/vs_limit.h>
18470 +#include <linux/vserver/limit.h>
18471 +#include <linux/vserver/limit_cmd.h>
18472 +
18473 +#include <asm/uaccess.h>
18474 +
18475 +
18476 +const char *vlimit_name[NUM_LIMITS] = {
18477 +       [RLIMIT_CPU]            = "CPU",
18478 +       [RLIMIT_NPROC]          = "NPROC",
18479 +       [RLIMIT_NOFILE]         = "NOFILE",
18480 +       [RLIMIT_LOCKS]          = "LOCKS",
18481 +       [RLIMIT_SIGPENDING]     = "SIGP",
18482 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
18483 +
18484 +       [VLIMIT_NSOCK]          = "NSOCK",
18485 +       [VLIMIT_OPENFD]         = "OPENFD",
18486 +       [VLIMIT_SHMEM]          = "SHMEM",
18487 +       [VLIMIT_DENTRY]         = "DENTRY",
18488 +};
18489 +
18490 +EXPORT_SYMBOL_GPL(vlimit_name);
18491 +
18492 +#define MASK_ENTRY(x)  (1 << (x))
18493 +
18494 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
18495 +               /* minimum */
18496 +       0
18497 +       ,       /* softlimit */
18498 +       0
18499 +       ,       /* maximum */
18500 +       MASK_ENTRY( RLIMIT_NPROC        ) |
18501 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
18502 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
18503 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
18504 +
18505 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
18506 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
18507 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
18508 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
18509 +       0
18510 +};
18511 +               /* accounting only */
18512 +uint32_t account_mask =
18513 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
18514 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
18515 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
18516 +       0;
18517 +
18518 +
18519 +static int is_valid_vlimit(int id)
18520 +{
18521 +       uint32_t mask = vlimit_mask.minimum |
18522 +               vlimit_mask.softlimit | vlimit_mask.maximum;
18523 +       return mask & (1 << id);
18524 +}
18525 +
18526 +static int is_accounted_vlimit(int id)
18527 +{
18528 +       if (is_valid_vlimit(id))
18529 +               return 1;
18530 +       return account_mask & (1 << id);
18531 +}
18532 +
18533 +
18534 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
18535 +{
18536 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
18537 +       return VX_VLIM(limit);
18538 +}
18539 +
18540 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
18541 +{
18542 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
18543 +       return VX_VLIM(limit);
18544 +}
18545 +
18546 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
18547 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
18548 +{
18549 +       if (!is_valid_vlimit(id))
18550 +               return -EINVAL;
18551 +
18552 +       if (minimum)
18553 +               *minimum = CRLIM_UNSET;
18554 +       if (softlimit)
18555 +               *softlimit = vc_get_soft(vxi, id);
18556 +       if (maximum)
18557 +               *maximum = vc_get_hard(vxi, id);
18558 +       return 0;
18559 +}
18560 +
18561 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
18562 +{
18563 +       struct vcmd_ctx_rlimit_v0 vc_data;
18564 +       int ret;
18565 +
18566 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18567 +               return -EFAULT;
18568 +
18569 +       ret = do_get_rlimit(vxi, vc_data.id,
18570 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18571 +       if (ret)
18572 +               return ret;
18573 +
18574 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18575 +               return -EFAULT;
18576 +       return 0;
18577 +}
18578 +
18579 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
18580 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
18581 +{
18582 +       if (!is_valid_vlimit(id))
18583 +               return -EINVAL;
18584 +
18585 +       if (maximum != CRLIM_KEEP)
18586 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
18587 +       if (softlimit != CRLIM_KEEP)
18588 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
18589 +
18590 +       /* clamp soft limit */
18591 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
18592 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
18593 +
18594 +       return 0;
18595 +}
18596 +
18597 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
18598 +{
18599 +       struct vcmd_ctx_rlimit_v0 vc_data;
18600 +
18601 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18602 +               return -EFAULT;
18603 +
18604 +       return do_set_rlimit(vxi, vc_data.id,
18605 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18606 +}
18607 +
18608 +#ifdef CONFIG_IA32_EMULATION
18609 +
18610 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
18611 +{
18612 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18613 +
18614 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18615 +               return -EFAULT;
18616 +
18617 +       return do_set_rlimit(vxi, vc_data.id,
18618 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18619 +}
18620 +
18621 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
18622 +{
18623 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18624 +       int ret;
18625 +
18626 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18627 +               return -EFAULT;
18628 +
18629 +       ret = do_get_rlimit(vxi, vc_data.id,
18630 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18631 +       if (ret)
18632 +               return ret;
18633 +
18634 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18635 +               return -EFAULT;
18636 +       return 0;
18637 +}
18638 +
18639 +#endif /* CONFIG_IA32_EMULATION */
18640 +
18641 +
18642 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
18643 +{
18644 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
18645 +               return -EFAULT;
18646 +       return 0;
18647 +}
18648 +
18649 +
18650 +static inline void vx_reset_hits(struct _vx_limit *limit)
18651 +{
18652 +       int lim;
18653 +
18654 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18655 +               atomic_set(&__rlim_lhit(limit, lim), 0);
18656 +       }
18657 +}
18658 +
18659 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
18660 +{
18661 +       vx_reset_hits(&vxi->limit);
18662 +       return 0;
18663 +}
18664 +
18665 +static inline void vx_reset_minmax(struct _vx_limit *limit)
18666 +{
18667 +       rlim_t value;
18668 +       int lim;
18669 +
18670 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18671 +               value = __rlim_get(limit, lim);
18672 +               __rlim_rmax(limit, lim) = value;
18673 +               __rlim_rmin(limit, lim) = value;
18674 +       }
18675 +}
18676 +
18677 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
18678 +{
18679 +       vx_reset_minmax(&vxi->limit);
18680 +       return 0;
18681 +}
18682 +
18683 +
18684 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
18685 +{
18686 +       struct vcmd_rlimit_stat_v0 vc_data;
18687 +       struct _vx_limit *limit = &vxi->limit;
18688 +       int id;
18689 +
18690 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18691 +               return -EFAULT;
18692 +
18693 +       id = vc_data.id;
18694 +       if (!is_accounted_vlimit(id))
18695 +               return -EINVAL;
18696 +
18697 +       vx_limit_fixup(limit, id);
18698 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
18699 +       vc_data.value = __rlim_get(limit, id);
18700 +       vc_data.minimum = __rlim_rmin(limit, id);
18701 +       vc_data.maximum = __rlim_rmax(limit, id);
18702 +
18703 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18704 +               return -EFAULT;
18705 +       return 0;
18706 +}
18707 +
18708 +
18709 +#ifdef CONFIG_MEMCG
18710 +
18711 +void dump_sysinfo(struct sysinfo *si)
18712 +{
18713 +       printk(KERN_INFO "sysinfo: memunit=%u\n"
18714 +               "\ttotalram:\t%lu\n"
18715 +               "\tfreeram:\t%lu\n"
18716 +               "\tsharedram:\t%lu\n"
18717 +               "\tbufferram:\t%lu\n"
18718 +               "\ttotalswap:\t%lu\n"
18719 +               "\tfreeswap:\t%lu\n"
18720 +               "\ttotalhigh:\t%lu\n"
18721 +               "\tfreehigh:\t%lu\n",
18722 +               si->mem_unit,
18723 +               si->totalram,
18724 +               si->freeram,
18725 +               si->sharedram,
18726 +               si->bufferram,
18727 +               si->totalswap,
18728 +               si->freeswap,
18729 +               si->totalhigh,
18730 +               si->freehigh);
18731 +}
18732 +
18733 +void vx_vsi_meminfo(struct sysinfo *val)
18734 +{
18735 +       struct mem_cgroup *mcg;
18736 +       unsigned long res_limit, res_usage;
18737 +       unsigned shift;
18738 +
18739 +       if (VXD_CBIT(cvirt, 4))
18740 +               dump_sysinfo(val);
18741 +
18742 +       rcu_read_lock();
18743 +       mcg = mem_cgroup_from_task(current);
18744 +       if (VXD_CBIT(cvirt, 5))
18745 +               dump_mem_cgroup(mcg);
18746 +       rcu_read_unlock();
18747 +       if (!mcg)
18748 +               goto out;
18749 +
18750 +       res_limit = mem_cgroup_mem_limit_pages(mcg);
18751 +       res_usage = mem_cgroup_mem_usage_pages(mcg);
18752 +       shift = val->mem_unit == 1 ? PAGE_SHIFT : 0;
18753 +
18754 +       if (res_limit != PAGE_COUNTER_MAX)
18755 +               val->totalram = res_limit << shift;
18756 +       val->freeram = val->totalram - (res_usage << shift);
18757 +       val->bufferram = 0;
18758 +       val->totalhigh = 0;
18759 +       val->freehigh = 0;
18760 +out:
18761 +       return;
18762 +}
18763 +
18764 +void vx_vsi_swapinfo(struct sysinfo *val)
18765 +{
18766 +#ifdef CONFIG_MEMCG_SWAP
18767 +       struct mem_cgroup *mcg;
18768 +       unsigned long res_limit, res_usage, memsw_limit, memsw_usage;
18769 +       signed long swap_limit, swap_usage;
18770 +       unsigned shift;
18771 +
18772 +       if (VXD_CBIT(cvirt, 6))
18773 +               dump_sysinfo(val);
18774 +
18775 +       rcu_read_lock();
18776 +       mcg = mem_cgroup_from_task(current);
18777 +       if (VXD_CBIT(cvirt, 7))
18778 +               dump_mem_cgroup(mcg);
18779 +       rcu_read_unlock();
18780 +       if (!mcg)
18781 +               goto out;
18782 +
18783 +       res_limit = mem_cgroup_mem_limit_pages(mcg);
18784 +
18785 +       /* memory unlimited */
18786 +       if (res_limit == PAGE_COUNTER_MAX)
18787 +               goto out;
18788 +
18789 +       res_usage = mem_cgroup_mem_usage_pages(mcg);
18790 +       memsw_limit = mem_cgroup_memsw_limit_pages(mcg);
18791 +       memsw_usage = mem_cgroup_memsw_usage_pages(mcg);
18792 +       shift = val->mem_unit == 1 ? PAGE_SHIFT : 0;
18793 +
18794 +       swap_limit = memsw_limit - res_limit;
18795 +       /* we have a swap limit? */
18796 +       if (memsw_limit != PAGE_COUNTER_MAX)
18797 +               val->totalswap = swap_limit << shift;
18798 +
18799 +       /* calculate swap part */
18800 +       swap_usage = (memsw_usage > res_usage) ?
18801 +               memsw_usage - res_usage : 0;
18802 +
18803 +       /* total shown minus usage gives free swap */
18804 +       val->freeswap = (swap_usage < swap_limit) ?
18805 +               val->totalswap - (swap_usage << shift) : 0;
18806 +out:
18807 +#else  /* !CONFIG_MEMCG_SWAP */
18808 +       val->totalswap = 0;
18809 +       val->freeswap = 0;
18810 +#endif /* !CONFIG_MEMCG_SWAP */
18811 +       return;
18812 +}
18813 +
18814 +long vx_vsi_cached(struct sysinfo *val)
18815 +{
18816 +       long cache = 0;
18817 +#ifdef CONFIG_MEMCG_BROKEN
18818 +       struct mem_cgroup *mcg;
18819 +
18820 +       if (VXD_CBIT(cvirt, 8))
18821 +               dump_sysinfo(val);
18822 +
18823 +       rcu_read_lock();
18824 +       mcg = mem_cgroup_from_task(current);
18825 +       if (VXD_CBIT(cvirt, 9))
18826 +               dump_mem_cgroup(mcg);
18827 +       rcu_read_unlock();
18828 +       if (!mcg)
18829 +               goto out;
18830 +
18831 +       // cache = mem_cgroup_stat_read_cache(mcg);
18832 +out:
18833 +#endif
18834 +       return cache;
18835 +}
18836 +#endif /* !CONFIG_MEMCG */
18837 +
18838 diff -NurpP --minimal linux-4.4.161/kernel/vserver/limit_init.h linux-4.4.161-vs2.3.9.8/kernel/vserver/limit_init.h
18839 --- linux-4.4.161/kernel/vserver/limit_init.h   1970-01-01 00:00:00.000000000 +0000
18840 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/limit_init.h 2018-10-20 04:57:21.000000000 +0000
18841 @@ -0,0 +1,31 @@
18842 +
18843 +
18844 +static inline void vx_info_init_limit(struct _vx_limit *limit)
18845 +{
18846 +       int lim;
18847 +
18848 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18849 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
18850 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
18851 +               __rlim_set(limit, lim, 0);
18852 +               atomic_set(&__rlim_lhit(limit, lim), 0);
18853 +               __rlim_rmin(limit, lim) = 0;
18854 +               __rlim_rmax(limit, lim) = 0;
18855 +       }
18856 +}
18857 +
18858 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
18859 +{
18860 +       rlim_t value;
18861 +       int lim;
18862 +
18863 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18864 +               if ((1 << lim) & VLIM_NOCHECK)
18865 +                       continue;
18866 +               value = __rlim_get(limit, lim);
18867 +               vxwprintk_xid(value,
18868 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
18869 +                       limit, vlimit_name[lim], lim, (long)value);
18870 +       }
18871 +}
18872 +
18873 diff -NurpP --minimal linux-4.4.161/kernel/vserver/limit_proc.h linux-4.4.161-vs2.3.9.8/kernel/vserver/limit_proc.h
18874 --- linux-4.4.161/kernel/vserver/limit_proc.h   1970-01-01 00:00:00.000000000 +0000
18875 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/limit_proc.h 2018-10-20 04:57:21.000000000 +0000
18876 @@ -0,0 +1,57 @@
18877 +#ifndef _VX_LIMIT_PROC_H
18878 +#define _VX_LIMIT_PROC_H
18879 +
18880 +#include <linux/vserver/limit_int.h>
18881 +
18882 +
18883 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
18884 +#define VX_LIMIT_TOP   \
18885 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
18886 +
18887 +#define VX_LIMIT_ARG(r)                                \
18888 +       (unsigned long)__rlim_get(limit, r),    \
18889 +       (unsigned long)__rlim_rmin(limit, r),   \
18890 +       (unsigned long)__rlim_rmax(limit, r),   \
18891 +       VX_VLIM(__rlim_soft(limit, r)),         \
18892 +       VX_VLIM(__rlim_hard(limit, r)),         \
18893 +       atomic_read(&__rlim_lhit(limit, r))
18894 +
18895 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
18896 +{
18897 +       vx_limit_fixup(limit, -1);
18898 +       return sprintf(buffer, VX_LIMIT_TOP
18899 +               "PROC"  VX_LIMIT_FMT
18900 +               "VM"    VX_LIMIT_FMT
18901 +               "VML"   VX_LIMIT_FMT
18902 +               "RSS"   VX_LIMIT_FMT
18903 +               "ANON"  VX_LIMIT_FMT
18904 +               "RMAP"  VX_LIMIT_FMT
18905 +               "FILES" VX_LIMIT_FMT
18906 +               "OFD"   VX_LIMIT_FMT
18907 +               "LOCKS" VX_LIMIT_FMT
18908 +               "SOCK"  VX_LIMIT_FMT
18909 +               "MSGQ"  VX_LIMIT_FMT
18910 +               "SHM"   VX_LIMIT_FMT
18911 +               "SEMA"  VX_LIMIT_FMT
18912 +               "SEMS"  VX_LIMIT_FMT
18913 +               "DENT"  VX_LIMIT_FMT,
18914 +               VX_LIMIT_ARG(RLIMIT_NPROC),
18915 +               VX_LIMIT_ARG(RLIMIT_AS),
18916 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
18917 +               VX_LIMIT_ARG(RLIMIT_RSS),
18918 +               VX_LIMIT_ARG(VLIMIT_ANON),
18919 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
18920 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
18921 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
18922 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
18923 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
18924 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
18925 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
18926 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
18927 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
18928 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
18929 +}
18930 +
18931 +#endif /* _VX_LIMIT_PROC_H */
18932 +
18933 +
18934 diff -NurpP --minimal linux-4.4.161/kernel/vserver/network.c linux-4.4.161-vs2.3.9.8/kernel/vserver/network.c
18935 --- linux-4.4.161/kernel/vserver/network.c      1970-01-01 00:00:00.000000000 +0000
18936 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/network.c    2018-10-20 04:57:21.000000000 +0000
18937 @@ -0,0 +1,1053 @@
18938 +/*
18939 + *  linux/kernel/vserver/network.c
18940 + *
18941 + *  Virtual Server: Network Support
18942 + *
18943 + *  Copyright (C) 2003-2007  Herbert P?tzl
18944 + *
18945 + *  V0.01  broken out from vcontext V0.05
18946 + *  V0.02  cleaned up implementation
18947 + *  V0.03  added equiv nx commands
18948 + *  V0.04  switch to RCU based hash
18949 + *  V0.05  and back to locking again
18950 + *  V0.06  changed vcmds to nxi arg
18951 + *  V0.07  have __create claim() the nxi
18952 + *
18953 + */
18954 +
18955 +#include <linux/err.h>
18956 +#include <linux/slab.h>
18957 +#include <linux/rcupdate.h>
18958 +#include <net/ipv6.h>
18959 +
18960 +#include <linux/vs_network.h>
18961 +#include <linux/vs_pid.h>
18962 +#include <linux/vserver/network_cmd.h>
18963 +
18964 +
18965 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
18966 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
18967 +
18968 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
18969 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
18970 +
18971 +
18972 +static int __init init_network(void)
18973 +{
18974 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
18975 +               sizeof(struct nx_addr_v4), 0,
18976 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18977 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
18978 +               sizeof(struct nx_addr_v6), 0,
18979 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18980 +       return 0;
18981 +}
18982 +
18983 +
18984 +/*     __alloc_nx_addr_v4()                                    */
18985 +
18986 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
18987 +{
18988 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
18989 +               nx_addr_v4_cachep, GFP_KERNEL);
18990 +
18991 +       if (!IS_ERR(nxa))
18992 +               memset(nxa, 0, sizeof(*nxa));
18993 +       return nxa;
18994 +}
18995 +
18996 +/*     __dealloc_nx_addr_v4()                                  */
18997 +
18998 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
18999 +{
19000 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19001 +}
19002 +
19003 +/*     __dealloc_nx_addr_v4_all()                              */
19004 +
19005 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19006 +{
19007 +       while (nxa) {
19008 +               struct nx_addr_v4 *next = nxa->next;
19009 +
19010 +               __dealloc_nx_addr_v4(nxa);
19011 +               nxa = next;
19012 +       }
19013 +}
19014 +
19015 +
19016 +#ifdef CONFIG_IPV6
19017 +
19018 +/*     __alloc_nx_addr_v6()                                    */
19019 +
19020 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19021 +{
19022 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19023 +               nx_addr_v6_cachep, GFP_KERNEL);
19024 +
19025 +       if (!IS_ERR(nxa))
19026 +               memset(nxa, 0, sizeof(*nxa));
19027 +       return nxa;
19028 +}
19029 +
19030 +/*     __dealloc_nx_addr_v6()                                  */
19031 +
19032 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19033 +{
19034 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19035 +}
19036 +
19037 +/*     __dealloc_nx_addr_v6_all()                              */
19038 +
19039 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19040 +{
19041 +       while (nxa) {
19042 +               struct nx_addr_v6 *next = nxa->next;
19043 +
19044 +               __dealloc_nx_addr_v6(nxa);
19045 +               nxa = next;
19046 +       }
19047 +}
19048 +
19049 +#endif /* CONFIG_IPV6 */
19050 +
19051 +/*     __alloc_nx_info()
19052 +
19053 +       * allocate an initialized nx_info struct
19054 +       * doesn't make it visible (hash)                        */
19055 +
19056 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19057 +{
19058 +       struct nx_info *new = NULL;
19059 +
19060 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19061 +
19062 +       /* would this benefit from a slab cache? */
19063 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19064 +       if (!new)
19065 +               return 0;
19066 +
19067 +       memset(new, 0, sizeof(struct nx_info));
19068 +       new->nx_id = nid;
19069 +       INIT_HLIST_NODE(&new->nx_hlist);
19070 +       atomic_set(&new->nx_usecnt, 0);
19071 +       atomic_set(&new->nx_tasks, 0);
19072 +       spin_lock_init(&new->addr_lock);
19073 +       new->nx_state = 0;
19074 +
19075 +       new->nx_flags = NXF_INIT_SET;
19076 +
19077 +       /* rest of init goes here */
19078 +
19079 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19080 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19081 +
19082 +       vxdprintk(VXD_CBIT(nid, 0),
19083 +               "alloc_nx_info(%d) = %p", nid, new);
19084 +       atomic_inc(&nx_global_ctotal);
19085 +       return new;
19086 +}
19087 +
19088 +/*     __dealloc_nx_info()
19089 +
19090 +       * final disposal of nx_info                             */
19091 +
19092 +static void __dealloc_nx_info(struct nx_info *nxi)
19093 +{
19094 +       vxdprintk(VXD_CBIT(nid, 0),
19095 +               "dealloc_nx_info(%p)", nxi);
19096 +
19097 +       nxi->nx_hlist.next = LIST_POISON1;
19098 +       nxi->nx_id = -1;
19099 +
19100 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19101 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19102 +
19103 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
19104 +#ifdef CONFIG_IPV6
19105 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
19106 +#endif
19107 +
19108 +       nxi->nx_state |= NXS_RELEASED;
19109 +       kfree(nxi);
19110 +       atomic_dec(&nx_global_ctotal);
19111 +}
19112 +
19113 +static void __shutdown_nx_info(struct nx_info *nxi)
19114 +{
19115 +       nxi->nx_state |= NXS_SHUTDOWN;
19116 +       vs_net_change(nxi, VSC_NETDOWN);
19117 +}
19118 +
19119 +/*     exported stuff                                          */
19120 +
19121 +void free_nx_info(struct nx_info *nxi)
19122 +{
19123 +       /* context shutdown is mandatory */
19124 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
19125 +
19126 +       /* context must not be hashed */
19127 +       BUG_ON(nxi->nx_state & NXS_HASHED);
19128 +
19129 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19130 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19131 +
19132 +       __dealloc_nx_info(nxi);
19133 +}
19134 +
19135 +
19136 +void __nx_set_lback(struct nx_info *nxi)
19137 +{
19138 +       int nid = nxi->nx_id;
19139 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
19140 +
19141 +       nxi->v4_lback.s_addr = lback;
19142 +}
19143 +
19144 +extern int __nx_inet_add_lback(__be32 addr);
19145 +extern int __nx_inet_del_lback(__be32 addr);
19146 +
19147 +
19148 +/*     hash table for nx_info hash */
19149 +
19150 +#define NX_HASH_SIZE   13
19151 +
19152 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
19153 +
19154 +static DEFINE_SPINLOCK(nx_info_hash_lock);
19155 +
19156 +
19157 +static inline unsigned int __hashval(vnid_t nid)
19158 +{
19159 +       return (nid % NX_HASH_SIZE);
19160 +}
19161 +
19162 +
19163 +
19164 +/*     __hash_nx_info()
19165 +
19166 +       * add the nxi to the global hash table
19167 +       * requires the hash_lock to be held                     */
19168 +
19169 +static inline void __hash_nx_info(struct nx_info *nxi)
19170 +{
19171 +       struct hlist_head *head;
19172 +
19173 +       vxd_assert_lock(&nx_info_hash_lock);
19174 +       vxdprintk(VXD_CBIT(nid, 4),
19175 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
19176 +
19177 +       /* context must not be hashed */
19178 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
19179 +
19180 +       nxi->nx_state |= NXS_HASHED;
19181 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
19182 +       hlist_add_head(&nxi->nx_hlist, head);
19183 +       atomic_inc(&nx_global_cactive);
19184 +}
19185 +
19186 +/*     __unhash_nx_info()
19187 +
19188 +       * remove the nxi from the global hash table
19189 +       * requires the hash_lock to be held                     */
19190 +
19191 +static inline void __unhash_nx_info(struct nx_info *nxi)
19192 +{
19193 +       vxd_assert_lock(&nx_info_hash_lock);
19194 +       vxdprintk(VXD_CBIT(nid, 4),
19195 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
19196 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
19197 +
19198 +       /* context must be hashed */
19199 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
19200 +       /* but without tasks */
19201 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19202 +
19203 +       nxi->nx_state &= ~NXS_HASHED;
19204 +       hlist_del(&nxi->nx_hlist);
19205 +       atomic_dec(&nx_global_cactive);
19206 +}
19207 +
19208 +
19209 +/*     __lookup_nx_info()
19210 +
19211 +       * requires the hash_lock to be held
19212 +       * doesn't increment the nx_refcnt                       */
19213 +
19214 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
19215 +{
19216 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
19217 +       struct hlist_node *pos;
19218 +       struct nx_info *nxi;
19219 +
19220 +       vxd_assert_lock(&nx_info_hash_lock);
19221 +       hlist_for_each(pos, head) {
19222 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19223 +
19224 +               if (nxi->nx_id == nid)
19225 +                       goto found;
19226 +       }
19227 +       nxi = NULL;
19228 +found:
19229 +       vxdprintk(VXD_CBIT(nid, 0),
19230 +               "__lookup_nx_info(#%u): %p[#%u]",
19231 +               nid, nxi, nxi ? nxi->nx_id : 0);
19232 +       return nxi;
19233 +}
19234 +
19235 +
19236 +/*     __create_nx_info()
19237 +
19238 +       * create the requested context
19239 +       * get(), claim() and hash it                            */
19240 +
19241 +static struct nx_info *__create_nx_info(int id)
19242 +{
19243 +       struct nx_info *new, *nxi = NULL;
19244 +
19245 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
19246 +
19247 +       if (!(new = __alloc_nx_info(id)))
19248 +               return ERR_PTR(-ENOMEM);
19249 +
19250 +       /* required to make dynamic xids unique */
19251 +       spin_lock(&nx_info_hash_lock);
19252 +
19253 +       /* static context requested */
19254 +       if ((nxi = __lookup_nx_info(id))) {
19255 +               vxdprintk(VXD_CBIT(nid, 0),
19256 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
19257 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19258 +                       nxi = ERR_PTR(-EBUSY);
19259 +               else
19260 +                       nxi = ERR_PTR(-EEXIST);
19261 +               goto out_unlock;
19262 +       }
19263 +       /* new context */
19264 +       vxdprintk(VXD_CBIT(nid, 0),
19265 +               "create_nx_info(%d) = %p (new)", id, new);
19266 +       claim_nx_info(new, NULL);
19267 +       __nx_set_lback(new);
19268 +       __hash_nx_info(get_nx_info(new));
19269 +       nxi = new, new = NULL;
19270 +
19271 +out_unlock:
19272 +       spin_unlock(&nx_info_hash_lock);
19273 +       if (new)
19274 +               __dealloc_nx_info(new);
19275 +       return nxi;
19276 +}
19277 +
19278 +
19279 +
19280 +/*     exported stuff                                          */
19281 +
19282 +
19283 +void unhash_nx_info(struct nx_info *nxi)
19284 +{
19285 +       __shutdown_nx_info(nxi);
19286 +       spin_lock(&nx_info_hash_lock);
19287 +       __unhash_nx_info(nxi);
19288 +       spin_unlock(&nx_info_hash_lock);
19289 +}
19290 +
19291 +/*     lookup_nx_info()
19292 +
19293 +       * search for a nx_info and get() it
19294 +       * negative id means current                             */
19295 +
19296 +struct nx_info *lookup_nx_info(int id)
19297 +{
19298 +       struct nx_info *nxi = NULL;
19299 +
19300 +       if (id < 0) {
19301 +               nxi = get_nx_info(current_nx_info());
19302 +       } else if (id > 1) {
19303 +               spin_lock(&nx_info_hash_lock);
19304 +               nxi = get_nx_info(__lookup_nx_info(id));
19305 +               spin_unlock(&nx_info_hash_lock);
19306 +       }
19307 +       return nxi;
19308 +}
19309 +
19310 +/*     nid_is_hashed()
19311 +
19312 +       * verify that nid is still hashed                       */
19313 +
19314 +int nid_is_hashed(vnid_t nid)
19315 +{
19316 +       int hashed;
19317 +
19318 +       spin_lock(&nx_info_hash_lock);
19319 +       hashed = (__lookup_nx_info(nid) != NULL);
19320 +       spin_unlock(&nx_info_hash_lock);
19321 +       return hashed;
19322 +}
19323 +
19324 +
19325 +#ifdef CONFIG_PROC_FS
19326 +
19327 +/*     get_nid_list()
19328 +
19329 +       * get a subset of hashed nids for proc
19330 +       * assumes size is at least one                          */
19331 +
19332 +int get_nid_list(int index, unsigned int *nids, int size)
19333 +{
19334 +       int hindex, nr_nids = 0;
19335 +
19336 +       /* only show current and children */
19337 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
19338 +               if (index > 0)
19339 +                       return 0;
19340 +               nids[nr_nids] = nx_current_nid();
19341 +               return 1;
19342 +       }
19343 +
19344 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
19345 +               struct hlist_head *head = &nx_info_hash[hindex];
19346 +               struct hlist_node *pos;
19347 +
19348 +               spin_lock(&nx_info_hash_lock);
19349 +               hlist_for_each(pos, head) {
19350 +                       struct nx_info *nxi;
19351 +
19352 +                       if (--index > 0)
19353 +                               continue;
19354 +
19355 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19356 +                       nids[nr_nids] = nxi->nx_id;
19357 +                       if (++nr_nids >= size) {
19358 +                               spin_unlock(&nx_info_hash_lock);
19359 +                               goto out;
19360 +                       }
19361 +               }
19362 +               /* keep the lock time short */
19363 +               spin_unlock(&nx_info_hash_lock);
19364 +       }
19365 +out:
19366 +       return nr_nids;
19367 +}
19368 +#endif
19369 +
19370 +
19371 +/*
19372 + *     migrate task to new network
19373 + *     gets nxi, puts old_nxi on change
19374 + */
19375 +
19376 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
19377 +{
19378 +       struct nx_info *old_nxi;
19379 +       int ret = 0;
19380 +
19381 +       if (!p || !nxi)
19382 +               BUG();
19383 +
19384 +       vxdprintk(VXD_CBIT(nid, 5),
19385 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
19386 +               p, nxi, nxi->nx_id,
19387 +               atomic_read(&nxi->nx_usecnt),
19388 +               atomic_read(&nxi->nx_tasks));
19389 +
19390 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
19391 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19392 +               return -EACCES;
19393 +
19394 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
19395 +               return -EFAULT;
19396 +
19397 +       /* maybe disallow this completely? */
19398 +       old_nxi = task_get_nx_info(p);
19399 +       if (old_nxi == nxi)
19400 +               goto out;
19401 +
19402 +       task_lock(p);
19403 +       if (old_nxi)
19404 +               clr_nx_info(&p->nx_info);
19405 +       claim_nx_info(nxi, p);
19406 +       set_nx_info(&p->nx_info, nxi);
19407 +       p->nid = nxi->nx_id;
19408 +       task_unlock(p);
19409 +
19410 +       vxdprintk(VXD_CBIT(nid, 5),
19411 +               "moved task %p into nxi:%p[#%d]",
19412 +               p, nxi, nxi->nx_id);
19413 +
19414 +       if (old_nxi)
19415 +               release_nx_info(old_nxi, p);
19416 +       ret = 0;
19417 +out:
19418 +       put_nx_info(old_nxi);
19419 +       return ret;
19420 +}
19421 +
19422 +
19423 +void nx_set_persistent(struct nx_info *nxi)
19424 +{
19425 +       vxdprintk(VXD_CBIT(nid, 6),
19426 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
19427 +
19428 +       get_nx_info(nxi);
19429 +       claim_nx_info(nxi, NULL);
19430 +}
19431 +
19432 +void nx_clear_persistent(struct nx_info *nxi)
19433 +{
19434 +       vxdprintk(VXD_CBIT(nid, 6),
19435 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
19436 +
19437 +       release_nx_info(nxi, NULL);
19438 +       put_nx_info(nxi);
19439 +}
19440 +
19441 +void nx_update_persistent(struct nx_info *nxi)
19442 +{
19443 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
19444 +               nx_set_persistent(nxi);
19445 +       else
19446 +               nx_clear_persistent(nxi);
19447 +}
19448 +
19449 +/* vserver syscall commands below here */
19450 +
19451 +/* taks nid and nx_info functions */
19452 +
19453 +#include <asm/uaccess.h>
19454 +
19455 +
19456 +int vc_task_nid(uint32_t id)
19457 +{
19458 +       vnid_t nid;
19459 +
19460 +       if (id) {
19461 +               struct task_struct *tsk;
19462 +
19463 +               rcu_read_lock();
19464 +               tsk = find_task_by_real_pid(id);
19465 +               nid = (tsk) ? tsk->nid : -ESRCH;
19466 +               rcu_read_unlock();
19467 +       } else
19468 +               nid = nx_current_nid();
19469 +       return nid;
19470 +}
19471 +
19472 +
19473 +int vc_nx_info(struct nx_info *nxi, void __user *data)
19474 +{
19475 +       struct vcmd_nx_info_v0 vc_data;
19476 +
19477 +       vc_data.nid = nxi->nx_id;
19478 +
19479 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19480 +               return -EFAULT;
19481 +       return 0;
19482 +}
19483 +
19484 +
19485 +/* network functions */
19486 +
19487 +int vc_net_create(uint32_t nid, void __user *data)
19488 +{
19489 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
19490 +       struct nx_info *new_nxi;
19491 +       int ret;
19492 +
19493 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19494 +               return -EFAULT;
19495 +
19496 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
19497 +               return -EINVAL;
19498 +
19499 +       new_nxi = __create_nx_info(nid);
19500 +       if (IS_ERR(new_nxi))
19501 +               return PTR_ERR(new_nxi);
19502 +
19503 +       /* initial flags */
19504 +       new_nxi->nx_flags = vc_data.flagword;
19505 +
19506 +       ret = -ENOEXEC;
19507 +       if (vs_net_change(new_nxi, VSC_NETUP))
19508 +               goto out;
19509 +
19510 +       ret = nx_migrate_task(current, new_nxi);
19511 +       if (ret)
19512 +               goto out;
19513 +
19514 +       /* return context id on success */
19515 +       ret = new_nxi->nx_id;
19516 +
19517 +       /* get a reference for persistent contexts */
19518 +       if ((vc_data.flagword & NXF_PERSISTENT))
19519 +               nx_set_persistent(new_nxi);
19520 +out:
19521 +       release_nx_info(new_nxi, NULL);
19522 +       put_nx_info(new_nxi);
19523 +       return ret;
19524 +}
19525 +
19526 +
19527 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
19528 +{
19529 +       return nx_migrate_task(current, nxi);
19530 +}
19531 +
19532 +
19533 +static inline
19534 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
19535 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
19536 +       struct nx_addr_v4 **prev)
19537 +{
19538 +       struct nx_addr_v4 *nxa = &nxi->v4;
19539 +
19540 +       for (; nxa; nxa = nxa->next) {
19541 +               if ((nxa->ip[0].s_addr == ip) &&
19542 +                   (nxa->ip[1].s_addr == ip2) &&
19543 +                   (nxa->mask.s_addr == mask) &&
19544 +                   (nxa->type == type) &&
19545 +                   (nxa->flags == flags))
19546 +                   return nxa;
19547 +
19548 +               /* save previous entry */
19549 +               if (prev)
19550 +                       *prev = nxa;
19551 +       }
19552 +       return NULL;
19553 +}
19554 +
19555 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19556 +       uint16_t type, uint16_t flags)
19557 +{
19558 +       struct nx_addr_v4 *nxa = NULL;
19559 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
19560 +       unsigned long irqflags;
19561 +       int ret = -EEXIST;
19562 +
19563 +       if (IS_ERR(new))
19564 +               return PTR_ERR(new);
19565 +
19566 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19567 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
19568 +               goto out_unlock;
19569 +
19570 +       if (NX_IPV4(nxi)) {
19571 +               nxa->next = new;
19572 +               nxa = new;
19573 +               new = NULL;
19574 +
19575 +               /* remove single ip for ip list */
19576 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
19577 +       }
19578 +
19579 +       nxa->ip[0].s_addr = ip;
19580 +       nxa->ip[1].s_addr = ip2;
19581 +       nxa->mask.s_addr = mask;
19582 +       nxa->type = type;
19583 +       nxa->flags = flags;
19584 +       ret = 0;
19585 +out_unlock:
19586 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19587 +       if (new)
19588 +               __dealloc_nx_addr_v4(new);
19589 +       return ret;
19590 +}
19591 +
19592 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19593 +       uint16_t type, uint16_t flags)
19594 +{
19595 +       struct nx_addr_v4 *nxa = NULL;
19596 +       struct nx_addr_v4 *old = NULL;
19597 +       unsigned long irqflags;
19598 +       int ret = 0;
19599 +
19600 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19601 +       switch (type) {
19602 +       case NXA_TYPE_ADDR:
19603 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
19604 +               if (old) {
19605 +                       if (nxa) {
19606 +                               nxa->next = old->next;
19607 +                               old->next = NULL;
19608 +                       } else {
19609 +                               if (old->next) {
19610 +                                       nxa = old;
19611 +                                       old = old->next;
19612 +                                       *nxa = *old;
19613 +                                       old->next = NULL;
19614 +                               } else {
19615 +                                       memset(old, 0, sizeof(*old));
19616 +                                       old = NULL;
19617 +                               }
19618 +                       }
19619 +               } else
19620 +                       ret = -ESRCH;
19621 +               break;
19622 +
19623 +       case NXA_TYPE_ANY:
19624 +               nxa = &nxi->v4;
19625 +               old = nxa->next;
19626 +               memset(nxa, 0, sizeof(*nxa));
19627 +               break;
19628 +
19629 +       default:
19630 +               ret = -EINVAL;
19631 +       }
19632 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19633 +       __dealloc_nx_addr_v4_all(old);
19634 +       return ret;
19635 +}
19636 +
19637 +
19638 +int vc_net_add(struct nx_info *nxi, void __user *data)
19639 +{
19640 +       struct vcmd_net_addr_v0 vc_data;
19641 +       int index, ret = 0;
19642 +
19643 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19644 +               return -EFAULT;
19645 +
19646 +       switch (vc_data.type) {
19647 +       case NXA_TYPE_IPV4:
19648 +               if ((vc_data.count < 1) || (vc_data.count > 4))
19649 +                       return -EINVAL;
19650 +
19651 +               index = 0;
19652 +               while (index < vc_data.count) {
19653 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
19654 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
19655 +                       if (ret)
19656 +                               return ret;
19657 +                       index++;
19658 +               }
19659 +               ret = index;
19660 +               break;
19661 +
19662 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
19663 +               nxi->v4_bcast = vc_data.ip[0];
19664 +               ret = 1;
19665 +               break;
19666 +
19667 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
19668 +               nxi->v4_lback = vc_data.ip[0];
19669 +               ret = 1;
19670 +               break;
19671 +
19672 +       default:
19673 +               ret = -EINVAL;
19674 +               break;
19675 +       }
19676 +       return ret;
19677 +}
19678 +
19679 +int vc_net_remove(struct nx_info *nxi, void __user *data)
19680 +{
19681 +       struct vcmd_net_addr_v0 vc_data;
19682 +
19683 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19684 +               return -EFAULT;
19685 +
19686 +       switch (vc_data.type) {
19687 +       case NXA_TYPE_ANY:
19688 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
19689 +       default:
19690 +               return -EINVAL;
19691 +       }
19692 +       return 0;
19693 +}
19694 +
19695 +
19696 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
19697 +{
19698 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19699 +
19700 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19701 +               return -EFAULT;
19702 +
19703 +       switch (vc_data.type) {
19704 +       case NXA_TYPE_ADDR:
19705 +       case NXA_TYPE_MASK:
19706 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
19707 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19708 +
19709 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19710 +               nxi->v4_bcast = vc_data.ip;
19711 +               break;
19712 +
19713 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19714 +               nxi->v4_lback = vc_data.ip;
19715 +               break;
19716 +
19717 +       default:
19718 +               return -EINVAL;
19719 +       }
19720 +       return 0;
19721 +}
19722 +
19723 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
19724 +{
19725 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19726 +
19727 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19728 +               return -EFAULT;
19729 +
19730 +       switch (vc_data.type) {
19731 +       case NXA_TYPE_ADDR:
19732 +       case NXA_TYPE_MASK:
19733 +       case NXA_TYPE_RANGE:
19734 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19735 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19736 +
19737 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19738 +               nxi->v4_bcast = vc_data.ip;
19739 +               break;
19740 +
19741 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19742 +               nxi->v4_lback = vc_data.ip;
19743 +               break;
19744 +
19745 +       default:
19746 +               return -EINVAL;
19747 +       }
19748 +       return 0;
19749 +}
19750 +
19751 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
19752 +{
19753 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19754 +
19755 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19756 +               return -EFAULT;
19757 +
19758 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
19759 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19760 +}
19761 +
19762 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
19763 +{
19764 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19765 +
19766 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19767 +               return -EFAULT;
19768 +
19769 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19770 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19771 +}
19772 +
19773 +#ifdef CONFIG_IPV6
19774 +
19775 +static inline
19776 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
19777 +       struct in6_addr *ip, struct in6_addr *mask,
19778 +       uint32_t prefix, uint16_t type, uint16_t flags,
19779 +       struct nx_addr_v6 **prev)
19780 +{
19781 +       struct nx_addr_v6 *nxa = &nxi->v6;
19782 +
19783 +       for (; nxa; nxa = nxa->next) {
19784 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
19785 +                   ipv6_addr_equal(&nxa->mask, mask) &&
19786 +                   (nxa->prefix == prefix) &&
19787 +                   (nxa->type == type) &&
19788 +                   (nxa->flags == flags))
19789 +                   return nxa;
19790 +
19791 +               /* save previous entry */
19792 +               if (prev)
19793 +                       *prev = nxa;
19794 +       }
19795 +       return NULL;
19796 +}
19797 +
19798 +
19799 +int do_add_v6_addr(struct nx_info *nxi,
19800 +       struct in6_addr *ip, struct in6_addr *mask,
19801 +       uint32_t prefix, uint16_t type, uint16_t flags)
19802 +{
19803 +       struct nx_addr_v6 *nxa = NULL;
19804 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
19805 +       unsigned long irqflags;
19806 +       int ret = -EEXIST;
19807 +
19808 +       if (IS_ERR(new))
19809 +               return PTR_ERR(new);
19810 +
19811 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19812 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
19813 +               goto out_unlock;
19814 +
19815 +       if (NX_IPV6(nxi)) {
19816 +               nxa->next = new;
19817 +               nxa = new;
19818 +               new = NULL;
19819 +       }
19820 +
19821 +       nxa->ip = *ip;
19822 +       nxa->mask = *mask;
19823 +       nxa->prefix = prefix;
19824 +       nxa->type = type;
19825 +       nxa->flags = flags;
19826 +       ret = 0;
19827 +out_unlock:
19828 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19829 +       if (new)
19830 +               __dealloc_nx_addr_v6(new);
19831 +       return ret;
19832 +}
19833 +
19834 +int do_remove_v6_addr(struct nx_info *nxi,
19835 +       struct in6_addr *ip, struct in6_addr *mask,
19836 +       uint32_t prefix, uint16_t type, uint16_t flags)
19837 +{
19838 +       struct nx_addr_v6 *nxa = NULL;
19839 +       struct nx_addr_v6 *old = NULL;
19840 +       unsigned long irqflags;
19841 +       int ret = 0;
19842 +
19843 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19844 +       switch (type) {
19845 +       case NXA_TYPE_ADDR:
19846 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
19847 +               if (old) {
19848 +                       if (nxa) {
19849 +                               nxa->next = old->next;
19850 +                               old->next = NULL;
19851 +                       } else {
19852 +                               if (old->next) {
19853 +                                       nxa = old;
19854 +                                       old = old->next;
19855 +                                       *nxa = *old;
19856 +                                       old->next = NULL;
19857 +                               } else {
19858 +                                       memset(old, 0, sizeof(*old));
19859 +                                       old = NULL;
19860 +                               }
19861 +                       }
19862 +               } else
19863 +                       ret = -ESRCH;
19864 +               break;
19865 +
19866 +       case NXA_TYPE_ANY:
19867 +               nxa = &nxi->v6;
19868 +               old = nxa->next;
19869 +               memset(nxa, 0, sizeof(*nxa));
19870 +               break;
19871 +
19872 +       default:
19873 +               ret = -EINVAL;
19874 +       }
19875 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19876 +       __dealloc_nx_addr_v6_all(old);
19877 +       return ret;
19878 +}
19879 +
19880 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
19881 +{
19882 +       struct vcmd_net_addr_ipv6_v1 vc_data;
19883 +
19884 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19885 +               return -EFAULT;
19886 +
19887 +       switch (vc_data.type) {
19888 +       case NXA_TYPE_ADDR:
19889 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
19890 +               /* fallthrough */
19891 +       case NXA_TYPE_MASK:
19892 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
19893 +                       vc_data.prefix, vc_data.type, vc_data.flags);
19894 +       default:
19895 +               return -EINVAL;
19896 +       }
19897 +       return 0;
19898 +}
19899 +
19900 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
19901 +{
19902 +       struct vcmd_net_addr_ipv6_v1 vc_data;
19903 +
19904 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19905 +               return -EFAULT;
19906 +
19907 +       switch (vc_data.type) {
19908 +       case NXA_TYPE_ADDR:
19909 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
19910 +               /* fallthrough */
19911 +       case NXA_TYPE_MASK:
19912 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
19913 +                       vc_data.prefix, vc_data.type, vc_data.flags);
19914 +       case NXA_TYPE_ANY:
19915 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
19916 +       default:
19917 +               return -EINVAL;
19918 +       }
19919 +       return 0;
19920 +}
19921 +
19922 +#endif /* CONFIG_IPV6 */
19923 +
19924 +
19925 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
19926 +{
19927 +       struct vcmd_net_flags_v0 vc_data;
19928 +
19929 +       vc_data.flagword = nxi->nx_flags;
19930 +
19931 +       /* special STATE flag handling */
19932 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
19933 +
19934 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19935 +               return -EFAULT;
19936 +       return 0;
19937 +}
19938 +
19939 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
19940 +{
19941 +       struct vcmd_net_flags_v0 vc_data;
19942 +       uint64_t mask, trigger;
19943 +
19944 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19945 +               return -EFAULT;
19946 +
19947 +       /* special STATE flag handling */
19948 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
19949 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
19950 +
19951 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
19952 +               vc_data.flagword, mask);
19953 +       if (trigger & NXF_PERSISTENT)
19954 +               nx_update_persistent(nxi);
19955 +
19956 +       return 0;
19957 +}
19958 +
19959 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
19960 +{
19961 +       struct vcmd_net_caps_v0 vc_data;
19962 +
19963 +       vc_data.ncaps = nxi->nx_ncaps;
19964 +       vc_data.cmask = ~0ULL;
19965 +
19966 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19967 +               return -EFAULT;
19968 +       return 0;
19969 +}
19970 +
19971 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
19972 +{
19973 +       struct vcmd_net_caps_v0 vc_data;
19974 +
19975 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19976 +               return -EFAULT;
19977 +
19978 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
19979 +               vc_data.ncaps, vc_data.cmask);
19980 +       return 0;
19981 +}
19982 +
19983 +
19984 +#include <linux/module.h>
19985 +
19986 +module_init(init_network);
19987 +
19988 +EXPORT_SYMBOL_GPL(free_nx_info);
19989 +EXPORT_SYMBOL_GPL(unhash_nx_info);
19990 +
19991 diff -NurpP --minimal linux-4.4.161/kernel/vserver/proc.c linux-4.4.161-vs2.3.9.8/kernel/vserver/proc.c
19992 --- linux-4.4.161/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
19993 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/proc.c       2018-10-20 04:57:21.000000000 +0000
19994 @@ -0,0 +1,1040 @@
19995 +/*
19996 + *  linux/kernel/vserver/proc.c
19997 + *
19998 + *  Virtual Context Support
19999 + *
20000 + *  Copyright (C) 2003-2011  Herbert P?tzl
20001 + *
20002 + *  V0.01  basic structure
20003 + *  V0.02  adaptation vs1.3.0
20004 + *  V0.03  proc permissions
20005 + *  V0.04  locking/generic
20006 + *  V0.05  next generation procfs
20007 + *  V0.06  inode validation
20008 + *  V0.07  generic rewrite vid
20009 + *  V0.08  remove inode type
20010 + *  V0.09  added u/wmask info
20011 + *
20012 + */
20013 +
20014 +#include <linux/proc_fs.h>
20015 +#include <linux/fs_struct.h>
20016 +#include <linux/mount.h>
20017 +#include <linux/namei.h>
20018 +#include <asm/unistd.h>
20019 +
20020 +#include <linux/vs_context.h>
20021 +#include <linux/vs_network.h>
20022 +#include <linux/vs_cvirt.h>
20023 +
20024 +#include <linux/in.h>
20025 +#include <linux/inetdevice.h>
20026 +#include <linux/vs_inet.h>
20027 +#include <linux/vs_inet6.h>
20028 +
20029 +#include <linux/vserver/global.h>
20030 +
20031 +#include "cvirt_proc.h"
20032 +#include "cacct_proc.h"
20033 +#include "limit_proc.h"
20034 +#include "sched_proc.h"
20035 +#include "vci_config.h"
20036 +
20037 +#include <../../fs/proc/internal.h>
20038 +
20039 +
20040 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20041 +{
20042 +       unsigned __capi;
20043 +
20044 +       CAP_FOR_EACH_U32(__capi) {
20045 +               buffer += sprintf(buffer, "%08x",
20046 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20047 +       }
20048 +       return buffer;
20049 +}
20050 +
20051 +
20052 +static struct proc_dir_entry *proc_virtual;
20053 +
20054 +static struct proc_dir_entry *proc_virtnet;
20055 +
20056 +
20057 +/* first the actual feeds */
20058 +
20059 +
20060 +static int proc_vci(char *buffer)
20061 +{
20062 +       return sprintf(buffer,
20063 +               "VCIVersion:\t%04x:%04x\n"
20064 +               "VCISyscall:\t%d\n"
20065 +               "VCIKernel:\t%08x\n",
20066 +               VCI_VERSION >> 16,
20067 +               VCI_VERSION & 0xFFFF,
20068 +               __NR_vserver,
20069 +               vci_kernel_config());
20070 +}
20071 +
20072 +static int proc_virtual_info(char *buffer)
20073 +{
20074 +       return proc_vci(buffer);
20075 +}
20076 +
20077 +static int proc_virtual_status(char *buffer)
20078 +{
20079 +       return sprintf(buffer,
20080 +               "#CTotal:\t%d\n"
20081 +               "#CActive:\t%d\n"
20082 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20083 +               "#InitTask:\t%d\t%d %d\n",
20084 +               atomic_read(&vx_global_ctotal),
20085 +               atomic_read(&vx_global_cactive),
20086 +               atomic_read(&vs_global_nsproxy),
20087 +               atomic_read(&vs_global_fs),
20088 +               atomic_read(&vs_global_mnt_ns),
20089 +               atomic_read(&vs_global_uts_ns),
20090 +               atomic_read(&nr_ipc_ns),
20091 +               atomic_read(&vs_global_user_ns),
20092 +               atomic_read(&vs_global_pid_ns),
20093 +               atomic_read(&init_task.usage),
20094 +               atomic_read(&init_task.nsproxy->count),
20095 +               init_task.fs->users);
20096 +}
20097 +
20098 +
20099 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20100 +{
20101 +       int length;
20102 +
20103 +       length = sprintf(buffer,
20104 +               "ID:\t%d\n"
20105 +               "Info:\t%p\n"
20106 +               "Init:\t%d\n"
20107 +               "OOM:\t%lld\n",
20108 +               vxi->vx_id,
20109 +               vxi,
20110 +               vxi->vx_initpid,
20111 +               vxi->vx_badness_bias);
20112 +       return length;
20113 +}
20114 +
20115 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
20116 +{
20117 +       char *orig = buffer;
20118 +
20119 +       buffer += sprintf(buffer,
20120 +               "UseCnt:\t%d\n"
20121 +               "Tasks:\t%d\n"
20122 +               "Flags:\t%016llx\n",
20123 +               atomic_read(&vxi->vx_usecnt),
20124 +               atomic_read(&vxi->vx_tasks),
20125 +               (unsigned long long)vxi->vx_flags);
20126 +
20127 +       buffer += sprintf(buffer, "BCaps:\t");
20128 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20129 +       buffer += sprintf(buffer, "\n");
20130 +
20131 +       buffer += sprintf(buffer,
20132 +               "CCaps:\t%016llx\n"
20133 +               "Umask:\t%16llx\n"
20134 +               "Wmask:\t%16llx\n"
20135 +               "Spaces:\t%08lx %08lx\n",
20136 +               (unsigned long long)vxi->vx_ccaps,
20137 +               (unsigned long long)vxi->vx_umask,
20138 +               (unsigned long long)vxi->vx_wmask,
20139 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20140 +       return buffer - orig;
20141 +}
20142 +
20143 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20144 +{
20145 +       return vx_info_proc_limit(&vxi->limit, buffer);
20146 +}
20147 +
20148 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20149 +{
20150 +       int cpu, length;
20151 +
20152 +       length = vx_info_proc_sched(&vxi->sched, buffer);
20153 +       for_each_online_cpu(cpu) {
20154 +               length += vx_info_proc_sched_pc(
20155 +                       &vx_per_cpu(vxi, sched_pc, cpu),
20156 +                       buffer + length, cpu);
20157 +       }
20158 +       return length;
20159 +}
20160 +
20161 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20162 +{
20163 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20164 +}
20165 +
20166 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20167 +{
20168 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20169 +}
20170 +
20171 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20172 +{
20173 +       int cpu, length;
20174 +
20175 +       vx_update_load(vxi);
20176 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20177 +       for_each_online_cpu(cpu) {
20178 +               length += vx_info_proc_cvirt_pc(
20179 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
20180 +                       buffer + length, cpu);
20181 +       }
20182 +       return length;
20183 +}
20184 +
20185 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20186 +{
20187 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
20188 +}
20189 +
20190 +
20191 +static int proc_virtnet_info(char *buffer)
20192 +{
20193 +       return proc_vci(buffer);
20194 +}
20195 +
20196 +static int proc_virtnet_status(char *buffer)
20197 +{
20198 +       return sprintf(buffer,
20199 +               "#CTotal:\t%d\n"
20200 +               "#CActive:\t%d\n",
20201 +               atomic_read(&nx_global_ctotal),
20202 +               atomic_read(&nx_global_cactive));
20203 +}
20204 +
20205 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
20206 +{
20207 +       struct nx_addr_v4 *v4a;
20208 +#ifdef CONFIG_IPV6
20209 +       struct nx_addr_v6 *v6a;
20210 +#endif
20211 +       int length, i;
20212 +
20213 +       length = sprintf(buffer,
20214 +               "ID:\t%d\n"
20215 +               "Info:\t%p\n"
20216 +               "Bcast:\t" NIPQUAD_FMT "\n"
20217 +               "Lback:\t" NIPQUAD_FMT "\n",
20218 +               nxi->nx_id,
20219 +               nxi,
20220 +               NIPQUAD(nxi->v4_bcast.s_addr),
20221 +               NIPQUAD(nxi->v4_lback.s_addr));
20222 +
20223 +       if (!NX_IPV4(nxi))
20224 +               goto skip_v4;
20225 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20226 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20227 +                       i, NXAV4(v4a));
20228 +skip_v4:
20229 +#ifdef CONFIG_IPV6
20230 +       if (!NX_IPV6(nxi))
20231 +               goto skip_v6;
20232 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20233 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
20234 +                       i, NXAV6(v6a));
20235 +skip_v6:
20236 +#endif
20237 +       return length;
20238 +}
20239 +
20240 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
20241 +{
20242 +       int length;
20243 +
20244 +       length = sprintf(buffer,
20245 +               "UseCnt:\t%d\n"
20246 +               "Tasks:\t%d\n"
20247 +               "Flags:\t%016llx\n"
20248 +               "NCaps:\t%016llx\n",
20249 +               atomic_read(&nxi->nx_usecnt),
20250 +               atomic_read(&nxi->nx_tasks),
20251 +               (unsigned long long)nxi->nx_flags,
20252 +               (unsigned long long)nxi->nx_ncaps);
20253 +       return length;
20254 +}
20255 +
20256 +
20257 +
20258 +/* here the inode helpers */
20259 +
20260 +struct vs_entry {
20261 +       int len;
20262 +       char *name;
20263 +       mode_t mode;
20264 +       struct inode_operations *iop;
20265 +       struct file_operations *fop;
20266 +       union proc_op op;
20267 +};
20268 +
20269 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
20270 +{
20271 +       struct inode *inode = new_inode(sb);
20272 +
20273 +       if (!inode)
20274 +               goto out;
20275 +
20276 +       inode->i_mode = p->mode;
20277 +       if (p->iop)
20278 +               inode->i_op = p->iop;
20279 +       if (p->fop)
20280 +               inode->i_fop = p->fop;
20281 +
20282 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
20283 +       inode->i_flags |= S_IMMUTABLE;
20284 +
20285 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
20286 +
20287 +       i_uid_write(inode, 0);
20288 +       i_gid_write(inode, 0);
20289 +       i_tag_write(inode, 0);
20290 +out:
20291 +       return inode;
20292 +}
20293 +
20294 +static struct dentry *vs_proc_instantiate(struct inode *dir,
20295 +       struct dentry *dentry, int id, void *ptr)
20296 +{
20297 +       struct vs_entry *p = ptr;
20298 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
20299 +       struct dentry *error = ERR_PTR(-EINVAL);
20300 +
20301 +       if (!inode)
20302 +               goto out;
20303 +
20304 +       PROC_I(inode)->op = p->op;
20305 +       PROC_I(inode)->fd = id;
20306 +       d_add(dentry, inode);
20307 +       error = NULL;
20308 +out:
20309 +       return error;
20310 +}
20311 +
20312 +/* Lookups */
20313 +
20314 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
20315 +
20316 +
20317 +/*
20318 + * Fill a directory entry.
20319 + *
20320 + * If possible create the dcache entry and derive our inode number and
20321 + * file type from dcache entry.
20322 + *
20323 + * Since all of the proc inode numbers are dynamically generated, the inode
20324 + * numbers do not exist until the inode is cache.  This means creating the
20325 + * the dcache entry in iterate is necessary to keep the inode numbers
20326 + * reported by iterate in sync with the inode numbers reported
20327 + * by stat.
20328 + */
20329 +static int vx_proc_fill_cache(struct file *filp, struct dir_context *ctx,
20330 +       char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
20331 +{
20332 +       struct dentry *child, *dir = filp->f_path.dentry;
20333 +       struct inode *inode;
20334 +       struct qstr qname;
20335 +       ino_t ino = 0;
20336 +       unsigned type = DT_UNKNOWN;
20337 +
20338 +       qname.name = name;
20339 +       qname.len  = len;
20340 +       qname.hash = full_name_hash(name, len);
20341 +
20342 +       child = d_lookup(dir, &qname);
20343 +       if (!child) {
20344 +               struct dentry *new;
20345 +               new = d_alloc(dir, &qname);
20346 +               if (new) {
20347 +                       child = instantiate(dir->d_inode, new, id, ptr);
20348 +                       if (child)
20349 +                               dput(new);
20350 +                       else
20351 +                               child = new;
20352 +               }
20353 +       }
20354 +       if (!child || IS_ERR(child) || !child->d_inode)
20355 +               goto end_instantiate;
20356 +       inode = child->d_inode;
20357 +       if (inode) {
20358 +               ino = inode->i_ino;
20359 +               type = inode->i_mode >> 12;
20360 +       }
20361 +       dput(child);
20362 +end_instantiate:
20363 +       if (!ino)
20364 +               ino = 1;
20365 +       return !dir_emit(ctx, name, len, ino, type);
20366 +}
20367 +
20368 +
20369 +
20370 +/* get and revalidate vx_info/xid */
20371 +
20372 +static inline
20373 +struct vx_info *get_proc_vx_info(struct inode *inode)
20374 +{
20375 +       return lookup_vx_info(PROC_I(inode)->fd);
20376 +}
20377 +
20378 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
20379 +{
20380 +       struct inode *inode = dentry->d_inode;
20381 +       vxid_t xid = PROC_I(inode)->fd;
20382 +
20383 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20384 +               return -ECHILD;
20385 +
20386 +       if (!xid || xid_is_hashed(xid))
20387 +               return 1;
20388 +       d_drop(dentry);
20389 +       return 0;
20390 +}
20391 +
20392 +
20393 +/* get and revalidate nx_info/nid */
20394 +
20395 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
20396 +{
20397 +       struct inode *inode = dentry->d_inode;
20398 +       vnid_t nid = PROC_I(inode)->fd;
20399 +
20400 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20401 +               return -ECHILD;
20402 +
20403 +       if (!nid || nid_is_hashed(nid))
20404 +               return 1;
20405 +       d_drop(dentry);
20406 +       return 0;
20407 +}
20408 +
20409 +
20410 +
20411 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
20412 +
20413 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
20414 +                         size_t count, loff_t *ppos)
20415 +{
20416 +       struct inode *inode = file->f_path.dentry->d_inode;
20417 +       unsigned long page;
20418 +       ssize_t length = 0;
20419 +
20420 +       if (count > PROC_BLOCK_SIZE)
20421 +               count = PROC_BLOCK_SIZE;
20422 +
20423 +       /* fade that out as soon as stable */
20424 +       WARN_ON(PROC_I(inode)->fd);
20425 +
20426 +       if (!(page = __get_free_page(GFP_KERNEL)))
20427 +               return -ENOMEM;
20428 +
20429 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
20430 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
20431 +
20432 +       if (length >= 0)
20433 +               length = simple_read_from_buffer(buf, count, ppos,
20434 +                       (char *)page, length);
20435 +
20436 +       free_page(page);
20437 +       return length;
20438 +}
20439 +
20440 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
20441 +                         size_t count, loff_t *ppos)
20442 +{
20443 +       struct inode *inode = file->f_path.dentry->d_inode;
20444 +       struct vx_info *vxi = NULL;
20445 +       vxid_t xid = PROC_I(inode)->fd;
20446 +       unsigned long page;
20447 +       ssize_t length = 0;
20448 +
20449 +       if (count > PROC_BLOCK_SIZE)
20450 +               count = PROC_BLOCK_SIZE;
20451 +
20452 +       /* fade that out as soon as stable */
20453 +       WARN_ON(!xid);
20454 +       vxi = lookup_vx_info(xid);
20455 +       if (!vxi)
20456 +               goto out;
20457 +
20458 +       length = -ENOMEM;
20459 +       if (!(page = __get_free_page(GFP_KERNEL)))
20460 +               goto out_put;
20461 +
20462 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
20463 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
20464 +
20465 +       if (length >= 0)
20466 +               length = simple_read_from_buffer(buf, count, ppos,
20467 +                       (char *)page, length);
20468 +
20469 +       free_page(page);
20470 +out_put:
20471 +       put_vx_info(vxi);
20472 +out:
20473 +       return length;
20474 +}
20475 +
20476 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
20477 +                         size_t count, loff_t *ppos)
20478 +{
20479 +       struct inode *inode = file->f_path.dentry->d_inode;
20480 +       struct nx_info *nxi = NULL;
20481 +       vnid_t nid = PROC_I(inode)->fd;
20482 +       unsigned long page;
20483 +       ssize_t length = 0;
20484 +
20485 +       if (count > PROC_BLOCK_SIZE)
20486 +               count = PROC_BLOCK_SIZE;
20487 +
20488 +       /* fade that out as soon as stable */
20489 +       WARN_ON(!nid);
20490 +       nxi = lookup_nx_info(nid);
20491 +       if (!nxi)
20492 +               goto out;
20493 +
20494 +       length = -ENOMEM;
20495 +       if (!(page = __get_free_page(GFP_KERNEL)))
20496 +               goto out_put;
20497 +
20498 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
20499 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
20500 +
20501 +       if (length >= 0)
20502 +               length = simple_read_from_buffer(buf, count, ppos,
20503 +                       (char *)page, length);
20504 +
20505 +       free_page(page);
20506 +out_put:
20507 +       put_nx_info(nxi);
20508 +out:
20509 +       return length;
20510 +}
20511 +
20512 +
20513 +
20514 +/* here comes the lower level */
20515 +
20516 +
20517 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
20518 +       .len  = sizeof(NAME) - 1,       \
20519 +       .name = (NAME),                 \
20520 +       .mode = MODE,                   \
20521 +       .iop  = IOP,                    \
20522 +       .fop  = FOP,                    \
20523 +       .op   = OP,                     \
20524 +}
20525 +
20526 +
20527 +#define DIR(NAME, MODE, OTYPE)                         \
20528 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
20529 +               &proc_ ## OTYPE ## _inode_operations,   \
20530 +               &proc_ ## OTYPE ## _file_operations, { } )
20531 +
20532 +#define INF(NAME, MODE, OTYPE)                         \
20533 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20534 +               &proc_vs_info_file_operations,          \
20535 +               { .proc_vs_read = &proc_##OTYPE } )
20536 +
20537 +#define VINF(NAME, MODE, OTYPE)                                \
20538 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20539 +               &proc_vx_info_file_operations,          \
20540 +               { .proc_vxi_read = &proc_##OTYPE } )
20541 +
20542 +#define NINF(NAME, MODE, OTYPE)                                \
20543 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20544 +               &proc_nx_info_file_operations,          \
20545 +               { .proc_nxi_read = &proc_##OTYPE } )
20546 +
20547 +
20548 +static struct file_operations proc_vs_info_file_operations = {
20549 +       .read =         proc_vs_info_read,
20550 +};
20551 +
20552 +static struct file_operations proc_vx_info_file_operations = {
20553 +       .read =         proc_vx_info_read,
20554 +};
20555 +
20556 +static struct dentry_operations proc_xid_dentry_operations = {
20557 +       .d_revalidate = proc_xid_revalidate,
20558 +};
20559 +
20560 +static struct vs_entry vx_base_stuff[] = {
20561 +       VINF("info",    S_IRUGO, vxi_info),
20562 +       VINF("status",  S_IRUGO, vxi_status),
20563 +       VINF("limit",   S_IRUGO, vxi_limit),
20564 +       VINF("sched",   S_IRUGO, vxi_sched),
20565 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
20566 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
20567 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
20568 +       VINF("cacct",   S_IRUGO, vxi_cacct),
20569 +       {}
20570 +};
20571 +
20572 +
20573 +
20574 +
20575 +static struct dentry *proc_xid_instantiate(struct inode *dir,
20576 +       struct dentry *dentry, int id, void *ptr)
20577 +{
20578 +       dentry->d_op = &proc_xid_dentry_operations;
20579 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20580 +}
20581 +
20582 +static struct dentry *proc_xid_lookup(struct inode *dir,
20583 +       struct dentry *dentry, unsigned int flags)
20584 +{
20585 +       struct vs_entry *p = vx_base_stuff;
20586 +       struct dentry *error = ERR_PTR(-ENOENT);
20587 +
20588 +       for (; p->name; p++) {
20589 +               if (p->len != dentry->d_name.len)
20590 +                       continue;
20591 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20592 +                       break;
20593 +       }
20594 +       if (!p->name)
20595 +               goto out;
20596 +
20597 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20598 +out:
20599 +       return error;
20600 +}
20601 +
20602 +static int proc_xid_iterate(struct file *filp, struct dir_context *ctx)
20603 +{
20604 +       struct dentry *dentry = filp->f_path.dentry;
20605 +       struct inode *inode = dentry->d_inode;
20606 +       struct vs_entry *p = vx_base_stuff;
20607 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
20608 +       int index;
20609 +
20610 +       if (!dir_emit_dots(filp, ctx))
20611 +               return 0;
20612 +
20613 +       index = ctx->pos - 2;
20614 +       if (index < size) {
20615 +               for (p += index; p->name; p++) {
20616 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20617 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20618 +                               return 0;
20619 +                       ctx->pos++;
20620 +               }
20621 +       }
20622 +       return 1;
20623 +}
20624 +
20625 +
20626 +
20627 +static struct file_operations proc_nx_info_file_operations = {
20628 +       .read =         proc_nx_info_read,
20629 +};
20630 +
20631 +static struct dentry_operations proc_nid_dentry_operations = {
20632 +       .d_revalidate = proc_nid_revalidate,
20633 +};
20634 +
20635 +static struct vs_entry nx_base_stuff[] = {
20636 +       NINF("info",    S_IRUGO, nxi_info),
20637 +       NINF("status",  S_IRUGO, nxi_status),
20638 +       {}
20639 +};
20640 +
20641 +
20642 +static struct dentry *proc_nid_instantiate(struct inode *dir,
20643 +       struct dentry *dentry, int id, void *ptr)
20644 +{
20645 +       dentry->d_op = &proc_nid_dentry_operations;
20646 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20647 +}
20648 +
20649 +static struct dentry *proc_nid_lookup(struct inode *dir,
20650 +       struct dentry *dentry, unsigned int flags)
20651 +{
20652 +       struct vs_entry *p = nx_base_stuff;
20653 +       struct dentry *error = ERR_PTR(-ENOENT);
20654 +
20655 +       for (; p->name; p++) {
20656 +               if (p->len != dentry->d_name.len)
20657 +                       continue;
20658 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20659 +                       break;
20660 +       }
20661 +       if (!p->name)
20662 +               goto out;
20663 +
20664 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20665 +out:
20666 +       return error;
20667 +}
20668 +
20669 +static int proc_nid_iterate(struct file *filp, struct dir_context *ctx)
20670 +{
20671 +       struct dentry *dentry = filp->f_path.dentry;
20672 +       struct inode *inode = dentry->d_inode;
20673 +       struct vs_entry *p = nx_base_stuff;
20674 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
20675 +       int index;
20676 +
20677 +       if (!dir_emit_dots(filp, ctx))
20678 +               return 0;
20679 +
20680 +       index = ctx->pos - 2;
20681 +       if (index < size) {
20682 +               for (p += index; p->name; p++) {
20683 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20684 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20685 +                               return 0;
20686 +                       ctx->pos++;
20687 +               }
20688 +       }
20689 +       return 1;
20690 +}
20691 +
20692 +
20693 +#define MAX_MULBY10    ((~0U - 9) / 10)
20694 +
20695 +static inline int atovid(const char *str, int len)
20696 +{
20697 +       int vid, c;
20698 +
20699 +       vid = 0;
20700 +       while (len-- > 0) {
20701 +               c = *str - '0';
20702 +               str++;
20703 +               if (c > 9)
20704 +                       return -1;
20705 +               if (vid >= MAX_MULBY10)
20706 +                       return -1;
20707 +               vid *= 10;
20708 +               vid += c;
20709 +               if (!vid)
20710 +                       return -1;
20711 +       }
20712 +       return vid;
20713 +}
20714 +
20715 +/* now the upper level (virtual) */
20716 +
20717 +
20718 +static struct file_operations proc_xid_file_operations = {
20719 +       .read =         generic_read_dir,
20720 +       .iterate =      proc_xid_iterate,
20721 +};
20722 +
20723 +static struct inode_operations proc_xid_inode_operations = {
20724 +       .lookup =       proc_xid_lookup,
20725 +};
20726 +
20727 +static struct vs_entry vx_virtual_stuff[] = {
20728 +       INF("info",     S_IRUGO, virtual_info),
20729 +       INF("status",   S_IRUGO, virtual_status),
20730 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
20731 +};
20732 +
20733 +
20734 +static struct dentry *proc_virtual_lookup(struct inode *dir,
20735 +       struct dentry *dentry, unsigned int flags)
20736 +{
20737 +       struct vs_entry *p = vx_virtual_stuff;
20738 +       struct dentry *error = ERR_PTR(-ENOENT);
20739 +       int id = 0;
20740 +
20741 +       for (; p->name; p++) {
20742 +               if (p->len != dentry->d_name.len)
20743 +                       continue;
20744 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20745 +                       break;
20746 +       }
20747 +       if (p->name)
20748 +               goto instantiate;
20749 +
20750 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
20751 +       if ((id < 0) || !xid_is_hashed(id))
20752 +               goto out;
20753 +
20754 +instantiate:
20755 +       error = proc_xid_instantiate(dir, dentry, id, p);
20756 +out:
20757 +       return error;
20758 +}
20759 +
20760 +static struct file_operations proc_nid_file_operations = {
20761 +       .read =         generic_read_dir,
20762 +       .iterate =      proc_nid_iterate,
20763 +};
20764 +
20765 +static struct inode_operations proc_nid_inode_operations = {
20766 +       .lookup =       proc_nid_lookup,
20767 +};
20768 +
20769 +static struct vs_entry nx_virtnet_stuff[] = {
20770 +       INF("info",     S_IRUGO, virtnet_info),
20771 +       INF("status",   S_IRUGO, virtnet_status),
20772 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
20773 +};
20774 +
20775 +
20776 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
20777 +       struct dentry *dentry, unsigned int flags)
20778 +{
20779 +       struct vs_entry *p = nx_virtnet_stuff;
20780 +       struct dentry *error = ERR_PTR(-ENOENT);
20781 +       int id = 0;
20782 +
20783 +       for (; p->name; p++) {
20784 +               if (p->len != dentry->d_name.len)
20785 +                       continue;
20786 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20787 +                       break;
20788 +       }
20789 +       if (p->name)
20790 +               goto instantiate;
20791 +
20792 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
20793 +       if ((id < 0) || !nid_is_hashed(id))
20794 +               goto out;
20795 +
20796 +instantiate:
20797 +       error = proc_nid_instantiate(dir, dentry, id, p);
20798 +out:
20799 +       return error;
20800 +}
20801 +
20802 +
20803 +#define PROC_MAXVIDS 32
20804 +
20805 +int proc_virtual_iterate(struct file *filp, struct dir_context *ctx)
20806 +{
20807 +       struct vs_entry *p = vx_virtual_stuff;
20808 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
20809 +       int index;
20810 +       unsigned int xid_array[PROC_MAXVIDS];
20811 +       char buf[PROC_NUMBUF];
20812 +       unsigned int nr_xids, i;
20813 +
20814 +       if (!dir_emit_dots(filp, ctx))
20815 +               return 0;
20816 +
20817 +       index = ctx->pos - 2;
20818 +       if (index < size) {
20819 +               for (p += index; p->name; p++) {
20820 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20821 +                               vs_proc_instantiate, 0, p))
20822 +                               return 0;
20823 +                       ctx->pos++;
20824 +               }
20825 +       }
20826 +
20827 +       index = ctx->pos - size;
20828 +       p = &vx_virtual_stuff[size - 1];
20829 +       nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
20830 +       for (i = 0; i < nr_xids; i++) {
20831 +               int n, xid = xid_array[i];
20832 +               unsigned int j = PROC_NUMBUF;
20833 +
20834 +               n = xid;
20835 +               do
20836 +                       buf[--j] = '0' + (n % 10);
20837 +               while (n /= 10);
20838 +
20839 +               if (vx_proc_fill_cache(filp, ctx,
20840 +                       buf + j, PROC_NUMBUF - j,
20841 +                       vs_proc_instantiate, xid, p))
20842 +                       return 0;
20843 +               ctx->pos++;
20844 +       }
20845 +       return 0;
20846 +}
20847 +
20848 +static int proc_virtual_getattr(struct vfsmount *mnt,
20849 +       struct dentry *dentry, struct kstat *stat)
20850 +{
20851 +       struct inode *inode = dentry->d_inode;
20852 +
20853 +       generic_fillattr(inode, stat);
20854 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
20855 +       return 0;
20856 +}
20857 +
20858 +static struct file_operations proc_virtual_dir_operations = {
20859 +       .read =         generic_read_dir,
20860 +       .iterate =      proc_virtual_iterate,
20861 +};
20862 +
20863 +static struct inode_operations proc_virtual_dir_inode_operations = {
20864 +       .getattr =      proc_virtual_getattr,
20865 +       .lookup =       proc_virtual_lookup,
20866 +};
20867 +
20868 +
20869 +
20870 +int proc_virtnet_iterate(struct file *filp, struct dir_context *ctx)
20871 +{
20872 +       struct vs_entry *p = nx_virtnet_stuff;
20873 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
20874 +       int index;
20875 +       unsigned int nid_array[PROC_MAXVIDS];
20876 +       char buf[PROC_NUMBUF];
20877 +       unsigned int nr_nids, i;
20878 +
20879 +       if (!dir_emit_dots(filp, ctx))
20880 +               return 0;
20881 +
20882 +       index = ctx->pos - 2;
20883 +       if (index < size) {
20884 +               for (p += index; p->name; p++) {
20885 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20886 +                               vs_proc_instantiate, 0, p))
20887 +                               return 0;
20888 +                       ctx->pos++;
20889 +               }
20890 +       }
20891 +
20892 +       index = ctx->pos - size;
20893 +       p = &nx_virtnet_stuff[size - 1];
20894 +       nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
20895 +       for (i = 0; i < nr_nids; i++) {
20896 +               int n, nid = nid_array[i];
20897 +               unsigned int j = PROC_NUMBUF;
20898 +
20899 +               n = nid;
20900 +               do
20901 +                       buf[--j] = '0' + (n % 10);
20902 +               while (n /= 10);
20903 +
20904 +               if (vx_proc_fill_cache(filp, ctx,
20905 +                       buf + j, PROC_NUMBUF - j,
20906 +                       vs_proc_instantiate, nid, p))
20907 +                       return 0;
20908 +               ctx->pos++;
20909 +       }
20910 +       return 0;
20911 +}
20912 +
20913 +static int proc_virtnet_getattr(struct vfsmount *mnt,
20914 +       struct dentry *dentry, struct kstat *stat)
20915 +{
20916 +       struct inode *inode = dentry->d_inode;
20917 +
20918 +       generic_fillattr(inode, stat);
20919 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
20920 +       return 0;
20921 +}
20922 +
20923 +static struct file_operations proc_virtnet_dir_operations = {
20924 +       .read =         generic_read_dir,
20925 +       .iterate =      proc_virtnet_iterate,
20926 +};
20927 +
20928 +static struct inode_operations proc_virtnet_dir_inode_operations = {
20929 +       .getattr =      proc_virtnet_getattr,
20930 +       .lookup =       proc_virtnet_lookup,
20931 +};
20932 +
20933 +
20934 +
20935 +void proc_vx_init(void)
20936 +{
20937 +       struct proc_dir_entry *ent;
20938 +
20939 +       ent = proc_mkdir("virtual", 0);
20940 +       if (ent) {
20941 +               ent->proc_fops = &proc_virtual_dir_operations;
20942 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
20943 +       }
20944 +       proc_virtual = ent;
20945 +
20946 +       ent = proc_mkdir("virtnet", 0);
20947 +       if (ent) {
20948 +               ent->proc_fops = &proc_virtnet_dir_operations;
20949 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
20950 +       }
20951 +       proc_virtnet = ent;
20952 +}
20953 +
20954 +
20955 +
20956 +
20957 +/* per pid info */
20958 +
20959 +void render_cap_t(struct seq_file *, const char *,
20960 +       struct vx_info *, kernel_cap_t *);
20961 +
20962 +
20963 +int proc_pid_vx_info(
20964 +       struct seq_file *m,
20965 +       struct pid_namespace *ns,
20966 +       struct pid *pid,
20967 +       struct task_struct *p)
20968 +{
20969 +       struct vx_info *vxi;
20970 +
20971 +       seq_printf(m, "XID:\t%d\n", vx_task_xid(p));
20972 +
20973 +       vxi = task_get_vx_info(p);
20974 +       if (!vxi)
20975 +               return 0;
20976 +
20977 +       render_cap_t(m, "BCaps:\t", vxi, &vxi->vx_bcaps);
20978 +       seq_printf(m, "CCaps:\t%016llx\n",
20979 +               (unsigned long long)vxi->vx_ccaps);
20980 +       seq_printf(m, "CFlags:\t%016llx\n",
20981 +               (unsigned long long)vxi->vx_flags);
20982 +       seq_printf(m, "CIPid:\t%d\n", vxi->vx_initpid);
20983 +
20984 +       put_vx_info(vxi);
20985 +       return 0;
20986 +}
20987 +
20988 +
20989 +int proc_pid_nx_info(
20990 +       struct seq_file *m,
20991 +       struct pid_namespace *ns,
20992 +       struct pid *pid,
20993 +       struct task_struct *p)
20994 +{
20995 +       struct nx_info *nxi;
20996 +       struct nx_addr_v4 *v4a;
20997 +#ifdef CONFIG_IPV6
20998 +       struct nx_addr_v6 *v6a;
20999 +#endif
21000 +       int i;
21001 +
21002 +       seq_printf(m, "NID:\t%d\n", nx_task_nid(p));
21003 +
21004 +       nxi = task_get_nx_info(p);
21005 +       if (!nxi)
21006 +               return 0;
21007 +
21008 +       seq_printf(m, "NCaps:\t%016llx\n",
21009 +               (unsigned long long)nxi->nx_ncaps);
21010 +       seq_printf(m, "NFlags:\t%016llx\n",
21011 +               (unsigned long long)nxi->nx_flags);
21012 +
21013 +       seq_printf(m, "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21014 +               NIPQUAD(nxi->v4_bcast.s_addr));
21015 +       seq_printf(m, "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21016 +               NIPQUAD(nxi->v4_lback.s_addr));
21017 +       if (!NX_IPV4(nxi))
21018 +               goto skip_v4;
21019 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21020 +               seq_printf(m, "V4Root[%d]:\t" NXAV4_FMT "\n",
21021 +                       i, NXAV4(v4a));
21022 +skip_v4:
21023 +#ifdef CONFIG_IPV6
21024 +       if (!NX_IPV6(nxi))
21025 +               goto skip_v6;
21026 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21027 +               seq_printf(m, "V6Root[%d]:\t" NXAV6_FMT "\n",
21028 +                       i, NXAV6(v6a));
21029 +skip_v6:
21030 +#endif
21031 +       put_nx_info(nxi);
21032 +       return 0;
21033 +}
21034 +
21035 diff -NurpP --minimal linux-4.4.161/kernel/vserver/sched.c linux-4.4.161-vs2.3.9.8/kernel/vserver/sched.c
21036 --- linux-4.4.161/kernel/vserver/sched.c        1970-01-01 00:00:00.000000000 +0000
21037 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/sched.c      2018-10-20 04:57:21.000000000 +0000
21038 @@ -0,0 +1,83 @@
21039 +/*
21040 + *  linux/kernel/vserver/sched.c
21041 + *
21042 + *  Virtual Server: Scheduler Support
21043 + *
21044 + *  Copyright (C) 2004-2010  Herbert P?tzl
21045 + *
21046 + *  V0.01  adapted Sam Vilains version to 2.6.3
21047 + *  V0.02  removed legacy interface
21048 + *  V0.03  changed vcmds to vxi arg
21049 + *  V0.04  removed older and legacy interfaces
21050 + *  V0.05  removed scheduler code/commands
21051 + *
21052 + */
21053 +
21054 +#include <linux/vs_context.h>
21055 +#include <linux/vs_sched.h>
21056 +#include <linux/cpumask.h>
21057 +#include <linux/vserver/sched_cmd.h>
21058 +
21059 +#include <asm/uaccess.h>
21060 +
21061 +
21062 +void vx_update_sched_param(struct _vx_sched *sched,
21063 +       struct _vx_sched_pc *sched_pc)
21064 +{
21065 +       sched_pc->prio_bias = sched->prio_bias;
21066 +}
21067 +
21068 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21069 +{
21070 +       int cpu;
21071 +
21072 +       if (data->prio_bias > MAX_PRIO_BIAS)
21073 +               data->prio_bias = MAX_PRIO_BIAS;
21074 +       if (data->prio_bias < MIN_PRIO_BIAS)
21075 +               data->prio_bias = MIN_PRIO_BIAS;
21076 +
21077 +       if (data->cpu_id != ~0) {
21078 +               vxi->sched.update = *get_cpu_mask(data->cpu_id);
21079 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
21080 +                       cpu_online_mask);
21081 +       } else
21082 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
21083 +
21084 +       for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)vxi->sched.update)
21085 +               vx_update_sched_param(&vxi->sched,
21086 +                       &vx_per_cpu(vxi, sched_pc, cpu));
21087 +       return 0;
21088 +}
21089 +
21090 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21091 +{
21092 +       struct vcmd_prio_bias vc_data;
21093 +
21094 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21095 +               return -EFAULT;
21096 +
21097 +       return do_set_prio_bias(vxi, &vc_data);
21098 +}
21099 +
21100 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21101 +{
21102 +       struct vcmd_prio_bias vc_data;
21103 +       struct _vx_sched_pc *pcd;
21104 +       int cpu;
21105 +
21106 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21107 +               return -EFAULT;
21108 +
21109 +       cpu = vc_data.cpu_id;
21110 +
21111 +       if (!cpu_possible(cpu))
21112 +               return -EINVAL;
21113 +
21114 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21115 +       vc_data.prio_bias = pcd->prio_bias;
21116 +
21117 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21118 +               return -EFAULT;
21119 +       return 0;
21120 +}
21121 +
21122 diff -NurpP --minimal linux-4.4.161/kernel/vserver/sched_init.h linux-4.4.161-vs2.3.9.8/kernel/vserver/sched_init.h
21123 --- linux-4.4.161/kernel/vserver/sched_init.h   1970-01-01 00:00:00.000000000 +0000
21124 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/sched_init.h 2018-10-20 04:57:21.000000000 +0000
21125 @@ -0,0 +1,27 @@
21126 +
21127 +static inline void vx_info_init_sched(struct _vx_sched *sched)
21128 +{
21129 +       /* scheduling; hard code starting values as constants */
21130 +       sched->prio_bias = 0;
21131 +}
21132 +
21133 +static inline
21134 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21135 +{
21136 +       sched_pc->prio_bias = 0;
21137 +
21138 +       sched_pc->user_ticks = 0;
21139 +       sched_pc->sys_ticks = 0;
21140 +       sched_pc->hold_ticks = 0;
21141 +}
21142 +
21143 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
21144 +{
21145 +       return;
21146 +}
21147 +
21148 +static inline
21149 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21150 +{
21151 +       return;
21152 +}
21153 diff -NurpP --minimal linux-4.4.161/kernel/vserver/sched_proc.h linux-4.4.161-vs2.3.9.8/kernel/vserver/sched_proc.h
21154 --- linux-4.4.161/kernel/vserver/sched_proc.h   1970-01-01 00:00:00.000000000 +0000
21155 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/sched_proc.h 2018-10-20 04:57:21.000000000 +0000
21156 @@ -0,0 +1,32 @@
21157 +#ifndef _VX_SCHED_PROC_H
21158 +#define _VX_SCHED_PROC_H
21159 +
21160 +
21161 +static inline
21162 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
21163 +{
21164 +       int length = 0;
21165 +
21166 +       length += sprintf(buffer,
21167 +               "PrioBias:\t%8d\n",
21168 +               sched->prio_bias);
21169 +       return length;
21170 +}
21171 +
21172 +static inline
21173 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
21174 +       char *buffer, int cpu)
21175 +{
21176 +       int length = 0;
21177 +
21178 +       length += sprintf(buffer + length,
21179 +               "cpu %d: %lld %lld %lld", cpu,
21180 +               (unsigned long long)sched_pc->user_ticks,
21181 +               (unsigned long long)sched_pc->sys_ticks,
21182 +               (unsigned long long)sched_pc->hold_ticks);
21183 +       length += sprintf(buffer + length,
21184 +               " %d\n", sched_pc->prio_bias);
21185 +       return length;
21186 +}
21187 +
21188 +#endif /* _VX_SCHED_PROC_H */
21189 diff -NurpP --minimal linux-4.4.161/kernel/vserver/signal.c linux-4.4.161-vs2.3.9.8/kernel/vserver/signal.c
21190 --- linux-4.4.161/kernel/vserver/signal.c       1970-01-01 00:00:00.000000000 +0000
21191 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/signal.c     2018-10-20 04:57:21.000000000 +0000
21192 @@ -0,0 +1,134 @@
21193 +/*
21194 + *  linux/kernel/vserver/signal.c
21195 + *
21196 + *  Virtual Server: Signal Support
21197 + *
21198 + *  Copyright (C) 2003-2007  Herbert P?tzl
21199 + *
21200 + *  V0.01  broken out from vcontext V0.05
21201 + *  V0.02  changed vcmds to vxi arg
21202 + *  V0.03  adjusted siginfo for kill
21203 + *
21204 + */
21205 +
21206 +#include <asm/uaccess.h>
21207 +
21208 +#include <linux/vs_context.h>
21209 +#include <linux/vs_pid.h>
21210 +#include <linux/vserver/signal_cmd.h>
21211 +
21212 +
21213 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
21214 +{
21215 +       int retval, count = 0;
21216 +       struct task_struct *p;
21217 +       struct siginfo *sip = SEND_SIG_PRIV;
21218 +
21219 +       retval = -ESRCH;
21220 +       vxdprintk(VXD_CBIT(misc, 4),
21221 +               "vx_info_kill(%p[#%d],%d,%d)*",
21222 +               vxi, vxi->vx_id, pid, sig);
21223 +       read_lock(&tasklist_lock);
21224 +       switch (pid) {
21225 +       case  0:
21226 +       case -1:
21227 +               for_each_process(p) {
21228 +                       int err = 0;
21229 +
21230 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
21231 +                               (pid && vxi->vx_initpid == p->pid))
21232 +                               continue;
21233 +
21234 +                       err = group_send_sig_info(sig, sip, p);
21235 +                       ++count;
21236 +                       if (err != -EPERM)
21237 +                               retval = err;
21238 +               }
21239 +               break;
21240 +
21241 +       case 1:
21242 +               if (vxi->vx_initpid) {
21243 +                       pid = vxi->vx_initpid;
21244 +                       /* for now, only SIGINT to private init ... */
21245 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21246 +                               /* ... as long as there are tasks left */
21247 +                               (atomic_read(&vxi->vx_tasks) > 1))
21248 +                               sig = SIGINT;
21249 +               }
21250 +               /* fallthrough */
21251 +       default:
21252 +               rcu_read_lock();
21253 +               p = find_task_by_real_pid(pid);
21254 +               rcu_read_unlock();
21255 +               if (p) {
21256 +                       if (vx_task_xid(p) == vxi->vx_id)
21257 +                               retval = group_send_sig_info(sig, sip, p);
21258 +               }
21259 +               break;
21260 +       }
21261 +       read_unlock(&tasklist_lock);
21262 +       vxdprintk(VXD_CBIT(misc, 4),
21263 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
21264 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
21265 +       return retval;
21266 +}
21267 +
21268 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
21269 +{
21270 +       struct vcmd_ctx_kill_v0 vc_data;
21271 +
21272 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21273 +               return -EFAULT;
21274 +
21275 +       /* special check to allow guest shutdown */
21276 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21277 +               /* forbid killall pid=0 when init is present */
21278 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
21279 +               (vc_data.pid > 1)))
21280 +               return -EACCES;
21281 +
21282 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
21283 +}
21284 +
21285 +
21286 +static int __wait_exit(struct vx_info *vxi)
21287 +{
21288 +       DECLARE_WAITQUEUE(wait, current);
21289 +       int ret = 0;
21290 +
21291 +       add_wait_queue(&vxi->vx_wait, &wait);
21292 +       set_current_state(TASK_INTERRUPTIBLE);
21293 +
21294 +wait:
21295 +       if (vx_info_state(vxi,
21296 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
21297 +               goto out;
21298 +       if (signal_pending(current)) {
21299 +               ret = -ERESTARTSYS;
21300 +               goto out;
21301 +       }
21302 +       schedule();
21303 +       goto wait;
21304 +
21305 +out:
21306 +       set_current_state(TASK_RUNNING);
21307 +       remove_wait_queue(&vxi->vx_wait, &wait);
21308 +       return ret;
21309 +}
21310 +
21311 +
21312 +
21313 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
21314 +{
21315 +       struct vcmd_wait_exit_v0 vc_data;
21316 +       int ret;
21317 +
21318 +       ret = __wait_exit(vxi);
21319 +       vc_data.reboot_cmd = vxi->reboot_cmd;
21320 +       vc_data.exit_code = vxi->exit_code;
21321 +
21322 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21323 +               ret = -EFAULT;
21324 +       return ret;
21325 +}
21326 +
21327 diff -NurpP --minimal linux-4.4.161/kernel/vserver/space.c linux-4.4.161-vs2.3.9.8/kernel/vserver/space.c
21328 --- linux-4.4.161/kernel/vserver/space.c        1970-01-01 00:00:00.000000000 +0000
21329 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/space.c      2018-10-20 04:57:21.000000000 +0000
21330 @@ -0,0 +1,436 @@
21331 +/*
21332 + *  linux/kernel/vserver/space.c
21333 + *
21334 + *  Virtual Server: Context Space Support
21335 + *
21336 + *  Copyright (C) 2003-2010  Herbert P?tzl
21337 + *
21338 + *  V0.01  broken out from context.c 0.07
21339 + *  V0.02  added task locking for namespace
21340 + *  V0.03  broken out vx_enter_namespace
21341 + *  V0.04  added *space support and commands
21342 + *  V0.05  added credential support
21343 + *
21344 + */
21345 +
21346 +#include <linux/utsname.h>
21347 +#include <linux/nsproxy.h>
21348 +#include <linux/err.h>
21349 +#include <linux/fs_struct.h>
21350 +#include <linux/cred.h>
21351 +#include <asm/uaccess.h>
21352 +
21353 +#include <linux/vs_context.h>
21354 +#include <linux/vserver/space.h>
21355 +#include <linux/vserver/space_cmd.h>
21356 +
21357 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
21358 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
21359 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
21360 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
21361 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
21362 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
21363 +
21364 +
21365 +/* namespace functions */
21366 +
21367 +#include <linux/mnt_namespace.h>
21368 +#include <linux/user_namespace.h>
21369 +#include <linux/pid_namespace.h>
21370 +#include <linux/ipc_namespace.h>
21371 +#include <net/net_namespace.h>
21372 +#include "../fs/mount.h"
21373 +
21374 +
21375 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
21376 +       .mask = CLONE_FS |
21377 +               CLONE_NEWNS |
21378 +#ifdef CONFIG_UTS_NS
21379 +               CLONE_NEWUTS |
21380 +#endif
21381 +#ifdef CONFIG_IPC_NS
21382 +               CLONE_NEWIPC |
21383 +#endif
21384 +#ifdef CONFIG_USER_NS
21385 +               CLONE_NEWUSER |
21386 +#endif
21387 +               0
21388 +};
21389 +
21390 +static const struct vcmd_space_mask_v1 space_mask = {
21391 +       .mask = CLONE_FS |
21392 +               CLONE_NEWNS |
21393 +#ifdef CONFIG_UTS_NS
21394 +               CLONE_NEWUTS |
21395 +#endif
21396 +#ifdef CONFIG_IPC_NS
21397 +               CLONE_NEWIPC |
21398 +#endif
21399 +#ifdef CONFIG_USER_NS
21400 +               CLONE_NEWUSER |
21401 +#endif
21402 +#ifdef CONFIG_PID_NS
21403 +               CLONE_NEWPID |
21404 +#endif
21405 +#ifdef CONFIG_NET_NS
21406 +               CLONE_NEWNET |
21407 +#endif
21408 +               0
21409 +};
21410 +
21411 +static const struct vcmd_space_mask_v1 default_space_mask = {
21412 +       .mask = CLONE_FS |
21413 +               CLONE_NEWNS |
21414 +#ifdef CONFIG_UTS_NS
21415 +               CLONE_NEWUTS |
21416 +#endif
21417 +#ifdef CONFIG_IPC_NS
21418 +               CLONE_NEWIPC |
21419 +#endif
21420 +#ifdef CONFIG_USER_NS
21421 +//             CLONE_NEWUSER |
21422 +#endif
21423 +#ifdef CONFIG_PID_NS
21424 +//             CLONE_NEWPID |
21425 +#endif
21426 +               0
21427 +};
21428 +
21429 +/*
21430 + *     build a new nsproxy mix
21431 + *      assumes that both proxies are 'const'
21432 + *     does not touch nsproxy refcounts
21433 + *     will hold a reference on the result.
21434 + */
21435 +
21436 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
21437 +       struct nsproxy *new_nsproxy, unsigned long mask)
21438 +{
21439 +       struct mnt_namespace *old_ns;
21440 +       struct uts_namespace *old_uts;
21441 +       struct ipc_namespace *old_ipc;
21442 +#ifdef CONFIG_PID_NS
21443 +       struct pid_namespace *old_pid;
21444 +#endif
21445 +#ifdef CONFIG_NET_NS
21446 +       struct net *old_net;
21447 +#endif
21448 +       struct nsproxy *nsproxy;
21449 +
21450 +       nsproxy = copy_nsproxy(old_nsproxy);
21451 +       if (!nsproxy)
21452 +               goto out;
21453 +
21454 +       if (mask & CLONE_NEWNS) {
21455 +               old_ns = nsproxy->mnt_ns;
21456 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
21457 +               if (nsproxy->mnt_ns)
21458 +                       get_mnt_ns(nsproxy->mnt_ns);
21459 +       } else
21460 +               old_ns = NULL;
21461 +
21462 +       if (mask & CLONE_NEWUTS) {
21463 +               old_uts = nsproxy->uts_ns;
21464 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
21465 +               if (nsproxy->uts_ns)
21466 +                       get_uts_ns(nsproxy->uts_ns);
21467 +       } else
21468 +               old_uts = NULL;
21469 +
21470 +       if (mask & CLONE_NEWIPC) {
21471 +               old_ipc = nsproxy->ipc_ns;
21472 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
21473 +               if (nsproxy->ipc_ns)
21474 +                       get_ipc_ns(nsproxy->ipc_ns);
21475 +       } else
21476 +               old_ipc = NULL;
21477 +
21478 +#ifdef CONFIG_PID_NS
21479 +       if (mask & CLONE_NEWPID) {
21480 +               old_pid = nsproxy->pid_ns_for_children;
21481 +               nsproxy->pid_ns_for_children = new_nsproxy->pid_ns_for_children;
21482 +               if (nsproxy->pid_ns_for_children)
21483 +                       get_pid_ns(nsproxy->pid_ns_for_children);
21484 +       } else
21485 +               old_pid = NULL;
21486 +#endif
21487 +#ifdef CONFIG_NET_NS
21488 +       if (mask & CLONE_NEWNET) {
21489 +               old_net = nsproxy->net_ns;
21490 +               nsproxy->net_ns = new_nsproxy->net_ns;
21491 +               if (nsproxy->net_ns)
21492 +                       get_net(nsproxy->net_ns);
21493 +       } else
21494 +               old_net = NULL;
21495 +#endif
21496 +       if (old_ns)
21497 +               put_mnt_ns(old_ns);
21498 +       if (old_uts)
21499 +               put_uts_ns(old_uts);
21500 +       if (old_ipc)
21501 +               put_ipc_ns(old_ipc);
21502 +#ifdef CONFIG_PID_NS
21503 +       if (old_pid)
21504 +               put_pid_ns(old_pid);
21505 +#endif
21506 +#ifdef CONFIG_NET_NS
21507 +       if (old_net)
21508 +               put_net(old_net);
21509 +#endif
21510 +out:
21511 +       return nsproxy;
21512 +}
21513 +
21514 +
21515 +/*
21516 + *     merge two nsproxy structs into a new one.
21517 + *     will hold a reference on the result.
21518 + */
21519 +
21520 +static inline
21521 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
21522 +       struct nsproxy *proxy, unsigned long mask)
21523 +{
21524 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
21525 +
21526 +       if (!proxy)
21527 +               return NULL;
21528 +
21529 +       if (mask) {
21530 +               /* vs_mix_nsproxy returns with reference */
21531 +               return vs_mix_nsproxy(old ? old : &null_proxy,
21532 +                       proxy, mask);
21533 +       }
21534 +       get_nsproxy(proxy);
21535 +       return proxy;
21536 +}
21537 +
21538 +
21539 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21540 +{
21541 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
21542 +       struct fs_struct *fs_cur, *fs = NULL;
21543 +       struct _vx_space *space;
21544 +       int ret, kill = 0;
21545 +
21546 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
21547 +               vxi, vxi->vx_id, mask, index);
21548 +
21549 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
21550 +               return -EACCES;
21551 +
21552 +       if (index >= VX_SPACES)
21553 +               return -EINVAL;
21554 +
21555 +       space = &vxi->space[index];
21556 +
21557 +       if (!mask)
21558 +               mask = space->vx_nsmask;
21559 +
21560 +       if ((mask & space->vx_nsmask) != mask)
21561 +               return -EINVAL;
21562 +
21563 +       if (mask & CLONE_FS) {
21564 +               fs = copy_fs_struct(space->vx_fs);
21565 +               if (!fs)
21566 +                       return -ENOMEM;
21567 +       }
21568 +       proxy = space->vx_nsproxy;
21569 +
21570 +       vxdprintk(VXD_CBIT(space, 9),
21571 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
21572 +               vxi, vxi->vx_id, mask, index, proxy, fs);
21573 +
21574 +       task_lock(current);
21575 +       fs_cur = current->fs;
21576 +
21577 +       if (mask & CLONE_FS) {
21578 +               spin_lock(&fs_cur->lock);
21579 +               current->fs = fs;
21580 +               kill = !--fs_cur->users;
21581 +               spin_unlock(&fs_cur->lock);
21582 +       }
21583 +
21584 +       proxy_cur = current->nsproxy;
21585 +       get_nsproxy(proxy_cur);
21586 +       task_unlock(current);
21587 +
21588 +       if (kill)
21589 +               free_fs_struct(fs_cur);
21590 +
21591 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
21592 +       if (IS_ERR(proxy_new)) {
21593 +               ret = PTR_ERR(proxy_new);
21594 +               goto out_put;
21595 +       }
21596 +
21597 +       proxy_new = xchg(&current->nsproxy, proxy_new);
21598 +
21599 +       if (mask & CLONE_NEWUSER) {
21600 +               struct cred *cred;
21601 +
21602 +               vxdprintk(VXD_CBIT(space, 10),
21603 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
21604 +                       vxi, vxi->vx_id, space->vx_cred,
21605 +                       current->real_cred, current->cred);
21606 +
21607 +               if (space->vx_cred) {
21608 +                       cred = __prepare_creds(space->vx_cred);
21609 +                       if (cred)
21610 +                               commit_creds(cred);
21611 +               }
21612 +       }
21613 +
21614 +       ret = 0;
21615 +
21616 +       if (proxy_new)
21617 +               put_nsproxy(proxy_new);
21618 +out_put:
21619 +       if (proxy_cur)
21620 +               put_nsproxy(proxy_cur);
21621 +       return ret;
21622 +}
21623 +
21624 +
21625 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21626 +{
21627 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
21628 +       struct fs_struct *fs_vxi, *fs = NULL;
21629 +       struct _vx_space *space;
21630 +       int ret, kill = 0;
21631 +
21632 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
21633 +               vxi, vxi->vx_id, mask, index);
21634 +
21635 +       if ((mask & space_mask.mask) != mask)
21636 +               return -EINVAL;
21637 +
21638 +       if (index >= VX_SPACES)
21639 +               return -EINVAL;
21640 +
21641 +       space = &vxi->space[index];
21642 +
21643 +       proxy_vxi = space->vx_nsproxy;
21644 +       fs_vxi = space->vx_fs;
21645 +
21646 +       if (mask & CLONE_FS) {
21647 +               fs = copy_fs_struct(current->fs);
21648 +               if (!fs)
21649 +                       return -ENOMEM;
21650 +       }
21651 +
21652 +       task_lock(current);
21653 +
21654 +       if (mask & CLONE_FS) {
21655 +               spin_lock(&fs_vxi->lock);
21656 +               space->vx_fs = fs;
21657 +               kill = !--fs_vxi->users;
21658 +               spin_unlock(&fs_vxi->lock);
21659 +       }
21660 +
21661 +       proxy_cur = current->nsproxy;
21662 +       get_nsproxy(proxy_cur);
21663 +       task_unlock(current);
21664 +
21665 +       if (kill)
21666 +               free_fs_struct(fs_vxi);
21667 +
21668 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
21669 +       if (IS_ERR(proxy_new)) {
21670 +               ret = PTR_ERR(proxy_new);
21671 +               goto out_put;
21672 +       }
21673 +
21674 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
21675 +       space->vx_nsmask |= mask;
21676 +
21677 +       if (mask & CLONE_NEWUSER) {
21678 +               struct cred *cred;
21679 +
21680 +               vxdprintk(VXD_CBIT(space, 10),
21681 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
21682 +                       vxi, vxi->vx_id, space->vx_cred,
21683 +                       current->real_cred, current->cred);
21684 +
21685 +               cred = prepare_creds();
21686 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
21687 +               if (cred)
21688 +                       abort_creds(cred);
21689 +       }
21690 +
21691 +       ret = 0;
21692 +
21693 +       if (proxy_new)
21694 +               put_nsproxy(proxy_new);
21695 +out_put:
21696 +       if (proxy_cur)
21697 +               put_nsproxy(proxy_cur);
21698 +       return ret;
21699 +}
21700 +
21701 +
21702 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
21703 +{
21704 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21705 +
21706 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21707 +               return -EFAULT;
21708 +
21709 +       return vx_enter_space(vxi, vc_data.mask, 0);
21710 +}
21711 +
21712 +int vc_enter_space(struct vx_info *vxi, void __user *data)
21713 +{
21714 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21715 +
21716 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21717 +               return -EFAULT;
21718 +
21719 +       if (vc_data.index >= VX_SPACES)
21720 +               return -EINVAL;
21721 +
21722 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
21723 +}
21724 +
21725 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
21726 +{
21727 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21728 +
21729 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21730 +               return -EFAULT;
21731 +
21732 +       return vx_set_space(vxi, vc_data.mask, 0);
21733 +}
21734 +
21735 +int vc_set_space(struct vx_info *vxi, void __user *data)
21736 +{
21737 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21738 +
21739 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21740 +               return -EFAULT;
21741 +
21742 +       if (vc_data.index >= VX_SPACES)
21743 +               return -EINVAL;
21744 +
21745 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
21746 +}
21747 +
21748 +int vc_get_space_mask(void __user *data, int type)
21749 +{
21750 +       const struct vcmd_space_mask_v1 *mask;
21751 +
21752 +       if (type == 0)
21753 +               mask = &space_mask_v0;
21754 +       else if (type == 1)
21755 +               mask = &space_mask;
21756 +       else
21757 +               mask = &default_space_mask;
21758 +
21759 +       vxdprintk(VXD_CBIT(space, 10),
21760 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
21761 +
21762 +       if (copy_to_user(data, mask, sizeof(*mask)))
21763 +               return -EFAULT;
21764 +       return 0;
21765 +}
21766 +
21767 diff -NurpP --minimal linux-4.4.161/kernel/vserver/switch.c linux-4.4.161-vs2.3.9.8/kernel/vserver/switch.c
21768 --- linux-4.4.161/kernel/vserver/switch.c       1970-01-01 00:00:00.000000000 +0000
21769 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/switch.c     2018-10-20 04:57:21.000000000 +0000
21770 @@ -0,0 +1,556 @@
21771 +/*
21772 + *  linux/kernel/vserver/switch.c
21773 + *
21774 + *  Virtual Server: Syscall Switch
21775 + *
21776 + *  Copyright (C) 2003-2011  Herbert P?tzl
21777 + *
21778 + *  V0.01  syscall switch
21779 + *  V0.02  added signal to context
21780 + *  V0.03  added rlimit functions
21781 + *  V0.04  added iattr, task/xid functions
21782 + *  V0.05  added debug/history stuff
21783 + *  V0.06  added compat32 layer
21784 + *  V0.07  vcmd args and perms
21785 + *  V0.08  added status commands
21786 + *  V0.09  added tag commands
21787 + *  V0.10  added oom bias
21788 + *  V0.11  added device commands
21789 + *  V0.12  added warn mask
21790 + *
21791 + */
21792 +
21793 +#include <linux/vs_context.h>
21794 +#include <linux/vs_network.h>
21795 +#include <linux/vserver/switch.h>
21796 +
21797 +#include "vci_config.h"
21798 +
21799 +
21800 +static inline
21801 +int vc_get_version(uint32_t id)
21802 +{
21803 +       return VCI_VERSION;
21804 +}
21805 +
21806 +static inline
21807 +int vc_get_vci(uint32_t id)
21808 +{
21809 +       return vci_kernel_config();
21810 +}
21811 +
21812 +#include <linux/vserver/context_cmd.h>
21813 +#include <linux/vserver/cvirt_cmd.h>
21814 +#include <linux/vserver/cacct_cmd.h>
21815 +#include <linux/vserver/limit_cmd.h>
21816 +#include <linux/vserver/network_cmd.h>
21817 +#include <linux/vserver/sched_cmd.h>
21818 +#include <linux/vserver/debug_cmd.h>
21819 +#include <linux/vserver/inode_cmd.h>
21820 +#include <linux/vserver/dlimit_cmd.h>
21821 +#include <linux/vserver/signal_cmd.h>
21822 +#include <linux/vserver/space_cmd.h>
21823 +#include <linux/vserver/tag_cmd.h>
21824 +#include <linux/vserver/device_cmd.h>
21825 +
21826 +#include <linux/vserver/inode.h>
21827 +#include <linux/vserver/dlimit.h>
21828 +
21829 +
21830 +#ifdef CONFIG_COMPAT
21831 +#define __COMPAT(name, id, data, compat)       \
21832 +       (compat) ? name ## _x32(id, data) : name(id, data)
21833 +#define __COMPAT_NO_ID(name, data, compat)     \
21834 +       (compat) ? name ## _x32(data) : name(data)
21835 +#else
21836 +#define __COMPAT(name, id, data, compat)       \
21837 +       name(id, data)
21838 +#define __COMPAT_NO_ID(name, data, compat)     \
21839 +       name(data)
21840 +#endif
21841 +
21842 +
21843 +static inline
21844 +long do_vcmd(uint32_t cmd, uint32_t id,
21845 +       struct vx_info *vxi, struct nx_info *nxi,
21846 +       void __user *data, int compat)
21847 +{
21848 +       switch (cmd) {
21849 +
21850 +       case VCMD_get_version:
21851 +               return vc_get_version(id);
21852 +       case VCMD_get_vci:
21853 +               return vc_get_vci(id);
21854 +
21855 +       case VCMD_task_xid:
21856 +               return vc_task_xid(id);
21857 +       case VCMD_vx_info:
21858 +               return vc_vx_info(vxi, data);
21859 +
21860 +       case VCMD_task_nid:
21861 +               return vc_task_nid(id);
21862 +       case VCMD_nx_info:
21863 +               return vc_nx_info(nxi, data);
21864 +
21865 +       case VCMD_task_tag:
21866 +               return vc_task_tag(id);
21867 +
21868 +       case VCMD_set_space_v1:
21869 +               return vc_set_space_v1(vxi, data);
21870 +       /* this is version 2 */
21871 +       case VCMD_set_space:
21872 +               return vc_set_space(vxi, data);
21873 +
21874 +       case VCMD_get_space_mask_v0:
21875 +               return vc_get_space_mask(data, 0);
21876 +       /* this is version 1 */
21877 +       case VCMD_get_space_mask:
21878 +               return vc_get_space_mask(data, 1);
21879 +
21880 +       case VCMD_get_space_default:
21881 +               return vc_get_space_mask(data, -1);
21882 +
21883 +       case VCMD_set_umask:
21884 +               return vc_set_umask(vxi, data);
21885 +
21886 +       case VCMD_get_umask:
21887 +               return vc_get_umask(vxi, data);
21888 +
21889 +       case VCMD_set_wmask:
21890 +               return vc_set_wmask(vxi, data);
21891 +
21892 +       case VCMD_get_wmask:
21893 +               return vc_get_wmask(vxi, data);
21894 +#ifdef CONFIG_IA32_EMULATION
21895 +       case VCMD_get_rlimit:
21896 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
21897 +       case VCMD_set_rlimit:
21898 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
21899 +#else
21900 +       case VCMD_get_rlimit:
21901 +               return vc_get_rlimit(vxi, data);
21902 +       case VCMD_set_rlimit:
21903 +               return vc_set_rlimit(vxi, data);
21904 +#endif
21905 +       case VCMD_get_rlimit_mask:
21906 +               return vc_get_rlimit_mask(id, data);
21907 +       case VCMD_reset_hits:
21908 +               return vc_reset_hits(vxi, data);
21909 +       case VCMD_reset_minmax:
21910 +               return vc_reset_minmax(vxi, data);
21911 +
21912 +       case VCMD_get_vhi_name:
21913 +               return vc_get_vhi_name(vxi, data);
21914 +       case VCMD_set_vhi_name:
21915 +               return vc_set_vhi_name(vxi, data);
21916 +
21917 +       case VCMD_ctx_stat:
21918 +               return vc_ctx_stat(vxi, data);
21919 +       case VCMD_virt_stat:
21920 +               return vc_virt_stat(vxi, data);
21921 +       case VCMD_sock_stat:
21922 +               return vc_sock_stat(vxi, data);
21923 +       case VCMD_rlimit_stat:
21924 +               return vc_rlimit_stat(vxi, data);
21925 +
21926 +       case VCMD_set_cflags:
21927 +               return vc_set_cflags(vxi, data);
21928 +       case VCMD_get_cflags:
21929 +               return vc_get_cflags(vxi, data);
21930 +
21931 +       /* this is version 1 */
21932 +       case VCMD_set_ccaps:
21933 +               return vc_set_ccaps(vxi, data);
21934 +       /* this is version 1 */
21935 +       case VCMD_get_ccaps:
21936 +               return vc_get_ccaps(vxi, data);
21937 +       case VCMD_set_bcaps:
21938 +               return vc_set_bcaps(vxi, data);
21939 +       case VCMD_get_bcaps:
21940 +               return vc_get_bcaps(vxi, data);
21941 +
21942 +       case VCMD_set_badness:
21943 +               return vc_set_badness(vxi, data);
21944 +       case VCMD_get_badness:
21945 +               return vc_get_badness(vxi, data);
21946 +
21947 +       case VCMD_set_nflags:
21948 +               return vc_set_nflags(nxi, data);
21949 +       case VCMD_get_nflags:
21950 +               return vc_get_nflags(nxi, data);
21951 +
21952 +       case VCMD_set_ncaps:
21953 +               return vc_set_ncaps(nxi, data);
21954 +       case VCMD_get_ncaps:
21955 +               return vc_get_ncaps(nxi, data);
21956 +
21957 +       case VCMD_set_prio_bias:
21958 +               return vc_set_prio_bias(vxi, data);
21959 +       case VCMD_get_prio_bias:
21960 +               return vc_get_prio_bias(vxi, data);
21961 +       case VCMD_add_dlimit:
21962 +               return __COMPAT(vc_add_dlimit, id, data, compat);
21963 +       case VCMD_rem_dlimit:
21964 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
21965 +       case VCMD_set_dlimit:
21966 +               return __COMPAT(vc_set_dlimit, id, data, compat);
21967 +       case VCMD_get_dlimit:
21968 +               return __COMPAT(vc_get_dlimit, id, data, compat);
21969 +
21970 +       case VCMD_ctx_kill:
21971 +               return vc_ctx_kill(vxi, data);
21972 +
21973 +       case VCMD_wait_exit:
21974 +               return vc_wait_exit(vxi, data);
21975 +
21976 +       case VCMD_get_iattr:
21977 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
21978 +       case VCMD_set_iattr:
21979 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
21980 +
21981 +       case VCMD_fget_iattr:
21982 +               return vc_fget_iattr(id, data);
21983 +       case VCMD_fset_iattr:
21984 +               return vc_fset_iattr(id, data);
21985 +
21986 +       case VCMD_enter_space_v0:
21987 +               return vc_enter_space_v1(vxi, NULL);
21988 +       case VCMD_enter_space_v1:
21989 +               return vc_enter_space_v1(vxi, data);
21990 +       /* this is version 2 */
21991 +       case VCMD_enter_space:
21992 +               return vc_enter_space(vxi, data);
21993 +
21994 +       case VCMD_ctx_create_v0:
21995 +               return vc_ctx_create(id, NULL);
21996 +       case VCMD_ctx_create:
21997 +               return vc_ctx_create(id, data);
21998 +       case VCMD_ctx_migrate_v0:
21999 +               return vc_ctx_migrate(vxi, NULL);
22000 +       case VCMD_ctx_migrate:
22001 +               return vc_ctx_migrate(vxi, data);
22002 +
22003 +       case VCMD_net_create_v0:
22004 +               return vc_net_create(id, NULL);
22005 +       case VCMD_net_create:
22006 +               return vc_net_create(id, data);
22007 +       case VCMD_net_migrate:
22008 +               return vc_net_migrate(nxi, data);
22009 +
22010 +       case VCMD_tag_migrate:
22011 +               return vc_tag_migrate(id);
22012 +
22013 +       case VCMD_net_add:
22014 +               return vc_net_add(nxi, data);
22015 +       case VCMD_net_remove:
22016 +               return vc_net_remove(nxi, data);
22017 +
22018 +       case VCMD_net_add_ipv4_v1:
22019 +               return vc_net_add_ipv4_v1(nxi, data);
22020 +       /* this is version 2 */
22021 +       case VCMD_net_add_ipv4:
22022 +               return vc_net_add_ipv4(nxi, data);
22023 +
22024 +       case VCMD_net_rem_ipv4_v1:
22025 +               return vc_net_rem_ipv4_v1(nxi, data);
22026 +       /* this is version 2 */
22027 +       case VCMD_net_rem_ipv4:
22028 +               return vc_net_rem_ipv4(nxi, data);
22029 +#ifdef CONFIG_IPV6
22030 +       case VCMD_net_add_ipv6:
22031 +               return vc_net_add_ipv6(nxi, data);
22032 +       case VCMD_net_remove_ipv6:
22033 +               return vc_net_remove_ipv6(nxi, data);
22034 +#endif
22035 +/*     case VCMD_add_match_ipv4:
22036 +               return vc_add_match_ipv4(nxi, data);
22037 +       case VCMD_get_match_ipv4:
22038 +               return vc_get_match_ipv4(nxi, data);
22039 +#ifdef CONFIG_IPV6
22040 +       case VCMD_add_match_ipv6:
22041 +               return vc_add_match_ipv6(nxi, data);
22042 +       case VCMD_get_match_ipv6:
22043 +               return vc_get_match_ipv6(nxi, data);
22044 +#endif */
22045 +
22046 +#ifdef CONFIG_VSERVER_DEVICE
22047 +       case VCMD_set_mapping:
22048 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
22049 +       case VCMD_unset_mapping:
22050 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
22051 +#endif
22052 +#ifdef CONFIG_VSERVER_HISTORY
22053 +       case VCMD_dump_history:
22054 +               return vc_dump_history(id);
22055 +       case VCMD_read_history:
22056 +               return __COMPAT(vc_read_history, id, data, compat);
22057 +#endif
22058 +       default:
22059 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
22060 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22061 +       }
22062 +       return -ENOSYS;
22063 +}
22064 +
22065 +
22066 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
22067 +       case VCMD_ ## vcmd: perm = _perm;               \
22068 +               args = _args; flags = _flags; break
22069 +
22070 +
22071 +#define VCA_NONE       0x00
22072 +#define VCA_VXI                0x01
22073 +#define VCA_NXI                0x02
22074 +
22075 +#define VCF_NONE       0x00
22076 +#define VCF_INFO       0x01
22077 +#define VCF_ADMIN      0x02
22078 +#define VCF_ARES       0x06    /* includes admin */
22079 +#define VCF_SETUP      0x08
22080 +
22081 +#define VCF_ZIDOK      0x10    /* zero id okay */
22082 +
22083 +
22084 +static inline
22085 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22086 +{
22087 +       long ret;
22088 +       int permit = -1, state = 0;
22089 +       int perm = -1, args = 0, flags = 0;
22090 +       struct vx_info *vxi = NULL;
22091 +       struct nx_info *nxi = NULL;
22092 +
22093 +       switch (cmd) {
22094 +       /* unpriviledged commands */
22095 +       __VCMD(get_version,      0, VCA_NONE,   0);
22096 +       __VCMD(get_vci,          0, VCA_NONE,   0);
22097 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
22098 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
22099 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
22100 +       __VCMD(get_space_default,0, VCA_NONE,   0);
22101 +
22102 +       /* info commands */
22103 +       __VCMD(task_xid,         2, VCA_NONE,   0);
22104 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
22105 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
22106 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
22107 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
22108 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
22109 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
22110 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
22111 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
22112 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
22113 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
22114 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
22115 +
22116 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
22117 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
22118 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
22119 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
22120 +
22121 +       __VCMD(task_nid,         2, VCA_NONE,   0);
22122 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
22123 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
22124 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
22125 +
22126 +       __VCMD(task_tag,         2, VCA_NONE,   0);
22127 +
22128 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
22129 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
22130 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
22131 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
22132 +
22133 +       /* lower admin commands */
22134 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
22135 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
22136 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
22137 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
22138 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
22139 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
22140 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
22141 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
22142 +
22143 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
22144 +       __VCMD(net_create,       5, VCA_NONE,   0);
22145 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
22146 +
22147 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
22148 +
22149 +       /* higher admin commands */
22150 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
22151 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22152 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22153 +
22154 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22155 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22156 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22157 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22158 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22159 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22160 +
22161 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22162 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22163 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22164 +
22165 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22166 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22167 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22168 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22169 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22170 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22171 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22172 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22173 +#ifdef CONFIG_IPV6
22174 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22175 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22176 +#endif
22177 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
22178 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
22179 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
22180 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
22181 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
22182 +
22183 +#ifdef CONFIG_VSERVER_DEVICE
22184 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22185 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22186 +#endif
22187 +       /* debug level admin commands */
22188 +#ifdef CONFIG_VSERVER_HISTORY
22189 +       __VCMD(dump_history,     9, VCA_NONE,   0);
22190 +       __VCMD(read_history,     9, VCA_NONE,   0);
22191 +#endif
22192 +
22193 +       default:
22194 +               perm = -1;
22195 +       }
22196 +
22197 +       vxdprintk(VXD_CBIT(switch, 0),
22198 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
22199 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22200 +               VC_VERSION(cmd), id, data, compat,
22201 +               perm, args, flags);
22202 +
22203 +       ret = -ENOSYS;
22204 +       if (perm < 0)
22205 +               goto out;
22206 +
22207 +       state = 1;
22208 +       if (!capable(CAP_CONTEXT))
22209 +               goto out;
22210 +
22211 +       state = 2;
22212 +       /* moved here from the individual commands */
22213 +       ret = -EPERM;
22214 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
22215 +               goto out;
22216 +
22217 +       state = 3;
22218 +       /* vcmd involves resource management  */
22219 +       ret = -EPERM;
22220 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
22221 +               goto out;
22222 +
22223 +       state = 4;
22224 +       /* various legacy exceptions */
22225 +       switch (cmd) {
22226 +       /* will go away when spectator is a cap */
22227 +       case VCMD_ctx_migrate_v0:
22228 +       case VCMD_ctx_migrate:
22229 +               if (id == 1) {
22230 +                       current->xid = 1;
22231 +                       ret = 1;
22232 +                       goto out;
22233 +               }
22234 +               break;
22235 +
22236 +       /* will go away when spectator is a cap */
22237 +       case VCMD_net_migrate:
22238 +               if (id == 1) {
22239 +                       current->nid = 1;
22240 +                       ret = 1;
22241 +                       goto out;
22242 +               }
22243 +               break;
22244 +       }
22245 +
22246 +       /* vcmds are fine by default */
22247 +       permit = 1;
22248 +
22249 +       /* admin type vcmds require admin ... */
22250 +       if (flags & VCF_ADMIN)
22251 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
22252 +
22253 +       /* ... but setup type vcmds override that */
22254 +       if (!permit && (flags & VCF_SETUP))
22255 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
22256 +
22257 +       state = 5;
22258 +       ret = -EPERM;
22259 +       if (!permit)
22260 +               goto out;
22261 +
22262 +       state = 6;
22263 +       if (!id && (flags & VCF_ZIDOK))
22264 +               goto skip_id;
22265 +
22266 +       ret = -ESRCH;
22267 +       if (args & VCA_VXI) {
22268 +               vxi = lookup_vx_info(id);
22269 +               if (!vxi)
22270 +                       goto out;
22271 +
22272 +               if ((flags & VCF_ADMIN) &&
22273 +                       /* special case kill for shutdown */
22274 +                       (cmd != VCMD_ctx_kill) &&
22275 +                       /* can context be administrated? */
22276 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
22277 +                       ret = -EACCES;
22278 +                       goto out_vxi;
22279 +               }
22280 +       }
22281 +       state = 7;
22282 +       if (args & VCA_NXI) {
22283 +               nxi = lookup_nx_info(id);
22284 +               if (!nxi)
22285 +                       goto out_vxi;
22286 +
22287 +               if ((flags & VCF_ADMIN) &&
22288 +                       /* can context be administrated? */
22289 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
22290 +                       ret = -EACCES;
22291 +                       goto out_nxi;
22292 +               }
22293 +       }
22294 +skip_id:
22295 +       state = 8;
22296 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
22297 +
22298 +out_nxi:
22299 +       if ((args & VCA_NXI) && nxi)
22300 +               put_nx_info(nxi);
22301 +out_vxi:
22302 +       if ((args & VCA_VXI) && vxi)
22303 +               put_vx_info(vxi);
22304 +out:
22305 +       vxdprintk(VXD_CBIT(switch, 1),
22306 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
22307 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22308 +               VC_VERSION(cmd), ret, ret, state, permit);
22309 +       return ret;
22310 +}
22311 +
22312 +asmlinkage long
22313 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
22314 +{
22315 +       return do_vserver(cmd, id, data, 0);
22316 +}
22317 +
22318 +#ifdef CONFIG_COMPAT
22319 +
22320 +asmlinkage long
22321 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
22322 +{
22323 +       return do_vserver(cmd, id, data, 1);
22324 +}
22325 +
22326 +#endif /* CONFIG_COMPAT */
22327 diff -NurpP --minimal linux-4.4.161/kernel/vserver/sysctl.c linux-4.4.161-vs2.3.9.8/kernel/vserver/sysctl.c
22328 --- linux-4.4.161/kernel/vserver/sysctl.c       1970-01-01 00:00:00.000000000 +0000
22329 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/sysctl.c     2018-10-20 04:57:21.000000000 +0000
22330 @@ -0,0 +1,247 @@
22331 +/*
22332 + *  kernel/vserver/sysctl.c
22333 + *
22334 + *  Virtual Context Support
22335 + *
22336 + *  Copyright (C) 2004-2007  Herbert P?tzl
22337 + *
22338 + *  V0.01  basic structure
22339 + *
22340 + */
22341 +
22342 +#include <linux/module.h>
22343 +#include <linux/ctype.h>
22344 +#include <linux/sysctl.h>
22345 +#include <linux/parser.h>
22346 +#include <asm/uaccess.h>
22347 +
22348 +enum {
22349 +       CTL_DEBUG_ERROR         = 0,
22350 +       CTL_DEBUG_SWITCH        = 1,
22351 +       CTL_DEBUG_XID,
22352 +       CTL_DEBUG_NID,
22353 +       CTL_DEBUG_TAG,
22354 +       CTL_DEBUG_NET,
22355 +       CTL_DEBUG_LIMIT,
22356 +       CTL_DEBUG_CRES,
22357 +       CTL_DEBUG_DLIM,
22358 +       CTL_DEBUG_QUOTA,
22359 +       CTL_DEBUG_CVIRT,
22360 +       CTL_DEBUG_SPACE,
22361 +       CTL_DEBUG_PERM,
22362 +       CTL_DEBUG_MISC,
22363 +};
22364 +
22365 +
22366 +unsigned int vs_debug_switch   = 0;
22367 +unsigned int vs_debug_xid      = 0;
22368 +unsigned int vs_debug_nid      = 0;
22369 +unsigned int vs_debug_tag      = 0;
22370 +unsigned int vs_debug_net      = 0;
22371 +unsigned int vs_debug_limit    = 0;
22372 +unsigned int vs_debug_cres     = 0;
22373 +unsigned int vs_debug_dlim     = 0;
22374 +unsigned int vs_debug_quota    = 0;
22375 +unsigned int vs_debug_cvirt    = 0;
22376 +unsigned int vs_debug_space    = 0;
22377 +unsigned int vs_debug_perm     = 0;
22378 +unsigned int vs_debug_misc     = 0;
22379 +
22380 +
22381 +static struct ctl_table_header *vserver_table_header;
22382 +static struct ctl_table vserver_root_table[];
22383 +
22384 +
22385 +void vserver_register_sysctl(void)
22386 +{
22387 +       if (!vserver_table_header) {
22388 +               vserver_table_header = register_sysctl_table(vserver_root_table);
22389 +       }
22390 +
22391 +}
22392 +
22393 +void vserver_unregister_sysctl(void)
22394 +{
22395 +       if (vserver_table_header) {
22396 +               unregister_sysctl_table(vserver_table_header);
22397 +               vserver_table_header = NULL;
22398 +       }
22399 +}
22400 +
22401 +
22402 +static int proc_dodebug(struct ctl_table *table, int write,
22403 +       void __user *buffer, size_t *lenp, loff_t *ppos)
22404 +{
22405 +       char            tmpbuf[20], *p, c;
22406 +       unsigned int    value;
22407 +       size_t          left, len;
22408 +
22409 +       if ((*ppos && !write) || !*lenp) {
22410 +               *lenp = 0;
22411 +               return 0;
22412 +       }
22413 +
22414 +       left = *lenp;
22415 +
22416 +       if (write) {
22417 +               if (!access_ok(VERIFY_READ, buffer, left))
22418 +                       return -EFAULT;
22419 +               p = (char *)buffer;
22420 +               while (left && __get_user(c, p) >= 0 && isspace(c))
22421 +                       left--, p++;
22422 +               if (!left)
22423 +                       goto done;
22424 +
22425 +               if (left > sizeof(tmpbuf) - 1)
22426 +                       return -EINVAL;
22427 +               if (copy_from_user(tmpbuf, p, left))
22428 +                       return -EFAULT;
22429 +               tmpbuf[left] = '\0';
22430 +
22431 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
22432 +                       value = 10 * value + (*p - '0');
22433 +               if (*p && !isspace(*p))
22434 +                       return -EINVAL;
22435 +               while (left && isspace(*p))
22436 +                       left--, p++;
22437 +               *(unsigned int *)table->data = value;
22438 +       } else {
22439 +               if (!access_ok(VERIFY_WRITE, buffer, left))
22440 +                       return -EFAULT;
22441 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
22442 +               if (len > left)
22443 +                       len = left;
22444 +               if (__copy_to_user(buffer, tmpbuf, len))
22445 +                       return -EFAULT;
22446 +               if ((left -= len) > 0) {
22447 +                       if (put_user('\n', (char *)buffer + len))
22448 +                               return -EFAULT;
22449 +                       left--;
22450 +               }
22451 +       }
22452 +
22453 +done:
22454 +       *lenp -= left;
22455 +       *ppos += *lenp;
22456 +       return 0;
22457 +}
22458 +
22459 +static int zero;
22460 +
22461 +#define        CTL_ENTRY(ctl, name)                            \
22462 +       {                                               \
22463 +               .procname       = #name,                \
22464 +               .data           = &vs_ ## name,         \
22465 +               .maxlen         = sizeof(int),          \
22466 +               .mode           = 0644,                 \
22467 +               .proc_handler   = &proc_dodebug,        \
22468 +               .extra1         = &zero,                \
22469 +               .extra2         = &zero,                \
22470 +       }
22471 +
22472 +static struct ctl_table vserver_debug_table[] = {
22473 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
22474 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
22475 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
22476 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
22477 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
22478 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
22479 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
22480 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
22481 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
22482 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
22483 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
22484 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
22485 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
22486 +       { 0 }
22487 +};
22488 +
22489 +static struct ctl_table vserver_root_table[] = {
22490 +       {
22491 +               .procname       = "vserver",
22492 +               .mode           = 0555,
22493 +               .child          = vserver_debug_table
22494 +       },
22495 +       { 0 }
22496 +};
22497 +
22498 +
22499 +static match_table_t tokens = {
22500 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
22501 +       { CTL_DEBUG_XID,        "xid=%x"        },
22502 +       { CTL_DEBUG_NID,        "nid=%x"        },
22503 +       { CTL_DEBUG_TAG,        "tag=%x"        },
22504 +       { CTL_DEBUG_NET,        "net=%x"        },
22505 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
22506 +       { CTL_DEBUG_CRES,       "cres=%x"       },
22507 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
22508 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
22509 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
22510 +       { CTL_DEBUG_SPACE,      "space=%x"      },
22511 +       { CTL_DEBUG_PERM,       "perm=%x"       },
22512 +       { CTL_DEBUG_MISC,       "misc=%x"       },
22513 +       { CTL_DEBUG_ERROR,      NULL            }
22514 +};
22515 +
22516 +#define        HANDLE_CASE(id, name, val)                              \
22517 +       case CTL_DEBUG_ ## id:                                  \
22518 +               vs_debug_ ## name = val;                        \
22519 +               printk("vs_debug_" #name "=0x%x\n", val);       \
22520 +               break
22521 +
22522 +
22523 +static int __init vs_debug_setup(char *str)
22524 +{
22525 +       char *p;
22526 +       int token;
22527 +
22528 +       printk("vs_debug_setup(%s)\n", str);
22529 +       while ((p = strsep(&str, ",")) != NULL) {
22530 +               substring_t args[MAX_OPT_ARGS];
22531 +               unsigned int value;
22532 +
22533 +               if (!*p)
22534 +                       continue;
22535 +
22536 +               token = match_token(p, tokens, args);
22537 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
22538 +
22539 +               switch (token) {
22540 +               HANDLE_CASE(SWITCH, switch, value);
22541 +               HANDLE_CASE(XID,    xid,    value);
22542 +               HANDLE_CASE(NID,    nid,    value);
22543 +               HANDLE_CASE(TAG,    tag,    value);
22544 +               HANDLE_CASE(NET,    net,    value);
22545 +               HANDLE_CASE(LIMIT,  limit,  value);
22546 +               HANDLE_CASE(CRES,   cres,   value);
22547 +               HANDLE_CASE(DLIM,   dlim,   value);
22548 +               HANDLE_CASE(QUOTA,  quota,  value);
22549 +               HANDLE_CASE(CVIRT,  cvirt,  value);
22550 +               HANDLE_CASE(SPACE,  space,  value);
22551 +               HANDLE_CASE(PERM,   perm,   value);
22552 +               HANDLE_CASE(MISC,   misc,   value);
22553 +               default:
22554 +                       return -EINVAL;
22555 +                       break;
22556 +               }
22557 +       }
22558 +       return 1;
22559 +}
22560 +
22561 +__setup("vsdebug=", vs_debug_setup);
22562 +
22563 +
22564 +
22565 +EXPORT_SYMBOL_GPL(vs_debug_switch);
22566 +EXPORT_SYMBOL_GPL(vs_debug_xid);
22567 +EXPORT_SYMBOL_GPL(vs_debug_nid);
22568 +EXPORT_SYMBOL_GPL(vs_debug_net);
22569 +EXPORT_SYMBOL_GPL(vs_debug_limit);
22570 +EXPORT_SYMBOL_GPL(vs_debug_cres);
22571 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
22572 +EXPORT_SYMBOL_GPL(vs_debug_quota);
22573 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
22574 +EXPORT_SYMBOL_GPL(vs_debug_space);
22575 +EXPORT_SYMBOL_GPL(vs_debug_perm);
22576 +EXPORT_SYMBOL_GPL(vs_debug_misc);
22577 +
22578 diff -NurpP --minimal linux-4.4.161/kernel/vserver/tag.c linux-4.4.161-vs2.3.9.8/kernel/vserver/tag.c
22579 --- linux-4.4.161/kernel/vserver/tag.c  1970-01-01 00:00:00.000000000 +0000
22580 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/tag.c        2018-10-20 04:57:21.000000000 +0000
22581 @@ -0,0 +1,63 @@
22582 +/*
22583 + *  linux/kernel/vserver/tag.c
22584 + *
22585 + *  Virtual Server: Shallow Tag Space
22586 + *
22587 + *  Copyright (C) 2007  Herbert P?tzl
22588 + *
22589 + *  V0.01  basic implementation
22590 + *
22591 + */
22592 +
22593 +#include <linux/sched.h>
22594 +#include <linux/vserver/debug.h>
22595 +#include <linux/vs_pid.h>
22596 +#include <linux/vs_tag.h>
22597 +
22598 +#include <linux/vserver/tag_cmd.h>
22599 +
22600 +
22601 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
22602 +{
22603 +       if (!p)
22604 +               BUG();
22605 +
22606 +       vxdprintk(VXD_CBIT(tag, 5),
22607 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
22608 +
22609 +       task_lock(p);
22610 +       p->tag = tag;
22611 +       task_unlock(p);
22612 +
22613 +       vxdprintk(VXD_CBIT(tag, 5),
22614 +               "moved task %p into [#%d]", p, tag);
22615 +       return 0;
22616 +}
22617 +
22618 +/* vserver syscall commands below here */
22619 +
22620 +/* taks xid and vx_info functions */
22621 +
22622 +
22623 +int vc_task_tag(uint32_t id)
22624 +{
22625 +       vtag_t tag;
22626 +
22627 +       if (id) {
22628 +               struct task_struct *tsk;
22629 +               rcu_read_lock();
22630 +               tsk = find_task_by_real_pid(id);
22631 +               tag = (tsk) ? tsk->tag : -ESRCH;
22632 +               rcu_read_unlock();
22633 +       } else
22634 +               tag = dx_current_tag();
22635 +       return tag;
22636 +}
22637 +
22638 +
22639 +int vc_tag_migrate(uint32_t tag)
22640 +{
22641 +       return dx_migrate_task(current, tag & 0xFFFF);
22642 +}
22643 +
22644 +
22645 diff -NurpP --minimal linux-4.4.161/kernel/vserver/vci_config.h linux-4.4.161-vs2.3.9.8/kernel/vserver/vci_config.h
22646 --- linux-4.4.161/kernel/vserver/vci_config.h   1970-01-01 00:00:00.000000000 +0000
22647 +++ linux-4.4.161-vs2.3.9.8/kernel/vserver/vci_config.h 2018-10-20 04:57:21.000000000 +0000
22648 @@ -0,0 +1,80 @@
22649 +
22650 +/*  interface version */
22651 +
22652 +#define VCI_VERSION            0x00020308
22653 +
22654 +
22655 +enum {
22656 +       VCI_KCBIT_NO_DYNAMIC = 0,
22657 +
22658 +       VCI_KCBIT_PROC_SECURE = 4,
22659 +       /* VCI_KCBIT_HARDCPU = 5, */
22660 +       /* VCI_KCBIT_IDLELIMIT = 6, */
22661 +       /* VCI_KCBIT_IDLETIME = 7, */
22662 +
22663 +       VCI_KCBIT_COWBL = 8,
22664 +       VCI_KCBIT_FULLCOWBL = 9,
22665 +       VCI_KCBIT_SPACES = 10,
22666 +       VCI_KCBIT_NETV2 = 11,
22667 +       VCI_KCBIT_MEMCG = 12,
22668 +       VCI_KCBIT_MEMCG_SWAP = 13,
22669 +
22670 +       VCI_KCBIT_DEBUG = 16,
22671 +       VCI_KCBIT_HISTORY = 20,
22672 +       VCI_KCBIT_TAGGED = 24,
22673 +       VCI_KCBIT_PPTAG = 28,
22674 +
22675 +       VCI_KCBIT_MORE = 31,
22676 +};
22677 +
22678 +
22679 +static inline uint32_t vci_kernel_config(void)
22680 +{
22681 +       return
22682 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
22683 +
22684 +       /* configured features */
22685 +#ifdef CONFIG_VSERVER_PROC_SECURE
22686 +       (1 << VCI_KCBIT_PROC_SECURE) |
22687 +#endif
22688 +#ifdef CONFIG_VSERVER_COWBL
22689 +       (1 << VCI_KCBIT_COWBL) |
22690 +       (1 << VCI_KCBIT_FULLCOWBL) |
22691 +#endif
22692 +       (1 << VCI_KCBIT_SPACES) |
22693 +       (1 << VCI_KCBIT_NETV2) |
22694 +#ifdef CONFIG_MEMCG
22695 +       (1 << VCI_KCBIT_MEMCG) |
22696 +#endif
22697 +#ifdef CONFIG_MEMCG_SWAP
22698 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
22699 +#endif
22700 +
22701 +       /* debug options */
22702 +#ifdef CONFIG_VSERVER_DEBUG
22703 +       (1 << VCI_KCBIT_DEBUG) |
22704 +#endif
22705 +#ifdef CONFIG_VSERVER_HISTORY
22706 +       (1 << VCI_KCBIT_HISTORY) |
22707 +#endif
22708 +
22709 +       /* inode context tagging */
22710 +#if    defined(CONFIG_TAGGING_NONE)
22711 +       (0 << VCI_KCBIT_TAGGED) |
22712 +#elif  defined(CONFIG_TAGGING_UID16)
22713 +       (1 << VCI_KCBIT_TAGGED) |
22714 +#elif  defined(CONFIG_TAGGING_GID16)
22715 +       (2 << VCI_KCBIT_TAGGED) |
22716 +#elif  defined(CONFIG_TAGGING_ID24)
22717 +       (3 << VCI_KCBIT_TAGGED) |
22718 +#elif  defined(CONFIG_TAGGING_INTERN)
22719 +       (4 << VCI_KCBIT_TAGGED) |
22720 +#elif  defined(CONFIG_TAGGING_RUNTIME)
22721 +       (5 << VCI_KCBIT_TAGGED) |
22722 +#else
22723 +       (7 << VCI_KCBIT_TAGGED) |
22724 +#endif
22725 +       (1 << VCI_KCBIT_PPTAG) |
22726 +       0;
22727 +}
22728 +
22729 diff -NurpP --minimal linux-4.4.161/mm/memcontrol.c linux-4.4.161-vs2.3.9.8/mm/memcontrol.c
22730 --- linux-4.4.161/mm/memcontrol.c       2018-10-20 02:34:31.000000000 +0000
22731 +++ linux-4.4.161-vs2.3.9.8/mm/memcontrol.c     2018-10-20 05:50:20.000000000 +0000
22732 @@ -2888,6 +2888,42 @@ static u64 mem_cgroup_read_u64(struct cg
22733         }
22734  }
22735  
22736 +unsigned long mem_cgroup_mem_usage_pages(struct mem_cgroup *memcg)
22737 +{
22738 +       return mem_cgroup_usage(memcg, false);
22739 +}
22740 +
22741 +unsigned long mem_cgroup_mem_limit_pages(struct mem_cgroup *memcg)
22742 +{
22743 +       return (u64)memcg->memory.limit;
22744 +}
22745 +
22746 +unsigned long mem_cgroup_memsw_usage_pages(struct mem_cgroup *memcg)
22747 +{
22748 +       return mem_cgroup_usage(memcg, true);
22749 +}
22750 +
22751 +unsigned long mem_cgroup_memsw_limit_pages(struct mem_cgroup *memcg)
22752 +{
22753 +       return (u64)memcg->memsw.limit;
22754 +}
22755 +
22756 +void dump_mem_cgroup(struct mem_cgroup *memcg)
22757 +{
22758 +       printk(KERN_INFO "memcg: %p/%d:\n"
22759 +               "\tmemory:\t%lu/%lu %lu/%lu\n"
22760 +               "\tmemsw:\t%lu/%lu %lu/%lu\n"
22761 +               "\tkmem:\t%lu/%lu %lu/%lu\n",
22762 +               memcg, memcg->id.id,
22763 +               page_counter_read(&memcg->memory), memcg->memory.limit,
22764 +               memcg->memory.watermark, memcg->memory.failcnt,
22765 +               page_counter_read(&memcg->memsw), memcg->memsw.limit,
22766 +               memcg->memsw.watermark, memcg->memsw.failcnt,
22767 +               page_counter_read(&memcg->kmem), memcg->kmem.limit,
22768 +               memcg->kmem.watermark, memcg->kmem.failcnt);
22769 +}
22770 +
22771 +
22772  #ifdef CONFIG_MEMCG_KMEM
22773  static int memcg_activate_kmem(struct mem_cgroup *memcg,
22774                                unsigned long nr_pages)
22775 diff -NurpP --minimal linux-4.4.161/mm/oom_kill.c linux-4.4.161-vs2.3.9.8/mm/oom_kill.c
22776 --- linux-4.4.161/mm/oom_kill.c 2016-01-10 23:01:32.000000000 +0000
22777 +++ linux-4.4.161-vs2.3.9.8/mm/oom_kill.c       2018-10-20 04:57:21.000000000 +0000
22778 @@ -35,6 +35,8 @@
22779  #include <linux/freezer.h>
22780  #include <linux/ftrace.h>
22781  #include <linux/ratelimit.h>
22782 +#include <linux/reboot.h>
22783 +#include <linux/vs_context.h>
22784  
22785  #define CREATE_TRACE_POINTS
22786  #include <trace/events/oom.h>
22787 @@ -131,11 +133,18 @@ static inline bool is_sysrq_oom(struct o
22788  static bool oom_unkillable_task(struct task_struct *p,
22789                 struct mem_cgroup *memcg, const nodemask_t *nodemask)
22790  {
22791 -       if (is_global_init(p))
22792 +       unsigned xid = vx_current_xid();
22793 +
22794 +       /* skip the init task, global and per guest */
22795 +       if (task_is_init(p))
22796                 return true;
22797         if (p->flags & PF_KTHREAD)
22798                 return true;
22799  
22800 +       /* skip other guest and host processes if oom in guest */
22801 +       if (xid && vx_task_xid(p) != xid)
22802 +               return true;
22803 +
22804         /* When mem_cgroup_out_of_memory() and p is not member of the group */
22805         if (memcg && !task_in_mem_cgroup(p, memcg))
22806                 return true;
22807 @@ -534,8 +543,8 @@ void oom_kill_process(struct oom_control
22808         if (__ratelimit(&oom_rs))
22809                 dump_header(oc, p, memcg);
22810  
22811 -       pr_err("%s: Kill process %d (%s) score %u or sacrifice child\n",
22812 -               message, task_pid_nr(p), p->comm, points);
22813 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
22814 +               message, task_pid_nr(p), p->xid, p->comm, points);
22815  
22816         /*
22817          * If any of p's children has a different mm and is eligible for kill,
22818 @@ -585,8 +594,8 @@ void oom_kill_process(struct oom_control
22819          */
22820         do_send_sig_info(SIGKILL, SEND_SIG_FORCED, victim, true);
22821         mark_oom_victim(victim);
22822 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
22823 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
22824 +       pr_err("Killed process %d:%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
22825 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
22826                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
22827                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
22828         task_unlock(victim);
22829 @@ -622,6 +631,8 @@ void oom_kill_process(struct oom_control
22830  }
22831  #undef K
22832  
22833 +long vs_oom_action(unsigned int);
22834 +
22835  /*
22836   * Determines whether the kernel must panic because of the panic_on_oom sysctl.
22837   */
22838 @@ -722,7 +733,12 @@ bool out_of_memory(struct oom_control *o
22839         /* Found nothing?!?! Either we hang forever, or we panic. */
22840         if (!p && !is_sysrq_oom(oc)) {
22841                 dump_header(oc, NULL, NULL);
22842 -               panic("Out of memory and no killable processes...\n");
22843 +
22844 +               /* avoid panic for guest OOM */
22845 +               if (vx_current_xid())
22846 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
22847 +               else
22848 +                       panic("Out of memory and no killable processes...\n");
22849         }
22850         if (p && p != (void *)-1UL) {
22851                 oom_kill_process(oc, p, points, totalpages, NULL,
22852 diff -NurpP --minimal linux-4.4.161/mm/page_alloc.c linux-4.4.161-vs2.3.9.8/mm/page_alloc.c
22853 --- linux-4.4.161/mm/page_alloc.c       2018-10-20 02:34:31.000000000 +0000
22854 +++ linux-4.4.161-vs2.3.9.8/mm/page_alloc.c     2018-10-20 04:57:21.000000000 +0000
22855 @@ -62,6 +62,8 @@
22856  #include <linux/sched/rt.h>
22857  #include <linux/page_owner.h>
22858  #include <linux/kthread.h>
22859 +#include <linux/vs_base.h>
22860 +#include <linux/vs_limit.h>
22861  
22862  #include <asm/sections.h>
22863  #include <asm/tlbflush.h>
22864 @@ -3659,6 +3661,9 @@ void si_meminfo(struct sysinfo *val)
22865         val->totalhigh = totalhigh_pages;
22866         val->freehigh = nr_free_highpages();
22867         val->mem_unit = PAGE_SIZE;
22868 +
22869 +       if (vx_flags(VXF_VIRT_MEM, 0))
22870 +               vx_vsi_meminfo(val);
22871  }
22872  
22873  EXPORT_SYMBOL(si_meminfo);
22874 @@ -3684,6 +3689,9 @@ void si_meminfo_node(struct sysinfo *val
22875         val->freehigh = 0;
22876  #endif
22877         val->mem_unit = PAGE_SIZE;
22878 +
22879 +       if (vx_flags(VXF_VIRT_MEM, 0))
22880 +               vx_vsi_meminfo(val);
22881  }
22882  #endif
22883  
22884 diff -NurpP --minimal linux-4.4.161/mm/pgtable-generic.c linux-4.4.161-vs2.3.9.8/mm/pgtable-generic.c
22885 --- linux-4.4.161/mm/pgtable-generic.c  2018-10-20 02:34:31.000000000 +0000
22886 +++ linux-4.4.161-vs2.3.9.8/mm/pgtable-generic.c        2018-10-20 04:57:21.000000000 +0000
22887 @@ -6,6 +6,8 @@
22888   *  Copyright (C) 2010  Linus Torvalds
22889   */
22890  
22891 +#include <linux/mm.h>
22892 +
22893  #include <linux/pagemap.h>
22894  #include <asm/tlb.h>
22895  #include <asm-generic/pgtable.h>
22896 diff -NurpP --minimal linux-4.4.161/mm/shmem.c linux-4.4.161-vs2.3.9.8/mm/shmem.c
22897 --- linux-4.4.161/mm/shmem.c    2018-10-20 02:34:31.000000000 +0000
22898 +++ linux-4.4.161-vs2.3.9.8/mm/shmem.c  2018-10-20 05:50:20.000000000 +0000
22899 @@ -2200,7 +2200,7 @@ static int shmem_statfs(struct dentry *d
22900  {
22901         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
22902  
22903 -       buf->f_type = TMPFS_MAGIC;
22904 +       buf->f_type = TMPFS_SUPER_MAGIC;
22905         buf->f_bsize = PAGE_CACHE_SIZE;
22906         buf->f_namelen = NAME_MAX;
22907         if (sbinfo->max_blocks) {
22908 @@ -3046,7 +3046,7 @@ int shmem_fill_super(struct super_block
22909         sb->s_maxbytes = MAX_LFS_FILESIZE;
22910         sb->s_blocksize = PAGE_CACHE_SIZE;
22911         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
22912 -       sb->s_magic = TMPFS_MAGIC;
22913 +       sb->s_magic = TMPFS_SUPER_MAGIC;
22914         sb->s_op = &shmem_ops;
22915         sb->s_time_gran = 1;
22916  #ifdef CONFIG_TMPFS_XATTR
22917 diff -NurpP --minimal linux-4.4.161/mm/slab.c linux-4.4.161-vs2.3.9.8/mm/slab.c
22918 --- linux-4.4.161/mm/slab.c     2018-10-20 02:34:31.000000000 +0000
22919 +++ linux-4.4.161-vs2.3.9.8/mm/slab.c   2018-10-20 04:57:21.000000000 +0000
22920 @@ -337,6 +337,8 @@ static void kmem_cache_node_init(struct
22921  #define STATS_INC_FREEMISS(x)  do { } while (0)
22922  #endif
22923  
22924 +#include "slab_vs.h"
22925 +
22926  #if DEBUG
22927  
22928  /*
22929 @@ -3183,6 +3185,7 @@ slab_alloc_node(struct kmem_cache *cache
22930         /* ___cache_alloc_node can fall back to other nodes */
22931         ptr = ____cache_alloc_node(cachep, flags, nodeid);
22932    out:
22933 +       vx_slab_alloc(cachep, flags);
22934         local_irq_restore(save_flags);
22935         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
22936         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
22937 @@ -3371,6 +3374,7 @@ static inline void __cache_free(struct k
22938         check_irq_off();
22939         kmemleak_free_recursive(objp, cachep->flags);
22940         objp = cache_free_debugcheck(cachep, objp, caller);
22941 +       vx_slab_free(cachep);
22942  
22943         kmemcheck_slab_free(cachep, objp, cachep->object_size);
22944  
22945 diff -NurpP --minimal linux-4.4.161/mm/slab_vs.h linux-4.4.161-vs2.3.9.8/mm/slab_vs.h
22946 --- linux-4.4.161/mm/slab_vs.h  1970-01-01 00:00:00.000000000 +0000
22947 +++ linux-4.4.161-vs2.3.9.8/mm/slab_vs.h        2018-10-20 04:57:21.000000000 +0000
22948 @@ -0,0 +1,29 @@
22949 +
22950 +#include <linux/vserver/context.h>
22951 +
22952 +#include <linux/vs_context.h>
22953 +
22954 +static inline
22955 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
22956 +{
22957 +       int what = gfp_zone(cachep->allocflags);
22958 +       struct vx_info *vxi = current_vx_info();
22959 +
22960 +       if (!vxi)
22961 +               return;
22962 +
22963 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
22964 +}
22965 +
22966 +static inline
22967 +void vx_slab_free(struct kmem_cache *cachep)
22968 +{
22969 +       int what = gfp_zone(cachep->allocflags);
22970 +       struct vx_info *vxi = current_vx_info();
22971 +
22972 +       if (!vxi)
22973 +               return;
22974 +
22975 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
22976 +}
22977 +
22978 diff -NurpP --minimal linux-4.4.161/mm/swapfile.c linux-4.4.161-vs2.3.9.8/mm/swapfile.c
22979 --- linux-4.4.161/mm/swapfile.c 2018-10-20 02:34:31.000000000 +0000
22980 +++ linux-4.4.161-vs2.3.9.8/mm/swapfile.c       2018-10-20 05:50:20.000000000 +0000
22981 @@ -39,6 +39,7 @@
22982  #include <asm/tlbflush.h>
22983  #include <linux/swapops.h>
22984  #include <linux/swap_cgroup.h>
22985 +#include <linux/vs_base.h>
22986  
22987  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
22988                                  unsigned char);
22989 @@ -2070,6 +2071,16 @@ static int swap_show(struct seq_file *sw
22990  
22991         if (si == SEQ_START_TOKEN) {
22992                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
22993 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
22994 +                       struct sysinfo si = { 0 };
22995 +
22996 +                       vx_vsi_swapinfo(&si);
22997 +                       if (si.totalswap < (1 << 10))
22998 +                               return 0;
22999 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23000 +                               "hdv0", "partition", si.totalswap >> 10,
23001 +                               (si.totalswap - si.freeswap) >> 10, -1);
23002 +               }
23003                 return 0;
23004         }
23005  
23006 @@ -2627,6 +2638,8 @@ void si_swapinfo(struct sysinfo *val)
23007         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23008         val->totalswap = total_swap_pages + nr_to_be_unused;
23009         spin_unlock(&swap_lock);
23010 +       if (vx_flags(VXF_VIRT_MEM, 0))
23011 +               vx_vsi_swapinfo(val);
23012  }
23013  
23014  /*
23015 diff -NurpP --minimal linux-4.4.161/net/bridge/br_multicast.c linux-4.4.161-vs2.3.9.8/net/bridge/br_multicast.c
23016 --- linux-4.4.161/net/bridge/br_multicast.c     2018-10-20 02:34:31.000000000 +0000
23017 +++ linux-4.4.161-vs2.3.9.8/net/bridge/br_multicast.c   2018-10-20 04:57:21.000000000 +0000
23018 @@ -462,7 +462,7 @@ static struct sk_buff *br_ip6_multicast_
23019         ip6h->hop_limit = 1;
23020         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23021         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23022 -                              &ip6h->saddr)) {
23023 +                              &ip6h->saddr, NULL)) {
23024                 kfree_skb(skb);
23025                 br->has_ipv6_addr = 0;
23026                 return NULL;
23027 diff -NurpP --minimal linux-4.4.161/net/core/dev.c linux-4.4.161-vs2.3.9.8/net/core/dev.c
23028 --- linux-4.4.161/net/core/dev.c        2018-10-20 02:34:31.000000000 +0000
23029 +++ linux-4.4.161-vs2.3.9.8/net/core/dev.c      2018-10-20 05:50:20.000000000 +0000
23030 @@ -124,6 +124,7 @@
23031  #include <linux/in.h>
23032  #include <linux/jhash.h>
23033  #include <linux/random.h>
23034 +#include <linux/vs_inet.h>
23035  #include <trace/events/napi.h>
23036  #include <trace/events/net.h>
23037  #include <trace/events/skb.h>
23038 @@ -726,7 +727,8 @@ struct net_device *__dev_get_by_name(str
23039         struct hlist_head *head = dev_name_hash(net, name);
23040  
23041         hlist_for_each_entry(dev, head, name_hlist)
23042 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23043 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23044 +                   nx_dev_visible(current_nx_info(), dev))
23045                         return dev;
23046  
23047         return NULL;
23048 @@ -751,7 +753,8 @@ struct net_device *dev_get_by_name_rcu(s
23049         struct hlist_head *head = dev_name_hash(net, name);
23050  
23051         hlist_for_each_entry_rcu(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 @@ -801,7 +804,8 @@ struct net_device *__dev_get_by_index(st
23059         struct hlist_head *head = dev_index_hash(net, ifindex);
23060  
23061         hlist_for_each_entry(dev, head, index_hlist)
23062 -               if (dev->ifindex == ifindex)
23063 +               if ((dev->ifindex == ifindex) &&
23064 +                   nx_dev_visible(current_nx_info(), dev))
23065                         return dev;
23066  
23067         return NULL;
23068 @@ -819,7 +823,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
23069   *     about locking. The caller must hold RCU lock.
23070   */
23071  
23072 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23073 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
23074  {
23075         struct net_device *dev;
23076         struct hlist_head *head = dev_index_hash(net, ifindex);
23077 @@ -830,6 +834,16 @@ struct net_device *dev_get_by_index_rcu(
23078  
23079         return NULL;
23080  }
23081 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23082 +
23083 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23084 +{
23085 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23086 +
23087 +       if (nx_dev_visible(current_nx_info(), dev))
23088 +               return dev;
23089 +       return NULL;
23090 +}
23091  EXPORT_SYMBOL(dev_get_by_index_rcu);
23092  
23093  
23094 @@ -912,7 +926,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23095  
23096         for_each_netdev_rcu(net, dev)
23097                 if (dev->type == type &&
23098 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
23099 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23100 +                   nx_dev_visible(current_nx_info(), dev))
23101                         return dev;
23102  
23103         return NULL;
23104 @@ -924,9 +939,11 @@ struct net_device *__dev_getfirstbyhwtyp
23105         struct net_device *dev;
23106  
23107         ASSERT_RTNL();
23108 -       for_each_netdev(net, dev)
23109 -               if (dev->type == type)
23110 +       for_each_netdev(net, dev) {
23111 +               if ((dev->type == type) &&
23112 +                   nx_dev_visible(current_nx_info(), dev))
23113                         return dev;
23114 +       }
23115  
23116         return NULL;
23117  }
23118 @@ -938,7 +955,8 @@ struct net_device *dev_getfirstbyhwtype(
23119  
23120         rcu_read_lock();
23121         for_each_netdev_rcu(net, dev)
23122 -               if (dev->type == type) {
23123 +               if ((dev->type == type) &&
23124 +                   nx_dev_visible(current_nx_info(), dev)) {
23125                         dev_hold(dev);
23126                         ret = dev;
23127                         break;
23128 @@ -968,7 +986,8 @@ struct net_device *__dev_get_by_flags(st
23129  
23130         ret = NULL;
23131         for_each_netdev(net, dev) {
23132 -               if (((dev->flags ^ if_flags) & mask) == 0) {
23133 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
23134 +                       nx_dev_visible(current_nx_info(), dev)) {
23135                         ret = dev;
23136                         break;
23137                 }
23138 @@ -1046,6 +1065,8 @@ static int __dev_alloc_name(struct net *
23139                                 continue;
23140                         if (i < 0 || i >= max_netdevices)
23141                                 continue;
23142 +                       if (!nx_dev_visible(current_nx_info(), d))
23143 +                               continue;
23144  
23145                         /*  avoid cases where sscanf is not exact inverse of printf */
23146                         snprintf(buf, IFNAMSIZ, name, i);
23147 diff -NurpP --minimal linux-4.4.161/net/core/net-procfs.c linux-4.4.161-vs2.3.9.8/net/core/net-procfs.c
23148 --- linux-4.4.161/net/core/net-procfs.c 2016-01-10 23:01:32.000000000 +0000
23149 +++ linux-4.4.161-vs2.3.9.8/net/core/net-procfs.c       2018-10-20 04:57:21.000000000 +0000
23150 @@ -1,6 +1,7 @@
23151  #include <linux/netdevice.h>
23152  #include <linux/proc_fs.h>
23153  #include <linux/seq_file.h>
23154 +#include <linux/vs_inet.h>
23155  #include <net/wext.h>
23156  
23157  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
23158 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
23159  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
23160  {
23161         struct rtnl_link_stats64 temp;
23162 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23163 +       const struct rtnl_link_stats64 *stats;
23164 +
23165 +       /* device visible inside network context? */
23166 +       if (!nx_dev_visible(current_nx_info(), dev))
23167 +               return;
23168  
23169 +       stats = dev_get_stats(dev, &temp);
23170         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23171                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23172                    dev->name, stats->rx_bytes, stats->rx_packets,
23173 diff -NurpP --minimal linux-4.4.161/net/core/rtnetlink.c linux-4.4.161-vs2.3.9.8/net/core/rtnetlink.c
23174 --- linux-4.4.161/net/core/rtnetlink.c  2018-10-20 02:34:31.000000000 +0000
23175 +++ linux-4.4.161-vs2.3.9.8/net/core/rtnetlink.c        2018-10-20 05:50:20.000000000 +0000
23176 @@ -1456,6 +1456,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23177                 hlist_for_each_entry(dev, head, index_hlist) {
23178                         if (idx < s_idx)
23179                                 goto cont;
23180 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23181 +                               continue;
23182                         err = rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23183                                                NETLINK_CB(cb->skb).portid,
23184                                                cb->nlh->nlmsg_seq, 0,
23185 @@ -2562,6 +2564,9 @@ void rtmsg_ifinfo(int type, struct net_d
23186  {
23187         struct sk_buff *skb;
23188  
23189 +       if (!nx_dev_visible(current_nx_info(), dev))
23190 +               return;
23191 +
23192         if (dev->reg_state != NETREG_REGISTERED)
23193                 return;
23194  
23195 diff -NurpP --minimal linux-4.4.161/net/core/sock.c linux-4.4.161-vs2.3.9.8/net/core/sock.c
23196 --- linux-4.4.161/net/core/sock.c       2018-10-20 02:34:31.000000000 +0000
23197 +++ linux-4.4.161-vs2.3.9.8/net/core/sock.c     2018-10-20 04:57:21.000000000 +0000
23198 @@ -134,6 +134,10 @@
23199  #include <linux/sock_diag.h>
23200  
23201  #include <linux/filter.h>
23202 +#include <linux/vs_socket.h>
23203 +#include <linux/vs_limit.h>
23204 +#include <linux/vs_context.h>
23205 +#include <linux/vs_network.h>
23206  
23207  #include <trace/events/sock.h>
23208  
23209 @@ -1363,6 +1367,8 @@ static struct sock *sk_prot_alloc(struct
23210                         goto out_free_sec;
23211                 sk_tx_queue_clear(sk);
23212         }
23213 +               sock_vx_init(sk);
23214 +               sock_nx_init(sk);
23215  
23216         return sk;
23217  
23218 @@ -1469,6 +1475,11 @@ void sk_destruct(struct sock *sk)
23219         put_pid(sk->sk_peer_pid);
23220         if (likely(sk->sk_net_refcnt))
23221                 put_net(sock_net(sk));
23222 +       vx_sock_dec(sk);
23223 +       clr_vx_info(&sk->sk_vx_info);
23224 +       sk->sk_xid = -1;
23225 +       clr_nx_info(&sk->sk_nx_info);
23226 +       sk->sk_nid = -1;
23227         sk_prot_free(sk->sk_prot_creator, sk);
23228  }
23229  
23230 @@ -1521,6 +1532,8 @@ struct sock *sk_clone_lock(const struct
23231                 /* SANITY */
23232                 if (likely(newsk->sk_net_refcnt))
23233                         get_net(sock_net(newsk));
23234 +               sock_vx_init(newsk);
23235 +               sock_nx_init(newsk);
23236                 sk_node_init(&newsk->sk_node);
23237                 sock_lock_init(newsk);
23238                 bh_lock_sock(newsk);
23239 @@ -1586,6 +1599,12 @@ struct sock *sk_clone_lock(const struct
23240                 smp_wmb();
23241                 atomic_set(&newsk->sk_refcnt, 2);
23242  
23243 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
23244 +               newsk->sk_xid = sk->sk_xid;
23245 +               vx_sock_inc(newsk);
23246 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
23247 +               newsk->sk_nid = sk->sk_nid;
23248 +
23249                 /*
23250                  * Increment the counter in the same struct proto as the master
23251                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
23252 @@ -2424,6 +2443,12 @@ void sock_init_data(struct socket *sock,
23253  
23254         sk->sk_stamp = ktime_set(-1L, 0);
23255  
23256 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
23257 +       sk->sk_xid = vx_current_xid();
23258 +       vx_sock_inc(sk);
23259 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
23260 +       sk->sk_nid = nx_current_nid();
23261 +
23262  #ifdef CONFIG_NET_RX_BUSY_POLL
23263         sk->sk_napi_id          =       0;
23264         sk->sk_ll_usec          =       sysctl_net_busy_read;
23265 diff -NurpP --minimal linux-4.4.161/net/ipv4/af_inet.c linux-4.4.161-vs2.3.9.8/net/ipv4/af_inet.c
23266 --- linux-4.4.161/net/ipv4/af_inet.c    2018-10-20 02:34:31.000000000 +0000
23267 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/af_inet.c  2018-10-20 05:50:20.000000000 +0000
23268 @@ -308,10 +308,15 @@ lookup_protocol:
23269         }
23270  
23271         err = -EPERM;
23272 +       if ((protocol == IPPROTO_ICMP) &&
23273 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
23274 +               goto override;
23275 +
23276         if (sock->type == SOCK_RAW && !kern &&
23277             !ns_capable(net->user_ns, CAP_NET_RAW))
23278                 goto out_rcu_unlock;
23279  
23280 +override:
23281         sock->ops = answer->ops;
23282         answer_prot = answer->prot;
23283         answer_flags = answer->flags;
23284 @@ -425,6 +430,7 @@ int inet_bind(struct socket *sock, struc
23285         struct sock *sk = sock->sk;
23286         struct inet_sock *inet = inet_sk(sk);
23287         struct net *net = sock_net(sk);
23288 +       struct nx_v4_sock_addr nsa;
23289         unsigned short snum;
23290         int chk_addr_ret;
23291         u32 tb_id = RT_TABLE_LOCAL;
23292 @@ -450,7 +456,11 @@ int inet_bind(struct socket *sock, struc
23293         }
23294  
23295         tb_id = l3mdev_fib_table_by_index(net, sk->sk_bound_dev_if) ? : tb_id;
23296 -       chk_addr_ret = inet_addr_type_table(net, addr->sin_addr.s_addr, tb_id);
23297 +       err = v4_map_sock_addr(inet, addr, &nsa);
23298 +       if (err)
23299 +               goto out;
23300 +
23301 +       chk_addr_ret = inet_addr_type_table(net, nsa.saddr, tb_id);
23302  
23303         /* Not specified by any standard per-se, however it breaks too
23304          * many applications when removed.  It is unfortunate since
23305 @@ -462,7 +472,7 @@ int inet_bind(struct socket *sock, struc
23306         err = -EADDRNOTAVAIL;
23307         if (!net->ipv4.sysctl_ip_nonlocal_bind &&
23308             !(inet->freebind || inet->transparent) &&
23309 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
23310 +           nsa.saddr != htonl(INADDR_ANY) &&
23311             chk_addr_ret != RTN_LOCAL &&
23312             chk_addr_ret != RTN_MULTICAST &&
23313             chk_addr_ret != RTN_BROADCAST)
23314 @@ -488,7 +498,7 @@ int inet_bind(struct socket *sock, struc
23315         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
23316                 goto out_release_sock;
23317  
23318 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23319 +       v4_set_sock_addr(inet, &nsa);
23320         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23321                 inet->inet_saddr = 0;  /* Use device */
23322  
23323 @@ -708,11 +718,13 @@ int inet_getname(struct socket *sock, st
23324                      peer == 1))
23325                         return -ENOTCONN;
23326                 sin->sin_port = inet->inet_dport;
23327 -               sin->sin_addr.s_addr = inet->inet_daddr;
23328 +               sin->sin_addr.s_addr =
23329 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
23330         } else {
23331                 __be32 addr = inet->inet_rcv_saddr;
23332                 if (!addr)
23333                         addr = inet->inet_saddr;
23334 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
23335                 sin->sin_port = inet->inet_sport;
23336                 sin->sin_addr.s_addr = addr;
23337         }
23338 @@ -896,6 +908,7 @@ static int inet_compat_ioctl(struct sock
23339         return err;
23340  }
23341  #endif
23342 +#include <linux/vs_limit.h>
23343  
23344  const struct proto_ops inet_stream_ops = {
23345         .family            = PF_INET,
23346 diff -NurpP --minimal linux-4.4.161/net/ipv4/arp.c linux-4.4.161-vs2.3.9.8/net/ipv4/arp.c
23347 --- linux-4.4.161/net/ipv4/arp.c        2018-10-20 02:34:31.000000000 +0000
23348 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/arp.c      2018-10-20 04:57:21.000000000 +0000
23349 @@ -1307,6 +1307,7 @@ static void arp_format_neigh_entry(struc
23350         struct net_device *dev = n->dev;
23351         int hatype = dev->type;
23352  
23353 +       /* FIXME: check for network context */
23354         read_lock(&n->lock);
23355         /* Convert hardware address to XX:XX:XX:XX ... form. */
23356  #if IS_ENABLED(CONFIG_AX25)
23357 @@ -1338,6 +1339,7 @@ static void arp_format_pneigh_entry(stru
23358         int hatype = dev ? dev->type : 0;
23359         char tbuf[16];
23360  
23361 +       /* FIXME: check for network context */
23362         sprintf(tbuf, "%pI4", n->key);
23363         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
23364                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
23365 diff -NurpP --minimal linux-4.4.161/net/ipv4/devinet.c linux-4.4.161-vs2.3.9.8/net/ipv4/devinet.c
23366 --- linux-4.4.161/net/ipv4/devinet.c    2018-10-20 02:34:31.000000000 +0000
23367 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/devinet.c  2018-10-20 04:57:21.000000000 +0000
23368 @@ -538,6 +538,7 @@ struct in_device *inetdev_by_index(struc
23369  }
23370  EXPORT_SYMBOL(inetdev_by_index);
23371  
23372 +
23373  /* Called only from RTNL semaphored context. No locks. */
23374  
23375  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
23376 @@ -992,6 +993,8 @@ int devinet_ioctl(struct net *net, unsig
23377  
23378         in_dev = __in_dev_get_rtnl(dev);
23379         if (in_dev) {
23380 +               struct nx_info *nxi = current_nx_info();
23381 +
23382                 if (tryaddrmatch) {
23383                         /* Matthias Andree */
23384                         /* compare label and address (4.4BSD style) */
23385 @@ -1000,6 +1003,8 @@ int devinet_ioctl(struct net *net, unsig
23386                            This is checked above. */
23387                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23388                              ifap = &ifa->ifa_next) {
23389 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23390 +                                       continue;
23391                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
23392                                     sin_orig.sin_addr.s_addr ==
23393                                                         ifa->ifa_local) {
23394 @@ -1012,9 +1017,12 @@ int devinet_ioctl(struct net *net, unsig
23395                    comparing just the label */
23396                 if (!ifa) {
23397                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23398 -                            ifap = &ifa->ifa_next)
23399 +                            ifap = &ifa->ifa_next) {
23400 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23401 +                                       continue;
23402                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
23403                                         break;
23404 +                       }
23405                 }
23406         }
23407  
23408 @@ -1168,6 +1176,8 @@ static int inet_gifconf(struct net_devic
23409                 goto out;
23410  
23411         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
23412 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
23413 +                       continue;
23414                 if (!buf) {
23415                         done += sizeof(ifr);
23416                         continue;
23417 @@ -1573,6 +1583,7 @@ static int inet_dump_ifaddr(struct sk_bu
23418         struct net_device *dev;
23419         struct in_device *in_dev;
23420         struct in_ifaddr *ifa;
23421 +       struct sock *sk = skb->sk;
23422         struct hlist_head *head;
23423  
23424         s_h = cb->args[0];
23425 @@ -1596,6 +1607,8 @@ static int inet_dump_ifaddr(struct sk_bu
23426  
23427                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
23428                              ifa = ifa->ifa_next, ip_idx++) {
23429 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
23430 +                               continue;
23431                                 if (ip_idx < s_ip_idx)
23432                                         continue;
23433                                 if (inet_fill_ifaddr(skb, ifa,
23434 diff -NurpP --minimal linux-4.4.161/net/ipv4/fib_trie.c linux-4.4.161-vs2.3.9.8/net/ipv4/fib_trie.c
23435 --- linux-4.4.161/net/ipv4/fib_trie.c   2018-10-20 02:34:31.000000000 +0000
23436 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/fib_trie.c 2018-10-20 04:57:21.000000000 +0000
23437 @@ -2591,6 +2591,7 @@ static int fib_route_seq_show(struct seq
23438  
23439                 seq_setwidth(seq, 127);
23440  
23441 +               /* FIXME: check for network context? */
23442                 if (fi)
23443                         seq_printf(seq,
23444                                    "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
23445 diff -NurpP --minimal linux-4.4.161/net/ipv4/inet_connection_sock.c linux-4.4.161-vs2.3.9.8/net/ipv4/inet_connection_sock.c
23446 --- linux-4.4.161/net/ipv4/inet_connection_sock.c       2018-10-20 02:34:31.000000000 +0000
23447 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/inet_connection_sock.c     2018-10-20 04:57:21.000000000 +0000
23448 @@ -43,6 +43,37 @@ void inet_get_local_port_range(struct ne
23449  }
23450  EXPORT_SYMBOL(inet_get_local_port_range);
23451  
23452 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23453 +{
23454 +       __be32  sk1_rcv_saddr = sk1->sk_rcv_saddr,
23455 +               sk2_rcv_saddr = sk2->sk_rcv_saddr;
23456 +
23457 +       if (inet_v6_ipv6only(sk2))
23458 +               return 0;
23459 +
23460 +       if (sk1_rcv_saddr &&
23461 +           sk2_rcv_saddr &&
23462 +           sk1_rcv_saddr == sk2_rcv_saddr)
23463 +               return 1;
23464 +
23465 +       if (sk1_rcv_saddr &&
23466 +           !sk2_rcv_saddr &&
23467 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
23468 +               return 1;
23469 +
23470 +       if (sk2_rcv_saddr &&
23471 +           !sk1_rcv_saddr &&
23472 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
23473 +               return 1;
23474 +
23475 +       if (!sk1_rcv_saddr &&
23476 +           !sk2_rcv_saddr &&
23477 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
23478 +               return 1;
23479 +
23480 +       return 0;
23481 +}
23482 +
23483  int inet_csk_bind_conflict(const struct sock *sk,
23484                            const struct inet_bind_bucket *tb, bool relax)
23485  {
23486 @@ -70,15 +101,13 @@ int inet_csk_bind_conflict(const struct
23487                             (sk2->sk_state != TCP_TIME_WAIT &&
23488                              !uid_eq(uid, sock_i_uid(sk2))))) {
23489  
23490 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23491 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23492 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23493                                         break;
23494                         }
23495                         if (!relax && reuse && sk2->sk_reuse &&
23496                             sk2->sk_state != TCP_LISTEN) {
23497  
23498 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23499 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23500 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23501                                         break;
23502                         }
23503                 }
23504 diff -NurpP --minimal linux-4.4.161/net/ipv4/inet_diag.c linux-4.4.161-vs2.3.9.8/net/ipv4/inet_diag.c
23505 --- linux-4.4.161/net/ipv4/inet_diag.c  2016-01-10 23:01:32.000000000 +0000
23506 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/inet_diag.c        2018-10-20 06:34:05.000000000 +0000
23507 @@ -31,6 +31,8 @@
23508  
23509  #include <linux/inet.h>
23510  #include <linux/stddef.h>
23511 +#include <linux/vs_network.h>
23512 +#include <linux/vs_inet.h>
23513  
23514  #include <linux/inet_diag.h>
23515  #include <linux/sock_diag.h>
23516 @@ -85,8 +87,8 @@ static void inet_diag_msg_common_fill(st
23517         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23518         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23519  
23520 -       r->id.idiag_src[0] = sk->sk_rcv_saddr;
23521 -       r->id.idiag_dst[0] = sk->sk_daddr;
23522 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, sk->sk_rcv_saddr);
23523 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, sk->sk_daddr);
23524         }
23525  }
23526  
23527 @@ -761,6 +763,9 @@ void inet_diag_dump_icsk(struct inet_has
23528                                 if (!net_eq(sock_net(sk), net))
23529                                         continue;
23530  
23531 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23532 +                                       continue;
23533 +
23534                                 if (num < s_num) {
23535                                         num++;
23536                                         continue;
23537 @@ -822,6 +827,8 @@ skip_listen_ht:
23538  
23539                         if (!net_eq(sock_net(sk), net))
23540                                 continue;
23541 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23542 +                               continue;
23543                         if (num < s_num)
23544                                 goto next_normal;
23545                         state = (sk->sk_state == TCP_TIME_WAIT) ?
23546 diff -NurpP --minimal linux-4.4.161/net/ipv4/inet_hashtables.c linux-4.4.161-vs2.3.9.8/net/ipv4/inet_hashtables.c
23547 --- linux-4.4.161/net/ipv4/inet_hashtables.c    2016-01-10 23:01:32.000000000 +0000
23548 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/inet_hashtables.c  2018-10-20 04:57:21.000000000 +0000
23549 @@ -23,6 +23,7 @@
23550  #include <net/inet_connection_sock.h>
23551  #include <net/inet_hashtables.h>
23552  #include <net/secure_seq.h>
23553 +#include <net/route.h>
23554  #include <net/ip.h>
23555  
23556  static u32 inet_ehashfn(const struct net *net, const __be32 laddr,
23557 @@ -183,6 +184,11 @@ static inline int compute_score(struct s
23558                         if (rcv_saddr != daddr)
23559                                 return -1;
23560                         score += 4;
23561 +               } else {
23562 +                       /* block non nx_info ips */
23563 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
23564 +                               daddr, NXA_MASK_BIND))
23565 +                               return -1;
23566                 }
23567                 if (sk->sk_bound_dev_if) {
23568                         if (sk->sk_bound_dev_if != dif)
23569 @@ -202,7 +208,6 @@ static inline int compute_score(struct s
23570   * wildcarded during the search since they can never be otherwise.
23571   */
23572  
23573 -
23574  struct sock *__inet_lookup_listener(struct net *net,
23575                                     struct inet_hashinfo *hashinfo,
23576                                     const __be32 saddr, __be16 sport,
23577 @@ -238,6 +243,7 @@ begin:
23578                         phash = next_pseudo_random32(phash);
23579                 }
23580         }
23581 +
23582         /*
23583          * if the nulls value we got at the end of this lookup is
23584          * not the expected one, we must restart lookup.
23585 diff -NurpP --minimal linux-4.4.161/net/ipv4/netfilter.c linux-4.4.161-vs2.3.9.8/net/ipv4/netfilter.c
23586 --- linux-4.4.161/net/ipv4/netfilter.c  2018-10-20 02:34:31.000000000 +0000
23587 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/netfilter.c        2018-10-20 04:57:21.000000000 +0000
23588 @@ -11,7 +11,7 @@
23589  #include <linux/skbuff.h>
23590  #include <linux/gfp.h>
23591  #include <linux/export.h>
23592 -#include <net/route.h>
23593 +// #include <net/route.h>
23594  #include <net/xfrm.h>
23595  #include <net/ip.h>
23596  #include <net/netfilter/nf_queue.h>
23597 diff -NurpP --minimal linux-4.4.161/net/ipv4/raw.c linux-4.4.161-vs2.3.9.8/net/ipv4/raw.c
23598 --- linux-4.4.161/net/ipv4/raw.c        2018-10-20 02:34:31.000000000 +0000
23599 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/raw.c      2018-10-20 04:57:21.000000000 +0000
23600 @@ -126,7 +126,7 @@ static struct sock *__raw_v4_lookup(stru
23601  
23602                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
23603                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
23604 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
23605 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
23606                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23607                         goto found; /* gotcha */
23608         }
23609 @@ -416,6 +416,12 @@ static int raw_send_hdrinc(struct sock *
23610                                 skb_transport_header(skb))->type);
23611         }
23612  
23613 +       err = -EPERM;
23614 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
23615 +               sk->sk_nx_info &&
23616 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
23617 +               goto error_free;
23618 +
23619         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT,
23620                       net, sk, skb, NULL, rt->dst.dev,
23621                       dst_output);
23622 @@ -626,6 +632,16 @@ static int raw_sendmsg(struct sock *sk,
23623                         goto done;
23624         }
23625  
23626 +       if (sk->sk_nx_info) {
23627 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
23628 +               if (IS_ERR(rt)) {
23629 +                       err = PTR_ERR(rt);
23630 +                       rt = NULL;
23631 +                       goto done;
23632 +               }
23633 +               ip_rt_put(rt);
23634 +       }
23635 +
23636         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
23637         rt = ip_route_output_flow(net, &fl4, sk);
23638         if (IS_ERR(rt)) {
23639 @@ -704,17 +720,19 @@ static int raw_bind(struct sock *sk, str
23640  {
23641         struct inet_sock *inet = inet_sk(sk);
23642         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
23643 +       struct nx_v4_sock_addr nsa = { 0 };
23644         int ret = -EINVAL;
23645         int chk_addr_ret;
23646  
23647         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
23648                 goto out;
23649 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
23650 +       v4_map_sock_addr(inet, addr, &nsa);
23651 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
23652         ret = -EADDRNOTAVAIL;
23653 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
23654 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
23655             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
23656                 goto out;
23657 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23658 +       v4_set_sock_addr(inet, &nsa);
23659         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23660                 inet->inet_saddr = 0;  /* Use device */
23661         sk_dst_reset(sk);
23662 @@ -763,7 +781,8 @@ static int raw_recvmsg(struct sock *sk,
23663         /* Copy the address. */
23664         if (sin) {
23665                 sin->sin_family = AF_INET;
23666 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
23667 +               sin->sin_addr.s_addr =
23668 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
23669                 sin->sin_port = 0;
23670                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
23671                 *addr_len = sizeof(*sin);
23672 @@ -959,7 +978,8 @@ static struct sock *raw_get_first(struct
23673         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
23674                         ++state->bucket) {
23675                 sk_for_each(sk, &state->h->ht[state->bucket])
23676 -                       if (sock_net(sk) == seq_file_net(seq))
23677 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
23678 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23679                                 goto found;
23680         }
23681         sk = NULL;
23682 @@ -975,7 +995,8 @@ static struct sock *raw_get_next(struct
23683                 sk = sk_next(sk);
23684  try_again:
23685                 ;
23686 -       } while (sk && sock_net(sk) != seq_file_net(seq));
23687 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
23688 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
23689  
23690         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
23691                 sk = sk_head(&state->h->ht[state->bucket]);
23692 diff -NurpP --minimal linux-4.4.161/net/ipv4/route.c linux-4.4.161-vs2.3.9.8/net/ipv4/route.c
23693 --- linux-4.4.161/net/ipv4/route.c      2018-10-20 02:34:31.000000000 +0000
23694 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/route.c    2018-10-20 04:57:21.000000000 +0000
23695 @@ -2238,7 +2238,7 @@ struct rtable *__ip_route_output_key_has
23696  
23697  
23698         if (fl4->flowi4_oif) {
23699 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
23700 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
23701                 rth = ERR_PTR(-ENODEV);
23702                 if (!dev_out)
23703                         goto out;
23704 diff -NurpP --minimal linux-4.4.161/net/ipv4/tcp.c linux-4.4.161-vs2.3.9.8/net/ipv4/tcp.c
23705 --- linux-4.4.161/net/ipv4/tcp.c        2018-10-20 02:34:31.000000000 +0000
23706 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/tcp.c      2018-10-20 05:50:20.000000000 +0000
23707 @@ -269,6 +269,7 @@
23708  #include <linux/crypto.h>
23709  #include <linux/time.h>
23710  #include <linux/slab.h>
23711 +#include <linux/in.h>
23712  
23713  #include <net/icmp.h>
23714  #include <net/inet_common.h>
23715 diff -NurpP --minimal linux-4.4.161/net/ipv4/tcp_ipv4.c linux-4.4.161-vs2.3.9.8/net/ipv4/tcp_ipv4.c
23716 --- linux-4.4.161/net/ipv4/tcp_ipv4.c   2018-10-20 02:34:31.000000000 +0000
23717 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/tcp_ipv4.c 2018-10-20 05:50:20.000000000 +0000
23718 @@ -1890,6 +1890,10 @@ static void *listening_get_next(struct s
23719         sk = sk_nulls_next(sk);
23720  get_sk:
23721         sk_nulls_for_each_from(sk, node) {
23722 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
23723 +                       sk, sk->sk_nid, nx_current_nid());
23724 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23725 +                       continue;
23726                 if (!net_eq(sock_net(sk), net))
23727                         continue;
23728                 if (sk->sk_family == st->family) {
23729 @@ -1954,6 +1958,11 @@ static void *established_get_first(struc
23730  
23731                 spin_lock_bh(lock);
23732                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
23733 +                       vxdprintk(VXD_CBIT(net, 6),
23734 +                               "sk,egf: %p [#%d] (from %d)",
23735 +                               sk, sk->sk_nid, nx_current_nid());
23736 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23737 +                               continue;
23738                         if (sk->sk_family != st->family ||
23739                             !net_eq(sock_net(sk), net)) {
23740                                 continue;
23741 @@ -1980,6 +1989,11 @@ static void *established_get_next(struct
23742         sk = sk_nulls_next(sk);
23743  
23744         sk_nulls_for_each_from(sk, node) {
23745 +               vxdprintk(VXD_CBIT(net, 6),
23746 +                       "sk,egn: %p [#%d] (from %d)",
23747 +                       sk, sk->sk_nid, nx_current_nid());
23748 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23749 +                       continue;
23750                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
23751                         return sk;
23752         }
23753 @@ -2171,9 +2185,9 @@ static void get_openreq4(const struct re
23754         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
23755                 " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK",
23756                 i,
23757 -               ireq->ir_loc_addr,
23758 +               nx_map_sock_lback(current_nx_info(), ireq->ir_loc_addr),
23759                 ireq->ir_num,
23760 -               ireq->ir_rmt_addr,
23761 +               nx_map_sock_lback(current_nx_info(), ireq->ir_rmt_addr),
23762                 ntohs(ireq->ir_rmt_port),
23763                 TCP_SYN_RECV,
23764                 0, 0, /* could print option size, but that is af dependent. */
23765 @@ -2196,8 +2210,8 @@ static void get_tcp4_sock(struct sock *s
23766         const struct inet_connection_sock *icsk = inet_csk(sk);
23767         const struct inet_sock *inet = inet_sk(sk);
23768         const struct fastopen_queue *fastopenq = &icsk->icsk_accept_queue.fastopenq;
23769 -       __be32 dest = inet->inet_daddr;
23770 -       __be32 src = inet->inet_rcv_saddr;
23771 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
23772 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
23773         __u16 destp = ntohs(inet->inet_dport);
23774         __u16 srcp = ntohs(inet->inet_sport);
23775         int rx_queue;
23776 @@ -2256,8 +2270,8 @@ static void get_timewait4_sock(const str
23777         __be32 dest, src;
23778         __u16 destp, srcp;
23779  
23780 -       dest  = tw->tw_daddr;
23781 -       src   = tw->tw_rcv_saddr;
23782 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
23783 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
23784         destp = ntohs(tw->tw_dport);
23785         srcp  = ntohs(tw->tw_sport);
23786  
23787 diff -NurpP --minimal linux-4.4.161/net/ipv4/tcp_minisocks.c linux-4.4.161-vs2.3.9.8/net/ipv4/tcp_minisocks.c
23788 --- linux-4.4.161/net/ipv4/tcp_minisocks.c      2018-10-20 02:34:31.000000000 +0000
23789 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/tcp_minisocks.c    2018-10-20 05:50:20.000000000 +0000
23790 @@ -23,6 +23,9 @@
23791  #include <linux/slab.h>
23792  #include <linux/sysctl.h>
23793  #include <linux/workqueue.h>
23794 +#include <linux/vs_limit.h>
23795 +#include <linux/vs_socket.h>
23796 +#include <linux/vs_context.h>
23797  #include <net/tcp.h>
23798  #include <net/inet_common.h>
23799  #include <net/xfrm.h>
23800 @@ -292,6 +295,11 @@ void tcp_time_wait(struct sock *sk, int
23801                 tcptw->tw_ts_offset     = tp->tsoffset;
23802                 tcptw->tw_last_oow_ack_time = 0;
23803  
23804 +               tw->tw_xid              = sk->sk_xid;
23805 +               tw->tw_vx_info          = NULL;
23806 +               tw->tw_nid              = sk->sk_nid;
23807 +               tw->tw_nx_info          = NULL;
23808 +
23809  #if IS_ENABLED(CONFIG_IPV6)
23810                 if (tw->tw_family == PF_INET6) {
23811                         struct ipv6_pinfo *np = inet6_sk(sk);
23812 diff -NurpP --minimal linux-4.4.161/net/ipv4/udp.c linux-4.4.161-vs2.3.9.8/net/ipv4/udp.c
23813 --- linux-4.4.161/net/ipv4/udp.c        2018-10-20 02:34:31.000000000 +0000
23814 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/udp.c      2018-10-20 04:57:21.000000000 +0000
23815 @@ -309,14 +309,7 @@ fail:
23816  }
23817  EXPORT_SYMBOL(udp_lib_get_port);
23818  
23819 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23820 -{
23821 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
23822 -
23823 -       return  (!ipv6_only_sock(sk2)  &&
23824 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
23825 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
23826 -}
23827 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
23828  
23829  static u32 udp4_portaddr_hash(const struct net *net, __be32 saddr,
23830                               unsigned int port)
23831 @@ -355,6 +348,11 @@ static inline int compute_score(struct s
23832                 if (inet->inet_rcv_saddr != daddr)
23833                         return -1;
23834                 score += 4;
23835 +               } else {
23836 +                       /* block non nx_info ips */
23837 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
23838 +                               daddr, NXA_MASK_BIND))
23839 +                               return -1;
23840         }
23841  
23842         if (inet->inet_daddr) {
23843 @@ -489,6 +487,7 @@ begin:
23844         return result;
23845  }
23846  
23847 +
23848  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
23849   * harder than this. -DaveM
23850   */
23851 @@ -535,6 +534,11 @@ begin:
23852         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
23853                 score = compute_score(sk, net, saddr, hnum, sport,
23854                                       daddr, dport, dif);
23855 +               /* FIXME: disabled?
23856 +               if (score == 9) {
23857 +                       result = sk;
23858 +                       break;
23859 +               } else */
23860                 if (score > badness) {
23861                         result = sk;
23862                         badness = score;
23863 @@ -559,6 +563,7 @@ begin:
23864         if (get_nulls_value(node) != slot)
23865                 goto begin;
23866  
23867 +
23868         if (result) {
23869                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
23870                         result = NULL;
23871 @@ -568,6 +573,7 @@ begin:
23872                         goto begin;
23873                 }
23874         }
23875 +
23876         rcu_read_unlock();
23877         return result;
23878  }
23879 @@ -602,7 +608,7 @@ static inline bool __udp_is_mcast_sock(s
23880             udp_sk(sk)->udp_port_hash != hnum ||
23881             (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
23882             (inet->inet_dport != rmt_port && inet->inet_dport) ||
23883 -           (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
23884 +           !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
23885             ipv6_only_sock(sk) ||
23886             (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23887                 return false;
23888 @@ -1035,6 +1041,16 @@ int udp_sendmsg(struct sock *sk, struct
23889                                 goto out;
23890                 }
23891  
23892 +               if (sk->sk_nx_info) {
23893 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
23894 +                       if (IS_ERR(rt)) {
23895 +                               err = PTR_ERR(rt);
23896 +                               rt = NULL;
23897 +                               goto out;
23898 +                       }
23899 +                       ip_rt_put(rt);
23900 +               }
23901 +
23902                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
23903                 rt = ip_route_output_flow(net, fl4, sk);
23904                 if (IS_ERR(rt)) {
23905 @@ -1340,7 +1356,8 @@ try_again:
23906         if (sin) {
23907                 sin->sin_family = AF_INET;
23908                 sin->sin_port = udp_hdr(skb)->source;
23909 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
23910 +               sin->sin_addr.s_addr = nx_map_sock_lback(
23911 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
23912                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
23913                 *addr_len = sizeof(*sin);
23914         }
23915 @@ -2327,6 +2344,8 @@ static struct sock *udp_get_first(struct
23916                 sk_nulls_for_each(sk, node, &hslot->head) {
23917                         if (!net_eq(sock_net(sk), net))
23918                                 continue;
23919 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23920 +                               continue;
23921                         if (sk->sk_family == state->family)
23922                                 goto found;
23923                 }
23924 @@ -2344,7 +2363,9 @@ static struct sock *udp_get_next(struct
23925  
23926         do {
23927                 sk = sk_nulls_next(sk);
23928 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
23929 +       } while (sk && (!net_eq(sock_net(sk), net) ||
23930 +               sk->sk_family != state->family ||
23931 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
23932  
23933         if (!sk) {
23934                 if (state->bucket <= state->udp_table->mask)
23935 @@ -2440,8 +2461,8 @@ static void udp4_format_sock(struct sock
23936                 int bucket)
23937  {
23938         struct inet_sock *inet = inet_sk(sp);
23939 -       __be32 dest = inet->inet_daddr;
23940 -       __be32 src  = inet->inet_rcv_saddr;
23941 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
23942 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
23943         __u16 destp       = ntohs(inet->inet_dport);
23944         __u16 srcp        = ntohs(inet->inet_sport);
23945  
23946 diff -NurpP --minimal linux-4.4.161/net/ipv4/udp_diag.c linux-4.4.161-vs2.3.9.8/net/ipv4/udp_diag.c
23947 --- linux-4.4.161/net/ipv4/udp_diag.c   2016-01-10 23:01:32.000000000 +0000
23948 +++ linux-4.4.161-vs2.3.9.8/net/ipv4/udp_diag.c 2018-10-20 04:57:21.000000000 +0000
23949 @@ -118,6 +118,8 @@ static void udp_dump(struct udp_table *t
23950  
23951                         if (!net_eq(sock_net(sk), net))
23952                                 continue;
23953 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23954 +                               continue;
23955                         if (num < s_num)
23956                                 goto next;
23957                         if (!(r->idiag_states & (1 << sk->sk_state)))
23958 diff -NurpP --minimal linux-4.4.161/net/ipv6/addrconf.c linux-4.4.161-vs2.3.9.8/net/ipv6/addrconf.c
23959 --- linux-4.4.161/net/ipv6/addrconf.c   2018-10-20 02:34:31.000000000 +0000
23960 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/addrconf.c 2018-10-20 04:57:21.000000000 +0000
23961 @@ -92,6 +92,8 @@
23962  #include <linux/proc_fs.h>
23963  #include <linux/seq_file.h>
23964  #include <linux/export.h>
23965 +#include <linux/vs_network.h>
23966 +#include <linux/vs_inet6.h>
23967  
23968  /* Set to 3 to get tracing... */
23969  #define ACONF_DEBUG 2
23970 @@ -1445,7 +1447,8 @@ static int __ipv6_dev_get_saddr(struct n
23971                                 struct ipv6_saddr_dst *dst,
23972                                 struct inet6_dev *idev,
23973                                 struct ipv6_saddr_score *scores,
23974 -                               int hiscore_idx)
23975 +                               int hiscore_idx,
23976 +                               struct nx_info *nxi)
23977  {
23978         struct ipv6_saddr_score *score = &scores[1 - hiscore_idx], *hiscore = &scores[hiscore_idx];
23979  
23980 @@ -1475,6 +1478,8 @@ static int __ipv6_dev_get_saddr(struct n
23981                                             idev->dev->name);
23982                         continue;
23983                 }
23984 +               if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
23985 +                       continue;
23986  
23987                 score->rule = -1;
23988                 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
23989 @@ -1522,7 +1527,7 @@ out:
23990  
23991  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
23992                        const struct in6_addr *daddr, unsigned int prefs,
23993 -                      struct in6_addr *saddr)
23994 +                      struct in6_addr *saddr, struct nx_info *nxi)
23995  {
23996         struct ipv6_saddr_score scores[2], *hiscore;
23997         struct ipv6_saddr_dst dst;
23998 @@ -1571,13 +1576,15 @@ int ipv6_dev_get_saddr(struct net *net,
23999  
24000         if (use_oif_addr) {
24001                 if (idev)
24002 -                       hiscore_idx = __ipv6_dev_get_saddr(net, &dst, idev, scores, hiscore_idx);
24003 +                       hiscore_idx = __ipv6_dev_get_saddr(net, &dst,
24004 +                               idev, scores, hiscore_idx, nxi);
24005         } else {
24006                 for_each_netdev_rcu(net, dev) {
24007                         idev = __in6_dev_get(dev);
24008                         if (!idev)
24009                                 continue;
24010 -                       hiscore_idx = __ipv6_dev_get_saddr(net, &dst, idev, scores, hiscore_idx);
24011 +                       hiscore_idx = __ipv6_dev_get_saddr(net, &dst,
24012 +                               idev, scores, hiscore_idx, nxi);
24013                 }
24014         }
24015         rcu_read_unlock();
24016 @@ -3849,7 +3856,10 @@ static void if6_seq_stop(struct seq_file
24017  static int if6_seq_show(struct seq_file *seq, void *v)
24018  {
24019         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
24020 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24021 +
24022 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
24023 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
24024 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24025                    &ifp->addr,
24026                    ifp->idev->dev->ifindex,
24027                    ifp->prefix_len,
24028 @@ -4433,6 +4443,11 @@ static int in6_dump_addrs(struct inet6_d
24029         struct ifacaddr6 *ifaca;
24030         int err = 1;
24031         int ip_idx = *p_ip_idx;
24032 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24033 +
24034 +       /* disable ipv6 on non v6 guests */
24035 +       if (nxi && !nx_info_has_v6(nxi))
24036 +               return skb->len;
24037  
24038         read_lock_bh(&idev->lock);
24039         switch (type) {
24040 @@ -4443,6 +4458,8 @@ static int in6_dump_addrs(struct inet6_d
24041                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
24042                         if (ip_idx < s_ip_idx)
24043                                 goto next;
24044 +                       if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
24045 +                               goto next;
24046                         err = inet6_fill_ifaddr(skb, ifa,
24047                                                 NETLINK_CB(cb->skb).portid,
24048                                                 cb->nlh->nlmsg_seq,
24049 @@ -4460,6 +4477,8 @@ static int in6_dump_addrs(struct inet6_d
24050                      ifmca = ifmca->next, ip_idx++) {
24051                         if (ip_idx < s_ip_idx)
24052                                 continue;
24053 +                       if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
24054 +                               continue;
24055                         err = inet6_fill_ifmcaddr(skb, ifmca,
24056                                                   NETLINK_CB(cb->skb).portid,
24057                                                   cb->nlh->nlmsg_seq,
24058 @@ -4475,6 +4494,8 @@ static int in6_dump_addrs(struct inet6_d
24059                      ifaca = ifaca->aca_next, ip_idx++) {
24060                         if (ip_idx < s_ip_idx)
24061                                 continue;
24062 +                       if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
24063 +                               continue;
24064                         err = inet6_fill_ifacaddr(skb, ifaca,
24065                                                   NETLINK_CB(cb->skb).portid,
24066                                                   cb->nlh->nlmsg_seq,
24067 @@ -4503,6 +4524,10 @@ static int inet6_dump_addr(struct sk_buf
24068         struct inet6_dev *idev;
24069         struct hlist_head *head;
24070  
24071 +       /* FIXME: maybe disable ipv6 on non v6 guests?
24072 +       if (skb->sk && skb->sk->sk_vx_info)
24073 +               return skb->len; */
24074 +
24075         s_h = cb->args[0];
24076         s_idx = idx = cb->args[1];
24077         s_ip_idx = ip_idx = cb->args[2];
24078 @@ -5011,6 +5036,7 @@ static int inet6_dump_ifinfo(struct sk_b
24079         struct net_device *dev;
24080         struct inet6_dev *idev;
24081         struct hlist_head *head;
24082 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24083  
24084         s_h = cb->args[0];
24085         s_idx = cb->args[1];
24086 @@ -5022,6 +5048,8 @@ static int inet6_dump_ifinfo(struct sk_b
24087                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24088                         if (idx < s_idx)
24089                                 goto cont;
24090 +                       if (!v6_dev_in_nx_info(dev, nxi))
24091 +                               goto cont;
24092                         idev = __in6_dev_get(dev);
24093                         if (!idev)
24094                                 goto cont;
24095 diff -NurpP --minimal linux-4.4.161/net/ipv6/af_inet6.c linux-4.4.161-vs2.3.9.8/net/ipv6/af_inet6.c
24096 --- linux-4.4.161/net/ipv6/af_inet6.c   2018-10-20 02:34:31.000000000 +0000
24097 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/af_inet6.c 2018-10-20 04:57:21.000000000 +0000
24098 @@ -43,6 +43,8 @@
24099  #include <linux/netdevice.h>
24100  #include <linux/icmpv6.h>
24101  #include <linux/netfilter_ipv6.h>
24102 +#include <linux/vs_inet.h>
24103 +#include <linux/vs_inet6.h>
24104  
24105  #include <net/ip.h>
24106  #include <net/ipv6.h>
24107 @@ -158,10 +160,13 @@ lookup_protocol:
24108         }
24109  
24110         err = -EPERM;
24111 +       if ((protocol == IPPROTO_ICMPV6) &&
24112 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24113 +               goto override;
24114         if (sock->type == SOCK_RAW && !kern &&
24115             !ns_capable(net->user_ns, CAP_NET_RAW))
24116                 goto out_rcu_unlock;
24117 -
24118 +override:
24119         sock->ops = answer->ops;
24120         answer_prot = answer->prot;
24121         answer_flags = answer->flags;
24122 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
24123         struct inet_sock *inet = inet_sk(sk);
24124         struct ipv6_pinfo *np = inet6_sk(sk);
24125         struct net *net = sock_net(sk);
24126 +       struct nx_v6_sock_addr nsa;
24127         __be32 v4addr = 0;
24128         unsigned short snum;
24129         int addr_type = 0;
24130 @@ -274,6 +280,10 @@ int inet6_bind(struct socket *sock, stru
24131         if (addr->sin6_family != AF_INET6)
24132                 return -EAFNOSUPPORT;
24133  
24134 +       err = v6_map_sock_addr(inet, addr, &nsa);
24135 +       if (err)
24136 +               return err;
24137 +
24138         addr_type = ipv6_addr_type(&addr->sin6_addr);
24139         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
24140                 return -EINVAL;
24141 @@ -314,6 +324,10 @@ int inet6_bind(struct socket *sock, stru
24142                         err = -EADDRNOTAVAIL;
24143                         goto out;
24144                 }
24145 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
24146 +                       err = -EADDRNOTAVAIL;
24147 +                       goto out;
24148 +               }
24149         } else {
24150                 if (addr_type != IPV6_ADDR_ANY) {
24151                         struct net_device *dev = NULL;
24152 @@ -340,6 +354,11 @@ int inet6_bind(struct socket *sock, stru
24153                                 }
24154                         }
24155  
24156 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24157 +                               err = -EADDRNOTAVAIL;
24158 +                               goto out_unlock;
24159 +                       }
24160 +
24161                         /* ipv4 addr of the socket is invalid.  Only the
24162                          * unspecified and mapped address have a v4 equivalent.
24163                          */
24164 @@ -357,6 +376,9 @@ int inet6_bind(struct socket *sock, stru
24165                 }
24166         }
24167  
24168 +       /* what's that for? */
24169 +       v6_set_sock_addr(inet, &nsa);
24170 +
24171         inet->inet_rcv_saddr = v4addr;
24172         inet->inet_saddr = v4addr;
24173  
24174 @@ -461,9 +483,11 @@ int inet6_getname(struct socket *sock, s
24175                         return -ENOTCONN;
24176                 sin->sin6_port = inet->inet_dport;
24177                 sin->sin6_addr = sk->sk_v6_daddr;
24178 +               /* FIXME: remap lback? */
24179                 if (np->sndflow)
24180                         sin->sin6_flowinfo = np->flow_label;
24181         } else {
24182 +               /* FIXME: remap lback? */
24183                 if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
24184                         sin->sin6_addr = np->saddr;
24185                 else
24186 diff -NurpP --minimal linux-4.4.161/net/ipv6/datagram.c linux-4.4.161-vs2.3.9.8/net/ipv6/datagram.c
24187 --- linux-4.4.161/net/ipv6/datagram.c   2018-10-20 02:34:31.000000000 +0000
24188 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/datagram.c 2018-10-20 05:50:20.000000000 +0000
24189 @@ -736,7 +736,7 @@ int ip6_datagram_send_ctl(struct net *ne
24190  
24191                         rcu_read_lock();
24192                         if (fl6->flowi6_oif) {
24193 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
24194 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
24195                                 if (!dev) {
24196                                         rcu_read_unlock();
24197                                         return -ENODEV;
24198 diff -NurpP --minimal linux-4.4.161/net/ipv6/fib6_rules.c linux-4.4.161-vs2.3.9.8/net/ipv6/fib6_rules.c
24199 --- linux-4.4.161/net/ipv6/fib6_rules.c 2018-10-20 02:34:31.000000000 +0000
24200 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/fib6_rules.c       2018-10-20 04:57:21.000000000 +0000
24201 @@ -97,7 +97,7 @@ static int fib6_rule_action(struct fib_r
24202                                                ip6_dst_idev(&rt->dst)->dev,
24203                                                &flp6->daddr,
24204                                                rt6_flags2srcprefs(flags),
24205 -                                              &saddr))
24206 +                                              &saddr, NULL))
24207                                 goto again;
24208                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
24209                                                r->src.plen))
24210 diff -NurpP --minimal linux-4.4.161/net/ipv6/inet6_hashtables.c linux-4.4.161-vs2.3.9.8/net/ipv6/inet6_hashtables.c
24211 --- linux-4.4.161/net/ipv6/inet6_hashtables.c   2016-01-10 23:01:32.000000000 +0000
24212 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/inet6_hashtables.c 2018-10-20 04:57:21.000000000 +0000
24213 @@ -16,6 +16,7 @@
24214  
24215  #include <linux/module.h>
24216  #include <linux/random.h>
24217 +#include <linux/vs_inet6.h>
24218  
24219  #include <net/inet_connection_sock.h>
24220  #include <net/inet_hashtables.h>
24221 @@ -66,7 +67,6 @@ struct sock *__inet6_lookup_established(
24222         unsigned int slot = hash & hashinfo->ehash_mask;
24223         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
24224  
24225 -
24226         rcu_read_lock();
24227  begin:
24228         sk_nulls_for_each_rcu(sk, node, &head->chain) {
24229 @@ -108,6 +108,9 @@ static inline int compute_score(struct s
24230                         if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24231                                 return -1;
24232                         score++;
24233 +               } else {
24234 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24235 +                               return -1;
24236                 }
24237                 if (sk->sk_bound_dev_if) {
24238                         if (sk->sk_bound_dev_if != dif)
24239 diff -NurpP --minimal linux-4.4.161/net/ipv6/ip6_fib.c linux-4.4.161-vs2.3.9.8/net/ipv6/ip6_fib.c
24240 --- linux-4.4.161/net/ipv6/ip6_fib.c    2018-10-20 02:34:31.000000000 +0000
24241 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/ip6_fib.c  2018-10-20 04:57:21.000000000 +0000
24242 @@ -1968,6 +1968,7 @@ static int ipv6_route_seq_show(struct se
24243         struct rt6_info *rt = v;
24244         struct ipv6_route_iter *iter = seq->private;
24245  
24246 +       /* FIXME: check for network context? */
24247         seq_printf(seq, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
24248  
24249  #ifdef CONFIG_IPV6_SUBTREES
24250 diff -NurpP --minimal linux-4.4.161/net/ipv6/ip6_output.c linux-4.4.161-vs2.3.9.8/net/ipv6/ip6_output.c
24251 --- linux-4.4.161/net/ipv6/ip6_output.c 2018-10-20 02:34:31.000000000 +0000
24252 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/ip6_output.c       2018-10-20 05:50:20.000000000 +0000
24253 @@ -943,7 +943,8 @@ static int ip6_dst_lookup_tail(struct ne
24254                 rt = (*dst)->error ? NULL : (struct rt6_info *)*dst;
24255                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
24256                                           sk ? inet6_sk(sk)->srcprefs : 0,
24257 -                                         &fl6->saddr);
24258 +                                         &fl6->saddr,
24259 +                                         sk ? sk->sk_nx_info : NULL);
24260                 if (err)
24261                         goto out_err_release;
24262  
24263 diff -NurpP --minimal linux-4.4.161/net/ipv6/ndisc.c linux-4.4.161-vs2.3.9.8/net/ipv6/ndisc.c
24264 --- linux-4.4.161/net/ipv6/ndisc.c      2018-10-20 02:34:31.000000000 +0000
24265 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/ndisc.c    2018-10-20 04:57:21.000000000 +0000
24266 @@ -501,7 +501,7 @@ void ndisc_send_na(struct net_device *de
24267         } else {
24268                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
24269                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
24270 -                                      &tmpaddr))
24271 +                                      &tmpaddr, NULL))
24272                         return;
24273                 src_addr = &tmpaddr;
24274         }
24275 diff -NurpP --minimal linux-4.4.161/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c linux-4.4.161-vs2.3.9.8/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c
24276 --- linux-4.4.161/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c   2016-01-10 23:01:32.000000000 +0000
24277 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/netfilter/nf_nat_masquerade_ipv6.c 2018-10-20 04:57:21.000000000 +0000
24278 @@ -35,7 +35,7 @@ nf_nat_masquerade_ipv6(struct sk_buff *s
24279                             ctinfo == IP_CT_RELATED_REPLY));
24280  
24281         if (ipv6_dev_get_saddr(nf_ct_net(ct), out,
24282 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
24283 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
24284                 return NF_DROP;
24285  
24286         nfct_nat(ct)->masq_index = out->ifindex;
24287 diff -NurpP --minimal linux-4.4.161/net/ipv6/raw.c linux-4.4.161-vs2.3.9.8/net/ipv6/raw.c
24288 --- linux-4.4.161/net/ipv6/raw.c        2018-10-20 02:34:31.000000000 +0000
24289 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/raw.c      2018-10-20 04:57:21.000000000 +0000
24290 @@ -30,6 +30,7 @@
24291  #include <linux/icmpv6.h>
24292  #include <linux/netfilter.h>
24293  #include <linux/netfilter_ipv6.h>
24294 +#include <linux/vs_inet6.h>
24295  #include <linux/skbuff.h>
24296  #include <linux/compat.h>
24297  #include <linux/uaccess.h>
24298 @@ -291,6 +292,13 @@ static int rawv6_bind(struct sock *sk, s
24299                                 goto out_unlock;
24300                 }
24301  
24302 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24303 +                       err = -EADDRNOTAVAIL;
24304 +                       if (dev)
24305 +                               dev_put(dev);
24306 +                       goto out;
24307 +               }
24308 +
24309                 /* ipv4 addr of the socket is invalid.  Only the
24310                  * unspecified and mapped address have a v4 equivalent.
24311                  */
24312 diff -NurpP --minimal linux-4.4.161/net/ipv6/route.c linux-4.4.161-vs2.3.9.8/net/ipv6/route.c
24313 --- linux-4.4.161/net/ipv6/route.c      2018-10-20 02:34:31.000000000 +0000
24314 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/route.c    2018-10-20 04:57:21.000000000 +0000
24315 @@ -62,6 +62,7 @@
24316  #include <net/lwtunnel.h>
24317  #include <net/ip_tunnels.h>
24318  #include <net/l3mdev.h>
24319 +#include <linux/vs_inet6.h>
24320  
24321  #include <asm/uaccess.h>
24322  
24323 @@ -2549,16 +2550,18 @@ int ip6_route_get_saddr(struct net *net,
24324                         struct rt6_info *rt,
24325                         const struct in6_addr *daddr,
24326                         unsigned int prefs,
24327 -                       struct in6_addr *saddr)
24328 +                       struct in6_addr *saddr,
24329 +                       struct nx_info *nxi)
24330  {
24331         struct inet6_dev *idev =
24332                 rt ? ip6_dst_idev((struct dst_entry *)rt) : NULL;
24333         int err = 0;
24334 -       if (rt && rt->rt6i_prefsrc.plen)
24335 +       if (rt && rt->rt6i_prefsrc.plen && (!nxi ||
24336 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
24337                 *saddr = rt->rt6i_prefsrc.addr;
24338         else
24339                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
24340 -                                        daddr, prefs, saddr);
24341 +                                        daddr, prefs, saddr, nxi);
24342         return err;
24343  }
24344  
24345 @@ -3174,7 +3177,8 @@ static int rt6_fill_node(struct net *net
24346                                 goto nla_put_failure;
24347         } else if (dst) {
24348                 struct in6_addr saddr_buf;
24349 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
24350 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
24351 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
24352                     nla_put_in6_addr(skb, RTA_PREFSRC, &saddr_buf))
24353                         goto nla_put_failure;
24354         }
24355 diff -NurpP --minimal linux-4.4.161/net/ipv6/tcp_ipv6.c linux-4.4.161-vs2.3.9.8/net/ipv6/tcp_ipv6.c
24356 --- linux-4.4.161/net/ipv6/tcp_ipv6.c   2018-10-20 02:34:31.000000000 +0000
24357 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/tcp_ipv6.c 2018-10-20 05:50:20.000000000 +0000
24358 @@ -69,6 +69,7 @@
24359  
24360  #include <linux/crypto.h>
24361  #include <linux/scatterlist.h>
24362 +#include <linux/vs_inet6.h>
24363  
24364  static void    tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb);
24365  static void    tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,
24366 @@ -150,11 +151,18 @@ static int tcp_v6_connect(struct sock *s
24367          */
24368  
24369         if (ipv6_addr_any(&usin->sin6_addr)) {
24370 -               if (ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
24371 -                       ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK),
24372 -                                              &usin->sin6_addr);
24373 -               else
24374 -                       usin->sin6_addr = in6addr_loopback;
24375 +               struct nx_info *nxi =  sk->sk_nx_info;
24376 +
24377 +               if (nxi && nx_info_has_v6(nxi))
24378 +                       /* FIXME: remap lback? */
24379 +                       usin->sin6_addr = nxi->v6.ip;
24380 +               else {
24381 +                       if (ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
24382 +                               ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK),
24383 +                                                      &usin->sin6_addr);
24384 +                       else
24385 +                               usin->sin6_addr = in6addr_loopback;
24386 +               }
24387         }
24388  
24389         addr_type = ipv6_addr_type(&usin->sin6_addr);
24390 diff -NurpP --minimal linux-4.4.161/net/ipv6/udp.c linux-4.4.161-vs2.3.9.8/net/ipv6/udp.c
24391 --- linux-4.4.161/net/ipv6/udp.c        2018-10-20 02:34:31.000000000 +0000
24392 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/udp.c      2018-10-20 04:57:21.000000000 +0000
24393 @@ -47,6 +47,7 @@
24394  #include <net/xfrm.h>
24395  #include <net/inet6_hashtables.h>
24396  #include <net/busy_poll.h>
24397 +#include <linux/vs_inet6.h>
24398  
24399  #include <linux/proc_fs.h>
24400  #include <linux/seq_file.h>
24401 @@ -76,32 +77,60 @@ static u32 udp6_ehashfn(const struct net
24402                                udp_ipv6_hash_secret + net_hash_mix(net));
24403  }
24404  
24405 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
24406 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24407  {
24408 +       const struct in6_addr *sk1_rcv_saddr6 = inet6_rcv_saddr(sk1);
24409         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
24410 +       __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr;
24411 +       __be32 sk2_rcv_saddr = sk2->sk_rcv_saddr;
24412         int sk2_ipv6only = inet_v6_ipv6only(sk2);
24413 -       int addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
24414 +       int addr_type1 = ipv6_addr_type(sk1_rcv_saddr6);
24415         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
24416  
24417         /* if both are mapped, treat as IPv4 */
24418 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
24419 -               return (!sk2_ipv6only &&
24420 -                       (!sk->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24421 -                         sk->sk_rcv_saddr == sk2->sk_rcv_saddr));
24422 +       if (addr_type1 == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
24423 +               if (!sk2_ipv6only &&
24424 +                       (!sk1->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24425 +                         sk1->sk_rcv_saddr == sk2->sk_rcv_saddr))
24426 +                       goto vs_v4;
24427 +               else
24428 +                       return 0;
24429 +       }
24430  
24431         if (addr_type2 == IPV6_ADDR_ANY &&
24432 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
24433 -               return 1;
24434 +           !(sk2_ipv6only && addr_type1 == IPV6_ADDR_MAPPED))
24435 +               goto vs;
24436  
24437 -       if (addr_type == IPV6_ADDR_ANY &&
24438 -           !(ipv6_only_sock(sk) && addr_type2 == IPV6_ADDR_MAPPED))
24439 -               return 1;
24440 +       if (addr_type1 == IPV6_ADDR_ANY &&
24441 +           !(ipv6_only_sock(sk1) && addr_type2 == IPV6_ADDR_MAPPED))
24442 +               goto vs;
24443  
24444         if (sk2_rcv_saddr6 &&
24445 -           ipv6_addr_equal(&sk->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24446 -               return 1;
24447 +           ipv6_addr_equal(&sk1->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24448 +               goto vs;
24449  
24450         return 0;
24451 +
24452 +vs_v4:
24453 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
24454 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24455 +       if (!sk2_rcv_saddr)
24456 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
24457 +       if (!sk1_rcv_saddr)
24458 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
24459 +       return 1;
24460 +vs:
24461 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type1 == IPV6_ADDR_ANY)
24462 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24463 +       else if (addr_type2 == IPV6_ADDR_ANY)
24464 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
24465 +       else if (addr_type1 == IPV6_ADDR_ANY) {
24466 +               if (addr_type2 == IPV6_ADDR_MAPPED)
24467 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24468 +               else
24469 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
24470 +       }
24471 +       return 1;
24472  }
24473  
24474  static u32 udp6_portaddr_hash(const struct net *net,
24475 @@ -162,6 +191,10 @@ static inline int compute_score(struct s
24476                 if (inet->inet_dport != sport)
24477                         return -1;
24478                 score++;
24479 +               } else {
24480 +                       /* block non nx_info ips */
24481 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24482 +                               return -1;
24483         }
24484  
24485         if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
24486 diff -NurpP --minimal linux-4.4.161/net/ipv6/xfrm6_policy.c linux-4.4.161-vs2.3.9.8/net/ipv6/xfrm6_policy.c
24487 --- linux-4.4.161/net/ipv6/xfrm6_policy.c       2018-10-20 02:34:31.000000000 +0000
24488 +++ linux-4.4.161-vs2.3.9.8/net/ipv6/xfrm6_policy.c     2018-10-20 04:57:21.000000000 +0000
24489 @@ -64,7 +64,8 @@ static int xfrm6_get_saddr(struct net *n
24490                 return -EHOSTUNREACH;
24491  
24492         dev = ip6_dst_idev(dst)->dev;
24493 -       ipv6_dev_get_saddr(dev_net(dev), dev, &daddr->in6, 0, &saddr->in6);
24494 +       ipv6_dev_get_saddr(dev_net(dev), dev, &daddr->in6,
24495 +               0, &saddr->in6, NULL);
24496         dst_release(dst);
24497         return 0;
24498  }
24499 diff -NurpP --minimal linux-4.4.161/net/netfilter/ipvs/ip_vs_xmit.c linux-4.4.161-vs2.3.9.8/net/netfilter/ipvs/ip_vs_xmit.c
24500 --- linux-4.4.161/net/netfilter/ipvs/ip_vs_xmit.c       2016-01-10 23:01:32.000000000 +0000
24501 +++ linux-4.4.161-vs2.3.9.8/net/netfilter/ipvs/ip_vs_xmit.c     2018-10-20 04:57:21.000000000 +0000
24502 @@ -381,7 +381,7 @@ __ip_vs_route_output_v6(struct net *net,
24503                 return dst;
24504         if (ipv6_addr_any(&fl6.saddr) &&
24505             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
24506 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
24507 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
24508                 goto out_err;
24509         if (do_xfrm) {
24510                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
24511 diff -NurpP --minimal linux-4.4.161/net/netlink/af_netlink.c linux-4.4.161-vs2.3.9.8/net/netlink/af_netlink.c
24512 --- linux-4.4.161/net/netlink/af_netlink.c      2018-10-20 02:34:31.000000000 +0000
24513 +++ linux-4.4.161-vs2.3.9.8/net/netlink/af_netlink.c    2018-10-20 05:53:02.000000000 +0000
24514 @@ -63,6 +63,8 @@
24515  #include <linux/hash.h>
24516  #include <linux/genetlink.h>
24517  #include <linux/nospec.h>
24518 +#include <linux/vs_context.h>
24519 +#include <linux/vs_network.h>
24520  
24521  #include <net/net_namespace.h>
24522  #include <net/sock.h>
24523 @@ -2472,7 +2474,8 @@ static void *__netlink_seq_next(struct s
24524                         if (err)
24525                                 return ERR_PTR(err);
24526                 }
24527 -       } while (sock_net(&nlk->sk) != seq_file_net(seq));
24528 +       } while ((sock_net(&nlk->sk) != seq_file_net(seq)) ||
24529 +               !nx_check(nlk->sk.sk_nid, VS_WATCH_P | VS_IDENT));
24530  
24531         return nlk;
24532  }
24533 diff -NurpP --minimal linux-4.4.161/net/packet/diag.c linux-4.4.161-vs2.3.9.8/net/packet/diag.c
24534 --- linux-4.4.161/net/packet/diag.c     2016-01-10 23:01:32.000000000 +0000
24535 +++ linux-4.4.161-vs2.3.9.8/net/packet/diag.c   2018-10-20 04:57:21.000000000 +0000
24536 @@ -4,6 +4,7 @@
24537  #include <linux/netdevice.h>
24538  #include <linux/packet_diag.h>
24539  #include <linux/percpu.h>
24540 +#include <linux/vs_network.h>
24541  #include <net/net_namespace.h>
24542  #include <net/sock.h>
24543  
24544 @@ -201,6 +202,8 @@ static int packet_diag_dump(struct sk_bu
24545         sk_for_each(sk, &net->packet.sklist) {
24546                 if (!net_eq(sock_net(sk), net))
24547                         continue;
24548 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24549 +                       continue;
24550                 if (num < s_num)
24551                         goto next;
24552  
24553 diff -NurpP --minimal linux-4.4.161/net/socket.c linux-4.4.161-vs2.3.9.8/net/socket.c
24554 --- linux-4.4.161/net/socket.c  2018-10-20 02:34:31.000000000 +0000
24555 +++ linux-4.4.161-vs2.3.9.8/net/socket.c        2018-10-20 05:50:20.000000000 +0000
24556 @@ -100,10 +100,12 @@
24557  
24558  #include <net/sock.h>
24559  #include <linux/netfilter.h>
24560 +#include <linux/vs_socket.h>
24561 +#include <linux/vs_inet.h>
24562 +#include <linux/vs_inet6.h>
24563  
24564  #include <linux/if_tun.h>
24565  #include <linux/ipv6_route.h>
24566 -#include <linux/route.h>
24567  #include <linux/sockios.h>
24568  #include <linux/atalk.h>
24569  #include <net/busy_poll.h>
24570 @@ -609,8 +611,24 @@ EXPORT_SYMBOL(__sock_tx_timestamp);
24571  
24572  static inline int sock_sendmsg_nosec(struct socket *sock, struct msghdr *msg)
24573  {
24574 -       int ret = sock->ops->sendmsg(sock, msg, msg_data_left(msg));
24575 -       BUG_ON(ret == -EIOCBQUEUED);
24576 +       size_t size = msg_data_left(msg);
24577 +       int ret = sock->ops->sendmsg(sock, msg, size);
24578 +#if 0
24579 +       if (sock->sk) {
24580 +               if (!ret)
24581 +                       vx_sock_fail(sock->sk, size);
24582 +               else
24583 +                       vx_sock_send(sock->sk, size);
24584 +       }
24585 +#endif
24586 +       vxdprintk(VXD_CBIT(net, 7),
24587 +               "sock_sendmsg_nosec: %p[%p,%p,%p;%d/%d]:%zu/%zu",
24588 +               sock, sock->sk,
24589 +               (sock->sk)?sock->sk->sk_nx_info:0,
24590 +               (sock->sk)?sock->sk->sk_vx_info:0,
24591 +               (sock->sk)?sock->sk->sk_xid:0,
24592 +               (sock->sk)?sock->sk->sk_nid:0,
24593 +               size, msg_data_left(msg));
24594         return ret;
24595  }
24596  
24597 @@ -1101,6 +1119,13 @@ int __sock_create(struct net *net, int f
24598         if (type < 0 || type >= SOCK_MAX)
24599                 return -EINVAL;
24600  
24601 +       if (!nx_check(0, VS_ADMIN)) {
24602 +               if (family == PF_INET && !current_nx_info_has_v4())
24603 +                       return -EAFNOSUPPORT;
24604 +               if (family == PF_INET6 && !current_nx_info_has_v6())
24605 +                       return -EAFNOSUPPORT;
24606 +       }
24607 +
24608         /* Compatibility.
24609  
24610            This uglymoron is moved from INET layer to here to avoid
24611 @@ -1235,6 +1260,7 @@ SYSCALL_DEFINE3(socket, int, family, int
24612         if (retval < 0)
24613                 goto out;
24614  
24615 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
24616         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
24617         if (retval < 0)
24618                 goto out_release;
24619 @@ -1276,10 +1302,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
24620         err = sock_create(family, type, protocol, &sock1);
24621         if (err < 0)
24622                 goto out;
24623 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
24624  
24625         err = sock_create(family, type, protocol, &sock2);
24626         if (err < 0)
24627                 goto out_release_1;
24628 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
24629  
24630         err = sock1->ops->socketpair(sock1, sock2);
24631         if (err < 0)
24632 diff -NurpP --minimal linux-4.4.161/net/sunrpc/auth.c linux-4.4.161-vs2.3.9.8/net/sunrpc/auth.c
24633 --- linux-4.4.161/net/sunrpc/auth.c     2016-01-10 23:01:32.000000000 +0000
24634 +++ linux-4.4.161-vs2.3.9.8/net/sunrpc/auth.c   2018-10-20 04:57:21.000000000 +0000
24635 @@ -15,6 +15,7 @@
24636  #include <linux/sunrpc/clnt.h>
24637  #include <linux/sunrpc/gss_api.h>
24638  #include <linux/spinlock.h>
24639 +#include <linux/vs_tag.h>
24640  
24641  #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
24642  # define RPCDBG_FACILITY       RPCDBG_AUTH
24643 @@ -630,6 +631,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
24644         memset(&acred, 0, sizeof(acred));
24645         acred.uid = cred->fsuid;
24646         acred.gid = cred->fsgid;
24647 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
24648         acred.group_info = cred->group_info;
24649         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
24650         return ret;
24651 @@ -669,6 +671,7 @@ rpcauth_bind_root_cred(struct rpc_task *
24652         struct auth_cred acred = {
24653                 .uid = GLOBAL_ROOT_UID,
24654                 .gid = GLOBAL_ROOT_GID,
24655 +               .tag = KTAGT_INIT(dx_current_tag()),
24656         };
24657  
24658         dprintk("RPC: %5u looking up %s cred\n",
24659 diff -NurpP --minimal linux-4.4.161/net/sunrpc/auth_unix.c linux-4.4.161-vs2.3.9.8/net/sunrpc/auth_unix.c
24660 --- linux-4.4.161/net/sunrpc/auth_unix.c        2016-01-10 23:01:32.000000000 +0000
24661 +++ linux-4.4.161-vs2.3.9.8/net/sunrpc/auth_unix.c      2018-10-20 04:57:21.000000000 +0000
24662 @@ -13,11 +13,13 @@
24663  #include <linux/sunrpc/clnt.h>
24664  #include <linux/sunrpc/auth.h>
24665  #include <linux/user_namespace.h>
24666 +#include <linux/vs_tag.h>
24667  
24668  #define NFS_NGROUPS    16
24669  
24670  struct unx_cred {
24671         struct rpc_cred         uc_base;
24672 +       ktag_t                  uc_tag;
24673         kgid_t                  uc_gid;
24674         kgid_t                  uc_gids[NFS_NGROUPS];
24675  };
24676 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
24677                 groups = NFS_NGROUPS;
24678  
24679         cred->uc_gid = acred->gid;
24680 +       cred->uc_tag = acred->tag;
24681         for (i = 0; i < groups; i++)
24682                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
24683         if (i < NFS_NGROUPS)
24684 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
24685         unsigned int i;
24686  
24687  
24688 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
24689 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
24690 +           !gid_eq(cred->uc_gid, acred->gid) ||
24691 +           !tag_eq(cred->uc_tag, acred->tag))
24692                 return 0;
24693  
24694         if (acred->group_info != NULL)
24695 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
24696         struct rpc_clnt *clnt = task->tk_client;
24697         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
24698         __be32          *base, *hold;
24699 -       int             i;
24700 +       int             i, tag;
24701  
24702         *p++ = htonl(RPC_AUTH_UNIX);
24703         base = p++;
24704 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
24705          */
24706         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
24707  
24708 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
24709 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
24710 +       tag = task->tk_client->cl_tag;
24711 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
24712 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
24713 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
24714 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
24715         hold = p++;
24716         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
24717                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
24718 diff -NurpP --minimal linux-4.4.161/net/sunrpc/clnt.c linux-4.4.161-vs2.3.9.8/net/sunrpc/clnt.c
24719 --- linux-4.4.161/net/sunrpc/clnt.c     2018-10-20 02:34:31.000000000 +0000
24720 +++ linux-4.4.161-vs2.3.9.8/net/sunrpc/clnt.c   2018-10-20 04:57:21.000000000 +0000
24721 @@ -31,6 +31,7 @@
24722  #include <linux/in.h>
24723  #include <linux/in6.h>
24724  #include <linux/un.h>
24725 +#include <linux/vs_cvirt.h>
24726  
24727  #include <linux/sunrpc/clnt.h>
24728  #include <linux/sunrpc/addr.h>
24729 @@ -477,6 +478,9 @@ static struct rpc_clnt *rpc_create_xprt(
24730         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
24731                 clnt->cl_chatty = 1;
24732  
24733 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
24734 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
24735 +               clnt->cl_tag = 1; */
24736         return clnt;
24737  }
24738  
24739 diff -NurpP --minimal linux-4.4.161/net/unix/af_unix.c linux-4.4.161-vs2.3.9.8/net/unix/af_unix.c
24740 --- linux-4.4.161/net/unix/af_unix.c    2018-10-20 02:34:31.000000000 +0000
24741 +++ linux-4.4.161-vs2.3.9.8/net/unix/af_unix.c  2018-10-20 04:57:21.000000000 +0000
24742 @@ -117,6 +117,8 @@
24743  #include <net/checksum.h>
24744  #include <linux/security.h>
24745  #include <linux/freezer.h>
24746 +#include <linux/vs_context.h>
24747 +#include <linux/vs_limit.h>
24748  
24749  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
24750  EXPORT_SYMBOL_GPL(unix_socket_table);
24751 @@ -282,6 +284,8 @@ static struct sock *__unix_find_socket_b
24752                 if (!net_eq(sock_net(s), net))
24753                         continue;
24754  
24755 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
24756 +                       continue;
24757                 if (u->addr->len == len &&
24758                     !memcmp(u->addr->name, sunname, len))
24759                         goto found;
24760 @@ -2741,6 +2745,8 @@ static struct sock *unix_from_bucket(str
24761         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
24762                 if (sock_net(sk) != seq_file_net(seq))
24763                         continue;
24764 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24765 +                       continue;
24766                 if (++count == offset)
24767                         break;
24768         }
24769 @@ -2758,6 +2764,8 @@ static struct sock *unix_next_socket(str
24770                 sk = sk_next(sk);
24771                 if (!sk)
24772                         goto next_bucket;
24773 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24774 +                       continue;
24775                 if (sock_net(sk) == seq_file_net(seq))
24776                         return sk;
24777         }
24778 diff -NurpP --minimal linux-4.4.161/net/unix/diag.c linux-4.4.161-vs2.3.9.8/net/unix/diag.c
24779 --- linux-4.4.161/net/unix/diag.c       2018-10-20 02:34:31.000000000 +0000
24780 +++ linux-4.4.161-vs2.3.9.8/net/unix/diag.c     2018-10-20 04:57:21.000000000 +0000
24781 @@ -4,6 +4,7 @@
24782  #include <linux/unix_diag.h>
24783  #include <linux/skbuff.h>
24784  #include <linux/module.h>
24785 +#include <linux/vs_network.h>
24786  #include <net/netlink.h>
24787  #include <net/af_unix.h>
24788  #include <net/tcp_states.h>
24789 @@ -199,6 +200,8 @@ static int unix_diag_dump(struct sk_buff
24790                 sk_for_each(sk, &unix_socket_table[slot]) {
24791                         if (!net_eq(sock_net(sk), net))
24792                                 continue;
24793 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24794 +                               continue;
24795                         if (num < s_num)
24796                                 goto next;
24797                         if (!(req->udiag_states & (1 << sk->sk_state)))
24798 diff -NurpP --minimal linux-4.4.161/scripts/checksyscalls.sh linux-4.4.161-vs2.3.9.8/scripts/checksyscalls.sh
24799 --- linux-4.4.161/scripts/checksyscalls.sh      2016-01-10 23:01:32.000000000 +0000
24800 +++ linux-4.4.161-vs2.3.9.8/scripts/checksyscalls.sh    2018-10-20 04:57:21.000000000 +0000
24801 @@ -196,7 +196,6 @@ cat << EOF
24802  #define __IGNORE_afs_syscall
24803  #define __IGNORE_getpmsg
24804  #define __IGNORE_putpmsg
24805 -#define __IGNORE_vserver
24806  EOF
24807  }
24808  
24809 diff -NurpP --minimal linux-4.4.161/security/commoncap.c linux-4.4.161-vs2.3.9.8/security/commoncap.c
24810 --- linux-4.4.161/security/commoncap.c  2018-10-20 02:34:31.000000000 +0000
24811 +++ linux-4.4.161-vs2.3.9.8/security/commoncap.c        2018-10-20 04:57:21.000000000 +0000
24812 @@ -71,6 +71,7 @@ static void warn_setuid_and_fcaps_mixed(
24813  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
24814                 int cap, int audit)
24815  {
24816 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
24817         struct user_namespace *ns = targ_ns;
24818  
24819         /* See if cred has the capability in the target user namespace
24820 @@ -79,8 +80,12 @@ int cap_capable(const struct cred *cred,
24821          */
24822         for (;;) {
24823                 /* Do we have the necessary capabilities? */
24824 -               if (ns == cred->user_ns)
24825 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
24826 +               if (ns == cred->user_ns) {
24827 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
24828 +                           cap_raised(cred->cap_effective, cap))
24829 +                               return 0;
24830 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
24831 +               }
24832  
24833                 /* Have we tried all of the parent namespaces? */
24834                 if (ns == &init_user_ns)
24835 @@ -664,7 +669,7 @@ int cap_inode_setxattr(struct dentry *de
24836  
24837         if (!strncmp(name, XATTR_SECURITY_PREFIX,
24838                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
24839 -           !capable(CAP_SYS_ADMIN))
24840 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
24841                 return -EPERM;
24842         return 0;
24843  }
24844 @@ -690,7 +695,7 @@ int cap_inode_removexattr(struct dentry
24845  
24846         if (!strncmp(name, XATTR_SECURITY_PREFIX,
24847                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
24848 -           !capable(CAP_SYS_ADMIN))
24849 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
24850                 return -EPERM;
24851         return 0;
24852  }
24853 diff -NurpP --minimal linux-4.4.161/security/selinux/hooks.c linux-4.4.161-vs2.3.9.8/security/selinux/hooks.c
24854 --- linux-4.4.161/security/selinux/hooks.c      2018-10-20 02:34:31.000000000 +0000
24855 +++ linux-4.4.161-vs2.3.9.8/security/selinux/hooks.c    2018-10-20 04:57:21.000000000 +0000
24856 @@ -67,7 +67,6 @@
24857  #include <linux/dccp.h>
24858  #include <linux/quota.h>
24859  #include <linux/un.h>          /* for Unix socket types */
24860 -#include <net/af_unix.h>       /* for Unix socket types */
24861  #include <linux/parser.h>
24862  #include <linux/nfs_mount.h>
24863  #include <net/ipv6.h>
This page took 2.054608 seconds and 4 git commands to generate.