From patchwork Mon Mar 6 09:49:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 64542 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1753603wrd; Mon, 6 Mar 2023 02:04:48 -0800 (PST) X-Google-Smtp-Source: AK7set8p4kDkbL6JKg1H9lq2Jl8k8o7cQj9/cWCzabZpkKIniszYWF9KPvWb6rSlDoOA00iq9+It X-Received: by 2002:a17:906:2cd6:b0:887:2248:efd5 with SMTP id r22-20020a1709062cd600b008872248efd5mr8959817ejr.77.1678097088395; Mon, 06 Mar 2023 02:04:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678097088; cv=none; d=google.com; s=arc-20160816; b=eZYdszTdI/q2xpOlZNXtAKCtY2uFEwzDWCeIXENYWdI0FkFxrsVeUSFHc1Ag+5chHP +1LHNSqo4aT0HbDYmfANbIzQ81cM8VBv3MzobpD/dqakBO4aws4B1LSuRO8BDXduTN0+ raD8spKwedSekU1EQ8E/ueFjv3CGthbRsMTDeDAzmr+dACeAPc2QgYwYH3ZhxOLs58bU bd0JjY32ka97n0nnn58l7XUn6E5r3Sx9nTAlPPuTAylmSmW0xVUj4OPBZw3apy7HJ3V6 lj7WxynhY6PfwQBI02qE2/XlO99TLQnnUUxpn35pAd/jRZGxE8wJQg8SpySymcq1bal4 AeOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:organization:content-disposition :mime-version:mail-followup-to:message-id:subject:cc:to:from:date; bh=cLO9vOVakWkBmcJlP4HELJyObY86aBFVngpb/6lEh/I=; b=KnGGAu6qsw3flOjlGudvjsNwaxVAfInkCD2WTa0L/svc6JTa1SRXTyP54JwYL6P7os uiHDT4aT4NK2S6T+5+98TBZaQmjhGrMxiU0ILhsNjen0T5ImuZm/PFMDW2UXs8qdtyCc Bo9l9iaC8rNmXPTPThj6xm97UQ2oVXIG0qQaduiGS0PD800W44GuTMOpDug0xu1adUxH tl7Y8kr7eI9sTCJ6eRKAkivVk1NnqfwFoPD4T4C7aW4ztSspvoDupAxIr9+K+xq6ly9Z Iwlwqv07wO5iejWl0B0sH7CKGjaL+EqtAO3bxVwybcESGPxAqdF6pXCuZvn88nJxoW4o G4KA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s13-20020a1709066c8d00b008cc8a6fea26si10139220ejr.561.2023.03.06.02.04.24; Mon, 06 Mar 2023 02:04:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbjCFJt1 (ORCPT + 99 others); Mon, 6 Mar 2023 04:49:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229540AbjCFJtZ (ORCPT ); Mon, 6 Mar 2023 04:49:25 -0500 Received: from sonata.ens-lyon.org (sonata.ens-lyon.org [140.77.166.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE608C651; Mon, 6 Mar 2023 01:49:24 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id BFA9E20137; Mon, 6 Mar 2023 10:49:22 +0100 (CET) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hErAdg_uF3sj; Mon, 6 Mar 2023 10:49:22 +0100 (CET) Received: from begin (nat-inria-interne-52-gw-01-bso.bordeaux.inria.fr [194.199.1.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id 455092012C; Mon, 6 Mar 2023 10:49:22 +0100 (CET) Received: from samy by begin with local (Exim 4.96) (envelope-from ) id 1pZ7T7-0001Rf-1i; Mon, 06 Mar 2023 10:49:21 +0100 Date: Mon, 6 Mar 2023 10:49:21 +0100 From: Samuel Thibault To: gregkh@linuxfoundation.org Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sanan Hasanov , Samuel Thibault , keescook@chromium.org, syzbot+3af17071816b61e807ed@syzkaller.appspotmail.com, akpm@linux-foundation.org, linux-hardening@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com, Jiri Slaby Subject: [PATCH] VT: Protect KD_FONT_OP_GET_TALL from unbound access Message-ID: <20230306094921.tik5ewne4ft6mfpo@begin> Mail-Followup-To: Samuel Thibault , gregkh@linuxfoundation.org, linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sanan Hasanov , keescook@chromium.org, syzbot+3af17071816b61e807ed@syzkaller.appspotmail.com, akpm@linux-foundation.org, linux-hardening@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com, Jiri Slaby MIME-Version: 1.0 Content-Disposition: inline Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759612332308787890?= X-GMAIL-MSGID: =?utf-8?q?1759612332308787890?= In ioctl(KD_FONT_OP_GET_TALL), userland tells through op->height which vpitch should be used to copy over the font. In con_font_get, we were not checking that it is within the maximum height value, and thus userland could make the vc->vc_sw->con_font_get(vc, &font, vpitch); call possibly overflow the allocated max_font_size bytes, and the copy_to_user(op->data, font.data, c) call possibly read out of that allocated buffer. By checking vpitch against max_font_height, the max_font_size buffer will always be large enough for the vc->vc_sw->con_font_get(vc, &font, vpitch) call (since we already prevent loading a font larger than that), and c = (font.width+7)/8 * vpitch * font.charcount will always remain below max_font_size. Fixes: 24d69384bcd3 ("VT: Add KD_FONT_OP_SET/GET_TALL operations") Reported-by: syzbot+3af17071816b61e807ed@syzkaller.appspotmail.com Signed-off-by: Samuel Thibault Reviewed-by: Jiri Slaby diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 57a5c23b51d4..3c2ea9c098f7 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -4545,6 +4545,9 @@ static int con_font_get(struct vc_data *vc, struct console_font_op *op) int c; unsigned int vpitch = op->op == KD_FONT_OP_GET_TALL ? op->height : 32; + if (vpitch > max_font_height) + return -EINVAL; + if (op->data) { font.data = kvmalloc(max_font_size, GFP_KERNEL); if (!font.data)