Re: [PATCH v8 4/4] usb: gadget: f_tcm: clear the scatter list when reusing the BOT status request
From: Greg KH
Date: Fri Nov 20 2026 - 05:56:02 EST
On Wed, Nov 18, 2026 at 09:40:05PM +0900, Yehyeong Lee wrote:
> bot_send_bad_status() reuses fu->bot_req_in/bot_req_out to send the CSW or
> drain the data phase, but a preceding sg command left req->sg and
> req->num_sgs pointing at that command's t_data_sg - set in
> bot_send_read_response() for a read, or usbg_prepare_w_request() for a
> write. That command is freed before the status request runs, so on an
> sg-capable UDC the status request is handed to the controller with a freed
> scatter list: the controller reads freed memory out to the host on an IN
> endpoint, or writes host data into it on an OUT endpoint.
>
> Clear req->num_sgs and req->sg so the UDC uses the linear req->buf instead.
>
> A test module that stands in for the controller's queue path, so that it
> dereferences req->sg the way an sg-capable UDC would, reports a KASAN
> slab-use-after-free on the freed entry for a read command followed by a
> rejected command that reuses bot_req_in: 20 runs out of 20 without this
> patch and 0 out of 20 with it. A normal sg read still queues its own
> scatter list.
Why is this paragraph here? What does it mean?