Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2479219yba; Mon, 15 Apr 2019 12:30:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjvfZh5X2UtemHXbvri08puKMZOK9Vz2oK9E0OH/wTp3V/+FxMseOHa9s9WGo6qd84OZlo X-Received: by 2002:a17:902:d211:: with SMTP id t17mr74911664ply.214.1555356633794; Mon, 15 Apr 2019 12:30:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555356633; cv=none; d=google.com; s=arc-20160816; b=fWkpw/Q3NNEYaxPsweZbrsq2TMgLhwu998bCuMLIRyOBHoy3d1oaCY387NL/m5XqMH J9V0BsPedZnZskI+yTz3ZOFow04+jyCvFcsZ5K5zu9QFI91QYctM/tgXP5VuPeq2D0X9 VzC42pBz8UfgxQrTti41He+mzI+DRw4uJfNgthtKNJ6qG1uEGjqiKqevb+IJJhpGNW/B gt1w79lx4XByP5QdMq/6VYTn5Gu8gqvb6s7Q0tSc+wsPVTZtoe+78KgRxO+KrAxetyPe vGf/ka9bEfTNeXPsmHxq2FgOPXWy/qFuq3aczQzGM9tIneuHvsZiQ0jRNSymkVxiBato EY5A== 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=DPlRRjs/GfgDVa7UARM6RNl4z7aXhwrTehqJZcfIFhc=; b=NfV3K+59qOZ6qlUrhOhHIIH7lMVGBgXkuLr+3vXijVavyGj3vQFl/05uy+u6NdSv46 DnqQfYgbS99GVeYNb1xvlbh/lugm918Xx67YysWPfvedXPe26pczBMDVLjjPn3qDK2eJ +EW01h3IJkLhyfIU685QPkcH3ljp6ONcdkiaJuwiEm8u1LTQQybqJoowB9FbcVZ/0gbp vQi+8QvJy1DNlJWmQkFg+3RXU5dYJkKnu4y8U0T1cZkh+QVWuyDBaluo2xrzSCWCP5fJ FG3/AmVU3955P1nJzQB4F/vosG452mJRs+x+97fjurvJZ8Qob9cNgQOWY2mhKWsP9zK9 2KHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oVWgTJw1; 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 v20si45331936pfa.224.2019.04.15.12.30.17; Mon, 15 Apr 2019 12:30:33 -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=oVWgTJw1; 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 S1728967AbfDOTCp (ORCPT + 99 others); Mon, 15 Apr 2019 15:02:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:33876 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728885AbfDOTCn (ORCPT ); Mon, 15 Apr 2019 15:02:43 -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 E6A31218A1; Mon, 15 Apr 2019 19:02:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555354961; bh=7bZHqLJaSD8Um4rnFPt71kY+dGOFr1V8Td2QvXSYYl4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oVWgTJw1D2PS6Z9I/53TRyUJTnxOPfenmeJ5bXNvtZ/XajjXmy68eOCLI0mQxjRL2 Ed+gx3uUIIPjPCJ6t+jg8/2KayBDLCgEPyM+sXjo6V0di2rAXZqnB6oJXNlUwdOVPQ u/mKUpDm3e5BVYFcDr0+3sTabHUCRIazV1Bi7WdY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso Subject: [PATCH 4.14 15/69] tty: ldisc: add sysctl to prevent autoloading of ldiscs Date: Mon, 15 Apr 2019 20:58:33 +0200 Message-Id: <20190415183729.578020584@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183726.036654568@linuxfoundation.org> References: <20190415183726.036654568@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 @@ -467,4 +467,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 @@ -511,6 +511,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 @@ -3332,6 +3334,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 @@ -155,6 +155,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; @@ -169,6 +176,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)) @@ -841,3 +850,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); +}