mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chao Yu <yuchao0@huawei.com>
To: Kinglong Mee <kinglongmee@gmail.com>, <jaegeuk@kernel.org>
Cc: <chao@kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-f2fs-devel@lists.sourceforge.net>
Subject: Re: [f2fs-dev] [PATCH] f2fs: don't allow rename unencrypted file to encrypted directory
Date: Thu, 9 Mar 2017 09:33:03 +0800	[thread overview]
Message-ID: <3f804074-49d5-1506-c588-cb2cf2a24200@huawei.com> (raw)
In-Reply-To: <99c57433-c631-4516-b5a2-e22c79e9a93d@gmail.com>

On 2017/3/8 21:35, Kinglong Mee wrote:
> On 3/8/2017 20:08, Chao Yu wrote:
>> In commit d9cdc9033181 ("ext4 crypto: enforce context consistency") we
>> declared that:
>>
>> 2) All files or directories in a directory must be protected using the
>>     same key as their containing directory.
>>
>> But in f2fs_cross_rename there is a vulnerability that allow to cross
>> rename unencrypted file into encrypted directory, it needs to be refused.
> 
> fscrypt_has_permitted_context has do the checking as this patch,
> 
> 168         /* no restrictions if the parent directory is not encrypted */
> 169         if (!parent->i_sb->s_cop->is_encrypted(parent))
> 170                 return 1;
> 171         /* if the child directory is not encrypted, this is always a problem */
> 172         if (!parent->i_sb->s_cop->is_encrypted(child))
> 173                 return 0;
> 
> So, the cross rename unencrypted file into encrypted directory is permitted right now. 
> 
> I have a encrypted directory "ncry",  "new" is unencrypted file.
> 
> [root@nfstestnic f2fs]# renameat2 -x encry/hello new
> Operation not permitted
> [root@nfstestnic f2fs]# renameat2 -x encry/hello new
> Operation not permitted

I've tried this, the same result as yours, so this patch is wrong, please ignore
it, sorry about the noise.

Thanks,

> 
> How do you test it? 
> 
> thanks,
> Kinglong Mee
>>
>> Signed-off-by: Chao Yu <yuchao0@huawei.com>
>> ---
>>  fs/f2fs/namei.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
>> index 25c073f6c7d4..8de684b84cb9 100644
>> --- a/fs/f2fs/namei.c
>> +++ b/fs/f2fs/namei.c
>> @@ -855,6 +855,10 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
>>  			!fscrypt_has_encryption_key(new_dir)))
>>  		return -ENOKEY;
>>  
>> +	if (f2fs_encrypted_inode(old_dir) && !f2fs_encrypted_inode(new_inode) ||
>> +		f2fs_encrypted_inode(new_dir) && !f2fs_encrypted_inode(old_inode))
>> +		return -EPERM;
>> +
>>  	if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) &&
>>  			(old_dir != new_dir) &&
>>  			(!fscrypt_has_permitted_context(new_dir, old_inode) ||
>>
> 
> .
> 

  reply	other threads:[~2017-03-09  1:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-08 12:08 Chao Yu
2017-03-08 13:35 ` [f2fs-dev] " Kinglong Mee
2017-03-09  1:33   ` Chao Yu [this message]
2017-03-10 21:49 ` kbuild test robot
2017-03-10 22:14 ` kbuild test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3f804074-49d5-1506-c588-cb2cf2a24200@huawei.com \
    --to=yuchao0@huawei.com \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=kinglongmee@gmail.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®