* [PATCH] drm/amdgpu: fix potential null dereference
@ 2022-03-02 5:47 Weiguo Li
0 siblings, 0 replies; 7+ messages in thread
From: Weiguo Li @ 2022-03-02 5:47 UTC (permalink / raw)
To: alexander.deucher; +Cc: amd-gfx
"ctx" is dereferenced but null checked later. Swap their positions
to avoid potential null dereference.
Found using a Coccinelle script:
https://coccinelle.gitlabpages.inria.fr/website/rules/mini_null_ref.cocci
Signed-off-by: Weiguo Li <liwg06@foxmail.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index f522b52725e4..b4f035ce44bc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -258,11 +258,12 @@ static void amdgpu_ctx_fini_entity(struct amdgpu_ctx_entity *entity)
static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
u32 *stable_pstate)
{
- struct amdgpu_device *adev = ctx->adev;
+ struct amdgpu_device *adev;
enum amd_dpm_forced_level current_level;
if (!ctx)
return -EINVAL;
+ adev = ctx->adev;
current_level = amdgpu_dpm_get_performance_level(adev);
@@ -289,12 +290,13 @@ static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx,
u32 stable_pstate)
{
- struct amdgpu_device *adev = ctx->adev;
+ struct amdgpu_device *adev;
enum amd_dpm_forced_level level;
int r;
if (!ctx)
return -EINVAL;
+ adev = ctx->adev;
mutex_lock(&adev->pm.stable_pstate_ctx_lock);
if (adev->pm.stable_pstate_ctx && adev->pm.stable_pstate_ctx != ctx) {
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] drm/amdgpu: Fix potential NULL dereference
2023-01-04 22:19 ` [PATCH] drm/amdgpu: Fix potential NULL dereference Luben Tuikov
@ 2023-01-05 9:15 ` Christian König
0 siblings, 0 replies; 7+ messages in thread
From: Christian König @ 2023-01-05 9:15 UTC (permalink / raw)
To: Luben Tuikov, AMD Graphics
Cc: Alex Deucher, Dan Carpenter, kernel test robot, Christian König
Am 04.01.23 um 23:19 schrieb Luben Tuikov:
> Fix potential NULL dereference, in the case when "man", the resource manager
> might be NULL, when/if we print debug information.
>
> Cc: Alex Deucher <Alexander.Deucher@amd.com>
> Cc: Christian König <christian.koenig@amd.com>
> Cc: AMD Graphics <amd-gfx@lists.freedesktop.org>
> Cc: Dan Carpenter <error27@gmail.com>
> Cc: kernel test robot <lkp@intel.com>
> Fixes: 7554886daa31ea ("drm/amdgpu: Fix size validation for non-exclusive domains (v4)")
> Signed-off-by: Luben Tuikov <luben.tuikov@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index af716afad9a59a..d1c90015651ba5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -470,8 +470,9 @@ static bool amdgpu_bo_validate_size(struct amdgpu_device *adev,
> return true;
>
> fail:
> - DRM_DEBUG("BO size %lu > total memory in domain: %llu\n", size,
> - man->size);
> + if (man)
> + DRM_DEBUG("BO size %lu > total memory in domain: %llu\n", size,
> + man->size);
> return false;
> }
>
>
> base-commit: b45d1c2754f5080acf2096ffcb17bcfeee7f5c2f
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] drm/amdgpu: Fix potential NULL dereference
2022-12-29 16:57 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c:473 amdgpu_bo_validate_size() error: we previously assumed 'man' could be null (see line 458) kernel test robot
@ 2023-01-04 22:19 ` Luben Tuikov
2023-01-05 9:15 ` Christian König
0 siblings, 1 reply; 7+ messages in thread
From: Luben Tuikov @ 2023-01-04 22:19 UTC (permalink / raw)
To: AMD Graphics
Cc: Alex Deucher, kernel test robot, Luben Tuikov,
Christian König, Dan Carpenter
Fix potential NULL dereference, in the case when "man", the resource manager
might be NULL, when/if we print debug information.
Cc: Alex Deucher <Alexander.Deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: AMD Graphics <amd-gfx@lists.freedesktop.org>
Cc: Dan Carpenter <error27@gmail.com>
Cc: kernel test robot <lkp@intel.com>
Fixes: 7554886daa31ea ("drm/amdgpu: Fix size validation for non-exclusive domains (v4)")
Signed-off-by: Luben Tuikov <luben.tuikov@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index af716afad9a59a..d1c90015651ba5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -470,8 +470,9 @@ static bool amdgpu_bo_validate_size(struct amdgpu_device *adev,
return true;
fail:
- DRM_DEBUG("BO size %lu > total memory in domain: %llu\n", size,
- man->size);
+ if (man)
+ DRM_DEBUG("BO size %lu > total memory in domain: %llu\n", size,
+ man->size);
return false;
}
base-commit: b45d1c2754f5080acf2096ffcb17bcfeee7f5c2f
--
2.39.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] drm/amdgpu: fix potential null dereference
2022-03-02 15:01 ` Christian König
@ 2022-03-02 15:39 ` Alex Deucher
0 siblings, 0 replies; 7+ messages in thread
From: Alex Deucher @ 2022-03-02 15:39 UTC (permalink / raw)
To: Christian König; +Cc: Weiguo Li, Deucher, Alexander, amd-gfx list
On Wed, Mar 2, 2022 at 10:01 AM Christian König
<ckoenig.leichtzumerken@gmail.com> wrote:
>
> Looks like my response never made it through.
>
> This change and the existing check is nonsense. The caller makes sure
> that ctx is never NULL here.
>
> So the check should probably just be dropped entirely.
agreed and dropped. Weiguo care to send a patch to drop the checks?
Alex
>
> Regards,
> Christian.
>
> Am 02.03.22 um 15:21 schrieb Alex Deucher:
> > Applied. Thanks!
> >
> > Alex
> >
> > On Wed, Mar 2, 2022 at 3:56 AM Weiguo Li <liwg06@foxmail.com> wrote:
> >> "ctx" is dereferenced but null checked later. Swap their positions
> >> to avoid potential null dereference.
> >>
> >> Found using a Coccinelle script:
> >> https://coccinelle.gitlabpages.inria.fr/website/rules/mini_null_ref.cocci
> >>
> >> Signed-off-by: Weiguo Li <liwg06@foxmail.com>
> >> ---
> >> drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 6 ++++--
> >> 1 file changed, 4 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> >> index f522b52725e4..b4f035ce44bc 100644
> >> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> >> @@ -258,11 +258,12 @@ static void amdgpu_ctx_fini_entity(struct amdgpu_ctx_entity *entity)
> >> static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
> >> u32 *stable_pstate)
> >> {
> >> - struct amdgpu_device *adev = ctx->adev;
> >> + struct amdgpu_device *adev;
> >> enum amd_dpm_forced_level current_level;
> >>
> >> if (!ctx)
> >> return -EINVAL;
> >> + adev = ctx->adev;
> >>
> >> current_level = amdgpu_dpm_get_performance_level(adev);
> >>
> >> @@ -289,12 +290,13 @@ static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
> >> static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx,
> >> u32 stable_pstate)
> >> {
> >> - struct amdgpu_device *adev = ctx->adev;
> >> + struct amdgpu_device *adev;
> >> enum amd_dpm_forced_level level;
> >> int r;
> >>
> >> if (!ctx)
> >> return -EINVAL;
> >> + adev = ctx->adev;
> >>
> >> mutex_lock(&adev->pm.stable_pstate_ctx_lock);
> >> if (adev->pm.stable_pstate_ctx && adev->pm.stable_pstate_ctx != ctx) {
> >> --
> >> 2.25.1
> >>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] drm/amdgpu: fix potential null dereference
2022-03-02 14:21 ` Alex Deucher
@ 2022-03-02 15:01 ` Christian König
2022-03-02 15:39 ` Alex Deucher
0 siblings, 1 reply; 7+ messages in thread
From: Christian König @ 2022-03-02 15:01 UTC (permalink / raw)
To: Alex Deucher, Weiguo Li; +Cc: Deucher, Alexander, amd-gfx list
Looks like my response never made it through.
This change and the existing check is nonsense. The caller makes sure
that ctx is never NULL here.
So the check should probably just be dropped entirely.
Regards,
Christian.
Am 02.03.22 um 15:21 schrieb Alex Deucher:
> Applied. Thanks!
>
> Alex
>
> On Wed, Mar 2, 2022 at 3:56 AM Weiguo Li <liwg06@foxmail.com> wrote:
>> "ctx" is dereferenced but null checked later. Swap their positions
>> to avoid potential null dereference.
>>
>> Found using a Coccinelle script:
>> https://coccinelle.gitlabpages.inria.fr/website/rules/mini_null_ref.cocci
>>
>> Signed-off-by: Weiguo Li <liwg06@foxmail.com>
>> ---
>> drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 6 ++++--
>> 1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> index f522b52725e4..b4f035ce44bc 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> @@ -258,11 +258,12 @@ static void amdgpu_ctx_fini_entity(struct amdgpu_ctx_entity *entity)
>> static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
>> u32 *stable_pstate)
>> {
>> - struct amdgpu_device *adev = ctx->adev;
>> + struct amdgpu_device *adev;
>> enum amd_dpm_forced_level current_level;
>>
>> if (!ctx)
>> return -EINVAL;
>> + adev = ctx->adev;
>>
>> current_level = amdgpu_dpm_get_performance_level(adev);
>>
>> @@ -289,12 +290,13 @@ static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
>> static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx,
>> u32 stable_pstate)
>> {
>> - struct amdgpu_device *adev = ctx->adev;
>> + struct amdgpu_device *adev;
>> enum amd_dpm_forced_level level;
>> int r;
>>
>> if (!ctx)
>> return -EINVAL;
>> + adev = ctx->adev;
>>
>> mutex_lock(&adev->pm.stable_pstate_ctx_lock);
>> if (adev->pm.stable_pstate_ctx && adev->pm.stable_pstate_ctx != ctx) {
>> --
>> 2.25.1
>>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] drm/amdgpu: fix potential null dereference
2022-03-02 4:35 [PATCH] drm/amdgpu: fix potential null dereference Weiguo Li
@ 2022-03-02 14:21 ` Alex Deucher
2022-03-02 15:01 ` Christian König
0 siblings, 1 reply; 7+ messages in thread
From: Alex Deucher @ 2022-03-02 14:21 UTC (permalink / raw)
To: Weiguo Li; +Cc: Deucher, Alexander, amd-gfx list
Applied. Thanks!
Alex
On Wed, Mar 2, 2022 at 3:56 AM Weiguo Li <liwg06@foxmail.com> wrote:
>
> "ctx" is dereferenced but null checked later. Swap their positions
> to avoid potential null dereference.
>
> Found using a Coccinelle script:
> https://coccinelle.gitlabpages.inria.fr/website/rules/mini_null_ref.cocci
>
> Signed-off-by: Weiguo Li <liwg06@foxmail.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> index f522b52725e4..b4f035ce44bc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> @@ -258,11 +258,12 @@ static void amdgpu_ctx_fini_entity(struct amdgpu_ctx_entity *entity)
> static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
> u32 *stable_pstate)
> {
> - struct amdgpu_device *adev = ctx->adev;
> + struct amdgpu_device *adev;
> enum amd_dpm_forced_level current_level;
>
> if (!ctx)
> return -EINVAL;
> + adev = ctx->adev;
>
> current_level = amdgpu_dpm_get_performance_level(adev);
>
> @@ -289,12 +290,13 @@ static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
> static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx,
> u32 stable_pstate)
> {
> - struct amdgpu_device *adev = ctx->adev;
> + struct amdgpu_device *adev;
> enum amd_dpm_forced_level level;
> int r;
>
> if (!ctx)
> return -EINVAL;
> + adev = ctx->adev;
>
> mutex_lock(&adev->pm.stable_pstate_ctx_lock);
> if (adev->pm.stable_pstate_ctx && adev->pm.stable_pstate_ctx != ctx) {
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] drm/amdgpu: fix potential null dereference
@ 2022-03-02 4:35 Weiguo Li
2022-03-02 14:21 ` Alex Deucher
0 siblings, 1 reply; 7+ messages in thread
From: Weiguo Li @ 2022-03-02 4:35 UTC (permalink / raw)
To: alexander.deucher; +Cc: amd-gfx
"ctx" is dereferenced but null checked later. Swap their positions
to avoid potential null dereference.
Found using a Coccinelle script:
https://coccinelle.gitlabpages.inria.fr/website/rules/mini_null_ref.cocci
Signed-off-by: Weiguo Li <liwg06@foxmail.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index f522b52725e4..b4f035ce44bc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -258,11 +258,12 @@ static void amdgpu_ctx_fini_entity(struct amdgpu_ctx_entity *entity)
static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
u32 *stable_pstate)
{
- struct amdgpu_device *adev = ctx->adev;
+ struct amdgpu_device *adev;
enum amd_dpm_forced_level current_level;
if (!ctx)
return -EINVAL;
+ adev = ctx->adev;
current_level = amdgpu_dpm_get_performance_level(adev);
@@ -289,12 +290,13 @@ static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx,
u32 stable_pstate)
{
- struct amdgpu_device *adev = ctx->adev;
+ struct amdgpu_device *adev;
enum amd_dpm_forced_level level;
int r;
if (!ctx)
return -EINVAL;
+ adev = ctx->adev;
mutex_lock(&adev->pm.stable_pstate_ctx_lock);
if (adev->pm.stable_pstate_ctx && adev->pm.stable_pstate_ctx != ctx) {
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-01-05 9:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-02 5:47 [PATCH] drm/amdgpu: fix potential null dereference Weiguo Li
-- strict thread matches above, loose matches on Subject: below --
2022-12-29 16:57 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c:473 amdgpu_bo_validate_size() error: we previously assumed 'man' could be null (see line 458) kernel test robot
2023-01-04 22:19 ` [PATCH] drm/amdgpu: Fix potential NULL dereference Luben Tuikov
2023-01-05 9:15 ` Christian König
2022-03-02 4:35 [PATCH] drm/amdgpu: fix potential null dereference Weiguo Li
2022-03-02 14:21 ` Alex Deucher
2022-03-02 15:01 ` Christian König
2022-03-02 15:39 ` Alex Deucher
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.