CVS commit: src/common/lib/libc/misc

2019-11-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Nov  1 14:54:07 UTC 2019

Modified Files:
src/common/lib/libc/misc: ubsan.c

Log Message:
uubsan: Implement function_type_mismatch_v1

RTTI is not supported by micro-UBSan (by design) and this is now a stub
handler.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/common/lib/libc/misc/ubsan.c

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



CVS commit: src/common/lib/libc/misc

2019-11-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Nov  1 14:54:07 UTC 2019

Modified Files:
src/common/lib/libc/misc: ubsan.c

Log Message:
uubsan: Implement function_type_mismatch_v1

RTTI is not supported by micro-UBSan (by design) and this is now a stub
handler.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/common/lib/libc/misc/ubsan.c

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

Modified files:

Index: src/common/lib/libc/misc/ubsan.c
diff -u src/common/lib/libc/misc/ubsan.c:1.8 src/common/lib/libc/misc/ubsan.c:1.9
--- src/common/lib/libc/misc/ubsan.c:1.8	Wed Oct 30 00:13:46 2019
+++ src/common/lib/libc/misc/ubsan.c	Fri Nov  1 14:54:07 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ubsan.c,v 1.8 2019/10/30 00:13:46 kamil Exp $	*/
+/*	$NetBSD: ubsan.c,v 1.9 2019/11/01 14:54:07 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -38,9 +38,9 @@
 
 #include 
 #if defined(_KERNEL)
-__KERNEL_RCSID(0, "$NetBSD: ubsan.c,v 1.8 2019/10/30 00:13:46 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ubsan.c,v 1.9 2019/11/01 14:54:07 kamil Exp $");
 #else
-__RCSID("$NetBSD: ubsan.c,v 1.8 2019/10/30 00:13:46 kamil Exp $");
+__RCSID("$NetBSD: ubsan.c,v 1.9 2019/11/01 14:54:07 kamil Exp $");
 #endif
 
 #if defined(_KERNEL)
@@ -290,6 +290,8 @@ void __ubsan_handle_float_cast_overflow(
 void __ubsan_handle_float_cast_overflow_abort(struct CFloatCastOverflowData *pData, unsigned long ulFrom);
 void __ubsan_handle_function_type_mismatch(struct CFunctionTypeMismatchData *pData, unsigned long ulFunction);
 void __ubsan_handle_function_type_mismatch_abort(struct CFunctionTypeMismatchData *pData, unsigned long ulFunction);
+void __ubsan_handle_function_type_mismatch_v1(struct CFunctionTypeMismatchData *pData, unsigned long ulFunction, unsigned long ulCalleeRTTI, unsigned long ulFnRTTI);
+void __ubsan_handle_function_type_mismatch_v1_abort(struct CFunctionTypeMismatchData *pData, unsigned long ulFunction, unsigned long ulCalleeRTTI, unsigned long ulFnRTTI);
 void __ubsan_handle_invalid_builtin(struct CInvalidBuiltinData *pData);
 void __ubsan_handle_invalid_builtin_abort(struct CInvalidBuiltinData *pData);
 void __ubsan_handle_load_invalid_value(struct CInvalidValueData *pData, unsigned long ulVal);
@@ -838,7 +840,45 @@ __ubsan_handle_function_type_mismatch_ab
 
 	ASSERT(pData);
 
+	HandleFunctionTypeMismatch(true, pData, ulFunction);
+}
+
+void
+__ubsan_handle_function_type_mismatch_v1(struct CFunctionTypeMismatchData *pData, unsigned long ulFunction, unsigned long ulCalleeRTTI, unsigned long ulFnRTTI)
+{
+
+	ASSERT(pData);
+#if 0
+	/*
+	 * Unimplemented.
+	 *
+	 * This UBSan handler is special as the check has to be impelemented
+	 * in an implementation. In order to handle it there is need to
+	 * introspect into C++ ABI internals (RTTI) and use low-level
+	 * C++ runtime interfaces.
+	 */
+
 	HandleFunctionTypeMismatch(false, pData, ulFunction);
+#endif
+}
+
+void
+__ubsan_handle_function_type_mismatch_v1_abort(struct CFunctionTypeMismatchData *pData, unsigned long ulFunction, unsigned long ulCalleeRTTI, unsigned long ulFnRTTI)
+{
+
+	ASSERT(pData);
+#if 0
+	/*
+	 * Unimplemented.
+	 *
+	 * This UBSan handler is special as the check has to be impelemented
+	 * in an implementation. In order to handle it there is need to
+	 * introspect into C++ ABI internals (RTTI) and use low-level
+	 * C++ runtime interfaces.
+	 */
+
+	HandleFunctionTypeMismatch(true, pData, ulFunction);
+#endif
 }
 
 void



