uipc_sem.c (0edd2576c0e07f525c80e4aa5ff24350b55f18b7) | uipc_sem.c (15bcf785ba268a1fb2b270233a7ae56d9e0ebc3a) |
---|---|
1/*- 2 * Copyright (c) 2002 Alfred Perlstein <alfred@FreeBSD.org> 3 * Copyright (c) 2003-2005 SPARTA, Inc. | 1/*- 2 * Copyright (c) 2002 Alfred Perlstein <alfred@FreeBSD.org> 3 * Copyright (c) 2003-2005 SPARTA, Inc. |
4 * Copyright (c) 2005 Robert N. M. Watson | 4 * Copyright (c) 2005, 2016-2017 Robert N. M. Watson |
5 * All rights reserved. 6 * 7 * This software was developed for the FreeBSD Project in part by Network 8 * Associates Laboratories, the Security Research Division of Network 9 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), 10 * as part of the DARPA CHATS research program. 11 * | 5 * All rights reserved. 6 * 7 * This software was developed for the FreeBSD Project in part by Network 8 * Associates Laboratories, the Security Research Division of Network 9 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), 10 * as part of the DARPA CHATS research program. 11 * |
12 * Portions of this software were developed by BAE Systems, the University of 13 * Cambridge Computer Laboratory, and Memorial University under DARPA/AFRL 14 * contract FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent 15 * Computing (TC) research program. 16 * |
|
12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. --- 41 unchanged lines hidden (view full) --- 61#include <sys/sysctl.h> 62#include <sys/sysent.h> 63#include <sys/sysproto.h> 64#include <sys/systm.h> 65#include <sys/sx.h> 66#include <sys/user.h> 67#include <sys/vnode.h> 68 | 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions 19 * are met: 20 * 1. Redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer. 22 * 2. Redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution. --- 41 unchanged lines hidden (view full) --- 66#include <sys/sysctl.h> 67#include <sys/sysent.h> 68#include <sys/sysproto.h> 69#include <sys/systm.h> 70#include <sys/sx.h> 71#include <sys/user.h> 72#include <sys/vnode.h> 73 |
74#include <security/audit/audit.h> |
|
69#include <security/mac/mac_framework.h> 70 71FEATURE(p1003_1b_semaphores, "POSIX P1003.1B semaphores support"); 72/* 73 * TODO 74 * 75 * - Resource limits? 76 * - Replace global sem_lock with mtx_pool locks? --- 385 unchanged lines hidden (view full) --- 462 struct ksem *ks; 463 struct file *fp; 464 char *path; 465 const char *pr_path; 466 size_t pr_pathlen; 467 Fnv32_t fnv; 468 int error, fd; 469 | 75#include <security/mac/mac_framework.h> 76 77FEATURE(p1003_1b_semaphores, "POSIX P1003.1B semaphores support"); 78/* 79 * TODO 80 * 81 * - Resource limits? 82 * - Replace global sem_lock with mtx_pool locks? --- 385 unchanged lines hidden (view full) --- 468 struct ksem *ks; 469 struct file *fp; 470 char *path; 471 const char *pr_path; 472 size_t pr_pathlen; 473 Fnv32_t fnv; 474 int error, fd; 475 |
476 AUDIT_ARG_FFLAGS(flags); 477 AUDIT_ARG_MODE(mode); 478 AUDIT_ARG_VALUE(value); 479 |
|
470 if (value > SEM_VALUE_MAX) 471 return (EINVAL); 472 473 fdp = td->td_proc->p_fd; 474 mode = (mode & ~fdp->fd_cmask) & ACCESSPERMS; 475 error = falloc(td, &fp, &fd, O_CLOEXEC); 476 if (error) { 477 if (name == NULL) --- 35 unchanged lines hidden (view full) --- 513 error = EINVAL; 514 if (error) { 515 fdclose(td, fp, fd); 516 fdrop(fp, td); 517 free(path, M_KSEM); 518 return (error); 519 } 520 | 480 if (value > SEM_VALUE_MAX) 481 return (EINVAL); 482 483 fdp = td->td_proc->p_fd; 484 mode = (mode & ~fdp->fd_cmask) & ACCESSPERMS; 485 error = falloc(td, &fp, &fd, O_CLOEXEC); 486 if (error) { 487 if (name == NULL) --- 35 unchanged lines hidden (view full) --- 523 error = EINVAL; 524 if (error) { 525 fdclose(td, fp, fd); 526 fdrop(fp, td); 527 free(path, M_KSEM); 528 return (error); 529 } 530 |
531 AUDIT_ARG_UPATH1_CANON(path); |
|
521 fnv = fnv_32_str(path, FNV1_32_INIT); 522 sx_xlock(&ksem_dict_lock); 523 ks = ksem_lookup(path, fnv); 524 if (ks == NULL) { 525 /* Object does not exist, create it if requested. */ 526 if (flags & O_CREAT) { 527 ks = ksem_alloc(td->td_ucred, mode, value); 528 if (ks == NULL) --- 127 unchanged lines hidden (view full) --- 656 : strlcpy(path, pr_path, MAXPATHLEN); 657 error = copyinstr(uap->name, path + pr_pathlen, MAXPATHLEN - pr_pathlen, 658 NULL); 659 if (error) { 660 free(path, M_TEMP); 661 return (error); 662 } 663 | 532 fnv = fnv_32_str(path, FNV1_32_INIT); 533 sx_xlock(&ksem_dict_lock); 534 ks = ksem_lookup(path, fnv); 535 if (ks == NULL) { 536 /* Object does not exist, create it if requested. */ 537 if (flags & O_CREAT) { 538 ks = ksem_alloc(td->td_ucred, mode, value); 539 if (ks == NULL) --- 127 unchanged lines hidden (view full) --- 667 : strlcpy(path, pr_path, MAXPATHLEN); 668 error = copyinstr(uap->name, path + pr_pathlen, MAXPATHLEN - pr_pathlen, 669 NULL); 670 if (error) { 671 free(path, M_TEMP); 672 return (error); 673 } 674 |
675 AUDIT_ARG_UPATH1_CANON(path); |
|
664 fnv = fnv_32_str(path, FNV1_32_INIT); 665 sx_xlock(&ksem_dict_lock); 666 error = ksem_remove(path, fnv, td->td_ucred); 667 sx_xunlock(&ksem_dict_lock); 668 free(path, M_TEMP); 669 670 return (error); 671} --- 7 unchanged lines hidden (view full) --- 679sys_ksem_close(struct thread *td, struct ksem_close_args *uap) 680{ 681 cap_rights_t rights; 682 struct ksem *ks; 683 struct file *fp; 684 int error; 685 686 /* No capability rights required to close a semaphore. */ | 676 fnv = fnv_32_str(path, FNV1_32_INIT); 677 sx_xlock(&ksem_dict_lock); 678 error = ksem_remove(path, fnv, td->td_ucred); 679 sx_xunlock(&ksem_dict_lock); 680 free(path, M_TEMP); 681 682 return (error); 683} --- 7 unchanged lines hidden (view full) --- 691sys_ksem_close(struct thread *td, struct ksem_close_args *uap) 692{ 693 cap_rights_t rights; 694 struct ksem *ks; 695 struct file *fp; 696 int error; 697 698 /* No capability rights required to close a semaphore. */ |
699 AUDIT_ARG_FD(uap->id); |
|
687 error = ksem_get(td, uap->id, cap_rights_init(&rights), &fp); 688 if (error) 689 return (error); 690 ks = fp->f_data; 691 if (ks->ks_flags & KS_ANONYMOUS) { 692 fdrop(fp, td); 693 return (EINVAL); 694 } --- 10 unchanged lines hidden (view full) --- 705int 706sys_ksem_post(struct thread *td, struct ksem_post_args *uap) 707{ 708 cap_rights_t rights; 709 struct file *fp; 710 struct ksem *ks; 711 int error; 712 | 700 error = ksem_get(td, uap->id, cap_rights_init(&rights), &fp); 701 if (error) 702 return (error); 703 ks = fp->f_data; 704 if (ks->ks_flags & KS_ANONYMOUS) { 705 fdrop(fp, td); 706 return (EINVAL); 707 } --- 10 unchanged lines hidden (view full) --- 718int 719sys_ksem_post(struct thread *td, struct ksem_post_args *uap) 720{ 721 cap_rights_t rights; 722 struct file *fp; 723 struct ksem *ks; 724 int error; 725 |
726 AUDIT_ARG_FD(uap->id); |
|
713 error = ksem_get(td, uap->id, 714 cap_rights_init(&rights, CAP_SEM_POST), &fp); 715 if (error) 716 return (error); 717 ks = fp->f_data; 718 719 mtx_lock(&sem_lock); 720#ifdef MAC --- 76 unchanged lines hidden (view full) --- 797 struct timespec ts1, ts2; 798 struct timeval tv; 799 cap_rights_t rights; 800 struct file *fp; 801 struct ksem *ks; 802 int error; 803 804 DP((">>> kern_sem_wait entered! pid=%d\n", (int)td->td_proc->p_pid)); | 727 error = ksem_get(td, uap->id, 728 cap_rights_init(&rights, CAP_SEM_POST), &fp); 729 if (error) 730 return (error); 731 ks = fp->f_data; 732 733 mtx_lock(&sem_lock); 734#ifdef MAC --- 76 unchanged lines hidden (view full) --- 811 struct timespec ts1, ts2; 812 struct timeval tv; 813 cap_rights_t rights; 814 struct file *fp; 815 struct ksem *ks; 816 int error; 817 818 DP((">>> kern_sem_wait entered! pid=%d\n", (int)td->td_proc->p_pid)); |
819 AUDIT_ARG_FD(id); |
|
805 error = ksem_get(td, id, cap_rights_init(&rights, CAP_SEM_WAIT), &fp); 806 if (error) 807 return (error); 808 ks = fp->f_data; 809 mtx_lock(&sem_lock); 810 DP((">>> kern_sem_wait critical section entered! pid=%d\n", 811 (int)td->td_proc->p_pid)); 812#ifdef MAC --- 51 unchanged lines hidden (view full) --- 864int 865sys_ksem_getvalue(struct thread *td, struct ksem_getvalue_args *uap) 866{ 867 cap_rights_t rights; 868 struct file *fp; 869 struct ksem *ks; 870 int error, val; 871 | 820 error = ksem_get(td, id, cap_rights_init(&rights, CAP_SEM_WAIT), &fp); 821 if (error) 822 return (error); 823 ks = fp->f_data; 824 mtx_lock(&sem_lock); 825 DP((">>> kern_sem_wait critical section entered! pid=%d\n", 826 (int)td->td_proc->p_pid)); 827#ifdef MAC --- 51 unchanged lines hidden (view full) --- 879int 880sys_ksem_getvalue(struct thread *td, struct ksem_getvalue_args *uap) 881{ 882 cap_rights_t rights; 883 struct file *fp; 884 struct ksem *ks; 885 int error, val; 886 |
887 AUDIT_ARG_FD(uap->id); |
|
872 error = ksem_get(td, uap->id, 873 cap_rights_init(&rights, CAP_SEM_GETVALUE), &fp); 874 if (error) 875 return (error); 876 ks = fp->f_data; 877 878 mtx_lock(&sem_lock); 879#ifdef MAC --- 21 unchanged lines hidden (view full) --- 901sys_ksem_destroy(struct thread *td, struct ksem_destroy_args *uap) 902{ 903 cap_rights_t rights; 904 struct file *fp; 905 struct ksem *ks; 906 int error; 907 908 /* No capability rights required to close a semaphore. */ | 888 error = ksem_get(td, uap->id, 889 cap_rights_init(&rights, CAP_SEM_GETVALUE), &fp); 890 if (error) 891 return (error); 892 ks = fp->f_data; 893 894 mtx_lock(&sem_lock); 895#ifdef MAC --- 21 unchanged lines hidden (view full) --- 917sys_ksem_destroy(struct thread *td, struct ksem_destroy_args *uap) 918{ 919 cap_rights_t rights; 920 struct file *fp; 921 struct ksem *ks; 922 int error; 923 924 /* No capability rights required to close a semaphore. */ |
925 AUDIT_ARG_FD(uap->id); |
|
909 error = ksem_get(td, uap->id, cap_rights_init(&rights), &fp); 910 if (error) 911 return (error); 912 ks = fp->f_data; 913 if (!(ks->ks_flags & KS_ANONYMOUS)) { 914 fdrop(fp, td); 915 return (EINVAL); 916 } --- 178 unchanged lines hidden --- | 926 error = ksem_get(td, uap->id, cap_rights_init(&rights), &fp); 927 if (error) 928 return (error); 929 ks = fp->f_data; 930 if (!(ks->ks_flags & KS_ANONYMOUS)) { 931 fdrop(fp, td); 932 return (EINVAL); 933 } --- 178 unchanged lines hidden --- |