scsi: libfc: safeguard against invalid exchange index

The cached exchange index might be invalid, in which case
we should drop down to allocate a new one.
And we should not try to access an invalid exchange when
responding to a BA_ABTS.

Signed-off-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
Hannes Reinecke 2016-10-13 15:10:49 +02:00 committed by Martin K. Petersen
parent 5d339d163a
commit b73aa56ee9
1 changed files with 14 additions and 7 deletions

View File

@ -827,15 +827,19 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
/* peek cache of free slot */ /* peek cache of free slot */
if (pool->left != FC_XID_UNKNOWN) { if (pool->left != FC_XID_UNKNOWN) {
if (!WARN_ON(fc_exch_ptr_get(pool, pool->left))) {
index = pool->left; index = pool->left;
pool->left = FC_XID_UNKNOWN; pool->left = FC_XID_UNKNOWN;
goto hit; goto hit;
} }
}
if (pool->right != FC_XID_UNKNOWN) { if (pool->right != FC_XID_UNKNOWN) {
if (!WARN_ON(fc_exch_ptr_get(pool, pool->right))) {
index = pool->right; index = pool->right;
pool->right = FC_XID_UNKNOWN; pool->right = FC_XID_UNKNOWN;
goto hit; goto hit;
} }
}
index = pool->next_index; index = pool->next_index;
/* allocate new exch from pool */ /* allocate new exch from pool */
@ -1782,7 +1786,10 @@ static void fc_exch_recv_bls(struct fc_exch_mgr *mp, struct fc_frame *fp)
fc_frame_free(fp); fc_frame_free(fp);
break; break;
case FC_RCTL_BA_ABTS: case FC_RCTL_BA_ABTS:
if (ep)
fc_exch_recv_abts(ep, fp); fc_exch_recv_abts(ep, fp);
else
fc_frame_free(fp);
break; break;
default: /* ignore junk */ default: /* ignore junk */
fc_frame_free(fp); fc_frame_free(fp);