153 Commits
Author SHA1 Message Date
Yusuke Ichiki 1403ca1018 man: Fix RFC 1918 network prefix lengths
According to RFC 1918, the following IP prefixes are reserved for
private internets:

    10.0.0.0/8
    172.16.0.0/12
    192.168.0.0/16

This PR fixes the prefix lengths in references to private networks
("RFC 1918 networks", "the standard private IP address ranges").
The changes are limited to man pages.

Signed-off-by:	Yusuke Ichiki <[email protected]>
Pull Request:	https://github.com/freebsd/freebsd-src/pull/2328
MFC after:	3 days
2026-07-17 09:51:11 -07:00
Gordon Bergling 0223ae33ad ipfilter(4): Fix a couple of typos in the manual pages
- s/heirarchical/hierarchical/
- s/itnerface/interface/
- s/conjuction/conjunction/

MFC after:	3 days
2026-06-27 12:51:19 +02:00
Cy Schubert f5d0b30e4a ippool(5): Correct example in man page
The example provided puts the semicolon in the wrong place. It must
come after the file:// specification, not in it.

MFC after:	1 week
2026-04-16 21:09:42 -07:00
Brooks Davis a79e2278c5 ipf: copy{in,out}ptr -> ipf_copy{in,out}_indirect
These functions take the source or destintation address indirectly from
a potentially missaligned buffer.  Rename them to refect this and to
free up the copy{in,out}ptr names.

Some of the code in question is dead code and doesn't or won't compile,
but I've changed it all for consistency.

NB: If the pointers are actually stored under aligned then this code is
broken with CHERI.

Reviewed by:	cy
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D54232
2025-12-19 15:59:08 +00:00
Dag-Erling Smørgrav a34c50fbd2 ipfilter: Prevent stack buffer overflow
When copying ipfs data from user space, don't just check that the payload
length is nonzero, but also that it does not exceed the size of the stack
buffer we're copying it into.

While we're at it, use a union to create a buffer of the exact size we
need instead of guessing that 2048 will be enough (and not too much).

Finally, check the size of the payload once it gets to where it's used.

MFC after:	3 days
Reported by:	Ilja Van Sprundel <[email protected]>
Reviewed by:	cy
Differential Revision:	https://reviews.freebsd.org/D54194
2025-12-16 17:12:36 +01:00
Cy Schubert 0ff0c19e7f ipfilter: Disable ipfs(8) by default
At the moment ipfs(8) is a tool that can be easily abused. Though the
concept is sound the implementation needs some work.

ipfs(8) should be considered experimental at the moment.

This commit also makes ipfs support in the kernel optional.

Reviewed by:		emaste, glebius
MFC after:		1 week
Differential revision:	https://reviews.freebsd.org/D53787
2025-12-08 08:15:18 -08:00
Cy Schubert d9788eabff ipfilter: Restrict ipfilter within a jail
Add a sysctl/tunable (net.inet.ipf.jail_allowed) to control whether a
jail can manage its own ipfilter rules, pools, and settings. A jail's
control over its own ipfilter rules and settings may not be desireable.
The default is jail access to ipfilter is denied.

The host system can stil manage a jail's rules by attaching the rules,
using the on keyword, limiting the rule to the jail's interface. Or
the sysctl/tunable can be enabled to allow a jail control over its own
ipfilter rules and settings.

Implementation note: Rather than store the jail_allowed variable,
referenced by sysctl(9), in a global area, storing the variable in the
ipfilter softc is consistent with ipfilter's use of its softc.

Discussed with:		emaste, jrm
MFC after:		1 week
Differential revision:	https://reviews.freebsd.org/D53623
2025-12-08 08:15:18 -08:00
Cy Schubert 821774dfbd ipfilter: Verify ipnat on entry into kernel
The ipnat struct is built by ipnat(8), specifically ipnat_y.y when
parsing the ipnat configuration file (typically ipnat.conf). ipnat
contains a variable length string field at the end of the struct. This
data field, called in_names, may contain various text strings such as
NIC names. There is no upper bound limit to the length of strings as
long as the in_namelen length field specifies the length of in_names
within the ipnat structure and in_size specifies the size of the ipnat
structure itself.

