git: ca687fba31c6 - stable/14 - pf: improve anchor string validation
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 27 Nov 2026 12:23:29 UTC
The branch stable/14 has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=ca687fba31c67e97d9c745358af6d774c150d477
commit ca687fba31c67e97d9c745358af6d774c150d477
Author: Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2026-11-10 14:54:37 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2026-11-27 10:42:53 +0000
pf: improve anchor string validation
Ensure that these are not overly long.
Add a test case.
Reported by: Kevin Day <kevin@your.org>
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
(cherry picked from commit a396a0218cc59cff48547fdf97d9e1a8c306f090)
---
sys/netpfil/pf/pf_table.c | 5 +++--
tests/sys/netpfil/pf/ioctl/validation.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/sys/netpfil/pf/pf_table.c b/sys/netpfil/pf/pf_table.c
index 6a1a3cc48306..c21328438f49 100644
--- a/sys/netpfil/pf/pf_table.c
+++ b/sys/netpfil/pf/pf_table.c
@@ -1755,6 +1755,9 @@ pfr_fix_anchor(char *anchor)
size_t siz = MAXPATHLEN;
int i;
+ if (strnlen(anchor, MAXPATHLEN) >= MAXPATHLEN)
+ return (-1);
+
if (anchor[0] == '/') {
char *path;
int off;
@@ -1766,8 +1769,6 @@ pfr_fix_anchor(char *anchor)
bcopy(path, anchor, siz - off);
memset(anchor + siz - off, 0, off);
}
- if (anchor[siz - 1])
- return (-1);
for (i = strlen(anchor); i < siz; i++)
if (anchor[i])
return (-1);
diff --git a/tests/sys/netpfil/pf/ioctl/validation.c b/tests/sys/netpfil/pf/ioctl/validation.c
index 651e6837acd7..e3a3724f8f6f 100644
--- a/tests/sys/netpfil/pf/ioctl/validation.c
+++ b/tests/sys/netpfil/pf/ioctl/validation.c
@@ -951,6 +951,38 @@ ATF_TC_CLEANUP(addstate, tc)
COMMON_CLEANUP();
}
+ATF_TC_WITH_CLEANUP(anchor);
+ATF_TC_HEAD(anchor, tc)
+{
+ atf_tc_set_md_var(tc, "require.user", "root");
+ atf_tc_set_md_var(tc, "require.kmods", "pf");
+}
+
+ATF_TC_BODY(anchor, tc)
+{
+ struct pfioc_table io;
+ struct pfr_table tbl;
+
+ COMMON_HEAD();
+
+ memset(&tbl, 0, sizeof(tbl));
+ memset(&io, '/', sizeof(io)); /* anchor + name all slashes */
+ io.pfrio_esize = sizeof(struct pfr_table);
+ io.pfrio_size = 1000;
+ io.pfrio_flags = PFR_FLAG_ALLRSETS;
+ io.pfrio_buffer = &tbl;
+
+ ATF_CHECK_ERRNO(EINVAL, ioctl(dev, DIOCRGETTABLES, &io) == -1);
+
+ io.pfrio_table.pfrt_anchor[MAXPATHLEN - 1] = 0;
+ ATF_CHECK(ioctl(dev, DIOCRGETTABLES, &io) == 0);
+}
+
+ATF_TC_CLEANUP(anchor, tc)
+{
+ COMMON_CLEANUP();
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, addtables);
@@ -977,6 +1009,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, rpool_mtx);
ATF_TP_ADD_TC(tp, rpool_mtx2);
ATF_TP_ADD_TC(tp, addstate);
+ ATF_TP_ADD_TC(tp, anchor);
return (atf_no_error());
}