8202650: Enforce group for attach listener file
authorclanger
Wed, 09 May 2018 07:48:31 +0100
changeset 50067 88b76c19d8eb
parent 50066 bd3e4517dfa3
child 50068 5201c9474ee7
8202650: Enforce group for attach listener file Reviewed-by: cjplummer, stuefe
src/hotspot/os/aix/attachListener_aix.cpp
src/hotspot/os/bsd/attachListener_bsd.cpp
src/hotspot/os/linux/attachListener_linux.cpp
--- a/src/hotspot/os/aix/attachListener_aix.cpp	Wed May 09 06:51:41 2018 +0200
+++ b/src/hotspot/os/aix/attachListener_aix.cpp	Wed May 09 07:48:31 2018 +0100
@@ -235,7 +235,12 @@
   if (res == 0) {
     RESTARTABLE(::chmod(initial_path, S_IREAD|S_IWRITE), res);
     if (res == 0) {
-      res = ::rename(initial_path, path);
+      // make sure the file is owned by the effective user and effective group
+      // e.g. the group could be inherited from the directory in case the s bit is set
+      RESTARTABLE(::chown(initial_path, geteuid(), getegid()), res);
+      if (res == 0) {
+        res = ::rename(initial_path, path);
+      }
     }
   }
   if (res == -1) {
--- a/src/hotspot/os/bsd/attachListener_bsd.cpp	Wed May 09 06:51:41 2018 +0200
+++ b/src/hotspot/os/bsd/attachListener_bsd.cpp	Wed May 09 07:48:31 2018 +0100
@@ -215,7 +215,8 @@
     RESTARTABLE(::chmod(initial_path, S_IREAD|S_IWRITE), res);
     if (res == 0) {
       // make sure the file is owned by the effective user and effective group
-      // (this is the default on linux, but not on mac os)
+      // e.g. default behavior on mac is that new files inherit the group of
+      // the directory that they are created in
       RESTARTABLE(::chown(initial_path, geteuid(), getegid()), res);
       if (res == 0) {
         res = ::rename(initial_path, path);
--- a/src/hotspot/os/linux/attachListener_linux.cpp	Wed May 09 06:51:41 2018 +0200
+++ b/src/hotspot/os/linux/attachListener_linux.cpp	Wed May 09 07:48:31 2018 +0100
@@ -215,7 +215,12 @@
   if (res == 0) {
     RESTARTABLE(::chmod(initial_path, S_IREAD|S_IWRITE), res);
     if (res == 0) {
-      res = ::rename(initial_path, path);
+      // make sure the file is owned by the effective user and effective group
+      // e.g. the group could be inherited from the directory in case the s bit is set
+      RESTARTABLE(::chown(initial_path, geteuid(), getegid()), res);
+      if (res == 0) {
+        res = ::rename(initial_path, path);
+      }
     }
   }
   if (res == -1) {