Skip to content
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

[Linux] procfs file reads and UnauthorizedAccessException handling #62513

Closed
am11 opened this issue Dec 8, 2021 · 3 comments · Fixed by #63696
Closed

[Linux] procfs file reads and UnauthorizedAccessException handling #62513

am11 opened this issue Dec 8, 2021 · 3 comments · Fixed by #63696
Assignees
Labels
area-System.Net help wanted [up-for-grabs] Good issue for external contributors os-linux Linux OS (any supported distro)
Milestone

Comments

@am11
Copy link
Member

am11 commented Dec 8, 2021

In restricted environments such as a container with limited access, shared hosting, chroot and other forms of sandbox, .NET process may not have read permissions on procfs files, while the file may exist. This can lead to UnauthorizedAccessException.

While most of the managed code reading procfs files in the runtime repo found by git grep /proc ':/*.cs' ':/!*[tT]est*' seem to handle unauhorized access case, we should try to make the user-experience consistent and align varied styles where possible. A few examples:

catch (Exception ex) when (ex is IOException || ex.InnerException is IOException)

catch (IOException) { }
catch (UnauthorizedAccessException) { }

throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform);

and then there are cases in NetworkInformation, which do not handle the exception at all. Majority of procfs files listed in NetworkInformation/NetworkFiles.cs are read via StringParsingHelpers. Some call sites catch IOException and UnauthorizedAccessException, others don't and it seems unintentional. For instance, GetIcmpV4Statistics and GetTcpIPv4Statistics docs do not mention PlatformNotSupportedException, IOException or UnauthorizedAccessException are the possible exceptions which these APIs can throw, only NetworkInformationException is noted.

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Net untriaged New issue has not been triaged by the area owner labels Dec 8, 2021
@ghost
Copy link

ghost commented Dec 8, 2021

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

In restricted environments such as a container with limited access, shared hosting, chroot and other forms of sandbox, .NET process may not have read permissions on procfs files, while the file may exist. This can lead to UnauthorizedAccessException.

While most of the managed code reading procfs files in the runtime repo found by git grep /proc ':/*.cs' ':/!*[tT]est*' seem to handle unauhorized access case, we should try to make the user-experience consistent and align varied styles where possible. A few examples:

catch (Exception ex) when (ex is IOException || ex.InnerException is IOException)

catch (IOException) { }
catch (UnauthorizedAccessException) { }

throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform);

and then there are cases in NetworkInformation, which do not handle the exception at all. Majority of procfs files listed in NetworkInformation/NetworkFiles.cs are read via StringParsingHelpers. Some call sites catch IOException and UnauthorizedAccessException, others don't and it seems unintentional. For instance, GetIcmpV4Statistics and GetTcpIPv4Statistics docs do not mention PlatformNotSupportedException, IOException or UnauthorizedAccessException are the possible exceptions which these APIs can throw, only NetworkInformationException is noted.

Author: am11
Assignees: -
Labels:

area-System.Net, untriaged

Milestone: -

@wfurt wfurt added the os-linux Linux OS (any supported distro) label Dec 8, 2021
@wfurt
Copy link
Member

wfurt commented Dec 8, 2021

this would be nice to fix for consistency.

@wfurt wfurt added the help wanted [up-for-grabs] Good issue for external contributors label Dec 8, 2021
@karelz
Copy link
Member

karelz commented Dec 9, 2021

Triage: It would be nice clean up. Should not be that difficult to do.

@karelz karelz added this to the Future milestone Dec 9, 2021
@karelz karelz removed the untriaged New issue has not been triaged by the area owner label Dec 9, 2021
@rzikm rzikm self-assigned this Jan 12, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 21, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Feb 24, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Mar 26, 2022
@karelz karelz modified the milestones: Future, 7.0.0 Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net help wanted [up-for-grabs] Good issue for external contributors os-linux Linux OS (any supported distro)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants