bgpd: Avoid having a dangling pointer after we free NHC attribute - #21605
Conversation
Greptile SummaryThis PR fixes dangling pointer bugs in Confidence Score: 5/5Safe to merge; the dangling-pointer fixes are correct and complete, and the one behavioral change (link-local without BGPID TLV) is defensible per the draft's MUST language. All remaining findings are P2 (log-level inconsistency). The core fix β adding No files require special attention beyond the Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["bgp_attr_nhc() entry\nnhc = bgp_attr_get_nhc(attr)"] --> B{discard/withdraw?}
B -- yes --> Z[nhc_ignore: skip bytes]
B -- no --> C{length < MIN_LEN?}
C -- yes --> E1["bgp_nhc_free(nhc)\nbgp_attr_set_nhc(attr, NULL)\nreturn malformed β
fixed"]
C -- no --> D{afi/safi valid?}
D -- no --> E2["bgp_nhc_free(nhc)\nbgp_attr_set_nhc(attr, NULL)\nreturn PARSE_ERROR β
fixed"]
D -- yes --> F{nh_length valid?}
F -- no --> E3["bgp_nhc_free(nhc)\nbgp_attr_set_nhc(attr, NULL)\nreturn malformed β
fixed"]
F -- yes --> G["if(!nhc) XCALLOC new nhc\nfill afi/safi/nh_length"]
G --> H{nh_length == IPv4?}
H -- no-else --> E4["bgp_nhc_free(nhc)\nbgp_attr_set_nhc(attr, NULL)\nreturn PARSE_ERROR_NOTIFYPLS β
fixed"]
H -- yes/IPv6 --> I[Parse TLV loop]
I --> J{TLV length OOB?}
J -- yes --> E5["bgp_nhc_free(nhc)\nbgp_attr_set_nhc(attr, NULL)\nreturn malformed β
fixed"]
J -- no --> K{NNHN TLV invalid?}
K -- yes --> E6["bgp_nhc_tlv_free + bgp_nhc_free\nbgp_attr_set_nhc(attr, NULL)\nreturn malformed β
fixed"]
K -- no --> I
I --> L{link-local && no BGPID TLV?}
L -- yes --> E7["bgp_nhc_free(nhc)\nbgp_attr_set_nhc(attr, NULL)\nreturn malformed\nβ οΈ behavior change: was PROCEED"]
L -- no --> M["bgp_attr_set_nhc(attr, bgp_nhc_intern(nhc))\nreturn PROCEED"]
Prompt To Fix All With AIThis is a comment left during a code review.
Path: bgpd/bgp_attr.c
Line: 4025-4028
Comment:
**Log level inconsistency after severity upgrade**
The link-local/missing-BGPID-TLV path was upgraded from `BGP_ATTR_PARSE_PROCEED` (non-fatal) to `bgp_attr_malformed()` (triggers a NOTIFICATION to the peer), but the log statement was left as `zlog_warn`. Every other hard error in this function uses `zlog_err`. Keeping `zlog_warn` here means operators won't see a consistent severity signal when a session is about to be torn down.
```suggestion
zlog_err("%pBP sent link-local next-hop in NHC without required BGPID TLV", peer);
bgp_nhc_free(nhc);
bgp_attr_set_nhc(attr, NULL);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, args->total);
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (2): Last reviewed commit: "bgpd: Avoid having a dangling pointer af..." | Re-trigger Greptile |
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
f918e5b to
c5b215e
Compare
|
@greptileai review |
|
@Mergifyio backport stable/10.6 stable/10.5 stable/10.4 |
β Backports have been createdDetails
Cherry-pick of c5b215e has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
Cherry-pick of c5b215e has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
Cherry-pick of c5b215e has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
No description provided.