public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: "Michael A. Halcrow" <mhalcrow@us.ibm.com>,
	Ingo Molnar <mingo@elte.hu>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] eCryptFS: fix missed mutex_unlock
Date: Tue, 20 May 2008 00:28:32 -0700	[thread overview]
Message-ID: <20080520002832.89e74522.akpm@linux-foundation.org> (raw)
In-Reply-To: <20080518142611.GA18000@cvg>

On Sun, 18 May 2008 18:26:11 +0400 Cyrill Gorcunov <gorcunov@gmail.com> wrote:

> ---
> 
> Ingo, could you please apply it and test? Actually I really doubt if it help
> with the locking problem you pointed. There are two procedures
> in miscrev.c - ecryptfs_miscdev_poll() and ecryptfs_miscdev_read()
> which takes/releases mutexes in a bit strange way... investigating,
> but this patch is needed anyway.
> 
> Index: linux-2.6.git/fs/ecryptfs/crypto.c
> ===================================================================
> --- linux-2.6.git.orig/fs/ecryptfs/crypto.c	2008-05-18 16:44:20.000000000 +0400
> +++ linux-2.6.git/fs/ecryptfs/crypto.c	2008-05-18 17:56:12.000000000 +0400
> @@ -1903,6 +1903,7 @@ int ecryptfs_get_tfm_and_mutex_for_ciphe
>  		if (rc) {
>  			printk(KERN_ERR "Error adding new key_tfm to list; "
>  					"rc = [%d]\n", rc);
> +			mutex_unlock(&key_tfm_list_mutex);
>  			goto out;
>  		}
>  	}

Better to do it this way, I think:

--- a/fs/ecryptfs/crypto.c~ecryptfs-fix-missed-mutex_unlock
+++ a/fs/ecryptfs/crypto.c
@@ -1906,9 +1906,9 @@ int ecryptfs_get_tfm_and_mutex_for_ciphe
 			goto out;
 		}
 	}
-	mutex_unlock(&key_tfm_list_mutex);
 	(*tfm) = key_tfm->key_tfm;
 	(*tfm_mutex) = &key_tfm->key_tfm_mutex;
 out:
+	mutex_unlock(&key_tfm_list_mutex);
 	return rc;
 }
_

Holding the lock for an additional few instructions may not be strictly
needed, but we might avoid the reintroduction of such bugs?


  reply	other threads:[~2008-05-20  7:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-18 14:26 [PATCH] eCryptFS: fix missed mutex_unlock Cyrill Gorcunov
2008-05-20  7:28 ` Andrew Morton [this message]
2008-05-20  9:46   ` Cyrill Gorcunov
2008-05-21  8:02 ` Ingo Molnar
2008-05-21  9:33   ` Cyrill Gorcunov

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=20080520002832.89e74522.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=gorcunov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhalcrow@us.ibm.com \
    --cc=mingo@elte.hu \
    /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