Skip to contentSkip to conversation

Genfscon and cramfs issue

DISCUSSION korkishko Tymur 2 participants 3 messages Oct 15, 2008 – Oct 16, 2008 SELinux security module

lore
Share & tools
lore
#0 lore raw

According to my understanding, on the step of creating cramfs image, all files that will go into that image are analyzed by mkcramfs software.
If identical files are found, only single copy of the file is compressed and preserved in the image. Filesystem entry point (inode) on cramfs image has information about path names of the same files. I suspect that cramfs implementation in kernel dynamically searches for file names and provides them from the single inode.

If I type ls -i command in Linux (to list inodes for files) for cramfs filesystem that contains identical files file_one and file_two located in different directories (dir_one and dir_two) I will get output like that:
#ls -li dir_one
756 -r--r--r-- 1 user user 1234 date time file_one
#ls -li dir_two
756 -r--r--r-- 1 user user 1234 date time file_two
So, inode number is the same for the two files. Same is applied to the case if two files are within the same directory.

Tymur Korkishko
Samsung Electronics

------- Original Message -------
Sender : Stephen Smalley<[email protected]>
Date : Oct 15, 2008 21:58 (GMT+09:00)
Title : Re: Genfscon and cramfs issue

Quoted 14 lines · Stephen Smalley
Quoted 13 lines · korkishko Tymur

I have discovered an issue with using genfscon for labeling cramfs filesystem.

I have Linux kernel 2.6.26 with a patch from NSA that allows genfscon support of security contexts for directories/files (others than/ ). I use genfscon to label files/directories on cramfsfilesystem(read-only filesystem) that does not support xattr.

Cramfs filesystem has following behavior: for two files with different names but with the same file content it assigns single inode. Example:
genfscon cramfs /usr/file_one user_u:system_r:file_one_t
genfscon cramfs /usr/file_two user_u:system_r:file_two_t

file-one and file-two have the same content (e.g. Hello world). file-one and file-two share the same inode on cramfs.

Quoted 8 lines
Quoted 5 lines

As a result, two files might have the _same_ security context - either ...:file_one_t or ...:file_two_t. If file /usr/file_one is accessed first, user_u:system_r:file_one_t is used for both files. If file /usr/file_two is accessed first, user_u:system_r:file_two_t is used for both files.

Any ideas how to fix/deal with that issue are welcomed.

Why use two different security context for files that have the same content?

Oh, and what is responsible for the aliasing of the files here - the program that creates the cramfs image originally or the kernel&#39;s cramfs filesystem implementation itself?

Signature · 14 lines
Stephen Smalley
National Security Agency


 
 
 
 


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw
Quoted 3 lines · korkishko Tymur

According to my understanding, on the step of creating cramfs image, all files that will go into that image are analyzed by mkcramfs software. If identical files are found, only single copy of the file is
compressed and preserved in the image.

I suspect that mkcramfs is responsible for creating the two links as hard links to the same inode when it creates the image. So I would suggest looking into mkcramfs and see if you can modify it or invoke it with options to not hard link the files you want to keep separate.

Quoted 14 lines

Filesystem entry point (inode) on cramfs image has information about
path names of the same files. I suspect that cramfs implementation in kernel dynamically searches for file names and provides them from the single inode.

If I type ls -i command in Linux (to list inodes for files) for cramfs filesystem that contains identical files file_one and file_two located in different directories (dir_one and dir_two) I will get output like that:
#ls -li dir_one
756 -r--r--r-- 1 user user 1234 date time file_one
#ls -li dir_two
756 -r--r--r-- 1 user user 1234 date time file_two
So, inode number is the same for the two files. Same is applied to the case if two files are within the same directory.

Tymur Korkishko
Samsung Electronics

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw
Quoted 9 lines · Stephen Smalley
Quoted 3 lines · korkishko Tymur

According to my understanding, on the step of creating cramfs image, all files that will go into that image are analyzed by mkcramfs software. If identical files are found, only single copy of the file is
compressed and preserved in the image.

I suspect that mkcramfs is responsible for creating the two links as hard links to the same inode when it creates the image. So I would suggest looking into mkcramfs and see if you can modify it or invoke it with options to not hard link the files you want to keep separate.

I looked at the mkfs.cramfs.c source code in util-linux-ng (disk-utils/mkfs.cramfs.c) and it has an eliminate_doubles() function that scans for duplicate files and coalesces them to save space in the image. So you could change or skip that function to avoid coalescing files that you need to keep separate. It appears to entirely be a userland issue for saving space in the image, not a kernel issue.

Quoted 15 lines
Quoted 14 lines

Filesystem entry point (inode) on cramfs image has information about
path names of the same files. I suspect that cramfs implementation in kernel dynamically searches for file names and provides them from the single inode.

If I type ls -i command in Linux (to list inodes for files) for cramfs filesystem that contains identical files file_one and file_two located in different directories (dir_one and dir_two) I will get output like that:
#ls -li dir_one
756 -r--r--r-- 1 user user 1234 date time file_one
#ls -li dir_two
756 -r--r--r-- 1 user user 1234 date time file_two
So, inode number is the same for the two files. Same is applied to the case if two files are within the same directory.

Tymur Korkishko
Samsung Electronics

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.