Skip to content

blobmsg_json: avoid out-of-bounds read on non-extended attributes - #57

Open
hauke wants to merge 1 commit into
openwrt:masterfrom
hauke:blobmsg-json-oob-read
Open

hauke wants to merge 1 commit into
openwrt:masterfrom
hauke:blobmsg-json-oob-read

Conversation

@hauke

@hauke hauke commented Oct 8, 2026

Copy link
Copy Markdown
Member

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

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