Skip to content

getuid, getgid: return host IDs when isolation is disabled - #5402

Draft
programskillforverification wants to merge 2 commits into
rust-lang:masterfrom
programskillforverification:host-uid-gid
Draft

programskillforverification wants to merge 2 commits into
rust-lang:masterfrom
programskillforverification:host-uid-gid

Conversation

@programskillforverification

@programskillforverification programskillforverification commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Fix #5399

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Oct 8, 2026

@RalfJung RalfJung left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for giving this a shot!

However, it seems like this requires direct calls to libc to be implemented? That would then explain why we didn't do this before. Miri should never call libc directly. If there is no way to get the UID from a std API then I am afraid I don't think we should land this. If this is something that Rust programs commonly need, maybe you can convince t-libs to add it to the standard library. If not, it's not something we want to maintain on the Miri side. I understand that this is a somewhat arbitrary line, but we have to draw the line somewhere to avoid Miri scope-creeping into an unmaintainable mess of way too many complicated shims.

View changes since this review

Comment thread src/shims/unix/env.rs
Comment on lines +340 to +366
fn getuid(&mut self) -> InterpResult<'tcx, Scalar> {
let this = self.eval_context_mut();
this.assert_target_os_is_unix("getuid");

interp_ok(Scalar::from_u32(this.get_uid(false)))
}

fn geteuid(&mut self) -> InterpResult<'tcx, Scalar> {
let this = self.eval_context_mut();
this.assert_target_os_is_unix("geteuid");

interp_ok(Scalar::from_u32(this.get_uid(true)))
}

fn getgid(&mut self) -> InterpResult<'tcx, Scalar> {
let this = self.eval_context_mut();
this.assert_target_os_is_unix("getgid");

interp_ok(Scalar::from_u32(this.get_gid(false)))
}

fn getegid(&mut self) -> InterpResult<'tcx, Scalar> {
let this = self.eval_context_mut();
this.assert_target_os_is_unix("getegid");

interp_ok(Scalar::from_u32(this.get_gid(true)))
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These functions are so simple, I don't think they are worth the overhead. You can just call get_uid etc directly from src/shims/unix/foreign_items.rs.

Comment on lines +1303 to +1310
"geteuid" => {
let [] = this.check_shim_sig(
shim_sig!(extern "C" fn() -> libc::uid_t),
(link_name, abi, args),
)?;
let result = this.geteuid()?;
this.write_scalar(result, dest)?;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not convinced that it makes sense for Miri to support the "effective" versions of this.

Comment thread src/shims/env.rs
fn get_uid(&self, effective: bool) -> u32 {
let this = self.eval_context_ref();
if !this.machine.communicate() {
return 1000;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You are repeating the value 1000 multiple times in this file. Please use a constant at the top of the file instead. Well, two constants: DEFAULT_UID and DEFAULT_GID.

Comment thread src/shims/env.rs
cfg_select! {
unix => {
// SAFETY: these functions are always safe to call.
unsafe { if effective { libc::geteuid() } else { libc::getuid() } }

@RalfJung RalfJung Oct 8, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We generally do not want shims that need to call libc directly. Quoting from our contribution guide

we will generally only add shims for functions that can be implemented in a portable way using just what is provided by the Rust standard library

The bar for shims that don't fit this pattern is extremely high. We currently have 0 of them. (The open shim uses libc constants, but only to feed into OpenOptions::custom_flags so we still don't have to call libc ourselves. This is an exceptional case because of how fundamental open is.) Miri has no interest in becoming a program that develops common abstractions over OS-specific functionality -- that's what std is for.

@RalfJung RalfJung removed the S-waiting-on-review Status: Waiting for a review to complete label Oct 11, 2026
@RalfJung
RalfJung marked this pull request as draft October 11, 2026 10:47
@rustbot rustbot added the S-waiting-on-author Status: Waiting for the PR author to address review comments label Oct 11, 2026
@RalfJung RalfJung added the S-blocked Status: blocked on something happening somewhere else label Oct 11, 2026
@RalfJung

Copy link
Copy Markdown
Member

I made this a draft as it is blocked on rust-lang/libs-team#909.

@rustbot

rustbot commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly #5431) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-blocked Status: blocked on something happening somewhere else S-waiting-on-author Status: Waiting for the PR author to address review comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getuid returns a fixed fake uid, which is inconsistent with stat

3 participants