Linux-Security-Module Archive on lore.kernel.org
 help / Atom feed
* [PATCH]  security/apparmor/domain: use PTR_ERR_OR_ZERO
@ 2019-01-04  9:17 Peng Hao
  2019-01-16 22:31 ` John Johansen
  0 siblings, 1 reply; 2+ messages in thread
From: Peng Hao @ 2019-01-04  9:17 UTC (permalink / raw)
  To: john.johansen, jmorris, serge
  Cc: linux-security-module, linux-kernel, Peng Hao

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(-)

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;
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] security/apparmor/domain: use PTR_ERR_OR_ZERO
  2019-01-04  9:17 [PATCH] security/apparmor/domain: use PTR_ERR_OR_ZERO Peng Hao
@ 2019-01-16 22:31 ` John Johansen
  0 siblings, 0 replies; 2+ messages in thread
From: John Johansen @ 2019-01-16 22:31 UTC (permalink / raw)
  To: Peng Hao, jmorris, serge; +Cc: linux-security-module, linux-kernel

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;
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-04  9:17 [PATCH] security/apparmor/domain: use PTR_ERR_OR_ZERO Peng Hao
2019-01-16 22:31 ` John Johansen

Linux-Security-Module Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-security-module/0 linux-security-module/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-security-module linux-security-module/ https://lore.kernel.org/linux-security-module \
		linux-security-module@vger.kernel.org linux-security-module@archiver.kernel.org
	public-inbox-index linux-security-module


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-security-module


AGPL code for this site: git clone https://public-inbox.org/ public-inbox