Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp190771rdb; Thu, 18 Jan 2024 00:01:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxWkI9BHJE17RX+2WrYwkLpCZA4Yt3Z8KmxP2V9rg4jAAO0EJ1Sz7UpyqFygXG++lyAnCy X-Received: by 2002:a05:6a00:3996:b0:6d9:ae76:c612 with SMTP id fi22-20020a056a00399600b006d9ae76c612mr443162pfb.50.1705564892590; Thu, 18 Jan 2024 00:01:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705564892; cv=pass; d=google.com; s=arc-20160816; b=H3Kynjbnql2qHnK6qBxnq3nLQShEcI/wbFBQD2On0IjNiouEWBQsyOX9XBE38uKxYb DVapksXhKHZ2cVJOZ1P2fXnbe0xeAkd+UyJqweDvI2dyZaAjJXwIS6o4iGdS3LdRkZKZ ByylHBzVCFEYlFCVgKzJ5S+B42CKPYev6t7ONEKcYqdhxwkjvWr7DwPJ/ZwSE0zI7K7m f21oH0+kyBB2crXNw/ICUbDm9JE90fAcX9ukAL9WjIg0oTxuZYWA4A9uZwKHok5D4sdV WiqdvY2tV6ZmzWwTrBywg+l0TTrVKZDwKHMOY/x5gH63jvKousPZ3YcpYeOuT0piEjq0 LnKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=en9WLcGI2YrhmBlSMmCDy7wqF/Gf2ulpVieebFOKcVE=; fh=1YNwm5KBWetjB3qGkhgLqh/dZnCTsWuqRk83JW6hjgE=; b=beW8WNF6RnnRQoGGMSRKXpYaX+PI4qVFMm6J5r1A/NPbZHgcjoYsyTphfBpYGtA58y Um0j/SrtF5arhuWJgHx0uwGMFD2forCdzvMUohQtqr8QbS5hLlpDHseWR69373XB/Vp/ gIXlVyg+6i0losy1MvyloYS+yJN6g5/MX5/Dn4rx82bbfhBE4PP6eEqYaAx7w+N6W3fw 4VlMm+ofpZ+6UTcGNcTaJaZ5458yxN4/yEEueDPhTzThj0Pj2yM5s0jxW5I+30B3FHNt PSgMFXZ20z3kbSNBIRz8DiARLrk4bFdS5KQM3X4ffnLihw7tqDtdRhlNnbzTs4HtO6zE SYuw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HE1F+swH; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-29793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id o134-20020a62cd8c000000b006dabee72f6esi3213042pfg.36.2024.01.18.00.01.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 00:01:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-29793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HE1F+swH; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-29793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 86C63B23EF8 for ; Thu, 18 Jan 2024 07:59:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B82820339; Thu, 18 Jan 2024 07:58:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HE1F+swH" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DEB8200BC; Thu, 18 Jan 2024 07:58:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705564694; cv=none; b=o52os+/DOYdtPNoBLcdcZcqaqgvGDmZ5ETTVAkbEwid1HH+39mLF7onLVXZs2+DLiUoXb+bMpu12EsAxTZx1FbUDQJVrH2MUfcVnqaVrPTzOLBPDXgvkF3iZLhZ14JuyZaXNkSaJ8DDTJVrStE2F1w8nHzJAust4JwdPoQteuzc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705564694; c=relaxed/simple; bh=KLUOMz+nCtQ37yc2nhuHZ5rCdOgRh78LalfH38bE/Io=; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; b=hH/2SHCC3FaVS0KMQj24HF4gWhld4jPrjX8sY/dXUgN9UIS8qqJ+d2al3PhDB8aTKKc91ADi4QB6nWQ674TSisba5XGFLk/aaD8mOVRYQQDZNfTmYKqPIKfxmsITxMLVg+I6aBsPjOMZXKvVZqJEhzeVNKiY7BTOAjWqesIpt7M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HE1F+swH; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23FB6C43390; Thu, 18 Jan 2024 07:58:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705564694; bh=KLUOMz+nCtQ37yc2nhuHZ5rCdOgRh78LalfH38bE/Io=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HE1F+swHwiEmOCOhxTxLu2VE+QOVFM6l9dW6E/T8BexybVd0VlBk5+p2ZBBghCWte uSr04nOoKyWd6wrHupsx/TKng89u6jJ4YfTwWM9Yx1yAqseL2N97bycflrMdMGKaLm MC1FVA0LIoGja1Y8LfQKO7XuRxOxYZq1aCkeXx2mnYOCCkp3aC15Ag2MwkJ1kCJRBB ARvdbMdtDHzy7a1v3AEm8UR2a7WqZ7Awxv534eE5CA20llt2NgSuX9LKS6MtNEABFl eMKbt2MXO/kIbwm1ct/ya+tHYPledlhfDzn7K/ETgLh2BnTq1voYn8+QPnQ8QAStAD ZvyGhzhehD2LA== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 06/45] tty: vt: push console lock from tioclinux() down to 2 functions Date: Thu, 18 Jan 2024 08:57:17 +0100 Message-ID: <20240118075756.10541-7-jirislaby@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118075756.10541-1-jirislaby@kernel.org> References: <20240118075756.10541-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Avoid costly user copies under the console lock. So push the lock down from tioclinux() to sel_loadlut() and set_vesa_blanking(). It is now obvious what is actually protected. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/vt/selection.c | 11 +++++++++-- drivers/tty/vt/vt.c | 13 +++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c index e172ede235a0..91d789c025c6 100644 --- a/drivers/tty/vt/selection.c +++ b/drivers/tty/vt/selection.c @@ -113,15 +113,22 @@ static inline int inword(const u32 c) * sel_loadlut() - load the LUT table * @lut: user table * - * Load the LUT table from user space. The caller must hold the console - * lock. Make a temporary copy so a partial update doesn't make a mess. + * Load the LUT table from user space. Make a temporary copy so a partial + * update doesn't make a mess. + * + * Locking: The console lock is acquired. */ int sel_loadlut(u32 __user *lut) { u32 tmplut[ARRAY_SIZE(inwordLut)]; + if (copy_from_user(tmplut, lut, sizeof(inwordLut))) return -EFAULT; + + console_lock(); memcpy(inwordLut, tmplut, sizeof(inwordLut)); + console_unlock(); + return 0; } diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 079dbff562fd..3a6f60ad2224 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -3162,10 +3162,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg) case TIOCL_SELLOADLUT: if (!capable(CAP_SYS_ADMIN)) return -EPERM; - console_lock(); - ret = sel_loadlut(param_aligned32); - console_unlock(); - break; + return sel_loadlut(param_aligned32); case TIOCL_GETSHIFTSTATE: /* * Make it possible to react to Shift+Mousebutton. Note that @@ -3181,10 +3178,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg) console_unlock(); return put_user(data, p); case TIOCL_SETVESABLANK: - console_lock(); - ret = set_vesa_blanking(param); - console_unlock(); - break; + return set_vesa_blanking(param); case TIOCL_GETKMSGREDIRECT: data = vt_get_kmsg_redirect(); return put_user(data, p); @@ -4270,7 +4264,10 @@ static int set_vesa_blanking(u8 __user *mode_user) if (get_user(mode, mode_user)) return -EFAULT; + console_lock(); vesa_blank_mode = (mode < 4) ? mode : 0; + console_unlock(); + return 0; } -- 2.43.0