28 Mar, 2011

3 commits

  • Unlock the page in error path of ecryptfs_write_begin(). This may
    happen, for example, if decryption fails while bring the page
    up-to-date.

    Cc:
    Signed-off-by: Tyler Hicks

    Tyler Hicks
     
  • Change the write path to encrypt the data only when the page is written to
    disk in ecryptfs_writepage. Previously, ecryptfs encrypts the page in
    ecryptfs_write_end which means that if there are multiple write requests to
    the same page, ecryptfs ends up re-encrypting that page over and over again.
    This patch minimizes the number of encryptions needed.

    Signed-off-by: Thieu Le
    [tyhicks: Changed NULL .drop_inode sop pointer to generic_drop_inode]
    Signed-off-by: Tyler Hicks

    Thieu Le
     
  • Now that grow_file() is not called in the ecryptfs_create() path, the
    ECRYPTFS_NEW_FILE flag is no longer needed. It helped
    ecryptfs_readpage() know not to decrypt zeroes that were read from the
    lower file in the grow_file() path.

    Signed-off-by: Tyler Hicks

    Tyler Hicks
     

18 Jan, 2011

2 commits


22 May, 2010

2 commits


20 Apr, 2010

1 commit

  • * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ecryptfs/ecryptfs-2.6:
    eCryptfs: Turn lower lookup error messages into debug messages
    eCryptfs: Copy lower directory inode times and size on link
    ecryptfs: fix use with tmpfs by removing d_drop from ecryptfs_destroy_inode
    ecryptfs: fix error code for missing xattrs in lower fs
    eCryptfs: Decrypt symlink target for stat size
    eCryptfs: Strip metadata in xattr flag in encrypted view
    eCryptfs: Clear buffer before reading in metadata xattr
    eCryptfs: Rename ecryptfs_crypt_stat.num_header_bytes_at_front
    eCryptfs: Fix metadata in xattr feature regression

    Linus Torvalds
     

30 Mar, 2010

1 commit

  • …it slab.h inclusion from percpu.h

    percpu.h is included by sched.h and module.h and thus ends up being
    included when building most .c files. percpu.h includes slab.h which
    in turn includes gfp.h making everything defined by the two files
    universally available and complicating inclusion dependencies.

    percpu.h -> slab.h dependency is about to be removed. Prepare for
    this change by updating users of gfp and slab facilities include those
    headers directly instead of assuming availability. As this conversion
    needs to touch large number of source files, the following script is
    used as the basis of conversion.

    http://userweb.kernel.org/~tj/misc/slabh-sweep.py

    The script does the followings.

    * Scan files for gfp and slab usages and update includes such that
    only the necessary includes are there. ie. if only gfp is used,
    gfp.h, if slab is used, slab.h.

    * When the script inserts a new include, it looks at the include
    blocks and try to put the new include such that its order conforms
    to its surrounding. It's put in the include block which contains
    core kernel includes, in the same order that the rest are ordered -
    alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
    doesn't seem to be any matching order.

    * If the script can't find a place to put a new include (mostly
    because the file doesn't have fitting include block), it prints out
    an error message indicating which .h file needs to be added to the
    file.

    The conversion was done in the following steps.

    1. The initial automatic conversion of all .c files updated slightly
    over 4000 files, deleting around 700 includes and adding ~480 gfp.h
    and ~3000 slab.h inclusions. The script emitted errors for ~400
    files.

    2. Each error was manually checked. Some didn't need the inclusion,
    some needed manual addition while adding it to implementation .h or
    embedding .c file was more appropriate for others. This step added
    inclusions to around 150 files.

    3. The script was run again and the output was compared to the edits
    from #2 to make sure no file was left behind.

    4. Several build tests were done and a couple of problems were fixed.
    e.g. lib/decompress_*.c used malloc/free() wrappers around slab
    APIs requiring slab.h to be added manually.

    5. The script was run on all .h files but without automatically
    editing them as sprinkling gfp.h and slab.h inclusions around .h
    files could easily lead to inclusion dependency hell. Most gfp.h
    inclusion directives were ignored as stuff from gfp.h was usually
    wildly available and often used in preprocessor macros. Each
    slab.h inclusion directive was examined and added manually as
    necessary.

    6. percpu.h was updated not to include slab.h.

    7. Build test were done on the following configurations and failures
    were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
    distributed build env didn't work with gcov compiles) and a few
    more options had to be turned off depending on archs to make things
    build (like ipr on powerpc/64 which failed due to missing writeq).

    * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
    * powerpc and powerpc64 SMP allmodconfig
    * sparc and sparc64 SMP allmodconfig
    * ia64 SMP allmodconfig
    * s390 SMP allmodconfig
    * alpha SMP allmodconfig
    * um on x86_64 SMP allmodconfig

    8. percpu.h modifications were reverted so that it could be applied as
    a separate patch and serve as bisection point.

    Given the fact that I had only a couple of failures from tests on step
    6, I'm fairly confident about the coverage of this conversion patch.
    If there is a breakage, it's likely to be something in one of the arch
    headers which should be easily discoverable easily on most builds of
    the specific arch.

    Signed-off-by: Tejun Heo <tj@kernel.org>
    Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>

    Tejun Heo
     

24 Mar, 2010

3 commits

  • The ecryptfs_encrypted_view mount option provides a unified way of
    viewing encrypted eCryptfs files. If the metadata is stored in a xattr,
    the metadata is moved to the file header when the file is read inside
    the eCryptfs mount. Because of this, we should strip the
    ECRYPTFS_METADATA_IN_XATTR flag from the header's flag section. This
    allows eCryptfs to treat the file as an eCryptfs file with a header
    at the front.

    Reviewed-by: Eric Sandeen
    Signed-off-by: Tyler Hicks

    Tyler Hicks
     
  • This patch renames the num_header_bytes_at_front variable to
    metadata_size since it now contains the max size of the metadata.

    Reviewed-by: Eric Sandeen
    Signed-off-by: Tyler Hicks

    Tyler Hicks
     
  • Fixes regression in 8faece5f906725c10e7a1f6caf84452abadbdc7b

    When using the ecryptfs_xattr_metadata mount option, eCryptfs stores the
    metadata (normally stored at the front of the file) in the user.ecryptfs
    xattr. This causes ecryptfs_crypt_stat.num_header_bytes_at_front to be
    0, since there is no header data at the front of the file. This results
    in too much memory being requested and ENOMEM being returned from
    ecryptfs_write_metadata().

    This patch fixes the problem by using the num_header_bytes_at_front
    variable for specifying the max size of the metadata, despite whether it
    is stored in the header or xattr.

    Reviewed-by: Eric Sandeen
    Signed-off-by: Tyler Hicks

    Tyler Hicks
     

23 Sep, 2009

1 commit

  • Errors returned from vfs_read() and vfs_write() calls to the lower
    filesystem were being masked as -EINVAL. This caused some confusion to
    users who saw EINVAL instead of ENOSPC when the disk was full, for
    instance.

    Also, the actual bytes read or written were not accessible by callers to
    ecryptfs_read_lower() and ecryptfs_write_lower(), which may be useful in
    some cases. This patch updates the error handling logic where those
    functions are called in order to accept positive return codes indicating
    success.

    Cc: Eric Sandeen
    Acked-by: Serge Hallyn
    Cc: ecryptfs-devel@lists.launchpad.net
    Signed-off-by: Tyler Hicks

    Tyler Hicks
     

22 Sep, 2009

1 commit


22 Apr, 2009

1 commit

  • ecryptfs_passthrough is a mount option that allows eCryptfs to allow
    data to be written to non-eCryptfs files in the lower filesystem. The
    passthrough option was causing data corruption due to it not always
    being treated as a non-eCryptfs file.

    The first 8 bytes of an eCryptfs file contains the decrypted file size.
    This value was being written to the non-eCryptfs files, too. Also,
    extra 0x00 characters were being written to make the file size a
    multiple of PAGE_CACHE_SIZE.

    Signed-off-by: Tyler Hicks

    Tyler Hicks
     

05 Jan, 2009

1 commit

  • With the write_begin/write_end aops, page_symlink was broken because it
    could no longer pass a GFP_NOFS type mask into the point where the
    allocations happened. They are done in write_begin, which would always
    assume that the filesystem can be entered from reclaim. This bug could
    cause filesystem deadlocks.

    The funny thing with having a gfp_t mask there is that it doesn't really
    allow the caller to arbitrarily tinker with the context in which it can be
    called. It couldn't ever be GFP_ATOMIC, for example, because it needs to
    take the page lock. The only thing any callers care about is __GFP_FS
    anyway, so turn that into a single flag.

    Add a new flag for write_begin, AOP_FLAG_NOFS. Filesystems can now act on
    this flag in their write_begin function. Change __grab_cache_page to
    accept a nofs argument as well, to honour that flag (while we're there,
    change the name to grab_cache_page_write_begin which is more instructive
    and does away with random leading underscores).

    This is really a more flexible way to go in the end anyway -- if a
    filesystem happens to want any extra allocations aside from the pagecache
    ones in ints write_begin function, it may now use GFP_KERNEL (rather than
    GFP_NOFS) for common case allocations (eg. ocfs2_alloc_write_ctxt, for a
    random example).

    [kosaki.motohiro@jp.fujitsu.com: fix ubifs]
    [kosaki.motohiro@jp.fujitsu.com: fix fuse]
    Signed-off-by: Nick Piggin
    Reviewed-by: KOSAKI Motohiro
    Cc: [2.6.28.x]
    Signed-off-by: KOSAKI Motohiro
    Signed-off-by: Andrew Morton
    [ Cleaned up the calling convention: just pass in the AOP flags
    untouched to the grab_cache_page_write_begin() function. That
    just simplifies everybody, and may even allow future expansion of the
    logic. - Linus ]
    Signed-off-by: Linus Torvalds

    Nick Piggin
     

17 Oct, 2008

1 commit


25 Jul, 2008

1 commit

  • Fixe sparse warnings:
    fs/ecryptfs/inode.c:368:15: warning: cast to restricted __be64
    fs/ecryptfs/mmap.c:385:12: warning: incorrect type in assignment (different base types)
    fs/ecryptfs/mmap.c:385:12: expected unsigned long long [unsigned] [assigned] [usertype] file_size
    fs/ecryptfs/mmap.c:385:12: got restricted __be64 [usertype]
    fs/ecryptfs/mmap.c:428:12: warning: incorrect type in assignment (different base types)
    fs/ecryptfs/mmap.c:428:12: expected unsigned long long [unsigned] [assigned] [usertype] file_size
    fs/ecryptfs/mmap.c:428:12: got restricted __be64 [usertype]

    Signed-off-by: Harvey Harrison
    Cc: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Harvey Harrison
     

29 Apr, 2008

1 commit


05 Mar, 2008

1 commit

  • When the page is not up to date, ecryptfs_prepare_write() should be
    acting much like ecryptfs_readpage(). This includes the painfully
    obvious step of actually decrypting the page contents read from the
    lower encrypted file.

    Note that this patch resolves a bug in eCryptfs in 2.6.24 that one can
    produce with these steps:

    # mount -t ecryptfs /secret /secret
    # echo "abc" > /secret/file.txt
    # umount /secret
    # mount -t ecryptfs /secret /secret
    # echo "def" >> /secret/file.txt
    # cat /secret/file.txt

    Without this patch, the resulting data returned from cat is likely to
    be something other than "abc\ndef\n".

    (Thanks to Benedikt Driessen for reporting this.)

    Signed-off-by: Michael Halcrow
    Cc: Benedikt Driessen
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     

07 Feb, 2008

