提交 036a45aa 编写于 作者: X Xiaomeng Tong 提交者: Martin K. Petersen

scsi: dc395x: Fix a missing check on list iterator

The bug is here:

	p->target_id, p->target_lun);

The list iterator 'p' will point to a bogus position containing HEAD if the
list is empty or no element is found. This case must be checked before any
use of the iterator, otherwise it will lead to an invalid memory access.

To fix this bug, add a check. Use a new variable 'iter' as the list
iterator, and use the original variable 'p' as a dedicated pointer to point
to the found element.

Link: https://lore.kernel.org/r/20220414040231.2662-1-xiam0nd.tong@gmail.com
Fixes: 1da177e4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: NXiaomeng Tong <xiam0nd.tong@gmail.com>
Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
上级 505420bd
...@@ -3585,10 +3585,19 @@ static struct DeviceCtlBlk *device_alloc(struct AdapterCtlBlk *acb, ...@@ -3585,10 +3585,19 @@ static struct DeviceCtlBlk *device_alloc(struct AdapterCtlBlk *acb,
#endif #endif
if (dcb->target_lun != 0) { if (dcb->target_lun != 0) {
/* Copy settings */ /* Copy settings */
struct DeviceCtlBlk *p; struct DeviceCtlBlk *p = NULL, *iter;
list_for_each_entry(p, &acb->dcb_list, list)
if (p->target_id == dcb->target_id) list_for_each_entry(iter, &acb->dcb_list, list)
if (iter->target_id == dcb->target_id) {
p = iter;
break; break;
}
if (!p) {
kfree(dcb);
return NULL;
}
dprintkdbg(DBG_1, dprintkdbg(DBG_1,
"device_alloc: <%02i-%i> copy from <%02i-%i>\n", "device_alloc: <%02i-%i> copy from <%02i-%i>\n",
dcb->target_id, dcb->target_lun, dcb->target_id, dcb->target_lun,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册