Fix unaligned access in auth-token
PATCH 1/5 Fix unaligned access in auth-token
The undefined behaviour USAN clang checker found this. The optimiser of clang/gcc will optimise the memcpy away in the auth_token case and output excactly the same assembly on amd64/arm64 but it is still better to not rely on undefined behaviour.
--- src/openvpn/auth_token.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
src/openvpn/auth_token.c +8 -2
@@ -324,8 +324,14 @@ verify_auth_token(struct user_pass *up, struct tls_multi *multi,const uint8_t *tstamp_initial = sessid +AUTH_TOKEN_SESSION_ID_LEN ;const uint8_t *tstamp = tstamp_initial +sizeof (int64_t ); -uint64_t timestamp =ntohll (*((uint64_t *) (tstamp))); -uint64_t timestamp_initial =ntohll (*((uint64_t *) (tstamp_initial))); +/* tstamp, tstamp_initial might not be aligned to an uint64, use memcpy +* to avoid unaligned access */ +uint64_t timestamp =0 , timestamp_initial =0 ; +memcpy (×tamp, tstamp,sizeof (uint64_t )); + timestamp =ntohll (timestamp); + +memcpy (×tamp_initial, tstamp_initial,sizeof (uint64_t )); + timestamp_initial =ntohll (timestamp_initial);hmac_ctx_t *ctx = multi->opt.auth_token_key.hmac;if (check_hmac_token (ctx, b64decoded, up->username))
Signature · 1 line
2.37.1 (Apple Git-137.1)
PATCH 2/5 Fix unaligned access in macOS/Solaris hwaddr
The undefined behaviour USAN clang checker found this.
This fix is a bit messy but so are the original structures.
--- src/openvpn/route.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-)
src/openvpn/route.c +23 -9
@@ -3637,7 +3637,7 @@ get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx)if (rgi->flags &RGI_IFACE_DEFINED ) {struct ifconf ifc; -struct ifreq *ifr; +struct ifreq ifr;const int bufsize =4096 ;char *buffer;
@@ -3662,23 +3662,37 @@ get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx)for (cp = buffer; cp <= buffer + ifc.ifc_len -sizeof (struct ifreq ); ) { - ifr = (struct ifreq *)cp; +/* this is not always using an 8byte alignment that struct ifr +* requires */ +memcpy (&ifr, cp,sizeof (struct ifreq ));#if defined(TARGET_SOLARIS ) -const size_t len =sizeof (ifr->ifr_name) +sizeof (ifr->ifr_addr); +const size_t len =sizeof (ifr.ifr_name) +sizeof (ifr.ifr_addr);#else -const size_t len =sizeof (ifr->ifr_name) +max (sizeof (ifr->ifr_addr), ifr->ifr_addr.sa_len); +const size_t len =sizeof (ifr.ifr_name) +max (sizeof (ifr.ifr_addr), ifr.ifr_addr.sa_len);#endif -if (!ifr->ifr_addr.sa_family) +if (!ifr.ifr_addr.sa_family) {break ; } -if (!strncmp (ifr->ifr_name, rgi->iface,IFNAMSIZ )) +if (!strncmp (ifr.ifr_name, rgi->iface,IFNAMSIZ )) { -if (ifr->ifr_addr.sa_family ==AF_LINK ) +if (ifr.ifr_addr.sa_family ==AF_LINK ) { -struct sockaddr_dl *sdl = (struct sockaddr_dl *)&ifr->ifr_addr; -memcpy (rgi->hwaddr,LLADDR (sdl),6 ); +/* This is a broken member access. struct sockaddr_dl has +* 20 bytes while if_addr has only 16 bytes. So casting if_addr +* to struct sockaddr_dl gives (legitimate) warnings +* +* sockaddr_dl has 12 bytes space for the hw address and +* Ethernet only uses 6 bytes. So the last 4 that are +* truncated and not in if_addr can be ignored here. +* +* So we use a memcpy here to avoid the warnings with ASAN +* that we are doing a very nasty cast here +*/ +struct sockaddr_dl sdl = {0 }; +memcpy (&sdl, &ifr.ifr_addr,sizeof (ifr.ifr_addr)); +memcpy (rgi->hwaddr,LLADDR (&sdl),6 ); rgi->flags |=RGI_HWADDR_DEFINED ; } }
Signature · 1 line
2.37.1 (Apple Git-137.1)
Re: [Openvpn-devel] [PATCH 2/5] Fix unaligned access in macOS/Solaris hwaddr
Quoted 4 lines · Arne Schwabe
The undefined behaviour USAN clang checker found this.
This fix is a bit messy but so are the original structures.
Well, it doesn't make it worse vOv
Regards,
Signature · 1 line
Frank Lichtenheld
Re: [Openvpn-devel] [PATCH 2/5] Fix unaligned access in macOS/Solaris hwaddr
Quoted 9 lines · Frank Lichtenheld
Quoted 4 lines · Arne Schwabe
The undefined behaviour USAN clang checker found this.
This fix is a bit messy but so are the original structures.
Well, it doesn't make it worse vOv
Note: I revoke this ACK. Would need to verify first whether we need further changes similar to what Arne did in OpenVPN3:
https://github.com/OpenVPN/openvpn3/commit/b755783a13257237f85d633fe2ae60e4118415a0
Regards,
Signature · 1 line
Frank Lichtenheld
Re: [Openvpn-devel] [PATCH 2/5] Fix unaligned access in macOS/Solaris hwaddr
In reply to Arne SchwabeHi,
Quoted 3 lines · Arne Schwabe
The undefined behaviour USAN clang checker found this.
This fix is a bit messy but so are the original structures.
I wonder...
src/openvpn/route.c get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) · line 3696
Quoted 4 lines
src/openvpn/route.c +3
-0+struct sockaddr_dl sdl = {0 }; +memcpy (&sdl, &ifr.ifr_addr,sizeof (ifr.ifr_addr)); +memcpy (rgi->hwaddr,LLADDR (&sdl),6 ); rgi->flags |=RGI_HWADDR_DEFINED ;
... why you keep the "sockaddr_dl" intermediate - this was useful for "we use it as a pointer", but doing two memcpy() with a huge explanation above looks weird.
LLADDR on FreeBSD is
#define LLADDR(s) ((caddr_t)((s)->sdl_data + (s)->sdl_nlen))
(to operate on a "struct sockaddr_dl")
struct ifaddr has
struct ifaddr {
struct sockaddr *ifa_addr; /* address of interface */
struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
struct sockaddr *ifa_netmask; /* used to determine subnet */... so the first memcpy() isn't actually copying the MAC address around, just a bunch of pointers, and then we dereference the first of them for the second memcpy(), using the dereferencing macro for a "sockaddr_dl" structure.
FreeBSD also has
#define IF_LLADDR(ifp) \
LLADDR((struct sockaddr_dl *)((ifp)->if_addr->ifa_addr))which sounds like "feed in an *ifr, out comes a pointer for the memcpy() to rgi->addr".
I'll check the other BSDs if LL_IFADDR() is available everywhere, but if not, we can just do the same thing (struct ifr is aligned) and get rid of the "sdl" and the first memcpy().
(Am I overlooking something?)
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]...Re: [Openvpn-devel] [PATCH 2/5] Fix unaligned access in macOS/Solaris hwaddr
Hi,
Quoted 3 lines · Gert Doering
I'll check the other BSDs if
LL_IFADDR()is available everywhere, but if not, we can just do the same thing (struct ifr is aligned) and get rid of the "sdl" and the firstmemcpy().
Of course neither Solaris nor OpenBSD have the LL_IFADDR(), but that's trivial enough.
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]...Re: [Openvpn-devel] [PATCH 2/5] Fix unaligned access in macOS/Solaris hwaddr
In reply to Gert DoeringAm 26.02.2023 um 11:02 schrieb Gert Doering:
Quoted 25 lines
Hi,
Quoted 3 lines · Arne Schwabe
The undefined behaviour USAN clang checker found this.
This fix is a bit messy but so are the original structures.
I wonder...
src/openvpn/route.c get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) · line 3696
Quoted 4 lines
src/openvpn/route.c +3
-0+struct sockaddr_dl sdl = {0 }; +memcpy (&sdl, &ifr.ifr_addr,sizeof (ifr.ifr_addr)); +memcpy (rgi->hwaddr,LLADDR (&sdl),6 ); rgi->flags |=RGI_HWADDR_DEFINED ;... why you keep the "
sockaddr_dl" intermediate - this was useful for "we use it as a pointer", but doing twomemcpy()with a huge explanation above looks weird.LLADDR on FreeBSD is
#define LLADDR(s) ((caddr_t)((s)->sdl_data + (s)->sdl_nlen))
(to operate on a "struct
sockaddr_dl")struct ifaddr has
struct ifaddr {
Quoted 8 lines
struct sockaddr *ifa_addr; /* address of interface */ struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ struct sockaddr *ifa_netmask; /* used to determine subnet */... so the first
memcpy()isn't actually copying the MAC address around, just a bunch of pointers, and then we dereference the first of them for the secondmemcpy(), using the dereferencing macro for a "sockaddr_dl" structure.
The problem is that LLVM ASAN does not like access to an unaligned struct. Even if it just accessing a member to deference it. So you are right that it is just copying a bunch of pointers, to not triggers the warning, we have to do this nonsense. The compiler will even optimise this then away again on platforms that have no problem with unaligned accesses.
Quoted 7 lines
FreeBSD also has
#define IF_LLADDR(ifp) \ LLADDR((struct sockaddr_dl *)((ifp)->if_addr->ifa_addr))which sounds like "feed in an *ifr, out comes a pointer for the
memcpy()torgi->addr".
Yes but you will still get warning about casting a smaller struct to a larger struct and that being a bad idea.
Arne
Re: [Openvpn-devel] [PATCH 2/5] Fix unaligned access in macOS/Solaris hwaddr
Hi,
Quoted 10 lines · Arne Schwabe
Quoted 9 lines
struct ifaddr {
struct sockaddr *ifa_addr; /* address of interface */ struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ struct sockaddr *ifa_netmask; /* used to determine subnet */... so the first
memcpy()isn't actually copying the MAC address around, just a bunch of pointers, and then we dereference the first of them for the secondmemcpy(), using the dereferencing macro for a "sockaddr_dl" structure.
Quoted 6 lines
The problem is that LLVM ASAN does not like access to an unaligned struct. Even if it just accessing a member to deference it. So you are right that it is just copying a bunch of pointers, to not triggers the warning, we have to do this nonsense. The compiler will even optimise this then away again on platforms that have no problem with unaligned accesses.
With ifr being a structure now, it is aligned just fine - I'm not objecting to that part, just to the intermediate "sdl" thing, and the double memcpy(), and 10 lines of comments.
Quoted 10 lines
Quoted 7 lines
FreeBSD also has
#define IF_LLADDR(ifp) \ LLADDR((struct sockaddr_dl *)((ifp)->if_addr->ifa_addr))which sounds like "feed in an *ifr, out comes a pointer for the
memcpy()torgi->addr".Yes but you will still get warning about casting a smaller struct to a larger struct and that being a bad idea.
This is not casting a struct, just casting a pointer. Does it still warn?
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]...PATCH v2 1/1 Fix unaligned access in macOS/Solaris hwaddr
In reply to Arne SchwabeThe undefined behaviour USAN clang checker found this.
This fix is a bit messy but so are the original structures.
Patch v2: handle the fact we need to beyond the struct ifr
correctly when mapping the result to struct sockaddr_dl
--- src/openvpn/route.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-)
src/openvpn/route.c +23 -9
@@ -3641,7 +3641,7 @@ get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx)if (rgi->flags &RGI_IFACE_DEFINED ) {struct ifconf ifc; -struct ifreq *ifr; +struct ifreq ifr;const int bufsize =4096 ;char *buffer;
@@ -3666,23 +3666,37 @@ get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx)for (cp = buffer; cp <= buffer + ifc.ifc_len -sizeof (struct ifreq ); ) { - ifr = (struct ifreq *)cp; +/* this is not always using an 8 byte alignment that struct ifr +* requires */ +memcpy (&ifr, cp,sizeof (struct ifreq ));#if defined(TARGET_SOLARIS ) -const size_t len =sizeof (ifr->ifr_name) +sizeof (ifr->ifr_addr); +const size_t len =sizeof (ifr.ifr_name) +sizeof (ifr.ifr_addr);#else -const size_t len =sizeof (ifr->ifr_name) +max (sizeof (ifr->ifr_addr), ifr->ifr_addr.sa_len); +const size_t len =sizeof (ifr.ifr_name) +max (sizeof (ifr.ifr_addr), ifr.ifr_addr.sa_len);#endif -if (!ifr->ifr_addr.sa_family) +if (!ifr.ifr_addr.sa_family) {break ; } -if (!strncmp (ifr->ifr_name, rgi->iface,IFNAMSIZ )) +if (!strncmp (ifr.ifr_name, rgi->iface,IFNAMSIZ )) { -if (ifr->ifr_addr.sa_family ==AF_LINK ) +if (ifr.ifr_addr.sa_family ==AF_LINK ) { -struct sockaddr_dl *sdl = (struct sockaddr_dl *)&ifr->ifr_addr; -memcpy (rgi->hwaddr,LLADDR (sdl),6 ); +/* This is a broken member access. struct sockaddr_dl has +* 20 bytes while if_addr has only 16 bytes. So casting if_addr +* to struct sockaddr_dl gives (legitimate) warnings +* +* sockaddr_dl has 12 bytes space for the inrerface name and +* the hw address. So the last 4 that might be part of the +* hw address are not in if_addr, so we need +* +* So we use a memcpy here to avoid the warnings with ASAN +* that we are doing a very nasty cast here +*/ +struct sockaddr_dl sdl = {0 }; +memcpy (&sdl, cp + offsetof(struct ifreq , ifr_addr),sizeof (sdl)); +memcpy (rgi->hwaddr,LLADDR (&sdl),6 ); rgi->flags |=RGI_HWADDR_DEFINED ; } }
Signature · 1 line
2.39.2 (Apple Git-143)
Re: [Openvpn-devel] [PATCH v2] Fix unaligned access in macOS/Solaris hwaddr
Quoted 50 lines · Arne Schwabe
The undefined behaviour USAN clang checker found this.
This fix is a bit messy but so are the original structures.
Patch v2: handle the fact we need to beyond the struct ifr
correctly when mapping the result to structsockaddr_dlChange-Id Ia797c8801fa9a9bc10b6674efde5fdbd7132e4a8Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/route.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-)src/openvpn/route.c +8
-6@@ -3641,7 +3641,7 @@ get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx)if (rgi->flags &RGI_IFACE_DEFINED ) {struct ifconf ifc; -struct ifreq *ifr; +struct ifreq ifr;const int bufsize =4096 ;char *buffer;@@ -3666,23 +3666,37 @@ get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx)for (cp = buffer; cp <= buffer + ifc.ifc_len -sizeof (struct ifreq ); ) { - ifr = (struct ifreq *)cp; +/* this is not always using an 8 byte alignment that struct ifr +* requires */ +memcpy (&ifr, cp,sizeof (struct ifreq ));#if defined(TARGET_SOLARIS ) -const size_t len =sizeof (ifr->ifr_name) +sizeof (ifr->ifr_addr); +const size_t len =sizeof (ifr.ifr_name) +sizeof (ifr.ifr_addr);#else -const size_t len =sizeof (ifr->ifr_name) +max (sizeof (ifr->ifr_addr), ifr->ifr_addr.sa_len); +const size_t len =sizeof (ifr.ifr_name) +max (sizeof (ifr.ifr_addr), ifr.ifr_addr.sa_len);#endif -if (!ifr->ifr_addr.sa_family) +if (!ifr.ifr_addr.sa_family) {break ; } -if (!strncmp (ifr->ifr_name, rgi->iface,IFNAMSIZ )) +if (!strncmp (ifr.ifr_name, rgi->iface,IFNAMSIZ )) {
src/openvpn/route.c get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) · line 3690
Quoted 10 lines
src/openvpn/route.c +6
-3-if (ifr->ifr_addr.sa_family ==AF_LINK ) +if (ifr.ifr_addr.sa_family ==AF_LINK ) { -struct sockaddr_dl *sdl = (struct sockaddr_dl *)&ifr->ifr_addr; -memcpy (rgi->hwaddr,LLADDR (sdl),6 ); +/* This is a broken member access. struct sockaddr_dl has +* 20 bytes while if_addr has only 16 bytes. So casting if_addr +* to struct sockaddr_dl gives (legitimate) warnings +* +* sockaddr_dl has 12 bytes space for the inrerface name and
"interface"
src/openvpn/route.c get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) · line 3692
Quoted 2 lines
src/openvpn/route.c +2
-0+* the hw address. So the last 4 that might be part of the +* hw address are not in if_addr, so we need
Sentence missing words at the end?
src/openvpn/route.c get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) · line 3700
Quoted 8 lines
src/openvpn/route.c +7
-0+* +* So we use a memcpy here to avoid the warnings with ASAN +* that we are doing a very nasty cast here +*/ +struct sockaddr_dl sdl = {0 }; +memcpy (&sdl, cp + offsetof(struct ifreq , ifr_addr),sizeof (sdl)); +memcpy (rgi->hwaddr,LLADDR (&sdl),6 ); rgi->flags |=RGI_HWADDR_DEFINED ;
So, reading the documentation about sockaddr and sockaddr_dl, I'm not sure that even this code is safe. E.g. you say "sockaddr_dl has 12 bytes space", but is that actually true? The actual headers always seems to suggest "at least 12 bytes space". Similar to how the generic sockaddr has "at least 16 bytes size". So is that memcpy that you're doing actually guaranteed to copy enough data to make LLADDR work? Or can LLADDR actually point behind sizeof(sockaddr_dl)? The documentation and comments in the BSD headers seem to be vague about that?
Regards,
Signature · 1 line
Frank Lichtenheld
PATCH 3/5 Update LibreSSL to 3.7.0 in Github actions
In reply to Arne SchwabeThe version 3.5.3 triggers undefined behaviour with the usan sanatizer. Updating LibreSSSL to 3.7.0 does unfortunately does not fix the issue but at least we are now using a current version.
--- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
.github/workflows/build.yaml +2 -2
@@ -409,7 +409,7 @@ jobs: with: path: libressl repository: libressl-portable/portable - ref: v3.5.3 + ref: v3.7.0 - name: "libressl: autogen.sh" run: ./autogen.sh working-directory: libressl
@@ -417,7 +417,7 @@ jobs: run: autoreconf -fvi working-directory: libressl - name: "libressl: configure" - run: ./configure --enable-openvpn + run: ./configure working-directory: libressl - name: "libressl: make all" run: make -j3
Signature · 1 line
2.37.1 (Apple Git-137.1)
Re: [Openvpn-devel] [PATCH 3/5] Update LibreSSL to 3.7.0 in Github actions
Quoted 23 lines · Arne Schwabe
The version 3.5.3 triggers undefined behaviour with the usan sanatizer. Updating LibreSSSL to 3.7.0 does unfortunately does not fix the issue but at least we are now using a current version.
Signed-off-by Arne Schwabe <[email protected]...>--- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-).github/workflows/build.yaml +1
-1@@ -409,7 +409,7 @@ jobs: with: path: libressl repository: libressl-portable/portable - ref: v3.5.3 + ref: v3.7.0 - name: "libressl: autogen.sh" run: ./autogen.sh working-directory: libressl
.github/workflows/build.yaml jobs: · line 422
Quoted 7 lines
.github/workflows/build.yaml +1
-1@@ -417,7 +417,7 @@ jobs: run: autoreconf -fvi working-directory: libressl - name: "libressl: configure" - run: ./configure --enable-openvpn + run: ./configure working-directory: libressl - name: "libressl: make all"
Always good to update to latest.
Regards,
Signature · 1 line
Frank Lichtenheld
[Openvpn-devel] [PATCH applied] Re: Update LibreSSL to 3.7.0 in Github actions
In reply to Arne SchwabeYour patch has been applied to the master and release/2.6 branch.
commit dc8f1f3963af8bce5e03c333dce9a0b252f6e1fd (master) commit 3973845ea5bc3fdc15a158917d819b5e9bd92635 (release/2.6)
Author: Arne Schwabe Date: Mon Jan 30 18:29:34 2023 +0100
Update LibreSSL to 3.7.0 in Github actions
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Frank Lichtenheld <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg26105.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 4/5 Add printing USAN stack trace on github actions
In reply to Arne SchwabeThis allows identifying the source of undefined behaviour more easily from the github action logs.
--- .github/workflows/build.yaml | 5 +++++ 1 file changed, 5 insertions(+)
.github/workflows/build.yaml +5 -0
@@ -242,6 +242,9 @@ jobs: name: "clang-asan - ${{matrix.os}} - ${{matrix.ssllib}}" + env: + UBSAN_OPTIONS: print_stacktrace=1 + runs-on: ${{matrix.os}} steps: - name: Install dependencies
@@ -291,6 +294,7 @@ jobs: LDFLAGS: ${{ matrix.ldflags }} OPENSSL_CFLAGS: "-I/usr/local/opt/${{matrix.libdir}}/include" OPENSSL_LIBS: "-L/usr/local/opt/${{matrix.libdir}}/lib -lcrypto -lssl" + UBSAN_OPTIONS: print_stacktrace=1 steps: - name: Install dependencies run: brew install [email protected]... [email protected]... lzo lz4 man2html cmocka libtool automake autoconf libressl
@@ -400,6 +404,7 @@ jobs: CFLAGS: ${{ matrix.cflags }} LDFLAGS: ${{ matrix.ldflags }} CC: ${{matrix.cc}} + UBSAN_OPTIONS: print_stacktrace=1 steps: - name: Install dependencies
Signature · 1 line
2.37.1 (Apple Git-137.1)
Re: [Openvpn-devel] [PATCH 4/5] Add printing USAN stack trace on github actions
Quoted 31 lines · Arne Schwabe
This allows identifying the source of undefined behaviour more easily from the github action logs.
Signed-off-by Arne Schwabe <[email protected]...>--- .github/workflows/build.yaml | 5 +++++ 1 file changed, 5 insertions(+).github/workflows/build.yaml +4
-0@@ -242,6 +242,9 @@ jobs: name: "clang-asan - ${{matrix.os}} - ${{matrix.ssllib}}" + env: + UBSAN_OPTIONS: print_stacktrace=1 + runs-on: ${{matrix.os}} steps: - name: Install dependencies@@ -291,6 +294,7 @@ jobs: LDFLAGS: ${{ matrix.ldflags }} OPENSSL_CFLAGS: "-I/usr/local/opt/${{matrix.libdir}}/include" OPENSSL_LIBS: "-L/usr/local/opt/${{matrix.libdir}}/lib -lcrypto -lssl" + UBSAN_OPTIONS: print_stacktrace=1 steps: - name: Install dependencies run: brew install [email protected]... [email protected]... lzo lz4 man2html cmocka libtool automake autoconf libressl
.github/workflows/build.yaml jobs: · line 410
Quoted 7 lines
.github/workflows/build.yaml +1
-0@@ -400,6 +404,7 @@ jobs: CFLAGS: ${{ matrix.cflags }} LDFLAGS: ${{ matrix.ldflags }} CC: ${{matrix.cc}} + UBSAN_OPTIONS: print_stacktrace=1 steps: - name: Install dependencies
Trivial enough.
Regards,
Signature · 1 line
Frank Lichtenheld
[Openvpn-devel] [PATCH applied] Re: Add printing USAN stack trace on github actions
In reply to Arne SchwabeI haven't tested it yet, but will have a close look at the GH test runs after I push this - the route.c fix hasn't been merged yet (want to stare more at it) so the MacOS/ASAN build should trigger something now... non-fatal, but red :-)
Your patch has been applied to the master and release/2.6 branch.
commit 98f295004391194d4770a450fda79a30dbaf7d60 (master) commit 0deb1afdba185de464d0c542f60de71712a34b80 (release/2.6)
Author: Arne Schwabe Date: Mon Jan 30 18:29:35 2023 +0100
Add printing USAN stack trace on github actions
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Frank Lichtenheld <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg26102.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 5/5 Add undefined and abort on error to clang sanaitize builds
In reply to Arne SchwabeThe -fno-sanitize-recover=all flag ensures that for all errors we actually abort the tests in the automated testing and not just print some errors in red that nobody sess. Also add the undefined tests to catch more bugs.
For libreSSL we do not add the udefined behaviour as we have (even with the latest LibreSSL version) an undefined behaviour in LibreSSL itself.
--- .github/workflows/build.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
.github/workflows/build.yaml +5 -5
@@ -254,7 +254,7 @@ jobs: - name: autoconf run: autoreconf -fvi - name: configure - run: CFLAGS="-fsanitize=address -fno-omit-frame-pointer -O2" CC=clang ./configure --with-crypto-library=${{matrix.ssllib}} + run: CFLAGS="-fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer -O2" CC=clang ./configure --with-crypto-library=${{matrix.ssllib}} - name: make all run: make -j3 - name: make check
@@ -269,8 +269,8 @@ jobs: os: [macos-11, macos-12] include: - build: asan - cflags: "-fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g -O1" - ldflags: -fsanitize=address + cflags: "-fsanitize=address,undefined -fno-sanitize-recover=all -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g -O1" + ldflags: -fsanitize=address,undefined -fno-sanitize-recover=all # Our build system ignores LDFLAGS for plugins configureflags: --disable-plugin-auth-pam --disable-plugin-down-root - build: normal
@@ -390,8 +390,8 @@ jobs: configureflags: ["--with-openssl-engine=no"] include: - build: asan - cflags: "-fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g -O1" - ldflags: -fsanitize=address + cflags: "-fsanitize=address -fno-sanitize-recover=all -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g -O1" + ldflags: -fsanitize=address -fno-sanitize-recover=all cc: clang - build: normal cflags: "-O2 -g"
Signature · 1 line
2.37.1 (Apple Git-137.1)
Re: [Openvpn-devel] [PATCH 5/5] Add undefined and abort on error to clang sanaitize builds
Quoted 6 lines · Arne Schwabe
The -fno-sanitize-recover=all flag ensures that for all errors we actually abort the tests in the automated testing and not just print some errors in red that nobody sess. Also add the undefined tests to catch more bugs.
For libreSSL we do not add the udefined behaviour as we have (even with the latest LibreSSL version) an undefined behaviour in LibreSSL itself.
Generally looks good to me. Needs rebase on current master.
Please while touching the ASAN stuff also change the ASAN build to use Ubuntu 22.04 instead of Ubuntu 20.04. Getting a newer clang shouldn't hurt. I tested it and it seems to work fine.
Note this need Patch 2/5 otherwise macOS GHA ASAN build fails. So can't be merged before that.
Regards,
Signature · 1 line
Frank Lichtenheld
Quoted 21 lines · Arne Schwabe
The undefined behaviour USAN clang checker found this. The optimiser of clang/gcc will optimise the memcpy away in the
auth_tokencase and output excactly the same assembly on amd64/arm64 but it is still better to not rely on undefined behaviour.Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/auth_token.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)src/openvpn/auth_token.c +1
-2@@ -324,8 +324,14 @@ verify_auth_token(struct user_pass *up, struct tls_multi *multi,const uint8_t *tstamp_initial = sessid +AUTH_TOKEN_SESSION_ID_LEN ;const uint8_t *tstamp = tstamp_initial +sizeof (int64_t ); -uint64_t timestamp =ntohll (*((uint64_t *) (tstamp))); -uint64_t timestamp_initial =ntohll (*((uint64_t *) (tstamp_initial))); +/* tstamp, tstamp_initial might not be aligned to an uint64, use memcpy
src/openvpn/auth_token.c verify_auth_token(struct user_pass *up, struct tls_multi *multi, · line 337
Quoted 10 lines
src/openvpn/auth_token.c +7
-0+* to avoid unaligned access */ +uint64_t timestamp =0 , timestamp_initial =0 ; +memcpy (×tamp, tstamp,sizeof (uint64_t )); + timestamp =ntohll (timestamp); + +memcpy (×tamp_initial, tstamp_initial,sizeof (uint64_t )); + timestamp_initial =ntohll (timestamp_initial);hmac_ctx_t *ctx = multi->opt.auth_token_key.hmac;if (check_hmac_token (ctx, b64decoded, up->username))
Trivial enough.
Regards,
Signature · 1 line
Frank Lichtenheld
This one is fairly straightforward. We had discussions on IRC if we really need to make this network byte order ("the data in the token is only for the server, nobody else needs to care") but then decided that if someone wants to run a cluster of an intel + a s390 host, they need to be compatible wrt timestamp representation...
Tested on the server testbed, just to be sure (it has an auth-token test) - things still work, including token expiry after the configured time.
Your patch has been applied to the master and release/2.6 branch (bugfix).
commit f6ccff6d7ea806711f9af59c9de52b7cf80d9c81 (master) commit 6241b2f8dbe39062a3273499a0259750d2f02cf8 (release/2.6)
Author: Arne Schwabe Date: Mon Jan 30 18:29:32 2023 +0100
Fix unaligned access in auth-token
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Frank Lichtenheld <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg26103.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering