From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 9328580A42 for ; Wed, 14 Oct 2026 17:17:53 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 69EHGc5M001614; Wed, 14 Oct 2026 20:16:39 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69EHGc5M001614 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="cPZDtyZg" Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 69EHGYHW001599 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 14 Oct 2026 20:16:34 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69EHGYHW001599 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-48c437ae81eso516375f8f.1 for ; Wed, 14 Oct 2026 10:16:34 -0700 (PDT) X-Gm-Message-State: AFq9FYLu0RqkT4+w/5pFIm7yqmF59syT281rrvm4bFa5xlomxTLrWSV2 niDTi4pQkTAjcZWp8vHByv6Otq8HZ1nhGY3K5XA0Vi2u1wVi7Ko6zfy1B2Z1/Lxf4wLEIEJBJZp YBcO09uU4q+LtmbD7Jg8lCbi8hFcXwyPBZ6Vg9iCBx5JRPbFydNr1gQ== X-Gm-Gg: AYBFou1UWz+9J60Dqn4B3+VFrXoRXEw9wL6NSLUAgBnqyex/cEuadHWYvgtYSrklYNE HgfBj+JQhwcZWh6ZntnIIQ3UBZQ0KwwilIemtOOu6ME6BWIzgUayUUeWPcu0Y93A96zR0Jf5/mY CrzEyVEL+nyV/7tUmgRzyzFyP+YtZ3cgct58L+9wxbKh6ittySlwHdp7NVYltSG8I0xHzHbXVD+ 6+4O/BByaeChXYG7WkX/XWmrBjEN2FjPngnugw+jN7GFjVxjuiCt3SIDok7tpwNG7rhw8waBGVX TKMy9vkGqo1s9302LCPfF4RWfxPop2SBSfO8Hg5Jyn9rnl9ppoZFkujJzOMU7jDqRoFkGypnaqs l09qA4JVgegYIybE2DQ== X-Received: by 2002:a05:6000:605:b0:48d:f383:2356 with SMTP id ffacd0b85a97d-48df383248cmr15067f8f.53.1791998194479; Wed, 14 Oct 2026 10:16:34 -0700 (PDT) X-Received: by 2002:a05:6000:605:b0:48d:f383:2356 with SMTP id ffacd0b85a97d-48df383248cmr14807f8f.53.1791998192433; Wed, 14 Oct 2026 10:16:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1791998192; cv=none; d=google.com; s=arc-20260327; b=mPZLC6qgMsI6SMAO2RQ3KY7T+0Jk56YUVSmjkkb8wM9N4nPSroT0zcfnzDih8WNHzU juFFqn2XNDtdfZuDAqArMjF8tcl2bUhjduA0BHvnG0arROgOu/7DP53V18lkCTwGNCpb J/QNDPmrzqBnLvfvw39Hh70h2K+NCjwdzhxrYQK6yi9Xf3NRurLiI91U+g4A/RxiXGH0 Kng5ooan16eCiamrBoywrH1a8NEjQBY3rEpJeFUmEAX0gOGRV/s84+i5fRqrICBcN6wm brXMa5FXnQy/h/inhRoD4Mntyv+qyRz0sqhWdLAPdXHbNPSnLQXd0tR55GKc1gsHAmpA 7/9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=8ykZCjEYZG0hDQZNESxLEStxKIxc/pp1EKSLO0a0JCQ=; fh=aQfw1i5a4NQPWqzJLDKkrMTvdRoUn/cswL6yDWdmKfA=; b=UvAGiTeH9bSZ60ClbNbVN3qS0Qar5qvhPyF14+nLH8+EOhFgMG5Ngkcfru/QqQCSgI hl0cVbuspb8WOE9Kt+a0VSpKcNxHABOGVjSNF+k4si0NhBSwUXTAqP2IjgzmIT7gUPux br42Lk579MM29Dd4WFZy0psGz8KAEPFSaEiGVoSVLeT+qGJKwlf+Qt8Jeojm3rKBn1uw szH1NZV7H0O63tQL0yQ/xlieIIUDh0baSwaK95b4nI7Mx/PI/qewcp6gwpb6mhQbiYMm flNbobneP0/bRrg6dH43tVoDCuH0CVySzK5TgFXOKG/UjHCJ1PPwq1/F1Hiw6baDOxeP zHTA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=cPZDtyZg; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-48df21b68easi748093f8f.0.2026.10.14.10.16.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Oct 2026 10:16:32 -0700 (PDT) Received-SPF: pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=cPZDtyZg; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=8ykZCjEYZG0hDQZNESxLEStxKIxc/pp1EKSLO0a0JCQ=; b=cPZDtyZg2PjncHyILXV Urt8JaqehiZ2oKAI2NxID2L2+o8/eGT6pmoyMCcc4hUkzpSUOdnlDKY4AMn/NGrr5D1px1RIbVgv4 FzCNwNgLE6SucheReI77qImt9+5s0FLKHC8UyAVjsRgN6JNVHH2Nc5SApfHNAOhxEx9NuA9Sp6I1g eVDE1BI2NZU9LsR7vyHKTLrmHpUBAtdcWLU3X83nUxmCqQ0QWKPnKoIWbNDSkOI0N1IcHQ1Qp5Mfu ZM1d/hht3tt+II/qMqxPiGkRFEPyhdDvw0qL0b0UKONM/sjvIMtpxp06JFNHj+4B71r6lzch2UO3S JBxGXCYpieSxEqg==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=f0.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xH2XD-0087Hi-01; Wed, 14 Oct 2026 19:16:31 +0200 From: Konstantin Khorenko Date: Wed, 14 Oct 2026 19:16:27 +0200 MIME-Version: 1.0 Message-Id: <20261014-b4-prep-khorenko-vstor-149847-6-vfio-exec-ms-backports-v1-2-07b4e541d4ec@virtuozzo.com> References: <20261014-b4-prep-khorenko-vstor-149847-6-vfio-exec-ms-backports-v1-0-07b4e541d4ec@virtuozzo.com> In-Reply-To: <20261014-b4-prep-khorenko-vstor-149847-6-vfio-exec-ms-backports-v1-0-07b4e541d4ec@virtuozzo.com> To: Vasileios Almpanis , Andrey Drobyshev , Pavel Tikhomirov X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3546; i=khorenko@virtuozzo.com; h=from:subject:message-id; bh=ujNU4cFX1zfWBdjZSCGGh5YqfEVbIwO1WgICdzPnl0M=; b=owEBbQKS/ZANAwAKAVGWCkf5YVwqAcsmYgBqz7jvqZl8cnMMUSQmXBYgGkIXTt8KlAg++EkdK Hg60XbSWbeJAjMEAAEKAB0WIQRWD23IPcXT0GO9CCxRlgpH+WFcKgUCas+47wAKCRBRlgpH+WFc Kvs8EADAPRqElHkUBRrwvTm+xRqelSQlX85t9VxI+MDkdBSBE1qAZyAbXuebN4qnX8zVtk1GGUU z+o0ivSA7iUyli3ZVADvBloitk1J2Ooo9wNjj8fX64ik4TdXW9d+TLHinvVe7aGT01hmJv7NFHZ dRC+8YjYZCIztkzXWYh09Z54ElK7oU6QRCj/6QxzvtpXHFKH28LZ1ReXfVj7wYg/b0oEY8Cklo8 BCDkzWmJ79Jj8Lk6mL+oZNGtrExDLwvx4YZ4BAa2i1XgAplHCf/PSbT2/CCPIQDRXukVsAUouao sEEpFQ/UIvPnhpea6bG3SOJCtNVOljeAtdx08uMzt2v6smKFQm8OelDZpTOA+su70GupGzsyBGi R14+58YhsJ6YddMM/6Iq4efhHTrMhd0TbTujjKOnU5WVy3X0qlH9FY7yBhAbwNTajqyWpgaK8Ua Gz+lW9aTd/JlbKkMIN7zle+8ZSC6FmFMK+jsAnPNgJCTAma7jzwRYM3d62kc8X1xujHEvGSuK0o WI/6BpAbZGyhRYODzCYT4rAnq88DigdhjwFzX/EV99GtgT0wpnwk1fc/nA3l1fz3fNQVzcbzOjE LEgMO1h00j1P/vtOidnms0MxOsnmZ+lsoOWRjWTNE10o0o2gDCr8Uo0uN+7MvLJMIxHWuTrh3sn mbgkSG3BSJyeqUQ== X-Developer-Key: i=khorenko@virtuozzo.com; a=openpgp; fpr=560F6DC83DC5D3D063BD082C51960A47F9615C2A X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 2/2] ms/exec: do_close_on_exec() before taking exec_update_lock X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Jann Horn do_close_on_exec() currently happens while holding the exec_update_lock, which is used in a lot of places that access process state to synchronize access checks. I recently added another such use of exec_update_lock, causing a regression. do_close_on_exec() can block waiting for a reply from a filesystem. That means a hung filesystem can block codepaths that use exec_update_lock; and it also means that a FUSE filesystem which attempts to inspect the calling process can deadlock. To avoid such problems, move do_close_on_exec() before the exec_update_lock is taken, but after the FD table has been copied if necessary. I have looked through all the calls between the old and new position of the do_close_on_exec() call; there seems to be no file descriptor table access in between. Reported-by: Benjamin Peterson Closes: https://lore.kernel.org/r/f5e8166a-88be-46c5-8939-1e5227ffe4c2@app.fastmail.com Fixes: 6650527444da ("proc: protect ptrace_may_access() with exec_update_lock (part 1)") Cc: stable@vger.kernel.org Signed-off-by: Jann Horn Link: https://patch.msgid.link/20260907-cloexec-before-exec-update-lock-v1-1-8018c201a7df@google.com Tested-by: Benjamin Peterson Reviewed-by: Jan Kara Signed-off-by: Christian Brauner (Amutable) (cherry picked from commit e780259b54e618ceb4763fbc21314acf3565e813) Backport note: the Fixes: target 6650527444da is not in this tree, but exec_update_lock already has readers here that a hung or self-inspecting FUSE flush blocks: mm_access() (/proc/PID/maps, mem, environ and the like, process_vm_readv()), lock_trace(), /proc/PID/io, pidfd_getfd(), kcmp(), get_robust_list() and perf_event_open(). vz fuse_flush() sends FLUSH only for files open for writing. https://virtuozzo.atlassian.net/browse/VSTOR-150235 Feature: fix ms/exec Assisted-by: LLM Signed-off-by: Konstantin Khorenko --- fs/exec.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index e861a54b491f8..3b3412bcd7276 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1305,6 +1305,20 @@ int begin_new_exec(struct linux_binprm * bprm) if (retval) goto out; + /* + * We have to apply CLOEXEC before we change whether the process is + * dumpable (in setup_new_exec) to avoid a race with a process in userspace + * trying to access the should-be-closed file descriptors of a process + * undergoing exec(2). + * + * This can block on filesystem ->flush() handlers, including waiting + * for FUSE daemons, so do it before exec_mmap takes the + * exec_update_lock. + * This must happen after the point of no return, and after unsharing + * the FD table. + */ + do_close_on_exec(me->files); + /* * Must be called _before_ exec_mmap() as bprm->mm is * not visible until then. Doing it here also ensures @@ -1355,14 +1369,6 @@ int begin_new_exec(struct linux_binprm * bprm) clear_syscall_work_syscall_user_dispatch(me); - /* - * We have to apply CLOEXEC before we change whether the process is - * dumpable (in setup_new_exec) to avoid a race with a process in userspace - * trying to access the should-be-closed file descriptors of a process - * undergoing exec(2). - */ - do_close_on_exec(me->files); - if (bprm->secureexec) { /* Make sure parent cannot signal privileged process. */ me->pdeath_signal = 0; -- 2.43.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel