Skip to contentSkip to conversation

dpkg bug related to SE Linux

DISCUSSION Russell Coker 2 participants 6 messages Apr 5, 2008 – Apr 9, 2008 SELinux security module

lore
Share & tools
lore
#0 lore raw

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=474339

When the file_contexts file has an invalid context then dpkg will crash, see the above bug report.

dpkg is statically linked against libselinux.

Signature · 9 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

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

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=474339

When the file_contexts file has an invalid context then dpkg will crash, see the above bug report.

dpkg is statically linked against libselinux.

Can you reproduce with a simpler caller, e.g. compile matchpathcon from libselinux/utils statically and run it on your corrupted file_contexts file, passing in a pathname that will match the invalid line?

I wasn't able to reproduce the bug myself.

libselinux does rely on its constructors having run before any functions are called. dpkg isn't built in such a way as to suppress constructor execution, is it? What options are passed to gcc when compiling dpkg?

Signature · 8 lines
Stephen Smalley
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.
#2 lore raw
Quoted 12 lines · Stephen Smalley
Quoted 6 lines · Russell Coker

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=474339

When the file_contexts file has an invalid context then dpkg will crash, see the above bug report.

dpkg is statically linked against libselinux.

Can you reproduce with a simpler caller, e.g. compile matchpathcon from libselinux/utils statically and run it on your corrupted file_contexts file, passing in a pathname that will match the invalid line?

Quoted 5 lines

I wasn't able to reproduce the bug myself.

libselinux does rely on its constructors having run before any functions are called. dpkg isn't built in such a way as to suppress constructor execution, is it? What options are passed to gcc when compiling dpkg?

Oh, and what version of libselinux and libsepol was dpkg built against?

Signature · 8 lines
Stephen Smalley
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.
#3 lore raw
Quoted 4 lines · Stephen Smalley
Quoted 3 lines · Stephen Smalley
Quoted 2 lines · Russell Coker

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=474339

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

When the file_contexts file has an invalid context then dpkg will crash, see the above bug report.

dpkg is statically linked against libselinux.

Can you reproduce with a simpler caller, e.g. compile matchpathcon from libselinux/utils statically and run it on your corrupted file_contexts file, passing in a pathname that will match the invalid line?

Restorecon doesn't have this problem, neither when dynamically nor statically linked.

# semanage fcontext -l|grep squid_conf
/etc/squid(/.*)?                                   all files          
system_u:object_r:squid_conf_t:s0
/usr/share/squid(/.*)?                             all files          
system_u:object_r:squid_conf_t:s0
# restorecon -R -v /etc/squid
restorecon reset /etc/squid context 
root:object_r:etc_t:s0->system_u:object_r:squid_conf_t:s0
restorecon set context /etc/squid->system_u:object_r:squid_conf_t:s0 
failed:'Invalid argument'
# ldd ./restorecon
        not a dynamic executable
# ./restorecon -R -v /etc/squid
./restorecon reset /etc/squid context 
root:object_r:etc_t:s0->system_u:object_r:squid_conf_t:s0
./restorecon set context /etc/squid->system_u:object_r:squid_conf_t:s0 
failed:'Invalid argument'
Quoted 5 lines
Quoted 5 lines

I wasn't able to reproduce the bug myself.

libselinux does rely on its constructors having run before any functions are called. dpkg isn't built in such a way as to suppress constructor execution, is it? What options are passed to gcc when compiling dpkg?

I don't believe that there is anything strange about the way dpkg is built. The fact that it works in the normal case suggests that constructors are not the problem.

Quoted 1 line

Oh, and what version of libselinux and libsepol was dpkg built against?

ii  libselinux1    2.0.59-1       SELinux shared libraries
ii  libsepol1      2.0.25-1       Security Enhanced Linux policy library for c
Signature · 9 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

--
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.
#4 lore raw
Quoted 8 lines · Russell Coker
Quoted 7 lines · Stephen Smalley
Quoted 6 lines · Stephen Smalley
Quoted 5 lines · Russell Coker

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=474339

When the file_contexts file has an invalid context then dpkg will crash, see the above bug report.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

dpkg is statically linked against libselinux.

Can you reproduce with a simpler caller, e.g. compile matchpathcon from libselinux/utils statically and run it on your corrupted file_contexts file, passing in a pathname that will match the invalid line?

Restorecon doesn't have this problem, neither when dynamically nor statically linked.

In that case, I'd recommend looking more closely at the dpkg selinux code itself rather than libselinux. For example, does dpkg try to free the context from matchpathcon() upon an error return? That would be a bug in it rather than libselinux. Or is dpkg double free'ing a returned context?

Signature · 8 lines
Stephen Smalley
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

The following patch fixes the problem.

scontext is allocated by matchpathcon(3) and needs to be freed by the caller. If it's not set to NULL before the attempted allocation then it'll keep the previous value (which had been freed) and then you get a double-free.

src/archives.c +1 -0
@@ -629,6 +629,7 @@
      * or if it has no context; in which case the default
      * context shall be applied.
      */
+    scontext = NULL;
     if( ! ((matchpathcon(fnamevb.buf,
                          (nifd->namenode->statoverride ?
                           nifd->namenode->statoverride->mode : ti->Mode)

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