From: Jarkko Sakkinen <jarkko@kernel.org>
To: BeaCox <0xbeac@gmail.com>
Cc: David Howells <dhowells@redhat.com>,
Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
keyrings@vger.kernel.org, linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] KEYS: Protect pkey method checks against type removal
Date: Thu, 5 Nov 2026 01:59:19 +0200 [thread overview]
Message-ID: <auvG1wGifSsoCuaQ@kernel.org> (raw)
In-Reply-To: <20261104021414.50696-1-0xbeac@gmail.com>
Please respond to any questions *before* sending a follow-up patch by
properly using email client and quoting etc.
https://docs.kernel.org/process/email-clients.html
On Wed, Nov 04, 2026 at 10:14:14AM +0800, BeaCox wrote:
> @@ -129,7 +126,14 @@ static int keyctl_pkey_params_get_2(const struct keyctl_pkey_params __user *_par
> if (ret < 0)
> return ret;
>
> + down_read(¶ms->key->sem);
> + ret = -EOPNOTSUPP;
> + if (!params->key->type->asym_query) {
ret -EOPNOTSUPP;
> + goto out_unlock;
}
> +
> ret = params->key->type->asym_query(params, &info);
There should be an empty line prepending the label.
> +out_unlock:
> + up_read(¶ms->key->sem);
> if (ret < 0)
> return ret;
>
> @@ -185,15 +189,25 @@ long keyctl_pkey_query(key_serial_t id,
> if (ret < 0)
> goto error;
>
> + down_read(¶ms.key->sem);
> + ret = -EOPNOTSUPP;
> + if (!params.key->type->asym_query)
> + goto error_unlock;
Ditto.
> +
> ret = params.key->type->asym_query(¶ms, &res);
> if (ret < 0)
> - goto error;
> + goto error_unlock;
> +
> + up_read(¶ms.key->sem);
>
> ret = -EFAULT;
> if (copy_to_user(_res, &res, sizeof(res)) == 0 &&
> clear_user(_res->__spare, sizeof(_res->__spare)) == 0)
> ret = 0;
Why up_read is not here?
> + goto error;
> +error_unlock:
> + up_read(¶ms.key->sem);
> error:
> keyctl_pkey_params_free(¶ms);
> return ret;
> @@ -230,9 +244,21 @@ long keyctl_pkey_e_d_s(int op,
> if (ret < 0)
> goto error_params;
>
> + in = memdup_user(_in, params.in_len);
> + if (IS_ERR(in)) {
> + ret = PTR_ERR(in);
> + goto error_params;
> + }
> +
> + ret = -ENOMEM;
> + out = kmalloc(params.out_len, GFP_KERNEL);
> + if (!out)
> + goto error_in;
> +
> + down_read(¶ms.key->sem);
> ret = -EOPNOTSUPP;
> if (!params.key->type->asym_eds_op)
> - goto error_params;
> + goto error_unlock;
>
> switch (op) {
> case KEYCTL_PKEY_ENCRYPT:
> @@ -246,27 +272,18 @@ long keyctl_pkey_e_d_s(int op,
> break;
> default:
> ret = -EOPNOTSUPP;
> - goto error_params;
> + goto error_unlock;
> }
>
> - in = memdup_user(_in, params.in_len);
> - if (IS_ERR(in)) {
> - ret = PTR_ERR(in);
> - goto error_params;
> - }
> -
> - ret = -ENOMEM;
> - out = kmalloc(params.out_len, GFP_KERNEL);
> - if (!out)
> - goto error_in;
> -
> ret = params.key->type->asym_eds_op(¶ms, in, out);
> - if (ret < 0)
> - goto error_out;
> + up_read(¶ms.key->sem);
>
> - if (copy_to_user(_out, out, ret) != 0)
> + if (ret >= 0 && copy_to_user(_out, out, ret) != 0)
> ret = -EFAULT;
> + goto error_out;
Please figure this part out it does not do a great job minimizing the diff.
There were similar repeating issues that I did not specifically point
out.
Br, Jarkko
next prev parent reply other threads:[~2026-11-04 23:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 3:29 [PATCH] " BeaCox
2026-11-03 15:17 ` Jarkko Sakkinen
2026-11-04 2:14 ` [PATCH v2] " BeaCox
2026-11-04 14:49 ` Jarkko Sakkinen
2026-11-04 23:59 ` Jarkko Sakkinen [this message]
2026-11-05 2:24 ` Yuansheng Yang
2026-11-05 3:28 ` Jarkko Sakkinen
2026-11-05 4:38 ` [PATCH v3] " Yuansheng Yang
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=auvG1wGifSsoCuaQ@kernel.org \
--to=jarkko@kernel.org \
--cc=0xbeac@gmail.com \
--cc=dhowells@redhat.com \
--cc=jmorris@namei.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
/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
all inboxes | Powered by JetHome®