qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: P J P <ppandit@redhat.com>
Cc: qemu-devel@nongnu.org, Ling Liu <liuling-it@360.cn>
Subject: Re: [Qemu-devel] [PATCH] hmp: avoid redundant null termination of buffer
Date: Fri, 8 Jan 2016 10:19:49 +0100	[thread overview]
Message-ID: <20160108091949.GA14724@olga> (raw)
In-Reply-To: <alpine.LFD.2.20.1512171804220.4286@wniryva>

On Thu, Dec 17, 2015 at 06:10:59PM +0530, P J P wrote:
>   Hello,
> 
> An OOB write issue was reported by Mr Ling Liu, CC'd here. It occurs while
> processing the 'sendkey' command, if the command argument was longer than
> the 'keyname_buf[16]' buffer.
> 
> ===
> From b0363f4c0e91671064dd7ffece8a6923c8dcaf20 Mon Sep 17 00:00:00 2001
> From: Prasad J Pandit <pjp@fedoraproject.org>
> Date: Thu, 17 Dec 2015 17:47:15 +0530
> Subject: [PATCH] hmp: avoid redundant null termination of buffer
> 
> When processing 'sendkey' command, hmp_sendkey routine null
> terminates the 'keyname_buf' array. This results in an OOB write
> issue, if 'keyname_len' was to fall outside of 'keyname_buf' array.
> Removed the redundant null termination, as pstrcpy routine already
> null terminates the target buffer.
> 
> Reported-by: Ling Liu <liuling-it@360.cn>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> ---
>  hmp.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/hmp.c b/hmp.c
> index 2140605..e530c9c 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -1746,9 +1746,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict)
>          /* Be compatible with old interface, convert user inputted "<" */
>          if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
>              pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
> -            keyname_len = 4;

keyname_buf is a char[16] so 4 will not overflow it.

>          }
> -        keyname_buf[keyname_len] = 0;

This last write is also used to separate combined keys, so removing
this write breaks commands such as `sendkeys ctrl-f1`.
Better add a -1 to the sizeof()s?

Come to think of it, when is this really an OOB write?
Given where keyname_len comes from:

| separator = strchr(keys, '-');
| keyname_len = separator ? separator - keys : strlen(keys);

If separator is found the assignment replaces the '-', which is valid,
and if not then it'll point to the '\0' byte and simply writes to that,
which is still inside the string. What might be useful to do is see if
(separator != NULL && separator - keys >= sizeof(keyname_buf)) you can
error out since it means there's a single key-name longer than
keyname_buf used as parameter.

The buffer used here is static, the pointer that is advanced through the
key names is the 'keys' variable which is only read from.

| const char *keys = qdict_get_str(qdict, "keys");

and

| keys = separator + 1;

So I'm not sure this is really a bug here?
And if it is, this patch still breaks combined 'sendkey' commands.

>          keylist = g_malloc0(sizeof(*keylist));
>          keylist->value = g_malloc0(sizeof(*keylist->value));
> -- 
> 2.4.3
> ===
> 
> Thank you.
> --
> Prasad J Pandit / Red Hat Product Security Team
> 47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F
> 
> 

  parent reply	other threads:[~2016-01-08  9:29 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-17 12:40 [Qemu-devel] [PATCH] hmp: avoid redundant null termination of buffer P J P
2015-12-18  3:46 ` 刘令
2015-12-18  4:34   ` P J P
2015-12-22 18:48 ` Luiz Capitulino
2016-01-12  8:41   ` Markus Armbruster
2016-01-08  9:19 ` Wolfgang Bumiller [this message]
2016-01-08 12:19   ` P J P
2016-01-08 13:02     ` Wolfgang Bumiller
2016-01-08 13:59       ` P J P
2016-01-08 14:38         ` Wolfgang Bumiller
2016-01-08 17:32           ` P J P
2016-01-09  9:31             ` Wolfgang Bumiller
2016-01-09 13:03               ` P J P
2016-01-10  7:56                 ` Michael Tokarev
2016-01-11  7:00                   ` P J P
2016-01-11  7:59                   ` Wolfgang Bumiller
2016-01-11  8:22                     ` P J P
2016-01-12  8:45                     ` Markus Armbruster
2016-01-12  9:27                       ` Wolfgang Bumiller
2016-01-12 16:00                         ` Markus Armbruster
2016-01-12 16:25                           ` Wolfgang Bumiller
2016-01-12 16:52                             ` Markus Armbruster
2016-01-13  8:09                               ` Wolfgang Bumiller
2016-01-18 13:02                                 ` Markus Armbruster
2016-01-18 13:38                                   ` Wolfgang Bumiller
2016-01-18 14:23                                     ` Markus Armbruster
2016-01-26  9:36                                       ` Michael Tokarev
2016-01-28 10:52                                         ` Michael Tokarev
2016-01-28 14:45                                           ` Markus Armbruster

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=20160108091949.GA14724@olga \
    --to=w.bumiller@proxmox.com \
    --cc=liuling-it@360.cn \
    --cc=ppandit@redhat.com \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).