|
|
99cbc7 |
From f7a3585a8bee3d91b1cd57dabd4c2b506afef596 Mon Sep 17 00:00:00 2001
|
|
|
99cbc7 |
Message-Id: <f7a3585a8bee3d91b1cd57dabd4c2b506afef596@dist-git>
|
|
|
99cbc7 |
From: Michal Privoznik <mprivozn@redhat.com>
|
|
|
99cbc7 |
Date: Mon, 21 Jan 2019 09:04:10 -0500
|
|
|
99cbc7 |
Subject: [PATCH] util: Don't overflow in virRandomBits
|
|
|
99cbc7 |
MIME-Version: 1.0
|
|
|
99cbc7 |
Content-Type: text/plain; charset=UTF-8
|
|
|
99cbc7 |
Content-Transfer-Encoding: 8bit
|
|
|
99cbc7 |
|
|
|
99cbc7 |
https://bugzilla.redhat.com/show_bug.cgi?id=1667329 (RHEL 7.6.z)
|
|
|
99cbc7 |
https://bugzilla.redhat.com/show_bug.cgi?id=1652894 (RHEL 7.7)
|
|
|
99cbc7 |
|
|
|
99cbc7 |
The function is supposed to return up to 64bit long integer. In
|
|
|
99cbc7 |
order to do that it calls virRandomBytes() to fill the integer
|
|
|
99cbc7 |
with random bytes and then masks out everything but requested
|
|
|
99cbc7 |
bits. However, when doing that it shifts 1U and not 1ULL. So
|
|
|
99cbc7 |
effectively, requesting 32 random bis or more always return 0
|
|
|
99cbc7 |
which is not random enough.
|
|
|
99cbc7 |
|
|
|
99cbc7 |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
99cbc7 |
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
99cbc7 |
Reviewed-by: Pino Toscano <ptoscano@redhat.com>
|
|
|
99cbc7 |
(cherry picked from commit 78c47a92ecb450c9f8bcabd35da7006dc2547882)
|
|
|
99cbc7 |
Signed-off-by: John Ferlan <jferlan@redhat.com>
|
|
|
99cbc7 |
Message-Id: <20190121140412.27804-2-jferlan@redhat.com>
|
|
|
99cbc7 |
Reviewed-by: Erik Skultety <eskultet@redhat.com>
|
|
|
99cbc7 |
---
|
|
|
99cbc7 |
src/util/virrandom.c | 2 +-
|
|
|
99cbc7 |
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
99cbc7 |
|
|
|
99cbc7 |
diff --git a/src/util/virrandom.c b/src/util/virrandom.c
|
|
|
99cbc7 |
index 01cc82a052..3c011a8615 100644
|
|
|
99cbc7 |
--- a/src/util/virrandom.c
|
|
|
99cbc7 |
+++ b/src/util/virrandom.c
|
|
|
99cbc7 |
@@ -68,7 +68,7 @@ uint64_t virRandomBits(int nbits)
|
|
|
99cbc7 |
return 0;
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- ret &= (1U << nbits) - 1;
|
|
|
99cbc7 |
+ ret &= (1ULL << nbits) - 1;
|
|
|
99cbc7 |
return ret;
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
|
|
|
99cbc7 |
--
|
|
|
99cbc7 |
2.21.0
|
|
|
99cbc7 |
|