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 903378017D for ; Mon, 2 Nov 2026 17:46:02 +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 6A2HijQw027731; Mon, 2 Nov 2026 20:44:46 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A2HijQw027731 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1793641488; bh=PM4HV+VLxNk0UwMTkU5NyspnN+/NqiZweEiEOPmiYn4=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe; b=Ka2eN45Lj2Ds8mUjNxaDZOKhiSqVIt2ucslGx0EEoV2LvLmBRv8kE1Oyn2U9nnCN6 TX4w34oqH76afo4aPgmI799QsbYa3VlCZ22Yzsw3Obj099QT4io3LtuggQyOxdrdQg WAbVgCWlY5b7WveSS/LGymDSpNLJW3rbupm9IvHLpGHuVaMFmTXUfLwCAJZGYiOaSz 2fJtqCcQWtifJMh3NI59KpaAkmCATspJJ4X4k2FjgxQp1Yf71z3s3cp/iBRFjRQlOo FpUK+J8+hsoUqWJNCuj/8nRRiLQ4RDUWOCrFAPN0ct7WN/OvcKJEQD1e4VzwSN7r5g 1kmVWI63LA7Jg== Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6A2HiiQH027727 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 2 Nov 2026 20:44:44 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A2HiiQH027727 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="HingnsL0" Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-3ab3061668eso16596031fa.1 for ; Mon, 02 Nov 2026 09:44:44 -0800 (PST) X-Gm-Message-State: APuU4Z+tHWB1aX47VlnDbC+Xih7/SCtzMqXh++0Lp8vQVdhRB4CJPJrr S8jkXr53Bc9ujW3XYFAdVPnrYYVOanb8WwoYlVXQGu8Yrp8bsyfJCDOs4wJ5cdozIyG+NMYSBnX Jc/x5ZHX0LYp36YiZhRqh3JIWhJJKaklVaN2o/G8KSFyvyVAib3AJXA== X-Gm-Gg: AYBFou3YXW5gXp0h7ZrRLl9+iwSw3QWjD4Pw3QbyM25IzlpBpLDsNjhRPbRnR6FGcCZ yOhX5dY7cSoTfsSg8OCujasT4xnqbS4mIT1IIrNfdGkVCHrcIDHjj0KbPfJbkUPK2Ee2ferp0Xu Be1y84XdvY0ujLcxsk3Tj0FET8thiBJhPlFtAFhqo3/GD7pP2JCREmYotJ16OfgG/PkjqfO4VuY DzkSnf4vZueelgXcxzY3f4LoKU06LuYTTsTf1defxL0wX9NEguS95BjvaPYnENmICGqyKeTBY5T rkSI7cxUaw== X-Received: by 2002:a05:600c:a301:b0:4a3:5d64:e063 with SMTP id 5b1f17b1804b1-4aa8a7ac897mr281021305e9.9.1793639710825; Mon, 02 Nov 2026 09:15:10 -0800 (PST) X-Received: by 2002:a05:600c:a301:b0:4a3:5d64:e063 with SMTP id 5b1f17b1804b1-4aa8a7ac897mr281020545e9.9.1793639710056; Mon, 02 Nov 2026 09:15:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1793639710; cv=none; d=google.com; s=arc-20260327; b=Rd2T83649+RhbGnRWzSwIjVq+xwLAQK3vHAq8uZ2RDtqgvXxbNVqNXU6mEC0XU1TmJ f2heW8BQVL3P4b6mkUMm1mrjjr0wekP04RqOks/yFL5pj7uFDDb/42rGUOdZ95fNwI7n Mp+sny7jGVdiZ1Cd75BUsAHRVPLYizdwEEq4XRLvcJy89fR/i/tOS4w/5hiWD4gjZgLI xHrpeaU56Ar0BvMMPm91euEP9HrU/mg+8zZykd8vnvm1mPiDVKjWjemgj/asXSF3w+lO jfCKS9xZ0C22WCjIr9s8zQkc7F+tsXT1m0KCuk8CrkwRIx3j/ifchajrEoDe/bCMZxfL hsDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=8ZOGu0XBEBrEoOZoouknhM6vDvfFMCzplgNyFDvllv4=; fh=ozrYJQ1t3QIP6s65KBq5xgJxiFM2qf+5wwn3ABTusyU=; b=ncqw84DHbo2bkMt3VBRExur+E584/HuOVm0J2+PoQW8rTfa1RiehwFnrZ1V2l3NKF6 s6dYolUT/pxI1Y1tIGqkw3jNQqV/Puuus9Q6yliNgiCH6kvEFTeag/keluwrfTFbGW49 i76f/w71r7Q8zBq+ZmNJevhp7P6lJ8j3SqKHKM2Z2TxcsxmxZuYcGneGN3w9Pfc/JEuo lRV9alxdp3L6Y1Bu0bSS85k4ioLQdOHSUA6lvmaP0qyCrP0ArS3ypd8GNTlIX4snYHm6 x3CFUEgVRHqtZ8s3aAT6yEmP1D6Go8xBIErO7lDz8q/65d8Xw2oPO/aTg6xRe7so7Ml/ 1azA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=HingnsL0; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:91db:48d7:7451:652a 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-48e89ce06eesor13674f8f.0.2026.11.02.09.15.09 for (Google Transport Security); Mon, 02 Nov 2026 09:15:10 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:91db:48d7:7451:652a as permitted sender) client-ip=2a06:5b06:b600:300:91db:48d7:7451:652a; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=HingnsL0; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:91db:48d7:7451:652a 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=1793639709; x=1794244509; darn=openvz.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8ZOGu0XBEBrEoOZoouknhM6vDvfFMCzplgNyFDvllv4=; b=HingnsL01SzX2AFh3WyFrDIOCe2452VnATgQZeRTAWYq1+w/+gkGDmL/VWBdFMdupz QtwKRU6YGwFP5mLpBwjEPQazo+BCngCMgRlpkMviV0QmDLj7SnsoF/io20t4C40MMpuJ 2s98cu4k5k6WpD1b8AumUrIqKUFRL2p62n2mgYhYOBYJvMiq5pEUkGRhh+G14CgXg6+6 /0gO/QVpkOjDMt/+dy4z+GpRpekwT3/3p+9aI09ByfYwrsu9wk4K1oWT6SuIefOQr2S6 /yDF//ORy151zoxm2tYSvpdAIDwCimqk00aDXOoVJs7kuL67qELN3MGsu8YyV0ROzRD5 /QtA== X-Received: by 2002:a05:6000:420c:b0:48e:6264:c371 with SMTP id ffacd0b85a97d-48e6e2cb57dmr25506807f8f.9.1793639709573; Mon, 02 Nov 2026 09:15:09 -0800 (PST) Received: from athena.sw.ru ([2a06:5b06:b600:300:91db:48d7:7451:652a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e88876946sm2127084f8f.5.2026.11.02.09.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 09:15:09 -0800 (PST) From: "Denis V. Lunev" To: khorenko@virtuozzo.com Date: Mon, 2 Nov 2026 18:15:04 +0100 Message-ID: <20261102171504.3809155-3-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261102171504.3809155-1-den@openvz.org> References: <20261102171504.3809155-1-den@openvz.org> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 2/2] ve/vtty: wait for a closing CT tty instead of failing the console attach 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 means a console is attached, 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. Wait for the closer instead, as tty_open() does for the same window since commit 7f22f6c935cd ("tty: Retry failed reopen if tty teardown in-progress"): drop the slave lock, the vtty context and tty_mutex, reschedule and look the pair up again. The fd and the file stay allocated across the retry. No userspace change is needed, and -EBUSY again means only that a console is attached. The loop ends. Both counts are zero only after tty_release() has taken the final close, and the closer then only needs tty_mutex in tty_release_struct() to reach vtty_shutdown(), which removes the pair from the vtty map. The next lookup misses and allocates a fresh pair. The opener spins on schedule() while the closer flushes the tty works, as tty_open() does. A pending signal ends the wait with -ERESTARTSYS, so the ioctl restarts or fails with EINTR. 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 Suggested-by: Konstantin Khorenko Signed-off-by: Denis V. Lunev --- drivers/tty/pty.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index 14d46bb9c293..6415456dca13 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c @@ -1054,6 +1054,7 @@ int vtty_open_master(envid_t veid, int idx) * else would access it while we're holding * the lock. */ +retry: mutex_lock(&tty_mutex); vtty_set_context(veid); @@ -1100,15 +1101,23 @@ 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. + * let the closer through and retry, the next lookup then misses + * 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; - goto err_unlock; + ret = -ERESTARTSYS; + if (signal_pending(current)) + goto err_unlock; + tty_unlock(slave); + vtty_drop_context(); + mutex_unlock(&tty_mutex); + schedule(); + goto retry; } /* -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel