Linux IOMMU Development
 help / color / mirror / Atom feed
From: "Li,Rongqing" <lirongqing@baidu.com>
To: Ankit Soni <Ankit.Soni@amd.com>
Cc: Joerg Roedel <joro@8bytes.org>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: 答复: [????] Re: [PATCH] iommu/amd: Fix undefined behavior in devid_write debugfs function
Date: Tue, 21 Jul 2026 12:24:18 +0000	[thread overview]
Message-ID: <5cd2519944854cc0b3c5e5d509f378dc@baidu.com> (raw)
In-Reply-To: <sw4p7b4v5fhguzoxu7oxiy3tjtarcivzalr36cjn3e5okbngw5@zj3oaab3ctxt>



> 
> On Mon, Jun 01, 2026 at 08:12:40AM -0400, lirongqing wrote:
> > From: Li RongQing <lirongqing@baidu.com>
> >
> > When for_each_pci_segment() loop completes without finding a matching
> > segment, the pci_seg pointer is not NULL but points to an invalid
> > memory location (the list head). Accessing pci_seg->id after the loop
> > causes undefined behavior.
> >
> > Fix this by handling the successful case inside the loop and returning
> > -EINVAL after the loop if no matching segment is found.
> >
> > Fixes: 2e98940f123d9 ("iommu/amd: Add support for device id user
> > input")
> > Signed-off-by: Li RongQing <lirongqing@baidu.com>
> 
> Hi,
> 
> Thanks for the fix. Looks good to me.
> 
> Reviewed-by: Ankit Soni <Ankit.Soni@amd.com>
> 

Ping

[Li,Rongqing] 


> > ---
> >  drivers/iommu/amd/debugfs.c | 12 +++---------
> >  1 file changed, 3 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/iommu/amd/debugfs.c b/drivers/iommu/amd/debugfs.c
> > index 4c53b63..5c573ec 100644
> > --- a/drivers/iommu/amd/debugfs.c
> > +++ b/drivers/iommu/amd/debugfs.c
> > @@ -176,19 +176,13 @@ static ssize_t devid_write(struct file *filp, const
> char __user *ubuf,
> >  			kfree(srcid_ptr);
> >  			return -ENODEV;
> >  		}
> > -		break;
> > -	}
> > -
> > -	if (pci_seg->id != seg) {
> > +		sbdf = PCI_SEG_DEVID_TO_SBDF(seg, devid);
> >  		kfree(srcid_ptr);
> > -		return -EINVAL;
> > +		return cnt;
> >  	}
> >
> > -	sbdf = PCI_SEG_DEVID_TO_SBDF(seg, devid);
> > -
> >  	kfree(srcid_ptr);
> > -
> > -	return cnt;
> > +	return -EINVAL;
> >  }
> >
> >  static int devid_show(struct seq_file *m, void *unused)
> > --
> > 2.9.4
> >

  reply	other threads:[~2026-07-21 12:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01 12:12 [PATCH] iommu/amd: Fix undefined behavior in devid_write debugfs function lirongqing
2026-06-02  4:48 ` Ankit Soni
2026-07-21 12:24   ` Li,Rongqing [this message]
2026-07-22 21:39 ` Will Deacon

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=5cd2519944854cc0b3c5e5d509f378dc@baidu.com \
    --to=lirongqing@baidu.com \
    --cc=Ankit.Soni@amd.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=will@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox