Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp854038pxv; Thu, 24 Jun 2021 23:11:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4wWZ8Ipi0CIBtuHtYNuuArgYTDxs5uq/QaFPUW2O6y267P9uKZdiaYQEK+WePZT9CQArZ X-Received: by 2002:a05:6e02:10c2:: with SMTP id s2mr6351369ilj.24.1624601502623; Thu, 24 Jun 2021 23:11:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624601502; cv=none; d=google.com; s=arc-20160816; b=WvT2lhT4IQWc5lvSSR7nzws+i78NnCV8L9AV3Nnfmoe8lyqZ2sKDbNoTGIAiGux4zZ uR19Y782IuxkS4Akc/Ud4PqVw4IGnAjWpoYZe+TBdvWwZaqVvGOt0u6DbO17iaVgUO8W gFm0mjAkbgj6SeJqNBXiJT1v3bosh+/pGTHz3yvZIaxT3eIXfMuWraK85Or4pZpmfJoo m0zmikKwpQap+0Dh7QjRNVYrgjtYq+P0jvrcAnKtffR7ISHEaNTT0Iy24SRXv5GcziAv jCD6xaBvutO1is1ViVOMBUEfaNSt9roVpR5Uw4avRqu5izrDblDbGCbVRdvQ6DhiCa/y LLvg== 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=JxZJNH/ldnqJ3IT7+jiuzqAO/ABMSxBK7lr/weQ/9tY=; b=WX+C23RZdPxJbEjqwkYrhXNoxXPAXZuY70wXKYg3opOaNMjW1MKSOpjiPsQf/UIZFl nxMMK+gfhX82Xu/d8EEzyoq8WvK9/GP5Tu6Yy7K0pZBhzmVStHx4E4ezrkDzmL3TIRU+ sA1nyJzFCApJlzdgfMnbxQpI/kGp0q9NKaWq2w9hsYx4Apx9w368BFHOWplch+SMs+Ku fRrmCipofxLX5aoE1FWAnZpYrSsisJrh8BIF5D9Obmgp4vsXpnMX1zKz+K51HP6uPxb/ n/h3QHdljmRp/sg0ApCmEg9wV2GrMiRn+3qeHtXDVKIsASwVPN8qmZwVVPq0dipQ4TBB U8wg== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u12si5885960iln.143.2021.06.24.23.11.30; Thu, 24 Jun 2021 23:11:42 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230228AbhFYGMQ (ORCPT + 99 others); Fri, 25 Jun 2021 02:12:16 -0400 Received: from mail-wr1-f47.google.com ([209.85.221.47]:39718 "EHLO mail-wr1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230192AbhFYGMP (ORCPT ); Fri, 25 Jun 2021 02:12:15 -0400 Received: by mail-wr1-f47.google.com with SMTP id b3so9268513wrm.6 for ; Thu, 24 Jun 2021 23:09:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=JxZJNH/ldnqJ3IT7+jiuzqAO/ABMSxBK7lr/weQ/9tY=; b=N9DIlmkP8/VtLcQ3bGGM53o644G4W3JiffolOTKJZtDB1HkJ1rBvnwGkDN0Ry2n7iP 6vGELeZgAa+UkJvjjlUNDndEdLPMfS2c8uiJq/xE/4lm2DirYtiefGWlDtWRLjKc3F9A IAilGfaP8Jm1ISRSFFPQw9T3VN46YRgx3LoathtFMQnNnDeUQ92LcUNIVXCSHqpsB0sk rmct9hAni7SBUo5Ls88J31odJM1qQjt/gbMwCR9bBJbn0vOipd3hZgPKQ+o+buBkxj1m 7wExl1sjZu7aP3y05EeGVTLKshkn+bcSYSJX1y0mIhf5IxNe0KO0V/0VKgSUIX7+YR8M zsuQ== X-Gm-Message-State: AOAM532/5cRK9DRfzTN9eorj9EfX70Ifve65dNroADya/5r+yiIawWML 4/S0d/Ur1GkPRbCXPOMmXUE= X-Received: by 2002:a5d:5388:: with SMTP id d8mr8604923wrv.423.1624601394637; Thu, 24 Jun 2021 23:09:54 -0700 (PDT) Received: from ?IPv6:2a0b:e7c0:0:107::49? ([2a0b:e7c0:0:107::49]) by smtp.gmail.com with ESMTPSA id y13sm4974387wmj.18.2021.06.24.23.09.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 23:09:54 -0700 (PDT) Subject: Re: [PATCH v4] tty: Fix out-of-bound vmalloc access in imageblit To: Igor Matheus Andrade Torrente , gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, syzbot+858dc7a2f7ef07c2c219@syzkaller.appspotmail.com References: <20210624202725.20415-1-igormtorrente@gmail.com> From: Jiri Slaby Message-ID: <6d3d27d2-36e2-d95b-98e4-df08dedc34e2@kernel.org> Date: Fri, 25 Jun 2021 08:09:53 +0200 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: <20210624202725.20415-1-igormtorrente@gmail.com> Content-Type: text/plain; charset=iso-8859-2; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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... > + * 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? > > if (new_screen_size > KMALLOC_MAX_SIZE || !new_screen_size) > return -EINVAL; > -- js suse labs