Skip to content

Commit a9c75e7

Browse files
committed
make-initrd-ng: fix file permissions
We want to strip the write bit from files after we copied them. XOR is not the right operator for this, since if the bit is 0 in both the actual permissions and the mask, then the result will be a 1. So in practice, we were assigning write permissions for group and others to all files and we were only stripping the write permissions of the owner (since the owner had write permissions, and so the result of the XOR is 0). The correct thing to do is to AND with the maximum permissions that we want to maintain (which is the inverse of what we want to strip), so that only those bits are preserved and the others are always set to 0.
1 parent cd6c09e commit a9c75e7

File tree

1 file changed

+1
-1
lines changed
  • pkgs/build-support/kernel/make-initrd-ng/src

1 file changed

+1
-1
lines changed

pkgs/build-support/kernel/make-initrd-ng/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ fn copy_file<
212212
}
213213

214214
// Remove writable permissions
215-
permissions.set_mode(permissions.mode() ^ 0o222);
215+
permissions.set_mode(permissions.mode() & 0o555);
216216
fs::set_permissions(&target, permissions)
217217
.wrap_err_with(|| format!("failed to remove writable permissions for {:?}", target))?;
218218
};

0 commit comments

Comments
 (0)