Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2358044pxk; Sun, 27 Sep 2020 04:48:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyO7GeesnI+oD+hC3Y+6o8uiDuRK69cd677gh5nhyXcl91S1UlZMUvAFwsHtZHlAt7rzQLW X-Received: by 2002:a17:906:3957:: with SMTP id g23mr11660166eje.24.1601207300291; Sun, 27 Sep 2020 04:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601207300; cv=none; d=google.com; s=arc-20160816; b=M/SyX2OEyULleZESxRoaXIg/Nmtpe5wm2tlwidfu00KQisELqXexhYntDyxORqL/jW no8oo1CsGpxRfBOkTVQLX+g3QwhGEVH1e/inBfJViLbvEvT3bAVkdGrjdeeotsB2Zj3G ESjl09bL8qvEn3tXijMkgQNy/TrnELGPgLvojxUbTgpO3WhykR/KNNOKFw9zS79ievUv MnzyBi2gNqWEC3ZLOOPlmsaCgdnRMEeA4uDVJaZaNKIRkxyybhoecvKnWP6dA5i7RBUG IzZ3vO+/NHOLIdtJgnVD4F22/emHrqSivTNAwRCjpPOMineUIqmwATqB1RjJRkxf48Yt +lQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=dk8ofHzMe2hZvx2lLRPIy7+QwvElcV6mvrmAHFPV6iI=; b=lD4Pa2JLz/p5vvWVcEpsgXnl2D1uqgVTloZz41si0DPMMDaRDAn0M74sLv0GLG8O/x TJAb4ZZHUFTOUEqVZEeZPT5G44qCQL9tSYwaahcxY1fEApZsiPk/vah1YD1OC0wvF81S iupeXGKyIl6uUH/8F111Gxn9k7VnHhbOQaRF8tYyELrilfdfQGtqaOj+ejQn0bdqinEd 8X08KafO0pH4XEKQ0V+iGD+KZ+sZZCb81FTfCdEAiq3UnyhG6NRyEZ7+5STlWYcufVnL eCfnnGuEx6hv92YkwQxiEHMC8833r4CjEiELGyMWmtaRM/2m8lCNsFy5TPyxh4aOgwsh cvNQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p8si5704826edi.48.2020.09.27.04.47.55; Sun, 27 Sep 2020 04:48:20 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726280AbgI0Lqe (ORCPT + 99 others); Sun, 27 Sep 2020 07:46:34 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:59255 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726185AbgI0Lqe (ORCPT ); Sun, 27 Sep 2020 07:46:34 -0400 Received: from fsav105.sakura.ne.jp (fsav105.sakura.ne.jp [27.133.134.232]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 08RBkVsj015800; Sun, 27 Sep 2020 20:46:31 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav105.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav105.sakura.ne.jp); Sun, 27 Sep 2020 20:46:31 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav105.sakura.ne.jp) Received: from [192.168.1.9] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 08RBkVRr015794 (version=TLSv1.2 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 27 Sep 2020 20:46:31 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Subject: [PATCH] vt_ioctl: make VT_RESIZEX behave like VT_RESIZE To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: Peilin Ye , syzbot , b.zolnierkie@samsung.com, daniel.vetter@ffwll.ch, deller@gmx.de, syzkaller-bugs@googlegroups.com, Linus Torvalds , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, George Kennedy References: <000000000000226d3f05b02dd607@google.com> <47907f77-b14b-b433-45c6-a315193f0c1a@i-love.sakura.ne.jp> <494395bc-a7dd-fdb1-8196-a236a266ef54@i-love.sakura.ne.jp> <20200927092701.GA1037755@PWN> From: Tetsuo Handa Message-ID: <4933b81b-9b1a-355b-df0e-9b31e8280ab9@i-love.sakura.ne.jp> Date: Sun, 27 Sep 2020 20:46:30 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20200927092701.GA1037755@PWN> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org syzbot is reporting UAF/OOB read at bit_putcs()/soft_cursor() [1][2], for vt_resizex() from ioctl(VT_RESIZEX) allows setting font height larger than actual font height calculated by con_font_set() from ioctl(PIO_FONT). Since fbcon_set_font() from con_font_set() allocates minimal amount of memory based on actual font height calculated by con_font_set(), use of vt_resizex() can cause UAF/OOB read for font data. VT_RESIZEX was introduced in Linux 1.3.3, but it is unclear that what comes to the "+ more" part, and I couldn't find a user of VT_RESIZEX. #define VT_RESIZE 0x5609 /* set kernel's idea of screensize */ #define VT_RESIZEX 0x560A /* set kernel's idea of screensize + more */ So far we are not aware of syzbot reports caused by setting non-zero value to v_vlin parameter. But given that it is possible that nobody is using VT_RESIZEX, we can try removing support for v_clin and v_vlin parameters. Therefore, this patch effectively makes VT_RESIZEX behave like VT_RESIZE, with emitting a message if somebody is still using v_clin and/or v_vlin parameters. [1] https://syzkaller.appspot.com/bug?id=32577e96d88447ded2d3b76d71254fb855245837 [2] https://syzkaller.appspot.com/bug?id=6b8355d27b2b94fb5cedf4655e3a59162d9e48e3 Reported-by: syzbot Reported-by: syzbot Signed-off-by: Tetsuo Handa --- drivers/tty/vt/vt_ioctl.c | 57 +++++++-------------------------------- 1 file changed, 10 insertions(+), 47 deletions(-) diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c index a4e520bdd521..bc33938e2f20 100644 --- a/drivers/tty/vt/vt_ioctl.c +++ b/drivers/tty/vt/vt_ioctl.c @@ -773,58 +773,21 @@ static int vt_resizex(struct vc_data *vc, struct vt_consize __user *cs) if (copy_from_user(&v, cs, sizeof(struct vt_consize))) return -EFAULT; - /* FIXME: Should check the copies properly */ - if (!v.v_vlin) - v.v_vlin = vc->vc_scan_lines; - - if (v.v_clin) { - int rows = v.v_vlin / v.v_clin; - if (v.v_rows != rows) { - if (v.v_rows) /* Parameters don't add up */ - return -EINVAL; - v.v_rows = rows; - } - } - - if (v.v_vcol && v.v_ccol) { - int cols = v.v_vcol / v.v_ccol; - if (v.v_cols != cols) { - if (v.v_cols) - return -EINVAL; - v.v_cols = cols; - } - } - - if (v.v_clin > 32) - return -EINVAL; + if (v.v_vlin) + pr_info_once("\"struct vt_consize\"->v_vlin is ignored. Please report if you need this.\n"); + if (v.v_clin) + pr_info_once("\"struct vt_consize\"->v_clin is ignored. Please report if you need this.\n"); + console_lock(); for (i = 0; i < MAX_NR_CONSOLES; i++) { - struct vc_data *vcp; + vc = vc_cons[i].d; - if (!vc_cons[i].d) - continue; - console_lock(); - vcp = vc_cons[i].d; - if (vcp) { - int ret; - int save_scan_lines = vcp->vc_scan_lines; - int save_font_height = vcp->vc_font.height; - - if (v.v_vlin) - vcp->vc_scan_lines = v.v_vlin; - if (v.v_clin) - vcp->vc_font.height = v.v_clin; - vcp->vc_resize_user = 1; - ret = vc_resize(vcp, v.v_cols, v.v_rows); - if (ret) { - vcp->vc_scan_lines = save_scan_lines; - vcp->vc_font.height = save_font_height; - console_unlock(); - return ret; - } + if (vc) { + vc->vc_resize_user = 1; + vc_resize(vc, v.v_cols, v.v_rows); } - console_unlock(); } + console_unlock(); return 0; } -- 2.25.1