| Message ID | 20240124152739.28248-1-kprovost@netgate.com |
|---|---|
| State | Accepted |
| Headers |
Return-Path: <openvpn-devel-bounces@lists.sourceforge.net>
Delivered-To: patchwork@openvpn.net
Received: by 2002:a05:7301:3b94:b0:101:b91e:57cc with SMTP id
kh20csp1117355dyb;
Wed, 24 Jan 2024 07:53:40 -0800 (PST)
X-Google-Smtp-Source:
AGHT+IEdKx0FempVC8JlQUKrlxg0jSlOiFOjjga9iSwc8GFbIpCksqcuUXTEXau/fj5wwdM2rVqa
X-Received: by 2002:a05:6a20:d046:b0:199:7546:74b0 with SMTP id
hv6-20020a056a20d04600b00199754674b0mr2408580pzb.5.1706111619823;
Wed, 24 Jan 2024 07:53:39 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1706111619; cv=none;
d=google.com; s=arc-20160816;
b=Q9wkNqWR2j6MHVkjpe/K/PEe4pyTtd80mQLI9uxBt/YUPO7yeHd5F97wvUlOODsqho
GcmjO3gxt+wZ5s16iPZOwZ7Za2DYaFWv22XWbm22Ttt144/c3gQMxJyicNugaQbxhpow
DOupCXGk+IhmIJzVB4r1O7G2OzCldRZXThHQEwzrFoUCr+N677iu0IMSDdIJ35mihy9n
/A7uYeSU7fOEsPaP4RtOOXPHoPiPV0BHE7BQHfNTp46LBkf4G3vlPJ/Vqko1gJhRnRmZ
EcuQ2YyhTEmX9L0bAe7aMlT42riTV9h3/pevlCD7zj/cEF4NTQPrQBUmmBbBtgmvVQuh
lT0Q==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20160816;
h=errors-to:content-transfer-encoding:reply-to:from:list-subscribe
:list-help:list-post:list-archive:list-unsubscribe:list-id
:precedence:subject:mime-version:message-id:date:to:dkim-signature
:dkim-signature:dkim-signature;
bh=xtNORDQTi0YtTQbb+ik35pVFEnSW3CdF4ERLtvScszc=;
fh=UWlByhJXNGJKzcJ5WmyoA1tw5ugXp4S86SRVYqcTfsM=;
b=v2oZ4MR8BoOwud4wLTtuqeI95TNCfM/nm1i/A0ucbcUGZflxRHDpPhaHxWxRJ/Ryfv
kjVkffvdthC/+inajAwygVqcja7zbIl4M1qsc9UHKivAg9a4/M62lO43OAl5HYAnY5ex
bWZVvlxjTrG5Fe6WX8hShlOW8OLYaxrn5c/yHa6k1rxMteL42UmDdPLncyk9brk1/Npl
FvmS7G8tNhLgSU0CpSreGg6UFsrWyJfLHlSEfN6ec//jYpaOEc5O5uHUkz4xPxoIy2sX
usVaCxRjyznN8Elnm5Q++VuMPSA3YExo9ObIi4Xmc8l+1LsNUJ5dXscPW/3DLkf+Ci8F
FReQ==
ARC-Authentication-Results: i=1; mx.google.com;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=YEYqYI8W;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=ehGAcyOr;
dkim=neutral (body hash did not verify) header.i=@netgate.com
header.s=google header.b=dNKu+tNC;
spf=pass (google.com: domain of
openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as
permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net;
dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=sourceforge.net
Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7])
by mx.google.com with ESMTPS id
j5-20020a63cf05000000b005b96d038729si11840498pgg.728.2024.01.24.07.53.39
(version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
Wed, 24 Jan 2024 07:53:39 -0800 (PST)
Received-SPF: pass (google.com: domain of
openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as
permitted sender) client-ip=216.105.38.7;
Authentication-Results: mx.google.com;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=YEYqYI8W;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=ehGAcyOr;
dkim=neutral (body hash did not verify) header.i=@netgate.com
header.s=google header.b=dNKu+tNC;
spf=pass (google.com: domain of
openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as
permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net;
dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=sourceforge.net
Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com)
by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95)
(envelope-from <openvpn-devel-bounces@lists.sourceforge.net>)
id 1rSfYi-0007Rm-Mp;
Wed, 24 Jan 2024 15:53:00 +0000
Received: from [172.30.20.202] (helo=mx.sourceforge.net)
by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95)
(envelope-from <kprovost@netgate.com>) id 1rSfYg-0007Rg-Pv
for openvpn-devel@lists.sourceforge.net;
Wed, 24 Jan 2024 15:52:58 +0000
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-ID:
Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID:
Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
:Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:
List-Subscribe:List-Post:List-Owner:List-Archive;
bh=+Kl9PVffT9IyDQNCc2AxhyGuN2pv3wP+6F5rFxjv2sE=; b=YEYqYI8WaTEwFh4UKvNs5ZX12O
ACaO0dzGbVEVudKsxtpuZMkFt+U/8N2SSHbaWfH8xrHNhhmYn6FHPo8eAgRLJ+YYksQYP7sSkEyDK
LXdk8GAeoIDEpZfpKPLa9uOuMbo7ShQSE5hxW48M/6HaQg15FLc66OW/RglUZW7iXLyw=;
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x
;
h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:To:From:
Sender:Reply-To:Cc:Content-Type:Content-ID:Content-Description:Resent-Date:
Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:
References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:
List-Owner:List-Archive; bh=+Kl9PVffT9IyDQNCc2AxhyGuN2pv3wP+6F5rFxjv2sE=; b=e
hGAcyOrga8fe8bwXapvLLJ6a5D3qUYgYyZSAYx42xqS6CbEBSNT83KuhHzqyjyAxo+J1EIbBVnHvx
Yq06DBQnWLk0XxQCNOl0yQgvR8tm+4/Cx4Vk5JeylKwZFMdMwCSy75M2mP3/q3Eto/yCrHAVMrou9
qfWwx0WkxJRn2XEc=;
Received: from mail-wm1-f48.google.com ([209.85.128.48])
by sfi-mx-2.v28.lw.sourceforge.com with esmtps
(TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95)
id 1rSfYc-0003wK-4y for openvpn-devel@lists.sourceforge.net;
Wed, 24 Jan 2024 15:52:58 +0000
Received: by mail-wm1-f48.google.com with SMTP id
5b1f17b1804b1-40d6b4e2945so66843475e9.0
for <openvpn-devel@lists.sourceforge.net>;
Wed, 24 Jan 2024 07:52:54 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=netgate.com; s=google; t=1706111562; x=1706716362;
darn=lists.sourceforge.net;
h=content-transfer-encoding:mime-version:message-id:date:subject:to
:from:from:to:cc:subject:date:message-id:reply-to;
bh=+Kl9PVffT9IyDQNCc2AxhyGuN2pv3wP+6F5rFxjv2sE=;
b=dNKu+tNCjMKk285033iVoXwcgz+66vx/H3vdwHIkyAwNxjRQ8IDfMAM8qgehw7ugrS
btA0bwWi3S0feK/x+ewU8KXvrP8Q5q5KaVAP3EkAfjAEfL9w6MsBTgc4ZX3ucFE76sZN
KHGoAEa0tkP/NGnEj0gZ+PjVWs0qm2Y0px4Hg=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1706111562; x=1706716362;
h=content-transfer-encoding:mime-version:message-id:date:subject:to
:from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=+Kl9PVffT9IyDQNCc2AxhyGuN2pv3wP+6F5rFxjv2sE=;
b=YSsIT1hhhqHeI3jkE3TOIgG2GzhrKEn2xcyh9w7O2NicYOxMTs1rbhdrFTXu87axCt
jEBbNI7W72cEvFyxWsVUB/T6i4Y0DQgTbBmdduD66Zaa0T9v0qRJ/r9r7KGZhzCBmRA1
KFSU/wyDzNAowqiqUajTGGb5lERGqu0gK7fXRRtSKCnq4aYMETnM0ewv9+q3qsmgHu/v
GPS2kC5g7SFlKta7KbTMyqI+QR7EbrVoZEyhSRTC4mIAAfjXQbDsRz9LMH3Y1jy7dVsW
4q33Q9rJWO4D3zQ3BW5vZI0BF/QPHUYQ5wEd5B0qpD0hdobflEmBJXA6fYy3KewLncjL
a+mQ==
X-Gm-Message-State: AOJu0YwwHhAYB5yiXUPBZYfGyfDKeSexjUtQzZNcW5kw8hjnUSOe7vJg
1KidIwqj/rG6Qv3mBUS0z/C7FZ5Dt9CRjJ/l31lM1hBSS2V9BMVR8gLEfGyKckxvpTHU+HgRcsI
=
X-Received: by 2002:a05:600c:1d16:b0:40e:6963:e764 with SMTP id
l22-20020a05600c1d1600b0040e6963e764mr856554wms.47.1706110061209;
Wed, 24 Jan 2024 07:27:41 -0800 (PST)
Received: from nut.jupiter.sigsegv.be
(ptr-8rhf62vj1z1egmd2c2g.18120a2.ip6.access.telenet.be.
[2a02:1811:2410:bf00:f602:70ff:feae:6e98])
by smtp.googlemail.com with ESMTPSA id
l13-20020a05600c4f0d00b0040ebf5956absm5201845wmq.29.2024.01.24.07.27.40
for <openvpn-devel@lists.sourceforge.net>
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 24 Jan 2024 07:27:40 -0800 (PST)
To: openvpn-devel <openvpn-devel@lists.sourceforge.net>
Date: Wed, 24 Jan 2024 16:27:39 +0100
Message-ID: <20240124152739.28248-1-kprovost@netgate.com>
X-Mailer: git-send-email 2.43.0
MIME-Version: 1.0
X-Spam-Score: -0.2 (/)
X-Spam-Report: Spam detection software,
running on the system "util-spamd-1.v13.lw.sourceforge.com",
has NOT identified this incoming email as spam. The original
message has been attached to this so you can view it or label
similar future email. If you have any questions, see
the administrator of that system for details.
Content preview: From: Kristof Provost <kp@FreeBSD.org> It's possible for the
buffer we provude for OVPN_GET_PEER_STATS to be too small. Handle the error,
re-allocate a larger buffer and try again rather than failing.
Content analysis details: (-0.2 points, 6.0 required)
pts rule name description
---- ----------------------
--------------------------------------------------
-0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2)
[209.85.128.48 listed in wl.mailspike.net]
-0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/,
no trust [209.85.128.48 listed in list.dnswl.org]
-0.0 SPF_PASS SPF: sender matches SPF record
0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record
-0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from
envelope-from domain
-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 -0.0 T_SCC_BODY_TEXT_LINE No description available.
X-Headers-End: 1rSfYc-0003wK-4y
Subject: [Openvpn-devel] [PATCH] dco-freebsd: dynamically re-allocate buffer
if it's too small
X-BeenThere: openvpn-devel@lists.sourceforge.net
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: <openvpn-devel.lists.sourceforge.net>
List-Unsubscribe: <https://lists.sourceforge.net/lists/options/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=unsubscribe>
List-Archive:
<http://sourceforge.net/mailarchive/forum.php?forum_name=openvpn-devel>
List-Post: <mailto:openvpn-devel@lists.sourceforge.net>
List-Help: <mailto:openvpn-devel-request@lists.sourceforge.net?subject=help>
List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=subscribe>
From: Kristof Provost via Openvpn-devel <openvpn-devel@lists.sourceforge.net>
Reply-To: Kristof Provost <kprovost@netgate.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: openvpn-devel-bounces@lists.sourceforge.net
X-getmail-retrieved-from-mailbox: Inbox
X-GMAIL-THRID: =?utf-8?q?1788987697929503297?=
X-GMAIL-MSGID: =?utf-8?q?1788987697929503297?=
|
| Series |
[Openvpn-devel] dco-freebsd: dynamically re-allocate buffer if it's too small
|
|
Commit Message
Kristof Provost
Jan. 24, 2024, 3:27 p.m. UTC
From: Kristof Provost <kp@FreeBSD.org> It's possible for the buffer we provude for OVPN_GET_PEER_STATS to be too small. Handle the error, re-allocate a larger buffer and try again rather than failing. Signed-off-by: Kristof Provost <kprovost@netgate.com> --- src/openvpn/dco_freebsd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
Comments
Ping? Does this need anything else before it can land? Best regards, Kristof On 24 Jan 2024, at 8:27, Kristof Provost via Openvpn-devel wrote: > From: Kristof Provost <kp@FreeBSD.org> > > It's possible for the buffer we provude for OVPN_GET_PEER_STATS to be > too small. Handle the error, re-allocate a larger buffer and try again > rather than failing. > > Signed-off-by: Kristof Provost <kprovost@netgate.com> > --- > src/openvpn/dco_freebsd.c | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > > diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c > index 3ba1c817..577c65f8 100644 > --- a/src/openvpn/dco_freebsd.c > +++ b/src/openvpn/dco_freebsd.c > @@ -698,7 +698,8 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) > { > > struct ifdrv drv; > - uint8_t buf[4096]; > + uint8_t *buf = NULL; > + size_t buf_size = 4096; > nvlist_t *nvl; > const nvlist_t *const *nvpeers; > size_t npeers; > @@ -712,17 +713,28 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) > CLEAR(drv); > snprintf(drv.ifd_name, IFNAMSIZ, "%s", dco->ifname); > drv.ifd_cmd = OVPN_GET_PEER_STATS; > - drv.ifd_len = sizeof(buf); > + > +retry: > + buf = realloc(buf, buf_size); > + drv.ifd_len = buf_size; > drv.ifd_data = buf; > > ret = ioctl(dco->fd, SIOCGDRVSPEC, &drv); > + if (ret && errno == ENOSPC) > + { > + buf_size *= 2; > + goto retry; > + } > + > if (ret) > { > + free(buf); > msg(M_WARN | M_ERRNO, "Failed to get peer stats"); > return -EINVAL; > } > > nvl = nvlist_unpack(buf, drv.ifd_len, 0); > + free(buf); > if (!nvl) > { > msg(M_WARN, "Failed to unpack nvlist"); > -- > 2.43.0 > > > > _______________________________________________ > Openvpn-devel mailing list > Openvpn-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Hi, On Tue, Feb 06, 2024 at 09:37:47AM -0700, Kristof Provost wrote: > Ping? > > Does this need anything else before it can land? Just time on my side. Busy weeks, apologies. Will handle tomorrow. gert
Acked-by: Gert Doering <gert@greenie.muc.de> Stare-at-code looks good :-) - there's one possible catch should realloc() return NULL - in that case we'd pass drv.ifd_data = NULL to the kernel - but I'm reasonably sure the kernel will then not crash but return EINVAL. I do not have a sufficient number of clients on a FreeBSD 14 system today to trigger the original problem, but I can attest that the new dynamic code will do the right thing - I tested this by reducing the start allocation to 1 byte and see it grow to 1024 (test with 2 clients, 512 sufficient for 1 client). (Also, master+patch passes the full server test rig on FreeBSD 14) Your patch has been applied to the master and release/2.6 branch (bugfix) commit 62676935d738f74908845ca96819a36a8c0c230e (master) commit d8faf568d237667c66141e2c3f6df3f999aa02bd (release/2.6) Author: Kristof Provost Date: Wed Jan 24 16:27:39 2024 +0100 dco-freebsd: dynamically re-allocate buffer if it's too small Signed-off-by: Kristof Provost <kprovost@netgate.com> Acked-by: Gert Doering <gert@greenie.muc.de> Message-Id: <20240124152739.28248-1-kprovost@netgate.com> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28128.html Signed-off-by: Gert Doering <gert@greenie.muc.de> -- kind regards, Gert Doering
diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index 3ba1c817..577c65f8 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -698,7 +698,8 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) { struct ifdrv drv; - uint8_t buf[4096]; + uint8_t *buf = NULL; + size_t buf_size = 4096; nvlist_t *nvl; const nvlist_t *const *nvpeers; size_t npeers; @@ -712,17 +713,28 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) CLEAR(drv); snprintf(drv.ifd_name, IFNAMSIZ, "%s", dco->ifname); drv.ifd_cmd = OVPN_GET_PEER_STATS; - drv.ifd_len = sizeof(buf); + +retry: + buf = realloc(buf, buf_size); + drv.ifd_len = buf_size; drv.ifd_data = buf; ret = ioctl(dco->fd, SIOCGDRVSPEC, &drv); + if (ret && errno == ENOSPC) + { + buf_size *= 2; + goto retry; + } + if (ret) { + free(buf); msg(M_WARN | M_ERRNO, "Failed to get peer stats"); return -EINVAL; } nvl = nvlist_unpack(buf, drv.ifd_len, 0); + free(buf); if (!nvl) { msg(M_WARN, "Failed to unpack nvlist");