From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>,
devel@linuxdriverproject.org, linux-kernel@vger.kernel.org,
Dexuan Cui <decui@microsoft.com>,
Laszlo Ersek <lersek@redhat.com>
Subject: [PATCH 2/2] Drivers: hv: hv_balloon: correctly handle num_pages>INT_MAX case
Date: Fri, 27 Mar 2015 17:03:00 +0100 [thread overview]
Message-ID: <1427472180-21439-3-git-send-email-vkuznets@redhat.com> (raw)
In-Reply-To: <1427472180-21439-1-git-send-email-vkuznets@redhat.com>
balloon_wrk.num_pages is __u32 and it comes from host in struct dm_balloon
where it is also __u32. We, however, use 'int' in balloon_up() and in case
we happen to receive num_pages>INT_MAX request we'll end up allocating zero
pages as 'num_pages < alloc_unit' check in alloc_balloon_pages() will pass.
Change num_pages type to unsigned int.
In real life ballooning request come with num_pages in [512, 32768] range so
this is more a future-proof/cleanup.
Reported-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
drivers/hv/hv_balloon.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index 20bfe36..35312e1 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -1071,11 +1071,12 @@ static void free_balloon_pages(struct hv_dynmem_device *dm,
-static int alloc_balloon_pages(struct hv_dynmem_device *dm, int num_pages,
- struct dm_balloon_response *bl_resp,
- int alloc_unit)
+static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm,
+ unsigned int num_pages,
+ struct dm_balloon_response *bl_resp,
+ int alloc_unit)
{
- int i = 0;
+ unsigned int i = 0;
struct page *pg;
if (num_pages < alloc_unit)
@@ -1122,8 +1123,8 @@ static int alloc_balloon_pages(struct hv_dynmem_device *dm, int num_pages,
static void balloon_up(struct work_struct *dummy)
{
- int num_pages = dm_device.balloon_wrk.num_pages;
- int num_ballooned = 0;
+ unsigned int num_pages = dm_device.balloon_wrk.num_pages;
+ unsigned int num_ballooned = 0;
struct dm_balloon_response *bl_resp;
int alloc_unit;
int ret;
--
1.9.3
next prev parent reply other threads:[~2015-03-27 16:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-27 16:02 [PATCH 0/2] Drivers: hv: hv_balloon: two additional corner cases in balloon_up() Vitaly Kuznetsov
2015-03-27 16:02 ` [PATCH 1/2] Drivers: hv: hv_balloon: correctly handle val.freeram<num_pages case Vitaly Kuznetsov
2015-03-27 16:03 ` Vitaly Kuznetsov [this message]
2015-03-27 22:25 ` [PATCH 0/2] Drivers: hv: hv_balloon: two additional corner cases in balloon_up() Laszlo Ersek
2015-03-31 18:16 K. Y. Srinivasan
2015-03-31 18:16 ` [PATCH 1/2] Drivers: hv: hv_balloon: correctly handle val.freeram<num_pages case K. Y. Srinivasan
2015-03-31 18:16 ` [PATCH 2/2] Drivers: hv: hv_balloon: correctly handle num_pages>INT_MAX case K. Y. Srinivasan
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=1427472180-21439-3-git-send-email-vkuznets@redhat.com \
--to=vkuznets@redhat.com \
--cc=decui@microsoft.com \
--cc=devel@linuxdriverproject.org \
--cc=haiyangz@microsoft.com \
--cc=kys@microsoft.com \
--cc=lersek@redhat.com \
--cc=linux-kernel@vger.kernel.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®