Skip to content

[Comgr] Use secure_getenv() for environment variable reads on glibc#3069

Open
lamb-j wants to merge 1 commit into
amd-stagingfrom
comgr/secure-getenv-hardening
Open

[Comgr] Use secure_getenv() for environment variable reads on glibc#3069
lamb-j wants to merge 1 commit into
amd-stagingfrom
comgr/secure-getenv-hardening

Conversation

@lamb-j

@lamb-j lamb-j commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Routes all env-var reads in comgr-env.cpp through a __GLIBC__-gated COMGR_GETENV macro (secure_getenv on glibc, plain getenv elsewhere) so env-controlled file paths (AMD_COMGR_REDIRECT_LOGS, AMD_COMGR_CACHE_DIR, AMD_COMGR_SAVE_TEMPS, AMD_COMGR_TIME_STATISTICS, etc.) are ignored under AT_SECURE (setuid/setgid / file-capability processes).

Windows, macOS, and musl have no AT_SECURE concept and no secure_getenv(), so they take the getenv() fallback — behavior there is unchanged.

Addresses security-triage finding SEC-00183 (ROCM-26567). Path validation / O_NOFOLLOW from the scan's remediation were intentionally not added: these env vars are documented features that legitimately take absolute user paths.

Route all env-var reads in comgr-env.cpp through a __GLIBC__-gated
COMGR_GETENV macro (secure_getenv on glibc, plain getenv elsewhere) so
env-controlled file paths are ignored under AT_SECURE. Windows/macOS/musl
take the getenv fallback, unchanged.

Addresses security-triage finding SEC-00183 (ROCM-26567).
@lamb-j lamb-j requested a review from chinmaydd as a code owner June 25, 2026 21:42
Comment on lines +25 to +29
#if defined(__GLIBC__)
#define COMGR_GETENV secure_getenv
#else
#define COMGR_GETENV getenv
#endif

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Windows seems to have an equivalent. Can we add handling for that ?

https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/getenv-s-wgetenv-s?view=msvc-170

@chinmaydd chinmaydd added the comgr Related to Code Object Manager label Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comgr Related to Code Object Manager

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants