Skip to content

Commit d44b5e2

Browse files
committed
ibmvnic: Use kernel helpers for hex dumps
jira LE-3504 cve CVE-2025-22104 Rebuild_History Non-Buildable kernel-6.12.0-55.19.1.el10_0 commit-author Nick Child <[email protected]> commit d93a6ca Previously, when the driver was printing hex dumps, the buffer was cast to an 8 byte long and printed using string formatters. If the buffer size was not a multiple of 8 then a read buffer overflow was possible. Therefore, create a new ibmvnic function that loops over a buffer and calls hex_dump_to_buffer instead. This patch address KASAN reports like the one below: ibmvnic 30000003 env3: Login Buffer: ibmvnic 30000003 env3: 01000000af000000 <...> ibmvnic 30000003 env3: 2e6d62692e736261 ibmvnic 30000003 env3: 65050003006d6f63 ================================================================== BUG: KASAN: slab-out-of-bounds in ibmvnic_login+0xacc/0xffc [ibmvnic] Read of size 8 at addr c0000001331a9aa8 by task ip/17681 <...> Allocated by task 17681: <...> ibmvnic_login+0x2f0/0xffc [ibmvnic] ibmvnic_open+0x148/0x308 [ibmvnic] __dev_open+0x1ac/0x304 <...> The buggy address is located 168 bytes inside of allocated 175-byte region [c0000001331a9a00, c0000001331a9aaf) <...> ================================================================= ibmvnic 30000003 env3: 000000000033766e Fixes: 032c5e8 ("Driver for IBM System i/p VNIC protocol") Signed-off-by: Nick Child <[email protected]> Reviewed-by: Dave Marquardt <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> (cherry picked from commit d93a6ca) Signed-off-by: Jonathan Maple <[email protected]>
1 parent ed0c10c commit d44b5e2

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

drivers/net/ethernet/ibm/ibmvnic.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4830,6 +4830,18 @@ static void vnic_add_client_data(struct ibmvnic_adapter *adapter,
48304830
strscpy(vlcd->name, adapter->netdev->name, len);
48314831
}
48324832

4833+
static void ibmvnic_print_hex_dump(struct net_device *dev, void *buf,
4834+
size_t len)
4835+
{
4836+
unsigned char hex_str[16 * 3];
4837+
4838+
for (size_t i = 0; i < len; i += 16) {
4839+
hex_dump_to_buffer((unsigned char *)buf + i, len - i, 16, 8,
4840+
hex_str, sizeof(hex_str), false);
4841+
netdev_dbg(dev, "%s\n", hex_str);
4842+
}
4843+
}
4844+
48334845
static int send_login(struct ibmvnic_adapter *adapter)
48344846
{
48354847
struct ibmvnic_login_rsp_buffer *login_rsp_buffer;
@@ -4940,10 +4952,8 @@ static int send_login(struct ibmvnic_adapter *adapter)
49404952
vnic_add_client_data(adapter, vlcd);
49414953

49424954
netdev_dbg(adapter->netdev, "Login Buffer:\n");
4943-
for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) {
4944-
netdev_dbg(adapter->netdev, "%016lx\n",
4945-
((unsigned long *)(adapter->login_buf))[i]);
4946-
}
4955+
ibmvnic_print_hex_dump(adapter->netdev, adapter->login_buf,
4956+
adapter->login_buf_sz);
49474957

49484958
memset(&crq, 0, sizeof(crq));
49494959
crq.login.first = IBMVNIC_CRQ_CMD;
@@ -5320,15 +5330,13 @@ static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter)
53205330
{
53215331
struct device *dev = &adapter->vdev->dev;
53225332
struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf;
5323-
int i;
53245333

53255334
dma_unmap_single(dev, adapter->ip_offload_tok,
53265335
sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE);
53275336

53285337
netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n");
5329-
for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++)
5330-
netdev_dbg(adapter->netdev, "%016lx\n",
5331-
((unsigned long *)(buf))[i]);
5338+
ibmvnic_print_hex_dump(adapter->netdev, buf,
5339+
sizeof(adapter->ip_offload_buf));
53325340

53335341
netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum);
53345342
netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum);
@@ -5559,10 +5567,8 @@ static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq,
55595567
netdev->mtu = adapter->req_mtu - ETH_HLEN;
55605568

55615569
netdev_dbg(adapter->netdev, "Login Response Buffer:\n");
5562-
for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) {
5563-
netdev_dbg(adapter->netdev, "%016lx\n",
5564-
((unsigned long *)(adapter->login_rsp_buf))[i]);
5565-
}
5570+
ibmvnic_print_hex_dump(netdev, adapter->login_rsp_buf,
5571+
adapter->login_rsp_buf_sz);
55665572

55675573
/* Sanity checks */
55685574
if (login->num_txcomp_subcrqs != login_rsp->num_txsubm_subcrqs ||

0 commit comments

Comments
 (0)