mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tyler Hicks <code@tyhicks.com>
To: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
Cc: ecryptfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+dc50906b100ac7a1c34d@syzkaller.appspotmail.com,
	stable@vger.kernel.org
Subject: Re: [PATCH] ecryptfs: validate key payload size before using it as an auth_tok
Date: Tue, 13 Oct 2026 00:51:15 -0500	[thread overview]
Message-ID: <as3G00lXXQnXaMmj@elm> (raw)
In-Reply-To: <20261011061902.144716-1-ngocthang2710.1999@gmail.com>

On 2026-10-11 13:19:01, Nguyen Ngoc Thang wrote:
> ecryptfs_get_key_payload_data() casts the payload of a "user" or
> "encrypted" key straight to struct ecryptfs_auth_tok. The payload size is
> chosen by whoever added the key, so a payload shorter than the struct
> makes later accesses run past the allocation. For example, a 712-byte
> "user" key makes write_tag_3_packet() read the password signature beyond
> the end of the kmalloc-1k object:
> 
>   BUG: KASAN: slab-out-of-bounds in ecryptfs_from_hex+0x18c/0x1d0
>   Read of size 1
>    write_tag_3_packet+0x145/0x1430
>    ecryptfs_generate_key_packet_set+0x7ae/0x1880
>    ecryptfs_write_metadata+0x590/0x930
>    ecryptfs_create+0x393/0x550
> 
> Reject payloads smaller than struct ecryptfs_auth_tok with -EINVAL. The
> callers already propagate errors from this helper, so mounting with such
> a key now fails cleanly.
> 
> Reported-by: syzbot+dc50906b100ac7a1c34d@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=dc50906b100ac7a1c34d
> Fixes: 237fead61998 ("[PATCH] ecryptfs: fs/Makefile and fs/Kconfig")
> Cc: stable@vger.kernel.org
> Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>

Hello and thanks for the patch! I've already taken the user key payload
fix from another contributor and will take the session key encryption
key check from a separate contributor. You can find the links here:

 * https://lore.kernel.org/ecryptfs/20260917044558.41677-1-neganhat@gmail.com/
 * https://lore.kernel.org/ecryptfs/20261004123755.14642-1-adrianox@gmail.com/

> ---
> Notes (not for the commit log):
> syzbot reports "KASAN: slab-out-of-bounds Read in ecryptfs_from_hex". The
> reproducer adds a 712-byte "user" key whose description matches
> ecryptfs_sig=; the mount succeeds and the first create makes
> write_tag_3_packet() read the signature past the end of the kmalloc-1k
> object. Tested in QEMU with syzbot's KASAN config: base kernel hits the
> KASAN report, patched kernel fails the mount with -EINVAL. Fixes points at
> the initial ecryptfs commit since the history here is grafted; happy to
> retarget.
> 
>  fs/ecryptfs/ecryptfs_kernel.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
> index 58165928ed1e..863761b3847a 100644
> --- a/fs/ecryptfs/ecryptfs_kernel.h
> +++ b/fs/ecryptfs/ecryptfs_kernel.h
> @@ -88,6 +88,9 @@ ecryptfs_get_encrypted_key_payload_data(struct key *key)
>  	if (!payload)
>  		return ERR_PTR(-EKEYREVOKED);
>  
> +	if (payload->decrypted_datalen < sizeof(struct ecryptfs_auth_tok))
> +		return ERR_PTR(-EINVAL);

I think Adriano's check on payload_datalen is more accurate. I believe
your check would block legitimate encrypted-keys.

Tyler

> +
>  	return (struct ecryptfs_auth_tok *)payload->payload_data;
>  }
>  
> @@ -124,6 +127,9 @@ ecryptfs_get_key_payload_data(struct key *key)
>  	if (!ukp)
>  		return ERR_PTR(-EKEYREVOKED);
>  
> +	if (ukp->datalen < sizeof(struct ecryptfs_auth_tok))
> +		return ERR_PTR(-EINVAL);
> +
>  	return (struct ecryptfs_auth_tok *)ukp->data;
>  }
>  
> -- 
> 2.43.0
> 

      reply	other threads:[~2026-10-13  5:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-11  6:19 Nguyen Ngoc Thang
2026-10-13  5:51 ` Tyler Hicks [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=as3G00lXXQnXaMmj@elm \
    --to=code@tyhicks.com \
    --cc=ecryptfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ngocthang2710.1999@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+dc50906b100ac7a1c34d@syzkaller.appspotmail.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®