Skip to contentSkip to conversation

is this pretty much it (to patch kdm 3.2.2)?

PATCH Luke Kenneth Casson Leighton 5 participants 19 messages May 19, 2004 – May 20, 2004 SELinux security module

lore
Share & tools
lore
#0 lore raw

is this pretty much all that's required??? compared to the 2.4 stuff it's like tiny.

this is all that the patch to wdm does. i'm just a little surprised (pleasantly so).

l.

backend/client.c renamed from client.c.old +24 -0
@@ -44,6 +44,12 @@
 #include <sys/stat.h>
 #include <pwd.h>
 #include <grp.h>
+
+#ifdef WITH_SELINUX
+#include <selinux/get_context_list.h>
+#include <selinux/selinux.h>
+#endif
+
 #ifdef SECURE_RPC
 # include <rpc/rpc.h>
 # include <rpc/key_prot.h>
@@ -1085,6 +1091,24 @@
 	   systemEnviron);
 
     /*
+     * for Security Enhanced Linux,
+     * set the default security context for this user.
+     */
+#ifdef WITH_SELINUX
+   if (is_selinux_enabled())
+   {
+        security_context_t scontext;
+        if (get_default_context(name,NULL,&scontext))
+             LogError("Failed to get default security context for %s.", name);
+        Debug("setting security context to %s", scontext);
+        if (setexeccon(scontext)) {
+             freecon(scontext);
+             LogError("Failed to set exec security context %s for %s.", scontext, name);
+        }
+        freecon(scontext);
+   }
+#endif
+    /*
      * for user-based authorization schemes,
      * add the user to the server's allowed "hosts" list.
      */
Signature · 15 lines
-- 
expecting email to be received and understood is a bit like
picking up the telephone and immediately dialing without
checking for a dial-tone; speaking immediately without listening
for either an answer or ring-tone; hanging up immediately and
believing that you have actually started a conversation.
--
<a href="http://lkcl.net">      lkcl.net      </a> <br />
<a href="mailto:[email protected]"> [email protected] </a> <br />


--
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

backend/client.c

Quoted 8 lines · Luke Kenneth Casson Leighton

is this pretty much all that's required??? compared to the 2.4 stuff it's like tiny.

this is all that the patch to wdm does. i'm just a little surprised (pleasantly so).

backend/client.c renamed from client.c.old +0 -0

<snip patch>

I don't think that even this is required. It should work without patching, just using pam_selinux.so.

Thomas

--
http://www.cip.ifi.lmu.de/~bleher/selinux/ - my SELinux pages
GPG-Fingerprint: BC4F BB16 30D6 F253 E3EA D09E C562 2BAE B2F4 ABE7

--
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 7 lines · Thomas Bleher
Quoted 6 lines · Luke Kenneth Casson Leighton

is this pretty much all that's required??? compared to the 2.4 stuff it's like tiny.

this is all that the patch to wdm does. i'm just a little surprised (pleasantly so).

Quoted 6 lines

backend/client.c

Quoted 2 lines
backend/client.c renamed from client.c.old +0 -0

<snip patch>

I don't think that even this is required. It should work without patching, just using pam_selinux.so.

oh?

do you have some example usage that i can try out, and does anyone have any advice on how to ensure that installation of debian packages (pam and selinux and kde) would result in pam being automatically updated?

sincerely,

l.

--
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.

#12 lore raw
In reply to Thomas Bleher
Quoted 2 lines · Thomas Bleher

I don't think that even this is required. It should work without patching, just using pam_selinux.so.

At least for gdm, we weren't able to use pam_selinux, because the pam_open_session is called from the wrong process to set up the exec context for the desired child.

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.
#13 lore raw
In reply to Luke Kenneth Casson Leighton

backend/client.c line 1098

Quoted 2 lines · Luke Kenneth Casson Leighton
backend/client.c renamed from client.c.old +2 -0
+#ifdef WITH_SELINUX
+   if (is_selinux_enabled())

Should be if (is_selinux_enabled() > 0)

backend/client.c line 1102

Quoted 2 lines
backend/client.c renamed from client.c.old +2 -0
+        if (get_default_context(name,NULL,&scontext))
+             LogError("Failed to get default security context for %s.", name);

Does LogError exit? If not, you need to return here.

backend/client.c line 1106

Quoted 4 lines
backend/client.c renamed from client.c.old +4 -0
+        Debug("setting security context to %s", scontext);
+        if (setexeccon(scontext)) {
+             freecon(scontext);
+             LogError("Failed to set exec security context %s for %s.", scontext, name);

As above, does LogError exit?

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.
#14 lore raw
Quoted 5 lines · Stephen Smalley

backend/client.c line 1098

Quoted 2 lines · Luke Kenneth Casson Leighton
backend/client.c renamed from client.c.old +2 -0
+#ifdef WITH_SELINUX
+   if (is_selinux_enabled())

Should be if (is_selinux_enabled() > 0)

ah, oops, then the wdm patch needs likewise mods.

Quoted 4 lines

backend/client.c line 1102

Quoted 2 lines
backend/client.c renamed from client.c.old +2 -0
+        if (get_default_context(name,NULL,&scontext))
+             LogError("Failed to get default security context for %s.", name);

Does LogError exit? If not, you need to return here.

no, it's just a printf wrapper.

Quoted 6 lines

backend/client.c line 1106

Quoted 4 lines
backend/client.c renamed from client.c.old +4 -0
+        Debug("setting security context to %s", scontext);
+        if (setexeccon(scontext)) {
+             freecon(scontext);
+             LogError("Failed to set exec security context %s for %s.", scontext, name);

As above, does LogError exit?

hm, then does the wdm patch need the same attention?

l.

--
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.

#15 lore raw
In reply to Luke Kenneth Casson Leighton
Quoted 2 lines · Luke Kenneth Casson Leighton

is this pretty much all that's required???  compared to the 2.4 stuff it's like tiny.

In addition to the issues Steve mentioned, there is (or was) another problem. There were compilation problems with the SE Linux headers last time I tried to compile kdm. As kdm is in the middle of a huge package that takes ages to compile I hadn't got around to trying to compile it recently. In your message you didn't mention whether you successfully compiled the code with the patch in question. Does it compile?

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.
#16 lore raw
Quoted 10 lines · Russell Coker
Quoted 2 lines · Luke Kenneth Casson Leighton

is this pretty much all that's required??? ?compared to the 2.4 stuff it's like tiny.

In addition to the issues Steve mentioned, there is (or was) another problem. There were compilation problems with the SE Linux headers last time I tried to compile kdm. As kdm is in the middle of a huge package that takes ages to compile I hadn't got around to trying to compile it recently. In your message you didn't mention whether you successfully compiled the code with the patch in question. Does it compile?

well, it does now, because i cheated.

i don't have automake-1.8.3 installed and if you install automake 1.8.5 it corrupts things (misses out a .moc file, aclocal bitches about some incompatibilities, and it all just goes horribly pearshaped)

if you _don't_ run automake then any modifications to Makefile.am of course don't get propagated into Makefiles.in and of course then configure --enable-selinux doesn't work.

... so i cheated:

after doing an apt-get source kdm and apt-get build-dep kdm:

1) i installed automake 1.8.5

2) i made the necessary patches to configure.in, configure.in.in, kdm/backend/Makefile.am

3) i ran aclocal; autoheader; automake --add-missing; autoconf

4) i made a backup of kdm/backend/Makefile.in and .am and other modified fils

5) i DELETED the entire kdebase-3.2.2 tree

6) i REINSTALLED the kdebase-3.2.2 tree

7) i COPIED the backups BACK to their locations

8) i ran autoconf (NOT automake and NOT aclocal)

9) i did a dpkg-buildpackage

repeat 9) darn it to heck because i hadn't added SessionExit at the appropriate points if get_default_context() failed, and also the username is stored in a variable curuser whereas in the wdm patch it's stored in a different local variable arg.

l.

backend/client.c renamed from orig/kdebase-3.2.2/kdm/backend/client.c +28 -0
@@ -44,6 +44,12 @@
 #include <sys/stat.h>
 #include <pwd.h>
 #include <grp.h>
+
+#ifdef WITH_SELINUX
+#include <selinux/get_context_list.h>
+#include <selinux/selinux.h>
+#endif
+
 #ifdef SECURE_RPC
 # include <rpc/rpc.h>
 # include <rpc/key_prot.h>
@@ -1085,6 +1091,28 @@
 	   systemEnviron);
 
     /*
+     * for Security Enhanced Linux,
+     * set the default security context for this user.
+     */
+#ifdef WITH_SELINUX
+   if (is_selinux_enabled() > 0)
+   {
+        security_context_t scontext;
+        if (get_default_context(curuser,NULL,&scontext))
+		{
+             LogError("Failed to get default security context for %s.", curuser);
+             SessionExit (EX_NORMAL);
+		}
+        Debug("setting security context to %s", scontext);
+        if (setexeccon(scontext)) {
+             freecon(scontext);
+             LogError("Failed to set exec security context %s for %s.", scontext, curuser);
+             SessionExit (EX_NORMAL);
+        }
+        freecon(scontext);
+   }
+#endif
+    /*
      * for user-based authorization schemes,
      * add the user to the server's allowed "hosts" list.
      */
configure.in.in renamed from orig/kdebase-3.2.2/configure.in.in +21 -0
@@ -196,3 +196,24 @@
 #define AVOID_XKB                 /* for konsole to avoid XKB and XTEST */
 #endif
 ])
+
+AC_MSG_CHECKING(for SELinux support)
+AC_ARG_ENABLE(selinux,
+   AC_HELP_STRING([--enable-selinux], [enable SELinux support]),
+   [
+       AC_MSG_RESULT(yes)
+       AC_CHECK_LIB(selinux, is_selinux_enabled, [SELINUX_LDFLAGS="-lselinux"
+           AC_DEFINE_UNQUOTED(HAVE_SELINUX_LIB, 1, [Define if libselinux is installed])
+               AC_DEFINE(WITH_SELINUX, 1, [Define if you want wdm to be compiled with SELinux support])
+               SELINUX_CFLAGS="-DWITH_SELINUX -I/usr/include/selinux"
+               ],
+               [
+               AC_MSG_WARN([libselinux not found, compiling without SELinux support])
+               ])
+   ],
+   [
+       AC_MSG_RESULT(no)
+   ])
+AC_SUBST(SELINUX_LDFLAGS)
+AC_SUBST(SELINUX_CFLAGS)
+
configure.in renamed from orig/kdebase-3.2.2/configure.in +21 -0
@@ -261,6 +263,27 @@
 #define AVOID_XKB                 /* for konsole to avoid XKB and XTEST */
 #endif
 ])
+
+AC_MSG_CHECKING(for SELinux support)
+AC_ARG_ENABLE(selinux,
+   AC_HELP_STRING([--enable-selinux], [enable SELinux support]),
+   [
+       AC_MSG_RESULT(yes)
+       AC_CHECK_LIB(selinux, is_selinux_enabled, [SELINUX_LDFLAGS="-lselinux"
+           AC_DEFINE_UNQUOTED(HAVE_SELINUX_LIB, 1, [Define if libselinux is installed])
+               AC_DEFINE(WITH_SELINUX, 1, [Define if you want wdm to be compiled with SELinux support])
+               SELINUX_CFLAGS="-DWITH_SELINUX -I/usr/include/selinux"
+               ],
+               [
+               AC_MSG_WARN([libselinux not found, compiling without SELinux support])
+               ])
+   ],
+   [
+       AC_MSG_RESULT(no)
+   ])
+AC_SUBST(SELINUX_LDFLAGS)
+AC_SUBST(SELINUX_CFLAGS)
+
 dnl =======================================================
 dnl FILE: ./kappfinder/configure.in.in
 dnl =======================================================
rules renamed from orig/kdebase-3.2.2/debian/rules +1 -1
@@ -72,7 +72,7 @@
 
 	# run configure with build tree $(objdir)
 	cd $(objdir) && \
-	../configure $(configkde) --enable-final \
+	../configure $(configkde) --enable-final --enable-selinux \
 	--with-shadow --without-java \
 	--with-pam=kde --with-kcp-pam=kcheckpass \
 	--with-kdm-pam=kdm --with-kss-pam=kscreensaver
#17 lore raw

kdm 3.2.2 and kernel image 2.6.6 selinux .debs available

Quoted 3 lines
Quoted 3 lines

compile I hadn't got around to trying to compile it recently. In your message you didn't mention whether you successfully compiled the code with the patch in question. Does it compile?

i have uploaded the kdm 3.2.2 selinux .deb to:

http://open.hands.com/selinux

i forgot: i hadn't added -se onto the package name/description. i _really_ can't face doing another 2 hour build. apologies in advance.

l.

p.s. a kernel-image-2.6.6-selinux1 .deb is also on its way to the
same location.

p.p.s. anyone using these is obviously and entirely responsible for
their own actions and decisions.

--
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.

#18 lore raw

Re: kdm 3.2.2 and kernel image 2.6.6 selinux .debs available

Quoted 7 lines · Luke Kenneth Casson Leighton
Quoted 3 lines
Quoted 3 lines

compile I hadn't got around to trying to compile it recently. In your message you didn't mention whether you successfully compiled the code with the patch in question. Does it compile?

i have uploaded the kdm 3.2.2 selinux .deb to:

http://open.hands.com/selinux

that's http://hands.com/~lkcl/selinux.

oops :)

--
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
In reply to Luke Kenneth Casson Leighton
Quoted 8 lines · Luke Kenneth Casson Leighton
Quoted 7 lines · Thomas Bleher
Quoted 6 lines · Luke Kenneth Casson Leighton

is this pretty much all that's required??? compared to the 2.4 stuff it's like tiny.

this is all that the patch to wdm does. i'm just a little surprised (pleasantly so).

Quoted 6 lines
Quoted 6 lines

backend/client.c

Quoted 2 lines
backend/client.c renamed from client.c.old +0 -0

<snip patch>

I don't think that even this is required. It should work without patching, just using pam_selinux.so.

I just rechecked, and it is indeed working fine on a SuSE box (kdebase3-kdm-3.2.2-8) without any patches, just using the selinux pam module.

Quoted 6 lines

oh?

do you have some example usage that i can try out, and does anyone have any advice on how to ensure that installation of debian packages (pam and selinux and kde) would result in pam being automatically updated?

echo "session required pam_selinux.so" >> /etc/pam.d/kdm
should do it.
/etc/pam.d/kdm is a conffile AFAIK, so there should be no problems when updating packages.

HTH,
Thomas

Signature · 2 lines
http://www.cip.ifi.lmu.de/~bleher/selinux/ - my SELinux pages
GPG-Fingerprint: BC4F BB16 30D6 F253 E3EA  D09E C562 2BAE B2F4 ABE7
#4 lore raw
Quoted 3 lines · Thomas Bleher

I just rechecked, and it is indeed working fine on a SuSE box (kdebase3-kdm-3.2.2-8) without any patches, just using the selinux pam module.

Interesting. We weren't able to use pam_selinux with gdm, as pam_open_session was called from a different process.

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.
#5 lore raw
Quoted 7 lines · Stephen Smalley
Quoted 3 lines · Thomas Bleher

I just rechecked, and it is indeed working fine on a SuSE box (kdebase3-kdm-3.2.2-8) without any patches, just using the selinux pam module.

Interesting. We weren't able to use pam_selinux with gdm, as pam_open_session was called from a different process.

i _do_ notice in permissive / audit mode that kdeinit attempts to do an su:

 May 20 14:53:58 tv kernel: audit(1085064838.508:0): avc:  denied  {
 execute } for  pid=2616 exe=/usr/bin/kdeinit name=su dev=hda5 ino=93620
 scontext=lkcl:user_r:user_t tcontext=system_u:object_r:su_exec_t
 tclass=file
 May 20 14:53:58 tv kernel: audit(1085064838.509:0): avc:  denied  {
 getattr } for  pid=2616 exe=/usr/bin/kdeinit path=/bin/su dev=hda5
 ino=93620 scontext=lkcl:user_r:user_t
 tcontext=system_u:object_r:su_exec_t tclass=file

this is _without_ doing a pam session, but with a patched kdm.

