Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2521840yba; Mon, 15 Apr 2019 13:29:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxW3GIgi2+v/BqjD4hF+JkZqJuXwzR6cqGBDijCzRzkgw5ALrBVEBBK1No5vURlciG75uq1 X-Received: by 2002:a17:902:567:: with SMTP id 94mr46299320plf.120.1555360194027; Mon, 15 Apr 2019 13:29:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555360194; cv=none; d=google.com; s=arc-20160816; b=WPrb99gME5VLd2W2/oPHUvvB/eBY3PLCWSXUNFBGK/cufema6Rp3n8Z6GCUOW2adZc aZOa3SyVYYGkF3Wossm79wCflFBCPMM3cFemPHbv2ivLfT7Ug0cb3AeilUCpK8o5bJFF VCmRczxxUTp5YbxAIvL0ZrU+Av2PNYEdeJoX+7L+RvOuVy8btI3j4+JjXBB4QOq5VJYt qx4jTPch37COFPxhNBKOic91gzMZn1717MtNWUr2vGCm/GE8j4qQiXV3eu8V7MUcJjBi XLITvN8rBSdzezX25hi5WUwjD8buGbm7QzkzZsxqrPd6CZiIgh1VMUMLyZ372GJdIP8U GCXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CUAD3J1PQlnJHEP8EMZz/cvZriCtwbmEmZXeqecb2lw=; b=hpBgITnwolS4hnoZAfJcQ2Zur6Uf7UnGpAGWTqr3Wlh8QlrH23s3lG+jp/ju/CYxHz hZ0LocvD3IPXgKplbzhMBcTbeeCH3mCT1uc+0uZ0qMsNR1wJ2YeisMDiISz05go00S9u LVMeefVhE83HzD1G7/3Hf4kQDHLE3DYe5IQyTCBCOalNsepMNBmI3uFA/0Nyi40s1D7f 01ik25uHN81piQCAKRW8RASIBoWw1uk+hMD9dz+yItYLU1Xb9JBRWS4JAmKvSk2nnE9q xTbUSkmKa0AILzYcUOH+FNIFleMmrxYtVuijmm9vk1qyzdOTCjrt3/3237SlWYRQ1C59 HtMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z6UnPpzb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t194si43726298pgb.316.2019.04.15.13.29.37; Mon, 15 Apr 2019 13:29:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z6UnPpzb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729954AbfDOTGa (ORCPT + 99 others); Mon, 15 Apr 2019 15:06:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:40892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729924AbfDOTG2 (ORCPT ); Mon, 15 Apr 2019 15:06:28 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 52920218A1; Mon, 15 Apr 2019 19:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355187; bh=zs877YgpGygAIbAjzA/5oGiiO+7HH/6rhHZ70NKLxvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z6UnPpzbAX+w3BV0cMtmXNJm6gzCZuUJzv94OV2IdfhcVet2GuimlSfPFIGiTkmn1 AmGRWGMgMtmKNkoHq+4uqzCUJ5OSelYHZUU2lo6et54IpmieP3PBH6YENSlPeGgeMw CVPdwBaQgxQA49GuYzxKA8Ko14eNZMKctFbnohws= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso Subject: [PATCH 4.19 046/101] tty: ldisc: add sysctl to prevent autoloading of ldiscs Date: Mon, 15 Apr 2019 20:58:44 +0200 Message-Id: <20190415183743.023183415@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183740.341577907@linuxfoundation.org> References: <20190415183740.341577907@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman commit 7c0cca7c847e6e019d67b7d793efbbe3b947d004 upstream. By default, the kernel will automatically load the module of any line dicipline that is asked for. As this sometimes isn't the safest thing to do, provide a sysctl to disable this feature. By default, we set this to 'y' as that is the historical way that Linux has worked, and we do not want to break working systems. But in the future, perhaps this can default to 'n' to prevent this functionality. Signed-off-by: Greg Kroah-Hartman Reviewed-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- drivers/tty/Kconfig | 24 ++++++++++++++++++++++++ drivers/tty/tty_io.c | 3 +++ drivers/tty/tty_ldisc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) --- a/drivers/tty/Kconfig +++ b/drivers/tty/Kconfig @@ -441,4 +441,28 @@ config VCC depends on SUN_LDOMS help Support for Sun logical domain consoles. + +config LDISC_AUTOLOAD + bool "Automatically load TTY Line Disciplines" + default y + help + Historically the kernel has always automatically loaded any + line discipline that is in a kernel module when a user asks + for it to be loaded with the TIOCSETD ioctl, or through other + means. This is not always the best thing to do on systems + where you know you will not be using some of the more + "ancient" line disciplines, so prevent the kernel from doing + this unless the request is coming from a process with the + CAP_SYS_MODULE permissions. + + Say 'Y' here if you trust your userspace users to do the right + thing, or if you have only provided the line disciplines that + you know you will be using, or if you wish to continue to use + the traditional method of on-demand loading of these modules + by any user. + + This functionality can be changed at runtime with the + dev.tty.ldisc_autoload sysctl, this configuration option will + only set the default value of this functionality. + endif # TTY --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -512,6 +512,8 @@ static const struct file_operations hung static DEFINE_SPINLOCK(redirect_lock); static struct file *redirect; +extern void tty_sysctl_init(void); + /** * tty_wakeup - request more data * @tty: terminal @@ -3340,6 +3342,7 @@ void console_sysfs_notify(void) */ int __init tty_init(void) { + tty_sysctl_init(); 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) --- a/drivers/tty/tty_ldisc.c +++ b/drivers/tty/tty_ldisc.c @@ -156,6 +156,13 @@ static void put_ldops(struct tty_ldisc_o * takes tty_ldiscs_lock to guard against ldisc races */ +#if defined(CONFIG_LDISC_AUTOLOAD) + #define INITIAL_AUTOLOAD_STATE 1 +#else + #define INITIAL_AUTOLOAD_STATE 0 +#endif +static int tty_ldisc_autoload = INITIAL_AUTOLOAD_STATE; + static struct tty_ldisc *tty_ldisc_get(struct tty_struct *tty, int disc) { struct tty_ldisc *ld; @@ -170,6 +177,8 @@ static struct tty_ldisc *tty_ldisc_get(s */ ldops = get_ldops(disc); if (IS_ERR(ldops)) { + if (!capable(CAP_SYS_MODULE) && !tty_ldisc_autoload) + return ERR_PTR(-EPERM); request_module("tty-ldisc-%d", disc); ldops = get_ldops(disc); if (IS_ERR(ldops)) @@ -829,3 +838,41 @@ void tty_ldisc_deinit(struct tty_struct tty_ldisc_put(tty->ldisc); tty->ldisc = NULL; } + +static int zero; +static int one = 1; +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 = &zero, + .extra2 = &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); +}