Skip to contentSkip to conversation

Fix bug in persistent label mapping code

PATCH New Stephen Smalley 1 participant 1 message Sep 24, 2002 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix bug in persistent label mapping code

The attached patch, also committed to the sourceforge CVS tree, fixes a bug in the persistent label mapping code when writing to the mapping files. To apply, save the patch to ~/psid_write.patch, cd lsm-2.4 && patch -p1 < ~/psid_write.patch. Then rebuild your kernel.

--
Stephen D. Smalley, NAI Labs
[email protected]

Index: lsm-2.4/security/selinux/psid.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/security/selinux/psid.c,v retrieving revision 1.4

security/selinux/psid.c +15 -3
diff -u -r1.4 psid.c
@@ -52,7 +52,14 @@
 }
 static inline ssize_t write_abs(struct file *fp, const char *buf, size_t len, loff_t off) 
 {
-  return fp->f_op->write(fp, buf, len, &off);
+	unsigned long limit;
+	ssize_t rc;
+
+	limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
+	current->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
+	rc = fp->f_op->write(fp, buf, len, &off);
+	current->rlim[RLIMIT_FSIZE].rlim_cur = limit;
+	return rc;
 }
 
 
@@ -445,6 +452,10 @@
 	char *cbuf;
 	int rc = 0;
 
+	/* Initialize the root directory SID before the lookup.
+	   This will be changed down below once we know the real SID. */
+	inode_security_set_sid(sb->s_root->d_inode, SECINITSID_FILE);
+
 	DPRINTF("psidfiles_init:  looking up %s\n", PSEC_SECDIR);
 	dir = lookup_one_len(PSEC_SECDIR, sb->s_root, strlen(PSEC_SECDIR));
 	rc = PTR_ERR(dir);
@@ -495,7 +506,7 @@
 
 			dput(dir);
 
-			rc = security_fs_sid((char *)kdevname(sb->s_dev), 
+			rc = security_fs_sid((char *)kdevname(to_kdev_t(sb->s_dev)), 
 					     &fs_sid, &file_sid);
 			if (rc) 
 				goto bad;
@@ -589,7 +600,7 @@
 		 */
 		DPRINTF("psidfiles_init:  initializing labeling files\n");
 
-		rc = security_fs_sid((char*)kdevname(sb->s_dev), 
+		rc = security_fs_sid((char*)kdevname(to_kdev_t(sb->s_dev)), 
 				     &fs_sid, &file_sid);
 		if (rc)
 			goto bad;
@@ -1017,6 +1028,7 @@
 		       inode->i_ino * sizeof(psid_t));
 	set_fs(old_fs);
 	if (rc < 0) {
+		printk("sid_to_psid:  write_abs failed, rc=%d (dev=%s ino=%ld), offset %ld\n", -rc, kdevname(to_kdev_t(inode->i_dev)), inode->i_ino, inode->i_ino * sizeof(psid_t));
 		psidtab_put(sbsec, t);
 		return rc;
 	}