Messages in this thread Patch in this message | | | Date | Wed, 27 Jun 2012 21:05:10 +0200 | From | Oleg Nesterov <> | Subject | Re: [PATCH 4/4] task_work: kill task_work->data |
| |
On 06/27, Oleg Nesterov wrote: > > Turn cred->rcu into rcu_head/task_work union for keyctl_session_to_parent().
I tried to make the minimal patch, but perhaps with this change we can also simplify the error handling in keyctl_session_to_parent() a little bit.
We can do cred_alloc_blank() before lookup_user_key() and remove error_keyring/key_ref_put.
IOW, on top of this patch:
--- x/security/keys/keyctl.c +++ x/security/keys/keyctl.c @@ -1461,17 +1461,18 @@ long keyctl_session_to_parent(void) struct cred *cred; int ret; - keyring_r = lookup_user_key(KEY_SPEC_SESSION_KEYRING, 0, KEY_LINK); - if (IS_ERR(keyring_r)) - return PTR_ERR(keyring_r); - /* our parent is going to need a new cred struct, a new tgcred struct * and new security data, so we allocate them here to prevent ENOMEM in * our parent */ - ret = -ENOMEM; cred = cred_alloc_blank(); if (!cred) - goto error_keyring; + return -ENOMEM; + + keyring_r = lookup_user_key(KEY_SPEC_SESSION_KEYRING, 0, KEY_LINK); + if (IS_ERR(keyring_r)) { + ret = PTR_ERR(keyring_r); + goto free_cred; + } cred->tgcred->session_keyring = key_ref_to_ptr(keyring_r); init_task_work(&cred->twork, key_change_session_keyring); @@ -1532,13 +1533,10 @@ unlock: if (oldwork) put_cred(container_of(oldwork, struct cred, twork)); +free_cred: if (cred) put_cred(cred); return ret; - -error_keyring: - key_ref_put(keyring_r); - return ret; } /*
| |