summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-10-06 19:14:16 (GMT)
committerGitHub <noreply@github.com>2022-10-06 19:14:16 (GMT)
commit3d89ac2f4c573f5facde11579db0791832f5b392 (patch)
tree89c32530996894126e5518630b56beff5b7c8607 /Modules
parent537c93ea3b822b4dc039c35ea1375046a9e95c7a (diff)
downloadcpython-3d89ac2f4c573f5facde11579db0791832f5b392.zip
cpython-3d89ac2f4c573f5facde11579db0791832f5b392.tar.gz
cpython-3d89ac2f4c573f5facde11579db0791832f5b392.tar.bz2
[3.10] gh-97897: Prevent os.mkfifo and os.mknod segfaults with macOS 13 SDK (GH-97944) (#97967)
The macOS 13 SDK includes support for the `mkfifoat` and `mknodat` system calls. Using the `dir_fd` option with either `os.mkfifo` or `os.mknod` could result in a segfault if cpython is built with the macOS 13 SDK but run on an earlier version of macOS. Prevent this by adding runtime support for detection of these system calls ("weaklinking") as is done for other newer syscalls on macOS. (cherry picked from commit 6d0a0191a4e5477bd843e62c24d7f3bcad4fd5fc) Co-authored-by: Ned Deily <nad@python.org>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c60
1 files changed, 52 insertions, 8 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 3d74b22..0b8b41c 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -85,6 +85,8 @@
# define HAVE_FUTIMENS_RUNTIME __builtin_available(macOS 10.13, iOS 11.0, tvOS 11.0, watchOS 4.0, *)
# define HAVE_UTIMENSAT_RUNTIME __builtin_available(macOS 10.13, iOS 11.0, tvOS 11.0, watchOS 4.0, *)
# define HAVE_PWRITEV_RUNTIME __builtin_available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
+# define HAVE_MKFIFOAT_RUNTIME __builtin_available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
+# define HAVE_MKNODAT_RUNTIME __builtin_available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
# define HAVE_POSIX_SPAWN_SETSID_RUNTIME __builtin_available(macOS 10.15, *)
@@ -169,6 +171,8 @@
# define HAVE_FUTIMENS_RUNTIME 1
# define HAVE_UTIMENSAT_RUNTIME 1
# define HAVE_PWRITEV_RUNTIME 1
+# define HAVE_MKFIFOAT_RUNTIME 1
+# define HAVE_MKNODAT_RUNTIME 1
#endif
@@ -10554,18 +10558,35 @@ os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd)
{
int result;
int async_err = 0;
+#ifdef HAVE_MKFIFOAT
+ int mkfifoat_unavailable = 0;
+#endif
do {
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_MKFIFOAT
- if (dir_fd != DEFAULT_DIR_FD)
- result = mkfifoat(dir_fd, path->narrow, mode);
- else
+ if (dir_fd != DEFAULT_DIR_FD) {
+ if (HAVE_MKFIFOAT_RUNTIME) {
+ result = mkfifoat(dir_fd, path->narrow, mode);
+
+ } else {
+ mkfifoat_unavailable = 1;
+ result = 0;
+ }
+ } else
#endif
result = mkfifo(path->narrow, mode);
Py_END_ALLOW_THREADS
} while (result != 0 && errno == EINTR &&
!(async_err = PyErr_CheckSignals()));
+
+#ifdef HAVE_MKFIFOAT
+ if (mkfifoat_unavailable) {
+ argument_unavailable_error(NULL, "dir_fd");
+ return NULL;
+ }
+#endif
+
if (result != 0)
return (!async_err) ? posix_error() : NULL;
@@ -10606,18 +10627,33 @@ os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
{
int result;
int async_err = 0;
+#ifdef HAVE_MKNODAT
+ int mknodat_unavailable = 0;
+#endif
do {
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_MKNODAT
- if (dir_fd != DEFAULT_DIR_FD)
- result = mknodat(dir_fd, path->narrow, mode, device);
- else
+ if (dir_fd != DEFAULT_DIR_FD) {
+ if (HAVE_MKNODAT_RUNTIME) {
+ result = mknodat(dir_fd, path->narrow, mode, device);
+
+ } else {
+ mknodat_unavailable = 1;
+ result = 0;
+ }
+ } else
#endif
result = mknod(path->narrow, mode, device);
Py_END_ALLOW_THREADS
} while (result != 0 && errno == EINTR &&
!(async_err = PyErr_CheckSignals()));
+#ifdef HAVE_MKNODAT
+ if (mknodat_unavailable) {
+ argument_unavailable_error(NULL, "dir_fd");
+ return NULL;
+ }
+#endif
if (result != 0)
return (!async_err) ? posix_error() : NULL;
@@ -15466,6 +15502,14 @@ PROBE(probe_fdopendir, HAVE_FDOPENDIR_RUNTIME)
PROBE(probe_mkdirat, HAVE_MKDIRAT_RUNTIME)
#endif
+#ifdef HAVE_MKFIFOAT
+PROBE(probe_mkfifoat, HAVE_MKFIFOAT_RUNTIME)
+#endif
+
+#ifdef HAVE_MKNODAT
+PROBE(probe_mknodat, HAVE_MKNODAT_RUNTIME)
+#endif
+
#ifdef HAVE_RENAMEAT
PROBE(probe_renameat, HAVE_RENAMEAT_RUNTIME)
#endif
@@ -15599,11 +15643,11 @@ static const struct have_function {
#endif
#ifdef HAVE_MKFIFOAT
- { "HAVE_MKFIFOAT", NULL },
+ { "HAVE_MKFIFOAT", probe_mkfifoat },
#endif
#ifdef HAVE_MKNODAT
- { "HAVE_MKNODAT", NULL },
+ { "HAVE_MKNODAT", probe_mknodat },
#endif
#ifdef HAVE_OPENAT