1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

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.
This commit is contained in:
Zdenek Kabelac 2018-11-16 16:01:03 +01:00
parent 43f8da7699
commit 55a8d6c86b
2 changed files with 4 additions and 0 deletions

View File

@ -471,6 +471,7 @@ static void _dm_zfree_string(char *string)
{ {
if (string) { if (string) {
memset(string, 0, strlen(string)); memset(string, 0, strlen(string));
asm volatile ("" ::: "memory"); /* Compiler barrier. */
free(string); free(string);
} }
} }
@ -479,6 +480,7 @@ static void _dm_zfree_dmi(struct dm_ioctl *dmi)
{ {
if (dmi) { if (dmi) {
memset(dmi, 0, dmi->data_size); memset(dmi, 0, dmi->data_size);
asm volatile ("" ::: "memory"); /* Compiler barrier. */
free(dmi); free(dmi);
} }
} }

View File

@ -469,6 +469,7 @@ static void _dm_zfree_string(char *string)
{ {
if (string) { if (string) {
memset(string, 0, strlen(string)); memset(string, 0, strlen(string));
asm volatile ("" ::: "memory"); /* Compiler barrier. */
dm_free(string); dm_free(string);
} }
} }
@ -477,6 +478,7 @@ static void _dm_zfree_dmi(struct dm_ioctl *dmi)
{ {
if (dmi) { if (dmi) {
memset(dmi, 0, dmi->data_size); memset(dmi, 0, dmi->data_size);
asm volatile ("" ::: "memory"); /* Compiler barrier. */
dm_free(dmi); dm_free(dmi);
} }
} }