umask corruption
by Jun'ichi Nomura
Hi,
while using cobbler, I've hit sometimes a strange problem,
that cobblerd starts creating files with wrong permissions like:
--w------- 2 root root 11405684 May 16 14:57 initrd.img
Basically, regular files become "--w-------" and directories become
"d-w---x---".
Once happen, it continues to generate files with such permissions
until restarting the daemon.
Investigating with 'crash' command, I found cobblerd had wrong umask
when the problem happened:
crash> ps cobblerd
PID PPID CPU TASK ST %MEM VSZ RSS COMM
4693 1 0 ffff810027fbc100 IN 0.7 375980 31688 cobblerd
crash> struct task_struct.fs 0xffff810027fbc100
fs = 0xffff810035f6fb00,
crash> struct fs_struct.umask 0xffff810035f6fb00
umask = 0x177,
Normally it has the following umask:
crash> struct fs_struct.umask 0xffff810035f6fb80
umask = 0x12,
The wrong umask explains why the generated files/directories have
such a strange permissions.
I found the following code in api.py and serializer.py are suspicious:
old = os.umask(0x777)
fd = open("/var/lib/cobbler/.mtime","w")
fd.write("%f" % time.time())
fd.close()
os.umask(old)
Firstly, "0x777" seems strange. I guess it should be octal "777".
It seems python ignores upper bits and set "0x177" when you do
os.umask(0x777).
Secondly, if the above code is not serialized each other,
it would end up with wrong umask as follows:
Context A Context B
------------------------------------------
old = umask(0x777)
old = umask(0x777)
[old is 0x777]
umask(old)
umask(old)
Any comments?
Thanks,
--
Jun'ichi Nomura, NEC Corporation
11 years, 11 months