Skip to content

pimd: Auto-RP hardening for discovery and announcements - #21745

Merged
donaldsharp merged 3 commits into
FRRouting:masterfrom
Jafaral:autorp-grp-bound
May 12, 2026
Merged

pimd: Auto-RP hardening for discovery and announcements#21745
donaldsharp merged 3 commits into
FRRouting:masterfrom
Jafaral:autorp-grp-bound

Conversation

@Jafaral

@Jafaral Jafaral commented Apr 22, 2026

Copy link
Copy Markdown
Member
  • Cap learned Auto-RP RPs and groups per RP per message (fixed upper bounds).
  • Validate Auto-RP multicast group prefixes; drop bad data and avoid leaking half-built prefix-lists on parse failure.
  • When candidate RPs are configured, accept announcements only from the RP address or a matching configured candidate; otherwise drop.
  • Delete superseded AUTORP*_ prefix-lists when an RP refresh uses a new group-list name.

@Jafaral
Jafaral requested a review from nabahr April 22, 2026 18:48
@frrbot frrbot Bot added the pim label Apr 22, 2026
@greptile-apps

greptile-apps Bot commented Apr 22, 2026

Copy link
Copy Markdown

Greptile Summary

This PR hardens the Auto-RP announcement and discovery paths against malformed or malicious traffic by adding a two-pass prescan for announcements, enforcing per-RP group-count and prefix-validity bounds, adding source-authorization gating, and cleaning up orphaned __AUTORP_*__ prefix-lists when a discovery RP's group-list name changes.

  • Announcement path: A new autorp_announcement_prescan_ok function validates source authorization, group-count caps, multicast-prefix validity, and capacity before any state mutations; per-RP state is built into a staging list (new_grps) and committed atomically, so parse failures never leave a partial mapping entry or an armed hold-timer.
  • Discovery path: Adds PIM_AUTORP_MAX_GROUPS_PER_RP and pim_autorp_group_prefix_valid checks that use continue/success=false rather than return false, preserving already-installed RPs; orphaned prefix-lists from superseded group-list names are now deleted inside pim_autorp_add_rp.
  • Capacity check ordering: The PIM_AUTORP_MAX_LEARNED_RPS guard in pim_autorp_add_rp is now placed before pim_rp_new, preventing a zombie RP from being registered in PIM's routing table when the discovery-list slot cap is reached.

Confidence Score: 4/5

The announcement hardening is structurally sound; the discovery-path changes are more manually managed and carry residual risk around prefix-list ownership across the caller/callee boundary.

The prescan-then-apply architecture for announcements cleanly solves the partial-state problem and source-auth bypass. The capacity check in pim_autorp_add_rp is now correctly placed before pim_rp_new. The discovery path grp_parse_ok flag and caller-side prefix_list_delete on failure properly close the orphaned-prefix-list gaps. The interaction between the caller-managed prefix-list lifecycle and the superseded-list deletion inside pim_autorp_add_rp is correct but non-obvious; a regression there would silently install an RP against a stale or double-freed prefix-list object.

pimd/pim_autorp.c β€” specifically the multi-group discovery path's prefix-list ownership handoff between autorp_recv_discovery and pim_autorp_add_rp, and the superseded-list deletion logic for RP group-list name transitions.

Important Files Changed

Filename Overview
pimd/pim_autorp.c Core announcement/discovery hardening: new prescan, per-RP abort helper, source-auth gating, capacity checks, and old-prefix-list cleanup; intricate parallel-pass logic between prescan and apply loop is correct but warrants careful testing
pimd/pim_autorp.h Adds PIM_AUTORP_MAX_LEARNED_RPS (1024) and PIM_AUTORP_MAX_GROUPS_PER_RP (128) constants with explanatory comment; no issues found

Sequence Diagram

sequenceDiagram
    participant Net as Network
    participant Recv as autorp_recv_msg
    participant Pre as autorp_announcement_prescan_ok
    participant Apply as autorp_announcement_apply_mapping_rp
    participant List as mapping_rp_list

    Net->>Recv: PIMv2 Auto-RP Announcement packet
    Recv->>Pre: rpcnt, buf, src
    loop For each RP in packet (prescan)
        Pre->>Pre: Skip PIMv1/unknown RPs (advance offset)
        Pre->>Pre: pim_autorp_allowed_announce_src(src, rp_addr)
        alt Source unauthorized
            Pre-->>Recv: return false (drop entire packet)
        end
        Pre->>Pre: "grpcnt == 0 continue"
        Pre->>Pre: "grpcnt > MAX_GROUPS_PER_RP return false"
        Pre->>Pre: Validate each group prefix
        Pre->>Pre: Check capacity (pending_new tracking)
    end
    Pre-->>Recv: return true
    loop For each RP in packet (apply)
        Recv->>Recv: Skip PIMv1/unknown RPs
        alt "grpcnt == 0"
            Recv->>List: Find existing RP
            List-->>Recv: ma_rp (if exists)
            Recv->>Recv: autorp_mapping_rp_restart_holdtimer
        else "grpcnt > 0"
            Recv->>Apply: holdtime, rp, rp_addr, buf, offset
            Apply->>List: autorp_mapping_rp_get_or_create(rp_addr)
            Apply->>Apply: Build groups into new_grps (staging list)
            alt Parse error or invalid prefix
                Apply->>List: Remove RP if newly created (abort)
                Apply-->>Recv: return false
            end
            Apply->>List: Swap new_grps into ma_rp.grp_pfix_list
            Apply->>List: autorp_mapping_rp_restart_holdtimer
            Apply-->>Recv: return true
        end
    end
Loading

Reviews (13): Last reviewed commit: "pimd: tighten Auto-RP announcement accep..." | Re-trigger Greptile

Comment thread pimd/pim_autorp.c Outdated
Comment thread pimd/pim_autorp.c Outdated
@Jafaral

Jafaral commented Apr 22, 2026

Copy link
Copy Markdown
Member Author

@greptile review

Comment thread pimd/pim_autorp.c Outdated
@Jafaral

Jafaral commented Apr 22, 2026

Copy link
Copy Markdown
Member Author

@greptile review

@Jafaral

Jafaral commented Apr 23, 2026

Copy link
Copy Markdown
Member Author

@greptile review

@Jafaral

Jafaral commented Apr 23, 2026

Copy link
Copy Markdown
Member Author

@greptile review

@Jafaral

Jafaral commented Apr 23, 2026

Copy link
Copy Markdown
Member Author

@Mergifyio backport stable/10.6 stable/10.5 stable/10.4

@mergify

mergify Bot commented Apr 23, 2026

Copy link
Copy Markdown

backport stable/10.6 stable/10.6 stable/10.4

βœ… Backports have been created

Details

Comment thread pimd/pim_autorp.c Outdated
ma_rp = trp;
/* Free the existing group prefix list, in case the advertised groups changed */
pim_autorp_grppfix_free(&ma_rp->grp_pfix_list);
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this open bracket? Seems odd and gives us more lines of code changes

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread pimd/pim_autorp.c

static bool pim_autorp_group_prefix_valid(const struct prefix *grp)
{
return grp->family == AF_INET && grp->prefixlen <= IPV4_MAX_BITLEN &&

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pim_autorp.c is only compiled for v4. Why do we need this test to check it's v4 ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to guards against a corrupted struct prefix built from packets received on the wire.

Comment thread pimd/pim_autorp.c Outdated
* announced from an unauthorized source β€” avoids applying a prefix of RPs
* before failing mid-packet.
*/
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need an open paranthesis here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread pimd/pim_autorp.c Outdated
* announced from an unauthorized source β€” avoids applying a prefix of RPs
* before failing mid-packet.
*/
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see this moved to a new announcement validation function

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Comment thread pimd/pim_autorp.c Outdated
/* Free the existing group prefix list, in case the advertised groups changed */
pim_autorp_grppfix_free(&ma_rp->grp_pfix_list);
}
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be made a bit cleaner as well if the storing of the announced RP is split out into it's own function as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@Jafaral
Jafaral force-pushed the autorp-grp-bound branch from 7f68649 to f3ae01c Compare May 4, 2026 18:31
@Jafaral

