Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3649878pxb; Mon, 30 Aug 2021 07:27:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWfmX0RnRGggqEVEFOLLhC2RJ5iIVctknCG2kQX67QBIegyn+Y7dnYW4V2TYYVsGqRuuQ+ X-Received: by 2002:a17:906:ff0c:: with SMTP id zn12mr5533133ejb.114.1630333655036; Mon, 30 Aug 2021 07:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630333655; cv=none; d=google.com; s=arc-20160816; b=EtKXEOCcZp71OLweMFHx0cEE5Mx2wwDZuxKENptDpSexg2p8sKZjOxk1txjp/jVWXT /zP/dKtoF8dBJP++sWOBxkgsFMssZ8ZJNQpEGvmHkTd+CJcxMlpJMd7AJq6n2wAxWMX6 dF/7KPbfxDbVJQH8idZoKTWRL0WkJH8ZV7u6NeUtd2/wDB0gQkEiSIkqFK/D9zs545vJ BTpTuPbbpj+5qRyZoIeM9HuwcEkcyarWOJobsHHJ5YmjpMZYYL/T4xC/UINcVmAhoJ44 Z2DtbO3qvwYFwkQk4mG9kXsU42Q72VQ8DIzQitzFlV5W782b88qQG9gs+IMEfRI0DSJw 6X4A== 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=15YXSnUuR4FWZEzGDgBrZlU8U3aN40EXx4gpRKS0MAE=; b=TFHNBk+91YVo8MaDN0xr4Yic2DDhsNvm8BMZZUcwJDL7ShqL08ubCIcjD9DwYdF/UD lYMtf+gS03bWvCMDkezf5BMxZQlu9Rh0bqoD805AHwl0y6EfJyyUDOFn6yhSd73F7F0h eESWJfU+LOSUlN1laqG4C0jwsnXNr9+C/5sPqi/uZufIGsWUOEghRUMU8YJ5lrhQQbq7 bkTplP6NBYKDL9kQqySblTUn4eddTLjGn/Dcyz9DtHdvvjaB6ogRfTi/OfBxMCFt8M/8 hf/ICtrbBEtm3bnduNcn3VHLu5mrot3MD34j6sWTJqXX3H6YVrD82omFD2Yz+1Vc+8/3 SlWg== 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 c12si15389547eja.706.2021.08.30.07.27.11; Mon, 30 Aug 2021 07:27:35 -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 S237484AbhH3O0t (ORCPT + 99 others); Mon, 30 Aug 2021 10:26:49 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:52732 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237220AbhH3O0r (ORCPT ); Mon, 30 Aug 2021 10:26:47 -0400 Received: from fsav117.sakura.ne.jp (fsav117.sakura.ne.jp [27.133.134.244]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 17UEPqjZ076941; Mon, 30 Aug 2021 23:25:52 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav117.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav117.sakura.ne.jp); Mon, 30 Aug 2021 23:25:52 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav117.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 17UEPqK6076922 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Mon, 30 Aug 2021 23:25:52 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Subject: Re: [syzbot] BUG: unable to handle kernel paging request in vga16fb_fillrect To: Dan Carpenter Cc: Geert Uytterhoeven , Randy Dunlap , syzbot , Andrew Morton , Bartlomiej Zolnierkiewicz , Colin King , DRI Development , Linux Fbdev development list , Linux Kernel Mailing List , Masahiro Yamada , syzkaller-bugs@googlegroups.com References: <000000000000815b9605c70e74f8@google.com> <131b24e5-ee31-6f7b-42b4-c34583711913@infradead.org> <2fccb5d3-191c-924e-159f-1c9d423e282f@i-love.sakura.ne.jp> <20210830130000.GW7722@kadam> <8ed0ca59-226b-2d0e-b1ae-82305202558d@i-love.sakura.ne.jp> <20210830134719.GI12231@kadam> From: Tetsuo Handa Message-ID: <03d0f549-9731-8b06-1393-60d4bef27884@i-love.sakura.ne.jp> Date: Mon, 30 Aug 2021 23:25:51 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210830134719.GI12231@kadam> 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 On 2021/08/30 22:47, Dan Carpenter wrote: > On Mon, Aug 30, 2021 at 10:37:31PM +0900, Tetsuo Handa wrote: >> On 2021/08/30 22:00, Dan Carpenter wrote: >>>>> diff --git a/drivers/video/fbdev/vga16fb.c b/drivers/video/fbdev/vga16fb.c >>>>> index e2757ff1c23d..e483a3f5fd47 100644 >>>>> --- a/drivers/video/fbdev/vga16fb.c >>>>> +++ b/drivers/video/fbdev/vga16fb.c >>>>> @@ -403,7 +403,7 @@ static int vga16fb_check_var(struct fb_var_screeninfo *var, >>>>> >>>>> if (yres > vyres) >>>>> vyres = yres; >>>>> - if (vxres * vyres > maxmem) { >>>>> + if ((u64) vxres * vyres > (u64) maxmem) { >>>> >>>> Mindlessly changing the sizes is not the solution. >>>> Please use e.g. the array_size() helper from >>>> instead. >>> >>> On a 64bit system the array_size() macro is going to do the exact same >>> casts? But I do think this code would be easier to understand if the >>> integer overflow check were pull out separately and done first: >>> >>> if (array_size(vxres, vyres) >= UINT_MAX) >>> return -EINVAL; >> >> This is wrong. array_size() returns ULONG_MAX on 64bits upon overflow and >> returns UINT_MAX on 32bits upon overflow. However, UINT_MAX is a valid >> value without overflow (e.g. vxres == UINT_MAX / 15 && vyres == 15). > > Huh... I just assumed we didn't allow resolutions that high. Of course, we don't allow resolutions that high. ;-) Since I don't know possible max resolutions, I chose UINT_MAX + 1 as a common limit for returning -EINVAL. Unless overflow happens, vga16fb_check_var() will return -ENOMEM on such high resolutions. > >> Comparing like "> (u64) UINT_MAX" is to detect only overflow. >> > > Of course, that doesn't work on 32 bit systems. Also the cast isn't > required because of type promotion. Indeed, "> UINT_MAX" seems to work on both 32bits and 64bits. ---------- #include #include int main(int argc, char *argv[]) { unsigned int w = 0x600; unsigned int h = 0x10000000; if ((unsigned long long) w * h > UINT_MAX) printf("Overflowed\n"); else printf("No overflow\n"); return 0; } ----------