From: Tyler Hicks Subject: Re: [PATCH] eCryptfs: support creating plain files Date: Tue, 8 Mar 2011 17:21:57 -0600 Message-ID: <20110308232156.GD4828@boyd.l.tihix.com> References: <1298990647-2218-1-git-send-email-ethan.too@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: linux-fsdevel , ecryptfs-devel@lists.launchpad.net To: Ethan Du Return-path: Received: from e35.co.us.ibm.com ([32.97.110.153]:47642 "EHLO e35.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756546Ab1CHXWB (ORCPT ); Tue, 8 Mar 2011 18:22:01 -0500 Received: from d03relay05.boulder.ibm.com (d03relay05.boulder.ibm.com [9.17.195.107]) by e35.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id p28N71ar015996 for ; Tue, 8 Mar 2011 16:07:01 -0700 Received: from d03av05.boulder.ibm.com (d03av05.boulder.ibm.com [9.17.195.85]) by d03relay05.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p28NLx5i073558 for ; Tue, 8 Mar 2011 16:21:59 -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 p28NLwrT004293 for ; Tue, 8 Mar 2011 16:21:59 -0700 Content-Disposition: inline In-Reply-To: Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Wed Mar 02, 2011 at 11:09:25AM +0800, Ethan Du = wrote: > With ecryptfs_create_plain mount option, newly created file will be > plain lower fs file > For those who want to read encrypted files, but want no more encrypte= d files Hi Ethan - Lets get the process issues out of the way. The gmail web client seems to break patches. See Documentation/email-clients.txt for details. Also, it is a good idea to include the maintainers and project 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. =46or the patch itself, I'm not sure that this mount option would get u= sed by many people, yet would add to the eCryptfs test burden. How do you see this being used? I can't imagine many users wanting to disable encrypted file creation at a mount wide level. I see the usefulness of optionally creating plaintext files at a more granular level. It has always been a goal to create an eCryptfs encryption policy language that could define things like, "User tyhicks uses key with sig deadbeefdeadbeef and aes-128", or "Files with the svirt_image_t type get encrypted by key with sig feedbeeffeedbeef and aes-256", or "Files under ~/public receive no encryption". Another idea that popped up somewhat recently is to have per-mount read and write keyrings. A process can clear their keyrings if they wan= t 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. Tyler >=20 > 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(-) >=20 > diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_ker= nel.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 =A00x0000004= 0 > =A0#define ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY =A0 =A00x00000080 > +#define ECRYPTFS_CREATE_PLAIN_FILE =A0 =A0 =A0 =A0 =A0 =A0 0x0000010= 0 > =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 dentry > *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_de= ntry->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(ecryptf= s_dentry->d_sb)-> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mount_crypt_stat; > =A0 =A0 =A0 =A0int rc =3D 0; >=20 > =A0 =A0 =A0 =A0if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { > @@ -182,6 +185,11 @@ static int ecryptfs_initialize_file(struct dentr= y > *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_PLAIN= _FILE)) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 crypt_stat->flags &=3D ~(ECRYPTFS_ENCRY= PTED); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out; > + =A0 =A0 =A0 } > =A0 =A0 =A0 =A0ecryptfs_printk(KERN_DEBUG, "Initializing crypto conte= xt\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_si= g, > =A0 =A0 =A0 =A0ecryptfs_opt_encrypted_view, ecryptfs_opt_fnek_sig, > =A0 =A0 =A0 =A0ecryptfs_opt_fn_cipher, ecryptfs_opt_fn_cipher_key_byt= es, > =A0 =A0 =A0 =A0ecryptfs_opt_unlink_sigs, ecryptfs_opt_mount_auth_tok_= only, > + =A0 =A0 =A0 ecryptfs_opt_create_plain, > =A0 =A0 =A0 =A0ecryptfs_opt_err }; >=20 > =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_by= tes=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_aut= h_tok_only"}, > + =A0 =A0 =A0 {ecryptfs_opt_create_plain, "ecryptfs_create_plain"}, > =A0 =A0 =A0 =A0{ecryptfs_opt_err, NULL} > =A0}; >=20 > @@ -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->flag= s |=3D > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ECRYPT= =46S_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->flags= |=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 inod= e > *inode, loff_t index) > =A0*/ > =A0static int ecryptfs_writepage(struct page *page, struct writeback_= 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; >=20 > - =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 en= crypting " > + =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_in= ode)->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 unencr= ypted page\n"); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rc =3D ecryptfs_write_lower_page_segmen= t(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_ER= R, "Error encrypting " > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"page = (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} >=20 > 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_file > *m, struct vfsmount *mnt) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0seq_printf(m, ",ecryptfs_unlink_sigs")= ; > =A0 =A0 =A0 =A0if (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_MOUNT_AU= TH_TOK_ONLY) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0seq_printf(m, ",ecryptfs_mount_auth_to= k_only"); > + =A0 =A0 =A0 if (mount_crypt_stat->flags & ECRYPTFS_CREATE_PLAIN_FIL= E) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 seq_printf(m, ",ecryptfs_create_plain")= ; >=20 > =A0 =A0 =A0 =A0return 0; > =A0} > -- > 1.7.2.3 > -- > To unsubscribe from this list: send the line "unsubscribe linux-fsdev= el" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- 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