Module Name:    src
Committed By:   riastradh
Date:           Wed Sep  4 12:57:10 UTC 2024

Modified Files:
        src/sys/external/bsd/libnv/dist: nvpair.c

Log Message:
libnv: Check for NUL within bounds when unpacking string arrays.

This avoids buffer overrun in the subsequent nv_strdup, which can be
triggered by root at securelevel 1 via ioctl(IOC_NPF_*) on /dev/npf.

Matches upstream FreeBSD change by Mariusz Zaborski
<osho...@freebsd.org>.

CVE-2024-45288

PR security/58652: libnv: Integer overflow and buffer overrun
vulnerabilities


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/external/bsd/libnv/dist/nvpair.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/libnv/dist/nvpair.c
diff -u src/sys/external/bsd/libnv/dist/nvpair.c:1.12 src/sys/external/bsd/libnv/dist/nvpair.c:1.13
--- src/sys/external/bsd/libnv/dist/nvpair.c:1.12	Wed Sep  4 12:57:00 2024
+++ src/sys/external/bsd/libnv/dist/nvpair.c	Wed Sep  4 12:57:10 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvpair.c,v 1.12 2024/09/04 12:57:00 riastradh Exp $	*/
+/*	$NetBSD: nvpair.c,v 1.13 2024/09/04 12:57:10 riastradh Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -36,7 +36,7 @@
 #ifdef __FreeBSD__
 __FBSDID("$FreeBSD: head/sys/contrib/libnv/nvpair.c 335382 2018-06-19 18:43:02Z lwhsu $");
 #else
-__RCSID("$NetBSD: nvpair.c,v 1.12 2024/09/04 12:57:00 riastradh Exp $");
+__RCSID("$NetBSD: nvpair.c,v 1.13 2024/09/04 12:57:10 riastradh Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1008,6 +1008,10 @@ nvpair_unpack_string_array(bool isbe __u
 	for (ii = 0; ii < nvp->nvp_nitems; ii++) {
 		len = strnlen(tmp, size - 1) + 1;
 		size -= len;
+		if (tmp[len - 1] != '\0') {
+			ERRNO_SET(EINVAL);
+			return (NULL);
+		}
 		if (size < 0) {
 			ERRNO_SET(EINVAL);
 			return (NULL);

Reply via email to