Skip to content

Commit

Permalink
let runc work with glibc lt 2.32 in go 1.22.x
Browse files Browse the repository at this point in the history
In glibc versions older than 2.32 (before commit 4721f95058),
pthread_getattr_np does not always initialize the `attr` argument,
and when it fails, it results in a NULL pointer dereference in
pthread_attr_destroy down the road. This has been fixed in go 1.22.4.
We hack this to let runc can work with glibc < 2.32 in go 1.22.x,
once runc doesn't support 1.22, we can remove this hack.

Signed-off-by: lifubang <[email protected]>
  • Loading branch information
lifubang committed Jun 6, 2024
1 parent 8fc5be4 commit 3c2ca11
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions libcontainer/nsenter/nsenter_go122.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
//go:build go1.22
//go:build go1.22 && !go1.23

package nsenter

/*
// We know for sure that glibc has issues with pthread_self() when called from
// Go after nsenter has run. This is likely a more general problem with how we
// ignore the rules in signal-safety(7), and so it's possible musl will also
// have issues, but as this is just a hotfix let's only block glibc builds.
// In glibc versions older than 2.32 (before commit 4721f95058),
// pthread_getattr_np does not always initialize the `attr` argument,
// and when it fails, it results in a NULL pointer dereference in
// pthread_attr_destroy down the road. This has been fixed in go 1.22.4.
// We hack this to let runc can work with glibc < 2.32 in go 1.22.x,
// once runc doesn't support 1.22, we can remove this hack.
#cgo LDFLAGS: -Wl,--wrap=pthread_getattr_np
#include <features.h>
#ifdef __GLIBC__
# error "runc does not currently work properly with Go >=1.22. See <https://github.com/opencontainers/runc/issues/4233>."
#include <pthread.h>
int __real_pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr);
int __wrap_pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr) {
#if __GLIBC__ && defined(__GLIBC_PREREQ)
# if !__GLIBC_PREREQ(2, 32)
pthread_attr_init(__attr);
# endif
#endif
return __real_pthread_getattr_np(__th, __attr);
}
*/
import "C"

0 comments on commit 3c2ca11

Please sign in to comment.