Skip to content

[lldb][Windows] Enforce exec permission using Platform::Install() from Windows host #91887

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
May 14, 2024

Conversation

slydiman
Copy link
Contributor

Target::Install() set 0700 permissions for the main executable file. Platform::Install() just copies permissions from the source. But the permission eFilePermissionsUserExecute is missing on the Windows host. A lot of tests failed in case of Windows host and Linux target because of this issue. There is no API to provide the exec flag. This patch set the permission eFilePermissionsUserExecute for all files installed via Platform::Install() from the Windows host. It fixes a lot of tests in case of Windows host and Linux target.

…m Windows host

Target::Install() set 0700 permissions for the main executable file. Platform::Install() just copies permissions from the source. But the permission eFilePermissionsUserExecute is missing on the Windows host. A lot of tests failed in case of Windows host and Linux target because of this issue. There is no API to provide the exec flag. This patch set the permission eFilePermissionsUserExecute for all files installed via Platform::Install() from the Windows host. It fixes a lot of tests in case of Windows host and Linux target.
@slydiman slydiman requested a review from JDevlieghere as a code owner May 12, 2024 14:30
@llvmbot llvmbot added the lldb label May 12, 2024
@llvmbot
Copy link
Member

llvmbot commented May 12, 2024

@llvm/pr-subscribers-lldb

Author: Dmitry Vasilyev (slydiman)

Changes

Target::Install() set 0700 permissions for the main executable file. Platform::Install() just copies permissions from the source. But the permission eFilePermissionsUserExecute is missing on the Windows host. A lot of tests failed in case of Windows host and Linux target because of this issue. There is no API to provide the exec flag. This patch set the permission eFilePermissionsUserExecute for all files installed via Platform::Install() from the Windows host. It fixes a lot of tests in case of Windows host and Linux target.


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

1 Files Affected:

  • (modified) lldb/source/Target/Platform.cpp (+4)
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 4af4aa68ccd01..0e7739b3712d7 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -1227,6 +1227,10 @@ Status Platform::PutFile(const FileSpec &source, const FileSpec &destination,
   if (permissions == 0)
     permissions = lldb::eFilePermissionsFileDefault;
 
+#if defined(_WIN32)
+  permissions |= lldb::eFilePermissionsUserExecute;
+#endif
+
   lldb::user_id_t dest_file = OpenFile(
       destination, File::eOpenOptionCanCreate | File::eOpenOptionWriteOnly |
                        File::eOpenOptionTruncate | File::eOpenOptionCloseOnExec,

@slydiman slydiman requested a review from labath May 13, 2024 06:12
@labath
Copy link
Collaborator

labath commented May 13, 2024

The ifdef in the generic code is not exactly ideal, and I'm wondering if we should just do the same thing as Target::Install does (i.e., set the execute flag unconditionally). Looking at the history, it appears that the Target::Install code was introduced to fix the same problem you are having, and it's quite possible this code path was not noticed because we were still in the very early stages of cross-debugging bringup (or the function did even not exist back then).

In fact, if I'm reading this correctly, you should be able to remove the Target::Install workaround if you put the code here.

WDYT?

@slydiman slydiman requested a review from DavidSpickett May 13, 2024 12:05
@slydiman
Copy link
Contributor Author

slydiman commented May 13, 2024

Target::Install() and Platform::Install() are used indirectly in many cases. For example look at the test lldb/test/API/python_api/hello_world/TestHelloWorld.py. target.LaunchSimple() uses Target::Install() and there is no problem with the exec permission. spawnSubprocess() uses the class _RemoteProcess and finally Platform::Install(). spawnSubprocess() is used in 27 test files and they are failed is case of Windows host and Linux target.

Target::Install does (i.e., set the execute flag unconditionally)

Target::Install() checks is_main_executable enumerating all modules.
But Target::Install()'s logic is not applicable in most cases where Platform::Install() is used.
I think Target::Install is not a workaround and we cannot remove this code.
I'd say this patch is a workaround for the case host=Windows and target!=Windows. We can even add a comment FIXME:... if someone will have an idea how to fix it better way.

@labath
Copy link
Collaborator

labath commented May 13, 2024

I'm not sure I'm following your reasoning. I'm not saying we should replace/remove Target::Install. I'm saying we should make everything installed by Platform::Install executable by default (which, by extension, includes everything installed by Target::Install, because it delegates to this function.

And you're saying that's not a good idea, because what? That not everything installed through Platform::Install is an actual executable?

@slydiman
Copy link
Contributor Author

@labath, Sorry for not being clear with my comment. Let me re-phrase.

I think unconditionally setting the executable flag for everything installed by Platform::Install by default for all platforms is overkill.

BTW, there is no API to change this behavior, so by default means always.

Implementation details aside. Test files have the correct permissions set if the host allows it. Platform::Install copies the host file permissions to the target. This seems a correct behavior except for the case when the host has a smaller set of permissions than the target, or permission sets on the host and the target do not match significantly. I'm aware of the only such case: Windows host and POSIX target. Do you know more?

@slydiman
Copy link
Contributor Author

I have updated the patch w/o #ifdef. Note if GetPermissions() returned 0 it means Windows host in most cases.

Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

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

I like this new version, thanks for sticking with me.

@slydiman slydiman merged commit 7b1b127 into llvm:main May 14, 2024
3 checks passed
@slydiman slydiman deleted the fix-lldb-PutFile-exec-permission branch July 25, 2024 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants