* [PATCH 1/4] sandbox: include: <asm/types.h>: don't define INTERNAL_SIZE_T
@ 2020-07-06 6:28 Ahmad Fatoum
2020-07-06 6:28 ` [PATCH 2/4] sandbox: os: common: fix compiler warning in add_image() Ahmad Fatoum
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2020-07-06 6:28 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The INTERNAL_SIZE_T default is size_t, which already is 64-bit on 64-bit
platforms and 32-bit on 32-bit ones. We can thus drop the #define and go
back to the minimal <asm/types.h>.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/sandbox/include/asm/types.h | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/arch/sandbox/include/asm/types.h b/arch/sandbox/include/asm/types.h
index 28046670f4e2..7b356a99eb66 100644
--- a/arch/sandbox/include/asm/types.h
+++ b/arch/sandbox/include/asm/types.h
@@ -1,15 +1,6 @@
-#ifndef __ASM_I386_TYPES_H
-#define __ASM_I386_TYPES_H
+#ifndef __ASM_SANDBOX_TYPES_H
+#define __ASM_SANDBOX_TYPES_H
#include <asm-generic/int-ll64.h>
-#ifdef __x86_64__
-/*
- * This is used in dlmalloc. On X86_64 we need it to be
- * 64 bit
- */
-#define INTERNAL_SIZE_T unsigned long
-
-#endif
-
#endif
--
2.27.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/4] sandbox: os: common: fix compiler warning in add_image()
2020-07-06 6:28 [PATCH 1/4] sandbox: include: <asm/types.h>: don't define INTERNAL_SIZE_T Ahmad Fatoum
@ 2020-07-06 6:28 ` Ahmad Fatoum
2020-07-06 6:28 ` [PATCH 3/4] sandbox: add libc memory allocator Ahmad Fatoum
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2020-07-06 6:28 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
GCC reports:
./arch/sandbox/os/common.c: In function ‘add_image’:
./arch/sandbox/os/common.c:271:6: warning: cast to pointer from integer of
different size [-Wint-to-pointer-cast]
This is because hf->base is an unsigned long long, with the upper 32 bit
all-zeroes on 32-bit systems. The compiler doesn't see that though.
Change the cast, so we no longer warn.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/sandbox/os/common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 382a92304020..534571c0e668 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -268,7 +268,7 @@ static int add_image(char *str, char *devname_template, int *devname_number)
hf->base = (unsigned long)mmap(NULL, hf->size,
PROT_READ | (readonly ? 0 : PROT_WRITE),
MAP_SHARED, fd, 0);
- if ((void *)hf->base == MAP_FAILED)
+ if (hf->base == (unsigned long)MAP_FAILED)
printf("warning: mmapping %s failed: %s\n", filename, strerror(errno));
ret = barebox_register_filedev(hf);
--
2.27.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/4] sandbox: add libc memory allocator
2020-07-06 6:28 [PATCH 1/4] sandbox: include: <asm/types.h>: don't define INTERNAL_SIZE_T Ahmad Fatoum
2020-07-06 6:28 ` [PATCH 2/4] sandbox: os: common: fix compiler warning in add_image() Ahmad Fatoum
@ 2020-07-06 6:28 ` Ahmad Fatoum
2020-07-06 6:28 ` [PATCH 4/4] sandbox: reinstate cooked terminal mode on sanitizer-induced death Ahmad Fatoum
2020-07-11 4:34 ` [PATCH 1/4] sandbox: include: <asm/types.h>: don't define INTERNAL_SIZE_T Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2020-07-06 6:28 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
While we typically want to reuse as much barebox functionality as
possible in sandbox, using system malloc(3) instead can be very
useful when using external memory integrity tools. This is even
useful for AddressSanitizer, because the reports resulting from
the memory poisoning API are less detailed than the built-in
support for the libc malloc(3).
Note that a barebox "heap" is still allocated upfront. It's only
used for request_sdram_region now though. Whatever is allocated by
means of malloc and memalign will be ina disjunct heap.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/sandbox/Makefile | 1 +
arch/sandbox/os/Makefile | 1 +
arch/sandbox/os/libc_malloc.c | 36 +++++++++++++++++++++++++++++++++++
common/Kconfig | 7 +++++++
4 files changed, 45 insertions(+)
create mode 100644 arch/sandbox/os/libc_malloc.c
diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile
index c08ea0cf83e0..26b2465999b8 100644
--- a/arch/sandbox/Makefile
+++ b/arch/sandbox/Makefile
@@ -12,6 +12,7 @@ lds-y := $(BOARD)/barebox.lds
TEXT_BASE = $(CONFIG_TEXT_BASE)
KBUILD_CFLAGS += -Dmalloc=barebox_malloc -Dcalloc=barebox_calloc \
+ -Dmalloc_stats=barebox_malloc_stats -Dmemalign=barebox_memalign \
-Dfree=barebox_free -Drealloc=barebox_realloc \
-Dread=barebox_read -Dwrite=barebox_write \
-Dopen=barebox_open -Dclose=barebox_close \
diff --git a/arch/sandbox/os/Makefile b/arch/sandbox/os/Makefile
index b2f95087dcc4..1d32a197ead4 100644
--- a/arch/sandbox/os/Makefile
+++ b/arch/sandbox/os/Makefile
@@ -14,6 +14,7 @@ KBUILD_CFLAGS += -m32
endif
obj-y = common.o tap.o
+obj-$(CONFIG_MALLOC_LIBC) += libc_malloc.o
CFLAGS_sdl.o = $(shell pkg-config sdl --cflags)
obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o
diff --git a/arch/sandbox/os/libc_malloc.c b/arch/sandbox/os/libc_malloc.c
new file mode 100644
index 000000000000..74e3e2680585
--- /dev/null
+++ b/arch/sandbox/os/libc_malloc.c
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2020 Ahmad Fatoum <a.fatoum@pengutronix.de>
+ */
+
+#include <stdlib.h>
+#include <malloc.h>
+
+void barebox_malloc_stats(void)
+{
+}
+
+void *barebox_memalign(size_t alignment, size_t bytes)
+{
+ return memalign(alignment, bytes);
+}
+
+void *barebox_malloc(size_t size)
+{
+ return malloc(size);
+}
+
+void barebox_free(void *ptr)
+{
+ free(ptr);
+}
+
+void *barebox_realloc(void *ptr, size_t size)
+{
+ return realloc(ptr, size);
+}
+
+void *barebox_calloc(size_t n, size_t elem_size)
+{
+ return calloc(n, elem_size);
+}
diff --git a/common/Kconfig b/common/Kconfig
index 4bf8007c4247..658437f01c5e 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -312,6 +312,13 @@ config MALLOC_DUMMY
memory is never freed. This is suitable for well tested noninteractive
environments only.
+config MALLOC_LIBC
+ bool "libc malloc"
+ depends on SANDBOX
+ help
+ select this option to use the libc malloc implementation in the sandbox.
+ This is benefecial for testing with external memory integrity tools.
+
endchoice
config MODULES
--
2.27.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 4/4] sandbox: reinstate cooked terminal mode on sanitizer-induced death
2020-07-06 6:28 [PATCH 1/4] sandbox: include: <asm/types.h>: don't define INTERNAL_SIZE_T Ahmad Fatoum
2020-07-06 6:28 ` [PATCH 2/4] sandbox: os: common: fix compiler warning in add_image() Ahmad Fatoum
2020-07-06 6:28 ` [PATCH 3/4] sandbox: add libc memory allocator Ahmad Fatoum
@ 2020-07-06 6:28 ` Ahmad Fatoum
2020-07-11 4:34 ` [PATCH 1/4] sandbox: include: <asm/types.h>: don't define INTERNAL_SIZE_T Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2020-07-06 6:28 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
If we exit due to AddressSanitizer error, we remain in raw mode, which
is not best user experience. Currently every exit is an AddressSanitizer
death due to leaks. We want to encourage users to always have ASan
enabled, to catch more errors, thus call cookmode() on exit.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/sandbox/os/Makefile | 4 ++++
arch/sandbox/os/common.c | 6 ++++++
2 files changed, 10 insertions(+)
diff --git a/arch/sandbox/os/Makefile b/arch/sandbox/os/Makefile
index 1d32a197ead4..f307e6a828c1 100644
--- a/arch/sandbox/os/Makefile
+++ b/arch/sandbox/os/Makefile
@@ -6,6 +6,10 @@ KBUILD_CPPFLAGS = $(patsubst %,-I$(srctree)/%include,$(machdirs))
KBUILD_CPPFLAGS += -DCONFIG_MALLOC_SIZE=$(CONFIG_MALLOC_SIZE)
+ifeq ($(CONFIG_KASAN),y)
+KBUILD_CPPFLAGS += -DCONFIG_KASAN=1
+endif
+
KBUILD_CFLAGS := -Wall
NOSTDINC_FLAGS :=
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 534571c0e668..69fadb3b47a4 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -44,6 +44,8 @@
#include <mach/linux.h>
#include <mach/hostfile.h>
+void __sanitizer_set_death_callback(void (*callback)(void));
+
int sdl_xres;
int sdl_yres;
@@ -345,6 +347,10 @@ int main(int argc, char *argv[])
int fdno = 0, envno = 0, option_index = 0;
char *aux;
+#ifdef CONFIG_KASAN
+ __sanitizer_set_death_callback(cookmode);
+#endif
+
while (1) {
option_index = 0;
opt = getopt_long(argc, argv, optstring,
--
2.27.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/4] sandbox: include: <asm/types.h>: don't define INTERNAL_SIZE_T
2020-07-06 6:28 [PATCH 1/4] sandbox: include: <asm/types.h>: don't define INTERNAL_SIZE_T Ahmad Fatoum
` (2 preceding siblings ...)
2020-07-06 6:28 ` [PATCH 4/4] sandbox: reinstate cooked terminal mode on sanitizer-induced death Ahmad Fatoum
@ 2020-07-11 4:34 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2020-07-11 4:34 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Jul 06, 2020 at 08:28:03AM +0200, Ahmad Fatoum wrote:
> The INTERNAL_SIZE_T default is size_t, which already is 64-bit on 64-bit
> platforms and 32-bit on 32-bit ones. We can thus drop the #define and go
> back to the minimal <asm/types.h>.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> arch/sandbox/include/asm/types.h | 13 ++-----------
> 1 file changed, 2 insertions(+), 11 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/arch/sandbox/include/asm/types.h b/arch/sandbox/include/asm/types.h
> index 28046670f4e2..7b356a99eb66 100644
> --- a/arch/sandbox/include/asm/types.h
> +++ b/arch/sandbox/include/asm/types.h
> @@ -1,15 +1,6 @@
> -#ifndef __ASM_I386_TYPES_H
> -#define __ASM_I386_TYPES_H
> +#ifndef __ASM_SANDBOX_TYPES_H
> +#define __ASM_SANDBOX_TYPES_H
>
> #include <asm-generic/int-ll64.h>
>
> -#ifdef __x86_64__
> -/*
> - * This is used in dlmalloc. On X86_64 we need it to be
> - * 64 bit
> - */
> -#define INTERNAL_SIZE_T unsigned long
> -
> -#endif
> -
> #endif
> --
> 2.27.0
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-07-11 4:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-06 6:28 [PATCH 1/4] sandbox: include: <asm/types.h>: don't define INTERNAL_SIZE_T Ahmad Fatoum
2020-07-06 6:28 ` [PATCH 2/4] sandbox: os: common: fix compiler warning in add_image() Ahmad Fatoum
2020-07-06 6:28 ` [PATCH 3/4] sandbox: add libc memory allocator Ahmad Fatoum
2020-07-06 6:28 ` [PATCH 4/4] sandbox: reinstate cooked terminal mode on sanitizer-induced death Ahmad Fatoum
2020-07-11 4:34 ` [PATCH 1/4] sandbox: include: <asm/types.h>: don't define INTERNAL_SIZE_T Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox