All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers3@gmail.com>
To: David Howells <dhowells@redhat.com>
Cc: keyrings@vger.kernel.org, linux-kernel@vger.kernel.org,
	Eric Biggers <ebiggers@google.com>
Subject: Re: [PATCH] KEYS: put keyring if install_session_keyring_to_cred() fails
Date: Mon, 3 Apr 2017 10:48:57 -0700	[thread overview]
Message-ID: <20170403174857.GA72831@gmail.com> (raw)
In-Reply-To: <2347.1491234125@warthog.procyon.org.uk>

Hi David,

On Mon, Apr 03, 2017 at 04:42:05PM +0100, David Howells wrote:
> Eric Biggers <ebiggers3@gmail.com> wrote:
> 
> > +error3:
> > +	key_put(keyring);
> >  error2:
> >  	mutex_unlock(&key_session_mutex);
> 
> I would prefer the put to be outside of the locked section.  How about the
> attached instead?

[...]

> diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
> index 44451af828c0..8e98e5d1b5fb 100644
> --- a/security/keys/process_keys.c
> +++ b/security/keys/process_keys.c
> @@ -793,21 +793,20 @@ long join_session_keyring(const char *name)
>  			KEY_ALLOC_IN_QUOTA, NULL, NULL);
>  		if (IS_ERR(keyring)) {
>  			ret = PTR_ERR(keyring);
> -			goto error2;
> +			goto error_unlock_no_keyring;
>  		}
>  	} else if (IS_ERR(keyring)) {
>  		ret = PTR_ERR(keyring);
> -		goto error2;
> +		goto error_unlock_no_keyring;
>  	} else if (keyring == new->session_keyring) {
> -		key_put(keyring);
>  		ret = 0;
> -		goto error2;
> +		goto error_unlock;
>  	}
>  
>  	/* we've got a keyring - now to install it */
>  	ret = install_session_keyring_to_cred(new, keyring);
>  	if (ret < 0)
> -		goto error2;
> +		goto error_unlock;
>  
>  	commit_creds(new);
>  	mutex_unlock(&key_session_mutex);
> @@ -817,8 +816,11 @@ long join_session_keyring(const char *name)
>  okay:
>  	return ret;
>  
> -error2:
> +error_unlock_no_keyring:
> +	keyring = NULL;
> +error_unlock:
>  	mutex_unlock(&key_session_mutex);
> +	key_put(keyring);
>  error:
>  	abort_creds(new);
>  	return ret;

I guess I'm okay with either patch, but I think jumping to the error labels in
the way I proposed is more straightforward since it keeps things in the logical
order.  And I doubt there's much advantage in moving key_put() outside of the
mutex, given that key_session_mutex is only used for joining session keyrings so
shouldn't be contended, and key_put() hardly does any work anyway.

- Eric

      reply	other threads:[~2017-04-03 17:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-01 18:54 [PATCH] KEYS: put keyring if install_session_keyring_to_cred() fails Eric Biggers
2017-04-03 15:42 ` David Howells
2017-04-03 17:48   ` Eric Biggers [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=20170403174857.GA72831@gmail.com \
    --to=ebiggers3@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=ebiggers@google.com \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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.