Skip to content

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

Open
lamb-j wants to merge 2 commits into
amd-stagingfrom
comgr/secure-getenv-hardening
Open

[Comgr] Use secure_getenv() for environment variable reads on glibc#3069
lamb-j wants to merge 2 commits 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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It seems like the windows one is a different kind of security check, not an analog

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(there's not true windows equivalent afaict)

@chinmaydd chinmaydd added the comgr Related to Code Object Manager label Jun 25, 2026
@ronlieb ronlieb requested a review from jplehr June 27, 2026 19:29
Comment thread amd/comgr/src/comgr-env.cpp
secure_getenv() (and getenv()) return nullptr when the variable is
unset, or under AT_SECURE for the glibc path. getLLVMPath() and
getCachePolicy() returned the raw pointer, relying on the implicit
const char* -> StringRef null conversion. Return "" explicitly instead,
matching getDriverOptionsAppend().
@lamb-j lamb-j requested a review from MixedMatched July 6, 2026 00:29

@jplehr jplehr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good from my point of view

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.

3 participants