genirq/proc: fix race in show_irq_affinity()
PATCH 1/1 genirq/proc: fix race in show_irq_affinity()
Reading /proc/irq/N/smp_affinity* races with irq_set_affinity() and irq_move_masked_irq(), leading to old or torn output for users.
We hit a real-world issue: after a user writes a new CPU mask to /proc/irq/N/affinity*, the syscall returns success, yet a subsequent read of the same file immediately returns a value different from what was just written—much to the user’s surprise. Root-causing showed that a race between show_irq_affinity() and irq_move_masked_irq() lets the read observe a transient, inconsistent affinity mask. struct irq_desc is supposed to be accessed under the desc->lock, it seems that show_irq_affinity() forgets that, so fix it.
--- kernel/irq/proc.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/irq/proc.c +2 -0
@@ -48,6 +48,8 @@ static int show_irq_affinity(int type, struct seq_file *m)struct irq_desc *desc =irq_to_desc ((long )m->private);const struct cpumask *mask; +guard (raw_spinlock_irq)(&desc->lock); +switch (type) {case AFFINITY :case AFFINITY_LIST :
Signature · 1 line
2.20.1
[tip: irq/core] genirq/proc: Fix race in show_irq_affinity()
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 9ea2b810d51ae662cc5b5578f9395cb620a34a26 Gitweb: https://git.kernel.org/tip/9ea2b810d51ae662cc5b5578f9395cb620a34a26 Author: Muchun Song <[email protected]> AuthorDate: Tue, 28 Oct 2025 17:04:08 +08:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Fri, 31 Oct 2025 22:30:05 +01:00
genirq/proc: Fix race in show_irq_affinity()
Reading /proc/irq/N/smp_affinity* races with irq_set_affinity() and irq_move_masked_irq(), leading to old or torn output for users.
After a user writes a new CPU mask to /proc/irq/N/affinity*, the syscall returns success, yet a subsequent read of the same file immediately returns a value different from what was just written.
That's due to a race between show_irq_affinity() and irq_move_masked_irq() which lets the read observe a transient, inconsistent affinity mask.
Cure it by guarding the read with irq_desc::lock.
[ tglx: Massaged change log ]
--- kernel/irq/proc.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/irq/proc.c +2 -0
@@ -48,6 +48,8 @@ static int show_irq_affinity(int type, struct seq_file *m)struct irq_desc *desc =irq_to_desc ((long )m->private);const struct cpumask *mask; +guard (raw_spinlock_irq)(&desc->lock); +switch (type) {case AFFINITY :case AFFINITY_LIST :