|
From: <sv...@va...> - 2014-05-22 08:57:15
|
Author: tom
Date: Thu May 22 08:57:06 2014
New Revision: 13990
Log:
Check for setcap executables, as we already do for setuid and
setgid ones, and refuse to run them in the same way. BZ#335143.
Modified:
trunk/coregrind/m_libcfile.c
trunk/coregrind/m_ume/main.c
trunk/coregrind/pub_core_libcfile.h
Modified: trunk/coregrind/m_libcfile.c
==============================================================================
--- trunk/coregrind/m_libcfile.c (original)
+++ trunk/coregrind/m_libcfile.c Thu May 22 08:57:06 2014
@@ -359,6 +359,18 @@
return (res == -1) ? (-1LL) : buf.size;
}
+SysRes VG_(getxattr) ( const HChar* file_name, const HChar* attr_name, Addr attr_value, SizeT attr_value_len )
+{
+ SysRes res;
+#if defined(VGO_linux)
+ res = VG_(do_syscall4)(__NR_getxattr, (UWord)file_name, (UWord)attr_name,
+ attr_value, attr_value_len);
+#else
+ res = VG_(mk_SysRes_Error)(VKI_ENOSYS);
+#endif
+ return res;
+}
+
Bool VG_(is_dir) ( const HChar* f )
{
struct vg_stat buf;
@@ -600,6 +612,13 @@
return VKI_EACCES;
}
+ res = VG_(getxattr)(f, "security.capability", (Addr)0, 0);
+ if (!sr_isError(res) && !allow_setuid) {
+ if (is_setuid)
+ *is_setuid = True;
+ return VKI_EACCES;
+ }
+
if (VG_(geteuid)() == st.uid) {
if (!(st.mode & VKI_S_IXUSR))
return VKI_EACCES;
Modified: trunk/coregrind/m_ume/main.c
==============================================================================
--- trunk/coregrind/m_ume/main.c (original)
+++ trunk/coregrind/m_ume/main.c Thu May 22 08:57:06 2014
@@ -87,7 +87,7 @@
if (is_setuid && !VG_(clo_xml)) {
VG_(message)(Vg_UserMsg, "\n");
VG_(message)(Vg_UserMsg,
- "Warning: Can't execute setuid/setgid executable: %s\n",
+ "Warning: Can't execute setuid/setgid/setcap executable: %s\n",
exe_name);
VG_(message)(Vg_UserMsg, "Possible workaround: remove "
"--trace-children=yes, if in effect\n");
Modified: trunk/coregrind/pub_core_libcfile.h
==============================================================================
--- trunk/coregrind/pub_core_libcfile.h (original)
+++ trunk/coregrind/pub_core_libcfile.h Thu May 22 08:57:06 2014
@@ -49,6 +49,9 @@
/* Return the size of a file, or -1 in case of error */
extern Long VG_(fsize) ( Int fd );
+/* Lookup an extended attribute for a file */
+extern SysRes VG_(getxattr) ( const HChar* file_name, const HChar* attr_name, Addr attr_value, SizeT attr_value_len );
+
/* Is the file a directory? */
extern Bool VG_(is_dir) ( const HChar* f );
|