server: compare the root admin resource limit against unlimited as a long - #14140
Open
nagaboinaramgopal wants to merge 1 commit into
Open
server: compare the root admin resource limit against unlimited as a long#14140nagaboinaramgopal wants to merge 1 commit into
nagaboinaramgopal wants to merge 1 commit into
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.