SA1111: Eliminate use after free
authorJulia Lawall <julia@diku.dk>
Fri, 30 Jul 2010 15:17:28 +0000 (17:17 +0200)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Fri, 30 Jul 2010 22:19:30 +0000 (23:19 +0100)
__sa1111_remove always frees its argument, so the subsequent reference to
sachip->saved_state represents a use after free.  __sa1111_remove does not
appear to use the saved_state field, so the patch simply frees it first.

A simplified version of the semantic patch that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression E,E2;
@@

__sa1111_remove(E)
...
(
  E = E2
|
* E
)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/common/sa1111.c

index 6f80665f477e70b0acad4d6ead228295446863c3..9eaf65f43642e6886b3ab4bae43e7821aad285b6 100644 (file)
@@ -1028,13 +1028,12 @@ static int sa1111_remove(struct platform_device *pdev)
        struct sa1111 *sachip = platform_get_drvdata(pdev);
 
        if (sachip) {
-               __sa1111_remove(sachip);
-               platform_set_drvdata(pdev, NULL);
-
 #ifdef CONFIG_PM
                kfree(sachip->saved_state);
                sachip->saved_state = NULL;
 #endif
+               __sa1111_remove(sachip);
+               platform_set_drvdata(pdev, NULL);
        }
 
        return 0;