Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

eth: fbnic: Fix counter roll-over issue

Fix a potential counter roll-over issue in fbnic_mbx_alloc_rx_msgs()
when calculating descriptor slots. The issue occurs when head - tail
results in a large positive value (unsigned) and the compiler interprets
head - tail - 1 as a signed value.

Since FBNIC_IPC_MBX_DESC_LEN is a power of two, use a masking operation,
which is a common way of avoiding this problem when dealing with these
sort of ring space calculations.

Fixes: da3cde08209e ("eth: fbnic: Add FW communication mechanism")
Signed-off-by: Mohsin Bashir <mohsin.bashr@gmail.com>
Link: https://patch.msgid.link/20251125211704.3222413-1-mohsin.bashr@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Mohsin Bashir and committed by
Jakub Kicinski
6d66e093 27fd0286

+1 -1
+1 -1
drivers/net/ethernet/meta/fbnic/fbnic_fw.c
··· 201 201 return -ENODEV; 202 202 203 203 /* Fill all but 1 unused descriptors in the Rx queue. */ 204 - count = (head - tail - 1) % FBNIC_IPC_MBX_DESC_LEN; 204 + count = (head - tail - 1) & (FBNIC_IPC_MBX_DESC_LEN - 1); 205 205 while (!err && count--) { 206 206 struct fbnic_tlv_msg *msg; 207 207