SELinux metadata protection
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 4 lines · KaiGai Kohei
It seems a bit curious behavior for me. Why can an unauthorized process be allowed to know whether the file exists or not ?
I think it's worthwhile to conceal the existence of files from unauthorized processes.
This behavior is also necessary for meeting the new medium robustness protection profiles.
Quoted 1 line
Thanks, any comments please, and have a good year :)
Haven't looked at the patch in detail, but the following stood out to me:
fs/readdir.c int vfs_readdir(struct file *file, filld · line 41
Quoted 13 lines
fs/readdir.c +5
-1@@ -33,7 +33,11 @@ int vfs_readdir(struct file *file, fillddown (&inode->i_sem); res = -ENOENT ;if (!IS_DEADDIR (inode)) { - res = file->f_op->readdir (file, buf, filler); +/* NOTE: +When LSM was not enable, security_file_readdir() +is same as 'file->f_op->readdir()'. +*/ + res =security_file_readdir (file, buf, filler);file_accessed (file);
I don't like this - the dir->f_op->readdir should not be done inside a function which claims to be a security check. Plus the added code doesn't have a return value of it's own. So why not stay closer to usual linux code and do something like
security_prep_readdir(); res = file->f_op->readdir(file, buf, filler);
inside vfs_readdir(), where security_prep_readdir() is defined away in the non-LSM case, and is
fs/readdir.c int vfs_readdir(struct file *file, filld
Quoted 7 lines
fs/readdir.c +7
-0+static inline void security_file_readdir (struct file *dir,void *buffer,filldir_t filler) +{ +security_filldir_t private; + + private.dir = dir; + private.buffer = buffer; + private.filler = filler;
in the LSM case?
thanks,
-serge
--
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.
Hi, thanks for your comments.
Quoted 10 lines · Serge E. Hallyn
Quoted 4 lines · KaiGai Kohei
It seems a bit curious behavior for me. Why can an unauthorized process be allowed to know whether the file exists or not ?
I think it's worthwhile to conceal the existence of files from unauthorized processes.This behavior is also necessary for meeting the new medium robustness protection profiles.
Hmm... I'm not so familiar with ISO-15408.
Do you know previous discussions about such behavior on filename resolving or readdir ?
Quoted 27 lines
fs/readdir.c int vfs_readdir(struct file *file, filld · line 41
Quoted 13 lines
fs/readdir.c +5
-1@@ -33,7 +33,11 @@ int vfs_readdir(struct file *file, fillddown (&inode->i_sem); res = -ENOENT ;if (!IS_DEADDIR (inode)) { - res = file->f_op->readdir (file, buf, filler); +/* NOTE: +When LSM was not enable, security_file_readdir() +is same as 'file->f_op->readdir()'. +*/ + res =security_file_readdir (file, buf, filler);file_accessed (file);I don't like this - the
dir->f_op->readdirshould not be done inside a function which claims to be a security check. Plus the added code doesn't have a return value of it's own. So why not stay closer to usual linux code and do something likesecurity_prep_readdir(); res = file->f_op->readdir(file, buf, filler);inside
vfs_readdir(), wheresecurity_prep_readdir()is defined away in the non-LSM case, and is
Quoted 10 lines
fs/readdir.c int vfs_readdir(struct file *file, filld
Quoted 7 lines
fs/readdir.c +7
-0+static inline void security_file_readdir (struct file *dir,void *buffer,filldir_t filler) +{ +security_filldir_t private; + + private.dir = dir; + private.buffer = buffer; + private.filler = filler;in the LSM case?
Indeed, file->f_op->readdir() need not necessary to be called inside LSM function. But overwriting 'filler' is necessary to check permission for each directory entry. I agree your suggestion if security_prep_readdir() is defined as macro, and this can overwrite 'filler' and 'buf'.
Pay attention to what 'filler' was overwritten in this patch.
When LSM is enable, FS's readdir method (dir->f_op->readdir) always calls 'security_file_filldir' for each directory entry instead of original 'filler' given by arguments.
When 'security_file_filldir' is called for authorized directory entry, it calls original 'filler' for writing the entry into userspace. But 'security_file_filldir' is called for unauthorized directory entry, it skips to call original 'filler'.
In the result, only authorized directory entries are returned to userspace.
The above code is necessary to implement such behavior.
* in normal casevfs_readdir()
-> FS's readdir method
- entry-1 -> filldir("entry-1")
- entry-2 -> filldir("entry-2")
:
- entry-N -> filldir("entry-N")
RESULT: all entries are returned to userspace.
* in metadata protection casevfs_readdir()
-> FS's readdir method
- entry-1 -> security_file_filldir("entry-1") -> filldir("entry-1), if permitted
- entry-2 -> security_file_filldir("entry-2") -> filldir("entry-2), if permitted :
- entry-N -> security_file_filldir("entry-N") -> filldir("entry-N), if permitted
RESULT: only authorized entries are returned to userspace.
Thanks,
# BTW, why doesn't deliver the first mail of this thread I posted in SELinux-list? --
KaiGai Kohei <[email protected]>
--
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.
Quoted 3 lines · KaiGai Kohei
Hmm... I'm not so familiar with ISO-15408.
Do you know previous discussions about such behavior on filename resolving or readdir ?
I can look around later in the week for past discussions (not sure whether there have been any), but at least here is the protection profile I'm talking about:
http://niap.nist.gov/cc-scheme/pp/PP_MLOSPP-MR_V1.22.html
Quoted 4 lines
Pay attention to what 'filler' was overwritten in this patch. When LSM is enable, FS's readdir method (
dir->f_op->readdir) always calls 'security_file_filldir'
for each directory entry instead of original 'filler' given by arguments.
Yes, I see, and I was being dense and misread it. So forget what I said before. But please add a good comment above the security_file_filldir definition. Also, the kernel community doesn't like typedefs, so please change
+typedef struct {
+ struct file *dir; + void *buffer; + filldir_t filler;
+} security_filldir_t;
to something like
+struct security_filldir_info {
+ struct file *dir; + void *buffer; + filldir_t filler;
+};
Do you have any performance measurements, say with selinux and with only capabilities compiled in, with and without this patch? I suspect that will be one of the most important points of contention if this goes to the linux-kernel list.
thanks,
-serge
--
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.
Hi,
Quoted 9 lines
Quoted 3 lines
Pay attention to what 'filler' was overwritten in this patch.
When LSM is enable, FS's readdir method (dir->f_op->readdir) always calls 'security_file_filldir' for each directory entry instead of original 'filler' given by arguments.Yes, I see, and I was being dense and misread it. So forget what I said before. But please add a good comment above the
security_file_filldirdefinition. Also, the kernel community doesn't like typedefs, so please change
OK, I'll modify the definition of 'security_filldir_t'.
Quoted 4 lines
Do you have any performance measurements, say with selinux and with only capabilities compiled in, with and without this patch? I suspect that will be one of the most important points of contention if this goes to the linux-kernel list.
I collected three performance measurements which includes kernel-build and two most extreme workload.
o Environment (My desktop PC)
CPU: Pentium4 2.4GHz (No-HT)
Mem: 1024MB
Kernel: 2.6.14.5-selinux / 2.6.14.5-selinux.mp
(stock 2.6.14.5 + NSA's patch ( + metadata protection patch))
GLIBC: glibc-2.3.5-10.3
o benchmark.1 - simple iteration of readdir()
by 'time -p for x in `seq 1 100`; do ls -R linux-2.6.14 > /dev/null; done'
The followings are avarage and standard deviation of 20 times trial.
* 2.6.14.5-selinux (without metadata protection)
real : 9.542 [sec] (std = 0.036)
user : 6.238 [sec] (std = 0.125)
sys : 3.253 [sec] (std = 0.124)* 2.6.14.5-selinux.mp (with metadata protection)
real : 11.920 [sec] (std = 0.015)
user : 6.293 [sec] (std = 0.111)
sys : 5.569 [sec] (std = 0.114)o benchmark.2 - iteration of resolving filename by attached short program. './a.out /lib/modules/2.6.14.5-selinux/build/security/selinux/hooks.c' The followings are average and standard diviation of 20 times trial.
* 2.6.14.5-selinux (without metadata protection)
Avg: 6.931 [sec] (std = 0.020)
* 2.6.14.5-selinux.mp (with metadata protection)
Avg: 8.528 [sec] (std = 0.096)o benchmark.3 - kernel-build by following commands. % tar jxvf linux-2.6.14.5.tar.bz2
% cd 2.6.14.5
% make defconfig
% time -p make -j 2
* 2.6.14.5-selinux (without metadata protection)
real: 391.14[sec] (user = 356.06[s], sys = 33.49[s])
* 2.6.14.5-selinux.mp (with metadata protection)
real: 406.09[sec] (user = 366.47[s], sys = 36.79[s])Thanks,
Signature · 1 line
KaiGai Kohei <[email protected]>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#define NLOOP 1000000
int main(int argc, char *argv[]) {
struct timeval start, end;
double interval;
int i;
if (argc != 2) {
fprintf(stderr, "usage: %s <filename>\n", argv[0]);
return 1;
}
/* iteration of stat() */
gettimeofday(&start, NULL);
for (i=0; i < NLOOP; i++) {
struct stat st_buf;
stat(argv[1], &st_buf);
}
gettimeofday(&end, NULL);
interval = (double)(1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec));
printf("%d times stat() : %f [s]\n", NLOOP, interval/1000000.0);
return 0;
}Quoted 21 lines · KaiGai Kohei
Hello,
Nowaday, I'm considering about a philosophical theme.
In my understanding, file-metadata includes _filename_ similar to filesize, update-timestamp, and so on. Most of permissions for reading metadata are defined as 'getattr' in SELinux.
But permission for reading filename is defined as 'read' of parent directory, 'getattr' of each child-entries are not evaluated.It seems a bit curious behavior for me. Why can an unauthorized process be allowed to know whether the file exists or not ?
I think it's worthwhile to conceal the existence of files from unauthorized processes.This patch enables to conceal the unauthorized files.
[1/2] LSM_metadata_protection_v1.patch
- addsecurity_file_readdir(), it's called whenreaddir()write each filename to userspace.
- addsecurity_inode_lookup(), it's called when filename is resolved bypath_walk().
Quoted 4 lines
[2/2] SELinux_metadata_protection_v1.patch
- add checking 'getattr' permission onfile_readdirandinode_lookuphooks.Thanks, any comments please, and have a good year :)
Hmm, a question on behavior.
Let's say hallyn_t is allowed to write /var (var_t), but not to do getattr on /var/secret_process_is_running (secret_t). If hallyn_t does ls /var/secret_process_is_running, he gets -ENOENT, but what should he get if he does 'touch /var/secret_process_is_running'? -EPERM obviously leaks information...
-serge
--
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.
Hi,
Quoted 7 lines
Hmm, a question on behavior.
Let's say
hallyn_tis allowed to write /var (var_t), but not to do getattr on/var/secret_process_is_running(secret_t). Ifhallyn_tdoes ls/var/secret_process_is_running, he gets-ENOENT, but what should he get if he does 'touch/var/secret_process_is_running'?-EPERMobviously leaks information...
In my implementation, -ENOENT can be returned if he tries to create new file with same name as existing unauthorized files. Becase resolving filename is done before DAC permission checking, and security_inode_lookup() is called inside path_walk(). (security_inode_permission() is called _after_ DAC permission checking.)
But I'm still thinking what is appropriate error code...
# I don't know whether it's true or not. I've heard that commercial Trusted OS
# creates a new file in separated namespace on such a situation. # But it's obviously out of the scope of SELinux, I think.
Thanks,
Signature · 6 lines
KaiGai Kohei <[email protected]> -- 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.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · Crispin Cowan
Quoted 8 lines · Serge E. Hallyn
Hmm, a question on behavior.
Let's say
hallyn_tis allowed to write /var (var_t), but not to do getattr on/var/secret_process_is_running(secret_t). Ifhallyn_tdoes ls/var/secret_process_is_running, he gets-ENOENT, but what should he get if he does 'touch/var/secret_process_is_running'?-EPERMobviously leaks information...
Quoted 8 lines
If you create a file whose existence is supposed to be secret, and you put it in a public directory, then you have made a mistake, because the file's existence is always detectable.
Suppose we create file in
/var/nothingtoseehere. The adversary can create any file they want, *except* for/var/nothingtoseehere, which will return some kind of error message (doesn't matter which error). From this, the attacker can infer the existence of the file, and its name.
Right. Of course we could solve this with a custom polyinstantiated filesystem, which might even be pretty simple to do as either a stackable fs around a real one, or a userspace filesystem. It would simply create a new entry for /var/nothingtoseehere with the creator's context, so that when a process in that context did ls /var, it would see the new file. I was wondering whether there are any other tricks we could play.
Sounds like no :)
And as you point out, if we don't solve this, there's no point returning -ENOENT on ls /var.
thanks,
-serge
--
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.