FAILED: patch "[PATCH] x86,fs/resctrl: Prevent out-of-bounds access while offlining" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x fc16126cc11d9f507130bf84ab137ee0938c900e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026071357-shifter-degree-6c12@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From fc16126cc11d9f507130bf84ab137ee0938c900e Mon Sep 17 00:00:00 2001
From: Reinette Chatre <[email protected]>
Date: Tue, 9 Jun 2026 14:02:27 -0700
Subject: [PATCH] x86,fs/resctrl: Prevent out-of-bounds access while offlining
CPU when SNC enabled
The architecture updates the cpu_mask in a domain's header to track which online CPUs are associated with the domain. When this mask becomes empty the architecture initiates offline of the domain that includes calling on resctrl fs to offline the domain. If it is a monitoring domain in which LLC occupancy is tracked resctrl fs forces the limbo handler to clear all busy RMID state associated with the domain.
The limbo handler always reads the current event value associated with a busy RMID irrespective of it being checked as part of regular "is it still busy" check or whether it will be forced released anyway. When reading an RMID on a system with SNC enabled the "logical RMID" is converted to the "physical RMID" and this conversion requires the NUMA node ID of the resctrl monitoring domain that is in turn determined by querying the NUMA node ID of any CPU belonging to the monitoring domain.
When the monitoring domain is going offline its cpu_mask is empty causing the NUMA node ID query via cpu_to_node() to be done with "nr_cpu_ids" as argument resulting in an out-of-bounds access.
Refactor the limbo handler to skip reading the RMID when the RMID will just be forced to no longer be dirty in the domain anyway. Add a safety check to the architecture's RMID reader to protect against this scenario.
arch/x86/kernel/cpu/resctrl/monitor.c +5 -0
@@ -259,6 +259,11 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,if (!domain_header_is_valid (hdr,RESCTRL_MON_DOMAIN ,RDT_RESOURCE_L3 ))return -EINVAL ; +if (cpumask_empty (&hdr->cpu_mask)) { +pr_warn_once ("Domain %d has no CPUs\n" , hdr->id); +return -EINVAL ; + } + d = container_of(hdr, struct rdt_l3_mon_domain, hdr); hw_dom =resctrl_to_arch_mon_dom (d); cpu =cpumask_any (&hdr->cpu_mask);
fs/resctrl/monitor.c +21 -16
@@ -135,10 +135,10 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free)struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 );u32 idx_limit =resctrl_arch_system_num_rmid_idx ();struct rmid_entry *entry; +bool rmid_dirty = true;u32 idx, cur_idx =1 ;void *arch_mon_ctx;void *arch_priv; -bool rmid_dirty;u64 val =0 ; arch_priv = mon_event_all[QOS_L3_OCCUP_EVENT_ID ].arch_priv;
@@ -161,22 +161,27 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free)break ; entry =__rmid_entry (idx); -if (resctrl_arch_rmid_read (r, &d->hdr, entry->closid, entry->rmid, -QOS_L3_OCCUP_EVENT_ID , arch_priv, &val, - arch_mon_ctx)) { - rmid_dirty = true; - }else { - rmid_dirty = (val >= resctrl_rmid_realloc_threshold); +if (!force_free) { +if (resctrl_arch_rmid_read (r, &d->hdr, entry->closid, + entry->rmid,QOS_L3_OCCUP_EVENT_ID , + arch_priv, &val, arch_mon_ctx)) { + rmid_dirty = true; + }else { + rmid_dirty = (val >= resctrl_rmid_realloc_threshold); -/* -* x86's CLOSID and RMID are independent numbers, so the entry's -* CLOSID is an empty CLOSID (X86_RESCTRL_EMPTY_CLOSID). On Arm the -* RMID (PMG) extends the CLOSID (PARTID) space with bits that aren't -* used to select the configuration. It is thus necessary to track both -* CLOSID and RMID because there may be dependencies between them -* on some architectures. -*/ -trace_mon_llc_occupancy_limbo (entry->closid, entry->rmid, d->hdr.id, val); +/* +* x86's CLOSID and RMID are independent numbers, +* so the entry's CLOSID is an empty CLOSID +* (X86_RESCTRL_EMPTY_CLOSID). On Arm the RMID +* (PMG) extends the CLOSID (PARTID) space with +* bits that aren't used to select the configuration. +* It is thus necessary to track both CLOSID and +* RMID because there may be dependencies between +* them on some architectures. +*/ +trace_mon_llc_occupancy_limbo (entry->closid, entry->rmid, + d->hdr.id, val); + } }if (force_free || !rmid_dirty) {
Reinette Chatre
maintainerPATCH 1/1 x86,fs/resctrl: Prevent out-of-bounds access while offlining CPU when SNC enabled
commit fc16126cc11d9f507130bf84ab137ee0938c900e upstream.
The architecture updates the cpu_mask in a domain's header to track which online CPUs are associated with the domain. When this mask becomes empty the architecture initiates offline of the domain that includes calling on resctrl fs to offline the domain. If it is a monitoring domain in which LLC occupancy is tracked resctrl fs forces the limbo handler to clear all busy RMID state associated with the domain.
The limbo handler always reads the current event value associated with a busy RMID irrespective of it being checked as part of regular "is it still busy" check or whether it will be forced released anyway. When reading an RMID on a system with SNC enabled the "logical RMID" is converted to the "physical RMID" and this conversion requires the NUMA node ID of the resctrl monitoring domain that is in turn determined by querying the NUMA node ID of any CPU belonging to the monitoring domain.
When the monitoring domain is going offline its cpu_mask is empty causing the NUMA node ID query via cpu_to_node() to be done with "nr_cpu_ids" as argument resulting in an out-of-bounds access.
Refactor the limbo handler to skip reading the RMID when the RMID will just be forced to no longer be dirty in the domain anyway. Add a safety check to the architecture's RMID reader to protect against this scenario.
--- arch/x86/kernel/cpu/resctrl/monitor.c | 47 +++++++++++++++++---------- 1 file changed, 29 insertions(+), 18 deletions(-)
arch/x86/kernel/cpu/resctrl/monitor.c +29 -18
@@ -338,14 +338,20 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d, u64 *val, void *ignored) {struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d); -int cpu =cpumask_any (&d->hdr.cpu_mask);struct arch_mbm_state *am;u64 msr_val;u32 prmid; +int cpu;int ret;resctrl_arch_rmid_read_context_check (); +if (cpumask_empty (&d->hdr.cpu_mask)) { +pr_warn_once ("Domain %d has no CPUs\n" , d->hdr.id); +return -EINVAL ; + } + + cpu =cpumask_any (&d->hdr.cpu_mask); prmid =logical_rmid_to_physical_rmid (cpu, rmid); ret =__rmid_read_phys (prmid, eventid, &msr_val);
@@ -382,9 +388,9 @@ void __check_limbo(struct rdt_mon_domain *d, bool force_free)struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl;u32 idx_limit =resctrl_arch_system_num_rmid_idx ();struct rmid_entry *entry; +bool rmid_dirty = true;u32 idx, cur_idx =1 ;void *arch_mon_ctx; -bool rmid_dirty;u64 val =0 ; arch_mon_ctx =resctrl_arch_mon_ctx_alloc (r,QOS_L3_OCCUP_EVENT_ID );
@@ -406,22 +412,27 @@ void __check_limbo(struct rdt_mon_domain *d, bool force_free)break ; entry =__rmid_entry (idx); -if (resctrl_arch_rmid_read (r, d, entry->closid, entry->rmid, -QOS_L3_OCCUP_EVENT_ID , &val, - arch_mon_ctx)) { - rmid_dirty = true; - }else { - rmid_dirty = (val >= resctrl_rmid_realloc_threshold); - -/* -* x86's CLOSID and RMID are independent numbers, so the entry's -* CLOSID is an empty CLOSID (X86_RESCTRL_EMPTY_CLOSID). On Arm the -* RMID (PMG) extends the CLOSID (PARTID) space with bits that aren't -* used to select the configuration. It is thus necessary to track both -* CLOSID and RMID because there may be dependencies between them -* on some architectures. -*/ -trace_mon_llc_occupancy_limbo (entry->closid, entry->rmid, d->hdr.id, val); +if (!force_free) { +if (resctrl_arch_rmid_read (r, d, entry->closid, + entry->rmid,QOS_L3_OCCUP_EVENT_ID , + &val, arch_mon_ctx)) { + rmid_dirty = true; + }else { + rmid_dirty = (val >= resctrl_rmid_realloc_threshold); + +/* +* x86's CLOSID and RMID are independent numbers, +* so the entry's CLOSID is an empty CLOSID +* (X86_RESCTRL_EMPTY_CLOSID). On Arm the RMID +* (PMG) extends the CLOSID (PARTID) space with +* bits that aren't used to select the configuration. +* It is thus necessary to track both CLOSID and +* RMID because there may be dependencies between +* them on some architectures. +*/ +trace_mon_llc_occupancy_limbo (entry->closid, entry->rmid, + d->hdr.id, val); + } }if (force_free || !rmid_dirty) {
Signature · 1 line
2.54.0
Sasha Levin
maintainerPATCH 1/1 x86,fs/resctrl: Prevent out-of-bounds access while offlining CPU when SNC enabled
In reply to [email protected]From: Reinette Chatre <[email protected]>
[ Upstream commit fc16126cc11d9f507130bf84ab137ee0938c900e ]
The architecture updates the cpu_mask in a domain's header to track which online CPUs are associated with the domain. When this mask becomes empty the architecture initiates offline of the domain that includes calling on resctrl fs to offline the domain. If it is a monitoring domain in which LLC occupancy is tracked resctrl fs forces the limbo handler to clear all busy RMID state associated with the domain.
The limbo handler always reads the current event value associated with a busy RMID irrespective of it being checked as part of regular "is it still busy" check or whether it will be forced released anyway. When reading an RMID on a system with SNC enabled the "logical RMID" is converted to the "physical RMID" and this conversion requires the NUMA node ID of the resctrl monitoring domain that is in turn determined by querying the NUMA node ID of any CPU belonging to the monitoring domain.
When the monitoring domain is going offline its cpu_mask is empty causing the NUMA node ID query via cpu_to_node() to be done with "nr_cpu_ids" as argument resulting in an out-of-bounds access.
Refactor the limbo handler to skip reading the RMID when the RMID will just be forced to no longer be dirty in the domain anyway. Add a safety check to the architecture's RMID reader to protect against this scenario.
--- arch/x86/kernel/cpu/resctrl/monitor.c | 47 +++++++++++++++++---------- 1 file changed, 29 insertions(+), 18 deletions(-)
arch/x86/kernel/cpu/resctrl/monitor.c +29 -18
@@ -338,14 +338,20 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d, u64 *val, void *ignored) {struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d); -int cpu =cpumask_any (&d->hdr.cpu_mask);struct arch_mbm_state *am;u64 msr_val;u32 prmid; +int cpu;int ret;resctrl_arch_rmid_read_context_check (); +if (cpumask_empty (&d->hdr.cpu_mask)) { +pr_warn_once ("Domain %d has no CPUs\n" , d->hdr.id); +return -EINVAL ; + } + + cpu =cpumask_any (&d->hdr.cpu_mask); prmid =logical_rmid_to_physical_rmid (cpu, rmid); ret =__rmid_read_phys (prmid, eventid, &msr_val);
@@ -382,9 +388,9 @@ void __check_limbo(struct rdt_mon_domain *d, bool force_free)struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl;u32 idx_limit =resctrl_arch_system_num_rmid_idx ();struct rmid_entry *entry; +bool rmid_dirty = true;u32 idx, cur_idx =1 ;void *arch_mon_ctx; -bool rmid_dirty;u64 val =0 ; arch_mon_ctx =resctrl_arch_mon_ctx_alloc (r,QOS_L3_OCCUP_EVENT_ID );
@@ -406,22 +412,27 @@ void __check_limbo(struct rdt_mon_domain *d, bool force_free)break ; entry =__rmid_entry (idx); -if (resctrl_arch_rmid_read (r, d, entry->closid, entry->rmid, -QOS_L3_OCCUP_EVENT_ID , &val, - arch_mon_ctx)) { - rmid_dirty = true; - }else { - rmid_dirty = (val >= resctrl_rmid_realloc_threshold); - -/* -* x86's CLOSID and RMID are independent numbers, so the entry's -* CLOSID is an empty CLOSID (X86_RESCTRL_EMPTY_CLOSID). On Arm the -* RMID (PMG) extends the CLOSID (PARTID) space with bits that aren't -* used to select the configuration. It is thus necessary to track both -* CLOSID and RMID because there may be dependencies between them -* on some architectures. -*/ -trace_mon_llc_occupancy_limbo (entry->closid, entry->rmid, d->hdr.id, val); +if (!force_free) { +if (resctrl_arch_rmid_read (r, d, entry->closid, + entry->rmid,QOS_L3_OCCUP_EVENT_ID , + &val, arch_mon_ctx)) { + rmid_dirty = true; + }else { + rmid_dirty = (val >= resctrl_rmid_realloc_threshold); + +/* +* x86's CLOSID and RMID are independent numbers, +* so the entry's CLOSID is an empty CLOSID +* (X86_RESCTRL_EMPTY_CLOSID). On Arm the RMID +* (PMG) extends the CLOSID (PARTID) space with +* bits that aren't used to select the configuration. +* It is thus necessary to track both CLOSID and +* RMID because there may be dependencies between +* them on some architectures. +*/ +trace_mon_llc_occupancy_limbo (entry->closid, entry->rmid, + d->hdr.id, val); + } }if (force_free || !rmid_dirty) {
Signature · 1 line
2.53.0