From patchwork Thu Mar 8 16:15:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davide Caratti X-Patchwork-Id: 883213 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ADeh9NIF"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JDHctmay"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zxwbn1r1rz9shl for ; Fri, 9 Mar 2018 03:15:49 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=sSNpaeGZgqMGHxZPaKw8eihyU8o5tpyc3v8vjiA56Ms=; b=ADe h9NIFvK/XF2LC9IFIhWByq4p0FEY4cE9s/hpCCAhDYumNl0B0YQs02bwH85Mcv2eCl1+fK5nISQ84 /GFBbRNZNPWShiK5sIBaE66/Fni1Mx5ExfTcTQzIvlXi6Pbr2AK9lZYnU21MkAJdO0pm+pQOWT9Dc URhTvQRhz+GG/0G0HZB4zVtXc3e0vYiFhiL6EVLJBhUrKrNzH9Fjrf2NXyM9f8TyB71NEXTr7OuqT Nbkys2xoA6yFJ1Y/5Y2vl37uQJ8cU4NfBRe1pzmXVBJ1Js5qrfEJ7uMkTTSTVVV4rVKP4ntP8j6jj UK6+tqV4f9Nwkt+SYPRBheqwa5PPd2A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1etyCd-0005wq-IS; Thu, 08 Mar 2018 16:15:35 +0000 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1etyCZ-0005us-Ok for hostap@lists.infradead.org; Thu, 08 Mar 2018 16:15:33 +0000 Received: by mail-wr0-x244.google.com with SMTP id m12so6223688wrm.13 for ; Thu, 08 Mar 2018 08:15:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=PIkpcKvAVBUOl5mkQXfnolAtHO4Cn+gnuwVjRP3tzKM=; b=JDHctmay+hGnTHEh5H6x2ynv7a/4LIQP1uctmNjuoB7JSYHxGEW7oCjr0s5IpEaDL+ ShVqtboCAU4qUj4AJYH0juoiOP3v+rMPeiEXr1n8zMlkHQUWY3a+f9O07MmHHMNMnnPR nwnr/kqxA/mF95f1NUlm2JcmO6MbJg5lw/4qAHvvYKe3Qc94ow7QvOqrgAcbDyLUWXUc lCfarG7+BQ973ivM9FHl74LO+Z4BZJUnBl5YmsxXKi+COkANOzrij+rDpwBvuIJuNx+4 33/CM++sp9YpnXPZq6DIJxjnFovzthfAFZZnCRPt5j4M2WTb5NW6ALxbZmEUSCTRMhOK +6VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=PIkpcKvAVBUOl5mkQXfnolAtHO4Cn+gnuwVjRP3tzKM=; b=EkIvsLNip3tIRJFZdNfLm21gPPcHyPVHDvT1sCXV+DQfWMjBjXp4DJqt/EyHmcls65 892aOcZO9tiKmOU0YK2rB1MnCJtknUciAN7dgDShtLDNoOcBdYKCj9Y8m+9g52Vi9/TH u11ACo+A4aaWb4lDeqlY4XSgYjXDwdVZXb38vnuRS2O8bjzwSDdzMxocmUwuAtIyEyBT t6k/8sdaNRGlQPYq4/n++Qq6KkQVVf3qNnR7cDH3A03vdkr51AFEfL6MdNUcmeQ3NGi7 2xU9gmUrbfCa5bT/U5LlDVAa2WnGF5tUkD1Y5bd09vQFRJ1dEd630VIhF5qhSjxht6kH oHSQ== X-Gm-Message-State: APf1xPBVtvL0MI0jmLBbZlRhxYV4iNEgF9Rxl6H/3pIbaByvnmk9bpij eBhs9PvMqh+EDd+ltBmCbA0IGibK X-Google-Smtp-Source: AG47ELuKP9WtYzHzyQbUsOtzBT176QUAguDXAdCPByjF4A2c1Y7EI02Jey1y7hXlj7Sm2IoYIAfMWA== X-Received: by 10.223.139.88 with SMTP id v24mr20975012wra.44.1520525718544; Thu, 08 Mar 2018 08:15:18 -0800 (PST) Received: from new-host.redhat.com (net-188-218-15-74.cust.vodafonedsl.it. [188.218.15.74]) by smtp.gmail.com with ESMTPSA id v75sm46510010wrb.76.2018.03.08.08.15.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Mar 2018 08:15:17 -0800 (PST) From: Davide Caratti To: hostap@lists.infradead.org Subject: [PATCH] wpa_supplicant: fix 2 memory leaks in ieee802_1x_create_preshared_mka() Date: Thu, 8 Mar 2018 17:15:02 +0100 Message-Id: <3db3d40417d4190ee071fb858e4d77834f3f709e.1520524691.git.davide.caratti@gmail.com> X-Mailer: git-send-email 2.14.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180308_081531_839288_384DBABC X-CRM114-Status: GOOD ( 12.50 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c0c:0:0:0:244 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (davide.caratti[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: j@w1.fi, sd@queasysnail.net MIME-Version: 1.0 Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org in case MKA is initialized successfully, local copies of CAK and CKN are allocated, but never freed: ensure that such memory is released also when ieee802_1x_kay_create_mka() returns a valid pointer. Fixes: ad51731abf06 ("wpa_supplicant: Allow pre-shared (CAK,CKN) pair for MKA") Signed-off-by: Davide Caratti --- wpa_supplicant/wpas_kay.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/wpa_supplicant/wpas_kay.c b/wpa_supplicant/wpas_kay.c index 11708b8a6..d3d06b8ae 100644 --- a/wpa_supplicant/wpas_kay.c +++ b/wpa_supplicant/wpas_kay.c @@ -392,25 +392,25 @@ void * ieee802_1x_create_preshared_mka(struct wpa_supplicant *wpa_s, { struct mka_key *cak; struct mka_key_name *ckn; - void *res; + void *res = NULL; if ((ssid->mka_psk_set & MKA_PSK_SET) != MKA_PSK_SET) - return NULL; - - if (ieee802_1x_alloc_kay_sm(wpa_s, ssid) < 0) - return NULL; - - if (!wpa_s->kay || wpa_s->kay->policy == DO_NOT_SECURE) - return NULL; + goto end; ckn = os_zalloc(sizeof(*ckn)); if (!ckn) - goto dealloc; + goto end; cak = os_zalloc(sizeof(*cak)); if (!cak) goto free_ckn; + if (ieee802_1x_alloc_kay_sm(wpa_s, ssid) < 0 || !wpa_s->kay) + goto free_cak; + + if (wpa_s->kay->policy == DO_NOT_SECURE) + goto dealloc; + cak->len = MACSEC_CAK_LEN; os_memcpy(cak->key, ssid->mka_cak, cak->len); @@ -419,17 +419,15 @@ void * ieee802_1x_create_preshared_mka(struct wpa_supplicant *wpa_s, res = ieee802_1x_kay_create_mka(wpa_s->kay, ckn, cak, 0, PSK, FALSE); if (res) - return res; + goto free_cak; +dealloc: /* Failed to create MKA */ + ieee802_1x_dealloc_kay_sm(wpa_s); +free_cak: os_free(cak); - - /* fallthrough */ - free_ckn: os_free(ckn); -dealloc: - ieee802_1x_dealloc_kay_sm(wpa_s); - - return NULL; +end: + return res; }