All of lore.kernel.org
 help / color / mirror / Atom feed
From: Breno Leitao <leitao@debian.org>
To: Alison Schofield <alison.schofield@intel.com>
Cc: vishal.l.verma@intel.com, ira.weiny@intel.com,
	bwidawsk@kernel.org, dan.j.williams@intel.com,
	linux-cxl@vger.kernel.org, ave.jiang@intel.com
Subject: Re: [PATCH v2] cxl/acpi: Release device after dev_err()
Date: Wed, 12 Jul 2023 07:24:56 -0700	[thread overview]
Message-ID: <ZK63uG6WkBJC/5+l@gmail.com> (raw)
In-Reply-To: <ZK2W50voY8augr8m@aschofie-mobl2>

Hello Alison,

On Tue, Jul 11, 2023 at 10:52:39AM -0700, Alison Schofield wrote:
> On Tue, Jul 11, 2023 at 09:17:04AM -0700, Breno Leitao wrote:
> > Kfence detected an user-after-free in the CXL driver. This happens in
> > the cxl_decoder_add() fail path. Kfence drops this message:
> > 
> >   BUG: KFENCE: use-after-free read in resource_string
> > 
> > This is happening in cxl_parse_cfmws(), where put_device() is called,
> > releasing cxld->dev, and then, later, dev_err(cxld->dev) is called
> > referencing the released device.
> > 
> > Just release the device after the message is printed/dev_err().  On top
> > of that, cxl_parse_cfmws() must fail (returns rc) in case of
> > cxl_decoder_add() or cxl_decoder_autoremove() failing (rc != 0), instead
> > of swallowing the error and returning 0.
> 
> Breno,
> 
> Is kfence satisfied if you do this?

Yes, this approach solves the complaints from kfence/kasan. I am
wondering if "cxld" is what is being freed up here at device_put().

> iff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c
> index 658e6b84a769..642983da01cb 100644
> --- a/drivers/cxl/acpi.c
> +++ b/drivers/cxl/acpi.c
> @@ -297,7 +297,7 @@ static int cxl_parse_cfmws(union acpi_subtable_headers *header, void *arg,
>                 rc = cxl_decoder_autoremove(dev, cxld);
>         if (rc) {
>                 dev_err(dev, "Failed to add decode range [%#llx - %#llx]\n",
> -                       cxld->hpa_range.start, cxld->hpa_range.end);
> +                       res->start, res->end);
>                 return 0;
>         }
>         dev_dbg(dev, "add: %s node: %d range [%#llx - %#llx]\n",

Do you prefer this patch above, mine patch or a mix of both?

Thanks

  reply	other threads:[~2023-07-12 14:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-11 16:17 [PATCH v2] cxl/acpi: Release device after dev_err() Breno Leitao
2023-07-11 17:29 ` Alison Schofield
2023-07-12 12:33   ` Breno Leitao
2023-07-13  4:38     ` Alison Schofield
2023-07-11 17:52 ` Alison Schofield
2023-07-12 14:24   ` Breno Leitao [this message]
2023-07-11 18:11 ` Dave Jiang

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=ZK63uG6WkBJC/5+l@gmail.com \
    --to=leitao@debian.org \
    --cc=alison.schofield@intel.com \
    --cc=ave.jiang@intel.com \
    --cc=bwidawsk@kernel.org \
    --cc=dan.j.williams@intel.com \
    --cc=ira.weiny@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=vishal.l.verma@intel.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 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.