Skip to contentSkip to conversation

apparmor: enforce nullbyte at end of tag string

PATCH In review Jann Horn 2 participants 2 messages May 28, 2019

Subsystems (2)
lore
Share & tools
lore

Jann Horn

author
#0 lore raw

PATCH 1/1 apparmor: enforce nullbyte at end of tag string

A packed AppArmor policy contains null-terminated tag strings that are read by unpack_nameX(). However, unpack_nameX() uses string functions on them without ensuring that they are actually null-terminated, potentially leading to out-of-bounds accesses.

Make sure that the tag string is null-terminated before passing it to strcmp().

---
Warning: The existence of this bug has not been verified at runtime, and the patch is compile-tested only. I noticed this while browsing through the code, but didn't want to spend the time necessary to figure out how to actually test this at runtime.

 security/apparmor/policy_unpack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/apparmor/policy_unpack.c +1 -1
index f6c2bcb2ab14..33041c4fb69f 100644
@@ -276,7 +276,7 @@ static bool unpack_nameX(struct aa_ext *e, enum aa_code code, const char *name)
 		char *tag = NULL;
 		size_t size = unpack_u16_chunk(e, &tag);
 		/* if a name is specified it must match. otherwise skip tag */
-		if (name && (!size || strcmp(name, tag)))
+		if (name && (!size || tag[size-1] != '\0' || strcmp(name, tag)))
 			goto fail;
 	} else if (name) {
 		/* if a name is specified and there is no name tag fail */
Signature · 1 line
2.22.0.rc1.257.g3120a18244-goog
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jann Horn

A packed AppArmor policy contains null-terminated tag strings that are read by unpack_nameX(). However, unpack_nameX() uses string functions on them without ensuring that they are actually null-terminated, potentially leading to out-of-bounds accesses.

Make sure that the tag string is null-terminated before passing it to strcmp().

gah! yes!

Quoted 24 lines

---
Warning: The existence of this bug has not been verified at runtime, and the patch is compile-tested only. I noticed this while browsing through the code, but didn't want to spend the time necessary to figure out how to actually test this at runtime.

 security/apparmor/policy_unpack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/apparmor/policy_unpack.c +1 -1
index f6c2bcb2ab14..33041c4fb69f 100644
@@ -276,7 +276,7 @@ static bool unpack_nameX(struct aa_ext *e, enum aa_code code, const char *name)
 		char *tag = NULL;
 		size_t size = unpack_u16_chunk(e, &tag);
 		/* if a name is specified it must match. otherwise skip tag */
-		if (name && (!size || strcmp(name, tag)))
+		if (name && (!size || tag[size-1] != '\0' || strcmp(name, tag)))
 			goto fail;
 	} else if (name) {
 		/* if a name is specified and there is no name tag fail */