mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xianting TIan <xianting.tian@linux.alibaba.com>
To: amit@kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org
Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [RESEND][PATCH] virtio_console: protect max_nr_ports to avoid invalid value
Date: Mon, 23 Aug 2021 19:55:20 +0800	[thread overview]
Message-ID: <2746b7f2-2cd0-1042-3c36-b4392620525a@linux.alibaba.com> (raw)
In-Reply-To: <20210820075219.202404-1-xianting.tian@linux.alibaba.com>

Could I get comments for the patch? thanks

Is the value of  MAX_NR_PORTS accurate?

this fix is similar to below patches, which are megered recently,

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.14-rc7&id=63947b3434f475418b9677a393d025c0962c2cf8 
<https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.14-rc7&id=63947b3434f475418b9677a393d025c0962c2cf8>

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.14-rc7&id=82e89ea077b93b3c131fa175b0df3acb5b1d5cdf 
<https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.14-rc7&id=82e89ea077b93b3c131fa175b0df3acb5b1d5cdf>

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.14-rc7&id=d00d8da5869a2608e97cfede094dfc5e11462a46 
<https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.14-rc7&id=d00d8da5869a2608e97cfede094dfc5e11462a46>


在 2021/8/20 下午3:52, Xianting Tian 写道:
> In theory untrusted remote host can pass a big or overflow value
> of max_nr_ports to guest, it may cause guest system consumes
> a lot of memory when create vqs and other impacts.
>
> Add the protection to guarantee max_nr_ports to get a safe value.
>
> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
> ---
>   drivers/char/virtio_console.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
> index 7eaf303a7..bba985c81 100644
> --- a/drivers/char/virtio_console.c
> +++ b/drivers/char/virtio_console.c
> @@ -29,6 +29,8 @@
>   
>   #define is_rproc_enabled IS_ENABLED(CONFIG_REMOTEPROC)
>   
> +#define MAX_NR_PORTS	MAX_NR_HVC_CONSOLES
> +
>   /*
>    * This is a global struct for storing common data for all the devices
>    * this driver handles.
> @@ -2039,6 +2041,9 @@ static int virtcons_probe(struct virtio_device *vdev)
>   		multiport = true;
>   	}
>   
> +	/* limit max_nr_ports to avoid invalid value from untrusted remote host */
> +	portdev->max_nr_ports = min_t(u32, portdev->max_nr_ports, MAX_NR_PORTS);
> +
>   	err = init_vqs(portdev);
>   	if (err < 0) {
>   		dev_err(&vdev->dev, "Error %d initializing vqs\n", err);

  reply	other threads:[~2021-08-23 11:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-20  7:52 Xianting Tian
2021-08-23 11:55 ` Xianting TIan [this message]
2021-08-27  9:00 ` Greg KH

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=2746b7f2-2cd0-1042-3c36-b4392620525a@linux.alibaba.com \
    --to=xianting.tian@linux.alibaba.com \
    --cc=amit@kernel.org \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.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®