From: Dave Jiang <dave.jiang@intel.com>
To: Breno Leitao <leitao@debian.org>, <alison.schofield@intel.com>,
<vishal.l.verma@intel.com>, <ira.weiny@intel.com>,
<bwidawsk@kernel.org>, <dan.j.williams@intel.com>
Cc: <linux-cxl@vger.kernel.org>, <ave.jiang@intel.com>
Subject: Re: [PATCH v2] cxl/acpi: Release device after dev_err()
Date: Tue, 11 Jul 2023 11:11:04 -0700 [thread overview]
Message-ID: <57e7dd38-cd63-ce9d-aa72-bf87054bb239@intel.com> (raw)
In-Reply-To: <20230711161704.3033220-1-leitao@debian.org>
On 7/11/23 09:17, 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.
>
> Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> v1 -> v2
> * Return the error (rc) instead of swalling it
>
> ---
> drivers/cxl/acpi.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c
> index 658e6b84a769..efead5cc8a89 100644
> --- a/drivers/cxl/acpi.c
> +++ b/drivers/cxl/acpi.c
> @@ -291,14 +291,16 @@ static int cxl_parse_cfmws(union acpi_subtable_headers *header, void *arg,
> }
> rc = cxl_decoder_add(cxld, target_map);
> err_xormap:
> - if (rc)
> - put_device(&cxld->dev);
> - else
> - 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);
> - return 0;
> + put_device(&cxld->dev);
> + return rc;
> + }
> + rc = cxl_decoder_autoremove(dev, cxld);
> + if (rc) {
> + dev_err(dev, "Failed to register autoremove action\n");
> + return rc;
> }
> dev_dbg(dev, "add: %s node: %d range [%#llx - %#llx]\n",
> dev_name(&cxld->dev),
prev parent reply other threads:[~2023-07-11 18:11 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
2023-07-11 18:11 ` Dave Jiang [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=57e7dd38-cd63-ce9d-aa72-bf87054bb239@intel.com \
--to=dave.jiang@intel.com \
--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=leitao@debian.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox