From 673ff3585880ccacc53abaea01df027859ed5c1b Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Wed, 13 Mar 2019 14:44:36 +0800
Subject: [PATCH 14/17] 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.

(cherry picked from commit 55a8d6c86b4c6c6c707cfcc3dd887bca0632114f)

Conflicts:
    device_mapper/ioctl/libdm-iface.c
---
 libdm/ioctl/libdm-iface.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index 769b69c..7f48e37 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -466,6 +466,7 @@ static void _dm_zfree_string(char *string)
 {
 	if (string) {
 		memset(string, 0, strlen(string));
+		asm volatile ("" ::: "memory"); /* Compiler barrier. */
 		dm_free(string);
 	}
 }
@@ -474,6 +475,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);
 	}
 }
-- 
2.19.1

