-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mbedtls] Patch sources to use
fcntl
syscall directly
Due to symbol incompatibility on different glibc versions (`fcntl` vs `fcntl64`), `ra-tls-mbedtls` example could not be built on Ubuntu 18.04 if Gramine was built on any newer distro. Signed-off-by: Borys Popławski <borysp@invisiblethingslab.com>
- Loading branch information
1 parent
132ebc1
commit 1d80fad
Showing
4 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
subprojects/mbedtls-mbedtls-2.26.0-1.wrap → subprojects/mbedtls-mbedtls-2.26.0-2.wrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
# NOTE: We use a custom version number (the `-1` suffix) to force Meson to rebuild when there is a | ||
# NOTE: We use a custom version number (the `-2` suffix) to force Meson to rebuild when there is a | ||
# breaking change to the interface between mbedTLS and Gramine. The important part is that the | ||
# directory in `subprojects` has to change (`subprojects/mbedtls-mbedtls-2.26.0-1`, | ||
# `subprojects/mbedtls-mbedtls-2.26.0-2` etc.) | ||
|
||
[wrap-file] | ||
directory = mbedtls-mbedtls-2.26.0-1 | ||
directory = mbedtls-mbedtls-2.26.0-2 | ||
source_url = https://github.com/ARMmbed/mbedtls/archive/mbedtls-2.26.0.tar.gz | ||
source_fallback_url = https://packages.gramineproject.io/distfiles/mbedtls-2.26.0.tar.gz | ||
source_filename = mbedtls-2.26.0.tar.gz | ||
source_hash = 35d8d87509cd0d002bddbd5508b9d2b931c5e83747d087234cc7ad551d53fe05 | ||
|
||
patch_directory = mbedtls | ||
|
||
# this unpacks the sources to `mbedtls-mbedtls-2.26.0-1/mbedtls-mbedtls-2.26.0` | ||
# this unpacks the sources to `mbedtls-mbedtls-2.26.0-2/mbedtls-mbedtls-2.26.0` | ||
lead_directory_missing = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Workaround for missing `fcntl64` symbol. | ||
# When built on a newer distro (e.g. Ubuntu 20.04) which has glibc in version >= 2.28, Gramine | ||
# failed to work on distros with older glibc (e.g. Ubuntu 18.04 - glibc 2.27). This is due to symbol | ||
# incompatibility, namely `fcntl` - since glibc 2.28 there is a newer version `fcntl64`, | ||
# which is not present on older versions. As a workaround we just changed each usage of `fcntl` to | ||
# a direct syscall - these calls just check and/or change `O_NONBLOCK` flag. | ||
# Note that building with this patch might throw a warning about missing `syscall` declaration. | ||
# We did not bother fixing this, because it will be always present and this is a hack anyway. | ||
# TODO: remove this patch after we drop Ubuntu 18.04 support | ||
|
||
diff --git a/library/net_sockets.c b/library/net_sockets.c | ||
index 17a9e4a5760bb19270af584f9acc861c2f9ab4c7..b02b4c99f15c4881876bf8a061748056f1161b86 100644 | ||
--- a/library/net_sockets.c | ||
+++ b/library/net_sockets.c | ||
@@ -92,6 +92,7 @@ static int wsa_init_done = 0; | ||
#include <fcntl.h> | ||
#include <netdb.h> | ||
#include <errno.h> | ||
+#include <sys/syscall.h> | ||
|
||
#define IS_EINTR( ret ) ( ( ret ) == EINTR ) | ||
|
||
@@ -313,7 +314,7 @@ static int net_would_block( const mbedtls_net_context *ctx ) | ||
/* | ||
* Never return 'WOULD BLOCK' on a blocking socket | ||
*/ | ||
- if( ( fcntl( ctx->fd, F_GETFL ) & O_NONBLOCK ) != O_NONBLOCK ) | ||
+ if( ( syscall( SYS_fcntl, ctx->fd, F_GETFL ) & O_NONBLOCK ) != O_NONBLOCK ) | ||
{ | ||
errno = err; | ||
return( 0 ); | ||
@@ -462,7 +463,7 @@ int mbedtls_net_set_block( mbedtls_net_context *ctx ) | ||
u_long n = 0; | ||
return( ioctlsocket( ctx->fd, FIONBIO, &n ) ); | ||
#else | ||
- return( fcntl( ctx->fd, F_SETFL, fcntl( ctx->fd, F_GETFL ) & ~O_NONBLOCK ) ); | ||
+ return( syscall( SYS_fcntl, ctx->fd, F_SETFL, syscall(SYS_fcntl, ctx->fd, F_GETFL ) & ~O_NONBLOCK ) ); | ||
#endif | ||
} | ||
|
||
@@ -473,7 +474,7 @@ int mbedtls_net_set_nonblock( mbedtls_net_context *ctx ) | ||
u_long n = 1; | ||
return( ioctlsocket( ctx->fd, FIONBIO, &n ) ); | ||
#else | ||
- return( fcntl( ctx->fd, F_SETFL, fcntl( ctx->fd, F_GETFL ) | O_NONBLOCK ) ); | ||
+ return( syscall( SYS_fcntl, ctx->fd, F_SETFL, syscall( SYS_fcntl, ctx->fd, F_GETFL ) | O_NONBLOCK ) ); | ||
#endif | ||
} | ||
|