Skip to content

Commit cce5ff2

Browse files
authored
Merge pull request #596 from Dstack-TEE/feat/fix-565-wait-for-generation-change
tdx-attest: fix infinite loop in ConfigFS generation wait (#565)
2 parents f87c977 + 1009898 commit cce5ff2

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

tdx-attest/src/linux.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::os::unix::io::AsRawFd;
1818
use std::path::Path;
1919
use std::sync::Mutex;
2020
use std::thread;
21-
use std::time::Duration;
21+
use std::time::{Duration, Instant};
2222

2323
use thiserror::Error;
2424

@@ -53,6 +53,10 @@ const QGS_MSG_GET_QUOTE_RESP: u32 = 1;
5353
const QGS_MSG_VERSION_MAJOR: u16 = 1;
5454
const QGS_MSG_VERSION_MINOR: u16 = 0;
5555

56+
// ConfigFS generation wait parameters
57+
const CONFIGFS_GEN_WAIT_TIMEOUT_SECS: u64 = 5;
58+
const CONFIGFS_GEN_POLL_INTERVAL_MS: u64 = 10;
59+
5660
// ============================================================================
5761
// ioctl definitions for /dev/tdx_guest
5862
// ============================================================================
@@ -431,12 +435,19 @@ fn write_inblob_with_retry(path: &str, data: &TdxReportData) -> Result<()> {
431435
}
432436

433437
fn wait_for_generation_change(path: &str, current: i64) -> Result<i64> {
438+
let deadline = Instant::now() + Duration::from_secs(CONFIGFS_GEN_WAIT_TIMEOUT_SECS);
439+
434440
loop {
435441
let gen = read_generation(path)?;
436442
if gen != current {
437443
return Ok(gen);
438444
}
439-
thread::sleep(Duration::from_micros(1));
445+
if Instant::now() >= deadline {
446+
return Err(TdxAttestError::QuoteFailure(
447+
"timed out waiting for configfs generation to advance".to_string(),
448+
));
449+
}
450+
thread::sleep(Duration::from_millis(CONFIGFS_GEN_POLL_INTERVAL_MS));
440451
}
441452
}
442453

0 commit comments

Comments
 (0)