Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3074531rwe; Mon, 29 Aug 2022 05:31:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR5dEioFbtPgYesVlMDs/YyuDFkFk57Ubyx7qc53dHVzk+gI3Epo6BITOPrhGZISVX6sD+XN X-Received: by 2002:a17:902:ce81:b0:172:9ac1:6ee with SMTP id f1-20020a170902ce8100b001729ac106eemr15955189plg.93.1661776289407; Mon, 29 Aug 2022 05:31:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661776289; cv=none; d=google.com; s=arc-20160816; b=x5uqlltvsWdm3go18lVpYmMFrPv0ZR9eEyQjPsF1dQUhs1vzWbfu7/O4/+ZyWIPPDE /Hl2JstqXQ1Pl0x6k/0zRYbr0T7ftX683u0yRKtmDbAK1tawPWLEud/7GKiH9hHE0Xi9 2SKvz4FEODDTwJW1xYCKUc99/+l3Jh1ewL3O94PK3n/uqvWafk7hkzCvkTR+b1YFv4xP RP7s1B2TyZkdS1Qrz+aYLX8rfeeAtF2NaGH42ESEjHecW/dBQCG0ozV9t31zB8utVLG4 5zgLmE9e24I8L96GtvZ/DhubeTq1abjyYohxDl0vWW2da05ijfWMGB0Py5zSlSFtbsor 8Qmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+uhkKH+U3Ci9Mn5uZ5oemzojniN42vG8HDIjrogeLtQ=; b=IDFH3IcA36sIwEVFfW6PHh2pnmFfwBxBT9LjbU5Y2VgcCMeQXNpWZljEGjVu/tKiWF 22y/QmTd8ligjG9IXnwtxqGV/eAh0uKhQ5SGVSEdDk3LvZVcWFBFIW1QowpQwbH4ZwsR oEEfv1TNCd5P8Ay7mGn6mTzv4AY3wgntHSu9fGb7bqaHh10PVBJqa8B3xiOcHuZCO3Vg MgvYeJ05J//oVob7ePigc3yQAuP5C3IJfslUPM7QrUzMnNDPt4NqS/fQKTPKuWp2UyET tBxPmtb7VvxbAGZzbupGXVadcKhHD0eqoGhBQzWeGukAtF0WbTYzrgWtDMDBltYIOnaX b/Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="A/F2z5j9"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u13-20020a63234d000000b0042a0dab10aasi8959865pgm.482.2022.08.29.05.31.17; Mon, 29 Aug 2022 05:31:29 -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=@linuxfoundation.org header.s=korg header.b="A/F2z5j9"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232728AbiH2LfK (ORCPT + 99 others); Mon, 29 Aug 2022 07:35:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232823AbiH2LeB (ORCPT ); Mon, 29 Aug 2022 07:34:01 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 790EC7CA8C; Mon, 29 Aug 2022 04:19:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3E613B80E4C; Mon, 29 Aug 2022 11:19:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DC2CC433D6; Mon, 29 Aug 2022 11:19:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771961; bh=QXzMtzimhRYt8XWF/LVdnFlStaAGw59NdLQPfaF4lB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A/F2z5j910CaZcxMB/L4oqmp0jnVl8N9JeAAAKCmxNplm5RZhD2Fn1tqM+lae8I3A 5MXDVqRjC8Q/jXMwq8mVIlQV4+SZjum1Lx7hqliDX39G5V368tm7hmXZ2j1239wqzB JQusUXakfnebjOrY0RFQ5Mg+GcfWLF14rC2kTb74= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+a168dbeaaa7778273c1b@syzkaller.appspotmail.com, Shigeru Yoshida , Helge Deller Subject: [PATCH 5.19 121/158] fbdev: fbcon: Properly revert changes when vc_resize() failed Date: Mon, 29 Aug 2022 12:59:31 +0200 Message-Id: <20220829105814.184053079@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Shigeru Yoshida commit a5a923038d70d2d4a86cb4e3f32625a5ee6e7e24 upstream. fbcon_do_set_font() calls vc_resize() when font size is changed. However, if if vc_resize() failed, current implementation doesn't revert changes for font size, and this causes inconsistent state. syzbot reported unable to handle page fault due to this issue [1]. syzbot's repro uses fault injection which cause failure for memory allocation, so vc_resize() failed. This patch fixes this issue by properly revert changes for font related date when vc_resize() failed. Link: https://syzkaller.appspot.com/bug?id=3443d3a1fa6d964dd7310a0cb1696d165a3e07c4 [1] Reported-by: syzbot+a168dbeaaa7778273c1b@syzkaller.appspotmail.com Signed-off-by: Shigeru Yoshida Signed-off-by: Helge Deller CC: stable@vger.kernel.org # 5.15+ Signed-off-by: Greg Kroah-Hartman --- drivers/video/fbdev/core/fbcon.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -2402,15 +2402,21 @@ static int fbcon_do_set_font(struct vc_d struct fb_info *info = fbcon_info_from_console(vc->vc_num); struct fbcon_ops *ops = info->fbcon_par; struct fbcon_display *p = &fb_display[vc->vc_num]; - int resize; + int resize, ret, old_userfont, old_width, old_height, old_charcount; char *old_data = NULL; resize = (w != vc->vc_font.width) || (h != vc->vc_font.height); if (p->userfont) old_data = vc->vc_font.data; vc->vc_font.data = (void *)(p->fontdata = data); + old_userfont = p->userfont; if ((p->userfont = userfont)) REFCOUNT(data)++; + + old_width = vc->vc_font.width; + old_height = vc->vc_font.height; + old_charcount = vc->vc_font.charcount; + vc->vc_font.width = w; vc->vc_font.height = h; vc->vc_font.charcount = charcount; @@ -2426,7 +2432,9 @@ static int fbcon_do_set_font(struct vc_d rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); cols /= w; rows /= h; - vc_resize(vc, cols, rows); + ret = vc_resize(vc, cols, rows); + if (ret) + goto err_out; } else if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) { fbcon_clear_margins(vc, 0); @@ -2436,6 +2444,21 @@ static int fbcon_do_set_font(struct vc_d if (old_data && (--REFCOUNT(old_data) == 0)) kfree(old_data - FONT_EXTRA_WORDS * sizeof(int)); return 0; + +err_out: + p->fontdata = old_data; + vc->vc_font.data = (void *)old_data; + + if (userfont) { + p->userfont = old_userfont; + REFCOUNT(data)--; + } + + vc->vc_font.width = old_width; + vc->vc_font.height = old_height; + vc->vc_font.charcount = old_charcount; + + return ret; } /*