Received: by 10.223.185.116 with SMTP id b49csp6558260wrg; Wed, 28 Feb 2018 11:28:37 -0800 (PST) X-Google-Smtp-Source: AH8x225AFbTH87LSPfaXYmTSl1YODAI60A4Ulwh3qi/QBICqbs34CaglHN3ALSAUXEH6BIkC4fXo X-Received: by 10.101.83.194 with SMTP id z2mr15082857pgr.133.1519846117859; Wed, 28 Feb 2018 11:28:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519846117; cv=none; d=google.com; s=arc-20160816; b=Qa6908K6USSxGZhX0f9/+2M2UhaE/XjVBTI2HVQMpE+ikBzvd5slsJ0vrP23x0o/bw kRb1nqTvJ4qS4RLnJkVmrk2coAHyBm9W8izgSaMOy6vMBv6AY1A6Ybru8dy14KLd/fJ7 79qdRHgfMr+GKtBP67frBHLa8c0Ay6/XjoexF7RnafVQwsgoOR3NhM2QZ13zm4HK6117 mZGvGuQ590o3j0RNTh9LaJMEtt0X5oclesMbOCyaUDfAJpwPPGosFHDn8wcrAxv/e+dC DwTp4pv9kUBmlPdQ+0Apsw4tPmd+U8OUh5YZAiHrZrXDTBtcpxlWIbn085SEEfGRVzFv tPfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=FXZdSuXACP7HultwrB2L9ZvZRIHOn+pjH2I4BYOeWt0=; b=LLcX9WEjrfW3s4F9p+CBhCPGx4+xLnXe2NlQGyiBnGrf0X8hXpHXljUjM4X5ntBbEl tEWTkHyzYXCYbIyqxuHUbblxc9lfXhKaJgOW0Y2c1Cd32+rz97PN8l09pvTAs5pMcyvh 0etM7lHJ1+IiwwzDWHLD0V97A1pDTIs6qZt0Fh6ezIHM/Sk5bEbbuFpZRwxihMGmaFYg SkZ32ZrijROONyxYPKMdsTAPSUYyLLYy4B5Rwkxdddim9NfttKK//C4PqlmmtpeuKT8s VHNQ2Oj9rZZ28zWj5PWDyOFPWLA4QNwHjPyFXSJRmbrr7Fs8Vg7uRcXFwqbUb2WyDqha oF1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=KFpdz6Za; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d15-v6si1704051plj.284.2018.02.28.11.28.22; Wed, 28 Feb 2018 11:28:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=KFpdz6Za; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933385AbeB1T1m (ORCPT + 99 others); Wed, 28 Feb 2018 14:27:42 -0500 Received: from mail-pl0-f66.google.com ([209.85.160.66]:36546 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933071AbeB1T1k (ORCPT ); Wed, 28 Feb 2018 14:27:40 -0500 Received: by mail-pl0-f66.google.com with SMTP id 61-v6so2119858plf.3; Wed, 28 Feb 2018 11:27:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=FXZdSuXACP7HultwrB2L9ZvZRIHOn+pjH2I4BYOeWt0=; b=KFpdz6ZazKjl9OGqm4xjZbj1sPsR6RNWH6ZqKidpT7wWLymdeX/oj8lbFkI64L9sUo dFlo0aGo0CmMYHPLpM2zvrBdPhir3sHl7g7oThQ6MlpPXr+Fn7QwihYco2KmfzNAblWP f/Mq8xYYxRvpqGcdYkuAoDol4hp05wwmiWj9If3bSJ84UgvWWkjcZs9ORAQOSfaGe2+F WWIGjKSDrOveXJlF1shBUt9nx8l0i8gPzME8p9be3Yu70ek1VI6ftX5iKiTSXtZBgC/j 3YQtdf6PAM1msDAQjWLFS9dsKJW3hbeKK8fgyNcY5dgLyFU6ul9iISNX2+awrchzseUJ llLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=FXZdSuXACP7HultwrB2L9ZvZRIHOn+pjH2I4BYOeWt0=; b=kUoYE7HMAUs6xZMrsCZpMd1jJqWH7RnIFZevppciQyPDbRJBi9NZ1708+nhvTKbVrT tQT390OTCT5kQS3S93jdFsDJ2URAxxSd6IxpOBLJVAzgytgCSGQenM6wBe4Hx5udFUSH vwOE69z9D49ZPWlEkkNlNEEC8Z3CM64G3bhNn0qpbtne7YQHRRzuSIouvu9Yu5EGqKy1 FPz0RRAW47F1C+mp0jU7pV+hdzMdywr3JXZ6Q/4uroptweAXpjHecQOp0TjLOk3BTP2Z 3RSEU1qpiNHHy3eMDnA9NaqaxFWIKtHb0e/0AO2jIovR1XZfg18fbXXfvxm1bemmNd79 mHCw== X-Gm-Message-State: APf1xPAoc0I40W+ytkVUVejmIx85gEMQrNWrKRRS0+LIPAf3Tp+2u2gA 6HHVlRzCOTYPZIC2C6U3dMs/4g== X-Received: by 2002:a17:902:a511:: with SMTP id s17-v6mr3727671plq.206.1519846059600; Wed, 28 Feb 2018 11:27:39 -0800 (PST) Received: from localhost (108-223-40-66.lightspeed.sntcca.sbcglobal.net. [108.223.40.66]) by smtp.gmail.com with ESMTPSA id p79sm4664523pfi.115.2018.02.28.11.27.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 11:27:38 -0800 (PST) Date: Wed, 28 Feb 2018 11:27:37 -0800 From: Guenter Roeck To: Tyler Hicks Cc: ecryptfs@vger.kernel.org, linux-kernel@vger.kernel.org, Al Viro Subject: Re: ecryptfs: Restore support for both encrypted and unencrypted file names Message-ID: <20180228192737.GA18217@roeck-us.net> References: <1518561368-8324-1-git-send-email-linux@roeck-us.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1518561368-8324-1-git-send-email-linux@roeck-us.net> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ping On Tue, Feb 13, 2018 at 02:36:08PM -0800, Guenter Roeck wrote: > Commit 88ae4ab9802e ("ecryptfs_lookup(): try either only encrypted or > plaintext name") was supposed to fix a situation where two files with > the same name and same inode could be created in ecryptfs. One of those > files had an encrypted file name, the other file name was unencrypted. > > After commit 88ae4ab9802e, having a mix of encrypted and unencrypted file > names is no longer supposed to be possible. However, that is not the case. > The only difference is that it is now even easier to create a situation > where two files with the same name coexist (one encrypted and the other > not encrypted). In practice, this looks like the following (files > created with v4.14.12). > > ecryptfs mounted with file name encryption enabled: > > $ ls -li > total 48 > 5252822 -rw-rw-r-- 1 groeck groeck 10 Jan 20 13:02 myfile > 5252822 -rw-rw-r-- 1 groeck groeck 10 Jan 20 13:02 myfile > 5252824 -rw-rw-r-- 1 groeck groeck 10 Jan 20 15:36 myfile2 > 5252824 -rw-rw-r-- 1 groeck groeck 10 Jan 20 15:36 myfile2 > $ grep . * > myfile:encrypted > myfile:encrypted > myfile2:encrypted > myfile2:encrypted > > $ ls -li > total 48 > 5252824 -rw-rw-r-- 1 groeck groeck 10 Jan 20 15:36 > ECRYPTFS_FNEK_ENCRYPTED.FWbF9U6H6L6ekEZYGWnkfR4wMiyeTVoCeVun.BU8Zu5-njbcIPoApxk7-E-- > 5252822 -rw-rw-r-- 1 groeck groeck 10 Jan 20 13:02 > ECRYPTFS_FNEK_ENCRYPTED.FWbF9U6H6L6ekEZYGWnkfR4wMiyeTVoCeVunt0fda7t9YCtJ70cm911yZ--- > 5252817 -rw-rw-r-- 1 groeck groeck 12 Jan 20 12:52 myfile > 5252827 -rw-rw-r-- 1 groeck groeck 12 Jan 20 15:37 myfile2 > > $ grep . * > ECRYPTFS_FNEK_ENCRYPTED.FWbF9U6H6L6ekEZYGWnkfR4wMiyeTVoCeVun.BU8Zu5-njbcIPoApxk7-E--:encrypted > ECRYPTFS_FNEK_ENCRYPTED.FWbF9U6H6L6ekEZYGWnkfR4wMiyeTVoCeVunt0fda7t9YCtJ70cm911yZ---:encrypted > myfile:unencrypted > myfile2:unencrypted > > Creating a file with file name encryption disabled and remounting with > file name encryption enabled results in the following. > > $ ls -li > ls: cannot access 'myfile3': No such file or directory > total 48 > 5252822 -rw-rw-r-- 1 groeck groeck 10 Jan 20 13:02 myfile > 5252822 -rw-rw-r-- 1 groeck groeck 10 Jan 20 13:02 myfile > 5252824 -rw-rw-r-- 1 groeck groeck 10 Jan 20 15:36 myfile2 > 5252824 -rw-rw-r-- 1 groeck groeck 10 Jan 20 15:36 myfile2 > ? -????????? ? ? ? ? ? myfile3 > > Prior to commit 88ae4ab9802e, the file system had to be mounted with > encrypted file names first to create a file, then the same had to be > repeated after mounting with unencrypted file names. Now the duplicate > files can be created both ways (unencrypted _or_ encrypted first). > > The only real difference is that it is no longer possible to have a > _working_ combination of encrypted and unencrypted file names. In other > words, commit 88ae4ab9802e results in reduced functionality with no > benefit whatsoever. > > Restore ability to have a mix of unencrypted and encrypted files. > This effectively reverts commit 88ae4ab9802e, but the code is now > better readable since it avoids a number of goto statements. > > Cc: Al Viro > Signed-off-by: Guenter Roeck > --- > fs/ecryptfs/inode.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c > index 847904aa63a9..14a5c096ead6 100644 > --- a/fs/ecryptfs/inode.c > +++ b/fs/ecryptfs/inode.c > @@ -392,11 +392,11 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, > int rc = 0; > > lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent); > - > + lower_dentry = lookup_one_len_unlocked(name, lower_dir_dentry, len); > mount_crypt_stat = &ecryptfs_superblock_to_private( > ecryptfs_dentry->d_sb)->mount_crypt_stat; > - if (mount_crypt_stat > - && (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)) { > + if (IS_ERR(lower_dentry) && > + (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)) { > rc = ecryptfs_encrypt_and_encode_filename( > &encrypted_and_encoded_name, &len, > mount_crypt_stat, name, len); > @@ -405,10 +405,10 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, > "filename; rc = [%d]\n", __func__, rc); > return ERR_PTR(rc); > } > - name = encrypted_and_encoded_name; > + lower_dentry = lookup_one_len_unlocked( > + encrypted_and_encoded_name, lower_dir_dentry, len); > } > > - lower_dentry = lookup_one_len_unlocked(name, lower_dir_dentry, len); > if (IS_ERR(lower_dentry)) { > ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " > "[%ld] on lower_dentry = [%s]\n", __func__,