apparmor: Fix aa_label_build() error handling for failed merges

[ Upstream commit d6d478aee0 ]

aa_label_merge() can return NULL for memory allocations failures
make sure to handle and set the correct error in this case.

Reported-by: Peng Hao <peng.hao2@zte.com.cn>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
John Johansen
2019-01-24 13:53:05 -08:00
committed by Greg Kroah-Hartman
parent 94d4062f61
commit a579fde7bd

View File

@@ -1444,6 +1444,9 @@ check:
new = aa_label_merge(label, target, GFP_KERNEL); new = aa_label_merge(label, target, GFP_KERNEL);
if (IS_ERR_OR_NULL(new)) { if (IS_ERR_OR_NULL(new)) {
info = "failed to build target label"; info = "failed to build target label";
if (!new)
error = -ENOMEM;
else
error = PTR_ERR(new); error = PTR_ERR(new);
new = NULL; new = NULL;
perms.allow = 0; perms.allow = 0;