From: Olivier Matz <olivier.matz@6wind.com>
To: dev@dpdk.org
Cc: Dongsu Han <dongsuh@cs.cmu.edu>
Subject: [dpdk-dev] eal/log: fix memory corruption
Date: Thu, 2 May 2013 11:22:37 +0200 [thread overview]
Message-ID: <1367486557-8589-1-git-send-email-olivier.matz@6wind.com> (raw)
In-Reply-To: <51822F49.5040406@6wind.com>
From: Dongsu Han <dongsuh@cs.cmu.edu>
The '\0' is written outside the bounds of the log buffer, which can
result in memory corruption or display issues with log messages.
Use a new constant LOG_BUF_SIZE to store the effective size of the
buffer in struct log_history.
Signed-off-by: Dongsu Han <dongsuh@cs.cmu.edu>
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
lib/librte_eal/common/eal_common_log.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index 1362109..9926ae4 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -64,6 +64,7 @@
#include "eal_private.h"
#define LOG_ELT_SIZE 2048
+#define LOG_BUF_SIZE (LOG_ELT_SIZE - sizeof(struct log_history))
#define LOG_HISTORY_MP_NAME "log_history"
@@ -196,7 +197,7 @@ rte_log_add_in_history(const char *buf, size_t size)
}
/* not enough room for msg, buffer go back in mempool */
- if (size >= (LOG_ELT_SIZE - sizeof(*hist_buf))) {
+ if (size >= LOG_BUF_SIZE - 1) {
rte_mempool_mp_put(log_history_mp, hist_buf);
rte_spinlock_unlock(&log_list_lock);
return -ENOBUFS;
@@ -204,7 +205,7 @@ rte_log_add_in_history(const char *buf, size_t size)
/* add in history */
memcpy(hist_buf->buf, buf, size);
- hist_buf->buf[LOG_ELT_SIZE-1] = '\0';
+ hist_buf->buf[size] = '\0';
hist_buf->size = size;
STAILQ_INSERT_TAIL(&log_history, hist_buf, next);
rte_spinlock_unlock(&log_list_lock);
--
1.7.10.4
next prev parent reply other threads:[~2013-05-02 9:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-01 18:50 [dpdk-dev] [PATCH] fixed buffer overrun in handling log messages Han, Dongsu
2013-05-02 8:24 ` Olivier MATZ
2013-05-02 9:18 ` Olivier MATZ
2013-05-02 9:22 ` Olivier Matz [this message]
2013-05-03 16:37 ` [dpdk-dev] eal/log: fix memory corruption 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=1367486557-8589-1-git-send-email-olivier.matz@6wind.com \
--to=olivier.matz@6wind.com \
--cc=dev@dpdk.org \
--cc=dongsuh@cs.cmu.edu \
/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).