Fix parse-side recursion gap in CVE-2025-0649 (GetDenseTensorShape / FillTensorProto) - #4146
Open
rishuranjanofficial wants to merge 1 commit into
Conversation
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.
Summary
CVE-2025-0649 (uncontrolled recursion in
GetDenseTensorShapeandFillTensorProto, CVSS 7.5 HIGH) was reported againsttensorflow_serving/util/json_tensor.cc. The prior fix attempt (#4133,closed without merge) only addressed the stringification side of this bug
class — the parse-side recursion in
GetDenseTensorShape/FillTensorProtoremains unbounded on current
master.This was independently confirmed by a reviewer on #4143 (the OSS-Fuzz
harness for this same parser), who reproduced a real ASAN stack-overflow
using a 250,000-level nested JSON request body:
$ python3 infra/helper.py reproduce tensorflow-serving json_tensor_fuzzer /tc.json
==ERROR: AddressSanitizer: stack-overflow ...
#0 tensorflow::serving::FillTensorProto(...)
... (249 recursive frames total, truncated)
SUMMARY: AddressSanitizer: stack-overflow .../json_tensor.cc:393 in FillTensorProto
An unauthenticated attacker can crash
tensorflow_model_serverwith asingle deeply nested JSON request to the REST API (
/v1/models/*:predict,:classify, or:regress).Related prior art
unreviewed for ~3 months. This PR takes a different, smaller-diff approach
(bounded recursion instead of an iterative rewrite) but addresses the same
root cause.
Fix
kMaxTensorRank = 254(aligned with TensorFlow'sTensorShape::MaxDimensions()).GetDenseTensorShapenow returnsabsl::Statusand rejects input nesteddeeper than
kMaxTensorRank, instead of recursing without bound. All threecall sites updated to propagate the new return value.
FillTensorProtogets an independent depth guard as defense-in-depth,since it was called out as its own recursion vector.
instancesandinputspayloads arenow rejected with
InvalidArgument, and a well-within-limit nested payloadis confirmed to still succeed (no legitimate-use-case regression).
Testing
Added
DeeplyNestedInstancesRejected,DeeplyNestedInputsRejected, andWellFormedNestedInstancesWithinLimitAcceptedtojson_tensor_test.cc.