All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in __nonstatic_find_io_region()
@ 2021-11-30 16:59 Zhou Qingyang
  2022-01-02 17:46 ` Dominik Brodowski
  0 siblings, 1 reply; 2+ messages in thread
From: Zhou Qingyang @ 2021-11-30 16:59 UTC (permalink / raw)
  To: zhou1615; +Cc: kjlu, Dominik Brodowski, Lee Jones, linux-kernel

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 ONFIG_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>
---
 drivers/pcmcia/rsrc_nonstatic.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index bb15a8bdbaab..4f5e1a46ebe4 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -689,6 +689,9 @@ static struct resource *__nonstatic_find_io_region(struct pcmcia_socket *s,
 	struct pcmcia_align_data data;
 	unsigned long min = base;
 	int ret;
+
+	if (!res)
+		return NULL;

 	data.mask = align - 1;
 	data.offset = base & data.mask;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in __nonstatic_find_io_region()
  2021-11-30 16:59 [PATCH] pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in __nonstatic_find_io_region() Zhou Qingyang
@ 2022-01-02 17:46 ` Dominik Brodowski
  0 siblings, 0 replies; 2+ messages in thread
From: Dominik Brodowski @ 2022-01-02 17:46 UTC (permalink / raw)
  To: Zhou Qingyang; +Cc: kjlu, Lee Jones, linux-kernel

Am Wed, Dec 01, 2021 at 12:59:23AM +0800 schrieb Zhou Qingyang:
> 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 ONFIG_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>

Although pcmcica_make_resource() will not fail, as the requested size is so
small: Applied to pcmcia-next.

Thanks,
	Dominik

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-02 18:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30 16:59 [PATCH] pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in __nonstatic_find_io_region() Zhou Qingyang
2022-01-02 17:46 ` Dominik Brodowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.