36
Security Enhanced Linux: SELinux Emre Can Kucukoglu [email protected] Research & Development Engineer 05.02.2015

Security Enhanced Linux Overview

Embed Size (px)

Citation preview

Page 1: Security Enhanced Linux Overview

Security Enhanced Linux:SELinux

Emre Can [email protected]

Research & Development Engineer05.02.2015

Page 2: Security Enhanced Linux Overview

OutlineWhat is SELinuxWhat can SELinux doWhat can not SELinux doWhy should SELinux be usedGetting SELinuxSELinux modesBasic conceptsLinux user mappingLogging

MLS and MCSSELinux policiesUserland toolsPerformanceLicenseSELinux demo on FedoraQuestions about SELinuxReferences

2

Page 3: Security Enhanced Linux Overview

What is SELinux (1/1)Internal firewall between programs.Linux security module (LSM)

Others are smack, tomoyo, apparmor.Mandatory Access Control (MAC)

What subjects can access which objects.Subjects: users, programs.Objects: files, devices, sockets, etc.

3

Page 4: Security Enhanced Linux Overview

What can SELinux do (1/2)Prevents

processes from reading data and programs,bypassing application security mechanisms,executing untrustworthy programs,interfering with other processes in violation of the system security

policy.Confine the potential damage that can be caused by

malicious or flawed programs.

4

Page 5: Security Enhanced Linux Overview

What can SELinux do (2/2)Type enforcement

focuses on the SELinux type within a SELinux security context.

Role-based access controldecides which types (for processes) a role is allowed to have.

Multi-level securityclassification of data.

5

Page 6: Security Enhanced Linux Overview

What can not SELinux do (1/1)Resource limits are outside the scope of an access control

systems.grsecurity, cgroups, pam are recommended.

6

Page 7: Security Enhanced Linux Overview

Why should SELinux be used (1/1)In multifunctional systems, to seperate

functionalitiese.g. For webserver, email and dns server,e.g. For Arcelik smart tv, money transaction and

entertainment processes.e.g. For Arcelik yazarkasa, aygaz app. and yapikredi

app.

7

Page 8: Security Enhanced Linux Overview

Getting SELinux (1/5)SELinux support is already included in the

mainline Linux 2.6 kernel available from kernel.org

8

Page 9: Security Enhanced Linux Overview

Getting SELinux (2/5)SE-enabled Linux kernel

CONFIG_SECURITY_SELINUXNSA SELinux support.

DEFAULT_SECURITY_SELINUXSet default security mode as SELinux.

SECURITY_SELINUX_AVC_STATSCollect access vector caches.

CONFIG_SECURITY_SELINUX_BOOTPARAMAllows SELinux to be disabled at boot.

SECURITY_SELINUX_DEVELOPExperiment with SELinux and develop policies.

CONFIG_SECURITY_SELINUX_DISABLEAllows SELinux to be disabled at runtime.

9

Page 10: Security Enhanced Linux Overview

Getting SELinux (3/5)SELinux userland packages [gse]

checkpolicypolicy compiler.uses libsepol.

libselinuxlibrary for security-aware applications.uses libsepol.

libsemanagelibrary for policy management tools.uses libsepol, libselinux.

10

Page 11: Security Enhanced Linux Overview

Getting SELinux (4/5)SELinux userland packages [gse]

libsepollibrary for binary policy manipulation.no dependency.

policycoreutilsseveral policy-related utilities.uses libselinux, libsepol, libsemanage.

sepolgenpython library that forms the core of modern audit2allow.

11

Page 12: Security Enhanced Linux Overview

Getting SELinux (5/5)Policy

SELinux reference policy project [rpp]

12

Page 13: Security Enhanced Linux Overview

SELinux modes (1/2)Permissive

Log warnings instead of enforcing.CONFIG_SECURITY_SELINUX_DEVELOPextra: Permissive domain recipe [pdr]

EnforcedSecurity policy is enforced.

DisabledDo not load security policy.CONFIG_SECURITY_SELINUX_BOOTPARAMAdd selinux=0 to kernel bootline.

13

Page 14: Security Enhanced Linux Overview

SELinux modes (2/2)Temporarily switch:

