Skip to contentSkip to conversation

caif: fix integer underflow in cffrml_receive()

PATCH Applied Junrui Luo 4 participants 5 messages Dec 4, 2025 – Dec 15, 2025

Subsystems (2)
lore
Share & tools
lore

Junrui Luo

author
#0 lore raw

PATCH 1/1 caif: fix integer underflow in cffrml_receive()

The cffrml_receive() function extracts a length field from the packet header and, when FCS is disabled, subtracts 2 from this length without validating that len >= 2.

If an attacker sends a malicious packet with a length field of 0 or 1 to an interface with FCS disabled, the subtraction causes an integer underflow.

This can lead to memory exhaustion and kernel instability, potential information disclosure if padding contains uninitialized kernel memory.

Fix this by validating that len >= 2 before performing the subtraction.

Fixes b482cd2053e3 ("net-caif: add CAIF core protocol stack")
---
 net/caif/cffrml.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
net/caif/cffrml.c +8 -1
index 6651a8dc62e0..d4d63586053a 100644
@@ -92,8 +92,15 @@ static int cffrml_receive(struct cflayer *layr, struct cfpkt *pkt)
 	len = le16_to_cpu(tmp);
 
 	/* Subtract for FCS on length if FCS is not used. */
-	if (!this->dofcs)
+	if (!this->dofcs) {
+		if (len < 2) {
+			++cffrml_rcv_error;
+			pr_err("Invalid frame length (%d)\n", len);
+			cfpkt_destroy(pkt);
+			return -EPROTO;
+		}
 		len -= 2;
+	}
 
 	if (cfpkt_setlen(pkt, len) < 0) {
 		++cffrml_rcv_error;

---
base-commit: 559e608c46553c107dbba19dae0854af7b219400
change-id: 20251204-fixes-23393d72bfc8

Best regards,

Signature · 1 line
Junrui Luo <[email protected]>
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Junrui Luo

The cffrml_receive() function extracts a length field from the packet header and, when FCS is disabled, subtracts 2 from this length without validating that len >= 2.

If an attacker sends a malicious packet with a length field of 0 or 1 to an interface with FCS disabled, the subtraction causes an integer underflow.

This can lead to memory exhaustion and kernel instability, potential information disclosure if padding contains uninitialized kernel memory.

Quoted 6 lines

Fix this by validating that len >= 2 before performing the subtraction.

Fixes b482cd2053e3 ("net-caif: add CAIF core protocol stack")

Hi Junrui,

I agree with your analysis and that the problem was introduced by the cited commit.

I think that this function could benefit with a goto label that is jumped to by all of the cases that follow the same error handling logic as this one - I count 4 including this one. But as a minimal bug fix I agree this is a good approach.

No need to repost, but in future please consider targeting networking bug fixes at the net tree like this:

Subject: [PATCH net] ...

...

#2 lore raw
In reply to Junrui Luo
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Thu, 04 Dec 2025 21:30:47 +0800 you wrote:

The cffrml_receive() function extracts a length field from the packet header and, when FCS is disabled, subtracts 2 from this length without validating that len >= 2.

If an attacker sends a malicious packet with a length field of 0 or 1 to an interface with FCS disabled, the subtraction causes an integer underflow.

[...]

Here is the summary with links:
- caif: fix integer underflow in cffrml_receive()

    https://git.kernel.org/netdev/net/c/8a11ff0948b5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#3 lore raw
In reply to Junrui Luo
Quoted 26 lines · On Thu, 04 Dec 2025 21:30:47 +0800 Junrui Luo <[email protected]> wrote:

The cffrml_receive() function extracts a length field from the packet header and, when FCS is disabled, subtracts 2 from this length without validating that len >= 2.

If an attacker sends a malicious packet with a length field of 0 or 1 to an interface with FCS disabled, the subtraction causes an integer underflow.

This can lead to memory exhaustion and kernel instability, potential information disclosure if padding contains uninitialized kernel memory.

Fix this by validating that len >= 2 before performing the subtraction.

Fixes b482cd2053e3 ("net-caif: add CAIF core protocol stack")
---
 net/caif/cffrml.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
net/caif/cffrml.c +0 -0
index 6651a8dc62e0..d4d63586053a 100644

net/caif/cffrml.c static int cffrml_receive(struct cflayer *layr, struct cfpkt *pkt) · line 98

Quoted 8 lines
net/caif/cffrml.c +4 -1
@@ -92,8 +92,15 @@ static int cffrml_receive(struct cflayer *layr, struct cfpkt *pkt)
 	len = le16_to_cpu(tmp);
 
 	/* Subtract for FCS on length if FCS is not used. */
-	if (!this->dofcs)
+	if (!this->dofcs) {
+		if (len < 2) {
+			++cffrml_rcv_error;
+			pr_err("Invalid frame length (%d)\n", len);

Doesn't that let the same remote attacker flood the kernel message buffer?

David

Quoted 14 lines
net/caif/cffrml.c +4 -1
+			cfpkt_destroy(pkt);
+			return -EPROTO;
+		}
 		len -= 2;
+	}
 
 	if (cfpkt_setlen(pkt, len) < 0) {
 		++cffrml_rcv_error;
 
---

base-commit: 559e608c46553c107dbba19dae0854af7b219400
change-id: 20251204-fixes-23393d72bfc8

Best regards,

author
#4 lore raw
Quoted 31 lines · David Laight
Quoted 28 lines · On Thu, 04 Dec 2025 21:30:47 +0800 Junrui Luo <[email protected]> wrote:

The cffrml_receive() function extracts a length field from the packet header and, when FCS is disabled, subtracts 2 from this length without validating that len >= 2.

If an attacker sends a malicious packet with a length field of 0 or 1 to an interface with FCS disabled, the subtraction causes an integer underflow.

This can lead to memory exhaustion and kernel instability, potential information disclosure if padding contains uninitialized kernel memory.

Fix this by validating that len >= 2 before performing the subtraction.

Fixes b482cd2053e3 ("net-caif: add CAIF core protocol stack")
---
 net/caif/cffrml.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
net/caif/cffrml.c +0 -0
index 6651a8dc62e0..d4d63586053a 100644
@@ -92,8 +92,15 @@ static int cffrml_receive(struct cflayer *layr, struct cfpkt *pkt)
 	len = le16_to_cpu(tmp);
 
Quoted 8 lines

net/caif/cffrml.c static int cffrml_receive(struct cflayer *layr, struct cfpkt *pkt) · line 98

Quoted 6 lines
net/caif/cffrml.c +4 -1
 	/* Subtract for FCS on length if FCS is not used. */
-	if (!this->dofcs)
+	if (!this->dofcs) {
+		if (len < 2) {
+			++cffrml_rcv_error;
+			pr_err("Invalid frame length (%d)\n", len);

Doesn't that let the same remote attacker flood the kernel message buffer?

Thanks for the review and suggestion. Please let me know if you'd like me to repost a patch removing pr_err(), or if there is a preferred alternative.

Quoted 9 lines

David

Quoted 6 lines
net/caif/cffrml.c +4 -0
+			cfpkt_destroy(pkt);
+			return -EPROTO;
+		}
 		len -= 2;
+	}
 
Quoted 9 lines
Quoted 8 lines
net/caif/cffrml.c +0 -1
 	if (cfpkt_setlen(pkt, len) < 0) {
 		++cffrml_rcv_error;
 
---

base-commit: 559e608c46553c107dbba19dae0854af7b219400
change-id: 20251204-fixes-23393d72bfc8

Best regards,

Thanks,
Junrui Luo