All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Philipp Stanner <pstanner@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Kefeng Wang <wangkefeng.wang@huawei.com>,
	Tony Luck <tony.luck@intel.com>, Ard Biesheuvel <ardb@kernel.org>,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	Dave Airlie <airlied@redhat.com>
Subject: Re: [PATCH] drivers/tty/vt: copy userspace arrays safely
Date: Thu, 2 Nov 2023 20:14:24 +0000	[thread overview]
Message-ID: <20231102201424.GL1957730@ZenIV> (raw)
In-Reply-To: <20231102192134.53301-2-pstanner@redhat.com>

On Thu, Nov 02, 2023 at 08:21:35PM +0100, Philipp Stanner wrote:
> The functions (v)memdup_user() are utilized to copy userspace arrays.
> This is done without overflow checks.
> 
> Use the new wrappers memdup_array_user() and vmemdup_array_user() to
> copy the arrays more safely.

> @@ -644,7 +644,7 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
>  	if (!ct)
>  		return 0;

> -	unilist = vmemdup_user(list, array_size(sizeof(*unilist), ct));
> +	unilist = vmemdup_array_user(list, ct, sizeof(*unilist));
>  	if (IS_ERR(unilist))
>  		return PTR_ERR(unilist);

a 16bit value times sizeof(something).
  
> diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
> index 1fe6107b539b..802ceb0a5e4c 100644
> --- a/drivers/tty/vt/keyboard.c
> +++ b/drivers/tty/vt/keyboard.c
> @@ -1773,8 +1773,8 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)

... and here we have
                if (ct >= MAX_DIACR)
			return -EINVAL;

directly upstream, so it's even better - a value below 256 times sizeof(something)

>  		if (ct) {
>  
> -			dia = memdup_user(a->kbdiacr,
> -					sizeof(struct kbdiacr) * ct);
> +			dia = memdup_array_user(a->kbdiacr,
> +						ct, sizeof(struct kbdiacr));
>  			if (IS_ERR(dia))
>  				return PTR_ERR(dia);
>  
> @@ -1811,8 +1811,8 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)
>  			return -EINVAL;

Ditto.

>  		if (ct) {
> -			buf = memdup_user(a->kbdiacruc,
> -					  ct * sizeof(struct kbdiacruc));
> +			buf = memdup_array_user(a->kbdiacruc,
> +						ct, sizeof(struct kbdiacruc));

  reply	other threads:[~2023-11-02 20:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-02 19:21 [PATCH] drivers/tty/vt: copy userspace arrays safely Philipp Stanner
2023-11-02 20:14 ` Al Viro [this message]
2023-11-02 20:24   ` David Airlie
2023-11-02 20:49     ` Al Viro
2023-11-02 22:07       ` Philipp Stanner

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=20231102201424.GL1957730@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=airlied@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=pstanner@redhat.com \
    --cc=tony.luck@intel.com \
    --cc=wangkefeng.wang@huawei.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 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.