Skip to content

[Linux] procfs file reads and UnauthorizedAccessException handling #62513

Closed

Description

@am11

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.

Activity

  1. ghost added
    untriaged
    on Dec 8, 2021
  2. added
    os-linux
    on Dec 8, 2021
  3. wfurt commented on Dec 8, 2021

    @wfurt
    Member

    this would be nice to fix for consistency.

  4. added
    help wanted
    on Dec 8, 2021
  5. karelz commented on Dec 9, 2021

    @karelz
    Member

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

  6. added this to the Future milestone on Dec 9, 2021
  7. removed
    untriaged
    on Dec 9, 2021
  8. self-assigned this
    on Jan 12, 2022
  9. ghost added
    in-pr
    on Jan 21, 2022
  10. ghost removed
    in-pr
    on Feb 24, 2022
  11. ghost locked as resolved and limited conversation to collaborators on Mar 26, 2022
  12. modified the milestones: Future, 7.0.0 on Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Nethelp wantedos-linux

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions