From 55a8d6c86b4c6c6c707cfcc3dd887bca0632114f Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Fri, 16 Nov 2018 16:01:03 +0100 Subject: [PATCH] libdm: add memory barrier Just for case ensure compiler is not able to optimize memset() away for resources that are released. This idea of using memory barrier is taken from openssl. Other options would be to check for 'explicit_bzero' function. --- device_mapper/ioctl/libdm-iface.c | 2 ++ libdm/ioctl/libdm-iface.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/device_mapper/ioctl/libdm-iface.c b/device_mapper/ioctl/libdm-iface.c index 1321dc008..eb6e9dbf3 100644 --- a/device_mapper/ioctl/libdm-iface.c +++ b/device_mapper/ioctl/libdm-iface.c @@ -471,6 +471,7 @@ static void _dm_zfree_string(char *string) { if (string) { memset(string, 0, strlen(string)); + asm volatile ("" ::: "memory"); /* Compiler barrier. */ free(string); } } @@ -479,6 +480,7 @@ static void _dm_zfree_dmi(struct dm_ioctl *dmi) { if (dmi) { memset(dmi, 0, dmi->data_size); + asm volatile ("" ::: "memory"); /* Compiler barrier. */ free(dmi); } } diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c index 002669e8d..b195c115f 100644 --- a/libdm/ioctl/libdm-iface.c +++ b/libdm/ioctl/libdm-iface.c @@ -469,6 +469,7 @@ static void _dm_zfree_string(char *string) { if (string) { memset(string, 0, strlen(string)); + asm volatile ("" ::: "memory"); /* Compiler barrier. */ dm_free(string); } } @@ -477,6 +478,7 @@ static void _dm_zfree_dmi(struct dm_ioctl *dmi) { if (dmi) { memset(dmi, 0, dmi->data_size); + asm volatile ("" ::: "memory"); /* Compiler barrier. */ dm_free(dmi); } }