Skip to contentSkip to conversation

vhost-vdpa: honor CAP_IPC_LOCK

PATCH Superseded Jason Wang 2 participants 3 messages Mar 2, 2021

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/1 vhost-vdpa: honor CAP_IPC_LOCK

When CAP_IPC_LOCK is set we should not check locked memory against rlimit as what has been implemented in mlock().

---
 drivers/vhost/vdpa.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/vdpa.c +2 -1
index ef688c8c0e0e..e93572e2e344 100644
@@ -638,7 +638,8 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
 	mmap_read_lock(dev->mm);
 
 	lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
-	if (npages + atomic64_read(&dev->mm->pinned_vm) > lock_limit) {
+	if (!capable(CAP_IPC_LOCK) &&
+	    (npages + atomic64_read(&dev->mm->pinned_vm) > lock_limit)) {
 		ret = -ENOMEM;
 		goto unlock;
 	}
Signature · 6 lines
2.18.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#1 lore raw
Quoted 4 lines · Jason Wang

When CAP_IPC_LOCK is set we should not check locked memory against rlimit as what has been implemented in mlock().

Indeed and it's not just mlock.

Documentation/admin-guide/perf-security.rst:

RLIMIT_MEMLOCK and perf_event_mlock_kb resource constraints are ignored for processes with the CAP_IPC_LOCK capability.

and let's add a Fixes: tag?

Quoted 20 lines
---
 drivers/vhost/vdpa.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/vdpa.c +2 -1
index ef688c8c0e0e..e93572e2e344 100644
@@ -638,7 +638,8 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
 	mmap_read_lock(dev->mm);
 
 	lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
-	if (npages + atomic64_read(&dev->mm->pinned_vm) > lock_limit) {
+	if (!capable(CAP_IPC_LOCK) &&
+	    (npages + atomic64_read(&dev->mm->pinned_vm) > lock_limit)) {
 		ret = -ENOMEM;
 		goto unlock;
 	}
Signature · 1 line
2.18.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#2 lore raw
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Jason Wang

When CAP_IPC_LOCK is set we should not check locked memory against rlimit as what has been implemented in mlock().

Quoted 8 lines

Indeed and it's not just mlock.

Documentation/admin-guide/perf-security.rst:

RLIMIT_MEMLOCK and perf_event_mlock_kb resource constraints are ignored for processes with the CAP_IPC_LOCK capability.

and let's add a Fixes: tag?

Sure, V2 is posted.

Thanks

Quoted 12 lines
Quoted 12 lines
---
  drivers/vhost/vdpa.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/vdpa.c +0 -0
index ef688c8c0e0e..e93572e2e344 100644
@@ -638,7 +638,8 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
  	mmap_read_lock(dev->mm);
 
Quoted 9 lines
Quoted 9 lines
drivers/vhost/vdpa.c +2 -1
  	lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
-	if (npages + atomic64_read(&dev->mm->pinned_vm) > lock_limit) {
+	if (!capable(CAP_IPC_LOCK) &&
+	    (npages + atomic64_read(&dev->mm->pinned_vm) > lock_limit)) {
  		ret = -ENOMEM;
  		goto unlock;
  	}
Signature · 1 line
2.18.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization