Added routines for pager to search a suitable capability to grant to clients

Pager handles client capability requests by using one of its own
capabilities to create a new one that suits the client's needs.

The current issue is that the kernel can have multiple caps and it
may not know which one is suitable for using to create one for the client.

The kernel knows this very well, so the solution would be to attempt to
use capabilities that roughly match (i.e. by type) and leave it to
the kernel to decide whether it is any powerful to suit client's needs.
This commit is contained in:
Bahadir Balban
2009-11-08 17:54:57 +02:00
parent dc03c7b130
commit 1bb2c05c9b
3 changed files with 121 additions and 52 deletions

View File

@@ -97,7 +97,7 @@ int cap_share(l4id_t capid, unsigned int flags)
}
/* Grants all caps */
int cap_grant_all(l4id_t tid)
int cap_grant_all(l4id_t tid, unsigned int flags)
{
struct ktcb *target;
struct capability *cap_head, *cap;
@@ -113,6 +113,12 @@ int cap_grant_all(l4id_t tid)
/* Change ownership */
cap->owner = target->tid;
/* Make immutable if GRANT_IMMUTABLE given */
if (flags & CAP_GRANT_IMMUTABLE) {
cap->access &= ~CAP_GENERIC_MASK;
cap->access |= CAP_IMMUTABLE;
}
/*
* Sanity check: granted cap cannot have used
* quantity. Otherwise how else the original
@@ -134,7 +140,7 @@ out_err:
return err;
}
int cap_grant_single(l4id_t capid, l4id_t tid)
int cap_grant_single(l4id_t capid, l4id_t tid, unsigned int flags)
{
struct capability *cap;
struct ktcb *target;
@@ -158,23 +164,84 @@ int cap_grant_single(l4id_t capid, l4id_t tid)
/* Change ownership */
cap->owner = target->tid;
/* Make immutable if GRANT_IMMUTABLE given */
if (flags & CAP_GRANT_IMMUTABLE) {
cap->access &= ~CAP_GENERIC_MASK;
cap->access |= CAP_IMMUTABLE;
}
/* Place it where it is granted */
cap_list_insert(cap, TASK_CAP_LIST(target));
return 0;
}
int cap_grant(unsigned int flags, l4id_t capid, l4id_t tid)
int cap_grant(l4id_t capid, l4id_t tid, unsigned int flags)
{
if (flags & CAP_GRANT_SINGLE)
cap_grant_single(capid, tid);
cap_grant_single(capid, tid, flags);
else if (flags & CAP_GRANT_ALL)
cap_grant_all(tid);
cap_grant_all(tid, flags);
else
return -EINVAL;
return 0;
}
int cap_deduce_rtype(struct capability *orig, struct capability *new)
{
struct ktcb *target;
struct address_space *sp;
/* An rtype deduction can only be to a space or thread */
switch (cap_rtype(new)) {
case CAP_RTYPE_SPACE:
/* Check containment right */
if (cap_rtype(orig) != CAP_RTYPE_CONTAINER)
return -ENOCAP;
/*
* Find out if this space exists in this
* container.
*
* Note address space search is local only.
* Only thread searches are global.
*/
if (!(sp = address_space_find(new->resid)))
return -ENOCAP;
/* Success. Assign new type to original cap */
cap_set_rtype(orig, cap_rtype(new));
/* Assign the space id to orig cap */
orig->resid = sp->spid;
break;
case CAP_RTYPE_THREAD:
/* Find the thread */
if (!(target = tcb_find(new->resid)))
return -ENOCAP;
/* Check containment */
if (cap_rtype(orig) == CAP_RTYPE_SPACE) {
if (orig->resid != target->space->spid)
return -ENOCAP;
} else if (cap_rtype(orig) == CAP_RTYPE_CONTAINER) {
if(orig->resid != target->container->cid)
return -ENOCAP;
} else
return -ENOCAP;
/* Success. Assign new type to original cap */
cap_set_rtype(orig, cap_rtype(new));
/* Assign the space id to orig cap */
orig->resid = target->tid;
break;
default:
return -ENOCAP;
}
return 0;
}
/*
* Deduction can be by access permissions, start, end, size
* fields, or the target resource type. Inter-container
@@ -202,7 +269,7 @@ int cap_grant(unsigned int flags, l4id_t capid, l4id_t tid)
int cap_deduce(struct capability *new)
{
struct capability *orig;
struct address_space *sp;
int ret;
/* Find original capability */
if (!(orig = cap_find_byid(new->capid)))
@@ -217,27 +284,9 @@ int cap_deduce(struct capability *new)
return -ENOCAP;
/* Check target resource deduction */
if (cap_rtype(new) != cap_rtype(orig)) {
/* An rtype deduction is always into a space */
if (cap_rtype(new) != CAP_RTYPE_SPACE)
return -ENOCAP;
/* Assign new type to original cap */
cap_set_rtype(orig, cap_rtype(new));
/*
* Find out if this space exists.
*
* Note address space search is
* local only. Only thread searches
* are global.
*/
if (!(sp = address_space_find(new->resid)))
return -ENOCAP;
/* Success. Assign the space id to orig cap */
orig->resid = sp->spid;
}
if (cap_rtype(new) != cap_rtype(orig))
if ((ret = cap_deduce_rtype(orig, new)) < 0)
return ret;
/* Check permissions for deduction */
if (orig->access) {
@@ -253,6 +302,7 @@ int cap_deduce(struct capability *new)
} else if (new->access)
return -EINVAL;
/* Check size for deduction */
if (orig->size) {
/* New can't have more, or make original redundant */
if (new->size >= orig->size)