From patchwork Mon Jul 19 14:49:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 479999 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4270242jao; Mon, 19 Jul 2021 09:10:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgn0wGZiVO/34ivCNIuq9iDsPLMjCKwStj1qtVTWW2GXgJK7Olz7W8+IW9fDeTdWnkygLs X-Received: by 2002:a5d:6986:: with SMTP id g6mr30238332wru.321.1626711048500; Mon, 19 Jul 2021 09:10:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626711048; cv=none; d=google.com; s=arc-20160816; b=lDG+U8hI4VzuByX+j+V2Jri7YAOq8XF2Azm8Czm2IDW/4HWcV+72IuRG4TAFmg0XiK VjXvzwTVDLcQuRmE/DyKrfoGOjEG/GP/OLLd7Medbblhs5wBJtFy7Zz+vBGvrNcPZ1nR KeDnH/rLEW5yRvTKnYQVK2IjSQtXp9JUxLk0RUWUP/ClRaR2k/ssb05iEGGj/smNu6Gr q7TIqcAyA5FFNugIeNJfTdCtveC6gkmXReYJ3HP5iBmGI2ybJbWl6YLoPiWpKVJm6ZWS 769kSGF5rN1fiMXNVRgYOw+nOczpivtszFXCDacrNUnzJqArnvBgRUikMONfeqCopJvy +s1A== 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=97UEc/mCT45/SNTqjnXO43/nsZqZI5g6BXq4EfZhWAg=; b=XEAvxtabgNW2oHFr7ZkfR1+tLo9wHyeDHY+eFmoXPa54iqAi3RXjM6o1vjt9b7QPv4 3q7Z6QmwzJoeqrOFcthBYfnrXeS7yLf9/rjJaueuYQY5feREQyTdtAqA8SLE4v0B5XFn UdHyV8bukruZPA2aXwoDBZ5g0DXaAM69NpcQDt2RDbmLZrqpuZf2Dp94+k97Ty/5okV4 rmGRvalFAwpVbf/B7jx5GpPWrhCKdv4ZBVk3WnyKdBclOD9A5IfbcPMbt+sToR2aBEi3 btBISnWBwjsn6C3NlKlpt2cCkFLbBRFNnmV1E56AhCqHpOq6I8lv2W/aSBk962hhW3Va EFIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1fFXwQqd; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id la14si22045543ejc.142.2021.07.19.09.10.48; Mon, 19 Jul 2021 09:10:48 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1fFXwQqd; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S1347798AbhGSP1u (ORCPT + 12 others); Mon, 19 Jul 2021 11:27:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:40022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348310AbhGSPYm (ORCPT ); Mon, 19 Jul 2021 11:24:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CF6B261469; Mon, 19 Jul 2021 16:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626710647; bh=s8qxXTQl66UCi8CW5gBxbUGTEfvj080RXKdnY+bWkSg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1fFXwQqdF5JEq2zOiVYgMdrOjXN8MSA7n/QXf55ue66f/FEAGMN72o3spKbvENlKN Z3TxoVjFbXZhQh2wy/HJ6s0yLccqOf5p162xhtRlAUnXhbw3PHGR65hAHBcdPCyB+G E4IECLsO96/hya923L8IaIgzbDIsemr7l++DT4XU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhen Lei , Daniel Vetter Subject: [PATCH 5.13 023/351] fbmem: Do not delete the mode that is still in use Date: Mon, 19 Jul 2021 16:49:29 +0200 Message-Id: <20210719144945.295570145@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144944.537151528@linuxfoundation.org> References: <20210719144944.537151528@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Zhen Lei commit 0af778269a522c988ef0b4188556aba97fb420cc upstream. The execution of fb_delete_videomode() is not based on the result of the previous fbcon_mode_deleted(). As a result, the mode is directly deleted, regardless of whether it is still in use, which may cause UAF. ================================================================== BUG: KASAN: use-after-free in fb_mode_is_equal+0x36e/0x5e0 \ drivers/video/fbdev/core/modedb.c:924 Read of size 4 at addr ffff88807e0ddb1c by task syz-executor.0/18962 CPU: 2 PID: 18962 Comm: syz-executor.0 Not tainted 5.10.45-rc1+ #3 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ... Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x137/0x1be lib/dump_stack.c:118 print_address_description+0x6c/0x640 mm/kasan/report.c:385 __kasan_report mm/kasan/report.c:545 [inline] kasan_report+0x13d/0x1e0 mm/kasan/report.c:562 fb_mode_is_equal+0x36e/0x5e0 drivers/video/fbdev/core/modedb.c:924 fbcon_mode_deleted+0x16a/0x220 drivers/video/fbdev/core/fbcon.c:2746 fb_set_var+0x1e1/0xdb0 drivers/video/fbdev/core/fbmem.c:975 do_fb_ioctl+0x4d9/0x6e0 drivers/video/fbdev/core/fbmem.c:1108 vfs_ioctl fs/ioctl.c:48 [inline] __do_sys_ioctl fs/ioctl.c:753 [inline] __se_sys_ioctl+0xfb/0x170 fs/ioctl.c:739 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Freed by task 18960: kasan_save_stack mm/kasan/common.c:48 [inline] kasan_set_track+0x3d/0x70 mm/kasan/common.c:56 kasan_set_free_info+0x17/0x30 mm/kasan/generic.c:355 __kasan_slab_free+0x108/0x140 mm/kasan/common.c:422 slab_free_hook mm/slub.c:1541 [inline] slab_free_freelist_hook+0xd6/0x1a0 mm/slub.c:1574 slab_free mm/slub.c:3139 [inline] kfree+0xca/0x3d0 mm/slub.c:4121 fb_delete_videomode+0x56a/0x820 drivers/video/fbdev/core/modedb.c:1104 fb_set_var+0x1f3/0xdb0 drivers/video/fbdev/core/fbmem.c:978 do_fb_ioctl+0x4d9/0x6e0 drivers/video/fbdev/core/fbmem.c:1108 vfs_ioctl fs/ioctl.c:48 [inline] __do_sys_ioctl fs/ioctl.c:753 [inline] __se_sys_ioctl+0xfb/0x170 fs/ioctl.c:739 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Fixes: 13ff178ccd6d ("fbcon: Call fbcon_mode_deleted/new_modelist directly") Signed-off-by: Zhen Lei Cc: # v5.3+ Signed-off-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/20210712085544.2828-1-thunder.leizhen@huawei.com Signed-off-by: Greg Kroah-Hartman --- drivers/video/fbdev/core/fbmem.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -970,13 +970,11 @@ fb_set_var(struct fb_info *info, struct fb_var_to_videomode(&mode2, &info->var); /* make sure we don't delete the videomode of current var */ ret = fb_mode_is_equal(&mode1, &mode2); - - if (!ret) - fbcon_mode_deleted(info, &mode1); - - if (!ret) - fb_delete_videomode(&mode1, &info->modelist); - + if (!ret) { + ret = fbcon_mode_deleted(info, &mode1); + if (!ret) + fb_delete_videomode(&mode1, &info->modelist); + } return ret ? -EINVAL : 0; }