mirror of
https://github.com/torvalds/linux.git
synced 2026-10-08 11:36:02 +02:00
HID: mcp2221: clear rxbuf after I2C/SMBus transfer completes
mcp_i2c_smbus_read() stores the caller-supplied buffer pointer in
mcp->rxbuf for the duration of a transfer but never clears it when the
transfer finishes or times out. Once the caller frees or reuses the
buffer, mcp->rxbuf becomes a dangling pointer. A delayed or spurious
MCP2221_I2C_GET_DATA report can then drive mcp2221_raw_event() to
memcpy device data into the freed memory, causing a write
use-after-free.
Route all return paths through a single exit point that clears
mcp->rxbuf and mcp->rxbuf_size, so that the existing !mcp->rxbuf guard
in the raw_event handler can reject any report arriving after the
transfer has ended.
Fixes: 67a95c2146 ("HID: mcp2221: add usb to i2c-smbus host bridge")
Cc: stable@vger.kernel.org
Signed-off-by: Jiangshan Yi <yijiangshan@kylinos.cn>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
This commit is contained in:
parent
dca151633c
commit
db2333f887
|
|
@ -343,7 +343,7 @@ static int mcp_i2c_smbus_read(struct mcp2221 *mcp,
|
|||
|
||||
ret = mcp_send_data_req_status(mcp, mcp->txbuf, 4);
|
||||
if (ret)
|
||||
return ret;
|
||||
goto out;
|
||||
|
||||
mcp->rxbuf_idx = 0;
|
||||
|
||||
|
|
@ -365,7 +365,7 @@ static int mcp_i2c_smbus_read(struct mcp2221 *mcp,
|
|||
} else {
|
||||
usleep_range(980, 1000);
|
||||
mcp_cancel_last_cmd(mcp);
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
retries = 0;
|
||||
|
|
@ -375,6 +375,10 @@ static int mcp_i2c_smbus_read(struct mcp2221 *mcp,
|
|||
usleep_range(980, 1000);
|
||||
ret = mcp_chk_last_cmd_status_free_bus(mcp);
|
||||
|
||||
out:
|
||||
mcp->rxbuf = NULL;
|
||||
mcp->rxbuf_size = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user