Skip to content

Commit 8a11ff0

Browse files
avasummerkuba-moo
authored andcommitted
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. Reported-by: Yuhao Jiang <danisjiang@gmail.com> Reported-by: Junrui Luo <moonafterrain@outlook.com> Fixes: b482cd2 ("net-caif: add CAIF core protocol stack") Signed-off-by: Junrui Luo <moonafterrain@outlook.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/SYBPR01MB7881511122BAFEA8212A1608AFA6A@SYBPR01MB7881.ausprd01.prod.outlook.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 71cfa7c commit 8a11ff0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

net/caif/cffrml.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,15 @@ static int cffrml_receive(struct cflayer *layr, struct cfpkt *pkt)
9292
len = le16_to_cpu(tmp);
9393

9494
/* Subtract for FCS on length if FCS is not used. */
95-
if (!this->dofcs)
95+
if (!this->dofcs) {
96+
if (len < 2) {
97+
++cffrml_rcv_error;
98+
pr_err("Invalid frame length (%d)\n", len);
99+
cfpkt_destroy(pkt);
100+
return -EPROTO;
101+
}
96102
len -= 2;
103+
}
97104

98105
if (cfpkt_setlen(pkt, len) < 0) {
99106
++cffrml_rcv_error;

0 commit comments

Comments
 (0)