Skip to contentSkip to conversation

libuuid: use explicit_bzero() in uuid_clear() when possible

PATCH In review Sami Kerola 2 participants 4 messages Oct 16, 2017 – Oct 24, 2017 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libuuid: use explicit_bzero() in uuid_clear() when possible

This ensures value is blanked. It is possible compiler optimization removed earlier uuid_clear() calls as unnecessary if value was not used after clear.

---
 libuuid/src/clear.c | 4 ++++
 1 file changed, 4 insertions(+)
libuuid/src/clear.c +4 -0
index 2d91fee93..5b1392464 100644
@@ -38,6 +38,10 @@
 
 void uuid_clear(uuid_t uu)
 {
+#ifdef HAVE_EXPLICIT_BZERO
+	explicit_bzero(uu, 16);
+#else
 	memset(uu, 0, 16);
+#endif
 }
 
Signature · 1 line
2.14.2
#1 lore raw
Quoted 2 lines · Sami Kerola

This ensures value is blanked. It is possible compiler optimization removed earlier uuid_clear() calls as unnecessary if value was not used after clear.

Can you explain the logic behind this a bit more? If no one uses the uuid later it doesn't matter if we cleared it or not.

#2 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Sami Kerola

This ensures value is blanked. It is possible compiler optimization removed earlier uuid_clear() calls as unnecessary if value was not used after clear.

Can you explain the logic behind this a bit more? If no one uses the uuid later it doesn't matter if we cleared it or not.

When value is not used compiler might deside to remove such clearning altogether. To me uuid_clear() is promise that the value disappears, and that is what the function should do. Who knows, maybe someone uses uuids to something sensitive that must be cleared not to leak secrets. In that sort of context one really hopes promise of clearing is kept.

Signature · 2 lines
Sami Kerola
http://www.iki.fi/kerolasa/
#3 lore raw
Quoted 8 lines · Sami Kerola
Quoted 2 lines

Can you explain the logic behind this a bit more? If no one uses the uuid later it doesn't matter if we cleared it or not.

When value is not used compiler might deside to remove such clearning altogether. To me uuid_clear() is promise that the value disappears, and that is what the function should do. Who knows, maybe someone uses uuids to something sensitive that must be cleared not to leak secrets. In that sort of context one really hopes promise of clearing is kept.

That's not how uuid_clear is documented. From the man page:

NAME
uuid_clear - reset value of UUID variable to the NULL value

SYNOPSIS

       #include <uuid.h>

       void uuid_clear(uuid_t uu);

DESCRIPTION
The uuid_clear function sets the value of the supplied uuid variable uu to the NULL value.

If the variable isn't used it obviously must not be cleared.