DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: bruce.richardson@intel.com
Subject: [dpdk-dev] [PATCH v2 1/2] mem: check if allocation size is too big
Date: Mon, 30 Apr 2018 12:21:42 +0100	[thread overview]
Message-ID: <fb6d9b6f3bbead5f9ab3e9906814d35431b9edf5.1525086045.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <be863f870fc02ea6464d15c87fa43e9d274f3240.1524155435.git.anatoly.burakov@intel.com>

Mapping size is a 64-bit integer, but mmap() will accept size_t for
size mappings. A user could request a mapping with an alignment, which
would have overflown size_t, so check if (size + alignment) will
overflow size_t.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/common/eal_common_memory.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
index 4c943b0..0ac7b33 100644
--- a/lib/librte_eal/common/eal_common_memory.c
+++ b/lib/librte_eal/common/eal_common_memory.c
@@ -75,8 +75,13 @@ eal_get_virtual_area(void *requested_addr, size_t *size,
 
 	do {
 		map_sz = no_align ? *size : *size + page_sz;
+		if (map_sz > SIZE_MAX) {
+			RTE_LOG(ERR, EAL, "Map size too big\n");
+			rte_errno = E2BIG;
+			return NULL;
+		}
 
-		mapped_addr = mmap(requested_addr, map_sz, PROT_READ,
+		mapped_addr = mmap(requested_addr, (size_t)map_sz, PROT_READ,
 				mmap_flags, -1, 0);
 		if (mapped_addr == MAP_FAILED && allow_shrink)
 			*size -= page_sz;
-- 
2.7.4

  parent reply	other threads:[~2018-04-30 11:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-19 16:35 [dpdk-dev] [PATCH] mem: unmap unneeded space Anatoly Burakov
2018-04-27 16:32 ` Bruce Richardson
2018-04-27 16:38 ` Bruce Richardson
2018-04-30 11:21 ` Anatoly Burakov [this message]
2018-04-30 12:49   ` [dpdk-dev] [PATCH v2 1/2] mem: check if allocation size is too big Bruce Richardson
2018-04-30 11:21 ` [dpdk-dev] [PATCH v2 2/2] mem: unmap unneeded space Anatoly Burakov
2018-04-30 12:50   ` Bruce Richardson
2018-05-02 21:00     ` Thomas Monjalon
2018-05-08 20:20       ` Thomas Monjalon
2018-05-13 23:33         ` Thomas Monjalon

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=fb6d9b6f3bbead5f9ab3e9906814d35431b9edf5.1525086045.git.anatoly.burakov@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.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).