Reported by:		Ilja Van Sprundel <[email protected]>
Reviewed by:		markj
MFC after:		1 week
Differential revision:	https://reviews.freebsd.org/D53843
2025-11-26 07:16:47 -08:00
Cy Schubert eda1756d04 ipfilter: Verify frentry on entry into kernel
The frentry struct is built by ipf(8), specifically ipf_y.y when parsing
the ipfilter configuration file (typically ipf.conf). frentry contains
a variable length string field at the end of the struct. This data field,
called fr_names, may contain various text strings such as NIC names,
destination list (dstlist) names, and filter rule comments.  The length
field specifies the length of fr_names within the frentry structure and
fr_size specifies the size of the frentry structure itself.

The upper bound limit to the length of strings field is controlled by the
fr_max_namelen sysctl/kenv or the max_namelen ipfilter tuneable.

The initial concepts were discussed with emaste and jrm.

Reported by:		Ilja Van Sprundel <[email protected]>
Reviewed by:		markj
MFC after:		1 week
Differential revision:	https://reviews.freebsd.org/D53843
2025-11-26 07:16:46 -08:00
Cy Schubert df381bec2d ipfilter: Don't trust userland supplied iph_size
ipf_htable_create() trusts a user-supplied iph_size from iphtable_t
and computes the allocation size as iph->iph_size * sizeof(*iph->iph_table)
without checking for integer overflow. A sufficiently large iph_size
causes the multiplication to wrap, resulting in an under-sized allocation
for the table pointer array. Subsequent code (e.g., in ipf_htent_insert())
can then write past the end of the allocated buffer, corrupting kernel
memory and causing DoS or potential privilege escalation.

This is not typically a problem when using the ipfilter provided
userland tools as calculate the correct lengths. This mitigates a
rogue actor calling ipfilter ioctls directly.

Reported by:		Ilja Van Sprundel <[email protected]>
Reviewed by:		markj
MFC after:		1 week
Differential revision:	https://reviews.freebsd.org/D53286
2025-11-05 07:32:17 -08:00
Cy Schubert ab3c985328 ipfilter: Calculate the number of elements in ipf_errors
It serves no purpose to manually manage the IPF_NUM_ERRORS count.
Calculate it instead.

Reviewed by:		emaste, markj
MFC after:		1 week
Differential revision:	https://reviews.freebsd.org/D53308
2025-11-05 07:32:16 -08:00
Cy Schubert 5ae7b106cf ipfs: Fix typo in error message
MFC after:	3 days
2025-10-27 20:43:14 -07:00
Cy Schubert eee36ffa0d ipfilter/ippool: Dump a copy of ippool dstlist data in "new" format
As with 7531c434a5, which dumped ippool table data in the "new"
format, print dstlist data in the "new" format.

MFC after:      1 week
2025-10-02 12:03:35 -07:00
Cy Schubert 2f30b43fa2 ipfilter/ippool: Dump a copy of ippool hash data in "new" format
As with 7531c434a5, which dumped ippool table data in the "new"
format, print hash data in the "new" format.

MFC after:	1 week
2025-10-02 12:03:35 -07:00
Cy Schubert f3ff6abb9d ipfilter ippool: Prefix deleted entries with "#"
To maintain consistency with ippool list functions, prefix deleted
entries with "#".

MFC after:	1 week
2025-10-02 12:03:35 -07:00
Cy Schubert 94758e72fd ipfilter ippool: Flag deleted entries with "#"
List deleted entries prefixed by "#". This is consistent with other
ippool list functions.

Fixes:		7531c434a5
MFC after:	1 week
2025-10-02 12:03:35 -07:00
Cy Schubert ac2e39b5dd ipfilter: End (cleanup) the iterative search key
This results in not finding nodes in subsequent hash table listings.

MFC after:	3 days
2025-07-07 16:37:07 -07:00
Michael Tuexen 6039cd1b45 Don't include netinet/tcp_timer.h when not needed
Reviewed by:		glebius
MFC after:		1 week
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D50889
2025-06-17 06:07:13 +02:00
Cy Schubert 278a726eec ipf: Correct ippool.5 man page
The file URL must be enclosed in quotes.

MFC after:	3 days
2025-03-04 12:39:07 -08:00
Olivier Cochard f16ca171ea man: Remove references to classful networks
Update wording in manual pages to replace references to classful networks with
CIDR notation.

Approved by:	glebius, dhw
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D48853
2025-02-04 22:27:21 +01:00
Richard Scheffenegger 31034044ff tcp: cleanup of nits after use of accessor tcp_get_flags
Remove unneeded th_x2 initalization, use named constants
instead of magic numbers (fixing one oversight) and add
some line breaks. Expand one man page slightly.

No functional change intended.

Reviewed By: tuexen, cc
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D48065
2024-12-19 16:37:24 +01:00
Richard Scheffenegger 347dd0539f tcp: add TH_AE capabilities to ppp and pf
Add support for the AE Flag in the TCP header to pf and ppp.
Commonalize to the use of "E"(ECE), "W"(CWR) and "e"(AE)
for the TCP header flags, in line with tcpdump.

Reviewers: kp, cc, tuexen, cy, #transport!
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D47106
2024-11-29 10:04:31 +01:00
Graham Percival e413da1358 manuals: fix "PP after SS | SH" warnings
The full mandoc warnings were:
    skipping paragraph macro: PP after SS
    skipping paragraph macro: PP after SH

The rendered output (in ascii and html) is not affected by this commit.

Fixes made by script in https://github.com/Tarsnap/freebsd-doc-scripts

Signed-off-by:	Graham Percival <[email protected]>
Reviewed by:	jlduran, mhorne
MFC after:	1 week
Sponsored by:	Tarsnap Backup Inc.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1524
2024-11-14 16:59:43 -04:00
Cy Schubert 9da30a23a5 ipfilter: Include the IP address in error message
Include the IP address in the message when a hashnode add error occurs.
This helps to identify the ippool.conf statement that the error occurred.

MFC after:	1 week
2024-11-11 19:22:15 -08:00
Cy Schubert 3a2cb65b6e ipfilter: Support printing of IPv6 addresses in error message
Replace inet_ntoa(3) with inet_ntop(3). This supporting the printing of
IPv6 IP addresses in addition to IPv4 IP addresses in error message.

MFC after:	1 week
2024-11-11 19:21:22 -08:00
Cy Schubert 858a7a27f5 ipfilter: Close a bracket in the poolnode error message
When a node in a tree is discovered in error, i.e. duplicate, the
IP address of the node is printed but no closing bracket completes
the node in the message. Fix this.

MFC after:	1 week
2024-11-11 19:20:49 -08:00
Cy Schubert 8aae4220d7 ipfilter: Print the hash name when adding a hashnode fails
As with when printing errors for failed poolnodes, printing the hash
node (IP address) only leads to speculation which hash pool the failed
add occurred. This is especially useful when the same IP address is
listed in multiple hash pools.

MFC after:	1 week
2024-11-11 19:18:08 -08:00
Cy Schubert 470c680cfb ipfilter: Print the pool name when adding a poolnode fails
Printing the pool node (IP address) only leads to speculation which
pool the failed add occurred. This is especially useful when the same
IP address is listed in multiple pools.

MFC after:	1 week
2024-11-11 19:15:45 -08:00
Cy Schubert 4293571628 ipfilter: Avoid overrunning the message buffer
Avoid overrunning the message buffer when printing an ippool btree error.
We do this in two ways. First we increase the message buffer from 80 to
255 bytes and secondly we replace strcat(3) with strlcat(3).

MFC after:	1 week
2024-11-11 19:14:31 -08:00
Graham Percival 759ddb4d24 manuals: Misc syntax fixes
These were reported by `mandoc -T lint ...` as errors.

Signed-off-by:	Graham Percival <[email protected]>
Reviewed by:	mhorne, Alexander Ziaee <[email protected]>
Sponsored by:	Tarsnap Backup Inc.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1472
2024-10-28 12:26:03 -03:00
Graham Percival ce251baf42 ipf.5: revert C style(9) applied to man page
These changes were made by accident in:
    ipfilter: Adjust userland returns to conform to style(9)
    2582ae5740

That commit made similar mistakes in other man pages, but those have
already been fixed.

Signed-off-by:	Graham Percival <[email protected]>
Reviewed by:	mhorne
Sponsored by:	Tarsnap Backup Inc.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1433
2024-09-24 14:29:39 -03:00
Ryan Libby 90818083d7 ipf: correct size limit in snprintf
Reported by:	GCC -Wsizeof-pointer-memaccess
Reviewed by:	zlei
Differential Revision:	https://reviews.freebsd.org/D45899
2024-07-20 09:14:57 -07:00
Warner Losh e9ac41698b Remove residual blank line at start of Makefile
This is a residual of the $FreeBSD$ removal.

MFC After: 3 days (though I'll just run the command on the branches)
Sponsored by: Netflix
2024-07-15 16:43:39 -06:00
Elyes Haouas 70fad8acae ipf: Use nitems(foo) instead of sizeof(foo)/sizeof(foo[0])
Pull Request: https://github.com/freebsd/freebsd-src/pull/888
Signed-off-by: Elyes Haouas <[email protected]>
2024-04-28 22:21:09 -06:00
Elyes Haouas f7cee4fa57 sbin: Remove repeated words
Signed-off-by: Elyes Haouas <[email protected]>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/887
2024-04-11 11:53:37 -06:00
Shin-Yi Zheng 94d9c5f3be ipf(8): Fix typo
Event:		Advanced UNIX Programming Course (Fall’23) at NTHU
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1002
2024-02-13 15:14:27 +08:00
Elyes Haouas c1f6704bf8 ipf: Fix some typos
Signed-off-by: Elyes Haouas <[email protected]>
2024-02-02 21:36:27 -07:00
Jens Schweikhardt 359fc7eb32 Typos corrected; dependant, addres. 2024-01-04 19:17:24 +01:00
Elyes Haouas 540be39b0b tree: Use 1 semicolon at the end of a statement
Signed-off-by: Elyes Haouas <[email protected]>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/889
2023-12-27 21:05:47 -07:00
Warner Losh 5b31cc94b1 sccs: Manual changes
For the uncommon items: Go through the tree and remove sccs tags that
didn't fit any nice pattern. If in the neighborhood, other SCM tags were
removed when they were detritis of long-ago CVS somehow in the early
mists of the project. Some adjacent copyrights stringswere removed (they
duplicated the copyright notices in the file). This also removed
non-standard formations of omission of SCCS tags (usually by adding an
extra #if 0 somewhere.

After this commit, a number of strings tagged with the 'what' @(#)
prefix remain, but they are primarily copyright notices.

Sponsored by:		Netflix
2023-11-26 22:23:58 -07:00
Warner Losh 51e16cb8fc sbin: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by:		Netflix
2023-11-26 22:23:29 -07:00
Dag-Erling Smørgrav 4cd9d804ae libipf: fix parser error message.
MFC after:	1 week
Reviewed by:	cy
Differential Revision:	https://reviews.freebsd.org/D41652
2023-08-31 22:15:54 +02:00
Warner Losh b2c76c41be Remove $FreeBSD$: one-line nroff pattern
Remove /^\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:15 -06:00
Warner Losh d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh 2a63c3be15 Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:29 -06:00
Warner Losh 42b388439b Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:23 -06:00
Mateusz Guzik e01f9fe10c ipf: low-effort fix to make it compilable without inet6 2023-07-05 10:02:32 +00:00
John Baldwin 90f2fee0e0 ipf: Remove set but unused variables.
Reported by:	clang
Differential Revision:	https://reviews.freebsd.org/D40667
2023-06-27 10:19:32 -07:00
John Baldwin a7f25f141a libipf: Remove set but unused variable from printfraginfo().
Reported by:	GCC
Differential Revision:	https://reviews.freebsd.org/D40652
2023-06-27 10:19:31 -07:00
John Baldwin 553022aba5 ipf: Remove no-longer-needed NO_WARRAY_BOUNDS. 2023-06-09 15:35:32 -07:00