Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 875702E5B2A; Sat, 17 Oct 2026 17:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792259714; cv=none; b=O/ej43Ltm07dGrowpKFDsMU9bFUw4d8OotwRU9Kw5Y5xE5ch/gPcGN6rNkCa2HyNipovVTHBsRRj5jOs1Psqr2o5F1jiUrcGJF03IIjCw3L4WDPVh249xpsmkxEghAe3EuYfjptzu7wrTzBmSZuDYdd7WYNH9awdyPOA0KwgttY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792259714; c=relaxed/simple; bh=4gEyrVlXZNDnSd3O7yAkaQK/fg7oIaHWbUfHYSslhzk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q0jlh88puOhMIcIsDQ31RcwyvD/i9M74/MHtS6/R6NJPCALORtk5L4JCDYru7/vFwaRr9USJGt0HFqHxD98+/K9aitVTFkKSSM1+JCrva9SqYhKZIpuVBdBwvQpTkEWQsYvBClZD3fZ3rHQGthH1300zxJJf4Spp1NgH3KMnYYM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=sZ/FGVnD; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="sZ/FGVnD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09A7D1F000C4; Sat, 17 Oct 2026 17:55:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792259712; bh=eWOhPepUv9U83u9iLJZZlUJWxa6699RA9tggJ2arOlw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=sZ/FGVnDwrZTHAF2t3pkh/P2X4xoTiLmPrHzGKUvBTiRcTvdp+NHTQM95I4oeJzDZ VFDIjcFGYN8F4jBjX6On/YnMIAPzw15TUfUWo5QTLwTt5Yf+hMMqdU0ANXnKEi0Mlu Z1zeb8/8AqaV1LnF/LglZCaXH8KlWDF19CxBNckU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jiangshan Yi , Jiri Kosina , Sasha Levin Subject: [PATCH 6.6 1305/1674] HID: mcp2221: clear rxbuf after I2C/SMBus transfer completes Date: Sat, 17 Oct 2026 17:59:37 +0200 Message-ID: <20261017160504.643655139@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160431.119607952@linuxfoundation.org> References: <20261017160431.119607952@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiangshan Yi [ Upstream commit db2333f88729c8aae062cb171ed058725ff5c901 ] 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: 67a95c21463d ("HID: mcp2221: add usb to i2c-smbus host bridge") Cc: stable@vger.kernel.org Signed-off-by: Jiangshan Yi Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-mcp2221.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c index 075ad0beae6a3..233f27d5ce16f 100644 --- a/drivers/hid/hid-mcp2221.c +++ b/drivers/hid/hid-mcp2221.c @@ -320,7 +320,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; @@ -342,7 +342,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; @@ -352,6 +352,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; } -- 2.53.0