Page MenuHomeFreeBSD

pf: grab pf_config_lock when freeing a rule
AbandonedPublic

Authored by rew on Apr 11 2022, 7:20 AM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 18 2024, 8:53 AM
Unknown Object (File)
Jan 2 2024, 12:07 PM
Unknown Object (File)
Dec 31 2023, 8:37 PM
Unknown Object (File)
Nov 24 2023, 8:31 AM
Unknown Object (File)
Nov 22 2023, 5:04 PM
Unknown Object (File)
Nov 15 2023, 12:17 PM
Unknown Object (File)
Nov 13 2023, 5:42 AM
Unknown Object (File)
Nov 11 2023, 6:39 AM

Details

Reviewers
kp
mjg
Summary

Take PF_CONFIG_LOCK() when pf_free_rule() is called. The assert being
hit was added in bd7762c86986537a5b393537b85de31b1556735b.

When adding a new rule through DIOCCHANGERULE it's possible the new rule
will be freed. This can happen if an error occurs or when the new rule
is to be added before/after a given rule number that doesn't exist.

It is the latter scenario that syzkaller found.

Reported by: syzbot+ba6bcae2eabec42983f6@syzkaller.appspotmail.com

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 45120
Build 42008: arc lint + arc unit

Event Timeline

rew requested review of this revision.Apr 11 2022, 7:20 AM

I'm aware of this crash, but this is more broken than that and sprinkling the lock only takes care of the apparent problem. The key here is that the ioctl at hand does not properly update the rule anymore and unfortunately there are no tests for it either. I'm going to fix it soon(tm).

In D34880#790375, @mjg wrote:

I'm aware of this crash, but this is more broken than that and sprinkling the lock only takes care of the apparent problem. The key here is that the ioctl at hand does not properly update the rule anymore and unfortunately there are no tests for it either. I'm going to fix it soon(tm).

I'm very, very tempted to say we should just remove DIOCCHANGERULE, but at least miniupnpd actually uses it.

In D34880#790376, @kp wrote:

I'm very, very tempted to say we should just remove DIOCCHANGERULE, but at least miniupnpd actually uses it.

Looks like it uses PF_CHANGE_REMOVE, PF_CHANGE_GET_TICKET, and PF_CHANGE_ADD_TAIL from the ioctl.

The locking contract did seem a bit odd when I was looking at this, guess because there's active work going on here.

I'll let this go, thanks for the comments.

thanks for the patch. if there was a way of marking syzkaller crashes as worked on I would have done it :)