From patchwork Thu Feb 11 19:30:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Germano Percossi X-Patchwork-Id: 8284791 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 008D49F6E4 for ; Thu, 11 Feb 2016 19:34:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 14CFB202FE for ; Thu, 11 Feb 2016 19:34:54 +0000 (UTC) Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 383A2202E9 for ; Thu, 11 Feb 2016 19:34:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1BJV4bm025963; Thu, 11 Feb 2016 14:31:06 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u1BJV3sQ008669 for ; Thu, 11 Feb 2016 14:31:03 -0500 Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1BJV2jF018155 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 11 Feb 2016 14:31:02 -0500 Received: from SMTP.CITRIX.COM (smtp.citrix.com [66.165.176.89]) by mx1.redhat.com (Postfix) with ESMTPS id 19A2070002 for ; Thu, 11 Feb 2016 19:31:00 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.22,432,1449532800"; d="scan'208";a="331175445" From: Germano Percossi To: Date: Thu, 11 Feb 2016 19:30:54 +0000 Message-ID: <1455219054-13122-1-git-send-email-germano.percossi@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 X-RedHat-Spam-Score: -4.856 (BAYES_50, DCC_REPUT_00_12, RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS) 66.165.176.89 smtp.citrix.com 66.165.176.89 smtp.citrix.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Scanned-By: MIMEDefang 2.75 on 10.5.110.28 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 1/1] multipath: fix memory leak and segfault in reconfigure X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Within the reconfigure function, the global pointer conf is stored in a local variable and then assigned NULL. If load_config should fail, for any reason, we end up with a memory leak, as soon as we leave the function, and with the global pointer conf set to NULL, leading to a segfault as soon as it is dereferenced. I tested it by calling a reconfigure and making the first allocation in load_config fail but any failure in load_config would do. >From a user perspective the CLI reports "fail". If something like this should happen there are at least 2 possible scenarios: 1) If a second immediate reconfigure succeeds, the conf now is fine but the leak stays 2) If the previous point does not happen, any command trying to access "conf" would fail. On my test box a "show conf" segfaulted. The fix is simple but in case of failure at least the previous conf is kept in memory without leaks or segfaluts Signed-off-by: Germano Percossi --- multipathd/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/multipathd/main.c b/multipathd/main.c index 04f6d02..f83c849 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1551,6 +1551,8 @@ reconfigure (struct vectors * vecs) configure(vecs, 1); free_config(old); retval = 0; + } else { + conf = old; } running_state = DAEMON_RUNNING;