Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp987960imn; Sat, 30 Jul 2022 10:38:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR78A5F1mNlKDyWsKwJq77++rtm+a/xqJzwhb7RGe+Qz573Cudte+H/W1qV8GAXSlBzwJtlp X-Received: by 2002:a17:902:ec90:b0:16d:d156:2c01 with SMTP id x16-20020a170902ec9000b0016dd1562c01mr9234724plg.114.1659202734944; Sat, 30 Jul 2022 10:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659202734; cv=none; d=google.com; s=arc-20160816; b=YW6YKtLSixUplZSuQ4QyTqJxiAJKB1JsI6urCbPQw0RMxVpxhvEToe+8RilUPBU9I5 6X9aacP1hRS6EaMsCxbocqjQzgtCrNsfgkBE6A4tt00DKygWKh+JrgFHushc7fCgJLEB wCINuMiyFg2lI/d97ZPVUQvKwcjIcpf3kmnIXmx39q3i2AkrVQ9TaooizI237OqKrarh H3qB5SkeruYo1uncsVQIO2NVwVF6xiJRIWoqkEjLu3xHpIz5KI2MDPWeA7ZbXTj0k+38 tU0p15oIVc+7qWScEw9a9HNAuD3BcUWvjYy/WTdZ3nx8WRuIfLJQSpQGy4VQUMSaGgPJ /vAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=pVXPC+HvaaizufALDJQvFhWuOS/U35TXeCh4ULLGVQs=; b=DsXdmifcNrO1S0ThyNaiLSnldEr+Joms3d9z2hgxZEcXTY1cPLOmxWqnsTVDxoTt+t uw9VExkg9p/CQWh5N02E1fYGu+D0PQjynHdIu8EIUM6jgLkwylcyl2F3bOLYSV5kC47v 5U4p8FojCrz9Ldhe4tYqKLMv/VAQbw4H+BtG/hz8S3IrmwVWRcHtOr7IEt0hZAuRH7jY 5eVkhb0J0LoZ4Omw4AZShbX7E5qUvgZVGFRzL+DGL958YY/tObGfatRadrG8EP1AbWgk WmXWeCtJnJg/Xtk2IrlNo7kGvTstTBu9Q/ynn7EdpLrV8Cv+Fm2rTwAaO6t5ToXo7dv2 4Kbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=jFgm+bEd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a639344000000b00415965ff537si7664735pgm.38.2022.07.30.10.38.38; Sat, 30 Jul 2022 10:38:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=jFgm+bEd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233791AbiG3R04 (ORCPT + 99 others); Sat, 30 Jul 2022 13:26:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234778AbiG3R0z (ORCPT ); Sat, 30 Jul 2022 13:26:55 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CAE26576; Sat, 30 Jul 2022 10:26:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659202000; bh=NHO94zdmagMHUsaDXQDJxauKZL4m2T37y8DaXk+oiBc=; h=X-UI-Sender-Class:Date:To:References:From:Subject:In-Reply-To; b=jFgm+bEdqMuhl1Zs4lJl96dRyYIWLgx8CrqS5eLJz2HK0s9qX6lIbxcinXUIWEqIR 1py8f8ma80kYmdqKFDYB0Z/WD4cN8mkE707PLR2o7+xLXItZoi7lxYgGIH5Lt31IMI ohJQuq1cvd1pxgbTiFqqTkQCnFFs00Wusdz6lr4o= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.20.60] ([92.116.141.10]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MryT9-1nczZt1jbJ-00nx62; Sat, 30 Jul 2022 19:26:40 +0200 Message-ID: Date: Sat, 30 Jul 2022 19:25:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Khalid Masum , syzbot , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Greg Kroah-Hartman , Jiri Slaby References: <000000000000bbdd0405d120c155@google.com> <20220729065139.6529-1-khalid.masum.92@gmail.com> From: Helge Deller Subject: Re: [syzbot] KASAN: vmalloc-out-of-bounds Write in imageblit (2) In-Reply-To: <20220729065139.6529-1-khalid.masum.92@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:HGCv5+J9ExWMCvImsXbvpBDgH9cpBuokI7iRcT+dOsw/ko38cY9 SauhNpWSWmZzKrt5xX6ITQ6sb6lWTkFiwQkvO+yzGOoyFWlfWy5XlbDyvOeWq3nRlFjpdhC ESNk6veDYuTCjd9wePfrPwAswVRaA/seIpRF4xZ9WqT1fmWSQNO4t/7TcxhDz534AcuoNsU 3BCm6PoXilYYBfZBeBmcA== X-UI-Out-Filter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uRw9Zonbaue4ed0fzvQ4hNzDOl fbHMdkjqfolBATOcmK8anKplX3YKSGHooQ0oXSLA1I8mmHf6T7fuliI5zisbaWInhKfxvLziZ +B9ED5iiXFCSfP53TMra3nbk2xR+0QnpMsnioh/G1h8AAk8LtG+pKuZ+A== X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/29/22 08:51, Khalid Masum wrote: > Here is a simplified reproducer for the issue: > > https://gist.githubusercontent.com/Labnann/923d6b9b3a19848fc129637b839b8= a55/raw/a68271fcc724569735fe27f80817e561b3ff629a/reproducer.c The reproducer does this: ioctl(3, TIOCLINUX, TIOCL_SETSEL, selection: xs:3 ys:0 xe:0 ye:0 mode:0)= =3D 0 -> sets the text selection area ioctl(4, KDFONTOP) with op=3D0 (con_font_set), charcount=3D512 width=3D8= height=3D32, 0x20000000) =3D 0 -> changes the font size. It does not crash with current Linus' head (v5.19-rc8). Kernel v5.16, which was used by this KASAN report, hasn't received backpor= ts since months, so I tried stable kernel v5.15.58 instead, and this kernel crashed with the reproducer. The reproducer brings up two issues with current code: 1. The reproducer uses ioctl(TIOCLINUX, TIOCL_SETSEL) and hands over (inva= lid) zero-values for ys and ye for the starting lines. This is wrong, since the API seems to expect a "1" as the very first line = for the selection. This can be easily fixed by adding checks for zero-values and return -EINV= AL if found. But this bug isn't critical itself and is not the reason for the kernel cr= ash. Without the checks, the ioctl handler simply wraps the coordinate values a= nd converts them from: input selection: xs:3 ys:0 xe:0 ye:0 mode:0 to the new: vc_selection =3D xs:2 ys:23 xe:127 ye:23 mode:0 which is the current maximum coordinates for the screen. Those higher values now trigger issue #2: After the TIOCL_SETSEL the last line on the screen is now selected. The KD= FONTOP ioctl then sets a 8x32 console font, and replaces the former 8x16 console font. With the bigger font the current screen selection is now outside the visib= le screen and this finally triggeres this backtrace, because vc_do_resize() calls cl= ear_selection() to unhighlight the selection (which starts to render chars outside of the = screen): drm_fb_helper_sys_imageblit drivers/gpu/drm/drm_fb_helper.c:794 [inline] drm_fbdev_fb_imageblit+0x15c/0x350 drivers/gpu/drm/drm_fb_helper.c:2288 bit_putcs_unaligned drivers/video/fbdev/core/bitblit.c:124 [inline] bit_putcs+0x6e1/0xd20 drivers/video/fbdev/core/bitblit.c:173 fbcon_putcs+0x353/0x440 drivers/video/fbdev/core/fbcon.c:1277 do_update_region+0x399/0x630 drivers/tty/vt/vt.c:676 invert_screen+0x1d4/0x600 drivers/tty/vt/vt.c:800 highlight drivers/tty/vt/selection.c:57 [inline] clear_selection drivers/tty/vt/selection.c:84 [inline] clear_selection+0x55/0x70 drivers/tty/vt/selection.c:80 vc_do_resize+0xe6e/0x1180 drivers/tty/vt/vt.c:1257 IMHO the easiest way to prevent this crash is to simply clear the selection before the various con_font_set() console handlers are called. Otherwise every console driver needs to add checks and verify if the curre= nt selection still fits with the selected font, which gets tricky because som= e of those drivers fiddle with the screen width&height before calling vc_do_= resize(). I'll follow up to this mail with patches for both issues shortly. Helge