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 8CB843264CA; Mon, 13 Apr 2026 16:55:21 +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=1776099321; cv=none; b=L6jhx7CXrv60xHR6kIyyCZQcjujwkHNlVh0jaECoGfWRr9dzy4dMANoEjHU9IrXIA11kE1YpJvhQ+Fl0yaihu2PoawwEhagDwcIEQXnvy8e7mCsW5vf16vjEjmw0hOl6gcbHEpYsVpxPa93ZBuQtU1ppgT8JM4oaJNFeqCh/L+E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776099321; c=relaxed/simple; bh=tJetqciEapeVEah8v0vLfGi/O5JP69u8No8Omq5cYm0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fggzDwWLOpWYh9kWhc/sTgqAmrfqlwsLK6bnA71bPPlEcAnbdXcQmwGvo6K2fQxqzX4M+JbNEknzJnnesCEpvW6vcsZ4Rzh0WRDmmLX6FossS9K4GpWp9JuJhtMLg+3f8OtN3jnTT/1fABAvbfoRMNlhJUie6TYjL79pepZxEPY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Dn9MQIlb; 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="Dn9MQIlb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21FA7C2BCB0; Mon, 13 Apr 2026 16:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776099321; bh=tJetqciEapeVEah8v0vLfGi/O5JP69u8No8Omq5cYm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dn9MQIlbAflVf1vM+5FuW1zrBxwShfvfpw3ST8SgRDuQaAPGJ7VQmkC7i09IMGCzk V9lZ0jIy90RCFVWZpEdCEOzxZUYLxfdo61BfLCW9WudnEBLCMfvaieOYupxmEF1KbR 40xAKLr47kBNmKfezGP24XFpaVpRfopR9IS+6ERU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ali Norouzi , Oliver Hartkopp , Marc Kleine-Budde Subject: [PATCH 5.10 296/491] can: gw: fix OOB heap access in cgw_csum_crc8_rel() Date: Mon, 13 Apr 2026 17:59:01 +0200 Message-ID: <20260413155830.125832624@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260413155819.042779211@linuxfoundation.org> References: <20260413155819.042779211@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ali Norouzi commit b9c310d72783cc2f30d103eed83920a5a29c671a upstream. cgw_csum_crc8_rel() correctly computes bounds-safe indices via calc_idx(): int from = calc_idx(crc8->from_idx, cf->len); int to = calc_idx(crc8->to_idx, cf->len); int res = calc_idx(crc8->result_idx, cf->len); if (from < 0 || to < 0 || res < 0) return; However, the loop and the result write then use the raw s8 fields directly instead of the computed variables: for (i = crc8->from_idx; ...) /* BUG: raw negative index */ cf->data[crc8->result_idx] = ...; /* BUG: raw negative index */ With from_idx = to_idx = result_idx = -64 on a 64-byte CAN FD frame, calc_idx(-64, 64) = 0 so the guard passes, but the loop iterates with i = -64, reading cf->data[-64], and the write goes to cf->data[-64]. This write might end up to 56 (7.0-rc) or 40 (<= 6.19) bytes before the start of the canfd_frame on the heap. The companion function cgw_csum_xor_rel() uses `from`/`to`/`res` correctly throughout; fix cgw_csum_crc8_rel() to match. Confirmed with KASAN on linux-7.0-rc2: BUG: KASAN: slab-out-of-bounds in cgw_csum_crc8_rel+0x515/0x5b0 Read of size 1 at addr ffff8880076619c8 by task poc_cgw_oob/62 To configure the can-gw crc8 checksums CAP_NET_ADMIN is needed. Fixes: 456a8a646b25 ("can: gw: add support for CAN FD frames") Cc: stable@vger.kernel.org Reported-by: Ali Norouzi Reviewed-by: Oliver Hartkopp Acked-by: Oliver Hartkopp Signed-off-by: Ali Norouzi Signed-off-by: Oliver Hartkopp Link: https://patch.msgid.link/20260319-fix-can-gw-and-can-isotp-v2-1-c45d52c6d2d8@pengutronix.de Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- net/can/gw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/net/can/gw.c +++ b/net/can/gw.c @@ -312,10 +312,10 @@ static void cgw_csum_crc8_rel(struct can return; if (from <= to) { - for (i = crc8->from_idx; i <= crc8->to_idx; i++) + for (i = from; i <= to; i++) crc = crc8->crctab[crc ^ cf->data[i]]; } else { - for (i = crc8->from_idx; i >= crc8->to_idx; i--) + for (i = from; i >= to; i--) crc = crc8->crctab[crc ^ cf->data[i]]; } @@ -334,7 +334,7 @@ static void cgw_csum_crc8_rel(struct can break; } - cf->data[crc8->result_idx] = crc ^ crc8->final_xor_val; + cf->data[res] = crc ^ crc8->final_xor_val; } static void cgw_csum_crc8_pos(struct canfd_frame *cf,