summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhou Qingyang <zhou1615@umn.edu>2021-12-01 00:59:23 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-01-27 09:04:20 +0100
commit32a530d272a928e66cec7c8a1335948c5617eaa3 (patch)
treeb76ef8f95434ceade4204283099d16e6c7b95933
parent6a706db05d9bb56d8c5463c2cf6ee7849b27c486 (diff)
downloadlinux-stable-32a530d272a928e66cec7c8a1335948c5617eaa3.tar.gz
linux-stable-32a530d272a928e66cec7c8a1335948c5617eaa3.tar.bz2
linux-stable-32a530d272a928e66cec7c8a1335948c5617eaa3.zip
pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in __nonstatic_find_io_region()
[ Upstream commit ca0fe0d7c35c97528bdf621fdca75f13157c27af ] In __nonstatic_find_io_region(), pcmcia_make_resource() is assigned to res and used in pci_bus_alloc_resource(). There is a dereference of res in pci_bus_alloc_resource(), which could lead to a NULL pointer dereference on failure of pcmcia_make_resource(). Fix this bug by adding a check of res. This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs. Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug. Builds with CONFIG_PCCARD_NONSTATIC=y show no new warnings, and our static analyzer no longer warns about this code. Fixes: 49b1153adfe1 ("pcmcia: move all pcmcia_resource_ops providers into one module") Signed-off-by: Zhou Qingyang <zhou1615@umn.edu> [linux@dominikbrodowski.net: Fix typo in commit message] Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/pcmcia/rsrc_nonstatic.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index 49377d502b74..5cb29d6951df 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -693,6 +693,9 @@ static struct resource *__nonstatic_find_io_region(struct pcmcia_socket *s,
unsigned long min = base;
int ret;
+ if (!res)
+ return NULL;
+
data.mask = align - 1;
data.offset = base & data.mask;
data.map = &s_data->io_db;