提交 1bb176cd 编写于 作者: S Sergey Shtylyov 提交者: Zheng Zengkai

ata: libata-core: fix NULL pointer deref in ata_host_alloc_pinfo()

stable inclusion
from stable-v5.10.124
commit 36cd19e7d4e5571d77a2ed20c5b6ef50cf57734a
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5L6E7

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=36cd19e7d4e5571d77a2ed20c5b6ef50cf57734a

--------------------------------

[ Upstream commit bf476fe2 ]

In an unlikely (and probably wrong?) case that the 'ppi' parameter of
ata_host_alloc_pinfo() points to an array starting with a NULL pointer,
there's going to be a kernel oops as the 'pi' local variable won't get
reassigned from the initial value of NULL. Initialize 'pi' instead to
'&ata_dummy_port_info' to fix the possible kernel oops for good...

Found by Linux Verification Center (linuxtesting.org) with the SVACE static
analysis tool.
Signed-off-by: NSergey Shtylyov <s.shtylyov@omp.ru>
Signed-off-by: NDamien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
上级 3f89aebb
...@@ -5475,7 +5475,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev, ...@@ -5475,7 +5475,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev,
const struct ata_port_info * const * ppi, const struct ata_port_info * const * ppi,
int n_ports) int n_ports)
{ {
const struct ata_port_info *pi; const struct ata_port_info *pi = &ata_dummy_port_info;
struct ata_host *host; struct ata_host *host;
int i, j; int i, j;
...@@ -5483,7 +5483,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev, ...@@ -5483,7 +5483,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev,
if (!host) if (!host)
return NULL; return NULL;
for (i = 0, j = 0, pi = NULL; i < host->n_ports; i++) { for (i = 0, j = 0; i < host->n_ports; i++) {
struct ata_port *ap = host->ports[i]; struct ata_port *ap = host->ports[i];
if (ppi[j]) if (ppi[j])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册