Page MenuHomeFreeBSD

pf: Avoid logging state creation failures unless requested
Needs ReviewPublic

Authored by markj on Fri, Mar 14, 2:39 AM.
Tags
None
Referenced Files
F112521079: D49352.diff
Wed, Mar 19, 6:43 AM
Unknown Object (File)
Mon, Mar 17, 8:52 PM
Unknown Object (File)
Sat, Mar 15, 8:44 AM
Unknown Object (File)
Fri, Mar 14, 1:48 PM
Unknown Object (File)
Fri, Mar 14, 1:03 PM

Details

Reviewers
kp
Summary

pd.act.log is applied unconditionally, but the intent in commit
886396f1b1a7 was to log only if the rule specifically requested it.
Thus, check the rule and associated NAT rule before setting
PF_LOG_FORCE.

Extend the regression test added in commit 886396f1b1a7 to check that we
don't log anything if a state creation failure occurs for a rule without
logging configured.

Fixes: 886396f1b1a7 ("pf: Force logging if pf_create_state() fails")

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 62913
Build 59797: arc lint + arc unit

Event Timeline

markj requested review of this revision.Fri, Mar 14, 2:39 AM

This seems inconsistent with what we do in other situations, e.g. if pf_setup_pdesc() or vlan_set_pcp() fail.
In those cases (and a few others) we consider a failure to be sufficient reason to log, even if logging wasn't explicitly requested.

In D49352#1125486, @kp wrote:

This seems inconsistent with what we do in other situations, e.g. if pf_setup_pdesc() or vlan_set_pcp() fail.
In those cases (and a few others) we consider a failure to be sufficient reason to log, even if logging wasn't explicitly requested.

This case is a bit different though, as pf_create_state() can fail for administrative reasons, e.g., if the rule has an associated limit. pf_setup_pdesc() and vlan_set_pcp() fail due to kernel memory allocation failures and malformed packets, which are always abnormal conditions where unconditional logging makes more sense.

What do you think of having pf_create_state() pass reason back up to the caller and using its value to decide whether to log? That is, if the value is PFRES_SRCLIMIT or MAXSTATES (and perhaps STATEINS), log only if the rule says so, otherwise log unconditionally.

This case is a bit different though, as pf_create_state() can fail for administrative reasons, e.g., if the rule has an associated limit. pf_setup_pdesc() and vlan_set_pcp() fail due to kernel memory allocation failures and malformed packets, which are always abnormal conditions where unconditional logging makes more sense.

We can fail pf_setup_pdesc() for a number of reasons. Some of them are indeed allocation problems, but others are also 'this packet is invalid', e.g. when it's a fragmented jumbo packet, or has multiple fragmentation headers, a route header type 0, invalid UDP port number, or a number of SCTP protocol violations.

What do you think of having pf_create_state() pass reason back up to the caller and using its value to decide whether to log? That is, if the value is PFRES_SRCLIMIT or MAXSTATES (and perhaps STATEINS), log only if the rule says so, otherwise log unconditionally.

That's make the error handling significantly more complex, in code that's already significantly complex.

It's not quite clear to me what problem we're trying to solve here.