pimd: fix heap OOB write in BSM fragmenter - #22222
Conversation
Greptile SummaryThis PR hardens the BSM fragment forwarder (
Confidence Score: 4/5The security-critical fragmentation and parse paths are materially improved; no new OOB write vectors introduced, but a handful of edge paths (zero-RP group continuation, frag_rp_cnt invariant comment accuracy) deserve a second look before merge. The fixes are well-structured and address the core heap-OOB write. The pimd/pim_bsm.c β specifically the interaction between the inner-loop flush at line 1044, the continuation group-header copy at lines 1067β1071, and the Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant pim_bsm_frag_send
participant pim_bsm_frag_flush
participant pim_bsm_send_intf
Caller->>pim_bsm_frag_send: buf, len, pim_mtu
pim_bsm_frag_send->>pim_bsm_frag_send: XCALLOC(pak_start, pim_mtu)
loop For each group in buf
pim_bsm_frag_send->>pim_bsm_frag_send: "bounds check parsed_len+GRP_LEN <= len"
alt "this_pkt_rem < GRP_LEN+RP_LEN"
pim_bsm_frag_send->>pim_bsm_frag_flush: flush current fragment
pim_bsm_frag_flush->>pim_bsm_send_intf: send fragment
pim_bsm_frag_flush-->>pim_bsm_frag_send: reset pkt, this_pkt_rem
end
pim_bsm_frag_send->>pim_bsm_frag_send: memcpy group header into fragment
alt "frag_rp_count == 0"
pim_bsm_frag_send->>pim_bsm_frag_send: "pak_pending=true, continue"
else "frag_rp_count > 0"
pim_bsm_frag_send->>pim_bsm_frag_send: "bounds frag_rp_count*RP_LEN <= remaining"
loop "While this_rp_cnt < total_rp_cnt"
pim_bsm_frag_send->>pim_bsm_frag_send: compute frag_rp_cnt
pim_bsm_frag_send->>pim_bsm_frag_send: "guard frag_rp_cnt != 0"
pim_bsm_frag_send->>pim_bsm_frag_send: "bounds parsed_len+copy <= len"
pim_bsm_frag_send->>pim_bsm_frag_send: memcpy RPs into fragment
alt fragment full or all RPs done
pim_bsm_frag_send->>pim_bsm_frag_flush: flush fragment
pim_bsm_frag_flush->>pim_bsm_send_intf: send fragment
end
end
end
end
alt pak_pending
pim_bsm_frag_send->>pim_bsm_send_intf: send final fragment
end
pim_bsm_frag_send->>pim_bsm_frag_send: XFREE(pak_start)
pim_bsm_frag_send-->>Caller: true
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
pimd/pim_bsm.c:1001-1006
The "Unreachable" comment is incomplete. It explains only the outer-loop pre-flush path but ignores the continuation path: after `pim_bsm_frag_flush` inside the inner loop, the group header is re-written at lines 1067β1071 and `this_pkt_rem` is decremented by `PIM_BSM_GRP_LEN`. The zero-entry guard only stays unreachable because the MTU check at line 1056 exits early when `this_pkt_rem < GRP_LEN + RP_LEN` after the inner flush. Without documenting this second invariant, a future refactor that relaxes or removes the line-1056 check could silently reach this guard β which then `return false`s rather than truly being unreachable.
```suggestion
/* Unreachable under correct invariants:
* (a) outer-loop pre-flush (line ~951) guarantees
* this_pkt_rem >= GRP_LEN + RP_LEN before the
* first group header write, so rp_fit_cnt >= 1;
* (b) after an inner-loop flush + continuation group
* header copy (lines ~1067-1071), the MTU check
* at line ~1056 has already enforced
* this_pkt_rem >= GRP_LEN + RP_LEN, so
* rp_fit_cnt >= 1 there too.
* Guard anyway so a future refactor that drops either
* check cannot silently spin forever.
*/
```
Reviews (8): Last reviewed commit: "pimd: fix heap OOB write in BSM fragment..." | Re-trigger Greptile |
|
@greptile review |
|
@greptile review |
|
@greptile review |
|
@greptile review |
|
@greptile review |
|
@greptile review |
Prevent pre-auth heap overflow when forwarding oversized BSMs with zero-RP group records by bounding fragment output and source RP copies, and reject rp_count/frag_rp_count mismatches at parse time. Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
|
@greptile review |
|
@Mergifyio backport stable/10.6 stable/10.5 |
β Backports have been createdDetails
|
pimd: fix heap OOB write in BSM fragmenter (backport #22222)
pimd: fix heap OOB write in BSM fragmenter (backport #22222)
Prevent pre-auth heap overflow when forwarding oversized BSMs with zero-RP group records by bounding fragment output and source RP copies, and reject rp_count/frag_rp_count mismatches at parse time.