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 626C93382C5; Fri, 7 Aug 2026 14:52:31 +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=1786114352; cv=none; b=QcuD2S3sgbzIOfznmDWQApo3s2Ry+iIw605vafKiQTuidgSiHENB4/h+EOVqpi1Kj/YMr8JpKGh3i5+TinR9dyQngLrvn5Et2kGMI9RHMhjcT6A//iQwXy3tOngxBSr94GpBCZiEKp88bC86lQFDiv3FCwmAtZ/AXeOxUWMArEc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786114352; c=relaxed/simple; bh=bsYXpHS2GunFZUhKv6Q3ufQz4FAk9PFm6eDeVacapj4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lTXJlz8WvlCBfoxr6H/o/fL7wMDRC2ZkbpzxBfBggPnChgAQjnGaNN0T7ClYgk6LHoxDUj4Oo2KRUGOoUpqHdJ+yZPFm9ACQ0ZTCrL5Bb0Jb53z/l7PXE527BmJW34NG8pV/AI7vmx+42QEvIeqxJzjd4Fu3gl3j2mcQcMgjQUo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MO3DxU29; 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="MO3DxU29" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B75131F000E9; Fri, 7 Aug 2026 14:52:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786114351; bh=5yHhA+QkD+vY3TRUbYrhu+tl+yIslqr/BhJrKSd96bo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MO3DxU29hQJ64ViwctwIJYNTtthV194b5jp46iILXQ9UwJaeHQ/EhxQYO2z4blhVV dsAKf9i8K4P3SQAGj5sco1wCEnvxl/cZ3JzJguJiTxvPCpPk2HssBNENdXZTNh7GDy L9NOJJUddEzbDGRcrKfeJlvm+N0kUQLaCNPlwZdk= 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 6.12 234/337] can: kvaser_usb_leaf: kvaser_usb_leaf_wait_cmd(): validate received command extents Date: Fri, 7 Aug 2026 16:37:17 +0200 Message-ID: <20260807143423.624705933@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260807143418.516897842@linuxfoundation.org> References: <20260807143418.516897842@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.12-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 @@ -668,13 +668,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; } @@ -1677,7 +1686,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; }