All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gu, JiaWei (Will)" <JiaWei.Gu@amd.com>
To: Kees Cook <keescook@chromium.org>,
	"Deucher, Alexander" <Alexander.Deucher@amd.com>
Cc: "StDenis, Tom" <Tom.StDenis@amd.com>,
	"Deucher, Alexander" <Alexander.Deucher@amd.com>,
	"Christian König" <ckoenig.leichtzumerken@gmail.com>,
	"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
	"Nieto, David M" <David.Nieto@amd.com>,
	"linux-next@vger.kernel.org" <linux-next@vger.kernel.org>
Subject: RE: [PATCH] drm/amdgpu: Add vbios info ioctl interface
Date: Sat, 8 May 2021 06:01:23 +0000	[thread overview]
Message-ID: <BN9PR12MB51616B5E43086FC4CE2B58FFF8569@BN9PR12MB5161.namprd12.prod.outlook.com> (raw)
In-Reply-To: <202105072117.1480D10A@keescook>

[AMD Official Use Only - Internal Distribution Only]

Thanks for this catching Kees.

Yes it should be 20, not 16. I was not aware that serial size had been changed from 16 to 20 in struct amdgpu_device.
Will submit a fix soon.

Best regards,
Jiawei


-----Original Message-----
From: Kees Cook <keescook@chromium.org> 
Sent: Saturday, May 8, 2021 12:28 PM
To: Gu, JiaWei (Will) <JiaWei.Gu@amd.com>; Deucher, Alexander <Alexander.Deucher@amd.com>
Cc: StDenis, Tom <Tom.StDenis@amd.com>; Deucher, Alexander <Alexander.Deucher@amd.com>; Christian König <ckoenig.leichtzumerken@gmail.com>; Gu, JiaWei (Will) <JiaWei.Gu@amd.com>; amd-gfx@lists.freedesktop.org; Nieto, David M <David.Nieto@amd.com>; linux-next@vger.kernel.org
Subject: Re: [PATCH] drm/amdgpu: Add vbios info ioctl interface

Hi!

This patch needs some fixing.

On Thu, Apr 22, 2021 at 10:34:48AM +0800, Jiawei Gu wrote:
> +		case AMDGPU_INFO_VBIOS_INFO: {
> +			struct drm_amdgpu_info_vbios vbios_info = {};
> +			struct atom_context *atom_context;
> +
> +			atom_context = adev->mode_info.atom_context;
> +			memcpy(vbios_info.name, atom_context->name, sizeof(atom_context->name));
> +			vbios_info.dbdf = PCI_DEVID(adev->pdev->bus->number, adev->pdev->devfn);
> +			memcpy(vbios_info.vbios_pn, atom_context->vbios_pn, sizeof(atom_context->vbios_pn));
> +			vbios_info.version = atom_context->version;
> +			memcpy(vbios_info.date, atom_context->date, sizeof(atom_context->date));
> +			memcpy(vbios_info.serial, adev->serial, sizeof(adev->serial));

This writes beyond the end of vbios_info.serial.

> +			vbios_info.dev_id = adev->pdev->device;
> +			vbios_info.rev_id = adev->pdev->revision;
> +			vbios_info.sub_dev_id = atom_context->sub_dev_id;
> +			vbios_info.sub_ved_id = atom_context->sub_ved_id;

Though it gets "repaired" by these writes.

> +
> +			return copy_to_user(out, &vbios_info,
> +						min((size_t)size, sizeof(vbios_info))) ? -EFAULT : 0;
> +		}

sizeof(adev->serial) != sizeof(vbios_info.serial)

adev is struct amdgpu_device:

struct amdgpu_device {
...
        char                            serial[20];


> +struct drm_amdgpu_info_vbios {
> [...]
> +	__u8 serial[16];
> +	__u32 dev_id;
> +	__u32 rev_id;
> +	__u32 sub_dev_id;
> +	__u32 sub_ved_id;
> +};

Is there a truncation issue (20 vs 16) and is this intended to be a NUL-terminated string?

--
Kees Cook

WARNING: multiple messages have this Message-ID (diff)
From: "Gu, JiaWei (Will)" <JiaWei.Gu@amd.com>
To: Kees Cook <keescook@chromium.org>,
	"Deucher, Alexander" <Alexander.Deucher@amd.com>
Cc: "StDenis, Tom" <Tom.StDenis@amd.com>,
	"Christian König" <ckoenig.leichtzumerken@gmail.com>,
	"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
	"linux-next@vger.kernel.org" <linux-next@vger.kernel.org>,
	"Deucher, Alexander" <Alexander.Deucher@amd.com>,
	"Nieto, David M" <David.Nieto@amd.com>
Subject: RE: [PATCH] drm/amdgpu: Add vbios info ioctl interface
Date: Sat, 8 May 2021 06:01:23 +0000	[thread overview]
Message-ID: <BN9PR12MB51616B5E43086FC4CE2B58FFF8569@BN9PR12MB5161.namprd12.prod.outlook.com> (raw)
In-Reply-To: <202105072117.1480D10A@keescook>

[AMD Official Use Only - Internal Distribution Only]

Thanks for this catching Kees.

Yes it should be 20, not 16. I was not aware that serial size had been changed from 16 to 20 in struct amdgpu_device.
Will submit a fix soon.

Best regards,
Jiawei


-----Original Message-----
From: Kees Cook <keescook@chromium.org> 
Sent: Saturday, May 8, 2021 12:28 PM
To: Gu, JiaWei (Will) <JiaWei.Gu@amd.com>; Deucher, Alexander <Alexander.Deucher@amd.com>
Cc: StDenis, Tom <Tom.StDenis@amd.com>; Deucher, Alexander <Alexander.Deucher@amd.com>; Christian König <ckoenig.leichtzumerken@gmail.com>; Gu, JiaWei (Will) <JiaWei.Gu@amd.com>; amd-gfx@lists.freedesktop.org; Nieto, David M <David.Nieto@amd.com>; linux-next@vger.kernel.org
Subject: Re: [PATCH] drm/amdgpu: Add vbios info ioctl interface

Hi!

This patch needs some fixing.

On Thu, Apr 22, 2021 at 10:34:48AM +0800, Jiawei Gu wrote:
> +		case AMDGPU_INFO_VBIOS_INFO: {
> +			struct drm_amdgpu_info_vbios vbios_info = {};
> +			struct atom_context *atom_context;
> +
> +			atom_context = adev->mode_info.atom_context;
> +			memcpy(vbios_info.name, atom_context->name, sizeof(atom_context->name));
> +			vbios_info.dbdf = PCI_DEVID(adev->pdev->bus->number, adev->pdev->devfn);
> +			memcpy(vbios_info.vbios_pn, atom_context->vbios_pn, sizeof(atom_context->vbios_pn));
> +			vbios_info.version = atom_context->version;
> +			memcpy(vbios_info.date, atom_context->date, sizeof(atom_context->date));
> +			memcpy(vbios_info.serial, adev->serial, sizeof(adev->serial));

This writes beyond the end of vbios_info.serial.

> +			vbios_info.dev_id = adev->pdev->device;
> +			vbios_info.rev_id = adev->pdev->revision;
> +			vbios_info.sub_dev_id = atom_context->sub_dev_id;
> +			vbios_info.sub_ved_id = atom_context->sub_ved_id;

Though it gets "repaired" by these writes.

> +
> +			return copy_to_user(out, &vbios_info,
> +						min((size_t)size, sizeof(vbios_info))) ? -EFAULT : 0;
> +		}

sizeof(adev->serial) != sizeof(vbios_info.serial)

adev is struct amdgpu_device:

struct amdgpu_device {
...
        char                            serial[20];


> +struct drm_amdgpu_info_vbios {
> [...]
> +	__u8 serial[16];
> +	__u32 dev_id;
> +	__u32 rev_id;
> +	__u32 sub_dev_id;
> +	__u32 sub_ved_id;
> +};

Is there a truncation issue (20 vs 16) and is this intended to be a NUL-terminated string?

--
Kees Cook
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  reply	other threads:[~2021-05-08  6:01 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-22  2:34 [PATCH] drm/amdgpu: Add vbios info ioctl interface Jiawei Gu
2021-04-22 13:09 ` Gu, JiaWei (Will)
2021-04-22 13:18   ` Gu, JiaWei (Will)
2021-04-22 13:27     ` Christian König
2021-04-23  3:25       ` Gu, JiaWei (Will)
2021-04-28  6:47         ` Nieto, David M
2021-04-28  7:15           ` Christian König
2021-04-28  7:25             ` Nieto, David M
2021-04-28  7:42               ` Christian König
2021-04-28  8:21                 ` Gu, JiaWei (Will)
2021-04-28 10:38                   ` Gu, JiaWei (Will)
2021-04-28 11:30                     ` StDenis, Tom
2021-04-28 20:53                       ` Alex Deucher
2021-04-28 21:18                         ` StDenis, Tom
2021-05-08  4:28 ` Kees Cook
2021-05-08  4:28   ` Kees Cook
2021-05-08  6:01   ` Gu, JiaWei (Will) [this message]
2021-05-08  6:01     ` Gu, JiaWei (Will)
2021-05-08  9:51     ` Kees Cook
2021-05-08  9:51       ` Kees Cook
2021-05-09  5:35       ` Nieto, David M
  -- strict thread matches above, loose matches on Subject: below --
2021-05-20  2:58 Jiawei Gu
2021-05-20  3:24 ` Alex Deucher
2021-05-18 12:16 Jiawei Gu
2021-05-18 12:19 ` Gu, JiaWei (Will)
2021-05-18 13:17   ` Christian König
2021-05-18 13:25     ` StDenis, Tom
2021-05-19  2:41       ` Gu, JiaWei (Will)
2021-05-19  3:10         ` Marek Olšák
2021-05-17 12:08 Jiawei Gu
2021-05-17 12:17 ` Gu, JiaWei (Will)
2021-05-17 12:25   ` Christian König
2021-05-18  2:11     ` Gu, JiaWei (Will)
2021-05-18  2:44       ` Nieto, David M
2021-05-18  3:07         ` Gu, JiaWei (Will)
2021-05-18  4:40           ` Nieto, David M
2021-05-18  5:58             ` Gu, JiaWei (Will)
2021-05-18  7:23               ` Nieto, David M
2021-05-18 10:50               ` Lazar, Lijo
2021-05-19  3:17                 ` Nieto, David M
2021-05-19 13:09               ` Deucher, Alexander
2021-05-19 13:23                 ` Christian König
2021-05-20  1:30                   ` Gu, JiaWei (Will)
2021-05-20 10:58                     ` Christian König
2021-04-28  8:18 Jiawei Gu
2021-04-14  9:08 Jiawei Gu
2021-04-14 13:01 ` Alex Deucher

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=BN9PR12MB51616B5E43086FC4CE2B58FFF8569@BN9PR12MB5161.namprd12.prod.outlook.com \
    --to=jiawei.gu@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=David.Nieto@amd.com \
    --cc=Tom.StDenis@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=ckoenig.leichtzumerken@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-next@vger.kernel.org \
    /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 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.