Skip to content

server: compare the root admin resource limit against unlimited as a long - #14140

Open
nagaboinaramgopal wants to merge 1 commit into
apache:4.20from
nagaboinaramgopal:fix/resourcelimit-unlimited-truncation
Open

server: compare the root admin resource limit against unlimited as a long#14140
nagaboinaramgopal wants to merge 1 commit into
apache:4.20from
nagaboinaramgopal:fix/resourcelimit-unlimited-truncation

Conversation

@nagaboinaramgopal

Copy link
Copy Markdown
Contributor

Description

updateResourceLimit only accepts -1 (unlimited) for a root admin account, but the check compared max.shortValue() != Resource.RESOURCE_UNLIMITED. max is a Long, so shortValue() 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

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

N/A

How Has This Been Tested?

Added updateResourceLimitRejectsAFiniteLimitForRootAdminEvenWhenItsLowBitsLookUnlimited to ResourceLimitManagerImplTest. 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 of ResourceLimitManagerImplTest (56 tests) passes.

mvn -pl server test -Dtest=ResourceLimitManagerImplTest

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:

22:07:06 command=updateResourceLimit&account=admin&resourcetype=0&max=65535  HTTP/1.1 200  "max":65535
22:07:06 command=updateResourceLimit&account=admin&resourcetype=0&max=100    HTTP/1.1 431  Only -1 limit is supported for Root Admin accounts
22:07:06 command=updateResourceLimit&account=admin&resourcetype=0&max=-1     HTTP/1.1 200

With the change, 65535 is rejected like any other finite value, and -1 is still accepted:

22:08:04 command=updateResourceLimit&account=admin&resourcetype=0&max=65535  HTTP/1.1 431  Only -1 limit is supported for Root Admin accounts
22:08:04 command=updateResourceLimit&account=admin&resourcetype=0&max=100    HTTP/1.1 431  Only -1 limit is supported for Root Admin accounts
22:08:04 command=updateResourceLimit&account=admin&resourcetype=0&max=-1     HTTP/1.1 200

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.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant