ovl: check the capability before cred overridden
authorJiufei Xue <jiufei.xue@linux.alibaba.com>
Mon, 6 May 2019 07:41:02 +0000 (15:41 +0800)
committerMiklos Szeredi <mszeredi@redhat.com>
Mon, 6 May 2019 12:00:37 +0000 (14:00 +0200)
commit98487de318a6f33312471ae1e2afa16fbf8361fe
tree8552812bd49f44f8d850fce0fef838f85a2f9ed9
parentd989903058a83e8536cc7aadf9256a47d5c173fe
ovl: check the capability before cred overridden

We found that it return success when we set IMMUTABLE_FL flag to a file in
docker even though the docker didn't have the capability
CAP_LINUX_IMMUTABLE.

The commit d1d04ef8572b ("ovl: stack file ops") and dab5ca8fd9dd ("ovl: add
lsattr/chattr support") implemented chattr operations on a regular overlay
file. ovl_real_ioctl() overridden the current process's subjective
credentials with ofs->creator_cred which have the capability
CAP_LINUX_IMMUTABLE so that it will return success in
vfs_ioctl()->cap_capable().

Fix this by checking the capability before cred overridden. And here we
only care about APPEND_FL and IMMUTABLE_FL, so get these information from
inode.

[SzM: move check and call to underlying fs inside inode locked region to
prevent two such calls from racing with each other]

Signed-off-by: Jiufei Xue <jiufei.xue@linux.alibaba.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/overlayfs/file.c