iscsi_create_context: improve ISID randomness
The current random seed for determining a new context's ISID is calculated by XOR'ing time(), getpid() and "iscsi". When invoked from iscsi_reconnect(), all three inputs are likely to be identical, resulting on identical ISIDs. That happens because iscsi_reconnect() malloc()s a temporary "iscsi" which is then free()d at the end of the call. Successive calls to malloc() (from that function) are therefore likely to reuse the same address for the context. When multiple sessions are used for different LUNs of the same target, and reconnects happen within the same second (the precision given by time()), then multiple login attempts will happen with identical values, violating the ISID RULE as described in Section 3.4.3 of RFC3270. This fixes the issue by introducing a sequence number to the ISID seed generation. Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
This commit is contained in:
@@ -153,6 +153,7 @@ iscsi_create_context(const char *initiator_name)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
size_t required = ISCSI_RAW_HEADER_SIZE + ISCSI_DIGEST_SIZE;
|
||||
static uint32_t ctx_seq = 0;
|
||||
char *ca;
|
||||
|
||||
if (!initiator_name[0]) {
|
||||
@@ -176,7 +177,7 @@ iscsi_create_context(const char *initiator_name)
|
||||
|
||||
iscsi->fd = -1;
|
||||
|
||||
srand(time(NULL) ^ getpid() ^ (uint32_t) ((uintptr_t) iscsi));
|
||||
srand(time(NULL) ^ getpid() ^ (uint32_t) ((uintptr_t) iscsi) ^ ctx_seq++);
|
||||
|
||||
/* initialize to a "random" isid */
|
||||
iscsi_set_isid_random(iscsi, rand(), 0);
|
||||
|
||||
Reference in New Issue
Block a user