gpu: nvgpu: fix CERT violations in nvgpu_dbg_gpu_access_gpu_va

Update nvgpu_dbg_gpu_access_gpu_va to:
1. Ensure that integer conversions do not result in lost or
   misinterpreted data.
2. Do not dereference null pointers.

CID 436748
CID 473585
CID 254272
CID 490303
Bug 3512546

Change-Id: I551484b671aa48175a8cea119885eac478c2731c
Signed-off-by: Sagar Kamble <skamble@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2707019
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
Reviewed-by: Sachin Nikam <snikam@nvidia.com>
GVS: Gerrit_Virtual_Submit
This commit is contained in:
Sagar Kamble
2022-05-04 14:09:02 +05:30
committed by mobile promotions
parent 9d6269ce7f
commit 45c6aed68d

View File

@@ -2623,10 +2623,11 @@ static int nvgpu_dbg_gpu_access_gpu_va(struct dbg_session_gk20a *dbg_s,
struct nvgpu_dbg_gpu_va_access_args *arg)
{
int ret = 0;
u32 i, buf_len;
size_t buf_len;
u32 i;
u8 cmd;
u64 *buffer = NULL;
u32 size, allocated_size = 0;
size_t size, allocated_size = 0;
void __user *user_buffer;
struct gk20a *g = dbg_s->g;
struct nvgpu_channel *ch;
@@ -2660,6 +2661,13 @@ static int nvgpu_dbg_gpu_access_gpu_va(struct dbg_session_gk20a *dbg_s,
cmd = arg->cmd;
for (i = 0; i < arg->count; i++) {
size = ops_buffer[i].size;
if (size == 0UL) {
nvgpu_err(g, "size is zero");
ret = -EINVAL;
goto fail;
}
if ((ops_buffer[i].gpu_va & 0x3)) {
nvgpu_err(g, "gpu va is not aligned %u 0x%llx", i,
ops_buffer[i].gpu_va);