Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
To: sashiko-reviews@lists.linux.dev
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v5 5/5] iommufd/vdevice: add TSM request ioctl
Date: Tue, 26 May 2026 13:48:50 +0530	[thread overview]
Message-ID: <yq5ase7eshw5.fsf@kernel.org> (raw)
In-Reply-To: <20260525221834.AD7021F000E9@smtp.kernel.org>

sashiko-bot@kernel.org writes:

> Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
> - [High] The ioctl handler incorrectly truncates the `ssize_t` residue from `tsm_guest_req()` to a 32-bit `int`, causing valid large positive residues to be misinterpreted as negative error codes.
> - [Medium] The `IOMMU_VDEVICE_TSM_REQ` ioctl omits the TSM implementation-specific result code (`tsm_code`), preventing userspace from forwarding it to the guest.
> - [Low] Manual initialization of `sockptr_t` bypasses kernel macros.
> --
>
> commit d5ee59b85809ac88694767fcc899de1ccc2821ca
> Author: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
>
> iommufd/vdevice: add TSM request ioctl
>
> This commit adds the IOMMU_VDEVICE_TSM_REQ ioctl to issue TSM guest
> request/response transactions against an iommufd vdevice. It forwards
> these requests through the new tsm_guest_req() helper to the PCI TSM
> backend, supporting CoCo guest device attestation.
>
>> diff --git a/drivers/iommu/iommufd/tsm.c b/drivers/iommu/iommufd/tsm.c
>> index 09ee668dbed9d..342fbdb6a6b95 100644
>> --- a/drivers/iommu/iommufd/tsm.c
>> +++ b/drivers/iommu/iommufd/tsm.c
> [ ... ]
>> +int iommufd_vdevice_tsm_req_ioctl(struct iommufd_ucmd *ucmd)
>> +{
>> +	int rc;
>
> [Severity: High]
> tsm_guest_req() returns an ssize_t representing the unconsumed byte residue,
> and the user-provided req_len and resp_len are __u32.
>
> If the residue is between 2GB and 4GB, could it overflow this 32-bit signed
> rc variable and become a negative value? This could cause the libc ioctl()
> wrapper to incorrectly treat a successful request as a failure.
>
> Would it be safer to return the residue by modifying a field in
> struct iommu_vdevice_tsm_req instead of returning unbounded positive values
> via the ioctl return code?
>

req_len and resp_len are both 32 bits.

>
>> +	struct iommufd_vdevice *vdev;
>> +	struct iommu_vdevice_tsm_req *cmd = ucmd->cmd;
>> +	struct tsm_guest_req_info info = {
>> +		.scope = cmd->scope,
>> +		.req   = {
>> +			.user = u64_to_user_ptr(cmd->req_uptr),
>> +			.is_kernel = false,
>> +		},
>
> [Severity: Low]
> Could this use the USER_SOCKPTR() macro to initialize the sockptr_t safely
> instead of manually setting .user and .is_kernel? Bypassing the macro makes
> this fragile against future layout changes in the sockptr_t structure.
>
>> +		.req_len = cmd->req_len,
>> +		.resp    =  {
>> +			.user = u64_to_user_ptr(cmd->resp_uptr),
>> +			.is_kernel = false,
>> +		},
>> +		.resp_len = cmd->resp_len,
>> +	};
> [ ... ]
>> diff --git a/drivers/virt/coco/tsm-core.c b/drivers/virt/coco/tsm-core.c
>> index 3870d08ffe0d1..c24886851f9e0 100644
>> --- a/drivers/virt/coco/tsm-core.c
>> +++ b/drivers/virt/coco/tsm-core.c
> [ ... ]
>> +ssize_t tsm_guest_req(struct device *dev, struct tsm_guest_req_info *info)
>> +{
>> +	int ret;
>> +	enum pci_tsm_req_scope pci_scope;
>> +
>> +	if (!dev_is_pci(dev))
>> +		return -EINVAL;
>> +
>> +	ret = tsm_pci_req_scope(info->scope, &pci_scope);
>> +	if (ret)
>> +		return ret;
>> +
>> +	return pci_tsm_guest_req(to_pci_dev(dev), pci_scope, info->req,
>> +				 info->req_len, info->resp, info->resp_len,
>> +				 NULL);
>
> [Severity: Medium]
> pci_tsm_guest_req() supports returning a TSM implementation-specific result
> code via the tsm_code parameter, but it is passed NULL here and omitted
> from struct iommu_vdevice_tsm_req.
>
> Do userspace VMMs need this architecture-specific result code to
> determine the outcome and failure reasons of attestation flows, and
> accurately emulate the hardware TSM interface for the guest?
>

Will update the iotcl to include tsm_code as part of the response. 

>
>> +}
>> +EXPORT_SYMBOL_GPL(tsm_guest_req);
>

-aneesh

  reply	other threads:[~2026-05-26  8:18 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-25 15:48 [PATCH v5 0/5] Add iommufd ioctls to support TSM operations Aneesh Kumar K.V (Arm)
2026-05-25 15:48 ` [PATCH v5 1/5] vfio: cache KVM VM file references instead of raw struct kvm pointers Aneesh Kumar K.V (Arm)
2026-05-25 16:47   ` sashiko-bot
2026-05-26  8:11     ` Aneesh Kumar K.V
2026-05-26 10:52   ` Anthony Krowiak
2026-05-25 15:48 ` [PATCH v5 2/5] iommufd/device: Associate KVM file pointer with iommufd_device Aneesh Kumar K.V (Arm)
2026-05-25 20:33   ` sashiko-bot
2026-05-26  8:17     ` Aneesh Kumar K.V
2026-05-25 15:48 ` [PATCH v5 3/5] iommufd/viommu: Keep a reference to the KVM file Aneesh Kumar K.V (Arm)
2026-05-25 15:48 ` [PATCH v5 4/5] iommufd/tsm: add vdevice TSM bind/unbind ioctl Aneesh Kumar K.V (Arm)
2026-05-25 21:44   ` sashiko-bot
2026-05-25 15:48 ` [PATCH v5 5/5] iommufd/vdevice: add TSM request ioctl Aneesh Kumar K.V (Arm)
2026-05-25 22:18   ` sashiko-bot
2026-05-26  8:18     ` Aneesh Kumar K.V [this message]
2026-05-27  0:16   ` Alexey Kardashevskiy
2026-05-27  6:17     ` Dan Williams (nvidia)
2026-05-27  6:56       ` Tian, Kevin
2026-05-27 12:51       ` Jason Gunthorpe
2026-05-27 15:34       ` Aneesh Kumar K.V
2026-05-27 17:49         ` Aneesh Kumar K.V
2026-05-27 22:49           ` Dan Williams (nvidia)
2026-06-02  5:10             ` Aneesh Kumar K.V
2026-06-02  8:40       ` Alexey Kardashevskiy

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=yq5ase7eshw5.fsf@kernel.org \
    --to=aneesh.kumar@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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