The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: Stepan Ionichev <sozdayvek@gmail.com>,
	Alexey Kardashevskiy <aik@amd.com>
Cc: john.allen@amd.com, herbert@gondor.apana.org.au,
	davem@davemloft.net, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org, ashish.kalra@amd.com
Subject: Re: [PATCH] crypto: ccp: sev-dev-tsm: bail out early when pdev->bus is NULL
Date: Thu, 7 May 2026 09:43:42 -0500	[thread overview]
Message-ID: <cd6b4e47-850b-4e65-b2b1-2b1d8bb08907@amd.com> (raw)
In-Reply-To: <20260507023619.398-1-sozdayvek@gmail.com>

On 5/6/26 21:36, Stepan Ionichev wrote:
> dsm_create() initially checks pdev->bus when computing segment_id:
> 
> 	u8 segment_id = pdev->bus ? pci_domain_nr(pdev->bus) : 0;
> 
> But the next two lines unconditionally dereference pdev->bus via
> pcie_find_root_port() and especially pci_dev_id(pdev), which expands
> to PCI_DEVID(dev->bus->number, dev->devfn). If pdev->bus is in fact
> NULL, segment_id is initialised to 0 but the very next statement
> crashes the kernel.
> 
> smatch flags this:
> 
>   drivers/crypto/ccp/sev-dev-tsm.c:253 dsm_create() error: we
>     previously assumed 'pdev->bus' could be null (see line 251)
> 
> Make the NULL handling consistent: if pdev->bus is NULL the device
> has no PCI context to work with and SEV TIO setup cannot proceed,
> so return -ENODEV before any of the bus-dependent lookups. The
> remaining initialisation now runs only on the path where pdev->bus
> is known to be valid.
> 
> No change for callers where pdev->bus is non-NULL, which is the
> only case where dsm_create() did meaningful work before this change.
> 
> Signed-off-by: Stepan Ionichev <sozdayvek@gmail.com>

This should have a Fixes: tag, which would have then added the main author
of the file to the email, so adding Alexey Kardashevskiy manually.

@Alexey, please also submit a patch to make yourself a maintainer of the
TIO/TSM support.

Thanks,
Tom

> ---
>  drivers/crypto/ccp/sev-dev-tsm.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/sev-dev-tsm.c b/drivers/crypto/ccp/sev-dev-tsm.c
> index b07ae529b..f303d8f55 100644
> --- a/drivers/crypto/ccp/sev-dev-tsm.c
> +++ b/drivers/crypto/ccp/sev-dev-tsm.c
> @@ -248,12 +248,19 @@ static void dsm_remove(struct pci_tsm *tsm)
>  static int dsm_create(struct tio_dsm *dsm)
>  {
>  	struct pci_dev *pdev = dsm->tsm.base_tsm.pdev;
> -	u8 segment_id = pdev->bus ? pci_domain_nr(pdev->bus) : 0;
> -	struct pci_dev *rootport = pcie_find_root_port(pdev);
> -	u16 device_id = pci_dev_id(pdev);
> +	struct pci_dev *rootport;
> +	u8 segment_id;
> +	u16 device_id;
>  	u16 root_port_id;
>  	u32 lnkcap = 0;
>  
> +	if (!pdev->bus)
> +		return -ENODEV;
> +
> +	segment_id = pci_domain_nr(pdev->bus);
> +	rootport = pcie_find_root_port(pdev);
> +	device_id = pci_dev_id(pdev);
> +
>  	if (pci_read_config_dword(rootport, pci_pcie_cap(rootport) + PCI_EXP_LNKCAP,
>  				  &lnkcap))
>  		return -ENODEV;


      parent reply	other threads:[~2026-05-07 14:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07  2:36 [PATCH] crypto: ccp: sev-dev-tsm: bail out early when pdev->bus is NULL Stepan Ionichev
2026-05-07 14:06 ` [PATCH v2] " Stepan Ionichev
2026-05-07 14:43 ` Tom Lendacky [this message]

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=cd6b4e47-850b-4e65-b2b1-2b1d8bb08907@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=aik@amd.com \
    --cc=ashish.kalra@amd.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=john.allen@amd.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sozdayvek@gmail.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