diff mbox series

security/apparmor/domain: use PTR_ERR_OR_ZERO

Message ID 1546593430-24355-1-git-send-email-peng.hao2@zte.com.cn (mailing list archive)
State New, archived
Headers show
Series security/apparmor/domain: use PTR_ERR_OR_ZERO | expand

Commit Message

Peng Hao Jan. 4, 2019, 9:17 a.m. UTC
The variable 'new' may be NULL, so use PTR_ERR_OR_ZERO instead
of PTR_ERR.

Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
---
 security/apparmor/domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

John Johansen Jan. 16, 2019, 10:31 p.m. UTC | #1
On 1/4/19 1:17 AM, Peng Hao wrote:
> The variable 'new' may be NULL, so use PTR_ERR_OR_ZERO instead
> of PTR_ERR.
> 
> Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>

yep that is a problem unfortunately the fix isn't quite right
we don't want to return 0 for an error here. Instead we can
do

diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c
index 08c88de0ffda..11975ec8d566 100644
--- a/security/apparmor/domain.c
+++ b/security/apparmor/domain.c
@@ -1444,7 +1444,10 @@ int aa_change_profile(const char *fqname, int flags)
 			new = aa_label_merge(label, target, GFP_KERNEL);
 		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;


I have pulled your patch into my apparmor tree with the above revision


> ---
>  security/apparmor/domain.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c
> index 08c88de..7663589 100644
> --- a/security/apparmor/domain.c
> +++ b/security/apparmor/domain.c
> @@ -1444,7 +1444,7 @@ int aa_change_profile(const char *fqname, int flags)
>  			new = aa_label_merge(label, target, GFP_KERNEL);
>  		if (IS_ERR_OR_NULL(new)) {
>  			info = "failed to build target label";
> -			error = PTR_ERR(new);
> +			error = PTR_ERR_OR_ZERO(new);
>  			new = NULL;
>  			perms.allow = 0;
>  			goto audit;
>
diff mbox series

Patch

diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c
index 08c88de..7663589 100644
--- a/security/apparmor/domain.c
+++ b/security/apparmor/domain.c
@@ -1444,7 +1444,7 @@  int aa_change_profile(const char *fqname, int flags)
 			new = aa_label_merge(label, target, GFP_KERNEL);
 		if (IS_ERR_OR_NULL(new)) {
 			info = "failed to build target label";
-			error = PTR_ERR(new);
+			error = PTR_ERR_OR_ZERO(new);
 			new = NULL;
 			perms.allow = 0;
 			goto audit;