From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 690A08045D for ; Thu, 29 Oct 2026 22:36:27 +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 69TMZBLb005385; Fri, 30 Oct 2026 01:35:12 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69TMZBLb005385 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1793313314; bh=Bhk5cJB+z7znhDz84iTayEk9e2DiUSMAMQH1LrXGTjY=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=TQ66IpbrVGN7rwzD2UZg8Gt4DdDJSKrmpXw+HZ4uaXr24gC4WxfuaIpM5DYLVSZQ2 YFwb2HB6NbNpPZFfNWZNhIVFipXEJlrwjw+i5Gibb56ZzFchcB/bqGkZ62Si08VBlQ kICCiI6x8x2CW4flUy7iMHXtllg03fGxPbq1D5dypmLecoWqEXGr15PTwXseQ2ZQDj 6YbjLZLN/yLFal6tlHMtotit9H2uAxea/xaCa4Z+D9spBQQgaK4gi7BHlL5tKZZ73L IhzUrxygSsk93sEtYoY2eQCX0JSwzZL3zJLsshlqTD98iZ+sA0kkNpEaNXBcEbUYZH Zib4VN6J/rBTQ== 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 69TMZ81D005381 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Fri, 30 Oct 2026 01:35:08 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69TMZ81D005381 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="NMGbQ/gb" Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-48e4d1e29f3so74226f8f.3 for ; Thu, 29 Oct 2026 15:35:08 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvByFfyDGfy1GOtdjSD98Zf71tHAm3fbww91tLsnMC5XhiWK7q1IfKAJlkNAOjamKAFc+t0Plrg==@openvz.org X-Gm-Message-State: AFq9FYLRpg1rGfDm8WGI/2DSe2k7B/UJ+dyh+C2FtVVQmZg+iPB25J9n Z++m/1IeVrs96oMw1divNLmdbceDR7nqPJ2hKkceGLPbWsx5lsC6ocW3itAA8Sx2VYSbWI8ZVph Sie5qBQ3gzlB6BYtvrMU5210mGmHHQx6XlceLKvN1FO6Z5eDzfzE9WA== X-Gm-Gg: AYBFou0XzKvjWgnDD1LjfiQlc+3p048jQcY9G+nq0FBWE420RCR12+daGyTtQfi9BPo pKRRuxqol2nimf30JVobkWhU2UR604uZXW4fgEyddGrixAgqMNOKxOqj0pYTwNJwEmN/tL7OWM4 tzc0i24e/bMtt16fX8Ce1vwFaS50LjEMXDbekexOQhZCZCQ1rotgZNw6F8pswdx0U+7sKLUunKe 98ttuRHDR2ccj1um2yvTHd23Ge8iFMr4EFdlOCD8uk6QJEYcTx2ctIxspIiLLp6w9jr55SGo7S2 lcjXlkd3Sg== X-Received: by 2002:adf:fa81:0:b0:48e:2114:8ab9 with SMTP id ffacd0b85a97d-48e6e4f578bmr1258512f8f.31.1793313307963; Thu, 29 Oct 2026 15:35:07 -0700 (PDT) X-Received: by 2002:adf:fa81:0:b0:48e:2114:8ab9 with SMTP id ffacd0b85a97d-48e6e4f578bmr1258485f8f.31.1793313307466; Thu, 29 Oct 2026 15:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1793313307; cv=none; d=google.com; s=arc-20260327; b=CTqAE4103S3RSKLWpxinTInLXuq3csld0Qc1Qb4PyGGv3fC/EwmiE/+uKJyDsNJfdu 6ZFzdfJT7VAcBoTcqYywJxYuxF9fsWBVxChNrcA+aGkLOLIcMnlpgDOKZJgNumQdbiHD zxJSrk2xsMEmQxi4ElCpsb0fu0fKXbrqDvcdThBCAmbF9w892droOlyhsaj3B/wRIHuk e6L19Q5UNxgb8QKRPvLMVLVwkzR62iaMiRVlpcynHRVHKwliQDSly9bImNLxSprUyyKz QmOLOBbd0pGEuwn/YMIunfHhgTda9SgJ4VTrEl1RHDcoUng0lwzxPllRLLLRAsVrMug2 4ozg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=3wDOTTXPnmUluk6BTHgXc9xlRmfpM4JGzpgkWACzz+c=; fh=PcGk/VnIgXRcZDF6ojTqMVUGrU9lD13jFsOMbWayKDY=; b=NiD2ozu+Xx4/XKYQ1EMowt/7D64e7fCiaLQGLhc6gj2ro+lSj8809ncl319gipi0vE uH0vklCdN01dyXnaCLeoLlYjLQvPK2mYvEkkfxf+JtYbgKEEZUOw3SHRf985DY7uyKSY VeWoKT3sAEK4EnZElmH77ysP1hGxm+WByZIsbV0s/e/jE5tDnRGZWfic/xK8pXs0V/n/ 59UnfNpcteMbD/ibxu6TCQpQVsyapLO19P+pdCM9OItRB1Y55TPOQ260Dez4Go2dSRjE t2LEfXF9qYBPU+iQGZc9EKvi0ibkejzLhivrNZimjH2YG+cyLGK2tl+3KIQFBu5mIcXt CSpA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b="NMGbQ/gb"; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:f4be:f111:4ee0:40d3 as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id ffacd0b85a97d-48e6df7dec4sor173839f8f.10.2026.10.29.15.35.07 for (Google Transport Security); Thu, 29 Oct 2026 15:35:07 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:f4be:f111:4ee0:40d3 as permitted sender) client-ip=2a06:5b06:b600:300:f4be:f111:4ee0:40d3; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b="NMGbQ/gb"; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:f4be:f111:4ee0:40d3 as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793313307; x=1793918107; darn=openvz.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=3wDOTTXPnmUluk6BTHgXc9xlRmfpM4JGzpgkWACzz+c=; b=NMGbQ/gb4wzd5aNRd4zc9KM3a52Tv8PF08xgRcsmYe5EEiY01Y+EQeLI85OgB6w2NT Fgvtqq3GpLW1WZnAa4IyCQELeV/SJ1Rgk0O115JJfOQNaY7v/HJUhqUcZI+7iOCGTC/F nRk7LTbRd0Vmq26cKW0NaMYQawGIURyIVWdtWAWIM6qc8nhzFDyCgTeR8OmxA+dPQ5t8 wVmSIg2oAXf9WzA/3rILz5LO5hRL1Ej/aB1K3SFiVfjrQ4luM4P+JmHKjsAvlZFpALOm stlWIM1GFoE4D+MgwwkKOyciZqh/y7imGW3EkLodMz4m5K6w6/PC+Nx/wkvNriX0tVoG 3/EA== X-Forwarded-Encrypted: i=1; AKwUvBxU/PyhlJpECXX/a4Pu7zwgiwF7CqvqF/nQ61DnKJHrAeTJBpDxigWK7xd/7BfSdJXP8W2IWw==@openvz.org X-Received: by 2002:a5d:6f0e:0:b0:487:27f9:842 with SMTP id ffacd0b85a97d-48e6e50d96amr1607993f8f.55.1793313306884; Thu, 29 Oct 2026 15:35:06 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:f4be:f111:4ee0:40d3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e7123f399sm233594f8f.0.2026.10.29.15.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 15:35:06 -0700 (PDT) From: "Denis V. Lunev" To: eva.kurchatova@virtuozzo.com, vasileios.almpanis@virtuozzo.com Date: Thu, 29 Oct 2026 23:35:02 +0100 Message-ID: <20261029223502.1437160-1-den@openvz.org> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1] ve/vtty: fix console attach failing with EBUSY while the CT closes the tty 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: Denis V. Lunev Since commit 23abb203a41a ("ve/vtty: fix use-after-free on concurrent tty close and reopen") vtty_open_master() refuses a pair whose slave count has dropped to zero: the last CT-side close has committed to the final close, and the pair stays in the vtty map only until release_tty() runs. The refusal is -EBUSY, the errno which already means a console is attached, so userspace cannot tell a pair that is about to go from one that is taken, and vzctl gives up: Error opening CT tty: Device or resource busy The window opens whenever the last process in the CT closes its tty: getty respawn, login with autologin, SAK. "vzctl console" run right after "vzctl start --wait" hits it. Return -EAGAIN for the dying pair. Nothing else on the VE_CONFIGURE_OPEN_TTY path returns -EAGAIN, so it can only mean "try again", which is what vzctl will do. An in-CT open of such a pair gets -EAGAIN from tty_reopen() and tty_open() retries it the same way. Retrying inside vtty_open_master() instead would have to drop tty_mutex for release_tty() to progress, and the global vtty context with it. Let ve_vtty_stress accept -EAGAIN as an expected open error. Fixes: 23abb203a41a ("ve/vtty: fix use-after-free on concurrent tty close and reopen") https://virtuozzo.atlassian.net/browse/VSTOR-152365 Feature: tty: virtual Container console Signed-off-by: Denis V. Lunev --- vzctl needs a matching change, "vzctl console: retry opening a CT tty the CT is still closing", which goes to the vzctl repository. Without it vzctl fails the same race with "Resource temporarily unavailable" instead of "Device or resource busy", so the two should land together. Tested on sqvm4-1002, hci-8.1 6.12.0-211.52.1.22.12 with this patch: - a host loop opening and closing the console via VE_CONFIGURE_OPEN_TTY while a loop inside the CT opens and closes the same tty: about two thirds of the host opens fail with EBUSY before the patch, none after, they get EAGAIN instead; - vzctl console with the vzctl change under the same race: every attach succeeds, after at most four retries; - vzctl test_vzctl_console.py passes, including the "tty already in use" case, which still gets EBUSY; - ve_vtty_stress passes; without the selftest hunk it bails out on the first EAGAIN; - nothing in dmesg. drivers/tty/pty.c | 5 +++-- tools/testing/selftests/ve/ve_vtty_stress.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index 14d46bb9c293..6f6dabba96e2 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c @@ -1100,14 +1100,15 @@ int vtty_open_master(envid_t veid, int idx) * user is gone and tty_release() has already committed to the final * close, release_tty() is only waiting for tty_mutex to free it. * Never hand out a reference to a tty which is about to be freed, - * report -EBUSY so that the next attempt allocates a fresh pair. + * report -EAGAIN so that the caller retries and allocates a fresh + * pair. -EBUSY above means a console is really attached. * * A pair we've just created above is exempt: it is not reachable by * anyone else yet and its zero count is merely the initial state, * vtty_install() gives its reference away to the master peer below. */ if (!created && slave->count == 0) { - ret = -EBUSY; + ret = -EAGAIN; goto err_unlock; } diff --git a/tools/testing/selftests/ve/ve_vtty_stress.c b/tools/testing/selftests/ve/ve_vtty_stress.c index f4bdd81133b8..d8d92ae54718 100644 --- a/tools/testing/selftests/ve/ve_vtty_stress.c +++ b/tools/testing/selftests/ve/ve_vtty_stress.c @@ -44,7 +44,7 @@ */ static bool expected_errno(int err) { - return err == EBUSY || err == EIO || err == ENXIO; + return err == EAGAIN || err == EBUSY || err == EIO || err == ENXIO; } /* A runner timeout must still reach the cleanup */ -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel