Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1482505pxv; Fri, 25 Jun 2021 14:11:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfjNPzuExV0Bpt+dVxscN2DPUOnqJPVaPgUwDQ86RRNQ6PY0dibvS+9Chjxzm6V5alx4Wj X-Received: by 2002:a02:908a:: with SMTP id x10mr10923411jaf.30.1624655507681; Fri, 25 Jun 2021 14:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624655507; cv=none; d=google.com; s=arc-20160816; b=sBhm+7KRVRpUSbr24BZgwx2tHEGUsOvI4UJZIUjyqAXMgfzLQKaMtT6nATSjd0wwvw TZAFREv9/UvEnxaPdztcWDdVaoxCHpgcZf81+LStBkwQPVSLCWHWw1ze6Eq0Y8idNvKK T2r/QkbvHOuiWLT99qxuOHtUuKLtyP3iasecwZz0QTa7JbDIxEbuCh/G2SE9eDmH/tiO 9A7a0fQ62Dgkznyk3KVo0Ce8jV9kq+zQDbocf049txXkYHRnrPfmybGOEklJev3ijndG Ucix0L3aNJZTbbyY0hbABdaV2sVzbV7DFmoqNBVE4NYS0JR5v4l//qjoy22sNUmzZ9Nn uTEQ== 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:references:cc :to:subject:from:dkim-signature; bh=GHJEjaQr0KmEeIyROSH4ZXM2rKTKH4pwJGeBqIbXJ6o=; b=ktSqWe63NsVLk6KhDo+pJSVrdFjfQFOeRplLnpshH5BPoS0IW3gvbM+LFUx5yzHdds Qbqn1V1DiIN5oz7lWEzE2XW+u+Er/R7f/m2zZcJuOmaQkjBPq7VhwozT2y8aHASYJV52 DKUjqOCrUBZTwOuHn7emX8AUL7+M36IhGUx3lnxlWw7/tW0aWxifkRIRbUoIol41p0tq ujHL6gvw9JZs/FhkQSiquNGb5hb3d4CGuxN7UeFK9QxpxUOCvcU706wxIwbvf6MFpMMj LkeT9jsCvlS7qRcqLKUz0BqbXJilFZK3AABsg6hb0ZbXLPGMeuT5ZYWckLSMFVEVqakm OKQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f3kFHqIi; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h23si6228850ila.82.2021.06.25.14.11.35; Fri, 25 Jun 2021 14:11:47 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f3kFHqIi; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbhFYVMJ (ORCPT + 99 others); Fri, 25 Jun 2021 17:12:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbhFYVMI (ORCPT ); Fri, 25 Jun 2021 17:12:08 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB78BC061574 for ; Fri, 25 Jun 2021 14:09:45 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id g3so4250715qth.11 for ; Fri, 25 Jun 2021 14:09:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=GHJEjaQr0KmEeIyROSH4ZXM2rKTKH4pwJGeBqIbXJ6o=; b=f3kFHqIiYcQI0wbq8uSmoaDYjt0SQKkom9h5Z34Fqon3fVl+H5e3G6eMV77z+rCo9+ 3z0AQKYxHzj3aEuV0NeMxfwwml0rRT9mVelUD8IvQWkK5IXYd6CFqNtEScTgqj1h7jRd qgklPjp9tCbt9kJUFmCJoP8ZV0EopQ10WVxsFTB4fbJpyAlchBVOUynr6L4fFmMbhFgv MEPAaM7DwOVzqX546Alikb+om87HqRqBWcPLdlh9jAB9SRms9sOZqShn225WELlJP5OV YM6y8Sd6owshXzAMMarxTTqu0nvABO7YpWmCpUCCtvIJIldlMeEyx3FolUN9+2FIvHke QyTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=GHJEjaQr0KmEeIyROSH4ZXM2rKTKH4pwJGeBqIbXJ6o=; b=dD8x/NlGF2+wxsu3LEI4BB+HmS1RA8UwkXx9r1V9CnvI/OkrgFW+85L8Lnzm3dA5Zi MQ+BZgjAusizO+IoLCQYs20HsvQAwHIz3PQurexl+VAid88VBJxj3mjUXw/RA+ByBfqK orTJUfk5cK01MUdDZ7hBsrAGdkUR0kWv+PkEJiW7WnkVRsIGaG50u/VtuISXJNZsEO2C heHUtiGrsk26Y04JscZNcikjA+uFJfYtneRZ0VxQgIog4VZ9ksTp5SnwpUSa3v3cVAJo ni6/CFyKLNcy485yp6/kkeKV+4eni2k2wPMzx+B1E9uX4iajlLorKmgJnxEu0aFreIJb zKdQ== X-Gm-Message-State: AOAM531BR4aO139Y9d4q4Et2sazKAbVNCSjGJYRwHeeYdBPwbvxXsY4h eUuYvEmM5a8fuAlTkTHflI8= X-Received: by 2002:ac8:7b53:: with SMTP id m19mr11304797qtu.349.1624655385151; Fri, 25 Jun 2021 14:09:45 -0700 (PDT) Received: from ?IPv6:2804:14c:125:811b:fbbc:3360:40c4:fb64? ([2804:14c:125:811b:fbbc:3360:40c4:fb64]) by smtp.gmail.com with ESMTPSA id w22sm4396929qta.55.2021.06.25.14.09.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Jun 2021 14:09:44 -0700 (PDT) From: Igor Torrente Subject: Re: [PATCH v4] tty: Fix out-of-bound vmalloc access in imageblit To: Jiri Slaby , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, syzbot References: <20210624202725.20415-1-igormtorrente@gmail.com> <6d3d27d2-36e2-d95b-98e4-df08dedc34e2@kernel.org> Message-ID: Date: Fri, 25 Jun 2021 18:09:41 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <6d3d27d2-36e2-d95b-98e4-df08dedc34e2@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/25/21 3:09 AM, Jiri Slaby wrote: > On 24. 06. 21, 22:27, Igor Matheus Andrade Torrente wrote: >> This issue happens when a userspace program does an ioctl >> FBIOPUT_VSCREENINFO passing the fb_var_screeninfo struct >> containing only the fields xres, yres, and bits_per_pixel >> with values. >> >> If this struct is the same as the previous ioctl, the >> vc_resize() detects it and doesn't call the resize_screen(), >> leaving the fb_var_screeninfo incomplete. And this leads to >> the updatescrollmode() calculates a wrong value to >> fbcon_display->vrows, which makes the real_y() return a >> wrong value of y, and that value, eventually, causes >> the imageblit to access an out-of-bound address value. >> >> To solve this issue I made the resize_screen() be called >> even if the screen does not need any resizing, so it will >> "fix and fill" the fb_var_screeninfo independently. >> >> Reported-and-tested-by: >> syzbot+858dc7a2f7ef07c2c219@syzkaller.appspotmail.com >> Signed-off-by: Igor Matheus Andrade Torrente >> --- >> drivers/tty/vt/vt.c | 17 ++++++++++++++++- >> 1 file changed, 16 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c >> index fa1548d4f94b..e342f5c905bc 100644 >> --- a/drivers/tty/vt/vt.c >> +++ b/drivers/tty/vt/vt.c >> @@ -1220,7 +1220,22 @@ static int vc_do_resize(struct tty_struct *tty, >> struct vc_data *vc, >> new_screen_size = new_row_size * new_rows; >> if (new_cols == vc->vc_cols && new_rows == vc->vc_rows) >> - return 0; >> + /* This function is being called here to cover the case > > This was already commented on v3: > > Please do not use networking style comments, use normal ones: > /* > * This function... > I don't know how, but I didn't see this comment in the original email. I will change it. > >> + * where the userspace calls the FBIOPUT_VSCREENINFO twice, >> + * passing the same fb_var_screeninfo containing the fields: >> + * yres/xres equal to a number non-multiple of vc_font.height >> + * and yres_virtual/xres_virtual equal to number lesser than the >> + * vc_font.height and yres/xres. >> + * In the second call, the struct fb_var_screeninfo isn't >> + * being modified by the underlying driver because of the >> + * if above, and this causes the fbcon_display->vrows to become >> + * negative and it eventually leads to out-of-bound >> + * access by the imageblit function. >> + * To give the correct values to the struct and to not have >> + * to deal with possible errors from the code below, we call >> + * the resize_screen here as well. >> + */ >> + return resize_screen(vc, new_cols, new_rows, user); > > I suppose you need to add { } after the if given how its body grew. > > With what all console drivers have you tested this with? fbcon > >> if (new_screen_size > KMALLOC_MAX_SIZE || !new_screen_size) >> return -EINVAL; >> > > Thanks, Igor M. A. Torrente