The branch main has been updated by kp:

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

commit 7250fc4eb5d0effdc285a2e7bc5c6b17d2fb1b9f
Author:     Kristof Provost <k...@freebsd.org>
AuthorDate: 2025-07-08 15:04:12 +0000
Commit:     Kristof Provost <k...@freebsd.org>
CommitDate: 2025-07-15 07:55:30 +0000

    pflog: improve uid logging
    
    Sometimes a user ID was logged in pflog(4) although the logopt of
    the rule did not specify it.  Check the option again for the log
    rule in case another rule has triggered a socket lookup.  Remove
    logopt group, it is not documented and cannot work as struct pfloghdr
    does not contain a gid.  Rename PF_LOG_SOCKET_LOOKUP to PF_LOG_USER
    to express what it does.  The lookup involved is only an implemntation
    detail.
    OK kn@ sashan@ mvs@
    
    Obtained from:  OpenBSD, bluhm <bl...@openbsd.org>, f6d3bf21b2
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 sbin/pfctl/parse.y        | 3 +--
 sbin/pfctl/pfctl_parser.c | 2 +-
 sys/netpfil/pf/if_pflog.c | 4 ++--
 sys/netpfil/pf/pf.h       | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y
index a8a165d336fa..358fa909fc50 100644
--- a/sbin/pfctl/parse.y
+++ b/sbin/pfctl/parse.y
@@ -3232,8 +3232,7 @@ logopts           : logopt                        { $$ = 
$1; }
 
 logopt         : ALL           { $$.log = PF_LOG_ALL; $$.logif = 0; }
                | MATCHES               { $$.log = PF_LOG_MATCHES; $$.logif = 
0; }
-               | USER          { $$.log = PF_LOG_SOCKET_LOOKUP; $$.logif = 0; }
-               | GROUP         { $$.log = PF_LOG_SOCKET_LOOKUP; $$.logif = 0; }
+               | USER          { $$.log = PF_LOG_USER; $$.logif = 0; }
                | TO string     {
                        const char      *errstr;
                        u_int            i;
diff --git a/sbin/pfctl/pfctl_parser.c b/sbin/pfctl/pfctl_parser.c
index cc2b03ec211f..f2eb75135609 100644
--- a/sbin/pfctl/pfctl_parser.c
+++ b/sbin/pfctl/pfctl_parser.c
@@ -928,7 +928,7 @@ print_rule(struct pfctl_rule *r, const char *anchor_call, 
int verbose, int numer
                                printf("%sall", count++ ? ", " : "");
                        if (r->log & PF_LOG_MATCHES)
                                printf("%smatches", count++ ? ", " : "");
-                       if (r->log & PF_LOG_SOCKET_LOOKUP)
+                       if (r->log & PF_LOG_USER)
                                printf("%suser", count++ ? ", " : "");
                        if (r->logif)
                                printf("%sto pflog%u", count++ ? ", " : "",
diff --git a/sys/netpfil/pf/if_pflog.c b/sys/netpfil/pf/if_pflog.c
index 0a84f9d680ac..cb96d2fcc44c 100644
--- a/sys/netpfil/pf/if_pflog.c
+++ b/sys/netpfil/pf/if_pflog.c
@@ -284,9 +284,9 @@ pflog_packet(uint8_t action, u_int8_t reason,
         * state lock, since this leads to unsafe LOR.
         * These conditions are very very rare, however.
         */
-       if (trigger->log & PF_LOG_SOCKET_LOOKUP && !pd->lookup.done && 
lookupsafe)
+       if (trigger->log & PF_LOG_USER && !pd->lookup.done && lookupsafe)
                pd->lookup.done = pf_socket_lookup(pd);
-       if (pd->lookup.done > 0)
+       if (trigger->log & PF_LOG_USER && pd->lookup.done > 0)
                hdr.uid = pd->lookup.uid;
        else
                hdr.uid = -1;
diff --git a/sys/netpfil/pf/pf.h b/sys/netpfil/pf/pf.h
index db353d185368..cfff58064922 100644
--- a/sys/netpfil/pf/pf.h
+++ b/sys/netpfil/pf/pf.h
@@ -140,7 +140,7 @@ enum        { PF_ADDR_ADDRMASK, PF_ADDR_NOROUTE, 
PF_ADDR_DYNIFTL,
 
 #define        PF_LOG                  0x01
 #define        PF_LOG_ALL              0x02
-#define        PF_LOG_SOCKET_LOOKUP    0x04
+#define        PF_LOG_USER             0x04
 #define        PF_LOG_FORCE            0x08
 #define        PF_LOG_MATCHES          0x10
 

Reply via email to