CVS commit: src/lib/libc/time

2024-03-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 16 00:16:21 UTC 2024

Modified Files:
src/lib/libc/time: strptime.c

Log Message:
strptime(3): Reduce unnecessary indentation.

Post-fix tidying.

No functional change intended.

PR lib/58041


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/lib/libc/time/strptime.c

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



CVS commit: src/lib/libc/time

2024-03-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 16 00:16:21 UTC 2024

Modified Files:
src/lib/libc/time: strptime.c

Log Message:
strptime(3): Reduce unnecessary indentation.

Post-fix tidying.

No functional change intended.

PR lib/58041


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/lib/libc/time/strptime.c

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

Modified files:

Index: src/lib/libc/time/strptime.c
diff -u src/lib/libc/time/strptime.c:1.64 src/lib/libc/time/strptime.c:1.65
--- src/lib/libc/time/strptime.c:1.64	Sat Mar 16 00:06:45 2024
+++ src/lib/libc/time/strptime.c	Sat Mar 16 00:16:21 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: strptime.c,v 1.64 2024/03/16 00:06:45 riastradh Exp $	*/
+/*	$NetBSD: strptime.c,v 1.65 2024/03/16 00:16:21 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: strptime.c,v 1.64 2024/03/16 00:06:45 riastradh Exp $");
+__RCSID("$NetBSD: strptime.c,v 1.65 2024/03/16 00:16:21 riastradh Exp $");
 #endif
 
 #include "namespace.h"
@@ -346,41 +346,40 @@ literal:
 			LEGAL_ALT(ALT_O);
 			continue;
 
-		case 's':	/* seconds since the epoch */
-			{
-const time_t TIME_MAX = __type_max(time_t);
-time_t sse;
-unsigned d;
+		case 's': {	/* seconds since the epoch */
+			const time_t TIME_MAX = __type_max(time_t);
+			time_t sse;
+			unsigned d;
 
-if (*bp < '0' || *bp > '9') {
-	bp = NULL;
-	continue;
-}
+			if (*bp < '0' || *bp > '9') {
+bp = NULL;
+continue;
+			}
 
-sse = *bp++ - '0';
-while (*bp >= '0' && *bp <= '9') {
-	d = *bp++ - '0';
-	if (sse > TIME_MAX/10) {
-		bp = NULL;
-		break;
-	}
-	sse *= 10;
-	if (sse > TIME_MAX - d) {
-		bp = NULL;
-		break;
-	}
-	sse += d;
+			sse = *bp++ - '0';
+			while (*bp >= '0' && *bp <= '9') {
+d = *bp++ - '0';
+if (sse > TIME_MAX/10) {
+	bp = NULL;
+	break;
 }
-if (bp == NULL)
-	continue;
-
-if (localtime_r(, tm) == NULL)
+sse *= 10;
+if (sse > TIME_MAX - d) {
 	bp = NULL;
-else
-	state |= S_YDAY | S_WDAY |
-	S_MON | S_MDAY | S_YEAR;
+	break;
+}
+sse += d;
 			}
+			if (bp == NULL)
+continue;
+
+			if (localtime_r(, tm) == NULL)
+bp = NULL;
+			else
+state |= S_YDAY | S_WDAY |
+S_MON | S_MDAY | S_YEAR;
 			continue;
+		}
 
 		case 'U':	/* The week of year, beginning on sunday. */
 		case 'W':	/* The week of year, beginning on monday. */



CVS commit: src/lib/libc/time

2024-03-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 16 00:06:46 UTC 2024

Modified Files:
src/lib/libc/time: strptime.c

Log Message:
strptime(3): Avoid arithmetic overflow.

PR lib/58041


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/lib/libc/time/strptime.c

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

Modified files:

Index: src/lib/libc/time/strptime.c
diff -u src/lib/libc/time/strptime.c:1.63 src/lib/libc/time/strptime.c:1.64
--- src/lib/libc/time/strptime.c:1.63	Mon Sep 21 15:31:54 2020
+++ src/lib/libc/time/strptime.c	Sat Mar 16 00:06:45 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: strptime.c,v 1.63 2020/09/21 15:31:54 ginsbach Exp $	*/
+/*	$NetBSD: strptime.c,v 1.64 2024/03/16 00:06:45 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: strptime.c,v 1.63 2020/09/21 15:31:54 ginsbach Exp $");
+__RCSID("$NetBSD: strptime.c,v 1.64 2024/03/16 00:06:45 riastradh Exp $");
 #endif
 
 #include "namespace.h"
@@ -346,30 +346,33 @@ literal:
 			LEGAL_ALT(ALT_O);
 			continue;
 
-#ifndef TIME_MAX
-#define TIME_MAX	INT64_MAX
-#endif
 		case 's':	/* seconds since the epoch */
 			{
-time_t sse = 0;
-uint64_t rulim = TIME_MAX;
+const time_t TIME_MAX = __type_max(time_t);
+time_t sse;
+unsigned d;
 
 if (*bp < '0' || *bp > '9') {
 	bp = NULL;
 	continue;
 }
 
-do {
+sse = *bp++ - '0';
+while (*bp >= '0' && *bp <= '9') {
+	d = *bp++ - '0';
+	if (sse > TIME_MAX/10) {
+		bp = NULL;
+		break;
+	}
 	sse *= 10;
-	sse += *bp++ - '0';
-	rulim /= 10;
-} while ((sse * 10 <= TIME_MAX) &&
-	 rulim && *bp >= '0' && *bp <= '9');
-
-if (sse < 0 || (uint64_t)sse > TIME_MAX) {
-	bp = NULL;
-	continue;
+	if (sse > TIME_MAX - d) {
+		bp = NULL;
+		break;
+	}
+	sse += d;
 }
+if (bp == NULL)
+	continue;
 
 if (localtime_r(, tm) == NULL)
 	bp = NULL;



CVS commit: src/tests/lib/libc/time

2024-03-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 16 00:06:37 UTC 2024

Modified Files:
src/tests/lib/libc/time: t_strptime.c

Log Message:
strptime(3): Exercise some edge cases in the automatic tests.

Unfortunately, we can't quite use strptime as a black box to detect
the cases that triggered undefined behaviour, because strptime just
fails in that case anyway since the number that would go in .tm_year
is far out of the representable range.

PR lib/58041


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libc/time/t_strptime.c

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

Modified files:

Index: src/tests/lib/libc/time/t_strptime.c
diff -u src/tests/lib/libc/time/t_strptime.c:1.15 src/tests/lib/libc/time/t_strptime.c:1.16
--- src/tests/lib/libc/time/t_strptime.c:1.15	Sun Jun  3 08:48:37 2018
+++ src/tests/lib/libc/time/t_strptime.c	Sat Mar 16 00:06:37 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strptime.c,v 1.15 2018/06/03 08:48:37 maya Exp $ */
+/* $NetBSD: t_strptime.c,v 1.16 2024/03/16 00:06:37 riastradh Exp $ */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -32,11 +32,13 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_strptime.c,v 1.15 2018/06/03 08:48:37 maya Exp $");
+__RCSID("$NetBSD: t_strptime.c,v 1.16 2024/03/16 00:06:37 riastradh Exp $");
 
-#include 
-#include 
+#include 
+#include 
 #include 
+#include 
+#include 
 
 #include 
 
@@ -441,6 +443,151 @@ ATF_TC_BODY(Zone, tc)
 	ztest("%Z");
 }
 
+ATF_TC(posixtime_overflow);
+
+ATF_TC_HEAD(posixtime_overflow, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr",
+	"Checks strptime(3) safely rejects POSIX time overfow");
+}
+
+ATF_TC_BODY(posixtime_overflow, tc)
+{
+	static const uint64_t P[] = { /* cases that should pass round-trip */
+		[0] = 0,
+		[1] = 1,
+		[2] = 2,
+		[3] = 0x7ffe,
+		[4] = 0x7fff,
+		[5] = 0x8000,
+		[6] = 0x8001,
+		[7] = 0xfffe,
+		[8] = 0x,
+		[9] = 0x1,
+		[10] = 0x10001,
+		[11] = 67767976233532799, /* 2147483647-12-31T23:59:59 */
+		/*
+		 * Beyond this point, the year (.tm_year + 1900)
+		 * overflows the signed 32-bit range, so we won't be
+		 * able to test round-trips:
+		 */
+		[12] = 67767976233532800,
+		[13] = 67767976233532801,
+		[14] = 67768036191676799,
+		/*
+		 * Beyond this point, .tm_year itself overflows the
+		 * signed 32-bit range, so strptime won't work at all;
+		 * the output can't be represented in struct tm.
+		 */
+#if 0
+		[15] = 67768036191676800,
+		[16] = 67768036191676801,
+		[17] = 0x7ffe,
+		[18] = 0x7fff,
+#endif
+	};
+	static const uint64_t F[] = { /* cases strptime should reject */
+		[0] = 67768036191676800,
+		[1] = 67768036191676801,
+		[2] = 0x7ffe,
+		[3] = 0x7fff,
+		[4] = 0x8000,
+		[5] = 0x8001,
+		[6] = 0xfffe,
+		[7] = 0x,
+	};
+	size_t i;
+
+	/*
+	 * Verify time_t fits in uint64_t, with space to spare since
+	 * it's signed.
+	 */
+	__CTASSERT(__type_max(time_t) < __type_max(uint64_t));
+
+	/*
+	 * Make sure we work in UTC so this test doesn't depend on
+	 * which time zone your machine is configured for.
+	 */
+	setenv("TZ", "UTC", 1);
+
+	/*
+	 * Check the should-pass cases.
+	 */
+	for (i = 0; i < __arraycount(P); i++) {
+		char buf[sizeof("18446744073709551616")];
+		int n;
+		struct tm tm;
+		time_t t;
+		int error;
+
+		/*
+		 * Format the integer in decimal.
+		 */
+		n = snprintf(buf, sizeof(buf), "%"PRIu64, P[i]);
+		ATF_CHECK_MSG(n >= 0 && (unsigned)n < sizeof(buf),
+		"P[%zu]: 64-bit requires %d digits", i, n);
+
+		/*
+		 * Parse the time into components.
+		 */
+		fprintf(stderr, "# P[%zu]: %"PRId64"\n", i, P[i]);
+		if (strptime(buf, "%s", ) == NULL) {
+			atf_tc_fail_nonfatal("P[%zu]: strptime failed", i);
+			continue;
+		}
+		fprintf(stderr, "tm_sec=%d\n", tm.tm_sec);
+		fprintf(stderr, "tm_min=%d\n", tm.tm_min);
+		fprintf(stderr, "tm_hour=%d\n", tm.tm_hour);
+		fprintf(stderr, "tm_mday=%d\n", tm.tm_mday);
+		fprintf(stderr, "tm_mon=%d\n", tm.tm_mon);
+		fprintf(stderr, "tm_year=%d\n", tm.tm_year);
+		fprintf(stderr, "tm_wday=%d\n", tm.tm_wday);
+		fprintf(stderr, "tm_yday=%d\n", tm.tm_yday);
+		fprintf(stderr, "tm_isdst=%d\n", tm.tm_isdst);
+		fprintf(stderr, "tm_gmtoff=%ld\n", tm.tm_gmtoff);
+		fprintf(stderr, "tm_zone=%s\n", tm.tm_zone);
+
+		/*
+		 * Convert back to POSIX seconds since epoch -- unless
+		 * the year number overflows signed 32-bit, in which
+		 * case stop here because we can't test further.
+		 */
+		if (tm.tm_year > 0x7fff - 1900)
+			continue;
+		t = mktime();
+		error = errno;
+		ATF_CHECK_MSG(t != -1, "P[%zu]: mktime failed: %d, %s",
+		i, error, strerror(error));
+
+		/*
+		 * Verify the round-trip.
+		 */
+		ATF_CHECK_EQ_MSG(P[i], (uint64_t)t,
+		"P[%zu]: %"PRId64" -> 

CVS commit: src/lib/libc/time

2024-03-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 16 00:06:46 UTC 2024

Modified Files:
src/lib/libc/time: strptime.c

Log Message:
strptime(3): Avoid arithmetic overflow.

PR lib/58041


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/lib/libc/time/strptime.c

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



CVS commit: src/tests/lib/libc/time

2024-03-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 16 00:06:37 UTC 2024

Modified Files:
src/tests/lib/libc/time: t_strptime.c

Log Message:
strptime(3): Exercise some edge cases in the automatic tests.

Unfortunately, we can't quite use strptime as a black box to detect
the cases that triggered undefined behaviour, because strptime just
fails in that case anyway since the number that would go in .tm_year
is far out of the representable range.

PR lib/58041


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libc/time/t_strptime.c

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



CVS commit: src/sys/uvm

2024-03-15 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Mar 15 22:15:21 UTC 2024

Modified Files:
src/sys/uvm: uvm_swap.h

Log Message:
"retval = 0" should be "*retval = 0", should fix the broken build.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/uvm/uvm_swap.h

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



CVS commit: src/sys/uvm

2024-03-15 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Mar 15 22:15:21 UTC 2024

Modified Files:
src/sys/uvm: uvm_swap.h

Log Message:
"retval = 0" should be "*retval = 0", should fix the broken build.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/uvm/uvm_swap.h

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

Modified files:

Index: src/sys/uvm/uvm_swap.h
diff -u src/sys/uvm/uvm_swap.h:1.28 src/sys/uvm/uvm_swap.h:1.29
--- src/sys/uvm/uvm_swap.h:1.28	Fri Mar 15 20:09:31 2024
+++ src/sys/uvm/uvm_swap.h	Fri Mar 15 22:15:21 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.h,v 1.28 2024/03/15 20:09:31 andvar Exp $	*/
+/*	$NetBSD: uvm_swap.h,v 1.29 2024/03/15 22:15:21 andvar Exp $	*/
 
 /*
  * Copyright (c) 1997 Matthew R. Green
@@ -65,7 +65,7 @@ uvm_swap_stats(char *c, int l, void (*f)
 size_t count, register_t *retval)
 {
 
-	retval = 0;
+	*retval = 0;
 	return ENOSYS;
 }
 



CVS commit: src/sys/uvm

2024-03-15 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Mar 15 20:09:31 UTC 2024

Modified Files:
src/sys/uvm: uvm_swap.h

Log Message:
Rewrite !VMSWAP uvm_swap_stats() macro as a static function. NFCI.

>From riastradh


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/uvm/uvm_swap.h

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

Modified files:

Index: src/sys/uvm/uvm_swap.h
diff -u src/sys/uvm/uvm_swap.h:1.27 src/sys/uvm/uvm_swap.h:1.28
--- src/sys/uvm/uvm_swap.h:1.27	Fri Mar 15 07:09:37 2024
+++ src/sys/uvm/uvm_swap.h	Fri Mar 15 20:09:31 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.h,v 1.27 2024/03/15 07:09:37 andvar Exp $	*/
+/*	$NetBSD: uvm_swap.h,v 1.28 2024/03/15 20:09:31 andvar Exp $	*/
 
 /*
  * Copyright (c) 1997 Matthew R. Green
@@ -39,10 +39,10 @@
 #endif
 
 struct lwp;
+struct swapent;
 
 #if defined(VMSWAP)
 
-struct swapent;
 struct vm_page;
 
 int	uvm_swap_get(struct vm_page *, int, int);
@@ -57,8 +57,18 @@ int	uvm_swap_stats(char *, int,
 void (*)(void *, const struct swapent *), size_t, register_t *);
 
 #else /* defined(VMSWAP) */
+
 #define	uvm_swapisfull()	true
-#define uvm_swap_stats(c, l, f, count, retval) (void)(f), (*retval = 0, ENOSYS)
+
+static inline int
+uvm_swap_stats(char *c, int l, void (*f)(void *, const struct swapent *),
+size_t count, register_t *retval)
+{
+
+	retval = 0;
+	return ENOSYS;
+}
+
 #endif /* defined(VMSWAP) */
 
 void	uvm_swap_shutdown(struct lwp *);



CVS commit: src/sys/uvm

2024-03-15 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Mar 15 20:09:31 UTC 2024

Modified Files:
src/sys/uvm: uvm_swap.h

Log Message:
Rewrite !VMSWAP uvm_swap_stats() macro as a static function. NFCI.

>From riastradh


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/uvm/uvm_swap.h

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



CVS commit: src

2024-03-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 15 18:10:37 UTC 2024

Modified Files:
src/crypto/external/bsd/openssl/dist/crypto/evp: legacy_sha.c
src/crypto/external/bsd/openssl/dist/include/crypto: sha.h
src/crypto/external/bsd/openssl/dist/providers/implementations/digests:
sha2_prov.c
src/crypto/external/bsd/openssl/lib/libcrypto: libc-sha2xx.c
src/tests/crypto/libcrypto: t_sha512trunc.c

Log Message:
libcrypto: Fix buffer overrun in truncated SHA-512 functions.

Further fallout from the libc/openssl sha2 symbol collision.

PR lib/58039


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.2 -r1.2 \
src/crypto/external/bsd/openssl/dist/crypto/evp/legacy_sha.c
cvs rdiff -u -r1.1.1.2 -r1.2 \
src/crypto/external/bsd/openssl/dist/include/crypto/sha.h
cvs rdiff -u -r1.1.1.1 -r1.2 \

src/crypto/external/bsd/openssl/dist/providers/implementations/digests/sha2_prov.c
cvs rdiff -u -r1.3 -r1.4 \
src/crypto/external/bsd/openssl/lib/libcrypto/libc-sha2xx.c
cvs rdiff -u -r1.1 -r1.2 src/tests/crypto/libcrypto/t_sha512trunc.c

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

Modified files:

Index: src/crypto/external/bsd/openssl/dist/crypto/evp/legacy_sha.c
diff -u src/crypto/external/bsd/openssl/dist/crypto/evp/legacy_sha.c:1.1.1.2 src/crypto/external/bsd/openssl/dist/crypto/evp/legacy_sha.c:1.2
--- src/crypto/external/bsd/openssl/dist/crypto/evp/legacy_sha.c:1.1.1.2	Wed Oct 25 17:13:53 2023
+++ src/crypto/external/bsd/openssl/dist/crypto/evp/legacy_sha.c	Fri Mar 15 18:10:37 2024
@@ -49,9 +49,9 @@ static int nm##_init(EVP_MD_CTX *ctx)   
 #define sha512_256_Initsha512_256_init
 
 #define sha512_224_Update  SHA512_Update
-#define sha512_224_Final   SHA512_Final
+#define sha512_224_Final   sha512_224_final /* XXX NetBSD libc sha2 */
 #define sha512_256_Update  SHA512_Update
-#define sha512_256_Final   SHA512_Final
+#define sha512_256_Final   sha512_256_final /* XXX NetBSD libc sha2 */
 
 IMPLEMENT_LEGACY_EVP_MD_METH(sha1, SHA1)
 IMPLEMENT_LEGACY_EVP_MD_METH(sha224, SHA224)

Index: src/crypto/external/bsd/openssl/dist/include/crypto/sha.h
diff -u src/crypto/external/bsd/openssl/dist/include/crypto/sha.h:1.1.1.2 src/crypto/external/bsd/openssl/dist/include/crypto/sha.h:1.2
--- src/crypto/external/bsd/openssl/dist/include/crypto/sha.h:1.1.1.2	Sun May  7 18:29:28 2023
+++ src/crypto/external/bsd/openssl/dist/include/crypto/sha.h	Fri Mar 15 18:10:37 2024
@@ -16,6 +16,8 @@
 
 int sha512_224_init(SHA512_CTX *);
 int sha512_256_init(SHA512_CTX *);
+int sha512_224_final(unsigned char *, SHA512_CTX *); /* XXX NetBSD libc sha2 */
+int sha512_256_final(unsigned char *, SHA512_CTX *); /* XXX NetBSD libc sha2 */
 int ossl_sha1_ctrl(SHA_CTX *ctx, int cmd, int mslen, void *ms);
 unsigned char *ossl_sha1(const unsigned char *d, size_t n, unsigned char *md);
 

Index: src/crypto/external/bsd/openssl/dist/providers/implementations/digests/sha2_prov.c
diff -u src/crypto/external/bsd/openssl/dist/providers/implementations/digests/sha2_prov.c:1.1.1.1 src/crypto/external/bsd/openssl/dist/providers/implementations/digests/sha2_prov.c:1.2
--- src/crypto/external/bsd/openssl/dist/providers/implementations/digests/sha2_prov.c:1.1.1.1	Sun May  7 18:29:30 2023
+++ src/crypto/external/bsd/openssl/dist/providers/implementations/digests/sha2_prov.c	Fri Mar 15 18:10:37 2024
@@ -86,10 +86,12 @@ IMPLEMENT_digest_functions(sha512, SHA51
 /* ossl_sha512_224_functions */
 IMPLEMENT_digest_functions(sha512_224, SHA512_CTX,
SHA512_CBLOCK, SHA224_DIGEST_LENGTH, SHA2_FLAGS,
-   sha512_224_init, SHA512_Update, SHA512_Final)
+   sha512_224_init, SHA512_Update,
+   /* XXX NetBSD libc sha2 */sha512_224_final)
 
 /* ossl_sha512_256_functions */
 IMPLEMENT_digest_functions(sha512_256, SHA512_CTX,
SHA512_CBLOCK, SHA256_DIGEST_LENGTH, SHA2_FLAGS,
-   sha512_256_init, SHA512_Update, SHA512_Final)
+   sha512_256_init, SHA512_Update,
+   /* XXX NetBSD libc sha2 */sha512_256_final)
 

Index: src/crypto/external/bsd/openssl/lib/libcrypto/libc-sha2xx.c
diff -u src/crypto/external/bsd/openssl/lib/libcrypto/libc-sha2xx.c:1.3 src/crypto/external/bsd/openssl/lib/libcrypto/libc-sha2xx.c:1.4
--- src/crypto/external/bsd/openssl/lib/libcrypto/libc-sha2xx.c:1.3	Sat May  6 17:07:23 2023
+++ src/crypto/external/bsd/openssl/lib/libcrypto/libc-sha2xx.c	Fri Mar 15 18:10:37 2024
@@ -47,6 +47,20 @@ sha512_224_init(SHA512_CTX *context)
 }
 
 extern int
+sha512_224_final(unsigned char *md, SHA512_CTX *context);
+int
+sha512_224_final(unsigned char *md, SHA512_CTX *context)
+{
+	unsigned char tmp[64];
+
+	SHA512_Final(tmp, context);
+	memcpy(md, tmp, 28);
+	explicit_memset(tmp, 0, sizeof(tmp));
+	return 1;
+
+}
+
+extern int
 

CVS commit: src

2024-03-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 15 18:10:37 UTC 2024

Modified Files:
src/crypto/external/bsd/openssl/dist/crypto/evp: legacy_sha.c
src/crypto/external/bsd/openssl/dist/include/crypto: sha.h
src/crypto/external/bsd/openssl/dist/providers/implementations/digests:
sha2_prov.c
src/crypto/external/bsd/openssl/lib/libcrypto: libc-sha2xx.c
src/tests/crypto/libcrypto: t_sha512trunc.c

Log Message:
libcrypto: Fix buffer overrun in truncated SHA-512 functions.

Further fallout from the libc/openssl sha2 symbol collision.

PR lib/58039


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.2 -r1.2 \
src/crypto/external/bsd/openssl/dist/crypto/evp/legacy_sha.c
cvs rdiff -u -r1.1.1.2 -r1.2 \
src/crypto/external/bsd/openssl/dist/include/crypto/sha.h
cvs rdiff -u -r1.1.1.1 -r1.2 \

src/crypto/external/bsd/openssl/dist/providers/implementations/digests/sha2_prov.c
cvs rdiff -u -r1.3 -r1.4 \
src/crypto/external/bsd/openssl/lib/libcrypto/libc-sha2xx.c
cvs rdiff -u -r1.1 -r1.2 src/tests/crypto/libcrypto/t_sha512trunc.c

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



CVS commit: src/doc

2024-03-15 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Mar 15 17:47:02 UTC 2024

Modified Files:
src/doc: CHANGES

Log Message:
doc: changes from the last 2 weeks


To generate a diff of this commit:
cvs rdiff -u -r1.3044 -r1.3045 src/doc/CHANGES

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

Modified files:

Index: src/doc/CHANGES
diff -u src/doc/CHANGES:1.3044 src/doc/CHANGES:1.3045
--- src/doc/CHANGES:1.3044	Wed Mar 13 08:13:56 2024
+++ src/doc/CHANGES	Fri Mar 15 17:47:02 2024
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.3044 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.3045 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -283,6 +283,13 @@ Changes from NetBSD 10.0 to NetBSD 11.0:
 	nsd: Import 4.8.0. [christos 20240217]
 	unbound(8): Import 1.19.1. [christos 20240217]
 	bind: Import 9.18.24 [christos 20240221]
+	re(4): Add support for Killer E2600 Ethernet. [jakllsch 20240228]
 	sqlite3(1): Import 3.45.1. [christos 20240301]
+	alpha: Add initial support for the DEC KN7AA ("Ruby") systems,
+		DEC 7000 and DEC 1. [thorpej 20240302]
 	elftoolchain: Import svn r4037. [christos 20240303]
+	certctl(8): Improve the performance of `certctl list`.
+		[riastradh 20240303]
+	audioplay(1): Add -n flag that doesn't write audio data for the
+		test suite. [mrg 20240304]
 	mac68k: Add ascaudio(4) ASC audio driver. [nat 20240313]



CVS commit: src/doc

2024-03-15 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Mar 15 17:47:02 UTC 2024

Modified Files:
src/doc: CHANGES

Log Message:
doc: changes from the last 2 weeks


To generate a diff of this commit:
cvs rdiff -u -r1.3044 -r1.3045 src/doc/CHANGES

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



CVS commit: src/doc

2024-03-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 15 15:49:01 UTC 2024

Modified Files:
src/doc: 3RDPARTY

Log Message:
doc/3RDPARTY: Note OpenSSL vendor/release tags.


To generate a diff of this commit:
cvs rdiff -u -r1.1999 -r1.2000 src/doc/3RDPARTY

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

Modified files:

Index: src/doc/3RDPARTY
diff -u src/doc/3RDPARTY:1.1999 src/doc/3RDPARTY:1.2000
--- src/doc/3RDPARTY:1.1999	Thu Mar 14 09:13:57 2024
+++ src/doc/3RDPARTY	Fri Mar 15 15:49:01 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: 3RDPARTY,v 1.1999 2024/03/14 09:13:57 wiz Exp $
+#	$NetBSD: 3RDPARTY,v 1.2000 2024/03/15 15:49:01 riastradh Exp $
 #
 # This file contains a list of the software that has been integrated into
 # NetBSD where we are not the primary maintainer.
@@ -1131,6 +1131,9 @@ Mailing List:	openssl-announce@openssl.o
 Responsible:	christos, mjf, tls, riastradh, spz
 License:	OpenSSL and SSLeay license (both BSD-like)
 Location:	crypto/external/bsd/openssl/dist
+Vendor tag:	OPENSSL
+Release tag:	openssl-x-y-z (openssl-x-y-zw in past with lettered releases)
+Current tag:	openssl-3-0-12
 Notes:
 - Run openssl2netbsd to get rid of the RCSID identifiers
 - run make in /usr/src/crypto/external/bsd/openssl/lib/libcrypto/man



CVS commit: src/doc

2024-03-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 15 15:49:01 UTC 2024

Modified Files:
src/doc: 3RDPARTY

Log Message:
doc/3RDPARTY: Note OpenSSL vendor/release tags.


To generate a diff of this commit:
cvs rdiff -u -r1.1999 -r1.2000 src/doc/3RDPARTY

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



CVS commit: src

2024-03-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 15 15:32:07 UTC 2024

Modified Files:
src/distrib/sets/lists/debug: mi
src/distrib/sets/lists/tests: mi
src/tests/crypto/libcrypto: Makefile
Added Files:
src/tests/crypto/libcrypto: t_sha512trunc.c

Log Message:
libcrypto: Add some trivial tests for truncated SHA-512 variants.

These should use more of the test vectors from

https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/Secure-Hashing#Testing

but this will do for now to detect the buffer overrun rake we left
lying around for ourselves.

PR lib/58039


To generate a diff of this commit:
cvs rdiff -u -r1.429 -r1.430 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.1310 -r1.1311 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.15 -r1.16 src/tests/crypto/libcrypto/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/crypto/libcrypto/t_sha512trunc.c

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



CVS commit: src

2024-03-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 15 15:32:07 UTC 2024

Modified Files:
src/distrib/sets/lists/debug: mi
src/distrib/sets/lists/tests: mi
src/tests/crypto/libcrypto: Makefile
Added Files:
src/tests/crypto/libcrypto: t_sha512trunc.c

Log Message:
libcrypto: Add some trivial tests for truncated SHA-512 variants.

These should use more of the test vectors from

https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/Secure-Hashing#Testing

but this will do for now to detect the buffer overrun rake we left
lying around for ourselves.

PR lib/58039


To generate a diff of this commit:
cvs rdiff -u -r1.429 -r1.430 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.1310 -r1.1311 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.15 -r1.16 src/tests/crypto/libcrypto/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/crypto/libcrypto/t_sha512trunc.c

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

Modified files:

Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.429 src/distrib/sets/lists/debug/mi:1.430
--- src/distrib/sets/lists/debug/mi:1.429	Thu Feb 22 01:13:43 2024
+++ src/distrib/sets/lists/debug/mi	Fri Mar 15 15:32:07 2024
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.429 2024/02/22 01:13:43 christos Exp $
+# $NetBSD: mi,v 1.430 2024/03/15 15:32:07 riastradh Exp $
 ./etc/mtree/set.debug   comp-sys-root
 ./usr/lib	comp-sys-usr		compatdir
 ./usr/lib/i18n/libBIG5_g.a			comp-c-debuglib		debuglib,compatfile
@@ -1650,6 +1650,7 @@
 ./usr/libdata/debug/usr/tests/crypto/libcrypto/h_srptest.debug		tests-crypto-debug	debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/crypto/libcrypto/h_threadstest.debug	tests-crypto-debug	debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/crypto/libcrypto/h_x509v3test.debug	tests-crypto-debug	debug,atf,compattestfile,openssl=10
+./usr/libdata/debug/usr/tests/crypto/libcrypto/t_sha512trunc.debug	tests-crypto-debug	debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/crypto/opencrypto/h_aescbc.debug		tests-crypto-debug	debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/crypto/opencrypto/h_aesctr1.debug		tests-crypto-debug	debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/crypto/opencrypto/h_aesctr2.debug		tests-crypto-debug	debug,atf,compattestfile

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1310 src/distrib/sets/lists/tests/mi:1.1311
--- src/distrib/sets/lists/tests/mi:1.1310	Thu Mar 14 21:00:33 2024
+++ src/distrib/sets/lists/tests/mi	Fri Mar 15 15:32:07 2024
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1310 2024/03/14 21:00:33 rillig Exp $
+# $NetBSD: mi,v 1.1311 2024/03/15 15:32:07 riastradh Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1476,6 +1476,7 @@
 ./usr/tests/crypto/libcrypto/t_hashes			tests-crypto-tests	compattestfile,atf
 ./usr/tests/crypto/libcrypto/t_libcrypto		tests-crypto-tests	compattestfile,atf
 ./usr/tests/crypto/libcrypto/t_pubkey			tests-crypto-tests	compattestfile,atf
+./usr/tests/crypto/libcrypto/t_sha512trunc		tests-crypto-tests	compattestfile,atf
 ./usr/tests/crypto/opencryptotests-crypto-tests	compattestfile,atf
 ./usr/tests/crypto/opencrypto/Atffile			tests-crypto-tests	compattestfile,atf
 ./usr/tests/crypto/opencrypto/Kyuafile			tests-crypto-tests	compattestfile,atf,kyua

Index: src/tests/crypto/libcrypto/Makefile
diff -u src/tests/crypto/libcrypto/Makefile:1.15 src/tests/crypto/libcrypto/Makefile:1.16
--- src/tests/crypto/libcrypto/Makefile:1.15	Mon May  8 17:46:06 2023
+++ src/tests/crypto/libcrypto/Makefile	Fri Mar 15 15:32:07 2024
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.15 2023/05/08 17:46:06 christos Exp $
+# $NetBSD: Makefile,v 1.16 2024/03/15 15:32:07 riastradh Exp $
 
 .include 
 
@@ -18,6 +18,10 @@ SUBDIR += lhash sha x509v3
 
 TESTSDIR=	${TESTSBASE}/crypto/libcrypto
 
+TESTS_C+=		t_sha512trunc
+DPADD.t_sha512trunc+=	${LIBCRYPTO}
+LDADD.t_sha512trunc+=	-lcrypto
+
 .if ${HAVE_OPENSSL} == 10
 TESTS_SH=	t_certs
 .endif

Added files:

Index: src/tests/crypto/libcrypto/t_sha512trunc.c
diff -u /dev/null src/tests/crypto/libcrypto/t_sha512trunc.c:1.1
--- /dev/null	Fri Mar 15 15:32:08 2024
+++ src/tests/crypto/libcrypto/t_sha512trunc.c	Fri Mar 15 15:32:07 2024
@@ -0,0 +1,174 @@
+/*	$NetBSD: t_sha512trunc.c,v 1.1 2024/03/15 15:32:07 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2024 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *  

CVS commit: src/sys/uvm

2024-03-15 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Mar 15 07:09:37 UTC 2024

Modified Files:
src/sys/uvm: uvm_fault.c uvm_pager.c uvm_swap.h uvm_swapstub.c

Log Message:
Fix !VMSWAP build:
Added __unused for few local variables, which are used in VMSWAP block only.
Adjust !VMSWAP uvm_swap_stats() definition to make it build with compat code.
Copied "int (*uvm_swap_stats50)(...)" definition from uvm_swap to uvm_swapstub
to avoid missing uvm_swap_stats50 reference on linking.

Fixes INSTALL_CPMBR1400, INSTALL_ZYXELKX evbmips kernel configs as a result.

Reviewed by simon and phone in IRC (thanks).


To generate a diff of this commit:
cvs rdiff -u -r1.236 -r1.237 src/sys/uvm/uvm_fault.c
cvs rdiff -u -r1.130 -r1.131 src/sys/uvm/uvm_pager.c
cvs rdiff -u -r1.26 -r1.27 src/sys/uvm/uvm_swap.h
cvs rdiff -u -r1.8 -r1.9 src/sys/uvm/uvm_swapstub.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/uvm/uvm_fault.c
diff -u src/sys/uvm/uvm_fault.c:1.236 src/sys/uvm/uvm_fault.c:1.237
--- src/sys/uvm/uvm_fault.c:1.236	Tue Sep 19 22:14:25 2023
+++ src/sys/uvm/uvm_fault.c	Fri Mar 15 07:09:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_fault.c,v 1.236 2023/09/19 22:14:25 ad Exp $	*/
+/*	$NetBSD: uvm_fault.c,v 1.237 2024/03/15 07:09:37 andvar Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.236 2023/09/19 22:14:25 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.237 2024/03/15 07:09:37 andvar Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -273,7 +273,7 @@ uvmfault_anonget(struct uvm_faultinfo *u
 {
 	struct vm_page *pg;
 	krw_t lock_type;
-	int error;
+	int error __unused; /* used for VMSWAP */
 
 	UVMHIST_FUNC(__func__); UVMHIST_CALLED(maphist);
 	KASSERT(rw_lock_held(anon->an_lock));

Index: src/sys/uvm/uvm_pager.c
diff -u src/sys/uvm/uvm_pager.c:1.130 src/sys/uvm/uvm_pager.c:1.131
--- src/sys/uvm/uvm_pager.c:1.130	Sun Oct 18 18:22:29 2020
+++ src/sys/uvm/uvm_pager.c	Fri Mar 15 07:09:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pager.c,v 1.130 2020/10/18 18:22:29 chs Exp $	*/
+/*	$NetBSD: uvm_pager.c,v 1.131 2024/03/15 07:09:37 andvar Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_pager.c,v 1.130 2020/10/18 18:22:29 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pager.c,v 1.131 2024/03/15 07:09:37 andvar Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_readahead.h"
@@ -330,7 +330,7 @@ uvm_aio_aiodone_pages(struct vm_page **p
 	struct vm_page *pg;
 	krwlock_t *slock;
 	int pageout_done;	/* number of PG_PAGEOUT pages processed */
-	int swslot;
+	int swslot __unused;	/* used for VMSWAP */
 	int i;
 	bool swap;
 	UVMHIST_FUNC(__func__); UVMHIST_CALLED(ubchist);
@@ -405,7 +405,7 @@ uvm_aio_aiodone_pages(struct vm_page **p
 		 */
 
 		if (error) {
-			int slot;
+			int slot __unused;	/* used for VMSWAP */
 			if (!write) {
 pg->flags |= PG_RELEASED;
 continue;

Index: src/sys/uvm/uvm_swap.h
diff -u src/sys/uvm/uvm_swap.h:1.26 src/sys/uvm/uvm_swap.h:1.27
--- src/sys/uvm/uvm_swap.h:1.26	Sat Sep  5 16:30:13 2020
+++ src/sys/uvm/uvm_swap.h	Fri Mar 15 07:09:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swap.h,v 1.26 2020/09/05 16:30:13 riastradh Exp $	*/
+/*	$NetBSD: uvm_swap.h,v 1.27 2024/03/15 07:09:37 andvar Exp $	*/
 
 /*
  * Copyright (c) 1997 Matthew R. Green
@@ -58,7 +58,7 @@ int	uvm_swap_stats(char *, int,
 
 #else /* defined(VMSWAP) */
 #define	uvm_swapisfull()	true
-#define uvm_swap_stats(c, l, f, count, retval) (__used f, *retval = 0, ENOSYS)
+#define uvm_swap_stats(c, l, f, count, retval) (void)(f), (*retval = 0, ENOSYS)
 #endif /* defined(VMSWAP) */
 
 void	uvm_swap_shutdown(struct lwp *);

Index: src/sys/uvm/uvm_swapstub.c
diff -u src/sys/uvm/uvm_swapstub.c:1.8 src/sys/uvm/uvm_swapstub.c:1.9
--- src/sys/uvm/uvm_swapstub.c:1.8	Tue Feb 18 06:18:13 2014
+++ src/sys/uvm/uvm_swapstub.c	Fri Mar 15 07:09:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_swapstub.c,v 1.8 2014/02/18 06:18:13 pooka Exp $	*/
+/*	$NetBSD: uvm_swapstub.c,v 1.9 2024/03/15 07:09:37 andvar Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_swapstub.c,v 1.8 2014/02/18 06:18:13 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swapstub.c,v 1.9 2024/03/15 07:09:37 andvar Exp $");
 
 #include 
 #include 
@@ -40,6 +40,9 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_swapstub
 
 #include 
 
+int (*uvm_swap_stats50)(const struct sys_swapctl_args *, register_t *) =
+(void *)enosys;
+
 void
 uvm_swap_init(void)
 {



CVS commit: src/sys/uvm

2024-03-15 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Mar 15 07:09:37 UTC 2024

Modified Files:
src/sys/uvm: uvm_fault.c uvm_pager.c uvm_swap.h uvm_swapstub.c

Log Message:
Fix !VMSWAP build:
Added __unused for few local variables, which are used in VMSWAP block only.
Adjust !VMSWAP uvm_swap_stats() definition to make it build with compat code.
Copied "int (*uvm_swap_stats50)(...)" definition from uvm_swap to uvm_swapstub
to avoid missing uvm_swap_stats50 reference on linking.

Fixes INSTALL_CPMBR1400, INSTALL_ZYXELKX evbmips kernel configs as a result.

Reviewed by simon and phone in IRC (thanks).


To generate a diff of this commit:
cvs rdiff -u -r1.236 -r1.237 src/sys/uvm/uvm_fault.c
cvs rdiff -u -r1.130 -r1.131 src/sys/uvm/uvm_pager.c
cvs rdiff -u -r1.26 -r1.27 src/sys/uvm/uvm_swap.h
cvs rdiff -u -r1.8 -r1.9 src/sys/uvm/uvm_swapstub.c

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