Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp520242ybh; Wed, 15 Jul 2020 08:08:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjak/1+oNsR0cwCi+JSl+9Hc7Cn5iy9pLs5WJcY3C7SgxZSnoSPwloPDnhIRKBN4SXKJr7 X-Received: by 2002:a05:6402:174e:: with SMTP id v14mr53716edx.153.1594825734827; Wed, 15 Jul 2020 08:08:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594825734; cv=none; d=google.com; s=arc-20160816; b=Vio0rg6B4P/mr9FX+O44gUWsPFLAVmDnAdPWhAk/1m4lwPHaXQHcy93cciX4E/Wzyv rnneuD1sCbjtXK4dyuLRnWkLKQZeBk+ahUWdXL74IGs/lYKhKTFib/1ZO89aE8nsGLXW r4qP5IcSCCCCwLHDlRw3LVDixRLV/M0/0wlprYpBssixB3WzE05Eucuz0YWqCp0aoVxd 9PYSIWgkkyqYQRfF7OstwzARnV3SpIjrQVzhTe4AdmILTsuC3UYvMuyUfH8JGac1xcek LVG2PX+6l1zkhUKZI1+jTzYyEg8fvjXp0Q0naRL1i085mB2v4XenEimVyLlyih7exyGh BNDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=ABdF9vA2nkxPkRNK181pGi4v/5aYM1QGi7QHdesXS+o=; b=MNetNErYfuB7Z4GQWA3GUM2Yc9iDRSiZgPut/VbCOSriIEX8PGmq3gdgcCuv+o8/VJ VwxZnH2dSqzs7+QIiQP0TkQfXCJ0L/tV/LYCCM4sXKXtIqXOG05xuF9aXXRIcwGrgK73 rX7L6INBNOTOEMr5URh7jDVXVS/TAnyLF5Qk1rvveR0mpIw78TLu7DFhdPu+iO8GmDMV SmCNCmRoUOElcvbNZpADvyQC35Mm9RAKcflB8iZhKGHsX9tjRQLClR831DY22xCus5cQ IkgY24o6Nl1NSFfOD8gTlu0Gn8hFjnU65x/YSYBWjUGPN9XYKgRLdnOkBX2mMBx27Ith bKzw== 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 a3si1486134ejd.449.2020.07.15.08.08.24; Wed, 15 Jul 2020 08:08:54 -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 S1732020AbgGOODH (ORCPT + 99 others); Wed, 15 Jul 2020 10:03:07 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:58029 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727822AbgGOODH (ORCPT ); Wed, 15 Jul 2020 10:03:07 -0400 Received: from fsav101.sakura.ne.jp (fsav101.sakura.ne.jp [27.133.134.228]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 06FE35Bp056463; Wed, 15 Jul 2020 23:03:05 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav101.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav101.sakura.ne.jp); Wed, 15 Jul 2020 23:03:05 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav101.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 06FE2xxt056225 (version=TLSv1.2 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 15 Jul 2020 23:03:05 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Subject: Re: [PATCH v2] fbdev: Detect integer underflow at "struct fbcon_ops"->clear_margins. From: Tetsuo Handa To: Dan Carpenter Cc: Bartlomiej Zolnierkiewicz , Greg Kroah-Hartman , Jiri Slaby , Dmitry Vyukov , George Kennedy , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot References: <20200715015102.3814-1-penguin-kernel@I-love.SAKURA.ne.jp> <20200715094836.GD2571@kadam> <9e6eac10-c5c3-f518-36cc-9ea32fb5d7fe@i-love.sakura.ne.jp> Message-ID: Date: Wed, 15 Jul 2020 23:02:58 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <9e6eac10-c5c3-f518-36cc-9ea32fb5d7fe@i-love.sakura.ne.jp> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/07/15 20:17, Tetsuo Handa wrote: > On 2020/07/15 18:48, Dan Carpenter wrote: >>> @@ -216,7 +216,7 @@ static void bit_clear_margins(struct vc_data *vc, struct fb_info *info, >>> region.color = color; >>> region.rop = ROP_COPY; >>> >>> - if (rw && !bottom_only) { >>> + if ((int) rw > 0 && !bottom_only) { >>> region.dx = info->var.xoffset + rs; >> ^^^^^^^^^^^^^^^^^^^^^^ >> >> If you choose a very high positive "rw" then this addition can overflow. >> info->var.xoffset comes from the user and I don't think it's checked... > > Well, I think it would be checked by "struct fb_ops"->check_var hook. > For example, vmw_fb_check_var() has > > if ((var->xoffset + var->xres) > par->max_width || > (var->yoffset + var->yres) > par->max_height) { > DRM_ERROR("Requested geom can not fit in framebuffer\n"); > return -EINVAL; > } > > check. Of course, there might be integer overflow in that check... > Having sanity check at caller of "struct fb_ops"->check_var might be nice. > Well, while const int fd = open("/dev/fb0", O_ACCMODE); struct fb_var_screeninfo var = { }; ioctl(fd, FBIOGET_VSCREENINFO, &var); var.xres = var.yres = 4; var.xoffset = 4294967292U; ioctl(fd, FBIOPUT_VSCREENINFO, &var); bypassed (var->xoffset + var->xres) > par->max_width check in vmw_fb_check_var(), ---------- --- a/drivers/video/fbdev/core/bitblit.c +++ b/drivers/video/fbdev/core/bitblit.c @@ -216,6 +216,7 @@ static void bit_clear_margins(struct vc_data *vc, struct fb_info *info, region.color = color; region.rop = ROP_COPY; + printk(KERN_INFO "%s info->var.xoffset=%u rs=%u info->var.yoffset=%u bs=%u\n", __func__, info->var.xoffset, rs, info->var.yoffset, bs); if ((int) rw > 0 && !bottom_only) { region.dx = info->var.xoffset + rs; region.dy = 0; ---------- says that info->var.xoffset does not come from the user. ---------- bit_clear_margins info->var.xoffset=0 rs=1024 info->var.yoffset=0 bs=800 ----------