]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
scsi: dc395x: Fix a missing check on list iterator
authorXiaomeng Tong <xiam0nd.tong@gmail.com>
Thu, 14 Apr 2022 04:02:31 +0000 (12:02 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jun 2022 08:26:21 +0000 (10:26 +0200)
commit58e4cbaefe0adfbe69d2e70c37d1227e18c3e200
treebb44a5729bafc90000951c6946034e5e73ed86cd
parentefb54ec548829e1d3605f0434526f86e345b1b28
scsi: dc395x: Fix a missing check on list iterator

commit 036a45aa587a10fa2abbd50fbd0f6c4cfc44f69f upstream.

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: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/scsi/dc395x.c