From: Tyler Hicks Subject: Re: [PATCH] eCryptfs: support creating plain files Date: Thu, 10 Mar 2011 18:28:26 -0600 Message-ID: <20110311002825.GE14558@boyd.l.tihix.com> References: <1298990647-2218-1-git-send-email-ethan.too@gmail.com> <20110308232156.GD4828@boyd.l.tihix.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: linux-fsdevel , ecryptfs-devel To: Ethan Du Return-path: Received: from e39.co.us.ibm.com ([32.97.110.160]:33689 "EHLO e39.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754358Ab1CKA23 (ORCPT ); Thu, 10 Mar 2011 19:28:29 -0500 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by e39.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id p2B0Fax0013429 for ; Thu, 10 Mar 2011 17:15:36 -0700 Received: from d03av05.boulder.ibm.com (d03av05.boulder.ibm.com [9.17.195.85]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p2B0SShG120866 for ; Thu, 10 Mar 2011 17:28:28 -0700 Received: from d03av05.boulder.ibm.com (loopback [127.0.0.1]) by d03av05.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p2B0SSh2009806 for ; Thu, 10 Mar 2011 17:28:28 -0700 Content-Disposition: inline In-Reply-To: Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Wed Mar 09, 2011 at 10:43:45AM +0800, Ethan Du = wrote: > On Wed, Mar 9, 2011 at 7:21 AM, Tyler Hicks wrote: > > On Wed Mar 02, 2011 at 11:09:25AM +0800, Ethan Du wrote: > >> With ecryptfs_create_plain mount option, newly created file will b= e > >> plain lower fs file > >> For those who want to read encrypted files, but want no more encry= pted files > > > > Hi Ethan - Lets get the process issues out of the way. The gmail we= b > > client seems to break patches. See Documentation/email-clients.txt = for > > details. Also, it is a good idea to include the maintainers and pro= ject > > mailing list in your distribution list to make sure that the right > > people see the patch. scripts/get_maintainer.pl works or you can > > manually take a look at the MAINTAINERS file. >=20 > Thanks for the info. I git-send-email to the mail list > ecryptfs-devel@lists.launchpad.net. And then lazily forwarded it to > here, maybe this is the reason. ecryptfs-devel is moderated for all non-members, so that's probably to blame. No worries, though. Just something to keep in mind to make sure your future patches don't get lost. >=20 > > > > For the patch itself, I'm not sure that this mount option would get= used > > by many people, yet would add to the eCryptfs test burden. How do y= ou > > see this being used? I can't imagine many users wanting to disable > > encrypted file creation at a mount wide level. >=20 > I think for most users, when they want to disable encryption on a > mount point, they will copy the files to elsewhere, and then unmount > ecryptfs, and move them back. Can you explain why you want to disable encryption on a mount point? > However, I am on a phone, the internal storage is limited, and I am > using ecryptfs on external micro SD card, the card could be 8/16/32GB= , > which may be a lot larger then the internal storage. >=20 > So I can't do a one time copy. Another option is to convert those > files one by one, however, even I can do it, if the micro SD card is > unfortunately full, the process could last for hours, and phone may > run out of battery. It is still hard to control. >=20 > So adding this mount option is the lazy way for me. >=20 > > > > I see the usefulness of optionally creating plaintext files at a mo= re > > granular level. It has always been a goal to create an eCryptfs > > encryption policy language that could define things like, "User tyh= icks > > uses key with sig deadbeefdeadbeef and aes-128", or "Files with the > > svirt_image_t type get encrypted by key with sig feedbeeffeedbeef a= nd > > aes-256", or "Files under ~/public receive no encryption". >=20 > Won't ecryptfs header exist in the lower file in such case? These decisions would have to be made at file creation time. If the decision was to not encrypt a file, then no eCryptfs header would be written out during file creation. >=20 > > > > Another idea that popped up somewhat recently is to have per-mount > > read and write keyrings. A process can clear their keyrings if they= want > > to do things like write plaintext or read ciphertext. > > > > However, I'll need a little more convincing before I see the value = of > > doing this with a mount option. >=20 > I've been using the patch for a while, finally decide to send out in > case someone else has the same requirement. I really do appreciate you sending it out. I'm just hesitant to add another mount opt which modifies the eCryptfs read and/or write paths unless it is something very useful. It isn't easy to remove mount options after the fact, so I'd rather err on the side of caution until = I hear of some more interest in this feature. >=20 > Regards, > -Ethan >=20 > > > > Tyler > > > >> > >> Signed-off-by: Ethan.Du > >> --- > >> =A0fs/ecryptfs/ecryptfs_kernel.h | =A0 =A01 + > >> =A0fs/ecryptfs/inode.c =A0 =A0 =A0 =A0 =A0 | =A0 =A08 ++++++++ > >> =A0fs/ecryptfs/main.c =A0 =A0 =A0 =A0 =A0 =A0| =A0 =A05 +++++ > >> =A0fs/ecryptfs/mmap.c =A0 =A0 =A0 =A0 =A0 =A0| =A0 33 ++++++++++++= +++++++++++++-------- > >> =A0fs/ecryptfs/super.c =A0 =A0 =A0 =A0 =A0 | =A0 =A02 ++ > >> =A05 files changed, 41 insertions(+), 8 deletions(-) > >> > >> diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_= kernel.h > >> index e007534..4d0c5c4 100644 > >> --- a/fs/ecryptfs/ecryptfs_kernel.h > >> +++ b/fs/ecryptfs/ecryptfs_kernel.h > >> @@ -377,6 +377,7 @@ struct ecryptfs_mount_crypt_stat { > >> =A0#define ECRYPTFS_GLOBAL_ENCFN_USE_MOUNT_FNEK =A0 0x00000020 > >> =A0#define ECRYPTFS_GLOBAL_ENCFN_USE_FEK =A0 =A0 =A0 =A0 =A00x0000= 0040 > >> =A0#define ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY =A0 =A00x00000080 > >> +#define ECRYPTFS_CREATE_PLAIN_FILE =A0 =A0 =A0 =A0 =A0 =A0 0x0000= 0100 > >> =A0 =A0 =A0 =A0u32 flags; > >> =A0 =A0 =A0 =A0struct list_head global_auth_tok_list; > >> =A0 =A0 =A0 =A0struct mutex global_auth_tok_list_mutex; > >> diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c > >> index b592938..a6ffe89 100644 > >> --- a/fs/ecryptfs/inode.c > >> +++ b/fs/ecryptfs/inode.c > >> @@ -174,6 +174,9 @@ static int ecryptfs_initialize_file(struct den= try > >> *ecryptfs_dentry) > >> =A0{ > >> =A0 =A0 =A0 =A0struct ecryptfs_crypt_stat *crypt_stat =3D > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&ecryptfs_inode_to_private(ecryptfs= _dentry->d_inode)->crypt_stat; > >> + =A0 =A0 =A0 struct ecryptfs_mount_crypt_stat *mount_crypt_stat =3D > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 &ecryptfs_superblock_to_private(ecry= ptfs_dentry->d_sb)-> > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mount_crypt_stat; > >> =A0 =A0 =A0 =A0int rc =3D 0; > >> > >> =A0 =A0 =A0 =A0if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { > >> @@ -182,6 +185,11 @@ static int ecryptfs_initialize_file(struct de= ntry > >> *ecryptfs_dentry) > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto out; > >> =A0 =A0 =A0 =A0} > >> =A0 =A0 =A0 =A0crypt_stat->flags |=3D ECRYPTFS_NEW_FILE; > >> + =A0 =A0 =A0 if (mount_crypt_stat && (mount_crypt_stat->flags > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 & ECRYPTFS_CREATE_PL= AIN_FILE)) { > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 crypt_stat->flags &=3D ~(ECRYPTFS_EN= CRYPTED); > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out; > >> + =A0 =A0 =A0 } > >> =A0 =A0 =A0 =A0ecryptfs_printk(KERN_DEBUG, "Initializing crypto co= ntext\n"); > >> =A0 =A0 =A0 =A0rc =3D ecryptfs_new_file_context(ecryptfs_dentry); > >> =A0 =A0 =A0 =A0if (rc) { > >> diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c > >> index 758323a..ee4e286 100644 > >> --- a/fs/ecryptfs/main.c > >> +++ b/fs/ecryptfs/main.c > >> @@ -218,6 +218,7 @@ enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs= _sig, > >> =A0 =A0 =A0 =A0ecryptfs_opt_encrypted_view, ecryptfs_opt_fnek_sig, > >> =A0 =A0 =A0 =A0ecryptfs_opt_fn_cipher, ecryptfs_opt_fn_cipher_key_= bytes, > >> =A0 =A0 =A0 =A0ecryptfs_opt_unlink_sigs, ecryptfs_opt_mount_auth_t= ok_only, > >> + =A0 =A0 =A0 ecryptfs_opt_create_plain, > >> =A0 =A0 =A0 =A0ecryptfs_opt_err }; > >> > >> =A0static const match_table_t tokens =3D { > >> @@ -234,6 +235,7 @@ static const match_table_t tokens =3D { > >> =A0 =A0 =A0 =A0{ecryptfs_opt_fn_cipher_key_bytes, "ecryptfs_fn_key= _bytes=3D%u"}, > >> =A0 =A0 =A0 =A0{ecryptfs_opt_unlink_sigs, "ecryptfs_unlink_sigs"}, > >> =A0 =A0 =A0 =A0{ecryptfs_opt_mount_auth_tok_only, "ecryptfs_mount_= auth_tok_only"}, > >> + =A0 =A0 =A0 {ecryptfs_opt_create_plain, "ecryptfs_create_plain"}= , > >> =A0 =A0 =A0 =A0{ecryptfs_opt_err, NULL} > >> =A0}; > >> > >> @@ -421,6 +423,9 @@ static int ecryptfs_parse_options(struct > >> ecryptfs_sb_info *sbi, char *options) > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0mount_crypt_stat->f= lags |=3D > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ECR= YPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY; > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 case ecryptfs_opt_create_plain: > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mount_crypt_stat->fl= ags |=3D ECRYPTFS_CREATE_PLAIN_FILE; > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0case ecryptfs_opt_err: > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0default: > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk(KERN_WARNING > >> diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c > >> index cc64fca..6c5786b 100644 > >> --- a/fs/ecryptfs/mmap.c > >> +++ b/fs/ecryptfs/mmap.c > >> @@ -60,18 +60,35 @@ struct page *ecryptfs_get_locked_page(struct i= node > >> *inode, loff_t index) > >> =A0*/ > >> =A0static int ecryptfs_writepage(struct page *page, struct writeba= ck_control *wbc) > >> =A0{ > >> - =A0 =A0 =A0 int rc; > >> + =A0 =A0 =A0 struct inode *ecryptfs_inode; > >> + =A0 =A0 =A0 struct ecryptfs_crypt_stat *crypt_stat; > >> + =A0 =A0 =A0 int rc =3D 0; > >> > >> - =A0 =A0 =A0 rc =3D ecryptfs_encrypt_page(page); > >> - =A0 =A0 =A0 if (rc) { > >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 ecryptfs_printk(KERN_WARNING, "Error= encrypting " > >> + =A0 =A0 =A0 ecryptfs_inode =3D page->mapping->host; > >> + =A0 =A0 =A0 crypt_stat =3D > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 &(ecryptfs_inode_to_private(ecryptfs= _inode)->crypt_stat); > >> + > >> + =A0 =A0 =A0 if (!crypt_stat > >> + =A0 =A0 =A0 =A0 =A0 || !(crypt_stat->flags & ECRYPTFS_ENCRYPTED) > >> + =A0 =A0 =A0 =A0 =A0 || (crypt_stat->flags & ECRYPTFS_NEW_FILE)) = { > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ecryptfs_printk(KERN_DEBUG, > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "Passing through une= ncrypted page\n"); > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rc =3D ecryptfs_write_lower_page_seg= ment(ecryptfs_inode, page, > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 0, PAGE_CACHE_SIZE); > >> + =A0 =A0 =A0 } else { > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rc =3D ecryptfs_encrypt_page(page); > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (rc) > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ecryptfs_printk(KERN= _ERR, "Error encrypting " > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"pa= ge (upper index [0x%.16lx])\n", page->index); > >> + =A0 =A0 =A0 } > >> + > >> + =A0 =A0 =A0 if (rc) > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ClearPageUptodate(page); > >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out; > >> + =A0 =A0 =A0 else { > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 SetPageUptodate(page); > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 unlock_page(page); > >> =A0 =A0 =A0 =A0} > >> - =A0 =A0 =A0 SetPageUptodate(page); > >> - =A0 =A0 =A0 unlock_page(page); > >> -out: > >> + > >> =A0 =A0 =A0 =A0return rc; > >> =A0} > >> > >> diff --git a/fs/ecryptfs/super.c b/fs/ecryptfs/super.c > >> index 3042fe1..dd19570 100644 > >> --- a/fs/ecryptfs/super.c > >> +++ b/fs/ecryptfs/super.c > >> @@ -191,6 +191,8 @@ static int ecryptfs_show_options(struct seq_fi= le > >> *m, struct vfsmount *mnt) > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0seq_printf(m, ",ecryptfs_unlink_sig= s"); > >> =A0 =A0 =A0 =A0if (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_MOUNT= _AUTH_TOK_ONLY) > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0seq_printf(m, ",ecryptfs_mount_auth= _tok_only"); > >> + =A0 =A0 =A0 if (mount_crypt_stat->flags & ECRYPTFS_CREATE_PLAIN_= =46ILE) > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 seq_printf(m, ",ecryptfs_create_plai= n"); > >> > >> =A0 =A0 =A0 =A0return 0; > >> =A0} > >> -- > >> 1.7.2.3 > >> -- > >> To unsubscribe from this list: send the line "unsubscribe linux-fs= devel" in > >> the body of a message to majordomo@vger.kernel.org > >> More majordomo info at =A0http://vger.kernel.org/majordomo-info.ht= ml > > -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel= " in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html