Skip to content

exec: context+timeout, find ldconfig via PATH (gosec G204, NixOS) - #684

Open
randomizedcoder wants to merge 1 commit into
NVIDIA:mainfrom
randomizedcoder:security/exec-context-timeout-and-nixos
Open

exec: context+timeout, find ldconfig via PATH (gosec G204, NixOS)#684
randomizedcoder wants to merge 1 commit into
NVIDIA:mainfrom
randomizedcoder:security/exec-context-timeout-and-nixos

Conversation

@randomizedcoder

Copy link
Copy Markdown
Contributor

What: make the exec wrapper context-aware and find ldconfig via PATH.
Why: subprocess timeouts protect the daemon from hung children; PATH lookup makes the prereq check work on NixOS, where /sbin/ldconfig is not always present.
How: Exec.CommandCommandContext; Validate(ctx); 10 s WithTimeout in dcgmlib_rule; exec.LookPath fallback when /sbin/ldconfig{,real} are absent.

Tested by: updated prerequisites suite (passes a context; stubs /sbin/ldconfig.real stat so tests are deterministic on NixOS hosts).

Found by:

  • gosec 2.27.0, rule G204CWE-78 subprocess launched with variable. The wrapper is intentionally generic; suppressed with // #nosec G204 and documented in the new internal/pkg/exec/README.md.
  • golangci-lint 2.12.2, linter noctxfunction calls os/exec.Command instead of CommandContext.

NixOS context: on NixOS /sbin/ldconfig does not exist unless symlinked via systemd.tmpfiles.rules. The PATH fallback removes the need for that workaround.

- Exec interface: Command → CommandContext.
- Validate() takes context; ldconfig call gets 10s timeout.
- Fall back to PATH lookup when /sbin/ldconfig{,real} are absent.
- Fixes NixOS where /sbin/ldconfig is not always present.
- #nosec G204 on the wrapper (generic by design).
- Add internal/pkg/exec/README.md policy.
- Regenerate exec mock.
- Update prerequisites tests.

Signed-off-by: randomizedcoder dave.seddon.ca@gmail.com <dave.seddon.ca@gmail.com>
randomizedcoder added a commit to randomizedcoder/dcgm-exporter that referenced this pull request Jun 20, 2026
Map each finding addressed in the report to its upstream PR
(NVIDIA/dcgm-exporter NVIDIA#681 NVIDIA#682 NVIDIA#683 NVIDIA#684 NVIDIA#685 NVIDIA#686 NVIDIA#687 NVIDIA#688 NVIDIA#689
 NVIDIA#690 NVIDIA#691 NVIDIA#692 NVIDIA#693 NVIDIA#694).

Signed-off-by: randomizedcoder dave.seddon.ca@gmail.com <dave.seddon.ca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant