From patchwork Wed Jan 9 03:55:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 155044 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp254734jaa; Tue, 8 Jan 2019 19:55:55 -0800 (PST) X-Google-Smtp-Source: ALg8bN7TGYheve/FuEIy13LCyC5J/DthtZuiur3oGmOjjNuTvKZ6XVapbGsFC3SZfAjvIG7XLE8m X-Received: by 2002:a63:3602:: with SMTP id d2mr3886017pga.404.1547006155633; Tue, 08 Jan 2019 19:55:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547006155; cv=none; d=google.com; s=arc-20160816; b=FUFeNOc6N0lgeg6pqZUHsU7e/hmYFVZlerbuR3IL08APP5sN+0alXk17Svd9+SDvG/ bm22gsGk+wlP8MaxWCNsqrVSLb7lcANNHLVAA86ypG5rgVAp0NxN+0ywp1KAhtgboz0W /4B5lKVaYstUzRs26PVVcBAFVc5DSmooEJHdMQeLNjCHjpOnTsqgr+0WHVikjpnYfpU6 F/akaSiYuxccbcaei4NTS7p6u/rB8mWHc5v5lSSqE1RpIQcfeU+PpnsXs2pz4pxDTnw+ T3SIBXlqCBuSUsIXu30NlIjYaHJ4/prGTjFIatQk+UJKVkdqHBVt4phaO6cwIIurUOV0 PMiw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6Dv01mCvUpuQlYx45hJPhTLqf1ZdQDmBP145IArq4pc=; b=Bp+lMnLsSuMN0BeFFr7kjdUz12gGwWsuWaH3P5NRB34B7PmYp533ZQcGIEzw+fueq4 uMqDqI1PkvzMWnX13W0ii4885AlEanUaqskz07XL8oYrzn5b+s2rduBJlXA1cN7DKVK0 +Wtra7QLfEyctdMH3yD56jACXevDUo5xA6FuV+ScA93qkY01VELejK/G4+W2nLtpnWhI r7SL+e8EZ1FSemPzragn6u5zm7BzL0Kp1KRhCemLx+NoAcziJtQOthHpg9EiKkcG0DQP qYiHwuLLqL29vOGwfAO/3SWhnxtYbAkxyjKZBBwbfZ9T0Gd+wbeDglOxk/QFkMSVaMDd SVEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pobox.com header.s=sasl header.b=MDP5Eu2g; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u21si61249842pgm.21.2019.01.08.19.55.55; Tue, 08 Jan 2019 19:55:55 -0800 (PST) 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=@pobox.com header.s=sasl header.b=MDP5Eu2g; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729463AbfAIDzy (ORCPT + 31 others); Tue, 8 Jan 2019 22:55:54 -0500 Received: from pb-smtp1.pobox.com ([64.147.108.70]:52600 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729172AbfAIDzt (ORCPT ); Tue, 8 Jan 2019 22:55:49 -0500 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 2E323119309; Tue, 8 Jan 2019 22:55:47 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=6xfC+s0P4dYOGWNJOn3g1/ibg c4=; b=MDP5Eu2gJD2ROAPU0wxTvj2CVPzy8yKEYZV71nwHKfZ9rHDqt6m1fEOnH /X76HlTKqVhRWhcY/kbT6/mpvyUd41e5R8aJMlMmCS542jKSsyEPWDhiaySinge3 giVGP/1mADbnphsrvVtDyihR8c59aRF4oWb0UHO5EnCWN7Z324= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 23627119308; Tue, 8 Jan 2019 22:55:47 -0500 (EST) Received: from yoda.home (unknown [70.82.104.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 8CF2C119300; Tue, 8 Jan 2019 22:55:46 -0500 (EST) Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id A91942DA06DA; Tue, 8 Jan 2019 22:55:45 -0500 (EST) From: Nicolas Pitre To: Greg Kroah-Hartman Cc: Dave Mielke , linux-kernel@vger.kernel.org Subject: [PATCH 4/6] vcsa: clamp header values when they don't fit Date: Tue, 8 Jan 2019 22:55:02 -0500 Message-Id: <20190109035504.8413-5-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190109035504.8413-1-nicolas.pitre@linaro.org> References: <20190109035504.8413-1-nicolas.pitre@linaro.org> MIME-Version: 1.0 X-Pobox-Relay-ID: 71D63472-13C2-11E9-BDB8-70EFDD2159A7-78420484!pb-smtp1.pobox.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The /dev/vcsa* devices have a fixed char-sized header that stores the screen geometry and cursor location. Let's make sure it doesn't contain random garbage when those values exceed 255. If ever it becomes necessary to convey larger screen info to user space then a larger header in the not-yet-implemented /dev/vcsua* devices should be considered. Signed-off-by: Nicolas Pitre --- drivers/tty/vt/vc_screen.c | 5 +++-- drivers/tty/vt/vt.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) -- 2.20.1 diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c index 2384ea85ff..3dba60825c 100644 --- a/drivers/tty/vt/vc_screen.c +++ b/drivers/tty/vt/vc_screen.c @@ -335,8 +335,9 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) if (p < HEADER_SIZE) { size_t tmp_count; - con_buf0[0] = (char)vc->vc_rows; - con_buf0[1] = (char)vc->vc_cols; + /* clamp header values if they don't fit */ + con_buf0[0] = min(vc->vc_rows, 0xFFu); + con_buf0[1] = min(vc->vc_cols, 0xFFu); getconsxy(vc, con_buf0 + 2); con_buf_start += p; diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index bba75560d1..f519c22e70 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -4591,8 +4591,9 @@ EXPORT_SYMBOL_GPL(screen_pos); void getconsxy(struct vc_data *vc, unsigned char *p) { - p[0] = vc->vc_x; - p[1] = vc->vc_y; + /* clamp values if they don't fit */ + p[0] = min(vc->vc_x, 0xFFu); + p[1] = min(vc->vc_y, 0xFFu); } void putconsxy(struct vc_data *vc, unsigned char *p)