From patchwork Thu Apr 9 14:12:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11481855 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 887201744 for ; Thu, 9 Apr 2020 14:15:39 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6C82120771 for ; Thu, 9 Apr 2020 14:15:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C82120771 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jMXvK-0002oV-Ca; Thu, 09 Apr 2020 14:12:54 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jMXvI-0002oI-RA for xen-devel@lists.xenproject.org; Thu, 09 Apr 2020 14:12:52 +0000 X-Inumbo-ID: 2efc5962-7a6c-11ea-82d6-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2efc5962-7a6c-11ea-82d6-12813bfff9fa; Thu, 09 Apr 2020 14:12:45 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E6972AD72; Thu, 9 Apr 2020 14:12:43 +0000 (UTC) From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Subject: [PATCH 1/3] mini-os: fix double free() in netfront Date: Thu, 9 Apr 2020 16:12:38 +0200 Message-Id: <20200409141240.28876-2-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200409141240.28876-1-jgross@suse.com> References: <20200409141240.28876-1-jgross@suse.com> X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , samuel.thibault@ens-lyon.org, wl@xen.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Commit d225f4012d69a19 ("Save/Restore Support: Add suspend/restore support for netfront") introduced a regression in form of freeing a netfront device structure twice. Fix that. Coverity-ID: 1433637 Fixes: d225f4012d69a19 ("Save/Restore Support: Add suspend/restore support for netfront") Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- netfront.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/netfront.c b/netfront.c index 50b3a57..fe7bb62 100644 --- a/netfront.c +++ b/netfront.c @@ -584,8 +584,6 @@ void shutdown_netfront(struct netfront_dev *dev) list->refcount--; if (list->refcount == 0) { _shutdown_netfront(dev); - free(dev->nodename); - free(dev); to_del = list; if (to_del == dev_list) { From patchwork Thu Apr 9 14:12:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11481847 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C639992A for ; Thu, 9 Apr 2020 14:14:38 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AB8C920771 for ; Thu, 9 Apr 2020 14:14:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB8C920771 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jMXvF-0002nv-2C; Thu, 09 Apr 2020 14:12:49 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jMXvD-0002nk-T3 for xen-devel@lists.xenproject.org; Thu, 09 Apr 2020 14:12:47 +0000 X-Inumbo-ID: 2f0d72f6-7a6c-11ea-82d6-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2f0d72f6-7a6c-11ea-82d6-12813bfff9fa; Thu, 09 Apr 2020 14:12:46 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0607EAE59; Thu, 9 Apr 2020 14:12:43 +0000 (UTC) From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Subject: [PATCH 2/3] mini-os: fix double free() in xenbus Date: Thu, 9 Apr 2020 16:12:39 +0200 Message-Id: <20200409141240.28876-3-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200409141240.28876-1-jgross@suse.com> References: <20200409141240.28876-1-jgross@suse.com> X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , samuel.thibault@ens-lyon.org, wl@xen.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Commit 973ad0c4de1b48 ("Save/Restore Support: Add suspend/restore support for xenbus") introduced a double free of some memory and leaked another memory allocation. Fix those. Coverity-ID: 1433640 Fixes: 973ad0c4de1b48 ("Save/Restore Support: Add suspend/restore support for xenbus") Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- xenbus/xenbus.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xenbus/xenbus.c b/xenbus/xenbus.c index d72dc3a..b12cef7 100644 --- a/xenbus/xenbus.c +++ b/xenbus/xenbus.c @@ -413,9 +413,11 @@ void resume_xenbus(int canceled) rep = xenbus_msg_reply(XS_WATCH, XBT_NIL, req, ARRAY_SIZE(req)); msg = errmsg(rep); - if (msg) + if (msg) { xprintk("error on XS_WATCH: %s\n", msg); - free(rep); + free(msg); + } else + free(rep); } } From patchwork Thu Apr 9 14:12:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11481843 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B797D92A for ; Thu, 9 Apr 2020 14:14:32 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9C7F020771 for ; Thu, 9 Apr 2020 14:14:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C7F020771 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jMXvR-0002sl-TY; Thu, 09 Apr 2020 14:13:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jMXvR-0002sX-HH for xen-devel@lists.xenproject.org; Thu, 09 Apr 2020 14:13:01 +0000 X-Inumbo-ID: 2f29d108-7a6c-11ea-b4f4-bc764e2007e4 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 2f29d108-7a6c-11ea-b4f4-bc764e2007e4; Thu, 09 Apr 2020 14:12:46 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2EF93AF6E; Thu, 9 Apr 2020 14:12:44 +0000 (UTC) From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Subject: [PATCH 3/3] mini-os: fix several memory leaks related to xenbus Date: Thu, 9 Apr 2020 16:12:40 +0200 Message-Id: <20200409141240.28876-4-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200409141240.28876-1-jgross@suse.com> References: <20200409141240.28876-1-jgross@suse.com> X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , samuel.thibault@ens-lyon.org, wl@xen.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" There are several instances of calls to xenbus functions which don't test for an error and in consequence are not freeing the returned error strings, or which are just not freeing the string after e.g. printing it. Fix that by either adding the needed calls of free(). Coverity-ID: 1433632 Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- blkfront.c | 4 ++-- console/xenbus.c | 2 +- fbfront.c | 4 ++-- netfront.c | 2 +- pcifront.c | 28 +++++++++++++--------------- shutdown.c | 2 +- xenbus/xenbus.c | 2 ++ 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/blkfront.c b/blkfront.c index f747216..834a978 100644 --- a/blkfront.c +++ b/blkfront.c @@ -200,7 +200,7 @@ done: snprintf(path, sizeof(path), "%s/state", dev->backend); - xenbus_watch_path_token(XBT_NIL, path, path, &dev->events); + free(xenbus_watch_path_token(XBT_NIL, path, path, &dev->events)); msg = NULL; state = xenbus_read_integer(path); @@ -208,7 +208,7 @@ done: msg = xenbus_wait_for_state_change(path, &state, &dev->events); if (msg != NULL || state != XenbusStateConnected) { printk("backend not available, state=%d\n", state); - xenbus_unwatch_path_token(XBT_NIL, path, path); + free(xenbus_unwatch_path_token(XBT_NIL, path, path)); goto error; } diff --git a/console/xenbus.c b/console/xenbus.c index 654b469..05fc31c 100644 --- a/console/xenbus.c +++ b/console/xenbus.c @@ -164,7 +164,7 @@ done: char path[strlen(dev->backend) + strlen("/state") + 1]; snprintf(path, sizeof(path), "%s/state", dev->backend); - xenbus_watch_path_token(XBT_NIL, path, path, &dev->events); + free(xenbus_watch_path_token(XBT_NIL, path, path, &dev->events)); msg = NULL; state = xenbus_read_integer(path); while (msg == NULL && state < XenbusStateConnected) diff --git a/fbfront.c b/fbfront.c index 9cc07b4..d3b3848 100644 --- a/fbfront.c +++ b/fbfront.c @@ -163,7 +163,7 @@ done: snprintf(path, sizeof(path), "%s/state", dev->backend); - xenbus_watch_path_token(XBT_NIL, path, path, &dev->events); + free(xenbus_watch_path_token(XBT_NIL, path, path, &dev->events)); err = NULL; state = xenbus_read_integer(path); @@ -530,7 +530,7 @@ done: snprintf(path, sizeof(path), "%s/state", dev->backend); - xenbus_watch_path_token(XBT_NIL, path, path, &dev->events); + free(xenbus_watch_path_token(XBT_NIL, path, path, &dev->events)); err = NULL; state = xenbus_read_integer(path); diff --git a/netfront.c b/netfront.c index fe7bb62..66f2bbc 100644 --- a/netfront.c +++ b/netfront.c @@ -513,7 +513,7 @@ done: err = xenbus_wait_for_state_change(path, &state, &dev->events); if (state != XenbusStateConnected) { printk("backend not avalable, state=%d\n", state); - xenbus_unwatch_path_token(XBT_NIL, path, path); + free(xenbus_unwatch_path_token(XBT_NIL, path, path)); goto error; } diff --git a/pcifront.c b/pcifront.c index 0fc5b30..5642356 100644 --- a/pcifront.c +++ b/pcifront.c @@ -70,28 +70,28 @@ void pcifront_watches(void *opaque) while (1) { printk("pcifront_watches: waiting for backend path to appear %s\n", path); - xenbus_watch_path_token(XBT_NIL, path, path, &events); + free(xenbus_watch_path_token(XBT_NIL, path, path, &events)); while ((err = xenbus_read(XBT_NIL, path, &be_path)) != NULL) { free(err); xenbus_wait_for_watch(&events); } - xenbus_unwatch_path_token(XBT_NIL, path, path); + free(xenbus_unwatch_path_token(XBT_NIL, path, path)); printk("pcifront_watches: waiting for backend to get into the right state %s\n", be_path); be_state = (char *) malloc(strlen(be_path) + 7); snprintf(be_state, strlen(be_path) + 7, "%s/state", be_path); - xenbus_watch_path_token(XBT_NIL, be_state, be_state, &events); + free(xenbus_watch_path_token(XBT_NIL, be_state, be_state, &events)); while ((err = xenbus_read(XBT_NIL, be_state, &msg)) != NULL || msg[0] > '4') { free(msg); free(err); xenbus_wait_for_watch(&events); } - xenbus_unwatch_path_token(XBT_NIL, be_state, be_state); + free(xenbus_unwatch_path_token(XBT_NIL, be_state, be_state)); if (init_pcifront(NULL) == NULL) { free(be_state); free(be_path); continue; } - xenbus_watch_path_token(XBT_NIL, be_state, be_state, &events); + free(xenbus_watch_path_token(XBT_NIL, be_state, be_state, &events)); state = XenbusStateConnected; printk("pcifront_watches: waiting for backend events %s\n", be_state); while ((err = xenbus_wait_for_state_change(be_state, &state, &events)) == NULL && @@ -103,10 +103,9 @@ void pcifront_watches(void *opaque) if ((err = xenbus_switch_state(XBT_NIL, fe_state, XenbusStateReconfiguring)) != NULL) { printk("pcifront_watches: error changing state to %d: %s\n", XenbusStateReconfiguring, err); - if (!strcmp(err, "ENOENT")) { - xenbus_write(XBT_NIL, fe_state, "7"); - free(err); - } + if (!strcmp(err, "ENOENT")) + free(xenbus_write(XBT_NIL, fe_state, "7")); + free(err); } } else if (state == XenbusStateReconfigured) { printk("pcifront_watches: writing %s %d\n", fe_state, XenbusStateConnected); @@ -114,10 +113,9 @@ void pcifront_watches(void *opaque) if ((err = xenbus_switch_state(XBT_NIL, fe_state, XenbusStateConnected)) != NULL) { printk("pcifront_watches: error changing state to %d: %s\n", XenbusStateConnected, err); - if (!strcmp(err, "ENOENT")) { - xenbus_write(XBT_NIL, fe_state, "4"); - free(err); - } + if (!strcmp(err, "ENOENT")) + free(xenbus_write(XBT_NIL, fe_state, "4")); + free(err); } } else if (state == XenbusStateClosing) break; @@ -135,7 +133,7 @@ void pcifront_watches(void *opaque) pcidev = NULL; } - xenbus_unwatch_path_token(XBT_NIL, path, path); + free(xenbus_unwatch_path_token(XBT_NIL, path, path)); } struct pcifront_dev *init_pcifront(char *_nodename) @@ -243,7 +241,7 @@ done: XenbusState state; snprintf(path, sizeof(path), "%s/state", dev->backend); - xenbus_watch_path_token(XBT_NIL, path, path, &dev->events); + free(xenbus_watch_path_token(XBT_NIL, path, path, &dev->events)); err = NULL; state = xenbus_read_integer(path); diff --git a/shutdown.c b/shutdown.c index c7c92cb..4c0b13c 100644 --- a/shutdown.c +++ b/shutdown.c @@ -71,7 +71,7 @@ static void shutdown_thread(void *p) char *shutdown, *err; unsigned int shutdown_reason; - xenbus_watch_path_token(XBT_NIL, path, token, &events); + free(xenbus_watch_path_token(XBT_NIL, path, token, &events)); for ( ;; ) { xenbus_wait_for_watch(&events); diff --git a/xenbus/xenbus.c b/xenbus/xenbus.c index b12cef7..9e61930 100644 --- a/xenbus/xenbus.c +++ b/xenbus/xenbus.c @@ -198,6 +198,8 @@ exit: } if (msg == NULL && msg2 != NULL) msg = msg2; + else + free(msg2); } while (retry); return msg;