pcp
[Top] [All Lists]

Bug#771793: pcp: insecure use of /var/tmp in postinst

To: Debian Bug Tracking System <submit@xxxxxxxxxxxxxxx>
Subject: Bug#771793: pcp: insecure use of /var/tmp in postinst
From: Jakub Wilk <jwilk@xxxxxxxxxx>
Date: Tue, 2 Dec 2014 14:16:42 +0100
Delivered-to: pcp@xxxxxxxxxxx
Delivered-to: submit@xxxxxxxxxxxxxxx
Reply-to: Jakub Wilk <jwilk@xxxxxxxxxx>, 771793@xxxxxxxxxxxxxxx
Resent-cc: jwilk@xxxxxxxxxx, PCP Development Team <pcp@xxxxxxxxxxx>
Resent-date: Tue, 02 Dec 2014 13:21:01 +0000
Resent-from: Jakub Wilk <jwilk@xxxxxxxxxx>
Resent-message-id: <handler.771793.B.14175262117896@xxxxxxxxxxxxxxx>
Resent-to: debian-bugs-dist@xxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.23 (2014-03-12)
Package: pcp
Version: 3.10.1
Tags: security

The postinst script does this:

for dir in /var/tmp/mmv /var/tmp/pmdabash
do
   [ -d $dir -a -G $dir -a -O $dir ] && mv $dir /var/lib/pcp/tmp
done

The intention here was to move only root-owned directories. But there are at least to ways to (partially) defeat this check:

1) On systems that lack symlink protection (/proc/sys/fs/protected_symlinks), local attacker could:
- create /var/tmp/mmv as a symlink to a root-owned directory;
- then, between the security check and the mv(1) call, switch the symlink to point to something else.

2) On systems that lack hardlink protection (/proc/sys/fs/protected_hardlinks), local attacker could: - create /var/tmp/mmv as a regular directory, so that the [ -d $dir ] check passes; - then rmdir /var/tmp/mmv, and make /var/tmp/mmv a hardlink to a root-owned file, so that the [ -G $dir ] and [ -O $dir ] checks pass.


I'd suggest using stat(1) to check the file type and ownership atomically, and without following symlinks. Something like this should work:

   [ "$(LC_ALL=C stat -c '%u %g %F' $dir)" = "0 0 directory" ] && mv $dir 
/var/lib/pcp/tmp

--
Jakub Wilk

<Prev in Thread] Current Thread [Next in Thread>