CVS commit: src/common/lib/libc/misc

2019-10-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Oct 30 00:13:46 UTC 2019

Modified Files:
src/common/lib/libc/misc: ubsan.c

Log Message:
uubsan: Handle implicit_conversion


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/common/lib/libc/misc/ubsan.c

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

Modified files:

Index: src/common/lib/libc/misc/ubsan.c
diff -u src/common/lib/libc/misc/ubsan.c:1.7 src/common/lib/libc/misc/ubsan.c:1.8
--- src/common/lib/libc/misc/ubsan.c:1.7	Fri Oct  4 12:12:47 2019
+++ src/common/lib/libc/misc/ubsan.c	Wed Oct 30 00:13:46 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ubsan.c,v 1.7 2019/10/04 12:12:47 mrg Exp $	*/
+/*	$NetBSD: ubsan.c,v 1.8 2019/10/30 00:13:46 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -38,9 +38,9 @@
 
 #include 
 #if defined(_KERNEL)
-__KERNEL_RCSID(0, "$NetBSD: ubsan.c,v 1.7 2019/10/04 12:12:47 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ubsan.c,v 1.8 2019/10/30 00:13:46 kamil Exp $");
 #else
-__RCSID("$NetBSD: ubsan.c,v 1.7 2019/10/04 12:12:47 mrg Exp $");
+__RCSID("$NetBSD: ubsan.c,v 1.8 2019/10/30 00:13:46 kamil Exp $");
 #endif
 
 #if defined(_KERNEL)
@@ -238,6 +238,13 @@ struct CFloatCastOverflowData {
 	struct CTypeDescriptor *mToType;
 };
 
+struct CImplicitConversionData {
+	struct CSourceLocation mLocation;
+	struct CTypeDescriptor *mFromType;
+	struct CTypeDescriptor *mToType;
+	uint8_t mKind;
+};
+
 /* Local utility functions */
 static void Report(bool isFatal, const char *pFormat, ...) __printflike(2, 3);
 static bool isAlreadyReported(struct CSourceLocation *pLocation);
@@ -261,6 +268,7 @@ static void DeserializeNumber(char *szLo
 static const char *DeserializeTypeCheckKind(uint8_t hhuTypeCheckKind);
 static const char *DeserializeBuiltinCheckKind(uint8_t hhuBuiltinCheckKind);
 static const char *DeserializeCFICheckKind(uint8_t hhuCFICheckKind);
+static const char *DeserializeImplicitConversionCheckKind(uint8_t hhuImplicitConversionCheckKind);
 static bool isNegativeNumber(char *szLocation, struct CTypeDescriptor *pType, unsigned long ulNumber);
 static bool isShiftExponentTooLarge(char *szLocation, struct CTypeDescriptor *pType, unsigned long ulNumber, size_t zWidth);
 
@@ -313,6 +321,8 @@ void __ubsan_handle_type_mismatch_v1(str
 void __ubsan_handle_type_mismatch_v1_abort(struct CTypeMismatchData_v1 *pData, unsigned long ulPointer);
 void __ubsan_handle_vla_bound_not_positive(struct CVLABoundData *pData, unsigned long ulBound);
 void __ubsan_handle_vla_bound_not_positive_abort(struct CVLABoundData *pData, unsigned long ulBound);
+void __ubsan_handle_implicit_conversion(struct CImplicitConversionData *pData, unsigned long ulFrom, unsigned long ulTo);
+void __ubsan_handle_implicit_conversion_abort(struct CImplicitConversionData *pData, unsigned long ulFrom, unsigned long ulTo);
 void __ubsan_get_current_report_data(const char **ppOutIssueKind, const char **ppOutMessage, const char **ppOutFilename, uint32_t *pOutLine, uint32_t *pOutCol, char **ppOutMemoryAddr);
 
 static void HandleOverflow(bool isFatal, struct COverflowData *pData, unsigned long ulLHS, unsigned long ulRHS, const char *szOperation);
@@ -684,6 +694,26 @@ HandlePointerOverflow(bool isFatal, stru
 	   szLocation, ulBase, ulResult);
 }
 
+static void
+HandleImplicitConversion(bool isFatal, struct CImplicitConversionData *pData, unsigned long ulFrom, unsigned long ulTo)
+{
+	char szLocation[LOCATION_MAXLEN];
+	char szFrom[NUMBER_MAXLEN];
+	char szTo[NUMBER_MAXLEN];
+
+	ASSERT(pData);
+
+	if (isAlreadyReported(>mLocation))
+		return;
+
+	DeserializeLocation(szLocation, LOCATION_MAXLEN, >mLocation);
+	DeserializeNumber(szLocation, szFrom, NUMBER_MAXLEN, pData->mFromType, ulFrom);
+	DeserializeNumber(szLocation, szTo, NUMBER_MAXLEN, pData->mToType, ulTo);
+
+	Report(isFatal, "UBSan: Undefined Behavior in %s, %s from %s %zu-bit %s (%s) to %s changed the value to %s %zu-bit %s\n",
+	   szLocation, DeserializeImplicitConversionCheckKind(pData->mKind), szFrom, zDeserializeTypeWidth(pData->mFromType), ISSET(pData->mFromType->mTypeInfo, NUMBER_SIGNED_BIT) ? "signed" : "unsigned", pData->mFromType->mTypeName, pData->mToType->mTypeName, szTo, zDeserializeTypeWidth(pData->mToType), ISSET(pData->mToType->mTypeInfo, NUMBER_SIGNED_BIT) ? "signed" : "unsigned");
+}
+
 /* Definions of public symbols emitted by the instrumentation code */
 void
 __ubsan_handle_add_overflow(struct COverflowData *pData, unsigned long ulLHS, unsigned long ulRHS)
@@ -1095,6 +1125,23 @@ __ubsan_handle_vla_bound_not_positive_ab
 }
 
 void
