Skip to contentSkip to conversation

char: ppdev: Fix a possible null-pointer dereference in pp_release()

PATCH New Jia-Ju Bai 1 participant 1 message Jul 24, 2019

Subsystems (2)
lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 char: ppdev: Fix a possible null-pointer dereference in pp_release()

In pp_release(), there is an if statement on line 730 to check whether pp->pdev is NULL:

    else if ((pp->flags & PP_CLAIMED) && pp->pdev && ...)

When pp->pdev is NULL, it is used on line 743:

    info = &pp->pdev->port->ieee1284;
and on line 748:
    parport_release(pp->pdev);

Thus, a possible null-pointer dereference may occur.

To fix this bug, pp->pdev is checked on line 740.

This bug is found by a static analysis tool STCheck written by us.

---
 drivers/char/ppdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/ppdev.c +1 -1
index f0a8adca1eee..c86f18aa8985 100644
@@ -737,7 +737,7 @@ static int pp_release(struct inode *inode, struct file *file)
 			"negotiated back to compatibility mode because user-space forgot\n");
 	}
 
-	if (pp->flags & PP_CLAIMED) {
+	if ((pp->flags & PP_CLAIMED) && pp->pdev) {
 		struct ieee1284_info *info;
 
 		info = &pp->pdev->port->ieee1284;
Signature · 1 line
2.17.0