xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Keir Fraser <keir@xen.org>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Jan Beulich <JBeulich@suse.com>
Subject: [PATCH 4/4] x86/microcode_amd: Fail attempts to load a 0-length microcode blob.
Date: Tue, 24 Sep 2013 13:10:38 +0100	[thread overview]
Message-ID: <1380024638-14983-5-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1380024638-14983-1-git-send-email-andrew.cooper3@citrix.com>

Coverity ID: 1055319

Coverity identified that when passed a microcode header with a length field of
0, get_ucode_from_buffer_amd() would end up calling memcpy(NULL, data, 0)
which is undefined behaviour.

While Xen's implementation of memcpy will do the correct thing in this case,
any user trying to load a 0 length microcode blob deserves an -EINVAL.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Keir Fraser <keir@xen.org>
CC: Jan Beulich <JBeulich@suse.com>
CC: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
CC: Boris Ostrovsky <boris.ostrovsky@oracle.com>
---
 xen/arch/x86/microcode_amd.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/arch/x86/microcode_amd.c b/xen/arch/x86/microcode_amd.c
index a3ceef8..2c767a9 100644
--- a/xen/arch/x86/microcode_amd.c
+++ b/xen/arch/x86/microcode_amd.c
@@ -202,7 +202,7 @@ static int get_ucode_from_buffer_amd(
         return -EINVAL;
     }
 
-    if ( (off + mpbuf->len) > bufsize )
+    if ( mpbuf->len == 0 || ((off + mpbuf->len) > bufsize) )
     {
         printk(KERN_ERR "microcode: Bad data in microcode data file\n");
         return -EINVAL;
-- 
1.7.10.4

  parent reply	other threads:[~2013-09-24 12:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-24 12:10 [PATCH 0/4] Misc Xen fixes identified by Coverity Andrew Cooper
2013-09-24 12:10 ` [PATCH 1/4] xen/irq: irq_to_desc() can't return NULL Andrew Cooper
2013-09-24 13:05   ` Jan Beulich
2013-09-24 12:10 ` [PATCH 2/4] x86/hap: Remove bogus assertion in hap_free_p2m_page() Andrew Cooper
2013-09-24 12:26   ` Tim Deegan
2013-09-24 12:10 ` [PATCH 3/4] common/page_alloc: Remove node id ASSERT()s Andrew Cooper
2013-09-24 13:13   ` Jan Beulich
2013-09-24 12:10 ` Andrew Cooper [this message]
2013-09-24 13:19   ` [PATCH 4/4] x86/microcode_amd: Fail attempts to load a 0-length microcode blob Jan Beulich
2013-09-24 14:26     ` Boris Ostrovsky
2013-09-24 14:31       ` Jan Beulich
2013-09-24 14:31       ` 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=1380024638-14983-5-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=keir@xen.org \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=xen-devel@lists.xen.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).