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 121783A3E7A; Fri, 7 Aug 2026 15:46: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=1786117588; cv=none; b=k/PT2jNbl4zVO1MwsINPdRQpzMpG5WT+cZMOy77mVmtyLi4XIoPOvkevLxZKXIK2V3P68kKc/Z2drc0XgTZmfqO4aNkmnCGTWzpj3+om9BlJoI9w9hqVW4SJxVKfd1ooseUJtyiTmXmIx1NfNpLpe2hXMqLaV9SrTMs0KhcMstw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786117588; c=relaxed/simple; bh=vctz7i1kXh7zIORNQlwUfLE06l276Ps/4aKFnlrPgzI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rhzFX4injm1BRbgwP+mdkTyNTec63/unkDPVw4tCWbL0IFR/ZJfUrNZoB01jjbJF5cXNEwadfrbUm2Qyx8+YPNbU3l0WxBHA+t/L/V0nirr2d+XNhbIyFEAO38vbraFCV17BoEawkyDg5b6lt/ZhQYLE6knpfIVj1J/ZQfST4t4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TRpqJ9vM; 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="TRpqJ9vM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FF6F1F000E9; Fri, 7 Aug 2026 15:46:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786117586; bh=O2ecqr5YaW1KQcozhCvqZ2oD2JsURUVdCQR3sjiNAtU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TRpqJ9vMyPU2dPdGkNqrvuqo8VQDUjCeQwM2k7Vy3lkhIIh8V7PNRHJaWViW7QEpo CYlWEP+BnPHZ9wQPZAoZFHpLjn77mefTc1nnTJvQxKNp6p+DBxvRSy3wJAxgOkBVlp PXPbJQH2STjm/VnVaZTqkiaVIsEpnkfocmvskOuk= 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 7.1 371/438] can: kvaser_usb_leaf: kvaser_usb_leaf_wait_cmd(): validate received command extents Date: Fri, 7 Aug 2026 16:39:27 +0200 Message-ID: <20260807143435.880140042@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260807143428.008222056@linuxfoundation.org> References: <20260807143428.008222056@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 7.1-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 @@ -691,13 +691,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; } @@ -1737,7 +1746,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; }