gpu: nvgpu: add checks as part of BVEC analysis

Add checks in common.utils unit as part of BVEC analysis.
The check in enabled.c makes sure that unauthorized memory access
is not performed and string.c is modified with a check to avoid
a possible invocation of BUG.

Jira NVGPU-6268

Change-Id: I672c9c54a2d7b61219dee1b249b9e1345381a965
Signed-off-by: ajesh <akv@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2494951
(cherry picked from commit 464e101b23b0143ff2e26e07659e34d1678dbf9d)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2497647
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: Ankur Kishore <ankkishore@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
GVS: Gerrit_Virtual_Submit
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
ajesh
2021-03-08 10:22:27 +03:00
committed by mobile promotions
parent 3c519157f5
commit e10f201602
2 changed files with 16 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2017-2021, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -89,11 +89,19 @@ void nvgpu_free_enabled_flags(struct gk20a *g)
bool nvgpu_is_enabled(struct gk20a *g, u32 flag)
{
return nvgpu_test_bit(flag, g->enabled_flags);
if (flag < NVGPU_MAX_ENABLED_BITS) {
return nvgpu_test_bit(flag, g->enabled_flags);
} else {
return 0;
}
}
void nvgpu_set_enabled(struct gk20a *g, u32 flag, bool state)
{
if (flag >= NVGPU_MAX_ENABLED_BITS) {
return;
}
if (state) {
nvgpu_set_bit(flag, g->enabled_flags);
} else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -47,6 +47,10 @@ int nvgpu_strnadd_u32(char *dst, const u32 value, size_t size, u32 radix)
return 0;
}
if (size > ((u64)(INT_MAX))) {
return 0;
}
/* how many digits do we need ? */
n = 0;
v = value;
@@ -56,7 +60,7 @@ int nvgpu_strnadd_u32(char *dst, const u32 value, size_t size, u32 radix)
} while (v > 0U);
/* bail out if there is not room for '\0' */
if (n >= nvgpu_safe_cast_u64_to_s32(size)) {
if (n >= (s32)size) {
return 0;
}