Skip to contentSkip to conversation

dibs: loopback: validate offset and size in move_data()

PATCH Applied Dust Li 4 participants 5 messages Jul 7 – Jul 9

Subsystems (4)
lore
Share & tools
lore

Dust Li

author
#0 lore raw

PATCH 1/1 dibs: loopback: validate offset and size in move_data()

The loopback move_data() performs a memcpy into the registered DMB without checking whether offset + size exceeds the DMB length. Unlike real ISM hardware, which enforces memory region bounds natively, the software loopback has no such protection.

A peer-supplied out-of-bounds offset or oversized write would result in an OOB write past the allocated kernel buffer. Add an explicit bounds check before the memcpy to reject such requests with -EINVAL.

Fixes f7a22071dbf3("net/smc: implement DMB-related operations of loopback-ism")
---
 drivers/dibs/dibs_loopback.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/dibs/dibs_loopback.c +5 -0
index ec3b48cb0e87..0f2e09311152 100644
@@ -254,6 +254,11 @@ static int dibs_lo_move_data(struct dibs_dev *dibs, u64 dmb_tok,
 		read_unlock_bh(&ldev->dmb_ht_lock);
 		return -EINVAL;
 	}
+	if ((u64)offset + size > rmb_node->len) {
+		read_unlock_bh(&ldev->dmb_ht_lock);
+		return -EINVAL;
+	}
+
 	memcpy((char *)rmb_node->cpu_addr + offset, data, size);
 	sba_idx = rmb_node->sba_idx;
 	read_unlock_bh(&ldev->dmb_ht_lock);
Signature · 1 line
2.43.7
author
#1 lore raw
Quoted 5 lines · Dust Li

The loopback move_data() performs a memcpy into the registered DMB without checking whether offset + size exceeds the DMB length. Unlike real ISM hardware, which enforces memory region bounds natively, the software loopback has no such protection.

Quoted 7 lines

A peer-supplied out-of-bounds offset or oversized write would result in an OOB write past the allocated kernel buffer. Add an explicit bounds check before the memcpy to reject such requests with -EINVAL.

Fixes f7a22071dbf3("net/smc: implement DMB-related operations of loopback-ism")

Best regards,
Dust

Quoted 23 lines

---
drivers/dibs/dibs_loopback.c | 5 +++++

1 file changed, 5 insertions(+)
drivers/dibs/dibs_loopback.c +5 -0
index ec3b48cb0e87..0f2e09311152 100644
@@ -254,6 +254,11 @@ static int dibs_lo_move_data(struct dibs_dev *dibs, u64 dmb_tok,
 		read_unlock_bh(&ldev->dmb_ht_lock);
 		return -EINVAL;
 	}
+	if ((u64)offset + size > rmb_node->len) {
+		read_unlock_bh(&ldev->dmb_ht_lock);
+		return -EINVAL;
+	}
+
 	memcpy((char *)rmb_node->cpu_addr + offset, data, size);
 	sba_idx = rmb_node->sba_idx;
 	read_unlock_bh(&ldev->dmb_ht_lock);
Signature · 1 line
2.43.7
#2 lore raw
Quoted 10 lines · Dust Li
Quoted 9 lines · Dust Li

The loopback move_data() performs a memcpy into the registered DMB without checking whether offset + size exceeds the DMB length. Unlike real ISM hardware, which enforces memory region bounds natively, the software loopback has no such protection.

A peer-supplied out-of-bounds offset or oversized write would result in an OOB write past the allocated kernel buffer. Add an explicit bounds check before the memcpy to reject such requests with -EINVAL.

Quoted 5 lines
Quoted 3 lines
Fixes f7a22071dbf3("net/smc: implement DMB-related operations of loopback-ism")

Could you provide a link to the report?

Thanks
Andrew

maintainer
#3 lore raw
Quoted 11 lines · Andrew Lunn
Quoted 10 lines · Dust Li
Quoted 9 lines · Dust Li

The loopback move_data() performs a memcpy into the registered DMB without checking whether offset + size exceeds the DMB length. Unlike real ISM hardware, which enforces memory region bounds natively, the software loopback has no such protection.

A peer-supplied out-of-bounds offset or oversized write would result in an OOB write past the allocated kernel buffer. Add an explicit bounds check before the memcpy to reject such requests with -EINVAL.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Fixes f7a22071dbf3("net/smc: implement DMB-related operations of loopback-ism")

Could you provide a link to the report?

Since both reporters belong to the same org, I assume they co-partecipated at the initial report.

Also there is a problem with the fixes tag that I'll address while applying the patch.

/P

#4 lore raw
In reply to Dust Li
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

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

Quoted 10 lines · On Tue, 7 Jul 2026 15:43:18 +0800 you wrote:

The loopback move_data() performs a memcpy into the registered DMB without checking whether offset + size exceeds the DMB length. Unlike real ISM hardware, which enforces memory region bounds natively, the software loopback has no such protection.

A peer-supplied out-of-bounds offset or oversized write would result in an OOB write past the allocated kernel buffer. Add an explicit bounds check before the memcpy to reject such requests with -EINVAL.

[...]

Here is the summary with links:
- [net] dibs: loopback: validate offset and size in move_data()

    https://git.kernel.org/netdev/net/c/78237e3c0720

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html