浏览代码

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6:
  CRED: Fix memory leak in error handling
Linus Torvalds 15 年之前
父节点
当前提交
246750ffa1
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      kernel/cred.c

+ 5 - 1
kernel/cred.c

@@ -364,7 +364,7 @@ struct cred *prepare_usermodehelper_creds(void)
 
 
 	new = kmem_cache_alloc(cred_jar, GFP_ATOMIC);
 	new = kmem_cache_alloc(cred_jar, GFP_ATOMIC);
 	if (!new)
 	if (!new)
-		return NULL;
+		goto free_tgcred;
 
 
 	kdebug("prepare_usermodehelper_creds() alloc %p", new);
 	kdebug("prepare_usermodehelper_creds() alloc %p", new);
 
 
@@ -397,6 +397,10 @@ struct cred *prepare_usermodehelper_creds(void)
 
 
 error:
 error:
 	put_cred(new);
 	put_cred(new);
+free_tgcred:
+#ifdef CONFIG_KEYS
+	kfree(tgcred);
+#endif
 	return NULL;
 	return NULL;
 }
 }