Skip to contentSkip to conversation

libselinux/policyvers

PATCH Chris PeBenito 1 participant 1 message Mar 29, 2004 SELinux security module

lore
Share & tools
lore
#0 lore raw

Attached is a suggested patch for libselinux/src/policyvers.c. It adds an errno check when the open() for /selinux/policyvers fails. If its ENOENT, it returns the default policy version, for the case that its a older kernel that doesn't have policyvers on selinuxfs. Otherwise, it returns -1, so the caller can know that its actually failed, rather than returning a possibly incorrect policy version.

Signature · 8 lines
Chris PeBenito
<[email protected]>
Developer,
Hardened Gentoo Linux
Embedded Gentoo Linux
 
Public Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE6AF9243
Key fingerprint = B0E6 877A 883F A57A 8E6A  CB00 BC8E E42D E6AF 9243

Index: src/policyvers.c
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux-usr/libselinux/src/policyvers.c,v retrieving revision 1.2

policyvers.c +6 -2
diff -u -r1.2 policyvers.c
@@ -20,8 +20,12 @@
 
 	snprintf(path, sizeof path, "%s/policyvers", selinux_mnt);
 	fd = open(path, O_RDONLY);
-	if (fd < 0)
-		return vers;
+	if (fd < 0) {
+		if (errno == ENOENT)
+			return vers;
+		else
+			return -1;
+	}
 	memset(buf, 0, sizeof buf);
 	ret = read(fd, buf, sizeof buf-1);
 	close(fd);