Changeset 2bb8648 in mainline for generic/src/security/cap.c


Ignore:
Timestamp:
2006-05-07T15:21:11Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
31282f9
Parents:
ecf3722
Message:

Add SYS_CAP_GRANT and SYS_CAP_REVOKE syscalls.
Move SYS_PREEMPT_CONTROL to ddi.c.
Add some comments and fix some small issues.

File:
1 edited

Legend:

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

    recf3722 r2bb8648  
    3737#include <proc/task.h>
    3838#include <synch/spinlock.h>
     39#include <syscall/sysarg64.h>
     40#include <syscall/copy.h>
    3941#include <arch.h>
    4042#include <typedefs.h>
     43#include <errno.h>
    4144
    4245/** Set capabilities.
     
    7881        return caps;
    7982}
     83
     84/** Grant capabilities to a task.
     85 *
     86 * The calling task must have the CAP_CAP capability.
     87 *
     88 * @param uspace_taskid_arg Userspace structure holding destination task ID.
     89 * @param caps Capabilities to grant.
     90 *
     91 * @return Zero on success or an error code from @ref errno.h.
     92 */
     93__native sys_cap_grant(sysarg64_t *uspace_taskid_arg, cap_t caps)
     94{
     95        sysarg64_t taskid_arg;
     96        task_t *t;
     97        ipl_t ipl;
     98        int rc;
     99       
     100        if (!(cap_get(TASK) & CAP_CAP))
     101                return (__native) EPERM;
     102       
     103        rc = copy_from_uspace(&taskid_arg, uspace_taskid_arg, sizeof(sysarg64_t));
     104        if (rc != 0)
     105                return (__native) rc;
     106               
     107        ipl = interrupts_disable();
     108        spinlock_lock(&tasks_lock);
     109        t = task_find_by_id((task_id_t) taskid_arg.value);
     110        if (!t) {
     111                spinlock_unlock(&tasks_lock);
     112                interrupts_restore(ipl);
     113                return (__native) ENOENT;
     114        }
     115        spinlock_unlock(&tasks_lock);
     116       
     117        cap_set(t, cap_get(t) | caps);
     118       
     119        interrupts_restore(ipl);       
     120        return 0;
     121}
     122
     123/** Revoke capabilities from a task.
     124 *
     125 * The calling task must have the CAP_CAP capability or the caller must
     126 * attempt to revoke capabilities from itself.
     127 *
     128 * @param uspace_taskid_arg Userspace structure holding destination task ID.
     129 * @param caps Capabilities to revoke.
     130 *
     131 * @return Zero on success or an error code from @ref errno.h.
     132 */
     133__native sys_cap_revoke(sysarg64_t *uspace_taskid_arg, cap_t caps)
     134{
     135        sysarg64_t taskid_arg;
     136        task_t *t;
     137        ipl_t ipl;
     138        int rc;
     139       
     140        rc = copy_from_uspace(&taskid_arg, uspace_taskid_arg, sizeof(sysarg64_t));
     141        if (rc != 0)
     142                return (__native) rc;
     143
     144        ipl = interrupts_disable();
     145        spinlock_lock(&tasks_lock);     
     146        t = task_find_by_id((task_id_t) taskid_arg.value);
     147        if (!t) {
     148                spinlock_unlock(&tasks_lock);
     149                interrupts_restore(ipl);
     150                return (__native) ENOENT;
     151        }
     152        spinlock_unlock(&tasks_lock);
     153
     154        /*
     155         * Revoking capabilities is different from granting them in that
     156         * a task can revoke capabilities from itself even if it
     157         * doesn't have CAP_CAP.
     158         */
     159        if (!(cap_get(TASK) & CAP_CAP) || !(t == TASK)) {
     160                interrupts_restore(ipl);
     161                return (__native) EPERM;
     162        }
     163
     164        cap_set(t, cap_get(t) & ~caps);
     165       
     166        interrupts_restore(ipl);
     167        return 0;
     168}
Note: See TracChangeset for help on using the changeset viewer.