Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp835979yba; Wed, 24 Apr 2019 10:22:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDlMk2hXAQHUaIMVVFJsdOYXn73q/TCqEnlOEllnXfoEmw6nybD1zDCJu6daV1KjzpD0u6 X-Received: by 2002:a63:8e:: with SMTP id 136mr30622550pga.367.1556126532917; Wed, 24 Apr 2019 10:22:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556126532; cv=none; d=google.com; s=arc-20160816; b=1EcmC7fPgOHxL4YjqVDBuBgQyeqOtZ4UC2H9RNU6EcEkLfNjyTkV9MjZ3ClrS2qdJd RRJcZS9U3HByTYEljc2LFECUsjiDZU534ByYOC7I2Vk72HbA+5yrA+5jVbnL8ighKPst IFCAvjmGuu3O7lez5nj3PcTPioFKK7zpFV4HTlSDkPAWOZafR2IquIDJj6ajoK91oaFa KSzQdwFek/aXHhIa5OTbYwtr4slxXp5eTpSLsH/t6KZkmrzzerBtskCv4xskbhc8o3GK DA+rh+czaWo487i5gsQcoYo/c4ksDr7gVCVm6n1/HRDumFf7kCWOUIFrtsWqxO4/02H+ eTYQ== 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=AYb63lX7HEd1J/hGQqO6pErlqrS9S9HchbMIw4UrMHM=; b=noiY2h6dEXqrTXyHsh1l2Ag/xF8p4vzbUB4jc4i62zy7ZWmw1DD09SywL3C7tu1IH3 krLPn+lIeVS7D7VeOskFOH1d4MXhTHTo9xYX12ylIV1Sh+Gn7kPzCuZ7ZOKUzDruzdfS IHMBlmClUi/JugoV6G/A4l0UNYJP8GMg75AyZ66nSC4cfVibsRi4E5VyXcdZMcDhbNA6 OsesA0pPAyHG22e77FnCWHrqrfVg8dohgbLAj0DowumtiqeZCQl5b48oGKxkYTzWH1fU dML5V5DsGm4frMAYwEToCouGKcf5YWXYgqbsAOkmHy7iERnUa/fMf5cPoBI97tlSqazp 5Fdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SEup2TZc; 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 p8si18403383pgb.77.2019.04.24.10.21.57; Wed, 24 Apr 2019 10:22:12 -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=SEup2TZc; 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 S2388922AbfDXRTA (ORCPT + 99 others); Wed, 24 Apr 2019 13:19:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:44144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388239AbfDXRS6 (ORCPT ); Wed, 24 Apr 2019 13:18:58 -0400 Received: from localhost (62-193-50-229.as16211.net [62.193.50.229]) (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 98FE4218B0; Wed, 24 Apr 2019 17:18:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556126337; bh=xZRO2nttMVX1PSkfMW7B1iRvG+br0ANEvUGGvxASUE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SEup2TZcSpjXT82vCThXBquk8uOYZApubNBZyFvYFtnMLalL1zD9THfW6vgkc7L4a pZyqm5YyuLOhsprcnfxKQWfITICMvg0yIOVBc0ND4xpxPD3Qvk56uyJrbtOOgFM397 EcGL3Kkd6UpZEFEx1rvCEk2IU1COTckGIU2TcEvA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso Subject: [PATCH 4.4 076/168] tty: ldisc: add sysctl to prevent autoloading of ldiscs Date: Wed, 24 Apr 2019 19:08:40 +0200 Message-Id: <20190424170928.415407422@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424170923.452349382@linuxfoundation.org> References: <20190424170923.452349382@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 | 23 +++++++++++++++++++++++ drivers/tty/tty_io.c | 3 +++ drivers/tty/tty_ldisc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) --- a/drivers/tty/Kconfig +++ b/drivers/tty/Kconfig @@ -466,4 +466,27 @@ config MIPS_EJTAG_FDC_KGDB_CHAN help FDC channel number to use for KGDB. +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 @@ -513,6 +513,8 @@ void proc_clear_tty(struct task_struct * tty_kref_put(tty); } +extern void tty_sysctl_init(void); + /** * proc_set_tty - set the controlling terminal * @@ -3689,6 +3691,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 @@ -148,6 +148,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; @@ -162,6 +169,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)) @@ -830,3 +839,41 @@ void tty_ldisc_begin(void) /* Setup the default TTY line discipline. */ (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY); } + +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); +}