Skip to content

Commit

Permalink
random: unpoison buffer after arc4random_buf()
Browse files Browse the repository at this point in the history
MSAN does not realise that the iv buffer for aes256_cbc_fips() is in
fact initialized by this function call. This path and subsequent use of
the "uninitialised" value was hit when upgrading to Ubuntu 24.04 (which
ships a version of glibc that implements arc4random_buf()).
  • Loading branch information
LDVG committed Oct 7, 2024
1 parent 2ea6c02 commit 18e95da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
#include <unistd.h>
#endif

#if defined(__has_feature)
# if __has_feature(memory_sanitizer)
# include <sanitizer/msan_interface.h>
# define WITH_MSAN 1
# endif
#endif

#include "fido.h"

#if defined(_WIN32)
Expand Down Expand Up @@ -45,6 +52,9 @@ int
fido_get_random(void *buf, size_t len)
{
arc4random_buf(buf, len);
#ifdef WITH_MSAN
__msan_unpoison(buf, len); /* XXX */
#endif
return (0);
}
#elif defined(HAVE_GETRANDOM)
Expand Down
2 changes: 1 addition & 1 deletion src/u2f.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ u2f_get_touch_status(fido_dev_t *dev, int *touched, int *ms)
if ((reply_len = fido_rx(dev, CTAP_CMD_MSG, reply, FIDO_MAXMSG,
ms)) < 2) {
fido_log_debug("%s: fido_rx", __func__);
r = FIDO_OK; /* ignore */
r = *ms != 0 ? FIDO_OK : FIDO_ERR_INTERNAL; /* ignore */
goto out;
}

Expand Down

0 comments on commit 18e95da

Please sign in to comment.