ovl: drop CAP_SYS_RESOURCE from saved mounter's credentials
authorKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
Tue, 10 Jan 2017 18:30:21 +0000 (21:30 +0300)
committerMiklos Szeredi <mszeredi@redhat.com>
Tue, 7 Feb 2017 14:47:14 +0000 (15:47 +0100)
If overlay was mounted by root then quota set for upper layer does not work
because overlay now always use mounter's credentials for operations.
Also overlay might deplete reserved space and inodes in ext4.

This patch drops capability SYS_RESOURCE from saved credentials.
This affects creation new files, whiteouts, and copy-up operations.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Fixes: 1175b6b8d963 ("ovl: do operations on underlying file system in mounter's context")
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/overlayfs/super.c

index 346f668e7df027e605d30ed971e26b90cecae38c..7b218818136779ced357489f4b88debc32575ece 100644 (file)
@@ -721,6 +721,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
        unsigned int stacklen = 0;
        unsigned int i;
        bool remote = false;
+       struct cred *cred;
        int err;
 
        err = -ENOMEM;
@@ -901,10 +902,13 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
        else
                sb->s_d_op = &ovl_dentry_operations;
 
-       ufs->creator_cred = prepare_creds();
-       if (!ufs->creator_cred)
+       ufs->creator_cred = cred = prepare_creds();
+       if (!cred)
                goto out_put_lower_mnt;
 
+       /* Never override disk quota limits or use reserved space */
+       cap_lower(cred->cap_effective, CAP_SYS_RESOURCE);
+
        err = -ENOMEM;
        oe = ovl_alloc_entry(numlower);
        if (!oe)