Repository navigation
Conversation
…long The root admin check in updateResourceLimit used max.shortValue() != RESOURCE_UNLIMITED. max is a Long, so shortValue() keeps only the low 16 bits: a finite limit such as 65535 or 131071 truncates to -1, passes the "Only -1 limit is supported for Root Admin accounts" check and is stored on the root admin account. Compare the full value instead.
|
|
||
| //only Unlimited value is accepted if account is Root Admin | ||
| if (_accountMgr.isRootAdmin(account.getId()) && max.shortValue() != Resource.RESOURCE_UNLIMITED) { | ||
| if (_accountMgr.isRootAdmin(account.getId()) && max != Resource.RESOURCE_UNLIMITED) { |
There was a problem hiding this comment.
| if (_accountMgr.isRootAdmin(account.getId()) && max != Resource.RESOURCE_UNLIMITED) { | |
| if (_accountMgr.isRootAdmin(account.getId()) && max != (long)Resource.RESOURCE_UNLIMITED { |
just to be sure
There was a problem hiding this comment.
Good call, thanks. Added the explicit (long) cast in 219aeb0 so the long comparison is obvious at a glance. max is a Long, so it already compared as long once shortValue() was gone, but this reads better.
Cast RESOURCE_UNLIMITED to long in the root-admin unlimited-only guard, as suggested in review. max is a Long, so the check already compared as long once shortValue() was dropped; the cast makes that intent obvious.
|
@blueorangutan package |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.20 #14140 +/- ##
============================================
+ Coverage 4.14% 16.42% +12.28%
- Complexity 0 13677 +13677
============================================
Files 405 5669 +5264
Lines 33073 501631 +468558
Branches 5903 60939 +55036
============================================
+ Hits 1370 82408 +81038
- Misses 31527 409976 +378449
- Partials 176 9247 +9071
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@blueorangutan package |
|
@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19801 |
Description
updateResourceLimit only accepts -1 (unlimited) for a root admin account, but the check compared
max.shortValue() != Resource.RESOURCE_UNLIMITED.maxis a Long, soshortValue()keeps only the low 16 bits, and any limit whose low 16 bits are all ones (65535, 131071, ...) truncates to -1. Such a value gets past the "Only -1 limit is supported for Root Admin accounts" check and is stored on the root admin account, while an ordinary value like 100 is rejected as expected. This compares the full value instead.The same code is on 4.20, 4.22 and main, so this targets 4.20.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
N/A
How Has This Been Tested?
Added
updateResourceLimitRejectsAFiniteLimitForRootAdminEvenWhenItsLowBitsLookUnlimitedtoResourceLimitManagerImplTest. It calls updateResourceLimit for a root admin account with 65535 and expects the "Only -1 limit" rejection. It fails against the current code (the update goes through) and passes with the fix, and the rest ofResourceLimitManagerImplTest(56 tests) passes.Also verified on a live 4.23 KVM environment with the same one line change, calling updateResourceLimit through the API for the root admin account
admin(resourcetype 0, user VMs).Before the change, 65535 is accepted and stored on the root admin account, while 100 is rejected:
With the change, 65535 is rejected like any other finite value, and -1 is still accepted:
How did you try to break this feature and the system with this change?
-1 is still accepted for root admin accounts, values that were already rejected stay rejected, and limits for accounts that are not root admins are not affected since this check only runs for root admins.