Add missing check for nl_socket_alloc failure
PATCH 1/1 Add missing check for nl_socket_alloc failure
This can happen if the memory alloc fails.
--- src/openvpn/dco_linux.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
src/openvpn/dco_linux.c +6 -2
@@ -79,10 +79,14 @@ typedef int (*ovpn_nl_cb)(struct nl_msg *msg, void *arg);static int resolve_ovpn_netlink_id (int msglevel) { -int ret;struct nl_sock *nl_sock =nl_socket_alloc (); - ret =genl_connect (nl_sock); +if (!nl_sock) + { +msg (msglevel,"Allocating net link socket failed" ); + } + +int ret =genl_connect (nl_sock);if (ret) { msg(msglevel, "Cannot connect to generic netlink: %s",
Signature · 1 line
2.37.1 (Apple Git-137.1)
Hi,
src/openvpn/dco_linux.c typedef int (*ovpn_nl_cb)(struct nl_msg *msg, void *arg); · line 87
Quoted 10 lines · Arne Schwabe
resolve_ovpn_netlink_id(int msglevel)
{src/openvpn/dco_linux.c +4
-2-int ret;struct nl_sock *nl_sock =nl_socket_alloc (); - ret =genl_connect (nl_sock); +if (!nl_sock) + { +msg (msglevel,"Allocating net link socket failed" ); + }
... shouldn't we abort in this case, aka, M_FATAL (or "return -errno")?
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Am 14.02.23 um 15:01 schrieb Gert Doering:
Quoted 8 lines
Hi,
Quoted 5 lines · Arne Schwabe
resolve_ovpn_netlink_id(int msglevel)
{- int ret; struct nl_sock *nl_sock = nl_socket_alloc();
Quoted 7 lines
src/openvpn/dco_linux.c typedef int (*ovpn_nl_cb)(struct nl_msg *msg, void *arg); · line 87
Quoted 5 lines
src/openvpn/dco_linux.c +4
-1- ret =genl_connect (nl_sock); +if (!nl_sock) + { +msg (msglevel,"Allocating net link socket failed" ); + }... shouldn't we abort in this case, aka,
M_FATAL(or "return -errno")?
I don't think so. This function is called from two code paths:
- dco_available: I don't think if detection of dco fails, we should quit openvpn completely.
- ovpn_dco_init_netlink: Here we already call it with M_ERR, which is (M_FATAL | M_ERRNO)
Arne
PATCH v2 1/1 Add missing check for nl_socket_alloc failure
In reply to Arne SchwabeThis can happen if the memory alloc fails.
Patch V2: add goto error
--- src/openvpn/dco_linux.c | 7 +++++++ 1 file changed, 7 insertions(+)
src/openvpn/dco_linux.c +7 -0
@@ -83,6 +83,13 @@ resolve_ovpn_netlink_id(int msglevel)int ret;struct nl_sock *nl_sock =nl_socket_alloc (); +if (!nl_sock) + { +msg (msglevel,"Allocating net link socket failed" ); + ret =-1 ; + goto err_sock; + } + ret =genl_connect (nl_sock);if (ret) {
Signature · 1 line
2.37.1 (Apple Git-137.1)
Quoted 15 lines · Arne Schwabe
This can happen if the memory alloc fails.
Patch V2: add goto error
Change-Id Iee66caa794d267ac5f8bee584633352893047171Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/dco_linux.c | 7 +++++++ 1 file changed, 7 insertions(+)src/openvpn/dco_linux.c +0
-0
src/openvpn/dco_linux.c resolve_ovpn_netlink_id(int msglevel) · line 89
Quoted 7 lines
src/openvpn/dco_linux.c +4
-0@@ -83,6 +83,13 @@ resolve_ovpn_netlink_id(int msglevel)int ret;struct nl_sock *nl_sock =nl_socket_alloc (); +if (!nl_sock) + { +msg (msglevel,"Allocating net link socket failed" ); + ret =-1 ;
Please use -ENOMEM here - it is always better to return an actual reason rather than just "failed".
src/openvpn/dco_linux.c resolve_ovpn_netlink_id(int msglevel) · line 90
Quoted 1 line
src/openvpn/dco_linux.c +1
-0+ goto err_sock;
There is no need to jump to cleanup.
You can just return -1 here and save one line. (this is what we do in other functions of this file)
Cheers,
Signature · 1 line
Antonio Quartulli
PATCH v3 1/1 Add missing check for nl_socket_alloc failure
In reply to Arne SchwabeThis can happen if the memory alloc fails.
Patch V2: add goto error
Patch V3: return -ENOMEM instead of going to error
--- src/openvpn/dco_linux.c | 6 ++++++ 1 file changed, 6 insertions(+)
src/openvpn/dco_linux.c +6 -0
@@ -81,6 +81,12 @@ resolve_ovpn_netlink_id(int msglevel)int ret;struct nl_sock *nl_sock =nl_socket_alloc (); +if (!nl_sock) + { +msg (msglevel,"Allocating net link socket failed" ); +return -ENOMEM ; + } + ret =genl_connect (nl_sock);if (ret) {
Signature · 1 line
2.39.3 (Apple Git-145)
Hi,
Quoted 7 lines · Arne Schwabe
This can happen if the memory alloc fails.
Patch V2: add goto error
Patch V3: return-ENOMEMinstead of going to errorChange-Id Iee66caa794d267ac5f8bee584633352893047171Signed-off-by Arne Schwabe <[email protected]...>
Quoted 21 lines
--- src/openvpn/dco_linux.c | 6 ++++++ 1 file changed, 6 insertions(+)src/openvpn/dco_linux.c +6
-0@@ -81,6 +81,12 @@ resolve_ovpn_netlink_id(int msglevel)int ret;struct nl_sock *nl_sock =nl_socket_alloc (); +if (!nl_sock) + { +msg (msglevel,"Allocating net link socket failed" ); +return -ENOMEM ; + } + ret =genl_connect (nl_sock);if (ret) {
Signature · 1 line
Antonio Quartulli
Took us long enough for such a simple fix... :-)
I have no easy way to trigger this, so only compile tested.
Your patch has been applied to the master and release/2.6 branch.
commit d1c31e428120bb0fc9488c62c1691c92a37d94c3 (master) commit aa19a6a90f7ef24df12eed205663f3cfbb7d8174 (release/2.6)
Author: Arne Schwabe Date: Tue Nov 21 18:06:03 2023 +0100
Add missing check for nl_socket_alloc failure
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg27541.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering