Changeset 719a208 in mainline for kernel/generic/src/security/perm.c


Ignore:
Timestamp:
2017-05-30T05:59:09Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f2460a50
Parents:
456c086
Message:

Rename SYS_CAP_GRANT/REVOKE to SYS_PERM_GRANT/REVOKE

File:
1 moved

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/security/perm.c

    r456c086 r719a208  
    3232
    3333/**
    34  * @file cap.c
    35  * @brief Capabilities control.
    36  *
    37  * @see cap.h
    38  */
    39 
    40 #include <security/cap.h>
     34 * @file perm.c
     35 * @brief Task permissions control.
     36 *
     37 * @see perm.h
     38 */
     39
     40#include <security/perm.h>
    4141#include <proc/task.h>
    4242#include <synch/spinlock.h>
     
    4545#include <errno.h>
    4646
    47 /** Set capabilities.
    48  *
    49  * @param task Task whose capabilities are to be changed.
    50  * @param caps New set of capabilities.
    51  *
    52  */
    53 void cap_set(task_t *task, cap_t caps)
     47/** Set permissions.
     48 *
     49 * @param task  Task whose permissions are to be changed.
     50 * @param perms New set of permissions.
     51 *
     52 */
     53void perm_set(task_t *task, perm_t perms)
    5454{
    5555        irq_spinlock_lock(&task->lock, true);
    56         task->capabilities = caps;
     56        task->perms = perms;
    5757        irq_spinlock_unlock(&task->lock, true);
    5858}
    5959
    60 /** Get capabilities.
    61  *
    62  * @param task Task whose capabilities are to be returned.
    63  *
    64  * @return Task's capabilities.
    65  *
    66  */
    67 cap_t cap_get(task_t *task)
     60/** Get permissions.
     61 *
     62 * @param task Task whose permissions are to be returned.
     63 *
     64 * @return Task's permissions.
     65 *
     66 */
     67perm_t perm_get(task_t *task)
    6868{
    6969        irq_spinlock_lock(&task->lock, true);
    70         cap_t caps = task->capabilities;
     70        perm_t perms = task->perms;
    7171        irq_spinlock_unlock(&task->lock, true);
    7272       
    73         return caps;
    74 }
    75 
    76 /** Grant capabilities to a task.
    77  *
    78  * The calling task must have the CAP_CAP capability.
    79  *
    80  * @param taskid Destination task ID.
    81  * @param caps   Capabilities to grant.
    82  *
    83  * @return Zero on success or an error code from @ref errno.h.
    84  *
    85  */
    86 static sysarg_t cap_grant(task_id_t taskid, cap_t caps)
    87 {
    88         if (!(cap_get(TASK) & CAP_CAP))
     73        return perms;
     74}
     75
     76/** Grant permissions to a task.
     77 *
     78 * The calling task must have the PERM_PERM permission.
     79 *
     80 * @param taskid Destination task ID.
     81 * @param perms   Permissions to grant.
     82 *
     83 * @return Zero on success or an error code from @ref errno.h.
     84 *
     85 */
     86static sysarg_t perm_grant(task_id_t taskid, perm_t perms)
     87{
     88        if (!(perm_get(TASK) & PERM_PERM))
    8989                return (sysarg_t) EPERM;
    9090       
     
    9898       
    9999        irq_spinlock_lock(&task->lock, false);
    100         task->capabilities |= caps;
     100        task->perms |= perms;
    101101        irq_spinlock_unlock(&task->lock, false);
    102102       
     
    105105}
    106106
    107 /** Revoke capabilities from a task.
    108  *
    109  * The calling task must have the CAP_CAP capability or the caller must
    110  * attempt to revoke capabilities from itself.
    111  *
    112  * @param taskid Destination task ID.
    113  * @param caps   Capabilities to revoke.
    114  *
    115  * @return Zero on success or an error code from @ref errno.h.
    116  *
    117  */
    118 static sysarg_t cap_revoke(task_id_t taskid, cap_t caps)
     107/** Revoke permissions from a task.
     108 *
     109 * The calling task must have the PERM_PERM permission or the caller must
     110 * attempt to revoke permissions from itself.
     111 *
     112 * @param taskid Destination task ID.
     113 * @param perms   Permissions to revoke.
     114 *
     115 * @return Zero on success or an error code from @ref errno.h.
     116 *
     117 */
     118static sysarg_t perm_revoke(task_id_t taskid, perm_t perms)
    119119{
    120120        irq_spinlock_lock(&tasks_lock, true);
     
    127127       
    128128        /*
    129          * Revoking capabilities is different from granting them in that
    130          * a task can revoke capabilities from itself even if it
    131          * doesn't have CAP_CAP.
     129         * Revoking permissions is different from granting them in that
     130         * a task can revoke permissions from itself even if it
     131         * doesn't have PERM_PERM.
    132132         */
    133133        irq_spinlock_unlock(&TASK->lock, false);
    134134       
    135         if ((!(TASK->capabilities & CAP_CAP)) || (task != TASK)) {
     135        if ((!(TASK->perms & PERM_PERM)) || (task != TASK)) {
    136136                irq_spinlock_unlock(&TASK->lock, false);
    137137                irq_spinlock_unlock(&tasks_lock, true);
     
    139139        }
    140140       
    141         task->capabilities &= ~caps;
     141        task->perms &= ~perms;
    142142        irq_spinlock_unlock(&TASK->lock, false);
    143143       
     
    148148#ifdef __32_BITS__
    149149
    150 /** Grant capabilities to a task (32 bits)
    151  *
    152  * The calling task must have the CAP_CAP capability.
     150/** Grant permissions to a task (32 bits)
     151 *
     152 * The calling task must have the PERM_PERM permission.
    153153 *
    154154 * @param uspace_taskid User-space pointer to destination task ID.
    155  * @param caps          Capabilities to grant.
    156  *
    157  * @return Zero on success or an error code from @ref errno.h.
    158  *
    159  */
    160 sysarg_t sys_cap_grant(sysarg64_t *uspace_taskid, cap_t caps)
     155 * @param perms         Permissions to grant.
     156 *
     157 * @return Zero on success or an error code from @ref errno.h.
     158 *
     159 */
     160sysarg_t sys_perm_grant(sysarg64_t *uspace_taskid, perm_t perms)
    161161{
    162162        sysarg64_t taskid;
     
    165165                return (sysarg_t) rc;
    166166       
    167         return cap_grant((task_id_t) taskid, caps);
    168 }
    169 
    170 /** Revoke capabilities from a task (32 bits)
    171  *
    172  * The calling task must have the CAP_CAP capability or the caller must
    173  * attempt to revoke capabilities from itself.
     167        return perm_grant((task_id_t) taskid, perms);
     168}
     169
     170/** Revoke permissions from a task (32 bits)
     171 *
     172 * The calling task must have the PERM_PERM permission or the caller must
     173 * attempt to revoke permissions from itself.
    174174 *
    175175 * @param uspace_taskid User-space pointer to destination task ID.
    176  * @param caps          Capabilities to revoke.
    177  *
    178  * @return Zero on success or an error code from @ref errno.h.
    179  *
    180  */
    181 sysarg_t sys_cap_revoke(sysarg64_t *uspace_taskid, cap_t caps)
     176 * @param perms         Perms to revoke.
     177 *
     178 * @return Zero on success or an error code from @ref errno.h.
     179 *
     180 */
     181sysarg_t sys_perm_revoke(sysarg64_t *uspace_taskid, perm_t perms)
    182182{
    183183        sysarg64_t taskid;
     
    186186                return (sysarg_t) rc;
    187187       
    188         return cap_revoke((task_id_t) taskid, caps);
     188        return perm_revoke((task_id_t) taskid, perms);
    189189}
    190190
     
    193193#ifdef __64_BITS__
    194194
    195 /** Grant capabilities to a task (64 bits)
    196  *
    197  * The calling task must have the CAP_CAP capability.
    198  *
    199  * @param taskid Destination task ID.
    200  * @param caps   Capabilities to grant.
    201  *
    202  * @return Zero on success or an error code from @ref errno.h.
    203  *
    204  */
    205 sysarg_t sys_cap_grant(sysarg_t taskid, cap_t caps)
    206 {
    207         return cap_grant((task_id_t) taskid, caps);
    208 }
    209 
    210 /** Revoke capabilities from a task (64 bits)
    211  *
    212  * The calling task must have the CAP_CAP capability or the caller must
    213  * attempt to revoke capabilities from itself.
    214  *
    215  * @param taskid Destination task ID.
    216  * @param caps   Capabilities to revoke.
    217  *
    218  * @return Zero on success or an error code from @ref errno.h.
    219  *
    220  */
    221 sysarg_t sys_cap_revoke(sysarg_t taskid, cap_t caps)
    222 {
    223         return cap_revoke((task_id_t) taskid, caps);
     195/** Grant permissions to a task (64 bits)
     196 *
     197 * The calling task must have the PERM_PERM permission.
     198 *
     199 * @param taskid Destination task ID.
     200 * @param perms  Permissions to grant.
     201 *
     202 * @return Zero on success or an error code from @ref errno.h.
     203 *
     204 */
     205sysarg_t sys_perm_grant(sysarg_t taskid, perm_t perms)
     206{
     207        return perm_grant((task_id_t) taskid, perms);
     208}
     209
     210/** Revoke permissions from a task (64 bits)
     211 *
     212 * The calling task must have the PERM_PERM permission or the caller must
     213 * attempt to revoke permissions from itself.
     214 *
     215 * @param taskid Destination task ID.
     216 * @param perms  Permissions to revoke.
     217 *
     218 * @return Zero on success or an error code from @ref errno.h.
     219 *
     220 */
     221sysarg_t sys_perm_revoke(sysarg_t taskid, perm_t perms)
     222{
     223        return perm_revoke((task_id_t) taskid, perms);
    224224}
    225225
Note: See TracChangeset for help on using the changeset viewer.