From b3baeedca9ca522fc6646509b3a17f89f8307b72ea2e1d5864003d27f828e4b4 Mon Sep 17 00:00:00 2001 From: Matej Cepl Date: Fri, 7 Feb 2025 19:25:18 +0000 Subject: [PATCH] - Add 314a4-no-SO_REUSEPORT.patch to fix build on new kernel (gh#python/cpython#128916). OBS-URL: https://build.opensuse.org/package/show/devel:languages:python:Factory/python314?expand=0&rev=36 --- 314a4-no-SO_REUSEPORT.patch | 94 +++++++++++++++++++++++++++++++++++++ python314.changes | 2 + python314.spec | 3 ++ 3 files changed, 99 insertions(+) create mode 100644 314a4-no-SO_REUSEPORT.patch diff --git a/314a4-no-SO_REUSEPORT.patch b/314a4-no-SO_REUSEPORT.patch new file mode 100644 index 0000000..f3df8ca --- /dev/null +++ b/314a4-no-SO_REUSEPORT.patch @@ -0,0 +1,94 @@ +From 1afcfaa5ce01cd949e570bc9035b3a7b6ccdd2be Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= +Date: Fri, 17 Jan 2025 11:46:19 +0100 +Subject: [PATCH 1/2] gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` + sockets + +Do not attempt to set ``SO_REUSEPORT`` on sockets of address familifies other +than ``AF_INET`` and ``AF_INET6``, as it is meaningless with these address +families, and the call with fail with Linux kernel 6.12.9 and newer. +--- + Lib/asyncio/base_events.py | 4 +++- + Lib/socket.py | 4 +++- + Lib/socketserver.py | 7 ++++++- + .../Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst | 3 +++ + 4 files changed, 15 insertions(+), 3 deletions(-) + create mode 100644 Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst + +diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py +index 6e6e5aaac15caf..85018797db33bb 100644 +--- a/Lib/asyncio/base_events.py ++++ b/Lib/asyncio/base_events.py +@@ -1593,7 +1593,9 @@ async def create_server( + if reuse_address: + sock.setsockopt( + socket.SOL_SOCKET, socket.SO_REUSEADDR, True) +- if reuse_port: ++ # Since Linux 6.12.9, SO_REUSEPORT is not allowed ++ # on other address families than AF_INET/AF_INET6. ++ if reuse_port and af in (socket.AF_INET, socket.AF_INET6): + _set_reuseport(sock) + if keep_alive: + sock.setsockopt( +diff --git a/Lib/socket.py b/Lib/socket.py +index be37c24d6174a2..727b0e75f03595 100644 +--- a/Lib/socket.py ++++ b/Lib/socket.py +@@ -937,7 +937,9 @@ def create_server(address, *, family=AF_INET, backlog=None, reuse_port=False, + # Fail later on bind(), for platforms which may not + # support this option. + pass +- if reuse_port: ++ # Since Linux 6.12.9, SO_REUSEPORT is not allowed ++ # on other address families than AF_INET/AF_INET6. ++ if reuse_port and family in (AF_INET, AF_INET6): + sock.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1) + if has_ipv6 and family == AF_INET6: + if dualstack_ipv6: +diff --git a/Lib/socketserver.py b/Lib/socketserver.py +index cd028ef1c63b85..35b2723de3babe 100644 +--- a/Lib/socketserver.py ++++ b/Lib/socketserver.py +@@ -468,7 +468,12 @@ def server_bind(self): + """ + if self.allow_reuse_address and hasattr(socket, "SO_REUSEADDR"): + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) +- if self.allow_reuse_port and hasattr(socket, "SO_REUSEPORT"): ++ # Since Linux 6.12.9, SO_REUSEPORT is not allowed ++ # on other address families than AF_INET/AF_INET6. ++ if ( ++ self.allow_reuse_port and hasattr(socket, "SO_REUSEPORT") ++ and self.address_family in (socket.AF_INET, socket.AF_INET6) ++ ): + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) + self.socket.bind(self.server_address) + self.server_address = self.socket.getsockname() +diff --git a/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst b/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst +new file mode 100644 +index 00000000000000..5d13825fb2b6ab +--- /dev/null ++++ b/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst +@@ -0,0 +1,3 @@ ++Do not attempt to set ``SO_REUSEPORT`` on sockets of address familifies ++other than ``AF_INET`` and ``AF_INET6``, as it is meaningless with these ++address families, and the call with fail with Linux kernel 6.12.9 and newer. + +From 8f8f0d67742ce151ea9b104ad0396660e2660b09 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= +Date: Fri, 17 Jan 2025 11:57:41 +0000 +Subject: [PATCH 2/2] Apply suggestions from code review + +Co-authored-by: Vinay Sajip +--- + .../next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst b/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst +index 5d13825fb2b6ab..f2db341ef81621 100644 +--- a/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst ++++ b/Misc/NEWS.d/next/Library/2025-01-17-11-46-16.gh-issue-128916.GEePbO.rst +@@ -1,3 +1,3 @@ +-Do not attempt to set ``SO_REUSEPORT`` on sockets of address familifies ++Do not attempt to set ``SO_REUSEPORT`` on sockets of address families + other than ``AF_INET`` and ``AF_INET6``, as it is meaningless with these + address families, and the call with fail with Linux kernel 6.12.9 and newer. diff --git a/python314.changes b/python314.changes index eb739a5..622b0f0 100644 --- a/python314.changes +++ b/python314.changes @@ -4,6 +4,8 @@ Tue Feb 4 14:43:13 UTC 2025 - Matej Cepl - Add CVE-2025-0938-sq-brackets-domain-names.patch which disallows square brackets ([ and ]) in domain names for parsed URLs (bsc#1236705, CVE-2025-0938, gh#python/cpython#105704) +- Add 314a4-no-SO_REUSEPORT.patch to fix build on new kernel + (gh#python/cpython#128916). ------------------------------------------------------------------- Mon Jan 27 09:16:22 UTC 2025 - Daniel Garcia diff --git a/python314.spec b/python314.spec index 02e6157..c2d9409 100644 --- a/python314.spec +++ b/python314.spec @@ -219,6 +219,9 @@ Patch40: fix-test-recursion-limit-15.6.patch # PATCH-FIX-UPSTREAM CVE-2025-0938-sq-brackets-domain-names.patch bsc#1236705 mcepl@suse.com # functions `urllib.parse.urlsplit` and `urlparse` accept domain names including square brackets Patch41: CVE-2025-0938-sq-brackets-domain-names.patch +# PATCH-FIX-UPSTREAM 314a4-no-SO_REUSEPORT.patch gh#python/cpython#128916 mcepl@suse.com +# changes in kernel break Python tests +Patch42: 314a4-no-SO_REUSEPORT.patch #### Python 3.14 DEVELOPMENT PATCHES BuildRequires: autoconf-archive BuildRequires: automake