Skip to content

[Linux] procfs file reads and UnauthorizedAccessException handling #62513

Closed
@am11

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.

Metadata

Metadata

Assignees

Labels

area-System.Nethelp wanted[up-for-grabs] Good issue for external contributorsos-linuxLinux OS (any supported distro)

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions