Bug 257218 - pfi_ifnet leak on interface removal
Summary: pfi_ifnet leak on interface removal
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-pf (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-16 15:35 UTC by Nick Reilly
Modified: 2022-12-28 09:08 UTC (History)
2 users (show)

See Also:


Attachments
Suggested diff (1.12 KB, patch)
2021-07-16 15:35 UTC, Nick Reilly
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Reilly 2021-07-16 15:35:18 UTC
Created attachment 226498 [details]
Suggested diff

The detach of the interface and group were leaving pfi_ifnet memory behind. Doing an unref on the kif frees it up if this is the last reference.

On interface detach, the group deletion was notified first and then a change notification was sent. This would recreate the group in the kif layer. Reorder the change to before the delete.
Comment 1 Kristof Provost freebsd_committer freebsd_triage 2022-11-30 16:18:34 UTC
Thanks!

I've posted the patch with a small variation here: https://reviews.freebsd.org/D37569 and a test case here: https://reviews.freebsd.org/D37570
Comment 2 commit-hook freebsd_committer freebsd_triage 2022-12-14 09:21:01 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=bfeef0d32a0036bf6bec93a439e0466efe6f4482

commit bfeef0d32a0036bf6bec93a439e0466efe6f4482
Author:     Nick Reilly <nreilly@blackberry.com>
AuthorDate: 2022-11-30 14:19:44 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-12-14 09:19:01 +0000

    pf: fix pfi_ifnet leak on interface removal

    The detach of the interface and group were leaving pfi_ifnet memory
    behind. Check if the kif still has references, and clean it up if it
    doesn't

    On interface detach, the group deletion was notified first and then a
    change notification was sent. This would recreate the group in the kif
    layer. Reorder the change to before the delete.

    PR:             257218
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D37569

 sys/net/if.c           |  3 +--
 sys/netpfil/pf/pf_if.c | 23 ++++++++++++++++++-----
 2 files changed, 19 insertions(+), 7 deletions(-)
Comment 3 commit-hook freebsd_committer freebsd_triage 2022-12-28 09:04:08 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=5f7454d8904ca68697dda569f71af6ef5ec178c7

commit 5f7454d8904ca68697dda569f71af6ef5ec178c7
Author:     Nick Reilly <nreilly@blackberry.com>
AuthorDate: 2022-11-30 14:19:44 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-12-28 04:56:08 +0000

    pf: fix pfi_ifnet leak on interface removal

    The detach of the interface and group were leaving pfi_ifnet memory
    behind. Check if the kif still has references, and clean it up if it
    doesn't

    On interface detach, the group deletion was notified first and then a
    change notification was sent. This would recreate the group in the kif
    layer. Reorder the change to before the delete.

    PR:             257218
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D37569

    (cherry picked from commit bfeef0d32a0036bf6bec93a439e0466efe6f4482)

 sys/net/if.c           |  3 +--
 sys/netpfil/pf/pf_if.c | 23 ++++++++++++++++++-----
 2 files changed, 19 insertions(+), 7 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2022-12-28 09:08:09 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=909167374fefcfa4981e4a43ee48872dcf76d0e2

commit 909167374fefcfa4981e4a43ee48872dcf76d0e2
Author:     Nick Reilly <nreilly@blackberry.com>
AuthorDate: 2022-11-30 14:19:44 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-12-28 04:56:08 +0000

    pf: fix pfi_ifnet leak on interface removal

    The detach of the interface and group were leaving pfi_ifnet memory
    behind. Check if the kif still has references, and clean it up if it
    doesn't

    On interface detach, the group deletion was notified first and then a
    change notification was sent. This would recreate the group in the kif
    layer. Reorder the change to before the delete.

    PR:             257218
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D37569

    (cherry picked from commit bfeef0d32a0036bf6bec93a439e0466efe6f4482)

 sys/net/if.c           |  3 +--
 sys/netpfil/pf/pf_if.c | 23 ++++++++++++++++++-----
 2 files changed, 19 insertions(+), 7 deletions(-)