Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp822974pxb; Tue, 3 Nov 2020 13:33:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJwdKwH7b8oog5NEWKy+oTxpUlM2HyGAma2M9yDnwamIVXm/R+QZxuDXm2/K5eK5In7OX/k/ X-Received: by 2002:aa7:c704:: with SMTP id i4mr23647006edq.51.1604439189448; Tue, 03 Nov 2020 13:33:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604439189; cv=none; d=google.com; s=arc-20160816; b=Gl9U95oFIa1xtEso+Q1J7vr6erjMeIwN4dgplSYCSrEeGFdA4TQlxxrVC9sKRyu6Fs iufWfMpeVCOW6rBUpo9WbDOFbz+n2N0ua+Mm3k17tFzQ26UMokk/dmKj8QOZg8njxaWR js7pXLvLq9KnfHCCf6i91nfc/BFUeqj7zpSD4cfcRiafcNrH38O/Ro43l1LjftfXg/bg tSZfPbP2MXkBwpgkuRNof4n9kDME9qDtgZkdkstxA+L9WInbY508ZlENh0uQjwAwBhbS VoNXmi9AdkKdgRvEYAX3pJpIVSSFqkAdlb5fYA0AVlGV7+bzIByjRaPoKXHz3DmMdFI6 gc2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5HV5S0cLGnNpk0TXeUB8ldkasf2dlw3jsIRM/Pf2egQ=; b=fjCt3kIGzdFEE9TOwM6ENs8aVlaJx78A9C0hdVV3+vb7/1x4KgIPYwN9EDuWwdJqn3 xieLpgoeKLNgKQH/DX/8IRRbY8VDMetGOjekhZfGJL/cw++2VsKr7EhSHaPRuEzSFnAl 4FXTcMjTl2HWcBlCH44h/hk1L9UCh6Um0KQxCv1NXKTsU3P+EB1sYUL9uNv2W8egT6A7 1Nf5nyKN8JsW133KAfKIKgMlxpMzmhVolutGFQv7th+Dt1tlDdUVJYlaD/1PN242lM9b +nuNxwW7x64ii/X34qO8b3xCw4Cr4oDYLZlRGrErwxiQBk5tpHJMHb2ewXTOsFVy6b+k FmEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=u2hfCC0s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x5si83102ejf.218.2020.11.03.13.32.46; Tue, 03 Nov 2020 13:33:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=u2hfCC0s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387438AbgKCVaM (ORCPT + 99 others); Tue, 3 Nov 2020 16:30:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:60980 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732951AbgKCU6U (ORCPT ); Tue, 3 Nov 2020 15:58:20 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 7EBA2223BF; Tue, 3 Nov 2020 20:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437100; bh=3KC4q/WKvwirtoZYm5qwm0oGZDlEH+sS+/qPASVN8PI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u2hfCC0sJ1ocyIK6Bou03/Z0YRRjhTwc6S761Or/oropdCtnI4hmVBTCe4QMWQZ7Q dE7+vzLWvUrLe63y76gO3pAr80mUgmpFVqTCt3gFrFPqk3zT1eT6cL3dy4c/uDKaTj 9NRuepsE1OWcNlcOI82eYue5kIbYtlFK6u6DAFys= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Slaby Subject: [PATCH 5.4 145/214] vt: keyboard, simplify vt_kdgkbsent Date: Tue, 3 Nov 2020 21:36:33 +0100 Message-Id: <20201103203304.398464393@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Slaby commit 6ca03f90527e499dd5e32d6522909e2ad390896b upstream. Use 'strlen' of the string, add one for NUL terminator and simply do 'copy_to_user' instead of the explicit 'for' loop. This makes the KDGKBSENT case more compact. The only thing we need to take care about is NULL 'func_table[i]'. Use an empty string in that case. The original check for overflow could never trigger as the func_buf strings are always shorter or equal to 'struct kbsentry's. Cc: Signed-off-by: Jiri Slaby Link: https://lore.kernel.org/r/20201019085517.10176-1-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman --- drivers/tty/vt/keyboard.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -1994,9 +1994,7 @@ out: int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm) { struct kbsentry *kbs; - char *p; u_char *q; - u_char __user *up; int sz, fnw_sz; int delta; char *first_free, *fj, *fnw; @@ -2022,23 +2020,15 @@ int vt_do_kdgkb_ioctl(int cmd, struct kb i = kbs->kb_func; switch (cmd) { - case KDGKBSENT: - sz = sizeof(kbs->kb_string) - 1; /* sz should have been - a struct member */ - up = user_kdgkb->kb_string; - p = func_table[i]; - if(p) - for ( ; *p && sz; p++, sz--) - if (put_user(*p, up++)) { - ret = -EFAULT; - goto reterr; - } - if (put_user('\0', up)) { - ret = -EFAULT; - goto reterr; - } - kfree(kbs); - return ((p && *p) ? -EOVERFLOW : 0); + case KDGKBSENT: { + /* size should have been a struct member */ + unsigned char *from = func_table[i] ? : ""; + + ret = copy_to_user(user_kdgkb->kb_string, from, + strlen(from) + 1) ? -EFAULT : 0; + + goto reterr; + } case KDSKBSENT: if (!perm) { ret = -EPERM;