Skip to contentSkip to conversation

ssh/login

DISCUSSION Brian May 3 participants 9 messages May 1, 2003 – May 11, 2003 SELinux security module

lore
Share & tools
lore

Brian May

author
#0 lore raw

Hello,

If I boot a computer with SE-Linux but without the SE-Linux policy installed (in permissive mode obviously[1]), neither the SE-Linux patched ssh or login will let me login. It means that the only option I have is to reboot is single user mode, and downgrade these packages to non-SE-Linux versions.

This is because there are no valid security contexts available for me to log in with.

Is there anyway I can get ssh or login to completely disable SE-Linux support if SE-Linux is loaded but no policy is?

Alternatively, it there anyway I can login even though none of the valid security contexts I am allowed to use exist?

Notes:
[1] Interesting enough, in this setup, my computer no longer seems to be crashing.... I have since loaded a policy and it still hasn't crashed yet. Hmmm.. I think I will need to track try and isolate this further. I wonder if it will survive a reboot...

Signature · 6 lines
Brian May <[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.
#1 lore raw
Quoted 8 lines · Brian May

If I boot a computer with SE-Linux but without the SE-Linux policy installed (in permissive mode obviously[1]), neither the SE-Linux patched ssh or login will let me login. It means that the only option I have is to reboot is single user mode, and downgrade these packages to non-SE-Linux versions.

This is because there are no valid security contexts available for me to log in with.

This can also occur even if the policy has been loaded if the login or sshd executables have the wrong type, e.g. you updated them to new versions and forgot to relabel them to the proper entrypoint types. In that case, the login or sshd process will run in the wrong domain, so security_get_user_sids will report that there are no reachable user contexts from its domain. In the login case, you can prompt the user for a context in this case, but the sshd patch doesn't presently allow for such a user interaction for obtaining a context.

Quoted 2 lines

Is there anyway I can get ssh or login to completely disable SE-Linux support if SE-Linux is loaded but no policy is?

At present, is_flask_enabled() tests for the presence of SELinux using getsecsid, so the below patch would cause it to return 0 if the policy has not been loaded even though SELinux is present.

Index: lsm-2.4/security/selinux/syscalls.c
===================================================================
RCS file: /home/pal/CVS/lsm-2.4/security/selinux/syscalls.c,v retrieving revision 1.14

security/selinux/syscalls.c +4 -0
diff -u -r1.14 syscalls.c
@@ -41,6 +41,10 @@
 long sys_getsecsid(void) 
 {
 	struct task_security_struct *tsec;
+	extern int ss_initialized;
+
+	if (!ss_initialized)
+		return -ENOSYS;
 
 	tsec = current->security;
 	return tsec->sid;
Signature · 8 lines
Stephen Smalley <[email protected]>
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.
author
#2 lore raw
Quoted 8 lines · Stephen Smalley

Index: lsm-2.4/security/selinux/syscalls.c
===================================================================
RCS file: /home/pal/CVS/lsm-2.4/security/selinux/syscalls.c,v retrieving revision 1.14
diff -u -r1.14 syscalls.c

security/selinux/syscalls.c line 50

Quoted 10 lines
security/selinux/syscalls.c +4 -0
@@ -41,6 +41,10 @@
 long sys_getsecsid(void) 
 {
 	struct task_security_struct *tsec;
+	extern int ss_initialized;
+
+	if (!ss_initialized)
+		return -ENOSYS;
 
 	tsec = current->security;
 	return tsec->sid;

I can confirm that this patch works.

Thanks.

Signature · 6 lines
Brian May <[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.
#3 lore raw
Quoted 9 lines · Brian May

security/selinux/syscalls.c line 50

Quoted 7 lines
security/selinux/syscalls.c +4 -0
+	extern int ss_initialized;
+
+	if (!ss_initialized)
+		return -ENOSYS;
 
 	tsec = current->security;
 	return tsec->sid;

I can confirm that this patch works.

Works for me on ARM too.

Signature · 10 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page


--
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.
author
#4 lore raw

Re: kernel crashes

In reply to Brian May
Quoted 4 lines · Brian May

[1] Interesting enough, in this setup, my computer no longer seems to be crashing.... I have since loaded a policy and it still hasn't crashed yet. Hmmm.. I think I will need to track try and isolate this further. I wonder if it will survive a reboot...

If I boot 2.4.20 and load the SE-Linux policy *after* it boots, there are no problems. This is after several days (if not weeks actually) after building lots of packages, daily cron jobs, etc.

If I boot 2.4.20 *with* the SE-Linux policy it crashes after 5 to 30 minutes.

It is not a CPU starvation issue, it is more like every call to exec results in the process hanging. The 2nd time it happens, the process cannot be killed.

However, just to make matters more confusing, some processes do hang, but others don't. Most noteable, was exec's would die if run via a ssh session. I was almost about to say that it was sshd's fault, but then I killed all copies of ssh (which correctly closed all connections), and typed in sync, and sync hanged.

Signature · 6 lines
Brian May <[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.
#5 lore raw

Re: kernel crashes

Quoted 3 lines · Brian May

If I boot 2.4.20 and load the SE-Linux policy *after* it boots, there are no problems. This is after several days (if not weeks actually) after building lots of packages, daily cron jobs, etc.

I'm not sure why you are seeing this behavior; I haven't seen it myself. However, as a caveat, you have to load the policy early in order for processes (including init) to transition properly to their desired domains. If you are loading the policy late, I'd expect that a ps -e --context would show many processes in the wrong domain (i.e. just being left in the domain of the caller).

FYI, in the mainline 2.5-based SELinux, we've moved the initial policy load into userspace based on kernel developer feedback, and are currently performing it via an initrd (ultimately, we'd like to migrate to using initramfs). A copy of the binary policy file and load_policy program are placed on the initrd, and the /linuxrc script is modified to perform the initial policy load. The kernel no longer reads the binary policy directly from the file; the load_policy program opens+mmaps the policy file and then writes the data to a /selinux/load pseudo node to perform the load operation, similar to the new module interface in 2.5.

Signature · 8 lines
Stephen Smalley <[email protected]>
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.
author
#6 lore raw

Re: kernel crashes

Quoted 11 lines · Stephen Smalley
Quoted 3 lines · Brian May

If I boot 2.4.20 and load the SE-Linux policy *after* it boots, there are no problems. This is after several days (if not weeks actually) after building lots of packages, daily cron jobs, etc.

I'm not sure why you are seeing this behavior; I haven't seen it myself. However, as a caveat, you have to load the policy early in order for processes (including init) to transition properly to their desired domains. If you are loading the policy late, I'd expect that a ps -e --context would show many processes in the wrong domain (i.e. just being left in the domain of the caller).

Hmmm... I guess the next thing to consider is maybe one of the daemons causes the crash but only when it is in the correct context (as unlikely as it this seems).

Next time I reboot my computer, I will boot it in single user mode, and see if it still crashes with fewer daemons being loaded.

Quoted 9 lines

FYI, in the mainline 2.5-based SELinux, we've moved the initial policy load into userspace based on kernel developer feedback, and are currently performing it via an initrd (ultimately, we'd like to migrate to using initramfs). A copy of the binary policy file and load_policy program are placed on the initrd, and the /linuxrc script is modified to perform the initial policy load. The kernel no longer reads the binary policy directly from the file; the load_policy program opens+mmaps the policy file and then writes the data to a /selinux/load pseudo node to perform the load operation, similar to the new module interface in 2.5.

I have read with interest about this initramfs[1]. I have read the idea is that all special case startup code, eg mounting the root file system, NFS-Root code, initial networking code for NFS-Root, RAID initialization, etc, will get moved to user space. This suposedly will make the kernel simpler and easier to maintain.

The long term plan (although controversial[2], at least in the mailing list archives I read) is to force everything to be compiled as modules, and not allow these optional features to be compiled directly in the kernel. The idea is that this will result in less code that only deals with "special cases", making it harder for bugs to go undetected.

Personally, my only concern with initrd images is that the Debian initrd images are far to big to even consider putting on a 1.44Meg boot disk (at least those created with the mkinitrd script), I would hope that initramfs can be made small enough so that this is no longer a problem.

Notes:

[1] although I am still not sure how it is different from initrd.

[2] the people for this plan also had ideas on how to load modules at mkinitramfs time in such a way that you wouldn't get the normal memory management overhead of loading each module seperately.

Signature · 6 lines
Brian May <[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.
#7 lore raw

Re: kernel crashes

Quoted 3 lines · Brian May

Next time I reboot my computer, I will boot it in single user mode, and see if it still crashes with fewer daemons being loaded.

Good idea. Then try adding different types of load (disk IO, fork/exec, etc).

Quoted 5 lines

I have read with interest about this initramfs[1]. I have read the idea is that all special case startup code, eg mounting the root file system, NFS-Root code, initial networking code for NFS-Root, RAID initialization, etc, will get moved to user space. This suposedly will make the kernel simpler and easier to maintain.

Of course you can already do all of that in initrd in 2.4.x. I've been doing it for ages.

Quoted 4 lines

Personally, my only concern with initrd images is that the Debian initrd images are far to big to even consider putting on a 1.44Meg boot disk (at least those created with the mkinitrd script), I would hope that initramfs can be made small enough so that this is no longer a problem.

My initrd images are <850K on disk, my kernel images are <720K.

If I was inclined then I am sure that I could squeeze a kernel and initrd onto a single floppy disk formatted with 21 sectors per track.

Apparently the Debian initrd scripts now support tracking module dependencies (which I have been doing myself for years). Also for a while they have supported using your own program for creating the initrd file system (I use genromfs and gzip -9).

One thing I tried was to get busybox to work as the shell. I've been getting a lot of practise hacking busybox lately, so next time I try this I should be able to get it going. This could reduce the size of the initrd significantly.

If I dig up my cut-down SE policy for initrd's then I am sure that I could make a single 1.44M disk be a SE Linux boot disk with the new 2.5.x policydb-on-initramfs scheme once I get busybox sorted out.

Signature · 10 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page


--
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.
author
#8 lore raw

Re: kernel crashes

Quoted 6 lines · Russell Coker
Quoted 3 lines · Brian May

Next time I reboot my computer, I will boot it in single user mode, and see if it still crashes with fewer daemons being loaded.

Good idea. Then try adding different types of load (disk IO, fork/exec, etc).

My crashes only seem to occur when connecting to the computer via a ssh connection.

If I do stuff entirely on the console, with X/Gnome and without X, it hasn't crashed yet.

Its been a while since I logged on last with ssh, so I will have to do so again, and see if it causes it to crash again.

Signature · 6 lines
Brian May <[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.