From mboxrd@z Thu Jan 1 00:00:00 1970 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 CB547429027; Mon, 17 Aug 2026 14:38:26 +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=1786977507; cv=none; b=pkhjxIImST/YrrYjTgqoFXthfv1nLafeoLAT8mk/0cS17+fkzn5MWGPCccGeoTdcXCaHSBZlAbJoc9/C8jhxymz7eblbzjwd9Qe3l4MIf88sgiyqD60aQCzBurMtxWsca4DkYwPUI9eBdbdmrEKYVOwT6zlA0Cfqe+FGPKFBfMI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786977507; c=relaxed/simple; bh=b0chBb1LvLg2c4Ngt/c7SCoWVFWwvSFVxUu1xUMnwyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AK7WKkcjtD4oRS6xXSV8gTBmuisz9xZFjQhLAe8xRi90zBCGv1jxKa3jN3CGIcDpWMNEytHXUq9V9GJrs+FFcahtz2PiJj+VLyqLSnekAwCv9HT4Pqxst63HmUS9Hs02KX05FCTC3ACfe0a13joRAiFwtDUMwV3flua8uKMNRCg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xEKMIG8X; 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="xEKMIG8X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E80921F000E9; Mon, 17 Aug 2026 14:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786977506; bh=llTSuNhuFfR2j6HJEzcNbzqq+cQXti7wBPMPSY3C9S8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xEKMIG8XPgFmzypiKSPPJ2LHFtaGpUYu/1K8FJY8AohvoQGKBMe7HWxzZh4JT30eV XvW7Bf7RH0eMY04A+vAzMt3YK/IcNubJSzqTYKppxiZ8H2HHTZpdxvPZ+QiFr4HAhS zY+QJZjSV4Molef5okwA39XfyTzxHk6O2QjA6Toc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pengpeng Hou , stable@kernel.org, Marc Kleine-Budde Subject: [PATCH 5.15 351/456] can: kvaser_usb_leaf: kvaser_usb_leaf_wait_cmd(): validate received command extents Date: Mon, 17 Aug 2026 15:32:21 +0200 Message-ID: <20260817132553.276371333@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817132539.792407575@linuxfoundation.org> References: <20260817132539.792407575@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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pengpeng Hou commit 0293dd153f9dbc1ddf5dacdccc76b363bce4a8ee upstream. The wait and bulk receive paths walk variable-length commands from a USB buffer. A nonzero command shorter than CMD_HEADER_LEN can still be dispatched, and the wait path copies a matching command into a fixed caller-owned struct kvaser_cmd using the device-provided length. Reject nonzero commands that do not contain the fixed header or that extend beyond the current USB buffer item. In the wait path, also reject a matching command that exceeds the destination before copying it. Fixes: 080f40a6fa28 ("can: kvaser_usb: Add support for Kvaser CAN/USB devices") Signed-off-by: Pengpeng Hou Link: https://patch.msgid.link/20260722042221.44066-1-pengpeng@iscas.ac.cn Cc: stable@kernel.org Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c @@ -616,13 +616,22 @@ static int kvaser_usb_leaf_wait_cmd(cons continue; } - if (pos + tmp->len > actual_len) { + if (tmp->len < CMD_HEADER_LEN || + tmp->len > actual_len - pos) { dev_err_ratelimited(&dev->intf->dev, "Format error\n"); break; } if (tmp->id == id) { + if (tmp->len > sizeof(*cmd)) { + dev_err_ratelimited(&dev->intf->dev, + "Received command %u too large (%u)\n", + tmp->id, tmp->len); + err = -EIO; + goto end; + } + memcpy(cmd, tmp, tmp->len); goto end; } @@ -1573,7 +1582,7 @@ static void kvaser_usb_leaf_read_bulk_ca continue; } - if (pos + cmd->len > len) { + if (cmd->len < CMD_HEADER_LEN || cmd->len > len - pos) { dev_err_ratelimited(&dev->intf->dev, "Format error\n"); break; }