vfs: vfs_tmpfile: ensure O_EXCL flag is enforced
authorPeter Griffin <peter.griffin@linaro.org>
Thu, 3 Nov 2022 17:02:10 +0000 (17:02 +0000)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 19 Nov 2022 07:22:11 +0000 (02:22 -0500)
commit406c706c7b7f1730aa787e914817b8d16b1e99f6
tree570db537a1ab34e0ab06c8d5adc8a31e031e11c7
parent7ee47dcfff1835ff75a794d1075b6b5f5462cfed
vfs: vfs_tmpfile: ensure O_EXCL flag is enforced

If O_EXCL is *not* specified, then linkat() can be
used to link the temporary file into the filesystem.
If O_EXCL is specified then linkat() should fail (-1).

After commit 863f144f12ad ("vfs: open inside ->tmpfile()")
the O_EXCL flag is no longer honored by the vfs layer for
tmpfile, which means the file can be linked even if O_EXCL
flag is specified, which is a change in behaviour for
userspace!

The open flags was previously passed as a parameter, so it
was uneffected by the changes to file->f_flags caused by
finish_open(). This patch fixes the issue by storing
file->f_flags in a local variable so the O_EXCL test
logic is restored.

This regression was detected by Android CTS Bionic fcntl()
tests running on android-mainline [1].

[1] https://android.googlesource.com/platform/bionic/+/
    refs/heads/master/tests/fcntl_test.cpp#352

Fixes: 863f144f12ad ("vfs: open inside ->tmpfile()")
Acked-by: Miklos Szeredi <mszeredi@redhat.com>
Tested-by: Will McVicker <willmcvicker@google.com>
Signed-off-by: Peter Griffin <peter.griffin@linaro.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/namei.c