AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Su Hui <suhui@nfschina.com>,
	alexander.deucher@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com,
	daniel@ffwll.ch
Cc: yifan1.zhang@amd.com, guchun.chen@amd.com, lijo.lazar@amd.com,
	kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
	amd-gfx@lists.freedesktop.org, le.ma@amd.com,
	christophe.jaillet@wanadoo.fr, dri-devel@lists.freedesktop.org,
	Yuliang.Shi@amd.com, candice.li@amd.com, Hawking.Zhang@amd.com
Subject: Re: [PATCH v2] drm/amdgpu: Avoid possible buffer overflow
Date: Mon, 21 Aug 2023 11:31:30 +0200	[thread overview]
Message-ID: <2a4448cb-ac01-71fc-9335-68acdded0a78@amd.com> (raw)
In-Reply-To: <20230821073727.225341-1-suhui@nfschina.com>

Am 21.08.23 um 09:37 schrieb Su Hui:
> smatch error:
> drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c:1257 amdgpu_discovery_reg_base_init() error:
> testing array offset 'adev->vcn.num_vcn_inst' after use.
>
> change the assignment order to avoid buffer overflow.
>
> Fixes: c40bdfb2ffa4 ("drm/amdgpu: fix incorrect VCN revision in SRIOV")
> Signed-off-by: Su Hui <suhui@nfschina.com>
> ---
> changes in v2:
>   - fix the error about ip->revision (thanks to Christophe JAILLET).
>   drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> index 8e1cfc87122d..b07bfd106a9b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> @@ -1250,11 +1250,10 @@ static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev)
>   				 *     0b10 : encode is disabled
>   				 *     0b01 : decode is disabled
>   				 */
> -				adev->vcn.vcn_config[adev->vcn.num_vcn_inst] =
> -					ip->revision & 0xc0;
> -				ip->revision &= ~0xc0;
>   				if (adev->vcn.num_vcn_inst <
>   				    AMDGPU_MAX_VCN_INSTANCES) {
> +					adev->vcn.vcn_config[adev->vcn.num_vcn_inst] =
> +						ip->revision & 0xc0;
>   					adev->vcn.num_vcn_inst++;
>   					adev->vcn.inst_mask |=
>   						(1U << ip->instance_number);
> @@ -1265,6 +1264,7 @@ static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev)
>   						adev->vcn.num_vcn_inst + 1,
>   						AMDGPU_MAX_VCN_INSTANCES);
>   				}
> +				ip->revision &= ~0xc0;

That doesn't looks correct either. The assignment is intentionally 
outside of the "if".

See "adev->vcn.vcn_config[adev->vcn.num_vcn_inst] = ip->revision & 
0xc0;" is always valid.

We just avoid incrementing num_vcn_inst when we already have to many.

Regards,
Christian.


>   			}
>   			if (le16_to_cpu(ip->hw_id) == SDMA0_HWID ||
>   			    le16_to_cpu(ip->hw_id) == SDMA1_HWID ||


  reply	other threads:[~2023-08-21  9:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-21  7:37 [PATCH v2] drm/amdgpu: Avoid possible buffer overflow Su Hui
2023-08-21  9:31 ` Christian König [this message]
2023-08-22  1:39   ` Su Hui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2a4448cb-ac01-71fc-9335-68acdded0a78@amd.com \
    --to=christian.koenig@amd.com \
    --cc=Hawking.Zhang@amd.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=Yuliang.Shi@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=candice.li@amd.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=guchun.chen@amd.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=le.ma@amd.com \
    --cc=lijo.lazar@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=suhui@nfschina.com \
    --cc=yifan1.zhang@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox