Repository navigation
usb: typec: fix CD321x partner identity use-after-free and empty USB mode list - #4
Merged
Merged
Conversation
added 2 commits
September 10, 2026 09:37
cd321x_update_work() points desc.identity at st.partner_identity, where "st" is a stack local. typec_register_partner() stores that pointer in partner->identity rather than copying the structure, so once the work function returns the partner is left referencing a freed stack page. Any later read of the partner's PD identity then dereferences it. On a MacBook Pro (16-inch, M2 Max) reading /sys/class/typec/port0-partner/type as an unprivileged user is enough: Unable to handle kernel paging request at virtual address ffff800083a87d0c Internal error: Oops: 0000000096000007 [omacom#1] SMP CPU: 10 UID: 1000 PID: 83017 Comm: cat pc : get_pd_product_type+0x54/0xa4 [typec] lr : type_show+0x14/0x3c [typec] get_pd_product_type() NULL-checks partner->identity and then reads id->id_header, which is the faulting access; the pointer is not NULL, just dangling. With VMAP_STACK the dead stack is unmapped, hence the vmalloc-range fault address. The driver already keeps a persistent copy in cd321x->cur_partner_identity, but only assigns it after registration. Fill it in first and register the partner against that instead. The generic tps6598x path already does the equivalent, pointing desc.identity at tps->partner_identity. Fixes: 82432bb ("usb: typec: tipd: Handle mode transitions for CD321x") Signed-off-by: Marcelo <[email protected]>
usb_mode_show() and usb_capability_show() build a space-separated list and then overwrite the trailing space with a newline: sysfs_emit_at(buf, len - 1, "\n"); When the partner or port advertises none of USB2/USB3/USB4 the loop body never runs, len stays 0, and the call is made with at == -1: invalid sysfs_emit_at: buf:00000000ffaad2a3 at:-1 WARNING: fs/sysfs/file.c:785 at sysfs_emit_at+0x54/0xd4, CPU#1: cat/892 sysfs_emit_at() rejects the negative offset, so the attribute also reads back empty rather than as a newline like every other list attribute. Seen on a MacBook Pro (16-inch, M2 Max), where one of the Type-C partners registered by the CD321x has no USB capability bits set, by reading /sys/class/typec/port1-partner/usb_mode Return a bare newline when nothing was written. Fixes: 2140a95 ("usb: typec: Add attribute file showing the USB Modes of the partner") Signed-off-by: Marcelo <[email protected]>
DjDeveloperr
approved these changes
Sep 12, 2026
DjDeveloperr
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, fixes are on point!
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.
Two Type-C fixes found while bringing up USB-C displays on a MacBook Pro (16-inch, M2 Max,
apple,j416c) running thetbbranch. Both are verified on that machine.1.
usb: typec: tipd: fix partner identity use-after-free on CD321xcd321x_update_work()pointsdesc.identityat a stack local, andtypec_register_partner()stores that pointer instead of copying the structure. The partner outlives the work function, so it is left referencing a freed stack page.Reading
/sys/class/typec/port0-partner/typeas an unprivileged user is enough to hit it:get_pd_product_type()null-checkspartner->identityand then readsid->id_header. The pointer isn't null, just dangling; withVMAP_STACKthe dead stack is unmapped, hence the vmalloc-range fault address.The driver already keeps a persistent copy in
cd321x->cur_partner_identitybut only assigns it after registration. The fix fills it in first and registers against that, which is what the generic tps6598x path already does.Fixes: 82432bb ("usb: typec: tipd: Handle mode transitions for CD321x")
2.
usb: typec: fix sysfs_emit_at() offset underflow on an empty mode listusb_mode_show()andusb_capability_show()overwrite a trailing space with a newline usingsysfs_emit_at(buf, len - 1, "\n"). When none of USB2/USB3/USB4 is advertised the loop never runs,lenstays 0, and the call is made withat == -1:The attribute then also reads back empty instead of a newline like every other list attribute. Seen on the same machine, where one of the partners registered by the CD321x has no USB capability bits set, by reading
/sys/class/typec/port1-partner/usb_mode.Fixes: 2140a95 ("usb: typec: Add attribute file showing the USB Modes of the partner")
Testing
Built and booted on the M2 Max with both patches applied. The read that previously oopsed the machine now returns normally,
usb_modereturns a newline instead of warning, and Type-C displays continue to work across replugs on all ports.Both changes are against code that is the same in mainline, so they can be sent to linux-usb if you want them upstream.