Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset a9b6bec in mainline for kernel/generic/src/security/cap.c


Ignore:
Timestamp:
2010-12-14T20:19:41Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
11658b64
Parents:
37f7cfe (diff), 228e490 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

Extra changes: ipcarg_t is sysarg_t and
IPC_GET_METHOD is IPC_GET_IMETHOD.

File:
1 edited

Legend:

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

    r37f7cfe ra9b6bec  
    4141#include <proc/task.h>
    4242#include <synch/spinlock.h>
    43 #include <syscall/sysarg64.h>
    4443#include <syscall/copy.h>
    4544#include <arch.h>
     
    7978 * The calling task must have the CAP_CAP capability.
    8079 *
    81  * @param uspace_taskid_arg Userspace structure holding destination task ID.
    82  * @param caps Capabilities to grant.
    83  *
    84  * @return Zero on success or an error code from @ref errno.h.
    85  *
    86  */
    87 unative_t sys_cap_grant(sysarg64_t *uspace_taskid_arg, cap_t caps)
     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 */
     86static sysarg_t cap_grant(task_id_t taskid, cap_t caps)
    8887{
    8988        if (!(cap_get(TASK) & CAP_CAP))
    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;
     89                return (sysarg_t) EPERM;
    9690       
    9791        irq_spinlock_lock(&tasks_lock, true);
    98         task_t *task = task_find_by_id((task_id_t) taskid_arg.value);
     92        task_t *task = task_find_by_id(taskid);
    9993       
    10094        if ((!task) || (!context_check(CONTEXT, task->context))) {
    10195                irq_spinlock_unlock(&tasks_lock, true);
    102                 return (unative_t) ENOENT;
     96                return (sysarg_t) ENOENT;
    10397        }
    10498       
     
    116110 * attempt to revoke capabilities from itself.
    117111 *
    118  * @param uspace_taskid_arg Userspace structure holding destination task ID.
    119  * @param caps Capabilities to revoke.
    120  *
    121  * @return Zero on success or an error code from @ref errno.h.
    122  *
    123  */
    124 unative_t sys_cap_revoke(sysarg64_t *uspace_taskid_arg, cap_t caps)
    125 {
    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        
     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 */
     118static sysarg_t cap_revoke(task_id_t taskid, cap_t caps)
     119{
    131120        irq_spinlock_lock(&tasks_lock, true);
    132121       
    133         task_t *task = task_find_by_id((task_id_t) taskid_arg.value);
     122        task_t *task = task_find_by_id(taskid);
    134123        if ((!task) || (!context_check(CONTEXT, task->context))) {
    135124                irq_spinlock_unlock(&tasks_lock, true);
    136                 return (unative_t) ENOENT;
     125                return (sysarg_t) ENOENT;
    137126        }
    138127       
     
    147136                irq_spinlock_unlock(&TASK->lock, false);
    148137                irq_spinlock_unlock(&tasks_lock, true);
    149                 return (unative_t) EPERM;
     138                return (sysarg_t) EPERM;
    150139        }
    151140       
     
    157146}
    158147
     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 */
     160sysarg_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 */
     181sysarg_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 */
     205sysarg_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 */
     221sysarg_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
    159228/** @}
    160229 */
Note: See TracChangeset for help on using the changeset viewer.