uutils/coreutils · warning · SmackError::LabelRetrievalFailure
smack-error-no-label-set
Error message
smack-error-no-label-set
What it means
`get_smack_label_for_path` reads the `security.SMACK64` xattr. When SMACK is enabled but the path has no label set (`xattr::get` returns Ok(None)), it wraps a NotFound io::Error with the localized "smack-error-no-label-set" message inside `SmackError::LabelRetrievalFailure`.
Source
Thrown at src/uucore/src/lib/features/smack.rs:89
pub fn set_smack_label_for_self(label: &str) -> Result<(), SmackError> {
if !is_smack_enabled() {
return Err(SmackError::SmackNotEnabled);
}
fs::File::create("/proc/self/attr/current")
.and_then(|mut f| f.write_all(label.as_bytes()))
.map_err(|e| SmackError::LabelSetFailure(label.to_string(), e))
}
/// Gets the SMACK label for a filesystem path via xattr.
pub fn get_smack_label_for_path(path: &Path) -> Result<String, SmackError> {
if !is_smack_enabled() {
return Err(SmackError::SmackNotEnabled);
}
match xattr::get(path, "security.SMACK64") {
Ok(Some(value)) => Ok(String::from_utf8_lossy(&value).trim().to_string()),
Ok(None) => Err(SmackError::LabelRetrievalFailure(io::Error::new(
io::ErrorKind::NotFound,
translate!("smack-error-no-label-set"),
))),
Err(e) => Err(SmackError::LabelRetrievalFailure(e)),
}
}
/// Sets the SMACK label for a filesystem path via xattr.
pub fn set_smack_label_for_path(path: &Path, label: &str) -> Result<(), SmackError> {
if !is_smack_enabled() {
return Err(SmackError::SmackNotEnabled);
}
xattr::set(path, "security.SMACK64", label.as_bytes())
.map_err(|e| SmackError::LabelSetFailure(label.to_string(), e))
}
/// Sets SMACK label for a new path, calling cleanup on failure.View on GitHub (pinned to 325183372a)
Solutions
- Set a label: `chsmack -a <label> <path>`
- Handle the LabelRetrievalFailure(NotFound) case as "unlabeled" rather than a hard error
- Ensure the filesystem supports SMACK64 xattrs or move the file to one that does
Example fix
// before
let label = get_smack_label_for_path(path)?;
// after
let label = match get_smack_label_for_path(path) {
Ok(l) => Some(l),
Err(SmackError::LabelRetrievalFailure(e)) if e.kind() == io::ErrorKind::NotFound => None,
Err(e) => return Err(e.into()),
}; Defensive patterns
Strategy: try-catch
Validate before calling
fn has_smack_label(path: &Path) -> bool {
xattr::get(path, "security.SMACK64")
.map(|v| v.is_some())
.unwrap_or(false)
} Type guard
fn is_no_label_set(err: &SmackError) -> bool {
matches!(err, SmackError::LabelRetrievalFailure(e)
if e.kind() == std::io::ErrorKind::NotFound)
} Try / catch
match get_smack_label_for_path(p) {
Err(SmackError::LabelRetrievalFailure(e))
if e.kind() == io::ErrorKind::NotFound => None, // unlabeled
other => Some(other?),
} Prevention
- Run chsmack -a on files created before SMACK enablement
- Verify the filesystem supports SMACK64 xattrs
- Treat missing labels explicitly in security policy code
When it happens
Trigger: Querying the SMACK label of an unlabeled file (files created before SMACK was enabled, or on filesystems not supporting xattrs that nonetheless report success paths) while `is_smack_enabled()` is true.
Common situations: Running on systems with SMACK LSM active (e.g. Tizen) touching newly created or tmpfs files lacking labels; copying files from non-SMACK systems.
AI-assisted analysis of uutils/coreutils@325183372a (2026-08-31).
Data as JSON: /api/errors/5e41cf42eadda8d9.
Report an issue: GitHub.