sched: enforce ref-counting on current task/thread pointers
This commit is contained in:
+32
-6
@@ -11,13 +11,15 @@ kern_status_t sys_address_space_read(
|
||||
size_t count,
|
||||
size_t *nr_read)
|
||||
{
|
||||
struct task *self = current_task();
|
||||
struct task *self = get_current_task();
|
||||
|
||||
if (!validate_access_w(self, dst, count)) {
|
||||
put_current_task(self);
|
||||
return KERN_MEMORY_FAULT;
|
||||
}
|
||||
|
||||
if (nr_read && !validate_access_w(self, nr_read, sizeof *nr_read)) {
|
||||
put_current_task(self);
|
||||
return KERN_MEMORY_FAULT;
|
||||
}
|
||||
|
||||
@@ -30,12 +32,14 @@ kern_status_t sys_address_space_read(
|
||||
= task_resolve_handle(self, region_handle, &obj, &handle_flags);
|
||||
if (status != KERN_OK) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return status;
|
||||
}
|
||||
|
||||
struct address_space *region = address_space_cast(obj);
|
||||
if (!region) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return KERN_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
@@ -52,6 +56,7 @@ kern_status_t sys_address_space_read(
|
||||
address_space_unlock_irqrestore(region, flags);
|
||||
|
||||
object_unref(obj);
|
||||
put_current_task(self);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -63,14 +68,16 @@ kern_status_t sys_address_space_write(
|
||||
size_t count,
|
||||
size_t *nr_written)
|
||||
{
|
||||
struct task *self = current_task();
|
||||
struct task *self = get_current_task();
|
||||
|
||||
if (!validate_access_r(self, src, count)) {
|
||||
put_current_task(self);
|
||||
return KERN_MEMORY_FAULT;
|
||||
}
|
||||
|
||||
if (nr_written
|
||||
&& !validate_access_w(self, nr_written, sizeof *nr_written)) {
|
||||
put_current_task(self);
|
||||
return KERN_MEMORY_FAULT;
|
||||
}
|
||||
|
||||
@@ -83,12 +90,14 @@ kern_status_t sys_address_space_write(
|
||||
= task_resolve_handle(self, region_handle, &obj, &handle_flags);
|
||||
if (status != KERN_OK) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return status;
|
||||
}
|
||||
|
||||
struct address_space *region = address_space_cast(obj);
|
||||
if (!region) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return KERN_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
@@ -105,6 +114,7 @@ kern_status_t sys_address_space_write(
|
||||
address_space_unlock_irqrestore(region, flags);
|
||||
|
||||
object_unref(obj);
|
||||
put_current_task(self);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -118,13 +128,14 @@ kern_status_t sys_address_space_map(
|
||||
vm_prot_t prot,
|
||||
virt_addr_t *out_base_address)
|
||||
{
|
||||
struct task *self = current_task();
|
||||
struct task *self = get_current_task();
|
||||
|
||||
if (out_base_address
|
||||
&& !validate_access_r(
|
||||
self,
|
||||
out_base_address,
|
||||
sizeof *out_base_address)) {
|
||||
put_current_task(self);
|
||||
return KERN_MEMORY_FAULT;
|
||||
}
|
||||
|
||||
@@ -141,24 +152,28 @@ kern_status_t sys_address_space_map(
|
||||
®ion_flags);
|
||||
if (status != KERN_OK) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = task_resolve_handle(self, object_handle, &vmo_obj, &vmo_flags);
|
||||
if (status != KERN_OK) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return status;
|
||||
}
|
||||
|
||||
struct address_space *region = address_space_cast(region_obj);
|
||||
if (!region) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return KERN_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
struct vm_object *vmo = vm_object_cast(vmo_obj);
|
||||
if (!vmo) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return KERN_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
@@ -177,6 +192,7 @@ kern_status_t sys_address_space_map(
|
||||
|
||||
object_unref(vmo_obj);
|
||||
object_unref(region_obj);
|
||||
put_current_task(self);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -186,7 +202,7 @@ kern_status_t sys_address_space_unmap(
|
||||
virt_addr_t base,
|
||||
size_t length)
|
||||
{
|
||||
struct task *self = current_task();
|
||||
struct task *self = get_current_task();
|
||||
|
||||
kern_status_t status = KERN_OK;
|
||||
unsigned long flags;
|
||||
@@ -201,12 +217,14 @@ kern_status_t sys_address_space_unmap(
|
||||
®ion_flags);
|
||||
if (status != KERN_OK) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return status;
|
||||
}
|
||||
|
||||
struct address_space *region = address_space_cast(region_obj);
|
||||
if (!region) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return KERN_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
@@ -215,6 +233,7 @@ kern_status_t sys_address_space_unmap(
|
||||
status = address_space_unmap(region, base, length);
|
||||
|
||||
object_unref(region_obj);
|
||||
put_current_task(self);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -225,13 +244,14 @@ kern_status_t sys_address_space_reserve(
|
||||
size_t length,
|
||||
virt_addr_t *out_base_address)
|
||||
{
|
||||
struct task *self = current_task();
|
||||
struct task *self = get_current_task();
|
||||
|
||||
if (out_base_address
|
||||
&& !validate_access_r(
|
||||
self,
|
||||
out_base_address,
|
||||
sizeof *out_base_address)) {
|
||||
put_current_task(self);
|
||||
return KERN_MEMORY_FAULT;
|
||||
}
|
||||
|
||||
@@ -248,12 +268,14 @@ kern_status_t sys_address_space_reserve(
|
||||
®ion_flags);
|
||||
if (status != KERN_OK) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return status;
|
||||
}
|
||||
|
||||
struct address_space *region = address_space_cast(region_obj);
|
||||
if (!region) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return KERN_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
@@ -268,6 +290,7 @@ kern_status_t sys_address_space_reserve(
|
||||
address_space_unlock_irqrestore(region, flags);
|
||||
|
||||
object_unref(region_obj);
|
||||
put_current_task(self);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -277,7 +300,7 @@ kern_status_t sys_address_space_release(
|
||||
virt_addr_t base,
|
||||
size_t length)
|
||||
{
|
||||
struct task *self = current_task();
|
||||
struct task *self = get_current_task();
|
||||
|
||||
kern_status_t status = KERN_OK;
|
||||
unsigned long flags;
|
||||
@@ -292,12 +315,14 @@ kern_status_t sys_address_space_release(
|
||||
®ion_flags);
|
||||
if (status != KERN_OK) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return status;
|
||||
}
|
||||
|
||||
struct address_space *region = address_space_cast(region_obj);
|
||||
if (!region) {
|
||||
task_unlock_irqrestore(self, flags);
|
||||
put_current_task(self);
|
||||
return KERN_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
@@ -308,6 +333,7 @@ kern_status_t sys_address_space_release(
|
||||
address_space_unlock_irqrestore(region, flags);
|
||||
|
||||
object_unref(region_obj);
|
||||
put_current_task(self);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user