linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Dan Williams <dan.j.williams@gmail.com>
Cc: Randy Dunlap <rdunlap@infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	linux-f2fs-devel@lists.sourceforge.net,
	Theodore Ts'o <tytso@mit.edu>
Subject: Re: [PATCH 01/10] fs crypto: add basic definitions for per-file encryption
Date: Fri, 11 Mar 2016 10:50:20 -0800	[thread overview]
Message-ID: <20160311185020.GA62857@jaegeuk.gateway> (raw)
In-Reply-To: <CAA9_cmfCU1piC9wQr0z=z7gHEmOOEiZu595JOJHod2Y1EgDw8Q@mail.gmail.com>

Hi Dan,

On Thu, Mar 10, 2016 at 09:00:25PM -0800, Dan Williams wrote:
> On Mon, Feb 29, 2016 at 5:35 PM, Jaegeuk Kim <jaegeuk@kernel.org> wrote:
> > On Sun, Feb 28, 2016 at 09:41:22PM -0800, Randy Dunlap wrote:
> >> On 02/25/16 11:25, Jaegeuk Kim wrote:
> >> > This patch adds definitions for per-file encryption used by ext4 and f2fs.
> >> >
> >> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> >> > ---
> >> >  include/linux/fs.h       |   8 ++
> >> >  include/linux/fscrypto.h | 239 +++++++++++++++++++++++++++++++++++++++++++++++
> >> >  include/uapi/linux/fs.h  |  18 ++++
> >> >  3 files changed, 265 insertions(+)
> >> >  create mode 100644 include/linux/fscrypto.h
> >> >
> >> > diff --git a/include/linux/fs.h b/include/linux/fs.h
> >> > index ae68100..d8f57cf 100644
> >> > --- a/include/linux/fs.h
> >> > +++ b/include/linux/fs.h
> >> > @@ -53,6 +53,8 @@ struct swap_info_struct;
> >> >  struct seq_file;
> >> >  struct workqueue_struct;
> >> >  struct iov_iter;
> >> > +struct fscrypt_info;
> >> > +struct fscrypt_operations;
> >> >
> >> >  extern void __init inode_init(void);
> >> >  extern void __init inode_init_early(void);
> >> > @@ -678,6 +680,10 @@ struct inode {
> >> >     struct hlist_head       i_fsnotify_marks;
> >> >  #endif
> >> >
> >> > +#ifdef CONFIG_FS_ENCRYPTION
> >> > +   struct fscrypt_info     *i_crypt_info;
> >> > +#endif
> >> > +
> >> >     void                    *i_private; /* fs or device private pointer */
> >> >  };
> >> >
> >> > @@ -1323,6 +1329,8 @@ struct super_block {
> >> >  #endif
> >> >     const struct xattr_handler **s_xattr;
> >> >
> >> > +   const struct fscrypt_operations *s_cop;
> >> > +
> >> >     struct hlist_bl_head    s_anon;         /* anonymous dentries for (nfs) exporting */
> >> >     struct list_head        s_mounts;       /* list of mounts; _not_ for fs use */
> >> >     struct block_device     *s_bdev;
> >> > diff --git a/include/linux/fscrypto.h b/include/linux/fscrypto.h
> >> > new file mode 100644
> >> > index 0000000..b0aed92
> >> > --- /dev/null
> >> > +++ b/include/linux/fscrypto.h
> >> > @@ -0,0 +1,239 @@
> >> > +/*
> >> > + * General per-file encryption definition
> >> > + *
> >> > + * Copyright (C) 2015, Google, Inc.
> >> > + *
> >> > + * Written by Michael Halcrow, 2015.
> >> > + * Modified by Jaegeuk Kim, 2015.
> >> > + */
> >> > +
> >> > +#ifndef _LINUX_FSCRYPTO_H
> >> > +#define _LINUX_FSCRYPTO_H
> >> > +
> >> > +#include <linux/key.h>
> >> > +#include <linux/fs.h>
> >> > +#include <linux/mm.h>
> >> > +#include <linux/bio.h>
> >> > +#include <linux/dcache.h>
> >> > +#include <uapi/linux/fs.h>
> >> > +
> >> > +#define FS_KEY_DERIVATION_NONCE_SIZE               16
> >> > +#define FS_ENCRYPTION_CONTEXT_FORMAT_V1            1
> >> > +
> >> > +#define FS_POLICY_FLAGS_PAD_4              0x00
> >> > +#define FS_POLICY_FLAGS_PAD_8              0x01
> >> > +#define FS_POLICY_FLAGS_PAD_16             0x02
> >> > +#define FS_POLICY_FLAGS_PAD_32             0x03
> >> > +#define FS_POLICY_FLAGS_PAD_MASK   0x03
> >> > +#define FS_POLICY_FLAGS_VALID              0x03
> >> > +
> >> > +/* Encryption algorithms */
> >> > +#define FS_ENCRYPTION_MODE_INVALID         0
> >> > +#define FS_ENCRYPTION_MODE_AES_256_XTS             1
> >> > +#define FS_ENCRYPTION_MODE_AES_256_GCM             2
> >> > +#define FS_ENCRYPTION_MODE_AES_256_CBC             3
> >> > +#define FS_ENCRYPTION_MODE_AES_256_CTS             4
> >> > +
> >> > +/**
> >> > + * Encryption context for inode
> >> > + *
> >> > + * Protector format:
> >> > + *  1 byte: Protector format (1 = this version)
> >> > + *  1 byte: File contents encryption mode
> >> > + *  1 byte: File names encryption mode
> >> > + *  1 byte: Flags
> >> > + *  8 bytes: Master Key descriptor
> >> > + *  16 bytes: Encryption Key derivation nonce
> >> > + */
> >> > +struct fscrypt_context {
> >> > +   char format;
> >> > +   char contents_encryption_mode;
> >> > +   char filenames_encryption_mode;
> >> > +   char flags;
> >> > +   char master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
> >> > +   char nonce[FS_KEY_DERIVATION_NONCE_SIZE];
> >>
> >> how about u8 instead of char?
> >
> > It seems that it needs to user u8 instead of char for other variables as well.
> > I'll take a look at all the usages.
> 
> I think it needs to be __u8 otherwise I get this in a userspace program:
> 
> In file included from test/blk_namespaces.c:17:0:
> /usr/include/linux/fs.h:256:2: error: unknown type name ‘u8’
>   u8 version;
>   ^
> /usr/include/linux/fs.h:257:2: error: unknown type name ‘u8’
>   u8 contents_encryption_mode;
>   ^
> /usr/include/linux/fs.h:258:2: error: unknown type name ‘u8’
>   u8 filenames_encryption_mode;
>   ^
> /usr/include/linux/fs.h:259:2: error: unknown type name ‘u8’
>   u8 flags;
>   ^
> /usr/include/linux/fs.h:260:2: error: unknown type name ‘u8’
>   u8 master_key_descriptor[FS_KEY_DESCRIPTOR_SIZE];
>   ^

I realized that it needs to use __u8 as an exportable data type which can be
seen by user-space programs.

So, IMO, only fscrypt_policy should be exportable, and other structures need
to use u8.

Let me know, if I'm missing something.

Thanks,
--
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

  reply	other threads:[~2016-03-11 18:50 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-25 19:25 [PATCH 00/10 v2] File-level Encryption Support by VFS Jaegeuk Kim
2016-02-25 19:25 ` [PATCH 01/10] fs crypto: add basic definitions for per-file encryption Jaegeuk Kim
2016-02-29  5:41   ` Randy Dunlap
2016-03-01  1:35     ` Jaegeuk Kim
2016-03-11  5:00       ` Dan Williams
2016-03-11 18:50         ` Jaegeuk Kim [this message]
2016-02-25 19:26 ` [PATCH 02/10] fs crypto: add crypto.c for encrypt/decrypt functions Jaegeuk Kim
2016-02-25 19:26 ` [PATCH 03/10] fs crypto: add policy.c to handle contexts Jaegeuk Kim
2016-02-25 19:26 ` [PATCH 04/10] fs crypto: add keyinfo.c to handle permissions Jaegeuk Kim
2016-02-25 19:26 ` [PATCH 05/10] fs crypto: add fname.c to support filename encryption Jaegeuk Kim
2016-02-25 19:26 ` [PATCH 06/10] fs crypto: add Makefile and Kconfig Jaegeuk Kim
2016-02-29  5:39   ` Randy Dunlap
2016-03-01  2:04     ` Jaegeuk Kim
2016-03-01 18:30       ` Randy Dunlap
2016-02-25 19:26 ` [PATCH 07/10] fs crypto: add dentry revalidation facility in crypto Jaegeuk Kim
2016-02-25 19:26 ` [PATCH 08/10] f2fs crypto: migrate into vfs's crypto engine Jaegeuk Kim
2016-02-25 19:26 ` [PATCH 09/10] f2fs crypto: sync ext4_lookup and ext4_file_open Jaegeuk Kim
2016-02-25 19:26 ` [PATCH 10/10] ext4 crypto: migrate into vfs's crypto engine Jaegeuk Kim
  -- strict thread matches above, loose matches on Subject: below --
2016-03-02 18:31 [PATCH v3 00/10] File-level Encryption Support by VFS Jaegeuk Kim
2016-03-02 18:31 ` [PATCH 01/10] fs crypto: add basic definitions for per-file encryption Jaegeuk Kim

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=20160311185020.GA62857@jaegeuk.gateway \
    --to=jaegeuk@kernel.org \
    --cc=dan.j.williams@gmail.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=tytso@mit.edu \
    /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;
as well as URLs for NNTP newsgroup(s).