checking the source code... kdm/process/client.c:StartClient() the get_default_context is at line 1102.

pam_open_session() is at line 1172.

track track track... oo, wossat? a fork()??? ah, that's at line 1184.

okay, so i prepare a context, then open the pam session, and _then_ there's a fork (this is horrible code, btw - really large switch statements and yuk indentation: i'm actually giving up looking for the end of the switch statement or another case or the default :)

so, if pam_open_session() does all the work, then i don't need to have patched kdm, and a line in /etc/pam.d/kdm to include module pam_selinux would do the job just as well.

oh well :)

l.

--
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
In reply to Russell Coker
Quoted 6 lines · Russell Coker
Quoted 2 lines · Luke Kenneth Casson Leighton

i _do_ notice in permissive / audit mode that kdeinit attempts to do an su:

Which program was it? Almost every KDE program runs as kdeinit as an attempt at optimising load performance.

sadly i cannot tell. i have been meaning to ask:

is it possible to run things to present more debug info at the TIME that an avc message is placed in the logs?

for example, when the above kdeinit occurs, to do, oh, i dunno, a ps -ax --forest.

i don't really care how long it takes, what i care about is identifying the parent process(es).

... alternatively, do you know how could i tell?

l.

Signature · 15 lines
-- 
expecting email to be received and understood is a bit like
picking up the telephone and immediately dialing without
checking for a dial-tone; speaking immediately without listening
for either an answer or ring-tone; hanging up immediately and
believing that you have actually started a conversation.
--
<a href="http://lkcl.net">      lkcl.net      </a> <br />
<a href="mailto:[email protected]"> [email protected] </a> <br />


--
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.
#8 lore raw
Quoted 4 lines · Luke Kenneth Casson Leighton

sadly i cannot tell. i have been meaning to ask:

is it possible to run things to present more debug info at the TIME that an avc message is placed in the logs?

You might get more information by enabling syscall auditing in your kernel. Boot with audit=1.

You could patch the audit daemon (if you are running one) or syslogd to run whatever you want as it receives audit messages.

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.
#9 lore raw
Quoted 8 lines · Stephen Smalley
Quoted 4 lines · Luke Kenneth Casson Leighton

sadly i cannot tell. i have been meaning to ask:

is it possible to run things to present more debug info at the TIME that an avc message is placed in the logs?

You might get more information by enabling syscall auditing in your kernel. Boot with audit=1.

ta.

Quoted 2 lines

You could patch the audit daemon (if you are running one) or syslogd to run whatever you want as it receives audit messages.

ah ha!

--
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.

#10 lore raw
In reply to Russell Coker
Quoted 6 lines · Russell Coker
Quoted 2 lines · Luke Kenneth Casson Leighton

i _do_ notice in permissive / audit mode that kdeinit attempts to do an su:

Which program was it? Almost every KDE program runs as kdeinit as an attempt at optimising load performance.

konsole --session 01012120310231203

--
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.

#11 lore raw
In reply to Russell Coker
Quoted 6 lines · Russell Coker
Quoted 2 lines · Luke Kenneth Casson Leighton

i _do_ notice in permissive / audit mode that kdeinit attempts to do an su:

Which program was it? Almost every KDE program runs as kdeinit as an attempt at optimising load performance.

okay, it's kconsole, which execs commands.

it's actually possible to configure KDE to use something - anything - via the "Exec" config option ... uhmmm.. track track track... /usr/share/apps/konsole/shell.desktop

so in theeoorry, it should be possible to specify a wrapper command under which the command will be exec'd (in this case "su something")

e.g. runcon?

oo. *wobble*. don't know what to doo.

... clues, anyone?

--
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.

#6 lore raw
In reply to Luke Kenneth Casson Leighton
Quoted 2 lines · Luke Kenneth Casson Leighton

i _do_ notice in permissive / audit mode that kdeinit attempts to do an su:

Which program was it? Almost every KDE program runs as kdeinit as an attempt at optimising load performance.

It would be nice if we could turn off the kdeinit functionality and have KDE use exec like everything else.

Signature · 7 lines
http://apac.redhat.com/disclaimer
See above URL for disclaimer.

--
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.