Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3096639ybi; Thu, 18 Jul 2019 20:58:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwLYBLH37XrOviOnPa5T+MEc8hKy3nA6upIg5/GBVXQSSDfQbs0uYFpha89NnDonPO0r6qh X-Received: by 2002:a17:902:b48c:: with SMTP id y12mr20125320plr.202.1563508695062; Thu, 18 Jul 2019 20:58:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563508695; cv=none; d=google.com; s=arc-20160816; b=ZHEM/c+w4elR6Jo+2ea12ozU1hLBGoq3UGjxZgqxMiKVoOQ+xLkC//qo2MIkkIStT7 lGEb1qDML4p0l7geh79wQ8v4mXdbfVG4MoWWj38YT7VHDOnXE1oa5K8kKMDYmAQQjsz/ ohhqreP45Fd1LbNEjA2J8rSwPDN06f2LCes7NMRlL133MEwt3qOK5o2ZI5KBViqs3ORP 8lFHThUpKJ8BiWOD/wap8KmLmZYxAIHWivg2l3HHlyNLWQIoNW4ticfJ5QhZoRJq9QEM qsSHspnnx1ycjyno9qsMwi8+lXu42SE8N7sh1nDgn6QFeYV/7qpfkiVQRddjb8hEOJit x2QQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KZzRzbN/pzpkEryvHHM49YPLWB/ipQLVREko44ovcHY=; b=zNdMxJpd53bbu31VRNCqBwDqad+3+GVF4H6tYJSdZfAuF0kfGm46NmRxp6pj/DHlbx 4ccBZbgONVSRF/CZUQK0636o9yPbgT679fqiO3hj+iLWpsmyrCo2ffiNjsVGXrMrQzMd TNyl8mQ8Nf/w9kB1sDmUaWwKEiUjXtWpz6R/cZrfrbizrVqKfnJXT4qidPqINhVFSYsb 6BNhU/UuheGO+3DLoC2rmsQap02gKJpuZVf3K3OKASRKEgIZe1QpPpuI+kll6x/Y0rT0 FsbqeHWN9lhJSmDgOqkoe5jahjjgfMNrANfjgbtd2uUKghlneZZQ60pc8jFfBap7scDI Jzog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="1kgziHW/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e129si843318pgc.344.2019.07.18.20.58.00; Thu, 18 Jul 2019 20:58:15 -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="1kgziHW/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727207AbfGSD5T (ORCPT + 99 others); Thu, 18 Jul 2019 23:57:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:56554 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727174AbfGSD5R (ORCPT ); Thu, 18 Jul 2019 23:57:17 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 533162082E; Fri, 19 Jul 2019 03:57:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508636; bh=J9xmBBYeV7Falpsj/fnhibMUKyl29JeWIf2sYOj903g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1kgziHW/yVN/+HjXjWH8qJDMOhAOUrqfLOV26rn3rp+nI2fXqm/gyHzwhWH4C9B+s JIS2m+ecXYR6o6WcmACCpIMSnar7byhCLHQl6KzW0wrJZ04z2B2Q2Vf0MltNbxRYMx gFeL0qwukhqy+4kDdnWz6cySI/CgZYHvJvCu9jIo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Gen Zhang , Kees Cook , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 5.2 014/171] consolemap: Fix a memory leaking bug in drivers/tty/vt/consolemap.c Date: Thu, 18 Jul 2019 23:54:05 -0400 Message-Id: <20190719035643.14300-14-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gen Zhang [ Upstream commit 84ecc2f6eb1cb12e6d44818f94fa49b50f06e6ac ] In function con_insert_unipair(), when allocation for p2 and p1[n] fails, ENOMEM is returned, but previously allocated p1 is not freed, remains as leaking memory. Thus we should free p1 as well when this allocation fails. Signed-off-by: Gen Zhang Reviewed-by: Kees Cook Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/vt/consolemap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c index b28aa0d289f8..79fcc96cc7c0 100644 --- a/drivers/tty/vt/consolemap.c +++ b/drivers/tty/vt/consolemap.c @@ -489,7 +489,11 @@ con_insert_unipair(struct uni_pagedir *p, u_short unicode, u_short fontpos) p2 = p1[n = (unicode >> 6) & 0x1f]; if (!p2) { p2 = p1[n] = kmalloc_array(64, sizeof(u16), GFP_KERNEL); - if (!p2) return -ENOMEM; + if (!p2) { + kfree(p1); + p->uni_pgdir[n] = NULL; + return -ENOMEM; + } memset(p2, 0xff, 64*sizeof(u16)); /* No glyphs for the characters (yet) */ } -- 2.20.1