# setenforce 1 /* Enforcing */# setenforce 0 /* Permissive */

Permanently:edit /etc/selinux/config

SELINUX=enforcingSELINUX=permissiveSELINUX=disabled

edit boot parameters (overrides configuration file)enforcing=0 /* Permissive */enforcing=1 /* Enforcing */selinux=0 /* Disabled */

SELINUX=enforcing

14

Page 15: Security Enhanced Linux Overview

Basic concepts (1/5)Security context

Every process and object has a context.Syntax: user:role:type[:range]

MLS range is optional.Inherited from processes (on fork) or parent files/directories.

UsersDiff. from linux users*

SELinux users do not change during a user session, whereas a Linux user might change via su or sudo.

suffix: *_u. e.g. user_uassociated to one or more roles that the SELinux user is allowed

to use.15

Page 16: Security Enhanced Linux Overview

Basic concepts (2/5)Roles

A SELinux user may be allowed to take on one or more roles.suffix: *_r. e.g. user_rassociated to one or more types the SELinux user is allowed to

access.Types

Determine access permission.suffix: *_t. e.g. music_tassociated with processes or objects.

AttributesGroup types with similar properties.

16

Page 17: Security Enhanced Linux Overview

Basic concepts (3/5)

17

RangesSecurity level.if policy supports MCS / MLS.

Object classesCategories of objects.

# ls /sys/fs/selinux/classEach class has a set of permissions. [ocp]

# ls /sys/fs/selinux/class/tcp_socket/perms/

RulesSpecified using the type of the process and object.e.g. allow user_t user_home_t:file { create read write };

Page 18: Security Enhanced Linux Overview

Basic concepts (4/5)

18

Booleansare used to enable/disable policies.# getsebool -a# sesearch -b selinuxuser_execheap -AC

ET allow user_t kernel_t : system syslog_read ; [ user_dmesg ]Rule will be allowed if corresponding boolean is true (T). And boolean is now enabled. (E)

Constraintsunder which circumstances an operation is allowed.circumstances that don't match are disallowed.# seinfo --constraine.g. constrain dir_file_class_set { create relabelto relabelfrom } (

u1 == u2 or t1 == can_change_object_identity );

Page 19: Security Enhanced Linux Overview

Basic concepts (5/5)

19

Type transitionfor objects (files):

# sesearch -Ttype_transition [Creating Subject type] [Parent Object/Subject Type] : [Class

of new Object/Subject] [New Object/Subject Type]for subjects (process):

# pstree -Z# sesearch -T -c processtype_transtion [Parent process type] [Type of process] : process [New type of

the process created]

Page 20: Security Enhanced Linux Overview

Linux user mapping (1/1)

20

Map a linux user to only one SELinux user. [ual]

Multiple linux users can be mapped to same SELinux user.

# semanage login -l# semanage login -a -s staff_u

emrecan

Page 21: Security Enhanced Linux Overview

Logging (1/1)Denials are logged in the audit subsystem.

/var/log/audit/audit.logPermissive mode generates more log

messages.# cat /var/log/audit/audit.log | audit2allow -r

21

Page 22: Security Enhanced Linux Overview

Multi-level security and MCS (1/2)

22

based on the Bell-La Padula model“no write down” and “no read up”

user:role:type:sensitivity [:category,...] - sensitivity [:category,...] | LEVEL | - | LEVEL | | RANGE |sensitivity: s0 lowest, s15 maximumcategory: optional, c0.c255.

unordered and unrelated lists of "compartments".

level: combination of sensitivity and category.

translate to human readable form in setrans.confs0 = unclassified, s15 = top secretc0 = finance, c100 = commercial, c255 = book

Page 23: Security Enhanced Linux Overview

Multi-level security and MCS (2/2)

23

utilization for android:app running on behalf of one user cannot read or write files created by the same

app running on behalf of another user.

in fact, MLS reference policy does not allow write-up, read-down.default is to use equal levels.

Page 24: Security Enhanced Linux Overview

SELinux policies (1/3)Compiled in a binary format.

smaller memory requirements.

Type enforcement file (*.te)mandatory.name, version of the module.types, rules, booleans, etc.

File contexts file (*.fc)contains the default security contexts to be provided for files created/used by the

application for which we are creating the policy module.

Interface file (*.if)generally would contain macro definitions that assist in creating type enforcement

rules. 24

Page 25: Security Enhanced Linux Overview

SELinux policies (2/3)3 steps to configure policy for embedded devices:

obtain reference policy,remove unnecessary rules,

have to remove too many rules.

add necessary rules.

25

Page 26: Security Enhanced Linux Overview

SELinux policies (3/3)Reference policy project [rpp]

basis for creating other policies.well-written and good enough for PC distros.many dependencies:

checkpolicypolicycoreutilslibsepollibsemanagepython

26

Page 27: Security Enhanced Linux Overview

Userland tools (1/4)id, ls, ps, netstat -Z

display context of shell, file, process, network.audit2allow

read SELinux denials, show corresponding rules.audit2why

determine why a denial occured.chcon

change context of a file.chcon -t user_home_t /tmp/osman

chcatchange categories of a file.change authorized categories for a user.

27

Page 28: Security Enhanced Linux Overview

Userland tools (2/4)getenforce

return status of SELinux.newrole

change role, type or level.newrole -r system_r -t unconfined_t

semanagechange boolean settings,change roles and levels for SELinux users,change context of a file persistently (restorecon)

semanage fcontext -a -t user_home_t /tmp/osmansemodule

insert, delete and list SELinux policy modules on the running system.

28

Page 29: Security Enhanced Linux Overview

Userland tools (3/4)setenforce

modify the mode.seinfo

policy query tool.setsebool

set the state of an SELinux boolean either temporarily or persistently.sestatus

status tool.

29

Page 30: Security Enhanced Linux Overview

Userland tools (4/4)restorecon, restorecond*

restores default context of a file.customizable types [wct]

context is not reset during a standard relabel operation.# cat /etc/selinux/targeted/contexts/customizable_types

runconchange context of a program when started (temporary)

runcon system_u:system_r:crond_t:s0:c0.c255 /bin/bashrun_init [gs]

start services in the correct domainrun_init /etc/init.d/ssh start

30

Page 31: Security Enhanced Linux Overview

Performance (1/1)Hard to measure.Overhead app~ 7% for completely untuned

code. [faq] [ffq]

31

Page 32: Security Enhanced Linux Overview

License (1/1)GNU General Public License (GPL) [sel]

32

Page 33: Security Enhanced Linux Overview

SELinux demo on Fedora (1/1)

33

Page 34: Security Enhanced Linux Overview

Questions about SELinux (1/1)Can I use SELinux with grsecurity (and PaX)?

Yes, even recommended. However grsecurity’s ACL support is not used together w/ SELinux. [gfq]

If root user can change, for example booleans, how is selinux more secure than DAC of linux?

i.e. setsebool -P allow_execheap on/offWe don't need to have conditional policy. If we do, the enabled/disabled rules are

defined in the policy. DAC doesn't have predefined conditions like that.Can we write a policy that doesn’t allow setenforce?

Yes, moreover we can even compile the kernel so permissive mode is disabled no matter what the policy says.

34

Page 35: Security Enhanced Linux Overview

References (1/2)[faq] http://www.crypt.gen.nz/selinux/faq.html[gse] https://github.com/SELinuxProject/selinux[gs] http://selinuxproject.org/page/Guide/Services[rpp] https://github.com/TresysTechnology/…[ocp] http://selinuxproject.org/page/ObjectCl…[pdr] http://selinuxproject.org/page/Permissi…[sqp] http://www.cs.virginia.edu/~jcg8f/SELi…

35

Page 36: Security Enhanced Linux Overview

References (2/2)[sel] https://www.nsa.gov/research/selinux/l...[ual] http://wiki.gentoo.org/wiki/SELinux/Use...[wct] http://wiki.gentoo.org/wiki/SELinux/Tuto...[gfq] http://wiki.gentoo.org/wiki/SELinux/FAQ[ffq] http://docs.fedoraproject.org/en-US/Fed…[use] http://www.fosteringlinux.com/category/…[nb4] http://taiga.selinuxproject.org/~rhaines/[mls] http://selinuxproject.org/page/MLSStat...

36