Jafaral commented May 4, 2026

Copy link
Copy Markdown
Member Author

@greptile review

1 similar comment
@Jafaral

Jafaral commented May 4, 2026

Copy link
Copy Markdown
Member Author

@greptile review

@Jafaral
Jafaral force-pushed the autorp-grp-bound branch from f3ae01c to c2e8a14 Compare May 4, 2026 19:03
@Jafaral

Jafaral commented May 9, 2026

Copy link
Copy Markdown
Member Author

@greptile review

Define fixed upper bounds for mapping-agent learned RPs and for how many group
ranges can be advertised per RP in one message.

Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
@Jafaral
Jafaral force-pushed the autorp-grp-bound branch from c2e8a14 to aed2532 Compare May 12, 2026 02:48
@Jafaral

Jafaral commented May 12, 2026

Copy link
Copy Markdown
Member Author

@greptile review

@Jafaral
Jafaral force-pushed the autorp-grp-bound branch from aed2532 to 4c2204e Compare May 12, 2026 03:32
@Jafaral

Jafaral commented May 12, 2026

Copy link
Copy Markdown
Member Author

@greptile review

Comment thread pimd/pim_autorp.c
@Jafaral
Jafaral force-pushed the autorp-grp-bound branch from 4c2204e to eddb4d0 Compare May 12, 2026 03:56
@Jafaral

Jafaral commented May 12, 2026

Copy link
Copy Markdown
Member Author

@greptile review

Comment thread pimd/pim_autorp.c
@Jafaral
Jafaral force-pushed the autorp-grp-bound branch from eddb4d0 to 3182874 Compare May 12, 2026 04:05
Reject bogus mask/address combinations early and discard prefix-list builds
when validation fails mid-parse so temporary lists are not leaked.

Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
@Jafaral
Jafaral force-pushed the autorp-grp-bound branch from 3182874 to e293e0f Compare May 12, 2026 04:07
@Jafaral

Jafaral commented May 12, 2026

Copy link
Copy Markdown
Member Author

@greptile review

Comment thread pimd/pim_autorp.c
@Jafaral
Jafaral force-pushed the autorp-grp-bound branch from e293e0f to 87c7d80 Compare May 12, 2026 04:48
@github-actions github-actions Bot added size/XL and removed size/L labels May 12, 2026
When local candidate-RP configuration exists, require announcements to come
from the RP address or a configured candidate address; otherwise drop.

Drop superseded Auto-RP-generated prefix lists when discovery refreshes an RP
with a new group-list name.

Apply source authentication in the announcement prescan before skipping RPs with
grpcnt zero. Parse advertised groups into a temporary sorted list and only
replace the mapping RP prefix list after a full successful parse; discard a
newly inserted mapping RP entry if parsing fails.

Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
@Jafaral
Jafaral force-pushed the autorp-grp-bound branch from 87c7d80 to cd510f3 Compare May 12, 2026 04:49
@Jafaral

Jafaral commented May 12, 2026

Copy link
Copy Markdown
Member Author

@greptile review

@donaldsharp
donaldsharp merged commit d3d1fd9 into FRRouting:master May 12, 2026
35 of 36 checks passed
@Jafaral
Jafaral deleted the autorp-grp-bound branch May 29, 2026 16:29
Jafaral added a commit that referenced this pull request Jun 3, 2026
pimd: Auto-RP hardening for discovery and announcements (backport #21745)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants