From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D921D3502B9; Wed, 3 Dec 2025 16:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764778412; cv=none; b=ikh4sSBWBSy4aWpDoSycwy1b/qY25ObI5yVI7Z1kUTNwHmcElYaoo+xrTsnGPMyrspZV41XvGdwhHvZVRzAiklivX5QqWNhcykSVBgtVR9YQljutIpWTiy/88WmJaU+T0Ygi7jAuuZYOe/NnQKDL7RDC8U6xXJMjEQMJ0JS6nXU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764778412; c=relaxed/simple; bh=zxlpV9eeU5+l0jSQwuWlGDColVyTPcgNhi9c2jDEfPs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MNO3zWibEL9Sh/4FPKnfhN78lV4eWvpRCyXrWYIl4sETel9N1qqHo/5ClRP31WTnLvdrAnkznUCTNXf6+zoyc6LmXsRf4YQWXjePERois2Fdmz43xBMlXBis9eJLuAmq/ZmNES73Zxb8GpdAfOI0J12baFQUSqpWipNYhoj0juY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MnrD0Jr9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="MnrD0Jr9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D987DC4CEF5; Wed, 3 Dec 2025 16:13:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1764778411; bh=zxlpV9eeU5+l0jSQwuWlGDColVyTPcgNhi9c2jDEfPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MnrD0Jr9/BmQF8MjjuRLOes/fZPcUmlrJjmxDsXVxDetCZ9xOlV9Wq+YCzoKYQR78 fIAvMBUaGQz7QnfYgBsGtE+l2KmjrpFMxVBKUaLMkwS9NaEsF/TRjB0MD3IEwg5sg5 FvZdRNCXY9pDKOxEzM2oW0/FSKZJe0g7YIY1czuM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Seungjin Bae , Jimmy Assarsson , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 5.15 337/392] can: kvaser_usb: leaf: Fix potential infinite loop in command parsers Date: Wed, 3 Dec 2025 16:28:07 +0100 Message-ID: <20251203152426.572780297@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251203152414.082328008@linuxfoundation.org> References: <20251203152414.082328008@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: Seungjin Bae [ Upstream commit 0c73772cd2b8cc108d5f5334de89ad648d89b9ec ] The `kvaser_usb_leaf_wait_cmd()` and `kvaser_usb_leaf_read_bulk_callback` functions contain logic to zero-length commands. These commands are used to align data to the USB endpoint's wMaxPacketSize boundary. The driver attempts to skip these placeholders by aligning the buffer position `pos` to the next packet boundary using `round_up()` function. However, if zero-length command is found exactly on a packet boundary (i.e., `pos` is a multiple of wMaxPacketSize, including 0), `round_up` function will return the unchanged value of `pos`. This prevents `pos` to be increased, causing an infinite loop in the parsing logic. This patch fixes this in the function by using `pos + 1` instead. This ensures that even if `pos` is on a boundary, the calculation is based on `pos + 1`, forcing `round_up()` to always return the next aligned boundary. Fixes: 7259124eac7d ("can: kvaser_usb: Split driver into kvaser_usb_core.c and kvaser_usb_leaf.c") Signed-off-by: Seungjin Bae Reviewed-by: Jimmy Assarsson Tested-by: Jimmy Assarsson Link: https://patch.msgid.link/20251023162709.348240-1-eeodqql09@gmail.com Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c index 43ec056646661..b6cef22a53e77 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c @@ -610,7 +610,7 @@ static int kvaser_usb_leaf_wait_cmd(const struct kvaser_usb *dev, u8 id, * for further details. */ if (tmp->len == 0) { - pos = round_up(pos, + pos = round_up(pos + 1, le16_to_cpu (dev->bulk_in->wMaxPacketSize)); continue; @@ -1568,7 +1568,7 @@ static void kvaser_usb_leaf_read_bulk_callback(struct kvaser_usb *dev, * number of events in case of a heavy rx load on the bus. */ if (cmd->len == 0) { - pos = round_up(pos, le16_to_cpu + pos = round_up(pos + 1, le16_to_cpu (dev->bulk_in->wMaxPacketSize)); continue; } -- 2.51.0