Skip to content

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

Open
rootnomad wants to merge 2 commits into
apache:4.20from
rootnomad:fix/resourcelimit-unlimited-truncation
Open

rootnomad wants to merge 2 commits into
apache:4.20from
rootnomad:fix/resourcelimit-unlimited-truncation

Conversation

@rootnomad

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.

//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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (_accountMgr.isRootAdmin(account.getId()) && max != Resource.RESOURCE_UNLIMITED) {
if (_accountMgr.isRootAdmin(account.getId()) && max != (long)Resource.RESOURCE_UNLIMITED {

just to be sure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@DaanHoogland DaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 16.42%. Comparing base (b93f603) to head (219aeb0).
⚠️ Report is 10 commits behind head on 4.20.

Files with missing lines Patch % Lines
.../cloud/resourcelimit/ResourceLimitManagerImpl.java 0.00% 1 Missing ⚠️
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     
Flag Coverage Δ
uitests 4.16% <ø> (+0.02%) ⬆️
unittests 17.29% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@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.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19801

This branch has not been deployed

No deployments
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.

3 participants