Re: [PATCH] USB: gadget: fix NULL pointer dereference in gadget_dev_ioctl()
From: Lovekesh Solanki
Date: Tue Aug 25 2026 - 10:31:03 EST
Thanks for the review,
On Tue, Aug 25, 2026 at 09:14:37AM -0400, Alan Stern wrote:
> Why does it matter that you read dev->gadget before the state check
> rather than after? If it doesn't matter, there's no reason to mention
> it in the patch description.
The order of reading it doesn't matter. The important part is to read it
while holding the lock, perhaps the wording is unclear, I'll reword it
in v2.
> Also, why does it matter that gadgetfs_bind() writes dev->gadget without
> holding the lock? Again, the description shouldn't mention things that
> don't matter.
Because ioctl can get a stale dev->gadget before dev->lock, while
dev->state is checked after acquiring the lock, which is the cause.
Is the reference to gadgetfs_bind() unncessary? Or this part of the
explanation is irrelvant?
> Why did you add this test for gadget being non-NULL? Is there any way
> it could possibly be NULL at this point?
It seems it doesn't matter since if read is correct it can't be NULL, it
was an initial attempt to fix but its unnecessary now, I'll remove that
as well.
Regards,
Lovekesh