Changeset eb522e8 in mainline for kernel/generic/src/security/cap.c
- Timestamp:
- 2011-06-01T08:43:42Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8d6c1f1
- Parents:
- 9e2e715 (diff), e51a514 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/security/cap.c
r9e2e715 reb522e8 41 41 #include <proc/task.h> 42 42 #include <synch/spinlock.h> 43 #include <syscall/sysarg64.h>44 43 #include <syscall/copy.h> 45 44 #include <arch.h> … … 79 78 * The calling task must have the CAP_CAP capability. 80 79 * 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 */ 86 static sysarg_t cap_grant(task_id_t taskid, cap_t caps) 88 87 { 89 88 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; 96 90 97 91 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); 99 93 100 94 if ((!task) || (!context_check(CONTEXT, task->context))) { 101 95 irq_spinlock_unlock(&tasks_lock, true); 102 return ( unative_t) ENOENT;96 return (sysarg_t) ENOENT; 103 97 } 104 98 … … 116 110 * attempt to revoke capabilities from itself. 117 111 * 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 */ 118 static sysarg_t cap_revoke(task_id_t taskid, cap_t caps) 119 { 131 120 irq_spinlock_lock(&tasks_lock, true); 132 121 133 task_t *task = task_find_by_id( (task_id_t) taskid_arg.value);122 task_t *task = task_find_by_id(taskid); 134 123 if ((!task) || (!context_check(CONTEXT, task->context))) { 135 124 irq_spinlock_unlock(&tasks_lock, true); 136 return ( unative_t) ENOENT;125 return (sysarg_t) ENOENT; 137 126 } 138 127 … … 147 136 irq_spinlock_unlock(&TASK->lock, false); 148 137 irq_spinlock_unlock(&tasks_lock, true); 149 return ( unative_t) EPERM;138 return (sysarg_t) EPERM; 150 139 } 151 140 … … 157 146 } 158 147 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 159 228 /** @} 160 229 */
Note:
See TracChangeset
for help on using the changeset viewer.