Skip to content

YARN: restrict leveldb assigned-resources deserialization to known types - #8689

Open
nishat-06 wants to merge 2 commits into
apache:trunkfrom
nishat-06:nm-assigned-resources-deser-allowlist
Open

YARN: restrict leveldb assigned-resources deserialization to known types#8689
nishat-06 wants to merge 2 commits into
apache:trunkfrom
nishat-06:nm-assigned-resources-deser-allowlist

Conversation

@nishat-06

Copy link
Copy Markdown
Contributor

Description of PR

ResourceMappings.AssignedResources.fromBytes reads the per-container assigned-resource record with SerializationUtils.deserialize, which is a bare ObjectInputStream.readObject() with no type restriction:

resources = SerializationUtils.deserialize(bytes);

NMLeveldbStateStoreService.loadContainerState hands it the bytes stored under the container's assigned-resources key and replays them during container recovery on NM restart. A tampered recovery record can therefore instantiate any serializable class on the NodeManager classpath, not just the resource descriptors this code stores.

The read is switched to a commons-io ValidatingObjectInputStream restricted to the types the resource plugins actually write: the gpu/fpga/numa value objects under the nodemanager package, the shaded-guava ImmutableMap that NumaResourceAllocation holds, and the wrapping collections/strings. toBytes is left as-is so records written by earlier NMs still recover.

How was this patch tested?

mvn test -pl hadoop-yarn-project/.../hadoop-yarn-server-nodemanager -Dtest=TestResourceMappings on trunk. Added a round-trip test over GpuDevice, FpgaDevice, NumaResourceAllocation and String so valid records still deserialize, plus a test that a record carrying an element type the plugins never store is rejected instead of instantiated.

For code changes:

  • Does the title of this PR start with the corresponding JIRA issue id (e.g. 'HADOOP-17799. Your PR title ...')?
  • Object storage: Have the integration tests been executed and the endpoint declared according to the connector-specific documentation?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE, LICENSE-binary, NOTICE-binary files?

AI Tooling

If an AI tool was used:

@hadoop-yetus

Copy link
Copy Markdown

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 22s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+1 💚 mvninstall 25m 24s trunk passed
+1 💚 compile 0m 58s trunk passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 compile 0m 59s trunk passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 checkstyle 0m 43s trunk passed
+1 💚 mvnsite 0m 44s trunk passed
+1 💚 javadoc 0m 42s trunk passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 javadoc 0m 43s trunk passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
-1 ❌ spotbugs 1m 11s /branch-spotbugs-hadoop-yarn-project_hadoop-yarn_hadoop-yarn-server_hadoop-yarn-server-nodemanager-warnings.html hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager in trunk has 1 extant spotbugs warnings.
+1 💚 shadedclient 16m 23s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 0m 40s the patch passed
+1 💚 compile 0m 37s the patch passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 javac 0m 37s the patch passed
+1 💚 compile 0m 38s the patch passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 javac 0m 38s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 18s the patch passed
+1 💚 mvnsite 0m 27s the patch passed
+1 💚 javadoc 0m 20s the patch passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 javadoc 0m 23s the patch passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 spotbugs 1m 0s the patch passed
+1 💚 shadedclient 15m 54s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 22m 52s hadoop-yarn-server-nodemanager in the patch passed.
+1 💚 asflicense 0m 25s The patch does not generate ASF License warnings.
92m 44s
Subsystem Report/Notes
Docker ClientAPI=1.55 ServerAPI=1.55 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8689/1/artifact/out/Dockerfile
GITHUB PR #8689
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 4afe1c7b7838 5.15.0-181-generic #191-Ubuntu SMP Fri May 22 19:09:02 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / eb93bee
Default Java Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.11+10-1-24.04.2-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8689/1/testReport/
Max. process+thread count 633 (vs. ulimit of 10000)
modules C: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager U: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8689/1/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@slfan1989
slfan1989 requested a lite review from Copilot August 19, 2026 10:19
@slfan1989 slfan1989 self-assigned this Aug 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Hardens NodeManager container recovery by restricting deserialization of assigned-resources records to a known set of safe types, preventing tampered LevelDB recovery entries from instantiating arbitrary classes.

