You are not logged in.

#1 2019-12-06 23:33:30

Exargon
Member
Registered: 2019-12-06
Posts: 2

[Solved]Root can't overwrite/append files owned by other users in /tmp

So I discovered a weird thing about /tmp while messing around the other day. When I create a file with my normal user in /tmp, I am not able to overwrite it as root!

To test this you can simply run

$ touch /tmp/test

and as root simply try

# echo test > /tmp/test

In my case I get a Permission Denied error after the last command. I also get an error when I try to write to it with other tools like vim and python.

I can still do rm, mv, chmod and all other whole file operations. But even if I give the file full permission by

# chmod 777 /tmp/test

I can still not write to it as root.

I can for the life of me not figure out what is causing this. I have tried to create a file with the exact same permissions, in a folder with the exact same permissions, and even on another tmpfs mounted with, as far as I can tell from

$ systemctl cat /tmp

,the exact same mount options. None recreate the behaviour. There are no file attributes messing things up either (lsattr just throws an ioctl error, and getfattr returns nothing. Attributes are presumably not enabled).

I am running out of ideas, and I can't seem to find any information about this anywhere. Do any of you experience this too? Is this normal behaviour (some security feature)? Do any of you know what is causing this?

This affects all the systems I've tried it on so far, up to date or otherwise, so I assume it is normal behaviour. It just annoys me that I can't figure out why it is behaving this way.

Last edited by Exargon (2019-12-07 00:53:48)

Offline

#2 2019-12-07 00:02:16

alkallio
Member
Registered: 2017-11-27
Posts: 1

Re: [Solved]Root can't overwrite/append files owned by other users in /tmp

Never noticed this before. Apparently it's because of fs.protected_regular parameter.

You can see the parameter's value with the following command:

sysctl -a | grep fs.protected_regular

More info available here: https://unix.stackexchange.com/a/503169

Offline

#3 2019-12-07 00:05:52

koffeinfriedhof
Member
Registered: 2017-11-30
Posts: 91

Re: [Solved]Root can't overwrite/append files owned by other users in /tmp

Hi!

Writing in /tmp is only allowed for the owner due to its world writable sticky - property. This was included in the kernel due to some security issues, but I forgot about the name used for it smile

Offline

#4 2019-12-07 00:53:09

Exargon
Member
Registered: 2019-12-06
Posts: 2

Re: [Solved]Root can't overwrite/append files owned by other users in /tmp

Thanks guys smile . Had a feeling it was connected to the sticky somehow, but couldn't seem to replicate it. I see now that in my hurry I left the owner of the folder and the file the same (as opposed to being different in the /tmp case). Interesting that this is an exception for the fs.protected_parameter.

Good to know for the future. I already know one application that this, through frankly careless writing to /tmp, can cause issues for.

Offline

Board footer

Powered by FluxBB