From: Jim Meyering <jim@meyering.net>
To: lvm-devel@redhat.com
Subject: clvmd-command.c: unchecked realloc return value: potential DoS?
Date: Thu, 26 Apr 2007 18:21:04 +0200 [thread overview]
Message-ID: <87ejm72jkf.fsf@rho.meyering.net> (raw)
While this "case:" is solely for CLVMD_CMD_TEST, which is documented like this:
#define CLVMD_CMD_TEST 4 /* Just for mucking about */
we wouldn't want a malicious client to be able to DoS a server
by provoking a low-memory condition and then sending a test message.
Here's the code:
int do_command(struct local_client *client, struct clvm_header *msg, int msglen,
char **buf, int buflen, int *retlen)
{
...
switch (msg->cmd) {
/* Just a test message */
case CLVMD_CMD_TEST:
if (arglen > buflen) {
buflen = arglen + 200;
*buf = realloc(*buf, buflen);
}
uname(&nodeinfo);
*retlen = 1 + snprintf(*buf, buflen, "TEST from %s: %s v%s",
nodeinfo.nodename, args,
nodeinfo.release);
break;
Here's an untested patch:
* daemons/clvmd/clvmd-command.c (do_command): Don't dereference NULL
upon failed realloc.
Index: daemons/clvmd/clvmd-command.c
===================================================================
RCS file: /cvs/lvm2/LVM2/daemons/clvmd/clvmd-command.c,v
retrieving revision 1.14
diff -u -p -r1.14 clvmd-command.c
--- daemons/clvmd/clvmd-command.c 11 Dec 2006 14:00:26 -0000 1.14
+++ daemons/clvmd/clvmd-command.c 26 Apr 2007 16:10:17 -0000
@@ -95,13 +95,22 @@ int do_command(struct local_client *clie
/* Just a test message */
case CLVMD_CMD_TEST:
if (arglen > buflen) {
+ char *new_buf;
buflen = arglen + 200;
- *buf = realloc(*buf, buflen);
+ new_buf = realloc(*buf, buflen);
+ if (new_buf == NULL) {
+ status = errno;
+ free (*buf);
+ }
+ *buf = new_buf;
+ }
+ if (*buf) {
+ uname(&nodeinfo);
+ *retlen = 1 + snprintf(*buf, buflen,
+ "TEST from %s: %s v%s",
+ nodeinfo.nodename, args,
+ nodeinfo.release);
}
- uname(&nodeinfo);
- *retlen = 1 + snprintf(*buf, buflen, "TEST from %s: %s v%s",
- nodeinfo.nodename, args,
- nodeinfo.release);
break;
case CLVMD_CMD_LOCK_VG:
------------------------------
BTW, in the same function, I noticed that "*retlen" is not set consistently.
In the CLVMD_CMD_TEST and CLVMD_CMD_LOCK_VG cases, it's set to
"1 + snprintf(...)", so it includes the trailing NUL byte.
But here, it doesn't:
case CLVMD_CMD_GET_CLUSTERNAME:
status = clops->get_cluster_name(*buf, buflen);
if (!status)
*retlen = strlen(*buf);
break;
I don't know enough to say whether there's a bug, but it's worth
fixing in any case, e.g.,
*retlen = 1 + strlen(*buf);
next reply other threads:[~2007-04-26 16:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-26 16:21 Jim Meyering [this message]
2007-04-27 8:03 ` clvmd-command.c: unchecked realloc return value: potential DoS? Patrick Caulfield
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=87ejm72jkf.fsf@rho.meyering.net \
--to=jim@meyering.net \
--cc=lvm-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.