From patchwork Wed Nov 1 11:03:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffan Karger X-Patchwork-Id: 42 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director6.mail.ord1d.rsapps.net ([172.28.255.1]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id a2cUDfFE+lkYVAAAgoeIoA for ; Wed, 01 Nov 2017 18:04:33 -0400 Received: from proxy2.mail.ord1c.rsapps.net ([172.28.255.1]) by director6.mail.ord1d.rsapps.net (Dovecot) with LMTP id OZ4CAvFE+lkAWwAAhgvE6Q ; Wed, 01 Nov 2017 18:04:33 -0400 Received: from smtp49.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy2.mail.ord1c.rsapps.net (Dovecot) with LMTP id UemgB/FE+lndMwAA311kuQ ; Wed, 01 Nov 2017 18:04:33 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-MessageSniffer-Scan-Result: 0 X-MessageSniffer-Rules: 0-298-1160-1376-w 0-298-1160-1740-w 0-298-0-12104-f X-CMAE-Scan-Result: 0 X-CNFS-Analysis: v=2.2 cv=PMJNwriC c=1 sm=1 tr=0 a=Q8DxjiC8O3VT/NpP1XjEZQ==:117 a=Q8DxjiC8O3VT/NpP1XjEZQ==:17 a=kj9zAlcOel0A:10 a=xqWC_Br6kY4A:10 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=sC3jslCIGhcA:10 a=9hBjR9qptiMA:10 a=WiVod9pSvdkA:10 a=ZZnuYtJkoWoA:10 a=Y4BXLp1PAAAA:8 a=9sSjY8p1AAAA:8 a=P_JWiMecAAAA:8 a=FP58Ms26AAAA:8 a=uJGzZxpayXJC9IAXop8A:9 a=CjuIK1q_8ugA:10 a=-FEs8UIgK8oA:10 a=NWVoK91CQyQA:10 a=byfke0vc68LhOSAAcvKj:22 a=ub54wNWiXv_DzeFsgEJW:22 a=D0-HAvA3Hk9NMREbgwuX:22 X-Orig-To: justin@openvpn.net X-Originating-Ip: [216.34.181.88] Authentication-Results: smtp49.gate.ord1c.rsapps.net; iprev=pass policy.iprev="216.34.181.88"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=karger-me.20150623.gappssmtp.com; dmarc=none (p=nil; dis=none) header.from=karger.me X-Classification-ID: a3b8a3e8-bf50-11e7-b82e-b8ca3a5bc230-1-1 Received: from [216.34.181.88] ([216.34.181.88:3386] helo=lists.sourceforge.net) by smtp49.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id F5/49-34177-0F44AF95; Wed, 01 Nov 2017 18:04:32 -0400 Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1eA17E-0003OJ-5D; Wed, 01 Nov 2017 22:04:04 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtps (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.89) (envelope-from ) id 1eA179-0003O3-IK for openvpn-devel@lists.sourceforge.net; Wed, 01 Nov 2017 22:03:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=aMJ2Y6M8r8w7WVCYWZSUzJYp0ncossrdtVhX1x/hV94=; b=mx3RzRWTbss/G2nzvHZOcqfr6W3HEY4p1Mn1N5YOcGg6FukWMwHcdPCRKJ5WGwV9ud2NrYXpXZAD7vsQSZovJui27w/feXPfMhD/CGyce1JTH9YOLXf3A8zIzr0FJg85asC+2hn3PokdcWsJgNIthgWhOKfGucjtRzve4GPofBo=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=aMJ2Y6M8r8w7WVCYWZSUzJYp0ncossrdtVhX1x/hV94=; b=UFef3b2emnuj8fKcOCUz7ltpVVX2CPLJcES+e8OdRByI+kkAf39Ht9+adly5t0zgEDU1IZOtqCUKYavP5LU2/HOT7psr5pwU/PqlDFSDo7INaB2KdqSjC3FIntec5kkRqY0oSV9aluvzFejqc7Ecr+mVwe2KNbQqL1Xy6NP1yLA=; Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of karger.me designates 74.125.82.68 as permitted sender) client-ip=74.125.82.68; envelope-from=steffan@karger.me; helo=mail-wm0-f68.google.com; Received: from mail-wm0-f68.google.com ([74.125.82.68]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1eA178-0008LU-Hd for openvpn-devel@lists.sourceforge.net; Wed, 01 Nov 2017 22:03:59 +0000 Received: by mail-wm0-f68.google.com with SMTP id m72so7337997wmc.1 for ; Wed, 01 Nov 2017 15:03:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=karger-me.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aMJ2Y6M8r8w7WVCYWZSUzJYp0ncossrdtVhX1x/hV94=; b=Fj5h4mE/F1qhL2dbvYojT3qyny70S+COwTDzEX5SxgVcN8ObsDzEwVQY5GFSN+4Sf6 bb8i+PF+tWu86WP72mk/khOHkoGHKFhf+xlcTwdTlWZmzYXVAx2mXyaquKtMr5Dx+o8U N9kAQRM56J9kNyEtuBV+yJcYr7lQihzMzvYIW0kUq1chW/cj15n8h7duTYOTrRddISHC pib8PA8HizQFVZr9MiLizyM0NeUOTxm4XGDm8CAV6d3c/Xie+sJon/THnHielVygD8JR DVInsFE3vL6ufsJ29TzEKpfzbOkE/ZOvaRlYeyWUUjkbQHH96pTtbYn4Z3FoUsm3HOMG CXlg== 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:in-reply-to :references; bh=aMJ2Y6M8r8w7WVCYWZSUzJYp0ncossrdtVhX1x/hV94=; b=SEcZ1N/D8Ab96MCzqE343H6SBaLpgqdTU5uiBoenan9wh8l57WFEbklwmVnVDwP61v W2y2NXVdjxjVCf/EUpIoIeOJTFn++aOkHOzg87I4zzcMmRkZZyojNTukqJdqqCcXzRfs Q51xRBm1AssJiIDGJYjloS7oR1dFlblOn6ZUv4Vk6+ODUMxgK96k/2F67Z8oTEEGxj3G ysPuCpUPFN5+QqNlYVVHr3qcCTvQ41gmsqA8InfaFMkvNWrUdx5vbW1AMWg2fI54Aluv s66b3nCwsfKqPvIxL8w4EjwibUep9iR81QP8OlJmu4yQD4d5wNcMzWf777xj7AMRLJE2 MgeA== X-Gm-Message-State: AMCzsaXwWjvceZQmziEJNvUMwnWYCNCIu+apmYGfXhz6LKi95mObvl8c xYiRn/Kh09erDjv98JcbsGuHPBDVJjM= X-Google-Smtp-Source: ABhQp+RWrvWhRUC1EC8iA66uC0vM0aXj+MLTS1KWH5vBlCgylcswsfB5d2O+yq9MXlqiomYeipz07Q== X-Received: by 10.80.224.7 with SMTP id e7mr1978293edl.117.1509573831696; Wed, 01 Nov 2017 15:03:51 -0700 (PDT) Received: from vesta.fritz.box ([2001:985:e54:1:f834:91b2:a7cf:128b]) by smtp.gmail.com with ESMTPSA id f39sm2096642edf.83.2017.11.01.15.03.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Nov 2017 15:03:51 -0700 (PDT) From: Steffan Karger To: openvpn-devel@lists.sourceforge.net Date: Wed, 1 Nov 2017 23:03:39 +0100 Message-Id: <20171101220342.14648-2-steffan@karger.me> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171101220342.14648-1-steffan@karger.me> References: <1505424872-27434-1-git-send-email-steffan.karger@fox-it.com> <20171101220342.14648-1-steffan@karger.me> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [74.125.82.68 listed in list.dnswl.org] 0.5 RCVD_IN_SORBS_SPAM RBL: SORBS: sender is a spam source [74.125.82.68 listed in dnsbl.sorbs.net] -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1eA178-0008LU-Hd Subject: [Openvpn-devel] [PATCH 1/4 v3] pf: clean up temporary files if plugin init fails X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Steffan Karger close_instance() tries to remove the file in c2.pf.filename, but that only works if we actually set that if we fail. So, set that filename as soon as we know we've created the file. Signed-off-by: Steffan Karger Acked-by: Antonio Quartulli --- v2: As suggested by Antionio, get rid of local 'gc' and 'file' vars. v3: make c->c2.pf.filename const (fixes compile warning) src/openvpn/pf.c | 10 ++++------ src/openvpn/pf.h | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/openvpn/pf.c b/src/openvpn/pf.c index 5cb002bf..e1b5b0e7 100644 --- a/src/openvpn/pf.c +++ b/src/openvpn/pf.c @@ -618,19 +618,18 @@ pf_load_from_buffer_list(struct context *c, const struct buffer_list *config) void pf_init_context(struct context *c) { - struct gc_arena gc = gc_new(); #ifdef PLUGIN_PF if (plugin_defined(c->plugins, OPENVPN_PLUGIN_ENABLE_PF)) { - const char *pf_file = create_temp_file(c->options.tmp_dir, "pf", &gc); - if (pf_file) + c->c2.pf.filename = create_temp_file(c->options.tmp_dir, "pf", + &c->c2.gc); + if (c->c2.pf.filename) { - setenv_str(c->c2.es, "pf_file", pf_file); + setenv_str(c->c2.es, "pf_file", c->c2.pf.filename); if (plugin_call(c->plugins, OPENVPN_PLUGIN_ENABLE_PF, NULL, NULL, c->c2.es) == OPENVPN_PLUGIN_FUNC_SUCCESS) { event_timeout_init(&c->c2.pf.reload, 1, now); - c->c2.pf.filename = string_alloc(pf_file, &c->c2.gc); c->c2.pf.enabled = true; #ifdef ENABLE_DEBUG if (check_debug_level(D_PF_DEBUG)) @@ -658,7 +657,6 @@ pf_init_context(struct context *c) #endif } #endif - gc_free(&gc); } void diff --git a/src/openvpn/pf.h b/src/openvpn/pf.h index 414c85b8..b839fd2e 100644 --- a/src/openvpn/pf.h +++ b/src/openvpn/pf.h @@ -75,7 +75,7 @@ struct pf_context { bool enabled; struct pf_set *pfs; #ifdef PLUGIN_PF - char *filename; + const char *filename; time_t file_last_mod; unsigned int n_check_reload; struct event_timeout reload; From patchwork Wed Nov 1 11:03:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffan Karger X-Patchwork-Id: 43 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director1.mail.ord1d.rsapps.net ([172.28.255.1]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id rMEdEvFE+lltKAAAgoeIoA for ; Wed, 01 Nov 2017 18:04:33 -0400 Received: from proxy2.mail.ord1c.rsapps.net ([172.28.255.1]) by director1.mail.ord1d.rsapps.net (Dovecot) with LMTP id v2WnEPFE+llafQAANGzteQ ; Wed, 01 Nov 2017 18:04:33 -0400 Received: from smtp49.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy2.mail.ord1c.rsapps.net (Dovecot) with LMTP id U+mgB/FE+lndMwAA311kuQ ; Wed, 01 Nov 2017 18:04:33 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-MessageSniffer-Scan-Result: 0 X-MessageSniffer-Rules: 0-298-1117-1329-w 0-298-1117-1693-w 0-298-0-9868-f X-CMAE-Scan-Result: 0 X-CNFS-Analysis: v=2.2 cv=PMJNwriC c=1 sm=1 tr=0 a=Q8DxjiC8O3VT/NpP1XjEZQ==:117 a=Q8DxjiC8O3VT/NpP1XjEZQ==:17 a=kj9zAlcOel0A:10 a=xqWC_Br6kY4A:10 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=sC3jslCIGhcA:10 a=9hBjR9qptiMA:10 a=WiVod9pSvdkA:10 a=ZZnuYtJkoWoA:10 a=9sSjY8p1AAAA:8 a=P_JWiMecAAAA:8 a=FP58Ms26AAAA:8 a=wMpPiceOs-SDPOSKYq4A:9 a=CjuIK1q_8ugA:10 a=-FEs8UIgK8oA:10 a=NWVoK91CQyQA:10 a=ub54wNWiXv_DzeFsgEJW:22 a=D0-HAvA3Hk9NMREbgwuX:22 X-Orig-To: justin@openvpn.net X-Originating-Ip: [216.34.181.88] Authentication-Results: smtp49.gate.ord1c.rsapps.net; iprev=pass policy.iprev="216.34.181.88"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=karger-me.20150623.gappssmtp.com; dmarc=none (p=nil; dis=none) header.from=karger.me X-Classification-ID: a4593e66-bf50-11e7-b82e-b8ca3a5bc230-1-1 Received: from [216.34.181.88] ([216.34.181.88:32584] helo=lists.sourceforge.net) by smtp49.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 18/49-34177-1F44AF95; Wed, 01 Nov 2017 18:04:33 -0400 Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1eA17C-0000Aj-MN; Wed, 01 Nov 2017 22:04:02 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtps (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.89) (envelope-from ) id 1eA17A-0000AI-8Q for openvpn-devel@lists.sourceforge.net; Wed, 01 Nov 2017 22:04:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=OnGj6IYokGDc8ONcdoDtGKVKSGdr+kVRrPnNW/Q9dZw=; b=B+FwJgIqEk2QfrNXerljY04hVhEbpsdqqVzKFuMg3Wq5YiGiN2qfmFjoQJgJotICbO0IN15ddTjYuBUpI0qjW2rlKbdTST2so6FnD0oG7n6Re5DaHQyAE7sMqN8XuOzMn8GzpGMnHJBCx9/skXqZUNYx2XKeXpgyMVkp6YGmRzc=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=OnGj6IYokGDc8ONcdoDtGKVKSGdr+kVRrPnNW/Q9dZw=; b=EFmJ/6gB8zi2/YDxMkJvjzqot+q+F9zjfSMtVUBUY70xjYl9RfMrfJf+mygTagT3QSmKAqfnZ+z3fLGhPsODzoCX5PbPet3EmGvI7KqEgAWWGAN3PXTfmRMwsClDP7K6SNh5ftqJ0UabY6fFIgmcdCsy1RX65OYxtwKrS055ndo=; Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of karger.me designates 74.125.82.65 as permitted sender) client-ip=74.125.82.65; envelope-from=steffan@karger.me; helo=mail-wm0-f65.google.com; Received: from mail-wm0-f65.google.com ([74.125.82.65]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1eA179-0007f2-4A for openvpn-devel@lists.sourceforge.net; Wed, 01 Nov 2017 22:04:00 +0000 Received: by mail-wm0-f65.google.com with SMTP id b189so7246941wmd.4 for ; Wed, 01 Nov 2017 15:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=karger-me.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OnGj6IYokGDc8ONcdoDtGKVKSGdr+kVRrPnNW/Q9dZw=; b=QtdjC61rxobUuzm3mizpwUwGR/0HE7Ip0HD/ObY4SqwMYf4FZWB1YBYxPcGWplA+x4 iXQJAJA74mKxItVvxJ37ciC8HifVPNEcbmdPh3nvm7Ldl8efi/+kNQRroy6km3FpIFsU z7eKrbkQpt5gHNWQTgicg0IN96fZk+kvPfiIo1M1FyuSovbuvr2NsBgmrGnf0N0bE2jB CORhbfEScaKpExwsoA2gopjL7qLmSuKLkBbuCou6NJKiRjRTZbKT/U5dvIQpqT5F+08t aGYWmEGSaM5tRDg5oSW3xjWe28/uMUE6qzXSuVLHxxB9XadVccTbmdNWE+ARtfMmS8LV qqSA== 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:in-reply-to :references; bh=OnGj6IYokGDc8ONcdoDtGKVKSGdr+kVRrPnNW/Q9dZw=; b=N5JVcNqG9ETcI81R1duou5+lrGmeZIWzTWYeqiDGGXjxImTfP/nQGxDJc7Nc3Xus0o yvdW/foSrH4qyjIyS4dA6NalRXRj2qo8sQH5Mqew3QU40JLnzloNTuX4fynXyLeye2uO URGmWQ86C4yhBU1x6iI1LS8gSONoMXniZmhMokK23RL/bBzAneNVNhwYXDO3eW6D/3Jm Gni2EDMUB+8+fyzKYfqB2oTEbkn3+ccTsIf9ueXl4gysYMxegVwdhxnWLk7WqlY/1xPB tvceIjyTk+VnWV2X4xW7cDPzkvSkNx/grWg0wH8ymSaB/P5YEzY9Xt4o3k2UBVNh+wm0 OUWg== X-Gm-Message-State: AMCzsaVCm7h9uzFSL3T0ZpCiJvTkWxt2WZCuXiMlSVpVNpjr8H6QKn0M Jd9gDqc2m5X5cDdwEDAXrP7dNIbwoOs= X-Google-Smtp-Source: ABhQp+SqEQ3iOzu3F6cT6FYP55F5KXMVN0aVz7Nitcp9G6WTPb5wQQHL0MhbBvUGUPQZ/C8JCnZ+2Q== X-Received: by 10.80.145.6 with SMTP id e6mr1970622eda.34.1509573832520; Wed, 01 Nov 2017 15:03:52 -0700 (PDT) Received: from vesta.fritz.box ([2001:985:e54:1:f834:91b2:a7cf:128b]) by smtp.gmail.com with ESMTPSA id f39sm2096642edf.83.2017.11.01.15.03.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Nov 2017 15:03:51 -0700 (PDT) From: Steffan Karger To: openvpn-devel@lists.sourceforge.net Date: Wed, 1 Nov 2017 23:03:40 +0100 Message-Id: <20171101220342.14648-3-steffan@karger.me> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171101220342.14648-1-steffan@karger.me> References: <1505424872-27434-1-git-send-email-steffan.karger@fox-it.com> <20171101220342.14648-1-steffan@karger.me> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.5 RCVD_IN_SORBS_SPAM RBL: SORBS: sender is a spam source [74.125.82.65 listed in dnsbl.sorbs.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [74.125.82.65 listed in list.dnswl.org] -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1eA179-0007f2-4A Subject: [Openvpn-devel] [PATCH 2/4 v2] pf: reject client if PF plugin is configured, but init fails X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox This changes the behavior for pf plugins: instead of just not initializing the firewall rules and happily continuing, this now rejects the client in the case of an (unlikely) failure to initialize the pf. Signed-off-by: Steffan Karger Acked-by: Antonio Quartulli --- v3: return immediately after registering signal src/openvpn/pf.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/openvpn/pf.c b/src/openvpn/pf.c index e1b5b0e7..6e4107c5 100644 --- a/src/openvpn/pf.c +++ b/src/openvpn/pf.c @@ -638,10 +638,12 @@ pf_init_context(struct context *c) } #endif } - else - { - msg(M_WARN, "WARNING: OPENVPN_PLUGIN_ENABLE_PF disabled"); - } + } + if (!c->c2.pf.enabled) + { + msg(M_WARN, "WARNING: failed to init PF plugin, rejecting client."); + register_signal(c, SIGUSR1, "plugin-pf-init-failed"); + return; } } #endif /* ifdef PLUGIN_PF */ From patchwork Wed Nov 1 11:03:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffan Karger X-Patchwork-Id: 44 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director3.mail.ord1d.rsapps.net ([172.30.191.6]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id awuDBPJE+lkeJgAAgoeIoA for ; Wed, 01 Nov 2017 18:04:34 -0400 Received: from proxy10.mail.ord1d.rsapps.net ([172.30.191.6]) by director3.mail.ord1d.rsapps.net (Dovecot) with LMTP id hUXYAvJE+lkxZQAAkXNnRw ; Wed, 01 Nov 2017 18:04:34 -0400 Received: from smtp4.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy10.mail.ord1d.rsapps.net (Dovecot) with LMTP id IM07BPJE+lmoEwAAfSg8FQ ; Wed, 01 Nov 2017 18:04:34 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: justin@openvpn.net X-Originating-Ip: [216.34.181.88] Authentication-Results: smtp4.gate.ord1d.rsapps.net; iprev=pass policy.iprev="216.34.181.88"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=karger-me.20150623.gappssmtp.com; dmarc=none (p=nil; dis=none) header.from=karger.me X-Classification-ID: a45f3a82-bf50-11e7-b327-525400760ffc-1-1 Received: from [216.34.181.88] ([216.34.181.88:37288] helo=lists.sourceforge.net) by smtp4.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id C1/B2-25778-1F44AF95; Wed, 01 Nov 2017 18:04:33 -0400 Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1eA17F-0000BK-Re; Wed, 01 Nov 2017 22:04:05 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtps (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.89) (envelope-from ) id 1eA17C-0000Ac-46 for openvpn-devel@lists.sourceforge.net; Wed, 01 Nov 2017 22:04:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ZOqesW2WDJfln40AlroGdjQhBvP4pbZ9feRvQRz9J5I=; b=YriswueKDpYBBZOPBQzIvCVzOFdtjfyNvkdtG3a5A9MsrqECzv9xdmqIoWW6sxVf7LdUrTEPEPVg8nE5/yacJYGaI1gjb3SvXYsb7Cir/uxd4B9Zw/q9PMTZmCM+wwrshSzyUtBNWORL0oS5ltRbp4maBqwQmr2mvqGEgh95VYA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ZOqesW2WDJfln40AlroGdjQhBvP4pbZ9feRvQRz9J5I=; b=ItXOrg2V+Gi8+5V0nRcF3rU3HOytWzY1PPakFcgURVGekCoEkQ3zdB4awHCOzJSzALW61ifZ24VA6bQzJfnaROQAdR7ISVHLkOkX3FGRokQgEyRRiZXf4X29bmFffOuXEC172vaPhn3dlwWSVA7gBPi6hv5rR4R64IV31FGEjW0=; Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of karger.me designates 74.125.82.66 as permitted sender) client-ip=74.125.82.66; envelope-from=steffan@karger.me; helo=mail-wm0-f66.google.com; Received: from mail-wm0-f66.google.com ([74.125.82.66]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1eA17A-00063c-6A for openvpn-devel@lists.sourceforge.net; Wed, 01 Nov 2017 22:04:02 +0000 Received: by mail-wm0-f66.google.com with SMTP id r196so7532250wmf.2 for ; Wed, 01 Nov 2017 15:03:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=karger-me.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZOqesW2WDJfln40AlroGdjQhBvP4pbZ9feRvQRz9J5I=; b=ObyceAVcmGR8zVCykijVow83F214KDgZkT56mFcfN9oElNTdPrnsR3+enCJtblo1eq 85nwfEWR0md5Kpsg+3LZq3nf35slk6LD47zIxFLx247NtT5V4ACqLMXOkvVlXfgrAvfR YqoPXs4J5v14jQdKmNnftz/RvG+u4KO3z/1DHNL/idlzqR2/K3pNan59KAheWvwwakkr XcE2/p18yaKVeYLpDIKtTDB6StZXJ1tpvrVdY8rIRda316tjDN4iYWnphN8vYq5K/kHd g4AmMWmH4Bq93TCTIhL9y3ic8h+Bn/gipYvm9+YIQrIJM71oW7fWUzZoIARsurrd2xRl HoTA== 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:in-reply-to :references; bh=ZOqesW2WDJfln40AlroGdjQhBvP4pbZ9feRvQRz9J5I=; b=SHZlc/JYsG1XXwZHUjsPzdm5R2WpdZlKJ13JELKha5DDTdDK+NkT59f6gbXg3p92EJ e901rB3AFohnW4pIQrVjMmqWrVNwglyqGsWuR6JHacd8cHpGo0o3G9O+ieitXjVgq5Vr dS0QL6TM2WSIleinSJWPNbqi/+Pvg7tPpO0xXk5P+3jPa2UV6hBAIHDuPBC0ttxI+zgJ gL+O7TRpuBCivKz6DqCF3+NaT/vCnAaetGkkL4FHTe1615YwQm9RuBRWcGe6+al8M6DW IwFTbegSEdtGZHwMX69lEFYHP8D/JPpO1u0MXr1/CsEWtBiFBZTq7eVHJXR42kwz4Y40 KtQg== X-Gm-Message-State: AMCzsaUlSc38KXI+VJgl9zDEFQZ3rsRNHPZYfUU+PkuLUuho25sC0BtC srOIcVoHDI0JmoJ5nxRKwCaexYhkYl8= X-Google-Smtp-Source: ABhQp+QMiyFxang7bRmng8Tj4ZCboZd1OGHz7G6BYREvQXjftI0DWRM3VIk58GFWWZ5NfPWnZ3tNfA== X-Received: by 10.80.136.4 with SMTP id b4mr1927654edb.155.1509573833344; Wed, 01 Nov 2017 15:03:53 -0700 (PDT) Received: from vesta.fritz.box ([2001:985:e54:1:f834:91b2:a7cf:128b]) by smtp.gmail.com with ESMTPSA id f39sm2096642edf.83.2017.11.01.15.03.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Nov 2017 15:03:52 -0700 (PDT) From: Steffan Karger To: openvpn-devel@lists.sourceforge.net Date: Wed, 1 Nov 2017 23:03:41 +0100 Message-Id: <20171101220342.14648-4-steffan@karger.me> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171101220342.14648-1-steffan@karger.me> References: <1505424872-27434-1-git-send-email-steffan.karger@fox-it.com> <20171101220342.14648-1-steffan@karger.me> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [74.125.82.66 listed in list.dnswl.org] -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.5 RCVD_IN_SORBS_SPAM RBL: SORBS: sender is a spam source [74.125.82.66 listed in dnsbl.sorbs.net] -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1eA17A-00063c-6A Subject: [Openvpn-devel] [PATCH 3/4 v2] Don't throw fatal errors from create_temp_file() X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Steffan Karger This function is called in response to connecting clients, and can fail when I/O fails for some (possibly temporary) reason. In such cases we should not exit the process, but just reject the connecting client. This commit changes the function to actually return NULL on errors, and (where needed) changes the callers to check for and handle errors. Since the tls-crypt-v2 metadata code also calls create_temp_file() when clients connect, I consider this a prerequisite for tls-crypt-v2. Signed-off-by: Steffan Karger Acked-by: Antonio Quartulli --- v2: put || at the beginning of a line (not the end) src/openvpn/misc.c | 6 +++--- src/openvpn/ssl_verify.c | 32 +++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index 8c7f6116..25f38003 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -740,7 +740,7 @@ create_temp_file(const char *directory, const char *prefix, struct gc_arena *gc) retfname = gen_path(directory, BSTR(&fname), gc); if (!retfname) { - msg(M_FATAL, "Failed to create temporary filename and path"); + msg(M_WARN, "Failed to create temporary filename and path"); return NULL; } @@ -755,14 +755,14 @@ create_temp_file(const char *directory, const char *prefix, struct gc_arena *gc) else if (fd == -1 && errno != EEXIST) { /* Something else went wrong, no need to retry. */ - msg(M_FATAL | M_ERRNO, "Could not create temporary file '%s'", + msg(M_WARN | M_ERRNO, "Could not create temporary file '%s'", retfname); return NULL; } } while (attempts < 6); - msg(M_FATAL, "Failed to create temporary file after %i attempts", attempts); + msg(M_WARN, "Failed to create temporary file after %i attempts", attempts); return NULL; } diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index 9cd36d7a..de54fb74 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -547,14 +547,14 @@ verify_cert_export_cert(openvpn_x509_cert_t *peercert, const char *tmp_dir, stru FILE *peercert_file; const char *peercert_filename = ""; - if (!tmp_dir) + /* create tmp file to store peer cert */ + if (!tmp_dir + || !(peercert_filename = create_temp_file(tmp_dir, "pcf", gc))) { + msg (M_WARN, "Failed to create peer cert file"); return NULL; } - /* create tmp file to store peer cert */ - peercert_filename = create_temp_file(tmp_dir, "pcf", gc); - /* write peer-cert in tmp-file */ peercert_file = fopen(peercert_filename, "w+"); if (!peercert_file) @@ -589,10 +589,13 @@ verify_cert_call_command(const char *verify_command, struct env_set *es, if (verify_export_cert) { - if ((tmp_file = verify_cert_export_cert(cert, verify_export_cert, &gc))) + tmp_file = verify_cert_export_cert(cert, verify_export_cert, &gc); + if (!tmp_file) { - setenv_str(es, "peer_cert", tmp_file); + ret = false; + goto cleanup; } + setenv_str(es, "peer_cert", tmp_file); } argv_parse_cmd(&argv, verify_command); @@ -609,6 +612,7 @@ verify_cert_call_command(const char *verify_command, struct env_set *es, } } +cleanup: gc_free(&gc); argv_reset(&argv); @@ -879,21 +883,21 @@ key_state_rm_auth_control_file(struct key_state *ks) } } -static void +static bool key_state_gen_auth_control_file(struct key_state *ks, const struct tls_options *opt) { struct gc_arena gc = gc_new(); - const char *acf; key_state_rm_auth_control_file(ks); - acf = create_temp_file(opt->tmp_dir, "acf", &gc); + const char *acf = create_temp_file(opt->tmp_dir, "acf", &gc); if (acf) { ks->auth_control_file = string_alloc(acf, NULL); setenv_str(opt->es, "auth_control_file", ks->auth_control_file); - } /* FIXME: Should have better error handling? */ + } gc_free(&gc); + return acf; } static unsigned int @@ -1184,7 +1188,12 @@ verify_user_pass_plugin(struct tls_session *session, const struct user_pass *up, #ifdef PLUGIN_DEF_AUTH /* generate filename for deferred auth control file */ - key_state_gen_auth_control_file(ks, session->opt); + if (!key_state_gen_auth_control_file(ks, session->opt)) + { + msg (D_TLS_ERRORS, "TLS Auth Error (%s): " + "could not create deferred auth control file", __func__); + goto cleanup; + } #endif /* call command */ @@ -1209,6 +1218,7 @@ verify_user_pass_plugin(struct tls_session *session, const struct user_pass *up, msg(D_TLS_ERRORS, "TLS Auth Error (verify_user_pass_plugin): peer provided a blank username"); } +cleanup: return retval; } From patchwork Wed Nov 1 11:03:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffan Karger X-Patchwork-Id: 41 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director6.mail.ord1d.rsapps.net ([172.30.191.6]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id rR05BOtE+ll8dwAAgoeIoA for ; Wed, 01 Nov 2017 18:04:27 -0400 Received: from proxy4.mail.ord1d.rsapps.net ([172.30.191.6]) by director6.mail.ord1d.rsapps.net (Dovecot) with LMTP id Ib6FHOtE+lmrbwAAhgvE6Q ; Wed, 01 Nov 2017 18:04:27 -0400 Received: from smtp50.gate.ord1c ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy4.mail.ord1d.rsapps.net (Dovecot) with LMTP id g69+FetE+lmXKgAAiYrejw ; Wed, 01 Nov 2017 18:04:27 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-MessageSniffer-Scan-Result: 0 X-MessageSniffer-Rules: 0-298-1118-1327-w 0-298-1118-1691-w 0-298-0-11882-f X-CMAE-Scan-Result: 0 X-CNFS-Analysis: v=2.2 cv=V4w/6qvi c=1 sm=1 tr=0 a=Q8DxjiC8O3VT/NpP1XjEZQ==:117 a=Q8DxjiC8O3VT/NpP1XjEZQ==:17 a=kj9zAlcOel0A:10 a=xqWC_Br6kY4A:10 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=sC3jslCIGhcA:10 a=9hBjR9qptiMA:10 a=WiVod9pSvdkA:10 a=ZZnuYtJkoWoA:10 a=9sSjY8p1AAAA:8 a=P_JWiMecAAAA:8 a=FP58Ms26AAAA:8 a=avj4neX-z-FaSJBd_tMA:9 a=CjuIK1q_8ugA:10 a=-FEs8UIgK8oA:10 a=NWVoK91CQyQA:10 a=ub54wNWiXv_DzeFsgEJW:22 a=D0-HAvA3Hk9NMREbgwuX:22 X-Orig-To: justin@openvpn.net X-Originating-Ip: [216.34.181.88] Authentication-Results: smtp50.gate.ord1c.rsapps.net; iprev=pass policy.iprev="216.34.181.88"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=karger-me.20150623.gappssmtp.com; dmarc=none (p=nil; dis=none) header.from=karger.me X-Classification-ID: a0590f4e-bf50-11e7-b77f-b8ca3a659864-1-1 Received: from [216.34.181.88] ([216.34.181.88:32504] helo=lists.sourceforge.net) by smtp50.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 87/87-18157-AE44AF95; Wed, 01 Nov 2017 18:04:26 -0400 Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1eA17C-0000As-Oy; Wed, 01 Nov 2017 22:04:02 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtps (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.89) (envelope-from ) id 1eA17B-0000AW-Le for openvpn-devel@lists.sourceforge.net; Wed, 01 Nov 2017 22:04:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=8n5OBZONiUJXnkNFVJ1GtvPCGGjr/Hbvqash5R9Qmh8=; b=fUw6P5GWD0gfPVv9qNQ3FIDXhftBoTtONqZieAz2JRr2hZfooTGZlcVbb9c8KLr8r9KnHpQBTEQSmguFiquQKRsXsYeubbGywReIV5TKrzi61w5l52FvmL11tCo4R74eZS2hFmLkFghgxvDSoOtoX6BzTa01dLs2Ab9NePp6XzQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=8n5OBZONiUJXnkNFVJ1GtvPCGGjr/Hbvqash5R9Qmh8=; b=VnHOnuAaGPjiO7qcfkeB/gXVGNuctqVEGYZM0Pz2j1A9jUiB0XwVB+IpmBednWXGz+gG0GQ6liOw5fEAYgE87g7r++73OKP8HoiAcP4uI90bg8bNlsCtg92Fx8PrG/2tjFqYijU5q3cPj8gG9C2axOgBumFBQtGiBXWCIli5Y8Y=; Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of karger.me designates 74.125.82.67 as permitted sender) client-ip=74.125.82.67; envelope-from=steffan@karger.me; helo=mail-wm0-f67.google.com; Received: from mail-wm0-f67.google.com ([74.125.82.67]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1eA17A-00063d-I2 for openvpn-devel@lists.sourceforge.net; Wed, 01 Nov 2017 22:04:01 +0000 Received: by mail-wm0-f67.google.com with SMTP id z3so7497127wme.5 for ; Wed, 01 Nov 2017 15:04:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=karger-me.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8n5OBZONiUJXnkNFVJ1GtvPCGGjr/Hbvqash5R9Qmh8=; b=ozzztnHdwq+4Sr9x2luRxlGFlNHpNBAGuUewunSy+oCmOi1oEmStdkEnRL79OhhQN6 xzawkq+S/UHO9ql+q5qYX6m4yNKXHlraPPdE1nc8RsyR4+TqeKZjiBlgmOCk5yQsf4z/ L0IdiWfAZjf4TIO8jlw6Ibh9K03vum72z+1WdUIosFjOVjrPMKcyazYQniw1pLIT+Htr mVV5QrHUUQGuF2U/JUmrylUlpsaTJsYV6YxYBjqY0d7H2iebUNr0r19J5ZFw/QOmw/qu KSHriEB9Oq1K04rKg4aYdyq2CDuJ3nyYc4hvfcXlrw40kPtynHGS8D6IDEtTrBNu74ml 28Rw== 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:in-reply-to :references; bh=8n5OBZONiUJXnkNFVJ1GtvPCGGjr/Hbvqash5R9Qmh8=; b=s8o4dKWY2Az3PhX0tviGHDIWrkkObMF6AJH4tpWyTj0JR1SAPi44GhmD6ZuyTZcf2A Sm3xEjjkcpSqpdrNNsXHQq665L/yy85tkS0nhXocd75CpFjUVuNe1VLWUd7p9XdLqzgU 3wpLiCSkjd9Wyq7IKycfAtlZN8g6/o7d/O7l16BpjV2u3H1MmEBKdLoPxymLn0MjqN8W wToquGsftwe8+XiMET7dYQk9wP+9GdQCpCogmFqivLIwo3LTUV6+fDwG18lPhoUb4muv i5ykEJa4BNGqx75e2MCZ1FANwN6iUbK+znme0s5b6lbhvm1JOP7ZbnmDAvFO7/ylNM26 IyOg== X-Gm-Message-State: AMCzsaWfy0if2LbdtQqMEaeoeGE6k2+BkF/jmFVUuunWnZDn4EmGviIj LH/ZCyLHz2YjFx7Zc6uWUyfsHJ/Zo/Q= X-Google-Smtp-Source: ABhQp+SZfjtMIifC37kHL94UyBg/1h2jUHpOaPAlwjsD0YiP6MGKH/mf7opbijpKmSb14waIlxBa9A== X-Received: by 10.80.205.28 with SMTP id z28mr1941593edi.264.1509573834269; Wed, 01 Nov 2017 15:03:54 -0700 (PDT) Received: from vesta.fritz.box ([2001:985:e54:1:f834:91b2:a7cf:128b]) by smtp.gmail.com with ESMTPSA id f39sm2096642edf.83.2017.11.01.15.03.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Nov 2017 15:03:53 -0700 (PDT) From: Steffan Karger To: openvpn-devel@lists.sourceforge.net Date: Wed, 1 Nov 2017 23:03:42 +0100 Message-Id: <20171101220342.14648-5-steffan@karger.me> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171101220342.14648-1-steffan@karger.me> References: <1505424872-27434-1-git-send-email-steffan.karger@fox-it.com> <20171101220342.14648-1-steffan@karger.me> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.5 RCVD_IN_SORBS_SPAM RBL: SORBS: sender is a spam source [74.125.82.67 listed in dnsbl.sorbs.net] -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [74.125.82.67 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1eA17A-00063d-I2 Subject: [Openvpn-devel] [PATCH 4/4 v3] create_temp_file/gen_path: prevent memory leak if gc == NULL X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox If gc == NULL, the data allocated in the alloc_gc_buf() call in create_temp_file or the string_mod_const call in gen_path would never be free'd. These functions are currently never called that way, but let's prevent future problems. While touching create_temp_file, also remove the counter variable, which is never read, simplify the do-while to a while loop, and truncate the prefix (if needed) to preserve the random and extension of the created filename. Signed-off-by: Steffan Karger Acked-by: Antonio Quartulli --- v2: - change create_temp_file to avoid using a struct buffer (simpler) - add gc != NULL check for gen_path (avoid similar memleak pitfall) v3: - Check the return value of openvpn_snprintf() src/openvpn/misc.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index 25f38003..67011169 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -723,21 +723,26 @@ test_file(const char *filename) const char * create_temp_file(const char *directory, const char *prefix, struct gc_arena *gc) { - static unsigned int counter; - struct buffer fname = alloc_buf_gc(256, gc); int fd; const char *retfname = NULL; unsigned int attempts = 0; + char fname[256] = { 0 }; + const char *fname_fmt = PACKAGE "_%.*s_%08lx%08lx.tmp"; + const int max_prefix_len = sizeof(fname) - (sizeof(PACKAGE) + 7 + (2 * 8)); - do + while (attempts < 6) { ++attempts; - ++counter; - buf_printf(&fname, PACKAGE "_%s_%08lx%08lx.tmp", prefix, - (unsigned long) get_random(), (unsigned long) get_random()); + if (!openvpn_snprintf(fname, sizeof(fname), fname_fmt, max_prefix_len, + prefix, (unsigned long) get_random(), + (unsigned long) get_random())) + { + msg(M_WARN, "ERROR: temporary filename too long"); + return NULL; + } - retfname = gen_path(directory, BSTR(&fname), gc); + retfname = gen_path(directory, fname, gc); if (!retfname) { msg(M_WARN, "Failed to create temporary filename and path"); @@ -760,7 +765,6 @@ create_temp_file(const char *directory, const char *prefix, struct gc_arena *gc) return NULL; } } - while (attempts < 6); msg(M_WARN, "Failed to create temporary file after %i attempts", attempts); return NULL; @@ -812,6 +816,12 @@ gen_path(const char *directory, const char *filename, struct gc_arena *gc) #else const int CC_PATH_RESERVED = CC_SLASH; #endif + + if (!gc) + { + return NULL; /* Would leak memory otherwise */ + } + const char *safe_filename = string_mod_const(filename, CC_PRINT, CC_PATH_RESERVED, '_', gc); if (safe_filename