From: Eric Biggers <ebiggers3@gmail.com>
To: Theodore Ts'o <tytso@mit.edu>
Cc: stable@vger.kernel.org, linux-ext4@vger.kernel.org
Subject: Re: [FOR STABLE 4.1] ext4 crypto: don't regenerate the per-inode encryption key unnecessarily
Date: Sun, 8 Oct 2017 12:17:49 -0700 [thread overview]
Message-ID: <20171008191749.GA26458@zzz.localdomain> (raw)
In-Reply-To: <20171008180953.rpnxvpggqggc334m@thunk.org>
Hi Ted,
On Sun, Oct 08, 2017 at 02:09:53PM -0400, Theodore Ts'o wrote:
> diff --git a/fs/ext4/crypto_key.c b/fs/ext4/crypto_key.c
> index 52170d0b7c40..c8c3bf0286be 100644
> --- a/fs/ext4/crypto_key.c
> +++ b/fs/ext4/crypto_key.c
> @@ -99,9 +99,14 @@ int ext4_generate_encryption_key(struct inode *inode)
> struct ext4_encryption_context ctx;
> struct user_key_payload *ukp;
> struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
> - int res = ext4_xattr_get(inode, EXT4_XATTR_INDEX_ENCRYPTION,
> - EXT4_XATTR_NAME_ENCRYPTION_CONTEXT,
> - &ctx, sizeof(ctx));
> + int res;
> +
> + if (ext4_has_encryption_key(inode))
> + return 0;
> +
> + res = ext4_xattr_get(inode, EXT4_XATTR_INDEX_ENCRYPTION,
> + EXT4_XATTR_NAME_ENCRYPTION_CONTEXT,
> + &ctx, sizeof(ctx));
>
> if (res != sizeof(ctx)) {
> if (res > 0)
This is an improvement, but it's still broken because there is no locking. If
two processes ->open() the same inode at the same time, one can observe
ext4_has_encryption_key() as true before the key has been fully initialized. It
may be a good idea to add a really simple
DEFINE_MUTEX(ext4_key_generation_mutex), then do the ext4_has_encryption_key()
check and key generation under the mutex...
Eric
next prev parent reply other threads:[~2017-10-08 19:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-08 18:09 [FOR STABLE 4.1] ext4 crypto: don't regenerate the per-inode encryption key unnecessarily Theodore Ts'o
2017-10-08 19:17 ` Eric Biggers [this message]
2017-10-08 20:34 ` Theodore Ts'o
2017-10-08 21:52 ` Eric Biggers
2017-10-09 0:02 ` Theodore Ts'o
2017-10-08 21:55 ` [FOR STABLE 4.1 -v2] " Theodore Ts'o
2017-10-08 22:16 ` Eric Biggers
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=20171008191749.GA26458@zzz.localdomain \
--to=ebiggers3@gmail.com \
--cc=linux-ext4@vger.kernel.org \
--cc=stable@vger.kernel.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).