freebsd-dev/sys
David Bright 2b08b42bae iconv uses strlen directly on user supplied memory
`iconv_sysctl_add` from `sys/libkern/iconv.c` incorrectly limits the
size of user strings, such that several out of bounds reads could have
been possible.

static int
iconv_sysctl_add(SYSCTL_HANDLER_ARGS)
{
	struct iconv_converter_class *dcp;
	struct iconv_cspair *csp;
	struct iconv_add_in din;
	struct iconv_add_out dout;
	int error;

	error = SYSCTL_IN(req, &din, sizeof(din));
	if (error)
		return error;
	if (din.ia_version != ICONV_ADD_VER)
		return EINVAL;
	if (din.ia_datalen > ICONV_CSMAXDATALEN)
		return EINVAL;
	if (strlen(din.ia_from) >= ICONV_CSNMAXLEN)
		return EINVAL;
	if (strlen(din.ia_to) >= ICONV_CSNMAXLEN)
		return EINVAL;
	if (strlen(din.ia_converter) >= ICONV_CNVNMAXLEN)
		return EINVAL;
...

Since the `din` struct is directly copied from userland, there is no
guarantee that the strings supplied will be NULL terminated. The
`strlen` calls could continue reading past the designated buffer
sizes.

Declaration of `struct iconv_add_in` is found in `sys/sys/iconv.h`:

struct iconv_add_in {
	int	ia_version;
	char	ia_converter[ICONV_CNVNMAXLEN];
	char	ia_to[ICONV_CSNMAXLEN];
	char	ia_from[ICONV_CSNMAXLEN];
	int	ia_datalen;
	const void *ia_data;
};

Our strings are followed by the `ia_datalen` member, which is checked
before the `strlen` calls:

if (din.ia_datalen > ICONV_CSMAXDATALEN)

Since `ICONV_CSMAXDATALEN` has value `0x41000` (and is `unsigned`),
this ensures that `din.ia_datalen` contains at least 1 byte of 0, so
it is not possible to trigger a read out of bounds of the `struct`
however, this code is fragile and could introduce subtle bugs in the
future if the `struct` is ever modified.

PR:		207302
Submitted by:	CTurt <cturt@hardenedbsd.org>
Reported by:	CTurt <cturt@hardenedbsd.org>
Reviewed by:	jhb, vangyzen
MFC after:	1 week
Sponsored by:	Dell EMC
Differential Revision:	https://reviews.freebsd.org/D14521
2018-02-26 18:23:36 +00:00
..
amd64 Greatly reduce the number of #ifdefs supporting the TCP_RFC7413 kernel option. 2018-02-26 03:03:41 +00:00
arm Add a SPI driver for imx5 and imx6. 2018-02-26 02:28:32 +00:00
arm64 In do_ast, make sure the interrupts are enabled before calling ast(). 2018-02-26 13:12:51 +00:00
bsm
cam Use bool instead of int for predicate functions relating to work 2018-02-23 16:06:54 +00:00
cddl Don't declare __assfail as static 2018-02-25 14:29:43 +00:00
compat Correct pseudo misspelling in sys/ comments 2018-02-23 18:15:50 +00:00
conf This is an implementation of the client side of TCP Fast Open (TFO) 2018-02-26 02:53:22 +00:00
contrib Define CK_MD_TSO for the relevant arches (i386, amd64 and sparc64). 2018-02-16 17:50:06 +00:00
crypto Remove unused error return from API that cannot fail 2018-02-23 20:15:19 +00:00
ddb Implement 'domainset', a cpuset based NUMA policy mechanism. This allows 2018-01-12 22:48:23 +00:00
dev ofw_fdt: Simplify parts with new libfdt methods 2018-02-26 14:00:23 +00:00
dts Add a skeleton Clock Manager for RPi2/3, and use that from pwm 2018-01-22 07:10:30 +00:00
fs {ext2|ufs}_readdir: Avoid setting negative ncookies. 2018-02-06 22:38:19 +00:00
gdb
geom Fix a memory leak introduced in r328426. 2018-02-16 15:41:03 +00:00
gnu bwn(4): txpid2g/txpid5g[lh] are not defined after sromrev 7; the default 2018-02-13 17:43:54 +00:00
i386 Remove unused error return from API that cannot fail 2018-02-23 20:15:19 +00:00
isa Add ISA PNP tables to ISA drivers. Fix a few incidental comments. 2018-01-29 00:22:30 +00:00
kern Don't generate data in sysctl_out_proc unless we intend to copy out. 2018-02-25 15:16:58 +00:00
kgssapi kgssapi: Remove trivial deadcode 2018-02-14 00:12:03 +00:00
libkern iconv uses strlen directly on user supplied memory 2018-02-26 18:23:36 +00:00
mips Do not include float interfaces when using libsa. 2018-02-23 04:04:25 +00:00
modules Add a SPI driver for imx5 and imx6. 2018-02-26 02:28:32 +00:00
net pf: Cope with overly large net.pf.states_hashsize 2018-02-25 08:56:44 +00:00
net80211
netgraph Correct pseudo misspelling in sys/ comments 2018-02-23 18:15:50 +00:00
netinet Greatly reduce the number of #ifdefs supporting the TCP_RFC7413 kernel option. 2018-02-26 03:03:41 +00:00
netinet6 Update the MTU in affected routes when IPv6 RA changes the MTU 2018-02-12 19:49:20 +00:00
netipsec Remove unused variables and sysctl declaration. 2018-02-19 12:20:51 +00:00
netpfil pf: Cope with overly large net.pf.states_hashsize 2018-02-25 08:56:44 +00:00
netsmb Unsign some values related to allocation. 2018-01-22 02:08:10 +00:00
nfs Modernize nfssvc(2) registartion. 2018-02-08 20:09:42 +00:00
nfsclient style: Remove remaining deprecated MALLOC/FREE macros 2018-01-25 22:25:13 +00:00
nfsserver
nlm Use syscall_helper_register() to register syscalls and initialize though 2018-02-10 01:09:22 +00:00
ofed Import the mthca kernel side infiniband driver from Linux 4.9 and fix 2018-02-13 17:04:34 +00:00
opencrypto Move per-operation data out of the csession structure. 2018-01-26 23:21:50 +00:00
powerpc Correct a copy&paste-o -- altivec assist interrupt, not watchdog 2018-02-26 03:05:36 +00:00
riscv Do not include float interfaces when using libsa. 2018-02-23 04:04:25 +00:00
rpc
security mac_portacl(4): stop panicing INVARIANTS-enabled kernel by loading .ko 2018-02-25 23:10:13 +00:00
sparc64 Do not include float interfaces when using libsa. 2018-02-23 04:04:25 +00:00
sys Add a generic Proportional Integral Derivative (PID) controller algorithm and 2018-02-23 22:51:51 +00:00
teken
tests
tools Avoid using \$. It's an unknown escape sequence. Some awks warn about 2018-01-28 05:13:08 +00:00
ufs Use a more straight-forward approach to relaxing the location 2018-02-26 00:34:56 +00:00
vm Restore the pre-r329882 inactive page shortage computation. 2018-02-24 20:47:22 +00:00
x86 Correct pseudo misspelling in sys/ comments 2018-02-23 18:15:50 +00:00
xdr
xen
Makefile