test capability for remote task
Subsystems (3)
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
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
@@ -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
PATCH v2 2/2 vfio iommu type1: fix the testing of capability for remote task
In reply to Jike SongBefore 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().
--- drivers/vfio/vfio_iommu_type1.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/vfio/vfio_iommu_type1.c +1 -2
@@ -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
Re: [v2 1/2] capability: export has_capability
In reply to Jike SongQuoted 7 lines · Jike Song
has_capability()is sometimes needed by modules to test capability for specified task other than current, so export it.Cc Alex Williamson <[email protected]>Cc Kirti Wankhede <[email protected]>Acked-by Serge Hallyn <[email protected]>Signed-off-by Jike Song <[email protected]>
Quoted 17 lines
--- kernel/capability.c | 1 + 1 file changed, 1 insertion(+)kernel/capability.c +1
-0@@ -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]>
Re: [v2 2/2] vfio iommu type1: fix the testing of capability for remote task
In reply to Jike SongQuoted 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 ininit_user_ns, the same namespace ascapable().Cc Alex Williamson <[email protected]>Cc Kirti Wankhede <[email protected]>Cc Gerd Hoffmann <[email protected]>Signed-off-by Jike Song <[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@@ -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]>
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 ininit_user_ns, the same namespace ascapable().Cc Alex Williamson <[email protected]>Cc Kirti Wankhede <[email protected]>Cc Gerd Hoffmann <[email protected]>Signed-off-by Jike Song <[email protected]>Reviewed-by James Morris <[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@@ -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;