linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ata: pata_platform: Fix a NULL pointer dereference in __pata_platform_probe()
@ 2022-01-24 16:45 Zhou Qingyang
  2022-01-25  9:46 ` Sergey Shtylyov
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Zhou Qingyang @ 2022-01-24 16:45 UTC (permalink / raw)
  To: zhou1615
  Cc: kjlu, Damien Le Moal, Alexander Shiyan,
	Bartlomiej Zolnierkiewicz, Jens Axboe, linux-ide, linux-kernel

In __pata_platform_probe(), devm_kzalloc() is assigned to ap->ops and
there is a dereference of it right after that, which could introduce a
NULL pointer dereference bug.

Fix this by adding a NULL check of ap->ops.

This bug was found by a static analyzer.

Builds with 'make allyesconfig' show no new warnings,
and our static analyzer no longer warns about this code.

Fixes: f3d5e4f18dba ("ata: pata_of_platform: Allow to use 16-bit wide data transfer")
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
---
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.

 drivers/ata/pata_platform.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 028329428b75..021ef9cbcbc1 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -128,6 +128,8 @@ int __pata_platform_probe(struct device *dev, struct resource *io_res,
 	ap = host->ports[0];
 
 	ap->ops = devm_kzalloc(dev, sizeof(*ap->ops), GFP_KERNEL);
+	if (ap->ops)
+		return -ENOMEM;
 	ap->ops->inherits = &ata_sff_port_ops;
 	ap->ops->cable_detect = ata_cable_unknown;
 	ap->ops->set_mode = pata_platform_set_mode;
-- 
2.25.1


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

end of thread, other threads:[~2022-01-31  0:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 16:45 [PATCH] ata: pata_platform: Fix a NULL pointer dereference in __pata_platform_probe() Zhou Qingyang
2022-01-25  9:46 ` Sergey Shtylyov
2022-01-27  2:15   ` Damien Le Moal
2022-01-27  9:37     ` Sergey Shtylyov
2022-01-27  1:54 ` Damien Le Moal
2022-01-28 10:11 ` Greg KH
2022-01-28 11:50   ` Damien Le Moal
2022-01-28 15:57     ` Greg KH
2022-01-29  0:12       ` Damien Le Moal
2022-01-29  7:06         ` Greg KH
2022-01-31  0:11           ` Damien Le Moal

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).