Changes:

  • Replace unrestricted SerializationUtils.deserialize with a ValidatingObjectInputStream allowlist in ResourceMappings.AssignedResources.fromBytes.
  • Add tests to ensure round-trip deserialization works for GPU/FPGA/NUMA plugin value objects and that unexpected types are rejected.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
.../container/TestResourceMappings.java Adds regression tests for allowlisted plugin types and rejection of unexpected serialized element types.
.../container/ResourceMappings.java Switches recovery deserialization to ValidatingObjectInputStream with an allowlist of accepted classes/packages.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +104 to +109
ois.accept(
"org.apache.hadoop.yarn.server.nodemanager.*",
"org.apache.hadoop.thirdparty.com.google.common.collect.*",
"java.util.*",
"java.lang.*",
"[Ljava.lang.Object;");

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 point. Tightened it: the four package wildcards are gone, replaced with the concrete value objects the plugins actually store (Device, GpuDevice, FpgaDevice, NumaResourceAllocation), the ArrayList/UnmodifiableList that wrap them, and the String/Number/Integer/Long those objects hold. The only remaining wildcard is the shaded-guava collect package, because NumaResourceAllocation's ImmutableMaps serialize through guava's internal SerializedForm and pinning those class names would break across guava versions.

"java.util.*",
"java.lang.*",
"[Ljava.lang.Object;");
resources = (List<Serializable>) ois.readObject();

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.

Fixed. It now reads into an Object, checks instanceof List and throws an IOException with the offending type name if it isn't one, so the cast can't produce a stray ClassCastException. Callers see the checked IOException the contract advertises.

Comment on lines +126 to +127
// allowlist rejects it by class name during readObject, before the class
// is loaded or any of its logic runs.

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.

Reworded to 'before the object is instantiated and any of its logic runs', which is the property the allowlist actually guarantees.

… closed on non-list records

Signed-off-by: nishat shabbir <nishat@bugqore.com>
@hadoop-yetus

Copy link
Copy Markdown

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 22s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+1 💚 mvninstall 26m 9s trunk passed
+1 💚 compile 0m 59s trunk passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 compile 0m 59s trunk passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 checkstyle 0m 45s trunk passed
+1 💚 mvnsite 0m 44s trunk passed
+1 💚 javadoc 0m 42s trunk passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 javadoc 0m 44s trunk passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
-1 ❌ spotbugs 1m 12s /branch-spotbugs-hadoop-yarn-project_hadoop-yarn_hadoop-yarn-server_hadoop-yarn-server-nodemanager-warnings.html hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager in trunk has 1 extant spotbugs warnings.
+1 💚 shadedclient 17m 13s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 0m 41s the patch passed
+1 💚 compile 0m 40s the patch passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 javac 0m 40s the patch passed
+1 💚 compile 0m 42s the patch passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 javac 0m 42s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 20s the patch passed
+1 💚 mvnsite 0m 26s the patch passed
+1 💚 javadoc 0m 24s the patch passed with JDK Ubuntu-21.0.11+10-1-24.04.2-Ubuntu
+1 💚 javadoc 0m 23s the patch passed with JDK Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
+1 💚 spotbugs 0m 59s the patch passed
+1 💚 shadedclient 16m 18s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 23m 2s hadoop-yarn-server-nodemanager in the patch passed.
+1 💚 asflicense 0m 24s The patch does not generate ASF License warnings.
95m 2s
Subsystem Report/Notes
Docker ClientAPI=1.55 ServerAPI=1.55 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8689/2/artifact/out/Dockerfile
GITHUB PR #8689
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 735d5769c78f 5.15.0-181-generic #191-Ubuntu SMP Fri May 22 19:09:02 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 44f9014
Default Java Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.11+10-1-24.04.2-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.19+10-1-24.04.2-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8689/2/testReport/
Max. process+thread count 634 (vs. ulimit of 10000)
modules C: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager U: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8689/2/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants