From: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
To: Erez Zadok <ezk@cs.sunysb.edu>
Cc: Dustin Kirkland <kirkland@canonical.com>,
linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk,
Andrew Morton <akpm@linux-foundation.org>,
Duckjin Kang <fromdj2k@gmail.com>
Subject: Re: [PATCH] ecryptfs: initialize private persistent file before dereferencing pointer
Date: Fri, 04 Dec 2009 17:23:57 -0600 [thread overview]
Message-ID: <4B199A0D.5050807@linux.vnet.ibm.com> (raw)
In-Reply-To: <200912031835.nB3IZRD3002819@agora.fsl.cs.sunysb.edu>
On 12/03/2009 12:35 PM, Erez Zadok wrote:
> Tyler/Dustin,
>
> As promised, here's another patch for ecryptfs to fix a problem discovered
> by my student Duckjin Kang. I've not personally tested this patch, but it
> seems safe to me: it swaps the order of two "if" statements so you first
> initialize the lower private file, and then you do something that may oops
> dereferencing a NULL ptr. This patch is probably not that urgent to send
> out right away, b/c if this NULL ptr was dereferenced easily, you'd have
> found out about it more quickly. I think this bug might get triggered more
> easily under memory pressure: when an inode holding the lower file is purged
> to free up memory, while a concurrent open() takes place. Anyway, you may
> have a better fix for this.
>
> Cheers,
> Erez.
>
> ------------------------------------------------------------------------------
>
> Ecryptfs: initialize private persistent file before dereferencing pointer
>
> Ecryptfs_open dereferences a pointer to the private lower file (the one
> stored in the ecryptfs inode), without checking if the pointer is NULL.
> Right afterward, it initializes that pointer if it is NULL. Swap order of
> statements to first initialize. Bug discovered by Duckjin Kang.
>
> Signed-off-by: Duckjin Kang <fromdj2k@gmail.com>
> Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
Thanks for the fix!
Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/ecryptfs/ecryptfs-2.6.git#next
> diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
> index 9e94405..1744f17 100644
> --- a/fs/ecryptfs/file.c
> +++ b/fs/ecryptfs/file.c
> @@ -191,13 +191,6 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
> | ECRYPTFS_ENCRYPTED);
> }
> mutex_unlock(&crypt_stat->cs_mutex);
> - if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_RDONLY)
> - && !(file->f_flags & O_RDONLY)) {
> - rc = -EPERM;
> - printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs "
> - "file must hence be opened RO\n", __func__);
> - goto out;
> - }
> if (!ecryptfs_inode_to_private(inode)->lower_file) {
> rc = ecryptfs_init_persistent_file(ecryptfs_dentry);
> if (rc) {
> @@ -208,6 +201,13 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
> goto out;
> }
> }
> + if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_RDONLY)
> + && !(file->f_flags & O_RDONLY)) {
> + rc = -EPERM;
> + printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs "
> + "file must hence be opened RO\n", __func__);
> + goto out;
> + }
> ecryptfs_set_file_lower(
> file, ecryptfs_inode_to_private(inode)->lower_file);
> if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) {
prev parent reply other threads:[~2009-12-04 23:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-03 18:35 [PATCH] ecryptfs: initialize private persistent file before dereferencing pointer Erez Zadok
2009-12-04 23:23 ` Tyler Hicks [this message]
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=4B199A0D.5050807@linux.vnet.ibm.com \
--to=tyhicks@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=ezk@cs.sunysb.edu \
--cc=fromdj2k@gmail.com \
--cc=kirkland@canonical.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.