mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: Junyoung Jang <graypanda.inzag@gmail.com>
Cc: "Marek Behún" <kabel@kernel.org>,
	"David Howells" <dhowells@redhat.com>,
	"Jarkko Sakkinen" <jarkko@kernel.org>,
	keyrings@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] platform: cznic: avoid slab-out-of-bounds write on short Turris key reads
Date: Thu, 12 Nov 2026 03:53:42 +0100	[thread overview]
Message-ID: <avUqKeNDFgeCx9Hi@solitude> (raw)
In-Reply-To: <20261109212632.2437881-1-graypanda.inzag@gmail.com>

Acked-by: Marek Behún <kabel@kernel.org>

On Tue, Nov 10, 2026 at 06:26:31AM +0900, Junyoung Jang wrote:
> For 0 < buflen <= PAGE_SIZE, keyctl_read_key() allocates a temporary
> kernel buffer of size buflen via kvmalloc() and passes it to the key
> type's .read() callback. Only after the callback returns does it check
> whether the returned required length exceeds buflen.
> 
> turris_signing_key_read() clamps buflen when it exceeds
> subtype->public_key_size, but ignores the clamped value and
> unconditionally passes subtype->public_key_size (33 or 67 bytes) to
> memcpy(). As a result, calling KEYCTL_READ with a smaller non-zero
> buffer (e.g., buflen=1) writes past the end of the temporary buffer,
> triggering a kernel heap slab-out-of-bounds write.
> 
> Per the key_type .read() contract, only copy the public key when the
> supplied buffer is large enough to hold it, and always return the
> required size.
> 
> Fixes: 0b28b7080ef5 ("platform: cznic: Add keyctl helpers for Turris platform")
> Signed-off-by: Junyoung Jang <graypanda.inzag@gmail.com>
> ---
>  drivers/platform/cznic/turris-signing-key.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/drivers/platform/cznic/turris-signing-key.c b/drivers/platform/cznic/turris-signing-key.c
> index 3827178565e2..af414e236de2 100644
> --- a/drivers/platform/cznic/turris-signing-key.c
> +++ b/drivers/platform/cznic/turris-signing-key.c
> @@ -46,12 +46,8 @@ static long turris_signing_key_read(const struct key *key, char *buffer, size_t
>  	if (!subtype)
>  		return -EIO;
>  
> -	if (buffer) {
> -		if (buflen > subtype->public_key_size)
> -			buflen = subtype->public_key_size;
> -
> +	if (buffer && buflen >= subtype->public_key_size)
>  		memcpy(buffer, subtype->get_public_key(key), subtype->public_key_size);
> -	}
>  
>  	return subtype->public_key_size;
>  }
> -- 
> 2.43.0

      reply	other threads:[~2026-11-12  2:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 21:26 Junyoung Jang
2026-11-12  2:53 ` Marek Behún [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=avUqKeNDFgeCx9Hi@solitude \
    --to=kabel@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=graypanda.inzag@gmail.com \
    --cc=jarkko@kernel.org \
    --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 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®