提交 c11ab92c 编写于 作者: Z Zhou Qingyang 提交者: Zheng Zengkai

drm/nouveau/acr: Fix undefined behavior in nvkm_acr_hsfw_load_bl()

stable inclusion
from stable-v5.10.110
commit 9abee51534113368479bdb334472147f5a1780b1
bugzilla: https://gitee.com/openeuler/kernel/issues/I574AL

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

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

[ Upstream commit 2343bcdb ]

In nvkm_acr_hsfw_load_bl(), the return value of kmalloc() is directly
passed to memcpy(), which could lead to undefined behavior on failure
of kmalloc().

Fix this bug by using kmemdup() instead of kmalloc()+memcpy().

This bug was found by a static analyzer.

Builds with 'make allyesconfig' show no new warnings,
and our static analyzer no longer warns about this code.

Fixes: 22dcda45 ("drm/nouveau/acr: implement new subdev to replace "secure boot"")
Signed-off-by: NZhou Qingyang <zhou1615@umn.edu>
Reviewed-by: NLyude Paul <lyude@redhat.com>
Signed-off-by: NLyude Paul <lyude@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220124165856.57022-1-zhou1615@umn.eduSigned-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYu Liao <liaoyu15@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 1f52b2b9
...@@ -142,10 +142,11 @@ nvkm_acr_hsfw_load_bl(struct nvkm_acr *acr, const char *name, int ver, ...@@ -142,10 +142,11 @@ nvkm_acr_hsfw_load_bl(struct nvkm_acr *acr, const char *name, int ver,
hsfw->imem_size = desc->code_size; hsfw->imem_size = desc->code_size;
hsfw->imem_tag = desc->start_tag; hsfw->imem_tag = desc->start_tag;
hsfw->imem = kmalloc(desc->code_size, GFP_KERNEL); hsfw->imem = kmemdup(data + desc->code_off, desc->code_size, GFP_KERNEL);
memcpy(hsfw->imem, data + desc->code_off, desc->code_size);
nvkm_firmware_put(fw); nvkm_firmware_put(fw);
if (!hsfw->imem)
return -ENOMEM;
else
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册