Repository navigation
Conversation
blobmsg_format_element() printed the attribute name whenever it formatted an element in a table context (without_name == false), calling blobmsg_name() unconditionally. blobmsg_name() blind-casts the attribute payload to a struct blobmsg_hdr and returns hdr->name, and blobmsg_format_string() then strlen()s that pointer with no length bound. A non-extended attribute carries no blobmsg name header. Such an attribute still passes blobmsg_check_attr(attr, false): the name check returns true for a non-extended attribute when no name is required, and a garbage attribute declaring itself BLOBMSG_TYPE_TABLE or BLOBMSG_TYPE_ARRAY has no entry in blob_type[] and so skips content validation entirely. Its raw bytes are then reinterpreted as a length-prefixed name string and strlen()d past the end of the attribute, leaking adjacent memory into the JSON output. Both ubus (via the monitor path) and rpcd forward attacker-controlled, non-revalidated UBUS_ATTR_DATA to this formatter. Guard the name access with blob_is_extended() so the name is only read from attributes that actually carry a name header. For extended attributes blobmsg_check_attr() has already verified the name is NUL-terminated within bounds, so the subsequent strlen() is safe. Add a regression test that crafts a non-extended, TABLE-typed attribute whose payload ends exactly at the allocation boundary; on an unfixed build the name strlen() reads past it, which the sanitized test catches. Reported-by: Erfan-Nasiri <https://github.com/Erfan-Nasiri> Fixes: 0918243 ("move json formatting to the blobmsg_json library") Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
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.
blobmsg_format_element() printed the attribute name whenever it formatted an element in a table context (without_name == false), calling blobmsg_name() unconditionally. blobmsg_name() blind-casts the attribute payload to a struct blobmsg_hdr and returns hdr->name, and blobmsg_format_string() then strlen()s that pointer with no length bound.
A non-extended attribute carries no blobmsg name header. Such an attribute still passes blobmsg_check_attr(attr, false): the name check returns true for a non-extended attribute when no name is required, and a garbage attribute declaring itself BLOBMSG_TYPE_TABLE or BLOBMSG_TYPE_ARRAY has no entry in blob_type[] and so skips content validation entirely. Its raw bytes are then reinterpreted as a length-prefixed name string and strlen()d past the end of the attribute, leaking adjacent memory into the JSON output. Both ubus (via the monitor path) and rpcd forward attacker-controlled, non-revalidated UBUS_ATTR_DATA to this formatter.
Guard the name access with blob_is_extended() so the name is only read from attributes that actually carry a name header. For extended attributes blobmsg_check_attr() has already verified the name is NUL-terminated within bounds, so the subsequent strlen() is safe.
Add a regression test that crafts a non-extended, TABLE-typed attribute whose payload ends exactly at the allocation boundary; on an unfixed build the name strlen() reads past it, which the sanitized test catches.
Reported-by: Erfan-Nasiri https://github.com/Erfan-Nasiri
Fixes: 0918243 ("move json formatting to the blobmsg_json library")
Assisted-by: Claude:claude-opus-4-8