Re: security(8) setuid checks and space character in file name

Previous thread: Cigarrillo Electrónico - El sano placer de fumar by Winged on Wednesday, December 29, 2010 - 1:36 pm. (1 message)

Next thread: PCI power management diff by Mark Kettenis on Wednesday, December 29, 2010 - 4:10 pm. (5 messages)
From: Ingo Schwarze
Date: Wednesday, December 29, 2010 - 4:08 pm

I consider this a bug in security(8).

The following is the best i could come up with so far; make sure
to wear your sed-peril-proof sunglasses before reading the patch.

This still mangles the file name, but at least you have a chance
to find it on your disk.  Anybody has a better plan?

I already told Marcus on misc to mount that one -o nodev,noexec
and use SUIDSKIP; but that's rather a workaround than a fix.




--- security	Wed Jun  3 11:06:07 2009
+++ /etc/security	Wed Dec 29 15:56:37 2010
@@ -427,7 +427,9 @@
 	\) -a -prune -o \
 	-type f -a \( -perm -u+s -o -perm -g+s \) -print0 -o \
 	! -type d -a ! -type f -a ! -type l -a ! -type s -a ! -type p \
-	-print0 | xargs -0 -r ls -ldgT | sort +9 > $LIST
+	-print0 | xargs -0 -r ls -ldgT | \
+	sed 'h;s,[^/]*,,;s,[[:blank:]],_,g;x;s,/.*,,;G;s/\n//' | \
+	sort +9 > $LIST
 )
 
 # Display any changes in the setuid/setgid file list.

From: Ted Unangst
Date: Thursday, December 30, 2010 - 11:02 am

sed it back?  assume blank is generally space, replace it with
__omgspace__, then after sorting, replace that with a single space?
It will still screw up for tabs and newlines, but I think spaces are a
lot more common.

From: patrick keshishian
Date: Thursday, December 30, 2010 - 12:01 pm

what if the file name contains "__omgspace__"? :-)

From: Otto Moerbeek
Date: Thursday, December 30, 2010 - 12:53 pm

My guess is that it would be better to sort first and then run xargs.
Something like:

find .... -print0 | sort -z | xargs -0 -L1 ls -ldgT

	-Otto

From: Nicholas Marriott
Date: Thursday, December 30, 2010 - 3:12 pm

Or could use stat(1) to put the item to be sorted at the start, albeit
ending up with a different format from ls:

find .... -print0 | xargs -0 -r stat -f '%-40N %-10Su %-10Sg %Sp' | sort



From: Nicholas Marriott
Date: Thursday, December 30, 2010 - 3:15 pm

Er, that would need other changes as well. Ignore me...



From: MERIGHI Marcus
Date: Friday, December 31, 2010 - 7:05 am

I'd like that one, by far more dapper; but it does not change a thing
about the abbreviated file name beeing compared and reported by join(1).

Marcus

Previous thread: Cigarrillo Electrónico - El sano placer de fumar by Winged on Wednesday, December 29, 2010 - 1:36 pm. (1 message)

Next thread: PCI power management diff by Mark Kettenis on Wednesday, December 29, 2010 - 4:10 pm. (5 messages)