Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/rump/librump/rumpkern Return early on 0-sized transfers ...
details: https://anonhg.NetBSD.org/src/rev/d518a2a0755a
branches: trunk
changeset: 970875:d518a2a0755a
user: kamil <kamil%NetBSD.org@localhost>
date: Sun Apr 05 15:16:11 2020 +0000
description:
Return early on 0-sized transfers (usually to/from NULL-objects)
This logic is already present in subr_copy.c:copyin_vmspace() and
rumpcopy.c:copyinstr().
This avoids memcpy() calls for NULL objects that is Undefined Behavior,
allowed in the kernel space (-fno-delete-null-pointer-checks), but not
in userland.
Reported by UBSan.
diffstat:
sys/rump/librump/rumpkern/rumpcopy.c | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)
diffs (58 lines):
diff -r 227fd0369d00 -r d518a2a0755a sys/rump/librump/rumpkern/rumpcopy.c
--- a/sys/rump/librump/rumpkern/rumpcopy.c Sun Apr 05 14:53:39 2020 +0000
+++ b/sys/rump/librump/rumpkern/rumpcopy.c Sun Apr 05 15:16:11 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpcopy.c,v 1.23 2019/04/06 03:06:28 thorpej Exp $ */
+/* $NetBSD: rumpcopy.c,v 1.24 2020/04/05 15:16:11 kamil Exp $ */
/*
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rumpcopy.c,v 1.23 2019/04/06 03:06:28 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rumpcopy.c,v 1.24 2020/04/05 15:16:11 kamil Exp $");
#define __UFETCHSTORE_PRIVATE
#define __UCAS_PRIVATE
@@ -45,6 +45,9 @@
{
int error = 0;
+ if (len == 0)
+ return 0;
+
if (__predict_false(uaddr == NULL && len)) {
return EFAULT;
}
@@ -64,6 +67,9 @@
{
int error = 0;
+ if (len == 0)
+ return 0;
+
if (__predict_false(uaddr == NULL && len)) {
return EFAULT;
}
@@ -137,6 +143,9 @@
size_t slen;
int error;
+ if (len == 0)
+ return 0;
+
if (__predict_false(uaddr == NULL && len)) {
return EFAULT;
}
@@ -160,6 +169,9 @@
kcopy(const void *src, void *dst, size_t len)
{
+ if (len == 0)
+ return 0;
+
memcpy(dst, src, len);
return 0;
}
Home |
Main Index |
Thread Index |
Old Index