changeset 50603:88b76c19d8eb

8202650: Enforce group for attach listener file Reviewed-by: cjplummer, stuefe
author clanger
date Wed, 09 May 2018 07:48:31 +0100
parents bd3e4517dfa3
children 5201c9474ee7
files src/hotspot/os/aix/attachListener_aix.cpp src/hotspot/os/bsd/attachListener_bsd.cpp src/hotspot/os/linux/attachListener_linux.cpp
diffstat 3 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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) {