Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1330386ybz; Sat, 25 Apr 2020 16:35:48 -0700 (PDT) X-Google-Smtp-Source: APiQypI3HkSRZTDUOmQ7zJ7bKg1bW/AFpZXxkvOjPogrpRgy3farnJVP7tY4Mv13uRW+D3j5aYOg X-Received: by 2002:a17:907:214f:: with SMTP id rk15mr13802386ejb.301.1587857748197; Sat, 25 Apr 2020 16:35:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587857748; cv=none; d=google.com; s=arc-20160816; b=pb/zM3KV/efhv/Ld4VvP9nEGWm6FLa5dTHlL1/iMfgdldsZ4vaIF82LuxbHLYMEw0N KS9XmFhmt01UUACKxDoY8rJQwoGt/X8/jY03tOfIHVT3WNWFkLOzu+RFzqij5WDDG/+p gvJ8LHx9PIn6DpoQrk+0YhRWhLBCiwEqYL+Hq8Upas1mdj101Z7rXs+0Ha0mGXHGRLy8 APhflOhw+f5x8imERPZ4B+A9fE1xtTmK/XYpIpqnLlHL8rQmV7UFvFEa/FEUMwrx0SLE KvfEVa0968pMNpLBcHL/JTnYm0P0+ELurx+eQfaBzfI5NpxvYYwgbPi0j7Bc7hK/9wkO fVLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=GR6Zp93w2P9nAEpmtk3P+nTTTrGY8uPP/pZ5DAWZeKk=; b=tNwICq1YSOEm3CStlCVaa/5WgLkWtPil3g21QXoh/J6mdYRm5obbEDcgEClech9WkA STHMpmc8jV1e7unFGwUyJ3kCpvIjF1o61IRms3dUSM4YeJ0V0inVEa9CAmmrq2xJmiu9 AtfW7FaokZdiV0NKua7P78VR/YuD8upHYQPofL9URMubzU0waJOc3oqR+uXpkQQAFz7N EdY+gc7expD2gDeNq9xmjPUGuk2gQ9yus74vunJZkyO5/SCyPRJN9ZmzsCZBwAeydK2U mpBaFUwXE4SZCvF3N/nPp0pHxxB+31wmgZfcRvV009OawlK6b9fKfULpbybIGucdJ+ic PzsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=MdSKweh+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e3si5446048edj.169.2020.04.25.16.35.23; Sat, 25 Apr 2020 16:35:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=MdSKweh+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726378AbgDYXeC (ORCPT + 99 others); Sat, 25 Apr 2020 19:34:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726303AbgDYXeB (ORCPT ); Sat, 25 Apr 2020 19:34:01 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E63FC061A0C for ; Sat, 25 Apr 2020 16:34:01 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id x18so16091984wrq.2 for ; Sat, 25 Apr 2020 16:34:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GR6Zp93w2P9nAEpmtk3P+nTTTrGY8uPP/pZ5DAWZeKk=; b=MdSKweh+JscsTN879u2NQv0JkN49sSglDkE7v9OyXfLIFFcZdXbEtdsD0cNjLClc/1 X/HHqsMuojP0QuiaBhnsJs0f8e5QIj7JL0PSBpmZPiH+12T2l7O95iVE3ii0ToxM5uPO lqBKieSlOC3Cmx9ufSY+IBUbMlSNviJ/5FBbhPaflyQSpIfDksgDIfP2X9QAj9DiQlR/ kSak9HxW6BghvVRtNZ5ujuwIg/weqGaH71P7xYYTe6tRefRXnHQ4lfoKJ5LChKuYdspG qzrH7qACTE2Jz8Y1bPmuCPlO0E41XrM4Lmuaw6RaFrR+3Nbg64tZ3BGp86A/uH1RyMb0 9vaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GR6Zp93w2P9nAEpmtk3P+nTTTrGY8uPP/pZ5DAWZeKk=; b=XbjX1Iv85hndGEnR7xpsMEiu/Z1Ba0kOIaa33lglQWHZcnl34/7FfzVcYG4Ds4xXlx kaKbrbZ8SXGVxcg66VoYWFuR5ohUmnhdekM/xMUXTB2+U7PWtynhlb7jSq96coWluQIj NNKi/FqQKxLkoX1DNACjn5v26ALnSZDXTxAdbh9aPlhzlR7kvh3NCGVhe255YCfZjRbb gVnEUYf/TL9D6xqVgFvoRzSvNyvc/ifEsb0Q0eRq6/J6Na+xkGbnz/YY1FtDvEMRv8gQ jtVTZCRfeFMMBo+8ZFhdg2GJePyj1yN1W2O7+ar78Gfs/O5LVY3j7ahiwiDThDQ8blEN D2bQ== X-Gm-Message-State: AGi0Pubtl6kKsMKJ4VVpBVIfud+dIMlsRaasJwiLyrchdF6u1eo+O9YG JiIQSZMtMkp9nn66Xo7tH44= X-Received: by 2002:a05:6000:12c7:: with SMTP id l7mr19840423wrx.239.1587857640288; Sat, 25 Apr 2020 16:34:00 -0700 (PDT) Received: from josarchlaptop.nilsvital.de (pD9F5358A.dip0.t-ipconnect.de. [217.245.53.138]) by smtp.gmail.com with ESMTPSA id l5sm8886988wmi.22.2020.04.25.16.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Apr 2020 16:33:59 -0700 (PDT) Received: by josarchlaptop.nilsvital.de (sSMTP sendmail emulation); Sun, 26 Apr 2020 01:33:58 +0200 From: Johannes Hostert Cc: Johannes Hostert , Greg Kroah-Hartman , Jiri Slaby , Eric Biggers , Eric Dumazet , linux-kernel@vger.kernel.org Subject: [PATCH] vt: vt_ioctl: Add new ioctl to read vt switch lock state Date: Sun, 26 Apr 2020 01:14:34 +0200 Message-Id: <20200425231436.535671-1-jojohostert@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The existing ioctls VT_LOCKSWITCH and VT_UNLOCKSWITCH can be used to allow/disallow switching the virtual terminal. However, no mechanism exists that allows software to read this lock state. Userspace programs that try to switch to another virtual terminal like chvt have no mechanism to figure out whether they will be able to actually switch the terminal. When eg. chvt is run while terminal switching is disabled, it simply sleeps forever waiting for the target terminal to become active. This commit introduces a new ioctl VT_GETLOCKSWITCH that allows reading the current state of the switch lock flag. Userspace software can then use that flag and handle not being able to switch virtual terminals. Example program using this: #include #include #include #include #include #include #include const char* console_device = "/dev/tty0"; int main(int argc, char* argv[]) { int fd; while ((fd = open(console_device, O_RDWR)) == -1 && errno == EINTR); if (fd < 0) error(1, errno, "Opening %s", console_device); int ret; while ((ret = ioctl(fd, VT_GETLOCKSWITCH, 1)) == -1 && errno == EINTR); if (ret == -1) error(1, errno, "%s: VT_GETLOCKSWITCH", console_device); printf("VT switching is %s\n", ret == 1 ? "locked" : "unlocked"); close(fd); return 0; } Signed-off-by: Johannes Hostert --- drivers/tty/vt/vt_ioctl.c | 5 +++++ include/uapi/linux/vt.h | 1 + 2 files changed, 6 insertions(+) diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c index daf61c28ba76..08b808e1fbf0 100644 --- a/drivers/tty/vt/vt_ioctl.c +++ b/drivers/tty/vt/vt_ioctl.c @@ -1028,6 +1028,11 @@ int vt_ioctl(struct tty_struct *tty, return -EPERM; vt_dont_switch = false; break; + case VT_GETLOCKSWITCH: + if (!capable(CAP_SYS_TTY_CONFIG)) + return -EPERM; + ret = vt_dont_switch ? 1 : 0; + break; case VT_GETHIFONTMASK: ret = put_user(vc->vc_hi_font_mask, (unsigned short __user *)arg); diff --git a/include/uapi/linux/vt.h b/include/uapi/linux/vt.h index e9d39c48520a..13a1e82dfb14 100644 --- a/include/uapi/linux/vt.h +++ b/include/uapi/linux/vt.h @@ -61,6 +61,7 @@ struct vt_consize { #define VT_RESIZEX 0x560A /* set kernel's idea of screensize + more */ #define VT_LOCKSWITCH 0x560B /* disallow vt switching */ #define VT_UNLOCKSWITCH 0x560C /* allow vt switching */ +#define VT_GETLOCKSWITCH 0x5610 /* return vt switch lock state */ #define VT_GETHIFONTMASK 0x560D /* return hi font mask */ struct vt_event { -- 2.26.2