Changes in kernel/generic/src/security/cap.c [6b10dab:da1bafb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/security/cap.c
r6b10dab rda1bafb 41 41 #include <proc/task.h> 42 42 #include <synch/spinlock.h> 43 #include <syscall/sysarg64.h> 43 44 #include <syscall/copy.h> 44 45 #include <arch.h> … … 78 79 * The calling task must have the CAP_CAP capability. 79 80 * 80 * @param taskid Destination task ID.81 * @param caps 81 * @param uspace_taskid_arg Userspace structure holding destination task ID. 82 * @param caps Capabilities to grant. 82 83 * 83 84 * @return Zero on success or an error code from @ref errno.h. 84 85 * 85 86 */ 86 static sysarg_t cap_grant(task_id_t taskid, cap_t caps)87 unative_t sys_cap_grant(sysarg64_t *uspace_taskid_arg, cap_t caps) 87 88 { 88 89 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; 90 96 91 97 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); 93 99 94 100 if ((!task) || (!context_check(CONTEXT, task->context))) { 95 101 irq_spinlock_unlock(&tasks_lock, true); 96 return ( sysarg_t) ENOENT;102 return (unative_t) ENOENT; 97 103 } 98 104 … … 110 116 * attempt to revoke capabilities from itself. 111 117 * 112 * @param taskid Destination task ID.113 * @param caps 118 * @param uspace_taskid_arg Userspace structure holding destination task ID. 119 * @param caps Capabilities to revoke. 114 120 * 115 121 * @return Zero on success or an error code from @ref errno.h. 116 122 * 117 123 */ 118 static sysarg_t cap_revoke(task_id_t taskid, cap_t caps)124 unative_t sys_cap_revoke(sysarg64_t *uspace_taskid_arg, cap_t caps) 119 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 120 131 irq_spinlock_lock(&tasks_lock, true); 121 132 122 task_t *task = task_find_by_id( taskid);133 task_t *task = task_find_by_id((task_id_t) taskid_arg.value); 123 134 if ((!task) || (!context_check(CONTEXT, task->context))) { 124 135 irq_spinlock_unlock(&tasks_lock, true); 125 return ( sysarg_t) ENOENT;136 return (unative_t) ENOENT; 126 137 } 127 138 … … 136 147 irq_spinlock_unlock(&TASK->lock, false); 137 148 irq_spinlock_unlock(&tasks_lock, true); 138 return ( sysarg_t) EPERM;149 return (unative_t) EPERM; 139 150 } 140 151 … … 146 157 } 147 158 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 must173 * 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 must213 * 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 228 159 /** @} 229 160 */
Note:
See TracChangeset
for help on using the changeset viewer.