Skip to content

Conversation

@swaroop-sridhar
Copy link
Contributor

In .net core 3, single file apps run by extracting the bundled contents to a temp directory.
The extraction directory is machine specific, and can be set through DOTNET_BUNDLE_EXTRACT_BASE_DIR environment variable.

When this setting is not configured, the host tries to use certain default directories.
On windows, extraction is within %TMPDIR%, which is user specific.
On Unix systems $TMPDIR/.net if set, which may be user specific (ex: MAC)
Otherwise, the extraction directory is within /var/tmp/ or /tmp/ which is common to all users, and may be locked by a specific user on first creation.

Therefore, this change fixes this issue by defaulting the extraction base directory in Unix systems to
<temp-dir>/.net/<user-ID> , where
<temp-dir>/.net/ has permission 0777, and
<temp-dir>/.net/<user-ID>/ has permission 0700.

This fix will be migrated to coreclr/3.1 branch for servicing.

Testing: Manual testing on Unix/Mac systems, since we don't have the setup to add automated tests with multiple users.

Fixes https://github.com/dotnet/core-setup/issues/8882

@jkotas
Copy link
Member

jkotas commented Jan 29, 2020

dotnet/designs#88

@jkotas jkotas requested a review from lpereira January 29, 2020 16:42
Copy link
Contributor

@lpereira lpereira Jan 29, 2020

Choose a reason for hiding this comment

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

I'd also set S_ISVTX (01000) in these two mkdir() calls in addition to their access permissions. This is the sticky bit.

