{"record":{"id":"5e41cf42eadda8d9","repo":"uutils/coreutils","slug":"smack-error-no-label-set","errorCode":null,"errorMessage":"smack-error-no-label-set","messagePattern":"smack-error-no-label-set","errorType":"exception","errorClass":"SmackError::LabelRetrievalFailure","httpStatus":null,"severity":"warning","filePath":"src/uucore/src/lib/features/smack.rs","lineNumber":89,"sourceCode":"pub fn set_smack_label_for_self(label: &str) -> Result<(), SmackError> {\n    if !is_smack_enabled() {\n        return Err(SmackError::SmackNotEnabled);\n    }\n\n    fs::File::create(\"/proc/self/attr/current\")\n        .and_then(|mut f| f.write_all(label.as_bytes()))\n        .map_err(|e| SmackError::LabelSetFailure(label.to_string(), e))\n}\n\n/// Gets the SMACK label for a filesystem path via xattr.\npub fn get_smack_label_for_path(path: &Path) -> Result<String, SmackError> {\n    if !is_smack_enabled() {\n        return Err(SmackError::SmackNotEnabled);\n    }\n\n    match xattr::get(path, \"security.SMACK64\") {\n        Ok(Some(value)) => Ok(String::from_utf8_lossy(&value).trim().to_string()),\n        Ok(None) => Err(SmackError::LabelRetrievalFailure(io::Error::new(\n            io::ErrorKind::NotFound,\n            translate!(\"smack-error-no-label-set\"),\n        ))),\n        Err(e) => Err(SmackError::LabelRetrievalFailure(e)),\n    }\n}\n\n/// Sets the SMACK label for a filesystem path via xattr.\npub fn set_smack_label_for_path(path: &Path, label: &str) -> Result<(), SmackError> {\n    if !is_smack_enabled() {\n        return Err(SmackError::SmackNotEnabled);\n    }\n\n    xattr::set(path, \"security.SMACK64\", label.as_bytes())\n        .map_err(|e| SmackError::LabelSetFailure(label.to_string(), e))\n}\n\n/// Sets SMACK label for a new path, calling cleanup on failure.","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/uutils/coreutils/blob/325183372aaf86d8ae6feaf4f9548f74fe815102/src/uucore/src/lib/features/smack.rs#L71-L107","documentation":"`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`.","triggerScenarios":"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.","commonSituations":"Running on systems with SMACK LSM active (e.g. Tizen) touching newly created or tmpfs files lacking labels; copying files from non-SMACK systems.","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"],"exampleFix":"// before\nlet label = get_smack_label_for_path(path)?;\n// after\nlet label = match get_smack_label_for_path(path) {\n    Ok(l) => Some(l),\n    Err(SmackError::LabelRetrievalFailure(e)) if e.kind() == io::ErrorKind::NotFound => None,\n    Err(e) => return Err(e.into()),\n};","handlingStrategy":"try-catch","validationCode":"fn has_smack_label(path: &Path) -> bool {\n    xattr::get(path, \"security.SMACK64\")\n        .map(|v| v.is_some())\n        .unwrap_or(false)\n}","typeGuard":"fn is_no_label_set(err: &SmackError) -> bool {\n    matches!(err, SmackError::LabelRetrievalFailure(e)\n        if e.kind() == std::io::ErrorKind::NotFound)\n}","tryCatchPattern":"match get_smack_label_for_path(p) {\n    Err(SmackError::LabelRetrievalFailure(e))\n        if e.kind() == io::ErrorKind::NotFound => None, // unlabeled\n    other => Some(other?),\n}","preventionTips":["Run chsmack -a on files created before SMACK enablement","Verify the filesystem supports SMACK64 xattrs","Treat missing labels explicitly in security policy code"],"tags":["smack","xattr","security","linux"],"backgroundTag":"smack-label-missing","analyzedSha":"325183372aaf86d8ae6feaf4f9548f74fe815102","analyzedAt":"2026-08-31T11:11:36.175Z","contentChangedAt":"2026-08-31T11:11:36.175Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}