Skip to content

[compiler-rt][rtsan] Fix failing file permissions test #106095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 28, 2024

Conversation

cjappl
Copy link
Contributor

@cjappl cjappl commented Aug 26, 2024

This reverts:

d8d8d65

This test was failing with the assertion:

/build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp:198: Failure
Value of: st.st_mode & 0777
Expected: is equal to 420
  Actual: 384

To fix this bug, we need to record the delta between the existing umask and the requested file permissions.

I have repro'd this on my local machine, which you can do by:

$ umask # look at the existing umask
0022 
$ umask 0077 # set it to the more restrictive umask
$ ninja check-rtsan
...
/Users/topher/code/radsan_cjappl/llvm-project/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp:198
Value of: st.st_mode & 0777
Expected: is equal to 420
  Actual: 384
...
$ git checkout $THIS_BRANCH
$ ninja check-rtsan
CLEAN :)

@cjappl
Copy link
Contributor Author

cjappl commented Aug 26, 2024

CC @davidtrevelyan

@llvmbot
Copy link
Member

llvmbot commented Aug 26, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Chris Apple (cjappl)

Changes

This reverts:

d8d8d65

This test was failing with the assertion:

/build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp:198: Failure
Value of: st.st_mode & 0777
Expected: is equal to 420
  Actual: 384

My thought is that on my local machine, umask starts at 0022 (owner everything, group read, others read) and on the build machine umask starts at 0077 (owner everything, group nothing, others nothing).

To fix this bug, we need to record the delta between the existing umask and the requested file permissions. Does this seem reasonable?


Full diff: https://github.com/llvm/llvm-project/pull/106095.diff

1 Files Affected:

  • (modified) compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp (+18-19)
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
index 5b88cf64612942..8e55ccc1116727 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
@@ -184,25 +184,24 @@ TEST_F(RtsanFileTest, OpenatDiesWhenRealtime) {
   ExpectNonRealtimeSurvival(func);
 }
 
-// FIXME: This fails on the build machines, but not locally!
-// see https://github.com/llvm/llvm-project/pull/105732#issuecomment-2310286530
-// Value of: st.st_mode & 0777
-// Expected: is equal to 420
-// Actual: 384
-// TEST_F(RtsanFileTest, OpenCreatesFileWithProperMode) {
-//   const int mode = S_IRGRP | S_IROTH | S_IRUSR | S_IWUSR;
-//
-//   const int fd = open(GetTemporaryFilePath(), O_CREAT | O_WRONLY, mode);
-//   ASSERT_THAT(fd, Ne(-1));
-//   close(fd);
-//
-//   struct stat st;
-//   ASSERT_THAT(stat(GetTemporaryFilePath(), &st), Eq(0));
-//
-//   // Mask st_mode to get permission bits only
-//
-//   //ASSERT_THAT(st.st_mode & 0777, Eq(mode)); FAILED ASSERTION
-// }
+TEST_F(RtsanFileTest, OpenCreatesFileWithProperMode) {
+  const mode_t existing_umask = umask(0);
+  umask(existing_umask);
+
+  const int mode = S_IRGRP | S_IROTH | S_IRUSR | S_IWUSR;
+
+  const int fd = open(GetTemporaryFilePath(), O_CREAT | O_WRONLY, mode);
+  ASSERT_THAT(fd, Ne(-1));
+  close(fd);
+
+  struct stat st;
+  ASSERT_THAT(stat(GetTemporaryFilePath(), &st), Eq(0));
+
+  // Mask st_mode to get permission bits only
+  const mode_t actual_mode = st.st_mode & 0777;
+  const mode_t expected_mode = mode & ~existing_umask;
+  ASSERT_THAT(actual_mode, Eq(expected_mode));
+}
 
 TEST_F(RtsanFileTest, CreatDiesWhenRealtime) {
   auto func = [this]() { creat(GetTemporaryFilePath(), S_IWOTH | S_IROTH); };

@cjappl cjappl force-pushed the fix_file_mode_test branch from 7184fb5 to 5ea9ff3 Compare August 26, 2024 19:52
@cjappl cjappl force-pushed the fix_file_mode_test branch from 5ea9ff3 to 462f1f1 Compare August 27, 2024 14:15
@cjappl
Copy link
Contributor Author

cjappl commented Aug 28, 2024

Unrelated test failure:

/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-g9cxr-1/llvm-project/github-pull-requests/llvm/unittests/Analysis/UnrollAnalyzerTest.cpp:249: Failure
Value of: I1 != SimplifiedValuesVector[5].end()
  Actual: false
Expected: true

merging in a second

@cjappl cjappl merged commit 898d52b into llvm:main Aug 28, 2024
5 of 7 checks passed
@cjappl cjappl deleted the fix_file_mode_test branch August 28, 2024 20:08
qiaojbao pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Sep 30, 2024
…df8d91f90

Local branch amd-gfx a6bdf8d Merged main:41b55071a13374654a290c01224eb066c38dc87a into amd-gfx:20624ccc2ecf
Remote branch main 898d52b [compiler-rt][rtsan] Fix failing file permissions test by checking umask (llvm#106095)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants