Skip to contentSkip to conversation

security: check for kstrdup() failure in lsm_append()

PATCH New Eric Biggers 2 participants 2 messages Jul 17, 2018 – Jul 18, 2018 Security (LSM)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 security: check for kstrdup() failure in lsm_append()

lsm_append() should return -ENOMEM if memory allocation failed.

Fixes d69dece5f5b6 ("LSM: Add /sys/kernel/security/lsm")
---
 security/security.c | 2 ++
 1 file changed, 2 insertions(+)
security/security.c +2 -0
index 03e98be76d58..259ff593d543 100644
@@ -121,6 +121,8 @@ static int lsm_append(char *new, char **result)
 
 	if (*result == NULL) {
 		*result = kstrdup(new, GFP_KERNEL);
+		if (*result == NULL)
+			return -ENOMEM;
 	} else {
 		/* Check if it is the last registered name */
 		if (match_last_lsm(*result, new))
Signature · 6 lines
2.18.0.203.gfac676dfb9-goog

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#1 lore raw

PATCH 1/1 security: check for kstrdup() failure in lsm_append()

Quoted 14 lines · Eric Biggers

lsm_append() should return -ENOMEM if memory allocation failed.

Fixes d69dece5f5b6 ("LSM: Add /sys/kernel/security/lsm")
---
 security/security.c | 2 ++
 1 file changed, 2 insertions(+)
security/security.c +0 -0
index 03e98be76d58..259ff593d543 100644

security/security.c static int lsm_append(char *new, char **result) · line 128

Quoted 8 lines
security/security.c +2 -0
@@ -121,6 +121,8 @@ static int lsm_append(char *new, char **result)
 
 	if (*result == NULL) {
 		*result = kstrdup(new, GFP_KERNEL);
+		if (*result == NULL)
+			return -ENOMEM;
 	} else {
 		/* Check if it is the last registered name */
 		if (match_last_lsm(*result, new))

Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security.git next-general

Signature · 7 lines
James Morris
<[email protected]>

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html