diff mbox series

[master,mickledore] glib-2.0: Avoid having g_futex_simple() inadvertently modify errno

Message ID 20230426150939.426088-1-pkj@axis.com
State New
Headers show
Series [master,mickledore] glib-2.0: Avoid having g_futex_simple() inadvertently modify errno | expand

Commit Message

Peter Kjellerstedt April 26, 2023, 3:09 p.m. UTC
From: Peter Kjellerstedt <peter.kjellerstedt@axis.com>

If both __NR_futex and __NR_futex_time64 are defined, g_futex_simple()
will first call futex_time64(). If that fails with ENOSYS, then
futex_time() is called instead. However, errno was not saved and
restored in this case, which would result in g_futex_simple()
returning with errno set to ENOSYS, even if futex_time() succeeded.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
---
 ...utex_simple-inadvertently-modify-err.patch | 36 +++++++++++++++++++
 meta/recipes-core/glib-2.0/glib-2.0_2.74.6.bb |  1 +
 2 files changed, 37 insertions(+)
 create mode 100644 meta/recipes-core/glib-2.0/glib-2.0/0001-Avoid-having-g_futex_simple-inadvertently-modify-err.patch
diff mbox series

Patch

diff --git a/meta/recipes-core/glib-2.0/glib-2.0/0001-Avoid-having-g_futex_simple-inadvertently-modify-err.patch b/meta/recipes-core/glib-2.0/glib-2.0/0001-Avoid-having-g_futex_simple-inadvertently-modify-err.patch
new file mode 100644
index 0000000000..db63cfd91e
--- /dev/null
+++ b/meta/recipes-core/glib-2.0/glib-2.0/0001-Avoid-having-g_futex_simple-inadvertently-modify-err.patch
@@ -0,0 +1,36 @@ 
+From edd1e47f107410d9e4edb691335410026ae5a534 Mon Sep 17 00:00:00 2001
+From: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
+Date: Tue, 25 Apr 2023 20:02:31 +0200
+Subject: [PATCH] Avoid having g_futex_simple() inadvertently modify errno
+
+If both __NR_futex and __NR_futex_time64 are defined, g_futex_simple()
+will first call futex_time64(). If that fails with ENOSYS, then
+futex_time() is called instead. However, errno was not saved and
+restored in this case, which would result in g_futex_simple()
+returning with errno set to ENOSYS, even if futex_time() succeeded.
+
+Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/glib/-/commit/edd1e47f107410d9e4edb691335410026ae5a534]
+Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
+---
+ glib/gthreadprivate.h | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h
+index 9c847e039..74d37ba32 100644
+--- a/glib/gthreadprivate.h
++++ b/glib/gthreadprivate.h
+@@ -65,9 +65,13 @@ struct  _GRealThread
+ #define g_futex_simple(uaddr, futex_op, ...)                                     \
+   G_STMT_START                                                                   \
+   {                                                                              \
++    int saved_errno = errno;                                                     \
+     int res = syscall (__NR_futex_time64, uaddr, (gsize) futex_op, __VA_ARGS__); \
+     if (res < 0 && errno == ENOSYS)                                              \
+-      syscall (__NR_futex, uaddr, (gsize) futex_op, __VA_ARGS__);                \
++      {                                                                          \
++        errno = saved_errno;                                                     \
++        syscall (__NR_futex, uaddr, (gsize) futex_op, __VA_ARGS__);              \
++      }                                                                          \
+   }                                                                              \
+   G_STMT_END
+ #elif defined(__NR_futex_time64)
diff --git a/meta/recipes-core/glib-2.0/glib-2.0_2.74.6.bb b/meta/recipes-core/glib-2.0/glib-2.0_2.74.6.bb
index 5b79ae481c..08a0878496 100644
--- a/meta/recipes-core/glib-2.0/glib-2.0_2.74.6.bb
+++ b/meta/recipes-core/glib-2.0/glib-2.0_2.74.6.bb
@@ -16,6 +16,7 @@  SRC_URI = "${GNOME_MIRROR}/glib/${SHRT_VER}/glib-${PV}.tar.xz \
            file://0001-gio-tests-resources.c-comment-out-a-build-host-only-.patch \
            file://0001-gio-tests-g-file-info-don-t-assume-million-in-one-ev.patch \
            file://0001-gio-tests-meson.build-do-not-use-can_run_host_binari.patch \
+           file://0001-Avoid-having-g_futex_simple-inadvertently-modify-err.patch \
            file://cpp-null.patch \
            file://cpp-null2.patch \
            "