VYPR
Low severityNVD Advisory· Published Sep 21, 2023· Updated Feb 13, 2025

sudo-rs Session File Relative Path Traversal vulnerability

CVE-2023-42456

Description

Sudo-rs, a memory safe implementation of sudo and su, allows users to not have to enter authentication at every sudo attempt, but instead only requiring authentication every once in a while in every terminal or process group. Only once a configurable timeout has passed will the user have to re-authenticate themselves. Supporting this functionality is a set of session files (timestamps) for each user, stored in /var/run/sudo-rs/ts. These files are named according to the username from which the sudo attempt is made (the origin user).

An issue was discovered in versions prior to 0.2.1 where usernames containing the . and / characters could result in the corruption of specific files on the filesystem. As usernames are generally not limited by the characters they can contain, a username appearing to be a relative path can be constructed. For example we could add a user to the system containing the username ../../../../bin/cp. When logged in as a user with that name, that user could run sudo -K to clear their session record file. The session code then constructs the path to the session file by concatenating the username to the session file storage directory, resulting in a resolved path of /bin/cp. The code then clears that file, resulting in the cp binary effectively being removed from the system.

An attacker needs to be able to login as a user with a constructed username. Given that such a username is unlikely to exist on an existing system, they will also need to be able to create the users with the constructed usernames.

The issue is patched in version 0.2.1 of sudo-rs. Sudo-rs now uses the uid for the user instead of their username for determining the filename. Note that an upgrade to this version will result in existing session files being ignored and users will be forced to re-authenticate. It also fully eliminates any possibility of path traversal, given that uids are always integer values.

The sudo -K and sudo -k commands can run, even if a user has no sudo access. As a workaround, make sure that one's system does not contain any users with a specially crafted username. While this is the case and while untrusted users do not have the ability to create arbitrary users on the system, one should not be able to exploit this issue.

AI Insight

LLM-synthesized narrative grounded in this CVE's description and references.

A path traversal vulnerability in sudo-rs allows an attacker to delete arbitrary files by using a crafted username and sudo -K.

Vulnerability

Description The sudo-rs utility, a memory-safe reimplementation of sudo, maintains timestamp files in /var/run/sudo-rs/ts/ to allow cached authentication [1]. Prior to version 0.2.1, these files were named after the username of the invoking user. A path traversal vulnerability arises because usernames can contain characters like . and /, allowing an attacker to construct a username that resembles a relative path [1]. For example, a user named ../../../../bin/cp would cause sudo-rs to resolve the session file path to /bin/cp when running sudo -K [1].

Exploitation

An attacker must be able to log in as a user with such a crafted username and have the ability to create users on the system [1]. The sudo -K or sudo -k command, which clears the user's timestamp file, will then remove the target file (e.g., /bin/cp) from the filesystem [1]. No special privileges beyond the ability to run sudo -K are required; this command works even without actual sudo access [1].

Impact

Successful exploitation results in arbitrary file deletion, potentially causing denial of service or disrupting system operations. The vulnerability was reported during a security audit of sudo-rs [3].

Mitigation

The vulnerability is patched in version 0.2.1 of sudo-rs. The fix changes the file naming scheme to use the user's numeric UID instead of the username, eliminating the path traversal vector [1][4]. Users should upgrade immediately; existing session files will be invalidated, requiring re-authentication [1].

AI Insight generated on May 20, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
sudo-rscrates.io
< 0.2.10.2.1

Affected products

3

Patches

1
bfdbda22968e

Merge pull request from GHSA-2r3c-m6v7-9354

https://github.com/memorysafety/sudo-rsRuben NijveldSep 21, 2023via ghsa
3 files changed · +22 19
  • src/sudo/mod.rs+2 2 modified
    @@ -92,15 +92,15 @@ fn sudo_process() -> Result<(), Error> {
                 SudoAction::RemoveTimestamp => {
                     let user = resolve_current_user()?;
                     let mut record_file =
    -                    SessionRecordFile::open_for_user(&user.name, Duration::seconds(0))?;
    +                    SessionRecordFile::open_for_user(user.uid, Duration::seconds(0))?;
                     record_file.reset()?;
                     Ok(())
                 }
                 SudoAction::ResetTimestamp => {
                     if let Some(scope) = RecordScope::for_process(&Process::new()) {
                         let user = resolve_current_user()?;
                         let mut record_file =
    -                        SessionRecordFile::open_for_user(&user.name, Duration::seconds(0))?;
    +                        SessionRecordFile::open_for_user(user.uid, Duration::seconds(0))?;
                         record_file.disable(scope, None)?;
                     }
                     Ok(())
    
  • src/sudo/pipeline.rs+6 6 modified
    @@ -133,7 +133,7 @@ impl<Policy: PolicyPlugin, Auth: AuthPlugin> Pipeline<Policy, Auth> {
                 context.use_session_records,
                 scope,
                 context.current_user.uid,
    -            &context.current_user.name,
    +            context.current_user.uid,
                 prior_validity,
             );
             self.authenticator.init(context)?;
    @@ -201,7 +201,7 @@ fn determine_auth_status(
         use_session_records: bool,
         record_for: Option<RecordScope>,
         auth_uid: UserId,
    -    current_user: &str,
    +    current_user: UserId,
         prior_validity: Duration,
     ) -> AuthStatus {
         if !must_policy_authenticate {
    @@ -232,13 +232,13 @@ fn determine_auth_status(
         }
     }
     
    -struct AuthStatus<'a> {
    +struct AuthStatus {
         must_authenticate: bool,
    -    record_file: Option<SessionRecordFile<'a>>,
    +    record_file: Option<SessionRecordFile>,
     }
     
    -impl<'a> AuthStatus<'a> {
    -    fn new(must_authenticate: bool, record_file: Option<SessionRecordFile<'a>>) -> AuthStatus<'a> {
    +impl AuthStatus {
    +    fn new(must_authenticate: bool, record_file: Option<SessionRecordFile>) -> AuthStatus {
             AuthStatus {
                 must_authenticate,
                 record_file,
    
  • src/system/timestamp.rs+14 11 modified
    @@ -35,18 +35,18 @@ const SIZE_OF_BOOL: i64 = std::mem::size_of::<BoolStorage>() as i64;
     const MOD_OFFSET: i64 = SIZE_OF_TS + SIZE_OF_BOOL;
     
     #[derive(Debug)]
    -pub struct SessionRecordFile<'u> {
    +pub struct SessionRecordFile {
         file: File,
         timeout: Duration,
    -    for_user: &'u str,
    +    for_user: UserId,
     }
     
    -impl<'u> SessionRecordFile<'u> {
    +impl SessionRecordFile {
         const BASE_PATH: &'static str = "/var/run/sudo-rs/ts";
     
    -    pub fn open_for_user(user: &'u str, timeout: Duration) -> io::Result<Self> {
    +    pub fn open_for_user(user: UserId, timeout: Duration) -> io::Result<Self> {
             let mut path = PathBuf::from(Self::BASE_PATH);
    -        path.push(user);
    +        path.push(user.to_string());
             SessionRecordFile::new(user, secure_open_cookie_file(&path)?, timeout)
         }
     
    @@ -59,7 +59,7 @@ impl<'u> SessionRecordFile<'u> {
         /// Create a new SessionRecordFile from the given i/o stream.
         /// Timestamps in this file are considered valid if they were created or
         /// updated at most `timeout` time ago.
    -    pub fn new(for_user: &'u str, io: File, timeout: Duration) -> io::Result<Self> {
    +    pub fn new(for_user: UserId, io: File, timeout: Duration) -> io::Result<Self> {
             let mut session_records = SessionRecordFile {
                 file: io,
                 timeout,
    @@ -578,6 +578,8 @@ mod tests {
     
         use crate::system::tests::tempfile;
     
    +    const TEST_USER_ID: UserId = 1000;
    +
         impl SetLength for Cursor<Vec<u8>> {
             fn set_len(&mut self, new_len: usize) -> io::Result<()> {
                 self.get_mut().truncate(new_len);
    @@ -714,25 +716,25 @@ mod tests {
             // valid header should remain valid
             let c = tempfile_with_data(&[0xD0, 0x50, 0x01, 0x00]).unwrap();
             let timeout = Duration::seconds(30);
    -        assert!(SessionRecordFile::new("test", c.try_clone().unwrap(), timeout).is_ok());
    +        assert!(SessionRecordFile::new(TEST_USER_ID, c.try_clone().unwrap(), timeout).is_ok());
             let v = data_from_tempfile(c).unwrap();
             assert_eq!(&v[..], &[0xD0, 0x50, 0x01, 0x00]);
     
             // invalid headers should be corrected
             let c = tempfile_with_data(&[0xAB, 0xBA]).unwrap();
    -        assert!(SessionRecordFile::new("test", c.try_clone().unwrap(), timeout).is_ok());
    +        assert!(SessionRecordFile::new(TEST_USER_ID, c.try_clone().unwrap(), timeout).is_ok());
             let v = data_from_tempfile(c).unwrap();
             assert_eq!(&v[..], &[0xD0, 0x50, 0x01, 0x00]);
     
             // empty header should be filled in
             let c = tempfile_with_data(&[]).unwrap();
    -        assert!(SessionRecordFile::new("test", c.try_clone().unwrap(), timeout).is_ok());
    +        assert!(SessionRecordFile::new(TEST_USER_ID, c.try_clone().unwrap(), timeout).is_ok());
             let v = data_from_tempfile(c).unwrap();
             assert_eq!(&v[..], &[0xD0, 0x50, 0x01, 0x00]);
     
             // invalid version should reset file
             let c = tempfile_with_data(&[0xD0, 0x50, 0xAB, 0xBA, 0x0, 0x0]).unwrap();
    -        assert!(SessionRecordFile::new("test", c.try_clone().unwrap(), timeout).is_ok());
    +        assert!(SessionRecordFile::new(TEST_USER_ID, c.try_clone().unwrap(), timeout).is_ok());
             let v = data_from_tempfile(c).unwrap();
             assert_eq!(&v[..], &[0xD0, 0x50, 0x01, 0x00]);
         }
    @@ -741,7 +743,8 @@ mod tests {
         fn can_create_and_update_valid_file() {
             let timeout = Duration::seconds(30);
             let c = tempfile_with_data(&[]).unwrap();
    -        let mut srf = SessionRecordFile::new("test", c.try_clone().unwrap(), timeout).unwrap();
    +        let mut srf =
    +            SessionRecordFile::new(TEST_USER_ID, c.try_clone().unwrap(), timeout).unwrap();
             let tty_scope = RecordScope::Tty {
                 tty_device: 0,
                 session_pid: 0,
    

Vulnerability mechanics

Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

9

News mentions

0

No linked articles in our index yet.