2 commits

  • Remove internal references to header extents; just keep track of header bytes
    instead. Headers can easily span multiple pages with the recent persistent
    file changes.

    Signed-off-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     
  • - make the following needlessly global code static:
    - crypto.c:ecryptfs_lower_offset_for_extent()
    - crypto.c:key_tfm_list
    - crypto.c:key_tfm_list_mutex
    - inode.c:ecryptfs_getxattr()
    - main.c:ecryptfs_init_persistent_file()

    - remove the no longer used mmap.c:ecryptfs_lower_page_cache

    - #if 0 the unused read_write.c:ecryptfs_read()

    Signed-off-by: Adrian Bunk
    Cc: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Adrian Bunk
     

06 Feb, 2008

1 commit

  • Simplify page cache zeroing of segments of pages through 3 functions

    zero_user_segments(page, start1, end1, start2, end2)

    Zeros two segments of the page. It takes the position where to
    start and end the zeroing which avoids length calculations and
    makes code clearer.

    zero_user_segment(page, start, end)

    Same for a single segment.

    zero_user(page, start, length)

    Length variant for the case where we know the length.

    We remove the zero_user_page macro. Issues:

    1. Its a macro. Inline functions are preferable.

    2. The KM_USER0 macro is only defined for HIGHMEM.

    Having to treat this special case everywhere makes the
    code needlessly complex. The parameter for zeroing is always
    KM_USER0 except in one single case that we open code.

    Avoiding KM_USER0 makes a lot of code not having to be dealing
    with the special casing for HIGHMEM anymore. Dealing with
    kmap is only necessary for HIGHMEM configurations. In those
    configurations we use KM_USER0 like we do for a series of other
    functions defined in highmem.h.

    Since KM_USER0 is depends on HIGHMEM the existing zero_user_page
    function could not be a macro. zero_user_* functions introduced
    here can be be inline because that constant is not used when these
    functions are called.

    Also extract the flushing of the caches to be outside of the kmap.

    [akpm@linux-foundation.org: fix nfs and ntfs build]
    [akpm@linux-foundation.org: fix ntfs build some more]
    Signed-off-by: Christoph Lameter
    Cc: Steven French
    Cc: Michael Halcrow
    Cc:
    Cc: Steven Whitehouse
    Cc: Trond Myklebust
    Cc: "J. Bruce Fields"
    Cc: Anton Altaparmakov
    Cc: Mark Fasheh
    Cc: David Chinner
    Cc: Michael Halcrow
    Cc: Steven French
    Cc: Steven Whitehouse
    Cc: Trond Myklebust
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Christoph Lameter
     

18 Dec, 2007

1 commit

  • ecryptfs in 2.6.24-rc3 wasn't surviving fsx for me at all, dying after 4
    ops. Generally, encountering problems with stale data and improperly
    zeroed pages. An extending truncate + write for example would expose stale
    data.

    With the changes below I got to a million ops and beyond with all mmap ops
    disabled - mmap still needs work. (A version of this patch on a RHEL5
    kernel ran for over 110 million fsx ops)

    I added a few comments as well, to the best of my understanding
    as I read through the code.

    Signed-off-by: Eric Sandeen
    Acked-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eric Sandeen
     

17 Oct, 2007

10 commits

  • The functions that eventually call down to ecryptfs_read_lower(),
    ecryptfs_decrypt_page(), and ecryptfs_copy_up_encrypted_with_header()
    should have the responsibility of managing the page Uptodate
    status. This patch gets rid of some of the ugliness that resulted from
    trying to push some of the page flag setting too far down the stack.

    Signed-off-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     
  • The switch to read_write.c routines and the persistent file make a number of
    functions unnecessary. This patch removes them.

    Signed-off-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     
  • Update data types and add casts in order to avoid potential overflow
    issues.

    Signed-off-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     
  • Convert readpage, prepare_write, and commit_write to use read_write.c
    routines. Remove sync_page; I cannot think of a good reason for implementing
    that in eCryptfs.

    Signed-off-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     
  • Update the metadata read/write functions and grow_file() to use the
    read_write.c routines. Do not open another lower file; use the persistent
    lower file instead. Provide a separate function for
    crypto.c::ecryptfs_read_xattr_region() to get to the lower xattr without
    having to go through the eCryptfs getxattr.

    Signed-off-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     
  • Replace page encryption and decryption routines and inode size write routine
    with versions that utilize the read_write.c functions.

    Signed-off-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     
  • Add a set of functions through which all I/O to lower files is consolidated.
    This patch adds a new inode_info reference to a persistent lower file for each
    eCryptfs inode; another patch later in this series will set that up. This
    persistent lower file is what the read_write.c functions use to call
    vfs_read() and vfs_write() on the lower filesystem, so even when reads and
    writes come in through aops->readpage and aops->writepage, we can satisfy them
    without resorting to direct access to the lower inode's address space.
    Several function declarations are going to be changing with this patchset.
    For now, in order to keep from breaking the build, I am putting dummy
    parameters in for those functions.

    Signed-off-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     
  • Remove assignments in if-statements.

    Signed-off-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     
  • There is no point to keeping a separate header_extent_size and an extent_size.
    The total size of the header can always be represented as some multiple of
    the regular data extent size.

    [randy.dunlap@oracle.com: ecryptfs: fix printk format warning]
    Signed-off-by: Michael Halcrow
    Signed-off-by: Randy Dunlap
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     
  • prepare/commit_write no longer returns AOP_TRUNCATED_PAGE since OCFS2 and
    GFS2 were converted to the new aops, so we can make some simplifications
    for that.

    [michal.k.k.piotrowski@gmail.com: fix warning]
    Signed-off-by: Nick Piggin
    Cc: Michael Halcrow
    Cc: Mark Fasheh
    Cc: Steven Whitehouse
    Signed-off-by: Michal Piotrowski
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Nick Piggin
     

31 Aug, 2007

1 commit

  • This will avoid a possible fault in ecryptfs_sync_page().

    In the function, eCryptfs calls sync_page() method of a lower filesystem
    without checking its existence. However, there are many filesystems that
    don't have this method including network filesystems such as NFS, AFS, and
    so forth. They may fail when an eCryptfs page is waiting for lock.

    Signed-off-by: Ryusuke Konishi
    Acked-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ryusuke Konishi
     

20 Jul, 2007

1 commit

  • Fix page index to offset conversion overflows in buffer layer, ecryptfs,
    and ocfs2.

    It would be nice to convert the whole tree to page_offset, but for now
    just fix the bugs.

    Signed-off-by: Nick Piggin
    Cc: Michael Halcrow
    Cc: Mark Fasheh
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Nick Piggin
     

29 Jun, 2007

2 commits

  • When one llseek's past the end of the file and then writes, every page past
    the previous end of the file should be cleared. Trevor found that the code,
    as is, does not assure that the very last page is always cleared. This patch
    takes care of that.

    Signed-off-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     
  • This patch fixes the processes involved in wiping regions of the data during
    truncate and write events, fixing a kernel hang in 2.6.22-rc4 while assuring
    that zero values are written out to the appropriate locations during events in
    which the i_size will change.

    The range passed to ecryptfs_truncate() from ecryptfs_prepare_write() includes
    the page that is the object of ecryptfs_prepare_write(). This leads to a
    kernel hang as read_cache_page() is executed on the same page in the
    ecryptfs_truncate() execution path. This patch remedies this by limiting the
    range passed to ecryptfs_truncate() so as to exclude the page that is the
    object of ecryptfs_prepare_write(); it also adds code to
    ecryptfs_prepare_write() to zero out the region of its own page when writing
    past the i_size position. This patch also modifies ecryptfs_truncate() so
    that when a file is truncated to a smaller size, eCryptfs will zero out the
    contents of the new last page from the new size through to the end of the last
    page.

    Signed-off-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     

24 May, 2007

1 commit

  • Delay writing 0's out in eCryptfs after a seek past the end of the file
    until data is actually written.

    http://www.opengroup.org/onlinepubs/009695399/functions/lseek.html

    ``The lseek() function shall not, by itself, extend the size of a
    file.''

    Without this fix, applications that lseek() past the end of the file without
    writing will experience unexpected behavior.

    Signed-off-by: Michael Halcrow
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Halcrow
     

17 May, 2007

1 commit