Hi there, The latest eCryptfs changes the write path to perform the encryption in ecryptfs_writepage, which minimizes the number of encryptions, however, if the ecryptfs_writepage is invoked in the context of page cache write back kernel thread, to write out the dirty pages to the lower page cache, the quota check by the lower file system gotta be ignored since the kernel thread has the CAP_SYS_CAPABILITY. To validate this, just let a user application open a file, write much data into it, then sleep for several miniutes before close it, those data gotta definitely be safely written into the disk in despite of the user quota limit. The patch below try to fix this by simply temporarily removing the capability from the kernel thread before invoking ecryptfs_write_lower, thereafter, reassign it. Fixme: It seems those commented codes in the patch (prepare_creds(), ..., commit_creds()) do the thing in a more official way, but they perform too much validity checks which are not needed in our case. Only if the simple cap_lower/cap_raise call will trigger some race condtions, otherwise I think it should be ok? Cheers, Li Wang signed-off-by: Li Wang <liwang@xxxxxxxxxxx> Yong Peng <pengyong@xxxxxxxxxxxxxx> --- --- fs/ecryptfs/crypto.c.orig 2011-11-26 20:21:08.109304786 +0800 +++ fs/ecryptfs/crypto.c 2011-11-26 20:20:09.651315978 +0800 @@ -506,8 +506,33 @@ int ecryptfs_encrypt_page(struct page *p * (PAGE_CACHE_SIZE / crypt_stat->extent_size)) + extent_offset), crypt_stat); + /* + * Temporarily remove the CAP_SYS_RESOURCE capability from the + * write back kernel thread to let it undergo quota check by + * the lower file system + */ + if (current->flags & PF_KTHREAD) { + cap_lower(((struct cred *)current->cred)->cap_effective, CAP_SYS_RESOURCE); + /* + * struct cred *cred; + * cred = prepare_creds(); + * if (unlikely(!cred)) { + * rc = -ENOMEM; + * goto out; + * } + * cap_lower(cred->cap_effective, CAP_SYS_RESOURCE); + * rc = commit_creds(cred); + * if (rc) + * goto out; + */ + } rc = ecryptfs_write_lower(ecryptfs_inode, enc_extent_virt, offset, crypt_stat->extent_size); + /* + * Reassign the CAP_SYS_RESOURCE capability + */ + if (current->flags & PF_KTHREAD) + cap_raise(((struct cred *)current->cred)->cap_effective, CAP_SYS_RESOURCE); if (rc < 0) { ecryptfs_printk(KERN_ERR, "Error attempting " "to write lower page; rc = [%d]" ?韬{.n?壏煯壄?%娝?檩?w?{.n?壏瀝缉蝶?{ay?蕠跈?jf"穐殢飦?戧鐉_璁(殠娸"濟?m??G珴?⒏?櫒璀?x忈