Advertisement
Guest User

Sequre Linux 4.2 Patch

a guest
Feb 8th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 121.93 KB | None | 0 0
  1. diff -aur linux-4.2/arch/x86/ia32/sys_ia32.c linux-4.2.tsarn1/arch/x86/ia32/sys_ia32.c
  2. --- linux-4.2/arch/x86/ia32/sys_ia32.c  2015-08-30 21:34:09.000000000 +0300
  3. +++ linux-4.2.tsarn1/arch/x86/ia32/sys_ia32.c   2016-02-08 16:51:12.597891701 +0300
  4. @@ -95,12 +95,26 @@
  5.     return 0;
  6.  }
  7.  
  8. +int cher_patch_is_secure_path(const char *);
  9. +
  10.  asmlinkage long sys32_stat64(const char __user *filename,
  11.                  struct stat64 __user *statbuf)
  12.  {
  13.     struct kstat stat;
  14. -   int ret = vfs_stat(filename, &stat);
  15. +   int ret = 0;
  16. +
  17. +        if (SBOX_IS_RESTRICTED()) {
  18. +                struct filename *tmp = getname(filename);
  19. +                if (IS_ERR(tmp)) return -EINVAL;
  20. +                if (cher_patch_is_secure_path(tmp->name) < 0) {
  21. +                        putname(tmp);
  22. +                        return -EPERM;
  23. +                }
  24. +                if (!strncmp(tmp->name, "/SANDBOX/", 9)) filename += 9;
  25. +                putname(tmp);
  26. +        }
  27.  
  28. +        ret = vfs_stat(filename, &stat);
  29.     if (!ret)
  30.         ret = cp_stat64(statbuf, &stat);
  31.     return ret;
  32. @@ -110,7 +124,20 @@
  33.                   struct stat64 __user *statbuf)
  34.  {
  35.     struct kstat stat;
  36. -   int ret = vfs_lstat(filename, &stat);
  37. +   int ret = 0;
  38. +
  39. +        if (SBOX_IS_RESTRICTED()) {
  40. +                struct filename *tmp = getname(filename);
  41. +                if (IS_ERR(tmp)) return -EINVAL;
  42. +                if (cher_patch_is_secure_path(tmp->name) < 0) {
  43. +                        putname(tmp);
  44. +                        return -EPERM;
  45. +                }
  46. +                if (!strncmp(tmp->name, "/SANDBOX/", 9)) filename += 9;
  47. +                putname(tmp);
  48. +        }
  49. +
  50. +   ret = vfs_lstat(filename, &stat);
  51.     if (!ret)
  52.         ret = cp_stat64(statbuf, &stat);
  53.     return ret;
  54. @@ -131,6 +158,10 @@
  55.     struct kstat stat;
  56.     int error;
  57.  
  58. +        if (SBOX_IS_RESTRICTED()) {
  59. +                return -EPERM;
  60. +        }
  61. +
  62.     error = vfs_fstatat(dfd, filename, &stat, flag);
  63.     if (error)
  64.         return error;
  65. diff -aur linux-4.2/arch/x86/kernel/ioport.c linux-4.2.tsarn1/arch/x86/kernel/ioport.c
  66. --- linux-4.2/arch/x86/kernel/ioport.c  2015-08-30 21:34:09.000000000 +0300
  67. +++ linux-4.2.tsarn1/arch/x86/kernel/ioport.c   2016-02-08 16:51:12.597891701 +0300
  68. @@ -26,6 +26,11 @@
  69.     struct tss_struct *tss;
  70.     unsigned int i, max_long, bytes, bytes_updated;
  71.  
  72. +        if (SBOX_IS_RESTRICTED()) {
  73. +                //SBOX_SET_SECURITY_ERR();
  74. +                return -EPERM;
  75. +        }
  76. +
  77.     if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
  78.         return -EINVAL;
  79.     if (turn_on && !capable(CAP_SYS_RAWIO))
  80. @@ -99,6 +104,11 @@
  81.     unsigned int old = (regs->flags >> 12) & 3;
  82.     struct thread_struct *t = &current->thread;
  83.  
  84. +        if (SBOX_IS_RESTRICTED()) {
  85. +                //SBOX_SET_SECURITY_ERR();
  86. +                return -EPERM;
  87. +        }
  88. +
  89.     if (level > 3)
  90.         return -EINVAL;
  91.     /* Trying to gain more privileges? */
  92. diff -aur linux-4.2/arch/x86/kernel/ldt.c linux-4.2.tsarn1/arch/x86/kernel/ldt.c
  93. --- linux-4.2/arch/x86/kernel/ldt.c 2015-08-30 21:34:09.000000000 +0300
  94. +++ linux-4.2.tsarn1/arch/x86/kernel/ldt.c  2016-02-08 16:51:12.597891701 +0300
  95. @@ -276,6 +276,11 @@
  96.  {
  97.     int ret = -ENOSYS;
  98.  
  99. +        if (SBOX_IS_RESTRICTED()) {
  100. +                SBOX_SET_SECURITY_ERR();
  101. +                return -EPERM;
  102. +        }
  103. +
  104.     switch (func) {
  105.     case 0:
  106.         ret = read_ldt(ptr, bytecount);
  107. diff -aur linux-4.2/arch/x86/kernel/vm86_32.c linux-4.2.tsarn1/arch/x86/kernel/vm86_32.c
  108. --- linux-4.2/arch/x86/kernel/vm86_32.c 2015-08-30 21:34:09.000000000 +0300
  109. +++ linux-4.2.tsarn1/arch/x86/kernel/vm86_32.c  2016-02-08 16:51:12.597891701 +0300
  110. @@ -212,6 +212,11 @@
  111.     struct task_struct *tsk = current;
  112.     int tmp;
  113.  
  114. +        if (SBOX_IS_RESTRICTED()) {
  115. +                SBOX_SET_SECURITY_ERR();
  116. +                return -EPERM;
  117. +        }
  118. +
  119.     if (tsk->thread.saved_sp0)
  120.         return -EPERM;
  121.     tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
  122. @@ -238,6 +243,11 @@
  123.     int tmp;
  124.     struct vm86plus_struct __user *v86;
  125.  
  126. +        if (SBOX_IS_RESTRICTED()) {
  127. +                SBOX_SET_SECURITY_ERR();
  128. +                return -EPERM;
  129. +        }
  130. +
  131.     tsk = current;
  132.     switch (cmd) {
  133.     case VM86_REQUEST_IRQ:
  134. diff -aur linux-4.2/fs/aio.c linux-4.2.tsarn1/fs/aio.c
  135. --- linux-4.2/fs/aio.c  2015-08-30 21:34:09.000000000 +0300
  136. +++ linux-4.2.tsarn1/fs/aio.c   2016-02-08 16:51:12.654559031 +0300
  137. @@ -1310,6 +1310,9 @@
  138.     unsigned long ctx;
  139.     long ret;
  140.  
  141. +        if (SBOX_IS_RESTRICTED())
  142. +                return -EPERM;
  143. +
  144.     ret = get_user(ctx, ctxp);
  145.     if (unlikely(ret))
  146.         goto out;
  147. @@ -1342,9 +1345,16 @@
  148.   */
  149.  SYSCALL_DEFINE1(io_destroy, aio_context_t, ctx)
  150.  {
  151. -   struct kioctx *ioctx = lookup_ioctx(ctx);
  152. +   struct kioctx *ioctx = NULL;
  153. +
  154. +        if (SBOX_IS_RESTRICTED()) {
  155. +                return -EPERM;
  156. +        }
  157. +
  158. +   ioctx = lookup_ioctx(ctx);
  159.     if (likely(NULL != ioctx)) {
  160.         struct ctx_rq_wait wait;
  161. +
  162.         int ret;
  163.  
  164.         init_completion(&wait.comp);
  165. @@ -1628,6 +1638,9 @@
  166.  SYSCALL_DEFINE3(io_submit, aio_context_t, ctx_id, long, nr,
  167.         struct iocb __user * __user *, iocbpp)
  168.  {
  169. +        if (SBOX_IS_RESTRICTED())
  170. +                return -EPERM;
  171. +
  172.     return do_io_submit(ctx_id, nr, iocbpp, 0);
  173.  }
  174.  
  175. @@ -1670,6 +1683,9 @@
  176.     u32 key;
  177.     int ret;
  178.  
  179. +        if (SBOX_IS_RESTRICTED())
  180. +                return -EPERM;
  181. +
  182.     ret = get_user(key, &iocb->aio_key);
  183.     if (unlikely(ret))
  184.         return -EFAULT;
  185. @@ -1720,9 +1736,13 @@
  186.         struct io_event __user *, events,
  187.         struct timespec __user *, timeout)
  188.  {
  189. -   struct kioctx *ioctx = lookup_ioctx(ctx_id);
  190. +   struct kioctx *ioctx;
  191.     long ret = -EINVAL;
  192.  
  193. +        if (SBOX_IS_RESTRICTED())
  194. +                return -EPERM;
  195. +
  196. +        ioctx = lookup_ioctx(ctx_id);
  197.     if (likely(ioctx)) {
  198.         if (likely(min_nr <= nr && min_nr >= 0))
  199.             ret = read_events(ioctx, min_nr, nr, events, timeout);
  200. diff -aur linux-4.2/fs/buffer.c linux-4.2.tsarn1/fs/buffer.c
  201. --- linux-4.2/fs/buffer.c   2015-08-30 21:34:09.000000000 +0300
  202. +++ linux-4.2.tsarn1/fs/buffer.c    2016-02-08 16:51:12.657892404 +0300
  203. @@ -3294,6 +3294,9 @@
  204.  {
  205.     static int msg_count;
  206.  
  207. +        if (SBOX_IS_RESTRICTED())
  208. +                return -EPERM;
  209. +
  210.     if (!capable(CAP_SYS_ADMIN))
  211.         return -EPERM;
  212.  
  213. Only in linux-4.2.tsarn1/fs: buffer.c.orig
  214. diff -aur linux-4.2/fs/compat.c linux-4.2.tsarn1/fs/compat.c
  215. --- linux-4.2/fs/compat.c   2015-08-30 21:34:09.000000000 +0300
  216. +++ linux-4.2.tsarn1/fs/compat.c    2016-02-08 16:51:12.657892404 +0300
  217. @@ -77,6 +77,11 @@
  218.  {
  219.     struct timespec tv[2];
  220.  
  221. +        if (SBOX_IS_RESTRICTED()) {
  222. +                SBOX_SET_SECURITY_ERR();
  223. +                return -EPERM;
  224. +        }
  225. +
  226.     if (t) {
  227.         if (get_user(tv[0].tv_sec, &t->actime) ||
  228.             get_user(tv[1].tv_sec, &t->modtime))
  229. @@ -91,6 +96,11 @@
  230.  {
  231.     struct timespec tv[2];
  232.  
  233. +        if (SBOX_IS_RESTRICTED()) {
  234. +                SBOX_SET_SECURITY_ERR();
  235. +                return -EPERM;
  236. +        }
  237. +
  238.     if  (t) {
  239.         if (compat_get_timespec(&tv[0], &t[0]) ||
  240.             compat_get_timespec(&tv[1], &t[1]))
  241. @@ -106,6 +116,11 @@
  242.  {
  243.     struct timespec tv[2];
  244.  
  245. +        if (SBOX_IS_RESTRICTED()) {
  246. +                SBOX_SET_SECURITY_ERR();
  247. +                return -EPERM;
  248. +        }
  249. +
  250.     if (t) {
  251.         if (get_user(tv[0].tv_sec, &t[0].tv_sec) ||
  252.             get_user(tv[0].tv_nsec, &t[0].tv_usec) ||
  253. @@ -159,12 +174,25 @@
  254.     return copy_to_user(ubuf, &tmp, sizeof(tmp)) ? -EFAULT : 0;
  255.  }
  256.  
  257. +int cher_patch_is_secure_path(const char*);
  258. +
  259.  COMPAT_SYSCALL_DEFINE2(newstat, const char __user *, filename,
  260.                struct compat_stat __user *, statbuf)
  261.  {
  262.     struct kstat stat;
  263.     int error;
  264.  
  265. +        if (SBOX_IS_RESTRICTED()) {
  266. +                struct filename *tmp = getname(filename);
  267. +                if (IS_ERR(tmp)) return -EINVAL;
  268. +                if (cher_patch_is_secure_path(tmp->name) < 0) {
  269. +                        putname(tmp);
  270. +                        return -EPERM;
  271. +                }
  272. +                if (!strncmp(tmp->name, "/SANDBOX/", 9)) filename += 9;
  273. +                putname(tmp);
  274. +        }
  275. +
  276.     error = vfs_stat(filename, &stat);
  277.     if (error)
  278.         return error;
  279. @@ -177,6 +205,17 @@
  280.     struct kstat stat;
  281.     int error;
  282.  
  283. +        if (SBOX_IS_RESTRICTED()) {
  284. +                struct filename *tmp = getname(filename);
  285. +                if (IS_ERR(tmp)) return -EINVAL;
  286. +                if (cher_patch_is_secure_path(tmp->name) < 0) {
  287. +                        putname(tmp);
  288. +                        return -EPERM;
  289. +                }
  290. +                if (!strncmp(tmp->name, "/SANDBOX/", 9)) filename += 9;
  291. +                putname(tmp);
  292. +        }
  293. +
  294.     error = vfs_lstat(filename, &stat);
  295.     if (error)
  296.         return error;
  297. @@ -191,6 +230,9 @@
  298.     struct kstat stat;
  299.     int error;
  300.  
  301. +        if (SBOX_IS_RESTRICTED())
  302. +                return -EPERM;
  303. +
  304.     error = vfs_fstatat(dfd, filename, &stat, flag);
  305.     if (error)
  306.         return error;
  307. @@ -250,7 +292,12 @@
  308.  COMPAT_SYSCALL_DEFINE2(statfs, const char __user *, pathname, struct compat_statfs __user *, buf)
  309.  {
  310.     struct kstatfs tmp;
  311. -   int error = user_statfs(pathname, &tmp);
  312. +   int error;
  313. +
  314. +        if (SBOX_IS_RESTRICTED())
  315. +                return -EPERM;
  316. +
  317. +        error = user_statfs(pathname, &tmp);
  318.     if (!error)
  319.         error = put_compat_statfs(buf, &tmp);
  320.     return error;
  321. @@ -259,7 +306,12 @@
  322.  COMPAT_SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct compat_statfs __user *, buf)
  323.  {
  324.     struct kstatfs tmp;
  325. -   int error = fd_statfs(fd, &tmp);
  326. +   int error;
  327. +
  328. +        if (SBOX_IS_RESTRICTED())
  329. +                return -EPERM;
  330. +
  331. +        error = fd_statfs(fd, &tmp);
  332.     if (!error)
  333.         error = put_compat_statfs(buf, &tmp);
  334.     return error;
  335. @@ -303,6 +355,9 @@
  336.     struct kstatfs tmp;
  337.     int error;
  338.  
  339. +        if (SBOX_IS_RESTRICTED())
  340. +                return -EPERM;
  341. +
  342.     if (sz != sizeof(*buf))
  343.         return -EINVAL;
  344.  
  345. @@ -317,6 +372,9 @@
  346.     struct kstatfs tmp;
  347.     int error;
  348.  
  349. +        if (SBOX_IS_RESTRICTED())
  350. +                return -EPERM;
  351. +
  352.     if (sz != sizeof(*buf))
  353.         return -EINVAL;
  354.  
  355. @@ -335,7 +393,12 @@
  356.  {
  357.     struct compat_ustat tmp;
  358.     struct kstatfs sbuf;
  359. -   int err = vfs_ustat(new_decode_dev(dev), &sbuf);
  360. +   int err;
  361. +
  362. +        if (SBOX_IS_RESTRICTED())
  363. +                return -EPERM;
  364. +
  365. +        err = vfs_ustat(new_decode_dev(dev), &sbuf);
  366.     if (err)
  367.         return err;
  368.  
  369. @@ -422,6 +485,9 @@
  370.     long ret;
  371.     unsigned int conv_cmd;
  372.  
  373. +        if (SBOX_IS_RESTRICTED())
  374. +                return -EPERM;
  375. +
  376.     switch (cmd) {
  377.     case F_GETLK:
  378.     case F_SETLK:
  379. @@ -506,6 +572,9 @@
  380.     long ret;
  381.     aio_context_t ctx64;
  382.  
  383. +        if (SBOX_IS_RESTRICTED())
  384. +                return -EPERM;
  385. +
  386.     mm_segment_t oldfs = get_fs();
  387.     if (unlikely(get_user(ctx64, ctx32p)))
  388.         return -EFAULT;
  389. @@ -529,6 +598,9 @@
  390.     struct timespec t;
  391.     struct timespec __user *ut = NULL;
  392.  
  393. +        if (SBOX_IS_RESTRICTED())
  394. +                return -EPERM;
  395. +
  396.     if (timeout) {
  397.         if (compat_get_timespec(&t, timeout))
  398.             return -EFAULT;
  399. @@ -639,6 +711,9 @@
  400.     struct iocb __user * __user *iocb64;
  401.     long ret;
  402.  
  403. +        if (SBOX_IS_RESTRICTED())
  404. +                return -EPERM;
  405. +
  406.     if (unlikely(nr < 0))
  407.         return -EINVAL;
  408.  
  409. @@ -796,6 +871,11 @@
  410.     char *kernel_dev;
  411.     int retval;
  412.  
  413. +        if (SBOX_IS_RESTRICTED()) {
  414. +                SBOX_SET_SECURITY_ERR();
  415. +                return -EPERM;
  416. +        }
  417. +
  418.     kernel_type = copy_mount_string(type);
  419.     retval = PTR_ERR(kernel_type);
  420.     if (IS_ERR(kernel_type))
  421. @@ -1098,6 +1178,10 @@
  422.   */
  423.  COMPAT_SYSCALL_DEFINE4(openat, int, dfd, const char __user *, filename, int, flags, umode_t, mode)
  424.  {
  425. +        if (SBOX_IS_RESTRICTED()) {
  426. +                SBOX_SET_SECURITY_ERR();
  427. +                return -EPERM;
  428. +        }
  429.     return do_sys_open(dfd, filename, flags, mode);
  430.  }
  431.  
  432. @@ -1476,6 +1560,11 @@
  433.  COMPAT_SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd,
  434.                  struct file_handle __user *, handle, int, flags)
  435.  {
  436. +        if (SBOX_IS_RESTRICTED()) {
  437. +                SBOX_SET_SECURITY_ERR();
  438. +                return -EPERM;
  439. +        }
  440. +
  441.     return do_handle_open(mountdirfd, handle, flags);
  442.  }
  443.  #endif
  444. diff -aur linux-4.2/fs/compat_ioctl.c linux-4.2.tsarn1/fs/compat_ioctl.c
  445. --- linux-4.2/fs/compat_ioctl.c 2015-08-30 21:34:09.000000000 +0300
  446. +++ linux-4.2.tsarn1/fs/compat_ioctl.c  2016-02-08 16:51:12.657892404 +0300
  447. @@ -1550,6 +1550,11 @@
  448.     if (!f.file)
  449.         goto out;
  450.  
  451. +        if (SBOX_IS_RESTRICTED() && cmd != FIOCLEX && cmd != FIONCLEX) {
  452. +       error = -EPERM;
  453. +       goto out_fput;
  454. +   }
  455. +
  456.     /* RED-PEN how should LSM module know it's handling 32bit? */
  457.     error = security_file_ioctl(f.file, cmd, arg);
  458.     if (error)
  459. Only in linux-4.2.tsarn1/fs: compat_ioctl.c.orig
  460. diff -aur linux-4.2/fs/dcache.c linux-4.2.tsarn1/fs/dcache.c
  461. --- linux-4.2/fs/dcache.c   2015-08-30 21:34:09.000000000 +0300
  462. +++ linux-4.2.tsarn1/fs/dcache.c    2016-02-08 16:51:12.657892404 +0300
  463. @@ -3242,8 +3242,14 @@
  464.  {
  465.     int error;
  466.     struct path pwd, root;
  467. -   char *page = __getname();
  468. +   char *page = 0;
  469.  
  470. +        if (SBOX_IS_RESTRICTED()) {
  471. +                copy_to_user(buf, "/SANDBOX", 9);
  472. +                return 9;
  473. +        }
  474. +
  475. +        page = __getname();
  476.     if (!page)
  477.         return -ENOMEM;
  478.  
  479. Only in linux-4.2.tsarn1/fs: dcache.c.orig
  480. diff -aur linux-4.2/fs/dcookies.c linux-4.2.tsarn1/fs/dcookies.c
  481. --- linux-4.2/fs/dcookies.c 2015-08-30 21:34:09.000000000 +0300
  482. +++ linux-4.2.tsarn1/fs/dcookies.c  2016-02-08 16:51:12.657892404 +0300
  483. @@ -155,6 +155,11 @@
  484.     size_t pathlen;
  485.     struct dcookie_struct * dcs;
  486.  
  487. +        if (SBOX_IS_RESTRICTED()) {
  488. +                SBOX_SET_SECURITY_ERR();
  489. +                return -EPERM;
  490. +        }
  491. +
  492.     /* we could leak path information to users
  493.      * without dir read permission without this
  494.      */
  495. diff -aur linux-4.2/fs/eventfd.c linux-4.2.tsarn1/fs/eventfd.c
  496. --- linux-4.2/fs/eventfd.c  2015-08-30 21:34:09.000000000 +0300
  497. +++ linux-4.2.tsarn1/fs/eventfd.c   2016-02-08 16:51:12.657892404 +0300
  498. @@ -422,6 +422,9 @@
  499.     int fd, error;
  500.     struct file *file;
  501.  
  502. +        if (SBOX_IS_RESTRICTED())
  503. +                return -EPERM;
  504. +
  505.     error = get_unused_fd_flags(flags & EFD_SHARED_FCNTL_FLAGS);
  506.     if (error < 0)
  507.         return error;
  508. diff -aur linux-4.2/fs/eventpoll.c linux-4.2.tsarn1/fs/eventpoll.c
  509. --- linux-4.2/fs/eventpoll.c    2015-08-30 21:34:09.000000000 +0300
  510. +++ linux-4.2.tsarn1/fs/eventpoll.c 2016-02-08 16:51:12.657892404 +0300
  511. @@ -1767,6 +1767,9 @@
  512.     struct eventpoll *ep = NULL;
  513.     struct file *file;
  514.  
  515. +        if (SBOX_IS_RESTRICTED())
  516. +                return -EPERM;
  517. +
  518.     /* Check the EPOLL_* constant for consistency.  */
  519.     BUILD_BUG_ON(EPOLL_CLOEXEC != O_CLOEXEC);
  520.  
  521. @@ -1828,6 +1831,9 @@
  522.     struct epoll_event epds;
  523.     struct eventpoll *tep = NULL;
  524.  
  525. +        if (SBOX_IS_RESTRICTED())
  526. +                return -EPERM;
  527. +
  528.     error = -EFAULT;
  529.     if (ep_op_has_event(op) &&
  530.         copy_from_user(&epds, event, sizeof(struct epoll_event)))
  531. @@ -1965,6 +1971,9 @@
  532.     struct fd f;
  533.     struct eventpoll *ep;
  534.  
  535. +        if (SBOX_IS_RESTRICTED())
  536. +                return -EPERM;
  537. +
  538.     /* The maximum number of event must be greater than zero */
  539.     if (maxevents <= 0 || maxevents > EP_MAX_EVENTS)
  540.         return -EINVAL;
  541. @@ -2011,6 +2020,9 @@
  542.     int error;
  543.     sigset_t ksigmask, sigsaved;
  544.  
  545. +        if (SBOX_IS_RESTRICTED())
  546. +                return -EPERM;
  547. +
  548.     /*
  549.      * If the caller wants a certain signal mask to be set during the wait,
  550.      * we apply it here.
  551. diff -aur linux-4.2/fs/exec.c linux-4.2.tsarn1/fs/exec.c
  552. --- linux-4.2/fs/exec.c 2015-08-30 21:34:09.000000000 +0300
  553. +++ linux-4.2.tsarn1/fs/exec.c  2016-02-08 16:51:12.661225775 +0300
  554. @@ -121,6 +121,11 @@
  555.     if (IS_ERR(tmp))
  556.         goto out;
  557.  
  558. +        if (SBOX_IS_RESTRICTED()) {
  559. +                putname(tmp);
  560. +                return -EPERM;
  561. +        }
  562. +
  563.     file = do_filp_open(AT_FDCWD, tmp, &uselib_flags);
  564.     putname(tmp);
  565.     error = PTR_ERR(file);
  566. @@ -1486,6 +1491,15 @@
  567.     struct files_struct *displaced;
  568.     int retval;
  569.  
  570. +        if (SBOX_IS_RESTRICTED() && fd != AT_FDCWD) {
  571. +                retval = -EPERM;
  572. +                goto out_ret;
  573. +        }
  574. +        if ((current->sbox_flags & SBOX_NO_EXEC)) {
  575. +                SBOX_SET_SECURITY_ERR();
  576. +                goto out_ret;
  577. +        }
  578. +
  579.     if (IS_ERR(filename))
  580.         return PTR_ERR(filename);
  581.  
  582. @@ -1595,6 +1609,9 @@
  583.     putname(filename);
  584.     if (displaced)
  585.         put_files_struct(displaced);
  586. +        if ((current->sbox_flags & SBOX_NO_SYSCALLS)) {
  587. +                current->sbox_flags |= SBOX_NO_EXEC;
  588. +        }
  589.     return retval;
  590.  
  591.  out:
  592. diff -aur linux-4.2/fs/fcntl.c linux-4.2.tsarn1/fs/fcntl.c
  593. --- linux-4.2/fs/fcntl.c    2015-08-30 21:34:09.000000000 +0300
  594. +++ linux-4.2.tsarn1/fs/fcntl.c 2016-02-08 16:51:12.661225775 +0300
  595. @@ -361,6 +361,11 @@
  596.     if (!f.file)
  597.         goto out;
  598.  
  599. +        if (SBOX_IS_RESTRICTED() && !check_fcntl_cmd(cmd)) {
  600. +       err = -EPERM;
  601. +                goto out1;
  602. +        }
  603. +
  604.     if (unlikely(f.file->f_mode & FMODE_PATH)) {
  605.         if (!check_fcntl_cmd(cmd))
  606.             goto out1;
  607. @@ -386,6 +391,11 @@
  608.     if (!f.file)
  609.         goto out;
  610.  
  611. +        if (SBOX_IS_RESTRICTED() && !check_fcntl_cmd(cmd)) {
  612. +       err = -EPERM;
  613. +                goto out1;
  614. +        }
  615. +
  616.     if (unlikely(f.file->f_mode & FMODE_PATH)) {
  617.         if (!check_fcntl_cmd(cmd))
  618.             goto out1;
  619. diff -aur linux-4.2/fs/fhandle.c linux-4.2.tsarn1/fs/fhandle.c
  620. --- linux-4.2/fs/fhandle.c  2015-08-30 21:34:09.000000000 +0300
  621. +++ linux-4.2.tsarn1/fs/fhandle.c   2016-02-08 16:51:12.661225775 +0300
  622. @@ -97,6 +97,11 @@
  623.     int lookup_flags;
  624.     int err;
  625.  
  626. +        if (SBOX_IS_RESTRICTED()) {
  627. +                SBOX_SET_SECURITY_ERR();
  628. +                return -EPERM;
  629. +        }
  630. +
  631.     if ((flag & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0)
  632.         return -EINVAL;
  633.  
  634. @@ -258,6 +263,11 @@
  635.  {
  636.     long ret;
  637.  
  638. +        if (SBOX_IS_RESTRICTED()) {
  639. +                SBOX_SET_SECURITY_ERR();
  640. +                return -EPERM;
  641. +        }
  642. +
  643.     if (force_o_largefile())
  644.         flags |= O_LARGEFILE;
  645.  
  646. diff -aur linux-4.2/fs/filesystems.c linux-4.2.tsarn1/fs/filesystems.c
  647. --- linux-4.2/fs/filesystems.c  2015-08-30 21:34:09.000000000 +0300
  648. +++ linux-4.2.tsarn1/fs/filesystems.c   2016-02-08 16:51:12.661225775 +0300
  649. @@ -185,6 +185,11 @@
  650.  {
  651.     int retval = -EINVAL;
  652.  
  653. +        if (SBOX_IS_RESTRICTED()) {
  654. +                SBOX_SET_SECURITY_ERR();
  655. +                return -EPERM;
  656. +        }
  657. +
  658.     switch (option) {
  659.         case 1:
  660.             retval = fs_index((const char __user *) arg1);
  661. diff -aur linux-4.2/fs/ioctl.c linux-4.2.tsarn1/fs/ioctl.c
  662. --- linux-4.2/fs/ioctl.c    2015-08-30 21:34:09.000000000 +0300
  663. +++ linux-4.2.tsarn1/fs/ioctl.c 2016-02-08 16:51:12.661225775 +0300
  664. @@ -617,6 +617,12 @@
  665.  
  666.     if (!f.file)
  667.         return -EBADF;
  668. +
  669. +        if (SBOX_IS_RESTRICTED() && cmd != FIOCLEX && cmd != FIONCLEX) {
  670. +                fdput(f);
  671. +                return -EPERM;
  672. +        }
  673. +
  674.     error = security_file_ioctl(f.file, cmd, arg);
  675.     if (!error)
  676.         error = do_vfs_ioctl(f.file, fd, cmd, arg);
  677. diff -aur linux-4.2/fs/locks.c linux-4.2.tsarn1/fs/locks.c
  678. --- linux-4.2/fs/locks.c    2015-08-30 21:34:09.000000000 +0300
  679. +++ linux-4.2.tsarn1/fs/locks.c 2016-02-08 16:51:12.661225775 +0300
  680. @@ -1904,6 +1904,11 @@
  681.     if (!f.file)
  682.         goto out;
  683.  
  684. +        if (SBOX_IS_RESTRICTED()) {
  685. +                fdput(f);
  686. +                return -EPERM;
  687. +        }
  688. +
  689.     can_sleep = !(cmd & LOCK_NB);
  690.     cmd &= ~LOCK_NB;
  691.     unlock = (cmd == LOCK_UN);
  692. diff -aur linux-4.2/fs/namei.c linux-4.2.tsarn1/fs/namei.c
  693. --- linux-4.2/fs/namei.c    2015-08-30 21:34:09.000000000 +0300
  694. +++ linux-4.2.tsarn1/fs/namei.c 2016-02-08 16:51:12.661225775 +0300
  695. @@ -3518,6 +3518,11 @@
  696.     int error;
  697.     unsigned int lookup_flags = 0;
  698.  
  699. +        if (SBOX_IS_RESTRICTED()) {
  700. +                SBOX_SET_SECURITY_ERR();
  701. +                return -EPERM;
  702. +        }
  703. +
  704.     error = may_mknod(mode);
  705.     if (error)
  706.         return error;
  707. @@ -3590,6 +3595,11 @@
  708.     int error;
  709.     unsigned int lookup_flags = LOOKUP_DIRECTORY;
  710.  
  711. +        if (SBOX_IS_RESTRICTED()) {
  712. +                SBOX_SET_SECURITY_ERR();
  713. +                return -EPERM;
  714. +        }
  715. +
  716.  retry:
  717.     dentry = user_path_create(dfd, pathname, &path, lookup_flags);
  718.     if (IS_ERR(dentry))
  719. @@ -3738,6 +3748,9 @@
  720.  
  721.  SYSCALL_DEFINE1(rmdir, const char __user *, pathname)
  722.  {
  723. +        if (SBOX_IS_RESTRICTED()) {
  724. +                return -EPERM;
  725. +        }
  726.     return do_rmdir(AT_FDCWD, pathname);
  727.  }
  728.  
  729. @@ -3880,6 +3893,10 @@
  730.  
  731.  SYSCALL_DEFINE3(unlinkat, int, dfd, const char __user *, pathname, int, flag)
  732.  {
  733. +        if (SBOX_IS_RESTRICTED()) {
  734. +                return -EPERM;
  735. +        }
  736. +
  737.     if ((flag & ~AT_REMOVEDIR) != 0)
  738.         return -EINVAL;
  739.  
  740. @@ -3891,6 +3908,10 @@
  741.  
  742.  SYSCALL_DEFINE1(unlink, const char __user *, pathname)
  743.  {
  744. +        if (SBOX_IS_RESTRICTED()) {
  745. +                return -EPERM;
  746. +        }
  747. +
  748.     return do_unlinkat(AT_FDCWD, pathname);
  749.  }
  750.  
  751. @@ -3924,6 +3945,10 @@
  752.     struct path path;
  753.     unsigned int lookup_flags = 0;
  754.  
  755. +        if (SBOX_IS_RESTRICTED()) {
  756. +                return -EPERM;
  757. +        }
  758. +
  759.     from = getname(oldname);
  760.     if (IS_ERR(from))
  761.         return PTR_ERR(from);
  762. @@ -4042,6 +4067,10 @@
  763.     int how = 0;
  764.     int error;
  765.  
  766. +        if (SBOX_IS_RESTRICTED()) {
  767. +                return -EPERM;
  768. +        }
  769. +
  770.     if ((flags & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0)
  771.         return -EINVAL;
  772.     /*
  773. @@ -4301,6 +4330,10 @@
  774.     bool should_retry = false;
  775.     int error;
  776.  
  777. +        if (SBOX_IS_RESTRICTED()) {
  778. +                return -EPERM;
  779. +        }
  780. +
  781.     if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
  782.         return -EINVAL;
  783.  
  784. Only in linux-4.2.tsarn1/fs: namei.c.orig
  785. diff -aur linux-4.2/fs/namespace.c linux-4.2.tsarn1/fs/namespace.c
  786. --- linux-4.2/fs/namespace.c    2015-08-30 21:34:09.000000000 +0300
  787. +++ linux-4.2.tsarn1/fs/namespace.c 2016-02-08 16:51:12.661225775 +0300
  788. @@ -1599,6 +1599,11 @@
  789.     int retval;
  790.     int lookup_flags = 0;
  791.  
  792. +        if (SBOX_IS_RESTRICTED()) {
  793. +                SBOX_SET_SECURITY_ERR();
  794. +                return -EPERM;
  795. +        }
  796. +
  797.     if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
  798.         return -EINVAL;
  799.  
  800. @@ -2898,6 +2903,11 @@
  801.     char *kernel_dev;
  802.     unsigned long data_page;
  803.  
  804. +        if (SBOX_IS_RESTRICTED()) {
  805. +                SBOX_SET_SECURITY_ERR();
  806. +                return -EPERM;
  807. +        }
  808. +
  809.     kernel_type = copy_mount_string(type);
  810.     ret = PTR_ERR(kernel_type);
  811.     if (IS_ERR(kernel_type))
  812. @@ -2982,6 +2992,11 @@
  813.     struct mountpoint *old_mp, *root_mp;
  814.     int error;
  815.  
  816. +        if (SBOX_IS_RESTRICTED()) {
  817. +                SBOX_SET_SECURITY_ERR();
  818. +                return -EPERM;
  819. +        }
  820. +
  821.     if (!may_mount())
  822.         return -EPERM;
  823.  
  824. Only in linux-4.2.tsarn1/fs: namespace.c.orig
  825. diff -aur linux-4.2/fs/notify/fanotify/fanotify_user.c linux-4.2.tsarn1/fs/notify/fanotify/fanotify_user.c
  826. --- linux-4.2/fs/notify/fanotify/fanotify_user.c    2015-08-30 21:34:09.000000000 +0300
  827. +++ linux-4.2.tsarn1/fs/notify/fanotify/fanotify_user.c 2016-02-08 16:51:12.664559148 +0300
  828. @@ -694,6 +694,9 @@
  829.     struct user_struct *user;
  830.     struct fanotify_event_info *oevent;
  831.  
  832. +        if (SBOX_IS_RESTRICTED())
  833. +                return -EPERM;
  834. +
  835.     pr_debug("%s: flags=%d event_f_flags=%d\n",
  836.         __func__, flags, event_f_flags);
  837.  
  838. @@ -808,6 +811,9 @@
  839.     struct path path;
  840.     int ret;
  841.  
  842. +        if (SBOX_IS_RESTRICTED())
  843. +                return -EPERM;
  844. +
  845.     pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n",
  846.          __func__, fanotify_fd, flags, dfd, pathname, mask);
  847.  
  848. diff -aur linux-4.2/fs/notify/inotify/inotify_user.c linux-4.2.tsarn1/fs/notify/inotify/inotify_user.c
  849. --- linux-4.2/fs/notify/inotify/inotify_user.c  2015-08-30 21:34:09.000000000 +0300
  850. +++ linux-4.2.tsarn1/fs/notify/inotify/inotify_user.c   2016-02-08 16:51:12.664559148 +0300
  851. @@ -671,6 +671,9 @@
  852.     struct fsnotify_group *group;
  853.     int ret;
  854.  
  855. +        if (SBOX_IS_RESTRICTED())
  856. +                return -EPERM;
  857. +
  858.     /* Check the IN_* constants for consistency.  */
  859.     BUILD_BUG_ON(IN_CLOEXEC != O_CLOEXEC);
  860.     BUILD_BUG_ON(IN_NONBLOCK != O_NONBLOCK);
  861. @@ -706,6 +709,9 @@
  862.     int ret;
  863.     unsigned flags = 0;
  864.  
  865. +        if (SBOX_IS_RESTRICTED())
  866. +                return -EPERM;
  867. +
  868.     /* don't allow invalid bits: we don't want flags set */
  869.     if (unlikely(!(mask & ALL_INOTIFY_BITS)))
  870.         return -EINVAL;
  871. @@ -748,6 +754,9 @@
  872.     struct fd f;
  873.     int ret = 0;
  874.  
  875. +        if (SBOX_IS_RESTRICTED())
  876. +                return -EPERM;
  877. +
  878.     f = fdget(fd);
  879.     if (unlikely(!f.file))
  880.         return -EBADF;
  881. diff -aur linux-4.2/fs/open.c linux-4.2.tsarn1/fs/open.c
  882. --- linux-4.2/fs/open.c 2015-08-30 21:34:09.000000000 +0300
  883. +++ linux-4.2.tsarn1/fs/open.c  2016-02-08 16:51:12.664559148 +0300
  884. @@ -34,6 +34,54 @@
  885.  
  886.  #include "internal.h"
  887.  
  888. +static const char * const secure_paths[] =
  889. +{
  890. +        "/lib/", "/lib32/", "/lib64/",
  891. +        "/usr/lib/", "/usr/lib32/", "/usr/lib64/",
  892. +        "/usr/include/", "/usr/libexec/",
  893. +        "/usr/local/lib/", "/usr/local/lib32/", "/usr/local/lib64/",
  894. +        "/usr/local/include/", "/usr/local/libexec/",
  895. +        "/bin/", "/usr/bin/", "/usr/local/bin/",
  896. +        "/usr/share/", "/usr/local/share/", "/dev/urandom", "/dev/zero", "/dev/null",
  897. +        "/SANDBOX/",
  898. +        NULL
  899. +};
  900. +
  901. +int cher_patch_is_secure_path(const char *path)
  902. +{
  903. +        const char *s;
  904. +        int i;
  905. +
  906. +        if (strstr(path, ".."))
  907. +                return -1;
  908. +        for (i = 0; secure_paths[i] && strncmp(path, secure_paths[i], strlen(secure_paths[i])); ++i);
  909. +        if (secure_paths[i]) {
  910. +                return 0;
  911. +        }
  912. +
  913. +        if (!strncmp(path, "/SANDBOX/", 9)) path += 9;
  914. +        s = path;
  915. +        while (s[0] == '.' && s[1] == '/') s += 2;
  916. +        for (; *s && *s != '/'; s++);
  917. +        if (*s == '/') return -1;
  918. +        return 0;
  919. +}
  920. +
  921. +int cher_check_user_path(int dfd, const char __user **p_path)
  922. +{
  923. +        struct filename *tmp = NULL;
  924. +        if (dfd != AT_FDCWD) return -EPERM;
  925. +        tmp = getname(*p_path);
  926. +        if (IS_ERR(tmp)) return -EINVAL;
  927. +        if (cher_patch_is_secure_path(tmp->name) < 0) {
  928. +                putname(tmp);
  929. +                return -EPERM;
  930. +        }
  931. +        if (!strncmp("/SANDBOX/", tmp->name, 9)) *p_path += 9;
  932. +        putname(tmp);
  933. +        return 0;
  934. +}
  935. +
  936.  int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
  937.     struct file *filp)
  938.  {
  939. @@ -141,12 +189,18 @@
  940.  
  941.  SYSCALL_DEFINE2(truncate, const char __user *, path, long, length)
  942.  {
  943. +        if (SBOX_IS_RESTRICTED())
  944. +                return -EPERM;
  945. +
  946.     return do_sys_truncate(path, length);
  947.  }
  948.  
  949.  #ifdef CONFIG_COMPAT
  950.  COMPAT_SYSCALL_DEFINE2(truncate, const char __user *, path, compat_off_t, length)
  951.  {
  952. +        if (SBOX_IS_RESTRICTED())
  953. +                return -EPERM;
  954. +
  955.     return do_sys_truncate(path, length);
  956.  }
  957.  #endif
  958. @@ -214,11 +268,17 @@
  959.  #if BITS_PER_LONG == 32
  960.  SYSCALL_DEFINE2(truncate64, const char __user *, path, loff_t, length)
  961.  {
  962. +        if (SBOX_IS_RESTRICTED())
  963. +                return -EPERM;
  964. +
  965.     return do_sys_truncate(path, length);
  966.  }
  967.  
  968.  SYSCALL_DEFINE2(ftruncate64, unsigned int, fd, loff_t, length)
  969.  {
  970. +        if (SBOX_IS_RESTRICTED())
  971. +                return -EPERM;
  972. +
  973.     return do_sys_ftruncate(fd, length, 0);
  974.  }
  975.  #endif /* BITS_PER_LONG == 32 */
  976. @@ -319,9 +379,13 @@
  977.  
  978.  SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
  979.  {
  980. -   struct fd f = fdget(fd);
  981. +   struct fd f;
  982.     int error = -EBADF;
  983.  
  984. +        if (SBOX_IS_RESTRICTED())
  985. +                return -EPERM;
  986. +
  987. +        f = fdget(fd);
  988.     if (f.file) {
  989.         error = vfs_fallocate(f.file, mode, offset, len);
  990.         fdput(f);
  991. @@ -343,6 +407,11 @@
  992.     int res;
  993.     unsigned int lookup_flags = LOOKUP_FOLLOW;
  994.  
  995. +        if (SBOX_IS_RESTRICTED()) {
  996. +                res = cher_check_user_path(dfd, &filename);
  997. +                if (res < 0) return res;
  998. +        }
  999. +
  1000.     if (mode & ~S_IRWXO)    /* where's F_OK, X_OK, W_OK, R_OK? */
  1001.         return -EINVAL;
  1002.  
  1003. @@ -420,6 +489,10 @@
  1004.     struct path path;
  1005.     int error;
  1006.     unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
  1007. +
  1008. +        if (SBOX_IS_RESTRICTED())
  1009. +                return -EPERM;
  1010. +
  1011.  retry:
  1012.     error = user_path_at(AT_FDCWD, filename, lookup_flags, &path);
  1013.     if (error)
  1014. @@ -451,6 +524,11 @@
  1015.     if (!f.file)
  1016.         goto out;
  1017.  
  1018. +        if (SBOX_IS_RESTRICTED()) {
  1019. +                error = -EPERM;
  1020. +                goto out_putf;
  1021. +        }
  1022. +
  1023.     inode = file_inode(f.file);
  1024.  
  1025.     error = -ENOTDIR;
  1026. @@ -471,6 +549,12 @@
  1027.     struct path path;
  1028.     int error;
  1029.     unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
  1030. +
  1031. +        if (SBOX_IS_RESTRICTED()) {
  1032. +                SBOX_SET_SECURITY_ERR();
  1033. +                return -EPERM;
  1034. +        }
  1035. +
  1036.  retry:
  1037.     error = user_path_at(AT_FDCWD, filename, lookup_flags, &path);
  1038.     if (error)
  1039. @@ -530,9 +614,15 @@
  1040.  
  1041.  SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
  1042.  {
  1043. -   struct fd f = fdget(fd);
  1044. +   struct fd f;
  1045.     int err = -EBADF;
  1046.  
  1047. +        if (SBOX_IS_RESTRICTED()) {
  1048. +                SBOX_SET_SECURITY_ERR();
  1049. +                return -EPERM;
  1050. +        }
  1051. +
  1052. +        f = fdget(fd);
  1053.     if (f.file) {
  1054.         audit_file(f.file);
  1055.         err = chmod_common(&f.file->f_path, mode);
  1056. @@ -546,6 +636,12 @@
  1057.     struct path path;
  1058.     int error;
  1059.     unsigned int lookup_flags = LOOKUP_FOLLOW;
  1060. +
  1061. +        if (SBOX_IS_RESTRICTED()) {
  1062. +                SBOX_SET_SECURITY_ERR();
  1063. +                return -EPERM;
  1064. +        }
  1065. +
  1066.  retry:
  1067.     error = user_path_at(dfd, filename, lookup_flags, &path);
  1068.     if (!error) {
  1069. @@ -613,6 +709,11 @@
  1070.     int error = -EINVAL;
  1071.     int lookup_flags;
  1072.  
  1073. +        if (SBOX_IS_RESTRICTED()) {
  1074. +                SBOX_SET_SECURITY_ERR();
  1075. +                return -EPERM;
  1076. +        }
  1077. +
  1078.     if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
  1079.         goto out;
  1080.  
  1081. @@ -657,6 +758,12 @@
  1082.     if (!f.file)
  1083.         goto out;
  1084.  
  1085. +        if (SBOX_IS_RESTRICTED()) {
  1086. +                SBOX_SET_SECURITY_ERR();
  1087. +                error = -EPERM;
  1088. +                goto out_fput;
  1089. +        }
  1090. +
  1091.     error = mnt_want_write_file(f.file);
  1092.     if (error)
  1093.         goto out_fput;
  1094. @@ -1010,9 +1117,16 @@
  1095.  long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
  1096.  {
  1097.     struct open_flags op;
  1098. -   int fd = build_open_flags(flags, mode, &op);
  1099. +   int fd = 0;
  1100.     struct filename *tmp;
  1101.  
  1102. +        if (SBOX_IS_RESTRICTED()) {
  1103. +                int res = cher_check_user_path(dfd, &filename);
  1104. +                if (res < 0) return res;
  1105. +                flags &= ~(O_CREAT | O_EXCL);
  1106. +        }
  1107. +
  1108. +   fd = build_open_flags(flags, mode, &op);
  1109.     if (fd)
  1110.         return fd;
  1111.  
  1112. @@ -1117,6 +1231,9 @@
  1113.   */
  1114.  SYSCALL_DEFINE0(vhangup)
  1115.  {
  1116. +        if (SBOX_IS_RESTRICTED())
  1117. +                return -EPERM;
  1118. +
  1119.     if (capable(CAP_SYS_TTY_CONFIG)) {
  1120.         tty_vhangup_self();
  1121.         return 0;
  1122. Only in linux-4.2.tsarn1/fs: open.c.orig
  1123. diff -aur linux-4.2/fs/pipe.c linux-4.2.tsarn1/fs/pipe.c
  1124. --- linux-4.2/fs/pipe.c 2015-08-30 21:34:09.000000000 +0300
  1125. +++ linux-4.2.tsarn1/fs/pipe.c  2016-02-08 16:51:12.664559148 +0300
  1126. @@ -780,6 +780,11 @@
  1127.     int fd[2];
  1128.     int error;
  1129.  
  1130. +        if (SBOX_IS_RESTRICTED()) {
  1131. +                SBOX_SET_SECURITY_ERR();
  1132. +                return -EPERM;
  1133. +        }
  1134. +
  1135.     error = __do_pipe_flags(fd, files, flags);
  1136.     if (!error) {
  1137.         if (unlikely(copy_to_user(fildes, fd, sizeof(fd)))) {
  1138. diff -aur linux-4.2/fs/proc/base.c linux-4.2.tsarn1/fs/proc/base.c
  1139. --- linux-4.2/fs/proc/base.c    2015-08-30 21:34:09.000000000 +0300
  1140. +++ linux-4.2.tsarn1/fs/proc/base.c 2016-02-08 16:53:55.973135133 +0300
  1141. @@ -613,6 +613,7 @@
  1142.     [RLIMIT_NICE] = {"Max nice priority", NULL},
  1143.     [RLIMIT_RTPRIO] = {"Max realtime priority", NULL},
  1144.     [RLIMIT_RTTIME] = {"Max realtime timeout", "us"},
  1145. +    [RLIMIT_MCPU] = {"Max cpu time", "ms"}
  1146.  };
  1147.  
  1148.  /* Display limits for a process */
  1149. diff -aur linux-4.2/fs/quota/compat.c linux-4.2.tsarn1/fs/quota/compat.c
  1150. --- linux-4.2/fs/quota/compat.c 2015-08-30 21:34:09.000000000 +0300
  1151. +++ linux-4.2.tsarn1/fs/quota/compat.c  2016-02-08 16:51:12.664559148 +0300
  1152. @@ -52,6 +52,11 @@
  1153.     u16 xdata;
  1154.     long ret;
  1155.  
  1156. +        if (SBOX_IS_RESTRICTED()) {
  1157. +                SBOX_SET_SECURITY_ERR();
  1158. +                return -EPERM;
  1159. +        }
  1160. +
  1161.     cmds = cmd >> SUBCMDSHIFT;
  1162.  
  1163.     switch (cmds) {
  1164. diff -aur linux-4.2/fs/quota/quota.c linux-4.2.tsarn1/fs/quota/quota.c
  1165. --- linux-4.2/fs/quota/quota.c  2015-08-30 21:34:09.000000000 +0300
  1166. +++ linux-4.2.tsarn1/fs/quota/quota.c   2016-02-08 16:51:12.664559148 +0300
  1167. @@ -765,6 +765,11 @@
  1168.     struct path path, *pathp = NULL;
  1169.     int ret;
  1170.  
  1171. +        if (SBOX_IS_RESTRICTED()) {
  1172. +                SBOX_SET_SECURITY_ERR();
  1173. +                return -EPERM;
  1174. +        }
  1175. +
  1176.     cmds = cmd >> SUBCMDSHIFT;
  1177.     type = cmd & SUBCMDMASK;
  1178.  
  1179. diff -aur linux-4.2/fs/read_write.c linux-4.2.tsarn1/fs/read_write.c
  1180. --- linux-4.2/fs/read_write.c   2015-08-30 21:34:09.000000000 +0300
  1181. +++ linux-4.2.tsarn1/fs/read_write.c    2016-02-08 16:51:12.664559148 +0300
  1182. @@ -597,6 +597,9 @@
  1183.     struct fd f;
  1184.     ssize_t ret = -EBADF;
  1185.  
  1186. +        if (SBOX_IS_RESTRICTED())
  1187. +                return -EPERM;
  1188. +
  1189.     if (pos < 0)
  1190.         return -EINVAL;
  1191.  
  1192. @@ -617,6 +620,9 @@
  1193.     struct fd f;
  1194.     ssize_t ret = -EBADF;
  1195.  
  1196. +        if (SBOX_IS_RESTRICTED())
  1197. +                return -EPERM;
  1198. +
  1199.     if (pos < 0)
  1200.         return -EINVAL;
  1201.  
  1202. @@ -902,6 +908,9 @@
  1203.     struct fd f;
  1204.     ssize_t ret = -EBADF;
  1205.  
  1206. +        if (SBOX_IS_RESTRICTED())
  1207. +                return -EPERM;
  1208. +
  1209.     if (pos < 0)
  1210.         return -EINVAL;
  1211.  
  1212. @@ -926,6 +935,9 @@
  1213.     struct fd f;
  1214.     ssize_t ret = -EBADF;
  1215.  
  1216. +        if (SBOX_IS_RESTRICTED())
  1217. +                return -EPERM;
  1218. +
  1219.     if (pos < 0)
  1220.         return -EINVAL;
  1221.  
  1222. @@ -1044,6 +1056,9 @@
  1223.     struct fd f;
  1224.     ssize_t ret;
  1225.  
  1226. +        if (SBOX_IS_RESTRICTED())
  1227. +                return -EPERM;
  1228. +
  1229.     if (pos < 0)
  1230.         return -EINVAL;
  1231.     f = fdget(fd);
  1232. @@ -1121,6 +1136,9 @@
  1233.     struct fd f;
  1234.     ssize_t ret;
  1235.  
  1236. +        if (SBOX_IS_RESTRICTED())
  1237. +                return -EPERM;
  1238. +
  1239.     if (pos < 0)
  1240.         return -EINVAL;
  1241.     f = fdget(fd);
  1242. diff -aur linux-4.2/fs/signalfd.c linux-4.2.tsarn1/fs/signalfd.c
  1243. --- linux-4.2/fs/signalfd.c 2015-08-30 21:34:09.000000000 +0300
  1244. +++ linux-4.2.tsarn1/fs/signalfd.c  2016-02-08 16:51:12.664559148 +0300
  1245. @@ -258,6 +258,9 @@
  1246.     sigset_t sigmask;
  1247.     struct signalfd_ctx *ctx;
  1248.  
  1249. +        if (SBOX_IS_RESTRICTED())
  1250. +                return -EPERM;
  1251. +
  1252.     /* Check the SFD_* constants for consistency.  */
  1253.     BUILD_BUG_ON(SFD_CLOEXEC != O_CLOEXEC);
  1254.     BUILD_BUG_ON(SFD_NONBLOCK != O_NONBLOCK);
  1255. @@ -322,6 +325,9 @@
  1256.     sigset_t tmp;
  1257.     sigset_t __user *ksigmask;
  1258.  
  1259. +        if (SBOX_IS_RESTRICTED())
  1260. +                return -EPERM;
  1261. +
  1262.     if (sigsetsize != sizeof(compat_sigset_t))
  1263.         return -EINVAL;
  1264.     if (copy_from_user(&ss32, sigmask, sizeof(ss32)))
  1265. diff -aur linux-4.2/fs/splice.c linux-4.2.tsarn1/fs/splice.c
  1266. --- linux-4.2/fs/splice.c   2015-08-30 21:34:09.000000000 +0300
  1267. +++ linux-4.2.tsarn1/fs/splice.c    2016-02-08 16:51:12.664559148 +0300
  1268. @@ -1635,6 +1635,9 @@
  1269.     struct fd f;
  1270.     long error;
  1271.  
  1272. +        if (SBOX_IS_RESTRICTED())
  1273. +                return -EPERM;
  1274. +
  1275.     if (unlikely(nr_segs > UIO_MAXIOV))
  1276.         return -EINVAL;
  1277.     else if (unlikely(!nr_segs))
  1278. @@ -1660,6 +1663,10 @@
  1279.  {
  1280.     unsigned i;
  1281.     struct iovec __user *iov;
  1282. +
  1283. +        if (SBOX_IS_RESTRICTED())
  1284. +                return -EPERM;
  1285. +
  1286.     if (nr_segs > UIO_MAXIOV)
  1287.         return -EINVAL;
  1288.     iov = compat_alloc_user_space(nr_segs * sizeof(struct iovec));
  1289. @@ -1682,6 +1689,9 @@
  1290.     struct fd in, out;
  1291.     long error;
  1292.  
  1293. +        if (SBOX_IS_RESTRICTED())
  1294. +                return -EPERM;
  1295. +
  1296.     if (unlikely(!len))
  1297.         return 0;
  1298.  
  1299. @@ -2013,6 +2023,9 @@
  1300.     struct fd in;
  1301.     int error;
  1302.  
  1303. +        if (SBOX_IS_RESTRICTED())
  1304. +                return -EPERM;
  1305. +
  1306.     if (unlikely(!len))
  1307.         return 0;
  1308.  
  1309. Only in linux-4.2.tsarn1/fs: splice.c.orig
  1310. diff -aur linux-4.2/fs/stat.c linux-4.2.tsarn1/fs/stat.c
  1311. --- linux-4.2/fs/stat.c 2015-08-30 21:34:09.000000000 +0300
  1312. +++ linux-4.2.tsarn1/fs/stat.c  2016-02-08 16:51:12.667892520 +0300
  1313. @@ -18,6 +18,8 @@
  1314.  #include <asm/uaccess.h>
  1315.  #include <asm/unistd.h>
  1316.  
  1317. +int cher_check_user_path(int dfd, const char __user **p_path);
  1318. +
  1319.  void generic_fillattr(struct inode *inode, struct kstat *stat)
  1320.  {
  1321.     stat->dev = inode->i_sb->s_dev;
  1322. @@ -180,6 +182,11 @@
  1323.     struct kstat stat;
  1324.     int error;
  1325.  
  1326. +        if (SBOX_IS_RESTRICTED()) {
  1327. +                error = cher_check_user_path(AT_FDCWD, &filename);
  1328. +                if (error < 0) return error;
  1329. +        }
  1330. +
  1331.     error = vfs_stat(filename, &stat);
  1332.     if (error)
  1333.         return error;
  1334. @@ -193,6 +200,11 @@
  1335.     struct kstat stat;
  1336.     int error;
  1337.  
  1338. +        if (SBOX_IS_RESTRICTED()) {
  1339. +                error = cher_check_user_path(AT_FDCWD, &filename);
  1340. +                if (error < 0) return error;
  1341. +        }
  1342. +
  1343.     error = vfs_lstat(filename, &stat);
  1344.     if (error)
  1345.         return error;
  1346. @@ -267,8 +279,14 @@
  1347.         struct stat __user *, statbuf)
  1348.  {
  1349.     struct kstat stat;
  1350. -   int error = vfs_stat(filename, &stat);
  1351. +   int error;
  1352.  
  1353. +        if (SBOX_IS_RESTRICTED()) {
  1354. +                error = cher_check_user_path(AT_FDCWD, &filename);
  1355. +                if (error < 0) return error;
  1356. +        }
  1357. +
  1358. +   error = vfs_stat(filename, &stat);
  1359.     if (error)
  1360.         return error;
  1361.     return cp_new_stat(&stat, statbuf);
  1362. @@ -280,6 +298,11 @@
  1363.     struct kstat stat;
  1364.     int error;
  1365.  
  1366. +        if (SBOX_IS_RESTRICTED()) {
  1367. +                error = cher_check_user_path(AT_FDCWD, &filename);
  1368. +                if (error < 0) return error;
  1369. +        }
  1370. +
  1371.     error = vfs_lstat(filename, &stat);
  1372.     if (error)
  1373.         return error;
  1374. @@ -294,6 +317,11 @@
  1375.     struct kstat stat;
  1376.     int error;
  1377.  
  1378. +        if (SBOX_IS_RESTRICTED()) {
  1379. +                error = cher_check_user_path(dfd, &filename);
  1380. +                if (error < 0) return error;
  1381. +        }
  1382. +
  1383.     error = vfs_fstatat(dfd, filename, &stat, flag);
  1384.     if (error)
  1385.         return error;
  1386. @@ -320,6 +348,11 @@
  1387.     int empty = 0;
  1388.     unsigned int lookup_flags = LOOKUP_EMPTY;
  1389.  
  1390. +        if (SBOX_IS_RESTRICTED()) {
  1391. +                error = cher_check_user_path(dfd, &pathname);
  1392. +                if (error < 0) return error;
  1393. +        }
  1394. +
  1395.     if (bufsiz <= 0)
  1396.         return -EINVAL;
  1397.  
  1398. @@ -401,8 +434,14 @@
  1399.         struct stat64 __user *, statbuf)
  1400.  {
  1401.     struct kstat stat;
  1402. -   int error = vfs_stat(filename, &stat);
  1403. +   int error;
  1404.  
  1405. +        if (SBOX_IS_RESTRICTED()) {
  1406. +                error = cher_check_user_path(AT_FDCWD, &filename);
  1407. +                if (error < 0) return error;
  1408. +        }
  1409. +
  1410. +   error = vfs_stat(filename, &stat);
  1411.     if (!error)
  1412.         error = cp_new_stat64(&stat, statbuf);
  1413.  
  1414. @@ -413,8 +452,14 @@
  1415.         struct stat64 __user *, statbuf)
  1416.  {
  1417.     struct kstat stat;
  1418. -   int error = vfs_lstat(filename, &stat);
  1419. +   int error;
  1420. +
  1421. +        if (SBOX_IS_RESTRICTED()) {
  1422. +                error = cher_check_user_path(AT_FDCWD, &filename);
  1423. +                if (error < 0) return error;
  1424. +        }
  1425.  
  1426. +   error = vfs_lstat(filename, &stat);
  1427.     if (!error)
  1428.         error = cp_new_stat64(&stat, statbuf);
  1429.  
  1430. @@ -438,6 +483,11 @@
  1431.     struct kstat stat;
  1432.     int error;
  1433.  
  1434. +        if (SBOX_IS_RESTRICTED()) {
  1435. +                error = cher_check_user_path(dfd, &filename);
  1436. +                if (error < 0) return error;
  1437. +        }
  1438. +
  1439.     error = vfs_fstatat(dfd, filename, &stat, flag);
  1440.     if (error)
  1441.         return error;
  1442. diff -aur linux-4.2/fs/statfs.c linux-4.2.tsarn1/fs/statfs.c
  1443. --- linux-4.2/fs/statfs.c   2015-08-30 21:34:09.000000000 +0300
  1444. +++ linux-4.2.tsarn1/fs/statfs.c    2016-02-08 16:51:12.667892520 +0300
  1445. @@ -172,7 +172,12 @@
  1446.  SYSCALL_DEFINE2(statfs, const char __user *, pathname, struct statfs __user *, buf)
  1447.  {
  1448.     struct kstatfs st;
  1449. -   int error = user_statfs(pathname, &st);
  1450. +   int error;
  1451. +
  1452. +        if (SBOX_IS_RESTRICTED())
  1453. +                return -EPERM;
  1454. +
  1455. +   error = user_statfs(pathname, &st);
  1456.     if (!error)
  1457.         error = do_statfs_native(&st, buf);
  1458.     return error;
  1459. @@ -182,6 +187,10 @@
  1460.  {
  1461.     struct kstatfs st;
  1462.     int error;
  1463. +
  1464. +        if (SBOX_IS_RESTRICTED())
  1465. +                return -EPERM;
  1466. +
  1467.     if (sz != sizeof(*buf))
  1468.         return -EINVAL;
  1469.     error = user_statfs(pathname, &st);
  1470. @@ -193,7 +202,12 @@
  1471.  SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct statfs __user *, buf)
  1472.  {
  1473.     struct kstatfs st;
  1474. -   int error = fd_statfs(fd, &st);
  1475. +   int error;
  1476. +
  1477. +        if (SBOX_IS_RESTRICTED())
  1478. +                return -EPERM;
  1479. +
  1480. +   error = fd_statfs(fd, &st);
  1481.     if (!error)
  1482.         error = do_statfs_native(&st, buf);
  1483.     return error;
  1484. @@ -204,6 +218,9 @@
  1485.     struct kstatfs st;
  1486.     int error;
  1487.  
  1488. +        if (SBOX_IS_RESTRICTED())
  1489. +                return -EPERM;
  1490. +
  1491.     if (sz != sizeof(*buf))
  1492.         return -EINVAL;
  1493.  
  1494. @@ -229,7 +246,12 @@
  1495.  {
  1496.     struct ustat tmp;
  1497.     struct kstatfs sbuf;
  1498. -   int err = vfs_ustat(new_decode_dev(dev), &sbuf);
  1499. +   int err;
  1500. +
  1501. +        if (SBOX_IS_RESTRICTED())
  1502. +                return -EPERM;
  1503. +
  1504. +   err = vfs_ustat(new_decode_dev(dev), &sbuf);
  1505.     if (err)
  1506.         return err;
  1507.  
  1508. diff -aur linux-4.2/fs/sync.c linux-4.2.tsarn1/fs/sync.c
  1509. --- linux-4.2/fs/sync.c 2015-08-30 21:34:09.000000000 +0300
  1510. +++ linux-4.2.tsarn1/fs/sync.c  2016-02-08 16:51:12.667892520 +0300
  1511. @@ -103,6 +103,9 @@
  1512.  {
  1513.     int nowait = 0, wait = 1;
  1514.  
  1515. +        if (SBOX_IS_RESTRICTED())
  1516. +                return -EPERM;
  1517. +
  1518.     wakeup_flusher_threads(0, WB_REASON_SYNC);
  1519.     iterate_supers(sync_inodes_one_sb, NULL);
  1520.     iterate_supers(sync_fs_one_sb, &nowait);
  1521. @@ -148,10 +151,14 @@
  1522.   */
  1523.  SYSCALL_DEFINE1(syncfs, int, fd)
  1524.  {
  1525. -   struct fd f = fdget(fd);
  1526. +   struct fd f;
  1527.     struct super_block *sb;
  1528.     int ret;
  1529.  
  1530. +        if (SBOX_IS_RESTRICTED())
  1531. +                return -EPERM;
  1532. +
  1533. +        f = fdget(fd);
  1534.     if (!f.file)
  1535.         return -EBADF;
  1536.     sb = f.file->f_path.dentry->d_sb;
  1537. @@ -219,11 +226,17 @@
  1538.  
  1539.  SYSCALL_DEFINE1(fsync, unsigned int, fd)
  1540.  {
  1541. +        if (SBOX_IS_RESTRICTED())
  1542. +                return -EPERM;
  1543. +
  1544.     return do_fsync(fd, 0);
  1545.  }
  1546.  
  1547.  SYSCALL_DEFINE1(fdatasync, unsigned int, fd)
  1548.  {
  1549. +        if (SBOX_IS_RESTRICTED())
  1550. +                return -EPERM;
  1551. +
  1552.     return do_fsync(fd, 1);
  1553.  }
  1554.  
  1555. @@ -283,6 +296,9 @@
  1556.     loff_t endbyte;         /* inclusive */
  1557.     umode_t i_mode;
  1558.  
  1559. +        if (SBOX_IS_RESTRICTED())
  1560. +                return -EPERM;
  1561. +
  1562.     ret = -EINVAL;
  1563.     if (flags & ~VALID_FLAGS)
  1564.         goto out;
  1565. diff -aur linux-4.2/fs/timerfd.c linux-4.2.tsarn1/fs/timerfd.c
  1566. --- linux-4.2/fs/timerfd.c  2015-08-30 21:34:09.000000000 +0300
  1567. +++ linux-4.2.tsarn1/fs/timerfd.c   2016-02-08 16:51:12.667892520 +0300
  1568. @@ -378,6 +378,9 @@
  1569.     int ufd;
  1570.     struct timerfd_ctx *ctx;
  1571.  
  1572. +        if (SBOX_IS_RESTRICTED())
  1573. +                return -EPERM;
  1574. +
  1575.     /* Check the TFD_* constants for consistency.  */
  1576.     BUILD_BUG_ON(TFD_CLOEXEC != O_CLOEXEC);
  1577.     BUILD_BUG_ON(TFD_NONBLOCK != O_NONBLOCK);
  1578. @@ -518,6 +521,9 @@
  1579.     struct itimerspec new, old;
  1580.     int ret;
  1581.  
  1582. +        if (SBOX_IS_RESTRICTED())
  1583. +                return -EPERM;
  1584. +
  1585.     if (copy_from_user(&new, utmr, sizeof(new)))
  1586.         return -EFAULT;
  1587.     ret = do_timerfd_settime(ufd, flags, &new, &old);
  1588. @@ -532,7 +538,12 @@
  1589.  SYSCALL_DEFINE2(timerfd_gettime, int, ufd, struct itimerspec __user *, otmr)
  1590.  {
  1591.     struct itimerspec kotmr;
  1592. -   int ret = do_timerfd_gettime(ufd, &kotmr);
  1593. +   int ret;
  1594. +
  1595. +        if (SBOX_IS_RESTRICTED())
  1596. +                return -EPERM;
  1597. +
  1598. +   ret = do_timerfd_gettime(ufd, &kotmr);
  1599.     if (ret)
  1600.         return ret;
  1601.     return copy_to_user(otmr, &kotmr, sizeof(kotmr)) ? -EFAULT: 0;
  1602. @@ -546,6 +557,9 @@
  1603.     struct itimerspec new, old;
  1604.     int ret;
  1605.  
  1606. +        if (SBOX_IS_RESTRICTED())
  1607. +                return -EPERM;
  1608. +
  1609.     if (get_compat_itimerspec(&new, utmr))
  1610.         return -EFAULT;
  1611.     ret = do_timerfd_settime(ufd, flags, &new, &old);
  1612. @@ -560,7 +574,12 @@
  1613.         struct compat_itimerspec __user *, otmr)
  1614.  {
  1615.     struct itimerspec kotmr;
  1616. -   int ret = do_timerfd_gettime(ufd, &kotmr);
  1617. +   int ret;
  1618. +
  1619. +        if (SBOX_IS_RESTRICTED())
  1620. +                return -EPERM;
  1621. +
  1622. +   ret = do_timerfd_gettime(ufd, &kotmr);
  1623.     if (ret)
  1624.         return ret;
  1625.     return put_compat_itimerspec(otmr, &kotmr) ? -EFAULT: 0;
  1626. diff -aur linux-4.2/fs/utimes.c linux-4.2.tsarn1/fs/utimes.c
  1627. --- linux-4.2/fs/utimes.c   2015-08-30 21:34:09.000000000 +0300
  1628. +++ linux-4.2.tsarn1/fs/utimes.c    2016-02-08 16:51:12.667892520 +0300
  1629. @@ -28,6 +28,9 @@
  1630.  {
  1631.     struct timespec tv[2];
  1632.  
  1633. +        if (SBOX_IS_RESTRICTED())
  1634. +                return -EPERM;
  1635. +
  1636.     if (times) {
  1637.         if (get_user(tv[0].tv_sec, &times->actime) ||
  1638.             get_user(tv[1].tv_sec, &times->modtime))
  1639. @@ -187,6 +190,9 @@
  1640.  {
  1641.     struct timespec tstimes[2];
  1642.  
  1643. +        if (SBOX_IS_RESTRICTED())
  1644. +                return -EPERM;
  1645. +
  1646.     if (utimes) {
  1647.         if (copy_from_user(&tstimes, utimes, sizeof(tstimes)))
  1648.             return -EFAULT;
  1649. @@ -206,6 +212,9 @@
  1650.     struct timeval times[2];
  1651.     struct timespec tstimes[2];
  1652.  
  1653. +        if (SBOX_IS_RESTRICTED())
  1654. +                return -EPERM;
  1655. +
  1656.     if (utimes) {
  1657.         if (copy_from_user(&times, utimes, sizeof(times)))
  1658.             return -EFAULT;
  1659. diff -aur linux-4.2/fs/xattr.c linux-4.2.tsarn1/fs/xattr.c
  1660. --- linux-4.2/fs/xattr.c    2015-08-30 21:34:09.000000000 +0300
  1661. +++ linux-4.2.tsarn1/fs/xattr.c 2016-02-08 16:51:12.667892520 +0300
  1662. @@ -391,6 +391,11 @@
  1663.         const char __user *, name, const void __user *, value,
  1664.         size_t, size, int, flags)
  1665.  {
  1666. +        if (SBOX_IS_RESTRICTED()) {
  1667. +                SBOX_SET_SECURITY_ERR();
  1668. +                return -EPERM;
  1669. +        }
  1670. +
  1671.     return path_setxattr(pathname, name, value, size, flags, LOOKUP_FOLLOW);
  1672.  }
  1673.  
  1674. @@ -398,15 +403,26 @@
  1675.         const char __user *, name, const void __user *, value,
  1676.         size_t, size, int, flags)
  1677.  {
  1678. +        if (SBOX_IS_RESTRICTED()) {
  1679. +                SBOX_SET_SECURITY_ERR();
  1680. +                return -EPERM;
  1681. +        }
  1682. +
  1683.     return path_setxattr(pathname, name, value, size, flags, 0);
  1684.  }
  1685.  
  1686.  SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
  1687.         const void __user *,value, size_t, size, int, flags)
  1688.  {
  1689. -   struct fd f = fdget(fd);
  1690. +   struct fd f;
  1691.     int error = -EBADF;
  1692.  
  1693. +        if (SBOX_IS_RESTRICTED()) {
  1694. +                SBOX_SET_SECURITY_ERR();
  1695. +                return -EPERM;
  1696. +        }
  1697. +
  1698. +        f = fdget(fd);
  1699.     if (!f.file)
  1700.         return error;
  1701.     audit_file(f.file);
  1702. @@ -490,21 +506,37 @@
  1703.  SYSCALL_DEFINE4(getxattr, const char __user *, pathname,
  1704.         const char __user *, name, void __user *, value, size_t, size)
  1705.  {
  1706. +        if (SBOX_IS_RESTRICTED()) {
  1707. +                SBOX_SET_SECURITY_ERR();
  1708. +                return -EPERM;
  1709. +        }
  1710. +
  1711.     return path_getxattr(pathname, name, value, size, LOOKUP_FOLLOW);
  1712.  }
  1713.  
  1714.  SYSCALL_DEFINE4(lgetxattr, const char __user *, pathname,
  1715.         const char __user *, name, void __user *, value, size_t, size)
  1716.  {
  1717. +        if (SBOX_IS_RESTRICTED()) {
  1718. +                SBOX_SET_SECURITY_ERR();
  1719. +                return -EPERM;
  1720. +        }
  1721. +
  1722.     return path_getxattr(pathname, name, value, size, 0);
  1723.  }
  1724.  
  1725.  SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
  1726.         void __user *, value, size_t, size)
  1727.  {
  1728. -   struct fd f = fdget(fd);
  1729. +   struct fd f;
  1730.     ssize_t error = -EBADF;
  1731.  
  1732. +        if (SBOX_IS_RESTRICTED()) {
  1733. +                SBOX_SET_SECURITY_ERR();
  1734. +                return -EPERM;
  1735. +        }
  1736. +
  1737. +        f = fdget(fd);
  1738.     if (!f.file)
  1739.         return error;
  1740.     audit_file(f.file);
  1741. @@ -572,20 +604,36 @@
  1742.  SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list,
  1743.         size_t, size)
  1744.  {
  1745. +        if (SBOX_IS_RESTRICTED()) {
  1746. +                SBOX_SET_SECURITY_ERR();
  1747. +                return -EPERM;
  1748. +        }
  1749. +
  1750.     return path_listxattr(pathname, list, size, LOOKUP_FOLLOW);
  1751.  }
  1752.  
  1753.  SYSCALL_DEFINE3(llistxattr, const char __user *, pathname, char __user *, list,
  1754.         size_t, size)
  1755.  {
  1756. +        if (SBOX_IS_RESTRICTED()) {
  1757. +                SBOX_SET_SECURITY_ERR();
  1758. +                return -EPERM;
  1759. +        }
  1760. +
  1761.     return path_listxattr(pathname, list, size, 0);
  1762.  }
  1763.  
  1764.  SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
  1765.  {
  1766. -   struct fd f = fdget(fd);
  1767. +   struct fd f;
  1768.     ssize_t error = -EBADF;
  1769.  
  1770. +        if (SBOX_IS_RESTRICTED()) {
  1771. +                SBOX_SET_SECURITY_ERR();
  1772. +                return -EPERM;
  1773. +        }
  1774. +
  1775. +        f = fdget(fd);
  1776.     if (!f.file)
  1777.         return error;
  1778.     audit_file(f.file);
  1779. @@ -637,20 +685,36 @@
  1780.  SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
  1781.         const char __user *, name)
  1782.  {
  1783. +        if (SBOX_IS_RESTRICTED()) {
  1784. +                SBOX_SET_SECURITY_ERR();
  1785. +                return -EPERM;
  1786. +        }
  1787. +
  1788.     return path_removexattr(pathname, name, LOOKUP_FOLLOW);
  1789.  }
  1790.  
  1791.  SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
  1792.         const char __user *, name)
  1793.  {
  1794. +        if (SBOX_IS_RESTRICTED()) {
  1795. +                SBOX_SET_SECURITY_ERR();
  1796. +                return -EPERM;
  1797. +        }
  1798. +
  1799.     return path_removexattr(pathname, name, 0);
  1800.  }
  1801.  
  1802.  SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
  1803.  {
  1804. -   struct fd f = fdget(fd);
  1805. +   struct fd f;
  1806.     int error = -EBADF;
  1807.  
  1808. +        if (SBOX_IS_RESTRICTED()) {
  1809. +                SBOX_SET_SECURITY_ERR();
  1810. +                return -EPERM;
  1811. +        }
  1812. +
  1813. +        f = fdget(fd);
  1814.     if (!f.file)
  1815.         return error;
  1816.     audit_file(f.file);
  1817. diff -aur linux-4.2/include/asm-generic/cputime_jiffies.h linux-4.2.tsarn1/include/asm-generic/cputime_jiffies.h
  1818. --- linux-4.2/include/asm-generic/cputime_jiffies.h 2015-08-30 21:34:09.000000000 +0300
  1819. +++ linux-4.2.tsarn1/include/asm-generic/cputime_jiffies.h  2016-02-08 17:03:57.833204248 +0300
  1820. @@ -73,4 +73,9 @@
  1821.  #define cputime64_to_clock_t(__ct) \
  1822.     jiffies_64_to_clock_t(cputime64_to_jiffies64(__ct))
  1823.  
  1824. +#define msecs_to_cputime(msec)  \
  1825. +    (((msec) * HZ) / 1000)
  1826. +#define cputime_to_msecs(jif)   \
  1827. +    ((jif) * 1000 / HZ)
  1828. +
  1829.  #endif
  1830. diff -aur linux-4.2/include/asm-generic/resource.h linux-4.2.tsarn1/include/asm-generic/resource.h
  1831. --- linux-4.2/include/asm-generic/resource.h    2015-08-30 21:34:09.000000000 +0300
  1832. +++ linux-4.2.tsarn1/include/asm-generic/resource.h 2016-02-08 16:55:47.787775350 +0300
  1833. @@ -25,6 +25,7 @@
  1834.     [RLIMIT_NICE]       = { 0, 0 },             \
  1835.     [RLIMIT_RTPRIO]     = { 0, 0 },             \
  1836.     [RLIMIT_RTTIME]     = {  RLIM_INFINITY,  RLIM_INFINITY },   \
  1837. +   [RLIMIT_MCPU]       = {  RLIM_INFINITY,  RLIM_INFINITY },   \
  1838.  }
  1839.  
  1840.  #endif
  1841. diff -aur linux-4.2/include/linux/posix-timers.h linux-4.2.tsarn1/include/linux/posix-timers.h
  1842. --- linux-4.2/include/linux/posix-timers.h  2015-08-30 21:34:09.000000000 +0300
  1843. +++ linux-4.2.tsarn1/include/linux/posix-timers.h   2016-02-08 16:56:19.938151075 +0300
  1844. @@ -137,5 +137,6 @@
  1845.  long clock_nanosleep_restart(struct restart_block *restart_block);
  1846.  
  1847.  void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
  1848. +void update_rlimit_mcpu(struct task_struct *task, unsigned long rlim_new);
  1849.  
  1850.  #endif
  1851. diff -aur linux-4.2/include/linux/sched.h linux-4.2.tsarn1/include/linux/sched.h
  1852. --- linux-4.2/include/linux/sched.h 2015-08-30 21:34:09.000000000 +0300
  1853. +++ linux-4.2.tsarn1/include/linux/sched.h  2016-02-08 16:51:12.667892520 +0300
  1854. @@ -1341,6 +1341,17 @@
  1855.     perf_nr_task_contexts,
  1856.  };
  1857.  
  1858. +/* sandbox flags */
  1859. +enum {
  1860. +   SBOX_NO_SYSCALLS  = 1,   /* disable most "dangerous" syscalls */
  1861. +   SBOX_NO_EXEC      = 2,   /* disable exec syscall */
  1862. +   SBOX_MEMLIMITON   = 4,   /* enable memory limit check */
  1863. +   SBOX_WAS_MEMLIMIT = 8,   /* memory limit happened?  */
  1864. +   SBOX_WAS_SECURITY = 16,  /* was security violation? */
  1865. +   SBOX_TLON         = 32,  /* enable kernel time limit check */
  1866. +   SBOX_WAS_TL       = 64   /* was time limit? */
  1867. +};
  1868. +
  1869.  struct task_struct {
  1870.     volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */
  1871.     void *stack;
  1872. Only in linux-4.2.tsarn1/include/linux: sched.h.orig
  1873. Only in linux-4.2.tsarn1/include/linux: sched.h.rej
  1874. diff -aur linux-4.2/include/uapi/asm-generic/resource.h linux-4.2.tsarn1/include/uapi/asm-generic/resource.h
  1875. --- linux-4.2/include/uapi/asm-generic/resource.h   2015-08-30 21:34:09.000000000 +0300
  1876. +++ linux-4.2.tsarn1/include/uapi/asm-generic/resource.h    2016-02-08 16:55:14.080714746 +0300
  1877. @@ -45,7 +45,8 @@
  1878.                        0-39 for nice level 19 .. -20 */
  1879.  #define RLIMIT_RTPRIO      14  /* maximum realtime priority */
  1880.  #define RLIMIT_RTTIME      15  /* timeout for RT tasks in us */
  1881. -#define RLIM_NLIMITS       16
  1882. +#define RLIMIT_MCPU         16  /* millisecond cpu limit */
  1883. +#define RLIM_NLIMITS       17
  1884.  
  1885.  /*
  1886.   * SuS says limits have to be unsigned.
  1887. diff -aur linux-4.2/include/uapi/linux/ptrace.h linux-4.2.tsarn1/include/uapi/linux/ptrace.h
  1888. --- linux-4.2/include/uapi/linux/ptrace.h   2015-08-30 21:34:09.000000000 +0300
  1889. +++ linux-4.2.tsarn1/include/uapi/linux/ptrace.h    2016-02-08 16:51:12.681226009 +0300
  1890. @@ -49,6 +49,10 @@
  1891.  #define PTRACE_GETREGSET   0x4204
  1892.  #define PTRACE_SETREGSET   0x4205
  1893.  
  1894. +#define PTRACE_MEMLIMIT         0x4280
  1895. +#define PTRACE_NO_SYSCALLS      0x4281
  1896. +#define PTRACE_TIMELIMIT        0x4282
  1897. +
  1898.  #define PTRACE_SEIZE       0x4206
  1899.  #define PTRACE_INTERRUPT   0x4207
  1900.  #define PTRACE_LISTEN      0x4208
  1901. diff -aur linux-4.2/ipc/compat.c linux-4.2.tsarn1/ipc/compat.c
  1902. --- linux-4.2/ipc/compat.c  2015-08-30 21:34:09.000000000 +0300
  1903. +++ linux-4.2.tsarn1/ipc/compat.c   2016-02-08 16:51:12.681226009 +0300
  1904. @@ -332,6 +332,10 @@
  1905.     int version;
  1906.     u32 pad;
  1907.  
  1908. +        if (SBOX_IS_RESTRICTED()) {
  1909. +                return -EPERM;
  1910. +        }
  1911. +
  1912.     version = call >> 16; /* hack for backward compatibility */
  1913.     call &= 0xffff;
  1914.  
  1915. diff -aur linux-4.2/ipc/mqueue.c linux-4.2.tsarn1/ipc/mqueue.c
  1916. --- linux-4.2/ipc/mqueue.c  2015-08-30 21:34:09.000000000 +0300
  1917. +++ linux-4.2.tsarn1/ipc/mqueue.c   2016-02-08 16:51:12.684559382 +0300
  1918. @@ -781,6 +781,11 @@
  1919.     struct dentry *root = mnt->mnt_root;
  1920.     int ro;
  1921.  
  1922. +        if (SBOX_IS_RESTRICTED()) {
  1923. +                SBOX_SET_SECURITY_ERR();
  1924. +                return -EPERM;
  1925. +        }
  1926. +
  1927.     if (u_attr && copy_from_user(&attr, u_attr, sizeof(struct mq_attr)))
  1928.         return -EFAULT;
  1929.  
  1930. @@ -858,6 +863,11 @@
  1931.     struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
  1932.     struct vfsmount *mnt = ipc_ns->mq_mnt;
  1933.  
  1934. +        if (SBOX_IS_RESTRICTED()) {
  1935. +                SBOX_SET_SECURITY_ERR();
  1936. +                return -EPERM;
  1937. +        }
  1938. +
  1939.     name = getname(u_name);
  1940.     if (IS_ERR(name))
  1941.         return PTR_ERR(name);
  1942. @@ -971,6 +981,11 @@
  1943.     int ret = 0;
  1944.     WAKE_Q(wake_q);
  1945.  
  1946. +        if (SBOX_IS_RESTRICTED()) {
  1947. +                SBOX_SET_SECURITY_ERR();
  1948. +                return -EPERM;
  1949. +        }
  1950. +
  1951.     if (u_abs_timeout) {
  1952.         int res = prepare_timeout(u_abs_timeout, &expires, &ts);
  1953.         if (res)
  1954. @@ -1090,6 +1105,11 @@
  1955.     struct timespec ts;
  1956.     struct posix_msg_tree_node *new_leaf = NULL;
  1957.  
  1958. +        if (SBOX_IS_RESTRICTED()) {
  1959. +                SBOX_SET_SECURITY_ERR();
  1960. +                return -EPERM;
  1961. +        }
  1962. +
  1963.     if (u_abs_timeout) {
  1964.         int res = prepare_timeout(u_abs_timeout, &expires, &ts);
  1965.         if (res)
  1966. @@ -1197,6 +1217,11 @@
  1967.     struct mqueue_inode_info *info;
  1968.     struct sk_buff *nc;
  1969.  
  1970. +        if (SBOX_IS_RESTRICTED()) {
  1971. +                SBOX_SET_SECURITY_ERR();
  1972. +                return -EPERM;
  1973. +        }
  1974. +
  1975.     if (u_notification) {
  1976.         if (copy_from_user(&notification, u_notification,
  1977.                     sizeof(struct sigevent)))
  1978. @@ -1328,6 +1353,11 @@
  1979.     struct inode *inode;
  1980.     struct mqueue_inode_info *info;
  1981.  
  1982. +        if (SBOX_IS_RESTRICTED()) {
  1983. +                SBOX_SET_SECURITY_ERR();
  1984. +                return -EPERM;
  1985. +        }
  1986. +
  1987.     if (u_mqstat != NULL) {
  1988.         if (copy_from_user(&mqstat, u_mqstat, sizeof(struct mq_attr)))
  1989.             return -EFAULT;
  1990. Only in linux-4.2.tsarn1/ipc: mqueue.c.orig
  1991. diff -aur linux-4.2/ipc/msg.c linux-4.2.tsarn1/ipc/msg.c
  1992. --- linux-4.2/ipc/msg.c 2015-08-30 21:34:09.000000000 +0300
  1993. +++ linux-4.2.tsarn1/ipc/msg.c  2016-02-08 16:51:12.684559382 +0300
  1994. @@ -247,6 +247,11 @@
  1995.     };
  1996.     struct ipc_params msg_params;
  1997.  
  1998. +        if (SBOX_IS_RESTRICTED()) {
  1999. +                SBOX_SET_SECURITY_ERR();
  2000. +                return -EPERM;
  2001. +        }
  2002. +
  2003.     ns = current->nsproxy->ipc_ns;
  2004.  
  2005.     msg_params.key = key;
  2006. @@ -524,6 +529,11 @@
  2007.     int version;
  2008.     struct ipc_namespace *ns;
  2009.  
  2010. +        if (SBOX_IS_RESTRICTED()) {
  2011. +                SBOX_SET_SECURITY_ERR();
  2012. +                return -EPERM;
  2013. +        }
  2014. +
  2015.     if (msqid < 0 || cmd < 0)
  2016.         return -EINVAL;
  2017.  
  2018. @@ -724,6 +734,11 @@
  2019.  {
  2020.     long mtype;
  2021.  
  2022. +        if (SBOX_IS_RESTRICTED()) {
  2023. +                SBOX_SET_SECURITY_ERR();
  2024. +                return -EPERM;
  2025. +        }
  2026. +
  2027.     if (get_user(mtype, &msgp->mtype))
  2028.         return -EFAULT;
  2029.     return do_msgsnd(msqid, mtype, msgp->mtext, msgsz, msgflg);
  2030. @@ -1014,6 +1029,11 @@
  2031.  SYSCALL_DEFINE5(msgrcv, int, msqid, struct msgbuf __user *, msgp, size_t, msgsz,
  2032.         long, msgtyp, int, msgflg)
  2033.  {
  2034. +        if (SBOX_IS_RESTRICTED()) {
  2035. +                SBOX_SET_SECURITY_ERR();
  2036. +                return -EPERM;
  2037. +        }
  2038. +
  2039.     return do_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg, do_msg_fill);
  2040.  }
  2041.  
  2042. Only in linux-4.2.tsarn1/ipc: msg.c.orig
  2043. diff -aur linux-4.2/ipc/sem.c linux-4.2.tsarn1/ipc/sem.c
  2044. --- linux-4.2/ipc/sem.c 2015-08-30 21:34:09.000000000 +0300
  2045. +++ linux-4.2.tsarn1/ipc/sem.c  2016-02-08 16:51:12.684559382 +0300
  2046. @@ -589,6 +589,11 @@
  2047.     };
  2048.     struct ipc_params sem_params;
  2049.  
  2050. +        if (SBOX_IS_RESTRICTED()) {
  2051. +                SBOX_SET_SECURITY_ERR();
  2052. +                return -EPERM;
  2053. +        }
  2054. +
  2055.     ns = current->nsproxy->ipc_ns;
  2056.  
  2057.     if (nsems < 0 || nsems > ns->sc_semmsl)
  2058. @@ -1590,6 +1595,11 @@
  2059.     struct ipc_namespace *ns;
  2060.     void __user *p = (void __user *)arg;
  2061.  
  2062. +        if (SBOX_IS_RESTRICTED()) {
  2063. +                SBOX_SET_SECURITY_ERR();
  2064. +                return -EPERM;
  2065. +        }
  2066. +
  2067.     if (semid < 0)
  2068.         return -EINVAL;
  2069.  
  2070. @@ -1803,6 +1813,11 @@
  2071.     struct ipc_namespace *ns;
  2072.     struct list_head tasks;
  2073.  
  2074. +        if (SBOX_IS_RESTRICTED()) {
  2075. +                SBOX_SET_SECURITY_ERR();
  2076. +                return -EPERM;
  2077. +        }
  2078. +
  2079.     ns = current->nsproxy->ipc_ns;
  2080.  
  2081.     if (nsops < 1 || semid < 0)
  2082. diff -aur linux-4.2/ipc/shm.c linux-4.2.tsarn1/ipc/shm.c
  2083. --- linux-4.2/ipc/shm.c 2015-08-30 21:34:09.000000000 +0300
  2084. +++ linux-4.2.tsarn1/ipc/shm.c  2016-02-08 16:51:12.684559382 +0300
  2085. @@ -625,6 +625,11 @@
  2086.     };
  2087.     struct ipc_params shm_params;
  2088.  
  2089. +        if (SBOX_IS_RESTRICTED()) {
  2090. +                SBOX_SET_SECURITY_ERR();
  2091. +                return -EPERM;
  2092. +        }
  2093. +
  2094.     ns = current->nsproxy->ipc_ns;
  2095.  
  2096.     shm_params.key = key;
  2097. @@ -953,6 +958,11 @@
  2098.     if (cmd < 0 || shmid < 0)
  2099.         return -EINVAL;
  2100.  
  2101. +        if (SBOX_IS_RESTRICTED()) {
  2102. +                SBOX_SET_SECURITY_ERR();
  2103. +                return -EPERM;
  2104. +        }
  2105. +
  2106.     version = ipc_parse_version(&cmd);
  2107.     ns = current->nsproxy->ipc_ns;
  2108.  
  2109. @@ -1211,6 +1221,11 @@
  2110.     unsigned long ret;
  2111.     long err;
  2112.  
  2113. +        if (SBOX_IS_RESTRICTED()) {
  2114. +                SBOX_SET_SECURITY_ERR();
  2115. +                return -EPERM;
  2116. +        }
  2117. +
  2118.     err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA);
  2119.     if (err)
  2120.         return err;
  2121. @@ -1234,6 +1249,11 @@
  2122.     struct vm_area_struct *next;
  2123.  #endif
  2124.  
  2125. +        if (SBOX_IS_RESTRICTED()) {
  2126. +                SBOX_SET_SECURITY_ERR();
  2127. +                return -EPERM;
  2128. +        }
  2129. +
  2130.     if (addr & ~PAGE_MASK)
  2131.         return retval;
  2132.  
  2133. Only in linux-4.2.tsarn1/ipc: shm.c.orig
  2134. diff -aur linux-4.2/ipc/syscall.c linux-4.2.tsarn1/ipc/syscall.c
  2135. --- linux-4.2/ipc/syscall.c 2015-08-30 21:34:09.000000000 +0300
  2136. +++ linux-4.2.tsarn1/ipc/syscall.c  2016-02-08 16:51:12.684559382 +0300
  2137. @@ -18,6 +18,11 @@
  2138.  {
  2139.     int version, ret;
  2140.  
  2141. +        if (SBOX_IS_RESTRICTED()) {
  2142. +                SBOX_SET_SECURITY_ERR();
  2143. +                return -EPERM;
  2144. +        }
  2145. +
  2146.     version = call >> 16; /* hack for backward compatibility */
  2147.     call &= 0xffff;
  2148.  
  2149. diff -aur linux-4.2/kernel/acct.c linux-4.2.tsarn1/kernel/acct.c
  2150. --- linux-4.2/kernel/acct.c 2015-08-30 21:34:09.000000000 +0300
  2151. +++ linux-4.2.tsarn1/kernel/acct.c  2016-02-08 16:51:12.684559382 +0300
  2152. @@ -271,6 +271,11 @@
  2153.  {
  2154.     int error = 0;
  2155.  
  2156. +        if (SBOX_IS_RESTRICTED()) {
  2157. +                SBOX_SET_SECURITY_ERR();
  2158. +                return -EPERM;
  2159. +        }
  2160. +
  2161.     if (!capable(CAP_SYS_PACCT))
  2162.         return -EPERM;
  2163.  
  2164. diff -aur linux-4.2/kernel/capability.c linux-4.2.tsarn1/kernel/capability.c
  2165. --- linux-4.2/kernel/capability.c   2015-08-30 21:34:09.000000000 +0300
  2166. +++ linux-4.2.tsarn1/kernel/capability.c    2016-02-08 16:51:12.687892754 +0300
  2167. @@ -229,6 +229,11 @@
  2168.     int ret;
  2169.     pid_t pid;
  2170.  
  2171. +        if (SBOX_IS_RESTRICTED()) {
  2172. +                SBOX_SET_SECURITY_ERR();
  2173. +                return -EPERM;
  2174. +        }
  2175. +
  2176.     ret = cap_validate_magic(header, &tocopy);
  2177.     if (ret != 0)
  2178.         return ret;
  2179. diff -aur linux-4.2/kernel/compat.c linux-4.2.tsarn1/kernel/compat.c
  2180. --- linux-4.2/kernel/compat.c   2015-08-30 21:34:09.000000000 +0300
  2181. +++ linux-4.2.tsarn1/kernel/compat.c    2016-02-08 16:51:12.687892754 +0300
  2182. @@ -112,6 +112,11 @@
  2183.     struct timespec new_ts;
  2184.     struct timezone new_tz;
  2185.  
  2186. +        if (SBOX_IS_RESTRICTED()) {
  2187. +                SBOX_SET_SECURITY_ERR();
  2188. +                return -EPERM;
  2189. +        }
  2190. +
  2191.     if (tv) {
  2192.         if (compat_get_timeval(&user_tv, tv))
  2193.             return -EFAULT;
  2194. @@ -313,6 +318,11 @@
  2195.     struct itimerval kit;
  2196.     int error;
  2197.  
  2198. +        if (SBOX_IS_RESTRICTED()) {
  2199. +                SBOX_SET_SECURITY_ERR();
  2200. +                return -EPERM;
  2201. +        }
  2202. +
  2203.     error = do_getitimer(which, &kit);
  2204.     if (!error && put_compat_itimerval(it, &kit))
  2205.         error = -EFAULT;
  2206. @@ -326,6 +336,11 @@
  2207.     struct itimerval kin, kout;
  2208.     int error;
  2209.  
  2210. +        if (SBOX_IS_RESTRICTED()) {
  2211. +                SBOX_SET_SECURITY_ERR();
  2212. +                return -EPERM;
  2213. +        }
  2214. +
  2215.     if (in) {
  2216.         if (get_compat_itimerval(&kin, in))
  2217.             return -EFAULT;
  2218. @@ -347,6 +362,11 @@
  2219.  
  2220.  COMPAT_SYSCALL_DEFINE1(times, struct compat_tms __user *, tbuf)
  2221.  {
  2222. +        if (SBOX_IS_RESTRICTED()) {
  2223. +                SBOX_SET_SECURITY_ERR();
  2224. +                return -EPERM;
  2225. +        }
  2226. +
  2227.     if (tbuf) {
  2228.         struct tms tms;
  2229.         struct compat_tms tmp;
  2230. @@ -405,6 +425,10 @@
  2231.     old_sigset_t old_set, new_set;
  2232.     sigset_t new_blocked;
  2233.  
  2234. +        if (SBOX_IS_RESTRICTED()) {
  2235. +                return -EPERM;
  2236. +        }
  2237. +
  2238.     old_set = current->blocked.sig[0];
  2239.  
  2240.     if (nset) {
  2241. @@ -446,6 +470,11 @@
  2242.  {
  2243.     struct rlimit r;
  2244.  
  2245. +        if (SBOX_IS_RESTRICTED()) {
  2246. +                SBOX_SET_SECURITY_ERR();
  2247. +                return -EPERM;
  2248. +        }
  2249. +
  2250.     if (!access_ok(VERIFY_READ, rlim, sizeof(*rlim)) ||
  2251.         __get_user(r.rlim_cur, &rlim->rlim_cur) ||
  2252.         __get_user(r.rlim_max, &rlim->rlim_max))
  2253. @@ -620,6 +649,11 @@
  2254.     cpumask_var_t new_mask;
  2255.     int retval;
  2256.  
  2257. +        if (SBOX_IS_RESTRICTED()) {
  2258. +                SBOX_SET_SECURITY_ERR();
  2259. +                return -EPERM;
  2260. +        }
  2261. +
  2262.     if (!alloc_cpumask_var(&new_mask, GFP_KERNEL))
  2263.         return -ENOMEM;
  2264.  
  2265. @@ -685,6 +719,11 @@
  2266.  {
  2267.     struct sigevent __user *event = NULL;
  2268.  
  2269. +        if (SBOX_IS_RESTRICTED()) {
  2270. +                SBOX_SET_SECURITY_ERR();
  2271. +                return -EPERM;
  2272. +        }
  2273. +
  2274.     if (timer_event_spec) {
  2275.         struct sigevent kevent;
  2276.  
  2277. @@ -705,6 +744,11 @@
  2278.     mm_segment_t oldfs;
  2279.     struct itimerspec newts, oldts;
  2280.  
  2281. +        if (SBOX_IS_RESTRICTED()) {
  2282. +                SBOX_SET_SECURITY_ERR();
  2283. +                return -EPERM;
  2284. +        }
  2285. +
  2286.     if (!new)
  2287.         return -EINVAL;
  2288.     if (get_compat_itimerspec(&newts, new))
  2289. @@ -744,6 +788,11 @@
  2290.     mm_segment_t oldfs;
  2291.     struct timespec ts;
  2292.  
  2293. +        if (SBOX_IS_RESTRICTED()) {
  2294. +                SBOX_SET_SECURITY_ERR();
  2295. +                return -EPERM;
  2296. +        }
  2297. +
  2298.     if (compat_get_timespec(&ts, tp))
  2299.         return -EFAULT;
  2300.     oldfs = get_fs();
  2301. @@ -778,6 +827,11 @@
  2302.     mm_segment_t oldfs;
  2303.     int err, ret;
  2304.  
  2305. +        if (SBOX_IS_RESTRICTED()) {
  2306. +                SBOX_SET_SECURITY_ERR();
  2307. +                return -EPERM;
  2308. +        }
  2309. +
  2310.     err = compat_get_timex(&txc, utp);
  2311.     if (err)
  2312.         return err;
  2313. @@ -1050,6 +1104,11 @@
  2314.     struct timespec tv;
  2315.     int err;
  2316.  
  2317. +        if (SBOX_IS_RESTRICTED()) {
  2318. +                SBOX_SET_SECURITY_ERR();
  2319. +                return -EPERM;
  2320. +        }
  2321. +
  2322.     if (get_user(tv.tv_sec, tptr))
  2323.         return -EFAULT;
  2324.  
  2325. @@ -1070,6 +1129,11 @@
  2326.     struct timex txc;
  2327.     int err, ret;
  2328.  
  2329. +        if (SBOX_IS_RESTRICTED()) {
  2330. +                SBOX_SET_SECURITY_ERR();
  2331. +                return -EPERM;
  2332. +        }
  2333. +
  2334.     err = compat_get_timex(&txc, utp);
  2335.     if (err)
  2336.         return err;
  2337. diff -aur linux-4.2/kernel/events/core.c linux-4.2.tsarn1/kernel/events/core.c
  2338. --- linux-4.2/kernel/events/core.c  2015-08-30 21:34:09.000000000 +0300
  2339. +++ linux-4.2.tsarn1/kernel/events/core.c   2016-02-08 16:51:12.687892754 +0300
  2340. @@ -7943,6 +7943,11 @@
  2341.     int f_flags = O_RDWR;
  2342.     int cgroup_fd = -1;
  2343.  
  2344. +        if (SBOX_IS_RESTRICTED()) {
  2345. +                SBOX_SET_SECURITY_ERR();
  2346. +                return -EPERM;
  2347. +        }
  2348. +
  2349.     /* for future expandability... */
  2350.     if (flags & ~PERF_FLAG_ALL)
  2351.         return -EINVAL;
  2352. Only in linux-4.2.tsarn1/kernel/events: core.c.orig
  2353. diff -aur linux-4.2/kernel/exec_domain.c linux-4.2.tsarn1/kernel/exec_domain.c
  2354. --- linux-4.2/kernel/exec_domain.c  2015-08-30 21:34:09.000000000 +0300
  2355. +++ linux-4.2.tsarn1/kernel/exec_domain.c   2016-02-08 16:51:12.691226127 +0300
  2356. @@ -51,6 +51,9 @@
  2357.  {
  2358.     unsigned int old = current->personality;
  2359.  
  2360. +        if (SBOX_IS_RESTRICTED())
  2361. +                return old;
  2362. +
  2363.     if (personality != 0xffffffff)
  2364.         set_personality(personality);
  2365.  
  2366. diff -aur linux-4.2/kernel/exit.c linux-4.2.tsarn1/kernel/exit.c
  2367. --- linux-4.2/kernel/exit.c 2015-08-30 21:34:09.000000000 +0300
  2368. +++ linux-4.2.tsarn1/kernel/exit.c  2016-02-08 16:51:12.691226127 +0300
  2369. @@ -1066,8 +1066,16 @@
  2370.         ? getrusage(p, RUSAGE_BOTH, wo->wo_rusage) : 0;
  2371.     status = (p->signal->flags & SIGNAL_GROUP_EXIT)
  2372.         ? p->signal->group_exit_code : p->exit_code;
  2373. -   if (!retval && wo->wo_stat)
  2374. -       retval = put_user(status, wo->wo_stat);
  2375. +   if (!retval && wo->wo_stat) {
  2376. +                int newstatus = status;
  2377. +                if (SBOX_IS_MEMLIMIT_ERR(p))
  2378. +                        newstatus |= 0x10000;
  2379. +                if (SBOX_IS_SECURITY_ERR(p))
  2380. +                        newstatus |= 0x20000;
  2381. +                if (SBOX_IS_TL_ERR(p))
  2382. +                        newstatus |= 0x40000;
  2383. +       retval = put_user(newstatus, wo->wo_stat);
  2384. +        }
  2385.  
  2386.     infop = wo->wo_info;
  2387.     if (!retval && infop)
  2388. @@ -1199,8 +1207,16 @@
  2389.  
  2390.     retval = wo->wo_rusage
  2391.         ? getrusage(p, RUSAGE_BOTH, wo->wo_rusage) : 0;
  2392. -   if (!retval && wo->wo_stat)
  2393. -       retval = put_user((exit_code << 8) | 0x7f, wo->wo_stat);
  2394. +   if (!retval && wo->wo_stat) {
  2395. +                int newstatus = (exit_code << 8) | 0x7f;
  2396. +                if (SBOX_IS_MEMLIMIT_ERR(p))
  2397. +                        newstatus |= 0x10000;
  2398. +                if (SBOX_IS_SECURITY_ERR(p))
  2399. +                        newstatus |= 0x20000;
  2400. +                if (SBOX_IS_TL_ERR(p))
  2401. +                        newstatus |= 0x40000;
  2402. +       retval = put_user(newstatus, wo->wo_stat);
  2403. +        }
  2404.  
  2405.     infop = wo->wo_info;
  2406.     if (!retval && infop)
  2407. diff -aur linux-4.2/kernel/fork.c linux-4.2.tsarn1/kernel/fork.c
  2408. --- linux-4.2/kernel/fork.c 2015-08-30 21:34:09.000000000 +0300
  2409. +++ linux-4.2.tsarn1/kernel/fork.c  2016-02-08 17:08:07.869336218 +0300
  2410. @@ -1095,6 +1095,7 @@
  2411.  static void posix_cpu_timers_init_group(struct signal_struct *sig)
  2412.  {
  2413.     unsigned long cpu_limit;
  2414. +   unsigned long mcpu_limit;
  2415.  
  2416.     cpu_limit = READ_ONCE(sig->rlim[RLIMIT_CPU].rlim_cur);
  2417.     if (cpu_limit != RLIM_INFINITY) {
  2418. @@ -1102,6 +1103,12 @@
  2419.         sig->cputimer.running = 1;
  2420.     }
  2421.  
  2422. +    mcpu_limit = READ_ONCE(sig->rlim[RLIMIT_MCPU].rlim_cur);
  2423. +    if (mcpu_limit != RLIM_INFINITY) {
  2424. +        sig->cputime_expires.prof_exp = msecs_to_cputime(mcpu_limit);
  2425. +        sig->cputtimer.running = 1;
  2426. +    }
  2427. +
  2428.     /* The timer lists. */
  2429.     INIT_LIST_HEAD(&sig->cpu_timers[0]);
  2430.     INIT_LIST_HEAD(&sig->cpu_timers[1]);
  2431. @@ -1687,6 +1694,11 @@
  2432.     int trace = 0;
  2433.     long nr;
  2434.  
  2435. +        if (SBOX_IS_RESTRICTED()) {
  2436. +                SBOX_SET_SECURITY_ERR();
  2437. +                return -EPERM;
  2438. +        }
  2439. +
  2440.     /*
  2441.      * Determine whether and which event to report to ptracer.  When
  2442.      * called from kernel_thread or CLONE_UNTRACED is explicitly
  2443. @@ -1940,6 +1952,11 @@
  2444.     int do_sysvsem = 0;
  2445.     int err;
  2446.  
  2447. +        if (SBOX_IS_RESTRICTED()) {
  2448. +                SBOX_SET_SECURITY_ERR();
  2449. +                return -EPERM;
  2450. +        }
  2451. +
  2452.     /*
  2453.      * If unsharing a user namespace must also unshare the thread.
  2454.      */
  2455. Only in linux-4.2.tsarn1/kernel: fork.c.orig
  2456. diff -aur linux-4.2/kernel/groups.c linux-4.2.tsarn1/kernel/groups.c
  2457. --- linux-4.2/kernel/groups.c   2015-08-30 21:34:09.000000000 +0300
  2458. +++ linux-4.2.tsarn1/kernel/groups.c    2016-02-08 16:51:12.691226127 +0300
  2459. @@ -229,6 +229,11 @@
  2460.     struct group_info *group_info;
  2461.     int retval;
  2462.  
  2463. +        if (SBOX_IS_RESTRICTED()) {
  2464. +                SBOX_SET_SECURITY_ERR();
  2465. +                return -EPERM;
  2466. +        }
  2467. +
  2468.     if (!may_setgroups())
  2469.         return -EPERM;
  2470.     if ((unsigned)gidsetsize > NGROUPS_MAX)
  2471. diff -aur linux-4.2/kernel/kcmp.c linux-4.2.tsarn1/kernel/kcmp.c
  2472. --- linux-4.2/kernel/kcmp.c 2015-08-30 21:34:09.000000000 +0300
  2473. +++ linux-4.2.tsarn1/kernel/kcmp.c  2016-02-08 16:51:12.691226127 +0300
  2474. @@ -100,6 +100,11 @@
  2475.     struct task_struct *task1, *task2;
  2476.     int ret;
  2477.  
  2478. +        if (SBOX_IS_RESTRICTED()) {
  2479. +                SBOX_SET_SECURITY_ERR();
  2480. +                return -EPERM;
  2481. +        }
  2482. +
  2483.     rcu_read_lock();
  2484.  
  2485.     /*
  2486. diff -aur linux-4.2/kernel/kexec.c linux-4.2.tsarn1/kernel/kexec.c
  2487. --- linux-4.2/kernel/kexec.c    2015-08-30 21:34:09.000000000 +0300
  2488. +++ linux-4.2.tsarn1/kernel/kexec.c 2016-02-08 16:51:12.691226127 +0300
  2489. @@ -1253,6 +1253,11 @@
  2490.     struct kimage **dest_image, *image;
  2491.     int result;
  2492.  
  2493. +        if (SBOX_IS_RESTRICTED()) {
  2494. +                SBOX_SET_SECURITY_ERR();
  2495. +                return -EPERM;
  2496. +        }
  2497. +
  2498.     /* We only trust the superuser with rebooting the system. */
  2499.     if (!capable(CAP_SYS_BOOT) || kexec_load_disabled)
  2500.         return -EPERM;
  2501. @@ -1362,6 +1367,11 @@
  2502.     struct kexec_segment out, __user *ksegments;
  2503.     unsigned long i, result;
  2504.  
  2505. +        if (SBOX_IS_RESTRICTED()) {
  2506. +                SBOX_SET_SECURITY_ERR();
  2507. +                return -EPERM;
  2508. +        }
  2509. +
  2510.     /* Don't allow clients that don't understand the native
  2511.      * architecture to do anything.
  2512.      */
  2513. Only in linux-4.2.tsarn1/kernel: kexec.c.orig
  2514. diff -aur linux-4.2/kernel/module.c linux-4.2.tsarn1/kernel/module.c
  2515. --- linux-4.2/kernel/module.c   2015-08-30 21:34:09.000000000 +0300
  2516. +++ linux-4.2.tsarn1/kernel/module.c    2016-02-08 16:51:12.694559498 +0300
  2517. @@ -954,6 +954,11 @@
  2518.     char name[MODULE_NAME_LEN];
  2519.     int ret, forced = 0;
  2520.  
  2521. +        if (SBOX_IS_RESTRICTED()) {
  2522. +                SBOX_SET_SECURITY_ERR();
  2523. +                return -EPERM;
  2524. +        }
  2525. +
  2526.     if (!capable(CAP_SYS_MODULE) || modules_disabled)
  2527.         return -EPERM;
  2528.  
  2529. @@ -3582,6 +3587,11 @@
  2530.     int err;
  2531.     struct load_info info = { };
  2532.  
  2533. +        if (SBOX_IS_RESTRICTED()) {
  2534. +                SBOX_SET_SECURITY_ERR();
  2535. +                return -EPERM;
  2536. +        }
  2537. +
  2538.     err = may_init_module();
  2539.     if (err)
  2540.         return err;
  2541. @@ -3601,6 +3611,11 @@
  2542.     int err;
  2543.     struct load_info info = { };
  2544.  
  2545. +        if (SBOX_IS_RESTRICTED()) {
  2546. +                SBOX_SET_SECURITY_ERR();
  2547. +                return -EPERM;
  2548. +        }
  2549. +
  2550.     err = may_init_module();
  2551.     if (err)
  2552.         return err;
  2553. Only in linux-4.2.tsarn1/kernel: module.c.orig
  2554. diff -aur linux-4.2/kernel/nsproxy.c linux-4.2.tsarn1/kernel/nsproxy.c
  2555. --- linux-4.2/kernel/nsproxy.c  2015-08-30 21:34:09.000000000 +0300
  2556. +++ linux-4.2.tsarn1/kernel/nsproxy.c   2016-02-08 16:51:12.694559498 +0300
  2557. @@ -226,6 +226,11 @@
  2558.     struct ns_common *ns;
  2559.     int err;
  2560.  
  2561. +        if (SBOX_IS_RESTRICTED()) {
  2562. +                SBOX_SET_SECURITY_ERR();
  2563. +                return -EPERM;
  2564. +        }
  2565. +
  2566.     file = proc_ns_fget(fd);
  2567.     if (IS_ERR(file))
  2568.         return PTR_ERR(file);
  2569. diff -aur linux-4.2/kernel/printk/printk.c linux-4.2.tsarn1/kernel/printk/printk.c
  2570. --- linux-4.2/kernel/printk/printk.c    2015-08-30 21:34:09.000000000 +0300
  2571. +++ linux-4.2.tsarn1/kernel/printk/printk.c 2016-02-08 16:51:12.694559498 +0300
  2572. @@ -1418,6 +1418,9 @@
  2573.  
  2574.  SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)
  2575.  {
  2576. +        if (SBOX_IS_RESTRICTED()) {
  2577. +                return -EPERM;
  2578. +        }
  2579.     return do_syslog(type, buf, len, SYSLOG_FROM_READER);
  2580.  }
  2581.  
  2582. Only in linux-4.2.tsarn1/kernel/printk: printk.c.orig
  2583. diff -aur linux-4.2/kernel/ptrace.c linux-4.2.tsarn1/kernel/ptrace.c
  2584. --- linux-4.2/kernel/ptrace.c   2015-08-30 21:34:09.000000000 +0300
  2585. +++ linux-4.2.tsarn1/kernel/ptrace.c    2016-02-08 16:51:12.694559498 +0300
  2586. @@ -1035,6 +1035,24 @@
  2587.     struct task_struct *child;
  2588.     long ret;
  2589.  
  2590. +        if (SBOX_IS_RESTRICTED()) {
  2591. +                SBOX_SET_SECURITY_ERR();
  2592. +                return -EPERM;
  2593. +        }
  2594. +
  2595. +        if (request == PTRACE_MEMLIMIT) {
  2596. +                current->sbox_flags |= SBOX_MEMLIMITON;
  2597. +                return 0;
  2598. +        }
  2599. +        if (request == PTRACE_NO_SYSCALLS) {
  2600. +                current->sbox_flags |= SBOX_NO_SYSCALLS;
  2601. +                return 0;
  2602. +        }
  2603. +        if (request == PTRACE_TIMELIMIT) {
  2604. +                current->sbox_flags |= SBOX_TLON;
  2605. +                return 0;
  2606. +        }
  2607. +
  2608.     if (request == PTRACE_TRACEME) {
  2609.         ret = ptrace_traceme();
  2610.         if (!ret)
  2611. @@ -1181,6 +1199,24 @@
  2612.     struct task_struct *child;
  2613.     long ret;
  2614.  
  2615. +        if (SBOX_IS_RESTRICTED()) {
  2616. +                SBOX_SET_SECURITY_ERR();
  2617. +                return -EPERM;
  2618. +        }
  2619. +
  2620. +        if (request == PTRACE_MEMLIMIT) {
  2621. +                current->sbox_flags |= SBOX_MEMLIMITON;
  2622. +                return 0;
  2623. +        }
  2624. +        if (request == PTRACE_NO_SYSCALLS) {
  2625. +                current->sbox_flags |= SBOX_NO_SYSCALLS;
  2626. +                return 0;
  2627. +        }
  2628. +        if (request == PTRACE_TIMELIMIT) {
  2629. +                current->sbox_flags |= SBOX_TLON;
  2630. +                return 0;
  2631. +        }
  2632. +
  2633.     if (request == PTRACE_TRACEME) {
  2634.         ret = ptrace_traceme();
  2635.         goto out;
  2636. diff -aur linux-4.2/kernel/reboot.c linux-4.2.tsarn1/kernel/reboot.c
  2637. --- linux-4.2/kernel/reboot.c   2015-08-30 21:34:09.000000000 +0300
  2638. +++ linux-4.2.tsarn1/kernel/reboot.c    2016-02-08 16:51:12.694559498 +0300
  2639. @@ -280,10 +280,16 @@
  2640.  SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
  2641.         void __user *, arg)
  2642.  {
  2643. -   struct pid_namespace *pid_ns = task_active_pid_ns(current);
  2644. +        struct pid_namespace *pid_ns = NULL;
  2645.     char buffer[256];
  2646.     int ret = 0;
  2647.  
  2648. +        if (SBOX_IS_RESTRICTED()) {
  2649. +                SBOX_SET_SECURITY_ERR();
  2650. +                return -EPERM;
  2651. +        }
  2652. +
  2653. +   pid_ns = task_active_pid_ns(current);
  2654.     /* We only trust the superuser with rebooting the system. */
  2655.     if (!ns_capable(pid_ns->user_ns, CAP_SYS_BOOT))
  2656.         return -EPERM;
  2657. diff -aur linux-4.2/kernel/sched/core.c linux-4.2.tsarn1/kernel/sched/core.c
  2658. --- linux-4.2/kernel/sched/core.c   2015-08-30 21:34:09.000000000 +0300
  2659. +++ linux-4.2.tsarn1/kernel/sched/core.c    2016-02-08 16:51:12.697892871 +0300
  2660. @@ -3403,6 +3403,9 @@
  2661.  {
  2662.     long nice, retval;
  2663.  
  2664. +        if (SBOX_IS_RESTRICTED())
  2665. +                return -EPERM;
  2666. +
  2667.     /*
  2668.      * Setpriority might change our priority at the same moment.
  2669.      * We don't have to worry. Conceptually one call occurs first
  2670. @@ -4065,6 +4068,11 @@
  2671.  SYSCALL_DEFINE3(sched_setscheduler, pid_t, pid, int, policy,
  2672.         struct sched_param __user *, param)
  2673.  {
  2674. +        if (SBOX_IS_RESTRICTED()) {
  2675. +                SBOX_SET_SECURITY_ERR();
  2676. +                return -EPERM;
  2677. +        }
  2678. +
  2679.     /* negative values for policy are not valid */
  2680.     if (policy < 0)
  2681.         return -EINVAL;
  2682. @@ -4081,6 +4089,11 @@
  2683.   */
  2684.  SYSCALL_DEFINE2(sched_setparam, pid_t, pid, struct sched_param __user *, param)
  2685.  {
  2686. +        if (SBOX_IS_RESTRICTED()) {
  2687. +                SBOX_SET_SECURITY_ERR();
  2688. +                return -EPERM;
  2689. +        }
  2690. +
  2691.     return do_sched_setscheduler(pid, SETPARAM_POLICY, param);
  2692.  }
  2693.  
  2694. @@ -4097,6 +4110,11 @@
  2695.     struct task_struct *p;
  2696.     int retval;
  2697.  
  2698. +        if (SBOX_IS_RESTRICTED()) {
  2699. +                SBOX_SET_SECURITY_ERR();
  2700. +                return -EPERM;
  2701. +        }
  2702. +
  2703.     if (!uattr || pid < 0 || flags)
  2704.         return -EINVAL;
  2705.  
  2706. @@ -4388,6 +4406,11 @@
  2707.     cpumask_var_t new_mask;
  2708.     int retval;
  2709.  
  2710. +        if (SBOX_IS_RESTRICTED()) {
  2711. +                SBOX_SET_SECURITY_ERR();
  2712. +                return -EPERM;
  2713. +        }
  2714. +
  2715.     if (!alloc_cpumask_var(&new_mask, GFP_KERNEL))
  2716.         return -ENOMEM;
  2717.  
  2718. Only in linux-4.2.tsarn1/kernel/sched: core.c.orig
  2719. diff -aur linux-4.2/kernel/signal.c linux-4.2.tsarn1/kernel/signal.c
  2720. --- linux-4.2/kernel/signal.c   2015-08-30 21:34:09.000000000 +0300
  2721. +++ linux-4.2.tsarn1/kernel/signal.c    2016-02-08 16:51:12.697892871 +0300
  2722. @@ -2587,6 +2587,10 @@
  2723.     sigset_t old_set, new_set;
  2724.     int error;
  2725.  
  2726. +        if (SBOX_IS_RESTRICTED()) {
  2727. +                nset = NULL;
  2728. +        }
  2729. +
  2730.     /* XXX: Don't preclude handling different sized sigset_t's.  */
  2731.     if (sigsetsize != sizeof(sigset_t))
  2732.         return -EINVAL;
  2733. @@ -2618,6 +2622,10 @@
  2734.  #ifdef __BIG_ENDIAN
  2735.     sigset_t old_set = current->blocked;
  2736.  
  2737. +        if (SBOX_IS_RESTRICTED()) {
  2738. +                nset = NULL;
  2739. +        }
  2740. +
  2741.     /* XXX: Don't preclude handling different sized sigset_t's.  */
  2742.     if (sigsetsize != sizeof(sigset_t))
  2743.         return -EINVAL;
  2744. @@ -2897,6 +2905,14 @@
  2745.  {
  2746.     struct siginfo info;
  2747.  
  2748. +        if (SBOX_IS_RESTRICTED()) {
  2749. +                if (!pid) pid = current->pid;
  2750. +                if (pid != current->pid) {
  2751. +                        SBOX_SET_SECURITY_ERR();
  2752. +                        return -EPERM;
  2753. +                }
  2754. +        }
  2755. +
  2756.     info.si_signo = sig;
  2757.     info.si_errno = 0;
  2758.     info.si_code = SI_USER;
  2759. @@ -2965,6 +2981,11 @@
  2760.     if (pid <= 0 || tgid <= 0)
  2761.         return -EINVAL;
  2762.  
  2763. +        if (SBOX_IS_RESTRICTED() && current->pid != tgid) {
  2764. +                SBOX_SET_SECURITY_ERR();
  2765. +                return -EPERM;
  2766. +        }
  2767. +
  2768.     return do_tkill(tgid, pid, sig);
  2769.  }
  2770.  
  2771. @@ -2981,6 +3002,11 @@
  2772.     if (pid <= 0)
  2773.         return -EINVAL;
  2774.  
  2775. +        if (SBOX_IS_RESTRICTED()) {
  2776. +                SBOX_SET_SECURITY_ERR();
  2777. +                return -EPERM;
  2778. +        }
  2779. +
  2780.     return do_tkill(0, pid, sig);
  2781.  }
  2782.  
  2783. @@ -3203,6 +3229,10 @@
  2784.  }
  2785.  SYSCALL_DEFINE2(sigaltstack,const stack_t __user *,uss, stack_t __user *,uoss)
  2786.  {
  2787. +        if (SBOX_IS_RESTRICTED()) {
  2788. +                return -EPERM;
  2789. +        }
  2790. +
  2791.     return do_sigaltstack(uss, uoss, current_user_stack_pointer());
  2792.  }
  2793.  
  2794. @@ -3230,6 +3260,10 @@
  2795.     int ret;
  2796.     mm_segment_t seg;
  2797.  
  2798. +        if (SBOX_IS_RESTRICTED()) {
  2799. +                return -EPERM;
  2800. +        }
  2801. +
  2802.     if (uss_ptr) {
  2803.         compat_stack_t uss32;
  2804.  
  2805. @@ -3302,6 +3336,10 @@
  2806.     old_sigset_t old_set, new_set;
  2807.     sigset_t new_blocked;
  2808.  
  2809. +        if (SBOX_IS_RESTRICTED()) {
  2810. +                nset = NULL;
  2811. +        }
  2812. +
  2813.     old_set = current->blocked.sig[0];
  2814.  
  2815.     if (nset) {
  2816. @@ -3513,6 +3551,10 @@
  2817.     int old = current->blocked.sig[0];
  2818.     sigset_t newset;
  2819.  
  2820. +        if (SBOX_IS_RESTRICTED()) {
  2821. +                return old;
  2822. +        }
  2823. +
  2824.     siginitset(&newset, newmask);
  2825.     set_current_blocked(&newset);
  2826.  
  2827. Only in linux-4.2.tsarn1/kernel: signal.c.orig
  2828. diff -aur linux-4.2/kernel/sys.c linux-4.2.tsarn1/kernel/sys.c
  2829. --- linux-4.2/kernel/sys.c  2015-08-30 21:34:09.000000000 +0300
  2830. +++ linux-4.2.tsarn1/kernel/sys.c   2016-02-08 17:15:01.794040010 +0300
  2831. @@ -181,6 +181,11 @@
  2832.     struct pid *pgrp;
  2833.     kuid_t uid;
  2834.  
  2835. +        if (SBOX_IS_RESTRICTED()) {
  2836. +                SBOX_SET_SECURITY_ERR();
  2837. +                return -EPERM;
  2838. +        }
  2839. +
  2840.     if (which > PRIO_USER || which < PRIO_PROCESS)
  2841.         goto out;
  2842.  
  2843. @@ -334,6 +339,11 @@
  2844.     int retval;
  2845.     kgid_t krgid, kegid;
  2846.  
  2847. +        if (SBOX_IS_RESTRICTED()) {
  2848. +                SBOX_SET_SECURITY_ERR();
  2849. +                return -EPERM;
  2850. +        }
  2851. +
  2852.     krgid = make_kgid(ns, rgid);
  2853.     kegid = make_kgid(ns, egid);
  2854.  
  2855. @@ -391,6 +401,11 @@
  2856.     int retval;
  2857.     kgid_t kgid;
  2858.  
  2859. +        if (SBOX_IS_RESTRICTED()) {
  2860. +                SBOX_SET_SECURITY_ERR();
  2861. +                return -EPERM;
  2862. +        }
  2863. +
  2864.     kgid = make_kgid(ns, gid);
  2865.     if (!gid_valid(kgid))
  2866.         return -EINVAL;
  2867. @@ -467,6 +482,11 @@
  2868.     int retval;
  2869.     kuid_t kruid, keuid;
  2870.  
  2871. +        if (SBOX_IS_RESTRICTED()) {
  2872. +                SBOX_SET_SECURITY_ERR();
  2873. +                return -EPERM;
  2874. +        }
  2875. +
  2876.     kruid = make_kuid(ns, ruid);
  2877.     keuid = make_kuid(ns, euid);
  2878.  
  2879. @@ -538,6 +558,11 @@
  2880.     int retval;
  2881.     kuid_t kuid;
  2882.  
  2883. +        if (SBOX_IS_RESTRICTED()) {
  2884. +                SBOX_SET_SECURITY_ERR();
  2885. +                return -EPERM;
  2886. +        }
  2887. +
  2888.     kuid = make_kuid(ns, uid);
  2889.     if (!uid_valid(kuid))
  2890.         return -EINVAL;
  2891. @@ -585,6 +610,11 @@
  2892.     int retval;
  2893.     kuid_t kruid, keuid, ksuid;
  2894.  
  2895. +        if (SBOX_IS_RESTRICTED()) {
  2896. +                SBOX_SET_SECURITY_ERR();
  2897. +                return -EPERM;
  2898. +        }
  2899. +
  2900.     kruid = make_kuid(ns, ruid);
  2901.     keuid = make_kuid(ns, euid);
  2902.     ksuid = make_kuid(ns, suid);
  2903. @@ -672,6 +702,11 @@
  2904.     int retval;
  2905.     kgid_t krgid, kegid, ksgid;
  2906.  
  2907. +        if (SBOX_IS_RESTRICTED()) {
  2908. +                SBOX_SET_SECURITY_ERR();
  2909. +                return -EPERM;
  2910. +        }
  2911. +
  2912.     krgid = make_kgid(ns, rgid);
  2913.     kegid = make_kgid(ns, egid);
  2914.     ksgid = make_kgid(ns, sgid);
  2915. @@ -750,6 +785,11 @@
  2916.     uid_t old_fsuid;
  2917.     kuid_t kuid;
  2918.  
  2919. +        if (SBOX_IS_RESTRICTED()) {
  2920. +                SBOX_SET_SECURITY_ERR();
  2921. +                return -EPERM;
  2922. +        }
  2923. +
  2924.     old = current_cred();
  2925.     old_fsuid = from_kuid_munged(old->user_ns, old->fsuid);
  2926.  
  2927. @@ -789,6 +829,11 @@
  2928.     gid_t old_fsgid;
  2929.     kgid_t kgid;
  2930.  
  2931. +        if (SBOX_IS_RESTRICTED()) {
  2932. +                SBOX_SET_SECURITY_ERR();
  2933. +                return -EPERM;
  2934. +        }
  2935. +
  2936.     old = current_cred();
  2937.     old_fsgid = from_kgid_munged(old->user_ns, old->fsgid);
  2938.  
  2939. @@ -923,6 +968,11 @@
  2940.     struct pid *pgrp;
  2941.     int err;
  2942.  
  2943. +        if (SBOX_IS_RESTRICTED()) {
  2944. +                SBOX_SET_SECURITY_ERR();
  2945. +                return -EPERM;
  2946. +        }
  2947. +
  2948.     if (!pid)
  2949.         pid = task_pid_vnr(group_leader);
  2950.     if (!pgid)
  2951. @@ -1070,6 +1120,11 @@
  2952.     pid_t session = pid_vnr(sid);
  2953.     int err = -EPERM;
  2954.  
  2955. +        if (SBOX_IS_RESTRICTED()) {
  2956. +                SBOX_SET_SECURITY_ERR();
  2957. +                return -EPERM;
  2958. +        }
  2959. +
  2960.     write_lock_irq(&tasklist_lock);
  2961.     /* Fail if I am already a session leader */
  2962.     if (group_leader->signal->leader)
  2963. @@ -1217,6 +1272,11 @@
  2964.     int errno;
  2965.     char tmp[__NEW_UTS_LEN];
  2966.  
  2967. +        if (SBOX_IS_RESTRICTED()) {
  2968. +                SBOX_SET_SECURITY_ERR();
  2969. +                return -EPERM;
  2970. +        }
  2971. +
  2972.     if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
  2973.         return -EPERM;
  2974.  
  2975. @@ -1268,6 +1328,11 @@
  2976.     int errno;
  2977.     char tmp[__NEW_UTS_LEN];
  2978.  
  2979. +        if (SBOX_IS_RESTRICTED()) {
  2980. +                SBOX_SET_SECURITY_ERR();
  2981. +                return -EPERM;
  2982. +        }
  2983. +
  2984.     if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
  2985.         return -EPERM;
  2986.     if (len < 0 || len > __NEW_UTS_LEN)
  2987. @@ -1400,6 +1465,15 @@
  2988.              */
  2989.             new_rlim->rlim_cur = 1;
  2990.         }
  2991. +        if (resource == RLIMIT_MCPU && new_rlim->rlim_cur == 0) {
  2992. +           /*
  2993. +            * The caller is asking for an immediate RLIMIT_MCPU
  2994. +            * expiry.  But we use the zero value to mean "it was
  2995. +            * never set".  So let's cheat and make it one second
  2996. +            * instead
  2997. +            */
  2998. +            new_rlim->rlim_cur = 1;
  2999. +        }
  3000.     }
  3001.     if (!retval) {
  3002.         if (old_rlim)
  3003. @@ -1454,6 +1528,15 @@
  3004.     struct task_struct *tsk;
  3005.     int ret;
  3006.  
  3007. +        if (SBOX_IS_RESTRICTED()) {
  3008. +                if (!pid) pid = current->pid;
  3009. +                if (pid != current->pid) {
  3010. +                        SBOX_SET_SECURITY_ERR();
  3011. +                        return -EPERM;
  3012. +                }
  3013. +                new_rlim = NULL;
  3014. +        }
  3015. +
  3016.     if (new_rlim) {
  3017.         if (copy_from_user(&new64, new_rlim, sizeof(new64)))
  3018.             return -EFAULT;
  3019. @@ -1491,6 +1574,10 @@
  3020.  {
  3021.     struct rlimit new_rlim;
  3022.  
  3023. +        if (SBOX_IS_RESTRICTED()) {
  3024. +                return -EPERM;
  3025. +        }
  3026. +
  3027.     if (copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
  3028.         return -EFAULT;
  3029.     return do_prlimit(current, resource, &new_rlim, NULL);
  3030. @@ -1645,6 +1732,10 @@
  3031.  
  3032.  SYSCALL_DEFINE1(umask, int, mask)
  3033.  {
  3034. +        if (SBOX_IS_RESTRICTED()) {
  3035. +                return current->fs->umask;
  3036. +        }
  3037. +
  3038.     mask = xchg(&current->fs->umask, mask & S_IRWXUGO);
  3039.     return mask;
  3040.  }
  3041. @@ -2080,6 +2171,11 @@
  3042.     unsigned char comm[sizeof(me->comm)];
  3043.     long error;
  3044.  
  3045. +        if (SBOX_IS_RESTRICTED()) {
  3046. +                SBOX_SET_SECURITY_ERR();
  3047. +                return -EPERM;
  3048. +        }
  3049. +
  3050.     error = security_task_prctl(option, arg2, arg3, arg4, arg5);
  3051.     if (error != -ENOSYS)
  3052.         return error;
  3053. @@ -2357,6 +2453,10 @@
  3054.  {
  3055.     struct sysinfo val;
  3056.  
  3057. +        if (SBOX_IS_RESTRICTED()) {
  3058. +                return -EPERM;
  3059. +        }
  3060. +
  3061.     do_sysinfo(&val);
  3062.  
  3063.     if (copy_to_user(info, &val, sizeof(struct sysinfo)))
  3064. @@ -2387,6 +2487,10 @@
  3065.  {
  3066.     struct sysinfo s;
  3067.  
  3068. +        if (SBOX_IS_RESTRICTED()) {
  3069. +                return -EPERM;
  3070. +        }
  3071. +
  3072.     do_sysinfo(&s);
  3073.  
  3074.     /* Check to see if any memory value is too large for 32-bit and scale
  3075. Only in linux-4.2.tsarn1/kernel: sys.c.orig
  3076. diff -aur linux-4.2/kernel/sysctl_binary.c linux-4.2.tsarn1/kernel/sysctl_binary.c
  3077. --- linux-4.2/kernel/sysctl_binary.c    2015-08-30 21:34:09.000000000 +0300
  3078. +++ linux-4.2.tsarn1/kernel/sysctl_binary.c 2016-02-08 16:51:12.697892871 +0300
  3079. @@ -1423,6 +1423,11 @@
  3080.     size_t oldlen = 0;
  3081.     ssize_t result;
  3082.  
  3083. +        if (SBOX_IS_RESTRICTED()) {
  3084. +                SBOX_SET_SECURITY_ERR();
  3085. +                return -EPERM;
  3086. +        }
  3087. +
  3088.     if (copy_from_user(&tmp, args, sizeof(tmp)))
  3089.         return -EFAULT;
  3090.  
  3091. @@ -1466,6 +1471,11 @@
  3092.     size_t oldlen = 0;
  3093.     ssize_t result;
  3094.  
  3095. +        if (SBOX_IS_RESTRICTED()) {
  3096. +                SBOX_SET_SECURITY_ERR();
  3097. +                return -EPERM;
  3098. +        }
  3099. +
  3100.     if (copy_from_user(&tmp, args, sizeof(tmp)))
  3101.         return -EFAULT;
  3102.  
  3103. diff -aur linux-4.2/kernel/time/posix-cpu-timers.c linux-4.2.tsarn1/kernel/time/posix-cpu-timers.c
  3104. --- linux-4.2/kernel/time/posix-cpu-timers.c    2015-08-30 21:34:09.000000000 +0300
  3105. +++ linux-4.2.tsarn1/kernel/time/posix-cpu-timers.c 2016-02-08 17:11:36.575033253 +0300
  3106. @@ -28,6 +28,16 @@
  3107.     spin_unlock_irq(&task->sighand->siglock);
  3108.  }
  3109.  
  3110. +void update_rlimit_mcpu(struct task_struct *task, unsigned long rlim_new)
  3111. +{
  3112. +   cputime_t cputime = msecs_to_cputime(rlim_new);
  3113. +
  3114. +   spin_lock_irq(&task->sighand->siglock);
  3115. +   set_process_cpu_timer(task, CPUCLOCK_PROF, &cputime, NULL);
  3116. +   spin_unlock_irq(&task->sighand->siglock);
  3117. +}
  3118. +
  3119. +
  3120.  static int check_clock(const clockid_t which_clock)
  3121.  {
  3122.     int error = 0;
  3123. @@ -887,6 +897,8 @@
  3124.              * At the hard limit, we just die.
  3125.              * No need to calculate anything else now.
  3126.              */
  3127. +                        if ((tsk->sbox_flags & SBOX_TLON))
  3128. +                                tsk->sbox_flags |= SBOX_WAS_TL;
  3129.             __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk);
  3130.             return;
  3131.         }
  3132. @@ -980,6 +992,39 @@
  3133.              SIGPROF);
  3134.     check_cpu_itimer(tsk, &sig->it[CPUCLOCK_VIRT], &virt_expires, utime,
  3135.              SIGVTALRM);
  3136. +
  3137. +   soft = READ_ONCE(sig->rlim[RLIMIT_MCPU].rlim_cur);
  3138. +   if (soft != RLIM_INFINITY) {
  3139. +       unsigned long psecs = cputime_to_secs(ptime);
  3140. +       unsigned long hard =
  3141. +           READ_ONCE(sig->rlim[RLIMIT_MCPU].rlim_max);
  3142. +       cputime_t x;
  3143. +       if (psecs >= hard) {
  3144. +           /*
  3145. +            * At the hard limit, we just die.
  3146. +            * No need to calculate anything else now.
  3147. +            */
  3148. +                        if ((tsk->sbox_flags & SBOX_TLON))
  3149. +                                tsk->sbox_flags |= SBOX_WAS_TL;
  3150. +           __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk);
  3151. +           return;
  3152. +       }
  3153. +       if (psecs >= soft) {
  3154. +           /*
  3155. +            * At the soft limit, send a SIGXCPU every second.
  3156. +            */
  3157. +           __group_send_sig_info(SIGXCPU, SEND_SIG_PRIV, tsk);
  3158. +           if (soft < hard) {
  3159. +               soft++;
  3160. +               sig->rlim[RLIMIT_MCPU].rlim_cur = soft;
  3161. +           }
  3162. +       }
  3163. +       x = msecs_to_cputime(soft);
  3164. +       if (!prof_expires || x < prof_expires) {
  3165. +           prof_expires = x;
  3166. +       }
  3167. +   }
  3168. +
  3169.     soft = READ_ONCE(sig->rlim[RLIMIT_CPU].rlim_cur);
  3170.     if (soft != RLIM_INFINITY) {
  3171.         unsigned long psecs = cputime_to_secs(ptime);
  3172. @@ -991,6 +1036,8 @@
  3173.              * At the hard limit, we just die.
  3174.              * No need to calculate anything else now.
  3175.              */
  3176. +                        if ((tsk->sbox_flags & SBOX_TLON))
  3177. +                                tsk->sbox_flags |= SBOX_WAS_TL;
  3178.             __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk);
  3179.             return;
  3180.         }
  3181. Only in linux-4.2.tsarn1/kernel/time: posix-cpu-timers.c.orig
  3182. diff -aur linux-4.2/kernel/time/time.c linux-4.2.tsarn1/kernel/time/time.c
  3183. --- linux-4.2/kernel/time/time.c    2015-08-30 21:34:09.000000000 +0300
  3184. +++ linux-4.2.tsarn1/kernel/time/time.c 2016-02-08 16:51:12.701226243 +0300
  3185. @@ -84,6 +84,11 @@
  3186.     struct timespec tv;
  3187.     int err;
  3188.  
  3189. +        if (SBOX_IS_RESTRICTED()) {
  3190. +                SBOX_SET_SECURITY_ERR();
  3191. +                return -EPERM;
  3192. +        }
  3193. +
  3194.     if (get_user(tv.tv_sec, tptr))
  3195.         return -EFAULT;
  3196.  
  3197. @@ -197,6 +202,11 @@
  3198.     struct timespec new_ts;
  3199.     struct timezone new_tz;
  3200.  
  3201. +        if (SBOX_IS_RESTRICTED()) {
  3202. +                SBOX_SET_SECURITY_ERR();
  3203. +                return -EPERM;
  3204. +        }
  3205. +
  3206.     if (tv) {
  3207.         if (copy_from_user(&user_tv, tv, sizeof(*tv)))
  3208.             return -EFAULT;
  3209. @@ -220,6 +230,11 @@
  3210.     struct timex txc;       /* Local copy of parameter */
  3211.     int ret;
  3212.  
  3213. +        if (SBOX_IS_RESTRICTED()) {
  3214. +                SBOX_SET_SECURITY_ERR();
  3215. +                return -EPERM;
  3216. +        }
  3217. +
  3218.     /* Copy the user data space into the kernel copy
  3219.      * structure. But bear in mind that the structures
  3220.      * may change
  3221. Only in linux-4.2.tsarn1/kernel/time: time.c.orig
  3222. diff -aur linux-4.2/kernel/uid16.c linux-4.2.tsarn1/kernel/uid16.c
  3223. --- linux-4.2/kernel/uid16.c    2015-08-30 21:34:09.000000000 +0300
  3224. +++ linux-4.2.tsarn1/kernel/uid16.c 2016-02-08 16:51:12.701226243 +0300
  3225. @@ -176,6 +176,11 @@
  3226.     struct group_info *group_info;
  3227.     int retval;
  3228.  
  3229. +        if (SBOX_IS_RESTRICTED()) {
  3230. +                SBOX_SET_SECURITY_ERR();
  3231. +                return -EPERM;
  3232. +        }
  3233. +
  3234.     if (!may_setgroups())
  3235.         return -EPERM;
  3236.     if ((unsigned)gidsetsize > NGROUPS_MAX)
  3237. Only in linux-4.2.tsarn1: Makefile.orig
  3238. Only in linux-4.2.tsarn1: Makefile.rej
  3239. diff -aur linux-4.2/mm/madvise.c linux-4.2.tsarn1/mm/madvise.c
  3240. --- linux-4.2/mm/madvise.c  2015-08-30 21:34:09.000000000 +0300
  3241. +++ linux-4.2.tsarn1/mm/madvise.c   2016-02-08 16:51:12.707892988 +0300
  3242. @@ -466,6 +466,9 @@
  3243.     size_t len;
  3244.     struct blk_plug plug;
  3245.  
  3246. +        if (SBOX_IS_RESTRICTED())
  3247. +                return -EPERM;
  3248. +
  3249.  #ifdef CONFIG_MEMORY_FAILURE
  3250.     if (behavior == MADV_HWPOISON || behavior == MADV_SOFT_OFFLINE)
  3251.         return madvise_hwpoison(behavior, start, start+len_in);
  3252. Only in linux-4.2.tsarn1/mm: madvise.c.orig
  3253. diff -aur linux-4.2/mm/mempolicy.c linux-4.2.tsarn1/mm/mempolicy.c
  3254. --- linux-4.2/mm/mempolicy.c    2015-08-30 21:34:09.000000000 +0300
  3255. +++ linux-4.2.tsarn1/mm/mempolicy.c 2016-02-08 16:51:12.707892988 +0300
  3256. @@ -1306,6 +1306,9 @@
  3257.     int err;
  3258.     unsigned short mode_flags;
  3259.  
  3260. +        if (SBOX_IS_RESTRICTED())
  3261. +                return -EPERM;
  3262. +
  3263.     mode_flags = mode & MPOL_MODE_FLAGS;
  3264.     mode &= ~MPOL_MODE_FLAGS;
  3265.     if (mode >= MPOL_MAX)
  3266. @@ -1327,6 +1330,9 @@
  3267.     nodemask_t nodes;
  3268.     unsigned short flags;
  3269.  
  3270. +        if (SBOX_IS_RESTRICTED())
  3271. +                return -EPERM;
  3272. +
  3273.     flags = mode & MPOL_MODE_FLAGS;
  3274.     mode &= ~MPOL_MODE_FLAGS;
  3275.     if ((unsigned int)mode >= MPOL_MAX)
  3276. @@ -1352,6 +1358,9 @@
  3277.     nodemask_t *new;
  3278.     NODEMASK_SCRATCH(scratch);
  3279.  
  3280. +        if (SBOX_IS_RESTRICTED())
  3281. +                return -EPERM;
  3282. +
  3283.     if (!scratch)
  3284.         return -ENOMEM;
  3285.  
  3286. @@ -1443,6 +1452,9 @@
  3287.     int uninitialized_var(pval);
  3288.     nodemask_t nodes;
  3289.  
  3290. +        if (SBOX_IS_RESTRICTED())
  3291. +                return -EPERM;
  3292. +
  3293.     if (nmask != NULL && maxnode < MAX_NUMNODES)
  3294.         return -EINVAL;
  3295.  
  3296. @@ -1472,6 +1484,9 @@
  3297.     unsigned long nr_bits, alloc_size;
  3298.     DECLARE_BITMAP(bm, MAX_NUMNODES);
  3299.  
  3300. +        if (SBOX_IS_RESTRICTED())
  3301. +                return -EPERM;
  3302. +
  3303.     nr_bits = min_t(unsigned long, maxnode-1, MAX_NUMNODES);
  3304.     alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
  3305.  
  3306. @@ -1500,6 +1515,9 @@
  3307.     unsigned long nr_bits, alloc_size;
  3308.     DECLARE_BITMAP(bm, MAX_NUMNODES);
  3309.  
  3310. +        if (SBOX_IS_RESTRICTED())
  3311. +                return -EPERM;
  3312. +
  3313.     nr_bits = min_t(unsigned long, maxnode-1, MAX_NUMNODES);
  3314.     alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
  3315.  
  3316. @@ -1524,6 +1542,9 @@
  3317.     unsigned long nr_bits, alloc_size;
  3318.     nodemask_t bm;
  3319.  
  3320. +        if (SBOX_IS_RESTRICTED())
  3321. +                return -EPERM;
  3322. +
  3323.     nr_bits = min_t(unsigned long, maxnode-1, MAX_NUMNODES);
  3324.     alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
  3325.  
  3326. diff -aur linux-4.2/mm/migrate.c linux-4.2.tsarn1/mm/migrate.c
  3327. --- linux-4.2/mm/migrate.c  2015-08-30 21:34:09.000000000 +0300
  3328. +++ linux-4.2.tsarn1/mm/migrate.c   2016-02-08 16:51:12.707892988 +0300
  3329. @@ -1467,6 +1467,9 @@
  3330.     int err;
  3331.     nodemask_t task_nodes;
  3332.  
  3333. +        if (SBOX_IS_RESTRICTED())
  3334. +                return -EPERM;
  3335. +
  3336.     /* Check flags */
  3337.     if (flags & ~(MPOL_MF_MOVE|MPOL_MF_MOVE_ALL))
  3338.         return -EINVAL;
  3339. Only in linux-4.2.tsarn1/mm: migrate.c.orig
  3340. diff -aur linux-4.2/mm/mincore.c linux-4.2.tsarn1/mm/mincore.c
  3341. --- linux-4.2/mm/mincore.c  2015-08-30 21:34:09.000000000 +0300
  3342. +++ linux-4.2.tsarn1/mm/mincore.c   2016-02-08 16:51:12.707892988 +0300
  3343. @@ -224,6 +224,9 @@
  3344.     unsigned long pages;
  3345.     unsigned char *tmp;
  3346.  
  3347. +        if (SBOX_IS_RESTRICTED())
  3348. +                return -EPERM;
  3349. +
  3350.     /* Check the start address: needs to be page-aligned.. */
  3351.     if (start & ~PAGE_CACHE_MASK)
  3352.         return -EINVAL;
  3353. diff -aur linux-4.2/mm/mlock.c linux-4.2.tsarn1/mm/mlock.c
  3354. --- linux-4.2/mm/mlock.c    2015-08-30 21:34:09.000000000 +0300
  3355. +++ linux-4.2.tsarn1/mm/mlock.c 2016-02-08 16:51:12.707892988 +0300
  3356. @@ -610,6 +610,9 @@
  3357.     unsigned long lock_limit;
  3358.     int error = -ENOMEM;
  3359.  
  3360. +        if (SBOX_IS_RESTRICTED())
  3361. +                return -EPERM;
  3362. +
  3363.     if (!can_do_mlock())
  3364.         return -EPERM;
  3365.  
  3366. @@ -644,6 +647,9 @@
  3367.  {
  3368.     int ret;
  3369.  
  3370. +        if (SBOX_IS_RESTRICTED())
  3371. +                return -EPERM;
  3372. +
  3373.     len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
  3374.     start &= PAGE_MASK;
  3375.  
  3376. @@ -685,6 +691,9 @@
  3377.     unsigned long lock_limit;
  3378.     int ret = -EINVAL;
  3379.  
  3380. +        if (SBOX_IS_RESTRICTED())
  3381. +                return -EPERM;
  3382. +
  3383.     if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE)))
  3384.         goto out;
  3385.  
  3386. @@ -715,6 +724,9 @@
  3387.  {
  3388.     int ret;
  3389.  
  3390. +        if (SBOX_IS_RESTRICTED())
  3391. +                return -EPERM;
  3392. +
  3393.     down_write(&current->mm->mmap_sem);
  3394.     ret = do_mlockall(0);
  3395.     up_write(&current->mm->mmap_sem);
  3396. diff -aur linux-4.2/mm/mmap.c linux-4.2.tsarn1/mm/mmap.c
  3397. --- linux-4.2/mm/mmap.c 2015-08-30 21:34:09.000000000 +0300
  3398. +++ linux-4.2.tsarn1/mm/mmap.c  2016-02-08 16:51:12.711226361 +0300
  3399. @@ -228,6 +228,9 @@
  3400.  error:
  3401.     vm_unacct_memory(pages);
  3402.  
  3403. +        if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3404. +                current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3405. +        }
  3406.     return -ENOMEM;
  3407.  }
  3408.  
  3409. @@ -563,8 +566,9 @@
  3410.  
  3411.         if (vma_tmp->vm_end > addr) {
  3412.             /* Fail if an existing vma overlaps the area */
  3413. -           if (vma_tmp->vm_start < end)
  3414. +           if (vma_tmp->vm_start < end) {
  3415.                 return -ENOMEM;
  3416. +                        }
  3417.             __rb_link = &__rb_parent->rb_left;
  3418.         } else {
  3419.             rb_prev = __rb_parent;
  3420. @@ -774,8 +778,12 @@
  3421.  
  3422.             importer->anon_vma = exporter->anon_vma;
  3423.             error = anon_vma_clone(importer, exporter);
  3424. -           if (error)
  3425. +           if (error) {
  3426. +                                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3427. +                                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3428. +                                }
  3429.                 return error;
  3430. +                        }
  3431.         }
  3432.     }
  3433.  
  3434. @@ -1281,11 +1289,15 @@
  3435.  
  3436.     /* offset overflow? */
  3437.     if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
  3438. -       return -EOVERFLOW;
  3439. +               return -EOVERFLOW;
  3440.  
  3441.     /* Too many mappings? */
  3442. -   if (mm->map_count > sysctl_max_map_count)
  3443. +   if (mm->map_count > sysctl_max_map_count) {
  3444. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3445. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3446. +                }
  3447.         return -ENOMEM;
  3448. +        }
  3449.  
  3450.     /* Obtain the address to map to. we verify (or select) it and ensure
  3451.      * that it represents a valid section of the address space.
  3452. @@ -1540,21 +1552,33 @@
  3453.          * MAP_FIXED may remove pages of mappings that intersects with
  3454.          * requested mapping. Account for the pages it would unmap.
  3455.          */
  3456. -       if (!(vm_flags & MAP_FIXED))
  3457. +       if (!(vm_flags & MAP_FIXED)) {
  3458. +                        if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3459. +                                current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3460. +                        }
  3461.             return -ENOMEM;
  3462. +                }
  3463.  
  3464.         nr_pages = count_vma_pages_range(mm, addr, addr + len);
  3465.  
  3466. -       if (!may_expand_vm(mm, (len >> PAGE_SHIFT) - nr_pages))
  3467. +       if (!may_expand_vm(mm, (len >> PAGE_SHIFT) - nr_pages)) {
  3468. +                        if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3469. +                                current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3470. +                        }
  3471.             return -ENOMEM;
  3472. +                }
  3473.     }
  3474.  
  3475.     /* Clear old maps */
  3476.     error = -ENOMEM;
  3477.     while (find_vma_links(mm, addr, addr + len, &prev, &rb_link,
  3478.                   &rb_parent)) {
  3479. -       if (do_munmap(mm, addr, len))
  3480. +       if (do_munmap(mm, addr, len)) {
  3481. +                        if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3482. +                                current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3483. +                        }
  3484.             return -ENOMEM;
  3485. +                }
  3486.     }
  3487.  
  3488.     /*
  3489. @@ -1562,8 +1586,12 @@
  3490.      */
  3491.     if (accountable_mapping(file, vm_flags)) {
  3492.         charged = len >> PAGE_SHIFT;
  3493. -       if (security_vm_enough_memory_mm(mm, charged))
  3494. +       if (security_vm_enough_memory_mm(mm, charged)) {
  3495. +                        if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3496. +                                current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3497. +                        }
  3498.             return -ENOMEM;
  3499. +                }
  3500.         vm_flags |= VM_ACCOUNT;
  3501.     }
  3502.  
  3503. @@ -1582,6 +1610,10 @@
  3504.      */
  3505.     vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
  3506.     if (!vma) {
  3507. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3508. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3509. +                }
  3510. +
  3511.         error = -ENOMEM;
  3512.         goto unacct_error;
  3513.     }
  3514. @@ -1706,16 +1738,28 @@
  3515.  
  3516.     /* Adjust search length to account for worst case alignment overhead */
  3517.     length = info->length + info->align_mask;
  3518. -   if (length < info->length)
  3519. +   if (length < info->length) {
  3520. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3521. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3522. +                }
  3523.         return -ENOMEM;
  3524. +        }
  3525.  
  3526.     /* Adjust search limits by the desired length */
  3527. -   if (info->high_limit < length)
  3528. +   if (info->high_limit < length) {
  3529. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3530. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3531. +                }
  3532.         return -ENOMEM;
  3533. +        }
  3534.     high_limit = info->high_limit - length;
  3535.  
  3536. -   if (info->low_limit > high_limit)
  3537. +   if (info->low_limit > high_limit) {
  3538. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3539. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3540. +                }
  3541.         return -ENOMEM;
  3542. +        }
  3543.     low_limit = info->low_limit + length;
  3544.  
  3545.     /* Check if rbtree root looks promising */
  3546. @@ -1741,8 +1785,12 @@
  3547.         gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
  3548.  check_current:
  3549.         /* Check if current node has a suitable gap */
  3550. -       if (gap_start > high_limit)
  3551. +       if (gap_start > high_limit) {
  3552. +                        if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3553. +                                current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3554. +                        }
  3555.             return -ENOMEM;
  3556. +                }
  3557.         if (gap_end >= low_limit && gap_end - gap_start >= length)
  3558.             goto found;
  3559.  
  3560. @@ -1776,8 +1824,12 @@
  3561.     /* Check highest gap, which does not precede any rbtree node */
  3562.     gap_start = mm->highest_vm_end;
  3563.     gap_end = ULONG_MAX;  /* Only for VM_BUG_ON below */
  3564. -   if (gap_start > high_limit)
  3565. +   if (gap_start > high_limit) {
  3566. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3567. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3568. +                }
  3569.         return -ENOMEM;
  3570. +        }
  3571.  
  3572.  found:
  3573.     /* We found a suitable gap. Clip it with the original low_limit. */
  3574. @@ -1800,20 +1852,32 @@
  3575.  
  3576.     /* Adjust search length to account for worst case alignment overhead */
  3577.     length = info->length + info->align_mask;
  3578. -   if (length < info->length)
  3579. +   if (length < info->length) {
  3580. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3581. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3582. +                }
  3583.         return -ENOMEM;
  3584. +        }
  3585.  
  3586.     /*
  3587.      * Adjust search limits by the desired length.
  3588.      * See implementation comment at top of unmapped_area().
  3589.      */
  3590.     gap_end = info->high_limit;
  3591. -   if (gap_end < length)
  3592. +   if (gap_end < length) {
  3593. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3594. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3595. +                }
  3596.         return -ENOMEM;
  3597. +        }
  3598.     high_limit = gap_end - length;
  3599.  
  3600. -   if (info->low_limit > high_limit)
  3601. +   if (info->low_limit > high_limit) {
  3602. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3603. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3604. +                }
  3605.         return -ENOMEM;
  3606. +        }
  3607.     low_limit = info->low_limit + length;
  3608.  
  3609.     /* Check highest gap, which does not precede any rbtree node */
  3610. @@ -1822,11 +1886,19 @@
  3611.         goto found_highest;
  3612.  
  3613.     /* Check if rbtree root looks promising */
  3614. -   if (RB_EMPTY_ROOT(&mm->mm_rb))
  3615. +   if (RB_EMPTY_ROOT(&mm->mm_rb)) {
  3616. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3617. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3618. +                }
  3619.         return -ENOMEM;
  3620. +        }
  3621.     vma = rb_entry(mm->mm_rb.rb_node, struct vm_area_struct, vm_rb);
  3622. -   if (vma->rb_subtree_gap < length)
  3623. +   if (vma->rb_subtree_gap < length) {
  3624. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3625. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3626. +                }
  3627.         return -ENOMEM;
  3628. +        }
  3629.  
  3630.     while (true) {
  3631.         /* Visit right subtree if it looks promising */
  3632. @@ -1844,8 +1916,12 @@
  3633.  check_current:
  3634.         /* Check if current node has a suitable gap */
  3635.         gap_end = vma->vm_start;
  3636. -       if (gap_end < low_limit)
  3637. +       if (gap_end < low_limit) {
  3638. +                        if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3639. +                                current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3640. +                        }
  3641.             return -ENOMEM;
  3642. +                }
  3643.         if (gap_start <= high_limit && gap_end - gap_start >= length)
  3644.             goto found;
  3645.  
  3646. @@ -1863,8 +1939,12 @@
  3647.         /* Go back up the rbtree to find next candidate node */
  3648.         while (true) {
  3649.             struct rb_node *prev = &vma->vm_rb;
  3650. -           if (!rb_parent(prev))
  3651. +           if (!rb_parent(prev)) {
  3652. +                                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3653. +                                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3654. +                                }
  3655.                 return -ENOMEM;
  3656. +                        }
  3657.             vma = rb_entry(rb_parent(prev),
  3658.                        struct vm_area_struct, vm_rb);
  3659.             if (prev == vma->vm_rb.rb_right) {
  3660. @@ -1910,8 +1990,12 @@
  3661.     struct vm_area_struct *vma;
  3662.     struct vm_unmapped_area_info info;
  3663.  
  3664. -   if (len > TASK_SIZE - mmap_min_addr)
  3665. +   if (len > TASK_SIZE - mmap_min_addr) {
  3666. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3667. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3668. +                }
  3669.         return -ENOMEM;
  3670. +        }
  3671.  
  3672.     if (flags & MAP_FIXED)
  3673.         return addr;
  3674. @@ -1949,8 +2033,12 @@
  3675.     struct vm_unmapped_area_info info;
  3676.  
  3677.     /* requested length too big for entire address space */
  3678. -   if (len > TASK_SIZE - mmap_min_addr)
  3679. +   if (len > TASK_SIZE - mmap_min_addr) {
  3680. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3681. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3682. +                }
  3683.         return -ENOMEM;
  3684. +        }
  3685.  
  3686.     if (flags & MAP_FIXED)
  3687.         return addr;
  3688. @@ -2001,8 +2089,12 @@
  3689.         return error;
  3690.  
  3691.     /* Careful about overflows.. */
  3692. -   if (len > TASK_SIZE)
  3693. +   if (len > TASK_SIZE) {
  3694. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3695. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3696. +                }
  3697.         return -ENOMEM;
  3698. +        }
  3699.  
  3700.     get_area = current->mm->get_unmapped_area;
  3701.     if (file && file->f_op->get_unmapped_area)
  3702. @@ -2011,10 +2103,18 @@
  3703.     if (IS_ERR_VALUE(addr))
  3704.         return addr;
  3705.  
  3706. -   if (addr > TASK_SIZE - len)
  3707. +   if (addr > TASK_SIZE - len) {
  3708. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3709. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3710. +                }
  3711.         return -ENOMEM;
  3712. -   if (addr & ~PAGE_MASK)
  3713. +        }
  3714. +   if (addr & ~PAGE_MASK) {
  3715. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3716. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3717. +                }
  3718.         return -EINVAL;
  3719. +        }
  3720.  
  3721.     addr = arch_rebalance_pgtables(addr, len);
  3722.     error = security_mmap_addr(addr);
  3723. @@ -2093,15 +2193,23 @@
  3724.     unsigned long new_start, actual_size;
  3725.  
  3726.     /* address space limit tests */
  3727. -   if (!may_expand_vm(mm, grow))
  3728. +   if (!may_expand_vm(mm, grow)) {
  3729. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3730. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3731. +                }
  3732.         return -ENOMEM;
  3733. +        }
  3734.  
  3735.     /* Stack limit test */
  3736.     actual_size = size;
  3737.     if (size && (vma->vm_flags & (VM_GROWSUP | VM_GROWSDOWN)))
  3738.         actual_size -= PAGE_SIZE;
  3739. -   if (actual_size > READ_ONCE(rlim[RLIMIT_STACK].rlim_cur))
  3740. +   if (actual_size > READ_ONCE(rlim[RLIMIT_STACK].rlim_cur)) {
  3741. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3742. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3743. +                }
  3744.         return -ENOMEM;
  3745. +        }
  3746.  
  3747.     /* mlock limit tests */
  3748.     if (vma->vm_flags & VM_LOCKED) {
  3749. @@ -2110,8 +2218,12 @@
  3750.         locked = mm->locked_vm + grow;
  3751.         limit = READ_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
  3752.         limit >>= PAGE_SHIFT;
  3753. -       if (locked > limit && !capable(CAP_IPC_LOCK))
  3754. +       if (locked > limit && !capable(CAP_IPC_LOCK)) {
  3755. +                        if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3756. +                                current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3757. +                        }
  3758.             return -ENOMEM;
  3759. +                }
  3760.     }
  3761.  
  3762.     /* Check to ensure the stack will not grow into a hugetlb-only region */
  3763. @@ -2124,8 +2236,12 @@
  3764.      * Overcommit..  This must be the final test, as it will
  3765.      * update security statistics.
  3766.      */
  3767. -   if (security_vm_enough_memory_mm(mm, grow))
  3768. +   if (security_vm_enough_memory_mm(mm, grow)) {
  3769. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3770. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3771. +                }
  3772.         return -ENOMEM;
  3773. +        }
  3774.  
  3775.     /* Ok, everything looks good - let it rip */
  3776.     if (vma->vm_flags & VM_LOCKED)
  3777. @@ -2150,8 +2266,12 @@
  3778.      * We must make sure the anon_vma is allocated
  3779.      * so that the anon_vma locking is not a noop.
  3780.      */
  3781. -   if (unlikely(anon_vma_prepare(vma)))
  3782. +   if (unlikely(anon_vma_prepare(vma))) {
  3783. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3784. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3785. +                }
  3786.         return -ENOMEM;
  3787. +        }
  3788.     vma_lock_anon_vma(vma);
  3789.  
  3790.     /*
  3791. @@ -2164,6 +2284,9 @@
  3792.         address = PAGE_ALIGN(address+4);
  3793.     else {
  3794.         vma_unlock_anon_vma(vma);
  3795. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3796. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3797. +                }
  3798.         return -ENOMEM;
  3799.     }
  3800.     error = 0;
  3801. @@ -2223,8 +2346,12 @@
  3802.      * We must make sure the anon_vma is allocated
  3803.      * so that the anon_vma locking is not a noop.
  3804.      */
  3805. -   if (unlikely(anon_vma_prepare(vma)))
  3806. +   if (unlikely(anon_vma_prepare(vma))) {
  3807. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3808. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3809. +                }
  3810.         return -ENOMEM;
  3811. +        }
  3812.  
  3813.     address &= PAGE_MASK;
  3814.     error = security_mmap_addr(address);
  3815. @@ -2298,8 +2425,12 @@
  3816.     address &= PAGE_MASK;
  3817.     next = vma->vm_next;
  3818.     if (next && next->vm_start == address + PAGE_SIZE) {
  3819. -       if (!(next->vm_flags & VM_GROWSUP))
  3820. +       if (!(next->vm_flags & VM_GROWSUP)) {
  3821. +                        if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3822. +                                current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3823. +                        }
  3824.             return -ENOMEM;
  3825. +                }
  3826.     }
  3827.     return expand_upwards(vma, address);
  3828.  }
  3829. @@ -2327,8 +2458,12 @@
  3830.     address &= PAGE_MASK;
  3831.     prev = vma->vm_prev;
  3832.     if (prev && prev->vm_end == address) {
  3833. -       if (!(prev->vm_flags & VM_GROWSDOWN))
  3834. +       if (!(prev->vm_flags & VM_GROWSDOWN)) {
  3835. +                        if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3836. +                                current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3837. +                        }
  3838.             return -ENOMEM;
  3839. +                }
  3840.     }
  3841.     return expand_downwards(vma, address);
  3842.  }
  3843. @@ -2637,6 +2772,10 @@
  3844.     unsigned long ret = -EINVAL;
  3845.     struct file *file;
  3846.  
  3847. +        if (SBOX_IS_RESTRICTED()) {
  3848. +                return -EPERM;
  3849. +        }
  3850. +
  3851.     pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. "
  3852.             "See Documentation/vm/remap_file_pages.txt.\n",
  3853.             current->comm, current->pid);
  3854. @@ -2746,8 +2885,12 @@
  3855.     }
  3856.  
  3857.     /* Check against address space limits *after* clearing old maps... */
  3858. -   if (!may_expand_vm(mm, len >> PAGE_SHIFT))
  3859. +   if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
  3860. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3861. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3862. +                }
  3863.         return -ENOMEM;
  3864. +        }
  3865.  
  3866.     if (mm->map_count > sysctl_max_map_count)
  3867.         return -ENOMEM;
  3868. diff -aur linux-4.2/mm/mremap.c linux-4.2.tsarn1/mm/mremap.c
  3869. --- linux-4.2/mm/mremap.c   2015-08-30 21:34:09.000000000 +0300
  3870. +++ linux-4.2.tsarn1/mm/mremap.c    2016-02-08 16:51:12.711226361 +0300
  3871. @@ -380,8 +380,12 @@
  3872.             return ERR_PTR(-EAGAIN);
  3873.     }
  3874.  
  3875. -   if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT))
  3876. +   if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
  3877. +                if ((current->sbox_flags & SBOX_MEMLIMITON)) {
  3878. +                        current->sbox_flags |= SBOX_WAS_MEMLIMIT;
  3879. +                }
  3880.         return ERR_PTR(-ENOMEM);
  3881. +        }
  3882.  
  3883.     if (vma->vm_flags & VM_ACCOUNT) {
  3884.         unsigned long charged = (new_len - old_len) >> PAGE_SHIFT;
  3885. Only in linux-4.2.tsarn1/mm: mremap.c.orig
  3886. diff -aur linux-4.2/mm/msync.c linux-4.2.tsarn1/mm/msync.c
  3887. --- linux-4.2/mm/msync.c    2015-08-30 21:34:09.000000000 +0300
  3888. +++ linux-4.2.tsarn1/mm/msync.c 2016-02-08 16:51:12.711226361 +0300
  3889. @@ -36,6 +36,9 @@
  3890.     int unmapped_error = 0;
  3891.     int error = -EINVAL;
  3892.  
  3893. +        if (SBOX_IS_RESTRICTED())
  3894. +                return -EPERM;
  3895. +
  3896.     if (flags & ~(MS_ASYNC | MS_INVALIDATE | MS_SYNC))
  3897.         goto out;
  3898.     if (start & ~PAGE_MASK)
  3899. diff -aur linux-4.2/mm/process_vm_access.c linux-4.2.tsarn1/mm/process_vm_access.c
  3900. --- linux-4.2/mm/process_vm_access.c    2015-08-30 21:34:09.000000000 +0300
  3901. +++ linux-4.2.tsarn1/mm/process_vm_access.c 2016-02-08 16:51:12.711226361 +0300
  3902. @@ -288,6 +288,8 @@
  3903.         unsigned long, liovcnt, const struct iovec __user *, rvec,
  3904.         unsigned long, riovcnt, unsigned long, flags)
  3905.  {
  3906. +        if (SBOX_IS_RESTRICTED())
  3907. +                return -EPERM;
  3908.     return process_vm_rw(pid, lvec, liovcnt, rvec, riovcnt, flags, 0);
  3909.  }
  3910.  
  3911. @@ -296,6 +298,8 @@
  3912.         unsigned long, liovcnt, const struct iovec __user *, rvec,
  3913.         unsigned long, riovcnt, unsigned long, flags)
  3914.  {
  3915. +        if (SBOX_IS_RESTRICTED())
  3916. +                return -EPERM;
  3917.     return process_vm_rw(pid, lvec, liovcnt, rvec, riovcnt, flags, 1);
  3918.  }
  3919.  
  3920. @@ -347,6 +351,9 @@
  3921.                compat_ulong_t, riovcnt,
  3922.                compat_ulong_t, flags)
  3923.  {
  3924. +        if (SBOX_IS_RESTRICTED())
  3925. +                return -EPERM;
  3926. +
  3927.     return compat_process_vm_rw(pid, lvec, liovcnt, rvec,
  3928.                     riovcnt, flags, 0);
  3929.  }
  3930. @@ -358,6 +365,9 @@
  3931.                compat_ulong_t, riovcnt,
  3932.                compat_ulong_t, flags)
  3933.  {
  3934. +        if (SBOX_IS_RESTRICTED())
  3935. +                return -EPERM;
  3936. +
  3937.     return compat_process_vm_rw(pid, lvec, liovcnt, rvec,
  3938.                     riovcnt, flags, 1);
  3939.  }
  3940. diff -aur linux-4.2/mm/readahead.c linux-4.2.tsarn1/mm/readahead.c
  3941. --- linux-4.2/mm/readahead.c    2015-08-30 21:34:09.000000000 +0300
  3942. +++ linux-4.2.tsarn1/mm/readahead.c 2016-02-08 16:51:12.711226361 +0300
  3943. @@ -564,6 +564,9 @@
  3944.     ssize_t ret;
  3945.     struct fd f;
  3946.  
  3947. +        if (SBOX_IS_RESTRICTED())
  3948. +                return -EPERM;
  3949. +
  3950.     ret = -EBADF;
  3951.     f = fdget(fd);
  3952.     if (f.file) {
  3953. diff -aur linux-4.2/mm/swapfile.c linux-4.2.tsarn1/mm/swapfile.c
  3954. --- linux-4.2/mm/swapfile.c 2015-08-30 21:34:09.000000000 +0300
  3955. +++ linux-4.2.tsarn1/mm/swapfile.c  2016-02-08 16:51:12.711226361 +0300
  3956. @@ -1812,6 +1812,11 @@
  3957.     int err, found = 0;
  3958.     unsigned int old_block_size;
  3959.  
  3960. +        if (SBOX_IS_RESTRICTED()) {
  3961. +                SBOX_SET_SECURITY_ERR();
  3962. +                return -EPERM;
  3963. +        }
  3964. +
  3965.     if (!capable(CAP_SYS_ADMIN))
  3966.         return -EPERM;
  3967.  
  3968. @@ -2361,6 +2366,11 @@
  3969.     struct page *page = NULL;
  3970.     struct inode *inode = NULL;
  3971.  
  3972. +        if (SBOX_IS_RESTRICTED()) {
  3973. +                SBOX_SET_SECURITY_ERR();
  3974. +                return -EPERM;
  3975. +        }
  3976. +
  3977.     if (swap_flags & ~SWAP_FLAGS_VALID)
  3978.         return -EINVAL;
  3979.  
  3980. diff -aur linux-4.2/net/compat.c linux-4.2.tsarn1/net/compat.c
  3981. --- linux-4.2/net/compat.c  2015-08-30 21:34:09.000000000 +0300
  3982. +++ linux-4.2.tsarn1/net/compat.c   2016-02-08 16:51:12.711226361 +0300
  3983. @@ -367,8 +367,14 @@
  3984.                char __user *, optval, unsigned int, optlen)
  3985.  {
  3986.     int err;
  3987. -   struct socket *sock = sockfd_lookup(fd, &err);
  3988. +   struct socket *sock;
  3989.  
  3990. +        if (SBOX_IS_RESTRICTED()) {
  3991. +                SBOX_SET_SECURITY_ERR();
  3992. +                return -EPERM;
  3993. +        }
  3994. +
  3995. +        sock = sockfd_lookup(fd, &err);
  3996.     if (sock) {
  3997.         err = security_socket_setsockopt(sock, level, optname);
  3998.         if (err) {
  3999. @@ -487,8 +493,14 @@
  4000.                char __user *, optval, int __user *, optlen)
  4001.  {
  4002.     int err;
  4003. -   struct socket *sock = sockfd_lookup(fd, &err);
  4004. +   struct socket *sock;
  4005. +
  4006. +        if (SBOX_IS_RESTRICTED()) {
  4007. +                SBOX_SET_SECURITY_ERR();
  4008. +                return -EPERM;
  4009. +        }
  4010.  
  4011. +        sock = sockfd_lookup(fd, &err);
  4012.     if (sock) {
  4013.         err = security_socket_getsockopt(sock, level, optname);
  4014.         if (err) {
  4015. @@ -716,23 +728,43 @@
  4016.  
  4017.  COMPAT_SYSCALL_DEFINE3(sendmsg, int, fd, struct compat_msghdr __user *, msg, unsigned int, flags)
  4018.  {
  4019. +        if (SBOX_IS_RESTRICTED()) {
  4020. +                SBOX_SET_SECURITY_ERR();
  4021. +                return -EPERM;
  4022. +        }
  4023. +
  4024.     return __sys_sendmsg(fd, (struct user_msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
  4025.  }
  4026.  
  4027.  COMPAT_SYSCALL_DEFINE4(sendmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
  4028.                unsigned int, vlen, unsigned int, flags)
  4029.  {
  4030. +        if (SBOX_IS_RESTRICTED()) {
  4031. +                SBOX_SET_SECURITY_ERR();
  4032. +                return -EPERM;
  4033. +        }
  4034. +
  4035.     return __sys_sendmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
  4036.                   flags | MSG_CMSG_COMPAT);
  4037.  }
  4038.  
  4039.  COMPAT_SYSCALL_DEFINE3(recvmsg, int, fd, struct compat_msghdr __user *, msg, unsigned int, flags)
  4040.  {
  4041. +        if (SBOX_IS_RESTRICTED()) {
  4042. +                SBOX_SET_SECURITY_ERR();
  4043. +                return -EPERM;
  4044. +        }
  4045. +
  4046.     return __sys_recvmsg(fd, (struct user_msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
  4047.  }
  4048.  
  4049.  COMPAT_SYSCALL_DEFINE4(recv, int, fd, void __user *, buf, compat_size_t, len, unsigned int, flags)
  4050.  {
  4051. +        if (SBOX_IS_RESTRICTED()) {
  4052. +                SBOX_SET_SECURITY_ERR();
  4053. +                return -EPERM;
  4054. +        }
  4055. +
  4056.     return sys_recv(fd, buf, len, flags | MSG_CMSG_COMPAT);
  4057.  }
  4058.  
  4059. @@ -740,6 +772,11 @@
  4060.                unsigned int, flags, struct sockaddr __user *, addr,
  4061.                int __user *, addrlen)
  4062.  {
  4063. +        if (SBOX_IS_RESTRICTED()) {
  4064. +                SBOX_SET_SECURITY_ERR();
  4065. +                return -EPERM;
  4066. +        }
  4067. +
  4068.     return sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr, addrlen);
  4069.  }
  4070.  
  4071. @@ -750,6 +787,11 @@
  4072.     int datagrams;
  4073.     struct timespec ktspec;
  4074.  
  4075. +        if (SBOX_IS_RESTRICTED()) {
  4076. +                SBOX_SET_SECURITY_ERR();
  4077. +                return -EPERM;
  4078. +        }
  4079. +
  4080.     if (timeout == NULL)
  4081.         return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
  4082.                       flags | MSG_CMSG_COMPAT, NULL);
  4083. @@ -771,6 +813,11 @@
  4084.     u32 a[6];
  4085.     u32 a0, a1;
  4086.  
  4087. +        if (SBOX_IS_RESTRICTED()) {
  4088. +                SBOX_SET_SECURITY_ERR();
  4089. +                return -EPERM;
  4090. +        }
  4091. +
  4092.     if (call < SYS_SOCKET || call > SYS_SENDMMSG)
  4093.         return -EINVAL;
  4094.     if (copy_from_user(a, args, nas[call]))
  4095. diff -aur linux-4.2/net/socket.c linux-4.2.tsarn1/net/socket.c
  4096. --- linux-4.2/net/socket.c  2015-08-30 21:34:09.000000000 +0300
  4097. +++ linux-4.2.tsarn1/net/socket.c   2016-02-08 16:51:12.711226361 +0300
  4098. @@ -1222,6 +1222,11 @@
  4099.     struct socket *sock;
  4100.     int flags;
  4101.  
  4102. +        if (SBOX_IS_RESTRICTED()) {
  4103. +                SBOX_SET_SECURITY_ERR();
  4104. +                return -EPERM;
  4105. +        }
  4106. +
  4107.     /* Check the SOCK_* constants for consistency.  */
  4108.     BUILD_BUG_ON(SOCK_CLOEXEC != O_CLOEXEC);
  4109.     BUILD_BUG_ON((SOCK_MAX | SOCK_TYPE_MASK) != SOCK_TYPE_MASK);
  4110. @@ -1265,6 +1270,11 @@
  4111.     struct file *newfile1, *newfile2;
  4112.     int flags;
  4113.  
  4114. +        if (SBOX_IS_RESTRICTED()) {
  4115. +                SBOX_SET_SECURITY_ERR();
  4116. +                return -EPERM;
  4117. +        }
  4118. +
  4119.     flags = type & ~SOCK_TYPE_MASK;
  4120.     if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK))
  4121.         return -EINVAL;
  4122. @@ -1372,6 +1382,11 @@
  4123.     struct sockaddr_storage address;
  4124.     int err, fput_needed;
  4125.  
  4126. +        if (SBOX_IS_RESTRICTED()) {
  4127. +                SBOX_SET_SECURITY_ERR();
  4128. +                return -EPERM;
  4129. +        }
  4130. +
  4131.     sock = sockfd_lookup_light(fd, &err, &fput_needed);
  4132.     if (sock) {
  4133.         err = move_addr_to_kernel(umyaddr, addrlen, &address);
  4134. @@ -1401,6 +1416,11 @@
  4135.     int err, fput_needed;
  4136.     int somaxconn;
  4137.  
  4138. +        if (SBOX_IS_RESTRICTED()) {
  4139. +                SBOX_SET_SECURITY_ERR();
  4140. +                return -EPERM;
  4141. +        }
  4142. +
  4143.     sock = sockfd_lookup_light(fd, &err, &fput_needed);
  4144.     if (sock) {
  4145.         somaxconn = sock_net(sock->sk)->core.sysctl_somaxconn;
  4146. @@ -1436,6 +1456,11 @@
  4147.     int err, len, newfd, fput_needed;
  4148.     struct sockaddr_storage address;
  4149.  
  4150. +        if (SBOX_IS_RESTRICTED()) {
  4151. +                SBOX_SET_SECURITY_ERR();
  4152. +                return -EPERM;
  4153. +        }
  4154. +
  4155.     if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK))
  4156.         return -EINVAL;
  4157.  
  4158. @@ -1534,6 +1559,11 @@
  4159.     struct sockaddr_storage address;
  4160.     int err, fput_needed;
  4161.  
  4162. +        if (SBOX_IS_RESTRICTED()) {
  4163. +                SBOX_SET_SECURITY_ERR();
  4164. +                return -EPERM;
  4165. +        }
  4166. +
  4167.     sock = sockfd_lookup_light(fd, &err, &fput_needed);
  4168.     if (!sock)
  4169.         goto out;
  4170. @@ -1566,6 +1596,11 @@
  4171.     struct sockaddr_storage address;
  4172.     int len, err, fput_needed;
  4173.  
  4174. +        if (SBOX_IS_RESTRICTED()) {
  4175. +                SBOX_SET_SECURITY_ERR();
  4176. +                return -EPERM;
  4177. +        }
  4178. +
  4179.     sock = sockfd_lookup_light(fd, &err, &fput_needed);
  4180.     if (!sock)
  4181.         goto out;
  4182. @@ -1597,6 +1632,11 @@
  4183.     struct sockaddr_storage address;
  4184.     int len, err, fput_needed;
  4185.  
  4186. +        if (SBOX_IS_RESTRICTED()) {
  4187. +                SBOX_SET_SECURITY_ERR();
  4188. +                return -EPERM;
  4189. +        }
  4190. +
  4191.     sock = sockfd_lookup_light(fd, &err, &fput_needed);
  4192.     if (sock != NULL) {
  4193.         err = security_socket_getpeername(sock);
  4194. @@ -1633,6 +1673,11 @@
  4195.     struct iovec iov;
  4196.     int fput_needed;
  4197.  
  4198. +        if (SBOX_IS_RESTRICTED()) {
  4199. +                SBOX_SET_SECURITY_ERR();
  4200. +                return -EPERM;
  4201. +        }
  4202. +
  4203.     err = import_single_range(WRITE, buff, len, &iov, &msg.msg_iter);
  4204.     if (unlikely(err))
  4205.         return err;
  4206. @@ -1689,6 +1734,11 @@
  4207.     int err, err2;
  4208.     int fput_needed;
  4209.  
  4210. +        if (SBOX_IS_RESTRICTED()) {
  4211. +                SBOX_SET_SECURITY_ERR();
  4212. +                return -EPERM;
  4213. +        }
  4214. +
  4215.     err = import_single_range(READ, ubuf, size, &iov, &msg.msg_iter);
  4216.     if (unlikely(err))
  4217.         return err;
  4218. @@ -1739,6 +1789,11 @@
  4219.     int err, fput_needed;
  4220.     struct socket *sock;
  4221.  
  4222. +        if (SBOX_IS_RESTRICTED()) {
  4223. +                SBOX_SET_SECURITY_ERR();
  4224. +                return -EPERM;
  4225. +        }
  4226. +
  4227.     if (optlen < 0)
  4228.         return -EINVAL;
  4229.  
  4230. @@ -1773,6 +1828,11 @@
  4231.     int err, fput_needed;
  4232.     struct socket *sock;
  4233.  
  4234. +        if (SBOX_IS_RESTRICTED()) {
  4235. +                SBOX_SET_SECURITY_ERR();
  4236. +                return -EPERM;
  4237. +        }
  4238. +
  4239.     sock = sockfd_lookup_light(fd, &err, &fput_needed);
  4240.     if (sock != NULL) {
  4241.         err = security_socket_getsockopt(sock, level, optname);
  4242. @@ -1802,6 +1862,11 @@
  4243.     int err, fput_needed;
  4244.     struct socket *sock;
  4245.  
  4246. +        if (SBOX_IS_RESTRICTED()) {
  4247. +                SBOX_SET_SECURITY_ERR();
  4248. +                return -EPERM;
  4249. +        }
  4250. +
  4251.     sock = sockfd_lookup_light(fd, &err, &fput_needed);
  4252.     if (sock != NULL) {
  4253.         err = security_socket_shutdown(sock, how);
  4254. @@ -1992,6 +2057,11 @@
  4255.  
  4256.  SYSCALL_DEFINE3(sendmsg, int, fd, struct user_msghdr __user *, msg, unsigned int, flags)
  4257.  {
  4258. +        if (SBOX_IS_RESTRICTED()) {
  4259. +                SBOX_SET_SECURITY_ERR();
  4260. +                return -EPERM;
  4261. +        }
  4262. +
  4263.     if (flags & MSG_CMSG_COMPAT)
  4264.         return -EINVAL;
  4265.     return __sys_sendmsg(fd, msg, flags);
  4266. @@ -2060,6 +2130,11 @@
  4267.  SYSCALL_DEFINE4(sendmmsg, int, fd, struct mmsghdr __user *, mmsg,
  4268.         unsigned int, vlen, unsigned int, flags)
  4269.  {
  4270. +        if (SBOX_IS_RESTRICTED()) {
  4271. +                SBOX_SET_SECURITY_ERR();
  4272. +                return -EPERM;
  4273. +        }
  4274. +
  4275.     if (flags & MSG_CMSG_COMPAT)
  4276.         return -EINVAL;
  4277.     return __sys_sendmmsg(fd, mmsg, vlen, flags);
  4278. @@ -2157,6 +2232,11 @@
  4279.  SYSCALL_DEFINE3(recvmsg, int, fd, struct user_msghdr __user *, msg,
  4280.         unsigned int, flags)
  4281.  {
  4282. +        if (SBOX_IS_RESTRICTED()) {
  4283. +                SBOX_SET_SECURITY_ERR();
  4284. +                return -EPERM;
  4285. +        }
  4286. +
  4287.     if (flags & MSG_CMSG_COMPAT)
  4288.         return -EINVAL;
  4289.     return __sys_recvmsg(fd, msg, flags);
  4290. @@ -2277,6 +2357,11 @@
  4291.     int datagrams;
  4292.     struct timespec timeout_sys;
  4293.  
  4294. +        if (SBOX_IS_RESTRICTED()) {
  4295. +                SBOX_SET_SECURITY_ERR();
  4296. +                return -EPERM;
  4297. +        }
  4298. +
  4299.     if (flags & MSG_CMSG_COMPAT)
  4300.         return -EINVAL;
  4301.  
  4302. @@ -2322,6 +2407,11 @@
  4303.     int err;
  4304.     unsigned int len;
  4305.  
  4306. +        if (SBOX_IS_RESTRICTED()) {
  4307. +                SBOX_SET_SECURITY_ERR();
  4308. +                return -EPERM;
  4309. +        }
  4310. +
  4311.     if (call < 1 || call > SYS_SENDMMSG)
  4312.         return -EINVAL;
  4313.  
  4314. Only in linux-4.2.tsarn1/net: socket.c.orig
  4315. diff -aur linux-4.2/security/keys/keyctl.c linux-4.2.tsarn1/security/keys/keyctl.c
  4316. --- linux-4.2/security/keys/keyctl.c    2015-08-30 21:34:09.000000000 +0300
  4317. +++ linux-4.2.tsarn1/security/keys/keyctl.c 2016-02-08 16:51:12.711226361 +0300
  4318. @@ -69,6 +69,11 @@
  4319.     long ret;
  4320.     bool vm;
  4321.  
  4322. +        if (SBOX_IS_RESTRICTED()) {
  4323. +                SBOX_SET_SECURITY_ERR();
  4324. +                return -EPERM;
  4325. +        }
  4326. +
  4327.     ret = -EINVAL;
  4328.     if (plen > 1024 * 1024 - 1)
  4329.         goto error;
  4330. @@ -173,6 +178,11 @@
  4331.     char type[32], *description, *callout_info;
  4332.     long ret;
  4333.  
  4334. +        if (SBOX_IS_RESTRICTED()) {
  4335. +                SBOX_SET_SECURITY_ERR();
  4336. +                return -EPERM;
  4337. +        }
  4338. +
  4339.     /* pull the type into kernel space */
  4340.     ret = key_get_type_from_user(type, _type, sizeof(type));
  4341.     if (ret < 0)
  4342. @@ -1559,6 +1569,11 @@
  4343.  SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3,
  4344.         unsigned long, arg4, unsigned long, arg5)
  4345.  {
  4346. +        if (SBOX_IS_RESTRICTED()) {
  4347. +                SBOX_SET_SECURITY_ERR();
  4348. +                return -EPERM;
  4349. +        }
  4350. +
  4351.     switch (option) {
  4352.     case KEYCTL_GET_KEYRING_ID:
  4353.         return keyctl_get_keyring_ID((key_serial_t) arg2,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement