-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util: make os_chmod best-effort, unless critical=True is specified #8997
base: master
Are you sure you want to change the base?
Conversation
os.chmod is often used as a security precaution, so it is probably not a good idea to have it fail ~silently. Btw, for the storage.py write() use case, it looks to me we might be calling os.chmod too late... The ordering does not look good. I will have a look at that. (EDIT: done in f495511) I don't fully understand the traces in the linked issue. Would not doing the chmod even "fix" those cases? Maybe there are permission issues in general there. |
I don't think it adds much in terms of security. Even without In most cases
The places where
I've ran into similar issues when using NFS mounts, which can have very granular permissions, e.g. permission changes with chmod can be explicity granted/forbidden, independent on read/write access. Maybe certain cloud filesystem offerings have similar restrictions. |
I think it depends on the umask. On many systems it defaults to
True.
Hmm, ok. I see. Note that both reports in #8409 are for custom wallet directories. diff --git a/electrum/storage.py b/electrum/storage.py
index d5770424a2..6e1752e5d7 100644
--- a/electrum/storage.py
+++ b/electrum/storage.py
@@ -94,7 +94,10 @@ class WalletStorage(Logger):
s = self.encrypt_before_writing(data)
temp_path = "%s.tmp.%s" % (self.path, os.getpid())
with open(temp_path, "wb") as f:
- os_chmod(temp_path, mode) # set restrictive perms *before* we write data
+ try:
+ os_chmod(temp_path, mode) # set restrictive perms *before* we write data
+ except PermissionError as e: # tolerate NFS or similar weirdness?
+ self.logger.warning(f"cannot chmod temp wallet file: {e!r}")
f.write(s.encode("utf-8"))
self.pos = f.seek(0, os.SEEK_END)
f.flush() I would prefer |
Set unix file permissions first, before writing data.
A successful
chmod
is not strictly necessary. Changing the default to best-effort, with override option.