From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 4.9 07/64] genirq: Make sparse_irq_lock protect what it should protect
Date: Tue, 3 Oct 2017 14:22:59 +0200 [thread overview]
Message-ID: <20171003114229.244193077@linuxfoundation.org> (raw)
In-Reply-To: <20171003114228.884821129@linuxfoundation.org>
4.9-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Gleixner <tglx@linutronix.de>
commit 12ac1d0f6c3e95732d144ffa65c8b20fbd9aa462 upstream.
for_each_active_irq() iterates the sparse irq allocation bitmap. The caller
must hold sparse_irq_lock. Several code pathes expect that an active bit in
the sparse bitmap also has a valid interrupt descriptor.
Unfortunately that's not true. The (de)allocation is a two step process,
which holds the sparse_irq_lock only across the queue/remove from the radix
tree and the set/clear in the allocation bitmap.
If a iteration locks sparse_irq_lock between the two steps, then it might
see an active bit but the corresponding irq descriptor is NULL. If that is
dereferenced unconditionally, then the kernel oopses. Of course, all
iterator sites could be audited and fixed, but....
There is no reason why the sparse_irq_lock needs to be dropped between the
two steps, in fact the code becomes simpler when the mutex is held across
both and the semantics become more straight forward, so future problems of
missing NULL pointer checks in the iteration are avoided and all existing
sites are fixed in one go.
Expand the lock held sections so both operations are covered and the bitmap
and the radixtree are in sync.
Fixes: a05a900a51c7 ("genirq: Make sparse_lock a mutex")
Reported-and-tested-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
kernel/irq/irqdesc.c | 24 +++++++-----------------
1 file changed, 7 insertions(+), 17 deletions(-)
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -405,10 +405,8 @@ static void free_desc(unsigned int irq)
* The sysfs entry must be serialized against a concurrent
* irq_sysfs_init() as well.
*/
- mutex_lock(&sparse_irq_lock);
kobject_del(&desc->kobj);
delete_irq_desc(irq);
- mutex_unlock(&sparse_irq_lock);
/*
* We free the descriptor, masks and stat fields via RCU. That
@@ -446,20 +444,15 @@ static int alloc_descs(unsigned int star
desc = alloc_desc(start + i, node, flags, mask, owner);
if (!desc)
goto err;
- mutex_lock(&sparse_irq_lock);
irq_insert_desc(start + i, desc);
irq_sysfs_add(start + i, desc);
- mutex_unlock(&sparse_irq_lock);
}
+ bitmap_set(allocated_irqs, start, cnt);
return start;
err:
for (i--; i >= 0; i--)
free_desc(start + i);
-
- mutex_lock(&sparse_irq_lock);
- bitmap_clear(allocated_irqs, start, cnt);
- mutex_unlock(&sparse_irq_lock);
return -ENOMEM;
}
@@ -558,6 +551,7 @@ static inline int alloc_descs(unsigned i
desc->owner = owner;
}
+ bitmap_set(allocated_irqs, start, cnt);
return start;
}
@@ -653,10 +647,10 @@ void irq_free_descs(unsigned int from, u
if (from >= nr_irqs || (from + cnt) > nr_irqs)
return;
+ mutex_lock(&sparse_irq_lock);
for (i = 0; i < cnt; i++)
free_desc(from + i);
- mutex_lock(&sparse_irq_lock);
bitmap_clear(allocated_irqs, from, cnt);
mutex_unlock(&sparse_irq_lock);
}
@@ -703,19 +697,15 @@ __irq_alloc_descs(int irq, unsigned int
from, cnt, 0);
ret = -EEXIST;
if (irq >=0 && start != irq)
- goto err;
+ goto unlock;
if (start + cnt > nr_irqs) {
ret = irq_expand_nr_irqs(start + cnt);
if (ret)
- goto err;
+ goto unlock;
}
-
- bitmap_set(allocated_irqs, start, cnt);
- mutex_unlock(&sparse_irq_lock);
- return alloc_descs(start, cnt, node, affinity, owner);
-
-err:
+ ret = alloc_descs(start, cnt, node, affinity, owner);
+unlock:
mutex_unlock(&sparse_irq_lock);
return ret;
}
next prev parent reply other threads:[~2017-10-03 12:25 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-03 12:22 [PATCH 4.9 00/64] 4.9.53-stable review Greg Kroah-Hartman
2017-10-03 12:22 ` [PATCH 4.9 01/64] cifs: release cifs root_cred after exit_cifs Greg Kroah-Hartman
2017-10-03 12:22 ` [PATCH 4.9 02/64] cifs: release auth_key.response for reconnect Greg Kroah-Hartman
2017-10-03 12:22 ` [PATCH 4.9 03/64] fs/proc: Report eip/esp in /prod/PID/stat for coredumping Greg Kroah-Hartman
2017-10-03 12:22 ` [PATCH 4.9 04/64] mac80211: fix VLAN handling with TXQs Greg Kroah-Hartman
2017-10-03 12:22 ` [PATCH 4.9 05/64] mac80211_hwsim: Use proper TX power Greg Kroah-Hartman
2017-10-03 12:22 ` [PATCH 4.9 06/64] mac80211: flush hw_roc_start work before cancelling the ROC Greg Kroah-Hartman
2017-10-03 12:22 ` Greg Kroah-Hartman [this message]
2017-10-03 12:23 ` [PATCH 4.9 08/64] KVM: PPC: Book3S: Fix race and leak in kvm_vm_ioctl_create_spapr_tce() Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 09/64] KVM: PPC: Book3S HV: Protect updates to spapr_tce_tables list Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 10/64] tracing: Fix trace_pipe behavior for instance traces Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 11/64] tracing: Erase irqsoff trace with empty write Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 12/64] md/raid5: fix a race condition in stripe batch Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 13/64] md/raid5: preserve STRIPE_ON_UNPLUG_LIST in break_stripe_batch_list Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 14/64] scsi: scsi_transport_iscsi: fix the issue that iscsi_if_rx doesnt parse nlmsg properly Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 15/64] drm/radeon: disable hard reset in hibernate for APUs Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 16/64] crypto: drbg - fix freeing of resources Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 17/64] crypto: talitos - Dont provide setkey for non hmac hashing algs Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 18/64] crypto: talitos - fix sha224 Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 19/64] crypto: talitos - fix hashing Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 20/64] security/keys: properly zero out sensitive key material in big_key Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 21/64] security/keys: rewrite all of big_key crypto Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 22/64] KEYS: fix writing past end of user-supplied buffer in keyring_read() Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 23/64] KEYS: prevent creating a different users keyrings Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 24/64] KEYS: prevent KEYCTL_READ on negative key Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 25/64] powerpc/pseries: Fix parent_dn reference leak in add_dt_node() Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 26/64] powerpc/tm: Flush TM only if CPU has TM feature Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 27/64] powerpc/ftrace: Pass the correct stack pointer for DYNAMIC_FTRACE_WITH_REGS Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 28/64] s390/mm: fix write access check in gup_huge_pmd() Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 29/64] PM: core: Fix device_pm_check_callbacks() Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 30/64] Fix SMB3.1.1 guest authentication to Samba Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 31/64] SMB3: Warn user if trying to sign connection that authenticated as guest Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 32/64] SMB: Validate negotiate (to protect against downgrade) even if signing off Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 33/64] SMB3: Dont ignore O_SYNC/O_DSYNC and O_DIRECT flags Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 34/64] vfs: Return -ENXIO for negative SEEK_HOLE / SEEK_DATA offsets Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 35/64] nl80211: check for the required netlink attributes presence Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 36/64] bsg-lib: dont free job in bsg_prepare_job Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 37/64] iw_cxgb4: remove the stid on listen create failure Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 38/64] iw_cxgb4: put ep reference in pass_accept_req() Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 39/64] selftests/seccomp: Support glibc 2.26 siginfo_t.h Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 40/64] seccomp: fix the usage of get/put_seccomp_filter() in seccomp_get_filter() Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 41/64] arm64: Make sure SPsel is always set Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 42/64] arm64: fault: Route pte translation faults via do_translation_fault Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 46/64] kvm/x86: Handle async PF in RCU read-side critical sections Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 48/64] kvm: nVMX: Dont allow L2 to access the hardware CR8 Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 49/64] xfs: validate bdev support for DAX inode flag Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 50/64] etnaviv: fix gem object list corruption Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 51/64] PCI: Fix race condition with driver_override Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 52/64] btrfs: fix NULL pointer dereference from free_reloc_roots() Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 53/64] btrfs: propagate error to btrfs_cmp_data_prepare caller Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 54/64] btrfs: prevent to set invalid default subvolid Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 55/64] x86/mm: Fix fault error path using unsafe vma pointer Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 56/64] x86/fpu: Dont let userspace set bogus xcomp_bv Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 57/64] gfs2: Fix debugfs glocks dump Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 58/64] timer/sysclt: Restrict timer migration sysctl values to 0 and 1 Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 61/64] cxl: Fix driver use count Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 62/64] KVM: VMX: use cmpxchg64 Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 63/64] video: fbdev: aty: do not leak uninitialized padding in clk to userspace Greg Kroah-Hartman
2017-10-03 12:23 ` [PATCH 4.9 64/64] swiotlb-xen: implement xen_swiotlb_dma_mmap callback Greg Kroah-Hartman
2017-10-03 19:27 ` [PATCH 4.9 00/64] 4.9.53-stable review Shuah Khan
2017-10-03 20:29 ` Tom Gall
2017-10-04 7:56 ` Greg Kroah-Hartman
2017-10-03 20:42 ` Guenter Roeck
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=20171003114229.244193077@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).