Skip to contentSkip to conversation

libsemanage: prevent string overflow on final paths

PATCH In review Stephen Smalley 2 participants 2 messages May 8, 2018 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsemanage: prevent string overflow on final paths

Verify that the final path does not exceed the size of the buffer before copying. This can only occur if an alternate path for the policy root and/or the policy store root has been specified and if the resulting path would exceed PATH_MAX. A similar check is already applied by semanage_make_final().

---
 libsemanage/src/semanage_store.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
libsemanage/src/semanage_store.c +6 -1
index bce648c4..f1984c50 100644
@@ -1597,7 +1597,12 @@ static int semanage_install_final_tmp(semanage_handle_t * sh)
 		/* skip genhomedircon if configured */
 		if (sh->conf->disable_genhomedircon &&
 		    i == SEMANAGE_FC_HOMEDIRS) continue;
-		
+
+		if (strlen(dst) >= sizeof(fn)) {
+			ERR(sh, "Unable to compose the final paths.");
+			status = -1;
+			goto cleanup;
+		}
 		strcpy(fn, dst);
 		ret = semanage_mkpath(sh, dirname(fn));
 		if (ret < 0) {
Signature · 1 line
2.14.3
#1 lore raw
Quoted 30 lines · Stephen Smalley

Verify that the final path does not exceed the size of the buffer before copying. This can only occur if an alternate path for the policy root and/or the policy store root has been specified and if the resulting path would exceed PATH_MAX. A similar check is already applied by semanage_make_final().

---
 libsemanage/src/semanage_store.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
libsemanage/src/semanage_store.c +6 -2
index bce648c4..f1984c50 100644
@@ -1597,7 +1597,12 @@ static int semanage_install_final_tmp(semanage_handle_t * sh)
                /* skip genhomedircon if configured */
                if (sh->conf->disable_genhomedircon &&
                    i == SEMANAGE_FC_HOMEDIRS) continue;
-
+
+               if (strlen(dst) >= sizeof(fn)) {
+                       ERR(sh, "Unable to compose the final paths.");
+                       status = -1;
+                       goto cleanup;
+               }
                strcpy(fn, dst);
                ret = semanage_mkpath(sh, dirname(fn));
                if (ret < 0) {
--
Quoted 2 lines

2.14.3

ack