8140244: Port fix of JDK-8075773 to AIX and possibly MacOSX
authorclanger
Wed, 04 Nov 2015 16:23:08 -0800
changeset 33769 d04b4e2165a7
parent 33762 3d1dd03dfd3f
child 33770 888a51053190
8140244: Port fix of JDK-8075773 to AIX and possibly MacOSX Reviewed-by: stuefe, dcubed
hotspot/src/os/aix/vm/perfMemory_aix.cpp
hotspot/src/os/bsd/vm/perfMemory_bsd.cpp
--- a/hotspot/src/os/aix/vm/perfMemory_aix.cpp	Wed Nov 04 20:02:54 2015 +0000
+++ b/hotspot/src/os/aix/vm/perfMemory_aix.cpp	Wed Nov 04 16:23:08 2015 -0800
@@ -201,6 +201,7 @@
 // the backing store files. Returns true if the directory is considered
 // a secure location. Returns false if the statbuf is a symbolic link or
 // if an error occurred.
+//
 static bool is_statbuf_secure(struct stat *statp) {
   if (S_ISLNK(statp->st_mode) || !S_ISDIR(statp->st_mode)) {
     // The path represents a link or some non-directory file type,
@@ -209,15 +210,18 @@
     return false;
   }
   // We have an existing directory, check if the permissions are safe.
+  //
   if ((statp->st_mode & (S_IWGRP|S_IWOTH)) != 0) {
     // The directory is open for writing and could be subjected
     // to a symlink or a hard link attack. Declare it insecure.
+    //
     return false;
   }
-  // See if the uid of the directory matches the effective uid of the process.
-  //
-  if (statp->st_uid != geteuid()) {
+  // If user is not root then see if the uid of the directory matches the effective uid of the process.
+  uid_t euid = geteuid();
+  if ((euid != 0) && (statp->st_uid != euid)) {
     // The directory was not created by this user, declare it insecure.
+    //
     return false;
   }
   return true;
@@ -228,6 +232,7 @@
 // the backing store files. Returns true if the directory exists
 // and is considered a secure location. Returns false if the path
 // is a symbolic link or if an error occurred.
+//
 static bool is_directory_secure(const char* path) {
   struct stat statbuf;
   int result = 0;
--- a/hotspot/src/os/bsd/vm/perfMemory_bsd.cpp	Wed Nov 04 20:02:54 2015 +0000
+++ b/hotspot/src/os/bsd/vm/perfMemory_bsd.cpp	Wed Nov 04 16:23:08 2015 -0800
@@ -217,9 +217,9 @@
     //
     return false;
   }
-  // See if the uid of the directory matches the effective uid of the process.
-  //
-  if (statp->st_uid != geteuid()) {
+  // If user is not root then see if the uid of the directory matches the effective uid of the process.
+  uid_t euid = geteuid();
+  if ((euid != 0) && (statp->st_uid != euid)) {
     // The directory was not created by this user, declare it insecure.
     //
     return false;