Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp494058ybi; Fri, 7 Jun 2019 11:25:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqyT3tkrTkLjlK74dIRdfGxb0wuOnRTppHiaLuTMqSRUp/FJG+DMXgGqvgKojXN6NjVlBkOX X-Received: by 2002:a65:51c7:: with SMTP id i7mr4318236pgq.211.1559931929693; Fri, 07 Jun 2019 11:25:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559931929; cv=none; d=google.com; s=arc-20160816; b=o7BCiEE14j6ZKTQC5Z4sj1v8mXBz42e7y4xqzoInopLuOg3goSO9tMvh0Gwb9hsLzJ u8QGnLLJTXHuoKbiWBWGATs2Juk7PViAolF1i9pjkLYPSNzBNQ53dUC/A/xziQa3DS1X BEcb+0Qwu8f/59b8c0oPFHa+A0Pbtb3SAGXeF4Of6enJXAufoAt7FY+pJbo31bGGWrWz zvMPYvQxdohdgSYtMDE7hixo5yP2WJOSIU2PRckLsSM3QMWERg182H733hBQJKYsZlG1 GR6rFCh+x+L2SQk8Qzfj7xFDbDBvqoLf9wb221eA1uGE80QWYXIiy0MaFPdsyKfhe3QR fIdQ== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0JHbSsZtN5Op0GOZ1KCTls2le+87+2Ej7ygWhICOej0=; b=f3/itQsURrZcPhaqUo6iY0xhVWF/6tWcAZtp0lTJ3GYUQZ8GzTsx7A1VosmnT54kqS NBYBBgnWfgE0N26plaVDWL3Nz2oZxEUrU+HjM300BCOEkD8inC4vsiYHZ7ZYkf0tN4Bi qRoPIiH0HymlISnpxTo7H6SLrQQ3EmeDr1AHC2m8l2QEQIfdq3a33FsxiV5NZWGHUIeE Kt/QmeNrTrvhcrUkKDRIXNyEGnSf4jjKeKhjlObGff0Ydq324S4fiys/ii/fCMIGhfUS v3yYdjIpLM3qjAOfIB9weTFOU3G+0zcc6JilNH/21pjbBEeDejHuMVL8wGtpPMm9XbkP PmRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vogjOTqm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q203si2579049pgq.384.2019.06.07.11.25.12; Fri, 07 Jun 2019 11:25:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vogjOTqm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729710AbfFGPvH (ORCPT + 99 others); Fri, 7 Jun 2019 11:51:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:38354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732274AbfFGPvE (ORCPT ); Fri, 7 Jun 2019 11:51:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B65A2146E; Fri, 7 Jun 2019 15:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559922663; bh=xOFzgDzIJd+HZd+bR7YkJZ9x9WUvI8zhPy1SBcGADjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vogjOTqmgVa/8nhVBuUATRdQNtGxhMTDvNkM7qzrgJY0tKyuH+dcAK/lPVTwBmEQ1 /JCqjyoXmtNjm3rsQLV8VCVypUOEqjwQtrDYN83ko72alj295yLF5vuhzyho5vi0pG pOV3/wBn0nMyk8FqvjsWeHN0YXLKnTQwnH9Ea6UE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Grzegorz Halat , Oleksandr Natalenko , Bartlomiej Zolnierkiewicz Subject: [PATCH 5.1 63/85] vt/fbcon: deinitialize resources in visual_init() after failed memory allocation Date: Fri, 7 Jun 2019 17:39:48 +0200 Message-Id: <20190607153856.346128456@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190607153849.101321647@linuxfoundation.org> References: <20190607153849.101321647@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Grzegorz Halat commit a1ad1cc9704f64c169261a76e1aee1cf1ae51832 upstream. After memory allocation failure vc_allocate() doesn't clean up data which has been initialized in visual_init(). In case of fbcon this leads to divide-by-0 in fbcon_init() on next open of the same tty. memory allocation in vc_allocate() may fail here: 1097: vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_KERNEL); on next open() fbcon_init() skips vc_font.data initialization: 1088: if (!p->fontdata) { division by zero in fbcon_init() happens here: 1149: new_cols /= vc->vc_font.width; Additional check is needed in fbcon_deinit() to prevent usage of uninitialized vc_screenbuf: 1251: if (vc->vc_hi_font_mask && vc->vc_screenbuf) 1252: set_vc_hi_font(vc, false); Crash: #6 [ffffc90001eafa60] divide_error at ffffffff81a00be4 [exception RIP: fbcon_init+463] RIP: ffffffff814b860f RSP: ffffc90001eafb18 RFLAGS: 00010246 ... #7 [ffffc90001eafb60] visual_init at ffffffff8154c36e #8 [ffffc90001eafb80] vc_allocate at ffffffff8154f53c #9 [ffffc90001eafbc8] con_install at ffffffff8154f624 ... Signed-off-by: Grzegorz Halat Reviewed-by: Oleksandr Natalenko Acked-by: Bartlomiej Zolnierkiewicz Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/tty/vt/vt.c | 11 +++++++++-- drivers/video/fbdev/core/fbcon.c | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -1056,6 +1056,13 @@ static void visual_init(struct vc_data * vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row; } + +static void visual_deinit(struct vc_data *vc) +{ + vc->vc_sw->con_deinit(vc); + module_put(vc->vc_sw->owner); +} + int vc_allocate(unsigned int currcons) /* return 0 on success */ { struct vt_notifier_param param; @@ -1103,6 +1110,7 @@ int vc_allocate(unsigned int currcons) / return 0; err_free: + visual_deinit(vc); kfree(vc); vc_cons[currcons].d = NULL; return -ENOMEM; @@ -1331,9 +1339,8 @@ struct vc_data *vc_deallocate(unsigned i param.vc = vc = vc_cons[currcons].d; atomic_notifier_call_chain(&vt_notifier_list, VT_DEALLOCATE, ¶m); vcs_remove_sysfs(currcons); - vc->vc_sw->con_deinit(vc); + visual_deinit(vc); put_pid(vc->vt_pid); - module_put(vc->vc_sw->owner); vc_uniscr_set(vc, NULL); kfree(vc->vc_screenbuf); vc_cons[currcons].d = NULL; --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -1248,7 +1248,7 @@ finished: if (free_font) vc->vc_font.data = NULL; - if (vc->vc_hi_font_mask) + if (vc->vc_hi_font_mask && vc->vc_screenbuf) set_vc_hi_font(vc, false); if (!con_is_bound(&fb_con))