Closed rwd2 closed 4 years ago
So I see this in your strace log:
59936 13:20:17.727300 openat(AT_FDCWD, "\370\247c", O_WRONLY|O_CREAT, 0600) = 3
59936 13:20:17.729831 fcntl(3, F_GETFL) = 0x8001 (flags O_WRONLY|O_LARGEFILE)
59936 13:20:17.730006 chmod("\370\247c", 0600) = 0
59936 13:20:17.730203 fstat(3, {st_mode=S_IFREG|0600, st_size=0, ...}) = 0
59936 13:20:17.730380 write(3, "e[\341,Q\251\320|O\nw;\350\345\246\243'\31\17\260\310n]\343~\27426\373\220N\345\247
[...]
\"+\332\346\364\16\373\324V\262\303\211\302\7\2131\4\350\377\362a\264r\322\330U"..., 1024) = 1024
59936 13:20:17.730609 close(3) = 0
I notice that, after I run pwsafe
, I end up with a file named ~/.rnd
which is similarly 1024 bytes.
It looks like this is your problem -- instead of opening the file ~/.rnd
, it's opening a file with a ... random name?
Not saying I can fix your problem, just that I can see it.
Do you by chance have an environment variable named RANDFILE
? The man page says that this variable is used to select the random number generator file.
'$ env | grep RANDFILE' gives no result. I will ask on the Arch forums how to fix that.
Thanks for the strace --- it make this much easier to figure out. Comparing your strace with one where ~/.rng is created shows that this is indeed pwsafe trying to restore some prng state to openssl's prng. It also shows pwsafe complained about the value of RANDFILE, and never opened nor read ~/.rng:
59936 13:20:14.384750 write(2, "WARNING: pwsafe unable to seed rng. Check $RANDFILE.\n", 53) = 53
in this same location, my local pwsafe opens and reads ~/.rnd and then calls getrandom(2). RANDFILE can also be defined in your openssl.cnf
pwsafe is asking openssl for the name of the randfile (RAND_file_name(3)), and aha, there's a bug in handling the case where there is no rand file at all. I'll fix it in a minute. As a work around, set RANDFILE=$HOME/.rnd and if pwsafe is installed with SIUD set, remove that flag. Aka chmod 755 $(which pwsafe)
.
(Edited to add the bit about SUID)
The workaround does not work. The cause was the pwsafe executable having setuid permissons.
Secure_getenv will return NULL when executed through setuid so $HOME and $RANDFILE are null so RAND_file_name is guaranteed to fail when used in an setuid binary.
(source: https://bbs.archlinux.org/viewtopic.php?pid=1924549#p1924549).
You and loqs are absolutely correct. When the OS sets up the SUID environment all environment variables not known to be safe (and RANDFILE definitely is not safe --- you could overwrite any file in the system with 1k of randomness with it) are cleared.
To use pwsafe with SUID you'd need to built your own with the 1-line fix https://github.com/nsd20463/pwsafe/commit/7cf95579fd0c0849749b1f1dcbd67ca143f76b61
With hindsight, my use of mlock() years ago (which is why SUID is needed) to prevent swapping out of the memory containing the secrets was the wrong trade off. In fact the
In this decade, my swapfiles are encrypted with a random, ephemeral key, and I don't worry about what gets swapped out being readable once power is cut. (Of course this also means my computers can suspend but not hibernate, but such is the price of security).
Ok I built 7cf9557
Changed the permissions of the executable to setuid:
-rwsr-sr-x 1 root root 110K Sep 6 16:46 pwsafe
Bit still the same "WARNING: pwsafe unable to seed rng. Check $RANDFILE." error. Included is the strace of :
strace -o strace.log.1 -f -tt -s 512 pwsafe
The warning is correct. There is no rand file, and there won't be one. The difference is that with the patch, you no longer get randomly names files in the current directory after running pwsafe.
And since you know why, you can safely ignore the warning.
Steps to reproduce:
1) run pwsafe with any valid (or no ) arguments, for example 'pwsafe -ulpE test'
Expected result:
pwsafe runs and does not create any random files in the home folder
Actual result:
pwsafe runs as it should, but eacht time it exits it creates a single file with a random name with question marks, containing binary data, in my home folder. These files seem like they don't serve any purpose and are the result of some bug.
I have been using pwsafe for years this problem started somewhere in 2020. Tested it with current version ( 20181220-1 from Arch Linux AUR)
output of ls -al ~/
output of stat ~/*
output of
https://pastebin.com/G49NCdaY