Ubuntu – User root can’t write to file in /tmp owned by someone else in 20.04, but can in 18.04

20.04bashcommand linepermissionsroot

In Ubuntu 18.04, I can create a file as one user in /tmp, and write to it as user root (despite the sticky bit being set on /tmp).

In Ubuntu 20.04, I get a Permission Denied error as user root.

Ubuntu 18.04:

# As user "ubuntu":
touch /tmp/tmplock

# As user "root":
echo "foo" > /tmp/tmplock

cat /tmp/tmplock
# Outputs "foo"

ls -lah /tmp
drwxrwxrwt 32 root   root    20K Jun 16 18:36 .
-rw-rw-r--  1 ubuntu ubuntu    4 Jun 16 18:36 tmplock

Ubuntu 20.04:

# As user "ubuntu":
touch /tmp/tmplock

# As user "root":
echo "foo" > /tmp/tmplock
# Outputs: bash: /tmp/tmplock: Permission denied

ls -lah /tmp
drwxrwxrwt 12 root   root   4.0K Jun 16 18:15 .
-rw-rw-r--  1 ubuntu ubuntu    0 Jun 16 18:14 tmplock

I can't find any information on if this is related to the sticky bit, or an underlying Linux kernel change, or anything.

Does anyone know what can explain the change in behavior?

Best Answer

  • To change the behavior back to the 18.04 default:

    sudo sysctl fs.protected_regular=0  
    

    See the accepted answer to

    https://unix.stackexchange.com/questions/503111/group-permissions-for-root-not-working-in-tmp

    Sigh, sometimes the cure is worse than the disease.

  • Related Question