Security
Headlines
HeadlinesLatestCVEs

Headline

CVE-2023-42456: Merge pull request from GHSA-2r3c-m6v7-9354 · memorysafety/sudo-rs@bfdbda2

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.

CVE
#auth

Expand Up @@ -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) }
Expand All @@ -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, Expand Down Expand Up @@ -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); Expand Down Expand Up @@ -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©.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©.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©.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©.unwrap(); assert_eq!(&v[…], &[0xD0, 0x50, 0x01, 0x00]); } Expand All @@ -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, Expand Down

Related news

GHSA-2r3c-m6v7-9354: sudo-rs Session File Relative Path Traversal vulnerability

### Background Sudo-rs 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). ### Impact An issue was discovered 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 ...

CVE: Latest News

CVE-2023-50976: Transactions API Authorization by oleiman · Pull Request #14969 · redpanda-data/redpanda