CRED: Fix double free in prepare_usermodehelper_creds() error handling
[linux-2.6-microblaze.git] / kernel / cred.c
index 1ed8ca1..ce1a52b 100644 (file)
@@ -10,6 +10,7 @@
  */
 #include <linux/module.h>
 #include <linux/cred.h>
+#include <linux/slab.h>
 #include <linux/sched.h>
 #include <linux/key.h>
 #include <linux/keyctl.h>
@@ -364,7 +365,7 @@ struct cred *prepare_usermodehelper_creds(void)
 
        new = kmem_cache_alloc(cred_jar, GFP_ATOMIC);
        if (!new)
-               return NULL;
+               goto free_tgcred;
 
        kdebug("prepare_usermodehelper_creds() alloc %p", new);
 
@@ -398,6 +399,12 @@ struct cred *prepare_usermodehelper_creds(void)
 error:
        put_cred(new);
        return NULL;
+
+free_tgcred:
+#ifdef CONFIG_KEYS
+       kfree(tgcred);
+#endif
+       return NULL;
 }
 
 /*