Blob Blame History Raw
From d6d478aee003e19ef90321176552a8ad2929a47f Mon Sep 17 00:00:00 2001
From: John Johansen <john.johansen@canonical.com>
Date: Thu, 24 Jan 2019 13:53:05 -0800
Subject: [PATCH] apparmor: Fix aa_label_build() error handling for failed merges
Git-commit: d6d478aee003e19ef90321176552a8ad2929a47f
Patch-mainline: v5.0-rc5
References: bsc#1051510

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>
Acked-by: Takashi Iwai <tiwai@suse.de>

---
 security/apparmor/domain.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--- a/security/apparmor/domain.c
+++ b/security/apparmor/domain.c
@@ -1310,7 +1310,10 @@ check:
 					aa_get_label(&profile->label));
 		if (IS_ERR_OR_NULL(new)) {
 			info = "failed to build target label";
-			error = PTR_ERR(new);
+			if (!new)
+				error = -ENOMEM;
+			else
+				error = PTR_ERR(new);
 			new = NULL;
 			perms.allow = 0;
 			goto audit;