+__ubsan_handle_implicit_conversion(struct CImplicitConversionData *pData, unsigned long ulFrom, unsigned long ulTo)
+{
+
+	ASSERT(pData);
+
+	HandleImplicitConversion(false, pData, ulFrom, ulTo);
+}
+
+void
+__ubsan_handle_implicit_conversion_abort(struct CImplicitConversionData *pData, unsigned long ulFrom, unsigned long ulTo)
+{
+	ASSERT(pData);
+
+	

CVS commit: src/common/lib/libc/misc

2019-10-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Oct 30 00:13:46 UTC 2019

Modified Files:
src/common/lib/libc/misc: ubsan.c

Log Message:
uubsan: Handle implicit_conversion


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/common/lib/libc/misc/ubsan.c

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



CVS commit: src/common/lib/libc/misc

2019-10-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Oct  4 12:12:47 UTC 2019

Modified Files:
src/common/lib/libc/misc: ubsan.c

Log Message:
workaround a GCC 8 warning:

- code that will be unreachable on platforms with
  sizeof(double) != sizeof(unsigned long) triggered an valid out
  of bounds warning.  avoid the error by using sizeof ul.
- also assert that the sizes are the same if entering here.

both from kamil@.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/common/lib/libc/misc/ubsan.c

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



CVS commit: src/common/lib/libc/misc

2019-10-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Oct  4 12:12:47 UTC 2019

Modified Files:
src/common/lib/libc/misc: ubsan.c

Log Message:
workaround a GCC 8 warning:

- code that will be unreachable on platforms with
  sizeof(double) != sizeof(unsigned long) triggered an valid out
  of bounds warning.  avoid the error by using sizeof ul.
- also assert that the sizes are the same if entering here.

both from kamil@.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/common/lib/libc/misc/ubsan.c

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

Modified files:

Index: src/common/lib/libc/misc/ubsan.c
diff -u src/common/lib/libc/misc/ubsan.c:1.6 src/common/lib/libc/misc/ubsan.c:1.7
--- src/common/lib/libc/misc/ubsan.c:1.6	Mon Jun 17 18:55:37 2019
+++ src/common/lib/libc/misc/ubsan.c	Fri Oct  4 12:12:47 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ubsan.c,v 1.6 2019/06/17 18:55:37 kamil Exp $	*/
+/*	$NetBSD: ubsan.c,v 1.7 2019/10/04 12:12:47 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -38,9 +38,9 @@
 
 #include 
 #if defined(_KERNEL)
-__KERNEL_RCSID(0, "$NetBSD: ubsan.c,v 1.6 2019/06/17 18:55:37 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ubsan.c,v 1.7 2019/10/04 12:12:47 mrg Exp $");
 #else
-__RCSID("$NetBSD: ubsan.c,v 1.6 2019/06/17 18:55:37 kamil Exp $");
+__RCSID("$NetBSD: ubsan.c,v 1.7 2019/10/04 12:12:47 mrg Exp $");
 #endif
 
 #if defined(_KERNEL)
@@ -1403,7 +1403,8 @@ DeserializeFloatInlined(char *pBuffer, s
 
 	switch (zDeserializeTypeWidth(pType)) {
 	case WIDTH_64:
-		memcpy(, , sizeof(double));
+		ASSERT(sizeof(D) == sizeof(ulNumber));
+		memcpy(, , sizeof(ulNumber));
 		snprintf(pBuffer, zBUfferLength, "%g", D);
 		break;
 	case WIDTH_32:



CVS commit: src/common/lib/libc/misc

2019-06-17 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Jun 17 18:55:37 UTC 2019

Modified Files:
src/common/lib/libc/misc: ubsan.c

Log Message:
Introduce UBSAN_ALWAYS_FATAL in micro-UBSan

UBSAN_ALWAYS_FATAL is a CPP option to mark all reports fatal always.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/common/lib/libc/misc/ubsan.c

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

Modified files:

Index: src/common/lib/libc/misc/ubsan.c
diff -u src/common/lib/libc/misc/ubsan.c:1.5 src/common/lib/libc/misc/ubsan.c:1.6
--- src/common/lib/libc/misc/ubsan.c:1.5	Wed Feb 13 17:17:02 2019
+++ src/common/lib/libc/misc/ubsan.c	Mon Jun 17 18:55:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ubsan.c,v 1.5 2019/02/13 17:17:02 kamil Exp $	*/
+/*	$NetBSD: ubsan.c,v 1.6 2019/06/17 18:55:37 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -38,9 +38,9 @@
 
 #include 
 #if defined(_KERNEL)
-__KERNEL_RCSID(0, "$NetBSD: ubsan.c,v 1.5 2019/02/13 17:17:02 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ubsan.c,v 1.6 2019/06/17 18:55:37 kamil Exp $");
 #else
-__RCSID("$NetBSD: ubsan.c,v 1.5 2019/02/13 17:17:02 kamil Exp $");
+__RCSID("$NetBSD: ubsan.c,v 1.6 2019/06/17 18:55:37 kamil Exp $");
 #endif
 
 #if defined(_KERNEL)
@@ -79,6 +79,12 @@ __RCSID("$NetBSD: ubsan.c,v 1.5 2019/02/
 #define CLR(t, f)	((t) &= ~(f))
 #endif
 
+#ifdef UBSAN_ALWAYS_FATAL
+static const bool alwaysFatal = true;
+#else
+static const bool alwaysFatal = false;
+#endif
+
 #define REINTERPRET_CAST(__dt, __st)	((__dt)(__st))
 #define STATIC_CAST(__dt, __st)		((__dt)(__st))
 
@@ -1122,7 +1128,7 @@ Report(bool isFatal, const char *pFormat
 
 	va_start(ap, pFormat);
 #if defined(_KERNEL)
-	if (isFatal)
+	if (isFatal || alwaysFatal)
 		vpanic(pFormat, ap);
 	else
 		vprintf(pFormat, ap);
@@ -1190,7 +1196,7 @@ Report(bool isFatal, const char *pFormat
 		ubsan_vsyslog(LOG_DEBUG | LOG_USER, , pFormat, tmp);
 		va_end(tmp);
 	}
-	if (isFatal || ISSET(ubsan_flags, UBSAN_ABORT)) {
+	if (isFatal || alwaysFatal || ISSET(ubsan_flags, UBSAN_ABORT)) {
 		abort();
 		__unreachable();
 		/* NOTREACHED */



CVS commit: src/common/lib/libc/misc

2019-06-17 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Jun 17 18:55:37 UTC 2019

Modified Files:
src/common/lib/libc/misc: ubsan.c

Log Message:
Introduce UBSAN_ALWAYS_FATAL in micro-UBSan

UBSAN_ALWAYS_FATAL is a CPP option to mark all reports fatal always.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/common/lib/libc/misc/ubsan.c

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



Re: ubsan.c (was: CVS commit: src/common/lib/libc/misc)

2018-08-02 Thread Kamil Rytarowski
On 03.08.2018 04:48, Paul Goyette wrote:
> If there are no licensing issues or concerns, then please describe the
> real reason(s) for avoiding KNF.
> 
> 

As discussed, we have removed the comment and drop the unnecessary part
from CVS log.




signature.asc
Description: OpenPGP digital signature


Re: ubsan.c (was: CVS commit: src/common/lib/libc/misc)

2018-08-02 Thread Paul Goyette

Module Name:src
Committed By:   kamil
Date:   Fri Aug  3 02:05:43 UTC 2018

Added Files:
src/common/lib/libc/misc: ubsan.c

Log Message:
Import micro-UBSan (ubsan.c)





This file does not follow the regular KNF style, due to potential 
licensing concerns.


If there are potential licensing issues, they should be discussed first, 
before the potentially offending code is committed.  Avoiding KNF (nor 
any other sort of reformatting) is not going to avoid a license issue.


If there are no licensing issues or concerns, then please describe the 
real reason(s) for avoiding KNF.




+--+--++
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:  |
| (Retired)| FA29 0E3B 35AF E8AE 6651 | paul at whooppee dot com   |
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd dot org |
+--+--++