From: kys@linuxonhyperv.com
To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com,
jasowang@redhat.com, sthemmin@microsoft.com,
Michael.H.Kelley@microsoft.com, vkuznets@redhat.com
Cc: Michael Kelley <mikelley@microsoft.com>,
"K . Y . Srinivasan" <kys@microsoft.com>
Subject: [PATCH 5/5] Drivers: hv: vmbus: Fix synic per-cpu context initialization
Date: Fri, 10 Aug 2018 23:06:11 +0000 [thread overview]
Message-ID: <20180810230611.2114-5-kys@linuxonhyperv.com> (raw)
In-Reply-To: <20180810230611.2114-1-kys@linuxonhyperv.com>
From: Michael Kelley <mikelley@microsoft.com>
If hv_synic_alloc() errors out, the state of the per-cpu context
for some CPUs is unknown since the zero'ing is done as each
CPU is iterated over. In such case, hv_synic_cleanup() may try to
free memory based on uninitialized values. Fix this by zero'ing
the per-cpu context for all CPUs before doing any memory
allocations that might fail.
Signed-off-by: Michael Kelley <mikelley@microsoft.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
---
drivers/hv/hv.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index 748a1c4172a6..332d7c34be5c 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -189,6 +189,17 @@ static void hv_init_clockevent_device(struct clock_event_device *dev, int cpu)
int hv_synic_alloc(void)
{
int cpu;
+ struct hv_per_cpu_context *hv_cpu;
+
+ /*
+ * First, zero all per-cpu memory areas so hv_synic_free() can
+ * detect what memory has been allocated and cleanup properly
+ * after any failures.
+ */
+ for_each_present_cpu(cpu) {
+ hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu);
+ memset(hv_cpu, 0, sizeof(*hv_cpu));
+ }
hv_context.hv_numa_map = kcalloc(nr_node_ids, sizeof(struct cpumask),
GFP_KERNEL);
@@ -198,10 +209,8 @@ int hv_synic_alloc(void)
}
for_each_present_cpu(cpu) {
- struct hv_per_cpu_context *hv_cpu
- = per_cpu_ptr(hv_context.cpu_context, cpu);
+ hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu);
- memset(hv_cpu, 0, sizeof(*hv_cpu));
tasklet_init(&hv_cpu->msg_dpc,
vmbus_on_msg_dpc, (unsigned long) hv_cpu);
--
2.18.0
next prev parent reply other threads:[~2018-08-10 23:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-10 23:05 [PATCH 0/5] Miscellaneous fixes/enhancements kys
2018-08-10 23:06 ` [PATCH 1/5] Tools: hv: Fix a bug in the key delete code kys
2018-08-10 23:06 ` [PATCH 2/5] vmbus: add driver_override support kys
2018-08-13 19:30 ` Michael Kelley (EOSG)
2018-08-13 19:40 ` gregkh
2018-08-13 19:56 ` Stephen Hemminger
2018-08-14 16:35 ` Stephen Hemminger
2018-08-14 19:13 ` Michael Kelley (EOSG)
2018-08-10 23:06 ` [PATCH 3/5] uio_hv_generic: increase size of receive and send buffers kys
2018-08-10 23:06 ` [PATCH 4/5] uio_hv_generic: drop #ifdef DEBUG kys
2018-08-10 23:06 ` kys [this message]
2018-08-13 16:41 ` [PATCH 1/5] Tools: hv: Fix a bug in the key delete code Michael Kelley (EOSG)
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=20180810230611.2114-5-kys@linuxonhyperv.com \
--to=kys@linuxonhyperv.com \
--cc=Michael.H.Kelley@microsoft.com \
--cc=apw@canonical.com \
--cc=devel@linuxdriverproject.org \
--cc=gregkh@linuxfoundation.org \
--cc=jasowang@redhat.com \
--cc=kys@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mikelley@microsoft.com \
--cc=olaf@aepfle.de \
--cc=sthemmin@microsoft.com \
--cc=vkuznets@redhat.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 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).