Ignore:
File:
1 edited

Legend:

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

    r6b10dab rda1bafb  
    4141#include <proc/task.h>
    4242#include <synch/spinlock.h>
     43#include <syscall/sysarg64.h>
    4344#include <syscall/copy.h>
    4445#include <arch.h>
     
    7879 * The calling task must have the CAP_CAP capability.
    7980 *
    80  * @param taskid Destination task ID.
    81  * @param caps   Capabilities to grant.
     81 * @param uspace_taskid_arg Userspace structure holding destination task ID.
     82 * @param caps Capabilities to grant.
    8283 *
    8384 * @return Zero on success or an error code from @ref errno.h.
    8485 *
    8586 */
    86 static sysarg_t cap_grant(task_id_t taskid, cap_t caps)
     87unative_t sys_cap_grant(sysarg64_t *uspace_taskid_arg, cap_t caps)
    8788{
    8889        if (!(cap_get(TASK) & CAP_CAP))
    89                 return (sysarg_t) EPERM;
     90                return (unative_t) EPERM;
     91       
     92        sysarg64_t taskid_arg;
     93        int rc = copy_from_uspace(&taskid_arg, uspace_taskid_arg, sizeof(sysarg64_t));
     94        if (rc != 0)
     95                return (unative_t) rc;
    9096       
    9197        irq_spinlock_lock(&tasks_lock, true);
    92         task_t *task = task_find_by_id(taskid);
     98        task_t *task = task_find_by_id((task_id_t) taskid_arg.value);
    9399       
    94100        if ((!task) || (!context_check(CONTEXT, task->context))) {
    95101                irq_spinlock_unlock(&tasks_lock, true);
    96                 return (sysarg_t) ENOENT;
     102                return (unative_t) ENOENT;
    97103        }
    98104       
     
    110116 * attempt to revoke capabilities from itself.
    111117 *
    112  * @param taskid Destination task ID.
    113  * @param caps   Capabilities to revoke.
     118 * @param uspace_taskid_arg Userspace structure holding destination task ID.
     119 * @param caps Capabilities to revoke.
    114120 *
    115121 * @return Zero on success or an error code from @ref errno.h.
    116122 *
    117123 */
    118 static sysarg_t cap_revoke(task_id_t taskid, cap_t caps)
     124unative_t sys_cap_revoke(sysarg64_t *uspace_taskid_arg, cap_t caps)
    119125{
     126        sysarg64_t taskid_arg;
     127        int rc = copy_from_uspace(&taskid_arg, uspace_taskid_arg, sizeof(sysarg64_t));
     128        if (rc != 0)
     129                return (unative_t) rc;
     130       
    120131        irq_spinlock_lock(&tasks_lock, true);
    121132       
    122         task_t *task = task_find_by_id(taskid);
     133        task_t *task = task_find_by_id((task_id_t) taskid_arg.value);
    123134        if ((!task) || (!context_check(CONTEXT, task->context))) {
    124135                irq_spinlock_unlock(&tasks_lock, true);
    125                 return (sysarg_t) ENOENT;
     136                return (unative_t) ENOENT;
    126137        }
    127138       
     
    136147                irq_spinlock_unlock(&TASK->lock, false);
    137148                irq_spinlock_unlock(&tasks_lock, true);
    138                 return (sysarg_t) EPERM;
     149                return (unative_t) EPERM;
    139150        }
    140151       
     
    146157}
    147158
    148 #ifdef __32_BITS__
    149 
    150 /** Grant capabilities to a task (32 bits)
    151  *
    152  * The calling task must have the CAP_CAP capability.
    153  *
    154  * @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)
    161 {
    162         sysarg64_t taskid;
    163         int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
    164         if (rc != 0)
    165                 return (sysarg_t) rc;
    166        
    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.
    174  *
    175  * @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)
    182 {
    183         sysarg64_t taskid;
    184         int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
    185         if (rc != 0)
    186                 return (sysarg_t) rc;
    187        
    188         return cap_revoke((task_id_t) taskid, caps);
    189 }
    190 
    191 #endif  /* __32_BITS__ */
    192 
    193 #ifdef __64_BITS__
    194 
    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);
    224 }
    225 
    226 #endif  /* __64_BITS__ */
    227 
    228159/** @}
    229160 */
Note: See TracChangeset for help on using the changeset viewer.