Skip to content

Commit 29d1cf1

Browse files
committed
Check return value of uk_random_bytes()
lwip provides the LWIP_RAND() macro to obtain random numbers for purposes like TCP ISNs, source port selection, IP fragment IDs, etc The default implementation implements the macro using rand(), which is implements a pseudo-rng. Furthermore, the macro assumes no error checking. Unikraft's implementation uses libukarandom's uk_random_bytes() to provide secure randomness. That function may fail on reseed, so it's is critical to check its return value. Add a check within the macro, and treat failures as fatal. Signed-off-by: Michalis Pappas <[email protected]> Approved-by: Andrei Tatar <[email protected]> Reviewed-by: Andrei Tatar <[email protected]> GitHub-Closes: #68
1 parent 82a9126 commit 29d1cf1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

include/arch/cc.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@
5959
#define ETH_PAD_SIZE 0
6060

6161
/* rand */
62-
#define LWIP_RAND() ({ \
63-
__u32 x; \
64-
uk_random_fill_buffer(&x, sizeof(x)); \
65-
x; \
62+
#define LWIP_RAND() ({ \
63+
int res; \
64+
__u32 x; \
65+
res = uk_random_fill_buffer(&x, sizeof(x)); \
66+
if (unlikely(res)) \
67+
UK_CRASH("Could not obtain randomness (%d)", \
68+
res); \
69+
x; \
6670
})
6771

6872
/* compiler hints for packing lwip's structures */

0 commit comments

Comments
 (0)