From patchwork Sat Oct 22 18:29:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 7921 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1324434wrr; Sat, 22 Oct 2022 12:12:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7offbkV/Wg9g50URBwvnxxeJhaDUqr3M6Qdd2mziOM9GxkBVkvWOd/cVLrOgFrUHZndmry X-Received: by 2002:a17:902:ccc2:b0:178:29e1:899e with SMTP id z2-20020a170902ccc200b0017829e1899emr25301088ple.114.1666465929780; Sat, 22 Oct 2022 12:12:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666465929; cv=none; d=google.com; s=arc-20160816; b=Fz4zHaLqsR2NIWZBAFS2pl9m3BGPY41YMdDcz62v0RX2xhiOjgrbhGtg6QC3p9b21R V18zEygyNuCl5oXCRV0VourRIXuLeHfkw9Gbm0CogbyEtegFJUOx0ziOX/87A96eGBLD +JxvfxFvlRFvMPG0i/J3B4HUugKASiei8OdBFURVXMsDrvzUwVruHYwZvxS5ri15EJD2 g914Zuj6biDP4SK3vaYoWQ0xD9Q6L2eFWICNMW1iW9jQa0UK3w8zhrgkQ0NKJSPXrxoC JWPznu4OJtREC9vflPff5fH4Yq7hs9OqWA1I3eCdo7y1lmTPFT55B9N4wqSaYKPWljyA HyHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lhK+n74IwfoEYJVpbYYVgx8zMlbePkYd2jvvQVl1DNI=; b=pYG6ldfW98e/R3vf7/Mypn3xF5XLCUydoaQideymuS872qm8G51chJDlPOjCkW0Z2d gJkCYdBYaQzq+VKHdt9NEt0R0vamIbxfOqW1nu+wYBk880u6APQhPHFqhaXeeSpMP8I1 Qjy9R/nWNRr3mQ/ZHOOUdU2WPd2O4V4VXukfdlIGNGfGTK6HRRALaYZEh5sOTRHqq2Bz SiQ6rSH6NWC90GbpXSZ9rlq51h6mHygjhxUgXM2U++CdNksZ2/3PrMLQPIULCeu2rUPd xobYf5541xed3d0WOF12VaPfQR+ae0lRZIm58q5hro85KsuV0n7TwduQ6AWHzgfR/L5u mIvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=S24Vm63c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e6-20020a17090a9a8600b001fd6e58cd98si3144098pjp.123.2022.10.22.12.11.50; Sat, 22 Oct 2022 12:12:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=S24Vm63c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229937AbiJVS35 (ORCPT + 99 others); Sat, 22 Oct 2022 14:29:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229921AbiJVS3y (ORCPT ); Sat, 22 Oct 2022 14:29:54 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 740BF40039 for ; Sat, 22 Oct 2022 11:29:52 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id f9so919638pgj.2 for ; Sat, 22 Oct 2022 11:29:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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; bh=lhK+n74IwfoEYJVpbYYVgx8zMlbePkYd2jvvQVl1DNI=; b=S24Vm63cnb/pQmXYC/Ji63qErM6N77P6FtUKv7pvhBPH9G2MNErakkWEYF4lZkUjPK afrGZX5qWhYQMm0S7qGGO3J7KvVYD0wYfO9ZN48fYvf6rdOnHxhfMsgAgMN1q7TS8VVV TP9HD40o8yDBNqSFof/ACZ0yRJUF5TWBEEVEY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lhK+n74IwfoEYJVpbYYVgx8zMlbePkYd2jvvQVl1DNI=; b=6V5fSWkQil3I1oz5QN5MEJqNgSQCBJpFx+QoRgLi6ivzFQ1punfo6D+Je6sOaQi8v6 bVuxOF2opJ1klLesTXKKDyj9prtC8iL5WHABCiRHYGo0kNM72mjzgQwTr+saM/VPuP13 +XkrCO1l7U5sH/Yg5fGh2M6hZQy8h61lFJZiiPLvFUrdkj4KtkZ1xY1Ycpf3YGBT73oF ZzSQ0k8CaBSUizWii2bL4Mv93rqYMeEG1uETZG7QbN7PWy9coRQQC2tCdH3U0d9dvij3 dYKPM2Y4Xhy0gWtOf/uhbmyrvTHvVuyWmjlRXn9etXmZwVQfEgSxvmJDNGQ9HqaZPXAm DUYA== X-Gm-Message-State: ACrzQf0NQgz4x3cblCzqoPW2LKrEVHXjkGJPlZvo7tYTJxwKbZTao+WK SekPPbBjK90MJnXDUUJh5z1k/Q== X-Received: by 2002:a05:6a00:21ce:b0:569:9dc2:a6c7 with SMTP id t14-20020a056a0021ce00b005699dc2a6c7mr12205646pfj.38.1666463391890; Sat, 22 Oct 2022 11:29:51 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h9-20020a170902f54900b001788ccecbf5sm17117951plf.31.2022.10.22.11.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Oct 2022 11:29:50 -0700 (PDT) From: Kees Cook To: Greg Kroah-Hartman Cc: Kees Cook , Jiri Slaby , Simon Brand , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v3 1/2] tty: Move sysctl setup into "core" tty logic Date: Sat, 22 Oct 2022 11:29:48 -0700 Message-Id: <20221022182949.2684794-1-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221022182828.give.717-kees@kernel.org> References: <20221022182828.give.717-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3545; h=from:subject; bh=Nyuo2IvupAQIigzsfxaAoDN3LMdaMzP0RYaZjpUzMxE=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjVDac8Ddo6K7F5HHzJjCDjWjPgrobDOvuScnUkqg3 YkeqaLSJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCY1Q2nAAKCRCJcvTf3G3AJkdwD/ 4rcSf2MSyYi0KOsvmUZvR/2jPe8raIT9H7agWXL6ThO/s75kx/SSFKDBhGBbsDRq7HK4Trla4qCCeR yyU71/X2FDErb6ika6NGdmD7ew5SAYke3TWP8VHWZvz3F/iSEY+lJB5vKl5jitIbyVinP9IHM0BfAA VvUSjntsswdXvEBRTHPihaijb/SSkGtC8VHT43fnOmowYi0WJIchQUAaivkexO9N3rchAKveGQO/+k wzjVTZ9mp+kUNm/KbK5scDpPYHm6enZM43NhkzEYlaRpYYm9hRRJxgg44pCLbQl/fMnK3Y1nZ+NKHX aMrm0X//dDKsyU4vYSD1ZKRkFzZRLdfeDZLDBMMhn5SFv1u+ShuguGtvu3SwsXcf2q4MLTJBJgr/GD Yxs1aPnYaex2Xb+wAKN22VRcK9FrFPVTX6GGSNpcDbSHq6eOdoaYKDkBGDNAIl/uvDucrzqFgPcgoU P4PzbRur4uA+UrO8FeOB9mr17gZofZB+USuNjOKM5wYoIjyKdD9dkwZRflmhZlRmRAop+3PvVhb3iC C1z4TrBwaOeSp4BUenQ5boYBpKZgES1iMJzN9RWL7OsH3N7YyTbsxdSLgInoWK2ocsYhyLAWGnQ2l2 x/7tro215lOVgCOUU+jhVRcwDEZjAQKub/j3MYB66XMAguVP/Ybj8bBlJqjQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747416178975504060?= X-GMAIL-MSGID: =?utf-8?q?1747416178975504060?= In preparation for adding another sysctl to the tty subsystem, move the tty setup code into the "core" tty code, which contains tty_init() itself. Cc: Greg Kroah-Hartman Cc: Jiri Slaby Signed-off-by: Kees Cook --- drivers/tty/tty.h | 2 +- drivers/tty/tty_io.c | 34 ++++++++++++++++++++++++++++++++-- drivers/tty/tty_ldisc.c | 38 +------------------------------------- 3 files changed, 34 insertions(+), 40 deletions(-) diff --git a/drivers/tty/tty.h b/drivers/tty/tty.h index 1c08c9b67b16..f45cd683c02e 100644 --- a/drivers/tty/tty.h +++ b/drivers/tty/tty.h @@ -93,7 +93,7 @@ void tty_ldisc_release(struct tty_struct *tty); int __must_check tty_ldisc_init(struct tty_struct *tty); void tty_ldisc_deinit(struct tty_struct *tty); -void tty_sysctl_init(void); +extern int tty_ldisc_autoload; /* tty_audit.c */ #ifdef CONFIG_AUDIT diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index de06c3c2ff70..fe77a3d41326 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3572,13 +3572,44 @@ void console_sysfs_notify(void) sysfs_notify(&consdev->kobj, NULL, "active"); } +static struct ctl_table tty_table[] = { + { + .procname = "ldisc_autoload", + .data = &tty_ldisc_autoload, + .maxlen = sizeof(tty_ldisc_autoload), + .mode = 0644, + .proc_handler = proc_dointvec, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, + { } +}; + +static struct ctl_table tty_dir_table[] = { + { + .procname = "tty", + .mode = 0555, + .child = tty_table, + }, + { } +}; + +static struct ctl_table tty_root_table[] = { + { + .procname = "dev", + .mode = 0555, + .child = tty_dir_table, + }, + { } +}; + /* * Ok, now we can initialize the rest of the tty devices and can count * on memory allocations, interrupts etc.. */ int __init tty_init(void) { - tty_sysctl_init(); + register_sysctl_table(tty_root_table); cdev_init(&tty_cdev, &tty_fops); if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) || register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0) @@ -3600,4 +3631,3 @@ int __init tty_init(void) #endif return 0; } - diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c index 776d8a62f77c..e758f44729e7 100644 --- a/drivers/tty/tty_ldisc.c +++ b/drivers/tty/tty_ldisc.c @@ -117,7 +117,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops) raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); } -static int tty_ldisc_autoload = IS_BUILTIN(CONFIG_LDISC_AUTOLOAD); +int tty_ldisc_autoload = IS_BUILTIN(CONFIG_LDISC_AUTOLOAD); /** * tty_ldisc_get - take a reference to an ldisc @@ -817,39 +817,3 @@ void tty_ldisc_deinit(struct tty_struct *tty) tty_ldisc_put(tty->ldisc); tty->ldisc = NULL; } - -static struct ctl_table tty_table[] = { - { - .procname = "ldisc_autoload", - .data = &tty_ldisc_autoload, - .maxlen = sizeof(tty_ldisc_autoload), - .mode = 0644, - .proc_handler = proc_dointvec, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, - }, - { } -}; - -static struct ctl_table tty_dir_table[] = { - { - .procname = "tty", - .mode = 0555, - .child = tty_table, - }, - { } -}; - -static struct ctl_table tty_root_table[] = { - { - .procname = "dev", - .mode = 0555, - .child = tty_dir_table, - }, - { } -}; - -void tty_sysctl_init(void) -{ - register_sysctl_table(tty_root_table); -} From patchwork Sat Oct 22 18:29:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 7923 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1325278wrr; Sat, 22 Oct 2022 12:14:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7oui3rE4VWjFOki9BL2NUYtGyM0NiT6M79+uEio27CcrCrkjuycLMgF4i2zC728UFITh29 X-Received: by 2002:a17:907:7606:b0:78e:61d:757e with SMTP id jx6-20020a170907760600b0078e061d757emr19808501ejc.690.1666466070423; Sat, 22 Oct 2022 12:14:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666466070; cv=none; d=google.com; s=arc-20160816; b=NGFJqZAhQ/3OeWhvmzIjqrG7tCeKQUVrTUXItdyVQTFbzylgqtz/sZrcOJG7k/AQHb FGmYIlvPKSzC3WKIGPSXfxL0BcT4UFUiWa5hY7GXeQFa0guxzhUhhvYf6jtQhAGQ0eUA tLfP74ErF2aAM1HLieK9CTmZvmCrvt5hPmFuWdnIfSZv/6zv+LYhRICzfm5pxsOkx/kR AlI9J1xoAj9HCgpCXVqC+A/J8nU8O1/kdoivT/IFlCbKSRTBu2imERPb/R0vDcf4DTf7 eWlKeBiL0Msg9TiiPvCpNiXPC2OCxzfJcQa4l1LXRgizHmYSi9+UC6kfhkegi1/UKg5+ FqoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HHhvxulLghF+vBS1CMcuNS4a1S3LavBD3tiqXSCICpE=; b=a90hzPCs10CRarHp2gSqmTAA6TSC1NEh0CU4vEuKCUPGsqVDF+qNjMwIdJkzq1BXf4 hHbmwDGw5CdUdtgCk2I5rGoQl30a6nx5xRqszv0e8FFGx2VgQ8j55P+YqxzJNpkgrQCY T7k52/1xdJ7WNagctQ2EbDVfBwngmplwIw8uwxKrdGzC3da7IS5v77/km5MOzl17ldCt WlVJ1krgyyuM7mzHcWI+rakSUx0hKd1xsP7cICa/zufA9EmNnCa6eEBGubv+8n2PkWFG Ccc5+cqZnD8xOzt0MoysyL4rRfa3iVQWPevy3qy77Ds9E4Xz+LEyBePX7htOWRMG5av5 9tqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="AafR3/M+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m15-20020a1709066d0f00b007881b45441asi19272320ejr.721.2022.10.22.12.14.06; Sat, 22 Oct 2022 12:14:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="AafR3/M+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229788AbiJVSaF (ORCPT + 99 others); Sat, 22 Oct 2022 14:30:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229932AbiJVS3z (ORCPT ); Sat, 22 Oct 2022 14:29:55 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4005245998 for ; Sat, 22 Oct 2022 11:29:53 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id ez6so5062330pjb.1 for ; Sat, 22 Oct 2022 11:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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; bh=HHhvxulLghF+vBS1CMcuNS4a1S3LavBD3tiqXSCICpE=; b=AafR3/M+ug0+nvsEqQpBtXxnG8Fx6fJvb/F5VyxLfeKxTkcaQRxNy9widlva+POEd2 l69QoIeWbB9nX1uzjqJXWpYutRLXsbUxyzlWQ9SE9mF4hCanBut+nLIWrs2L5zhasmVH 56Rz4NuzJPs89s7gTDjFKxKTXCwnmz2nVjAns= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HHhvxulLghF+vBS1CMcuNS4a1S3LavBD3tiqXSCICpE=; b=frrPnyEsVbZELMCp4TdpYdY87th+R2HZCJI8IMMKaR6HnjkCXbw1MMxVjNO34wcI1s sNZ9qwoNtqQ6O6oLlg1T8/oFpmUASpbxYjBqb2m73bmVLFHnMoWixQF0WjnXqypd5dRm QReDIZEtkRUzG0akNzBm8Bqvf+gp6uybYQXDZphul7mZmbVxgbr5NKqGNcXbmSlUqH6M U2Gi+PF+zmnqCHJp8MLG2PAGOQ3D8h2TPkrthjlriBGyJrK15sXEqmrPW3rFPHZMZfIq dHTqQNy1MmtRfn0U/uUA1YZUfgbVNVps+xgZWGNxICi+4i0wRvm+wNTaD6hUEccjQqdg 9ssg== X-Gm-Message-State: ACrzQf3JC3POZX6njDV8SZUGTYMug4dhuTu+k91Qwp3i4BRCgXinzAdf 9vtnhkLyl3WVwcU1ueeMdJhezKuoDHg3lg== X-Received: by 2002:a17:90b:2812:b0:20d:7a3b:df3e with SMTP id qb18-20020a17090b281200b0020d7a3bdf3emr65327223pjb.169.1666463392500; Sat, 22 Oct 2022 11:29:52 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id p7-20020a170902780700b0017bb38e4591sm3822240pll.41.2022.10.22.11.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Oct 2022 11:29:50 -0700 (PDT) From: Kees Cook To: Greg Kroah-Hartman Cc: Kees Cook , Jiri Slaby , Simon Brand , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v3 2/2] tty: Allow TIOCSTI to be disabled Date: Sat, 22 Oct 2022 11:29:49 -0700 Message-Id: <20221022182949.2684794-2-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221022182828.give.717-kees@kernel.org> References: <20221022182828.give.717-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3522; h=from:subject; bh=JIl7HOU/ElX414nbe5g4/ExXJarRYqkuhmz9GGmO2pw=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjVDaccwzraGBf+oCRGY9wtTvemKlYckYVJh940e1k Fpe8K/iJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCY1Q2nAAKCRCJcvTf3G3AJlydD/ 9ekv6HRzYt9CJtEJ2xHytL/yPSnjzvfeUNKwGzahN6kuwiLRtM8fFfjsYMFnCKRIjyDd05VpYo28fY IyRz3jvMIMaS2vF8CGekYplbhzbpMtyIsi2nu5v2FIufVHyBzgQ6PsIYKh8oFa70JW9LBKTrnb/Ilv nFZfLtKgnG581LreZy4D63ejpIyAsisGZHMs510EVFWTLsLw/eh5v3WDcLPoP+9/zzfpvrmyQJFkv0 2TNHyeF2C0Rn+I4nueCzQyHuzzmg/dmQNicIgtbKLCSJ1582jlZbfNFfYBH5XQj2jhYhqpZ7au1yMl qWLOYI1K9WxMmakKwtpaCsE0VTntNY7JA8YrBHsrmhVe0j0AdD9HQ/Hwf72JgyMbK7t1nEKsXVWx2w fSdsSQjM7XW0ihcQ2Z7PuZjTtB4JTUsuG10LvtUE6vq9Ad6L0x0nMkwI9A2VkmaPxcpGKODWiwavnC FoMGr0xMiozIJz7bHSxs3nwwVZp9ccJj8l5dmQvCtVjOwK10atr5jOkVInCt4/CNG+S30N1pjnbld5 NUdV8irF2YG8OZxEh9Emd9n2milDAsAWev/KYSlj1VWGmGvDDlzbUZ2OcyLW/UzImWF0gdldy9iTQy AQ0TPHVKpK8hVPqZerX5gj4B/N3uYfObMlEz9N+8sZk5BbRIp78ZXxx0yGKg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747416326091061403?= X-GMAIL-MSGID: =?utf-8?q?1747416326091061403?= TIOCSTI continues its long history of being used in privilege escalation attacks[1]. Prior attempts to provide a mechanism to disable this have devolved into discussions around creating full-blown LSMs to provide arbitrary ioctl filtering, which is hugely over-engineered -- only TIOCSTI is being used this way. 3 years ago OpenBSD entirely removed TIOCSTI[2], Android has had it filtered for longer[3], and the tools that had historically used TIOCSTI either do not need it, are not commonly built with it, or have had its use removed. Provide a simple CONFIG and global sysctl to disable this for the system builders who have wanted this functionality for literally decades now, much like the ldisc_autoload CONFIG and sysctl. [1] https://lore.kernel.org/linux-hardening/Y0m9l52AKmw6Yxi1@hostpad [2] https://undeadly.org/cgi?action=article;sid=20170701132619 [3] https://lore.kernel.org/lkml/CAFJ0LnFGRuEEn1tCLhoki8ZyWrKfktbF+rwwN7WzyC_kBFoQVA@mail.gmail.com/ Cc: Greg Kroah-Hartman Cc: Jiri Slaby Cc: Simon Brand Signed-off-by: Kees Cook --- drivers/tty/Kconfig | 19 +++++++++++++++++++ drivers/tty/tty_io.c | 11 +++++++++++ 2 files changed, 30 insertions(+) diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig index cc30ff93e2e4..d35fc068da74 100644 --- a/drivers/tty/Kconfig +++ b/drivers/tty/Kconfig @@ -149,6 +149,25 @@ config LEGACY_PTY_COUNT When not in use, each legacy PTY occupies 12 bytes on 32-bit architectures and 24 bytes on 64-bit architectures. +config LEGACY_TIOCSTI + bool "Allow legacy TIOCSTI usage" + default y + help + Historically the kernel has allowed TIOCSTI, which will push + characters into a controlling TTY. This continues to be used + as a malicious privilege escalation mechanism, and provides no + meaningful real-world utility any more. Its use is considered + a dangerous legacy operation, and can be disabled on most + systems. + + Say 'Y here only if you have confirmed that your system's + userspace depends on this functionality to continue operating + normally. + + This functionality can be changed at runtime with the + dev.tty.legacy_tiocsti sysctl. This configuration option sets + the default value of the sysctl. + config LDISC_AUTOLOAD bool "Automatically load TTY Line Disciplines" default y diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index fe77a3d41326..a6a16cf986b7 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -2268,11 +2268,15 @@ static int tty_fasync(int fd, struct file *filp, int on) * * Called functions take tty_ldiscs_lock * * current->signal->tty check is safe without locks */ +static bool tty_legacy_tiocsti __read_mostly = IS_ENABLED(CONFIG_LEGACY_TIOCSTI); static int tiocsti(struct tty_struct *tty, char __user *p) { char ch, mbz = 0; struct tty_ldisc *ld; + if (!tty_legacy_tiocsti) + return -EIO; + if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN)) return -EPERM; if (get_user(ch, p)) @@ -3573,6 +3577,13 @@ void console_sysfs_notify(void) } static struct ctl_table tty_table[] = { + { + .procname = "legacy_tiocsti", + .data = &tty_legacy_tiocsti, + .maxlen = sizeof(tty_legacy_tiocsti), + .mode = 0644, + .proc_handler = proc_dobool, + }, { .procname = "ldisc_autoload", .data = &tty_ldisc_autoload,