Skip to content

[Support] Use all_read | all_write for createTemporaryFile #83360

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 1 commit into from
Feb 29, 2024

Conversation

JDevlieghere
Copy link
Member

In a04879c, dsymutil switched from using TempFile to createTemporaryFile. This caused a regression because the two use different permissions:

  • TempFile opens the file as all_read | all_write
  • createTemporaryFile opens the file as owner_read | owner_write

The latter turns out to be problematic for dsymutil because it either promotes the temporary to a proper output file, or it would pass it to lipo to create a universal binary and lipo preserves the permissions of the input files. Either way, this caused issues when the build system was run as a different user than the one ingesting the resulting binaries.

I did some version control archeology and I couldn't find evidence that these permissions were chosen purposely. Both could be considered reasonable default.

This patch changes the permissions to all read | all write to make the two consistent and match the one currently used by the higher level abstraction (TempFile).

rdar://123722848

In a04879c, dsymutil switched from using TempFile to
createTemporaryFile. This caused a regression because the two use
different permissions:

 - TempFile opens the file as all_read | all_write
 - createTemporaryFile opens the file as owner_read | owner_write

The latter turns out to be problematic for dsymutil because it either
promotes the temporary to a proper output file, or it would pass it to
`lipo` to create a universal binary and `lipo` preserves the permissions
of the input files. Either way, this caused issues when the build system
was run as a different user than the one ingesting the resulting
binaries.

I did some version control archeology and I couldn't find evidence that
these permissions were chosen purposely. Both could be considered
reasonable default.

This patch changes the permissions to `all read | all write` to make the
two consistent and match the one currently used by the higher level
abstraction (TempFile).

rdar://123722848
@llvmbot
Copy link
Member

llvmbot commented Feb 29, 2024

@llvm/pr-subscribers-llvm-support

Author: Jonas Devlieghere (JDevlieghere)

Changes

In a04879c, dsymutil switched from using TempFile to createTemporaryFile. This caused a regression because the two use different permissions:

  • TempFile opens the file as all_read | all_write
  • createTemporaryFile opens the file as owner_read | owner_write

The latter turns out to be problematic for dsymutil because it either promotes the temporary to a proper output file, or it would pass it to lipo to create a universal binary and lipo preserves the permissions of the input files. Either way, this caused issues when the build system was run as a different user than the one ingesting the resulting binaries.

I did some version control archeology and I couldn't find evidence that these permissions were chosen purposely. Both could be considered reasonable default.

This patch changes the permissions to all read | all write to make the two consistent and match the one currently used by the higher level abstraction (TempFile).

rdar://123722848


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

1 Files Affected:

  • (modified) llvm/lib/Support/Path.cpp (+1-1)
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index c8de2c0625aa26..acee228a0d0462 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -850,7 +850,7 @@ createTemporaryFile(const Twine &Model, int &ResultFD,
          "Model must be a simple filename.");
   // Use P.begin() so that createUniqueEntity doesn't need to recreate Storage.
   return createUniqueEntity(P.begin(), ResultFD, ResultPath, true, Type, Flags,
-                            owner_read | owner_write);
+                            all_read | all_write);
 }
 
 static std::error_code

Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable. I guess it's possible, but unlikely, that it does affect some case somewhere, but we'll never know unless we roll it out. So LGTM.

@JDevlieghere JDevlieghere merged commit 310ed33 into llvm:main Feb 29, 2024
@JDevlieghere JDevlieghere deleted the createUniqueEntity-permissions branch February 29, 2024 16:05
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Mar 1, 2024
In a04879c, dsymutil switched from using TempFile to
createTemporaryFile. This caused a regression because the two use
different permissions:

 - TempFile opens the file as all_read | all_write
 - createTemporaryFile opens the file as owner_read | owner_write

The latter turns out to be problematic for dsymutil because it either
promotes the temporary to a proper output file, or it would pass it to
`lipo` to create a universal binary and `lipo` preserves the permissions
of the input files. Either way, this caused issues when the build system
was run as a different user than the one ingesting the resulting
binaries.

I did some version control archeology and I couldn't find evidence that
these permissions were chosen purposely. Both could be considered
reasonable default.

This patch changes the permissions to `all read | all write` to make the
two consistent and match the one currently used by the higher level
abstraction (TempFile).

rdar://123722848
(cherry picked from commit 310ed33)
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Mar 1, 2024
[Support] Use all_read | all_write for createTemporaryFile (llvm#83360)
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