mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Reinette Chatre <reinette.chatre@intel.com>
To: <tony.luck@intel.com>, <james.morse@arm.com>,
	<Dave.Martin@arm.com>, <babu.moger@amd.com>, <bp@alien8.de>,
	<tglx@linutronix.de>, <dave.hansen@linux.intel.com>
Cc: <x86@kernel.org>, <hpa@zytor.com>, <ben.horgan@arm.com>,
	<fustini@kernel.org>, <fenghuay@nvidia.com>,
	<peternewman@google.com>, <yu.c.chen@intel.com>,
	<linux-kernel@vger.kernel.org>, <patches@lists.linux.dev>
Subject: Re: [PATCH v4 10/10] fs/resctrl: Fix UAF from worker threads when domains are removed
Date: Thu, 4 Jun 2026 08:31:32 -0700	[thread overview]
Message-ID: <ec49c03f-9fda-44c2-9d3d-591818367e0c@intel.com> (raw)
In-Reply-To: <c6bdc19625e0aba4978db2031b7cefb3bfd6fbc1.1780456704.git.reinette.chatre@intel.com>



On 6/2/26 8:27 PM, Reinette Chatre wrote:
> The mbm_handle_overflow() and cqm_handle_limbo() workers read event
> counters and may sleep while doing so. They are scheduled via
> delayed_work embedded in struct rdt_l3_mon_domain. Architecture allocates
> and frees these domains from CPU hotplug callbacks under cpus_write_lock(),
> and the workers acquire cpus_read_lock() to keep the domain alive across
> their access.
> 
> A use-after-free can occur when a worker is blocked waiting for
> cpus_read_lock() while the hotplug core holds cpus_write_lock():
> the architecture frees the rdt_l3_mon_domain that contains the worker's
> work_struct. When the worker unblocks, the container_of() it performs on
> the embedded work pointer dereferences freed memory.
> 
> Drop cpus_read_lock() from the workers and instead drain pending and
> in-flight work synchronously before the architecture can free the domain.
> Since architecture offlines the domain under cpus_write_lock() after it has
> been unlinked from the RCU list and a grace period has elapsed, no new work
> can be scheduled. The cancel only needs to wait out existing work.
> Drop rdtgroup_mutex during CPU offline around cancel_delayed_work_sync()
> so that a worker waiting on the mutex can complete before re-pinning the
> work on a different CPU.
> 
> When offlining a CPU the architecture may iterate over resources in any
> order. For example, the MBA control domain may be offlined before or
> after a corresponding L3 monitor domain. Ensure that resctrl fs cancels
> the workers no matter what order the architecture offlines the domains.
> 
> Fixes: 24247aeeabe9 ("x86/intel_rdt/cqm: Improve limbo list processing")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/patchset/20260429184858.36423-1-tony.luck%40intel.com # [1]
> Co-developed-by: Tony Luck <tony.luck@intel.com>
> Signed-off-by: Tony Luck <tony.luck@intel.com>
> Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
> ---

Sashiko highlighted [1] that since this patch ensures the workers can complete
as part of CPU offline the worker is more likely to run with on a domain while that
domain's cpu_mask is empty. There are places where the workers peek into the
domain's cpu_mask. For example, 
- if SNC is enabled the limbo handler needs to know the NUMA node ID of the
  domain and uses a CPU from cpu_mask to determine that
- both workers always look into the cpu_mask to determine where to reschedule next.

To protect against this I plan to add a check for an empty cpu_mask at the start
of both workers and just exit if the cpu_mask is empty.

Reinette

[1] https://sashiko.dev/#/patchset/cover.1780456704.git.reinette.chatre%40intel.com?part=10

  reply	other threads:[~2026-06-04 15:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03  3:27 [PATCH v4 00/10] x86,fs/resctrl: Fix long-standing issues Reinette Chatre
2026-06-03  3:27 ` [PATCH v4 01/10] x86,fs/resctrl: Document safe RCU list traversal Reinette Chatre
2026-06-04 15:30   ` Reinette Chatre
2026-06-03  3:27 ` [PATCH v4 02/10] fs/resctrl: Move functions to avoid forward references in subsequent fixes Reinette Chatre
2026-06-03  3:27 ` [PATCH v4 03/10] fs/resctrl: Free mon_data structures on rdt_get_tree() failure Reinette Chatre
2026-06-03  3:27 ` [PATCH v4 04/10] fs/resctrl: Fix use-after-free during unmount Reinette Chatre
2026-06-03  3:27 ` [PATCH v4 05/10] fs/resctrl: Fix deadlock on errors during mount Reinette Chatre
2026-06-03  3:27 ` [PATCH v4 06/10] fs/resctrl: Prevent use-after-free in rdtgroup_kn_put() Reinette Chatre
2026-06-03  3:27 ` [PATCH v4 07/10] fs/resctrl: Fix double-add of pseudo-locked region's RMID to free list Reinette Chatre
2026-06-03  3:27 ` [PATCH v4 08/10] fs/resctrl: Prevent deadlock and use-after-free in info file handlers Reinette Chatre
2026-06-03  3:27 ` [PATCH v4 09/10] x86/resctrl: Ensure domain fully initialized before placed on RCU list Reinette Chatre
2026-06-03  3:27 ` [PATCH v4 10/10] fs/resctrl: Fix UAF from worker threads when domains are removed Reinette Chatre
2026-06-04 15:31   ` Reinette Chatre [this message]
2026-06-04 15:28 ` [PATCH v4 00/10] x86,fs/resctrl: Fix long-standing issues Reinette Chatre

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=ec49c03f-9fda-44c2-9d3d-591818367e0c@intel.com \
    --to=reinette.chatre@intel.com \
    --cc=Dave.Martin@arm.com \
    --cc=babu.moger@amd.com \
    --cc=ben.horgan@arm.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=fenghuay@nvidia.com \
    --cc=fustini@kernel.org \
    --cc=hpa@zytor.com \
    --cc=james.morse@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=peternewman@google.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.org \
    --cc=yu.c.chen@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

all inboxes | Powered by JetHome®