freebsd-dev/sys/netpfil/pf
Mark Johnston 64432ad2a2 pf: Validate user string nul-termination before copying
Some pf ioctl handlers use strlcpy() to copy strings when converting
from user structures to their in-kernel representations.  strlcpy()
ensures that the destination will be nul-terminated, but it assumes that
the source is nul-terminated.  In particular, it returns the full length
of the source string, so if the source is not nul-terminated, strlcpy()
will keep scanning until it finds a nul byte, and it may encounter an
unmapped page first.  Add a helper to validate user strings before
copying.

There are also places where we look up a ruleset using a user-provided
anchor string.  In some ioctl handlers we were already nul-terminating
the string, avoiding the same problem, but in other places we were not.
Fix those by nul-terminating as well.  Aside from being consistent,
anchors have a maximum length of MAXPATHLEN - 1 so calling strnlen()
might not be so desirable.

Reported by:	syzbot+35a1549b4663e9483dd1@syzkaller.appspotmail.com
Reviewed by:	kp
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31169
2021-07-28 10:41:01 -04:00
..
if_pflog.c pf: Split pfi_kif into a user and kernel space structure 2021-01-05 23:35:37 +01:00
if_pfsync.c pf: rename pf_state to pf_kstate 2021-07-08 10:31:43 +02:00
in4_cksum.c SPDX: license IDs for some ISC-related files. 2017-12-08 15:57:29 +00:00
pf_altq.h Extended pf(4) ioctl interface and pfctl(8) to allow bandwidths of 2018-08-22 19:38:48 +00:00
pf_if.c pf: switch kif counters to pf_counter_u64 2021-07-25 10:22:17 +02:00
pf_ioctl.c pf: Validate user string nul-termination before copying 2021-07-28 10:41:01 -04:00
pf_lb.c pf: switch rule counters to pf_counter_u64 2021-07-25 10:22:17 +02:00
pf_mtag.h pf: syncookie support 2021-07-20 10:36:13 +02:00
pf_norm.c pf: batch critical section for several counters 2021-07-25 10:22:17 +02:00
pf_nv.c pf: switch rule counters to pf_counter_u64 2021-07-25 10:22:17 +02:00
pf_nv.h pf: switch rule counters to pf_counter_u64 2021-07-25 10:22:17 +02:00
pf_osfp.c net: clean up empty lines in .c and .h files 2020-09-01 21:19:14 +00:00
pf_ruleset.c pf: match keyword support 2021-07-17 12:01:08 +02:00
pf_syncookies.c pf: fix ABI breakage 2021-07-28 12:16:33 +02:00
pf_table.c pf: Remove unneeded NULL check 2021-07-08 10:32:33 +02:00
pf.c vlan: deduplicate bpf_setpcp() and pf_ieee8021q_setpcp() 2021-07-26 23:13:31 +02:00
pf.h pf: fix ABI breakage 2021-07-28 12:16:33 +02:00