Skip to contentSkip to conversation

bug in SE Linux / LSM

DISCUSSION Russell Coker 2 participants 2 messages Sep 5, 2002 SELinux security module

lore
Share & tools
lore
#0 lore raw

In my tutorial yesterday a Robert Dorn <[email protected]> discovered a bug in the way SE Linux/LSM operates.

If you login to a virtual console as an unpriviledged user you can use "loadkeys" to change the keyboard mapping for everything apart from the SAK sequence.

This can allow you to arbitarily re-program the keyboard which can make it impossible to login (define it such that there is no ENTER key) or so that a common key performs a bad function such as "; mkfs /dev/hda".

You can do this whenever you are logged in at the console, but if there are a number of virtual consoles open then you could change to a console that's not commonly used and then run a program that takes input from the network to determine keyboard mappings (and then wait for someone to login at the console and control what they can do).

One partial solution to this is to have a getty wrapper which runs "loadkeys -d", which solves the problem of a hostile user remapping the keyboard and logging out. But it doesn't solve the problem of a hostile user remapping the keyboard from a program that's still in a login session on another virtual console.

One potential solution to this would be to have the SAK sequence trigger a relabel of all the devices that have getty's to their default type before running "loadkeys -d". Then you just have to get into the habit of "SAK before login" (which you should have anyway).

But it would be better if we could just catch such remappings in SE policy, in 99% of all machines there is no cause for the user to remap the keyboard.

Signature · 3 lines
I do not get viruses because I do not use MS software.
If you use Outlook then please do not put my email address in your
address-book so that WHEN you get a virus it won't use my address in the
Quoted 1 line

From field.

--
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 9 lines · Russell Coker

In my tutorial yesterday a Robert Dorn <[email protected]> discovered a bug in the way SE Linux/LSM operates.

If you login to a virtual console as an unpriviledged user you can use "loadkeys" to change the keyboard mapping for everything apart from the SAK sequence.

But it would be better if we could just catch such remappings in SE policy, in 99% of all machines there is no cause for the user to remap the keyboard.

This issue is mentioned in the BUGS section of the loadkeys(1) man page, although it doesn't appear to be entirely accurate. If I understand correctly, the relevant kernel code is the handling of the KDSKBENT ioctl in drivers/char/vt.c. The base kernel code appears to permit the use of this ioctl as long as the process is the owner of the tty or the process has CAP_SYS_TTY_CONFIG (2.5) or the process is root (2.4, legacy superuser check). The base kernel code further limits the ability to remap the SAK by requiring CAP_SYS_ADMIN.

LSM hooks capable() and SELinux performs a parallel check for each capability check, but that doesn't affect the code path when no capability is checked (any non-SAK remapping by the owner or root in 2.4, any non-SAK remapping by the owner of the tty in 2.5). LSM does provide a hook in sys_ioctl could be used to control this operation based on the file and command (but not the argument, as it is a userspace pointer in this case). At present, SELinux only implements specific permission checks for a small set of ioctls that are generic operations or ext[23]-specific. All other ioctls merely cause a check of the generic 'ioctl' permission to the file.

We could implement an additional check for this particular ioctl in the SELinux ioctl hook function, either using an existing capability or defining a new permission for this purpose. More generally, you would really want to perform an audit of all ioctls relevant to your kernel configuration.

--
Stephen D. Smalley, NAI Labs
[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.