From: Olaf Hering <olaf@aepfle.de>
To: konrad.wilk@oracle.com
Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xen.org,
jbeulich@suse.com, Olaf Hering <olaf@aepfle.de>
Subject: [PATCH] xen/blkback: prevent leak of mode during multiple backend_changed calls
Date: Wed, 5 Dec 2012 11:01:37 +0100 [thread overview]
Message-ID: <1354701697-5815-1-git-send-email-olaf@aepfle.de> (raw)
backend_changed might be called multiple times, which will leak
be->mode. free the previous value before storing the current mode value.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
!! Not compile tested !!
drivers/block/xen-blkback/xenbus.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index a6585a4..8650b19 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -502,7 +502,7 @@ static void backend_changed(struct xenbus_watch *watch,
= container_of(watch, struct backend_info, backend_watch);
struct xenbus_device *dev = be->dev;
int cdrom = 0;
- char *device_type;
+ char *mode, *device_type;
DPRINTK("");
@@ -528,13 +528,15 @@ static void backend_changed(struct xenbus_watch *watch,
return;
}
- be->mode = xenbus_read(XBT_NIL, dev->nodename, "mode", NULL);
- if (IS_ERR(be->mode)) {
- err = PTR_ERR(be->mode);
+ mode = xenbus_read(XBT_NIL, dev->nodename, "mode", NULL);
+ kfree(be->mode);
+ if (IS_ERR(mode)) {
+ err = PTR_ERR(mode);
be->mode = NULL;
xenbus_dev_fatal(dev, err, "reading mode");
return;
}
+ be->mode = mode;
device_type = xenbus_read(XBT_NIL, dev->otherend, "device-type", NULL);
if (!IS_ERR(device_type)) {
@@ -555,7 +557,7 @@ static void backend_changed(struct xenbus_watch *watch,
be->minor = minor;
err = xen_vbd_create(be->blkif, handle, major, minor,
- (NULL == strchr(be->mode, 'w')), cdrom);
+ (NULL == strchr(mode, 'w')), cdrom);
if (err) {
be->major = 0;
be->minor = 0;
--
1.8.0.1
next reply other threads:[~2012-12-05 10:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-05 10:01 Olaf Hering [this message]
2012-12-05 10:21 ` [PATCH] xen/blkback: prevent leak of mode during multiple backend_changed calls Jan Beulich
2012-12-06 16:23 ` Olaf Hering
2012-12-06 17:02 ` Jan Beulich
2012-12-06 19:04 ` Olaf Hering
2012-12-07 19:46 ` Konrad Rzeszutek Wilk
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=1354701697-5815-1-git-send-email-olaf@aepfle.de \
--to=olaf@aepfle.de \
--cc=jbeulich@suse.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=xen-devel@lists.xen.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).