Skip to contentSkip to conversation

test capability for remote task

PATCH In review Jike Song 3 participants 6 messages Jan 12, 2017 – Jan 13, 2017

Subsystems (3)
lore
Share & tools
lore

Jike Song

author
#0 lore raw

v2 cover test capability for remote task

Sometimes vfio iommu type1 needs to pin memory for a remote task other than current, thereby needs to test the CAP_IPC_LOCK capability for that task.

The proper routine for this purpose is has_capability(), but it is not yet exported for modules. None of currently exported capability- testing symbols allows a specified task. So here in this series has_capability() is exported then used in the vfio iommu type1 driver.

v2: -> Add Serge's Acked-by to PATCH [1/2]

    -> Remove the change in vfio_pin_pages_remote, since it's now guaranteed the 'current' process

Hi Alex,

I kept EXPORT_SYMBOL other than EXPORT_SYMBOL_GPL, since I'm still worry about changing the type of existing exports in 'capability.c'. I'm new to open-source fearing of violating GPL :)

Jike Song (2):
capability: export has_capability
vfio iommu type1: fix the testing of capability for remote task

 drivers/vfio/vfio_iommu_type1.c | 3 +--
 kernel/capability.c             | 1 +
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.3
author
#1 lore raw

PATCH v2 1/2 capability: export has_capability

has_capability() is sometimes needed by modules to test capability for specified task other than current, so export it.

---
 kernel/capability.c | 1 +
 1 file changed, 1 insertion(+)
kernel/capability.c +1 -0
index a98e814..f97fe77 100644
@@ -318,6 +318,7 @@ bool has_capability(struct task_struct *t, int cap)
 {
 	return has_ns_capability(t, &init_user_ns, cap);
 }
+EXPORT_SYMBOL(has_capability);
 
 /**
  * has_ns_capability_noaudit - Does a task have a capability (unaudited)
Signature · 1 line
1.9.3
Acked-by on v2 1/2
#2 lore raw

Re: [v2 1/2] capability: export has_capability

Quoted 7 lines · Jike Song

has_capability() is sometimes needed by modules to test capability for specified task other than current, so export it.

Quoted 17 lines
---
 kernel/capability.c | 1 +
 1 file changed, 1 insertion(+)
kernel/capability.c +1 -0
index a98e814..f97fe77 100644
@@ -318,6 +318,7 @@ bool has_capability(struct task_struct *t, int cap)
 {
 	return has_ns_capability(t, &init_user_ns, cap);
 }
+EXPORT_SYMBOL(has_capability);
 
 /**
  * has_ns_capability_noaudit - Does a task have a capability (unaudited)
Signature · 2 lines
James Morris
<[email protected]>
author
#3 lore raw

PATCH v2 2/2 vfio iommu type1: fix the testing of capability for remote task

In reply to Jike Song

Before the mdev enhancement type1 iommu used capable() to test the capability of current task; in the course of mdev development a new requirement, testing for another task other than current, was raised. ns_capable() was used for this purpose, however it still tests current, the only difference is, in a specified namespace.

Fix it by using has_capability() instead, which tests the cap for specified task in init_user_ns, the same namespace as capable().

Cc Alex Williamson <[email protected]>
Cc Kirti Wankhede <[email protected]>
Cc Gerd Hoffmann <[email protected]>
---
 drivers/vfio/vfio_iommu_type1.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/vfio/vfio_iommu_type1.c +1 -2
index 9266271..77373e5 100644
@@ -495,8 +495,7 @@ static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr,
 				  unsigned long *pfn_base, bool do_accounting)
 {
 	unsigned long limit;
-	bool lock_cap = ns_capable(task_active_pid_ns(dma->task)->user_ns,
-				   CAP_IPC_LOCK);
+	bool lock_cap = has_capability(dma->task, CAP_IPC_LOCK);
 	struct mm_struct *mm;
 	int ret;
 	bool rsvd;
Signature · 1 line
1.9.3
Reviewed-by on v2 2/2
#4 lore raw

Re: [v2 2/2] vfio iommu type1: fix the testing of capability for remote task

Quoted 6 lines · Jike Song

Before the mdev enhancement type1 iommu used capable() to test the capability of current task; in the course of mdev development a new requirement, testing for another task other than current, was raised. ns_capable() was used for this purpose, however it still tests current, the only difference is, in a specified namespace.

Quoted 7 lines

Fix it by using has_capability() instead, which tests the cap for specified task in init_user_ns, the same namespace as capable().

Cc Alex Williamson <[email protected]>
Cc Kirti Wankhede <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Quoted 19 lines
---
 drivers/vfio/vfio_iommu_type1.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/vfio/vfio_iommu_type1.c +1 -2
index 9266271..77373e5 100644
@@ -495,8 +495,7 @@ static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr,
 				  unsigned long *pfn_base, bool do_accounting)
 {
 	unsigned long limit;
-	bool lock_cap = ns_capable(task_active_pid_ns(dma->task)->user_ns,
-				   CAP_IPC_LOCK);
+	bool lock_cap = has_capability(dma->task, CAP_IPC_LOCK);
 	struct mm_struct *mm;
 	int ret;
 	bool rsvd;
Signature · 2 lines
James Morris
<[email protected]>
#5 lore raw

Re: [v2 2/2] vfio iommu type1: fix the testing of capability for remote task

Looks good to me

Reviewed by: Kirti Wankhede <[email protected]>

Quoted 39 lines · James Morris
Quoted 6 lines · Jike Song

Before the mdev enhancement type1 iommu used capable() to test the capability of current task; in the course of mdev development a new requirement, testing for another task other than current, was raised. ns_capable() was used for this purpose, however it still tests current, the only difference is, in a specified namespace.

Quoted 7 lines

Fix it by using has_capability() instead, which tests the cap for specified task in init_user_ns, the same namespace as capable().

Cc Alex Williamson <[email protected]>
Cc Kirti Wankhede <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Quoted 19 lines
---
 drivers/vfio/vfio_iommu_type1.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/vfio/vfio_iommu_type1.c +1 -2
index 9266271..77373e5 100644
@@ -495,8 +495,7 @@ static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr,
 				  unsigned long *pfn_base, bool do_accounting)
 {
 	unsigned long limit;
-	bool lock_cap = ns_capable(task_active_pid_ns(dma->task)->user_ns,
-				   CAP_IPC_LOCK);
+	bool lock_cap = has_capability(dma->task, CAP_IPC_LOCK);
 	struct mm_struct *mm;
 	int ret;
 	bool rsvd;