All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: "Jan Beulich" <jbeulich@suse.com>,
	"Jürgen Groß" <jgross@suse.com>, "Julien Grall" <julien@xen.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>,
	KonradWilk <konrad.wilk@oracle.com>,
	Ilja Van Sprundel <ivansprundel@ioactive.com>,
	GeorgeDunlap <George.Dunlap@citrix.com>,
	Ian Jackson <ian.jackson@citrix.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [Xen-devel] [PATCH] console: avoid buffer overflow in guest_console_write()
Date: Fri, 29 Nov 2019 13:57:03 +0000	[thread overview]
Message-ID: <91765e08-cb02-0d3e-1989-13118c2521e1@citrix.com> (raw)
In-Reply-To: <abddefb1-6fac-67d9-c825-43a1b63300c1@suse.com>

On 29/11/2019 13:55, Jan Beulich wrote:
> On 29.11.2019 14:37, Jürgen Groß wrote:
>> On 29.11.19 14:26, Jan Beulich wrote:
>>> On 29.11.2019 13:37, Andrew Cooper wrote:
>>>> On 29/11/2019 12:19, Jan Beulich wrote:
>>>>> On 29.11.2019 13:15, Andrew Cooper wrote:
>>>>>> On 29/11/2019 12:13, Jan Beulich wrote:
>>>>>>> On 29.11.2019 13:01, Ian Jackson wrote:
>>>>>>>> Jan Beulich writes ("Re: [PATCH] console: avoid buffer overflow in guest_console_write()"):
>>>>>>>>> On 29.11.2019 11:22, Andrew Cooper wrote:
>>>>>>>>>> Is sizeof(array[0]) always 0, or is this just a GCC-ism ?  Godbolt
>>>>>>>>>> suggests is 0 on all compiler we support.
>>>>>>>>>>
>>>>>>>>>> Either way, isn't the more common idiom + 0ul ?  Personally, I feel that
>>>>>>>>>> is clearer to follow.
>>>>>>>>> I decided against + 0ul or alike because in principle size_t
>>>>>>>>> and unsigned long are different types. In particular 32-bit
>>>>>>>>> x86 gcc uses unsigned int for size_t, and hence min()'s
>>>>>>>>> type safety check would cause the build to fail there. The
>>>>>>>>> same risk obviously exists for any 32-bit arch (e.g. Arm32,
>>>>>>>>> but I haven't checked what type it actually uses).
>>>>>>>> I don't know what i wrong with
>>>>>>>>     (size_t)0
>>>>>>>> which is shorter, even !
>>>>>>> True. Yet it contains a cast, no matter how risk-free it may be
>>>>>>> in this case. With a cast, I could as well have written (yet
>>>>>>> shorter) (size_t)count.
>>>>>> Given that min() has a very strict typecheck, I think we should permit
>>>>>> any use of an explicit cast in a single operand, because it *is* safer
>>>>>> than switching to the min_t() route to make things compile.
>>>>> Well, I can switch to (size_t)count if this is liked better
>>>>> overall.
>>>> Personally, I'd prefer this option most of all.
>>> Okay, I've switched to this, but while doing so I started wondering
>>> why we'd then not use
>>>
>>>          kcount = min(count, (unsigned int)sizeof(kbuf) - 1);
>>>
>>> which is an (often slightly cheaper) 32-bit operation (and which
>>> is what I had actually started from).
>> While modifying guest_console_write(), would you mind writing a '\0'
>> to kbuf[kcount]? There is a "conring_puts(kbuf);" later in this
>> function which would like a 0 terminated string as input.
> That's not the right change for this problem, I think. Now that
> we support embedded nul characters, a count should be passed
> instead. Julien?
>
> I also wouldn't want to merge this into this patch; I'm happy to
> send a separate one.

I agree.  Lets fix the concrete stack corruption issue separately from
the concern over NUL-correctness (which was the purpose of the patch
which introduced this vulnerability to start with).

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-11-29 13:57 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-29 10:13 [Xen-devel] [PATCH] console: avoid buffer overflow in guest_console_write() Jan Beulich
2019-11-29 10:22 ` Andrew Cooper
2019-11-29 10:27   ` Jan Beulich
2019-11-29 12:01     ` Ian Jackson
2019-11-29 12:04       ` Andrew Cooper
2019-11-29 12:13       ` Jan Beulich
2019-11-29 12:15         ` Andrew Cooper
2019-11-29 12:19           ` Jan Beulich
2019-11-29 12:37             ` Andrew Cooper
2019-11-29 13:26               ` Jan Beulich
2019-11-29 13:37                 ` Jürgen Groß
2019-11-29 13:55                   ` Jan Beulich
2019-11-29 13:57                     ` Andrew Cooper [this message]
2019-11-29 13:57                     ` Jürgen Groß
2019-11-29 10:39 ` Julien Grall
2019-11-29 11:59 ` Ian Jackson
2019-11-29 12:15   ` Jan Beulich
2019-11-29 12:17     ` Andrew Cooper
2019-11-29 12:02 ` Jürgen Groß
2019-11-29 14:35 ` [Xen-devel] [PATCH XTF] CONSOLEIO_write stack overflow PoC Andrew Cooper
2019-11-29 14:43   ` Jan Beulich
2019-11-29 14:45     ` Jan Beulich
2019-11-29 14:50       ` Andrew Cooper

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=91765e08-cb02-0d3e-1989-13118c2521e1@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=George.Dunlap@citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=ivansprundel@ioactive.com \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=julien@xen.org \
    --cc=konrad.wilk@oracle.com \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.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 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.