~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/kernel/sys.c

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.14 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.57 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.138 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.193 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  linux/kernel/sys.c
  3  *
  4  *  Copyright (C) 1991, 1992  Linus Torvalds
  5  */
  6 
  7 #include <linux/config.h>
  8 #include <linux/compat.h>
  9 #include <linux/module.h>
 10 #include <linux/mm.h>
 11 #include <linux/utsname.h>
 12 #include <linux/mman.h>
 13 #include <linux/smp_lock.h>
 14 #include <linux/notifier.h>
 15 #include <linux/reboot.h>
 16 #include <linux/prctl.h>
 17 #include <linux/init.h>
 18 #include <linux/highuid.h>
 19 #include <linux/fs.h>
 20 #include <linux/workqueue.h>
 21 #include <linux/device.h>
 22 #include <linux/times.h>
 23 #include <linux/security.h>
 24 #include <linux/dcookies.h>
 25 #include <linux/suspend.h>
 26 
 27 #include <asm/uaccess.h>
 28 #include <asm/io.h>
 29 #include <asm/unistd.h>
 30 
 31 #ifndef SET_UNALIGN_CTL
 32 # define SET_UNALIGN_CTL(a,b)   (-EINVAL)
 33 #endif
 34 #ifndef GET_UNALIGN_CTL
 35 # define GET_UNALIGN_CTL(a,b)   (-EINVAL)
 36 #endif
 37 #ifndef SET_FPEMU_CTL
 38 # define SET_FPEMU_CTL(a,b)     (-EINVAL)
 39 #endif
 40 #ifndef GET_FPEMU_CTL
 41 # define GET_FPEMU_CTL(a,b)     (-EINVAL)
 42 #endif
 43 #ifndef SET_FPEXC_CTL
 44 # define SET_FPEXC_CTL(a,b)     (-EINVAL)
 45 #endif
 46 #ifndef GET_FPEXC_CTL
 47 # define GET_FPEXC_CTL(a,b)     (-EINVAL)
 48 #endif
 49 
 50 /*
 51  * this is where the system-wide overflow UID and GID are defined, for
 52  * architectures that now have 32-bit UID/GID but didn't in the past
 53  */
 54 
 55 int overflowuid = DEFAULT_OVERFLOWUID;
 56 int overflowgid = DEFAULT_OVERFLOWGID;
 57 
 58 #ifdef CONFIG_UID16
 59 EXPORT_SYMBOL(overflowuid);
 60 EXPORT_SYMBOL(overflowgid);
 61 #endif
 62 
 63 /*
 64  * the same as above, but for filesystems which can only store a 16-bit
 65  * UID and GID. as such, this is needed on all architectures
 66  */
 67 
 68 int fs_overflowuid = DEFAULT_FS_OVERFLOWUID;
 69 int fs_overflowgid = DEFAULT_FS_OVERFLOWUID;
 70 
 71 EXPORT_SYMBOL(fs_overflowuid);
 72 EXPORT_SYMBOL(fs_overflowgid);
 73 
 74 /*
 75  * this indicates whether you can reboot with ctrl-alt-del: the default is yes
 76  */
 77 
 78 int C_A_D = 1;
 79 int cad_pid = 1;
 80 
 81 /*
 82  *      Notifier list for kernel code which wants to be called
 83  *      at shutdown. This is used to stop any idling DMA operations
 84  *      and the like. 
 85  */
 86 
 87 static struct notifier_block *reboot_notifier_list;
 88 rwlock_t notifier_lock = RW_LOCK_UNLOCKED;
 89 
 90 /**
 91  *      notifier_chain_register - Add notifier to a notifier chain
 92  *      @list: Pointer to root list pointer
 93  *      @n: New entry in notifier chain
 94  *
 95  *      Adds a notifier to a notifier chain.
 96  *
 97  *      Currently always returns zero.
 98  */
 99  