With this bit set, only the owner of extraction_dir can rename or delete that directory. (Otherwise, there's a potential race condition here: while you can only remove empty directories -- and need to recursively delete files from a directory -- a malicious process can remove the directory even before we were able to start extracting the files there.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @lpereira, I've fixed this on the extraction_dir, per our discussion.

@swaroop-sridhar swaroop-sridhar changed the title WIP: Unix: Default to a users-specific temp directory for extracting single-file apps Unix: Default to a users-specific temp directory for extracting single-file apps Jan 30, 2020
@swaroop-sridhar swaroop-sridhar force-pushed the user branch 2 times, most recently from 92dd76f to fb3de95 Compare January 30, 2020 04:14
@swaroop-sridhar
Copy link
Contributor Author

@lpereira I've addressed your comments about S_ISVTX bit, and made another change to replace the getlogin() call, in the last two commits. Please take a look. Thanks,.

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if you run a program with $TMPDIR/.net already created, but with the permissions different than the one you set with chmod() because someone went there and changed them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be too bad. We just provide the $TPMDIR/.net/$UID as the default for $DOTNET_BUNDLE_EXTRACTION_BASE_DIR. If the default directory is not available/accessible on a system, then the user should set DOTNET_BUNDLE_EXTRACTION_BASE_DIR to an alternate location.

@ghost
Copy link

ghost commented Feb 7, 2020

Hello @lpereira!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

…e-file apps

In .net core 3, single file apps run by extracting the bundled contents to a temp directory.
The extraction directory is machine specific, and can be set through DOTNET_BUNDLE_EXTRACT_BASE_DIR environment variable.

When this setting is not configured, the host tries to use certain default directories.
On windows, extraction is within %TMPDIR%, which is user specific.
On Unix systems $TMPDIR/.net if set, which may be user specific (ex: MAC)
Otherwise, the extraction directory is within /var/tmp/ or /tmp/ which is common to all users, and may be locked by a specific user on first creation.

Therefore, this change fixes this issue by defaulting the extraction base directory in Unix systems to
`<temp-dir>/.net/<user-ID>` , where
`<temp-dir>/.net/` has permission 0777, and
`<temp-dir>/.net/<user-ID>/` has permission 01700.

This fix will be migrated to coreclr/3.1 branch for servicing.

Testing: Manual testing on Unix/Mac systems, since we don't have the setup to add automated tests with multiple users.

Fixes https://github.com/dotnet/core-setup/issues/8882
@swaroop-sridhar swaroop-sridhar merged commit 9082716 into dotnet:master Feb 12, 2020
@swaroop-sridhar swaroop-sridhar deleted the user branch February 12, 2020 02:24
swaroop-sridhar added a commit to swaroop-sridhar/core-setup that referenced this pull request Feb 28, 2020
…tory

dotnet/runtime#3846

On some Unix systems, multiple users cannot use single-file apps on the same machine.

In .net core 3, single file apps run by extracting the bundled contents to a temp directory.
The extraction directory is machine specific, and can be set through DOTNET_BUNDLE_EXTRACT_BASE_DIR environment variable.

When this setting is not configured, the host tries to use certain default directories.
On windows, extraction is within %TMPDIR%, which is user specific.
On Unix systems $TMPDIR/.net if set, which may be user specific (ex: MAC)
Otherwise, the extraction directory is within /var/tmp/ or /tmp/ which is common to all users, and may be locked by a specific user on first creation.

This change fixes this issue by defaulting the extraction base directory in Unix systems to
<temp-dir>/.net/<user-ID> , where
<temp-dir>/.net/ has permission 0777, and
<temp-dir>/.net/<user-ID>/ has permission 0700.

Low, scenario is contained, change is small.

dotnet/runtime#2329
swaroop-sridhar added a commit to swaroop-sridhar/core-setup that referenced this pull request Feb 28, 2020
…tory

dotnet/runtime#3846

On some Unix systems, multiple users cannot use single-file apps on the same machine.

In .net core 3, single file apps run by extracting the bundled contents to a temp directory.
The extraction directory is machine specific, and can be set through DOTNET_BUNDLE_EXTRACT_BASE_DIR environment variable.

When this setting is not configured, the host tries to use certain default directories.
On windows, extraction is within %TMPDIR%, which is user specific.
On Unix systems $TMPDIR/.net if set, which may be user specific (ex: MAC)
Otherwise, the extraction directory is within /var/tmp/ or /tmp/ which is common to all users, and may be locked by a specific user on first creation.

This change fixes this issue by defaulting the extraction base directory in Unix systems to
<temp-dir>/.net/<user-ID> , where
<temp-dir>/.net/ has permission 0777, and
<temp-dir>/.net/<user-ID>/ has permission 0700.

Low, scenario is contained, change is small.

dotnet/runtime#2329
swaroop-sridhar added a commit to swaroop-sridhar/core-setup that referenced this pull request Feb 28, 2020
…tory

** Issue

dotnet/runtime#3846

** Customer Scenario

On some Unix systems, multiple users cannot use single-file apps on the same machine.

** Problem

In .net core 3, single file apps run by extracting the bundled contents to a temp directory.
The extraction directory is machine specific, and can be set through DOTNET_BUNDLE_EXTRACT_BASE_DIR environment variable.

When this setting is not configured, the host tries to use certain default directories.
On windows, extraction is within %TMPDIR%, which is user specific.
On Unix systems $TMPDIR/.net if set, which may be user specific (ex: MAC)
Otherwise, the extraction directory is within /var/tmp/ or /tmp/ which is common to all users, and may be locked by a specific user on first creation.

** Solution

This change fixes this issue by defaulting the extraction base directory in Unix systems to
<temp-dir>/.net/<user-ID> , where
<temp-dir>/.net/ has permission 0777, and
<temp-dir>/.net/<user-ID>/ has permission 0700.

** Risk

Low, scenario is contained, change is small.

** Master Branch

dotnet/runtime#2329
Anipik pushed a commit to dotnet/core-setup that referenced this pull request Mar 25, 2020
…tory (#9011)

** Issue

dotnet/runtime#3846

** Customer Scenario

On some Unix systems, multiple users cannot use single-file apps on the same machine.

** Problem

In .net core 3, single file apps run by extracting the bundled contents to a temp directory.
The extraction directory is machine specific, and can be set through DOTNET_BUNDLE_EXTRACT_BASE_DIR environment variable.

When this setting is not configured, the host tries to use certain default directories.
On windows, extraction is within %TMPDIR%, which is user specific.
On Unix systems $TMPDIR/.net if set, which may be user specific (ex: MAC)
Otherwise, the extraction directory is within /var/tmp/ or /tmp/ which is common to all users, and may be locked by a specific user on first creation.

** Solution

This change fixes this issue by defaulting the extraction base directory in Unix systems to
<temp-dir>/.net/<user-ID> , where
<temp-dir>/.net/ has permission 0777, and
<temp-dir>/.net/<user-ID>/ has permission 0700.

** Risk

Low, scenario is contained, change is small.

** Master Branch

dotnet/runtime#2329
@omajid
Copy link
Member

omajid commented Apr 20, 2020

Can you help me understand why we are using an error prone approach where /tmp/.net (with a predictable name) is used? Wouldn't it be more secure to fall back to a user-specific path? $XDG_CACHE_HOME (falling back to $HOME/.cache/) seems like a location that would be much less susceptible attacks and accidental clashes.

Also, most recent distributions treat /tmp as temporary. systemd, for example, wipes things older than 10 days on /tmp/ on my machine. Compare this with the persistent $HOME/.cache. On the other hand, if we want things cleaned up, using the more secure /run/user/$UID (created on user login, secure without races) seems like the better way to go.

@danmoseley
Copy link
Member

@omajid might be best to open a new issue so folks see it.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants