net: mana: cap HWC init max message size to HW_CHANNEL_MAX_REQUEST_SIZE
Subsystems (5)
PATCH 1/1 net: mana: cap HWC init max message size to HW_CHANNEL_MAX_REQUEST_SIZE
mana_hwc_init_event_handler() in hw_channel.c stores device-advertised HWC_INIT_DATA_MAX_REQUEST and HWC_INIT_DATA_MAX_RESPONSE values without bounds checking. mana_hwc_alloc_dma_buf() later computes the DMA buffer size as MANA_PAGE_ALIGN(q_depth * max_msg_size) in 32-bit arithmetic. A malicious device returning a large max_msg_size causes the product to wrap, allocating a small buffer while laying out q_depth request slots at the unwrapped stride, placing slots outside the allocation.
Impact: a compromised hypervisor device model or malicious MANA PCI device can cause out-of-bounds DMA buffer writes during HWC channel initialization. A reproducer is available on request.
Clamp both values to HW_CHANNEL_MAX_REQUEST_SIZE (4096), consistent with the cap already applied at the channel-create callsite.
--- drivers/net/ethernet/microsoft/mana/hw_channel.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/microsoft/mana/hw_channel.c +4 -0
@@ -152,10 +152,14 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,break ;case HWC_INIT_DATA_MAX_REQUEST : +if (val ==0 || val >HW_CHANNEL_MAX_REQUEST_SIZE ) + val =HW_CHANNEL_MAX_REQUEST_SIZE ; hwc->hwc_init_max_req_msg_size = val;break ;case HWC_INIT_DATA_MAX_RESPONSE : +if (val ==0 || val >HW_CHANNEL_MAX_REQUEST_SIZE ) + val =HW_CHANNEL_MAX_REQUEST_SIZE ; hwc->hwc_init_max_resp_msg_size = val;break ;
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [Medium] The commit message describes an integer overflow vulnerability in mana_hwc_alloc_dma_buf() caused by using unbounded device-advertised message sizes, but this vulnerability is entirely hallucinated and the modified variables are dead code.
- [Low] The patch incorrectly clamps HWC_INIT_DATA_MAX_RESPONSE using HW_CHANNEL_MAX_REQUEST_SIZE instead of HW_CHANNEL_MAX_RESPONSE_SIZE.
Pre-existing issues:
- [High] An unchecked eq_db.doorbell index from a hardware event causes an out-of-bounds MMIO write during doorbell ringing.
- [High] An unchecked max_num_cqs value retrieved from the hardware event allows a malicious device to trigger enormous kernel memory allocations. --
--- Patch [1]: [PATCH] net: mana: cap HWC init max message size to HW_CHANNEL_MAX_REQUEST_SIZE --- commit ea80048daa839e9f12f06618139e15fddebc0ac5
Author: Michael Bommarito <[email protected]>
net: mana: cap HWC init max message size to HW_CHANNEL_MAX_REQUEST_SIZE
The commit adds bounds checking for max message size during HWC initialization. It claims this prevents an out-of-bounds DMA buffer write in mana_hwc_alloc_dma_buf().
Quoted 8 lines
mana_hwc_init_event_handler()inhw_channel.cstores device-advertisedHWC_INIT_DATA_MAX_REQUESTandHWC_INIT_DATA_MAX_RESPONSEvalues without bounds checking.mana_hwc_alloc_dma_buf()later computes the DMA buffer size asMANA_PAGE_ALIGN(q_depth * max_msg_size)in 32-bit arithmetic. A malicious device returning a largemax_msg_sizecauses the product to wrap, allocating a small buffer while laying outq_depthrequest slots at the unwrapped stride, placing slots outside the allocation.
[Severity: Medium]
Is this description accurate?
The modified variables (hwc->hwc_init_max_req_msg_size and hwc->hwc_init_max_resp_msg_size) appear to be dead code that do not affect memory allocation. mana_hwc_alloc_dma_buf() is invoked before the event handler runs (via mana_hwc_init_queues()) using hardcoded sizes (4096), not the hardware-provided ones.
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +0
-0@@ -150,10 +150,14 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,break ;
drivers/net/ethernet/microsoft/mana/hw_channel.c static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self, · line 160
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +4
-0case HWC_INIT_DATA_MAX_REQUEST : +if (val ==0 || val >HW_CHANNEL_MAX_REQUEST_SIZE ) + val =HW_CHANNEL_MAX_REQUEST_SIZE ; hwc->hwc_init_max_req_msg_size = val;break ;case HWC_INIT_DATA_MAX_RESPONSE : +if (val ==0 || val >HW_CHANNEL_MAX_REQUEST_SIZE ) + val =HW_CHANNEL_MAX_REQUEST_SIZE ;
[Severity: Low]
Does this incorrectly clamp HWC_INIT_DATA_MAX_RESPONSE using HW_CHANNEL_MAX_REQUEST_SIZE instead of HW_CHANNEL_MAX_RESPONSE_SIZE?
drivers/net/ethernet/microsoft/mana/hw_channel.c static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self, · line 165
Quoted 3 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +0
-0hwc->hwc_init_max_resp_msg_size = val;break ;
[Severity: High]
This is a pre-existing issue, but is it possible for a malicious device to trigger an out-of-bounds MMIO write via an unchecked doorbell index?
Earlier in mana_hwc_init_event_handler():
case GDMA_EQE_HWC_INIT_EQ_ID_DB: eq_db.as_uint32 = event->details[0]; hwc->cq->gdma_eq->id = eq_db.eq_id; gd->doorbell = eq_db.doorbell;
When the driver posts WQEs and rings the doorbell via mana_gd_ring_doorbell():
drivers/net/ethernet/microsoft/mana/gdma_main.c:mana_gd_ring_doorbell() {
...
void __iomem *addr = gc->db_page_base + gc->db_page_size * db_index;
...
writeq(e.as_uint64, addr);
...
}If eq_db.doorbell is excessively large, could it calculate a memory-mapped address that exceeds gc->bar0_size, resulting in an out-of-bounds writeq() that corrupts adjacent mappings?
[Severity: High]
This is a pre-existing issue, but does the unchecked max_num_cqs value allow a malicious device to exhaust system memory?
Later in mana_hwc_init_event_handler():
case HWC_INIT_DATA_MAX_NUM_CQS: gd->gdma_context->max_num_cqs = val; break;
This unbounded max_num_cqs value is later used for memory allocation:
drivers/net/ethernet/microsoft/mana/hw_channel.c:mana_hwc_establish_channel() {
...
gc->cq_table = vcalloc(gc->max_num_cqs, sizeof(struct gdma_queue *));
...
}If max_num_cqs is an exceptionally large 32-bit value (e.g., 0x1FFFFFFF), could vcalloc() attempt to allocate multiple gigabytes of memory and cause a host-level denial of service?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Simon Horman
reviewerThis is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
https://sashiko.dev/#/patchset/[email protected]?part=1
---
--- Patch [1]: [PATCH] net: mana: cap HWC init max message size to HW_CHANNEL_MAX_REQUEST_SIZE --- commit ea80048daa839e9f12f06618139e15fddebc0ac5
Author: Michael Bommarito <[email protected]>
net: mana: cap HWC init max message size to HW_CHANNEL_MAX_REQUEST_SIZE
The commit adds bounds checking for max message size during HWC initialization. It claims this prevents an out-of-bounds DMA buffer write in mana_hwc_alloc_dma_buf().
Quoted 8 lines
mana_hwc_init_event_handler()inhw_channel.cstores device-advertisedHWC_INIT_DATA_MAX_REQUESTandHWC_INIT_DATA_MAX_RESPONSEvalues without bounds checking.mana_hwc_alloc_dma_buf()later computes the DMA buffer size asMANA_PAGE_ALIGN(q_depth * max_msg_size)in 32-bit arithmetic. A malicious device returning a largemax_msg_sizecauses the product to wrap, allocating a small buffer while laying outq_depthrequest slots at the unwrapped stride, placing slots outside the allocation.
[Severity: Medium]
Is this description accurate?
The modified variables (hwc->hwc_init_max_req_msg_size and hwc->hwc_init_max_resp_msg_size) appear to be dead code that do not affect memory allocation. mana_hwc_alloc_dma_buf() is invoked before the event handler runs (via mana_hwc_init_queues()) using hardcoded sizes (4096), not the hardware-provided ones.
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +0
-0@@ -150,10 +150,14 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,break ;
drivers/net/ethernet/microsoft/mana/hw_channel.c static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self, · line 160
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +4
-0case HWC_INIT_DATA_MAX_REQUEST : +if (val ==0 || val >HW_CHANNEL_MAX_REQUEST_SIZE ) + val =HW_CHANNEL_MAX_REQUEST_SIZE ; hwc->hwc_init_max_req_msg_size = val;break ;case HWC_INIT_DATA_MAX_RESPONSE : +if (val ==0 || val >HW_CHANNEL_MAX_REQUEST_SIZE ) + val =HW_CHANNEL_MAX_REQUEST_SIZE ;
[Severity: Low]
Does this incorrectly clamp HWC_INIT_DATA_MAX_RESPONSE using HW_CHANNEL_MAX_REQUEST_SIZE instead of HW_CHANNEL_MAX_RESPONSE_SIZE?
drivers/net/ethernet/microsoft/mana/hw_channel.c static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self, · line 165
Quoted 3 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +0
-0hwc->hwc_init_max_resp_msg_size = val;break ;
[Severity: High]
This is a pre-existing issue, but is it possible for a malicious device to trigger an out-of-bounds MMIO write via an unchecked doorbell index?
Earlier in mana_hwc_init_event_handler():
case GDMA_EQE_HWC_INIT_EQ_ID_DB: eq_db.as_uint32 = event->details[0]; hwc->cq->gdma_eq->id = eq_db.eq_id; gd->doorbell = eq_db.doorbell;
When the driver posts WQEs and rings the doorbell via mana_gd_ring_doorbell():
drivers/net/ethernet/microsoft/mana/gdma_main.c:mana_gd_ring_doorbell() {
...
void __iomem *addr = gc->db_page_base + gc->db_page_size * db_index;
...
writeq(e.as_uint64, addr);
...
}If eq_db.doorbell is excessively large, could it calculate a memory-mapped address that exceeds gc->bar0_size, resulting in an out-of-bounds writeq() that corrupts adjacent mappings?
[Severity: High]
This is a pre-existing issue, but does the unchecked max_num_cqs value allow a malicious device to exhaust system memory?
Later in mana_hwc_init_event_handler():
case HWC_INIT_DATA_MAX_NUM_CQS: gd->gdma_context->max_num_cqs = val; break;
This unbounded max_num_cqs value is later used for memory allocation:
drivers/net/ethernet/microsoft/mana/hw_channel.c:mana_hwc_establish_channel() {
...
gc->cq_table = vcalloc(gc->max_num_cqs, sizeof(struct gdma_queue *));
...
}If max_num_cqs is an exceptionally large 32-bit value (e.g., 0x1FFFFFFF), could vcalloc() attempt to allocate multiple gigabytes of memory and cause a host-level denial of service?
Quoted 8 lines · Michael Bommarito
mana_hwc_init_event_handler()inhw_channel.cstores device-advertisedHWC_INIT_DATA_MAX_REQUESTandHWC_INIT_DATA_MAX_RESPONSEvalues without bounds checking.mana_hwc_alloc_dma_buf()later computes the DMA buffer size asMANA_PAGE_ALIGN(q_depth * max_msg_size)in 32-bit arithmetic. A malicious device returning a largemax_msg_sizecauses the product to wrap, allocating a small buffer while laying outq_depthrequest slots at the unwrapped stride, placing slots outside the allocation.
I don't think the described data flow actually
exists in the current tree, so the security framing looks inaccurate. Please check the comment below.
Quoted 25 lines
Impact: a compromised hypervisor device model or malicious MANA PCI device can cause out-of-bounds DMA buffer writes during HWC channel initialization. A reproducer is available on request.
Clamp both values to
HW_CHANNEL_MAX_REQUEST_SIZE(4096), consistent with the cap already applied at the channel-create callsite.Fixes ca9c54d2d6a5 ("net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)")Assisted-by Claude:claude-opus-4-7Signed-off-by Michael Bommarito <[email protected]>--- drivers/net/ethernet/microsoft/mana/hw_channel.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/net/ethernet/microsoft/mana/hw_channel.c +1
-0@@ -152,10 +152,14 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,break ;case HWC_INIT_DATA_MAX_REQUEST : +if (val ==0 || val >HW_CHANNEL_MAX_REQUEST_SIZE )
drivers/net/ethernet/microsoft/mana/hw_channel.c static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self, · line 165
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +3
-0+ val =HW_CHANNEL_MAX_REQUEST_SIZE ; hwc->hwc_init_max_req_msg_size = val;break ;case HWC_INIT_DATA_MAX_RESPONSE : +if (val ==0 || val >HW_CHANNEL_MAX_REQUEST_SIZE ) + val =HW_CHANNEL_MAX_REQUEST_SIZE ; hwc->hwc_init_max_resp_msg_size = val;break ;
The clamp is applied to hwc->hwc_init_max_req_msg_size and hwc->hwc_init_max_resp_msg_size. Tracing where those two fields are consumed:
mana_hwc_init_event_handler()
|
mana_hwc_establish_channel() // copies them out to *max_req_msg_size
| and *max_resp_msg_size
mana_hwc_create_channel() // passes those locals only to
| mana_hwc_test_channel()
mana_hwc_test_channel() // passed as parameters but never
used them
The DMA buffers that alloc_dma_buf() sizes are created from mana_hwc_init_queues(), which is called with the compile-time constants:
err = mana_hwc_init_queues(hwc, HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH,
HW_CHANNEL_MAX_REQUEST_SIZE, HW_CHANNEL_MAX_RESPONSE_SIZE);
Therefore, q_depth * max_msg_size cannot wrap from a device-controlled value here.
Thanks,
Vennela
Quoted 5 lines
Signature · 1 line
2.53.0
Quoted 3 lines · Erni Sri Satya Vennela
I don't think the described data flow actually
exists in the current tree, so the security framing looks inaccurate. Please check the comment below.
Agreed, I got mixed up on that. Sorry for the noise
Thanks,
Mike