100 int notifier_chain_register(struct notifier_block **list, struct notifier_block *n)
101 {
102         write_lock(&notifier_lock);
103         while(*list)
104         {
105                 if(n->priority > (*list)->priority)
106                         break;
107                 list= &((*list)->next);
108         }
109         n->next = *list;
110         *list=n;
111         write_unlock(&notifier_lock);
112         return 0;
113 }
114 
115 EXPORT_SYMBOL(notifier_chain_register);
116 
117 /**
118  *      notifier_chain_unregister - Remove notifier from a notifier chain
119  *      @nl: Pointer to root list pointer
120  *      @n: New entry in notifier chain
121  *
122  *      Removes a notifier from a notifier chain.
123  *
124  *      Returns zero on success, or %-ENOENT on failure.
125  */
126  
127 int notifier_chain_unregister(struct notifier_block **nl, struct notifier_block *n)
128 {
129         write_lock(&notifier_lock);
130         while((*nl)!=NULL)
131         {
132                 if((*nl)==n)
133                 {
134                         *nl=n->next;
135                         write_unlock(&notifier_lock);
136                         return 0;
137                 }
138                 nl=&((*nl)->next);
139         }
140         write_unlock(&notifier_lock);
141         return -ENOENT;
142 }
143 
144 EXPORT_SYMBOL(notifier_chain_unregister);
145 
146 /**
147  *      notifier_call_chain - Call functions in a notifier chain
148  *      @n: Pointer to root pointer of notifier chain
149  *      @val: Value passed unmodified to notifier function
150  *      @v: Pointer passed unmodified to notifier function
151  *
152  *      Calls each function in a notifier chain in turn.
153  *
154  *      If the return value of the notifier can be and'd
155  *      with %NOTIFY_STOP_MASK, then notifier_call_chain
156  *      will return immediately, with the return value of
157  *      the notifier function which halted execution.
158  *      Otherwise, the return value is the return value
159  *      of the last notifier function called.
160  */
161  
162 int notifier_call_chain(struct notifier_block **n, unsigned long val, void *v)
163 {
164         int ret=NOTIFY_DONE;
165         struct notifier_block *nb = *n;
166 
167         while(nb)
168         {
169                 ret=nb->notifier_call(nb,val,v);
170                 if(ret&NOTIFY_STOP_MASK)
171                 {
172                         return ret;
173                 }
174                 nb=nb->next;
175         }
176         return ret;
177 }
178 
179 EXPORT_SYMBOL(notifier_call_chain);
180 
181 /**
182  *      register_reboot_notifier - Register function to be called at reboot time
183  *      @nb: Info about notifier function to be called
184  *
185  *      Registers a function with the list of functions
186  *      to be called at reboot time.
187  *
188  *      Currently always returns zero, as notifier_chain_register
189  *      always returns zero.
190  */
191  
192 int register_reboot_notifier(struct notifier_block * nb)
193 {
194         return notifier_chain_register(&reboot_notifier_list, nb);
195 }
196 
197 EXPORT_SYMBOL(register_reboot_notifier);
198 
199 /**
200  *      unregister_reboot_notifier - Unregister previously registered reboot notifier
201  *      @nb: Hook to be unregistered
202  *
203  *      Unregisters a previously registered reboot
204  *      notifier function.
205  *
206  *      Returns zero on success, or %-ENOENT on failure.
207  */
208  
209 int unregister_reboot_notifier(struct notifier_block * nb)
210 {
211         return notifier_chain_unregister(&reboot_notifier_list, nb);
212 }
213 
214 EXPORT_SYMBOL(unregister_reboot_notifier);
215 
216 asmlinkage long sys_ni_syscall(void)
217 {
218         return -ENOSYS;
219 }
220 
221 cond_syscall(sys_nfsservctl)
222 cond_syscall(sys_quotactl)
223 cond_syscall(sys_acct)
224 cond_syscall(sys_lookup_dcookie)
225 cond_syscall(sys_swapon)
226 cond_syscall(sys_swapoff)
227 cond_syscall(sys_init_module)
228 cond_syscall(sys_delete_module)
229 cond_syscall(sys_socketpair)
230 cond_syscall(sys_bind)
231 cond_syscall(sys_listen)
232 cond_syscall(sys_accept)
233 cond_syscall(sys_connect)
234 cond_syscall(sys_getsockname)
235 cond_syscall(sys_getpeername)
236 cond_syscall(sys_sendto)
237 cond_syscall(sys_send)
238 cond_syscall(sys_recvfrom)
239 cond_syscall(sys_recv)
240 cond_syscall(sys_socket)
241 cond_syscall(sys_setsockopt)
242 cond_syscall(sys_getsockopt)
243 cond_syscall(sys_shutdown)
244 cond_syscall(sys_sendmsg)
245 cond_syscall(sys_recvmsg)
246 cond_syscall(sys_socketcall)
247 cond_syscall(sys_futex)
248 cond_syscall(compat_sys_futex)
249 cond_syscall(sys_epoll_create)
250 cond_syscall(sys_epoll_ctl)
251 cond_syscall(sys_epoll_wait)
252 cond_syscall(sys_pciconfig_read)
253 cond_syscall(sys_pciconfig_write)
254 
255 static int set_one_prio(struct task_struct *p, int niceval, int error)
256 {
257         int no_nice;
258 
259         if (p->uid != current->euid &&
260                 p->uid != current->uid && !capable(CAP_SYS_NICE)) {
261                 error = -EPERM;
262                 goto out;
263         }
264         if (niceval < task_nice(p) && !capable(CAP_SYS_NICE)) {
265                 error = -EACCES;
266                 goto out;
267         }
268         no_nice = security_task_setnice(p, niceval);
269         if (no_nice) {
270                 error = no_nice;
271                 goto out;
272         }
273         if (error == -ESRCH)
274                 error = 0;
275         set_user_nice(p, niceval);
276 out:
277         return error;
278 }
279 
280 asmlinkage long sys_setpriority(int which, int who, int niceval)
281 {
282         struct task_struct *g, *p;
283         struct user_struct *user;
284         struct pid *pid;
285         struct list_head *l;
286         int error = -EINVAL;
287 
288         if (which > 2 || which < 0)
289                 goto out;
290 
291         /* normalize: avoid signed division (rounding problems) */
292         error = -ESRCH;
293         if (niceval < -20)
294                 niceval = -20;
295         if (niceval > 19)
296                 niceval = 19;
297 
298         read_lock(&tasklist_lock);
299         switch (which) {
300                 case PRIO_PROCESS:
301                         if (!who)
302                                 who = current->pid;
303                         p = find_task_by_pid(who);
304                         if (p)
305                                 error = set_one_prio(p, niceval, error);
306                         break;
307                 case PRIO_PGRP:
308                         if (!who)
309                                 who = process_group(current);
310                         for_each_task_pid(who, PIDTYPE_PGID, p, l, pid)
311                                 error = set_one_prio(p, niceval, error);
312                         break;
313                 case PRIO_USER:
314                         if (!who)
315                                 user = current->user;
316                         else
317                                 user = find_user(who);
318 
319                         if (!user)
320                                 goto out_unlock;
321 
322                         do_each_thread(g, p)
323                                 if (p->uid == who)
324                                         error = set_one_prio(p, niceval, error);
325                         while_each_thread(g, p);
326                         break;
327         }
328 out_unlock:
329         read_unlock(&tasklist_lock);
330 out:
331         return error;
332 }
333 
334 /*
335  * Ugh. To avoid negative return values, "getpriority()" will
336  * not return the normal nice-value, but a negated value that
337  * has been offset by 20 (ie it returns 40..1 instead of -20..19)
338  * to stay compatible.
339  */
340 asmlinkage long sys_getpriority(int which, int who)
341 {
342         struct task_struct *g, *p;
343         struct list_head *l;
344         struct pid *pid;
345         struct user_struct *user;
346         long niceval, retval = -ESRCH;
347 
348         if (which > 2 || which < 0)
349                 return -EINVAL;
350 
351         read_lock(&tasklist_lock);
352         switch (which) {
353                 case PRIO_PROCESS:
354                         if (!who)
355                                 who = current->pid;
356                         p = find_task_by_pid(who);
357                         if (p) {
358                                 niceval = 20 - task_nice(p);
359                                 if (niceval > retval)
360                                         retval = niceval;
361                         }
362                         break;
363                 case PRIO_PGRP:
364                         if (!who)
365                                 who = process_group(current);
366                         for_each_task_pid(who, PIDTYPE_PGID, p, l, pid) {
367                                 niceval = 20 - task_nice(p);
368                                 if (niceval > retval)
369                                         retval = niceval;
370                         }
371                         break;
372                 case PRIO_USER:
373                         if (!who)
374                                 user = current->user;
375                         else
376                                 user = find_user(who);
377 
378                         if (!user)
379                                 goto out_unlock;
380 
381                         do_each_thread(g, p)
382                                 if (p->uid == who) {
383                                         niceval = 20 - task_nice(p);
384                                         if (niceval > retval)
385                                                 retval = niceval;
386                                 }
387                         while_each_thread(g, p);
388                         break;
389         }
390 out_unlock:
391         read_unlock(&tasklist_lock);
392 
393         return retval;
394 }
395 
396 
397 /*
398  * Reboot system call: for obvious reasons only root may call it,
399  * and even root needs to set up some magic numbers in the registers
400  * so that some mistake won't make this reboot the whole machine.
401  * You can also set the meaning of the ctrl-alt-del-key here.
402  *
403  * reboot doesn't sync: do that yourself before calling this.
404  */
405 asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user * arg)
406 {
407         char buffer[256];
408 
409         /* We only trust the superuser with rebooting the system. */
410         if (!capable(CAP_SYS_BOOT))
411                 return -EPERM;
412 
413         /* For safety, we require "magic" arguments. */
414         if (magic1 != LINUX_REBOOT_MAGIC1 ||
415             (magic2 != LINUX_REBOOT_MAGIC2 &&
416                         magic2 != LINUX_REBOOT_MAGIC2A &&
417                         magic2 != LINUX_REBOOT_MAGIC2B &&
418                         magic2 != LINUX_REBOOT_MAGIC2C))
419                 return -EINVAL;
420 
421         lock_kernel();
422         switch (cmd) {
423         case LINUX_REBOOT_CMD_RESTART:
424                 notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL);
425                 system_running = 0;
426                 device_shutdown();
427                 printk(KERN_EMERG "Restarting system.\n");
428                 machine_restart(NULL);
429                 break;
430 
431         case LINUX_REBOOT_CMD_CAD_ON:
432                 C_A_D = 1;
433                 break;
434 
435         case LINUX_REBOOT_CMD_CAD_OFF:
436                 C_A_D = 0;
437                 break;
438 
439         case LINUX_REBOOT_CMD_HALT:
440                 notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL);
441                 system_running = 0;
442                 device_shutdown();
443                 printk(KERN_EMERG "System halted.\n");
444                 machine_halt();
445                 unlock_kernel();
446                 do_exit(0);
447                 break;
448 
449         case LINUX_REBOOT_CMD_POWER_OFF:
450                 notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL);
451                 system_running = 0;
452                 device_shutdown();
453                 printk(KERN_EMERG "Power down.\n");
454                 machine_power_off();
455                 unlock_kernel();
456                 do_exit(0);
457                 break;
458 
459         case LINUX_REBOOT_CMD_RESTART2:
460                 if (strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1) < 0) {
461                         unlock_kernel();
462                         return -EFAULT;
463                 }
464                 buffer[sizeof(buffer) - 1] = '\0';
465 
466                 notifier_call_chain(&reboot_notifier_list, SYS_RESTART, buffer);
467                 system_running = 0;
468                 device_shutdown();
469                 printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer);
470                 machine_restart(buffer);
471                 break;
472 
473 #ifdef CONFIG_SOFTWARE_SUSPEND
474         case LINUX_REBOOT_CMD_SW_SUSPEND:
475                 if (!software_suspend_enabled) {
476                         unlock_kernel();
477                         return -EAGAIN;
478                 }
479                 software_suspend();
480                 do_exit(0);
481                 break;
482 #endif
483 
484         default:
485                 unlock_kernel();
486                 return -EINVAL;
487         }
488         unlock_kernel();
489         return 0;
490 }
491 
492 static void deferred_cad(void *dummy)
493 {
494         notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL);
495         machine_restart(NULL);
496 }
497 
498 /*
499  * This function gets called by ctrl-alt-del - ie the keyboard interrupt.
500  * As it's called within an interrupt, it may NOT sync: the only choice
501  * is whether to reboot at once, or just ignore the ctrl-alt-del.
502  */
503 void ctrl_alt_del(void)
504 {
505         static DECLARE_WORK(cad_work, deferred_cad, NULL);
506 
507         if (C_A_D)
508                 schedule_work(&cad_work);
509         else
510                 kill_proc(cad_pid, SIGINT, 1);
511 }
512         
513 
514 /*
515  * Unprivileged users may change the real gid to the effective gid
516  * or vice versa.  (BSD-style)
517  *
518  * If you set the real gid at all, or set the effective gid to a value not
519  * equal to the real gid, then the saved gid is set to the new effective gid.
520  *
521  * This makes it possible for a setgid program to completely drop its
522  * privileges, which is often a useful assertion to make when you are doing
523  * a security audit over a program.
524  *
525  * The general idea is that a program which uses just setregid() will be
526  * 100% compatible with BSD.  A program which uses just setgid() will be
527  * 100% compatible with POSIX with saved IDs. 
528  *
529  * SMP: There are not races, the GIDs are checked only by filesystem
530  *      operations (as far as semantic preservation is concerned).
531  */
532 asmlinkage long sys_setregid(gid_t rgid, gid_t egid)
533 {
534         int old_rgid = current->gid;
535         int old_egid = current->egid;
536         int new_rgid = old_rgid;
537         int new_egid = old_egid;
538         int retval;
539 
540         retval = security_task_setgid(rgid, egid, (gid_t)-1, LSM_SETID_RE);
541         if (retval)
542                 return retval;
543 
544         if (rgid != (gid_t) -1) {
545                 if ((old_rgid == rgid) ||
546                     (current->egid==rgid) ||
547                     capable(CAP_SETGID))
548                         new_rgid = rgid;
549                 else
550                         return -EPERM;
551         }
552         if (egid != (gid_t) -1) {
553                 if ((old_rgid == egid) ||
554                     (current->egid == egid) ||
555                     (current->sgid == egid) ||
556                     capable(CAP_SETGID))
557                         new_egid = egid;
558                 else {
559                         return -EPERM;
560                 }
561         }
562         if (new_egid != old_egid)
563         {
564                 current->mm->dumpable = 0;
565                 wmb();
566         }
567         if (rgid != (gid_t) -1 ||
568             (egid != (gid_t) -1 && egid != old_rgid))
569                 current->sgid = new_egid;
570         current->fsgid = new_egid;
571         current->egid = new_egid;
572         current->gid = new_rgid;
573         return 0;
574 }
575 
576 /*
577  * setgid() is implemented like SysV w/ SAVED_IDS 
578  *
579  * SMP: Same implicit races as above.
580  */
581 asmlinkage long sys_setgid(gid_t gid)
582 {
583         int old_egid = current->egid;
584         int retval;
585 
586         retval = security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_ID);
587         if (retval)
588                 return retval;
589 
590         if (capable(CAP_SETGID))
591         {
592                 if(old_egid != gid)
593                 {
594                         current->mm->dumpable=0;
595                         wmb();
596                 }
597                 current->gid = current->egid = current->sgid = current->fsgid = gid;
598         }
599         else if ((gid == current->gid) || (gid == current->sgid))
600         {
601                 if(old_egid != gid)
602                 {
603                         current->mm->dumpable=0;
604                         wmb();
605                 }
606                 current->egid = current->fsgid = gid;
607         }
608         else
609                 return -EPERM;
610         return 0;
611 }
612   
613 static int set_user(uid_t new_ruid, int dumpclear)
614 {
615         struct user_struct *new_user;
616 
617         new_user = alloc_uid(new_ruid);
618         if (!new_user)
619                 return -EAGAIN;
620 
621         if (atomic_read(&new_user->processes) >=
622                                 current->rlim[RLIMIT_NPROC].rlim_cur &&
623                         new_user != &root_user) {
624                 free_uid(new_user);
625                 return -EAGAIN;
626         }
627 
628         switch_uid(new_user);
629 
630         if(dumpclear)
631         {
632                 current->mm->dumpable = 0;
633                 wmb();
634         }
635         current->uid = new_ruid;
636         return 0;
637 }
638 
639 /*
640  * Unprivileged users may change the real uid to the effective uid
641  * or vice versa.  (BSD-style)
642  *
643  * If you set the real uid at all, or set the effective uid to a value not
644  * equal to the real uid, then the saved uid is set to the new effective uid.
645  *
646  * This makes it possible for a setuid program to completely drop its
647  * privileges, which is often a useful assertion to make when you are doing
648  * a security audit over a program.
649  *
650  * The general idea is that a program which uses just setreuid() will be
651  * 100% compatible with BSD.  A program which uses just setuid() will be
652  * 100% compatible with POSIX with saved IDs. 
653  */
654 asmlinkage long sys_setreuid(uid_t ruid, uid_t euid)
655 {
656         int old_ruid, old_euid, old_suid, new_ruid, new_euid;
657         int retval;
658 
659         retval = security_task_setuid(ruid, euid, (uid_t)-1, LSM_SETID_RE);
660         if (retval)
661                 return retval;
662 
663         new_ruid = old_ruid = current->uid;
664         new_euid = old_euid = current->euid;
665         old_suid = current->suid;
666 
667         if (ruid != (uid_t) -1) {
668                 new_ruid = ruid;
669                 if ((old_ruid != ruid) &&
670                     (current->euid != ruid) &&
671                     !capable(CAP_SETUID))
672                         return -EPERM;
673         }
674 
675         if (euid != (uid_t) -1) {
676                 new_euid = euid;
677                 if ((old_ruid != euid) &&
678                     (current->euid != euid) &&
679                     (current->suid != euid) &&
680                     !capable(CAP_SETUID))
681                         return -EPERM;
682         }
683 
684         if (new_ruid != old_ruid && set_user(new_ruid, new_euid != old_euid) < 0)
685                 return -EAGAIN;
686 
687         if (new_euid != old_euid)
688         {
689                 current->mm->dumpable=0;
690                 wmb();
691         }
692         current->fsuid = current->euid = new_euid;
693         if (ruid != (uid_t) -1 ||
694             (euid != (uid_t) -1 && euid != old_ruid))
695                 current->suid = current->euid;
696         current->fsuid = current->euid;
697 
698         return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RE);
699 }
700 
701 
702                 
703 /*
704  * setuid() is implemented like SysV with SAVED_IDS 
705  * 
706  * Note that SAVED_ID's is deficient in that a setuid root program
707  * like sendmail, for example, cannot set its uid to be a normal 
708  * user and then switch back, because if you're root, setuid() sets
709  * the saved uid too.  If you don't like this, blame the bright people
710  * in the POSIX committee and/or USG.  Note that the BSD-style setreuid()
711  * will allow a root program to temporarily drop privileges and be able to
712  * regain them by swapping the real and effective uid.  
713  */
714 asmlinkage long sys_setuid(uid_t uid)
715 {
716         int old_euid = current->euid;
717         int old_ruid, old_suid, new_ruid, new_suid;
718         int retval;
719 
720         retval = security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_ID);
721         if (retval)
722                 return retval;
723 
724         old_ruid = new_ruid = current->uid;
725         old_suid = current->suid;
726         new_suid = old_suid;
727         
728         if (capable(CAP_SETUID)) {
729                 if (uid != old_ruid && set_user(uid, old_euid != uid) < 0)
730                         return -EAGAIN;
731                 new_suid = uid;
732         } else if ((uid != current->uid) && (uid != new_suid))
733                 return -EPERM;
734 
735         if (old_euid != uid)
736         {
737                 current->mm->dumpable = 0;
738                 wmb();
739         }
740         current->fsuid = current->euid = uid;
741         current->suid = new_suid;
742 
743         return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_ID);
744 }
745 
746 
747 /*
748  * This function implements a generic ability to update ruid, euid,
749  * and suid.  This allows you to implement the 4.4 compatible seteuid().
750  */
751 asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid)
752 {
753         int old_ruid = current->uid;
754         int old_euid = current->euid;
755         int old_suid = current->suid;
756         int retval;
757 
758         retval = security_task_setuid(ruid, euid, suid, LSM_SETID_RES);
759         if (retval)
760                 return retval;
761 
762         if (!capable(CAP_SETUID)) {
763                 if ((ruid != (uid_t) -1) && (ruid != current->uid) &&
764                     (ruid != current->euid) && (ruid != current->suid))
765                         return -EPERM;
766                 if ((euid != (uid_t) -1) && (euid != current->uid) &&
767                     (euid != current->euid) && (euid != current->suid))
768                         return -EPERM;
769                 if ((suid != (uid_t) -1) && (suid != current->uid) &&
770                     (suid != current->euid) && (suid != current->suid))
771                         return -EPERM;
772         }
773         if (ruid != (uid_t) -1) {
774                 if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
775                         return -EAGAIN;
776         }
777         if (euid != (uid_t) -1) {
778                 if (euid != current->euid)
779                 {
780                         current->mm->dumpable = 0;
781                         wmb();
782                 }
783                 current->euid = euid;
784         }
785         current->fsuid = current->euid;
786         if (suid != (uid_t) -1)
787                 current->suid = suid;
788 
789         return security_task_post_setuid(old_ruid, old_euid, old_suid, LSM_SETID_RES);
790 }
791 
792 asmlinkage long sys_getresuid(uid_t *ruid, uid_t *euid, uid_t *suid)
793 {
794         int retval;
795 
796         if (!(retval = put_user(current->uid, ruid)) &&
797             !(retval = put_user(current->euid, euid)))
798                 retval = put_user(current->suid, suid);
799 
800         return retval;
801 }
802 
803 /*
804  * Same as above, but for rgid, egid, sgid.
805  */
806 asmlinkage long sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
807 {
808         int retval;
809 
810         retval = security_task_setgid(rgid, egid, sgid, LSM_SETID_RES);
811         if (retval)
812                 return retval;
813 
814         if (!capable(CAP_SETGID)) {
815                 if ((rgid != (gid_t) -1) && (rgid != current->gid) &&
816                     (rgid != current->egid) && (rgid != current->sgid))
817                         return -EPERM;
818                 if ((egid != (gid_t) -1) && (egid != current->gid) &&
819                     (egid != current->egid) && (egid != current->sgid))
820                         return -EPERM;
821                 if ((sgid != (gid_t) -1) && (sgid != current->gid) &&
822                     (sgid != current->egid) && (sgid != current->sgid))
823                         return -EPERM;
824         }
825         if (egid != (gid_t) -1) {
826                 if (egid != current->egid)
827                 {
828                         current->mm->dumpable = 0;
829                         wmb();
830                 }
831                 current->egid = egid;
832         }
833         current->fsgid = current->egid;
834         if (rgid != (gid_t) -1)
835                 current->gid = rgid;
836         if (sgid != (gid_t) -1)
837                 current->sgid = sgid;
838         return 0;
839 }
840 
841 asmlinkage long sys_getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid)
842 {
843         int retval;
844 
845         if (!(retval = put_user(current->gid, rgid)) &&
846             !(retval = put_user(current->egid, egid)))
847                 retval = put_user(current->sgid, sgid);
848 
849         return retval;
850 }
851 
852 
853 /*
854  * "setfsuid()" sets the fsuid - the uid used for filesystem checks. This
855  * is used for "access()" and for the NFS daemon (letting nfsd stay at
856  * whatever uid it wants to). It normally shadows "euid", except when
857  * explicitly set by setfsuid() or for access..
858  */
859 asmlinkage long sys_setfsuid(uid_t uid)
860 {
861         int old_fsuid;
862 
863         old_fsuid = current->fsuid;
864         if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS))
865                 return old_fsuid;
866 
867         if (uid == current->uid || uid == current->euid ||
868             uid == current->suid || uid == current->fsuid || 
869             capable(CAP_SETUID))
870         {
871                 if (uid != old_fsuid)
872                 {
873                         current->mm->dumpable = 0;
874                         wmb();
875                 }
876                 current->fsuid = uid;
877         }
878 
879         security_task_post_setuid(old_fsuid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS);
880 
881         return old_fsuid;
882 }
883 
884 /*
885  * Samma på svenska..
886  */
887 asmlinkage long sys_setfsgid(gid_t gid)
888 {
889         int old_fsgid;
890 
891         old_fsgid = current->fsgid;
892         if (security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_FS))
893                 return old_fsgid;
894 
895         if (gid == current->gid || gid == current->egid ||
896             gid == current->sgid || gid == current->fsgid || 
897             capable(CAP_SETGID))
898         {
899                 if (gid != old_fsgid)
900                 {
901                         current->mm->dumpable = 0;
902                         wmb();
903                 }
904                 current->fsgid = gid;
905         }
906         return old_fsgid;
907 }
908 
909 asmlinkage long sys_times(struct tms __user * tbuf)
910 {
911         /*
912          *      In the SMP world we might just be unlucky and have one of
913          *      the times increment as we use it. Since the value is an
914          *      atomically safe type this is just fine. Conceptually its
915          *      as if the syscall took an instant longer to occur.
916          */
917         if (tbuf) {
918                 struct tms tmp;
919                 tmp.tms_utime = jiffies_to_clock_t(current->utime);
920                 tmp.tms_stime = jiffies_to_clock_t(current->stime);
921                 tmp.tms_cutime = jiffies_to_clock_t(current->cutime);
922                 tmp.tms_cstime = jiffies_to_clock_t(current->cstime);
923                 if (copy_to_user(tbuf, &tmp, sizeof(struct tms)))
924                         return -EFAULT;
925         }
926         return (long) jiffies_64_to_clock_t(get_jiffies_64());
927 }
928 
929 /*
930  * This needs some heavy checking ...
931  * I just haven't the stomach for it. I also don't fully
932  * understand sessions/pgrp etc. Let somebody who does explain it.
933  *
934  * OK, I think I have the protection semantics right.... this is really
935  * only important on a multi-user system anyway, to make sure one user
936  * can't send a signal to a process owned by another.  -TYT, 12/12/91
937  *
938  * Auch. Had to add the 'did_exec' flag to conform completely to POSIX.
939  * LBT 04.03.94
940  */
941 
942 asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
943 {
944         struct task_struct *p;
945         int err = -EINVAL;
946 
947         if (!pid)
948                 pid = current->pid;
949         if (!pgid)
950                 pgid = pid;
951         if (pgid < 0)
952                 return -EINVAL;
953 
954         /* From this point forward we keep holding onto the tasklist lock
955          * so that our parent does not change from under us. -DaveM
956          */
957         write_lock_irq(&tasklist_lock);
958 
959         err = -ESRCH;
960         p = find_task_by_pid(pid);
961         if (!p)
962                 goto out;
963 
964         err = -EINVAL;
965         if (!thread_group_leader(p))
966                 goto out;
967 
968         if (p->parent == current || p->real_parent == current) {
969                 err = -EPERM;
970                 if (p->session != current->session)
971                         goto out;
972                 err = -EACCES;
973                 if (p->did_exec)
974                         goto out;
975         } else {
976                 err = -ESRCH;
977                 if (p != current)
978                         goto out;
979         }
980 
981         err = -EPERM;
982         if (p->leader)
983                 goto out;
984 
985         if (pgid != pid) {
986                 struct task_struct *p;
987                 struct pid *pid;
988                 struct list_head *l;
989 
990                 for_each_task_pid(pgid, PIDTYPE_PGID, p, l, pid)
991                         if (p->session == current->session)
992                                 goto ok_pgid;
993                 goto out;
994         }
995 
996 ok_pgid:
997         err = security_task_setpgid(p, pgid);
998         if (err)
999                 goto out;
1000 
1001         if (process_group(p) != pgid) {
1002                 detach_pid(p, PIDTYPE_PGID);
1003                 p->group_leader->__pgrp = pgid;
1004                 attach_pid(p, PIDTYPE_PGID, pgid);
1005         }
1006 
1007         err = 0;
1008 out:
1009         /* All paths lead to here, thus we are safe. -DaveM */
1010         write_unlock_irq(&tasklist_lock);
1011         return err;
1012 }
1013 
1014 asmlinkage long sys_getpgid(pid_t pid)
1015 {
1016         if (!pid) {
1017                 return process_group(current);
1018         } else {
1019                 int retval;
1020                 struct task_struct *p;
1021 
1022                 read_lock(&tasklist_lock);
1023                 p = find_task_by_pid(pid);
1024 
1025                 retval = -ESRCH;
1026                 if (p) {
1027                         retval = security_task_getpgid(p);
1028                         if (!retval)
1029                                 retval = process_group(p);
1030                 }
1031                 read_unlock(&tasklist_lock);
1032                 return retval;
1033         }
1034 }
1035 
1036 asmlinkage long sys_getpgrp(void)
1037 {
1038         /* SMP - assuming writes are word atomic this is fine */
1039         return process_group(current);
1040 }
1041 
1042 asmlinkage long sys_getsid(pid_t pid)
1043 {
1044         if (!pid) {
1045                 return current->session;
1046         } else {
1047                 int retval;
1048                 struct task_struct *p;
1049 
1050                 read_lock(&tasklist_lock);
1051                 p = find_task_by_pid(pid);
1052 
1053                 retval = -ESRCH;
1054                 if(p) {
1055                         retval = security_task_getsid(p);
1056                         if (!retval)
1057                                 retval = p->session;
1058                 }
1059                 read_unlock(&tasklist_lock);
1060                 return retval;
1061         }
1062 }
1063 
1064 asmlinkage long sys_setsid(void)
1065 {
1066         struct pid *pid;
1067         int err = -EPERM;
1068 
1069         if (!thread_group_leader(current))
1070                 return -EINVAL;
1071 
1072         write_lock_irq(&tasklist_lock);
1073 
1074         pid = find_pid(PIDTYPE_PGID, current->pid);
1075         if (pid)
1076                 goto out;
1077 
1078         current->leader = 1;
1079         __set_special_pids(current->pid, current->pid);
1080         current->tty = NULL;
1081         current->tty_old_pgrp = 0;
1082         err = process_group(current);
1083 out:
1084         write_unlock_irq(&tasklist_lock);
1085         return err;
1086 }
1087 
1088 /*
1089  * Supplementary group IDs
1090  */
1091 asmlinkage long sys_getgroups(int gidsetsize, gid_t __user *grouplist)
1092 {
1093         int i;
1094         
1095         /*
1096          *      SMP: Nobody else can change our grouplist. Thus we are
1097          *      safe.
1098          */
1099 
1100         if (gidsetsize < 0)
1101                 return -EINVAL;
1102         i = current->ngroups;
1103         if (gidsetsize) {
1104                 if (i > gidsetsize)
1105                         return -EINVAL;
1106                 if (copy_to_user(grouplist, current->groups, sizeof(gid_t)*i))
1107                         return -EFAULT;
1108         }
1109         return i;
1110 }
1111 
1112 /*
1113  *      SMP: Our groups are not shared. We can copy to/from them safely
1114  *      without another task interfering.
1115  */
1116  
1117 asmlinkage long sys_setgroups(int gidsetsize, gid_t __user *grouplist)
1118 {
1119         gid_t groups[NGROUPS];
1120         int retval;
1121 
1122         if (!capable(CAP_SETGID))
1123                 return -EPERM;
1124         if ((unsigned) gidsetsize > NGROUPS)
1125                 return -EINVAL;
1126         if (copy_from_user(groups, grouplist, gidsetsize * sizeof(gid_t)))
1127                 return -EFAULT;
1128         retval = security_task_setgroups(gidsetsize, groups);
1129         if (retval)
1130                 return retval;
1131         memcpy(current->groups, groups, gidsetsize * sizeof(gid_t));
1132         current->ngroups = gidsetsize;
1133         return 0;
1134 }
1135 
1136 static int supplemental_group_member(gid_t grp)
1137 {
1138         int i = current->ngroups;
1139 
1140         if (i) {
1141                 gid_t *groups = current->groups;
1142                 do {
1143                         if (*groups == grp)
1144                                 return 1;
1145                         groups++;
1146                         i--;
1147                 } while (i);
1148         }
1149         return 0;
1150 }
1151 
1152 /*
1153  * Check whether we're fsgid/egid or in the supplemental group..
1154  */
1155 int in_group_p(gid_t grp)
1156 {
1157         int retval = 1;
1158         if (grp != current->fsgid)
1159                 retval = supplemental_group_member(grp);
1160         return retval;
1161 }
1162 
1163 EXPORT_SYMBOL(in_group_p);
1164 
1165 int in_egroup_p(gid_t grp)
1166 {
1167         int retval = 1;
1168         if (grp != current->egid)
1169                 retval = supplemental_group_member(grp);
1170         return retval;
1171 }
1172 
1173 EXPORT_SYMBOL(in_egroup_p);
1174 
1175 DECLARE_RWSEM(uts_sem);
1176 
1177 EXPORT_SYMBOL(uts_sem);
1178 
1179 asmlinkage long sys_newuname(struct new_utsname __user * name)
1180 {
1181         int errno = 0;
1182 
1183         down_read(&uts_sem);
1184         if (copy_to_user(name,&system_utsname,sizeof *name))
1185                 errno = -EFAULT;
1186         up_read(&uts_sem);
1187         return errno;
1188 }
1189 
1190 asmlinkage long sys_sethostname(char __user *name, int len)
1191 {
1192         int errno;
1193         char tmp[__NEW_UTS_LEN];
1194 
1195         if (!capable(CAP_SYS_ADMIN))
1196                 return -EPERM;
1197         if (len < 0 || len > __NEW_UTS_LEN)
1198                 return -EINVAL;
1199         down_write(&uts_sem);
1200         errno = -EFAULT;
1201         if (!copy_from_user(tmp, name, len)) {
1202                 memcpy(system_utsname.nodename, tmp, len);
1203                 system_utsname.nodename[len] = 0;
1204                 errno = 0;
1205         }
1206         up_write(&uts_sem);
1207         return errno;
1208 }
1209 
1210 asmlinkage long sys_gethostname(char __user *name, int len)
1211 {
1212         int i, errno;
1213 
1214         if (len < 0)
1215                 return -EINVAL;
1216         down_read(&uts_sem);
1217         i = 1 + strlen(system_utsname.nodename);
1218         if (i > len)
1219                 i = len;
1220         errno = 0;
1221         if (copy_to_user(name, system_utsname.nodename, i))
1222                 errno = -EFAULT;
1223         up_read(&uts_sem);
1224         return errno;
1225 }
1226 
1227 /*
1228  * Only setdomainname; getdomainname can be implemented by calling
1229  * uname()
1230  */
1231 asmlinkage long sys_setdomainname(char __user *name, int len)
1232 {
1233         int errno;
1234         char tmp[__NEW_UTS_LEN];
1235 
1236         if (!capable(CAP_SYS_ADMIN))
1237                 return -EPERM;
1238         if (len < 0 || len > __NEW_UTS_LEN)
1239                 return -EINVAL;
1240 
1241         down_write(&uts_sem);
1242         errno = -EFAULT;
1243         if (!copy_from_user(tmp, name, len)) {
1244                 memcpy(system_utsname.domainname, tmp, len);
1245                 system_utsname.domainname[len] = 0;
1246                 errno = 0;
1247         }
1248         up_write(&uts_sem);
1249         return errno;
1250 }
1251 
1252 asmlinkage long sys_getrlimit(unsigned int resource, struct rlimit __user *rlim)
1253 {
1254         if (resource >= RLIM_NLIMITS)
1255                 return -EINVAL;
1256         else
1257                 return copy_to_user(rlim, current->rlim + resource, sizeof(*rlim))
1258                         ? -EFAULT : 0;
1259 }
1260 
1261 #if defined(COMPAT_RLIM_OLD_INFINITY) || !(defined(CONFIG_IA64) || defined(CONFIG_V850))
1262 
1263 /*
1264  *      Back compatibility for getrlimit. Needed for some apps.
1265  */
1266  
1267 asmlinkage long sys_old_getrlimit(unsigned int resource, struct rlimit __user *rlim)
1268 {
1269         struct rlimit x;
1270         if (resource >= RLIM_NLIMITS)
1271                 return -EINVAL;
1272 
1273         memcpy(&x, current->rlim + resource, sizeof(*rlim));
1274         if(x.rlim_cur > 0x7FFFFFFF)
1275                 x.rlim_cur = 0x7FFFFFFF;
1276         if(x.rlim_max > 0x7FFFFFFF)
1277                 x.rlim_max = 0x7FFFFFFF;
1278         return copy_to_user(rlim, &x, sizeof(x))?-EFAULT:0;
1279 }
1280 
1281 #endif
1282 
1283 asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim)
1284 {
1285         struct rlimit new_rlim, *old_rlim;
1286         int retval;
1287 
1288         if (resource >= RLIM_NLIMITS)
1289                 return -EINVAL;
1290         if(copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
1291                 return -EFAULT;
1292        if (new_rlim.rlim_cur > new_rlim.rlim_max)
1293                return -EINVAL;
1294         old_rlim = current->rlim + resource;
1295         if (((new_rlim.rlim_cur > old_rlim->rlim_max) ||
1296              (new_rlim.rlim_max > old_rlim->rlim_max)) &&
1297             !capable(CAP_SYS_RESOURCE))
1298                 return -EPERM;
1299         if (resource == RLIMIT_NOFILE) {
1300                 if (new_rlim.rlim_cur > NR_OPEN || new_rlim.rlim_max > NR_OPEN)
1301                         return -EPERM;
1302         }
1303 
1304         retval = security_task_setrlimit(resource, &new_rlim);
1305         if (retval)
1306                 return retval;
1307 
1308         *old_rlim = new_rlim;
1309         return 0;
1310 }
1311 
1312 /*
1313  * It would make sense to put struct rusage in the task_struct,
1314  * except that would make the task_struct be *really big*.  After
1315  * task_struct gets moved into malloc'ed memory, it would
1316  * make sense to do this.  It will make moving the rest of the information
1317  * a lot simpler!  (Which we're not doing right now because we're not
1318  * measuring them yet).
1319  *
1320  * This is SMP safe.  Either we are called from sys_getrusage on ourselves
1321  * below (we know we aren't going to exit/disappear and only we change our
1322  * rusage counters), or we are called from wait4() on a process which is
1323  * either stopped or zombied.  In the zombied case the task won't get
1324  * reaped till shortly after the call to getrusage(), in both cases the
1325  * task being examined is in a frozen state so the counters won't change.
1326  *
1327  * FIXME! Get the fault counts properly!
1328  */
1329 int getrusage(struct task_struct *p, int who, struct rusage __user *ru)
1330 {
1331         struct rusage r;
1332 
1333         memset((char *) &r, 0, sizeof(r));
1334         switch (who) {
1335                 case RUSAGE_SELF:
1336                         jiffies_to_timeval(p->utime, &r.ru_utime);
1337                         jiffies_to_timeval(p->stime, &r.ru_stime);
1338                         r.ru_nvcsw = p->nvcsw;
1339                         r.ru_nivcsw = p->nivcsw;
1340                         r.ru_minflt = p->min_flt;
1341                         r.ru_majflt = p->maj_flt;
1342                         r.ru_nswap = p->nswap;
1343                         break;
1344                 case RUSAGE_CHILDREN:
1345                         jiffies_to_timeval(p->cutime, &r.ru_utime);
1346                         jiffies_to_timeval(p->cstime, &r.ru_stime);
1347                         r.ru_nvcsw = p->cnvcsw;
1348                         r.ru_nivcsw = p->cnivcsw;
1349                         r.ru_minflt = p->cmin_flt;
1350                         r.ru_majflt = p->cmaj_flt;
1351                         r.ru_nswap = p->cnswap;
1352                         break;
1353                 default:
1354                         jiffies_to_timeval(p->utime + p->cutime, &r.ru_utime);
1355                         jiffies_to_timeval(p->stime + p->cstime, &r.ru_stime);
1356                         r.ru_nvcsw = p->nvcsw + p->cnvcsw;
1357                         r.ru_nivcsw = p->nivcsw + p->cnivcsw;
1358                         r.ru_minflt = p->min_flt + p->cmin_flt;
1359                         r.ru_majflt = p->maj_flt + p->cmaj_flt;
1360                         r.ru_nswap = p->nswap + p->cnswap;
1361                         break;
1362         }
1363         return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
1364 }
1365 
1366 asmlinkage long sys_getrusage(int who, struct rusage __user *ru)
1367 {
1368         if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
1369                 return -EINVAL;
1370         return getrusage(current, who, ru);
1371 }
1372 
1373 asmlinkage long sys_umask(int mask)
1374 {
1375         mask = xchg(&current->fs->umask, mask & S_IRWXUGO);
1376         return mask;
1377 }
1378     
1379 asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
1380                           unsigned long arg4, unsigned long arg5)
1381 {
1382         int error;
1383         int sig;
1384 
1385         error = security_task_prctl(option, arg2, arg3, arg4, arg5);
1386         if (error)
1387                 return error;
1388 
1389         switch (option) {
1390                 case PR_SET_PDEATHSIG:
1391                         sig = arg2;
1392                         if (sig < 0 || sig > _NSIG) {
1393                                 error = -EINVAL;
1394                                 break;
1395                         }
1396                         current->pdeath_signal = sig;
1397                         break;
1398                 case PR_GET_PDEATHSIG:
1399                         error = put_user(current->pdeath_signal, (int __user *)arg2);
1400                         break;
1401                 case PR_GET_DUMPABLE:
1402                         if (current->mm->dumpable)
1403                                 error = 1;
1404                         break;
1405                 case PR_SET_DUMPABLE:
1406                         if (arg2 != 0 && arg2 != 1) {
1407                                 error = -EINVAL;
1408                                 break;
1409                         }
1410                         current->mm->dumpable = arg2;
1411                         break;
1412 
1413                 case PR_SET_UNALIGN:
1414                         error = SET_UNALIGN_CTL(current, arg2);
1415                         break;
1416                 case PR_GET_UNALIGN:
1417                         error = GET_UNALIGN_CTL(current, arg2);
1418                         break;
1419                 case PR_SET_FPEMU:
1420                         error = SET_FPEMU_CTL(current, arg2);
1421                         break;
1422                 case PR_GET_FPEMU:
1423                         error = GET_FPEMU_CTL(current, arg2);
1424                         break;
1425                 case PR_SET_FPEXC:
1426                         error = SET_FPEXC_CTL(current, arg2);
1427                         break;
1428                 case PR_GET_FPEXC:
1429                         error = GET_FPEXC_CTL(current, arg2);
1430                         break;
1431                 case PR_GET_TIMING:
1432                         error = PR_TIMING_STATISTICAL;
1433                         break;
1434                 case PR_SET_TIMING:
1435                         if (arg2 == PR_TIMING_STATISTICAL)
1436                                 error = 0;
1437                         else
1438                                 error = -EINVAL;
1439                         break;
1440 
1441                 case PR_GET_KEEPCAPS:
1442                         if (current->keep_capabilities)
1443                                 error = 1;
1444                         break;
1445                 case PR_SET_KEEPCAPS:
1446                         if (arg2 != 0 && arg2 != 1) {
1447                                 error = -EINVAL;
1448                                 break;
1449                         }
1450                         current->keep_capabilities = arg2;
1451                         break;
1452                 default:
1453                         error = -EINVAL;
1454                         break;
1455         }
1456         return error;
1457 }
1458 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp