Skip to contentSkip to conversation

apparmor: Fix error cod in __aa_fs_profile_mkdir()

PATCH In review Dan Carpenter 3 participants 4 messages May 23, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 apparmor: Fix error cod in __aa_fs_profile_mkdir()

We can either return PTR_ERR(NULL) or a PTR_ERR(a valid pointer) here. Returning NULL is probably not good, but since this happens at boot then we are probably already toasted if we were to hit this bug in real life. In other words, it seems like a very low severity bug to me.

security/apparmor/apparmorfs.c +4 -2
index 4f6ac9dbc65d..18f0d105084d 100644
@@ -728,8 +728,10 @@ int __aa_fs_profile_mkdir(struct aa_profile *profile, struct dentry *parent)
 		id_len = snprintf(NULL, 0, ".%ld", profile->ns->uniq_id);
 
 		profile->dirname = kmalloc(len + id_len + 1, GFP_KERNEL);
-		if (!profile->dirname)
-			goto fail;
+		if (!profile->dirname) {
+			error = -ENOMEM;
+			goto fail2;
+		}
 
 		mangle_name(profile->base.name, profile->dirname);
 		sprintf(profile->dirname + len, ".%ld", profile->ns->uniq_id++);
#1 lore raw

Am 23.05.2017 16:33, schrieb Dan Carpenter:

Quoted 14 lines

We can either return PTR_ERR(NULL) or a PTR_ERR(a valid pointer) here. Returning NULL is probably not good, but since this happens at boot then we are probably already toasted if we were to hit this bug in real life. In other words, it seems like a very low severity bug to me.

security/apparmor/apparmorfs.c +0 -0
index 4f6ac9dbc65d..18f0d105084d 100644
@@ -728,8 +728,10 @@ int __aa_fs_profile_mkdir(struct aa_profile *profile, struct dentry *parent)
 		id_len = snprintf(NULL, 0, ".%ld", profile->ns->uniq_id);
 

security/apparmor/apparmorfs.c int __aa_fs_profile_mkdir(struct aa_profile *profile, struct dentry *parent) · line 737

Quoted 10 lines
security/apparmor/apparmorfs.c +4 -2
 		profile->dirname = kmalloc(len + id_len + 1, GFP_KERNEL);
-		if (!profile->dirname)
-			goto fail;
+		if (!profile->dirname) {
+			error = -ENOMEM;
+			goto fail2;
+		}
 
 		mangle_name(profile->base.name, profile->dirname);
 		sprintf(profile->dirname + len, ".%ld", profile->ns->uniq_id++);

Can mangle_name made to return a propper string ?
IFF this can be reduced to

	profile->dirname =kasprintf(GFP_KERNEL,"%s.%ld",mangle_name(),profile->ns->uniq_id);
	if (!profile->dirname) ....

just a hint.

re,
wh

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#2 lore raw
Quoted 30 lines · walter harms

Am 23.05.2017 16:33, schrieb Dan Carpenter:

Quoted 14 lines

We can either return PTR_ERR(NULL) or a PTR_ERR(a valid pointer) here. Returning NULL is probably not good, but since this happens at boot then we are probably already toasted if we were to hit this bug in real life. In other words, it seems like a very low severity bug to me.

security/apparmor/apparmorfs.c +0 -0
index 4f6ac9dbc65d..18f0d105084d 100644
@@ -728,8 +728,10 @@ int __aa_fs_profile_mkdir(struct aa_profile *profile, struct dentry *parent)
 		id_len = snprintf(NULL, 0, ".%ld", profile->ns->uniq_id);
 

security/apparmor/apparmorfs.c int __aa_fs_profile_mkdir(struct aa_profile *profile, struct dentry *parent) · line 737

Quoted 10 lines
security/apparmor/apparmorfs.c +4 -2
 		profile->dirname = kmalloc(len + id_len + 1, GFP_KERNEL);
-		if (!profile->dirname)
-			goto fail;
+		if (!profile->dirname) {
+			error = -ENOMEM;
+			goto fail2;
+		}
 
 		mangle_name(profile->base.name, profile->dirname);
 		sprintf(profile->dirname + len, ".%ld", profile->ns->uniq_id++);

Can mangle_name made to return a propper string ?
IFF this can be reduced to

Quoted 5 lines
	profile->dirname =kasprintf(GFP_KERNEL,"%s.%ld",mangle_name(),profile->ns->uniq_id);
	if (!profile->dirname) ....

just a hint.

something of the sort could be done, but you would need to track the allocation returned from mangle_name so that it can be freed. But we can take this whole sequence and shove it into mangle_name and have it do the allocation, and return a string. It would clean things up. I'll cons together a patch for the next pull request.

maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Dan Carpenter
Quoted 6 lines · Dan Carpenter

We can either return PTR_ERR(NULL) or a PTR_ERR(a valid pointer) here. Returning NULL is probably not good, but since this happens at boot then we are probably already toasted if we were to hit this bug in real life. In other words, it seems like a very low severity bug to me.

yep,

and puled into my tree

Quoted 19 lines
security/apparmor/apparmorfs.c +4 -2
index 4f6ac9dbc65d..18f0d105084d 100644
@@ -728,8 +728,10 @@ int __aa_fs_profile_mkdir(struct aa_profile *profile, struct dentry *parent)
 		id_len = snprintf(NULL, 0, ".%ld", profile->ns->uniq_id);
 
 		profile->dirname = kmalloc(len + id_len + 1, GFP_KERNEL);
-		if (!profile->dirname)
-			goto fail;
+		if (!profile->dirname) {
+			error = -ENOMEM;
+			goto fail2;
+		}
 
 		mangle_name(profile->base.name, profile->dirname);
 		sprintf(profile->dirname + len, ".%ld", profile->ns->uniq_id++);